@drincs/pixi-vn-json 1.13.4 → 1.13.6

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.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.4"};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});}
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.6"};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
2
  export{_ as PIXIVNJSON_PARAM_ID,N as PIXIVNJSON_SCHEMA_URL,T as PixiVNJsonComparationOperators,O as TextReplaces,g as VariableGetter,pe as init};
@@ -1,43 +1,10 @@
1
- import { n as PixiVNJsonLabelStep, w as PixiVNJsonValueSet, k as PixiVNJsonIfElse, q as PixiVNJsonOperation } from './PixiVNJsonLabelStep-B7SEp127.cjs';
1
+ import { F as PixiVNJsonLabelStep, L as PixiVNJsonOperation } from './PixiVNJsonLabelStep-DJgORyFd.cjs';
2
2
  import { LabelAbstract, LabelProps, StepLabelPropsType, StepLabelType } from '@drincs/pixi-vn/narration';
3
+ import { PixiVNJson } from './schema.cjs';
3
4
  import '@drincs/pixi-vn';
4
5
  import '@drincs/pixi-vn/motion';
5
6
  import 'pixi.js';
6
7
 
7
- /**
8
- * Collection of labels to be used in the narrative.
9
- */
10
- type PixiVNJsonLabels = {
11
- [labelId: string]: PixiVNJsonLabelStep[];
12
- };
13
-
14
- /**
15
- * PixiVNJson It can be defined as a programming language to write a narrative written in json.
16
- */
17
- interface PixiVNJson {
18
- /**
19
- * The URI of the JSON Schema that describes and validates this document.
20
- *
21
- * You can point to a specific version of the schema, for example:
22
- * - `"https://pixi-vn.com/schemas/1.13.0/schema.json"` — pin to a specific version
23
- * - `"https://pixi-vn.com/schemas/latest/schema.json"` — always use the latest version
24
- *
25
- * Most editors (VS Code, WebStorm, etc.) use this field to provide
26
- * auto-completion, hover documentation, and validation for the document.
27
- */
28
- $schema?: string;
29
- /**
30
- * The operations to be executed before the narrative starts.
31
- * For the set storage: They will be set only if there are no variables with the same key already.
32
- * For the det tempstorage: if there are variables with the same key already, they will be overwritten.
33
- */
34
- initialOperations?: (PixiVNJsonValueSet | PixiVNJsonIfElse<PixiVNJsonValueSet>)[];
35
- /**
36
- * The labels to be used in the narrative. They will be added to the system
37
- */
38
- labels?: PixiVNJsonLabels;
39
- }
40
-
41
8
  type LabelJsonOptions = {
42
9
  /**
43
10
  * Function that converts a string to a {@link PixiVNJsonOperation}.
@@ -1,43 +1,10 @@
1
- import { n as PixiVNJsonLabelStep, w as PixiVNJsonValueSet, k as PixiVNJsonIfElse, q as PixiVNJsonOperation } from './PixiVNJsonLabelStep-B7SEp127.js';
1
+ import { F as PixiVNJsonLabelStep, L as PixiVNJsonOperation } from './PixiVNJsonLabelStep-DJgORyFd.js';
2
2
  import { LabelAbstract, LabelProps, StepLabelPropsType, StepLabelType } from '@drincs/pixi-vn/narration';
3
+ import { PixiVNJson } from './schema.js';
3
4
  import '@drincs/pixi-vn';
4
5
  import '@drincs/pixi-vn/motion';
5
6
  import 'pixi.js';
6
7
 
7
- /**
8
- * Collection of labels to be used in the narrative.
9
- */
10
- type PixiVNJsonLabels = {
11
- [labelId: string]: PixiVNJsonLabelStep[];
12
- };
13
-
14
- /**
15
- * PixiVNJson It can be defined as a programming language to write a narrative written in json.
16
- */
17
- interface PixiVNJson {
18
- /**
19
- * The URI of the JSON Schema that describes and validates this document.
20
- *
21
- * You can point to a specific version of the schema, for example:
22
- * - `"https://pixi-vn.com/schemas/1.13.0/schema.json"` — pin to a specific version
23
- * - `"https://pixi-vn.com/schemas/latest/schema.json"` — always use the latest version
24
- *
25
- * Most editors (VS Code, WebStorm, etc.) use this field to provide
26
- * auto-completion, hover documentation, and validation for the document.
27
- */
28
- $schema?: string;
29
- /**
30
- * The operations to be executed before the narrative starts.
31
- * For the set storage: They will be set only if there are no variables with the same key already.
32
- * For the det tempstorage: if there are variables with the same key already, they will be overwritten.
33
- */
34
- initialOperations?: (PixiVNJsonValueSet | PixiVNJsonIfElse<PixiVNJsonValueSet>)[];
35
- /**
36
- * The labels to be used in the narrative. They will be added to the system
37
- */
38
- labels?: PixiVNJsonLabels;
39
- }
40
-
41
8
  type LabelJsonOptions = {
42
9
  /**
43
10
  * Function that converts a string to a {@link PixiVNJsonOperation}.
@@ -0,0 +1,73 @@
1
+ import { StepLabelPropsType } from '@drincs/pixi-vn';
2
+ import { F as PixiVNJsonLabelStep, L as PixiVNJsonOperation } from './PixiVNJsonLabelStep-DJgORyFd.cjs';
3
+ import '@drincs/pixi-vn/motion';
4
+ import 'pixi.js';
5
+
6
+ /**
7
+ * Manages the translation pipeline for all text displayed by pixi-vn-json.
8
+ *
9
+ * The pipeline applies three optional hooks in order:
10
+ * 1. `beforeToTranslate` – pre-processes the key before translation.
11
+ * 2. `translate` – the main translation function (identity by default).
12
+ * 3. `afterToTranslate` – post-processes the translated string.
13
+ *
14
+ * Use {@link TranslatorManager.t} to translate a key or array of keys.
15
+ */
16
+ declare class TranslatorManager {
17
+ private static _beforeToTranslate;
18
+ private static _translate;
19
+ private static _afterToTranslate;
20
+ /**
21
+ * Translates a single key or an array of keys using the registered pipeline.
22
+ * Returns the same type (`string` or `string[]`) as the input.
23
+ *
24
+ * @param key - The string key or array of string keys to translate.
25
+ * @returns The translated string(s).
26
+ */
27
+ static t<T = string | string[]>(key: T): T;
28
+ /**
29
+ * Sets a hook that runs **before** the main translation function.
30
+ * Useful for key normalization (e.g. trimming, lowercasing).
31
+ */
32
+ static set beforeToTranslate(value: (key: string) => string);
33
+ /**
34
+ * Sets the main translation function.
35
+ * Defaults to an identity function (returns the key unchanged).
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * translator.translate = (key) => i18n.t(key);
40
+ * ```
41
+ */
42
+ static set translate(value: (key: string) => string);
43
+ /** Returns the composed translation pipeline (before → translate → after). */
44
+ static get translate(): (key: string) => string;
45
+ /**
46
+ * Sets a hook that runs **after** the main translation function.
47
+ * Useful for post-processing translated strings (e.g. replacing placeholders).
48
+ */
49
+ static set afterToTranslate(value: (key: string) => string);
50
+ private static addKey;
51
+ private static getConditionalsThenElse;
52
+ /**
53
+ * Generates a JSON translation object from the provided labels.
54
+ * @param labels The labels to translate.
55
+ * @param json The JSON object to populate with translations.
56
+ * @param options Options for translation, including default value handling.
57
+ * @returns The populated JSON object with translations.
58
+ */
59
+ static generateJsonTranslation(labels: PixiVNJsonLabelStep[], json?: object, options?: {
60
+ /**
61
+ * Default value to use when a key is not found.
62
+ * - "empty_string": Use an empty string as the default value.
63
+ * - "copy_key": Use the key itself as the default value.
64
+ * @default "copy_key"
65
+ */
66
+ defaultValue?: "empty_string" | "copy_key";
67
+ operationStringConvert?: (value: string, step: PixiVNJsonLabelStep, props: StepLabelPropsType | {}) => Promise<PixiVNJsonOperation | undefined>;
68
+ }): Promise<object>;
69
+ }
70
+
71
+ declare const translator: typeof TranslatorManager;
72
+
73
+ export { translator };
@@ -0,0 +1,73 @@
1
+ import { StepLabelPropsType } from '@drincs/pixi-vn';
2
+ import { F as PixiVNJsonLabelStep, L as PixiVNJsonOperation } from './PixiVNJsonLabelStep-DJgORyFd.js';
3
+ import '@drincs/pixi-vn/motion';
4
+ import 'pixi.js';
5
+
6
+ /**
7
+ * Manages the translation pipeline for all text displayed by pixi-vn-json.
8
+ *
9
+ * The pipeline applies three optional hooks in order:
10
+ * 1. `beforeToTranslate` – pre-processes the key before translation.
11
+ * 2. `translate` – the main translation function (identity by default).
12
+ * 3. `afterToTranslate` – post-processes the translated string.
13
+ *
14
+ * Use {@link TranslatorManager.t} to translate a key or array of keys.
15
+ */
16
+ declare class TranslatorManager {
17
+ private static _beforeToTranslate;
18
+ private static _translate;
19
+ private static _afterToTranslate;
20
+ /**
21
+ * Translates a single key or an array of keys using the registered pipeline.
22
+ * Returns the same type (`string` or `string[]`) as the input.
23
+ *
24
+ * @param key - The string key or array of string keys to translate.
25
+ * @returns The translated string(s).
26
+ */
27
+ static t<T = string | string[]>(key: T): T;
28
+ /**
29
+ * Sets a hook that runs **before** the main translation function.
30
+ * Useful for key normalization (e.g. trimming, lowercasing).
31
+ */
32
+ static set beforeToTranslate(value: (key: string) => string);
33
+ /**
34
+ * Sets the main translation function.
35
+ * Defaults to an identity function (returns the key unchanged).
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * translator.translate = (key) => i18n.t(key);
40
+ * ```
41
+ */
42
+ static set translate(value: (key: string) => string);
43
+ /** Returns the composed translation pipeline (before → translate → after). */
44
+ static get translate(): (key: string) => string;
45
+ /**
46
+ * Sets a hook that runs **after** the main translation function.
47
+ * Useful for post-processing translated strings (e.g. replacing placeholders).
48
+ */
49
+ static set afterToTranslate(value: (key: string) => string);
50
+ private static addKey;
51
+ private static getConditionalsThenElse;
52
+ /**
53
+ * Generates a JSON translation object from the provided labels.
54
+ * @param labels The labels to translate.
55
+ * @param json The JSON object to populate with translations.
56
+ * @param options Options for translation, including default value handling.
57
+ * @returns The populated JSON object with translations.
58
+ */
59
+ static generateJsonTranslation(labels: PixiVNJsonLabelStep[], json?: object, options?: {
60
+ /**
61
+ * Default value to use when a key is not found.
62
+ * - "empty_string": Use an empty string as the default value.
63
+ * - "copy_key": Use the key itself as the default value.
64
+ * @default "copy_key"
65
+ */
66
+ defaultValue?: "empty_string" | "copy_key";
67
+ operationStringConvert?: (value: string, step: PixiVNJsonLabelStep, props: StepLabelPropsType | {}) => Promise<PixiVNJsonOperation | undefined>;
68
+ }): Promise<object>;
69
+ }
70
+
71
+ declare const translator: typeof TranslatorManager;
72
+
73
+ export { translator };
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@drincs/pixi-vn-json",
3
- "version": "1.13.4",
3
+ "version": "1.13.6",
4
4
  "type": "module",
5
5
  "description": "Pixi'VN can be integrated with JSON files to create a visual novel.",
6
6
  "main": "./dist/index.cjs",
7
- "module": "./dist/index.js",
7
+ "module": "./dist/index.mjs",
8
8
  "types": "./dist/index.d.ts",
9
9
  "files": [
10
10
  "dist"