@keyfunc/keybricks-ds 2.5.0 → 2.5.1

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 (60) hide show
  1. package/DEPLOY.md +3 -3
  2. package/INTEGRATION.md +12 -1
  3. package/_adherence.oxlintrc.json +10 -4
  4. package/_ds_bundle.js +20559 -0
  5. package/_src/icon-index.js +1 -0
  6. package/_src/unicons-index.js +1 -0
  7. package/_src/usage-code.js +737 -0
  8. package/changelog.js +7 -0
  9. package/components/charts/BarList.jsx +1 -1
  10. package/components/charts/BarList.vue +8 -3
  11. package/components/charts/Ribbon3D.d.ts +2 -0
  12. package/components/charts/Scatter3D.d.ts +4 -0
  13. package/components/charts/SunburstChart.jsx +6 -1
  14. package/components/charts/SunburstChart.vue +7 -1
  15. package/components/charts/Surface3D.d.ts +2 -0
  16. package/components/charts/WorldMap.jsx +6 -1
  17. package/components/charts/WorldMap.vue +7 -1
  18. package/components/data/Table.jsx +1 -1
  19. package/components/data/Table.vue +1 -1
  20. package/components/display/ProgressBar.jsx +1 -1
  21. package/components/display/ProgressBar.vue +1 -1
  22. package/components/feedback/Accordion.jsx +1 -1
  23. package/components/feedback/Accordion.vue +1 -1
  24. package/components/feedback/ContextMenu.jsx +3 -3
  25. package/components/feedback/ContextMenu.vue +4 -4
  26. package/components/feedback/Drawer.jsx +3 -3
  27. package/components/feedback/Drawer.vue +3 -3
  28. package/components/forms/Checkbox.d.ts +2 -0
  29. package/components/forms/Checkbox.jsx +9 -4
  30. package/components/forms/Checkbox.vue +6 -2
  31. package/components/forms/DatePicker.jsx +3 -1
  32. package/components/forms/DatePicker.vue +2 -1
  33. package/components/forms/Dropzone.jsx +1 -1
  34. package/components/forms/Dropzone.vue +1 -1
  35. package/components/forms/MultiSelect.jsx +5 -3
  36. package/components/forms/MultiSelect.vue +4 -3
  37. package/components/forms/Slider.jsx +1 -1
  38. package/components/forms/Slider.vue +1 -1
  39. package/components/forms/Switch.jsx +4 -4
  40. package/components/forms/Switch.vue +4 -4
  41. package/components/navigation/Sidebar.jsx +2 -2
  42. package/components/navigation/Sidebar.vue +2 -2
  43. package/components/navigation/TopBar.jsx +1 -1
  44. package/components/navigation/TopBar.vue +1 -1
  45. package/components/navigation/Tree.jsx +2 -2
  46. package/components/navigation/Tree.vue +8 -5
  47. package/components/pipeline/DataPreview.jsx +1 -1
  48. package/components/pipeline/DataPreview.vue +1 -1
  49. package/components/pipeline/NodeCard.jsx +1 -1
  50. package/components/pipeline/NodeCard.vue +1 -1
  51. package/components/pipeline/PaletteItem.vue +1 -1
  52. package/components/pipeline/PalettePanel.jsx +3 -3
  53. package/components/pipeline/PalettePanel.vue +2 -2
  54. package/components/tabs/SegmentedControl.jsx +2 -2
  55. package/components/tabs/SegmentedControl.vue +2 -2
  56. package/index.html +1 -1
  57. package/package.json +4 -2
  58. package/tokens/dark.css +1 -1
  59. package/tokens/interaction.css +4 -0
  60. package/tokens/layout.css +3 -0
@@ -0,0 +1,737 @@
1
+ /* Usage code for component cards — the "Show code" bar under each example, like Element UI's demos.
2
+ It reads the card's live React tree (fibers), finds the outermost design-system component instances, groups them by the
3
+ example block they sit in, and prints the code that builds that example: React (JSX) and Vue 3 (SFC), each with its import from
4
+ the package entry ('@keyfunc/keybricks-ds' / '@keyfunc/keybricks-ds/vue'). Code is generated when the bar opens, from the props
5
+ the components have at that moment, so it always matches what is on screen. Loaded on demand by view-source.js; lives in _src/
6
+ so it stays out of _ds_bundle.js. */
7
+ (function () {
8
+ if (window.KBUsage) return;
9
+ var NSN = 'KeybricksDesignSystem_71231a';
10
+ var VUE = new Set('ActionChip,Button,ButtonGroup,IconButton,Bar3D,BarChart,BarList,BoxPlot,BulletChart,CandlestickChart,ChartLegend,ChartTooltip,ChordChart,DonutChart,FunnelChart,GanttChart,GaugeChart,HeatmapChart,Histogram,LineChart,ParetoChart,Pie3D,PlotGrid,RadarChart,Ribbon3D,SankeyChart,Scatter3D,ScatterChart,Sparkline,SunburstChart,Surface3D,TreemapChart,WaterfallChart,WorldMap,XLabels,CodeBlock,DiffValue,FilterBar,KeyValue,KeyValueList,ListRow,Pagination,SmartTable,Spreadsheet,Table,AreaChart,Avatar,AvatarGroup,Badge,Card,Divider,Donut,IconTile,Kbd,MiniBars,ProgressBar,StatCard,StatusBadge,Tag,Accordion,ActivityItem,Alert,Banner,ContextMenu,DotActivity,Drawer,EmptyState,LogViewer,Menu,Modal,Skeleton,Spinner,Stepper,Timeline,Toast,ToastStack,Tooltip,Checkbox,Combobox,DatePicker,Dropzone,Field,Input,MultiSelect,NumberStepper,Radio,RadioGroup,RelativeTimePicker,SearchInput,Select,Slider,Switch,Textarea,Icon,Lucide,Unicon,Breadcrumb,DocTree,PageHeading,PageToolbar,SidePanel,Sidebar,ThemeToggle,TopBar,Tree,UserMenu,ConfigPanel,DataPreview,NodeCard,PaletteItem,PaletteListItem,PalettePanel,PipelineCanvas,Port,PortLabel,ZoomControls,CountBadge,PanelTabs,PillTabs,SegmentedControl,Tabs,ViewToggle'.split(','));
11
+ var L = {
12
+ show: ['Show code', '显示代码', 'コードを表示'], hide: ['Hide code', '隐藏代码', 'コードを隠す'],
13
+ copy: ['Copy', '复制', 'コピー'], copied: ['Copied', '已复制', 'コピー済み'],
14
+ novue: ['This example uses components that have no Vue version yet: ', '此示例用到的组件暂无 Vue 版本:', 'この例のコンポーネントには Vue 版がまだありません:'],
15
+ example: ['Example', '示例', '例'], tiers: ['Size tiers — the control inherits data-size from its region', '尺寸档位 — 控件继承所在区域的 data-size', 'サイズ段階 — コントロールは領域の data-size を継承']
16
+ };
17
+ var lang = 'en', fw = 'react';
18
+ try { fw = localStorage.getItem('kb-code-fw') === 'vue' ? 'vue' : 'react'; } catch (e) {}
19
+ function tr(k) { var v = L[k]; return lang === 'zh' ? v[1] : lang === 'ja' ? v[2] : lang === 'both' ? v[0] + ' · ' + v[1] : v[0]; }
20
+ var bars = [];
21
+ window.addEventListener('message', function (e) { var m = e.data; if (m && m.kb === 'lang' && m.lang && m.lang !== lang) { lang = m.lang; bars.forEach(function (b) { b.paint(); }); } });
22
+
23
+ /* ---------- component names ---------- */
24
+ var names = new Map();
25
+ function buildNames() { var ns = window[NSN] || {}; Object.keys(ns).forEach(function (k) { var v = ns[k]; if (/^[A-Z]/.test(k) && v && (typeof v === 'function' || typeof v === 'object') && !names.has(v)) names.set(v, k); }); }
26
+ function dsName(t) { return t && names.has(t) ? names.get(t) : null; }
27
+ var VALUE_KEYS = { value: 1, checked: 1, selected: 1, open: 1, active: 1, page: 1, activeKey: 1, current: 1, expanded: 1, tab: 1, values: 1, date: 1, query: 1 };
28
+
29
+ /* ---------- fiber walk ---------- */
30
+ /* The container keeps the first HostRoot fiber; the live tree hangs off its FiberRoot's current. */
31
+ function rootFiber(el) { var k = Object.keys(el).find(function (k) { return k.indexOf('__reactContainer$') === 0; }); if (!k) return null; var hr = el[k]; return hr.stateNode && hr.stateNode.current ? hr.stateNode.current : hr; }
32
+ function collect(f, out, live) {
33
+ for (; f; f = f.sibling) {
34
+ var n = dsName(f.elementType) || dsName(f.type);
35
+ if (n) { out.push({ fiber: f, name: n, live: live }); continue; }
36
+ collect(f.child, out, f.type && f.type === window.KBLive ? f : live);
37
+ }
38
+ }
39
+ function domOf(f) { if (f.stateNode && f.stateNode.nodeType === 1) return f.stateNode; for (var c = f.child; c; c = c.sibling) { var d = domOf(c); if (d) return d; } return null; }
40
+ function isRow(el) { var cs = getComputedStyle(el); return (cs.display === 'flex' || cs.display === 'inline-flex') && cs.flexDirection.indexOf('row') === 0; }
41
+ function isFlow(el) { var cs = getComputedStyle(el); return cs.display === 'block' || cs.display === 'flow-root' || ((cs.display === 'flex' || cs.display === 'inline-flex') && cs.flexDirection.indexOf('column') === 0); }
42
+ /* Where an example's bar goes: the nearest block that flows top-to-bottom, or the section (.kb-sec / .sec / .case / section) holding it. */
43
+ function place(el, root) {
44
+ var tiers = el.closest('.kb-tiers');
45
+ var rowNode = tiers || (el.parentElement && el.parentElement !== root && isRow(el.parentElement) ? el.parentElement : el);
46
+ var node = rowNode;
47
+ while (node.parentElement && node.parentElement !== root && root.contains(node.parentElement) && !isFlow(node.parentElement)) node = node.parentElement;
48
+ var sec = node.closest('.kb-sec,.sec,.case,section');
49
+ var anchor = node, mode = 'after';
50
+ if (sec && sec !== root && root.contains(sec)) { anchor = sec; mode = 'append'; }
51
+ /* The bar needs a full-width line of its own: never inside a horizontal row, a multi-column grid or a narrow cell.
52
+ Climb until the box it lands in is a single column at least 320px wide; examples sharing that box share one bar. */
53
+ for (var g = 0; g < 10; g++) {
54
+ if (mode === 'append') { if (flexRow(anchor) || anchor.getBoundingClientRect().width < 280) { mode = 'after'; continue; } break; }
55
+ var box = anchor.parentElement;
56
+ if (!box || box === root.parentElement || (box !== root && !root.contains(box))) break;
57
+ var bw = box.getBoundingClientRect().width, aw = anchor.getBoundingClientRect().width;
58
+ /* One of several cells side by side in a grid: the bar goes under that grid row, after its last cell, spanning the row —
59
+ cells on the same row share it. (A label | content row is not side by side: its content cell keeps its own bar.) */
60
+ if (gridCols(box) > 1 && aw < bw * 0.6) {
61
+ var top = anchor.getBoundingClientRect().top, last = anchor;
62
+ for (var s = anchor.nextElementSibling; s; s = s.nextElementSibling) { if (s.hasAttribute('data-kb-code')) continue; if (Math.abs(s.getBoundingClientRect().top - top) < 4) last = s; else break; }
63
+ anchor = last; break;
64
+ }
65
+ /* out of a horizontal row or a narrow box */
66
+ if (!(flexRow(box) || (box !== root && bw < 280)) || box === root) break;
67
+ anchor = box;
68
+ }
69
+ return { anchor: anchor, mode: mode, row: rowNode, tiers: tiers };
70
+ }
71
+ function flexRow(el) { var cs = getComputedStyle(el); return (cs.display === 'flex' || cs.display === 'inline-flex') && cs.flexDirection.indexOf('row') === 0; }
72
+ function gridCols(el) { var cs = getComputedStyle(el); return cs.display.indexOf('grid') >= 0 ? cs.gridTemplateColumns.split(' ').filter(Boolean).length : 0; }
73
+ var LABEL = '.lbl,.k,.kb-k,.kb-h,.kb-th,h3,h4,.cap,.hint';
74
+ function labelFor(u, stop) {
75
+ if (u.name === 'Field' && typeof u.props.label === 'string') return u.props.label;
76
+ for (var n = u.row; n && n !== stop.parentElement; n = n.parentElement) {
77
+ for (var s = n.previousElementSibling; s; s = s.previousElementSibling) {
78
+ if (s.matches && s.matches(LABEL)) return s.textContent.trim();
79
+ if (s.querySelector && s.closest('[data-kb-code]') == null) { var q = s.matches('div,span') && s.children.length < 3 ? s.querySelector(LABEL) : null; if (q) return q.textContent.trim(); }
80
+ break;
81
+ }
82
+ if (n === stop) break;
83
+ }
84
+ var first = stop.querySelector && stop.querySelector(LABEL); return first ? first.textContent.trim() : '';
85
+ }
86
+ function scan(root) {
87
+ buildNames();
88
+ var rf = rootFiber(root), units = [];
89
+ if (!rf) return units;
90
+ collect(rf.child || rf, units, null);
91
+ units.forEach(function (u) { u.el = domOf(u.fiber); u.props = u.fiber.memoizedProps || {}; if (u.el && root.contains(u.el) && !u.el.closest('[data-kb-code]')) { var p = place(u.el, root); u.anchor = p.anchor; u.mode = p.mode; u.row = p.row; u.tiers = p.tiers; } });
92
+ /* A fixed overlay (ToastStack, a floating panel) belongs to the example that opens it: the previous unit on the page. */
93
+ var prev = null;
94
+ units.forEach(function (u) {
95
+ if (!u.anchor) return;
96
+ if (getComputedStyle(u.el).position === 'fixed') { if (prev) { u.anchor = prev.anchor; u.mode = prev.mode; u.row = prev.row; u.tiers = prev.tiers; u.fixed = true; } }
97
+ else prev = u;
98
+ });
99
+ return units.filter(function (u) { return u.anchor; });
100
+ }
101
+
102
+ /* ---------- printing ---------- */
103
+ var IDENT = /^[A-Za-z_$][\w$]*$/;
104
+ function q(s) { return "'" + String(s).replace(/\\/g, '\\\\').replace(/'/g, "\\'").replace(/\n/g, '\\n') + "'"; }
105
+ function kebab(k) { return k.replace(/[A-Z]/g, function (m) { return '-' + m.toLowerCase(); }); }
106
+ function isEl(v) { return v && typeof v === 'object' && v.$$typeof && v.props !== undefined; }
107
+ /* The card's authored JSX: dev React keeps each element's source position (_source / _debugSource), so an attribute's
108
+ expression can be printed exactly as written — arrows, spreads and JSX intact, not Babel's ES5 output. */
109
+ var SRC = null;
110
+ function srcText() { if (SRC == null) { var s = document.querySelector('script[type="text/babel"]'); SRC = s ? s.textContent : ''; } return SRC; }
111
+ function offsetOf(pos) { var s = srcText(); if (!s || !pos || !pos.lineNumber) return -1; var i = 0; for (var l = 1; l < pos.lineNumber; l++) { i = s.indexOf('\n', i); if (i < 0) return -1; i++; } i += Math.max(0, (pos.columnNumber || 1) - 1); var j = s.indexOf('<', i); return j >= 0 && j - i < 4 ? j : s.lastIndexOf('<', i + 1); }
112
+ function balanced(s, i) { var d = 0, q = null; for (var k = i; k < s.length; k++) { var c = s[k]; if (q) { if (c === '\\') { k++; continue; } if (c === q) q = null; continue; } if (c === '"' || c === "'" || c === '`') { q = c; continue; } if (c === '{') d++; else if (c === '}') { d--; if (!d) return k; } } return -1; }
113
+ function attrSrc(pos) {
114
+ var s = srcText(), i = offsetOf(pos), out = {}; if (i < 0) return out;
115
+ var k = i + 1; while (k < s.length && /[\w.$]/.test(s[k])) k++;
116
+ while (k < s.length) {
117
+ while (/\s/.test(s[k])) k++;
118
+ if (s[k] === '>' || (s[k] === '/' && s[k + 1] === '>')) break;
119
+ var m = /^([\w$-]+)/.exec(s.slice(k, k + 60)); if (!m) { if (s[k] === '{') { var e0 = balanced(s, k); if (e0 < 0) break; k = e0 + 1; continue; } break; }
120
+ k += m[1].length; while (/\s/.test(s[k])) k++;
121
+ if (s[k] !== '=') continue; k++; while (/\s/.test(s[k])) k++;
122
+ if (s[k] === '{') { var e = balanced(s, k); if (e < 0) break; out[m[1]] = s.slice(k + 1, e).trim(); k = e + 1; }
123
+ else if (s[k] === '"' || s[k] === "'") { var e2 = s.indexOf(s[k], k + 1); k = e2 + 1; } else break;
124
+ }
125
+ return out;
126
+ }
127
+ var TOP = null;
128
+ function topConsts() {
129
+ if (TOP) return TOP; TOP = {}; var s = srcText(), re = /^const\s+([A-Za-z_$][\w$]*)\s*=\s*/gm, m;
130
+ while ((m = re.exec(s))) {
131
+ var i = re.lastIndex, d = 0, q = null, k = i;
132
+ for (; k < s.length; k++) { var c = s[k]; if (q) { if (c === '\\') { k++; continue; } if (c === q) q = null; continue; } if (c === '"' || c === "'" || c === '`') { q = c; continue; } if ('([{'.indexOf(c) >= 0) d++; else if (')]}'.indexOf(c) >= 0) d--; else if (d === 0 && (c === ';' || (c === '\n' && /^\S/.test(s.slice(k + 1, k + 2)) && !/^[.?:+\-*|&]/.test(s.slice(k + 1, k + 2))))) break; }
133
+ TOP[m[1]] = s.slice(i, k).trim();
134
+ }
135
+ return TOP;
136
+ }
137
+ /* A prop written as a card constant (columns={CFG}) is printed as that constant, as authored, with the constants it uses. */
138
+ function useConst(name, S) { var tx = topConsts()[name] || ((defOf(name) || '').replace(/^const\s+[\w$]+\s*=\s*/, '')); if (!tx || /^(window|React)\b/.test(tx)) return false; pullOne(name, S); return S.consts.some(function (c) { return c.name === name; }) || S.helpers.some(function (h) { return h.name === name; }); }
139
+ /* End of an expression starting at i: the first ; or line break at bracket depth 0 (not inside a string). */
140
+ function exprEnd(s, i) { var d = 0, q = null, k = i; for (; k < s.length; k++) { var c = s[k]; if (q) { if (c === '\\') { k++; continue; } if (c === q) q = null; continue; } if (c === '"' || c === "'" || c === '`') { q = c; continue; } if ('([{'.indexOf(c) >= 0) d++; else if (')]}'.indexOf(c) >= 0) { d--; if (d < 0) return k; } else if (d === 0 && (c === ';' || (c === '\n' && !/^\s*[.?:+\-*|&]/.test(s.slice(k + 1, k + 40))))) return k; } return k; }
141
+ function defOf(id) {
142
+ var s = srcText(), m = new RegExp('(?:const|let|var)\\s+' + id + '\\s*=\\s*').exec(s);
143
+ if (m) return 'const ' + id + ' = ' + s.slice(m.index + m[0].length, exprEnd(s, m.index + m[0].length)).trim();
144
+ m = new RegExp('function\\s+' + id + '\\s*\\(').exec(s);
145
+ if (m) { var b = s.indexOf('{', m.index), e = balanced(s, b); if (e > 0) return s.slice(m.index, e + 1); }
146
+ return null;
147
+ }
148
+ function stateSrc(name) { var m = new RegExp('\\[\\s*' + name + '\\s*,\\s*([\\w$]+)\\s*\\]\\s*=\\s*(?:React\\.)?useState\\(').exec(srcText()); if (!m) return null; var i = m.index + m[0].length; return { set: m[1], init: srcText().slice(i, exprEnd(srcText(), i)).trim() }; }
149
+ function setterSrc(set) { var m = new RegExp('\\[\\s*([\\w$]+)\\s*,\\s*' + set + '\\s*\\]\\s*=\\s*(?:React\\.)?useState\\(').exec(srcText()); if (!m) return null; var i = m.index + m[0].length; return { name: m[1], init: srcText().slice(i, exprEnd(srcText(), i)).trim() }; }
150
+ var GLOBALS = /^(Math|JSON|console|setTimeout|clearTimeout|setInterval|Date|Array|Object|String|Number|Boolean|Promise|window|document|React|alert|parseInt|parseFloat|isNaN|Set|Map|if|for|while|switch|return|function|typeof|new|catch)$/;
151
+ /* Card-local functions and values a printed snippet calls (notify(…), fmt(…)) are copied in, so the snippet runs on its own. */
152
+ function idsIn(text) {
153
+ text = text.replace(/\.\.\./g, ' '); /* a spread (...RUNS) names RUNS; it is not a property access */
154
+ text = text.replace(/`(?:[^`\\]|\\.)*`|"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'/g, '""'); /* words inside strings ("Detail Sheet") are not names */
155
+ /* Names the text uses, minus what it declares itself (params, locals) and property names after a dot. */
156
+ var local = new Set();
157
+ (text.match(/(?:const|let|var)\s+([\w$]+)/g) || []).forEach(function (m) { local.add(m.split(/\s+/)[1]); });
158
+ (text.match(/\(([^()]*)\)\s*=>/g) || []).forEach(function (m) { m.slice(1, m.indexOf(')')).split(',').forEach(function (p) { p = p.replace(/[{}\[\]=].*$/, '').trim(); if (p) local.add(p); }); });
159
+ (text.match(/\b([\w$]+)\s*=>/g) || []).forEach(function (m) { local.add(m.replace(/\s*=>/, '')); });
160
+ var ids = []; text.replace(/(^|[^.\w$'"])([A-Za-z_$][\w$]*)/g, function (all, pre, id) { if (!local.has(id) && ids.indexOf(id) < 0) ids.push(id); return all; });
161
+ return ids;
162
+ }
163
+ /* Names an authored expression needs from outside: strings and JSX text removed; object keys and JSX attribute names are not names. */
164
+ function freeIds(ex) {
165
+ var s = ex.replace(/`(?:[^`\\]|\\.)*`|"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'/g, '""').replace(/>([^<>{}]*)</g, '><');
166
+ /* JSX tags: keep the tag name and the {expressions} in its attributes; attribute names (muted, label=…) are not names. */
167
+ var o = '', k = 0;
168
+ while (k < s.length) {
169
+ if (s[k] === '<' && /[A-Za-z]/.test(s[k + 1] || '')) {
170
+ var nm = /^[\w.$]+/.exec(s.slice(k + 1))[0]; o += ' ' + nm + ' '; k += 1 + nm.length;
171
+ while (k < s.length && s[k] !== '>') { if (s[k] === '{') { var e = balanced(s, k); if (e < 0) break; o += ' ' + s.slice(k + 1, e) + ' '; k = e + 1; } else k++; }
172
+ k++; continue;
173
+ }
174
+ o += s[k++];
175
+ }
176
+ s = o;
177
+ s = s.replace(/([A-Za-z_$][\w$]*)\s*:(?!:)/g, ' :').replace(/([A-Za-z_$][\w$-]*)\s*=(?![=>])/g, ' =');
178
+ return idsIn(s).filter(function (id) { return !GLOBALS.test(id) && !/^(true|false|null|undefined|NaN|Infinity|this)$/.test(id); });
179
+ }
180
+ function resolvable(id, S) { return S.declared(id) || (window[NSN] && window[NSN][id]) || defOf(id) || stateSrc(id) || (/^set[A-Z]/.test(id) && setterSrc(id)); }
181
+ /* End of a value inside an object literal: the , or } at depth 0. */
182
+ function valueEnd(s, i) { var d = 0, q = null; for (var k = i; k < s.length; k++) { var c = s[k]; if (q) { if (c === '\\') { k++; continue; } if (c === q) q = null; continue; } if (c === '"' || c === "'" || c === '`') { q = c; continue; } if ('([{'.indexOf(c) >= 0) d++; else if (')]}'.indexOf(c) >= 0) { if (d === 0) return k; d--; } else if (c === ',' && d === 0) return k; } return k; }
183
+ /* Column renders in an authored columns expression: [{ key, text }] — and the expression without them (for Vue, where cells are slots). */
184
+ function columnRenders(ex) {
185
+ var out = [], re = /render\s*:\s*/g, m;
186
+ while ((m = re.exec(ex))) {
187
+ var st = m.index + m[0].length, en = valueEnd(ex, st);
188
+ var before = ex.slice(0, m.index), ob = before.lastIndexOf('{'), km = /key\s*:\s*["']([^"']+)["']/.exec(ex.slice(ob, en));
189
+ if (km) out.push({ key: km[1], text: ex.slice(st, en).trim() });
190
+ }
191
+ var res = '', last = 0, re2 = /,\s*render\s*:\s*/g, m2;
192
+ while ((m2 = re2.exec(ex))) { var en3 = valueEnd(ex, m2.index + m2[0].length); res += ex.slice(last, m2.index); last = en3; re2.lastIndex = en3; }
193
+ res += ex.slice(last);
194
+ return { renders: out, stripped: res };
195
+ }
196
+ /* A JSX expression → a Vue template, for the common shapes (elements, attributes, {expr} children). Returns null when it can't. */
197
+ function jsxToVue(src, params) {
198
+ var s = src.trim(), i = 0, ok = true;
199
+ function fail() { ok = false; return ''; }
200
+ function expr(e) { e = e.trim(); if (/<[A-Za-z>]/.test(e) || /\bfunction\b/.test(e)) return fail(); return e.replace(/"/g, "'"); }
201
+ function node() {
202
+ if (s[i] !== '<') return fail();
203
+ i++;
204
+ if (s[i] === '>') { i++; var kids0 = children(''); return kids0; }
205
+ var nm = /^[\w.$-]+/.exec(s.slice(i)); if (!nm) return fail(); var tag = nm[0]; i += tag.length;
206
+ if (/^[A-Z]/.test(tag) && !(window[NSN] && window[NSN][tag])) return fail();
207
+ var at = [];
208
+ for (;;) {
209
+ while (/\s/.test(s[i])) i++;
210
+ if (s[i] === '/' && s[i + 1] === '>') { i += 2; return '<' + tag + (at.length ? ' ' + at.join(' ') : '') + ' />'; }
211
+ if (s[i] === '>') { i++; break; }
212
+ if (s[i] === '{') return fail();
213
+ var an = /^[\w$-]+/.exec(s.slice(i)); if (!an) return fail(); var a = an[0]; i += a.length; while (/\s/.test(s[i])) i++;
214
+ var vn = a === 'className' ? 'class' : a;
215
+ if (s[i] !== '=') { at.push(vn); continue; }
216
+ i++; while (/\s/.test(s[i])) i++;
217
+ if (s[i] === '"' || s[i] === "'") { var e2 = s.indexOf(s[i], i + 1); at.push(vn + '="' + s.slice(i + 1, e2) + '"'); i = e2 + 1; continue; }
218
+ if (s[i] === '{') { var e3 = balanced(s, i); var x = expr(s.slice(i + 1, e3)); i = e3 + 1; at.push(/^on[A-Z]/.test(a) ? '@' + kebab(a.slice(2)).replace(/^-/, '') + '="' + x + '"' : ':' + vn + '="' + x + '"'); continue; }
219
+ return fail();
220
+ }
221
+ var inner = children(tag);
222
+ return '<' + tag + (at.length ? ' ' + at.join(' ') : '') + '>' + inner + '</' + tag + '>';
223
+ }
224
+ function children(tag) {
225
+ var out = '';
226
+ for (var g = 0; g < 500 && ok; g++) {
227
+ if (s.slice(i, i + 2) === '</') { var close = s.indexOf('>', i); i = close + 1; return out; }
228
+ if (i >= s.length) return fail();
229
+ if (s[i] === '<') { out += node(); continue; }
230
+ if (s[i] === '{') { var e = balanced(s, i); var x = s.slice(i + 1, e).trim(); i = e + 1; if (/^\/\*[\s\S]*\*\/$/.test(x)) continue;
231
+ /* {list.map(t => <Tag key={t}>{t}</Tag>)} → <Tag v-for="t in list" :key="t">{{ t }}</Tag> */
232
+ var mp = /^([\s\S]+?)\.map\(\s*\(?\s*([\w$]+)\s*(?:,\s*([\w$]+))?\s*\)?\s*=>\s*\(?\s*(<[\s\S]*>)\s*\)?\s*\)$/.exec(x);
233
+ if (mp) { var sub = jsxToVue(mp[4]); if (sub == null) return fail(); out += addAttr(sub, 'v-for="' + (mp[3] ? '(' + mp[2] + ', ' + mp[3] + ')' : mp[2]) + ' in ' + expr(mp[1]) + '"'); continue; }
234
+ out += '{{ ' + expr(x) + ' }}'; continue; }
235
+ var nx = s.slice(i).search(/[<{]/); if (nx < 0) return fail(); out += s.slice(i, i + nx).replace(/\s+/g, ' '); i += nx;
236
+ }
237
+ return out;
238
+ }
239
+ if (s[0] === '(' && s[s.length - 1] === ')') s = s.slice(1, -1).trim();
240
+ var res;
241
+ if (s[0] === '<') res = node(); else res = '{{ ' + expr(s) + ' }}';
242
+ return ok && i >= s.length - 1 ? res.trim() : (ok && s[0] !== '<' ? res : null);
243
+ }
244
+ /* Identifier substitution outside strings and property names: replace(text, { a: '(expr)' }). */
245
+ function substIds(text, map) {
246
+ return text.replace(/(`(?:[^`\\]|\\.)*`|"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*')|(\.?)\b([A-Za-z_$][\w$]*)\b(\s*:(?!:))?/g, function (all, str, dot, id, colon) { if (str) return str; if (dot || colon || !Object.prototype.hasOwnProperty.call(map, id)) return all; return map[id]; });
247
+ }
248
+ function simpleExpr(e) { return /^(?:[\w$.]+|"[^"]*"|'[^']*'|\d+(?:\.\d+)?|true|false|null)$/.test(e.trim()); }
249
+ /* Parse <Tag attrs>children</Tag> starting at s[i] === '<'. → { tag, attrs: {name: exprSrc}, children, end } */
250
+ function parseEl(s, i) {
251
+ var nm = /^<([\w.$]+)/.exec(s.slice(i)); if (!nm) return null; var tag = nm[1], k = i + nm[0].length, at = {};
252
+ for (;;) {
253
+ while (/\s/.test(s[k])) k++;
254
+ if (s[k] === '/' && s[k + 1] === '>') return { tag: tag, attrs: at, children: '', end: k + 2 };
255
+ if (s[k] === '>') { k++; break; }
256
+ var an = /^[\w$-]+/.exec(s.slice(k)); if (!an) return null; k += an[0].length; while (/\s/.test(s[k])) k++;
257
+ if (s[k] !== '=') { at[an[0]] = 'true'; continue; }
258
+ k++; while (/\s/.test(s[k])) k++;
259
+ if (s[k] === '"' || s[k] === "'") { var e2 = s.indexOf(s[k], k + 1); at[an[0]] = s.slice(k, e2 + 1); k = e2 + 1; continue; }
260
+ if (s[k] === '{') { var e3 = balanced(s, k); at[an[0]] = s.slice(k + 1, e3).trim(); k = e3 + 1; continue; }
261
+ return null;
262
+ }
263
+ var close = '</' + tag + '>', depth = 1, j = k, open = new RegExp('<' + tag.replace(/\./g, '\\.') + '[\\s/>]', 'g');
264
+ for (; j < s.length; j++) { if (s.startsWith(close, j)) { if (--depth === 0) break; } else if (s[j] === '<' && open.test(s.slice(j, j + tag.length + 2))) { open.lastIndex = 0; depth++; } open.lastIndex = 0; }
265
+ if (j >= s.length) return null;
266
+ return { tag: tag, attrs: at, children: s.slice(k, j), end: j + close.length };
267
+ }
268
+ /* A card helper component (<IconText icon="…">{v}</IconText>) used in a cell: its own JSX with the props filled in. */
269
+ function expandHelpers(body, used) {
270
+ for (var pass = 0; pass < 4; pass++) {
271
+ var changed = false, re = /<([A-Z][\w$]*)/g, m;
272
+ while ((m = re.exec(body))) {
273
+ var tag = m[1]; if ((window[NSN] && window[NSN][tag]) || tag === 'Live') continue;
274
+ var d = defOf(tag); if (!d) return null;
275
+ var hm = /^const\s+[\w$]+\s*=\s*\(\s*\{([^}]*)\}\s*\)\s*=>\s*([\s\S]*?);?\s*$/.exec(d); if (!hm) return null;
276
+ var el = parseEl(body, m.index); if (!el) return null;
277
+ var map = {};
278
+ hm[1].split(',').forEach(function (p) { p = p.trim(); if (!p) return; var eq = p.indexOf('='), n = (eq < 0 ? p : p.slice(0, eq)).trim(), dv = eq < 0 ? 'undefined' : p.slice(eq + 1).trim(); var v = n === 'children' ? null : el.attrs[n] != null ? el.attrs[n] : dv; if (n !== 'children') map[n] = simpleExpr(v) ? v : '(' + v + ')'; });
279
+ var hb = hm[2].trim(); if (hb[0] === '(' && hb[hb.length - 1] === ')') hb = hb.slice(1, -1).trim();
280
+ hb = hb.replace(/\{\s*children\s*\}/g, function () { return el.children; });
281
+ hb = substIds(hb, map);
282
+ used.add(tag);
283
+ body = body.slice(0, m.index) + hb + body.slice(el.end); changed = true; break;
284
+ }
285
+ if (!changed) return body;
286
+ }
287
+ return body;
288
+ }
289
+ /* <Live init={v}>{(x, set) => <Input value={x} onChange={set} />}</Live> — per-cell state in a card — becomes a binding to the row's field. */
290
+ function expandLive(body, field) {
291
+ for (var g = 0; g < 6; g++) {
292
+ var i = body.indexOf('<Live'); if (i < 0) return body;
293
+ var el = parseEl(body, i); if (!el) return null;
294
+ var ch = el.children.trim(); if (ch[0] !== '{') return null; var e = balanced(ch, 0), fn = ch.slice(1, e).trim();
295
+ var fm = /^\(?\s*([\w$]+)\s*(?:,\s*([\w$]+))?\s*\)?\s*=>\s*([\s\S]*)$/.exec(fn); if (!fm) return null;
296
+ var inner = fm[3].trim(), map = {}; map[fm[1]] = field;
297
+ if (fm[2]) { inner = inner.replace(new RegExp('\\b' + fm[2] + '\\(', 'g'), '(' + field + ' = '); map[fm[2]] = '((val) => (' + field + ' = val))'; }
298
+ inner = substIds(inner, map);
299
+ body = body.slice(0, i) + inner + body.slice(el.end);
300
+ }
301
+ return body;
302
+ }
303
+ /* cond ? A : B at the top level of an expression → [cond, A, B]. */
304
+ function splitTernary(s) {
305
+ var d = 0, q = null, qi = -1, depthQ = 0;
306
+ for (var k = 0; k < s.length; k++) { var c = s[k]; if (q) { if (c === '\\') { k++; continue; } if (c === q) q = null; continue; } if (c === '"' || c === "'" || c === '`') { q = c; continue; }
307
+ if ('([{'.indexOf(c) >= 0) d++; else if (')]}'.indexOf(c) >= 0) d--;
308
+ else if (d === 0 && c === '?' && s[k + 1] !== '.' && s[k + 1] !== '?') { if (qi < 0) qi = k; depthQ++; }
309
+ else if (d === 0 && c === ':' && qi >= 0) { if (--depthQ === 0) return [s.slice(0, qi).trim(), s.slice(qi + 1, k).trim(), s.slice(k + 1).trim()]; } }
310
+ return null;
311
+ }
312
+ function addAttr(tpl, attr) { return tpl.replace(/^<([\w.$-]+)/, '<$1 ' + attr); }
313
+ /* A column's render (v, row, i) => body → a Vue cell slot. Card helpers are inlined; per-cell state binds to the row. */
314
+ function renderSlot(key, text, ind, S, slotName, names) {
315
+ var m = /^(?:\(([^)]*)\)|([\w$]+))\s*=>\s*([\s\S]*)$/.exec(text.trim()); if (!m) return null;
316
+ var ps = (m[1] != null ? m[1] : m[2]).split(',').map(function (x) { return x.trim(); }).filter(Boolean), body = m[3].trim();
317
+ if (body[0] === '{') { var rm = /^\{\s*return\s+([\s\S]*?);?\s*\}$/.exec(body); if (!rm) return null; body = rm[1]; }
318
+ var used = new Set(); body = expandHelpers(body, used); if (body == null) return null;
319
+ var live = body.indexOf('<Live') >= 0;
320
+ if (live) { while (ps.length < 2) ps.push(['value', 'row'][ps.length]); if (ps[1] === '_') ps[1] = 'row'; body = expandLive(body, ps[1] + (/^[A-Za-z_$][\w$]*$/.test(key) ? '.' + key : "['" + key + "']")); if (body == null) return null; }
321
+ var tpl, tern = splitTernary(body);
322
+ if (tern && /^\(?\s*</.test(tern[1]) && /^\(?\s*</.test(tern[2])) { var A = jsxToVue(tern[1]), B = jsxToVue(tern[2]); if (A == null || B == null) return null; tpl = addAttr(A, 'v-if="' + tern[0].replace(/"/g, "'") + '"') + '\n' + ' '.repeat(ind + 1) + addAttr(B, 'v-else'); }
323
+ else { tpl = jsxToVue(body, ps); if (tpl == null) return null; }
324
+ names = names || ['value', 'row', 'index']; var dest = ps.map(function (p, i) { if (/^[{[]/.test(p)) return null; if (p === '_') return ''; return p === names[i] ? p : names[i] + ': ' + p; });
325
+ if (dest.some(function (d) { return d == null; })) return null;
326
+ dest = dest.filter(Boolean);
327
+ var html = new Set((body.match(/<([a-z][\w-]*)/g) || []).map(function (x) { return x.slice(1); }));
328
+ var params = new Set(ps), ids = freeIds(body).filter(function (id) { return !params.has(id) && !html.has(id) && !(window[NSN] && window[NSN][id]) && !used.has(id) && id !== 'val'; });
329
+ (body.match(/<([A-Z][\w$]*)/g) || []).forEach(function (mm) { var n = mm.slice(1); if (window[NSN] && window[NSN][n]) { S.used.add(n); if (!VUE.has(n)) S.novue.add(n); } });
330
+ var pad = ' '.repeat(ind);
331
+ return { live: live, ids: ids, text: pad + '<template #' + (slotName || 'cell-' + key) + (dest.length ? '="{ ' + dest.join(', ') + ' }"' : '') + '>\n' + pad + ' ' + tpl + '\n' + pad + '</template>' };
332
+ }
333
+ /* Bring in one card-local name the snippet uses — after the names it depends on, so the printed order runs top to bottom.
334
+ Definitions that touch component state go inside the component; the rest at module level. */
335
+ function pullOne(id, S) {
336
+ if (GLOBALS.test(id) || S.declared(id) || S.seen.has(id) || (window[NSN] && window[NSN][id])) return;
337
+ S.seen.add(id);
338
+ if (/^set[A-Z]/.test(id)) { var ss = setterSrc(id); if (ss) S.stateFromSetter(id, null, ss); return; }
339
+ var st = stateSrc(id); if (st) { S.stateFromSetter(st.set, null, { name: id, init: st.init }); return; }
340
+ var d = defOf(id); if (!d || d.length > 4000) return;
341
+ if (/^const [\w$]+ = (?:React\.)?use[A-Z]/.test(d)) return;
342
+ var body = d.replace(/^(const [\w$]+ = |function [\w$]+)/, '');
343
+ var deps = idsIn(body); deps.forEach(function (x) { pullOne(x, S); });
344
+ if (/<[A-Za-z]|=>|function/.test(body)) S.vueFn = S.vueFn || /<[A-Za-z]/.test(body);
345
+ (body.match(/<([A-Z][\w$]*)/g) || []).forEach(function (m) { var n = m.slice(1); if (window[NSN] && window[NSN][n]) S.used.add(n); });
346
+ var usesState = deps.some(function (x) { return S.declared(x) || S.helpers.some(function (h) { return h.name === x; }); });
347
+ (usesState ? S.helpers : S.consts).push({ name: id, text: usesState ? d : body, full: d });
348
+ }
349
+ function pullHelpers(text, S) { idsIn(text).forEach(function (id) { pullOne(id, S); }); }
350
+ function clean(s, S) {
351
+ s = s.replace(/\/\*#__PURE__\*\/\s*/g, '').replace(/,?\s*__source:\s*\{[^{}]*\}/g, '').replace(/,?\s*__self:\s*this/g, '').replace(/,?\s*"data-(om|cc|dm)-[\w-]+":\s*"(?:[^"\\]|\\.)*"/g, '')
352
+ /* Editor text overrides compiled into the card: keep only the authored fallback text. */
353
+ .replace(/\(\s*(_[\w$]+)\s*=\s*\(window\.__omTextO\s*\|\|\s*\{\}\)\[[^\]]*\]\)\s*!==\s*null\s*&&\s*\1\s*!==\s*void 0\s*\?\s*\1\s*:\s*/g, '')
354
+ .replace(/var _txt[\w$]*(?:,\s*_txt[\w$]*)*;\s*/g, '');
355
+ (s.match(/React\.createElement\(\s*([A-Z][\w$]*)/g) || []).forEach(function (m) { var n = m.replace(/React\.createElement\(\s*/, ''); if (VUE.has(n) || (window[NSN] && window[NSN][n])) S.used.add(n); });
356
+ return s;
357
+ }
358
+ function fnStr(f, S) {
359
+ var s = Function.prototype.toString.call(f);
360
+ if (/\[native code\]/.test(s)) { var nm = S.setterName(f); return nm || '() => {}'; }
361
+ if (/React\.createElement/.test(s)) { S.react = true; s = clean(s, S); }
362
+ S.handlers = (S.handlers || '') + ' ' + s;
363
+ /* Babel turns arrows into functions; print them back as arrows. */
364
+ var m = s.match(/^function\s*[\w$]*\s*\(([^)]*)\)\s*\{\s*return\s+([\s\S]*?);?\s*\}$/);
365
+ if (m && m[2].indexOf('\n') < 0) s = '(' + m[1].trim() + ') => ' + m[2].trim();
366
+ else { m = s.match(/^function\s*[\w$]*\s*\(([^)]*)\)\s*(\{[\s\S]*\})$/); if (m) s = '(' + m[1].trim() + ') => ' + m[2]; }
367
+ return s.length < 140 ? s.replace(/\s*\n\s*/g, ' ') : s;
368
+ }
369
+ function lit(v, ind, S, depth) {
370
+ depth = depth || 0;
371
+ if (v === null) return 'null'; if (v === undefined) return 'undefined';
372
+ if (typeof v === 'string') return q(v);
373
+ if (typeof v === 'number' || typeof v === 'boolean') return String(v);
374
+ if (typeof v === 'function') return fnStr(v, S);
375
+ if (depth > 6) return 'undefined';
376
+ if (isEl(v)) { if (S.fw === 'vue') return hCall(v, ind, S); return jsx(v, ind, S).trim(); }
377
+ if (v instanceof Date) return 'new Date(' + q(v.toISOString()) + ')';
378
+ var pad = ' '.repeat(ind + 1), parts;
379
+ if (Array.isArray(v)) {
380
+ parts = v.map(function (x) { return lit(x, ind + 1, S, depth + 1); });
381
+ var one = '[' + parts.join(', ') + ']';
382
+ return one.length <= 72 && one.indexOf('\n') < 0 ? one : '[\n' + parts.map(function (p) { return pad + p; }).join(',\n') + '\n' + ' '.repeat(ind) + ']';
383
+ }
384
+ if (typeof v === 'object') {
385
+ var ks = Object.keys(v).filter(function (k) { return v[k] !== undefined; });
386
+ parts = ks.map(function (k) { return (IDENT.test(k) ? k : q(k)) + ': ' + lit(v[k], ind + 1, S, depth + 1); });
387
+ var o = '{ ' + parts.join(', ') + ' }';
388
+ if (!ks.length) return '{}';
389
+ return o.length <= 72 && o.indexOf('\n') < 0 ? o : '{\n' + parts.map(function (p) { return pad + p; }).join(',\n') + '\n' + ' '.repeat(ind) + '}';
390
+ }
391
+ return 'undefined';
392
+ }
393
+ /* Vue: an element inside data (a row value, an item body) is written as h(Component, props, …) — the component renders it as a VNode. */
394
+ function hCall(node, ind, S) {
395
+ if (node == null || node === false || node === true) return 'null';
396
+ if (typeof node === 'string' || typeof node === 'number') return lit(node, ind, S);
397
+ if (Array.isArray(node)) return '[' + kids(node).map(function (c) { return hCall(c, ind, S); }).join(', ') + ']';
398
+ if (!isEl(node)) return 'null';
399
+ if (isWrap(node)) { var w = kids(node.props.children); return w.length === 1 ? hCall(w[0], ind, S) : hCall(w, ind, S); }
400
+ S.needH = true;
401
+ var ds = dsName(node.type), tag = ds ? (S.used.add(ds), (VUE.has(ds) || S.novue.add(ds)), ds) : typeof node.type === 'string' ? q(node.type) : null;
402
+ if (!tag) { var ex = expand(node, S); return ex !== undefined ? hCall(ex, ind, S) : 'null'; }
403
+ var p = node.props || {}, pr = {};
404
+ Object.keys(p).forEach(function (k) { if (k !== 'children' && k !== 'key' && !/^data-(om|cc|dm)-/.test(k) && p[k] !== undefined) pr[k === 'className' ? 'class' : k] = p[k]; });
405
+ var ch = kids(p.children).filter(function (c) { return !(isEl(c) && isWrap(c) && !kids(c.props.children).length); });
406
+ var props = Object.keys(pr).length ? lit(pr, ind, S) : 'null';
407
+ if (!ch.length) return 'h(' + tag + (props !== 'null' ? ', ' + props : '') + ')';
408
+ var body = ch.length === 1 ? hCall(ch[0], ind, S) : '[' + ch.map(function (c) { return hCall(c, ind, S); }).join(', ') + ']';
409
+ return 'h(' + tag + ', ' + props + ', ' + (ds ? '() => ' + body : body) + ')';
410
+ }
411
+ function hoist(key, text, S) { var n = key, i = 2; while (S.consts.some(function (c) { return c.name === n; }) || S.helpers.some(function (h) { return h.name === n; }) || S.declared(n) || defOf(n)) n = key + i++; S.consts.push({ name: n, text: text }); return n; }
412
+ function nameOf(type, S) {
413
+ var n = dsName(type);
414
+ if (n) { S.used.add(n); if (!VUE.has(n)) S.novue.add(n); return n; }
415
+ if (typeof type === 'string') return type;
416
+ return (type && (type.displayName || type.name)) || 'Component';
417
+ }
418
+ /* Card-local helpers with no hooks are expanded to what they render; KBLive turns into a state variable. */
419
+ function expand(el, S) {
420
+ var ty = el.type;
421
+ if (typeof ty !== 'function' || dsName(ty) || (ty.prototype && ty.prototype.isReactComponent)) return undefined;
422
+ if (ty === window.KBLive && typeof el.props.children === 'function') { var st = S.state(el.props.children, el.props.init, null); return el.props.children(st.val, st.set); }
423
+ var src = Function.prototype.toString.call(ty);
424
+ if (/\buse[A-Z]\w*\s*\(/.test(src)) return undefined;
425
+ try { return ty(el.props); } catch (e) { return undefined; }
426
+ }
427
+ function isWrap(n) { return isEl(n) && n.props && typeof n.props.i === 'string' && n.props.i.indexOf('txt:') === 0; }
428
+ function kids(c) { var out = []; (function f(x) { if (x == null || x === false || x === true) return; if (Array.isArray(x)) x.forEach(f); else out.push(x); })(c); return out; }
429
+ function textOk(s) { return !/[{}<>]/.test(s); }
430
+ /* Props of one element → [attr strings, slot children (vue)] */
431
+ function attrs(el, ind, S, unit) {
432
+ var p = el.props || {}, out = [], slots = [], as = attrSrc(el._source || (unit && el.__unit ? unit.fiber._debugSource : null));
433
+ var fns = Object.keys(p).filter(function (k) { return typeof p[k] === 'function' && k !== 'children'; }).map(function (k) { return fnStr(p[k], S); }).join(' ');
434
+ var fsrc = Object.keys(p).filter(function (k) { return typeof p[k] === 'function' && k !== 'children'; }).map(function (k) { return as[k] || ''; }).join(' ') + ' ' + fns;
435
+ var free = (fsrc.match(/\bset[A-Z][\w$]*/g) || []).filter(function (n, i, a) { return !S.declared(n) && a.indexOf(n) === i; });
436
+ S.free = (S.free || []).concat(free);
437
+ /* An onChange the card builds in a helper (spread props, no source to print) becomes plain state on the value it drives. */
438
+ var auto = null;
439
+ if (typeof p.onChange === 'function' && !as.onChange && !S.setterName(p.onChange)) {
440
+ var vk = Object.keys(p).find(function (k) { return VALUE_KEYS[k] && typeof p[k] !== 'function' && !S.boundName(p[k], unit); });
441
+ if (vk) { var base = vk, nm = base, n2 = 2; while (S.declared(nm)) nm = base + n2++; var setn = 'set' + nm[0].toUpperCase() + nm.slice(1); S.states.push({ name: nm, set: setn, init: p[vk], val: {}, sentinel: function () {} }); auto = { key: vk, name: nm, set: setn }; }
442
+ }
443
+ Object.keys(p).forEach(function (k) {
444
+ if (k === 'children' || k === 'key' || k === 'ref' || k === '__self' || k === '__source' || /^data-(om|cc|dm)-/.test(k)) return;
445
+ var v = p[k]; if (v === undefined) return;
446
+ var name = S.fw === 'vue' ? (k === 'className' ? 'class' : kebab(k)) : k;
447
+ var bound = auto && auto.key === k ? auto.name : VALUE_KEYS[k] ? S.boundName(v, unit) : null;
448
+ if (!bound && as[k] && /^[A-Za-z_$][\w$]*$/.test(as[k]) && typeof v !== 'function') { var ss2 = stateSrc(as[k]); if (ss2) bound = S.stateFromSetter(ss2.set, v, { name: as[k], init: ss2.init }); }
449
+ /* Guessing a value from a setter only when the card's source for this prop is unknown. */
450
+ if (!bound && !as[k] && VALUE_KEYS[k] && free.length && typeof v !== 'function') { bound = S.stateFromSetter(free.shift(), v); }
451
+ if (bound) { out.push(S.fw === 'vue' ? ':' + name + '="' + bound + '"' : k + '={' + bound + '}'); return; }
452
+ if (typeof v === 'function') {
453
+ /* Vue: a render prop written as JSX (Tree rowActions={(n) => <>…</>}) becomes the component's slot. */
454
+ var VSLOTS = { Tree: { rowActions: ['node'] } }, tg = dsName(el.type);
455
+ if (S.fw === 'vue' && as[k] && /</.test(as[k]) && VSLOTS[tg] && VSLOTS[tg][k]) {
456
+ var rs = renderSlot(k, as[k], ind + 1, S, kebab(k), VSLOTS[tg][k]);
457
+ if (rs && rs.ids.every(function (id) { return resolvable(id, S); })) { rs.ids.forEach(function (id) { pullOne(id, S); }); slots.push({ raw: rs.text }); return; }
458
+ }
459
+ /* A handler the card names (onToggle={toggle}) is printed by name, with its authored definition copied in. */
460
+ if (as[k] && /^[A-Za-z_$][\w$]*$/.test(as[k]) && !S.declared(as[k]) && !/^set[A-Z]/.test(as[k]) && defOf(as[k])) pullOne(as[k], S);
461
+ var fs = (auto && k === 'onChange' ? auto.set : null) || S.setterName(v) || (as[k] && (/=>|function/.test(as[k]) || (/^[\w$.]+$/.test(as[k]) && (S.declared(as[k]) || /^set[A-Z]/.test(as[k]) || S.helpers.some(function (h) { return h.name === as[k]; }) || S.consts.some(function (c) { return c.name === as[k]; })))) ? as[k] : fnStr(v, S));
462
+ var vq = function (x) { return x.indexOf("'") < 0 ? x.replace(/"/g, "'") : x.replace(/"/g, '&quot;'); };
463
+ S.handlers = (S.handlers || '') + ' ' + fs;
464
+ if (S.fw === 'vue') { if (/^on[A-Z]/.test(k)) out.push('@' + kebab(k.slice(2)).replace(/^-/, '') + '="' + vq(fs) + '"'); else { if (/React\.createElement/.test(fs)) S.vueFn = true; out.push(':' + name + '="' + fs.replace(/"/g, '&quot;') + '"'); } }
465
+ else out.push(k + '={' + fs + '}');
466
+ return;
467
+ }
468
+ if (typeof v === 'string') { if (S.fw === 'vue') out.push(name + '="' + v.replace(/"/g, '&quot;') + '"'); else out.push(/["\n]/.test(v) ? k + '={' + q(v) + '}' : k + '="' + v + '"'); return; }
469
+ if (v === true) { out.push(name); return; }
470
+ if (isEl(v) || (Array.isArray(v) && v.length && v.every(isEl))) {
471
+ if (S.fw === 'vue') { slots.push({ name: k, el: v }); return; }
472
+ out.push(k + '={' + (Array.isArray(v) ? '[' + v.map(function (x) { return jsx(x, ind + 1, S).trim(); }).join(', ') + ']' : jsx(v, ind + 1, S).trim()) + '}'); return;
473
+ }
474
+ /* Vue Table: column renders become #cell-<key> slots; the columns themselves are printed without render. */
475
+ if (S.fw === 'vue' && k === 'columns' && Array.isArray(v) && v.some(function (c) { return c && typeof c.render === 'function'; })) {
476
+ var csrc = as[k] && /^[A-Za-z_$][\w$]*$/.test(as[k]) ? (topConsts()[as[k]] || (defOf(as[k]) || '').replace(/^const\s+[\w$]+\s*=\s*/, '')) : as[k];
477
+ /* const TIER_COLS_SM = TIER_COLS("sm") with TIER_COLS = (t) => [...]: use the array with t filled in. */
478
+ var fc = csrc && /^([A-Za-z_$][\w$]*)\(\s*([^()]*?)\s*\)$/.exec(csrc.trim()), fdef = fc && topConsts()[fc[1]], fm2 = fdef && /^\(?\s*([\w$]+)\s*\)?\s*=>\s*([\s\S]*)$/.exec(fdef.trim());
479
+ if (fm2) { var mp2 = {}; mp2[fm2[1]] = fc[2]; csrc = substIds(fm2[2].trim(), mp2); }
480
+ var cr = csrc ? columnRenders(csrc) : { renders: [], stripped: null };
481
+ /* Renders that live in the constants this one spreads or maps (…RUNS) count too; those constants print without them. */
482
+ var refd = [];
483
+ var queue = csrc ? freeIds(csrc) : [], seenR = new Set();
484
+ while (queue.length) { var id = queue.shift(); if (seenR.has(id)) continue; seenR.add(id); var tx = topConsts()[id]; if (!tx) continue; queue = queue.concat(freeIds(tx)); if (/render\s*:/.test(tx)) { refd.push(id); columnRenders(tx).renders.forEach(function (r) { if (!cr.renders.some(function (x) { return x.key === r.key; })) cr.renders.push(r); }); } }
485
+ /* render: dimCell — a named function: use its definition. */
486
+ cr.renders.forEach(function (r) { if (/^[A-Za-z_$][\w$]*$/.test(r.text)) { var dd = defOf(r.text); var mm = dd && /^const\s+[\w$]+\s*=\s*([\s\S]*)$/.exec(dd); if (mm) r.text = mm[1].trim().replace(/;$/, ''); } });
487
+ var tplSlots = cr.renders.map(function (r) { return renderSlot(r.key, r.text, ind + 1, S); });
488
+ if (cr.stripped && tplSlots.length && tplSlots.every(Boolean) && tplSlots.every(function (sl) { return sl.ids.every(function (id) { return resolvable(id, S); }); })) {
489
+ tplSlots.forEach(function (sl) { slots.push({ raw: sl.text }); sl.ids.forEach(function (id) { pullOne(id, S); }); });
490
+ if (tplSlots.some(function (sl) { return sl.live; }) && as.rows && /^[A-Za-z_$][\w$]*$/.test(as.rows)) { S.reactive = S.reactive || new Set(); S.reactive.add(as.rows); }
491
+ (cr.stripped.match(/<([A-Z][\w$]*)/g) || []).forEach(function () {});
492
+ cr.renders.forEach(function (r) { (r.text.match(/<([A-Z][\w$]*)/g) || []).forEach(function (mm) { var n = mm.slice(1); if (window[NSN] && window[NSN][n]) { S.used.add(n); if (!VUE.has(n)) S.novue.add(n); } }); });
493
+ var ids0 = freeIds(cr.stripped);
494
+ if (ids0.every(function (id) { return resolvable(id, S); })) {
495
+ ids0.forEach(function (id) { pullOne(id, S); });
496
+ S.consts.forEach(function (c) { if (refd.indexOf(c.name) >= 0) c.text = columnRenders(c.text).stripped; });
497
+ var nm0 = as[k] && /^[A-Za-z_$][\w$]*$/.test(as[k]) ? as[k] : 'columns';
498
+ S.consts = S.consts.filter(function (c) { return c.name !== nm0; });
499
+ S.consts.push({ name: nm0, text: cr.stripped.trim() });
500
+ out.push(':' + name + '="' + nm0 + '"'); return;
501
+ }
502
+ slots.length = 0;
503
+ }
504
+ v = v.map(function (c) { if (!c || typeof c.render !== 'function') return c; var o = {}; Object.keys(c).forEach(function (kk) { if (kk !== 'render') o[kk] = c[kk]; }); return o; });
505
+ S.vueFn = true;
506
+ }
507
+ /* Any other authored expression (an inline array, a .map over a constant, JSX) is printed as written, with the names it uses. */
508
+ if (as[k] && typeof v === 'object' && v !== null && !isEl(v) && !/^[A-Za-z_$][\w$]*$/.test(as[k]) && !(S.fw === 'vue' && /<[A-Za-z]|=>/.test(as[k]))) {
509
+ var ids = freeIds(as[k]);
510
+ if (ids.every(function (id) { return resolvable(id, S); })) {
511
+ ids.forEach(function (id) { pullOne(id, S); });
512
+ (as[k].match(/<([A-Z][\w$]*)/g) || []).forEach(function (mm) { var n = mm.slice(1); if (window[NSN] && window[NSN][n]) S.used.add(n); });
513
+ var ex = as[k].trim(), txt = k !== 'style' && (ex.length > 60 || ex.indexOf('\n') >= 0) ? hoist(k, ex, S) : ex;
514
+ out.push(S.fw === 'vue' ? ':' + name + '="' + txt.replace(/"/g, "'") + '"' : k + '={' + txt + '}'); return;
515
+ }
516
+ }
517
+ if (as[k] && /^[A-Za-z_$][\w$]*$/.test(as[k]) && typeof v === 'object' && useConst(as[k], S)) { out.push(S.fw === 'vue' ? ':' + name + '="' + as[k] + '"' : k + '={' + as[k] + '}'); return; }
518
+ var text = lit(v, ind + 1, S);
519
+ if (k !== 'style' && (text.length > 60 || text.indexOf('\n') >= 0) && typeof v === 'object') text = hoist(k, lit(v, 0, S), S);
520
+ out.push(S.fw === 'vue' ? ':' + name + '="' + text.replace(/"/g, '&quot;') + '"' : k + '={' + text + '}');
521
+ });
522
+ return [out, slots];
523
+ }
524
+ function tagLine(open, a, ind) {
525
+ var pad = ' '.repeat(ind), one = open + (a.length ? ' ' + a.join(' ') : '');
526
+ if (one.length + pad.length <= 100 && one.indexOf('\n') < 0) return [one];
527
+ return [open].concat(a.map(function (x) { return ' ' + x.replace(/\n/g, '\n '); }));
528
+ }
529
+ function jsx(node, ind, S, unit) {
530
+ var pad = ' '.repeat(ind);
531
+ if (node == null || node === false || node === true) return '';
532
+ if (typeof node === 'string' || typeof node === 'number') { var s = String(node); return pad + (S.fw === 'vue' ? s.replace(/</g, '&lt;') : textOk(s) ? s : '{' + q(s) + '}'); }
533
+ if (Array.isArray(node)) return kids(node).map(function (c) { return jsx(c, ind, S, unit); }).filter(Boolean).join('\n');
534
+ if (!isEl(node)) return '';
535
+ if (typeof node.type === 'symbol' || (node.type && node.type === (window.React && window.React.Fragment))) { var fk = kids(node.props.children), fb = fk.map(function (c) { return jsx(c, S.fw === 'vue' || fk.length < 2 ? ind : ind + 1, S, unit); }).filter(Boolean).join('\n'); return S.fw === 'vue' || fk.length < 2 ? fb : ' '.repeat(ind) + '<>\n' + fb + '\n' + ' '.repeat(ind) + '</>'; }
536
+ /* Editor instrumentation (a text wrapper <e i="txt:…">) is not part of the example. */
537
+ if (isWrap(node)) return kids(node.props.children).map(function (c) { return jsx(c, ind, S, unit); }).filter(Boolean).join('\n');
538
+ var ex = expand(node, S); if (ex !== undefined) return jsx(ex, ind, S, unit);
539
+ var tag = nameOf(node.type, S), r = attrs(node, ind, S, unit), a = r[0], slots = r[1];
540
+ var ch = kids(node.props && node.props.children);
541
+ if (typeof (node.props && node.props.children) === 'function') { a.push(S.fw === 'vue' ? '<!-- render function -->' : 'children={' + fnStr(node.props.children, S) + '}'); ch = []; }
542
+ var head = tagLine('<' + tag, a, ind);
543
+ if (!ch.length && !slots.length) { head[head.length - 1] += ' />'; return head.map(function (l) { return pad + l; }).join('\n'); }
544
+ head[head.length - 1] += '>';
545
+ if (ch.length === 1 && isWrap(ch[0])) ch = kids(ch[0].props.children);
546
+ if (!slots.length && ch.length === 1 && (typeof ch[0] === 'string' || typeof ch[0] === 'number') && head.length === 1 && String(ch[0]).length < 60 && (S.fw === 'vue' || textOk(String(ch[0])))) return pad + head[0] + String(ch[0]).replace(/</g, S.fw === 'vue' ? '&lt;' : '<') + '</' + tag + '>';
547
+ var body = slots.map(function (sl) { if (sl.raw) return sl.raw; return ' '.repeat(ind + 1) + '<template #' + kebab(sl.name) + '>\n' + jsx(sl.el, ind + 2, S, unit) + '\n' + ' '.repeat(ind + 1) + '</template>'; });
548
+ var inner = ch.map(function (c) { return jsx(c, ind + 1, S, unit); }).filter(Boolean);
549
+ return head.map(function (l) { return pad + l; }).join('\n') + '\n' + body.concat(inner).join('\n') + '\n' + pad + '</' + tag + '>';
550
+ }
551
+
552
+ /* ---------- state ---------- */
553
+ function Ctx(fwk) {
554
+ var S = { fw: fwk, used: new Set(), novue: new Set(), consts: [], states: [], react: false, vueEl: false, vueFn: false };
555
+ S.declared = function (n) { return S.states.some(function (s) { return s.set === n || s.name === n; }); };
556
+ S.state = function (childFn, init, dispatch) {
557
+ var m = Function.prototype.toString.call(childFn).match(/^\s*(?:function\s*[\w$]*\s*)?\(?\s*([\w$]+)\s*(?:,\s*([\w$]+))?/);
558
+ var name = m && m[1] || 'value', set = m && m[2] || 'set' + name[0].toUpperCase() + name.slice(1);
559
+ var ex = S.states.find(function (s) { return s.name === name; }); if (ex) return ex;
560
+ var st = { name: name, set: set, init: init, val: init, dispatch: dispatch, sentinel: function (x) {} };
561
+ S.states.push(st); return { val: st.val, set: st.sentinel };
562
+ };
563
+ S.boundName = function (v, unit) { if (v === null || v === undefined) return null; var st = S.states.find(function (s) { return (s.unit === unit || !s.unit) && Object.is(s.val, v); }); return st ? st.name : null; };
564
+ S.setterName = function (f) { var st = S.states.find(function (s) { return s.sentinel === f || (s.dispatch && s.dispatch === f); }); return st ? st.set : null; };
565
+ S.stateFromSetter = function (set, v, src) { src = src || setterSrc(set); var name = src ? src.name : set.slice(3); if (!src) name = name[0].toLowerCase() + name.slice(1); if (S.declared(name)) return name; S.states.push({ name: name, set: set, init: v, initSrc: src ? src.init : null, val: v, sentinel: function () {} }); return name; };
566
+ S.helpers = []; S.seen = new Set();
567
+ return S;
568
+ }
569
+ function liveOf(u, S) {
570
+ var lf = u.live; if (!lf) return;
571
+ var hook = lf.memoizedState, val = hook ? hook.memoizedState : lf.memoizedProps.init, dispatch = hook && hook.queue ? hook.queue.dispatch : null;
572
+ var r = S.state(lf.memoizedProps.children, val, dispatch); var st = S.states[S.states.length - 1]; st.val = val; st.unit = u; return r;
573
+ }
574
+ function gen(snips, fwk) {
575
+ var S = Ctx(fwk), blocks = [];
576
+ snips.forEach(function (sn) {
577
+ var lines = [];
578
+ if (sn.tiers) {
579
+ sn.units.forEach(function (u) { var cell = u.el.closest('[data-size]'); var pr = {}; Object.keys(u.props).forEach(function (k) { if (typeof u.props[k] !== 'function') pr[k] = u.props[k]; }); var inner = jsx({ $typeof: 1, type: u.fiber.elementType || u.fiber.type, props: pr, _source: u.fiber._debugSource }, 1, S, u); lines.push(S.fw === 'vue' ? '<div data-size="' + (cell ? cell.getAttribute('data-size') : 'md') + '">\n' + inner + '\n</div>' : '<div data-size="' + (cell ? cell.getAttribute('data-size') : 'md') + '">\n' + inner + '\n</div>'); });
580
+ } else {
581
+ sn.units.forEach(function (u) { liveOf(u, S); lines.push(jsx({ $$typeof: 1, type: u.fiber.elementType || u.fiber.type, props: u.props, _source: u.fiber._debugSource }, 0, S, u)); });
582
+ }
583
+ blocks.push({ title: sn.title, lines: lines, row: sn.units.length > 1 && !sn.tiers });
584
+ });
585
+ return { S: S, blocks: blocks };
586
+ }
587
+ function indent(s, n) { var p = ' '.repeat(n); return s.split('\n').map(function (l) { return l ? p + l : l; }).join('\n'); }
588
+ function wrapBody(lines, row, fwk) {
589
+ if (lines.length === 1) return lines[0];
590
+ if (!row) return lines.join('\n');
591
+ var open = fwk === 'vue' ? '<div style="display: flex; flex-wrap: wrap; gap: 8px; align-items: center">' : "<div style={{ display: 'flex', flexWrap: 'wrap', gap: 8, alignItems: 'center' }}>";
592
+ return open + '\n' + indent(lines.join('\n'), 1) + '\n</div>';
593
+ }
594
+ function code(snip, fwk) {
595
+ var g = gen([snip], fwk), S = g.S, b = g.blocks[0];
596
+ (S.free || []).forEach(function (n) { if (!S.declared(n)) S.stateFromSetter(n, null); });
597
+ pullHelpers((S.handlers || '') + ' ' + S.consts.map(function (c) { return c.text; }).join(' '), S);
598
+ /* A module-level constant that reads component state or a helper inside the component moves inside too. */
599
+ for (var moved = true; moved;) {
600
+ moved = false;
601
+ var inner = new Set(S.states.reduce(function (a, s) { return a.concat([s.name, s.set]); }, []).concat(S.helpers.map(function (h) { return h.name; })));
602
+ S.consts = S.consts.filter(function (c) { if (idsIn(c.text).some(function (x) { return inner.has(x); })) { S.helpers.push({ name: c.name, text: 'const ' + c.name + ' = ' + c.text }); moved = true; return false; } return true; });
603
+ }
604
+ var body = wrapBody(b.lines, b.row, fwk), comps = Array.from(S.used).sort();
605
+ var imp = comps.length ? 'import { ' + comps.join(', ') + " } from '@keyfunc/keybricks-ds" + (fwk === 'vue' ? '/vue' : '') + "'" : '';
606
+ /* Vue: rows that cells edit in place (bound to row.field) are reactive. */
607
+ var consts = S.consts.map(function (c) { return 'const ' + c.name + ' = ' + (fwk === 'vue' && S.reactive && S.reactive.has(c.name) ? 'reactive(' + c.text + ')' : c.text); }).join('\n\n');
608
+ if (fwk === 'vue') {
609
+ (S.free || []).forEach(function (n) { if (!S.declared(n)) S.stateFromSetter(n, null); });
610
+ var st = S.states.map(function (s) { return 'const ' + s.name + ' = ref(' + (s.initSrc || lit(s.init, 0, S)) + ')\nconst ' + s.set + " = (x) => { " + s.name + ".value = typeof x === 'function' ? x(" + s.name + '.value) : x }'; }).join('\n') + (S.helpers.length ? '\n' + S.helpers.map(function (h) { /* in <script setup> a ref is read as name.value (the template unwraps it) */ var mp = {}; S.states.forEach(function (s) { mp[s.name] = s.name + '.value'; }); return substIds(h.text, mp); }).join('\n') : '');
611
+ var multiRoot = body.split('\n').filter(function (l) { return /^</.test(l) && !/^<\//.test(l); }).length;
612
+ var scriptPart = (st || '') + '\n' + (consts || '');
613
+ var note = /<[A-Za-z][\w.]*[\s/>]/.test(scriptPart) ? '<!-- Custom cells below are written for React. In Vue, write each one as a slot — <template #cell-<key>="{ value, row }">…</template> — using the markup from the React tab. -->\n' : S.vueEl ? '<!-- Some props here take a React element in the React tab; in Vue pass that content through the component\'s slot. -->\n' : '';
614
+ return { novue: Array.from(S.novue), text: '<script setup>\n' + (S.states.length || S.reactive || S.needH ? "import { " + [S.needH ? 'h' : '', S.states.length ? 'ref' : '', S.reactive ? 'reactive' : ''].filter(Boolean).join(', ') + " } from 'vue'\n" : '') + imp + (consts ? '\n\n' + consts : '') + (st ? '\n\n' + st : '') + '\n<\/script>\n\n<template>\n' + note + indent(body, 1) + '\n</template>' };
615
+ }
616
+ (S.free || []).forEach(function (n) { if (!S.declared(n)) S.stateFromSetter(n, null); });
617
+ var helpers = S.helpers.map(function (h) { return h.text; }).join('\n');
618
+ /* Cards keep per-cell demo state with a Live helper (<Live init={v}>{(x, set) => …}</Live>); the snippet carries its three-line definition. */
619
+ var needLive = /<Live[\s>]/.test((consts || '') + '\n' + helpers + '\n' + body);
620
+ var useSt = S.states.length || needLive;
621
+ var reactImp = useSt && S.react ? "import React, { useState } from 'react'\n" : useSt ? "import { useState } from 'react'\n" : S.react ? "import React from 'react'\n" : '';
622
+ var liveDef = needLive ? '// One cell\'s own value — stands in for your row state\nfunction Live({ init, children }) {\n const [value, setValue] = useState(init)\n return children(value, setValue)\n}\n\n' : '';
623
+ var st2 = S.states.map(function (s) { return ' const [' + s.name + ', ' + s.set + '] = useState(' + (s.initSrc || lit(s.init, 1, S)) + ')'; }).join('\n') + (helpers ? '\n' + indent(helpers, 1) : '');
624
+ var multi = b.lines.length > 1 && !b.row;
625
+ var ret = multi ? '<>\n' + indent(body, 1) + '\n</>' : body;
626
+ return { novue: [], text: reactImp + imp + '\n\n' + liveDef + (consts ? consts + '\n\n' : '') + 'export default function Example() {\n' + (st2 ? st2 + '\n\n' : '') + ' return (\n' + indent(ret, 2) + '\n )\n}' };
627
+ }
628
+
629
+ /* ---------- UI ---------- */
630
+ var ICON = '<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m18 16 4-4-4-4"/><path d="m6 8-4 4 4 4"/><path d="m14.5 4-5 16"/></svg>';
631
+ var SEG = 'display:inline-flex;gap:2px;padding:2px;height:28px;box-sizing:border-box;border-radius:var(--radius-md);background:var(--bg-inset);border:1px solid var(--border-control)';
632
+ var SEGB = 'height:22px;padding:0 8px;border:none;border-radius:var(--radius-sm);cursor:pointer;font-family:var(--font-sans);font-size:var(--text-xs);font-weight:var(--weight-medium);white-space:nowrap;';
633
+ var BTN = 'display:inline-flex;align-items:center;gap:4px;height:24px;padding:0 8px;box-sizing:border-box;border-radius:var(--radius-md);border:1px solid var(--border-control);background:var(--bg-surface);color:var(--text-secondary);font-family:var(--font-sans);font-size:var(--text-xs);cursor:pointer;flex-shrink:0';
634
+ function el(tag, css, html) { var e = document.createElement(tag); if (css) e.style.cssText = css; if (html != null) e.innerHTML = html; return e; }
635
+ function makeBar(anchor, root) {
636
+ var wrap = el('div', 'grid-column:1/-1;contain:inline-size;max-width:100%;margin-top:12px;border:1px solid var(--border-subtle);border-radius:var(--radius-md);overflow:hidden;font-family:var(--font-sans);background:var(--bg-surface);min-width:0;width:100%;box-sizing:border-box');
637
+ wrap.setAttribute('data-kb-code', ''); wrap.__kbAnchor = anchor; wrap.__anchor = anchor;
638
+ var panel = el('div', 'display:none;border-bottom:1px solid var(--border-subtle)');
639
+ var head = el('div', 'display:flex;align-items:center;justify-content:flex-end;padding:8px 12px;border-bottom:1px solid var(--border-subtle)');
640
+ var seg = el('div', SEG); head.appendChild(seg);
641
+ var list = el('div');
642
+ panel.appendChild(head); panel.appendChild(list);
643
+ var toggle = el('button', 'display:flex;align-items:center;justify-content:center;gap:6px;width:100%;height:32px;border:none;background:var(--addrow-bg,transparent);color:var(--addrow-fg,var(--text-secondary));font-family:var(--font-sans);font-size:var(--text-xs);font-weight:var(--weight-medium);cursor:pointer');
644
+ toggle.type = 'button'; toggle.setAttribute('data-addrow', '');
645
+ wrap.appendChild(panel); wrap.appendChild(toggle);
646
+ var open = false, bar = { anchor: anchor };
647
+ function render() {
648
+ seg.innerHTML = '';
649
+ [['react', 'React'], ['vue', 'Vue 3']].forEach(function (o) {
650
+ var b = el('button', SEGB + (fw === o[0] ? 'background:var(--bg-surface);box-shadow:0 1px 2px rgba(0,0,0,.08);color:var(--text-heading)' : 'background:transparent;color:var(--text-secondary)'), o[1]);
651
+ b.type = 'button'; b.onclick = function () { fw = o[0]; try { localStorage.setItem('kb-code-fw', fw); } catch (e) {} bars.forEach(function (x) { x.refresh(); }); }; seg.appendChild(b);
652
+ });
653
+ list.innerHTML = '';
654
+ snipsFor(anchor, root).forEach(function (sn, i) {
655
+ var c = code(sn, fw);
656
+ var item = el('div', i ? 'border-top:1px solid var(--border-subtle)' : '');
657
+ var top = el('div', 'display:flex;align-items:center;justify-content:space-between;gap:8px;padding:8px 12px 0');
658
+ var title = el('span', 'font-size:var(--text-xs);line-height:var(--leading-xs);color:var(--text-secondary);min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap'); title.textContent = sn.title || '';
659
+ var cp = el('button', BTN); cp.type = 'button';
660
+ var label = function (k) { cp.innerHTML = '<svg width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect width="14" height="14" x="8" y="8" rx="2"/><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/></svg><span></span>'; cp.lastChild.textContent = tr(k); };
661
+ label('copy');
662
+ var text = fw === 'vue' && c.novue.length ? null : c.text;
663
+ cp.onclick = function () { try { navigator.clipboard.writeText(text || ''); } catch (e) {} label('copied'); setTimeout(function () { label('copy'); }, 1200); };
664
+ top.appendChild(title); if (text) top.appendChild(cp);
665
+ var pre = el('pre', 'margin:8px 0 0;padding:12px 16px;overflow:auto;max-height:420px;background:var(--bg-inset);font-family:var(--font-mono);font-size:var(--text-code);line-height:var(--leading-code);color:var(--text-body);white-space:pre;tab-size:2');
666
+ pre.textContent = text || tr('novue') + c.novue.join(', ');
667
+ if (!text) pre.style.whiteSpace = 'normal';
668
+ item.appendChild(top); item.appendChild(pre); list.appendChild(item);
669
+ });
670
+ }
671
+ var count = 0; try { count = snipsFor(anchor, root).length; } catch (e) {}
672
+ bar.paint = function () { toggle.innerHTML = ICON + '<span></span>'; toggle.lastChild.textContent = tr(open ? 'hide' : 'show') + (count > 1 ? ' · ' + count : ''); if (open) render(); };
673
+ bar.refresh = function () { if (open) render(); };
674
+ /* A card whose root is a narrow, centred box (one small control): the bar still gets a readable width. */
675
+ setTimeout(function () { if (wrap.parentElement === root && wrap.getBoundingClientRect().width < 320) wrap.style.minWidth = 'min(560px, calc(100vw - 32px))'; }, 0);
676
+ toggle.onclick = function () { open = !open; panel.style.display = open ? 'block' : 'none'; bar.paint(); };
677
+ bar.paint();
678
+ bars.push(bar);
679
+ return wrap;
680
+ }
681
+ function snipsFor(anchor, root) {
682
+ var units = scan(root).filter(function (u) { return u.anchor === anchor; }), map = new Map(), out = [];
683
+ units.forEach(function (u) {
684
+ if (u.tiers && u.el.closest('[lang]') && u.el.closest('[lang]').getAttribute('lang') !== 'en') return;
685
+ var key = u.row; if (!map.has(key)) { var sn = { units: [], tiers: !!u.tiers, title: '' }; map.set(key, sn); out.push(sn); } map.get(key).units.push(u);
686
+ });
687
+ out.forEach(function (sn) { sn.title = sn.tiers ? (labelFor(sn.units[0], anchor) || tr('tiers')) : labelFor(sn.units[0], anchor); });
688
+ /* A section (.kb-sec / .sec / .case) without live state reads as one example: one snippet for all its controls. */
689
+ if (out.length > 1 && units[0].mode === 'append' && !out.some(function (s) { return s.tiers || s.units.some(function (u) { return u.live; }); })) {
690
+ var h = anchor.querySelector('.kb-h,h3,h4,.k,.lbl');
691
+ return [{ units: out.reduce(function (a, s) { return a.concat(s.units); }, []), tiers: false, title: h ? h.textContent.trim() : '' }];
692
+ }
693
+ return out;
694
+ }
695
+ /* Examples that overflow their box (an open menu, a stacked toast) must not sit on the bar: push the bar below them. */
696
+ function clear(bar, anchor, root) {
697
+ var fix = function () {
698
+ var us = scan(root).filter(function (u) { return u.anchor === anchor && u.el && !u.fixed; }); if (!us.length) return;
699
+ var bottom = Math.max.apply(null, us.map(function (u) { return u.el.getBoundingClientRect().bottom; }));
700
+ bar.style.marginTop = '12px'; var gap = bar.getBoundingClientRect().top - bottom;
701
+ if (gap < 8) bar.style.marginTop = (12 + 8 - gap) + 'px';
702
+ };
703
+ requestAnimationFrame(fix); setTimeout(fix, 500);
704
+ }
705
+ function pass(root) {
706
+ var units = scan(root); if (!units.length || units.length > 80) return;
707
+ var seen = new Set(), anchors = [];
708
+ units.forEach(function (u) { if (!seen.has(u.anchor)) { seen.add(u.anchor); anchors.push(u); } });
709
+ anchors.forEach(function (u) {
710
+ if (u.anchor.__kbCode) return; u.anchor.__kbCode = true;
711
+ var bar = makeBar(u.anchor, root);
712
+ /* Never inside a box that clips (a fixed-height pane): the bar goes after the outermost clipping box instead. */
713
+ var clips = function (n) { var cs = getComputedStyle(n); return cs.overflowY !== 'visible' || cs.overflowX !== 'visible'; };
714
+ var top = null; for (var n = u.mode === 'append' ? u.anchor : u.anchor.parentElement; n && n !== root && root.contains(n); n = n.parentElement) if (clips(n)) top = n;
715
+ if (top) { top.parentNode.insertBefore(bar, top.nextSibling); clear(bar, u.anchor, root); return; }
716
+ if (u.mode === 'append') { u.anchor.appendChild(bar); clear(bar, u.anchor, root); return; }
717
+ /* A grid that also holds a full-width block with its own bar: this bar goes right under the grid's own cells, before that block. */
718
+ var inner = false && Array.prototype.find.call(u.anchor.children, function (ch) { return anchors.some(function (o) { return o.anchor !== u.anchor && ch.contains(o.anchor); }); });
719
+ if (inner) u.anchor.insertBefore(bar, inner); else u.anchor.parentNode.insertBefore(bar, u.anchor.nextSibling);
720
+ clear(bar, u.anchor, root);
721
+ });
722
+ }
723
+ function attach(sel) {
724
+ if (/\/icons-[^/]*\.card\.html/.test(location.pathname)) return;
725
+ var root = document.querySelector(sel); if (!root) return;
726
+ /* Cards render at different speeds (charts, 3D): pass now, then again whenever the card's own DOM changes, for 20s. */
727
+ var run = function () { try { pass(root); } catch (e) { console.warn('usage-code:', e); } };
728
+ [60, 600, 1600].forEach(function (d) { setTimeout(run, d); });
729
+ var tm = null, mo = new MutationObserver(function (ms) {
730
+ if (ms.every(function (m) { return m.target.closest && m.target.closest('[data-kb-code]'); })) return;
731
+ clearTimeout(tm); tm = setTimeout(run, 250);
732
+ });
733
+ mo.observe(root, { childList: true, subtree: true });
734
+ setTimeout(function () { mo.disconnect(); }, 20000);
735
+ }
736
+ window.KBUsage = { _rs: function (k, tx) { return renderSlot(k, tx, 0, Ctx('vue')); }, _x: function (b) { var u = new Set(); var r = expandHelpers(b, u); return [r, r && jsxToVue(r)]; }, attach: attach, _code: code, _snips: function (sel) { var r = document.querySelector(sel); var a = scan(r); return a; } };
737
+ })();