@altnovatrail/widgets 0.2.0 → 0.3.0
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.md +1 -1
- package/cores/vector.schema.json +22 -1
- package/kinds/cards/cards.handles.json +109 -0
- package/kinds/cards/cards.schema.json +483 -0
- package/kinds/cards/vectors/any.json +255 -0
- package/kinds/cards/vectors/box.json +325 -0
- package/kinds/cards/vectors/fork-taps.json +305 -0
- package/kinds/cards/vectors/fork.json +254 -0
- package/kinds/cards/vectors/invalid-goal.json +70 -0
- package/kinds/cards/vectors/invalid-ids.json +113 -0
- package/kinds/cards/vectors/invalid-schema.json +88 -0
- package/kinds/cards/vectors/invalid-taps.json +214 -0
- package/kinds/cards/vectors/key.json +264 -0
- package/kinds/cards/vectors/limit.json +274 -0
- package/kinds/cards/vectors/no-goal.json +205 -0
- package/kinds/cards/vectors/none.json +239 -0
- package/kinds/cards/vectors/recog.json +113 -0
- package/kinds/cards/vectors/riddle.json +397 -0
- package/kinds/cards/vectors/solo.json +218 -0
- package/kinds/cells/cells.schema.json +17 -2
- package/kinds/line/line.handles.json +195 -0
- package/kinds/line/line.schema.json +336 -0
- package/kinds/line/vectors/cases.json +213 -0
- package/kinds/line/vectors/gaps-12-d1-1.json +140 -0
- package/kinds/line/vectors/gaps-12-d1-2.json +95 -0
- package/kinds/line/vectors/gaps-12-d1-3.json +122 -0
- package/kinds/line/vectors/gaps-12-d1-4.json +121 -0
- package/kinds/line/vectors/gaps-12-d1-5.json +87 -0
- package/kinds/line/vectors/gaps-12-d2-1.json +173 -0
- package/kinds/line/vectors/gaps-12-d2-6.json +87 -0
- package/kinds/line/vectors/gaps-12-d3-2.json +173 -0
- package/kinds/line/vectors/gaps-12-d4-4.json +168 -0
- package/kinds/line/vectors/gaps-12-d5-3.json +99 -0
- package/kinds/line/vectors/gaps-12-d5-4.json +215 -0
- package/kinds/line/vectors/gaps-34-d1-1.json +37 -0
- package/kinds/line/vectors/gaps-34-d1-2.json +130 -0
- package/kinds/line/vectors/gaps-34-d1-4.json +155 -0
- package/kinds/line/vectors/gaps-34-d1-5.json +43 -0
- package/kinds/line/vectors/gaps-34-d3-2.json +38 -0
- package/kinds/line/vectors/gaps-34-d3-5.json +177 -0
- package/kinds/line/vectors/gaps-34-d5-3.json +39 -0
- package/kinds/line/vectors/invalid-line.json +34 -0
- package/kinds/line/vectors/invalid-ring.json +34 -0
- package/kinds/line/vectors/invalid.json +43 -0
- package/kinds/line/vectors/jump-unreachable.json +104 -0
- package/kinds/line/vectors/limit.json +40 -0
- package/kinds/line/vectors/op-not-in-scene.json +47 -0
- package/kinds/line/vectors/ring-cut.json +104 -0
- package/kinds/line/vectors/ring-every.json +107 -0
- package/kinds/line/vectors/ring-jump.json +135 -0
- package/lib/cores/arith.d.ts +62 -0
- package/lib/cores/arith.js +197 -0
- package/lib/cores/kind.d.ts +31 -3
- package/lib/cores/registry.d.ts +43 -0
- package/lib/cores/registry.js +87 -0
- package/lib/cores/search.d.ts +22 -6
- package/lib/cores/search.js +70 -14
- package/lib/kinds/cards/goal.d.ts +25 -0
- package/lib/kinds/cards/goal.js +72 -0
- package/lib/kinds/cards/index.d.ts +14 -0
- package/lib/kinds/cards/index.js +17 -0
- package/lib/kinds/cards/kind.d.ts +23 -0
- package/lib/kinds/cards/kind.js +101 -0
- package/lib/kinds/cards/parts.d.ts +36 -0
- package/lib/kinds/cards/parts.js +34 -0
- package/lib/kinds/cards/scene.d.ts +102 -0
- package/lib/kinds/cards/scene.js +356 -0
- package/lib/kinds/cards/schema.d.ts +10 -0
- package/lib/kinds/cards/schema.js +285 -0
- package/lib/kinds/cells/kind.js +11 -64
- package/lib/kinds/cells/operation.d.ts +6 -0
- package/lib/kinds/cells/polyomino.d.ts +14 -0
- package/lib/kinds/cells/polyomino.js +100 -24
- package/lib/kinds/cells/registry.js +1 -1
- package/lib/kinds/cells/schema.js +3 -1
- package/lib/kinds/line/cut.d.ts +2 -0
- package/lib/kinds/line/cut.js +63 -0
- package/lib/kinds/line/goals.d.ts +22 -0
- package/lib/kinds/line/goals.js +137 -0
- package/lib/kinds/line/index.d.ts +13 -0
- package/lib/kinds/line/index.js +17 -0
- package/lib/kinds/line/jump.d.ts +10 -0
- package/lib/kinds/line/jump.js +95 -0
- package/lib/kinds/line/kind.d.ts +25 -0
- package/lib/kinds/line/kind.js +125 -0
- package/lib/kinds/line/line.d.ts +63 -0
- package/lib/kinds/line/line.js +157 -0
- package/lib/kinds/line/operation.d.ts +69 -0
- package/lib/kinds/line/operation.js +1 -0
- package/lib/kinds/line/posts.d.ts +11 -0
- package/lib/kinds/line/posts.js +85 -0
- package/lib/kinds/line/registry.d.ts +2 -0
- package/lib/kinds/line/registry.js +11 -0
- package/lib/kinds/line/schema.d.ts +4 -0
- package/lib/kinds/line/schema.js +159 -0
- package/package.json +16 -4
- package/cores/handles.schema.json +0 -63
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
// A scene of the kind cards, read from its JSON by hand as cards.schema.json has it: the signs the
|
|
2
|
+
// scene names with their values, the cards in groups, each giving a value to every sign, the
|
|
3
|
+
// options to choose among, how a tap chooses, the table of signs and at most one goal. The reading
|
|
4
|
+
// refuses what the schema cannot say — an ID given twice, a sign or a value the scene does not
|
|
5
|
+
// name, a card that leaves a sign out — and never takes what the schema refuses.
|
|
6
|
+
import { array, isObject, map, object, pointer, string } from "../../cores/json.js";
|
|
7
|
+
/** The ID of a card, a group or an option: a part's ID, as the widget gives it, by itself. */
|
|
8
|
+
export const partId = /^[A-Za-z0-9][A-Za-z0-9_.-]{0,23}$/;
|
|
9
|
+
/** The ID of a sign, a value or a column: kebab-case, with no colon, so a part's ID holds it. */
|
|
10
|
+
export const nameId = /^[a-z0-9][a-z0-9-]{0,23}$/;
|
|
11
|
+
export const maxSigns = 10;
|
|
12
|
+
export const maxValues = 12;
|
|
13
|
+
export const maxGroups = 6;
|
|
14
|
+
export const maxCards = 12;
|
|
15
|
+
export const maxOptions = 6;
|
|
16
|
+
export const maxColumns = 8;
|
|
17
|
+
export const maxLabel = 80;
|
|
18
|
+
export const maxText = 300;
|
|
19
|
+
/** The most conditions an all or an any joins, and the deepest they nest, a literal at depth 1. */
|
|
20
|
+
export const maxJoined = 8;
|
|
21
|
+
export const maxDepth = 4;
|
|
22
|
+
// A text's length is in characters, as the schema's maxLength counts them, not UTF-16 code units.
|
|
23
|
+
const label = (value, path, errors, max = maxLabel) => {
|
|
24
|
+
const length = typeof value === "string" ? [...value].length : 0;
|
|
25
|
+
if (typeof value !== "string" || length < 1 || length > max) {
|
|
26
|
+
errors.push({ path, message: `a text of 1 to ${max} characters` });
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
return value;
|
|
30
|
+
};
|
|
31
|
+
/** An ID not given before in its set; one given twice is named and not taken again. */
|
|
32
|
+
function fresh(value, path, errors, pattern, what, taken) {
|
|
33
|
+
const id = string(value, path, errors, pattern, what);
|
|
34
|
+
if (id === undefined)
|
|
35
|
+
return undefined;
|
|
36
|
+
if (taken.has(id)) {
|
|
37
|
+
errors.push({ path, message: "this ID is given twice" });
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
taken.add(id);
|
|
41
|
+
return id;
|
|
42
|
+
}
|
|
43
|
+
/** A list of IDs, each once and each one of those known. */
|
|
44
|
+
function ids(value, path, errors, known, what, max) {
|
|
45
|
+
const items = array(value, path, errors, 1, max);
|
|
46
|
+
if (items === undefined)
|
|
47
|
+
return undefined;
|
|
48
|
+
const read = [];
|
|
49
|
+
let ok = true;
|
|
50
|
+
items.forEach((item, i) => {
|
|
51
|
+
const at = pointer(path, i);
|
|
52
|
+
if (typeof item !== "string" || !known.has(item)) {
|
|
53
|
+
errors.push({ path: at, message: what });
|
|
54
|
+
ok = false;
|
|
55
|
+
}
|
|
56
|
+
else if (read.includes(item)) {
|
|
57
|
+
errors.push({ path: at, message: "this ID is given twice" });
|
|
58
|
+
ok = false;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
read.push(item);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
return ok ? read : undefined;
|
|
65
|
+
}
|
|
66
|
+
function readSigns(value, errors) {
|
|
67
|
+
const items = array(value, "/signs", errors, 1, maxSigns);
|
|
68
|
+
if (items === undefined)
|
|
69
|
+
return undefined;
|
|
70
|
+
const taken = new Set();
|
|
71
|
+
const signs = [];
|
|
72
|
+
items.forEach((item, i) => {
|
|
73
|
+
const at = pointer("/signs", i);
|
|
74
|
+
const o = object(item, at, errors, ["id", "label", "values"]);
|
|
75
|
+
if (o === undefined)
|
|
76
|
+
return;
|
|
77
|
+
const id = fresh(o.id, pointer(at, "id"), errors, nameId, "a sign's ID", taken);
|
|
78
|
+
const named = label(o.label, pointer(at, "label"), errors);
|
|
79
|
+
const listed = array(o.values, pointer(at, "values"), errors, 1, maxValues);
|
|
80
|
+
const valueIds = new Set();
|
|
81
|
+
const values = [];
|
|
82
|
+
listed?.forEach((v, j) => {
|
|
83
|
+
const vat = pointer(pointer(at, "values"), j);
|
|
84
|
+
const vo = object(v, vat, errors, ["id", "label"]);
|
|
85
|
+
if (vo === undefined)
|
|
86
|
+
return;
|
|
87
|
+
const vid = fresh(vo.id, pointer(vat, "id"), errors, nameId, "a value's ID", valueIds);
|
|
88
|
+
const vlabel = label(vo.label, pointer(vat, "label"), errors);
|
|
89
|
+
if (vid !== undefined && vlabel !== undefined)
|
|
90
|
+
values.push({ id: vid, label: vlabel });
|
|
91
|
+
});
|
|
92
|
+
if (id !== undefined && named !== undefined && listed !== undefined) {
|
|
93
|
+
signs.push({ id, label: named, values });
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
return signs;
|
|
97
|
+
}
|
|
98
|
+
/** The value a sign has, or that a literal names, read against the scene's signs. */
|
|
99
|
+
function signValue(value, sign, path, errors) {
|
|
100
|
+
if (sign === undefined)
|
|
101
|
+
return undefined;
|
|
102
|
+
const id = typeof value === "string" ? value : undefined;
|
|
103
|
+
if (id === undefined || !sign.values.some((v) => v.id === id)) {
|
|
104
|
+
errors.push({ path, message: `a value of the sign "${sign.id}"` });
|
|
105
|
+
return undefined;
|
|
106
|
+
}
|
|
107
|
+
return id;
|
|
108
|
+
}
|
|
109
|
+
function readCard(value, path, errors, signs, taken) {
|
|
110
|
+
const o = object(value, path, errors, ["id", "signs"], ["text"]);
|
|
111
|
+
if (o === undefined)
|
|
112
|
+
return undefined;
|
|
113
|
+
const id = fresh(o.id, pointer(path, "id"), errors, partId, "a card's ID", taken);
|
|
114
|
+
const text = o.text === undefined ? null : label(o.text, pointer(path, "text"), errors, maxText);
|
|
115
|
+
const at = pointer(path, "signs");
|
|
116
|
+
const given = map(o.signs, at, errors);
|
|
117
|
+
const values = new Map();
|
|
118
|
+
if (given !== undefined && signs !== undefined) {
|
|
119
|
+
for (const name of Object.keys(given)) {
|
|
120
|
+
if (!signs.some((sign) => sign.id === name)) {
|
|
121
|
+
errors.push({ path: pointer(at, name), message: "no sign of the scene has this ID" });
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
for (const sign of signs) {
|
|
125
|
+
if (!Object.hasOwn(given, sign.id)) {
|
|
126
|
+
errors.push({ path: at, message: `the sign "${sign.id}" is missing` });
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
const v = signValue(given[sign.id], sign, pointer(at, sign.id), errors);
|
|
130
|
+
if (v !== undefined)
|
|
131
|
+
values.set(sign.id, v);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (id === undefined || text === undefined || given === undefined)
|
|
135
|
+
return undefined;
|
|
136
|
+
return { id, text, signs: values };
|
|
137
|
+
}
|
|
138
|
+
function readGroups(value, errors, signs, taken) {
|
|
139
|
+
const items = array(value, "/groups", errors, 1, maxGroups);
|
|
140
|
+
if (items === undefined)
|
|
141
|
+
return undefined;
|
|
142
|
+
const groups = [];
|
|
143
|
+
items.forEach((item, i) => {
|
|
144
|
+
const at = pointer("/groups", i);
|
|
145
|
+
const o = object(item, at, errors, ["id", "cards"], ["label"]);
|
|
146
|
+
if (o === undefined)
|
|
147
|
+
return;
|
|
148
|
+
const id = fresh(o.id, pointer(at, "id"), errors, partId, "a group's ID", taken);
|
|
149
|
+
const named = o.label === undefined ? null : label(o.label, pointer(at, "label"), errors);
|
|
150
|
+
const listed = array(o.cards, pointer(at, "cards"), errors, 1, maxCards);
|
|
151
|
+
const cards = (listed ?? []).map((card, j) => readCard(card, pointer(pointer(at, "cards"), j), errors, signs, taken));
|
|
152
|
+
if (id !== undefined && named !== undefined && listed !== undefined) {
|
|
153
|
+
groups.push({ id, label: named, cards: cards.filter((card) => card !== undefined) });
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
return groups;
|
|
157
|
+
}
|
|
158
|
+
function readOptions(value, errors, taken) {
|
|
159
|
+
if (value === undefined)
|
|
160
|
+
return [];
|
|
161
|
+
const items = array(value, "/options", errors, 1, maxOptions);
|
|
162
|
+
const options = [];
|
|
163
|
+
items?.forEach((item, i) => {
|
|
164
|
+
const at = pointer("/options", i);
|
|
165
|
+
const o = object(item, at, errors, ["id", "label"]);
|
|
166
|
+
if (o === undefined)
|
|
167
|
+
return;
|
|
168
|
+
const id = fresh(o.id, pointer(at, "id"), errors, partId, "an option's ID", taken);
|
|
169
|
+
const named = label(o.label, pointer(at, "label"), errors);
|
|
170
|
+
if (id !== undefined && named !== undefined)
|
|
171
|
+
options.push({ id, label: named });
|
|
172
|
+
});
|
|
173
|
+
return options;
|
|
174
|
+
}
|
|
175
|
+
/** A sign and one of its values, as a literal and a column give them. */
|
|
176
|
+
function readLiteral(o, path, errors, signs) {
|
|
177
|
+
const name = typeof o.sign === "string" ? o.sign : undefined;
|
|
178
|
+
const sign = signs.find((s) => s.id === name);
|
|
179
|
+
if (sign === undefined) {
|
|
180
|
+
errors.push({ path: pointer(path, "sign"), message: "a sign of the scene" });
|
|
181
|
+
}
|
|
182
|
+
const has = Object.hasOwn(o, "is");
|
|
183
|
+
if (has === Object.hasOwn(o, "not")) {
|
|
184
|
+
errors.push({ path, message: 'one of the members "is" and "not"' });
|
|
185
|
+
return undefined;
|
|
186
|
+
}
|
|
187
|
+
const member = has ? "is" : "not";
|
|
188
|
+
const v = signValue(o[member], sign, pointer(path, member), errors);
|
|
189
|
+
if (sign === undefined || v === undefined)
|
|
190
|
+
return undefined;
|
|
191
|
+
return has ? { sign: sign.id, is: v } : { sign: sign.id, not: v };
|
|
192
|
+
}
|
|
193
|
+
function readCondition(value, path, errors, signs, depth) {
|
|
194
|
+
if (!isObject(value)) {
|
|
195
|
+
errors.push({ path, message: "an object" });
|
|
196
|
+
return undefined;
|
|
197
|
+
}
|
|
198
|
+
const join = Object.hasOwn(value, "all") ? "all" : Object.hasOwn(value, "any") ? "any" : null;
|
|
199
|
+
if (join === null) {
|
|
200
|
+
const o = object(value, path, errors, ["sign"], ["is", "not"]);
|
|
201
|
+
return o === undefined ? undefined : readLiteral(o, path, errors, signs);
|
|
202
|
+
}
|
|
203
|
+
const o = object(value, path, errors, [join]);
|
|
204
|
+
if (o === undefined)
|
|
205
|
+
return undefined;
|
|
206
|
+
if (depth >= maxDepth) {
|
|
207
|
+
errors.push({ path, message: `conditions nested at most ${maxDepth} deep` });
|
|
208
|
+
return undefined;
|
|
209
|
+
}
|
|
210
|
+
const at = pointer(path, join);
|
|
211
|
+
const items = array(o[join], at, errors, 1, maxJoined);
|
|
212
|
+
if (items === undefined)
|
|
213
|
+
return undefined;
|
|
214
|
+
const read = items.map((item, i) => readCondition(item, pointer(at, i), errors, signs, depth + 1));
|
|
215
|
+
if (read.some((c) => c === undefined))
|
|
216
|
+
return undefined;
|
|
217
|
+
const conditions = read;
|
|
218
|
+
return join === "all" ? { all: conditions } : { any: conditions };
|
|
219
|
+
}
|
|
220
|
+
function readChoose(value, errors, groups) {
|
|
221
|
+
if (value === undefined)
|
|
222
|
+
return null;
|
|
223
|
+
const o = object(value, "/choose", errors, [], ["many", "from"]);
|
|
224
|
+
if (o === undefined)
|
|
225
|
+
return undefined;
|
|
226
|
+
if (o.many !== undefined && typeof o.many !== "boolean") {
|
|
227
|
+
errors.push({ path: "/choose/many", message: "true or false" });
|
|
228
|
+
}
|
|
229
|
+
const from = o.from === undefined
|
|
230
|
+
? [...groups]
|
|
231
|
+
: ids(o.from, "/choose/from", errors, groups, "a group of the scene", maxGroups);
|
|
232
|
+
if (from === undefined || (o.many !== undefined && typeof o.many !== "boolean")) {
|
|
233
|
+
return undefined;
|
|
234
|
+
}
|
|
235
|
+
return { many: o.many === true, from };
|
|
236
|
+
}
|
|
237
|
+
function readTable(value, errors, signs, groups) {
|
|
238
|
+
if (value === undefined)
|
|
239
|
+
return null;
|
|
240
|
+
const o = object(value, "/table", errors, ["columns"], ["rows"]);
|
|
241
|
+
if (o === undefined)
|
|
242
|
+
return undefined;
|
|
243
|
+
const rows = o.rows === undefined
|
|
244
|
+
? [...groups]
|
|
245
|
+
: ids(o.rows, "/table/rows", errors, groups, "a group of the scene", maxGroups);
|
|
246
|
+
const items = array(o.columns, "/table/columns", errors, 1, maxColumns);
|
|
247
|
+
const taken = new Set();
|
|
248
|
+
const columns = [];
|
|
249
|
+
items?.forEach((item, i) => {
|
|
250
|
+
const at = pointer("/table/columns", i);
|
|
251
|
+
const c = object(item, at, errors, ["id", "label", "sign"], ["is", "not"]);
|
|
252
|
+
if (c === undefined)
|
|
253
|
+
return;
|
|
254
|
+
const id = fresh(c.id, pointer(at, "id"), errors, nameId, "a column's ID", taken);
|
|
255
|
+
const named = label(c.label, pointer(at, "label"), errors);
|
|
256
|
+
const literal = readLiteral(c, at, errors, signs);
|
|
257
|
+
if (id !== undefined && named !== undefined && literal !== undefined) {
|
|
258
|
+
columns.push({ id, label: named, literal });
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
if (rows === undefined || items === undefined || columns.length !== items.length) {
|
|
262
|
+
return undefined;
|
|
263
|
+
}
|
|
264
|
+
return { rows, columns };
|
|
265
|
+
}
|
|
266
|
+
function readGoal(value, errors, signs, groups) {
|
|
267
|
+
if (value === undefined)
|
|
268
|
+
return null;
|
|
269
|
+
if (!isObject(value)) {
|
|
270
|
+
errors.push({ path: "/goal", message: "an object" });
|
|
271
|
+
return undefined;
|
|
272
|
+
}
|
|
273
|
+
const forms = ["signs", "like", "differs"].filter((form) => Object.hasOwn(value, form));
|
|
274
|
+
if (forms.length !== 1) {
|
|
275
|
+
errors.push({ path: "/goal", message: 'one of the members "signs", "like" and "differs"' });
|
|
276
|
+
return undefined;
|
|
277
|
+
}
|
|
278
|
+
const form = forms[0];
|
|
279
|
+
const o = object(value, "/goal", errors, [form], ["among"]);
|
|
280
|
+
if (o === undefined)
|
|
281
|
+
return undefined;
|
|
282
|
+
const known = new Set(groups.map((group) => group.id));
|
|
283
|
+
const at = pointer("/goal", form);
|
|
284
|
+
if (form === "signs") {
|
|
285
|
+
const condition = readCondition(o.signs, at, errors, signs, 1);
|
|
286
|
+
const among = readAmong(o.among, errors, known, undefined);
|
|
287
|
+
return condition === undefined || among === undefined ? undefined : { signs: condition, among };
|
|
288
|
+
}
|
|
289
|
+
if (form === "like") {
|
|
290
|
+
const group = groups.find((g) => g.id === o.like);
|
|
291
|
+
if (group === undefined) {
|
|
292
|
+
errors.push({ path: at, message: "a group of the scene" });
|
|
293
|
+
return undefined;
|
|
294
|
+
}
|
|
295
|
+
if (shared(group, signs).length === 0) {
|
|
296
|
+
errors.push({ path: at, message: "a group whose cards share a value of some sign" });
|
|
297
|
+
return undefined;
|
|
298
|
+
}
|
|
299
|
+
const among = readAmong(o.among, errors, known, group.id);
|
|
300
|
+
return among === undefined ? undefined : { like: group.id, among };
|
|
301
|
+
}
|
|
302
|
+
const named = ids(o.differs, at, errors, new Set(signs.map((sign) => sign.id)), "a sign of the scene", maxSigns);
|
|
303
|
+
const among = readAmong(o.among, errors, known, undefined);
|
|
304
|
+
return named === undefined || among === undefined ? undefined : { differs: named, among };
|
|
305
|
+
}
|
|
306
|
+
/** The groups a goal ranges over: those named, or every group but the one it learns from. */
|
|
307
|
+
function readAmong(value, errors, known, learnsFrom) {
|
|
308
|
+
if (value === undefined) {
|
|
309
|
+
const others = [...known].filter((id) => id !== learnsFrom);
|
|
310
|
+
if (others.length === 0) {
|
|
311
|
+
errors.push({ path: "/goal", message: "another group for the goal to range over" });
|
|
312
|
+
return undefined;
|
|
313
|
+
}
|
|
314
|
+
return others;
|
|
315
|
+
}
|
|
316
|
+
return ids(value, "/goal/among", errors, known, "a group of the scene", maxGroups);
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* The values every card of a group gives, as literals in the order of the scene's signs: the rule
|
|
320
|
+
* the group teaches.
|
|
321
|
+
*/
|
|
322
|
+
export function shared(group, signs) {
|
|
323
|
+
const rule = [];
|
|
324
|
+
for (const sign of signs) {
|
|
325
|
+
const first = group.cards[0]?.signs.get(sign.id);
|
|
326
|
+
if (first !== undefined && group.cards.every((card) => card.signs.get(sign.id) === first)) {
|
|
327
|
+
rule.push({ sign: sign.id, is: first });
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
return rule;
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* A scene read by the kind's schema, or every error it names: the taps, the table and the goal are
|
|
334
|
+
* read once the signs, the groups and the options are, against what they name.
|
|
335
|
+
*/
|
|
336
|
+
export function readScene(input) {
|
|
337
|
+
const errors = [];
|
|
338
|
+
const o = object(input, "", errors, ["signs", "groups"], ["options", "choose", "table", "goal"]);
|
|
339
|
+
if (o === undefined)
|
|
340
|
+
return { ok: false, errors };
|
|
341
|
+
const signs = readSigns(o.signs, errors);
|
|
342
|
+
const taken = new Set();
|
|
343
|
+
const groups = readGroups(o.groups, errors, signs, taken);
|
|
344
|
+
const options = readOptions(o.options, errors, taken);
|
|
345
|
+
if (signs === undefined || groups === undefined || errors.length > 0) {
|
|
346
|
+
return { ok: false, errors };
|
|
347
|
+
}
|
|
348
|
+
const known = new Set(groups.map((group) => group.id));
|
|
349
|
+
const choose = readChoose(o.choose, errors, known);
|
|
350
|
+
const table = readTable(o.table, errors, signs, known);
|
|
351
|
+
const goal = readGoal(o.goal, errors, signs, groups);
|
|
352
|
+
if (errors.length > 0 || choose === undefined || table === undefined || goal === undefined) {
|
|
353
|
+
return { ok: false, errors };
|
|
354
|
+
}
|
|
355
|
+
return { ok: true, scene: { signs, groups, options, choose, table, goal } };
|
|
356
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Json } from "../../cores/kind.js";
|
|
2
|
+
/** The version of the kind's schema: a new member a scene may give is its next minor version. */
|
|
3
|
+
export declare const version = "1.0";
|
|
4
|
+
/** The $id of the kind's schema at a version: a name, which need not resolve. */
|
|
5
|
+
export declare function schemaId(at: string): string;
|
|
6
|
+
type Schema = {
|
|
7
|
+
readonly [keyword: string]: Json;
|
|
8
|
+
};
|
|
9
|
+
export declare function cardsSchema(): Schema;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import { maxCards, maxColumns, maxGroups, maxJoined, maxLabel, maxOptions, maxSigns, maxText, maxValues, nameId, partId, } from "./scene.js";
|
|
2
|
+
/** The version of the kind's schema: a new member a scene may give is its next minor version. */
|
|
3
|
+
export const version = "1.0";
|
|
4
|
+
/** The $id of the kind's schema at a version: a name, which need not resolve. */
|
|
5
|
+
export function schemaId(at) {
|
|
6
|
+
return `https://altnovatrail.github.io/widgets/kinds/cards/${at}/cards.schema.json`;
|
|
7
|
+
}
|
|
8
|
+
const label = (description, max = maxLabel) => ({
|
|
9
|
+
description,
|
|
10
|
+
type: "string",
|
|
11
|
+
minLength: 1,
|
|
12
|
+
maxLength: max,
|
|
13
|
+
});
|
|
14
|
+
const groupIds = (description) => ({
|
|
15
|
+
description,
|
|
16
|
+
type: "array",
|
|
17
|
+
items: { description: "A group, by its ID.", $ref: "#/$defs/id" },
|
|
18
|
+
minItems: 1,
|
|
19
|
+
maxItems: maxGroups,
|
|
20
|
+
uniqueItems: true,
|
|
21
|
+
});
|
|
22
|
+
const sign = (description) => ({ description, $ref: "#/$defs/name" });
|
|
23
|
+
/** A sign and one of its values, as a literal of a condition and a column of the table give them. */
|
|
24
|
+
const literal = (what) => [
|
|
25
|
+
{
|
|
26
|
+
description: `${what} where a card gives the sign this value.`,
|
|
27
|
+
properties: {
|
|
28
|
+
sign: sign("The sign, by its ID."),
|
|
29
|
+
is: { description: "The value, by its ID.", $ref: "#/$defs/name" },
|
|
30
|
+
},
|
|
31
|
+
required: ["sign", "is"],
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
description: `${what} where a card gives the sign any value but this one.`,
|
|
35
|
+
properties: {
|
|
36
|
+
sign: sign("The sign, by its ID."),
|
|
37
|
+
not: { description: "The value, by its ID.", $ref: "#/$defs/name" },
|
|
38
|
+
},
|
|
39
|
+
required: ["sign", "not"],
|
|
40
|
+
},
|
|
41
|
+
];
|
|
42
|
+
const joined = (join, description) => ({
|
|
43
|
+
description,
|
|
44
|
+
properties: {
|
|
45
|
+
[join]: {
|
|
46
|
+
description: "The conditions joined.",
|
|
47
|
+
type: "array",
|
|
48
|
+
items: {
|
|
49
|
+
description: "A condition.",
|
|
50
|
+
$ref: "#/$defs/condition",
|
|
51
|
+
unevaluatedProperties: false,
|
|
52
|
+
},
|
|
53
|
+
minItems: 1,
|
|
54
|
+
maxItems: maxJoined,
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
required: [join],
|
|
58
|
+
});
|
|
59
|
+
export function cardsSchema() {
|
|
60
|
+
return {
|
|
61
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
62
|
+
$id: schemaId(version),
|
|
63
|
+
title: "A scene of the widget kind cards",
|
|
64
|
+
description: "Cards in groups, each giving a value to every sign the scene names; options to choose among; how a tap chooses; a table of signs, its rows the cards and its columns conditions of signs; and at most one goal, whose answer is the cards that meet it. Under $defs, a move and a state of the kind, and the form of a scene's key.",
|
|
65
|
+
type: "object",
|
|
66
|
+
properties: {
|
|
67
|
+
signs: {
|
|
68
|
+
description: "The signs the cards give values to, each with its values: a colour, a pattern, eyes, a hat, or any other the scene names.",
|
|
69
|
+
type: "array",
|
|
70
|
+
items: {
|
|
71
|
+
description: "A sign.",
|
|
72
|
+
$ref: "#/$defs/sign",
|
|
73
|
+
unevaluatedProperties: false,
|
|
74
|
+
},
|
|
75
|
+
minItems: 1,
|
|
76
|
+
maxItems: maxSigns,
|
|
77
|
+
},
|
|
78
|
+
groups: {
|
|
79
|
+
description: "The groups of cards, in the order they are drawn: the examples a goal learns from, the cards to choose among, the cards to mark with the pen.",
|
|
80
|
+
type: "array",
|
|
81
|
+
items: {
|
|
82
|
+
description: "A group.",
|
|
83
|
+
$ref: "#/$defs/group",
|
|
84
|
+
unevaluatedProperties: false,
|
|
85
|
+
},
|
|
86
|
+
minItems: 1,
|
|
87
|
+
maxItems: maxGroups,
|
|
88
|
+
},
|
|
89
|
+
options: {
|
|
90
|
+
description: "Options to choose among that are no cards, each a label, as an answer that the learner does not know yet; a tap chooses them wherever the scene lets a tap choose.",
|
|
91
|
+
type: "array",
|
|
92
|
+
items: {
|
|
93
|
+
description: "An option.",
|
|
94
|
+
type: "object",
|
|
95
|
+
properties: {
|
|
96
|
+
id: { description: "The option's ID, its part's.", $ref: "#/$defs/id" },
|
|
97
|
+
label: label("The option's words."),
|
|
98
|
+
},
|
|
99
|
+
required: ["id", "label"],
|
|
100
|
+
unevaluatedProperties: false,
|
|
101
|
+
},
|
|
102
|
+
minItems: 1,
|
|
103
|
+
maxItems: maxOptions,
|
|
104
|
+
},
|
|
105
|
+
choose: {
|
|
106
|
+
description: "How a tap chooses, where it does: none where left out, a scene only to look at and mark with the pen.",
|
|
107
|
+
type: "object",
|
|
108
|
+
properties: {
|
|
109
|
+
many: {
|
|
110
|
+
description: "Whether a tap adds to what is chosen; where false or left out, a tap chooses one and lets the one before go.",
|
|
111
|
+
type: "boolean",
|
|
112
|
+
},
|
|
113
|
+
from: groupIds("The groups whose cards a tap chooses; every group where left out. The options are chosen whatever it names."),
|
|
114
|
+
},
|
|
115
|
+
unevaluatedProperties: false,
|
|
116
|
+
},
|
|
117
|
+
table: {
|
|
118
|
+
description: "The table of signs: a row for each card of the groups named, a column for each condition, and an empty cell where they cross, for the pen to tick or cross. A tap fills no cell.",
|
|
119
|
+
type: "object",
|
|
120
|
+
properties: {
|
|
121
|
+
rows: groupIds("The groups whose cards are the rows; every group where left out."),
|
|
122
|
+
columns: {
|
|
123
|
+
description: "The columns, in order.",
|
|
124
|
+
type: "array",
|
|
125
|
+
items: {
|
|
126
|
+
description: "A column: its ID, its heading and the condition it asks of a card.",
|
|
127
|
+
type: "object",
|
|
128
|
+
properties: {
|
|
129
|
+
id: { description: "The column's ID.", $ref: "#/$defs/name" },
|
|
130
|
+
label: label("The column's heading, as horns or no hat."),
|
|
131
|
+
},
|
|
132
|
+
required: ["id", "label"],
|
|
133
|
+
oneOf: literal("A column that holds"),
|
|
134
|
+
unevaluatedProperties: false,
|
|
135
|
+
},
|
|
136
|
+
minItems: 1,
|
|
137
|
+
maxItems: maxColumns,
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
required: ["columns"],
|
|
141
|
+
unevaluatedProperties: false,
|
|
142
|
+
},
|
|
143
|
+
goal: {
|
|
144
|
+
description: "What a card is to meet, over the cards of the groups it ranges over: a condition of signs, the values every card of a group shares, or a difference from every other card by the signs named. The answer is the cards that meet it, and a state meets the goal where it holds them chosen.",
|
|
145
|
+
type: "object",
|
|
146
|
+
properties: {
|
|
147
|
+
signs: {
|
|
148
|
+
description: "A condition of signs, which a card meets.",
|
|
149
|
+
$ref: "#/$defs/condition",
|
|
150
|
+
unevaluatedProperties: false,
|
|
151
|
+
},
|
|
152
|
+
like: {
|
|
153
|
+
description: "A group, by its ID, whose cards' shared values a card must give, every one: the group teaches its rule by example.",
|
|
154
|
+
$ref: "#/$defs/id",
|
|
155
|
+
},
|
|
156
|
+
differs: {
|
|
157
|
+
description: "The signs a card must differ by from every other card of the range, at least one of them for each other card: the odd one out by those signs, the others left out.",
|
|
158
|
+
type: "array",
|
|
159
|
+
items: sign("A sign, by its ID."),
|
|
160
|
+
minItems: 1,
|
|
161
|
+
maxItems: maxSigns,
|
|
162
|
+
uniqueItems: true,
|
|
163
|
+
},
|
|
164
|
+
among: groupIds("The groups whose cards the goal ranges over; where left out, every group but the one it learns from."),
|
|
165
|
+
},
|
|
166
|
+
oneOf: ["signs", "like", "differs"].map((form) => ({
|
|
167
|
+
description: `A goal of the form ${form}.`,
|
|
168
|
+
properties: { [form]: { description: `The goal's ${form}.` } },
|
|
169
|
+
required: [form],
|
|
170
|
+
})),
|
|
171
|
+
unevaluatedProperties: false,
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
required: ["signs", "groups"],
|
|
175
|
+
unevaluatedProperties: false,
|
|
176
|
+
$defs: {
|
|
177
|
+
id: {
|
|
178
|
+
description: "The ID of a card, a group or an option, the ID of its part: each once in the scene.",
|
|
179
|
+
type: "string",
|
|
180
|
+
pattern: partId.source,
|
|
181
|
+
},
|
|
182
|
+
name: {
|
|
183
|
+
description: "The ID of a sign, a value or a column, in kebab-case.",
|
|
184
|
+
type: "string",
|
|
185
|
+
pattern: nameId.source,
|
|
186
|
+
},
|
|
187
|
+
sign: {
|
|
188
|
+
description: "A sign, its label and its values.",
|
|
189
|
+
type: "object",
|
|
190
|
+
properties: {
|
|
191
|
+
id: { description: "The sign's ID, each once in the scene.", $ref: "#/$defs/name" },
|
|
192
|
+
label: label("The sign's name, as colour."),
|
|
193
|
+
values: {
|
|
194
|
+
description: "The values a card may give the sign.",
|
|
195
|
+
type: "array",
|
|
196
|
+
items: {
|
|
197
|
+
description: "A value.",
|
|
198
|
+
type: "object",
|
|
199
|
+
properties: {
|
|
200
|
+
id: { description: "The value's ID, each once in its sign.", $ref: "#/$defs/name" },
|
|
201
|
+
label: label("The value's words, as blue or two eyes."),
|
|
202
|
+
},
|
|
203
|
+
required: ["id", "label"],
|
|
204
|
+
unevaluatedProperties: false,
|
|
205
|
+
},
|
|
206
|
+
minItems: 1,
|
|
207
|
+
maxItems: maxValues,
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
required: ["id", "label", "values"],
|
|
211
|
+
},
|
|
212
|
+
card: {
|
|
213
|
+
description: "A card: a creature drawn from its signs, or the card of a task, its statement's text.",
|
|
214
|
+
type: "object",
|
|
215
|
+
properties: {
|
|
216
|
+
id: { description: "The card's ID, its part's.", $ref: "#/$defs/id" },
|
|
217
|
+
text: label("The statement of a task, drawn in place of a creature.", maxText),
|
|
218
|
+
signs: {
|
|
219
|
+
description: "The value the card gives each sign of the scene, every one, by its ID.",
|
|
220
|
+
type: "object",
|
|
221
|
+
propertyNames: { description: "A sign's ID.", $ref: "#/$defs/name" },
|
|
222
|
+
additionalProperties: { description: "The value's ID.", $ref: "#/$defs/name" },
|
|
223
|
+
},
|
|
224
|
+
},
|
|
225
|
+
required: ["id", "signs"],
|
|
226
|
+
},
|
|
227
|
+
group: {
|
|
228
|
+
description: "A group of cards, with its heading where it has one.",
|
|
229
|
+
type: "object",
|
|
230
|
+
properties: {
|
|
231
|
+
id: { description: "The group's ID, its part's.", $ref: "#/$defs/id" },
|
|
232
|
+
label: label("The group's heading, as Bips."),
|
|
233
|
+
cards: {
|
|
234
|
+
description: "The group's cards, in the order they are drawn.",
|
|
235
|
+
type: "array",
|
|
236
|
+
items: {
|
|
237
|
+
description: "A card.",
|
|
238
|
+
$ref: "#/$defs/card",
|
|
239
|
+
unevaluatedProperties: false,
|
|
240
|
+
},
|
|
241
|
+
minItems: 1,
|
|
242
|
+
maxItems: maxCards,
|
|
243
|
+
},
|
|
244
|
+
},
|
|
245
|
+
required: ["id", "cards"],
|
|
246
|
+
},
|
|
247
|
+
condition: {
|
|
248
|
+
description: "A condition of signs: a sign has a value, or any other; or conditions joined, all of them or any.",
|
|
249
|
+
type: "object",
|
|
250
|
+
oneOf: [
|
|
251
|
+
...literal("A literal that holds"),
|
|
252
|
+
joined("all", "Every condition holds."),
|
|
253
|
+
joined("any", "At least one condition holds."),
|
|
254
|
+
],
|
|
255
|
+
},
|
|
256
|
+
move: {
|
|
257
|
+
description: "A tap on a card or an option, by its ID.",
|
|
258
|
+
type: "object",
|
|
259
|
+
properties: {
|
|
260
|
+
choose: { description: "The card or the option, by its ID.", $ref: "#/$defs/id" },
|
|
261
|
+
},
|
|
262
|
+
required: ["choose"],
|
|
263
|
+
},
|
|
264
|
+
state: {
|
|
265
|
+
description: "What is chosen.",
|
|
266
|
+
type: "object",
|
|
267
|
+
properties: {
|
|
268
|
+
chosen: {
|
|
269
|
+
description: "The cards and options chosen, by their IDs sorted by UTF-16 code units.",
|
|
270
|
+
type: "array",
|
|
271
|
+
items: { description: "A card or an option, by its ID.", $ref: "#/$defs/id" },
|
|
272
|
+
uniqueItems: true,
|
|
273
|
+
},
|
|
274
|
+
},
|
|
275
|
+
required: ["chosen"],
|
|
276
|
+
},
|
|
277
|
+
key: {
|
|
278
|
+
description: "The key of a scene, the form of the kind solver's proof: the IDs of the cards that meet the goal, sorted by UTF-16 code units, each once; none where no card meets it.",
|
|
279
|
+
type: "array",
|
|
280
|
+
items: { description: "A card, by its ID.", $ref: "#/$defs/id" },
|
|
281
|
+
uniqueItems: true,
|
|
282
|
+
},
|
|
283
|
+
},
|
|
284
|
+
};
|
|
285
|
+
}
|