@vectojs/markdown 0.23.2 → 0.24.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.
@@ -1,5 +1,10 @@
1
1
  import type { InlineObjectBox, InlineObjectSurface } from '@vectojs/core';
2
2
  import type { Token, Tokens } from 'marked';
3
+ import type { ImageSource } from '@vectojs/ui';
4
+ /** Resolve a markdown image `src` to a generic {@link ImageSource}. */
5
+ export type MarkdownImageResolver = (src: string) => ImageSource | Promise<ImageSource>;
6
+ /** Default resolver — identity mapping to `{kind:'url'}`. */
7
+ export declare const defaultMarkdownImageResolver: MarkdownImageResolver;
3
8
  /**
4
9
  * Image predicates over a `marked` token tree, plus the raster store for images
5
10
  * that render *inline* rather than as their own block.
@@ -75,16 +80,26 @@ export declare function lastIndexOfImage(tokens: Token[]): number;
75
80
  * `InlineObject`, and the box it occupies is fixed when the span is collected, so
76
81
  * the natural size has to be readable from here before the next layout rather than
77
82
  * applied to an entity afterwards.
83
+ *
84
+ * Supports generic {@link ImageSource}: `url` decodes via `HTMLImageElement`,
85
+ * `blob` via `createImageBitmap` (with object-URL fallback), and `bitmap` is used
86
+ * directly. The backing `source` is the `CanvasImageSource` drawn by
87
+ * `paintInlineImage`; `bitmap` is retained as a legacy alias for `url` rasters so
88
+ * existing tests that reach through `raster.bitmap` keep working.
78
89
  */
79
90
  export interface InlineImageRaster {
80
91
  /** `undefined` when this environment has no `Image` (SSR, plain unit tests). */
81
92
  bitmap?: HTMLImageElement;
93
+ /** Generic backing source for `IRenderer.drawImage` / `InlineObjectSurface`. */
94
+ source?: CanvasImageSource;
82
95
  decoded: boolean;
83
96
  /** Natural size, known only once decoded. */
84
97
  naturalWidth?: number;
85
98
  naturalHeight?: number;
86
99
  /** Set when the decode failed, so a broken URL is not retried every frame. */
87
100
  failed?: boolean;
101
+ /** Release `ImageBitmap` / revoke `blob:` URL when evicted or cleared. */
102
+ dispose?: () => void;
88
103
  }
89
104
  /** Subscribe `notify` to inline-image decodes. Idempotent per closure. */
90
105
  export declare function subscribeInlineImageRaster(notify: () => void): void;
@@ -102,14 +117,22 @@ export declare function unsubscribeInlineImageRaster(notify: () => void): void;
102
117
  * paint path calls it on every visible frame, and only the first call starts a
103
118
  * decode. Exported because the span collector needs the natural size to size its
104
119
  * box, which is the whole reason this store reports one.
120
+ *
121
+ * When a resolver is supplied, its result (which may be `blob` or `bitmap`) is
122
+ * decoded instead of the raw `src` URL. Resolver may be async — the raster stays
123
+ * square until the promise settles, then notifies waiters so the owner can
124
+ * re-measure.
105
125
  */
106
- export declare function ensureInlineImageRaster(src: string): InlineImageRaster;
126
+ export declare function ensureInlineImageRaster(src: string, resolver?: MarkdownImageResolver): InlineImageRaster;
107
127
  /**
108
128
  * Paint one inline image into the box the layout engine reserved for it.
109
129
  *
110
130
  * Draws nothing until the raster decodes — one frame of empty box, then a repaint
111
131
  * through {@link inlineImageRasterWaiters}. Mirrors `paintInlineMath`; a
112
132
  * placeholder slab would flash a grey rectangle mid-sentence on every first paint.
133
+ *
134
+ * Supports generic {@link ImageSource} backing: `source` may be an `ImageBitmap`
135
+ * or an `HTMLImageElement`.
113
136
  */
114
137
  export declare function paintInlineImage(src: string, surface: InlineObjectSurface, box: InlineObjectBox): void;
115
138
  /** Drop every cached raster. Tests only — a decode is process-wide state. */
@@ -1,6 +1,7 @@
1
1
  import { type StyledSpan, type TextStyle } from '@vectojs/core';
2
2
  import { RichText } from '@vectojs/ui';
3
3
  import type { Token } from 'marked';
4
+ import { type MarkdownImageResolver } from './markdown-image';
4
5
  import type { MarkdownTheme } from './theme';
5
6
  /**
6
7
  * Inline tokens to `RichText` spans: the entity decoder, the span collector and
@@ -62,7 +63,14 @@ blockFontSize?: number,
62
63
  * call site that has none to thread — nested recursive calls, and callers
63
64
  * predating this feature — costs nothing extra.
64
65
  */
65
- abbr?: ReadonlyMap<string, string>): void;
66
+ abbr?: ReadonlyMap<string, string>,
67
+ /**
68
+ * How a markdown image `src` becomes a generic {@link ImageSource}. When
69
+ * omitted the default identity `{kind:'url'}` mapping is used, so a plain
70
+ * `![alt](https://…)` keeps its historic path and an app can supply a
71
+ * CapGlyph adapter that returns `{kind:'bitmap'}` for `capglyph:` URLs.
72
+ */
73
+ imageResolver?: MarkdownImageResolver): void;
66
74
  /**
67
75
  * One trailing inline construct that has opened but not closed yet.
68
76
  *
@@ -93,4 +101,4 @@ export declare function findUnclosedInline(text: string): UnclosedInline | null;
93
101
  /** Parse inline markdown tokens and produce a {@link RichText} entity. */
94
102
  export declare function renderInlineToRichText(tokens: Token[] | undefined, fallbackText: string, font: string, color: string, maxWidth: number, theme: Required<MarkdownTheme>, selectable: boolean, onLinkClick?: (url: string) => void,
95
103
  /** The document's `*[TERM]: definition` dictionary — see {@link emitProse}. */
96
- abbr?: ReadonlyMap<string, string>): RichText;
104
+ abbr?: ReadonlyMap<string, string>, imageResolver?: MarkdownImageResolver): RichText;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vectojs/markdown",
3
- "version": "0.23.2",
3
+ "version": "0.24.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },