@velumo/renderer-dom 0.1.0-beta.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.
Files changed (58) hide show
  1. package/dist/background-renderer.d.ts +16 -0
  2. package/dist/background-renderer.d.ts.map +1 -0
  3. package/dist/background-renderer.js +41 -0
  4. package/dist/background-renderer.js.map +1 -0
  5. package/dist/camera-adapter.d.ts +16 -0
  6. package/dist/camera-adapter.d.ts.map +1 -0
  7. package/dist/camera-adapter.js +13 -0
  8. package/dist/camera-adapter.js.map +1 -0
  9. package/dist/default-theme.d.ts +5 -0
  10. package/dist/default-theme.d.ts.map +1 -0
  11. package/dist/default-theme.js +579 -0
  12. package/dist/default-theme.js.map +1 -0
  13. package/dist/dom-renderer.d.ts +62 -0
  14. package/dist/dom-renderer.d.ts.map +1 -0
  15. package/dist/dom-renderer.js +306 -0
  16. package/dist/dom-renderer.js.map +1 -0
  17. package/dist/html-sanitize.d.ts +18 -0
  18. package/dist/html-sanitize.d.ts.map +1 -0
  19. package/dist/html-sanitize.js +379 -0
  20. package/dist/html-sanitize.js.map +1 -0
  21. package/dist/index.d.ts +12 -0
  22. package/dist/index.d.ts.map +1 -0
  23. package/dist/index.js +10 -0
  24. package/dist/index.js.map +1 -0
  25. package/dist/layout-renderer.d.ts +16 -0
  26. package/dist/layout-renderer.d.ts.map +1 -0
  27. package/dist/layout-renderer.js +450 -0
  28. package/dist/layout-renderer.js.map +1 -0
  29. package/dist/slide-thumbnail.d.ts +63 -0
  30. package/dist/slide-thumbnail.d.ts.map +1 -0
  31. package/dist/slide-thumbnail.js +93 -0
  32. package/dist/slide-thumbnail.js.map +1 -0
  33. package/dist/spatial-renderer.d.ts +18 -0
  34. package/dist/spatial-renderer.d.ts.map +1 -0
  35. package/dist/spatial-renderer.js +36 -0
  36. package/dist/spatial-renderer.js.map +1 -0
  37. package/dist/theme-fonts.d.ts +8 -0
  38. package/dist/theme-fonts.d.ts.map +1 -0
  39. package/dist/theme-fonts.js +68 -0
  40. package/dist/theme-fonts.js.map +1 -0
  41. package/dist/theme-tokens.d.ts +3 -0
  42. package/dist/theme-tokens.d.ts.map +1 -0
  43. package/dist/theme-tokens.js +43 -0
  44. package/dist/theme-tokens.js.map +1 -0
  45. package/dist/tsconfig.tsbuildinfo +1 -0
  46. package/package.json +20 -0
  47. package/src/background-renderer.ts +77 -0
  48. package/src/camera-adapter.ts +21 -0
  49. package/src/default-theme.ts +582 -0
  50. package/src/dom-renderer.ts +486 -0
  51. package/src/html-sanitize.ts +446 -0
  52. package/src/index.ts +25 -0
  53. package/src/layout-renderer.ts +721 -0
  54. package/src/slide-thumbnail.ts +146 -0
  55. package/src/spatial-renderer.ts +62 -0
  56. package/src/theme-fonts.ts +75 -0
  57. package/src/theme-tokens.ts +66 -0
  58. package/tsconfig.json +10 -0
@@ -0,0 +1,306 @@
1
+ import { ActionDispatcher, dispatchControlAction, } from "@velumo/runtime";
2
+ import { defaultTheme } from "./default-theme.js";
3
+ import { compileFontFaceCss, escapeCssString } from "./theme-fonts.js";
4
+ import { tokensToCssProperties } from "./theme-tokens.js";
5
+ import { renderBackground } from "./background-renderer.js";
6
+ import { renderLayoutNode } from "./layout-renderer.js";
7
+ import { renderSafeHtml } from "./html-sanitize.js";
8
+ export class DomRenderer {
9
+ #root;
10
+ #manifest;
11
+ #runtime;
12
+ #registry;
13
+ #actionDispatcher;
14
+ #themeTokenProperties = new Set();
15
+ constructor(options) {
16
+ this.#root = options.root;
17
+ this.#manifest = options.manifest;
18
+ this.#runtime = options.runtime;
19
+ this.#registry = options.registry;
20
+ // One dispatcher over the active registry, reused by every layer context's
21
+ // dispatch. Absent when the registry has no action-handler seam (a minimal
22
+ // host) — control clicks then render inert.
23
+ const registry = options.registry;
24
+ this.#actionDispatcher =
25
+ registry?.getActionHandler !== undefined
26
+ ? new ActionDispatcher({
27
+ registry: {
28
+ getActionHandler: (type) => registry.getActionHandler?.(type),
29
+ },
30
+ })
31
+ : undefined;
32
+ }
33
+ getRoot() {
34
+ return this.#root;
35
+ }
36
+ mount() {
37
+ this.#root.setAttribute("data-velumo-renderer", "dom");
38
+ this.render();
39
+ }
40
+ render() {
41
+ this.#applyTheme();
42
+ this.#root.replaceChildren(this.#renderSlide(this.#currentSlide()));
43
+ }
44
+ unmount() {
45
+ this.#root.replaceChildren();
46
+ this.#root.removeAttribute("data-velumo-renderer");
47
+ this.#root.removeAttribute("data-velumo-theme");
48
+ this.#clearThemeTokenProperties();
49
+ }
50
+ dispose() {
51
+ this.unmount();
52
+ }
53
+ #applyTheme() {
54
+ const theme = this.#manifest.theme ?? defaultTheme;
55
+ const themeId = theme.id;
56
+ this.#root.setAttribute("data-velumo-theme", themeId);
57
+ this.#applyThemeTokenProperties(theme.tokens);
58
+ this.#applyThemeCss(theme);
59
+ this.#applyThemeFonts(theme);
60
+ }
61
+ // Injects the active theme's own CSS into document.head once per
62
+ // (document, theme id). The injected <style> is intentionally NOT removed on
63
+ // unmount: it is document-level and may be shared by other live renderers
64
+ // (e.g. the presenter mounts several). This is only safe because every rule a
65
+ // theme ships in `theme.css` is expected to be scoped to
66
+ // `[data-velumo-theme="<id>"]`, so a lingering style for an inactive theme
67
+ // matches nothing. A theme shipping unscoped rules here would leak across the page.
68
+ #applyThemeCss(theme) {
69
+ const css = typeof theme.css === "string" ? theme.css : undefined;
70
+ if (css === undefined || css === "") {
71
+ return;
72
+ }
73
+ const doc = this.#root.ownerDocument;
74
+ const head = doc.head;
75
+ if (head === undefined || typeof doc.querySelector !== "function") {
76
+ return;
77
+ }
78
+ const marker = "data-velumo-theme-style";
79
+ if (doc.querySelector(`[${marker}="${escapeCssString(theme.id)}"]`) !== null) {
80
+ return;
81
+ }
82
+ const style = doc.createElement("style");
83
+ style.setAttribute(marker, theme.id);
84
+ style.textContent = css;
85
+ head.appendChild(style);
86
+ }
87
+ // Injects the active theme's declared font faces into document.head as a
88
+ // single `<style>`, deduped per (document, theme id), no-op when there are no
89
+ // fonts or the host lacks head/querySelector. The injected text is exactly
90
+ // `compileFontFaceCss(theme.fonts)` — there is no second, hand-rolled code
91
+ // path. Like the theme-css style it is NOT removed on unmount: it is
92
+ // document-level and may be shared by other live renderers (the presenter
93
+ // mounts several of the same theme).
94
+ //
95
+ // The safety argument differs from `#applyThemeCss`. Theme CSS is selector-
96
+ // scoped to `[data-velumo-theme="<id>"]`, so a lingering style for an
97
+ // inactive theme matches nothing. `@font-face` is NOT selector-scoped — it
98
+ // registers a font family document-globally. Deduping per theme id keeps each
99
+ // theme's faces under their own marker so they coexist without clobbering, and
100
+ // a lingering face for an inactive theme is mostly inert (nothing references
101
+ // the family; a data-URI triggers no network fetch). The one residual edge:
102
+ // two themes declaring the SAME `family` with different bytes in one document
103
+ // resolve by cascade/head order. Not reachable today (a document carries one
104
+ // theme id); themes should namespace family names.
105
+ #applyThemeFonts(theme) {
106
+ const fonts = theme.fonts;
107
+ if (fonts === undefined || fonts.length === 0) {
108
+ return;
109
+ }
110
+ const doc = this.#root.ownerDocument;
111
+ const head = doc.head;
112
+ if (head === undefined || typeof doc.querySelector !== "function") {
113
+ return;
114
+ }
115
+ const marker = "data-velumo-theme-fonts";
116
+ if (doc.querySelector(`[${marker}="${escapeCssString(theme.id)}"]`) !== null) {
117
+ return;
118
+ }
119
+ const style = doc.createElement("style");
120
+ style.setAttribute(marker, theme.id);
121
+ style.textContent = compileFontFaceCss(fonts);
122
+ head.appendChild(style);
123
+ }
124
+ #currentSlide() {
125
+ const state = this.#runtime.getState();
126
+ return (this.#manifest.slides.find((slide) => slide.id === state.slideId) ??
127
+ this.#manifest.slides[0]);
128
+ }
129
+ #renderSlide(slide) {
130
+ const slideElement = this.#createElement("section");
131
+ slideElement.setAttribute("data-velumo-slide-id", slide.id);
132
+ slideElement.setAttribute("data-velumo-slide-kind", slide.kind);
133
+ slideElement.setAttribute("aria-label", `${this.#manifest.deck.title} ${slide.id}`);
134
+ if (slide.transition !== undefined) {
135
+ slideElement.setAttribute("data-velumo-transition", slide.transition);
136
+ }
137
+ const watermark = this.#manifest.deck.watermark;
138
+ const hasWatermark = typeof watermark === "string" &&
139
+ watermark.trim().length > 0 &&
140
+ slide.chrome !== false;
141
+ const needsPositioning = slide.background !== undefined ||
142
+ slide.layout?.kind === "canvas" ||
143
+ hasWatermark;
144
+ if (needsPositioning) {
145
+ this.#setStyleProperty(slideElement, "position", "relative");
146
+ }
147
+ if (slide.background !== undefined) {
148
+ this.#setStyleProperty(slideElement, "z-index", "0");
149
+ slideElement.appendChild(renderBackground(slide.background, {
150
+ createElement: (tag) => this.#createElement(tag),
151
+ setStyleProperty: (el, prop, val) => this.#setStyleProperty(el, prop, val),
152
+ }));
153
+ }
154
+ if (slide.layout !== undefined) {
155
+ const layoutRoot = this.#createElement("div");
156
+ layoutRoot.setAttribute("data-velumo-layout-root", "");
157
+ layoutRoot.appendChild(renderLayoutNode(slide.layout, {
158
+ createElement: (tag) => this.#createElement(tag),
159
+ createElementNS: (ns, tag) => this.#createElementNS(ns, tag),
160
+ setStyleProperty: (el, prop, val) => this.#setStyleProperty(el, prop, val),
161
+ }));
162
+ slideElement.appendChild(layoutRoot);
163
+ }
164
+ for (const layer of slide.layers ?? []) {
165
+ slideElement.appendChild(this.#renderLayer(slide, layer));
166
+ }
167
+ if (hasWatermark) {
168
+ const mark = this.#createElement("div");
169
+ mark.setAttribute("data-velumo-watermark", "");
170
+ mark.setAttribute("aria-hidden", "true");
171
+ mark.textContent = watermark;
172
+ slideElement.appendChild(mark);
173
+ }
174
+ return slideElement;
175
+ }
176
+ #renderLayer(slide, layer) {
177
+ const layerElement = this.#createElement("div");
178
+ layerElement.setAttribute("data-velumo-layer-type", layer.type);
179
+ if (layer.id !== undefined) {
180
+ layerElement.setAttribute("data-velumo-layer-id", layer.id);
181
+ }
182
+ this.#applyFragmentState(slide, layer, layerElement);
183
+ const customRenderer = this.#registry?.getLayerRenderer(layer.type);
184
+ if (customRenderer !== undefined) {
185
+ this.#appendCustomLayerResult(layerElement, customRenderer(this.#createLayerContext(slide, layer)));
186
+ return layerElement;
187
+ }
188
+ switch (layer.type) {
189
+ case "markdown":
190
+ layerElement.append(...this.#renderMarkdown(String(layer.content ?? "")));
191
+ return layerElement;
192
+ case "html":
193
+ layerElement.append(...renderSafeHtml(String(layer.content ?? ""), {
194
+ createElement: (tag) => this.#createElement(tag),
195
+ createText: (text) => this.#createText(text),
196
+ textElement: (tag, text) => this.#textElement(tag, text),
197
+ }));
198
+ return layerElement;
199
+ default:
200
+ layerElement.textContent = layer.type;
201
+ return layerElement;
202
+ }
203
+ }
204
+ #createLayerContext(slide, layer) {
205
+ const dispatcher = this.#actionDispatcher;
206
+ const runtime = this.#runtime;
207
+ return {
208
+ layer,
209
+ slide,
210
+ manifest: this.#manifest,
211
+ runtime,
212
+ createElement: (tagName) => this.#createElement(tagName),
213
+ createText: (text) => this.#createText(text),
214
+ dispatch: (action) => {
215
+ if (dispatcher === undefined) {
216
+ return; // inert on a minimal / no-action-handler host
217
+ }
218
+ dispatchControlAction(dispatcher, {
219
+ type: action.type,
220
+ ...(action.payload === undefined
221
+ ? {}
222
+ : { payload: action.payload }),
223
+ }, runtime);
224
+ },
225
+ };
226
+ }
227
+ #appendCustomLayerResult(layerElement, result) {
228
+ if (result === null || result === undefined) {
229
+ return;
230
+ }
231
+ const children = Array.isArray(result) ? result : [result];
232
+ layerElement.append(...children);
233
+ }
234
+ #applyFragmentState(slide, layer, layerElement) {
235
+ const fragmentIndex = this.#fragmentIndexForLayer(slide, layer);
236
+ if (fragmentIndex === undefined) {
237
+ return;
238
+ }
239
+ const visible = fragmentIndex + 1 <= this.#runtime.getState().fragmentIndex;
240
+ layerElement.setAttribute("data-velumo-fragment", visible ? "visible" : "hidden");
241
+ }
242
+ #fragmentIndexForLayer(slide, layer) {
243
+ if (layer.id === undefined) {
244
+ return undefined;
245
+ }
246
+ const fragmentIndex = slide.fragments?.findIndex((fragment) => fragment.layerId === layer.id);
247
+ return fragmentIndex === undefined || fragmentIndex === -1
248
+ ? undefined
249
+ : fragmentIndex;
250
+ }
251
+ #renderMarkdown(source) {
252
+ const elements = [];
253
+ for (const block of source.split(/\n{2,}/)) {
254
+ const lines = block.split(/\n/).filter((line) => line.length > 0);
255
+ for (const line of lines) {
256
+ if (line.startsWith("## ")) {
257
+ elements.push(this.#textElement("h2", line.slice(3)));
258
+ continue;
259
+ }
260
+ if (line.startsWith("# ")) {
261
+ elements.push(this.#textElement("h1", line.slice(2)));
262
+ continue;
263
+ }
264
+ elements.push(this.#textElement("p", line));
265
+ }
266
+ }
267
+ return elements;
268
+ }
269
+ #textElement(tagName, text) {
270
+ const element = this.#createElement(tagName);
271
+ element.textContent = text;
272
+ return element;
273
+ }
274
+ #createElement(tagName) {
275
+ return this.#root.ownerDocument.createElement(tagName);
276
+ }
277
+ #createElementNS(namespace, tagName) {
278
+ return this.#root.ownerDocument.createElementNS(namespace, tagName);
279
+ }
280
+ #createText(text) {
281
+ return this.#root.ownerDocument.createTextNode(text);
282
+ }
283
+ #applyThemeTokenProperties(tokens) {
284
+ const nextProperties = tokensToCssProperties(tokens);
285
+ for (const property of this.#themeTokenProperties) {
286
+ if (!nextProperties.has(property)) {
287
+ this.#root.style?.removeProperty(property);
288
+ this.#themeTokenProperties.delete(property);
289
+ }
290
+ }
291
+ for (const [property, value] of nextProperties) {
292
+ this.#setStyleProperty(this.#root, property, value);
293
+ this.#themeTokenProperties.add(property);
294
+ }
295
+ }
296
+ #clearThemeTokenProperties() {
297
+ for (const property of this.#themeTokenProperties) {
298
+ this.#root.style?.removeProperty(property);
299
+ }
300
+ this.#themeTokenProperties.clear();
301
+ }
302
+ #setStyleProperty(element, property, value) {
303
+ element.style?.setProperty(property, value);
304
+ }
305
+ }
306
+ //# sourceMappingURL=dom-renderer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dom-renderer.js","sourceRoot":"","sources":["../src/dom-renderer.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,gBAAgB,EAChB,qBAAqB,GAKtB,MAAM,iBAAiB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CAAC,KAAK,EAAE,cAAc,CAAC,QAAQ,CAAC,CAAC;gBAC3C,IAAI,CAAC,qBAAqB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YAC9C,CAAC;QACH,CAAC;QAED,KAAK,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAI,cAAc,EAAE,CAAC;YAC/C,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;YACpD,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC3C,CAAC;IACH,CAAC;IAED,0BAA0B;QACxB,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,qBAAqB,EAAE,CAAC;YAClD,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,cAAc,CAAC,QAAQ,CAAC,CAAC;QAC7C,CAAC;QAED,IAAI,CAAC,qBAAqB,CAAC,KAAK,EAAE,CAAC;IACrC,CAAC;IAED,iBAAiB,CACf,OAEC,EACD,QAAgB,EAChB,KAAa;QAEb,OAAO,CAAC,KAAK,EAAE,WAAW,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IAC9C,CAAC;CACF"}
@@ -0,0 +1,18 @@
1
+ export interface HtmlSanitizeElement {
2
+ setAttribute(name: string, value: string): void;
3
+ textContent: string;
4
+ parentNode?: unknown;
5
+ }
6
+ export interface HtmlSanitizeNode {
7
+ textContent: string;
8
+ parentNode?: unknown;
9
+ }
10
+ export interface HtmlSanitizeFactories {
11
+ createElement(tagName: string): HtmlSanitizeElement;
12
+ createText(text: string): HtmlSanitizeNode;
13
+ textElement(tagName: string, text: string): HtmlSanitizeElement;
14
+ }
15
+ export declare function sanitizeHtmlLayer(source: string): string;
16
+ export declare function stripTags(source: string): string;
17
+ export declare function renderSafeHtml(source: string, factories: HtmlSanitizeFactories): Array<HtmlSanitizeElement | HtmlSanitizeNode>;
18
+ //# sourceMappingURL=html-sanitize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"html-sanitize.d.ts","sourceRoot":"","sources":["../src/html-sanitize.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,mBAAmB;IAClC,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAChD,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,WAAW,gBAAgB;IAC/B,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,WAAW,qBAAqB;IACpC,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,mBAAmB,CAAC;IACpD,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,CAAC;IAC3C,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,mBAAmB,CAAC;CACjE;AAiYD,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CA2BxD;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED,wBAAgB,cAAc,CAC5B,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,qBAAqB,GAC/B,KAAK,CAAC,mBAAmB,GAAG,gBAAgB,CAAC,CAS/C"}