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