@opendata-ai/openchart-vanilla 8.0.0-rc.9 → 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.
- package/dist/{chunk-SPILUE5S.js → chunk-2NAQRP66.js} +2 -2
- package/dist/{chunk-IZQBT6QM.js → chunk-6BUCYCLD.js} +7283 -5881
- package/dist/chunk-6BUCYCLD.js.map +1 -0
- package/dist/chunk-DCODCLWI.js +234 -0
- package/dist/chunk-DCODCLWI.js.map +1 -0
- package/dist/{chunk-QW7ZB6NE.js → chunk-EKAUQAAX.js} +49 -45
- package/dist/chunk-EKAUQAAX.js.map +1 -0
- package/dist/chunk-RM5XS6NR.js +113 -0
- package/dist/chunk-RM5XS6NR.js.map +1 -0
- package/dist/chunk-T32UHMZA.js +282 -0
- package/dist/chunk-T32UHMZA.js.map +1 -0
- package/dist/export-gif.d.ts +113 -0
- package/dist/export-gif.js +21 -0
- package/dist/export-gif.js.map +1 -0
- package/dist/index.d.ts +309 -27
- package/dist/index.js +2020 -836
- package/dist/index.js.map +1 -1
- package/dist/{mount-CUKQLeqD.d.ts → mount-CL-nA0f-.d.ts} +85 -2
- package/dist/simulation-worker.js +83 -2
- package/dist/static.d.ts +2 -0
- package/dist/static.js +8 -69
- package/dist/static.js.map +1 -1
- package/dist/story/index.d.ts +25 -9
- package/dist/story/index.js +9 -7
- package/dist/story/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/styles.css.map +1 -1
- package/package.json +14 -6
- package/dist/chunk-IZQBT6QM.js.map +0 -1
- package/dist/chunk-QW7ZB6NE.js.map +0 -1
- package/src/__test-fixtures__/dom.ts +0 -70
- package/src/__test-fixtures__/specs.ts +0 -214
- package/src/__tests__/animation.test.ts +0 -358
- package/src/__tests__/annotations-render.test.ts +0 -201
- package/src/__tests__/compound-labels.test.ts +0 -122
- package/src/__tests__/continuous-legend.test.ts +0 -91
- package/src/__tests__/crosshair.test.ts +0 -130
- package/src/__tests__/edit-events.test.ts +0 -1477
- package/src/__tests__/editable-prop.test.ts +0 -174
- package/src/__tests__/events.test.ts +0 -387
- package/src/__tests__/export.test.ts +0 -241
- package/src/__tests__/font-race.test.ts +0 -199
- package/src/__tests__/gradient-ids.test.ts +0 -159
- package/src/__tests__/gradient-utils.test.ts +0 -125
- package/src/__tests__/invert.test.ts +0 -187
- package/src/__tests__/known-bugs-render.test.ts +0 -183
- package/src/__tests__/map.test.ts +0 -636
- package/src/__tests__/mount.test.ts +0 -357
- package/src/__tests__/pattern-fills.test.ts +0 -105
- package/src/__tests__/resize-timing.test.ts +0 -218
- package/src/__tests__/sankey.test.ts +0 -133
- package/src/__tests__/selection-events.test.ts +0 -1062
- package/src/__tests__/series-search.test.ts +0 -311
- package/src/__tests__/static.test.ts +0 -141
- package/src/__tests__/svg-renderer.test.ts +0 -895
- package/src/__tests__/table-keyboard.test.ts +0 -361
- package/src/__tests__/table-mount.test.ts +0 -639
- package/src/__tests__/tilemap.test.ts +0 -158
- package/src/__tests__/tooltip.test.ts +0 -337
- package/src/__tests__/transition.test.ts +0 -1792
- package/src/__tests__/update-scrolly-matrix.test.ts +0 -563
- package/src/__tests__/you-draw-it.test.ts +0 -273
- package/src/animation-vars.ts +0 -42
- package/src/animation.ts +0 -76
- package/src/barlist-mount.ts +0 -383
- package/src/barlist-renderer.ts +0 -267
- package/src/dom-helpers.ts +0 -17
- package/src/export.ts +0 -482
- package/src/gradient-utils.ts +0 -138
- package/src/graph/__tests__/canvas-renderer.test.ts +0 -713
- package/src/graph/__tests__/graph-mount.test.ts +0 -213
- package/src/graph/__tests__/interaction.test.ts +0 -205
- package/src/graph/__tests__/keyboard.test.ts +0 -653
- package/src/graph/__tests__/search.test.ts +0 -88
- package/src/graph/__tests__/simulation.test.ts +0 -233
- package/src/graph/__tests__/spatial-index.test.ts +0 -142
- package/src/graph/__tests__/zoom.test.ts +0 -203
- package/src/graph/canvas-renderer.ts +0 -747
- package/src/graph/interaction.ts +0 -367
- package/src/graph/keyboard.ts +0 -208
- package/src/graph/search.ts +0 -50
- package/src/graph/simulation-worker-url.ts +0 -12
- package/src/graph/simulation-worker.ts +0 -278
- package/src/graph/simulation.ts +0 -422
- package/src/graph/spatial-index.ts +0 -121
- package/src/graph/types.ts +0 -47
- package/src/graph/worker-protocol.ts +0 -70
- package/src/graph/zoom.ts +0 -134
- package/src/graph-mount.ts +0 -888
- package/src/index.ts +0 -76
- package/src/interactions/chart-events.ts +0 -139
- package/src/interactions/crosshair.ts +0 -233
- package/src/interactions/drag-handler.ts +0 -175
- package/src/interactions/editing-drags.ts +0 -649
- package/src/interactions/index.ts +0 -27
- package/src/interactions/invert.ts +0 -54
- package/src/interactions/keyboard-nav.ts +0 -111
- package/src/interactions/legend-interaction.ts +0 -46
- package/src/interactions/selection.ts +0 -286
- package/src/interactions/tooltip-events.ts +0 -72
- package/src/map-camera.ts +0 -111
- package/src/map-mount.ts +0 -797
- package/src/map-renderer.ts +0 -476
- package/src/map-transition.ts +0 -99
- package/src/measure-text.ts +0 -134
- package/src/mount.ts +0 -1434
- package/src/pattern-utils.ts +0 -110
- package/src/renderers/annotations.ts +0 -388
- package/src/renderers/axes.ts +0 -351
- package/src/renderers/brand.ts +0 -87
- package/src/renderers/chrome.ts +0 -196
- package/src/renderers/endpoint-labels.ts +0 -150
- package/src/renderers/legend.ts +0 -312
- package/src/renderers/marks.ts +0 -561
- package/src/renderers/metrics.ts +0 -63
- package/src/renderers/svg-dom.ts +0 -40
- package/src/renderers/table-cells.ts +0 -446
- package/src/resize-observer.ts +0 -46
- package/src/sankey-mount.ts +0 -622
- package/src/sankey-renderer.ts +0 -614
- package/src/series-search.ts +0 -392
- package/src/static.ts +0 -251
- package/src/story/__tests__/camera-math.test.ts +0 -145
- package/src/story/__tests__/create-chart-story.test.ts +0 -317
- package/src/story/__tests__/progress-math.test.ts +0 -95
- package/src/story/__tests__/scroll-driver.test.ts +0 -130
- package/src/story/__tests__/tween.test.ts +0 -159
- package/src/story/camera-math.ts +0 -125
- package/src/story/create-chart-story.ts +0 -353
- package/src/story/crossfade.ts +0 -70
- package/src/story/index.ts +0 -39
- package/src/story/progress-math.ts +0 -85
- package/src/story/resolve-camera-target.ts +0 -119
- package/src/story/scroll-driver.ts +0 -206
- package/src/story/story-camera.ts +0 -49
- package/src/story/tween.ts +0 -112
- package/src/story/types.ts +0 -76
- package/src/svg-ids.ts +0 -23
- package/src/svg-renderer.ts +0 -383
- package/src/table-keyboard.ts +0 -266
- package/src/table-mount.ts +0 -567
- package/src/table-renderer.ts +0 -414
- package/src/text-edit-overlay.ts +0 -389
- package/src/theme-tokens.ts +0 -51
- package/src/tilemap-mount.ts +0 -511
- package/src/tilemap-renderer.ts +0 -396
- package/src/tooltip.ts +0 -177
- package/src/transition.ts +0 -2816
- package/src/you-draw-it.ts +0 -480
- /package/dist/{chunk-SPILUE5S.js.map → chunk-2NAQRP66.js.map} +0 -0
package/src/measure-text.ts
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Canvas-backed text measurement factory.
|
|
3
|
-
*
|
|
4
|
-
* Shared by mount.ts (charts) and sankey-mount.ts (sankey diagrams) so both
|
|
5
|
-
* pipelines get accurate browser-measured text widths instead of the heuristic
|
|
6
|
-
* fallback. Falls back to the heuristic when canvas isn't available (e.g. SSR).
|
|
7
|
-
*
|
|
8
|
-
* The font family is passed in (resolved from the container's --oc-font-family
|
|
9
|
-
* or the spec theme) rather than hardcoded, so measurement matches what the SVG
|
|
10
|
-
* text actually renders with. This matters on real devices where the primary
|
|
11
|
-
* webfont (e.g. Inter) loads late: measuring against the wrong font produces
|
|
12
|
-
* wrong widths and mangles layout.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
import type { MeasureTextFn } from '@opendata-ai/openchart-core';
|
|
16
|
-
import { estimateTextWidth } from '@opendata-ai/openchart-core';
|
|
17
|
-
|
|
18
|
-
const DEFAULT_FONT_FAMILY = 'Inter, sans-serif';
|
|
19
|
-
|
|
20
|
-
export function createMeasureText(fontFamily: string = DEFAULT_FONT_FAMILY): MeasureTextFn {
|
|
21
|
-
let canvas: HTMLCanvasElement | null = null;
|
|
22
|
-
let ctx: CanvasRenderingContext2D | null = null;
|
|
23
|
-
|
|
24
|
-
return (
|
|
25
|
-
text: string,
|
|
26
|
-
fontSize: number,
|
|
27
|
-
fontWeight?: number,
|
|
28
|
-
): { width: number; height: number } => {
|
|
29
|
-
if (!canvas) {
|
|
30
|
-
canvas = document.createElement('canvas');
|
|
31
|
-
ctx = canvas.getContext('2d');
|
|
32
|
-
}
|
|
33
|
-
if (!ctx) {
|
|
34
|
-
// Fallback: heuristic estimation
|
|
35
|
-
return {
|
|
36
|
-
width: estimateTextWidth(text, fontSize, fontWeight ?? 400),
|
|
37
|
-
height: fontSize * 1.2,
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const weight = fontWeight ?? 400;
|
|
42
|
-
ctx.font = `${weight} ${fontSize}px ${fontFamily}`;
|
|
43
|
-
const metrics = ctx.measureText(text);
|
|
44
|
-
return {
|
|
45
|
-
width: metrics.width,
|
|
46
|
-
height: fontSize * 1.2,
|
|
47
|
-
};
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Resolve the font family a container's SVG text will actually render with.
|
|
53
|
-
*
|
|
54
|
-
* Reads the --oc-font-family custom property (set by tokens.css once .oc-root
|
|
55
|
-
* is applied, or overridden per-spec by the theme resolver), falling back to
|
|
56
|
-
* the container's computed fontFamily, then to the default Inter stack. Returns
|
|
57
|
-
* the previous hardcoded stack when there is no DOM (SSR) or no computed style.
|
|
58
|
-
*/
|
|
59
|
-
export function resolveFontFamily(container: HTMLElement): string {
|
|
60
|
-
if (typeof window === 'undefined' || typeof getComputedStyle !== 'function') {
|
|
61
|
-
return DEFAULT_FONT_FAMILY;
|
|
62
|
-
}
|
|
63
|
-
try {
|
|
64
|
-
const style = getComputedStyle(container);
|
|
65
|
-
const custom = style.getPropertyValue('--oc-font-family').trim();
|
|
66
|
-
if (custom) return custom;
|
|
67
|
-
const computed = style.fontFamily?.trim();
|
|
68
|
-
if (computed) return computed;
|
|
69
|
-
} catch {
|
|
70
|
-
// getComputedStyle can throw on detached nodes in some engines; fall through.
|
|
71
|
-
}
|
|
72
|
-
return DEFAULT_FONT_FAMILY;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* The first family in a CSS font stack, with surrounding quotes stripped, e.g.
|
|
77
|
-
* `'"Inter Variable", Inter, sans-serif'` -> `Inter Variable`. Used to build a
|
|
78
|
-
* representative check string for document.fonts.check().
|
|
79
|
-
*/
|
|
80
|
-
export function primaryFontName(fontFamily: string): string {
|
|
81
|
-
const first = fontFamily.split(',')[0]?.trim() ?? '';
|
|
82
|
-
return first.replace(/^["']|["']$/g, '').trim();
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* True when the primary font of the resolved stack is not yet loaded and a
|
|
87
|
-
* later document.fonts.ready may change text metrics. False when fonts are
|
|
88
|
-
* ready, unavailable (SSR / no FontFaceSet), or the primary is a generic family.
|
|
89
|
-
*/
|
|
90
|
-
export function fontsPending(fontFamily: string): boolean {
|
|
91
|
-
if (typeof document === 'undefined') return false;
|
|
92
|
-
const fonts = (document as Document & { fonts?: FontFaceSet }).fonts;
|
|
93
|
-
if (!fonts || typeof fonts.check !== 'function') return false;
|
|
94
|
-
const name = primaryFontName(fontFamily);
|
|
95
|
-
if (!name) return false;
|
|
96
|
-
const generics = new Set([
|
|
97
|
-
'sans-serif',
|
|
98
|
-
'serif',
|
|
99
|
-
'monospace',
|
|
100
|
-
'system-ui',
|
|
101
|
-
'cursive',
|
|
102
|
-
'fantasy',
|
|
103
|
-
'ui-sans-serif',
|
|
104
|
-
'ui-serif',
|
|
105
|
-
'ui-monospace',
|
|
106
|
-
]);
|
|
107
|
-
if (generics.has(name.toLowerCase())) return false;
|
|
108
|
-
try {
|
|
109
|
-
return !fonts.check(`12px "${name}"`);
|
|
110
|
-
} catch {
|
|
111
|
-
return false;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Run `onReady` exactly once after webfonts finish loading, if they were
|
|
117
|
-
* pending at call time. `isAlive` is checked before invoking so a destroyed
|
|
118
|
-
* chart is never re-rendered. Returns the initial pending state so callers can
|
|
119
|
-
* set their `ocFontsState` dataset flag. No-op (returns false) under SSR or
|
|
120
|
-
* when the primary font is already loaded.
|
|
121
|
-
*/
|
|
122
|
-
export function scheduleFontReload(
|
|
123
|
-
fontFamily: string,
|
|
124
|
-
isAlive: () => boolean,
|
|
125
|
-
onReady: () => void,
|
|
126
|
-
): boolean {
|
|
127
|
-
if (!fontsPending(fontFamily)) return false;
|
|
128
|
-
const fonts = (document as Document & { fonts?: FontFaceSet }).fonts;
|
|
129
|
-
if (!fonts?.ready) return false;
|
|
130
|
-
fonts.ready.then(() => {
|
|
131
|
-
if (isAlive()) onReady();
|
|
132
|
-
});
|
|
133
|
-
return true;
|
|
134
|
-
}
|