@drincs/pixi-vn-json 1.10.3 → 1.11.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/core.cjs +2 -1
- package/dist/core.cjs.map +1 -0
- package/dist/core.d.cts +9 -8
- package/dist/core.d.ts +9 -8
- package/dist/core.mjs +2 -1
- package/dist/core.mjs.map +1 -0
- package/dist/importer.cjs +2 -1
- package/dist/importer.cjs.map +1 -0
- package/dist/importer.d.cts +9 -8
- package/dist/importer.d.ts +9 -8
- package/dist/importer.mjs +2 -1
- package/dist/importer.mjs.map +1 -0
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +9 -8
- package/dist/index.d.ts +9 -8
- package/dist/index.mjs +2 -2
- package/dist/translator.cjs +2 -1
- package/dist/translator.cjs.map +1 -0
- package/dist/translator.d.cts +9 -8
- package/dist/translator.d.ts +9 -8
- package/dist/translator.mjs +2 -1
- package/dist/translator.mjs.map +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/operationtoconvert.ts","../src/translator/TranslatorManager.ts","../src/translator/index.ts"],"names":["operationStringToString","operation","stringOperation","value","res","JsonUnifier","_TranslatorManager","key","k","text","json","options","defaultValue","data","element","tempRes","item","labels","operationStringConvert","promises","label","multichoices","c","choice","t","tt","dialogues","dialogue","ttt","__publicField","TranslatorManager","translator"],"mappings":"qOAGO,SAASA,EAAwBC,CAAAA,CAA8C,CAClF,IAAIC,CAAAA,CAAkB,EAAA,CACtB,OAAAD,CAAAA,CAAU,MAAA,CAAO,QAASE,CAAAA,EAAU,CAChC,GAAI,OAAOA,CAAAA,EAAU,SACjBD,CAAAA,EAAmBC,CAAAA,CAAAA,KAChB,CACH,IAAIC,CAAAA,CAAMC,iBAAY,cAAA,CAAuBF,CAAK,EAClDD,CAAAA,EAAmB,CAAA,EAAGE,CAAG,CAAA,EAC7B,CACJ,CAAC,CAAA,CACMF,CACX,CCDA,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S,CAAA,CACnDG,CAAAA,CAAM,MAAMc,CAAAA,CAAuBhB,CAAAA,CAAiBkB,EAAO,EAAE,EACjE,GAAI,CAAChB,EACD,OAEJH,CAAAA,CAAYG,EAChB,CACQH,CAAAA,CAAU,OACT,MAAA,EACOA,CAAAA,CAAU,gBACT,MAAA,EACDK,CAAAA,CAAkB,OAAOI,CAAAA,CAAMT,CAAAA,CAAU,KAAM,CAAE,YAAA,CAAAW,CAAa,CAAC,EAKnF,CAEAQ,CAAAA,CAAM,eAAA,EACEd,EAAkB,uBAAA,CAAwBc,CAAAA,CAAM,eAAe,CAAA,CACrE,OAAA,CAASJ,GAAS,CACZ,KAAA,CAAM,QAAQA,CAAI,CAAA,CAClBV,EAAkB,uBAAA,CAAwBU,CAAAA,CAAMN,EAAMC,CAAO,CAAA,CAE7DL,EAAkB,uBAAA,CAAwB,CAACU,CAAI,CAAA,CAAGN,CAAAA,CAAMC,CAAO,EAEvE,CAAC,EAET,CAAC,CAAA,CACD,aAAM,OAAA,CAAQ,GAAA,CAAIQ,CAAQ,CAAA,CACnBT,CACX,CACJ,CAAA,CA3QImB,CAAAA,CADiBvB,EACF,oBAAA,CAAA,CACfuB,CAAAA,CAFiBvB,EAEF,YAAA,CAAuCC,CAAAA,EAAgBA,GACtEsB,CAAAA,CAHiBvB,CAAAA,CAGF,qBAHnB,IAAqBwB,CAAAA,CAArBxB,CAAAA,CCXA,IAAMyB,CAAAA,CAAaD","file":"translator.cjs","sourcesContent":["import { JsonUnifier } from \"@drincs/pixi-vn-json/core\";\nimport { PixiVNJsonOperationString } from \"../interface\";\n\nexport function operationStringToString(operation: PixiVNJsonOperationString): string {\n let stringOperation = \"\";\n operation.values.forEach((value) => {\n if (typeof value === \"string\") {\n stringOperation += value;\n } else {\n let res = JsonUnifier.getLogichValue<string>(value);\n stringOperation += `${res}`;\n }\n });\n return stringOperation;\n}\n","import type { StepLabelPropsType } from \"@drincs/pixi-vn\";\nimport {\n PixiVNJsonChoice,\n PixiVNJsonChoices,\n PixiVNJsonConditionalResultToCombine,\n PixiVNJsonConditionalStatements,\n PixiVNJsonDialog,\n PixiVNJsonDialogText,\n PixiVNJsonLabelStep,\n PixiVNJsonOperation,\n} from \"../interface\";\nimport { operationStringToString } from \"../utils/operationtoconvert\";\n\nexport default class TranslatorManager {\n private static _beforeToTranslate: ((key: string) => string) | undefined = undefined;\n private static _translate: (key: string) => string = (key: string) => key;\n private static _afterToTranslate: ((key: string) => string) | undefined = undefined;\n static t<T = string | string[]>(key: T): T {\n if (Array.isArray(key)) {\n return key.map((k?: string) => TranslatorManager.translate(`${k}`)) as T;\n }\n return TranslatorManager.translate(`${key}`) as T;\n }\n static set beforeToTranslate(value: (key: string) => string) {\n TranslatorManager._beforeToTranslate = value;\n }\n static set translate(value: (key: string) => string) {\n TranslatorManager._translate = value;\n }\n static get translate(): (key: string) => string {\n return (key: string) => {\n let text = key;\n if (TranslatorManager._beforeToTranslate) {\n text = TranslatorManager._beforeToTranslate(text);\n }\n text = TranslatorManager._translate(text);\n if (TranslatorManager._afterToTranslate) {\n text = TranslatorManager._afterToTranslate(text);\n }\n return text;\n };\n }\n static set afterToTranslate(value: (key: string) => string) {\n TranslatorManager._afterToTranslate = value;\n }\n\n private static addKey(\n json: any,\n key: string[] | string,\n options: {\n defaultValue: \"empty_string\" | \"copy_key\";\n }\n ) {\n let defaultValue = options.defaultValue || \"empty_string\";\n if (typeof key === \"string\") {\n key = [key];\n }\n if (Array.isArray(key)) {\n key.forEach((k) => {\n if (json[k] === undefined) {\n if (defaultValue === \"empty_string\") {\n json[k] = \"\";\n } else if (defaultValue === \"copy_key\") {\n if (TranslatorManager._beforeToTranslate) {\n json[k] = TranslatorManager._beforeToTranslate(k);\n } else {\n json[k] = k;\n }\n }\n }\n });\n }\n }\n private static getConditionalsThenElse<T>(\n data: PixiVNJsonConditionalStatements<T> | PixiVNJsonConditionalResultToCombine<T> | T,\n res: T[] = []\n ): T[] {\n if (typeof data === \"object\" && data && \"type\" in data) {\n if (data.type === \"ifelse\") {\n if (data.then) {\n TranslatorManager.getConditionalsThenElse(data.then, res);\n }\n if (data.else) {\n TranslatorManager.getConditionalsThenElse(data.else, res);\n }\n } else if (data.type === \"stepswitch\") {\n if (data.elements) {\n if (Array.isArray(data.elements)) {\n data.elements.forEach((element) => {\n TranslatorManager.getConditionalsThenElse(element, res);\n });\n } else {\n if (data.elements.type === \"ifelse\") {\n let tempRes: T[][] = [];\n TranslatorManager.getConditionalsThenElse(data.elements, tempRes);\n tempRes.forEach((item) => {\n res.push(...item);\n });\n } else if (data.elements.type === \"stepswitch\") {\n let tempRes: T[][] = [];\n TranslatorManager.getConditionalsThenElse(data.elements, tempRes);\n tempRes.forEach((item) => {\n res.push(...item);\n });\n } else {\n TranslatorManager.getConditionalsThenElse(data.elements, res);\n }\n }\n }\n } else if (data.type === \"resulttocombine\") {\n if (data.firstItem) {\n TranslatorManager.getConditionalsThenElse(data.firstItem, res);\n }\n if (data.secondConditionalItem) {\n data.secondConditionalItem.forEach((item) => {\n TranslatorManager.getConditionalsThenElse(item, res);\n });\n }\n } else {\n res.push(data);\n }\n } else if (data) {\n res.push(data);\n }\n return res;\n }\n\n /**\n * Generates a JSON translation object from the provided labels.\n * @param labels The labels to translate.\n * @param json The JSON object to populate with translations.\n * @param options Options for translation, including default value handling.\n * @returns The populated JSON object with translations.\n */\n static async generateJsonTranslation(\n labels: PixiVNJsonLabelStep[],\n json: object = {},\n options: {\n /**\n * Default value to use when a key is not found.\n * - \"empty_string\": Use an empty string as the default value.\n * - \"copy_key\": Use the key itself as the default value.\n * @default \"copy_key\"\n */\n defaultValue?: \"empty_string\" | \"copy_key\";\n operationStringConvert?: (\n value: string,\n step: PixiVNJsonLabelStep,\n props: StepLabelPropsType | {}\n ) => Promise<PixiVNJsonOperation | undefined>;\n } = {}\n ) {\n const { defaultValue = \"copy_key\", operationStringConvert } = options;\n let promises = labels.map(async (label) => {\n if (label.choices) {\n let multichoices: PixiVNJsonChoices[] = [];\n if (!Array.isArray(label.choices)) {\n multichoices = TranslatorManager.getConditionalsThenElse(label.choices);\n } else {\n multichoices = [label.choices];\n }\n multichoices.forEach((c) =>\n c.forEach((choice) => {\n if (\"type\" in choice) {\n let res: PixiVNJsonChoice[] = [];\n if (choice.type === \"ifelse\" || choice.type === \"stepswitch\") {\n TranslatorManager.getConditionalsThenElse(choice, res);\n } else {\n res = [choice];\n }\n let texts = res.map((item) => TranslatorManager.getConditionalsThenElse(item.text));\n texts.forEach((text) => {\n if (Array.isArray(text)) {\n text.forEach((t) => {\n if (Array.isArray(t)) {\n t.forEach((tt) => {\n if (typeof tt === \"string\") {\n TranslatorManager.addKey(json, tt, { defaultValue });\n } else {\n TranslatorManager.getConditionalsThenElse(tt).forEach((t) => {\n if (Array.isArray(t)) {\n t.forEach((tt) => {\n if (typeof tt === \"string\") {\n TranslatorManager.addKey(json, tt, {\n defaultValue,\n });\n }\n });\n } else if (typeof t === \"string\") {\n TranslatorManager.addKey(json, t, { defaultValue });\n }\n });\n }\n });\n } else if (typeof t === \"string\") {\n TranslatorManager.addKey(json, t, { defaultValue });\n }\n });\n }\n });\n }\n })\n );\n }\n if (label.dialogue) {\n let dialogues: PixiVNJsonDialog<PixiVNJsonDialogText>[] = [];\n if (!Array.isArray(label.dialogue)) {\n dialogues = TranslatorManager.getConditionalsThenElse(label.dialogue);\n } else {\n dialogues = [label.dialogue];\n }\n dialogues.forEach((dialogue) => {\n if (typeof dialogue === \"string\") {\n TranslatorManager.addKey(json, dialogue, { defaultValue });\n } else if (\"text\" in dialogue) {\n let text = TranslatorManager.getConditionalsThenElse(dialogue.text);\n if (typeof text === \"string\") {\n text = [text];\n }\n text.forEach((text) => {\n if (typeof text === \"string\") {\n TranslatorManager.addKey(json, text, { defaultValue });\n } else {\n let t = TranslatorManager.getConditionalsThenElse(text);\n t.forEach((tt) => {\n if (typeof tt === \"string\") {\n TranslatorManager.addKey(json, tt, { defaultValue });\n } else if (Array.isArray(tt)) {\n tt.forEach((ttt) => {\n if (typeof ttt === \"string\") {\n TranslatorManager.addKey(json, ttt, { defaultValue });\n } else {\n TranslatorManager.getConditionalsThenElse(ttt).forEach((t) => {\n if (typeof t === \"string\") {\n TranslatorManager.addKey(json, t, { defaultValue });\n }\n });\n }\n });\n }\n });\n }\n });\n }\n });\n }\n if (label.operations) {\n for (let operation of label.operations) {\n if (operation.type === \"operationtoconvert\" && operationStringConvert) {\n let stringOperation = operationStringToString(operation);\n let res = await operationStringConvert(stringOperation, label, {});\n if (!res) {\n return;\n }\n operation = res;\n }\n switch (operation.type) {\n case \"text\":\n switch (operation.operationType) {\n case \"show\":\n TranslatorManager.addKey(json, operation.text, { defaultValue });\n break;\n }\n break;\n }\n }\n }\n if (label.conditionalStep) {\n let l = TranslatorManager.getConditionalsThenElse(label.conditionalStep);\n l.forEach((item) => {\n if (Array.isArray(item)) {\n TranslatorManager.generateJsonTranslation(item, json, options);\n } else {\n TranslatorManager.generateJsonTranslation([item], json, options);\n }\n });\n }\n });\n await Promise.all(promises);\n return json;\n }\n}\n","import TranslateManager from \"./TranslatorManager\";\n\nconst translator = TranslateManager;\n\nexport { translator };\n"]}
|
package/dist/translator.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StorageElementType, CanvasBaseInterface, ImageSprite, ShakeEffectProps, ShowWithDissolveTransitionProps, ShowWithFadeTransitionProps, MoveInOutProps, ZoomInOutProps, PushInOutProps, ImageContainerOptions, ImageSpriteOptions, TextOptions, ImageSpriteMemory, VideoSpriteMemory, ImageContainerMemory, TextMemory, ContainerOptions, ContainerMemory,
|
|
1
|
+
import { StorageElementType, CanvasBaseInterface, ImageSprite, ShakeEffectProps, ShowWithDissolveTransitionProps, ShowWithFadeTransitionProps, MoveInOutProps, ZoomInOutProps, PushInOutProps, ImageContainerOptions, ImageSpriteOptions, TextOptions, ImageSpriteMemory, VideoSpriteMemory, ImageContainerMemory, TextMemory, ContainerOptions, ContainerMemory, SoundPlayOptionsWithChannel, IMediaInstance, LabelRunModeType, StorageObjectType, StepLabelPropsType } from '@drincs/pixi-vn';
|
|
2
2
|
import { KeyframesType, AnimationOptions, ObjectSegment, ObjectSegmentWithTransition, SequenceOptions } from '@drincs/pixi-vn/motion';
|
|
3
3
|
import { UPDATE_PRIORITY } from 'pixi.js';
|
|
4
4
|
|
|
@@ -351,7 +351,7 @@ type PixiVNJsonTextEdit = {
|
|
|
351
351
|
alias: string;
|
|
352
352
|
props?: Partial<TextMemory>;
|
|
353
353
|
};
|
|
354
|
-
type PixiVNJsonUnknownEdit<T extends ContainerOptions
|
|
354
|
+
type PixiVNJsonUnknownEdit<T extends ContainerOptions<any>> = {
|
|
355
355
|
type: "canvaselement";
|
|
356
356
|
operationType: "edit";
|
|
357
357
|
alias: string;
|
|
@@ -393,7 +393,8 @@ type PixiVNJsonSoundPlay = {
|
|
|
393
393
|
type: "sound";
|
|
394
394
|
operationType: "play";
|
|
395
395
|
alias: string;
|
|
396
|
-
|
|
396
|
+
url?: string;
|
|
397
|
+
props?: SoundPlayOptionsWithChannel;
|
|
397
398
|
};
|
|
398
399
|
type PixiVNJsonSoundRemove = {
|
|
399
400
|
type: "sound";
|
|
@@ -401,17 +402,17 @@ type PixiVNJsonSoundRemove = {
|
|
|
401
402
|
alias: string;
|
|
402
403
|
};
|
|
403
404
|
type PixiVNJsonSoundPauseResume = {
|
|
404
|
-
type: "sound";
|
|
405
|
+
type: "sound" | "channel" | "all";
|
|
405
406
|
operationType: "pause" | "resume";
|
|
406
407
|
alias: string;
|
|
407
408
|
};
|
|
408
|
-
type
|
|
409
|
+
type PixiVNJsonSoundEdit = {
|
|
409
410
|
type: "sound";
|
|
410
|
-
operationType: "
|
|
411
|
+
operationType: "edit";
|
|
411
412
|
alias: string;
|
|
412
|
-
|
|
413
|
+
props: Partial<Pick<IMediaInstance, "speed" | "volume" | "muted" | "loop" | "paused">>;
|
|
413
414
|
};
|
|
414
|
-
type PixiVNJsonSound = PixiVNJsonSoundPlay | PixiVNJsonSoundRemove | PixiVNJsonSoundPauseResume |
|
|
415
|
+
type PixiVNJsonSound = PixiVNJsonSoundPlay | PixiVNJsonSoundRemove | PixiVNJsonSoundPauseResume | PixiVNJsonSoundEdit;
|
|
415
416
|
|
|
416
417
|
type PixiVNJsonOperationString = {
|
|
417
418
|
type: "operationtoconvert";
|
package/dist/translator.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StorageElementType, CanvasBaseInterface, ImageSprite, ShakeEffectProps, ShowWithDissolveTransitionProps, ShowWithFadeTransitionProps, MoveInOutProps, ZoomInOutProps, PushInOutProps, ImageContainerOptions, ImageSpriteOptions, TextOptions, ImageSpriteMemory, VideoSpriteMemory, ImageContainerMemory, TextMemory, ContainerOptions, ContainerMemory,
|
|
1
|
+
import { StorageElementType, CanvasBaseInterface, ImageSprite, ShakeEffectProps, ShowWithDissolveTransitionProps, ShowWithFadeTransitionProps, MoveInOutProps, ZoomInOutProps, PushInOutProps, ImageContainerOptions, ImageSpriteOptions, TextOptions, ImageSpriteMemory, VideoSpriteMemory, ImageContainerMemory, TextMemory, ContainerOptions, ContainerMemory, SoundPlayOptionsWithChannel, IMediaInstance, LabelRunModeType, StorageObjectType, StepLabelPropsType } from '@drincs/pixi-vn';
|
|
2
2
|
import { KeyframesType, AnimationOptions, ObjectSegment, ObjectSegmentWithTransition, SequenceOptions } from '@drincs/pixi-vn/motion';
|
|
3
3
|
import { UPDATE_PRIORITY } from 'pixi.js';
|
|
4
4
|
|
|
@@ -351,7 +351,7 @@ type PixiVNJsonTextEdit = {
|
|
|
351
351
|
alias: string;
|
|
352
352
|
props?: Partial<TextMemory>;
|
|
353
353
|
};
|
|
354
|
-
type PixiVNJsonUnknownEdit<T extends ContainerOptions
|
|
354
|
+
type PixiVNJsonUnknownEdit<T extends ContainerOptions<any>> = {
|
|
355
355
|
type: "canvaselement";
|
|
356
356
|
operationType: "edit";
|
|
357
357
|
alias: string;
|
|
@@ -393,7 +393,8 @@ type PixiVNJsonSoundPlay = {
|
|
|
393
393
|
type: "sound";
|
|
394
394
|
operationType: "play";
|
|
395
395
|
alias: string;
|
|
396
|
-
|
|
396
|
+
url?: string;
|
|
397
|
+
props?: SoundPlayOptionsWithChannel;
|
|
397
398
|
};
|
|
398
399
|
type PixiVNJsonSoundRemove = {
|
|
399
400
|
type: "sound";
|
|
@@ -401,17 +402,17 @@ type PixiVNJsonSoundRemove = {
|
|
|
401
402
|
alias: string;
|
|
402
403
|
};
|
|
403
404
|
type PixiVNJsonSoundPauseResume = {
|
|
404
|
-
type: "sound";
|
|
405
|
+
type: "sound" | "channel" | "all";
|
|
405
406
|
operationType: "pause" | "resume";
|
|
406
407
|
alias: string;
|
|
407
408
|
};
|
|
408
|
-
type
|
|
409
|
+
type PixiVNJsonSoundEdit = {
|
|
409
410
|
type: "sound";
|
|
410
|
-
operationType: "
|
|
411
|
+
operationType: "edit";
|
|
411
412
|
alias: string;
|
|
412
|
-
|
|
413
|
+
props: Partial<Pick<IMediaInstance, "speed" | "volume" | "muted" | "loop" | "paused">>;
|
|
413
414
|
};
|
|
414
|
-
type PixiVNJsonSound = PixiVNJsonSoundPlay | PixiVNJsonSoundRemove | PixiVNJsonSoundPauseResume |
|
|
415
|
+
type PixiVNJsonSound = PixiVNJsonSoundPlay | PixiVNJsonSoundRemove | PixiVNJsonSoundPauseResume | PixiVNJsonSoundEdit;
|
|
415
416
|
|
|
416
417
|
type PixiVNJsonOperationString = {
|
|
417
418
|
type: "operationtoconvert";
|
package/dist/translator.mjs
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
import {JsonUnifier}from'@drincs/pixi-vn-json/core';var V=Object.defineProperty;var J=(y,e,i)=>e in y?V(y,e,{enumerable:true,configurable:true,writable:true,value:i}):y[e]=i;var m=(y,e,i)=>J(y,typeof e!="symbol"?e+"":e,i);function E(y){let e="";return y.values.forEach(i=>{if(typeof i=="string")e+=i;else {let n=JsonUnifier.getLogichValue(i);e+=`${n}`;}}),e}var t=class t{static t(e){return Array.isArray(e)?e.map(i=>t.translate(`${i}`)):t.translate(`${e}`)}static set beforeToTranslate(e){t._beforeToTranslate=e;}static set translate(e){t._translate=e;}static get translate(){return e=>{let i=e;return t._beforeToTranslate&&(i=t._beforeToTranslate(i)),i=t._translate(i),t._afterToTranslate&&(i=t._afterToTranslate(i)),i}}static set afterToTranslate(e){t._afterToTranslate=e;}static addKey(e,i,n){let s=n.defaultValue||"empty_string";typeof i=="string"&&(i=[i]),Array.isArray(i)&&i.forEach(f=>{e[f]===void 0&&(s==="empty_string"?e[f]="":s==="copy_key"&&(t._beforeToTranslate?e[f]=t._beforeToTranslate(f):e[f]=f));});}static getConditionalsThenElse(e,i=[]){if(typeof e=="object"&&e&&"type"in e)if(e.type==="ifelse")e.then&&t.getConditionalsThenElse(e.then,i),e.else&&t.getConditionalsThenElse(e.else,i);else if(e.type==="stepswitch"){if(e.elements)if(Array.isArray(e.elements))e.elements.forEach(n=>{t.getConditionalsThenElse(n,i);});else if(e.elements.type==="ifelse"){let n=[];t.getConditionalsThenElse(e.elements,n),n.forEach(s=>{i.push(...s);});}else if(e.elements.type==="stepswitch"){let n=[];t.getConditionalsThenElse(e.elements,n),n.forEach(s=>{i.push(...s);});}else t.getConditionalsThenElse(e.elements,i);}else e.type==="resulttocombine"?(e.firstItem&&t.getConditionalsThenElse(e.firstItem,i),e.secondConditionalItem&&e.secondConditionalItem.forEach(n=>{t.getConditionalsThenElse(n,i);})):i.push(e);else e&&i.push(e);return i}static async generateJsonTranslation(e,i={},n={}){let{defaultValue:s="copy_key",operationStringConvert:f}=n,C=e.map(async o=>{if(o.choices){let r=[];Array.isArray(o.choices)?r=[o.choices]:r=t.getConditionalsThenElse(o.choices),r.forEach(l=>l.forEach(a=>{if("type"in a){let T=[];a.type==="ifelse"||a.type==="stepswitch"?t.getConditionalsThenElse(a,T):T=[a],T.map(p=>t.getConditionalsThenElse(p.text)).forEach(p=>{Array.isArray(p)&&p.forEach(g=>{Array.isArray(g)?g.forEach(c=>{typeof c=="string"?t.addKey(i,c,{defaultValue:s}):t.getConditionalsThenElse(c).forEach(d=>{Array.isArray(d)?d.forEach(u=>{typeof u=="string"&&t.addKey(i,u,{defaultValue:s});}):typeof d=="string"&&t.addKey(i,d,{defaultValue:s});});}):typeof g=="string"&&t.addKey(i,g,{defaultValue:s});});});}}));}if(o.dialogue){let r=[];Array.isArray(o.dialogue)?r=[o.dialogue]:r=t.getConditionalsThenElse(o.dialogue),r.forEach(l=>{if(typeof l=="string")t.addKey(i,l,{defaultValue:s});else if("text"in l){let a=t.getConditionalsThenElse(l.text);typeof a=="string"&&(a=[a]),a.forEach(T=>{typeof T=="string"?t.addKey(i,T,{defaultValue:s}):t.getConditionalsThenElse(T).forEach(p=>{typeof p=="string"?t.addKey(i,p,{defaultValue:s}):Array.isArray(p)&&p.forEach(g=>{typeof g=="string"?t.addKey(i,g,{defaultValue:s}):t.getConditionalsThenElse(g).forEach(c=>{typeof c=="string"&&t.addKey(i,c,{defaultValue:s});});});});});}});}if(o.operations)for(let r of o.operations){if(r.type==="operationtoconvert"&&f){let l=E(r),a=await f(l,o,{});if(!a)return;r=a;}r.type==="text"&&r.operationType==="show"&&t.addKey(i,r.text,{defaultValue:s});}o.conditionalStep&&t.getConditionalsThenElse(o.conditionalStep).forEach(l=>{Array.isArray(l)?t.generateJsonTranslation(l,i,n):t.generateJsonTranslation([l],i,n);});});return await Promise.all(C),i}};m(t,"_beforeToTranslate"),m(t,"_translate",e=>e),m(t,"_afterToTranslate");var h=t;var L=h;export{L as translator}
|
|
1
|
+
import {JsonUnifier}from'@drincs/pixi-vn-json/core';var V=Object.defineProperty;var J=(y,e,i)=>e in y?V(y,e,{enumerable:true,configurable:true,writable:true,value:i}):y[e]=i;var m=(y,e,i)=>J(y,typeof e!="symbol"?e+"":e,i);function E(y){let e="";return y.values.forEach(i=>{if(typeof i=="string")e+=i;else {let n=JsonUnifier.getLogichValue(i);e+=`${n}`;}}),e}var t=class t{static t(e){return Array.isArray(e)?e.map(i=>t.translate(`${i}`)):t.translate(`${e}`)}static set beforeToTranslate(e){t._beforeToTranslate=e;}static set translate(e){t._translate=e;}static get translate(){return e=>{let i=e;return t._beforeToTranslate&&(i=t._beforeToTranslate(i)),i=t._translate(i),t._afterToTranslate&&(i=t._afterToTranslate(i)),i}}static set afterToTranslate(e){t._afterToTranslate=e;}static addKey(e,i,n){let s=n.defaultValue||"empty_string";typeof i=="string"&&(i=[i]),Array.isArray(i)&&i.forEach(f=>{e[f]===void 0&&(s==="empty_string"?e[f]="":s==="copy_key"&&(t._beforeToTranslate?e[f]=t._beforeToTranslate(f):e[f]=f));});}static getConditionalsThenElse(e,i=[]){if(typeof e=="object"&&e&&"type"in e)if(e.type==="ifelse")e.then&&t.getConditionalsThenElse(e.then,i),e.else&&t.getConditionalsThenElse(e.else,i);else if(e.type==="stepswitch"){if(e.elements)if(Array.isArray(e.elements))e.elements.forEach(n=>{t.getConditionalsThenElse(n,i);});else if(e.elements.type==="ifelse"){let n=[];t.getConditionalsThenElse(e.elements,n),n.forEach(s=>{i.push(...s);});}else if(e.elements.type==="stepswitch"){let n=[];t.getConditionalsThenElse(e.elements,n),n.forEach(s=>{i.push(...s);});}else t.getConditionalsThenElse(e.elements,i);}else e.type==="resulttocombine"?(e.firstItem&&t.getConditionalsThenElse(e.firstItem,i),e.secondConditionalItem&&e.secondConditionalItem.forEach(n=>{t.getConditionalsThenElse(n,i);})):i.push(e);else e&&i.push(e);return i}static async generateJsonTranslation(e,i={},n={}){let{defaultValue:s="copy_key",operationStringConvert:f}=n,C=e.map(async o=>{if(o.choices){let r=[];Array.isArray(o.choices)?r=[o.choices]:r=t.getConditionalsThenElse(o.choices),r.forEach(l=>l.forEach(a=>{if("type"in a){let T=[];a.type==="ifelse"||a.type==="stepswitch"?t.getConditionalsThenElse(a,T):T=[a],T.map(p=>t.getConditionalsThenElse(p.text)).forEach(p=>{Array.isArray(p)&&p.forEach(g=>{Array.isArray(g)?g.forEach(c=>{typeof c=="string"?t.addKey(i,c,{defaultValue:s}):t.getConditionalsThenElse(c).forEach(d=>{Array.isArray(d)?d.forEach(u=>{typeof u=="string"&&t.addKey(i,u,{defaultValue:s});}):typeof d=="string"&&t.addKey(i,d,{defaultValue:s});});}):typeof g=="string"&&t.addKey(i,g,{defaultValue:s});});});}}));}if(o.dialogue){let r=[];Array.isArray(o.dialogue)?r=[o.dialogue]:r=t.getConditionalsThenElse(o.dialogue),r.forEach(l=>{if(typeof l=="string")t.addKey(i,l,{defaultValue:s});else if("text"in l){let a=t.getConditionalsThenElse(l.text);typeof a=="string"&&(a=[a]),a.forEach(T=>{typeof T=="string"?t.addKey(i,T,{defaultValue:s}):t.getConditionalsThenElse(T).forEach(p=>{typeof p=="string"?t.addKey(i,p,{defaultValue:s}):Array.isArray(p)&&p.forEach(g=>{typeof g=="string"?t.addKey(i,g,{defaultValue:s}):t.getConditionalsThenElse(g).forEach(c=>{typeof c=="string"&&t.addKey(i,c,{defaultValue:s});});});});});}});}if(o.operations)for(let r of o.operations){if(r.type==="operationtoconvert"&&f){let l=E(r),a=await f(l,o,{});if(!a)return;r=a;}r.type==="text"&&r.operationType==="show"&&t.addKey(i,r.text,{defaultValue:s});}o.conditionalStep&&t.getConditionalsThenElse(o.conditionalStep).forEach(l=>{Array.isArray(l)?t.generateJsonTranslation(l,i,n):t.generateJsonTranslation([l],i,n);});});return await Promise.all(C),i}};m(t,"_beforeToTranslate"),m(t,"_translate",e=>e),m(t,"_afterToTranslate");var h=t;var L=h;export{L as translator};//# sourceMappingURL=translator.mjs.map
|
|
2
|
+
//# sourceMappingURL=translator.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/operationtoconvert.ts","../src/translator/TranslatorManager.ts","../src/translator/index.ts"],"names":["operationStringToString","operation","stringOperation","value","res","JsonUnifier","_TranslatorManager","key","k","text","json","options","defaultValue","data","element","tempRes","item","labels","operationStringConvert","promises","label","multichoices","c","choice","t","tt","dialogues","dialogue","ttt","__publicField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A,CCXA,IAAMyB,CAAAA,CAAaD","file":"translator.mjs","sourcesContent":["import { JsonUnifier } from \"@drincs/pixi-vn-json/core\";\nimport { PixiVNJsonOperationString } from \"../interface\";\n\nexport function operationStringToString(operation: PixiVNJsonOperationString): string {\n let stringOperation = \"\";\n operation.values.forEach((value) => {\n if (typeof value === \"string\") {\n stringOperation += value;\n } else {\n let res = JsonUnifier.getLogichValue<string>(value);\n stringOperation += `${res}`;\n }\n });\n return stringOperation;\n}\n","import type { StepLabelPropsType } from \"@drincs/pixi-vn\";\nimport {\n PixiVNJsonChoice,\n PixiVNJsonChoices,\n PixiVNJsonConditionalResultToCombine,\n PixiVNJsonConditionalStatements,\n PixiVNJsonDialog,\n PixiVNJsonDialogText,\n PixiVNJsonLabelStep,\n PixiVNJsonOperation,\n} from \"../interface\";\nimport { operationStringToString } from \"../utils/operationtoconvert\";\n\nexport default class TranslatorManager {\n private static _beforeToTranslate: ((key: string) => string) | undefined = undefined;\n private static _translate: (key: string) => string = (key: string) => key;\n private static _afterToTranslate: ((key: string) => string) | undefined = undefined;\n static t<T = string | string[]>(key: T): T {\n if (Array.isArray(key)) {\n return key.map((k?: string) => TranslatorManager.translate(`${k}`)) as T;\n }\n return TranslatorManager.translate(`${key}`) as T;\n }\n static set beforeToTranslate(value: (key: string) => string) {\n TranslatorManager._beforeToTranslate = value;\n }\n static set translate(value: (key: string) => string) {\n TranslatorManager._translate = value;\n }\n static get translate(): (key: string) => string {\n return (key: string) => {\n let text = key;\n if (TranslatorManager._beforeToTranslate) {\n text = TranslatorManager._beforeToTranslate(text);\n }\n text = TranslatorManager._translate(text);\n if (TranslatorManager._afterToTranslate) {\n text = TranslatorManager._afterToTranslate(text);\n }\n return text;\n };\n }\n static set afterToTranslate(value: (key: string) => string) {\n TranslatorManager._afterToTranslate = value;\n }\n\n private static addKey(\n json: any,\n key: string[] | string,\n options: {\n defaultValue: \"empty_string\" | \"copy_key\";\n }\n ) {\n let defaultValue = options.defaultValue || \"empty_string\";\n if (typeof key === \"string\") {\n key = [key];\n }\n if (Array.isArray(key)) {\n key.forEach((k) => {\n if (json[k] === undefined) {\n if (defaultValue === \"empty_string\") {\n json[k] = \"\";\n } else if (defaultValue === \"copy_key\") {\n if (TranslatorManager._beforeToTranslate) {\n json[k] = TranslatorManager._beforeToTranslate(k);\n } else {\n json[k] = k;\n }\n }\n }\n });\n }\n }\n private static getConditionalsThenElse<T>(\n data: PixiVNJsonConditionalStatements<T> | PixiVNJsonConditionalResultToCombine<T> | T,\n res: T[] = []\n ): T[] {\n if (typeof data === \"object\" && data && \"type\" in data) {\n if (data.type === \"ifelse\") {\n if (data.then) {\n TranslatorManager.getConditionalsThenElse(data.then, res);\n }\n if (data.else) {\n TranslatorManager.getConditionalsThenElse(data.else, res);\n }\n } else if (data.type === \"stepswitch\") {\n if (data.elements) {\n if (Array.isArray(data.elements)) {\n data.elements.forEach((element) => {\n TranslatorManager.getConditionalsThenElse(element, res);\n });\n } else {\n if (data.elements.type === \"ifelse\") {\n let tempRes: T[][] = [];\n TranslatorManager.getConditionalsThenElse(data.elements, tempRes);\n tempRes.forEach((item) => {\n res.push(...item);\n });\n } else if (data.elements.type === \"stepswitch\") {\n let tempRes: T[][] = [];\n TranslatorManager.getConditionalsThenElse(data.elements, tempRes);\n tempRes.forEach((item) => {\n res.push(...item);\n });\n } else {\n TranslatorManager.getConditionalsThenElse(data.elements, res);\n }\n }\n }\n } else if (data.type === \"resulttocombine\") {\n if (data.firstItem) {\n TranslatorManager.getConditionalsThenElse(data.firstItem, res);\n }\n if (data.secondConditionalItem) {\n data.secondConditionalItem.forEach((item) => {\n TranslatorManager.getConditionalsThenElse(item, res);\n });\n }\n } else {\n res.push(data);\n }\n } else if (data) {\n res.push(data);\n }\n return res;\n }\n\n /**\n * Generates a JSON translation object from the provided labels.\n * @param labels The labels to translate.\n * @param json The JSON object to populate with translations.\n * @param options Options for translation, including default value handling.\n * @returns The populated JSON object with translations.\n */\n static async generateJsonTranslation(\n labels: PixiVNJsonLabelStep[],\n json: object = {},\n options: {\n /**\n * Default value to use when a key is not found.\n * - \"empty_string\": Use an empty string as the default value.\n * - \"copy_key\": Use the key itself as the default value.\n * @default \"copy_key\"\n */\n defaultValue?: \"empty_string\" | \"copy_key\";\n operationStringConvert?: (\n value: string,\n step: PixiVNJsonLabelStep,\n props: StepLabelPropsType | {}\n ) => Promise<PixiVNJsonOperation | undefined>;\n } = {}\n ) {\n const { defaultValue = \"copy_key\", operationStringConvert } = options;\n let promises = labels.map(async (label) => {\n if (label.choices) {\n let multichoices: PixiVNJsonChoices[] = [];\n if (!Array.isArray(label.choices)) {\n multichoices = TranslatorManager.getConditionalsThenElse(label.choices);\n } else {\n multichoices = [label.choices];\n }\n multichoices.forEach((c) =>\n c.forEach((choice) => {\n if (\"type\" in choice) {\n let res: PixiVNJsonChoice[] = [];\n if (choice.type === \"ifelse\" || choice.type === \"stepswitch\") {\n TranslatorManager.getConditionalsThenElse(choice, res);\n } else {\n res = [choice];\n }\n let texts = res.map((item) => TranslatorManager.getConditionalsThenElse(item.text));\n texts.forEach((text) => {\n if (Array.isArray(text)) {\n text.forEach((t) => {\n if (Array.isArray(t)) {\n t.forEach((tt) => {\n if (typeof tt === \"string\") {\n TranslatorManager.addKey(json, tt, { defaultValue });\n } else {\n TranslatorManager.getConditionalsThenElse(tt).forEach((t) => {\n if (Array.isArray(t)) {\n t.forEach((tt) => {\n if (typeof tt === \"string\") {\n TranslatorManager.addKey(json, tt, {\n defaultValue,\n });\n }\n });\n } else if (typeof t === \"string\") {\n TranslatorManager.addKey(json, t, { defaultValue });\n }\n });\n }\n });\n } else if (typeof t === \"string\") {\n TranslatorManager.addKey(json, t, { defaultValue });\n }\n });\n }\n });\n }\n })\n );\n }\n if (label.dialogue) {\n let dialogues: PixiVNJsonDialog<PixiVNJsonDialogText>[] = [];\n if (!Array.isArray(label.dialogue)) {\n dialogues = TranslatorManager.getConditionalsThenElse(label.dialogue);\n } else {\n dialogues = [label.dialogue];\n }\n dialogues.forEach((dialogue) => {\n if (typeof dialogue === \"string\") {\n TranslatorManager.addKey(json, dialogue, { defaultValue });\n } else if (\"text\" in dialogue) {\n let text = TranslatorManager.getConditionalsThenElse(dialogue.text);\n if (typeof text === \"string\") {\n text = [text];\n }\n text.forEach((text) => {\n if (typeof text === \"string\") {\n TranslatorManager.addKey(json, text, { defaultValue });\n } else {\n let t = TranslatorManager.getConditionalsThenElse(text);\n t.forEach((tt) => {\n if (typeof tt === \"string\") {\n TranslatorManager.addKey(json, tt, { defaultValue });\n } else if (Array.isArray(tt)) {\n tt.forEach((ttt) => {\n if (typeof ttt === \"string\") {\n TranslatorManager.addKey(json, ttt, { defaultValue });\n } else {\n TranslatorManager.getConditionalsThenElse(ttt).forEach((t) => {\n if (typeof t === \"string\") {\n TranslatorManager.addKey(json, t, { defaultValue });\n }\n });\n }\n });\n }\n });\n }\n });\n }\n });\n }\n if (label.operations) {\n for (let operation of label.operations) {\n if (operation.type === \"operationtoconvert\" && operationStringConvert) {\n let stringOperation = operationStringToString(operation);\n let res = await operationStringConvert(stringOperation, label, {});\n if (!res) {\n return;\n }\n operation = res;\n }\n switch (operation.type) {\n case \"text\":\n switch (operation.operationType) {\n case \"show\":\n TranslatorManager.addKey(json, operation.text, { defaultValue });\n break;\n }\n break;\n }\n }\n }\n if (label.conditionalStep) {\n let l = TranslatorManager.getConditionalsThenElse(label.conditionalStep);\n l.forEach((item) => {\n if (Array.isArray(item)) {\n TranslatorManager.generateJsonTranslation(item, json, options);\n } else {\n TranslatorManager.generateJsonTranslation([item], json, options);\n }\n });\n }\n });\n await Promise.all(promises);\n return json;\n }\n}\n","import TranslateManager from \"./TranslatorManager\";\n\nconst translator = TranslateManager;\n\nexport { translator };\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@drincs/pixi-vn-json",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.0",
|
|
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",
|
|
@@ -66,15 +66,15 @@
|
|
|
66
66
|
"devDependencies": {
|
|
67
67
|
"@types/crypto-js": "^4.2.2",
|
|
68
68
|
"crypto-js": "^4.2.0",
|
|
69
|
-
"jsdom": "^
|
|
69
|
+
"jsdom": "^29.0.1",
|
|
70
70
|
"pixi.js": "^8.17.0",
|
|
71
71
|
"ts-node": "^10.9.2",
|
|
72
72
|
"tsup": "^8.5.1",
|
|
73
73
|
"typescript": "^5.9.3",
|
|
74
|
-
"vite-tsconfig-paths": "^6.
|
|
74
|
+
"vite-tsconfig-paths": "^6.1.1"
|
|
75
75
|
},
|
|
76
76
|
"peerDependencies": {
|
|
77
|
-
"@drincs/pixi-vn": ">=1.
|
|
77
|
+
"@drincs/pixi-vn": ">=1.6.0"
|
|
78
78
|
},
|
|
79
79
|
"keywords": [
|
|
80
80
|
"game",
|