mol_tree2 0.0.3 → 1.0.6

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/web.esm.js CHANGED
@@ -5,642 +5,1217 @@ function require( path ){ return $node[ path ] };
5
5
  var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
6
6
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
7
7
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
8
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
8
+ else for (var i = decorators.length - 1; i >= 0; i--) if ((d = decorators[i])) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
9
9
  return c > 3 && r && Object.defineProperty(target, key, r), r;
10
10
  };
11
11
 
12
- var globalThis = globalThis || ( typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : this )
13
- var $ = ( typeof module === 'object' ) ? Object.setPrototypeOf( module['export'+'s'] , globalThis ) : globalThis
12
+ var $ = ( typeof module === 'object' ) ? ( module['export'+'s'] = globalThis ) : globalThis
14
13
  $.$$ = $
15
- $.$mol = $ // deprecated
16
14
 
17
15
  ;
18
16
 
19
17
  var $node = $node || {}
20
- void function( module ) { var exports = module.exports = this; function require( id ) { return $node[ id.replace( /^.\// , "../mol/" ) ] };
18
+ void function( module ) { var exports = module.exports = this; function require( id ) { return $node[ id.replace( /^.\// , "../" ) ] };
21
19
  ;
22
- "use strict";
23
- Error.stackTraceLimit = Infinity;
24
- var $;
25
- (function ($) {
26
- })($ || ($ = {}));
27
- module.exports = $;
28
- //mol.js.map
20
+ "use strict";
21
+ Error.stackTraceLimit = 50;
22
+ var $;
23
+ (function ($) {
24
+ })($ || ($ = {}));
25
+ module.exports = $;
26
+ //mam.ts
29
27
  ;
30
28
 
31
- $node[ "../mol/mol" ] = $node[ "../mol/mol.js" ] = module.exports }.call( {} , {} )
29
+ $node[ "../mam.ts" ] = $node[ "../mam.ts" ] = module.exports }.call( {} , {} )
30
+ ;
31
+ "use strict";
32
+ var $;
33
+ (function ($) {
34
+ $.$mol_ambient_ref = Symbol('$mol_ambient_ref');
35
+ function $mol_ambient(overrides) {
36
+ return Object.setPrototypeOf(overrides, this || $);
37
+ }
38
+ $.$mol_ambient = $mol_ambient;
39
+ })($ || ($ = {}));
40
+ //mol/ambient/ambient.ts
41
+ ;
42
+ "use strict";
43
+ var $;
44
+ (function ($) {
45
+ const instances = new WeakSet();
46
+ function $mol_delegate(proto, target) {
47
+ const proxy = new Proxy(proto, {
48
+ get: (_, field) => {
49
+ const obj = target();
50
+ let val = Reflect.get(obj, field);
51
+ if (typeof val === 'function') {
52
+ val = val.bind(obj);
53
+ }
54
+ return val;
55
+ },
56
+ has: (_, field) => Reflect.has(target(), field),
57
+ set: (_, field, value) => Reflect.set(target(), field, value),
58
+ getOwnPropertyDescriptor: (_, field) => Reflect.getOwnPropertyDescriptor(target(), field),
59
+ ownKeys: () => Reflect.ownKeys(target()),
60
+ getPrototypeOf: () => Reflect.getPrototypeOf(target()),
61
+ setPrototypeOf: (_, donor) => Reflect.setPrototypeOf(target(), donor),
62
+ isExtensible: () => Reflect.isExtensible(target()),
63
+ preventExtensions: () => Reflect.preventExtensions(target()),
64
+ apply: (_, self, args) => Reflect.apply(target(), self, args),
65
+ construct: (_, args, retarget) => Reflect.construct(target(), args, retarget),
66
+ defineProperty: (_, field, descr) => Reflect.defineProperty(target(), field, descr),
67
+ deleteProperty: (_, field) => Reflect.deleteProperty(target(), field),
68
+ });
69
+ instances.add(proxy);
70
+ return proxy;
71
+ }
72
+ $.$mol_delegate = $mol_delegate;
73
+ Reflect.defineProperty($mol_delegate, Symbol.hasInstance, {
74
+ value: (obj) => instances.has(obj),
75
+ });
76
+ })($ || ($ = {}));
77
+ //mol/delegate/delegate.ts
78
+ ;
79
+ "use strict";
80
+ var $;
81
+ (function ($) {
82
+ $.$mol_owning_map = new WeakMap();
83
+ function $mol_owning_allow(having) {
84
+ try {
85
+ if (!having)
86
+ return false;
87
+ if (typeof having !== 'object')
88
+ return false;
89
+ if (having instanceof $mol_delegate)
90
+ return false;
91
+ if (typeof having['destructor'] !== 'function')
92
+ return false;
93
+ return true;
94
+ }
95
+ catch {
96
+ return false;
97
+ }
98
+ }
99
+ $.$mol_owning_allow = $mol_owning_allow;
100
+ function $mol_owning_get(having, Owner) {
101
+ if (!$mol_owning_allow(having))
102
+ return null;
103
+ while (true) {
104
+ const owner = $.$mol_owning_map.get(having);
105
+ if (!owner)
106
+ return owner;
107
+ if (!Owner)
108
+ return owner;
109
+ if (owner instanceof Owner)
110
+ return owner;
111
+ having = owner;
112
+ }
113
+ }
114
+ $.$mol_owning_get = $mol_owning_get;
115
+ function $mol_owning_check(owner, having) {
116
+ if (!$mol_owning_allow(having))
117
+ return false;
118
+ if ($.$mol_owning_map.get(having) !== owner)
119
+ return false;
120
+ return true;
121
+ }
122
+ $.$mol_owning_check = $mol_owning_check;
123
+ function $mol_owning_catch(owner, having) {
124
+ if (!$mol_owning_allow(having))
125
+ return false;
126
+ if ($.$mol_owning_map.get(having))
127
+ return false;
128
+ $.$mol_owning_map.set(having, owner);
129
+ return true;
130
+ }
131
+ $.$mol_owning_catch = $mol_owning_catch;
132
+ })($ || ($ = {}));
133
+ //mol/owning/owning.ts
134
+ ;
135
+ "use strict";
136
+ var $;
137
+ (function ($) {
138
+ function $mol_fail(error) {
139
+ throw error;
140
+ }
141
+ $.$mol_fail = $mol_fail;
142
+ })($ || ($ = {}));
143
+ //mol/fail/fail.ts
144
+ ;
145
+ "use strict";
146
+ var $;
147
+ (function ($) {
148
+ function $mol_fail_hidden(error) {
149
+ throw error;
150
+ }
151
+ $.$mol_fail_hidden = $mol_fail_hidden;
152
+ })($ || ($ = {}));
153
+ //mol/fail/hidden/hidden.ts
154
+ ;
155
+ "use strict";
156
+ //mol/type/writable/writable.ts
157
+ ;
158
+ "use strict";
159
+ var $;
160
+ (function ($) {
161
+ class $mol_object2 {
162
+ static $ = $;
163
+ [$mol_ambient_ref] = null;
164
+ get $() {
165
+ if (this[$mol_ambient_ref])
166
+ return this[$mol_ambient_ref];
167
+ const owner = $mol_owning_get(this);
168
+ return this[$mol_ambient_ref] = owner?.$ || $mol_object2.$;
169
+ }
170
+ set $(next) {
171
+ if (this[$mol_ambient_ref])
172
+ $mol_fail_hidden(new Error('Context already defined'));
173
+ this[$mol_ambient_ref] = next;
174
+ }
175
+ static create(init) {
176
+ const obj = new this;
177
+ if (init)
178
+ init(obj);
179
+ return obj;
180
+ }
181
+ static [Symbol.toPrimitive]() {
182
+ return this.toString();
183
+ }
184
+ static toString() {
185
+ if (Symbol.toStringTag in this)
186
+ return this[Symbol.toStringTag];
187
+ return this.name;
188
+ }
189
+ destructor() { }
190
+ toString() {
191
+ return this[Symbol.toStringTag] || this.constructor.name + '()';
192
+ }
193
+ toJSON() {
194
+ return this.toString();
195
+ }
196
+ }
197
+ $.$mol_object2 = $mol_object2;
198
+ })($ || ($ = {}));
199
+ //mol/object2/object2.ts
200
+ ;
201
+ "use strict";
202
+ var $;
203
+ (function ($) {
204
+ class $mol_span extends $mol_object2 {
205
+ uri;
206
+ source;
207
+ row;
208
+ col;
209
+ length;
210
+ constructor(uri, source, row, col, length) {
211
+ super();
212
+ this.uri = uri;
213
+ this.source = source;
214
+ this.row = row;
215
+ this.col = col;
216
+ this.length = length;
217
+ this[Symbol.toStringTag] = `${this.uri}#${this.row}:${this.col}/${this.length}`;
218
+ }
219
+ static unknown = $mol_span.begin('unknown');
220
+ static begin(uri, source = '') {
221
+ return new $mol_span(uri, source, 1, 1, 0);
222
+ }
223
+ static end(uri, source) {
224
+ return new $mol_span(uri, source, 1, source.length + 1, length);
225
+ }
226
+ static entire(uri, source) {
227
+ return new $mol_span(uri, source, 1, 1, source.length);
228
+ }
229
+ toString() {
230
+ return this[Symbol.toStringTag];
231
+ }
232
+ toJSON() {
233
+ return {
234
+ uri: this.uri,
235
+ row: this.row,
236
+ col: this.col,
237
+ length: this.length
238
+ };
239
+ }
240
+ error(message, Class = Error) {
241
+ return new Class(`${message}${this}`);
242
+ }
243
+ span(row, col, length) {
244
+ return new $mol_span(this.uri, this.source, row, col, length);
245
+ }
246
+ after(length = 0) {
247
+ return new $mol_span(this.uri, this.source, this.row, this.col + this.length, length);
248
+ }
249
+ slice(begin, end = -1) {
250
+ let len = this.length;
251
+ if (begin < 0)
252
+ begin += len;
253
+ if (end < 0)
254
+ end += len;
255
+ if (begin < 0 || begin > len)
256
+ this.$.$mol_fail(`Begin value '${begin}' out of range ${this}`);
257
+ if (end < 0 || end > len)
258
+ this.$.$mol_fail(`End value '${end}' out of range ${this}`);
259
+ if (end < begin)
260
+ this.$.$mol_fail(`End value '${end}' can't be less than begin value ${this}`);
261
+ return this.span(this.row, this.col + begin, end - begin);
262
+ }
263
+ }
264
+ $.$mol_span = $mol_span;
265
+ })($ || ($ = {}));
266
+ //mol/span/span.ts
32
267
  ;
33
- "use strict";
34
- var $;
35
- (function ($) {
36
- $.$mol_ambient_ref = Symbol('$mol_ambient_ref');
37
- function $mol_ambient(overrides) {
38
- return Object.setPrototypeOf(overrides, this || $);
39
- }
40
- $.$mol_ambient = $mol_ambient;
41
- })($ || ($ = {}));
42
- //ambient.js.map
268
+ "use strict";
269
+ var $;
270
+ (function ($) {
271
+ class $mol_error_syntax extends SyntaxError {
272
+ reason;
273
+ line;
274
+ span;
275
+ constructor(reason, line, span) {
276
+ super(`${reason}\n${span}\n${line.substring(0, span.col - 1).replace(/\S/g, ' ')}${''.padEnd(span.length, '!')}\n${line}`);
277
+ this.reason = reason;
278
+ this.line = line;
279
+ this.span = span;
280
+ }
281
+ }
282
+ $.$mol_error_syntax = $mol_error_syntax;
283
+ })($ || ($ = {}));
284
+ //mol/error/syntax/syntax.ts
43
285
  ;
44
- "use strict";
45
- var $;
46
- (function ($) {
47
- const instances = new WeakSet();
48
- function $mol_delegate(proto, target) {
49
- const proxy = new Proxy(proto, {
50
- get: (_, field) => {
51
- const obj = target();
52
- let val = Reflect.get(obj, field);
53
- if (typeof val === 'function') {
54
- val = val.bind(obj);
55
- }
56
- return val;
57
- },
58
- has: (_, field) => Reflect.has(target(), field),
59
- set: (_, field, value) => Reflect.set(target(), field, value),
60
- getOwnPropertyDescriptor: (_, field) => Reflect.getOwnPropertyDescriptor(target(), field),
61
- ownKeys: () => Reflect.ownKeys(target()),
62
- getPrototypeOf: () => Reflect.getPrototypeOf(target()),
63
- setPrototypeOf: (_, donor) => Reflect.setPrototypeOf(target(), donor),
64
- isExtensible: () => Reflect.isExtensible(target()),
65
- preventExtensions: () => Reflect.preventExtensions(target()),
66
- apply: (_, self, args) => Reflect.apply(target(), self, args),
67
- construct: (_, args, retarget) => Reflect.construct(target(), args, retarget),
68
- defineProperty: (_, field, descr) => Reflect.defineProperty(target(), field, descr),
69
- deleteProperty: (_, field) => Reflect.deleteProperty(target(), field),
70
- });
71
- instances.add(proxy);
72
- return proxy;
73
- }
74
- $.$mol_delegate = $mol_delegate;
75
- Reflect.defineProperty($mol_delegate, Symbol.hasInstance, {
76
- value: (obj) => instances.has(obj),
77
- });
78
- })($ || ($ = {}));
79
- //delegate.js.map
286
+ "use strict";
287
+ var $;
288
+ (function ($) {
289
+ function $mol_tree2_from_string(str, uri = 'unknown') {
290
+ const span = $mol_span.entire(uri, str);
291
+ var root = $mol_tree2.list([], span);
292
+ var stack = [root];
293
+ var pos = 0, row = 0, min_indent = 0;
294
+ while (str.length > pos) {
295
+ var indent = 0;
296
+ var line_start = pos;
297
+ row++;
298
+ while (str.length > pos && str[pos] == '\t') {
299
+ indent++;
300
+ pos++;
301
+ }
302
+ if (!root.kids.length) {
303
+ min_indent = indent;
304
+ }
305
+ indent -= min_indent;
306
+ if (indent < 0 || indent >= stack.length) {
307
+ const sp = span.span(row, 1, pos - line_start);
308
+ while (str.length > pos && str[pos] != '\n') {
309
+ pos++;
310
+ }
311
+ if (indent < 0) {
312
+ if (str.length > pos) {
313
+ this.$mol_fail(new this.$mol_error_syntax(`Too few tabs`, str.substring(line_start, pos), sp));
314
+ }
315
+ }
316
+ else {
317
+ this.$mol_fail(new this.$mol_error_syntax(`Too many tabs`, str.substring(line_start, pos), sp));
318
+ }
319
+ }
320
+ stack.length = indent + 1;
321
+ var parent = stack[indent];
322
+ while (str.length > pos && str[pos] != '\\' && str[pos] != '\n') {
323
+ var error_start = pos;
324
+ while (str.length > pos && (str[pos] == ' ' || str[pos] == '\t')) {
325
+ pos++;
326
+ }
327
+ if (pos > error_start) {
328
+ let line_end = str.indexOf('\n', pos);
329
+ if (line_end === -1)
330
+ line_end = str.length;
331
+ const sp = span.span(row, error_start - line_start, pos - error_start + 1);
332
+ this.$mol_fail(new this.$mol_error_syntax(`Wrong nodes separator`, str.substring(line_start, line_end), sp));
333
+ }
334
+ var type_start = pos;
335
+ while (str.length > pos &&
336
+ str[pos] != '\\' &&
337
+ str[pos] != ' ' &&
338
+ str[pos] != '\t' &&
339
+ str[pos] != '\n') {
340
+ pos++;
341
+ }
342
+ if (pos > type_start) {
343
+ let next = new $mol_tree2(str.slice(type_start, pos), '', [], span.span(row, type_start - line_start + 1, pos - type_start));
344
+ const parent_kids = parent.kids;
345
+ parent_kids.push(next);
346
+ parent = next;
347
+ }
348
+ if (str.length > pos && str[pos] == ' ') {
349
+ pos++;
350
+ }
351
+ }
352
+ if (str.length > pos && str[pos] == '\\') {
353
+ var data_start = pos;
354
+ while (str.length > pos && str[pos] != '\n') {
355
+ pos++;
356
+ }
357
+ let next = new $mol_tree2('', str.slice(data_start + 1, pos), [], span.span(row, data_start - line_start + 2, pos - data_start - 1));
358
+ const parent_kids = parent.kids;
359
+ parent_kids.push(next);
360
+ parent = next;
361
+ }
362
+ if (str.length === pos && stack.length > 0) {
363
+ const sp = span.span(row, pos - line_start + 1, 1);
364
+ this.$mol_fail(new this.$mol_error_syntax(`Undexpected EOF, LF required`, str.substring(line_start, str.length), sp));
365
+ }
366
+ stack.push(parent);
367
+ pos++;
368
+ }
369
+ return root;
370
+ }
371
+ $.$mol_tree2_from_string = $mol_tree2_from_string;
372
+ })($ || ($ = {}));
373
+ //mol/tree2/from/string/string.ts
80
374
  ;
81
- "use strict";
82
- var $;
83
- (function ($) {
84
- $.$mol_owning_map = new WeakMap();
85
- function $mol_owning_allow(having) {
86
- try {
87
- if (!having)
88
- return false;
89
- if (typeof having !== 'object')
90
- return false;
91
- if (having instanceof $.$mol_delegate)
92
- return false;
93
- if (typeof having['destructor'] !== 'function')
94
- return false;
95
- return true;
96
- }
97
- catch (_a) {
98
- return false;
99
- }
100
- }
101
- $.$mol_owning_allow = $mol_owning_allow;
102
- function $mol_owning_get(having, Owner) {
103
- if (!$mol_owning_allow(having))
104
- return null;
105
- while (true) {
106
- const owner = $.$mol_owning_map.get(having);
107
- if (!owner)
108
- return owner;
109
- if (!Owner)
110
- return owner;
111
- if (owner instanceof Owner)
112
- return owner;
113
- having = owner;
114
- }
115
- }
116
- $.$mol_owning_get = $mol_owning_get;
117
- function $mol_owning_check(owner, having) {
118
- if (!$mol_owning_allow(having))
119
- return false;
120
- if ($.$mol_owning_map.get(having) !== owner)
121
- return false;
122
- return true;
123
- }
124
- $.$mol_owning_check = $mol_owning_check;
125
- function $mol_owning_catch(owner, having) {
126
- if (!$mol_owning_allow(having))
127
- return false;
128
- if ($.$mol_owning_map.get(having))
129
- return false;
130
- $.$mol_owning_map.set(having, owner);
131
- return true;
132
- }
133
- $.$mol_owning_catch = $mol_owning_catch;
134
- })($ || ($ = {}));
135
- //owning.js.map
375
+ "use strict";
376
+ var $;
377
+ (function ($) {
378
+ function $mol_tree2_to_string(tree) {
379
+ let output = [];
380
+ function dump(tree, prefix = '') {
381
+ if (tree.type.length) {
382
+ if (!prefix.length) {
383
+ prefix = "\t";
384
+ }
385
+ output.push(tree.type);
386
+ if (tree.kids.length == 1) {
387
+ output.push(' ');
388
+ dump(tree.kids[0], prefix);
389
+ return;
390
+ }
391
+ output.push("\n");
392
+ }
393
+ else if (tree.value.length || prefix.length) {
394
+ output.push("\\" + tree.value + "\n");
395
+ }
396
+ for (const kid of tree.kids) {
397
+ output.push(prefix);
398
+ dump(kid, prefix + "\t");
399
+ }
400
+ }
401
+ dump(tree);
402
+ return output.join('');
403
+ }
404
+ $.$mol_tree2_to_string = $mol_tree2_to_string;
405
+ })($ || ($ = {}));
406
+ //mol/tree2/to/string/string.ts
136
407
  ;
137
- "use strict";
138
- var $;
139
- (function ($) {
140
- function $mol_fail(error) {
141
- throw error;
142
- }
143
- $.$mol_fail = $mol_fail;
144
- })($ || ($ = {}));
145
- //fail.js.map
408
+ "use strict";
409
+ var $;
410
+ (function ($) {
411
+ class $mol_tree2 extends Object {
412
+ type;
413
+ value;
414
+ kids;
415
+ span;
416
+ constructor(type, value, kids, span) {
417
+ super();
418
+ this.type = type;
419
+ this.value = value;
420
+ this.kids = kids;
421
+ this.span = span;
422
+ this[Symbol.toStringTag] = type || '\\' + value;
423
+ }
424
+ static list(kids, span = $mol_span.unknown) {
425
+ return new $mol_tree2('', '', kids, span);
426
+ }
427
+ list(kids) {
428
+ return $mol_tree2.list(kids, this.span);
429
+ }
430
+ static data(value, kids = [], span = $mol_span.unknown) {
431
+ const chunks = value.split('\n');
432
+ if (chunks.length > 1) {
433
+ let kid_span = span.span(span.row, span.col, 0);
434
+ const data = chunks.map(chunk => {
435
+ kid_span = kid_span.after(chunk.length);
436
+ return new $mol_tree2('', chunk, [], kid_span);
437
+ });
438
+ kids = [...data, ...kids];
439
+ value = '';
440
+ }
441
+ return new $mol_tree2('', value, kids, span);
442
+ }
443
+ data(value, kids = []) {
444
+ return $mol_tree2.data(value, kids, this.span);
445
+ }
446
+ static struct(type, kids = [], span = $mol_span.unknown) {
447
+ if (/[ \n\t\\]/.test(type)) {
448
+ $$.$mol_fail(span.error(`Wrong type ${JSON.stringify(type)}`));
449
+ }
450
+ return new $mol_tree2(type, '', kids, span);
451
+ }
452
+ struct(type, kids = []) {
453
+ return $mol_tree2.struct(type, kids, this.span);
454
+ }
455
+ clone(kids, span = this.span) {
456
+ return new $mol_tree2(this.type, this.value, kids, span);
457
+ }
458
+ text() {
459
+ var values = [];
460
+ for (var kid of this.kids) {
461
+ if (kid.type)
462
+ continue;
463
+ values.push(kid.value);
464
+ }
465
+ return this.value + values.join('\n');
466
+ }
467
+ static fromString(str, uri = 'unknown') {
468
+ return $$.$mol_tree2_from_string(str, uri);
469
+ }
470
+ toString() {
471
+ return $$.$mol_tree2_to_string(this);
472
+ }
473
+ insert(value, ...path) {
474
+ if (path.length === 0)
475
+ return value;
476
+ const type = path[0];
477
+ if (typeof type === 'string') {
478
+ let replaced = false;
479
+ const sub = this.kids.map((item, index) => {
480
+ if (item.type !== type)
481
+ return item;
482
+ replaced = true;
483
+ return item.insert(value, ...path.slice(1));
484
+ }).filter(Boolean);
485
+ if (!replaced && value) {
486
+ sub.push(this.struct(type, []).insert(value, ...path.slice(1)));
487
+ }
488
+ return this.clone(sub);
489
+ }
490
+ else if (typeof type === 'number') {
491
+ const sub = this.kids.slice();
492
+ sub[type] = (sub[type] || this.list([]))
493
+ .insert(value, ...path.slice(1));
494
+ return this.clone(sub.filter(Boolean));
495
+ }
496
+ else {
497
+ const kids = ((this.kids.length === 0) ? [this.list([])] : this.kids)
498
+ .map(item => item.insert(value, ...path.slice(1)))
499
+ .filter(Boolean);
500
+ return this.clone(kids);
501
+ }
502
+ }
503
+ select(...path) {
504
+ let next = [this];
505
+ for (const type of path) {
506
+ if (!next.length)
507
+ break;
508
+ const prev = next;
509
+ next = [];
510
+ for (var item of prev) {
511
+ switch (typeof (type)) {
512
+ case 'string':
513
+ for (var child of item.kids) {
514
+ if (child.type == type) {
515
+ next.push(child);
516
+ }
517
+ }
518
+ break;
519
+ case 'number':
520
+ if (type < item.kids.length)
521
+ next.push(item.kids[type]);
522
+ break;
523
+ default: next.push(...item.kids);
524
+ }
525
+ }
526
+ }
527
+ return this.list(next);
528
+ }
529
+ filter(path, value) {
530
+ const sub = this.kids.filter(item => {
531
+ var found = item.select(...path);
532
+ if (value === undefined) {
533
+ return Boolean(found.kids.length);
534
+ }
535
+ else {
536
+ return found.kids.some(child => child.value == value);
537
+ }
538
+ });
539
+ return this.clone(sub);
540
+ }
541
+ hack(belt, context = {}) {
542
+ return [].concat(...this.kids.map(child => {
543
+ let handle = belt[child.type] || belt[''];
544
+ if (!handle || handle === Object.prototype[child.type]) {
545
+ handle = (input, belt, context) => [
546
+ input.clone(input.hack(belt, context), context.span)
547
+ ];
548
+ }
549
+ try {
550
+ return handle(child, belt, context);
551
+ }
552
+ catch (error) {
553
+ error.message += `\n${child.clone([])}${child.span}`;
554
+ $mol_fail_hidden(error);
555
+ }
556
+ }));
557
+ }
558
+ error(message, Class = Error) {
559
+ return this.span.error(`${message}\n${this.clone([])}`, Class);
560
+ }
561
+ }
562
+ $.$mol_tree2 = $mol_tree2;
563
+ class $mol_tree2_empty extends $mol_tree2 {
564
+ constructor() {
565
+ super('', '', [], $mol_span.unknown);
566
+ }
567
+ }
568
+ $.$mol_tree2_empty = $mol_tree2_empty;
569
+ })($ || ($ = {}));
570
+ //mol/tree2/tree2.ts
146
571
  ;
147
- "use strict";
148
- var $;
149
- (function ($) {
150
- function $mol_fail_hidden(error) {
151
- throw error;
152
- }
153
- $.$mol_fail_hidden = $mol_fail_hidden;
154
- })($ || ($ = {}));
155
- //hidden.js.map
572
+ "use strict";
573
+ var $;
574
+ (function ($) {
575
+ function $mol_tree2_from_json(json, span = $mol_span.unknown) {
576
+ if (typeof json === 'boolean' || typeof json === 'number' || json === null) {
577
+ return new $mol_tree2(String(json), '', [], span);
578
+ }
579
+ if (typeof json === 'string') {
580
+ return $mol_tree2.data(json, [], span);
581
+ }
582
+ if (Array.isArray(json)) {
583
+ const sub = json.map(json => $mol_tree2_from_json(json, span));
584
+ return new $mol_tree2('/', '', sub, span);
585
+ }
586
+ if (json instanceof Date) {
587
+ return new $mol_tree2('', json.toISOString(), [], span);
588
+ }
589
+ if (typeof json.toJSON === 'function') {
590
+ return $mol_tree2_from_json(json.toJSON());
591
+ }
592
+ if (json instanceof Error) {
593
+ const { name, message, stack } = json;
594
+ json = { ...json, name, message, stack };
595
+ }
596
+ const sub = [];
597
+ for (var key in json) {
598
+ const val = json[key];
599
+ if (val === undefined)
600
+ continue;
601
+ const subsub = $mol_tree2_from_json(val, span);
602
+ if (/^[^\n\t\\ ]+$/.test(key)) {
603
+ sub.push(new $mol_tree2(key, '', [subsub], span));
604
+ }
605
+ else {
606
+ sub.push($mol_tree2.data(key, [subsub], span));
607
+ }
608
+ }
609
+ return new $mol_tree2('*', '', sub, span);
610
+ }
611
+ $.$mol_tree2_from_json = $mol_tree2_from_json;
612
+ })($ || ($ = {}));
613
+ //mol/tree2/from/json/json.ts
156
614
  ;
157
- "use strict";
158
- //writable.js.map
615
+ "use strict";
616
+ var $;
617
+ (function ($) {
618
+ function $mol_tree2_js_to_text(js) {
619
+ function sequence(open, separator, close) {
620
+ return (input, belt) => [
621
+ ...open ? [input.data(open)] : [],
622
+ input.struct(separator && input.kids.length > 2 ? 'indent' : 'line', [].concat(...input.kids.map((kid, index) => [
623
+ kid.struct('line', [
624
+ ...kid.list([kid]).hack(belt),
625
+ ...(separator && index < input.kids.length - 1) ? [input.data(separator)] : [],
626
+ ]),
627
+ ]))),
628
+ ...close ? [input.data(close)] : [],
629
+ ];
630
+ }
631
+ function duplet(open, separator, close) {
632
+ return (input, belt) => [
633
+ ...open ? [input.data(open)] : [],
634
+ ...input.list(input.kids.slice(0, 1)).hack(belt),
635
+ ...(separator && input.kids.length > 1) ? [input.data(separator)] : [],
636
+ ...input.list(input.kids.slice(1, 2)).hack(belt),
637
+ ...close ? [input.data(close)] : [],
638
+ ];
639
+ }
640
+ function triplet(open, separator12, separator23, close) {
641
+ return (input, belt) => [
642
+ ...open ? [input.data(open)] : [],
643
+ ...input.list(input.kids.slice(0, 1)).hack(belt),
644
+ ...(separator12 && input.kids.length > 1) ? [input.data(separator12)] : [],
645
+ ...input.list(input.kids.slice(1, 2)).hack(belt),
646
+ ...(separator23 && input.kids.length > 2) ? [input.data(separator23)] : [],
647
+ ...input.list(input.kids.slice(2, 3)).hack(belt),
648
+ ...close ? [input.data(close)] : [],
649
+ ];
650
+ }
651
+ return js.list([js.struct('line', js.hack({
652
+ '+': sequence('+'),
653
+ '-': sequence('-'),
654
+ '!': sequence('!'),
655
+ '~': sequence('~'),
656
+ 'return': sequence('return '),
657
+ 'break': sequence('break '),
658
+ 'continue': sequence('continue '),
659
+ 'yield': sequence('yield '),
660
+ 'yield*': sequence('yield* '),
661
+ 'await': sequence('await '),
662
+ 'void': sequence('void '),
663
+ 'delete': sequence('delete '),
664
+ 'typeof': sequence('typeof '),
665
+ 'new': sequence('new '),
666
+ '...': sequence('...'),
667
+ '@++': sequence('', '', '++'),
668
+ '@--': sequence('', '', '--'),
669
+ '(in)': sequence('(', ' in ', ')'),
670
+ '(instanceof)': sequence('(', ' instanceof ', ')'),
671
+ '(+)': sequence('(', ' + ', ')'),
672
+ '(-)': sequence('(', ' - ', ')'),
673
+ '(*)': sequence('(', ' * ', ')'),
674
+ '(/)': sequence('(', ' / ', ')'),
675
+ '(%)': sequence('(', ' % ', ')'),
676
+ '(**)': sequence('(', ' ** ', ')'),
677
+ '(<)': sequence('(', ' < ', ')'),
678
+ '(<=)': sequence('(', ' <= ', ')'),
679
+ '(>)': sequence('(', ' > ', ')'),
680
+ '(>=)': sequence('(', ' >= ', ')'),
681
+ '(==)': sequence('(', ' == ', ')'),
682
+ '(!=)': sequence('(', ' != ', ')'),
683
+ '(===)': sequence('(', ' === ', ')'),
684
+ '(!==)': sequence('(', ' !== ', ')'),
685
+ '(<<)': sequence('(', ' << ', ')'),
686
+ '(>>)': sequence('(', ' >> ', ')'),
687
+ '(>>>)': sequence('(', ' >>> ', ')'),
688
+ '(&)': sequence('(', ' & ', ')'),
689
+ '(|)': sequence('(', ' | ', ')'),
690
+ '(^)': sequence('(', ' ^ ', ')'),
691
+ '(&&)': sequence('(', ' && ', ')'),
692
+ '(||)': sequence('(', ' || ', ')'),
693
+ '(,)': sequence('(', ', ', ')'),
694
+ '{;}': sequence('{', '; ', '}'),
695
+ ';': sequence('', ';', ''),
696
+ '[,]': sequence('[', ', ', ']'),
697
+ '{,}': sequence('{', ', ', '}'),
698
+ '()': sequence('(', '', ')'),
699
+ '{}': sequence('{', '', '}'),
700
+ '[]': (input, belt) => {
701
+ const first = input.kids[0];
702
+ if (first.type)
703
+ return sequence('[', '', ']')(input, belt);
704
+ else
705
+ return [input.data('.' + first.text())];
706
+ },
707
+ ':': (input, belt) => {
708
+ const first = input.kids[0];
709
+ if (first.type)
710
+ return duplet('[', ']: ')(input, belt);
711
+ else
712
+ return duplet('', ': ')(input, belt);
713
+ },
714
+ 'let': duplet('let ', ' = '),
715
+ 'const': duplet('const ', ' = '),
716
+ 'var': duplet('var ', ' = '),
717
+ '=': duplet('', ' = '),
718
+ '+=': duplet('', ' += '),
719
+ '-=': duplet('', ' -= '),
720
+ '*=': duplet('', ' *= '),
721
+ '/=': duplet('', ' /= '),
722
+ '%=': duplet('', ' %= '),
723
+ '**=': duplet('', ' **= '),
724
+ '<<=': duplet('', ' <<= '),
725
+ '>>=': duplet('', ' >>= '),
726
+ '>>>=': duplet('', ' >>>= '),
727
+ '&=': duplet('', ' &= '),
728
+ '|=': duplet('', ' |= '),
729
+ '^=': duplet('', ' ^= '),
730
+ '&&=': duplet('', ' &&= '),
731
+ '||=': duplet('', ' ||= '),
732
+ '=>': duplet('', ' => '),
733
+ 'async=>': duplet('async ', ' => '),
734
+ 'function': triplet('function '),
735
+ 'function*': triplet('function* '),
736
+ 'async': triplet('async function '),
737
+ 'async*': triplet('async function* '),
738
+ 'class': triplet('class ', ' '),
739
+ 'extends': sequence('extends ', '', ' '),
740
+ 'if': triplet('if', ' ', 'else'),
741
+ '?:': triplet('', ' ? ', ' : '),
742
+ '.': (input, belt) => {
743
+ const first = input.kids[0];
744
+ if (first.type)
745
+ return triplet('[', ']')(input, belt);
746
+ else
747
+ return [
748
+ input.data(first.text()),
749
+ ...input.list(input.kids.slice(1)).hack(belt),
750
+ ];
751
+ },
752
+ 'get': triplet('get [', ']'),
753
+ 'set': triplet('set [', ']'),
754
+ 'static': triplet('static [', ']'),
755
+ '/./': sequence(),
756
+ '.global': sequence('g'),
757
+ '.multiline': sequence('m'),
758
+ '.ignoreCase': sequence('i'),
759
+ '.source': (input, belt) => [
760
+ input.data('/'),
761
+ input.data(JSON.stringify(input.text()).slice(1, -1)),
762
+ input.data('/'),
763
+ ],
764
+ '``': (input, belt) => {
765
+ return [
766
+ input.data('`'),
767
+ ...[].concat(...input.kids.map(kid => {
768
+ if (kid.type) {
769
+ return [
770
+ kid.data('${'),
771
+ ...kid.list([kid]).hack(belt),
772
+ kid.data('}'),
773
+ ];
774
+ }
775
+ else {
776
+ return [
777
+ input.data(JSON.stringify(kid.text()).slice(1, -1)),
778
+ ];
779
+ }
780
+ })),
781
+ input.data('`'),
782
+ ];
783
+ },
784
+ '': (input, belt) => {
785
+ if (!input.type)
786
+ return [
787
+ input.data(JSON.stringify(input.text())),
788
+ ];
789
+ if (/^[\w$#][\w0-9$]*$/i.test(input.type))
790
+ return [
791
+ input.data(input.type),
792
+ ];
793
+ if (input.type === 'NaN' || !Number.isNaN(Number(input.type)))
794
+ return [
795
+ input.data(input.type)
796
+ ];
797
+ $mol_fail(new SyntaxError(`Wrong node type`));
798
+ },
799
+ }))]);
800
+ }
801
+ $.$mol_tree2_js_to_text = $mol_tree2_js_to_text;
802
+ })($ || ($ = {}));
803
+ //mol/tree2/js/to/text/text.ts
159
804
  ;
160
- "use strict";
161
- var $;
162
- (function ($) {
163
- var _a;
164
- class $mol_object2 {
165
- constructor(init) {
166
- this[_a] = null;
167
- if (init)
168
- init(this);
169
- }
170
- get $() {
171
- if (this[$.$mol_ambient_ref])
172
- return this[$.$mol_ambient_ref];
173
- const owner = $.$mol_owning_get(this);
174
- return this[$.$mol_ambient_ref] = (owner === null || owner === void 0 ? void 0 : owner.$) || $mol_object2.$;
175
- }
176
- set $(next) {
177
- if (this[$.$mol_ambient_ref])
178
- $.$mol_fail_hidden(new Error('Context already defined'));
179
- this[$.$mol_ambient_ref] = next;
180
- }
181
- static create(init) {
182
- return new this(init);
183
- }
184
- static [(_a = $.$mol_ambient_ref, Symbol.toPrimitive)]() {
185
- return this.toString();
186
- }
187
- static toString() {
188
- if (Symbol.toStringTag in this)
189
- return this[Symbol.toStringTag];
190
- return this.name;
191
- }
192
- destructor() { }
193
- [Symbol.toPrimitive](hint) {
194
- return hint === 'number' ? this.valueOf() : this.toString();
195
- }
196
- toString() {
197
- return this[Symbol.toStringTag] || this.constructor.name + '()';
198
- }
199
- toJSON() {
200
- return this.toString();
201
- }
202
- }
203
- $mol_object2.$ = $;
204
- $.$mol_object2 = $mol_object2;
205
- })($ || ($ = {}));
206
- //object2.js.map
805
+ "use strict";
806
+ var $;
807
+ (function ($) {
808
+ function $mol_tree2_span_imprint(tree) {
809
+ const sources = new Map();
810
+ const res = tree.clone(tree.hack({
811
+ '': (input, belt) => {
812
+ if (!sources.has(input.span.uri)) {
813
+ sources.set(input.span.uri, tree.struct(input.span.uri, [
814
+ tree.data(input.span.source)
815
+ ]));
816
+ }
817
+ return [
818
+ input.clone([
819
+ input.data(input.span.toString()),
820
+ ...input.hack(belt),
821
+ ]),
822
+ ];
823
+ },
824
+ }));
825
+ return tree.clone([
826
+ ...sources.values(),
827
+ res,
828
+ ]);
829
+ }
830
+ $.$mol_tree2_span_imprint = $mol_tree2_span_imprint;
831
+ })($ || ($ = {}));
832
+ //mol/tree2/span/imprint/imprint.ts
207
833
  ;
208
- "use strict";
209
- var $;
210
- (function ($) {
211
- class $mol_span extends $.$mol_object2 {
212
- constructor(uri, source, row, col, length) {
213
- super();
214
- this.uri = uri;
215
- this.source = source;
216
- this.row = row;
217
- this.col = col;
218
- this.length = length;
219
- this[Symbol.toStringTag] = `${this.uri}#${this.row}:${this.col}/${this.length}`;
220
- }
221
- static begin(uri, source = '') {
222
- return new $mol_span(uri, source, 1, 1, 0);
223
- }
224
- static end(uri, source) {
225
- return new $mol_span(uri, source, 1, source.length + 1, length);
226
- }
227
- static entire(uri, source) {
228
- return new $mol_span(uri, source, 1, 1, source.length);
229
- }
230
- toString() {
231
- return this[Symbol.toStringTag];
232
- }
233
- toJSON() {
234
- return {
235
- uri: this.uri,
236
- row: this.row,
237
- col: this.col,
238
- length: this.length
239
- };
240
- }
241
- error(message, Class = Error) {
242
- return new Class(`${message}${this}`);
243
- }
244
- span(row, col, length) {
245
- return new $mol_span(this.uri, this.source, row, col, length);
246
- }
247
- after(length = 0) {
248
- return new $mol_span(this.uri, this.source, this.row, this.col + this.length, length);
249
- }
250
- slice(begin, end = -1) {
251
- let len = this.length;
252
- if (begin < 0)
253
- begin += len;
254
- if (end < 0)
255
- end += len;
256
- if (begin < 0 || begin > len)
257
- this.$.$mol_fail(`Begin value '${begin}' out of range ${this}`);
258
- if (end < 0 || end > len)
259
- this.$.$mol_fail(`End value '${end}' out of range ${this}`);
260
- if (end < begin)
261
- this.$.$mol_fail(`End value '${end}' can't be less than begin value ${this}`);
262
- return this.span(this.row, this.col + begin, end - begin);
263
- }
264
- }
265
- $mol_span.unknown = $mol_span.begin('unknown');
266
- $.$mol_span = $mol_span;
267
- })($ || ($ = {}));
268
- //span.js.map
834
+ "use strict";
835
+ var $;
836
+ (function ($) {
837
+ function $mol_tree2_span_reuse(tree) {
838
+ const sources = new Map();
839
+ return tree.clone(tree.hack({
840
+ '': (input, belt) => {
841
+ if (input.type) {
842
+ sources.set(input.type, input.kids[0].text());
843
+ return [];
844
+ }
845
+ return input.hack({
846
+ '': (input, belt) => {
847
+ const kids = input.list(input.kids.slice(1)).hack(belt);
848
+ const [_, uri, row, col, length] = /^(.*)#(\d+):(\d+)\/(\d+)$/.exec(input.kids[0].text());
849
+ const span = new $mol_span(uri, sources.get(uri), Number(row), Number(col), Number(length));
850
+ return [
851
+ new $mol_tree2(input.type, input.value, kids, span),
852
+ ];
853
+ },
854
+ });
855
+ },
856
+ }));
857
+ }
858
+ $.$mol_tree2_span_reuse = $mol_tree2_span_reuse;
859
+ })($ || ($ = {}));
860
+ //mol/tree2/span/reuse/reuse.ts
269
861
  ;
270
- "use strict";
271
- var $;
272
- (function ($) {
273
- function $mol_log3_area_lazy(event) {
274
- const self = this;
275
- const stack = self.$mol_log3_stack;
276
- const deep = stack.length;
277
- let logged = false;
278
- stack.push(() => {
279
- logged = true;
280
- self.$mol_log3_area.call(self, event);
281
- });
282
- return () => {
283
- if (logged)
284
- self.console.groupEnd();
285
- if (stack.length > deep)
286
- stack.length = deep;
287
- };
288
- }
289
- $.$mol_log3_area_lazy = $mol_log3_area_lazy;
290
- $.$mol_log3_stack = [];
291
- })($ || ($ = {}));
292
- //log3.js.map
862
+ "use strict";
863
+ var $;
864
+ (function ($) {
865
+ function $mol_tree2_text_to_string(text) {
866
+ let res = '';
867
+ function visit(text, prefix, inline) {
868
+ if (text.type === 'indent') {
869
+ if (inline)
870
+ res += '\n';
871
+ for (let kid of text.kids) {
872
+ visit(kid, prefix + '\t', false);
873
+ }
874
+ if (inline)
875
+ res += prefix;
876
+ }
877
+ else if (text.type === 'line') {
878
+ if (!inline)
879
+ res += prefix;
880
+ for (let kid of text.kids) {
881
+ visit(kid, prefix, true);
882
+ }
883
+ if (!inline)
884
+ res += '\n';
885
+ }
886
+ else {
887
+ if (!inline)
888
+ res += prefix;
889
+ res += text.text();
890
+ if (!inline)
891
+ res += '\n';
892
+ }
893
+ }
894
+ for (let kid of text.kids) {
895
+ visit(kid, '', false);
896
+ }
897
+ return res;
898
+ }
899
+ $.$mol_tree2_text_to_string = $mol_tree2_text_to_string;
900
+ })($ || ($ = {}));
901
+ //mol/tree2/text/to/string/string.ts
293
902
  ;
294
- "use strict";
295
- var $;
296
- (function ($) {
297
- function $mol_log3_web_make(level, color) {
298
- return function $mol_log3_logger(event) {
299
- const pending = this.$mol_log3_stack.pop();
300
- if (pending)
301
- pending();
302
- let tpl = '%c';
303
- const chunks = Object.values(event);
304
- for (let i = 0; i < chunks.length; ++i) {
305
- tpl += (typeof chunks[i] === 'string') ? ' ⦙ %s' : ' ⦙ %o';
306
- }
307
- const style = `color:${color};font-weight:bolder`;
308
- this.console[level](tpl, style, ...chunks);
309
- const self = this;
310
- return () => self.console.groupEnd();
311
- };
312
- }
313
- $.$mol_log3_web_make = $mol_log3_web_make;
314
- $.$mol_log3_come = $mol_log3_web_make('info', 'royalblue');
315
- $.$mol_log3_done = $mol_log3_web_make('info', 'forestgreen');
316
- $.$mol_log3_fail = $mol_log3_web_make('error', 'orangered');
317
- $.$mol_log3_warn = $mol_log3_web_make('warn', 'goldenrod');
318
- $.$mol_log3_rise = $mol_log3_web_make('log', 'magenta');
319
- $.$mol_log3_area = $mol_log3_web_make('group', 'cyan');
320
- })($ || ($ = {}));
321
- //log3.web.js.map
903
+ "use strict";
904
+ var $;
905
+ (function ($) {
906
+ const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
907
+ function $mol_vlq_encode(val) {
908
+ const sign = val < 0 ? 1 : 0;
909
+ if (sign)
910
+ val = -val;
911
+ let index = sign | ((val & 0b1111) << 1);
912
+ val >>>= 4;
913
+ let res = '';
914
+ while (val) {
915
+ index |= 1 << 5;
916
+ res += alphabet[index];
917
+ if (!val)
918
+ break;
919
+ index = val & 0b11111;
920
+ val >>>= 5;
921
+ }
922
+ res += alphabet[index];
923
+ return res;
924
+ }
925
+ $.$mol_vlq_encode = $mol_vlq_encode;
926
+ })($ || ($ = {}));
927
+ //mol/vlq/vlq.ts
928
+ ;
929
+ "use strict";
930
+ var $;
931
+ (function ($) {
932
+ function $mol_tree2_text_to_sourcemap(tree) {
933
+ let col = 1;
934
+ let prev_span;
935
+ let prev_index = 0;
936
+ let prev_col = 1;
937
+ let mappings = '';
938
+ let line = [];
939
+ const file_indexes = new Map();
940
+ const file_sources = new Map();
941
+ function span2index(span) {
942
+ if (file_indexes.has(span.uri))
943
+ return file_indexes.get(span.uri);
944
+ const index = file_indexes.size;
945
+ file_indexes.set(span.uri, index);
946
+ file_sources.set(span.uri, span.source);
947
+ return index;
948
+ }
949
+ function next_line() {
950
+ if (!line.length)
951
+ return;
952
+ mappings += line.join(',') + ';';
953
+ line = [];
954
+ col = 1;
955
+ prev_col = 1;
956
+ }
957
+ function visit(text, prefix, inline) {
958
+ function indent() {
959
+ col += prefix;
960
+ }
961
+ if (inline && text.type === 'indent')
962
+ next_line();
963
+ if (prev_span !== text.span || col === 1) {
964
+ const index = span2index(text.span);
965
+ line.push($mol_vlq_encode(col - prev_col) +
966
+ $mol_vlq_encode(index - prev_index) +
967
+ $mol_vlq_encode(text.span.row - (prev_span?.row ?? 1)) +
968
+ $mol_vlq_encode(text.span.col - (prev_span?.col ?? 1)));
969
+ prev_col = col;
970
+ prev_span = text.span;
971
+ prev_index = index;
972
+ }
973
+ if (text.type === 'indent') {
974
+ for (let kid of text.kids) {
975
+ visit(kid, prefix + 1, false);
976
+ }
977
+ if (inline)
978
+ indent();
979
+ }
980
+ else if (text.type === 'line') {
981
+ if (!inline)
982
+ indent();
983
+ for (let kid of text.kids) {
984
+ visit(kid, prefix, true);
985
+ }
986
+ if (!inline)
987
+ next_line();
988
+ }
989
+ else {
990
+ if (!inline)
991
+ indent();
992
+ col += text.text().length;
993
+ if (!inline)
994
+ next_line();
995
+ }
996
+ }
997
+ for (let kid of tree.kids) {
998
+ visit(kid, 0, false);
999
+ }
1000
+ next_line();
1001
+ const map = {
1002
+ version: 3,
1003
+ sources: [...file_sources.keys()],
1004
+ sourcesContent: [...file_sources.values()],
1005
+ mappings,
1006
+ };
1007
+ return map;
1008
+ }
1009
+ $.$mol_tree2_text_to_sourcemap = $mol_tree2_text_to_sourcemap;
1010
+ })($ || ($ = {}));
1011
+ //mol/tree2/text/to/sourcemap/sourcemap.ts
322
1012
  ;
323
- "use strict";
324
- var $;
325
- (function ($) {
326
- function $mol_deprecated(message) {
327
- return (host, field, descr) => {
328
- const value = descr.value;
329
- let warned = false;
330
- descr.value = function $mol_deprecated_wrapper(...args) {
331
- if (!warned) {
332
- this.$.$mol_log3_warn({
333
- place: `${host.constructor.name}::${field}`,
334
- message: `Deprecated`,
335
- hint: message,
336
- });
337
- warned = true;
338
- }
339
- return value.call(this, ...args);
340
- };
341
- };
342
- }
343
- $.$mol_deprecated = $mol_deprecated;
344
- })($ || ($ = {}));
345
- //deprecated.js.map
1013
+ "use strict";
1014
+ var $;
1015
+ (function ($) {
1016
+ function $mol_tree2_text_to_string_mapped(text, type) {
1017
+ const code = this.$mol_tree2_text_to_string(text);
1018
+ const map = this.$mol_tree2_text_to_sourcemap(text);
1019
+ map.mappings = ';;' + map.mappings;
1020
+ let res = code;
1021
+ const map_uri = `data:application/json,${this.encodeURIComponent(JSON.stringify(map))}`;
1022
+ if (type === 'js')
1023
+ res += `\n//# sourceMappingURL=${map_uri}`;
1024
+ else
1025
+ res += `\n/*# sourceMappingURL=${map_uri} */`;
1026
+ return res;
1027
+ }
1028
+ $.$mol_tree2_text_to_string_mapped = $mol_tree2_text_to_string_mapped;
1029
+ function $mol_tree2_text_to_string_mapped_js(text) {
1030
+ return this.$mol_tree2_text_to_string_mapped(text, 'js');
1031
+ }
1032
+ $.$mol_tree2_text_to_string_mapped_js = $mol_tree2_text_to_string_mapped_js;
1033
+ function $mol_tree2_text_to_string_mapped_css(text) {
1034
+ return this.$mol_tree2_text_to_string_mapped(text, 'css');
1035
+ }
1036
+ $.$mol_tree2_text_to_string_mapped_css = $mol_tree2_text_to_string_mapped_css;
1037
+ })($ || ($ = {}));
1038
+ //mol/tree2/text/to/string/mapped/mapped.ts
346
1039
  ;
347
- "use strict";
348
- var $;
349
- (function ($) {
350
- class $mol_tree2 extends $.$mol_object2 {
351
- constructor(type, value, kids, span) {
352
- super();
353
- this.type = type;
354
- this.value = value;
355
- this.kids = kids;
356
- this.span = span;
357
- this[Symbol.toStringTag] = type || '\\' + value;
358
- }
359
- static list(kids, span = $.$mol_span.unknown) {
360
- return new $mol_tree2('', '', kids, span);
361
- }
362
- list(kids) {
363
- return $mol_tree2.list(kids, this.span);
364
- }
365
- static data(value, kids = [], span = $.$mol_span.unknown) {
366
- const chunks = value.split('\n');
367
- if (chunks.length > 1) {
368
- let kid_span = span.span(span.row, span.col, 0);
369
- const data = chunks.map(chunk => {
370
- kid_span = kid_span.after(chunk.length);
371
- return new $mol_tree2('', chunk, [], kid_span);
372
- });
373
- kids = [...data, ...kids];
374
- value = '';
375
- }
376
- return new $mol_tree2('', value, kids, span);
377
- }
378
- data(value, kids = []) {
379
- return $mol_tree2.data(value, kids, this.span);
380
- }
381
- static struct(type, kids = [], span = $.$mol_span.unknown) {
382
- if (/[ \n\t\\]/.test(type)) {
383
- this.$.$mol_fail(span.error(`Wrong type ${JSON.stringify(type)}`));
384
- }
385
- return new $mol_tree2(type, '', kids, span);
386
- }
387
- struct(type, kids = []) {
388
- return $mol_tree2.struct(type, kids, this.span);
389
- }
390
- clone(kids, span = this.span) {
391
- return new $mol_tree2(this.type, this.value, kids, span);
392
- }
393
- text() {
394
- var values = [];
395
- for (var kid of this.kids) {
396
- if (kid.type)
397
- continue;
398
- values.push(kid.value);
399
- }
400
- return this.value + values.join('\n');
401
- }
402
- static fromString(str, uri = 'unknown') {
403
- return this.$.$mol_tree2_from_string(str, uri);
404
- }
405
- toString() {
406
- return this.$.$mol_tree2_to_string(this);
407
- }
408
- insert(value, ...path) {
409
- if (path.length === 0)
410
- return value;
411
- const type = path[0];
412
- if (typeof type === 'string') {
413
- let replaced = false;
414
- const sub = this.kids.map((item, index) => {
415
- if (item.type !== type)
416
- return item;
417
- replaced = true;
418
- return item.insert(value, ...path.slice(1));
419
- });
420
- if (!replaced) {
421
- sub.push(this.struct(type, []).insert(value, ...path.slice(1)));
422
- }
423
- return this.clone(sub);
424
- }
425
- else if (typeof type === 'number') {
426
- const sub = this.kids.slice();
427
- sub[type] = (sub[type] || this.list([])).insert(value, ...path.slice(1));
428
- return this.clone(sub);
429
- }
430
- else {
431
- const kids = ((this.kids.length === 0) ? [this.list([])] : this.kids)
432
- .map(item => item.insert(value, ...path.slice(1)));
433
- return this.clone(kids);
434
- }
435
- }
436
- select(...path) {
437
- let next = [this];
438
- for (const type of path) {
439
- if (!next.length)
440
- break;
441
- const prev = next;
442
- next = [];
443
- for (var item of prev) {
444
- switch (typeof (type)) {
445
- case 'string':
446
- for (var child of item.kids) {
447
- if (!type || (child.type == type)) {
448
- next.push(child);
449
- }
450
- }
451
- break;
452
- case 'number':
453
- if (type < item.kids.length)
454
- next.push(item.kids[type]);
455
- break;
456
- default: next.push(...item.kids);
457
- }
458
- }
459
- }
460
- return this.list(next);
461
- }
462
- filter(path, value) {
463
- const sub = this.kids.filter(item => {
464
- var found = item.select(...path);
465
- if (value === undefined) {
466
- return Boolean(found.kids.length);
467
- }
468
- else {
469
- return found.kids.some(child => child.value == value);
470
- }
471
- });
472
- return this.clone(sub);
473
- }
474
- hack(belt, context = {}) {
475
- return [].concat(...this.kids.map(child => {
476
- let handle = belt[child.type] || belt[''];
477
- if (!handle || handle === Object.prototype[child.type]) {
478
- handle = (input, belt, context) => [
479
- input.clone(input.hack(belt, context), context.span)
480
- ];
481
- }
482
- try {
483
- return handle(child, belt, context);
484
- }
485
- catch (error) {
486
- error.message += `\n${child.clone([])}${child.span}`;
487
- $.$mol_fail_hidden(error);
488
- }
489
- }));
490
- }
491
- error(message, Class = Error) {
492
- return this.span.error(`${message}\n${this.clone([])}`, Class);
493
- }
494
- }
495
- __decorate([
496
- $.$mol_deprecated('Use $mol_tree2_from_string')
497
- ], $mol_tree2, "fromString", null);
498
- $.$mol_tree2 = $mol_tree2;
499
- class $mol_tree2_empty extends $mol_tree2 {
500
- constructor() {
501
- super('', '', [], $.$mol_span.unknown);
502
- }
503
- }
504
- $.$mol_tree2_empty = $mol_tree2_empty;
505
- })($ || ($ = {}));
506
- //tree2.js.map
1040
+ "use strict";
1041
+ var $;
1042
+ (function ($) {
1043
+ function $mol_tree2_text_to_sourcemap_vis(text) {
1044
+ const code = this.$mol_tree2_text_to_string(text);
1045
+ const map = this.$mol_tree2_text_to_sourcemap(text);
1046
+ const uri = [
1047
+ 'https://sokra.github.io/source-map-visualization/#base64',
1048
+ btoa(code),
1049
+ btoa(JSON.stringify(map)),
1050
+ ...map.sourcesContent.map(btoa),
1051
+ ].join(',');
1052
+ return uri;
1053
+ }
1054
+ $.$mol_tree2_text_to_sourcemap_vis = $mol_tree2_text_to_sourcemap_vis;
1055
+ })($ || ($ = {}));
1056
+ //mol/tree2/text/to/sourcemap/vis/vis.ts
507
1057
  ;
508
- "use strict";
509
- var $;
510
- (function ($) {
511
- class $mol_error_syntax extends SyntaxError {
512
- constructor(reason, line, span) {
513
- super(`${reason}\n${span}\n${line.substring(0, span.col - 1).replace(/\S/g, ' ')}${''.padEnd(span.length, '!')}\n${line}`);
514
- this.reason = reason;
515
- this.line = line;
516
- this.span = span;
517
- }
518
- }
519
- $.$mol_error_syntax = $mol_error_syntax;
520
- })($ || ($ = {}));
521
- //syntax.js.map
1058
+ "use strict";
1059
+ var $;
1060
+ (function ($) {
1061
+ function $mol_tree2_xml_from_dom(dom) {
1062
+ switch (dom.nodeType) {
1063
+ case dom.DOCUMENT_NODE: {
1064
+ let kids = [];
1065
+ for (const kid of dom.childNodes) {
1066
+ kids.push($mol_tree2_xml_from_dom(kid));
1067
+ }
1068
+ return $mol_tree2.list(kids);
1069
+ }
1070
+ case dom.PROCESSING_INSTRUCTION_NODE: {
1071
+ return $mol_tree2.struct('?', [
1072
+ $mol_tree2.struct(dom.nodeName, dom.nodeValue.split(' ').map(chunk => {
1073
+ const [, name, value] = /^(.*?)(?:="(.*?)")?$/.exec(chunk);
1074
+ const kids = value ? [$mol_tree2.data(value)] : [];
1075
+ return $mol_tree2.struct(name, kids);
1076
+ }))
1077
+ ]);
1078
+ }
1079
+ case dom.DOCUMENT_TYPE_NODE: {
1080
+ const dom2 = dom;
1081
+ return $mol_tree2.struct('!', [
1082
+ $mol_tree2.struct('DOCTYPE', [
1083
+ $mol_tree2.struct(dom2.name)
1084
+ ])
1085
+ ]);
1086
+ }
1087
+ case dom.ELEMENT_NODE: {
1088
+ let kids = [];
1089
+ for (const attr of dom.attributes) {
1090
+ kids.push($mol_tree2.struct('@', [
1091
+ $mol_tree2.struct(attr.nodeName, [
1092
+ $mol_tree2.data(attr.nodeValue)
1093
+ ])
1094
+ ]));
1095
+ }
1096
+ for (const kid of dom.childNodes) {
1097
+ const k = $mol_tree2_xml_from_dom(kid);
1098
+ if (k.type || k.value)
1099
+ kids.push(k);
1100
+ }
1101
+ return $mol_tree2.struct(dom.nodeName, kids);
1102
+ }
1103
+ case dom.COMMENT_NODE: {
1104
+ return $mol_tree2.struct('--', [
1105
+ $mol_tree2.data(dom.nodeValue)
1106
+ ]);
1107
+ }
1108
+ case dom.TEXT_NODE: {
1109
+ if (!dom.nodeValue.trim())
1110
+ return $mol_tree2.list([]);
1111
+ return $mol_tree2.data(dom.nodeValue.replace(/\s+/g, ' '));
1112
+ }
1113
+ }
1114
+ return $mol_fail(new Error(`Unsupported node ${dom.nodeName}`));
1115
+ }
1116
+ $.$mol_tree2_xml_from_dom = $mol_tree2_xml_from_dom;
1117
+ })($ || ($ = {}));
1118
+ //mol/tree2/xml/from/dom/dom.ts
522
1119
  ;
523
- "use strict";
524
- var $;
525
- (function ($) {
526
- function $mol_tree2_from_string(str, uri = 'unknown') {
527
- const span = $.$mol_span.entire(uri, str);
528
- var root = $.$mol_tree2.list([], span);
529
- var stack = [root];
530
- var pos = 0, row = 0, min_indent = 0;
531
- while (str.length > pos) {
532
- var indent = 0;
533
- var line_start = pos;
534
- row++;
535
- while (str.length > pos && str[pos] == '\t') {
536
- indent++;
537
- pos++;
538
- }
539
- if (!root.kids.length) {
540
- min_indent = indent;
541
- }
542
- indent -= min_indent;
543
- if (indent < 0 || indent >= stack.length) {
544
- const sp = span.span(row, 1, pos - line_start);
545
- while (str.length > pos && str[pos] != '\n') {
546
- pos++;
547
- }
548
- if (indent < 0) {
549
- if (str.length > pos) {
550
- this.$mol_fail(new this.$mol_error_syntax(`Too few tabs`, str.substring(line_start, pos), sp));
551
- }
552
- }
553
- else {
554
- this.$mol_fail(new this.$mol_error_syntax(`Too many tabs`, str.substring(line_start, pos), sp));
555
- }
556
- }
557
- stack.length = indent + 1;
558
- var parent = stack[indent];
559
- while (str.length > pos && str[pos] != '\\' && str[pos] != '\n') {
560
- var error_start = pos;
561
- while (str.length > pos && (str[pos] == ' ' || str[pos] == '\t')) {
562
- pos++;
563
- }
564
- if (pos > error_start) {
565
- let line_end = str.indexOf('\n', pos);
566
- if (line_end === -1)
567
- line_end = str.length;
568
- const sp = span.span(row, error_start - line_start, pos - error_start + 1);
569
- this.$mol_fail(new this.$mol_error_syntax(`Wrong nodes separator`, str.substring(line_start, line_end), sp));
570
- }
571
- var type_start = pos;
572
- while (str.length > pos &&
573
- str[pos] != '\\' &&
574
- str[pos] != ' ' &&
575
- str[pos] != '\t' &&
576
- str[pos] != '\n') {
577
- pos++;
578
- }
579
- if (pos > type_start) {
580
- let next = new $.$mol_tree2(str.slice(type_start, pos), '', [], span.span(row, type_start - line_start + 1, pos - type_start));
581
- const parent_kids = parent.kids;
582
- parent_kids.push(next);
583
- parent = next;
584
- }
585
- if (str.length > pos && str[pos] == ' ') {
586
- pos++;
587
- }
588
- }
589
- if (str.length > pos && str[pos] == '\\') {
590
- var data_start = pos;
591
- while (str.length > pos && str[pos] != '\n') {
592
- pos++;
593
- }
594
- let next = new $.$mol_tree2('', str.slice(data_start + 1, pos), [], span.span(row, data_start - line_start + 1, pos - data_start - 1));
595
- const parent_kids = parent.kids;
596
- parent_kids.push(next);
597
- parent = next;
598
- }
599
- if (str.length === pos && stack.length > 0) {
600
- const sp = span.span(row, pos - line_start + 1, 1);
601
- this.$mol_fail(new this.$mol_error_syntax(`Undexpected EOF, LF required`, str.substring(line_start, str.length), sp));
602
- }
603
- stack.push(parent);
604
- pos++;
605
- }
606
- return root;
607
- }
608
- $.$mol_tree2_from_string = $mol_tree2_from_string;
609
- })($ || ($ = {}));
610
- //string.js.map
1120
+ "use strict";
1121
+ var $;
1122
+ (function ($) {
1123
+ const mapping = {
1124
+ '<': '&lt;',
1125
+ '>': '&gt;',
1126
+ '"': '&quot;',
1127
+ '&': '&amp;',
1128
+ };
1129
+ function $mol_html_encode(text) {
1130
+ return text.replace(/[&<">]/gi, str => mapping[str]);
1131
+ }
1132
+ $.$mol_html_encode = $mol_html_encode;
1133
+ })($ || ($ = {}));
1134
+ //mol/html/encode/encode.ts
611
1135
  ;
612
- "use strict";
613
- var $;
614
- (function ($) {
615
- function $mol_tree2_to_string(tree) {
616
- let output = [];
617
- function dump(tree, prefix = '') {
618
- if (tree.type.length) {
619
- if (!prefix.length) {
620
- prefix = "\t";
621
- }
622
- output.push(tree.type);
623
- if (tree.kids.length == 1) {
624
- output.push(' ');
625
- dump(tree.kids[0], prefix);
626
- return;
627
- }
628
- output.push("\n");
629
- }
630
- else if (tree.value.length || prefix.length) {
631
- output.push("\\" + tree.value + "\n");
632
- }
633
- for (const kid of tree.kids) {
634
- output.push(prefix);
635
- dump(kid, prefix + "\t");
636
- }
637
- }
638
- dump(tree);
639
- return output.join('');
640
- }
641
- $.$mol_tree2_to_string = $mol_tree2_to_string;
642
- })($ || ($ = {}));
643
- //string.js.map
1136
+ "use strict";
1137
+ var $;
1138
+ (function ($) {
1139
+ function attrs_belt(separator) {
1140
+ return {
1141
+ '': (input) => [
1142
+ input.data(' '),
1143
+ input.data($mol_html_encode(input.type)),
1144
+ ...input.value ? [
1145
+ input.data('"'),
1146
+ input.data($mol_html_encode(input.value)),
1147
+ input.data('"'),
1148
+ ] : [],
1149
+ ...input.hack({
1150
+ '': (input) => {
1151
+ if (!input.type)
1152
+ return [
1153
+ input.data(separator),
1154
+ input.data('"'),
1155
+ input.data($mol_html_encode(input.text())),
1156
+ input.data('"'),
1157
+ ];
1158
+ $mol_fail(new SyntaxError('Wrong attribute value'));
1159
+ },
1160
+ }),
1161
+ ],
1162
+ };
1163
+ }
1164
+ function $mol_tree2_xml_to_text(xml) {
1165
+ return xml.list(xml.hack({
1166
+ '@': (input, belt) => [],
1167
+ '--': (input, belt) => [
1168
+ xml.struct('line', [
1169
+ input.data('<!-- '),
1170
+ ...input.hack(belt),
1171
+ input.data(' -->'),
1172
+ ]),
1173
+ ],
1174
+ '?': (input, belt) => [
1175
+ xml.struct('line', [
1176
+ input.data('<?'),
1177
+ input.kids[0].data(input.kids[0].type),
1178
+ ...input.kids[0].hack(attrs_belt('=')),
1179
+ input.data('?>'),
1180
+ ]),
1181
+ ],
1182
+ '!': (input, belt) => [
1183
+ xml.struct('line', [
1184
+ input.data('<!'),
1185
+ input.kids[0].data(input.kids[0].type),
1186
+ ...input.kids[0].hack(attrs_belt(' ')),
1187
+ input.data('>'),
1188
+ ]),
1189
+ ],
1190
+ '': (input, belt) => {
1191
+ if (!input.type)
1192
+ return [
1193
+ input.data($mol_html_encode(input.text())),
1194
+ ];
1195
+ const attrs = input.select('@', null).hack(attrs_belt('='));
1196
+ const content = input.hack(belt);
1197
+ return [
1198
+ input.struct('line', [
1199
+ input.data(`<`),
1200
+ input.data(input.type),
1201
+ ...attrs,
1202
+ ...content.length ? [
1203
+ input.data(`>`),
1204
+ input.struct('indent', content),
1205
+ input.data(`</`),
1206
+ input.data(input.type),
1207
+ input.data(`>`),
1208
+ ] : [
1209
+ input.data(` />`),
1210
+ ]
1211
+ ]),
1212
+ ];
1213
+ },
1214
+ }));
1215
+ }
1216
+ $.$mol_tree2_xml_to_text = $mol_tree2_xml_to_text;
1217
+ })($ || ($ = {}));
1218
+ //mol/tree2/xml/to/text/text.ts
644
1219
  ;
645
1220
  export default $
646
1221
  //# sourceMappingURL=web.esm.js.map