@drincs/pixi-vn-json 1.13.8 → 1.13.10

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.cts CHANGED
@@ -1,13 +1,14 @@
1
- import { r as PixiVNJsonComparationOperatorsType } from './PixiVNJsonLabelStep-DJgORyFd.cjs';
2
- export { P as PixiVNJsonAnimateBase, a as PixiVNJsonAnimateSequence, b as PixiVNJsonArithmeticOperations, c as PixiVNJsonArithmeticOperationsArithmetic, d as PixiVNJsonArithmeticOperationsArithmeticSingle, e as PixiVNJsonCanvas, f as PixiVNJsonCanvasAnimate, g as PixiVNJsonCanvasEdit, h as PixiVNJsonCanvasEffect, i as PixiVNJsonCanvasImageContainerShow, j as PixiVNJsonCanvasImageVideoShow, k as PixiVNJsonCanvasRemove, l as PixiVNJsonCanvasShow, m as PixiVNJsonCanvasTextShow, n as PixiVNJsonChoice, o as PixiVNJsonChoiceGet, p as PixiVNJsonChoices, q as PixiVNJsonComparation, s as PixiVNJsonConditionalOperation, t as PixiVNJsonConditionalResultToCombine, u as PixiVNJsonConditionalStatements, v as PixiVNJsonConditions, w as PixiVNJsonDialog, x as PixiVNJsonDialogText, y as PixiVNJsonDialogue, z as PixiVNJsonFunction, A as PixiVNJsonIfElse, B as PixiVNJsonImageContainerEdit, C as PixiVNJsonImageEdit, D as PixiVNJsonInputRequest, E as PixiVNJsonLabelGet, F as PixiVNJsonLabelStep, G as PixiVNJsonLabelToOpen, H as PixiVNJsonLogicGet, I as PixiVNJsonMediaTransiotions, J as PixiVNJsonNarration, K as PixiVNJsonOnlyStorageSet, L as PixiVNJsonOperation, M as PixiVNJsonOperationString, N as PixiVNJsonParamGet, O as PixiVNJsonSound, Q as PixiVNJsonSoundEdit, R as PixiVNJsonSoundPauseResume, S as PixiVNJsonSoundPlay, T as PixiVNJsonSoundRemove, U as PixiVNJsonStepSwitch, V as PixiVNJsonStepSwitchElementType, W as PixiVNJsonStepSwitchElementsType, X as PixiVNJsonStorageGet, Y as PixiVNJsonTextEdit, Z as PixiVNJsonUnionCondition, _ as PixiVNJsonUnknownEdit, $ as PixiVNJsonValueGet, a0 as PixiVNJsonValueSet, a1 as PixiVNJsonVideoEdit, a2 as PixiVNJsonVideoPauseResume } from './PixiVNJsonLabelStep-DJgORyFd.cjs';
3
- import { ZodType } from 'zod';
4
- import { StorageElementType, StepLabelPropsType } from '@drincs/pixi-vn';
5
- export { LabelJson, importPixiVNJson } from './interpreter.cjs';
1
+ import { x as PixiVNJsonComparationOperatorsType } from './PixiVNJsonLabelStep-BsGHNfkq.cjs';
2
+ export { y as PixiVNJsonAnimateBase, z as PixiVNJsonAnimateSequence, t as PixiVNJsonArithmeticOperations, A as PixiVNJsonArithmeticOperationsArithmetic, B as PixiVNJsonArithmeticOperationsArithmeticSingle, C as PixiVNJsonCanvas, r as PixiVNJsonCanvasAnimate, D as PixiVNJsonCanvasEdit, q as PixiVNJsonCanvasEffect, i as PixiVNJsonCanvasImageContainerShow, d as PixiVNJsonCanvasImageVideoShow, f as PixiVNJsonCanvasRemove, E as PixiVNJsonCanvasShow, k as PixiVNJsonCanvasTextShow, F as PixiVNJsonChoice, G as PixiVNJsonChoiceGet, H as PixiVNJsonChoices, I as PixiVNJsonComparation, J as PixiVNJsonConditionalOperation, K as PixiVNJsonConditionalResultToCombine, v as PixiVNJsonConditionalStatements, u as PixiVNJsonConditions, L as PixiVNJsonDialog, M as PixiVNJsonDialogText, N as PixiVNJsonDialogue, O as PixiVNJsonFunction, a as PixiVNJsonIfElse, j as PixiVNJsonImageContainerEdit, e as PixiVNJsonImageEdit, Q as PixiVNJsonInputRequest, R as PixiVNJsonLabelGet, w as PixiVNJsonLabelStep, S as PixiVNJsonLabelToOpen, T as PixiVNJsonLogicGet, U as PixiVNJsonMediaTransiotions, p as PixiVNJsonNarration, o as PixiVNJsonOnlyStorageSet, P as PixiVNJsonOperation, b as PixiVNJsonOperationString, V as PixiVNJsonParamGet, c as PixiVNJsonSound, W as PixiVNJsonSoundEdit, X as PixiVNJsonSoundPauseResume, Y as PixiVNJsonSoundPlay, Z as PixiVNJsonSoundRemove, _ as PixiVNJsonStepSwitch, $ as PixiVNJsonStepSwitchElementType, a0 as PixiVNJsonStepSwitchElementsType, a1 as PixiVNJsonStorageGet, l as PixiVNJsonTextEdit, a2 as PixiVNJsonUnionCondition, m as PixiVNJsonUnknownEdit, s as PixiVNJsonValueGet, n as PixiVNJsonValueSet, g as PixiVNJsonVideoEdit, h as PixiVNJsonVideoPauseResume } from './PixiVNJsonLabelStep-BsGHNfkq.cjs';
6
3
  export { PixiVNJson, PixiVNJsonLabels } from './schema.cjs';
7
- export { translator } from './translator.cjs';
4
+ export { V as VariableGetter, a as VariableGetterHandler } from './VariableGetter-ZDA6kdah.cjs';
5
+ export { LabelJson, importPixiVNJson } from './interpreter.cjs';
6
+ export { ReplaceHandler, ReplaceHandlerOptions, TextReplaces, translator } from './translator.cjs';
7
+ import '@drincs/pixi-vn';
8
8
  import '@drincs/pixi-vn/motion';
9
9
  import 'pixi.js';
10
10
  import '@drincs/pixi-vn/narration';
11
+ import 'zod';
11
12
 
12
13
  /**
13
14
  * Internal storage key prefix used to pass positional parameters to a called label.
@@ -35,244 +36,6 @@ declare const PIXIVNJSON_SCHEMA_URL: string;
35
36
  */
36
37
  declare const PixiVNJsonComparationOperators: PixiVNJsonComparationOperatorsType[];
37
38
 
38
- /**
39
- * A handler function invoked for each `[key]` token found in the text that passes the
40
- * {@link ReplaceHandlerOptions.validation} check.
41
- *
42
- * @param key The content found inside the square brackets (without the brackets themselves).
43
- * For example, for the token `[john]` the key is `"john"`.
44
- * @returns The string to substitute in place of `[key]`, or `undefined` to leave the token unchanged.
45
- */
46
- type ReplaceHandler = (
47
- /**
48
- * The key to be replaced
49
- */
50
- key: string) => string | undefined;
51
- /**
52
- * Configuration options for a text-replacement handler registered via {@link TextReplaces.add}.
53
- */
54
- type ReplaceHandlerOptions = {
55
- /**
56
- * A unique name that identifies this handler.
57
- * Used for documentation and debugging purposes.
58
- */
59
- name: string;
60
- /**
61
- * An optional human-readable description of what this handler does.
62
- * Used for documentation purposes.
63
- */
64
- description?: string;
65
- /**
66
- * Determines whether this handler should be invoked for a given `[key]` token.
67
- *
68
- * - `"all"` – the handler is always invoked for every token found.
69
- * - `"characterId"` – the handler is invoked only when the key matches a registered character ID
70
- * (i.e. the character is present in `RegisteredCharacters`).
71
- * - `RegExp` – the key string is tested against the regular expression. The handler is invoked
72
- * only if the regex matches.
73
- * - `ZodType<string>` – the key string is validated with `schema.safeParse(key)`. The handler
74
- * is invoked only if validation succeeds.
75
- *
76
- * @example
77
- * ```ts
78
- * // RegExp: only replace keys that look like lowercase identifiers
79
- * validation: /^[a-z_]+$/
80
- *
81
- * // Zod: only replace keys that are one of a fixed set of values
82
- * import { z } from "zod"
83
- * validation: z.enum(["player", "npc", "enemy"])
84
- * ```
85
- */
86
- validation: RegExp | "characterId" | "all" | ZodType<string>;
87
- /**
88
- * When this handler should be invoked relative to the translation step.
89
- *
90
- * - `"before-translation"` – the handler runs **before** {@link onInkTranslate} is called.
91
- * Useful for pre-processing tokens, e.g. converting `[key]` into `{{key}}` for i18next.
92
- * - `"after-translation"` – the handler runs **after** {@link onInkTranslate} is called.
93
- * Useful for substituting values that depend on the translated text.
94
- *
95
- * @default "before-translation"
96
- */
97
- type?: "after-translation" | "before-translation";
98
- /**
99
- * When `true`, the **first** occurrence of a matched `[key]` token is converted to the i18n
100
- * double-brace format `{{[key]}}` (exactly once). Any subsequent occurrences of `[key]` in
101
- * the same text are then replaced with the handler's return value as usual.
102
- *
103
- * The transformation sequence for a matched key is:
104
- * - first occurrence: `[key]` → `{{[key]}}`
105
- * - remaining occurrences: `[key]` → handler return value
106
- *
107
- * When `false` or omitted, the handler's return value directly replaces all occurrences of `[key]`.
108
- *
109
- * **Recommended i18n configuration:** when this option is enabled, configure
110
- * `missingInterpolationHandler` in your i18n instance so that keys with no matching
111
- * translation are left intact rather than replaced with an empty string:
112
- *
113
- * ```ts title="lib/i18n.ts"
114
- * i18n.init({
115
- * // ...
116
- * missingInterpolationHandler(_text, value, _options) {
117
- * return value[1];
118
- * },
119
- * });
120
- * ```
121
- *
122
- * @default false
123
- */
124
- i18nInterpolation?: boolean;
125
- };
126
-
127
- /**
128
- * A middleware handler that can intercept and transform a logic value before it is
129
- * returned by {@link VariableGetter.getLogichValue}.
130
- *
131
- * Handlers are called in registration order, each receiving the current value and a
132
- * `next` function to invoke the rest of the chain (including the built-in resolver).
133
- * Return `undefined` to fall through to `next`.
134
- */
135
- type VariableGetterHandler = <T = StorageElementType>(value: T, next: (value: T) => T | undefined) => T | undefined;
136
-
137
- /**
138
- * Manages text replacement handlers that process content enclosed in square brackets (`[key]`).
139
- *
140
- * Handlers are called in the order they were added. For each handler, the current text is scanned
141
- * for all `[key]` patterns. If the handler's `validation` matches a key, the handler is
142
- * invoked with that key. If the handler returns a string, all occurrences of `[key]` are replaced
143
- * with the returned value. After a handler finishes processing the text, the next handler starts
144
- * on the updated text.
145
- *
146
- * Each handler specifies whether it runs before or after translation via the `type` field in its
147
- * options (defaults to `"before-translation"`).
148
- *
149
- * @example
150
- * ```ts title="content/text-replaces.ts"
151
- * import { TextReplaces } from 'pixi-vn-ink'
152
- * import { getCharacterById } from "@drincs/pixi-vn";
153
- *
154
- * // Replace [characterId] with the character's display name
155
- * TextReplaces.add(
156
- * (key) => {
157
- * const character = getCharacterById(key)
158
- * return character?.name
159
- * },
160
- * {
161
- * name: "character-name",
162
- * description: "Replaces character IDs with their display names",
163
- * validation: /^[a-z_]+$/,
164
- * type: "after-translation",
165
- * }
166
- * )
167
- * // "Hello [john], meet [jane]!" -> "Hello John, meet Jane!"
168
- * ```
169
- */
170
- declare namespace TextReplaces {
171
- /**
172
- * Configuration options for the `TextReplaces` system.
173
- */
174
- const options: {
175
- /**
176
- * The regex used to find replacement tokens in the text (e.g. `[key]`).
177
- * @default /\[([^\]]+)\]/
178
- */
179
- replaceRegex: RegExp;
180
- };
181
- /**
182
- * Registers a new replacement handler.
183
- *
184
- * Handlers are executed in the order they are added. The first handler added runs first.
185
- *
186
- * When the first handler of a given type (`"before-translation"` or `"after-translation"`)
187
- * is registered, the corresponding translator hook (`translator.beforeToTranslate` or
188
- * `translator.afterToTranslate`) is automatically set so that `TextReplaces` takes exclusive
189
- * ownership of that hook. Do **not** mix `TextReplaces` with the deprecated
190
- * {@link onReplaceTextBeforeTranslation} / {@link onReplaceTextAfterTranslation} functions
191
- * for the same phase, as they will overwrite each other's hook.
192
- *
193
- * @param fn The handler function. Receives the key found inside `[...]` and should return
194
- * the replacement string, or `undefined` to leave that token unchanged.
195
- * @param handlerOptions Configuration for this handler, including its name, optional
196
- * description, validation regex, and execution phase.
197
- * @example
198
- * ```ts title="content/text-replaces.ts"
199
- * import { TextReplaces } from 'pixi-vn-ink'
200
- *
201
- * TextReplaces.add(
202
- * (key) => key === "player" ? "Mario" : undefined,
203
- * {
204
- * name: "player-name",
205
- * validation: /^player$/,
206
- * }
207
- * )
208
- * ```
209
- */
210
- function add(fn: ReplaceHandler, handlerOptions: ReplaceHandlerOptions): void;
211
- /**
212
- * Removes a previously registered handler function.
213
- *
214
- * Only the first registration matching `fn` is removed. If the same function was added
215
- * multiple times, subsequent registrations remain.
216
- *
217
- * @param fn The handler function to remove.
218
- */
219
- function remove(fn: ReplaceHandler): void;
220
- /**
221
- * Returns metadata for all registered handlers, in registration order.
222
- *
223
- * @returns An array of {@link ReplaceHandlerOptions} for each registered handler.
224
- */
225
- function info(): ReplaceHandlerOptions[];
226
- /**
227
- * Applies all registered handlers of the specified type to the given text in order.
228
- *
229
- * For each handler:
230
- * 1. All `[key]` tokens currently present in the text are collected.
231
- * 2. For each unique key, the handler's `validation` is tested against the key.
232
- * 3. If validation passes, the handler is called with the key.
233
- * 4. If the handler returns a string, **all** occurrences of `[key]` in the text are
234
- * replaced with that string.
235
- * 5. After the handler has processed all tokens, the next handler starts on the updated text.
236
- *
237
- * @param text The source text to process.
238
- * @param replaceOptions Specifies which phase of handlers to run.
239
- * @returns The text after all matching handlers have been applied.
240
- * @example
241
- * ```ts title="content/text-replaces.ts"
242
- * // Given handlers that replace [name] -> "Mario" and [surname] -> "Rossi":
243
- * TextReplaces.replace("Ciao [name] [surname]. [name] vai pure", { type: "before-translation" })
244
- * // => "Ciao Mario Rossi. Mario vai pure"
245
- * ```
246
- */
247
- function replace(text: string, replaceOptions: {
248
- /** Which phase of handlers to execute. */
249
- type: "after-translation" | "before-translation";
250
- }): string;
251
- }
252
-
253
- declare namespace VariableGetter {
254
- /**
255
- * Registers a new middleware handler into the resolution chain.
256
- * Handlers are invoked in the order they were added.
257
- *
258
- * @param handler - The middleware handler to register.
259
- */
260
- function add(handler: VariableGetterHandler): void;
261
- /**
262
- * Removes all registered middleware handlers, restoring the default resolution behaviour.
263
- */
264
- function clear(): void;
265
- /**
266
- * Resolves a JSON logic value, running it through all registered middleware handlers
267
- * before falling back to the built-in storage/arithmetic/condition evaluator.
268
- *
269
- * @param value - The value or logic expression to resolve.
270
- * @param props - The current step label props passed to each handler.
271
- * @returns The resolved value, or `undefined`.
272
- */
273
- function getLogichValue<T = StorageElementType>(value: any, props?: StepLabelPropsType): T | undefined;
274
- }
275
-
276
39
  /**
277
40
  * Initialises the pixi-vn-json system by registering all default operation handlers
278
41
  * (canvas, sound, assets, storage, narration, etc.) into the {@link JsonUnifier}.
@@ -281,4 +44,4 @@ declare namespace VariableGetter {
281
44
  */
282
45
  declare function init(): void;
283
46
 
284
- export { PIXIVNJSON_PARAM_ID, PIXIVNJSON_SCHEMA_URL, PixiVNJsonComparationOperators, PixiVNJsonComparationOperatorsType, type ReplaceHandler, type ReplaceHandlerOptions, TextReplaces, VariableGetter, type VariableGetterHandler, init };
47
+ export { PIXIVNJSON_PARAM_ID, PIXIVNJSON_SCHEMA_URL, PixiVNJsonComparationOperators, PixiVNJsonComparationOperatorsType, init };
package/dist/index.d.ts CHANGED
@@ -1,13 +1,14 @@
1
- import { r as PixiVNJsonComparationOperatorsType } from './PixiVNJsonLabelStep-DJgORyFd.js';
2
- export { P as PixiVNJsonAnimateBase, a as PixiVNJsonAnimateSequence, b as PixiVNJsonArithmeticOperations, c as PixiVNJsonArithmeticOperationsArithmetic, d as PixiVNJsonArithmeticOperationsArithmeticSingle, e as PixiVNJsonCanvas, f as PixiVNJsonCanvasAnimate, g as PixiVNJsonCanvasEdit, h as PixiVNJsonCanvasEffect, i as PixiVNJsonCanvasImageContainerShow, j as PixiVNJsonCanvasImageVideoShow, k as PixiVNJsonCanvasRemove, l as PixiVNJsonCanvasShow, m as PixiVNJsonCanvasTextShow, n as PixiVNJsonChoice, o as PixiVNJsonChoiceGet, p as PixiVNJsonChoices, q as PixiVNJsonComparation, s as PixiVNJsonConditionalOperation, t as PixiVNJsonConditionalResultToCombine, u as PixiVNJsonConditionalStatements, v as PixiVNJsonConditions, w as PixiVNJsonDialog, x as PixiVNJsonDialogText, y as PixiVNJsonDialogue, z as PixiVNJsonFunction, A as PixiVNJsonIfElse, B as PixiVNJsonImageContainerEdit, C as PixiVNJsonImageEdit, D as PixiVNJsonInputRequest, E as PixiVNJsonLabelGet, F as PixiVNJsonLabelStep, G as PixiVNJsonLabelToOpen, H as PixiVNJsonLogicGet, I as PixiVNJsonMediaTransiotions, J as PixiVNJsonNarration, K as PixiVNJsonOnlyStorageSet, L as PixiVNJsonOperation, M as PixiVNJsonOperationString, N as PixiVNJsonParamGet, O as PixiVNJsonSound, Q as PixiVNJsonSoundEdit, R as PixiVNJsonSoundPauseResume, S as PixiVNJsonSoundPlay, T as PixiVNJsonSoundRemove, U as PixiVNJsonStepSwitch, V as PixiVNJsonStepSwitchElementType, W as PixiVNJsonStepSwitchElementsType, X as PixiVNJsonStorageGet, Y as PixiVNJsonTextEdit, Z as PixiVNJsonUnionCondition, _ as PixiVNJsonUnknownEdit, $ as PixiVNJsonValueGet, a0 as PixiVNJsonValueSet, a1 as PixiVNJsonVideoEdit, a2 as PixiVNJsonVideoPauseResume } from './PixiVNJsonLabelStep-DJgORyFd.js';
3
- import { ZodType } from 'zod';
4
- import { StorageElementType, StepLabelPropsType } from '@drincs/pixi-vn';
5
- export { LabelJson, importPixiVNJson } from './interpreter.js';
1
+ import { x as PixiVNJsonComparationOperatorsType } from './PixiVNJsonLabelStep-BsGHNfkq.js';
2
+ export { y as PixiVNJsonAnimateBase, z as PixiVNJsonAnimateSequence, t as PixiVNJsonArithmeticOperations, A as PixiVNJsonArithmeticOperationsArithmetic, B as PixiVNJsonArithmeticOperationsArithmeticSingle, C as PixiVNJsonCanvas, r as PixiVNJsonCanvasAnimate, D as PixiVNJsonCanvasEdit, q as PixiVNJsonCanvasEffect, i as PixiVNJsonCanvasImageContainerShow, d as PixiVNJsonCanvasImageVideoShow, f as PixiVNJsonCanvasRemove, E as PixiVNJsonCanvasShow, k as PixiVNJsonCanvasTextShow, F as PixiVNJsonChoice, G as PixiVNJsonChoiceGet, H as PixiVNJsonChoices, I as PixiVNJsonComparation, J as PixiVNJsonConditionalOperation, K as PixiVNJsonConditionalResultToCombine, v as PixiVNJsonConditionalStatements, u as PixiVNJsonConditions, L as PixiVNJsonDialog, M as PixiVNJsonDialogText, N as PixiVNJsonDialogue, O as PixiVNJsonFunction, a as PixiVNJsonIfElse, j as PixiVNJsonImageContainerEdit, e as PixiVNJsonImageEdit, Q as PixiVNJsonInputRequest, R as PixiVNJsonLabelGet, w as PixiVNJsonLabelStep, S as PixiVNJsonLabelToOpen, T as PixiVNJsonLogicGet, U as PixiVNJsonMediaTransiotions, p as PixiVNJsonNarration, o as PixiVNJsonOnlyStorageSet, P as PixiVNJsonOperation, b as PixiVNJsonOperationString, V as PixiVNJsonParamGet, c as PixiVNJsonSound, W as PixiVNJsonSoundEdit, X as PixiVNJsonSoundPauseResume, Y as PixiVNJsonSoundPlay, Z as PixiVNJsonSoundRemove, _ as PixiVNJsonStepSwitch, $ as PixiVNJsonStepSwitchElementType, a0 as PixiVNJsonStepSwitchElementsType, a1 as PixiVNJsonStorageGet, l as PixiVNJsonTextEdit, a2 as PixiVNJsonUnionCondition, m as PixiVNJsonUnknownEdit, s as PixiVNJsonValueGet, n as PixiVNJsonValueSet, g as PixiVNJsonVideoEdit, h as PixiVNJsonVideoPauseResume } from './PixiVNJsonLabelStep-BsGHNfkq.js';
6
3
  export { PixiVNJson, PixiVNJsonLabels } from './schema.js';
7
- export { translator } from './translator.js';
4
+ export { V as VariableGetter, a as VariableGetterHandler } from './VariableGetter-ZDA6kdah.js';
5
+ export { LabelJson, importPixiVNJson } from './interpreter.js';
6
+ export { ReplaceHandler, ReplaceHandlerOptions, TextReplaces, translator } from './translator.js';
7
+ import '@drincs/pixi-vn';
8
8
  import '@drincs/pixi-vn/motion';
9
9
  import 'pixi.js';
10
10
  import '@drincs/pixi-vn/narration';
11
+ import 'zod';
11
12
 
12
13
  /**
13
14
  * Internal storage key prefix used to pass positional parameters to a called label.
@@ -35,244 +36,6 @@ declare const PIXIVNJSON_SCHEMA_URL: string;
35
36
  */
36
37
  declare const PixiVNJsonComparationOperators: PixiVNJsonComparationOperatorsType[];
37
38
 
38
- /**
39
- * A handler function invoked for each `[key]` token found in the text that passes the
40
- * {@link ReplaceHandlerOptions.validation} check.
41
- *
42
- * @param key The content found inside the square brackets (without the brackets themselves).
43
- * For example, for the token `[john]` the key is `"john"`.
44
- * @returns The string to substitute in place of `[key]`, or `undefined` to leave the token unchanged.
45
- */
46
- type ReplaceHandler = (
47
- /**
48
- * The key to be replaced
49
- */
50
- key: string) => string | undefined;
51
- /**
52
- * Configuration options for a text-replacement handler registered via {@link TextReplaces.add}.
53
- */
54
- type ReplaceHandlerOptions = {
55
- /**
56
- * A unique name that identifies this handler.
57
- * Used for documentation and debugging purposes.
58
- */
59
- name: string;
60
- /**
61
- * An optional human-readable description of what this handler does.
62
- * Used for documentation purposes.
63
- */
64
- description?: string;
65
- /**
66
- * Determines whether this handler should be invoked for a given `[key]` token.
67
- *
68
- * - `"all"` – the handler is always invoked for every token found.
69
- * - `"characterId"` – the handler is invoked only when the key matches a registered character ID
70
- * (i.e. the character is present in `RegisteredCharacters`).
71
- * - `RegExp` – the key string is tested against the regular expression. The handler is invoked
72
- * only if the regex matches.
73
- * - `ZodType<string>` – the key string is validated with `schema.safeParse(key)`. The handler
74
- * is invoked only if validation succeeds.
75
- *
76
- * @example
77
- * ```ts
78
- * // RegExp: only replace keys that look like lowercase identifiers
79
- * validation: /^[a-z_]+$/
80
- *
81
- * // Zod: only replace keys that are one of a fixed set of values
82
- * import { z } from "zod"
83
- * validation: z.enum(["player", "npc", "enemy"])
84
- * ```
85
- */
86
- validation: RegExp | "characterId" | "all" | ZodType<string>;
87
- /**
88
- * When this handler should be invoked relative to the translation step.
89
- *
90
- * - `"before-translation"` – the handler runs **before** {@link onInkTranslate} is called.
91
- * Useful for pre-processing tokens, e.g. converting `[key]` into `{{key}}` for i18next.
92
- * - `"after-translation"` – the handler runs **after** {@link onInkTranslate} is called.
93
- * Useful for substituting values that depend on the translated text.
94
- *
95
- * @default "before-translation"
96
- */
97
- type?: "after-translation" | "before-translation";
98
- /**
99
- * When `true`, the **first** occurrence of a matched `[key]` token is converted to the i18n
100
- * double-brace format `{{[key]}}` (exactly once). Any subsequent occurrences of `[key]` in
101
- * the same text are then replaced with the handler's return value as usual.
102
- *
103
- * The transformation sequence for a matched key is:
104
- * - first occurrence: `[key]` → `{{[key]}}`
105
- * - remaining occurrences: `[key]` → handler return value
106
- *
107
- * When `false` or omitted, the handler's return value directly replaces all occurrences of `[key]`.
108
- *
109
- * **Recommended i18n configuration:** when this option is enabled, configure
110
- * `missingInterpolationHandler` in your i18n instance so that keys with no matching
111
- * translation are left intact rather than replaced with an empty string:
112
- *
113
- * ```ts title="lib/i18n.ts"
114
- * i18n.init({
115
- * // ...
116
- * missingInterpolationHandler(_text, value, _options) {
117
- * return value[1];
118
- * },
119
- * });
120
- * ```
121
- *
122
- * @default false
123
- */
124
- i18nInterpolation?: boolean;
125
- };
126
-
127
- /**
128
- * A middleware handler that can intercept and transform a logic value before it is
129
- * returned by {@link VariableGetter.getLogichValue}.
130
- *
131
- * Handlers are called in registration order, each receiving the current value and a
132
- * `next` function to invoke the rest of the chain (including the built-in resolver).
133
- * Return `undefined` to fall through to `next`.
134
- */
135
- type VariableGetterHandler = <T = StorageElementType>(value: T, next: (value: T) => T | undefined) => T | undefined;
136
-
137
- /**
138
- * Manages text replacement handlers that process content enclosed in square brackets (`[key]`).
139
- *
140
- * Handlers are called in the order they were added. For each handler, the current text is scanned
141
- * for all `[key]` patterns. If the handler's `validation` matches a key, the handler is
142
- * invoked with that key. If the handler returns a string, all occurrences of `[key]` are replaced
143
- * with the returned value. After a handler finishes processing the text, the next handler starts
144
- * on the updated text.
145
- *
146
- * Each handler specifies whether it runs before or after translation via the `type` field in its
147
- * options (defaults to `"before-translation"`).
148
- *
149
- * @example
150
- * ```ts title="content/text-replaces.ts"
151
- * import { TextReplaces } from 'pixi-vn-ink'
152
- * import { getCharacterById } from "@drincs/pixi-vn";
153
- *
154
- * // Replace [characterId] with the character's display name
155
- * TextReplaces.add(
156
- * (key) => {
157
- * const character = getCharacterById(key)
158
- * return character?.name
159
- * },
160
- * {
161
- * name: "character-name",
162
- * description: "Replaces character IDs with their display names",
163
- * validation: /^[a-z_]+$/,
164
- * type: "after-translation",
165
- * }
166
- * )
167
- * // "Hello [john], meet [jane]!" -> "Hello John, meet Jane!"
168
- * ```
169
- */
170
- declare namespace TextReplaces {
171
- /**
172
- * Configuration options for the `TextReplaces` system.
173
- */
174
- const options: {
175
- /**
176
- * The regex used to find replacement tokens in the text (e.g. `[key]`).
177
- * @default /\[([^\]]+)\]/
178
- */
179
- replaceRegex: RegExp;
180
- };
181
- /**
182
- * Registers a new replacement handler.
183
- *
184
- * Handlers are executed in the order they are added. The first handler added runs first.
185
- *
186
- * When the first handler of a given type (`"before-translation"` or `"after-translation"`)
187
- * is registered, the corresponding translator hook (`translator.beforeToTranslate` or
188
- * `translator.afterToTranslate`) is automatically set so that `TextReplaces` takes exclusive
189
- * ownership of that hook. Do **not** mix `TextReplaces` with the deprecated
190
- * {@link onReplaceTextBeforeTranslation} / {@link onReplaceTextAfterTranslation} functions
191
- * for the same phase, as they will overwrite each other's hook.
192
- *
193
- * @param fn The handler function. Receives the key found inside `[...]` and should return
194
- * the replacement string, or `undefined` to leave that token unchanged.
195
- * @param handlerOptions Configuration for this handler, including its name, optional
196
- * description, validation regex, and execution phase.
197
- * @example
198
- * ```ts title="content/text-replaces.ts"
199
- * import { TextReplaces } from 'pixi-vn-ink'
200
- *
201
- * TextReplaces.add(
202
- * (key) => key === "player" ? "Mario" : undefined,
203
- * {
204
- * name: "player-name",
205
- * validation: /^player$/,
206
- * }
207
- * )
208
- * ```
209
- */
210
- function add(fn: ReplaceHandler, handlerOptions: ReplaceHandlerOptions): void;
211
- /**
212
- * Removes a previously registered handler function.
213
- *
214
- * Only the first registration matching `fn` is removed. If the same function was added
215
- * multiple times, subsequent registrations remain.
216
- *
217
- * @param fn The handler function to remove.
218
- */
219
- function remove(fn: ReplaceHandler): void;
220
- /**
221
- * Returns metadata for all registered handlers, in registration order.
222
- *
223
- * @returns An array of {@link ReplaceHandlerOptions} for each registered handler.
224
- */
225
- function info(): ReplaceHandlerOptions[];
226
- /**
227
- * Applies all registered handlers of the specified type to the given text in order.
228
- *
229
- * For each handler:
230
- * 1. All `[key]` tokens currently present in the text are collected.
231
- * 2. For each unique key, the handler's `validation` is tested against the key.
232
- * 3. If validation passes, the handler is called with the key.
233
- * 4. If the handler returns a string, **all** occurrences of `[key]` in the text are
234
- * replaced with that string.
235
- * 5. After the handler has processed all tokens, the next handler starts on the updated text.
236
- *
237
- * @param text The source text to process.
238
- * @param replaceOptions Specifies which phase of handlers to run.
239
- * @returns The text after all matching handlers have been applied.
240
- * @example
241
- * ```ts title="content/text-replaces.ts"
242
- * // Given handlers that replace [name] -> "Mario" and [surname] -> "Rossi":
243
- * TextReplaces.replace("Ciao [name] [surname]. [name] vai pure", { type: "before-translation" })
244
- * // => "Ciao Mario Rossi. Mario vai pure"
245
- * ```
246
- */
247
- function replace(text: string, replaceOptions: {
248
- /** Which phase of handlers to execute. */
249
- type: "after-translation" | "before-translation";
250
- }): string;
251
- }
252
-
253
- declare namespace VariableGetter {
254
- /**
255
- * Registers a new middleware handler into the resolution chain.
256
- * Handlers are invoked in the order they were added.
257
- *
258
- * @param handler - The middleware handler to register.
259
- */
260
- function add(handler: VariableGetterHandler): void;
261
- /**
262
- * Removes all registered middleware handlers, restoring the default resolution behaviour.
263
- */
264
- function clear(): void;
265
- /**
266
- * Resolves a JSON logic value, running it through all registered middleware handlers
267
- * before falling back to the built-in storage/arithmetic/condition evaluator.
268
- *
269
- * @param value - The value or logic expression to resolve.
270
- * @param props - The current step label props passed to each handler.
271
- * @returns The resolved value, or `undefined`.
272
- */
273
- function getLogichValue<T = StorageElementType>(value: any, props?: StepLabelPropsType): T | undefined;
274
- }
275
-
276
39
  /**
277
40
  * Initialises the pixi-vn-json system by registering all default operation handlers
278
41
  * (canvas, sound, assets, storage, narration, etc.) into the {@link JsonUnifier}.
@@ -281,4 +44,4 @@ declare namespace VariableGetter {
281
44
  */
282
45
  declare function init(): void;
283
46
 
284
- export { PIXIVNJSON_PARAM_ID, PIXIVNJSON_SCHEMA_URL, PixiVNJsonComparationOperators, PixiVNJsonComparationOperatorsType, type ReplaceHandler, type ReplaceHandlerOptions, TextReplaces, VariableGetter, type VariableGetterHandler, init };
47
+ export { PIXIVNJSON_PARAM_ID, PIXIVNJSON_SCHEMA_URL, PixiVNJsonComparationOperators, PixiVNJsonComparationOperatorsType, init };
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import {getValueFromConditionalStatements,getLogichValue,getConditionalStep,setInitialStorageValue,setStorageValue,videoOperation,soundOperation,loadAssets,narrationOperation,textOperation,imageOperation,imageContainerOperation,effectOperation,canvasElementOperation,animateOperation}from'@drincs/pixi-vn-json/actions';import {JsonUnifier}from'@drincs/pixi-vn-json/core';import {translator as translator$1}from'@drincs/pixi-vn-json/translator';export*from'@drincs/pixi-vn-json/translator';import {RegisteredCharacters}from'@drincs/pixi-vn/characters';import {ZodType}from'zod';export*from'@drincs/pixi-vn-json/interpreter';var g;(v=>{let n=new Set;function o(m){n.add(m);}v.add=o;function h(){n.clear();}v.clear=h;function y(m,x={}){let p=a=>getLogichValue(a,x)??void 0,u=getValueFromConditionalStatements(m,x);if(n.size===0)return p(u);let c=p;for(let a of n){let e=c;c=i=>a(i,e)??void 0;}return c(u)}v.getLogichValue=y;})(g||(g={}));var b={version:"1.13.8"};var _="___param___",N=`https://pixi-vn.com/schemas/${b.version}/schema.json`,T=["==","!=","<","<=",">",">=","CONTAINS"];var O;(a=>{a.options={replaceRegex:/\[([^\]]+)\]/};let o=[],h=false,y=false;function v(e,i){o.unshift({fn:e,opts:i});let t=i.type??"before-translation";t==="before-translation"&&!h?(translator$1.beforeToTranslate=r=>p(r,{type:"before-translation"}),h=true):t==="after-translation"&&!y&&(translator$1.afterToTranslate=r=>p(r,{type:"after-translation"}),y=true);}a.add=v;function m(e){let i=o.findIndex(t=>t.fn===e);i!==-1&&o.splice(i,1);}a.remove=m;function x(){return o.map(e=>e.opts)}a.info=x;function p(e,i){for(let r of o.filter(d=>d.opts.i18nInterpolation))e=u(e,r.fn,r.opts.validation);let t=o.filter(r=>(r.opts.type??"before-translation")===i.type);for(let r of t)e=c(e,r.fn,r.opts.validation);return e}a.replace=p;function u(e,i,t){let r=new RegExp(a.options.replaceRegex.source,"g"),d=[...e.matchAll(r)],l=new Set,f=[];for(let s of d)l.has(s[1])||(l.add(s[1]),f.push(s[1]));for(let s of f){if(t==="characterId"){if(!RegisteredCharacters.has(s))continue}else if(t!=="all"){if(t instanceof RegExp){if(!t.test(s))continue}else if(t instanceof ZodType&&!t.safeParse(s).success)continue}i(s)!==void 0&&(e=e.replace(`[${s}]`,`{{[${s}]}}`));}return e}function c(e,i,t){let r=new RegExp(a.options.replaceRegex.source,"g"),d=[...e.matchAll(r)],l=new Set,f=[];for(let s of d)l.has(s[1])||(l.add(s[1]),f.push(s[1]));for(let s of f){if(t==="characterId"){if(!RegisteredCharacters.has(s))continue}else if(t!=="all"){if(t instanceof RegExp){if(!t.test(s))continue}else if(t instanceof ZodType&&!t.safeParse(s).success)continue}let j=i(s);j!==void 0&&(e=e.replaceAll(`[${s}]`,j));}return e}})(O||(O={}));function pe(){JsonUnifier.init({animateOperation:animateOperation,canvasElementOperation:canvasElementOperation,effectOperation:effectOperation,imageContainerOperation:imageContainerOperation,imageOperation:imageOperation,textOperation:textOperation,narrationOperation:narrationOperation,loadAssets:loadAssets,soundOperation:soundOperation,videoOperation:videoOperation,setStorageValue:setStorageValue,setInitialStorageValue:setInitialStorageValue,getLogichValue:g.getLogichValue,getConditionalStep:getConditionalStep});}
2
- export{_ as PIXIVNJSON_PARAM_ID,N as PIXIVNJSON_SCHEMA_URL,T as PixiVNJsonComparationOperators,O as TextReplaces,g as VariableGetter,pe as init};
1
+ import {getConditionalStep,VariableGetter,setInitialStorageValue,setStorageValue,videoOperation,soundOperation,loadAssets,narrationOperation,textOperation,imageOperation,imageContainerOperation,effectOperation,canvasElementOperation,animateOperation}from'@drincs/pixi-vn-json/actions';export{VariableGetter}from'@drincs/pixi-vn-json/actions';import {JsonUnifier}from'@drincs/pixi-vn-json/core';export*from'@drincs/pixi-vn-json/interpreter';export*from'@drincs/pixi-vn-json/translator';var t={version:"1.13.10"};var i="___param___",s=`https://pixi-vn.com/schemas/${t.version}/schema.json`,r=["==","!=","<","<=",">",">=","CONTAINS"];function b(){JsonUnifier.init({animateOperation:animateOperation,canvasElementOperation:canvasElementOperation,effectOperation:effectOperation,imageContainerOperation:imageContainerOperation,imageOperation:imageOperation,textOperation:textOperation,narrationOperation:narrationOperation,loadAssets:loadAssets,soundOperation:soundOperation,videoOperation:videoOperation,setStorageValue:setStorageValue,setInitialStorageValue:setInitialStorageValue,getLogichValue:VariableGetter.getLogichValue,getConditionalStep:getConditionalStep});}
2
+ export{i as PIXIVNJSON_PARAM_ID,s as PIXIVNJSON_SCHEMA_URL,r as PixiVNJsonComparationOperators,b as init};