@opendata-ai/openchart-vanilla 8.0.0-rc.8 → 8.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. package/dist/{chunk-W34KN7FD.js → chunk-2NAQRP66.js} +2 -2
  2. package/dist/{chunk-UZ7J3NOF.js → chunk-6BUCYCLD.js} +7314 -5605
  3. package/dist/chunk-6BUCYCLD.js.map +1 -0
  4. package/dist/chunk-DCODCLWI.js +234 -0
  5. package/dist/chunk-DCODCLWI.js.map +1 -0
  6. package/dist/{chunk-5EOV5JQZ.js → chunk-EKAUQAAX.js} +50 -46
  7. package/dist/chunk-EKAUQAAX.js.map +1 -0
  8. package/dist/chunk-RM5XS6NR.js +113 -0
  9. package/dist/chunk-RM5XS6NR.js.map +1 -0
  10. package/dist/chunk-T32UHMZA.js +282 -0
  11. package/dist/chunk-T32UHMZA.js.map +1 -0
  12. package/dist/export-gif.d.ts +113 -0
  13. package/dist/export-gif.js +21 -0
  14. package/dist/export-gif.js.map +1 -0
  15. package/dist/index.d.ts +309 -27
  16. package/dist/index.js +2020 -836
  17. package/dist/index.js.map +1 -1
  18. package/dist/{mount-CUKQLeqD.d.ts → mount-CL-nA0f-.d.ts} +85 -2
  19. package/dist/simulation-worker.js +83 -2
  20. package/dist/static.d.ts +2 -0
  21. package/dist/static.js +8 -69
  22. package/dist/static.js.map +1 -1
  23. package/dist/story/index.d.ts +25 -9
  24. package/dist/story/index.js +9 -7
  25. package/dist/story/index.js.map +1 -1
  26. package/dist/styles.css +1 -1
  27. package/dist/styles.css.map +1 -1
  28. package/package.json +14 -6
  29. package/dist/chunk-5EOV5JQZ.js.map +0 -1
  30. package/dist/chunk-UZ7J3NOF.js.map +0 -1
  31. package/src/__test-fixtures__/dom.ts +0 -70
  32. package/src/__test-fixtures__/specs.ts +0 -214
  33. package/src/__tests__/animation.test.ts +0 -358
  34. package/src/__tests__/annotations-render.test.ts +0 -201
  35. package/src/__tests__/compound-labels.test.ts +0 -122
  36. package/src/__tests__/continuous-legend.test.ts +0 -91
  37. package/src/__tests__/crosshair.test.ts +0 -130
  38. package/src/__tests__/edit-events.test.ts +0 -950
  39. package/src/__tests__/events.test.ts +0 -387
  40. package/src/__tests__/export.test.ts +0 -241
  41. package/src/__tests__/font-race.test.ts +0 -199
  42. package/src/__tests__/gradient-ids.test.ts +0 -159
  43. package/src/__tests__/gradient-utils.test.ts +0 -125
  44. package/src/__tests__/known-bugs-render.test.ts +0 -183
  45. package/src/__tests__/map.test.ts +0 -636
  46. package/src/__tests__/mount.test.ts +0 -357
  47. package/src/__tests__/pattern-fills.test.ts +0 -105
  48. package/src/__tests__/resize-timing.test.ts +0 -218
  49. package/src/__tests__/sankey.test.ts +0 -133
  50. package/src/__tests__/selection-events.test.ts +0 -869
  51. package/src/__tests__/series-search.test.ts +0 -311
  52. package/src/__tests__/static.test.ts +0 -141
  53. package/src/__tests__/svg-renderer.test.ts +0 -895
  54. package/src/__tests__/table-keyboard.test.ts +0 -361
  55. package/src/__tests__/table-mount.test.ts +0 -639
  56. package/src/__tests__/tilemap.test.ts +0 -158
  57. package/src/__tests__/tooltip.test.ts +0 -337
  58. package/src/__tests__/transition.test.ts +0 -1792
  59. package/src/__tests__/update-scrolly-matrix.test.ts +0 -563
  60. package/src/__tests__/you-draw-it.test.ts +0 -273
  61. package/src/animation-vars.ts +0 -42
  62. package/src/animation.ts +0 -76
  63. package/src/barlist-mount.ts +0 -383
  64. package/src/barlist-renderer.ts +0 -267
  65. package/src/dom-helpers.ts +0 -17
  66. package/src/export.ts +0 -482
  67. package/src/gradient-utils.ts +0 -138
  68. package/src/graph/__tests__/canvas-renderer.test.ts +0 -713
  69. package/src/graph/__tests__/graph-mount.test.ts +0 -213
  70. package/src/graph/__tests__/interaction.test.ts +0 -205
  71. package/src/graph/__tests__/keyboard.test.ts +0 -653
  72. package/src/graph/__tests__/search.test.ts +0 -88
  73. package/src/graph/__tests__/simulation.test.ts +0 -233
  74. package/src/graph/__tests__/spatial-index.test.ts +0 -142
  75. package/src/graph/__tests__/zoom.test.ts +0 -203
  76. package/src/graph/canvas-renderer.ts +0 -747
  77. package/src/graph/interaction.ts +0 -367
  78. package/src/graph/keyboard.ts +0 -208
  79. package/src/graph/search.ts +0 -50
  80. package/src/graph/simulation-worker-url.ts +0 -12
  81. package/src/graph/simulation-worker.ts +0 -278
  82. package/src/graph/simulation.ts +0 -422
  83. package/src/graph/spatial-index.ts +0 -121
  84. package/src/graph/types.ts +0 -47
  85. package/src/graph/worker-protocol.ts +0 -70
  86. package/src/graph/zoom.ts +0 -134
  87. package/src/graph-mount.ts +0 -888
  88. package/src/index.ts +0 -76
  89. package/src/interactions/chart-events.ts +0 -139
  90. package/src/interactions/crosshair.ts +0 -233
  91. package/src/interactions/drag-handler.ts +0 -175
  92. package/src/interactions/editing-drags.ts +0 -515
  93. package/src/interactions/index.ts +0 -25
  94. package/src/interactions/keyboard-nav.ts +0 -111
  95. package/src/interactions/legend-interaction.ts +0 -46
  96. package/src/interactions/selection.ts +0 -280
  97. package/src/interactions/tooltip-events.ts +0 -72
  98. package/src/map-camera.ts +0 -111
  99. package/src/map-mount.ts +0 -792
  100. package/src/map-renderer.ts +0 -460
  101. package/src/map-transition.ts +0 -99
  102. package/src/measure-text.ts +0 -134
  103. package/src/mount.ts +0 -1382
  104. package/src/pattern-utils.ts +0 -110
  105. package/src/renderers/annotations.ts +0 -388
  106. package/src/renderers/axes.ts +0 -351
  107. package/src/renderers/brand.ts +0 -87
  108. package/src/renderers/chrome.ts +0 -196
  109. package/src/renderers/endpoint-labels.ts +0 -150
  110. package/src/renderers/legend.ts +0 -311
  111. package/src/renderers/marks.ts +0 -561
  112. package/src/renderers/metrics.ts +0 -63
  113. package/src/renderers/svg-dom.ts +0 -40
  114. package/src/renderers/table-cells.ts +0 -446
  115. package/src/resize-observer.ts +0 -46
  116. package/src/sankey-mount.ts +0 -622
  117. package/src/sankey-renderer.ts +0 -614
  118. package/src/series-search.ts +0 -392
  119. package/src/static.ts +0 -251
  120. package/src/story/__tests__/camera-math.test.ts +0 -145
  121. package/src/story/__tests__/create-chart-story.test.ts +0 -317
  122. package/src/story/__tests__/progress-math.test.ts +0 -95
  123. package/src/story/__tests__/scroll-driver.test.ts +0 -130
  124. package/src/story/__tests__/tween.test.ts +0 -159
  125. package/src/story/camera-math.ts +0 -125
  126. package/src/story/create-chart-story.ts +0 -353
  127. package/src/story/crossfade.ts +0 -70
  128. package/src/story/index.ts +0 -39
  129. package/src/story/progress-math.ts +0 -85
  130. package/src/story/resolve-camera-target.ts +0 -119
  131. package/src/story/scroll-driver.ts +0 -206
  132. package/src/story/story-camera.ts +0 -49
  133. package/src/story/tween.ts +0 -112
  134. package/src/story/types.ts +0 -76
  135. package/src/svg-ids.ts +0 -23
  136. package/src/svg-renderer.ts +0 -383
  137. package/src/table-keyboard.ts +0 -266
  138. package/src/table-mount.ts +0 -567
  139. package/src/table-renderer.ts +0 -414
  140. package/src/text-edit-overlay.ts +0 -255
  141. package/src/theme-tokens.ts +0 -51
  142. package/src/tilemap-mount.ts +0 -511
  143. package/src/tilemap-renderer.ts +0 -396
  144. package/src/tooltip.ts +0 -177
  145. package/src/transition.ts +0 -2816
  146. package/src/you-draw-it.ts +0 -480
  147. /package/dist/{chunk-W34KN7FD.js.map → chunk-2NAQRP66.js.map} +0 -0
@@ -1,446 +0,0 @@
1
- /**
2
- * Table cell renderers: produce DOM elements for each cell type.
3
- *
4
- * Each renderer takes a resolved TableCell and returns an HTMLElement
5
- * (typically a <td>) with appropriate content, styling, and classes.
6
- */
7
-
8
- import type {
9
- BarTableCell,
10
- CategoryTableCell,
11
- FlagTableCell,
12
- HeatmapTableCell,
13
- ImageTableCell,
14
- SparklineData,
15
- SparklineTableCell,
16
- TableCell,
17
- TextTableCell,
18
- } from '@opendata-ai/openchart-core';
19
-
20
- // ---------------------------------------------------------------------------
21
- // Utility
22
- // ---------------------------------------------------------------------------
23
-
24
- /** Apply common cell styles (background, color, font weight, font variant). */
25
- function applyCellStyle(td: HTMLTableCellElement, cell: TableCell): void {
26
- if (cell.style.backgroundColor) {
27
- td.style.background = cell.style.backgroundColor;
28
- }
29
- if (cell.style.color) {
30
- td.style.color = cell.style.color;
31
- }
32
- if (cell.style.fontWeight) {
33
- td.style.fontWeight = String(cell.style.fontWeight);
34
- }
35
- if (cell.style.fontVariant) {
36
- td.style.fontVariant = cell.style.fontVariant;
37
- }
38
- if (cell.aria) {
39
- td.setAttribute('aria-label', cell.aria);
40
- }
41
- }
42
-
43
- /**
44
- * Convert a 2-char ISO 3166-1 alpha-2 country code to a flag emoji.
45
- * Each letter maps to a Regional Indicator Symbol (offset 0x1F1A5 from ASCII).
46
- */
47
- function countryToEmoji(code: string): string {
48
- return [...code.toUpperCase()]
49
- .map((c) => String.fromCodePoint(c.charCodeAt(0) + 0x1f1a5))
50
- .join('');
51
- }
52
-
53
- /**
54
- * Lookup map for common country names by ISO 3166-1 alpha-2 code.
55
- * Falls back to the raw code for unrecognized values.
56
- */
57
- const COUNTRY_NAMES: Record<string, string> = {
58
- US: 'United States',
59
- CN: 'China',
60
- IN: 'India',
61
- ID: 'Indonesia',
62
- BR: 'Brazil',
63
- PK: 'Pakistan',
64
- NG: 'Nigeria',
65
- BD: 'Bangladesh',
66
- RU: 'Russia',
67
- MX: 'Mexico',
68
- JP: 'Japan',
69
- DE: 'Germany',
70
- GB: 'United Kingdom',
71
- FR: 'France',
72
- IT: 'Italy',
73
- CA: 'Canada',
74
- AU: 'Australia',
75
- KR: 'South Korea',
76
- ES: 'Spain',
77
- AR: 'Argentina',
78
- CO: 'Colombia',
79
- ZA: 'South Africa',
80
- TR: 'Turkey',
81
- SA: 'Saudi Arabia',
82
- UA: 'Ukraine',
83
- PL: 'Poland',
84
- NL: 'Netherlands',
85
- SE: 'Sweden',
86
- NO: 'Norway',
87
- DK: 'Denmark',
88
- FI: 'Finland',
89
- CH: 'Switzerland',
90
- AT: 'Austria',
91
- BE: 'Belgium',
92
- PT: 'Portugal',
93
- IE: 'Ireland',
94
- NZ: 'New Zealand',
95
- SG: 'Singapore',
96
- IL: 'Israel',
97
- AE: 'United Arab Emirates',
98
- EG: 'Egypt',
99
- TH: 'Thailand',
100
- VN: 'Vietnam',
101
- PH: 'Philippines',
102
- MY: 'Malaysia',
103
- CL: 'Chile',
104
- PE: 'Peru',
105
- CZ: 'Czech Republic',
106
- GR: 'Greece',
107
- HU: 'Hungary',
108
- RO: 'Romania',
109
- ET: 'Ethiopia',
110
- };
111
-
112
- /** Get a human-readable name for a country code. */
113
- function getCountryName(code: string): string {
114
- return COUNTRY_NAMES[code.toUpperCase()] || code.toUpperCase();
115
- }
116
-
117
- /**
118
- * Describe a sparkline trend for screen readers.
119
- * Compares first and last values to determine direction.
120
- */
121
- function describeSparklineTrend(data: SparklineData): string {
122
- if (data.type === 'line' && data.points.length >= 2) {
123
- const first = data.points[0].y;
124
- const last = data.points[data.points.length - 1].y;
125
- const count = data.points.length;
126
- if (last > first) return `Sparkline with ${count} points, trending upward`;
127
- if (last < first) return `Sparkline with ${count} points, trending downward`;
128
- return `Sparkline with ${count} points, roughly flat`;
129
- }
130
- if ((data.type === 'bar' || data.type === 'column') && data.bars.length > 0) {
131
- return `${data.type === 'column' ? 'Column' : 'Bar'} sparkline with ${data.bars.length} values`;
132
- }
133
- return 'Sparkline';
134
- }
135
-
136
- // ---------------------------------------------------------------------------
137
- // Cell renderers
138
- // ---------------------------------------------------------------------------
139
-
140
- /** Render a plain text cell. */
141
- export function renderTextCell(cell: TextTableCell): HTMLTableCellElement {
142
- const td = document.createElement('td');
143
- td.textContent = cell.formattedValue;
144
- applyCellStyle(td, cell);
145
- return td;
146
- }
147
-
148
- /** Render a heatmap-colored cell. */
149
- export function renderHeatmapCell(cell: HeatmapTableCell): HTMLTableCellElement {
150
- const td = document.createElement('td');
151
- td.className = 'oc-table-heatmap';
152
- td.textContent = cell.formattedValue;
153
- applyCellStyle(td, cell);
154
- return td;
155
- }
156
-
157
- /** Render a category-colored cell. */
158
- export function renderCategoryCell(cell: CategoryTableCell): HTMLTableCellElement {
159
- const td = document.createElement('td');
160
- td.className = 'oc-table-category';
161
- td.textContent = cell.formattedValue;
162
- applyCellStyle(td, cell);
163
- return td;
164
- }
165
-
166
- /** Render a cell with an inline bar visualization. */
167
- export function renderBarCell(cell: BarTableCell): HTMLTableCellElement {
168
- const td = document.createElement('td');
169
- td.className = 'oc-table-bar';
170
- applyCellStyle(td, cell);
171
-
172
- const fill = document.createElement('div');
173
- fill.className = 'oc-table-bar-fill';
174
- fill.style.width = `${Math.round(cell.barWidth * 100)}%`;
175
- fill.style.left = `${Math.round(cell.barOffset * 100)}%`;
176
- fill.style.background = cell.barColor;
177
- td.appendChild(fill);
178
-
179
- const valueSpan = document.createElement('span');
180
- valueSpan.className = 'oc-table-bar-value';
181
- valueSpan.textContent = cell.formattedValue;
182
- td.appendChild(valueSpan);
183
-
184
- return td;
185
- }
186
-
187
- /**
188
- * Format a sparkline endpoint value for display.
189
- * Keeps it compact: no decimals for values >= 100, one decimal otherwise.
190
- */
191
- function formatSparklineValue(v: number): string {
192
- if (Math.abs(v) >= 1000) {
193
- return v.toLocaleString('en-US', { maximumFractionDigits: 0 });
194
- }
195
- if (Math.abs(v) >= 100) {
196
- return v.toFixed(0);
197
- }
198
- return v.toFixed(1);
199
- }
200
-
201
- /** Render a cell with an inline sparkline SVG. */
202
- export function renderSparklineCell(cell: SparklineTableCell): HTMLTableCellElement {
203
- const td = document.createElement('td');
204
- applyCellStyle(td, cell);
205
-
206
- const sparklineData = cell.sparklineData;
207
- if (!sparklineData || sparklineData.count === 0) {
208
- td.textContent = cell.formattedValue || '';
209
- return td;
210
- }
211
-
212
- // Add aria-label describing the trend for screen readers
213
- const trendDescription = describeSparklineTrend(sparklineData);
214
- if (!td.getAttribute('aria-label')) {
215
- td.setAttribute('aria-label', trendDescription);
216
- }
217
-
218
- const wrapper = document.createElement('span');
219
- wrapper.className = 'oc-table-sparkline';
220
-
221
- const svgNS = 'http://www.w3.org/2000/svg';
222
-
223
- if (sparklineData.type === 'line') {
224
- // Infrographic-style sparkline: SVG polyline fills cell width via percentage x-coords.
225
- // Dots are HTML elements (not SVG circles) to avoid aspect-ratio distortion.
226
- // Labels are HTML below the SVG.
227
- const svgH = 28;
228
- const padY = 4;
229
- const lineH = svgH - padY * 2;
230
-
231
- const svg = document.createElementNS(svgNS, 'svg');
232
- svg.setAttribute('aria-hidden', 'true');
233
- svg.setAttribute('xmlns', svgNS);
234
- svg.style.height = `${svgH}px`;
235
-
236
- // Compute y positions in pixel space (no viewBox scaling)
237
- const yPositions = sparklineData.points.map((p) => padY + (1 - p.y) * lineH);
238
-
239
- // SVG polyline doesn't support % in points attribute, so use a viewBox
240
- // with a wide aspect ratio and map x to 0-1000 range. preserveAspectRatio="none"
241
- // stretches the x-axis to fill the cell width. Y values stay in pixel space
242
- // since viewBox height matches the SVG height. Only the polyline is in the SVG;
243
- // dots are HTML elements to avoid circle distortion from the non-uniform scaling.
244
- const viewW = 1000;
245
- svg.setAttribute('viewBox', `0 0 ${viewW} ${svgH}`);
246
- svg.setAttribute('preserveAspectRatio', 'none');
247
-
248
- const ptsScaled = sparklineData.points.map((p, i) => ({
249
- x: p.x * viewW,
250
- y: yPositions[i],
251
- }));
252
- const scaledPointsStr = ptsScaled.map((p) => `${p.x},${p.y}`).join(' ');
253
-
254
- const polyline = document.createElementNS(svgNS, 'polyline');
255
- polyline.setAttribute('points', scaledPointsStr);
256
- polyline.setAttribute('fill', 'none');
257
- polyline.setAttribute('stroke', sparklineData.color);
258
- polyline.setAttribute('stroke-width', '1.5');
259
- polyline.setAttribute('stroke-linejoin', 'round');
260
- polyline.setAttribute('vector-effect', 'non-scaling-stroke');
261
- svg.appendChild(polyline);
262
-
263
- wrapper.appendChild(svg);
264
-
265
- // HTML dots at start and end (positioned absolutely over the SVG)
266
- const firstY = yPositions[0];
267
- const lastY = yPositions[yPositions.length - 1];
268
- const dotSize = 5;
269
-
270
- const startDot = document.createElement('span');
271
- startDot.className = 'oc-table-sparkline-dot';
272
- startDot.style.left = '0';
273
- startDot.style.top = `${firstY - dotSize / 2}px`;
274
- startDot.style.background = sparklineData.color;
275
- wrapper.appendChild(startDot);
276
-
277
- const endDot = document.createElement('span');
278
- endDot.className = 'oc-table-sparkline-dot';
279
- endDot.style.right = '0';
280
- endDot.style.top = `${lastY - dotSize / 2}px`;
281
- endDot.style.background = sparklineData.color;
282
- wrapper.appendChild(endDot);
283
-
284
- // HTML labels below the SVG, positioned at left and right edges
285
- const labelsRow = document.createElement('span');
286
- labelsRow.className = 'oc-table-sparkline-labels';
287
- labelsRow.style.color = sparklineData.color;
288
-
289
- const startLabel = document.createElement('span');
290
- startLabel.textContent = formatSparklineValue(sparklineData.startValue);
291
- labelsRow.appendChild(startLabel);
292
-
293
- const endLabel = document.createElement('span');
294
- endLabel.textContent = formatSparklineValue(sparklineData.endValue);
295
- labelsRow.appendChild(endLabel);
296
-
297
- wrapper.appendChild(labelsRow);
298
- } else if (sparklineData.type === 'column') {
299
- // Vertical bars at proportional heights
300
- const width = 80;
301
- const height = 20;
302
- const padding = 2;
303
- const innerW = width - padding * 2;
304
- const innerH = height - padding * 2;
305
-
306
- const svg = document.createElementNS(svgNS, 'svg');
307
- svg.setAttribute('width', String(width));
308
- svg.setAttribute('height', String(height));
309
- svg.setAttribute('viewBox', `0 0 ${width} ${height}`);
310
- svg.setAttribute('aria-hidden', 'true');
311
-
312
- const barCount = sparklineData.bars.length;
313
- if (barCount > 0) {
314
- const gap = 1;
315
- const barW = Math.max(1, (innerW - gap * (barCount - 1)) / barCount);
316
-
317
- for (let i = 0; i < barCount; i++) {
318
- const barH = Math.max(1, sparklineData.bars[i] * innerH);
319
- const x = padding + i * (barW + gap);
320
- const y = padding + innerH - barH;
321
-
322
- const rect = document.createElementNS(svgNS, 'rect');
323
- rect.setAttribute('x', String(x));
324
- rect.setAttribute('y', String(y));
325
- rect.setAttribute('width', String(barW));
326
- rect.setAttribute('height', String(barH));
327
- rect.setAttribute('rx', '1.5');
328
- rect.setAttribute('fill', sparklineData.color);
329
- svg.appendChild(rect);
330
- }
331
- }
332
-
333
- wrapper.appendChild(svg);
334
- } else {
335
- // 'bar' type: horizontal bars at proportional widths
336
- const width = 80;
337
- const height = 20;
338
- const padding = 2;
339
- const innerW = width - padding * 2;
340
- const innerH = height - padding * 2;
341
-
342
- const svg = document.createElementNS(svgNS, 'svg');
343
- svg.setAttribute('width', String(width));
344
- svg.setAttribute('height', String(height));
345
- svg.setAttribute('viewBox', `0 0 ${width} ${height}`);
346
- svg.setAttribute('aria-hidden', 'true');
347
-
348
- const barCount = sparklineData.bars.length;
349
- if (barCount > 0) {
350
- const gap = 1;
351
- const barH = Math.max(1, (innerH - gap * (barCount - 1)) / barCount);
352
-
353
- for (let i = 0; i < barCount; i++) {
354
- const barW = Math.max(1, sparklineData.bars[i] * innerW);
355
- const x = padding;
356
- const y = padding + i * (barH + gap);
357
-
358
- const rect = document.createElementNS(svgNS, 'rect');
359
- rect.setAttribute('x', String(x));
360
- rect.setAttribute('y', String(y));
361
- rect.setAttribute('width', String(barW));
362
- rect.setAttribute('height', String(barH));
363
- rect.setAttribute('rx', '1.5');
364
- rect.setAttribute('fill', sparklineData.color);
365
- svg.appendChild(rect);
366
- }
367
- }
368
-
369
- wrapper.appendChild(svg);
370
- }
371
-
372
- td.appendChild(wrapper);
373
-
374
- return td;
375
- }
376
-
377
- /** Render a cell with an image. */
378
- export function renderImageCell(cell: ImageTableCell): HTMLTableCellElement {
379
- const td = document.createElement('td');
380
- applyCellStyle(td, cell);
381
-
382
- const wrapper = document.createElement('span');
383
- wrapper.className = `oc-table-image${cell.rounded ? ' oc-table-image-rounded' : ''}`;
384
-
385
- const img = document.createElement('img');
386
- img.src = cell.src;
387
- img.alt = cell.formattedValue || '';
388
- img.width = cell.imageWidth;
389
- img.height = cell.imageHeight;
390
- img.loading = 'lazy';
391
-
392
- wrapper.appendChild(img);
393
- td.appendChild(wrapper);
394
-
395
- return td;
396
- }
397
-
398
- /** Render a cell with a country flag emoji. */
399
- export function renderFlagCell(cell: FlagTableCell): HTMLTableCellElement {
400
- const td = document.createElement('td');
401
- applyCellStyle(td, cell);
402
-
403
- const span = document.createElement('span');
404
- span.className = 'oc-table-flag';
405
- span.setAttribute('role', 'img');
406
-
407
- if (cell.countryCode && cell.countryCode.length === 2) {
408
- const countryName = getCountryName(cell.countryCode);
409
- span.textContent = countryToEmoji(cell.countryCode);
410
- span.setAttribute('aria-label', `Flag: ${countryName}`);
411
- } else {
412
- span.textContent = cell.formattedValue;
413
- span.setAttribute('aria-label', cell.formattedValue);
414
- }
415
-
416
- td.appendChild(span);
417
-
418
- return td;
419
- }
420
-
421
- // ---------------------------------------------------------------------------
422
- // Dispatcher
423
- // ---------------------------------------------------------------------------
424
-
425
- /** Render any table cell by dispatching on its cellType. */
426
- export function renderCell(cell: TableCell): HTMLTableCellElement {
427
- switch (cell.cellType) {
428
- case 'text':
429
- return renderTextCell(cell);
430
- case 'heatmap':
431
- return renderHeatmapCell(cell);
432
- case 'category':
433
- return renderCategoryCell(cell);
434
- case 'bar':
435
- return renderBarCell(cell);
436
- case 'sparkline':
437
- return renderSparklineCell(cell);
438
- case 'image':
439
- return renderImageCell(cell);
440
- case 'flag':
441
- return renderFlagCell(cell);
442
- default:
443
- // Exhaustive check fallback
444
- return renderTextCell(cell as TextTableCell);
445
- }
446
- }
@@ -1,46 +0,0 @@
1
- /**
2
- * Resize observer: thin wrapper around ResizeObserver with debounce.
3
- *
4
- * Watches a container element for size changes and calls back with
5
- * the new width and height. Debounced at ~60fps (16ms) to avoid
6
- * excessive re-renders during drag resizes.
7
- */
8
-
9
- const DEBOUNCE_MS = 16;
10
-
11
- /**
12
- * Observe a container element for size changes.
13
- *
14
- * @param container - The element to watch.
15
- * @param callback - Called with (width, height) when size changes.
16
- * @returns A cleanup function that disconnects the observer.
17
- */
18
- export function observeResize(
19
- container: HTMLElement,
20
- callback: (width: number, height: number) => void,
21
- ): () => void {
22
- let timeoutId: ReturnType<typeof setTimeout> | null = null;
23
-
24
- const observer = new ResizeObserver((entries) => {
25
- // Debounce to ~60fps
26
- if (timeoutId !== null) {
27
- clearTimeout(timeoutId);
28
- }
29
- timeoutId = setTimeout(() => {
30
- for (const entry of entries) {
31
- const { width, height } = entry.contentRect;
32
- callback(width, height);
33
- }
34
- timeoutId = null;
35
- }, DEBOUNCE_MS);
36
- });
37
-
38
- observer.observe(container);
39
-
40
- return () => {
41
- if (timeoutId !== null) {
42
- clearTimeout(timeoutId);
43
- }
44
- observer.disconnect();
45
- };
46
- }