infographic-for-react 0.1.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/index.js ADDED
@@ -0,0 +1,535 @@
1
+ 'use strict';
2
+
3
+ var react = require('react');
4
+ var lodashEs = require('lodash-es');
5
+ var jsxRuntime = require('react/jsx-runtime');
6
+
7
+ // src/components/Infographic.tsx
8
+ function useRenderer(containerRef) {
9
+ const rendererRef = react.useRef(null);
10
+ const isInitializedRef = react.useRef(false);
11
+ const pendingListenersRef = react.useRef(/* @__PURE__ */ new Map());
12
+ const createRenderer = react.useCallback(
13
+ async (options) => {
14
+ const { Infographic: InfographicClass } = await import('@antv/infographic');
15
+ const renderer = new InfographicClass(options);
16
+ renderer.on("rendered", () => {
17
+ rendererRef.current = renderer;
18
+ isInitializedRef.current = true;
19
+ pendingListenersRef.current.forEach((listeners, event) => {
20
+ listeners.forEach((listener) => {
21
+ renderer.on(event, listener);
22
+ });
23
+ });
24
+ pendingListenersRef.current.clear();
25
+ });
26
+ renderer.on("error", (error) => {
27
+ console.error("[Infographic-for-React] Renderer error:", error);
28
+ });
29
+ return renderer;
30
+ },
31
+ []
32
+ );
33
+ const render = react.useCallback(
34
+ async (options) => {
35
+ const container = containerRef.current;
36
+ if (!container) {
37
+ throw new Error("Container element not found");
38
+ }
39
+ const renderOptions = { ...options, container };
40
+ if (rendererRef.current) {
41
+ rendererRef.current.update(renderOptions);
42
+ } else {
43
+ const renderer = await createRenderer(renderOptions);
44
+ renderer.render();
45
+ }
46
+ },
47
+ [containerRef, createRenderer]
48
+ );
49
+ const update = react.useCallback((options) => {
50
+ if (!rendererRef.current) {
51
+ throw new Error("Renderer not initialized. Call render first.");
52
+ }
53
+ rendererRef.current.update(options);
54
+ }, []);
55
+ const toDataURL = react.useCallback(
56
+ (options) => {
57
+ if (!rendererRef.current) {
58
+ throw new Error("Renderer not initialized");
59
+ }
60
+ return rendererRef.current.toDataURL(options);
61
+ },
62
+ []
63
+ );
64
+ const getTypes = react.useCallback(() => {
65
+ if (!rendererRef.current) {
66
+ throw new Error("Renderer not initialized");
67
+ }
68
+ return rendererRef.current.getTypes();
69
+ }, []);
70
+ const destroy = react.useCallback(() => {
71
+ if (rendererRef.current) {
72
+ rendererRef.current.destroy();
73
+ rendererRef.current = null;
74
+ }
75
+ isInitializedRef.current = false;
76
+ }, []);
77
+ const on = react.useCallback((event, listener) => {
78
+ if (!rendererRef.current) {
79
+ const listeners = pendingListenersRef.current.get(event) || /* @__PURE__ */ new Set();
80
+ listeners.add(listener);
81
+ pendingListenersRef.current.set(event, listeners);
82
+ return;
83
+ }
84
+ rendererRef.current.on(event, listener);
85
+ }, []);
86
+ const off = react.useCallback((event, listener) => {
87
+ if (!rendererRef.current) {
88
+ const listeners = pendingListenersRef.current.get(event);
89
+ if (listeners) {
90
+ listeners.delete(listener);
91
+ if (listeners.size === 0) {
92
+ pendingListenersRef.current.delete(event);
93
+ }
94
+ }
95
+ return;
96
+ }
97
+ rendererRef.current.off(event, listener);
98
+ }, []);
99
+ react.useEffect(() => {
100
+ return () => {
101
+ destroy();
102
+ };
103
+ }, [destroy]);
104
+ return {
105
+ render,
106
+ update,
107
+ toDataURL,
108
+ getTypes,
109
+ destroy,
110
+ on,
111
+ off,
112
+ isReady: isInitializedRef.current
113
+ };
114
+ }
115
+
116
+ // src/utils/dsl/merge.ts
117
+ function setByPath(obj, path, value) {
118
+ const keys = path.split(".");
119
+ let current = obj;
120
+ for (let i = 0; i < keys.length; i++) {
121
+ const key = keys[i];
122
+ const isLast = i === keys.length - 1;
123
+ if (isLast) {
124
+ current[key] = value;
125
+ } else {
126
+ if (typeof current[key] !== "object" || current[key] === null) {
127
+ current[key] = {};
128
+ }
129
+ current = current[key];
130
+ }
131
+ }
132
+ }
133
+ function applyOverrides(base, overrides) {
134
+ if (overrides.length === 0) return base;
135
+ const result = { ...base };
136
+ for (const override of overrides) {
137
+ setByPath(result, override.path, override.value);
138
+ }
139
+ return result;
140
+ }
141
+ function mergeDSL(dsl1, dsl2) {
142
+ const merged = deepMerge(dsl1, dsl2);
143
+ return merged;
144
+ }
145
+ function deepMerge(target, source) {
146
+ const result = { ...target };
147
+ for (const key in source) {
148
+ if (source[key] === void 0) {
149
+ continue;
150
+ }
151
+ const value = source[key];
152
+ if (value === null) {
153
+ result[key] = null;
154
+ continue;
155
+ }
156
+ const targetValue = result[key];
157
+ if (typeof value === "object" && !Array.isArray(value) && targetValue && typeof targetValue === "object" && !Array.isArray(targetValue)) {
158
+ result[key] = deepMerge(targetValue, value);
159
+ } else {
160
+ result[key] = value;
161
+ }
162
+ }
163
+ return result;
164
+ }
165
+
166
+ // src/utils/dsl/compose.ts
167
+ function isContainerNode(node) {
168
+ return typeof node === "object" && node !== null && "children" in node && Array.isArray(node.children);
169
+ }
170
+ function composeTemplates(options) {
171
+ const { templates, overrides = [] } = options;
172
+ if (templates.length === 0) {
173
+ throw new Error("At least one template is required");
174
+ }
175
+ if (templates.length === 1) {
176
+ const base = templates[0];
177
+ if (overrides.length > 0) {
178
+ return applyOverrides(base, overrides);
179
+ }
180
+ return base;
181
+ }
182
+ const root = templates[0];
183
+ if (!isContainerNode(root)) {
184
+ throw new Error("Root template must be a container node with children");
185
+ }
186
+ let currentChildren = root.children || [];
187
+ for (let i = 1; i < templates.length; i++) {
188
+ const template = templates[i];
189
+ if (isContainerNode(template) && template.children) {
190
+ currentChildren = [...currentChildren, ...template.children];
191
+ } else {
192
+ currentChildren.push(template);
193
+ }
194
+ }
195
+ root.children = currentChildren;
196
+ let composed = root;
197
+ if (overrides.length > 0) {
198
+ composed = applyOverrides(composed, overrides);
199
+ }
200
+ return composed;
201
+ }
202
+
203
+ // src/hooks/useInfographic.ts
204
+ function useInfographic(containerRef, props) {
205
+ const { render: rendererRender, update, toDataURL, getTypes, destroy, on, off } = useRenderer(containerRef);
206
+ const propsRef = react.useRef(props);
207
+ const dslCacheRef = react.useRef(null);
208
+ propsRef.current = props;
209
+ const resolveDSL = react.useCallback(
210
+ async (input) => {
211
+ if (!input) {
212
+ throw new Error("DSL is required");
213
+ }
214
+ return input;
215
+ },
216
+ []
217
+ );
218
+ const processDSL = react.useCallback(
219
+ async (input) => {
220
+ let processed = input;
221
+ const { overrides, beforeRender } = propsRef.current;
222
+ if (overrides && overrides.length > 0) {
223
+ try {
224
+ processed = applyOverrides(processed, overrides);
225
+ } catch (error) {
226
+ const infographicError = {
227
+ type: "syntax",
228
+ message: `Failed to apply overrides: ${error instanceof Error ? error.message : String(error)}`,
229
+ dsl: JSON.stringify(processed),
230
+ details: error
231
+ };
232
+ propsRef.current.onError?.(infographicError);
233
+ throw infographicError;
234
+ }
235
+ }
236
+ if (beforeRender) {
237
+ try {
238
+ processed = await beforeRender(processed);
239
+ } catch (error) {
240
+ const infographicError = {
241
+ type: "runtime",
242
+ message: `beforeRender hook failed: ${error instanceof Error ? error.message : String(error)}`,
243
+ dsl: JSON.stringify(processed),
244
+ details: error
245
+ };
246
+ propsRef.current.onError?.(infographicError);
247
+ throw infographicError;
248
+ }
249
+ }
250
+ return processed;
251
+ },
252
+ []
253
+ );
254
+ const handleRendered = react.useCallback(
255
+ async (result) => {
256
+ const { afterRender, onRender } = propsRef.current;
257
+ if (afterRender) {
258
+ try {
259
+ await afterRender(result);
260
+ } catch (error) {
261
+ const infographicError = {
262
+ type: "runtime",
263
+ message: `afterRender hook failed: ${error instanceof Error ? error.message : String(error)}`,
264
+ details: error
265
+ };
266
+ propsRef.current.onError?.(infographicError);
267
+ return;
268
+ }
269
+ }
270
+ onRender?.(result);
271
+ },
272
+ []
273
+ );
274
+ const render = react.useCallback(async () => {
275
+ const {
276
+ dsl,
277
+ width,
278
+ height,
279
+ theme,
280
+ editable,
281
+ className
282
+ } = propsRef.current;
283
+ try {
284
+ let processedDSL;
285
+ if (!dsl) {
286
+ throw new Error("DSL prop is required");
287
+ }
288
+ processedDSL = await resolveDSL(dsl);
289
+ processedDSL = await processDSL(processedDSL);
290
+ const dslString = JSON.stringify(processedDSL);
291
+ if (dslCacheRef.current !== dslString) {
292
+ dslCacheRef.current = dslString;
293
+ const renderOptions = { ...processedDSL };
294
+ if (processedDSL.theme) renderOptions.theme = processedDSL.theme;
295
+ else if (theme) renderOptions.theme = theme;
296
+ if (processedDSL.palette) {
297
+ const existingThemeConfig = processedDSL.themeConfig || {};
298
+ renderOptions.themeConfig = {
299
+ ...existingThemeConfig,
300
+ palette: processedDSL.palette
301
+ };
302
+ }
303
+ if (editable !== void 0) renderOptions.editable = editable;
304
+ delete renderOptions.palette;
305
+ if (width || height) {
306
+ renderOptions.width = width;
307
+ renderOptions.height = height;
308
+ }
309
+ if (containerRef.current && className) {
310
+ containerRef.current.className = className;
311
+ }
312
+ rendererRender(renderOptions);
313
+ }
314
+ } catch (error) {
315
+ const infographicError = {
316
+ type: "runtime",
317
+ message: error instanceof Error ? error.message : String(error),
318
+ details: error
319
+ };
320
+ propsRef.current.onError?.(infographicError);
321
+ }
322
+ }, [containerRef, rendererRender, resolveDSL, processDSL]);
323
+ const debouncedRender = react.useCallback(
324
+ lodashEs.debounce(() => {
325
+ render().catch((error) => {
326
+ console.error("[Infographic-for-React] Render error:", error);
327
+ });
328
+ }, 100),
329
+ [render]
330
+ );
331
+ react.useEffect(() => {
332
+ on("rendered", handleRendered);
333
+ on("loaded", handleRendered);
334
+ return () => {
335
+ off("rendered", handleRendered);
336
+ off("loaded", handleRendered);
337
+ };
338
+ }, [on, off, handleRendered]);
339
+ react.useEffect(() => {
340
+ debouncedRender();
341
+ return debouncedRender.cancel;
342
+ }, [debouncedRender]);
343
+ const refUpdate = react.useCallback(
344
+ async (options) => {
345
+ const processed = await processDSL(options);
346
+ const themeConfig = processed.themeConfig || {};
347
+ if (processed.palette) {
348
+ themeConfig.palette = processed.palette;
349
+ }
350
+ const { palette: _, ...rest } = processed;
351
+ const renderOptions = {
352
+ ...rest,
353
+ theme: processed.theme ?? propsRef.current.theme,
354
+ themeConfig
355
+ };
356
+ update(renderOptions);
357
+ },
358
+ [update, processDSL]
359
+ );
360
+ const ref = {
361
+ toDataURL,
362
+ getTypes,
363
+ update: refUpdate,
364
+ destroy
365
+ };
366
+ return ref;
367
+ }
368
+ var defaultError = {
369
+ message: "An error occurred while rendering the infographic."
370
+ };
371
+ function InfographicComponent(props, ref) {
372
+ const containerRef = react.useRef(null);
373
+ const [error, setError] = react.useState(null);
374
+ const [errorKey, setErrorKey] = react.useState(0);
375
+ const infographicRef = useInfographic(containerRef, {
376
+ ...props,
377
+ onError: (err) => {
378
+ setError(err);
379
+ props.onError?.(err);
380
+ }
381
+ });
382
+ react.useImperativeHandle(ref, () => infographicRef, [infographicRef]);
383
+ const handleRetry = () => {
384
+ setError(null);
385
+ setErrorKey((prev) => prev + 1);
386
+ };
387
+ const containerStyle = {
388
+ width: props.width ?? "100%",
389
+ height: props.height ?? "auto",
390
+ overflow: "hidden"
391
+ };
392
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
393
+ /* @__PURE__ */ jsxRuntime.jsx(
394
+ "div",
395
+ {
396
+ ref: containerRef,
397
+ className: props.className,
398
+ style: containerStyle,
399
+ "data-infographic-container": true
400
+ },
401
+ `infographic-container-${errorKey}`
402
+ ),
403
+ error && /* @__PURE__ */ jsxRuntime.jsxs(
404
+ "div",
405
+ {
406
+ style: {
407
+ position: "absolute",
408
+ top: 0,
409
+ left: 0,
410
+ right: 0,
411
+ bottom: 0,
412
+ display: "flex",
413
+ flexDirection: "column",
414
+ alignItems: "center",
415
+ justifyContent: "center",
416
+ backgroundColor: "rgba(0, 0, 0, 0.05)",
417
+ color: "#d32f2f",
418
+ padding: "20px",
419
+ zIndex: 1,
420
+ textAlign: "center"
421
+ },
422
+ children: [
423
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: { fontSize: "1.2em", fontWeight: "bold", marginBottom: "10px" }, children: "Infographic Render Error" }),
424
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: { marginBottom: "15px" }, children: error.message || defaultError.message }),
425
+ /* @__PURE__ */ jsxRuntime.jsx(
426
+ "button",
427
+ {
428
+ type: "button",
429
+ onClick: handleRetry,
430
+ style: {
431
+ padding: "8px 16px",
432
+ backgroundColor: "#1976d2",
433
+ color: "white",
434
+ border: "none",
435
+ borderRadius: "4px",
436
+ cursor: "pointer",
437
+ fontSize: "14px"
438
+ },
439
+ children: "Retry"
440
+ }
441
+ )
442
+ ]
443
+ }
444
+ )
445
+ ] });
446
+ }
447
+ var Infographic = react.forwardRef(InfographicComponent);
448
+ var ErrorBoundary = class extends react.Component {
449
+ constructor(props) {
450
+ super(props);
451
+ this.handleReset = () => {
452
+ this.setState({ hasError: false, error: void 0, errorInfo: void 0 });
453
+ };
454
+ this.state = { hasError: false };
455
+ }
456
+ static getDerivedStateFromError(error) {
457
+ return { hasError: true, error };
458
+ }
459
+ componentDidCatch(error, errorInfo) {
460
+ this.setState({ errorInfo });
461
+ this.props.onError?.(error, errorInfo);
462
+ }
463
+ render() {
464
+ const { hasError, error, errorInfo } = this.state;
465
+ const { children, fallback } = this.props;
466
+ if (!hasError || !error) {
467
+ return children;
468
+ }
469
+ if (fallback) {
470
+ if (typeof fallback === "function") {
471
+ return fallback(error, errorInfo);
472
+ }
473
+ return fallback;
474
+ }
475
+ return /* @__PURE__ */ jsxRuntime.jsxs(
476
+ "div",
477
+ {
478
+ style: {
479
+ padding: "20px",
480
+ backgroundColor: "#fee",
481
+ border: "1px solid #fcc",
482
+ borderRadius: "4px",
483
+ color: "#c33"
484
+ },
485
+ children: [
486
+ /* @__PURE__ */ jsxRuntime.jsx("h2", { style: { marginTop: 0 }, children: "Something went wrong" }),
487
+ /* @__PURE__ */ jsxRuntime.jsx("p", { children: error.message }),
488
+ errorInfo && /* @__PURE__ */ jsxRuntime.jsxs("details", { style: { marginTop: "10px" }, children: [
489
+ /* @__PURE__ */ jsxRuntime.jsx("summary", { children: "Stack trace" }),
490
+ /* @__PURE__ */ jsxRuntime.jsx(
491
+ "pre",
492
+ {
493
+ style: {
494
+ marginTop: "10px",
495
+ padding: "10px",
496
+ backgroundColor: "white",
497
+ borderRadius: "4px",
498
+ overflow: "auto"
499
+ },
500
+ children: errorInfo.componentStack
501
+ }
502
+ )
503
+ ] }),
504
+ /* @__PURE__ */ jsxRuntime.jsx(
505
+ "button",
506
+ {
507
+ type: "button",
508
+ onClick: this.handleReset,
509
+ style: {
510
+ marginTop: "15px",
511
+ padding: "8px 16px",
512
+ backgroundColor: "#c33",
513
+ color: "white",
514
+ border: "none",
515
+ borderRadius: "4px",
516
+ cursor: "pointer"
517
+ },
518
+ children: "Try again"
519
+ }
520
+ )
521
+ ]
522
+ }
523
+ );
524
+ }
525
+ };
526
+
527
+ exports.ErrorBoundary = ErrorBoundary;
528
+ exports.Infographic = Infographic;
529
+ exports.applyOverrides = applyOverrides;
530
+ exports.composeTemplates = composeTemplates;
531
+ exports.mergeDSL = mergeDSL;
532
+ exports.useInfographic = useInfographic;
533
+ exports.useRenderer = useRenderer;
534
+ //# sourceMappingURL=index.js.map
535
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/useRenderer.ts","../src/utils/dsl/merge.ts","../src/utils/dsl/compose.ts","../src/hooks/useInfographic.ts","../src/components/Infographic.tsx","../src/components/ErrorBoundary.tsx"],"names":["useRef","useCallback","useEffect","debounce","useState","useImperativeHandle","jsxs","Fragment","jsx","forwardRef","Component"],"mappings":";;;;;;;AAOO,SAAS,YAAY,YAAA,EAA4C;AACtE,EAAA,MAAM,WAAA,GAAcA,aAAgC,IAAI,CAAA;AACxD,EAAA,MAAM,gBAAA,GAAmBA,aAAO,KAAK,CAAA;AACrC,EAAA,MAAM,mBAAA,GAAsBA,YAAA,iBAAmD,IAAI,GAAA,EAAK,CAAA;AAExF,EAAA,MAAM,cAAA,GAAiBC,iBAAA;AAAA,IACrB,OAAO,OAAA,KAAoE;AACzE,MAAA,MAAM,EAAE,WAAA,EAAa,gBAAA,EAAiB,GAAI,MAAM,OAAO,mBA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AA,EAAiB,OAAA;AAAA,kBACjB,YAAA,EAAc,KAAA;AAAA,kBACd,QAAA,EAAU;AAAA,iBACZ;AAAA,gBAEC,QAAA,EAAA,SAAA,CAAU;AAAA;AAAA;AACb,WAAA,EACF,CAAA;AAAA,0BAEFA,cAAAA;AAAA,YAAC,QAAA;AAAA,YAAA;AAAA,cACC,IAAA,EAAK,QAAA;AAAA,cACL,SAAS,IAAA,CAAK,WAAA;AAAA,cACd,KAAA,EAAO;AAAA,gBACL,SAAA,EAAW,MAAA;AAAA,gBACX,OAAA,EAAS,UAAA;AAAA,gBACT,eAAA,EAAiB,MAAA;AAAA,gBACjB,KAAA,EAAO,OAAA;AAAA,gBACP,MAAA,EAAQ,MAAA;AAAA,gBACR,YAAA,EAAc,KAAA;AAAA,gBACd,MAAA,EAAQ;AAAA,eACV;AAAA,cACD,QAAA,EAAA;AAAA;AAAA;AAED;AAAA;AAAA,KACF;AAAA,EAEJ;AACF","file":"index.js","sourcesContent":["import { useEffect, useRef, useCallback } from 'react';\nimport type {\n InfographicOptions,\n RendererInstance,\n ExportOptions,\n} from '../types';\n\nexport function useRenderer(containerRef: React.RefObject<HTMLElement>) {\n const rendererRef = useRef<RendererInstance | null>(null);\n const isInitializedRef = useRef(false);\n const pendingListenersRef = useRef<Map<string, Set<(...args: any[]) => void>>>(new Map());\n\n const createRenderer = useCallback(\n async (options: Partial<InfographicOptions>): Promise<RendererInstance> => {\n const { Infographic: InfographicClass } = await import('@antv/infographic');\n const renderer = new InfographicClass(options);\n\n renderer.on('rendered', () => {\n rendererRef.current = renderer;\n isInitializedRef.current = true;\n\n pendingListenersRef.current.forEach((listeners, event) => {\n listeners.forEach((listener) => {\n renderer.on(event, listener);\n });\n });\n pendingListenersRef.current.clear();\n });\n\n renderer.on('error', (error) => {\n console.error('[Infographic-for-React] Renderer error:', error);\n });\n\n return renderer;\n },\n [],\n );\n\n const render = useCallback(\n async (options: Partial<InfographicOptions>) => {\n const container = containerRef.current;\n if (!container) {\n throw new Error('Container element not found');\n }\n\n const renderOptions = { ...options, container };\n\n if (rendererRef.current) {\n rendererRef.current.update(renderOptions);\n } else {\n const renderer = await createRenderer(renderOptions);\n renderer.render();\n }\n },\n [containerRef, createRenderer],\n );\n\n const update = useCallback((options: Partial<InfographicOptions>) => {\n if (!rendererRef.current) {\n throw new Error('Renderer not initialized. Call render first.');\n }\n rendererRef.current.update(options);\n }, []);\n\n const toDataURL = useCallback(\n (options?: ExportOptions): Promise<string> => {\n if (!rendererRef.current) {\n throw new Error('Renderer not initialized');\n }\n return rendererRef.current.toDataURL(options);\n },\n [],\n );\n\n const getTypes = useCallback(() => {\n if (!rendererRef.current) {\n throw new Error('Renderer not initialized');\n }\n return rendererRef.current.getTypes();\n }, []);\n\n const destroy = useCallback(() => {\n if (rendererRef.current) {\n rendererRef.current.destroy();\n rendererRef.current = null;\n }\n isInitializedRef.current = false;\n }, []);\n\n const on = useCallback((event: string, listener: (...args: any[]) => void) => {\n if (!rendererRef.current) {\n const listeners = pendingListenersRef.current.get(event) || new Set();\n listeners.add(listener);\n pendingListenersRef.current.set(event, listeners);\n return;\n }\n rendererRef.current.on(event, listener);\n }, []);\n\n const off = useCallback((event: string, listener: (...args: any[]) => void) => {\n if (!rendererRef.current) {\n const listeners = pendingListenersRef.current.get(event);\n if (listeners) {\n listeners.delete(listener);\n if (listeners.size === 0) {\n pendingListenersRef.current.delete(event);\n }\n }\n return;\n }\n rendererRef.current.off(event, listener);\n }, []);\n\n useEffect(() => {\n return () => {\n destroy();\n };\n }, [destroy]);\n\n return {\n render,\n update,\n toDataURL,\n getTypes,\n destroy,\n on,\n off,\n isReady: isInitializedRef.current,\n };\n}\n","import type { DSLOverride, DSLObject } from '../../types';\n\nfunction setByPath(obj: Record<string, unknown>, path: string, value: unknown): void {\n const keys = path.split('.');\n let current = obj;\n\n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n const isLast = i === keys.length - 1;\n\n if (isLast) {\n current[key] = value;\n } else {\n if (typeof current[key] !== 'object' || current[key] === null) {\n current[key] = {};\n }\n current = current[key] as Record<string, unknown>;\n }\n }\n}\n\nexport function applyOverrides(base: DSLObject, overrides: DSLOverride[]): DSLObject {\n if (overrides.length === 0) return base;\n\n const result = { ...base };\n\n for (const override of overrides) {\n setByPath(result as Record<string, unknown>, override.path, override.value);\n }\n\n return result;\n}\n\nexport function mergeDSL(dsl1: DSLObject, dsl2: DSLObject): DSLObject {\n const merged = deepMerge(dsl1 as unknown as Record<string, unknown>, dsl2 as unknown as Record<string, unknown>);\n return merged as unknown as DSLObject;\n}\n\nfunction deepMerge(target: Record<string, unknown>, source: Record<string, unknown>): Record<string, unknown> {\n const result: Record<string, unknown> = { ...target };\n\n for (const key in source) {\n if (source[key] === undefined) {\n continue;\n }\n\n const value = source[key];\n\n if (value === null) {\n result[key] = null;\n continue;\n }\n\n const targetValue = result[key];\n\n if (typeof value === 'object' && !Array.isArray(value) && targetValue && typeof targetValue === 'object' && !Array.isArray(targetValue)) {\n result[key] = deepMerge(targetValue as Record<string, unknown>, value as Record<string, unknown>);\n } else {\n result[key] = value;\n }\n }\n\n return result;\n}\n","import type { ComposeTemplateOptions, DSLObject } from '../../types';\nimport { applyOverrides } from './merge';\n\ninterface DSLNode {\n type?: string;\n data?: unknown;\n props?: Record<string, unknown>;\n children?: DSLNode[];\n [key: string]: unknown;\n}\n\nfunction isContainerNode(node: unknown): node is DSLNode {\n return (\n typeof node === 'object' &&\n node !== null &&\n 'children' in node &&\n Array.isArray((node as DSLNode).children)\n );\n}\n\nexport function composeTemplates(options: ComposeTemplateOptions): DSLObject {\n const { templates, overrides = [] } = options;\n\n if (templates.length === 0) {\n throw new Error('At least one template is required');\n }\n\n if (templates.length === 1) {\n const base = templates[0];\n if (overrides.length > 0) {\n return applyOverrides(base, overrides);\n }\n return base;\n }\n\n const root = templates[0] as DSLNode;\n\n if (!isContainerNode(root)) {\n throw new Error('Root template must be a container node with children');\n }\n\n let currentChildren = root.children || [];\n\n for (let i = 1; i < templates.length; i++) {\n const template = templates[i] as DSLNode;\n\n if (isContainerNode(template) && template.children) {\n currentChildren = [...currentChildren, ...template.children];\n } else {\n currentChildren.push(template);\n }\n }\n\n root.children = currentChildren;\n\n let composed = root as DSLObject;\n\n if (overrides.length > 0) {\n composed = applyOverrides(composed, overrides);\n }\n\n return composed;\n}\n","import { useRef, useCallback, useEffect } from 'react';\nimport { debounce } from 'lodash-es';\nimport { useRenderer } from './useRenderer';\nimport { applyOverrides } from '../utils/dsl';\nimport type {\n InfographicProps,\n InfographicRef,\n InfographicError,\n InfographicRenderResult,\n DSLInput,\n DSLObject,\n ThemeConfig,\n InfographicOptions,\n} from '../types';\n\nexport function useInfographic(\n containerRef: React.RefObject<HTMLElement>,\n props: InfographicProps,\n) {\n const { render: rendererRender, update, toDataURL, getTypes, destroy, on, off } = useRenderer(containerRef);\n\n const propsRef = useRef(props);\n const dslCacheRef = useRef<string | null>(null);\n\n propsRef.current = props;\n\n const resolveDSL = useCallback(\n async (input: DSLInput | undefined): Promise<DSLObject> => {\n if (!input) {\n throw new Error('DSL is required');\n }\n return input;\n },\n [],\n );\n\n const processDSL = useCallback(\n async (input: DSLObject): Promise<DSLObject> => {\n let processed: DSLObject = input;\n const { overrides, beforeRender } = propsRef.current;\n\n if (overrides && overrides.length > 0) {\n try {\n processed = applyOverrides(processed, overrides);\n } catch (error) {\n const infographicError: InfographicError = {\n type: 'syntax',\n message: `Failed to apply overrides: ${error instanceof Error ? error.message : String(error)}`,\n dsl: JSON.stringify(processed),\n details: error,\n };\n propsRef.current.onError?.(infographicError);\n throw infographicError;\n }\n }\n\n if (beforeRender) {\n try {\n processed = await beforeRender(processed);\n } catch (error) {\n const infographicError: InfographicError = {\n type: 'runtime',\n message: `beforeRender hook failed: ${error instanceof Error ? error.message : String(error)}`,\n dsl: JSON.stringify(processed),\n details: error,\n };\n propsRef.current.onError?.(infographicError);\n throw infographicError;\n }\n }\n\n return processed;\n },\n [],\n );\n\n const handleRendered = useCallback(\n async (result: InfographicRenderResult) => {\n const { afterRender, onRender } = propsRef.current;\n\n if (afterRender) {\n try {\n await afterRender(result);\n } catch (error) {\n const infographicError: InfographicError = {\n type: 'runtime',\n message: `afterRender hook failed: ${error instanceof Error ? error.message : String(error)}`,\n details: error,\n };\n propsRef.current.onError?.(infographicError);\n return;\n }\n }\n\n onRender?.(result);\n },\n [],\n );\n\n const render = useCallback(async () => {\n const {\n dsl,\n width,\n height,\n theme,\n editable,\n className,\n } = propsRef.current;\n\n try {\n let processedDSL: DSLObject;\n\n if (!dsl) {\n throw new Error('DSL prop is required');\n }\n\n processedDSL = await resolveDSL(dsl);\n processedDSL = await processDSL(processedDSL);\n\n const dslString = JSON.stringify(processedDSL);\n if (dslCacheRef.current !== dslString) {\n dslCacheRef.current = dslString;\n\n const renderOptions: Partial<InfographicOptions> = { ...processedDSL };\n\n if (processedDSL.theme) renderOptions.theme = processedDSL.theme;\n else if (theme) renderOptions.theme = theme;\n\n if (processedDSL.palette) {\n const existingThemeConfig = (processedDSL.themeConfig || {}) as ThemeConfig;\n renderOptions.themeConfig = {\n ...existingThemeConfig,\n palette: processedDSL.palette,\n };\n }\n\n if (editable !== undefined) renderOptions.editable = editable;\n\n delete (renderOptions as any).palette;\n\n if (width || height) {\n renderOptions.width = width;\n renderOptions.height = height;\n }\n\n if (containerRef.current && className) {\n containerRef.current.className = className;\n }\n\n rendererRender(renderOptions);\n }\n } catch (error) {\n const infographicError: InfographicError = {\n type: 'runtime',\n message: error instanceof Error ? error.message : String(error),\n details: error,\n };\n propsRef.current.onError?.(infographicError);\n }\n }, [containerRef, rendererRender, resolveDSL, processDSL]);\n\n const debouncedRender = useCallback(\n debounce(() => {\n render().catch((error) => {\n console.error('[Infographic-for-React] Render error:', error);\n });\n }, 100),\n [render],\n );\n\n useEffect(() => {\n on('rendered', handleRendered);\n on('loaded', handleRendered);\n\n return () => {\n off('rendered', handleRendered);\n off('loaded', handleRendered);\n };\n }, [on, off, handleRendered]);\n\n useEffect(() => {\n debouncedRender();\n return debouncedRender.cancel;\n }, [debouncedRender]);\n\n const refUpdate = useCallback(\n async (options: DSLInput) => {\n const processed = await processDSL(options);\n const themeConfig = (processed.themeConfig || {}) as ThemeConfig;\n if (processed.palette) {\n themeConfig.palette = processed.palette;\n }\n\n const { palette: _, ...rest } = processed as any;\n const renderOptions: Partial<InfographicOptions> = {\n ...rest,\n theme: processed.theme ?? propsRef.current.theme,\n themeConfig,\n };\n update(renderOptions);\n },\n [update, processDSL],\n );\n\n const ref: InfographicRef = {\n toDataURL,\n getTypes,\n update: refUpdate,\n destroy,\n };\n\n return ref;\n}\n","import React, { forwardRef, useImperativeHandle, useRef, useState } from 'react';\nimport { useInfographic } from '../hooks';\nimport type { InfographicProps, InfographicRef, InfographicError } from '../types';\n\nconst defaultError = {\n type: 'render' as const,\n message: 'An error occurred while rendering the infographic.',\n};\n\nfunction InfographicComponent(\n props: InfographicProps,\n ref: React.Ref<InfographicRef>,\n) {\n const containerRef = useRef<HTMLDivElement>(null);\n const [error, setError] = useState<InfographicError | null>(null);\n const [errorKey, setErrorKey] = useState(0);\n\n const infographicRef = useInfographic(containerRef, {\n ...props,\n onError: (err) => {\n setError(err);\n props.onError?.(err);\n },\n });\n\n useImperativeHandle(ref, () => infographicRef, [infographicRef]);\n\n const handleRetry = () => {\n setError(null);\n setErrorKey((prev) => prev + 1);\n };\n\n const containerStyle: React.CSSProperties = {\n width: props.width ?? '100%',\n height: props.height ?? 'auto',\n overflow: 'hidden',\n };\n\n return (\n <>\n <div\n key={`infographic-container-${errorKey}`}\n ref={containerRef}\n className={props.className}\n style={containerStyle}\n data-infographic-container\n />\n {error && (\n <div\n style={{\n position: 'absolute',\n top: 0,\n left: 0,\n right: 0,\n bottom: 0,\n display: 'flex',\n flexDirection: 'column',\n alignItems: 'center',\n justifyContent: 'center',\n backgroundColor: 'rgba(0, 0, 0, 0.05)',\n color: '#d32f2f',\n padding: '20px',\n zIndex: 1,\n textAlign: 'center',\n }}\n >\n <div style={{ fontSize: '1.2em', fontWeight: 'bold', marginBottom: '10px' }}>\n Infographic Render Error\n </div>\n <div style={{ marginBottom: '15px' }}>\n {error.message || defaultError.message}\n </div>\n <button\n type=\"button\"\n onClick={handleRetry}\n style={{\n padding: '8px 16px',\n backgroundColor: '#1976d2',\n color: 'white',\n border: 'none',\n borderRadius: '4px',\n cursor: 'pointer',\n fontSize: '14px',\n }}\n >\n Retry\n </button>\n </div>\n )}\n </>\n );\n}\n\nexport const Infographic = forwardRef(InfographicComponent);\n","import { Component, ErrorInfo, ReactNode } from 'react';\n\ninterface ErrorBoundaryProps {\n children: ReactNode;\n fallback?: ReactNode | ((error: Error, errorInfo: ErrorInfo) => ReactNode);\n onError?: (error: Error, errorInfo: ErrorInfo) => void;\n}\n\ninterface ErrorBoundaryState {\n hasError: boolean;\n error?: Error;\n errorInfo?: ErrorInfo;\n}\n\nexport class ErrorBoundary extends Component<\n ErrorBoundaryProps,\n ErrorBoundaryState\n> {\n constructor(props: ErrorBoundaryProps) {\n super(props);\n this.state = { hasError: false };\n }\n\n static getDerivedStateFromError(error: Error): ErrorBoundaryState {\n return { hasError: true, error };\n }\n\n componentDidCatch(error: Error, errorInfo: ErrorInfo) {\n this.setState({ errorInfo });\n this.props.onError?.(error, errorInfo);\n }\n\n handleReset = () => {\n this.setState({ hasError: false, error: undefined, errorInfo: undefined });\n };\n\n render() {\n const { hasError, error, errorInfo } = this.state;\n const { children, fallback } = this.props;\n\n if (!hasError || !error) {\n return children;\n }\n\n if (fallback) {\n if (typeof fallback === 'function') {\n return fallback(error, errorInfo!);\n }\n return fallback;\n }\n\n return (\n <div\n style={{\n padding: '20px',\n backgroundColor: '#fee',\n border: '1px solid #fcc',\n borderRadius: '4px',\n color: '#c33',\n }}\n >\n <h2 style={{ marginTop: 0 }}>Something went wrong</h2>\n <p>{error.message}</p>\n {errorInfo && (\n <details style={{ marginTop: '10px' }}>\n <summary>Stack trace</summary>\n <pre\n style={{\n marginTop: '10px',\n padding: '10px',\n backgroundColor: 'white',\n borderRadius: '4px',\n overflow: 'auto',\n }}\n >\n {errorInfo.componentStack}\n </pre>\n </details>\n )}\n <button\n type=\"button\"\n onClick={this.handleReset}\n style={{\n marginTop: '15px',\n padding: '8px 16px',\n backgroundColor: '#c33',\n color: 'white',\n border: 'none',\n borderRadius: '4px',\n cursor: 'pointer',\n }}\n >\n Try again\n </button>\n </div>\n );\n }\n}\n"]}