@novely/core 0.33.0-beta.0 → 0.33.0-beta.2

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
@@ -95,6 +95,11 @@ type Context = {
95
95
  }, resolve: () => void) => void;
96
96
  custom: (fn: CustomHandler<Lang, State>, push: () => void) => Thenable<void>;
97
97
  clearCustom: (fn: CustomHandler<Lang, State>) => void;
98
+ /**
99
+ * Clears all mentioned actions except for preserved one
100
+ * @param preserve Action to preserve
101
+ */
102
+ clearAction: (preserve: 'dialog' | 'choice' | 'input' | 'text') => void;
98
103
  text: (str: string, resolve: () => void) => void;
99
104
  vibrate: (pattern: VibratePattern) => void;
100
105
  audio: {
@@ -256,6 +261,10 @@ type NovelyScreen = 'mainmenu' | 'game' | 'saves' | 'settings';
256
261
  type DeepPartial<T> = unknown extends T ? T : T extends object ? {
257
262
  [P in keyof T]?: T[P] extends Array<infer U> ? Array<DeepPartial<U>> : T[P] extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : DeepPartial<T[P]>;
258
263
  } : T;
264
+ /**
265
+ *
266
+ */
267
+ type Assign<A extends object, B extends object> = Pick<A, Exclude<keyof A, keyof B>> & B;
259
268
  type NonEmptyRecord<T extends Record<PropertyKey, unknown>> = keyof T extends never ? never : T;
260
269
  type CoreData = {
261
270
  dataLoaded: boolean;
@@ -740,4 +749,19 @@ declare const novely: <$Language extends string, $Characters extends Record<stri
740
749
  getCurrentStorageData: () => StorageData<$Language, $Data> | null;
741
750
  };
742
751
 
743
- export { type ActionInputOnInputMeta, type ActionInputSetup, type ActionProxy, type AllowedContent, type AudioHandle, type BackgroundImage, type BaseTranslationStrings, type Character, type CharacterHandle, type ConditionParams, type Context, type CoreData, type CustomHandler, type CustomHandlerFunctionGetFn, type CustomHandlerFunctionParameters, type CustomHandlerGetResult, type CustomHandlerGetResultDataFunction, type Data, type DeepPartial, type DefaultActionProxy, EN, type Emotions, type FunctionableValue, type GetActionParameters, JP, KK, type Lang, type NovelyInit, type NovelyScreen, type Path, type PluralType, type Pluralization, RU, type Renderer, type RendererInit, 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 TypewriterSpeed, type ValidAction, localStorageStorage, novely };
752
+ /**
753
+ * Extens core action with custom actions
754
+ * @param base Actions object you will extend, `engine.action`
755
+ * @param extension Actions object you will extend with
756
+ * @example
757
+ * ```ts
758
+ * const action = extendAction(engine.action, {
759
+ * particles: (options: Parameters<typeof particles>[0]) => {
760
+ * return ['custom', particles(options)]
761
+ * }
762
+ * })
763
+ * ```
764
+ */
765
+ declare const extendAction: <Part0 extends Record<string, (...args: any[]) => ValidAction>, Part1 extends Record<string, (...args: any[]) => ValidAction>>(base: Part0, extension: Part1) => Readonly<Assign<Part0, Part1>>;
766
+
767
+ export { type ActionInputOnInputMeta, type ActionInputSetup, type ActionProxy, type AllowedContent, type AudioHandle, type BackgroundImage, type BaseTranslationStrings, type Character, type CharacterHandle, type ConditionParams, type Context, type CoreData, type CustomHandler, type CustomHandlerFunctionGetFn, type CustomHandlerFunctionParameters, type CustomHandlerGetResult, type CustomHandlerGetResultDataFunction, type Data, type DeepPartial, type DefaultActionProxy, EN, type Emotions, type FunctionableValue, type GetActionParameters, JP, KK, type Lang, type NovelyInit, type NovelyScreen, type Path, type PluralType, type Pluralization, RU, type Renderer, type RendererInit, 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 TypewriterSpeed, type ValidAction, extendAction, localStorageStorage, novely };
@@ -156,6 +156,7 @@ var Novely = (() => {
156
156
  JP: () => JP,
157
157
  KK: () => KK,
158
158
  RU: () => RU,
159
+ extendAction: () => extendAction,
159
160
  localStorageStorage: () => localStorageStorage,
160
161
  novely: () => novely
161
162
  });
@@ -214,6 +215,34 @@ var Novely = (() => {
214
215
  // ../../node_modules/.pnpm/esm-env@1.0.0/node_modules/esm-env/prod-ssr.js
215
216
  var DEV = false;
216
217
 
218
+ // ../../node_modules/.pnpm/klona@2.0.6/node_modules/klona/json/index.mjs
219
+ function klona(val) {
220
+ var k, out, tmp;
221
+ if (Array.isArray(val)) {
222
+ out = Array(k = val.length);
223
+ while (k--)
224
+ out[k] = (tmp = val[k]) && typeof tmp === "object" ? klona(tmp) : tmp;
225
+ return out;
226
+ }
227
+ if (Object.prototype.toString.call(val) === "[object Object]") {
228
+ out = {};
229
+ for (k in val) {
230
+ if (k === "__proto__") {
231
+ Object.defineProperty(out, k, {
232
+ value: klona(val[k]),
233
+ configurable: true,
234
+ enumerable: true,
235
+ writable: true
236
+ });
237
+ } else {
238
+ out[k] = (tmp = val[k]) && typeof tmp === "object" ? klona(tmp) : tmp;
239
+ }
240
+ }
241
+ return out;
242
+ }
243
+ return val;
244
+ }
245
+
217
246
  // src/utils.ts
218
247
  var matchAction = ({ getContext, push, forward }, values) => {
219
248
  return (action, props, { ctx, data }) => {
@@ -685,7 +714,7 @@ var Novely = (() => {
685
714
  if (isExitImpossible(path)) {
686
715
  const referred = refer(path);
687
716
  if (isAction(referred) && isSkippedDuringRestore(referred[0])) {
688
- onExitImpossible();
717
+ onExitImpossible?.();
689
718
  }
690
719
  wasExitImpossible = true;
691
720
  return {
@@ -857,34 +886,6 @@ var Novely = (() => {
857
886
  }
858
887
  };
859
888
 
860
- // ../../node_modules/.pnpm/klona@2.0.6/node_modules/klona/json/index.mjs
861
- function klona(val) {
862
- var k, out, tmp;
863
- if (Array.isArray(val)) {
864
- out = Array(k = val.length);
865
- while (k--)
866
- out[k] = (tmp = val[k]) && typeof tmp === "object" ? klona(tmp) : tmp;
867
- return out;
868
- }
869
- if (Object.prototype.toString.call(val) === "[object Object]") {
870
- out = {};
871
- for (k in val) {
872
- if (k === "__proto__") {
873
- Object.defineProperty(out, k, {
874
- value: klona(val[k]),
875
- configurable: true,
876
- enumerable: true,
877
- writable: true
878
- });
879
- } else {
880
- out[k] = (tmp = val[k]) && typeof tmp === "object" ? klona(tmp) : tmp;
881
- }
882
- }
883
- return out;
884
- }
885
- return val;
886
- }
887
-
888
889
  // src/translation.ts
889
890
  var RGX = /{{(.*?)}}/g;
890
891
  var split = (input, delimeters) => {
@@ -1406,7 +1407,7 @@ var Novely = (() => {
1406
1407
  const path = stack.value[0];
1407
1408
  nextPath(path);
1408
1409
  };
1409
- const matchActionInit = {
1410
+ const matchActionOptions = {
1410
1411
  getContext: renderer.getContext,
1411
1412
  push(ctx) {
1412
1413
  if (ctx.meta.restoring)
@@ -1417,12 +1418,12 @@ var Novely = (() => {
1417
1418
  forward(ctx) {
1418
1419
  if (!ctx.meta.preview)
1419
1420
  enmemory(ctx);
1420
- matchActionInit.push(ctx);
1421
+ matchActionOptions.push(ctx);
1421
1422
  if (!ctx.meta.preview)
1422
1423
  interactivity(true);
1423
1424
  }
1424
1425
  };
1425
- const match = matchAction(matchActionInit, {
1426
+ const match = matchAction(matchActionOptions, {
1426
1427
  wait({ ctx, push }, [time]) {
1427
1428
  if (ctx.meta.restoring)
1428
1429
  return;
@@ -1504,6 +1505,7 @@ var Novely = (() => {
1504
1505
  }
1505
1506
  return c || "";
1506
1507
  })();
1508
+ ctx.clearAction("dialog");
1507
1509
  ctx.dialog(
1508
1510
  templateReplace(content, data2),
1509
1511
  templateReplace(name, data2),
@@ -1554,6 +1556,7 @@ var Novely = (() => {
1554
1556
  if (DEV && transformedChoices.length === 0) {
1555
1557
  throw new Error(`Running choice without variants to choose from, look at how to use Choice action properly [https://novely.pages.dev/guide/actions/choice#usage]`);
1556
1558
  }
1559
+ ctx.clearAction("choice");
1557
1560
  ctx.choices(templateReplace(question, data2), transformedChoices, (selected) => {
1558
1561
  if (!ctx.meta.preview) {
1559
1562
  enmemory(ctx);
@@ -1617,6 +1620,7 @@ var Novely = (() => {
1617
1620
  exit(true, false);
1618
1621
  },
1619
1622
  input({ ctx, data: data2, forward }, [question, onInput, setup]) {
1623
+ ctx.clearAction("input");
1620
1624
  ctx.input(
1621
1625
  templateReplace(question, data2),
1622
1626
  onInput,
@@ -1660,6 +1664,7 @@ var Novely = (() => {
1660
1664
  if (DEV && string.length === 0) {
1661
1665
  throw new Error(`Action Text was called with empty string or array`);
1662
1666
  }
1667
+ ctx.clearAction("text");
1663
1668
  ctx.text(string, forward);
1664
1669
  },
1665
1670
  exit({ ctx, data: data2 }) {
@@ -1857,6 +1862,15 @@ var Novely = (() => {
1857
1862
  };
1858
1863
  };
1859
1864
 
1865
+ // src/extend-actions.ts
1866
+ var extendAction = (base, extension) => {
1867
+ return new Proxy({}, {
1868
+ get(_, key, receiver) {
1869
+ return Reflect.get(key in extension ? extension : base, key, receiver);
1870
+ }
1871
+ });
1872
+ };
1873
+
1860
1874
  // src/translations.ts
1861
1875
  var RU = {
1862
1876
  NewGame: "\u041D\u043E\u0432\u0430\u044F \u0438\u0433\u0440\u0430",