lineputscript 1.0.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.
@@ -0,0 +1,965 @@
1
+ import { getHashCode } from './chunk-X2OHQJFP.mjs';
2
+ import { StringStructure } from './chunk-OV7CLVHP.mjs';
3
+ import { textReplace, FInt64, textDeReplace, splitLimited } from './chunk-4RRNVMEO.mjs';
4
+
5
+ // src/core/sub.ts
6
+ var Sub = class {
7
+ constructor(nameOrLps, infoOrSecond, ...rest) {
8
+ this._infos = null;
9
+ if (nameOrLps === void 0) {
10
+ this.name = "";
11
+ this._info = "";
12
+ } else if (infoOrSecond === void 0 && rest.length === 0) {
13
+ this.name = "";
14
+ this._info = "";
15
+ this.load(nameOrLps);
16
+ } else {
17
+ this.name = nameOrLps;
18
+ if (rest.length > 0) {
19
+ const allInfos = [infoOrSecond ?? "", ...rest];
20
+ const joined = allInfos.map((s) => textReplace(s)).join(",");
21
+ this._info = joined;
22
+ } else {
23
+ this._info = textReplace(infoOrSecond ?? "");
24
+ }
25
+ }
26
+ }
27
+ getStoreString() {
28
+ return this._info;
29
+ }
30
+ getString() {
31
+ return this.infoDisplay;
32
+ }
33
+ getInteger64() {
34
+ return BigInt(this._info || "0");
35
+ }
36
+ getInteger() {
37
+ return parseInt(this._info, 10) || 0;
38
+ }
39
+ getDouble() {
40
+ return parseFloat(this._info) || 0;
41
+ }
42
+ getFloat() {
43
+ return FInt64.parse(this._info);
44
+ }
45
+ getDateTime() {
46
+ const longMatch = /^-?\d+$/.test(this._info);
47
+ if (longMatch) {
48
+ try {
49
+ const ticks = BigInt(this._info);
50
+ const ticksPerMs = 10000n;
51
+ const epochOffset = 621355968000000000n;
52
+ const ms = Number((ticks - epochOffset) / ticksPerMs);
53
+ return new Date(ms);
54
+ } catch {
55
+ return /* @__PURE__ */ new Date(0);
56
+ }
57
+ }
58
+ const d = new Date(this._info);
59
+ if (!isNaN(d.getTime())) return d;
60
+ return /* @__PURE__ */ new Date(0);
61
+ }
62
+ getBoolean() {
63
+ const lower = this._info.toLowerCase();
64
+ return lower === "true" || lower === "t" || lower === "1";
65
+ }
66
+ setString(value) {
67
+ this._info = textReplace(value);
68
+ }
69
+ setInteger(value) {
70
+ this._info = value.toString();
71
+ }
72
+ setInteger64(value) {
73
+ this._info = value.toString();
74
+ }
75
+ setDouble(value) {
76
+ this._info = value.toString();
77
+ }
78
+ setFloat(value) {
79
+ this._info = value.toStoreString();
80
+ }
81
+ setDateTime(value) {
82
+ const ticksPerMs = 10000n;
83
+ const epochOffset = 621355968000000000n;
84
+ const ticks = BigInt(value.getTime()) * ticksPerMs + epochOffset;
85
+ this._info = ticks.toString();
86
+ }
87
+ setBoolean(value) {
88
+ this._info = value ? "True" : "False";
89
+ }
90
+ get info() {
91
+ return this._info;
92
+ }
93
+ set info(value) {
94
+ this._info = value;
95
+ }
96
+ get infoDisplay() {
97
+ return textDeReplace(this._info);
98
+ }
99
+ set infoDisplay(value) {
100
+ this._info = textReplace(value);
101
+ }
102
+ get infoToInt() {
103
+ return this.getInteger();
104
+ }
105
+ set infoToInt(value) {
106
+ this.setInteger(value);
107
+ }
108
+ get infoToInt64() {
109
+ return this.getInteger64();
110
+ }
111
+ set infoToInt64(value) {
112
+ this.setInteger64(value);
113
+ }
114
+ get infoToDouble() {
115
+ return this.getDouble();
116
+ }
117
+ set infoToDouble(value) {
118
+ this.setDouble(value);
119
+ }
120
+ get infoToBoolean() {
121
+ return this.getBoolean();
122
+ }
123
+ set infoToBoolean(value) {
124
+ this.setBoolean(value);
125
+ }
126
+ get infos() {
127
+ if (!this._infos) {
128
+ this._infos = new StringStructure(
129
+ (x) => {
130
+ this._info = x;
131
+ },
132
+ () => this._info
133
+ );
134
+ }
135
+ return this._infos;
136
+ }
137
+ load(nameOrLps, info) {
138
+ if (info === void 0) {
139
+ const st = splitLimited(nameOrLps, "#", 1);
140
+ this.name = st[0];
141
+ this._info = st.length > 1 ? st[1] : "";
142
+ } else {
143
+ this.name = nameOrLps;
144
+ this._info = textReplace(info);
145
+ }
146
+ }
147
+ set(other) {
148
+ this.name = other.name;
149
+ this._info = other.info;
150
+ }
151
+ getInfo() {
152
+ return this.infoDisplay;
153
+ }
154
+ getInfos() {
155
+ if (!this._info) return [];
156
+ return this._info.split(",").filter((x) => x.length > 0).map((s) => textDeReplace(s));
157
+ }
158
+ first() {
159
+ const infos = this.getInfos();
160
+ return infos.length > 0 ? infos[0] : null;
161
+ }
162
+ last() {
163
+ const infos = this.getInfos();
164
+ return infos.length > 0 ? infos[infos.length - 1] : null;
165
+ }
166
+ getLongHashCode() {
167
+ return getHashCode(this.name) * 2n + getHashCode(this._info) * 3n;
168
+ }
169
+ toString() {
170
+ if (!this._info) return `${this.name}:|`;
171
+ return `${this.name}#${this._info}:|`;
172
+ }
173
+ static split(text, separator, count = -1) {
174
+ return splitLimited(text, separator, count);
175
+ }
176
+ };
177
+
178
+ // src/core/line.ts
179
+ var Line = class extends Sub {
180
+ constructor(nameOrLps, info, text, ...subs) {
181
+ super();
182
+ this._texts = null;
183
+ this._text = "";
184
+ this.comments = "";
185
+ this.subs = [];
186
+ if (nameOrLps === void 0) return;
187
+ if (typeof nameOrLps !== "string") {
188
+ this.name = nameOrLps.name;
189
+ this._info = nameOrLps.info;
190
+ this._text = nameOrLps.text;
191
+ this.comments = nameOrLps.comments;
192
+ for (const sub of nameOrLps.subs) this.subs.push(sub);
193
+ return;
194
+ }
195
+ if (info === void 0) {
196
+ this.load(nameOrLps);
197
+ } else {
198
+ this.name = nameOrLps;
199
+ this._info = textReplace(info);
200
+ this._text = textReplace(text ?? "");
201
+ for (const sub of subs) this.subs.push(sub);
202
+ }
203
+ }
204
+ load(nameOrLps, info, text, subs) {
205
+ if (typeof nameOrLps !== "string") {
206
+ this.name = nameOrLps.name;
207
+ this._info = nameOrLps.info;
208
+ this._text = nameOrLps.text;
209
+ this.comments = nameOrLps.comments;
210
+ this.subs = [];
211
+ for (const sub of nameOrLps.subs) this.subs.push(sub);
212
+ } else if (info === void 0) {
213
+ const sts = splitLimited(nameOrLps, "///", 1);
214
+ if (sts.length === 2) this.comments = sts[1];
215
+ const parts = sts[0].split(":|");
216
+ const st = splitLimited(parts[0], "#", 1);
217
+ this.name = st[0];
218
+ this._info = st.length > 1 ? st[1] : "";
219
+ this._text = parts[parts.length - 1];
220
+ this.subs = [];
221
+ for (let i = 1; i < parts.length - 1; i++) {
222
+ const sub = new Sub();
223
+ sub.load(parts[i]);
224
+ this.subs.push(sub);
225
+ }
226
+ } else {
227
+ this.name = nameOrLps;
228
+ this._info = textReplace(info);
229
+ this._text = textReplace(text ?? "");
230
+ this.subs = [];
231
+ if (subs) for (const sub of subs) this.subs.push(sub);
232
+ }
233
+ }
234
+ get text() {
235
+ return this._text;
236
+ }
237
+ set text(value) {
238
+ this._text = value;
239
+ }
240
+ get textDisplay() {
241
+ return textDeReplace(this._text);
242
+ }
243
+ set textDisplay(value) {
244
+ this._text = textReplace(value);
245
+ }
246
+ get textToInt() {
247
+ return parseInt(this._text, 10) || 0;
248
+ }
249
+ set textToInt(value) {
250
+ this._text = value.toString();
251
+ }
252
+ get textToInt64() {
253
+ return BigInt(this._text || "0");
254
+ }
255
+ set textToInt64(value) {
256
+ this._text = value.toString();
257
+ }
258
+ get textToDouble() {
259
+ return parseFloat(this._text) || 0;
260
+ }
261
+ set textToDouble(value) {
262
+ this._text = value.toString();
263
+ }
264
+ getText() {
265
+ return this.textDisplay;
266
+ }
267
+ get texts() {
268
+ if (!this._texts) this._texts = new StringStructure((x) => {
269
+ this._text = x;
270
+ }, () => this._text);
271
+ return this._texts;
272
+ }
273
+ addSub(newSub) {
274
+ this.subs.push(newSub);
275
+ }
276
+ addorReplaceSub(newSub) {
277
+ const old = this.find(newSub.name);
278
+ if (old) old.set(newSub);
279
+ else this.subs.push(newSub);
280
+ }
281
+ addRange(newSubs) {
282
+ for (const sub of newSubs) this.subs.push(sub);
283
+ }
284
+ insertSub(index, newSub) {
285
+ this.subs.splice(index, 0, newSub);
286
+ }
287
+ insertRange(index, newSubs) {
288
+ this.subs.splice(index, 0, ...newSubs);
289
+ }
290
+ remove(sub) {
291
+ const idx = this.subs.indexOf(sub);
292
+ if (idx === -1) return false;
293
+ this.subs.splice(idx, 1);
294
+ return true;
295
+ }
296
+ removeByName(subName) {
297
+ for (let i = 0; i < this.subs.length; i++) {
298
+ if (this.subs[i].name === subName) {
299
+ this.subs.splice(i, 1);
300
+ return true;
301
+ }
302
+ }
303
+ return false;
304
+ }
305
+ removeAll(subName) {
306
+ for (let i = this.subs.length - 1; i >= 0; i--)
307
+ if (this.subs[i].name === subName) this.subs.splice(i, 1);
308
+ }
309
+ removeAt(index) {
310
+ this.subs.splice(index, 1);
311
+ }
312
+ contains(sub) {
313
+ return this.subs.indexOf(sub) !== -1;
314
+ }
315
+ containsByName(value) {
316
+ return this.subs.some((x) => x.name === value);
317
+ }
318
+ find(subName, subinfo) {
319
+ if (subinfo === void 0) return this.subs.find((x) => x.name === subName) ?? null;
320
+ return this.subs.find((x) => x.name === subName && x.info === subinfo) ?? null;
321
+ }
322
+ findInfo(subinfo) {
323
+ return this.subs.find((x) => x.info === subinfo) ?? null;
324
+ }
325
+ findAll(subName, subinfo) {
326
+ if (subinfo === void 0) return this.subs.filter((x) => x.name === subName);
327
+ return this.subs.filter((x) => x.name === subName && x.info === subinfo);
328
+ }
329
+ findAllInfo(subinfo) {
330
+ return this.subs.filter((x) => x.info === subinfo);
331
+ }
332
+ findorAdd(subName) {
333
+ const existing = this.find(subName);
334
+ if (existing) return existing;
335
+ const sub = new Sub();
336
+ sub.name = subName;
337
+ this.subs.push(sub);
338
+ return sub;
339
+ }
340
+ searchAll(value) {
341
+ return this.subs.filter((x) => x.name.includes(value));
342
+ }
343
+ search(value) {
344
+ return this.subs.find((x) => x.name.includes(value)) ?? null;
345
+ }
346
+ indexOf(subName) {
347
+ return this.subs.findIndex((x) => x.name === subName);
348
+ }
349
+ indexsOf(subName) {
350
+ const indices = [];
351
+ for (let i = 0; i < this.subs.length; i++)
352
+ if (this.subs[i].name === subName) indices.push(i);
353
+ return indices;
354
+ }
355
+ // Typed shorthands on subs
356
+ getSubBool(subName) {
357
+ return this.find(subName)?.getBoolean() ?? false;
358
+ }
359
+ setSubBool(subName, value) {
360
+ this.findorAdd(subName).infoToBoolean = value;
361
+ }
362
+ getSubInt(subName, defaultValue = 0) {
363
+ return this.find(subName)?.infoToInt ?? defaultValue;
364
+ }
365
+ setSubInt(subName, value) {
366
+ this.findorAdd(subName).infoToInt = value;
367
+ }
368
+ getSubInt64(subName, defaultValue = 0n) {
369
+ return this.find(subName)?.infoToInt64 ?? defaultValue;
370
+ }
371
+ setSubInt64(subName, value) {
372
+ this.findorAdd(subName).infoToInt64 = value;
373
+ }
374
+ getSubFloat(subName, defaultValue) {
375
+ return this.find(subName)?.getFloat() ?? (defaultValue ?? FInt64.Zero);
376
+ }
377
+ setSubFloat(subName, value) {
378
+ this.findorAdd(subName).setFloat(value);
379
+ }
380
+ getSubDateTime(subName, defaultValue) {
381
+ return this.find(subName)?.getDateTime() ?? (defaultValue ?? null);
382
+ }
383
+ setSubDateTime(subName, value) {
384
+ this.findorAdd(subName).setDateTime(value);
385
+ }
386
+ getSubString(subName, defaultValue) {
387
+ return this.find(subName)?.infoDisplay ?? (defaultValue ?? null);
388
+ }
389
+ setSubString(subName, value) {
390
+ this.findorAdd(subName).infoDisplay = value ?? "";
391
+ }
392
+ getSubDouble(subName, defaultValue = 0) {
393
+ return this.find(subName)?.infoToDouble ?? defaultValue;
394
+ }
395
+ setSubDouble(subName, value) {
396
+ this.findorAdd(subName).infoToDouble = value;
397
+ }
398
+ getLongHashCode() {
399
+ let hash = getHashCode(this.name) * 2n + getHashCode(this._info) * 3n + getHashCode(this._text) * 4n;
400
+ for (const sub of this.subs) hash += sub.getLongHashCode();
401
+ return hash;
402
+ }
403
+ toList() {
404
+ return [...this.subs];
405
+ }
406
+ toString(sb) {
407
+ const parts = [this.name];
408
+ if (this._info) parts.push(`#${this._info}`);
409
+ if (parts.length > 0 || this.subs.length > 0 || this._text || this.comments) parts.push(":|");
410
+ for (const sub of this.subs) parts.push(sub.toString());
411
+ parts.push(this._text);
412
+ if (this.comments) parts.push(`///${this.comments}`);
413
+ const result = parts.join("");
414
+ if (sb) {
415
+ sb.push("\n");
416
+ sb.push(result);
417
+ }
418
+ return result;
419
+ }
420
+ };
421
+
422
+ // src/core/line-dict.ts
423
+ var LineDict = class extends Sub {
424
+ constructor(nameOrLps, info, text, ...subs) {
425
+ super();
426
+ this._texts = null;
427
+ this._text = "";
428
+ this.comments = "";
429
+ this._subs = /* @__PURE__ */ new Map();
430
+ if (nameOrLps === void 0) return;
431
+ if (typeof nameOrLps !== "string") {
432
+ this.name = nameOrLps.name;
433
+ this._info = nameOrLps.info;
434
+ this._text = nameOrLps.text;
435
+ this.comments = nameOrLps.comments;
436
+ for (const sub of nameOrLps.subs) this._subs.set(sub.name, sub);
437
+ return;
438
+ }
439
+ if (info === void 0) {
440
+ this.load(nameOrLps);
441
+ } else {
442
+ this.name = nameOrLps;
443
+ this._info = textReplace(info);
444
+ this._text = textReplace(text ?? "");
445
+ for (const sub of subs) this._subs.set(sub.name, sub);
446
+ }
447
+ }
448
+ load(nameOrLps, info, text, subs) {
449
+ if (typeof nameOrLps !== "string") {
450
+ this.name = nameOrLps.name;
451
+ this._info = nameOrLps.info;
452
+ this._text = nameOrLps.text;
453
+ this.comments = nameOrLps.comments;
454
+ this._subs.clear();
455
+ for (const sub of nameOrLps.subs) this._subs.set(sub.name, sub);
456
+ } else if (info === void 0) {
457
+ const sts = splitLimited(nameOrLps, "///", 1);
458
+ if (sts.length === 2) this.comments = sts[1];
459
+ const parts = sts[0].split(":|");
460
+ const st = splitLimited(parts[0], "#", 1);
461
+ this.name = st[0];
462
+ this._info = st.length > 1 ? st[1] : "";
463
+ this._text = parts[parts.length - 1];
464
+ this._subs.clear();
465
+ for (let i = 1; i < parts.length - 1; i++) {
466
+ const sub = new Sub();
467
+ sub.load(parts[i]);
468
+ this._subs.set(sub.name, sub);
469
+ }
470
+ } else {
471
+ this.name = nameOrLps;
472
+ this._info = textReplace(info);
473
+ this._text = textReplace(text ?? "");
474
+ this._subs.clear();
475
+ if (subs) for (const sub of subs) this._subs.set(sub.name, sub);
476
+ }
477
+ }
478
+ get text() {
479
+ return this._text;
480
+ }
481
+ set text(value) {
482
+ this._text = value;
483
+ }
484
+ get textDisplay() {
485
+ return textDeReplace(this._text);
486
+ }
487
+ set textDisplay(value) {
488
+ this._text = textReplace(value);
489
+ }
490
+ get textToInt() {
491
+ return parseInt(this._text, 10) || 0;
492
+ }
493
+ set textToInt(value) {
494
+ this._text = value.toString();
495
+ }
496
+ get textToInt64() {
497
+ return BigInt(this._text || "0");
498
+ }
499
+ set textToInt64(value) {
500
+ this._text = value.toString();
501
+ }
502
+ get textToDouble() {
503
+ return parseFloat(this._text) || 0;
504
+ }
505
+ set textToDouble(value) {
506
+ this._text = value.toString();
507
+ }
508
+ getText() {
509
+ return this.textDisplay;
510
+ }
511
+ get texts() {
512
+ if (!this._texts) this._texts = new StringStructure((x) => {
513
+ this._text = x;
514
+ }, () => this._text);
515
+ return this._texts;
516
+ }
517
+ get subs() {
518
+ return Array.from(this._subs.values());
519
+ }
520
+ set subs(value) {
521
+ this._subs.clear();
522
+ for (const sub of value) this._subs.set(sub.name, sub);
523
+ }
524
+ addSub(newSub) {
525
+ this._subs.set(newSub.name, newSub);
526
+ }
527
+ addorReplaceSub(newSub) {
528
+ this._subs.set(newSub.name, newSub);
529
+ }
530
+ addRange(newSubs) {
531
+ for (const sub of newSubs) this._subs.set(sub.name, sub);
532
+ }
533
+ insertSub(index, newSub) {
534
+ const entries = Array.from(this._subs.entries());
535
+ entries.splice(index, 0, [newSub.name, newSub]);
536
+ this._subs = new Map(entries);
537
+ }
538
+ insertRange(index, newSubs) {
539
+ const entries = Array.from(this._subs.entries());
540
+ const insert = newSubs.map((s) => [s.name, s]);
541
+ entries.splice(index, 0, ...insert);
542
+ this._subs = new Map(entries);
543
+ }
544
+ remove(sub) {
545
+ return this._subs.delete(sub.name);
546
+ }
547
+ removeByName(subName) {
548
+ return this._subs.delete(subName);
549
+ }
550
+ removeAll(subName) {
551
+ this._subs.delete(subName);
552
+ }
553
+ removeAt(index) {
554
+ const entries = Array.from(this._subs.entries());
555
+ if (index < entries.length) {
556
+ entries.splice(index, 1);
557
+ this._subs = new Map(entries);
558
+ }
559
+ }
560
+ contains(sub) {
561
+ const existing = this._subs.get(sub.name);
562
+ return existing !== void 0 && existing.info === sub.info;
563
+ }
564
+ containsByName(value) {
565
+ return this._subs.has(value);
566
+ }
567
+ find(subName, subinfo) {
568
+ const sub = this._subs.get(subName);
569
+ if (!sub) return null;
570
+ if (subinfo !== void 0 && sub.info !== subinfo) return null;
571
+ return sub;
572
+ }
573
+ findInfo(subinfo) {
574
+ for (const sub of this._subs.values()) if (sub.info === subinfo) return sub;
575
+ return null;
576
+ }
577
+ findAll(subName, subinfo) {
578
+ const sub = this._subs.get(subName);
579
+ if (!sub) return [];
580
+ if (subinfo !== void 0 && sub.info !== subinfo) return [];
581
+ return [sub];
582
+ }
583
+ findAllInfo(subinfo) {
584
+ const result = [];
585
+ for (const sub of this._subs.values()) if (sub.info === subinfo) result.push(sub);
586
+ return result;
587
+ }
588
+ findorAdd(subName) {
589
+ const existing = this._subs.get(subName);
590
+ if (existing) return existing;
591
+ const sub = new Sub();
592
+ sub.name = subName;
593
+ this._subs.set(subName, sub);
594
+ return sub;
595
+ }
596
+ searchAll(value) {
597
+ return this.subs.filter((x) => x.name.includes(value));
598
+ }
599
+ search(value) {
600
+ return this.subs.find((x) => x.name.includes(value)) ?? null;
601
+ }
602
+ indexOf(subName) {
603
+ return Array.from(this._subs.keys()).indexOf(subName);
604
+ }
605
+ indexsOf(subName) {
606
+ const idx = this.indexOf(subName);
607
+ return idx >= 0 ? [idx] : [];
608
+ }
609
+ // Typed shorthands on subs
610
+ getSubBool(subName) {
611
+ return this._subs.get(subName)?.getBoolean() ?? false;
612
+ }
613
+ setSubBool(subName, value) {
614
+ this.findorAdd(subName).infoToBoolean = value;
615
+ }
616
+ getSubInt(subName, defaultValue = 0) {
617
+ return this._subs.get(subName)?.infoToInt ?? defaultValue;
618
+ }
619
+ setSubInt(subName, value) {
620
+ this.findorAdd(subName).infoToInt = value;
621
+ }
622
+ getSubInt64(subName, defaultValue = 0n) {
623
+ return this._subs.get(subName)?.infoToInt64 ?? defaultValue;
624
+ }
625
+ setSubInt64(subName, value) {
626
+ this.findorAdd(subName).infoToInt64 = value;
627
+ }
628
+ getSubFloat(subName, defaultValue) {
629
+ return this._subs.get(subName)?.getFloat() ?? (defaultValue ?? FInt64.Zero);
630
+ }
631
+ setSubFloat(subName, value) {
632
+ this.findorAdd(subName).setFloat(value);
633
+ }
634
+ getSubDateTime(subName, defaultValue) {
635
+ return this._subs.get(subName)?.getDateTime() ?? (defaultValue ?? null);
636
+ }
637
+ setSubDateTime(subName, value) {
638
+ this.findorAdd(subName).setDateTime(value);
639
+ }
640
+ getSubString(subName, defaultValue) {
641
+ return this._subs.get(subName)?.infoDisplay ?? (defaultValue ?? null);
642
+ }
643
+ setSubString(subName, value) {
644
+ this.findorAdd(subName).infoDisplay = value ?? "";
645
+ }
646
+ getSubDouble(subName, defaultValue = 0) {
647
+ return this._subs.get(subName)?.infoToDouble ?? defaultValue;
648
+ }
649
+ setSubDouble(subName, value) {
650
+ this.findorAdd(subName).infoToDouble = value;
651
+ }
652
+ getLongHashCode() {
653
+ let hash = getHashCode(this.name) * 2n + getHashCode(this._info) * 3n + getHashCode(this._text) * 4n;
654
+ for (const sub of this._subs.values()) hash += sub.getLongHashCode();
655
+ return hash;
656
+ }
657
+ toList() {
658
+ return this.subs;
659
+ }
660
+ toString(sb) {
661
+ const parts = [this.name];
662
+ if (this._info) parts.push(`#${this._info}`);
663
+ if (parts.length > 0 || this._subs.size > 0 || this._text || this.comments) parts.push(":|");
664
+ for (const sub of this._subs.values()) parts.push(sub.toString());
665
+ parts.push(this._text);
666
+ if (this.comments) parts.push(`///${this.comments}`);
667
+ const result = parts.join("");
668
+ if (sb) {
669
+ sb.push("\n");
670
+ sb.push(result);
671
+ }
672
+ return result;
673
+ }
674
+ };
675
+
676
+ // src/core/lps.ts
677
+ var LPS = class {
678
+ constructor(lpsOrLine, ...moreLines) {
679
+ this.assemblage = [];
680
+ if (lpsOrLine === void 0) return;
681
+ if (typeof lpsOrLine === "string") {
682
+ this.load(lpsOrLine);
683
+ } else if (Array.isArray(lpsOrLine)) {
684
+ this.addRange(lpsOrLine);
685
+ } else {
686
+ this.addLine(lpsOrLine);
687
+ this.addRange(moreLines);
688
+ }
689
+ }
690
+ load(lpsOrLines) {
691
+ if (typeof lpsOrLines === "string") {
692
+ this.assemblage = [];
693
+ const normalized = lpsOrLines.replace(/\r/g, "").replace(/:\n\|/g, "/n").replace(/:\n:/g, "");
694
+ const file = normalized.split("\n").filter((line) => line.trim().length > 0);
695
+ for (const str of file) {
696
+ const line = new Line();
697
+ line.load(str);
698
+ this.assemblage.push(line);
699
+ }
700
+ } else {
701
+ this.assemblage = [];
702
+ this.addRange(lpsOrLines);
703
+ }
704
+ }
705
+ addLine(newLine) {
706
+ this.assemblage.push(newLine);
707
+ }
708
+ addorReplaceLine(newLine) {
709
+ const old = this.findLine(newLine.name);
710
+ if (old) old.load(newLine);
711
+ else this.assemblage.push(newLine);
712
+ }
713
+ addRange(newLines) {
714
+ for (const line of newLines) this.assemblage.push(line);
715
+ }
716
+ insertLine(index, newLine) {
717
+ this.assemblage.splice(index, 0, newLine);
718
+ }
719
+ insertRange(index, newLines) {
720
+ this.assemblage.splice(index, 0, ...newLines);
721
+ }
722
+ remove(target) {
723
+ if (typeof target === "string") {
724
+ for (let i = 0; i < this.assemblage.length; i++) {
725
+ if (this.assemblage[i].name === target) {
726
+ this.assemblage.splice(i, 1);
727
+ return true;
728
+ }
729
+ }
730
+ return false;
731
+ }
732
+ const idx = this.assemblage.indexOf(target);
733
+ if (idx === -1) return false;
734
+ this.assemblage.splice(idx, 1);
735
+ return true;
736
+ }
737
+ removeAll(target) {
738
+ if (typeof target === "string") {
739
+ for (let i = this.assemblage.length - 1; i >= 0; i--)
740
+ if (this.assemblage[i].name === target) this.assemblage.splice(i, 1);
741
+ } else {
742
+ for (let i = this.assemblage.length - 1; i >= 0; i--)
743
+ if (this.assemblage[i] === target) this.assemblage.splice(i, 1);
744
+ }
745
+ }
746
+ removeAt(index) {
747
+ this.assemblage.splice(index, 1);
748
+ }
749
+ contains(target) {
750
+ if ("subs" in target) return this.assemblage.includes(target);
751
+ return this.assemblage.some((line) => line.contains(target));
752
+ }
753
+ containsLine(value) {
754
+ return this.assemblage.some((line) => line.name === value);
755
+ }
756
+ containsSub(value) {
757
+ return this.assemblage.some((line) => line.containsByName(value));
758
+ }
759
+ findLine(lineName, lineinfo) {
760
+ if (lineinfo === void 0) return this.assemblage.find((x) => x.name === lineName) ?? null;
761
+ return this.assemblage.find((x) => x.name === lineName && x.info === lineinfo) ?? null;
762
+ }
763
+ findLineInfo(lineinfo) {
764
+ return this.assemblage.find((x) => x.info === lineinfo) ?? null;
765
+ }
766
+ findorAddLine(lineName) {
767
+ const existing = this.findLine(lineName);
768
+ if (existing) return existing;
769
+ const line = new Line();
770
+ line.name = lineName;
771
+ this.assemblage.push(line);
772
+ return line;
773
+ }
774
+ findAllLine(lineName, lineinfo) {
775
+ if (lineinfo === void 0) return this.assemblage.filter((x) => x.name === lineName);
776
+ return this.assemblage.filter((x) => x.name === lineName && x.info === lineinfo);
777
+ }
778
+ findAllLineInfo(lineinfo) {
779
+ return this.assemblage.filter((x) => x.info === lineinfo);
780
+ }
781
+ findSub(subName, subinfo) {
782
+ for (const line of this.assemblage) {
783
+ const r = subinfo !== void 0 ? line.find(subName, subinfo) : line.find(subName);
784
+ if (r) return r;
785
+ }
786
+ return null;
787
+ }
788
+ findSubInfo(subinfo) {
789
+ for (const line of this.assemblage) {
790
+ const r = line.findInfo(subinfo);
791
+ if (r) return r;
792
+ }
793
+ return null;
794
+ }
795
+ findAllSub(subName, subinfo) {
796
+ const results = [];
797
+ for (const line of this.assemblage) results.push(...subinfo !== void 0 ? line.findAll(subName, subinfo) : line.findAll(subName));
798
+ return results;
799
+ }
800
+ findAllSubInfo(subinfo) {
801
+ const results = [];
802
+ for (const line of this.assemblage) results.push(...line.findAllInfo(subinfo));
803
+ return results;
804
+ }
805
+ searchAllLine(value) {
806
+ return this.assemblage.filter((x) => x.name.includes(value));
807
+ }
808
+ searchLine(value) {
809
+ return this.assemblage.find((x) => x.name.includes(value)) ?? null;
810
+ }
811
+ searchAllSub(value) {
812
+ const results = [];
813
+ for (const line of this.assemblage) results.push(...line.searchAll(value));
814
+ return results;
815
+ }
816
+ searchSub(value) {
817
+ for (const line of this.assemblage) {
818
+ const r = line.search(value);
819
+ if (r) return r;
820
+ }
821
+ return null;
822
+ }
823
+ indexOf(lineName) {
824
+ return this.assemblage.findIndex((x) => x.name === lineName);
825
+ }
826
+ indexsOf(lineName) {
827
+ const indices = [];
828
+ for (let i = 0; i < this.assemblage.length; i++)
829
+ if (this.assemblage[i].name === lineName) indices.push(i);
830
+ return indices;
831
+ }
832
+ first() {
833
+ return this.assemblage.length > 0 ? this.assemblage[0] : null;
834
+ }
835
+ last() {
836
+ return this.assemblage.length > 0 ? this.assemblage[this.assemblage.length - 1] : null;
837
+ }
838
+ getLongHashCode() {
839
+ let hash = 0n;
840
+ for (const line of this.assemblage) hash += line.getLongHashCode();
841
+ return hash;
842
+ }
843
+ // Typed shorthands on lines
844
+ getLineBool(lineName) {
845
+ return this.findLine(lineName)?.getBoolean() ?? false;
846
+ }
847
+ setLineBool(lineName, value) {
848
+ this.findorAddLine(lineName).infoToBoolean = value;
849
+ }
850
+ getLineInt(lineName, defaultValue = 0) {
851
+ return this.findLine(lineName)?.infoToInt ?? defaultValue;
852
+ }
853
+ setLineInt(lineName, value) {
854
+ this.findorAddLine(lineName).infoToInt = value;
855
+ }
856
+ getLineInt64(lineName, defaultValue = 0n) {
857
+ return this.findLine(lineName)?.infoToInt64 ?? defaultValue;
858
+ }
859
+ setLineInt64(lineName, value) {
860
+ this.findorAddLine(lineName).infoToInt64 = value;
861
+ }
862
+ getLineString(lineName, defaultValue) {
863
+ return this.findLine(lineName)?.infoDisplay ?? (defaultValue ?? null);
864
+ }
865
+ setLineString(lineName, value) {
866
+ this.findorAddLine(lineName).infoDisplay = value ?? "";
867
+ }
868
+ getLineDouble(lineName, defaultValue = 0) {
869
+ return this.findLine(lineName)?.infoToDouble ?? defaultValue;
870
+ }
871
+ setLineDouble(lineName, value) {
872
+ this.findorAddLine(lineName).infoToDouble = value;
873
+ }
874
+ getLineFloat(lineName, defaultValue) {
875
+ return this.findLine(lineName)?.getFloat() ?? (defaultValue ?? FInt64.Zero);
876
+ }
877
+ setLineFloat(lineName, value) {
878
+ this.findorAddLine(lineName).setFloat(value);
879
+ }
880
+ getLineDateTime(lineName, defaultValue) {
881
+ return this.findLine(lineName)?.getDateTime() ?? (defaultValue ?? null);
882
+ }
883
+ setLineDateTime(lineName, value) {
884
+ this.findorAddLine(lineName).setDateTime(value);
885
+ }
886
+ get length() {
887
+ let len = 3;
888
+ for (const line of this.assemblage) {
889
+ len += line.name.length + line.getStoreString().length + line.text.length + 6;
890
+ for (const sub of line.subs) len += sub.name.length + sub.getStoreString().length + 3;
891
+ }
892
+ return len;
893
+ }
894
+ get count() {
895
+ return this.assemblage.length;
896
+ }
897
+ toString() {
898
+ return this.assemblage.map((line) => line.toString()).join("\n");
899
+ }
900
+ };
901
+
902
+ // src/core/lps-document.ts
903
+ var LpsDocument = class extends LPS {
904
+ constructor(lpsOrLine, ...moreLines) {
905
+ super();
906
+ this._lineNode = 0;
907
+ if (lpsOrLine === void 0) return;
908
+ if (typeof lpsOrLine === "string") {
909
+ this.load(lpsOrLine);
910
+ } else if (Array.isArray(lpsOrLine)) {
911
+ this.addRange(lpsOrLine);
912
+ } else {
913
+ this.addLine(lpsOrLine);
914
+ this.addRange(moreLines);
915
+ }
916
+ }
917
+ get lineNode() {
918
+ return this._lineNode;
919
+ }
920
+ set lineNode(value) {
921
+ if (value > this.assemblage.length) this._lineNode = this.assemblage.length;
922
+ else if (value < 0) this._lineNode = 0;
923
+ else this._lineNode = value;
924
+ }
925
+ readNext() {
926
+ if (this._lineNode >= this.assemblage.length) return null;
927
+ return this.assemblage[this._lineNode++];
928
+ }
929
+ read() {
930
+ if (this._lineNode >= this.assemblage.length) return null;
931
+ return this.assemblage[this._lineNode];
932
+ }
933
+ append(newLineOrName, info = "", text = "", ...subs) {
934
+ if (typeof newLineOrName === "string") {
935
+ const line = new Line();
936
+ line.load(newLineOrName, info, text, subs);
937
+ this.insertLine(this._lineNode + 1, line);
938
+ } else {
939
+ this.insertLine(this._lineNode + 1, newLineOrName);
940
+ }
941
+ }
942
+ appendSub(...newSubs) {
943
+ const current = this.read();
944
+ if (current) current.addRange(newSubs);
945
+ }
946
+ appendSubByName(newSubName, subInfo = "") {
947
+ const current = this.read();
948
+ if (current) {
949
+ const sub = new Sub();
950
+ sub.load(newSubName, subInfo);
951
+ current.addSub(sub);
952
+ }
953
+ }
954
+ readReset() {
955
+ this._lineNode = 0;
956
+ }
957
+ readEnd() {
958
+ this._lineNode = this.assemblage.length;
959
+ }
960
+ readCanNext() {
961
+ return this._lineNode < this.assemblage.length;
962
+ }
963
+ };
964
+
965
+ export { LPS, Line, LineDict, LpsDocument, Sub };