Merge remote-tracking branch 'upstream/master'
* upstream/master: Change: simplify msg.js (#544) Add: store the reason why db failed (#550) Change: drop less, switch to less-bundle (#542) Add: improve import performance (#547)
This commit is contained in:
commit
5717a542a8
|
@ -108,7 +108,7 @@ function getUsercssCompiler(preprocessor) {
|
||||||
useFileCache: false,
|
useFileCache: false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
loadScript('/vendor/less/less.min.js');
|
loadScript('/vendor/less-bundle/less.min.js');
|
||||||
const varDefs = Object.keys(vars).map(key => `@${key}:${vars[key].value};\n`).join('');
|
const varDefs = Object.keys(vars).map(key => `@${key}:${vars[key].value};\n`).join('');
|
||||||
return self.less.render(varDefs + source)
|
return self.less.render(varDefs + source)
|
||||||
.then(({css}) => css);
|
.then(({css}) => css);
|
||||||
|
|
|
@ -17,6 +17,7 @@ window.API_METHODS = Object.assign(window.API_METHODS || {}, {
|
||||||
getStyle: styleManager.get,
|
getStyle: styleManager.get,
|
||||||
getStylesByUrl: styleManager.getStylesByUrl,
|
getStylesByUrl: styleManager.getStylesByUrl,
|
||||||
importStyle: styleManager.importStyle,
|
importStyle: styleManager.importStyle,
|
||||||
|
importManyStyles: styleManager.importMany,
|
||||||
installStyle: styleManager.installStyle,
|
installStyle: styleManager.installStyle,
|
||||||
styleExists: styleManager.styleExists,
|
styleExists: styleManager.styleExists,
|
||||||
toggleStyle: styleManager.toggleStyle,
|
toggleStyle: styleManager.toggleStyle,
|
||||||
|
|
201
background/db.js
201
background/db.js
|
@ -1,4 +1,4 @@
|
||||||
/* global tryCatch chromeLocal ignoreChromeError */
|
/* global chromeLocal ignoreChromeError workerUtil */
|
||||||
/* exported db */
|
/* exported db */
|
||||||
/*
|
/*
|
||||||
Initialize a database. There are some problems using IndexedDB in Firefox:
|
Initialize a database. There are some problems using IndexedDB in Firefox:
|
||||||
|
@ -18,52 +18,78 @@ const db = (() => {
|
||||||
};
|
};
|
||||||
|
|
||||||
function prepare() {
|
function prepare() {
|
||||||
// we use chrome.storage.local fallback if IndexedDB doesn't save data,
|
return shouldUseIndexedDB().then(
|
||||||
// which, once detected on the first run, is remembered in chrome.storage.local
|
ok => {
|
||||||
// for reliablility and in localStorage for fast synchronous access
|
if (ok) {
|
||||||
// (FF may block localStorage depending on its privacy options)
|
|
||||||
|
|
||||||
// test localStorage
|
|
||||||
const fallbackSet = localStorage.dbInChromeStorage;
|
|
||||||
if (fallbackSet === 'true' || !tryCatch(() => indexedDB)) {
|
|
||||||
useChromeStorage();
|
|
||||||
return Promise.resolve();
|
|
||||||
}
|
|
||||||
if (fallbackSet === 'false') {
|
|
||||||
useIndexedDB();
|
|
||||||
return Promise.resolve();
|
|
||||||
}
|
|
||||||
// test storage.local
|
|
||||||
return chromeLocal.get('dbInChromeStorage')
|
|
||||||
.then(data =>
|
|
||||||
data && data.dbInChromeStorage && Promise.reject())
|
|
||||||
.then(() =>
|
|
||||||
tryCatch(dbExecIndexedDB, 'getAllKeys', IDBKeyRange.lowerBound(1), 1) ||
|
|
||||||
Promise.reject())
|
|
||||||
.then(({target}) => (
|
|
||||||
(target.result || [])[0] ?
|
|
||||||
Promise.reject('ok') :
|
|
||||||
dbExecIndexedDB('put', {id: -1})))
|
|
||||||
.then(() =>
|
|
||||||
dbExecIndexedDB('get', -1))
|
|
||||||
.then(({target}) => (
|
|
||||||
(target.result || {}).id === -1 ?
|
|
||||||
dbExecIndexedDB('delete', -1) :
|
|
||||||
Promise.reject()))
|
|
||||||
.then(() =>
|
|
||||||
Promise.reject('ok'))
|
|
||||||
.catch(result => {
|
|
||||||
if (result === 'ok') {
|
|
||||||
useIndexedDB();
|
useIndexedDB();
|
||||||
} else {
|
} else {
|
||||||
useChromeStorage();
|
useChromeStorage();
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
err => {
|
||||||
|
useChromeStorage(err);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function shouldUseIndexedDB() {
|
||||||
|
// we use chrome.storage.local fallback if IndexedDB doesn't save data,
|
||||||
|
// which, once detected on the first run, is remembered in chrome.storage.local
|
||||||
|
// for reliablility and in localStorage for fast synchronous access
|
||||||
|
// (FF may block localStorage depending on its privacy options)
|
||||||
|
if (typeof indexedDB === 'undefined') {
|
||||||
|
return Promise.reject(new Error('indexedDB is undefined'));
|
||||||
|
}
|
||||||
|
// test localStorage
|
||||||
|
const fallbackSet = localStorage.dbInChromeStorage;
|
||||||
|
if (fallbackSet === 'true') {
|
||||||
|
return Promise.resolve(false);
|
||||||
|
}
|
||||||
|
if (fallbackSet === 'false') {
|
||||||
|
return Promise.resolve(true);
|
||||||
|
}
|
||||||
|
// test storage.local
|
||||||
|
return chromeLocal.get('dbInChromeStorage')
|
||||||
|
.then(data => {
|
||||||
|
if (data && data.dbInChromeStorage) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return testDBSize()
|
||||||
|
.then(ok => ok || testDBMutation());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function useChromeStorage() {
|
function testDBSize() {
|
||||||
|
return dbExecIndexedDB('getAllKeys', IDBKeyRange.lowerBound(1), 1)
|
||||||
|
.then(event => (
|
||||||
|
event.target.result &&
|
||||||
|
event.target.result.length &&
|
||||||
|
event.target.result[0]
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
function testDBMutation() {
|
||||||
|
return dbExecIndexedDB('put', {id: -1})
|
||||||
|
.then(() => dbExecIndexedDB('get', -1))
|
||||||
|
.then(event => {
|
||||||
|
if (!event.target.result) {
|
||||||
|
throw new Error('failed to get previously put item');
|
||||||
|
}
|
||||||
|
if (event.target.result.id !== -1) {
|
||||||
|
throw new Error('item id is wrong');
|
||||||
|
}
|
||||||
|
return dbExecIndexedDB('delete', -1);
|
||||||
|
})
|
||||||
|
.then(() => true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function useChromeStorage(err) {
|
||||||
exec = dbExecChromeStorage;
|
exec = dbExecChromeStorage;
|
||||||
chromeLocal.set({dbInChromeStorage: true}, ignoreChromeError);
|
chromeLocal.set({dbInChromeStorage: true}, ignoreChromeError);
|
||||||
|
if (err) {
|
||||||
|
chromeLocal.setValue('dbInChromeStorageReason', workerUtil.cloneError(err));
|
||||||
|
console.warn('Failed to access indexedDB. Switched to storage API.', err);
|
||||||
|
}
|
||||||
localStorage.dbInChromeStorage = 'true';
|
localStorage.dbInChromeStorage = 'true';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,39 +100,48 @@ const db = (() => {
|
||||||
}
|
}
|
||||||
|
|
||||||
function dbExecIndexedDB(method, ...args) {
|
function dbExecIndexedDB(method, ...args) {
|
||||||
return new Promise((resolve, reject) => {
|
return open().then(database => {
|
||||||
Object.assign(indexedDB.open('stylish', 2), {
|
if (!method) {
|
||||||
onsuccess(event) {
|
return database;
|
||||||
const database = event.target.result;
|
}
|
||||||
if (!method) {
|
if (method === 'putMany') {
|
||||||
resolve(database);
|
return putMany(database, ...args);
|
||||||
} else {
|
}
|
||||||
const transaction = database.transaction(['styles'], 'readwrite');
|
const mode = method.startsWith('get') ? 'readonly' : 'readwrite';
|
||||||
const store = transaction.objectStore('styles');
|
const transaction = database.transaction(['styles'], mode);
|
||||||
try {
|
const store = transaction.objectStore('styles');
|
||||||
Object.assign(store[method](...args), {
|
return storeRequest(store, method, ...args);
|
||||||
onsuccess: event => resolve(event, store, transaction, database),
|
});
|
||||||
onerror: reject,
|
|
||||||
});
|
function storeRequest(store, method, ...args) {
|
||||||
} catch (err) {
|
return new Promise((resolve, reject) => {
|
||||||
reject(err);
|
const request = store[method](...args);
|
||||||
}
|
request.onsuccess = resolve;
|
||||||
}
|
request.onerror = reject;
|
||||||
},
|
});
|
||||||
onerror(event) {
|
}
|
||||||
console.warn(event.target.error || event.target.errorCode);
|
|
||||||
reject(event);
|
function open() {
|
||||||
},
|
return new Promise((resolve, reject) => {
|
||||||
onupgradeneeded(event) {
|
const request = indexedDB.open('stylish', 2);
|
||||||
|
request.onsuccess = () => resolve(request.result);
|
||||||
|
request.onerror = reject;
|
||||||
|
request.onupgradeneeded = event => {
|
||||||
if (event.oldVersion === 0) {
|
if (event.oldVersion === 0) {
|
||||||
event.target.result.createObjectStore('styles', {
|
event.target.result.createObjectStore('styles', {
|
||||||
keyPath: 'id',
|
keyPath: 'id',
|
||||||
autoIncrement: true,
|
autoIncrement: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
|
function putMany(database, items) {
|
||||||
|
const transaction = database.transaction(['styles'], 'readwrite');
|
||||||
|
const store = transaction.objectStore('styles');
|
||||||
|
return Promise.all(items.map(item => storeRequest(store, 'put', item)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function dbExecChromeStorage(method, data) {
|
function dbExecChromeStorage(method, data) {
|
||||||
|
@ -118,17 +153,33 @@ const db = (() => {
|
||||||
|
|
||||||
case 'put':
|
case 'put':
|
||||||
if (!data.id) {
|
if (!data.id) {
|
||||||
return getAllStyles().then(styles => {
|
return getMaxId().then(id => {
|
||||||
data.id = 1;
|
data.id = id + 1;
|
||||||
for (const style of styles) {
|
|
||||||
data.id = Math.max(data.id, style.id + 1);
|
|
||||||
}
|
|
||||||
return dbExecChromeStorage('put', data);
|
return dbExecChromeStorage('put', data);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return chromeLocal.setValue(STYLE_KEY_PREFIX + data.id, data)
|
return chromeLocal.setValue(STYLE_KEY_PREFIX + data.id, data)
|
||||||
.then(() => (chrome.runtime.lastError ? Promise.reject() : data.id));
|
.then(() => (chrome.runtime.lastError ? Promise.reject() : data.id));
|
||||||
|
|
||||||
|
case 'putMany': {
|
||||||
|
const newItems = data.filter(i => !i.id);
|
||||||
|
const doPut = () =>
|
||||||
|
chromeLocal.set(data.reduce((o, item) => {
|
||||||
|
o[STYLE_KEY_PREFIX + item.id] = item;
|
||||||
|
return o;
|
||||||
|
}, {}))
|
||||||
|
.then(() => data.map(d => ({target: {result: d.id}})));
|
||||||
|
if (newItems.length) {
|
||||||
|
return getMaxId().then(id => {
|
||||||
|
for (const item of newItems) {
|
||||||
|
item.id = ++id;
|
||||||
|
}
|
||||||
|
return doPut();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return doPut();
|
||||||
|
}
|
||||||
|
|
||||||
case 'delete':
|
case 'delete':
|
||||||
return chromeLocal.remove(STYLE_KEY_PREFIX + data);
|
return chromeLocal.remove(STYLE_KEY_PREFIX + data);
|
||||||
|
|
||||||
|
@ -150,5 +201,17 @@ const db = (() => {
|
||||||
return styles;
|
return styles;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getMaxId() {
|
||||||
|
return getAllStyles().then(styles => {
|
||||||
|
let result = 0;
|
||||||
|
for (const style of styles) {
|
||||||
|
if (style.id > result) {
|
||||||
|
result = style.id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -55,6 +55,7 @@ const styleManager = (() => {
|
||||||
editSave,
|
editSave,
|
||||||
findStyle,
|
findStyle,
|
||||||
importStyle,
|
importStyle,
|
||||||
|
importMany,
|
||||||
toggleStyle,
|
toggleStyle,
|
||||||
setStyleExclusions,
|
setStyleExclusions,
|
||||||
getAllStyles, // used by import-export
|
getAllStyles, // used by import-export
|
||||||
|
@ -138,6 +139,18 @@ const styleManager = (() => {
|
||||||
.then(newData => handleSave(newData, 'import'));
|
.then(newData => handleSave(newData, 'import'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function importMany(items) {
|
||||||
|
return db.exec('putMany', items)
|
||||||
|
.then(events => {
|
||||||
|
for (let i = 0; i < items.length; i++) {
|
||||||
|
if (!items[i].id) {
|
||||||
|
items[i].id = events[i].target.result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Promise.all(items.map(i => handleSave(i, 'import')));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function installStyle(data, reason = null) {
|
function installStyle(data, reason = null) {
|
||||||
const style = styles.get(data.id);
|
const style = styles.get(data.id);
|
||||||
if (!style) {
|
if (!style) {
|
||||||
|
|
195
js/msg.js
195
js/msg.js
|
@ -4,30 +4,20 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const msg = (() => {
|
const msg = (() => {
|
||||||
let isBg = false;
|
const runtimeSend = promisify(chrome.runtime.sendMessage.bind(chrome.runtime));
|
||||||
if (chrome.extension.getBackgroundPage && chrome.extension.getBackgroundPage() === window) {
|
const tabSend = chrome.tabs && promisify(chrome.tabs.sendMessage.bind(chrome.tabs));
|
||||||
isBg = true;
|
const tabQuery = chrome.tabs && promisify(chrome.tabs.query.bind(chrome.tabs));
|
||||||
|
|
||||||
|
const isBg = chrome.extension.getBackgroundPage && chrome.extension.getBackgroundPage() === window;
|
||||||
|
if (isBg) {
|
||||||
window._msg = {
|
window._msg = {
|
||||||
id: 1,
|
|
||||||
storage: new Map(),
|
|
||||||
handler: null,
|
handler: null,
|
||||||
clone: deepCopy
|
clone: deepCopy
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const runtimeSend = promisify(chrome.runtime.sendMessage.bind(chrome.runtime));
|
const bgReady = getBg();
|
||||||
const tabSend = chrome.tabs && promisify(chrome.tabs.sendMessage.bind(chrome.tabs));
|
|
||||||
const tabQuery = chrome.tabs && promisify(chrome.tabs.query.bind(chrome.tabs));
|
|
||||||
let bg;
|
|
||||||
const preparing = !isBg && chrome.runtime.getBackgroundPage &&
|
|
||||||
promisify(chrome.runtime.getBackgroundPage.bind(chrome.runtime))()
|
|
||||||
.catch(() => null)
|
|
||||||
.then(_bg => {
|
|
||||||
bg = _bg;
|
|
||||||
});
|
|
||||||
bg = isBg ? window : !preparing ? null : undefined;
|
|
||||||
const EXTENSION_URL = chrome.runtime.getURL('');
|
const EXTENSION_URL = chrome.runtime.getURL('');
|
||||||
let handler;
|
let handler;
|
||||||
const from_ = location.href.startsWith(EXTENSION_URL) ? 'extension' : 'content';
|
|
||||||
const RX_NO_RECEIVER = /Receiving end does not exist/;
|
const RX_NO_RECEIVER = /Receiving end does not exist/;
|
||||||
const RX_PORT_CLOSED = /The message port closed before a response was received/;
|
const RX_PORT_CLOSED = /The message port closed before a response was received/;
|
||||||
return {
|
return {
|
||||||
|
@ -46,33 +36,29 @@ const msg = (() => {
|
||||||
RX_PORT_CLOSED
|
RX_PORT_CLOSED
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function getBg() {
|
||||||
|
if (isBg) {
|
||||||
|
return Promise.resolve(window);
|
||||||
|
}
|
||||||
|
if (!chrome.runtime.getBackgroundPage) {
|
||||||
|
return Promise.resolve();
|
||||||
|
}
|
||||||
|
return promisify(chrome.runtime.getBackgroundPage.bind(chrome.runtime))()
|
||||||
|
.catch(() => null);
|
||||||
|
}
|
||||||
|
|
||||||
function send(data, target = 'extension') {
|
function send(data, target = 'extension') {
|
||||||
if (bg === undefined) {
|
const message = {data, target};
|
||||||
return preparing.then(() => send(data, target));
|
return runtimeSend(message).then(unwrapData);
|
||||||
}
|
|
||||||
const message = {type: 'direct', data, target, from: from_};
|
|
||||||
if (bg) {
|
|
||||||
exchangeSet(message);
|
|
||||||
}
|
|
||||||
const request = runtimeSend(message).then(unwrapData);
|
|
||||||
if (message.id) {
|
|
||||||
return withCleanup(request, () => bg._msg.storage.delete(message.id));
|
|
||||||
}
|
|
||||||
return request;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendTab(tabId, data, options, target = 'tab') {
|
function sendTab(tabId, data, options, target = 'tab') {
|
||||||
return tabSend(tabId, {type: 'direct', data, target, from: from_}, options)
|
return tabSend(tabId, {data, target}, options)
|
||||||
.then(unwrapData);
|
.then(unwrapData);
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendBg(data) {
|
function sendBg(data) {
|
||||||
if (bg === undefined) {
|
return bgReady.then(bg => {
|
||||||
return preparing.then(doSend);
|
|
||||||
}
|
|
||||||
return withPromiseError(doSend);
|
|
||||||
|
|
||||||
function doSend() {
|
|
||||||
if (bg) {
|
if (bg) {
|
||||||
if (!bg._msg.handler) {
|
if (!bg._msg.handler) {
|
||||||
throw new Error('there is no bg handler');
|
throw new Error('there is no bg handler');
|
||||||
|
@ -84,7 +70,7 @@ const msg = (() => {
|
||||||
.then(deepCopy);
|
.then(deepCopy);
|
||||||
}
|
}
|
||||||
return send(data);
|
return send(data);
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function ignoreError(err) {
|
function ignoreError(err) {
|
||||||
|
@ -126,15 +112,12 @@ const msg = (() => {
|
||||||
if (!dataObj) {
|
if (!dataObj) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const message = {type: 'direct', data: dataObj, target, from: from_};
|
const message = {data: dataObj, target};
|
||||||
if (isExtension) {
|
requests.push(
|
||||||
exchangeSet(message);
|
tabSend(tab.id, message, options)
|
||||||
}
|
.then(unwrapData)
|
||||||
let request = tabSend(tab.id, message, options).then(unwrapData);
|
.catch(ignoreError)
|
||||||
if (message.id) {
|
);
|
||||||
request = withCleanup(request, () => bg._msg.storage.delete(message.id));
|
|
||||||
}
|
|
||||||
requests.push(request.catch(ignoreError));
|
|
||||||
}
|
}
|
||||||
return Promise.all(requests);
|
return Promise.all(requests);
|
||||||
});
|
});
|
||||||
|
@ -178,7 +161,7 @@ const msg = (() => {
|
||||||
extension: []
|
extension: []
|
||||||
};
|
};
|
||||||
if (isBg) {
|
if (isBg) {
|
||||||
bg._msg.handler = handler;
|
window._msg.handler = handler;
|
||||||
}
|
}
|
||||||
chrome.runtime.onMessage.addListener(handleMessage);
|
chrome.runtime.onMessage.addListener(handleMessage);
|
||||||
}
|
}
|
||||||
|
@ -202,70 +185,27 @@ const msg = (() => {
|
||||||
if (!handlers.length) {
|
if (!handlers.length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (message.type === 'exchange') {
|
const result = executeCallbacks(handlers, message.data, sender);
|
||||||
const pending = exchangeGet(message, true);
|
if (result === undefined) {
|
||||||
if (pending) {
|
return;
|
||||||
pending.then(response);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return response();
|
Promise.resolve(result)
|
||||||
|
.then(
|
||||||
function response() {
|
data => ({
|
||||||
const result = executeCallbacks(handlers, message.data, sender);
|
error: false,
|
||||||
if (result === undefined) {
|
data
|
||||||
return;
|
}),
|
||||||
}
|
err => ({
|
||||||
Promise.resolve(result)
|
error: true,
|
||||||
.then(
|
data: Object.assign({
|
||||||
data => ({
|
message: err.message || String(err),
|
||||||
error: false,
|
// FIXME: do we want to pass the entire stack?
|
||||||
data
|
stack: err.stack
|
||||||
}),
|
}, err) // this allows us to pass custom properties e.g. `err.index`
|
||||||
err => ({
|
|
||||||
error: true,
|
|
||||||
data: Object.assign({
|
|
||||||
message: err.message || String(err),
|
|
||||||
// FIXME: do we want to pass the entire stack?
|
|
||||||
stack: err.stack
|
|
||||||
}, err) // this allows us to pass custom properties e.g. `err.index`
|
|
||||||
})
|
|
||||||
)
|
|
||||||
.then(function doResponse(responseMessage) {
|
|
||||||
if (message.from === 'extension' && bg === undefined) {
|
|
||||||
return preparing.then(() => doResponse(responseMessage));
|
|
||||||
}
|
|
||||||
if (message.from === 'extension' && bg) {
|
|
||||||
exchangeSet(responseMessage);
|
|
||||||
} else {
|
|
||||||
responseMessage.type = 'direct';
|
|
||||||
}
|
|
||||||
return responseMessage;
|
|
||||||
})
|
})
|
||||||
.then(sendResponse);
|
)
|
||||||
return true;
|
.then(sendResponse);
|
||||||
}
|
return true;
|
||||||
}
|
|
||||||
|
|
||||||
function exchangeGet(message, keepStorage = false) {
|
|
||||||
if (bg === undefined) {
|
|
||||||
return preparing.then(() => exchangeGet(message, keepStorage));
|
|
||||||
}
|
|
||||||
message.data = bg._msg.storage.get(message.id);
|
|
||||||
if (keepStorage) {
|
|
||||||
message.data = deepCopy(message.data);
|
|
||||||
} else {
|
|
||||||
bg._msg.storage.delete(message.id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function exchangeSet(message) {
|
|
||||||
const id = bg._msg.id;
|
|
||||||
bg._msg.storage.set(id, message.data);
|
|
||||||
bg._msg.id++;
|
|
||||||
message.type = 'exchange';
|
|
||||||
message.id = id;
|
|
||||||
delete message.data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function withPromiseError(fn, ...args) {
|
function withPromiseError(fn, ...args) {
|
||||||
|
@ -276,46 +216,15 @@ const msg = (() => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function withCleanup(p, fn) {
|
|
||||||
return p.then(
|
|
||||||
result => {
|
|
||||||
cleanup();
|
|
||||||
return result;
|
|
||||||
},
|
|
||||||
err => {
|
|
||||||
cleanup();
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
function cleanup() {
|
|
||||||
try {
|
|
||||||
fn();
|
|
||||||
} catch (err) {
|
|
||||||
// pass
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// {type, error, data, id}
|
// {type, error, data, id}
|
||||||
function unwrapData(result) {
|
function unwrapData(result) {
|
||||||
if (result === undefined) {
|
if (result === undefined) {
|
||||||
throw new Error('Receiving end does not exist');
|
throw new Error('Receiving end does not exist');
|
||||||
}
|
}
|
||||||
if (result.type === 'exchange') {
|
if (result.error) {
|
||||||
const pending = exchangeGet(result);
|
throw Object.assign(new Error(result.data.message), result.data);
|
||||||
if (pending) {
|
|
||||||
return pending.then(unwrap);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return unwrap();
|
|
||||||
|
|
||||||
function unwrap() {
|
|
||||||
if (result.error) {
|
|
||||||
throw Object.assign(new Error(result.data.message), result.data);
|
|
||||||
}
|
|
||||||
return result.data;
|
|
||||||
}
|
}
|
||||||
|
return result.data;
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
|
@ -126,13 +126,20 @@ function importFromString(jsonString) {
|
||||||
oldStyles.map(style => [style.id, style]));
|
oldStyles.map(style => [style.id, style]));
|
||||||
oldStylesByName = json.length && new Map(
|
oldStylesByName = json.length && new Map(
|
||||||
oldStyles.map(style => [style.name.trim(), style]));
|
oldStyles.map(style => [style.name.trim(), style]));
|
||||||
return Promise.all(json.map((item, i) => {
|
|
||||||
|
const items = [];
|
||||||
|
json.forEach((item, i) => {
|
||||||
const info = analyze(item, i);
|
const info = analyze(item, i);
|
||||||
if (info) {
|
if (info) {
|
||||||
return API.importStyle(item)
|
items.push({info, item});
|
||||||
.then(style => updateStats(style, info));
|
|
||||||
}
|
}
|
||||||
}));
|
});
|
||||||
|
return API.importManyStyles(items.map(i => i.item))
|
||||||
|
.then(styles => {
|
||||||
|
for (let i = 0; i < styles.length; i++) {
|
||||||
|
updateStats(styles[i], items[i].info);
|
||||||
|
}
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.then(done);
|
.then(done);
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
"eslint": "^5.9.0",
|
"eslint": "^5.9.0",
|
||||||
"fs-extra": "^7.0.1",
|
"fs-extra": "^7.0.1",
|
||||||
"jsonlint": "^1.6.3",
|
"jsonlint": "^1.6.3",
|
||||||
"less": "^3.8.1",
|
"less-bundle": "github:openstyles/less-bundle#v0.1.0",
|
||||||
"lz-string-unsafe": "^1.4.4-fork-1",
|
"lz-string-unsafe": "^1.4.4-fork-1",
|
||||||
"rimraf": "^2.6.2",
|
"rimraf": "^2.6.2",
|
||||||
"semver-bundle": "^0.1.1",
|
"semver-bundle": "^0.1.1",
|
||||||
|
|
|
@ -14,7 +14,7 @@ const files = {
|
||||||
'jsonlint': [
|
'jsonlint': [
|
||||||
'lib/jsonlint.js → jsonlint.js'
|
'lib/jsonlint.js → jsonlint.js'
|
||||||
],
|
],
|
||||||
'less': [
|
'less-bundle': [
|
||||||
'dist/less.min.js → less.min.js'
|
'dist/less.min.js → less.min.js'
|
||||||
],
|
],
|
||||||
'lz-string-unsafe': [
|
'lz-string-unsafe': [
|
||||||
|
|
358
vendor/less/LICENSE → vendor/less-bundle/LICENSE
vendored
358
vendor/less/LICENSE → vendor/less-bundle/LICENSE
vendored
|
@ -1,181 +1,177 @@
|
||||||
https://github.com/less/less.js
|
|
||||||
|
Apache License
|
||||||
https://github.com/less/less.js/blob/master/LICENSE
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
Apache License
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
Version 2.0, January 2004
|
|
||||||
http://www.apache.org/licenses/
|
1. Definitions.
|
||||||
|
|
||||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
1. Definitions.
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
"License" shall mean the terms and conditions for use, reproduction,
|
the copyright owner that is granting the License.
|
||||||
and distribution as defined by Sections 1 through 9 of this document.
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
"Licensor" shall mean the copyright owner or entity authorized by
|
other entities that control, are controlled by, or are under common
|
||||||
the copyright owner that is granting the License.
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
"Legal Entity" shall mean the union of the acting entity and all
|
direction or management of such entity, whether by contract or
|
||||||
other entities that control, are controlled by, or are under common
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
control with that entity. For the purposes of this definition,
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
"control" means (i) the power, direct or indirect, to cause the
|
|
||||||
direction or management of such entity, whether by contract or
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
exercising permissions granted by this License.
|
||||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
"You" (or "Your") shall mean an individual or Legal Entity
|
including but not limited to software source code, documentation
|
||||||
exercising permissions granted by this License.
|
source, and configuration files.
|
||||||
|
|
||||||
"Source" form shall mean the preferred form for making modifications,
|
"Object" form shall mean any form resulting from mechanical
|
||||||
including but not limited to software source code, documentation
|
transformation or translation of a Source form, including but
|
||||||
source, and configuration files.
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
"Object" form shall mean any form resulting from mechanical
|
|
||||||
transformation or translation of a Source form, including but
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
not limited to compiled object code, generated documentation,
|
Object form, made available under the License, as indicated by a
|
||||||
and conversions to other media types.
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
"Work" shall mean the work of authorship, whether in Source or
|
|
||||||
Object form, made available under the License, as indicated by a
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
copyright notice that is included in or attached to the work
|
form, that is based on (or derived from) the Work and for which the
|
||||||
(an example is provided in the Appendix below).
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
"Derivative Works" shall mean any work, whether in Source or Object
|
of this License, Derivative Works shall not include works that remain
|
||||||
form, that is based on (or derived from) the Work and for which the
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
editorial revisions, annotations, elaborations, or other modifications
|
the Work and Derivative Works thereof.
|
||||||
represent, as a whole, an original work of authorship. For the purposes
|
|
||||||
of this License, Derivative Works shall not include works that remain
|
"Contribution" shall mean any work of authorship, including
|
||||||
separable from, or merely link (or bind by name) to the interfaces of,
|
the original version of the Work and any modifications or additions
|
||||||
the Work and Derivative Works thereof.
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
"Contribution" shall mean any work of authorship, including
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
the original version of the Work and any modifications or additions
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
to that Work or Derivative Works thereof, that is intentionally
|
means any form of electronic, verbal, or written communication sent
|
||||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
to the Licensor or its representatives, including but not limited to
|
||||||
or by an individual or Legal Entity authorized to submit on behalf of
|
communication on electronic mailing lists, source code control systems,
|
||||||
the copyright owner. For the purposes of this definition, "submitted"
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
means any form of electronic, verbal, or written communication sent
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
to the Licensor or its representatives, including but not limited to
|
excluding communication that is conspicuously marked or otherwise
|
||||||
communication on electronic mailing lists, source code control systems,
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
and issue tracking systems that are managed by, or on behalf of, the
|
|
||||||
Licensor for the purpose of discussing and improving the Work, but
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
excluding communication that is conspicuously marked or otherwise
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
designated in writing by the copyright owner as "Not a Contribution."
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
on behalf of whom a Contribution has been received by Licensor and
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
subsequently incorporated within the Work.
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
Work and such Derivative Works in Source or Object form.
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
copyright license to reproduce, prepare Derivative Works of,
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
publicly display, publicly perform, sublicense, and distribute the
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
Work and such Derivative Works in Source or Object form.
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
3. Grant of Patent License. Subject to the terms and conditions of
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
where such license applies only to those patent claims licensable
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
by such Contributor that are necessarily infringed by their
|
||||||
(except as stated in this section) patent license to make, have made,
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
where such license applies only to those patent claims licensable
|
institute patent litigation against any entity (including a
|
||||||
by such Contributor that are necessarily infringed by their
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
Contribution(s) alone or by combination of their Contribution(s)
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
with the Work to which such Contribution(s) was submitted. If You
|
or contributory patent infringement, then any patent licenses
|
||||||
institute patent litigation against any entity (including a
|
granted to You under this License for that Work shall terminate
|
||||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
as of the date such litigation is filed.
|
||||||
or a Contribution incorporated within the Work constitutes direct
|
|
||||||
or contributory patent infringement, then any patent licenses
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
granted to You under this License for that Work shall terminate
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
as of the date such litigation is filed.
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
4. Redistribution. You may reproduce and distribute copies of the
|
|
||||||
Work or Derivative Works thereof in any medium, with or without
|
(a) You must give any other recipients of the Work or
|
||||||
modifications, and in Source or Object form, provided that You
|
Derivative Works a copy of this License; and
|
||||||
meet the following conditions:
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
(a) You must give any other recipients of the Work or
|
stating that You changed the files; and
|
||||||
Derivative Works a copy of this License; and
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
(b) You must cause any modified files to carry prominent notices
|
that You distribute, all copyright, patent, trademark, and
|
||||||
stating that You changed the files; and
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
(c) You must retain, in the Source form of any Derivative Works
|
the Derivative Works; and
|
||||||
that You distribute, all copyright, patent, trademark, and
|
|
||||||
attribution notices from the Source form of the Work,
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
excluding those notices that do not pertain to any part of
|
distribution, then any Derivative Works that You distribute must
|
||||||
the Derivative Works; and
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
(d) If the Work includes a "NOTICE" text file as part of its
|
pertain to any part of the Derivative Works, in at least one
|
||||||
distribution, then any Derivative Works that You distribute must
|
of the following places: within a NOTICE text file distributed
|
||||||
include a readable copy of the attribution notices contained
|
as part of the Derivative Works; within the Source form or
|
||||||
within such NOTICE file, excluding those notices that do not
|
documentation, if provided along with the Derivative Works; or,
|
||||||
pertain to any part of the Derivative Works, in at least one
|
within a display generated by the Derivative Works, if and
|
||||||
of the following places: within a NOTICE text file distributed
|
wherever such third-party notices normally appear. The contents
|
||||||
as part of the Derivative Works; within the Source form or
|
of the NOTICE file are for informational purposes only and
|
||||||
documentation, if provided along with the Derivative Works; or,
|
do not modify the License. You may add Your own attribution
|
||||||
within a display generated by the Derivative Works, if and
|
notices within Derivative Works that You distribute, alongside
|
||||||
wherever such third-party notices normally appear. The contents
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
of the NOTICE file are for informational purposes only and
|
that such additional attribution notices cannot be construed
|
||||||
do not modify the License. You may add Your own attribution
|
as modifying the License.
|
||||||
notices within Derivative Works that You distribute, alongside
|
|
||||||
or as an addendum to the NOTICE text from the Work, provided
|
You may add Your own copyright statement to Your modifications and
|
||||||
that such additional attribution notices cannot be construed
|
may provide additional or different license terms and conditions
|
||||||
as modifying the License.
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
You may add Your own copyright statement to Your modifications and
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
may provide additional or different license terms and conditions
|
the conditions stated in this License.
|
||||||
for use, reproduction, or distribution of Your modifications, or
|
|
||||||
for any such Derivative Works as a whole, provided Your use,
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
reproduction, and distribution of the Work otherwise complies with
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
the conditions stated in this License.
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
any Contribution intentionally submitted for inclusion in the Work
|
the terms of any separate license agreement you may have executed
|
||||||
by You to the Licensor shall be under the terms and conditions of
|
with Licensor regarding such Contributions.
|
||||||
this License, without any additional terms or conditions.
|
|
||||||
Notwithstanding the above, nothing herein shall supersede or modify
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
the terms of any separate license agreement you may have executed
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
with Licensor regarding such Contributions.
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
6. Trademarks. This License does not grant permission to use the trade
|
|
||||||
names, trademarks, service marks, or product names of the Licensor,
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
except as required for reasonable and customary use in describing the
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
origin of the Work and reproducing the content of the NOTICE file.
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
implied, including, without limitation, any warranties or conditions
|
||||||
agreed to in writing, Licensor provides the Work (and each
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
appropriateness of using or redistributing the Work and assume any
|
||||||
implied, including, without limitation, any warranties or conditions
|
risks associated with Your exercise of permissions under this License.
|
||||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
||||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
appropriateness of using or redistributing the Work and assume any
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
risks associated with Your exercise of permissions under this License.
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
8. Limitation of Liability. In no event and under no legal theory,
|
liable to You for damages, including any direct, indirect, special,
|
||||||
whether in tort (including negligence), contract, or otherwise,
|
incidental, or consequential damages of any character arising as a
|
||||||
unless required by applicable law (such as deliberate and grossly
|
result of this License or out of the use or inability to use the
|
||||||
negligent acts) or agreed to in writing, shall any Contributor be
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
liable to You for damages, including any direct, indirect, special,
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
incidental, or consequential damages of any character arising as a
|
other commercial damages or losses), even if such Contributor
|
||||||
result of this License or out of the use or inability to use the
|
has been advised of the possibility of such damages.
|
||||||
Work (including but not limited to damages for loss of goodwill,
|
|
||||||
work stoppage, computer failure or malfunction, or any and all
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
other commercial damages or losses), even if such Contributor
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
has been advised of the possibility of such damages.
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
9. Accepting Warranty or Additional Liability. While redistributing
|
License. However, in accepting such obligations, You may act only
|
||||||
the Work or Derivative Works thereof, You may choose to offer,
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
or other liability obligations and/or rights consistent with this
|
defend, and hold each Contributor harmless for any liability
|
||||||
License. However, in accepting such obligations, You may act only
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
on Your own behalf and on Your sole responsibility, not on behalf
|
of your accepting any such warranty or additional liability.
|
||||||
of any other Contributor, and only if You agree to indemnify,
|
|
||||||
defend, and hold each Contributor harmless for any liability
|
END OF TERMS AND CONDITIONS
|
||||||
incurred by, or claims asserted against, such Contributor by reason
|
|
||||||
of your accepting any such warranty or additional liability.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
5
vendor/less-bundle/README.md
vendored
Normal file
5
vendor/less-bundle/README.md
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
## less-bundle v0.1.0
|
||||||
|
|
||||||
|
less-bundle installed via npm - source repo:
|
||||||
|
|
||||||
|
https://github.com/openstyles/less-bundle/raw/v0.1.0/dist/less.min.js
|
1
vendor/less-bundle/less.min.js
vendored
Normal file
1
vendor/less-bundle/less.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
10
vendor/less/README.md
vendored
10
vendor/less/README.md
vendored
|
@ -1,10 +0,0 @@
|
||||||
## LESS v3.8.1
|
|
||||||
|
|
||||||
less.js installed via npm - source repo:
|
|
||||||
|
|
||||||
https://github.com/less/less.js/blob/v3.8.1/dist/less.min.js
|
|
||||||
|
|
||||||
If the link doesn't work, it is likely that the npm version and the release versions don't match:
|
|
||||||
|
|
||||||
- https://www.npmjs.com/package/less
|
|
||||||
- https://github.com/less/less.js/releases
|
|
18
vendor/less/less.min.js
vendored
18
vendor/less/less.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user