From b3c69fa6a48c94f729901787b21b8664fc5df7bf Mon Sep 17 00:00:00 2001 From: Alan Grainger Date: Sat, 21 Oct 2023 10:22:18 +0200 Subject: [PATCH 1/4] Update icons --- src/main.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.ts b/src/main.ts index 222535f..4724e26 100644 --- a/src/main.ts +++ b/src/main.ts @@ -220,7 +220,7 @@ export default class SharePlugin extends Plugin { let count = 0 const timer = setInterval(() => { count++ - if (count > 5) { + if (count > 8) { clearInterval(timer) return } @@ -259,7 +259,7 @@ export default class SharePlugin extends Plugin { valueEl.prepend(iconsEl) } }) - }, 100) + }, 50) } /** From c9b908258bd1b974f09d35c4de7894589cf5f941 Mon Sep 17 00:00:00 2001 From: Alan Grainger Date: Sat, 21 Oct 2023 14:27:49 +0200 Subject: [PATCH 2/4] Minify CSS --- package-lock.json | 43 +++++++++++++++++++++++++++++++++++++++++-- package.json | 3 ++- src/note.ts | 8 +++++--- 3 files changed, 48 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index b5710fc..b715725 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,14 +1,15 @@ { "name": "share-note", - "version": "0.5.22", + "version": "0.6.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "share-note", - "version": "0.5.22", + "version": "0.6.1", "license": "MIT", "dependencies": { + "csso": "^5.0.5", "data-uri-to-buffer": "^6.0.1" }, "devDependencies": { @@ -1084,6 +1085,31 @@ "node": ">= 8" } }, + "node_modules/css-tree": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/css-tree/-/css-tree-2.2.1.tgz", + "integrity": "sha512-OA0mILzGc1kCOCSJerOeqDxDQ4HOh+G8NbOJFOTgOCzpw7fCBubk0fEyxp8AgOL/jvLgYA/uV0cMbe43ElF1JA==", + "dependencies": { + "mdn-data": "2.0.28", + "source-map-js": "^1.0.1" + }, + "engines": { + "node": "^10 || ^12.20.0 || ^14.13.0 || >=15.0.0", + "npm": ">=7.0.0" + } + }, + "node_modules/csso": { + "version": "5.0.5", + "resolved": "https://registry.npmjs.org/csso/-/csso-5.0.5.tgz", + "integrity": "sha512-0LrrStPOdJj+SPCCrGhzryycLjwcgUSHBtxNA8aIDxf0GLsRh1cKYhB00Gd1lDOS4yGH69+SNn13+TWbVHETFQ==", + "dependencies": { + "css-tree": "~2.2.0" + }, + "engines": { + "node": "^10 || ^12.20.0 || ^14.13.0 || >=15.0.0", + "npm": ">=7.0.0" + } + }, "node_modules/data-uri-to-buffer": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-6.0.1.tgz", @@ -2530,6 +2556,11 @@ "node": ">=10" } }, + "node_modules/mdn-data": { + "version": "2.0.28", + "resolved": "https://registry.npmjs.org/mdn-data/-/mdn-data-2.0.28.tgz", + "integrity": "sha512-aylIc7Z9y4yzHYAJNuESG3hfhC+0Ibp/MAMiaOZgNv4pmEdFyfZhhhny4MNiAfWdBQ1RQ2mfDWmM1x8SvGyp8g==" + }, "node_modules/merge2": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", @@ -3057,6 +3088,14 @@ "node": ">=8" } }, + "node_modules/source-map-js": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.0.2.tgz", + "integrity": "sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/string.prototype.trim": { "version": "1.2.7", "resolved": "https://registry.npmjs.org/string.prototype.trim/-/string.prototype.trim-1.2.7.tgz", diff --git a/package.json b/package.json index 296bc10..8ab8704 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "typescript": "4.7.4" }, "dependencies": { - "data-uri-to-buffer": "^6.0.1" + "data-uri-to-buffer": "^6.0.1", + "csso": "^5.0.5" } } diff --git a/src/note.ts b/src/note.ts index 9e05db9..d3c4da1 100644 --- a/src/note.ts +++ b/src/note.ts @@ -7,6 +7,7 @@ import { ThemeMode, TitleSource, YamlField } from './settings' import { dataUriToBuffer } from 'data-uri-to-buffer' import FileTypes from './libraries/FileTypes' import { parseExistingShareUrl } from './api' +import { minify } from 'csso' const cssAttachmentWhitelist: { [key: string]: string[] } = { ttf: ['font/ttf', 'application/x-font-ttf', 'application/x-font-truetype', 'font/truetype'], @@ -381,13 +382,14 @@ export default class Note { this.status.setStatus('Uploading CSS attachments...') await this.plugin.api.processQueue(this.status, 'CSS attachment') this.status.setStatus('Uploading CSS...') - const cssHash = await sha1(this.css) + const minified = minify(this.css).css + const cssHash = await sha1(minified) try { await this.plugin.api.upload({ filetype: 'css', hash: cssHash, - content: this.css, - byteLength: this.css.length + content: minified, + byteLength: minified.length }) // Store the CSS theme in the settings From 04e271bd3b1b1e793c8708584174a2d27ac14ea5 Mon Sep 17 00:00:00 2001 From: Alan Grainger Date: Sat, 21 Oct 2023 20:31:27 +0200 Subject: [PATCH 3/4] csso types --- package-lock.json | 16 ++++++++++++++++ package.json | 5 +++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index b715725..c5b20e2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,7 @@ "data-uri-to-buffer": "^6.0.1" }, "devDependencies": { + "@types/csso": "^5.0.2", "@types/node": "^16.11.6", "@typescript-eslint/eslint-plugin": "5.29.0", "@typescript-eslint/parser": "5.29.0", @@ -538,6 +539,21 @@ "@types/tern": "*" } }, + "node_modules/@types/css-tree": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/@types/css-tree/-/css-tree-2.3.3.tgz", + "integrity": "sha512-w2id4lNf2DzAAQ+A3bD9QTY/qpCw9rYlci9RbBscEmF5RO3U/acrcCErvsqkoIZqz9n0yv4CVUqz/6DKDOEZnw==", + "dev": true + }, + "node_modules/@types/csso": { + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/@types/csso/-/csso-5.0.2.tgz", + "integrity": "sha512-4rX9xyR3Fk7hCbFvneunO74kfA6hgkc8vDW8LnzFrMHU+mqoMmsG7WtD1YAuHw/zhJHHQPfGxFf04Ypmnpyd5w==", + "dev": true, + "dependencies": { + "@types/css-tree": "*" + } + }, "node_modules/@types/estree": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.1.tgz", diff --git a/package.json b/package.json index 8ab8704..fb23839 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "author": "Alan Grainger", "license": "MIT", "devDependencies": { + "@types/csso": "^5.0.2", "@types/node": "^16.11.6", "@typescript-eslint/eslint-plugin": "5.29.0", "@typescript-eslint/parser": "5.29.0", @@ -24,7 +25,7 @@ "typescript": "4.7.4" }, "dependencies": { - "data-uri-to-buffer": "^6.0.1", - "csso": "^5.0.5" + "csso": "^5.0.5", + "data-uri-to-buffer": "^6.0.1" } } From 6e891abde15bab0cabc36ecdfcd44e3c69139b94 Mon Sep 17 00:00:00 2001 From: Alan Grainger Date: Sun, 22 Oct 2023 14:21:47 +0200 Subject: [PATCH 4/4] Fix bug with reading line length sometimes not parsed --- src/main.ts | 10 +++++----- src/note.ts | 14 ++++++++------ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/main.ts b/src/main.ts index 4724e26..5413a95 100644 --- a/src/main.ts +++ b/src/main.ts @@ -59,11 +59,6 @@ export default class SharePlugin extends Plugin { } }) - // Add share icons to properties panel - this.registerEvent(this.app.workspace.on('active-leaf-change', () => { - this.addShareIcons() - })) - // Add command - Share note this.addCommand({ id: 'share-note', @@ -120,6 +115,11 @@ export default class SharePlugin extends Plugin { } }) ) + + // Add share icons to properties panel + this.registerEvent(this.app.workspace.on('active-leaf-change', () => { + this.addShareIcons() + })) } onunload () { diff --git a/src/note.ts b/src/note.ts index d3c4da1..597a0bb 100644 --- a/src/note.ts +++ b/src/note.ts @@ -72,18 +72,19 @@ export default class Note { const previewMode = this.leaf.getViewState() previewMode.state.mode = 'preview' await this.leaf.setViewState(previewMode) + await new Promise(resolve => setTimeout(resolve, 40)) // Scroll the view to the top to ensure we get the default margins for .markdown-preview-pusher // @ts-ignore // 'view.previewMode' this.leaf.view.previewMode.applyScroll(0) - this.status.setStatus('Processing note...') + await new Promise(resolve => setTimeout(resolve, 40)) try { + // @ts-ignore - view.modes + const renderer = this.leaf.view.modes.preview.renderer // Copy classes and styles this.elements.push(getElementStyle('html', document.documentElement)) this.elements.push(getElementStyle('body', document.body)) - const previewEl = this.leaf.view.containerEl.querySelector('.markdown-preview-view.markdown-rendered') - if (previewEl) this.elements.push(getElementStyle('preview', previewEl as HTMLElement)) - const pusherEl = this.leaf.view.containerEl.querySelector('.markdown-preview-pusher') - if (pusherEl) this.elements.push(getElementStyle('pusher', pusherEl as HTMLElement)) + this.elements.push(getElementStyle('preview', renderer.previewEl)) + this.elements.push(getElementStyle('pusher', renderer.pusherEl)) this.contentDom = new DOMParser().parseFromString(await this.querySelectorAll(this.leaf.view), 'text/html') this.cssRules = [] Array.from(document.styleSheets) @@ -101,8 +102,9 @@ export default class Note { // Reset the view to the original mode // The timeout is required, even though we 'await' the preview mode setting earlier - setTimeout(() => { this.leaf.setViewState(startMode) }, 400) + setTimeout(() => { this.leaf.setViewState(startMode) }, 200) + this.status.setStatus('Processing note...') const file = this.plugin.app.workspace.getActiveFile() if (!(file instanceof TFile)) { // No active file