@g9tm/lynxcontrols-foundation 1.4.7 → 1.5.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/dist/.tsbuildinfo +1 -1
- package/dist/culture/strings.d.ts +2 -0
- package/dist/culture/strings.d.ts.map +1 -1
- package/dist/culture/strings.js +8 -4
- package/dist/culture/strings.js.map +1 -1
- package/dist/enums/index.d.ts +5 -1
- package/dist/enums/index.d.ts.map +1 -1
- package/dist/enums/index.js +2 -1
- package/dist/enums/index.js.map +1 -1
- package/dist/icons/generated/glyph-svg.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/route/address.d.ts +68 -0
- package/dist/route/address.d.ts.map +1 -0
- package/dist/route/address.js +282 -0
- package/dist/route/address.js.map +1 -0
- package/dist/route/catalogue.d.ts +131 -0
- package/dist/route/catalogue.d.ts.map +1 -0
- package/dist/route/catalogue.js +236 -0
- package/dist/route/catalogue.js.map +1 -0
- package/dist/route/index.d.ts +7 -0
- package/dist/route/index.d.ts.map +1 -0
- package/dist/route/index.js +6 -0
- package/dist/route/journey.d.ts +147 -0
- package/dist/route/journey.d.ts.map +1 -0
- package/dist/route/journey.js +345 -0
- package/dist/route/journey.js.map +1 -0
- package/dist/route/resolve.d.ts +43 -0
- package/dist/route/resolve.d.ts.map +1 -0
- package/dist/route/resolve.js +116 -0
- package/dist/route/resolve.js.map +1 -0
- package/dist/route/sink.d.ts +62 -0
- package/dist/route/sink.d.ts.map +1 -0
- package/dist/route/sink.js +11 -0
- package/dist/route/sink.js.map +1 -0
- package/dist/route/view.d.ts +60 -0
- package/dist/route/view.d.ts.map +1 -0
- package/dist/route/view.js +104 -0
- package/dist/route/view.js.map +1 -0
- package/dist/services/contracts.d.ts +6 -0
- package/dist/services/contracts.d.ts.map +1 -1
- package/dist/services/contracts.js.map +1 -1
- package/dist/tokens/generated/metrics.d.ts +4 -0
- package/dist/tokens/generated/metrics.d.ts.map +1 -1
- package/dist/tokens/generated/metrics.js +8 -0
- package/dist/tokens/generated/metrics.js.map +1 -1
- package/dist/tokens/generated/palettes.js.map +1 -1
- package/docs/api.md +72 -1
- package/docs/migration/Core.Controls.Shared.md +5 -0
- package/docs/migration/Core.Localization.md +1 -0
- package/package.json +6 -1
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
import { tryParseAddress } from "./address.js";
|
|
2
|
+
const g9JourneyLimits = Object.freeze({
|
|
3
|
+
steps: 40,
|
|
4
|
+
text: 240,
|
|
5
|
+
value: 512,
|
|
6
|
+
id: 64,
|
|
7
|
+
effects: 6,
|
|
8
|
+
waitMs: 120000
|
|
9
|
+
});
|
|
10
|
+
const SOURCES = [
|
|
11
|
+
'bundled',
|
|
12
|
+
'assistant',
|
|
13
|
+
'link',
|
|
14
|
+
'tester',
|
|
15
|
+
'qa'
|
|
16
|
+
];
|
|
17
|
+
const ANCHOR = /^[A-Za-z0-9._-]{1,128}$/;
|
|
18
|
+
const JOURNEY_ID = /^[A-Za-z0-9._-]{1,64}$/;
|
|
19
|
+
const CONTROL = /[\u0000-\u0008\u000b-\u001f\u007f-\u009f]/;
|
|
20
|
+
class Invalid extends Error {
|
|
21
|
+
}
|
|
22
|
+
function obj(x, what, keys) {
|
|
23
|
+
if (!x || 'object' != typeof x || Array.isArray(x)) throw new Invalid(`${what} is not an object.`);
|
|
24
|
+
for (const k of Object.keys(x))if (keys.indexOf(k) < 0) throw new Invalid(`${what} has an unknown key "${k}".`);
|
|
25
|
+
return x;
|
|
26
|
+
}
|
|
27
|
+
function journey_text(x, what, required) {
|
|
28
|
+
if (void 0 === x && !required) return;
|
|
29
|
+
const one = (s, w)=>{
|
|
30
|
+
if ('string' != typeof s || '' === s.trim() || s.length > g9JourneyLimits.text || CONTROL.test(s)) throw new Invalid(`${w} must be text of 1–${g9JourneyLimits.text} characters.`);
|
|
31
|
+
};
|
|
32
|
+
if ('string' == typeof x) return void one(x, what);
|
|
33
|
+
const t = obj(x, what, [
|
|
34
|
+
'fa',
|
|
35
|
+
'en'
|
|
36
|
+
]);
|
|
37
|
+
one(t.fa, `${what}.fa`);
|
|
38
|
+
one(t.en, `${what}.en`);
|
|
39
|
+
}
|
|
40
|
+
function journey_anchor(x, what) {
|
|
41
|
+
if ('string' != typeof x || !ANCHOR.test(x)) throw new Invalid(`${what} must be an anchor id.`);
|
|
42
|
+
}
|
|
43
|
+
function route(x, what) {
|
|
44
|
+
if ('string' != typeof x || !tryParseAddress(x).ok) throw new Invalid(`${what} must be an address.`);
|
|
45
|
+
}
|
|
46
|
+
function oneOf(x, values, what, required = false) {
|
|
47
|
+
if (void 0 === x && !required) return;
|
|
48
|
+
if ('string' != typeof x || values.indexOf(x) < 0) throw new Invalid(`${what} must be one of ${values.join(', ')}.`);
|
|
49
|
+
}
|
|
50
|
+
function ms(x, what) {
|
|
51
|
+
if (void 0 === x) return;
|
|
52
|
+
if ('number' != typeof x || !Number.isFinite(x) || x < 0 || x > g9JourneyLimits.waitMs) throw new Invalid(`${what} must be 0–${g9JourneyLimits.waitMs} ms.`);
|
|
53
|
+
}
|
|
54
|
+
function valueCheck(x, what) {
|
|
55
|
+
const v = obj(x, what, [
|
|
56
|
+
'target',
|
|
57
|
+
'equals'
|
|
58
|
+
]);
|
|
59
|
+
journey_anchor(v.target, `${what}.target`);
|
|
60
|
+
if (void 0 !== v.equals && ('string' != typeof v.equals || v.equals.length > g9JourneyLimits.value)) throw new Invalid(`${what}.equals is too long.`);
|
|
61
|
+
}
|
|
62
|
+
function until(x, what) {
|
|
63
|
+
if (void 0 === x || 'tap' === x || 'next' === x) return;
|
|
64
|
+
const u = obj(x, what, [
|
|
65
|
+
'ms',
|
|
66
|
+
'route',
|
|
67
|
+
'value'
|
|
68
|
+
]);
|
|
69
|
+
const keys = Object.keys(u);
|
|
70
|
+
if (1 !== keys.length) throw new Invalid(`${what} names exactly one condition.`);
|
|
71
|
+
if (void 0 !== u.ms) ms(u.ms, `${what}.ms`);
|
|
72
|
+
if (void 0 !== u.route) route(u.route, `${what}.route`);
|
|
73
|
+
if (void 0 !== u.value) valueCheck(u.value, `${what}.value`);
|
|
74
|
+
}
|
|
75
|
+
const EFFECT_KEYS = {
|
|
76
|
+
highlight: [
|
|
77
|
+
'type',
|
|
78
|
+
'color',
|
|
79
|
+
'opacity',
|
|
80
|
+
'ring',
|
|
81
|
+
'padding',
|
|
82
|
+
'radius',
|
|
83
|
+
'pulse'
|
|
84
|
+
],
|
|
85
|
+
spotlight: [
|
|
86
|
+
'type',
|
|
87
|
+
'scrim',
|
|
88
|
+
'padding',
|
|
89
|
+
'radius',
|
|
90
|
+
'modal'
|
|
91
|
+
],
|
|
92
|
+
pointer: [
|
|
93
|
+
'type',
|
|
94
|
+
'gesture'
|
|
95
|
+
],
|
|
96
|
+
caption: [
|
|
97
|
+
'type',
|
|
98
|
+
'text',
|
|
99
|
+
'title',
|
|
100
|
+
'placement'
|
|
101
|
+
],
|
|
102
|
+
beacon: [
|
|
103
|
+
'type',
|
|
104
|
+
'corner',
|
|
105
|
+
'color'
|
|
106
|
+
],
|
|
107
|
+
badge: [
|
|
108
|
+
'type',
|
|
109
|
+
'text'
|
|
110
|
+
],
|
|
111
|
+
ripple: [
|
|
112
|
+
'type'
|
|
113
|
+
]
|
|
114
|
+
};
|
|
115
|
+
const COLOR = /^#[0-9A-Fa-f]{6}([0-9A-Fa-f]{2})?$/;
|
|
116
|
+
function effects(x, what) {
|
|
117
|
+
if (void 0 === x) return;
|
|
118
|
+
if (!Array.isArray(x) || x.length > g9JourneyLimits.effects) throw new Invalid(`${what} must be a list of at most ${g9JourneyLimits.effects} effects.`);
|
|
119
|
+
x.forEach((e, i)=>{
|
|
120
|
+
const w = `${what}[${i}]`;
|
|
121
|
+
const type = null == e ? void 0 : e.type;
|
|
122
|
+
const keys = 'string' == typeof type ? EFFECT_KEYS[type] : void 0;
|
|
123
|
+
if (!keys) throw new Invalid(`${w} has an unknown type.`);
|
|
124
|
+
const f = obj(e, w, keys);
|
|
125
|
+
for (const k of [
|
|
126
|
+
'color',
|
|
127
|
+
'scrim'
|
|
128
|
+
])if (void 0 !== f[k] && ('string' != typeof f[k] || !COLOR.test(f[k]))) throw new Invalid(`${w}.${k} must be #RRGGBB(AA).`);
|
|
129
|
+
for (const k of [
|
|
130
|
+
'opacity'
|
|
131
|
+
])if (void 0 !== f[k] && ('number' != typeof f[k] || f[k] < 0 || f[k] > 1)) throw new Invalid(`${w}.${k} must be 0–1.`);
|
|
132
|
+
for (const k of [
|
|
133
|
+
'ring',
|
|
134
|
+
'padding'
|
|
135
|
+
])if (void 0 !== f[k] && ('number' != typeof f[k] || f[k] < 0 || f[k] > 48)) throw new Invalid(`${w}.${k} must be 0–48.`);
|
|
136
|
+
if (void 0 !== f.radius && 'auto' !== f.radius && ('number' != typeof f.radius || f.radius < 0 || f.radius > 200)) throw new Invalid(`${w}.radius must be "auto" or 0–200.`);
|
|
137
|
+
for (const k of [
|
|
138
|
+
'pulse',
|
|
139
|
+
'modal'
|
|
140
|
+
])if (void 0 !== f[k] && 'boolean' != typeof f[k]) throw new Invalid(`${w}.${k} must be true or false.`);
|
|
141
|
+
if ('pointer' === type) oneOf(f.gesture, [
|
|
142
|
+
'tap',
|
|
143
|
+
'longPress',
|
|
144
|
+
'swipeUp',
|
|
145
|
+
'swipeDown',
|
|
146
|
+
'swipeStart',
|
|
147
|
+
'swipeEnd'
|
|
148
|
+
], `${w}.gesture`);
|
|
149
|
+
if ('caption' === type) {
|
|
150
|
+
journey_text(f.text, `${w}.text`, true);
|
|
151
|
+
journey_text(f.title, `${w}.title`, false);
|
|
152
|
+
oneOf(f.placement, [
|
|
153
|
+
'auto',
|
|
154
|
+
'above',
|
|
155
|
+
'below',
|
|
156
|
+
'start',
|
|
157
|
+
'end'
|
|
158
|
+
], `${w}.placement`);
|
|
159
|
+
}
|
|
160
|
+
if ('beacon' === type) oneOf(f.corner, [
|
|
161
|
+
'top-start',
|
|
162
|
+
'top-end',
|
|
163
|
+
'bottom-start',
|
|
164
|
+
'bottom-end'
|
|
165
|
+
], `${w}.corner`);
|
|
166
|
+
if ('badge' === type && ('string' != typeof f.text || 0 === f.text.length || f.text.length > 4)) throw new Invalid(`${w}.text must be 1–4 characters.`);
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
function step(x, i) {
|
|
170
|
+
const w = `steps[${i}]`;
|
|
171
|
+
const kind = null == x ? void 0 : x.do;
|
|
172
|
+
switch(kind){
|
|
173
|
+
case 'go':
|
|
174
|
+
{
|
|
175
|
+
const s = obj(x, w, [
|
|
176
|
+
'do',
|
|
177
|
+
'to',
|
|
178
|
+
'by'
|
|
179
|
+
]);
|
|
180
|
+
route(s.to, `${w}.to`);
|
|
181
|
+
oneOf(s.by, [
|
|
182
|
+
'jump',
|
|
183
|
+
'user',
|
|
184
|
+
'demo'
|
|
185
|
+
], `${w}.by`);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
case 'show':
|
|
189
|
+
{
|
|
190
|
+
const s = obj(x, w, [
|
|
191
|
+
'do',
|
|
192
|
+
'target',
|
|
193
|
+
'text',
|
|
194
|
+
'effects',
|
|
195
|
+
'until'
|
|
196
|
+
]);
|
|
197
|
+
journey_anchor(s.target, `${w}.target`);
|
|
198
|
+
journey_text(s.text, `${w}.text`, false);
|
|
199
|
+
effects(s.effects, `${w}.effects`);
|
|
200
|
+
until(s.until, `${w}.until`);
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
case 'say':
|
|
204
|
+
{
|
|
205
|
+
const s = obj(x, w, [
|
|
206
|
+
'do',
|
|
207
|
+
'text',
|
|
208
|
+
'until'
|
|
209
|
+
]);
|
|
210
|
+
journey_text(s.text, `${w}.text`, true);
|
|
211
|
+
until(s.until, `${w}.until`);
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
case 'fill':
|
|
215
|
+
{
|
|
216
|
+
const s = obj(x, w, [
|
|
217
|
+
'do',
|
|
218
|
+
'target',
|
|
219
|
+
'value',
|
|
220
|
+
'by'
|
|
221
|
+
]);
|
|
222
|
+
journey_anchor(s.target, `${w}.target`);
|
|
223
|
+
if ('string' != typeof s.value || s.value.length > g9JourneyLimits.value || CONTROL.test(s.value)) throw new Invalid(`${w}.value must be text of at most ${g9JourneyLimits.value} characters.`);
|
|
224
|
+
oneOf(s.by, [
|
|
225
|
+
'user',
|
|
226
|
+
'engine'
|
|
227
|
+
], `${w}.by`);
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
case 'select':
|
|
231
|
+
{
|
|
232
|
+
const s = obj(x, w, [
|
|
233
|
+
'do',
|
|
234
|
+
'target',
|
|
235
|
+
'item',
|
|
236
|
+
'by'
|
|
237
|
+
]);
|
|
238
|
+
journey_anchor(s.target, `${w}.target`);
|
|
239
|
+
if ('string' != typeof s.item || '' === s.item || s.item.length > 128) throw new Invalid(`${w}.item must be an item key.`);
|
|
240
|
+
oneOf(s.by, [
|
|
241
|
+
'user',
|
|
242
|
+
'engine'
|
|
243
|
+
], `${w}.by`);
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
case 'press':
|
|
247
|
+
{
|
|
248
|
+
const s = obj(x, w, [
|
|
249
|
+
'do',
|
|
250
|
+
'target',
|
|
251
|
+
'by',
|
|
252
|
+
'text'
|
|
253
|
+
]);
|
|
254
|
+
journey_anchor(s.target, `${w}.target`);
|
|
255
|
+
oneOf(s.by, [
|
|
256
|
+
'user',
|
|
257
|
+
'engine'
|
|
258
|
+
], `${w}.by`);
|
|
259
|
+
journey_text(s.text, `${w}.text`, false);
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
case 'wait':
|
|
263
|
+
{
|
|
264
|
+
const s = obj(x, w, [
|
|
265
|
+
'do',
|
|
266
|
+
'for',
|
|
267
|
+
'timeoutMs'
|
|
268
|
+
]);
|
|
269
|
+
const f = obj(s.for, `${w}.for`, [
|
|
270
|
+
'route',
|
|
271
|
+
'anchor',
|
|
272
|
+
'value',
|
|
273
|
+
'ms'
|
|
274
|
+
]);
|
|
275
|
+
if (0 === Object.keys(f).length) throw new Invalid(`${w}.for names nothing to wait for.`);
|
|
276
|
+
if (void 0 !== f.route) route(f.route, `${w}.for.route`);
|
|
277
|
+
if (void 0 !== f.anchor) journey_anchor(f.anchor, `${w}.for.anchor`);
|
|
278
|
+
if (void 0 !== f.value) valueCheck(f.value, `${w}.for.value`);
|
|
279
|
+
ms(f.ms, `${w}.for.ms`);
|
|
280
|
+
ms(s.timeoutMs, `${w}.timeoutMs`);
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
case 'back':
|
|
284
|
+
obj(x, w, [
|
|
285
|
+
'do'
|
|
286
|
+
]);
|
|
287
|
+
return;
|
|
288
|
+
default:
|
|
289
|
+
throw new Invalid(`${w} has an unknown "do".`);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
function validateJourney(x) {
|
|
293
|
+
try {
|
|
294
|
+
const j = obj(x, 'The journey', [
|
|
295
|
+
'id',
|
|
296
|
+
'title',
|
|
297
|
+
'source',
|
|
298
|
+
'pace',
|
|
299
|
+
'steps'
|
|
300
|
+
]);
|
|
301
|
+
if ('string' != typeof j.id || !JOURNEY_ID.test(j.id)) throw new Invalid('The journey id must be 1–64 of [A-Za-z0-9._-].');
|
|
302
|
+
journey_text(j.title, 'The title', false);
|
|
303
|
+
oneOf(j.source, SOURCES, 'The source', true);
|
|
304
|
+
oneOf(j.pace, [
|
|
305
|
+
'auto',
|
|
306
|
+
'manual'
|
|
307
|
+
], 'The pace');
|
|
308
|
+
if (!Array.isArray(j.steps) || 0 === j.steps.length || j.steps.length > g9JourneyLimits.steps) throw new Invalid(`A journey has 1–${g9JourneyLimits.steps} steps.`);
|
|
309
|
+
j.steps.forEach(step);
|
|
310
|
+
return {
|
|
311
|
+
ok: true,
|
|
312
|
+
journey: x
|
|
313
|
+
};
|
|
314
|
+
} catch (error) {
|
|
315
|
+
if (error instanceof Invalid) return {
|
|
316
|
+
ok: false,
|
|
317
|
+
error: error.message
|
|
318
|
+
};
|
|
319
|
+
throw error;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
function journeyAuthority(source, action, risk = 'none') {
|
|
323
|
+
if ('press' !== action || 'none' === risk) return 'engine';
|
|
324
|
+
if ('qa' === source) return 'engine';
|
|
325
|
+
if ('tester' === source) return 'user';
|
|
326
|
+
return 'engine-confirm';
|
|
327
|
+
}
|
|
328
|
+
const g9ConfirmTimingDefaults = Object.freeze({
|
|
329
|
+
commitSeconds: 5,
|
|
330
|
+
destructiveSeconds: 10,
|
|
331
|
+
linkExtraSeconds: 3,
|
|
332
|
+
undescribedFactor: 2
|
|
333
|
+
});
|
|
334
|
+
function confirmSeconds(source, risk, described, timing = g9ConfirmTimingDefaults) {
|
|
335
|
+
let s = 'destructive' === risk ? timing.destructiveSeconds : timing.commitSeconds;
|
|
336
|
+
if ('link' === source) s += timing.linkExtraSeconds;
|
|
337
|
+
if (!described) s *= timing.undescribedFactor;
|
|
338
|
+
return Math.max(1, Math.round(s));
|
|
339
|
+
}
|
|
340
|
+
function textIn(t, language) {
|
|
341
|
+
return 'string' == typeof t ? t : t[language];
|
|
342
|
+
}
|
|
343
|
+
export { confirmSeconds, g9ConfirmTimingDefaults, g9JourneyLimits, journeyAuthority, textIn, validateJourney };
|
|
344
|
+
|
|
345
|
+
//# sourceMappingURL=journey.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route/journey.js","sources":["../../src/route/journey.ts"],"sourcesContent":["import { tryParseAddress } from './address';\nimport type { G9BilingualText } from './catalogue';\n\n// A journey: steps a guide runs on screen — go somewhere, show a control, say something, fill a field, pick an item,\n// press a button, wait, come back. Plain JSON, so an assistant, a link or a server can author one; validated strictly\n// before it runs. Who may do what is the SOURCE POLICY below: a person can do everything their permissions allow, and\n// so can a journey — but a save or a delete the ENGINE presses always shows what will change and waits for the\n// person's confirmation behind a countdown (owner, 2026-11-12). Fill / select only change a form, never save.\n\n/** Who authored a journey. The runner uses the CALLER's source, never the journey's own claim. */\nexport type G9JourneySource = 'bundled' | 'assistant' | 'link' | 'tester' | 'qa';\n\n/** What pressing a control does to data. */\nexport type G9AnchorRisk = 'none' | 'commit' | 'destructive';\n\n/** Text in one language or both. */\nexport type G9Text = string | G9BilingualText;\n\n/** One visual effect of a journey step (JSON-safe; the guide draws it). */\nexport type G9GuideEffectSpec =\n | {\n readonly type: 'highlight';\n readonly color?: string;\n readonly opacity?: number;\n readonly ring?: number;\n readonly padding?: number;\n readonly radius?: 'auto' | number;\n readonly pulse?: boolean;\n }\n | {\n readonly type: 'spotlight';\n readonly scrim?: string;\n readonly padding?: number;\n readonly radius?: 'auto' | number;\n readonly modal?: boolean;\n }\n | {\n readonly type: 'pointer';\n readonly gesture?: 'tap' | 'longPress' | 'swipeUp' | 'swipeDown' | 'swipeStart' | 'swipeEnd';\n }\n | {\n readonly type: 'caption';\n readonly text: G9Text;\n readonly title?: G9Text;\n readonly placement?: 'auto' | 'above' | 'below' | 'start' | 'end';\n }\n | {\n readonly type: 'beacon';\n readonly corner?: 'top-start' | 'top-end' | 'bottom-start' | 'bottom-end';\n readonly color?: string;\n }\n | { readonly type: 'badge'; readonly text: string }\n | { readonly type: 'ripple' };\n\n/** When a show / say step moves on. */\nexport type G9Until =\n | 'tap'\n | 'next'\n | { readonly ms: number }\n | { readonly route: string }\n | { readonly value: { readonly target: string; readonly equals?: string } };\n\n/** What a wait step waits for (any one of them). */\nexport interface G9WaitFor {\n readonly route?: string;\n readonly anchor?: string;\n readonly value?: { readonly target: string; readonly equals?: string };\n readonly ms?: number;\n}\n\n/** One step of a journey. */\nexport type G9JourneyStep =\n | { readonly do: 'go'; readonly to: string; readonly by?: 'jump' | 'user' | 'demo' }\n | {\n readonly do: 'show';\n readonly target: string;\n readonly text?: G9Text;\n readonly effects?: readonly G9GuideEffectSpec[];\n readonly until?: G9Until;\n }\n | { readonly do: 'say'; readonly text: G9Text; readonly until?: G9Until }\n | { readonly do: 'fill'; readonly target: string; readonly value: string; readonly by?: 'user' | 'engine' }\n | { readonly do: 'select'; readonly target: string; readonly item: string; readonly by?: 'user' | 'engine' }\n | { readonly do: 'press'; readonly target: string; readonly by?: 'user' | 'engine'; readonly text?: G9Text }\n | { readonly do: 'wait'; readonly for: G9WaitFor; readonly timeoutMs?: number }\n | { readonly do: 'back' };\n\n/** A journey: validated JSON steps a guide runs on screen. */\nexport interface G9Journey {\n readonly id: string;\n readonly title?: G9Text;\n readonly source: G9JourneySource;\n /** `auto` runs through; `manual` waits for «بعدی» at every step. Default `auto`. */\n readonly pace?: 'auto' | 'manual';\n readonly steps: readonly G9JourneyStep[];\n}\n\n/** The bounds of a journey. */\nexport const g9JourneyLimits = Object.freeze({ steps: 40, text: 240, value: 512, id: 64, effects: 6, waitMs: 120000 });\n\nconst SOURCES: readonly G9JourneySource[] = ['bundled', 'assistant', 'link', 'tester', 'qa'];\nconst ANCHOR = /^[A-Za-z0-9._-]{1,128}$/;\nconst JOURNEY_ID = /^[A-Za-z0-9._-]{1,64}$/;\n// biome-ignore lint/suspicious/noControlCharactersInRegex: control characters are what this refuses\nconst CONTROL = /[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f]/;\n\ntype R = Record<string, unknown>;\nclass Invalid extends Error {}\n\nfunction obj(x: unknown, what: string, keys: readonly string[]): R {\n if (!x || typeof x !== 'object' || Array.isArray(x)) throw new Invalid(`${what} is not an object.`);\n for (const k of Object.keys(x)) if (keys.indexOf(k) < 0) throw new Invalid(`${what} has an unknown key \"${k}\".`);\n return x as R;\n}\n\nfunction text(x: unknown, what: string, required: boolean): void {\n if (x === undefined && !required) return;\n const one = (s: unknown, w: string) => {\n if (typeof s !== 'string' || s.trim() === '' || s.length > g9JourneyLimits.text || CONTROL.test(s))\n throw new Invalid(`${w} must be text of 1–${g9JourneyLimits.text} characters.`);\n };\n if (typeof x === 'string') {\n one(x, what);\n return;\n }\n const t = obj(x, what, ['fa', 'en']);\n one(t.fa, `${what}.fa`);\n one(t.en, `${what}.en`);\n}\n\nfunction anchor(x: unknown, what: string): void {\n if (typeof x !== 'string' || !ANCHOR.test(x)) throw new Invalid(`${what} must be an anchor id.`);\n}\n\nfunction route(x: unknown, what: string): void {\n if (typeof x !== 'string' || !tryParseAddress(x).ok) throw new Invalid(`${what} must be an address.`);\n}\n\nfunction oneOf(x: unknown, values: readonly string[], what: string, required = false): void {\n if (x === undefined && !required) return;\n if (typeof x !== 'string' || values.indexOf(x) < 0) throw new Invalid(`${what} must be one of ${values.join(', ')}.`);\n}\n\nfunction ms(x: unknown, what: string): void {\n if (x === undefined) return;\n if (typeof x !== 'number' || !Number.isFinite(x) || x < 0 || x > g9JourneyLimits.waitMs)\n throw new Invalid(`${what} must be 0–${g9JourneyLimits.waitMs} ms.`);\n}\n\nfunction valueCheck(x: unknown, what: string): void {\n const v = obj(x, what, ['target', 'equals']);\n anchor(v.target, `${what}.target`);\n if (v.equals !== undefined && (typeof v.equals !== 'string' || v.equals.length > g9JourneyLimits.value))\n throw new Invalid(`${what}.equals is too long.`);\n}\n\nfunction until(x: unknown, what: string): void {\n if (x === undefined || x === 'tap' || x === 'next') return;\n const u = obj(x, what, ['ms', 'route', 'value']);\n const keys = Object.keys(u);\n if (keys.length !== 1) throw new Invalid(`${what} names exactly one condition.`);\n if (u.ms !== undefined) ms(u.ms, `${what}.ms`);\n if (u.route !== undefined) route(u.route, `${what}.route`);\n if (u.value !== undefined) valueCheck(u.value, `${what}.value`);\n}\n\nconst EFFECT_KEYS: Readonly<Record<string, readonly string[]>> = {\n highlight: ['type', 'color', 'opacity', 'ring', 'padding', 'radius', 'pulse'],\n spotlight: ['type', 'scrim', 'padding', 'radius', 'modal'],\n pointer: ['type', 'gesture'],\n caption: ['type', 'text', 'title', 'placement'],\n beacon: ['type', 'corner', 'color'],\n badge: ['type', 'text'],\n ripple: ['type'],\n};\nconst COLOR = /^#[0-9A-Fa-f]{6}([0-9A-Fa-f]{2})?$/;\n\nfunction effects(x: unknown, what: string): void {\n if (x === undefined) return;\n if (!Array.isArray(x) || x.length > g9JourneyLimits.effects)\n throw new Invalid(`${what} must be a list of at most ${g9JourneyLimits.effects} effects.`);\n x.forEach((e, i) => {\n const w = `${what}[${i}]`;\n const type = (e as R | null)?.type;\n const keys = typeof type === 'string' ? EFFECT_KEYS[type] : undefined;\n if (!keys) throw new Invalid(`${w} has an unknown type.`);\n const f = obj(e, w, keys);\n for (const k of ['color', 'scrim'])\n if (f[k] !== undefined && (typeof f[k] !== 'string' || !COLOR.test(f[k] as string)))\n throw new Invalid(`${w}.${k} must be #RRGGBB(AA).`);\n for (const k of ['opacity'])\n if (f[k] !== undefined && (typeof f[k] !== 'number' || (f[k] as number) < 0 || (f[k] as number) > 1))\n throw new Invalid(`${w}.${k} must be 0–1.`);\n for (const k of ['ring', 'padding'])\n if (f[k] !== undefined && (typeof f[k] !== 'number' || (f[k] as number) < 0 || (f[k] as number) > 48))\n throw new Invalid(`${w}.${k} must be 0–48.`);\n if (\n f.radius !== undefined &&\n f.radius !== 'auto' &&\n (typeof f.radius !== 'number' || f.radius < 0 || f.radius > 200)\n )\n throw new Invalid(`${w}.radius must be \"auto\" or 0–200.`);\n for (const k of ['pulse', 'modal'])\n if (f[k] !== undefined && typeof f[k] !== 'boolean') throw new Invalid(`${w}.${k} must be true or false.`);\n if (type === 'pointer')\n oneOf(f.gesture, ['tap', 'longPress', 'swipeUp', 'swipeDown', 'swipeStart', 'swipeEnd'], `${w}.gesture`);\n if (type === 'caption') {\n text(f.text, `${w}.text`, true);\n text(f.title, `${w}.title`, false);\n oneOf(f.placement, ['auto', 'above', 'below', 'start', 'end'], `${w}.placement`);\n }\n if (type === 'beacon') oneOf(f.corner, ['top-start', 'top-end', 'bottom-start', 'bottom-end'], `${w}.corner`);\n if (type === 'badge' && (typeof f.text !== 'string' || f.text.length === 0 || f.text.length > 4))\n throw new Invalid(`${w}.text must be 1–4 characters.`);\n });\n}\n\nfunction step(x: unknown, i: number): void {\n const w = `steps[${i}]`;\n const kind = (x as R | null)?.do;\n switch (kind) {\n case 'go': {\n const s = obj(x, w, ['do', 'to', 'by']);\n route(s.to, `${w}.to`);\n oneOf(s.by, ['jump', 'user', 'demo'], `${w}.by`);\n return;\n }\n case 'show': {\n const s = obj(x, w, ['do', 'target', 'text', 'effects', 'until']);\n anchor(s.target, `${w}.target`);\n text(s.text, `${w}.text`, false);\n effects(s.effects, `${w}.effects`);\n until(s.until, `${w}.until`);\n return;\n }\n case 'say': {\n const s = obj(x, w, ['do', 'text', 'until']);\n text(s.text, `${w}.text`, true);\n until(s.until, `${w}.until`);\n return;\n }\n case 'fill': {\n const s = obj(x, w, ['do', 'target', 'value', 'by']);\n anchor(s.target, `${w}.target`);\n if (typeof s.value !== 'string' || s.value.length > g9JourneyLimits.value || CONTROL.test(s.value))\n throw new Invalid(`${w}.value must be text of at most ${g9JourneyLimits.value} characters.`);\n oneOf(s.by, ['user', 'engine'], `${w}.by`);\n return;\n }\n case 'select': {\n const s = obj(x, w, ['do', 'target', 'item', 'by']);\n anchor(s.target, `${w}.target`);\n if (typeof s.item !== 'string' || s.item === '' || s.item.length > 128)\n throw new Invalid(`${w}.item must be an item key.`);\n oneOf(s.by, ['user', 'engine'], `${w}.by`);\n return;\n }\n case 'press': {\n const s = obj(x, w, ['do', 'target', 'by', 'text']);\n anchor(s.target, `${w}.target`);\n oneOf(s.by, ['user', 'engine'], `${w}.by`);\n text(s.text, `${w}.text`, false);\n return;\n }\n case 'wait': {\n const s = obj(x, w, ['do', 'for', 'timeoutMs']);\n const f = obj(s.for, `${w}.for`, ['route', 'anchor', 'value', 'ms']);\n if (Object.keys(f).length === 0) throw new Invalid(`${w}.for names nothing to wait for.`);\n if (f.route !== undefined) route(f.route, `${w}.for.route`);\n if (f.anchor !== undefined) anchor(f.anchor, `${w}.for.anchor`);\n if (f.value !== undefined) valueCheck(f.value, `${w}.for.value`);\n ms(f.ms, `${w}.for.ms`);\n ms(s.timeoutMs, `${w}.timeoutMs`);\n return;\n }\n case 'back':\n obj(x, w, ['do']);\n return;\n default:\n throw new Invalid(`${w} has an unknown \"do\".`);\n }\n}\n\n/** Validates untrusted JSON as a journey: unknown keys, bad texts, addresses or ids are refused. */\nexport function validateJourney(\n x: unknown,\n): { readonly ok: true; readonly journey: G9Journey } | { readonly ok: false; readonly error: string } {\n try {\n const j = obj(x, 'The journey', ['id', 'title', 'source', 'pace', 'steps']);\n if (typeof j.id !== 'string' || !JOURNEY_ID.test(j.id))\n throw new Invalid('The journey id must be 1–64 of [A-Za-z0-9._-].');\n text(j.title, 'The title', false);\n oneOf(j.source, SOURCES, 'The source', true);\n oneOf(j.pace, ['auto', 'manual'], 'The pace');\n if (!Array.isArray(j.steps) || j.steps.length === 0 || j.steps.length > g9JourneyLimits.steps)\n throw new Invalid(`A journey has 1–${g9JourneyLimits.steps} steps.`);\n j.steps.forEach(step);\n return { ok: true, journey: x as G9Journey };\n } catch (error) {\n if (error instanceof Invalid) return { ok: false, error: error.message };\n throw error;\n }\n}\n\n/** Who carries a step out: the engine, the engine after the person's countdown confirmation, or the person. */\nexport type G9StepAuthority = 'engine' | 'engine-confirm' | 'user';\n\n/**\n * The source policy (plan §11.3). `navigate` covers go / show / say / wait; `fill` covers fill and select (a form\n * value, never a save); `press` reads the anchor's risk. An app may only make it stricter.\n */\nexport function journeyAuthority(\n source: G9JourneySource,\n action: 'navigate' | 'fill' | 'press',\n risk: G9AnchorRisk = 'none',\n): G9StepAuthority {\n if (action !== 'press' || risk === 'none') return 'engine';\n if (source === 'qa') return 'engine';\n if (source === 'tester') return 'user';\n return 'engine-confirm';\n}\n\n/** Countdown lengths of the confirmation (seconds). */\nexport interface G9ConfirmTiming {\n readonly commitSeconds: number;\n readonly destructiveSeconds: number;\n /** Added when the journey came from outside the app (a link). */\n readonly linkExtraSeconds: number;\n /** Multiplies the countdown when the place could not describe its changes. */\n readonly undescribedFactor: number;\n}\n\n/** The default countdowns: 5 s for a save, 10 s for a delete, +3 s from a link, ×2 when undescribed. */\nexport const g9ConfirmTimingDefaults: G9ConfirmTiming = Object.freeze({\n commitSeconds: 5,\n destructiveSeconds: 10,\n linkExtraSeconds: 3,\n undescribedFactor: 2,\n});\n\n/** The countdown of one confirmation (whole seconds, ≥ 1). */\nexport function confirmSeconds(\n source: G9JourneySource,\n risk: Exclude<G9AnchorRisk, 'none'>,\n described: boolean,\n timing: G9ConfirmTiming = g9ConfirmTimingDefaults,\n): number {\n let s = risk === 'destructive' ? timing.destructiveSeconds : timing.commitSeconds;\n if (source === 'link') s += timing.linkExtraSeconds;\n if (!described) s *= timing.undescribedFactor;\n return Math.max(1, Math.round(s));\n}\n\n/** A text in the person's language. */\nexport function textIn(t: G9Text, language: 'fa' | 'en'): string {\n return typeof t === 'string' ? t : t[language];\n}\n"],"names":["g9JourneyLimits","Object","SOURCES","ANCHOR","JOURNEY_ID","CONTROL","Invalid","Error","obj","x","what","keys","Array","k","text","required","undefined","one","s","w","t","anchor","route","tryParseAddress","oneOf","values","ms","Number","valueCheck","v","until","u","EFFECT_KEYS","COLOR","effects","e","i","type","f","step","kind","validateJourney","j","error","journeyAuthority","source","action","risk","g9ConfirmTimingDefaults","confirmSeconds","described","timing","Math","textIn","language"],"mappings":";AAkGO,MAAMA,kBAAkBC,OAAO,MAAM,CAAC;IAAE,OAAO;IAAI,MAAM;IAAK,OAAO;IAAK,IAAI;IAAI,SAAS;IAAG,QAAQ;AAAO;AAEpH,MAAMC,UAAsC;IAAC;IAAW;IAAa;IAAQ;IAAU;CAAK;AAC5F,MAAMC,SAAS;AACf,MAAMC,aAAa;AAEnB,MAAMC,UAAU;AAGhB,MAAMC,gBAAgBC;AAAO;AAE7B,SAASC,IAAIC,CAAU,EAAEC,IAAY,EAAEC,IAAuB;IAC5D,IAAI,CAACF,KAAK,AAAa,YAAb,OAAOA,KAAkBG,MAAM,OAAO,CAACH,IAAI,MAAM,IAAIH,QAAQ,GAAGI,KAAK,kBAAkB,CAAC;IAClG,KAAK,MAAMG,KAAKZ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OAAO,MAAM,CAAC;IACpE,eAAe;IACf,oBAAoB;IACpB,kBAAkB;IAClB,mBAAmB;AACrB;AAGO,SAASgD,eACdJ,MAAuB,EACvBE,IAAmC,EACnCG,SAAkB,EAClBC,SAA0BH,uBAAuB;IAEjD,IAAI9B,IAAI6B,AAAS,kBAATA,OAAyBI,OAAO,kBAAkB,GAAGA,OAAO,aAAa;IACjF,IAAIN,AAAW,WAAXA,QAAmB3B,KAAKiC,OAAO,gBAAgB;IACnD,IAAI,CAACD,WAAWhC,KAAKiC,OAAO,iBAAiB;IAC7C,OAAOC,KAAK,GAAG,CAAC,GAAGA,KAAK,KAAK,CAAClC;AAChC;AAGO,SAASmC,OAAOjC,CAAS,EAAEkC,QAAqB;IACrD,OAAO,AAAa,YAAb,OAAOlC,IAAiBA,IAAIA,CAAC,CAACkC,SAAS;AAChD"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type G9Segment } from './address.js';
|
|
2
|
+
import type { G9Catalogue } from './catalogue.js';
|
|
3
|
+
import { type G9PlaceLayer } from './sink.js';
|
|
4
|
+
/** One open place as the resolver sees it. */
|
|
5
|
+
export interface G9LivePlace {
|
|
6
|
+
readonly token: number;
|
|
7
|
+
readonly segment: G9Segment;
|
|
8
|
+
readonly layer: G9PlaceLayer;
|
|
9
|
+
readonly order: number;
|
|
10
|
+
readonly under: readonly G9Segment[];
|
|
11
|
+
}
|
|
12
|
+
/** The logical path and how each step is held. */
|
|
13
|
+
export interface G9ResolvedPath {
|
|
14
|
+
readonly segments: readonly G9Segment[];
|
|
15
|
+
/** Per segment: the open place holding it, or null when it was made up (`under`, default ancestors). */
|
|
16
|
+
readonly tokens: ReadonlyArray<number | null>;
|
|
17
|
+
/** The path does not reach the root: a parent was missing. */
|
|
18
|
+
readonly incomplete: boolean;
|
|
19
|
+
/** Open places that are not on the path. */
|
|
20
|
+
readonly others: readonly number[];
|
|
21
|
+
}
|
|
22
|
+
/** Bottom-to-top order of open places. */
|
|
23
|
+
export declare function compareLivePlaces(a: G9LivePlace, b: G9LivePlace): number;
|
|
24
|
+
/** The logical path of what is open. */
|
|
25
|
+
export declare function resolvePath(live: readonly G9LivePlace[], catalogue: G9Catalogue<unknown>): G9ResolvedPath;
|
|
26
|
+
/** What going to a target path changes. */
|
|
27
|
+
export interface G9NavigationPlan {
|
|
28
|
+
/** How many leading segments of the target are already open (and kept). */
|
|
29
|
+
readonly keep: number;
|
|
30
|
+
/** Open places to close, top first. */
|
|
31
|
+
readonly close: readonly number[];
|
|
32
|
+
/** Segments to open, in order (the target from `keep` on). */
|
|
33
|
+
readonly open: readonly G9Segment[];
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The plan from what is open to a target path (pure). The kept prefix must END on an open place (a made-up ancestor
|
|
37
|
+
* is kept only when an open place below the divergence holds it): leaving the sampling map for its own task overview
|
|
38
|
+
* closes the map mode and opens the overview, it does not keep a task that was never open. Closed: every open place of
|
|
39
|
+
* the current path past the kept prefix, and every overlay (sheet, popup) above it; never a root place (opening a
|
|
40
|
+
* sibling root replaces it).
|
|
41
|
+
*/
|
|
42
|
+
export declare function planNavigation(target: readonly G9Segment[], current: G9ResolvedPath, live: readonly G9LivePlace[]): G9NavigationPlan;
|
|
43
|
+
//# sourceMappingURL=resolve.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../src/route/resolve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAe,MAAM,WAAW,CAAC;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,KAAK,YAAY,EAAiB,MAAM,QAAQ,CAAC;AAQ1D,8CAA8C;AAC9C,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,SAAS,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE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|
|
5
|
+
return g9PlaceLayers.indexOf(p.layer);
|
|
6
|
+
}
|
|
7
|
+
function compareLivePlaces(a, b) {
|
|
8
|
+
return rank(a) - rank(b) || a.order - b.order || a.token - b.token;
|
|
9
|
+
}
|
|
10
|
+
function resolvePath(live, catalogue) {
|
|
11
|
+
if (0 === live.length) return {
|
|
12
|
+
segments: [],
|
|
13
|
+
tokens: [],
|
|
14
|
+
incomplete: false,
|
|
15
|
+
others: []
|
|
16
|
+
};
|
|
17
|
+
const sorted = live.slice().sort(compareLivePlaces);
|
|
18
|
+
let floor = sorted.length - 1;
|
|
19
|
+
const top = sorted[floor];
|
|
20
|
+
const segments = [
|
|
21
|
+
top.segment
|
|
22
|
+
];
|
|
23
|
+
const tokens = [
|
|
24
|
+
top.token
|
|
25
|
+
];
|
|
26
|
+
let kind = top.segment.kind;
|
|
27
|
+
let pending = top.under.slice();
|
|
28
|
+
let incomplete = false;
|
|
29
|
+
const below = (predicate)=>{
|
|
30
|
+
for(let i = floor - 1; i >= 0; i--)if (predicate(sorted[i])) return i;
|
|
31
|
+
return -1;
|
|
32
|
+
};
|
|
33
|
+
for(let step = 0; step < MAX_STEPS; step++){
|
|
34
|
+
if (pending.length > 0) {
|
|
35
|
+
const u = pending[pending.length - 1];
|
|
36
|
+
if (!catalogue.allowsParent(kind, u.kind)) {
|
|
37
|
+
pending = [];
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
pending = pending.slice(0, -1);
|
|
41
|
+
const same = below((p)=>sameSegment(p.segment, u));
|
|
42
|
+
if (same >= 0) {
|
|
43
|
+
const p = sorted[same];
|
|
44
|
+
segments.unshift(p.segment);
|
|
45
|
+
tokens.unshift(p.token);
|
|
46
|
+
floor = same;
|
|
47
|
+
pending = [
|
|
48
|
+
...p.under,
|
|
49
|
+
...pending
|
|
50
|
+
];
|
|
51
|
+
} else {
|
|
52
|
+
segments.unshift(u);
|
|
53
|
+
tokens.unshift(null);
|
|
54
|
+
}
|
|
55
|
+
kind = u.kind;
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
const parentAt = below((p)=>catalogue.allowsParent(kind, p.segment.kind));
|
|
59
|
+
if (parentAt >= 0) {
|
|
60
|
+
const p = sorted[parentAt];
|
|
61
|
+
segments.unshift(p.segment);
|
|
62
|
+
tokens.unshift(p.token);
|
|
63
|
+
floor = parentAt;
|
|
64
|
+
kind = p.segment.kind;
|
|
65
|
+
pending = p.under.slice();
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (catalogue.allowsParent(kind, '')) break;
|
|
69
|
+
const made = catalogue.defaultAncestors(kind);
|
|
70
|
+
if (made) {
|
|
71
|
+
segments.unshift(...made);
|
|
72
|
+
tokens.unshift(...made.map(()=>null));
|
|
73
|
+
} else incomplete = true;
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
const onPath = new Set(tokens.filter((t)=>null !== t));
|
|
77
|
+
const others = sorted.filter((p)=>!onPath.has(p.token)).map((p)=>p.token);
|
|
78
|
+
return {
|
|
79
|
+
segments,
|
|
80
|
+
tokens,
|
|
81
|
+
incomplete,
|
|
82
|
+
others
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function planNavigation(target, current, live) {
|
|
86
|
+
let keep = 0;
|
|
87
|
+
const max = Math.min(target.length, current.segments.length);
|
|
88
|
+
while(keep < max && sameSegment(target[keep], current.segments[keep]))keep++;
|
|
89
|
+
while(keep > 0 && null === current.tokens[keep - 1])keep--;
|
|
90
|
+
const byToken = new Map(live.map((p)=>[
|
|
91
|
+
p.token,
|
|
92
|
+
p
|
|
93
|
+
]));
|
|
94
|
+
const keptTop = keep > 0 ? byToken.get(current.tokens[keep - 1]) : void 0;
|
|
95
|
+
const closing = new Set();
|
|
96
|
+
for(let i = keep; i < current.tokens.length; i++){
|
|
97
|
+
var _byToken_get;
|
|
98
|
+
const t = current.tokens[i];
|
|
99
|
+
if (null != t && (null == (_byToken_get = byToken.get(t)) ? void 0 : _byToken_get.layer) !== 'root') closing.add(t);
|
|
100
|
+
}
|
|
101
|
+
for (const t of current.others){
|
|
102
|
+
const p = byToken.get(t);
|
|
103
|
+
if (p && ('sheet' === p.layer || 'popup' === p.layer)) {
|
|
104
|
+
if (!keptTop || compareLivePlaces(p, keptTop) > 0) closing.add(t);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const close = Array.from(closing).map((t)=>byToken.get(t)).sort((a, b)=>compareLivePlaces(b, a)).map((p)=>p.token);
|
|
108
|
+
return {
|
|
109
|
+
keep,
|
|
110
|
+
close,
|
|
111
|
+
open: target.slice(keep)
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
export { compareLivePlaces, planNavigation, resolvePath };
|
|
115
|
+
|
|
116
|
+
//# sourceMappingURL=resolve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route/resolve.js","sources":["../../src/route/resolve.ts"],"sourcesContent":["import { type G9Segment, sameSegment } from './address';\nimport type { G9Catalogue } from './catalogue';\nimport { type G9PlaceLayer, g9PlaceLayers } from './sink';\n\n// From the places that are open to the LOGICAL path (pure). The top place (highest layer, then order, then the latest\n// declaration) is the leaf; each step up takes, in this order: the declared `under` ancestors (explicit beats inferred;\n// a live place equal to one is used instead of a made-up one), the nearest open place below that the catalogue allows\n// as a parent, the root when the kind may sit there, the kind's default ancestors, or — none of these — the path ends\n// `incomplete`. Same input, same output.\n\n/** One open place as the resolver sees it. */\nexport interface G9LivePlace {\n readonly token: number;\n readonly segment: G9Segment;\n readonly layer: G9PlaceLayer;\n readonly order: number;\n readonly under: readonly G9Segment[];\n}\n\n/** The logical path and how each step is held. */\nexport interface G9ResolvedPath {\n readonly segments: readonly G9Segment[];\n /** Per segment: the open place holding it, or null when it was made up (`under`, default ancestors). */\n readonly tokens: ReadonlyArray<number | null>;\n /** The path does not reach the root: a parent was missing. */\n readonly incomplete: boolean;\n /** Open places that are not on the path. */\n readonly others: readonly number[];\n}\n\nconst MAX_STEPS = 64;\n\nfunction rank(p: G9LivePlace): number {\n return g9PlaceLayers.indexOf(p.layer);\n}\n\n/** Bottom-to-top order of open places. */\nexport function compareLivePlaces(a: G9LivePlace, b: G9LivePlace): number {\n return rank(a) - rank(b) || a.order - b.order || a.token - b.token;\n}\n\n/** The logical path of what is open. */\nexport function resolvePath(live: readonly G9LivePlace[], catalogue: G9Catalogue<unknown>): G9ResolvedPath {\n if (live.length === 0) return { segments: [], tokens: [], incomplete: false, others: [] };\n const sorted = live.slice().sort(compareLivePlaces);\n let floor = sorted.length - 1;\n const top = sorted[floor] as G9LivePlace;\n const segments: G9Segment[] = [top.segment];\n const tokens: Array<number | null> = [top.token];\n let kind = top.segment.kind;\n let pending: G9Segment[] = top.under.slice();\n let incomplete = false;\n\n const below = (predicate: (p: G9LivePlace) => boolean): number => {\n for (let i = floor - 1; i >= 0; i--) if (predicate(sorted[i] as G9LivePlace)) return i;\n return -1;\n };\n\n for (let step = 0; step < MAX_STEPS; step++) {\n if (pending.length > 0) {\n const u = pending[pending.length - 1] as G9Segment;\n if (!catalogue.allowsParent(kind, u.kind)) {\n pending = [];\n continue;\n }\n pending = pending.slice(0, -1);\n const same = below((p) => sameSegment(p.segment, u));\n if (same >= 0) {\n const p = sorted[same] as G9LivePlace;\n segments.unshift(p.segment);\n tokens.unshift(p.token);\n floor = same;\n pending = [...p.under, ...pending];\n } else {\n segments.unshift(u);\n tokens.unshift(null);\n }\n kind = u.kind;\n continue;\n }\n const parentAt = below((p) => catalogue.allowsParent(kind, p.segment.kind));\n if (parentAt >= 0) {\n const p = sorted[parentAt] as G9LivePlace;\n segments.unshift(p.segment);\n tokens.unshift(p.token);\n floor = parentAt;\n kind = p.segment.kind;\n pending = p.under.slice();\n continue;\n }\n if (catalogue.allowsParent(kind, '')) break;\n const made = catalogue.defaultAncestors(kind);\n if (made) {\n segments.unshift(...made);\n tokens.unshift(...made.map(() => null));\n } else incomplete = true;\n break;\n }\n\n const onPath = new Set(tokens.filter((t): t is number => t !== null));\n const others = sorted.filter((p) => !onPath.has(p.token)).map((p) => p.token);\n return { segments, tokens, incomplete, others };\n}\n\n/** What going to a target path changes. */\nexport interface G9NavigationPlan {\n /** How many leading segments of the target are already open (and kept). */\n readonly keep: number;\n /** Open places to close, top first. */\n readonly close: readonly number[];\n /** Segments to open, in order (the target from `keep` on). */\n readonly open: readonly G9Segment[];\n}\n\n/**\n * The plan from what is open to a target path (pure). The kept prefix must END on an open place (a made-up ancestor\n * is kept only when an open place below the divergence holds it): leaving the sampling map for its own task overview\n * closes the map mode and opens the overview, it does not keep a task that was never open. Closed: every open place of\n * the current path past the kept prefix, and every overlay (sheet, popup) above it; never a root place (opening a\n * sibling root replaces it).\n */\nexport function planNavigation(\n target: readonly G9Segment[],\n current: G9ResolvedPath,\n live: readonly G9LivePlace[],\n): G9NavigationPlan {\n let keep = 0;\n const max = Math.min(target.length, current.segments.length);\n while (keep < max && sameSegment(target[keep] as G9Segment, current.segments[keep] as G9Segment)) keep++;\n while (keep > 0 && current.tokens[keep - 1] === null) keep--;\n\n const byToken = new Map(live.map((p) => [p.token, p] as const));\n const keptTop = keep > 0 ? byToken.get(current.tokens[keep - 1] as number) : undefined;\n const closing = new Set<number>();\n for (let i = keep; i < current.tokens.length; i++) {\n const t = current.tokens[i];\n if (t !== null && t !== undefined && byToken.get(t)?.layer !== 'root') closing.add(t);\n }\n for (const t of current.others) {\n const p = byToken.get(t);\n if (!p || (p.layer !== 'sheet' && p.layer !== 'popup')) continue;\n if (!keptTop || compareLivePlaces(p, keptTop) > 0) closing.add(t);\n }\n const close = Array.from(closing)\n .map((t) => byToken.get(t) as G9LivePlace)\n .sort((a, b) => compareLivePlaces(b, a))\n .map((p) => p.token);\n return { keep, close, open: target.slice(keep) };\n}\n"],"names":["MAX_STEPS","rank","p","g9PlaceLayers","compareLivePlaces","a","b","resolvePath","live","catalogue","sorted","floor","top","segments","tokens","kind","pending","incomplete","below","predicate","i","step","u","same","sameSegment","parentAt","made","onPath","Set","t","others","planNavigation","target","current","keep","max","Math","byToken","Map","keptTop","undefined","closing","_byToken_get","close","Array"],"mappings":";;AA8BA,MAAMA,YAAY;AAElB,SAASC,KAAKC,CAAc;IAC1B,OAAOC,cAAc,OAAO,CAACD,EAAE,KAAK;AACtC;AAGO,SAASE,kBAAkBC,CAAc,EAAEC,CAAc;IAC9D,OAAOL,KAAKI,KAAKJ,KAAKK,MAAMD,EAAE,KAAK,GAAGC,EAAE,KAAK,IAAID,EAAE,KAAK,GAAGC,EAAE,KAAK;AACpE;AAGO,SAASC,YAAYC,IAA4B,EAAEC,SAA+B;IACvF,IAAID,AAAgB,MAAhBA,KAAK,MAAM,EAAQ,OAAO;QAAE,UAAU,EAAE;QAAE,QAAQ,EAAE;QAAE,YAAY;QAAO,QAAQ,EAAE;IAAC;IACxF,MAAME,SAASF,KAAK,KAAK,GAAG,IAAI,CAACJ;IACjC,IAAIO,QAAQD,OAAO,MAAM,GAAG;IAC5B,MAAME,MAAMF,MAAM,CAACC,MAAM;IACzB,MAAME,WAAwB;QAACD,IAAI,OAAO;KAAC;IAC3C,MAAME,SAA+B;QAACF,IAAI,KAAK;KAAC;IAChD,IAAIG,OAAOH,IAAI,OAAO,CAAC,IAAI;IAC3B,IAAII,UAAuBJ,IAAI,KAAK,CAAC,KAAK;IAC1C,IAAIK,aAAa;IAEjB,MAAMC,QAAQ,CAACC;QACb,IAAK,IAAIC,IAAIT,QAAQ,GAAGS,KAAK,GAAGA,IAAK,IAAID,UAAUT,MAAM,CAACU,EAAE,GAAkB,OAAOA;QACrF,OAAO;IACT;IAEA,IAAK,IAAIC,OAAO,GAAGA,OAAOrB,WAAWqB,OAAQ;QAC3C,IAAIL,QAAQ,MAAM,GAAG,GAAG;YACtB,MAAMM,IAAIN,OAAO,CAACA,QAAQ,MAAM,GAAG,EAAE;YACrC,IAAI,CAACP,UAAU,YAAY,CAACM,MAAMO,EAAE,IAAI,GAAG;gBACzCN,UAAU,EAAE;gBACZ;YACF;YACAA,UAAUA,QAAQ,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C,CAACxB,GAAGC,IAAMF,kBAAkBE,GAAGD,IACpC,GAAG,CAAC,CAACH,IAAMA,EAAE,KAAK;IACrB,OAAO;QAAEgC;QAAMS;QAAO,MAAMX,OAAO,KAAK,CAACE;IAAM;AACjD"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { G9Segment } from './address.js';
|
|
2
|
+
/** Where a place is drawn: decides which open place is on top. Bottom to top. */
|
|
3
|
+
export type G9PlaceLayer = 'root' | 'page' | 'mode' | 'inner' | 'sheet' | 'popup';
|
|
4
|
+
/** Every layer, bottom to top. */
|
|
5
|
+
export declare const g9PlaceLayers: readonly G9PlaceLayer[];
|
|
6
|
+
/** One change a write would make, as a person reads it (the confirmation before a guided save lists these). */
|
|
7
|
+
export interface G9ChangeLine {
|
|
8
|
+
readonly action: 'create' | 'update' | 'delete' | 'send' | 'other';
|
|
9
|
+
/** What it is about: «گزارش مشاهده»، «بستهٔ PK-12». */
|
|
10
|
+
readonly subject: string;
|
|
11
|
+
/** For an update: which field. */
|
|
12
|
+
readonly field?: string;
|
|
13
|
+
readonly from?: string | null;
|
|
14
|
+
readonly to?: string | null;
|
|
15
|
+
/** A consequence the person must know («۱۲ نمونهٔ این بسته هم حذف میشود»). */
|
|
16
|
+
readonly note?: string;
|
|
17
|
+
}
|
|
18
|
+
/** A place that is open right now, as it declares itself. */
|
|
19
|
+
export interface G9PlaceDeclaration {
|
|
20
|
+
/** Read again on every `touch()`: a segment may carry live view parameters (search, sort). */
|
|
21
|
+
readonly segment: G9Segment | (() => G9Segment);
|
|
22
|
+
readonly layer: G9PlaceLayer;
|
|
23
|
+
/** Order inside the layer (the sheet stack index). Default 0. */
|
|
24
|
+
readonly order?: number;
|
|
25
|
+
/** Logical ancestors that are not open themselves, root first (a mode drawn on the map tab but living under a task). */
|
|
26
|
+
readonly under?: readonly G9Segment[];
|
|
27
|
+
/** The breadcrumb of the live place (its real title). Default: the catalogue's title. */
|
|
28
|
+
title?(): string | null | undefined;
|
|
29
|
+
/** Extra view state of this place (scroll marks are collected by the router). */
|
|
30
|
+
view?(): Readonly<Record<string, string>> | undefined;
|
|
31
|
+
applyView?(view: Readonly<Record<string, string>>): void | Promise<void>;
|
|
32
|
+
/** How the router leaves this place. Absent = the router cannot close it. */
|
|
33
|
+
close?(): void | Promise<void>;
|
|
34
|
+
/** Unsaved work: the router asks before closing it. */
|
|
35
|
+
canLeave?(): true | {
|
|
36
|
+
readonly dirty: true;
|
|
37
|
+
readonly message?: string;
|
|
38
|
+
};
|
|
39
|
+
/** What saving this place would change (the guided-save confirmation). */
|
|
40
|
+
describeChanges?(): readonly G9ChangeLine[];
|
|
41
|
+
/** Physical facts for snapshots and reports, never part of the address (the surface it is drawn on, the open site). */
|
|
42
|
+
facts?(): Readonly<Record<string, string | number | boolean | null>>;
|
|
43
|
+
/**
|
|
44
|
+
* False while the place is open but not on screen — the content of a background tab (a site left open on the map
|
|
45
|
+
* while the person is on another tab). A hidden place is not part of the location; going to it opens it again (its
|
|
46
|
+
* `open` brings it forward). Read on every recompute: call `touch()` when it changes. Absent = always shown.
|
|
47
|
+
*/
|
|
48
|
+
shown?(): boolean;
|
|
49
|
+
}
|
|
50
|
+
/** The handle of one declaration. */
|
|
51
|
+
export interface G9PlaceHandle {
|
|
52
|
+
readonly token: number;
|
|
53
|
+
/** The place's own state changed (view parameters, title): the router re-reads it. */
|
|
54
|
+
touch(): void;
|
|
55
|
+
/** The place closed. Idempotent. */
|
|
56
|
+
remove(): void;
|
|
57
|
+
}
|
|
58
|
+
/** The router as places see it (`G9Capabilities.route`). */
|
|
59
|
+
export interface G9RouteSink {
|
|
60
|
+
declare(declaration: G9PlaceDeclaration): G9PlaceHandle;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=sink.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sink.d.ts","sourceRoot":"","sources":["../../src/route/sink.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,E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