@cardenelabs/dragon 0.46.0 → 0.46.3

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.cjs CHANGED
@@ -841,8 +841,8 @@ function longest(points) {
841
841
  }
842
842
  return { a: best.a, b: best.b, vertical: Math.abs(best.b[0] - best.a[0]) < Math.abs(best.b[1] - best.a[1]) };
843
843
  }
844
- function along(points, distance) {
845
- let left = distance;
844
+ function along(points, distance2) {
845
+ let left = distance2;
846
846
  for (let i = 1; i < points.length; i++) {
847
847
  const a = points[i - 1];
848
848
  const b = points[i];
@@ -1675,6 +1675,7 @@ var ja = {
1675
1675
  additionalProperties: (key) => `${key} \u3068\u3044\u3046\u6B04\u306F\u66F8\u3051\u306A\u3044`,
1676
1676
  required: (key) => `${key} \u306E\u6B04\u304C\u8981\u308B`,
1677
1677
  enum: (values) => `${values.join(" / ")} \u306E\u3069\u308C\u304B\u306B\u3059\u308B`,
1678
+ unknownIcon: (value, near) => `${value} \u3068\u3044\u3046 icon \u306F\u7121\u3044\u3002\u8FD1\u3044\u540D\u524D\u306F ${near}`,
1678
1679
  type: (type) => TYPES_JA[type] ?? `${type} \u306B\u3059\u308B`,
1679
1680
  minLength: (limit) => `${limit} \u5B57\u4EE5\u4E0A\u66F8\u304F`,
1680
1681
  maxLength: (limit) => `${limit} \u5B57\u307E\u3067\u306B\u3059\u308B`,
@@ -1699,6 +1700,7 @@ var en = {
1699
1700
  additionalProperties: (key) => `The ${key} field is not allowed`,
1700
1701
  required: (key) => `The ${key} field is required`,
1701
1702
  enum: (values) => `Use one of ${values.join(" / ")}`,
1703
+ unknownIcon: (value, near) => `There is no icon named ${value}. The closest is ${near}`,
1702
1704
  type: (type) => TYPES_EN[type] ?? `Use ${type}`,
1703
1705
  minLength: (limit) => `Write at least ${plural(limit, "character")}`,
1704
1706
  maxLength: (limit) => `Write at most ${plural(limit, "character")}`,
@@ -1721,6 +1723,33 @@ var en = {
1721
1723
  };
1722
1724
  var FIELD_MESSAGES = { ja, en };
1723
1725
 
1726
+ // src/nearest.ts
1727
+ var MAX_DISTANCE = 2;
1728
+ function nearest(word, candidates) {
1729
+ const written = [...word.toLowerCase()];
1730
+ let limit = Math.min(MAX_DISTANCE, written.length - 1);
1731
+ let best;
1732
+ for (const candidate of candidates) {
1733
+ const d = distance(written, [...candidate.toLowerCase()]);
1734
+ if (d > limit) continue;
1735
+ best = candidate;
1736
+ limit = d - 1;
1737
+ }
1738
+ return best;
1739
+ }
1740
+ function distance(a, b) {
1741
+ let previous = Array.from({ length: b.length + 1 }, (_, j) => j);
1742
+ for (let i = 1; i <= a.length; i++) {
1743
+ const current = [i];
1744
+ for (let j = 1; j <= b.length; j++) {
1745
+ const replace = previous[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1);
1746
+ current.push(Math.min(previous[j] + 1, current[j - 1] + 1, replace));
1747
+ }
1748
+ previous = current;
1749
+ }
1750
+ return previous[b.length];
1751
+ }
1752
+
1724
1753
  // src/render/icons.ts
1725
1754
  var ICONS = {
1726
1755
  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",
@@ -8169,7 +8198,16 @@ var WIRED_EVENTS = ["edge", "action"];
8169
8198
  var DURATION = /^\^\[0-9\]\+\(\\\.\[0-9\]\+\)\?\(([a-z|]+)\)\$$/u;
8170
8199
  var RATIO = /%\)\$$/u;
8171
8200
  var escape = (key) => key.replaceAll("~", "~0").replaceAll("/", "~1");
8201
+ function valueAt(input, pointer) {
8202
+ let value = input;
8203
+ for (const raw of pointer.split("/").slice(1)) {
8204
+ if (typeof value !== "object" || value === null) return void 0;
8205
+ value = value[raw.replaceAll("~1", "/").replaceAll("~0", "~")];
8206
+ }
8207
+ return value;
8208
+ }
8172
8209
  var URL_RULE = "#/definitions/url/pattern";
8210
+ var ICON_RULE = "#/definitions/icon/enum";
8173
8211
  var HEX = /^\^\[0-9a-f\]\{(\d+),(\d+)\}\$$/u;
8174
8212
  function forbiddenOf(pattern) {
8175
8213
  const inside = /^\^\[\^(.+)\]\+\$$/u.exec(pattern)?.[1];
@@ -8180,7 +8218,7 @@ function forbiddenOf(pattern) {
8180
8218
  var branchesOf = (anyOf, errors) => errors.filter(
8181
8219
  (error) => error !== anyOf && error.schemaPath.startsWith(`${anyOf.schemaPath}/`) && (error.instancePath === anyOf.instancePath || error.instancePath.startsWith(`${anyOf.instancePath}/`))
8182
8220
  );
8183
- function toFieldError(error, errors, m) {
8221
+ function toFieldError(error, errors, m, input) {
8184
8222
  const params = error.params;
8185
8223
  const at2 = error.instancePath;
8186
8224
  switch (error.keyword) {
@@ -8213,8 +8251,12 @@ function toFieldError(error, errors, m) {
8213
8251
  const tag = String(params.tag);
8214
8252
  return { pointer: `${at2}/${escape(tag)}`, message: m.discriminator(tag, EVENT_TYPES) };
8215
8253
  }
8216
- case "enum":
8254
+ case "enum": {
8255
+ const written = error.schemaPath === ICON_RULE ? valueAt(input, at2) : void 0;
8256
+ const near = typeof written === "string" ? nearest(written, ICON_NAMES) : void 0;
8257
+ if (typeof written === "string" && near !== void 0) return { pointer: at2, message: m.unknownIcon(written, near) };
8217
8258
  return { pointer: at2, message: m.enum(params.allowedValues.map(String)) };
8259
+ }
8218
8260
  case "type":
8219
8261
  return { pointer: at2, message: m.type(String(params.type)) };
8220
8262
  case "minLength":
@@ -8250,7 +8292,7 @@ function validateDiagram(input, options = {}) {
8250
8292
  const all = validate_diagram_default.errors ?? [];
8251
8293
  const inBranch = new Set(all.filter((error) => error.keyword === "anyOf").flatMap((anyOf) => branchesOf(anyOf, all)));
8252
8294
  const m = FIELD_MESSAGES[options.lang ?? "ja"];
8253
- const errors = all.filter((error) => error.keyword !== "if" && !inBranch.has(error)).map((error) => toFieldError(error, all, m));
8295
+ const errors = all.filter((error) => error.keyword !== "if" && !inBranch.has(error)).map((error) => toFieldError(error, all, m, input));
8254
8296
  return { ok: false, errors };
8255
8297
  }
8256
8298
 
@@ -11182,7 +11224,7 @@ function simplify(keys2) {
11182
11224
  }
11183
11225
  return out;
11184
11226
  }
11185
- function valueAt(keys2, t) {
11227
+ function valueAt2(keys2, t) {
11186
11228
  const first = keys2[0];
11187
11229
  if (!first) return 0;
11188
11230
  if (t <= first[0]) return first[1];
@@ -11364,7 +11406,7 @@ function meterField(field, keys2, ctx) {
11364
11406
  const y = field.y + M.y;
11365
11407
  const kf = m.kf([
11366
11408
  ...simplify(keys2).map(([t, v]) => [t, { transform: `scaleX(${r14(v * 1e3) / 1e3})` }]),
11367
- [m.last, { transform: `scaleX(${r14(valueAt(keys2, m.last) * 1e3) / 1e3})` }, EASE.inOut],
11409
+ [m.last, { transform: `scaleX(${r14(valueAt2(keys2, m.last) * 1e3) / 1e3})` }, EASE.inOut],
11368
11410
  [m.total, { transform: "scaleX(0)" }]
11369
11411
  ]);
11370
11412
  const lx = x + w * line;
@@ -11372,9 +11414,9 @@ function meterField(field, keys2, ctx) {
11372
11414
  }
11373
11415
  function timeFocus(layout, timeline, step, parts, vw, vh) {
11374
11416
  const span = timeline.steps[step];
11375
- const position = valueAt(timeline.needle ?? [], span.end - MOTION.still);
11417
+ const position = valueAt2(timeline.needle ?? [], span.end - MOTION.still);
11376
11418
  const badge2 = layout.badges.find((b) => b.step === step);
11377
- const anchored = badge2 && valueAt(timeline.needle ?? [], span.start) === position && !(layout.strip && badge2.y >= layout.strip.y);
11419
+ const anchored = badge2 && valueAt2(timeline.needle ?? [], span.start) === position && !(layout.strip && badge2.y >= layout.strip.y);
11378
11420
  const ax = anchored ? badge2.x : layout.axis.x + position * layout.axis.unit;
11379
11421
  const top = Math.min(...layout.rows.map((r) => r.y));
11380
11422
  const bottom = Math.max(...layout.rows.map((r) => r.y + r.h));
@@ -11956,16 +11998,16 @@ async function film(stage2, plan2) {
11956
11998
  const delay = gifEvery / fps * 1e3;
11957
11999
  const sampled = [];
11958
12000
  let colors = [];
11959
- const nearest = /* @__PURE__ */ new Map();
12001
+ const nearest2 = /* @__PURE__ */ new Map();
11960
12002
  const toIndex = (data) => {
11961
12003
  const index = new Uint8Array(data.length / 4);
11962
12004
  for (let p = 0; p < index.length; p++) {
11963
12005
  const i = p * 4;
11964
12006
  const key = data[i] << 16 | data[i + 1] << 8 | data[i + 2];
11965
- let k = nearest.get(key);
12007
+ let k = nearest2.get(key);
11966
12008
  if (k === void 0) {
11967
12009
  k = gif.nearestColorIndex(colors, [data[i], data[i + 1], data[i + 2]]);
11968
- nearest.set(key, k);
12010
+ nearest2.set(key, k);
11969
12011
  }
11970
12012
  index[p] = k;
11971
12013
  }
@@ -12198,6 +12240,10 @@ function writeOutputs(outDir, name, outputs) {
12198
12240
 
12199
12241
  // src/messages.ts
12200
12242
  var list = (words) => words.join(" / ");
12243
+ var withNear = (value, near, none) => {
12244
+ const name = nearest(value, ICON_NAMES);
12245
+ return name === void 0 ? none : near(name);
12246
+ };
12201
12247
  var ja3 = () => {
12202
12248
  const shapes = {
12203
12249
  sequence: "sequence <\u984C>",
@@ -12258,7 +12304,7 @@ var ja3 = () => {
12258
12304
  attrTwice: (key) => `${key} \u306F 1 \u3064\u306E\u884C\u306B 1 \u3064\u307E\u3067`,
12259
12305
  badAttr: (key, allowed) => `${key} \u306F\u3053\u306E\u884C\u306B\u66F8\u3051\u306A\u3044\u5C5E\u6027\u3002\u66F8\u3051\u308B\u306E\u306F ${list(allowed)}`,
12260
12306
  badColor: `color \u306F ${list(COLORS)} \u306E\u3069\u308C\u304B`,
12261
- badIcon: `icon \u306F ${list(ICON_NAMES)} \u306E\u3069\u308C\u304B`,
12307
+ 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`),
12262
12308
  badView: `view \u306F ${list(VIEWS)} \u306E\u3069\u308C\u304B`,
12263
12309
  badCarry: `carry \u306F ${list(CARRIES)} \u306E\u3069\u308C\u304B\u3002\u672D\u306F tag: <\u5024> \u3067\u66F8\u304F`,
12264
12310
  badSide: `side \u306F ${list(SIDES)} \u306E\u3069\u308C\u304B`,
@@ -12397,7 +12443,7 @@ var en2 = () => {
12397
12443
  attrTwice: (key) => `Write ${key} only once on a line`,
12398
12444
  badAttr: (key, allowed) => `${key} cannot be written on this line. Write ${list(allowed)}`,
12399
12445
  badColor: `color is one of ${list(COLORS)}`,
12400
- badIcon: `icon is one of ${list(ICON_NAMES)}`,
12446
+ badIcon: (value) => withNear(value, (near) => `There is no icon named ${value}. The closest is ${near}`, `icon is one of ${list(ICON_NAMES)}`),
12401
12447
  badView: `view is one of ${list(VIEWS)}`,
12402
12448
  badCarry: `carry is one of ${list(CARRIES)}. Write a tag as tag: <value>`,
12403
12449
  badSide: `side is one of ${list(SIDES)}`,
@@ -12639,7 +12685,7 @@ function lookOf(source, attrs, m) {
12639
12685
  const color = attrs.get("color");
12640
12686
  if (color && !isOneOf(COLORS, color.value)) throw fail(source, color.at, m.badColor);
12641
12687
  const icon = attrs.get("icon");
12642
- if (icon && !ICON_NAMES.includes(icon.value)) throw fail(source, icon.at, m.badIcon);
12688
+ if (icon && !ICON_NAMES.includes(icon.value)) throw fail(source, icon.at, m.badIcon(icon.value));
12643
12689
  const note = attrs.get("note")?.value;
12644
12690
  return {
12645
12691
  ...note !== void 0 ? { note } : {},