@novely/core 0.40.2 → 0.40.3

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.js CHANGED
@@ -54,31 +54,51 @@ var ASSETS_TO_PRELOAD = /* @__PURE__ */ new Set();
54
54
  // src/utils.ts
55
55
  import { DEV as DEV2 } from "esm-env";
56
56
 
57
- // ../../node_modules/.pnpm/klona@2.0.6/node_modules/klona/json/index.mjs
58
- function klona(val) {
59
- var k, out, tmp;
60
- if (Array.isArray(val)) {
61
- out = Array(k = val.length);
62
- while (k--) out[k] = (tmp = val[k]) && typeof tmp === "object" ? klona(tmp) : tmp;
63
- return out;
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);
64
91
  }
65
- if (Object.prototype.toString.call(val) === "[object Object]") {
66
- out = {};
67
- for (k in val) {
68
- if (k === "__proto__") {
69
- Object.defineProperty(out, k, {
70
- value: klona(val[k]),
71
- configurable: true,
72
- enumerable: true,
73
- writable: true
74
- });
75
- } else {
76
- out[k] = (tmp = val[k]) && typeof tmp === "object" ? klona(tmp) : tmp;
77
- }
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));
78
99
  }
79
- return out;
80
100
  }
81
- return val;
101
+ return tmp || x;
82
102
  }
83
103
 
84
104
  // src/utils.ts
@@ -560,8 +580,8 @@ var createUseStackFunction = (renderer) => {
560
580
  };
561
581
  return useStack;
562
582
  };
563
- var mapSet = (set, fn) => {
564
- return [...set].map(fn);
583
+ var mapSet = (set2, fn) => {
584
+ return [...set2].map(fn);
565
585
  };
566
586
  var isImageAsset = (asset2) => {
567
587
  return isString(asset2) && isCSSImage(asset2);
@@ -825,13 +845,13 @@ var store = (current, subscribers = /* @__PURE__ */ new Set()) => {
825
845
  const update = (fn) => {
826
846
  push(current = fn(current));
827
847
  };
828
- const set = (val) => {
848
+ const set2 = (val) => {
829
849
  update(() => val);
830
850
  };
831
851
  const get = () => {
832
852
  return current;
833
853
  };
834
- return { subscribe, update, set, get };
854
+ return { subscribe, update, set: set2, get };
835
855
  };
836
856
 
837
857
  // src/translation.ts
@@ -1296,7 +1316,7 @@ var novely = ({
1296
1316
  renderer.ui.showScreen("game");
1297
1317
  render(context);
1298
1318
  };
1299
- const set = (save2, ctx) => {
1319
+ const set2 = (save2, ctx) => {
1300
1320
  const stack = useStack(ctx || MAIN_CONTEXT_KEY);
1301
1321
  stack.value = save2;
1302
1322
  return restore(save2);
@@ -1494,7 +1514,7 @@ var novely = ({
1494
1514
  mainContextKey: MAIN_CONTEXT_KEY,
1495
1515
  characters: getCharactersData(characters),
1496
1516
  characterAssetSizes,
1497
- set,
1517
+ set: set2,
1498
1518
  restore,
1499
1519
  save,
1500
1520
  newGame,
@@ -2003,7 +2023,7 @@ var novely = ({
2003
2023
  */
2004
2024
  typeEssentials,
2005
2025
  /**
2006
- * Replaces content inside {{braces}} with using global data
2026
+ * Replaces content inside {{braces}} using global data
2007
2027
  * @example
2008
2028
  * ```ts
2009
2029
  * data({ name: 'Alexei' })
@@ -2017,6 +2037,12 @@ var novely = ({
2017
2037
  templateReplace(content) {
2018
2038
  return templateReplace(content);
2019
2039
  },
2040
+ /**
2041
+ * Same as `templateReplace` but uses state and requires explicitly providing it
2042
+ */
2043
+ templateReplaceState(content, state) {
2044
+ return templateReplace(content, state);
2045
+ },
2020
2046
  /**
2021
2047
  * Cancel data loading, hide UI, ignore page change events
2022
2048
  * Data updates still will work in case Novely already was loaded