stickyflow 0.9.2 → 0.10.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.
Files changed (58) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +1 -1
  3. package/dist/binding/index.cjs +9 -9
  4. package/dist/binding/index.d.cts +3 -3
  5. package/dist/binding/index.d.ts +3 -3
  6. package/dist/binding/index.js +3 -3
  7. package/dist/{chunk-EURX7QT3.cjs → chunk-5PJ55GPG.cjs} +883 -830
  8. package/dist/chunk-5PJ55GPG.cjs.map +1 -0
  9. package/dist/{chunk-AAP24GBG.js → chunk-EGUPN56K.js} +3 -3
  10. package/dist/chunk-EGUPN56K.js.map +1 -0
  11. package/dist/{chunk-Q6FBISNP.js → chunk-HRU6VOEC.js} +545 -331
  12. package/dist/chunk-HRU6VOEC.js.map +1 -0
  13. package/dist/{chunk-3EOG34QN.cjs → chunk-KRSX4UZ7.cjs} +308 -252
  14. package/dist/chunk-KRSX4UZ7.cjs.map +1 -0
  15. package/dist/{chunk-XNNNIOJU.js → chunk-L7CEX5JV.js} +5 -5
  16. package/dist/{chunk-XNNNIOJU.js.map → chunk-L7CEX5JV.js.map} +1 -1
  17. package/dist/{chunk-C25NWWIH.cjs → chunk-LSEMXRB5.cjs} +549 -331
  18. package/dist/chunk-LSEMXRB5.cjs.map +1 -0
  19. package/dist/{chunk-MR32IJQO.cjs → chunk-SCD3AHMY.cjs} +15 -15
  20. package/dist/chunk-SCD3AHMY.cjs.map +1 -0
  21. package/dist/{chunk-G2N3KJYJ.js → chunk-SDOHUNBW.js} +237 -184
  22. package/dist/chunk-SDOHUNBW.js.map +1 -0
  23. package/dist/{chunk-2GKXPZRL.cjs → chunk-TECWZVIM.cjs} +23 -23
  24. package/dist/chunk-TECWZVIM.cjs.map +1 -0
  25. package/dist/{chunk-C3LVKPWQ.js → chunk-VPNOVRWP.js} +279 -223
  26. package/dist/chunk-VPNOVRWP.js.map +1 -0
  27. package/dist/index.cjs +36 -36
  28. package/dist/index.d.cts +33 -28
  29. package/dist/index.d.ts +33 -28
  30. package/dist/index.js +5 -5
  31. package/dist/interaction/index.cjs +358 -337
  32. package/dist/interaction/index.cjs.map +1 -1
  33. package/dist/interaction/index.js +133 -112
  34. package/dist/interaction/index.js.map +1 -1
  35. package/dist/{runtime-DG8X3Fwf.d.cts → runtime-Bkv7QW7H.d.cts} +1 -1
  36. package/dist/{runtime-kqD1RS17.d.ts → runtime-DJ4K4_HZ.d.ts} +1 -1
  37. package/dist/{runtimeTypes-CvjlBZds.d.cts → runtimeTypes-BvJBZLkr.d.cts} +1 -1
  38. package/dist/{runtimeTypes-vRaHOIHi.d.ts → runtimeTypes-C1shzoyr.d.ts} +1 -1
  39. package/dist/stickyflow-diagram.global.js +41 -41
  40. package/dist/stickyflow-diagram.global.js.map +1 -1
  41. package/dist/viewer/index.cjs +9 -9
  42. package/dist/viewer/index.d.cts +1 -1
  43. package/dist/viewer/index.d.ts +1 -1
  44. package/dist/viewer/index.js +4 -4
  45. package/dist/web-component/index.cjs +6 -6
  46. package/dist/web-component/index.cjs.map +1 -1
  47. package/dist/web-component/index.js +4 -4
  48. package/dist/web-component/index.js.map +1 -1
  49. package/package.json +1 -1
  50. package/dist/chunk-2GKXPZRL.cjs.map +0 -1
  51. package/dist/chunk-3EOG34QN.cjs.map +0 -1
  52. package/dist/chunk-AAP24GBG.js.map +0 -1
  53. package/dist/chunk-C25NWWIH.cjs.map +0 -1
  54. package/dist/chunk-C3LVKPWQ.js.map +0 -1
  55. package/dist/chunk-EURX7QT3.cjs.map +0 -1
  56. package/dist/chunk-G2N3KJYJ.js.map +0 -1
  57. package/dist/chunk-MR32IJQO.cjs.map +0 -1
  58. package/dist/chunk-Q6FBISNP.js.map +0 -1
@@ -191,23 +191,135 @@ function extrudeFootprint(frame, footprint, cornerRadius = 0) {
191
191
  return { top, sides };
192
192
  }
193
193
 
194
- // src/model/isometricObject/shading.ts
195
- function clamp255(value) {
196
- return Math.max(0, Math.min(255, Math.round(value)));
197
- }
198
- function hexToRgb(hex) {
199
- const match = /^#?([0-9a-fA-F]{6})$/.exec(hex.trim());
194
+ // src/model/color/conversion.ts
195
+ var hexToRgb = (hex) => {
196
+ const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?$/i.exec(hex);
197
+ if (!result) {
198
+ return { r: 255, g: 255, b: 255, a: 1 };
199
+ }
200
+ return {
201
+ r: parseInt(result[1], 16),
202
+ g: parseInt(result[2], 16),
203
+ b: parseInt(result[3], 16),
204
+ a: result[4] === void 0 ? 1 : parseInt(result[4], 16) / 255
205
+ };
206
+ };
207
+ var parseHexRgb = (value) => {
208
+ const match = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(value.trim());
200
209
  if (!match) {
201
210
  return null;
202
211
  }
203
- const n = Number.parseInt(match[1], 16);
212
+ const digits = match[1].length === 3 ? [...match[1]].map((digit) => digit + digit).join("") : match[1];
213
+ const n = Number.parseInt(digits, 16);
204
214
  return [n >> 16 & 255, n >> 8 & 255, n & 255];
215
+ };
216
+ var rgbToHex = (r, g, b, a) => {
217
+ const channel = (x) => {
218
+ const hex = Math.max(0, Math.min(255, Math.round(x))).toString(16);
219
+ return hex.length === 1 ? `0${hex}` : hex;
220
+ };
221
+ const alphaChannel = a === void 0 || a >= 1 ? "" : channel(a * 255);
222
+ return `#${channel(r)}${channel(g)}${channel(b)}${alphaChannel}`;
223
+ };
224
+ var hsvToRgb = (h, s, v) => {
225
+ const c = v * s;
226
+ const x = c * (1 - Math.abs(h / 60 % 2 - 1));
227
+ const m = v - c;
228
+ let r = 0, g = 0, b = 0;
229
+ if (h >= 0 && h < 60) {
230
+ r = c;
231
+ g = x;
232
+ b = 0;
233
+ } else if (h >= 60 && h < 120) {
234
+ r = x;
235
+ g = c;
236
+ b = 0;
237
+ } else if (h >= 120 && h < 180) {
238
+ r = 0;
239
+ g = c;
240
+ b = x;
241
+ } else if (h >= 180 && h < 240) {
242
+ r = 0;
243
+ g = x;
244
+ b = c;
245
+ } else if (h >= 240 && h < 300) {
246
+ r = x;
247
+ g = 0;
248
+ b = c;
249
+ } else if (h >= 300 && h < 360) {
250
+ r = c;
251
+ g = 0;
252
+ b = x;
253
+ }
254
+ return {
255
+ r: Math.round((r + m) * 255),
256
+ g: Math.round((g + m) * 255),
257
+ b: Math.round((b + m) * 255)
258
+ };
259
+ };
260
+ var rgbToHsv = (r, g, b) => {
261
+ r /= 255;
262
+ g /= 255;
263
+ b /= 255;
264
+ const max = Math.max(r, g, b);
265
+ const min = Math.min(r, g, b);
266
+ const delta = max - min;
267
+ let h = 0;
268
+ if (delta !== 0) {
269
+ if (max === r) {
270
+ h = 60 * ((g - b) / delta % 6);
271
+ } else if (max === g) {
272
+ h = 60 * ((b - r) / delta + 2);
273
+ } else if (max === b) {
274
+ h = 60 * ((r - g) / delta + 4);
275
+ }
276
+ }
277
+ if (h < 0) {
278
+ h += 360;
279
+ }
280
+ const s = max === 0 ? 0 : delta / max;
281
+ const v = max;
282
+ return { h, s, v };
283
+ };
284
+
285
+ // src/model/color/interpolation.ts
286
+ function mixHexColors(start, end, ratio) {
287
+ const startRgb = hexToRgb(start);
288
+ const endRgb = hexToRgb(end);
289
+ const startAlpha = startRgb.a ?? 1;
290
+ const endAlpha = endRgb.a ?? 1;
291
+ return rgbToHex(
292
+ Math.round(startRgb.r + (endRgb.r - startRgb.r) * ratio),
293
+ Math.round(startRgb.g + (endRgb.g - startRgb.g) * ratio),
294
+ Math.round(startRgb.b + (endRgb.b - startRgb.b) * ratio),
295
+ startAlpha + (endAlpha - startAlpha) * ratio
296
+ );
205
297
  }
206
- function rgbToHex(r, g, b) {
207
- return `#${[r, g, b].map((channel) => clamp255(channel).toString(16).padStart(2, "0")).join("")}`;
298
+ function interpolateHexColorStops(stops, position) {
299
+ const sortedStops = [...stops].sort((first2, second) => first2.position - second.position);
300
+ const first = sortedStops[0];
301
+ const last = sortedStops[sortedStops.length - 1];
302
+ if (position <= first.position) {
303
+ return first.color;
304
+ }
305
+ if (position >= last.position) {
306
+ return last.color;
307
+ }
308
+ for (let index = 0; index < sortedStops.length - 1; index++) {
309
+ const start = sortedStops[index];
310
+ const end = sortedStops[index + 1];
311
+ if (position >= start.position && position <= end.position) {
312
+ const range = end.position - start.position;
313
+ const ratio = range === 0 ? 0 : (position - start.position) / range;
314
+ return mixHexColors(start.color, end.color, ratio);
315
+ }
316
+ }
317
+ return last.color;
208
318
  }
319
+
320
+ // src/model/isometricObject/shading.ts
209
321
  function multiply(hex, factor) {
210
- const rgb = hexToRgb(hex);
322
+ const rgb = parseHexRgb(hex);
211
323
  if (!rgb) {
212
324
  return hex;
213
325
  }
@@ -1070,14 +1182,16 @@ var NAMED_BLOCK_KINDS = [
1070
1182
  "Symbol",
1071
1183
  "Port",
1072
1184
  "DataSource",
1073
- "Repeat"
1185
+ "Repeat",
1186
+ "Template",
1187
+ "Use"
1074
1188
  ];
1075
1189
  var SIDES = ["top", "bottom", "left", "right"];
1076
1190
  var isSide = (s) => SIDES.includes(s);
1077
1191
  var isComponentBlockKind = (kind) => kind === "Component" || kind === "Widget";
1078
1192
  var isNamedBlockKind = (s) => NAMED_BLOCK_KINDS.includes(s);
1079
1193
 
1080
- // src/sflLanguage/parsing/values.ts
1194
+ // src/sflLanguage/parsing/pathSegments.ts
1081
1195
  function parsePathSegments(cursor) {
1082
1196
  const segments = [cursor.expect("ident", "path identifier").value];
1083
1197
  while (cursor.at("dot")) {
@@ -1086,111 +1200,6 @@ function parsePathSegments(cursor) {
1086
1200
  }
1087
1201
  return segments;
1088
1202
  }
1089
- function parseEndpoint(cursor) {
1090
- const segments = parsePathSegments(cursor);
1091
- let side;
1092
- let fraction;
1093
- if (cursor.at("comma")) {
1094
- cursor.next();
1095
- const sideToken = cursor.expect("ident", 'side after ","');
1096
- if (!isSide(sideToken.value)) {
1097
- throw new SflParseError(
1098
- `expected a side (top/right/bottom/left), got '${sideToken.value}'`,
1099
- sideToken.line,
1100
- sideToken.col
1101
- );
1102
- }
1103
- side = sideToken.value;
1104
- if (cursor.at("lparen")) {
1105
- cursor.next();
1106
- fraction = cursor.expectNumber('fraction inside "("');
1107
- cursor.expect("rparen", "')'");
1108
- }
1109
- }
1110
- return { type: "endpoint", segments, side, fraction };
1111
- }
1112
- function parseList(cursor) {
1113
- cursor.expect("lbracket", "'['");
1114
- const values = [];
1115
- cursor.skipNewlines();
1116
- if (!cursor.at("rbracket")) {
1117
- values.push(parseValue(cursor, false));
1118
- cursor.skipNewlines();
1119
- while (cursor.at("comma")) {
1120
- cursor.next();
1121
- cursor.skipNewlines();
1122
- if (cursor.at("rbracket")) {
1123
- break;
1124
- }
1125
- values.push(parseValue(cursor, false));
1126
- cursor.skipNewlines();
1127
- }
1128
- }
1129
- cursor.expect("rbracket", "']'");
1130
- return { type: "list", values };
1131
- }
1132
- var ARITHMETIC = /* @__PURE__ */ new Set(["+", "-", "*", "/", ">", "<", ">=", "<=", "==", "!=", "&&", "||"]);
1133
- function startsComputed(cursor) {
1134
- const first = cursor.peek();
1135
- if (first.type === "op" && first.value === "-") {
1136
- return true;
1137
- }
1138
- if (first.type !== "number" && first.type !== "ident" && first.type !== "lparen") {
1139
- return false;
1140
- }
1141
- for (let offset = 0; ; offset++) {
1142
- const token = cursor.peek(offset);
1143
- if (token.type === "newline" || token.type === "semi" || token.type === "rbrace" || token.type === "eof") {
1144
- return false;
1145
- }
1146
- if (token.type === "lparen" || token.type === "op" && ARITHMETIC.has(token.value)) {
1147
- return true;
1148
- }
1149
- if (token.type === "ident" && cursor.peek(offset - 1).type === "comma") {
1150
- return true;
1151
- }
1152
- if (offset === 0 && token.type === "ident" && cursor.peek(1).type === "comma") {
1153
- return true;
1154
- }
1155
- }
1156
- }
1157
- function parseComputed(cursor) {
1158
- const items = [parseExpression(cursor)];
1159
- while (cursor.at("comma")) {
1160
- cursor.next();
1161
- items.push(parseExpression(cursor));
1162
- }
1163
- return { type: "expr", items };
1164
- }
1165
- function parseValue(cursor, allowTuple = true) {
1166
- if (allowTuple && startsComputed(cursor)) {
1167
- return parseComputed(cursor);
1168
- }
1169
- const token = cursor.peek();
1170
- switch (token.type) {
1171
- case "string":
1172
- cursor.next();
1173
- return { type: "string", value: token.value };
1174
- case "lbracket":
1175
- return parseList(cursor);
1176
- case "number": {
1177
- const firstValue = cursor.expectNumber("number");
1178
- if (!allowTuple || !cursor.at("comma")) {
1179
- return { type: "number", value: firstValue };
1180
- }
1181
- const values = [firstValue];
1182
- while (cursor.at("comma")) {
1183
- cursor.next();
1184
- values.push(cursor.expectNumber("number in tuple"));
1185
- }
1186
- return { type: "tuple", values };
1187
- }
1188
- case "ident":
1189
- return { type: "ident", segments: parsePathSegments(cursor) };
1190
- default:
1191
- throw new SflParseError(`expected a value, got '${token.value || token.type}'`, token.line, token.col);
1192
- }
1193
- }
1194
1203
 
1195
1204
  // src/sflLanguage/parsing/expressions.ts
1196
1205
  var COMPARISONS = /* @__PURE__ */ new Set([">", "<", ">=", "<=", "==", "!="]);
@@ -1334,6 +1343,113 @@ function expectEnd(cursor, what) {
1334
1343
  }
1335
1344
  }
1336
1345
 
1346
+ // src/sflLanguage/parsing/values.ts
1347
+ function parseEndpoint(cursor) {
1348
+ const segments = parsePathSegments(cursor);
1349
+ let side;
1350
+ let fraction;
1351
+ if (cursor.at("comma")) {
1352
+ cursor.next();
1353
+ const sideToken = cursor.expect("ident", 'side after ","');
1354
+ if (!isSide(sideToken.value)) {
1355
+ throw new SflParseError(
1356
+ `expected a side (top/right/bottom/left), got '${sideToken.value}'`,
1357
+ sideToken.line,
1358
+ sideToken.col
1359
+ );
1360
+ }
1361
+ side = sideToken.value;
1362
+ if (cursor.at("lparen")) {
1363
+ cursor.next();
1364
+ fraction = cursor.expectNumber('fraction inside "("');
1365
+ cursor.expect("rparen", "')'");
1366
+ }
1367
+ }
1368
+ return { type: "endpoint", segments, side, fraction };
1369
+ }
1370
+ function parseList(cursor) {
1371
+ cursor.expect("lbracket", "'['");
1372
+ const values = [];
1373
+ cursor.skipNewlines();
1374
+ if (!cursor.at("rbracket")) {
1375
+ values.push(parseValue(cursor, false));
1376
+ cursor.skipNewlines();
1377
+ while (cursor.at("comma")) {
1378
+ cursor.next();
1379
+ cursor.skipNewlines();
1380
+ if (cursor.at("rbracket")) {
1381
+ break;
1382
+ }
1383
+ values.push(parseValue(cursor, false));
1384
+ cursor.skipNewlines();
1385
+ }
1386
+ }
1387
+ cursor.expect("rbracket", "']'");
1388
+ return { type: "list", values };
1389
+ }
1390
+ var ARITHMETIC = /* @__PURE__ */ new Set(["+", "-", "*", "/", ">", "<", ">=", "<=", "==", "!=", "&&", "||"]);
1391
+ function startsComputed(cursor) {
1392
+ const first = cursor.peek();
1393
+ if (first.type === "op" && first.value === "-") {
1394
+ return true;
1395
+ }
1396
+ if (first.type !== "number" && first.type !== "ident" && first.type !== "lparen") {
1397
+ return false;
1398
+ }
1399
+ for (let offset = 0; ; offset++) {
1400
+ const token = cursor.peek(offset);
1401
+ if (token.type === "newline" || token.type === "semi" || token.type === "rbrace" || token.type === "eof") {
1402
+ return false;
1403
+ }
1404
+ if (token.type === "lparen" || token.type === "op" && ARITHMETIC.has(token.value)) {
1405
+ return true;
1406
+ }
1407
+ if (token.type === "ident" && cursor.peek(offset - 1).type === "comma") {
1408
+ return true;
1409
+ }
1410
+ if (offset === 0 && token.type === "ident" && cursor.peek(1).type === "comma") {
1411
+ return true;
1412
+ }
1413
+ }
1414
+ }
1415
+ function parseComputed(cursor) {
1416
+ const items = [parseExpression(cursor)];
1417
+ while (cursor.at("comma")) {
1418
+ cursor.next();
1419
+ items.push(parseExpression(cursor));
1420
+ }
1421
+ return { type: "expr", items };
1422
+ }
1423
+ function parseValue(cursor, allowTuple = true) {
1424
+ if (allowTuple && startsComputed(cursor)) {
1425
+ return parseComputed(cursor);
1426
+ }
1427
+ const token = cursor.peek();
1428
+ switch (token.type) {
1429
+ case "string":
1430
+ cursor.next();
1431
+ return { type: "string", value: token.value };
1432
+ case "lbracket":
1433
+ return parseList(cursor);
1434
+ case "number": {
1435
+ const firstValue = cursor.expectNumber("number");
1436
+ if (!allowTuple || !cursor.at("comma")) {
1437
+ return { type: "number", value: firstValue };
1438
+ }
1439
+ const values = [firstValue];
1440
+ while (cursor.at("comma")) {
1441
+ cursor.next();
1442
+ values.push(cursor.expectNumber("number in tuple"));
1443
+ }
1444
+ return { type: "tuple", values };
1445
+ }
1446
+ case "ident":
1447
+ return { type: "ident", segments: parsePathSegments(cursor) };
1448
+ default:
1449
+ throw new SflParseError(`expected a value, got '${token.value || token.type}'`, token.line, token.col);
1450
+ }
1451
+ }
1452
+
1337
1453
  // src/sflLanguage/parsing/properties.ts
1338
1454
  var PropertyParser = class {
1339
1455
  constructor(cursor) {
@@ -1608,7 +1724,7 @@ function emitComposition(composition) {
1608
1724
  return ` : ${composition.join(" & ")}`;
1609
1725
  }
1610
1726
 
1611
- // src/sflLanguage/emitting/values.ts
1727
+ // src/sflLanguage/emitting/literals.ts
1612
1728
  function formatNumber(value) {
1613
1729
  if (Object.is(value, -0)) {
1614
1730
  return "0";
@@ -1619,33 +1735,6 @@ function emitString(value) {
1619
1735
  const escaped = value.replace(/\r\n?/g, "\n").replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n").replace(/\t/g, "\\t");
1620
1736
  return `"${escaped}"`;
1621
1737
  }
1622
- function emitValue(value) {
1623
- switch (value.type) {
1624
- case "string":
1625
- return emitString(value.value);
1626
- case "number":
1627
- return formatNumber(value.value);
1628
- case "tuple":
1629
- return value.values.map(formatNumber).join(", ");
1630
- case "list":
1631
- return `[${value.values.map(emitValue).join(", ")}]`;
1632
- case "ident":
1633
- return value.segments.join(".");
1634
- case "expr":
1635
- return value.items.map((item) => emitExpression(item)).join(", ");
1636
- case "endpoint": {
1637
- let output = value.segments.join(".");
1638
- if (value.side) {
1639
- output += `, ${value.side}`;
1640
- if (value.fraction !== void 0) {
1641
- output += ` (${formatNumber(value.fraction)})`;
1642
- }
1643
- }
1644
- return output;
1645
- }
1646
- }
1647
- }
1648
- var emitProperty = (property) => `${property.key}: ${emitValue(property.value)}`;
1649
1738
 
1650
1739
  // src/sflLanguage/emitting/expressions.ts
1651
1740
  var PRECEDENCE = {
@@ -1667,7 +1756,7 @@ function emitExpression(expr, parentPrecedence = 0) {
1667
1756
  case "number":
1668
1757
  return String(expr.value);
1669
1758
  case "string":
1670
- return emitValue({ type: "string", value: expr.value });
1759
+ return emitString(expr.value);
1671
1760
  case "boolean":
1672
1761
  return String(expr.value);
1673
1762
  case "ref":
@@ -1736,6 +1825,35 @@ function compareByOrder(order, a, b) {
1736
1825
  var compareLayoutProps = (a, b) => compareByOrder(LAYOUT_ORDER, a, b);
1737
1826
  var compareStyleProps = (a, b) => compareByOrder(STYLE_ORDER, a, b);
1738
1827
 
1828
+ // src/sflLanguage/emitting/values.ts
1829
+ function emitValue(value) {
1830
+ switch (value.type) {
1831
+ case "string":
1832
+ return emitString(value.value);
1833
+ case "number":
1834
+ return formatNumber(value.value);
1835
+ case "tuple":
1836
+ return value.values.map(formatNumber).join(", ");
1837
+ case "list":
1838
+ return `[${value.values.map(emitValue).join(", ")}]`;
1839
+ case "ident":
1840
+ return value.segments.join(".");
1841
+ case "expr":
1842
+ return value.items.map((item) => emitExpression(item)).join(", ");
1843
+ case "endpoint": {
1844
+ let output = value.segments.join(".");
1845
+ if (value.side) {
1846
+ output += `, ${value.side}`;
1847
+ if (value.fraction !== void 0) {
1848
+ output += ` (${formatNumber(value.fraction)})`;
1849
+ }
1850
+ }
1851
+ return output;
1852
+ }
1853
+ }
1854
+ }
1855
+ var emitProperty = (property) => `${property.key}: ${emitValue(property.value)}`;
1856
+
1739
1857
  // src/sflLanguage/emitting/propertyBlock.ts
1740
1858
  var INDENT = " ";
1741
1859
  function emitPropertyBlock(name, properties, depth, bindings = []) {
@@ -1867,51 +1985,34 @@ function canonicalizeSource(sflText) {
1867
1985
  return emitDocument(parseSource(sflText));
1868
1986
  }
1869
1987
 
1870
- // src/sflSemantic/canvasObjects/artifacts/chart/types.ts
1988
+ // src/sflSemantic/canvasObjects/artifacts/chart/object.ts
1871
1989
  function isChartObject(canvasObject) {
1872
1990
  return canvasObject.objectType === "chart" && canvasObject.chart !== void 0;
1873
1991
  }
1874
1992
 
1875
- // src/sflSemantic/canvasObjects/artifacts/dimension/types.ts
1993
+ // src/sflSemantic/canvasObjects/artifacts/dimension/object.ts
1876
1994
  function isDimensionObject(canvasObject) {
1877
1995
  return canvasObject.objectType === "dimension" && canvasObject.dimension !== void 0;
1878
1996
  }
1879
1997
 
1880
- // src/sflSemantic/canvasObjects/artifacts/isometric/types.ts
1998
+ // src/sflSemantic/canvasObjects/artifacts/isometric/object.ts
1881
1999
  function isIsometricObject(canvasObject) {
1882
2000
  return canvasObject.objectType === "isometric" && canvasObject.isometric !== void 0;
1883
2001
  }
1884
2002
 
1885
- // src/sflSemantic/canvasObjects/artifacts/path/types.ts
2003
+ // src/sflSemantic/canvasObjects/artifacts/path/object.ts
1886
2004
  function isPathObject(canvasObject) {
1887
2005
  return canvasObject.objectType === "path" && canvasObject.path !== void 0;
1888
2006
  }
1889
2007
 
1890
- // src/sflSemantic/canvasObjects/artifacts/swimlane/types.ts
2008
+ // src/sflSemantic/canvasObjects/artifacts/swimlane/object.ts
1891
2009
  function isSwimlaneObject(canvasObject) {
1892
2010
  return canvasObject.objectType === "swimlane" && canvasObject.swimlane !== void 0;
1893
2011
  }
1894
2012
 
1895
- // src/sflLanguage/expansion/repeat.ts
1896
- var RESERVED = /* @__PURE__ */ new Set(["columns", "rows", "count", "step", "origin", "seed", "jitter", "chance", "order", "where"]);
1897
- var MAX_CELLS = 2e4;
1898
- var MAX_VALUES = 1e6;
1899
- var Random = class {
1900
- state;
1901
- constructor(seed) {
1902
- this.state = seed >>> 0;
1903
- }
1904
- // mulberry32: a small generator that gives the same numbers for the same seed, on every machine.
1905
- next() {
1906
- this.state = this.state + 1831565813 >>> 0;
1907
- let t = this.state;
1908
- t = Math.imul(t ^ t >>> 15, t | 1);
1909
- t ^= t + Math.imul(t ^ t >>> 7, t | 61);
1910
- return ((t ^ t >>> 14) >>> 0) / 4294967296;
1911
- }
1912
- };
2013
+ // src/sflLanguage/expansion/scope.ts
1913
2014
  function fail(scope, message) {
1914
- throw new Error(`Repeat ${scope.repeat}: ${message}`);
2015
+ throw new Error(`${scope.label}: ${message}`);
1915
2016
  }
1916
2017
  function numberOf(scope, value, what) {
1917
2018
  if (typeof value !== "number" || !Number.isFinite(value)) {
@@ -1919,6 +2020,8 @@ function numberOf(scope, value, what) {
1919
2020
  }
1920
2021
  return value;
1921
2022
  }
2023
+
2024
+ // src/sflLanguage/expansion/functions.ts
1922
2025
  function rgbOf(scope, value) {
1923
2026
  const match = typeof value === "string" ? /^#([0-9a-f]{6})$/i.exec(value) : null;
1924
2027
  if (!match) {
@@ -1987,6 +2090,8 @@ function callFunction(scope, name, args) {
1987
2090
  return fail(scope, `unknown function ${name}()`);
1988
2091
  }
1989
2092
  }
2093
+
2094
+ // src/sflLanguage/expansion/evaluation.ts
1990
2095
  function evaluate(scope, expr) {
1991
2096
  switch (expr.kind) {
1992
2097
  case "number":
@@ -2044,27 +2149,37 @@ function evaluate(scope, expr) {
2044
2149
  }
2045
2150
  }
2046
2151
  var round2 = (value) => Math.round(value * 1e3) / 1e3;
2152
+ function scalarValue(scope, only) {
2153
+ if (typeof only === "number") {
2154
+ return { type: "number", value: round2(numberOf(scope, only, "a value")) };
2155
+ }
2156
+ if (typeof only === "string") {
2157
+ return { type: "string", value: only };
2158
+ }
2159
+ return { type: "ident", segments: [String(only)] };
2160
+ }
2047
2161
  function resolveValue(scope, value) {
2162
+ if (scope.substitute && value.type === "ident" && value.segments.length === 1) {
2163
+ const known = scope.vars.get(value.segments[0]);
2164
+ if (known !== void 0) {
2165
+ return scalarValue(scope, known);
2166
+ }
2167
+ }
2048
2168
  if (value.type !== "expr") {
2049
2169
  return value;
2050
2170
  }
2051
2171
  const results = value.items.map((item) => evaluate(scope, item));
2052
2172
  if (results.length === 1) {
2053
- const [only] = results;
2054
- if (typeof only === "number") {
2055
- return { type: "number", value: round2(numberOf(scope, only, "a value")) };
2056
- }
2057
- if (typeof only === "string") {
2058
- return { type: "string", value: only };
2059
- }
2060
- return { type: "ident", segments: [String(only)] };
2173
+ return scalarValue(scope, results[0]);
2061
2174
  }
2062
2175
  return { type: "tuple", values: results.map((result) => round2(numberOf(scope, result, "a tuple"))) };
2063
2176
  }
2177
+
2178
+ // src/sflLanguage/expansion/instance.ts
2064
2179
  function propertiesOf(scope, properties) {
2065
2180
  return properties.map((property) => ({ key: property.key, value: resolveValue(scope, property.value) }));
2066
2181
  }
2067
- function entryOf(scope, entry, suffix) {
2182
+ function entryOf(scope, entry, rename) {
2068
2183
  switch (entry.type) {
2069
2184
  case "property":
2070
2185
  return {
@@ -2076,18 +2191,20 @@ function entryOf(scope, entry, suffix) {
2076
2191
  case "style":
2077
2192
  return { type: "style", style: { ...entry.style, properties: propertiesOf(scope, entry.style.properties) } };
2078
2193
  case "block":
2079
- return { type: "block", block: instance(scope, entry.block, suffix) };
2194
+ return { type: "block", block: instance(scope, entry.block, rename) };
2080
2195
  default:
2081
2196
  return entry;
2082
2197
  }
2083
2198
  }
2084
- function instance(scope, block2, suffix) {
2199
+ function instance(scope, block2, rename) {
2085
2200
  return {
2086
2201
  ...block2,
2087
- name: `${block2.name}${suffix}`,
2088
- entries: block2.entries.map((entry) => entryOf(scope, entry, suffix))
2202
+ name: rename(block2.name),
2203
+ entries: block2.entries.map((entry) => entryOf(scope, entry, rename))
2089
2204
  };
2090
2205
  }
2206
+
2207
+ // src/sflLanguage/expansion/properties.ts
2091
2208
  function propertyOf(block2, key) {
2092
2209
  for (const entry of block2.entries) {
2093
2210
  if (entry.type === "property" && entry.property.key === key) {
@@ -2110,88 +2227,244 @@ function numbersOf(block2, key) {
2110
2227
  }
2111
2228
  return void 0;
2112
2229
  }
2113
- function expandRepeat(block2) {
2114
- const scope = { vars: /* @__PURE__ */ new Map(), random: new Random(0), repeat: block2.name };
2230
+
2231
+ // src/sflLanguage/expansion/random.ts
2232
+ var Random = class {
2233
+ state;
2234
+ constructor(seed) {
2235
+ this.state = seed >>> 0;
2236
+ }
2237
+ // mulberry32: a small generator that gives the same numbers for the same seed, on every machine.
2238
+ next() {
2239
+ this.state = this.state + 1831565813 >>> 0;
2240
+ let t = this.state;
2241
+ t = Math.imul(t ^ t >>> 15, t | 1);
2242
+ t ^= t + Math.imul(t ^ t >>> 7, t | 61);
2243
+ return ((t ^ t >>> 14) >>> 0) / 4294967296;
2244
+ }
2245
+ };
2246
+
2247
+ // src/sflLanguage/expansion/repeat.ts
2248
+ var RESERVED = /* @__PURE__ */ new Set(["columns", "rows", "count", "step", "origin", "seed", "jitter", "chance", "order", "where"]);
2249
+ var MAX_CELLS = 2e4;
2250
+ var MAX_VALUES = 1e6;
2251
+ function readGrid(block2, scope) {
2115
2252
  const count = numbersOf(block2, "count")?.[0];
2116
2253
  const columns = Math.max(1, Math.floor(count ?? numbersOf(block2, "columns")?.[0] ?? 1));
2117
2254
  const rows = count === void 0 ? Math.max(1, Math.floor(numbersOf(block2, "rows")?.[0] ?? 1)) : 1;
2118
- const total = columns * rows;
2119
- if (total > MAX_CELLS) {
2120
- fail(scope, `${total} cells are too many, the limit is ${MAX_CELLS}`);
2255
+ if (columns * rows > MAX_CELLS) {
2256
+ fail(scope, `${columns * rows} cells are too many, the limit is ${MAX_CELLS}`);
2121
2257
  }
2122
2258
  const [stepX = 0, stepY = stepX] = numbersOf(block2, "step") ?? [];
2123
2259
  const [originX = 0, originY = 0] = numbersOf(block2, "origin") ?? [];
2124
- const seed = numbersOf(block2, "seed")?.[0] ?? 0;
2125
- const jitter = numbersOf(block2, "jitter")?.[0] ?? 0;
2126
- const chance = numbersOf(block2, "chance")?.[0] ?? 1;
2127
- const diagonal = propertyOf(block2, "order")?.type === "ident" && propertyOf(block2, "order").segments[0] === "diagonal";
2128
- const condition = propertyOf(block2, "where");
2129
- const helpers = block2.entries.flatMap(
2130
- (entry) => entry.type === "property" && entry.property.value.type === "expr" && !RESERVED.has(entry.property.key) ? [entry.property] : []
2131
- );
2260
+ const order = propertyOf(block2, "order");
2132
2261
  const templates = block2.entries.flatMap((entry) => entry.type === "block" ? [entry.block] : []);
2133
2262
  if (templates.some((template) => template.kind === "Repeat")) {
2134
2263
  fail(scope, "a Repeat cannot hold another Repeat");
2135
2264
  }
2136
- if (total * Math.max(1, templates.length) > MAX_VALUES) {
2265
+ if (columns * rows * Math.max(1, templates.length) > MAX_VALUES) {
2137
2266
  fail(scope, "too many blocks");
2138
2267
  }
2268
+ return {
2269
+ columns,
2270
+ rows,
2271
+ step: [stepX, stepY],
2272
+ origin: [originX, originY],
2273
+ seed: numbersOf(block2, "seed")?.[0] ?? 0,
2274
+ jitter: numbersOf(block2, "jitter")?.[0] ?? 0,
2275
+ chance: numbersOf(block2, "chance")?.[0] ?? 1,
2276
+ diagonal: order?.type === "ident" && order.segments[0] === "diagonal",
2277
+ condition: propertyOf(block2, "where"),
2278
+ helpers: block2.entries.flatMap(
2279
+ (entry) => entry.type === "property" && entry.property.value.type === "expr" && !RESERVED.has(entry.property.key) ? [entry.property] : []
2280
+ ),
2281
+ templates
2282
+ };
2283
+ }
2284
+ function cellsOf(grid) {
2139
2285
  const cells = [];
2140
- for (let row = 0; row < rows; row++) {
2141
- for (let col = 0; col < columns; col++) {
2286
+ for (let row = 0; row < grid.rows; row++) {
2287
+ for (let col = 0; col < grid.columns; col++) {
2142
2288
  cells.push([col, row]);
2143
2289
  }
2144
2290
  }
2145
- if (diagonal) {
2146
- cells.sort((a, b) => a[0] + a[1] - (b[0] + b[1]) || a[0] - b[0]);
2291
+ return grid.diagonal ? cells.sort((a, b) => a[0] + a[1] - (b[0] + b[1]) || a[0] - b[0]) : cells;
2292
+ }
2293
+ function enterCell(scope, grid, col, row) {
2294
+ const index = row * grid.columns + col;
2295
+ scope.random = new Random(Math.imul(grid.seed + 1, 2654435761) ^ Math.imul(index + 1, 2246822507));
2296
+ if (grid.chance < 1 && scope.random.next() >= grid.chance) {
2297
+ return false;
2147
2298
  }
2148
- const out = [];
2149
- for (const [col, row] of cells) {
2150
- {
2151
- const index = row * columns + col;
2152
- scope.random = new Random(Math.imul(seed + 1, 2654435761) ^ Math.imul(index + 1, 2246822507));
2153
- if (chance < 1 && scope.random.next() >= chance) {
2154
- continue;
2155
- }
2156
- const spread = () => jitter > 0 ? (scope.random.next() * 2 - 1) * jitter : 0;
2157
- scope.vars = /* @__PURE__ */ new Map([
2158
- ["col", col],
2159
- ["row", row],
2160
- ["index", index],
2161
- ["count", total],
2162
- ["columns", columns],
2163
- ["rows", rows],
2164
- ["x", round2(originX + col * stepX + spread())],
2165
- ["y", round2(originY + row * stepY + spread())]
2166
- ]);
2167
- for (const helper of helpers) {
2168
- const value = resolveValue(scope, helper.value);
2169
- if (value.type === "number" || value.type === "string") {
2170
- scope.vars.set(helper.key, value.value);
2171
- } else if (value.type === "ident") {
2172
- scope.vars.set(helper.key, value.segments[0] === "true" ? 1 : 0);
2173
- } else {
2174
- fail(scope, `${helper.key} needs a number`);
2175
- }
2299
+ const spread = () => grid.jitter > 0 ? (scope.random.next() * 2 - 1) * grid.jitter : 0;
2300
+ scope.vars = /* @__PURE__ */ new Map([
2301
+ ["col", col],
2302
+ ["row", row],
2303
+ ["index", index],
2304
+ ["count", grid.columns * grid.rows],
2305
+ ["columns", grid.columns],
2306
+ ["rows", grid.rows],
2307
+ ["x", round2(grid.origin[0] + col * grid.step[0] + spread())],
2308
+ ["y", round2(grid.origin[1] + row * grid.step[1] + spread())]
2309
+ ]);
2310
+ return true;
2311
+ }
2312
+ function nameHelpers(scope, helpers) {
2313
+ for (const helper of helpers) {
2314
+ const value = resolveValue(scope, helper.value);
2315
+ if (value.type === "number" || value.type === "string") {
2316
+ scope.vars.set(helper.key, value.value);
2317
+ } else if (value.type === "ident") {
2318
+ scope.vars.set(helper.key, value.segments[0] === "true" ? 1 : 0);
2319
+ } else {
2320
+ fail(scope, `${helper.key} needs a number`);
2321
+ }
2322
+ }
2323
+ }
2324
+ function keepsCell(scope, condition) {
2325
+ return condition?.type !== "expr" || Boolean(condition.items.map((item) => evaluate(scope, item))[0]);
2326
+ }
2327
+ function expandRepeat(block2) {
2328
+ const scope = { vars: /* @__PURE__ */ new Map(), random: new Random(0), label: `Repeat ${block2.name}` };
2329
+ const grid = readGrid(block2, scope);
2330
+ const made = [];
2331
+ for (const [col, row] of cellsOf(grid)) {
2332
+ if (!enterCell(scope, grid, col, row)) {
2333
+ continue;
2334
+ }
2335
+ nameHelpers(scope, grid.helpers);
2336
+ if (!keepsCell(scope, grid.condition)) {
2337
+ continue;
2338
+ }
2339
+ const suffix = grid.rows === 1 ? `_${col}` : `_${col}_${row}`;
2340
+ for (const template of grid.templates) {
2341
+ made.push(instance(scope, template, (name) => `${name}${suffix}`));
2342
+ }
2343
+ }
2344
+ return made;
2345
+ }
2346
+ function expandRepeatBlocks(blocks) {
2347
+ return blocks.flatMap((block2) => {
2348
+ if (block2.kind === "Repeat") {
2349
+ return expandRepeat(block2);
2350
+ }
2351
+ if (block2.kind === "Template" || !block2.entries.some((entry) => entry.type === "block")) {
2352
+ return [block2];
2353
+ }
2354
+ return [
2355
+ {
2356
+ ...block2,
2357
+ entries: block2.entries.flatMap(
2358
+ (entry) => entry.type === "block" ? expandRepeatBlocks([entry.block]).map((child) => ({ type: "block", block: child })) : [entry]
2359
+ )
2176
2360
  }
2177
- if (condition && condition.type === "expr") {
2178
- const result = condition.items.map((item) => evaluate(scope, item))[0];
2179
- if (!result) {
2180
- continue;
2181
- }
2361
+ ];
2362
+ });
2363
+ }
2364
+ function hasRepeats(blocks) {
2365
+ return blocks.some(
2366
+ (block2) => block2.kind === "Repeat" || block2.entries.some((entry) => entry.type === "block" && hasRepeats([entry.block]))
2367
+ );
2368
+ }
2369
+
2370
+ // src/sflLanguage/expansion/template.ts
2371
+ var MAX_DEPTH = 4;
2372
+ var MAX_BLOCKS = 1e5;
2373
+ var OWN = /* @__PURE__ */ new Set(["at", "seed"]);
2374
+ var PLACE = /* @__PURE__ */ new Set(["x", "y"]);
2375
+ function hashOf(text) {
2376
+ let hash = 2166136261;
2377
+ for (let index = 0; index < text.length; index++) {
2378
+ hash = Math.imul(hash ^ text.charCodeAt(index), 16777619);
2379
+ }
2380
+ return hash >>> 0;
2381
+ }
2382
+ function collect(blocks, into) {
2383
+ for (const block2 of blocks) {
2384
+ if (block2.kind === "Template") {
2385
+ if (into.has(block2.name)) {
2386
+ throw new Error(`Template ${block2.name}: there is another Template of this name`);
2182
2387
  }
2183
- const suffix = rows === 1 ? `_${col}` : `_${col}_${row}`;
2184
- for (const template of templates) {
2185
- out.push(instance(scope, template, suffix));
2388
+ if (block2.entries.some((entry) => entry.type === "block" && entry.block.kind === "Repeat")) {
2389
+ throw new Error(`Template ${block2.name}: a Template cannot hold a Repeat, a Repeat can hold a Use`);
2186
2390
  }
2391
+ into.set(block2.name, block2);
2187
2392
  }
2393
+ collect(
2394
+ block2.entries.flatMap((entry) => entry.type === "block" ? [entry.block] : []),
2395
+ into
2396
+ );
2188
2397
  }
2189
- return out;
2190
2398
  }
2191
- function expandBlocks(blocks) {
2399
+ var BlockBudget = class {
2400
+ made = 0;
2401
+ take(count, scope) {
2402
+ this.made += count;
2403
+ if (this.made > MAX_BLOCKS) {
2404
+ fail(scope, "too many blocks");
2405
+ }
2406
+ }
2407
+ };
2408
+ function expandUse(use, templates, depth, budget) {
2409
+ const scope = { vars: /* @__PURE__ */ new Map(), random: new Random(0), label: `Use ${use.name}`, substitute: true };
2410
+ if (depth > MAX_DEPTH) {
2411
+ fail(scope, `Templates are nested more than ${MAX_DEPTH} deep, which may be a Template that uses itself`);
2412
+ }
2413
+ if (use.composition.length !== 1) {
2414
+ fail(scope, "a Use names one Template, as in Use oak : tree");
2415
+ }
2416
+ const template = templates.get(use.composition[0]);
2417
+ if (!template) {
2418
+ fail(scope, `there is no Template ${use.composition[0]}`);
2419
+ }
2420
+ const seed = numbersOf(use, "seed")?.[0] ?? 0;
2421
+ scope.random = new Random(Math.imul(seed + 1, 2654435761) ^ hashOf(use.name));
2422
+ const [x = 0, y = 0] = numbersOf(use, "at") ?? [];
2423
+ scope.vars.set("x", x);
2424
+ scope.vars.set("y", y);
2425
+ const given = new Map(
2426
+ use.entries.flatMap(
2427
+ (entry) => entry.type === "property" && !OWN.has(entry.property.key) ? [[entry.property.key, entry.property.value]] : []
2428
+ )
2429
+ );
2430
+ for (const entry of template.entries) {
2431
+ if (entry.type !== "property") {
2432
+ continue;
2433
+ }
2434
+ const { key, value } = entry.property;
2435
+ if (PLACE.has(key) || OWN.has(key)) {
2436
+ fail(scope, `${key} is the name of something a Use sets, so it cannot be a parameter`);
2437
+ }
2438
+ const chosen = resolveValue(scope, given.get(key) ?? value);
2439
+ given.delete(key);
2440
+ if (chosen.type === "number" || chosen.type === "string") {
2441
+ scope.vars.set(key, chosen.value);
2442
+ } else if (chosen.type === "ident") {
2443
+ scope.vars.set(
2444
+ key,
2445
+ chosen.segments[0] === "true" ? 1 : chosen.segments[0] === "false" ? 0 : chosen.segments.join(".")
2446
+ );
2447
+ } else {
2448
+ fail(scope, `${key} needs a number, a text or a name`);
2449
+ }
2450
+ }
2451
+ const unknown = [...given.keys()][0];
2452
+ if (unknown !== void 0) {
2453
+ fail(scope, `Template ${template.name} has no parameter ${unknown}`);
2454
+ }
2455
+ const made = template.entries.flatMap(
2456
+ (entry) => entry.type === "block" ? [instance(scope, entry.block, (name) => `${use.name}_${name}`)] : []
2457
+ );
2458
+ budget.take(made.length, scope);
2459
+ return expandIn(made, templates, depth + 1, budget);
2460
+ }
2461
+ function expandIn(blocks, templates, depth, budget) {
2192
2462
  return blocks.flatMap((block2) => {
2193
- if (block2.kind === "Repeat") {
2194
- return expandRepeat(block2);
2463
+ if (block2.kind === "Template") {
2464
+ return [];
2465
+ }
2466
+ if (block2.kind === "Use") {
2467
+ return expandUse(block2, templates, depth, budget);
2195
2468
  }
2196
2469
  if (!block2.entries.some((entry) => entry.type === "block")) {
2197
2470
  return [block2];
@@ -2200,15 +2473,24 @@ function expandBlocks(blocks) {
2200
2473
  {
2201
2474
  ...block2,
2202
2475
  entries: block2.entries.flatMap(
2203
- (entry) => entry.type === "block" ? (entry.block.kind === "Repeat" ? expandRepeat(entry.block) : expandBlocks([entry.block])).map((child) => ({
2204
- type: "block",
2205
- block: child
2206
- })) : [entry]
2476
+ (entry) => entry.type === "block" ? expandIn([entry.block], templates, depth, budget).map((child) => ({ type: "block", block: child })) : [entry]
2207
2477
  )
2208
2478
  }
2209
2479
  ];
2210
2480
  });
2211
2481
  }
2482
+ function hasTemplates(blocks) {
2483
+ return blocks.some(
2484
+ (block2) => block2.kind === "Template" || block2.kind === "Use" || block2.entries.some((entry) => entry.type === "block" && hasTemplates([entry.block]))
2485
+ );
2486
+ }
2487
+ function expandUses(blocks) {
2488
+ const templates = /* @__PURE__ */ new Map();
2489
+ collect(blocks, templates);
2490
+ return expandIn(blocks, templates, 0, new BlockBudget());
2491
+ }
2492
+
2493
+ // src/sflLanguage/expansion/expandDocument.ts
2212
2494
  function checkNoComputed(blocks) {
2213
2495
  for (const block2 of blocks) {
2214
2496
  for (const entry of block2.entries) {
@@ -2226,15 +2508,13 @@ function checkNoComputed(blocks) {
2226
2508
  }
2227
2509
  }
2228
2510
  }
2229
- function expandRepeats(doc) {
2230
- const has = (blocks) => blocks.some(
2231
- (block2) => block2.kind === "Repeat" || block2.entries.some((entry) => entry.type === "block" ? has([entry.block]) : false)
2232
- );
2233
- if (!has(doc.blocks)) {
2511
+ function expandDocument(doc) {
2512
+ const repeats = hasRepeats(doc.blocks);
2513
+ if (!repeats && !hasTemplates(doc.blocks)) {
2234
2514
  checkNoComputed(doc.blocks);
2235
2515
  return doc;
2236
2516
  }
2237
- const expanded = { ...doc, blocks: expandBlocks(doc.blocks) };
2517
+ const expanded = { ...doc, blocks: expandUses(repeats ? expandRepeatBlocks(doc.blocks) : doc.blocks) };
2238
2518
  checkNoComputed(expanded.blocks);
2239
2519
  return expanded;
2240
2520
  }
@@ -3588,7 +3868,7 @@ function resolveCanvasState(document) {
3588
3868
 
3589
3869
  // src/sflSemantic/sflToCanvasState.ts
3590
3870
  function sflToCanvasState(source) {
3591
- return resolveCanvasState(expandRepeats(parseSource(source)));
3871
+ return resolveCanvasState(expandDocument(parseSource(source)));
3592
3872
  }
3593
3873
 
3594
3874
  // src/svg/domContract/version.ts
@@ -4733,63 +5013,6 @@ function createPieSlicePath(geometry, angles, cornerRadius = 0, gapPx = 0) {
4733
5013
  return cornerRadius > 0 ? roundedDonutSlicePath(geometry, geometry.innerRadius, outerAngles, innerAngles, cornerRadius) : donutSlicePath(geometry, geometry.innerRadius, outerAngles, innerAngles);
4734
5014
  }
4735
5015
 
4736
- // src/model/color/conversion.ts
4737
- var hexToRgb2 = (hex) => {
4738
- const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?$/i.exec(hex);
4739
- if (!result) {
4740
- return { r: 255, g: 255, b: 255, a: 1 };
4741
- }
4742
- return {
4743
- r: parseInt(result[1], 16),
4744
- g: parseInt(result[2], 16),
4745
- b: parseInt(result[3], 16),
4746
- a: result[4] === void 0 ? 1 : parseInt(result[4], 16) / 255
4747
- };
4748
- };
4749
- var rgbToHex2 = (r, g, b, a) => {
4750
- const channel = (x) => {
4751
- const hex = Math.max(0, Math.min(255, Math.round(x))).toString(16);
4752
- return hex.length === 1 ? `0${hex}` : hex;
4753
- };
4754
- const alphaChannel = a === void 0 || a >= 1 ? "" : channel(a * 255);
4755
- return `#${channel(r)}${channel(g)}${channel(b)}${alphaChannel}`;
4756
- };
4757
-
4758
- // src/model/color/interpolation.ts
4759
- function mixHexColors(start, end, ratio) {
4760
- const startRgb = hexToRgb2(start);
4761
- const endRgb = hexToRgb2(end);
4762
- const startAlpha = startRgb.a ?? 1;
4763
- const endAlpha = endRgb.a ?? 1;
4764
- return rgbToHex2(
4765
- Math.round(startRgb.r + (endRgb.r - startRgb.r) * ratio),
4766
- Math.round(startRgb.g + (endRgb.g - startRgb.g) * ratio),
4767
- Math.round(startRgb.b + (endRgb.b - startRgb.b) * ratio),
4768
- startAlpha + (endAlpha - startAlpha) * ratio
4769
- );
4770
- }
4771
- function interpolateHexColorStops(stops, position) {
4772
- const sortedStops = [...stops].sort((first2, second) => first2.position - second.position);
4773
- const first = sortedStops[0];
4774
- const last = sortedStops[sortedStops.length - 1];
4775
- if (position <= first.position) {
4776
- return first.color;
4777
- }
4778
- if (position >= last.position) {
4779
- return last.color;
4780
- }
4781
- for (let index = 0; index < sortedStops.length - 1; index++) {
4782
- const start = sortedStops[index];
4783
- const end = sortedStops[index + 1];
4784
- if (position >= start.position && position <= end.position) {
4785
- const range = end.position - start.position;
4786
- const ratio = range === 0 ? 0 : (position - start.position) / range;
4787
- return mixHexColors(start.color, end.color, ratio);
4788
- }
4789
- }
4790
- return last.color;
4791
- }
4792
-
4793
5016
  // src/renderScene/charts/primitives/defaults.ts
4794
5017
  var CHART_COLORS = ["#7c3aed", "#0ea5e9", "#f97316", "#10b981", "#ec4899", "#eab308"];
4795
5018
  var DEFAULT_ZONE_FILL = "#94a3b8";
@@ -4868,16 +5091,11 @@ function computeBoxplotStats(values) {
4868
5091
  }
4869
5092
 
4870
5093
  // src/renderScene/color.ts
4871
- function hexToRgb3(hex) {
4872
- if (hex?.[0] !== "#") {
4873
- return void 0;
4874
- }
4875
- const channels = hex.length === 4 ? hex.slice(1).split("").map((channel) => parseInt(channel + channel, 16)) : [1, 3, 5].map((index) => parseInt(hex.slice(index, index + 2), 16));
4876
- const [red, green, blue] = channels;
4877
- return [red, green, blue].some((channel) => Number.isNaN(channel)) ? void 0 : [red, green, blue];
5094
+ function hexToRgb2(hex) {
5095
+ return hex?.startsWith("#") ? parseHexRgb(hex) ?? void 0 : void 0;
4878
5096
  }
4879
5097
  function colorWithAlpha(hex, alpha) {
4880
- const rgb = hexToRgb3(hex);
5098
+ const rgb = hexToRgb2(hex);
4881
5099
  const clamped = Math.max(0, Math.min(1, alpha));
4882
5100
  if (!rgb) {
4883
5101
  return clamped <= 0 ? "transparent" : hex ?? "transparent";
@@ -4885,10 +5103,6 @@ function colorWithAlpha(hex, alpha) {
4885
5103
  const [red, green, blue] = rgb;
4886
5104
  return `rgba(${red}, ${green}, ${blue}, ${clamped})`;
4887
5105
  }
4888
- function rgbToHex3(red, green, blue) {
4889
- const channel = (value) => Math.round(Math.max(0, Math.min(255, value))).toString(16).padStart(2, "0");
4890
- return `#${channel(red)}${channel(green)}${channel(blue)}`;
4891
- }
4892
5106
  function rgbToHsl(red, green, blue) {
4893
5107
  const r = red / 255;
4894
5108
  const g = green / 255;
@@ -4954,7 +5168,7 @@ var SAME_HUE_LIGHT_MIN_LIGHTNESS = 0.78;
4954
5168
  var SAME_HUE_LIGHT_MAX_LIGHTNESS = 0.92;
4955
5169
  var SAME_HUE_MIN_CONTRAST = 3;
4956
5170
  function contrastTextColor(hex) {
4957
- const rgb = hexToRgb3(hex);
5171
+ const rgb = hexToRgb2(hex);
4958
5172
  if (!rgb) {
4959
5173
  return "#0f172a";
4960
5174
  }
@@ -4970,10 +5184,10 @@ function contrastTextColor(hex) {
4970
5184
  );
4971
5185
  const variant = hslToRgb(hue, saturation, targetLightness);
4972
5186
  const ratio = contrastRatio(relativeLuminance(red, green, blue), relativeLuminance(...variant));
4973
- return ratio >= SAME_HUE_MIN_CONTRAST ? rgbToHex3(...variant) : fallback;
5187
+ return ratio >= SAME_HUE_MIN_CONTRAST ? rgbToHex(...variant) : fallback;
4974
5188
  }
4975
5189
  function sameHueContrastColor(hex, fallback) {
4976
- const rgb = hexToRgb3(hex);
5190
+ const rgb = hexToRgb2(hex);
4977
5191
  if (!rgb) {
4978
5192
  return fallback;
4979
5193
  }
@@ -4986,14 +5200,14 @@ function sameHueContrastColor(hex, fallback) {
4986
5200
  SAME_HUE_LIGHT_MAX_LIGHTNESS,
4987
5201
  Math.max(lightness + SAME_HUE_LIGHTNESS_GAP, SAME_HUE_LIGHT_MIN_LIGHTNESS)
4988
5202
  );
4989
- return rgbToHex3(...hslToRgb(hue, saturation, targetLightness));
5203
+ return rgbToHex(...hslToRgb(hue, saturation, targetLightness));
4990
5204
  }
4991
5205
  function isLightColor(hex) {
4992
- const rgb = hexToRgb3(hex);
5206
+ const rgb = hexToRgb2(hex);
4993
5207
  return rgb ? rgbToHsl(...rgb)[2] > 0.5 : false;
4994
5208
  }
4995
5209
  function sameHueTint(hex, targetLightness) {
4996
- const rgb = hexToRgb3(hex);
5210
+ const rgb = hexToRgb2(hex);
4997
5211
  if (!rgb) {
4998
5212
  return void 0;
4999
5213
  }
@@ -5001,7 +5215,7 @@ function sameHueTint(hex, targetLightness) {
5001
5215
  if (saturation === 0) {
5002
5216
  return void 0;
5003
5217
  }
5004
- return rgbToHex3(...hslToRgb(hue, saturation, targetLightness));
5218
+ return rgbToHex(...hslToRgb(hue, saturation, targetLightness));
5005
5219
  }
5006
5220
 
5007
5221
  // src/renderScene/charts/primitives/colors.ts
@@ -5845,7 +6059,7 @@ exports.elementCenter = elementCenter;
5845
6059
  exports.ellipsizeToWidth = ellipsizeToWidth;
5846
6060
  exports.errorBarRange = errorBarRange;
5847
6061
  exports.estimateTextWidth = estimateTextWidth;
5848
- exports.expandRepeats = expandRepeats;
6062
+ exports.expandDocument = expandDocument;
5849
6063
  exports.extrudeFootprint = extrudeFootprint;
5850
6064
  exports.finite = finite;
5851
6065
  exports.flattenPath = flattenPath;
@@ -5858,6 +6072,7 @@ exports.getComponentDescriptor = getComponentDescriptor;
5858
6072
  exports.getLineMidpoint = getLineMidpoint;
5859
6073
  exports.heuristicRichMeasure = heuristicRichMeasure;
5860
6074
  exports.horizontalRows = horizontalRows;
6075
+ exports.hsvToRgb = hsvToRgb;
5861
6076
  exports.interpolateHexColorStops = interpolateHexColorStops;
5862
6077
  exports.isBuiltInComponentType = isBuiltInComponentType;
5863
6078
  exports.isChartObject = isChartObject;
@@ -5883,6 +6098,7 @@ exports.mapChartValue = mapChartValue;
5883
6098
  exports.maxApexCornerRadius = maxApexCornerRadius;
5884
6099
  exports.maxPieCornerRadius = maxPieCornerRadius;
5885
6100
  exports.paint = paint;
6101
+ exports.parseHexRgb = parseHexRgb;
5886
6102
  exports.parseSource = parseSource;
5887
6103
  exports.pathBounds = pathBounds;
5888
6104
  exports.pathToSymbol = pathToSymbol;
@@ -5908,6 +6124,8 @@ exports.representativeColor = representativeColor;
5908
6124
  exports.resolveChartShadow = resolveChartShadow;
5909
6125
  exports.resolvePieRadii = resolvePieRadii;
5910
6126
  exports.resolveRollingNumberStyle = resolveRollingNumberStyle;
6127
+ exports.rgbToHex = rgbToHex;
6128
+ exports.rgbToHsv = rgbToHsv;
5911
6129
  exports.rightRoundedRectPath = rightRoundedRectPath;
5912
6130
  exports.rotatedBounds = rotatedBounds;
5913
6131
  exports.roundedBarPath = roundedBarPath;
@@ -5937,5 +6155,5 @@ exports.tokenizeSource = tokenizeSource;
5937
6155
  exports.topRoundedRectPath = topRoundedRectPath;
5938
6156
  exports.wrapText = wrapText;
5939
6157
  exports.zoneColorAtValue = zoneColorAtValue;
5940
- //# sourceMappingURL=chunk-C25NWWIH.cjs.map
5941
- //# sourceMappingURL=chunk-C25NWWIH.cjs.map
6158
+ //# sourceMappingURL=chunk-LSEMXRB5.cjs.map
6159
+ //# sourceMappingURL=chunk-LSEMXRB5.cjs.map