@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/node.cjs CHANGED
@@ -28,6 +28,7 @@ var ja = {
28
28
  additionalProperties: (key) => `${key} \u3068\u3044\u3046\u6B04\u306F\u66F8\u3051\u306A\u3044`,
29
29
  required: (key) => `${key} \u306E\u6B04\u304C\u8981\u308B`,
30
30
  enum: (values) => `${values.join(" / ")} \u306E\u3069\u308C\u304B\u306B\u3059\u308B`,
31
+ unknownIcon: (value, near) => `${value} \u3068\u3044\u3046 icon \u306F\u7121\u3044\u3002\u8FD1\u3044\u540D\u524D\u306F ${near}`,
31
32
  type: (type) => TYPES_JA[type] ?? `${type} \u306B\u3059\u308B`,
32
33
  minLength: (limit) => `${limit} \u5B57\u4EE5\u4E0A\u66F8\u304F`,
33
34
  maxLength: (limit) => `${limit} \u5B57\u307E\u3067\u306B\u3059\u308B`,
@@ -52,6 +53,7 @@ var en = {
52
53
  additionalProperties: (key) => `The ${key} field is not allowed`,
53
54
  required: (key) => `The ${key} field is required`,
54
55
  enum: (values) => `Use one of ${values.join(" / ")}`,
56
+ unknownIcon: (value, near) => `There is no icon named ${value}. The closest is ${near}`,
55
57
  type: (type) => TYPES_EN[type] ?? `Use ${type}`,
56
58
  minLength: (limit) => `Write at least ${plural(limit, "character")}`,
57
59
  maxLength: (limit) => `Write at most ${plural(limit, "character")}`,
@@ -74,6 +76,75 @@ var en = {
74
76
  };
75
77
  var FIELD_MESSAGES = { ja, en };
76
78
 
79
+ // src/nearest.ts
80
+ var MAX_DISTANCE = 2;
81
+ function nearest(word, candidates) {
82
+ const written = [...word.toLowerCase()];
83
+ let limit = Math.min(MAX_DISTANCE, written.length - 1);
84
+ let best;
85
+ for (const candidate of candidates) {
86
+ const d = distance(written, [...candidate.toLowerCase()]);
87
+ if (d > limit) continue;
88
+ best = candidate;
89
+ limit = d - 1;
90
+ }
91
+ return best;
92
+ }
93
+ function distance(a, b) {
94
+ let previous = Array.from({ length: b.length + 1 }, (_, j) => j);
95
+ for (let i = 1; i <= a.length; i++) {
96
+ const current = [i];
97
+ for (let j = 1; j <= b.length; j++) {
98
+ const replace = previous[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1);
99
+ current.push(Math.min(previous[j] + 1, current[j - 1] + 1, replace));
100
+ }
101
+ previous = current;
102
+ }
103
+ return previous[b.length];
104
+ }
105
+
106
+ // src/render/icons.ts
107
+ var ICONS = {
108
+ 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",
109
+ router: "M -9 -4 h16 M 3 -8 l4 4 l-4 4 M 9 5 h-16 M -3 1 l-4 4 l4 4",
110
+ on: "M -7 7 L 7 -7 M -1 -7 h8 v8",
111
+ off: "M -7 -7 L 7 7 M 7 -1 v8 h-8",
112
+ pool: "M -9 -5 a9 3.5 0 1 0 18 0 a9 3.5 0 1 0 -18 0 M -9 -5 v10 a9 3.5 0 0 0 18 0 v-10 M -9 0 a9 3.5 0 0 0 18 0",
113
+ db: "M -9 -5 a9 3.5 0 1 0 18 0 a9 3.5 0 1 0 -18 0 M -9 -5 v10 a9 3.5 0 0 0 18 0 v-10 M -9 0 a9 3.5 0 0 0 18 0",
114
+ exe: "M -5 -8 L 7 0 L -5 8 Z",
115
+ idx: "M -9 -7 h18 M -9 -2 h18 M -9 3 h18 M -9 8 h11",
116
+ sign: "M -9 4 c 3 -9 5 -9 6 0 s 3 7 6 -2 s 3 -6 6 0",
117
+ env: "M -8 -5.5 h16 v11 h-16 z M -8 -5.5 l8 6 l8 -6",
118
+ lock: "M -5.5 -1 h11 v8 h-11 z M -3.5 -1 v-3 a3.5 3.5 0 0 1 7 0 v3",
119
+ check: "M -5 0 l3.5 3.5 l6.5 -7",
120
+ flag: "M -4 8 V -8 M -4 -7 H 6 L 3.5 -3.5 L 6 0 H -4",
121
+ x: "M -5 -5 l10 10 M 5 -5 l-10 10",
122
+ chain: "M -1.5 4.5 l-2 2 a3.5 3.5 0 0 1 -5 -5 l3 -3 a3.5 3.5 0 0 1 5 0 M 1.5 -4.5 l2 -2 a3.5 3.5 0 0 1 5 5 l-3 3 a3.5 3.5 0 0 1 -5 0 M -2.5 2.5 l5 -5",
123
+ net: "M -1.3 -4.6 L -5.8 3 M 1.3 -4.6 L 5.8 3 M -4.3 5.5 H 4.3 M -2.2 -7 a 2.2 2.2 0 1 0 4.4 0 a 2.2 2.2 0 1 0 -4.4 0 M -9.2 5.5 a 2.2 2.2 0 1 0 4.4 0 a 2.2 2.2 0 1 0 -4.4 0 M 4.8 5.5 a 2.2 2.2 0 1 0 4.4 0 a 2.2 2.2 0 1 0 -4.4 0",
124
+ user: "M -4 -4.5 a4 4 0 1 0 8 0 a4 4 0 1 0 -8 0 M -8 9 c0 -5 3.6 -7.5 8 -7.5 s8 2.5 8 7.5",
125
+ server: "M -9 -8 h18 v7 h-18 z M -9 1 h18 v7 h-18 z M -5 -4.5 h0.01 M -5 4.5 h0.01",
126
+ key: "M -9 0 a3.5 3.5 0 1 0 7 0 a3.5 3.5 0 1 0 -7 0 M -2 0 h10 M 5 0 v3.5 M 8 0 v2.5",
127
+ shield: "M 0 -9 l8 3 v5 c0 5 -3.5 8 -8 10 c-4.5 -2 -8 -5 -8 -10 v-5 z",
128
+ globe: "M -9 0 a9 9 0 1 0 18 0 a9 9 0 1 0 -18 0 M -9 0 h18 M 0 -9 c-4.5 4 -4.5 14 0 18 M 0 -9 c4.5 4 4.5 14 0 18",
129
+ bolt: "M 2 -9 L -5 1 h5 l-2 8 l7 -10 h-5 z",
130
+ doc: "M -6 -9 h8 l5 5 v13 h-13 z M 2 -9 v5 h5 M -3 1 h7 M -3 5 h5",
131
+ box: "M -9 -4.5 l9 -4.5 l9 4.5 v9 l-9 4.5 l-9 -4.5 z M -9 -4.5 l9 4.5 l9 -4.5 M 0 0 v9",
132
+ truck: "M -10 -6 h11 v10 h-11 z M 1 -2 h5 l3.5 3.5 v2.5 h-8.5 M -7.5 6.5 a1.8 1.8 0 1 0 3.6 0 a1.8 1.8 0 1 0 -3.6 0 M 3 6.5 a1.8 1.8 0 1 0 3.6 0 a1.8 1.8 0 1 0 -3.6 0",
133
+ card: "M -9 -6.5 h18 a2 2 0 0 1 2 2 v9 a2 2 0 0 1 -2 2 h-18 a2 2 0 0 1 -2 -2 v-9 a2 2 0 0 1 2 -2 z M -11 -2 h22 M -7 3 h5",
134
+ cart: "M -10 -8 h3 l3 11 h11 l2.5 -8 h-15.5 M -4.5 7.5 a1.5 1.5 0 1 0 3 0 a1.5 1.5 0 1 0 -3 0 M 5 7.5 a1.5 1.5 0 1 0 3 0 a1.5 1.5 0 1 0 -3 0",
135
+ clock: "M -9 0 a9 9 0 1 0 18 0 a9 9 0 1 0 -18 0 M 0 -5 v5 l3.5 2.5",
136
+ branch: "M -4 -4.5 v9 M 5 0.5 c0 4 -9 3 -9 6.5 M -6.2 -7 a2.2 2.2 0 1 0 4.4 0 a2.2 2.2 0 1 0 -4.4 0 M -6.2 7 a2.2 2.2 0 1 0 4.4 0 a2.2 2.2 0 1 0 -4.4 0 M 2.8 -2 a2.2 2.2 0 1 0 4.4 0 a2.2 2.2 0 1 0 -4.4 0",
137
+ cloud: "M -7 6 h13 a4.5 4.5 0 0 0 0.5 -9 a6 6 0 0 0 -11.5 -1 a4.5 4.5 0 0 0 -2 10 z",
138
+ refresh: "M 7 -3 a7.5 7.5 0 1 0 0.5 5 M 7.5 -8 v5 h-5",
139
+ undo: "M -7 -2 h10 a5 5 0 0 1 0 10 h-6 M -3 -6 l-4 4 l4 4",
140
+ yen: "M -6 -8 l6 7 l6 -7 M 0 -1 v9 M -5 1.5 h10 M -5 5 h10",
141
+ layers: "M 0 -8 l9 4.5 l-9 4.5 l-9 -4.5 z M -9 2.5 l9 4.5 l9 -4.5",
142
+ code: "M -4 -6 l-5 6 l5 6 M 4 -6 l5 6 l-5 6",
143
+ paint: "M -8 8 c 0 -3 2 -5 4.5 -5 l 9 -9 l 3.5 3.5 l -9 9 c 0 2.5 -2 4.5 -5 4.5 z",
144
+ tree: "M 0 -5 v4 M -6 -1 h12 M -6 -1 v3 M 6 -1 v3 M -9 2 h6 v6 h-6 z M 3 2 h6 v6 h-6 z M -3 -10 h6 v5 h-6 z",
145
+ block: "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.5 h22 M -6 2.5 h8"
146
+ };
147
+
77
148
  // src/schemas/validate-diagram.js
78
149
  function ucs2length(str) {
79
150
  let length = 0;
@@ -6393,6 +6464,9 @@ function validate10(data, { instancePath = "", parentData, parentDataProperty, r
6393
6464
  return errors === 0;
6394
6465
  }
6395
6466
  var STATE_ENDS = ["start", "finish"];
6467
+
6468
+ // src/schema.ts
6469
+ var ICON_NAMES = Object.keys(ICONS);
6396
6470
  var EVENT_TYPES = ["edge", "action", "swap", "strip", "commit", "branch", "now", "mark", "span", "leaf", "node", "line", "seal", "open", "pick", "stamp"];
6397
6471
  var ABSENT = "#/definitions/absent/not";
6398
6472
  var ABSENT_KINDS = {
@@ -6422,7 +6496,16 @@ var WIRED_EVENTS = ["edge", "action"];
6422
6496
  var DURATION = /^\^\[0-9\]\+\(\\\.\[0-9\]\+\)\?\(([a-z|]+)\)\$$/u;
6423
6497
  var RATIO = /%\)\$$/u;
6424
6498
  var escape = (key) => key.replaceAll("~", "~0").replaceAll("/", "~1");
6499
+ function valueAt(input, pointer) {
6500
+ let value = input;
6501
+ for (const raw of pointer.split("/").slice(1)) {
6502
+ if (typeof value !== "object" || value === null) return void 0;
6503
+ value = value[raw.replaceAll("~1", "/").replaceAll("~0", "~")];
6504
+ }
6505
+ return value;
6506
+ }
6425
6507
  var URL_RULE = "#/definitions/url/pattern";
6508
+ var ICON_RULE = "#/definitions/icon/enum";
6426
6509
  var HEX = /^\^\[0-9a-f\]\{(\d+),(\d+)\}\$$/u;
6427
6510
  function forbiddenOf(pattern) {
6428
6511
  const inside = /^\^\[\^(.+)\]\+\$$/u.exec(pattern)?.[1];
@@ -6433,7 +6516,7 @@ function forbiddenOf(pattern) {
6433
6516
  var branchesOf = (anyOf, errors) => errors.filter(
6434
6517
  (error) => error !== anyOf && error.schemaPath.startsWith(`${anyOf.schemaPath}/`) && (error.instancePath === anyOf.instancePath || error.instancePath.startsWith(`${anyOf.instancePath}/`))
6435
6518
  );
6436
- function toFieldError(error, errors, m) {
6519
+ function toFieldError(error, errors, m, input) {
6437
6520
  const params = error.params;
6438
6521
  const at = error.instancePath;
6439
6522
  switch (error.keyword) {
@@ -6466,8 +6549,12 @@ function toFieldError(error, errors, m) {
6466
6549
  const tag = String(params.tag);
6467
6550
  return { pointer: `${at}/${escape(tag)}`, message: m.discriminator(tag, EVENT_TYPES) };
6468
6551
  }
6469
- case "enum":
6552
+ case "enum": {
6553
+ const written = error.schemaPath === ICON_RULE ? valueAt(input, at) : void 0;
6554
+ const near = typeof written === "string" ? nearest(written, ICON_NAMES) : void 0;
6555
+ if (typeof written === "string" && near !== void 0) return { pointer: at, message: m.unknownIcon(written, near) };
6470
6556
  return { pointer: at, message: m.enum(params.allowedValues.map(String)) };
6557
+ }
6471
6558
  case "type":
6472
6559
  return { pointer: at, message: m.type(String(params.type)) };
6473
6560
  case "minLength":
@@ -6503,7 +6590,7 @@ function validateDiagram(input, options = {}) {
6503
6590
  const all = validate_diagram_default.errors ?? [];
6504
6591
  const inBranch = new Set(all.filter((error) => error.keyword === "anyOf").flatMap((anyOf) => branchesOf(anyOf, all)));
6505
6592
  const m = FIELD_MESSAGES[options.lang ?? "ja"];
6506
- const errors = all.filter((error) => error.keyword !== "if" && !inBranch.has(error)).map((error) => toFieldError(error, all, m));
6593
+ const errors = all.filter((error) => error.keyword !== "if" && !inBranch.has(error)).map((error) => toFieldError(error, all, m, input));
6507
6594
  return { ok: false, errors };
6508
6595
  }
6509
6596