@novely/core 0.38.0 → 0.38.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -2
- package/dist/index.global.js +186 -239
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +47 -93
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.global.js
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var Novely = (() => {
|
|
3
|
-
var __create = Object.create;
|
|
4
3
|
var __defProp = Object.defineProperty;
|
|
5
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
8
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
10
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
11
|
-
};
|
|
12
7
|
var __export = (target, all) => {
|
|
13
8
|
for (var name in all)
|
|
14
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -21,134 +16,8 @@ var Novely = (() => {
|
|
|
21
16
|
}
|
|
22
17
|
return to;
|
|
23
18
|
};
|
|
24
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
25
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
26
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
27
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
28
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
29
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
30
|
-
mod
|
|
31
|
-
));
|
|
32
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
33
20
|
|
|
34
|
-
// ../../node_modules/.pnpm/yocto-queue@0.1.0/node_modules/yocto-queue/index.js
|
|
35
|
-
var require_yocto_queue = __commonJS({
|
|
36
|
-
"../../node_modules/.pnpm/yocto-queue@0.1.0/node_modules/yocto-queue/index.js"(exports, module) {
|
|
37
|
-
"use strict";
|
|
38
|
-
var Node = class {
|
|
39
|
-
/// value;
|
|
40
|
-
/// next;
|
|
41
|
-
constructor(value) {
|
|
42
|
-
this.value = value;
|
|
43
|
-
this.next = void 0;
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
var Queue = class {
|
|
47
|
-
// TODO: Use private class fields when targeting Node.js 12.
|
|
48
|
-
// #_head;
|
|
49
|
-
// #_tail;
|
|
50
|
-
// #_size;
|
|
51
|
-
constructor() {
|
|
52
|
-
this.clear();
|
|
53
|
-
}
|
|
54
|
-
enqueue(value) {
|
|
55
|
-
const node = new Node(value);
|
|
56
|
-
if (this._head) {
|
|
57
|
-
this._tail.next = node;
|
|
58
|
-
this._tail = node;
|
|
59
|
-
} else {
|
|
60
|
-
this._head = node;
|
|
61
|
-
this._tail = node;
|
|
62
|
-
}
|
|
63
|
-
this._size++;
|
|
64
|
-
}
|
|
65
|
-
dequeue() {
|
|
66
|
-
const current = this._head;
|
|
67
|
-
if (!current) {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
this._head = this._head.next;
|
|
71
|
-
this._size--;
|
|
72
|
-
return current.value;
|
|
73
|
-
}
|
|
74
|
-
clear() {
|
|
75
|
-
this._head = void 0;
|
|
76
|
-
this._tail = void 0;
|
|
77
|
-
this._size = 0;
|
|
78
|
-
}
|
|
79
|
-
get size() {
|
|
80
|
-
return this._size;
|
|
81
|
-
}
|
|
82
|
-
*[Symbol.iterator]() {
|
|
83
|
-
let current = this._head;
|
|
84
|
-
while (current) {
|
|
85
|
-
yield current.value;
|
|
86
|
-
current = current.next;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
module.exports = Queue;
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
// ../../node_modules/.pnpm/p-limit@3.1.0/node_modules/p-limit/index.js
|
|
95
|
-
var require_p_limit = __commonJS({
|
|
96
|
-
"../../node_modules/.pnpm/p-limit@3.1.0/node_modules/p-limit/index.js"(exports, module) {
|
|
97
|
-
"use strict";
|
|
98
|
-
var Queue = require_yocto_queue();
|
|
99
|
-
var pLimit2 = (concurrency) => {
|
|
100
|
-
if (!((Number.isInteger(concurrency) || concurrency === Infinity) && concurrency > 0)) {
|
|
101
|
-
throw new TypeError("Expected `concurrency` to be a number from 1 and up");
|
|
102
|
-
}
|
|
103
|
-
const queue = new Queue();
|
|
104
|
-
let activeCount = 0;
|
|
105
|
-
const next = () => {
|
|
106
|
-
activeCount--;
|
|
107
|
-
if (queue.size > 0) {
|
|
108
|
-
queue.dequeue()();
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
const run = async (fn, resolve, ...args) => {
|
|
112
|
-
activeCount++;
|
|
113
|
-
const result = (async () => fn(...args))();
|
|
114
|
-
resolve(result);
|
|
115
|
-
try {
|
|
116
|
-
await result;
|
|
117
|
-
} catch {
|
|
118
|
-
}
|
|
119
|
-
next();
|
|
120
|
-
};
|
|
121
|
-
const enqueue = (fn, resolve, ...args) => {
|
|
122
|
-
queue.enqueue(run.bind(null, fn, resolve, ...args));
|
|
123
|
-
(async () => {
|
|
124
|
-
await Promise.resolve();
|
|
125
|
-
if (activeCount < concurrency && queue.size > 0) {
|
|
126
|
-
queue.dequeue()();
|
|
127
|
-
}
|
|
128
|
-
})();
|
|
129
|
-
};
|
|
130
|
-
const generator = (fn, ...args) => new Promise((resolve) => {
|
|
131
|
-
enqueue(fn, resolve, ...args);
|
|
132
|
-
});
|
|
133
|
-
Object.defineProperties(generator, {
|
|
134
|
-
activeCount: {
|
|
135
|
-
get: () => activeCount
|
|
136
|
-
},
|
|
137
|
-
pendingCount: {
|
|
138
|
-
get: () => queue.size
|
|
139
|
-
},
|
|
140
|
-
clearQueue: {
|
|
141
|
-
value: () => {
|
|
142
|
-
queue.clear();
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
return generator;
|
|
147
|
-
};
|
|
148
|
-
module.exports = pLimit2;
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
|
|
152
21
|
// src/index.ts
|
|
153
22
|
var src_exports = {};
|
|
154
23
|
__export(src_exports, {
|
|
@@ -222,8 +91,7 @@ var Novely = (() => {
|
|
|
222
91
|
var k, out, tmp;
|
|
223
92
|
if (Array.isArray(val)) {
|
|
224
93
|
out = Array(k = val.length);
|
|
225
|
-
while (k--)
|
|
226
|
-
out[k] = (tmp = val[k]) && typeof tmp === "object" ? klona(tmp) : tmp;
|
|
94
|
+
while (k--) out[k] = (tmp = val[k]) && typeof tmp === "object" ? klona(tmp) : tmp;
|
|
227
95
|
return out;
|
|
228
96
|
}
|
|
229
97
|
if (Object.prototype.toString.call(val) === "[object Object]") {
|
|
@@ -260,13 +128,11 @@ var Novely = (() => {
|
|
|
260
128
|
ctx: context,
|
|
261
129
|
data,
|
|
262
130
|
push() {
|
|
263
|
-
if (context.meta.preview)
|
|
264
|
-
return;
|
|
131
|
+
if (context.meta.preview) return;
|
|
265
132
|
push(context);
|
|
266
133
|
},
|
|
267
134
|
forward() {
|
|
268
|
-
if (context.meta.preview)
|
|
269
|
-
return;
|
|
135
|
+
if (context.meta.preview) return;
|
|
270
136
|
forward(context);
|
|
271
137
|
}
|
|
272
138
|
}, props);
|
|
@@ -388,8 +254,7 @@ var Novely = (() => {
|
|
|
388
254
|
const flat = (item) => {
|
|
389
255
|
return item.flatMap((data) => {
|
|
390
256
|
const type = data[0];
|
|
391
|
-
if (Array.isArray(type))
|
|
392
|
-
return flat(data);
|
|
257
|
+
if (Array.isArray(type)) return flat(data);
|
|
393
258
|
return [data];
|
|
394
259
|
});
|
|
395
260
|
};
|
|
@@ -450,8 +315,7 @@ var Novely = (() => {
|
|
|
450
315
|
}
|
|
451
316
|
for (let i = startIndex; i <= val; i++) {
|
|
452
317
|
const item = current[i];
|
|
453
|
-
if (!isAction(item))
|
|
454
|
-
continue;
|
|
318
|
+
if (!isAction(item)) continue;
|
|
455
319
|
const [action] = item;
|
|
456
320
|
const last = index === max && i === val;
|
|
457
321
|
const shouldSkip = isSkippedDuringRestore(action) || isUserRequiredAction(item);
|
|
@@ -509,16 +373,14 @@ var Novely = (() => {
|
|
|
509
373
|
const fn = params[0];
|
|
510
374
|
if ("callOnlyLatest" in fn && fn.callOnlyLatest) {
|
|
511
375
|
const notLatest = next(i).some(([, func]) => {
|
|
512
|
-
if (!isFunction(func))
|
|
513
|
-
return false;
|
|
376
|
+
if (!isFunction(func)) return false;
|
|
514
377
|
const c0 = func;
|
|
515
378
|
const c1 = fn;
|
|
516
379
|
const isIdenticalID = Boolean(c0.id && c1.id && c0.id === c1.id);
|
|
517
380
|
const isIdenticalByReference = c0 === c1;
|
|
518
381
|
return isIdenticalID || isIdenticalByReference || str(c0) === str(c1);
|
|
519
382
|
});
|
|
520
|
-
if (notLatest)
|
|
521
|
-
continue;
|
|
383
|
+
if (notLatest) continue;
|
|
522
384
|
} else if ("skipOnRestore" in fn && fn.skipOnRestore) {
|
|
523
385
|
let getNext = () => {
|
|
524
386
|
const nextActions = next(i);
|
|
@@ -527,23 +389,21 @@ var Novely = (() => {
|
|
|
527
389
|
};
|
|
528
390
|
return nextActions;
|
|
529
391
|
};
|
|
530
|
-
if (fn.skipOnRestore(getNext))
|
|
531
|
-
continue;
|
|
392
|
+
if (fn.skipOnRestore(getNext)) continue;
|
|
532
393
|
}
|
|
533
394
|
}
|
|
534
395
|
processedQueue.push(item);
|
|
535
396
|
} else if (action === "showCharacter" || action === "playSound" || action === "playMusic" || action === "voice") {
|
|
536
397
|
const closing = getOppositeAction(action);
|
|
537
398
|
const skip = next(i).some(([_action, target]) => {
|
|
538
|
-
if (target !== params[0]) {
|
|
399
|
+
if (target !== params[0] && action !== "voice") {
|
|
539
400
|
return false;
|
|
540
401
|
}
|
|
541
402
|
const musicGonnaBePaused = action === "playMusic" && _action === "pauseMusic";
|
|
542
403
|
const soundGonnaBePaused = action === "playSound" && _action === "pauseSound";
|
|
543
404
|
return musicGonnaBePaused || soundGonnaBePaused || _action === closing || _action === action;
|
|
544
405
|
});
|
|
545
|
-
if (skip)
|
|
546
|
-
continue;
|
|
406
|
+
if (skip) continue;
|
|
547
407
|
if (action === "showCharacter") {
|
|
548
408
|
characters.add(params[0]);
|
|
549
409
|
} else if (action === "playMusic") {
|
|
@@ -554,8 +414,7 @@ var Novely = (() => {
|
|
|
554
414
|
processedQueue.push(item);
|
|
555
415
|
} else if (action === "showBackground" || action === "preload") {
|
|
556
416
|
const skip = next(i).some(([_action]) => action === _action);
|
|
557
|
-
if (skip)
|
|
558
|
-
continue;
|
|
417
|
+
if (skip) continue;
|
|
559
418
|
processedQueue.push(item);
|
|
560
419
|
} else if (action === "animateCharacter") {
|
|
561
420
|
const skip = next(i).some(([_action, character], j, array) => {
|
|
@@ -567,8 +426,7 @@ var Novely = (() => {
|
|
|
567
426
|
const hasBlockingActions = next2.some((item2) => options.skip.has(item2));
|
|
568
427
|
return characterWillAnimate && hasBlockingActions;
|
|
569
428
|
});
|
|
570
|
-
if (skip)
|
|
571
|
-
continue;
|
|
429
|
+
if (skip) continue;
|
|
572
430
|
processedQueue.push(item);
|
|
573
431
|
} else {
|
|
574
432
|
processedQueue.push(item);
|
|
@@ -595,8 +453,7 @@ var Novely = (() => {
|
|
|
595
453
|
var getStack = (ctx) => {
|
|
596
454
|
const { id } = ctx;
|
|
597
455
|
const cached = STACK_MAP.get(id);
|
|
598
|
-
if (cached)
|
|
599
|
-
return cached;
|
|
456
|
+
if (cached) return cached;
|
|
600
457
|
const stack = [];
|
|
601
458
|
STACK_MAP.set(id, stack);
|
|
602
459
|
return stack;
|
|
@@ -758,16 +615,14 @@ var Novely = (() => {
|
|
|
758
615
|
if (isBlockExitStatement(name)) {
|
|
759
616
|
ignore.push(name);
|
|
760
617
|
}
|
|
761
|
-
if (!isBlockStatement(name))
|
|
762
|
-
continue;
|
|
618
|
+
if (!isBlockStatement(name)) continue;
|
|
763
619
|
if (ignore.at(-1)?.startsWith(name)) {
|
|
764
620
|
ignore.pop();
|
|
765
621
|
continue;
|
|
766
622
|
}
|
|
767
623
|
path.push([`${name}:exit`]);
|
|
768
624
|
const prev = findLastPathItemBeforeItemOfType(path.slice(0, i + 1), name);
|
|
769
|
-
if (prev)
|
|
770
|
-
path.push([null, prev[1] + 1]);
|
|
625
|
+
if (prev) path.push([null, prev[1] + 1]);
|
|
771
626
|
if (!isAction(refer(path))) {
|
|
772
627
|
path.pop();
|
|
773
628
|
continue;
|
|
@@ -812,8 +667,7 @@ var Novely = (() => {
|
|
|
812
667
|
const choiceProps = props;
|
|
813
668
|
for (let i = 0; i < choiceProps.length; i++) {
|
|
814
669
|
const branchContent = choiceProps[i];
|
|
815
|
-
if (!Array.isArray(branchContent))
|
|
816
|
-
continue;
|
|
670
|
+
if (!Array.isArray(branchContent)) continue;
|
|
817
671
|
const virtualPath = klona(path);
|
|
818
672
|
virtualPath.push(["choice", i], [null, 0]);
|
|
819
673
|
const innerActions = collectActionsBeforeBlockingAction({
|
|
@@ -854,27 +708,21 @@ var Novely = (() => {
|
|
|
854
708
|
var has = Object.prototype.hasOwnProperty;
|
|
855
709
|
function dequal(foo, bar) {
|
|
856
710
|
var ctor, len;
|
|
857
|
-
if (foo === bar)
|
|
858
|
-
return true;
|
|
711
|
+
if (foo === bar) return true;
|
|
859
712
|
if (foo && bar && (ctor = foo.constructor) === bar.constructor) {
|
|
860
|
-
if (ctor === Date)
|
|
861
|
-
|
|
862
|
-
if (ctor === RegExp)
|
|
863
|
-
return foo.toString() === bar.toString();
|
|
713
|
+
if (ctor === Date) return foo.getTime() === bar.getTime();
|
|
714
|
+
if (ctor === RegExp) return foo.toString() === bar.toString();
|
|
864
715
|
if (ctor === Array) {
|
|
865
716
|
if ((len = foo.length) === bar.length) {
|
|
866
|
-
while (len-- && dequal(foo[len], bar[len]))
|
|
867
|
-
;
|
|
717
|
+
while (len-- && dequal(foo[len], bar[len])) ;
|
|
868
718
|
}
|
|
869
719
|
return len === -1;
|
|
870
720
|
}
|
|
871
721
|
if (!ctor || typeof foo === "object") {
|
|
872
722
|
len = 0;
|
|
873
723
|
for (ctor in foo) {
|
|
874
|
-
if (has.call(foo, ctor) && ++len && !has.call(bar, ctor))
|
|
875
|
-
|
|
876
|
-
if (!(ctor in bar) || !dequal(foo[ctor], bar[ctor]))
|
|
877
|
-
return false;
|
|
724
|
+
if (has.call(foo, ctor) && ++len && !has.call(bar, ctor)) return false;
|
|
725
|
+
if (!(ctor in bar) || !dequal(foo[ctor], bar[ctor])) return false;
|
|
878
726
|
}
|
|
879
727
|
return Object.keys(bar).length === len;
|
|
880
728
|
}
|
|
@@ -891,8 +739,7 @@ var Novely = (() => {
|
|
|
891
739
|
};
|
|
892
740
|
};
|
|
893
741
|
const push = (value) => {
|
|
894
|
-
for (const cb of subscribers)
|
|
895
|
-
cb(value);
|
|
742
|
+
for (const cb of subscribers) cb(value);
|
|
896
743
|
};
|
|
897
744
|
const update = (fn) => {
|
|
898
745
|
push(current = fn(current));
|
|
@@ -922,8 +769,7 @@ var Novely = (() => {
|
|
|
922
769
|
propertyIsEnumerable.call(target, key));
|
|
923
770
|
};
|
|
924
771
|
var getEnumerableOwnPropertySymbols = (target) => {
|
|
925
|
-
if (!getOwnPropertySymbols)
|
|
926
|
-
return [];
|
|
772
|
+
if (!getOwnPropertySymbols) return [];
|
|
927
773
|
return getOwnPropertySymbols(target).filter((symbol) => propertyIsEnumerable.call(target, symbol));
|
|
928
774
|
};
|
|
929
775
|
var keys = (target) => {
|
|
@@ -985,8 +831,7 @@ var Novely = (() => {
|
|
|
985
831
|
var split = (input, delimeters) => {
|
|
986
832
|
const output = [];
|
|
987
833
|
for (const delimeter of delimeters) {
|
|
988
|
-
if (!input)
|
|
989
|
-
break;
|
|
834
|
+
if (!input) break;
|
|
990
835
|
const [start, end] = input.split(delimeter, 2);
|
|
991
836
|
output.push(start);
|
|
992
837
|
input = end;
|
|
@@ -1012,14 +857,12 @@ var Novely = (() => {
|
|
|
1012
857
|
return "";
|
|
1013
858
|
}
|
|
1014
859
|
const path = pathstr.split(".");
|
|
1015
|
-
while (y && x < path.length)
|
|
1016
|
-
y = y[path[x++]];
|
|
860
|
+
while (y && x < path.length) y = y[path[x++]];
|
|
1017
861
|
if (plural && pluralization && y && pr) {
|
|
1018
862
|
y = pluralization[plural][pr.select(y)];
|
|
1019
863
|
}
|
|
1020
864
|
const actionHandler = actions && action ? actions[action] : void 0;
|
|
1021
|
-
if (actionHandler)
|
|
1022
|
-
y = actionHandler(y);
|
|
865
|
+
if (actionHandler) y = actionHandler(y);
|
|
1023
866
|
return y == null ? "" : y;
|
|
1024
867
|
});
|
|
1025
868
|
};
|
|
@@ -1117,8 +960,7 @@ var Novely = (() => {
|
|
|
1117
960
|
|
|
1118
961
|
// src/browser.ts
|
|
1119
962
|
var setupBrowserVisibilityChangeListeners = ({ onChange }) => {
|
|
1120
|
-
if (typeof document === "undefined")
|
|
1121
|
-
return noop;
|
|
963
|
+
if (typeof document === "undefined") return noop;
|
|
1122
964
|
const onVisibilityChange = () => {
|
|
1123
965
|
if (document.visibilityState === "hidden") {
|
|
1124
966
|
onChange();
|
|
@@ -1132,8 +974,138 @@ var Novely = (() => {
|
|
|
1132
974
|
};
|
|
1133
975
|
};
|
|
1134
976
|
|
|
977
|
+
// ../../node_modules/.pnpm/yocto-queue@1.1.1/node_modules/yocto-queue/index.js
|
|
978
|
+
var Node = class {
|
|
979
|
+
value;
|
|
980
|
+
next;
|
|
981
|
+
constructor(value) {
|
|
982
|
+
this.value = value;
|
|
983
|
+
}
|
|
984
|
+
};
|
|
985
|
+
var Queue = class {
|
|
986
|
+
#head;
|
|
987
|
+
#tail;
|
|
988
|
+
#size;
|
|
989
|
+
constructor() {
|
|
990
|
+
this.clear();
|
|
991
|
+
}
|
|
992
|
+
enqueue(value) {
|
|
993
|
+
const node = new Node(value);
|
|
994
|
+
if (this.#head) {
|
|
995
|
+
this.#tail.next = node;
|
|
996
|
+
this.#tail = node;
|
|
997
|
+
} else {
|
|
998
|
+
this.#head = node;
|
|
999
|
+
this.#tail = node;
|
|
1000
|
+
}
|
|
1001
|
+
this.#size++;
|
|
1002
|
+
}
|
|
1003
|
+
dequeue() {
|
|
1004
|
+
const current = this.#head;
|
|
1005
|
+
if (!current) {
|
|
1006
|
+
return;
|
|
1007
|
+
}
|
|
1008
|
+
this.#head = this.#head.next;
|
|
1009
|
+
this.#size--;
|
|
1010
|
+
return current.value;
|
|
1011
|
+
}
|
|
1012
|
+
peek() {
|
|
1013
|
+
if (!this.#head) {
|
|
1014
|
+
return;
|
|
1015
|
+
}
|
|
1016
|
+
return this.#head.value;
|
|
1017
|
+
}
|
|
1018
|
+
clear() {
|
|
1019
|
+
this.#head = void 0;
|
|
1020
|
+
this.#tail = void 0;
|
|
1021
|
+
this.#size = 0;
|
|
1022
|
+
}
|
|
1023
|
+
get size() {
|
|
1024
|
+
return this.#size;
|
|
1025
|
+
}
|
|
1026
|
+
*[Symbol.iterator]() {
|
|
1027
|
+
let current = this.#head;
|
|
1028
|
+
while (current) {
|
|
1029
|
+
yield current.value;
|
|
1030
|
+
current = current.next;
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
};
|
|
1034
|
+
|
|
1035
|
+
// ../../node_modules/.pnpm/p-limit@6.1.0/node_modules/p-limit/index.js
|
|
1036
|
+
function pLimit(concurrency) {
|
|
1037
|
+
validateConcurrency(concurrency);
|
|
1038
|
+
const queue = new Queue();
|
|
1039
|
+
let activeCount = 0;
|
|
1040
|
+
const resumeNext = () => {
|
|
1041
|
+
if (activeCount < concurrency && queue.size > 0) {
|
|
1042
|
+
queue.dequeue()();
|
|
1043
|
+
activeCount++;
|
|
1044
|
+
}
|
|
1045
|
+
};
|
|
1046
|
+
const next = () => {
|
|
1047
|
+
activeCount--;
|
|
1048
|
+
resumeNext();
|
|
1049
|
+
};
|
|
1050
|
+
const run = async (function_, resolve, arguments_) => {
|
|
1051
|
+
const result = (async () => function_(...arguments_))();
|
|
1052
|
+
resolve(result);
|
|
1053
|
+
try {
|
|
1054
|
+
await result;
|
|
1055
|
+
} catch {
|
|
1056
|
+
}
|
|
1057
|
+
next();
|
|
1058
|
+
};
|
|
1059
|
+
const enqueue = (function_, resolve, arguments_) => {
|
|
1060
|
+
new Promise((internalResolve) => {
|
|
1061
|
+
queue.enqueue(internalResolve);
|
|
1062
|
+
}).then(
|
|
1063
|
+
run.bind(void 0, function_, resolve, arguments_)
|
|
1064
|
+
);
|
|
1065
|
+
(async () => {
|
|
1066
|
+
await Promise.resolve();
|
|
1067
|
+
if (activeCount < concurrency) {
|
|
1068
|
+
resumeNext();
|
|
1069
|
+
}
|
|
1070
|
+
})();
|
|
1071
|
+
};
|
|
1072
|
+
const generator = (function_, ...arguments_) => new Promise((resolve) => {
|
|
1073
|
+
enqueue(function_, resolve, arguments_);
|
|
1074
|
+
});
|
|
1075
|
+
Object.defineProperties(generator, {
|
|
1076
|
+
activeCount: {
|
|
1077
|
+
get: () => activeCount
|
|
1078
|
+
},
|
|
1079
|
+
pendingCount: {
|
|
1080
|
+
get: () => queue.size
|
|
1081
|
+
},
|
|
1082
|
+
clearQueue: {
|
|
1083
|
+
value() {
|
|
1084
|
+
queue.clear();
|
|
1085
|
+
}
|
|
1086
|
+
},
|
|
1087
|
+
concurrency: {
|
|
1088
|
+
get: () => concurrency,
|
|
1089
|
+
set(newConcurrency) {
|
|
1090
|
+
validateConcurrency(newConcurrency);
|
|
1091
|
+
concurrency = newConcurrency;
|
|
1092
|
+
queueMicrotask(() => {
|
|
1093
|
+
while (activeCount < concurrency && queue.size > 0) {
|
|
1094
|
+
resumeNext();
|
|
1095
|
+
}
|
|
1096
|
+
});
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
});
|
|
1100
|
+
return generator;
|
|
1101
|
+
}
|
|
1102
|
+
function validateConcurrency(concurrency) {
|
|
1103
|
+
if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) {
|
|
1104
|
+
throw new TypeError("Expected `concurrency` to be a number from 1 and up");
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1135
1108
|
// src/novely.ts
|
|
1136
|
-
var import_p_limit = __toESM(require_p_limit(), 1);
|
|
1137
1109
|
var novely = ({
|
|
1138
1110
|
characters,
|
|
1139
1111
|
characterAssetSizes = {},
|
|
@@ -1158,8 +1130,8 @@ var Novely = (() => {
|
|
|
1158
1130
|
startKey = "start"
|
|
1159
1131
|
}) => {
|
|
1160
1132
|
const languages = Object.keys(translation);
|
|
1161
|
-
const limitScript = (
|
|
1162
|
-
const limitAssetsDownload = (
|
|
1133
|
+
const limitScript = pLimit(1);
|
|
1134
|
+
const limitAssetsDownload = pLimit(parallelAssetsDownloadLimit);
|
|
1163
1135
|
const story = {};
|
|
1164
1136
|
const times = /* @__PURE__ */ new Set();
|
|
1165
1137
|
const ASSETS_TO_PRELOAD = /* @__PURE__ */ new Set();
|
|
@@ -1195,8 +1167,7 @@ var Novely = (() => {
|
|
|
1195
1167
|
}
|
|
1196
1168
|
};
|
|
1197
1169
|
const scriptBase = async (part) => {
|
|
1198
|
-
if (destroyed)
|
|
1199
|
-
return;
|
|
1170
|
+
if (destroyed) return;
|
|
1200
1171
|
Object.assign(story, flattenStory(part));
|
|
1201
1172
|
let loadingIsShown = false;
|
|
1202
1173
|
if (!initialScreenWasShown) {
|
|
@@ -1230,8 +1201,7 @@ var Novely = (() => {
|
|
|
1230
1201
|
}
|
|
1231
1202
|
if (props[0] && typeof props[0] === "object") {
|
|
1232
1203
|
for (const value of Object.values(props[0])) {
|
|
1233
|
-
if (!isImageAsset(value))
|
|
1234
|
-
continue;
|
|
1204
|
+
if (!isImageAsset(value)) continue;
|
|
1235
1205
|
doAction(value);
|
|
1236
1206
|
}
|
|
1237
1207
|
}
|
|
@@ -1312,8 +1282,7 @@ var Novely = (() => {
|
|
|
1312
1282
|
};
|
|
1313
1283
|
dataLoaded.promise.then(onDataLoadedPromise);
|
|
1314
1284
|
const onStorageDataChange = (value) => {
|
|
1315
|
-
if (coreData.get().dataLoaded)
|
|
1316
|
-
storage.set(value);
|
|
1285
|
+
if (coreData.get().dataLoaded) storage.set(value);
|
|
1317
1286
|
};
|
|
1318
1287
|
const throttledOnStorageDataChange = throttle(onStorageDataChange, throttleTimeout);
|
|
1319
1288
|
const throttledEmergencyOnStorageDataChange = throttle(() => {
|
|
@@ -1349,10 +1318,8 @@ var Novely = (() => {
|
|
|
1349
1318
|
onChange: throttledEmergencyOnStorageDataChange
|
|
1350
1319
|
});
|
|
1351
1320
|
const save = (type) => {
|
|
1352
|
-
if (!coreData.get().dataLoaded)
|
|
1353
|
-
|
|
1354
|
-
if (!autosaves && type === "auto")
|
|
1355
|
-
return;
|
|
1321
|
+
if (!coreData.get().dataLoaded) return;
|
|
1322
|
+
if (!autosaves && type === "auto") return;
|
|
1356
1323
|
const stack = useStack(MAIN_CONTEXT_KEY);
|
|
1357
1324
|
const current = klona(stack.value);
|
|
1358
1325
|
storageData.update((prev) => {
|
|
@@ -1365,8 +1332,7 @@ var Novely = (() => {
|
|
|
1365
1332
|
return prev;
|
|
1366
1333
|
};
|
|
1367
1334
|
const last = prev.saves.at(-1);
|
|
1368
|
-
if (!last)
|
|
1369
|
-
return add();
|
|
1335
|
+
if (!last) return add();
|
|
1370
1336
|
current[2][0] = intime(Date.now());
|
|
1371
1337
|
current[2][1] = type;
|
|
1372
1338
|
const isIdentical = dequal(last[0], current[0]) && dequal(last[1], current[1]);
|
|
@@ -1384,8 +1350,7 @@ var Novely = (() => {
|
|
|
1384
1350
|
});
|
|
1385
1351
|
};
|
|
1386
1352
|
const newGame = () => {
|
|
1387
|
-
if (!coreData.get().dataLoaded)
|
|
1388
|
-
return;
|
|
1353
|
+
if (!coreData.get().dataLoaded) return;
|
|
1389
1354
|
const save2 = getDefaultSave(klona(defaultState));
|
|
1390
1355
|
if (autosaves) {
|
|
1391
1356
|
storageData.update((prev) => {
|
|
@@ -1412,8 +1377,7 @@ var Novely = (() => {
|
|
|
1412
1377
|
}
|
|
1413
1378
|
return;
|
|
1414
1379
|
}
|
|
1415
|
-
if (!coreData.get().dataLoaded)
|
|
1416
|
-
return;
|
|
1380
|
+
if (!coreData.get().dataLoaded) return;
|
|
1417
1381
|
let latest = save2 || storageData.get().saves.at(-1);
|
|
1418
1382
|
if (!latest) {
|
|
1419
1383
|
latest = klona(initial);
|
|
@@ -1455,8 +1419,7 @@ var Novely = (() => {
|
|
|
1455
1419
|
const lastQueueItem = queue.at(-1);
|
|
1456
1420
|
const lastQueueItemRequiresUserAction = lastQueueItem && isBlockingAction(lastQueueItem);
|
|
1457
1421
|
await run((item) => {
|
|
1458
|
-
if (!latest)
|
|
1459
|
-
return;
|
|
1422
|
+
if (!latest) return;
|
|
1460
1423
|
if (lastQueueItem === item && lastQueueItemRequiresUserAction) {
|
|
1461
1424
|
return;
|
|
1462
1425
|
}
|
|
@@ -1532,12 +1495,9 @@ var Novely = (() => {
|
|
|
1532
1495
|
useStack(ctx).push(klona(save2));
|
|
1533
1496
|
const assets = [];
|
|
1534
1497
|
await processor.run(([action2, ...props]) => {
|
|
1535
|
-
if (isAudioAction(action2))
|
|
1536
|
-
|
|
1537
|
-
if (action2 === "
|
|
1538
|
-
return;
|
|
1539
|
-
if (action2 === "end")
|
|
1540
|
-
return;
|
|
1498
|
+
if (isAudioAction(action2)) return;
|
|
1499
|
+
if (action2 === "vibrate") return;
|
|
1500
|
+
if (action2 === "end") return;
|
|
1541
1501
|
assetPreloadingCheck(action2, props, assets.push.bind(assets));
|
|
1542
1502
|
return match(action2, props, {
|
|
1543
1503
|
ctx,
|
|
@@ -1606,8 +1566,7 @@ var Novely = (() => {
|
|
|
1606
1566
|
useStack(MAIN_CONTEXT_KEY).push(initial);
|
|
1607
1567
|
const UIInstance = renderer.ui.start();
|
|
1608
1568
|
const enmemory = (ctx) => {
|
|
1609
|
-
if (ctx.meta.restoring)
|
|
1610
|
-
return;
|
|
1569
|
+
if (ctx.meta.restoring) return;
|
|
1611
1570
|
const stack = useStack(ctx);
|
|
1612
1571
|
const current = klona(stack.value);
|
|
1613
1572
|
current[2][1] = "auto";
|
|
@@ -1622,25 +1581,19 @@ var Novely = (() => {
|
|
|
1622
1581
|
const matchActionOptions = {
|
|
1623
1582
|
getContext: renderer.getContext,
|
|
1624
1583
|
push(ctx) {
|
|
1625
|
-
if (ctx.meta.restoring)
|
|
1626
|
-
return;
|
|
1584
|
+
if (ctx.meta.restoring) return;
|
|
1627
1585
|
next(ctx);
|
|
1628
1586
|
render(ctx);
|
|
1629
1587
|
},
|
|
1630
1588
|
forward(ctx) {
|
|
1631
|
-
if (!ctx.meta.preview)
|
|
1632
|
-
enmemory(ctx);
|
|
1589
|
+
if (!ctx.meta.preview) enmemory(ctx);
|
|
1633
1590
|
matchActionOptions.push(ctx);
|
|
1634
|
-
if (!ctx.meta.preview)
|
|
1635
|
-
interactivity(true);
|
|
1591
|
+
if (!ctx.meta.preview) interactivity(true);
|
|
1636
1592
|
},
|
|
1637
1593
|
onBeforeActionCall({ action: action2, props, ctx }) {
|
|
1638
|
-
if (preloadAssets !== "automatic")
|
|
1639
|
-
|
|
1640
|
-
if (
|
|
1641
|
-
return;
|
|
1642
|
-
if (!isBlockingAction([action2, ...props]))
|
|
1643
|
-
return;
|
|
1594
|
+
if (preloadAssets !== "automatic") return;
|
|
1595
|
+
if (ctx.meta.preview || ctx.meta.restoring) return;
|
|
1596
|
+
if (!isBlockingAction([action2, ...props])) return;
|
|
1644
1597
|
try {
|
|
1645
1598
|
const collection = collectActionsBeforeBlockingAction({
|
|
1646
1599
|
path: nextPath(klona(useStack(ctx).value[0])),
|
|
@@ -1675,8 +1628,7 @@ var Novely = (() => {
|
|
|
1675
1628
|
};
|
|
1676
1629
|
const match = matchAction(matchActionOptions, {
|
|
1677
1630
|
wait({ ctx, push }, [time]) {
|
|
1678
|
-
if (ctx.meta.restoring)
|
|
1679
|
-
return;
|
|
1631
|
+
if (ctx.meta.restoring) return;
|
|
1680
1632
|
setTimeout(push, isFunction(time) ? time(getStateAtCtx(ctx)) : time);
|
|
1681
1633
|
},
|
|
1682
1634
|
showBackground({ ctx, push }, [background]) {
|
|
@@ -1726,8 +1678,7 @@ var Novely = (() => {
|
|
|
1726
1678
|
if (DEV && !emotion) {
|
|
1727
1679
|
throw new Error(`Attemp to show character "${character}" without emotion provided.`);
|
|
1728
1680
|
}
|
|
1729
|
-
if (!emotion)
|
|
1730
|
-
return;
|
|
1681
|
+
if (!emotion) return;
|
|
1731
1682
|
if (DEV && !characters[character].emotions[emotion]) {
|
|
1732
1683
|
throw new Error(`Attempt to show character "${character}" with unknown emotion "${emotion}"`);
|
|
1733
1684
|
}
|
|
@@ -1865,8 +1816,7 @@ var Novely = (() => {
|
|
|
1865
1816
|
}
|
|
1866
1817
|
},
|
|
1867
1818
|
end({ ctx }) {
|
|
1868
|
-
if (ctx.meta.preview)
|
|
1869
|
-
return;
|
|
1819
|
+
if (ctx.meta.preview) return;
|
|
1870
1820
|
exit(true, false);
|
|
1871
1821
|
},
|
|
1872
1822
|
input({ ctx, data: data2, forward }, [question, onInput, setup]) {
|
|
@@ -1917,8 +1867,7 @@ var Novely = (() => {
|
|
|
1917
1867
|
if (DEV && classes.length === 0) {
|
|
1918
1868
|
throw new Error("Attempt to use AnimateCharacter without classes. Classes should be provided [https://novely.pages.dev/guide/actions/animateCharacter.html]");
|
|
1919
1869
|
}
|
|
1920
|
-
if (ctx.meta.preview)
|
|
1921
|
-
return;
|
|
1870
|
+
if (ctx.meta.preview) return;
|
|
1922
1871
|
ctx.character(character).animate(classes);
|
|
1923
1872
|
push();
|
|
1924
1873
|
},
|
|
@@ -1931,8 +1880,7 @@ var Novely = (() => {
|
|
|
1931
1880
|
ctx.text(string, forward);
|
|
1932
1881
|
},
|
|
1933
1882
|
exit({ ctx, data: data2 }) {
|
|
1934
|
-
if (ctx.meta.restoring)
|
|
1935
|
-
return;
|
|
1883
|
+
if (ctx.meta.restoring) return;
|
|
1936
1884
|
const { exitImpossible } = exitPath({
|
|
1937
1885
|
path: useStack(ctx).value[0],
|
|
1938
1886
|
refer,
|
|
@@ -2015,8 +1963,7 @@ var Novely = (() => {
|
|
|
2015
1963
|
};
|
|
2016
1964
|
const data = (value) => {
|
|
2017
1965
|
const _data = storageData.get().data;
|
|
2018
|
-
if (!value)
|
|
2019
|
-
return _data;
|
|
1966
|
+
if (!value) return _data;
|
|
2020
1967
|
const val = isFunction(value) ? value(_data) : deepmerge(_data, value);
|
|
2021
1968
|
storageData.update((prev) => {
|
|
2022
1969
|
prev.data = val;
|