@opendata-ai/openchart-vanilla 6.19.2 → 6.20.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 CHANGED
@@ -3314,11 +3314,24 @@ function setupTableAnimationCleanup(wrapper) {
3314
3314
  }
3315
3315
 
3316
3316
  // src/svg-renderer.ts
3317
- import { BRAND_FONT_SIZE as BRAND_FONT_SIZE2, BRAND_MIN_WIDTH as BRAND_MIN_WIDTH2, estimateTextWidth } from "@opendata-ai/openchart-core";
3317
+ import {
3318
+ BRAND_FONT_SIZE as BRAND_FONT_SIZE2,
3319
+ BRAND_MIN_WIDTH as BRAND_MIN_WIDTH2,
3320
+ estimateTextWidth,
3321
+ wrapText
3322
+ } from "@opendata-ai/openchart-core";
3318
3323
  import { clampStaggerDelay } from "@opendata-ai/openchart-engine";
3319
3324
 
3320
3325
  // src/gradient-utils.ts
3321
3326
  import { isGradientDef } from "@opendata-ai/openchart-core";
3327
+
3328
+ // src/svg-ids.ts
3329
+ var counter = 0;
3330
+ function nextSvgId(prefix) {
3331
+ return `${prefix}-${counter++}`;
3332
+ }
3333
+
3334
+ // src/gradient-utils.ts
3322
3335
  var SVG_NS = "http://www.w3.org/2000/svg";
3323
3336
  function gradientKey(def) {
3324
3337
  return sortedStringify(def);
@@ -3375,7 +3388,6 @@ function appendStop(parent, stop) {
3375
3388
  }
3376
3389
  parent.appendChild(stopEl);
3377
3390
  }
3378
- var globalGradientCounter = 0;
3379
3391
  function buildGradientDefs(marks, defs) {
3380
3392
  const map = /* @__PURE__ */ new Map();
3381
3393
  for (const mark of marks) {
@@ -3383,7 +3395,7 @@ function buildGradientDefs(marks, defs) {
3383
3395
  if (fill && isGradientDef(fill)) {
3384
3396
  const key = gradientKey(fill);
3385
3397
  if (!map.has(key)) {
3386
- const id = `oc-grad-${globalGradientCounter++}`;
3398
+ const id = nextSvgId("oc-grad");
3387
3399
  const el = createGradientElement(fill, id);
3388
3400
  defs.appendChild(el);
3389
3401
  map.set(key, id);
@@ -3455,64 +3467,6 @@ function applyTextStyle(el, style) {
3455
3467
  el.setAttribute("font-variant", style.fontVariant);
3456
3468
  }
3457
3469
  }
3458
- function wrapText(text, fontSize, fontWeight, maxWidth, measureText) {
3459
- if (maxWidth <= 0) return [text];
3460
- const segments = text.split("\n");
3461
- if (segments.length > 1) {
3462
- return segments.flatMap(
3463
- (segment) => segment.length === 0 ? [""] : wrapText(segment, fontSize, fontWeight, maxWidth, measureText)
3464
- );
3465
- }
3466
- if (measureText) {
3467
- const textWidth = measureText(text, fontSize, fontWeight).width;
3468
- if (textWidth <= maxWidth) return [text];
3469
- const words2 = text.split(" ");
3470
- const lines2 = [];
3471
- let current2 = "";
3472
- for (const word of words2) {
3473
- const candidate = current2 ? `${current2} ${word}` : word;
3474
- const candidateWidth = measureText(candidate, fontSize, fontWeight).width;
3475
- if (candidateWidth > maxWidth && current2) {
3476
- lines2.push(current2);
3477
- current2 = word;
3478
- } else {
3479
- current2 = candidate;
3480
- }
3481
- }
3482
- if (current2) lines2.push(current2);
3483
- return lines2;
3484
- }
3485
- const AVG_CHAR_WIDTH = 0.57;
3486
- const WEIGHT_FACTORS = {
3487
- 100: 0.9,
3488
- 200: 0.92,
3489
- 300: 0.95,
3490
- 400: 1,
3491
- 500: 1.02,
3492
- 600: 1.05,
3493
- 700: 1.08,
3494
- 800: 1.1,
3495
- 900: 1.12
3496
- };
3497
- const weightFactor = WEIGHT_FACTORS[fontWeight] ?? 1;
3498
- const charWidth = fontSize * AVG_CHAR_WIDTH * weightFactor;
3499
- const maxChars = Math.floor(maxWidth / charWidth);
3500
- if (text.length <= maxChars) return [text];
3501
- const words = text.split(" ");
3502
- const lines = [];
3503
- let current = "";
3504
- for (const word of words) {
3505
- const candidate = current ? `${current} ${word}` : word;
3506
- if (candidate.length > maxChars && current) {
3507
- lines.push(current);
3508
- current = word;
3509
- } else {
3510
- current = candidate;
3511
- }
3512
- }
3513
- if (current) lines.push(current);
3514
- return lines;
3515
- }
3516
3470
  function renderChromeElement(parent, element, className, chromeKey, measureText) {
3517
3471
  const text = createSVGElement("text");
3518
3472
  setAttrs(text, { x: element.x, y: element.y });
@@ -4354,7 +4308,7 @@ function renderChartSVG(layout, container, opts) {
4354
4308
  fill: layout.theme.colors.background
4355
4309
  });
4356
4310
  svg.appendChild(bg);
4357
- const clipId = `oc-clip-${Math.random().toString(36).slice(2, 8)}`;
4311
+ const clipId = nextSvgId("oc-clip");
4358
4312
  const defs = createSVGElement("defs");
4359
4313
  const clipPath = createSVGElement("clipPath");
4360
4314
  clipPath.setAttribute("id", clipId);
@@ -5680,7 +5634,6 @@ function createChart(container, spec, options) {
5680
5634
  let destroyed = false;
5681
5635
  let isDragging = false;
5682
5636
  let pendingRender = false;
5683
- let resizeTimer = null;
5684
5637
  let isFirstRender = true;
5685
5638
  let cleanupAnimations = null;
5686
5639
  let pendingResize = false;
@@ -6109,10 +6062,6 @@ function createChart(container, spec, options) {
6109
6062
  pendingResize = false;
6110
6063
  }
6111
6064
  cancelAnimations(svgElement);
6112
- if (resizeTimer !== null) {
6113
- clearTimeout(resizeTimer);
6114
- resizeTimer = null;
6115
- }
6116
6065
  if (cleanupTooltipEvents) {
6117
6066
  cleanupTooltipEvents();
6118
6067
  cleanupTooltipEvents = null;
@@ -6178,11 +6127,7 @@ function createChart(container, spec, options) {
6178
6127
  render();
6179
6128
  if (options?.responsive !== false) {
6180
6129
  disconnectResize = observeResize(container, () => {
6181
- if (resizeTimer !== null) clearTimeout(resizeTimer);
6182
- resizeTimer = setTimeout(() => {
6183
- resizeTimer = null;
6184
- resize();
6185
- }, 100);
6130
+ resize();
6186
6131
  });
6187
6132
  }
6188
6133
  return {
@@ -6534,7 +6479,12 @@ function renderCell(cell) {
6534
6479
  import { compileSankey } from "@opendata-ai/openchart-engine";
6535
6480
 
6536
6481
  // src/sankey-renderer.ts
6537
- import { BRAND_FONT_SIZE as BRAND_FONT_SIZE3, BRAND_MIN_WIDTH as BRAND_MIN_WIDTH3, estimateTextWidth as estimateTextWidth2 } from "@opendata-ai/openchart-core";
6482
+ import {
6483
+ BRAND_FONT_SIZE as BRAND_FONT_SIZE3,
6484
+ BRAND_MIN_WIDTH as BRAND_MIN_WIDTH3,
6485
+ estimateTextWidth as estimateTextWidth2,
6486
+ wrapText as wrapText2
6487
+ } from "@opendata-ai/openchart-core";
6538
6488
  import { clampStaggerDelay as clampStaggerDelay2 } from "@opendata-ai/openchart-engine";
6539
6489
  var SVG_NS3 = "http://www.w3.org/2000/svg";
6540
6490
  var XLINK_NS2 = "http://www.w3.org/1999/xlink";
@@ -6574,39 +6524,6 @@ function stampAnimationAttrs2(el, mark, fallbackIndex, animation) {
6574
6524
  el.setAttribute("data-animation-index", String(idx));
6575
6525
  el.style.setProperty("--oc-mark-index", String(idx));
6576
6526
  }
6577
- function wrapText2(text, fontSize, fontWeight, maxWidth) {
6578
- if (maxWidth <= 0) return [text];
6579
- const AVG_CHAR_WIDTH = 0.57;
6580
- const WEIGHT_FACTORS = {
6581
- 100: 0.9,
6582
- 200: 0.92,
6583
- 300: 0.95,
6584
- 400: 1,
6585
- 500: 1.02,
6586
- 600: 1.05,
6587
- 700: 1.08,
6588
- 800: 1.1,
6589
- 900: 1.12
6590
- };
6591
- const weightFactor = WEIGHT_FACTORS[fontWeight] ?? 1;
6592
- const charWidth = fontSize * AVG_CHAR_WIDTH * weightFactor;
6593
- const maxChars = Math.floor(maxWidth / charWidth);
6594
- if (text.length <= maxChars) return [text];
6595
- const words = text.split(" ");
6596
- const lines = [];
6597
- let current = "";
6598
- for (const word of words) {
6599
- const candidate = current ? `${current} ${word}` : word;
6600
- if (candidate.length > maxChars && current) {
6601
- lines.push(current);
6602
- current = word;
6603
- } else {
6604
- current = candidate;
6605
- }
6606
- }
6607
- if (current) lines.push(current);
6608
- return lines;
6609
- }
6610
6527
  function renderChromeElement2(parent, element, className, chromeKey) {
6611
6528
  const text = createSVGElement2("text");
6612
6529
  setAttrs2(text, { x: element.x, y: element.y });