@ng-native/components 0.29.0 → 0.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/activity-indicator.js +3 -3
- package/dist/animated-style.js +3 -3
- package/dist/animations-web.js +3 -3
- package/dist/animations.js +3 -3
- package/dist/content-container.js +3 -3
- package/dist/context-menu.js +3 -3
- package/dist/drag-and-drop.js +6 -6
- package/dist/gestures-web.js +6 -6
- package/dist/gestures.js +6 -6
- package/dist/gradient-text.d.ts +1 -1
- package/dist/gradient-text.js +4 -4
- package/dist/gradient-text.js.map +1 -1
- package/dist/image-background.js +3 -3
- package/dist/image.js +3 -3
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/input-accessory-view.js +3 -3
- package/dist/keyboard-avoiding-view.js +3 -3
- package/dist/keyboard-dock.js +15 -15
- package/dist/markdown-blocks.d.ts +2 -1
- package/dist/markdown-blocks.js +22 -18
- package/dist/markdown-blocks.js.map +1 -1
- package/dist/markdown-columns.js +3 -3
- package/dist/markdown-stream.js +8 -5
- package/dist/markdown-stream.js.map +1 -1
- package/dist/markdown.js +5 -5
- package/dist/markdown.js.map +1 -1
- package/dist/menu.js +12 -12
- package/dist/modal.js +8 -3
- package/dist/modal.js.map +1 -1
- package/dist/native-button.js +3 -3
- package/dist/native-gesture.js +3 -3
- package/dist/native-ref.js +3 -3
- package/dist/press-menu.d.ts +17 -8
- package/dist/press-menu.js +39 -18
- package/dist/press-menu.js.map +1 -1
- package/dist/pressable.js +12 -12
- package/dist/reanimated-web.js +6 -6
- package/dist/reanimated.js +6 -6
- package/dist/refresh-control.js +3 -3
- package/dist/safe-area-provider.js +3 -3
- package/dist/safe-area-view.js +3 -3
- package/dist/scroll-view-props.js +3 -3
- package/dist/scroll-view.js +3 -3
- package/dist/section-list.d.ts +4 -4
- package/dist/section-list.js +37 -34
- package/dist/section-list.js.map +1 -1
- package/dist/shortcut.js +3 -3
- package/dist/sidebar-item.js +3 -3
- package/dist/sidebar-section.d.ts +12 -5
- package/dist/sidebar-section.js +32 -12
- package/dist/sidebar-section.js.map +1 -1
- package/dist/sidebar.d.ts +11 -3
- package/dist/sidebar.js +16 -7
- package/dist/sidebar.js.map +1 -1
- package/dist/split-view.js +6 -6
- package/dist/stand-ins/animations.js +3 -3
- package/dist/switch.js +3 -3
- package/dist/template-slot.js +3 -3
- package/dist/text-input.js +3 -3
- package/dist/text.js +3 -3
- package/dist/touchable-opacity.js +3 -3
- package/dist/tray-icon.js +3 -3
- package/dist/view-base.d.ts +18 -2
- package/dist/view-base.js +42 -10
- package/dist/view-base.js.map +1 -1
- package/dist/view.js +3 -3
- package/dist/virtual-list-layout.d.ts +5 -0
- package/dist/virtual-list-layout.js.map +1 -1
- package/dist/virtual-list-num-columns.d.ts +8 -4
- package/dist/virtual-list-num-columns.js +13 -5
- package/dist/virtual-list-num-columns.js.map +1 -1
- package/dist/virtual-list-sticky-level.js +3 -3
- package/dist/virtual-list.d.ts +48 -5
- package/dist/virtual-list.js +206 -46
- package/dist/virtual-list.js.map +1 -1
- package/dist/visual-effect.d.ts +37 -0
- package/dist/visual-effect.js +60 -0
- package/dist/visual-effect.js.map +1 -0
- package/dist/worklet-scroll.js +3 -3
- package/dist/worklet-style.js +3 -3
- package/dist/written-props.js +7 -0
- package/dist/written-props.js.map +1 -1
- package/ios/NgNativeComponents.podspec +2 -2
- package/ios/NgNativeKeyboardFocus.h +21 -0
- package/ios/NgNativeKeyboardFocus.mm +28 -0
- package/ios/NgNativeKeyboardFocusModule.mm +203 -0
- package/ios/NgNativeMenus.mm +20 -0
- package/ios/NgNativePressMenu.h +13 -5
- package/ios/NgNativePressMenu.mm +36 -2
- package/ios/NgNativeViewBinder.h +5 -0
- package/ios/NgNativeViewBinder.mm +31 -4
- package/package.json +6 -6
package/dist/markdown-blocks.js
CHANGED
|
@@ -276,7 +276,8 @@ export function blockKey(block) {
|
|
|
276
276
|
* `next`, with every part of it that equals the same part of `previous` replaced by that part, so
|
|
277
277
|
* a block that did not change is the object drawn already and is not drawn again. The two are
|
|
278
278
|
* matched from each end, so a block added or removed in the middle leaves those either side of it
|
|
279
|
-
* kept; what is left between is matched by position.
|
|
279
|
+
* kept; what is left between is matched by position. Only that last match keeps a part that
|
|
280
|
+
* changed, so no part of `previous` is matched with two of `next` and no two blocks share a key.
|
|
280
281
|
*/
|
|
281
282
|
export function shareBlocks(previous, next) {
|
|
282
283
|
return previous ? share(previous, next) : next;
|
|
@@ -296,30 +297,33 @@ function shareArray(previous, next) {
|
|
|
296
297
|
const out = next.slice();
|
|
297
298
|
// Each pair is compared once: the passes below meet at the same position, and comparing a
|
|
298
299
|
// changed block again in each of them made a nested one cost three times as much a level.
|
|
299
|
-
const compared = new
|
|
300
|
+
const compared = new Map();
|
|
300
301
|
const shareAt = (was, at) => {
|
|
301
|
-
if (was
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
compared.
|
|
305
|
-
|
|
306
|
-
|
|
302
|
+
if (was !== at)
|
|
303
|
+
return share(previous[was], next[at]);
|
|
304
|
+
if (!compared.has(at))
|
|
305
|
+
compared.set(at, share(previous[at], next[at]));
|
|
306
|
+
return compared.get(at);
|
|
307
|
+
};
|
|
308
|
+
const keepAt = (was, at) => {
|
|
309
|
+
const kept = shareAt(was, at);
|
|
310
|
+
if (kept !== previous[was])
|
|
311
|
+
return false;
|
|
312
|
+
out[at] = kept;
|
|
313
|
+
return true;
|
|
307
314
|
};
|
|
308
315
|
let start = 0;
|
|
309
|
-
while (start < out.length && start < previous.length)
|
|
310
|
-
if (shareAt(start, start) !== previous[start])
|
|
311
|
-
break;
|
|
316
|
+
while (start < out.length && start < previous.length && keepAt(start, start))
|
|
312
317
|
start++;
|
|
313
|
-
}
|
|
314
318
|
let end = 0;
|
|
315
|
-
while (end < out.length - start &&
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
break;
|
|
319
|
+
while (end < out.length - start &&
|
|
320
|
+
end < previous.length - start &&
|
|
321
|
+
keepAt(previous.length - 1 - end, out.length - 1 - end)) {
|
|
319
322
|
end++;
|
|
320
323
|
}
|
|
321
|
-
for (let i = start; i < out.length - end && i < previous.length - end; i++)
|
|
322
|
-
shareAt(i, i);
|
|
324
|
+
for (let i = start; i < out.length - end && i < previous.length - end; i++) {
|
|
325
|
+
out[i] = shareAt(i, i);
|
|
326
|
+
}
|
|
323
327
|
const same = out.length === previous.length && out.every((one, i) => one === previous[i]);
|
|
324
328
|
return same ? previous : out;
|
|
325
329
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown-blocks.js","sourceRoot":"","sources":["../src/markdown-blocks.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAmEnD,IAAI,aAA8C,CAAC;AAEnD,+FAA+F;AAC/F,SAAS,WAAW,CAAC,IAAY;IAC/B,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,aAAa,GAAG,IAAI,GAAG,EAAE,CAAC;QAC1B,MAAM,KAAK,GAAG,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACvC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC;YAAE,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAE,EAAE,KAAK,CAAC,CAAC,GAAG,CAAC,CAAE,CAAC,CAAC;IAC5F,CAAC;IACD,OAAO,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AACjC,CAAC;AAED,MAAM,MAAM,GAAG,uEAAuE,CAAC;AAEvF;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,IAAY;IACzC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IACrC,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CA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,KAAK,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC;IACzD,MAAM,GAAG,GAA4B,EAAE,CAAC;IACxC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,GAAG,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC3B,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjF,IAAI,IAAI,KAAK,GAAG;YAAE,IAAI,GAAG,KAAK,CAAC;QAC/B,GAAG,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IACnB,CAAC;IACD,IAAI,IAAI;QAAE,OAAO,QAAQ,CAAC;IAC1B,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC/B,IAAI,GAAG,KAAK,SAAS;QAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAC1C,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["/**\n * Marked's tokens, turned into the blocks `<markdown>` draws: the entities decoded, the links and\n * images held to the schemes they may use, raw HTML made plain text, and an image lifted out of\n * its paragraph, since a `<text>` cannot hold one.\n *\n * Plain functions with no Angular in them, so the policy is the same wherever the tokens came from:\n * `marked.lexer` on the device, or a build step that lexed them ahead of time.\n */\nimport type { Token, Tokens } from 'marked';\nimport { HTML_ENTITIES } from './html-entities.ts';\n\n/** The elements a document is drawn with, by the HTML names the Markdown would have produced. */\nexport type MarkdownElement =\n | 'h1'\n | 'h2'\n | 'h3'\n | 'h4'\n | 'h5'\n | 'h6'\n | 'p'\n | 'blockquote'\n | 'ul'\n | 'ol'\n | 'li'\n | 'marker'\n | 'pre'\n | 'code'\n | 'strong'\n | 'em'\n | 'del'\n | 'a'\n | 'hr'\n | 'img'\n | 'table'\n | 'tr'\n | 'th'\n | 'td';\n\nexport type MarkdownInline =\n | { readonly kind: 'text'; readonly text: string }\n | { readonly kind: 'strong' | 'em' | 'del'; readonly children: readonly MarkdownInline[] }\n | { readonly kind: 'code'; readonly text: string }\n | {\n readonly kind: 'link';\n readonly href: string;\n readonly title: string | null;\n readonly children: readonly MarkdownInline[];\n };\n\nexport interface MarkdownListItem {\n readonly marker: string;\n readonly children: readonly MarkdownBlock[];\n}\n\nexport type MarkdownBlock =\n | {\n readonly kind: 'heading';\n readonly element: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';\n readonly children: readonly MarkdownInline[];\n }\n | { readonly kind: 'paragraph'; readonly children: readonly MarkdownInline[] }\n | { readonly kind: 'image'; readonly src: string; readonly alt: string }\n | { readonly kind: 'blockquote'; readonly children: readonly MarkdownBlock[] }\n | {\n readonly kind: 'list';\n readonly element: 'ul' | 'ol';\n readonly items: readonly MarkdownListItem[];\n }\n | { readonly kind: 'code'; readonly text: string }\n | { readonly kind: 'hr' }\n | {\n readonly kind: 'table';\n readonly header: readonly (readonly MarkdownInline[])[];\n readonly rows: readonly (readonly (readonly MarkdownInline[])[])[];\n };\n\nlet namedEntities: Map<string, string> | undefined;\n\n/** The character HTML names `name`, from its full table, built on the first name looked up. */\nfunction namedEntity(name: string): string | undefined {\n if (!namedEntities) {\n namedEntities = new Map();\n const pairs = HTML_ENTITIES.split(' ');\n for (let i = 0; i + 1 < pairs.length; i += 2) namedEntities.set(pairs[i]!, pairs[i + 1]!);\n }\n return namedEntities.get(name);\n}\n\nconst ENTITY = /&(?:#(\\d{1,7})|#[xX]([0-9a-fA-F]{1,6})|([a-zA-Z][a-zA-Z0-9]{1,31}));/g;\n\n/**\n * The text an HTML reader would show for `text`, in one pass so `&lt;` is `<` and not `<`.\n * A reference to no character, or to one outside Unicode, is the replacement character, as HTML\n * makes it; a name HTML does not have stays as written.\n */\nexport function decodeEntities(text: string): string {\n if (!text.includes('&')) return text;\n return text.replace(ENTITY, (whole, decimal?: string, hex?: string, name?: string) => {\n if (name !== undefined) return namedEntity(name) ?? whole;\n const code = decimal !== undefined ? Number(decimal) : parseInt(hex!, 16);\n const valid = code > 0 && code <= 0x10ffff && (code < 0xd800 || code > 0xdfff);\n return valid ? String.fromCodePoint(code) : '�';\n });\n}\n\n/**\n * What a URL parser ignores while it reads a scheme: the C0 controls and the space, and the C1\n * controls and DEL beside them. `java\\tscript:` is `javascript:` to the thing that opens it.\n */\nconst IGNORED_IN_SCHEME = /[\\u0000- \\u007f-\\u009f]/g;\nconst SCHEME = /^([a-z][a-z0-9+.-]*):/;\n\n/** The scheme `url` would be opened with, lowercased, or null for a relative one. */\nexport function schemeOf(url: string): string | null {\n return SCHEME.exec(url.replace(IGNORED_IN_SCHEME, '').toLowerCase())?.[1] ?? null;\n}\n\nconst LINK_SCHEMES = new Set(['http', 'https', 'mailto', 'tel']);\nconst IMAGE_SCHEMES = new Set(['http', 'https']);\n\n/** The schemes an app lists for `<markdown>` to draw links in, lowercased. See {@link linkSchemeSet}. */\nexport type AppLinkSchemes = ReadonlySet<string>;\n\n/** No app scheme: what a document is drawn with when the app lists none. */\nexport const NO_APP_SCHEMES: AppLinkSchemes = new Set();\n\nconst SCHEME_NAME = /^[a-z][a-z0-9+.-]*$/;\n\n/**\n * The set of schemes an app lists, as {@link linkTarget} reads them. Each is trimmed, lowercased\n * and stripped of one trailing colon, so `'MyApp:'` and `'myapp'` are the same; an entry that\n * cannot be a scheme is dropped.\n */\nexport function linkSchemeSet(schemes: readonly string[]): AppLinkSchemes {\n const set = new Set<string>();\n for (const one of schemes) {\n const name = one.trim().toLowerCase().replace(/:$/, '');\n if (SCHEME_NAME.test(name)) set.add(name);\n }\n return set.size ? set : NO_APP_SCHEMES;\n}\n\n/**\n * A link's target if it may be drawn as a link: `http`, `https`, `mailto`, `tel`, a scheme the app\n * listed in `appSchemes`, or relative, which is the app's to resolve. Anything else,\n * `javascript:`, `data:`, `vbscript:` and `file:` among them, is null, and the link is drawn as\n * its text. The scheme is read after the trim, so whitespace the trim strips cannot hide one.\n */\nexport function linkTarget(\n href: string,\n appSchemes: AppLinkSchemes = NO_APP_SCHEMES,\n): string | null {\n const target = href.trim();\n const scheme = schemeOf(target);\n return scheme === null || LINK_SCHEMES.has(scheme) || appSchemes.has(scheme) ? target : null;\n}\n\n/**\n * Whether `href` is absolute in one of the built-in schemes a link is followed to, and so is\n * opened on press. A scheme the app listed is drawn as a link but never opens here.\n */\nexport function opensOnPress(href: string): boolean {\n const scheme = schemeOf(href.trim());\n return scheme !== null && LINK_SCHEMES.has(scheme);\n}\n\n/**\n * An image's address if it may be loaded: `http`, `https`, or a picture written into the document\n * as a `data:` url of a raster type. A pasted screenshot arrives that way from a web editor, and\n * a native image only decodes such a picture: nothing in it runs. Any other `data:` url, an SVG\n * or HTML among them, is refused, as is every other scheme.\n */\nexport function imageSource(href: string): string | null {\n const source = href.trim();\n const scheme = schemeOf(source);\n if (scheme === null) return null;\n if (IMAGE_SCHEMES.has(scheme)) return source;\n if (scheme !== 'data') return null;\n // A native loader may not decode a url with whitespace in it, so a wrapped payload is joined.\n const joined = source.replace(/\\s+/g, '');\n return DATA_IMAGE.test(joined) ? joined : null;\n}\n\n/** A base64 `data:` url of a raster picture: PNG, JPEG, GIF or WebP. */\nconst DATA_IMAGE = /^data:image\\/(?:png|jpe?g|gif|webp);base64,[a-z0-9+/=]+$/i;\n\n/** A link's or an image's target with its entities decoded, or null when it is not a string. */\nfunction hrefOf(token: Token): string | null {\n const href: unknown = (token as Tokens.Link).href;\n return typeof href === 'string' ? decodeEntities(href) : null;\n}\n\nconst HEADINGS = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'] as const;\n\n/** The blocks a document of `tokens` is drawn as, with links in `appSchemes` drawn as links too. */\nexport function markdownBlocks(\n tokens: readonly Token[],\n appSchemes: AppLinkSchemes = NO_APP_SCHEMES,\n): MarkdownBlock[] {\n return tokens.flatMap((token) => block(token, appSchemes));\n}\n\n/** What each kind of block token is drawn as. A kind not here is drawn as its source text. */\nconst BLOCKS: Readonly<Record<string, (token: Token, app: AppLinkSchemes) => MarkdownBlock[]>> = {\n heading: (token, app) => {\n const heading = token as Tokens.Heading;\n const depth = Math.min(Math.max(heading.depth, 1), 6);\n const children = trimmedEnd(inlines(heading.tokens, app));\n return [{ kind: 'heading', element: HEADINGS[depth - 1]!, children }];\n },\n paragraph: (token, app) => paragraphs((token as Tokens.Paragraph).tokens, app),\n text: (token, app) => {\n const text = token as Tokens.Text;\n return text.tokens\n ? paragraphs(text.tokens, app)\n : [{ kind: 'paragraph', children: [plain(softBreaks(text.text))] }];\n },\n blockquote: (token, app) => [\n { kind: 'blockquote', children: markdownBlocks((token as Tokens.Blockquote).tokens, app) },\n ],\n list: (token, app) => [list(token as Tokens.List, app)],\n code: (token) => [{ kind: 'code', text: indented((token as Tokens.Code).text) }],\n hr: () => [{ kind: 'hr' }],\n table: (token, app) => {\n const table = token as Tokens.Table;\n return [\n {\n kind: 'table',\n header: table.header.map((cell) => inlines(cell.tokens, app)),\n rows: table.rows.map((row) => row.map((cell) => inlines(cell.tokens, app))),\n },\n ];\n },\n html: (token) => literal((token as Tokens.HTML).text),\n space: () => [],\n def: () => [],\n checkbox: () => [],\n};\n\nfunction block(token: Token, app: AppLinkSchemes): MarkdownBlock[] {\n const draw = Object.hasOwn(BLOCKS, token.type) ? BLOCKS[token.type]! : null;\n return draw ? draw(token, app) : literal(token.raw ?? '');\n}\n\n/**\n * A code block's text with its first line's indent made of no-break spaces: a paragraph loses the\n * spaces at its start, and a block's indent is part of the code.\n */\nfunction indented(text: string): string {\n return text.replace(/^ +/, (spaces) => '\\u00a0'.repeat(spaces.length));\n}\n\n/** Text drawn as written, which is what raw HTML and a token nothing here knows become. */\nfunction literal(text: string): MarkdownBlock[] {\n const trimmed = text.replace(/\\n+$/, '');\n return trimmed.trim() ? [{ kind: 'paragraph', children: [{ kind: 'text', text: trimmed }] }] : [];\n}\n\nfunction list(token: Tokens.List, app: AppLinkSchemes): MarkdownBlock {\n const start = typeof token.start === 'number' ? token.start : 1;\n return {\n kind: 'list',\n element: token.ordered ? 'ol' : 'ul',\n items: token.items.map((item, index) => ({\n marker: item.task ? (item.checked ? '☑' : '☐') : token.ordered ? `${start + index}.` : '•',\n children: markdownBlocks(item.tokens, app),\n })),\n };\n}\n\n/**\n * A paragraph's runs, split around the images at its top level: an image is a block of its own,\n * and the text either side of it a paragraph each. An image whose address is refused, and one\n * inside a link or an emphasis, is its alt text instead.\n */\nfunction paragraphs(tokens: readonly Token[], app: AppLinkSchemes): MarkdownBlock[] {\n const out: MarkdownBlock[] = [];\n let run: MarkdownInline[] = [];\n const flush = () => {\n if (run.some((one) => one.kind !== 'text' || one.text.trim())) {\n out.push({ kind: 'paragraph', children: trimmedEnd(run) });\n }\n run = [];\n };\n for (const token of tokens) {\n const href = token.type === 'image' ? hrefOf(token) : null;\n const src = href === null ? null : imageSource(href);\n if (src === null) {\n run.push(...inline(token, app));\n continue;\n }\n flush();\n out.push({ kind: 'image', src, alt: decodeEntities((token as Tokens.Image).text) });\n }\n flush();\n return out;\n}\n\n/**\n * Runs without the whitespace at their end, which a paragraph does not draw. The engine works out\n * that trim when a run changes, not when a run arrives after it, so a run that ended a streaming\n * paragraph and stops ending it would otherwise keep its trimmed space: `Run ` and then a code\n * span would read as one word.\n */\nfunction trimmedEnd(runs: MarkdownInline[]): MarkdownInline[] {\n const last = runs.at(-1);\n if (last?.kind !== 'text') return runs;\n const text = last.text.replace(/[ \\t\\n\\r\\f]+$/, '');\n if (text === last.text) return runs;\n return text ? [...runs.slice(0, -1), { kind: 'text', text }] : runs.slice(0, -1);\n}\n\nfunction inlines(tokens: readonly Token[] | undefined, app: AppLinkSchemes): MarkdownInline[] {\n return (tokens ?? []).flatMap((token) => inline(token, app));\n}\n\n/**\n * Text with each line break the source wrapped it at made a space, as CommonMark reads a soft\n * break, with the spaces around it. A hard break is a `br` token of its own, and stays one.\n */\nfunction softBreaks(text: string): string {\n return text.replace(/ *\\n */g, ' ');\n}\n\nfunction plain(text: string): MarkdownInline {\n return { kind: 'text', text: decodeEntities(text) };\n}\n\nfunction emphasis(token: Token, app: AppLinkSchemes): MarkdownInline[] {\n const kind = token.type as 'strong' | 'em' | 'del';\n return [{ kind, children: inlines((token as Tokens.Strong).tokens, app) }];\n}\n\n/** What each kind of inline token is drawn as. A kind not here is drawn as its source text. */\nconst INLINES: Readonly<Record<string, (token: Token, app: AppLinkSchemes) => MarkdownInline[]>> = {\n text: (token, app) => {\n const text = token as Tokens.Text;\n return text.tokens ? inlines(text.tokens, app) : [plain(softBreaks(text.text))];\n },\n escape: (token) => [plain((token as Tokens.Escape).text)],\n strong: emphasis,\n em: emphasis,\n del: emphasis,\n codespan: (token) => [{ kind: 'code', text: (token as Tokens.Codespan).text }],\n br: () => [{ kind: 'text', text: '\\n' }],\n link: (token, app) => {\n const link = token as Tokens.Link;\n const children = inlines(link.tokens, app);\n const decoded = hrefOf(link);\n const href = decoded === null ? null : linkTarget(decoded, app);\n if (href === null) return children;\n const title = link.title ? decodeEntities(link.title) : null;\n return [{ kind: 'link', href, title, children }];\n },\n image: (token) => [plain((token as Tokens.Image).text)],\n html: (token) => [{ kind: 'text', text: (token as Tokens.HTML).text }],\n checkbox: () => [],\n};\n\nfunction inline(token: Token, app: AppLinkSchemes): MarkdownInline[] {\n const draw = Object.hasOwn(INLINES, token.type) ? INLINES[token.type]! : null;\n if (draw) return draw(token, app);\n return token.raw ? [{ kind: 'text', text: token.raw }] : [];\n}\n\nconst keys = new WeakMap<object, number>();\nlet lastKey = 0;\n\n/**\n * A key for `block` that stays the same while it is drawn: a block kept from the document before\n * keeps its own, and one {@link shareBlocks} made in place of an edited one takes that one's.\n */\nexport function blockKey(block: MarkdownBlock): number {\n let key = keys.get(block);\n if (key === undefined) keys.set(block, (key = ++lastKey));\n return key;\n}\n\n/**\n * `next`, with every part of it that equals the same part of `previous` replaced by that part, so\n * a block that did not change is the object drawn already and is not drawn again. The two are\n * matched from each end, so a block added or removed in the middle leaves those either side of it\n * kept; what is left between is matched by position.\n */\nexport function shareBlocks(\n previous: readonly MarkdownBlock[] | undefined,\n next: readonly MarkdownBlock[],\n): readonly MarkdownBlock[] {\n return previous ? (share(previous, next) as readonly MarkdownBlock[]) : next;\n}\n\nfunction share(previous: unknown, next: unknown): unknown {\n if (previous === next || typeof previous !== 'object' || typeof next !== 'object') return next;\n if (previous === null || next === null) return next;\n if (Array.isArray(previous) !== Array.isArray(next)) return next;\n if (Array.isArray(previous)) return shareArray(previous, next as unknown[]);\n return shareObject(previous as Record<string, unknown>, next as Record<string, unknown>);\n}\n\nfunction shareArray(previous: readonly unknown[], next: readonly unknown[]): readonly unknown[] {\n const out = next.slice();\n // Each pair is compared once: the passes below meet at the same position, and comparing a\n // changed block again in each of them made a nested one cost three times as much a level.\n const compared = new Set<number>();\n const shareAt = (was: number, at: number): unknown => {\n if (was === at) {\n if (compared.has(at)) return out[at];\n compared.add(at);\n }\n return (out[at] = share(previous[was], out[at]));\n };\n let start = 0;\n while (start < out.length && start < previous.length) {\n if (shareAt(start, start) !== previous[start]) break;\n start++;\n }\n let end = 0;\n while (end < out.length - start && end < previous.length - start) {\n const was = previous.length - 1 - end;\n if (shareAt(was, out.length - 1 - end) !== previous[was]) break;\n end++;\n }\n for (let i = start; i < out.length - end && i < previous.length - end; i++) shareAt(i, i);\n const same = out.length === previous.length && out.every((one, i) => one === previous[i]);\n return same ? previous : out;\n}\n\nfunction shareObject(\n previous: Record<string, unknown>,\n next: Record<string, unknown>,\n): Record<string, unknown> {\n if (previous['kind'] !== next['kind']) return next;\n const names = Object.keys(next);\n let same = names.length === Object.keys(previous).length;\n const out: Record<string, unknown> = {};\n for (const name of names) {\n const was = previous[name];\n const kept = Object.hasOwn(previous, name) ? share(was, next[name]) : next[name];\n if (kept !== was) same = false;\n out[name] = kept;\n }\n if (same) return previous;\n const key = keys.get(previous);\n if (key !== undefined) keys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IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,GAAG,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC3B,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjF,IAAI,IAAI,KAAK,GAAG;YAAE,IAAI,GAAG,KAAK,CAAC;QAC/B,GAAG,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IACnB,CAAC;IACD,IAAI,IAAI;QAAE,OAAO,QAAQ,CAAC;IAC1B,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC/B,IAAI,GAAG,KAAK,SAAS;QAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAC1C,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["/**\n * Marked's tokens, turned into the blocks `<markdown>` draws: the entities decoded, the links and\n * images held to the schemes they may use, raw HTML made plain text, and an image lifted out of\n * its paragraph, since a `<text>` cannot hold one.\n *\n * Plain functions with no Angular in them, so the policy is the same wherever the tokens came from:\n * `marked.lexer` on the device, or a build step that lexed them ahead of time.\n */\nimport type { Token, Tokens } from 'marked';\nimport { HTML_ENTITIES } from './html-entities.ts';\n\n/** The elements a document is drawn with, by the HTML names the Markdown would have produced. */\nexport type MarkdownElement =\n | 'h1'\n | 'h2'\n | 'h3'\n | 'h4'\n | 'h5'\n | 'h6'\n | 'p'\n | 'blockquote'\n | 'ul'\n | 'ol'\n | 'li'\n | 'marker'\n | 'pre'\n | 'code'\n | 'strong'\n | 'em'\n | 'del'\n | 'a'\n | 'hr'\n | 'img'\n | 'table'\n | 'tr'\n | 'th'\n | 'td';\n\nexport type MarkdownInline =\n | { readonly kind: 'text'; readonly text: string }\n | { readonly kind: 'strong' | 'em' | 'del'; readonly children: readonly MarkdownInline[] }\n | { readonly kind: 'code'; readonly text: string }\n | {\n readonly kind: 'link';\n readonly href: string;\n readonly title: string | null;\n readonly children: readonly MarkdownInline[];\n };\n\nexport interface MarkdownListItem {\n readonly marker: string;\n readonly children: readonly MarkdownBlock[];\n}\n\nexport type MarkdownBlock =\n | {\n readonly kind: 'heading';\n readonly element: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';\n readonly children: readonly MarkdownInline[];\n }\n | { readonly kind: 'paragraph'; readonly children: readonly MarkdownInline[] }\n | { readonly kind: 'image'; readonly src: string; readonly alt: string }\n | { readonly kind: 'blockquote'; readonly children: readonly MarkdownBlock[] }\n | {\n readonly kind: 'list';\n readonly element: 'ul' | 'ol';\n readonly items: readonly MarkdownListItem[];\n }\n | { readonly kind: 'code'; readonly text: string }\n | { readonly kind: 'hr' }\n | {\n readonly kind: 'table';\n readonly header: readonly (readonly MarkdownInline[])[];\n readonly rows: readonly (readonly (readonly MarkdownInline[])[])[];\n };\n\nlet namedEntities: Map<string, string> | undefined;\n\n/** The character HTML names `name`, from its full table, built on the first name looked up. */\nfunction namedEntity(name: string): string | undefined {\n if (!namedEntities) {\n namedEntities = new Map();\n const pairs = HTML_ENTITIES.split(' ');\n for (let i = 0; i + 1 < pairs.length; i += 2) namedEntities.set(pairs[i]!, pairs[i + 1]!);\n }\n return namedEntities.get(name);\n}\n\nconst ENTITY = /&(?:#(\\d{1,7})|#[xX]([0-9a-fA-F]{1,6})|([a-zA-Z][a-zA-Z0-9]{1,31}));/g;\n\n/**\n * The text an HTML reader would show for `text`, in one pass so `&lt;` is `<` and not `<`.\n * A reference to no character, or to one outside Unicode, is the replacement character, as HTML\n * makes it; a name HTML does not have stays as written.\n */\nexport function decodeEntities(text: string): string {\n if (!text.includes('&')) return text;\n return text.replace(ENTITY, (whole, decimal?: string, hex?: string, name?: string) => {\n if (name !== undefined) return namedEntity(name) ?? whole;\n const code = decimal !== undefined ? Number(decimal) : parseInt(hex!, 16);\n const valid = code > 0 && code <= 0x10ffff && (code < 0xd800 || code > 0xdfff);\n return valid ? String.fromCodePoint(code) : '�';\n });\n}\n\n/**\n * What a URL parser ignores while it reads a scheme: the C0 controls and the space, and the C1\n * controls and DEL beside them. `java\\tscript:` is `javascript:` to the thing that opens it.\n */\nconst IGNORED_IN_SCHEME = /[\\u0000- \\u007f-\\u009f]/g;\nconst SCHEME = /^([a-z][a-z0-9+.-]*):/;\n\n/** The scheme `url` would be opened with, lowercased, or null for a relative one. */\nexport function schemeOf(url: string): string | null {\n return SCHEME.exec(url.replace(IGNORED_IN_SCHEME, '').toLowerCase())?.[1] ?? null;\n}\n\nconst LINK_SCHEMES = new Set(['http', 'https', 'mailto', 'tel']);\nconst IMAGE_SCHEMES = new Set(['http', 'https']);\n\n/** The schemes an app lists for `<markdown>` to draw links in, lowercased. See {@link linkSchemeSet}. */\nexport type AppLinkSchemes = ReadonlySet<string>;\n\n/** No app scheme: what a document is drawn with when the app lists none. */\nexport const NO_APP_SCHEMES: AppLinkSchemes = new Set();\n\nconst SCHEME_NAME = /^[a-z][a-z0-9+.-]*$/;\n\n/**\n * The set of schemes an app lists, as {@link linkTarget} reads them. Each is trimmed, lowercased\n * and stripped of one trailing colon, so `'MyApp:'` and `'myapp'` are the same; an entry that\n * cannot be a scheme is dropped.\n */\nexport function linkSchemeSet(schemes: readonly string[]): AppLinkSchemes {\n const set = new Set<string>();\n for (const one of schemes) {\n const name = one.trim().toLowerCase().replace(/:$/, '');\n if (SCHEME_NAME.test(name)) set.add(name);\n }\n return set.size ? set : NO_APP_SCHEMES;\n}\n\n/**\n * A link's target if it may be drawn as a link: `http`, `https`, `mailto`, `tel`, a scheme the app\n * listed in `appSchemes`, or relative, which is the app's to resolve. Anything else,\n * `javascript:`, `data:`, `vbscript:` and `file:` among them, is null, and the link is drawn as\n * its text. The scheme is read after the trim, so whitespace the trim strips cannot hide one.\n */\nexport function linkTarget(\n href: string,\n appSchemes: AppLinkSchemes = NO_APP_SCHEMES,\n): string | null {\n const target = href.trim();\n const scheme = schemeOf(target);\n return scheme === null || LINK_SCHEMES.has(scheme) || appSchemes.has(scheme) ? target : null;\n}\n\n/**\n * Whether `href` is absolute in one of the built-in schemes a link is followed to, and so is\n * opened on press. A scheme the app listed is drawn as a link but never opens here.\n */\nexport function opensOnPress(href: string): boolean {\n const scheme = schemeOf(href.trim());\n return scheme !== null && LINK_SCHEMES.has(scheme);\n}\n\n/**\n * An image's address if it may be loaded: `http`, `https`, or a picture written into the document\n * as a `data:` url of a raster type. A pasted screenshot arrives that way from a web editor, and\n * a native image only decodes such a picture: nothing in it runs. Any other `data:` url, an SVG\n * or HTML among them, is refused, as is every other scheme.\n */\nexport function imageSource(href: string): string | null {\n const source = href.trim();\n const scheme = schemeOf(source);\n if (scheme === null) return null;\n if (IMAGE_SCHEMES.has(scheme)) return source;\n if (scheme !== 'data') return null;\n // A native loader may not decode a url with whitespace in it, so a wrapped payload is joined.\n const joined = source.replace(/\\s+/g, '');\n return DATA_IMAGE.test(joined) ? joined : null;\n}\n\n/** A base64 `data:` url of a raster picture: PNG, JPEG, GIF or WebP. */\nconst DATA_IMAGE = /^data:image\\/(?:png|jpe?g|gif|webp);base64,[a-z0-9+/=]+$/i;\n\n/** A link's or an image's target with its entities decoded, or null when it is not a string. */\nfunction hrefOf(token: Token): string | null {\n const href: unknown = (token as Tokens.Link).href;\n return typeof href === 'string' ? decodeEntities(href) : null;\n}\n\nconst HEADINGS = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'] as const;\n\n/** The blocks a document of `tokens` is drawn as, with links in `appSchemes` drawn as links too. */\nexport function markdownBlocks(\n tokens: readonly Token[],\n appSchemes: AppLinkSchemes = NO_APP_SCHEMES,\n): MarkdownBlock[] {\n return tokens.flatMap((token) => block(token, appSchemes));\n}\n\n/** What each kind of block token is drawn as. A kind not here is drawn as its source text. */\nconst BLOCKS: Readonly<Record<string, (token: Token, app: AppLinkSchemes) => MarkdownBlock[]>> = {\n heading: (token, app) => {\n const heading = token as Tokens.Heading;\n const depth = Math.min(Math.max(heading.depth, 1), 6);\n const children = trimmedEnd(inlines(heading.tokens, app));\n return [{ kind: 'heading', element: HEADINGS[depth - 1]!, children }];\n },\n paragraph: (token, app) => paragraphs((token as Tokens.Paragraph).tokens, app),\n text: (token, app) => {\n const text = token as Tokens.Text;\n return text.tokens\n ? paragraphs(text.tokens, app)\n : [{ kind: 'paragraph', children: [plain(softBreaks(text.text))] }];\n },\n blockquote: (token, app) => [\n { kind: 'blockquote', children: markdownBlocks((token as Tokens.Blockquote).tokens, app) },\n ],\n list: (token, app) => [list(token as Tokens.List, app)],\n code: (token) => [{ kind: 'code', text: indented((token as Tokens.Code).text) }],\n hr: () => [{ kind: 'hr' }],\n table: (token, app) => {\n const table = token as Tokens.Table;\n return [\n {\n kind: 'table',\n header: table.header.map((cell) => inlines(cell.tokens, app)),\n rows: table.rows.map((row) => row.map((cell) => inlines(cell.tokens, app))),\n },\n ];\n },\n html: (token) => literal((token as Tokens.HTML).text),\n space: () => [],\n def: () => [],\n checkbox: () => [],\n};\n\nfunction block(token: Token, app: AppLinkSchemes): MarkdownBlock[] {\n const draw = Object.hasOwn(BLOCKS, token.type) ? BLOCKS[token.type]! : null;\n return draw ? draw(token, app) : literal(token.raw ?? '');\n}\n\n/**\n * A code block's text with its first line's indent made of no-break spaces: a paragraph loses the\n * spaces at its start, and a block's indent is part of the code.\n */\nfunction indented(text: string): string {\n return text.replace(/^ +/, (spaces) => '\\u00a0'.repeat(spaces.length));\n}\n\n/** Text drawn as written, which is what raw HTML and a token nothing here knows become. */\nfunction literal(text: string): MarkdownBlock[] {\n const trimmed = text.replace(/\\n+$/, '');\n return trimmed.trim() ? [{ kind: 'paragraph', children: [{ kind: 'text', text: trimmed }] }] : [];\n}\n\nfunction list(token: Tokens.List, app: AppLinkSchemes): MarkdownBlock {\n const start = typeof token.start === 'number' ? token.start : 1;\n return {\n kind: 'list',\n element: token.ordered ? 'ol' : 'ul',\n items: token.items.map((item, index) => ({\n marker: item.task ? (item.checked ? '☑' : '☐') : token.ordered ? `${start + index}.` : '•',\n children: markdownBlocks(item.tokens, app),\n })),\n };\n}\n\n/**\n * A paragraph's runs, split around the images at its top level: an image is a block of its own,\n * and the text either side of it a paragraph each. An image whose address is refused, and one\n * inside a link or an emphasis, is its alt text instead.\n */\nfunction paragraphs(tokens: readonly Token[], app: AppLinkSchemes): MarkdownBlock[] {\n const out: MarkdownBlock[] = [];\n let run: MarkdownInline[] = [];\n const flush = () => {\n if (run.some((one) => one.kind !== 'text' || one.text.trim())) {\n out.push({ kind: 'paragraph', children: trimmedEnd(run) });\n }\n run = [];\n };\n for (const token of tokens) {\n const href = token.type === 'image' ? hrefOf(token) : null;\n const src = href === null ? null : imageSource(href);\n if (src === null) {\n run.push(...inline(token, app));\n continue;\n }\n flush();\n out.push({ kind: 'image', src, alt: decodeEntities((token as Tokens.Image).text) });\n }\n flush();\n return out;\n}\n\n/**\n * Runs without the whitespace at their end, which a paragraph does not draw. The engine works out\n * that trim when a run changes, not when a run arrives after it, so a run that ended a streaming\n * paragraph and stops ending it would otherwise keep its trimmed space: `Run ` and then a code\n * span would read as one word.\n */\nfunction trimmedEnd(runs: MarkdownInline[]): MarkdownInline[] {\n const last = runs.at(-1);\n if (last?.kind !== 'text') return runs;\n const text = last.text.replace(/[ \\t\\n\\r\\f]+$/, '');\n if (text === last.text) return runs;\n return text ? [...runs.slice(0, -1), { kind: 'text', text }] : runs.slice(0, -1);\n}\n\nfunction inlines(tokens: readonly Token[] | undefined, app: AppLinkSchemes): MarkdownInline[] {\n return (tokens ?? []).flatMap((token) => inline(token, app));\n}\n\n/**\n * Text with each line break the source wrapped it at made a space, as CommonMark reads a soft\n * break, with the spaces around it. A hard break is a `br` token of its own, and stays one.\n */\nfunction softBreaks(text: string): string {\n return text.replace(/ *\\n */g, ' ');\n}\n\nfunction plain(text: string): MarkdownInline {\n return { kind: 'text', text: decodeEntities(text) };\n}\n\nfunction emphasis(token: Token, app: AppLinkSchemes): MarkdownInline[] {\n const kind = token.type as 'strong' | 'em' | 'del';\n return [{ kind, children: inlines((token as Tokens.Strong).tokens, app) }];\n}\n\n/** What each kind of inline token is drawn as. A kind not here is drawn as its source text. */\nconst INLINES: Readonly<Record<string, (token: Token, app: AppLinkSchemes) => MarkdownInline[]>> = {\n text: (token, app) => {\n const text = token as Tokens.Text;\n return text.tokens ? inlines(text.tokens, app) : [plain(softBreaks(text.text))];\n },\n escape: (token) => [plain((token as Tokens.Escape).text)],\n strong: emphasis,\n em: emphasis,\n del: emphasis,\n codespan: (token) => [{ kind: 'code', text: (token as Tokens.Codespan).text }],\n br: () => [{ kind: 'text', text: '\\n' }],\n link: (token, app) => {\n const link = token as Tokens.Link;\n const children = inlines(link.tokens, app);\n const decoded = hrefOf(link);\n const href = decoded === null ? null : linkTarget(decoded, app);\n if (href === null) return children;\n const title = link.title ? decodeEntities(link.title) : null;\n return [{ kind: 'link', href, title, children }];\n },\n image: (token) => [plain((token as Tokens.Image).text)],\n html: (token) => [{ kind: 'text', text: (token as Tokens.HTML).text }],\n checkbox: () => [],\n};\n\nfunction inline(token: Token, app: AppLinkSchemes): MarkdownInline[] {\n const draw = Object.hasOwn(INLINES, token.type) ? INLINES[token.type]! : null;\n if (draw) return draw(token, app);\n return token.raw ? [{ kind: 'text', text: token.raw }] : [];\n}\n\nconst keys = new WeakMap<object, number>();\nlet lastKey = 0;\n\n/**\n * A key for `block` that stays the same while it is drawn: a block kept from the document before\n * keeps its own, and one {@link shareBlocks} made in place of an edited one takes that one's.\n */\nexport function blockKey(block: MarkdownBlock): number {\n let key = keys.get(block);\n if (key === undefined) keys.set(block, (key = ++lastKey));\n return key;\n}\n\n/**\n * `next`, with every part of it that equals the same part of `previous` replaced by that part, so\n * a block that did not change is the object drawn already and is not drawn again. The two are\n * matched from each end, so a block added or removed in the middle leaves those either side of it\n * kept; what is left between is matched by position. Only that last match keeps a part that\n * changed, so no part of `previous` is matched with two of `next` and no two blocks share a key.\n */\nexport function shareBlocks(\n previous: readonly MarkdownBlock[] | undefined,\n next: readonly MarkdownBlock[],\n): readonly MarkdownBlock[] {\n return previous ? (share(previous, next) as readonly MarkdownBlock[]) : next;\n}\n\nfunction share(previous: unknown, next: unknown): unknown {\n if (previous === next || typeof previous !== 'object' || typeof next !== 'object') return next;\n if (previous === null || next === null) return next;\n if (Array.isArray(previous) !== Array.isArray(next)) return next;\n if (Array.isArray(previous)) return shareArray(previous, next as unknown[]);\n return shareObject(previous as Record<string, unknown>, next as Record<string, unknown>);\n}\n\nfunction shareArray(previous: readonly unknown[], next: readonly unknown[]): readonly unknown[] {\n const out = next.slice();\n // Each pair is compared once: the passes below meet at the same position, and comparing a\n // changed block again in each of them made a nested one cost three times as much a level.\n const compared = new Map<number, unknown>();\n const shareAt = (was: number, at: number): unknown => {\n if (was !== at) return share(previous[was], next[at]);\n if (!compared.has(at)) compared.set(at, share(previous[at], next[at]));\n return compared.get(at);\n };\n const keepAt = (was: number, at: number): boolean => {\n const kept = shareAt(was, at);\n if (kept !== previous[was]) return false;\n out[at] = kept;\n return true;\n };\n let start = 0;\n while (start < out.length && start < previous.length && keepAt(start, start)) start++;\n let end = 0;\n while (\n end < out.length - start &&\n end < previous.length - start &&\n keepAt(previous.length - 1 - end, out.length - 1 - end)\n ) {\n end++;\n }\n for (let i = start; i < out.length - end && i < previous.length - end; i++) {\n out[i] = shareAt(i, i);\n }\n const same = out.length === previous.length && out.every((one, i) => one === previous[i]);\n return same ? previous : out;\n}\n\nfunction shareObject(\n previous: Record<string, unknown>,\n next: Record<string, unknown>,\n): Record<string, unknown> {\n if (previous['kind'] !== next['kind']) return next;\n const names = Object.keys(next);\n let same = names.length === Object.keys(previous).length;\n const out: Record<string, unknown> = {};\n for (const name of names) {\n const was = previous[name];\n const kept = Object.hasOwn(previous, name) ? share(was, next[name]) : next[name];\n if (kept !== was) same = false;\n out[name] = kept;\n }\n if (same) return previous;\n const key = keys.get(previous);\n if (key !== undefined) keys.set(out, key);\n return out;\n}\n"]}
|
package/dist/markdown-columns.js
CHANGED
|
@@ -48,10 +48,10 @@ export class MarkdownColumns {
|
|
|
48
48
|
changed[column] = next;
|
|
49
49
|
this.columns.set({ cells, widths: changed });
|
|
50
50
|
}
|
|
51
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
52
|
-
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.
|
|
51
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: MarkdownColumns, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
52
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.3.0", type: MarkdownColumns, isStandalone: true, selector: "[markdownColumns]", inputs: { table: { classPropertyName: "table", publicName: "markdownColumns", isSignal: true, isRequired: true, transformFunction: null } }, exportAs: ["markdownColumns"], ngImport: i0 });
|
|
53
53
|
}
|
|
54
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
54
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: MarkdownColumns, decorators: [{
|
|
55
55
|
type: Directive,
|
|
56
56
|
args: [{ selector: '[markdownColumns]', exportAs: 'markdownColumns' }]
|
|
57
57
|
}], propDecorators: { table: [{ type: i0.Input, args: [{ isSignal: true, alias: "markdownColumns", required: true }] }] } });
|
package/dist/markdown-stream.js
CHANGED
|
@@ -152,12 +152,15 @@ function heldInline(inline, tail, start) {
|
|
|
152
152
|
return null;
|
|
153
153
|
}
|
|
154
154
|
/**
|
|
155
|
-
* A line of `=`, of dashes with pipes, colons and spaces,
|
|
156
|
-
* `.` or `)`,
|
|
157
|
-
*
|
|
158
|
-
* so it would draw as text in the
|
|
155
|
+
* A line of `=`, of dashes with pipes, colons and spaces, of a lone `+`, `*` or number with or
|
|
156
|
+
* without its `.` or `)`, or of three or more `*` or `_` with spaces, after any quote markers.
|
|
157
|
+
* Until it ends it may be a setext underline, a list item, a table's delimiter row or a thematic
|
|
158
|
+
* break, and a marker with no text yet is not a list item, so it would draw as text in the
|
|
159
|
+
* paragraph above. A number whose `.` has not arrived, or a run of `*` or `_` that more text turns
|
|
160
|
+
* into an emphasis, would otherwise end the block above as it lexes, and keep it ended: a list
|
|
161
|
+
* split in two, or a paragraph whose next line starts `***Note:***` drawn as two.
|
|
159
162
|
*/
|
|
160
|
-
const UNDERLINE = /^(?:[ \t]*>)*(?:[ \t]*=+[ \t]*|[|: \t]*-[-|: \t]*|[ \t]*(?:[+*]|\d{1,9}[.)])[ \t]*)$/;
|
|
163
|
+
const UNDERLINE = /^(?:[ \t]*>)*(?:[ \t]*=+[ \t]*|[|: \t]*-[-|: \t]*|[ \t]*(?:[+*]|\d{1,9}[.)]?|(?:\*[ \t]*){3,}|(?:_[ \t]*){3,})[ \t]*)$/;
|
|
161
164
|
/** Where `tail` is cut so its last block shows nothing half written, or null to show all of it. */
|
|
162
165
|
function holdBackAt(tail, tokens) {
|
|
163
166
|
const block = lastBlock(tokens);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown-stream.js","sourceRoot":"","sources":["../src/markdown-stream.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,KAAK,EAA4C,MAAM,QAAQ,CAAC;AAIzE,0EAA0E;AAC1E,SAAS,gBAAgB,CAAC,MAAwB;IAChD,IAAI,EAAE,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;IAC3B,OAAO,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,EAAE,CAAE,CAAC,IAAI,KAAK,OAAO;QAAE,EAAE,EAAE,CAAC;IACrD,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,8FAA8F;AAC9F,SAAS,SAAS,CAAC,MAAwB;IACzC,MAAM,IAAI,GAAG,MAAM,CAA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QACrB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QACxB,OAAO,CAAC,GAAG,OAAO,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;IACtC,CAAC;IAED;;;OAGG;IACK,MAAM,CAAC,MAAc,EAAE,OAAgB,EAAE,MAAc,EAAE,KAAY,EAAE,IAAa;QAC1F,MAAM,IAAI,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC;QACpC,MAAM,IAAI,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC;QAC1B,MAAM,SAAS,GAAG,EAAE,GAAG,KAAK,EAAE,CAAC;QAC/B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC;YAC9B,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,CAAE,CAAC;YACvB,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,EAAE,MAAM,CAAC;gBAAE,MAAM;YACjD,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC;YAC3B,cAAc,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;QACnC,CAAC;QACD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACpB,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC;QAC5B,IAAI,CAAC,YAAY,GAAG,SAAS,CAAC;IAChC,CAAC;CACF","sourcesContent":["/**\n * A Markdown source that grows as it streams in, lexed a chunk at a time: the blocks before the\n * last one are kept, only the last is lexed again, and syntax still open at its end is held back\n * until it closes, so a half-written code span, emphasis, link, image, table row or code fence\n * line never shows as the characters it is written with. A last line of only dashes, `=` or a\n * list marker waits for its end too, since until then it may make the text above a heading, a\n * list or a table.\n *\n * Plain functions and a class with no Angular in them, beside `markdown-blocks.ts`.\n */\nimport { Lexer, type Token, type Tokens, type TokensList } from 'marked';\n\ntype Links = TokensList['links'];\n\n/** Where the last token in `tokens` that is not blank space is, or -1. */\nfunction lastIndexOfBlock(tokens: readonly Token[]): number {\n let at = tokens.length - 1;\n while (at >= 0 && tokens[at]!.type === 'space') at--;\n return at;\n}\n\n/** The last block in `tokens` that is not blank space, inside the last quote or list item. */\nfunction lastBlock(tokens: readonly Token[]): Token | undefined {\n const last = tokens[lastIndexOfBlock(tokens)];\n if (last?.type === 'list') {\n const item = (last as Tokens.List).items.at(-1);\n return (item && lastBlock(item.tokens)) ?? last;\n }\n if (last?.type === 'blockquote') return lastBlock((last as Tokens.Blockquote).tokens) ?? last;\n return last;\n}\n\nconst WHITESPACE = /\\s/;\nconst WORD = /[\\p{L}\\p{N}]/u;\nconst PUNCTUATION = /[\\p{P}\\p{S}]/u;\nconst DELIMITERS = /`+|\\*+|_+|~+/g;\n\n/** A text token marked left as text, and where it is in the tail, or -1 when it was not found. */\ninterface Leaf {\n readonly raw: string;\n readonly at: number;\n}\n\n/**\n * The text tokens in `inline`, in order, each found in `tail` after the one before it, starting\n * from `from`. A link or an image is passed over whole, as it closed.\n */\nfunction leavesOf(inline: readonly Token[], tail: string, from: number, leaves: Leaf[] = []) {\n let cursor = from;\n for (const token of inline) {\n const at = tail.indexOf(token.raw, cursor);\n const children = (token as Tokens.Generic).tokens;\n if (token.type === 'text' && !children?.length) leaves.push({ raw: token.raw, at });\n else if (children && token.type !== 'link' && token.type !== 'image') {\n leavesOf(children, tail, at < 0 ? cursor : at, leaves);\n }\n if (at >= 0) cursor = at + token.raw.length;\n }\n return leaves;\n}\n\n/**\n * Where the first delimiter in a text token at `at` in `tail` is that could still open a code span\n * or an emphasis. A backtick left as text always could. An asterisk, underscore or tilde could\n * when what follows is not a space, or has not arrived yet, and is not punctuation straight after\n * a letter or digit; an underscore inside a word cannot. What is before and after the delimiter\n * is read from `tail`, since a text token can end where another token starts.\n */\nfunction openerIn(raw: string, at: number, tail: string): number | null {\n for (const match of raw.matchAll(DELIMITERS)) {\n const from = at + match.index;\n const next = tail[from + match[0].length];\n if (canOpen(match[0], tail[from - 1], next)) return from;\n }\n return null;\n}\n\n/** Whether a delimiter run, between `before` and `next`, could open a code span or an emphasis. */\nfunction canOpen(run: string, before: string | undefined, next: string | undefined) {\n if (run[0] === '`') return true;\n if (next !== undefined && WHITESPACE.test(next)) return false;\n const afterWord = before !== undefined && WORD.test(before);\n if (afterWord && next !== undefined && PUNCTUATION.test(next)) return false;\n if (run[0] === '_' && afterWord) return false;\n return !(run[0] === '~' && run.length > 2);\n}\n\n/** Where a fenced code block's half-written fence line starts, or null when it has none. */\nfunction heldFence(block: Token, tail: string): number | null {\n const fence = /^ {0,3}(`{3,}|~{3,})/.exec(block.raw);\n if (!fence) return null;\n const lineStart = tail.lastIndexOf('\\n') + 1;\n // An opening fence whose info string is still arriving.\n if (!block.raw.includes('\\n')) return lineStart;\n // A closing fence, or a line of the fence's own marker that may yet grow into one: a run too\n // short to close it can grow only while nothing follows it. The block's own last line, since in\n // a quote or a list item the source line starts with their markers.\n const closing = fence[1]![0] === '`' ? /^ {0,3}(`+)(\\s*)$/ : /^ {0,3}(~+)(\\s*)$/;\n const last = closing.exec(block.raw.slice(block.raw.lastIndexOf('\\n') + 1));\n const grows = last && (!last[2] || last[1]!.length >= fence[1]!.length);\n return grows && !tail.endsWith('\\n') ? lineStart : null;\n}\n\n/**\n * Where a paragraph that starts like a table row starts, while it is a header row whose delimiter\n * row has not arrived, or is arriving, and so a table once it does.\n */\nfunction heldHeaderRow(block: Token, tail: string): number | null {\n const lines = block.raw.trimEnd().split('\\n');\n // A header row has a pipe, leading or not, as in marked's table syntax.\n if (!lines[0]!.includes('|')) return null;\n if (lines.length > 2) return null;\n // A second line that has ended, or that can no longer be a delimiter row, made no table.\n if (lines.length === 2 && (tail.endsWith('\\n') || !/^[\\s|:-]*$/.test(lines[1]!))) return null;\n const first = tail.lastIndexOf(lines[0]!.trim());\n return first < 0 ? null : tail.lastIndexOf('\\n', first - 1) + 1;\n}\n\n/**\n * From where in `tail` a bracket starts an unfinished link: a label still open, a label that a\n * target may yet follow, or a target still open. Each has at most one closing bracket after its\n * opening one, so the two last closing brackets in `tail` bound where it can start.\n */\nfunction unfinishedLinksFrom(tail: string): number {\n const close = tail.lastIndexOf(']');\n if (close < 0) return 0;\n const after = tail.slice(close + 1);\n const open = after === '' || after[0] === '[' || (after[0] === '(' && !after.includes(')'));\n return open ? tail.lastIndexOf(']', close - 1) + 1 : close + 1;\n}\n\n/**\n * Where the first unfinished link, code span or emphasis in `inline` starts in `tail`, found in\n * one pass over its text tokens. Cutting at the first, rather than the last, means the source is\n * lexed again only when the cut opens a span that closed after it, not once for each delimiter\n * that never closes.\n */\nfunction heldInline(inline: readonly Token[], tail: string, start: number): number | null {\n const leaves = leavesOf(inline, tail, start);\n const links = unfinishedLinksFrom(tail);\n for (const { raw, at } of leaves) {\n if (at < 0) continue;\n const opener = openerIn(raw, at, tail);\n for (let bracket = raw.indexOf('['); bracket >= 0; bracket = raw.indexOf('[', bracket + 1)) {\n const from = at + bracket;\n if (opener !== null && from > opener) break;\n if (from >= links) return tail[from - 1] === '!' ? from - 1 : from;\n }\n if (opener !== null) return opener;\n }\n return null;\n}\n\n/**\n * A line of `=`, of dashes with pipes, colons and spaces, or of a lone `+`, `*` or number with\n * `.` or `)`, after any quote markers. Until it ends it may be a setext underline, a list item,\n * a table's delimiter row or a thematic break, and a marker with no text yet is not a list item,\n * so it would draw as text in the paragraph above.\n */\nconst UNDERLINE =\n /^(?:[ \\t]*>)*(?:[ \\t]*=+[ \\t]*|[|: \\t]*-[-|: \\t]*|[ \\t]*(?:[+*]|\\d{1,9}[.)])[ \\t]*)$/;\n\n/** Where `tail` is cut so its last block shows nothing half written, or null to show all of it. */\nfunction holdBackAt(tail: string, tokens: readonly Token[]): number | null {\n const block = lastBlock(tokens);\n if (!block) return null;\n if (block.type === 'code') return heldFence(block, tail);\n const lineStart = tail.lastIndexOf('\\n') + 1;\n if (block.type === 'table') return tail.endsWith('\\n') ? null : lineStart;\n if (UNDERLINE.test(tail.slice(lineStart))) return lineStart;\n const header = block.type === 'paragraph' ? heldHeaderRow(block, tail) : null;\n if (header !== null) return header;\n const inline = (block as Tokens.Generic).tokens;\n return inline ? heldInline(inline, tail, floorOf(tail, tokens)) : null;\n}\n\n/**\n * Where the last block starts in `tail`, inside a quote or a list item too, found by its first\n * line since there each source line starts with their markers.\n */\nfunction floorOf(tail: string, tokens: readonly Token[]): number {\n const block = lastBlock(tokens);\n if (!block) return tail.length;\n // Its whole source when that is in the tail as it is, since its first line can come again.\n const whole = tail.lastIndexOf(block.raw.trimEnd());\n return Math.max(0, whole >= 0 ? whole : tail.lastIndexOf(block.raw.split('\\n')[0]!));\n}\n\n/** A line's quote and list item markers, up to where the block they hold starts. */\nconst MARKERS = /^(?:[ \\t]*(?:>|[-+*](?=[ \\t])|\\d{1,9}[.)](?=[ \\t])))*[ \\t]*$/;\n\n/**\n * Where the markers before `at` on its line start, when only markers are before it, or `at`. A\n * block held back whole takes its markers with it, or a list item marker left behind would join\n * the paragraph before it.\n */\nfunction markersStart(tail: string, at: number): number {\n const line = tail.lastIndexOf('\\n', at - 1) + 1;\n return MARKERS.test(tail.slice(line, at)) ? line : at;\n}\n\n/**\n * `tail` lexed, cut back until nothing at its end is half written. Only its last block is cut:\n * once a cut reaches where that block starts, the blocks before it, in its quote or list item\n * too, are drawn as they are.\n */\nfunction lexHeldBack(tail: string, links: Links): { tokens: Token[]; links: Links } {\n let floor: number | undefined;\n for (;;) {\n const lexer = new Lexer();\n Object.assign(lexer.tokens.links, links);\n const tokens = lexer.lex(tail);\n floor ??= floorOf(tail, tokens);\n const cut = floor < tail.length ? holdBackAt(tail, tokens) : null;\n if (cut === null || cut >= tail.length) return { tokens, links: tokens.links };\n tail = tail.slice(0, cut > floor ? cut : markersStart(tail, floor));\n }\n}\n\n/** Adds the link references `token` defines, in a quote or a list item too, as marked does. */\nfunction addDefinitions(token: Token, links: Links) {\n if (token.type === 'def') {\n const def = token as Tokens.Def;\n links[def.tag] ??= { href: def.href, title: def.title };\n }\n const inner =\n token.type === 'list'\n ? (token as Tokens.List).items\n : token.type === 'blockquote' || token.type === 'list_item'\n ? (token as Tokens.Generic).tokens\n : undefined;\n for (const child of inner ?? []) addDefinitions(child, links);\n}\n\nfunction sameLinks(next: Links, previous: Links): boolean {\n const names = Object.keys(next);\n if (names.length !== Object.keys(previous).length) return false;\n return names.every(\n (name) =>\n previous[name]?.href === next[name]!.href && previous[name]?.title === next[name]!.title,\n );\n}\n\n/**\n * Lexes a source that grows, keeping the blocks before the last one from the lex before. A source\n * that does not start with the one before is lexed whole, as is one whose new tail defines a link\n * reference or changes one, since that can change a block already kept.\n */\nexport class MarkdownStream {\n private source = '';\n /** The blocks before the last one, whose raw text is the start of the source exactly. */\n private settled: Token[] = [];\n /** How much of the source the settled blocks are. */\n private settledLength = 0;\n /** The link references the settled blocks define. */\n private settledLinks: Links = {};\n /** The link references the whole source defines. */\n private links: Links = {};\n\n lex(text: string): Token[] {\n const source = text.replace(/\\r\\n?/g, '\\n');\n const grown = source.startsWith(this.source);\n let settled = grown ? this.settled : [];\n let offset = grown ? this.settledLength : 0;\n let links = grown ? this.settledLinks : {};\n let tail = lexHeldBack(source.slice(offset), links);\n if (settled.length && !sameLinks(tail.links, this.links)) {\n settled = [];\n offset = 0;\n links = {};\n tail = lexHeldBack(source, links);\n }\n this.settle(source, settled, offset, links, tail.tokens);\n this.source = source;\n this.links = tail.links;\n return [...settled, ...tail.tokens];\n }\n\n /**\n * Keeps the tail's blocks before its last one as settled, as far as their raw text is the\n * source's: marked trims some blocks' raw text, and the lex after starts again from there.\n */\n private settle(source: string, settled: Token[], offset: number, links: Links, tail: Token[]) {\n const last = lastIndexOfBlock(tail);\n const kept = [...settled];\n const keptLinks = { ...links };\n for (let i = 0; i < last; i++) {\n const token = tail[i]!;\n if (!source.startsWith(token.raw, offset)) break;\n kept.push(token);\n offset += token.raw.length;\n addDefinitions(token, keptLinks);\n }\n this.settled = kept;\n this.settledLength = offset;\n this.settledLinks = keptLinks;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"markdown-stream.js","sourceRoot":"","sources":["../src/markdown-stream.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,KAAK,EAA4C,MAAM,QAAQ,CAAC;AAIzE,0EAA0E;AAC1E,SAAS,gBAAgB,CAAC,MAAwB;IAChD,IAAI,EAAE,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;IAC3B,OAAO,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,EAAE,CAAE,CAAC,IAAI,KAAK,OAAO;QAAE,EAAE,EAAE,CAAC;IACrD,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,8FAA8F;AAC9F,SAAS,SAAS,CAAC,MAAwB;IACzC,MAAM,IAAI,GAAG,MAAM,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC;IAC9C,IAAI,IAAI,EAAE,IAAI,KAAK,MAAM,EAAE,CAAC;QAC1B,MAAM,IAAI,GAAI,IAAoB,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QAChD,OAAO,CAAC,IAAI,IAAI,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,IAAI,CAAC;IAClD,CAAC;IACD,IAAI,IAAI,EAAE,IAAI,KAAK,YAAY;QAAE,OAAO,SAAS,CAAE,IAA0B,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC;IAC9F,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,GAAG,IAAI,CAAC;AACxB,MAAM,IAAI,GAAG,eAAe,CAAC;AAC7B,MAAM,WAAW,GAAG,eAAe,CAAC;AACpC,MAAM,UAAU,GAAG,eAAe,CAAC;AAQnC;;;GAGG;AACH,SAAS,QAAQ,CAAC,MAAwB,EAAE,IAAY,EAAE,IAAY,EAAE,SAAiB,EAAE;IACzF,IAAI,MAAM,GAAG,IAAI,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AAI,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC;YAC3B,cAAc,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;QACnC,CAAC;QACD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACpB,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC;QAC5B,IAAI,CAAC,YAAY,GAAG,SAAS,CAAC;IAChC,CAAC;CACF","sourcesContent":["/**\n * A Markdown source that grows as it streams in, lexed a chunk at a time: the blocks before the\n * last one are kept, only the last is lexed again, and syntax still open at its end is held back\n * until it closes, so a half-written code span, emphasis, link, image, table row or code fence\n * line never shows as the characters it is written with. A last line of only dashes, `=` or a\n * list marker waits for its end too, since until then it may make the text above a heading, a\n * list or a table.\n *\n * Plain functions and a class with no Angular in them, beside `markdown-blocks.ts`.\n */\nimport { Lexer, type Token, type Tokens, type TokensList } from 'marked';\n\ntype Links = TokensList['links'];\n\n/** Where the last token in `tokens` that is not blank space is, or -1. */\nfunction lastIndexOfBlock(tokens: readonly Token[]): number {\n let at = tokens.length - 1;\n while (at >= 0 && tokens[at]!.type === 'space') at--;\n return at;\n}\n\n/** The last block in `tokens` that is not blank space, inside the last quote or list item. */\nfunction lastBlock(tokens: readonly Token[]): Token | undefined {\n const last = tokens[lastIndexOfBlock(tokens)];\n if (last?.type === 'list') {\n const item = (last as Tokens.List).items.at(-1);\n return (item && lastBlock(item.tokens)) ?? last;\n }\n if (last?.type === 'blockquote') return lastBlock((last as Tokens.Blockquote).tokens) ?? last;\n return last;\n}\n\nconst WHITESPACE = /\\s/;\nconst WORD = /[\\p{L}\\p{N}]/u;\nconst PUNCTUATION = /[\\p{P}\\p{S}]/u;\nconst DELIMITERS = /`+|\\*+|_+|~+/g;\n\n/** A text token marked left as text, and where it is in the tail, or -1 when it was not found. */\ninterface Leaf {\n readonly raw: string;\n readonly at: number;\n}\n\n/**\n * The text tokens in `inline`, in order, each found in `tail` after the one before it, starting\n * from `from`. A link or an image is passed over whole, as it closed.\n */\nfunction leavesOf(inline: readonly Token[], tail: string, from: number, leaves: Leaf[] = []) {\n let cursor = from;\n for (const token of inline) {\n const at = tail.indexOf(token.raw, cursor);\n const children = (token as Tokens.Generic).tokens;\n if (token.type === 'text' && !children?.length) leaves.push({ raw: token.raw, at });\n else if (children && token.type !== 'link' && token.type !== 'image') {\n leavesOf(children, tail, at < 0 ? cursor : at, leaves);\n }\n if (at >= 0) cursor = at + token.raw.length;\n }\n return leaves;\n}\n\n/**\n * Where the first delimiter in a text token at `at` in `tail` is that could still open a code span\n * or an emphasis. A backtick left as text always could. An asterisk, underscore or tilde could\n * when what follows is not a space, or has not arrived yet, and is not punctuation straight after\n * a letter or digit; an underscore inside a word cannot. What is before and after the delimiter\n * is read from `tail`, since a text token can end where another token starts.\n */\nfunction openerIn(raw: string, at: number, tail: string): number | null {\n for (const match of raw.matchAll(DELIMITERS)) {\n const from = at + match.index;\n const next = tail[from + match[0].length];\n if (canOpen(match[0], tail[from - 1], next)) return from;\n }\n return null;\n}\n\n/** Whether a delimiter run, between `before` and `next`, could open a code span or an emphasis. */\nfunction canOpen(run: string, before: string | undefined, next: string | undefined) {\n if (run[0] === '`') return true;\n if (next !== undefined && WHITESPACE.test(next)) return false;\n const afterWord = before !== undefined && WORD.test(before);\n if (afterWord && next !== undefined && PUNCTUATION.test(next)) return false;\n if (run[0] === '_' && afterWord) return false;\n return !(run[0] === '~' && run.length > 2);\n}\n\n/** Where a fenced code block's half-written fence line starts, or null when it has none. */\nfunction heldFence(block: Token, tail: string): number | null {\n const fence = /^ {0,3}(`{3,}|~{3,})/.exec(block.raw);\n if (!fence) return null;\n const lineStart = tail.lastIndexOf('\\n') + 1;\n // An opening fence whose info string is still arriving.\n if (!block.raw.includes('\\n')) return lineStart;\n // A closing fence, or a line of the fence's own marker that may yet grow into one: a run too\n // short to close it can grow only while nothing follows it. The block's own last line, since in\n // a quote or a list item the source line starts with their markers.\n const closing = fence[1]![0] === '`' ? /^ {0,3}(`+)(\\s*)$/ : /^ {0,3}(~+)(\\s*)$/;\n const last = closing.exec(block.raw.slice(block.raw.lastIndexOf('\\n') + 1));\n const grows = last && (!last[2] || last[1]!.length >= fence[1]!.length);\n return grows && !tail.endsWith('\\n') ? lineStart : null;\n}\n\n/**\n * Where a paragraph that starts like a table row starts, while it is a header row whose delimiter\n * row has not arrived, or is arriving, and so a table once it does.\n */\nfunction heldHeaderRow(block: Token, tail: string): number | null {\n const lines = block.raw.trimEnd().split('\\n');\n // A header row has a pipe, leading or not, as in marked's table syntax.\n if (!lines[0]!.includes('|')) return null;\n if (lines.length > 2) return null;\n // A second line that has ended, or that can no longer be a delimiter row, made no table.\n if (lines.length === 2 && (tail.endsWith('\\n') || !/^[\\s|:-]*$/.test(lines[1]!))) return null;\n const first = tail.lastIndexOf(lines[0]!.trim());\n return first < 0 ? null : tail.lastIndexOf('\\n', first - 1) + 1;\n}\n\n/**\n * From where in `tail` a bracket starts an unfinished link: a label still open, a label that a\n * target may yet follow, or a target still open. Each has at most one closing bracket after its\n * opening one, so the two last closing brackets in `tail` bound where it can start.\n */\nfunction unfinishedLinksFrom(tail: string): number {\n const close = tail.lastIndexOf(']');\n if (close < 0) return 0;\n const after = tail.slice(close + 1);\n const open = after === '' || after[0] === '[' || (after[0] === '(' && !after.includes(')'));\n return open ? tail.lastIndexOf(']', close - 1) + 1 : close + 1;\n}\n\n/**\n * Where the first unfinished link, code span or emphasis in `inline` starts in `tail`, found in\n * one pass over its text tokens. Cutting at the first, rather than the last, means the source is\n * lexed again only when the cut opens a span that closed after it, not once for each delimiter\n * that never closes.\n */\nfunction heldInline(inline: readonly Token[], tail: string, start: number): number | null {\n const leaves = leavesOf(inline, tail, start);\n const links = unfinishedLinksFrom(tail);\n for (const { raw, at } of leaves) {\n if (at < 0) continue;\n const opener = openerIn(raw, at, tail);\n for (let bracket = raw.indexOf('['); bracket >= 0; bracket = raw.indexOf('[', bracket + 1)) {\n const from = at + bracket;\n if (opener !== null && from > opener) break;\n if (from >= links) return tail[from - 1] === '!' ? from - 1 : from;\n }\n if (opener !== null) return opener;\n }\n return null;\n}\n\n/**\n * A line of `=`, of dashes with pipes, colons and spaces, of a lone `+`, `*` or number with or\n * without its `.` or `)`, or of three or more `*` or `_` with spaces, after any quote markers.\n * Until it ends it may be a setext underline, a list item, a table's delimiter row or a thematic\n * break, and a marker with no text yet is not a list item, so it would draw as text in the\n * paragraph above. A number whose `.` has not arrived, or a run of `*` or `_` that more text turns\n * into an emphasis, would otherwise end the block above as it lexes, and keep it ended: a list\n * split in two, or a paragraph whose next line starts `***Note:***` drawn as two.\n */\nconst UNDERLINE =\n /^(?:[ \\t]*>)*(?:[ \\t]*=+[ \\t]*|[|: \\t]*-[-|: \\t]*|[ \\t]*(?:[+*]|\\d{1,9}[.)]?|(?:\\*[ \\t]*){3,}|(?:_[ \\t]*){3,})[ \\t]*)$/;\n\n/** Where `tail` is cut so its last block shows nothing half written, or null to show all of it. */\nfunction holdBackAt(tail: string, tokens: readonly Token[]): number | null {\n const block = lastBlock(tokens);\n if (!block) return null;\n if (block.type === 'code') return heldFence(block, tail);\n const lineStart = tail.lastIndexOf('\\n') + 1;\n if (block.type === 'table') return tail.endsWith('\\n') ? null : lineStart;\n if (UNDERLINE.test(tail.slice(lineStart))) return lineStart;\n const header = block.type === 'paragraph' ? heldHeaderRow(block, tail) : null;\n if (header !== null) return header;\n const inline = (block as Tokens.Generic).tokens;\n return inline ? heldInline(inline, tail, floorOf(tail, tokens)) : null;\n}\n\n/**\n * Where the last block starts in `tail`, inside a quote or a list item too, found by its first\n * line since there each source line starts with their markers.\n */\nfunction floorOf(tail: string, tokens: readonly Token[]): number {\n const block = lastBlock(tokens);\n if (!block) return tail.length;\n // Its whole source when that is in the tail as it is, since its first line can come again.\n const whole = tail.lastIndexOf(block.raw.trimEnd());\n return Math.max(0, whole >= 0 ? whole : tail.lastIndexOf(block.raw.split('\\n')[0]!));\n}\n\n/** A line's quote and list item markers, up to where the block they hold starts. */\nconst MARKERS = /^(?:[ \\t]*(?:>|[-+*](?=[ \\t])|\\d{1,9}[.)](?=[ \\t])))*[ \\t]*$/;\n\n/**\n * Where the markers before `at` on its line start, when only markers are before it, or `at`. A\n * block held back whole takes its markers with it, or a list item marker left behind would join\n * the paragraph before it.\n */\nfunction markersStart(tail: string, at: number): number {\n const line = tail.lastIndexOf('\\n', at - 1) + 1;\n return MARKERS.test(tail.slice(line, at)) ? line : at;\n}\n\n/**\n * `tail` lexed, cut back until nothing at its end is half written. Only its last block is cut:\n * once a cut reaches where that block starts, the blocks before it, in its quote or list item\n * too, are drawn as they are.\n */\nfunction lexHeldBack(tail: string, links: Links): { tokens: Token[]; links: Links } {\n let floor: number | undefined;\n for (;;) {\n const lexer = new Lexer();\n Object.assign(lexer.tokens.links, links);\n const tokens = lexer.lex(tail);\n floor ??= floorOf(tail, tokens);\n const cut = floor < tail.length ? holdBackAt(tail, tokens) : null;\n if (cut === null || cut >= tail.length) return { tokens, links: tokens.links };\n tail = tail.slice(0, cut > floor ? cut : markersStart(tail, floor));\n }\n}\n\n/** Adds the link references `token` defines, in a quote or a list item too, as marked does. */\nfunction addDefinitions(token: Token, links: Links) {\n if (token.type === 'def') {\n const def = token as Tokens.Def;\n links[def.tag] ??= { href: def.href, title: def.title };\n }\n const inner =\n token.type === 'list'\n ? (token as Tokens.List).items\n : token.type === 'blockquote' || token.type === 'list_item'\n ? (token as Tokens.Generic).tokens\n : undefined;\n for (const child of inner ?? []) addDefinitions(child, links);\n}\n\nfunction sameLinks(next: Links, previous: Links): boolean {\n const names = Object.keys(next);\n if (names.length !== Object.keys(previous).length) return false;\n return names.every(\n (name) =>\n previous[name]?.href === next[name]!.href && previous[name]?.title === next[name]!.title,\n );\n}\n\n/**\n * Lexes a source that grows, keeping the blocks before the last one from the lex before. A source\n * that does not start with the one before is lexed whole, as is one whose new tail defines a link\n * reference or changes one, since that can change a block already kept.\n */\nexport class MarkdownStream {\n private source = '';\n /** The blocks before the last one, whose raw text is the start of the source exactly. */\n private settled: Token[] = [];\n /** How much of the source the settled blocks are. */\n private settledLength = 0;\n /** The link references the settled blocks define. */\n private settledLinks: Links = {};\n /** The link references the whole source defines. */\n private links: Links = {};\n\n lex(text: string): Token[] {\n const source = text.replace(/\\r\\n?/g, '\\n');\n const grown = source.startsWith(this.source);\n let settled = grown ? this.settled : [];\n let offset = grown ? this.settledLength : 0;\n let links = grown ? this.settledLinks : {};\n let tail = lexHeldBack(source.slice(offset), links);\n if (settled.length && !sameLinks(tail.links, this.links)) {\n settled = [];\n offset = 0;\n links = {};\n tail = lexHeldBack(source, links);\n }\n this.settle(source, settled, offset, links, tail.tokens);\n this.source = source;\n this.links = tail.links;\n return [...settled, ...tail.tokens];\n }\n\n /**\n * Keeps the tail's blocks before its last one as settled, as far as their raw text is the\n * source's: marked trims some blocks' raw text, and the lex after starts again from there.\n */\n private settle(source: string, settled: Token[], offset: number, links: Links, tail: Token[]) {\n const last = lastIndexOfBlock(tail);\n const kept = [...settled];\n const keptLinks = { ...links };\n for (let i = 0; i < last; i++) {\n const token = tail[i]!;\n if (!source.startsWith(token.raw, offset)) break;\n kept.push(token);\n offset += token.raw.length;\n addDefinitions(token, keptLinks);\n }\n this.settled = kept;\n this.settledLength = offset;\n this.settledLinks = keptLinks;\n }\n}\n"]}
|
package/dist/markdown.js
CHANGED
|
@@ -270,8 +270,8 @@ export class Markdown {
|
|
|
270
270
|
if (!prevented && opensOnPress(link.href))
|
|
271
271
|
this.injector.get(DeepLinks).open(link.href);
|
|
272
272
|
}
|
|
273
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
274
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.
|
|
273
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: Markdown, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
274
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.3.0", type: Markdown, isStandalone: true, selector: "markdown", inputs: { source: { classPropertyName: "source", publicName: "source", isSignal: true, isRequired: false, transformFunction: null }, tokens: { classPropertyName: "tokens", publicName: "tokens", isSignal: true, isRequired: false, transformFunction: null }, streaming: { classPropertyName: "streaming", publicName: "streaming", isSignal: true, isRequired: false, transformFunction: null }, linkSchemes: { classPropertyName: "linkSchemes", publicName: "linkSchemes", isSignal: true, isRequired: false, transformFunction: null }, classes: { classPropertyName: "classes", publicName: "classes", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { linkPress: "linkPress" }, host: { properties: { "class.md-ios": "apple", "class.md-android": "platform === 'android'" } }, ngImport: i0, template: `
|
|
275
275
|
<ng-template #blockTemplate let-list>
|
|
276
276
|
@for (block of list; track blockKey(block)) {
|
|
277
277
|
@switch (block.kind) {
|
|
@@ -392,9 +392,9 @@ export class Markdown {
|
|
|
392
392
|
</ng-template>
|
|
393
393
|
|
|
394
394
|
<ng-container *templateSlot="blockTemplate; context: { $implicit: blocks() }" />
|
|
395
|
-
`, isInline: true, styles: ["/* What a document looks like with no `classes` of the app's, in light and in dark. */\n\n:host {\n gap: 12px;\n color: #1c1c1e;\n}\n\n.md-h1,\n.md-h2,\n.md-h3,\n.md-h4,\n.md-h5,\n.md-h6 {\n font-weight: 700;\n}\n\n.md-h1 {\n font-size: 28px;\n line-height: 34px;\n}\n\n.md-h2 {\n font-size: 22px;\n line-height: 28px;\n}\n\n.md-h3 {\n font-size: 20px;\n line-height: 25px;\n}\n\n.md-h4 {\n font-size: 17px;\n line-height: 22px;\n}\n\n.md-h5 {\n font-size: 15px;\n line-height: 20px;\n}\n\n.md-h6 {\n font-size: 13px;\n line-height: 18px;\n color: #6c6c70;\n}\n\n.md-
|
|
395
|
+
`, isInline: true, styles: ["/* What a document looks like with no `classes` of the app's, in light and in dark. */\n\n:host {\n gap: 12px;\n color: #1c1c1e;\n /* The document's size, here so a class on the element replaces it: paragraphs, list markers and\n table cells set none of their own and inherit this. */\n font-size: 16px;\n line-height: 23px;\n}\n\n.md-h1,\n.md-h2,\n.md-h3,\n.md-h4,\n.md-h5,\n.md-h6 {\n font-weight: 700;\n}\n\n.md-h1 {\n font-size: 28px;\n line-height: 34px;\n}\n\n.md-h2 {\n font-size: 22px;\n line-height: 28px;\n}\n\n.md-h3 {\n font-size: 20px;\n line-height: 25px;\n}\n\n.md-h4 {\n font-size: 17px;\n line-height: 22px;\n}\n\n.md-h5 {\n font-size: 15px;\n line-height: 20px;\n}\n\n.md-h6 {\n font-size: 13px;\n line-height: 18px;\n color: #6c6c70;\n}\n\n.md-strong {\n font-weight: 700;\n}\n\n.md-em {\n font-style: italic;\n}\n\n.md-del {\n text-decoration-line: line-through;\n}\n\n.md-a {\n color: #0a66d8;\n text-decoration-line: underline;\n}\n\n.md-code {\n background-color: rgba(120, 120, 128, 0.16);\n}\n\n.md-code,\n.md-pre {\n font-family: Courier New;\n}\n\n:host(.md-ios) .md-code,\n:host(.md-ios) .md-pre {\n font-family: Menlo;\n}\n\n:host(.md-android) .md-code,\n:host(.md-android) .md-pre {\n font-family: monospace;\n}\n\n.md-blockquote {\n gap: 8px;\n padding-left: 12px;\n border-left-width: 3px;\n border-left-color: #d1d1d6;\n color: #6c6c70;\n}\n\n.md-ul,\n.md-ol {\n gap: 4px;\n}\n\n.md-li {\n flex-direction: row;\n gap: 8px;\n}\n\n.md-marker {\n min-width: 16px;\n}\n\n.md-li-body {\n flex: 1;\n gap: 4px;\n}\n\n.md-pre {\n flex-grow: 0;\n border-radius: 8px;\n background-color: #f2f2f7;\n}\n\n.md-pre-text {\n padding: 12px;\n font-size: 14px;\n line-height: 20px;\n}\n\n.md-hr {\n height: 1px;\n background-color: #d1d1d6;\n}\n\n.md-img {\n width: var(--md-img-width, 100%);\n max-width: 100%;\n height: 200px;\n border-radius: 8px;\n}\n\n.md-table {\n border-width: 1px;\n border-color: #d1d1d6;\n border-radius: 8px;\n overflow: hidden;\n}\n\n.md-tr {\n flex-direction: row;\n}\n\n/* The text hugs its content inside the column's least width, so it can report a narrower one. */\n.md-cell {\n align-items: flex-start;\n}\n\n.md-th,\n.md-td {\n max-width: 280px;\n padding: 6px 8px;\n}\n\n.md-cell-body {\n border-top-width: 1px;\n border-top-color: #d1d1d6;\n}\n\n.md-th {\n font-weight: 600;\n}\n\n@media (prefers-color-scheme: dark) {\n :host {\n color: #f2f2f7;\n }\n\n .md-h6,\n .md-blockquote {\n color: #98989f;\n }\n\n .md-a {\n color: #4c9bff;\n }\n\n .md-code {\n background-color: rgba(120, 120, 128, 0.32);\n }\n\n .md-pre {\n background-color: #1c1c1e;\n }\n\n .md-blockquote,\n .md-table,\n .md-cell-body {\n border-color: #38383a;\n }\n\n .md-hr {\n background-color: #38383a;\n }\n}\n"], dependencies: [{ kind: "directive", type: Image, selector: "image", inputs: ["source", "src", "srcSet", "defaultSource", "loadingIndicatorSource", "resizeMode", "resizeMethod", "resizeMultiplier", "blurRadius", "capInsets", "tintColor", "fadeDuration", "progressiveRenderingEnabled", "alt", "crossOrigin", "referrerPolicy"] }, { kind: "directive", type: MarkdownColumns, selector: "[markdownColumns]", inputs: ["markdownColumns"], exportAs: ["markdownColumns"] }, { kind: "component", type: ScrollView, selector: "scroll-view", inputs: ["contentContainerStyle", "contentContainerClass", "horizontal", "contentOffset", "maintainVisibleContentPosition", "keyboardShouldPersistTaps", "nestedScrollEnabled", "stickyHeaderIndices"], outputs: ["contentSizeChange"], exportAs: ["scrollView"] }, { kind: "directive", type: TemplateSlot, selector: "[templateSlot]", inputs: ["templateSlot", "templateSlotContext"] }, { kind: "directive", type: Text, selector: "text", inputs: ["numberOfLines", "ellipsizeMode", "selectable", "selectionColor", "allowFontScaling", "maxFontSizeMultiplier", "dynamicTypeRamp", "adjustsFontSizeToFit", "minimumFontScale", "lineBreakStrategyIOS", "textBreakStrategy", "dataDetectorType", "android_hyphenationFrequency", "pressable", "suppressHighlighting"], exportAs: ["text"] }, { kind: "directive", type: View, selector: "view" }] });
|
|
396
396
|
}
|
|
397
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
397
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: Markdown, decorators: [{
|
|
398
398
|
type: Component,
|
|
399
399
|
args: [{ selector: 'markdown', imports: [Image, MarkdownColumns, ScrollView, TemplateSlot, Text, View], template: `
|
|
400
400
|
<ng-template #blockTemplate let-list>
|
|
@@ -520,6 +520,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImpor
|
|
|
520
520
|
`, host: {
|
|
521
521
|
'[class.md-ios]': 'apple',
|
|
522
522
|
'[class.md-android]': "platform === 'android'",
|
|
523
|
-
}, styles: ["/* What a document looks like with no `classes` of the app's, in light and in dark. */\n\n:host {\n gap: 12px;\n color: #1c1c1e;\n}\n\n.md-h1,\n.md-h2,\n.md-h3,\n.md-h4,\n.md-h5,\n.md-h6 {\n font-weight: 700;\n}\n\n.md-h1 {\n font-size: 28px;\n line-height: 34px;\n}\n\n.md-h2 {\n font-size: 22px;\n line-height: 28px;\n}\n\n.md-h3 {\n font-size: 20px;\n line-height: 25px;\n}\n\n.md-h4 {\n font-size: 17px;\n line-height: 22px;\n}\n\n.md-h5 {\n font-size: 15px;\n line-height: 20px;\n}\n\n.md-h6 {\n font-size: 13px;\n line-height: 18px;\n color: #6c6c70;\n}\n\n.md-
|
|
523
|
+
}, styles: ["/* What a document looks like with no `classes` of the app's, in light and in dark. */\n\n:host {\n gap: 12px;\n color: #1c1c1e;\n /* The document's size, here so a class on the element replaces it: paragraphs, list markers and\n table cells set none of their own and inherit this. */\n font-size: 16px;\n line-height: 23px;\n}\n\n.md-h1,\n.md-h2,\n.md-h3,\n.md-h4,\n.md-h5,\n.md-h6 {\n font-weight: 700;\n}\n\n.md-h1 {\n font-size: 28px;\n line-height: 34px;\n}\n\n.md-h2 {\n font-size: 22px;\n line-height: 28px;\n}\n\n.md-h3 {\n font-size: 20px;\n line-height: 25px;\n}\n\n.md-h4 {\n font-size: 17px;\n line-height: 22px;\n}\n\n.md-h5 {\n font-size: 15px;\n line-height: 20px;\n}\n\n.md-h6 {\n font-size: 13px;\n line-height: 18px;\n color: #6c6c70;\n}\n\n.md-strong {\n font-weight: 700;\n}\n\n.md-em {\n font-style: italic;\n}\n\n.md-del {\n text-decoration-line: line-through;\n}\n\n.md-a {\n color: #0a66d8;\n text-decoration-line: underline;\n}\n\n.md-code {\n background-color: rgba(120, 120, 128, 0.16);\n}\n\n.md-code,\n.md-pre {\n font-family: Courier New;\n}\n\n:host(.md-ios) .md-code,\n:host(.md-ios) .md-pre {\n font-family: Menlo;\n}\n\n:host(.md-android) .md-code,\n:host(.md-android) .md-pre {\n font-family: monospace;\n}\n\n.md-blockquote {\n gap: 8px;\n padding-left: 12px;\n border-left-width: 3px;\n border-left-color: #d1d1d6;\n color: #6c6c70;\n}\n\n.md-ul,\n.md-ol {\n gap: 4px;\n}\n\n.md-li {\n flex-direction: row;\n gap: 8px;\n}\n\n.md-marker {\n min-width: 16px;\n}\n\n.md-li-body {\n flex: 1;\n gap: 4px;\n}\n\n.md-pre {\n flex-grow: 0;\n border-radius: 8px;\n background-color: #f2f2f7;\n}\n\n.md-pre-text {\n padding: 12px;\n font-size: 14px;\n line-height: 20px;\n}\n\n.md-hr {\n height: 1px;\n background-color: #d1d1d6;\n}\n\n.md-img {\n width: var(--md-img-width, 100%);\n max-width: 100%;\n height: 200px;\n border-radius: 8px;\n}\n\n.md-table {\n border-width: 1px;\n border-color: #d1d1d6;\n border-radius: 8px;\n overflow: hidden;\n}\n\n.md-tr {\n flex-direction: row;\n}\n\n/* The text hugs its content inside the column's least width, so it can report a narrower one. */\n.md-cell {\n align-items: flex-start;\n}\n\n.md-th,\n.md-td {\n max-width: 280px;\n padding: 6px 8px;\n}\n\n.md-cell-body {\n border-top-width: 1px;\n border-top-color: #d1d1d6;\n}\n\n.md-th {\n font-weight: 600;\n}\n\n@media (prefers-color-scheme: dark) {\n :host {\n color: #f2f2f7;\n }\n\n .md-h6,\n .md-blockquote {\n color: #98989f;\n }\n\n .md-a {\n color: #4c9bff;\n }\n\n .md-code {\n background-color: rgba(120, 120, 128, 0.32);\n }\n\n .md-pre {\n background-color: #1c1c1e;\n }\n\n .md-blockquote,\n .md-table,\n .md-cell-body {\n border-color: #38383a;\n }\n\n .md-hr {\n background-color: #38383a;\n }\n}\n"] }]
|
|
524
524
|
}], propDecorators: { source: [{ type: i0.Input, args: [{ isSignal: true, alias: "source", required: false }] }], tokens: [{ type: i0.Input, args: [{ isSignal: true, alias: "tokens", required: false }] }], streaming: [{ type: i0.Input, args: [{ isSignal: true, alias: "streaming", required: false }] }], linkSchemes: [{ type: i0.Input, args: [{ isSignal: true, alias: "linkSchemes", required: false }] }], classes: [{ type: i0.Input, args: [{ isSignal: true, alias: "classes", required: false }] }], linkPress: [{ type: i0.Output, args: ["linkPress"] }] } });
|
|
525
525
|
//# sourceMappingURL=markdown.js.map
|
package/dist/markdown.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown.js","sourceRoot":"","sources":["../src/markdown.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EACL,SAAS,EACT,QAAQ,EACR,cAAc,EACd,gBAAgB,EAChB,QAAQ,EACR,MAAM,EACN,KAAK,EACL,YAAY,EACZ,MAAM,GAEP,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,KAAK,EAAc,MAAM,QAAQ,CAAC;AAE3C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EACL,QAAQ,EACR,aAAa,EACb,cAAc,EACd,YAAY,EACZ,WAAW,GAKZ,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,eAAe,EAAE,M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B,EAAE,OAAO;wBACzB,oBAAoB,EAAE,wBAAwB;qBAC/C","sourcesContent":["/**\n * Markdown, drawn as native views and text.\n *\n * Its own entry point because it parses with `marked`, an optional peer dependency an app installs\n * only when it renders Markdown: the barrel never imports it, so an app that does not is not asked\n * for it.\n *\n * ```ts\n * import { Markdown } from '@ng-native/components/markdown';\n * ```\n */\nimport {\n Component,\n Injector,\n InjectionToken,\n booleanAttribute,\n computed,\n inject,\n input,\n linkedSignal,\n output,\n type Provider,\n} from '@angular/core';\nimport { DeepLinks } from '@ng-native/device';\nimport { isApplePlatform, nativePlatform } from '@ng-native/fabric';\nimport { lexer, type Token } from 'marked';\nimport type { ImageLoadEvent, LayoutEvent } from './events.ts';\nimport { Image } from './image.ts';\nimport {\n blockKey,\n linkSchemeSet,\n markdownBlocks,\n opensOnPress,\n shareBlocks,\n type AppLinkSchemes,\n type MarkdownBlock,\n type MarkdownElement,\n type MarkdownInline,\n} from './markdown-blocks.ts';\nimport { MarkdownColumns } from './markdown-columns.ts';\nimport { MarkdownStream } from './markdown-stream.ts';\nimport { ScrollView } from './scroll-view.ts';\nimport { TemplateSlot } from './template-slot.ts';\nimport { Text } from './text.ts';\nimport { View } from './view.ts';\n\nexport type { MarkdownElement } from './markdown-blocks.ts';\n\n/** Classes for the elements a document is drawn with, each one in place of the default. */\nexport type MarkdownClasses = Partial<Readonly<Record<MarkdownElement, string>>>;\n\n/** `(linkPress)`: a link was pressed. */\nexport interface MarkdownLinkPress {\n /** The target as written, after its entities are decoded and its scheme was allowed. */\n readonly href: string;\n readonly title: string | null;\n /** Keep the link from being opened, to handle it in the app instead. */\n preventDefault(): void;\n}\n\n/**\n * The schemes, beyond `http`, `https`, `mailto` and `tel`, that every `<markdown>` draws links in\n * unless its own `linkSchemes` is set. See `provideMarkdownLinkSchemes`.\n */\nexport const MARKDOWN_LINK_SCHEMES = new InjectionToken<readonly string[]>(\n 'MARKDOWN_LINK_SCHEMES',\n { providedIn: 'root', factory: () => [] },\n);\n\n/**\n * Make links in the app's own schemes links in every `<markdown>`, such as `myapp:item/42`:\n * drawn as links and reported through `(linkPress)`, and never opened by default. A\n * `[linkSchemes]` input on one `<markdown>` replaces this list for that one.\n *\n * ```ts\n * providers: [provideMarkdownLinkSchemes('myapp')]\n * ```\n */\nexport function provideMarkdownLinkSchemes(...schemes: readonly string[]): Provider {\n return { provide: MARKDOWN_LINK_SCHEMES, useValue: schemes };\n}\n\nconst ELEMENTS: readonly MarkdownElement[] = [\n ...['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'blockquote', 'ul', 'ol', 'li', 'marker'],\n ...['pre', 'code', 'strong', 'em', 'del', 'a', 'hr', 'img', 'table', 'tr', 'th', 'td'],\n] as MarkdownElement[];\n\nconst DEFAULT_CLASSES = Object.fromEntries(\n ELEMENTS.map((element) => [element, `md-${element}`]),\n) as Readonly<Record<MarkdownElement, string>>;\n\ntype MarkdownLink = Extract<MarkdownInline, { kind: 'link' }>;\n\n/** A loaded image's own width in points, and its width over its height. */\ninterface ImageSize {\n readonly width: number;\n readonly ratio: number;\n}\n\ntype ImageBlock = Extract<MarkdownBlock, { kind: 'image' }>;\n\n/** Every image in `blocks`, however deep in quotes and lists. */\nfunction imageBlocks(\n blocks: readonly MarkdownBlock[],\n into = new Set<ImageBlock>(),\n): Set<ImageBlock> {\n for (const block of blocks) {\n if (block.kind === 'image') into.add(block);\n else if (block.kind === 'blockquote') imageBlocks(block.children, into);\n else if (block.kind === 'list') {\n for (const item of block.items) imageBlocks(item.children, into);\n }\n }\n return into;\n}\n\n/**\n * A Markdown document as `<text>`, `<view>`, `<image>` and `<scroll-view>`: headings, paragraphs,\n * emphasis, inline code, links, quotes, ordered, unordered and task lists, code blocks, rules,\n * tables and images.\n *\n * `source` is parsed with `marked.lexer`; `tokens` takes tokens lexed already, and wins when both\n * are set. A paragraph is one `<text>` with a nested `<text>` for each emphasis, code span and\n * link, so it wraps as one run; an image is lifted out to a block of its own.\n *\n * Nothing in the document is interpreted. Raw HTML is drawn as the text it is written as, a link\n * is followed only to `http`, `https`, `mailto`, `tel` or a relative target, and an image is\n * loaded only over `http` or `https`; anything else is drawn as its text.\n *\n * Each element carries a default class, `md-h1`, `md-p`, `md-a` and so on, styled in light and\n * dark. `classes` replaces one by its element's name, so a global stylesheet or Tailwind styles it\n * instead: `{ h1: 'text-3xl font-bold' }`. Put the default back beside your own to keep both.\n *\n * For a source that grows as it streams in, an answer arriving a few words at a time, set\n * `streaming` until it is complete. The blocks before the last one are then kept as they are and\n * only the last is lexed and converted again, unless a chunk defines or changes a link reference,\n * which can change a block already kept, and the whole source is lexed again. Syntax still open at its end, a code span, an emphasis, a link,\n * an image or a table row, is held back until it closes. Of a code fence only an unfinished\n * opening line is held back, and its code then streams as it arrives. Clearing `streaming` draws\n * the whole source as written, and `tokens` are always drawn as given. A block that did not\n * change keeps its views, streaming or not.\n *\n * A pressed link is `(linkPress)`. An absolute target is then opened with `DeepLinks.open` unless\n * a handler calls `preventDefault()`; a relative one is only reported, for the app to route.\n *\n * A link in the app's own scheme, `myapp:item/42`, is drawn as plain text unless the scheme is\n * listed in `linkSchemes`, or app-wide with `provideMarkdownLinkSchemes`. A listed scheme is drawn\n * as a link and reported through `(linkPress)`, and is never opened: the app routes it. The input\n * replaces the provider's list when it is set, even to an empty one. Schemes are matched without\n * regard to case, and the list is read as a value: give a new array to change it.\n */\n@Component({\n selector: 'markdown',\n imports: [Image, MarkdownColumns, ScrollView, TemplateSlot, Text, View],\n template: `\n <ng-template #blockTemplate let-list>\n @for (block of list; track blockKey(block)) {\n @switch (block.kind) {\n @case ('heading') {\n <text [class]=\"classFor(block.element)\" accessibilityRole=\"header\"\n ><ng-container *templateSlot=\"inlineTemplate; context: { $implicit: block.children }\"\n /></text>\n }\n @case ('paragraph') {\n <text [class]=\"classFor('p')\"\n ><ng-container *templateSlot=\"inlineTemplate; context: { $implicit: block.children }\"\n /></text>\n }\n @case ('image') {\n <image\n [src]=\"block.src\"\n [alt]=\"block.alt || undefined\"\n resizeMode=\"contain\"\n [class]=\"classFor('img')\"\n [style.--md-img-width]=\"imageWidth(block.src)\"\n [style.aspectRatio]=\"sizes().get(block.src)?.ratio ?? null\"\n [style.height]=\"imageHeight(block)\"\n (load)=\"sizeImage(block.src, $any($event))\"\n (layout)=\"layOutImage(block, $any($event))\"\n />\n }\n @case ('blockquote') {\n <view [class]=\"classFor('blockquote')\">\n <ng-container *templateSlot=\"blockTemplate; context: { $implicit: block.children }\" />\n </view>\n }\n @case ('list') {\n <view [class]=\"classFor(block.element)\">\n @for (item of block.items; track $index) {\n <view [class]=\"classFor('li')\">\n <text [class]=\"classFor('marker')\">{{ item.marker }}</text>\n <view class=\"md-li-body\">\n <ng-container\n *templateSlot=\"blockTemplate; context: { $implicit: item.children }\"\n />\n </view>\n </view>\n }\n </view>\n }\n @case ('code') {\n <scroll-view horizontal [class]=\"classFor('pre')\">\n <text selectable class=\"md-pre-text\">{{ block.text }}</text>\n </scroll-view>\n }\n @case ('hr') {\n <view [class]=\"classFor('hr')\"></view>\n }\n @case ('table') {\n <scroll-view horizontal>\n <view\n [class]=\"classFor('table')\"\n [markdownColumns]=\"block\"\n #columns=\"markdownColumns\"\n >\n <view [class]=\"classFor('tr')\">\n @for (cell of block.header; track $index; let column = $index) {\n <view class=\"md-cell\" [style.minWidth]=\"columns.width(column)\">\n <text\n [class]=\"classFor('th')\"\n (layout)=\"columns.measure(0, column, $any($event))\"\n ><ng-container *templateSlot=\"inlineTemplate; context: { $implicit: cell }\"\n /></text>\n </view>\n }\n </view>\n @for (row of block.rows; track $index; let r = $index) {\n <view [class]=\"classFor('tr')\">\n @for (cell of row; track $index; let column = $index) {\n <view class=\"md-cell md-cell-body\" [style.minWidth]=\"columns.width(column)\">\n <text\n [class]=\"classFor('td')\"\n (layout)=\"columns.measure(r + 1, column, $any($event))\"\n ><ng-container\n *templateSlot=\"inlineTemplate; context: { $implicit: cell }\"\n /></text>\n </view>\n }\n </view>\n }\n </view>\n </scroll-view>\n }\n }\n }\n </ng-template>\n\n <ng-template #inlineTemplate let-runs>\n @for (run of runs; track $index) {\n @switch (run.kind) {\n @case ('text') {\n <ng-container>{{ run.text }}</ng-container>\n }\n @case ('code') {\n <text [class]=\"classFor('code')\">{{ run.text }}</text>\n }\n @case ('link') {\n <text\n [class]=\"classFor('a')\"\n pressable\n [accessibilityHint]=\"run.title ?? undefined\"\n (press)=\"followLink(run)\"\n ><ng-container *templateSlot=\"inlineTemplate; context: { $implicit: run.children }\"\n /></text>\n }\n @default {\n <text [class]=\"classFor(run.kind)\"\n ><ng-container *templateSlot=\"inlineTemplate; context: { $implicit: run.children }\"\n /></text>\n }\n }\n }\n </ng-template>\n\n <ng-container *templateSlot=\"blockTemplate; context: { $implicit: blocks() }\" />\n `,\n styleUrl: './markdown.css',\n host: {\n '[class.md-ios]': 'apple',\n '[class.md-android]': \"platform === 'android'\",\n },\n})\nexport class Markdown {\n private readonly injector = inject(Injector);\n /** Which monospace font code is drawn in, as the platform names it. */\n protected readonly platform = nativePlatform();\n /** Menlo, which iOS and macOS both have. */\n protected readonly apple = isApplePlatform();\n\n /** The Markdown to draw. */\n readonly source = input<string>();\n /** Tokens `marked.lexer` made already, drawn in place of `source`. */\n readonly tokens = input<readonly Token[]>();\n /**\n * Whether `source` is still arriving, a chunk at a time. While it is, only its last block is\n * lexed again, unless a link reference changes, and syntax still open at its end is held back.\n * See the class note.\n */\n readonly streaming = input(false, { transform: booleanAttribute });\n /**\n * Schemes besides `http`, `https`, `mailto` and `tel` whose links are drawn as links and\n * reported through `(linkPress)`, never opened. Replaces `provideMarkdownLinkSchemes` when set.\n * See the class note.\n */\n readonly linkSchemes = input<readonly string[]>();\n /** A class for an element, in place of its default. See the class note. */\n readonly classes = input<MarkdownClasses>({});\n /** A link was pressed. See the class note. */\n readonly linkPress = output<MarkdownLinkPress>();\n\n private readonly stream = new MarkdownStream();\n protected readonly blockKey = blockKey;\n\n /**\n * The blocks each token the stream kept was drawn as. A kept token is the same object from one\n * chunk to the next, so its blocks are not converted or compared again; a source lexed whole\n * makes new tokens, and so new blocks.\n */\n private streamed = new WeakMap<Token, readonly MarkdownBlock[]>();\n /** The schemes `streamed` was converted with; its blocks are stale once they change. */\n private streamedFor: AppLinkSchemes | undefined;\n\n private readonly providedSchemes = inject(MARKDOWN_LINK_SCHEMES);\n\n /** The schemes links are drawn in, the same set while the list reads the same. */\n private readonly appSchemes = computed(\n () => linkSchemeSet(this.linkSchemes() ?? this.providedSchemes),\n { equal: (a, b) => a.size === b.size && [...a].every((scheme) => b.has(scheme)) },\n );\n\n private readonly lexed = computed(() => {\n const tokens = this.tokens();\n if (tokens) return { tokens, streamed: false };\n const streamed = this.streaming();\n return { tokens: this.lex(this.source() ?? '', streamed), streamed };\n });\n\n /** The document's blocks, with each one that did not change kept, so it is not drawn again. */\n protected readonly blocks = linkedSignal({\n source: () => ({ ...this.lexed(), schemes: this.appSchemes() }),\n computation: ({ tokens, streamed, schemes }, previous?: { value: readonly MarkdownBlock[] }) =>\n streamed\n ? this.streamedBlocks(tokens, previous?.value, schemes)\n : shareBlocks(previous?.value, markdownBlocks(tokens, schemes)),\n });\n\n private readonly classOf = computed(() => ({ ...DEFAULT_CLASSES, ...this.classes() }));\n\n /**\n * Each image's own width and its width over its height, once it has loaded, so it is drawn at its\n * own size and shape, as a browser draws it, and no wider than the document. The width reaches\n * the image as `--md-img-width`, which `.md-img` reads, so a class of the app's own still sets\n * the width. An image the document no longer has is forgotten when the document changes.\n */\n protected readonly sizes = linkedSignal<readonly MarkdownBlock[], ReadonlyMap<string, ImageSize>>(\n {\n source: this.blocks,\n computation: (blocks, previous) => {\n const kept = new Map<string, ImageSize>();\n if (!previous) return kept;\n const present = new Set([...imageBlocks(blocks)].map((block) => block.src));\n for (const [src, size] of previous.value) if (present.has(src)) kept.set(src, size);\n return kept;\n },\n },\n );\n\n /**\n * The width each image is laid out at where that is less than its own, narrowed by\n * `max-width`. Yoga takes an image's height from its width before `max-width` narrows it, where\n * CSS takes it after, so a narrowed image is given the height its ratio makes of the width it\n * has. An image no longer in the document is forgotten when the document changes.\n */\n protected readonly narrowed = linkedSignal<\n readonly MarkdownBlock[],\n ReadonlyMap<ImageBlock, number>\n >({\n source: this.blocks,\n computation: (blocks, previous) => {\n const kept = new Map<ImageBlock, number>();\n if (!previous) return kept;\n const present = imageBlocks(blocks);\n for (const [block, width] of previous.value) if (present.has(block)) kept.set(block, width);\n return kept;\n },\n });\n\n private lex(source: string, streaming: boolean): readonly Token[] {\n return streaming ? this.stream.lex(source) : lexer(source);\n }\n\n /** `tokens`' blocks, converting and sharing only those of tokens the stream had not kept. */\n private streamedBlocks(\n tokens: readonly Token[],\n previous: readonly MarkdownBlock[] | undefined,\n schemes: AppLinkSchemes,\n ): readonly MarkdownBlock[] {\n if (this.streamedFor !== schemes) {\n this.streamed = new WeakMap();\n this.streamedFor = schemes;\n }\n const kept: MarkdownBlock[] = [];\n let at = 0;\n for (; at < tokens.length; at++) {\n const blocks = this.streamed.get(tokens[at]!);\n if (!blocks) break;\n kept.push(...blocks);\n }\n const rest = tokens.slice(at);\n const converted = rest.map((token) => markdownBlocks([token], schemes));\n // The blocks drawn after the kept ones, when those are still the ones drawn first.\n const drawn = !kept.length || previous?.[kept.length - 1] === kept.at(-1);\n const was = drawn ? previous?.slice(kept.length) : undefined;\n const shared = shareBlocks(was, converted.flat());\n let from = 0;\n rest.forEach((token, i) => {\n const count = converted[i]!.length;\n this.streamed.set(token, shared.slice(from, (from += count)));\n });\n return [...kept, ...shared];\n }\n\n protected classFor(element: MarkdownElement): string {\n return this.classOf()[element];\n }\n\n protected imageWidth(src: string): string | null {\n const size = this.sizes().get(src);\n return size ? `${size.width}px` : null;\n }\n\n /** The class's height until the image loads, then its ratio's, or a narrowed image's own. */\n protected imageHeight(block: ImageBlock): number | 'auto' | null {\n const size = this.sizes().get(block.src);\n if (!size) return null;\n const width = this.narrowed().get(block);\n return width === undefined ? 'auto' : width / size.ratio;\n }\n\n protected layOutImage(block: ImageBlock, event: Partial<LayoutEvent>): void {\n const width = event.nativeEvent?.layout?.width;\n const size = this.sizes().get(block.src);\n if (width === undefined || !size) return;\n const narrowed = width < size.width ? width : undefined;\n if (this.narrowed().get(block) === narrowed) return;\n this.narrowed.update((all) => {\n const next = new Map(all);\n if (narrowed === undefined) next.delete(block);\n else next.set(block, narrowed);\n return next;\n });\n }\n\n protected sizeImage(src: string, event: Partial<ImageLoadEvent>): void {\n const source = event.nativeEvent?.source;\n if (!source) return;\n const { width, height } = source;\n if (!(width > 0 && height > 0)) return;\n // A url's or a data url's scale is 1, so the load event's pixels are the points a browser's\n // CSS pixels are.\n this.sizes.update((sizes) => new Map(sizes).set(src, { width, ratio: width / height }));\n }\n\n protected followLink(link: MarkdownLink): void {\n let prevented = false;\n this.linkPress.emit({\n href: link.href,\n title: link.title,\n preventDefault: () => {\n prevented = true;\n },\n });\n if (!prevented && opensOnPress(link.href)) this.injector.get(DeepLinks).open(link.href);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"markdown.js","sourceRoot":"","sources":["../src/markdown.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EACL,SAAS,EACT,QAAQ,EACR,cAAc,EACd,gBAAgB,EAChB,QAAQ,EACR,MAAM,EACN,KAAK,EACL,YAAY,EACZ,MAAM,GAEP,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,KAAK,EAAc,MAAM,QAAQ,CAAC;AAE3C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EACL,QAAQ,EACR,aAAa,EACb,cAAc,EACd,YAAY,EACZ,WAAW,GAKZ,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM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ourcesContent":["/**\n * Markdown, drawn as native views and text.\n *\n * Its own entry point because it parses with `marked`, an optional peer dependency an app installs\n * only when it renders Markdown: the barrel never imports it, so an app that does not is not asked\n * for it.\n *\n * ```ts\n * import { Markdown } from '@ng-native/components/markdown';\n * ```\n */\nimport {\n Component,\n Injector,\n InjectionToken,\n booleanAttribute,\n computed,\n inject,\n input,\n linkedSignal,\n output,\n type Provider,\n} from '@angular/core';\nimport { DeepLinks } from '@ng-native/device';\nimport { isApplePlatform, nativePlatform } from '@ng-native/fabric';\nimport { lexer, type Token } from 'marked';\nimport type { ImageLoadEvent, LayoutEvent } from './events.ts';\nimport { Image } from './image.ts';\nimport {\n blockKey,\n linkSchemeSet,\n markdownBlocks,\n opensOnPress,\n shareBlocks,\n type AppLinkSchemes,\n type MarkdownBlock,\n type MarkdownElement,\n type MarkdownInline,\n} from './markdown-blocks.ts';\nimport { MarkdownColumns } from './markdown-columns.ts';\nimport { MarkdownStream } from './markdown-stream.ts';\nimport { ScrollView } from './scroll-view.ts';\nimport { TemplateSlot } from './template-slot.ts';\nimport { Text } from './text.ts';\nimport { View } from './view.ts';\n\nexport type { MarkdownElement } from './markdown-blocks.ts';\n\n/** Classes for the elements a document is drawn with, each one in place of the default. */\nexport type MarkdownClasses = Partial<Readonly<Record<MarkdownElement, string>>>;\n\n/** `(linkPress)`: a link was pressed. */\nexport interface MarkdownLinkPress {\n /** The target as written, after its entities are decoded and its scheme was allowed. */\n readonly href: string;\n readonly title: string | null;\n /** Keep the link from being opened, to handle it in the app instead. */\n preventDefault(): void;\n}\n\n/**\n * The schemes, beyond `http`, `https`, `mailto` and `tel`, that every `<markdown>` draws links in\n * unless its own `linkSchemes` is set. See `provideMarkdownLinkSchemes`.\n */\nexport const MARKDOWN_LINK_SCHEMES = new InjectionToken<readonly string[]>(\n 'MARKDOWN_LINK_SCHEMES',\n { providedIn: 'root', factory: () => [] },\n);\n\n/**\n * Make links in the app's own schemes links in every `<markdown>`, such as `myapp:item/42`:\n * drawn as links and reported through `(linkPress)`, and never opened by default. A\n * `[linkSchemes]` input on one `<markdown>` replaces this list for that one.\n *\n * ```ts\n * providers: [provideMarkdownLinkSchemes('myapp')]\n * ```\n */\nexport function provideMarkdownLinkSchemes(...schemes: readonly string[]): Provider {\n return { provide: MARKDOWN_LINK_SCHEMES, useValue: schemes };\n}\n\nconst ELEMENTS: readonly MarkdownElement[] = [\n ...['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'blockquote', 'ul', 'ol', 'li', 'marker'],\n ...['pre', 'code', 'strong', 'em', 'del', 'a', 'hr', 'img', 'table', 'tr', 'th', 'td'],\n] as MarkdownElement[];\n\nconst DEFAULT_CLASSES = Object.fromEntries(\n ELEMENTS.map((element) => [element, `md-${element}`]),\n) as Readonly<Record<MarkdownElement, string>>;\n\ntype MarkdownLink = Extract<MarkdownInline, { kind: 'link' }>;\n\n/** A loaded image's own width in points, and its width over its height. */\ninterface ImageSize {\n readonly width: number;\n readonly ratio: number;\n}\n\ntype ImageBlock = Extract<MarkdownBlock, { kind: 'image' }>;\n\n/** Every image in `blocks`, however deep in quotes and lists. */\nfunction imageBlocks(\n blocks: readonly MarkdownBlock[],\n into = new Set<ImageBlock>(),\n): Set<ImageBlock> {\n for (const block of blocks) {\n if (block.kind === 'image') into.add(block);\n else if (block.kind === 'blockquote') imageBlocks(block.children, into);\n else if (block.kind === 'list') {\n for (const item of block.items) imageBlocks(item.children, into);\n }\n }\n return into;\n}\n\n/**\n * A Markdown document as `<text>`, `<view>`, `<image>` and `<scroll-view>`: headings, paragraphs,\n * emphasis, inline code, links, quotes, ordered, unordered and task lists, code blocks, rules,\n * tables and images.\n *\n * `source` is parsed with `marked.lexer`; `tokens` takes tokens lexed already, and wins when both\n * are set. A paragraph is one `<text>` with a nested `<text>` for each emphasis, code span and\n * link, so it wraps as one run; an image is lifted out to a block of its own.\n *\n * Nothing in the document is interpreted. Raw HTML is drawn as the text it is written as, a link\n * is followed only to `http`, `https`, `mailto`, `tel` or a relative target, and an image is\n * loaded only over `http` or `https`; anything else is drawn as its text.\n *\n * Each element carries a default class, `md-h1`, `md-p`, `md-a` and so on, styled in light and\n * dark. `classes` replaces one by its element's name, so a global stylesheet or Tailwind styles it\n * instead: `{ h1: 'text-3xl font-bold' }`. Put the default back beside your own to keep both.\n *\n * For a source that grows as it streams in, an answer arriving a few words at a time, set\n * `streaming` until it is complete. The blocks before the last one are then kept as they are and\n * only the last is lexed and converted again, unless a chunk defines or changes a link reference,\n * which can change a block already kept, and the whole source is lexed again. Syntax still open at its end, a code span, an emphasis, a link,\n * an image or a table row, is held back until it closes. Of a code fence only an unfinished\n * opening line is held back, and its code then streams as it arrives. Clearing `streaming` draws\n * the whole source as written, and `tokens` are always drawn as given. A block that did not\n * change keeps its views, streaming or not.\n *\n * A pressed link is `(linkPress)`. An absolute target is then opened with `DeepLinks.open` unless\n * a handler calls `preventDefault()`; a relative one is only reported, for the app to route.\n *\n * A link in the app's own scheme, `myapp:item/42`, is drawn as plain text unless the scheme is\n * listed in `linkSchemes`, or app-wide with `provideMarkdownLinkSchemes`. A listed scheme is drawn\n * as a link and reported through `(linkPress)`, and is never opened: the app routes it. The input\n * replaces the provider's list when it is set, even to an empty one. Schemes are matched without\n * regard to case, and the list is read as a value: give a new array to change it.\n */\n@Component({\n selector: 'markdown',\n imports: [Image, MarkdownColumns, ScrollView, TemplateSlot, Text, View],\n template: `\n <ng-template #blockTemplate let-list>\n @for (block of list; track blockKey(block)) {\n @switch (block.kind) {\n @case ('heading') {\n <text [class]=\"classFor(block.element)\" accessibilityRole=\"header\"\n ><ng-container *templateSlot=\"inlineTemplate; context: { $implicit: block.children }\"\n /></text>\n }\n @case ('paragraph') {\n <text [class]=\"classFor('p')\"\n ><ng-container *templateSlot=\"inlineTemplate; context: { $implicit: block.children }\"\n /></text>\n }\n @case ('image') {\n <image\n [src]=\"block.src\"\n [alt]=\"block.alt || undefined\"\n resizeMode=\"contain\"\n [class]=\"classFor('img')\"\n [style.--md-img-width]=\"imageWidth(block.src)\"\n [style.aspectRatio]=\"sizes().get(block.src)?.ratio ?? null\"\n [style.height]=\"imageHeight(block)\"\n (load)=\"sizeImage(block.src, $any($event))\"\n (layout)=\"layOutImage(block, $any($event))\"\n />\n }\n @case ('blockquote') {\n <view [class]=\"classFor('blockquote')\">\n <ng-container *templateSlot=\"blockTemplate; context: { $implicit: block.children }\" />\n </view>\n }\n @case ('list') {\n <view [class]=\"classFor(block.element)\">\n @for (item of block.items; track $index) {\n <view [class]=\"classFor('li')\">\n <text [class]=\"classFor('marker')\">{{ item.marker }}</text>\n <view class=\"md-li-body\">\n <ng-container\n *templateSlot=\"blockTemplate; context: { $implicit: item.children }\"\n />\n </view>\n </view>\n }\n </view>\n }\n @case ('code') {\n <scroll-view horizontal [class]=\"classFor('pre')\">\n <text selectable class=\"md-pre-text\">{{ block.text }}</text>\n </scroll-view>\n }\n @case ('hr') {\n <view [class]=\"classFor('hr')\"></view>\n }\n @case ('table') {\n <scroll-view horizontal>\n <view\n [class]=\"classFor('table')\"\n [markdownColumns]=\"block\"\n #columns=\"markdownColumns\"\n >\n <view [class]=\"classFor('tr')\">\n @for (cell of block.header; track $index; let column = $index) {\n <view class=\"md-cell\" [style.minWidth]=\"columns.width(column)\">\n <text\n [class]=\"classFor('th')\"\n (layout)=\"columns.measure(0, column, $any($event))\"\n ><ng-container *templateSlot=\"inlineTemplate; context: { $implicit: cell }\"\n /></text>\n </view>\n }\n </view>\n @for (row of block.rows; track $index; let r = $index) {\n <view [class]=\"classFor('tr')\">\n @for (cell of row; track $index; let column = $index) {\n <view class=\"md-cell md-cell-body\" [style.minWidth]=\"columns.width(column)\">\n <text\n [class]=\"classFor('td')\"\n (layout)=\"columns.measure(r + 1, column, $any($event))\"\n ><ng-container\n *templateSlot=\"inlineTemplate; context: { $implicit: cell }\"\n /></text>\n </view>\n }\n </view>\n }\n </view>\n </scroll-view>\n }\n }\n }\n </ng-template>\n\n <ng-template #inlineTemplate let-runs>\n @for (run of runs; track $index) {\n @switch (run.kind) {\n @case ('text') {\n <ng-container>{{ run.text }}</ng-container>\n }\n @case ('code') {\n <text [class]=\"classFor('code')\">{{ run.text }}</text>\n }\n @case ('link') {\n <text\n [class]=\"classFor('a')\"\n pressable\n [accessibilityHint]=\"run.title ?? undefined\"\n (press)=\"followLink(run)\"\n ><ng-container *templateSlot=\"inlineTemplate; context: { $implicit: run.children }\"\n /></text>\n }\n @default {\n <text [class]=\"classFor(run.kind)\"\n ><ng-container *templateSlot=\"inlineTemplate; context: { $implicit: run.children }\"\n /></text>\n }\n }\n }\n </ng-template>\n\n <ng-container *templateSlot=\"blockTemplate; context: { $implicit: blocks() }\" />\n `,\n styleUrl: './markdown.css',\n host: {\n '[class.md-ios]': 'apple',\n '[class.md-android]': \"platform === 'android'\",\n },\n})\nexport class Markdown {\n private readonly injector = inject(Injector);\n /** Which monospace font code is drawn in, as the platform names it. */\n protected readonly platform = nativePlatform();\n /** Menlo, which iOS and macOS both have. */\n protected readonly apple = isApplePlatform();\n\n /** The Markdown to draw. */\n readonly source = input<string>();\n /** Tokens `marked.lexer` made already, drawn in place of `source`. */\n readonly tokens = input<readonly Token[]>();\n /**\n * Whether `source` is still arriving, a chunk at a time. While it is, only its last block is\n * lexed again, unless a link reference changes, and syntax still open at its end is held back.\n * See the class note.\n */\n readonly streaming = input(false, { transform: booleanAttribute });\n /**\n * Schemes besides `http`, `https`, `mailto` and `tel` whose links are drawn as links and\n * reported through `(linkPress)`, never opened. Replaces `provideMarkdownLinkSchemes` when set.\n * See the class note.\n */\n readonly linkSchemes = input<readonly string[]>();\n /** A class for an element, in place of its default. See the class note. */\n readonly classes = input<MarkdownClasses>({});\n /** A link was pressed. See the class note. */\n readonly linkPress = output<MarkdownLinkPress>();\n\n private readonly stream = new MarkdownStream();\n protected readonly blockKey = blockKey;\n\n /**\n * The blocks each token the stream kept was drawn as. A kept token is the same object from one\n * chunk to the next, so its blocks are not converted or compared again; a source lexed whole\n * makes new tokens, and so new blocks.\n */\n private streamed = new WeakMap<Token, readonly MarkdownBlock[]>();\n /** The schemes `streamed` was converted with; its blocks are stale once they change. */\n private streamedFor: AppLinkSchemes | undefined;\n\n private readonly providedSchemes = inject(MARKDOWN_LINK_SCHEMES);\n\n /** The schemes links are drawn in, the same set while the list reads the same. */\n private readonly appSchemes = computed(\n () => linkSchemeSet(this.linkSchemes() ?? this.providedSchemes),\n { equal: (a, b) => a.size === b.size && [...a].every((scheme) => b.has(scheme)) },\n );\n\n private readonly lexed = computed(() => {\n const tokens = this.tokens();\n if (tokens) return { tokens, streamed: false };\n const streamed = this.streaming();\n return { tokens: this.lex(this.source() ?? '', streamed), streamed };\n });\n\n /** The document's blocks, with each one that did not change kept, so it is not drawn again. */\n protected readonly blocks = linkedSignal({\n source: () => ({ ...this.lexed(), schemes: this.appSchemes() }),\n computation: ({ tokens, streamed, schemes }, previous?: { value: readonly MarkdownBlock[] }) =>\n streamed\n ? this.streamedBlocks(tokens, previous?.value, schemes)\n : shareBlocks(previous?.value, markdownBlocks(tokens, schemes)),\n });\n\n private readonly classOf = computed(() => ({ ...DEFAULT_CLASSES, ...this.classes() }));\n\n /**\n * Each image's own width and its width over its height, once it has loaded, so it is drawn at its\n * own size and shape, as a browser draws it, and no wider than the document. The width reaches\n * the image as `--md-img-width`, which `.md-img` reads, so a class of the app's own still sets\n * the width. An image the document no longer has is forgotten when the document changes.\n */\n protected readonly sizes = linkedSignal<readonly MarkdownBlock[], ReadonlyMap<string, ImageSize>>(\n {\n source: this.blocks,\n computation: (blocks, previous) => {\n const kept = new Map<string, ImageSize>();\n if (!previous) return kept;\n const present = new Set([...imageBlocks(blocks)].map((block) => block.src));\n for (const [src, size] of previous.value) if (present.has(src)) kept.set(src, size);\n return kept;\n },\n },\n );\n\n /**\n * The width each image is laid out at where that is less than its own, narrowed by\n * `max-width`. Yoga takes an image's height from its width before `max-width` narrows it, where\n * CSS takes it after, so a narrowed image is given the height its ratio makes of the width it\n * has. An image no longer in the document is forgotten when the document changes.\n */\n protected readonly narrowed = linkedSignal<\n readonly MarkdownBlock[],\n ReadonlyMap<ImageBlock, number>\n >({\n source: this.blocks,\n computation: (blocks, previous) => {\n const kept = new Map<ImageBlock, number>();\n if (!previous) return kept;\n const present = imageBlocks(blocks);\n for (const [block, width] of previous.value) if (present.has(block)) kept.set(block, width);\n return kept;\n },\n });\n\n private lex(source: string, streaming: boolean): readonly Token[] {\n return streaming ? this.stream.lex(source) : lexer(source);\n }\n\n /** `tokens`' blocks, converting and sharing only those of tokens the stream had not kept. */\n private streamedBlocks(\n tokens: readonly Token[],\n previous: readonly MarkdownBlock[] | undefined,\n schemes: AppLinkSchemes,\n ): readonly MarkdownBlock[] {\n if (this.streamedFor !== schemes) {\n this.streamed = new WeakMap();\n this.streamedFor = schemes;\n }\n const kept: MarkdownBlock[] = [];\n let at = 0;\n for (; at < tokens.length; at++) {\n const blocks = this.streamed.get(tokens[at]!);\n if (!blocks) break;\n kept.push(...blocks);\n }\n const rest = tokens.slice(at);\n const converted = rest.map((token) => markdownBlocks([token], schemes));\n // The blocks drawn after the kept ones, when those are still the ones drawn first.\n const drawn = !kept.length || previous?.[kept.length - 1] === kept.at(-1);\n const was = drawn ? previous?.slice(kept.length) : undefined;\n const shared = shareBlocks(was, converted.flat());\n let from = 0;\n rest.forEach((token, i) => {\n const count = converted[i]!.length;\n this.streamed.set(token, shared.slice(from, (from += count)));\n });\n return [...kept, ...shared];\n }\n\n protected classFor(element: MarkdownElement): string {\n return this.classOf()[element];\n }\n\n protected imageWidth(src: string): string | null {\n const size = this.sizes().get(src);\n return size ? `${size.width}px` : null;\n }\n\n /** The class's height until the image loads, then its ratio's, or a narrowed image's own. */\n protected imageHeight(block: ImageBlock): number | 'auto' | null {\n const size = this.sizes().get(block.src);\n if (!size) return null;\n const width = this.narrowed().get(block);\n return width === undefined ? 'auto' : width / size.ratio;\n }\n\n protected layOutImage(block: ImageBlock, event: Partial<LayoutEvent>): void {\n const width = event.nativeEvent?.layout?.width;\n const size = this.sizes().get(block.src);\n if (width === undefined || !size) return;\n const narrowed = width < size.width ? width : undefined;\n if (this.narrowed().get(block) === narrowed) return;\n this.narrowed.update((all) => {\n const next = new Map(all);\n if (narrowed === undefined) next.delete(block);\n else next.set(block, narrowed);\n return next;\n });\n }\n\n protected sizeImage(src: string, event: Partial<ImageLoadEvent>): void {\n const source = event.nativeEvent?.source;\n if (!source) return;\n const { width, height } = source;\n if (!(width > 0 && height > 0)) return;\n // A url's or a data url's scale is 1, so the load event's pixels are the points a browser's\n // CSS pixels are.\n this.sizes.update((sizes) => new Map(sizes).set(src, { width, ratio: width / height }));\n }\n\n protected followLink(link: MarkdownLink): void {\n let prevented = false;\n this.linkPress.emit({\n href: link.href,\n title: link.title,\n preventDefault: () => {\n prevented = true;\n },\n });\n if (!prevented && opensOnPress(link.href)) this.injector.get(DeepLinks).open(link.href);\n }\n}\n"]}
|