contour-ds 1.7.1 → 1.8.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.
Files changed (109) hide show
  1. package/README.md +80 -11
  2. package/dist/agent-rules.json +16 -0
  3. package/dist/build-manifest.json +184 -107
  4. package/dist/contour-wc-content.esm.js +5125 -0
  5. package/dist/contour-wc-content.esm.min.js +1 -0
  6. package/dist/contour-wc-dashboard.esm.js +8654 -0
  7. package/dist/contour-wc-dashboard.esm.min.js +1 -0
  8. package/dist/contour-wc-data.esm.js +8260 -0
  9. package/dist/contour-wc-data.esm.min.js +1 -0
  10. package/dist/contour-wc-docs.esm.js +4305 -0
  11. package/dist/contour-wc-docs.esm.min.js +1 -0
  12. package/dist/contour-wc-feedback.esm.js +4917 -0
  13. package/dist/contour-wc-feedback.esm.min.js +1 -0
  14. package/dist/contour-wc-forms.esm.js +5688 -0
  15. package/dist/contour-wc-forms.esm.min.js +1 -0
  16. package/dist/contour-wc-interaction.esm.js +4580 -0
  17. package/dist/contour-wc-interaction.esm.min.js +1 -0
  18. package/dist/contour-wc-layout.esm.js +4174 -0
  19. package/dist/contour-wc-layout.esm.min.js +1 -0
  20. package/dist/contour-wc-map.esm.js +5205 -0
  21. package/dist/contour-wc-map.esm.min.js +1 -0
  22. package/dist/contour-wc-misc.esm.js +4264 -0
  23. package/dist/contour-wc-misc.esm.min.js +1 -0
  24. package/dist/contour-wc-navigation.esm.js +5844 -0
  25. package/dist/contour-wc-navigation.esm.min.js +1 -0
  26. package/dist/contour-wc-ui.esm.js +9009 -0
  27. package/dist/contour-wc-ui.esm.min.js +1 -0
  28. package/dist/contour-wc.esm.js +6136 -1634
  29. package/dist/contour-wc.esm.min.js +1 -1
  30. package/dist/contour-wc.js +6135 -1634
  31. package/dist/contour-wc.min.js +1 -1
  32. package/dist/contour.code-snippets +4512 -0
  33. package/dist/contour.components.json +3321 -868
  34. package/dist/contour.css +5863 -3999
  35. package/dist/contour.d.ts +560 -1085
  36. package/dist/contour.esm.js +7 -0
  37. package/dist/contour.esm.min.js +1 -1
  38. package/dist/contour.html-data.json +10311 -0
  39. package/dist/contour.js +7 -0
  40. package/dist/contour.min.css +1 -1
  41. package/dist/contour.min.js +1 -1
  42. package/dist/contour.react.d.ts +420 -0
  43. package/dist/contour.single.html +17 -0
  44. package/dist/contour.single.min.css +1 -0
  45. package/dist/contour.tokens.json +940 -902
  46. package/dist/contour.vue.d.ts +418 -0
  47. package/dist/contour.web-types.json +10703 -0
  48. package/dist/custom-elements.json +30708 -0
  49. package/dist/docs/actions.md +3 -2
  50. package/dist/docs/affordances.md +25 -9
  51. package/dist/docs/apireference.md +1 -1
  52. package/dist/docs/colour.md +1 -1
  53. package/dist/docs/componentindex.md +6 -2
  54. package/dist/docs/data.md +7 -2
  55. package/dist/docs/docs.md +9 -2
  56. package/dist/docs/feedback.md +1 -1
  57. package/dist/docs/field.md +1 -1
  58. package/dist/docs/forms.md +1 -1
  59. package/dist/docs/index.json +22 -20
  60. package/dist/docs/install.md +1 -1
  61. package/dist/docs/landing.md +1 -1
  62. package/dist/docs/mapengine.md +19 -2
  63. package/dist/docs/motion.md +1 -1
  64. package/dist/docs/navigation.md +1 -1
  65. package/dist/docs/overlays.md +1 -1
  66. package/dist/docs/overview.md +1 -1
  67. package/dist/docs/patterns.md +2 -2
  68. package/dist/docs/playground.md +22 -2
  69. package/dist/docs/principles.md +1 -1
  70. package/dist/docs/recipes.md +13 -8
  71. package/dist/docs/space.md +1 -1
  72. package/dist/docs/status.md +14 -2
  73. package/dist/docs/surfaces.md +1 -1
  74. package/dist/docs/theming.md +1 -1
  75. package/dist/docs/type.md +1 -1
  76. package/dist/docs/webcomponents.md +17 -3
  77. package/dist/registry/items/contour-core.json +2 -2
  78. package/dist/registry/items/contour-data.json +2 -2
  79. package/dist/registry/items/contour-docs.json +2 -2
  80. package/dist/registry/items/contour-landing.json +2 -2
  81. package/dist/registry/registry.json +8 -8
  82. package/dist/surfaces/contour-core.min.css +1 -1
  83. package/dist/surfaces/contour-data.min.css +1 -1
  84. package/dist/surfaces/contour-docs.min.css +1 -1
  85. package/dist/surfaces/contour-landing.min.css +1 -1
  86. package/dist/wc/behaviours.mjs +45 -57
  87. package/dist/wc/content.mjs +264 -63
  88. package/dist/wc/core.mjs +390 -71
  89. package/dist/wc/dashboard.mjs +220 -13
  90. package/dist/wc/data.mjs +1094 -458
  91. package/dist/wc/docs.mjs +105 -12
  92. package/dist/wc/feedback.mjs +63 -14
  93. package/dist/wc/forms.mjs +739 -106
  94. package/dist/wc/index.mjs +9 -2
  95. package/dist/wc/interaction.mjs +184 -28
  96. package/dist/wc/layout.mjs +97 -27
  97. package/dist/wc/map.mjs +185 -118
  98. package/dist/wc/misc.mjs +124 -24
  99. package/dist/wc/navigation.mjs +384 -114
  100. package/dist/wc/shadow.mjs +94 -18
  101. package/dist/wc/states.mjs +21 -3
  102. package/dist/wc/svg.mjs +104 -0
  103. package/dist/wc/ui.mjs +1995 -478
  104. package/integrations/README.md +2 -0
  105. package/integrations/ai/CLAUDE.md +3 -3
  106. package/integrations/frameworks/README.md +235 -0
  107. package/integrations/native/style-dictionary.config.json +1 -1
  108. package/integrations/tailwind/contour-theme.css +5 -6
  109. package/package.json +53 -24
@@ -70,10 +70,19 @@ import { define, MODS, REGISTERED, CONTOUR_EVENTS, contourId } from './core.mjs'
70
70
  static get observedAttributes() { return MODS; }
71
71
  constructor() {
72
72
  super();
73
- const root = this.attachShadow({ mode: "open" });
73
+ // Reuse a Declarative Shadow Root when the platform already attached one
74
+ // (SSR/DSD hydration); otherwise create and populate the shadow root.
75
+ let root = this.shadowRoot;
76
+ if (!root) {
77
+ root = this.attachShadow({ mode: "open" });
78
+ if (this.constructor.contourTemplate) {
79
+ root.appendChild(this.constructor.contourTemplate.content.cloneNode(true));
80
+ }
81
+ }
74
82
  const sheets = adoptedSheets();
75
- if (sheets.length) root.adoptedStyleSheets = sheets;
76
- root.appendChild(this.constructor.contourTemplate.content.cloneNode(true));
83
+ if (sheets.length) {
84
+ try { root.adoptedStyleSheets = sheets; } catch (e) { /* unsupported or read-only */ }
85
+ }
77
86
  this._shadowBase = root.firstElementChild ? root.firstElementChild.className : "";
78
87
  }
79
88
  // Subclasses with behaviour beyond the template override this.
@@ -144,10 +153,21 @@ import { define, MODS, REGISTERED, CONTOUR_EVENTS, contourId } from './core.mjs'
144
153
  }
145
154
  }
146
155
  });
147
- // ARIA: alert elements get live region roles
156
+ // ARIA: alert elements are live regions, and the variant sets the volume.
157
+ // A warning/danger interrupts; info/success/accent speaks politely. An
158
+ // information alert that asserts itself on load talks over the reader.
148
159
  root.querySelectorAll(".c-alert").forEach((el) => {
149
- if (!el.hasAttribute("role")) el.setAttribute("role", "alert");
150
- if (!el.hasAttribute("aria-live")) el.setAttribute("aria-live", "assertive");
160
+ const urgent = el.classList.contains("c-alert--warning") || el.classList.contains("c-alert--danger");
161
+ const role = urgent ? "alert" : "status";
162
+ const live = urgent ? "assertive" : "polite";
163
+ if (!el.hasAttribute("role") || el.dataset.contourAutoRole) {
164
+ el.setAttribute("role", role);
165
+ el.dataset.contourAutoRole = role;
166
+ }
167
+ if (!el.hasAttribute("aria-live") || el.dataset.contourAutoLive) {
168
+ el.setAttribute("aria-live", live);
169
+ el.dataset.contourAutoLive = live;
170
+ }
151
171
  });
152
172
  // ARIA: required form fields
153
173
  root.querySelectorAll("input[required], textarea[required], select[required]").forEach((el) => {
@@ -202,19 +222,41 @@ connectedCallback() {
202
222
  }
203
223
  }
204
224
  el.className = (this._shadowBase + " " + mods.join(" ")).trim();
225
+ // An alert's live region follows its variant, and rewriting the class above
226
+ // is the only signal a variant change produces. `dataset.contourAutoRole`
227
+ // marks a role this code set, so an authored one is never overwritten.
228
+ if (el.classList.contains("c-alert")) {
229
+ const urgent = el.classList.contains("c-alert--warning") || el.classList.contains("c-alert--danger");
230
+ const role = urgent ? "alert" : "status";
231
+ const live = urgent ? "assertive" : "polite";
232
+ if (!el.hasAttribute("role") || el.dataset.contourAutoRole) {
233
+ el.setAttribute("role", role);
234
+ el.dataset.contourAutoRole = role;
235
+ }
236
+ if (!el.hasAttribute("aria-live") || el.dataset.contourAutoLive) {
237
+ el.setAttribute("aria-live", live);
238
+ el.dataset.contourAutoLive = live;
239
+ }
240
+ }
205
241
  }
206
242
  }
207
243
 
208
- // Registers a wrapper. The template is parsed once into a <template> and
209
- // cloned per instance, so the markup below is the markup the root gets.
244
+ // Registers a wrapper. The template markup is always recorded so Node/SSR
245
+ // tooling can emit Declarative Shadow DOM strings; in a browser the template
246
+ // is also parsed once into a <template> and cloned per instance.
210
247
  const SHADOW_PARTS_PUBLIC = {};
248
+ const SHADOW_MARKUP = {};
249
+ const recordParts = (name, markup) => {
250
+ SHADOW_PARTS_PUBLIC[name] = [...markup.matchAll(/part="([^"]+)"/g)]
251
+ .flatMap((m) => m[1].split(/\s+/))
252
+ .filter(Boolean);
253
+ };
211
254
  const shadow = (name, markup) => {
255
+ SHADOW_MARKUP[name] = markup;
256
+ recordParts(name, markup);
212
257
  if (typeof document === "undefined") return;
213
258
  const tpl = document.createElement("template");
214
259
  tpl.innerHTML = markup;
215
- SHADOW_PARTS_PUBLIC[name] = [...tpl.content.querySelectorAll("[part]")]
216
- .flatMap((node) => (node.getAttribute("part") || "").split(/\s+/))
217
- .filter(Boolean);
218
260
  const cls = class extends ContourShadow {};
219
261
  cls.contourTemplate = tpl;
220
262
  define(name, cls);
@@ -274,12 +316,16 @@ connectedCallback() {
274
316
  "contour-plot": "plot",
275
317
  };
276
318
 
277
- if (typeof document !== "undefined") {
278
- for (const [tag, blocks] of Object.entries(SHADOW_SLOTS)) {
279
- for (const block of blocks) {
280
- const part = SHADOW_PARTS[block] || block;
281
- shadow("contour-shadow-" + block, slotWrapper(tag, block, part));
282
- }
319
+ // The slot wrappers are recorded wherever this module runs. `shadow()` already
320
+ // returns before touching `document` when there is none, so the markup is
321
+ // available to Node/SSR either way — which is the whole point of recording it.
322
+ // This loop used to sit inside the browser guard, so `renderShadowDSD` could
323
+ // only resolve the 50 hand-written wrappers in Node and returned null for the
324
+ // 121 slot wrappers, i.e. it failed in the one environment it exists for.
325
+ for (const [tag, blocks] of Object.entries(SHADOW_SLOTS)) {
326
+ for (const block of blocks) {
327
+ const part = SHADOW_PARTS[block] || block;
328
+ shadow("contour-shadow-" + block, slotWrapper(tag, block, part));
283
329
  }
284
330
  }
285
331
 
@@ -345,10 +391,13 @@ shadow("contour-shadow-filter-pill", `<span class="c-filter-pill" part="filter-p
345
391
 
346
392
  // The dialog is the one wrapper with behaviour, because a close button that
347
393
  // does not close is a control the reader cannot use.
394
+ const DIALOG_MARKUP = "<dialog class=\"c-dialog\" part=\"dialog\"> <div class=\"c-dialog__head\" part=\"head\"> <slot name=\"title\"></slot> <button class=\"c-btn c-btn--icon c-btn--ghost\" part=\"close\" type=\"button\" aria-label=\"Close\"> <svg aria-hidden=\"true\"><use href=\"#i-x\" /></svg> </button> </div> <div class=\"c-dialog__body\" part=\"body\"><slot></slot></div> <div class=\"c-dialog__foot\" part=\"foot\"><slot name=\"foot\"></slot></div> </dialog>";
395
+ SHADOW_MARKUP["contour-shadow-dialog"] = DIALOG_MARKUP;
396
+ recordParts("contour-shadow-dialog", DIALOG_MARKUP);
348
397
  class ContourShadowDialog extends ContourShadow {
349
398
  static contourTemplate = (typeof document !== "undefined") ? (() => {
350
399
  const tpl = document.createElement("template");
351
- tpl.innerHTML = "<dialog class=\"c-dialog\" part=\"dialog\"> <div class=\"c-dialog__head\" part=\"head\"> <slot name=\"title\"></slot> <button class=\"c-btn c-btn--icon c-btn--ghost\" part=\"close\" type=\"button\" aria-label=\"Close\"> <svg aria-hidden=\"true\"><use href=\"#i-close\" /></svg> </button> </div> <div class=\"c-dialog__body\" part=\"body\"><slot></slot></div> <div class=\"c-dialog__foot\" part=\"foot\"><slot name=\"foot\"></slot></div> </dialog>";
400
+ tpl.innerHTML = DIALOG_MARKUP;
352
401
  return tpl;
353
402
  })() : null;
354
403
  enhance(root) {
@@ -404,13 +453,36 @@ shadow("contour-shadow-filter-pill", `<span class="c-filter-pill" part="filter-p
404
453
  }
405
454
  show() { this.shadowRoot?.querySelector("dialog")?.showModal(); }
406
455
  close() { this.shadowRoot?.querySelector("dialog")?.close(); }
456
+ // Native-dialog parity with the light family (R20 T-32): showModal() is
457
+ // the same modal open path under its native name, open routes through
458
+ // show()/close(), and returnValue delegates to the platform's own.
459
+ showModal() { this.show(); }
460
+ get open() { return !!this.shadowRoot?.querySelector("dialog")?.open; }
461
+ set open(v) { if (v) this.show(); else this.close(); }
462
+ get returnValue() { return this.shadowRoot?.querySelector("dialog")?.returnValue ?? ""; }
463
+ set returnValue(v) { const d = this.shadowRoot?.querySelector("dialog"); if (d) d.returnValue = String(v); }
407
464
  }
408
465
  define("contour-shadow-dialog", ContourShadowDialog);
409
466
 
467
+ /**
468
+ * Render a Declarative Shadow DOM string for a registered contour-shadow-* element.
469
+ * Intended for SSR/string emission; returns null for unknown tags.
470
+ */
471
+ const renderShadowDSD = (tag, attrs = "", light = "") => {
472
+ const markup = SHADOW_MARKUP[tag];
473
+ if (typeof markup !== "string") return null;
474
+ const attrStr = attrs ? (attrs.startsWith(" ") ? attrs : " " + attrs) : "";
475
+ return `<${tag}${attrStr}><template shadowrootmode="open">${markup}</template>${light}</${tag}>`;
476
+ };
477
+
410
478
  // Published once, at the end, so the array holds what the browser was actually
411
479
  // handed rather than what the source appears to say. Frozen: a page that
412
480
  // reshapes it would make the next reader's count wrong, which is the failure
413
481
  // this array exists to prevent.
482
+ const FROZEN_SHADOW_MARKUP = Object.freeze({ ...SHADOW_MARKUP });
483
+ if (typeof globalThis !== "undefined") {
484
+ globalThis.ContourShadowTemplates = FROZEN_SHADOW_MARKUP;
485
+ }
414
486
  if (typeof window !== "undefined") {
415
487
  window.ContourElements = Object.freeze(REGISTERED.slice());
416
488
  window.ContourShadowParts = Object.freeze(Object.fromEntries(
@@ -420,4 +492,8 @@ shadow("contour-shadow-filter-pill", `<span class="c-filter-pill" part="filter-p
420
492
  // page cannot add names the source never emitted, which would make the gate's
421
493
  // "every dispatchEvent name has an entry" read meaningless.
422
494
  window.ContourEvents = Object.freeze(CONTOUR_EVENTS);
495
+ if (!window.Contour) window.Contour = {};
496
+ try { window.Contour.shadowTemplates = FROZEN_SHADOW_MARKUP; } catch {}
423
497
  }
498
+
499
+ export { SHADOW_MARKUP, renderShadowDSD };
@@ -55,6 +55,24 @@ export const STATE_FALLBACK = {
55
55
  error: "Could not load.",
56
56
  };
57
57
 
58
+ /**
59
+ * Resolve a state label for a host (R18-63). A consumer supplies a `labels`
60
+ * JSON attribute (e.g. `labels='{"loading":"Chargement…"}'`); it is merged over
61
+ * the English default, so a partial object localises only the keys it names.
62
+ * A malformed attribute is ignored rather than thrown — a bad label must not
63
+ * take the widget down. Returns the default when no override is present.
64
+ */
65
+ export function stateLabel(host, key) {
66
+ const fallback = STATE_FALLBACK[key] || key;
67
+ const raw = host && host.getAttribute ? host.getAttribute("labels") : null;
68
+ if (!raw) return fallback;
69
+ try {
70
+ const parsed = JSON.parse(raw);
71
+ if (parsed && typeof parsed === "object" && typeof parsed[key] === "string" && parsed[key]) return parsed[key];
72
+ } catch (e) { /* a malformed labels attribute is ignored, not fatal */ }
73
+ return fallback;
74
+ }
75
+
58
76
  // One in-flight request per URL, shared by every host that asked for it.
59
77
  const remoteInflight = new Map();
60
78
  // The last result per URL, so a re-mounted host paints instead of re-asking. A
@@ -495,12 +513,12 @@ export function renderStates(host, block, opts) {
495
513
  const options = opts || {};
496
514
  const loading = host.getAttribute("loading");
497
515
  if (loading !== null || host._remoteStatus === "loading") {
498
- host.appendChild(stateNode(block, "loading", loading || STATE_FALLBACK.loading));
516
+ host.appendChild(stateNode(block, "loading", loading || stateLabel(host, "loading")));
499
517
  return true;
500
518
  }
501
519
  const error = host.getAttribute("error");
502
520
  if (error !== null || host._remoteStatus === "error") {
503
- const message = (error !== null && error !== "") ? error : (host._remoteError || STATE_FALLBACK.error);
521
+ const message = (error !== null && error !== "") ? error : (host._remoteError || stateLabel(host, "error"));
504
522
  const node = stateNode(block, "error", message);
505
523
  // `retry` is the actionable half of an error. It reuses the button the system
506
524
  // already ships and the `contour:retry` event three components already emit,
@@ -528,7 +546,7 @@ export function renderStates(host, block, opts) {
528
546
  /** Paint the empty state — for a host with no data and no authored content. */
529
547
  /** Render the empty state for a block. */
530
548
  export function renderEmpty(host, block) {
531
- host.appendChild(stateNode(block, "empty", host.getAttribute("empty") || STATE_FALLBACK.empty));
549
+ host.appendChild(stateNode(block, "empty", host.getAttribute("empty") || stateLabel(host, "empty")));
532
550
  }
533
551
 
534
552
  // Delegated on the host (AGENTS.md rule 12): the retry button is regenerated on
package/dist/wc/svg.mjs CHANGED
@@ -230,3 +230,107 @@ export function markerStyles(shape) {
230
230
  export function assignMarkers(items) {
231
231
  return (items || []).map((it, i) => ({ ...it, marker: MARKER_SHAPES[i % MARKER_SHAPES.length] }));
232
232
  }
233
+
234
+ /* ---------------------------------------------------------------------------
235
+ * Contour lines — marching squares over a 2D field.
236
+ *
237
+ * The same algorithm as tools/contour-gen.py, ported to the browser. Iso-lines
238
+ * of different levels of one continuous field cannot cross; the asymptotic
239
+ * saddle decider below is what guarantees that, so a hand-drawn path is never
240
+ * a substitute. Shared by the `contour-contour-plot` element and the guide's
241
+ * `data-contour-plot` renderer so the two cannot drift.
242
+ * ------------------------------------------------------------------------- */
243
+
244
+ /**
245
+ * Extract the iso-line segments of a scalar field at one level.
246
+ *
247
+ * @param {number[][]} grid row-major field values
248
+ * @param {number} level iso-level to extract
249
+ * @returns {Array<[{x:number,y:number},{x:number,y:number}]>} segments in grid space
250
+ */
251
+ export function marchingSquares(grid, level) {
252
+ const rows = grid.length;
253
+ const cols = rows ? grid[0].length : 0;
254
+ const segments = [];
255
+ if (!rows || !cols) return segments;
256
+
257
+ const lerp = (a, b, va, vb) => (vb === va ? 0.5 : (level - va) / (vb - va));
258
+
259
+ for (let y = 0; y < rows - 1; y++) {
260
+ for (let x = 0; x < cols - 1; x++) {
261
+ const tl = grid[y][x];
262
+ const tr = grid[y][x + 1];
263
+ const bl = grid[y + 1][x];
264
+ const br = grid[y + 1][x + 1];
265
+ const code =
266
+ (tl >= level ? 8 : 0) |
267
+ (tr >= level ? 4 : 0) |
268
+ (br >= level ? 2 : 0) |
269
+ (bl >= level ? 1 : 0);
270
+ if (code === 0 || code === 15) continue;
271
+
272
+ const top = { x: x + lerp(tl, tr, tl, tr), y };
273
+ const right = { x: x + 1, y: y + lerp(tr, br, tr, br) };
274
+ const bottom = { x: x + lerp(bl, br, bl, br), y: y + 1 };
275
+ const left = { x, y: y + lerp(tl, bl, tl, bl) };
276
+
277
+ let connect;
278
+ if (code === 5) {
279
+ const center = (tl + tr + bl + br) / 4;
280
+ connect = center >= level ? "top-bottom" : "left-right";
281
+ } else if (code === 10) {
282
+ const center = (tl + tr + bl + br) / 4;
283
+ connect = center >= level ? "left-right" : "top-bottom";
284
+ }
285
+
286
+ switch (code) {
287
+ case 1: case 14: segments.push([left, bottom]); break;
288
+ case 2: case 13: segments.push([bottom, right]); break;
289
+ case 3: case 12: segments.push([left, right]); break;
290
+ case 4: case 11: segments.push([top, right]); break;
291
+ case 6: case 9: segments.push([top, bottom]); break;
292
+ case 7: case 8: segments.push([left, top]); break;
293
+ case 5:
294
+ if (connect === "top-bottom") {
295
+ segments.push([top, bottom], [left, right]);
296
+ } else {
297
+ segments.push([top, right], [left, bottom]);
298
+ }
299
+ break;
300
+ case 10:
301
+ if (connect === "left-right") {
302
+ segments.push([left, right], [top, bottom]);
303
+ } else {
304
+ segments.push([top, right], [left, bottom]);
305
+ }
306
+ break;
307
+ }
308
+ }
309
+ }
310
+ return segments;
311
+ }
312
+
313
+ /**
314
+ * Build the SVG `d` path for every level of a field.
315
+ *
316
+ * @param {number[][]} grid row-major field values
317
+ * @param {number[]} levels iso-levels, one path per level
318
+ * @param {number} width viewBox width in px
319
+ * @param {number} height viewBox height in px
320
+ * @returns {Array<{level:number, d:string}>} one entry per level
321
+ */
322
+ export function contourPaths(grid, levels, width, height) {
323
+ const rows = grid.length;
324
+ const cols = rows ? grid[0].length : 0;
325
+ if (rows < 2 || cols < 2) return [];
326
+ const sx = width / (cols - 1);
327
+ const sy = height / (rows - 1);
328
+ return (levels || []).map((level) => {
329
+ const segs = marchingSquares(grid, level);
330
+ let d = "";
331
+ for (const [a, b] of segs) {
332
+ d += `M ${(a.x * sx).toFixed(2)} ${(a.y * sy).toFixed(2)} L ${(b.x * sx).toFixed(2)} ${(b.y * sy).toFixed(2)} `;
333
+ }
334
+ return { level, d: d.trim() };
335
+ });
336
+ }