diff --git a/docs/TOOLS.md b/docs/TOOLS.md index 33dd7d6b9..6e02835e4 100644 --- a/docs/TOOLS.md +++ b/docs/TOOLS.md @@ -438,7 +438,11 @@ spec/north-star.md or docs/NAME.md of a project: one local commit authored by th business's human, refused `stale-base` if the file changed since the editor opened it. It is the human bus verb `project.file.save` through the human transport; an agent refuses it. Nothing is pushed. Without `--send` the page reads and previews only. See -`packages/webui/README.md` ("Spec and docs editor"). A save of spec/north-star.md also +`packages/webui/README.md` ("Spec and docs editor"). The page opens in a visual editor +built from reviewable source (row 154): `third_party/editor/` is unmodified upstream +source with its licenses and `PROVENANCE.json`, and `npm run build:editor` in +`packages/webui` rebuilds `src/public/editor.js` and `editor.css` with esbuild 0.28.2; +the save, the verb and the routes are unchanged. See "Visual editor" there. A save of spec/north-star.md also sends the business's pm and cto one notice naming the commit (row 143); a BLOCK from either goes to the chief of staff and on to the assistant. See `packages/bus/README.md` ("Spec review notices"). diff --git a/packages/webui/README.md b/packages/webui/README.md index 203325059..6bfc117dd 100644 --- a/packages/webui/README.md +++ b/packages/webui/README.md @@ -486,9 +486,11 @@ never loaded. Each render has a look-ahead budget of 32 characters examined per character of text (at least 1 Mi): an opener with no closer searches at most 2000 characters, and the budget caps the total over a whole file. Once it is spent, every later link, image, code span and emphasis shows as its source text, so a hostile file -can slow the editor by a fixed multiple of its length and no more. Nothing is vendored -and the Content-Security-Policy is unchanged; the choice against a bundled editor is -recorded in `agents/researcher/work/queue-148/LIBRARY.md`. +can slow the editor by a fixed multiple of its length and no more. The preview vendors +nothing and the Content-Security-Policy is unchanged; the choice against a bundled editor +is recorded in `agents/researcher/work/queue-148/LIBRARY.md`. Row 154 later added one, +for the page's default view; this textarea and preview are now its Source view (see +"Visual editor"). Routes: GET `/api/project-files?project=` and GET `/api/project-file?project=&path=` run the human transport like the other reads (400 for a bad query, 503 with no bus, 502 @@ -506,7 +508,61 @@ outcome, never the content. Tests: `project-file.test.mjs` (the routes), `markdown-preview.test.mjs` (the sink check, each element, the scheme rules, the look-ahead budget) and `docs-browser.test.mjs` (markdown with ` diff --git a/packages/webui/src/serve.mjs b/packages/webui/src/serve.mjs index 5635bd72c..1c7c2edcd 100644 --- a/packages/webui/src/serve.mjs +++ b/packages/webui/src/serve.mjs @@ -24,6 +24,8 @@ const files = new Map([ ['/', ['index.html', 'text/html; charset=utf-8']], ...['app.js', 'brand.js', 'bus.js', 'markdown-preview.js', 'chat.js'].map(f => ['/' + f, [f, 'text/javascript; charset=utf-8']]), ...['shared/app.css', 'tokens.css', 'console.css', 'live.css', 'bus.css', 'shell.css', 'chat.css'].map(f => ['/' + f, [f, 'text/css; charset=utf-8']]), + ['/editor.js', ['editor.js', 'text/javascript; charset=utf-8']], + ['/editor.css', ['editor.css', 'text/css; charset=utf-8']], ['/icons.svg', ['icons.svg', 'image/svg+xml']], ...[400, 500, 600, 700].map(w => [`/assets/fonts/manrope-${w}.woff2`, [`assets/fonts/manrope-${w}.woff2`, 'font/woff2']]), ...[400, 500, 700].map(w => [`/assets/fonts/jetbrains-mono-${w}.woff2`, [`assets/fonts/jetbrains-mono-${w}.woff2`, 'font/woff2']]), diff --git a/packages/webui/tests/browser.test.mjs b/packages/webui/tests/browser.test.mjs index 061216857..4a600817d 100644 --- a/packages/webui/tests/browser.test.mjs +++ b/packages/webui/tests/browser.test.mjs @@ -18,7 +18,8 @@ test('served Console browser: real board fixtures, keyboard, drafts, receipts, t assert.equal(await b.evaluate('document.querySelector("#session-count").textContent'), '3 of 4'); await b.evaluate('document.querySelector("#hide-offline").click()'); assert.equal(await b.evaluate('document.querySelectorAll("table.sessions tbody tr").length'), 4); - assert.equal(await b.evaluate('document.querySelectorAll("script").length'), 5); + // Rows 129 and 154: chat.js and editor.js are the scripts added, same origin; the list is the pin, so another script is a visible change. + assert.deepEqual(await b.evaluate('[...document.querySelectorAll("script")].map(s => s.getAttribute("src"))'), ['/editor.js', '/brand.js', '/app.js', '/markdown-preview.js', '/chat.js', '/bus.js']); assert.equal(await b.evaluate(`document.querySelectorAll('script[src="/chat.js"]').length`), 1); assert.equal(await b.evaluate('!!window.injected'), false); // Project filtering does not hide another project's waiting requests. diff --git a/packages/webui/tests/docs-browser.test.mjs b/packages/webui/tests/docs-browser.test.mjs index fbbd2ff9f..77c192b3e 100644 --- a/packages/webui/tests/docs-browser.test.mjs +++ b/packages/webui/tests/docs-browser.test.mjs @@ -60,7 +60,13 @@ test('the editor: the list, hostile markdown that runs nothing, the draft, and e const set = (sel, v) => b.evaluate(`(()=>{const e=document.querySelector(${JSON.stringify(sel)});e.value=${JSON.stringify(v)};e.dispatchEvent(new Event('input',{bubbles:true}));return true})()`); const answer = a => b.evaluate(`window.__answers.push(${JSON.stringify(a)}), true`); const saves = () => b.evaluate('window.__saves'); - const open = async path => { await b.evaluate(`location.hash = '#/docs/stack/' + encodeURIComponent(${JSON.stringify(path)}), true`); await wait(`document.querySelector("#doc-text") && document.querySelector("#doc-commit") && !document.querySelector("#bus-view [aria-busy]")`); }; + // Row 154: a page opens in the visual editor; every row 148 check below drives the Source view. + const source = async () => { + await wait('document.querySelector("#doc-commit")?.textContent !== "" && document.querySelector("#doc-commit") && !document.querySelector("#bus-view [aria-busy]")'); + if (!await b.evaluate('!!document.querySelector("#doc-text")')) await b.evaluate('document.querySelector("#doc-mode-source").click(), true'); + await wait('document.querySelector("#doc-text") && document.querySelector("#doc-commit") && document.querySelector("#doc-commit").textContent !== "" && !document.querySelector("#bus-view [aria-busy]")'); + }; + const open = async path => { await b.evaluate(`location.hash = '#/docs/stack/' + encodeURIComponent(${JSON.stringify(path)}), true`); await source(); }; const save = async () => { await b.evaluate('document.querySelector("#doc-save").click(), true'); await wait('document.querySelector("#doc-status").textContent !== "" && document.querySelector("#doc-status").textContent !== "Saving…"'); }; const PATH = 'spec/north-star.md'; try { @@ -74,7 +80,7 @@ test('the editor: the list, hostile markdown that runs nothing, the draft, and e Object.keys(files).map(p => [p, `#/docs/stack/${encodeURIComponent(p)}`])); assert.equal(await b.evaluate('document.querySelector("#sections a[aria-current=page]").textContent.trim()'), 'Docs'); await b.evaluate('document.querySelector("#bus-view ul a").click(), true'); - await wait('document.querySelector("#doc-text")'); + await source(); assert.equal(await text('#bus-view h1'), `Edit ${PATH}`); assert.deepEqual(reads.file, [{ project: 'stack', path: PATH }]); @@ -232,7 +238,7 @@ test('the editor: the list, hostile markdown that runs nothing, the draft, and e // Without edit in /api/config the source is read-only and Save is off. await b.navigate(`${base}?noedit#/docs/stack/${encodeURIComponent('docs/plain.md')}`); - await wait('document.querySelector("#doc-text") && !document.querySelector("#bus-view [aria-busy]")'); + await source(); assert.equal(await b.evaluate('document.querySelector("#doc-text").readOnly'), true); assert.equal(await b.evaluate('document.querySelector("#doc-save").disabled'), true); assert.match(await text('#bus-view'), /Saving needs a Console started with --send/); @@ -240,7 +246,7 @@ test('the editor: the list, hostile markdown that runs nothing, the draft, and e // The first paint of a page whose preview throws: the same message, the source shown, no unhandled rejection. await b.navigate(`${base}?throwrender#/docs/stack/${encodeURIComponent(PATH)}`); - await wait('document.querySelector("#doc-text") && document.querySelector("#doc-commit")?.textContent !== "" && !document.querySelector("#bus-view [aria-busy]")'); + await source(); assert.equal(await text('#doc-preview'), FAILED); assert.equal(await value('#doc-text'), HOSTILE); assert.equal(await text('#doc-commit'), C1.slice(0, 12)); diff --git a/packages/webui/tests/editor-browser.test.mjs b/packages/webui/tests/editor-browser.test.mjs new file mode 100644 index 000000000..869c74db9 --- /dev/null +++ b/packages/webui/tests/editor-browser.test.mjs @@ -0,0 +1,503 @@ +// Row 154 (#1648, Q168): the visual editor in a browser, under the Console's own Content-Security-Policy. +// Same harness as docs-browser.test.mjs: a script added before the page loads answers /api/config with edit +// on and records each POST /api/project-file, and the reads go to the real routes with stubbed bus answers. +// Row 148's checks (the Source view, the save receipts) are docs-browser.test.mjs's and run unchanged there. +import { test } from 'node:test'; +import assert from 'node:assert/strict'; +import { startServer } from '../src/serve.mjs'; +import { browser } from './browser.mjs'; +import { fixture, close } from './fixture.mjs'; +import { EVERY } from './helpers/every-element.mjs'; + +const C1 = '1'.repeat(40), C2 = '2'.repeat(40); +const HOSTILE = [ + '# Title', '', + '', + '', '', + '[click](javascript:window.injected=3) [data](data:text/html,) [ok](https://example.com/a)', '', + '[evil](//evil.example/x)', '', + '[sp](https://a b.example/)', '', + '![pixel](https://tracker.example/p.png)', '', + '![svg](data:image/svg+xml,)', '', + '', '', + '``', '', + '```', '', '```', '', +].join('\n'); +const MIX = '# Title\n\nFirst para.\n\n| a | b |\n|---|---|\n| 1 | 2 |\n\nLast para.\n'; +const files = { 'docs/hostile.md': HOSTILE, 'docs/every.md': EVERY, 'docs/mix.md': MIX, 'docs/empty.md': '', 'docs/tilde.md': '~~~a`b\ncode\n~~~\n' }; + +const STUB = `(() => { + const real = window.fetch.bind(window); + window.__saves = []; window.__answers = []; window.__rejections = []; window.__csp = []; window.__errors = []; + addEventListener('unhandledrejection', e => window.__rejections.push(String(e.reason?.message ?? e.reason))); + addEventListener('securitypolicyviolation', e => window.__csp.push(e.violatedDirective + ' ' + e.blockedURI)); + addEventListener('error', e => window.__errors.push(String(e.message))); + window.fetch = async (url, init = {}) => { + const u = String(url); + if (u === '/api/config') { + const c = await (await real(url, init)).json(); + return new Response(JSON.stringify({ ...c, send: !location.search.includes('noedit'), edit: !location.search.includes('noedit') }), { headers: { 'content-type': 'application/json' } }); + } + if (u !== '/api/project-file' || init.method !== 'POST') return real(url, init); + window.__saves.push({ body: init.body }); + const a = window.__answers.shift(); + if (!a) throw new TypeError('no answer queued'); + return new Response(JSON.stringify(a.body), { status: a.status, headers: { 'content-type': 'application/json' } }); + }; +})();`; + +// One page over the fixture server, with the helpers every test here uses. +async function session(run) { + const reads = []; + const f = await fixture(), b = await browser(); + const web = await startServer({ + port: 0, board: f.boardURL, + reads: { business: async () => ({ business: { id: 'demo', human: 'jason', projects: ['stack'] } }) }, + projectFiles: async () => ({ head: C1, files: Object.keys(files).map(path => ({ path })) }), + projectFile: async args => { reads.push(args.path); return { path: args.path, head: C1, commit: C1, content: files[args.path], author: 'jason', at: '2026-10-16T00:00:00Z' }; }, + }); + const base = `http://127.0.0.1:${web.address().port}/`; + const wait = (expr, tries = 100) => b.evaluate(`(async()=>{for(let i=0;i<${tries};i++){if(${expr})return true;await new Promise(r=>setTimeout(r,50))}throw new Error('Condition timed out: '+${JSON.stringify(expr)})})()`); + const h = { + b, base, wait, + reads, + q: expr => b.evaluate(expr), + open: async (path, query = '') => { + await b.navigate(`${base}${query}#/docs/stack/${encodeURIComponent(path)}`); + await wait('document.querySelector("#doc-commit") && !document.querySelector("#bus-view [aria-busy]")'); + }, + pm: () => wait('document.querySelector("#doc-visual .ProseMirror")'), + answer: a => b.evaluate(`window.__answers.push(${JSON.stringify(a)}), true`), + // What the page holds that must stay empty, whatever else a test does. + quiet: async () => assert.deepEqual(await b.evaluate('({ csp: window.__csp, errors: window.__errors, rejections: window.__rejections, injected: window.injected ?? null })'), + { csp: [], errors: [], rejections: [], injected: null }), + // The editor's inert-ness: nothing in it can run or load. + inert: () => b.evaluate(`(() => { const p = document.querySelector('#doc-visual .ProseMirror'); return { + // prosemirror-view's own src-less (a cursor hack after a non-editable node) is not content + bad: [...p.querySelectorAll('script, img, iframe, object, embed, style, link, form, svg, video, audio, source, base, meta')].filter(e => !e.matches('img.ProseMirror-separator:not([src])')).map(e => e.localName), + handlers: [...p.querySelectorAll('*')].filter(e => [...e.attributes].some(a => /^on/i.test(a.name))).length, + links: [...p.querySelectorAll('a')].map(a => [a.getAttribute('href'), a.getAttribute('rel'), a.getAttribute('target')]), + hrefs: [...p.querySelectorAll('[href], [src], [srcset], [data], [action], [formaction]')].filter(e => e.localName !== 'a').length, + fetched: performance.getEntriesByType('resource').map(r => r.name).filter(n => /tracker\\.example|evil\\.example/.test(n)), + injected: window.injected ?? null }; })()`), + save: async () => { + await b.evaluate('document.querySelector("#doc-save").click(), true'); + await wait('document.querySelector("#doc-status").textContent.startsWith("Saved")'); + }, + saved: async () => (await b.evaluate('window.__saves')).map(s => JSON.parse(s.body)), + done: async () => { await b.close(); await close(web); await f.close(); }, + }; + try { await b.call('Page.addScriptToEvaluateOnNewDocument', { source: STUB }); await b.viewport(1280); await run(h); } finally { await h.done(); } +} + +test('the Console\'s CSP stands and the editor runs under it; hostile markdown on the load path runs and loads nothing', { timeout: 120000 }, async () => { + await session(async h => { + const csp = (await fetch(h.base)).headers.get('content-security-policy'); + assert.match(csp, /(^|; )script-src 'self'(;|$)/); + assert.doesNotMatch(csp, /unsafe-eval|script-src[^;]*unsafe-inline|data:|blob:/); + + await h.open('docs/hostile.md'); + await h.pm(); + assert.equal(await h.q('document.querySelector("#doc-mode-visual").getAttribute("aria-pressed")'), 'true', 'a page opens in the visual editor'); + assert.equal(await h.q('!!document.querySelector("#doc-text")'), false); + assert.equal(await h.q('typeof window.MosaicEditor.mount'), 'function', 'editor.js ran under script-src self'); + assert.equal(await h.q('getComputedStyle(document.querySelector(".ed-toolbar")).display'), 'flex', 'editor.css applied'); + const view = await h.inert(); + assert.deepEqual(view.bad, []); + assert.equal(view.handlers, 0); + assert.equal(view.hrefs, 0); + assert.deepEqual(view.fetched, []); + assert.equal(view.injected, null); + // markdown-it itself makes no link of a javascript: or a data: target, so those stay text; the paragraph holding them + // is not a refused block, and its one good link is a real link. A target markdown-it accepts but the gate refuses + // (`//evil.example/x`) makes its whole block a source block; a target with a space is no link to markdown-it at all. + assert.deepEqual(view.links, [['https://example.com/a', 'noopener noreferrer', '_blank']], 'the one good link is the only anchor on the page'); + const shown = await h.q('document.querySelector("#doc-visual .ProseMirror").textContent'); + assert.ok(shown.includes('') && shown.includes('javascript:window.injected=3') && shown.includes('data:text/html') && shown.includes('https://tracker.example/p.png'), 'what the file says shows as text'); + assert.equal(await h.q('[...document.querySelectorAll("#doc-visual .ProseMirror pre.md-raw")].some(e => e.textContent.includes("[evil](//evil.example/x)"))'), true, 'a target the gate refuses leaves its block as source text'); + assert.ok(shown.includes('[sp](https://a b.example/)'), 'a target with a space stays text'); + // typing works under the policy: an edit changes the draft and turns Save on + await h.q('(() => { const p = document.querySelector("#doc-visual .ProseMirror"); p.focus(); getSelection().selectAllChildren(p); getSelection().collapseToEnd(); return true; })()'); + await h.b.call('Input.insertText', { text: 'typed' }); + await h.wait('!document.querySelector("#doc-save").disabled'); + await h.quiet(); + + // a doc with every element: nothing in it runs, and a file's own links the gate accepts are real links + await h.open('docs/every.md'); + await h.pm(); + const every = await h.inert(); + assert.deepEqual([every.bad, every.handlers, every.hrefs, every.fetched, every.injected], [[], 0, 0, [], null]); + for (const [href, rel, target] of every.links) { + assert.match(href, /^(https:\/\/|http:\/\/|[^:]*$)/, `a link target the gate accepts: ${href}`); + assert.equal(rel, 'noopener noreferrer'); + assert.equal(target, '_blank'); + } + assert.ok(every.links.some(([href]) => href === 'https://example.com/a'), 'a plain https link is a link'); + assert.equal(await h.q('!document.querySelector("#doc-visual .ProseMirror a[href^=javascript i], #doc-visual .ProseMirror a[href^=data i]")'), true); + // open and save with no edit: nothing to save, and the editor holds the file's own bytes + assert.equal(await h.q('document.querySelector("#doc-save").disabled'), true); + assert.equal(await h.q(`window.MosaicEditor.roundTrip(${JSON.stringify(files['docs/every.md'])}) === ${JSON.stringify(files['docs/every.md'])}`), true); + await h.quiet(); + + // an empty file opens, and the same page read-only has no toolbar, no editing and no save + await h.open('docs/empty.md'); + await h.pm(); + await h.open('docs/mix.md', '?noedit'); + await h.pm(); + assert.equal(await h.q('document.querySelector("#doc-visual .ProseMirror").getAttribute("contenteditable")'), 'false'); + assert.equal(await h.q('!!document.querySelector(".ed-toolbar")'), false); + assert.equal(await h.q('document.querySelector("#doc-save").disabled'), true); + await h.quiet(); + }); +}); + +test('hostile content pasted into the editor runs and loads nothing, and a bad link target is refused in the link bar', { timeout: 120000 }, async () => { + await session(async h => { + await h.open('docs/mix.md'); + await h.pm(); + const paste = (html, plain) => h.q(`(() => { + const p = document.querySelector('#doc-visual .ProseMirror'); p.focus(); + getSelection().selectAllChildren(p); getSelection().collapseToEnd(); + const dt = new DataTransfer(); + ${html == null ? '' : `dt.setData('text/html', ${JSON.stringify(html)});`} + ${plain == null ? '' : `dt.setData('text/plain', ${JSON.stringify(plain)});`} + p.dispatchEvent(new ClipboardEvent('paste', { clipboardData: dt, bubbles: true, cancelable: true })); + return true; })()`); + const HTML = [ + '

pasted

', + '', + '', + '

js', + 'data', + 'space', + 'proto-relative', + 'ok', + 'rel

', + '

img', + 'img', + 'img

', + '', + '', + '', + '
', + '
styled
', + ].join(''); + await paste(HTML, '[x](javascript:window.injected=22) '); + await h.wait('document.querySelector("#doc-visual .ProseMirror").textContent.includes("pasted")'); + const view = await h.inert(); + assert.deepEqual(view.bad, [], 'no script, image, frame, object, style or form came in'); + assert.equal(view.handlers, 0); + assert.equal(view.hrefs, 0); + assert.deepEqual(view.fetched, []); + assert.equal(view.injected, null); + assert.deepEqual(view.links.map(l => l[0]).sort(), ['../docs/rel.md', 'https://ok.example/p'], 'only targets the gate accepts became links'); + for (const [, rel, target] of view.links) assert.deepEqual([rel, target], ['noopener noreferrer', '_blank']); + assert.equal(await h.q('document.querySelector("#doc-visual .ProseMirror [style*=url]")'), null, 'no style attribute came in'); + // pasting plain text that looks like markup or a link leaves it as text + await paste(null, '[x](javascript:window.injected=24) ![i](https://tracker.example/z.png)'); + await h.wait('document.querySelector("#doc-visual .ProseMirror").textContent.includes("window.injected=25")'); + const plain = await h.inert(); + assert.deepEqual([plain.bad, plain.handlers, plain.fetched, plain.injected], [[], 0, [], null]); + assert.ok(!plain.links.some(l => /javascript/i.test(l[0]))); + // what the save writes holds no live script, frame or image from the paste: only text, escaped + await h.answer({ status: 200, body: { path: 'docs/mix.md', commit: C2, at: '2026-10-16T01:00:00Z' } }); + await h.save(); + const [{ content }] = await h.saved(); + // A bracket that survives is escaped (`\<`), so it is text on the next load. A link or image survives only with a + // target the gate accepts: the two links and the one https image the paste carried (written as text, never + // fetched), and no javascript: or data: target anywhere. + assert.doesNotMatch(content.replace(/\\ m[1]).sort(), ['../docs/rel.md', 'https://ok.example/p', 'https://tracker.example/q.png']); + assert.doesNotMatch(content, /(? { const p = [...document.querySelectorAll('#doc-visual .ProseMirror p')].find(e => e.textContent === 'First para.'); + p.parentElement.focus(); const r = document.createRange(); r.setStart(p.firstChild, 0); r.setEnd(p.firstChild, 5); const s = getSelection(); s.removeAllRanges(); s.addRange(r); return true; })()`); + await h.wait('(() => { const s = getSelection(); return s.toString() === "First"; })()'); + await h.q('document.querySelector(".ed-btn[data-cmd=link]").click(), true'); + await h.wait('!document.querySelector(".ed-linkbar").hidden'); + const setLink = async target => { + await h.q(`(() => { const i = document.querySelector('.ed-link-input'); i.value = ${JSON.stringify(target)}; i.form.requestSubmit(); return true; })()`); + }; + for (const bad of ['javascript:window.injected=30', 'JaVaScRiPt:window.injected=31', 'data:text/html,x', ' javascript:x', '//evil.example/x', 'vbscript:x', 'https://a b.example/']) { + await setLink(bad); + await h.wait('document.querySelector(".ed-link-note").textContent.includes("not allowed")'); + assert.equal(await h.q('document.querySelectorAll("#doc-visual .ProseMirror a").length'), 0, `${bad} made no link`); + assert.equal(await h.q('document.querySelector(".ed-linkbar").hidden'), false, 'the bar stays open and says why'); + await h.q('document.querySelector(".ed-link-note").textContent = "", true'); + } + await setLink('https://ok.example/page'); + await h.wait('document.querySelectorAll("#doc-visual .ProseMirror a").length === 1'); + assert.deepEqual(await h.q('[...document.querySelectorAll("#doc-visual .ProseMirror a")].map(a => [a.getAttribute("href"), a.getAttribute("rel"), a.getAttribute("target"), a.textContent])'), + [['https://ok.example/page', 'noopener noreferrer', '_blank', 'First']]); + await h.quiet(); + }); +}); + +// Mos's text said an image becomes text; this row also gates a pasted image span (span.md-image[data-src], the editor's own +// copy format) on the link gate, so a target the gate refuses never becomes an image node, and none can reach a save. +test('a pasted image span is kept only for a target the link gate accepts, and a save writes only those', { timeout: 120000 }, async () => { + await session(async h => { + await h.open('docs/mix.md'); + await h.pm(); + const ACCEPTED = [['a', 'https://ok.example/a.png'], ['r', '../img/r.png']]; + const REFUSED = ['data:image/png;base64,AAAA', 'javascript:window.injected=40', '//evil.example/i.png', ' javascript:window.injected=41', 'vbscript:x', 'https://a b.example/i.png', 'DATA:image/gif;base64,AAAA']; + const HTML = [...ACCEPTED.map(([alt, src]) => `

kept-${alt} x

`), + ...REFUSED.map((src, i) => `

refused-${i} x

`)].join(''); + await h.q(`(() => { + const p = document.querySelector('#doc-visual .ProseMirror'); p.focus(); + getSelection().selectAllChildren(p); getSelection().collapseToEnd(); + const dt = new DataTransfer(); dt.setData('text/html', ${JSON.stringify(HTML)}); + p.dispatchEvent(new ClipboardEvent('paste', { clipboardData: dt, bubbles: true, cancelable: true })); + return true; })()`); + await h.wait(`document.querySelector("#doc-visual .ProseMirror").textContent.includes("refused-${REFUSED.length - 1}")`); + // in the editor: an image node for each accepted target, drawn as text, and for no refused one + const atoms = await h.q('[...document.querySelectorAll("#doc-visual .ProseMirror .md-image")].map(e => [e.getAttribute("data-src"), e.getAttribute("data-alt"), e.localName, e.textContent])'); + assert.deepEqual(atoms.map(a => a.slice(0, 3)), ACCEPTED.map(([alt, src]) => [src, alt, 'span']), 'image nodes for the accepted targets only'); + assert.deepEqual(atoms.map(a => a[3]), ACCEPTED.map(([alt, src]) => `[image: ${alt}] ${src}`), 'drawn as text'); + const refusedText = await h.q('document.querySelector("#doc-visual .ProseMirror").textContent'); + for (let i = 0; i < REFUSED.length; i++) assert.ok(refusedText.includes(`refused-${i}`), `the text around refused target ${i} is kept`); + for (const src of REFUSED) assert.ok(!refusedText.includes(src.trim()), `${src} is nowhere in the editor`); + const view = await h.inert(); + assert.deepEqual([view.bad, view.handlers, view.hrefs, view.fetched, view.injected], [[], 0, 0, [], null]); + // a save: an image for each accepted target, written as markdown, and no refused target anywhere + await h.answer({ status: 200, body: { path: 'docs/mix.md', commit: C2, at: '2026-10-16T01:00:00Z' } }); + await h.save(); + const [{ content }] = await h.saved(); + assert.deepEqual([...content.matchAll(/!\[([^\]]*)\]\(([^)\s]*)\)/g)].map(m => [m[1], m[2]]), ACCEPTED, 'saved images: the accepted targets, in order'); + for (const src of REFUSED) assert.ok(!content.includes(src.trim()), `${src} is not in the saved file`); + assert.doesNotMatch(content, /javascript:|vbscript:|data:image|evil\.example/i); + for (let i = 0; i < REFUSED.length; i++) assert.ok(content.includes(`refused-${i}`), `the text around refused target ${i} is saved as text`); + await h.quiet(); + }); +}); + +// A switch of view reuses the draft it holds; everything else that opens a file still reads it, once each. +test('a switch of view reads nothing; a reload, and a trip away and back, each read the file exactly once', { timeout: 120000 }, async () => { + await session(async h => { + const settle = () => h.q('new Promise(r => setTimeout(r, 300)).then(() => true)'); + const mix = () => h.reads.filter(p => p === 'docs/mix.md').length; + await h.open('docs/mix.md'); + await h.pm(); + // a cold load renders twice (the page draws again when /api/config answers), so count from what opening cost + await settle(); + const opened = mix(); + assert.ok(opened >= 1, 'opening reads the file'); + for (let i = 0; i < 2; i++) { + await h.q('document.querySelector("#doc-mode-source").click(), true'); + await h.wait('document.querySelector("#doc-text")'); + await h.q('document.querySelector("#doc-mode-visual").click(), true'); + await h.pm(); + } + await settle(); + assert.equal(mix(), opened, 'two round trips between the views read nothing'); + + // Reload from the project: one read, and a switch after it reads nothing more + await h.q('document.querySelector("#doc-reload").click(), true'); + await h.wait('document.querySelector("#doc-commit") && !document.querySelector("#bus-view [aria-busy]")'); + await h.pm(); + await settle(); + assert.equal(mix(), opened + 1, 'Reload reads once'); + await h.q('document.querySelector("#doc-mode-source").click(), true'); + await h.wait('document.querySelector("#doc-text")'); + await settle(); + assert.equal(mix(), opened + 1, 'a switch after Reload reads nothing'); + + // away and back: the draft is clean, so opening the file again reads it once + await h.q('location.hash = "#/docs", true'); + await h.wait('document.querySelector("#bus-view h1")?.textContent === "Docs" && !document.querySelector("#bus-view [aria-busy]")'); + await h.open('docs/mix.md'); + await settle(); + assert.equal(mix(), opened + 2, 'going away and back reads once'); + await h.quiet(); + }); +}); + +test('an edit rewrites only the block touched; a save sends the rest byte for byte; the Source view carries the draft',{ timeout: 120000 }, async () => { + await session(async h => { + await h.open('docs/mix.md'); + await h.pm(); + assert.equal(await h.q('document.querySelector("#doc-save").disabled'), true, 'open with no edit: nothing to save'); + // a table is drawn as a tinted source block, not a table + assert.equal(await h.q('document.querySelectorAll("#doc-visual .ProseMirror table").length'), 0); + assert.equal(await h.q('document.querySelectorAll("#doc-visual .ProseMirror pre.md-raw").length'), 1); + // type at the end of the first paragraph + await h.q(`(() => { const p = [...document.querySelectorAll('#doc-visual .ProseMirror p')].find(e => e.textContent === 'First para.'); + p.parentElement.focus(); const r = document.createRange(); r.setStart(p.firstChild, p.firstChild.length); r.collapse(true); const s = getSelection(); s.removeAllRanges(); s.addRange(r); return true; })()`); + await h.b.call('Input.insertText', { text: ' More **not bold**.' }); + await h.wait('!document.querySelector("#doc-save").disabled'); + // Save is on because the draft differs, so the editor must hold the typed text, and keep holding it until the click. + const typed = () => h.q('document.querySelector("#doc-visual .ProseMirror").textContent'); + assert.ok((await typed()).includes('First para. More **not bold**.'), 'the typed text is in the editor'); + await h.q('new Promise(r => setTimeout(r, 300)).then(() => true)'); + assert.equal(await h.q('document.querySelector("#doc-save").disabled'), false, 'Save stays on'); + assert.ok((await typed()).includes('First para. More **not bold**.'), 'the typed text is still in the editor'); + await h.answer({ status: 200, body: { path: 'docs/mix.md', commit: C2, at: '2026-10-16T01:00:00Z' } }); + await h.save(); + const [sent] = await h.saved(); + assert.deepEqual(Object.keys(sent).sort(), ['base', 'content', 'path', 'project'], 'the body row 148 sends'); + assert.deepEqual([sent.project, sent.path, sent.base], ['stack', 'docs/mix.md', C1]); + // the typed `**` is text, so it is escaped; the table, the heading and the last paragraph are untouched + assert.equal(sent.content, '# Title\n\nFirst para. More \\*\\*not bold\\*\\*.\n\n| a | b |\n|---|---|\n| 1 | 2 |\n\nLast para.\n'); + assert.equal(await h.q('document.querySelector("#doc-save").disabled'), true, 'saved, so nothing left to save'); + + // the Source view shows the draft as the editor would save it, with no new read of the project, and an edit there + // comes back to the visual view + const readsBefore = h.reads.length; + await h.q('document.querySelector("#doc-mode-source").click(), true'); + await h.wait('document.querySelector("#doc-text")'); + assert.equal(await h.q('document.querySelector("#doc-text").value'), sent.content); + assert.equal(h.reads.length, readsBefore, 'a switch of view reads nothing'); + await h.q(`(() => { const t = document.querySelector('#doc-text'); t.value = t.value.replace('Last para.', 'Final para.'); t.dispatchEvent(new Event('input', { bubbles: true })); return true; })()`); + await h.q('document.querySelector("#doc-mode-visual").click(), true'); + await h.pm(); + assert.ok((await h.q('document.querySelector("#doc-visual .ProseMirror").textContent')).includes('Final para.')); + assert.equal(await h.q('document.querySelector("#doc-save").disabled'), false); + assert.equal(h.reads.length, readsBefore, 'the switch back reads nothing either'); + + // toolbar and keys: bold with the key, a heading from the toolbar, a list from the markdown shortcut + await h.q(`(() => { const p = [...document.querySelectorAll('#doc-visual .ProseMirror p')].find(e => e.textContent === 'Final para.'); + p.parentElement.focus(); const r = document.createRange(); r.setStart(p.firstChild, 0); r.setEnd(p.firstChild, 5); const s = getSelection(); s.removeAllRanges(); s.addRange(r); return true; })()`); + await h.wait('getSelection().toString() === "Final"'); + await h.q('document.querySelector(".ed-btn[data-cmd=strong]").click(), true'); + await h.wait('document.querySelectorAll("#doc-visual .ProseMirror strong").length === 1'); + await h.q('document.querySelector(".ed-btn[data-cmd=h2]").click(), true'); + await h.wait('document.querySelectorAll("#doc-visual .ProseMirror h2").length === 1'); + await h.answer({ status: 200, body: { path: 'docs/mix.md', commit: '3'.repeat(40), at: '2026-10-16T02:00:00Z' } }); + await h.save(); + const second = (await h.saved())[1]; + assert.equal(second.content, '# Title\n\nFirst para. More \\*\\*not bold\\*\\*.\n\n| a | b |\n|---|---|\n| 1 | 2 |\n\n## **Final** para.\n'); + assert.equal(second.base, C2, 'the second save is based on the commit the first one made'); + await h.quiet(); + }); +}); + +test('a file the editor cannot write back byte for byte opens as Source, says so, cannot save, and the Visual button works once it can', { timeout: 120000 }, async () => { + await session(async h => { + const settle = () => h.q('new Promise(r => setTimeout(r, 300)).then(() => true)'); + const shown = () => h.q(`({ pm: !!document.querySelector('#doc-visual .ProseMirror'), text: document.querySelector('#doc-text')?.value ?? null, + note: document.querySelector('#bus-view')?.textContent.includes('The visual editor is not available for this file, so it is open as source.'), + pressed: [document.querySelector('#doc-mode-visual')?.getAttribute('aria-pressed'), document.querySelector('#doc-mode-source')?.getAttribute('aria-pressed')], + saveOff: document.querySelector('#doc-save')?.disabled })`); + const reload = async () => { await h.q('document.querySelector("#doc-reload").click(), true'); await h.wait('document.querySelector("#doc-commit")?.textContent !== "" && !document.querySelector("#bus-view [aria-busy]")'); await settle(); }; + await h.open('docs/mix.md'); + await h.pm(); + assert.deepEqual((await shown()).pressed, ['true', 'false'], 'a plain file opens in the visual editor'); + + // roundTrip disagrees with the file: the gate refuses, whatever else the editor could do + await h.q(`(() => { const real = window.MosaicEditor; window.__rt = false; window.MosaicEditor = { mount: real.mount, roundTrip: t => window.__rt ? real.roundTrip(t) : t + ' ' }; return true; })()`); + await reload(); + assert.deepEqual(await shown(), { pm: false, text: MIX, note: true, pressed: ['false', 'true'], saveOff: true }, 'a failed round trip shows the source, the note and a Save that is off'); + // the screen shows Source, so the Visual button must act: once the file round-trips it opens the editor with no new read + await h.q('window.__rt = true, true'); + const reads = h.reads.length; + await h.q('document.querySelector("#doc-mode-visual").click(), true'); + await h.pm(); + assert.deepEqual((await shown()).pressed, ['true', 'false'], 'Visual works from a fallback'); + assert.equal(h.reads.length, reads, 'the switch reads nothing'); + // the preference is not lost: the next fallback is a fallback again, not the Source the user never picked + await h.q('window.__rt = false, true'); + await reload(); + assert.equal((await shown()).pm, false); + + // no editor script at all: the same page, the same note + await h.q('window.MosaicEditor = undefined, true'); + await reload(); + assert.deepEqual(await shown(), { pm: false, text: MIX, note: true, pressed: ['false', 'true'], saveOff: true }, 'without window.MosaicEditor the page is Source with the note'); + await h.q('document.querySelector("#doc-mode-visual").click(), true'); + await settle(); + assert.deepEqual(await shown(), { pm: false, text: MIX, note: true, pressed: ['false', 'true'], saveOff: true }, 'Visual with no editor stays Source'); + await h.quiet(); + }); +}); + +// Dewey's r1 finding: a link title, an image alt or title and a code block's info string are written into one line of +// Markdown, a paste can set any of them, and a line break in one saved a raw HTML block. Each of the four, on the paste path. +// (The editor's own reading of a file can give a single line break in a title or alt, never a blank line; see BUILD.md.) +const BREAK = 'T\n\n\n\n'; +// Each test first waits for the pasted node, holding the hostile value, to be in the editor's document (read from its DOM), +// so a paste that was dropped fails there and not as a missing string after Save. The
 comes between two paragraphs:
+// prosemirror-view opens the first and last node of a pasted slice (Slice.maxOpen), so a lone 
 joins the block the
+// cursor is in as plain text and sets no params; the paste here lands in the first block, the heading.
+const attrOf = v => v.replace(/&/g, '&').replace(/"/g, '"');
+// One paste, then Save: `value` is what the pasted node must hold in the document, `written` what the file must then contain.
+// With `reread`, the saved text is also opened by the editor's own reader (a second, read-only mount): the title must come
+// back as pasted and no tag may have come out as text of the document, which is what a renderer with raw HTML would run.
+function pasteTest(name, html, value, written, node, attr, headline = `${name} pasted with line breaks in it is written on one line, so no HTML block comes of it`, reread = false) {
+  test(headline, { timeout: 120000 }, async () => {
+    await session(async h => {
+      await h.open('docs/mix.md');
+      await h.pm();
+      await h.q(`(() => {
+        const p = document.querySelector('#doc-visual .ProseMirror'); p.focus();
+        getSelection().selectAllChildren(p); getSelection().collapseToEnd();
+        const dt = new DataTransfer(); dt.setData('text/html', ${JSON.stringify(html)});
+        p.dispatchEvent(new ClipboardEvent('paste', { clipboardData: dt, bubbles: true, cancelable: true }));
+        return true; })()`);
+      const sel = `#doc-visual .ProseMirror ${node}[${attr}]`;
+      await h.wait(`document.querySelector(${JSON.stringify(sel)})`);
+      assert.equal(await h.q(`document.querySelector(${JSON.stringify(sel)}).getAttribute(${JSON.stringify(attr)})`), value, 'the pasted node holds the hostile value in the document');
+      await h.wait('!document.querySelector("#doc-save").disabled');
+      await h.answer({ status: 200, body: { path: 'docs/mix.md', commit: C2, at: '2026-10-16T01:00:00Z' } });
+      await h.save();
+      const [{ content }] = await h.saved();
+      assert.ok(content.includes(written), `the value is written as ${JSON.stringify(written)} in ${JSON.stringify(content)}`);
+      assert.doesNotMatch(content, /^[ \t]* {
+          const host = document.createElement('div'); document.body.appendChild(host);
+          const ed = window.MosaicEditor.mount(host, { text: ${JSON.stringify(content)}, editable: false });
+          const titles = [];
+          ed.view.state.doc.descendants(n => { if (n.type.name === 'image') titles.push(n.attrs.title); for (const m of n.marks) if (m.type.name === 'link') titles.push(m.attrs.title); });
+          const text = ed.view.state.doc.textContent;
+          ed.destroy(); host.remove();
+          return { titles, text }; })()`);
+        assert.deepEqual(back.titles, [value], 'the saved title reads back as it was pasted');
+        assert.ok(!back.text.includes('word

`, '[word](https://ok.example/p "T ")', 'a[href="https://ok.example/p"]', 'title'], + ['an image alt', `

x

`, '![T ](https://ok.example/a.png)', 'span.md-image', 'data-alt'], + ['an image title', `

x

`, '![a](https://ok.example/a.png "T ")', 'span.md-image', 'data-title'], + ['a code block info string', `

x

code

y

`, '```T\ncode\n```', 'pre[data-params]', 'data-params'], +]) pasteTest(name, html, BREAK, written, node, attr); + +// Dewey's r2 finding: the title writers escaped `"` and not `\`. A title `x\") ` then ended its quotes early +// (the saved line re-read as a link titled `x\` followed by live inline HTML), and a title ending in `\` swallowed its own +// closing quote. Both shapes, for a link title and an image title, on the paste path. Written, each backslash is doubled +// and each quote gets its own backslash. +const ESCAPE = 'x\\") '; +const TRAILING = 'end\\'; +for (const [what, value, written] of [['a quote after a backslash then a tag', ESCAPE, 'x\\\\\\") '], ['a trailing backslash', TRAILING, 'end\\\\']]) { + pasteTest('a link title', `

word

`, value, `[word](https://ok.example/p "${written}")`, 'a[href="https://ok.example/p"]', 'title', + `a link title holding ${what} is written with the backslash escaped, so the title stays closed`, true); + pasteTest('an image title', `

x

`, value, `![a](https://ok.example/a.png "${written}")`, 'span.md-image', 'data-title', + `an image title holding ${what} is written with the backslash escaped, so the title stays closed`, true); +} + +// Filbert's g5: a backtick in a code block's info string ends the fence if written; the load side refuses it first (tilde +// fence, below), so only a paste reaches the save side. +pasteTest('a code block info string', '

x

code

y

', 'a`b', '```\ncode\n```', 'pre[data-params]', 'data-params', + 'a code block info string with a backtick, pasted, is dropped on Save, so the fence stays closed'); + +test('a code block info string with a backtick, as a tilde fence can have, is kept as source, not rewritten without it', { timeout: 120000 }, async () => { + await session(async h => { + await h.open('docs/tilde.md'); + await h.pm(); + assert.equal(await h.q('document.querySelectorAll("#doc-visual .ProseMirror pre.md-raw").length'), 1, 'the block is a source block'); + assert.ok((await h.q('document.querySelector("#doc-visual .ProseMirror pre.md-raw").textContent')).startsWith('~~~a`b')); + await h.quiet(); + }); +}); diff --git a/packages/webui/tests/editor-provenance.test.mjs b/packages/webui/tests/editor-provenance.test.mjs new file mode 100644 index 000000000..8cf12b611 --- /dev/null +++ b/packages/webui/tests/editor-provenance.test.mjs @@ -0,0 +1,173 @@ +// Row 154 (#1648, Q168): the imported editor source and the build. third_party/editor/ is upstream source +// copied byte for byte; this fails if one byte of it changes without a recorded local change, if a file is +// added or removed, or if the built bundle is not the build of that source. +import { test } from 'node:test'; +import assert from 'node:assert/strict'; +import { createHash } from 'node:crypto'; +import { spawnSync } from 'node:child_process'; +import { copyFileSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs'; +import { tmpdir } from 'node:os'; +import { dirname, join } from 'node:path'; +import { fileURLToPath, pathToFileURL } from 'node:url'; + +const webui = join(dirname(fileURLToPath(import.meta.url)), '..'); +const imported = join(webui, 'third_party/editor'); +const sha = buf => createHash('sha256').update(buf).digest('hex'); +const gitBlob = buf => createHash('sha1').update(Buffer.concat([Buffer.from(`blob ${buf.length}\0`), buf])).digest('hex'); +const provenance = JSON.parse(readFileSync(join(imported, 'PROVENANCE.json'), 'utf8')); +const build = JSON.parse(readFileSync(join(webui, 'editor/BUILD.json'), 'utf8')); + +const filesOnDisk = () => readdirSync(imported, { withFileTypes: true, recursive: true }) + .filter(e => e.isFile()).map(e => join(e.parentPath, e.name).slice(imported.length + 1)).filter(p => p !== 'PROVENANCE.json').sort(); +const treeOf = entries => sha(entries.sort((a, b) => (a[0] < b[0] ? -1 : 1)).map(([path, h]) => `${h} ${path}\n`).join('')); + +test('the imported source is the tagged upstream source plus the recorded local changes, and nothing else', () => { + assert.equal(provenance.schema, 1); + const changes = new Map(provenance.localChanges.map(c => [c.path, c])); + for (const c of changes.values()) assert.ok(c.path && /^[0-9a-f]{64}$/.test(c.sha256) && c.reason, `a local change names its path, its new sha256 and why: ${JSON.stringify(c)}`); + + // 1. The record names every file and the disk has exactly those. + const recorded = new Map([['NOTICE', provenance.notice.sha256]]); + for (const p of provenance.packages) { + assert.match(p.commit, /^[0-9a-f]{40}$/, `${p.name} commit`); + assert.match(p.upstreamTree, /^[0-9a-f]{40}$/, `${p.name} upstream tree`); + assert.ok(p.files[p.license], `${p.name} ships its license file ${p.license}`); + assert.ok(p.files['package.json'], `${p.name} ships its package.json`); + for (const [path, f] of Object.entries(p.files)) recorded.set(`${p.name}/${path}`, f.sha256); + } + assert.deepEqual(filesOnDisk(), [...recorded.keys()].sort(), 'files on disk against files recorded'); + + // 2. Each file is the recorded bytes: the upstream bytes, or the recorded local change. + const expected = []; + for (const p of provenance.packages) { + for (const [path, f] of Object.entries(p.files)) { + const key = `${p.name}/${path}`, buf = readFileSync(join(imported, key)); + const change = changes.get(key); + if (change) assert.equal(sha(buf), change.sha256, `${key} differs from its recorded local change`); + else { + assert.equal(sha(buf), f.sha256, `${key} differs from upstream and has no recorded local change`); + assert.equal(gitBlob(buf), f.blob, `${key} is not the git blob ${f.blob} of ${p.tag}`); + assert.equal(buf.length, f.bytes, key); + } + expected.push([key, change ? change.sha256 : f.sha256]); + } + } + for (const key of changes.keys()) assert.ok(recorded.has(key), `local change for ${key}, which is not an imported file`); + const notice = readFileSync(join(imported, 'NOTICE')); + assert.equal(sha(notice), provenance.notice.sha256, 'NOTICE'); + expected.push(['NOTICE', provenance.notice.sha256]); + + // 3. The tree hash: from the record, and from the bytes on disk. + assert.equal(treeOf(expected), provenance.tree.sha256, 'tree hash from the record'); + const fromDisk = filesOnDisk().map(p => [p, sha(readFileSync(join(imported, p)))]); + assert.equal(fromDisk.length, provenance.tree.files); + assert.equal(treeOf(fromDisk), provenance.tree.sha256, 'tree hash from the files on disk'); +}); + +test('every package names its origin and license, and NOTICE lists each', () => { + const notice = readFileSync(join(imported, 'NOTICE'), 'utf8'); + for (const p of provenance.packages) { + assert.match(p.origin, /^https:\/\//, p.name); + assert.ok(p.spdx && p.copyright.length, `${p.name} license id and copyright line`); + assert.ok(notice.includes(`${p.name} ${p.version}`) && notice.includes(p.commit) && notice.includes(`${p.name}/${p.license}`), `NOTICE lists ${p.name}`); + for (const line of p.copyright) assert.ok(notice.includes(line), `NOTICE carries "${line}"`); + assert.ok(readFileSync(join(imported, p.name, p.license), 'utf8').includes(p.copyright[0]), `${p.name} license file carries its copyright`); + } + assert.equal(new Set(provenance.packages.map(p => p.name)).size, provenance.packages.length); +}); + +test('the build reads only imported source and the editor\'s own files; the bundle is the recorded build', () => { + const imp = new Set(provenance.packages.flatMap(p => Object.keys(p.files).map(f => `third_party/editor/${p.name}/${f}`))); + for (const input of build.inputs) { + if (input.startsWith('third_party/editor/')) assert.ok(imp.has(input), `${input} is read by the build but is not in PROVENANCE.json`); + else assert.match(input, /^editor\/[a-z]+\.mjs$/, input); + assert.ok(!/(^|\/)(dist|node_modules)\//.test(input), `${input}: no prebuilt output goes in`); + } + for (const input of build.inputs) readFileSync(join(webui, input)); // every input exists + for (const [path, out] of Object.entries(build.outputs)) { + const buf = readFileSync(join(webui, path)); + assert.equal(sha(buf), out.sha256, `${path} is not the recorded build`); + assert.equal(buf.length, out.bytes, path); + } + const bundle = readFileSync(join(webui, 'src/public/editor.js'), 'utf8'); + assert.doesNotMatch(bundle, /sourceMappingURL/); + assert.match(bundle, /^\(\(\) => \{/, 'one unminified IIFE'); + assert.ok(bundle.split('\n').length > 5000, 'unminified'); +}); + +// A fake install: node_modules/esbuild/package.json with a version, and the platform binary with the given bytes. +const fakeInstall = (version, bytes) => { + const dir = mkdtempSync(join(tmpdir(), 'editor-toolchain-')); + mkdirSync(join(dir, 'node_modules/esbuild'), { recursive: true }); + writeFileSync(join(dir, 'node_modules/esbuild/package.json'), JSON.stringify({ name: 'esbuild', version })); + if (bytes !== undefined) { + const bin = join(dir, `node_modules/@esbuild/${process.platform}-${process.arch}/bin`); + mkdirSync(bin, { recursive: true }); + writeFileSync(join(bin, 'esbuild'), bytes); writeFileSync(join(dir, `node_modules/@esbuild/${process.platform}-${process.arch}/package.json`), '{}'); + } + return { dir, from: pathToFileURL(join(dir, 'x.mjs')) }; +}; + +test('MOSAIC_REQUIRE_EDITOR_BUILD: a missing or wrong esbuild skips without it and fails with it; a wrong binary always fails', async () => { + const { ESBUILD, toolchain, required, verdict } = await import('../editor/toolchain.mjs'); + const cases = []; + try { + for (const [label, install, kind] of [ + ['not installed', fakeInstall('0.0.0'), null], + ['another version', fakeInstall('0.28.1', 'x'), 'absent'], + ['the pinned version, another binary', fakeInstall(ESBUILD, 'not the esbuild binary'), 'refused'], + ['the pinned version, no binary', fakeInstall(ESBUILD), 'refused'], + ]) { + cases.push(install.dir); + if (label === 'not installed') rmSync(join(install.dir, 'node_modules'), { recursive: true }); + const tool = toolchain(install.from); + assert.equal(tool.ok, false, label); + assert.equal(tool.kind, kind ?? 'absent', label); + assert.ok(tool.reason.length > 20, `${label}: the reason is printed`); + assert.equal(verdict(tool, false), kind === 'refused' ? 'fail' : 'skip', `${label} without the switch`); + assert.equal(verdict(tool, true), 'fail', `${label} with the switch`); + } + // The switch itself: "1" requires; unset, empty and "0" do not; anything else throws. + assert.equal(required({}), false); assert.equal(required({ MOSAIC_REQUIRE_EDITOR_BUILD: '' }), false); assert.equal(required({ MOSAIC_REQUIRE_EDITOR_BUILD: '0' }), false); + assert.equal(required({ MOSAIC_REQUIRE_EDITOR_BUILD: '1' }), true); + for (const v of ['true', 'yes', ' 1', '2']) assert.throws(() => required({ MOSAIC_REQUIRE_EDITOR_BUILD: v }), /MOSAIC_REQUIRE_EDITOR_BUILD/); + // ESBUILD_BINARY_PATH replaces the binary esbuild runs, so it is refused whatever the install holds. + const fake = fakeInstall(ESBUILD, 'x'); cases.push(fake.dir); + process.env.ESBUILD_BINARY_PATH = '/bin/true'; + try { assert.equal(toolchain(fake.from).kind, 'refused'); } finally { delete process.env.ESBUILD_BINARY_PATH; } + } finally { for (const dir of cases) rmSync(dir, { recursive: true, force: true }); } +}); + +test('the toolchain check, run as a program, exits non-zero without esbuild when the build is required', () => { + // A copy of the check in a directory with no esbuild above it, so it cannot find one. + const dir = mkdtempSync(join(tmpdir(), 'editor-toolchain-cli-')); + try { + const copy = join(dir, 'toolchain.mjs'); + copyFileSync(join(webui, 'editor/toolchain.mjs'), copy); + const run = switchValue => { + const env = { ...process.env }; delete env.MOSAIC_REQUIRE_EDITOR_BUILD; delete env.NODE_PATH; delete env.ESBUILD_BINARY_PATH; + if (switchValue !== undefined) env.MOSAIC_REQUIRE_EDITOR_BUILD = switchValue; + return spawnSync(process.execPath, [copy], { encoding: 'utf8', env, cwd: dir }); + }; + const routine = run(); assert.equal(routine.status, 0, routine.stderr); assert.match(routine.stdout, /^skip: esbuild /); + assert.equal(run('0').status, 0); + const required = run('1'); assert.equal(required.status, 3); assert.match(required.stderr, /^missing: esbuild /); assert.equal(required.stdout, ''); + assert.notEqual(run('true').status, 0, 'a mistyped value is a failure, not a silent skip'); + } finally { rmSync(dir, { recursive: true, force: true }); } +}); + +test('rebuilding from the source gives the same bytes (needs the pinned esbuild; MOSAIC_REQUIRE_EDITOR_BUILD=1 makes its absence a failure)', async t => { + const { toolchain, required, verdict } = await import('../editor/toolchain.mjs'); + const tool = toolchain(), action = verdict(tool, required()); + if (action === 'skip') { t.skip(`${tool.reason} (set MOSAIC_REQUIRE_EDITOR_BUILD=1 to fail instead of skip)`); return; } + assert.equal(action, 'run', tool.reason); + const { run } = await import('../editor/build.mjs'); + const out = mkdtempSync(join(tmpdir(), 'editor-rebuild-')); + try { + const info = await run(out, join(out, 'BUILD.json')); + assert.equal(info.esbuild, build.esbuild); + assert.deepEqual(info.inputs, build.inputs); + for (const path of Object.keys(build.outputs)) assert.equal(sha(readFileSync(join(out, path.split('/').pop()))), build.outputs[path].sha256, `${path} rebuilt`); + assert.equal(readFileSync(join(out, 'BUILD.json'), 'utf8'), readFileSync(join(webui, 'editor/BUILD.json'), 'utf8')); + } finally { rmSync(out, { recursive: true, force: true }); } +}); diff --git a/packages/webui/tests/editor.test.mjs b/packages/webui/tests/editor.test.mjs new file mode 100644 index 000000000..aa2c278d1 --- /dev/null +++ b/packages/webui/tests/editor.test.mjs @@ -0,0 +1,75 @@ +// Row 154 (#1648, Q168): the Console's visual editor, the parts that need no browser. The routes, the +// round trip (open and save with no edit writes the same bytes), and the rules the editor source keeps. +// The imported source and the build are editor-provenance.test.mjs's; the page is editor-browser.test.mjs's. +import { test } from 'node:test'; +import assert from 'node:assert/strict'; +import { readFileSync, readdirSync } from 'node:fs'; +import { dirname, join } from 'node:path'; +import { fileURLToPath } from 'node:url'; +import { loadEditor } from './helpers/editor-bundle.mjs'; +import { EVERY } from './helpers/every-element.mjs'; +import { fixture } from './fixture.mjs'; + +const webui = join(dirname(fileURLToPath(import.meta.url)), '..'); +const repo = join(webui, '../..'); +const editor = loadEditor(); + +test('the editor routes serve the built files with their types and no cache', async t => { + const f = await fixture(); + t.after(() => f.close()); + for (const [path, type] of [['/editor.js', 'text/javascript'], ['/editor.css', 'text/css']]) { + const response = await fetch(f.base + path); + assert.equal(response.status, 200, path); + assert.ok(response.headers.get('content-type').startsWith(type), path); + assert.equal(response.headers.get('cache-control'), 'no-store', path); + assert.equal(await response.text(), readFileSync(join(webui, 'src/public', path), 'utf8'), `${path} is the built file`); + } + const index = await (await fetch(f.base + '/')).text(); + assert.match(index, //); + assert.ok(index.indexOf('src="/editor.js"') < index.indexOf('src="/bus.js"'), 'the editor loads before the page script, so bus.js can mount it'); +}); + +test('open and save with no edit writes the same bytes: the goals review and a doc with every element', () => { + const goals = readFileSync(join(repo, 'docs/plans/2026-09-27_goals-review.md'), 'utf8'); + assert.equal(editor.roundTrip(goals), goals); + assert.equal(editor.roundTrip(EVERY), EVERY); + // the same with the other line ending conventions a file can end in + for (const text of ['', '\n', '\n\n\n', 'no newline', '# T\n', '# T\n\n\n\ntext\n\n\n', '\n\n indented first line\n']) assert.equal(editor.roundTrip(text), text, JSON.stringify(text)); +}); + +test('open and save with no edit writes the same bytes: every repository doc under docs/ and spec/', () => { + const found = []; + const walk = dir => { + for (const e of readdirSync(dir, { withFileTypes: true })) { + if (e.isDirectory()) { if (!['node_modules', '.git', 'v1'].includes(e.name)) walk(join(dir, e.name)); } + else if (e.name.endsWith('.md')) found.push(join(dir, e.name)); + } + }; + for (const d of ['docs', 'spec']) { try { walk(join(repo, d)); } catch (e) { if (e.code !== 'ENOENT') throw e; } } + assert.ok(found.length > 20, `found ${found.length} docs`); + const changed = []; + for (const file of found) { + const text = readFileSync(file, 'utf8').replace(/\r\n/g, '\n'); // CRLF is saved as LF, as row 148's save does + if (editor.roundTrip(text) !== text) changed.push(file.slice(repo.length + 1)); + } + assert.deepEqual(changed, [], 'files the editor would change on an open and save with no edit'); +}); + +test('the editor source builds markup only with DOM calls, and the bundle has no eval', () => { + const sinks = /\binnerHTML\b|\bouterHTML\b|\binsertAdjacentHTML\b|\bdocument\.write\b|\beval\s*\(|\bnew\s+Function\b|\bsrcdoc\b|\bcreateContextualFragment\b|\bDOMParser\b/; + for (const file of ['entry.mjs', 'model.mjs', 'view.mjs']) { + const source = readFileSync(join(webui, 'editor', file), 'utf8').split('\n').filter(l => !l.trim().startsWith('//')).join('\n'); + assert.doesNotMatch(source, sinks, `editor/${file}`); + } + const bundle = readFileSync(join(webui, 'src/public/editor.js'), 'utf8'); + assert.doesNotMatch(bundle, /\beval\s*\(|\bnew\s+Function\b/, 'src/public/editor.js'); +}); + +test('the link gate and the image rule are the preview\'s', () => { + const model = readFileSync(join(webui, 'editor/model.mjs'), 'utf8'); + assert.match(model, /globalThis\.MosaicMarkdown\?\.linkTarget/, 'the link target goes through the one gate'); + assert.doesNotMatch(model, /tag:\s*'img/, 'no schema rule makes an '); + // a file's link the gate refuses stays source text, byte for byte, on a round trip and an edit-free save + const hostile = '[a](javascript:alert(1)) [b](data:text/html,x) [c](vbscript:x) [d](//evil.example/x) [e](https://ok.example/)\n'; + assert.equal(editor.roundTrip(hostile), hostile); +}); diff --git a/packages/webui/tests/helpers/editor-bundle.mjs b/packages/webui/tests/helpers/editor-bundle.mjs new file mode 100644 index 000000000..ae03ebc9d --- /dev/null +++ b/packages/webui/tests/helpers/editor-bundle.mjs @@ -0,0 +1,17 @@ +// Loads src/public/editor.js (and markdown-preview.js, the link gate it needs) into a vm context with a +// bare `window`, so model-level tests can call MosaicEditor.roundTrip without a browser. +import { readFileSync } from 'node:fs'; +import { dirname, join } from 'node:path'; +import { fileURLToPath } from 'node:url'; +import vm from 'node:vm'; + +const pub = join(dirname(fileURLToPath(import.meta.url)), '../../src/public'); + +export function loadEditor() { + const sandbox = { console }; + sandbox.window = sandbox; + sandbox.globalThis = sandbox; + vm.createContext(sandbox); + for (const f of ['markdown-preview.js', 'editor.js']) vm.runInContext(readFileSync(join(pub, f), 'utf8'), sandbox, { filename: f }); + return sandbox.MosaicEditor; +} diff --git a/packages/webui/tests/helpers/every-element.mjs b/packages/webui/tests/helpers/every-element.mjs new file mode 100644 index 000000000..2ead3c454 --- /dev/null +++ b/packages/webui/tests/helpers/every-element.mjs @@ -0,0 +1,30 @@ +// Every element row 148's preview draws, and the ones it shows as source text. +export const EVERY = [ + '---', 'title: front matter', '---', '', + '# One', '', '## Two', '', '### Three', '', '#### Four', '', '##### Five', '', '###### Six', '', + 'Setext one', '==========', '', + 'Plain paragraph with *emphasis*, _emphasis_, **strong**, ***both***, `code`, a [link](https://example.com/a "title"),', + 'a [relative](../docs/x.md), a [fragment](#top), and a hard break\\', 'on the next line.', '', + '> A quote', '> with two lines', '>', '> > and a nested quote', '', + '- one', '- two', ' - nested', ' - nested too', '- three', '', + '1. first', '2. second', ' 1. inner', '3. third', '', + '* star list', '* second', '', + '+ plus list', '', + '```js', 'const x = "not bold";', '```', '', + '~~~', 'tilde fence', '~~~', '', + ' indented code', '', + '---', '', + '***', '', + '| a | b |', '|---|---|', '| 1 | 2 |', '', + '
raw html
', '', + '', '', + '', '', + '![alt text](https://tracker.example/p.png "t")', '', + '[click](javascript:window.injected=3) [data](data:text/html,)', '', + '~~struck~~ text', '', + '[ref]: https://example.com/ref', '', + 'Text with a [reference link][ref] and an autolink .', '', + '\\# not a heading and \\* not a list and a literal \\ and & entity', '', + '', + 'two blank lines above, no newline at end', +].join('\n'); diff --git a/packages/webui/tests/serve.test.mjs b/packages/webui/tests/serve.test.mjs index cec64ccef..7de4b1ddb 100644 --- a/packages/webui/tests/serve.test.mjs +++ b/packages/webui/tests/serve.test.mjs @@ -33,7 +33,7 @@ test('real board fixture passes through WebUI; assets and isolated seen/reply wo const reply = await post(f.base, '/api/reply', { agent: 'proj/agent1', text: 'fixture reply' }); assert.equal((await reply.json()).delivered, true); assert.equal(f.captures.length, 1); assert.match(f.captures[0].args.at(-1), /^fixture reply\n\(control-board:/); - for (const path of ['/', '/app.js', '/brand.js', '/console.css', '/live.css', '/shared/app.css', '/assets/fonts/manrope-400.woff2']) { + for (const path of ['/', '/app.js', '/brand.js', '/console.css', '/live.css', '/editor.js', '/editor.css', '/shared/app.css', '/assets/fonts/manrope-400.woff2']) { const response = await fetch(f.base + path); assert.equal(response.status, 200, path); assert.equal(response.headers.get('cache-control'), 'no-store'); } // #1542: the shell's tokens, sprite, stylesheet and mono fonts, each with its type. diff --git a/packages/webui/third_party/editor/NOTICE b/packages/webui/third_party/editor/NOTICE new file mode 100644 index 000000000..f72a55ea3 --- /dev/null +++ b/packages/webui/third_party/editor/NOTICE @@ -0,0 +1,102 @@ +Third-party source used by the Console editor (row 154, #1648, Q168). + +The source under this directory is unmodified upstream source, imported from tagged trees by +agents/researcher/work/queue-154/repro/import-sources.mjs and described in PROVENANCE.json. Each package +below keeps its own license file next to its source; the SPDX id is the one its package.json declares. +The editor bundle src/public/editor.js is built from this source by editor/build.mjs. + +prosemirror-model 1.25.12 + source: https://code.haverbeke.berlin/prosemirror/prosemirror-model at hb-1.25.12 (4211aeeaa3d738454a5d1428a95c1a210e86d787) + license: MIT, prosemirror-model/LICENSE + notice: Copyright (C) 2015-2017 by Marijn Haverbeke and others + +prosemirror-state 1.4.4 + source: https://code.haverbeke.berlin/prosemirror/prosemirror-state at hb-1.4.4 (d6fdcd19c4f7f68206b0a8d49649860365672585) + license: MIT, prosemirror-state/LICENSE + notice: Copyright (C) 2015-2017 by Marijn Haverbeke and others + +prosemirror-view 1.42.6 + source: https://code.haverbeke.berlin/prosemirror/prosemirror-view at hb-1.42.6 (f5a5b93a78f6f723c1fbf1a2eec1556a022cd0ee) + license: MIT, prosemirror-view/LICENSE + notice: Copyright (C) 2015-2017 by Marijn Haverbeke and others + +prosemirror-transform 1.12.2 + source: https://code.haverbeke.berlin/prosemirror/prosemirror-transform at hb-1.12.2 (a93e228a10b76698e0878df2e1f881389e3a94ec) + license: MIT, prosemirror-transform/LICENSE + notice: Copyright (C) 2015-2017 by Marijn Haverbeke and others + +prosemirror-inputrules 1.5.1 + source: https://code.haverbeke.berlin/prosemirror/prosemirror-inputrules at hb-1.5.1 (089aa3852a55d551211af90aae2560c554ccf476) + license: MIT, prosemirror-inputrules/LICENSE + notice: Copyright (C) 2015-2017 by Marijn Haverbeke and others + +prosemirror-markdown 1.13.8 + source: https://code.haverbeke.berlin/prosemirror/prosemirror-markdown at hb-1.13.8 (e3a5926aa3236af2a463d824f4f22455460b008f) + license: MIT, prosemirror-markdown/LICENSE + notice: Copyright (C) 2015-2017 by Marijn Haverbeke and others + +prosemirror-commands 1.7.2 + source: https://code.haverbeke.berlin/prosemirror/prosemirror-commands at hb-1.7.2 (59fee8d89be2d033b28c2bac68e6736e2989bf9d) + license: MIT, prosemirror-commands/LICENSE + notice: Copyright (C) 2015-2017 by Marijn Haverbeke and others + +prosemirror-history 1.5.1 + source: https://code.haverbeke.berlin/prosemirror/prosemirror-history at hb-1.5.1 (44956b6a1929d7bc99aca9a8ec01c790260fa45f) + license: MIT, prosemirror-history/LICENSE + notice: Copyright (C) 2015-2017 by Marijn Haverbeke and others + +prosemirror-keymap 1.2.3 + source: https://code.haverbeke.berlin/prosemirror/prosemirror-keymap at hb-1.2.3 (081f24f65b6a394174a4bdf07b9a55a00361f1b7) + license: MIT, prosemirror-keymap/LICENSE + notice: Copyright (C) 2015-2017 by Marijn Haverbeke and others + +prosemirror-schema-list 1.5.1 + source: https://code.haverbeke.berlin/prosemirror/prosemirror-schema-list at hb-1.5.1 (e65a144f2285178a20cbdea5b0ee16925be7d6c5) + license: MIT, prosemirror-schema-list/LICENSE + notice: Copyright (C) 2015-2017 by Marijn Haverbeke and others + +markdown-it 14.3.3 + source: https://github.com/markdown-it/markdown-it at 14.3.3 (d372f0d8a68bef0b0acaa68868ce8ae8ba85b384) + license: MIT, markdown-it/LICENSE + notice: Copyright (c) 2014 Vitaly Puzrin, Alex Kocharin. + +linkify-it 5.0.2 + source: https://github.com/markdown-it/linkify-it at 5.0.2 (50a0c914f834b201cab25ff4faefd1f832b37332) + license: MIT, linkify-it/LICENSE + notice: Copyright (c) 2015 Vitaly Puzrin. + +uc.micro 2.1.0 + source: https://github.com/markdown-it/uc.micro at 2.1.0 (d91cec10974f125be7accd4dd870900fd18fdec7) + license: MIT, uc.micro/LICENSE.txt + notice: Copyright Mathias Bynens + +mdurl 2.1.0 + source: https://github.com/markdown-it/mdurl at 2.1.0 (dd913f6290a4d8772240a401aab993eb65c5786d) + license: MIT, mdurl/LICENSE + notice: Copyright (c) 2015 Vitaly Puzrin, Alex Kocharin. + notice: Copyright Joyent, Inc. and other Node contributors. All rights reserved. + +punycode.js 2.3.1 + source: https://github.com/mathiasbynens/punycode.js at v2.3.1 (9e1b2cda98d215d3a73fcbfe93c62e021f4ba768) + license: MIT, punycode.js/LICENSE-MIT.txt + notice: Copyright Mathias Bynens + +entities 4.5.0 + source: https://github.com/fb55/entities at v4.5.0 (61afd4701eaa736978b13c7351cd3de9a96b04bc) + license: BSD-2-Clause, entities/LICENSE + notice: Copyright (c) Felix Böhm + +orderedmap 2.1.1 + source: https://github.com/marijnh/orderedmap at 2.1.1 (6a30ebbbecd30fed8bda884c7acf4ca9c6a02405) + license: MIT, orderedmap/LICENSE + notice: Copyright (C) 2016 by Marijn Haverbeke and others + +rope-sequence 1.3.4 + source: https://github.com/marijnh/rope-sequence at 1.3.4 (11db1ba5aa2abf31ff8040bdf01fabdb9db34c7a) + license: MIT, rope-sequence/LICENSE + notice: Copyright (C) 2016 by Marijn Haverbeke + +w3c-keyname 2.2.8 + source: https://github.com/marijnh/w3c-keyname at 2.2.8 (5ea93b04bb62230c7de4165e3a9b5c840f05cd44) + license: MIT, w3c-keyname/LICENSE + notice: Copyright (C) 2016 by Marijn Haverbeke and others diff --git a/packages/webui/third_party/editor/PROVENANCE.json b/packages/webui/third_party/editor/PROVENANCE.json new file mode 100644 index 000000000..5ce2fe4fd --- /dev/null +++ b/packages/webui/third_party/editor/PROVENANCE.json @@ -0,0 +1,1145 @@ +{ + "schema": 1, + "localChanges": [], + "notice": { + "sha256": "2f687a0fd1ea83ce3935b8a06db2aa8a21cb33feb95c22a7b12f8d38e504d6a7", + "bytes": 5588 + }, + "tree": { + "sha256": "6ec83e443981bc8d50d1f2eee6b12518eb0983870c22b6838532758202947667", + "files": 170 + }, + "packages": [ + { + "name": "prosemirror-model", + "version": "1.25.12", + "origin": "https://code.haverbeke.berlin/prosemirror/prosemirror-model", + "tag": "hb-1.25.12", + "commit": "4211aeeaa3d738454a5d1428a95c1a210e86d787", + "upstreamTree": "30600a5e07c4ec5c63f1fb1c8ab392e2bc019b9f", + "spdx": "MIT", + "license": "LICENSE", + "copyright": [ + "Copyright (C) 2015-2017 by Marijn Haverbeke and others" + ], + "files": { + "LICENSE": { + "blob": "7e2295b307446b171b993b705239928d8e0347b8", + "sha256": "ef0b452ced6304db2ce78ca66de1fc7b97bab05bc1750c95df359ed3fe1d65c8", + "bytes": 1105 + }, + "package.json": { + "blob": "3344cc86b9c0705f0fb322cfb0a23bf4d446ee80", + "sha256": "b9357f3e9f19800fa43e91e70cf62e63e7f181c1acd607c7cf2aac8de212877e", + "bytes": 900 + }, + "src/comparedeep.ts": { + "blob": "f721031043db2e45110f5f6d9a9f7a52ef2d5561", + "sha256": "2ea58a7903bd66ce21a7d313f1af3f0674f240e7a207622d6fc1d64b16a7e174", + "bytes": 534 + }, + "src/content.ts": { + "blob": "adcc8a3c8e26a4b7afc60791aa57751cacbfe3f2", + "sha256": "a07fd75d13dd2765526589fd31fdd0307037e6e27dfece91301ca371d3b5fe0c", + "bytes": 14107 + }, + "src/diff.ts": { + "blob": "a20452675f3e66e711d29520636847a4dfff08d9", + "sha256": "d1f2c1bc168e0fb891a519ab0daa7e136bd43b7f8a25d50d1cdbed45fe3d6cd5", + "bytes": 2154 + }, + "src/fragment.ts": { + "blob": "0bf655aab5ffb8162943572208d354ec4b18db2a", + "sha256": "bb9d6b507b084093de4efbe3066dd47b14afe32a41e4390af4aacbe8d98058af", + "bytes": 10449 + }, + "src/from_dom.ts": { + "blob": "e6ae3d4d0ebd2c8a48ba05120e93f221a96900e2", + "sha256": "b4f5e77c9dd4f430002b83fae8e1d114d9653e16ef4b28fba5ea01eb52980abb", + "bytes": 33633 + }, + "src/index.ts": { + "blob": "e131caec931a6a2a2393979a5ce1145f49ca7f51", + "sha256": "d6bd6dfd331f27a8b7ca6554ed4833c4983a6cb1cd6332d1c576c0529df386ea", + "bytes": 502 + }, + "src/mark.ts": { + "blob": "11c27f2d0394a8b456741395082cae67142af5dd", + "sha256": "7ba7a7ba2f1861ae15cd894afa80e5211b59e2117bf4568af0b5cc9cd8e18057", + "bytes": 3678 + }, + "src/node.ts": { + "blob": "8dbd6f5ae8bcd194d24fc56f697abb0fc42e1314", + "sha256": "39defcbeff65f8de187e61d956a1b5b1080962eda32bb875ac1d1e025c31f0d2", + "bytes": 16346 + }, + "src/replace.ts": { + "blob": "44275cf8eaf0ffd1048c9535130f22072c8d4fdb", + "sha256": "4f2fbf315fba1e70b7802f7c7f5e3478848c5f57f025c2b2169b680153f18b2c", + "bytes": 9137 + }, + "src/resolvedpos.ts": { + "blob": "40e4c8eda2699fcc8a2517e16952ed2afe151ad5", + "sha256": "dcef2f457569f8c9daf9c33012470a3446d7b42b1c7aecc9b79d025679fcf596", + "bytes": 11616 + }, + "src/schema.ts": { + "blob": "2362e713af38a95e8aafefbd45dde66606d4b02c", + "sha256": "ca0b19ac52487b2d8e75a3ee8321e02ecc5b24397218ca9606bd7b6648c22f7a", + "bytes": 27212 + }, + "src/to_dom.ts": { + "blob": "b02ea04d89a1b8359b02dd6ceb413d33b7d1dd11", + "sha256": "b7b3ee52fd9218c3fcaf45a873aa769a3ec28e539715ec1162a545fbd4c8981f", + "bytes": 10068 + } + } + }, + { + "name": "prosemirror-state", + "version": "1.4.4", + "origin": "https://code.haverbeke.berlin/prosemirror/prosemirror-state", + "tag": "hb-1.4.4", + "commit": "d6fdcd19c4f7f68206b0a8d49649860365672585", + "upstreamTree": "b781a85e73fb7c3f37bc669e7dc27e7d16f592d6", + "spdx": "MIT", + "license": "LICENSE", + "copyright": [ + "Copyright (C) 2015-2017 by Marijn Haverbeke and others" + ], + "files": { + "LICENSE": { + "blob": "7e2295b307446b171b993b705239928d8e0347b8", + "sha256": "ef0b452ced6304db2ce78ca66de1fc7b97bab05bc1750c95df359ed3fe1d65c8", + "bytes": 1105 + }, + "package.json": { + "blob": "b5c55bf32b08ca8bc4a08496270b261a8026ccc9", + "sha256": "b40080e3d2ebfaab5a6ee44b3b2cb20761d79cbe514411df8641a8434d2b65ef", + "bytes": 934 + }, + "src/index.ts": { + "blob": "a6defe3cfa8ebf14770bcd12dc428b508cf3d963", + "sha256": "eb9e85c66caac02f0140ca3686efd10cd117d64eda4d9054bc8c3e4622055d6a", + "bytes": 305 + }, + "src/plugin.ts": { + "blob": "29f07543dea295a22747e9a7fe6e5c50298dcafa", + "sha256": "a0bac3d5db226ed673774b0b6b58d43e36d13f34b9ecee874d081dc3145e2202", + "bytes": 5790 + }, + "src/selection.ts": { + "blob": "407a335433657ab0d474b818e396bb7a9891e434", + "sha256": "cea98fb72c5ced3604556909df9acddf924b3e62f80cab4bdbe430a78afc529a", + "bytes": 17277 + }, + "src/state.ts": { + "blob": "e8c3e41cbd29306950d79ef49da6024095f14489", + "sha256": "081d675bbeaa6598c17f45be84a84011c5e083b66f9c6282be0304a5f38f7f44", + "bytes": 10514 + }, + "src/transaction.ts": { + "blob": "6638994520eaaf1a02cf2127c53e2e8ae20bd772", + "sha256": "fbab5b3d17fc510152167b387e15dcf360c086ed78dcb2751cecae7938d01a83", + "bytes": 7932 + } + } + }, + { + "name": "prosemirror-view", + "version": "1.42.6", + "origin": "https://code.haverbeke.berlin/prosemirror/prosemirror-view", + "tag": "hb-1.42.6", + "commit": "f5a5b93a78f6f723c1fbf1a2eec1556a022cd0ee", + "upstreamTree": "d73328db75884503bf74157722236efe4a6ef867", + "spdx": "MIT", + "license": "LICENSE", + "copyright": [ + "Copyright (C) 2015-2017 by Marijn Haverbeke and others" + ], + "files": { + "LICENSE": { + "blob": "7e2295b307446b171b993b705239928d8e0347b8", + "sha256": "ef0b452ced6304db2ce78ca66de1fc7b97bab05bc1750c95df359ed3fe1d65c8", + "bytes": 1105 + }, + "package.json": { + "blob": "4a7b292ed8864b35383354d26b6a48024fcf951d", + "sha256": "79841007db65e2d7abf34585ae8accff299081c2f2731b81c138afef050dd29a", + "bytes": 1093 + }, + "src/browser.ts": { + "blob": "3ff97105bb5a0fa211db7e97ac0fe879a64e26b8", + "sha256": "753c05e4ed16081e169e57fee6febaddafb7de6edd568fb93b2690c3fd63b3af", + "bytes": 1355 + }, + "src/capturekeys.ts": { + "blob": "d48e0e4e64dbbd1aebd457a4e7568eb850d38e9b", + "sha256": "e08d4a3bb328babc0681a3c20bd151b1fb2225d6201949ef4605b933ffe04705", + "bytes": 13285 + }, + "src/clipboard.ts": { + "blob": "3ed9ce4f79dee117cfe21902b022b376d6157746", + "sha256": "4401b14080289627189743717edfb4131b42087c4d705faab90e0c7bee7b82d9", + "bytes": 12259 + }, + "src/decoration.ts": { + "blob": "31ee3700a3da54a83f37c61a5a2e1c874d5e1ece", + "sha256": "a18ba09db59bd096ffe84b73554542f93f3c4aa5b92322de38a7ed78da493e3a", + "bytes": 30881 + }, + "src/dom.ts": { + "blob": "638826444bf8da779ae39e84fea57a795f4e9e9e", + "sha256": "045cb9f2ee04030a9488b1c8de850a1dbb35e28050a73b92842f3503d37ec6af", + "bytes": 6112 + }, + "src/domchange.ts": { + "blob": "b55af62898a3ceac10f55892069ebf80da5d0136", + "sha256": "6ff0d1123fce86c9d8ebf1370dc3c6ce143bce30427680556b1b07df76c2a08a", + "bytes": 16955 + }, + "src/domcoords.ts": { + "blob": "df7fdc7405da454cb3c4347d4e3ad502be06ef60", + "sha256": "d7848f023b7b301267fbc2f73fce36f89ae3a6704f5ca428675ad36f56edb418", + "bytes": 23259 + }, + "src/domobserver.ts": { + "blob": "337240e7c0952b4bc6734bd293c5fd393950bc7a", + "sha256": "ce088c9e363f5f1834a7ed9d32e0b19721651ff04398bafc5db6fd86a7ad60cb", + "bytes": 15654 + }, + "src/index.ts": { + "blob": "7d4205736a5533b8c22b2ce9a8ea719f8f52f143", + "sha256": "14a8ed0e44a7fc73a6886e1dc6ab7c70311f4590b9501578a2fac4e7e37e8200", + "bytes": 36957 + }, + "src/input.ts": { + "blob": "b385cc19d572f49ce00b3335c9a5c9b35da3fab5", + "sha256": "58b78c5da37cb9cc255e494c72566c1013eae4972a4b093cca866a6b7de255e4", + "bytes": 34481 + }, + "src/selection.ts": { + "blob": "2cc1de165cafd2ede4f6b96d4eff0a7d1e6553a5", + "sha256": "6a305d8080a038b0fdb0d7e02b54f802179a9dac47ab3c5386077b5f09d78437", + "bytes": 9556 + }, + "src/viewdesc.ts": { + "blob": "226a161dcdfb26051cd5c19518a9c9336eef560d", + "sha256": "3291f9a85c2cd8efcb1f031eed62cfa5a103d760b3a924bcf8d2ee148b8a121f", + "bytes": 65078 + }, + "style/prosemirror.css": { + "blob": "45c081e59b4ebfd8a3d9aab341619ae58b4e002e", + "sha256": "1234171efd99cd16d1a6754c0f6586d0d8b69573432aff2e671cb6a26c9eaa57", + "bytes": 1243 + } + } + }, + { + "name": "prosemirror-transform", + "version": "1.12.2", + "origin": "https://code.haverbeke.berlin/prosemirror/prosemirror-transform", + "tag": "hb-1.12.2", + "commit": "a93e228a10b76698e0878df2e1f881389e3a94ec", + "upstreamTree": "a0aaeb587f5fa15efa9fadaab03e7fcb26bbe64e", + "spdx": "MIT", + "license": "LICENSE", + "copyright": [ + "Copyright (C) 2015-2017 by Marijn Haverbeke and others" + ], + "files": { + "LICENSE": { + "blob": "7e2295b307446b171b993b705239928d8e0347b8", + "sha256": "ef0b452ced6304db2ce78ca66de1fc7b97bab05bc1750c95df359ed3fe1d65c8", + "bytes": 1105 + }, + "package.json": { + "blob": "397951c09879a99f49331d2eeaa8828a4fb91062", + "sha256": "2e7118bcda51981c6a6703a6acb43d50aad87cb43fee2a35a9b0f0538ed50bcb", + "bytes": 899 + }, + "src/attr_step.ts": { + "blob": "b5d7da89069cd0be9d3a6c5f1f3953a01d20b001", + "sha256": "02a7084a3a5cf784504f3e954c248e655ffa16c41bbbb40f35c1139333833f6d", + "bytes": 2675 + }, + "src/index.ts": { + "blob": "9e96449ba59457b74c048288d22954be8d93e026", + "sha256": "340e51489f5ea1e160dc80c9fe0bad0933d276abf33964a05060005c1f314bed", + "bytes": 561 + }, + "src/map.ts": { + "blob": "15a3fbd80f22cc45cf09ff3db0472b72e9cb62ed", + "sha256": "ddb1fc54b8e49581b6f1f71b84689ccad8b2cb10c44ecc9c01d9b32045624e78", + "bytes": 11016 + }, + "src/mark.ts": { + "blob": "8ec5a3098f0f8478a148977581bc8714ed73592a", + "sha256": "f16e4d61bbd8ea94646c16b7b3a781f73a29308a32ac4d9cacc7974c2db5a0cb", + "bytes": 3948 + }, + "src/mark_step.ts": { + "blob": "7fadfed5e7e9a687b9d73c02b78dd061257d0980", + "sha256": "0beed9199e494bd664e685e05f18a94fd7299f72181702fd9aa5804a6a371ee4", + "bytes": 7357 + }, + "src/replace.ts": { + "blob": "1438ebf46c8605c688d65328f11c746a86d8bceb", + "sha256": "07110ea74d962e5be381628bacb5e340124c77004d08c343a1c500ba1436bfe1", + "bytes": 21184 + }, + "src/replace_step.ts": { + "blob": "03505dd68b14bc6a1a8d96682ed0e1f3a9fe53cb", + "sha256": "478a68a658aa697ad75be626eaf99616d09e082ed04fb6fb3dd3cb0e76dc28a9", + "bytes": 7665 + }, + "src/step.ts": { + "blob": "92499ce72bbf6df4c5189f777234e66bf10d1bb6", + "sha256": "1080eb080282f47c9ac6edf91b1ea788069a2644da4d7257b139ca610ab9e1ac", + "bytes": 4015 + }, + "src/structure.ts": { + "blob": "090a569aeae2c26b2c04e8faf70eb55f8231f6a1", + "sha256": "0fbbe54771f17d3c309b19846d3bf4ce160642eb7ec43c8bc6edef55a87beae3", + "bytes": 15448 + }, + "src/transform.ts": { + "blob": "d76b171b07e6d36064c7a1533c90b8d0b94f903c", + "sha256": "ce12d2c55f42342f077a1b08a5ccca1c2847433bacdf2548e00c7e53704342f3", + "bytes": 10429 + } + } + }, + { + "name": "prosemirror-inputrules", + "version": "1.5.1", + "origin": "https://code.haverbeke.berlin/prosemirror/prosemirror-inputrules", + "tag": "hb-1.5.1", + "commit": "089aa3852a55d551211af90aae2560c554ccf476", + "upstreamTree": "056aa2801460da409048c2eef074f6e513bb1233", + "spdx": "MIT", + "license": "LICENSE", + "copyright": [ + "Copyright (C) 2015-2017 by Marijn Haverbeke and others" + ], + "files": { + "LICENSE": { + "blob": "7e2295b307446b171b993b705239928d8e0347b8", + "sha256": "ef0b452ced6304db2ce78ca66de1fc7b97bab05bc1750c95df359ed3fe1d65c8", + "bytes": 1105 + }, + "package.json": { + "blob": "52fdf409a4298ff9a69698019f96bb8f2d0a9159", + "sha256": "d6609dcfd99fe0dbcf0dcb9121693337b2ded4b4d20ee5255b797277ca59f8c9", + "bytes": 866 + }, + "src/index.ts": { + "blob": "2d82a9747a591a61f411f8512c5e16f5fa317ad9", + "sha256": "fcf2d6220de0ad68e71a28591d1aafdb776707a551e0e30de5f1b1a772eabbe9", + "bytes": 271 + }, + "src/inputrules.ts": { + "blob": "6a64b331c4ae790aab8876ff14a0ae9066dbf3ff", + "sha256": "3a551544aa4c81843d0120936f1bee96fa553b1d90ed2ac429688024bf1a21d2", + "bytes": 6208 + }, + "src/rulebuilders.ts": { + "blob": "d17328ccd89e7fe440ee2ec4d7eacaaae1cfa87b", + "sha256": "17eab940d68292553eda7fb3ec665f2fb5c1e2c18402115e8bc9931aa97b1bed", + "bytes": 2751 + }, + "src/rules.ts": { + "blob": "ab8188906606073e461088115d6c46a7a3b753a9", + "sha256": "444a4f1ea383a140708f2a22730568fed590ae4a749581dc2a20937471bb75dd", + "bytes": 979 + } + } + }, + { + "name": "prosemirror-markdown", + "version": "1.13.8", + "origin": "https://code.haverbeke.berlin/prosemirror/prosemirror-markdown", + "tag": "hb-1.13.8", + "commit": "e3a5926aa3236af2a463d824f4f22455460b008f", + "upstreamTree": "1467a53e37b554d0f0329a5017781db89ecc3da1", + "spdx": "MIT", + "license": "LICENSE", + "copyright": [ + "Copyright (C) 2015-2017 by Marijn Haverbeke and others" + ], + "files": { + "LICENSE": { + "blob": "7e2295b307446b171b993b705239928d8e0347b8", + "sha256": "ef0b452ced6304db2ce78ca66de1fc7b97bab05bc1750c95df359ed3fe1d65c8", + "bytes": 1105 + }, + "package.json": { + "blob": "83262986c5a7e61b0875b8434cc465489cb0b5b2", + "sha256": "f0cbcc04e45defa3e2533ce02e39f06212814b9c17cdccf4e98fd1142e1be494", + "bytes": 986 + }, + "src/from_markdown.ts": { + "blob": "d29f9ac77eb18ed74ab374b5936c48c887de5219", + "sha256": "8f021766089ae38beb47892a8526eb78453cbfc48ee5537ea15bef230cd8283d", + "bytes": 10408 + }, + "src/index.ts": { + "blob": "bca4892ea5301d47a7676f4b3a3f4ce38ec41c9e", + "sha256": "f0dcc085537da271aa3bc4969576bbd5f03d9982f35807386fdf9b12af7d0aa5", + "bytes": 297 + }, + "src/schema.ts": { + "blob": "0eefe62b0edab823d453cdb1cce6f9997a1a2d98", + "sha256": "f2559c4d6b14e3a322078f0fdf653f3c8a98ccbd28ec5c9c19eff7be63a6eece", + "bytes": 4339 + }, + "src/to_markdown.ts": { + "blob": "e01e5f91f57d1facab0707a3cbd8f9953e5a9937", + "sha256": "fa394f5f51ae8834c78cff106faa9892a0f12a2c265a4bde095861f2a7d207eb", + "bytes": 18530 + } + } + }, + { + "name": "prosemirror-commands", + "version": "1.7.2", + "origin": "https://code.haverbeke.berlin/prosemirror/prosemirror-commands", + "tag": "hb-1.7.2", + "commit": "59fee8d89be2d033b28c2bac68e6736e2989bf9d", + "upstreamTree": "b5e1865a2d532f1424f409dc5be1d56ac077b855", + "spdx": "MIT", + "license": "LICENSE", + "copyright": [ + "Copyright (C) 2015-2017 by Marijn Haverbeke and others" + ], + "files": { + "LICENSE": { + "blob": "7e2295b307446b171b993b705239928d8e0347b8", + "sha256": "ef0b452ced6304db2ce78ca66de1fc7b97bab05bc1750c95df359ed3fe1d65c8", + "bytes": 1105 + }, + "package.json": { + "blob": "084fa603ff4e727e3ab2285d79c8ed8b51a1f18a", + "sha256": "4cef535a05c932ce887caa9fd6a6af08c1b4eb0ec0b30f7f7d81cb7ef3d32e79", + "bytes": 969 + }, + "src/commands.ts": { + "blob": "aa0cef4bd36c877aa47095d91f3270a51e313772", + "sha256": "41ea89670248c1b68a7120c1304d1491b37e7ed7c02ee36002fed08f3a411dfc", + "bytes": 32982 + } + } + }, + { + "name": "prosemirror-history", + "version": "1.5.1", + "origin": "https://code.haverbeke.berlin/prosemirror/prosemirror-history", + "tag": "hb-1.5.1", + "commit": "44956b6a1929d7bc99aca9a8ec01c790260fa45f", + "upstreamTree": "8c1e6d7ec040a87886e7f39fbf3029b0c2961ca9", + "spdx": "MIT", + "license": "LICENSE", + "copyright": [ + "Copyright (C) 2015-2017 by Marijn Haverbeke and others" + ], + "files": { + "LICENSE": { + "blob": "7e2295b307446b171b993b705239928d8e0347b8", + "sha256": "ef0b452ced6304db2ce78ca66de1fc7b97bab05bc1750c95df359ed3fe1d65c8", + "bytes": 1105 + }, + "package.json": { + "blob": "e75e9ce7b70db37ffb7d4c403201eccaf7c22d22", + "sha256": "e6119f791faa9f4b162b7fe5fd6a5a5a42ffbd7070a682db922787e4cbd6df22", + "bytes": 992 + }, + "src/history.ts": { + "blob": "3924e56ea437224def44f83ccee8bff021b87502", + "sha256": "146298d448b0290b6e978ff579a9e159414789d6d37ee9e2bfe7c41e1d45f50c", + "bytes": 17917 + } + } + }, + { + "name": "prosemirror-keymap", + "version": "1.2.3", + "origin": "https://code.haverbeke.berlin/prosemirror/prosemirror-keymap", + "tag": "hb-1.2.3", + "commit": "081f24f65b6a394174a4bdf07b9a55a00361f1b7", + "upstreamTree": "9031f125a6b53618b55b12b9272573a5aba1677c", + "spdx": "MIT", + "license": "LICENSE", + "copyright": [ + "Copyright (C) 2015-2017 by Marijn Haverbeke and others" + ], + "files": { + "LICENSE": { + "blob": "7e2295b307446b171b993b705239928d8e0347b8", + "sha256": "ef0b452ced6304db2ce78ca66de1fc7b97bab05bc1750c95df359ed3fe1d65c8", + "bytes": 1105 + }, + "package.json": { + "blob": "1f2a7cf481a27f8c18361dd4e95edaf6d8134d64", + "sha256": "15652f722a20aa5a7db8a8ae5a1326e56435f6651c67cf8a594c2c826eada761", + "bytes": 897 + }, + "src/keymap.ts": { + "blob": "d0f29705cbf44e3705daf9ab6c17502793d9c0f8", + "sha256": "9d27d674fd56226ce0deb5ba367873872375296d6088783191c039206ea92b60", + "bytes": 4634 + } + } + }, + { + "name": "prosemirror-schema-list", + "version": "1.5.1", + "origin": "https://code.haverbeke.berlin/prosemirror/prosemirror-schema-list", + "tag": "hb-1.5.1", + "commit": "e65a144f2285178a20cbdea5b0ee16925be7d6c5", + "upstreamTree": "12f3dd9c2735f86f54af2442e2600a14dc14f61f", + "spdx": "MIT", + "license": "LICENSE", + "copyright": [ + "Copyright (C) 2015-2017 by Marijn Haverbeke and others" + ], + "files": { + "LICENSE": { + "blob": "7e2295b307446b171b993b705239928d8e0347b8", + "sha256": "ef0b452ced6304db2ce78ca66de1fc7b97bab05bc1750c95df359ed3fe1d65c8", + "bytes": 1105 + }, + "package.json": { + "blob": "1581e0f8494a99dc9ee6aecd93572c0ac98df364", + "sha256": "98d90d8f6748a87c4948f518b14a453f00e9f4e1dd507744786a3e0614953964", + "bytes": 1020 + }, + "src/schema-list.ts": { + "blob": "f86a973f7a7f9f22c0dd92438300b9ecf5bb15bb", + "sha256": "fc816321f12d8b9ebbaecfaacd9c48807e3ef0af4f95cc536e30b8cd5df44d54", + "bytes": 12911 + } + } + }, + { + "name": "markdown-it", + "version": "14.3.3", + "origin": "https://github.com/markdown-it/markdown-it", + "tag": "14.3.3", + "commit": "d372f0d8a68bef0b0acaa68868ce8ae8ba85b384", + "upstreamTree": "add6fa27b88402728a549324407204b5ca0b9799", + "spdx": "MIT", + "license": "LICENSE", + "copyright": [ + "Copyright (c) 2014 Vitaly Puzrin, Alex Kocharin." + ], + "files": { + "LICENSE": { + "blob": "7ffa058cb78f8fb9beb974d9fd429004d2d2e585", + "sha256": "792c48c5a849a15fdf9e37e8bcf9e6d1dd13b32b46c642a748a0a46a9919d473", + "bytes": 1073 + }, + "index.mjs": { + "blob": "f7ba45f9f05fd74a315428fba4cdc8d15fd0486d", + "sha256": "a112fad9f779e8e4d58a76586ec54b5b9fe134d92a670a96749bcb676be2c62b", + "bytes": 42 + }, + "lib/common/html_blocks.mjs": { + "blob": "1e27a7f602ec26b5a7042549e5755f6adf88c996", + "sha256": "5bbdf4ab71bd31461b29d47da1077c600ba941c3e53d74f8d50ce31ac45546a5", + "bytes": 799 + }, + "lib/common/html_re.mjs": { + "blob": "90071d8e4e037b771591435702ce19596a2187fd", + "sha256": "82021df92c9f3f856cd1bb59454c2033c50a0617a748acc150bbdacb8101abcc", + "bytes": 964 + }, + "lib/common/utils.mjs": { + "blob": "773ae8de738a0cb2512ee8cd9cb5f07abd581c72", + "sha256": "952160caa972e1d2e291dc284d8531f835b9eb7628c1e806c9cf95351c55afbe", + "bytes": 8350 + }, + "lib/helpers/index.mjs": { + "blob": "7ea30af9a05a53f45927213ac5e9298b7d5e3e93", + "sha256": "c5a73b8f46eaa0f027f06a309a362f885ec4467c99a581d798cbb6a3bac14965", + "bytes": 275 + }, + "lib/helpers/parse_link_destination.mjs": { + "blob": "31523ce226cf8fbeedd9d23f297af7b5190fdcbb", + "sha256": "0426a1489ec76c3e10c8b36bf5a286e97cca90a800e4e24a98b314835b790c1c", + "bytes": 1553 + }, + "lib/helpers/parse_link_label.mjs": { + "blob": "f1a53fa1f5b95327353922557f0d96117c0c2898", + "sha256": "70129adaa86dfd0f99e05971c51f865a3956775c045ccdc2ec8f2f2e0c0893aa", + "bytes": 985 + }, + "lib/helpers/parse_link_title.mjs": { + "blob": "4605647bf02e5c17b285cc62bb5923df788f3363", + "sha256": "c10fc0bd89f11eb982a865dcf525cf6f3bec328958bb4de752e3993b44eb9c7c", + "bytes": 1851 + }, + "lib/index.mjs": { + "blob": "482bf9eafa9b400b489d3c9eece82f9ed5b8e00c", + "sha256": "840746264c1655558e80752c663d745e4336e806978f74d4c678c5e21bab5158", + "bytes": 17899 + }, + "lib/parser_block.mjs": { + "blob": "36e0109377eee0e1b8a753c2ed6aef9fecdfbe5b", + "sha256": "ba9fe86713007b6c04e4381fc15500936ce3852eeaefe819350fa1a42eb10bd4", + "bytes": 3922 + }, + "lib/parser_core.mjs": { + "blob": "4337554c244677760755b38b3fdf2d0cc09fb11e", + "sha256": "d6789a1f7ef8ad05a64114b873ca18b4b5c8245fee02d2d7559a20bba93858ec", + "bytes": 1470 + }, + "lib/parser_inline.mjs": { + "blob": "9f7bb4c48662d96b158b4c98941d07e4186bceec", + "sha256": "67ed63ad6efecc6f03bf1dc40f01a0abec7c0e675053b7503847bd4b287f72e4", + "bytes": 5330 + }, + "lib/presets/commonmark.mjs": { + "blob": "7e705ad2f9b69fbbf10af716f7a61bc195d7744f", + "sha256": "0287ae7e457b4a18f049aa81a7ca39bbc543eb2e9b95718476a8fb16dc299eee", + "bytes": 1909 + }, + "lib/presets/default.mjs": { + "blob": "25402070ce0aaf39c9fbca0eb76ee6bc8a21ebd7", + "sha256": "f8b577995fcde6bd0fcb96524eb32a872d9e82874921956fda81477913a94cc9", + "bytes": 1281 + }, + "lib/presets/zero.mjs": { + "blob": "c83a48ee001f34a9c592853b7fb7cd72e9086259", + "sha256": "d88083cd3b6a87566b63950c99a810fa3228345a41cb1fe441f2d8139bb9e60f", + "bytes": 1652 + }, + "lib/renderer.mjs": { + "blob": "6466a173a2efdcc45de7b5cc3a4bd492b72fc867", + "sha256": "47750faf7a1f9dab8d3e984ee4c6a799c195130ff141c9cb1a98e13d7bf70cc2", + "bytes": 8927 + }, + "lib/ruler.mjs": { + "blob": "92c98e915e0b757121a783bc0aae727cb3e0bf94", + "sha256": "86b94f2a50df56a51ef6ee8bdfb23a6733e83a1efa2f58b3b166aebae84a7ce2", + "bytes": 8478 + }, + "lib/rules_block/blockquote.mjs": { + "blob": "4ac80be7dfe627008c464e99f00df68eaee1f36c", + "sha256": "d88eaf1c88489376a825e9de09031d17b6cf442ae5f420acce3619df94f5c899", + "bytes": 6048 + }, + "lib/rules_block/code.mjs": { + "blob": "27d608c0fcd79eefc514a508acf2d04e7b649d03", + "sha256": "5b5aad3b00bf175f55849ae44974944fc26a45d416440f3710d11c6213f49968", + "bytes": 680 + }, + "lib/rules_block/fence.mjs": { + "blob": "e78f70d7111e00d646a45b9a8b5584130b3ab260", + "sha256": "4434e2f70150df1490bd11eeea8bd20fe763f029c22fc21305b6376f068cfd21", + "bytes": 2402 + }, + "lib/rules_block/heading.mjs": { + "blob": "e4fbff73503e141a67cf2ad13d21668de313a7ab", + "sha256": "75e812fc9938775e55d7c4e840a856e557ef0f4a2ab27aec535d25c78c6e8d7c", + "bytes": 1497 + }, + "lib/rules_block/hr.mjs": { + "blob": "bc174af3814fccba6d5aaf144f6fb699dc03bb18", + "sha256": "2d786cf899247071a305d4fefcb3d41de707e31982997ebf134672497f20edc9", + "bytes": 1066 + }, + "lib/rules_block/html_block.mjs": { + "blob": "a27a2918039d5bfee7e34c954c1003ebb96fbefb", + "sha256": "d8e20eca3742fb8e5d3eae238de1afa962104d772df6dbccad604325940ca86b", + "bytes": 2820 + }, + "lib/rules_block/lheading.mjs": { + "blob": "660a2e1bf335c11e084655af128209c9f9fb6a6e", + "sha256": "ae83782c9a5bbcb69f3127a4541c1e27e6a46be86d4955bf840c5cd1a289a482", + "bytes": 2553 + }, + "lib/rules_block/list.mjs": { + "blob": "b02d1e1c1aafa8d2dcd10cd462df967782b6338b", + "sha256": "1f569f81b61a73094ea7c70a30b2d6d3577de26de2d55d5f8b9146027f2f8a5f", + "bytes": 9071 + }, + "lib/rules_block/paragraph.mjs": { + "blob": "d09db3ee3b9d5148e1991d55d8a88e3fbabfacfc", + "sha256": "be9534ba8fa1312ae6ab6e6ecd6e96173a5a3dd35e924b7751782675bb15dc9a", + "bytes": 1494 + }, + "lib/rules_block/reference.mjs": { + "blob": "21231680f7574d8199a89945268f9469100ddf9b", + "sha256": "8884a101e95de67d72b1fd3dfe3341bf52876132398d72a528481f662e0eecb6", + "bytes": 6482 + }, + "lib/rules_block/state_block.mjs": { + "blob": "b0e9cba7972f45e907c8a2a0d2ed6c445a4fbd34", + "sha256": "3f26d52f4fa67c5fa5f85346acf18f4139419b5dc8496056dd6050bd3a266860", + "bytes": 5874 + }, + "lib/rules_block/table.mjs": { + "blob": "2096344a7e1f78086fe6e2c35cbba04e04467701", + "sha256": "454553ff462fc68e353dad0f7b04ba1da46ee18acf88047dde8faf1873d64bca", + "bytes": 7083 + }, + "lib/rules_core/block.mjs": { + "blob": "1128f5a3c8215421b5e321393b6c778b2907e44e", + "sha256": "52ef23be5d9248275a5c0ff8b43602540bd3ed8a69bc63fbdc262b09c5de69b5", + "bytes": 318 + }, + "lib/rules_core/inline.mjs": { + "blob": "efd6c0706dd62e0a89ed0c6d4ab90d17159e3c4a", + "sha256": "0da70e72022dda01deaf6630a772a9c4798b6b6dc1d37144520b872d302b12a3", + "bytes": 289 + }, + "lib/rules_core/linkify.mjs": { + "blob": "9257818268c97e3eb3f5a0cc886ed7f446411405", + "sha256": "e68ac3597363b13a7451e65d9a7943ce99f4b57e9509eb62eebb1a3162423499", + "bytes": 4883 + }, + "lib/rules_core/normalize.mjs": { + "blob": "eb0aa363292a7d4070bb174fa4904f980fc4c0a1", + "sha256": "7f7fab952ebe0a0c16016835e1af0bf682af6e2eb5a28454eb350c28332cfa93", + "bytes": 345 + }, + "lib/rules_core/replacements.mjs": { + "blob": "b18ecd93b13a598680d4c38c602359ab47c11d3d", + "sha256": "9b3211580c89951bad60aa4550f76ebf2d2b81cc4523849ed34e6b85ed25ba3a", + "bytes": 2633 + }, + "lib/rules_core/smartquotes.mjs": { + "blob": "35e72df79820d297d37f93d28489ce0e45afd79c", + "sha256": "2d92309d2a0517b7ac74ba6780333996ff3bf0763e28464916f04befdddb4dee", + "bytes": 6685 + }, + "lib/rules_core/state_core.mjs": { + "blob": "a96c8fbcd1b68b50b422785696ccf211c99bdd54", + "sha256": "eb68c945733124231b5dc98d480854393b99fc069fd95703f4c36d310572e4f0", + "bytes": 325 + }, + "lib/rules_core/text_join.mjs": { + "blob": "ee8f87244df0fa406b1a2c8142ce80bdf817e1ad", + "sha256": "d61f0f19e2e49b565564a1537c46828c18da453516226d1637816021d4d68fce", + "bytes": 1147 + }, + "lib/rules_inline/autolink.mjs": { + "blob": "12b84e58b5c189e240dada28f2d1e0b1fd767bee", + "sha256": "78599ff3df236375e29dc63f04ad93ae1bb4744d7c47021b93104462cbfc61c5", + "bytes": 1977 + }, + "lib/rules_inline/backticks.mjs": { + "blob": "5b926d0724645688ae55daa4a06404d601272699", + "sha256": "8baed32815f895f72b0a01255c3180ba2e72fcffb51fbea7677ccf128dafbc40", + "bytes": 1674 + }, + "lib/rules_inline/balance_pairs.mjs": { + "blob": "37376839d560115f4294168facc7ca84520763a1", + "sha256": "06769d0aa4e5af875e504dea82db9bc726b463911e7b1c17f732098be95ad403", + "bytes": 4081 + }, + "lib/rules_inline/emphasis.mjs": { + "blob": "1d692bc995ac8dd930514fd6459685acb433f086", + "sha256": "23e1dbd2fdb408e257f2bbccccae1b1ee8a068db1c43a38b4edd9db76c2f40a1", + "bytes": 3500 + }, + "lib/rules_inline/entity.mjs": { + "blob": "38ac9086f0434581f6c529ff14522d694bf777e3", + "sha256": "37c2420b56e055ff150c13485a2322914974b0364a8d3823c3ef81318196c101", + "bytes": 1486 + }, + "lib/rules_inline/escape.mjs": { + "blob": "139c3f34b9f6acb3c5d4bee56c05aee42c0ba389", + "sha256": "f498e10cc6318f2a2856e51217e6c0f0a837b18dd920162d2cd6e49789b15adf", + "bytes": 1798 + }, + "lib/rules_inline/fragments_join.mjs": { + "blob": "e89ef9e340863a824af8f11fa1334c291bd5ba0c", + "sha256": "143e477737ce7565af95a6c5dbb854667a07d45e7f3e1b849fb68ba39937014c", + "bytes": 1267 + }, + "lib/rules_inline/html_inline.mjs": { + "blob": "18a4aa01506533fb812cd9a5e0e1f77b643f3b15", + "sha256": "f7bee2bd14c158e0178ef409ea84a5d330672094265fbd112673d23a75ff1924", + "bytes": 2347 + }, + "lib/rules_inline/image.mjs": { + "blob": "32cbb31117918d8dce550a35ec09b1abfb84f9f2", + "sha256": "67e1ad7ba6ce1a2ee0dfaee83653fec3f3e602f8d8841c4b8426c770b03870b4", + "bytes": 3638 + }, + "lib/rules_inline/link.mjs": { + "blob": "a6e2765106fe784891af6ff0061c2d9289f7da06", + "sha256": "a805f4cc75ad14b8b7838d408b703a9e26401badfd00a39a80a21e10a3af5cd0", + "bytes": 3723 + }, + "lib/rules_inline/linkify.mjs": { + "blob": "dcda6a87722747e2899c652c41f165b1bf46f84d", + "sha256": "3a55e9a5fa81bd7b924d4f7469452a7fa6ba999f5204ff076a64f5dc8477348e", + "bytes": 2640 + }, + "lib/rules_inline/newline.mjs": { + "blob": "2c0e3ae7ee4ea0d2f4591f7bf34e020daf917123", + "sha256": "4c51181f46d59ce1d40dfdec014d1eb69937de850eacfdd4fcb759f9f141e990", + "bytes": 1199 + }, + "lib/rules_inline/state_inline.mjs": { + "blob": "c496317a3946e0fddaee3bd6cefb911df61274e4", + "sha256": "f4b30bd182fea54a661528d6a031c2cdcb06c688a00fb5598c39cf8ae9554372", + "bytes": 4776 + }, + "lib/rules_inline/strikethrough.mjs": { + "blob": "6baaff6bd026e60aff10f82faa91ec771427e9a1", + "sha256": "cf130f8d2405731b5a2ed687ad7b4571baf9dbc3f98a472629c6553c1c6cb089", + "bytes": 2887 + }, + "lib/rules_inline/text.mjs": { + "blob": "9be42274c599ad2211de862104b979af134000d4", + "sha256": "63aca7fc12c4e44bbe8edb6b8cf38c8bf01e3aa1ef5dd0feef82aae930b1d0e8", + "bytes": 2101 + }, + "lib/token.mjs": { + "blob": "db247abd78d984e380fada603f6b9b839ff0b84e", + "sha256": "c6ebce7f456a6fef97e3cf2cd411418a80eb15ef469d7a7ea12405191cd5705f", + "bytes": 3762 + }, + "package.json": { + "blob": "4f37a27b1b7d97a29d06746e106c7edbc7a5dfae", + "sha256": "4e47c64787bcfe32c7a8bebc922e03cc5d007f389fc0f8c61199ab76bf7287e5", + "bytes": 3013 + } + } + }, + { + "name": "linkify-it", + "version": "5.0.2", + "origin": "https://github.com/markdown-it/linkify-it", + "tag": "5.0.2", + "commit": "50a0c914f834b201cab25ff4faefd1f832b37332", + "upstreamTree": "c8b101da7bbcff3a3de72621fc7e9abf31903eab", + "spdx": "MIT", + "license": "LICENSE", + "copyright": [ + "Copyright (c) 2015 Vitaly Puzrin." + ], + "files": { + "LICENSE": { + "blob": "67596f5f24007c3e42773400a7bfd57effe20160", + "sha256": "95e3f7f0e81e9b4940cdfaa1956aaff5e4dfd2fb1565041e7c78eb9a606f23e3", + "bytes": 1058 + }, + "index.mjs": { + "blob": "1c4706b4e595050aca1ea9e4ef0453454a6bbbd9", + "sha256": "b7cdca31306ba9d92b963134333e9ec71df74bd9d8a2c649e0e2f6c7468d92b1", + "bytes": 17725 + }, + "lib/re.mjs": { + "blob": "d9b98ce12486dc08a5df848d8174e6fd598e61a8", + "sha256": "ce32a3968ede95c9fe29fe505fec5c19ab0bb7f8eb5d7666ab3180910adc9cf8", + "bytes": 5655 + }, + "package.json": { + "blob": "3254731ac2af795eb47844e4b82ed399be4eec6c", + "sha256": "492ffef383ead25ddc4a7615129c3c41eafe1a0a10172680a93fbb5039c84204", + "bytes": 1551 + } + } + }, + { + "name": "uc.micro", + "version": "2.1.0", + "origin": "https://github.com/markdown-it/uc.micro", + "tag": "2.1.0", + "commit": "d91cec10974f125be7accd4dd870900fd18fdec7", + "upstreamTree": "085c2a8b6c255efbd5ccd1fb13c4fc012a3521da", + "spdx": "MIT", + "license": "LICENSE.txt", + "copyright": [ + "Copyright Mathias Bynens " + ], + "files": { + "LICENSE.txt": { + "blob": "a41e0a7ef970ecdd83d82cd99bda97b22077bc62", + "sha256": "483acb265f182907d1caf6cff9c16c96f31325ed23792832cc5d8b12d5f88c8a", + "bytes": 1077 + }, + "categories/Cc/regex.mjs": { + "blob": "91cd397c329881b6fa32bec459eb6b3eb716a57d", + "sha256": "d73b91600fd887bccf8f3a7ccb8a98d497222b2923064ca135cd3d86eecba9b8", + "bytes": 35 + }, + "categories/Cf/regex.mjs": { + "blob": "bb58c7d3ebc4e7486410c60124c4d3b3d70df836", + "sha256": "0ba760155f77b39359cf0ab088589444a68987facd696ae8fe7fc8b7ced5c5c5", + "bytes": 264 + }, + "categories/P/regex.mjs": { + "blob": "b0842645850a6d2c1931c56d342274291aa40157", + "sha256": "378c0a61fee0d8c911d0c6bff819a601571a95ac4296ac5068c56ea76291697f", + "bytes": 2042 + }, + "categories/S/regex.mjs": { + "blob": "45a2624c7e334185365b62b6acd20a41d3a34b9d", + "sha256": "53579876c2563673dbd3f14ad7ccbb0e232aa25f9398679f5d792b75fcbfa40e", + "bytes": 2551 + }, + "categories/Z/regex.mjs": { + "blob": "6f154197bb96936c95ae882c379b429dd0fb45f8", + "sha256": "32c50e92e9f4bab827145c99299616178f65192aedda27d0b9bf938a34c48325", + "bytes": 73 + }, + "index.mjs": { + "blob": "21b80d34acc9641737293d8c0555c26acdf515bb", + "sha256": "4c6142bf1f94e06fc9942639b651b22e7982a8ccc1427f694ffc6fdf49ef5087", + "bytes": 302 + }, + "package.json": { + "blob": "73102ce5a5a359a8c07b26ed5dc9d27f4a375dbc", + "sha256": "8b60af5ea73b0bac4d26111a3f5b00844657b998f9a3fd473710d9e33d274250", + "bytes": 813 + }, + "properties/Any/regex.mjs": { + "blob": "72d3b16d556ed9d16ce2a66384712a050f162b96", + "sha256": "41d50d9f5babe77f07305aec91f0e4bf29fd95980feb2a6592a3bbd077b313bc", + "bytes": 145 + } + } + }, + { + "name": "mdurl", + "version": "2.1.0", + "origin": "https://github.com/markdown-it/mdurl", + "tag": "2.1.0", + "commit": "dd913f6290a4d8772240a401aab993eb65c5786d", + "upstreamTree": "36d7a3131965a4e77531f549b89ecb73eede5080", + "spdx": "MIT", + "license": "LICENSE", + "copyright": [ + "Copyright (c) 2015 Vitaly Puzrin, Alex Kocharin.", + "Copyright Joyent, Inc. and other Node contributors. All rights reserved." + ], + "files": { + "LICENSE": { + "blob": "3b2c7bfb15fbe1447af858ed261007bf0ae69cce", + "sha256": "6b6a356c4337e2446841f30f3cdf7e7023af8c5260b5e347c0f987b9f6aa2644", + "bytes": 2303 + }, + "index.mjs": { + "blob": "fd78c377f575463bcf8760db59220cc0566bd584", + "sha256": "8ea430f1f8a107f529e2dac519d2f18e71ec9befe6f23f78bf6510cf86d3f9a0", + "bytes": 200 + }, + "lib/decode.mjs": { + "blob": "9fdc133f8b2e7507c0056cd1f8abc60aff45ea88", + "sha256": "d91544cfb42b9639073f5fa0f576bf72ef6697e848005357c433cad036c2ef20", + "bytes": 2843 + }, + "lib/encode.mjs": { + "blob": "7a0c35697598809d1a9b17a8bd087b65d0bb9801", + "sha256": "0ae621933b548f880404841b251b0f4fc2c8446ded699e6812def217250ac15d", + "bytes": 2211 + }, + "lib/format.mjs": { + "blob": "4b76000158858fd0f18244ce71d914ffd0cd002d", + "sha256": "2410ec324b913a42c572e01ae49436e5fa4e2e5fbea15c08c92a6dea8bc5887d", + "bytes": 485 + }, + "lib/parse.mjs": { + "blob": "fac50650321f4d00e7769eec9828f63bf5ccb8c5", + "sha256": "2a417b42e9ea8ee94fc77c596a34eb206d6c69823484e89d80bf1e7583d8f91d", + "bytes": 9733 + }, + "package.json": { + "blob": "6e8b7680cf1576053398fe05eb3e4423974b9c49", + "sha256": "807e00f99605ba97f4953f8ceb6a65db877d23a9f5496ae367eb953c0e4e627d", + "bytes": 1110 + } + } + }, + { + "name": "punycode.js", + "version": "2.3.1", + "origin": "https://github.com/mathiasbynens/punycode.js", + "tag": "v2.3.1", + "commit": "9e1b2cda98d215d3a73fcbfe93c62e021f4ba768", + "upstreamTree": "f95d544642e1599cd27de41416654b7b7a950031", + "spdx": "MIT", + "license": "LICENSE-MIT.txt", + "copyright": [ + "Copyright Mathias Bynens " + ], + "files": { + "LICENSE-MIT.txt": { + "blob": "a41e0a7ef970ecdd83d82cd99bda97b22077bc62", + "sha256": "483acb265f182907d1caf6cff9c16c96f31325ed23792832cc5d8b12d5f88c8a", + "bytes": 1077 + }, + "package.json": { + "blob": "b8b76fc76c2162104f066c6f2330a7cacdee4a72", + "sha256": "e025033bd11110af671fb8eb62f0db8895073ccdca70b596aa94a27eb5bf9acb", + "bytes": 1227 + }, + "punycode.js": { + "blob": "a1ef251924c81e2cf620132f7765058c690eeb6e", + "sha256": "6052a80eac47e46bd4de17ae0095e0192c336d3d7c387d292ad2176ebfc53d04", + "bytes": 12711 + } + } + }, + { + "name": "entities", + "version": "4.5.0", + "origin": "https://github.com/fb55/entities", + "tag": "v4.5.0", + "commit": "61afd4701eaa736978b13c7351cd3de9a96b04bc", + "upstreamTree": "23f047805a33dc7ce35dbdb137c947e5526d8d5c", + "spdx": "BSD-2-Clause", + "license": "LICENSE", + "copyright": [ + "Copyright (c) Felix Böhm" + ], + "files": { + "LICENSE": { + "blob": "c464f863ea2b18a15ca3883bc5d98065ed5d039a", + "sha256": "cb992345949ccd6e8394b2cd6c465f7b897c864f845937dbf64e8997f389e164", + "bytes": 1260 + }, + "package.json": { + "blob": "2e857f8cf555d6895eafe74781139751595ce5d6", + "sha256": "c92f657f679669a91bc32cd98f0b4812b3f4a9c6f3b3af3022a70cb25b7efc7c", + "bytes": 2883 + }, + "src/decode.ts": { + "blob": "a55fea11a58e3d87981710cac8f6121e4a0a9938", + "sha256": "38a42d441b67aa4f6397a2edbc57a2845110f2f64c18c56c931f1ac55179be94", + "bytes": 19879 + }, + "src/decode_codepoint.ts": { + "blob": "a0f17b4800c5f0ed7cf8e584cbf3f9a480a9ee83", + "sha256": "7467c31bd84fed848ee0b1b7b4ec100ffe387fb2802ef0fa66307744a45f331c", + "bytes": 2098 + }, + "src/encode.ts": { + "blob": "c1676e47a69d0c886585c3f811c6a6889263c3f8", + "sha256": "e40bad527b5c9a1d5b9e0e7d0b8643328cb4d9e1b2d79777a367b81bcec3e09b", + "bytes": 2628 + }, + "src/escape.ts": { + "blob": "c4183f91e4424b94139e6f25425bf60b67288763", + "sha256": "c062e448b06654fa3c99a04e89bc53bc4463bf5e5cf65ac711f372a77e22639f", + "bytes": 4272 + }, + "src/generated/decode-data-html.ts": { + "blob": "90ee62b4243c3a7d554bff739a7339644404e204", + "sha256": "99bd4f1a69db8431bf58444e6c38a8b60f2a1820e1ce5781c851c1914a8822c4", + "bytes": 47698 + }, + "src/generated/decode-data-xml.ts": { + "blob": "d36c066f7bfc4bbb9fc230497be5ac78e2b29c87", + "sha256": "701497193dd355232513b7e4a7c6fea4d856eb33d5116c61cda4d59028d4790b", + "bytes": 254 + }, + "src/generated/encode-html.ts": { + "blob": "aba0f556df53100f12257ea081f8b77da24a30ac", + "sha256": "409c7a156de66f45037fa684afaa6147f98d8860274ef0218f02a16c993cb103", + "bytes": 23902 + }, + "src/index.ts": { + "blob": "c9ff92da958a56665fa741e9e0df09a5b490d1c5", + "sha256": "6487bfc6a09ad4211e1264ccd7d21fbce19bfcfd06eba8b83cb80537f0109687", + "bytes": 4673 + } + } + }, + { + "name": "orderedmap", + "version": "2.1.1", + "origin": "https://github.com/marijnh/orderedmap", + "tag": "2.1.1", + "commit": "6a30ebbbecd30fed8bda884c7acf4ca9c6a02405", + "upstreamTree": "49c032b36195f4f3eb5bdf3aa9a0a7b70b0d523c", + "spdx": "MIT", + "license": "LICENSE", + "copyright": [ + "Copyright (C) 2016 by Marijn Haverbeke and others" + ], + "files": { + "LICENSE": { + "blob": "17da88ae48508e163d0b31cf4780abe6cb8b7fed", + "sha256": "869c30f368eb08735e779027b9f4bc9fea2f39624351856aebe42741f0bc0884", + "bytes": 1100 + }, + "index.js": { + "blob": "dcb98051df844135dcdec2d4eedd4a76b5618826", + "sha256": "eb0160f63616895337d3b99b8e445d07327ef283f6b525dbcdce7f11efc7a641", + "bytes": 4392 + }, + "package.json": { + "blob": "f4d851a2f52efa07b301c612c9ed9ab5e9d33677", + "sha256": "282ea598284094608736ed5a75f4e0b48da53b851b62bba22362feac507d5c6c", + "bytes": 881 + } + } + }, + { + "name": "rope-sequence", + "version": "1.3.4", + "origin": "https://github.com/marijnh/rope-sequence", + "tag": "1.3.4", + "commit": "11db1ba5aa2abf31ff8040bdf01fabdb9db34c7a", + "upstreamTree": "4006f2f2db7ababcbe84527ccc71afc6b69c19b3", + "spdx": "MIT", + "license": "LICENSE", + "copyright": [ + "Copyright (C) 2016 by Marijn Haverbeke " + ], + "files": { + "LICENSE": { + "blob": "602adc305b08d5403019c06b8301ca20ee89a047", + "sha256": "530424aebdd0e73f53238d1f89df250057bc8d8ce090cf5954197fadce5bf226", + "bytes": 1089 + }, + "index.js": { + "blob": "2f2f918702ce1b07f669829695a9faae2231aa5d", + "sha256": "efb85fca2ecef4b1dfd63103cfb8c755ff209ffe6e72ae0928e833c3ac666624", + "bytes": 5682 + }, + "package.json": { + "blob": "13a1fd21566c3622981af1982021bbd1f6e99a9f", + "sha256": "0e378a9dcc447c04e712238d60a1f2ffb878bfc161cbb95ef0a3c34d2a541548", + "bytes": 745 + } + } + }, + { + "name": "w3c-keyname", + "version": "2.2.8", + "origin": "https://github.com/marijnh/w3c-keyname", + "tag": "2.2.8", + "commit": "5ea93b04bb62230c7de4165e3a9b5c840f05cd44", + "upstreamTree": "d6851bd96544a49c9ffd99a0b0eae920656b098d", + "spdx": "MIT", + "license": "LICENSE", + "copyright": [ + "Copyright (C) 2016 by Marijn Haverbeke and others" + ], + "files": { + "LICENSE": { + "blob": "17da88ae48508e163d0b31cf4780abe6cb8b7fed", + "sha256": "869c30f368eb08735e779027b9f4bc9fea2f39624351856aebe42741f0bc0884", + "bytes": 1100 + }, + "index.js": { + "blob": "bc6d88ecfb2f0f2a156bb25167b9a1181aa07f92", + "sha256": "b649dec4f01c7c5eb05be4641b5b698c6938231ee50b38e17a2f0f822ca3df2e", + "bytes": 2630 + }, + "package.json": { + "blob": "eb858fb81849157656715dc5c6a1832d866ef644", + "sha256": "0396c646f74d52c1b0851074ecdb5cabf540af595ceb5e5a5136df2bf3c2f83b", + "bytes": 842 + } + } + } + ] +} diff --git a/packages/webui/third_party/editor/entities/LICENSE b/packages/webui/third_party/editor/entities/LICENSE new file mode 100644 index 000000000..c464f863e --- /dev/null +++ b/packages/webui/third_party/editor/entities/LICENSE @@ -0,0 +1,11 @@ +Copyright (c) Felix Böhm +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + +Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + +THIS IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS, +EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/packages/webui/third_party/editor/entities/package.json b/packages/webui/third_party/editor/entities/package.json new file mode 100644 index 000000000..2e857f8cf --- /dev/null +++ b/packages/webui/third_party/editor/entities/package.json @@ -0,0 +1,90 @@ +{ + "name": "entities", + "version": "4.5.0", + "description": "Encode & decode XML and HTML entities with ease & speed", + "author": "Felix Boehm ", + "funding": "https://github.com/fb55/entities?sponsor=1", + "sideEffects": false, + "keywords": [ + "entity", + "decoding", + "encoding", + "html", + "xml", + "html entities" + ], + "directories": { + "lib": "lib/" + }, + "main": "lib/index.js", + "types": "lib/index.d.ts", + "module": "lib/esm/index.js", + "exports": { + ".": { + "require": "./lib/index.js", + "import": "./lib/esm/index.js" + }, + "./lib/decode.js": { + "require": "./lib/decode.js", + "import": "./lib/esm/decode.js" + }, + "./lib/escape.js": { + "require": "./lib/escape.js", + "import": "./lib/esm/escape.js" + } + }, + "files": [ + "lib/**/*" + ], + "engines": { + "node": ">=0.12" + }, + "devDependencies": { + "@types/jest": "^28.1.8", + "@types/node": "^18.15.11", + "@typescript-eslint/eslint-plugin": "^5.58.0", + "@typescript-eslint/parser": "^5.58.0", + "eslint": "^8.38.0", + "eslint-config-prettier": "^8.8.0", + "eslint-plugin-node": "^11.1.0", + "jest": "^28.1.3", + "prettier": "^2.8.7", + "ts-jest": "^28.0.8", + "typedoc": "^0.24.1", + "typescript": "^5.0.4" + }, + "scripts": { + "test": "npm run test:jest && npm run lint", + "test:jest": "jest", + "lint": "npm run lint:es && npm run lint:prettier", + "lint:es": "eslint .", + "lint:prettier": "npm run prettier -- --check", + "format": "npm run format:es && npm run format:prettier", + "format:es": "npm run lint:es -- --fix", + "format:prettier": "npm run prettier -- --write", + "prettier": "prettier '**/*.{ts,md,json,yml}'", + "build": "npm run build:cjs && npm run build:esm", + "build:cjs": "tsc --sourceRoot https://raw.githubusercontent.com/fb55/entities/$(git rev-parse HEAD)/src/", + "build:esm": "npm run build:cjs -- --module esnext --target es2019 --outDir lib/esm && echo '{\"type\":\"module\"}' > lib/esm/package.json", + "build:docs": "typedoc --hideGenerator src/index.ts", + "build:trie": "ts-node scripts/write-decode-map.ts", + "build:encode-trie": "ts-node scripts/write-encode-map.ts", + "prepare": "npm run build" + }, + "repository": { + "type": "git", + "url": "git://github.com/fb55/entities.git" + }, + "license": "BSD-2-Clause", + "jest": { + "preset": "ts-jest", + "coverageProvider": "v8", + "moduleNameMapper": { + "^(.*)\\.js$": "$1" + } + }, + "prettier": { + "tabWidth": 4, + "proseWrap": "always" + } +} diff --git a/packages/webui/third_party/editor/entities/src/decode.ts b/packages/webui/third_party/editor/entities/src/decode.ts new file mode 100644 index 000000000..a55fea11a --- /dev/null +++ b/packages/webui/third_party/editor/entities/src/decode.ts @@ -0,0 +1,614 @@ +import htmlDecodeTree from "./generated/decode-data-html.js"; +import xmlDecodeTree from "./generated/decode-data-xml.js"; +import decodeCodePoint, { + replaceCodePoint, + fromCodePoint, +} from "./decode_codepoint.js"; + +// Re-export for use by eg. htmlparser2 +export { htmlDecodeTree, xmlDecodeTree, decodeCodePoint }; +export { replaceCodePoint, fromCodePoint } from "./decode_codepoint.js"; + +const enum CharCodes { + NUM = 35, // "#" + SEMI = 59, // ";" + EQUALS = 61, // "=" + ZERO = 48, // "0" + NINE = 57, // "9" + LOWER_A = 97, // "a" + LOWER_F = 102, // "f" + LOWER_X = 120, // "x" + LOWER_Z = 122, // "z" + UPPER_A = 65, // "A" + UPPER_F = 70, // "F" + UPPER_Z = 90, // "Z" +} + +/** Bit that needs to be set to convert an upper case ASCII character to lower case */ +const TO_LOWER_BIT = 0b100000; + +export enum BinTrieFlags { + VALUE_LENGTH = 0b1100_0000_0000_0000, + BRANCH_LENGTH = 0b0011_1111_1000_0000, + JUMP_TABLE = 0b0000_0000_0111_1111, +} + +function isNumber(code: number): boolean { + return code >= CharCodes.ZERO && code <= CharCodes.NINE; +} + +function isHexadecimalCharacter(code: number): boolean { + return ( + (code >= CharCodes.UPPER_A && code <= CharCodes.UPPER_F) || + (code >= CharCodes.LOWER_A && code <= CharCodes.LOWER_F) + ); +} + +function isAsciiAlphaNumeric(code: number): boolean { + return ( + (code >= CharCodes.UPPER_A && code <= CharCodes.UPPER_Z) || + (code >= CharCodes.LOWER_A && code <= CharCodes.LOWER_Z) || + isNumber(code) + ); +} + +/** + * Checks if the given character is a valid end character for an entity in an attribute. + * + * Attribute values that aren't terminated properly aren't parsed, and shouldn't lead to a parser error. + * See the example in https://html.spec.whatwg.org/multipage/parsing.html#named-character-reference-state + */ +function isEntityInAttributeInvalidEnd(code: number): boolean { + return code === CharCodes.EQUALS || isAsciiAlphaNumeric(code); +} + +const enum EntityDecoderState { + EntityStart, + NumericStart, + NumericDecimal, + NumericHex, + NamedEntity, +} + +export enum DecodingMode { + /** Entities in text nodes that can end with any character. */ + Legacy = 0, + /** Only allow entities terminated with a semicolon. */ + Strict = 1, + /** Entities in attributes have limitations on ending characters. */ + Attribute = 2, +} + +/** + * Producers for character reference errors as defined in the HTML spec. + */ +export interface EntityErrorProducer { + missingSemicolonAfterCharacterReference(): void; + absenceOfDigitsInNumericCharacterReference( + consumedCharacters: number + ): void; + validateNumericCharacterReference(code: number): void; +} + +/** + * Token decoder with support of writing partial entities. + */ +export class EntityDecoder { + constructor( + /** The tree used to decode entities. */ + private readonly decodeTree: Uint16Array, + /** + * The function that is called when a codepoint is decoded. + * + * For multi-byte named entities, this will be called multiple times, + * with the second codepoint, and the same `consumed` value. + * + * @param codepoint The decoded codepoint. + * @param consumed The number of bytes consumed by the decoder. + */ + private readonly emitCodePoint: (cp: number, consumed: number) => void, + /** An object that is used to produce errors. */ + private readonly errors?: EntityErrorProducer + ) {} + + /** The current state of the decoder. */ + private state = EntityDecoderState.EntityStart; + /** Characters that were consumed while parsing an entity. */ + private consumed = 1; + /** + * The result of the entity. + * + * Either the result index of a numeric entity, or the codepoint of a + * numeric entity. + */ + private result = 0; + + /** The current index in the decode tree. */ + private treeIndex = 0; + /** The number of characters that were consumed in excess. */ + private excess = 1; + /** The mode in which the decoder is operating. */ + private decodeMode = DecodingMode.Strict; + + /** Resets the instance to make it reusable. */ + startEntity(decodeMode: DecodingMode): void { + this.decodeMode = decodeMode; + this.state = EntityDecoderState.EntityStart; + this.result = 0; + this.treeIndex = 0; + this.excess = 1; + this.consumed = 1; + } + + /** + * Write an entity to the decoder. This can be called multiple times with partial entities. + * If the entity is incomplete, the decoder will return -1. + * + * Mirrors the implementation of `getDecoder`, but with the ability to stop decoding if the + * entity is incomplete, and resume when the next string is written. + * + * @param string The string containing the entity (or a continuation of the entity). + * @param offset The offset at which the entity begins. Should be 0 if this is not the first call. + * @returns The number of characters that were consumed, or -1 if the entity is incomplete. + */ + write(str: string, offset: number): number { + switch (this.state) { + case EntityDecoderState.EntityStart: { + if (str.charCodeAt(offset) === CharCodes.NUM) { + this.state = EntityDecoderState.NumericStart; + this.consumed += 1; + return this.stateNumericStart(str, offset + 1); + } + this.state = EntityDecoderState.NamedEntity; + return this.stateNamedEntity(str, offset); + } + + case EntityDecoderState.NumericStart: { + return this.stateNumericStart(str, offset); + } + + case EntityDecoderState.NumericDecimal: { + return this.stateNumericDecimal(str, offset); + } + + case EntityDecoderState.NumericHex: { + return this.stateNumericHex(str, offset); + } + + case EntityDecoderState.NamedEntity: { + return this.stateNamedEntity(str, offset); + } + } + } + + /** + * Switches between the numeric decimal and hexadecimal states. + * + * Equivalent to the `Numeric character reference state` in the HTML spec. + * + * @param str The string containing the entity (or a continuation of the entity). + * @param offset The current offset. + * @returns The number of characters that were consumed, or -1 if the entity is incomplete. + */ + private stateNumericStart(str: string, offset: number): number { + if (offset >= str.length) { + return -1; + } + + if ((str.charCodeAt(offset) | TO_LOWER_BIT) === CharCodes.LOWER_X) { + this.state = EntityDecoderState.NumericHex; + this.consumed += 1; + return this.stateNumericHex(str, offset + 1); + } + + this.state = EntityDecoderState.NumericDecimal; + return this.stateNumericDecimal(str, offset); + } + + private addToNumericResult( + str: string, + start: number, + end: number, + base: number + ): void { + if (start !== end) { + const digitCount = end - start; + this.result = + this.result * Math.pow(base, digitCount) + + parseInt(str.substr(start, digitCount), base); + this.consumed += digitCount; + } + } + + /** + * Parses a hexadecimal numeric entity. + * + * Equivalent to the `Hexademical character reference state` in the HTML spec. + * + * @param str The string containing the entity (or a continuation of the entity). + * @param offset The current offset. + * @returns The number of characters that were consumed, or -1 if the entity is incomplete. + */ + private stateNumericHex(str: string, offset: number): number { + const startIdx = offset; + + while (offset < str.length) { + const char = str.charCodeAt(offset); + if (isNumber(char) || isHexadecimalCharacter(char)) { + offset += 1; + } else { + this.addToNumericResult(str, startIdx, offset, 16); + return this.emitNumericEntity(char, 3); + } + } + + this.addToNumericResult(str, startIdx, offset, 16); + + return -1; + } + + /** + * Parses a decimal numeric entity. + * + * Equivalent to the `Decimal character reference state` in the HTML spec. + * + * @param str The string containing the entity (or a continuation of the entity). + * @param offset The current offset. + * @returns The number of characters that were consumed, or -1 if the entity is incomplete. + */ + private stateNumericDecimal(str: string, offset: number): number { + const startIdx = offset; + + while (offset < str.length) { + const char = str.charCodeAt(offset); + if (isNumber(char)) { + offset += 1; + } else { + this.addToNumericResult(str, startIdx, offset, 10); + return this.emitNumericEntity(char, 2); + } + } + + this.addToNumericResult(str, startIdx, offset, 10); + + return -1; + } + + /** + * Validate and emit a numeric entity. + * + * Implements the logic from the `Hexademical character reference start + * state` and `Numeric character reference end state` in the HTML spec. + * + * @param lastCp The last code point of the entity. Used to see if the + * entity was terminated with a semicolon. + * @param expectedLength The minimum number of characters that should be + * consumed. Used to validate that at least one digit + * was consumed. + * @returns The number of characters that were consumed. + */ + private emitNumericEntity(lastCp: number, expectedLength: number): number { + // Ensure we consumed at least one digit. + if (this.consumed <= expectedLength) { + this.errors?.absenceOfDigitsInNumericCharacterReference( + this.consumed + ); + return 0; + } + + // Figure out if this is a legit end of the entity + if (lastCp === CharCodes.SEMI) { + this.consumed += 1; + } else if (this.decodeMode === DecodingMode.Strict) { + return 0; + } + + this.emitCodePoint(replaceCodePoint(this.result), this.consumed); + + if (this.errors) { + if (lastCp !== CharCodes.SEMI) { + this.errors.missingSemicolonAfterCharacterReference(); + } + + this.errors.validateNumericCharacterReference(this.result); + } + + return this.consumed; + } + + /** + * Parses a named entity. + * + * Equivalent to the `Named character reference state` in the HTML spec. + * + * @param str The string containing the entity (or a continuation of the entity). + * @param offset The current offset. + * @returns The number of characters that were consumed, or -1 if the entity is incomplete. + */ + private stateNamedEntity(str: string, offset: number): number { + const { decodeTree } = this; + let current = decodeTree[this.treeIndex]; + // The mask is the number of bytes of the value, including the current byte. + let valueLength = (current & BinTrieFlags.VALUE_LENGTH) >> 14; + + for (; offset < str.length; offset++, this.excess++) { + const char = str.charCodeAt(offset); + + this.treeIndex = determineBranch( + decodeTree, + current, + this.treeIndex + Math.max(1, valueLength), + char + ); + + if (this.treeIndex < 0) { + return this.result === 0 || + // If we are parsing an attribute + (this.decodeMode === DecodingMode.Attribute && + // We shouldn't have consumed any characters after the entity, + (valueLength === 0 || + // And there should be no invalid characters. + isEntityInAttributeInvalidEnd(char))) + ? 0 + : this.emitNotTerminatedNamedEntity(); + } + + current = decodeTree[this.treeIndex]; + valueLength = (current & BinTrieFlags.VALUE_LENGTH) >> 14; + + // If the branch is a value, store it and continue + if (valueLength !== 0) { + // If the entity is terminated by a semicolon, we are done. + if (char === CharCodes.SEMI) { + return this.emitNamedEntityData( + this.treeIndex, + valueLength, + this.consumed + this.excess + ); + } + + // If we encounter a non-terminated (legacy) entity while parsing strictly, then ignore it. + if (this.decodeMode !== DecodingMode.Strict) { + this.result = this.treeIndex; + this.consumed += this.excess; + this.excess = 0; + } + } + } + + return -1; + } + + /** + * Emit a named entity that was not terminated with a semicolon. + * + * @returns The number of characters consumed. + */ + private emitNotTerminatedNamedEntity(): number { + const { result, decodeTree } = this; + + const valueLength = + (decodeTree[result] & BinTrieFlags.VALUE_LENGTH) >> 14; + + this.emitNamedEntityData(result, valueLength, this.consumed); + this.errors?.missingSemicolonAfterCharacterReference(); + + return this.consumed; + } + + /** + * Emit a named entity. + * + * @param result The index of the entity in the decode tree. + * @param valueLength The number of bytes in the entity. + * @param consumed The number of characters consumed. + * + * @returns The number of characters consumed. + */ + private emitNamedEntityData( + result: number, + valueLength: number, + consumed: number + ): number { + const { decodeTree } = this; + + this.emitCodePoint( + valueLength === 1 + ? decodeTree[result] & ~BinTrieFlags.VALUE_LENGTH + : decodeTree[result + 1], + consumed + ); + if (valueLength === 3) { + // For multi-byte values, we need to emit the second byte. + this.emitCodePoint(decodeTree[result + 2], consumed); + } + + return consumed; + } + + /** + * Signal to the parser that the end of the input was reached. + * + * Remaining data will be emitted and relevant errors will be produced. + * + * @returns The number of characters consumed. + */ + end(): number { + switch (this.state) { + case EntityDecoderState.NamedEntity: { + // Emit a named entity if we have one. + return this.result !== 0 && + (this.decodeMode !== DecodingMode.Attribute || + this.result === this.treeIndex) + ? this.emitNotTerminatedNamedEntity() + : 0; + } + // Otherwise, emit a numeric entity if we have one. + case EntityDecoderState.NumericDecimal: { + return this.emitNumericEntity(0, 2); + } + case EntityDecoderState.NumericHex: { + return this.emitNumericEntity(0, 3); + } + case EntityDecoderState.NumericStart: { + this.errors?.absenceOfDigitsInNumericCharacterReference( + this.consumed + ); + return 0; + } + case EntityDecoderState.EntityStart: { + // Return 0 if we have no entity. + return 0; + } + } + } +} + +/** + * Creates a function that decodes entities in a string. + * + * @param decodeTree The decode tree. + * @returns A function that decodes entities in a string. + */ +function getDecoder(decodeTree: Uint16Array) { + let ret = ""; + const decoder = new EntityDecoder( + decodeTree, + (str) => (ret += fromCodePoint(str)) + ); + + return function decodeWithTrie( + str: string, + decodeMode: DecodingMode + ): string { + let lastIndex = 0; + let offset = 0; + + while ((offset = str.indexOf("&", offset)) >= 0) { + ret += str.slice(lastIndex, offset); + + decoder.startEntity(decodeMode); + + const len = decoder.write( + str, + // Skip the "&" + offset + 1 + ); + + if (len < 0) { + lastIndex = offset + decoder.end(); + break; + } + + lastIndex = offset + len; + // If `len` is 0, skip the current `&` and continue. + offset = len === 0 ? lastIndex + 1 : lastIndex; + } + + const result = ret + str.slice(lastIndex); + + // Make sure we don't keep a reference to the final string. + ret = ""; + + return result; + }; +} + +/** + * Determines the branch of the current node that is taken given the current + * character. This function is used to traverse the trie. + * + * @param decodeTree The trie. + * @param current The current node. + * @param nodeIdx The index right after the current node and its value. + * @param char The current character. + * @returns The index of the next node, or -1 if no branch is taken. + */ +export function determineBranch( + decodeTree: Uint16Array, + current: number, + nodeIdx: number, + char: number +): number { + const branchCount = (current & BinTrieFlags.BRANCH_LENGTH) >> 7; + const jumpOffset = current & BinTrieFlags.JUMP_TABLE; + + // Case 1: Single branch encoded in jump offset + if (branchCount === 0) { + return jumpOffset !== 0 && char === jumpOffset ? nodeIdx : -1; + } + + // Case 2: Multiple branches encoded in jump table + if (jumpOffset) { + const value = char - jumpOffset; + + return value < 0 || value >= branchCount + ? -1 + : decodeTree[nodeIdx + value] - 1; + } + + // Case 3: Multiple branches encoded in dictionary + + // Binary search for the character. + let lo = nodeIdx; + let hi = lo + branchCount - 1; + + while (lo <= hi) { + const mid = (lo + hi) >>> 1; + const midVal = decodeTree[mid]; + + if (midVal < char) { + lo = mid + 1; + } else if (midVal > char) { + hi = mid - 1; + } else { + return decodeTree[mid + branchCount]; + } + } + + return -1; +} + +const htmlDecoder = getDecoder(htmlDecodeTree); +const xmlDecoder = getDecoder(xmlDecodeTree); + +/** + * Decodes an HTML string. + * + * @param str The string to decode. + * @param mode The decoding mode. + * @returns The decoded string. + */ +export function decodeHTML(str: string, mode = DecodingMode.Legacy): string { + return htmlDecoder(str, mode); +} + +/** + * Decodes an HTML string in an attribute. + * + * @param str The string to decode. + * @returns The decoded string. + */ +export function decodeHTMLAttribute(str: string): string { + return htmlDecoder(str, DecodingMode.Attribute); +} + +/** + * Decodes an HTML string, requiring all entities to be terminated by a semicolon. + * + * @param str The string to decode. + * @returns The decoded string. + */ +export function decodeHTMLStrict(str: string): string { + return htmlDecoder(str, DecodingMode.Strict); +} + +/** + * Decodes an XML string, requiring all entities to be terminated by a semicolon. + * + * @param str The string to decode. + * @returns The decoded string. + */ +export function decodeXML(str: string): string { + return xmlDecoder(str, DecodingMode.Strict); +} diff --git a/packages/webui/third_party/editor/entities/src/decode_codepoint.ts b/packages/webui/third_party/editor/entities/src/decode_codepoint.ts new file mode 100644 index 000000000..a0f17b480 --- /dev/null +++ b/packages/webui/third_party/editor/entities/src/decode_codepoint.ts @@ -0,0 +1,78 @@ +// Adapted from https://github.com/mathiasbynens/he/blob/36afe179392226cf1b6ccdb16ebbb7a5a844d93a/src/he.js#L106-L134 + +const decodeMap = new Map([ + [0, 65533], + // C1 Unicode control character reference replacements + [128, 8364], + [130, 8218], + [131, 402], + [132, 8222], + [133, 8230], + [134, 8224], + [135, 8225], + [136, 710], + [137, 8240], + [138, 352], + [139, 8249], + [140, 338], + [142, 381], + [145, 8216], + [146, 8217], + [147, 8220], + [148, 8221], + [149, 8226], + [150, 8211], + [151, 8212], + [152, 732], + [153, 8482], + [154, 353], + [155, 8250], + [156, 339], + [158, 382], + [159, 376], +]); + +/** + * Polyfill for `String.fromCodePoint`. It is used to create a string from a Unicode code point. + */ +export const fromCodePoint = + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, node/no-unsupported-features/es-builtins + String.fromCodePoint ?? + function (codePoint: number): string { + let output = ""; + + if (codePoint > 0xffff) { + codePoint -= 0x10000; + output += String.fromCharCode( + ((codePoint >>> 10) & 0x3ff) | 0xd800 + ); + codePoint = 0xdc00 | (codePoint & 0x3ff); + } + + output += String.fromCharCode(codePoint); + return output; + }; + +/** + * Replace the given code point with a replacement character if it is a + * surrogate or is outside the valid range. Otherwise return the code + * point unchanged. + */ +export function replaceCodePoint(codePoint: number) { + if ((codePoint >= 0xd800 && codePoint <= 0xdfff) || codePoint > 0x10ffff) { + return 0xfffd; + } + + return decodeMap.get(codePoint) ?? codePoint; +} + +/** + * Replace the code point if relevant, then convert it to a string. + * + * @deprecated Use `fromCodePoint(replaceCodePoint(codePoint))` instead. + * @param codePoint The code point to decode. + * @returns The decoded code point. + */ +export default function decodeCodePoint(codePoint: number): string { + return fromCodePoint(replaceCodePoint(codePoint)); +} diff --git a/packages/webui/third_party/editor/entities/src/encode.ts b/packages/webui/third_party/editor/entities/src/encode.ts new file mode 100644 index 000000000..c1676e47a --- /dev/null +++ b/packages/webui/third_party/editor/entities/src/encode.ts @@ -0,0 +1,77 @@ +import htmlTrie from "./generated/encode-html.js"; +import { xmlReplacer, getCodePoint } from "./escape.js"; + +const htmlReplacer = /[\t\n!-,./:-@[-`\f{-}$\x80-\uFFFF]/g; + +/** + * Encodes all characters in the input using HTML entities. This includes + * characters that are valid ASCII characters in HTML documents, such as `#`. + * + * To get a more compact output, consider using the `encodeNonAsciiHTML` + * function, which will only encode characters that are not valid in HTML + * documents, as well as non-ASCII characters. + * + * If a character has no equivalent entity, a numeric hexadecimal reference + * (eg. `ü`) will be used. + */ +export function encodeHTML(data: string): string { + return encodeHTMLTrieRe(htmlReplacer, data); +} +/** + * Encodes all non-ASCII characters, as well as characters not valid in HTML + * documents using HTML entities. This function will not encode characters that + * are valid in HTML documents, such as `#`. + * + * If a character has no equivalent entity, a numeric hexadecimal reference + * (eg. `ü`) will be used. + */ +export function encodeNonAsciiHTML(data: string): string { + return encodeHTMLTrieRe(xmlReplacer, data); +} + +function encodeHTMLTrieRe(regExp: RegExp, str: string): string { + let ret = ""; + let lastIdx = 0; + let match; + + while ((match = regExp.exec(str)) !== null) { + const i = match.index; + ret += str.substring(lastIdx, i); + const char = str.charCodeAt(i); + let next = htmlTrie.get(char); + + if (typeof next === "object") { + // We are in a branch. Try to match the next char. + if (i + 1 < str.length) { + const nextChar = str.charCodeAt(i + 1); + const value = + typeof next.n === "number" + ? next.n === nextChar + ? next.o + : undefined + : next.n.get(nextChar); + + if (value !== undefined) { + ret += value; + lastIdx = regExp.lastIndex += 1; + continue; + } + } + + next = next.v; + } + + // We might have a tree node without a value; skip and use a numeric entity. + if (next !== undefined) { + ret += next; + lastIdx = i + 1; + } else { + const cp = getCodePoint(str, i); + ret += `&#x${cp.toString(16)};`; + // Increase by 1 if we have a surrogate pair + lastIdx = regExp.lastIndex += Number(cp !== char); + } + } + + return ret + str.substr(lastIdx); +} diff --git a/packages/webui/third_party/editor/entities/src/escape.ts b/packages/webui/third_party/editor/entities/src/escape.ts new file mode 100644 index 000000000..c4183f91e --- /dev/null +++ b/packages/webui/third_party/editor/entities/src/escape.ts @@ -0,0 +1,144 @@ +export const xmlReplacer = /["&'<>$\x80-\uFFFF]/g; + +const xmlCodeMap = new Map([ + [34, """], + [38, "&"], + [39, "'"], + [60, "<"], + [62, ">"], +]); + +// For compatibility with node < 4, we wrap `codePointAt` +export const getCodePoint = + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition + String.prototype.codePointAt != null + ? (str: string, index: number): number => str.codePointAt(index)! + : // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae + (c: string, index: number): number => + (c.charCodeAt(index) & 0xfc00) === 0xd800 + ? (c.charCodeAt(index) - 0xd800) * 0x400 + + c.charCodeAt(index + 1) - + 0xdc00 + + 0x10000 + : c.charCodeAt(index); + +/** + * Encodes all non-ASCII characters, as well as characters not valid in XML + * documents using XML entities. + * + * If a character has no equivalent entity, a + * numeric hexadecimal reference (eg. `ü`) will be used. + */ +export function encodeXML(str: string): string { + let ret = ""; + let lastIdx = 0; + let match; + + while ((match = xmlReplacer.exec(str)) !== null) { + const i = match.index; + const char = str.charCodeAt(i); + const next = xmlCodeMap.get(char); + + if (next !== undefined) { + ret += str.substring(lastIdx, i) + next; + lastIdx = i + 1; + } else { + ret += `${str.substring(lastIdx, i)}&#x${getCodePoint( + str, + i + ).toString(16)};`; + // Increase by 1 if we have a surrogate pair + lastIdx = xmlReplacer.lastIndex += Number( + (char & 0xfc00) === 0xd800 + ); + } + } + + return ret + str.substr(lastIdx); +} + +/** + * Encodes all non-ASCII characters, as well as characters not valid in XML + * documents using numeric hexadecimal reference (eg. `ü`). + * + * Have a look at `escapeUTF8` if you want a more concise output at the expense + * of reduced transportability. + * + * @param data String to escape. + */ +export const escape = encodeXML; + +/** + * Creates a function that escapes all characters matched by the given regular + * expression using the given map of characters to escape to their entities. + * + * @param regex Regular expression to match characters to escape. + * @param map Map of characters to escape to their entities. + * + * @returns Function that escapes all characters matched by the given regular + * expression using the given map of characters to escape to their entities. + */ +function getEscaper( + regex: RegExp, + map: Map +): (data: string) => string { + return function escape(data: string): string { + let match; + let lastIdx = 0; + let result = ""; + + while ((match = regex.exec(data))) { + if (lastIdx !== match.index) { + result += data.substring(lastIdx, match.index); + } + + // We know that this character will be in the map. + result += map.get(match[0].charCodeAt(0))!; + + // Every match will be of length 1 + lastIdx = match.index + 1; + } + + return result + data.substring(lastIdx); + }; +} + +/** + * Encodes all characters not valid in XML documents using XML entities. + * + * Note that the output will be character-set dependent. + * + * @param data String to escape. + */ +export const escapeUTF8 = getEscaper(/[&<>'"]/g, xmlCodeMap); + +/** + * Encodes all characters that have to be escaped in HTML attributes, + * following {@link https://html.spec.whatwg.org/multipage/parsing.html#escapingString}. + * + * @param data String to escape. + */ +export const escapeAttribute = getEscaper( + /["&\u00A0]/g, + new Map([ + [34, """], + [38, "&"], + [160, " "], + ]) +); + +/** + * Encodes all characters that have to be escaped in HTML text, + * following {@link https://html.spec.whatwg.org/multipage/parsing.html#escapingString}. + * + * @param data String to escape. + */ +export const escapeText = getEscaper( + /[&<>\u00A0]/g, + new Map([ + [38, "&"], + [60, "<"], + [62, ">"], + [160, " "], + ]) +); diff --git a/packages/webui/third_party/editor/entities/src/generated/decode-data-html.ts b/packages/webui/third_party/editor/entities/src/generated/decode-data-html.ts new file mode 100644 index 000000000..90ee62b42 --- /dev/null +++ b/packages/webui/third_party/editor/entities/src/generated/decode-data-html.ts @@ -0,0 +1,8 @@ +// Generated using scripts/write-decode-map.ts + +export default new Uint16Array( + // prettier-ignore + "\u1d41<\xd5\u0131\u028a\u049d\u057b\u05d0\u0675\u06de\u07a2\u07d6\u080f\u0a4a\u0a91\u0da1\u0e6d\u0f09\u0f26\u10ca\u1228\u12e1\u1415\u149d\u14c3\u14df\u1525\0\0\0\0\0\0\u156b\u16cd\u198d\u1c12\u1ddd\u1f7e\u2060\u21b0\u228d\u23c0\u23fb\u2442\u2824\u2912\u2d08\u2e48\u2fce\u3016\u32ba\u3639\u37ac\u38fe\u3a28\u3a71\u3ae0\u3b2e\u0800EMabcfglmnoprstu\\bfms\x7f\x84\x8b\x90\x95\x98\xa6\xb3\xb9\xc8\xcflig\u803b\xc6\u40c6P\u803b&\u4026cute\u803b\xc1\u40c1reve;\u4102\u0100iyx}rc\u803b\xc2\u40c2;\u4410r;\uc000\ud835\udd04rave\u803b\xc0\u40c0pha;\u4391acr;\u4100d;\u6a53\u0100gp\x9d\xa1on;\u4104f;\uc000\ud835\udd38plyFunction;\u6061ing\u803b\xc5\u40c5\u0100cs\xbe\xc3r;\uc000\ud835\udc9cign;\u6254ilde\u803b\xc3\u40c3ml\u803b\xc4\u40c4\u0400aceforsu\xe5\xfb\xfe\u0117\u011c\u0122\u0127\u012a\u0100cr\xea\xf2kslash;\u6216\u0176\xf6\xf8;\u6ae7ed;\u6306y;\u4411\u0180crt\u0105\u010b\u0114ause;\u6235noullis;\u612ca;\u4392r;\uc000\ud835\udd05pf;\uc000\ud835\udd39eve;\u42d8c\xf2\u0113mpeq;\u624e\u0700HOacdefhilorsu\u014d\u0151\u0156\u0180\u019e\u01a2\u01b5\u01b7\u01ba\u01dc\u0215\u0273\u0278\u027ecy;\u4427PY\u803b\xa9\u40a9\u0180cpy\u015d\u0162\u017aute;\u4106\u0100;i\u0167\u0168\u62d2talDifferentialD;\u6145leys;\u612d\u0200aeio\u0189\u018e\u0194\u0198ron;\u410cdil\u803b\xc7\u40c7rc;\u4108nint;\u6230ot;\u410a\u0100dn\u01a7\u01adilla;\u40b8terDot;\u40b7\xf2\u017fi;\u43a7rcle\u0200DMPT\u01c7\u01cb\u01d1\u01d6ot;\u6299inus;\u6296lus;\u6295imes;\u6297o\u0100cs\u01e2\u01f8kwiseContourIntegral;\u6232eCurly\u0100DQ\u0203\u020foubleQuote;\u601duote;\u6019\u0200lnpu\u021e\u0228\u0247\u0255on\u0100;e\u0225\u0226\u6237;\u6a74\u0180git\u022f\u0236\u023aruent;\u6261nt;\u622fourIntegral;\u622e\u0100fr\u024c\u024e;\u6102oduct;\u6210nterClockwiseContourIntegral;\u6233oss;\u6a2fcr;\uc000\ud835\udc9ep\u0100;C\u0284\u0285\u62d3ap;\u624d\u0580DJSZacefios\u02a0\u02ac\u02b0\u02b4\u02b8\u02cb\u02d7\u02e1\u02e6\u0333\u048d\u0100;o\u0179\u02a5trahd;\u6911cy;\u4402cy;\u4405cy;\u440f\u0180grs\u02bf\u02c4\u02c7ger;\u6021r;\u61a1hv;\u6ae4\u0100ay\u02d0\u02d5ron;\u410e;\u4414l\u0100;t\u02dd\u02de\u6207a;\u4394r;\uc000\ud835\udd07\u0100af\u02eb\u0327\u0100cm\u02f0\u0322ritical\u0200ADGT\u0300\u0306\u0316\u031ccute;\u40b4o\u0174\u030b\u030d;\u42d9bleAcute;\u42ddrave;\u4060ilde;\u42dcond;\u62c4ferentialD;\u6146\u0470\u033d\0\0\0\u0342\u0354\0\u0405f;\uc000\ud835\udd3b\u0180;DE\u0348\u0349\u034d\u40a8ot;\u60dcqual;\u6250ble\u0300CDLRUV\u0363\u0372\u0382\u03cf\u03e2\u03f8ontourIntegra\xec\u0239o\u0274\u0379\0\0\u037b\xbb\u0349nArrow;\u61d3\u0100eo\u0387\u03a4ft\u0180ART\u0390\u0396\u03a1rrow;\u61d0ightArrow;\u61d4e\xe5\u02cang\u0100LR\u03ab\u03c4eft\u0100AR\u03b3\u03b9rrow;\u67f8ightArrow;\u67faightArrow;\u67f9ight\u0100AT\u03d8\u03derrow;\u61d2ee;\u62a8p\u0241\u03e9\0\0\u03efrrow;\u61d1ownArrow;\u61d5erticalBar;\u6225n\u0300ABLRTa\u0412\u042a\u0430\u045e\u047f\u037crrow\u0180;BU\u041d\u041e\u0422\u6193ar;\u6913pArrow;\u61f5reve;\u4311eft\u02d2\u043a\0\u0446\0\u0450ightVector;\u6950eeVector;\u695eector\u0100;B\u0459\u045a\u61bdar;\u6956ight\u01d4\u0467\0\u0471eeVector;\u695fector\u0100;B\u047a\u047b\u61c1ar;\u6957ee\u0100;A\u0486\u0487\u62a4rrow;\u61a7\u0100ct\u0492\u0497r;\uc000\ud835\udc9frok;\u4110\u0800NTacdfglmopqstux\u04bd\u04c0\u04c4\u04cb\u04de\u04e2\u04e7\u04ee\u04f5\u0521\u052f\u0536\u0552\u055d\u0560\u0565G;\u414aH\u803b\xd0\u40d0cute\u803b\xc9\u40c9\u0180aiy\u04d2\u04d7\u04dcron;\u411arc\u803b\xca\u40ca;\u442dot;\u4116r;\uc000\ud835\udd08rave\u803b\xc8\u40c8ement;\u6208\u0100ap\u04fa\u04fecr;\u4112ty\u0253\u0506\0\0\u0512mallSquare;\u65fberySmallSquare;\u65ab\u0100gp\u0526\u052aon;\u4118f;\uc000\ud835\udd3csilon;\u4395u\u0100ai\u053c\u0549l\u0100;T\u0542\u0543\u6a75ilde;\u6242librium;\u61cc\u0100ci\u0557\u055ar;\u6130m;\u6a73a;\u4397ml\u803b\xcb\u40cb\u0100ip\u056a\u056fsts;\u6203onentialE;\u6147\u0280cfios\u0585\u0588\u058d\u05b2\u05ccy;\u4424r;\uc000\ud835\udd09lled\u0253\u0597\0\0\u05a3mallSquare;\u65fcerySmallSquare;\u65aa\u0370\u05ba\0\u05bf\0\0\u05c4f;\uc000\ud835\udd3dAll;\u6200riertrf;\u6131c\xf2\u05cb\u0600JTabcdfgorst\u05e8\u05ec\u05ef\u05fa\u0600\u0612\u0616\u061b\u061d\u0623\u066c\u0672cy;\u4403\u803b>\u403emma\u0100;d\u05f7\u05f8\u4393;\u43dcreve;\u411e\u0180eiy\u0607\u060c\u0610dil;\u4122rc;\u411c;\u4413ot;\u4120r;\uc000\ud835\udd0a;\u62d9pf;\uc000\ud835\udd3eeater\u0300EFGLST\u0635\u0644\u064e\u0656\u065b\u0666qual\u0100;L\u063e\u063f\u6265ess;\u62dbullEqual;\u6267reater;\u6aa2ess;\u6277lantEqual;\u6a7eilde;\u6273cr;\uc000\ud835\udca2;\u626b\u0400Aacfiosu\u0685\u068b\u0696\u069b\u069e\u06aa\u06be\u06caRDcy;\u442a\u0100ct\u0690\u0694ek;\u42c7;\u405eirc;\u4124r;\u610clbertSpace;\u610b\u01f0\u06af\0\u06b2f;\u610dizontalLine;\u6500\u0100ct\u06c3\u06c5\xf2\u06a9rok;\u4126mp\u0144\u06d0\u06d8ownHum\xf0\u012fqual;\u624f\u0700EJOacdfgmnostu\u06fa\u06fe\u0703\u0707\u070e\u071a\u071e\u0721\u0728\u0744\u0778\u078b\u078f\u0795cy;\u4415lig;\u4132cy;\u4401cute\u803b\xcd\u40cd\u0100iy\u0713\u0718rc\u803b\xce\u40ce;\u4418ot;\u4130r;\u6111rave\u803b\xcc\u40cc\u0180;ap\u0720\u072f\u073f\u0100cg\u0734\u0737r;\u412ainaryI;\u6148lie\xf3\u03dd\u01f4\u0749\0\u0762\u0100;e\u074d\u074e\u622c\u0100gr\u0753\u0758ral;\u622bsection;\u62c2isible\u0100CT\u076c\u0772omma;\u6063imes;\u6062\u0180gpt\u077f\u0783\u0788on;\u412ef;\uc000\ud835\udd40a;\u4399cr;\u6110ilde;\u4128\u01eb\u079a\0\u079ecy;\u4406l\u803b\xcf\u40cf\u0280cfosu\u07ac\u07b7\u07bc\u07c2\u07d0\u0100iy\u07b1\u07b5rc;\u4134;\u4419r;\uc000\ud835\udd0dpf;\uc000\ud835\udd41\u01e3\u07c7\0\u07ccr;\uc000\ud835\udca5rcy;\u4408kcy;\u4404\u0380HJacfos\u07e4\u07e8\u07ec\u07f1\u07fd\u0802\u0808cy;\u4425cy;\u440cppa;\u439a\u0100ey\u07f6\u07fbdil;\u4136;\u441ar;\uc000\ud835\udd0epf;\uc000\ud835\udd42cr;\uc000\ud835\udca6\u0580JTaceflmost\u0825\u0829\u082c\u0850\u0863\u09b3\u09b8\u09c7\u09cd\u0a37\u0a47cy;\u4409\u803b<\u403c\u0280cmnpr\u0837\u083c\u0841\u0844\u084dute;\u4139bda;\u439bg;\u67ealacetrf;\u6112r;\u619e\u0180aey\u0857\u085c\u0861ron;\u413ddil;\u413b;\u441b\u0100fs\u0868\u0970t\u0500ACDFRTUVar\u087e\u08a9\u08b1\u08e0\u08e6\u08fc\u092f\u095b\u0390\u096a\u0100nr\u0883\u088fgleBracket;\u67e8row\u0180;BR\u0899\u089a\u089e\u6190ar;\u61e4ightArrow;\u61c6eiling;\u6308o\u01f5\u08b7\0\u08c3bleBracket;\u67e6n\u01d4\u08c8\0\u08d2eeVector;\u6961ector\u0100;B\u08db\u08dc\u61c3ar;\u6959loor;\u630aight\u0100AV\u08ef\u08f5rrow;\u6194ector;\u694e\u0100er\u0901\u0917e\u0180;AV\u0909\u090a\u0910\u62a3rrow;\u61a4ector;\u695aiangle\u0180;BE\u0924\u0925\u0929\u62b2ar;\u69cfqual;\u62b4p\u0180DTV\u0937\u0942\u094cownVector;\u6951eeVector;\u6960ector\u0100;B\u0956\u0957\u61bfar;\u6958ector\u0100;B\u0965\u0966\u61bcar;\u6952ight\xe1\u039cs\u0300EFGLST\u097e\u098b\u0995\u099d\u09a2\u09adqualGreater;\u62daullEqual;\u6266reater;\u6276ess;\u6aa1lantEqual;\u6a7dilde;\u6272r;\uc000\ud835\udd0f\u0100;e\u09bd\u09be\u62d8ftarrow;\u61daidot;\u413f\u0180npw\u09d4\u0a16\u0a1bg\u0200LRlr\u09de\u09f7\u0a02\u0a10eft\u0100AR\u09e6\u09ecrrow;\u67f5ightArrow;\u67f7ightArrow;\u67f6eft\u0100ar\u03b3\u0a0aight\xe1\u03bfight\xe1\u03caf;\uc000\ud835\udd43er\u0100LR\u0a22\u0a2ceftArrow;\u6199ightArrow;\u6198\u0180cht\u0a3e\u0a40\u0a42\xf2\u084c;\u61b0rok;\u4141;\u626a\u0400acefiosu\u0a5a\u0a5d\u0a60\u0a77\u0a7c\u0a85\u0a8b\u0a8ep;\u6905y;\u441c\u0100dl\u0a65\u0a6fiumSpace;\u605flintrf;\u6133r;\uc000\ud835\udd10nusPlus;\u6213pf;\uc000\ud835\udd44c\xf2\u0a76;\u439c\u0480Jacefostu\u0aa3\u0aa7\u0aad\u0ac0\u0b14\u0b19\u0d91\u0d97\u0d9ecy;\u440acute;\u4143\u0180aey\u0ab4\u0ab9\u0aberon;\u4147dil;\u4145;\u441d\u0180gsw\u0ac7\u0af0\u0b0eative\u0180MTV\u0ad3\u0adf\u0ae8ediumSpace;\u600bhi\u0100cn\u0ae6\u0ad8\xeb\u0ad9eryThi\xee\u0ad9ted\u0100GL\u0af8\u0b06reaterGreate\xf2\u0673essLes\xf3\u0a48Line;\u400ar;\uc000\ud835\udd11\u0200Bnpt\u0b22\u0b28\u0b37\u0b3areak;\u6060BreakingSpace;\u40a0f;\u6115\u0680;CDEGHLNPRSTV\u0b55\u0b56\u0b6a\u0b7c\u0ba1\u0beb\u0c04\u0c5e\u0c84\u0ca6\u0cd8\u0d61\u0d85\u6aec\u0100ou\u0b5b\u0b64ngruent;\u6262pCap;\u626doubleVerticalBar;\u6226\u0180lqx\u0b83\u0b8a\u0b9bement;\u6209ual\u0100;T\u0b92\u0b93\u6260ilde;\uc000\u2242\u0338ists;\u6204reater\u0380;EFGLST\u0bb6\u0bb7\u0bbd\u0bc9\u0bd3\u0bd8\u0be5\u626fqual;\u6271ullEqual;\uc000\u2267\u0338reater;\uc000\u226b\u0338ess;\u6279lantEqual;\uc000\u2a7e\u0338ilde;\u6275ump\u0144\u0bf2\u0bfdownHump;\uc000\u224e\u0338qual;\uc000\u224f\u0338e\u0100fs\u0c0a\u0c27tTriangle\u0180;BE\u0c1a\u0c1b\u0c21\u62eaar;\uc000\u29cf\u0338qual;\u62ecs\u0300;EGLST\u0c35\u0c36\u0c3c\u0c44\u0c4b\u0c58\u626equal;\u6270reater;\u6278ess;\uc000\u226a\u0338lantEqual;\uc000\u2a7d\u0338ilde;\u6274ested\u0100GL\u0c68\u0c79reaterGreater;\uc000\u2aa2\u0338essLess;\uc000\u2aa1\u0338recedes\u0180;ES\u0c92\u0c93\u0c9b\u6280qual;\uc000\u2aaf\u0338lantEqual;\u62e0\u0100ei\u0cab\u0cb9verseElement;\u620cghtTriangle\u0180;BE\u0ccb\u0ccc\u0cd2\u62ebar;\uc000\u29d0\u0338qual;\u62ed\u0100qu\u0cdd\u0d0cuareSu\u0100bp\u0ce8\u0cf9set\u0100;E\u0cf0\u0cf3\uc000\u228f\u0338qual;\u62e2erset\u0100;E\u0d03\u0d06\uc000\u2290\u0338qual;\u62e3\u0180bcp\u0d13\u0d24\u0d4eset\u0100;E\u0d1b\u0d1e\uc000\u2282\u20d2qual;\u6288ceeds\u0200;EST\u0d32\u0d33\u0d3b\u0d46\u6281qual;\uc000\u2ab0\u0338lantEqual;\u62e1ilde;\uc000\u227f\u0338erset\u0100;E\u0d58\u0d5b\uc000\u2283\u20d2qual;\u6289ilde\u0200;EFT\u0d6e\u0d6f\u0d75\u0d7f\u6241qual;\u6244ullEqual;\u6247ilde;\u6249erticalBar;\u6224cr;\uc000\ud835\udca9ilde\u803b\xd1\u40d1;\u439d\u0700Eacdfgmoprstuv\u0dbd\u0dc2\u0dc9\u0dd5\u0ddb\u0de0\u0de7\u0dfc\u0e02\u0e20\u0e22\u0e32\u0e3f\u0e44lig;\u4152cute\u803b\xd3\u40d3\u0100iy\u0dce\u0dd3rc\u803b\xd4\u40d4;\u441eblac;\u4150r;\uc000\ud835\udd12rave\u803b\xd2\u40d2\u0180aei\u0dee\u0df2\u0df6cr;\u414cga;\u43a9cron;\u439fpf;\uc000\ud835\udd46enCurly\u0100DQ\u0e0e\u0e1aoubleQuote;\u601cuote;\u6018;\u6a54\u0100cl\u0e27\u0e2cr;\uc000\ud835\udcaaash\u803b\xd8\u40d8i\u016c\u0e37\u0e3cde\u803b\xd5\u40d5es;\u6a37ml\u803b\xd6\u40d6er\u0100BP\u0e4b\u0e60\u0100ar\u0e50\u0e53r;\u603eac\u0100ek\u0e5a\u0e5c;\u63deet;\u63b4arenthesis;\u63dc\u0480acfhilors\u0e7f\u0e87\u0e8a\u0e8f\u0e92\u0e94\u0e9d\u0eb0\u0efcrtialD;\u6202y;\u441fr;\uc000\ud835\udd13i;\u43a6;\u43a0usMinus;\u40b1\u0100ip\u0ea2\u0eadncareplan\xe5\u069df;\u6119\u0200;eio\u0eb9\u0eba\u0ee0\u0ee4\u6abbcedes\u0200;EST\u0ec8\u0ec9\u0ecf\u0eda\u627aqual;\u6aaflantEqual;\u627cilde;\u627eme;\u6033\u0100dp\u0ee9\u0eeeuct;\u620fortion\u0100;a\u0225\u0ef9l;\u621d\u0100ci\u0f01\u0f06r;\uc000\ud835\udcab;\u43a8\u0200Ufos\u0f11\u0f16\u0f1b\u0f1fOT\u803b\"\u4022r;\uc000\ud835\udd14pf;\u611acr;\uc000\ud835\udcac\u0600BEacefhiorsu\u0f3e\u0f43\u0f47\u0f60\u0f73\u0fa7\u0faa\u0fad\u1096\u10a9\u10b4\u10bearr;\u6910G\u803b\xae\u40ae\u0180cnr\u0f4e\u0f53\u0f56ute;\u4154g;\u67ebr\u0100;t\u0f5c\u0f5d\u61a0l;\u6916\u0180aey\u0f67\u0f6c\u0f71ron;\u4158dil;\u4156;\u4420\u0100;v\u0f78\u0f79\u611cerse\u0100EU\u0f82\u0f99\u0100lq\u0f87\u0f8eement;\u620builibrium;\u61cbpEquilibrium;\u696fr\xbb\u0f79o;\u43a1ght\u0400ACDFTUVa\u0fc1\u0feb\u0ff3\u1022\u1028\u105b\u1087\u03d8\u0100nr\u0fc6\u0fd2gleBracket;\u67e9row\u0180;BL\u0fdc\u0fdd\u0fe1\u6192ar;\u61e5eftArrow;\u61c4eiling;\u6309o\u01f5\u0ff9\0\u1005bleBracket;\u67e7n\u01d4\u100a\0\u1014eeVector;\u695dector\u0100;B\u101d\u101e\u61c2ar;\u6955loor;\u630b\u0100er\u102d\u1043e\u0180;AV\u1035\u1036\u103c\u62a2rrow;\u61a6ector;\u695biangle\u0180;BE\u1050\u1051\u1055\u62b3ar;\u69d0qual;\u62b5p\u0180DTV\u1063\u106e\u1078ownVector;\u694feeVector;\u695cector\u0100;B\u1082\u1083\u61bear;\u6954ector\u0100;B\u1091\u1092\u61c0ar;\u6953\u0100pu\u109b\u109ef;\u611dndImplies;\u6970ightarrow;\u61db\u0100ch\u10b9\u10bcr;\u611b;\u61b1leDelayed;\u69f4\u0680HOacfhimoqstu\u10e4\u10f1\u10f7\u10fd\u1119\u111e\u1151\u1156\u1161\u1167\u11b5\u11bb\u11bf\u0100Cc\u10e9\u10eeHcy;\u4429y;\u4428FTcy;\u442ccute;\u415a\u0280;aeiy\u1108\u1109\u110e\u1113\u1117\u6abcron;\u4160dil;\u415erc;\u415c;\u4421r;\uc000\ud835\udd16ort\u0200DLRU\u112a\u1134\u113e\u1149ownArrow\xbb\u041eeftArrow\xbb\u089aightArrow\xbb\u0fddpArrow;\u6191gma;\u43a3allCircle;\u6218pf;\uc000\ud835\udd4a\u0272\u116d\0\0\u1170t;\u621aare\u0200;ISU\u117b\u117c\u1189\u11af\u65a1ntersection;\u6293u\u0100bp\u118f\u119eset\u0100;E\u1197\u1198\u628fqual;\u6291erset\u0100;E\u11a8\u11a9\u6290qual;\u6292nion;\u6294cr;\uc000\ud835\udcaear;\u62c6\u0200bcmp\u11c8\u11db\u1209\u120b\u0100;s\u11cd\u11ce\u62d0et\u0100;E\u11cd\u11d5qual;\u6286\u0100ch\u11e0\u1205eeds\u0200;EST\u11ed\u11ee\u11f4\u11ff\u627bqual;\u6ab0lantEqual;\u627dilde;\u627fTh\xe1\u0f8c;\u6211\u0180;es\u1212\u1213\u1223\u62d1rset\u0100;E\u121c\u121d\u6283qual;\u6287et\xbb\u1213\u0580HRSacfhiors\u123e\u1244\u1249\u1255\u125e\u1271\u1276\u129f\u12c2\u12c8\u12d1ORN\u803b\xde\u40deADE;\u6122\u0100Hc\u124e\u1252cy;\u440by;\u4426\u0100bu\u125a\u125c;\u4009;\u43a4\u0180aey\u1265\u126a\u126fron;\u4164dil;\u4162;\u4422r;\uc000\ud835\udd17\u0100ei\u127b\u1289\u01f2\u1280\0\u1287efore;\u6234a;\u4398\u0100cn\u128e\u1298kSpace;\uc000\u205f\u200aSpace;\u6009lde\u0200;EFT\u12ab\u12ac\u12b2\u12bc\u623cqual;\u6243ullEqual;\u6245ilde;\u6248pf;\uc000\ud835\udd4bipleDot;\u60db\u0100ct\u12d6\u12dbr;\uc000\ud835\udcafrok;\u4166\u0ae1\u12f7\u130e\u131a\u1326\0\u132c\u1331\0\0\0\0\0\u1338\u133d\u1377\u1385\0\u13ff\u1404\u140a\u1410\u0100cr\u12fb\u1301ute\u803b\xda\u40dar\u0100;o\u1307\u1308\u619fcir;\u6949r\u01e3\u1313\0\u1316y;\u440eve;\u416c\u0100iy\u131e\u1323rc\u803b\xdb\u40db;\u4423blac;\u4170r;\uc000\ud835\udd18rave\u803b\xd9\u40d9acr;\u416a\u0100di\u1341\u1369er\u0100BP\u1348\u135d\u0100ar\u134d\u1350r;\u405fac\u0100ek\u1357\u1359;\u63dfet;\u63b5arenthesis;\u63ddon\u0100;P\u1370\u1371\u62c3lus;\u628e\u0100gp\u137b\u137fon;\u4172f;\uc000\ud835\udd4c\u0400ADETadps\u1395\u13ae\u13b8\u13c4\u03e8\u13d2\u13d7\u13f3rrow\u0180;BD\u1150\u13a0\u13a4ar;\u6912ownArrow;\u61c5ownArrow;\u6195quilibrium;\u696eee\u0100;A\u13cb\u13cc\u62a5rrow;\u61a5own\xe1\u03f3er\u0100LR\u13de\u13e8eftArrow;\u6196ightArrow;\u6197i\u0100;l\u13f9\u13fa\u43d2on;\u43a5ing;\u416ecr;\uc000\ud835\udcb0ilde;\u4168ml\u803b\xdc\u40dc\u0480Dbcdefosv\u1427\u142c\u1430\u1433\u143e\u1485\u148a\u1490\u1496ash;\u62abar;\u6aeby;\u4412ash\u0100;l\u143b\u143c\u62a9;\u6ae6\u0100er\u1443\u1445;\u62c1\u0180bty\u144c\u1450\u147aar;\u6016\u0100;i\u144f\u1455cal\u0200BLST\u1461\u1465\u146a\u1474ar;\u6223ine;\u407ceparator;\u6758ilde;\u6240ThinSpace;\u600ar;\uc000\ud835\udd19pf;\uc000\ud835\udd4dcr;\uc000\ud835\udcb1dash;\u62aa\u0280cefos\u14a7\u14ac\u14b1\u14b6\u14bcirc;\u4174dge;\u62c0r;\uc000\ud835\udd1apf;\uc000\ud835\udd4ecr;\uc000\ud835\udcb2\u0200fios\u14cb\u14d0\u14d2\u14d8r;\uc000\ud835\udd1b;\u439epf;\uc000\ud835\udd4fcr;\uc000\ud835\udcb3\u0480AIUacfosu\u14f1\u14f5\u14f9\u14fd\u1504\u150f\u1514\u151a\u1520cy;\u442fcy;\u4407cy;\u442ecute\u803b\xdd\u40dd\u0100iy\u1509\u150drc;\u4176;\u442br;\uc000\ud835\udd1cpf;\uc000\ud835\udd50cr;\uc000\ud835\udcb4ml;\u4178\u0400Hacdefos\u1535\u1539\u153f\u154b\u154f\u155d\u1560\u1564cy;\u4416cute;\u4179\u0100ay\u1544\u1549ron;\u417d;\u4417ot;\u417b\u01f2\u1554\0\u155boWidt\xe8\u0ad9a;\u4396r;\u6128pf;\u6124cr;\uc000\ud835\udcb5\u0be1\u1583\u158a\u1590\0\u15b0\u15b6\u15bf\0\0\0\0\u15c6\u15db\u15eb\u165f\u166d\0\u1695\u169b\u16b2\u16b9\0\u16becute\u803b\xe1\u40e1reve;\u4103\u0300;Ediuy\u159c\u159d\u15a1\u15a3\u15a8\u15ad\u623e;\uc000\u223e\u0333;\u623frc\u803b\xe2\u40e2te\u80bb\xb4\u0306;\u4430lig\u803b\xe6\u40e6\u0100;r\xb2\u15ba;\uc000\ud835\udd1erave\u803b\xe0\u40e0\u0100ep\u15ca\u15d6\u0100fp\u15cf\u15d4sym;\u6135\xe8\u15d3ha;\u43b1\u0100ap\u15dfc\u0100cl\u15e4\u15e7r;\u4101g;\u6a3f\u0264\u15f0\0\0\u160a\u0280;adsv\u15fa\u15fb\u15ff\u1601\u1607\u6227nd;\u6a55;\u6a5clope;\u6a58;\u6a5a\u0380;elmrsz\u1618\u1619\u161b\u161e\u163f\u164f\u1659\u6220;\u69a4e\xbb\u1619sd\u0100;a\u1625\u1626\u6221\u0461\u1630\u1632\u1634\u1636\u1638\u163a\u163c\u163e;\u69a8;\u69a9;\u69aa;\u69ab;\u69ac;\u69ad;\u69ae;\u69aft\u0100;v\u1645\u1646\u621fb\u0100;d\u164c\u164d\u62be;\u699d\u0100pt\u1654\u1657h;\u6222\xbb\xb9arr;\u637c\u0100gp\u1663\u1667on;\u4105f;\uc000\ud835\udd52\u0380;Eaeiop\u12c1\u167b\u167d\u1682\u1684\u1687\u168a;\u6a70cir;\u6a6f;\u624ad;\u624bs;\u4027rox\u0100;e\u12c1\u1692\xf1\u1683ing\u803b\xe5\u40e5\u0180cty\u16a1\u16a6\u16a8r;\uc000\ud835\udcb6;\u402amp\u0100;e\u12c1\u16af\xf1\u0288ilde\u803b\xe3\u40e3ml\u803b\xe4\u40e4\u0100ci\u16c2\u16c8onin\xf4\u0272nt;\u6a11\u0800Nabcdefiklnoprsu\u16ed\u16f1\u1730\u173c\u1743\u1748\u1778\u177d\u17e0\u17e6\u1839\u1850\u170d\u193d\u1948\u1970ot;\u6aed\u0100cr\u16f6\u171ek\u0200ceps\u1700\u1705\u170d\u1713ong;\u624cpsilon;\u43f6rime;\u6035im\u0100;e\u171a\u171b\u623dq;\u62cd\u0176\u1722\u1726ee;\u62bded\u0100;g\u172c\u172d\u6305e\xbb\u172drk\u0100;t\u135c\u1737brk;\u63b6\u0100oy\u1701\u1741;\u4431quo;\u601e\u0280cmprt\u1753\u175b\u1761\u1764\u1768aus\u0100;e\u010a\u0109ptyv;\u69b0s\xe9\u170cno\xf5\u0113\u0180ahw\u176f\u1771\u1773;\u43b2;\u6136een;\u626cr;\uc000\ud835\udd1fg\u0380costuvw\u178d\u179d\u17b3\u17c1\u17d5\u17db\u17de\u0180aiu\u1794\u1796\u179a\xf0\u0760rc;\u65efp\xbb\u1371\u0180dpt\u17a4\u17a8\u17adot;\u6a00lus;\u6a01imes;\u6a02\u0271\u17b9\0\0\u17becup;\u6a06ar;\u6605riangle\u0100du\u17cd\u17d2own;\u65bdp;\u65b3plus;\u6a04e\xe5\u1444\xe5\u14adarow;\u690d\u0180ako\u17ed\u1826\u1835\u0100cn\u17f2\u1823k\u0180lst\u17fa\u05ab\u1802ozenge;\u69ebriangle\u0200;dlr\u1812\u1813\u1818\u181d\u65b4own;\u65beeft;\u65c2ight;\u65b8k;\u6423\u01b1\u182b\0\u1833\u01b2\u182f\0\u1831;\u6592;\u65914;\u6593ck;\u6588\u0100eo\u183e\u184d\u0100;q\u1843\u1846\uc000=\u20e5uiv;\uc000\u2261\u20e5t;\u6310\u0200ptwx\u1859\u185e\u1867\u186cf;\uc000\ud835\udd53\u0100;t\u13cb\u1863om\xbb\u13cctie;\u62c8\u0600DHUVbdhmptuv\u1885\u1896\u18aa\u18bb\u18d7\u18db\u18ec\u18ff\u1905\u190a\u1910\u1921\u0200LRlr\u188e\u1890\u1892\u1894;\u6557;\u6554;\u6556;\u6553\u0280;DUdu\u18a1\u18a2\u18a4\u18a6\u18a8\u6550;\u6566;\u6569;\u6564;\u6567\u0200LRlr\u18b3\u18b5\u18b7\u18b9;\u655d;\u655a;\u655c;\u6559\u0380;HLRhlr\u18ca\u18cb\u18cd\u18cf\u18d1\u18d3\u18d5\u6551;\u656c;\u6563;\u6560;\u656b;\u6562;\u655fox;\u69c9\u0200LRlr\u18e4\u18e6\u18e8\u18ea;\u6555;\u6552;\u6510;\u650c\u0280;DUdu\u06bd\u18f7\u18f9\u18fb\u18fd;\u6565;\u6568;\u652c;\u6534inus;\u629flus;\u629eimes;\u62a0\u0200LRlr\u1919\u191b\u191d\u191f;\u655b;\u6558;\u6518;\u6514\u0380;HLRhlr\u1930\u1931\u1933\u1935\u1937\u1939\u193b\u6502;\u656a;\u6561;\u655e;\u653c;\u6524;\u651c\u0100ev\u0123\u1942bar\u803b\xa6\u40a6\u0200ceio\u1951\u1956\u195a\u1960r;\uc000\ud835\udcb7mi;\u604fm\u0100;e\u171a\u171cl\u0180;bh\u1968\u1969\u196b\u405c;\u69c5sub;\u67c8\u016c\u1974\u197el\u0100;e\u1979\u197a\u6022t\xbb\u197ap\u0180;Ee\u012f\u1985\u1987;\u6aae\u0100;q\u06dc\u06db\u0ce1\u19a7\0\u19e8\u1a11\u1a15\u1a32\0\u1a37\u1a50\0\0\u1ab4\0\0\u1ac1\0\0\u1b21\u1b2e\u1b4d\u1b52\0\u1bfd\0\u1c0c\u0180cpr\u19ad\u19b2\u19ddute;\u4107\u0300;abcds\u19bf\u19c0\u19c4\u19ca\u19d5\u19d9\u6229nd;\u6a44rcup;\u6a49\u0100au\u19cf\u19d2p;\u6a4bp;\u6a47ot;\u6a40;\uc000\u2229\ufe00\u0100eo\u19e2\u19e5t;\u6041\xee\u0693\u0200aeiu\u19f0\u19fb\u1a01\u1a05\u01f0\u19f5\0\u19f8s;\u6a4don;\u410ddil\u803b\xe7\u40e7rc;\u4109ps\u0100;s\u1a0c\u1a0d\u6a4cm;\u6a50ot;\u410b\u0180dmn\u1a1b\u1a20\u1a26il\u80bb\xb8\u01adptyv;\u69b2t\u8100\xa2;e\u1a2d\u1a2e\u40a2r\xe4\u01b2r;\uc000\ud835\udd20\u0180cei\u1a3d\u1a40\u1a4dy;\u4447ck\u0100;m\u1a47\u1a48\u6713ark\xbb\u1a48;\u43c7r\u0380;Ecefms\u1a5f\u1a60\u1a62\u1a6b\u1aa4\u1aaa\u1aae\u65cb;\u69c3\u0180;el\u1a69\u1a6a\u1a6d\u42c6q;\u6257e\u0261\u1a74\0\0\u1a88rrow\u0100lr\u1a7c\u1a81eft;\u61baight;\u61bb\u0280RSacd\u1a92\u1a94\u1a96\u1a9a\u1a9f\xbb\u0f47;\u64c8st;\u629birc;\u629aash;\u629dnint;\u6a10id;\u6aefcir;\u69c2ubs\u0100;u\u1abb\u1abc\u6663it\xbb\u1abc\u02ec\u1ac7\u1ad4\u1afa\0\u1b0aon\u0100;e\u1acd\u1ace\u403a\u0100;q\xc7\xc6\u026d\u1ad9\0\0\u1ae2a\u0100;t\u1ade\u1adf\u402c;\u4040\u0180;fl\u1ae8\u1ae9\u1aeb\u6201\xee\u1160e\u0100mx\u1af1\u1af6ent\xbb\u1ae9e\xf3\u024d\u01e7\u1afe\0\u1b07\u0100;d\u12bb\u1b02ot;\u6a6dn\xf4\u0246\u0180fry\u1b10\u1b14\u1b17;\uc000\ud835\udd54o\xe4\u0254\u8100\xa9;s\u0155\u1b1dr;\u6117\u0100ao\u1b25\u1b29rr;\u61b5ss;\u6717\u0100cu\u1b32\u1b37r;\uc000\ud835\udcb8\u0100bp\u1b3c\u1b44\u0100;e\u1b41\u1b42\u6acf;\u6ad1\u0100;e\u1b49\u1b4a\u6ad0;\u6ad2dot;\u62ef\u0380delprvw\u1b60\u1b6c\u1b77\u1b82\u1bac\u1bd4\u1bf9arr\u0100lr\u1b68\u1b6a;\u6938;\u6935\u0270\u1b72\0\0\u1b75r;\u62dec;\u62dfarr\u0100;p\u1b7f\u1b80\u61b6;\u693d\u0300;bcdos\u1b8f\u1b90\u1b96\u1ba1\u1ba5\u1ba8\u622arcap;\u6a48\u0100au\u1b9b\u1b9ep;\u6a46p;\u6a4aot;\u628dr;\u6a45;\uc000\u222a\ufe00\u0200alrv\u1bb5\u1bbf\u1bde\u1be3rr\u0100;m\u1bbc\u1bbd\u61b7;\u693cy\u0180evw\u1bc7\u1bd4\u1bd8q\u0270\u1bce\0\0\u1bd2re\xe3\u1b73u\xe3\u1b75ee;\u62ceedge;\u62cfen\u803b\xa4\u40a4earrow\u0100lr\u1bee\u1bf3eft\xbb\u1b80ight\xbb\u1bbde\xe4\u1bdd\u0100ci\u1c01\u1c07onin\xf4\u01f7nt;\u6231lcty;\u632d\u0980AHabcdefhijlorstuwz\u1c38\u1c3b\u1c3f\u1c5d\u1c69\u1c75\u1c8a\u1c9e\u1cac\u1cb7\u1cfb\u1cff\u1d0d\u1d7b\u1d91\u1dab\u1dbb\u1dc6\u1dcdr\xf2\u0381ar;\u6965\u0200glrs\u1c48\u1c4d\u1c52\u1c54ger;\u6020eth;\u6138\xf2\u1133h\u0100;v\u1c5a\u1c5b\u6010\xbb\u090a\u016b\u1c61\u1c67arow;\u690fa\xe3\u0315\u0100ay\u1c6e\u1c73ron;\u410f;\u4434\u0180;ao\u0332\u1c7c\u1c84\u0100gr\u02bf\u1c81r;\u61catseq;\u6a77\u0180glm\u1c91\u1c94\u1c98\u803b\xb0\u40b0ta;\u43b4ptyv;\u69b1\u0100ir\u1ca3\u1ca8sht;\u697f;\uc000\ud835\udd21ar\u0100lr\u1cb3\u1cb5\xbb\u08dc\xbb\u101e\u0280aegsv\u1cc2\u0378\u1cd6\u1cdc\u1ce0m\u0180;os\u0326\u1cca\u1cd4nd\u0100;s\u0326\u1cd1uit;\u6666amma;\u43ddin;\u62f2\u0180;io\u1ce7\u1ce8\u1cf8\u40f7de\u8100\xf7;o\u1ce7\u1cf0ntimes;\u62c7n\xf8\u1cf7cy;\u4452c\u026f\u1d06\0\0\u1d0arn;\u631eop;\u630d\u0280lptuw\u1d18\u1d1d\u1d22\u1d49\u1d55lar;\u4024f;\uc000\ud835\udd55\u0280;emps\u030b\u1d2d\u1d37\u1d3d\u1d42q\u0100;d\u0352\u1d33ot;\u6251inus;\u6238lus;\u6214quare;\u62a1blebarwedg\xe5\xfan\u0180adh\u112e\u1d5d\u1d67ownarrow\xf3\u1c83arpoon\u0100lr\u1d72\u1d76ef\xf4\u1cb4igh\xf4\u1cb6\u0162\u1d7f\u1d85karo\xf7\u0f42\u026f\u1d8a\0\0\u1d8ern;\u631fop;\u630c\u0180cot\u1d98\u1da3\u1da6\u0100ry\u1d9d\u1da1;\uc000\ud835\udcb9;\u4455l;\u69f6rok;\u4111\u0100dr\u1db0\u1db4ot;\u62f1i\u0100;f\u1dba\u1816\u65bf\u0100ah\u1dc0\u1dc3r\xf2\u0429a\xf2\u0fa6angle;\u69a6\u0100ci\u1dd2\u1dd5y;\u445fgrarr;\u67ff\u0900Dacdefglmnopqrstux\u1e01\u1e09\u1e19\u1e38\u0578\u1e3c\u1e49\u1e61\u1e7e\u1ea5\u1eaf\u1ebd\u1ee1\u1f2a\u1f37\u1f44\u1f4e\u1f5a\u0100Do\u1e06\u1d34o\xf4\u1c89\u0100cs\u1e0e\u1e14ute\u803b\xe9\u40e9ter;\u6a6e\u0200aioy\u1e22\u1e27\u1e31\u1e36ron;\u411br\u0100;c\u1e2d\u1e2e\u6256\u803b\xea\u40ealon;\u6255;\u444dot;\u4117\u0100Dr\u1e41\u1e45ot;\u6252;\uc000\ud835\udd22\u0180;rs\u1e50\u1e51\u1e57\u6a9aave\u803b\xe8\u40e8\u0100;d\u1e5c\u1e5d\u6a96ot;\u6a98\u0200;ils\u1e6a\u1e6b\u1e72\u1e74\u6a99nters;\u63e7;\u6113\u0100;d\u1e79\u1e7a\u6a95ot;\u6a97\u0180aps\u1e85\u1e89\u1e97cr;\u4113ty\u0180;sv\u1e92\u1e93\u1e95\u6205et\xbb\u1e93p\u01001;\u1e9d\u1ea4\u0133\u1ea1\u1ea3;\u6004;\u6005\u6003\u0100gs\u1eaa\u1eac;\u414bp;\u6002\u0100gp\u1eb4\u1eb8on;\u4119f;\uc000\ud835\udd56\u0180als\u1ec4\u1ece\u1ed2r\u0100;s\u1eca\u1ecb\u62d5l;\u69e3us;\u6a71i\u0180;lv\u1eda\u1edb\u1edf\u43b5on\xbb\u1edb;\u43f5\u0200csuv\u1eea\u1ef3\u1f0b\u1f23\u0100io\u1eef\u1e31rc\xbb\u1e2e\u0269\u1ef9\0\0\u1efb\xed\u0548ant\u0100gl\u1f02\u1f06tr\xbb\u1e5dess\xbb\u1e7a\u0180aei\u1f12\u1f16\u1f1als;\u403dst;\u625fv\u0100;D\u0235\u1f20D;\u6a78parsl;\u69e5\u0100Da\u1f2f\u1f33ot;\u6253rr;\u6971\u0180cdi\u1f3e\u1f41\u1ef8r;\u612fo\xf4\u0352\u0100ah\u1f49\u1f4b;\u43b7\u803b\xf0\u40f0\u0100mr\u1f53\u1f57l\u803b\xeb\u40ebo;\u60ac\u0180cip\u1f61\u1f64\u1f67l;\u4021s\xf4\u056e\u0100eo\u1f6c\u1f74ctatio\xee\u0559nential\xe5\u0579\u09e1\u1f92\0\u1f9e\0\u1fa1\u1fa7\0\0\u1fc6\u1fcc\0\u1fd3\0\u1fe6\u1fea\u2000\0\u2008\u205allingdotse\xf1\u1e44y;\u4444male;\u6640\u0180ilr\u1fad\u1fb3\u1fc1lig;\u8000\ufb03\u0269\u1fb9\0\0\u1fbdg;\u8000\ufb00ig;\u8000\ufb04;\uc000\ud835\udd23lig;\u8000\ufb01lig;\uc000fj\u0180alt\u1fd9\u1fdc\u1fe1t;\u666dig;\u8000\ufb02ns;\u65b1of;\u4192\u01f0\u1fee\0\u1ff3f;\uc000\ud835\udd57\u0100ak\u05bf\u1ff7\u0100;v\u1ffc\u1ffd\u62d4;\u6ad9artint;\u6a0d\u0100ao\u200c\u2055\u0100cs\u2011\u2052\u03b1\u201a\u2030\u2038\u2045\u2048\0\u2050\u03b2\u2022\u2025\u2027\u202a\u202c\0\u202e\u803b\xbd\u40bd;\u6153\u803b\xbc\u40bc;\u6155;\u6159;\u615b\u01b3\u2034\0\u2036;\u6154;\u6156\u02b4\u203e\u2041\0\0\u2043\u803b\xbe\u40be;\u6157;\u615c5;\u6158\u01b6\u204c\0\u204e;\u615a;\u615d8;\u615el;\u6044wn;\u6322cr;\uc000\ud835\udcbb\u0880Eabcdefgijlnorstv\u2082\u2089\u209f\u20a5\u20b0\u20b4\u20f0\u20f5\u20fa\u20ff\u2103\u2112\u2138\u0317\u213e\u2152\u219e\u0100;l\u064d\u2087;\u6a8c\u0180cmp\u2090\u2095\u209dute;\u41f5ma\u0100;d\u209c\u1cda\u43b3;\u6a86reve;\u411f\u0100iy\u20aa\u20aerc;\u411d;\u4433ot;\u4121\u0200;lqs\u063e\u0642\u20bd\u20c9\u0180;qs\u063e\u064c\u20c4lan\xf4\u0665\u0200;cdl\u0665\u20d2\u20d5\u20e5c;\u6aa9ot\u0100;o\u20dc\u20dd\u6a80\u0100;l\u20e2\u20e3\u6a82;\u6a84\u0100;e\u20ea\u20ed\uc000\u22db\ufe00s;\u6a94r;\uc000\ud835\udd24\u0100;g\u0673\u061bmel;\u6137cy;\u4453\u0200;Eaj\u065a\u210c\u210e\u2110;\u6a92;\u6aa5;\u6aa4\u0200Eaes\u211b\u211d\u2129\u2134;\u6269p\u0100;p\u2123\u2124\u6a8arox\xbb\u2124\u0100;q\u212e\u212f\u6a88\u0100;q\u212e\u211bim;\u62e7pf;\uc000\ud835\udd58\u0100ci\u2143\u2146r;\u610am\u0180;el\u066b\u214e\u2150;\u6a8e;\u6a90\u8300>;cdlqr\u05ee\u2160\u216a\u216e\u2173\u2179\u0100ci\u2165\u2167;\u6aa7r;\u6a7aot;\u62d7Par;\u6995uest;\u6a7c\u0280adels\u2184\u216a\u2190\u0656\u219b\u01f0\u2189\0\u218epro\xf8\u209er;\u6978q\u0100lq\u063f\u2196les\xf3\u2088i\xed\u066b\u0100en\u21a3\u21adrtneqq;\uc000\u2269\ufe00\xc5\u21aa\u0500Aabcefkosy\u21c4\u21c7\u21f1\u21f5\u21fa\u2218\u221d\u222f\u2268\u227dr\xf2\u03a0\u0200ilmr\u21d0\u21d4\u21d7\u21dbrs\xf0\u1484f\xbb\u2024il\xf4\u06a9\u0100dr\u21e0\u21e4cy;\u444a\u0180;cw\u08f4\u21eb\u21efir;\u6948;\u61adar;\u610firc;\u4125\u0180alr\u2201\u220e\u2213rts\u0100;u\u2209\u220a\u6665it\xbb\u220alip;\u6026con;\u62b9r;\uc000\ud835\udd25s\u0100ew\u2223\u2229arow;\u6925arow;\u6926\u0280amopr\u223a\u223e\u2243\u225e\u2263rr;\u61fftht;\u623bk\u0100lr\u2249\u2253eftarrow;\u61a9ightarrow;\u61aaf;\uc000\ud835\udd59bar;\u6015\u0180clt\u226f\u2274\u2278r;\uc000\ud835\udcbdas\xe8\u21f4rok;\u4127\u0100bp\u2282\u2287ull;\u6043hen\xbb\u1c5b\u0ae1\u22a3\0\u22aa\0\u22b8\u22c5\u22ce\0\u22d5\u22f3\0\0\u22f8\u2322\u2367\u2362\u237f\0\u2386\u23aa\u23b4cute\u803b\xed\u40ed\u0180;iy\u0771\u22b0\u22b5rc\u803b\xee\u40ee;\u4438\u0100cx\u22bc\u22bfy;\u4435cl\u803b\xa1\u40a1\u0100fr\u039f\u22c9;\uc000\ud835\udd26rave\u803b\xec\u40ec\u0200;ino\u073e\u22dd\u22e9\u22ee\u0100in\u22e2\u22e6nt;\u6a0ct;\u622dfin;\u69dcta;\u6129lig;\u4133\u0180aop\u22fe\u231a\u231d\u0180cgt\u2305\u2308\u2317r;\u412b\u0180elp\u071f\u230f\u2313in\xe5\u078ear\xf4\u0720h;\u4131f;\u62b7ed;\u41b5\u0280;cfot\u04f4\u232c\u2331\u233d\u2341are;\u6105in\u0100;t\u2338\u2339\u621eie;\u69dddo\xf4\u2319\u0280;celp\u0757\u234c\u2350\u235b\u2361al;\u62ba\u0100gr\u2355\u2359er\xf3\u1563\xe3\u234darhk;\u6a17rod;\u6a3c\u0200cgpt\u236f\u2372\u2376\u237by;\u4451on;\u412ff;\uc000\ud835\udd5aa;\u43b9uest\u803b\xbf\u40bf\u0100ci\u238a\u238fr;\uc000\ud835\udcben\u0280;Edsv\u04f4\u239b\u239d\u23a1\u04f3;\u62f9ot;\u62f5\u0100;v\u23a6\u23a7\u62f4;\u62f3\u0100;i\u0777\u23aelde;\u4129\u01eb\u23b8\0\u23bccy;\u4456l\u803b\xef\u40ef\u0300cfmosu\u23cc\u23d7\u23dc\u23e1\u23e7\u23f5\u0100iy\u23d1\u23d5rc;\u4135;\u4439r;\uc000\ud835\udd27ath;\u4237pf;\uc000\ud835\udd5b\u01e3\u23ec\0\u23f1r;\uc000\ud835\udcbfrcy;\u4458kcy;\u4454\u0400acfghjos\u240b\u2416\u2422\u2427\u242d\u2431\u2435\u243bppa\u0100;v\u2413\u2414\u43ba;\u43f0\u0100ey\u241b\u2420dil;\u4137;\u443ar;\uc000\ud835\udd28reen;\u4138cy;\u4445cy;\u445cpf;\uc000\ud835\udd5ccr;\uc000\ud835\udcc0\u0b80ABEHabcdefghjlmnoprstuv\u2470\u2481\u2486\u248d\u2491\u250e\u253d\u255a\u2580\u264e\u265e\u2665\u2679\u267d\u269a\u26b2\u26d8\u275d\u2768\u278b\u27c0\u2801\u2812\u0180art\u2477\u247a\u247cr\xf2\u09c6\xf2\u0395ail;\u691barr;\u690e\u0100;g\u0994\u248b;\u6a8bar;\u6962\u0963\u24a5\0\u24aa\0\u24b1\0\0\0\0\0\u24b5\u24ba\0\u24c6\u24c8\u24cd\0\u24f9ute;\u413amptyv;\u69b4ra\xee\u084cbda;\u43bbg\u0180;dl\u088e\u24c1\u24c3;\u6991\xe5\u088e;\u6a85uo\u803b\xab\u40abr\u0400;bfhlpst\u0899\u24de\u24e6\u24e9\u24eb\u24ee\u24f1\u24f5\u0100;f\u089d\u24e3s;\u691fs;\u691d\xeb\u2252p;\u61abl;\u6939im;\u6973l;\u61a2\u0180;ae\u24ff\u2500\u2504\u6aabil;\u6919\u0100;s\u2509\u250a\u6aad;\uc000\u2aad\ufe00\u0180abr\u2515\u2519\u251drr;\u690crk;\u6772\u0100ak\u2522\u252cc\u0100ek\u2528\u252a;\u407b;\u405b\u0100es\u2531\u2533;\u698bl\u0100du\u2539\u253b;\u698f;\u698d\u0200aeuy\u2546\u254b\u2556\u2558ron;\u413e\u0100di\u2550\u2554il;\u413c\xec\u08b0\xe2\u2529;\u443b\u0200cqrs\u2563\u2566\u256d\u257da;\u6936uo\u0100;r\u0e19\u1746\u0100du\u2572\u2577har;\u6967shar;\u694bh;\u61b2\u0280;fgqs\u258b\u258c\u0989\u25f3\u25ff\u6264t\u0280ahlrt\u2598\u25a4\u25b7\u25c2\u25e8rrow\u0100;t\u0899\u25a1a\xe9\u24f6arpoon\u0100du\u25af\u25b4own\xbb\u045ap\xbb\u0966eftarrows;\u61c7ight\u0180ahs\u25cd\u25d6\u25derrow\u0100;s\u08f4\u08a7arpoon\xf3\u0f98quigarro\xf7\u21f0hreetimes;\u62cb\u0180;qs\u258b\u0993\u25falan\xf4\u09ac\u0280;cdgs\u09ac\u260a\u260d\u261d\u2628c;\u6aa8ot\u0100;o\u2614\u2615\u6a7f\u0100;r\u261a\u261b\u6a81;\u6a83\u0100;e\u2622\u2625\uc000\u22da\ufe00s;\u6a93\u0280adegs\u2633\u2639\u263d\u2649\u264bppro\xf8\u24c6ot;\u62d6q\u0100gq\u2643\u2645\xf4\u0989gt\xf2\u248c\xf4\u099bi\xed\u09b2\u0180ilr\u2655\u08e1\u265asht;\u697c;\uc000\ud835\udd29\u0100;E\u099c\u2663;\u6a91\u0161\u2669\u2676r\u0100du\u25b2\u266e\u0100;l\u0965\u2673;\u696alk;\u6584cy;\u4459\u0280;acht\u0a48\u2688\u268b\u2691\u2696r\xf2\u25c1orne\xf2\u1d08ard;\u696bri;\u65fa\u0100io\u269f\u26a4dot;\u4140ust\u0100;a\u26ac\u26ad\u63b0che\xbb\u26ad\u0200Eaes\u26bb\u26bd\u26c9\u26d4;\u6268p\u0100;p\u26c3\u26c4\u6a89rox\xbb\u26c4\u0100;q\u26ce\u26cf\u6a87\u0100;q\u26ce\u26bbim;\u62e6\u0400abnoptwz\u26e9\u26f4\u26f7\u271a\u272f\u2741\u2747\u2750\u0100nr\u26ee\u26f1g;\u67ecr;\u61fdr\xeb\u08c1g\u0180lmr\u26ff\u270d\u2714eft\u0100ar\u09e6\u2707ight\xe1\u09f2apsto;\u67fcight\xe1\u09fdparrow\u0100lr\u2725\u2729ef\xf4\u24edight;\u61ac\u0180afl\u2736\u2739\u273dr;\u6985;\uc000\ud835\udd5dus;\u6a2dimes;\u6a34\u0161\u274b\u274fst;\u6217\xe1\u134e\u0180;ef\u2757\u2758\u1800\u65cange\xbb\u2758ar\u0100;l\u2764\u2765\u4028t;\u6993\u0280achmt\u2773\u2776\u277c\u2785\u2787r\xf2\u08a8orne\xf2\u1d8car\u0100;d\u0f98\u2783;\u696d;\u600eri;\u62bf\u0300achiqt\u2798\u279d\u0a40\u27a2\u27ae\u27bbquo;\u6039r;\uc000\ud835\udcc1m\u0180;eg\u09b2\u27aa\u27ac;\u6a8d;\u6a8f\u0100bu\u252a\u27b3o\u0100;r\u0e1f\u27b9;\u601arok;\u4142\u8400<;cdhilqr\u082b\u27d2\u2639\u27dc\u27e0\u27e5\u27ea\u27f0\u0100ci\u27d7\u27d9;\u6aa6r;\u6a79re\xe5\u25f2mes;\u62c9arr;\u6976uest;\u6a7b\u0100Pi\u27f5\u27f9ar;\u6996\u0180;ef\u2800\u092d\u181b\u65c3r\u0100du\u2807\u280dshar;\u694ahar;\u6966\u0100en\u2817\u2821rtneqq;\uc000\u2268\ufe00\xc5\u281e\u0700Dacdefhilnopsu\u2840\u2845\u2882\u288e\u2893\u28a0\u28a5\u28a8\u28da\u28e2\u28e4\u0a83\u28f3\u2902Dot;\u623a\u0200clpr\u284e\u2852\u2863\u287dr\u803b\xaf\u40af\u0100et\u2857\u2859;\u6642\u0100;e\u285e\u285f\u6720se\xbb\u285f\u0100;s\u103b\u2868to\u0200;dlu\u103b\u2873\u2877\u287bow\xee\u048cef\xf4\u090f\xf0\u13d1ker;\u65ae\u0100oy\u2887\u288cmma;\u6a29;\u443cash;\u6014asuredangle\xbb\u1626r;\uc000\ud835\udd2ao;\u6127\u0180cdn\u28af\u28b4\u28c9ro\u803b\xb5\u40b5\u0200;acd\u1464\u28bd\u28c0\u28c4s\xf4\u16a7ir;\u6af0ot\u80bb\xb7\u01b5us\u0180;bd\u28d2\u1903\u28d3\u6212\u0100;u\u1d3c\u28d8;\u6a2a\u0163\u28de\u28e1p;\u6adb\xf2\u2212\xf0\u0a81\u0100dp\u28e9\u28eeels;\u62a7f;\uc000\ud835\udd5e\u0100ct\u28f8\u28fdr;\uc000\ud835\udcc2pos\xbb\u159d\u0180;lm\u2909\u290a\u290d\u43bctimap;\u62b8\u0c00GLRVabcdefghijlmoprstuvw\u2942\u2953\u297e\u2989\u2998\u29da\u29e9\u2a15\u2a1a\u2a58\u2a5d\u2a83\u2a95\u2aa4\u2aa8\u2b04\u2b07\u2b44\u2b7f\u2bae\u2c34\u2c67\u2c7c\u2ce9\u0100gt\u2947\u294b;\uc000\u22d9\u0338\u0100;v\u2950\u0bcf\uc000\u226b\u20d2\u0180elt\u295a\u2972\u2976ft\u0100ar\u2961\u2967rrow;\u61cdightarrow;\u61ce;\uc000\u22d8\u0338\u0100;v\u297b\u0c47\uc000\u226a\u20d2ightarrow;\u61cf\u0100Dd\u298e\u2993ash;\u62afash;\u62ae\u0280bcnpt\u29a3\u29a7\u29ac\u29b1\u29ccla\xbb\u02deute;\u4144g;\uc000\u2220\u20d2\u0280;Eiop\u0d84\u29bc\u29c0\u29c5\u29c8;\uc000\u2a70\u0338d;\uc000\u224b\u0338s;\u4149ro\xf8\u0d84ur\u0100;a\u29d3\u29d4\u666el\u0100;s\u29d3\u0b38\u01f3\u29df\0\u29e3p\u80bb\xa0\u0b37mp\u0100;e\u0bf9\u0c00\u0280aeouy\u29f4\u29fe\u2a03\u2a10\u2a13\u01f0\u29f9\0\u29fb;\u6a43on;\u4148dil;\u4146ng\u0100;d\u0d7e\u2a0aot;\uc000\u2a6d\u0338p;\u6a42;\u443dash;\u6013\u0380;Aadqsx\u0b92\u2a29\u2a2d\u2a3b\u2a41\u2a45\u2a50rr;\u61d7r\u0100hr\u2a33\u2a36k;\u6924\u0100;o\u13f2\u13f0ot;\uc000\u2250\u0338ui\xf6\u0b63\u0100ei\u2a4a\u2a4ear;\u6928\xed\u0b98ist\u0100;s\u0ba0\u0b9fr;\uc000\ud835\udd2b\u0200Eest\u0bc5\u2a66\u2a79\u2a7c\u0180;qs\u0bbc\u2a6d\u0be1\u0180;qs\u0bbc\u0bc5\u2a74lan\xf4\u0be2i\xed\u0bea\u0100;r\u0bb6\u2a81\xbb\u0bb7\u0180Aap\u2a8a\u2a8d\u2a91r\xf2\u2971rr;\u61aear;\u6af2\u0180;sv\u0f8d\u2a9c\u0f8c\u0100;d\u2aa1\u2aa2\u62fc;\u62facy;\u445a\u0380AEadest\u2ab7\u2aba\u2abe\u2ac2\u2ac5\u2af6\u2af9r\xf2\u2966;\uc000\u2266\u0338rr;\u619ar;\u6025\u0200;fqs\u0c3b\u2ace\u2ae3\u2aeft\u0100ar\u2ad4\u2ad9rro\xf7\u2ac1ightarro\xf7\u2a90\u0180;qs\u0c3b\u2aba\u2aealan\xf4\u0c55\u0100;s\u0c55\u2af4\xbb\u0c36i\xed\u0c5d\u0100;r\u0c35\u2afei\u0100;e\u0c1a\u0c25i\xe4\u0d90\u0100pt\u2b0c\u2b11f;\uc000\ud835\udd5f\u8180\xac;in\u2b19\u2b1a\u2b36\u40acn\u0200;Edv\u0b89\u2b24\u2b28\u2b2e;\uc000\u22f9\u0338ot;\uc000\u22f5\u0338\u01e1\u0b89\u2b33\u2b35;\u62f7;\u62f6i\u0100;v\u0cb8\u2b3c\u01e1\u0cb8\u2b41\u2b43;\u62fe;\u62fd\u0180aor\u2b4b\u2b63\u2b69r\u0200;ast\u0b7b\u2b55\u2b5a\u2b5flle\xec\u0b7bl;\uc000\u2afd\u20e5;\uc000\u2202\u0338lint;\u6a14\u0180;ce\u0c92\u2b70\u2b73u\xe5\u0ca5\u0100;c\u0c98\u2b78\u0100;e\u0c92\u2b7d\xf1\u0c98\u0200Aait\u2b88\u2b8b\u2b9d\u2ba7r\xf2\u2988rr\u0180;cw\u2b94\u2b95\u2b99\u619b;\uc000\u2933\u0338;\uc000\u219d\u0338ghtarrow\xbb\u2b95ri\u0100;e\u0ccb\u0cd6\u0380chimpqu\u2bbd\u2bcd\u2bd9\u2b04\u0b78\u2be4\u2bef\u0200;cer\u0d32\u2bc6\u0d37\u2bc9u\xe5\u0d45;\uc000\ud835\udcc3ort\u026d\u2b05\0\0\u2bd6ar\xe1\u2b56m\u0100;e\u0d6e\u2bdf\u0100;q\u0d74\u0d73su\u0100bp\u2beb\u2bed\xe5\u0cf8\xe5\u0d0b\u0180bcp\u2bf6\u2c11\u2c19\u0200;Ees\u2bff\u2c00\u0d22\u2c04\u6284;\uc000\u2ac5\u0338et\u0100;e\u0d1b\u2c0bq\u0100;q\u0d23\u2c00c\u0100;e\u0d32\u2c17\xf1\u0d38\u0200;Ees\u2c22\u2c23\u0d5f\u2c27\u6285;\uc000\u2ac6\u0338et\u0100;e\u0d58\u2c2eq\u0100;q\u0d60\u2c23\u0200gilr\u2c3d\u2c3f\u2c45\u2c47\xec\u0bd7lde\u803b\xf1\u40f1\xe7\u0c43iangle\u0100lr\u2c52\u2c5ceft\u0100;e\u0c1a\u2c5a\xf1\u0c26ight\u0100;e\u0ccb\u2c65\xf1\u0cd7\u0100;m\u2c6c\u2c6d\u43bd\u0180;es\u2c74\u2c75\u2c79\u4023ro;\u6116p;\u6007\u0480DHadgilrs\u2c8f\u2c94\u2c99\u2c9e\u2ca3\u2cb0\u2cb6\u2cd3\u2ce3ash;\u62adarr;\u6904p;\uc000\u224d\u20d2ash;\u62ac\u0100et\u2ca8\u2cac;\uc000\u2265\u20d2;\uc000>\u20d2nfin;\u69de\u0180Aet\u2cbd\u2cc1\u2cc5rr;\u6902;\uc000\u2264\u20d2\u0100;r\u2cca\u2ccd\uc000<\u20d2ie;\uc000\u22b4\u20d2\u0100At\u2cd8\u2cdcrr;\u6903rie;\uc000\u22b5\u20d2im;\uc000\u223c\u20d2\u0180Aan\u2cf0\u2cf4\u2d02rr;\u61d6r\u0100hr\u2cfa\u2cfdk;\u6923\u0100;o\u13e7\u13e5ear;\u6927\u1253\u1a95\0\0\0\0\0\0\0\0\0\0\0\0\0\u2d2d\0\u2d38\u2d48\u2d60\u2d65\u2d72\u2d84\u1b07\0\0\u2d8d\u2dab\0\u2dc8\u2dce\0\u2ddc\u2e19\u2e2b\u2e3e\u2e43\u0100cs\u2d31\u1a97ute\u803b\xf3\u40f3\u0100iy\u2d3c\u2d45r\u0100;c\u1a9e\u2d42\u803b\xf4\u40f4;\u443e\u0280abios\u1aa0\u2d52\u2d57\u01c8\u2d5alac;\u4151v;\u6a38old;\u69bclig;\u4153\u0100cr\u2d69\u2d6dir;\u69bf;\uc000\ud835\udd2c\u036f\u2d79\0\0\u2d7c\0\u2d82n;\u42dbave\u803b\xf2\u40f2;\u69c1\u0100bm\u2d88\u0df4ar;\u69b5\u0200acit\u2d95\u2d98\u2da5\u2da8r\xf2\u1a80\u0100ir\u2d9d\u2da0r;\u69beoss;\u69bbn\xe5\u0e52;\u69c0\u0180aei\u2db1\u2db5\u2db9cr;\u414dga;\u43c9\u0180cdn\u2dc0\u2dc5\u01cdron;\u43bf;\u69b6pf;\uc000\ud835\udd60\u0180ael\u2dd4\u2dd7\u01d2r;\u69b7rp;\u69b9\u0380;adiosv\u2dea\u2deb\u2dee\u2e08\u2e0d\u2e10\u2e16\u6228r\xf2\u1a86\u0200;efm\u2df7\u2df8\u2e02\u2e05\u6a5dr\u0100;o\u2dfe\u2dff\u6134f\xbb\u2dff\u803b\xaa\u40aa\u803b\xba\u40bagof;\u62b6r;\u6a56lope;\u6a57;\u6a5b\u0180clo\u2e1f\u2e21\u2e27\xf2\u2e01ash\u803b\xf8\u40f8l;\u6298i\u016c\u2e2f\u2e34de\u803b\xf5\u40f5es\u0100;a\u01db\u2e3as;\u6a36ml\u803b\xf6\u40f6bar;\u633d\u0ae1\u2e5e\0\u2e7d\0\u2e80\u2e9d\0\u2ea2\u2eb9\0\0\u2ecb\u0e9c\0\u2f13\0\0\u2f2b\u2fbc\0\u2fc8r\u0200;ast\u0403\u2e67\u2e72\u0e85\u8100\xb6;l\u2e6d\u2e6e\u40b6le\xec\u0403\u0269\u2e78\0\0\u2e7bm;\u6af3;\u6afdy;\u443fr\u0280cimpt\u2e8b\u2e8f\u2e93\u1865\u2e97nt;\u4025od;\u402eil;\u6030enk;\u6031r;\uc000\ud835\udd2d\u0180imo\u2ea8\u2eb0\u2eb4\u0100;v\u2ead\u2eae\u43c6;\u43d5ma\xf4\u0a76ne;\u660e\u0180;tv\u2ebf\u2ec0\u2ec8\u43c0chfork\xbb\u1ffd;\u43d6\u0100au\u2ecf\u2edfn\u0100ck\u2ed5\u2eddk\u0100;h\u21f4\u2edb;\u610e\xf6\u21f4s\u0480;abcdemst\u2ef3\u2ef4\u1908\u2ef9\u2efd\u2f04\u2f06\u2f0a\u2f0e\u402bcir;\u6a23ir;\u6a22\u0100ou\u1d40\u2f02;\u6a25;\u6a72n\u80bb\xb1\u0e9dim;\u6a26wo;\u6a27\u0180ipu\u2f19\u2f20\u2f25ntint;\u6a15f;\uc000\ud835\udd61nd\u803b\xa3\u40a3\u0500;Eaceinosu\u0ec8\u2f3f\u2f41\u2f44\u2f47\u2f81\u2f89\u2f92\u2f7e\u2fb6;\u6ab3p;\u6ab7u\xe5\u0ed9\u0100;c\u0ece\u2f4c\u0300;acens\u0ec8\u2f59\u2f5f\u2f66\u2f68\u2f7eppro\xf8\u2f43urlye\xf1\u0ed9\xf1\u0ece\u0180aes\u2f6f\u2f76\u2f7approx;\u6ab9qq;\u6ab5im;\u62e8i\xed\u0edfme\u0100;s\u2f88\u0eae\u6032\u0180Eas\u2f78\u2f90\u2f7a\xf0\u2f75\u0180dfp\u0eec\u2f99\u2faf\u0180als\u2fa0\u2fa5\u2faalar;\u632eine;\u6312urf;\u6313\u0100;t\u0efb\u2fb4\xef\u0efbrel;\u62b0\u0100ci\u2fc0\u2fc5r;\uc000\ud835\udcc5;\u43c8ncsp;\u6008\u0300fiopsu\u2fda\u22e2\u2fdf\u2fe5\u2feb\u2ff1r;\uc000\ud835\udd2epf;\uc000\ud835\udd62rime;\u6057cr;\uc000\ud835\udcc6\u0180aeo\u2ff8\u3009\u3013t\u0100ei\u2ffe\u3005rnion\xf3\u06b0nt;\u6a16st\u0100;e\u3010\u3011\u403f\xf1\u1f19\xf4\u0f14\u0a80ABHabcdefhilmnoprstux\u3040\u3051\u3055\u3059\u30e0\u310e\u312b\u3147\u3162\u3172\u318e\u3206\u3215\u3224\u3229\u3258\u326e\u3272\u3290\u32b0\u32b7\u0180art\u3047\u304a\u304cr\xf2\u10b3\xf2\u03ddail;\u691car\xf2\u1c65ar;\u6964\u0380cdenqrt\u3068\u3075\u3078\u307f\u308f\u3094\u30cc\u0100eu\u306d\u3071;\uc000\u223d\u0331te;\u4155i\xe3\u116emptyv;\u69b3g\u0200;del\u0fd1\u3089\u308b\u308d;\u6992;\u69a5\xe5\u0fd1uo\u803b\xbb\u40bbr\u0580;abcfhlpstw\u0fdc\u30ac\u30af\u30b7\u30b9\u30bc\u30be\u30c0\u30c3\u30c7\u30cap;\u6975\u0100;f\u0fe0\u30b4s;\u6920;\u6933s;\u691e\xeb\u225d\xf0\u272el;\u6945im;\u6974l;\u61a3;\u619d\u0100ai\u30d1\u30d5il;\u691ao\u0100;n\u30db\u30dc\u6236al\xf3\u0f1e\u0180abr\u30e7\u30ea\u30eer\xf2\u17e5rk;\u6773\u0100ak\u30f3\u30fdc\u0100ek\u30f9\u30fb;\u407d;\u405d\u0100es\u3102\u3104;\u698cl\u0100du\u310a\u310c;\u698e;\u6990\u0200aeuy\u3117\u311c\u3127\u3129ron;\u4159\u0100di\u3121\u3125il;\u4157\xec\u0ff2\xe2\u30fa;\u4440\u0200clqs\u3134\u3137\u313d\u3144a;\u6937dhar;\u6969uo\u0100;r\u020e\u020dh;\u61b3\u0180acg\u314e\u315f\u0f44l\u0200;ips\u0f78\u3158\u315b\u109cn\xe5\u10bbar\xf4\u0fa9t;\u65ad\u0180ilr\u3169\u1023\u316esht;\u697d;\uc000\ud835\udd2f\u0100ao\u3177\u3186r\u0100du\u317d\u317f\xbb\u047b\u0100;l\u1091\u3184;\u696c\u0100;v\u318b\u318c\u43c1;\u43f1\u0180gns\u3195\u31f9\u31fcht\u0300ahlrst\u31a4\u31b0\u31c2\u31d8\u31e4\u31eerrow\u0100;t\u0fdc\u31ada\xe9\u30c8arpoon\u0100du\u31bb\u31bfow\xee\u317ep\xbb\u1092eft\u0100ah\u31ca\u31d0rrow\xf3\u0feaarpoon\xf3\u0551ightarrows;\u61c9quigarro\xf7\u30cbhreetimes;\u62ccg;\u42daingdotse\xf1\u1f32\u0180ahm\u320d\u3210\u3213r\xf2\u0feaa\xf2\u0551;\u600foust\u0100;a\u321e\u321f\u63b1che\xbb\u321fmid;\u6aee\u0200abpt\u3232\u323d\u3240\u3252\u0100nr\u3237\u323ag;\u67edr;\u61fer\xeb\u1003\u0180afl\u3247\u324a\u324er;\u6986;\uc000\ud835\udd63us;\u6a2eimes;\u6a35\u0100ap\u325d\u3267r\u0100;g\u3263\u3264\u4029t;\u6994olint;\u6a12ar\xf2\u31e3\u0200achq\u327b\u3280\u10bc\u3285quo;\u603ar;\uc000\ud835\udcc7\u0100bu\u30fb\u328ao\u0100;r\u0214\u0213\u0180hir\u3297\u329b\u32a0re\xe5\u31f8mes;\u62cai\u0200;efl\u32aa\u1059\u1821\u32ab\u65b9tri;\u69celuhar;\u6968;\u611e\u0d61\u32d5\u32db\u32df\u332c\u3338\u3371\0\u337a\u33a4\0\0\u33ec\u33f0\0\u3428\u3448\u345a\u34ad\u34b1\u34ca\u34f1\0\u3616\0\0\u3633cute;\u415bqu\xef\u27ba\u0500;Eaceinpsy\u11ed\u32f3\u32f5\u32ff\u3302\u330b\u330f\u331f\u3326\u3329;\u6ab4\u01f0\u32fa\0\u32fc;\u6ab8on;\u4161u\xe5\u11fe\u0100;d\u11f3\u3307il;\u415frc;\u415d\u0180Eas\u3316\u3318\u331b;\u6ab6p;\u6abaim;\u62e9olint;\u6a13i\xed\u1204;\u4441ot\u0180;be\u3334\u1d47\u3335\u62c5;\u6a66\u0380Aacmstx\u3346\u334a\u3357\u335b\u335e\u3363\u336drr;\u61d8r\u0100hr\u3350\u3352\xeb\u2228\u0100;o\u0a36\u0a34t\u803b\xa7\u40a7i;\u403bwar;\u6929m\u0100in\u3369\xf0nu\xf3\xf1t;\u6736r\u0100;o\u3376\u2055\uc000\ud835\udd30\u0200acoy\u3382\u3386\u3391\u33a0rp;\u666f\u0100hy\u338b\u338fcy;\u4449;\u4448rt\u026d\u3399\0\0\u339ci\xe4\u1464ara\xec\u2e6f\u803b\xad\u40ad\u0100gm\u33a8\u33b4ma\u0180;fv\u33b1\u33b2\u33b2\u43c3;\u43c2\u0400;deglnpr\u12ab\u33c5\u33c9\u33ce\u33d6\u33de\u33e1\u33e6ot;\u6a6a\u0100;q\u12b1\u12b0\u0100;E\u33d3\u33d4\u6a9e;\u6aa0\u0100;E\u33db\u33dc\u6a9d;\u6a9fe;\u6246lus;\u6a24arr;\u6972ar\xf2\u113d\u0200aeit\u33f8\u3408\u340f\u3417\u0100ls\u33fd\u3404lsetm\xe9\u336ahp;\u6a33parsl;\u69e4\u0100dl\u1463\u3414e;\u6323\u0100;e\u341c\u341d\u6aaa\u0100;s\u3422\u3423\u6aac;\uc000\u2aac\ufe00\u0180flp\u342e\u3433\u3442tcy;\u444c\u0100;b\u3438\u3439\u402f\u0100;a\u343e\u343f\u69c4r;\u633ff;\uc000\ud835\udd64a\u0100dr\u344d\u0402es\u0100;u\u3454\u3455\u6660it\xbb\u3455\u0180csu\u3460\u3479\u349f\u0100au\u3465\u346fp\u0100;s\u1188\u346b;\uc000\u2293\ufe00p\u0100;s\u11b4\u3475;\uc000\u2294\ufe00u\u0100bp\u347f\u348f\u0180;es\u1197\u119c\u3486et\u0100;e\u1197\u348d\xf1\u119d\u0180;es\u11a8\u11ad\u3496et\u0100;e\u11a8\u349d\xf1\u11ae\u0180;af\u117b\u34a6\u05b0r\u0165\u34ab\u05b1\xbb\u117car\xf2\u1148\u0200cemt\u34b9\u34be\u34c2\u34c5r;\uc000\ud835\udcc8tm\xee\xf1i\xec\u3415ar\xe6\u11be\u0100ar\u34ce\u34d5r\u0100;f\u34d4\u17bf\u6606\u0100an\u34da\u34edight\u0100ep\u34e3\u34eapsilo\xee\u1ee0h\xe9\u2eafs\xbb\u2852\u0280bcmnp\u34fb\u355e\u1209\u358b\u358e\u0480;Edemnprs\u350e\u350f\u3511\u3515\u351e\u3523\u352c\u3531\u3536\u6282;\u6ac5ot;\u6abd\u0100;d\u11da\u351aot;\u6ac3ult;\u6ac1\u0100Ee\u3528\u352a;\u6acb;\u628alus;\u6abfarr;\u6979\u0180eiu\u353d\u3552\u3555t\u0180;en\u350e\u3545\u354bq\u0100;q\u11da\u350feq\u0100;q\u352b\u3528m;\u6ac7\u0100bp\u355a\u355c;\u6ad5;\u6ad3c\u0300;acens\u11ed\u356c\u3572\u3579\u357b\u3326ppro\xf8\u32faurlye\xf1\u11fe\xf1\u11f3\u0180aes\u3582\u3588\u331bppro\xf8\u331aq\xf1\u3317g;\u666a\u0680123;Edehlmnps\u35a9\u35ac\u35af\u121c\u35b2\u35b4\u35c0\u35c9\u35d5\u35da\u35df\u35e8\u35ed\u803b\xb9\u40b9\u803b\xb2\u40b2\u803b\xb3\u40b3;\u6ac6\u0100os\u35b9\u35bct;\u6abeub;\u6ad8\u0100;d\u1222\u35c5ot;\u6ac4s\u0100ou\u35cf\u35d2l;\u67c9b;\u6ad7arr;\u697bult;\u6ac2\u0100Ee\u35e4\u35e6;\u6acc;\u628blus;\u6ac0\u0180eiu\u35f4\u3609\u360ct\u0180;en\u121c\u35fc\u3602q\u0100;q\u1222\u35b2eq\u0100;q\u35e7\u35e4m;\u6ac8\u0100bp\u3611\u3613;\u6ad4;\u6ad6\u0180Aan\u361c\u3620\u362drr;\u61d9r\u0100hr\u3626\u3628\xeb\u222e\u0100;o\u0a2b\u0a29war;\u692alig\u803b\xdf\u40df\u0be1\u3651\u365d\u3660\u12ce\u3673\u3679\0\u367e\u36c2\0\0\0\0\0\u36db\u3703\0\u3709\u376c\0\0\0\u3787\u0272\u3656\0\0\u365bget;\u6316;\u43c4r\xeb\u0e5f\u0180aey\u3666\u366b\u3670ron;\u4165dil;\u4163;\u4442lrec;\u6315r;\uc000\ud835\udd31\u0200eiko\u3686\u369d\u36b5\u36bc\u01f2\u368b\0\u3691e\u01004f\u1284\u1281a\u0180;sv\u3698\u3699\u369b\u43b8ym;\u43d1\u0100cn\u36a2\u36b2k\u0100as\u36a8\u36aeppro\xf8\u12c1im\xbb\u12acs\xf0\u129e\u0100as\u36ba\u36ae\xf0\u12c1rn\u803b\xfe\u40fe\u01ec\u031f\u36c6\u22e7es\u8180\xd7;bd\u36cf\u36d0\u36d8\u40d7\u0100;a\u190f\u36d5r;\u6a31;\u6a30\u0180eps\u36e1\u36e3\u3700\xe1\u2a4d\u0200;bcf\u0486\u36ec\u36f0\u36f4ot;\u6336ir;\u6af1\u0100;o\u36f9\u36fc\uc000\ud835\udd65rk;\u6ada\xe1\u3362rime;\u6034\u0180aip\u370f\u3712\u3764d\xe5\u1248\u0380adempst\u3721\u374d\u3740\u3751\u3757\u375c\u375fngle\u0280;dlqr\u3730\u3731\u3736\u3740\u3742\u65b5own\xbb\u1dbbeft\u0100;e\u2800\u373e\xf1\u092e;\u625cight\u0100;e\u32aa\u374b\xf1\u105aot;\u65ecinus;\u6a3alus;\u6a39b;\u69cdime;\u6a3bezium;\u63e2\u0180cht\u3772\u377d\u3781\u0100ry\u3777\u377b;\uc000\ud835\udcc9;\u4446cy;\u445brok;\u4167\u0100io\u378b\u378ex\xf4\u1777head\u0100lr\u3797\u37a0eftarro\xf7\u084fightarrow\xbb\u0f5d\u0900AHabcdfghlmoprstuw\u37d0\u37d3\u37d7\u37e4\u37f0\u37fc\u380e\u381c\u3823\u3834\u3851\u385d\u386b\u38a9\u38cc\u38d2\u38ea\u38f6r\xf2\u03edar;\u6963\u0100cr\u37dc\u37e2ute\u803b\xfa\u40fa\xf2\u1150r\u01e3\u37ea\0\u37edy;\u445eve;\u416d\u0100iy\u37f5\u37farc\u803b\xfb\u40fb;\u4443\u0180abh\u3803\u3806\u380br\xf2\u13adlac;\u4171a\xf2\u13c3\u0100ir\u3813\u3818sht;\u697e;\uc000\ud835\udd32rave\u803b\xf9\u40f9\u0161\u3827\u3831r\u0100lr\u382c\u382e\xbb\u0957\xbb\u1083lk;\u6580\u0100ct\u3839\u384d\u026f\u383f\0\0\u384arn\u0100;e\u3845\u3846\u631cr\xbb\u3846op;\u630fri;\u65f8\u0100al\u3856\u385acr;\u416b\u80bb\xa8\u0349\u0100gp\u3862\u3866on;\u4173f;\uc000\ud835\udd66\u0300adhlsu\u114b\u3878\u387d\u1372\u3891\u38a0own\xe1\u13b3arpoon\u0100lr\u3888\u388cef\xf4\u382digh\xf4\u382fi\u0180;hl\u3899\u389a\u389c\u43c5\xbb\u13faon\xbb\u389aparrows;\u61c8\u0180cit\u38b0\u38c4\u38c8\u026f\u38b6\0\0\u38c1rn\u0100;e\u38bc\u38bd\u631dr\xbb\u38bdop;\u630eng;\u416fri;\u65f9cr;\uc000\ud835\udcca\u0180dir\u38d9\u38dd\u38e2ot;\u62f0lde;\u4169i\u0100;f\u3730\u38e8\xbb\u1813\u0100am\u38ef\u38f2r\xf2\u38a8l\u803b\xfc\u40fcangle;\u69a7\u0780ABDacdeflnoprsz\u391c\u391f\u3929\u392d\u39b5\u39b8\u39bd\u39df\u39e4\u39e8\u39f3\u39f9\u39fd\u3a01\u3a20r\xf2\u03f7ar\u0100;v\u3926\u3927\u6ae8;\u6ae9as\xe8\u03e1\u0100nr\u3932\u3937grt;\u699c\u0380eknprst\u34e3\u3946\u394b\u3952\u395d\u3964\u3996app\xe1\u2415othin\xe7\u1e96\u0180hir\u34eb\u2ec8\u3959op\xf4\u2fb5\u0100;h\u13b7\u3962\xef\u318d\u0100iu\u3969\u396dgm\xe1\u33b3\u0100bp\u3972\u3984setneq\u0100;q\u397d\u3980\uc000\u228a\ufe00;\uc000\u2acb\ufe00setneq\u0100;q\u398f\u3992\uc000\u228b\ufe00;\uc000\u2acc\ufe00\u0100hr\u399b\u399fet\xe1\u369ciangle\u0100lr\u39aa\u39afeft\xbb\u0925ight\xbb\u1051y;\u4432ash\xbb\u1036\u0180elr\u39c4\u39d2\u39d7\u0180;be\u2dea\u39cb\u39cfar;\u62bbq;\u625alip;\u62ee\u0100bt\u39dc\u1468a\xf2\u1469r;\uc000\ud835\udd33tr\xe9\u39aesu\u0100bp\u39ef\u39f1\xbb\u0d1c\xbb\u0d59pf;\uc000\ud835\udd67ro\xf0\u0efbtr\xe9\u39b4\u0100cu\u3a06\u3a0br;\uc000\ud835\udccb\u0100bp\u3a10\u3a18n\u0100Ee\u3980\u3a16\xbb\u397en\u0100Ee\u3992\u3a1e\xbb\u3990igzag;\u699a\u0380cefoprs\u3a36\u3a3b\u3a56\u3a5b\u3a54\u3a61\u3a6airc;\u4175\u0100di\u3a40\u3a51\u0100bg\u3a45\u3a49ar;\u6a5fe\u0100;q\u15fa\u3a4f;\u6259erp;\u6118r;\uc000\ud835\udd34pf;\uc000\ud835\udd68\u0100;e\u1479\u3a66at\xe8\u1479cr;\uc000\ud835\udccc\u0ae3\u178e\u3a87\0\u3a8b\0\u3a90\u3a9b\0\0\u3a9d\u3aa8\u3aab\u3aaf\0\0\u3ac3\u3ace\0\u3ad8\u17dc\u17dftr\xe9\u17d1r;\uc000\ud835\udd35\u0100Aa\u3a94\u3a97r\xf2\u03c3r\xf2\u09f6;\u43be\u0100Aa\u3aa1\u3aa4r\xf2\u03b8r\xf2\u09eba\xf0\u2713is;\u62fb\u0180dpt\u17a4\u3ab5\u3abe\u0100fl\u3aba\u17a9;\uc000\ud835\udd69im\xe5\u17b2\u0100Aa\u3ac7\u3acar\xf2\u03cer\xf2\u0a01\u0100cq\u3ad2\u17b8r;\uc000\ud835\udccd\u0100pt\u17d6\u3adcr\xe9\u17d4\u0400acefiosu\u3af0\u3afd\u3b08\u3b0c\u3b11\u3b15\u3b1b\u3b21c\u0100uy\u3af6\u3afbte\u803b\xfd\u40fd;\u444f\u0100iy\u3b02\u3b06rc;\u4177;\u444bn\u803b\xa5\u40a5r;\uc000\ud835\udd36cy;\u4457pf;\uc000\ud835\udd6acr;\uc000\ud835\udcce\u0100cm\u3b26\u3b29y;\u444el\u803b\xff\u40ff\u0500acdefhiosw\u3b42\u3b48\u3b54\u3b58\u3b64\u3b69\u3b6d\u3b74\u3b7a\u3b80cute;\u417a\u0100ay\u3b4d\u3b52ron;\u417e;\u4437ot;\u417c\u0100et\u3b5d\u3b61tr\xe6\u155fa;\u43b6r;\uc000\ud835\udd37cy;\u4436grarr;\u61ddpf;\uc000\ud835\udd6bcr;\uc000\ud835\udccf\u0100jn\u3b85\u3b87;\u600dj;\u600c" + .split("") + .map((c) => c.charCodeAt(0)) +); diff --git a/packages/webui/third_party/editor/entities/src/generated/decode-data-xml.ts b/packages/webui/third_party/editor/entities/src/generated/decode-data-xml.ts new file mode 100644 index 000000000..d36c066f7 --- /dev/null +++ b/packages/webui/third_party/editor/entities/src/generated/decode-data-xml.ts @@ -0,0 +1,8 @@ +// Generated using scripts/write-decode-map.ts + +export default new Uint16Array( + // prettier-ignore + "\u0200aglq\t\x15\x18\x1b\u026d\x0f\0\0\x12p;\u4026os;\u4027t;\u403et;\u403cuot;\u4022" + .split("") + .map((c) => c.charCodeAt(0)) +); diff --git a/packages/webui/third_party/editor/entities/src/generated/encode-html.ts b/packages/webui/third_party/editor/entities/src/generated/encode-html.ts new file mode 100644 index 000000000..aba0f556d --- /dev/null +++ b/packages/webui/third_party/editor/entities/src/generated/encode-html.ts @@ -0,0 +1,17 @@ +// Generated using scripts/write-encode-map.ts + +type EncodeTrieNode = + | string + | { v?: string; n: number | Map; o?: string }; + +function restoreDiff>( + arr: T +): T { + for (let i = 1; i < arr.length; i++) { + arr[i][0] += arr[i - 1][0] + 1; + } + return arr; +} + +// prettier-ignore +export default new Map(/* #__PURE__ */restoreDiff([[9," "],[0," "],[22,"!"],[0,"""],[0,"#"],[0,"$"],[0,"%"],[0,"&"],[0,"'"],[0,"("],[0,")"],[0,"*"],[0,"+"],[0,","],[1,"."],[0,"/"],[10,":"],[0,";"],[0,{v:"<",n:8402,o:"<⃒"}],[0,{v:"=",n:8421,o:"=⃥"}],[0,{v:">",n:8402,o:">⃒"}],[0,"?"],[0,"@"],[26,"["],[0,"\"],[0,"]"],[0,"^"],[0,"_"],[0,"`"],[5,{n:106,o:"fj"}],[20,"{"],[0,"|"],[0,"}"],[34," "],[0,"¡"],[0,"¢"],[0,"£"],[0,"¤"],[0,"¥"],[0,"¦"],[0,"§"],[0,"¨"],[0,"©"],[0,"ª"],[0,"«"],[0,"¬"],[0,"­"],[0,"®"],[0,"¯"],[0,"°"],[0,"±"],[0,"²"],[0,"³"],[0,"´"],[0,"µ"],[0,"¶"],[0,"·"],[0,"¸"],[0,"¹"],[0,"º"],[0,"»"],[0,"¼"],[0,"½"],[0,"¾"],[0,"¿"],[0,"À"],[0,"Á"],[0,"Â"],[0,"Ã"],[0,"Ä"],[0,"Å"],[0,"Æ"],[0,"Ç"],[0,"È"],[0,"É"],[0,"Ê"],[0,"Ë"],[0,"Ì"],[0,"Í"],[0,"Î"],[0,"Ï"],[0,"Ð"],[0,"Ñ"],[0,"Ò"],[0,"Ó"],[0,"Ô"],[0,"Õ"],[0,"Ö"],[0,"×"],[0,"Ø"],[0,"Ù"],[0,"Ú"],[0,"Û"],[0,"Ü"],[0,"Ý"],[0,"Þ"],[0,"ß"],[0,"à"],[0,"á"],[0,"â"],[0,"ã"],[0,"ä"],[0,"å"],[0,"æ"],[0,"ç"],[0,"è"],[0,"é"],[0,"ê"],[0,"ë"],[0,"ì"],[0,"í"],[0,"î"],[0,"ï"],[0,"ð"],[0,"ñ"],[0,"ò"],[0,"ó"],[0,"ô"],[0,"õ"],[0,"ö"],[0,"÷"],[0,"ø"],[0,"ù"],[0,"ú"],[0,"û"],[0,"ü"],[0,"ý"],[0,"þ"],[0,"ÿ"],[0,"Ā"],[0,"ā"],[0,"Ă"],[0,"ă"],[0,"Ą"],[0,"ą"],[0,"Ć"],[0,"ć"],[0,"Ĉ"],[0,"ĉ"],[0,"Ċ"],[0,"ċ"],[0,"Č"],[0,"č"],[0,"Ď"],[0,"ď"],[0,"Đ"],[0,"đ"],[0,"Ē"],[0,"ē"],[2,"Ė"],[0,"ė"],[0,"Ę"],[0,"ę"],[0,"Ě"],[0,"ě"],[0,"Ĝ"],[0,"ĝ"],[0,"Ğ"],[0,"ğ"],[0,"Ġ"],[0,"ġ"],[0,"Ģ"],[1,"Ĥ"],[0,"ĥ"],[0,"Ħ"],[0,"ħ"],[0,"Ĩ"],[0,"ĩ"],[0,"Ī"],[0,"ī"],[2,"Į"],[0,"į"],[0,"İ"],[0,"ı"],[0,"IJ"],[0,"ij"],[0,"Ĵ"],[0,"ĵ"],[0,"Ķ"],[0,"ķ"],[0,"ĸ"],[0,"Ĺ"],[0,"ĺ"],[0,"Ļ"],[0,"ļ"],[0,"Ľ"],[0,"ľ"],[0,"Ŀ"],[0,"ŀ"],[0,"Ł"],[0,"ł"],[0,"Ń"],[0,"ń"],[0,"Ņ"],[0,"ņ"],[0,"Ň"],[0,"ň"],[0,"ʼn"],[0,"Ŋ"],[0,"ŋ"],[0,"Ō"],[0,"ō"],[2,"Ő"],[0,"ő"],[0,"Œ"],[0,"œ"],[0,"Ŕ"],[0,"ŕ"],[0,"Ŗ"],[0,"ŗ"],[0,"Ř"],[0,"ř"],[0,"Ś"],[0,"ś"],[0,"Ŝ"],[0,"ŝ"],[0,"Ş"],[0,"ş"],[0,"Š"],[0,"š"],[0,"Ţ"],[0,"ţ"],[0,"Ť"],[0,"ť"],[0,"Ŧ"],[0,"ŧ"],[0,"Ũ"],[0,"ũ"],[0,"Ū"],[0,"ū"],[0,"Ŭ"],[0,"ŭ"],[0,"Ů"],[0,"ů"],[0,"Ű"],[0,"ű"],[0,"Ų"],[0,"ų"],[0,"Ŵ"],[0,"ŵ"],[0,"Ŷ"],[0,"ŷ"],[0,"Ÿ"],[0,"Ź"],[0,"ź"],[0,"Ż"],[0,"ż"],[0,"Ž"],[0,"ž"],[19,"ƒ"],[34,"Ƶ"],[63,"ǵ"],[65,"ȷ"],[142,"ˆ"],[0,"ˇ"],[16,"˘"],[0,"˙"],[0,"˚"],[0,"˛"],[0,"˜"],[0,"˝"],[51,"̑"],[127,"Α"],[0,"Β"],[0,"Γ"],[0,"Δ"],[0,"Ε"],[0,"Ζ"],[0,"Η"],[0,"Θ"],[0,"Ι"],[0,"Κ"],[0,"Λ"],[0,"Μ"],[0,"Ν"],[0,"Ξ"],[0,"Ο"],[0,"Π"],[0,"Ρ"],[1,"Σ"],[0,"Τ"],[0,"Υ"],[0,"Φ"],[0,"Χ"],[0,"Ψ"],[0,"Ω"],[7,"α"],[0,"β"],[0,"γ"],[0,"δ"],[0,"ε"],[0,"ζ"],[0,"η"],[0,"θ"],[0,"ι"],[0,"κ"],[0,"λ"],[0,"μ"],[0,"ν"],[0,"ξ"],[0,"ο"],[0,"π"],[0,"ρ"],[0,"ς"],[0,"σ"],[0,"τ"],[0,"υ"],[0,"φ"],[0,"χ"],[0,"ψ"],[0,"ω"],[7,"ϑ"],[0,"ϒ"],[2,"ϕ"],[0,"ϖ"],[5,"Ϝ"],[0,"ϝ"],[18,"ϰ"],[0,"ϱ"],[3,"ϵ"],[0,"϶"],[10,"Ё"],[0,"Ђ"],[0,"Ѓ"],[0,"Є"],[0,"Ѕ"],[0,"І"],[0,"Ї"],[0,"Ј"],[0,"Љ"],[0,"Њ"],[0,"Ћ"],[0,"Ќ"],[1,"Ў"],[0,"Џ"],[0,"А"],[0,"Б"],[0,"В"],[0,"Г"],[0,"Д"],[0,"Е"],[0,"Ж"],[0,"З"],[0,"И"],[0,"Й"],[0,"К"],[0,"Л"],[0,"М"],[0,"Н"],[0,"О"],[0,"П"],[0,"Р"],[0,"С"],[0,"Т"],[0,"У"],[0,"Ф"],[0,"Х"],[0,"Ц"],[0,"Ч"],[0,"Ш"],[0,"Щ"],[0,"Ъ"],[0,"Ы"],[0,"Ь"],[0,"Э"],[0,"Ю"],[0,"Я"],[0,"а"],[0,"б"],[0,"в"],[0,"г"],[0,"д"],[0,"е"],[0,"ж"],[0,"з"],[0,"и"],[0,"й"],[0,"к"],[0,"л"],[0,"м"],[0,"н"],[0,"о"],[0,"п"],[0,"р"],[0,"с"],[0,"т"],[0,"у"],[0,"ф"],[0,"х"],[0,"ц"],[0,"ч"],[0,"ш"],[0,"щ"],[0,"ъ"],[0,"ы"],[0,"ь"],[0,"э"],[0,"ю"],[0,"я"],[1,"ё"],[0,"ђ"],[0,"ѓ"],[0,"є"],[0,"ѕ"],[0,"і"],[0,"ї"],[0,"ј"],[0,"љ"],[0,"њ"],[0,"ћ"],[0,"ќ"],[1,"ў"],[0,"џ"],[7074," "],[0," "],[0," "],[0," "],[1," "],[0," "],[0," "],[0," "],[0,"​"],[0,"‌"],[0,"‍"],[0,"‎"],[0,"‏"],[0,"‐"],[2,"–"],[0,"—"],[0,"―"],[0,"‖"],[1,"‘"],[0,"’"],[0,"‚"],[1,"“"],[0,"”"],[0,"„"],[1,"†"],[0,"‡"],[0,"•"],[2,"‥"],[0,"…"],[9,"‰"],[0,"‱"],[0,"′"],[0,"″"],[0,"‴"],[0,"‵"],[3,"‹"],[0,"›"],[3,"‾"],[2,"⁁"],[1,"⁃"],[0,"⁄"],[10,"⁏"],[7,"⁗"],[7,{v:" ",n:8202,o:"  "}],[0,"⁠"],[0,"⁡"],[0,"⁢"],[0,"⁣"],[72,"€"],[46,"⃛"],[0,"⃜"],[37,"ℂ"],[2,"℅"],[4,"ℊ"],[0,"ℋ"],[0,"ℌ"],[0,"ℍ"],[0,"ℎ"],[0,"ℏ"],[0,"ℐ"],[0,"ℑ"],[0,"ℒ"],[0,"ℓ"],[1,"ℕ"],[0,"№"],[0,"℗"],[0,"℘"],[0,"ℙ"],[0,"ℚ"],[0,"ℛ"],[0,"ℜ"],[0,"ℝ"],[0,"℞"],[3,"™"],[1,"ℤ"],[2,"℧"],[0,"ℨ"],[0,"℩"],[2,"ℬ"],[0,"ℭ"],[1,"ℯ"],[0,"ℰ"],[0,"ℱ"],[1,"ℳ"],[0,"ℴ"],[0,"ℵ"],[0,"ℶ"],[0,"ℷ"],[0,"ℸ"],[12,"ⅅ"],[0,"ⅆ"],[0,"ⅇ"],[0,"ⅈ"],[10,"⅓"],[0,"⅔"],[0,"⅕"],[0,"⅖"],[0,"⅗"],[0,"⅘"],[0,"⅙"],[0,"⅚"],[0,"⅛"],[0,"⅜"],[0,"⅝"],[0,"⅞"],[49,"←"],[0,"↑"],[0,"→"],[0,"↓"],[0,"↔"],[0,"↕"],[0,"↖"],[0,"↗"],[0,"↘"],[0,"↙"],[0,"↚"],[0,"↛"],[1,{v:"↝",n:824,o:"↝̸"}],[0,"↞"],[0,"↟"],[0,"↠"],[0,"↡"],[0,"↢"],[0,"↣"],[0,"↤"],[0,"↥"],[0,"↦"],[0,"↧"],[1,"↩"],[0,"↪"],[0,"↫"],[0,"↬"],[0,"↭"],[0,"↮"],[1,"↰"],[0,"↱"],[0,"↲"],[0,"↳"],[1,"↵"],[0,"↶"],[0,"↷"],[2,"↺"],[0,"↻"],[0,"↼"],[0,"↽"],[0,"↾"],[0,"↿"],[0,"⇀"],[0,"⇁"],[0,"⇂"],[0,"⇃"],[0,"⇄"],[0,"⇅"],[0,"⇆"],[0,"⇇"],[0,"⇈"],[0,"⇉"],[0,"⇊"],[0,"⇋"],[0,"⇌"],[0,"⇍"],[0,"⇎"],[0,"⇏"],[0,"⇐"],[0,"⇑"],[0,"⇒"],[0,"⇓"],[0,"⇔"],[0,"⇕"],[0,"⇖"],[0,"⇗"],[0,"⇘"],[0,"⇙"],[0,"⇚"],[0,"⇛"],[1,"⇝"],[6,"⇤"],[0,"⇥"],[15,"⇵"],[7,"⇽"],[0,"⇾"],[0,"⇿"],[0,"∀"],[0,"∁"],[0,{v:"∂",n:824,o:"∂̸"}],[0,"∃"],[0,"∄"],[0,"∅"],[1,"∇"],[0,"∈"],[0,"∉"],[1,"∋"],[0,"∌"],[2,"∏"],[0,"∐"],[0,"∑"],[0,"−"],[0,"∓"],[0,"∔"],[1,"∖"],[0,"∗"],[0,"∘"],[1,"√"],[2,"∝"],[0,"∞"],[0,"∟"],[0,{v:"∠",n:8402,o:"∠⃒"}],[0,"∡"],[0,"∢"],[0,"∣"],[0,"∤"],[0,"∥"],[0,"∦"],[0,"∧"],[0,"∨"],[0,{v:"∩",n:65024,o:"∩︀"}],[0,{v:"∪",n:65024,o:"∪︀"}],[0,"∫"],[0,"∬"],[0,"∭"],[0,"∮"],[0,"∯"],[0,"∰"],[0,"∱"],[0,"∲"],[0,"∳"],[0,"∴"],[0,"∵"],[0,"∶"],[0,"∷"],[0,"∸"],[1,"∺"],[0,"∻"],[0,{v:"∼",n:8402,o:"∼⃒"}],[0,{v:"∽",n:817,o:"∽̱"}],[0,{v:"∾",n:819,o:"∾̳"}],[0,"∿"],[0,"≀"],[0,"≁"],[0,{v:"≂",n:824,o:"≂̸"}],[0,"≃"],[0,"≄"],[0,"≅"],[0,"≆"],[0,"≇"],[0,"≈"],[0,"≉"],[0,"≊"],[0,{v:"≋",n:824,o:"≋̸"}],[0,"≌"],[0,{v:"≍",n:8402,o:"≍⃒"}],[0,{v:"≎",n:824,o:"≎̸"}],[0,{v:"≏",n:824,o:"≏̸"}],[0,{v:"≐",n:824,o:"≐̸"}],[0,"≑"],[0,"≒"],[0,"≓"],[0,"≔"],[0,"≕"],[0,"≖"],[0,"≗"],[1,"≙"],[0,"≚"],[1,"≜"],[2,"≟"],[0,"≠"],[0,{v:"≡",n:8421,o:"≡⃥"}],[0,"≢"],[1,{v:"≤",n:8402,o:"≤⃒"}],[0,{v:"≥",n:8402,o:"≥⃒"}],[0,{v:"≦",n:824,o:"≦̸"}],[0,{v:"≧",n:824,o:"≧̸"}],[0,{v:"≨",n:65024,o:"≨︀"}],[0,{v:"≩",n:65024,o:"≩︀"}],[0,{v:"≪",n:new Map(/* #__PURE__ */restoreDiff([[824,"≪̸"],[7577,"≪⃒"]]))}],[0,{v:"≫",n:new Map(/* #__PURE__ */restoreDiff([[824,"≫̸"],[7577,"≫⃒"]]))}],[0,"≬"],[0,"≭"],[0,"≮"],[0,"≯"],[0,"≰"],[0,"≱"],[0,"≲"],[0,"≳"],[0,"≴"],[0,"≵"],[0,"≶"],[0,"≷"],[0,"≸"],[0,"≹"],[0,"≺"],[0,"≻"],[0,"≼"],[0,"≽"],[0,"≾"],[0,{v:"≿",n:824,o:"≿̸"}],[0,"⊀"],[0,"⊁"],[0,{v:"⊂",n:8402,o:"⊂⃒"}],[0,{v:"⊃",n:8402,o:"⊃⃒"}],[0,"⊄"],[0,"⊅"],[0,"⊆"],[0,"⊇"],[0,"⊈"],[0,"⊉"],[0,{v:"⊊",n:65024,o:"⊊︀"}],[0,{v:"⊋",n:65024,o:"⊋︀"}],[1,"⊍"],[0,"⊎"],[0,{v:"⊏",n:824,o:"⊏̸"}],[0,{v:"⊐",n:824,o:"⊐̸"}],[0,"⊑"],[0,"⊒"],[0,{v:"⊓",n:65024,o:"⊓︀"}],[0,{v:"⊔",n:65024,o:"⊔︀"}],[0,"⊕"],[0,"⊖"],[0,"⊗"],[0,"⊘"],[0,"⊙"],[0,"⊚"],[0,"⊛"],[1,"⊝"],[0,"⊞"],[0,"⊟"],[0,"⊠"],[0,"⊡"],[0,"⊢"],[0,"⊣"],[0,"⊤"],[0,"⊥"],[1,"⊧"],[0,"⊨"],[0,"⊩"],[0,"⊪"],[0,"⊫"],[0,"⊬"],[0,"⊭"],[0,"⊮"],[0,"⊯"],[0,"⊰"],[1,"⊲"],[0,"⊳"],[0,{v:"⊴",n:8402,o:"⊴⃒"}],[0,{v:"⊵",n:8402,o:"⊵⃒"}],[0,"⊶"],[0,"⊷"],[0,"⊸"],[0,"⊹"],[0,"⊺"],[0,"⊻"],[1,"⊽"],[0,"⊾"],[0,"⊿"],[0,"⋀"],[0,"⋁"],[0,"⋂"],[0,"⋃"],[0,"⋄"],[0,"⋅"],[0,"⋆"],[0,"⋇"],[0,"⋈"],[0,"⋉"],[0,"⋊"],[0,"⋋"],[0,"⋌"],[0,"⋍"],[0,"⋎"],[0,"⋏"],[0,"⋐"],[0,"⋑"],[0,"⋒"],[0,"⋓"],[0,"⋔"],[0,"⋕"],[0,"⋖"],[0,"⋗"],[0,{v:"⋘",n:824,o:"⋘̸"}],[0,{v:"⋙",n:824,o:"⋙̸"}],[0,{v:"⋚",n:65024,o:"⋚︀"}],[0,{v:"⋛",n:65024,o:"⋛︀"}],[2,"⋞"],[0,"⋟"],[0,"⋠"],[0,"⋡"],[0,"⋢"],[0,"⋣"],[2,"⋦"],[0,"⋧"],[0,"⋨"],[0,"⋩"],[0,"⋪"],[0,"⋫"],[0,"⋬"],[0,"⋭"],[0,"⋮"],[0,"⋯"],[0,"⋰"],[0,"⋱"],[0,"⋲"],[0,"⋳"],[0,"⋴"],[0,{v:"⋵",n:824,o:"⋵̸"}],[0,"⋶"],[0,"⋷"],[1,{v:"⋹",n:824,o:"⋹̸"}],[0,"⋺"],[0,"⋻"],[0,"⋼"],[0,"⋽"],[0,"⋾"],[6,"⌅"],[0,"⌆"],[1,"⌈"],[0,"⌉"],[0,"⌊"],[0,"⌋"],[0,"⌌"],[0,"⌍"],[0,"⌎"],[0,"⌏"],[0,"⌐"],[1,"⌒"],[0,"⌓"],[1,"⌕"],[0,"⌖"],[5,"⌜"],[0,"⌝"],[0,"⌞"],[0,"⌟"],[2,"⌢"],[0,"⌣"],[9,"⌭"],[0,"⌮"],[7,"⌶"],[6,"⌽"],[1,"⌿"],[60,"⍼"],[51,"⎰"],[0,"⎱"],[2,"⎴"],[0,"⎵"],[0,"⎶"],[37,"⏜"],[0,"⏝"],[0,"⏞"],[0,"⏟"],[2,"⏢"],[4,"⏧"],[59,"␣"],[164,"Ⓢ"],[55,"─"],[1,"│"],[9,"┌"],[3,"┐"],[3,"└"],[3,"┘"],[3,"├"],[7,"┤"],[7,"┬"],[7,"┴"],[7,"┼"],[19,"═"],[0,"║"],[0,"╒"],[0,"╓"],[0,"╔"],[0,"╕"],[0,"╖"],[0,"╗"],[0,"╘"],[0,"╙"],[0,"╚"],[0,"╛"],[0,"╜"],[0,"╝"],[0,"╞"],[0,"╟"],[0,"╠"],[0,"╡"],[0,"╢"],[0,"╣"],[0,"╤"],[0,"╥"],[0,"╦"],[0,"╧"],[0,"╨"],[0,"╩"],[0,"╪"],[0,"╫"],[0,"╬"],[19,"▀"],[3,"▄"],[3,"█"],[8,"░"],[0,"▒"],[0,"▓"],[13,"□"],[8,"▪"],[0,"▫"],[1,"▭"],[0,"▮"],[2,"▱"],[1,"△"],[0,"▴"],[0,"▵"],[2,"▸"],[0,"▹"],[3,"▽"],[0,"▾"],[0,"▿"],[2,"◂"],[0,"◃"],[6,"◊"],[0,"○"],[32,"◬"],[2,"◯"],[8,"◸"],[0,"◹"],[0,"◺"],[0,"◻"],[0,"◼"],[8,"★"],[0,"☆"],[7,"☎"],[49,"♀"],[1,"♂"],[29,"♠"],[2,"♣"],[1,"♥"],[0,"♦"],[3,"♪"],[2,"♭"],[0,"♮"],[0,"♯"],[163,"✓"],[3,"✗"],[8,"✠"],[21,"✶"],[33,"❘"],[25,"❲"],[0,"❳"],[84,"⟈"],[0,"⟉"],[28,"⟦"],[0,"⟧"],[0,"⟨"],[0,"⟩"],[0,"⟪"],[0,"⟫"],[0,"⟬"],[0,"⟭"],[7,"⟵"],[0,"⟶"],[0,"⟷"],[0,"⟸"],[0,"⟹"],[0,"⟺"],[1,"⟼"],[2,"⟿"],[258,"⤂"],[0,"⤃"],[0,"⤄"],[0,"⤅"],[6,"⤌"],[0,"⤍"],[0,"⤎"],[0,"⤏"],[0,"⤐"],[0,"⤑"],[0,"⤒"],[0,"⤓"],[2,"⤖"],[2,"⤙"],[0,"⤚"],[0,"⤛"],[0,"⤜"],[0,"⤝"],[0,"⤞"],[0,"⤟"],[0,"⤠"],[2,"⤣"],[0,"⤤"],[0,"⤥"],[0,"⤦"],[0,"⤧"],[0,"⤨"],[0,"⤩"],[0,"⤪"],[8,{v:"⤳",n:824,o:"⤳̸"}],[1,"⤵"],[0,"⤶"],[0,"⤷"],[0,"⤸"],[0,"⤹"],[2,"⤼"],[0,"⤽"],[7,"⥅"],[2,"⥈"],[0,"⥉"],[0,"⥊"],[0,"⥋"],[2,"⥎"],[0,"⥏"],[0,"⥐"],[0,"⥑"],[0,"⥒"],[0,"⥓"],[0,"⥔"],[0,"⥕"],[0,"⥖"],[0,"⥗"],[0,"⥘"],[0,"⥙"],[0,"⥚"],[0,"⥛"],[0,"⥜"],[0,"⥝"],[0,"⥞"],[0,"⥟"],[0,"⥠"],[0,"⥡"],[0,"⥢"],[0,"⥣"],[0,"⥤"],[0,"⥥"],[0,"⥦"],[0,"⥧"],[0,"⥨"],[0,"⥩"],[0,"⥪"],[0,"⥫"],[0,"⥬"],[0,"⥭"],[0,"⥮"],[0,"⥯"],[0,"⥰"],[0,"⥱"],[0,"⥲"],[0,"⥳"],[0,"⥴"],[0,"⥵"],[0,"⥶"],[1,"⥸"],[0,"⥹"],[1,"⥻"],[0,"⥼"],[0,"⥽"],[0,"⥾"],[0,"⥿"],[5,"⦅"],[0,"⦆"],[4,"⦋"],[0,"⦌"],[0,"⦍"],[0,"⦎"],[0,"⦏"],[0,"⦐"],[0,"⦑"],[0,"⦒"],[0,"⦓"],[0,"⦔"],[0,"⦕"],[0,"⦖"],[3,"⦚"],[1,"⦜"],[0,"⦝"],[6,"⦤"],[0,"⦥"],[0,"⦦"],[0,"⦧"],[0,"⦨"],[0,"⦩"],[0,"⦪"],[0,"⦫"],[0,"⦬"],[0,"⦭"],[0,"⦮"],[0,"⦯"],[0,"⦰"],[0,"⦱"],[0,"⦲"],[0,"⦳"],[0,"⦴"],[0,"⦵"],[0,"⦶"],[0,"⦷"],[1,"⦹"],[1,"⦻"],[0,"⦼"],[1,"⦾"],[0,"⦿"],[0,"⧀"],[0,"⧁"],[0,"⧂"],[0,"⧃"],[0,"⧄"],[0,"⧅"],[3,"⧉"],[3,"⧍"],[0,"⧎"],[0,{v:"⧏",n:824,o:"⧏̸"}],[0,{v:"⧐",n:824,o:"⧐̸"}],[11,"⧜"],[0,"⧝"],[0,"⧞"],[4,"⧣"],[0,"⧤"],[0,"⧥"],[5,"⧫"],[8,"⧴"],[1,"⧶"],[9,"⨀"],[0,"⨁"],[0,"⨂"],[1,"⨄"],[1,"⨆"],[5,"⨌"],[0,"⨍"],[2,"⨐"],[0,"⨑"],[0,"⨒"],[0,"⨓"],[0,"⨔"],[0,"⨕"],[0,"⨖"],[0,"⨗"],[10,"⨢"],[0,"⨣"],[0,"⨤"],[0,"⨥"],[0,"⨦"],[0,"⨧"],[1,"⨩"],[0,"⨪"],[2,"⨭"],[0,"⨮"],[0,"⨯"],[0,"⨰"],[0,"⨱"],[1,"⨳"],[0,"⨴"],[0,"⨵"],[0,"⨶"],[0,"⨷"],[0,"⨸"],[0,"⨹"],[0,"⨺"],[0,"⨻"],[0,"⨼"],[2,"⨿"],[0,"⩀"],[1,"⩂"],[0,"⩃"],[0,"⩄"],[0,"⩅"],[0,"⩆"],[0,"⩇"],[0,"⩈"],[0,"⩉"],[0,"⩊"],[0,"⩋"],[0,"⩌"],[0,"⩍"],[2,"⩐"],[2,"⩓"],[0,"⩔"],[0,"⩕"],[0,"⩖"],[0,"⩗"],[0,"⩘"],[1,"⩚"],[0,"⩛"],[0,"⩜"],[0,"⩝"],[1,"⩟"],[6,"⩦"],[3,"⩪"],[2,{v:"⩭",n:824,o:"⩭̸"}],[0,"⩮"],[0,"⩯"],[0,{v:"⩰",n:824,o:"⩰̸"}],[0,"⩱"],[0,"⩲"],[0,"⩳"],[0,"⩴"],[0,"⩵"],[1,"⩷"],[0,"⩸"],[0,"⩹"],[0,"⩺"],[0,"⩻"],[0,"⩼"],[0,{v:"⩽",n:824,o:"⩽̸"}],[0,{v:"⩾",n:824,o:"⩾̸"}],[0,"⩿"],[0,"⪀"],[0,"⪁"],[0,"⪂"],[0,"⪃"],[0,"⪄"],[0,"⪅"],[0,"⪆"],[0,"⪇"],[0,"⪈"],[0,"⪉"],[0,"⪊"],[0,"⪋"],[0,"⪌"],[0,"⪍"],[0,"⪎"],[0,"⪏"],[0,"⪐"],[0,"⪑"],[0,"⪒"],[0,"⪓"],[0,"⪔"],[0,"⪕"],[0,"⪖"],[0,"⪗"],[0,"⪘"],[0,"⪙"],[0,"⪚"],[2,"⪝"],[0,"⪞"],[0,"⪟"],[0,"⪠"],[0,{v:"⪡",n:824,o:"⪡̸"}],[0,{v:"⪢",n:824,o:"⪢̸"}],[1,"⪤"],[0,"⪥"],[0,"⪦"],[0,"⪧"],[0,"⪨"],[0,"⪩"],[0,"⪪"],[0,"⪫"],[0,{v:"⪬",n:65024,o:"⪬︀"}],[0,{v:"⪭",n:65024,o:"⪭︀"}],[0,"⪮"],[0,{v:"⪯",n:824,o:"⪯̸"}],[0,{v:"⪰",n:824,o:"⪰̸"}],[2,"⪳"],[0,"⪴"],[0,"⪵"],[0,"⪶"],[0,"⪷"],[0,"⪸"],[0,"⪹"],[0,"⪺"],[0,"⪻"],[0,"⪼"],[0,"⪽"],[0,"⪾"],[0,"⪿"],[0,"⫀"],[0,"⫁"],[0,"⫂"],[0,"⫃"],[0,"⫄"],[0,{v:"⫅",n:824,o:"⫅̸"}],[0,{v:"⫆",n:824,o:"⫆̸"}],[0,"⫇"],[0,"⫈"],[2,{v:"⫋",n:65024,o:"⫋︀"}],[0,{v:"⫌",n:65024,o:"⫌︀"}],[2,"⫏"],[0,"⫐"],[0,"⫑"],[0,"⫒"],[0,"⫓"],[0,"⫔"],[0,"⫕"],[0,"⫖"],[0,"⫗"],[0,"⫘"],[0,"⫙"],[0,"⫚"],[0,"⫛"],[8,"⫤"],[1,"⫦"],[0,"⫧"],[0,"⫨"],[0,"⫩"],[1,"⫫"],[0,"⫬"],[0,"⫭"],[0,"⫮"],[0,"⫯"],[0,"⫰"],[0,"⫱"],[0,"⫲"],[0,"⫳"],[9,{v:"⫽",n:8421,o:"⫽⃥"}],[44343,{n:new Map(/* #__PURE__ */restoreDiff([[56476,"𝒜"],[1,"𝒞"],[0,"𝒟"],[2,"𝒢"],[2,"𝒥"],[0,"𝒦"],[2,"𝒩"],[0,"𝒪"],[0,"𝒫"],[0,"𝒬"],[1,"𝒮"],[0,"𝒯"],[0,"𝒰"],[0,"𝒱"],[0,"𝒲"],[0,"𝒳"],[0,"𝒴"],[0,"𝒵"],[0,"𝒶"],[0,"𝒷"],[0,"𝒸"],[0,"𝒹"],[1,"𝒻"],[1,"𝒽"],[0,"𝒾"],[0,"𝒿"],[0,"𝓀"],[0,"𝓁"],[0,"𝓂"],[0,"𝓃"],[1,"𝓅"],[0,"𝓆"],[0,"𝓇"],[0,"𝓈"],[0,"𝓉"],[0,"𝓊"],[0,"𝓋"],[0,"𝓌"],[0,"𝓍"],[0,"𝓎"],[0,"𝓏"],[52,"𝔄"],[0,"𝔅"],[1,"𝔇"],[0,"𝔈"],[0,"𝔉"],[0,"𝔊"],[2,"𝔍"],[0,"𝔎"],[0,"𝔏"],[0,"𝔐"],[0,"𝔑"],[0,"𝔒"],[0,"𝔓"],[0,"𝔔"],[1,"𝔖"],[0,"𝔗"],[0,"𝔘"],[0,"𝔙"],[0,"𝔚"],[0,"𝔛"],[0,"𝔜"],[1,"𝔞"],[0,"𝔟"],[0,"𝔠"],[0,"𝔡"],[0,"𝔢"],[0,"𝔣"],[0,"𝔤"],[0,"𝔥"],[0,"𝔦"],[0,"𝔧"],[0,"𝔨"],[0,"𝔩"],[0,"𝔪"],[0,"𝔫"],[0,"𝔬"],[0,"𝔭"],[0,"𝔮"],[0,"𝔯"],[0,"𝔰"],[0,"𝔱"],[0,"𝔲"],[0,"𝔳"],[0,"𝔴"],[0,"𝔵"],[0,"𝔶"],[0,"𝔷"],[0,"𝔸"],[0,"𝔹"],[1,"𝔻"],[0,"𝔼"],[0,"𝔽"],[0,"𝔾"],[1,"𝕀"],[0,"𝕁"],[0,"𝕂"],[0,"𝕃"],[0,"𝕄"],[1,"𝕆"],[3,"𝕊"],[0,"𝕋"],[0,"𝕌"],[0,"𝕍"],[0,"𝕎"],[0,"𝕏"],[0,"𝕐"],[1,"𝕒"],[0,"𝕓"],[0,"𝕔"],[0,"𝕕"],[0,"𝕖"],[0,"𝕗"],[0,"𝕘"],[0,"𝕙"],[0,"𝕚"],[0,"𝕛"],[0,"𝕜"],[0,"𝕝"],[0,"𝕞"],[0,"𝕟"],[0,"𝕠"],[0,"𝕡"],[0,"𝕢"],[0,"𝕣"],[0,"𝕤"],[0,"𝕥"],[0,"𝕦"],[0,"𝕧"],[0,"𝕨"],[0,"𝕩"],[0,"𝕪"],[0,"𝕫"]]))}],[8906,"ff"],[0,"fi"],[0,"fl"],[0,"ffi"],[0,"ffl"]])); diff --git a/packages/webui/third_party/editor/entities/src/index.ts b/packages/webui/third_party/editor/entities/src/index.ts new file mode 100644 index 000000000..c9ff92da9 --- /dev/null +++ b/packages/webui/third_party/editor/entities/src/index.ts @@ -0,0 +1,178 @@ +import { decodeXML, decodeHTML, DecodingMode } from "./decode.js"; +import { encodeHTML, encodeNonAsciiHTML } from "./encode.js"; +import { + encodeXML, + escapeUTF8, + escapeAttribute, + escapeText, +} from "./escape.js"; + +/** The level of entities to support. */ +export enum EntityLevel { + /** Support only XML entities. */ + XML = 0, + /** Support HTML entities, which are a superset of XML entities. */ + HTML = 1, +} + +export enum EncodingMode { + /** + * The output is UTF-8 encoded. Only characters that need escaping within + * XML will be escaped. + */ + UTF8, + /** + * The output consists only of ASCII characters. Characters that need + * escaping within HTML, and characters that aren't ASCII characters will + * be escaped. + */ + ASCII, + /** + * Encode all characters that have an equivalent entity, as well as all + * characters that are not ASCII characters. + */ + Extensive, + /** + * Encode all characters that have to be escaped in HTML attributes, + * following {@link https://html.spec.whatwg.org/multipage/parsing.html#escapingString}. + */ + Attribute, + /** + * Encode all characters that have to be escaped in HTML text, + * following {@link https://html.spec.whatwg.org/multipage/parsing.html#escapingString}. + */ + Text, +} + +export interface DecodingOptions { + /** + * The level of entities to support. + * @default {@link EntityLevel.XML} + */ + level?: EntityLevel; + /** + * Decoding mode. If `Legacy`, will support legacy entities not terminated + * with a semicolon (`;`). + * + * Always `Strict` for XML. For HTML, set this to `true` if you are parsing + * an attribute value. + * + * The deprecated `decodeStrict` function defaults this to `Strict`. + * + * @default {@link DecodingMode.Legacy} + */ + mode?: DecodingMode | undefined; +} + +/** + * Decodes a string with entities. + * + * @param data String to decode. + * @param options Decoding options. + */ +export function decode( + data: string, + options: DecodingOptions | EntityLevel = EntityLevel.XML +): string { + const level = typeof options === "number" ? options : options.level; + + if (level === EntityLevel.HTML) { + const mode = typeof options === "object" ? options.mode : undefined; + return decodeHTML(data, mode); + } + + return decodeXML(data); +} + +/** + * Decodes a string with entities. Does not allow missing trailing semicolons for entities. + * + * @param data String to decode. + * @param options Decoding options. + * @deprecated Use `decode` with the `mode` set to `Strict`. + */ +export function decodeStrict( + data: string, + options: DecodingOptions | EntityLevel = EntityLevel.XML +): string { + const opts = typeof options === "number" ? { level: options } : options; + opts.mode ??= DecodingMode.Strict; + + return decode(data, opts); +} + +/** + * Options for `encode`. + */ +export interface EncodingOptions { + /** + * The level of entities to support. + * @default {@link EntityLevel.XML} + */ + level?: EntityLevel; + /** + * Output format. + * @default {@link EncodingMode.Extensive} + */ + mode?: EncodingMode; +} + +/** + * Encodes a string with entities. + * + * @param data String to encode. + * @param options Encoding options. + */ +export function encode( + data: string, + options: EncodingOptions | EntityLevel = EntityLevel.XML +): string { + const opts = typeof options === "number" ? { level: options } : options; + + // Mode `UTF8` just escapes XML entities + if (opts.mode === EncodingMode.UTF8) return escapeUTF8(data); + if (opts.mode === EncodingMode.Attribute) return escapeAttribute(data); + if (opts.mode === EncodingMode.Text) return escapeText(data); + + if (opts.level === EntityLevel.HTML) { + if (opts.mode === EncodingMode.ASCII) { + return encodeNonAsciiHTML(data); + } + + return encodeHTML(data); + } + + // ASCII and Extensive are equivalent + return encodeXML(data); +} + +export { + encodeXML, + escape, + escapeUTF8, + escapeAttribute, + escapeText, +} from "./escape.js"; + +export { + encodeHTML, + encodeNonAsciiHTML, + // Legacy aliases (deprecated) + encodeHTML as encodeHTML4, + encodeHTML as encodeHTML5, +} from "./encode.js"; + +export { + EntityDecoder, + DecodingMode, + decodeXML, + decodeHTML, + decodeHTMLStrict, + decodeHTMLAttribute, + // Legacy aliases (deprecated) + decodeHTML as decodeHTML4, + decodeHTML as decodeHTML5, + decodeHTMLStrict as decodeHTML4Strict, + decodeHTMLStrict as decodeHTML5Strict, + decodeXML as decodeXMLStrict, +} from "./decode.js"; diff --git a/packages/webui/third_party/editor/linkify-it/LICENSE b/packages/webui/third_party/editor/linkify-it/LICENSE new file mode 100644 index 000000000..67596f5f2 --- /dev/null +++ b/packages/webui/third_party/editor/linkify-it/LICENSE @@ -0,0 +1,22 @@ +Copyright (c) 2015 Vitaly Puzrin. + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/packages/webui/third_party/editor/linkify-it/index.mjs b/packages/webui/third_party/editor/linkify-it/index.mjs new file mode 100644 index 000000000..1c4706b4e --- /dev/null +++ b/packages/webui/third_party/editor/linkify-it/index.mjs @@ -0,0 +1,646 @@ +import reFactory from './lib/re.mjs' + +// +// Helpers +// + +// Merge objects +// +function assign (obj /* from1, from2, from3, ... */) { + const sources = Array.prototype.slice.call(arguments, 1) + + sources.forEach(function (source) { + if (!source) { return } + + Object.keys(source).forEach(function (key) { + obj[key] = source[key] + }) + }) + + return obj +} + +function _class (obj) { return Object.prototype.toString.call(obj) } +function isString (obj) { return _class(obj) === '[object String]' } +function isObject (obj) { return _class(obj) === '[object Object]' } +function isRegExp (obj) { return _class(obj) === '[object RegExp]' } +function isFunction (obj) { return _class(obj) === '[object Function]' } + +function escapeRE (str) { return str.replace(/[.?*+^$[\]\\(){}|-]/g, '\\$&') } + +// + +const defaultOptions = { + fuzzyLink: true, + fuzzyEmail: true, + fuzzyIP: false +} + +function isOptionsObj (obj) { + return Object.keys(obj || {}).reduce(function (acc, k) { + /* eslint-disable-next-line no-prototype-builtins */ + return acc || defaultOptions.hasOwnProperty(k) + }, false) +} + +const defaultSchemas = { + 'http:': { + validate: function (text, pos, self) { + const tail = text.slice(pos) + + if (!self.re.http) { + // compile lazily, because "host"-containing variables can change on tlds update. + self.re.http = new RegExp( + `^\\/\\/${self.re.src_auth}${self.re.src_host_port_strict}${self.re.src_path}`, 'i' + ) + } + if (self.re.http.test(tail)) { + return tail.match(self.re.http)[0].length + } + return 0 + } + }, + 'https:': 'http:', + 'ftp:': 'http:', + '//': { + validate: function (text, pos, self) { + const tail = text.slice(pos) + + if (!self.re.no_http) { + // compile lazily, because "host"-containing variables can change on tlds update. + self.re.no_http = new RegExp( + '^' + + self.re.src_auth + + // Don't allow single-level domains, because of false positives like '//test' + // with code comments + `(?:localhost|(?:(?:${self.re.src_domain})\\.)+${self.re.src_domain_root})` + + self.re.src_port + + self.re.src_host_terminator + + self.re.src_path, + + 'i' + ) + } + + if (self.re.no_http.test(tail)) { + // should not be `://` & `///`, that protects from errors in protocol name + if (pos >= 3 && text[pos - 3] === ':') { return 0 } + if (pos >= 3 && text[pos - 3] === '/') { return 0 } + return tail.match(self.re.no_http)[0].length + } + return 0 + } + }, + 'mailto:': { + validate: function (text, pos, self) { + const tail = text.slice(pos) + + if (!self.re.mailto) { + self.re.mailto = new RegExp( + `^${self.re.src_email_name}@${self.re.src_host_strict}`, 'i' + ) + } + if (self.re.mailto.test(tail)) { + return tail.match(self.re.mailto)[0].length + } + return 0 + } + } +} + +// RE pattern for 2-character tlds (autogenerated by ./support/tlds_2char_gen.js) +const tlds_2ch_src_re = 'a[cdefgilmnoqrstuwxz]|b[abdefghijmnorstvwyz]|c[acdfghiklmnoruvwxyz]|d[ejkmoz]|e[cegrstu]|f[ijkmor]|g[abdefghilmnpqrstuwy]|h[kmnrtu]|i[delmnoqrst]|j[emop]|k[eghimnprwyz]|l[abcikrstuvy]|m[acdeghklmnopqrstuvwxyz]|n[acefgilopruz]|om|p[aefghklmnrstwy]|qa|r[eosuw]|s[abcdeghijklmnortuvxyz]|t[cdfghjklmnortvwz]|u[agksyz]|v[aceginu]|w[fs]|y[et]|z[amw]' + +// DON'T try to make PRs with changes. Extend TLDs with LinkifyIt.tlds() instead +const tlds_default = 'biz|com|edu|gov|net|org|pro|web|xxx|aero|asia|coop|info|museum|name|shop|рф'.split('|') + +function createValidator (re) { + return function (text, pos) { + const tail = text.slice(pos) + + if (re.test(tail)) { + return tail.match(re)[0].length + } + return 0 + } +} + +function createNormalizer () { + return function (match, self) { + self.normalize(match) + } +} + +// Schemas compiler. Build regexps. +// +function compile (self) { + // Load & clone RE patterns. + const re = self.re = reFactory(self.__opts__) + + // Define dynamic patterns + const tlds = self.__tlds__.slice() + + self.onCompile() + + if (!self.__tlds_replaced__) { + tlds.push(tlds_2ch_src_re) + } + tlds.push(re.src_xn) + + re.src_tlds = tlds.join('|') + + function untpl (tpl) { return tpl.replace('%TLDS%', re.src_tlds) } + + re.email_fuzzy = RegExp(untpl(re.tpl_email_fuzzy), 'i') + re.email_fuzzy_global = RegExp(untpl(re.tpl_email_fuzzy), 'ig') + re.link_fuzzy = RegExp(untpl(re.tpl_link_fuzzy), 'i') + re.link_fuzzy_global = RegExp(untpl(re.tpl_link_fuzzy), 'ig') + re.link_no_ip_fuzzy = RegExp(untpl(re.tpl_link_no_ip_fuzzy), 'i') + re.link_no_ip_fuzzy_global = RegExp(untpl(re.tpl_link_no_ip_fuzzy), 'ig') + re.host_fuzzy_test = RegExp(untpl(re.tpl_host_fuzzy_test), 'i') + + // + // Compile each schema + // + + const aliases = [] + + self.__compiled__ = {} // Reset compiled data + + function schemaError (name, val) { + throw new Error(`(LinkifyIt) Invalid schema "${name}": ${val}`) + } + + Object.keys(self.__schemas__).forEach(function (name) { + const val = self.__schemas__[name] + + // skip disabled methods + if (val === null) { return } + + const compiled = { validate: null, link: null } + + self.__compiled__[name] = compiled + + if (isObject(val)) { + if (isRegExp(val.validate)) { + compiled.validate = createValidator(val.validate) + } else if (isFunction(val.validate)) { + compiled.validate = val.validate + } else { + schemaError(name, val) + } + + if (isFunction(val.normalize)) { + compiled.normalize = val.normalize + } else if (!val.normalize) { + compiled.normalize = createNormalizer() + } else { + schemaError(name, val) + } + + return + } + + if (isString(val)) { + aliases.push(name) + return + } + + schemaError(name, val) + }) + + // + // Compile postponed aliases + // + + aliases.forEach(function (alias) { + if (!self.__compiled__[self.__schemas__[alias]]) { + // Silently fail on missed schemas to avoid errons on disable. + // schemaError(alias, self.__schemas__[alias]); + return + } + + self.__compiled__[alias].validate = + self.__compiled__[self.__schemas__[alias]].validate + self.__compiled__[alias].normalize = + self.__compiled__[self.__schemas__[alias]].normalize + }) + + // + // Fake record for guessed links + // + self.__compiled__[''] = { validate: null, normalize: createNormalizer() } + + // + // Build schema condition + // + const slist = Object.keys(self.__compiled__) + .filter(function (name) { + // Filter disabled & fake schemas + return name.length > 0 && self.__compiled__[name] + }) + .map(escapeRE) + .join('|') + // (?!_) cause 1.5x slowdown + self.re.schema_test = RegExp(`(^|(?!_)(?:[><\uff5c]|${re.src_ZPCc}))(${slist})`, 'i') + self.re.schema_search = RegExp(`(^|(?!_)(?:[><\uff5c]|${re.src_ZPCc}))(${slist})`, 'ig') + self.re.schema_at_start = RegExp(`^${self.re.schema_search.source}`, 'i') + + self.re.pretest = RegExp( + `(${self.re.schema_test.source})|(${self.re.host_fuzzy_test.source})|@`, + 'i' + ) +} + +/** + * class Match + * + * Match result. Single element of array, returned by [[LinkifyIt#match]] + **/ +function Match (text, schema, index, lastIndex) { + const raw = text.slice(index, lastIndex) + + /** + * Match#schema -> String + * + * Prefix (protocol) for matched string. + **/ + this.schema = schema.toLowerCase() + /** + * Match#index -> Number + * + * First position of matched string. + **/ + this.index = index + /** + * Match#lastIndex -> Number + * + * Next position after matched string. + **/ + this.lastIndex = lastIndex + /** + * Match#raw -> String + * + * Matched string. + **/ + this.raw = raw + /** + * Match#text -> String + * + * Notmalized text of matched string. + **/ + this.text = raw + /** + * Match#url -> String + * + * Normalized url of matched string. + **/ + this.url = raw +} + +/** + * class LinkifyIt + **/ + +/** + * new LinkifyIt(schemas, options) + * - schemas (Object): Optional. Additional schemas to validate (prefix/validator) + * - options (Object): { fuzzyLink|fuzzyEmail|fuzzyIP: true|false } + * + * Creates new linkifier instance with optional additional schemas. + * Can be called without `new` keyword for convenience. + * + * By default understands: + * + * - `http(s)://...` , `ftp://...`, `mailto:...` & `//...` links + * - "fuzzy" links and emails (example.com, foo@bar.com). + * + * `schemas` is an object, where each key/value describes protocol/rule: + * + * - __key__ - link prefix (usually, protocol name with `:` at the end, `skype:` + * for example). `linkify-it` makes shure that prefix is not preceeded with + * alphanumeric char and symbols. Only whitespaces and punctuation allowed. + * - __value__ - rule to check tail after link prefix + * - _String_ - just alias to existing rule + * - _Object_ + * - _validate_ - validator function (should return matched length on success), + * or `RegExp`. + * - _normalize_ - optional function to normalize text & url of matched result + * (for example, for @twitter mentions). + * + * `options`: + * + * - __fuzzyLink__ - recognige URL-s without `http(s):` prefix. Default `true`. + * - __fuzzyIP__ - allow IPs in fuzzy links above. Can conflict with some texts + * like version numbers. Default `false`. + * - __fuzzyEmail__ - recognize emails without `mailto:` prefix. + * + **/ +function LinkifyIt (schemas, options) { + if (!(this instanceof LinkifyIt)) { + return new LinkifyIt(schemas, options) + } + + if (!options) { + if (isOptionsObj(schemas)) { + options = schemas + schemas = {} + } + } + + this.__opts__ = assign({}, defaultOptions, options) + + this.__schemas__ = assign({}, defaultSchemas, schemas) + this.__compiled__ = {} + + this.__tlds__ = tlds_default + this.__tlds_replaced__ = false + + this.re = {} + + compile(this) +} + +/** chainable + * LinkifyIt#add(schema, definition) + * - schema (String): rule name (fixed pattern prefix) + * - definition (String|RegExp|Object): schema definition + * + * Add new rule definition. See constructor description for details. + **/ +LinkifyIt.prototype.add = function add (schema, definition) { + this.__schemas__[schema] = definition + compile(this) + return this +} + +/** chainable + * LinkifyIt#set(options) + * - options (Object): { fuzzyLink|fuzzyEmail|fuzzyIP: true|false } + * + * Set recognition options for links without schema. + **/ +LinkifyIt.prototype.set = function set (options) { + this.__opts__ = assign(this.__opts__, options) + return this +} + +/** + * LinkifyIt#test(text) -> Boolean + * + * Searches linkifiable pattern and returns `true` on success or `false` on fail. + **/ +LinkifyIt.prototype.test = function test (text) { + if (!text.length) { return false } + + let m, re + + // try to scan for link with schema - that's the most simple rule + if (this.re.schema_test.test(text)) { + re = this.re.schema_search + re.lastIndex = 0 + while ((m = re.exec(text)) !== null) { + if (this.testSchemaAt(text, m[2], re.lastIndex)) { return true } + } + } + + if (this.__opts__.fuzzyLink && this.__compiled__['http:']) { + // guess schemaless links + if (text.search(this.re.host_fuzzy_test) >= 0) { + if (text.match(this.__opts__.fuzzyIP ? this.re.link_fuzzy : this.re.link_no_ip_fuzzy) !== null) { + return true + } + } + } + + if (this.__opts__.fuzzyEmail && this.__compiled__['mailto:']) { + // guess schemaless emails + if (text.indexOf('@') >= 0) { + // We can't skip this check, because this cases are possible: + // 192.168.1.1@gmail.com, my.in@example.com + if (text.match(this.re.email_fuzzy) !== null) { return true } + } + } + + return false +} + +/** + * LinkifyIt#pretest(text) -> Boolean + * + * Very quick check, that can give false positives. Returns true if link MAY BE + * can exists. Can be used for speed optimization, when you need to check that + * link NOT exists. + **/ +LinkifyIt.prototype.pretest = function pretest (text) { + return this.re.pretest.test(text) +} + +/** + * LinkifyIt#testSchemaAt(text, name, position) -> Number + * - text (String): text to scan + * - name (String): rule (schema) name + * - position (Number): text offset to check from + * + * Similar to [[LinkifyIt#test]] but checks only specific protocol tail exactly + * at given position. Returns length of found pattern (0 on fail). + **/ +LinkifyIt.prototype.testSchemaAt = function testSchemaAt (text, schema, pos) { + // If not supported schema check requested - terminate + if (!this.__compiled__[schema.toLowerCase()]) { + return 0 + } + return this.__compiled__[schema.toLowerCase()].validate(text, pos, this) +} + +/** + * LinkifyIt#match(text) -> Array|null + * + * Returns array of found link descriptions or `null` on fail. We strongly + * recommend to use [[LinkifyIt#test]] first, for best speed. + * + * ##### Result match description + * + * - __schema__ - link schema, can be empty for fuzzy links, or `//` for + * protocol-neutral links. + * - __index__ - offset of matched text + * - __lastIndex__ - index of next char after mathch end + * - __raw__ - matched text + * - __text__ - normalized text + * - __url__ - link, generated from matched text + **/ +LinkifyIt.prototype.match = function match (text) { + const result = [] + const type_schemed = [] + const type_fuzzy_link = [] + const type_fuzzy_email = [] + let m, len, re + + function choose (a, b) { + if (!a) { return b } + if (!b) { return a } + if (a.index !== b.index) { return a.index < b.index ? a : b } + return a.lastIndex >= b.lastIndex ? a : b + } + + if (!text.length) { return null } + + // scan for links with schema + if (this.re.schema_test.test(text)) { + re = this.re.schema_search + re.lastIndex = 0 + while ((m = re.exec(text)) !== null) { + len = this.testSchemaAt(text, m[2], re.lastIndex) + if (len) { + type_schemed.push({ + schema: m[2], + index: m.index + m[1].length, + lastIndex: m.index + m[0].length + len + }) + } + } + } + + if (this.__opts__.fuzzyLink && this.__compiled__['http:']) { + re = this.__opts__.fuzzyIP ? this.re.link_fuzzy_global : this.re.link_no_ip_fuzzy_global + re.lastIndex = 0 + while ((m = re.exec(text)) !== null) { + type_fuzzy_link.push({ + schema: '', + index: m.index + m[1].length, + lastIndex: m.index + m[0].length + }) + } + } + + if (this.__opts__.fuzzyEmail && this.__compiled__['mailto:']) { + re = this.re.email_fuzzy_global + re.lastIndex = 0 + while ((m = re.exec(text)) !== null) { + type_fuzzy_email.push({ + schema: 'mailto:', + index: m.index + m[1].length, + lastIndex: m.index + m[0].length + }) + } + } + + const indexes = [0, 0, 0] + let lastIndex = 0 + + for (;;) { + const candidates = [ + type_schemed[indexes[0]], + type_fuzzy_email[indexes[1]], + type_fuzzy_link[indexes[2]] + ] + + const candidate = choose(choose(candidates[0], candidates[1]), candidates[2]) + + if (!candidate) { break } + + if (candidate === candidates[0]) { + indexes[0]++ + } else if (candidate === candidates[1]) { + indexes[1]++ + } else { + indexes[2]++ + } + + if (candidate.index < lastIndex) { continue } + + const match = new Match(text, candidate.schema, candidate.index, candidate.lastIndex) + this.__compiled__[match.schema].normalize(match, this) + result.push(match) + lastIndex = candidate.lastIndex + } + + if (result.length) { + return result + } + + return null +} + +/** + * LinkifyIt#matchAtStart(text) -> Match|null + * + * Returns fully-formed (not fuzzy) link if it starts at the beginning + * of the string, and null otherwise. + **/ +LinkifyIt.prototype.matchAtStart = function matchAtStart (text) { + if (!text.length) return null + + const m = this.re.schema_at_start.exec(text) + if (!m) return null + + const len = this.testSchemaAt(text, m[2], m[0].length) + if (!len) return null + + const match = new Match(text, m[2], m.index + m[1].length, m.index + m[0].length + len) + + this.__compiled__[match.schema].normalize(match, this) + return match +} + +/** chainable + * LinkifyIt#tlds(list [, keepOld]) -> this + * - list (Array): list of tlds + * - keepOld (Boolean): merge with current list if `true` (`false` by default) + * + * Load (or merge) new tlds list. Those are user for fuzzy links (without prefix) + * to avoid false positives. By default this algorythm used: + * + * - hostname with any 2-letter root zones are ok. + * - biz|com|edu|gov|net|org|pro|web|xxx|aero|asia|coop|info|museum|name|shop|рф + * are ok. + * - encoded (`xn--...`) root zones are ok. + * + * If list is replaced, then exact match for 2-chars root zones will be checked. + **/ +LinkifyIt.prototype.tlds = function tlds (list, keepOld) { + list = Array.isArray(list) ? list : [list] + + if (!keepOld) { + this.__tlds__ = list.slice() + this.__tlds_replaced__ = true + compile(this) + return this + } + + this.__tlds__ = this.__tlds__.concat(list) + .sort() + .filter(function (el, idx, arr) { + return el !== arr[idx - 1] + }) + .reverse() + + compile(this) + return this +} + +/** + * LinkifyIt#normalize(match) + * + * Default normalizer (if schema does not define it's own). + **/ +LinkifyIt.prototype.normalize = function normalize (match) { + // Do minimal possible changes by default. Need to collect feedback prior + // to move forward https://github.com/markdown-it/linkify-it/issues/1 + + if (!match.schema) { match.url = `http://${match.url}` } + + if (match.schema === 'mailto:' && !/^mailto:/i.test(match.url)) { + match.url = `mailto:${match.url}` + } +} + +/** + * LinkifyIt#onCompile() + * + * Override to modify basic RegExp-s. + **/ +LinkifyIt.prototype.onCompile = function onCompile () { +} + +export default LinkifyIt diff --git a/packages/webui/third_party/editor/linkify-it/lib/re.mjs b/packages/webui/third_party/editor/linkify-it/lib/re.mjs new file mode 100644 index 000000000..d9b98ce12 --- /dev/null +++ b/packages/webui/third_party/editor/linkify-it/lib/re.mjs @@ -0,0 +1,193 @@ +import { Any, Cc, Z, P } from 'uc.micro' + +export default function (opts) { + const re = {} + opts = opts || {} + + re.src_Any = Any.source + re.src_Cc = Cc.source + re.src_Z = Z.source + re.src_P = P.source + + // \p{\Z\P\Cc\CF} (white spaces + control + format + punctuation) + re.src_ZPCc = [re.src_Z, re.src_P, re.src_Cc].join('|') + + // \p{\Z\Cc} (white spaces + control) + re.src_ZCc = [re.src_Z, re.src_Cc].join('|') + + // Experimental. List of chars, completely prohibited in links + // because can separate it from other part of text + const text_separators = '[><\uff5c]' + + // All possible word characters (everything without punctuation, spaces & controls) + // Defined via punctuation & spaces to save space + // Should be something like \p{\L\N\S\M} (\w but without `_`) + re.src_pseudo_letter = `(?:(?!${text_separators}|${re.src_ZPCc})${re.src_Any})` + // The same as abothe but without [0-9] + // var src_pseudo_letter_non_d = '(?:(?![0-9]|' + src_ZPCc + ')' + src_Any + ')'; + + re.src_ip4 = + + '(?:(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)' + + // Prohibit any of "@/[]()" in user/pass to avoid wrong domain fetch. + // Length is capped to exclude possible rescans till the end and avoid O(n^2) + // DoS. No standard limit, just take something reasonable. + re.src_auth = `(?:(?:(?!${re.src_ZCc}|[@/\\[\\]()]).){1,50}@)?` + + re.src_port = + + '(?::(?:6(?:[0-4]\\d{3}|5(?:[0-4]\\d{2}|5(?:[0-2]\\d|3[0-5])))|[1-5]?\\d{1,4}))?' + + re.src_host_terminator = + + `(?=$|${text_separators}|${re.src_ZPCc})` + + `(?!${opts['---'] ? '-(?!--)|' : '-|'}_|:\\d|\\.-|\\.(?!$|${re.src_ZPCc}))` + + re.src_path = + + '(?:' + + '[/?#]' + + '(?:' + + `(?!${re.src_ZCc}|${text_separators}|[()[\\]{}.,"'?!\\-;]).|` + + `\\[(?:(?!${re.src_ZCc}|\\]).)*\\]|` + + `\\((?:(?!${re.src_ZCc}|[)]).)*\\)|` + + `\\{(?:(?!${re.src_ZCc}|[}]).)*\\}|` + + `\\"(?:(?!${re.src_ZCc}|["]).)+\\"|` + + `\\'(?:(?!${re.src_ZCc}|[']).)+\\'|` + + + // allow `I'm_king` if no pair found + `\\'(?=${re.src_pseudo_letter}|[-])|` + + + // google has many dots in "google search" links (#66, #81). + // github has ... in commit range links, + // Restrict to + // - english + // - percent-encoded + // - parts of file path + // - params separator + // until more examples found. + '\\.{2,}[a-zA-Z0-9%/&]|' + + + `\\.(?!${re.src_ZCc}|[.]|$)|` + + (opts['---'] + ? '\\-(?!--(?:[^-]|$))(?:-*)|' // `---` => long dash, terminate + : '\\-+|' + ) + + // allow `,,,` in paths + `,(?!${re.src_ZCc}|$)|` + + + // allow `;` if not followed by space-like char + `;(?!${re.src_ZCc}|$)|` + + + // allow `!!!` in paths, but not at the end + `\\!+(?!${re.src_ZCc}|[!]|$)|` + + + `\\?(?!${re.src_ZCc}|[?]|$)` + + ')+' + + '|\\/' + + ')?' + + // Allow anything in markdown spec, forbid quote (") at the first position + // because emails enclosed in quotes are far more common + // Max name length capped to 64 chars (RFC 5321). This also prevents O(n^2) + // rescans to the end on inputs like `mailto:mailto:...` + re.src_email_name = + + '[\\-;:&=\\+\\$,\\.a-zA-Z0-9_][\\-;:&=\\+\\$,\\"\\.a-zA-Z0-9_]{0,63}' + + re.src_xn = + + 'xn--[a-z0-9\\-]{1,59}' + + // More to read about domain names + // http://serverfault.com/questions/638260/ + + re.src_domain_root = + + // Allow letters & digits (http://test1) + '(?:' + + re.src_xn + + '|' + + `${re.src_pseudo_letter}{1,63}` + + ')' + + re.src_domain = + + '(?:' + + re.src_xn + + '|' + + `(?:${re.src_pseudo_letter})` + + '|' + + `(?:${re.src_pseudo_letter}(?:-|${re.src_pseudo_letter}){0,61}${re.src_pseudo_letter})` + + ')' + + re.src_host = + + '(?:' + + // Don't need IP check, because digits are already allowed in normal domain names + // src_ip4 + + // '|' + + `(?:(?:(?:${re.src_domain})\\.)*${re.src_domain})`/* _root */ + + ')' + + re.tpl_host_fuzzy = + + '(?:' + + re.src_ip4 + + '|' + + `(?:(?:(?:${re.src_domain})\\.)+(?:%TLDS%))` + + ')' + + re.tpl_host_no_ip_fuzzy = + + `(?:(?:(?:${re.src_domain})\\.)+(?:%TLDS%))` + + re.src_host_strict = + + re.src_host + re.src_host_terminator + + re.tpl_host_fuzzy_strict = + + re.tpl_host_fuzzy + re.src_host_terminator + + re.src_host_port_strict = + + re.src_host + re.src_port + re.src_host_terminator + + re.tpl_host_port_fuzzy_strict = + + re.tpl_host_fuzzy + re.src_port + re.src_host_terminator + + re.tpl_host_port_no_ip_fuzzy_strict = + + re.tpl_host_no_ip_fuzzy + re.src_port + re.src_host_terminator + + // + // Main rules + // + + // Rude test fuzzy links by host, for quick deny + re.tpl_host_fuzzy_test = + + `localhost|www\\.|\\.\\d{1,3}\\.|(?:\\.(?:%TLDS%)(?:${re.src_ZPCc}|>|$))` + + re.tpl_email_fuzzy = + + `(^|${text_separators}|"|\\(|${re.src_ZCc})` + + `(${re.src_email_name}@${re.tpl_host_fuzzy_strict})` + + re.tpl_link_fuzzy = + // Fuzzy link can't be prepended with .:/\- and non punctuation. + // but can start with > (markdown blockquote) + `(^|(?![.:/\\-_@])(?:[$+<=>^\`|\uff5c]|${re.src_ZPCc}))` + + `((?![$+<=>^\`|\uff5c])${re.tpl_host_port_fuzzy_strict}${re.src_path})` + + re.tpl_link_no_ip_fuzzy = + // Fuzzy link can't be prepended with .:/\- and non punctuation. + // but can start with > (markdown blockquote) + `(^|(?![.:/\\-_@])(?:[$+<=>^\`|\uff5c]|${re.src_ZPCc}))` + + `((?![$+<=>^\`|\uff5c])${re.tpl_host_port_no_ip_fuzzy_strict}${re.src_path})` + + return re +} diff --git a/packages/webui/third_party/editor/linkify-it/package.json b/packages/webui/third_party/editor/linkify-it/package.json new file mode 100644 index 000000000..3254731ac --- /dev/null +++ b/packages/webui/third_party/editor/linkify-it/package.json @@ -0,0 +1,63 @@ +{ + "name": "linkify-it", + "version": "5.0.2", + "description": "Links recognition library with FULL unicode support", + "keywords": [ + "linkify", + "linkifier", + "autolink", + "autolinker" + ], + "repository": "markdown-it/linkify-it", + "main": "build/index.cjs.js", + "module": "index.mjs", + "exports": { + ".": { + "require": "./build/index.cjs.js", + "import": "./index.mjs" + }, + "./*": { + "require": "./*", + "import": "./*" + } + }, + "files": [ + "index.mjs", + "lib/", + "build/" + ], + "license": "MIT", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/puzrin" + }, + { + "type": "github", + "url": "https://github.com/sponsors/markdown-it" + } + ], + "scripts": { + "lint": "eslint .", + "test": "npm run lint && npm run build && c8 --exclude build --exclude test -r text -r html -r lcov node --test", + "demo": "npm run lint && node support/build_demo.mjs", + "doc": "node support/build_doc.mjs", + "build": "rollup -c support/rollup.config.mjs", + "gh-pages": "npm run demo && npm run doc && gh-pages -d demo -f", + "prepack": "npm test && npm run build && npm run demo && npm run doc", + "postpublish": "npm run gh-pages" + }, + "dependencies": { + "uc.micro": "^2.0.0" + }, + "devDependencies": { + "@rollup/plugin-node-resolve": "^15.2.3", + "c8": "^11.0.0", + "eslint": "^9.39.3", + "gh-pages": "^6.1.0", + "mitata": "^1.0.34", + "neostandard": "^0.13.0", + "ndoc": "^6.0.0", + "rollup": "^4.6.1" + } +} diff --git a/packages/webui/third_party/editor/markdown-it/LICENSE b/packages/webui/third_party/editor/markdown-it/LICENSE new file mode 100644 index 000000000..7ffa058cb --- /dev/null +++ b/packages/webui/third_party/editor/markdown-it/LICENSE @@ -0,0 +1,22 @@ +Copyright (c) 2014 Vitaly Puzrin, Alex Kocharin. + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/packages/webui/third_party/editor/markdown-it/index.mjs b/packages/webui/third_party/editor/markdown-it/index.mjs new file mode 100644 index 000000000..f7ba45f9f --- /dev/null +++ b/packages/webui/third_party/editor/markdown-it/index.mjs @@ -0,0 +1 @@ +export { default } from './lib/index.mjs' diff --git a/packages/webui/third_party/editor/markdown-it/lib/common/html_blocks.mjs b/packages/webui/third_party/editor/markdown-it/lib/common/html_blocks.mjs new file mode 100644 index 000000000..1e27a7f60 --- /dev/null +++ b/packages/webui/third_party/editor/markdown-it/lib/common/html_blocks.mjs @@ -0,0 +1,67 @@ +// List of valid html blocks names, according to commonmark spec +// https://spec.commonmark.org/0.30/#html-blocks + +export default [ + 'address', + 'article', + 'aside', + 'base', + 'basefont', + 'blockquote', + 'body', + 'caption', + 'center', + 'col', + 'colgroup', + 'dd', + 'details', + 'dialog', + 'dir', + 'div', + 'dl', + 'dt', + 'fieldset', + 'figcaption', + 'figure', + 'footer', + 'form', + 'frame', + 'frameset', + 'h1', + 'h2', + 'h3', + 'h4', + 'h5', + 'h6', + 'head', + 'header', + 'hr', + 'html', + 'iframe', + 'legend', + 'li', + 'link', + 'main', + 'menu', + 'menuitem', + 'nav', + 'noframes', + 'ol', + 'optgroup', + 'option', + 'p', + 'param', + 'search', + 'section', + 'summary', + 'table', + 'tbody', + 'td', + 'tfoot', + 'th', + 'thead', + 'title', + 'tr', + 'track', + 'ul' +] diff --git a/packages/webui/third_party/editor/markdown-it/lib/common/html_re.mjs b/packages/webui/third_party/editor/markdown-it/lib/common/html_re.mjs new file mode 100644 index 000000000..90071d8e4 --- /dev/null +++ b/packages/webui/third_party/editor/markdown-it/lib/common/html_re.mjs @@ -0,0 +1,25 @@ +// Regexps to match html elements + +const attr_name = '[a-zA-Z_:][a-zA-Z0-9:._-]*' + +const unquoted = '[^"\'=<>`\\x00-\\x20]+' +const single_quoted = "'[^']*'" +const double_quoted = '"[^"]*"' + +const attr_value = '(?:' + unquoted + '|' + single_quoted + '|' + double_quoted + ')' + +const attribute = '(?:\\s+' + attr_name + '(?:\\s*=\\s*' + attr_value + ')?)' + +const open_tag = '<[A-Za-z][A-Za-z0-9\\-]*' + attribute + '*\\s*\\/?>' + +const close_tag = '<\\/[A-Za-z][A-Za-z0-9\\-]*\\s*>' +const comment = '' +const processing = '<[?][\\s\\S]*?[?]>' +const declaration = ']*>' +const cdata = '' + +const HTML_TAG_RE = new RegExp('^(?:' + open_tag + '|' + close_tag + '|' + comment + + '|' + processing + '|' + declaration + '|' + cdata + ')') +const HTML_OPEN_CLOSE_TAG_RE = new RegExp('^(?:' + open_tag + '|' + close_tag + ')') + +export { HTML_TAG_RE, HTML_OPEN_CLOSE_TAG_RE } diff --git a/packages/webui/third_party/editor/markdown-it/lib/common/utils.mjs b/packages/webui/third_party/editor/markdown-it/lib/common/utils.mjs new file mode 100644 index 000000000..773ae8de7 --- /dev/null +++ b/packages/webui/third_party/editor/markdown-it/lib/common/utils.mjs @@ -0,0 +1,324 @@ +// Utilities +// + +import * as mdurl from 'mdurl' +import * as ucmicro from 'uc.micro' +import { decodeHTML } from 'entities' + +function _class (obj) { return Object.prototype.toString.call(obj) } + +function isString (obj) { return _class(obj) === '[object String]' } + +const _hasOwnProperty = Object.prototype.hasOwnProperty + +function has (object, key) { + return _hasOwnProperty.call(object, key) +} + +// Merge objects +// +function assign (obj /* from1, from2, from3, ... */) { + const sources = Array.prototype.slice.call(arguments, 1) + + sources.forEach(function (source) { + if (!source) { return } + + if (typeof source !== 'object') { + throw new TypeError(source + 'must be object') + } + + Object.keys(source).forEach(function (key) { + obj[key] = source[key] + }) + }) + + return obj +} + +// Remove element from array and put another array at those position. +// Useful for some operations with tokens +function arrayReplaceAt (src, pos, newElements) { + return [].concat(src.slice(0, pos), newElements, src.slice(pos + 1)) +} + +function isValidEntityCode (c) { + // broken sequence + if (c >= 0xD800 && c <= 0xDFFF) { return false } + // never used + if (c >= 0xFDD0 && c <= 0xFDEF) { return false } + if ((c & 0xFFFF) === 0xFFFF || (c & 0xFFFF) === 0xFFFE) { return false } + // control codes + if (c >= 0x00 && c <= 0x08) { return false } + if (c === 0x0B) { return false } + if (c >= 0x0E && c <= 0x1F) { return false } + if (c >= 0x7F && c <= 0x9F) { return false } + // out of range + if (c > 0x10FFFF) { return false } + return true +} + +function fromCodePoint (c) { + /* eslint no-bitwise:0 */ + if (c > 0xffff) { + c -= 0x10000 + const surrogate1 = 0xd800 + (c >> 10) + const surrogate2 = 0xdc00 + (c & 0x3ff) + + return String.fromCharCode(surrogate1, surrogate2) + } + return String.fromCharCode(c) +} + +const UNESCAPE_MD_RE = /\\([!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~])/g +const ENTITY_RE = /&([a-z#][a-z0-9]{1,31});/gi +const UNESCAPE_ALL_RE = new RegExp(UNESCAPE_MD_RE.source + '|' + ENTITY_RE.source, 'gi') + +const DIGITAL_ENTITY_TEST_RE = /^#((?:x[a-f0-9]{1,8}|[0-9]{1,8}))$/i + +function replaceEntityPattern (match, name) { + if (name.charCodeAt(0) === 0x23/* # */ && DIGITAL_ENTITY_TEST_RE.test(name)) { + const code = name[1].toLowerCase() === 'x' + ? parseInt(name.slice(2), 16) + : parseInt(name.slice(1), 10) + + if (isValidEntityCode(code)) { + return fromCodePoint(code) + } + + return match + } + + const decoded = decodeHTML(match) + if (decoded !== match) { + return decoded + } + + return match +} + +function unescapeMd (str) { + if (str.indexOf('\\') < 0) { return str } + return str.replace(UNESCAPE_MD_RE, '$1') +} + +function unescapeAll (str) { + if (str.indexOf('\\') < 0 && str.indexOf('&') < 0) { return str } + + return str.replace(UNESCAPE_ALL_RE, function (match, escaped, entity) { + if (escaped) { return escaped } + return replaceEntityPattern(match, entity) + }) +} + +const HTML_ESCAPE_TEST_RE = /[&<>"]/ +const HTML_ESCAPE_REPLACE_RE = /[&<>"]/g +const HTML_REPLACEMENTS = { + '&': '&', + '<': '<', + '>': '>', + '"': '"' +} + +function replaceUnsafeChar (ch) { + return HTML_REPLACEMENTS[ch] +} + +function escapeHtml (str) { + if (HTML_ESCAPE_TEST_RE.test(str)) { + return str.replace(HTML_ESCAPE_REPLACE_RE, replaceUnsafeChar) + } + return str +} + +const REGEXP_ESCAPE_RE = /[.?*+^$[\]\\(){}|-]/g + +function escapeRE (str) { + return str.replace(REGEXP_ESCAPE_RE, '\\$&') +} + +function isSpace (code) { + switch (code) { + case 0x09: + case 0x20: + return true + } + return false +} + +// Zs (unicode class) || [\t\f\v\r\n] +function isWhiteSpace (code) { + if (code >= 0x2000 && code <= 0x200A) { return true } + switch (code) { + case 0x09: // \t + case 0x0A: // \n + case 0x0B: // \v + case 0x0C: // \f + case 0x0D: // \r + case 0x20: + case 0xA0: + case 0x1680: + case 0x202F: + case 0x205F: + case 0x3000: + return true + } + return false +} + +// Currently without astral characters support. +function isPunctChar (ch) { + return ucmicro.P.test(ch) || ucmicro.S.test(ch) +} + +function isPunctCharCode (code) { + return isPunctChar(fromCodePoint(code)) +} + +// Markdown ASCII punctuation characters. +// +// !, ", #, $, %, &, ', (, ), *, +, ,, -, ., /, :, ;, <, =, >, ?, @, [, \, ], ^, _, `, {, |, }, or ~ +// http://spec.commonmark.org/0.15/#ascii-punctuation-character +// +// Don't confuse with unicode punctuation !!! It lacks some chars in ascii range. +// +function isMdAsciiPunct (ch) { + switch (ch) { + case 0x21/* ! */: + case 0x22/* " */: + case 0x23/* # */: + case 0x24/* $ */: + case 0x25/* % */: + case 0x26/* & */: + case 0x27/* ' */: + case 0x28/* ( */: + case 0x29/* ) */: + case 0x2A/* * */: + case 0x2B/* + */: + case 0x2C/* , */: + case 0x2D/* - */: + case 0x2E/* . */: + case 0x2F/* / */: + case 0x3A/* : */: + case 0x3B/* ; */: + case 0x3C/* < */: + case 0x3D/* = */: + case 0x3E/* > */: + case 0x3F/* ? */: + case 0x40/* @ */: + case 0x5B/* [ */: + case 0x5C/* \ */: + case 0x5D/* ] */: + case 0x5E/* ^ */: + case 0x5F/* _ */: + case 0x60/* ` */: + case 0x7B/* { */: + case 0x7C/* | */: + case 0x7D/* } */: + case 0x7E/* ~ */: + return true + default: + return false + } +} + +// Hepler to unify [reference labels]. +// +function normalizeReference (str) { + // Trim and collapse whitespace + // + str = str.trim().replace(/\s+/g, ' ') + + // In node v10 'ẞ'.toLowerCase() === 'Ṿ', which is presumed to be a bug + // fixed in v12 (couldn't find any details). + // + // So treat this one as a special case + // (remove this when node v10 is no longer supported). + // + if ('ẞ'.toLowerCase() === 'Ṿ') { + /* c8 ignore next 2 */ + str = str.replace(/ẞ/g, 'ß') + } + + // .toLowerCase().toUpperCase() should get rid of all differences + // between letter variants. + // + // Simple .toLowerCase() doesn't normalize 125 code points correctly, + // and .toUpperCase doesn't normalize 6 of them (list of exceptions: + // İ, ϴ, ẞ, Ω, K, Å - those are already uppercased, but have differently + // uppercased versions). + // + // Here's an example showing how it happens. Lets take greek letter omega: + // uppercase U+0398 (Θ), U+03f4 (ϴ) and lowercase U+03b8 (θ), U+03d1 (ϑ) + // + // Unicode entries: + // 0398;GREEK CAPITAL LETTER THETA;Lu;0;L;;;;;N;;;;03B8; + // 03B8;GREEK SMALL LETTER THETA;Ll;0;L;;;;;N;;;0398;;0398 + // 03D1;GREEK THETA SYMBOL;Ll;0;L; 03B8;;;;N;GREEK SMALL LETTER SCRIPT THETA;;0398;;0398 + // 03F4;GREEK CAPITAL THETA SYMBOL;Lu;0;L; 0398;;;;N;;;;03B8; + // + // Case-insensitive comparison should treat all of them as equivalent. + // + // But .toLowerCase() doesn't change ϑ (it's already lowercase), + // and .toUpperCase() doesn't change ϴ (already uppercase). + // + // Applying first lower then upper case normalizes any character: + // '\u0398\u03f4\u03b8\u03d1'.toLowerCase().toUpperCase() === '\u0398\u0398\u0398\u0398' + // + // Note: this is equivalent to unicode case folding; unicode normalization + // is a different step that is not required here. + // + // Final result should be uppercased, because it's later stored in an object + // (this avoid a conflict with Object.prototype members, + // most notably, `__proto__`) + // + return str.toLowerCase().toUpperCase() +} + +function isAsciiTrimmable (c) { + return c === 0x20 || c === 0x09 || c === 0x0a || c === 0x0d +} + +// "Light" .trim() for blocks (headers, paragraphs), where unicode spaces +// should be preserved. +function asciiTrim (str) { + let start = 0 + for (; start < str.length; start++) { + if (!isAsciiTrimmable(str.charCodeAt(start))) { + break + } + } + let end = str.length - 1 + for (; end >= start; end--) { + if (!isAsciiTrimmable(str.charCodeAt(end))) { + break + } + } + return str.slice(start, end + 1) +} + +// Re-export libraries commonly used in both markdown-it and its plugins, +// so plugins won't have to depend on them explicitly, which reduces their +// bundled size (e.g. a browser build). +// +const lib = { mdurl, ucmicro } + +export { + lib, + assign, + isString, + has, + unescapeMd, + unescapeAll, + isValidEntityCode, + fromCodePoint, + escapeHtml, + arrayReplaceAt, + isSpace, + isWhiteSpace, + isMdAsciiPunct, + isPunctChar, + isPunctCharCode, + escapeRE, + normalizeReference, + asciiTrim +} diff --git a/packages/webui/third_party/editor/markdown-it/lib/helpers/index.mjs b/packages/webui/third_party/editor/markdown-it/lib/helpers/index.mjs new file mode 100644 index 000000000..7ea30af9a --- /dev/null +++ b/packages/webui/third_party/editor/markdown-it/lib/helpers/index.mjs @@ -0,0 +1,11 @@ +// Just a shortcut for bulk export + +import parseLinkLabel from './parse_link_label.mjs' +import parseLinkDestination from './parse_link_destination.mjs' +import parseLinkTitle from './parse_link_title.mjs' + +export { + parseLinkLabel, + parseLinkDestination, + parseLinkTitle +} diff --git a/packages/webui/third_party/editor/markdown-it/lib/helpers/parse_link_destination.mjs b/packages/webui/third_party/editor/markdown-it/lib/helpers/parse_link_destination.mjs new file mode 100644 index 000000000..31523ce22 --- /dev/null +++ b/packages/webui/third_party/editor/markdown-it/lib/helpers/parse_link_destination.mjs @@ -0,0 +1,77 @@ +// Parse link destination +// + +import { unescapeAll } from '../common/utils.mjs' + +export default function parseLinkDestination (str, start, max) { + let code + let pos = start + + const result = { + ok: false, + pos: 0, + str: '' + } + + if (str.charCodeAt(pos) === 0x3C /* < */) { + pos++ + while (pos < max) { + code = str.charCodeAt(pos) + if (code === 0x0A /* \n */) { return result } + if (code === 0x3C /* < */) { return result } + if (code === 0x3E /* > */) { + result.pos = pos + 1 + result.str = unescapeAll(str.slice(start + 1, pos)) + result.ok = true + return result + } + if (code === 0x5C /* \ */ && pos + 1 < max) { + pos += 2 + continue + } + + pos++ + } + + // no closing '>' + return result + } + + // this should be ... } else { ... branch + + let level = 0 + while (pos < max) { + code = str.charCodeAt(pos) + + if (code === 0x20) { break } + + // ascii control characters + if (code < 0x20 || code === 0x7F) { break } + + if (code === 0x5C /* \ */ && pos + 1 < max) { + if (str.charCodeAt(pos + 1) === 0x20) { pos++; continue } + pos += 2 + continue + } + + if (code === 0x28 /* ( */) { + level++ + if (level > 32) { return result } + } + + if (code === 0x29 /* ) */) { + if (level === 0) { break } + level-- + } + + pos++ + } + + if (start === pos) { return result } + if (level !== 0) { return result } + + result.str = unescapeAll(str.slice(start, pos)) + result.pos = pos + result.ok = true + return result +} diff --git a/packages/webui/third_party/editor/markdown-it/lib/helpers/parse_link_label.mjs b/packages/webui/third_party/editor/markdown-it/lib/helpers/parse_link_label.mjs new file mode 100644 index 000000000..f1a53fa1f --- /dev/null +++ b/packages/webui/third_party/editor/markdown-it/lib/helpers/parse_link_label.mjs @@ -0,0 +1,49 @@ +// Parse link label +// +// this function assumes that first character ("[") already matches; +// returns the end of the label +// + +export default function parseLinkLabel (state, start, disableNested) { + let level, found, marker, prevPos + + const max = state.posMax + const oldPos = state.pos + + state.pos = start + 1 + level = 1 + + while (state.pos < max) { + marker = state.src.charCodeAt(state.pos) + if (marker === 0x5D /* ] */) { + level-- + if (level === 0) { + found = true + break + } + } + + prevPos = state.pos + state.md.inline.skipToken(state) + if (marker === 0x5B /* [ */) { + if (prevPos === state.pos - 1) { + // increase level if we find text `[`, which is not a part of any token + level++ + } else if (disableNested) { + state.pos = oldPos + return -1 + } + } + } + + let labelEnd = -1 + + if (found) { + labelEnd = state.pos + } + + // restore old state + state.pos = oldPos + + return labelEnd +} diff --git a/packages/webui/third_party/editor/markdown-it/lib/helpers/parse_link_title.mjs b/packages/webui/third_party/editor/markdown-it/lib/helpers/parse_link_title.mjs new file mode 100644 index 000000000..4605647bf --- /dev/null +++ b/packages/webui/third_party/editor/markdown-it/lib/helpers/parse_link_title.mjs @@ -0,0 +1,66 @@ +// Parse link title +// + +import { unescapeAll } from '../common/utils.mjs' + +// Parse link title within `str` in [start, max] range, +// or continue previous parsing if `prev_state` is defined (equal to result of last execution). +// +export default function parseLinkTitle (str, start, max, prev_state) { + let code + let pos = start + + const state = { + // if `true`, this is a valid link title + ok: false, + // if `true`, this link can be continued on the next line + can_continue: false, + // if `ok`, it's the position of the first character after the closing marker + pos: 0, + // if `ok`, it's the unescaped title + str: '', + // expected closing marker character code + marker: 0 + } + + if (prev_state) { + // this is a continuation of a previous parseLinkTitle call on the next line, + // used in reference links only + state.str = prev_state.str + state.marker = prev_state.marker + } else { + if (pos >= max) { return state } + + let marker = str.charCodeAt(pos) + if (marker !== 0x22 /* " */ && marker !== 0x27 /* ' */ && marker !== 0x28 /* ( */) { return state } + + start++ + pos++ + + // if opening marker is "(", switch it to closing marker ")" + if (marker === 0x28) { marker = 0x29 } + + state.marker = marker + } + + while (pos < max) { + code = str.charCodeAt(pos) + if (code === state.marker) { + state.pos = pos + 1 + state.str += unescapeAll(str.slice(start, pos)) + state.ok = true + return state + } else if (code === 0x28 /* ( */ && state.marker === 0x29 /* ) */) { + return state + } else if (code === 0x5C /* \ */ && pos + 1 < max) { + pos++ + } + + pos++ + } + + // no closing marker found, but this link title may continue on the next line (for references) + state.can_continue = true + state.str += unescapeAll(str.slice(start, pos)) + return state +} diff --git a/packages/webui/third_party/editor/markdown-it/lib/index.mjs b/packages/webui/third_party/editor/markdown-it/lib/index.mjs new file mode 100644 index 000000000..482bf9eaf --- /dev/null +++ b/packages/webui/third_party/editor/markdown-it/lib/index.mjs @@ -0,0 +1,565 @@ +// Main parser class + +import * as utils from './common/utils.mjs' +import * as helpers from './helpers/index.mjs' +import Renderer from './renderer.mjs' +import ParserCore from './parser_core.mjs' +import ParserBlock from './parser_block.mjs' +import ParserInline from './parser_inline.mjs' +import LinkifyIt from 'linkify-it' +import * as mdurl from 'mdurl' +import punycode from 'punycode.js' + +import cfg_default from './presets/default.mjs' +import cfg_zero from './presets/zero.mjs' +import cfg_commonmark from './presets/commonmark.mjs' + +const config = { + default: cfg_default, + zero: cfg_zero, + commonmark: cfg_commonmark +} + +// +// This validator can prohibit more than really needed to prevent XSS. It's a +// tradeoff to keep code simple and to be secure by default. +// +// If you need different setup - override validator method as you wish. Or +// replace it with dummy function and use external sanitizer. +// + +const BAD_PROTO_RE = /^(vbscript|javascript|file|data):/ +const GOOD_DATA_RE = /^data:image\/(gif|png|jpeg|webp);/ + +function validateLink (url) { + // url should be normalized at this point, and existing entities are decoded + const str = url.trim().toLowerCase() + + return BAD_PROTO_RE.test(str) ? GOOD_DATA_RE.test(str) : true +} + +const RECODE_HOSTNAME_FOR = ['http:', 'https:', 'mailto:'] + +function normalizeLink (url) { + const parsed = mdurl.parse(url, true) + + if (parsed.hostname) { + // Encode hostnames in urls like: + // `http://host/`, `https://host/`, `mailto:user@host`, `//host/` + // + // We don't encode unknown schemas, because it's likely that we encode + // something we shouldn't (e.g. `skype:name` treated as `skype:host`) + // + if (!parsed.protocol || RECODE_HOSTNAME_FOR.indexOf(parsed.protocol) >= 0) { + try { + parsed.hostname = punycode.toASCII(parsed.hostname) + } catch (er) { /**/ } + } + } + + return mdurl.encode(mdurl.format(parsed)) +} + +function normalizeLinkText (url) { + const parsed = mdurl.parse(url, true) + + if (parsed.hostname) { + // Encode hostnames in urls like: + // `http://host/`, `https://host/`, `mailto:user@host`, `//host/` + // + // We don't encode unknown schemas, because it's likely that we encode + // something we shouldn't (e.g. `skype:name` treated as `skype:host`) + // + if (!parsed.protocol || RECODE_HOSTNAME_FOR.indexOf(parsed.protocol) >= 0) { + try { + parsed.hostname = punycode.toUnicode(parsed.hostname) + } catch (er) { /**/ } + } + } + + // add '%' to exclude list because of https://github.com/markdown-it/markdown-it/issues/720 + return mdurl.decode(mdurl.format(parsed), mdurl.decode.defaultChars + '%') +} + +/** + * class MarkdownIt + * + * Main parser/renderer class. + * + * ##### Usage + * + * ```javascript + * // node.js, "classic" way: + * var MarkdownIt = require('markdown-it'), + * md = new MarkdownIt(); + * var result = md.render('# markdown-it rulezz!'); + * + * // node.js, the same, but with sugar: + * var md = require('markdown-it')(); + * var result = md.render('# markdown-it rulezz!'); + * + * // browser without AMD, added to "window" on script load + * // Note, there are no dash. + * var md = window.markdownit(); + * var result = md.render('# markdown-it rulezz!'); + * ``` + * + * Single line rendering, without paragraph wrap: + * + * ```javascript + * var md = require('markdown-it')(); + * var result = md.renderInline('__markdown-it__ rulezz!'); + * ``` + **/ + +/** + * new MarkdownIt([presetName, options]) + * - presetName (String): optional, `commonmark` / `zero` + * - options (Object) + * + * Creates parser instanse with given config. Can be called without `new`. + * + * ##### presetName + * + * MarkdownIt provides named presets as a convenience to quickly + * enable/disable active syntax rules and options for common use cases. + * + * - ["commonmark"](https://github.com/markdown-it/markdown-it/blob/master/lib/presets/commonmark.mjs) - + * configures parser to strict [CommonMark](http://commonmark.org/) mode. + * - [default](https://github.com/markdown-it/markdown-it/blob/master/lib/presets/default.mjs) - + * similar to GFM, used when no preset name given. Enables all available rules, + * but still without html, typographer & autolinker. + * - ["zero"](https://github.com/markdown-it/markdown-it/blob/master/lib/presets/zero.mjs) - + * all rules disabled. Useful to quickly setup your config via `.enable()`. + * For example, when you need only `bold` and `italic` markup and nothing else. + * + * ##### options: + * + * - __html__ - `false`. Set `true` to enable HTML tags in source. Be careful! + * That's not safe! You may need external sanitizer to protect output from XSS. + * It's better to extend features via plugins, instead of enabling HTML. + * - __xhtmlOut__ - `false`. Set `true` to add '/' when closing single tags + * (`
`). This is needed only for full CommonMark compatibility. In real + * world you will need HTML output. + * - __breaks__ - `false`. Set `true` to convert `\n` in paragraphs into `
`. + * - __langPrefix__ - `language-`. CSS language class prefix for fenced blocks. + * Can be useful for external highlighters. + * - __linkify__ - `false`. Set `true` to autoconvert URL-like text to links. + * - __typographer__ - `false`. Set `true` to enable [some language-neutral + * replacement](https://github.com/markdown-it/markdown-it/blob/master/lib/rules_core/replacements.mjs) + + * quotes beautification (smartquotes). + * - __quotes__ - `“”‘’`, String or Array. Double + single quotes replacement + * pairs, when typographer enabled and smartquotes on. For example, you can + * use `'«»„“'` for Russian, `'„“‚‘'` for German, and + * `['«\xA0', '\xA0»', '‹\xA0', '\xA0›']` for French (including nbsp). + * - __highlight__ - `null`. Highlighter function for fenced code blocks. + * Highlighter `function (str, lang)` should return escaped HTML. It can also + * return empty string if the source was not changed and should be escaped + * externaly. If result starts with ` or ``): + * + * ```javascript + * var hljs = require('highlight.js') // https://highlightjs.org/ + * + * // Actual default values + * var md = require('markdown-it')({ + * highlight: function (str, lang) { + * if (lang && hljs.getLanguage(lang)) { + * try { + * return '
' +
+ *                hljs.highlight(str, { language: lang, ignoreIllegals: true }).value +
+ *                '
'; + * } catch (__) {} + * } + * + * return '
' + md.utils.escapeHtml(str) + '
'; + * } + * }); + * ``` + * + **/ +function MarkdownIt (presetName, options) { + if (!(this instanceof MarkdownIt)) { + return new MarkdownIt(presetName, options) + } + + if (!options) { + if (!utils.isString(presetName)) { + options = presetName || {} + presetName = 'default' + } + } + + /** + * MarkdownIt#inline -> ParserInline + * + * Instance of [[ParserInline]]. You may need it to add new rules when + * writing plugins. For simple rules control use [[MarkdownIt.disable]] and + * [[MarkdownIt.enable]]. + **/ + this.inline = new ParserInline() + + /** + * MarkdownIt#block -> ParserBlock + * + * Instance of [[ParserBlock]]. You may need it to add new rules when + * writing plugins. For simple rules control use [[MarkdownIt.disable]] and + * [[MarkdownIt.enable]]. + **/ + this.block = new ParserBlock() + + /** + * MarkdownIt#core -> Core + * + * Instance of [[Core]] chain executor. You may need it to add new rules when + * writing plugins. For simple rules control use [[MarkdownIt.disable]] and + * [[MarkdownIt.enable]]. + **/ + this.core = new ParserCore() + + /** + * MarkdownIt#renderer -> Renderer + * + * Instance of [[Renderer]]. Use it to modify output look. Or to add rendering + * rules for new token types, generated by plugins. + * + * ##### Example + * + * ```javascript + * var md = require('markdown-it')(); + * + * function myToken(tokens, idx, options, env, self) { + * //... + * return result; + * }; + * + * md.renderer.rules['my_token'] = myToken + * ``` + * + * See [[Renderer]] docs and [source code](https://github.com/markdown-it/markdown-it/blob/master/lib/renderer.mjs). + **/ + this.renderer = new Renderer() + + /** + * MarkdownIt#linkify -> LinkifyIt + * + * [linkify-it](https://github.com/markdown-it/linkify-it) instance. + * Used by [linkify](https://github.com/markdown-it/markdown-it/blob/master/lib/rules_core/linkify.mjs) + * rule. + **/ + this.linkify = new LinkifyIt() + + /** + * MarkdownIt#validateLink(url) -> Boolean + * + * Link validation function. CommonMark allows too much in links. By default + * we disable `javascript:`, `vbscript:`, `file:` schemas, and almost all `data:...` schemas + * except some embedded image types. + * + * You can change this behaviour: + * + * ```javascript + * var md = require('markdown-it')(); + * // enable everything + * md.validateLink = function () { return true; } + * ``` + **/ + this.validateLink = validateLink + + /** + * MarkdownIt#normalizeLink(url) -> String + * + * Function used to encode link url to a machine-readable format, + * which includes url-encoding, punycode, etc. + **/ + this.normalizeLink = normalizeLink + + /** + * MarkdownIt#normalizeLinkText(url) -> String + * + * Function used to decode link url to a human-readable format` + **/ + this.normalizeLinkText = normalizeLinkText + + // Expose utils & helpers for easy acces from plugins + + /** + * MarkdownIt#utils -> utils + * + * Assorted utility functions, useful to write plugins. See details + * [here](https://github.com/markdown-it/markdown-it/blob/master/lib/common/utils.mjs). + **/ + this.utils = utils + + /** + * MarkdownIt#helpers -> helpers + * + * Link components parser functions, useful to write plugins. See details + * [here](https://github.com/markdown-it/markdown-it/blob/master/lib/helpers). + **/ + this.helpers = utils.assign({}, helpers) + + this.options = {} + this.configure(presetName) + + if (options) { this.set(options) } +} + +/** chainable + * MarkdownIt.set(options) + * + * Set parser options (in the same format as in constructor). Probably, you + * will never need it, but you can change options after constructor call. + * + * ##### Example + * + * ```javascript + * var md = require('markdown-it')() + * .set({ html: true, breaks: true }) + * .set({ typographer: true }); + * ``` + * + * __Note:__ To achieve the best possible performance, don't modify a + * `markdown-it` instance options on the fly. If you need multiple configurations + * it's best to create multiple instances and initialize each with separate + * config. + **/ +MarkdownIt.prototype.set = function (options) { + utils.assign(this.options, options) + return this +} + +/** chainable, internal + * MarkdownIt.configure(presets) + * + * Batch load of all options and compenent settings. This is internal method, + * and you probably will not need it. But if you will - see available presets + * and data structure [here](https://github.com/markdown-it/markdown-it/tree/master/lib/presets) + * + * We strongly recommend to use presets instead of direct config loads. That + * will give better compatibility with next versions. + **/ +MarkdownIt.prototype.configure = function (presets) { + const self = this + + if (utils.isString(presets)) { + const presetName = presets + presets = config[presetName] + if (!presets) { throw new Error('Wrong `markdown-it` preset "' + presetName + '", check name') } + } + + if (!presets) { throw new Error('Wrong `markdown-it` preset, can\'t be empty') } + + if (presets.options) { self.set(presets.options) } + + if (presets.components) { + Object.keys(presets.components).forEach(function (name) { + if (presets.components[name].rules) { + self[name].ruler.enableOnly(presets.components[name].rules) + } + if (presets.components[name].rules2) { + self[name].ruler2.enableOnly(presets.components[name].rules2) + } + }) + } + return this +} + +/** chainable + * MarkdownIt.enable(list, ignoreInvalid) + * - list (String|Array): rule name or list of rule names to enable + * - ignoreInvalid (Boolean): set `true` to ignore errors when rule not found. + * + * Enable list or rules. It will automatically find appropriate components, + * containing rules with given names. If rule not found, and `ignoreInvalid` + * not set - throws exception. + * + * ##### Example + * + * ```javascript + * var md = require('markdown-it')() + * .enable(['sub', 'sup']) + * .disable('smartquotes'); + * ``` + **/ +MarkdownIt.prototype.enable = function (list, ignoreInvalid) { + let result = [] + + if (!Array.isArray(list)) { list = [list] } + + ['core', 'block', 'inline'].forEach(function (chain) { + result = result.concat(this[chain].ruler.enable(list, true)) + }, this) + + result = result.concat(this.inline.ruler2.enable(list, true)) + + const missed = list.filter(function (name) { return result.indexOf(name) < 0 }) + + if (missed.length && !ignoreInvalid) { + throw new Error('MarkdownIt. Failed to enable unknown rule(s): ' + missed) + } + + return this +} + +/** chainable + * MarkdownIt.disable(list, ignoreInvalid) + * - list (String|Array): rule name or list of rule names to disable. + * - ignoreInvalid (Boolean): set `true` to ignore errors when rule not found. + * + * The same as [[MarkdownIt.enable]], but turn specified rules off. + **/ +MarkdownIt.prototype.disable = function (list, ignoreInvalid) { + let result = [] + + if (!Array.isArray(list)) { list = [list] } + + ['core', 'block', 'inline'].forEach(function (chain) { + result = result.concat(this[chain].ruler.disable(list, true)) + }, this) + + result = result.concat(this.inline.ruler2.disable(list, true)) + + const missed = list.filter(function (name) { return result.indexOf(name) < 0 }) + + if (missed.length && !ignoreInvalid) { + throw new Error('MarkdownIt. Failed to disable unknown rule(s): ' + missed) + } + return this +} + +/** chainable + * MarkdownIt.use(plugin, params) + * + * Load specified plugin with given params into current parser instance. + * It's just a sugar to call `plugin(md, params)` with curring. + * + * ##### Example + * + * ```javascript + * var iterator = require('markdown-it-for-inline'); + * var md = require('markdown-it')() + * .use(iterator, 'foo_replace', 'text', function (tokens, idx) { + * tokens[idx].content = tokens[idx].content.replace(/foo/g, 'bar'); + * }); + * ``` + **/ +MarkdownIt.prototype.use = function (plugin /*, params, ... */) { + const args = [this].concat(Array.prototype.slice.call(arguments, 1)) + plugin.apply(plugin, args) + return this +} + +/** internal + * MarkdownIt.parse(src, env) -> Array + * - src (String): source string + * - env (Object): environment sandbox + * + * Parse input string and return list of block tokens (special token type + * "inline" will contain list of inline tokens). You should not call this + * method directly, until you write custom renderer (for example, to produce + * AST). + * + * `env` is used to pass data between "distributed" rules and return additional + * metadata like reference info, needed for the renderer. It also can be used to + * inject data in specific cases. Usually, you will be ok to pass `{}`, + * and then pass updated object to renderer. + **/ +MarkdownIt.prototype.parse = function (src, env) { + if (typeof src !== 'string') { + throw new Error('Input data should be a String') + } + + const state = new this.core.State(src, this, env) + + this.core.process(state) + + return state.tokens +} + +/** + * MarkdownIt.render(src [, env]) -> String + * - src (String): source string + * - env (Object): environment sandbox + * + * Render markdown string into html. It does all magic for you :). + * + * `env` can be used to inject additional metadata (`{}` by default). + * But you will not need it with high probability. See also comment + * in [[MarkdownIt.parse]]. + **/ +MarkdownIt.prototype.render = function (src, env) { + env = env || {} + + return this.renderer.render(this.parse(src, env), this.options, env) +} + +/** internal + * MarkdownIt.parseInline(src, env) -> Array + * - src (String): source string + * - env (Object): environment sandbox + * + * The same as [[MarkdownIt.parse]] but skip all block rules. It returns the + * block tokens list with the single `inline` element, containing parsed inline + * tokens in `children` property. Also updates `env` object. + **/ +MarkdownIt.prototype.parseInline = function (src, env) { + const state = new this.core.State(src, this, env) + + state.inlineMode = true + this.core.process(state) + + return state.tokens +} + +/** + * MarkdownIt.renderInline(src [, env]) -> String + * - src (String): source string + * - env (Object): environment sandbox + * + * Similar to [[MarkdownIt.render]] but for single paragraph content. Result + * will NOT be wrapped into `

` tags. + **/ +MarkdownIt.prototype.renderInline = function (src, env) { + env = env || {} + + return this.renderer.render(this.parseInline(src, env), this.options, env) +} + +export default MarkdownIt diff --git a/packages/webui/third_party/editor/markdown-it/lib/parser_block.mjs b/packages/webui/third_party/editor/markdown-it/lib/parser_block.mjs new file mode 100644 index 000000000..36e010937 --- /dev/null +++ b/packages/webui/third_party/editor/markdown-it/lib/parser_block.mjs @@ -0,0 +1,134 @@ +/** internal + * class ParserBlock + * + * Block-level tokenizer. + **/ + +import Ruler from './ruler.mjs' +import StateBlock from './rules_block/state_block.mjs' + +import r_table from './rules_block/table.mjs' +import r_code from './rules_block/code.mjs' +import r_fence from './rules_block/fence.mjs' +import r_blockquote from './rules_block/blockquote.mjs' +import r_hr from './rules_block/hr.mjs' +import r_list from './rules_block/list.mjs' +import r_reference from './rules_block/reference.mjs' +import r_html_block from './rules_block/html_block.mjs' +import r_heading from './rules_block/heading.mjs' +import r_lheading from './rules_block/lheading.mjs' +import r_paragraph from './rules_block/paragraph.mjs' + +const _rules = [ + // First 2 params - rule name & source. Secondary array - list of rules, + // which can be terminated by this one. + ['table', r_table, ['paragraph', 'reference']], + ['code', r_code], + ['fence', r_fence, ['paragraph', 'reference', 'blockquote', 'list']], + ['blockquote', r_blockquote, ['paragraph', 'reference', 'blockquote', 'list']], + ['hr', r_hr, ['paragraph', 'reference', 'blockquote', 'list']], + ['list', r_list, ['paragraph', 'reference', 'blockquote']], + ['reference', r_reference], + ['html_block', r_html_block, ['paragraph', 'reference', 'blockquote']], + ['heading', r_heading, ['paragraph', 'reference', 'blockquote']], + ['lheading', r_lheading], + ['paragraph', r_paragraph] +] + +/** + * new ParserBlock() + **/ +function ParserBlock () { + /** + * ParserBlock#ruler -> Ruler + * + * [[Ruler]] instance. Keep configuration of block rules. + **/ + this.ruler = new Ruler() + + for (let i = 0; i < _rules.length; i++) { + this.ruler.push(_rules[i][0], _rules[i][1], { alt: (_rules[i][2] || []).slice() }) + } +} + +// Generate tokens for input range +// +ParserBlock.prototype.tokenize = function (state, startLine, endLine) { + const rules = this.ruler.getRules('') + const len = rules.length + const maxNesting = state.md.options.maxNesting + let line = startLine + let hasEmptyLines = false + + while (line < endLine) { + state.line = line = state.skipEmptyLines(line) + if (line >= endLine) { break } + + // Termination condition for nested calls. + // Nested calls currently used for blockquotes & lists + if (state.sCount[line] < state.blkIndent) { break } + + // If nesting level exceeded - skip tail to the end. That's not ordinary + // situation and we should not care about content. + if (state.level >= maxNesting) { + state.line = endLine + break + } + + // Try all possible rules. + // On success, rule should: + // + // - update `state.line` + // - update `state.tokens` + // - return true + const prevLine = state.line + let ok = false + + for (let i = 0; i < len; i++) { + ok = rules[i](state, line, endLine, false) + if (ok) { + if (prevLine >= state.line) { + throw new Error("block rule didn't increment state.line") + } + break + } + } + + // this can only happen if user disables paragraph rule + if (!ok) throw new Error('none of the block rules matched') + + // set state.tight if we had an empty line before current tag + // i.e. latest empty line should not count + state.tight = !hasEmptyLines + + // paragraph might "eat" one newline after it in nested lists + if (state.isEmpty(state.line - 1)) { + hasEmptyLines = true + } + + line = state.line + + if (line < endLine && state.isEmpty(line)) { + hasEmptyLines = true + line++ + state.line = line + } + } +} + +/** + * ParserBlock.parse(str, md, env, outTokens) + * + * Process input string and push block tokens into `outTokens` + **/ +ParserBlock.prototype.parse = function (src, md, env, outTokens) { + if (!src) { return } + + const state = new this.State(src, md, env, outTokens) + + this.tokenize(state, state.line, state.lineMax) +} + +ParserBlock.prototype.State = StateBlock + +export default ParserBlock diff --git a/packages/webui/third_party/editor/markdown-it/lib/parser_core.mjs b/packages/webui/third_party/editor/markdown-it/lib/parser_core.mjs new file mode 100644 index 000000000..4337554c2 --- /dev/null +++ b/packages/webui/third_party/editor/markdown-it/lib/parser_core.mjs @@ -0,0 +1,62 @@ +/** internal + * class Core + * + * Top-level rules executor. Glues block/inline parsers and does intermediate + * transformations. + **/ + +import Ruler from './ruler.mjs' +import StateCore from './rules_core/state_core.mjs' + +import r_normalize from './rules_core/normalize.mjs' +import r_block from './rules_core/block.mjs' +import r_inline from './rules_core/inline.mjs' +import r_linkify from './rules_core/linkify.mjs' +import r_replacements from './rules_core/replacements.mjs' +import r_smartquotes from './rules_core/smartquotes.mjs' +import r_text_join from './rules_core/text_join.mjs' + +const _rules = [ + ['normalize', r_normalize], + ['block', r_block], + ['inline', r_inline], + ['linkify', r_linkify], + ['replacements', r_replacements], + ['smartquotes', r_smartquotes], + // `text_join` finds `text_special` tokens (for escape sequences) + // and joins them with the rest of the text + ['text_join', r_text_join] +] + +/** + * new Core() + **/ +function Core () { + /** + * Core#ruler -> Ruler + * + * [[Ruler]] instance. Keep configuration of core rules. + **/ + this.ruler = new Ruler() + + for (let i = 0; i < _rules.length; i++) { + this.ruler.push(_rules[i][0], _rules[i][1]) + } +} + +/** + * Core.process(state) + * + * Executes core chain rules. + **/ +Core.prototype.process = function (state) { + const rules = this.ruler.getRules('') + + for (let i = 0, l = rules.length; i < l; i++) { + rules[i](state) + } +} + +Core.prototype.State = StateCore + +export default Core diff --git a/packages/webui/third_party/editor/markdown-it/lib/parser_inline.mjs b/packages/webui/third_party/editor/markdown-it/lib/parser_inline.mjs new file mode 100644 index 000000000..9f7bb4c48 --- /dev/null +++ b/packages/webui/third_party/editor/markdown-it/lib/parser_inline.mjs @@ -0,0 +1,197 @@ +/** internal + * class ParserInline + * + * Tokenizes paragraph content. + **/ + +import Ruler from './ruler.mjs' +import StateInline from './rules_inline/state_inline.mjs' + +import r_text from './rules_inline/text.mjs' +import r_linkify from './rules_inline/linkify.mjs' +import r_newline from './rules_inline/newline.mjs' +import r_escape from './rules_inline/escape.mjs' +import r_backticks from './rules_inline/backticks.mjs' +import r_strikethrough from './rules_inline/strikethrough.mjs' +import r_emphasis from './rules_inline/emphasis.mjs' +import r_link from './rules_inline/link.mjs' +import r_image from './rules_inline/image.mjs' +import r_autolink from './rules_inline/autolink.mjs' +import r_html_inline from './rules_inline/html_inline.mjs' +import r_entity from './rules_inline/entity.mjs' + +import r_balance_pairs from './rules_inline/balance_pairs.mjs' +import r_fragments_join from './rules_inline/fragments_join.mjs' + +// Parser rules + +const _rules = [ + ['text', r_text], + ['linkify', r_linkify], + ['newline', r_newline], + ['escape', r_escape], + ['backticks', r_backticks], + ['strikethrough', r_strikethrough.tokenize], + ['emphasis', r_emphasis.tokenize], + ['link', r_link], + ['image', r_image], + ['autolink', r_autolink], + ['html_inline', r_html_inline], + ['entity', r_entity] +] + +// `rule2` ruleset was created specifically for emphasis/strikethrough +// post-processing and may be changed in the future. +// +// Don't use this for anything except pairs (plugins working with `balance_pairs`). +// +const _rules2 = [ + ['balance_pairs', r_balance_pairs], + ['strikethrough', r_strikethrough.postProcess], + ['emphasis', r_emphasis.postProcess], + // rules for pairs separate '**' into its own text tokens, which may be left unused, + // rule below merges unused segments back with the rest of the text + ['fragments_join', r_fragments_join] +] + +/** + * new ParserInline() + **/ +function ParserInline () { + /** + * ParserInline#ruler -> Ruler + * + * [[Ruler]] instance. Keep configuration of inline rules. + **/ + this.ruler = new Ruler() + + for (let i = 0; i < _rules.length; i++) { + this.ruler.push(_rules[i][0], _rules[i][1]) + } + + /** + * ParserInline#ruler2 -> Ruler + * + * [[Ruler]] instance. Second ruler used for post-processing + * (e.g. in emphasis-like rules). + **/ + this.ruler2 = new Ruler() + + for (let i = 0; i < _rules2.length; i++) { + this.ruler2.push(_rules2[i][0], _rules2[i][1]) + } +} + +// Skip single token by running all rules in validation mode; +// returns `true` if any rule reported success +// +ParserInline.prototype.skipToken = function (state) { + const pos = state.pos + const rules = this.ruler.getRules('') + const len = rules.length + const maxNesting = state.md.options.maxNesting + const cache = state.cache + + if (typeof cache[pos] !== 'undefined') { + state.pos = cache[pos] + return + } + + let ok = false + + if (state.level < maxNesting) { + for (let i = 0; i < len; i++) { + // Increment state.level and decrement it later to limit recursion. + // It's harmless to do here, because no tokens are created. But ideally, + // we'd need a separate private state variable for this purpose. + // + state.level++ + ok = rules[i](state, true) + state.level-- + + if (ok) { + if (pos >= state.pos) { throw new Error("inline rule didn't increment state.pos") } + break + } + } + } else { + // Too much nesting, just skip until the end of the paragraph. + // + // NOTE: this will cause links to behave incorrectly in the following case, + // when an amount of `[` is exactly equal to `maxNesting + 1`: + // + // [[[[[[[[[[[[[[[[[[[[[foo]() + // + // TODO: remove this workaround when CM standard will allow nested links + // (we can replace it by preventing links from being parsed in + // validation mode) + // + state.pos = state.posMax + } + + if (!ok) { state.pos++ } + cache[pos] = state.pos +} + +// Generate tokens for input range +// +ParserInline.prototype.tokenize = function (state) { + const rules = this.ruler.getRules('') + const len = rules.length + const end = state.posMax + const maxNesting = state.md.options.maxNesting + + while (state.pos < end) { + // Try all possible rules. + // On success, rule should: + // + // - update `state.pos` + // - update `state.tokens` + // - return true + const prevPos = state.pos + let ok = false + + if (state.level < maxNesting) { + for (let i = 0; i < len; i++) { + ok = rules[i](state, false) + if (ok) { + if (prevPos >= state.pos) { throw new Error("inline rule didn't increment state.pos") } + break + } + } + } + + if (ok) { + if (state.pos >= end) { break } + continue + } + + state.pending += state.src[state.pos++] + } + + if (state.pending) { + state.pushPending() + } +} + +/** + * ParserInline.parse(str, md, env, outTokens) + * + * Process input string and push inline tokens into `outTokens` + **/ +ParserInline.prototype.parse = function (str, md, env, outTokens) { + const state = new this.State(str, md, env, outTokens) + + this.tokenize(state) + + const rules = this.ruler2.getRules('') + const len = rules.length + + for (let i = 0; i < len; i++) { + rules[i](state) + } +} + +ParserInline.prototype.State = StateInline + +export default ParserInline diff --git a/packages/webui/third_party/editor/markdown-it/lib/presets/commonmark.mjs b/packages/webui/third_party/editor/markdown-it/lib/presets/commonmark.mjs new file mode 100644 index 000000000..7e705ad2f --- /dev/null +++ b/packages/webui/third_party/editor/markdown-it/lib/presets/commonmark.mjs @@ -0,0 +1,88 @@ +// Commonmark default options + +export default { + options: { + // Enable HTML tags in source + html: true, + + // Use '/' to close single tags (
) + xhtmlOut: true, + + // Convert '\n' in paragraphs into
+ breaks: false, + + // CSS language prefix for fenced blocks + langPrefix: 'language-', + + // autoconvert URL-like texts to links + linkify: false, + + // Enable some language-neutral replacements + quotes beautification + typographer: false, + + // Double + single quotes replacement pairs, when typographer enabled, + // and smartquotes on. Could be either a String or an Array. + // + // For example, you can use '«»„“' for Russian, '„“‚‘' for German, + // and ['«\xA0', '\xA0»', '‹\xA0', '\xA0›'] for French (including nbsp). + quotes: '\u201c\u201d\u2018\u2019', /* “”‘’ */ + + // Highlighter function. Should return escaped HTML, + // or '' if the source string is not changed and should be escaped externaly. + // If result starts with ) + xhtmlOut: false, + + // Convert '\n' in paragraphs into
+ breaks: false, + + // CSS language prefix for fenced blocks + langPrefix: 'language-', + + // autoconvert URL-like texts to links + linkify: false, + + // Enable some language-neutral replacements + quotes beautification + typographer: false, + + // Double + single quotes replacement pairs, when typographer enabled, + // and smartquotes on. Could be either a String or an Array. + // + // For example, you can use '«»„“' for Russian, '„“‚‘' for German, + // and ['«\xA0', '\xA0»', '‹\xA0', '\xA0›'] for French (including nbsp). + quotes: '\u201c\u201d\u2018\u2019', /* “”‘’ */ + + // Highlighter function. Should return escaped HTML, + // or '' if the source string is not changed and should be escaped externaly. + // If result starts with ) + xhtmlOut: false, + + // Convert '\n' in paragraphs into
+ breaks: false, + + // CSS language prefix for fenced blocks + langPrefix: 'language-', + + // autoconvert URL-like texts to links + linkify: false, + + // Enable some language-neutral replacements + quotes beautification + typographer: false, + + // Double + single quotes replacement pairs, when typographer enabled, + // and smartquotes on. Could be either a String or an Array. + // + // For example, you can use '«»„“' for Russian, '„“‚‘' for German, + // and ['«\xA0', '\xA0»', '‹\xA0', '\xA0›'] for French (including nbsp). + quotes: '\u201c\u201d\u2018\u2019', /* “”‘’ */ + + // Highlighter function. Should return escaped HTML, + // or '' if the source string is not changed and should be escaped externaly. + // If result starts with ' + + escapeHtml(token.content) + + '
' +} + +default_rules.code_block = function (tokens, idx, options, env, slf) { + const token = tokens[idx] + + return '' + + escapeHtml(tokens[idx].content) + + '

\n' +} + +default_rules.fence = function (tokens, idx, options, env, slf) { + const token = tokens[idx] + const info = token.info ? unescapeAll(token.info).trim() : '' + let langName = '' + let langAttrs = '' + + if (info) { + const arr = info.split(/(\s+)/g) + langName = arr[0] + langAttrs = arr.slice(2).join('') + } + + let highlighted + if (options.highlight) { + highlighted = options.highlight(token.content, langName, langAttrs) || escapeHtml(token.content) + } else { + highlighted = escapeHtml(token.content) + } + + if (highlighted.indexOf('${highlighted}
\n` + } + + return `
${highlighted}
\n` +} + +default_rules.image = function (tokens, idx, options, env, slf) { + const token = tokens[idx] + + // "alt" attr MUST be set, even if empty. Because it's mandatory and + // should be placed on proper position for tests. + // + // Replace content with actual value + + token.attrs[token.attrIndex('alt')][1] = + slf.renderInlineAsText(token.children, options, env) + + return slf.renderToken(tokens, idx, options) +} + +default_rules.hardbreak = function (tokens, idx, options /*, env */) { + return options.xhtmlOut ? '
\n' : '
\n' +} +default_rules.softbreak = function (tokens, idx, options /*, env */) { + return options.breaks ? (options.xhtmlOut ? '
\n' : '
\n') : '\n' +} + +default_rules.text = function (tokens, idx /*, options, env */) { + return escapeHtml(tokens[idx].content) +} + +default_rules.html_block = function (tokens, idx /*, options, env */) { + return tokens[idx].content +} +default_rules.html_inline = function (tokens, idx /*, options, env */) { + return tokens[idx].content +} + +/** + * new Renderer() + * + * Creates new [[Renderer]] instance and fill [[Renderer#rules]] with defaults. + **/ +function Renderer () { + /** + * Renderer#rules -> Object + * + * Contains render rules for tokens. Can be updated and extended. + * + * ##### Example + * + * ```javascript + * var md = require('markdown-it')(); + * + * md.renderer.rules.strong_open = function () { return ''; }; + * md.renderer.rules.strong_close = function () { return ''; }; + * + * var result = md.renderInline(...); + * ``` + * + * Each rule is called as independent static function with fixed signature: + * + * ```javascript + * function my_token_render(tokens, idx, options, env, renderer) { + * // ... + * return renderedHTML; + * } + * ``` + * + * See [source code](https://github.com/markdown-it/markdown-it/blob/master/lib/renderer.mjs) + * for more details and examples. + **/ + this.rules = assign({}, default_rules) +} + +/** + * Renderer.renderAttrs(token) -> String + * + * Render token attributes to string. + **/ +Renderer.prototype.renderAttrs = function renderAttrs (token) { + let i, l, result + + if (!token.attrs) { return '' } + + result = '' + + for (i = 0, l = token.attrs.length; i < l; i++) { + result += ' ' + escapeHtml(token.attrs[i][0]) + '="' + escapeHtml(token.attrs[i][1]) + '"' + } + + return result +} + +/** + * Renderer.renderToken(tokens, idx, options) -> String + * - tokens (Array): list of tokens + * - idx (Numbed): token index to render + * - options (Object): params of parser instance + * + * Default token renderer. Can be overriden by custom function + * in [[Renderer#rules]]. + **/ +Renderer.prototype.renderToken = function renderToken (tokens, idx, options) { + const token = tokens[idx] + let result = '' + + // Tight list paragraphs + if (token.hidden) { + return '' + } + + // Insert a newline between hidden paragraph and subsequent opening + // block-level tag. + // + // For example, here we should insert a newline before blockquote: + // - a + // > + // + if (token.block && token.nesting !== -1 && idx && tokens[idx - 1].hidden) { + result += '\n' + } + + // Add token name, e.g. ``. + // + needLf = false + } + } + } + } + + result += needLf ? '>\n' : '>' + + return result +} + +/** + * Renderer.renderInline(tokens, options, env) -> String + * - tokens (Array): list on block tokens to render + * - options (Object): params of parser instance + * - env (Object): additional data from parsed input (references, for example) + * + * The same as [[Renderer.render]], but for single token of `inline` type. + **/ +Renderer.prototype.renderInline = function (tokens, options, env) { + let result = '' + const rules = this.rules + + for (let i = 0, len = tokens.length; i < len; i++) { + const type = tokens[i].type + + if (typeof rules[type] !== 'undefined') { + result += rules[type](tokens, i, options, env, this) + } else { + result += this.renderToken(tokens, i, options) + } + } + + return result +} + +/** internal + * Renderer.renderInlineAsText(tokens, options, env) -> String + * - tokens (Array): list on block tokens to render + * - options (Object): params of parser instance + * - env (Object): additional data from parsed input (references, for example) + * + * Special kludge for image `alt` attributes to conform CommonMark spec. + * Don't try to use it! Spec requires to show `alt` content with stripped markup, + * instead of simple escaping. + **/ +Renderer.prototype.renderInlineAsText = function (tokens, options, env) { + let result = '' + + for (let i = 0, len = tokens.length; i < len; i++) { + switch (tokens[i].type) { + case 'text': + result += tokens[i].content + break + case 'image': + result += this.renderInlineAsText(tokens[i].children, options, env) + break + case 'html_inline': + case 'html_block': + result += tokens[i].content + break + case 'softbreak': + case 'hardbreak': + result += '\n' + break + default: + // all other tokens are skipped + } + } + + return result +} + +/** + * Renderer.render(tokens, options, env) -> String + * - tokens (Array): list on block tokens to render + * - options (Object): params of parser instance + * - env (Object): additional data from parsed input (references, for example) + * + * Takes token stream and generates HTML. Probably, you will never need to call + * this method directly. + **/ +Renderer.prototype.render = function (tokens, options, env) { + let result = '' + const rules = this.rules + + for (let i = 0, len = tokens.length; i < len; i++) { + const type = tokens[i].type + + if (type === 'inline') { + result += this.renderInline(tokens[i].children, options, env) + } else if (typeof rules[type] !== 'undefined') { + result += rules[type](tokens, i, options, env, this) + } else { + result += this.renderToken(tokens, i, options, env) + } + } + + return result +} + +export default Renderer diff --git a/packages/webui/third_party/editor/markdown-it/lib/ruler.mjs b/packages/webui/third_party/editor/markdown-it/lib/ruler.mjs new file mode 100644 index 000000000..92c98e915 --- /dev/null +++ b/packages/webui/third_party/editor/markdown-it/lib/ruler.mjs @@ -0,0 +1,340 @@ +/** + * class Ruler + * + * Helper class, used by [[MarkdownIt#core]], [[MarkdownIt#block]] and + * [[MarkdownIt#inline]] to manage sequences of functions (rules): + * + * - keep rules in defined order + * - assign the name to each rule + * - enable/disable rules + * - add/replace rules + * - allow assign rules to additional named chains (in the same) + * - cacheing lists of active rules + * + * You will not need use this class directly until write plugins. For simple + * rules control use [[MarkdownIt.disable]], [[MarkdownIt.enable]] and + * [[MarkdownIt.use]]. + **/ + +/** + * new Ruler() + **/ +function Ruler () { + // List of added rules. Each element is: + // + // { + // name: XXX, + // enabled: Boolean, + // fn: Function(), + // alt: [ name2, name3 ] + // } + // + this.__rules__ = [] + + // Cached rule chains. + // + // First level - chain name, '' for default. + // Second level - diginal anchor for fast filtering by charcodes. + // + this.__cache__ = null +} + +// Helper methods, should not be used directly + +// Find rule index by name +// +Ruler.prototype.__find__ = function (name) { + for (let i = 0; i < this.__rules__.length; i++) { + if (this.__rules__[i].name === name) { + return i + } + } + return -1 +} + +// Build rules lookup cache +// +Ruler.prototype.__compile__ = function () { + const self = this + const chains = [''] + + // collect unique names + self.__rules__.forEach(function (rule) { + if (!rule.enabled) { return } + + rule.alt.forEach(function (altName) { + if (chains.indexOf(altName) < 0) { + chains.push(altName) + } + }) + }) + + self.__cache__ = {} + + chains.forEach(function (chain) { + self.__cache__[chain] = [] + self.__rules__.forEach(function (rule) { + if (!rule.enabled) { return } + + if (chain && rule.alt.indexOf(chain) < 0) { return } + + self.__cache__[chain].push(rule.fn) + }) + }) +} + +/** + * Ruler.at(name, fn [, options]) + * - name (String): rule name to replace. + * - fn (Function): new rule function. + * - options (Object): new rule options (not mandatory). + * + * Replace rule by name with new function & options. Throws error if name not + * found. + * + * ##### Options: + * + * - __alt__ - array with names of "alternate" chains. + * + * ##### Example + * + * Replace existing typographer replacement rule with new one: + * + * ```javascript + * var md = require('markdown-it')(); + * + * md.core.ruler.at('replacements', function replace(state) { + * //... + * }); + * ``` + **/ +Ruler.prototype.at = function (name, fn, options) { + const index = this.__find__(name) + const opt = options || {} + + if (index === -1) { throw new Error('Parser rule not found: ' + name) } + + this.__rules__[index].fn = fn + this.__rules__[index].alt = opt.alt || [] + this.__cache__ = null +} + +/** + * Ruler.before(beforeName, ruleName, fn [, options]) + * - beforeName (String): new rule will be added before this one. + * - ruleName (String): name of added rule. + * - fn (Function): rule function. + * - options (Object): rule options (not mandatory). + * + * Add new rule to chain before one with given name. See also + * [[Ruler.after]], [[Ruler.push]]. + * + * ##### Options: + * + * - __alt__ - array with names of "alternate" chains. + * + * ##### Example + * + * ```javascript + * var md = require('markdown-it')(); + * + * md.block.ruler.before('paragraph', 'my_rule', function replace(state) { + * //... + * }); + * ``` + **/ +Ruler.prototype.before = function (beforeName, ruleName, fn, options) { + const index = this.__find__(beforeName) + const opt = options || {} + + if (index === -1) { throw new Error('Parser rule not found: ' + beforeName) } + + this.__rules__.splice(index, 0, { + name: ruleName, + enabled: true, + fn, + alt: opt.alt || [] + }) + + this.__cache__ = null +} + +/** + * Ruler.after(afterName, ruleName, fn [, options]) + * - afterName (String): new rule will be added after this one. + * - ruleName (String): name of added rule. + * - fn (Function): rule function. + * - options (Object): rule options (not mandatory). + * + * Add new rule to chain after one with given name. See also + * [[Ruler.before]], [[Ruler.push]]. + * + * ##### Options: + * + * - __alt__ - array with names of "alternate" chains. + * + * ##### Example + * + * ```javascript + * var md = require('markdown-it')(); + * + * md.inline.ruler.after('text', 'my_rule', function replace(state) { + * //... + * }); + * ``` + **/ +Ruler.prototype.after = function (afterName, ruleName, fn, options) { + const index = this.__find__(afterName) + const opt = options || {} + + if (index === -1) { throw new Error('Parser rule not found: ' + afterName) } + + this.__rules__.splice(index + 1, 0, { + name: ruleName, + enabled: true, + fn, + alt: opt.alt || [] + }) + + this.__cache__ = null +} + +/** + * Ruler.push(ruleName, fn [, options]) + * - ruleName (String): name of added rule. + * - fn (Function): rule function. + * - options (Object): rule options (not mandatory). + * + * Push new rule to the end of chain. See also + * [[Ruler.before]], [[Ruler.after]]. + * + * ##### Options: + * + * - __alt__ - array with names of "alternate" chains. + * + * ##### Example + * + * ```javascript + * var md = require('markdown-it')(); + * + * md.core.ruler.push('my_rule', function replace(state) { + * //... + * }); + * ``` + **/ +Ruler.prototype.push = function (ruleName, fn, options) { + const opt = options || {} + + this.__rules__.push({ + name: ruleName, + enabled: true, + fn, + alt: opt.alt || [] + }) + + this.__cache__ = null +} + +/** + * Ruler.enable(list [, ignoreInvalid]) -> Array + * - list (String|Array): list of rule names to enable. + * - ignoreInvalid (Boolean): set `true` to ignore errors when rule not found. + * + * Enable rules with given names. If any rule name not found - throw Error. + * Errors can be disabled by second param. + * + * Returns list of found rule names (if no exception happened). + * + * See also [[Ruler.disable]], [[Ruler.enableOnly]]. + **/ +Ruler.prototype.enable = function (list, ignoreInvalid) { + if (!Array.isArray(list)) { list = [list] } + + const result = [] + + // Search by name and enable + list.forEach(function (name) { + const idx = this.__find__(name) + + if (idx < 0) { + if (ignoreInvalid) { return } + throw new Error('Rules manager: invalid rule name ' + name) + } + this.__rules__[idx].enabled = true + result.push(name) + }, this) + + this.__cache__ = null + return result +} + +/** + * Ruler.enableOnly(list [, ignoreInvalid]) + * - list (String|Array): list of rule names to enable (whitelist). + * - ignoreInvalid (Boolean): set `true` to ignore errors when rule not found. + * + * Enable rules with given names, and disable everything else. If any rule name + * not found - throw Error. Errors can be disabled by second param. + * + * See also [[Ruler.disable]], [[Ruler.enable]]. + **/ +Ruler.prototype.enableOnly = function (list, ignoreInvalid) { + if (!Array.isArray(list)) { list = [list] } + + this.__rules__.forEach(function (rule) { rule.enabled = false }) + + this.enable(list, ignoreInvalid) +} + +/** + * Ruler.disable(list [, ignoreInvalid]) -> Array + * - list (String|Array): list of rule names to disable. + * - ignoreInvalid (Boolean): set `true` to ignore errors when rule not found. + * + * Disable rules with given names. If any rule name not found - throw Error. + * Errors can be disabled by second param. + * + * Returns list of found rule names (if no exception happened). + * + * See also [[Ruler.enable]], [[Ruler.enableOnly]]. + **/ +Ruler.prototype.disable = function (list, ignoreInvalid) { + if (!Array.isArray(list)) { list = [list] } + + const result = [] + + // Search by name and disable + list.forEach(function (name) { + const idx = this.__find__(name) + + if (idx < 0) { + if (ignoreInvalid) { return } + throw new Error('Rules manager: invalid rule name ' + name) + } + this.__rules__[idx].enabled = false + result.push(name) + }, this) + + this.__cache__ = null + return result +} + +/** + * Ruler.getRules(chainName) -> Array + * + * Return array of active functions (rules) for given chain name. It analyzes + * rules configuration, compiles caches if not exists and returns result. + * + * Default chain name is `''` (empty string). It can't be skipped. That's + * done intentionally, to keep signature monomorphic for high speed. + **/ +Ruler.prototype.getRules = function (chainName) { + if (this.__cache__ === null) { + this.__compile__() + } + + // Chain can be empty, if rules disabled. But we still have to return Array. + return this.__cache__[chainName] || [] +} + +export default Ruler diff --git a/packages/webui/third_party/editor/markdown-it/lib/rules_block/blockquote.mjs b/packages/webui/third_party/editor/markdown-it/lib/rules_block/blockquote.mjs new file mode 100644 index 000000000..4ac80be7d --- /dev/null +++ b/packages/webui/third_party/editor/markdown-it/lib/rules_block/blockquote.mjs @@ -0,0 +1,209 @@ +// Block quotes + +import { isSpace } from '../common/utils.mjs' + +export default function blockquote (state, startLine, endLine, silent) { + let pos = state.bMarks[startLine] + state.tShift[startLine] + let max = state.eMarks[startLine] + + const oldLineMax = state.lineMax + + // if it's indented more than 3 spaces, it should be a code block + if (state.sCount[startLine] - state.blkIndent >= 4) { return false } + + // check the block quote marker + if (state.src.charCodeAt(pos) !== 0x3E/* > */) { return false } + + // we know that it's going to be a valid blockquote, + // so no point trying to find the end of it in silent mode + if (silent) { return true } + + const oldBMarks = [] + const oldBSCount = [] + const oldSCount = [] + const oldTShift = [] + + const terminatorRules = state.md.block.ruler.getRules('blockquote') + + const oldParentType = state.parentType + state.parentType = 'blockquote' + let lastLineEmpty = false + let nextLine + + // Search the end of the block + // + // Block ends with either: + // 1. an empty line outside: + // ``` + // > test + // + // ``` + // 2. an empty line inside: + // ``` + // > + // test + // ``` + // 3. another tag: + // ``` + // > test + // - - - + // ``` + for (nextLine = startLine; nextLine < endLine; nextLine++) { + // check if it's outdented, i.e. it's inside list item and indented + // less than said list item: + // + // ``` + // 1. anything + // > current blockquote + // 2. checking this line + // ``` + const isOutdented = state.sCount[nextLine] < state.blkIndent + + pos = state.bMarks[nextLine] + state.tShift[nextLine] + max = state.eMarks[nextLine] + + if (pos >= max) { + // Case 1: line is not inside the blockquote, and this line is empty. + break + } + + if (state.src.charCodeAt(pos++) === 0x3E/* > */ && !isOutdented) { + // This line is inside the blockquote. + + // set offset past spaces and ">" + let initial = state.sCount[nextLine] + 1 + let spaceAfterMarker + let adjustTab + + // skip one optional space after '>' + if (state.src.charCodeAt(pos) === 0x20 /* space */) { + // ' > test ' + // ^ -- position start of line here: + pos++ + initial++ + adjustTab = false + spaceAfterMarker = true + } else if (state.src.charCodeAt(pos) === 0x09 /* tab */) { + spaceAfterMarker = true + + if ((state.bsCount[nextLine] + initial) % 4 === 3) { + // ' >\t test ' + // ^ -- position start of line here (tab has width===1) + pos++ + initial++ + adjustTab = false + } else { + // ' >\t test ' + // ^ -- position start of line here + shift bsCount slightly + // to make extra space appear + adjustTab = true + } + } else { + spaceAfterMarker = false + } + + let offset = initial + oldBMarks.push(state.bMarks[nextLine]) + state.bMarks[nextLine] = pos + + while (pos < max) { + const ch = state.src.charCodeAt(pos) + + if (isSpace(ch)) { + if (ch === 0x09) { + offset += 4 - (offset + state.bsCount[nextLine] + (adjustTab ? 1 : 0)) % 4 + } else { + offset++ + } + } else { + break + } + + pos++ + } + + lastLineEmpty = pos >= max + + oldBSCount.push(state.bsCount[nextLine]) + state.bsCount[nextLine] = state.sCount[nextLine] + 1 + (spaceAfterMarker ? 1 : 0) + + oldSCount.push(state.sCount[nextLine]) + state.sCount[nextLine] = offset - initial + + oldTShift.push(state.tShift[nextLine]) + state.tShift[nextLine] = pos - state.bMarks[nextLine] + continue + } + + // Case 2: line is not inside the blockquote, and the last line was empty. + if (lastLineEmpty) { break } + + // Case 3: another tag found. + let terminate = false + for (let i = 0, l = terminatorRules.length; i < l; i++) { + if (terminatorRules[i](state, nextLine, endLine, true)) { + terminate = true + break + } + } + + if (terminate) { + // Quirk to enforce "hard termination mode" for paragraphs; + // normally if you call `tokenize(state, startLine, nextLine)`, + // paragraphs will look below nextLine for paragraph continuation, + // but if blockquote is terminated by another tag, they shouldn't + state.lineMax = nextLine + + if (state.blkIndent !== 0) { + // state.blkIndent was non-zero, we now set it to zero, + // so we need to re-calculate all offsets to appear as + // if indent wasn't changed + oldBMarks.push(state.bMarks[nextLine]) + oldBSCount.push(state.bsCount[nextLine]) + oldTShift.push(state.tShift[nextLine]) + oldSCount.push(state.sCount[nextLine]) + state.sCount[nextLine] -= state.blkIndent + } + + break + } + + oldBMarks.push(state.bMarks[nextLine]) + oldBSCount.push(state.bsCount[nextLine]) + oldTShift.push(state.tShift[nextLine]) + oldSCount.push(state.sCount[nextLine]) + + // A negative indentation means that this is a paragraph continuation + // + state.sCount[nextLine] = -1 + } + + const oldIndent = state.blkIndent + state.blkIndent = 0 + + const token_o = state.push('blockquote_open', 'blockquote', 1) + token_o.markup = '>' + const lines = [startLine, 0] + token_o.map = lines + + state.md.block.tokenize(state, startLine, nextLine) + + const token_c = state.push('blockquote_close', 'blockquote', -1) + token_c.markup = '>' + + state.lineMax = oldLineMax + state.parentType = oldParentType + lines[1] = state.line + + // Restore original tShift; this might not be necessary since the parser + // has already been here, but just to make sure we can do that. + for (let i = 0; i < oldTShift.length; i++) { + state.bMarks[i + startLine] = oldBMarks[i] + state.tShift[i + startLine] = oldTShift[i] + state.sCount[i + startLine] = oldSCount[i] + state.bsCount[i + startLine] = oldBSCount[i] + } + state.blkIndent = oldIndent + + return true +} diff --git a/packages/webui/third_party/editor/markdown-it/lib/rules_block/code.mjs b/packages/webui/third_party/editor/markdown-it/lib/rules_block/code.mjs new file mode 100644 index 000000000..27d608c0f --- /dev/null +++ b/packages/webui/third_party/editor/markdown-it/lib/rules_block/code.mjs @@ -0,0 +1,30 @@ +// Code block (4 spaces padded) + +export default function code (state, startLine, endLine/*, silent */) { + if (state.sCount[startLine] - state.blkIndent < 4) { return false } + + let nextLine = startLine + 1 + let last = nextLine + + while (nextLine < endLine) { + if (state.isEmpty(nextLine)) { + nextLine++ + continue + } + + if (state.sCount[nextLine] - state.blkIndent >= 4) { + nextLine++ + last = nextLine + continue + } + break + } + + state.line = last + + const token = state.push('code_block', 'code', 0) + token.content = state.getLines(startLine, last, 4 + state.blkIndent, false) + '\n' + token.map = [startLine, state.line] + + return true +} diff --git a/packages/webui/third_party/editor/markdown-it/lib/rules_block/fence.mjs b/packages/webui/third_party/editor/markdown-it/lib/rules_block/fence.mjs new file mode 100644 index 000000000..e78f70d71 --- /dev/null +++ b/packages/webui/third_party/editor/markdown-it/lib/rules_block/fence.mjs @@ -0,0 +1,94 @@ +// fences (``` lang, ~~~ lang) + +export default function fence (state, startLine, endLine, silent) { + let pos = state.bMarks[startLine] + state.tShift[startLine] + let max = state.eMarks[startLine] + + // if it's indented more than 3 spaces, it should be a code block + if (state.sCount[startLine] - state.blkIndent >= 4) { return false } + + if (pos + 3 > max) { return false } + + const marker = state.src.charCodeAt(pos) + + if (marker !== 0x7E/* ~ */ && marker !== 0x60 /* ` */) { + return false + } + + // scan marker length + let mem = pos + pos = state.skipChars(pos, marker) + + let len = pos - mem + + if (len < 3) { return false } + + const markup = state.src.slice(mem, pos) + const params = state.src.slice(pos, max) + + if (marker === 0x60 /* ` */) { + if (params.indexOf(String.fromCharCode(marker)) >= 0) { + return false + } + } + + // Since start is found, we can report success here in validation mode + if (silent) { return true } + + // search end of block + let nextLine = startLine + let haveEndMarker = false + + for (;;) { + nextLine++ + if (nextLine >= endLine) { + // unclosed block should be autoclosed by end of document. + // also block seems to be autoclosed by end of parent + break + } + + pos = mem = state.bMarks[nextLine] + state.tShift[nextLine] + max = state.eMarks[nextLine] + + if (pos < max && state.sCount[nextLine] < state.blkIndent) { + // non-empty line with negative indent should stop the list: + // - ``` + // test + break + } + + if (state.src.charCodeAt(pos) !== marker) { continue } + + if (state.sCount[nextLine] - state.blkIndent >= 4) { + // closing fence should be indented less than 4 spaces + continue + } + + pos = state.skipChars(pos, marker) + + // closing code fence must be at least as long as the opening one + if (pos - mem < len) { continue } + + // make sure tail has spaces only + pos = state.skipSpaces(pos) + + if (pos < max) { continue } + + haveEndMarker = true + // found! + break + } + + // If a fence has heading spaces, they should be removed from its inner block + len = state.sCount[startLine] + + state.line = nextLine + (haveEndMarker ? 1 : 0) + + const token = state.push('fence', 'code', 0) + token.info = params + token.content = state.getLines(startLine + 1, nextLine, len, true) + token.markup = markup + token.map = [startLine, state.line] + + return true +} diff --git a/packages/webui/third_party/editor/markdown-it/lib/rules_block/heading.mjs b/packages/webui/third_party/editor/markdown-it/lib/rules_block/heading.mjs new file mode 100644 index 000000000..e4fbff735 --- /dev/null +++ b/packages/webui/third_party/editor/markdown-it/lib/rules_block/heading.mjs @@ -0,0 +1,51 @@ +// heading (#, ##, ...) + +import { isSpace, asciiTrim } from '../common/utils.mjs' + +export default function heading (state, startLine, endLine, silent) { + let pos = state.bMarks[startLine] + state.tShift[startLine] + let max = state.eMarks[startLine] + + // if it's indented more than 3 spaces, it should be a code block + if (state.sCount[startLine] - state.blkIndent >= 4) { return false } + + let ch = state.src.charCodeAt(pos) + + if (ch !== 0x23/* # */ || pos >= max) { return false } + + // count heading level + let level = 1 + ch = state.src.charCodeAt(++pos) + while (ch === 0x23/* # */ && pos < max && level <= 6) { + level++ + ch = state.src.charCodeAt(++pos) + } + + if (level > 6 || (pos < max && !isSpace(ch))) { return false } + + if (silent) { return true } + + // Let's cut tails like ' ### ' from the end of string + + max = state.skipSpacesBack(max, pos) + const tmp = state.skipCharsBack(max, 0x23, pos) // # + if (tmp > pos && isSpace(state.src.charCodeAt(tmp - 1))) { + max = tmp + } + + state.line = startLine + 1 + + const token_o = state.push('heading_open', 'h' + String(level), 1) + token_o.markup = '########'.slice(0, level) + token_o.map = [startLine, state.line] + + const token_i = state.push('inline', '', 0) + token_i.content = asciiTrim(state.src.slice(pos, max)) + token_i.map = [startLine, state.line] + token_i.children = [] + + const token_c = state.push('heading_close', 'h' + String(level), -1) + token_c.markup = '########'.slice(0, level) + + return true +} diff --git a/packages/webui/third_party/editor/markdown-it/lib/rules_block/hr.mjs b/packages/webui/third_party/editor/markdown-it/lib/rules_block/hr.mjs new file mode 100644 index 000000000..bc174af38 --- /dev/null +++ b/packages/webui/third_party/editor/markdown-it/lib/rules_block/hr.mjs @@ -0,0 +1,40 @@ +// Horizontal rule + +import { isSpace } from '../common/utils.mjs' + +export default function hr (state, startLine, endLine, silent) { + const max = state.eMarks[startLine] + // if it's indented more than 3 spaces, it should be a code block + if (state.sCount[startLine] - state.blkIndent >= 4) { return false } + + let pos = state.bMarks[startLine] + state.tShift[startLine] + const marker = state.src.charCodeAt(pos++) + + // Check hr marker + if (marker !== 0x2A/* * */ && + marker !== 0x2D/* - */ && + marker !== 0x5F/* _ */) { + return false + } + + // markers can be mixed with spaces, but there should be at least 3 of them + + let cnt = 1 + while (pos < max) { + const ch = state.src.charCodeAt(pos++) + if (ch !== marker && !isSpace(ch)) { return false } + if (ch === marker) { cnt++ } + } + + if (cnt < 3) { return false } + + if (silent) { return true } + + state.line = startLine + 1 + + const token = state.push('hr', 'hr', 0) + token.map = [startLine, state.line] + token.markup = Array(cnt + 1).join(String.fromCharCode(marker)) + + return true +} diff --git a/packages/webui/third_party/editor/markdown-it/lib/rules_block/html_block.mjs b/packages/webui/third_party/editor/markdown-it/lib/rules_block/html_block.mjs new file mode 100644 index 000000000..a27a29180 --- /dev/null +++ b/packages/webui/third_party/editor/markdown-it/lib/rules_block/html_block.mjs @@ -0,0 +1,80 @@ +// HTML block + +import block_names from '../common/html_blocks.mjs' +import { HTML_OPEN_CLOSE_TAG_RE } from '../common/html_re.mjs' + +// An array of opening and corresponding closing sequences for html tags, +// last argument defines whether it can terminate a paragraph or not +// +const HTML_SEQUENCES = [ + [/^<(script|pre|style|textarea)(?=(\s|>|$))/i, /<\/(script|pre|style|textarea)>/i, true], + [/^/, true], + [/^<\?/, /\?>/, true], + [/^/, true], + [/^/, true], + [new RegExp('^|$))', 'i'), /^$/, true], + [new RegExp(HTML_OPEN_CLOSE_TAG_RE.source + '\\s*$'), /^$/, false] +] + +export default function html_block (state, startLine, endLine, silent) { + let pos = state.bMarks[startLine] + state.tShift[startLine] + let max = state.eMarks[startLine] + + // if it's indented more than 3 spaces, it should be a code block + if (state.sCount[startLine] - state.blkIndent >= 4) { return false } + + if (!state.md.options.html) { return false } + + if (state.src.charCodeAt(pos) !== 0x3C/* < */) { return false } + + let lineText = state.src.slice(pos, max) + + let i = 0 + for (; i < HTML_SEQUENCES.length; i++) { + if (HTML_SEQUENCES[i][0].test(lineText)) { break } + } + if (i === HTML_SEQUENCES.length) { return false } + + if (silent) { + // true if this sequence can be a terminator, false otherwise + return HTML_SEQUENCES[i][2] + } + + let nextLine = startLine + 1 + + // Block types 6 and 7 (the only ones whose end condition is a blank line) + // have `/^$/` as their closing regexp. For all other types (1-5, e.g. + // `' + } else if (src.startsWith('' + } else if (src.charCodeAt(pos + 1) === 0x3F/* ? */) { + start = pos + 2 + terminator = '?>' + } else if (isLetter(src.charCodeAt(pos + 2))) { + start = pos + 3 + terminator = '>' + } else { + return -1 + } + + if (state.skipHtmlSpecial) { return -1 } + + const end = src.indexOf(terminator, start) + if (end < 0) { + // One flag for all constructs to keep code simple. Valid constructs after + // an unclosed one in the same paragraph become text, that's acceptable. + state.skipHtmlSpecial = true + return -1 + } + return end + terminator.length +} + +export default function html_inline (state, silent) { + if (!state.md.options.html) { return false } + + // Check start + const max = state.posMax + const pos = state.pos + if (state.src.charCodeAt(pos) !== 0x3C/* < */ || + pos + 2 >= max) { + return false + } + + let end + const ch = state.src.charCodeAt(pos + 1) + + if (ch === 0x21/* ! */ || ch === 0x3F/* ? */) { + end = scanSpecial(state, pos) + } else if (ch === 0x2F/* / */ || isLetter(ch)) { + const match = state.src.slice(pos).match(HTML_OPEN_CLOSE_TAG_RE) + end = match ? pos + match[0].length : -1 + } else { + return false + } + + if (end < 0) { return false } + + if (!silent) { + const token = state.push('html_inline', '', 0) + token.content = state.src.slice(pos, end) + + if (isLinkOpen(token.content)) state.linkLevel++ + if (isLinkClose(token.content)) state.linkLevel-- + } + state.pos = end + return true +} diff --git a/packages/webui/third_party/editor/markdown-it/lib/rules_inline/image.mjs b/packages/webui/third_party/editor/markdown-it/lib/rules_inline/image.mjs new file mode 100644 index 000000000..32cbb3111 --- /dev/null +++ b/packages/webui/third_party/editor/markdown-it/lib/rules_inline/image.mjs @@ -0,0 +1,138 @@ +// Process ![image]( "title") + +import { normalizeReference, isSpace } from '../common/utils.mjs' + +export default function image (state, silent) { + let code, content, label, pos, ref, res, title, start + let href = '' + const oldPos = state.pos + const max = state.posMax + + if (state.src.charCodeAt(state.pos) !== 0x21/* ! */) { return false } + if (state.src.charCodeAt(state.pos + 1) !== 0x5B/* [ */) { return false } + + const labelStart = state.pos + 2 + const labelEnd = state.md.helpers.parseLinkLabel(state, state.pos + 1, false) + + // parser failed to find ']', so it's not a valid link + if (labelEnd < 0) { return false } + + pos = labelEnd + 1 + if (pos < max && state.src.charCodeAt(pos) === 0x28/* ( */) { + // + // Inline link + // + + // [link]( "title" ) + // ^^ skipping these spaces + pos++ + for (; pos < max; pos++) { + code = state.src.charCodeAt(pos) + if (!isSpace(code) && code !== 0x0A) { break } + } + if (pos >= max) { return false } + + // [link]( "title" ) + // ^^^^^^ parsing link destination + start = pos + res = state.md.helpers.parseLinkDestination(state.src, pos, state.posMax) + if (res.ok) { + href = state.md.normalizeLink(res.str) + if (state.md.validateLink(href)) { + pos = res.pos + } else { + href = '' + } + } + + // [link]( "title" ) + // ^^ skipping these spaces + start = pos + for (; pos < max; pos++) { + code = state.src.charCodeAt(pos) + if (!isSpace(code) && code !== 0x0A) { break } + } + + // [link]( "title" ) + // ^^^^^^^ parsing link title + res = state.md.helpers.parseLinkTitle(state.src, pos, state.posMax) + if (pos < max && start !== pos && res.ok) { + title = res.str + pos = res.pos + + // [link]( "title" ) + // ^^ skipping these spaces + for (; pos < max; pos++) { + code = state.src.charCodeAt(pos) + if (!isSpace(code) && code !== 0x0A) { break } + } + } else { + title = '' + } + + if (pos >= max || state.src.charCodeAt(pos) !== 0x29/* ) */) { + state.pos = oldPos + return false + } + pos++ + } else { + // + // Link reference + // + if (typeof state.env.references === 'undefined') { return false } + + if (pos < max && state.src.charCodeAt(pos) === 0x5B/* [ */) { + start = pos + 1 + pos = state.md.helpers.parseLinkLabel(state, pos) + if (pos >= 0) { + label = state.src.slice(start, pos++) + } else { + pos = labelEnd + 1 + } + } else { + pos = labelEnd + 1 + } + + // covers label === '' and label === undefined + // (collapsed reference link and shortcut reference link respectively) + if (!label) { label = state.src.slice(labelStart, labelEnd) } + + ref = state.env.references[normalizeReference(label)] + if (!ref) { + state.pos = oldPos + return false + } + href = ref.href + title = ref.title + } + + // + // We found the end of the link, and know for a fact it's a valid link; + // so all that's left to do is to call tokenizer. + // + if (!silent) { + content = state.src.slice(labelStart, labelEnd) + + const tokens = [] + state.md.inline.parse( + content, + state.md, + state.env, + tokens + ) + + const token = state.push('image', 'img', 0) + const attrs = [['src', href], ['alt', '']] + token.attrs = attrs + token.children = tokens + token.content = content + + if (title) { + attrs.push(['title', title]) + } + } + + state.pos = pos + state.posMax = max + return true +} diff --git a/packages/webui/third_party/editor/markdown-it/lib/rules_inline/link.mjs b/packages/webui/third_party/editor/markdown-it/lib/rules_inline/link.mjs new file mode 100644 index 000000000..a6e276510 --- /dev/null +++ b/packages/webui/third_party/editor/markdown-it/lib/rules_inline/link.mjs @@ -0,0 +1,139 @@ +// Process [link]( "stuff") + +import { normalizeReference, isSpace } from '../common/utils.mjs' + +export default function link (state, silent) { + let code, label, res, ref + let href = '' + let title = '' + let start = state.pos + let parseReference = true + + if (state.src.charCodeAt(state.pos) !== 0x5B/* [ */) { return false } + + const oldPos = state.pos + const max = state.posMax + const labelStart = state.pos + 1 + const labelEnd = state.md.helpers.parseLinkLabel(state, state.pos, true) + + // parser failed to find ']', so it's not a valid link + if (labelEnd < 0) { return false } + + let pos = labelEnd + 1 + if (pos < max && state.src.charCodeAt(pos) === 0x28/* ( */) { + // + // Inline link + // + + // might have found a valid shortcut link, disable reference parsing + parseReference = false + + // [link]( "title" ) + // ^^ skipping these spaces + pos++ + for (; pos < max; pos++) { + code = state.src.charCodeAt(pos) + if (!isSpace(code) && code !== 0x0A) { break } + } + if (pos >= max) { return false } + + // [link]( "title" ) + // ^^^^^^ parsing link destination + start = pos + res = state.md.helpers.parseLinkDestination(state.src, pos, state.posMax) + if (res.ok) { + href = state.md.normalizeLink(res.str) + if (state.md.validateLink(href)) { + pos = res.pos + } else { + href = '' + } + + // [link]( "title" ) + // ^^ skipping these spaces + start = pos + for (; pos < max; pos++) { + code = state.src.charCodeAt(pos) + if (!isSpace(code) && code !== 0x0A) { break } + } + + // [link]( "title" ) + // ^^^^^^^ parsing link title + res = state.md.helpers.parseLinkTitle(state.src, pos, state.posMax) + if (pos < max && start !== pos && res.ok) { + title = res.str + pos = res.pos + + // [link]( "title" ) + // ^^ skipping these spaces + for (; pos < max; pos++) { + code = state.src.charCodeAt(pos) + if (!isSpace(code) && code !== 0x0A) { break } + } + } + } + + if (pos >= max || state.src.charCodeAt(pos) !== 0x29/* ) */) { + // parsing a valid shortcut link failed, fallback to reference + parseReference = true + } + pos++ + } + + if (parseReference) { + // + // Link reference + // + if (typeof state.env.references === 'undefined') { return false } + + if (pos < max && state.src.charCodeAt(pos) === 0x5B/* [ */) { + start = pos + 1 + pos = state.md.helpers.parseLinkLabel(state, pos) + if (pos >= 0) { + label = state.src.slice(start, pos++) + } else { + pos = labelEnd + 1 + } + } else { + pos = labelEnd + 1 + } + + // covers label === '' and label === undefined + // (collapsed reference link and shortcut reference link respectively) + if (!label) { label = state.src.slice(labelStart, labelEnd) } + + ref = state.env.references[normalizeReference(label)] + if (!ref) { + state.pos = oldPos + return false + } + href = ref.href + title = ref.title + } + + // + // We found the end of the link, and know for a fact it's a valid link; + // so all that's left to do is to call tokenizer. + // + if (!silent) { + state.pos = labelStart + state.posMax = labelEnd + + const token_o = state.push('link_open', 'a', 1) + const attrs = [['href', href]] + token_o.attrs = attrs + if (title) { + attrs.push(['title', title]) + } + + state.linkLevel++ + state.md.inline.tokenize(state) + state.linkLevel-- + + state.push('link_close', 'a', -1) + } + + state.pos = pos + state.posMax = max + return true +} diff --git a/packages/webui/third_party/editor/markdown-it/lib/rules_inline/linkify.mjs b/packages/webui/third_party/editor/markdown-it/lib/rules_inline/linkify.mjs new file mode 100644 index 000000000..dcda6a877 --- /dev/null +++ b/packages/webui/third_party/editor/markdown-it/lib/rules_inline/linkify.mjs @@ -0,0 +1,81 @@ +// Early process links like https://example.org/ to have priority +// over emphasis, etc. + +// RFC3986: scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) +function isAsciiAlpha (code) { + return (code >= 0x41 && code <= 0x5A) || (code >= 0x61 && code <= 0x7A) +} + +function isSchemeChar (code) { + return (code >= 0x41 && code <= 0x5A) || + (code >= 0x61 && code <= 0x7A) || + (code >= 0x30 && code <= 0x39) || + code === 0x2B || code === 0x2D || code === 0x2E +} + +export default function linkify (state, silent) { + if (!state.md.options.linkify) return false + if (state.linkLevel > 0) return false + + const pos = state.pos + const max = state.posMax + + if (pos + 3 > max) return false + if (state.src.charCodeAt(pos) !== 0x3A/* : */) return false + if (state.src.charCodeAt(pos + 1) !== 0x2F/* / */) return false + if (state.src.charCodeAt(pos + 2) !== 0x2F/* / */) return false + + // Search backwards for the scheme, but no more than 10 characters, the length + // of the pending string, or the length of the source prefix. + // Use state.src instead of state.pending because it is faster to access. + const protoMin = pos - Math.min(10, state.pending.length, pos) + let protoStart = pos + while (protoStart > protoMin && isSchemeChar(state.src.charCodeAt(protoStart - 1))) { + protoStart-- + } + + if (protoStart === pos || !isAsciiAlpha(state.src.charCodeAt(protoStart))) return false + + const protoLength = pos - protoStart + + const link = state.md.linkify.matchAtStart(state.src.slice(protoStart)) + if (!link) return false + + let url = link.url + + // invalid link, but still detected by linkify somehow; + // need to check to prevent infinite loop below + if (url.length <= protoLength) return false + + // disallow '*' at the end of the link (conflicts with emphasis) + // do manual backsearch to avoid perf issues with regex /\*+$/ on "****...****a". + let urlEnd = url.length + while (urlEnd > 0 && url.charCodeAt(urlEnd - 1) === 0x2A/* * */) { + urlEnd-- + } + if (urlEnd !== url.length) { + url = url.slice(0, urlEnd) + } + + const fullUrl = state.md.normalizeLink(url) + if (!state.md.validateLink(fullUrl)) return false + + if (!silent) { + state.pending = state.pending.slice(0, -protoLength) + + const token_o = state.push('link_open', 'a', 1) + token_o.attrs = [['href', fullUrl]] + token_o.markup = 'linkify' + token_o.info = 'auto' + + const token_t = state.push('text', '', 0) + token_t.content = state.md.normalizeLinkText(url) + + const token_c = state.push('link_close', 'a', -1) + token_c.markup = 'linkify' + token_c.info = 'auto' + } + + state.pos += url.length - protoLength + return true +} diff --git a/packages/webui/third_party/editor/markdown-it/lib/rules_inline/newline.mjs b/packages/webui/third_party/editor/markdown-it/lib/rules_inline/newline.mjs new file mode 100644 index 000000000..2c0e3ae7e --- /dev/null +++ b/packages/webui/third_party/editor/markdown-it/lib/rules_inline/newline.mjs @@ -0,0 +1,42 @@ +// Proceess '\n' + +import { isSpace } from '../common/utils.mjs' + +export default function newline (state, silent) { + let pos = state.pos + + if (state.src.charCodeAt(pos) !== 0x0A/* \n */) { return false } + + const pmax = state.pending.length - 1 + const max = state.posMax + + // ' \n' -> hardbreak + // Lookup in pending chars is bad practice! Don't copy to other rules! + // Pending string is stored in concat mode, indexed lookups will cause + // convertion to flat mode. + if (!silent) { + if (pmax >= 0 && state.pending.charCodeAt(pmax) === 0x20) { + if (pmax >= 1 && state.pending.charCodeAt(pmax - 1) === 0x20) { + // Find whitespaces tail of pending chars. + let ws = pmax - 1 + while (ws >= 1 && state.pending.charCodeAt(ws - 1) === 0x20) ws-- + + state.pending = state.pending.slice(0, ws) + state.push('hardbreak', 'br', 0) + } else { + state.pending = state.pending.slice(0, -1) + state.push('softbreak', 'br', 0) + } + } else { + state.push('softbreak', 'br', 0) + } + } + + pos++ + + // skip heading spaces for next line + while (pos < max && isSpace(state.src.charCodeAt(pos))) { pos++ } + + state.pos = pos + return true +} diff --git a/packages/webui/third_party/editor/markdown-it/lib/rules_inline/state_inline.mjs b/packages/webui/third_party/editor/markdown-it/lib/rules_inline/state_inline.mjs new file mode 100644 index 000000000..c496317a3 --- /dev/null +++ b/packages/webui/third_party/editor/markdown-it/lib/rules_inline/state_inline.mjs @@ -0,0 +1,158 @@ +// Inline parser state + +import Token from '../token.mjs' +import { isWhiteSpace, isPunctCharCode, isMdAsciiPunct } from '../common/utils.mjs' + +function StateInline (src, md, env, outTokens) { + this.src = src + this.env = env + this.md = md + this.tokens = outTokens + this.tokens_meta = Array(outTokens.length) + + this.pos = 0 + this.posMax = this.src.length + this.level = 0 + this.pending = '' + this.pendingLevel = 0 + + // Stores { start: end } pairs. Useful for backtrack + // optimization of pairs parse (emphasis, strikes). + this.cache = {} + + // List of emphasis-like delimiters for current tag + this.delimiters = [] + + // Stack of delimiter lists for upper level tags + this._prev_delimiters = [] + + // backtick length => last seen position + this.backticks = {} + this.backticksScanned = false + + // Set when html comment / PI / declaration / CDATA has no terminator, + // to skip further scans of these constructs + this.skipHtmlSpecial = false + + // Counter used to disable inline linkify-it execution + // inside and markdown links + this.linkLevel = 0 +} + +// Flush pending text +// +StateInline.prototype.pushPending = function () { + const token = new Token('text', '', 0) + token.content = this.pending + token.level = this.pendingLevel + this.tokens.push(token) + this.pending = '' + return token +} + +// Push new token to "stream". +// If pending text exists - flush it as text token +// +StateInline.prototype.push = function (type, tag, nesting) { + if (this.pending) { + this.pushPending() + } + + const token = new Token(type, tag, nesting) + let token_meta = null + + if (nesting < 0) { + // closing tag + this.level-- + this.delimiters = this._prev_delimiters.pop() + } + + token.level = this.level + + if (nesting > 0) { + // opening tag + this.level++ + this._prev_delimiters.push(this.delimiters) + this.delimiters = [] + token_meta = { delimiters: this.delimiters } + } + + this.pendingLevel = this.level + this.tokens.push(token) + this.tokens_meta.push(token_meta) + return token +} + +// Scan a sequence of emphasis-like markers, and determine whether +// it can start an emphasis sequence or end an emphasis sequence. +// +// - start - position to scan from (it should point at a valid marker); +// - canSplitWord - determine if these markers can be found inside a word +// +StateInline.prototype.scanDelims = function (start, canSplitWord) { + const max = this.posMax + const marker = this.src.charCodeAt(start) + + // Astral characters below are combined manually, because .codePointAt() + // does not guarantee numeric type output. And we don't wish JIT cache issues. + // The broken surrogate pairs are evaluated as U+FFFD to prevent possible + // crashes. + + let lastChar + if (start === 0) { + // treat beginning of the line as a whitespace + lastChar = 0x20 + } else if (start === 1) { + lastChar = this.src.charCodeAt(0) + if ((lastChar & 0xF800) === 0xD800) { lastChar = 0xFFFD } + } else { + lastChar = this.src.charCodeAt(start - 1) + if ((lastChar & 0xFC00) === 0xDC00) { + // low surrogate => add high one, replace broken pair with U+FFFD + const highSurr = this.src.charCodeAt(start - 2) + lastChar = (highSurr & 0xFC00) === 0xD800 + ? 0x10000 + ((highSurr - 0xD800) << 10) + (lastChar - 0xDC00) + : 0xFFFD + } else if ((lastChar & 0xFC00) === 0xD800) { + lastChar = 0xFFFD + } + } + + let pos = start + while (pos < max && this.src.charCodeAt(pos) === marker) { pos++ } + + const count = pos - start + + // treat end of the line as a whitespace + let nextChar = pos < max ? this.src.charCodeAt(pos) : 0x20 + if ((nextChar & 0xFC00) === 0xD800) { + // high surrogate => add low one, replace broken pair with U+FFFD + const lowSurr = this.src.charCodeAt(pos + 1) + nextChar = (lowSurr & 0xFC00) === 0xDC00 + ? 0x10000 + ((nextChar - 0xD800) << 10) + (lowSurr - 0xDC00) + : 0xFFFD + } else if ((nextChar & 0xFC00) === 0xDC00) { + nextChar = 0xFFFD + } + + const isLastPunctChar = isMdAsciiPunct(lastChar) || isPunctCharCode(lastChar) + const isNextPunctChar = isMdAsciiPunct(nextChar) || isPunctCharCode(nextChar) + + const isLastWhiteSpace = isWhiteSpace(lastChar) + const isNextWhiteSpace = isWhiteSpace(nextChar) + + const left_flanking = + !isNextWhiteSpace && (!isNextPunctChar || isLastWhiteSpace || isLastPunctChar) + const right_flanking = + !isLastWhiteSpace && (!isLastPunctChar || isNextWhiteSpace || isNextPunctChar) + + const can_open = left_flanking && (canSplitWord || !right_flanking || isLastPunctChar) + const can_close = right_flanking && (canSplitWord || !left_flanking || isNextPunctChar) + + return { can_open, can_close, length: count } +} + +// re-export Token class to use in block rules +StateInline.prototype.Token = Token + +export default StateInline diff --git a/packages/webui/third_party/editor/markdown-it/lib/rules_inline/strikethrough.mjs b/packages/webui/third_party/editor/markdown-it/lib/rules_inline/strikethrough.mjs new file mode 100644 index 000000000..6baaff6bd --- /dev/null +++ b/packages/webui/third_party/editor/markdown-it/lib/rules_inline/strikethrough.mjs @@ -0,0 +1,127 @@ +// ~~strike through~~ +// + +// Insert each marker as a separate text token, and add it to delimiter list +// +function strikethrough_tokenize (state, silent) { + const start = state.pos + const marker = state.src.charCodeAt(start) + + if (silent) { return false } + + if (marker !== 0x7E/* ~ */) { return false } + + const scanned = state.scanDelims(state.pos, true) + let len = scanned.length + const ch = String.fromCharCode(marker) + + if (len < 2) { return false } + + let token + + if (len % 2) { + token = state.push('text', '', 0) + token.content = ch + len-- + } + + for (let i = 0; i < len; i += 2) { + token = state.push('text', '', 0) + token.content = ch + ch + + state.delimiters.push({ + marker, + length: 0, // disable "rule of 3" length checks meant for emphasis + token: state.tokens.length - 1, + end: -1, + open: scanned.can_open, + close: scanned.can_close + }) + } + + state.pos += scanned.length + + return true +} + +function postProcess (state, delimiters) { + let token + const loneMarkers = [] + const max = delimiters.length + + for (let i = 0; i < max; i++) { + const startDelim = delimiters[i] + + if (startDelim.marker !== 0x7E/* ~ */) { + continue + } + + if (startDelim.end === -1) { + continue + } + + const endDelim = delimiters[startDelim.end] + + token = state.tokens[startDelim.token] + token.type = 's_open' + token.tag = 's' + token.nesting = 1 + token.markup = '~~' + token.content = '' + + token = state.tokens[endDelim.token] + token.type = 's_close' + token.tag = 's' + token.nesting = -1 + token.markup = '~~' + token.content = '' + + if (state.tokens[endDelim.token - 1].type === 'text' && + state.tokens[endDelim.token - 1].content === '~') { + loneMarkers.push(endDelim.token - 1) + } + } + + // If a marker sequence has an odd number of characters, it's splitted + // like this: `~~~~~` -> `~` + `~~` + `~~`, leaving one marker at the + // start of the sequence. + // + // So, we have to move all those markers after subsequent s_close tags. + // + while (loneMarkers.length) { + const i = loneMarkers.pop() + let j = i + 1 + + while (j < state.tokens.length && state.tokens[j].type === 's_close') { + j++ + } + + j-- + + if (i !== j) { + token = state.tokens[j] + state.tokens[j] = state.tokens[i] + state.tokens[i] = token + } + } +} + +// Walk through delimiter list and replace text tokens with tags +// +function strikethrough_postProcess (state) { + const tokens_meta = state.tokens_meta + const max = state.tokens_meta.length + + postProcess(state, state.delimiters) + + for (let curr = 0; curr < max; curr++) { + if (tokens_meta[curr] && tokens_meta[curr].delimiters) { + postProcess(state, tokens_meta[curr].delimiters) + } + } +} + +export default { + tokenize: strikethrough_tokenize, + postProcess: strikethrough_postProcess +} diff --git a/packages/webui/third_party/editor/markdown-it/lib/rules_inline/text.mjs b/packages/webui/third_party/editor/markdown-it/lib/rules_inline/text.mjs new file mode 100644 index 000000000..9be42274c --- /dev/null +++ b/packages/webui/third_party/editor/markdown-it/lib/rules_inline/text.mjs @@ -0,0 +1,86 @@ +// Skip text characters for text token, place those to pending buffer +// and increment current pos + +// Rule to skip pure text +// '{}$%@~+=:' reserved for extentions + +// !, ", #, $, %, &, ', (, ), *, +, ,, -, ., /, :, ;, <, =, >, ?, @, [, \, ], ^, _, `, {, |, }, or ~ + +// !!!! Don't confuse with "Markdown ASCII Punctuation" chars +// http://spec.commonmark.org/0.15/#ascii-punctuation-character +function isTerminatorChar (ch) { + switch (ch) { + case 0x0A/* \n */: + case 0x21/* ! */: + case 0x23/* # */: + case 0x24/* $ */: + case 0x25/* % */: + case 0x26/* & */: + case 0x2A/* * */: + case 0x2B/* + */: + case 0x2D/* - */: + case 0x3A/* : */: + case 0x3C/* < */: + case 0x3D/* = */: + case 0x3E/* > */: + case 0x40/* @ */: + case 0x5B/* [ */: + case 0x5C/* \ */: + case 0x5D/* ] */: + case 0x5E/* ^ */: + case 0x5F/* _ */: + case 0x60/* ` */: + case 0x7B/* { */: + case 0x7D/* } */: + case 0x7E/* ~ */: + return true + default: + return false + } +} + +export default function text (state, silent) { + let pos = state.pos + + while (pos < state.posMax && !isTerminatorChar(state.src.charCodeAt(pos))) { + pos++ + } + + if (pos === state.pos) { return false } + + if (!silent) { state.pending += state.src.slice(state.pos, pos) } + + state.pos = pos + + return true +} + +// Alternative implementation, for memory. +// +// It costs 10% of performance, but allows extend terminators list, if place it +// to `ParserInline` property. Probably, will switch to it sometime, such +// flexibility required. + +/* +var TERMINATOR_RE = /[\n!#$%&*+\-:<=>@[\\\]^_`{}~]/; + +module.exports = function text(state, silent) { + var pos = state.pos, + idx = state.src.slice(pos).search(TERMINATOR_RE); + + // first char is terminator -> empty text + if (idx === 0) { return false; } + + // no terminator -> text till end of string + if (idx < 0) { + if (!silent) { state.pending += state.src.slice(pos); } + state.pos = state.src.length; + return true; + } + + if (!silent) { state.pending += state.src.slice(pos, pos + idx); } + + state.pos += idx; + + return true; +}; */ diff --git a/packages/webui/third_party/editor/markdown-it/lib/token.mjs b/packages/webui/third_party/editor/markdown-it/lib/token.mjs new file mode 100644 index 000000000..db247abd7 --- /dev/null +++ b/packages/webui/third_party/editor/markdown-it/lib/token.mjs @@ -0,0 +1,191 @@ +// Token class + +/** + * class Token + **/ + +/** + * new Token(type, tag, nesting) + * + * Create new token and fill passed properties. + **/ +function Token (type, tag, nesting) { + /** + * Token#type -> String + * + * Type of the token (string, e.g. "paragraph_open") + **/ + this.type = type + + /** + * Token#tag -> String + * + * html tag name, e.g. "p" + **/ + this.tag = tag + + /** + * Token#attrs -> Array + * + * Html attributes. Format: `[ [ name1, value1 ], [ name2, value2 ] ]` + **/ + this.attrs = null + + /** + * Token#map -> Array + * + * Source map info. Format: `[ line_begin, line_end ]` + **/ + this.map = null + + /** + * Token#nesting -> Number + * + * Level change (number in {-1, 0, 1} set), where: + * + * - `1` means the tag is opening + * - `0` means the tag is self-closing + * - `-1` means the tag is closing + **/ + this.nesting = nesting + + /** + * Token#level -> Number + * + * nesting level, the same as `state.level` + **/ + this.level = 0 + + /** + * Token#children -> Array + * + * An array of child nodes (inline and img tokens) + **/ + this.children = null + + /** + * Token#content -> String + * + * In a case of self-closing tag (code, html, fence, etc.), + * it has contents of this tag. + **/ + this.content = '' + + /** + * Token#markup -> String + * + * '*' or '_' for emphasis, fence string for fence, etc. + **/ + this.markup = '' + + /** + * Token#info -> String + * + * Additional information: + * + * - Info string for "fence" tokens + * - The value "auto" for autolink "link_open" and "link_close" tokens + * - The string value of the item marker for ordered-list "list_item_open" tokens + **/ + this.info = '' + + /** + * Token#meta -> Object + * + * A place for plugins to store an arbitrary data + **/ + this.meta = null + + /** + * Token#block -> Boolean + * + * True for block-level tokens, false for inline tokens. + * Used in renderer to calculate line breaks + **/ + this.block = false + + /** + * Token#hidden -> Boolean + * + * If it's true, ignore this element when rendering. Used for tight lists + * to hide paragraphs. + **/ + this.hidden = false +} + +/** + * Token.attrIndex(name) -> Number + * + * Search attribute index by name. + **/ +Token.prototype.attrIndex = function attrIndex (name) { + if (!this.attrs) { return -1 } + + const attrs = this.attrs + + for (let i = 0, len = attrs.length; i < len; i++) { + if (attrs[i][0] === name) { return i } + } + return -1 +} + +/** + * Token.attrPush(attrData) + * + * Add `[ name, value ]` attribute to list. Init attrs if necessary + **/ +Token.prototype.attrPush = function attrPush (attrData) { + if (this.attrs) { + this.attrs.push(attrData) + } else { + this.attrs = [attrData] + } +} + +/** + * Token.attrSet(name, value) + * + * Set `name` attribute to `value`. Override old value if exists. + **/ +Token.prototype.attrSet = function attrSet (name, value) { + const idx = this.attrIndex(name) + const attrData = [name, value] + + if (idx < 0) { + this.attrPush(attrData) + } else { + this.attrs[idx] = attrData + } +} + +/** + * Token.attrGet(name) + * + * Get the value of attribute `name`, or null if it does not exist. + **/ +Token.prototype.attrGet = function attrGet (name) { + const idx = this.attrIndex(name) + let value = null + if (idx >= 0) { + value = this.attrs[idx][1] + } + return value +} + +/** + * Token.attrJoin(name, value) + * + * Join value to existing attribute via space. Or create new attribute if not + * exists. Useful to operate with token classes. + **/ +Token.prototype.attrJoin = function attrJoin (name, value) { + const idx = this.attrIndex(name) + + if (idx < 0) { + this.attrPush([name, value]) + } else { + this.attrs[idx][1] = this.attrs[idx][1] + ' ' + value + } +} + +export default Token diff --git a/packages/webui/third_party/editor/markdown-it/package.json b/packages/webui/third_party/editor/markdown-it/package.json new file mode 100644 index 000000000..4f37a27b1 --- /dev/null +++ b/packages/webui/third_party/editor/markdown-it/package.json @@ -0,0 +1,96 @@ +{ + "name": "markdown-it", + "version": "14.3.3", + "description": "Markdown-it - modern pluggable markdown parser.", + "keywords": [ + "markdown", + "parser", + "commonmark", + "markdown-it", + "markdown-it-plugin" + ], + "repository": "markdown-it/markdown-it", + "license": "MIT", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/puzrin" + }, + { + "type": "github", + "url": "https://github.com/sponsors/markdown-it" + } + ], + "main": "dist/index.cjs.js", + "module": "index.mjs", + "exports": { + ".": { + "import": "./index.mjs", + "require": "./dist/index.cjs.js" + }, + "./*": { + "require": "./*", + "import": "./*" + } + }, + "bin": { + "markdown-it": "bin/markdown-it.mjs" + }, + "scripts": { + "lint": "eslint .", + "test": "npm run lint && npm run test:cmspec && npm run test:markdown-it && npm run test:build", + "test:cmspec": "node --test --test-reporter=dot test/cmspec/**/*.test.mjs", + "test:markdown-it": "node --test test/markdown-it/**/*.test.mjs", + "test:build": "npm run build && node --test test/build/**/*.test.mjs", + "pathological:track-ref": "node support/track-ref-pathological.mjs", + "pathological:update-hash": "node support/track-ref-pathological.mjs --update", + "coverage": "npm run build && c8 --include 'lib/**' -r text -r html -r lcov node --test --test-reporter=dot", + "doc": "node support/build_doc.mjs", + "gh-doc": "npm run doc && gh-pages -d apidoc -f", + "demo": "npm run lint && node support/build_demo.mjs", + "gh-demo": "npm run demo && gh-pages -d demo -f -b master -r git@github.com:markdown-it/markdown-it.github.io.git", + "build": "node support/build-dist.mjs", + "benchmark-deps": "npm install --prefix benchmark/extra/", + "specsplit": "support/specsplit.mjs good -o test/fixtures/commonmark/good.txt && support/specsplit.mjs bad -o test/fixtures/commonmark/bad.txt && support/specsplit.mjs", + "todo": "grep 'TODO' -n -r ./lib 2>/dev/null", + "prepack": "npm test && npm run build" + }, + "files": [ + "index.mjs", + "lib/", + "dist/" + ], + "publishConfig": { + "tag": "v14-legacy" + }, + "dependencies": { + "argparse": "^2.0.1", + "entities": "^4.5.0", + "linkify-it": "^5.0.2", + "mdurl": "^2.0.0", + "punycode.js": "^2.3.1", + "uc.micro": "^2.1.0" + }, + "devDependencies": { + "c8": "^11.0.0", + "eslint": "^9.39.4", + "gh-pages": "^6.3.0", + "highlight.js": "^11.11.1", + "markdown-it-abbr": "^2.0.0", + "markdown-it-container": "^4.0.0", + "markdown-it-deflist": "^3.0.1", + "markdown-it-emoji": "^3.0.0", + "markdown-it-footnote": "^4.0.0", + "markdown-it-for-inline": "^2.0.1", + "markdown-it-ins": "^4.0.0", + "markdown-it-mark": "^4.0.0", + "markdown-it-sub": "^2.0.0", + "markdown-it-sup": "^2.0.0", + "ndoc": "^6.0.1", + "neostandard": "^0.13.0", + "terser": "^5.48.0", + "tinybench": "^6.0.2", + "vite": "^8.1.2", + "vite-plugin-singlefile": "^2.3.3" + } +} diff --git a/packages/webui/third_party/editor/mdurl/LICENSE b/packages/webui/third_party/editor/mdurl/LICENSE new file mode 100644 index 000000000..3b2c7bfb1 --- /dev/null +++ b/packages/webui/third_party/editor/mdurl/LICENSE @@ -0,0 +1,45 @@ +Copyright (c) 2015 Vitaly Puzrin, Alex Kocharin. + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +-------------------------------------------------------------------------------- + +.parse() is based on Joyent's node.js `url` code: + +Copyright Joyent, Inc. and other Node contributors. All rights reserved. +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to +deal in the Software without restriction, including without limitation the +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +IN THE SOFTWARE. diff --git a/packages/webui/third_party/editor/mdurl/index.mjs b/packages/webui/third_party/editor/mdurl/index.mjs new file mode 100644 index 000000000..fd78c377f --- /dev/null +++ b/packages/webui/third_party/editor/mdurl/index.mjs @@ -0,0 +1,11 @@ +import decode from './lib/decode.mjs' +import encode from './lib/encode.mjs' +import format from './lib/format.mjs' +import parse from './lib/parse.mjs' + +export { + decode, + encode, + format, + parse +} diff --git a/packages/webui/third_party/editor/mdurl/lib/decode.mjs b/packages/webui/third_party/editor/mdurl/lib/decode.mjs new file mode 100644 index 000000000..9fdc133f8 --- /dev/null +++ b/packages/webui/third_party/editor/mdurl/lib/decode.mjs @@ -0,0 +1,112 @@ +/* eslint-disable no-bitwise */ + +const decodeCache = {} + +function getDecodeCache (exclude) { + let cache = decodeCache[exclude] + if (cache) { return cache } + + cache = decodeCache[exclude] = [] + + for (let i = 0; i < 128; i++) { + const ch = String.fromCharCode(i) + cache.push(ch) + } + + for (let i = 0; i < exclude.length; i++) { + const ch = exclude.charCodeAt(i) + cache[ch] = '%' + ('0' + ch.toString(16).toUpperCase()).slice(-2) + } + + return cache +} + +// Decode percent-encoded string. +// +function decode (string, exclude) { + if (typeof exclude !== 'string') { + exclude = decode.defaultChars + } + + const cache = getDecodeCache(exclude) + + return string.replace(/(%[a-f0-9]{2})+/gi, function (seq) { + let result = '' + + for (let i = 0, l = seq.length; i < l; i += 3) { + const b1 = parseInt(seq.slice(i + 1, i + 3), 16) + + if (b1 < 0x80) { + result += cache[b1] + continue + } + + if ((b1 & 0xE0) === 0xC0 && (i + 3 < l)) { + // 110xxxxx 10xxxxxx + const b2 = parseInt(seq.slice(i + 4, i + 6), 16) + + if ((b2 & 0xC0) === 0x80) { + const chr = ((b1 << 6) & 0x7C0) | (b2 & 0x3F) + + if (chr < 0x80) { + result += '\ufffd\ufffd' + } else { + result += String.fromCharCode(chr) + } + + i += 3 + continue + } + } + + if ((b1 & 0xF0) === 0xE0 && (i + 6 < l)) { + // 1110xxxx 10xxxxxx 10xxxxxx + const b2 = parseInt(seq.slice(i + 4, i + 6), 16) + const b3 = parseInt(seq.slice(i + 7, i + 9), 16) + + if ((b2 & 0xC0) === 0x80 && (b3 & 0xC0) === 0x80) { + const chr = ((b1 << 12) & 0xF000) | ((b2 << 6) & 0xFC0) | (b3 & 0x3F) + + if (chr < 0x800 || (chr >= 0xD800 && chr <= 0xDFFF)) { + result += '\ufffd\ufffd\ufffd' + } else { + result += String.fromCharCode(chr) + } + + i += 6 + continue + } + } + + if ((b1 & 0xF8) === 0xF0 && (i + 9 < l)) { + // 111110xx 10xxxxxx 10xxxxxx 10xxxxxx + const b2 = parseInt(seq.slice(i + 4, i + 6), 16) + const b3 = parseInt(seq.slice(i + 7, i + 9), 16) + const b4 = parseInt(seq.slice(i + 10, i + 12), 16) + + if ((b2 & 0xC0) === 0x80 && (b3 & 0xC0) === 0x80 && (b4 & 0xC0) === 0x80) { + let chr = ((b1 << 18) & 0x1C0000) | ((b2 << 12) & 0x3F000) | ((b3 << 6) & 0xFC0) | (b4 & 0x3F) + + if (chr < 0x10000 || chr > 0x10FFFF) { + result += '\ufffd\ufffd\ufffd\ufffd' + } else { + chr -= 0x10000 + result += String.fromCharCode(0xD800 + (chr >> 10), 0xDC00 + (chr & 0x3FF)) + } + + i += 9 + continue + } + } + + result += '\ufffd' + } + + return result + }) +} + +decode.defaultChars = ';/?:@&=+$,#' +decode.componentChars = '' + +export default decode diff --git a/packages/webui/third_party/editor/mdurl/lib/encode.mjs b/packages/webui/third_party/editor/mdurl/lib/encode.mjs new file mode 100644 index 000000000..7a0c35697 --- /dev/null +++ b/packages/webui/third_party/editor/mdurl/lib/encode.mjs @@ -0,0 +1,89 @@ +const encodeCache = {} + +// Create a lookup array where anything but characters in `chars` string +// and alphanumeric chars is percent-encoded. +// +function getEncodeCache (exclude) { + let cache = encodeCache[exclude] + if (cache) { return cache } + + cache = encodeCache[exclude] = [] + + for (let i = 0; i < 128; i++) { + const ch = String.fromCharCode(i) + + if (/^[0-9a-z]$/i.test(ch)) { + // always allow unencoded alphanumeric characters + cache.push(ch) + } else { + cache.push('%' + ('0' + i.toString(16).toUpperCase()).slice(-2)) + } + } + + for (let i = 0; i < exclude.length; i++) { + cache[exclude.charCodeAt(i)] = exclude[i] + } + + return cache +} + +// Encode unsafe characters with percent-encoding, skipping already +// encoded sequences. +// +// - string - string to encode +// - exclude - list of characters to ignore (in addition to a-zA-Z0-9) +// - keepEscaped - don't encode '%' in a correct escape sequence (default: true) +// +function encode (string, exclude, keepEscaped) { + if (typeof exclude !== 'string') { + // encode(string, keepEscaped) + keepEscaped = exclude + exclude = encode.defaultChars + } + + if (typeof keepEscaped === 'undefined') { + keepEscaped = true + } + + const cache = getEncodeCache(exclude) + let result = '' + + for (let i = 0, l = string.length; i < l; i++) { + const code = string.charCodeAt(i) + + if (keepEscaped && code === 0x25 /* % */ && i + 2 < l) { + if (/^[0-9a-f]{2}$/i.test(string.slice(i + 1, i + 3))) { + result += string.slice(i, i + 3) + i += 2 + continue + } + } + + if (code < 128) { + result += cache[code] + continue + } + + if (code >= 0xD800 && code <= 0xDFFF) { + if (code >= 0xD800 && code <= 0xDBFF && i + 1 < l) { + const nextCode = string.charCodeAt(i + 1) + if (nextCode >= 0xDC00 && nextCode <= 0xDFFF) { + result += encodeURIComponent(string[i] + string[i + 1]) + i++ + continue + } + } + result += '%EF%BF%BD' + continue + } + + result += encodeURIComponent(string[i]) + } + + return result +} + +encode.defaultChars = ";/?:@&=+$,-_.!~*'()#" +encode.componentChars = "-_.!~*'()" + +export default encode diff --git a/packages/webui/third_party/editor/mdurl/lib/format.mjs b/packages/webui/third_party/editor/mdurl/lib/format.mjs new file mode 100644 index 000000000..4b7600015 --- /dev/null +++ b/packages/webui/third_party/editor/mdurl/lib/format.mjs @@ -0,0 +1,21 @@ +export default function format (url) { + let result = '' + + result += url.protocol || '' + result += url.slashes ? '//' : '' + result += url.auth ? url.auth + '@' : '' + + if (url.hostname && url.hostname.indexOf(':') !== -1) { + // ipv6 address + result += '[' + url.hostname + ']' + } else { + result += url.hostname || '' + } + + result += url.port ? ':' + url.port : '' + result += url.pathname || '' + result += url.search || '' + result += url.hash || '' + + return result +}; diff --git a/packages/webui/third_party/editor/mdurl/lib/parse.mjs b/packages/webui/third_party/editor/mdurl/lib/parse.mjs new file mode 100644 index 000000000..fac506503 --- /dev/null +++ b/packages/webui/third_party/editor/mdurl/lib/parse.mjs @@ -0,0 +1,308 @@ +// Copyright Joyent, Inc. and other Node contributors. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to permit +// persons to whom the Software is furnished to do so, subject to the +// following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +// USE OR OTHER DEALINGS IN THE SOFTWARE. + +// +// Changes from joyent/node: +// +// 1. No leading slash in paths, +// e.g. in `url.parse('http://foo?bar')` pathname is ``, not `/` +// +// 2. Backslashes are not replaced with slashes, +// so `http:\\example.org\` is treated like a relative path +// +// 3. Trailing colon is treated like a part of the path, +// i.e. in `http://example.org:foo` pathname is `:foo` +// +// 4. Nothing is URL-encoded in the resulting object, +// (in joyent/node some chars in auth and paths are encoded) +// +// 5. `url.parse()` does not have `parseQueryString` argument +// +// 6. Removed extraneous result properties: `host`, `path`, `query`, etc., +// which can be constructed using other parts of the url. +// + +function Url () { + this.protocol = null + this.slashes = null + this.auth = null + this.port = null + this.hostname = null + this.hash = null + this.search = null + this.pathname = null +} + +// Reference: RFC 3986, RFC 1808, RFC 2396 + +// define these here so at least they only have to be +// compiled once on the first module load. +const protocolPattern = /^([a-z0-9.+-]+:)/i +const portPattern = /:[0-9]*$/ + +// Special case for a simple path URL +/* eslint-disable-next-line no-useless-escape */ +const simplePathPattern = /^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/ + +// RFC 2396: characters reserved for delimiting URLs. +// We actually just auto-escape these. +const delims = ['<', '>', '"', '`', ' ', '\r', '\n', '\t'] + +// RFC 2396: characters not allowed for various reasons. +const unwise = ['{', '}', '|', '\\', '^', '`'].concat(delims) + +// Allowed by RFCs, but cause of XSS attacks. Always escape these. +const autoEscape = ['\''].concat(unwise) +// Characters that are never ever allowed in a hostname. +// Note that any invalid chars are also handled, but these +// are the ones that are *expected* to be seen, so we fast-path +// them. +const nonHostChars = ['%', '/', '?', ';', '#'].concat(autoEscape) +const hostEndingChars = ['/', '?', '#'] +const hostnameMaxLen = 255 +const hostnamePartPattern = /^[+a-z0-9A-Z_-]{0,63}$/ +const hostnamePartStart = /^([+a-z0-9A-Z_-]{0,63})(.*)$/ +// protocols that can allow "unsafe" and "unwise" chars. +// protocols that never have a hostname. +const hostlessProtocol = { + javascript: true, + 'javascript:': true +} +// protocols that always contain a // bit. +const slashedProtocol = { + http: true, + https: true, + ftp: true, + gopher: true, + file: true, + 'http:': true, + 'https:': true, + 'ftp:': true, + 'gopher:': true, + 'file:': true +} + +function urlParse (url, slashesDenoteHost) { + if (url && url instanceof Url) return url + + const u = new Url() + u.parse(url, slashesDenoteHost) + return u +} + +Url.prototype.parse = function (url, slashesDenoteHost) { + let lowerProto, hec, slashes + let rest = url + + // trim before proceeding. + // This is to support parse stuff like " http://foo.com \n" + rest = rest.trim() + + if (!slashesDenoteHost && url.split('#').length === 1) { + // Try fast path regexp + const simplePath = simplePathPattern.exec(rest) + if (simplePath) { + this.pathname = simplePath[1] + if (simplePath[2]) { + this.search = simplePath[2] + } + return this + } + } + + let proto = protocolPattern.exec(rest) + if (proto) { + proto = proto[0] + lowerProto = proto.toLowerCase() + this.protocol = proto + rest = rest.substr(proto.length) + } + + // figure out if it's got a host + // user@server is *always* interpreted as a hostname, and url + // resolution will treat //foo/bar as host=foo,path=bar because that's + // how the browser resolves relative URLs. + /* eslint-disable-next-line no-useless-escape */ + if (slashesDenoteHost || proto || rest.match(/^\/\/[^@\/]+@[^@\/]+/)) { + slashes = rest.substr(0, 2) === '//' + if (slashes && !(proto && hostlessProtocol[proto])) { + rest = rest.substr(2) + this.slashes = true + } + } + + if (!hostlessProtocol[proto] && + (slashes || (proto && !slashedProtocol[proto]))) { + // there's a hostname. + // the first instance of /, ?, ;, or # ends the host. + // + // If there is an @ in the hostname, then non-host chars *are* allowed + // to the left of the last @ sign, unless some host-ending character + // comes *before* the @-sign. + // URLs are obnoxious. + // + // ex: + // http://a@b@c/ => user:a@b host:c + // http://a@b?@c => user:a host:c path:/?@c + + // v0.12 TODO(isaacs): This is not quite how Chrome does things. + // Review our test case against browsers more comprehensively. + + // find the first instance of any hostEndingChars + let hostEnd = -1 + for (let i = 0; i < hostEndingChars.length; i++) { + hec = rest.indexOf(hostEndingChars[i]) + if (hec !== -1 && (hostEnd === -1 || hec < hostEnd)) { + hostEnd = hec + } + } + + // at this point, either we have an explicit point where the + // auth portion cannot go past, or the last @ char is the decider. + let auth, atSign + if (hostEnd === -1) { + // atSign can be anywhere. + atSign = rest.lastIndexOf('@') + } else { + // atSign must be in auth portion. + // http://a@b/c@d => host:b auth:a path:/c@d + atSign = rest.lastIndexOf('@', hostEnd) + } + + // Now we have a portion which is definitely the auth. + // Pull that off. + if (atSign !== -1) { + auth = rest.slice(0, atSign) + rest = rest.slice(atSign + 1) + this.auth = auth + } + + // the host is the remaining to the left of the first non-host char + hostEnd = -1 + for (let i = 0; i < nonHostChars.length; i++) { + hec = rest.indexOf(nonHostChars[i]) + if (hec !== -1 && (hostEnd === -1 || hec < hostEnd)) { + hostEnd = hec + } + } + // if we still have not hit it, then the entire thing is a host. + if (hostEnd === -1) { + hostEnd = rest.length + } + + if (rest[hostEnd - 1] === ':') { hostEnd-- } + const host = rest.slice(0, hostEnd) + rest = rest.slice(hostEnd) + + // pull out port. + this.parseHost(host) + + // we've indicated that there is a hostname, + // so even if it's empty, it has to be present. + this.hostname = this.hostname || '' + + // if hostname begins with [ and ends with ] + // assume that it's an IPv6 address. + const ipv6Hostname = this.hostname[0] === '[' && + this.hostname[this.hostname.length - 1] === ']' + + // validate a little. + if (!ipv6Hostname) { + const hostparts = this.hostname.split(/\./) + for (let i = 0, l = hostparts.length; i < l; i++) { + const part = hostparts[i] + if (!part) { continue } + if (!part.match(hostnamePartPattern)) { + let newpart = '' + for (let j = 0, k = part.length; j < k; j++) { + if (part.charCodeAt(j) > 127) { + // we replace non-ASCII char with a temporary placeholder + // we need this to make sure size of hostname is not + // broken by replacing non-ASCII by nothing + newpart += 'x' + } else { + newpart += part[j] + } + } + // we test again with ASCII char only + if (!newpart.match(hostnamePartPattern)) { + const validParts = hostparts.slice(0, i) + const notHost = hostparts.slice(i + 1) + const bit = part.match(hostnamePartStart) + if (bit) { + validParts.push(bit[1]) + notHost.unshift(bit[2]) + } + if (notHost.length) { + rest = notHost.join('.') + rest + } + this.hostname = validParts.join('.') + break + } + } + } + } + + if (this.hostname.length > hostnameMaxLen) { + this.hostname = '' + } + + // strip [ and ] from the hostname + // the host field still retains them, though + if (ipv6Hostname) { + this.hostname = this.hostname.substr(1, this.hostname.length - 2) + } + } + + // chop off from the tail first. + const hash = rest.indexOf('#') + if (hash !== -1) { + // got a fragment string. + this.hash = rest.substr(hash) + rest = rest.slice(0, hash) + } + const qm = rest.indexOf('?') + if (qm !== -1) { + this.search = rest.substr(qm) + rest = rest.slice(0, qm) + } + if (rest) { this.pathname = rest } + if (slashedProtocol[lowerProto] && + this.hostname && !this.pathname) { + this.pathname = '' + } + + return this +} + +Url.prototype.parseHost = function (host) { + let port = portPattern.exec(host) + if (port) { + port = port[0] + if (port !== ':') { + this.port = port.substr(1) + } + host = host.substr(0, host.length - port.length) + } + if (host) { this.hostname = host } +} + +export default urlParse diff --git a/packages/webui/third_party/editor/mdurl/package.json b/packages/webui/third_party/editor/mdurl/package.json new file mode 100644 index 000000000..6e8b7680c --- /dev/null +++ b/packages/webui/third_party/editor/mdurl/package.json @@ -0,0 +1,43 @@ +{ + "name": "mdurl", + "version": "2.1.0", + "description": "URL utilities for markdown-it", + "repository": { + "type": "git", + "url": "git+https://github.com/markdown-it/mdurl.git" + }, + "license": "MIT", + "main": "build/index.cjs.js", + "module": "index.mjs", + "types": "lib/index.d.ts", + "exports": { + ".": { + "types": "./lib/index.d.ts", + "require": "./build/index.cjs.js", + "import": "./index.mjs" + }, + "./*": { + "require": "./*", + "import": "./*" + } + }, + "scripts": { + "lint": "eslint .", + "build": "rollup -c", + "type-check": "tsc --noEmit --strict --target ESNext --module ESNext --moduleResolution Bundler test/types.ts", + "test": "npm run lint && npm run build && npm run type-check && c8 --exclude build --exclude test -r text -r html -r lcov node --test test/**/*.test.*", + "prepack": "npm run build" + }, + "files": [ + "index.mjs", + "lib/", + "build/" + ], + "devDependencies": { + "c8": "^12.0.0", + "eslint": "^8.54.0", + "eslint-config-standard": "^17.1.0", + "rollup": "^4.62.2", + "typescript": "^7.0.2" + } +} diff --git a/packages/webui/third_party/editor/orderedmap/LICENSE b/packages/webui/third_party/editor/orderedmap/LICENSE new file mode 100644 index 000000000..17da88ae4 --- /dev/null +++ b/packages/webui/third_party/editor/orderedmap/LICENSE @@ -0,0 +1,19 @@ +Copyright (C) 2016 by Marijn Haverbeke and others + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/packages/webui/third_party/editor/orderedmap/index.js b/packages/webui/third_party/editor/orderedmap/index.js new file mode 100644 index 000000000..dcb98051d --- /dev/null +++ b/packages/webui/third_party/editor/orderedmap/index.js @@ -0,0 +1,135 @@ +// ::- Persistent data structure representing an ordered mapping from +// strings to values, with some convenient update methods. +export default function OrderedMap(content) { + this.content = content +} + +OrderedMap.prototype = { + constructor: OrderedMap, + + find: function(key) { + for (var i = 0; i < this.content.length; i += 2) + if (this.content[i] === key) return i + return -1 + }, + + // :: (string) → ?any + // Retrieve the value stored under `key`, or return undefined when + // no such key exists. + get: function(key) { + var found = this.find(key) + return found == -1 ? undefined : this.content[found + 1] + }, + + // :: (string, any, ?string) → OrderedMap + // Create a new map by replacing the value of `key` with a new + // value, or adding a binding to the end of the map. If `newKey` is + // given, the key of the binding will be replaced with that key. + update: function(key, value, newKey) { + var self = newKey && newKey != key ? this.remove(newKey) : this + var found = self.find(key), content = self.content.slice() + if (found == -1) { + content.push(newKey || key, value) + } else { + content[found + 1] = value + if (newKey) content[found] = newKey + } + return new OrderedMap(content) + }, + + // :: (string) → OrderedMap + // Return a map with the given key removed, if it existed. + remove: function(key) { + var found = this.find(key) + if (found == -1) return this + var content = this.content.slice() + content.splice(found, 2) + return new OrderedMap(content) + }, + + // :: (string, any) → OrderedMap + // Add a new key to the start of the map. + addToStart: function(key, value) { + return new OrderedMap([key, value].concat(this.remove(key).content)) + }, + + // :: (string, any) → OrderedMap + // Add a new key to the end of the map. + addToEnd: function(key, value) { + var content = this.remove(key).content.slice() + content.push(key, value) + return new OrderedMap(content) + }, + + // :: (string, string, any) → OrderedMap + // Add a key after the given key. If `place` is not found, the new + // key is added to the end. + addBefore: function(place, key, value) { + var without = this.remove(key), content = without.content.slice() + var found = without.find(place) + content.splice(found == -1 ? content.length : found, 0, key, value) + return new OrderedMap(content) + }, + + // :: ((key: string, value: any)) + // Call the given function for each key/value pair in the map, in + // order. + forEach: function(f) { + for (var i = 0; i < this.content.length; i += 2) + f(this.content[i], this.content[i + 1]) + }, + + // :: (union) → OrderedMap + // Create a new map by prepending the keys in this map that don't + // appear in `map` before the keys in `map`. + prepend: function(map) { + map = OrderedMap.from(map) + if (!map.size) return this + return new OrderedMap(map.content.concat(this.subtract(map).content)) + }, + + // :: (union) → OrderedMap + // Create a new map by appending the keys in this map that don't + // appear in `map` after the keys in `map`. + append: function(map) { + map = OrderedMap.from(map) + if (!map.size) return this + return new OrderedMap(this.subtract(map).content.concat(map.content)) + }, + + // :: (union) → OrderedMap + // Create a map containing all the keys in this map that don't + // appear in `map`. + subtract: function(map) { + var result = this + map = OrderedMap.from(map) + for (var i = 0; i < map.content.length; i += 2) + result = result.remove(map.content[i]) + return result + }, + + // :: () → Object + // Turn ordered map into a plain object. + toObject: function() { + var result = {} + this.forEach(function(key, value) { result[key] = value }) + return result + }, + + // :: number + // The amount of keys in this map. + get size() { + return this.content.length >> 1 + } +} + +// :: (?union) → OrderedMap +// Return a map with the given content. If null, create an empty +// map. If given an ordered map, return that map itself. If given an +// object, create a map from the object's properties. +OrderedMap.from = function(value) { + if (value instanceof OrderedMap) return value + var content = [] + if (value) for (var prop in value) content.push(prop, value[prop]) + return new OrderedMap(content) +} diff --git a/packages/webui/third_party/editor/orderedmap/package.json b/packages/webui/third_party/editor/orderedmap/package.json new file mode 100644 index 000000000..f4d851a2f --- /dev/null +++ b/packages/webui/third_party/editor/orderedmap/package.json @@ -0,0 +1,39 @@ +{ + "name": "orderedmap", + "version": "2.1.1", + "description": "Persistent ordered mapping from strings", + "type": "module", + "main": "dist/index.cjs", + "types": "dist/index.d.ts", + "module": "dist/index.js", + "exports": { + "import": "./dist/index.js", + "require": "./dist/index.cjs" + }, + "sideEffects": false, + "files": [ + "dist/*" + ], + "repository": { + "type": "git", + "url": "git+https://github.com/marijnh/orderedmap.git" + }, + "keywords": [ + "persistent", + "map" + ], + "author": "Marijn Haverbeke ", + "license": "MIT", + "bugs": { + "url": "https://github.com/marijnh/orderedmap/issues" + }, + "homepage": "https://github.com/marijnh/orderedmap#readme", + "scripts": { + "build": "rollup -c", + "watch": "rollup -c -w", + "prepare": "npm run build" + }, + "devDependencies": { + "rollup": "^1.26.3" + } +} diff --git a/packages/webui/third_party/editor/prosemirror-commands/LICENSE b/packages/webui/third_party/editor/prosemirror-commands/LICENSE new file mode 100644 index 000000000..7e2295b30 --- /dev/null +++ b/packages/webui/third_party/editor/prosemirror-commands/LICENSE @@ -0,0 +1,19 @@ +Copyright (C) 2015-2017 by Marijn Haverbeke and others + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/packages/webui/third_party/editor/prosemirror-commands/package.json b/packages/webui/third_party/editor/prosemirror-commands/package.json new file mode 100644 index 000000000..084fa603f --- /dev/null +++ b/packages/webui/third_party/editor/prosemirror-commands/package.json @@ -0,0 +1,39 @@ +{ + "name": "prosemirror-commands", + "version": "1.7.2", + "description": "Editing commands for ProseMirror", + "type": "module", + "main": "dist/index.cjs", + "module": "dist/index.js", + "types": "dist/index.d.ts", + "exports": { + "import": "./dist/index.js", + "require": "./dist/index.cjs" + }, + "sideEffects": false, + "license": "MIT", + "maintainers": [ + { + "name": "Marijn Haverbeke", + "email": "marijn@haverbeke.berlin", + "web": "http://marijnhaverbeke.nl" + } + ], + "repository": { + "type": "git", + "url": "git+https://code.haverbeke.berlin/prosemirror/prosemirror-commands.git" + }, + "dependencies": { + "prosemirror-model": "^1.0.0", + "prosemirror-transform": "^1.10.2", + "prosemirror-state": "^1.0.0" + }, + "devDependencies": { + "@prosemirror/buildhelper": "^0.1.5", + "prosemirror-test-builder": "^1.0.0" + }, + "scripts": { + "test": "pm-runtests", + "prepare": "pm-buildhelper src/commands.ts" + } +} diff --git a/packages/webui/third_party/editor/prosemirror-commands/src/commands.ts b/packages/webui/third_party/editor/prosemirror-commands/src/commands.ts new file mode 100644 index 000000000..aa0cef4bd --- /dev/null +++ b/packages/webui/third_party/editor/prosemirror-commands/src/commands.ts @@ -0,0 +1,786 @@ +import {joinPoint, canJoin, findWrapping, liftTarget, canSplit, + ReplaceStep, ReplaceAroundStep, replaceStep} from "prosemirror-transform" +import {Slice, Fragment, Node, NodeType, Attrs, MarkType, ResolvedPos, ContentMatch} from "prosemirror-model" +import {Selection, EditorState, Transaction, TextSelection, NodeSelection, + SelectionRange, AllSelection, Command} from "prosemirror-state" +import {EditorView} from "prosemirror-view" + +/// Delete the selection, if there is one. +export const deleteSelection: Command = (state, dispatch) => { + if (state.selection.empty) return false + if (dispatch) dispatch(state.tr.deleteSelection().scrollIntoView()) + return true +} + +function atBlockStart(state: EditorState, view?: EditorView): ResolvedPos | null { + let {$cursor} = state.selection as TextSelection + if (!$cursor || (view ? !view.endOfTextblock("backward", state) + : $cursor.parentOffset > 0)) + return null + return $cursor +} + +/// If the selection is empty and at the start of a textblock, try to +/// reduce the distance between that block and the one before it—if +/// there's a block directly before it that can be joined, join them. +/// If not, try to move the selected block closer to the next one in +/// the document structure by lifting it out of its parent or moving it +/// into a parent of the previous block. Will use the view for accurate +/// (bidi-aware) start-of-textblock detection if given. +export const joinBackward: Command = (state, dispatch, view) => { + let $cursor = atBlockStart(state, view) + if (!$cursor) return false + + let $cut = findCutBefore($cursor) + + // If there is no node before this, try to lift + if (!$cut) { + let range = $cursor.blockRange(), target = range && liftTarget(range) + if (target == null) return false + if (dispatch) dispatch(state.tr.lift(range!, target).scrollIntoView()) + return true + } + + let before = $cut.nodeBefore! + // Apply the joining algorithm + if (deleteBarrier(state, $cut, dispatch, -1)) return true + + // If the node below has no content and the node above is + // selectable, delete the node below and select the one above. + if ($cursor.parent.content.size == 0 && + (textblockAt(before, "end") || NodeSelection.isSelectable(before))) { + for (let depth = $cursor.depth;; depth--) { + let delStep = replaceStep(state.doc, $cursor.before(depth), $cursor.after(depth), Slice.empty) + if (delStep && (delStep as ReplaceStep).slice.size < (delStep as ReplaceStep).to - (delStep as ReplaceStep).from) { + if (dispatch) { + let tr = state.tr.step(delStep) + tr.setSelection(textblockAt(before, "end") + ? Selection.findFrom(tr.doc.resolve(tr.mapping.map($cut.pos, -1)), -1)! + : NodeSelection.create(tr.doc, $cut.pos - before.nodeSize)) + dispatch(tr.scrollIntoView()) + } + return true + } + if (depth == 1 || $cursor.node(depth - 1).childCount > 1) break + } + } + + // If the node before is an atom, delete it + if (before.isAtom && $cut.depth == $cursor.depth - 1) { + if (dispatch) dispatch(state.tr.delete($cut.pos - before.nodeSize, $cut.pos).scrollIntoView()) + return true + } + + return false +} + +/// A more limited form of [`joinBackward`](#commands.joinBackward) +/// that only tries to join the current textblock to the one before +/// it, if the cursor is at the start of a textblock. +export const joinTextblockBackward: Command = (state, dispatch, view) => { + let $cursor = atBlockStart(state, view) + if (!$cursor) return false + let $cut = findCutBefore($cursor) + return $cut ? joinTextblocksAround(state, $cut, dispatch) : false +} + +/// A more limited form of [`joinForward`](#commands.joinForward) +/// that only tries to join the current textblock to the one after +/// it, if the cursor is at the end of a textblock. +export const joinTextblockForward: Command = (state, dispatch, view) => { + let $cursor = atBlockEnd(state, view) + if (!$cursor) return false + let $cut = findCutAfter($cursor) + return $cut ? joinTextblocksAround(state, $cut, dispatch) : false +} + +function joinTextblocksAround(state: EditorState, $cut: ResolvedPos, dispatch?: (tr: Transaction) => void) { + let before = $cut.nodeBefore!, beforeText = before, beforePos = $cut.pos - 1 + for (; !beforeText.isTextblock; beforePos--) { + if (beforeText.type.spec.isolating) return false + let child = beforeText.lastChild + if (!child) return false + beforeText = child + } + let after = $cut.nodeAfter!, afterText = after, afterPos = $cut.pos + 1 + for (; !afterText.isTextblock; afterPos++) { + if (afterText.type.spec.isolating) return false + let child = afterText.firstChild + if (!child) return false + afterText = child + } + let step = replaceStep(state.doc, beforePos, afterPos, Slice.empty) as ReplaceStep | null + if (!step || step.from != beforePos || + step instanceof ReplaceStep && step.slice.size >= afterPos - beforePos) return false + if (dispatch) { + let tr = state.tr.step(step) + tr.setSelection(TextSelection.create(tr.doc, beforePos)) + dispatch(tr.scrollIntoView()) + } + return true + +} + +function textblockAt(node: Node, side: "start" | "end", only = false) { + for (let scan: Node | null = node; scan; scan = (side == "start" ? scan.firstChild : scan.lastChild)) { + if (scan.isTextblock) return true + if (only && scan.childCount != 1) return false + } + return false +} + +/// When the selection is empty and at the start of a textblock, select +/// the node before that textblock, if possible. This is intended to be +/// bound to keys like backspace, after +/// [`joinBackward`](#commands.joinBackward) or other deleting +/// commands, as a fall-back behavior when the schema doesn't allow +/// deletion at the selected point. +export const selectNodeBackward: Command = (state, dispatch, view) => { + let {$head, empty} = state.selection, $cut: ResolvedPos | null = $head + if (!empty) return false + + if ($head.parent.isTextblock) { + if (view ? !view.endOfTextblock("backward", state) : $head.parentOffset > 0) return false + $cut = findCutBefore($head) + } + let node = $cut && $cut.nodeBefore + if (!node || !NodeSelection.isSelectable(node)) return false + if (dispatch) + dispatch(state.tr.setSelection(NodeSelection.create(state.doc, $cut!.pos - node.nodeSize)).scrollIntoView()) + return true +} + +function findCutBefore($pos: ResolvedPos): ResolvedPos | null { + if (!$pos.parent.type.spec.isolating) for (let i = $pos.depth - 1; i >= 0; i--) { + if ($pos.index(i) > 0) return $pos.doc.resolve($pos.before(i + 1)) + if ($pos.node(i).type.spec.isolating) break + } + return null +} + +function atBlockEnd(state: EditorState, view?: EditorView): ResolvedPos | null { + let {$cursor} = state.selection as TextSelection + if (!$cursor || (view ? !view.endOfTextblock("forward", state) + : $cursor.parentOffset < $cursor.parent.content.size)) + return null + return $cursor +} + +/// If the selection is empty and the cursor is at the end of a +/// textblock, try to reduce or remove the boundary between that block +/// and the one after it, either by joining them or by moving the other +/// block closer to this one in the tree structure. Will use the view +/// for accurate start-of-textblock detection if given. +export const joinForward: Command = (state, dispatch, view) => { + let $cursor = atBlockEnd(state, view) + if (!$cursor) return false + + let $cut = findCutAfter($cursor) + // If there is no node after this, there's nothing to do + if (!$cut) return false + + let after = $cut.nodeAfter! + // Try the joining algorithm + if (deleteBarrier(state, $cut, dispatch, 1)) return true + + // If the node above has no content and the node below is + // selectable, delete the node above and select the one below. + if ($cursor.parent.content.size == 0 && + (textblockAt(after, "start") || NodeSelection.isSelectable(after))) { + let delStep = replaceStep(state.doc, $cursor.before(), $cursor.after(), Slice.empty) + if (delStep && (delStep as ReplaceStep).slice.size < (delStep as ReplaceStep).to - (delStep as ReplaceStep).from) { + if (dispatch) { + let tr = state.tr.step(delStep) + tr.setSelection(textblockAt(after, "start") ? Selection.findFrom(tr.doc.resolve(tr.mapping.map($cut.pos)), 1)! + : NodeSelection.create(tr.doc, tr.mapping.map($cut.pos))) + dispatch(tr.scrollIntoView()) + } + return true + } + } + + // If the next node is an atom, delete it + if (after.isAtom && $cut.depth == $cursor.depth - 1) { + if (dispatch) dispatch(state.tr.delete($cut.pos, $cut.pos + after.nodeSize).scrollIntoView()) + return true + } + + return false +} + +/// When the selection is empty and at the end of a textblock, select +/// the node coming after that textblock, if possible. This is intended +/// to be bound to keys like delete, after +/// [`joinForward`](#commands.joinForward) and similar deleting +/// commands, to provide a fall-back behavior when the schema doesn't +/// allow deletion at the selected point. +export const selectNodeForward: Command = (state, dispatch, view) => { + let {$head, empty} = state.selection, $cut: ResolvedPos | null = $head + if (!empty) return false + if ($head.parent.isTextblock) { + if (view ? !view.endOfTextblock("forward", state) : $head.parentOffset < $head.parent.content.size) + return false + $cut = findCutAfter($head) + } + let node = $cut && $cut.nodeAfter + if (!node || !NodeSelection.isSelectable(node)) return false + if (dispatch) + dispatch(state.tr.setSelection(NodeSelection.create(state.doc, $cut!.pos)).scrollIntoView()) + return true +} + +function findCutAfter($pos: ResolvedPos) { + if (!$pos.parent.type.spec.isolating) for (let i = $pos.depth - 1; i >= 0; i--) { + let parent = $pos.node(i) + if ($pos.index(i) + 1 < parent.childCount) return $pos.doc.resolve($pos.after(i + 1)) + if (parent.type.spec.isolating) break + } + return null +} + +/// Join the selected block or, if there is a text selection, the +/// closest ancestor block of the selection that can be joined, with +/// the sibling above it. +export const joinUp: Command = (state, dispatch) => { + let sel = state.selection, nodeSel = sel instanceof NodeSelection, point + if (nodeSel) { + if ((sel as NodeSelection).node.isTextblock || !canJoin(state.doc, sel.from)) return false + point = sel.from + } else { + point = joinPoint(state.doc, sel.from, -1) + if (point == null) return false + } + if (dispatch) { + let tr = state.tr.join(point) + if (nodeSel) tr.setSelection(NodeSelection.create(tr.doc, point - state.doc.resolve(point).nodeBefore!.nodeSize)) + dispatch(tr.scrollIntoView()) + } + return true +} + +/// Join the selected block, or the closest ancestor of the selection +/// that can be joined, with the sibling after it. +export const joinDown: Command = (state, dispatch) => { + let sel = state.selection, point + if (sel instanceof NodeSelection) { + if (sel.node.isTextblock || !canJoin(state.doc, sel.to)) return false + point = sel.to + } else { + point = joinPoint(state.doc, sel.to, 1) + if (point == null) return false + } + if (dispatch) + dispatch(state.tr.join(point).scrollIntoView()) + return true +} + +/// Lift the selected block, or the closest ancestor block of the +/// selection that can be lifted, out of its parent node. +export const lift: Command = (state, dispatch) => { + let {$from, $to} = state.selection + let range = $from.blockRange($to), target = range && liftTarget(range) + if (target == null) return false + if (dispatch) dispatch(state.tr.lift(range!, target).scrollIntoView()) + return true +} + +/// If the selection is in a node whose type has a truthy +/// [`code`](#model.NodeSpec.code) property in its spec, replace the +/// selection with a newline character. +export const newlineInCode: Command = (state, dispatch) => { + let {$head, $anchor} = state.selection + if (!$head.parent.type.spec.code || !$head.sameParent($anchor)) return false + if (dispatch) dispatch(state.tr.insertText("\n").scrollIntoView()) + return true +} + +function defaultBlockAt(match: ContentMatch) { + for (let i = 0; i < match.edgeCount; i++) { + let {type} = match.edge(i) + if (type.isTextblock && !type.hasRequiredAttrs()) return type + } + return null +} + +/// When the selection is in a node with a truthy +/// [`code`](#model.NodeSpec.code) property in its spec, create a +/// default block after the code block, and move the cursor there. +export const exitCode: Command = (state, dispatch) => { + let {$head, $anchor} = state.selection + if (!$head.parent.type.spec.code || !$head.sameParent($anchor)) return false + let above = $head.node(-1), after = $head.indexAfter(-1), type = defaultBlockAt(above.contentMatchAt(after)) + if (!type || !above.canReplaceWith(after, after, type)) return false + if (dispatch) { + let pos = $head.after(), tr = state.tr.replaceWith(pos, pos, type.createAndFill()!) + tr.setSelection(Selection.near(tr.doc.resolve(pos), 1)) + dispatch(tr.scrollIntoView()) + } + return true +} + +/// If a block node is selected, create an empty paragraph before (if +/// it is its parent's first child) or after it. +export const createParagraphNear: Command = (state, dispatch) => { + let sel = state.selection, {$from, $to} = sel + if (sel instanceof AllSelection || $from.parent.inlineContent || $to.parent.inlineContent) return false + let type = defaultBlockAt($to.parent.contentMatchAt($to.indexAfter())) + if (!type || !type.isTextblock) return false + if (dispatch) { + let side = (!$from.parentOffset && $to.index() < $to.parent.childCount ? $from : $to).pos + let tr = state.tr.insert(side, type.createAndFill()!) + tr.setSelection(TextSelection.create(tr.doc, side + 1)) + dispatch(tr.scrollIntoView()) + } + return true +} + +/// If the cursor is in an empty textblock that can be lifted, lift the +/// block. +export const liftEmptyBlock: Command = (state, dispatch) => { + let {$cursor} = state.selection as TextSelection + if (!$cursor || $cursor.parent.content.size) return false + if ($cursor.depth > 1 && $cursor.after() != $cursor.end(-1)) { + let before = $cursor.before() + if (canSplit(state.doc, before)) { + if (dispatch) dispatch(state.tr.split(before).scrollIntoView()) + return true + } + } + let range = $cursor.blockRange(), target = range && liftTarget(range) + if (target == null) return false + if (dispatch) dispatch(state.tr.lift(range!, target).scrollIntoView()) + return true +} + +/// Create a variant of [`splitBlock`](#commands.splitBlock) that uses +/// a custom function to determine the type of the newly split off block. +export function splitBlockAs( + splitNode?: (node: Node, atEnd: boolean, $from: ResolvedPos) => {type: NodeType, attrs?: Attrs} | null +): Command { + return (state, dispatch) => { + if (state.selection instanceof NodeSelection && state.selection.node.isBlock) { + let {$from} = state.selection + if (!$from.parentOffset || !canSplit(state.doc, $from.pos)) return false + if (dispatch) dispatch(state.tr.split($from.pos).scrollIntoView()) + return true + } + + if (!state.selection.$from.depth) return false + let tr = state.tr + if (!state.selection.empty && (state.selection instanceof TextSelection || state.selection instanceof AllSelection)) + tr.deleteSelection() + let {$from} = tr.selection, mapFrom = tr.steps.length + let types: (null | {type: NodeType, attrs?: Attrs | null})[] = [] + let splitDepth, deflt, atEnd = false, atStart = false + for (let d = $from.depth;; d--) { + let node = $from.node(d) + if (node.isBlock) { + atEnd = $from.end(d) == $from.pos + ($from.depth - d) + atStart = $from.start(d) == $from.pos - ($from.depth - d) + deflt = defaultBlockAt($from.node(d - 1).contentMatchAt($from.indexAfter(d - 1))) + let splitType = splitNode && splitNode($from.parent, atEnd, $from) + types.unshift(splitType || (atEnd && deflt ? {type: deflt} : null)) + splitDepth = d + break + } else { + if (d == 1) return false + types.unshift(null) + } + } + + let splitPos = $from.pos + let can = canSplit(tr.doc, splitPos, types.length, types) + if (!can) { + types[0] = deflt ? {type: deflt} : null + can = canSplit(tr.doc, splitPos, types.length, types) + } + if (!can) return false + tr.split(splitPos, types.length, types) + if (!atEnd && atStart && $from.node(splitDepth).type != deflt) { + let mapping = tr.mapping.slice(mapFrom) + let first = mapping.map($from.before(splitDepth)), $first = tr.doc.resolve(first) + if (deflt && $from.node(splitDepth - 1).canReplaceWith($first.index(), $first.index() + 1, deflt)) + tr.setNodeMarkup(mapping.map($from.before(splitDepth)), deflt) + } + if (dispatch) dispatch(tr.scrollIntoView()) + return true + } +} + +/// Split the parent block of the selection. If the selection is a text +/// selection, also delete its content. +export const splitBlock: Command = splitBlockAs() + +/// Acts like [`splitBlock`](#commands.splitBlock), but without +/// resetting the set of active marks at the cursor. +export const splitBlockKeepMarks: Command = (state, dispatch) => { + return splitBlock(state, dispatch && (tr => { + let marks = state.storedMarks || (state.selection.$to.parentOffset && state.selection.$from.marks()) + if (marks) tr.ensureMarks(marks) + dispatch(tr) + })) +} + +/// Move the selection to the node wrapping the current selection, if +/// any. (Will not select the document node.) +export const selectParentNode: Command = (state, dispatch) => { + let {$from, to} = state.selection, pos + let same = $from.sharedDepth(to) + if (same == 0) return false + pos = $from.before(same) + if (dispatch) dispatch(state.tr.setSelection(NodeSelection.create(state.doc, pos))) + return true +} + +/// Select the whole document. +export const selectAll: Command = (state, dispatch) => { + if (dispatch) dispatch(state.tr.setSelection(new AllSelection(state.doc))) + return true +} + +function joinMaybeClear(state: EditorState, $pos: ResolvedPos, dispatch: ((tr: Transaction) => void) | undefined) { + let before = $pos.nodeBefore, after = $pos.nodeAfter, index = $pos.index() + if (!before || !after || !before.type.compatibleContent(after.type)) return false + if (!before.content.size && $pos.parent.canReplace(index - 1, index)) { + if (dispatch) dispatch(state.tr.delete($pos.pos - before.nodeSize, $pos.pos).scrollIntoView()) + return true + } + if (!$pos.parent.canReplace(index, index + 1) || !(after.isTextblock || canJoin(state.doc, $pos.pos))) + return false + if (dispatch) + dispatch(state.tr.join($pos.pos).scrollIntoView()) + return true +} + +function deleteBarrier(state: EditorState, $cut: ResolvedPos, dispatch: ((tr: Transaction) => void) | undefined, dir: number) { + let before = $cut.nodeBefore!, after = $cut.nodeAfter!, conn, match + let isolated = before.type.spec.isolating || after.type.spec.isolating + if (!isolated && joinMaybeClear(state, $cut, dispatch)) return true + + let canDelAfter = !isolated && $cut.parent.canReplace($cut.index(), $cut.index() + 1) + if (canDelAfter && + (conn = (match = before.contentMatchAt(before.childCount)).findWrapping(after.type)) && + match.matchType(conn[0] || after.type)!.validEnd) { + if (dispatch) { + let end = $cut.pos + after.nodeSize, wrap = Fragment.empty + for (let i = conn.length - 1; i >= 0; i--) + wrap = Fragment.from(conn[i].create(null, wrap)) + wrap = Fragment.from(before.copy(wrap)) + let tr = state.tr.step(new ReplaceAroundStep($cut.pos - 1, end, $cut.pos, end, new Slice(wrap, 1, 0), conn.length, true)) + let $joinAt = tr.doc.resolve(end + 2 * conn.length) + if ($joinAt.nodeAfter && $joinAt.nodeAfter.type == before.type && + canJoin(tr.doc, $joinAt.pos)) tr.join($joinAt.pos) + dispatch(tr.scrollIntoView()) + } + return true + } + + let selAfter = after.type.spec.isolating || (dir > 0 && isolated) ? null : Selection.findFrom($cut, 1) + let range = selAfter && selAfter.$from.blockRange(selAfter.$to), target = range && liftTarget(range) + if (target != null && target >= $cut.depth) { + if (dispatch) dispatch(state.tr.lift(range!, target).scrollIntoView()) + return true + } + + if (canDelAfter && textblockAt(after, "start", true) && textblockAt(before, "end")) { + let at = before, wrap = [] + for (;;) { + wrap.push(at) + if (at.isTextblock) break + at = at.lastChild! + } + let afterText = after, afterDepth = 1 + for (; !afterText.isTextblock; afterText = afterText.firstChild!) afterDepth++ + if (at.canReplace(at.childCount, at.childCount, afterText.content)) { + if (dispatch) { + let end = Fragment.empty + for (let i = wrap.length - 1; i >= 0; i--) end = Fragment.from(wrap[i].copy(end)) + let tr = state.tr.step(new ReplaceAroundStep($cut.pos - wrap.length, $cut.pos + after.nodeSize, + $cut.pos + afterDepth, $cut.pos + after.nodeSize - afterDepth, + new Slice(end, wrap.length, 0), 0, true)) + dispatch(tr.scrollIntoView()) + } + return true + } + } + + return false +} + +function selectTextblockSide(side: number): Command { + return function(state, dispatch) { + let sel = state.selection, $pos = side < 0 ? sel.$from : sel.$to + let depth = $pos.depth + while ($pos.node(depth).isInline) { + if (!depth) return false + depth-- + } + if (!$pos.node(depth).isTextblock) return false + if (dispatch) + dispatch(state.tr.setSelection(TextSelection.create( + state.doc, side < 0 ? $pos.start(depth) : $pos.end(depth)))) + return true + } +} + +/// Moves the cursor to the start of current text block. +export const selectTextblockStart = selectTextblockSide(-1) + +/// Moves the cursor to the end of current text block. +export const selectTextblockEnd = selectTextblockSide(1) + +// Parameterized commands + +/// Wrap the selection in a node of the given type with the given +/// attributes. +export function wrapIn(nodeType: NodeType, attrs: Attrs | null = null): Command { + return function(state, dispatch) { + let {$from, $to} = state.selection + let range = $from.blockRange($to), wrapping = range && findWrapping(range, nodeType, attrs) + if (!wrapping) return false + if (dispatch) dispatch(state.tr.wrap(range!, wrapping).scrollIntoView()) + return true + } +} + +/// Returns a command that tries to set the selected textblocks to the +/// given node type with the given attributes. +export function setBlockType(nodeType: NodeType, attrs: Attrs | null = null): Command { + return function(state, dispatch) { + let applicable = false + for (let i = 0; i < state.selection.ranges.length && !applicable; i++) { + let {$from: {pos: from}, $to: {pos: to}} = state.selection.ranges[i] + state.doc.nodesBetween(from, to, (node, pos) => { + if (applicable) return false + if (!node.isTextblock || node.hasMarkup(nodeType, attrs)) return + if (node.type == nodeType) { + applicable = true + } else { + let $pos = state.doc.resolve(pos), index = $pos.index() + applicable = $pos.parent.canReplaceWith(index, index + 1, nodeType) + } + }) + } + if (!applicable) return false + if (dispatch) { + let tr = state.tr + for (let i = 0; i < state.selection.ranges.length; i++) { + let {$from: {pos: from}, $to: {pos: to}} = state.selection.ranges[i] + tr.setBlockType(from, to, nodeType, attrs) + } + dispatch(tr.scrollIntoView()) + } + return true + } +} + +function markApplies(doc: Node, ranges: readonly SelectionRange[], type: MarkType, enterAtoms: boolean) { + for (let i = 0; i < ranges.length; i++) { + let {$from, $to} = ranges[i] + let can = $from.depth == 0 ? doc.inlineContent && doc.type.allowsMarkType(type) : false + doc.nodesBetween($from.pos, $to.pos, (node, pos) => { + if (can || !enterAtoms && node.isAtom && node.isInline && pos >= $from.pos && pos + node.nodeSize <= $to.pos) + return false + can = node.inlineContent && node.type.allowsMarkType(type) + }) + if (can) return true + } + return false +} + +function removeInlineAtoms(ranges: readonly SelectionRange[]): readonly SelectionRange[] { + let result = [] + for (let i = 0; i < ranges.length; i++) { + let {$from, $to} = ranges[i] + $from.doc.nodesBetween($from.pos, $to.pos, (node, pos) => { + if (node.isAtom && node.content.size && node.isInline && pos >= $from.pos && pos + node.nodeSize <= $to.pos) { + if (pos + 1 > $from.pos) result.push(new SelectionRange($from, $from.doc.resolve(pos + 1))) + $from = $from.doc.resolve(pos + 1 + node.content.size) + return false + } + }) + if ($from.pos < $to.pos) result.push(new SelectionRange($from, $to)) + } + return result +} + +/// Create a command function that toggles the given mark with the +/// given attributes. Will return `false` when the current selection +/// doesn't support that mark. This will remove the mark if any marks +/// of that type exist in the selection, or add it otherwise. If the +/// selection is empty, this applies to the [stored +/// marks](#state.EditorState.storedMarks) instead of a range of the +/// document. +export function toggleMark(markType: MarkType, attrs: Attrs | null = null, options?: { + /// Controls whether, when part of the selected range has the mark + /// already and part doesn't, the mark is removed (`true`, the + /// default) or added (`false`). + removeWhenPresent?: boolean + /// When set to false, this will prevent the command from acting on + /// the content of inline nodes marked as + /// [atoms](#model.NodeSpec.atom) that are completely covered by a + /// selection range. + enterInlineAtoms?: boolean + /// By default, this command doesn't apply to leading and trailing + /// whitespace in the selection. Set this to `true` to change that. + includeWhitespace?: boolean +}): Command { + let removeWhenPresent = (options && options.removeWhenPresent) !== false + let enterAtoms = (options && options.enterInlineAtoms) !== false + let dropSpace = !(options && options.includeWhitespace) + return function(state, dispatch) { + let {empty, $cursor, ranges} = state.selection as TextSelection + if ((empty && !$cursor) || !markApplies(state.doc, ranges, markType, enterAtoms)) return false + if (dispatch) { + if ($cursor) { + if (markType.isInSet(state.storedMarks || $cursor.marks())) + dispatch(state.tr.removeStoredMark(markType)) + else + dispatch(state.tr.addStoredMark(markType.create(attrs))) + } else { + let add, tr = state.tr + if (!enterAtoms) ranges = removeInlineAtoms(ranges) + if (removeWhenPresent) { + add = !ranges.some(r => state.doc.rangeHasMark(r.$from.pos, r.$to.pos, markType)) + } else { + add = !ranges.every(r => { + let missing = false + tr.doc.nodesBetween(r.$from.pos, r.$to.pos, (node, pos, parent) => { + if (missing) return false + missing = !markType.isInSet(node.marks) && !!parent && parent.type.allowsMarkType(markType) && + !(node.isText && /^\s*$/.test(node.textBetween(Math.max(0, r.$from.pos - pos), + Math.min(node.nodeSize, r.$to.pos - pos)))) + }) + return !missing + }) + } + for (let i = 0; i < ranges.length; i++) { + let {$from, $to} = ranges[i] + if (!add) { + tr.removeMark($from.pos, $to.pos, markType) + } else { + let from = $from.pos, to = $to.pos, start = $from.nodeAfter, end = $to.nodeBefore + let spaceStart = dropSpace && start && start.isText ? /^\s*/.exec(start.text!)![0].length : 0 + let spaceEnd = dropSpace && end && end.isText ? /\s*$/.exec(end.text!)![0].length : 0 + if (from + spaceStart < to) { from += spaceStart; to -= spaceEnd } + tr.addMark(from, to, markType.create(attrs)) + } + } + dispatch(tr.scrollIntoView()) + } + } + return true + } +} + +function wrapDispatchForJoin(dispatch: (tr: Transaction) => void, isJoinable: (a: Node, b: Node) => boolean) { + return (tr: Transaction) => { + if (!tr.isGeneric) return dispatch(tr) + + let ranges: number[] = [] + for (let i = 0; i < tr.mapping.maps.length; i++) { + let map = tr.mapping.maps[i] + for (let j = 0; j < ranges.length; j++) + ranges[j] = map.map(ranges[j]) + map.forEach((_s, _e, from, to) => ranges.push(from, to)) + } + + // Figure out which joinable points exist inside those ranges, + // by checking all node boundaries in their parent nodes. + let joinable = [] + for (let i = 0; i < ranges.length; i += 2) { + let from = ranges[i], to = ranges[i + 1] + let $from = tr.doc.resolve(from), depth = $from.sharedDepth(to), parent = $from.node(depth) + for (let index = $from.indexAfter(depth), pos = $from.after(depth + 1); pos <= to; ++index) { + let after = parent.maybeChild(index) + if (!after) break + if (index && joinable.indexOf(pos) == -1) { + let before = parent.child(index - 1) + if (before.type == after.type && isJoinable(before, after)) + joinable.push(pos) + } + pos += after.nodeSize + } + } + // Join the joinable points + joinable.sort((a, b) => a - b) + for (let i = joinable.length - 1; i >= 0; i--) { + if (canJoin(tr.doc, joinable[i])) tr.join(joinable[i]) + } + dispatch(tr) + } +} + +/// Wrap a command so that, when it produces a transform that causes +/// two joinable nodes to end up next to each other, those are joined. +/// Nodes are considered joinable when they are of the same type and +/// when the `isJoinable` predicate returns true for them or, if an +/// array of strings was passed, if their node type name is in that +/// array. +export function autoJoin( + command: Command, + isJoinable: ((before: Node, after: Node) => boolean) | readonly string[] +): Command { + let canJoin = Array.isArray(isJoinable) ? (node: Node) => isJoinable.indexOf(node.type.name) > -1 + : isJoinable as (a: Node, b: Node) => boolean + return (state, dispatch, view) => command(state, dispatch && wrapDispatchForJoin(dispatch, canJoin), view) +} + +/// Combine a number of command functions into a single function (which +/// calls them one by one until one returns true). +export function chainCommands(...commands: readonly Command[]): Command { + return function(state, dispatch, view) { + for (let i = 0; i < commands.length; i++) + if (commands[i](state, dispatch, view)) return true + return false + } +} + +let backspace = chainCommands(deleteSelection, joinBackward, selectNodeBackward) +let del = chainCommands(deleteSelection, joinForward, selectNodeForward) + +/// A basic keymap containing bindings not specific to any schema. +/// Binds the following keys (when multiple commands are listed, they +/// are chained with [`chainCommands`](#commands.chainCommands)): +/// +/// * **Enter** to `newlineInCode`, `createParagraphNear`, `liftEmptyBlock`, `splitBlock` +/// * **Mod-Enter** to `exitCode` +/// * **Backspace** and **Mod-Backspace** to `deleteSelection`, `joinBackward`, `selectNodeBackward` +/// * **Delete** and **Mod-Delete** to `deleteSelection`, `joinForward`, `selectNodeForward` +/// * **Mod-Delete** to `deleteSelection`, `joinForward`, `selectNodeForward` +/// * **Mod-a** to `selectAll` +export const pcBaseKeymap: {[key: string]: Command} = { + "Enter": chainCommands(newlineInCode, createParagraphNear, liftEmptyBlock, splitBlock), + "Mod-Enter": exitCode, + "Backspace": backspace, + "Mod-Backspace": backspace, + "Shift-Backspace": backspace, + "Delete": del, + "Mod-Delete": del, + "Mod-a": selectAll +} + +/// A copy of `pcBaseKeymap` that also binds **Ctrl-h** like Backspace, +/// **Ctrl-d** like Delete, **Alt-Backspace** like Ctrl-Backspace, and +/// **Ctrl-Alt-Backspace**, **Alt-Delete**, and **Alt-d** like +/// Ctrl-Delete. +export const macBaseKeymap: {[key: string]: Command} = { + "Ctrl-h": pcBaseKeymap["Backspace"], + "Alt-Backspace": pcBaseKeymap["Mod-Backspace"], + "Ctrl-d": pcBaseKeymap["Delete"], + "Ctrl-Alt-Backspace": pcBaseKeymap["Mod-Delete"], + "Alt-Delete": pcBaseKeymap["Mod-Delete"], + "Alt-d": pcBaseKeymap["Mod-Delete"], + "Ctrl-a": selectTextblockStart, + "Ctrl-e": selectTextblockEnd +} +for (let key in pcBaseKeymap) (macBaseKeymap as any)[key] = pcBaseKeymap[key] + +const mac = typeof navigator != "undefined" ? /Mac|iP(hone|[oa]d)/.test(navigator.platform) + // @ts-ignore + : typeof os != "undefined" && os.platform ? os.platform() == "darwin" : false + +/// Depending on the detected platform, this will hold +/// [`pcBasekeymap`](#commands.pcBaseKeymap) or +/// [`macBaseKeymap`](#commands.macBaseKeymap). +export const baseKeymap: {[key: string]: Command} = mac ? macBaseKeymap : pcBaseKeymap diff --git a/packages/webui/third_party/editor/prosemirror-history/LICENSE b/packages/webui/third_party/editor/prosemirror-history/LICENSE new file mode 100644 index 000000000..7e2295b30 --- /dev/null +++ b/packages/webui/third_party/editor/prosemirror-history/LICENSE @@ -0,0 +1,19 @@ +Copyright (C) 2015-2017 by Marijn Haverbeke and others + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/packages/webui/third_party/editor/prosemirror-history/package.json b/packages/webui/third_party/editor/prosemirror-history/package.json new file mode 100644 index 000000000..e75e9ce7b --- /dev/null +++ b/packages/webui/third_party/editor/prosemirror-history/package.json @@ -0,0 +1,40 @@ +{ + "name": "prosemirror-history", + "version": "1.5.1", + "description": "Undo history for ProseMirror", + "type": "module", + "main": "dist/index.cjs", + "module": "dist/index.js", + "types": "dist/index.d.ts", + "exports": { + "import": "./dist/index.js", + "require": "./dist/index.cjs" + }, + "sideEffects": false, + "license": "MIT", + "maintainers": [ + { + "name": "Marijn Haverbeke", + "email": "marijn@haverbeke.berlin", + "web": "http://marijnhaverbeke.nl" + } + ], + "repository": { + "type": "git", + "url": "git+https://code.haverbeke.berlin/prosemirror/prosemirror-history.git" + }, + "dependencies": { + "prosemirror-state": "^1.2.2", + "prosemirror-transform": "^1.0.0", + "prosemirror-view": "^1.31.0", + "rope-sequence": "^1.3.0" + }, + "devDependencies": { + "@prosemirror/buildhelper": "^0.1.5", + "prosemirror-test-builder": "^1.0.0" + }, + "scripts": { + "test": "pm-runtests", + "prepare": "pm-buildhelper src/history.ts" + } +} diff --git a/packages/webui/third_party/editor/prosemirror-history/src/history.ts b/packages/webui/third_party/editor/prosemirror-history/src/history.ts new file mode 100644 index 000000000..3924e56ea --- /dev/null +++ b/packages/webui/third_party/editor/prosemirror-history/src/history.ts @@ -0,0 +1,466 @@ +import RopeSequence from "rope-sequence" +import {Mapping, Step, StepMap, Transform} from "prosemirror-transform" +import {Plugin, Command, PluginKey, EditorState, Transaction, SelectionBookmark} from "prosemirror-state" + +// ProseMirror's history isn't simply a way to roll back to a previous +// state, because ProseMirror supports applying changes without adding +// them to the history (for example during collaboration). +// +// To this end, each 'Branch' (one for the undo history and one for +// the redo history) keeps an array of 'Items', which can optionally +// hold a step (an actual undoable change), and always hold a position +// map (which is needed to move changes below them to apply to the +// current document). +// +// An item that has both a step and a selection bookmark is the start +// of an 'event' — a group of changes that will be undone or redone at +// once. (It stores only the bookmark, since that way we don't have to +// provide a document until the selection is actually applied, which +// is useful when compressing.) + +// Used to schedule history compression +const max_empty_items = 500 + +class Branch { + constructor(readonly items: RopeSequence, readonly eventCount: number) {} + + // Pop the latest event off the branch's history and apply it + // to a document transform. + popEvent(state: EditorState, preserveItems: boolean) { + if (this.eventCount == 0) return null + + let end = this.items.length + for (;; end--) { + let next = this.items.get(end - 1) + if (next.selection) { --end; break } + } + + let remap: Mapping | undefined, mapFrom: number | undefined + if (preserveItems) { + remap = this.remapping(end, this.items.length) + mapFrom = remap.maps.length + } + let transform = state.tr + let selection: SelectionBookmark | undefined, remaining: Branch | undefined + let addAfter: Item[] = [], addBefore: Item[] = [] + + this.items.forEach((item, i) => { + if (!item.step) { + if (!remap) { + remap = this.remapping(end, i + 1) + mapFrom = remap.maps.length + } + mapFrom!-- + addBefore.push(item) + return + } + + if (remap) { + addBefore.push(new Item(item.map)) + let step = item.step.map(remap.slice(mapFrom)), map + + if (step && transform.maybeStep(step).doc) { + map = transform.mapping.maps[transform.mapping.maps.length - 1] + addAfter.push(new Item(map, undefined, undefined, addAfter.length + addBefore.length)) + } + mapFrom!-- + if (map) remap.appendMap(map, mapFrom) + } else { + transform.maybeStep(item.step) + } + + if (item.selection) { + selection = remap ? item.selection.map(remap.slice(mapFrom)) : item.selection + remaining = new Branch(this.items.slice(0, end).append(addBefore.reverse().concat(addAfter)), this.eventCount - 1) + return false + } + }, this.items.length, 0) + + return {remaining: remaining!, transform, selection: selection!} + } + + // Create a new branch with the given transform added. + addTransform(transform: Transform, selection: SelectionBookmark | undefined, + histOptions: Required, preserveItems: boolean) { + let newItems = [], eventCount = this.eventCount + let oldItems = this.items, lastItem = !preserveItems && oldItems.length ? oldItems.get(oldItems.length - 1) : null + + for (let i = 0; i < transform.steps.length; i++) { + let step = transform.steps[i].invert(transform.docs[i]) + let item = new Item(transform.mapping.maps[i], step, selection), merged + if (merged = lastItem && lastItem.merge(item)) { + item = merged + if (i) newItems.pop() + else oldItems = oldItems.slice(0, oldItems.length - 1) + } + newItems.push(item) + if (selection) { + eventCount++ + selection = undefined + } + if (!preserveItems) lastItem = item + } + let overflow = eventCount - histOptions.depth + if (overflow > DEPTH_OVERFLOW) { + oldItems = cutOffEvents(oldItems, overflow) + eventCount -= overflow + } + return new Branch(oldItems.append(newItems), eventCount) + } + + remapping(from: number, to: number): Mapping { + let maps = new Mapping + this.items.forEach((item, i) => { + let mirrorPos = item.mirrorOffset != null && i - item.mirrorOffset >= from + ? maps.maps.length - item.mirrorOffset : undefined + maps.appendMap(item.map, mirrorPos) + }, from, to) + return maps + } + + addMaps(array: readonly StepMap[]) { + if (this.eventCount == 0) return this + return new Branch(this.items.append(array.map(map => new Item(map))), this.eventCount) + } + + // When the collab module receives remote changes, the history has + // to know about those, so that it can adjust the steps that were + // rebased on top of the remote changes, and include the position + // maps for the remote changes in its array of items. + rebased(rebasedTransform: Transform, rebasedCount: number) { + if (!this.eventCount) return this + + rebasedCount = Math.min(this.items.length, rebasedCount) + let rebasedItems: Item[] = [], start = this.items.length - rebasedCount + + let mapping = rebasedTransform.mapping + let newUntil = rebasedTransform.steps.length + let eventCount = this.eventCount + this.items.forEach(item => { if (item.selection) eventCount-- }, start) + + let iRebased = rebasedCount + this.items.forEach(item => { + let pos = mapping.getMirror(--iRebased) + if (pos == null) return + newUntil = Math.min(newUntil, pos) + let map = mapping.maps[pos] + if (item.step) { + let step = rebasedTransform.steps[pos].invert(rebasedTransform.docs[pos]) + let selection = item.selection && item.selection.map(mapping.slice(iRebased + 1, pos)) + if (selection) eventCount++ + rebasedItems.push(new Item(map, step, selection)) + } else { + rebasedItems.push(new Item(map)) + } + }, start) + + let newMaps = [] + for (let i = rebasedCount; i < newUntil; i++) + newMaps.push(new Item(mapping.maps[i])) + let items = this.items.slice(0, start).append(newMaps).append(rebasedItems) + let branch = new Branch(items, eventCount) + + if (branch.emptyItemCount() > max_empty_items) + branch = branch.compress(this.items.length - rebasedItems.length) + return branch + } + + emptyItemCount() { + let count = 0 + this.items.forEach(item => { if (!item.step) count++ }) + return count + } + + // Compressing a branch means rewriting it to push the air (map-only + // items) out. During collaboration, these naturally accumulate + // because each remote change adds one. The `upto` argument is used + // to ensure that only the items below a given level are compressed, + // because `rebased` relies on a clean, untouched set of items in + // order to associate old items with rebased steps. + compress(upto = this.items.length) { + let remap = this.remapping(0, upto), mapFrom = remap.maps.length + let items: Item[] = [], events = 0 + this.items.forEach((item, i) => { + if (i >= upto) { + items.push(item) + if (item.selection) events++ + } else if (item.step) { + let step = item.step.map(remap.slice(mapFrom)), map = step && step.getMap() + mapFrom-- + if (map) remap.appendMap(map, mapFrom) + if (step) { + let selection = item.selection && item.selection.map(remap.slice(mapFrom)) + if (selection) events++ + let newItem = new Item(map!.invert(), step, selection), merged, last = items.length - 1 + if (merged = items.length && items[last].merge(newItem)) + items[last] = merged + else + items.push(newItem) + } + } else if (item.map) { + mapFrom-- + } + }, this.items.length, 0) + return new Branch(RopeSequence.from(items.reverse()), events) + } + + static empty = new Branch(RopeSequence.empty, 0) +} + +function cutOffEvents(items: RopeSequence, n: number) { + let cutPoint: number | undefined + items.forEach((item, i) => { + if (item.selection && (n-- == 0)) { + cutPoint = i + return false + } + }) + return items.slice(cutPoint!) +} + +class Item { + constructor( + // The (forward) step map for this item. + readonly map: StepMap, + // The inverted step + readonly step?: Step, + // If this is non-null, this item is the start of a group, and + // this selection is the starting selection for the group (the one + // that was active before the first step was applied) + readonly selection?: SelectionBookmark, + // If this item is the inverse of a previous mapping on the stack, + // this points at the inverse's offset + readonly mirrorOffset?: number + ) {} + + merge(other: Item) { + if (this.step && other.step && !other.selection) { + let step = other.step.merge(this.step) + if (step) return new Item(step.getMap().invert(), step, this.selection) + } + } +} + +// The value of the state field that tracks undo/redo history for that +// state. Will be stored in the plugin state when the history plugin +// is active. +class HistoryState { + constructor( + readonly done: Branch, + readonly undone: Branch, + readonly prevRanges: readonly number[] | null, + readonly prevTime: number, + readonly prevComposition: number + ) {} +} + +const DEPTH_OVERFLOW = 20 + +// Record a transformation in undo history. +function applyTransaction(history: HistoryState, state: EditorState, tr: Transaction, options: Required) { + let historyTr = tr.getMeta(historyKey), rebased + if (historyTr) return historyTr.historyState + + if (tr.getMeta(closeHistoryKey)) history = new HistoryState(history.done, history.undone, null, 0, -1) + + let appended = tr.getMeta("appendedTransaction") + + if (tr.steps.length == 0) { + return history + } else if (appended && appended.getMeta(historyKey)) { + if (appended.getMeta(historyKey).redo) + return new HistoryState(history.done.addTransform(tr, undefined, options, mustPreserveItems(state)), + history.undone, rangesFor(tr.mapping.maps), + history.prevTime, history.prevComposition) + else + return new HistoryState(history.done, history.undone.addTransform(tr, undefined, options, mustPreserveItems(state)), + null, history.prevTime, history.prevComposition) + } else if (tr.getMeta("addToHistory") !== false && !(appended && appended.getMeta("addToHistory") === false)) { + // Group transforms that occur in quick succession into one event. + let composition = tr.getMeta("composition") + let newGroup = history.prevTime == 0 || + (!appended && history.prevComposition != composition && + (history.prevTime < (tr.time || 0) - options.newGroupDelay || !isAdjacentTo(tr, history.prevRanges!))) + let prevRanges = appended ? mapRanges(history.prevRanges!, tr.mapping) : rangesFor(tr.mapping.maps) + return new HistoryState(history.done.addTransform(tr, newGroup ? state.selection.getBookmark() : undefined, + options, mustPreserveItems(state)), + Branch.empty, prevRanges, tr.time, composition == null ? history.prevComposition : composition) + } else if (rebased = tr.getMeta("rebased")) { + // Used by the collab module to tell the history that some of its + // content has been rebased. + return new HistoryState(history.done.rebased(tr, rebased), + history.undone.rebased(tr, rebased), + mapRanges(history.prevRanges!, tr.mapping), history.prevTime, history.prevComposition) + } else { + return new HistoryState(history.done.addMaps(tr.mapping.maps), + history.undone.addMaps(tr.mapping.maps), + mapRanges(history.prevRanges!, tr.mapping), history.prevTime, history.prevComposition) + } +} + +function isAdjacentTo(transform: Transform, prevRanges: readonly number[]) { + if (!prevRanges) return false + if (!transform.docChanged) return true + let adjacent = false + transform.mapping.maps[0].forEach((start, end) => { + for (let i = 0; i < prevRanges.length; i += 2) + if (start <= prevRanges[i + 1] && end >= prevRanges[i]) + adjacent = true + }) + return adjacent +} + +function rangesFor(maps: readonly StepMap[]) { + let result: number[] = [] + for (let i = maps.length - 1; i >= 0 && result.length == 0; i--) + maps[i].forEach((_from, _to, from, to) => result.push(from, to)) + return result +} + +function mapRanges(ranges: readonly number[], mapping: Mapping) { + if (!ranges) return null + let result = [] + for (let i = 0; i < ranges.length; i += 2) { + let from = mapping.map(ranges[i], 1), to = mapping.map(ranges[i + 1], -1) + if (from <= to) result.push(from, to) + } + return result +} + +// Apply the latest event from one branch to the document and shift the event +// onto the other branch. +function histTransaction(history: HistoryState, state: EditorState, redo: boolean): Transaction | null { + let preserveItems = mustPreserveItems(state) + let histOptions = (historyKey.get(state)!.spec as any).config as Required + let pop = (redo ? history.undone : history.done).popEvent(state, preserveItems) + if (!pop) return null + + let selection = pop.selection!.resolve(pop.transform.doc) + let added = (redo ? history.done : history.undone).addTransform(pop.transform, state.selection.getBookmark(), + histOptions, preserveItems) + + let newHist = new HistoryState(redo ? added : pop.remaining, redo ? pop.remaining : added, null, 0, -1) + return pop.transform.setSelection(selection).setMeta(historyKey, {redo, historyState: newHist}) +} + +let cachedPreserveItems = false, cachedPreserveItemsPlugins: readonly Plugin[] | null = null +// Check whether any plugin in the given state has a +// `historyPreserveItems` property in its spec, in which case we must +// preserve steps exactly as they came in, so that they can be +// rebased. +function mustPreserveItems(state: EditorState) { + let plugins = state.plugins + if (cachedPreserveItemsPlugins != plugins) { + cachedPreserveItems = false + cachedPreserveItemsPlugins = plugins + for (let i = 0; i < plugins.length; i++) if ((plugins[i].spec as any).historyPreserveItems) { + cachedPreserveItems = true + break + } + } + return cachedPreserveItems +} + +/// Set a flag on the given transaction that will prevent further steps +/// from being appended to an existing history event (so that they +/// require a separate undo command to undo). +export function closeHistory(tr: Transaction) { + return tr.setMeta(closeHistoryKey, true) +} + +const historyKey = new PluginKey("history") +const closeHistoryKey = new PluginKey("closeHistory") + +interface HistoryOptions { + /// The amount of history events that are collected before the + /// oldest events are discarded. Defaults to 100. + depth?: number + + /// The delay between changes after which a new group should be + /// started. Defaults to 500 (milliseconds). Note that when changes + /// aren't adjacent, a new group is always started. + newGroupDelay?: number +} + +/// Returns a plugin that enables the undo history for an editor. The +/// plugin will track undo and redo stacks, which can be used with the +/// [`undo`](#history.undo) and [`redo`](#history.redo) commands. +/// +/// You can set an `"addToHistory"` [metadata +/// property](#state.Transaction.setMeta) of `false` on a transaction +/// to prevent it from being rolled back by undo. +export function history(config: HistoryOptions = {}): Plugin { + config = {depth: config.depth || 100, + newGroupDelay: config.newGroupDelay || 500} + + return new Plugin({ + key: historyKey, + + state: { + init() { + return new HistoryState(Branch.empty, Branch.empty, null, 0, -1) + }, + apply(tr, hist, state) { + return applyTransaction(hist, state, tr, config as Required) + } + }, + + config, + + props: { + handleDOMEvents: { + beforeinput(view, e: Event) { + let inputType = (e as InputEvent).inputType + let command = inputType == "historyUndo" ? undo : inputType == "historyRedo" ? redo : null + if (!command || !view.editable) return false + e.preventDefault() + return command(view.state, view.dispatch) + } + } + } + }) +} + +function buildCommand(redo: boolean, scroll: boolean): Command { + return (state, dispatch) => { + let hist = historyKey.getState(state) + if (!hist || (redo ? hist.undone : hist.done).eventCount == 0) return false + if (dispatch) { + let tr = histTransaction(hist, state, redo) + if (tr) dispatch(scroll ? tr.scrollIntoView() : tr) + } + return true + } +} + +/// A command function that undoes the last change, if any. +export const undo = buildCommand(false, true) + +/// A command function that redoes the last undone change, if any. +export const redo = buildCommand(true, true) + +/// A command function that undoes the last change. Don't scroll the +/// selection into view. +export const undoNoScroll = buildCommand(false, false) + +/// A command function that redoes the last undone change. Don't +/// scroll the selection into view. +export const redoNoScroll = buildCommand(true, false) + +/// The amount of undoable events available in a given state. +export function undoDepth(state: EditorState) { + let hist = historyKey.getState(state) + return hist ? hist.done.eventCount : 0 +} + +/// The amount of redoable events available in a given editor state. +export function redoDepth(state: EditorState) { + let hist = historyKey.getState(state) + return hist ? hist.undone.eventCount : 0 +} + +/// Returns true if the given transaction was generated by the history +/// plugin. +export function isHistoryTransaction(tr: Transaction) { + return tr.getMeta(historyKey) != null +} diff --git a/packages/webui/third_party/editor/prosemirror-inputrules/LICENSE b/packages/webui/third_party/editor/prosemirror-inputrules/LICENSE new file mode 100644 index 000000000..7e2295b30 --- /dev/null +++ b/packages/webui/third_party/editor/prosemirror-inputrules/LICENSE @@ -0,0 +1,19 @@ +Copyright (C) 2015-2017 by Marijn Haverbeke and others + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/packages/webui/third_party/editor/prosemirror-inputrules/package.json b/packages/webui/third_party/editor/prosemirror-inputrules/package.json new file mode 100644 index 000000000..52fdf409a --- /dev/null +++ b/packages/webui/third_party/editor/prosemirror-inputrules/package.json @@ -0,0 +1,36 @@ +{ + "name": "prosemirror-inputrules", + "version": "1.5.1", + "description": "Automatic transforms on text input for ProseMirror", + "type": "module", + "main": "dist/index.cjs", + "module": "dist/index.js", + "types": "dist/index.d.ts", + "exports": { + "import": "./dist/index.js", + "require": "./dist/index.cjs" + }, + "sideEffects": false, + "license": "MIT", + "maintainers": [ + { + "name": "Marijn Haverbeke", + "email": "marijn@haverbeke.berlin", + "web": "http://marijnhaverbeke.nl" + } + ], + "repository": { + "type": "git", + "url": "git://github.com/prosemirror/prosemirror-inputrules.git" + }, + "dependencies": { + "prosemirror-state": "^1.0.0", + "prosemirror-transform": "^1.0.0" + }, + "devDependencies": { + "@prosemirror/buildhelper": "^0.1.5" + }, + "scripts": { + "prepare": "pm-buildhelper src/index.ts" + } +} diff --git a/packages/webui/third_party/editor/prosemirror-inputrules/src/index.ts b/packages/webui/third_party/editor/prosemirror-inputrules/src/index.ts new file mode 100644 index 000000000..2d82a9747 --- /dev/null +++ b/packages/webui/third_party/editor/prosemirror-inputrules/src/index.ts @@ -0,0 +1,4 @@ +export {InputRule, inputRules, undoInputRule} from "./inputrules" +export {emDash, ellipsis, openDoubleQuote, closeDoubleQuote, openSingleQuote, closeSingleQuote, + smartQuotes} from "./rules" +export {wrappingInputRule, textblockTypeInputRule} from "./rulebuilders" diff --git a/packages/webui/third_party/editor/prosemirror-inputrules/src/inputrules.ts b/packages/webui/third_party/editor/prosemirror-inputrules/src/inputrules.ts new file mode 100644 index 000000000..6a64b331c --- /dev/null +++ b/packages/webui/third_party/editor/prosemirror-inputrules/src/inputrules.ts @@ -0,0 +1,167 @@ +import {Plugin, Transaction, EditorState, TextSelection, Command} from "prosemirror-state" +import {EditorView} from "prosemirror-view" + +/// Input rules are regular expressions describing a piece of text +/// that, when typed, causes something to happen. This might be +/// changing two dashes into an emdash, wrapping a paragraph starting +/// with `"> "` into a blockquote, or something entirely different. +export class InputRule { + /// @internal + handler: (state: EditorState, match: RegExpMatchArray, start: number, end: number) => Transaction | null + + /// @internal + undoable: boolean + inCode: boolean | "only" + inCodeMark: boolean | "only" + + /// Create an input rule. The rule applies when the user typed + /// something and the text directly in front of the cursor matches + /// `match`, which should end with `$`. + /// + /// The `handler` can be a string, in which case the matched text, or + /// the first matched group in the regexp, is replaced by that + /// string. + /// + /// Or a it can be a function, which will be called with the match + /// array produced by + /// [`RegExp.exec`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec), + /// as well as the start and end of the matched range, and which can + /// return a [transaction](#state.Transaction) that describes the + /// rule's effect, or null to indicate the input was not handled. + constructor( + /// @internal + readonly match: RegExp, + handler: string | ((state: EditorState, match: RegExpMatchArray, start: number, end: number) => Transaction | null), + options: { + /// When set to false, + /// [`undoInputRule`](#inputrules.undoInputRule) doesn't work on + /// this rule. + undoable?: boolean, + /// By default, input rules will not apply inside nodes marked + /// as [code](#model.NodeSpec.code). Set this to true to change + /// that, or to `"only"` to _only_ match in such nodes. + inCode?: boolean | "only" + /// When set to `false`, this rule will not fire inside marks + /// marked as [code](#model.MarkSpec.code). The default is + /// `true`. + inCodeMark?: boolean + } = {} + ) { + this.match = match + this.handler = typeof handler == "string" ? stringHandler(handler) : handler + this.undoable = options.undoable !== false + this.inCode = options.inCode || false + this.inCodeMark = options.inCodeMark !== false + } +} + +function stringHandler(string: string) { + return function(state: EditorState, match: RegExpMatchArray, start: number, end: number) { + let insert = string + if (match[1]) { + let offset = match[0].lastIndexOf(match[1]) + insert += match[0].slice(offset + match[1].length) + start += offset + let cutOff = start - end + if (cutOff > 0) { + insert = match[0].slice(offset - cutOff, offset) + insert + start = end + } + } + return state.tr.insertText(insert, start, end) + } +} + +const MAX_MATCH = 500 + +type PluginState = {transform: Transaction, from: number, to: number, text: string} | null + +/// Create an input rules plugin. When enabled, it will cause text +/// input that matches any of the given rules to trigger the rule's +/// action. +export function inputRules({rules}: {rules: readonly InputRule[]}) { + let plugin: Plugin = new Plugin({ + state: { + init() { return null }, + apply(this: typeof plugin, tr, prev) { + let stored = tr.getMeta(this) + if (stored) return stored + return tr.selectionSet || tr.docChanged ? null : prev + } + }, + + props: { + handleTextInput(view, from, to, text) { + return run(view, from, to, text, rules, plugin) + }, + handleDOMEvents: { + compositionend: (view) => { + setTimeout(() => { + let {$cursor} = view.state.selection as TextSelection + if ($cursor) run(view, $cursor.pos, $cursor.pos, "", rules, plugin) + }) + } + } + }, + + isInputRules: true + }) + return plugin +} + +function run(view: EditorView, from: number, to: number, text: string, rules: readonly InputRule[], plugin: Plugin) { + if (view.composing) return false + let state = view.state, $from = state.doc.resolve(from) + let textBefore = $from.parent.textBetween(Math.max(0, $from.parentOffset - MAX_MATCH), $from.parentOffset, + null, "\ufffc") + text + for (let i = 0; i < rules.length; i++) { + let rule = rules[i]; + if (!rule.inCodeMark && $from.marks().some(m => m.type.spec.code)) continue + if ($from.parent.type.spec.code) { + if (!rule.inCode) continue + } else if (rule.inCode === "only") { + continue + } + let match = rule.match.exec(textBefore) + if (!match || match[0].length < text.length) continue + let startPos = from - (match[0].length - text.length) + if (!rule.inCodeMark) { + let hasMark = false + state.doc.nodesBetween(startPos, $from.pos, node => { + if (node.isInline && node.marks.some(m => m.type.spec.code)) hasMark = true + }) + if (hasMark) continue + } + let tr = rule.handler(state, match, startPos, to) + if (!tr) continue + if (rule.undoable) tr.setMeta(plugin, {transform: tr, from, to, text}) + view.dispatch(tr) + return true + } + return false +} + +/// This is a command that will undo an input rule, if applying such a +/// rule was the last thing that the user did. +export const undoInputRule: Command = (state, dispatch) => { + let plugins = state.plugins + for (let i = 0; i < plugins.length; i++) { + let plugin = plugins[i], undoable + if ((plugin.spec as any).isInputRules && (undoable = plugin.getState(state))) { + if (dispatch) { + let tr = state.tr, toUndo = undoable.transform + for (let j = toUndo.steps.length - 1; j >= 0; j--) + tr.step(toUndo.steps[j].invert(toUndo.docs[j])) + if (undoable.text) { + let marks = tr.doc.resolve(undoable.from).marks() + tr.replaceWith(undoable.from, undoable.to, state.schema.text(undoable.text, marks)) + } else { + tr.delete(undoable.from, undoable.to) + } + dispatch(tr) + } + return true + } + } + return false +} diff --git a/packages/webui/third_party/editor/prosemirror-inputrules/src/rulebuilders.ts b/packages/webui/third_party/editor/prosemirror-inputrules/src/rulebuilders.ts new file mode 100644 index 000000000..d17328ccd --- /dev/null +++ b/packages/webui/third_party/editor/prosemirror-inputrules/src/rulebuilders.ts @@ -0,0 +1,59 @@ +import {InputRule} from "./inputrules" +import {findWrapping, canJoin} from "prosemirror-transform" +import {NodeType, Node, Attrs} from "prosemirror-model" + +/// Build an input rule for automatically wrapping a textblock when a +/// given string is typed. The `regexp` argument is +/// directly passed through to the `InputRule` constructor. You'll +/// probably want the regexp to start with `^`, so that the pattern can +/// only occur at the start of a textblock. +/// +/// `nodeType` is the type of node to wrap in. If it needs attributes, +/// you can either pass them directly, or pass a function that will +/// compute them from the regular expression match. +/// +/// By default, if there's a node with the same type above the newly +/// wrapped node, the rule will try to [join](#transform.Transform.join) those +/// two nodes. You can pass a join predicate, which takes a regular +/// expression match and the node before the wrapped node, and can +/// return a boolean to indicate whether a join should happen. +export function wrappingInputRule( + regexp: RegExp, + nodeType: NodeType, + getAttrs: Attrs | null | ((matches: RegExpMatchArray) => Attrs | null) = null, + joinPredicate?: (match: RegExpMatchArray, node: Node) => boolean +) { + return new InputRule(regexp, (state, match, start, end) => { + let attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs + let tr = state.tr.delete(start, end) + let $start = tr.doc.resolve(start), range = $start.blockRange(), wrapping = range && findWrapping(range, nodeType, attrs) + if (!wrapping) return null + tr.wrap(range!, wrapping) + let before = tr.doc.resolve(start - 1).nodeBefore + if (before && before.type == nodeType && canJoin(tr.doc, start - 1) && + (!joinPredicate || joinPredicate(match, before))) + tr.join(start - 1) + return tr + }) +} + +/// Build an input rule that changes the type of a textblock when the +/// matched text is typed into it. You'll usually want to start your +/// regexp with `^` to that it is only matched at the start of a +/// textblock. The optional `getAttrs` parameter can be used to compute +/// the new node's attributes, and works the same as in the +/// `wrappingInputRule` function. +export function textblockTypeInputRule( + regexp: RegExp, + nodeType: NodeType, + getAttrs: Attrs | null | ((match: RegExpMatchArray) => Attrs | null) = null +) { + return new InputRule(regexp, (state, match, start, end) => { + let $start = state.doc.resolve(start) + let attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs + if (!$start.node(-1).canReplaceWith($start.index(-1), $start.indexAfter(-1), nodeType)) return null + return state.tr + .delete(start, end) + .setBlockType(start, start, nodeType, attrs) + }) +} diff --git a/packages/webui/third_party/editor/prosemirror-inputrules/src/rules.ts b/packages/webui/third_party/editor/prosemirror-inputrules/src/rules.ts new file mode 100644 index 000000000..ab8188906 --- /dev/null +++ b/packages/webui/third_party/editor/prosemirror-inputrules/src/rules.ts @@ -0,0 +1,17 @@ +import {InputRule} from "./inputrules" + +/// Converts double dashes to an emdash. +export const emDash = new InputRule(/--$/, "—", {inCodeMark: false}) +/// Converts three dots to an ellipsis character. +export const ellipsis = new InputRule(/\.\.\.$/, "…", {inCodeMark: false}) +/// “Smart” opening double quotes. +export const openDoubleQuote = new InputRule(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/, "“", {inCodeMark: false}) +/// “Smart” closing double quotes. +export const closeDoubleQuote = new InputRule(/"$/, "”", {inCodeMark: false}) +/// “Smart” opening single quotes. +export const openSingleQuote = new InputRule(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/, "‘", {inCodeMark: false}) +/// “Smart” closing single quotes. +export const closeSingleQuote = new InputRule(/'$/, "’", {inCodeMark: false}) + +/// Smart-quote related input rules. +export const smartQuotes: readonly InputRule[] = [openDoubleQuote, closeDoubleQuote, openSingleQuote, closeSingleQuote] diff --git a/packages/webui/third_party/editor/prosemirror-keymap/LICENSE b/packages/webui/third_party/editor/prosemirror-keymap/LICENSE new file mode 100644 index 000000000..7e2295b30 --- /dev/null +++ b/packages/webui/third_party/editor/prosemirror-keymap/LICENSE @@ -0,0 +1,19 @@ +Copyright (C) 2015-2017 by Marijn Haverbeke and others + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/packages/webui/third_party/editor/prosemirror-keymap/package.json b/packages/webui/third_party/editor/prosemirror-keymap/package.json new file mode 100644 index 000000000..1f2a7cf48 --- /dev/null +++ b/packages/webui/third_party/editor/prosemirror-keymap/package.json @@ -0,0 +1,38 @@ +{ + "name": "prosemirror-keymap", + "version": "1.2.3", + "description": "Keymap plugin for ProseMirror", + "type": "module", + "main": "dist/index.cjs", + "module": "dist/index.js", + "types": "dist/index.d.ts", + "exports": { + "import": "./dist/index.js", + "require": "./dist/index.cjs" + }, + "sideEffects": false, + "license": "MIT", + "maintainers": [ + { + "name": "Marijn Haverbeke", + "email": "marijn@haverbeke.berlin", + "web": "http://marijnhaverbeke.nl" + } + ], + "repository": { + "type": "git", + "url": "git://github.com/prosemirror/prosemirror-keymap.git" + }, + "dependencies": { + "w3c-keyname": "^2.2.0", + "prosemirror-state": "^1.0.0" + }, + "devDependencies": { + "@prosemirror/buildhelper": "^0.1.5", + "prosemirror-test-builder": "^1.0.0" + }, + "scripts": { + "test": "pm-runtests", + "prepare": "pm-buildhelper src/keymap.ts" + } +} diff --git a/packages/webui/third_party/editor/prosemirror-keymap/src/keymap.ts b/packages/webui/third_party/editor/prosemirror-keymap/src/keymap.ts new file mode 100644 index 000000000..d0f29705c --- /dev/null +++ b/packages/webui/third_party/editor/prosemirror-keymap/src/keymap.ts @@ -0,0 +1,105 @@ +import {base, keyName} from "w3c-keyname" +import {Plugin, Command} from "prosemirror-state" +import {EditorView} from "prosemirror-view" + +const mac = typeof navigator != "undefined" && /Mac|iP(hone|[oa]d)/.test(navigator.platform) +const windows = typeof navigator != "undefined" && /Win/.test(navigator.platform) + +function normalizeKeyName(name: string) { + let parts = name.split(/-(?!$)/), result = parts[parts.length - 1] + if (result == "Space") result = " " + let alt, ctrl, shift, meta + for (let i = 0; i < parts.length - 1; i++) { + let mod = parts[i] + if (/^(cmd|meta|m)$/i.test(mod)) meta = true + else if (/^a(lt)?$/i.test(mod)) alt = true + else if (/^(c|ctrl|control)$/i.test(mod)) ctrl = true + else if (/^s(hift)?$/i.test(mod)) shift = true + else if (/^mod$/i.test(mod)) { if (mac) meta = true; else ctrl = true } + else throw new Error("Unrecognized modifier name: " + mod) + } + if (alt) result = "Alt-" + result + if (ctrl) result = "Ctrl-" + result + if (meta) result = "Meta-" + result + if (shift) result = "Shift-" + result + return result +} + +function normalize(map: {[key: string]: Command}) { + let copy: {[key: string]: Command} = Object.create(null) + for (let prop in map) copy[normalizeKeyName(prop)] = map[prop] + return copy +} + +function modifiers(name: string, event: KeyboardEvent, shift = true) { + if (event.altKey) name = "Alt-" + name + if (event.ctrlKey) name = "Ctrl-" + name + if (event.metaKey) name = "Meta-" + name + if (shift && event.shiftKey) name = "Shift-" + name + return name +} + +/// Create a keymap plugin for the given set of bindings. +/// +/// Bindings should map key names to [command](#commands)-style +/// functions, which will be called with `(EditorState, dispatch, +/// EditorView)` arguments, and should return true when they've handled +/// the key. Note that the view argument isn't part of the command +/// protocol, but can be used as an escape hatch if a binding needs to +/// directly interact with the UI. +/// +/// Key names may be strings like `"Shift-Ctrl-Enter"`—a key +/// identifier prefixed with zero or more modifiers. Key identifiers +/// are based on the strings that can appear in +/// [`KeyEvent.key`](https:///developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key). +/// Use lowercase letters to refer to letter keys (or uppercase letters +/// if you want shift to be held). You may use `"Space"` as an alias +/// for the `" "` name. +/// +/// Modifiers can be given in any order. `Shift-` (or `s-`), `Alt-` (or +/// `a-`), `Ctrl-` (or `c-` or `Control-`) and `Cmd-` (or `m-` or +/// `Meta-`) are recognized. For characters that are created by holding +/// shift, the `Shift-` prefix is implied, and should not be added +/// explicitly. +/// +/// You can use `Mod-` as a shorthand for `Cmd-` on Mac and `Ctrl-` on +/// other platforms. +/// +/// You can add multiple keymap plugins to an editor. The order in +/// which they appear determines their precedence (the ones early in +/// the array get to dispatch first). +export function keymap(bindings: {[key: string]: Command}): Plugin { + return new Plugin({props: {handleKeyDown: keydownHandler(bindings)}}) +} + +/// Given a set of bindings (using the same format as +/// [`keymap`](#keymap.keymap)), return a [keydown +/// handler](#view.EditorProps.handleKeyDown) that handles them. +export function keydownHandler(bindings: {[key: string]: Command}): (view: EditorView, event: KeyboardEvent) => boolean { + let map = normalize(bindings) + return function(view, event) { + let name = keyName(event), baseName, direct = map[modifiers(name, event)] + if (direct && direct(view.state, view.dispatch, view)) return true + // A character key + if (name.length == 1 && name != " ") { + if (event.shiftKey) { + // In case the name was already modified by shift, try looking + // it up without its shift modifier + let noShift = map[modifiers(name, event, false)] + if (noShift && noShift(view.state, view.dispatch, view)) return true + } + if ((event.altKey || event.metaKey || event.ctrlKey) && + // Ctrl-Alt may be used for AltGr on Windows + !(windows && event.ctrlKey && event.altKey) && + (baseName = base[event.keyCode]) && baseName != name) { + // Try falling back to the keyCode when there's a modifier + // active or the character produced isn't ASCII, and our table + // produces a different name from the the keyCode. See #668, + // #1060, #1529. + let fromCode = map[modifiers(baseName, event)] + if (fromCode && fromCode(view.state, view.dispatch, view)) return true + } + } + return false + } +} diff --git a/packages/webui/third_party/editor/prosemirror-markdown/LICENSE b/packages/webui/third_party/editor/prosemirror-markdown/LICENSE new file mode 100644 index 000000000..7e2295b30 --- /dev/null +++ b/packages/webui/third_party/editor/prosemirror-markdown/LICENSE @@ -0,0 +1,19 @@ +Copyright (C) 2015-2017 by Marijn Haverbeke and others + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/packages/webui/third_party/editor/prosemirror-markdown/package.json b/packages/webui/third_party/editor/prosemirror-markdown/package.json new file mode 100644 index 000000000..83262986c --- /dev/null +++ b/packages/webui/third_party/editor/prosemirror-markdown/package.json @@ -0,0 +1,40 @@ +{ + "name": "prosemirror-markdown", + "version": "1.13.8", + "description": "ProseMirror Markdown integration", + "type": "module", + "main": "dist/index.cjs", + "module": "dist/index.js", + "types": "dist/index.d.ts", + "exports": { + "import": "./dist/index.js", + "require": "./dist/index.cjs" + }, + "sideEffects": false, + "license": "MIT", + "maintainers": [ + { + "name": "Marijn Haverbeke", + "email": "marijn@haverbeke.berlin", + "web": "http://marijnhaverbeke.nl" + } + ], + "repository": { + "type": "git", + "url": "git+https://code.haverbeke.berlin/prosemirror/prosemirror-markdown.git" + }, + "dependencies": { + "markdown-it": "^14.0.0", + "prosemirror-model": "^1.25.0", + "@types/markdown-it": "^14.0.0" + }, + "devDependencies": { + "@prosemirror/buildhelper": "^0.1.5", + "prosemirror-test-builder": "^1.0.0", + "punycode": "^1.4.0" + }, + "scripts": { + "test": "pm-runtests", + "prepare": "pm-buildhelper src/index.ts" + } +} diff --git a/packages/webui/third_party/editor/prosemirror-markdown/src/from_markdown.ts b/packages/webui/third_party/editor/prosemirror-markdown/src/from_markdown.ts new file mode 100644 index 000000000..d29f9ac77 --- /dev/null +++ b/packages/webui/third_party/editor/prosemirror-markdown/src/from_markdown.ts @@ -0,0 +1,272 @@ +// @ts-ignore +import MarkdownIt from "markdown-it" +import Token from "markdown-it/lib/token.mjs" +import {schema} from "./schema" +import {Mark, MarkType, Node, Attrs, Schema, NodeType} from "prosemirror-model" + +function maybeMerge(a: Node, b: Node): Node | undefined { + if (a.isText && b.isText && Mark.sameSet(a.marks, b.marks)) + return (a as any).withText(a.text! + b.text!) +} + +// Object used to track the context of a running parse. +class MarkdownParseState { + stack: {type: NodeType, attrs: Attrs | null, content: Node[], marks: readonly Mark[]}[] + + constructor( + readonly schema: Schema, + readonly tokenHandlers: {[token: string]: (stat: MarkdownParseState, token: Token, tokens: Token[], i: number) => void} + ) { + this.stack = [{type: schema.topNodeType, attrs: null, content: [], marks: Mark.none}] + } + + top() { + return this.stack[this.stack.length - 1] + } + + push(elt: Node) { + if (this.stack.length) this.top().content.push(elt) + } + + // Adds the given text to the current position in the document, + // using the current marks as styling. + addText(text: string) { + if (!text) return + let top = this.top(), nodes = top.content, last = nodes[nodes.length - 1] + let node = this.schema.text(text, top.marks), merged + if (last && (merged = maybeMerge(last, node))) nodes[nodes.length - 1] = merged + else nodes.push(node) + } + + // Adds the given mark to the set of active marks. + openMark(mark: Mark) { + let top = this.top() + top.marks = mark.addToSet(top.marks) + } + + // Removes the given mark from the set of active marks. + closeMark(mark: MarkType) { + let top = this.top() + top.marks = mark.removeFromSet(top.marks) + } + + parseTokens(toks: Token[]) { + for (let i = 0; i < toks.length; i++) { + let tok = toks[i] + let handler = this.tokenHandlers[tok.type] + if (!handler) + throw new Error("Token type `" + tok.type + "` not supported by Markdown parser") + handler(this, tok, toks, i) + } + } + + // Add a node at the current position. + addNode(type: NodeType, attrs: Attrs | null, content?: readonly Node[]) { + let top = this.top() + let node = type.createAndFill(attrs, content, top ? top.marks : []) + if (!node) return null + this.push(node) + return node + } + + // Wrap subsequent content in a node of the given type. + openNode(type: NodeType, attrs: Attrs | null) { + this.stack.push({type: type, attrs: attrs, content: [], marks: Mark.none}) + } + + // Close and return the node that is currently on top of the stack. + closeNode() { + let info = this.stack.pop()! + return this.addNode(info.type, info.attrs, info.content) + } +} + +function attrs(spec: ParseSpec, token: Token, tokens: Token[], i: number) { + if (spec.getAttrs) return spec.getAttrs(token, tokens, i) + // For backwards compatibility when `attrs` is a Function + else if (spec.attrs instanceof Function) return spec.attrs(token) + else return spec.attrs +} + +// Code content is represented as a single token with a `content` +// property in Markdown-it. +function noCloseToken(spec: ParseSpec, type: string) { + return spec.noCloseToken || type == "code_inline" || type == "code_block" || type == "fence" +} + +function withoutTrailingNewline(str: string) { + return str[str.length - 1] == "\n" ? str.slice(0, str.length - 1) : str +} + +function noOp() {} + +function tokenHandlers(schema: Schema, tokens: {[token: string]: ParseSpec}) { + let handlers: {[token: string]: (stat: MarkdownParseState, token: Token, tokens: Token[], i: number) => void} = + Object.create(null) + for (let type in tokens) { + let spec = tokens[type] + if (spec.block) { + let nodeType = schema.nodeType(spec.block) + if (noCloseToken(spec, type)) { + handlers[type] = (state, tok, tokens, i) => { + state.openNode(nodeType, attrs(spec, tok, tokens, i)) + state.addText(withoutTrailingNewline(tok.content)) + state.closeNode() + } + } else { + handlers[type + "_open"] = (state, tok, tokens, i) => state.openNode(nodeType, attrs(spec, tok, tokens, i)) + handlers[type + "_close"] = state => state.closeNode() + } + } else if (spec.node) { + let nodeType = schema.nodeType(spec.node) + handlers[type] = (state, tok, tokens, i) => state.addNode(nodeType, attrs(spec, tok, tokens, i)) + } else if (spec.mark) { + let markType = schema.marks[spec.mark] + if (noCloseToken(spec, type)) { + handlers[type] = (state, tok, tokens, i) => { + state.openMark(markType.create(attrs(spec, tok, tokens, i))) + state.addText(withoutTrailingNewline(tok.content)) + state.closeMark(markType) + } + } else { + handlers[type + "_open"] = (state, tok, tokens, i) => state.openMark(markType.create(attrs(spec, tok, tokens, i))) + handlers[type + "_close"] = state => state.closeMark(markType) + } + } else if (spec.ignore) { + if (noCloseToken(spec, type)) { + handlers[type] = noOp + } else { + handlers[type + "_open"] = noOp + handlers[type + "_close"] = noOp + } + } else { + throw new RangeError("Unrecognized parsing spec " + JSON.stringify(spec)) + } + } + + handlers.text = (state, tok) => state.addText(tok.content) + handlers.inline = (state, tok) => state.parseTokens(tok.children!) + handlers.softbreak = handlers.softbreak || (state => state.addText(" ")) + + return handlers +} + +/// Object type used to specify how Markdown tokens should be parsed. +export interface ParseSpec { + /// This token maps to a single node, whose type can be looked up + /// in the schema under the given name. Exactly one of `node`, + /// `block`, or `mark` must be set. + node?: string + + /// This token (unless `noCloseToken` is true) comes in `_open` + /// and `_close` variants (which are appended to the base token + /// name provides a the object property), and wraps a block of + /// content. The block should be wrapped in a node of the type + /// named to by the property's value. If the token does not have + /// `_open` or `_close`, use the `noCloseToken` option. + block?: string + + /// This token (again, unless `noCloseToken` is true) also comes + /// in `_open` and `_close` variants, but should add a mark + /// (named by the value) to its content, rather than wrapping it + /// in a node. + mark?: string + + /// Attributes for the node or mark. When `getAttrs` is provided, + /// it takes precedence. + attrs?: Attrs | null + + /// A function used to compute the attributes for the node or mark + /// that takes a [markdown-it + /// token](https://markdown-it.github.io/markdown-it/#Token) and + /// returns an attribute object. + getAttrs?: (token: Token, tokenStream: Token[], index: number) => Attrs | null + + /// Indicates that the [markdown-it + /// token](https://markdown-it.github.io/markdown-it/#Token) has + /// no `_open` or `_close` for the nodes. This defaults to `true` + /// for `code_inline`, `code_block` and `fence`. + noCloseToken?: boolean + + /// When true, ignore content for the matched token. + ignore?: boolean +} + +/// A configuration of a Markdown parser. Such a parser uses +/// [markdown-it](https://github.com/markdown-it/markdown-it) to +/// tokenize a file, and then runs the custom rules it is given over +/// the tokens to create a ProseMirror document tree. +export class MarkdownParser { + /// @internal + tokenHandlers: {[token: string]: (stat: MarkdownParseState, token: Token, tokens: Token[], i: number) => void} + + /// Create a parser with the given configuration. You can configure + /// the markdown-it parser to parse the dialect you want, and provide + /// a description of the ProseMirror entities those tokens map to in + /// the `tokens` object, which maps token names to descriptions of + /// what to do with them. Such a description is an object, and may + /// have the following properties: + constructor( + /// The parser's document schema. + readonly schema: Schema, + /// This parser's markdown-it tokenizer. + readonly tokenizer: MarkdownIt, + /// The value of the `tokens` object used to construct this + /// parser. Can be useful to copy and modify to base other parsers + /// on. + readonly tokens: {[name: string]: ParseSpec} + ) { + this.tokenHandlers = tokenHandlers(schema, tokens) + } + + /// Parse a string as [CommonMark](http://commonmark.org/) markup, + /// and create a ProseMirror document as prescribed by this parser's + /// rules. + /// + /// The second argument, when given, is passed through to the + /// [Markdown + /// parser](https://markdown-it.github.io/markdown-it/#MarkdownIt.parse). + parse(text: string, markdownEnv: Object = {}) { + let state = new MarkdownParseState(this.schema, this.tokenHandlers), doc + state.parseTokens(this.tokenizer.parse(text, markdownEnv)) + do { doc = state.closeNode() } while (state.stack.length) + return doc || this.schema.topNodeType.createAndFill()! + } +} + +function listIsTight(tokens: readonly Token[], i: number) { + while (++i < tokens.length) + if (tokens[i].type != "list_item_open") return tokens[i].hidden + return false +} + +/// A parser parsing unextended [CommonMark](http://commonmark.org/), +/// without inline HTML, and producing a document in the basic schema. +export const defaultMarkdownParser = new MarkdownParser(schema, MarkdownIt("commonmark", {html: false}), { + blockquote: {block: "blockquote"}, + paragraph: {block: "paragraph"}, + list_item: {block: "list_item"}, + bullet_list: {block: "bullet_list", getAttrs: (_, tokens, i) => ({tight: listIsTight(tokens, i)})}, + ordered_list: {block: "ordered_list", getAttrs: (tok, tokens, i) => ({ + order: +tok.attrGet("start")! || 1, + tight: listIsTight(tokens, i) + })}, + heading: {block: "heading", getAttrs: tok => ({level: +tok.tag.slice(1)})}, + code_block: {block: "code_block", noCloseToken: true}, + fence: {block: "code_block", getAttrs: tok => ({params: tok.info || ""}), noCloseToken: true}, + hr: {node: "horizontal_rule"}, + image: {node: "image", getAttrs: tok => ({ + src: tok.attrGet("src"), + title: tok.attrGet("title") || null, + alt: tok.children![0] && tok.children![0].content || null + })}, + hardbreak: {node: "hard_break"}, + + em: {mark: "em"}, + strong: {mark: "strong"}, + link: {mark: "link", getAttrs: tok => ({ + href: tok.attrGet("href"), + title: tok.attrGet("title") || null + })}, + code_inline: {mark: "code", noCloseToken: true} +}) diff --git a/packages/webui/third_party/editor/prosemirror-markdown/src/index.ts b/packages/webui/third_party/editor/prosemirror-markdown/src/index.ts new file mode 100644 index 000000000..bca4892ea --- /dev/null +++ b/packages/webui/third_party/editor/prosemirror-markdown/src/index.ts @@ -0,0 +1,5 @@ +// Defines a parser and serializer for [CommonMark](http://commonmark.org/) text. + +export {schema} from "./schema" +export {defaultMarkdownParser, MarkdownParser, ParseSpec} from "./from_markdown" +export {MarkdownSerializer, defaultMarkdownSerializer, MarkdownSerializerState} from "./to_markdown" diff --git a/packages/webui/third_party/editor/prosemirror-markdown/src/schema.ts b/packages/webui/third_party/editor/prosemirror-markdown/src/schema.ts new file mode 100644 index 000000000..0eefe62b0 --- /dev/null +++ b/packages/webui/third_party/editor/prosemirror-markdown/src/schema.ts @@ -0,0 +1,156 @@ +import {Schema, MarkSpec} from "prosemirror-model" + +/// Document schema for the data model used by CommonMark. +export const schema = new Schema({ + nodes: { + doc: { + content: "block+" + }, + + paragraph: { + content: "inline*", + group: "block", + parseDOM: [{tag: "p"}], + toDOM() { return ["p", 0] } + }, + + blockquote: { + content: "block+", + group: "block", + parseDOM: [{tag: "blockquote"}], + toDOM() { return ["blockquote", 0] } + }, + + horizontal_rule: { + group: "block", + parseDOM: [{tag: "hr"}], + toDOM() { return ["div", ["hr"]] } + }, + + heading: { + attrs: {level: {default: 1, validate: "number"}}, + content: "(text | image)*", + group: "block", + defining: true, + parseDOM: [{tag: "h1", attrs: {level: 1}}, + {tag: "h2", attrs: {level: 2}}, + {tag: "h3", attrs: {level: 3}}, + {tag: "h4", attrs: {level: 4}}, + {tag: "h5", attrs: {level: 5}}, + {tag: "h6", attrs: {level: 6}}], + toDOM(node) { return ["h" + +node.attrs.level, 0] } + }, + + code_block: { + content: "text*", + group: "block", + code: true, + defining: true, + marks: "", + attrs: {params: {default: ""}}, + parseDOM: [{tag: "pre", preserveWhitespace: "full", getAttrs: node => ( + {params: (node as HTMLElement).getAttribute("data-params") || ""} + )}], + toDOM(node) { return ["pre", node.attrs.params ? {"data-params": node.attrs.params} : {}, ["code", 0]] } + }, + + ordered_list: { + content: "list_item+", + group: "block", + attrs: {order: {default: 1}, tight: {default: false}}, + parseDOM: [{tag: "ol", getAttrs(dom) { + return {order: (dom as HTMLElement).hasAttribute("start") ? +(dom as HTMLElement).getAttribute("start")! : 1, + tight: (dom as HTMLElement).hasAttribute("data-tight")} + }}], + toDOM(node) { + return ["ol", {start: node.attrs.order == 1 ? null : node.attrs.order, + "data-tight": node.attrs.tight ? "true" : null}, 0] + } + }, + + bullet_list: { + content: "list_item+", + group: "block", + attrs: {tight: {default: false}}, + parseDOM: [{tag: "ul", getAttrs: dom => ({tight: (dom as HTMLElement).hasAttribute("data-tight")})}], + toDOM(node) { return ["ul", {"data-tight": node.attrs.tight ? "true" : null}, 0] } + }, + + list_item: { + content: "block+", + defining: true, + parseDOM: [{tag: "li"}], + toDOM() { return ["li", 0] } + }, + + text: { + group: "inline" + }, + + image: { + inline: true, + attrs: { + src: {}, + alt: {default: null}, + title: {default: null} + }, + group: "inline", + draggable: true, + parseDOM: [{tag: "img[src]", getAttrs(dom) { + return { + src: (dom as HTMLElement).getAttribute("src"), + title: (dom as HTMLElement).getAttribute("title"), + alt: (dom as HTMLElement).getAttribute("alt") + } + }}], + toDOM(node) { return ["img", node.attrs] } + }, + + hard_break: { + inline: true, + group: "inline", + selectable: false, + parseDOM: [{tag: "br"}], + toDOM() { return ["br"] } + } + }, + + marks: { + em: { + parseDOM: [ + {tag: "i"}, {tag: "em"}, + {style: "font-style=italic"}, + {style: "font-style=normal", clearMark: m => m.type.name == "em"} + ], + toDOM() { return ["em"] } + }, + + strong: { + parseDOM: [ + {tag: "strong"}, + {tag: "b", getAttrs: node => node.style.fontWeight != "normal" && null}, + {style: "font-weight=400", clearMark: m => m.type.name == "strong"}, + {style: "font-weight", getAttrs: value => /^(bold(er)?|[5-9]\d{2,})$/.test(value) && null} + ], + toDOM() { return ["strong"] } + } as MarkSpec, + + link: { + attrs: { + href: {}, + title: {default: null} + }, + inclusive: false, + parseDOM: [{tag: "a[href]", getAttrs(dom) { + return {href: (dom as HTMLElement).getAttribute("href"), title: dom.getAttribute("title")} + }}], + toDOM(node) { return ["a", node.attrs] } + }, + + code: { + code: true, + parseDOM: [{tag: "code"}], + toDOM() { return ["code"] } + } + } +}) diff --git a/packages/webui/third_party/editor/prosemirror-markdown/src/to_markdown.ts b/packages/webui/third_party/editor/prosemirror-markdown/src/to_markdown.ts new file mode 100644 index 000000000..e01e5f91f --- /dev/null +++ b/packages/webui/third_party/editor/prosemirror-markdown/src/to_markdown.ts @@ -0,0 +1,484 @@ +import {Node, Mark} from "prosemirror-model" + +type MarkSerializerSpec = { + /// The string that should appear before a piece of content marked + /// by this mark, either directly or as a function that returns an + /// appropriate string. + open: string | ((state: MarkdownSerializerState, mark: Mark, parent: Node, index: number) => string), + /// The string that should appear after a piece of content marked by + /// this mark. + close: string | ((state: MarkdownSerializerState, mark: Mark, parent: Node, index: number) => string), + /// When `true`, this indicates that the order in which the mark's + /// opening and closing syntax appears relative to other mixable + /// marks can be varied. (For example, you can say `**a *b***` and + /// `*a **b***`, but not `` `a *b*` ``.) + mixable?: boolean, + /// When enabled, causes the serializer to move enclosing whitespace + /// from inside the marks to outside the marks. This is necessary + /// for emphasis marks as CommonMark does not permit enclosing + /// whitespace inside emphasis marks, see: + /// http:///spec.commonmark.org/0.26/#example-330 + expelEnclosingWhitespace?: boolean, + /// Can be set to `false` to disable character escaping in a mark. A + /// non-escaping mark has to have the highest precedence (must + /// always be the innermost mark). + escape?: boolean +} + +const blankMark: MarkSerializerSpec = {open: "", close: "", mixable: true} + +/// A specification for serializing a ProseMirror document as +/// Markdown/CommonMark text. +export class MarkdownSerializer { + /// Construct a serializer with the given configuration. The `nodes` + /// object should map node names in a given schema to function that + /// take a serializer state and such a node, and serialize the node. + constructor( + /// The node serializer functions for this serializer. + readonly nodes: {[node: string]: (state: MarkdownSerializerState, node: Node, parent: Node, index: number) => void}, + /// The mark serializer info. + readonly marks: {[mark: string]: MarkSerializerSpec}, + readonly options: { + /// Extra characters can be added for escaping. This is passed + /// directly to String.replace(), and the matching characters are + /// preceded by a backslash. + escapeExtraCharacters?: RegExp, + /// Specify the node name of hard breaks. + /// Defaults to "hard_break" + hardBreakNodeName?: string, + /// By default, the serializer raises an error when it finds a + /// node or mark type for which no serializer is defined. Set + /// this to `false` to make it just ignore such elements, + /// rendering only their content. + strict?: boolean + } = {} + ) {} + + /// Serialize the content of the given node to + /// [CommonMark](http://commonmark.org/). + serialize(content: Node, options: { + /// Whether to render lists in a tight style. This can be overridden + /// on a node level by specifying a tight attribute on the node. + /// Defaults to false. + tightLists?: boolean + } = {}) { + options = Object.assign({}, this.options, options) + let state = new MarkdownSerializerState(this.nodes, this.marks, options) + state.renderContent(content) + return state.out + } +} + +/// A serializer for the [basic schema](#schema). +export const defaultMarkdownSerializer = new MarkdownSerializer({ + blockquote(state, node) { + state.wrapBlock("> ", null, node, () => state.renderContent(node)) + }, + code_block(state, node) { + // Make sure the front matter fences are longer than any dash sequence within it + const backticks = node.textContent.match(/`{3,}/gm) + const fence = backticks ? (backticks.sort().slice(-1)[0] + "`") : "```" + + state.write(fence + (node.attrs.params || "") + "\n") + state.text(node.textContent, false) + // Add a newline to the current content before adding closing marker + state.write("\n") + state.write(fence) + state.closeBlock(node) + }, + heading(state, node) { + state.write(state.repeat("#", node.attrs.level) + " ") + state.renderInline(node, false) + state.closeBlock(node) + }, + horizontal_rule(state, node) { + state.write(node.attrs.markup || "---") + state.closeBlock(node) + }, + bullet_list(state, node) { + state.renderList(node, " ", () => (node.attrs.bullet || "*") + " ") + }, + ordered_list(state, node) { + let start = node.attrs.order ?? 1 + let maxW = String(start + node.childCount - 1).length + let space = state.repeat(" ", maxW + 2) + state.renderList(node, space, i => { + let nStr = String(start + i) + return state.repeat(" ", maxW - nStr.length) + nStr + ". " + }) + }, + list_item(state, node) { + state.renderContent(node) + }, + paragraph(state, node) { + state.renderInline(node) + state.closeBlock(node) + }, + + image(state, node) { + state.write("![" + state.esc(node.attrs.alt || "") + "](" + node.attrs.src.replace(/[\(\)]/g, "\\$&") + + (node.attrs.title ? ' "' + node.attrs.title.replace(/"/g, '\\"') + '"' : "") + ")") + }, + hard_break(state, node, parent, index) { + for (let i = index + 1; i < parent.childCount; i++) + if (parent.child(i).type != node.type) { + state.write("\\\n") + return + } + }, + text(state, node) { + state.text(node.text!, !state.inAutolink) + } +}, { + em: {open: "*", close: "*", mixable: true, expelEnclosingWhitespace: true}, + strong: {open: "**", close: "**", mixable: true, expelEnclosingWhitespace: true}, + link: { + open(state, mark, parent, index) { + state.inAutolink = isPlainURL(mark, parent, index) + return state.inAutolink ? "<" : "[" + }, + close(state, mark, parent, index) { + let {inAutolink} = state + state.inAutolink = undefined + return inAutolink ? ">" + : "](" + mark.attrs.href.replace(/[\(\)"]/g, "\\$&") + (mark.attrs.title ? ` "${mark.attrs.title.replace(/"/g, '\\"')}"` : "") + ")" + }, + mixable: true + }, + code: {open(_state, _mark, parent, index) { return backticksFor(parent.child(index), -1) }, + close(_state, _mark, parent, index) { return backticksFor(parent.child(index - 1), 1) }, + escape: false} +}) + +function backticksFor(node: Node, side: number) { + let ticks = /`+/g, m: RegExpExecArray | null, len = 0 + if (node.isText) while (m = ticks.exec(node.text!)) len = Math.max(len, m[0].length) + let result = len > 0 && side > 0 ? " `" : "`" + for (let i = 0; i < len; i++) result += "`" + if (len > 0 && side < 0) result += " " + return result +} + +function isPlainURL(link: Mark, parent: Node, index: number) { + if (link.attrs.title || !/^\w+:/.test(link.attrs.href)) return false + let content = parent.child(index) + if (!content.isText || content.text != link.attrs.href || content.marks[content.marks.length - 1] != link) return false + return index == parent.childCount - 1 || !link.isInSet(parent.child(index + 1).marks) +} + +/// This is an object used to track state and expose +/// methods related to markdown serialization. Instances are passed to +/// node and mark serialization methods (see `toMarkdown`). +export class MarkdownSerializerState { + /// @internal + delim: string = "" + /// @internal + out: string = "" + /// @internal + closed: Node | null = null + /// @internal + inAutolink: boolean | undefined = undefined + /// @internal + atBlockStart: boolean = false + /// @internal + inTightList: boolean = false + + /// @internal + constructor( + /// @internal + readonly nodes: {[node: string]: (state: MarkdownSerializerState, node: Node, parent: Node, index: number) => void}, + /// @internal + readonly marks: {[mark: string]: MarkSerializerSpec}, + /// The options passed to the serializer. + readonly options: {tightLists?: boolean, escapeExtraCharacters?: RegExp, hardBreakNodeName?: string, strict?: boolean} + ) { + if (typeof this.options.tightLists == "undefined") + this.options.tightLists = false + if (typeof this.options.hardBreakNodeName == "undefined") + this.options.hardBreakNodeName = "hard_break" + } + + /// @internal + flushClose(size: number = 2) { + if (this.closed) { + if (!this.atBlank()) this.out += "\n" + if (size > 1) { + let delimMin = this.delim + let trim = /\s+$/.exec(delimMin) + if (trim) delimMin = delimMin.slice(0, delimMin.length - trim[0].length) + for (let i = 1; i < size; i++) + this.out += delimMin + "\n" + } + this.closed = null + } + } + + /// @internal + getMark(name: string) { + let info = this.marks[name] + if (!info) { + if (this.options.strict !== false) + throw new Error(`Mark type \`${name}\` not supported by Markdown renderer`) + info = blankMark + } + return info + } + + /// Render a block, prefixing each line with `delim`, and the first + /// line in `firstDelim`. `node` should be the node that is closed at + /// the end of the block, and `f` is a function that renders the + /// content of the block. + wrapBlock(delim: string, firstDelim: string | null, node: Node, f: () => void) { + let old = this.delim + this.write(firstDelim != null ? firstDelim : delim) + this.delim += delim + f() + this.delim = old + this.closeBlock(node) + } + + /// @internal + atBlank() { + return /(^|\n)$/.test(this.out) + } + + /// Ensure the current content ends with a newline. + ensureNewLine() { + if (!this.atBlank()) this.out += "\n" + } + + /// Prepare the state for writing output (closing closed paragraphs, + /// adding delimiters, and so on), and then optionally add content + /// (unescaped) to the output. + write(content?: string) { + this.flushClose() + if (this.delim && this.atBlank()) + this.out += this.delim + if (content) this.out += content + } + + /// Close the block for the given node. + closeBlock(node: Node) { + this.closed = node + } + + /// Add the given text to the document. When escape is not `false`, + /// it will be escaped. + text(text: string, escape = true) { + let lines = text.split("\n") + for (let i = 0; i < lines.length; i++) { + this.write() + // Escape exclamation marks in front of links + if (!escape && lines[i][0] == "[" && /(^|[^\\])\!$/.test(this.out)) + this.out = this.out.slice(0, this.out.length - 1) + "\\!" + this.out += escape ? this.esc(lines[i], this.atBlockStart) : lines[i] + if (i != lines.length - 1) this.out += "\n" + } + } + + /// Render the given node as a block. + render(node: Node, parent: Node, index: number) { + if (this.nodes[node.type.name]) { + this.nodes[node.type.name](this, node, parent, index) + } else { + if (this.options.strict !== false) { + throw new Error("Token type `" + node.type.name + "` not supported by Markdown renderer") + } else if (!node.type.isLeaf) { + if (node.type.inlineContent) this.renderInline(node) + else this.renderContent(node) + if (node.isBlock) this.closeBlock(node) + } + } + } + + /// Render the contents of `parent` as block nodes. + renderContent(parent: Node) { + parent.forEach((node, _, i) => this.render(node, parent, i)) + } + + /// Render the contents of `parent` as inline content. + renderInline(parent: Node, fromBlockStart = true) { + this.atBlockStart = fromBlockStart + let active: Mark[] = [], trailing = "" + let progress = (node: Node | null, offset: number, index: number) => { + let marks = node ? node.marks : [] + + // Remove marks from `hard_break` that are the last node inside + // that mark to prevent parser edge cases with new lines just + // before closing marks. + if (node && node.type.name === this.options.hardBreakNodeName) + marks = marks.filter(m => { + if (index + 1 == parent.childCount) return false + let next = parent.child(index + 1) + return m.isInSet(next.marks) && (!next.isText || /\S/.test(next.text!)) + }) + + let inner = marks.length ? marks[marks.length - 1] : null + let noEsc = inner && this.getMark(inner.type.name).escape === false + let len = marks.length - (noEsc ? 1 : 0) + + // Try to reorder 'mixable' marks, such as em and strong, which + // in Markdown may be opened and closed in different order, so + // that order of the marks for the token matches the order in + // active. + outer: for (let i = 0; i < len; i++) { + let mark = marks[i] + if (!this.getMark(mark.type.name).mixable) break + for (let j = 0; j < active.length; j++) { + let other = active[j] + if (!this.getMark(other.type.name).mixable) break + if (mark.eq(other)) { + if (i > j) + marks = marks.slice(0, j).concat(mark).concat(marks.slice(j, i)).concat(marks.slice(i + 1, len)) + else if (j > i) + marks = marks.slice(0, i).concat(marks.slice(i + 1, j)).concat(mark).concat(marks.slice(j, len)) + continue outer + } + } + } + + // Find the prefix of the mark set that didn't change + let keep = 0 + while (keep < Math.min(active.length, len) && marks[keep].eq(active[keep])) ++keep + + let leading = trailing + trailing = "" + // If whitespace has to be expelled from the node, adjust + // leading and trailing accordingly. + if (node && node.isText && marks.some(mark => { + let info = this.getMark(mark.type.name) + return info && info.expelEnclosingWhitespace && !active.some((m, i) => i < keep && m.eq(mark)) + })) { + let [_, lead, rest] = /^(\s*)(.*)$/m.exec(node.text!)! + if (lead) { + leading += lead + node = rest ? (node as any).withText(rest) : null + if (!node) marks = active + } + } + if (node && node.isText && marks.some((mark, i) => { + let info = this.getMark(mark.type.name) + return info && info.expelEnclosingWhitespace && !this.isMarkAhead(parent, index + 1, marks.slice(0, i + 1)) + })) { + let [_, rest, trail] = /^(.*?)(\s*)$/m.exec(node.text!)! + if (trail) { + trailing = trail + node = rest ? (node as any).withText(rest) : null + if (!node) marks = active + } + } + + // Close the marks that need to be closed + if (node || index == parent.childCount) while (keep < active.length) + this.text(this.markString(active.pop()!, false, parent, index), false) + + // Output any previously expelled trailing whitespace outside the marks + if (leading) this.text(leading) + + // Open the marks that need to be opened + if (node) { + while (active.length < len) { + let add = marks[active.length] + active.push(add) + this.text(this.markString(add, true, parent, index), false) + this.atBlockStart = false + } + + // Render the node. Special case code marks, since their content + // may not be escaped. + if (noEsc && node.isText) + this.text(this.markString(inner!, true, parent, index) + node.text + + this.markString(inner!, false, parent, index + 1), false) + else + this.render(node, parent, index) + this.atBlockStart = false + + // After the first non-empty text node is rendered, the end of output + // is no longer at block start. + // + // FIXME: If a non-text node writes something to the output for this + // block, the end of output is also no longer at block start. But how + // can we detect that? + if (node.isText && node.nodeSize > 0) this.atBlockStart = false + } + } + parent.forEach(progress) + progress(null, 0, parent.childCount) + this.atBlockStart = false + } + + /// Render a node's content as a list. `delim` should be the extra + /// indentation added to all lines except the first in an item, + /// `firstDelim` is a function going from an item index to a + /// delimiter for the first line of the item. + renderList(node: Node, delim: string, firstDelim: (index: number) => string) { + if (this.closed && this.closed.type == node.type) + this.flushClose(3) + else if (this.inTightList) + this.flushClose(1) + + let isTight = typeof node.attrs.tight != "undefined" ? node.attrs.tight : this.options.tightLists + let prevTight = this.inTightList + this.inTightList = isTight + node.forEach((child, _, i) => { + if (i && isTight) this.flushClose(1) + this.wrapBlock(delim, firstDelim(i), node, () => this.render(child, node, i)) + }) + this.inTightList = prevTight + } + + /// Escape the given string so that it can safely appear in Markdown + /// content. If `startOfLine` is true, also escape characters that + /// have special meaning only at the start of the line. + esc(str: string, startOfLine = false) { + str = str.replace( + /[`*\\~\[\]_]/g, + (m, i) => m == "_" && i > 0 && i + 1 < str.length && str[i-1].match(/\w/) && str[i+1].match(/\w/) ? m : "\\" + m + ) + if (startOfLine) str = str.replace(/^(\+[ ]|[\-*>])/, "\\$&").replace(/^(\s*)(#{1,6})(\s|$)/, '$1\\$2$3').replace(/^(\s*\d+)\.\s/, "$1\\. ") + if (this.options.escapeExtraCharacters) str = str.replace(this.options.escapeExtraCharacters, "\\$&") + return str + } + + /// @internal + quote(str: string) { + let wrap = str.indexOf('"') == -1 ? '""' : str.indexOf("'") == -1 ? "''" : "()" + return wrap[0] + str + wrap[1] + } + + /// Repeat the given string `n` times. + repeat(str: string, n: number) { + let out = "" + for (let i = 0; i < n; i++) out += str + return out + } + + /// Get the markdown string for a given opening or closing mark. + markString(mark: Mark, open: boolean, parent: Node, index: number) { + let info = this.getMark(mark.type.name) + let value = open ? info.open : info.close + return typeof value == "string" ? value : value(this, mark, parent, index) + } + + /// Get leading and trailing whitespace from a string. Values of + /// leading or trailing property of the return object will be undefined + /// if there is no match. + getEnclosingWhitespace(text: string): {leading?: string, trailing?: string} { + return { + leading: (text.match(/^(\s+)/) || [undefined])[0], + trailing: (text.match(/(\s+)$/) || [undefined])[0] + } + } + + /// @internal + isMarkAhead(parent: Node, index: number, marks: readonly Mark[]) { + for (;; index++) { + if (index >= parent.childCount) return false + let next = parent.child(index) + if (next.type.name != this.options.hardBreakNodeName) { + return next.marks.length >= marks.length && Mark.sameSet(next.marks.slice(0, marks.length), marks) + } + index++ + } + } +} diff --git a/packages/webui/third_party/editor/prosemirror-model/LICENSE b/packages/webui/third_party/editor/prosemirror-model/LICENSE new file mode 100644 index 000000000..7e2295b30 --- /dev/null +++ b/packages/webui/third_party/editor/prosemirror-model/LICENSE @@ -0,0 +1,19 @@ +Copyright (C) 2015-2017 by Marijn Haverbeke and others + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/packages/webui/third_party/editor/prosemirror-model/package.json b/packages/webui/third_party/editor/prosemirror-model/package.json new file mode 100644 index 000000000..3344cc86b --- /dev/null +++ b/packages/webui/third_party/editor/prosemirror-model/package.json @@ -0,0 +1,38 @@ +{ + "name": "prosemirror-model", + "version": "1.25.12", + "description": "ProseMirror's document model", + "type": "module", + "main": "dist/index.cjs", + "module": "dist/index.js", + "types": "dist/index.d.ts", + "exports": { + "import": "./dist/index.js", + "require": "./dist/index.cjs" + }, + "sideEffects": false, + "license": "MIT", + "maintainers": [ + { + "name": "Marijn Haverbeke", + "email": "marijn@haverbeke.berlin", + "web": "http://marijnhaverbeke.nl" + } + ], + "repository": { + "type": "git", + "url": "git+https://code.haverbeke.berlin/prosemirror/prosemirror-model.git" + }, + "dependencies": { + "orderedmap": "^2.0.0" + }, + "devDependencies": { + "@prosemirror/buildhelper": "^0.1.5", + "jsdom": "^20.0.0", + "prosemirror-test-builder": "^1.0.0" + }, + "scripts": { + "test": "pm-runtests", + "prepare": "pm-buildhelper src/index.ts" + } +} diff --git a/packages/webui/third_party/editor/prosemirror-model/src/comparedeep.ts b/packages/webui/third_party/editor/prosemirror-model/src/comparedeep.ts new file mode 100644 index 000000000..f72103104 --- /dev/null +++ b/packages/webui/third_party/editor/prosemirror-model/src/comparedeep.ts @@ -0,0 +1,15 @@ +export function compareDeep(a: any, b: any) { + if (a === b) return true + if (!(a && typeof a == "object") || + !(b && typeof b == "object")) return false + let array = Array.isArray(a) + if (Array.isArray(b) != array) return false + if (array) { + if (a.length != b.length) return false + for (let i = 0; i < a.length; i++) if (!compareDeep(a[i], b[i])) return false + } else { + for (let p in a) if (!(p in b) || !compareDeep(a[p], b[p])) return false + for (let p in b) if (!(p in a)) return false + } + return true +} diff --git a/packages/webui/third_party/editor/prosemirror-model/src/content.ts b/packages/webui/third_party/editor/prosemirror-model/src/content.ts new file mode 100644 index 000000000..adcc8a3c8 --- /dev/null +++ b/packages/webui/third_party/editor/prosemirror-model/src/content.ts @@ -0,0 +1,413 @@ +import {Fragment} from "./fragment" +import {NodeType} from "./schema" + +type MatchEdge = {type: NodeType, next: ContentMatch} + +/// Instances of this class represent a match state of a node type's +/// [content expression](#model.NodeSpec.content), and can be used to +/// find out whether further content matches here, and whether a given +/// position is a valid end of the node. +export class ContentMatch { + /// @internal + readonly next: MatchEdge[] = [] + /// @internal + readonly wrapCache: (NodeType | readonly NodeType[] | null)[] = [] + + /// @internal + constructor( + /// True when this match state represents a valid end of the node. + readonly validEnd: boolean + ) {} + + /// @internal + static parse(string: string, nodeTypes: {readonly [name: string]: NodeType}): ContentMatch { + let stream = new TokenStream(string, nodeTypes) + if (stream.next == null) return ContentMatch.empty + let expr = parseExpr(stream) + if (stream.next) stream.err("Unexpected trailing text") + let match = dfa(nfa(expr)) + checkForDeadEnds(match, stream) + return match + } + + /// Match a node type, returning a match after that node if + /// successful. + matchType(type: NodeType): ContentMatch | null { + for (let i = 0; i < this.next.length; i++) + if (this.next[i].type == type) return this.next[i].next + return null + } + + /// Try to match a fragment. Returns the resulting match when + /// successful. + matchFragment(frag: Fragment, start = 0, end = frag.childCount): ContentMatch | null { + let cur: ContentMatch | null = this + for (let i = start; cur && i < end; i++) + cur = cur.matchType(frag.child(i).type) + return cur + } + + /// @internal + get inlineContent() { + return this.next.length != 0 && this.next[0].type.isInline + } + + /// Get the first matching node type at this match position that can + /// be generated. + get defaultType(): NodeType | null { + for (let i = 0; i < this.next.length; i++) { + let {type} = this.next[i] + if (!(type.isText || type.hasRequiredAttrs())) return type + } + return null + } + + /// @internal + compatible(other: ContentMatch) { + for (let i = 0; i < this.next.length; i++) + for (let j = 0; j < other.next.length; j++) + if (this.next[i].type == other.next[j].type) return true + return false + } + + /// Try to match the given fragment, and if that fails, see if it can + /// be made to match by inserting nodes in front of it. When + /// successful, return a fragment of inserted nodes (which may be + /// empty if nothing had to be inserted). When `toEnd` is true, only + /// return a fragment if the resulting match goes to the end of the + /// content expression. + fillBefore(after: Fragment, toEnd = false, startIndex = 0): Fragment | null { + let seen: ContentMatch[] = [this] + function search(match: ContentMatch, types: readonly NodeType[]): Fragment | null { + let finished = match.matchFragment(after, startIndex) + if (finished && (!toEnd || finished.validEnd)) + return Fragment.from(types.map(tp => tp.createAndFill()!)) + + for (let i = 0; i < match.next.length; i++) { + let {type, next} = match.next[i] + if (!(type.isText || type.hasRequiredAttrs()) && seen.indexOf(next) == -1) { + seen.push(next) + let found = search(next, types.concat(type)) + if (found) return found + } + } + return null + } + + return search(this, []) + } + + /// Find a set of wrapping node types that would allow a node of the + /// given type to appear at this position. The result may be empty + /// (when it fits directly) and will be null when no such wrapping + /// exists. + findWrapping(target: NodeType): readonly NodeType[] | null { + for (let i = 0; i < this.wrapCache.length; i += 2) + if (this.wrapCache[i] == target) return this.wrapCache[i + 1] as (readonly NodeType[] | null) + let computed = this.computeWrapping(target) + this.wrapCache.push(target, computed) + return computed + } + + /// @internal + computeWrapping(target: NodeType): readonly NodeType[] | null { + type Active = {match: ContentMatch, type: NodeType | null, via: Active | null} + let seen = Object.create(null), active: Active[] = [{match: this, type: null, via: null}] + while (active.length) { + let current = active.shift()!, match = current.match + if (match.matchType(target)) { + let result: NodeType[] = [] + for (let obj: Active = current; obj.type; obj = obj.via!) + result.push(obj.type) + return result.reverse() + } + for (let i = 0; i < match.next.length; i++) { + let {type, next} = match.next[i] + if (!type.isLeaf && !type.hasRequiredAttrs() && !(type.name in seen) && (!current.type || next.validEnd)) { + active.push({match: type.contentMatch, type, via: current}) + seen[type.name] = true + } + } + } + return null + } + + /// The number of outgoing edges this node has in the finite + /// automaton that describes the content expression. + get edgeCount() { + return this.next.length + } + + /// Get the _n_​th outgoing edge from this node in the finite + /// automaton that describes the content expression. + edge(n: number): MatchEdge { + if (n >= this.next.length) throw new RangeError(`There's no ${n}th edge in this content match`) + return this.next[n] + } + + /// @internal + toString() { + let seen: ContentMatch[] = [] + function scan(m: ContentMatch) { + seen.push(m) + for (let i = 0; i < m.next.length; i++) + if (seen.indexOf(m.next[i].next) == -1) scan(m.next[i].next) + } + scan(this) + return seen.map((m, i) => { + let out = i + (m.validEnd ? "*" : " ") + " " + for (let i = 0; i < m.next.length; i++) + out += (i ? ", " : "") + m.next[i].type.name + "->" + seen.indexOf(m.next[i].next) + return out + }).join("\n") + } + + /// @internal + static empty = new ContentMatch(true) +} + +class TokenStream { + inline: boolean | null = null + pos = 0 + tokens: string[] + + constructor( + readonly string: string, + readonly nodeTypes: {readonly [name: string]: NodeType} + ) { + this.tokens = string.split(/\s*(?=\b|\W|$)/) + if (this.tokens[this.tokens.length - 1] == "") this.tokens.pop() + if (this.tokens[0] == "") this.tokens.shift() + } + + get next() { return this.tokens[this.pos] } + + eat(tok: string) { return this.next == tok && (this.pos++ || true) } + + err(str: string): never { throw new SyntaxError(str + " (in content expression '" + this.string + "')") } +} + +type Expr = + {type: "choice", exprs: Expr[]} | + {type: "seq", exprs: Expr[]} | + {type: "plus", expr: Expr} | + {type: "star", expr: Expr} | + {type: "opt", expr: Expr} | + {type: "range", min: number, max: number, expr: Expr} | + {type: "name", value: NodeType} + +function parseExpr(stream: TokenStream): Expr { + let exprs: Expr[] = [] + do { exprs.push(parseExprSeq(stream)) } + while (stream.eat("|")) + return exprs.length == 1 ? exprs[0] : {type: "choice", exprs} +} + +function parseExprSeq(stream: TokenStream): Expr { + let exprs: Expr[] = [] + do { exprs.push(parseExprSubscript(stream)) } + while (stream.next && stream.next != ")" && stream.next != "|") + return exprs.length == 1 ? exprs[0] : {type: "seq", exprs} +} + +function parseExprSubscript(stream: TokenStream): Expr { + let expr = parseExprAtom(stream) + for (;;) { + if (stream.eat("+")) + expr = {type: "plus", expr} + else if (stream.eat("*")) + expr = {type: "star", expr} + else if (stream.eat("?")) + expr = {type: "opt", expr} + else if (stream.eat("{")) + expr = parseExprRange(stream, expr) + else break + } + return expr +} + +function parseNum(stream: TokenStream) { + if (/\D/.test(stream.next)) stream.err("Expected number, got '" + stream.next + "'") + let result = Number(stream.next) + stream.pos++ + return result +} + +function parseExprRange(stream: TokenStream, expr: Expr): Expr { + let min = parseNum(stream), max = min + if (stream.eat(",")) { + if (stream.next != "}") max = parseNum(stream) + else max = -1 + } + if (!stream.eat("}")) stream.err("Unclosed braced range") + return {type: "range", min, max, expr} +} + +function resolveName(stream: TokenStream, name: string): readonly NodeType[] { + let types = stream.nodeTypes, type = types[name] + if (type) return [type] + let result: NodeType[] = [] + for (let typeName in types) { + let type = types[typeName] + if (type.isInGroup(name)) result.push(type) + } + if (result.length == 0) stream.err("No node type or group '" + name + "' found") + return result +} + +function parseExprAtom(stream: TokenStream): Expr { + if (stream.eat("(")) { + let expr = parseExpr(stream) + if (!stream.eat(")")) stream.err("Missing closing paren") + return expr + } else if (!/\W/.test(stream.next)) { + let exprs = resolveName(stream, stream.next).map(type => { + if (stream.inline == null) stream.inline = type.isInline + else if (stream.inline != type.isInline) stream.err("Mixing inline and block content") + return {type: "name", value: type} as Expr + }) + stream.pos++ + return exprs.length == 1 ? exprs[0] : {type: "choice", exprs} + } else { + stream.err("Unexpected token '" + stream.next + "'") + } +} + +// The code below helps compile a regular-expression-like language +// into a deterministic finite automaton. For a good introduction to +// these concepts, see https://swtch.com/~rsc/regexp/regexp1.html + +type Edge = {term: NodeType | undefined, to: number | undefined} + +// Construct an NFA from an expression as returned by the parser. The +// NFA is represented as an array of states, which are themselves +// arrays of edges, which are `{term, to}` objects. The first state is +// the entry state and the last node is the success state. +// +// Note that unlike typical NFAs, the edge ordering in this one is +// significant, in that it is used to contruct filler content when +// necessary. +function nfa(expr: Expr): Edge[][] { + let nfa: Edge[][] = [[]] + connect(compile(expr, 0), node()) + return nfa + + function node() { return nfa.push([]) - 1 } + function edge(from: number, to?: number, term?: NodeType) { + let edge = {term, to} + nfa[from].push(edge) + return edge + } + function connect(edges: Edge[], to: number) { + edges.forEach(edge => edge.to = to) + } + + function compile(expr: Expr, from: number): Edge[] { + if (expr.type == "choice") { + return expr.exprs.reduce((out, expr) => out.concat(compile(expr, from)), [] as Edge[]) + } else if (expr.type == "seq") { + for (let i = 0;; i++) { + let next = compile(expr.exprs[i], from) + if (i == expr.exprs.length - 1) return next + connect(next, from = node()) + } + } else if (expr.type == "star") { + let loop = node() + edge(from, loop) + connect(compile(expr.expr, loop), loop) + return [edge(loop)] + } else if (expr.type == "plus") { + let loop = node() + connect(compile(expr.expr, from), loop) + connect(compile(expr.expr, loop), loop) + return [edge(loop)] + } else if (expr.type == "opt") { + return [edge(from)].concat(compile(expr.expr, from)) + } else if (expr.type == "range") { + let cur = from + for (let i = 0; i < expr.min; i++) { + let next = node() + connect(compile(expr.expr, cur), next) + cur = next + } + if (expr.max == -1) { + connect(compile(expr.expr, cur), cur) + } else { + for (let i = expr.min; i < expr.max; i++) { + let next = node() + edge(cur, next) + connect(compile(expr.expr, cur), next) + cur = next + } + } + return [edge(cur)] + } else if (expr.type == "name") { + return [edge(from, undefined, expr.value)] + } else { + throw new Error("Unknown expr type") + } + } +} + +function cmp(a: number, b: number) { return b - a } + +// Get the set of nodes reachable by null edges from `node`. Omit +// nodes with only a single null-out-edge, since they may lead to +// needless duplicated nodes. +function nullFrom(nfa: Edge[][], node: number): readonly number[] { + let result: number[] = [] + scan(node) + return result.sort(cmp) + + function scan(node: number): void { + let edges = nfa[node] + if (edges.length == 1 && !edges[0].term) return scan(edges[0].to!) + result.push(node) + for (let i = 0; i < edges.length; i++) { + let {term, to} = edges[i] + if (!term && result.indexOf(to!) == -1) scan(to!) + } + } +} + +// Compiles an NFA as produced by `nfa` into a DFA, modeled as a set +// of state objects (`ContentMatch` instances) with transitions +// between them. +function dfa(nfa: Edge[][]): ContentMatch { + let labeled = Object.create(null) + return explore(nullFrom(nfa, 0)) + + function explore(states: readonly number[]) { + let out: [NodeType, number[]][] = [] + states.forEach(node => { + nfa[node].forEach(({term, to}) => { + if (!term) return + let set: number[] | undefined + for (let i = 0; i < out.length; i++) if (out[i][0] == term) set = out[i][1] + nullFrom(nfa, to!).forEach(node => { + if (!set) out.push([term, set = []]) + if (set.indexOf(node) == -1) set.push(node) + }) + }) + }) + let state = labeled[states.join(",")] = new ContentMatch(states.indexOf(nfa.length - 1) > -1) + for (let i = 0; i < out.length; i++) { + let states = out[i][1].sort(cmp) + state.next.push({type: out[i][0], next: labeled[states.join(",")] || explore(states)}) + } + return state + } +} + +function checkForDeadEnds(match: ContentMatch, stream: TokenStream) { + for (let i = 0, work = [match]; i < work.length; i++) { + let state = work[i], dead = !state.validEnd, nodes: string[] = [] + for (let j = 0; j < state.next.length; j++) { + let {type, next} = state.next[j] + nodes.push(type.name) + if (dead && !(type.isText || type.hasRequiredAttrs())) dead = false + if (work.indexOf(next) == -1) work.push(next) + } + if (dead) stream.err("Only non-generatable nodes (" + nodes.join(", ") + ") in a required position (see https://prosemirror.net/docs/guide/#generatable)") + } +} diff --git a/packages/webui/third_party/editor/prosemirror-model/src/diff.ts b/packages/webui/third_party/editor/prosemirror-model/src/diff.ts new file mode 100644 index 000000000..a20452675 --- /dev/null +++ b/packages/webui/third_party/editor/prosemirror-model/src/diff.ts @@ -0,0 +1,57 @@ +import {Fragment} from "./fragment" + +export function findDiffStart(a: Fragment, b: Fragment, pos: number): number | null { + for (let i = 0;; i++) { + if (i == a.childCount || i == b.childCount) + return a.childCount == b.childCount ? null : pos + + let childA = a.child(i), childB = b.child(i) + if (childA == childB) { pos += childA.nodeSize; continue } + + if (!childA.sameMarkup(childB)) return pos + + if (childA.isText && childA.text != childB.text) { + let tA = childA.text!, tB = childB.text!, j = 0 + for (; tA[j] == tB[j]; j++) pos++ + if (j && j < tA.length && j < tB.length && surrogateHigh(tA.charCodeAt(j - 1)) && surrogateLow(tA.charCodeAt(j))) pos-- + return pos + } + if (childA.content.size || childB.content.size) { + let inner = findDiffStart(childA.content, childB.content, pos + 1) + if (inner != null) return inner + } + pos += childA.nodeSize + } +} + +export function findDiffEnd(a: Fragment, b: Fragment, posA: number, posB: number): {a: number, b: number} | null { + for (let iA = a.childCount, iB = b.childCount;;) { + if (iA == 0 || iB == 0) + return iA == iB ? null : {a: posA, b: posB} + + let childA = a.child(--iA), childB = b.child(--iB), size = childA.nodeSize + if (childA == childB) { + posA -= size; posB -= size + continue + } + + if (!childA.sameMarkup(childB)) return {a: posA, b: posB} + + if (childA.isText && childA.text != childB.text) { + let tA = childA.text!, tB = childB.text!, iA = tA.length, iB = tB.length + while (iA > 0 && iB > 0 && tA[iA - 1] == tB[iB - 1]) { iA--; iB--; posA--; posB-- } + if (iA && iB && iA < tA.length && surrogateHigh(tA.charCodeAt(iA - 1)) && surrogateLow(tA.charCodeAt(iA))) { + posA++; posB++ + } + return {a: posA, b: posB} + } + if (childA.content.size || childB.content.size) { + let inner = findDiffEnd(childA.content, childB.content, posA - 1, posB - 1) + if (inner) return inner + } + posA -= size; posB -= size + } +} + +function surrogateLow(ch: number) { return ch >= 0xDC00 && ch < 0xE000 } +function surrogateHigh(ch: number) { return ch >= 0xD800 && ch < 0xDC00 } diff --git a/packages/webui/third_party/editor/prosemirror-model/src/fragment.ts b/packages/webui/third_party/editor/prosemirror-model/src/fragment.ts new file mode 100644 index 000000000..0bf655aab --- /dev/null +++ b/packages/webui/third_party/editor/prosemirror-model/src/fragment.ts @@ -0,0 +1,268 @@ +import {findDiffStart, findDiffEnd} from "./diff" +import {Node, TextNode} from "./node" +import {Schema} from "./schema" + +/// A fragment represents a node's collection of child nodes. +/// +/// Like nodes, fragments are persistent data structures, and you +/// should not mutate them or their content. Rather, you create new +/// instances whenever needed. The API tries to make this easy. +export class Fragment { + /// The size of the fragment, which is the total of the size of + /// its content nodes. + readonly size: number + + /// @internal + constructor( + /// The child nodes in this fragment. + readonly content: readonly Node[], + size?: number + ) { + this.size = size || 0 + if (size == null) for (let i = 0; i < content.length; i++) + this.size += content[i].nodeSize + } + + /// Invoke a callback for all descendant nodes between the given two + /// positions (relative to start of this fragment). Doesn't descend + /// into a node when the callback returns `false`. + nodesBetween(from: number, to: number, + f: (node: Node, start: number, parent: Node | null, index: number) => boolean | void, + nodeStart = 0, + parent?: Node) { + for (let i = 0, pos = 0; pos < to; i++) { + let child = this.content[i], end = pos + child.nodeSize + if (end > from && f(child, nodeStart + pos, parent || null, i) !== false && child.content.size) { + let start = pos + 1 + child.nodesBetween(Math.max(0, from - start), + Math.min(child.content.size, to - start), + f, nodeStart + start) + } + pos = end + } + } + + /// Call the given callback for every descendant node. `pos` will be + /// relative to the start of the fragment. The callback may return + /// `false` to prevent traversal of a given node's children. + descendants(f: (node: Node, pos: number, parent: Node | null, index: number) => boolean | void) { + this.nodesBetween(0, this.size, f) + } + + /// Extract the text between `from` and `to`. See the same method on + /// [`Node`](#model.Node.textBetween). + textBetween(from: number, to: number, blockSeparator?: string | null, leafText?: string | null | ((leafNode: Node) => string)) { + let text = "", first = true + this.nodesBetween(from, to, (node, pos) => { + let nodeText = node.isText ? node.text!.slice(Math.max(from, pos) - pos, to - pos) + : !node.isLeaf ? "" + : leafText ? (typeof leafText === "function" ? leafText(node) : leafText) + : node.type.spec.leafText ? node.type.spec.leafText(node) + : "" + if (node.isBlock && (node.isLeaf && nodeText || node.isTextblock) && blockSeparator) { + if (first) first = false + else text += blockSeparator + } + text += nodeText + }, 0) + return text + } + + /// Create a new fragment containing the combined content of this + /// fragment and the other. + append(other: Fragment) { + if (!other.size) return this + if (!this.size) return other + let last = this.lastChild!, first = other.firstChild!, content = this.content.slice(), i = 0 + if (last.isText && last.sameMarkup(first)) { + content[content.length - 1] = (last as TextNode).withText(last.text! + first.text!) + i = 1 + } + for (; i < other.content.length; i++) content.push(other.content[i]) + return new Fragment(content, this.size + other.size) + } + + /// Cut out the sub-fragment between the two given positions. + cut(from: number, to = this.size) { + if (from == 0 && to == this.size) return this + let result: Node[] = [], size = 0 + if (to > from) for (let i = 0, pos = 0; pos < to; i++) { + let child = this.content[i], end = pos + child.nodeSize + if (end > from) { + if (pos < from || end > to) { + if (child.isText) + child = child.cut(Math.max(0, from - pos), Math.min(child.text!.length, to - pos)) + else + child = child.cut(Math.max(0, from - pos - 1), Math.min(child.content.size, to - pos - 1)) + } + result.push(child) + size += child.nodeSize + } + pos = end + } + return new Fragment(result, size) + } + + /// @internal + cutByIndex(from: number, to: number) { + if (from == to) return Fragment.empty + if (from == 0 && to == this.content.length) return this + return new Fragment(this.content.slice(from, to)) + } + + /// Create a new fragment in which the node at the given index is + /// replaced by the given node. + replaceChild(index: number, node: Node) { + let current = this.content[index] + if (current == node) return this + let copy = this.content.slice() + let size = this.size + node.nodeSize - current.nodeSize + copy[index] = node + return new Fragment(copy, size) + } + + /// Create a new fragment by prepending the given node to this + /// fragment. + addToStart(node: Node) { + return new Fragment([node].concat(this.content), this.size + node.nodeSize) + } + + /// Create a new fragment by appending the given node to this + /// fragment. + addToEnd(node: Node) { + return new Fragment(this.content.concat(node), this.size + node.nodeSize) + } + + /// Compare this fragment to another one. + eq(other: Fragment): boolean { + if (this.content.length != other.content.length) return false + for (let i = 0; i < this.content.length; i++) + if (!this.content[i].eq(other.content[i])) return false + return true + } + + /// The first child of the fragment, or `null` if it is empty. + get firstChild(): Node | null { return this.content.length ? this.content[0] : null } + + /// The last child of the fragment, or `null` if it is empty. + get lastChild(): Node | null { return this.content.length ? this.content[this.content.length - 1] : null } + + /// The number of child nodes in this fragment. + get childCount() { return this.content.length } + + /// Get the child node at the given index. Raise an error when the + /// index is out of range. + child(index: number) { + let found = this.content[index] + if (!found) throw new RangeError("Index " + index + " out of range for " + this) + return found + } + + /// Get the child node at the given index, if it exists. + maybeChild(index: number): Node | null { + return this.content[index] || null + } + + /// Call `f` for every child node, passing the node, its offset + /// into this parent node, and its index. + forEach(f: (node: Node, offset: number, index: number) => void) { + for (let i = 0, p = 0; i < this.content.length; i++) { + let child = this.content[i] + f(child, p, i) + p += child.nodeSize + } + } + + /// Find the first position at which this fragment and another + /// fragment differ, or `null` if they are the same. + findDiffStart(other: Fragment, pos = 0) { + return findDiffStart(this, other, pos) + } + + /// Find the first position, searching from the end, at which this + /// fragment and the given fragment differ, or `null` if they are + /// the same. Since this position will not be the same in both + /// nodes, an object with two separate positions is returned. + findDiffEnd(other: Fragment, pos = this.size, otherPos = other.size) { + return findDiffEnd(this, other, pos, otherPos) + } + + /// Find the index and inner offset corresponding to a given relative + /// position in this fragment. The result object will be reused + /// (overwritten) the next time the function is called. @internal + findIndex(pos: number): {index: number, offset: number} { + if (pos == 0) return retIndex(0, pos) + if (pos == this.size) return retIndex(this.content.length, pos) + if (pos > this.size || pos < 0) throw new RangeError(`Position ${pos} outside of fragment (${this})`) + for (let i = 0, curPos = 0;; i++) { + let cur = this.child(i), end = curPos + cur.nodeSize + if (end >= pos) { + if (end == pos) return retIndex(i + 1, end) + return retIndex(i, curPos) + } + curPos = end + } + } + + /// Return a debugging string that describes this fragment. + toString(): string { return "<" + this.toStringInner() + ">" } + + /// @internal + toStringInner() { return this.content.join(", ") } + + /// Create a JSON-serializeable representation of this fragment. + toJSON(): any { + return this.content.length ? this.content.map(n => n.toJSON()) : null + } + + /// Deserialize a fragment from its JSON representation. + static fromJSON(schema: Schema, value: any) { + if (!value) return Fragment.empty + if (!Array.isArray(value)) throw new RangeError("Invalid input for Fragment.fromJSON") + return Fragment.fromArray(value.map(schema.nodeFromJSON)) + } + + /// Build a fragment from an array of nodes. Ensures that adjacent + /// text nodes with the same marks are joined together. + static fromArray(array: readonly Node[]) { + if (!array.length) return Fragment.empty + let joined: Node[] | undefined, size = 0 + for (let i = 0; i < array.length; i++) { + let node = array[i] + size += node.nodeSize + if (i && node.isText && array[i - 1].sameMarkup(node)) { + if (!joined) joined = array.slice(0, i) + joined[joined.length - 1] = (node as TextNode) + .withText((joined[joined.length - 1] as TextNode).text + (node as TextNode).text) + } else if (joined) { + joined.push(node) + } + } + return new Fragment(joined || array, size) + } + + /// Create a fragment from something that can be interpreted as a + /// set of nodes. For `null`, it returns the empty fragment. For a + /// fragment, the fragment itself. For a node or array of nodes, a + /// fragment containing those nodes. + static from(nodes?: Fragment | Node | readonly Node[] | null) { + if (!nodes) return Fragment.empty + if (nodes instanceof Fragment) return nodes + if (Array.isArray(nodes)) return this.fromArray(nodes) + if ((nodes as Node).attrs) return new Fragment([nodes as Node], (nodes as Node).nodeSize) + throw new RangeError("Can not convert " + nodes + " to a Fragment" + + ((nodes as any).nodesBetween ? " (looks like multiple versions of prosemirror-model were loaded)" : "")) + } + + /// An empty fragment. Intended to be reused whenever a node doesn't + /// contain anything (rather than allocating a new empty fragment for + /// each leaf node). + static empty: Fragment = new Fragment([], 0) +} + +const found = {index: 0, offset: 0} +function retIndex(index: number, offset: number) { + found.index = index + found.offset = offset + return found +} diff --git a/packages/webui/third_party/editor/prosemirror-model/src/from_dom.ts b/packages/webui/third_party/editor/prosemirror-model/src/from_dom.ts new file mode 100644 index 000000000..e6ae3d4d0 --- /dev/null +++ b/packages/webui/third_party/editor/prosemirror-model/src/from_dom.ts @@ -0,0 +1,851 @@ +import {Fragment} from "./fragment" +import {Slice} from "./replace" +import {Mark} from "./mark" +import {Node, TextNode} from "./node" +import {ContentMatch} from "./content" +import {ResolvedPos} from "./resolvedpos" +import {Schema, Attrs, NodeType, MarkType} from "./schema" +import {DOMNode} from "./dom" + +/// These are the options recognized by the +/// [`parse`](#model.DOMParser.parse) and +/// [`parseSlice`](#model.DOMParser.parseSlice) methods. +export interface ParseOptions { + /// By default, whitespace is collapsed as per HTML's rules. Pass + /// `true` to preserve whitespace, but normalize newlines to + /// spaces or, if available, [line break replacements](#model.NodeSpec.linebreakReplacement), + /// and `"full"` to preserve whitespace entirely. + preserveWhitespace?: boolean | "full" + + /// When given, the parser will, beside parsing the content, + /// record the document positions of the given DOM positions. It + /// will do so by writing to the objects, adding a `pos` property + /// that holds the document position. DOM positions that are not + /// in the parsed content will not be written to. + findPositions?: {node: DOMNode, offset: number, pos?: number}[] + + /// The child node index to start parsing from. + from?: number + + /// The child node index to stop parsing at. + to?: number + + /// By default, the content is parsed into the schema's default + /// [top node type](#model.Schema.topNodeType). You can pass this + /// option to use the type and attributes from a different node + /// as the top container. + topNode?: Node + + /// Provide the starting content match that content parsed into the + /// top node is matched against. + topMatch?: ContentMatch + + /// A set of additional nodes to count as + /// [context](#model.GenericParseRule.context) when parsing, above the + /// given [top node](#model.ParseOptions.topNode). + context?: ResolvedPos + + /// @internal + ruleFromNode?: (node: DOMNode) => Omit | null + /// @internal + topOpen?: boolean +} + +/// Fields that may be present in both [tag](#model.TagParseRule) and +/// [style](#model.StyleParseRule) parse rules. +export interface GenericParseRule { + /// Can be used to change the order in which the parse rules in a + /// schema are tried. Those with higher priority come first. Rules + /// without a priority are counted as having priority 50. This + /// property is only meaningful in a schema—when directly + /// constructing a parser, the order of the rule array is used. + priority?: number + + /// By default, when a rule matches an element or style, no further + /// rules get a chance to match it. By setting this to `false`, you + /// indicate that even when this rule matches, other rules that come + /// after it should also run. + consuming?: boolean + + /// When given, restricts this rule to only match when the current + /// context—the parent nodes into which the content is being + /// parsed—matches this expression. Should contain one or more node + /// names or node group names followed by single or double slashes. + /// For example `"paragraph/"` means the rule only matches when the + /// parent node is a paragraph, `"blockquote/paragraph/"` restricts + /// it to be in a paragraph that is inside a blockquote, and + /// `"section//"` matches any position inside a section—a double + /// slash matches any sequence of ancestor nodes. To allow multiple + /// different contexts, they can be separated by a pipe (`|`) + /// character, as in `"blockquote/|list_item/"`. + context?: string + + /// The name of the mark type to wrap the matched content in. + mark?: string + + /// When true, ignore content that matches this rule. Any ``, + /// `