@opendata-ai/openchart-vanilla 8.9.0 → 9.0.0-rc.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.
- package/README.md +4 -4
- package/dist/{chunk-2OJZBMXM.js → chunk-46E3QB6O.js} +51 -65
- package/dist/chunk-46E3QB6O.js.map +1 -0
- package/dist/{chunk-YBVDBY6P.js → chunk-5ZLSMZRM.js} +466 -332
- package/dist/chunk-5ZLSMZRM.js.map +1 -0
- package/dist/{chunk-YHZAH6EN.js → chunk-6YPRYQKD.js} +16 -50
- package/dist/chunk-6YPRYQKD.js.map +1 -0
- package/dist/{chunk-SDJHUELU.js → chunk-A5C4VCUO.js} +26 -45
- package/dist/chunk-A5C4VCUO.js.map +1 -0
- package/dist/{chunk-MGFXAROR.js → chunk-CMIJA63X.js} +5 -3
- package/dist/chunk-CMIJA63X.js.map +1 -0
- package/dist/{chunk-TP3GCWCO.js → chunk-ERPYVYFW.js} +1609 -300
- package/dist/chunk-ERPYVYFW.js.map +1 -0
- package/dist/chunk-FFP5GXIP.js +45 -0
- package/dist/chunk-FFP5GXIP.js.map +1 -0
- package/dist/chunk-NLKQ5AOA.js +448 -0
- package/dist/chunk-NLKQ5AOA.js.map +1 -0
- package/dist/{chunk-R5TZHNTG.js → chunk-RBXIZJPE.js} +17 -5
- package/dist/chunk-RBXIZJPE.js.map +1 -0
- package/dist/{chunk-6TD7GWR4.js → chunk-T6IPHUN4.js} +2359 -2101
- package/dist/chunk-T6IPHUN4.js.map +1 -0
- package/dist/export-gif.d.ts +2 -2
- package/dist/export-gif.js +4 -3
- package/dist/graph-3d/index.d.ts +1 -1
- package/dist/graph-3d/index.js +25 -7
- package/dist/graph-3d/index.js.map +1 -1
- package/dist/index.d.ts +155 -29
- package/dist/index.js +1774 -186
- package/dist/index.js.map +1 -1
- package/dist/{mount-FmUdKlCq.d.ts → mount-types-DeUCa2hy.d.ts} +38 -20
- package/dist/{renderer-registry-Cng76n8F.d.ts → renderer-registry-Bu22Roek.d.ts} +5 -22
- package/dist/simulation-worker.js +1 -0
- package/dist/static.d.ts +4 -2
- package/dist/static.js +34 -10
- package/dist/static.js.map +1 -1
- package/dist/story/index.d.ts +8 -6
- package/dist/story/index.js +15 -12
- package/dist/story/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/styles.css.map +1 -1
- package/package.json +3 -3
- package/dist/chunk-2OJZBMXM.js.map +0 -1
- package/dist/chunk-6TD7GWR4.js.map +0 -1
- package/dist/chunk-MGFXAROR.js.map +0 -1
- package/dist/chunk-NG7CVCI2.js +0 -58
- package/dist/chunk-NG7CVCI2.js.map +0 -1
- package/dist/chunk-R5TZHNTG.js.map +0 -1
- package/dist/chunk-SDJHUELU.js.map +0 -1
- package/dist/chunk-TP3GCWCO.js.map +0 -1
- package/dist/chunk-YBVDBY6P.js.map +0 -1
- package/dist/chunk-YHZAH6EN.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ResolvedTheme, Point, ChartSpec, LayerSpec,
|
|
1
|
+
import { ResolvedTheme, Point, ChartSpec, LayerSpec, ElementRef, ChartLayout, ChartEventHandlers, ThemeConfig, DarkMode } from '@opendata-ai/openchart-core';
|
|
2
2
|
import { GIFExportOptions } from './export-gif.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -219,16 +219,38 @@ interface TransitionHandle {
|
|
|
219
219
|
readonly totalMs: number;
|
|
220
220
|
}
|
|
221
221
|
|
|
222
|
+
/** Public types for chart mounts: options, update options, and the instance API. */
|
|
223
|
+
|
|
222
224
|
/**
|
|
223
|
-
*
|
|
225
|
+
* What a chart lets the reader do with its elements.
|
|
224
226
|
*
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
*
|
|
228
|
-
*
|
|
227
|
+
* - `'read'`: no selection or editing; arrow keys navigate data points.
|
|
228
|
+
* - `'select'`: click/Tab selection with `onSelect`/`onDeselect`; arrow keys
|
|
229
|
+
* still navigate data. No drags, nudges, text editing, or delete.
|
|
230
|
+
* - `'edit'`: selection plus every edit gesture, emitted through `onEdit`.
|
|
231
|
+
* Arrow keys nudge the selection instead of navigating data.
|
|
229
232
|
*/
|
|
230
|
-
|
|
233
|
+
type InteractionMode = 'read' | 'select' | 'edit';
|
|
234
|
+
/**
|
|
235
|
+
* Resolve the interaction mode a mount runs in. An explicit `interaction`
|
|
236
|
+
* wins; otherwise `onEdit` implies `'edit'`, `onSelect`/`onDeselect` imply
|
|
237
|
+
* `'select'`, and no callbacks means `'read'`.
|
|
238
|
+
*/
|
|
239
|
+
declare function resolveInteractionMode(opts?: {
|
|
240
|
+
interaction?: InteractionMode;
|
|
241
|
+
onEdit?: unknown;
|
|
242
|
+
onSelect?: unknown;
|
|
243
|
+
onDeselect?: unknown;
|
|
244
|
+
}): InteractionMode;
|
|
231
245
|
interface MountOptions extends ChartEventHandlers {
|
|
246
|
+
/** Quiet row inspection for simple horizontal bars. Runtime only; omitted by default. */
|
|
247
|
+
rowHover?: boolean;
|
|
248
|
+
/**
|
|
249
|
+
* Interaction mode. When omitted it is inferred once from the callbacks:
|
|
250
|
+
* `onEdit` -> `'edit'`, `onSelect`/`onDeselect` -> `'select'`, else `'read'`.
|
|
251
|
+
* See {@link InteractionMode}.
|
|
252
|
+
*/
|
|
253
|
+
interaction?: InteractionMode;
|
|
232
254
|
/** Theme overrides. */
|
|
233
255
|
theme?: ThemeConfig;
|
|
234
256
|
/** Dark mode setting: "auto" (system pref), "force", or "off". */
|
|
@@ -240,16 +262,16 @@ interface MountOptions extends ChartEventHandlers {
|
|
|
240
262
|
* console warning for non-point marks and faceted/layered/sparkline charts.
|
|
241
263
|
*/
|
|
242
264
|
renderer?: 'auto' | 'svg' | 'canvas';
|
|
243
|
-
/**
|
|
244
|
-
|
|
245
|
-
/** Enable responsive resizing. Defaults to true. */
|
|
246
|
-
responsive?: boolean;
|
|
265
|
+
/** Observe container resizing. Defaults to true. */
|
|
266
|
+
autoResize?: boolean;
|
|
247
267
|
/** Show the OpenData watermark. Defaults to true. */
|
|
248
268
|
watermark?: boolean;
|
|
249
269
|
/** Initial selected element. */
|
|
250
270
|
selectedElement?: ElementRef;
|
|
251
271
|
}
|
|
252
272
|
interface UpdateOptions {
|
|
273
|
+
/** Source revision for subsequent edit transactions. */
|
|
274
|
+
revision?: string | number;
|
|
253
275
|
/** Override the selected element after update. When omitted, preserves current selection. */
|
|
254
276
|
selectedElement?: ElementRef;
|
|
255
277
|
}
|
|
@@ -257,14 +279,14 @@ interface ExportOptions extends JPGExportOptions {
|
|
|
257
279
|
}
|
|
258
280
|
interface ChartInstance {
|
|
259
281
|
/** Re-compile and re-render with a new spec. */
|
|
260
|
-
update(spec: ChartSpec | LayerSpec
|
|
282
|
+
update(spec: ChartSpec | LayerSpec, options?: UpdateOptions): void;
|
|
261
283
|
/**
|
|
262
284
|
* Re-render with a new spec and start a MANUAL update transition the caller
|
|
263
285
|
* drives via `handle.step(elapsedMs)`, with no rAF clock. Returns the handle,
|
|
264
286
|
* or null when no transition applies (the render already swapped instantly).
|
|
265
287
|
* For headless frame capture (e.g. GIF export of a spec-swap stepper).
|
|
266
288
|
*/
|
|
267
|
-
beginManualUpdate(spec: ChartSpec | LayerSpec
|
|
289
|
+
beginManualUpdate(spec: ChartSpec | LayerSpec): TransitionHandle | null;
|
|
268
290
|
/** Re-compile at current container dimensions. */
|
|
269
291
|
resize(): void;
|
|
270
292
|
/** Geometry currently visible, sampled on demand for reader hit testing. */
|
|
@@ -287,8 +309,8 @@ interface ChartInstance {
|
|
|
287
309
|
select(ref: ElementRef): void;
|
|
288
310
|
/** Deselect the current element. */
|
|
289
311
|
deselect(): void;
|
|
290
|
-
/** Whether inline text editing is active. */
|
|
291
|
-
readonly
|
|
312
|
+
/** Whether inline text editing (the annotation/chrome text overlay) is active. */
|
|
313
|
+
readonly isTextEditing: boolean;
|
|
292
314
|
/** Set highlight values on the color encoding and re-render. Pass null to clear. */
|
|
293
315
|
setHighlight(values: string[] | null): void;
|
|
294
316
|
/**
|
|
@@ -302,9 +324,5 @@ interface ChartInstance {
|
|
|
302
324
|
*/
|
|
303
325
|
revealDrawing(): void;
|
|
304
326
|
}
|
|
305
|
-
/**
|
|
306
|
-
* Create a chart instance from a spec and mount it into a container.
|
|
307
|
-
*/
|
|
308
|
-
declare function createChart<TData extends DataRow = DataRow>(container: HTMLElement, spec: ChartSpec<TData> | LayerSpec<TData> | GraphSpec, options?: MountOptions): ChartInstance;
|
|
309
327
|
|
|
310
|
-
export { type Camera as C, type ExportOptions as E, FULL_VIEW as F, type JPGExportOptions as J, type MountOptions as M, type PNGExportOptions as P, type SVGExportOptions as S, type UpdateOptions as U, type ViewBoxSize as V, type ChartInstance as a, exportJPG as b,
|
|
328
|
+
export { type Camera as C, type ExportOptions as E, FULL_VIEW as F, type InteractionMode as I, type JPGExportOptions as J, type MountOptions as M, type PNGExportOptions as P, type SVGExportOptions as S, type UpdateOptions as U, type ViewBoxSize as V, type ChartInstance as a, exportJPG as b, exportPNG as c, exportSVG as d, exportCSV as e, exportSVGWithFonts as f, type CameraTarget as g, cameraTransform as h, camerasClose as i, damp as j, dampCamera as k, fitTarget as l, interpolateCamera as m, resolveInteractionMode as r, scrubCamera as s };
|
|
@@ -91,14 +91,7 @@ interface CameraFlightOptions {
|
|
|
91
91
|
ease?: AnimationEase;
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
/**
|
|
95
|
-
* Graph mount API: the main entry point for vanilla JS graph usage.
|
|
96
|
-
*
|
|
97
|
-
* createGraph() takes a container, GraphSpec, and options, compiles the graph,
|
|
98
|
-
* creates a force simulation, canvas renderer, spatial index, interaction
|
|
99
|
-
* manager, and search manager, then runs an animation loop driven by
|
|
100
|
-
* simulation ticks. Returns a GraphInstance with update/search/zoom/destroy.
|
|
101
|
-
*/
|
|
94
|
+
/** Public types for graph mounts: options, tooltip formatter, legend data, and the instance API. */
|
|
102
95
|
|
|
103
96
|
/** A hovered node or edge, passed to a tooltip formatter. */
|
|
104
97
|
interface GraphTooltipItem {
|
|
@@ -142,7 +135,8 @@ interface GraphMountOptions {
|
|
|
142
135
|
* recompile doesn't spam the console on `update()`.
|
|
143
136
|
*/
|
|
144
137
|
onWarn?: (message: string) => void;
|
|
145
|
-
|
|
138
|
+
/** Observe container resizing. Defaults to true. */
|
|
139
|
+
autoResize?: boolean;
|
|
146
140
|
/** Show the OpenData watermark. Defaults to true. */
|
|
147
141
|
watermark?: boolean;
|
|
148
142
|
/** Show the built-in tooltip; pass an object for a custom formatter. Defaults to true. */
|
|
@@ -191,8 +185,6 @@ interface GraphMountOptions {
|
|
|
191
185
|
}
|
|
192
186
|
interface GraphInstance {
|
|
193
187
|
update(spec: GraphSpec): void;
|
|
194
|
-
/** Re-compile encoding/legend/chrome without restarting the simulation. Preserves node positions. */
|
|
195
|
-
updateVisuals(spec: GraphSpec): void;
|
|
196
188
|
search(query: string): void;
|
|
197
189
|
clearSearch(): void;
|
|
198
190
|
/** Fit all nodes into the viewport. Animated by default; `{ duration: 0 }` snaps. */
|
|
@@ -244,15 +236,6 @@ interface GraphInstance {
|
|
|
244
236
|
resize(): void;
|
|
245
237
|
destroy(): void;
|
|
246
238
|
}
|
|
247
|
-
/**
|
|
248
|
-
* Create a graph instance from a spec and mount it into a container.
|
|
249
|
-
*
|
|
250
|
-
* @param container - The DOM element to render into.
|
|
251
|
-
* @param spec - The graph spec.
|
|
252
|
-
* @param options - Mount options.
|
|
253
|
-
* @returns A GraphInstance with update/search/zoom/destroy methods.
|
|
254
|
-
*/
|
|
255
|
-
declare function createGraph(container: HTMLElement, spec: GraphSpec, options?: GraphMountOptions): GraphInstance;
|
|
256
239
|
|
|
257
240
|
/**
|
|
258
241
|
* Tooltip manager: creates and positions a floating tooltip element.
|
|
@@ -357,7 +340,7 @@ interface GraphShell {
|
|
|
357
340
|
height: number;
|
|
358
341
|
};
|
|
359
342
|
/**
|
|
360
|
-
* Subscribe to container resizes. Honours `options.
|
|
343
|
+
* Subscribe to container resizes. Honours `options.autoResize === false`
|
|
361
344
|
* (returns a no-op disconnect). The ResizeObserver fires once on first
|
|
362
345
|
* layout, so renderers must tolerate an immediate callback.
|
|
363
346
|
*/
|
|
@@ -380,4 +363,4 @@ type GraphRendererFactory = (ctx: GraphRendererContext) => GraphInstance;
|
|
|
380
363
|
declare function registerGraphRenderer(dimensions: 3, factory: GraphRendererFactory): void;
|
|
381
364
|
declare const GRAPH_3D_NOT_REGISTERED_ERROR = "createGraph: dimensions: 3 requires import \"@opendata-ai/openchart-vanilla/graph-3d\"";
|
|
382
365
|
|
|
383
|
-
export { type CameraFlightOptions as C,
|
|
366
|
+
export { type CameraFlightOptions as C, type GraphMountOptions as G, type TooltipManager as T, type GraphInstance as a, GRAPH_3D_NOT_REGISTERED_ERROR as b, type GraphCamera as c, type GraphFlyTarget as d, type GraphHighlightTarget as e, type GraphLegendData as f, type GraphRendererContext as g, type GraphRendererFactory as h, type GraphShell as i, type GraphTooltipFormatter as j, type GraphTooltipItem as k, createTooltipManager as l, registerGraphRenderer as r };
|
package/dist/static.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { ThemeConfig, DarkMode, ChartSpec, LayerSpec, TileMapSpec } from '@opendata-ai/openchart-core';
|
|
1
|
+
import { ThemeConfig, DarkMode, ChartSpec, LayerSpec, TileMapSpec, GeoMapSpec } from '@opendata-ai/openchart-core';
|
|
2
2
|
|
|
3
3
|
interface StaticRenderOptions {
|
|
4
|
+
/** Stable XML-safe prefix. Use distinct prefixes for figures sharing one document. */
|
|
5
|
+
idPrefix?: string;
|
|
4
6
|
width?: number;
|
|
5
7
|
height?: number;
|
|
6
8
|
theme?: ThemeConfig;
|
|
@@ -26,6 +28,6 @@ interface StaticRenderOptions {
|
|
|
26
28
|
* The entire render pipeline is synchronous; the global swap is safe as long
|
|
27
29
|
* as no code schedules microtasks that outlive the call.
|
|
28
30
|
*/
|
|
29
|
-
declare function renderStaticSVG(spec: ChartSpec | LayerSpec | TileMapSpec, options?: StaticRenderOptions): string;
|
|
31
|
+
declare function renderStaticSVG(spec: ChartSpec | LayerSpec | TileMapSpec | GeoMapSpec, options?: StaticRenderOptions): string;
|
|
30
32
|
|
|
31
33
|
export { type StaticRenderOptions, renderStaticSVG };
|
package/dist/static.js
CHANGED
|
@@ -1,20 +1,32 @@
|
|
|
1
1
|
import {
|
|
2
2
|
renderTileMapSVG
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-6YPRYQKD.js";
|
|
4
4
|
import {
|
|
5
|
+
applyMapCamera,
|
|
6
|
+
cameraForTarget,
|
|
7
|
+
captureSvgIdState,
|
|
5
8
|
renderChartSVG,
|
|
6
|
-
|
|
7
|
-
|
|
9
|
+
renderMapSVG,
|
|
10
|
+
resetSvgIdCounter,
|
|
11
|
+
restoreSvgIdState
|
|
12
|
+
} from "./chunk-ERPYVYFW.js";
|
|
8
13
|
import {
|
|
9
|
-
SVG_NS,
|
|
10
14
|
buildThemeStyleBlock
|
|
11
|
-
} from "./chunk-
|
|
12
|
-
import "./chunk-
|
|
15
|
+
} from "./chunk-A5C4VCUO.js";
|
|
16
|
+
import "./chunk-NLKQ5AOA.js";
|
|
17
|
+
import {
|
|
18
|
+
SVG_NS
|
|
19
|
+
} from "./chunk-FFP5GXIP.js";
|
|
13
20
|
|
|
14
21
|
// src/static.ts
|
|
15
22
|
import { createRequire } from "module";
|
|
16
|
-
import { isLayerSpec, isTileMapSpec } from "@opendata-ai/openchart-core";
|
|
17
|
-
import {
|
|
23
|
+
import { isGeoMapSpec, isLayerSpec, isTileMapSpec } from "@opendata-ai/openchart-core";
|
|
24
|
+
import {
|
|
25
|
+
compileChart,
|
|
26
|
+
compileGeoMap,
|
|
27
|
+
compileLayer,
|
|
28
|
+
compileTileMap
|
|
29
|
+
} from "@opendata-ai/openchart-engine";
|
|
18
30
|
var esmRequire = createRequire(import.meta.url);
|
|
19
31
|
var cachedWindow;
|
|
20
32
|
function getHappyDomWindow() {
|
|
@@ -43,18 +55,23 @@ function stripInteractiveElements(svg) {
|
|
|
43
55
|
}
|
|
44
56
|
}
|
|
45
57
|
function renderStaticSVG(spec, options) {
|
|
58
|
+
if (options?.idPrefix !== void 0 && !/^[A-Za-z_][A-Za-z0-9_.-]*$/.test(options.idPrefix))
|
|
59
|
+
throw new Error(
|
|
60
|
+
"idPrefix must start with a letter or underscore and contain only letters, digits, underscores, periods or hyphens."
|
|
61
|
+
);
|
|
46
62
|
if (rendering) {
|
|
47
63
|
throw new Error("renderStaticSVG is not reentrant \u2014 serialize calls through a queue or mutex");
|
|
48
64
|
}
|
|
49
65
|
rendering = true;
|
|
50
66
|
const Window = getHappyDomWindow();
|
|
51
67
|
const win = new Window({ url: "about:blank" });
|
|
68
|
+
const svgIdState = captureSvgIdState();
|
|
52
69
|
const prevDocument = globalThis.document;
|
|
53
70
|
const prevWindow = globalThis.window;
|
|
54
71
|
try {
|
|
55
72
|
globalThis.document = win.document;
|
|
56
73
|
globalThis.window = win;
|
|
57
|
-
resetSvgIdCounter();
|
|
74
|
+
resetSvgIdCounter(options?.idPrefix);
|
|
58
75
|
const width = options?.width ?? 640;
|
|
59
76
|
const height = options?.height ?? 420;
|
|
60
77
|
const darkMode = resolveStaticDarkMode(options?.darkMode);
|
|
@@ -68,7 +85,13 @@ function renderStaticSVG(spec, options) {
|
|
|
68
85
|
};
|
|
69
86
|
let svg;
|
|
70
87
|
let themeForStyle;
|
|
71
|
-
if (
|
|
88
|
+
if (isGeoMapSpec(spec)) {
|
|
89
|
+
const mapLayout = compileGeoMap(spec, compileOpts);
|
|
90
|
+
svg = renderMapSVG(mapLayout, { animate: false });
|
|
91
|
+
if (!mapLayout.views)
|
|
92
|
+
applyMapCamera(svg, cameraForTarget(mapLayout, mapLayout.focus?.target), mapLayout);
|
|
93
|
+
themeForStyle = mapLayout.theme;
|
|
94
|
+
} else if (isTileMapSpec(spec)) {
|
|
72
95
|
const tileMapLayout = compileTileMap(spec, compileOpts);
|
|
73
96
|
svg = renderTileMapSVG(tileMapLayout, { animate: false });
|
|
74
97
|
themeForStyle = tileMapLayout.theme;
|
|
@@ -112,6 +135,7 @@ function renderStaticSVG(spec, options) {
|
|
|
112
135
|
const serializer = new win.XMLSerializer();
|
|
113
136
|
return serializer.serializeToString(svg);
|
|
114
137
|
} finally {
|
|
138
|
+
restoreSvgIdState(svgIdState);
|
|
115
139
|
rendering = false;
|
|
116
140
|
if (prevDocument !== void 0) {
|
|
117
141
|
globalThis.document = prevDocument;
|
package/dist/static.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/static.ts"],"sourcesContent":["// Node.js only — do not import from browser code.\nimport { createRequire } from 'node:module';\nimport type {\n ChartLayout,\n ChartSpec,\n CompileOptions,\n DarkMode,\n LayerSpec,\n ResolvedTheme,\n ThemeConfig,\n TileMapSpec,\n} from '@opendata-ai/openchart-core';\nimport { isLayerSpec, isTileMapSpec } from '@opendata-ai/openchart-core';\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/static.ts"],"sourcesContent":["// Node.js only — do not import from browser code.\nimport { createRequire } from 'node:module';\nimport type {\n ChartLayout,\n ChartSpec,\n CompileOptions,\n DarkMode,\n GeoMapSpec,\n LayerSpec,\n ResolvedTheme,\n ThemeConfig,\n TileMapSpec,\n} from '@opendata-ai/openchart-core';\nimport { isGeoMapSpec, isLayerSpec, isTileMapSpec } from '@opendata-ai/openchart-core';\nimport {\n compileChart,\n compileGeoMap,\n compileLayer,\n compileTileMap,\n} from '@opendata-ai/openchart-engine';\nimport { applyMapCamera, cameraForTarget } from './map-camera';\nimport { renderMapSVG } from './map-renderer';\nimport { SVG_NS } from './renderers/svg-dom';\nimport { captureSvgIdState, resetSvgIdCounter, restoreSvgIdState } from './svg-ids';\nimport { renderChartSVG } from './svg-renderer';\nimport { buildThemeStyleBlock } from './theme-style-block';\nimport { renderTileMapSVG } from './tilemap-renderer';\n\nconst esmRequire = createRequire(import.meta.url);\n\nlet cachedWindow: typeof import('happy-dom').Window | undefined;\nfunction getHappyDomWindow(): typeof import('happy-dom').Window {\n if (cachedWindow) return cachedWindow;\n try {\n ({ Window: cachedWindow } = esmRequire('happy-dom') as typeof import('happy-dom'));\n } catch {\n throw new Error(\n \"renderStaticSVG requires 'happy-dom' as a peer dependency. Install it with: npm add happy-dom\",\n );\n }\n return cachedWindow;\n}\n\nlet rendering = false;\n\nexport interface StaticRenderOptions {\n /** Stable XML-safe prefix. Use distinct prefixes for figures sharing one document. */\n idPrefix?: string;\n width?: number;\n height?: number;\n theme?: ThemeConfig;\n /**\n * Dark mode setting. In static rendering `'auto'` resolves to light mode\n * since there is no `matchMedia` to query. Use `'force'` for dark output.\n */\n darkMode?: DarkMode;\n /** Rendering backend for point marks; see `MountOptions.renderer`. */\n renderer?: 'auto' | 'svg' | 'canvas';\n watermark?: boolean;\n}\n\nfunction resolveStaticDarkMode(mode?: DarkMode): boolean {\n if (mode === 'force') return true;\n return false;\n}\n\nfunction stripInteractiveElements(svg: Element): void {\n const selectors = ['[data-voronoi-overlay]', '[data-crosshair]', '[data-snap-dots]'];\n for (const selector of selectors) {\n const els = svg.querySelectorAll(selector);\n for (const el of els) {\n el.parentNode?.removeChild(el);\n }\n }\n}\n\n/**\n * Render a chart spec to a standalone SVG string without a browser DOM.\n *\n * Requires `happy-dom` as a peer dependency (`bun add happy-dom`).\n *\n * Not safe for concurrent invocation: the render pipeline relies on a global\n * SVG ID counter and a temporary global `document` swap, both of which are\n * single-threaded. In a server handling parallel requests, serialize calls\n * through a queue or mutex.\n *\n * The entire render pipeline is synchronous; the global swap is safe as long\n * as no code schedules microtasks that outlive the call.\n */\nexport function renderStaticSVG(\n spec: ChartSpec | LayerSpec | TileMapSpec | GeoMapSpec,\n options?: StaticRenderOptions,\n): string {\n if (options?.idPrefix !== undefined && !/^[A-Za-z_][A-Za-z0-9_.-]*$/.test(options.idPrefix))\n throw new Error(\n 'idPrefix must start with a letter or underscore and contain only letters, digits, underscores, periods or hyphens.',\n );\n if (rendering) {\n throw new Error('renderStaticSVG is not reentrant — serialize calls through a queue or mutex');\n }\n rendering = true;\n\n const Window = getHappyDomWindow();\n const win = new Window({ url: 'about:blank' });\n\n const svgIdState = captureSvgIdState();\n const prevDocument = globalThis.document;\n const prevWindow = (globalThis as Record<string, unknown>).window;\n\n try {\n (globalThis as Record<string, unknown>).document = win.document;\n (globalThis as Record<string, unknown>).window = win;\n\n resetSvgIdCounter(options?.idPrefix);\n\n const width = options?.width ?? 640;\n const height = options?.height ?? 420;\n const darkMode = resolveStaticDarkMode(options?.darkMode);\n\n const compileOpts: CompileOptions = {\n width,\n height,\n theme: options?.theme,\n darkMode,\n renderer: options?.renderer,\n watermark: options?.watermark,\n };\n\n let svg: SVGElement;\n let themeForStyle: ResolvedTheme;\n\n if (isGeoMapSpec(spec)) {\n const mapLayout = compileGeoMap(spec, compileOpts);\n svg = renderMapSVG(mapLayout, { animate: false });\n // Multi-view rendering already resolves every authored camera and its labels\n // through the same per-view renderer used by live mounts.\n if (!mapLayout.views)\n applyMapCamera(svg, cameraForTarget(mapLayout, mapLayout.focus?.target), mapLayout);\n themeForStyle = mapLayout.theme;\n } else if (isTileMapSpec(spec)) {\n const tileMapLayout = compileTileMap(spec, compileOpts);\n svg = renderTileMapSVG(tileMapLayout, { animate: false });\n themeForStyle = tileMapLayout.theme;\n } else {\n let layout: ChartLayout;\n if (isLayerSpec(spec)) {\n layout = compileLayer(spec, compileOpts);\n } else {\n layout = compileChart(spec, compileOpts);\n }\n\n const container = win.document.createElement('div');\n Object.defineProperty(container, 'getBoundingClientRect', {\n value: () => ({\n width,\n height,\n top: 0,\n left: 0,\n right: width,\n bottom: height,\n x: 0,\n y: 0,\n toJSON: () => ({}),\n }),\n });\n\n svg = renderChartSVG(layout, container as unknown as HTMLElement, {\n animate: false,\n crosshair: false,\n });\n\n stripInteractiveElements(svg);\n themeForStyle = layout.theme;\n }\n\n const doc = win.document as unknown as Document;\n let defs = svg.querySelector('defs');\n if (!defs) {\n defs = doc.createElementNS(SVG_NS, 'defs');\n svg.insertBefore(defs as unknown as Node, svg.firstChild);\n }\n const styleEl = doc.createElementNS(SVG_NS, 'style');\n styleEl.textContent = buildThemeStyleBlock(themeForStyle);\n defs.insertBefore(styleEl as unknown as Node, defs.firstChild);\n\n const serializer = new (\n win as unknown as { XMLSerializer: typeof XMLSerializer }\n ).XMLSerializer();\n return serializer.serializeToString(svg as unknown as Node);\n } finally {\n restoreSvgIdState(svgIdState);\n rendering = false;\n if (prevDocument !== undefined) {\n (globalThis as Record<string, unknown>).document = prevDocument;\n } else {\n delete (globalThis as Record<string, unknown>).document;\n }\n if (prevWindow !== undefined) {\n (globalThis as Record<string, unknown>).window = prevWindow;\n } else {\n delete (globalThis as Record<string, unknown>).window;\n }\n win.close();\n }\n}\n"],"mappings":"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","names":[]}
|
package/dist/story/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { C as Camera, F as FULL_VIEW, V as ViewBoxSize,
|
|
3
|
-
import { DataRow, ChartSpec, LayerSpec,
|
|
1
|
+
import { g as CameraTarget, M as MountOptions } from '../mount-types-DeUCa2hy.js';
|
|
2
|
+
export { C as Camera, F as FULL_VIEW, V as ViewBoxSize, h as cameraTransform, i as camerasClose, j as damp, k as dampCamera, l as fitTarget, m as interpolateCamera, s as scrubCamera } from '../mount-types-DeUCa2hy.js';
|
|
3
|
+
import { DataRow, ChartSpec, LayerSpec, GeoMapSpec, ChartLayout } from '@opendata-ai/openchart-core';
|
|
4
4
|
import '../export-gif.js';
|
|
5
5
|
|
|
6
|
-
/** A spec a story can drive:
|
|
7
|
-
type StorySpec<TData extends DataRow = DataRow> = ChartSpec<TData> | LayerSpec<TData> |
|
|
6
|
+
/** A spec a story can drive: what `ChartInstance.update()` accepts, plus geo maps. */
|
|
7
|
+
type StorySpec<TData extends DataRow = DataRow> = ChartSpec<TData> | LayerSpec<TData> | GeoMapSpec;
|
|
8
8
|
/** Deep-partial patch applied onto the accumulated spec at each step. */
|
|
9
9
|
type StorySpecPatch = Record<string, unknown>;
|
|
10
10
|
/**
|
|
@@ -82,7 +82,7 @@ interface ChartStoryInstance {
|
|
|
82
82
|
* the base spec, then drives it through cumulative patch steps as the
|
|
83
83
|
* reader scrolls (or via `goTo`).
|
|
84
84
|
*
|
|
85
|
-
* `editMode` (any of `onEdit`/`onSelect`/`onDeselect
|
|
85
|
+
* `editMode` (any of `onEdit`/`onSelect`/`onDeselect` on
|
|
86
86
|
* `mountOptions`) and an active story are mutually exclusive in v1: passing
|
|
87
87
|
* both warns once and disables the story's own drive loop, matching the
|
|
88
88
|
* seriesSearch/edit-mode precedent in `mount.ts`.
|
|
@@ -272,6 +272,8 @@ interface TweenConfig<T> {
|
|
|
272
272
|
/** Default `easingFns.easeOutCubic` */
|
|
273
273
|
ease?: EasingFn;
|
|
274
274
|
onFrame: (value: T) => void;
|
|
275
|
+
/** Runs after natural completion or a snap; cancellation never completes. */
|
|
276
|
+
onComplete?: (value: T) => void;
|
|
275
277
|
}
|
|
276
278
|
interface Tween<T> {
|
|
277
279
|
/**
|
package/dist/story/index.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CANVAS_DEFAULT_UPDATE_MAX_MARKS,
|
|
3
3
|
DEFAULT_UPDATE_MAX_MARKS,
|
|
4
|
-
FULL_VIEW,
|
|
5
|
-
cameraTransform,
|
|
6
|
-
camerasClose,
|
|
7
4
|
canTransitionSpecShape,
|
|
8
5
|
createChart,
|
|
9
6
|
createGeoMap,
|
|
7
|
+
resolveInteractionMode
|
|
8
|
+
} from "../chunk-T6IPHUN4.js";
|
|
9
|
+
import "../chunk-RBXIZJPE.js";
|
|
10
|
+
import {
|
|
11
|
+
FULL_VIEW,
|
|
12
|
+
cameraTransform,
|
|
13
|
+
camerasClose,
|
|
10
14
|
createTween,
|
|
11
15
|
damp,
|
|
12
16
|
dampCamera,
|
|
@@ -15,15 +19,14 @@ import {
|
|
|
15
19
|
interpolateCamera,
|
|
16
20
|
scrubCamera,
|
|
17
21
|
storyMotion
|
|
18
|
-
} from "../chunk-
|
|
19
|
-
import "../chunk-
|
|
20
|
-
import "../chunk-
|
|
21
|
-
import "../chunk-SDJHUELU.js";
|
|
22
|
+
} from "../chunk-ERPYVYFW.js";
|
|
23
|
+
import "../chunk-A5C4VCUO.js";
|
|
24
|
+
import "../chunk-46E3QB6O.js";
|
|
22
25
|
import {
|
|
23
26
|
clamp01,
|
|
24
27
|
lerp
|
|
25
|
-
} from "../chunk-
|
|
26
|
-
import "../chunk-
|
|
28
|
+
} from "../chunk-NLKQ5AOA.js";
|
|
29
|
+
import "../chunk-FFP5GXIP.js";
|
|
27
30
|
|
|
28
31
|
// src/story/create-chart-story.ts
|
|
29
32
|
import { deepMergeSpec, isGeoMapSpec } from "@opendata-ai/openchart-core";
|
|
@@ -365,10 +368,10 @@ function createChartStory(container, options, mountOptions) {
|
|
|
365
368
|
"[openchart] step.camera is ignored for map stories. Drive the map camera via geo.focus patches in the spec instead."
|
|
366
369
|
);
|
|
367
370
|
}
|
|
368
|
-
const editModeRequested =
|
|
371
|
+
const editModeRequested = resolveInteractionMode(mountOptions) !== "read";
|
|
369
372
|
if (editModeRequested) {
|
|
370
373
|
console.warn(
|
|
371
|
-
"[openchart] a chart story and edit mode are mutually exclusive; the story will not drive updates
|
|
374
|
+
"[openchart] a chart story and edit mode are mutually exclusive; the story will not drive updates unless interaction is 'read'."
|
|
372
375
|
);
|
|
373
376
|
}
|
|
374
377
|
let currentStep = -1;
|
|
@@ -380,7 +383,7 @@ function createChartStory(container, options, mountOptions) {
|
|
|
380
383
|
theme: mountOptions?.theme,
|
|
381
384
|
darkMode: mountOptions?.darkMode,
|
|
382
385
|
watermark: mountOptions?.watermark,
|
|
383
|
-
|
|
386
|
+
autoResize: mountOptions?.autoResize
|
|
384
387
|
};
|
|
385
388
|
instance = createGeoMap(container, initialSpec, mapOpts);
|
|
386
389
|
} else {
|