@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/cli.js CHANGED
@@ -835,8 +835,8 @@ function longest(points) {
835
835
  }
836
836
  return { a: best.a, b: best.b, vertical: Math.abs(best.b[0] - best.a[0]) < Math.abs(best.b[1] - best.a[1]) };
837
837
  }
838
- function along(points, distance) {
839
- let left = distance;
838
+ function along(points, distance2) {
839
+ let left = distance2;
840
840
  for (let i = 1; i < points.length; i++) {
841
841
  const a = points[i - 1];
842
842
  const b = points[i];
@@ -1669,6 +1669,7 @@ var ja = {
1669
1669
  additionalProperties: (key) => `${key} \u3068\u3044\u3046\u6B04\u306F\u66F8\u3051\u306A\u3044`,
1670
1670
  required: (key) => `${key} \u306E\u6B04\u304C\u8981\u308B`,
1671
1671
  enum: (values) => `${values.join(" / ")} \u306E\u3069\u308C\u304B\u306B\u3059\u308B`,
1672
+ unknownIcon: (value, near) => `${value} \u3068\u3044\u3046 icon \u306F\u7121\u3044\u3002\u8FD1\u3044\u540D\u524D\u306F ${near}`,
1672
1673
  type: (type) => TYPES_JA[type] ?? `${type} \u306B\u3059\u308B`,
1673
1674
  minLength: (limit) => `${limit} \u5B57\u4EE5\u4E0A\u66F8\u304F`,
1674
1675
  maxLength: (limit) => `${limit} \u5B57\u307E\u3067\u306B\u3059\u308B`,
@@ -1693,6 +1694,7 @@ var en = {
1693
1694
  additionalProperties: (key) => `The ${key} field is not allowed`,
1694
1695
  required: (key) => `The ${key} field is required`,
1695
1696
  enum: (values) => `Use one of ${values.join(" / ")}`,
1697
+ unknownIcon: (value, near) => `There is no icon named ${value}. The closest is ${near}`,
1696
1698
  type: (type) => TYPES_EN[type] ?? `Use ${type}`,
1697
1699
  minLength: (limit) => `Write at least ${plural(limit, "character")}`,
1698
1700
  maxLength: (limit) => `Write at most ${plural(limit, "character")}`,
@@ -1715,6 +1717,33 @@ var en = {
1715
1717
  };
1716
1718
  var FIELD_MESSAGES = { ja, en };
1717
1719
 
1720
+ // src/nearest.ts
1721
+ var MAX_DISTANCE = 2;
1722
+ function nearest(word, candidates) {
1723
+ const written = [...word.toLowerCase()];
1724
+ let limit = Math.min(MAX_DISTANCE, written.length - 1);
1725
+ let best;
1726
+ for (const candidate of candidates) {
1727
+ const d = distance(written, [...candidate.toLowerCase()]);
1728
+ if (d > limit) continue;
1729
+ best = candidate;
1730
+ limit = d - 1;
1731
+ }
1732
+ return best;
1733
+ }
1734
+ function distance(a, b) {
1735
+ let previous = Array.from({ length: b.length + 1 }, (_, j) => j);
1736
+ for (let i = 1; i <= a.length; i++) {
1737
+ const current = [i];
1738
+ for (let j = 1; j <= b.length; j++) {
1739
+ const replace = previous[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1);
1740
+ current.push(Math.min(previous[j] + 1, current[j - 1] + 1, replace));
1741
+ }
1742
+ previous = current;
1743
+ }
1744
+ return previous[b.length];
1745
+ }
1746
+
1718
1747
  // src/render/icons.ts
1719
1748
  var ICONS = {
1720
1749
  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",
@@ -8163,7 +8192,16 @@ var WIRED_EVENTS = ["edge", "action"];
8163
8192
  var DURATION = /^\^\[0-9\]\+\(\\\.\[0-9\]\+\)\?\(([a-z|]+)\)\$$/u;
8164
8193
  var RATIO = /%\)\$$/u;
8165
8194
  var escape = (key) => key.replaceAll("~", "~0").replaceAll("/", "~1");
8195
+ function valueAt(input, pointer) {
8196
+ let value = input;
8197
+ for (const raw of pointer.split("/").slice(1)) {
8198
+ if (typeof value !== "object" || value === null) return void 0;
8199
+ value = value[raw.replaceAll("~1", "/").replaceAll("~0", "~")];
8200
+ }
8201
+ return value;
8202
+ }
8166
8203
  var URL_RULE = "#/definitions/url/pattern";
8204
+ var ICON_RULE = "#/definitions/icon/enum";
8167
8205
  var HEX = /^\^\[0-9a-f\]\{(\d+),(\d+)\}\$$/u;
8168
8206
  function forbiddenOf(pattern) {
8169
8207
  const inside = /^\^\[\^(.+)\]\+\$$/u.exec(pattern)?.[1];
@@ -8174,7 +8212,7 @@ function forbiddenOf(pattern) {
8174
8212
  var branchesOf = (anyOf, errors) => errors.filter(
8175
8213
  (error) => error !== anyOf && error.schemaPath.startsWith(`${anyOf.schemaPath}/`) && (error.instancePath === anyOf.instancePath || error.instancePath.startsWith(`${anyOf.instancePath}/`))
8176
8214
  );
8177
- function toFieldError(error, errors, m) {
8215
+ function toFieldError(error, errors, m, input) {
8178
8216
  const params = error.params;
8179
8217
  const at2 = error.instancePath;
8180
8218
  switch (error.keyword) {
@@ -8207,8 +8245,12 @@ function toFieldError(error, errors, m) {
8207
8245
  const tag = String(params.tag);
8208
8246
  return { pointer: `${at2}/${escape(tag)}`, message: m.discriminator(tag, EVENT_TYPES) };
8209
8247
  }
8210
- case "enum":
8248
+ case "enum": {
8249
+ const written = error.schemaPath === ICON_RULE ? valueAt(input, at2) : void 0;
8250
+ const near = typeof written === "string" ? nearest(written, ICON_NAMES) : void 0;
8251
+ if (typeof written === "string" && near !== void 0) return { pointer: at2, message: m.unknownIcon(written, near) };
8211
8252
  return { pointer: at2, message: m.enum(params.allowedValues.map(String)) };
8253
+ }
8212
8254
  case "type":
8213
8255
  return { pointer: at2, message: m.type(String(params.type)) };
8214
8256
  case "minLength":
@@ -8244,7 +8286,7 @@ function validateDiagram(input, options = {}) {
8244
8286
  const all = validate_diagram_default.errors ?? [];
8245
8287
  const inBranch = new Set(all.filter((error) => error.keyword === "anyOf").flatMap((anyOf) => branchesOf(anyOf, all)));
8246
8288
  const m = FIELD_MESSAGES[options.lang ?? "ja"];
8247
- const errors = all.filter((error) => error.keyword !== "if" && !inBranch.has(error)).map((error) => toFieldError(error, all, m));
8289
+ const errors = all.filter((error) => error.keyword !== "if" && !inBranch.has(error)).map((error) => toFieldError(error, all, m, input));
8248
8290
  return { ok: false, errors };
8249
8291
  }
8250
8292
 
@@ -11176,7 +11218,7 @@ function simplify(keys2) {
11176
11218
  }
11177
11219
  return out;
11178
11220
  }
11179
- function valueAt(keys2, t) {
11221
+ function valueAt2(keys2, t) {
11180
11222
  const first = keys2[0];
11181
11223
  if (!first) return 0;
11182
11224
  if (t <= first[0]) return first[1];
@@ -11358,7 +11400,7 @@ function meterField(field, keys2, ctx) {
11358
11400
  const y = field.y + M.y;
11359
11401
  const kf = m.kf([
11360
11402
  ...simplify(keys2).map(([t, v]) => [t, { transform: `scaleX(${r14(v * 1e3) / 1e3})` }]),
11361
- [m.last, { transform: `scaleX(${r14(valueAt(keys2, m.last) * 1e3) / 1e3})` }, EASE.inOut],
11403
+ [m.last, { transform: `scaleX(${r14(valueAt2(keys2, m.last) * 1e3) / 1e3})` }, EASE.inOut],
11362
11404
  [m.total, { transform: "scaleX(0)" }]
11363
11405
  ]);
11364
11406
  const lx = x + w * line;
@@ -11366,9 +11408,9 @@ function meterField(field, keys2, ctx) {
11366
11408
  }
11367
11409
  function timeFocus(layout, timeline, step, parts, vw, vh) {
11368
11410
  const span = timeline.steps[step];
11369
- const position = valueAt(timeline.needle ?? [], span.end - MOTION.still);
11411
+ const position = valueAt2(timeline.needle ?? [], span.end - MOTION.still);
11370
11412
  const badge2 = layout.badges.find((b) => b.step === step);
11371
- const anchored = badge2 && valueAt(timeline.needle ?? [], span.start) === position && !(layout.strip && badge2.y >= layout.strip.y);
11413
+ const anchored = badge2 && valueAt2(timeline.needle ?? [], span.start) === position && !(layout.strip && badge2.y >= layout.strip.y);
11372
11414
  const ax = anchored ? badge2.x : layout.axis.x + position * layout.axis.unit;
11373
11415
  const top = Math.min(...layout.rows.map((r) => r.y));
11374
11416
  const bottom = Math.max(...layout.rows.map((r) => r.y + r.h));
@@ -11950,16 +11992,16 @@ async function film(stage2, plan2) {
11950
11992
  const delay = gifEvery / fps * 1e3;
11951
11993
  const sampled = [];
11952
11994
  let colors = [];
11953
- const nearest = /* @__PURE__ */ new Map();
11995
+ const nearest2 = /* @__PURE__ */ new Map();
11954
11996
  const toIndex = (data) => {
11955
11997
  const index = new Uint8Array(data.length / 4);
11956
11998
  for (let p = 0; p < index.length; p++) {
11957
11999
  const i = p * 4;
11958
12000
  const key = data[i] << 16 | data[i + 1] << 8 | data[i + 2];
11959
- let k = nearest.get(key);
12001
+ let k = nearest2.get(key);
11960
12002
  if (k === void 0) {
11961
12003
  k = gif.nearestColorIndex(colors, [data[i], data[i + 1], data[i + 2]]);
11962
- nearest.set(key, k);
12004
+ nearest2.set(key, k);
11963
12005
  }
11964
12006
  index[p] = k;
11965
12007
  }
@@ -12192,6 +12234,10 @@ function writeOutputs(outDir, name, outputs) {
12192
12234
 
12193
12235
  // src/messages.ts
12194
12236
  var list = (words) => words.join(" / ");
12237
+ var withNear = (value, near, none) => {
12238
+ const name = nearest(value, ICON_NAMES);
12239
+ return name === void 0 ? none : near(name);
12240
+ };
12195
12241
  var ja3 = () => {
12196
12242
  const shapes = {
12197
12243
  sequence: "sequence <\u984C>",
@@ -12252,7 +12298,7 @@ var ja3 = () => {
12252
12298
  attrTwice: (key) => `${key} \u306F 1 \u3064\u306E\u884C\u306B 1 \u3064\u307E\u3067`,
12253
12299
  badAttr: (key, allowed) => `${key} \u306F\u3053\u306E\u884C\u306B\u66F8\u3051\u306A\u3044\u5C5E\u6027\u3002\u66F8\u3051\u308B\u306E\u306F ${list(allowed)}`,
12254
12300
  badColor: `color \u306F ${list(COLORS)} \u306E\u3069\u308C\u304B`,
12255
- badIcon: `icon \u306F ${list(ICON_NAMES)} \u306E\u3069\u308C\u304B`,
12301
+ badIcon: (value) => withNear(value, (near) => `${value} \u3068\u3044\u3046 icon \u306F\u7121\u3044\u3002\u8FD1\u3044\u540D\u524D\u306F ${near}`, `icon \u306F ${list(ICON_NAMES)} \u306E\u3069\u308C\u304B`),
12256
12302
  badView: `view \u306F ${list(VIEWS)} \u306E\u3069\u308C\u304B`,
12257
12303
  badCarry: `carry \u306F ${list(CARRIES)} \u306E\u3069\u308C\u304B\u3002\u672D\u306F tag: <\u5024> \u3067\u66F8\u304F`,
12258
12304
  badSide: `side \u306F ${list(SIDES)} \u306E\u3069\u308C\u304B`,
@@ -12391,7 +12437,7 @@ var en2 = () => {
12391
12437
  attrTwice: (key) => `Write ${key} only once on a line`,
12392
12438
  badAttr: (key, allowed) => `${key} cannot be written on this line. Write ${list(allowed)}`,
12393
12439
  badColor: `color is one of ${list(COLORS)}`,
12394
- badIcon: `icon is one of ${list(ICON_NAMES)}`,
12440
+ badIcon: (value) => withNear(value, (near) => `There is no icon named ${value}. The closest is ${near}`, `icon is one of ${list(ICON_NAMES)}`),
12395
12441
  badView: `view is one of ${list(VIEWS)}`,
12396
12442
  badCarry: `carry is one of ${list(CARRIES)}. Write a tag as tag: <value>`,
12397
12443
  badSide: `side is one of ${list(SIDES)}`,
@@ -12633,7 +12679,7 @@ function lookOf(source, attrs, m) {
12633
12679
  const color = attrs.get("color");
12634
12680
  if (color && !isOneOf(COLORS, color.value)) throw fail(source, color.at, m.badColor);
12635
12681
  const icon = attrs.get("icon");
12636
- if (icon && !ICON_NAMES.includes(icon.value)) throw fail(source, icon.at, m.badIcon);
12682
+ if (icon && !ICON_NAMES.includes(icon.value)) throw fail(source, icon.at, m.badIcon(icon.value));
12637
12683
  const note = attrs.get("note")?.value;
12638
12684
  return {
12639
12685
  ...note !== void 0 ? { note } : {},