@ng-native/components 0.19.2 → 0.20.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.
@@ -146,9 +146,12 @@ export class KeyboardAvoidingView extends ViewBase {
146
146
  const layout = event.nativeEvent?.layout;
147
147
  if (!layout)
148
148
  return;
149
+ // Only a layout of the view as nothing adjusted it counts as the natural height: not one it
150
+ // shrank to, nor one its padding grew. The keyboard can be up at the first one already, before
151
+ // the view had a frame to shrink.
152
+ const adjusted = this.avoidance() !== undefined;
149
153
  this.frame.set({ ...layout, y: this.windowTop(layout.y) });
150
- // Only a layout that the keyboard did not cause counts as the natural height.
151
- if (this.overlap() === 0)
154
+ if (!adjusted)
152
155
  this.initialHeight = layout.height;
153
156
  }
154
157
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"keyboard-avoiding-view.js","sourceRoot":"","sources":["../src/keyboard-avoiding-view.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,QAAQ,EACR,MAAM,EACN,MAAM,EACN,KAAK,EACL,MAAM,EACN,gBAAgB,GACjB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAqB,MAAM,mBAAmB,CAAC;AAGjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;;AAI3C;;;GAGG;AACH,MAAM,cAAc,GAAwB,IAAI,GAAG,CAAC;IAClD,QAAQ;IACR,eAAe;IACf,QAAQ;IACR,SAAS;IACT,QAAQ;IACR,UAAU;CACX,CAAC,CAAC;AAEH,uGAAuG;AACvG,SAAS,cAAc,CAAC,MAA0B;IAChD,OAAO,MAAM,KAAK,SAAS,IAAI,cAAc,CAAC,GAAG,CAAC,MAA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;IAED;;;OAGG;IACK,SAAS,CAAC,QAAgB;QAChC,IAAI,GAAG,GAAG,QAAQ,CAAC;QACnB,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QAC3D,OAAO,GAAG,CAAC;IACb,CAAC;uGAxGU,oBAAoB;2FAApB,oBAAoB,s9BAjBrB;;;;;;;;;;;GAWT,4DAZS,gBAAgB,0HAAE,IAAI;;2FAkBrB,oBAAoB;kBApBhC,SAAS;mBAAC;oBACT,QAAQ,EAAE,wBAAwB;oBAClC,OAAO,EAAE,CAAC,gBAAgB,EAAE,IAAI,CAAC;oBACjC,QAAQ,EAAE;;;;;;;;;;;GAWT;oBACD,IAAI,EAAE;wBACJ,iBAAiB,EAAE,aAAa;wBAChC,UAAU,EAAE,kBAAkB;qBAC/B;iBACF","sourcesContent":["import {\n Component,\n computed,\n effect,\n inject,\n input,\n signal,\n booleanAttribute,\n} from '@angular/core';\nimport { Keyboard, LayoutAnimation, type LayoutEasing } from '@ng-native/device';\nimport type { NativeSyntheticEvent } from '@ng-native/fabric';\nimport type { Rect } from './events.ts';\nimport { ContentContainer } from './content-container.ts';\nimport { View } from './view.ts';\nimport { ViewBase } from './view-base.ts';\nimport { numberOr } from './transforms.ts';\n\nexport type KeyboardAvoidingBehavior = 'padding' | 'height' | 'position';\n\n/**\n * The names `LayoutEasing` knows. `'keyboard'` is among them: iOS reports its keyboard's own\n * curve by that name, and RN's KeyboardAvoidingView animates on it.\n */\nconst LAYOUT_EASINGS: ReadonlySet<string> = new Set([\n 'linear',\n 'easeInEaseOut',\n 'easeIn',\n 'easeOut',\n 'spring',\n 'keyboard',\n]);\n\n/** A keyboard event's `easing`, narrowed to what `LayoutAnimation` accepts, or left to its default. */\nfunction layoutEasingOf(easing: string | undefined): LayoutEasing | undefined {\n return easing !== undefined && LAYOUT_EASINGS.has(easing) ? (easing as LayoutEasing) : undefined;\n}\n\n/**\n * Moves its content clear of the keyboard.\n *\n * RN's KeyboardAvoidingView is a JS composite: there is no native component, only a view whose\n * padding, height or position tracks the keyboard. Off a device the `Keyboard` service reports\n * nothing, so this renders as a plain view and does nothing, which is also the right behaviour on\n * a platform with no soft keyboard.\n *\n * The overlap is the view's own frame against the keyboard's top edge, so a view that does not\n * reach the bottom of the screen moves only as far as it must. Unlike RN, the frame's top is\n * measured in the window, and the keyboard's `screenY` brought into it: `(layout)` reports the top\n * in the parent's coordinates, and on a screen under a navigation bar those start a bar's height\n * down. RN leaves that to `keyboardVerticalOffset`, and a view that was not told came up short by\n * exactly that much, its bottom edge still behind the keyboard. On Android, when React Native's\n * edge-to-edge flag is off (Expo Go leaves it off), the window starts below the status bar while\n * `screenY` counts from the top of the screen, so the keyboard's top is taken `Keyboard.windowTop`\n * higher in the window, or the view comes up short by the status bar; when the flag is on,\n * `Keyboard.windowTop` is zero. The overlap never exceeds the\n * view's own height either: padding a view by more than it has pushes its content out of it.\n * When the keyboard source reports no `screenY`, the keyboard's height stands in.\n *\n * The adjustment itself animates with the keyboard's own motion, the way RN's own\n * KeyboardAvoidingView does: a keyboard event's `duration` and `easing` configure the next\n * layout animation before the style change that moves this view, so the two run together rather\n * than the padding, height or position jumping to its resting place in one step. Android animates\n * no layout unless an app turns that on, and reports no duration, so there the view jumps; with\n * `@ng-native/expo`'s `provideNativeKeyboard()` it follows the keyboard frame by frame instead.\n */\n@Component({\n selector: 'keyboard-avoiding-view',\n imports: [ContentContainer, View],\n template: `\n @if (behavior() === 'position') {\n <view\n [contentContainerOf]=\"node\"\n [contentContainerClass]=\"contentContainerClass()\"\n [style]=\"positioned()\"\n ><ng-content\n /></view>\n } @else {\n <ng-content />\n }\n `,\n host: {\n '[styleOverride]': 'avoidance()',\n '(layout)': 'onLayout($event)',\n },\n})\nexport class KeyboardAvoidingView extends ViewBase {\n /**\n * How to make room: pad the bottom, shrink the height, or shift the content up. RN leaves this\n * unset and does nothing; `padding` is the default here because that is what a form wants.\n */\n readonly behavior = input<KeyboardAvoidingBehavior>('padding');\n /** Styles for the inner view that `position` moves. */\n readonly contentContainerStyle = input<Record<string, unknown>>();\n /**\n * Classes for the inner view that `position` moves, matched as if it were written in the\n * template this view is. See `ContentContainer`.\n */\n readonly contentContainerClass = input<string>();\n /** Set to false to stop avoiding without removing the view. */\n readonly enabled = input(true, { transform: booleanAttribute });\n /**\n * Extra room to leave above the keyboard, in points. RN's name, and in RN the place to put a\n * header's height; here the view is measured in the window, so a navigation bar needs none.\n */\n readonly keyboardVerticalOffset = input(0, { transform: numberOr(0) });\n\n private readonly keyboardService = inject(Keyboard);\n /** Where the keyboard is, at every frame of its motion where the platform says. */\n private readonly keyboard = this.keyboardService.position;\n private readonly layoutAnimation = inject(LayoutAnimation);\n private readonly frame = signal<Rect | null>(null);\n /** The height before any adjustment, which `height` mode shrinks from. */\n private initialHeight: number | null = null;\n\n /** How far the keyboard intrudes into this view, in points. */\n protected readonly overlap = computed(() => {\n if (!this.enabled()) return 0;\n const { height, screenY } = this.keyboard();\n if (height === 0) return 0;\n const frame = this.frame();\n const offset = this.keyboardVerticalOffset();\n if (!frame) return Math.max(0, height - offset);\n // In `height` mode the frame is the one this view already shrank, so measure the height it\n // had before, as RN adds its current adjustment back; otherwise the room it made reads as no\n // overlap and the height springs back under the keyboard.\n const extent =\n this.behavior() === 'height' ? (this.initialHeight ?? frame.height) : frame.height;\n const top = screenY === undefined ? undefined : screenY - this.keyboardService.windowTop;\n const overlap = top === undefined ? height - offset : frame.y + extent - (top - offset);\n return Math.min(extent, Math.max(0, overlap));\n });\n\n /**\n * The adjustment, or nothing to adjust. Bound as the engine's style override rather than as\n * host style, because Angular ranks a host style binding under the template's: a caller's\n * `[style]=\"{flex: 1}\"` would otherwise keep its flex in height mode and the view would not\n * shrink at all. RN composes the adjustment after the caller's style, so it wins there too.\n */\n protected readonly avoidance = computed(() => {\n const overlap = this.overlap();\n const behavior = this.behavior();\n if (overlap === 0 || behavior === 'position') return undefined;\n if (behavior === 'height') {\n const base = this.initialHeight ?? this.frame()?.height;\n return base === undefined ? undefined : { height: base - overlap, flex: 0 };\n }\n return { paddingBottom: overlap };\n });\n\n protected readonly positioned = computed(() => ({\n ...this.contentContainerStyle(),\n bottom: this.overlap(),\n }));\n\n constructor() {\n super();\n // A duration of zero is Android's own keyboard event, which says nothing of the motion; there\n // is nothing to configure alongside it. Nor where the view follows the motion frame by frame.\n // `appear`/`leave` are turned off because this is an update to a view already on screen, not\n // one appearing or leaving - RN's own bare `LayoutAnimation.configureNext({duration, update})`\n // animates nothing else either.\n effect(() => {\n const { duration, easing } = this.keyboardService.metrics();\n if (!this.enabled() || !duration || this.keyboardService.followsMotion) return;\n void this.layoutAnimation.animate(() => {}, {\n duration,\n easing: layoutEasingOf(easing),\n appear: 'none',\n leave: 'none',\n });\n });\n }\n\n protected onLayout(event: NativeSyntheticEvent<{ layout?: Rect }>): void {\n const layout = event.nativeEvent?.layout;\n if (!layout) return;\n this.frame.set({ ...layout, y: this.windowTop(layout.y) });\n // Only a layout that the keyboard did not cause counts as the natural height.\n if (this.overlap() === 0) this.initialHeight = layout.height;\n }\n\n /**\n * Where this view's top edge is in the window, or `fallback` where the platform cannot say.\n * Synchronous on the new architecture, so it answers for the layout being reported.\n */\n private windowTop(fallback: number): number {\n let top = fallback;\n this.engine.measure(this.node, (frame) => (top = frame.y));\n return top;\n }\n}\n"]}
1
+ {"version":3,"file":"keyboard-avoiding-view.js","sourceRoot":"","sources":["../src/keyboard-avoiding-view.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,QAAQ,EACR,MAAM,EACN,MAAM,EACN,KAAK,EACL,MAAM,EACN,gBAAgB,GACjB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAqB,MAAM,mBAAmB,CAAC;AAGjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC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,CAAC;IAES,QAAQ,CAAC,KAA8C;QAC/D,MAAM,MAAM,GAAG,KAAK,CAAC,WAAW,EAAE,MAAM,CAAC;QACzC,IAAI,CAAC,MAAM;YAAE,OAAO;QACpB,4FAA4F;QAC5F,+FAA+F;QAC/F,kCAAkC;QAClC,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,EAAE,KAAK,SAAS,CAAC;QAChD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,GAAG,MAAM,EAAE,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QAC3D,IAAI,CAAC,QAAQ;YAAE,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC;IACpD,CAAC;IAED;;;OAGG;IACK,SAAS,CAAC,QAAgB;QAChC,IAAI,GAAG,GAAG,QAAQ,CAAC;QACnB,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QAC3D,OAAO,GAAG,CAAC;IACb,CAAC;uGA3GU,oBAAoB;2FAApB,oBAAoB,s9BAjBrB;;;;;;;;;;;GAWT,4DAZS,gBAAgB,0HAAE,IAAI;;2FAkBrB,oBAAoB;kBApBhC,SAAS;mBAAC;oBACT,QAAQ,EAAE,wBAAwB;oBAClC,OAAO,EAAE,CAAC,gBAAgB,EAAE,IAAI,CAAC;oBACjC,QAAQ,EAAE;;;;;;;;;;;GAWT;oBACD,IAAI,EAAE;wBACJ,iBAAiB,EAAE,aAAa;wBAChC,UAAU,EAAE,kBAAkB;qBAC/B;iBACF","sourcesContent":["import {\n Component,\n computed,\n effect,\n inject,\n input,\n signal,\n booleanAttribute,\n} from '@angular/core';\nimport { Keyboard, LayoutAnimation, type LayoutEasing } from '@ng-native/device';\nimport type { NativeSyntheticEvent } from '@ng-native/fabric';\nimport type { Rect } from './events.ts';\nimport { ContentContainer } from './content-container.ts';\nimport { View } from './view.ts';\nimport { ViewBase } from './view-base.ts';\nimport { numberOr } from './transforms.ts';\n\nexport type KeyboardAvoidingBehavior = 'padding' | 'height' | 'position';\n\n/**\n * The names `LayoutEasing` knows. `'keyboard'` is among them: iOS reports its keyboard's own\n * curve by that name, and RN's KeyboardAvoidingView animates on it.\n */\nconst LAYOUT_EASINGS: ReadonlySet<string> = new Set([\n 'linear',\n 'easeInEaseOut',\n 'easeIn',\n 'easeOut',\n 'spring',\n 'keyboard',\n]);\n\n/** A keyboard event's `easing`, narrowed to what `LayoutAnimation` accepts, or left to its default. */\nfunction layoutEasingOf(easing: string | undefined): LayoutEasing | undefined {\n return easing !== undefined && LAYOUT_EASINGS.has(easing) ? (easing as LayoutEasing) : undefined;\n}\n\n/**\n * Moves its content clear of the keyboard.\n *\n * RN's KeyboardAvoidingView is a JS composite: there is no native component, only a view whose\n * padding, height or position tracks the keyboard. Off a device the `Keyboard` service reports\n * nothing, so this renders as a plain view and does nothing, which is also the right behaviour on\n * a platform with no soft keyboard.\n *\n * The overlap is the view's own frame against the keyboard's top edge, so a view that does not\n * reach the bottom of the screen moves only as far as it must. Unlike RN, the frame's top is\n * measured in the window, and the keyboard's `screenY` brought into it: `(layout)` reports the top\n * in the parent's coordinates, and on a screen under a navigation bar those start a bar's height\n * down. RN leaves that to `keyboardVerticalOffset`, and a view that was not told came up short by\n * exactly that much, its bottom edge still behind the keyboard. On Android, when React Native's\n * edge-to-edge flag is off (Expo Go leaves it off), the window starts below the status bar while\n * `screenY` counts from the top of the screen, so the keyboard's top is taken `Keyboard.windowTop`\n * higher in the window, or the view comes up short by the status bar; when the flag is on,\n * `Keyboard.windowTop` is zero. The overlap never exceeds the\n * view's own height either: padding a view by more than it has pushes its content out of it.\n * When the keyboard source reports no `screenY`, the keyboard's height stands in.\n *\n * The adjustment itself animates with the keyboard's own motion, the way RN's own\n * KeyboardAvoidingView does: a keyboard event's `duration` and `easing` configure the next\n * layout animation before the style change that moves this view, so the two run together rather\n * than the padding, height or position jumping to its resting place in one step. Android animates\n * no layout unless an app turns that on, and reports no duration, so there the view jumps; with\n * `@ng-native/expo`'s `provideNativeKeyboard()` it follows the keyboard frame by frame instead.\n */\n@Component({\n selector: 'keyboard-avoiding-view',\n imports: [ContentContainer, View],\n template: `\n @if (behavior() === 'position') {\n <view\n [contentContainerOf]=\"node\"\n [contentContainerClass]=\"contentContainerClass()\"\n [style]=\"positioned()\"\n ><ng-content\n /></view>\n } @else {\n <ng-content />\n }\n `,\n host: {\n '[styleOverride]': 'avoidance()',\n '(layout)': 'onLayout($event)',\n },\n})\nexport class KeyboardAvoidingView extends ViewBase {\n /**\n * How to make room: pad the bottom, shrink the height, or shift the content up. RN leaves this\n * unset and does nothing; `padding` is the default here because that is what a form wants.\n */\n readonly behavior = input<KeyboardAvoidingBehavior>('padding');\n /** Styles for the inner view that `position` moves. */\n readonly contentContainerStyle = input<Record<string, unknown>>();\n /**\n * Classes for the inner view that `position` moves, matched as if it were written in the\n * template this view is. See `ContentContainer`.\n */\n readonly contentContainerClass = input<string>();\n /** Set to false to stop avoiding without removing the view. */\n readonly enabled = input(true, { transform: booleanAttribute });\n /**\n * Extra room to leave above the keyboard, in points. RN's name, and in RN the place to put a\n * header's height; here the view is measured in the window, so a navigation bar needs none.\n */\n readonly keyboardVerticalOffset = input(0, { transform: numberOr(0) });\n\n private readonly keyboardService = inject(Keyboard);\n /** Where the keyboard is, at every frame of its motion where the platform says. */\n private readonly keyboard = this.keyboardService.position;\n private readonly layoutAnimation = inject(LayoutAnimation);\n private readonly frame = signal<Rect | null>(null);\n /** The height before any adjustment, which `height` mode shrinks from. */\n private initialHeight: number | null = null;\n\n /** How far the keyboard intrudes into this view, in points. */\n protected readonly overlap = computed(() => {\n if (!this.enabled()) return 0;\n const { height, screenY } = this.keyboard();\n if (height === 0) return 0;\n const frame = this.frame();\n const offset = this.keyboardVerticalOffset();\n if (!frame) return Math.max(0, height - offset);\n // In `height` mode the frame is the one this view already shrank, so measure the height it\n // had before, as RN adds its current adjustment back; otherwise the room it made reads as no\n // overlap and the height springs back under the keyboard.\n const extent =\n this.behavior() === 'height' ? (this.initialHeight ?? frame.height) : frame.height;\n const top = screenY === undefined ? undefined : screenY - this.keyboardService.windowTop;\n const overlap = top === undefined ? height - offset : frame.y + extent - (top - offset);\n return Math.min(extent, Math.max(0, overlap));\n });\n\n /**\n * The adjustment, or nothing to adjust. Bound as the engine's style override rather than as\n * host style, because Angular ranks a host style binding under the template's: a caller's\n * `[style]=\"{flex: 1}\"` would otherwise keep its flex in height mode and the view would not\n * shrink at all. RN composes the adjustment after the caller's style, so it wins there too.\n */\n protected readonly avoidance = computed(() => {\n const overlap = this.overlap();\n const behavior = this.behavior();\n if (overlap === 0 || behavior === 'position') return undefined;\n if (behavior === 'height') {\n const base = this.initialHeight ?? this.frame()?.height;\n return base === undefined ? undefined : { height: base - overlap, flex: 0 };\n }\n return { paddingBottom: overlap };\n });\n\n protected readonly positioned = computed(() => ({\n ...this.contentContainerStyle(),\n bottom: this.overlap(),\n }));\n\n constructor() {\n super();\n // A duration of zero is Android's own keyboard event, which says nothing of the motion; there\n // is nothing to configure alongside it. Nor where the view follows the motion frame by frame.\n // `appear`/`leave` are turned off because this is an update to a view already on screen, not\n // one appearing or leaving - RN's own bare `LayoutAnimation.configureNext({duration, update})`\n // animates nothing else either.\n effect(() => {\n const { duration, easing } = this.keyboardService.metrics();\n if (!this.enabled() || !duration || this.keyboardService.followsMotion) return;\n void this.layoutAnimation.animate(() => {}, {\n duration,\n easing: layoutEasingOf(easing),\n appear: 'none',\n leave: 'none',\n });\n });\n }\n\n protected onLayout(event: NativeSyntheticEvent<{ layout?: Rect }>): void {\n const layout = event.nativeEvent?.layout;\n if (!layout) return;\n // Only a layout of the view as nothing adjusted it counts as the natural height: not one it\n // shrank to, nor one its padding grew. The keyboard can be up at the first one already, before\n // the view had a frame to shrink.\n const adjusted = this.avoidance() !== undefined;\n this.frame.set({ ...layout, y: this.windowTop(layout.y) });\n if (!adjusted) this.initialHeight = layout.height;\n }\n\n /**\n * Where this view's top edge is in the window, or `fallback` where the platform cannot say.\n * Synchronous on the new architecture, so it answers for the layout being reported.\n */\n private windowTop(fallback: number): number {\n let top = fallback;\n this.engine.measure(this.node, (frame) => (top = frame.y));\n return top;\n }\n}\n"]}
@@ -64,14 +64,27 @@ export type MarkdownBlock = {
64
64
  export declare function decodeEntities(text: string): string;
65
65
  /** The scheme `url` would be opened with, lowercased, or null for a relative one. */
66
66
  export declare function schemeOf(url: string): string | null;
67
+ /** The schemes an app lists for `<markdown>` to draw links in, lowercased. See {@link linkSchemeSet}. */
68
+ export type AppLinkSchemes = ReadonlySet<string>;
69
+ /** No app scheme: what a document is drawn with when the app lists none. */
70
+ export declare const NO_APP_SCHEMES: AppLinkSchemes;
67
71
  /**
68
- * A link's target if it may be followed: `http`, `https`, `mailto`, `tel`, or relative, which is
69
- * the app's to resolve. Anything else, `javascript:`, `data:`, `vbscript:` and `file:` among
70
- * them, is null, and the link is drawn as its text. The scheme is read after the trim, so
71
- * whitespace the trim strips cannot hide one.
72
+ * The set of schemes an app lists, as {@link linkTarget} reads them. Each is trimmed, lowercased
73
+ * and stripped of one trailing colon, so `'MyApp:'` and `'myapp'` are the same; an entry that
74
+ * cannot be a scheme is dropped.
75
+ */
76
+ export declare function linkSchemeSet(schemes: readonly string[]): AppLinkSchemes;
77
+ /**
78
+ * A link's target if it may be drawn as a link: `http`, `https`, `mailto`, `tel`, a scheme the app
79
+ * listed in `appSchemes`, or relative, which is the app's to resolve. Anything else,
80
+ * `javascript:`, `data:`, `vbscript:` and `file:` among them, is null, and the link is drawn as
81
+ * its text. The scheme is read after the trim, so whitespace the trim strips cannot hide one.
82
+ */
83
+ export declare function linkTarget(href: string, appSchemes?: AppLinkSchemes): string | null;
84
+ /**
85
+ * Whether `href` is absolute in one of the built-in schemes a link is followed to, and so is
86
+ * opened on press. A scheme the app listed is drawn as a link but never opens here.
72
87
  */
73
- export declare function linkTarget(href: string): string | null;
74
- /** Whether `href` is absolute in a scheme a link may be followed to, and so is opened on press. */
75
88
  export declare function opensOnPress(href: string): boolean;
76
89
  /**
77
90
  * An image's address if it may be loaded: `http`, `https`, or a picture written into the document
@@ -80,8 +93,8 @@ export declare function opensOnPress(href: string): boolean;
80
93
  * or HTML among them, is refused, as is every other scheme.
81
94
  */
82
95
  export declare function imageSource(href: string): string | null;
83
- /** The blocks a document of `tokens` is drawn as. */
84
- export declare function markdownBlocks(tokens: readonly Token[]): MarkdownBlock[];
96
+ /** The blocks a document of `tokens` is drawn as, with links in `appSchemes` drawn as links too. */
97
+ export declare function markdownBlocks(tokens: readonly Token[], appSchemes?: AppLinkSchemes): MarkdownBlock[];
85
98
  /**
86
99
  * A key for `block` that stays the same while it is drawn: a block kept from the document before
87
100
  * keeps its own, and one {@link shareBlocks} made in place of an edited one takes that one's.
@@ -39,18 +39,38 @@ export function schemeOf(url) {
39
39
  }
40
40
  const LINK_SCHEMES = new Set(['http', 'https', 'mailto', 'tel']);
41
41
  const IMAGE_SCHEMES = new Set(['http', 'https']);
42
+ /** No app scheme: what a document is drawn with when the app lists none. */
43
+ export const NO_APP_SCHEMES = new Set();
44
+ const SCHEME_NAME = /^[a-z][a-z0-9+.-]*$/;
42
45
  /**
43
- * A link's target if it may be followed: `http`, `https`, `mailto`, `tel`, or relative, which is
44
- * the app's to resolve. Anything else, `javascript:`, `data:`, `vbscript:` and `file:` among
45
- * them, is null, and the link is drawn as its text. The scheme is read after the trim, so
46
- * whitespace the trim strips cannot hide one.
46
+ * The set of schemes an app lists, as {@link linkTarget} reads them. Each is trimmed, lowercased
47
+ * and stripped of one trailing colon, so `'MyApp:'` and `'myapp'` are the same; an entry that
48
+ * cannot be a scheme is dropped.
47
49
  */
48
- export function linkTarget(href) {
50
+ export function linkSchemeSet(schemes) {
51
+ const set = new Set();
52
+ for (const one of schemes) {
53
+ const name = one.trim().toLowerCase().replace(/:$/, '');
54
+ if (SCHEME_NAME.test(name))
55
+ set.add(name);
56
+ }
57
+ return set.size ? set : NO_APP_SCHEMES;
58
+ }
59
+ /**
60
+ * A link's target if it may be drawn as a link: `http`, `https`, `mailto`, `tel`, a scheme the app
61
+ * listed in `appSchemes`, or relative, which is the app's to resolve. Anything else,
62
+ * `javascript:`, `data:`, `vbscript:` and `file:` among them, is null, and the link is drawn as
63
+ * its text. The scheme is read after the trim, so whitespace the trim strips cannot hide one.
64
+ */
65
+ export function linkTarget(href, appSchemes = NO_APP_SCHEMES) {
49
66
  const target = href.trim();
50
67
  const scheme = schemeOf(target);
51
- return scheme === null || LINK_SCHEMES.has(scheme) ? target : null;
68
+ return scheme === null || LINK_SCHEMES.has(scheme) || appSchemes.has(scheme) ? target : null;
52
69
  }
53
- /** Whether `href` is absolute in a scheme a link may be followed to, and so is opened on press. */
70
+ /**
71
+ * Whether `href` is absolute in one of the built-in schemes a link is followed to, and so is
72
+ * opened on press. A scheme the app listed is drawn as a link but never opens here.
73
+ */
54
74
  export function opensOnPress(href) {
55
75
  const scheme = schemeOf(href.trim());
56
76
  return scheme !== null && LINK_SCHEMES.has(scheme);
@@ -82,38 +102,38 @@ function hrefOf(token) {
82
102
  return typeof href === 'string' ? decodeEntities(href) : null;
83
103
  }
84
104
  const HEADINGS = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
85
- /** The blocks a document of `tokens` is drawn as. */
86
- export function markdownBlocks(tokens) {
87
- return tokens.flatMap(block);
105
+ /** The blocks a document of `tokens` is drawn as, with links in `appSchemes` drawn as links too. */
106
+ export function markdownBlocks(tokens, appSchemes = NO_APP_SCHEMES) {
107
+ return tokens.flatMap((token) => block(token, appSchemes));
88
108
  }
89
109
  /** What each kind of block token is drawn as. A kind not here is drawn as its source text. */
90
110
  const BLOCKS = {
91
- heading: (token) => {
111
+ heading: (token, app) => {
92
112
  const heading = token;
93
113
  const depth = Math.min(Math.max(heading.depth, 1), 6);
94
- const children = trimmedEnd(inlines(heading.tokens));
114
+ const children = trimmedEnd(inlines(heading.tokens, app));
95
115
  return [{ kind: 'heading', element: HEADINGS[depth - 1], children }];
96
116
  },
97
- paragraph: (token) => paragraphs(token.tokens),
98
- text: (token) => {
117
+ paragraph: (token, app) => paragraphs(token.tokens, app),
118
+ text: (token, app) => {
99
119
  const text = token;
100
120
  return text.tokens
101
- ? paragraphs(text.tokens)
121
+ ? paragraphs(text.tokens, app)
102
122
  : [{ kind: 'paragraph', children: [plain(softBreaks(text.text))] }];
103
123
  },
104
- blockquote: (token) => [
105
- { kind: 'blockquote', children: markdownBlocks(token.tokens) },
124
+ blockquote: (token, app) => [
125
+ { kind: 'blockquote', children: markdownBlocks(token.tokens, app) },
106
126
  ],
107
- list: (token) => [list(token)],
127
+ list: (token, app) => [list(token, app)],
108
128
  code: (token) => [{ kind: 'code', text: indented(token.text) }],
109
129
  hr: () => [{ kind: 'hr' }],
110
- table: (token) => {
130
+ table: (token, app) => {
111
131
  const table = token;
112
132
  return [
113
133
  {
114
134
  kind: 'table',
115
- header: table.header.map((cell) => inlines(cell.tokens)),
116
- rows: table.rows.map((row) => row.map((cell) => inlines(cell.tokens))),
135
+ header: table.header.map((cell) => inlines(cell.tokens, app)),
136
+ rows: table.rows.map((row) => row.map((cell) => inlines(cell.tokens, app))),
117
137
  },
118
138
  ];
119
139
  },
@@ -122,9 +142,9 @@ const BLOCKS = {
122
142
  def: () => [],
123
143
  checkbox: () => [],
124
144
  };
125
- function block(token) {
145
+ function block(token, app) {
126
146
  const draw = Object.hasOwn(BLOCKS, token.type) ? BLOCKS[token.type] : null;
127
- return draw ? draw(token) : literal(token.raw ?? '');
147
+ return draw ? draw(token, app) : literal(token.raw ?? '');
128
148
  }
129
149
  /**
130
150
  * A code block's text with its first line's indent made of no-break spaces: a paragraph loses the
@@ -138,14 +158,14 @@ function literal(text) {
138
158
  const trimmed = text.replace(/\n+$/, '');
139
159
  return trimmed.trim() ? [{ kind: 'paragraph', children: [{ kind: 'text', text: trimmed }] }] : [];
140
160
  }
141
- function list(token) {
161
+ function list(token, app) {
142
162
  const start = typeof token.start === 'number' ? token.start : 1;
143
163
  return {
144
164
  kind: 'list',
145
165
  element: token.ordered ? 'ol' : 'ul',
146
166
  items: token.items.map((item, index) => ({
147
167
  marker: item.task ? (item.checked ? '☑' : '☐') : token.ordered ? `${start + index}.` : '•',
148
- children: markdownBlocks(item.tokens),
168
+ children: markdownBlocks(item.tokens, app),
149
169
  })),
150
170
  };
151
171
  }
@@ -154,7 +174,7 @@ function list(token) {
154
174
  * and the text either side of it a paragraph each. An image whose address is refused, and one
155
175
  * inside a link or an emphasis, is its alt text instead.
156
176
  */
157
- function paragraphs(tokens) {
177
+ function paragraphs(tokens, app) {
158
178
  const out = [];
159
179
  let run = [];
160
180
  const flush = () => {
@@ -167,7 +187,7 @@ function paragraphs(tokens) {
167
187
  const href = token.type === 'image' ? hrefOf(token) : null;
168
188
  const src = href === null ? null : imageSource(href);
169
189
  if (src === null) {
170
- run.push(...inline(token));
190
+ run.push(...inline(token, app));
171
191
  continue;
172
192
  }
173
193
  flush();
@@ -191,8 +211,8 @@ function trimmedEnd(runs) {
191
211
  return runs;
192
212
  return text ? [...runs.slice(0, -1), { kind: 'text', text }] : runs.slice(0, -1);
193
213
  }
194
- function inlines(tokens) {
195
- return (tokens ?? []).flatMap(inline);
214
+ function inlines(tokens, app) {
215
+ return (tokens ?? []).flatMap((token) => inline(token, app));
196
216
  }
197
217
  /**
198
218
  * Text with each line break the source wrapped it at made a space, as CommonMark reads a soft
@@ -204,15 +224,15 @@ function softBreaks(text) {
204
224
  function plain(text) {
205
225
  return { kind: 'text', text: decodeEntities(text) };
206
226
  }
207
- function emphasis(token) {
227
+ function emphasis(token, app) {
208
228
  const kind = token.type;
209
- return [{ kind, children: inlines(token.tokens) }];
229
+ return [{ kind, children: inlines(token.tokens, app) }];
210
230
  }
211
231
  /** What each kind of inline token is drawn as. A kind not here is drawn as its source text. */
212
232
  const INLINES = {
213
- text: (token) => {
233
+ text: (token, app) => {
214
234
  const text = token;
215
- return text.tokens ? inlines(text.tokens) : [plain(softBreaks(text.text))];
235
+ return text.tokens ? inlines(text.tokens, app) : [plain(softBreaks(text.text))];
216
236
  },
217
237
  escape: (token) => [plain(token.text)],
218
238
  strong: emphasis,
@@ -220,11 +240,11 @@ const INLINES = {
220
240
  del: emphasis,
221
241
  codespan: (token) => [{ kind: 'code', text: token.text }],
222
242
  br: () => [{ kind: 'text', text: '\n' }],
223
- link: (token) => {
243
+ link: (token, app) => {
224
244
  const link = token;
225
- const children = inlines(link.tokens);
245
+ const children = inlines(link.tokens, app);
226
246
  const decoded = hrefOf(link);
227
- const href = decoded === null ? null : linkTarget(decoded);
247
+ const href = decoded === null ? null : linkTarget(decoded, app);
228
248
  if (href === null)
229
249
  return children;
230
250
  const title = link.title ? decodeEntities(link.title) : null;
@@ -234,10 +254,10 @@ const INLINES = {
234
254
  html: (token) => [{ kind: 'text', text: token.text }],
235
255
  checkbox: () => [],
236
256
  };
237
- function inline(token) {
257
+ function inline(token, app) {
238
258
  const draw = Object.hasOwn(INLINES, token.type) ? INLINES[token.type] : null;
239
259
  if (draw)
240
- return draw(token);
260
+ return draw(token, app);
241
261
  return token.raw ? [{ kind: 'text', text: token.raw }] : [];
242
262
  }
243
263
  const keys = new WeakMap();
@@ -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,GAA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AG,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 `&amp;lt;` is `&lt;` 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/**\n * A link's target if it may be followed: `http`, `https`, `mailto`, `tel`, or relative, which is\n * the app's to resolve. Anything else, `javascript:`, `data:`, `vbscript:` and `file:` among\n * them, is null, and the link is drawn as its text. The scheme is read after the trim, so\n * whitespace the trim strips cannot hide one.\n */\nexport function linkTarget(href: string): string | null {\n const target = href.trim();\n const scheme = schemeOf(target);\n return scheme === null || LINK_SCHEMES.has(scheme) ? target : null;\n}\n\n/** Whether `href` is absolute in a scheme a link may be followed to, and so is opened on press. */\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. */\nexport function markdownBlocks(tokens: readonly Token[]): MarkdownBlock[] {\n return tokens.flatMap(block);\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) => MarkdownBlock[]>> = {\n heading: (token) => {\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));\n return [{ kind: 'heading', element: HEADINGS[depth - 1]!, children }];\n },\n paragraph: (token) => paragraphs((token as Tokens.Paragraph).tokens),\n text: (token) => {\n const text = token as Tokens.Text;\n return text.tokens\n ? paragraphs(text.tokens)\n : [{ kind: 'paragraph', children: [plain(softBreaks(text.text))] }];\n },\n blockquote: (token) => [\n { kind: 'blockquote', children: markdownBlocks((token as Tokens.Blockquote).tokens) },\n ],\n list: (token) => [list(token as Tokens.List)],\n code: (token) => [{ kind: 'code', text: indented((token as Tokens.Code).text) }],\n hr: () => [{ kind: 'hr' }],\n table: (token) => {\n const table = token as Tokens.Table;\n return [\n {\n kind: 'table',\n header: table.header.map((cell) => inlines(cell.tokens)),\n rows: table.rows.map((row) => row.map((cell) => inlines(cell.tokens))),\n },\n ];\n },\n html: (token) => literal((token as Tokens.HTML).text),\n space: () => [],\n def: () => [],\n checkbox: () => [],\n};\n\nfunction block(token: Token): MarkdownBlock[] {\n const draw = Object.hasOwn(BLOCKS, token.type) ? BLOCKS[token.type]! : null;\n return draw ? draw(token) : 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): 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),\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[]): 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));\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): MarkdownInline[] {\n return (tokens ?? []).flatMap(inline);\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): MarkdownInline[] {\n const kind = token.type as 'strong' | 'em' | 'del';\n return [{ kind, children: inlines((token as Tokens.Strong).tokens) }];\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) => MarkdownInline[]>> = {\n text: (token) => {\n const text = token as Tokens.Text;\n return text.tokens ? inlines(text.tokens) : [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) => {\n const link = token as Tokens.Link;\n const children = inlines(link.tokens);\n const decoded = hrefOf(link);\n const href = decoded === null ? null : linkTarget(decoded);\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): MarkdownInline[] {\n const draw = Object.hasOwn(INLINES, token.type) ? INLINES[token.type]! : null;\n if (draw) return draw(token);\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.set(out, key);\n return out;\n}\n"]}
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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AAG,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 `&amp;lt;` is `&lt;` 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.set(out, key);\n return out;\n}\n"]}
@@ -1,3 +1,15 @@
1
+ /**
2
+ * Markdown, drawn as native views and text.
3
+ *
4
+ * Its own entry point because it parses with `marked`, an optional peer dependency an app installs
5
+ * only when it renders Markdown: the barrel never imports it, so an app that does not is not asked
6
+ * for it.
7
+ *
8
+ * ```ts
9
+ * import { Markdown } from '@ng-native/components/markdown';
10
+ * ```
11
+ */
12
+ import { InjectionToken, type Provider } from '@angular/core';
1
13
  import { type Token } from 'marked';
2
14
  import type { ImageLoadEvent, LayoutEvent } from './events.ts';
3
15
  import { blockKey, type MarkdownBlock, type MarkdownElement, type MarkdownInline } from './markdown-blocks.ts';
@@ -13,6 +25,21 @@ export interface MarkdownLinkPress {
13
25
  /** Keep the link from being opened, to handle it in the app instead. */
14
26
  preventDefault(): void;
15
27
  }
28
+ /**
29
+ * The schemes, beyond `http`, `https`, `mailto` and `tel`, that every `<markdown>` draws links in
30
+ * unless its own `linkSchemes` is set. See `provideMarkdownLinkSchemes`.
31
+ */
32
+ export declare const MARKDOWN_LINK_SCHEMES: InjectionToken<readonly string[]>;
33
+ /**
34
+ * Make links in the app's own schemes links in every `<markdown>`, such as `myapp:item/42`:
35
+ * drawn as links and reported through `(linkPress)`, and never opened by default. A
36
+ * `[linkSchemes]` input on one `<markdown>` replaces this list for that one.
37
+ *
38
+ * ```ts
39
+ * providers: [provideMarkdownLinkSchemes('myapp')]
40
+ * ```
41
+ */
42
+ export declare function provideMarkdownLinkSchemes(...schemes: readonly string[]): Provider;
16
43
  type MarkdownLink = Extract<MarkdownInline, {
17
44
  kind: 'link';
18
45
  }>;
@@ -52,6 +79,12 @@ type ImageBlock = Extract<MarkdownBlock, {
52
79
  *
53
80
  * A pressed link is `(linkPress)`. An absolute target is then opened with `DeepLinks.open` unless
54
81
  * a handler calls `preventDefault()`; a relative one is only reported, for the app to route.
82
+ *
83
+ * A link in the app's own scheme, `myapp:item/42`, is drawn as plain text unless the scheme is
84
+ * listed in `linkSchemes`, or app-wide with `provideMarkdownLinkSchemes`. A listed scheme is drawn
85
+ * as a link and reported through `(linkPress)`, and is never opened: the app routes it. The input
86
+ * replaces the provider's list when it is set, even to an empty one. Schemes are matched without
87
+ * regard to case, and the list is read as a value: give a new array to change it.
55
88
  */
56
89
  export declare class Markdown {
57
90
  private readonly injector;
@@ -67,6 +100,12 @@ export declare class Markdown {
67
100
  * See the class note.
68
101
  */
69
102
  readonly streaming: import("@angular/core").InputSignalWithTransform<boolean, unknown>;
103
+ /**
104
+ * Schemes besides `http`, `https`, `mailto` and `tel` whose links are drawn as links and
105
+ * reported through `(linkPress)`, never opened. Replaces `provideMarkdownLinkSchemes` when set.
106
+ * See the class note.
107
+ */
108
+ readonly linkSchemes: import("@angular/core").InputSignal<readonly string[] | undefined>;
70
109
  /** A class for an element, in place of its default. See the class note. */
71
110
  readonly classes: import("@angular/core").InputSignal<Partial<Readonly<Record<MarkdownElement, string>>>>;
72
111
  /** A link was pressed. See the class note. */
@@ -78,7 +117,13 @@ export declare class Markdown {
78
117
  * chunk to the next, so its blocks are not converted or compared again; a source lexed whole
79
118
  * makes new tokens, and so new blocks.
80
119
  */
81
- private readonly streamed;
120
+ private streamed;
121
+ /** The schemes `streamed` was converted with; its blocks are stale once they change. */
122
+ private streamedFor;
123
+ private readonly providedSchemes;
124
+ /** The schemes links are drawn in, the same set while the list reads the same. */
125
+ private readonly appSchemes;
126
+ private readonly lexed;
82
127
  /** The document's blocks, with each one that did not change kept, so it is not drawn again. */
83
128
  protected readonly blocks: import("@angular/core").WritableSignal<readonly MarkdownBlock[]>;
84
129
  private readonly classOf;
@@ -111,5 +156,5 @@ export declare class Markdown {
111
156
  protected sizeImage(src: string, event: Partial<ImageLoadEvent>): void;
112
157
  protected followLink(link: MarkdownLink): void;
113
158
  static ɵfac: i0.ɵɵFactoryDeclaration<Markdown, never>;
114
- static ɵcmp: i0.ɵɵComponentDeclaration<Markdown, "markdown", never, { "source": { "alias": "source"; "required": false; "isSignal": true; }; "tokens": { "alias": "tokens"; "required": false; "isSignal": true; }; "streaming": { "alias": "streaming"; "required": false; "isSignal": true; }; "classes": { "alias": "classes"; "required": false; "isSignal": true; }; }, { "linkPress": "linkPress"; }, never, never, true, never>;
159
+ static ɵcmp: i0.ɵɵComponentDeclaration<Markdown, "markdown", never, { "source": { "alias": "source"; "required": false; "isSignal": true; }; "tokens": { "alias": "tokens"; "required": false; "isSignal": true; }; "streaming": { "alias": "streaming"; "required": false; "isSignal": true; }; "linkSchemes": { "alias": "linkSchemes"; "required": false; "isSignal": true; }; "classes": { "alias": "classes"; "required": false; "isSignal": true; }; }, { "linkPress": "linkPress"; }, never, never, true, never>;
115
160
  }