@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 CHANGED
@@ -328,6 +328,7 @@ type CharactersData<$Characters extends Record<string, Character<Lang>>> = {
328
328
  };
329
329
  };
330
330
  type AssetsPreloading = 'lazy' | 'blocking' | 'automatic';
331
+ type CloneFN = <T>(value: T) => T;
331
332
  interface NovelyInit<$Language extends Lang, $Characters extends Record<string, Character<NoInfer<$Language>>>, $State extends State, $Data extends Data, $Actions extends Record<string, (...args: any[]) => ValidAction>> {
332
333
  /**
333
334
  * An object containing the characters in the game.
@@ -509,6 +510,10 @@ interface NovelyInit<$Language extends Lang, $Characters extends Record<string,
509
510
  * Fetching function
510
511
  */
511
512
  fetch?: typeof fetch;
513
+ /**
514
+ * Function for clonning operations
515
+ */
516
+ cloneFunction?: CloneFN;
512
517
  /**
513
518
  * When page is going to be unloaded will call `storage.set` method
514
519
  * If 'prod' is passed enable only in production env.
@@ -796,7 +801,7 @@ type ChoiceParams<T> = T extends TypeEssentials<infer $Lang, infer $State, any,
796
801
  type FunctionParams<T> = T extends TypeEssentials<infer $Lang, infer $State, any, any> ? FunctionActionProps<$Lang, $State> : never;
797
802
  type InputHandler<T> = T extends TypeEssentials<infer $Lang, infer $State, any, any> ? ActionInputOnInputMeta<$Lang, $State> : never;
798
803
 
799
- declare const novely: <$Language extends string, $Characters extends Record<string, Character<$Language>>, $State extends State, $Data extends Data, $Actions extends Record<string, (...args: any[]) => ValidAction>>({ characters, characterAssetSizes, defaultEmotions, storage, storageDelay, renderer: createRenderer, initialScreen, translation, state: defaultState, data: defaultData, autosaves, migrations, throttleTimeout, getLanguage, overrideLanguage, askBeforeExit, preloadAssets, parallelAssetsDownloadLimit, fetch: request, saveOnUnload, startKey }: NovelyInit<$Language, $Characters, $State, $Data, $Actions>) => {
804
+ declare const novely: <$Language extends string, $Characters extends Record<string, Character<$Language>>, $State extends State, $Data extends Data, $Actions extends Record<string, (...args: any[]) => ValidAction>>({ characters, characterAssetSizes, defaultEmotions, storage, storageDelay, renderer: createRenderer, initialScreen, translation, state: defaultState, data: defaultData, autosaves, migrations, throttleTimeout, getLanguage, overrideLanguage, askBeforeExit, preloadAssets, parallelAssetsDownloadLimit, fetch: request, cloneFunction: clone, saveOnUnload, startKey, }: NovelyInit<$Language, $Characters, $State, $Data, $Actions>) => {
800
805
  /**
801
806
  * Function to set game script
802
807
  *
@@ -87,53 +87,6 @@ var Novely = (() => {
87
87
  // ../../node_modules/.pnpm/esm-env@1.0.0/node_modules/esm-env/prod-ssr.js
88
88
  var DEV = false;
89
89
 
90
- // ../../node_modules/.pnpm/klona@2.0.6/node_modules/klona/full/index.mjs
91
- function set(obj, key, val) {
92
- if (typeof val.value === "object") val.value = klona(val.value);
93
- if (!val.enumerable || val.get || val.set || !val.configurable || !val.writable || key === "__proto__") {
94
- Object.defineProperty(obj, key, val);
95
- } else obj[key] = val.value;
96
- }
97
- function klona(x) {
98
- if (typeof x !== "object") return x;
99
- var i = 0, k, list, tmp, str2 = Object.prototype.toString.call(x);
100
- if (str2 === "[object Object]") {
101
- tmp = Object.create(x.__proto__ || null);
102
- } else if (str2 === "[object Array]") {
103
- tmp = Array(x.length);
104
- } else if (str2 === "[object Set]") {
105
- tmp = /* @__PURE__ */ new Set();
106
- x.forEach(function(val) {
107
- tmp.add(klona(val));
108
- });
109
- } else if (str2 === "[object Map]") {
110
- tmp = /* @__PURE__ */ new Map();
111
- x.forEach(function(val, key) {
112
- tmp.set(klona(key), klona(val));
113
- });
114
- } else if (str2 === "[object Date]") {
115
- tmp = /* @__PURE__ */ new Date(+x);
116
- } else if (str2 === "[object RegExp]") {
117
- tmp = new RegExp(x.source, x.flags);
118
- } else if (str2 === "[object DataView]") {
119
- tmp = new x.constructor(klona(x.buffer));
120
- } else if (str2 === "[object ArrayBuffer]") {
121
- tmp = x.slice(0);
122
- } else if (str2.slice(-6) === "Array]") {
123
- tmp = new x.constructor(x);
124
- }
125
- if (tmp) {
126
- for (list = Object.getOwnPropertySymbols(x); i < list.length; i++) {
127
- set(tmp, list[i], Object.getOwnPropertyDescriptor(x, list[i]));
128
- }
129
- for (i = 0, list = Object.getOwnPropertyNames(x); i < list.length; i++) {
130
- if (Object.hasOwnProperty.call(tmp, k = list[i]) && tmp[k] === x[k]) continue;
131
- set(tmp, k, Object.getOwnPropertyDescriptor(x, k));
132
- }
133
- }
134
- return tmp || x;
135
- }
136
-
137
90
  // ../../node_modules/.pnpm/es-toolkit@1.16.0/node_modules/es-toolkit/dist/function/once.mjs
138
91
  function once(func) {
139
92
  let called = false;
@@ -803,7 +756,7 @@ var Novely = (() => {
803
756
  var isBlockingAction = (action) => {
804
757
  return isUserRequiredAction(action) || isSkippedDuringRestore(action[0]) && action[0] !== "vibrate";
805
758
  };
806
- var collectActionsBeforeBlockingAction = ({ path, refer }) => {
759
+ var collectActionsBeforeBlockingAction = ({ path, refer, clone }) => {
807
760
  const collection = [];
808
761
  let action = refer(path);
809
762
  while (true) {
@@ -826,11 +779,12 @@ var Novely = (() => {
826
779
  for (let i = 0; i < choiceProps.length; i++) {
827
780
  const branchContent = choiceProps[i];
828
781
  if (!Array.isArray(branchContent)) continue;
829
- const virtualPath = klona(path);
782
+ const virtualPath = clone(path);
830
783
  virtualPath.push(["choice", i], [null, 0]);
831
784
  const innerActions = collectActionsBeforeBlockingAction({
832
785
  path: virtualPath,
833
- refer
786
+ refer,
787
+ clone
834
788
  });
835
789
  collection.push(...innerActions);
836
790
  }
@@ -838,11 +792,12 @@ var Novely = (() => {
838
792
  const conditionProps = props;
839
793
  const conditions = Object.keys(conditionProps[1]);
840
794
  for (const condition of conditions) {
841
- const virtualPath = klona(path);
795
+ const virtualPath = clone(path);
842
796
  virtualPath.push(["condition", condition], [null, 0]);
843
797
  const innerActions = collectActionsBeforeBlockingAction({
844
798
  path: virtualPath,
845
- refer
799
+ refer,
800
+ clone
846
801
  });
847
802
  collection.push(...innerActions);
848
803
  }
@@ -968,6 +923,53 @@ var Novely = (() => {
968
923
  return { subscribe, update, set: set2, get };
969
924
  };
970
925
 
926
+ // ../../node_modules/.pnpm/klona@2.0.6/node_modules/klona/full/index.mjs
927
+ function set(obj, key, val) {
928
+ if (typeof val.value === "object") val.value = klona(val.value);
929
+ if (!val.enumerable || val.get || val.set || !val.configurable || !val.writable || key === "__proto__") {
930
+ Object.defineProperty(obj, key, val);
931
+ } else obj[key] = val.value;
932
+ }
933
+ function klona(x) {
934
+ if (typeof x !== "object") return x;
935
+ var i = 0, k, list, tmp, str2 = Object.prototype.toString.call(x);
936
+ if (str2 === "[object Object]") {
937
+ tmp = Object.create(x.__proto__ || null);
938
+ } else if (str2 === "[object Array]") {
939
+ tmp = Array(x.length);
940
+ } else if (str2 === "[object Set]") {
941
+ tmp = /* @__PURE__ */ new Set();
942
+ x.forEach(function(val) {
943
+ tmp.add(klona(val));
944
+ });
945
+ } else if (str2 === "[object Map]") {
946
+ tmp = /* @__PURE__ */ new Map();
947
+ x.forEach(function(val, key) {
948
+ tmp.set(klona(key), klona(val));
949
+ });
950
+ } else if (str2 === "[object Date]") {
951
+ tmp = /* @__PURE__ */ new Date(+x);
952
+ } else if (str2 === "[object RegExp]") {
953
+ tmp = new RegExp(x.source, x.flags);
954
+ } else if (str2 === "[object DataView]") {
955
+ tmp = new x.constructor(klona(x.buffer));
956
+ } else if (str2 === "[object ArrayBuffer]") {
957
+ tmp = x.slice(0);
958
+ } else if (str2.slice(-6) === "Array]") {
959
+ tmp = new x.constructor(x);
960
+ }
961
+ if (tmp) {
962
+ for (list = Object.getOwnPropertySymbols(x); i < list.length; i++) {
963
+ set(tmp, list[i], Object.getOwnPropertyDescriptor(x, list[i]));
964
+ }
965
+ for (i = 0, list = Object.getOwnPropertyNames(x); i < list.length; i++) {
966
+ if (Object.hasOwnProperty.call(tmp, k = list[i]) && tmp[k] === x[k]) continue;
967
+ set(tmp, k, Object.getOwnPropertyDescriptor(x, k));
968
+ }
969
+ }
970
+ return tmp || x;
971
+ }
972
+
971
973
  // src/translation.ts
972
974
  var RGX = /{{(.*?)}}/g;
973
975
  var split = (input, delimeters) => {
@@ -1367,6 +1369,7 @@ var Novely = (() => {
1367
1369
  preloadAssets = "lazy",
1368
1370
  parallelAssetsDownloadLimit = 15,
1369
1371
  fetch: request = fetch,
1372
+ cloneFunction: clone = klona,
1370
1373
  saveOnUnload = true,
1371
1374
  startKey = "start"
1372
1375
  }) => {
@@ -1434,7 +1437,7 @@ var Novely = (() => {
1434
1437
  };
1435
1438
  }
1436
1439
  });
1437
- const getDefaultSave = (state = {}) => {
1440
+ const getDefaultSave = (state) => {
1438
1441
  return [
1439
1442
  [
1440
1443
  ["jump", startKey],
@@ -1456,7 +1459,7 @@ var Novely = (() => {
1456
1459
  };
1457
1460
  const initialData = {
1458
1461
  saves: [],
1459
- data: klona(defaultData),
1462
+ data: clone(defaultData),
1460
1463
  meta: [getLanguageWithoutParameters(), DEFAULT_TYPEWRITER_SPEED, 1, 1, 1]
1461
1464
  };
1462
1465
  const storageData = store(initialData);
@@ -1506,7 +1509,7 @@ var Novely = (() => {
1506
1509
  storageData.set(stored);
1507
1510
  };
1508
1511
  storageDelay.then(getStoredData);
1509
- const initial = getDefaultSave(klona(defaultState));
1512
+ const initial = getDefaultSave(clone(defaultState));
1510
1513
  const unsubscribeFromBrowserVisibilityChange = setupBrowserVisibilityChangeListeners({
1511
1514
  onChange: throttledEmergencyOnStorageDataChange
1512
1515
  });
@@ -1514,7 +1517,7 @@ var Novely = (() => {
1514
1517
  if (!coreData.get().dataLoaded) return;
1515
1518
  if (!autosaves && type === "auto") return;
1516
1519
  const stack = useStack(MAIN_CONTEXT_KEY);
1517
- const current = klona(stack.value);
1520
+ const current = clone(stack.value);
1518
1521
  storageData.update((prev) => {
1519
1522
  const replace2 = () => {
1520
1523
  prev.saves[prev.saves.length - 1] = current;
@@ -1544,7 +1547,7 @@ var Novely = (() => {
1544
1547
  };
1545
1548
  const newGame = () => {
1546
1549
  if (!coreData.get().dataLoaded) return;
1547
- const save2 = getDefaultSave(klona(defaultState));
1550
+ const save2 = getDefaultSave(clone(defaultState));
1548
1551
  if (autosaves) {
1549
1552
  storageData.update((prev) => {
1550
1553
  return prev.saves.push(save2), prev;
@@ -1573,7 +1576,7 @@ var Novely = (() => {
1573
1576
  if (!coreData.get().dataLoaded) return;
1574
1577
  let latest = save2 || storageData.get().saves.at(-1);
1575
1578
  if (!latest) {
1576
- latest = klona(initial);
1579
+ latest = clone(initial);
1577
1580
  storageData.update((prev) => {
1578
1581
  prev.saves.push(latest);
1579
1582
  return prev;
@@ -1685,7 +1688,7 @@ var Novely = (() => {
1685
1688
  const processor = createQueueProcessor(queue, {
1686
1689
  skip: EMPTY_SET
1687
1690
  });
1688
- useStack(ctx).push(klona(save2));
1691
+ useStack(ctx).push(clone(save2));
1689
1692
  const assets = [];
1690
1693
  await processor.run(([action2, ...props]) => {
1691
1694
  if (isAudioAction(action2)) return;
@@ -1780,7 +1783,7 @@ var Novely = (() => {
1780
1783
  const enmemory = (ctx) => {
1781
1784
  if (ctx.meta.restoring) return;
1782
1785
  const stack = useStack(ctx);
1783
- const current = klona(stack.value);
1786
+ const current = clone(stack.value);
1784
1787
  current[2][1] = "auto";
1785
1788
  stack.push(current);
1786
1789
  save("auto");
@@ -1808,8 +1811,9 @@ var Novely = (() => {
1808
1811
  if (!isBlockingAction([action2, ...props])) return;
1809
1812
  try {
1810
1813
  const collection = collectActionsBeforeBlockingAction({
1811
- path: nextPath(klona(useStack(ctx).value[0])),
1812
- refer
1814
+ path: nextPath(clone(useStack(ctx).value[0])),
1815
+ refer,
1816
+ clone
1813
1817
  });
1814
1818
  for (const [action3, ...props2] of collection) {
1815
1819
  huntAssets({
@@ -2191,7 +2195,7 @@ var Novely = (() => {
2191
2195
  c: null
2192
2196
  };
2193
2197
  const getCurrentStorageData = () => {
2194
- return coreData.get().dataLoaded ? klona(storageData.get()) : null;
2198
+ return coreData.get().dataLoaded ? clone(storageData.get()) : null;
2195
2199
  };
2196
2200
  const setStorageData = (data2) => {
2197
2201
  if (destroyed) {