@novely/core 0.45.0 → 0.45.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
@@ -1,16 +1,9 @@
1
- type LocalStorageStorageSettings = {
2
- key: string;
3
- };
4
- type NovelyStorage = {
5
- get: () => Promise<StorageData>;
6
- set: (data: StorageData) => Promise<void>;
1
+ type Stored<T> = {
2
+ subscribe: (cb: (value: T) => void) => () => void;
3
+ update: (fn: (prev: T) => T) => void;
4
+ set: (val: T) => void;
5
+ get: () => T;
7
6
  };
8
- declare const localStorageStorage: (options: LocalStorageStorageSettings) => NovelyStorage;
9
-
10
- type PluralType = Intl.LDMLPluralRule;
11
- type Pluralization = Partial<Record<PluralType, string>>;
12
- type AllowedContent = string | ((state: State | Data) => string | string[]) | string[] | (string | ((state: State | Data) => string | string[]))[];
13
- type TranslationActions = Partial<Record<string, (str: string) => string>>;
14
7
 
15
8
  declare const RU: {
16
9
  NewGame: string;
@@ -59,13 +52,6 @@ declare const KK: Record<BaseTranslationStrings, string>;
59
52
  */
60
53
  declare const JP: Record<BaseTranslationStrings, string>;
61
54
 
62
- type Stored<T> = {
63
- subscribe: (cb: (value: T) => void) => () => void;
64
- update: (fn: (prev: T) => T) => void;
65
- set: (val: T) => void;
66
- get: () => T;
67
- };
68
-
69
55
  interface CharacterHandle {
70
56
  canvas: HTMLCanvasElement;
71
57
  ctx: CanvasRenderingContext2D;
@@ -101,7 +87,13 @@ type Context = {
101
87
  character: (character: string) => CharacterHandle;
102
88
  background: (background: Record<string, string>) => void;
103
89
  dialog: (content: string, name: string, character: string | undefined, emotion: string | undefined, resolve: () => void) => void;
104
- choices: (question: string, choices: [name: string, active: Stored<boolean>, visible: Stored<boolean>, onselect: ChoiceOnSelectFunction, image: string][], resolve: (selected: number) => void) => void;
90
+ choices: (question: string, choices: [
91
+ name: string,
92
+ active: Stored<boolean>,
93
+ visible: Stored<boolean>,
94
+ onselect: () => void,
95
+ image: string
96
+ ][], resolve: (selected: number) => void) => void;
105
97
  input: (question: string, onInput: (meta: ActionInputOnInputMeta<Lang, State>) => void, setup: ActionInputSetup, resolve: () => void) => void;
106
98
  clear: (keep: Set<keyof DefaultActionProxy>, keepCharacters: Set<string>, keepAudio: {
107
99
  music: Set<string>;
@@ -237,14 +229,28 @@ type RendererInit<$Language extends Lang, $Characters extends Record<string, Cha
237
229
  getLanguageDisplayName: (lang: Lang) => string;
238
230
  getCharacterColor: (character: string) => string;
239
231
  getCharacterAssets: (character: string, emotion: string) => string[];
240
- getResourseType: (url: string) => Promise<"image" | "audio" | "other">;
232
+ getResourseType: (url: string) => Promise<'image' | 'audio' | 'other'>;
233
+ };
234
+
235
+ type LocalStorageStorageSettings = {
236
+ key: string;
241
237
  };
238
+ type NovelyStorage = {
239
+ get: () => Promise<StorageData>;
240
+ set: (data: StorageData) => Promise<void>;
241
+ };
242
+ declare const localStorageStorage: (options: LocalStorageStorageSettings) => NovelyStorage;
243
+
244
+ type PluralType = Intl.LDMLPluralRule;
245
+ type Pluralization = Partial<Record<PluralType, string>>;
246
+ type AllowedContent = string | ((state: State | Data) => string | string[]) | string[] | (string | ((state: State | Data) => string | string[]))[];
247
+ type TranslationActions = Partial<Record<string, (str: string) => string>>;
242
248
 
243
249
  declare const getLanguage: (languages: string[]) => string;
244
250
 
245
251
  type NovelyAsset = {
246
252
  readonly source: string;
247
- readonly type: "audio" | "image";
253
+ readonly type: 'audio' | 'image';
248
254
  };
249
255
  type Thenable<T> = T | Promise<T>;
250
256
  type PathItem = [null, number | string] | ['jump', string] | ['choice', number] | ['choice:exit'] | ['condition', string] | ['condition:exit'] | ['exit'] | ['block', string] | ['block:exit'];
@@ -254,11 +260,7 @@ type Data = Record<string, any>;
254
260
  type SaveDate = number;
255
261
  type SaveType = 'manual' | 'auto';
256
262
  type SaveMeta = [date: SaveDate, type: SaveType];
257
- type Save<S extends State = State> = [
258
- path: Path,
259
- state: S,
260
- meta: SaveMeta
261
- ];
263
+ type Save<S extends State = State> = [path: Path, state: S, meta: SaveMeta];
262
264
  type Lang = string;
263
265
  type TypewriterSpeed = 'Slow' | 'Medium' | 'Fast' | 'Auto';
264
266
  type SoundVolume = number;
@@ -313,7 +315,7 @@ type TranslationDescription = {
313
315
  actions?: TranslationActions;
314
316
  };
315
317
  type DefaultEmotions<$Characters extends Record<string, Character<Lang>>> = {
316
- [Character in keyof $Characters]?: (keyof $Characters[Character]['emotions'] & string);
318
+ [Character in keyof $Characters]?: keyof $Characters[Character]['emotions'] & string;
317
319
  };
318
320
  type CharacterAssetSizes<$Characters extends Record<string, Character<Lang>>> = {
319
321
  [Character in keyof $Characters]?: {
@@ -563,7 +565,7 @@ type Character<$Lang extends Lang = string> = {
563
565
  type ValidAction = ['choice', string | undefined, ...[string, unknown[], (() => boolean)?, (() => boolean)?, string?][]] | ['clear', Set<keyof DefaultActionProxy>?, Set<string>?, {
564
566
  music: Set<string>;
565
567
  sounds: Set<string>;
566
- }?] | ['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[];
568
+ }?] | ['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[];
567
569
  type Story = Record<string, ValidAction[]>;
568
570
  type TextContent<L extends string, S extends State> = string | ((state: S) => string) | Record<L, string | ((state: S) => string)>;
569
571
  type FunctionableValue<T> = T | (() => T);
@@ -657,7 +659,7 @@ type CustomHandlerInfo = CustomHandlerCalling & {
657
659
  /**
658
660
  * Assets (pictures, audio files) used by action
659
661
  */
660
- assets?: string[];
662
+ assets?: (NovelyAsset | string)[];
661
663
  /**
662
664
  * When true interacting with it will be saved in history
663
665
  */
@@ -730,8 +732,14 @@ type ChoiceCheckFunctionProps<L extends Lang, S extends State> = {
730
732
  */
731
733
  state: S;
732
734
  };
735
+ type ChoiceOnSelectFunctionProps = {
736
+ /**
737
+ * Triggers `active` and `visible` properties computation
738
+ */
739
+ recompute: () => void;
740
+ };
733
741
  type ChoiceCheckFunction<L extends Lang, S extends State> = (props: ChoiceCheckFunctionProps<L, S>) => boolean;
734
- type ChoiceOnSelectFunction = () => Thenable<void>;
742
+ type ChoiceOnSelectFunction = (props: ChoiceOnSelectFunctionProps) => void;
735
743
  type ConditionCheckFunction<S extends State, R extends string | true | false> = (state: S) => R;
736
744
  type FunctionAction<L extends string, S extends State> = (props: FunctionActionProps<L, S>) => Thenable<void>;
737
745
  type ActionInputSetupCleanup = () => void;
@@ -879,7 +887,7 @@ declare const novely: <$Language extends string, $Characters extends Record<stri
879
887
  * @example
880
888
  * ```ts
881
889
  * import type { ConditionParams, StateFunction } from '@novely/core';
882
- *
890
+ *
883
891
  * const conditionCheck = (state: StateFunction<ConditionParams<typeof engine.typeEssintials>>) => {
884
892
  * return state.age >= 18;
885
893
  * }
@@ -977,4 +985,4 @@ declare const extendAction: <Part0 extends Record<string, (...args: any[]) => Va
977
985
  */
978
986
  declare const asset: (...variants: string[]) => NovelyAsset;
979
987
 
980
- 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 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 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 };
988
+ 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 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 };