@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.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- interface LocalStorageStorageSettings {
1
+ type LocalStorageStorageSettings = {
2
2
  key: string;
3
- }
4
- interface Storage {
3
+ };
4
+ type NovelyStorage = {
5
5
  get: () => Promise<StorageData>;
6
6
  set: (data: StorageData) => Promise<void>;
7
- }
8
- declare const localStorageStorage: (options: LocalStorageStorageSettings) => Storage;
7
+ };
8
+ declare const localStorageStorage: (options: LocalStorageStorageSettings) => NovelyStorage;
9
9
 
10
10
  type PluralType = Intl.LDMLPluralRule;
11
11
  type Pluralization = Partial<Record<PluralType, string>>;
@@ -406,7 +406,7 @@ interface NovelyInit<$Language extends Lang, $Characters extends Record<string,
406
406
  * An object that provides access to the game's storage system.
407
407
  * @default localStorage // at key `novely-game-storage`
408
408
  */
409
- storage?: Storage;
409
+ storage?: NovelyStorage;
410
410
  /**
411
411
  * Delay loading data until Promise is resolved
412
412
  */
@@ -587,6 +587,12 @@ type CustomHandlerFunctionParameters<L extends string, S extends State> = {
587
587
  * ```
588
588
  */
589
589
  getDomNodes: CustomHandlerFunctionGetFn;
590
+ /**
591
+ * Function to get current Path. Path can be mutated. Can be helpful when making complex custom actions.
592
+ *
593
+ * Only use it when you know what you do
594
+ */
595
+ getPath: () => Path;
590
596
  /**
591
597
  * Renderer Context
592
598
  */
@@ -852,7 +858,7 @@ declare const novely: <$Language extends string, $Characters extends Record<stri
852
858
  */
853
859
  typeEssentials: TypeEssentials<$Language, $State, $Data, $Characters>;
854
860
  /**
855
- * Replaces content inside {{braces}} with using global data
861
+ * Replaces content inside {{braces}} using global data
856
862
  * @example
857
863
  * ```ts
858
864
  * data({ name: 'Alexei' })
@@ -864,6 +870,10 @@ declare const novely: <$Language extends string, $Characters extends Record<stri
864
870
  * ```
865
871
  */
866
872
  templateReplace(content: TextContent<$Language, $Data>): string;
873
+ /**
874
+ * Same as `templateReplace` but uses state and requires explicitly providing it
875
+ */
876
+ templateReplaceState(content: TextContent<$Language, $State>, state: State): string;
867
877
  /**
868
878
  * Cancel data loading, hide UI, ignore page change events
869
879
  * Data updates still will work in case Novely already was loaded
@@ -938,4 +948,4 @@ declare const extendAction: <Part0 extends Record<string, (...args: any[]) => Va
938
948
  */
939
949
  declare const asset: (...variants: string[]) => NovelyAsset;
940
950
 
941
- export { type ActionInputOnInputMeta, type ActionInputSetup, type ActionInputSetupCleanup, type ActionProxy, type AllowedContent, type AudioHandle, type BackgroundImage, type BaseTranslationStrings, type Character, type CharacterAssetSizes, type CharacterHandle, type CharactersData, type ChoiceParams, type ConditionParams, type Context, type CoreData, type CustomActionHandle, type CustomHandler, type CustomHandlerFunctionGetFn, type CustomHandlerFunctionParameters, type CustomHandlerGetResult, type CustomHandlerGetResultDataFunction, type Data, type DeepPartial, type DefaultActionProxy, EN, type Emotions, type FunctionParams, type FunctionableValue, type GetActionParameters, type InputHandler, JP, KK, type Lang, type NovelyInit, type NovelyScreen, type Path, type PluralType, type Pluralization, RU, type Renderer, type RendererInit, type RendererInitPreviewReturn, type Save, type Stack, type StackHolder, type State, type StateFunction, type Storage, type StorageData, type StorageMeta, type Stored, type Story, type TextContent, type Thenable, type TranslationActions, type TypeEssentials, type TypewriterSpeed, type ValidAction, asset, extendAction, localStorageStorage, novely };
951
+ export { type ActionInputOnInputMeta, type ActionInputSetup, type ActionInputSetupCleanup, type ActionProxy, type AllowedContent, type AudioHandle, type BackgroundImage, type BaseTranslationStrings, type Character, type CharacterAssetSizes, type CharacterHandle, type CharactersData, type ChoiceParams, type ConditionParams, type Context, type CoreData, type CustomActionHandle, type CustomHandler, type CustomHandlerFunctionGetFn, type CustomHandlerFunctionParameters, type CustomHandlerGetResult, type CustomHandlerGetResultDataFunction, type Data, type DeepPartial, type DefaultActionProxy, EN, type Emotions, type FunctionParams, type FunctionableValue, type GetActionParameters, type InputHandler, JP, KK, type Lang, type NovelyInit, type NovelyScreen, type NovelyStorage, type Path, type PluralType, type Pluralization, RU, type Renderer, type RendererInit, type RendererInitPreviewReturn, type Save, type Stack, type StackHolder, type State, type StateFunction, type StorageData, type StorageMeta, type Stored, type Story, type TextContent, type Thenable, type TranslationActions, type TypeEssentials, type TypewriterSpeed, type ValidAction, asset, extendAction, localStorageStorage, novely };
@@ -87,31 +87,51 @@ 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/json/index.mjs
91
- function klona(val) {
92
- var k, out, tmp;
93
- if (Array.isArray(val)) {
94
- out = Array(k = val.length);
95
- while (k--) out[k] = (tmp = val[k]) && typeof tmp === "object" ? klona(tmp) : tmp;
96
- return out;
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);
97
124
  }
98
- if (Object.prototype.toString.call(val) === "[object Object]") {
99
- out = {};
100
- for (k in val) {
101
- if (k === "__proto__") {
102
- Object.defineProperty(out, k, {
103
- value: klona(val[k]),
104
- configurable: true,
105
- enumerable: true,
106
- writable: true
107
- });
108
- } else {
109
- out[k] = (tmp = val[k]) && typeof tmp === "object" ? klona(tmp) : tmp;
110
- }
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));
111
132
  }
112
- return out;
113
133
  }
114
- return val;
134
+ return tmp || x;
115
135
  }
116
136
 
117
137
  // ../../node_modules/.pnpm/es-toolkit@1.16.0/node_modules/es-toolkit/dist/function/once.mjs
@@ -630,8 +650,8 @@ var Novely = (() => {
630
650
  };
631
651
  return useStack;
632
652
  };
633
- var mapSet = (set, fn) => {
634
- return [...set].map(fn);
653
+ var mapSet = (set2, fn) => {
654
+ return [...set2].map(fn);
635
655
  };
636
656
  var isImageAsset = (asset2) => {
637
657
  return isString(asset2) && isCSSImage(asset2);
@@ -939,13 +959,13 @@ var Novely = (() => {
939
959
  const update = (fn) => {
940
960
  push(current = fn(current));
941
961
  };
942
- const set = (val) => {
962
+ const set2 = (val) => {
943
963
  update(() => val);
944
964
  };
945
965
  const get = () => {
946
966
  return current;
947
967
  };
948
- return { subscribe, update, set, get };
968
+ return { subscribe, update, set: set2, get };
949
969
  };
950
970
 
951
971
  // src/translation.ts
@@ -1009,7 +1029,7 @@ var Novely = (() => {
1009
1029
  CUSTOM_ACTION_MAP.set(ctx.id + fn.key, holder);
1010
1030
  return holder;
1011
1031
  };
1012
- var handleCustomAction = (ctx, fn, { lang, state, setMountElement, setClear, remove: renderersRemove }) => {
1032
+ var handleCustomAction = (ctx, fn, { lang, state, setMountElement, setClear, remove: renderersRemove, getStack: getStack2 }) => {
1013
1033
  const holder = getCustomActionHolder(ctx, fn);
1014
1034
  const flags = {
1015
1035
  ...ctx.meta
@@ -1047,6 +1067,10 @@ var Novely = (() => {
1047
1067
  holder.cleanup();
1048
1068
  renderersRemove();
1049
1069
  };
1070
+ const stack = getStack2(ctx);
1071
+ const getPath = () => {
1072
+ return stack.value[0];
1073
+ };
1050
1074
  return fn({
1051
1075
  flags,
1052
1076
  lang,
@@ -1055,7 +1079,8 @@ var Novely = (() => {
1055
1079
  clear,
1056
1080
  remove,
1057
1081
  rendererContext: ctx,
1058
- getDomNodes
1082
+ getDomNodes,
1083
+ getPath
1059
1084
  });
1060
1085
  };
1061
1086
 
@@ -1532,7 +1557,7 @@ var Novely = (() => {
1532
1557
  renderer.ui.showScreen("game");
1533
1558
  render(context);
1534
1559
  };
1535
- const set = (save2, ctx) => {
1560
+ const set2 = (save2, ctx) => {
1536
1561
  const stack = useStack(ctx || MAIN_CONTEXT_KEY);
1537
1562
  stack.value = save2;
1538
1563
  return restore(save2);
@@ -1730,7 +1755,7 @@ var Novely = (() => {
1730
1755
  mainContextKey: MAIN_CONTEXT_KEY,
1731
1756
  characters: getCharactersData(characters),
1732
1757
  characterAssetSizes,
1733
- set,
1758
+ set: set2,
1734
1759
  restore,
1735
1760
  save,
1736
1761
  newGame,
@@ -2024,7 +2049,8 @@ var Novely = (() => {
2024
2049
  const result = handleCustomAction(ctx, fn, {
2025
2050
  ...ctx.custom(fn),
2026
2051
  state,
2027
- lang
2052
+ lang,
2053
+ getStack: useStack
2028
2054
  });
2029
2055
  const next2 = () => {
2030
2056
  if (fn.requireUserAction && !ctx.meta.preview) {
@@ -2238,7 +2264,7 @@ var Novely = (() => {
2238
2264
  */
2239
2265
  typeEssentials,
2240
2266
  /**
2241
- * Replaces content inside {{braces}} with using global data
2267
+ * Replaces content inside {{braces}} using global data
2242
2268
  * @example
2243
2269
  * ```ts
2244
2270
  * data({ name: 'Alexei' })
@@ -2252,6 +2278,12 @@ var Novely = (() => {
2252
2278
  templateReplace(content) {
2253
2279
  return templateReplace(content);
2254
2280
  },
2281
+ /**
2282
+ * Same as `templateReplace` but uses state and requires explicitly providing it
2283
+ */
2284
+ templateReplaceState(content, state) {
2285
+ return templateReplace(content, state);
2286
+ },
2255
2287
  /**
2256
2288
  * Cancel data loading, hide UI, ignore page change events
2257
2289
  * Data updates still will work in case Novely already was loaded