@novely/core 0.40.1 → 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
@@ -895,7 +915,7 @@ var getCustomActionHolder = (ctx, fn) => {
895
915
  CUSTOM_ACTION_MAP.set(ctx.id + fn.key, holder);
896
916
  return holder;
897
917
  };
898
- var handleCustomAction = (ctx, fn, { lang, state, setMountElement, setClear, remove: renderersRemove }) => {
918
+ var handleCustomAction = (ctx, fn, { lang, state, setMountElement, setClear, remove: renderersRemove, getStack: getStack2 }) => {
899
919
  const holder = getCustomActionHolder(ctx, fn);
900
920
  const flags = {
901
921
  ...ctx.meta
@@ -933,6 +953,10 @@ var handleCustomAction = (ctx, fn, { lang, state, setMountElement, setClear, rem
933
953
  holder.cleanup();
934
954
  renderersRemove();
935
955
  };
956
+ const stack = getStack2(ctx);
957
+ const getPath = () => {
958
+ return stack.value[0];
959
+ };
936
960
  return fn({
937
961
  flags,
938
962
  lang,
@@ -941,7 +965,8 @@ var handleCustomAction = (ctx, fn, { lang, state, setMountElement, setClear, rem
941
965
  clear,
942
966
  remove,
943
967
  rendererContext: ctx,
944
- getDomNodes
968
+ getDomNodes,
969
+ getPath
945
970
  });
946
971
  };
947
972
 
@@ -1291,7 +1316,7 @@ var novely = ({
1291
1316
  renderer.ui.showScreen("game");
1292
1317
  render(context);
1293
1318
  };
1294
- const set = (save2, ctx) => {
1319
+ const set2 = (save2, ctx) => {
1295
1320
  const stack = useStack(ctx || MAIN_CONTEXT_KEY);
1296
1321
  stack.value = save2;
1297
1322
  return restore(save2);
@@ -1489,7 +1514,7 @@ var novely = ({
1489
1514
  mainContextKey: MAIN_CONTEXT_KEY,
1490
1515
  characters: getCharactersData(characters),
1491
1516
  characterAssetSizes,
1492
- set,
1517
+ set: set2,
1493
1518
  restore,
1494
1519
  save,
1495
1520
  newGame,
@@ -1783,7 +1808,8 @@ var novely = ({
1783
1808
  const result = handleCustomAction(ctx, fn, {
1784
1809
  ...ctx.custom(fn),
1785
1810
  state,
1786
- lang
1811
+ lang,
1812
+ getStack: useStack
1787
1813
  });
1788
1814
  const next2 = () => {
1789
1815
  if (fn.requireUserAction && !ctx.meta.preview) {
@@ -1997,7 +2023,7 @@ var novely = ({
1997
2023
  */
1998
2024
  typeEssentials,
1999
2025
  /**
2000
- * Replaces content inside {{braces}} with using global data
2026
+ * Replaces content inside {{braces}} using global data
2001
2027
  * @example
2002
2028
  * ```ts
2003
2029
  * data({ name: 'Alexei' })
@@ -2011,6 +2037,12 @@ var novely = ({
2011
2037
  templateReplace(content) {
2012
2038
  return templateReplace(content);
2013
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
+ },
2014
2046
  /**
2015
2047
  * Cancel data loading, hide UI, ignore page change events
2016
2048
  * Data updates still will work in case Novely already was loaded