chore: update deps, add vendor script

This commit is contained in:
dragonwocky 2022-12-08 15:48:47 +11:00
parent c38c5006e0
commit 73e3c7c3a9
Signed by: dragonwocky
GPG Key ID: 7998D08F7D7BD7A8
20 changed files with 97 additions and 11153 deletions

View File

@ -277,7 +277,7 @@ try {
// asar blocks thread = spinner won't actually spin
// first frame at least can serve as waiting indicator
startSpinner();
unpackApp();
await unpackApp();
stopSpinner();
}
// backup is used to restore app to pre-enhanced state
@ -364,6 +364,7 @@ try {
printHelp(commands, options);
}
} catch (error) {
stopSpinner();
const message = error.message.split("\n")[0];
if (__debug) {
print`{bold.red ${error.name}:} ${message}\n{grey ${error.stack

View File

@ -7,20 +7,17 @@
"repository": "github:notion-enhancer/desktop",
"bugs": "https://github.com/notion-enhancer/desktop/issues",
"funding": "https://github.com/sponsors/dragonwocky",
"packageManager": "yarn@3.3.0",
"license": "MIT",
"bin": "bin.mjs",
"type": "module",
"scripts": {
"build-ext": "./scripts/build-browser-extension.sh"
"build": "./scripts/build-browser-extension.sh",
"vendor": "node ./scripts/vendor-dependencies.mjs"
},
"engines": {
"node": ">=16.x.x"
},
"dependencies": {
"@electron/asar": "^3.2.2",
"arg": "^5.0.2",
"chalk-template": "^0.4.0"
},
"keywords": [
"windows",
"macos",
@ -37,5 +34,9 @@
"notion",
"notion-enhancer"
],
"packageManager": "yarn@3.3.0"
"dependencies": {
"@electron/asar": "^3.2.2",
"arg": "^5.0.2",
"chalk-template": "^0.4.0"
}
}

View File

@ -6,7 +6,8 @@
import asar from "@electron/asar";
import os from "node:os";
import { promises as fsp, existsSync } from "node:fs";
import fsp from "node:fs/promises";
import { existsSync } from "node:fs";
import { fileURLToPath } from "node:url";
import { join, resolve } from "node:path";
import { execSync } from "node:child_process";
@ -101,11 +102,12 @@ const setNotionPath = (path) => {
return insertVersion;
};
const unpackApp = () => {
const unpackApp = async () => {
const appPath = getAppPath();
if (!appPath || !appPath.endsWith("asar")) return false;
// asar reads synchronously
asar.extractAll(appPath, appPath.replace(/\.asar$/, ""));
await fsp.rm(appPath);
return true;
},
applyEnhancements = async () => {
@ -140,9 +142,11 @@ const unpackApp = () => {
// remove cli-specific fields
delete insertManifest.bin;
delete insertManifest.type;
delete insertManifest.scripts;
delete insertManifest.engines;
delete insertManifest.dependencies;
delete insertManifest.packageManager;
delete insertManifest.dependencies;
delete insertManifest.devDependencies;
scriptUpdates.push(fsp.writeFile(manifestPath, JSON.stringify(insertManifest)));
await Promise.all(scriptUpdates);
return true;

View File

@ -32,19 +32,16 @@ const patches = {
{ /* notion-enhancer */
const schemePrefix = "notion://www.notion.so/__notion-enhancer/";
if (req.url.startsWith(schemePrefix)) {
const { search, hash, pathname } = new URL(req.url),
const { search, hash, pathname } = new URL(req.url),
fileExt = pathname.split(".").reverse()[0],
filePath = \`../node_modules/notion-enhancer/\${req.url.slice(
schemePrefix.length,
-(search.length + hash.length)
)}\`,
mimeType = Object.entries(require("notion-enhancer/dep/mime-db.json"))
.filter(([_, data]) => data.extensions)
.find(([_, data]) => data.extensions.includes(fileExt));
callback({
data: require("fs").createReadStream(require("path").resolve(\`\${__dirname}/\${filePath}\`)),
headers: { "content-type": mimeType },
});
)}\`;
callback({
data: require("fs").createReadStream(require("path").resolve(\`\${__dirname}/\${filePath}\`)),
headers: { "content-type": require("notion-enhancer/vendor/content-types.min.js").get(fileExt) },
});
}
}`;
if (scriptContent.includes(replaceValue)) return scriptContent;

View File

@ -0,0 +1,37 @@
/**
* notion-enhancer
* (c) 2022 dragonwocky <thedragonring.bod@gmail.com> (https://dragonwocky.me/)
* (https://notion-enhancer.github.io/) under the MIT license
*/
import fsp from "node:fs/promises";
import { existsSync } from "node:fs";
import { resolve } from "node:path";
import { fileURLToPath } from "node:url";
const dependencies = [
["twind.min.js", "https://cdn.twind.style"],
["lucide.min.js", "https://unpkg.com/lucide@0.104.0/dist/umd/lucide.min.js"],
["jscolor.min.js", "https://cdnjs.cloudflare.com/ajax/libs/jscolor/2.5.1/jscolor.min.js"],
];
const output = fileURLToPath(new URL("../src/vendor", import.meta.url));
if (existsSync(output)) await fsp.rm(output, { recursive: true });
await fsp.mkdir(output);
for (const [file, source] of dependencies) {
const res = await (await fetch(source)).text();
await fsp.writeFile(resolve(`${output}/${file}`), res);
}
// build content type lookup script from mime-db to avoid
// re-processing entire the database every time a file is
// requested via notion://www.notion.so/__notion-enhancer/
const mimeTypes = await (await fetch("https://unpkg.com/mime-db@1.52.0/db.json")).json(),
contentTypes = [];
for (const [type, { extensions, charset }] of Object.entries(mimeTypes)) {
if (!extensions) continue;
const contentType = charset ? `${type}; charset=${charset.toLowerCase()}` : type;
for (const ext of extensions) contentTypes.push([ext, contentType]);
}
const encodedContentTypes = `module.exports=new Map(${JSON.stringify(contentTypes)});`;
await fsp.writeFile(resolve(`${output}/content-types.min.js`), encodedContentTypes);

View File

@ -1,5 +0,0 @@
# notion-enhancer/dep
libraries depended on by the notion-enhancer
[read the docs online](https://notion-enhancer.github.io/about/credits/#dependencies)

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 59 KiB

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -1,58 +0,0 @@
/**
* style-vendorizer v2.0.0
* @license MIT
* @source https://unpkg.com/style-vendorizer@^2.0.0?module
*/
var i = new Map([
['align-self', '-ms-grid-row-align'],
['color-adjust', '-webkit-print-color-adjust'],
['column-gap', 'grid-column-gap'],
['gap', 'grid-gap'],
['grid-template-columns', '-ms-grid-columns'],
['grid-template-rows', '-ms-grid-rows'],
['justify-self', '-ms-grid-column-align'],
['margin-inline-end', '-webkit-margin-end'],
['margin-inline-start', '-webkit-margin-start'],
['overflow-wrap', 'word-wrap'],
['padding-inline-end', '-webkit-padding-end'],
['padding-inline-start', '-webkit-padding-start'],
['row-gap', 'grid-row-gap'],
['scroll-margin-bottom', 'scroll-snap-margin-bottom'],
['scroll-margin-left', 'scroll-snap-margin-left'],
['scroll-margin-right', 'scroll-snap-margin-right'],
['scroll-margin-top', 'scroll-snap-margin-top'],
['scroll-margin', 'scroll-snap-margin'],
['text-combine-upright', '-ms-text-combine-horizontal'],
]);
function r(r) {
return i.get(r);
}
function n(i) {
var r =
/^(?:(text-(?:decoration$|e|or|si)|back(?:ground-cl|d|f)|box-d|(?:mask(?:$|-[ispro]|-cl)))|(tab-|column(?!-s)|text-align-l)|(ap)|(u|hy))/i.exec(
i
);
return r ? (r[1] ? 1 : r[2] ? 2 : r[3] ? 3 : 5) : 0;
}
function t(i, r) {
var n = /^(?:(pos)|(background-i)|((?:max-|min-)?(?:block-s|inl|he|widt))|(dis))/i.exec(i);
return n
? n[1]
? /^sti/i.test(r)
? 1
: 0
: n[2]
? /^image-/i.test(r)
? 1
: 0
: n[3]
? '-' === r[3]
? 2
: 0
: /^(inline-)?grid$/i.test(r)
? 4
: 0
: 0;
}
export { r as cssPropertyAlias, n as cssPropertyPrefixFlags, t as cssValuePrefixFlags };

View File

@ -1,43 +0,0 @@
/**
* Twind v0.16.16
* @license MIT
* @source https://unpkg.com/@twind/content@0.1.0/content.js?module
*/
import { directive as o } from './twind.mjs';
var c = new Set([
'open-quote',
'close-quote',
'no-open-quote',
'no-close-quote',
'normal',
'none',
'inherit',
'initial',
'unset',
]),
n = (t) => t.join('-'),
s = (t) => {
switch (t[0]) {
case 'data':
return `attr(${n(t)})`;
case 'attr':
case 'counter':
return `${t[0]}(${n(t.slice(1))})`;
case 'var':
return `var(--${n(t)})`;
case void 0:
return 'attr(data-content)';
default:
return JSON.stringify(n(t));
}
},
i = (t, { theme: r }) => {
let e = Array.isArray(t) ? n(t) : t;
return {
content:
(e && r('content', [e], '')) || (c.has(e) && e) || (Array.isArray(t) ? s(t) : e),
};
},
u = (t, r) => (Array.isArray(t) ? i(t, r) : o(i, t));
export { u as content };

View File

@ -1,134 +0,0 @@
/**
* Twind v0.16.16
* @license MIT
* @source https://unpkg.com/twind@0.16.16/css/css.js?module
*/
// src/css/index.ts
import { apply, hash, directive } from "./twind.mjs";
// src/internal/util.ts
var includes = (value, search) => !!~value.indexOf(search);
var join = (parts, separator = "-") => parts.join(separator);
var hyphenate = value => value.replace(/[A-Z]/g, "-$&").toLowerCase();
var evalThunk = (value, context) => {
while (typeof value == "function") {
value = value(context);
}
return value;
};
var isCSSProperty = (key, value) => !includes("@:&", key[0]) && (includes("rg", (typeof value)[5]) || Array.isArray(value));
var merge = (target, source, context) => source ? Object.keys(source).reduce((target2, key) => {
const value = evalThunk(source[key], context);
if (isCSSProperty(key, value)) {
target2[hyphenate(key)] = value;
} else {
target2[key] = key[0] == "@" && includes("figa", key[1]) ? (target2[key] || []).concat(value) : merge(target2[key] || {}, value, context);
}
return target2;
}, target) : target;
var escape = typeof CSS !== "undefined" && CSS.escape || (className => className.replace(/[!"'`*+.,;:\\/<=>?@#$%&^|~()[\]{}]/g, "\\$&").replace(/^\d/, "\\3$& "));
var buildMediaQuery = screen2 => {
if (!Array.isArray(screen2)) {
screen2 = [screen2];
}
return "@media " + join(screen2.map(screen3 => {
if (typeof screen3 == "string") {
screen3 = { min: screen3 };
}
return screen3.raw || join(Object.keys(screen3).map(feature => `(${feature}-width:${screen3[feature]})`), " and ");
}), ",");
};
// src/css/index.ts
var translate = (tokens, context) => {
const collect = (target, token) => Array.isArray(token) ? token.reduce(collect, target) : merge(target, evalThunk(token, context), context);
return tokens.reduce(collect, {});
};
var newRule = /\s*(?:([\w-%@]+)\s*:?\s*([^{;]+?)\s*(?:;|$|})|([^;}{]*?)\s*{)|(})/gi;
var ruleClean = /\/\*[\s\S]*?\*\/|\s+|\n/gm;
var decorate = (selectors, currentBlock) => selectors.reduceRight((rules, selector) => ({ [selector]: rules }), currentBlock);
var saveBlock = (rules, selectors, currentBlock) => {
if (currentBlock) {
rules.push(decorate(selectors, currentBlock));
}
};
var interleave = (strings, interpolations, context) => {
let buffer = strings[0];
const result = [];
for (let index = 0; index < interpolations.length;) {
const interpolation = evalThunk(interpolations[index], context);
if (interpolation && typeof interpolation == "object") {
result.push(buffer, interpolation);
buffer = strings[++index];
} else {
buffer += (interpolation || "") + strings[++index];
}
}
result.push(buffer);
return result;
};
var astish = (values, context) => {
const selectors = [];
const rules = [];
let currentBlock;
let match;
for (let index = 0; index < values.length; index++) {
const value = values[index];
if (typeof value == "string") {
while (match = newRule.exec(value.replace(ruleClean, " "))) {
if (!match[0])
continue;
if (match[4]) {
currentBlock = saveBlock(rules, selectors, currentBlock);
selectors.pop();
}
if (match[3]) {
currentBlock = saveBlock(rules, selectors, currentBlock);
selectors.push(match[3]);
} else if (!match[4]) {
if (!currentBlock)
currentBlock = {};
const value2 = match[2] && /\S/.test(match[2]) ? match[2] : values[++index];
if (value2) {
if (match[1] == "@apply") {
merge(currentBlock, evalThunk(apply(value2), context), context);
} else {
currentBlock[match[1]] = value2;
}
}
}
}
} else {
currentBlock = saveBlock(rules, selectors, currentBlock);
rules.push(decorate(selectors, value));
}
}
saveBlock(rules, selectors, currentBlock);
return rules;
};
var cssFactory = (tokens, context) => translate(Array.isArray(tokens[0]) && Array.isArray(tokens[0].raw) ? astish(interleave(tokens[0], tokens.slice(1), context), context) : tokens, context);
var css = (...tokens) => directive(cssFactory, tokens);
var keyframesFactory = (tokens, context) => {
const waypoints = cssFactory(tokens, context);
const id = hash(JSON.stringify(waypoints));
context.tw(() => ({ [`@keyframes ${id}`]: waypoints }));
return id;
};
var keyframes = (...tokens) => directive(keyframesFactory, tokens);
var animation = (value, waypoints) => waypoints === void 0 ? (...args) => animation(value, keyframes(...args)) : css({
...(value && typeof value == "object" ? value : { animation: value }),
animationName: typeof waypoints == "function" ? waypoints : keyframes(waypoints) });
var screenFactory = ({ size, rules }, context) => {
const media = buildMediaQuery(context.theme("screens", size));
return rules === void 0 ? media : {
[media]: typeof rules == "function" ? evalThunk(rules, context) : cssFactory([rules], context) };
};
var screen = (size, rules) => directive(screenFactory, { size, rules });
export {
animation,
css,
keyframes,
screen };

File diff suppressed because it is too large Load Diff

View File

@ -4,36 +4,36 @@
* (https://notion-enhancer.github.io/) under the MIT license
*/
'use strict';
"use strict";
module.exports = async function (target, __exports, __eval) {
require('notion-enhancer/electronApi.cjs');
const api = require('notion-enhancer/api/index.cjs'),
require("notion-enhancer/electronApi.cjs");
const api = require("notion-enhancer/api/index.cjs"),
{ registry } = api;
if (target === 'renderer/index') {
document.addEventListener('readystatechange', (event) => {
if (document.readyState !== 'complete') return false;
const script = document.createElement('script');
script.type = 'module';
script.src = api.fs.localPath('frame.mjs');
if (target === "renderer/index") {
document.addEventListener("readystatechange", (event) => {
if (document.readyState !== "complete") return false;
const script = document.createElement("script");
script.type = "module";
script.src = api.fs.localPath("frame.mjs");
document.head.appendChild(script);
});
}
if (target === 'renderer/preload') {
document.addEventListener('readystatechange', (event) => {
if (document.readyState !== 'complete') return false;
const script = document.createElement('script');
script.type = 'module';
script.src = api.fs.localPath('client.mjs');
if (target === "renderer/preload") {
document.addEventListener("readystatechange", (event) => {
if (document.readyState !== "complete") return false;
const script = document.createElement("script");
script.type = "module";
script.src = api.fs.localPath("client.mjs");
document.head.appendChild(script);
});
}
if (target === 'main/main') {
const { app } = require('electron');
app.whenReady().then(require('notion-enhancer/worker.cjs').listen);
if (target === "main/main") {
const { app } = require("electron");
app.whenReady().then(require("notion-enhancer/worker.cjs").listen);
}
for (const mod of await registry.list((mod) => registry.enabled(mod.id))) {

View File

@ -19,7 +19,7 @@
"page": "mods/menu/menu.html",
"open_in_tab": true
},
"web_accessible_resources": ["browser/*", "common/*", "dep/*", "media/*", "mods/*"],
"web_accessible_resources": ["browser/*", "common/*", "vendor/*", "media/*", "mods/*"],
"content_scripts": [
{
"matches": ["https://*.notion.so/*", "https://*.notion.site/*"],

1
src/vendor/content-types.min.js vendored Normal file

File diff suppressed because one or more lines are too long

1
src/vendor/jscolor.min.js vendored Normal file

File diff suppressed because one or more lines are too long

9
src/vendor/lucide.min.js vendored Normal file

File diff suppressed because one or more lines are too long

7
src/vendor/twind.min.js vendored Normal file

File diff suppressed because one or more lines are too long