@novely/core 0.40.3 → 0.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +6 -1
- package/dist/index.global.js +67 -63
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +67 -65
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -53,55 +53,6 @@ var ASSETS_TO_PRELOAD = /* @__PURE__ */ new Set();
|
|
|
53
53
|
|
|
54
54
|
// src/utils.ts
|
|
55
55
|
import { DEV as DEV2 } from "esm-env";
|
|
56
|
-
|
|
57
|
-
// ../../node_modules/.pnpm/klona@2.0.6/node_modules/klona/full/index.mjs
|
|
58
|
-
function set(obj, key, val) {
|
|
59
|
-
if (typeof val.value === "object") val.value = klona(val.value);
|
|
60
|
-
if (!val.enumerable || val.get || val.set || !val.configurable || !val.writable || key === "__proto__") {
|
|
61
|
-
Object.defineProperty(obj, key, val);
|
|
62
|
-
} else obj[key] = val.value;
|
|
63
|
-
}
|
|
64
|
-
function klona(x) {
|
|
65
|
-
if (typeof x !== "object") return x;
|
|
66
|
-
var i = 0, k, list, tmp, str2 = Object.prototype.toString.call(x);
|
|
67
|
-
if (str2 === "[object Object]") {
|
|
68
|
-
tmp = Object.create(x.__proto__ || null);
|
|
69
|
-
} else if (str2 === "[object Array]") {
|
|
70
|
-
tmp = Array(x.length);
|
|
71
|
-
} else if (str2 === "[object Set]") {
|
|
72
|
-
tmp = /* @__PURE__ */ new Set();
|
|
73
|
-
x.forEach(function(val) {
|
|
74
|
-
tmp.add(klona(val));
|
|
75
|
-
});
|
|
76
|
-
} else if (str2 === "[object Map]") {
|
|
77
|
-
tmp = /* @__PURE__ */ new Map();
|
|
78
|
-
x.forEach(function(val, key) {
|
|
79
|
-
tmp.set(klona(key), klona(val));
|
|
80
|
-
});
|
|
81
|
-
} else if (str2 === "[object Date]") {
|
|
82
|
-
tmp = /* @__PURE__ */ new Date(+x);
|
|
83
|
-
} else if (str2 === "[object RegExp]") {
|
|
84
|
-
tmp = new RegExp(x.source, x.flags);
|
|
85
|
-
} else if (str2 === "[object DataView]") {
|
|
86
|
-
tmp = new x.constructor(klona(x.buffer));
|
|
87
|
-
} else if (str2 === "[object ArrayBuffer]") {
|
|
88
|
-
tmp = x.slice(0);
|
|
89
|
-
} else if (str2.slice(-6) === "Array]") {
|
|
90
|
-
tmp = new x.constructor(x);
|
|
91
|
-
}
|
|
92
|
-
if (tmp) {
|
|
93
|
-
for (list = Object.getOwnPropertySymbols(x); i < list.length; i++) {
|
|
94
|
-
set(tmp, list[i], Object.getOwnPropertyDescriptor(x, list[i]));
|
|
95
|
-
}
|
|
96
|
-
for (i = 0, list = Object.getOwnPropertyNames(x); i < list.length; i++) {
|
|
97
|
-
if (Object.hasOwnProperty.call(tmp, k = list[i]) && tmp[k] === x[k]) continue;
|
|
98
|
-
set(tmp, k, Object.getOwnPropertyDescriptor(x, k));
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
return tmp || x;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// src/utils.ts
|
|
105
56
|
import { memoize as memoize2 } from "es-toolkit/function";
|
|
106
57
|
|
|
107
58
|
// src/asset.ts
|
|
@@ -733,7 +684,7 @@ var nextPath = (path) => {
|
|
|
733
684
|
var isBlockingAction = (action) => {
|
|
734
685
|
return isUserRequiredAction(action) || isSkippedDuringRestore(action[0]) && action[0] !== "vibrate";
|
|
735
686
|
};
|
|
736
|
-
var collectActionsBeforeBlockingAction = ({ path, refer }) => {
|
|
687
|
+
var collectActionsBeforeBlockingAction = ({ path, refer, clone }) => {
|
|
737
688
|
const collection = [];
|
|
738
689
|
let action = refer(path);
|
|
739
690
|
while (true) {
|
|
@@ -756,11 +707,12 @@ var collectActionsBeforeBlockingAction = ({ path, refer }) => {
|
|
|
756
707
|
for (let i = 0; i < choiceProps.length; i++) {
|
|
757
708
|
const branchContent = choiceProps[i];
|
|
758
709
|
if (!Array.isArray(branchContent)) continue;
|
|
759
|
-
const virtualPath =
|
|
710
|
+
const virtualPath = clone(path);
|
|
760
711
|
virtualPath.push(["choice", i], [null, 0]);
|
|
761
712
|
const innerActions = collectActionsBeforeBlockingAction({
|
|
762
713
|
path: virtualPath,
|
|
763
|
-
refer
|
|
714
|
+
refer,
|
|
715
|
+
clone
|
|
764
716
|
});
|
|
765
717
|
collection.push(...innerActions);
|
|
766
718
|
}
|
|
@@ -768,11 +720,12 @@ var collectActionsBeforeBlockingAction = ({ path, refer }) => {
|
|
|
768
720
|
const conditionProps = props;
|
|
769
721
|
const conditions = Object.keys(conditionProps[1]);
|
|
770
722
|
for (const condition of conditions) {
|
|
771
|
-
const virtualPath =
|
|
723
|
+
const virtualPath = clone(path);
|
|
772
724
|
virtualPath.push(["condition", condition], [null, 0]);
|
|
773
725
|
const innerActions = collectActionsBeforeBlockingAction({
|
|
774
726
|
path: virtualPath,
|
|
775
|
-
refer
|
|
727
|
+
refer,
|
|
728
|
+
clone
|
|
776
729
|
});
|
|
777
730
|
collection.push(...innerActions);
|
|
778
731
|
}
|
|
@@ -854,6 +807,53 @@ var store = (current, subscribers = /* @__PURE__ */ new Set()) => {
|
|
|
854
807
|
return { subscribe, update, set: set2, get };
|
|
855
808
|
};
|
|
856
809
|
|
|
810
|
+
// ../../node_modules/.pnpm/klona@2.0.6/node_modules/klona/full/index.mjs
|
|
811
|
+
function set(obj, key, val) {
|
|
812
|
+
if (typeof val.value === "object") val.value = klona(val.value);
|
|
813
|
+
if (!val.enumerable || val.get || val.set || !val.configurable || !val.writable || key === "__proto__") {
|
|
814
|
+
Object.defineProperty(obj, key, val);
|
|
815
|
+
} else obj[key] = val.value;
|
|
816
|
+
}
|
|
817
|
+
function klona(x) {
|
|
818
|
+
if (typeof x !== "object") return x;
|
|
819
|
+
var i = 0, k, list, tmp, str2 = Object.prototype.toString.call(x);
|
|
820
|
+
if (str2 === "[object Object]") {
|
|
821
|
+
tmp = Object.create(x.__proto__ || null);
|
|
822
|
+
} else if (str2 === "[object Array]") {
|
|
823
|
+
tmp = Array(x.length);
|
|
824
|
+
} else if (str2 === "[object Set]") {
|
|
825
|
+
tmp = /* @__PURE__ */ new Set();
|
|
826
|
+
x.forEach(function(val) {
|
|
827
|
+
tmp.add(klona(val));
|
|
828
|
+
});
|
|
829
|
+
} else if (str2 === "[object Map]") {
|
|
830
|
+
tmp = /* @__PURE__ */ new Map();
|
|
831
|
+
x.forEach(function(val, key) {
|
|
832
|
+
tmp.set(klona(key), klona(val));
|
|
833
|
+
});
|
|
834
|
+
} else if (str2 === "[object Date]") {
|
|
835
|
+
tmp = /* @__PURE__ */ new Date(+x);
|
|
836
|
+
} else if (str2 === "[object RegExp]") {
|
|
837
|
+
tmp = new RegExp(x.source, x.flags);
|
|
838
|
+
} else if (str2 === "[object DataView]") {
|
|
839
|
+
tmp = new x.constructor(klona(x.buffer));
|
|
840
|
+
} else if (str2 === "[object ArrayBuffer]") {
|
|
841
|
+
tmp = x.slice(0);
|
|
842
|
+
} else if (str2.slice(-6) === "Array]") {
|
|
843
|
+
tmp = new x.constructor(x);
|
|
844
|
+
}
|
|
845
|
+
if (tmp) {
|
|
846
|
+
for (list = Object.getOwnPropertySymbols(x); i < list.length; i++) {
|
|
847
|
+
set(tmp, list[i], Object.getOwnPropertyDescriptor(x, list[i]));
|
|
848
|
+
}
|
|
849
|
+
for (i = 0, list = Object.getOwnPropertyNames(x); i < list.length; i++) {
|
|
850
|
+
if (Object.hasOwnProperty.call(tmp, k = list[i]) && tmp[k] === x[k]) continue;
|
|
851
|
+
set(tmp, k, Object.getOwnPropertyDescriptor(x, k));
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
return tmp || x;
|
|
855
|
+
}
|
|
856
|
+
|
|
857
857
|
// src/translation.ts
|
|
858
858
|
var RGX = /{{(.*?)}}/g;
|
|
859
859
|
var split = (input, delimeters) => {
|
|
@@ -1126,6 +1126,7 @@ var novely = ({
|
|
|
1126
1126
|
preloadAssets = "lazy",
|
|
1127
1127
|
parallelAssetsDownloadLimit = 15,
|
|
1128
1128
|
fetch: request = fetch,
|
|
1129
|
+
cloneFunction: clone = klona,
|
|
1129
1130
|
saveOnUnload = true,
|
|
1130
1131
|
startKey = "start"
|
|
1131
1132
|
}) => {
|
|
@@ -1193,7 +1194,7 @@ var novely = ({
|
|
|
1193
1194
|
};
|
|
1194
1195
|
}
|
|
1195
1196
|
});
|
|
1196
|
-
const getDefaultSave = (state
|
|
1197
|
+
const getDefaultSave = (state) => {
|
|
1197
1198
|
return [
|
|
1198
1199
|
[
|
|
1199
1200
|
["jump", startKey],
|
|
@@ -1215,7 +1216,7 @@ var novely = ({
|
|
|
1215
1216
|
};
|
|
1216
1217
|
const initialData = {
|
|
1217
1218
|
saves: [],
|
|
1218
|
-
data:
|
|
1219
|
+
data: clone(defaultData),
|
|
1219
1220
|
meta: [getLanguageWithoutParameters(), DEFAULT_TYPEWRITER_SPEED, 1, 1, 1]
|
|
1220
1221
|
};
|
|
1221
1222
|
const storageData = store(initialData);
|
|
@@ -1265,7 +1266,7 @@ var novely = ({
|
|
|
1265
1266
|
storageData.set(stored);
|
|
1266
1267
|
};
|
|
1267
1268
|
storageDelay.then(getStoredData);
|
|
1268
|
-
const initial = getDefaultSave(
|
|
1269
|
+
const initial = getDefaultSave(clone(defaultState));
|
|
1269
1270
|
const unsubscribeFromBrowserVisibilityChange = setupBrowserVisibilityChangeListeners({
|
|
1270
1271
|
onChange: throttledEmergencyOnStorageDataChange
|
|
1271
1272
|
});
|
|
@@ -1273,7 +1274,7 @@ var novely = ({
|
|
|
1273
1274
|
if (!coreData.get().dataLoaded) return;
|
|
1274
1275
|
if (!autosaves && type === "auto") return;
|
|
1275
1276
|
const stack = useStack(MAIN_CONTEXT_KEY);
|
|
1276
|
-
const current =
|
|
1277
|
+
const current = clone(stack.value);
|
|
1277
1278
|
storageData.update((prev) => {
|
|
1278
1279
|
const replace2 = () => {
|
|
1279
1280
|
prev.saves[prev.saves.length - 1] = current;
|
|
@@ -1303,7 +1304,7 @@ var novely = ({
|
|
|
1303
1304
|
};
|
|
1304
1305
|
const newGame = () => {
|
|
1305
1306
|
if (!coreData.get().dataLoaded) return;
|
|
1306
|
-
const save2 = getDefaultSave(
|
|
1307
|
+
const save2 = getDefaultSave(clone(defaultState));
|
|
1307
1308
|
if (autosaves) {
|
|
1308
1309
|
storageData.update((prev) => {
|
|
1309
1310
|
return prev.saves.push(save2), prev;
|
|
@@ -1332,7 +1333,7 @@ var novely = ({
|
|
|
1332
1333
|
if (!coreData.get().dataLoaded) return;
|
|
1333
1334
|
let latest = save2 || storageData.get().saves.at(-1);
|
|
1334
1335
|
if (!latest) {
|
|
1335
|
-
latest =
|
|
1336
|
+
latest = clone(initial);
|
|
1336
1337
|
storageData.update((prev) => {
|
|
1337
1338
|
prev.saves.push(latest);
|
|
1338
1339
|
return prev;
|
|
@@ -1444,7 +1445,7 @@ var novely = ({
|
|
|
1444
1445
|
const processor = createQueueProcessor(queue, {
|
|
1445
1446
|
skip: EMPTY_SET
|
|
1446
1447
|
});
|
|
1447
|
-
useStack(ctx).push(
|
|
1448
|
+
useStack(ctx).push(clone(save2));
|
|
1448
1449
|
const assets = [];
|
|
1449
1450
|
await processor.run(([action2, ...props]) => {
|
|
1450
1451
|
if (isAudioAction(action2)) return;
|
|
@@ -1539,7 +1540,7 @@ var novely = ({
|
|
|
1539
1540
|
const enmemory = (ctx) => {
|
|
1540
1541
|
if (ctx.meta.restoring) return;
|
|
1541
1542
|
const stack = useStack(ctx);
|
|
1542
|
-
const current =
|
|
1543
|
+
const current = clone(stack.value);
|
|
1543
1544
|
current[2][1] = "auto";
|
|
1544
1545
|
stack.push(current);
|
|
1545
1546
|
save("auto");
|
|
@@ -1567,8 +1568,9 @@ var novely = ({
|
|
|
1567
1568
|
if (!isBlockingAction([action2, ...props])) return;
|
|
1568
1569
|
try {
|
|
1569
1570
|
const collection = collectActionsBeforeBlockingAction({
|
|
1570
|
-
path: nextPath(
|
|
1571
|
-
refer
|
|
1571
|
+
path: nextPath(clone(useStack(ctx).value[0])),
|
|
1572
|
+
refer,
|
|
1573
|
+
clone
|
|
1572
1574
|
});
|
|
1573
1575
|
for (const [action3, ...props2] of collection) {
|
|
1574
1576
|
huntAssets({
|
|
@@ -1950,7 +1952,7 @@ var novely = ({
|
|
|
1950
1952
|
c: null
|
|
1951
1953
|
};
|
|
1952
1954
|
const getCurrentStorageData = () => {
|
|
1953
|
-
return coreData.get().dataLoaded ?
|
|
1955
|
+
return coreData.get().dataLoaded ? clone(storageData.get()) : null;
|
|
1954
1956
|
};
|
|
1955
1957
|
const setStorageData = (data2) => {
|
|
1956
1958
|
if (destroyed) {
|