@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/node.js CHANGED
@@ -26,6 +26,7 @@ var ja = {
26
26
  additionalProperties: (key) => `${key} \u3068\u3044\u3046\u6B04\u306F\u66F8\u3051\u306A\u3044`,
27
27
  required: (key) => `${key} \u306E\u6B04\u304C\u8981\u308B`,
28
28
  enum: (values) => `${values.join(" / ")} \u306E\u3069\u308C\u304B\u306B\u3059\u308B`,
29
+ unknownIcon: (value, near) => `${value} \u3068\u3044\u3046 icon \u306F\u7121\u3044\u3002\u8FD1\u3044\u540D\u524D\u306F ${near}`,
29
30
  type: (type) => TYPES_JA[type] ?? `${type} \u306B\u3059\u308B`,
30
31
  minLength: (limit) => `${limit} \u5B57\u4EE5\u4E0A\u66F8\u304F`,
31
32
  maxLength: (limit) => `${limit} \u5B57\u307E\u3067\u306B\u3059\u308B`,
@@ -50,6 +51,7 @@ var en = {
50
51
  additionalProperties: (key) => `The ${key} field is not allowed`,
51
52
  required: (key) => `The ${key} field is required`,
52
53
  enum: (values) => `Use one of ${values.join(" / ")}`,
54
+ unknownIcon: (value, near) => `There is no icon named ${value}. The closest is ${near}`,
53
55
  type: (type) => TYPES_EN[type] ?? `Use ${type}`,
54
56
  minLength: (limit) => `Write at least ${plural(limit, "character")}`,
55
57
  maxLength: (limit) => `Write at most ${plural(limit, "character")}`,
@@ -72,6 +74,75 @@ var en = {
72
74
  };
73
75
  var FIELD_MESSAGES = { ja, en };
74
76
 
77
+ // src/nearest.ts
78
+ var MAX_DISTANCE = 2;
79
+ function nearest(word, candidates) {
80
+ const written = [...word.toLowerCase()];
81
+ let limit = Math.min(MAX_DISTANCE, written.length - 1);
82
+ let best;
83
+ for (const candidate of candidates) {
84
+ const d = distance(written, [...candidate.toLowerCase()]);
85
+ if (d > limit) continue;
86
+ best = candidate;
87
+ limit = d - 1;
88
+ }
89
+ return best;
90
+ }
91
+ function distance(a, b) {
92
+ let previous = Array.from({ length: b.length + 1 }, (_, j) => j);
93
+ for (let i = 1; i <= a.length; i++) {
94
+ const current = [i];
95
+ for (let j = 1; j <= b.length; j++) {
96
+ const replace = previous[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1);
97
+ current.push(Math.min(previous[j] + 1, current[j - 1] + 1, replace));
98
+ }
99
+ previous = current;
100
+ }
101
+ return previous[b.length];
102
+ }
103
+
104
+ // src/render/icons.ts
105
+ var ICONS = {
106
+ 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",
107
+ 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",
108
+ on: "M -7 7 L 7 -7 M -1 -7 h8 v8",
109
+ off: "M -7 -7 L 7 7 M 7 -1 v8 h-8",
110
+ 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",
111
+ 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",
112
+ exe: "M -5 -8 L 7 0 L -5 8 Z",
113
+ idx: "M -9 -7 h18 M -9 -2 h18 M -9 3 h18 M -9 8 h11",
114
+ sign: "M -9 4 c 3 -9 5 -9 6 0 s 3 7 6 -2 s 3 -6 6 0",
115
+ env: "M -8 -5.5 h16 v11 h-16 z M -8 -5.5 l8 6 l8 -6",
116
+ 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",
117
+ check: "M -5 0 l3.5 3.5 l6.5 -7",
118
+ flag: "M -4 8 V -8 M -4 -7 H 6 L 3.5 -3.5 L 6 0 H -4",
119
+ x: "M -5 -5 l10 10 M 5 -5 l-10 10",
120
+ 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",
121
+ 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",
122
+ 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",
123
+ 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",
124
+ 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",
125
+ 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",
126
+ 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",
127
+ bolt: "M 2 -9 L -5 1 h5 l-2 8 l7 -10 h-5 z",
128
+ doc: "M -6 -9 h8 l5 5 v13 h-13 z M 2 -9 v5 h5 M -3 1 h7 M -3 5 h5",
129
+ 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",
130
+ 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",
131
+ 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",
132
+ 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",
133
+ 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",
134
+ 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",
135
+ 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",
136
+ refresh: "M 7 -3 a7.5 7.5 0 1 0 0.5 5 M 7.5 -8 v5 h-5",
137
+ undo: "M -7 -2 h10 a5 5 0 0 1 0 10 h-6 M -3 -6 l-4 4 l4 4",
138
+ yen: "M -6 -8 l6 7 l6 -7 M 0 -1 v9 M -5 1.5 h10 M -5 5 h10",
139
+ 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",
140
+ code: "M -4 -6 l-5 6 l5 6 M 4 -6 l5 6 l-5 6",
141
+ 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",
142
+ 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",
143
+ 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"
144
+ };
145
+
75
146
  // src/schemas/validate-diagram.js
76
147
  function ucs2length(str) {
77
148
  let length = 0;
@@ -6391,6 +6462,9 @@ function validate10(data, { instancePath = "", parentData, parentDataProperty, r
6391
6462
  return errors === 0;
6392
6463
  }
6393
6464
  var STATE_ENDS = ["start", "finish"];
6465
+
6466
+ // src/schema.ts
6467
+ var ICON_NAMES = Object.keys(ICONS);
6394
6468
  var EVENT_TYPES = ["edge", "action", "swap", "strip", "commit", "branch", "now", "mark", "span", "leaf", "node", "line", "seal", "open", "pick", "stamp"];
6395
6469
  var ABSENT = "#/definitions/absent/not";
6396
6470
  var ABSENT_KINDS = {
@@ -6420,7 +6494,16 @@ var WIRED_EVENTS = ["edge", "action"];
6420
6494
  var DURATION = /^\^\[0-9\]\+\(\\\.\[0-9\]\+\)\?\(([a-z|]+)\)\$$/u;
6421
6495
  var RATIO = /%\)\$$/u;
6422
6496
  var escape = (key) => key.replaceAll("~", "~0").replaceAll("/", "~1");
6497
+ function valueAt(input, pointer) {
6498
+ let value = input;
6499
+ for (const raw of pointer.split("/").slice(1)) {
6500
+ if (typeof value !== "object" || value === null) return void 0;
6501
+ value = value[raw.replaceAll("~1", "/").replaceAll("~0", "~")];
6502
+ }
6503
+ return value;
6504
+ }
6423
6505
  var URL_RULE = "#/definitions/url/pattern";
6506
+ var ICON_RULE = "#/definitions/icon/enum";
6424
6507
  var HEX = /^\^\[0-9a-f\]\{(\d+),(\d+)\}\$$/u;
6425
6508
  function forbiddenOf(pattern) {
6426
6509
  const inside = /^\^\[\^(.+)\]\+\$$/u.exec(pattern)?.[1];
@@ -6431,7 +6514,7 @@ function forbiddenOf(pattern) {
6431
6514
  var branchesOf = (anyOf, errors) => errors.filter(
6432
6515
  (error) => error !== anyOf && error.schemaPath.startsWith(`${anyOf.schemaPath}/`) && (error.instancePath === anyOf.instancePath || error.instancePath.startsWith(`${anyOf.instancePath}/`))
6433
6516
  );
6434
- function toFieldError(error, errors, m) {
6517
+ function toFieldError(error, errors, m, input) {
6435
6518
  const params = error.params;
6436
6519
  const at = error.instancePath;
6437
6520
  switch (error.keyword) {
@@ -6464,8 +6547,12 @@ function toFieldError(error, errors, m) {
6464
6547
  const tag = String(params.tag);
6465
6548
  return { pointer: `${at}/${escape(tag)}`, message: m.discriminator(tag, EVENT_TYPES) };
6466
6549
  }
6467
- case "enum":
6550
+ case "enum": {
6551
+ const written = error.schemaPath === ICON_RULE ? valueAt(input, at) : void 0;
6552
+ const near = typeof written === "string" ? nearest(written, ICON_NAMES) : void 0;
6553
+ if (typeof written === "string" && near !== void 0) return { pointer: at, message: m.unknownIcon(written, near) };
6468
6554
  return { pointer: at, message: m.enum(params.allowedValues.map(String)) };
6555
+ }
6469
6556
  case "type":
6470
6557
  return { pointer: at, message: m.type(String(params.type)) };
6471
6558
  case "minLength":
@@ -6501,7 +6588,7 @@ function validateDiagram(input, options = {}) {
6501
6588
  const all = validate_diagram_default.errors ?? [];
6502
6589
  const inBranch = new Set(all.filter((error) => error.keyword === "anyOf").flatMap((anyOf) => branchesOf(anyOf, all)));
6503
6590
  const m = FIELD_MESSAGES[options.lang ?? "ja"];
6504
- const errors = all.filter((error) => error.keyword !== "if" && !inBranch.has(error)).map((error) => toFieldError(error, all, m));
6591
+ const errors = all.filter((error) => error.keyword !== "if" && !inBranch.has(error)).map((error) => toFieldError(error, all, m, input));
6505
6592
  return { ok: false, errors };
6506
6593
  }
6507
6594