@novely/core 0.49.0 → 0.50.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
@@ -45,14 +45,6 @@ declare const RU: {
45
45
  };
46
46
  type BaseTranslationStrings = keyof typeof RU;
47
47
  declare const EN: Record<BaseTranslationStrings, string>;
48
- /**
49
- * Translated automatically
50
- */
51
- declare const KK: Record<BaseTranslationStrings, string>;
52
- /**
53
- * Translated automatically
54
- */
55
- declare const JP: Record<BaseTranslationStrings, string>;
56
48
 
57
49
  type CharacterHandle = {
58
50
  emotion: (emotion: string, render: boolean) => void;
@@ -256,7 +248,7 @@ type NovelyAsset = {
256
248
  readonly type: 'audio' | 'image';
257
249
  };
258
250
  type Thenable<T> = T | Promise<T>;
259
- type PathItem = [null, number | string] | ['jump', string] | ['choice', number] | ['choice:exit'] | ['condition', string] | ['condition:exit'] | ['exit'] | ['block', string] | ['block:exit'];
251
+ type PathItem = [null, number] | ['jump', string] | ['choice', number] | ['choice:exit'] | ['condition', string] | ['condition:exit'] | ['exit'] | ['block', string] | ['block:exit'];
260
252
  type Path = PathItem[];
261
253
  type State = Record<string, any>;
262
254
  type Data = Record<string, any>;
@@ -332,7 +324,7 @@ type CharactersData<$Characters extends Record<string, Character<Lang>>> = {
332
324
  emotions: Array<keyof $Characters[Character]['emotions']>;
333
325
  };
334
326
  };
335
- type AssetsPreloading = 'lazy' | 'blocking' | 'automatic';
327
+ type AssetsPreloading = 'lazy' | 'automatic';
336
328
  type CloneFN = <T>(value: T) => T;
337
329
  type StoryOptionsStatic = {
338
330
  /**
@@ -552,7 +544,11 @@ interface NovelyInit<$Language extends Lang, $Characters extends Record<string,
552
544
  */
553
545
  askBeforeExit?: boolean;
554
546
  /**
555
- * @default "lazy"
547
+ * "automatic" will try to preload assets when possible
548
+ *
549
+ * "lazy" will load assets only when they are shown
550
+ *
551
+ * @default "automatic"
556
552
  */
557
553
  preloadAssets?: AssetsPreloading;
558
554
  /**
@@ -602,12 +598,21 @@ type StateFunction<S extends State> = {
602
598
  (value: DeepPartial<S> | ((prev: S) => S)): void;
603
599
  (): S;
604
600
  };
601
+ /**
602
+ * @deprecated `EngineTypes` should be used instead
603
+ */
605
604
  type TypeEssentials<$Lang extends Lang, $State extends State, $Data extends Data, $Characters extends Record<string, Character<$Lang>>> = {
606
605
  readonly l: $Lang | null;
607
606
  readonly s: $State | null;
608
607
  readonly d: $Data | null;
609
608
  readonly c: $Characters | null;
610
609
  };
610
+ type EngineTypes<$Lang extends Lang = Lang, $State extends State = State, $Data extends Data = Data, $Characters extends Record<string, Character<$Lang>> = Record<string, Character<$Lang>>> = {
611
+ readonly l: $Lang;
612
+ readonly s: $State;
613
+ readonly d: $Data;
614
+ readonly c: $Characters;
615
+ };
611
616
  type DialogOverviewEntry = {
612
617
  /**
613
618
  * Link to character voice
@@ -635,7 +640,7 @@ type Character<$Lang extends Lang = string> = {
635
640
  type ValidAction = ['choice', string | undefined, ...[string, unknown[], (() => boolean)?, (() => boolean)?, string?][]] | ['clear', Set<keyof DefaultActionProxy>?, Set<string>?, {
636
641
  music: Set<string>;
637
642
  sounds: Set<string>;
638
- }?] | ['condition', (state: State) => boolean, Record<string, ValidAction[]>] | ['dialog', string | undefined, TextContent<string, State>, string | undefined] | ['end'] | ['showBackground', string | NovelyAsset | BackgroundImage] | ['playMusic', string | NovelyAsset] | ['stopMusic', string | NovelyAsset] | ['pauseMusic', string | NovelyAsset] | ['playSound', audio: string | NovelyAsset, loop?: boolean] | ['pauseSound', string | NovelyAsset] | ['stopSound', string | NovelyAsset] | ['voice', string | NovelyAsset | Record<string, string | NovelyAsset>] | ['stopVoice'] | ['jump', string] | ['showCharacter', string, keyof Character['emotions'], string?, string?] | ['hideCharacter', string, string?, string?, number?] | ['animateCharacter', string, number, ...string[]] | ['wait', number | ((state: State) => number)] | ['function', FunctionAction<string, State>] | ['input', string, (meta: ActionInputOnInputMeta<string, State>) => void, ActionInputSetup?] | ['custom', CustomHandler<string, State>] | ['vibrate', ...number[]] | ['next'] | ['text', ...TextContent<string, State>[]] | ['exit'] | ['preload', string] | ['block', string] | ValidAction[];
643
+ }?] | ['condition', (state: State) => boolean, Record<string, ValidAction[]>] | ['dialog', string | undefined, TextContent<string, State>, string | undefined] | ['end'] | ['showBackground', string | NovelyAsset | BackgroundImage] | ['playMusic', string | NovelyAsset] | ['stopMusic', string | NovelyAsset] | ['pauseMusic', string | NovelyAsset] | ['playSound', audio: string | NovelyAsset, loop?: boolean] | ['pauseSound', string | NovelyAsset] | ['stopSound', string | NovelyAsset] | ['voice', string | NovelyAsset | Record<string, string | NovelyAsset>] | ['stopVoice'] | ['jump', string] | ['showCharacter', string, keyof Character['emotions'], string?, string?] | ['hideCharacter', string, string?, string?, number?] | ['animateCharacter', string, number, ...string[]] | ['wait', number | ((state: State) => number)] | ['function', FunctionAction<string, State>] | ['input', string, (meta: ActionInputOnInputMeta<string, State>) => void, ActionInputSetup?] | ['custom', CustomHandler<string, State>] | ['vibrate', ...number[]] | ['next'] | ['text', ...TextContent<string, State>[]] | ['exit'] | ['preload', string | NovelyAsset] | ['block', string] | ValidAction[];
639
644
  type Story = Record<string, ValidAction[]>;
640
645
  type TextContent<L extends string, S extends State> = string | ((state: S) => string) | Record<L, string | ((state: S) => string)>;
641
646
  type FunctionableValue<T> = T | (() => T);
@@ -892,7 +897,7 @@ type ActionProxy<Characters extends Record<string, Character>, Languages extends
892
897
  vibrate: (...pattern: number[]) => ValidAction;
893
898
  next: () => ValidAction;
894
899
  text: (...text: TextContent<Languages, S>[]) => ValidAction;
895
- preload: (source: string) => ValidAction;
900
+ preload: (source: string | NovelyAsset) => ValidAction;
896
901
  block: (scene: string) => ValidAction;
897
902
  };
898
903
  type DefaultActionProxy = ActionProxy<Record<string, Character>, Lang, State>;
@@ -902,10 +907,19 @@ type VirtualActions<$Characters extends Record<string, Character>, $Lang extends
902
907
  say: (character: keyof $Characters, content: TextContent<$Lang, $State>) => ValidAction;
903
908
  };
904
909
 
905
- type ConditionParams<T> = T extends TypeEssentials<any, infer $State, any, any> ? $State : never;
906
- type ChoiceParams<T> = T extends TypeEssentials<infer $Lang, infer $State, any, any> ? ChoiceCheckFunctionProps<$Lang, $State> : never;
907
- type FunctionParams<T> = T extends TypeEssentials<infer $Lang, infer $State, any, any> ? FunctionActionProps<$Lang, $State> : never;
908
- type InputHandler<T> = T extends TypeEssentials<infer $Lang, infer $State, any, any> ? ActionInputOnInputMeta<$Lang, $State> : never;
910
+ type ConditionParams<T> = T extends EngineTypes<any, infer $State, any, any> ? $State : never;
911
+ type ChoiceParams<T> = T extends EngineTypes<infer $Lang, infer $State, any, any> ? ChoiceCheckFunctionProps<$Lang, $State> : never;
912
+ type FunctionParams<T> = T extends EngineTypes<infer $Lang, infer $State, any, any> ? FunctionActionProps<$Lang, $State> : never;
913
+ type InputHandler<T> = T extends EngineTypes<infer $Lang, infer $State, any, any> ? ActionInputOnInputMeta<$Lang, $State> : never;
914
+ /**
915
+ * @example
916
+ * ```ts
917
+ * type Types = TypesFromEngine<typeof engine>;
918
+ * ```
919
+ */
920
+ type TypesFromEngine<T> = T extends {
921
+ types: EngineTypes<infer $Lang, infer $State, infer $Data, infer $Characters> | null;
922
+ } ? EngineTypes<$Lang, $State, $Data, $Characters> : never;
909
923
 
910
924
  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, defaultTypewriterSpeed, storyOptions, }: NovelyInit<$Language, $Characters, $State, $Data, $Actions>) => {
911
925
  /**
@@ -958,7 +972,7 @@ declare const novely: <$Language extends string, $Characters extends Record<stri
958
972
  data: StateFunction<$Data>;
959
973
  /**
960
974
  * Used in combination with type utilities
961
- *
975
+ * @deprecated Use `engine.types` instead
962
976
  * @example
963
977
  * ```ts
964
978
  * import type { ConditionParams, StateFunction } from '@novely/core';
@@ -969,6 +983,20 @@ declare const novely: <$Language extends string, $Characters extends Record<stri
969
983
  * ```
970
984
  */
971
985
  typeEssentials: TypeEssentials<$Language, $State, $Data, $Characters>;
986
+ /**
987
+ * Used in combination with type utilities
988
+ * @example
989
+ * ```ts
990
+ * import type { TypesFromEngine, ConditionParams, StateFunction } from '@novely/core';
991
+ *
992
+ * type Types = TypesFromEngine<typeof engine>;
993
+ *
994
+ * const conditionCheck = (state: StateFunction<ConditionParams<Types>>) => {
995
+ * return state.age >= 18;
996
+ * }
997
+ * ```
998
+ */
999
+ types: EngineTypes<$Language, $State, $Data, $Characters> | null;
972
1000
  /**
973
1001
  * Replaces content inside {{braces}} using global data
974
1002
  * @example
@@ -1065,4 +1093,4 @@ declare const asset: {
1065
1093
  audio(source: string): NovelyAsset;
1066
1094
  };
1067
1095
 
1068
- export { type ActionChoiceChoice, type ActionChoiceChoiceObject, 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 ChoiceCheckFunction, type ChoiceCheckFunctionProps, type ChoiceOnSelectFunction, type ChoiceOnSelectFunctionProps, type ChoiceParams, type ConditionCheckFunction, type ConditionParams, type Context, type CoreData, type CustomActionHandle, type CustomHandler, type CustomHandlerFunction, type CustomHandlerFunctionGetFn, type CustomHandlerFunctionParameters, type CustomHandlerGetResult, type CustomHandlerGetResultDataFunction, type CustomHandlerInfo, type Data, type DeepPartial, type DefaultActionProxy, EN, type Emotions, type FunctionParams, type FunctionableValue, type GetActionParameters, type InputHandler, JP, KK, type Lang, type NovelyAsset, 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 };
1096
+ export { type ActionChoiceChoice, type ActionChoiceChoiceObject, 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 ChoiceCheckFunction, type ChoiceCheckFunctionProps, type ChoiceOnSelectFunction, type ChoiceOnSelectFunctionProps, type ChoiceParams, type ConditionCheckFunction, type ConditionParams, type Context, type CoreData, type CustomActionHandle, type CustomHandler, type CustomHandlerFunction, type CustomHandlerFunctionGetFn, type CustomHandlerFunctionParameters, type CustomHandlerGetResult, type CustomHandlerGetResultDataFunction, type CustomHandlerInfo, type Data, type DeepPartial, type DefaultActionProxy, EN, type Emotions, type EngineTypes, type FunctionParams, type FunctionableValue, type GetActionParameters, type InputHandler, type Lang, type NovelyAsset, type NovelyInit, type NovelyScreen, type NovelyStorage, type Path, type PathItem, 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 TypesFromEngine, type TypewriterSpeed, type ValidAction, asset, extendAction, localStorageStorage, novely };