@cardenelabs/dragon 0.46.0 → 0.46.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/export.js CHANGED
@@ -833,8 +833,8 @@ function longest(points) {
833
833
  }
834
834
  return { a: best.a, b: best.b, vertical: Math.abs(best.b[0] - best.a[0]) < Math.abs(best.b[1] - best.a[1]) };
835
835
  }
836
- function along(points, distance) {
837
- let left = distance;
836
+ function along(points, distance2) {
837
+ let left = distance2;
838
838
  for (let i = 1; i < points.length; i++) {
839
839
  const a = points[i - 1];
840
840
  const b = points[i];
@@ -1667,6 +1667,7 @@ var ja = {
1667
1667
  additionalProperties: (key) => `${key} \u3068\u3044\u3046\u6B04\u306F\u66F8\u3051\u306A\u3044`,
1668
1668
  required: (key) => `${key} \u306E\u6B04\u304C\u8981\u308B`,
1669
1669
  enum: (values) => `${values.join(" / ")} \u306E\u3069\u308C\u304B\u306B\u3059\u308B`,
1670
+ unknownIcon: (value, near) => `${value} \u3068\u3044\u3046 icon \u306F\u7121\u3044\u3002\u8FD1\u3044\u540D\u524D\u306F ${near}`,
1670
1671
  type: (type) => TYPES_JA[type] ?? `${type} \u306B\u3059\u308B`,
1671
1672
  minLength: (limit) => `${limit} \u5B57\u4EE5\u4E0A\u66F8\u304F`,
1672
1673
  maxLength: (limit) => `${limit} \u5B57\u307E\u3067\u306B\u3059\u308B`,
@@ -1691,6 +1692,7 @@ var en = {
1691
1692
  additionalProperties: (key) => `The ${key} field is not allowed`,
1692
1693
  required: (key) => `The ${key} field is required`,
1693
1694
  enum: (values) => `Use one of ${values.join(" / ")}`,
1695
+ unknownIcon: (value, near) => `There is no icon named ${value}. The closest is ${near}`,
1694
1696
  type: (type) => TYPES_EN[type] ?? `Use ${type}`,
1695
1697
  minLength: (limit) => `Write at least ${plural(limit, "character")}`,
1696
1698
  maxLength: (limit) => `Write at most ${plural(limit, "character")}`,
@@ -1713,6 +1715,33 @@ var en = {
1713
1715
  };
1714
1716
  var FIELD_MESSAGES = { ja, en };
1715
1717
 
1718
+ // src/nearest.ts
1719
+ var MAX_DISTANCE = 2;
1720
+ function nearest(word, candidates) {
1721
+ const written = [...word.toLowerCase()];
1722
+ let limit = Math.min(MAX_DISTANCE, written.length - 1);
1723
+ let best;
1724
+ for (const candidate of candidates) {
1725
+ const d = distance(written, [...candidate.toLowerCase()]);
1726
+ if (d > limit) continue;
1727
+ best = candidate;
1728
+ limit = d - 1;
1729
+ }
1730
+ return best;
1731
+ }
1732
+ function distance(a, b) {
1733
+ let previous = Array.from({ length: b.length + 1 }, (_, j) => j);
1734
+ for (let i = 1; i <= a.length; i++) {
1735
+ const current = [i];
1736
+ for (let j = 1; j <= b.length; j++) {
1737
+ const replace = previous[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1);
1738
+ current.push(Math.min(previous[j] + 1, current[j - 1] + 1, replace));
1739
+ }
1740
+ previous = current;
1741
+ }
1742
+ return previous[b.length];
1743
+ }
1744
+
1716
1745
  // src/render/icons.ts
1717
1746
  var ICONS = {
1718
1747
  app: "M -9 -7 h18 a2 2 0 0 1 2 2 v10 a2 2 0 0 1 -2 2 h-18 a2 2 0 0 1 -2 -2 v-10 a2 2 0 0 1 2 -2 z M -11 -2 h22",
@@ -8076,6 +8105,9 @@ function validate10(data, { instancePath = "", parentData, parentDataProperty, r
8076
8105
  var STATE_ENDS = ["start", "finish"];
8077
8106
  var LANE_MOST = 12;
8078
8107
  var HEAD = "HEAD";
8108
+
8109
+ // src/schema.ts
8110
+ var ICON_NAMES = Object.keys(ICONS);
8079
8111
  var EVENT_TYPES = ["edge", "action", "swap", "strip", "commit", "branch", "now", "mark", "span", "leaf", "node", "line", "seal", "open", "pick", "stamp"];
8080
8112
  var ABSENT = "#/definitions/absent/not";
8081
8113
  var ABSENT_KINDS = {
@@ -8105,7 +8137,16 @@ var WIRED_EVENTS = ["edge", "action"];
8105
8137
  var DURATION = /^\^\[0-9\]\+\(\\\.\[0-9\]\+\)\?\(([a-z|]+)\)\$$/u;
8106
8138
  var RATIO = /%\)\$$/u;
8107
8139
  var escape = (key) => key.replaceAll("~", "~0").replaceAll("/", "~1");
8140
+ function valueAt(input, pointer) {
8141
+ let value = input;
8142
+ for (const raw of pointer.split("/").slice(1)) {
8143
+ if (typeof value !== "object" || value === null) return void 0;
8144
+ value = value[raw.replaceAll("~1", "/").replaceAll("~0", "~")];
8145
+ }
8146
+ return value;
8147
+ }
8108
8148
  var URL_RULE = "#/definitions/url/pattern";
8149
+ var ICON_RULE = "#/definitions/icon/enum";
8109
8150
  var HEX = /^\^\[0-9a-f\]\{(\d+),(\d+)\}\$$/u;
8110
8151
  function forbiddenOf(pattern) {
8111
8152
  const inside = /^\^\[\^(.+)\]\+\$$/u.exec(pattern)?.[1];
@@ -8116,7 +8157,7 @@ function forbiddenOf(pattern) {
8116
8157
  var branchesOf = (anyOf, errors) => errors.filter(
8117
8158
  (error) => error !== anyOf && error.schemaPath.startsWith(`${anyOf.schemaPath}/`) && (error.instancePath === anyOf.instancePath || error.instancePath.startsWith(`${anyOf.instancePath}/`))
8118
8159
  );
8119
- function toFieldError(error, errors, m) {
8160
+ function toFieldError(error, errors, m, input) {
8120
8161
  const params = error.params;
8121
8162
  const at2 = error.instancePath;
8122
8163
  switch (error.keyword) {
@@ -8149,8 +8190,12 @@ function toFieldError(error, errors, m) {
8149
8190
  const tag = String(params.tag);
8150
8191
  return { pointer: `${at2}/${escape(tag)}`, message: m.discriminator(tag, EVENT_TYPES) };
8151
8192
  }
8152
- case "enum":
8193
+ case "enum": {
8194
+ const written = error.schemaPath === ICON_RULE ? valueAt(input, at2) : void 0;
8195
+ const near = typeof written === "string" ? nearest(written, ICON_NAMES) : void 0;
8196
+ if (typeof written === "string" && near !== void 0) return { pointer: at2, message: m.unknownIcon(written, near) };
8153
8197
  return { pointer: at2, message: m.enum(params.allowedValues.map(String)) };
8198
+ }
8154
8199
  case "type":
8155
8200
  return { pointer: at2, message: m.type(String(params.type)) };
8156
8201
  case "minLength":
@@ -8186,7 +8231,7 @@ function validateDiagram(input, options = {}) {
8186
8231
  const all = validate_diagram_default.errors ?? [];
8187
8232
  const inBranch = new Set(all.filter((error) => error.keyword === "anyOf").flatMap((anyOf) => branchesOf(anyOf, all)));
8188
8233
  const m = FIELD_MESSAGES[options.lang ?? "ja"];
8189
- const errors = all.filter((error) => error.keyword !== "if" && !inBranch.has(error)).map((error) => toFieldError(error, all, m));
8234
+ const errors = all.filter((error) => error.keyword !== "if" && !inBranch.has(error)).map((error) => toFieldError(error, all, m, input));
8190
8235
  return { ok: false, errors };
8191
8236
  }
8192
8237
 
@@ -11111,7 +11156,7 @@ function simplify(keys2) {
11111
11156
  }
11112
11157
  return out;
11113
11158
  }
11114
- function valueAt(keys2, t) {
11159
+ function valueAt2(keys2, t) {
11115
11160
  const first = keys2[0];
11116
11161
  if (!first) return 0;
11117
11162
  if (t <= first[0]) return first[1];
@@ -11293,7 +11338,7 @@ function meterField(field, keys2, ctx) {
11293
11338
  const y = field.y + M.y;
11294
11339
  const kf = m.kf([
11295
11340
  ...simplify(keys2).map(([t, v]) => [t, { transform: `scaleX(${r14(v * 1e3) / 1e3})` }]),
11296
- [m.last, { transform: `scaleX(${r14(valueAt(keys2, m.last) * 1e3) / 1e3})` }, EASE.inOut],
11341
+ [m.last, { transform: `scaleX(${r14(valueAt2(keys2, m.last) * 1e3) / 1e3})` }, EASE.inOut],
11297
11342
  [m.total, { transform: "scaleX(0)" }]
11298
11343
  ]);
11299
11344
  const lx = x + w * line;
@@ -11301,9 +11346,9 @@ function meterField(field, keys2, ctx) {
11301
11346
  }
11302
11347
  function timeFocus(layout, timeline, step, parts, vw, vh) {
11303
11348
  const span = timeline.steps[step];
11304
- const position = valueAt(timeline.needle ?? [], span.end - MOTION.still);
11349
+ const position = valueAt2(timeline.needle ?? [], span.end - MOTION.still);
11305
11350
  const badge2 = layout.badges.find((b) => b.step === step);
11306
- const anchored = badge2 && valueAt(timeline.needle ?? [], span.start) === position && !(layout.strip && badge2.y >= layout.strip.y);
11351
+ const anchored = badge2 && valueAt2(timeline.needle ?? [], span.start) === position && !(layout.strip && badge2.y >= layout.strip.y);
11307
11352
  const ax = anchored ? badge2.x : layout.axis.x + position * layout.axis.unit;
11308
11353
  const top = Math.min(...layout.rows.map((r) => r.y));
11309
11354
  const bottom = Math.max(...layout.rows.map((r) => r.y + r.h));
@@ -11885,16 +11930,16 @@ async function film(stage2, plan2) {
11885
11930
  const delay = gifEvery / fps * 1e3;
11886
11931
  const sampled = [];
11887
11932
  let colors = [];
11888
- const nearest = /* @__PURE__ */ new Map();
11933
+ const nearest2 = /* @__PURE__ */ new Map();
11889
11934
  const toIndex = (data) => {
11890
11935
  const index = new Uint8Array(data.length / 4);
11891
11936
  for (let p = 0; p < index.length; p++) {
11892
11937
  const i = p * 4;
11893
11938
  const key = data[i] << 16 | data[i + 1] << 8 | data[i + 2];
11894
- let k = nearest.get(key);
11939
+ let k = nearest2.get(key);
11895
11940
  if (k === void 0) {
11896
11941
  k = gif.nearestColorIndex(colors, [data[i], data[i + 1], data[i + 2]]);
11897
- nearest.set(key, k);
11942
+ nearest2.set(key, k);
11898
11943
  }
11899
11944
  index[p] = k;
11900
11945
  }