@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/README.ja.md +331 -0
- package/README.md +200 -188
- package/dist/cli.cjs +61 -15
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +61 -15
- package/dist/cli.js.map +1 -1
- package/dist/export.cjs +57 -12
- package/dist/export.cjs.map +1 -1
- package/dist/export.js +57 -12
- package/dist/export.js.map +1 -1
- package/dist/index.cjs +54 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +54 -8
- package/dist/index.js.map +1 -1
- package/dist/light/index.cjs +52 -6
- package/dist/light/index.cjs.map +1 -1
- package/dist/light/index.js +52 -6
- package/dist/light/index.js.map +1 -1
- package/dist/node.cjs +90 -3
- package/dist/node.cjs.map +1 -1
- package/dist/node.js +90 -3
- package/dist/node.js.map +1 -1
- package/dist/player.global.js +3 -3
- package/package.json +1 -1
- package/src/field-messages.ts +4 -0
- package/src/messages.ts +10 -3
- package/src/nearest.ts +37 -0
- package/src/parser.ts +1 -1
- package/src/schema.ts +21 -3
package/dist/light/index.cjs
CHANGED
|
@@ -135,6 +135,33 @@ function extractDiagrams(markdown) {
|
|
|
135
135
|
return fences;
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
+
// src/nearest.ts
|
|
139
|
+
var MAX_DISTANCE = 2;
|
|
140
|
+
function nearest(word, candidates) {
|
|
141
|
+
const written = [...word.toLowerCase()];
|
|
142
|
+
let limit = Math.min(MAX_DISTANCE, written.length - 1);
|
|
143
|
+
let best;
|
|
144
|
+
for (const candidate of candidates) {
|
|
145
|
+
const d = distance(written, [...candidate.toLowerCase()]);
|
|
146
|
+
if (d > limit) continue;
|
|
147
|
+
best = candidate;
|
|
148
|
+
limit = d - 1;
|
|
149
|
+
}
|
|
150
|
+
return best;
|
|
151
|
+
}
|
|
152
|
+
function distance(a, b) {
|
|
153
|
+
let previous = Array.from({ length: b.length + 1 }, (_, j) => j);
|
|
154
|
+
for (let i = 1; i <= a.length; i++) {
|
|
155
|
+
const current = [i];
|
|
156
|
+
for (let j = 1; j <= b.length; j++) {
|
|
157
|
+
const replace = previous[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1);
|
|
158
|
+
current.push(Math.min(previous[j] + 1, current[j - 1] + 1, replace));
|
|
159
|
+
}
|
|
160
|
+
previous = current;
|
|
161
|
+
}
|
|
162
|
+
return previous[b.length];
|
|
163
|
+
}
|
|
164
|
+
|
|
138
165
|
// src/field-messages.ts
|
|
139
166
|
var TYPES_JA = {
|
|
140
167
|
string: "\u6587\u5B57\u5217\u306B\u3059\u308B",
|
|
@@ -159,6 +186,7 @@ var ja = {
|
|
|
159
186
|
additionalProperties: (key2) => `${key2} \u3068\u3044\u3046\u6B04\u306F\u66F8\u3051\u306A\u3044`,
|
|
160
187
|
required: (key2) => `${key2} \u306E\u6B04\u304C\u8981\u308B`,
|
|
161
188
|
enum: (values) => `${values.join(" / ")} \u306E\u3069\u308C\u304B\u306B\u3059\u308B`,
|
|
189
|
+
unknownIcon: (value2, near) => `${value2} \u3068\u3044\u3046 icon \u306F\u7121\u3044\u3002\u8FD1\u3044\u540D\u524D\u306F ${near}`,
|
|
162
190
|
type: (type) => _nullishCoalesce(TYPES_JA[type], () => ( `${type} \u306B\u3059\u308B`)),
|
|
163
191
|
minLength: (limit) => `${limit} \u5B57\u4EE5\u4E0A\u66F8\u304F`,
|
|
164
192
|
maxLength: (limit) => `${limit} \u5B57\u307E\u3067\u306B\u3059\u308B`,
|
|
@@ -183,6 +211,7 @@ var en = {
|
|
|
183
211
|
additionalProperties: (key2) => `The ${key2} field is not allowed`,
|
|
184
212
|
required: (key2) => `The ${key2} field is required`,
|
|
185
213
|
enum: (values) => `Use one of ${values.join(" / ")}`,
|
|
214
|
+
unknownIcon: (value2, near) => `There is no icon named ${value2}. The closest is ${near}`,
|
|
186
215
|
type: (type) => _nullishCoalesce(TYPES_EN[type], () => ( `Use ${type}`)),
|
|
187
216
|
minLength: (limit) => `Write at least ${plural(limit, "character")}`,
|
|
188
217
|
maxLength: (limit) => `Write at most ${plural(limit, "character")}`,
|
|
@@ -6577,7 +6606,16 @@ var WIRED_EVENTS = ["edge", "action"];
|
|
|
6577
6606
|
var DURATION = /^\^\[0-9\]\+\(\\\.\[0-9\]\+\)\?\(([a-z|]+)\)\$$/u;
|
|
6578
6607
|
var RATIO = /%\)\$$/u;
|
|
6579
6608
|
var escape = (key2) => key2.replaceAll("~", "~0").replaceAll("/", "~1");
|
|
6609
|
+
function valueAt(input, pointer) {
|
|
6610
|
+
let value2 = input;
|
|
6611
|
+
for (const raw of pointer.split("/").slice(1)) {
|
|
6612
|
+
if (typeof value2 !== "object" || value2 === null) return void 0;
|
|
6613
|
+
value2 = value2[raw.replaceAll("~1", "/").replaceAll("~0", "~")];
|
|
6614
|
+
}
|
|
6615
|
+
return value2;
|
|
6616
|
+
}
|
|
6580
6617
|
var URL_RULE = "#/definitions/url/pattern";
|
|
6618
|
+
var ICON_RULE = "#/definitions/icon/enum";
|
|
6581
6619
|
var HEX = /^\^\[0-9a-f\]\{(\d+),(\d+)\}\$$/u;
|
|
6582
6620
|
function forbiddenOf(pattern) {
|
|
6583
6621
|
const inside = _optionalChain([/^\^\[\^(.+)\]\+\$$/u, 'access', _6 => _6.exec, 'call', _7 => _7(pattern), 'optionalAccess', _8 => _8[1]]);
|
|
@@ -6588,7 +6626,7 @@ function forbiddenOf(pattern) {
|
|
|
6588
6626
|
var branchesOf = (anyOf, errors) => errors.filter(
|
|
6589
6627
|
(error) => error !== anyOf && error.schemaPath.startsWith(`${anyOf.schemaPath}/`) && (error.instancePath === anyOf.instancePath || error.instancePath.startsWith(`${anyOf.instancePath}/`))
|
|
6590
6628
|
);
|
|
6591
|
-
function toFieldError(error, errors, m) {
|
|
6629
|
+
function toFieldError(error, errors, m, input) {
|
|
6592
6630
|
const params = error.params;
|
|
6593
6631
|
const at = error.instancePath;
|
|
6594
6632
|
switch (error.keyword) {
|
|
@@ -6621,8 +6659,12 @@ function toFieldError(error, errors, m) {
|
|
|
6621
6659
|
const tag = String(params.tag);
|
|
6622
6660
|
return { pointer: `${at}/${escape(tag)}`, message: m.discriminator(tag, EVENT_TYPES) };
|
|
6623
6661
|
}
|
|
6624
|
-
case "enum":
|
|
6662
|
+
case "enum": {
|
|
6663
|
+
const written = error.schemaPath === ICON_RULE ? valueAt(input, at) : void 0;
|
|
6664
|
+
const near = typeof written === "string" ? nearest(written, ICON_NAMES) : void 0;
|
|
6665
|
+
if (typeof written === "string" && near !== void 0) return { pointer: at, message: m.unknownIcon(written, near) };
|
|
6625
6666
|
return { pointer: at, message: m.enum(params.allowedValues.map(String)) };
|
|
6667
|
+
}
|
|
6626
6668
|
case "type":
|
|
6627
6669
|
return { pointer: at, message: m.type(String(params.type)) };
|
|
6628
6670
|
case "minLength":
|
|
@@ -6658,12 +6700,16 @@ function validateDiagram(input, options = {}) {
|
|
|
6658
6700
|
const all = _nullishCoalesce(validate_diagram_default.errors, () => ( []));
|
|
6659
6701
|
const inBranch = new Set(all.filter((error) => error.keyword === "anyOf").flatMap((anyOf) => branchesOf(anyOf, all)));
|
|
6660
6702
|
const m = FIELD_MESSAGES[_nullishCoalesce(options.lang, () => ( "ja"))];
|
|
6661
|
-
const errors = all.filter((error) => error.keyword !== "if" && !inBranch.has(error)).map((error) => toFieldError(error, all, m));
|
|
6703
|
+
const errors = all.filter((error) => error.keyword !== "if" && !inBranch.has(error)).map((error) => toFieldError(error, all, m, input));
|
|
6662
6704
|
return { ok: false, errors };
|
|
6663
6705
|
}
|
|
6664
6706
|
|
|
6665
6707
|
// src/messages.ts
|
|
6666
6708
|
var list = (words) => words.join(" / ");
|
|
6709
|
+
var withNear = (value2, near, none) => {
|
|
6710
|
+
const name2 = nearest(value2, ICON_NAMES);
|
|
6711
|
+
return name2 === void 0 ? none : near(name2);
|
|
6712
|
+
};
|
|
6667
6713
|
var ja2 = () => {
|
|
6668
6714
|
const shapes = {
|
|
6669
6715
|
sequence: "sequence <\u984C>",
|
|
@@ -6724,7 +6770,7 @@ var ja2 = () => {
|
|
|
6724
6770
|
attrTwice: (key2) => `${key2} \u306F 1 \u3064\u306E\u884C\u306B 1 \u3064\u307E\u3067`,
|
|
6725
6771
|
badAttr: (key2, allowed) => `${key2} \u306F\u3053\u306E\u884C\u306B\u66F8\u3051\u306A\u3044\u5C5E\u6027\u3002\u66F8\u3051\u308B\u306E\u306F ${list(allowed)}`,
|
|
6726
6772
|
badColor: `color \u306F ${list(COLORS)} \u306E\u3069\u308C\u304B`,
|
|
6727
|
-
badIcon: `icon \u306F ${list(ICON_NAMES)} \u306E\u3069\u308C\u304B
|
|
6773
|
+
badIcon: (value2) => withNear(value2, (near) => `${value2} \u3068\u3044\u3046 icon \u306F\u7121\u3044\u3002\u8FD1\u3044\u540D\u524D\u306F ${near}`, `icon \u306F ${list(ICON_NAMES)} \u306E\u3069\u308C\u304B`),
|
|
6728
6774
|
badView: `view \u306F ${list(_chunkCLS6JVKKcjs.VIEWS)} \u306E\u3069\u308C\u304B`,
|
|
6729
6775
|
badCarry: `carry \u306F ${list(_chunkCLS6JVKKcjs.CARRIES)} \u306E\u3069\u308C\u304B\u3002\u672D\u306F tag: <\u5024> \u3067\u66F8\u304F`,
|
|
6730
6776
|
badSide: `side \u306F ${list(_chunkCLS6JVKKcjs.SIDES)} \u306E\u3069\u308C\u304B`,
|
|
@@ -6863,7 +6909,7 @@ var en2 = () => {
|
|
|
6863
6909
|
attrTwice: (key2) => `Write ${key2} only once on a line`,
|
|
6864
6910
|
badAttr: (key2, allowed) => `${key2} cannot be written on this line. Write ${list(allowed)}`,
|
|
6865
6911
|
badColor: `color is one of ${list(COLORS)}`,
|
|
6866
|
-
badIcon: `icon is one of ${list(ICON_NAMES)}
|
|
6912
|
+
badIcon: (value2) => withNear(value2, (near) => `There is no icon named ${value2}. The closest is ${near}`, `icon is one of ${list(ICON_NAMES)}`),
|
|
6867
6913
|
badView: `view is one of ${list(_chunkCLS6JVKKcjs.VIEWS)}`,
|
|
6868
6914
|
badCarry: `carry is one of ${list(_chunkCLS6JVKKcjs.CARRIES)}. Write a tag as tag: <value>`,
|
|
6869
6915
|
badSide: `side is one of ${list(_chunkCLS6JVKKcjs.SIDES)}`,
|
|
@@ -7124,7 +7170,7 @@ function lookOf(source, attrs2, m) {
|
|
|
7124
7170
|
const color = attrs2.get("color");
|
|
7125
7171
|
if (color && !isOneOf(COLORS, color.value)) throw fail(source, color.at, m.badColor);
|
|
7126
7172
|
const icon = attrs2.get("icon");
|
|
7127
|
-
if (icon && !ICON_NAMES.includes(icon.value)) throw fail(source, icon.at, m.badIcon);
|
|
7173
|
+
if (icon && !ICON_NAMES.includes(icon.value)) throw fail(source, icon.at, m.badIcon(icon.value));
|
|
7128
7174
|
const note = _optionalChain([attrs2, 'access', _12 => _12.get, 'call', _13 => _13("note"), 'optionalAccess', _14 => _14.value]);
|
|
7129
7175
|
return {
|
|
7130
7176
|
...note !== void 0 ? { note } : {},
|