@treasure-ai/treasure-deck 2026.11.4 → 2026.11.6

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 (48) hide show
  1. package/dist/build.d.ts +7 -3
  2. package/dist/build.js +17 -7
  3. package/dist/build.js.map +1 -1
  4. package/dist/charts.d.ts +17 -0
  5. package/dist/charts.js +454 -0
  6. package/dist/charts.js.map +1 -0
  7. package/dist/check.js +14 -1
  8. package/dist/check.js.map +1 -1
  9. package/dist/chrome.js +2 -0
  10. package/dist/chrome.js.map +1 -1
  11. package/dist/cli.js +3 -3
  12. package/dist/cli.js.map +1 -1
  13. package/dist/components.d.ts +13 -0
  14. package/dist/components.js +46 -0
  15. package/dist/components.js.map +1 -0
  16. package/dist/deckindex.js +21 -4
  17. package/dist/deckindex.js.map +1 -1
  18. package/dist/deckstyle.js +1 -1
  19. package/dist/dev.js +15 -11
  20. package/dist/dev.js.map +1 -1
  21. package/dist/diagrams.d.ts +15 -8
  22. package/dist/diagrams.js +60 -26
  23. package/dist/diagrams.js.map +1 -1
  24. package/dist/render.d.ts +18 -0
  25. package/dist/render.js +103 -0
  26. package/dist/render.js.map +1 -1
  27. package/dist/slides.js +8 -4
  28. package/dist/slides.js.map +1 -1
  29. package/dist/slidesexport.js +2 -2
  30. package/dist/slidesexport.js.map +1 -1
  31. package/dist/themecheck.js +2 -2
  32. package/dist/themecheck.js.map +1 -1
  33. package/dist/vendor.d.ts +10 -1
  34. package/dist/vendor.js +32 -2
  35. package/dist/vendor.js.map +1 -1
  36. package/docs/syntax.md +71 -0
  37. package/package.json +8 -1
  38. package/runtime/base.css +11 -0
  39. package/runtime/embed.js +4 -2
  40. package/runtime/runtime.js +292 -3
  41. package/skills/treasure-deck/SKILL.md +47 -0
  42. package/vendor/echarts/LICENSE +222 -0
  43. package/vendor/echarts/echarts.min.js +45 -0
  44. package/vendor/react/LICENSE-react +21 -0
  45. package/vendor/react/LICENSE-react-dom +21 -0
  46. package/vendor/react/LICENSE-recharts +22 -0
  47. package/vendor/react/LICENSE-tailwindcss +21 -0
  48. package/vendor/react/deck-react.js +78 -0
package/docs/syntax.md CHANGED
@@ -216,3 +216,74 @@ Fenced code is highlighted at build time for every [highlight.js](https://highli
216
216
  ` ```mermaid ` blocks render as diagrams colored by the theme, and follow light and dark mode. `deck build` draws them ahead of time in headless Chrome with a bundled Mermaid and inlines the SVG, so the page needs no network and a diagram with a syntax error fails the build (without Chrome, they render in the browser from jsDelivr). Nodes are bold, gradient-filled, and shadowed; give one a palette role with `A[Label]:::accent`, `:::dark`, `:::muted`, or `:::light` (the default is the primary gradient).
217
217
 
218
218
  A diagram is as wide as Mermaid draws it, up to its column. ` ```mermaid {w=60%} ` scales it to that width (canvas px or % of the column, larger as well as smaller), centered, and `{h=300}` to that height.
219
+
220
+ ## Charts
221
+
222
+ A ` ```chart ` block draws a chart in the theme's colors (`--deck-series-1` to `6`, with the theme's text, lines, and font), and follows light and dark mode. Like diagrams, `deck build` draws charts ahead of time in headless Chrome with a bundled [ECharts](https://echarts.apache.org/) and inlines the SVG, so the page needs no network (without Chrome, they draw in the browser from jsDelivr). A chart is static on the page: no hover tooltips.
223
+
224
+ ````md
225
+ ```chart
226
+ type: bar
227
+ x: [Q1, Q2, Q3, Q4]
228
+ series:
229
+ Revenue: [12, 18, 25, 35]
230
+ Cost: [8, 9, 11, 12]
231
+ ```
232
+ ````
233
+
234
+ | Key | Meaning |
235
+ |---|---|
236
+ | `type` | `bar`, `line`, `area`, `pie`, `donut`, `scatter`, `funnel`, `gauge`, `radar`, `sankey`, or `treemap`; also `horizontal-bar` and `stacked-bar` (a bar with `horizontal` or `stack`) |
237
+ | `x` | The categories, in order |
238
+ | `series` | Each series by name, with one value per category (`Revenue: [12, 18]`), or one unnamed list (`[12, 18]`). For `scatter`, a list of `[x, y]` points. A `pie`, `donut`, `funnel`, or `treemap` takes one series |
239
+ | `links` | A `sankey`'s flows, each `[from, to, value]` (or `{source, target, value}`) by node name; the nodes are the names it uses |
240
+ | `data` | Instead of `x` and `series`: a `.csv` or `.json` file beside the deck, or a list of rows (`- {month: Jan, revenue: 12}`). The first column is the categories, each other column a series named by its header |
241
+ | `stack` | `true` stacks the series |
242
+ | `horizontal` | `true` lays bars on their side |
243
+ | `labels` | `true` writes each value on its bar or point (pies show labels unless `false`) |
244
+ | `highlight` | One category drawn in the accent, the others muted: the bar the slide is about |
245
+ | `unit`, `prefix` | Around every value on the axis and labels: `prefix: "$"`, `unit: M` reads `$35M` |
246
+ | `min`, `max` | The value axis's range (a gauge's too, 0–100 by default) |
247
+ | `value`, `name` | A `gauge`'s number and its caption |
248
+ | `title`, `legend`, `smooth` | A title above the chart, the legend on or off (shown for more than one series), and straight lines with `smooth: false` |
249
+ | `x_axis_title`, `y_axis_title` | Names under the bottom axis and beside the left one, whichever way the bars lie (`y` is short for `y_axis_title`) |
250
+
251
+ Treasure Work's `render_chart` arguments work as written, in JSON or YAML: `type` (any of its 11 types), `title`, `labels`, `datasets` (`[{label, data, x_data}]`, with `x_data` for scatter), `x_axis_title`, `y_axis_title`, `nodes` and `links` (by node index) for a sankey, and `treemap_data` (`[{name, value}]`) for a treemap. As in Treasure Work, a pie or funnel draws the first dataset. So a chart made in chat goes onto a slide by pasting its arguments into a ` ```chart ` block:
252
+
253
+ ````md
254
+ ```chart
255
+ {"type": "stacked-bar", "title": "Revenue by segment", "labels": ["Q1", "Q2", "Q3"],
256
+ "datasets": [{"label": "Enterprise", "data": [8, 11, 15]}, {"label": "Self-serve", "data": [4, 5, 7]}]}
257
+ ```
258
+ ````
259
+
260
+ A block without `type:`, or with its option under `option:`, is an [ECharts option](https://echarts.apache.org/en/option.html) as is, in YAML or JSON. The theme still colors what the option leaves to it, and any color in it can be a theme token, such as `color: var(--deck-accent)`. An option with a series type ECharts doesn't have fails the build.
261
+
262
+ A chart is its column's width at 16:9, at most 440px tall. ` ```chart {h=300} ` sets its height and `{w=60%}` its width (canvas px or % of the column), centered.
263
+
264
+ ## React components
265
+
266
+ A slide can hold a React component, written the way Treasure Work's `render_react` takes one, so a dashboard made in chat moves onto a slide unchanged: `![Q3 KPIs](kpi.jsx){data=kpi.json}` for a `.jsx` or `.tsx` file beside the deck, or the code itself in a ` ```react ` block.
267
+
268
+ ```jsx
269
+ export default function KPIs({ data }) {
270
+ return (
271
+ <div className="grid grid-cols-3 gap-4">
272
+ {data.kpis.map((k) => (
273
+ <div key={k.label} className="p-4 rounded-lg border border-gray-200 dark:border-gray-700">
274
+ <div className="text-sm text-gray-500">{k.label}</div>
275
+ <div className="text-3xl font-bold" style={{ color: palette.accent }}>{k.value}</div>
276
+ </div>
277
+ ))}
278
+ </div>
279
+ );
280
+ }
281
+ ```
282
+
283
+ - **One component**, `export default function Name({ data }) { ... }`, in JSX or TSX. Imports are dropped: React's hooks (`useState`, `useEffect`, `useMemo`, …), `React`, and every [Recharts](https://recharts.org/) component (`ResponsiveContainer`, `LineChart`, `Bar`, …) are already in scope.
284
+ - **`data`** is the JSON file named by `data=`. `isDark` and `theme` (`"light"` or `"dark"`) follow the slide's background, and `palette` holds the slide's resolved theme colors: `series` (six), `accent`, `accent2`, `fg`, `muted`, `line`, `card`, `bg`, `ok`, `warn`, and `font`. Use them to match the deck's theme. They are props as well.
285
+ - **Tailwind**: the same subset of utility classes `render_react` ships, with `dark:` variants following the slide. Each component draws in its own shadow root, so these styles never reach the rest of the slide, and the slide's font and text color carry into it.
286
+ - **Size**: the component is as wide as its column (`w=` narrower) and as tall as it draws itself. `h=` fixes its height. `scale=0.8` draws it at 80%, for a dashboard designed for a larger screen. `deck check` reports a component wider than its column or taller than its `h=`.
287
+ - On the page it is live: tooltips and buttons work while presenting, and its charts animate in each time its slide is shown. `deck pdf`, `deck check`, deck index thumbnails, and Google Slides export capture it as drawn, without the animation. A component that doesn't compile fails the build at its slide; one that throws shows its error on the slide, and `deck check` and `deck build` report it.
288
+ - A page with components carries React, Recharts, and the Tailwind classes (about 1.1 MB). A page without any doesn't.
289
+ - The component's file and its data travel in the built page's source, so `deck import` writes them back out.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@treasure-ai/treasure-deck",
3
- "version": "2026.11.4",
3
+ "version": "2026.11.6",
4
4
  "description": "Markdown presentations without <div> markup: four layouts, themes, and a single-file HTML output that publishes to Apps Script",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "homepage": "https://www.npmjs.com/package/@treasure-ai/treasure-deck",
@@ -56,13 +56,20 @@
56
56
  "markdown-it": "^15.0.3",
57
57
  "markdown-it-attrs": "^5.0.1",
58
58
  "markdown-it-bracketed-spans": "^1.0.3",
59
+ "sucrase": "^3.35.1",
59
60
  "vite": "^8.3.3",
60
61
  "yaml": "^2.9.1"
61
62
  },
62
63
  "devDependencies": {
64
+ "@tailwindcss/vite": "^4.3.5",
63
65
  "@types/node": "^26.6.4",
66
+ "echarts": "^6.1.0",
64
67
  "lucide-static": "^1.52.0",
65
68
  "mermaid": "^12.2.0",
69
+ "react": "^19.3.1",
70
+ "react-dom": "^19.3.1",
71
+ "recharts": "^3.10.1",
72
+ "tailwindcss": "^4.3.5",
66
73
  "tsx": "^4.23.15",
67
74
  "typescript": "^7.0.2",
68
75
  "vitest": "^5.0.3"
package/runtime/base.css CHANGED
@@ -151,6 +151,17 @@ body { -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
151
151
  .slide .diagram svg .node, .slide .diagram svg rect.actor, .slide .diagram svg .note { filter: drop-shadow(0 6px 10px var(--deck-diagram-shadow, rgba(0, 0, 0, .16))) drop-shadow(0 1px 2px var(--deck-diagram-shadow, rgba(0, 0, 0, .16))); }
152
152
  .slide .diagram foreignObject * { font-size: 19px; line-height: 1.5; letter-spacing: normal; margin: 0; padding: 0; text-transform: none; }
153
153
 
154
+ /* ```chart: the column's width (w= narrower) at 16:9, at most 440px tall (h= sets the height); the SVG scales to it. */
155
+ .slide .chart { display: block; width: min(var(--box-w, 100%), 100%); margin: 0 auto .5em; }
156
+ .slide .chart > .chart-plot { width: 100%; aspect-ratio: 16 / 9; max-height: 440px; }
157
+ .slide .chart[style*="--box-h"] > .chart-plot { height: var(--box-h); aspect-ratio: auto; max-height: none; }
158
+ .slide .chart > .chart-plot > svg { display: block; width: 100%; height: 100%; overflow: visible; }
159
+ .slide .chart > .chart-plot[data-error] { aspect-ratio: auto; padding: 12px; border: 1px dashed var(--deck-warn); color: var(--deck-warn); font-size: 16px; }
160
+ /* React components (![](kpi.jsx), ```react): the column's width (w=), their own height (h= fixes it), drawn at scale=. */
161
+ .slide .component { display: block; position: relative; width: min(var(--box-w, 100%), 100%); margin: 0 auto .5em; zoom: var(--box-scale, 1); }
162
+ .slide .component[style*="--box-h"] { height: var(--box-h); }
163
+ .slide .component > script { display: none; }
164
+
154
165
  /* Text over a background image: light with a soft shadow in every theme (overrides theme colors and gradient text). */
155
166
  .slide.has-bg .slide-body :is(h1, h2, h3, h4, p, li, td, th, strong, em, a, blockquote, .eyebrow, .eyebrow-num, .eyebrow-title, .hl) {
156
167
  color: #fff !important; -webkit-text-fill-color: #fff; background-image: none !important; text-shadow: 0 2px 14px rgba(0, 0, 0, .5);
package/runtime/embed.js CHANGED
@@ -695,7 +695,7 @@
695
695
  // several lines, joined by \n). `html` puts it back as it was shown.
696
696
  function rawTarget(el, given) {
697
697
  if (!/^(P|H[1-6]|LI|TD|TH)$/.test(el.tagName) || el.classList.contains('slide-error-box') ||
698
- el.querySelector('img, video, ul, ol, pre, table, p, .mermaid')) return null;
698
+ el.querySelector('img, video, ul, ol, pre, table, p, .mermaid, .component')) return null;
699
699
  var cell = /^T[DH]$/.test(el.tagName) && el.closest('tr[data-src]');
700
700
  var src = parseSrc((cell || el).getAttribute('data-src'));
701
701
  if (!src) return null;
@@ -2739,6 +2739,8 @@
2739
2739
  i++;
2740
2740
  } else return;
2741
2741
  thumbs.appendChild(b);
2742
+ // A copy has no shadow roots: its components mount again (the runtime's, with the copy's colors).
2743
+ if (window.deckMountComponents && b.querySelector('.component')) window.deckMountComponents(b);
2742
2744
  });
2743
2745
  thumbs.scrollLeft = keep;
2744
2746
  markThumb();
@@ -4052,7 +4054,7 @@
4052
4054
  // A block of text, as textLines takes it (paragraphs and list items of several lines too).
4053
4055
  function cuttable(el) {
4054
4056
  var src = parseSrc(el.getAttribute('data-src'));
4055
- return !!src && /^(P|H[1-6]|LI)$/.test(el.tagName) && !el.querySelector('img, video, ul, ol, p, pre, table, .mermaid') &&
4057
+ return !!src && /^(P|H[1-6]|LI)$/.test(el.tagName) && !el.querySelector('img, video, ul, ol, p, pre, table, .mermaid, .component') &&
4056
4058
  (src.start === src.end ? !el.querySelector('br') : /^(P|LI)$/.test(el.tagName));
4057
4059
  }
4058
4060
  function deleteRange(r) {
@@ -119,6 +119,7 @@
119
119
  renderPresenter();
120
120
  renderEmbedBar();
121
121
  playVideos(i);
122
+ replayComponents(i);
122
123
  if (deck.classList.contains('is-overview')) slides[i].scrollIntoView({ block: 'nearest' });
123
124
  // For the access metrics `deck build` adds: page numbers as presented, from 1.
124
125
  var heading = slides[i].querySelector('h1, h2, h3');
@@ -629,6 +630,290 @@
629
630
  return diagramQueue;
630
631
  }
631
632
  var diagramsDone = renderDiagrams(Array.prototype.slice.call(stage.querySelectorAll('pre.mermaid:not([data-processed])')));
633
+
634
+ // Theme colors of one slide, for charts and components: `rgb(value)` resolves any CSS color (var(--deck-…),
635
+ // color-mix() of them) against the slide to rgb()/rgba(), through a canvas since derived tokens compute to oklch().
636
+ var THEME_TOKENS = ['--deck-series-1', '--deck-series-2', '--deck-series-3', '--deck-series-4', '--deck-series-5', '--deck-series-6',
637
+ '--deck-accent', '--deck-accent-2', '--deck-fg', '--deck-fg-muted', '--deck-line', '--deck-bg', '--deck-card', '--deck-ok', '--deck-warn'];
638
+ function slideColors(slide) {
639
+ var probe = document.createElement('span');
640
+ probe.style.display = 'none';
641
+ slide.appendChild(probe);
642
+ var pixel = document.createElement('canvas').getContext('2d', { willReadFrequently: true });
643
+ var cache = {};
644
+ function rgb(value) {
645
+ if (cache[value]) return cache[value];
646
+ probe.style.color = '';
647
+ probe.style.color = value;
648
+ var c = getComputedStyle(probe).color;
649
+ if (!/^rgba?\(/.test(c) && pixel) {
650
+ pixel.clearRect(0, 0, 1, 1);
651
+ pixel.fillStyle = c;
652
+ pixel.fillRect(0, 0, 1, 1);
653
+ var d = pixel.getImageData(0, 0, 1, 1).data;
654
+ c = d[3] === 255 ? 'rgb(' + d[0] + ', ' + d[1] + ', ' + d[2] + ')' : 'rgba(' + d[0] + ', ' + d[1] + ', ' + d[2] + ', ' + (d[3] / 255).toFixed(3) + ')';
655
+ }
656
+ return (cache[value] = c);
657
+ }
658
+ var cs = getComputedStyle(slide);
659
+ var t = {};
660
+ THEME_TOKENS.forEach(function (n) { t[n] = rgb('var(' + n + ')'); });
661
+ var bg = /(\d+)\D+(\d+)\D+(\d+)/.exec(t['--deck-bg']) || [0, 255, 255, 255];
662
+ var dark = (0.2126 * bg[1] + 0.7152 * bg[2] + 0.0722 * bg[3]) / 255 < 0.5;
663
+ var colors = {
664
+ rgb: rgb, tokens: t, dark: dark,
665
+ font: (cs.getPropertyValue('--deck-font-body') || cs.fontFamily || 'sans-serif').trim(),
666
+ done: function () { probe.remove(); },
667
+ };
668
+ return colors;
669
+ }
670
+
671
+ // ```chart: an ECharts option (compiled by `deck build` from the short form, src/charts.ts), drawn as SVG with the
672
+ // slide's theme: series colors, text, lines, and font. Strings in the option with var() or color-mix() resolve
673
+ // against the slide, and the drawing's colors point back at the tokens, so the `d` mode switch recolors it. As with
674
+ // Mermaid, `deck build` draws charts ahead of time in headless Chrome and inlines the SVG (data-processed); ECharts
675
+ // comes from a page-provided window.echarts (deck dev, check, pdf) or jsDelivr. A chart that fails records data-error.
676
+ var loadECharts = null, chartQueue = Promise.resolve();
677
+ function chartTheme(c) {
678
+ var t = c.tokens;
679
+ var axis = {
680
+ axisLine: { lineStyle: { color: t['--deck-line'], width: 1.5 } }, axisTick: { lineStyle: { color: t['--deck-line'] } },
681
+ axisLabel: { color: t['--deck-fg-muted'], fontSize: 17, fontFamily: c.font },
682
+ splitLine: { lineStyle: { color: t['--deck-line'], type: [4, 4] } },
683
+ nameTextStyle: { color: t['--deck-fg-muted'], fontSize: 16, fontFamily: c.font },
684
+ };
685
+ return {
686
+ color: [1, 2, 3, 4, 5, 6].map(function (n) { return t['--deck-series-' + n]; }),
687
+ backgroundColor: 'transparent',
688
+ textStyle: { color: t['--deck-fg'], fontFamily: c.font, fontSize: 17 },
689
+ title: { textStyle: { color: t['--deck-fg'], fontSize: 22, fontWeight: 700, fontFamily: c.font } },
690
+ legend: { textStyle: { color: t['--deck-fg'], fontSize: 17, fontFamily: c.font }, itemWidth: 18, itemHeight: 12 },
691
+ categoryAxis: axis, valueAxis: axis, logAxis: axis, timeAxis: axis,
692
+ radar: { axisName: { color: t['--deck-fg'], fontSize: 17 }, splitLine: { lineStyle: { color: t['--deck-line'] } }, splitArea: { show: false }, axisLine: { lineStyle: { color: t['--deck-line'] } } },
693
+ gauge: { title: { color: t['--deck-fg-muted'] }, detail: { color: t['--deck-fg'] } },
694
+ };
695
+ }
696
+ function resolveOption(value, c) {
697
+ if (typeof value === 'string') return /var\(|color-mix\(/.test(value) ? c.rgb(value) : value;
698
+ if (Array.isArray(value)) return value.map(function (v) { return resolveOption(v, c); });
699
+ if (value && typeof value === 'object') {
700
+ var out = {};
701
+ Object.keys(value).forEach(function (k) { out[k] = resolveOption(value[k], c); });
702
+ return out;
703
+ }
704
+ return value;
705
+ }
706
+ function renderCharts(plots) {
707
+ if (!plots.length) return Promise.resolve();
708
+ var fontsReady = document.fonts && document.fonts.ready ? document.fonts.ready : Promise.resolve();
709
+ loadECharts = loadECharts || (window.echarts ? Promise.resolve(window.echarts)
710
+ : import('https://cdn.jsdelivr.net/npm/echarts@6/dist/echarts.esm.min.mjs').then(function (m) { return m.default || m; }));
711
+ chartQueue = chartQueue.then(function () { return Promise.all([loadECharts, fontsReady]); }).then(function (r) {
712
+ var echarts = r[0];
713
+ plots.forEach(function (plot) {
714
+ var box = plot.parentNode, slide = box.closest('.slide');
715
+ if (!slide) return;
716
+ var c = slideColors(slide);
717
+ try {
718
+ var option = resolveOption(JSON.parse(box.querySelector('script[type="application/json"]').textContent), c);
719
+ option.animation = false;
720
+ var w = plot.clientWidth || 640, h = plot.clientHeight || 360;
721
+ // Server-side rendering mode draws at once, to a string (the DOM renderer paints on a later frame).
722
+ var chart = echarts.init(null, chartTheme(c), { renderer: 'svg', ssr: true, width: w, height: h });
723
+ chart.setOption(option);
724
+ plot.innerHTML = chart.renderToSVGString();
725
+ chart.dispose();
726
+ var svg = plot.querySelector('svg');
727
+ if (!svg) throw new Error('ECharts drew nothing');
728
+ svg.setAttribute('viewBox', '0 0 ' + w + ' ' + h);
729
+ svg.removeAttribute('width');
730
+ svg.removeAttribute('height');
731
+ svg.style.cssText = '';
732
+ // Colors that are theme tokens follow them (the `d` switch, a theme edit), with today's color as the fallback.
733
+ var tokenOf = {};
734
+ THEME_TOKENS.forEach(function (n) { var k = c.tokens[n].replace(/\s/g, ''); if (!tokenOf[k]) tokenOf[k] = n; });
735
+ svg.querySelectorAll('[fill], [stroke]').forEach(function (n) {
736
+ ['fill', 'stroke'].forEach(function (p) {
737
+ var v = n.getAttribute(p), k = v && tokenOf[v.replace(/\s/g, '')];
738
+ if (k) n.style.setProperty(p, 'var(' + k + ', ' + v + ')');
739
+ });
740
+ });
741
+ plot.setAttribute('data-processed', 'true');
742
+ plot.removeAttribute('data-error');
743
+ } catch (e) {
744
+ plot.setAttribute('data-error', (e && e.message) || String(e));
745
+ plot.textContent = 'Chart failed: ' + ((e && e.message) || e);
746
+ console.warn('treasure-deck: a chart failed', e);
747
+ } finally {
748
+ c.done();
749
+ }
750
+ });
751
+ }).catch(function (e) { console.warn('treasure-deck: ECharts failed to load', e); });
752
+ return chartQueue;
753
+ }
754
+ var chartsDone = renderCharts(Array.prototype.slice.call(stage.querySelectorAll('.chart > .chart-plot:not([data-processed])')));
755
+
756
+ // React components (`![](kpi.jsx)`, ```react; compiled by `deck build`, src/components.ts): each mounts in its own
757
+ // shadow root with Treasure Work's render_react contract, React's hooks and Recharts in scope, `data` from data=,
758
+ // `isDark` and `theme` from the slide's background, and `palette` with the slide's resolved theme colors. The
759
+ // Tailwind subset render_react ships is scoped to the shadow root, so its reset never touches the slide. React comes
760
+ // from window.__DECK_REACT__ (inlined by `deck build`, vendor/react/deck-react.js). A component that throws shows its
761
+ // error and records data-error. When its slide is shown it mounts again, so its charts animate in (unless the
762
+ // viewer prefers reduced motion, as `deck check` and `deck pdf` do).
763
+ var reactLib = null, reactSheet = null, mounted = [];
764
+ function reactOf() {
765
+ if (reactLib) return reactLib;
766
+ var lib = window.__DECK_REACT__;
767
+ try { if (!lib && window.opener) lib = window.opener.__DECK_REACT__; } catch (e) { /* cross-origin opener */ }
768
+ if (!lib) return null;
769
+ // @property rules don't apply inside a shadow root: Tailwind's are declared on the page instead.
770
+ var props = (lib.css.match(/@property[^{]+\{[^}]*\}/g) || []).join('\n');
771
+ if (props) { var st = document.createElement('style'); st.textContent = props; document.head.appendChild(st); }
772
+ try { reactSheet = new CSSStyleSheet(); reactSheet.replaceSync(lib.css); } catch (e) { reactSheet = null; }
773
+ return (reactLib = lib);
774
+ }
775
+ var factoryId = 0;
776
+ function componentFactory(code) {
777
+ // An inline script rather than eval, as render_react does (a page's CSP may forbid eval).
778
+ var key = '__deckComponent' + (++factoryId);
779
+ var R = reactOf();
780
+ var s = document.createElement('script');
781
+ s.textContent = 'window.' + key + ' = function (React, Recharts, isDark, theme, palette) {\n' +
782
+ 'const { ' + REACT_NAMES + ' } = React;\nconst { ' + Object.keys(R.Recharts).filter(function (n) { return /^[A-Z][\w$]*$/.test(n); }).join(', ') + ' } = Recharts;\n' +
783
+ 'return (function () {\n' + code + '\n})();\n};';
784
+ document.head.appendChild(s);
785
+ s.remove();
786
+ var f = window[key];
787
+ delete window[key];
788
+ if (typeof f !== 'function') throw new Error('the component did not load (a syntax error? see the console)');
789
+ return f;
790
+ }
791
+ var REACT_NAMES = 'useState, useEffect, useMemo, useCallback, useRef, useReducer, useContext, useLayoutEffect, useId, Fragment, createElement';
792
+ function mountComponents(hosts) {
793
+ var R = reactOf(), added = [];
794
+ hosts.forEach(function (host) {
795
+ if (host.shadowRoot || !host.closest('.slide')) return;
796
+ var root = host.attachShadow({ mode: 'open' });
797
+ if (!R) {
798
+ host.setAttribute('data-error', 'React is not loaded on this page');
799
+ root.innerHTML = '<div style="padding:12px;border:1px dashed currentColor;opacity:.6">React component: this page has no React (build it with deck build)</div>';
800
+ return;
801
+ }
802
+ if (reactSheet) root.adoptedStyleSheets = [reactSheet];
803
+ else { var st = document.createElement('style'); st.textContent = R.css; root.appendChild(st); }
804
+ var frame = document.createElement('div');
805
+ frame.className = 'deck-component-root';
806
+ root.appendChild(frame);
807
+ var scripts = host.querySelectorAll(':scope > script');
808
+ var entry = { host: host, frame: frame, code: scripts[0].textContent, data: JSON.parse(scripts[1].textContent || 'null'), round: 0 };
809
+ try {
810
+ entry.factory = componentFactory(entry.code);
811
+ } catch (e) {
812
+ failComponent(entry, e);
813
+ return;
814
+ }
815
+ entry.root = R.createRoot(frame);
816
+ mounted.push(entry);
817
+ added.push(entry);
818
+ renderComponent(entry);
819
+ });
820
+ return added;
821
+ }
822
+ var ERROR_STYLE = 'padding:12px 14px;border-radius:8px;border:1px solid #f87171;background:#fef2f2;color:#991b1b;font:14px/1.4 ui-monospace,monospace;white-space:pre-wrap';
823
+ function errorElement(React, message) {
824
+ return React.createElement('div', { ref: function (n) { if (n) n.style.cssText = ERROR_STYLE; } }, 'Component error: ' + message);
825
+ }
826
+ function failComponent(entry, e) {
827
+ var message = (e && e.message) || String(e);
828
+ entry.host.setAttribute('data-error', message);
829
+ console.warn('treasure-deck: a component failed', e);
830
+ if (entry.root) {
831
+ var React = reactLib.React;
832
+ reactLib.flushSync(function () { entry.root.render(errorElement(React, message)); });
833
+ return;
834
+ }
835
+ var box = document.createElement('div');
836
+ box.style.cssText = ERROR_STYLE;
837
+ box.textContent = 'Component error: ' + message;
838
+ entry.frame.appendChild(box);
839
+ }
840
+ function renderComponent(entry) {
841
+ var R = reactLib, React = R.React;
842
+ var slide = entry.host.closest('.slide');
843
+ if (!slide) return;
844
+ var c = slideColors(slide);
845
+ c.done();
846
+ var t = c.tokens;
847
+ var palette = {
848
+ series: [1, 2, 3, 4, 5, 6].map(function (n) { return t['--deck-series-' + n]; }),
849
+ accent: t['--deck-accent'], accent2: t['--deck-accent-2'], fg: t['--deck-fg'], muted: t['--deck-fg-muted'],
850
+ line: t['--deck-line'], card: t['--deck-card'], bg: t['--deck-bg'], ok: t['--deck-ok'], warn: t['--deck-warn'], font: c.font,
851
+ };
852
+ var mode = c.dark ? 'dark' : 'light';
853
+ entry.frame.classList.toggle('dark', c.dark);
854
+ entry.host.removeAttribute('data-error');
855
+ var Component;
856
+ try {
857
+ if (entry.mode !== mode || !entry.Component) entry.Component = entry.factory(React, R.Recharts, c.dark, mode, palette);
858
+ Component = entry.Component;
859
+ if (typeof Component !== 'function') throw new Error('the code must export a component: export default function Name({ data }) { ... }');
860
+ } catch (e) {
861
+ failComponent(entry, e);
862
+ return;
863
+ }
864
+ entry.mode = mode;
865
+ function Boundary(props) { React.Component.call(this, props); this.state = { error: null }; }
866
+ Boundary.prototype = Object.create(React.Component.prototype);
867
+ Boundary.prototype.constructor = Boundary;
868
+ Boundary.getDerivedStateFromError = function (error) { return { error: error }; };
869
+ Boundary.prototype.componentDidCatch = function (error) {
870
+ entry.host.setAttribute('data-error', (error && error.message) || String(error));
871
+ console.warn('treasure-deck: a component failed', error);
872
+ };
873
+ Boundary.prototype.render = function () {
874
+ var error = this.state.error;
875
+ return error ? errorElement(React, (error && error.message) || String(error)) : this.props.children;
876
+ };
877
+ R.flushSync(function () {
878
+ entry.root.render(React.createElement(Boundary, { key: entry.round },
879
+ React.createElement(Component, { data: entry.data, isDark: c.dark, theme: mode, palette: palette })));
880
+ });
881
+ }
882
+ // Resolves once the components' DOM has been quiet for a moment (Recharts draws after measuring its container).
883
+ function componentsSettled(entries) {
884
+ if (!entries.length) return Promise.resolve();
885
+ return new Promise(function (resolve) {
886
+ var timer = null, start = Date.now();
887
+ var observer = new MutationObserver(function () { kick(); });
888
+ entries.forEach(function (e) { observer.observe(e.frame, { childList: true, subtree: true, attributes: true, characterData: true }); });
889
+ function kick() {
890
+ clearTimeout(timer);
891
+ timer = setTimeout(function () { observer.disconnect(); resolve(); }, Date.now() - start > 4000 ? 0 : 200);
892
+ }
893
+ kick();
894
+ });
895
+ }
896
+ var reducedMotion = window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches;
897
+ function replayComponents(i) {
898
+ if (!mounted || presenter || reducedMotion || deck.classList.contains('is-overview')) return;
899
+ mounted.forEach(function (entry) {
900
+ if (entry.host.closest('.slide') !== slides[i] || !entry.Component) return;
901
+ entry.round++;
902
+ renderComponent(entry);
903
+ });
904
+ }
905
+ // The deck's mode switched (`d`): components on slides whose background changed render again with isDark.
906
+ function refreshComponents() {
907
+ if (!mounted) return;
908
+ mounted = mounted.filter(function (entry) { if (entry.host.isConnected) return true; if (entry.root) entry.root.unmount(); return false; });
909
+ mounted.forEach(function (entry) { if (entry.Component) renderComponent(entry); });
910
+ }
911
+ function componentHosts(root) { return Array.prototype.slice.call(root.querySelectorAll('.slide .component')); }
912
+ var componentsDone = componentsSettled(mountComponents(componentHosts(stage)));
913
+ // The editor's thumbnails are copies of the slides: it mounts their components with this.
914
+ window.deckMountComponents = function (root) {
915
+ return componentsSettled(mountComponents(Array.prototype.slice.call(root.querySelectorAll('.component'))));
916
+ };
632
917
  // Code blocks whose longest line is wider than their panel (a long line, or a column narrowed by the table of
633
918
  // contents sidebar) shrink their font just enough to fit, down to 12px, instead of clipping. Blocks that fit
634
919
  // keep the theme's size. Runs once fonts are ready and again whenever the sidebar is toggled.
@@ -688,7 +973,7 @@
688
973
  }
689
974
  window.addEventListener('beforeprint', function () { measureTableHeads(); });
690
975
  // Resolves once fonts and diagrams are rendered; `deck pdf` waits on it before printing.
691
- window.deckReady = Promise.all([document.fonts ? document.fonts.ready : null, diagramsDone]).then(function () {
976
+ window.deckReady = Promise.all([document.fonts ? document.fonts.ready : null, diagramsDone, chartsDone, componentsDone]).then(function () {
692
977
  fitSlides();
693
978
  fitCode();
694
979
  measureTableHeads();
@@ -698,9 +983,12 @@
698
983
  // window.deckUpdated resolves once they are.
699
984
  document.addEventListener('deck:slides-updated', function (e) {
700
985
  var changed = e.detail.slides;
701
- window.deckUpdated = renderDiagrams(changed.reduce(function (all, s) {
986
+ var plots = changed.reduce(function (all, s) { return all.concat(Array.prototype.slice.call(s.querySelectorAll('.chart > .chart-plot:not([data-processed])'))); }, []);
987
+ mounted = mounted.filter(function (entry) { if (entry.host.isConnected) return true; entry.root.unmount(); return false; });
988
+ var added = mountComponents(changed.reduce(function (all, s) { return all.concat(Array.prototype.slice.call(s.querySelectorAll('.component'))); }, []));
989
+ window.deckUpdated = Promise.all([renderDiagrams(changed.reduce(function (all, s) {
702
990
  return all.concat(Array.prototype.slice.call(s.querySelectorAll('pre.mermaid:not([data-processed])')));
703
- }, [])).then(function () {
991
+ }, [])), renderCharts(plots), componentsSettled(added)]).then(function () {
704
992
  fitSlides(changed);
705
993
  changed.forEach(function (s) { fitCode(s); measureTableHeads(s); });
706
994
  return true;
@@ -738,6 +1026,7 @@
738
1026
  function setMode(mode, fromPeer) {
739
1027
  deck.setAttribute('data-mode', mode);
740
1028
  if (!fromPeer) sync({ mode: mode });
1029
+ refreshComponents();
741
1030
  renderPresenter();
742
1031
  }
743
1032
  // An embed is a reader's copy: it neither steers nor follows a talk being presented from the same deck.
@@ -132,6 +132,12 @@ Reach for `nowrap` on short label, number, and unit columns that break awkwardly
132
132
  - A `mermaid` fence draws a diagram colored by the theme. Give a node a role with `A[Label]:::accent` (also `:::dark`, `:::muted`, `:::light`). Size it on the fence line: `mermaid {w=60%}` (canvas px or % of the column) or `mermaid {h=300}`.
133
133
  - A diagram scales to its column's width, so its text shrinks with it. Keep it to about 5–6 nodes with one-to-three-word labels. Use `flowchart TB` in a column, and `LR` only for a short chain (3–4 nodes) or a full-width slide. `deck check` warns when labels render below 13px.
134
134
 
135
+ ### Charts and components
136
+
137
+ - A `chart` fence draws a chart in the theme's colors. Short form: `type:` (`bar`, `line`, `area`, `pie`, `donut`, `scatter`, `funnel`, `gauge`, `radar`, `treemap`, `sankey`, `horizontal-bar`, `stacked-bar`), `x: [categories]`, `series: {Name: [values]}` (or one list), or `data: file.csv` (first column the categories); a `sankey` takes `links: [[from, to, value], ...]` by name. Options: `stack: true`, `horizontal: true`, `labels: true`, `highlight: Q4` (that bar in the accent, the rest muted), `prefix: "$"`, `unit: M`, `min`/`max`, and for a gauge `value:` and `name:`. `render_chart`'s arguments (`labels`, `datasets`, `x_axis_title`, `nodes`/`links`, `treemap_data`) work as written, so a chart from chat can be pasted in; `x_axis_title`/`y_axis_title` name the axes in the short form too. A block without `type:` is an ECharts option as is. Size: `chart {h=300}` or `{w=60%}`; the default is the column's width at 16:9, at most 440px tall.
138
+ - A React component goes on a slide as `![Alt](kpi.jsx){data=kpi.json}`, or inline as a `react` fence: the `render_react` format (`export default function Name({ data })`, React hooks, Recharts components, and Tailwind classes in scope, no imports). It also gets `isDark` and `palette` (the slide's theme colors: `palette.accent`, `palette.series[0..5]`, `palette.fg`, `palette.muted`, `palette.line`, `palette.card`): use them instead of hard-coded hex colors so the component matches the theme. `scale=0.8` shrinks a dashboard designed for a bigger screen; `h=` fixes its height.
139
+ - Prefer a `chart` for a single chart (static, small, crisp in PDF). Reach for a component for a KPI row with a chart, an interactive view, or a dashboard the user already made with `render_react`.
140
+
135
141
  ### Classes
136
142
 
137
143
  - Blocks: `{.lead}` (the key sentence, 1.2× body size), `{.muted}`, `{.small}` (sources, footnotes), `{.center}` and `{.right}` (horizontal alignment only), `{.subtitle}` and `{.meta}` (title slides; under a columns slide's heading, a `{.subtitle}` spans all columns), `{.callout}`, `{.note}`, `{.warn}` (boxed asides).
@@ -286,6 +292,46 @@ Text over the photo.{.lead}
286
292
  flowchart LR
287
293
  A[Source]:::accent --> B[Build] --> C[Publish]
288
294
  ```
295
+
296
+ --- columns 2:3
297
+
298
+ # Revenue grew 40% in Q4
299
+
300
+ - **Enterprise** drove most of it
301
+ - Margins held at 31%
302
+
303
+ === col
304
+
305
+ ```chart
306
+ type: bar
307
+ x: [Q1, Q2, Q3, Q4]
308
+ series:
309
+ Revenue: [12, 18, 25, 35]
310
+ highlight: Q4
311
+ labels: true
312
+ prefix: "$"
313
+ unit: M
314
+ ```
315
+
316
+ ---
317
+
318
+ # Q3 at a glance
319
+
320
+ ```react
321
+ export default function KPIs() {
322
+ const kpis = [['ARR', '$42M'], ['Net retention', '128%'], ['Customers', '312']];
323
+ return (
324
+ <div className="grid grid-cols-3 gap-6">
325
+ {kpis.map(([label, value]) => (
326
+ <div key={label} className="p-6 rounded-xl" style={{ background: palette.card }}>
327
+ <div className="text-4xl font-bold" style={{ color: palette.accent }}>{value}</div>
328
+ <div style={{ color: palette.muted }}>{label}</div>
329
+ </div>
330
+ ))}
331
+ </div>
332
+ );
333
+ }
334
+ ```
289
335
  ````
290
336
 
291
337
  ## House style
@@ -296,6 +342,7 @@ The canvas is 1280×720 with 21–22px body text, so slides hold real content
296
342
  - **One idea per slide.** If a slide needs two titles, it's two slides.
297
343
  - **Bullets are short statements**, 5–6 at most, one line each where possible; start with the bolded key phrase (`- **Strict** — typos fail the build`). Nest at most one level.
298
344
  - **Use columns for comparison and for text + evidence** (claim on the left, code/table/image on the right) — `--- columns 3:2` or `1:1`. Cards (`### Heading` columns) suit 2–4 parallel options.
345
+ - **Show the number.** A claim about data ("Q4 revenue grew 40%") gets a chart beside it, not a bullet restating it: the title says the point, the chart is the evidence, and `highlight:` marks the bar the slide is about. A slide of three or four headline numbers is a KPI row (a small component, or `### $42M` cards in columns).
299
346
  - **Prefer a table** over bullets when items share attributes; prefer a Mermaid diagram over a bullet list describing a flow. Right-align number columns (`--:`) and keep them, and short labels, on one line with `{nowrap}` on the header cell; give a long text column a `{w=…%}` so it takes the wrapping.
300
347
  - **Fill the slide, or make it a statement.** Two bullets under a title leave most of the canvas empty. Merge the slide with a neighbor, add the evidence (a table, diagram, code, or image beside the text in columns), or make it a deliberate one-line statement with `.lead`.
301
348
  - **One `.lead` sentence** per slide at most, for the takeaway; `.muted` for context the speaker will say aloud anyway.