@joplo-app/core 0.2.16 → 0.2.17
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/agent-skill.d.ts +1 -1
- package/dist/agent-skill.js +1 -1
- package/dist/compile.d.ts +3 -0
- package/dist/compile.js +105 -13
- package/dist/content-i18n.d.ts +34 -0
- package/dist/content-i18n.js +242 -0
- package/dist/feature-diff.d.ts +3 -3
- package/dist/guide.js +12 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/load.d.ts +9 -0
- package/dist/load.js +48 -1
- package/dist/schema.d.ts +30 -1
- package/dist/schema.js +19 -1
- package/dist/scope.js +11 -2
- package/package.json +2 -2
package/dist/agent-skill.d.ts
CHANGED
|
@@ -42,7 +42,7 @@ export declare const SKILL_TOPICS: readonly [{
|
|
|
42
42
|
readonly description: "Compare public feature builds, stable step identity, uncertain matches, isolated PR CI publication";
|
|
43
43
|
}, {
|
|
44
44
|
readonly name: "publish";
|
|
45
|
-
readonly description: "pick, build, share, review version, feedback write-back, deployment, chapters and phone viewing";
|
|
45
|
+
readonly description: "pick, build, share, review version, feedback write-back, deployment, chapters and phone viewing, viewers in several languages";
|
|
46
46
|
}];
|
|
47
47
|
/** 心智模型:所有入口最先读到的几句话。 */
|
|
48
48
|
export declare const MENTAL_MODEL: readonly ["Joplo turns a feature idea into a clickable, replayable demo. It is a player for pre-declared scenarios, not a free-form app prototype, and not a slide or PPT tool: you write the screens and scripted scenarios in TSX, the local board plays them step by step, and reviewers compare options and leave feedback.", "Structure: a project has features; a feature has options (alternative designs, A/B) and cases (edge cases to cover); an option plays scenarios; a scenario is a list of steps.", "A step is one user action (.click / .type / .select / .press) or system event plus its visible effects (set, toast, go, done). Results and errors come from these effects, not from real logic or a backend.", "Viewers advance by clicking the highlighted element (other clicks only show a hint). Inputs show the sample value the step types; viewers cannot type their own, but the board's native feedback panel accepts real reviewer text.", "Options and cases are compared in the local board; only the picked option is published."];
|
package/dist/agent-skill.js
CHANGED
|
@@ -19,7 +19,7 @@ export const SKILL_TOPICS = [
|
|
|
19
19
|
{ name: 'selection', description: 'Edit only the element selected by the user in the board' },
|
|
20
20
|
{ name: 'review', description: 'Local live feedback, Share polling, prompt acknowledgement, session/version isolation, and recovery' },
|
|
21
21
|
{ name: 'diff', description: 'Compare public feature builds, stable step identity, uncertain matches, isolated PR CI publication' },
|
|
22
|
-
{ name: 'publish', description: 'pick, build, share, review version, feedback write-back, deployment, chapters and phone viewing' },
|
|
22
|
+
{ name: 'publish', description: 'pick, build, share, review version, feedback write-back, deployment, chapters and phone viewing, viewers in several languages' },
|
|
23
23
|
];
|
|
24
24
|
/** 心智模型:所有入口最先读到的几句话。 */
|
|
25
25
|
export const MENTAL_MODEL = [
|
package/dist/compile.d.ts
CHANGED
|
@@ -24,6 +24,9 @@ export type AuthoringProject = {
|
|
|
24
24
|
}>;
|
|
25
25
|
/** 作者主题(D51):themes/<name>.css 的原文。 */
|
|
26
26
|
themes?: Record<string, string>;
|
|
27
|
+
/** 作者内容译文(D84):locales/<语言>.json 的内容(原文 → 译文);语言 → 文件相对路径见 localeFiles。 */
|
|
28
|
+
locales?: Record<string, Record<string, string>>;
|
|
29
|
+
localeFiles?: Record<string, string>;
|
|
27
30
|
};
|
|
28
31
|
export type CompileResult = {
|
|
29
32
|
project: Project | null;
|
package/dist/compile.js
CHANGED
|
@@ -13,6 +13,7 @@ import { HOLD_MAX_SECONDS, HOLD_MIN_SECONDS, inShotFrame } from "./focus.js";
|
|
|
13
13
|
import { choicesOf, commonPrefix } from "./player.js";
|
|
14
14
|
import { CALLOUT_SIDES, LAYER_ICONS, Project, SCHEMA_VERSION } from "./schema.js";
|
|
15
15
|
import { schemaDiagnostics } from "./schema-issues.js";
|
|
16
|
+
import { CONTENT_LOCALES, collectMessages, isContentLocale, nearestKey, pruneMessages } from "./content-i18n.js";
|
|
16
17
|
import { DIAGRAM_GROUP_ICONS, DIAGRAM_NODE_KINDS, DIAGRAM_PINS, DIAGRAM_TONES, GRAPH_FAMILY, SEQUENCE_BLOCK_KINDS, SEQUENCE_FAMILY, attachLayouts, diagramsIn, isDiagramRoot } from "./diagram/index.js";
|
|
17
18
|
const KNOWN = new Set(COMPONENT_TYPES);
|
|
18
19
|
const OVERLAY = 'overlay';
|
|
@@ -208,7 +209,10 @@ export function compile(src, mode, opts = {}) {
|
|
|
208
209
|
return { id: sceneId, optionId: ctx?.qid ?? null, route: route.path, name: `${page.title}${ctx ? ` · ${ctx.def.name}` : ''}`, viewport: page.viewport ?? 'desktop', root };
|
|
209
210
|
};
|
|
210
211
|
if (src.config.voice !== undefined && !voiceConfigOf(src.config.voice, true))
|
|
211
|
-
err('VOICE_CONFIG_INVALID', `config({ voice }) must be { profile?: string, narrator?: string, roles?: { [roleKey]: string } } with non-empty strings; got ${JSON.stringify(src.config.voice)}`, src.config.source ?? `${src.config.file}:1:1`);
|
|
212
|
+
err('VOICE_CONFIG_INVALID', `config({ voice }) must be { profile?: string, narrator?: string, roles?: { [roleKey]: string }, locales?: { [locale]: { narrator?: string, roles?: { [roleKey]: string } } } } with non-empty strings; got ${JSON.stringify(src.config.voice)}`, src.config.source ?? `${src.config.file}:1:1`);
|
|
213
|
+
const i18nCfg = contentLocalesOf(src, err);
|
|
214
|
+
if (i18nCfg)
|
|
215
|
+
out.i18n = { default: i18nCfg[0], locales: i18nCfg, messages: Object.fromEntries(i18nCfg.slice(1).map((l) => [l, Object.fromEntries(Object.entries(src.locales?.[l] ?? {}).filter(([, v]) => typeof v === 'string' && v.trim()))])) };
|
|
212
216
|
if (src.config.autoFocus !== undefined && typeof src.config.autoFocus !== 'boolean')
|
|
213
217
|
err('AUTOFOCUS_INVALID', `config({ autoFocus }) must be true or false (default true); got ${JSON.stringify(src.config.autoFocus)}`, src.config.source ?? `${src.config.file}:1:1`);
|
|
214
218
|
// 主题(D51):config.theme 必须是内置主题或 themes/<name>.css
|
|
@@ -716,7 +720,73 @@ export function compile(src, mode, opts = {}) {
|
|
|
716
720
|
diags.push(...schemaDiagnostics(out, parsed.error.issues, { limit: 20, rel }));
|
|
717
721
|
return { project: null, diagnostics: diags };
|
|
718
722
|
}
|
|
719
|
-
|
|
723
|
+
const project = pruneMessages(parsed.data);
|
|
724
|
+
if (mode === 'dev' && project.i18n) {
|
|
725
|
+
const stale = localeDiagnostics(project, src, diags);
|
|
726
|
+
project.i18n = { ...project.i18n, stale };
|
|
727
|
+
}
|
|
728
|
+
return { project, diagnostics: diags };
|
|
729
|
+
}
|
|
730
|
+
/** config.locales(D84):非空、不重复、都是支持的语言;第一个是默认语言。没写时为 null。 */
|
|
731
|
+
function contentLocalesOf(src, err) {
|
|
732
|
+
const v = src.config.locales;
|
|
733
|
+
const at = src.config.source ?? `${src.config.file}:1:1`;
|
|
734
|
+
if (v === undefined) {
|
|
735
|
+
for (const [l, f] of Object.entries(src.localeFiles ?? {}))
|
|
736
|
+
err('LOCALES_UNDECLARED', `${f} exists but joplo.config.ts has no locales; add locales: ['<source language>', '${l}'] (the first is the language the source files are written in)`, at);
|
|
737
|
+
return null;
|
|
738
|
+
}
|
|
739
|
+
const bad = !Array.isArray(v) || !v.length ? 'must be a non-empty array' : v.find((x) => !isContentLocale(x)) !== undefined ? `contains "${String(v.find((x) => !isContentLocale(x)))}"` : new Set(v).size !== v.length ? 'lists a language twice' : null;
|
|
740
|
+
if (bad) {
|
|
741
|
+
err('LOCALES_INVALID', `config({ locales }) ${bad}. Write the source language first, for example locales: ['zh-CN', 'en', 'ja']; supported: ${CONTENT_LOCALES.join(', ')}`, at);
|
|
742
|
+
return null;
|
|
743
|
+
}
|
|
744
|
+
for (const [l, f] of Object.entries(src.localeFiles ?? {}))
|
|
745
|
+
if (!v.includes(l))
|
|
746
|
+
err('LOCALES_UNDECLARED', `${f} is not in config({ locales }); add '${l}' to locales or delete the file`, at);
|
|
747
|
+
if (src.localeFiles?.[v[0]])
|
|
748
|
+
err('LOCALES_UNDECLARED', `${src.localeFiles[v[0]]} translates the default language ${v[0]}; the source files are already in ${v[0]}, so delete it (or put another language first in locales)`, at);
|
|
749
|
+
return [...v];
|
|
750
|
+
}
|
|
751
|
+
/**
|
|
752
|
+
* 译文的检查(D84,只在 dev):每种语言一条 I18N_MISSING(缺多少、前几条)、原文改过的每条一条 I18N_STALE(附最接近的旧条目)、
|
|
753
|
+
* 没人用的旧条目一条 I18N_UNUSED。返回每种语言的过期条数,给看板菜单显示。
|
|
754
|
+
*/
|
|
755
|
+
function localeDiagnostics(project, src, diags) {
|
|
756
|
+
const i18n = project.i18n;
|
|
757
|
+
const uses = collectMessages(project);
|
|
758
|
+
const texts = new Set(uses.map((u) => u.text));
|
|
759
|
+
const stale = {};
|
|
760
|
+
const q = (s) => JSON.stringify(s.length > 40 ? `${s.slice(0, 40)}…` : s);
|
|
761
|
+
for (const l of i18n.locales.slice(1)) {
|
|
762
|
+
const file = src.localeFiles?.[l] ?? `locales/${l}.json`;
|
|
763
|
+
const table = src.locales?.[l] ?? {};
|
|
764
|
+
const unused = Object.keys(table).filter((k) => !texts.has(k) && typeof table[k] === 'string' && table[k].trim());
|
|
765
|
+
const missing = uses.filter((u) => !(typeof table[u.text] === 'string' && table[u.text].trim()));
|
|
766
|
+
const plain = [];
|
|
767
|
+
const matched = new Set();
|
|
768
|
+
let n = 0;
|
|
769
|
+
for (const m of missing) {
|
|
770
|
+
const old = nearestKey(m.text, unused);
|
|
771
|
+
if (old === null) {
|
|
772
|
+
plain.push(m);
|
|
773
|
+
continue;
|
|
774
|
+
}
|
|
775
|
+
matched.add(old);
|
|
776
|
+
n++;
|
|
777
|
+
diags.push({ severity: 'warning', code: 'I18N_STALE', message: `${file}: no translation for ${q(m.text)}; the closest old entry is ${q(old)}: ${q(table[old])} (the source text changed). Update the key and translation`, source: 'structure', ...(m.at ? { at: m.at } : {}) });
|
|
778
|
+
}
|
|
779
|
+
stale[l] = n;
|
|
780
|
+
if (plain.length) {
|
|
781
|
+
const first = plain.slice(0, 5).map((m) => q(m.text)).join(', ');
|
|
782
|
+
const hint = src.localeFiles?.[l] ? `translate them in ${file}` : `run npx joplo i18n add ${l}, then translate ${file}`;
|
|
783
|
+
diags.push({ severity: 'warning', code: 'I18N_MISSING', message: `${l}: ${plain.length} of ${uses.length} texts have no translation (${first}${plain.length > 5 ? `, +${plain.length - 5} more` : ''}); ${hint}. Viewers see the ${i18n.default} source text for them`, source: 'structure', at: `${file}:1:1` });
|
|
784
|
+
}
|
|
785
|
+
const leftover = unused.filter((k) => !matched.has(k));
|
|
786
|
+
if (leftover.length)
|
|
787
|
+
diags.push({ severity: 'info', code: 'I18N_UNUSED', message: `${file}: ${leftover.length} entries are not used by any text (${leftover.slice(0, 3).map(q).join(', ')}${leftover.length > 3 ? ', …' : ''}); delete them or run npx joplo i18n add ${l} --prune`, source: 'structure', at: `${file}:1:1` });
|
|
788
|
+
}
|
|
789
|
+
return stale;
|
|
720
790
|
}
|
|
721
791
|
// ---------- 帮助函数 ----------
|
|
722
792
|
/** 角色的颜色(D56):没写 color 时按声明顺序取。 */
|
|
@@ -1181,24 +1251,46 @@ function voiceConfigOf(v, strict = false) {
|
|
|
1181
1251
|
const o = v;
|
|
1182
1252
|
const str = (x) => (typeof x === 'string' && x.trim() ? x.trim() : null);
|
|
1183
1253
|
for (const k of Object.keys(o))
|
|
1184
|
-
if (!['profile', 'narrator', 'roles'].includes(k))
|
|
1254
|
+
if (!['profile', 'narrator', 'roles', 'locales'].includes(k))
|
|
1185
1255
|
return null;
|
|
1186
1256
|
if (o.profile !== undefined && !str(o.profile))
|
|
1187
1257
|
return null;
|
|
1188
|
-
|
|
1258
|
+
/** 旁白与角色(顶层,或某种语言下);形状不对时返回 false。 */
|
|
1259
|
+
const voices = (x) => {
|
|
1260
|
+
if (x.narrator !== undefined && !str(x.narrator))
|
|
1261
|
+
return false;
|
|
1262
|
+
let roles;
|
|
1263
|
+
if (x.roles !== undefined) {
|
|
1264
|
+
if (!x.roles || typeof x.roles !== 'object' || Array.isArray(x.roles))
|
|
1265
|
+
return false;
|
|
1266
|
+
roles = {};
|
|
1267
|
+
for (const [k, val] of Object.entries(x.roles)) {
|
|
1268
|
+
const s = str(val);
|
|
1269
|
+
if (!s)
|
|
1270
|
+
return false;
|
|
1271
|
+
roles[k] = s;
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
return { ...(str(x.narrator) ? { narrator: str(x.narrator) } : {}), ...(roles && Object.keys(roles).length ? { roles } : {}) };
|
|
1275
|
+
};
|
|
1276
|
+
const top = voices(o);
|
|
1277
|
+
if (!top)
|
|
1189
1278
|
return null;
|
|
1190
|
-
let
|
|
1191
|
-
if (o.
|
|
1192
|
-
if (!o.
|
|
1279
|
+
let locales;
|
|
1280
|
+
if (o.locales !== undefined) {
|
|
1281
|
+
if (!o.locales || typeof o.locales !== 'object' || Array.isArray(o.locales))
|
|
1193
1282
|
return null;
|
|
1194
|
-
|
|
1195
|
-
for (const [
|
|
1196
|
-
|
|
1197
|
-
|
|
1283
|
+
locales = {};
|
|
1284
|
+
for (const [l, x] of Object.entries(o.locales)) {
|
|
1285
|
+
if (!x || typeof x !== 'object' || Array.isArray(x) || Object.keys(x).some((k) => k !== 'narrator' && k !== 'roles'))
|
|
1286
|
+
return null;
|
|
1287
|
+
const vv = voices(x);
|
|
1288
|
+
if (!vv)
|
|
1198
1289
|
return null;
|
|
1199
|
-
|
|
1290
|
+
if (Object.keys(vv).length)
|
|
1291
|
+
locales[l] = vv;
|
|
1200
1292
|
}
|
|
1201
1293
|
}
|
|
1202
|
-
const out = { ...(str(o.profile) ? { profile: str(o.profile) } : {}), ...
|
|
1294
|
+
const out = { ...(str(o.profile) ? { profile: str(o.profile) } : {}), ...top, ...(locales && Object.keys(locales).length ? { locales } : {}) };
|
|
1203
1295
|
return Object.keys(out).length ? out : strict ? out : null;
|
|
1204
1296
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 作者内容多语言(D84):源文件用默认语言写,译文放在 `locales/<语言>.json`(原文 → 译文)。
|
|
3
|
+
*
|
|
4
|
+
* - 编译时把译文放进 IR 的 `i18n.messages`(只留这份 IR 用得到的条目,见 pruneMessages),默认语言没有译文表。
|
|
5
|
+
* - 看板、发布站、服务端都用 localizeProject 把整份 IR 换成某种语言:同一个原文在任何位置都换成同一个译文,
|
|
6
|
+
* 所以状态值与条件里的同一个字面量一起换,比较结果不变;结构字段(id、路径、连线两端、颜色等)从不翻译。
|
|
7
|
+
* - collectMessages 列出这份 IR 里要翻译的原文(joplo i18n add 与 check 用)。状态里的字符串只收显示出来的
|
|
8
|
+
* (路径和某个绑定重叠),输入值与状态值跳过像代码的单个 ASCII 词(id、邮箱、网址)。
|
|
9
|
+
* - 内容语言只能是界面支持的 10 种(D57),观众选界面语言就是选内容语言;项目没有这种语言时退回默认语言。
|
|
10
|
+
*/
|
|
11
|
+
import type { Project } from './schema.js';
|
|
12
|
+
/** 内容语言 = 界面支持的 10 种语言(与网页、服务端的 locale 列表一致)。 */
|
|
13
|
+
export declare const CONTENT_LOCALES: readonly ["en", "zh-CN", "zh-TW", "ja", "ko", "es", "fr", "de", "pt-BR", "ru"];
|
|
14
|
+
export type ContentLocale = (typeof CONTENT_LOCALES)[number];
|
|
15
|
+
export declare const isContentLocale: (v: unknown) => v is ContentLocale;
|
|
16
|
+
export type ContentI18n = {
|
|
17
|
+
default: string;
|
|
18
|
+
locales: string[];
|
|
19
|
+
messages: Record<string, Record<string, string>>;
|
|
20
|
+
};
|
|
21
|
+
export type MessageUse = {
|
|
22
|
+
text: string;
|
|
23
|
+
at?: string;
|
|
24
|
+
};
|
|
25
|
+
/** 这份 IR 里要翻译的原文(去重,按首次出现的顺序;at 是第一次出现的源位置)。 */
|
|
26
|
+
export declare function collectMessages(p: Project): MessageUse[];
|
|
27
|
+
/** 把 IR 换成某种语言;没有 i18n、语言是默认语言或没有译文表时原样返回。 */
|
|
28
|
+
export declare function localizeProject(p: Project, locale: string | null | undefined): Project;
|
|
29
|
+
/** 观众的界面语言对应的内容语言:项目有这种语言就用它,否则退回默认语言(用户 2026-11-08 选定)。没有 i18n 时为 null。 */
|
|
30
|
+
export declare function contentLocaleFor(p: Pick<Project, 'i18n'>, uiLocale: string | null | undefined): string | null;
|
|
31
|
+
/** 只留这份 IR 用得到的译文(编译、范围分享之后调用,不带别的功能的文字)。 */
|
|
32
|
+
export declare function pruneMessages(p: Project): Project;
|
|
33
|
+
/** 最接近的旧条目(原文改过时给 check 提示):编辑距离不超过较长一方的一半;没有时为 null。 */
|
|
34
|
+
export declare function nearestKey(text: string, candidates: readonly string[]): string | null;
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
/** 内容语言 = 界面支持的 10 种语言(与网页、服务端的 locale 列表一致)。 */
|
|
2
|
+
export const CONTENT_LOCALES = ['en', 'zh-CN', 'zh-TW', 'ja', 'ko', 'es', 'fr', 'de', 'pt-BR', 'ru'];
|
|
3
|
+
export const isContentLocale = (v) => typeof v === 'string' && CONTENT_LOCALES.includes(v);
|
|
4
|
+
const BIND = /^\$(ui|data|inputs)(\.|$)/;
|
|
5
|
+
const isBinding = (s) => BIND.test(s);
|
|
6
|
+
/** 不翻译的属性:引用、样式与枚举。值是字符串时也原样保留。 */
|
|
7
|
+
const STRUCTURAL = new Set(['from', 'to', 'accessor', 'target', 'href', 'src', 'type', 'kind', 'tone', 'variant', 'color', 'c', 'bg', 'size', 'radius', 'position', 'direction', 'icon', 'pin', 'states', 'style', 'layout', 'orientation', 'align', 'justify', 'ff', 'fw', 'fz', 'ta', 'shadow', 'dir', 'lang', 'id', 'key', 'side', 'tt', 'td', 'fs', 'lh', 'display', 'pos', 'inset', 'top', 'left', 'right', 'bottom',
|
|
8
|
+
'p', 'px', 'py', 'pt', 'pb', 'pl', 'pr', 'm', 'mx', 'my', 'mt', 'mb', 'ml', 'mr', 'w', 'h', 'maw', 'mah', 'miw', 'mih', 'gap', 'rowGap', 'columnGap', 'gutter', 'spacing', 'verticalSpacing', 'horizontalSpacing',
|
|
9
|
+
'cols', 'span', 'offset', 'order', 'wrap', 'grow', 'mode', 'aspect', 'fit', 'inputMode', 'autoComplete', 'visibleFrom', 'hiddenFrom', 'transition', 'transitionProps', 'loaderProps', 'overlayProps', 'zIndex', 'opacity']);
|
|
10
|
+
/** 选项、列表项(数组里的对象)的 value 是选项的身份:照常按同一张表换(和状态值、选择动作的值一致),但收集时当作普通属性(像 id 的单词不收)。 */
|
|
11
|
+
const ITEM_VALUE = 'value';
|
|
12
|
+
/** 显示文字的属性:收集时不跳过单个英文词(英文项目的按钮名就是一个词)。其余属性里的单个 ASCII 词多半是枚举(sm、blue),不收。 */
|
|
13
|
+
const DISPLAY_PROPS = new Set(['text', 'label', 'title', 'description', 'placeholder', 'aria-label', 'alt', 'error', 'hint', 'caption', 'message', 'content', 'subtitle', 'tooltip', 'leftSection', 'rightSection', 'name', 'value', 'data', 'records', 'labels', 'emptyText', 'actionLabel', 'sub', 'badge', 'status', 'items']);
|
|
14
|
+
/** 每一行都是邮箱或网址:不翻译。 */
|
|
15
|
+
const addressLike = (s) => s.split('\n').every((l) => /^\s*([^\s@]+@[^\s@]+|https?:\/\/\S+)\s*$/.test(l));
|
|
16
|
+
/** 有没有字母(任何文字):纯数字、符号不翻译。 */
|
|
17
|
+
const hasLetter = (s) => /\p{L}/u.test(s);
|
|
18
|
+
/** 像代码的单个 ASCII 词:id、邮箱、网址、命令参数。只对状态值和输入值跳过。 */
|
|
19
|
+
const codeLike = (s) => /^[\x21-\x7e]+$/.test(s.trim());
|
|
20
|
+
function mapDeep(v, visit, path, inItem = false, itemValue = false) {
|
|
21
|
+
if (typeof v === 'string')
|
|
22
|
+
return isBinding(v) ? v : visit(v, path, itemValue);
|
|
23
|
+
if (Array.isArray(v))
|
|
24
|
+
return v.map((x, i) => mapDeep(x, visit, `${path}.${i}`, true));
|
|
25
|
+
if (v && typeof v === 'object') {
|
|
26
|
+
const out = {};
|
|
27
|
+
for (const [k, x] of Object.entries(v))
|
|
28
|
+
out[k] = STRUCTURAL.has(k) ? x : mapDeep(x, visit, `${path}.${k}`, false, inItem && k === ITEM_VALUE);
|
|
29
|
+
return out;
|
|
30
|
+
}
|
|
31
|
+
return v;
|
|
32
|
+
}
|
|
33
|
+
function mapCondition(c, visit) {
|
|
34
|
+
if (!c)
|
|
35
|
+
return c;
|
|
36
|
+
if ('eq' in c)
|
|
37
|
+
return { eq: [c.eq[0], mapDeep(c.eq[1], (s) => visit(s, 'state'), '')] };
|
|
38
|
+
if ('neq' in c)
|
|
39
|
+
return { neq: [c.neq[0], mapDeep(c.neq[1], (s) => visit(s, 'state'), '')] };
|
|
40
|
+
if ('in' in c)
|
|
41
|
+
return { in: [c.in[0], c.in[1].map((x) => mapDeep(x, (s) => visit(s, 'state'), ''))] };
|
|
42
|
+
if ('and' in c)
|
|
43
|
+
return { and: c.and.map((x) => mapCondition(x, visit)) };
|
|
44
|
+
if ('or' in c)
|
|
45
|
+
return { or: c.or.map((x) => mapCondition(x, visit)) };
|
|
46
|
+
if ('not' in c)
|
|
47
|
+
return { not: mapCondition(c.not, visit) };
|
|
48
|
+
return c;
|
|
49
|
+
}
|
|
50
|
+
function mapNode(n, visit) {
|
|
51
|
+
const out = { ...n };
|
|
52
|
+
if (n.props) {
|
|
53
|
+
const props = {};
|
|
54
|
+
for (const [k, v] of Object.entries(n.props))
|
|
55
|
+
props[k] = STRUCTURAL.has(k) ? v : mapDeep(v, (s, _p, itemValue) => visit(s, DISPLAY_PROPS.has(k) && !itemValue ? 'text' : 'prop', n.source), '');
|
|
56
|
+
out.props = props;
|
|
57
|
+
}
|
|
58
|
+
if (n.children)
|
|
59
|
+
out.children = n.children.map((c) => mapNode(c, visit));
|
|
60
|
+
if (n.when)
|
|
61
|
+
out.when = mapCondition(n.when, visit);
|
|
62
|
+
if (n.disabled && typeof n.disabled === 'object')
|
|
63
|
+
out.disabled = mapCondition(n.disabled, visit);
|
|
64
|
+
if (n.redact && typeof n.redact === 'object')
|
|
65
|
+
out.redact = mapCondition(n.redact, visit);
|
|
66
|
+
if (n.disabledReason && !isBinding(n.disabledReason))
|
|
67
|
+
out.disabledReason = visit(n.disabledReason, 'text', n.source);
|
|
68
|
+
// 设计备注(看板检查元素时显示;发布站没有)
|
|
69
|
+
if (n.note)
|
|
70
|
+
out.note = visit(n.note, 'text', n.source);
|
|
71
|
+
return out;
|
|
72
|
+
}
|
|
73
|
+
const t = (s, visit, at) => (s ? visit(s, 'text', at) : s);
|
|
74
|
+
const stateMap = (v, base, visit) => mapDeep(v, (s, p) => visit(s, 'state', undefined, `${base}${p}`), '');
|
|
75
|
+
function mapStep(st, visit) {
|
|
76
|
+
const at = st.source;
|
|
77
|
+
const a = st.action;
|
|
78
|
+
const action = a.type === 'card' ? { ...a, title: visit(a.title, 'text', at), ...(a.sub ? { sub: visit(a.sub, 'text', at) } : {}), ...(a.points ? { points: a.points.map((p) => visit(p, 'text', at)) } : {}) }
|
|
79
|
+
: a.type === 'type' || a.type === 'select' ? { ...a, value: visit(a.value, 'typed', at) }
|
|
80
|
+
: a.type === 'event' ? { ...a, name: visit(a.name, 'text', at) }
|
|
81
|
+
: a;
|
|
82
|
+
const effects = st.effects.map((e) => {
|
|
83
|
+
if (e.type === 'set' || e.type === 'append')
|
|
84
|
+
return { ...e, value: stateMap(e.value, e.path, visit) };
|
|
85
|
+
if (e.type === 'stream')
|
|
86
|
+
return { ...e, value: visit(e.value, 'text', at) };
|
|
87
|
+
if (e.type === 'toast' || e.type === 'complete')
|
|
88
|
+
return { ...e, text: visit(e.text, 'text', at) };
|
|
89
|
+
return e;
|
|
90
|
+
});
|
|
91
|
+
return {
|
|
92
|
+
...st,
|
|
93
|
+
action,
|
|
94
|
+
// 自动字幕是英文兜底,网页按 captionAuto 生成;只换它引用的元素名和值
|
|
95
|
+
caption: st.captionAuto ? st.caption : visit(st.caption, 'text', at),
|
|
96
|
+
...(st.captionAuto ? { captionAuto: { ...st.captionAuto, label: visit(st.captionAuto.label, 'state'), ...(st.captionAuto.value !== undefined ? { value: visit(st.captionAuto.value, 'state') } : {}) } } : {}),
|
|
97
|
+
effects,
|
|
98
|
+
...(st.explain ? { explain: visit(st.explain, 'text', at) } : {}),
|
|
99
|
+
...(st.say ? { say: visit(st.say, 'text', at) } : {}),
|
|
100
|
+
...(st.narrate ? { narrate: visit(st.narrate, 'text', at) } : {}),
|
|
101
|
+
...(st.callouts ? { callouts: st.callouts.map((c) => ({ ...c, text: visit(c.text, 'text', at) })) } : {}),
|
|
102
|
+
marks: st.marks.map((m) => (m.note ? { ...m, note: visit(m.note, 'text', at) } : m)),
|
|
103
|
+
forks: st.forks.map((f) => ({ ...f, label: visit(f.label, 'text', at) })),
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function mapScenario(sc, visit) {
|
|
107
|
+
const at = sc.source;
|
|
108
|
+
return {
|
|
109
|
+
...sc,
|
|
110
|
+
name: visit(sc.name, 'text', at),
|
|
111
|
+
description: t(sc.description, visit, at) ?? '',
|
|
112
|
+
...(sc.expected !== undefined ? { expected: t(sc.expected, visit, at) ?? '' } : {}),
|
|
113
|
+
mock: sc.mock.auto ? sc.mock : { ...sc.mock, label: visit(sc.mock.label, 'text', at) },
|
|
114
|
+
initial: { ...sc.initial, ui: stateMap(sc.initial.ui, 'ui', visit), data: stateMap(sc.initial.data, 'data', visit), inputs: stateMap(sc.initial.inputs, 'inputs', visit) },
|
|
115
|
+
steps: sc.steps.map((st) => mapStep(st, visit)),
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
/** 对 IR 里所有作者内容字符串调用 visit,返回替换后的新 IR(不改原对象)。 */
|
|
119
|
+
function mapProject(p, visit) {
|
|
120
|
+
// 缺字段(旧 IR、测试里的最小 IR)原样保留,不补空对象
|
|
121
|
+
const obj = (o, f) => (o ? Object.fromEntries(Object.entries(o).map(([k, v]) => [k, f(v)])) : o);
|
|
122
|
+
const arr = (a, f) => (a ? a.map(f) : a);
|
|
123
|
+
return {
|
|
124
|
+
...p,
|
|
125
|
+
name: visit(p.name, 'text'),
|
|
126
|
+
description: t(p.description, visit) ?? '',
|
|
127
|
+
routes: obj(p.routes, (r) => ({ ...r, title: visit(r.title, 'text', r.source) })),
|
|
128
|
+
features: obj(p.features, (f) => ({ ...f, name: visit(f.name, 'text', f.source), goal: visit(f.goal, 'text', f.source), roles: arr(f.roles, (r) => ({ ...r, name: visit(r.name, 'text', f.source), ...(r.desc ? { desc: visit(r.desc, 'text', f.source) } : {}) })), constraints: arr(f.constraints, (c) => ({ ...c, text: visit(c.text, 'text', f.source) })) })),
|
|
129
|
+
options: obj(p.options, (o) => ({
|
|
130
|
+
...o,
|
|
131
|
+
name: visit(o.name, 'text', o.source),
|
|
132
|
+
idea: visit(o.idea, 'text', o.source),
|
|
133
|
+
...(o.decisionFocus !== undefined ? { decisionFocus: t(o.decisionFocus, visit, o.source) ?? '' } : {}),
|
|
134
|
+
tradeoffs: arr(o.tradeoffs, (x) => visit(x, 'text', o.source)),
|
|
135
|
+
coverage: obj(o.coverage, (c) => (c.reason ? { ...c, reason: visit(c.reason, 'text', o.source) } : c)),
|
|
136
|
+
layers: obj(o.layers, (l) => ({ ...l, title: visit(l.title, 'text', o.source) })),
|
|
137
|
+
})),
|
|
138
|
+
// 创作侧信息(看板与评审里显示;发布站不带,所以发布 IR 里收不到也不带译文)
|
|
139
|
+
cases: obj(p.cases, (c) => ({ ...c, title: visit(c.title, 'text', c.source), expected: t(c.expected, visit, c.source) ?? '' })),
|
|
140
|
+
rules: obj(p.rules, (r) => ({ ...r, text: visit(r.text, 'text', r.source) })),
|
|
141
|
+
issues: obj(p.issues, (q) => ({ ...q, text: visit(q.text, 'text', q.source) })),
|
|
142
|
+
scenes: obj(p.scenes, (s) => ({ ...s, root: mapNode(s.root, visit) })),
|
|
143
|
+
scenarios: obj(p.scenarios, (s) => mapScenario(s, visit)),
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
/** 画面里显示出来的状态路径(文字、属性、禁用原因里的绑定)。 */
|
|
147
|
+
function boundPaths(p) {
|
|
148
|
+
const out = new Set();
|
|
149
|
+
const add = (s) => {
|
|
150
|
+
if (isBinding(s))
|
|
151
|
+
out.add(s.slice(1));
|
|
152
|
+
};
|
|
153
|
+
const walk = (v) => {
|
|
154
|
+
if (typeof v === 'string')
|
|
155
|
+
add(v);
|
|
156
|
+
else if (Array.isArray(v))
|
|
157
|
+
v.forEach(walk);
|
|
158
|
+
else if (v && typeof v === 'object')
|
|
159
|
+
Object.values(v).forEach(walk);
|
|
160
|
+
};
|
|
161
|
+
const node = (n) => {
|
|
162
|
+
if (n.props)
|
|
163
|
+
for (const [k, v] of Object.entries(n.props))
|
|
164
|
+
if (k !== 'style')
|
|
165
|
+
walk(v);
|
|
166
|
+
if (n.disabledReason)
|
|
167
|
+
add(n.disabledReason);
|
|
168
|
+
n.children?.forEach(node);
|
|
169
|
+
};
|
|
170
|
+
for (const s of Object.values(p.scenes))
|
|
171
|
+
node(s.root);
|
|
172
|
+
return [...out];
|
|
173
|
+
}
|
|
174
|
+
const overlaps = (a, b) => a === b || a.startsWith(`${b}.`) || b.startsWith(`${a}.`);
|
|
175
|
+
/** 这份 IR 里要翻译的原文(去重,按首次出现的顺序;at 是第一次出现的源位置)。 */
|
|
176
|
+
export function collectMessages(p) {
|
|
177
|
+
const shown = boundPaths(p);
|
|
178
|
+
const seen = new Map();
|
|
179
|
+
mapProject(p, (s, kind, at, path) => {
|
|
180
|
+
const text = s;
|
|
181
|
+
if (!text.trim() || !hasLetter(text) || addressLike(text) || seen.has(text))
|
|
182
|
+
return s;
|
|
183
|
+
if (kind === 'state' && (!path || codeLike(text) || !shown.some((b) => overlaps(b, path))))
|
|
184
|
+
return s;
|
|
185
|
+
if ((kind === 'typed' || kind === 'prop') && codeLike(text))
|
|
186
|
+
return s;
|
|
187
|
+
seen.set(text, { text, ...(at ? { at } : {}) });
|
|
188
|
+
return s;
|
|
189
|
+
});
|
|
190
|
+
return [...seen.values()];
|
|
191
|
+
}
|
|
192
|
+
/** 把 IR 换成某种语言;没有 i18n、语言是默认语言或没有译文表时原样返回。 */
|
|
193
|
+
export function localizeProject(p, locale) {
|
|
194
|
+
const i18n = p.i18n;
|
|
195
|
+
if (!i18n || !locale || locale === i18n.default)
|
|
196
|
+
return p;
|
|
197
|
+
const table = i18n.messages[locale];
|
|
198
|
+
if (!table || !Object.keys(table).length)
|
|
199
|
+
return p;
|
|
200
|
+
return mapProject(p, (s) => (Object.hasOwn(table, s) && table[s] ? table[s] : s));
|
|
201
|
+
}
|
|
202
|
+
/** 观众的界面语言对应的内容语言:项目有这种语言就用它,否则退回默认语言(用户 2026-11-08 选定)。没有 i18n 时为 null。 */
|
|
203
|
+
export function contentLocaleFor(p, uiLocale) {
|
|
204
|
+
const i18n = p.i18n;
|
|
205
|
+
if (!i18n)
|
|
206
|
+
return null;
|
|
207
|
+
return uiLocale && i18n.locales.includes(uiLocale) ? uiLocale : i18n.default;
|
|
208
|
+
}
|
|
209
|
+
/** 只留这份 IR 用得到的译文(编译、范围分享之后调用,不带别的功能的文字)。 */
|
|
210
|
+
export function pruneMessages(p) {
|
|
211
|
+
if (!p.i18n)
|
|
212
|
+
return p;
|
|
213
|
+
const used = new Set(collectMessages(p).map((m) => m.text));
|
|
214
|
+
const messages = Object.fromEntries(Object.entries(p.i18n.messages).map(([l, table]) => [l, Object.fromEntries(Object.entries(table).filter(([k, v]) => used.has(k) && v))]));
|
|
215
|
+
return { ...p, i18n: { ...p.i18n, messages } };
|
|
216
|
+
}
|
|
217
|
+
/** 编辑距离(按码点)。 */
|
|
218
|
+
function distance(a, b) {
|
|
219
|
+
const x = [...a], y = [...b];
|
|
220
|
+
let prev = Array.from({ length: y.length + 1 }, (_, j) => j);
|
|
221
|
+
for (let i = 1; i <= x.length; i++) {
|
|
222
|
+
const cur = [i];
|
|
223
|
+
for (let j = 1; j <= y.length; j++)
|
|
224
|
+
cur[j] = Math.min(prev[j] + 1, cur[j - 1] + 1, prev[j - 1] + (x[i - 1] === y[j - 1] ? 0 : 1));
|
|
225
|
+
prev = cur;
|
|
226
|
+
}
|
|
227
|
+
return prev[y.length];
|
|
228
|
+
}
|
|
229
|
+
/** 最接近的旧条目(原文改过时给 check 提示):编辑距离不超过较长一方的一半;没有时为 null。 */
|
|
230
|
+
export function nearestKey(text, candidates) {
|
|
231
|
+
let best = null;
|
|
232
|
+
let bestD = Infinity;
|
|
233
|
+
for (const c of candidates) {
|
|
234
|
+
const d = distance(text, c);
|
|
235
|
+
const limit = Math.max([...text].length, [...c].length) / 2;
|
|
236
|
+
if (d <= limit && d < bestD) {
|
|
237
|
+
best = c;
|
|
238
|
+
bestD = d;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return best;
|
|
242
|
+
}
|
package/dist/feature-diff.d.ts
CHANGED
|
@@ -29,8 +29,8 @@ export declare const DiffStep: z.ZodObject<{
|
|
|
29
29
|
action: "action";
|
|
30
30
|
key: "key";
|
|
31
31
|
none: "none";
|
|
32
|
-
uncertain: "uncertain";
|
|
33
32
|
content: "content";
|
|
33
|
+
uncertain: "uncertain";
|
|
34
34
|
}>;
|
|
35
35
|
reasons: z.ZodArray<z.ZodString>;
|
|
36
36
|
results: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
@@ -82,8 +82,8 @@ export declare const DiffScenario: z.ZodObject<{
|
|
|
82
82
|
action: "action";
|
|
83
83
|
key: "key";
|
|
84
84
|
none: "none";
|
|
85
|
-
uncertain: "uncertain";
|
|
86
85
|
content: "content";
|
|
86
|
+
uncertain: "uncertain";
|
|
87
87
|
}>;
|
|
88
88
|
reasons: z.ZodArray<z.ZodString>;
|
|
89
89
|
results: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
@@ -157,8 +157,8 @@ export declare const FeatureDiffManifest: z.ZodObject<{
|
|
|
157
157
|
action: "action";
|
|
158
158
|
key: "key";
|
|
159
159
|
none: "none";
|
|
160
|
-
uncertain: "uncertain";
|
|
161
160
|
content: "content";
|
|
161
|
+
uncertain: "uncertain";
|
|
162
162
|
}>;
|
|
163
163
|
reasons: z.ZodArray<z.ZodString>;
|
|
164
164
|
results: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
package/dist/guide.js
CHANGED
|
@@ -431,6 +431,7 @@ What viewers look at in each step, and the lighter forms (spotlight, highlight,
|
|
|
431
431
|
- Props that shape a Diagram's layout (tone, label, kind) are fixed at compile time and cannot bind state. To recolor per step, draw that part with your own elements and a bound style.
|
|
432
432
|
- Ids inside reusable graphics must be unique across layers: prefix them with the instance id (map_TX, not TX). A cue resolves an id to the first layer that has it, so the same id on two layers sends the director to the wrong layer, and check cannot tell which one you meant.
|
|
433
433
|
- Let a missing asset() fail loudly. Do not wrap it in try/catch with a drawn fallback: a stale dev process or a wrong path then shows a substitute without any error.
|
|
434
|
+
- One screen in several variants (languages, brands, plans): bind every visible string to $.ui, keep the variants in one table, and write a helper that returns the set() effects for a whole variant (...variant('ja')). Include breadcrumbs, badges, button labels, status text and captions; render one key frame per variant to catch strings left in the old variant.
|
|
434
435
|
|
|
435
436
|
## Write a theme
|
|
436
437
|
- A theme is a CSS file at themes/<name>.css in the project root. Set theme: '<name>' in joplo.config.ts as the default. A custom theme overrides a built-in with the same name.
|
|
@@ -501,6 +502,7 @@ Choose by the question: "what is where" → Diagram; "what happens in what order
|
|
|
501
502
|
- Leave out direction: Joplo tries top → bottom and left → right and keeps the one that fills the stage with the largest text (domain groups end up side by side). direction="right" / "down" forces one; aspect={1.6} sets the wanted width / height; h="100%" fills a layer.
|
|
502
503
|
- Source order is the order within a layer: write nodes, groups, and edges in reading order. Write the request edge before its reply (api → kernel before kernel → api): the later one is drawn as a return edge.
|
|
503
504
|
- Mark secondary flows async (usage events, audit logs): they may stop pushing their target a layer down, so domains sit side by side instead of in a tall column.
|
|
505
|
+
- When two chains feed one node (author → storage → player, and viewer → player), write the upstream chain's groups and edges first, in the direction data flows. An edge written before its upstream chain is drawn as a loop back across the stage.
|
|
504
506
|
- pin="start" / pin="end" puts a node or group in the first / last layer of its group. The layout covers every element, including ones hidden with when: nodes never move between steps.
|
|
505
507
|
- In each step only the traced call is bold, colored, with a moving dot and its label outlined; other edges turn thin and light. One call per step reads best.
|
|
506
508
|
|
|
@@ -719,7 +721,9 @@ Example: features/invite/options/a.tsx:12:5 warning UNBOUND_INTERACTIVE Inter
|
|
|
719
721
|
- EXPLAIN_TOO_LONG: Shorten the explain note to about 48 units, using the same CJK 1 / other 0.5 calculation. Put detailed rationale in a separate explanation layer. See demo.
|
|
720
722
|
- SAY_TOO_LONG / NARRATE_TOO_LONG (warning): a say() or narrate() line over about 80 units (about 10 seconds aloud). Autoplay waits until it is read; say less or split the step.
|
|
721
723
|
- SAY_EMPTY / NARRATE_EMPTY: say() needs the character's words, narrate() the narrator's. Remove it to fall back to the caption.
|
|
722
|
-
- VOICE_CONFIG_INVALID: config({ voice }) takes { profile?, narrator?, roles?: { roleKey: 'voice' } } with non-empty strings. API keys never go in the config.
|
|
724
|
+
- VOICE_CONFIG_INVALID: config({ voice }) takes { profile?, narrator?, roles?: { roleKey: 'voice' }, locales?: { ja: { narrator?, roles? } } } with non-empty strings. API keys never go in the config.
|
|
725
|
+
- LOCALES_INVALID / LOCALES_UNDECLARED: config({ locales }) lists supported languages once each, source language first; every locales/<lang>.json must be listed there and must not be the source language. LOCALE_FILE_INVALID: the file must be one JSON object of "source text": "translation" strings.
|
|
726
|
+
- I18N_MISSING / I18N_STALE / I18N_UNUSED (warnings): texts with no translation (viewers see the source text), a source text that changed (the closest old entry is shown: rename the key and update the translation), entries nothing uses. npx joplo i18n add <lang> adds the missing keys.
|
|
723
727
|
- DESCRIPTION_TOO_LONG: flow({ description }) is the scenario cover sentence; keep it within 30 units, one sentence saying what this scenario shows. See story.
|
|
724
728
|
- CARD_TEXT_TOO_LONG (info): a transition card's sub is over 48 units, a point over 24, or more than 4 points. Keep one sentence and a few short points; move details into steps.
|
|
725
729
|
- SCENARIO_TOO_LONG (info): the scenario plays over 90 s at 1×. One scenario tells one thing: split it (happy path, then each recovery) or branch with fork(). npx joplo outline shows the pacing.
|
|
@@ -973,6 +977,13 @@ Deploy only dist output, not author source files. MCP, comments, and collaborati
|
|
|
973
977
|
- CI: set JOPLO_API_KEY (jpk_..., created in Settings → API keys) instead of logging in. Every cloud command then uses it; credentials.json and browser login are never touched. An invalid or revoked key returns AUTH_EXPIRED: ask the user for a new key.
|
|
974
978
|
- PR previews: in GitHub Actions run npx joplo share --new --pr <number> --format json; repo, commit, and run URL come from the Actions environment. Outside Actions pass --repo owner/name. data.pr.comment "skipped" means the Joplo GitHub App is not installed; tell the user, the share itself succeeded.
|
|
975
979
|
|
|
980
|
+
## Viewers in several languages
|
|
981
|
+
- Write the source files in one language. To add another: npx joplo i18n add <lang> (first time also --source <source lang>). It adds the language to config({ locales }) (the first entry is the source language) and writes locales/<lang>.json as "source text": "" for every text viewers see: screens, captions, narrate / say, cards, toasts, done, feature and scenario names, displayed sample data, and board-only texts (case titles and expected results, rules, questions, element notes).
|
|
982
|
+
- Translate every "" yourself, whole sentences, keeping on-screen names consistent where captions quote them; narration as people say it in that language. Do not put t() calls or per-language objects in the TSX. Then npx joplo check: I18N_MISSING lists what is left, I18N_STALE means a source text changed (it shows the closest old entry: rename the key and update the translation).
|
|
983
|
+
- After editing source texts, run npx joplo i18n add <lang> again for each language: it adds new keys and keeps existing translations (--prune drops unused ones).
|
|
984
|
+
- One link serves everyone: viewers get their browser language, ?lang=<lang> picks one, and languages the project lacks fall back to the source language. The board's content-language menu previews each language; npx joplo render --content <lang> screenshots one.
|
|
985
|
+
- Narration: generate audio per language in the board; each language picks a native preset voice when the provider has one, or set config({ voice: { locales: { ja: { narrator } } } }). Languages without audio use the viewer's browser voice. Re-sharing reuses the audio already in the previous share (same text and voice). On another computer (no .joplo/cloud.json) run npx joplo share --update <share link>: it updates that share (Pro; free plans get a new link) and reuses its audio instead of regenerating it.
|
|
986
|
+
|
|
976
987
|
## Feature changes across versions
|
|
977
988
|
For local comparisons and PR CI, read npx joplo skill diff. It compares two real publish builds and creates one immutable bundle; ordinary share --pr remains a single preview.
|
|
978
989
|
|
package/dist/index.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export * from './pace.js';
|
|
|
18
18
|
export * from './outline.js';
|
|
19
19
|
export * from './diagram/index.js';
|
|
20
20
|
export * from './voice.js';
|
|
21
|
+
export * from './content-i18n.js';
|
|
21
22
|
export * from './local-review.js';
|
|
22
23
|
export * from './feature-diff.js';
|
|
23
24
|
export * from './step-identity.js';
|
package/dist/index.js
CHANGED
|
@@ -18,6 +18,7 @@ export * from "./pace.js";
|
|
|
18
18
|
export * from "./outline.js";
|
|
19
19
|
export * from "./diagram/index.js";
|
|
20
20
|
export * from "./voice.js";
|
|
21
|
+
export * from "./content-i18n.js";
|
|
21
22
|
export * from "./local-review.js";
|
|
22
23
|
export * from "./feature-diff.js";
|
|
23
24
|
export * from "./step-identity.js";
|
package/dist/load.d.ts
CHANGED
|
@@ -5,6 +5,15 @@ export type Importer = (absPath: string) => Promise<Record<string, unknown>>;
|
|
|
5
5
|
export declare function discoverFiles(root: string): string[];
|
|
6
6
|
/** 作者主题:themes/<name>.css(文件名就是主题名)。 */
|
|
7
7
|
export declare function loadThemes(root: string): Record<string, string>;
|
|
8
|
+
/**
|
|
9
|
+
* 作者内容译文(D84):locales/<语言>.json,一个扁平对象(原文 → 译文,值是字符串)。
|
|
10
|
+
* 文件名不是语言标签、JSON 写错、值不是字符串时报 LOCALE_FILE_INVALID,这个文件不参与编译。
|
|
11
|
+
*/
|
|
12
|
+
export declare function loadLocales(root: string): {
|
|
13
|
+
locales: Record<string, Record<string, string>>;
|
|
14
|
+
files: Record<string, string>;
|
|
15
|
+
diagnostics: Diagnostic[];
|
|
16
|
+
};
|
|
8
17
|
export declare function loadAuthoring(root: string, importer: Importer): Promise<{
|
|
9
18
|
authoring: AuthoringProject | null;
|
|
10
19
|
diagnostics: Diagnostic[];
|
package/dist/load.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* features/<f>/feature.ts
|
|
9
9
|
* features/<f>/options/<o>.tsx
|
|
10
10
|
* themes/<name>.css 作者主题(D51),按原文读取
|
|
11
|
+
* locales/<语言>.json 作者内容译文(D84):原文 → 译文
|
|
11
12
|
*/
|
|
12
13
|
import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs';
|
|
13
14
|
import { join, relative, resolve, sep } from 'node:path';
|
|
@@ -50,6 +51,9 @@ export function discoverFiles(root) {
|
|
|
50
51
|
for (const f of list(join(r, 'themes')))
|
|
51
52
|
if (/\.css$/.test(f))
|
|
52
53
|
files.push(join(r, 'themes', f));
|
|
54
|
+
for (const f of list(join(r, 'locales')))
|
|
55
|
+
if (/\.json$/.test(f))
|
|
56
|
+
files.push(join(r, 'locales', f));
|
|
53
57
|
return files;
|
|
54
58
|
}
|
|
55
59
|
/** 作者主题:themes/<name>.css(文件名就是主题名)。 */
|
|
@@ -63,6 +67,47 @@ export function loadThemes(root) {
|
|
|
63
67
|
}
|
|
64
68
|
return out;
|
|
65
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* 作者内容译文(D84):locales/<语言>.json,一个扁平对象(原文 → 译文,值是字符串)。
|
|
72
|
+
* 文件名不是语言标签、JSON 写错、值不是字符串时报 LOCALE_FILE_INVALID,这个文件不参与编译。
|
|
73
|
+
*/
|
|
74
|
+
export function loadLocales(root) {
|
|
75
|
+
const r = resolve(root);
|
|
76
|
+
const locales = {};
|
|
77
|
+
const files = {};
|
|
78
|
+
const diagnostics = [];
|
|
79
|
+
for (const f of list(join(r, 'locales'))) {
|
|
80
|
+
if (!/\.json$/.test(f))
|
|
81
|
+
continue;
|
|
82
|
+
const rel = `locales/${f}`;
|
|
83
|
+
const bad = (message) => diagnostics.push({ severity: 'error', code: 'LOCALE_FILE_INVALID', message: `${rel}: ${message}`, source: 'schema', at: `${rel}:1:1` });
|
|
84
|
+
const tag = f.slice(0, -5);
|
|
85
|
+
if (!/^[a-z]{2,3}(-[A-Za-z0-9]{2,8})*$/.test(tag)) {
|
|
86
|
+
bad('the file name must be a language tag such as ja.json or zh-CN.json');
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
let raw;
|
|
90
|
+
try {
|
|
91
|
+
raw = JSON.parse(readFileSync(join(r, 'locales', f), 'utf8'));
|
|
92
|
+
}
|
|
93
|
+
catch (e) {
|
|
94
|
+
bad(`not valid JSON (${e instanceof Error ? e.message : String(e)})`);
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
|
|
98
|
+
bad('must be one object of "source text": "translation"');
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
const nonString = Object.entries(raw).find(([, v]) => typeof v !== 'string');
|
|
102
|
+
if (nonString) {
|
|
103
|
+
bad(`the value of ${JSON.stringify(nonString[0])} must be a string (write "" while it is not translated yet)`);
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
locales[tag] = raw;
|
|
107
|
+
files[tag] = rel;
|
|
108
|
+
}
|
|
109
|
+
return { locales, files, diagnostics };
|
|
110
|
+
}
|
|
66
111
|
export async function loadAuthoring(root, importer) {
|
|
67
112
|
// 步骤和规则的源位置来自调用栈;开启原生 source map,保证行号指向 TSX 源码而不是转译产物。
|
|
68
113
|
process.setSourceMapsEnabled?.(true);
|
|
@@ -142,5 +187,7 @@ export async function loadAuthoring(root, importer) {
|
|
|
142
187
|
}
|
|
143
188
|
if (!config)
|
|
144
189
|
return { authoring: null, diagnostics: diags };
|
|
145
|
-
|
|
190
|
+
const loc = loadLocales(r);
|
|
191
|
+
diags.push(...loc.diagnostics);
|
|
192
|
+
return { authoring: { root: r, config, layouts, routes, features, themes: loadThemes(r), ...(Object.keys(loc.files).length ? { locales: loc.locales, localeFiles: loc.files } : {}) }, diagnostics: diags };
|
|
146
193
|
}
|
package/dist/schema.d.ts
CHANGED
|
@@ -669,11 +669,21 @@ export declare const Issue: z.ZodObject<{
|
|
|
669
669
|
refs: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
670
670
|
source: z.ZodOptional<z.ZodString>;
|
|
671
671
|
}, z.core.$strict>;
|
|
672
|
-
/**
|
|
672
|
+
/** 作者内容多语言(D84):default 是原文的语言,locales 第一个就是它。 */
|
|
673
|
+
export declare const ContentI18nSchema: z.ZodObject<{
|
|
674
|
+
default: z.ZodString;
|
|
675
|
+
locales: z.ZodArray<z.ZodString>;
|
|
676
|
+
messages: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>>>;
|
|
677
|
+
stale: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
|
|
678
|
+
}, z.core.$strict>;
|
|
673
679
|
export declare const VoiceConfig: z.ZodObject<{
|
|
674
680
|
profile: z.ZodOptional<z.ZodString>;
|
|
675
681
|
narrator: z.ZodOptional<z.ZodString>;
|
|
676
682
|
roles: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
683
|
+
locales: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
684
|
+
narrator: z.ZodOptional<z.ZodString>;
|
|
685
|
+
roles: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
686
|
+
}, z.core.$strict>>>;
|
|
677
687
|
}, z.core.$strict>;
|
|
678
688
|
/**
|
|
679
689
|
* 发布站带上的朗读音频(D74,joplo build 写入):voices 是每个声音的指纹(旁白与各角色),
|
|
@@ -683,6 +693,10 @@ export declare const VoiceIndex: z.ZodObject<{
|
|
|
683
693
|
narrator: z.ZodNullable<z.ZodString>;
|
|
684
694
|
roles: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
685
695
|
clips: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
696
|
+
locales: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
697
|
+
narrator: z.ZodNullable<z.ZodString>;
|
|
698
|
+
roles: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
699
|
+
}, z.core.$strict>>>;
|
|
686
700
|
}, z.core.$strict>;
|
|
687
701
|
export declare const Project: z.ZodObject<{
|
|
688
702
|
schemaVersion: z.ZodLiteral<2>;
|
|
@@ -694,11 +708,25 @@ export declare const Project: z.ZodObject<{
|
|
|
694
708
|
profile: z.ZodOptional<z.ZodString>;
|
|
695
709
|
narrator: z.ZodOptional<z.ZodString>;
|
|
696
710
|
roles: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
711
|
+
locales: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
712
|
+
narrator: z.ZodOptional<z.ZodString>;
|
|
713
|
+
roles: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
714
|
+
}, z.core.$strict>>>;
|
|
697
715
|
}, z.core.$strict>>;
|
|
698
716
|
voiceIndex: z.ZodOptional<z.ZodObject<{
|
|
699
717
|
narrator: z.ZodNullable<z.ZodString>;
|
|
700
718
|
roles: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
701
719
|
clips: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
720
|
+
locales: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
721
|
+
narrator: z.ZodNullable<z.ZodString>;
|
|
722
|
+
roles: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
723
|
+
}, z.core.$strict>>>;
|
|
724
|
+
}, z.core.$strict>>;
|
|
725
|
+
i18n: z.ZodOptional<z.ZodObject<{
|
|
726
|
+
default: z.ZodString;
|
|
727
|
+
locales: z.ZodArray<z.ZodString>;
|
|
728
|
+
messages: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodString>>>;
|
|
729
|
+
stale: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
|
|
702
730
|
}, z.core.$strict>>;
|
|
703
731
|
themes: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
704
732
|
mode: z.ZodEnum<{
|
|
@@ -1043,3 +1071,4 @@ export type Cue = z.infer<typeof Cue>;
|
|
|
1043
1071
|
export type Callout = z.infer<typeof Callout>;
|
|
1044
1072
|
export type VoiceConfig = z.infer<typeof VoiceConfig>;
|
|
1045
1073
|
export type VoiceIndex = z.infer<typeof VoiceIndex>;
|
|
1074
|
+
export type ContentI18nIR = z.infer<typeof ContentI18nSchema>;
|
package/dist/schema.js
CHANGED
|
@@ -275,11 +275,25 @@ export const Issue = z.strictObject({
|
|
|
275
275
|
refs: z.array(z.string()).default([]),
|
|
276
276
|
source: Source,
|
|
277
277
|
});
|
|
278
|
-
/**
|
|
278
|
+
/** 作者内容多语言(D84):default 是原文的语言,locales 第一个就是它。 */
|
|
279
|
+
export const ContentI18nSchema = z.strictObject({
|
|
280
|
+
default: z.string().min(1),
|
|
281
|
+
locales: z.array(z.string().min(1)).min(1),
|
|
282
|
+
/** 语言 → 原文 → 译文(不含空译文)。 */
|
|
283
|
+
messages: z.record(z.string(), z.record(z.string(), z.string().min(1))).default({}),
|
|
284
|
+
/** 每种语言里原文改过、旧译文还在的条数(看板菜单显示“过期”);只在 dev IR。 */
|
|
285
|
+
stale: z.record(z.string(), z.number().int().nonnegative()).optional(),
|
|
286
|
+
});
|
|
287
|
+
/** 朗读配置(D74,来自 config({ voice })):只在 dev / review IR 里,发布站去掉。locales(D84):按内容语言覆盖旁白与角色的音色。 */
|
|
288
|
+
const VoiceVoices = z.strictObject({
|
|
289
|
+
narrator: z.string().min(1).optional(),
|
|
290
|
+
roles: z.record(z.string(), z.string().min(1)).optional(),
|
|
291
|
+
});
|
|
279
292
|
export const VoiceConfig = z.strictObject({
|
|
280
293
|
profile: z.string().min(1).optional(),
|
|
281
294
|
narrator: z.string().min(1).optional(),
|
|
282
295
|
roles: z.record(z.string(), z.string().min(1)).optional(),
|
|
296
|
+
locales: z.record(z.string(), VoiceVoices).optional(),
|
|
283
297
|
});
|
|
284
298
|
/**
|
|
285
299
|
* 发布站带上的朗读音频(D74,joplo build 写入):voices 是每个声音的指纹(旁白与各角色),
|
|
@@ -289,6 +303,8 @@ export const VoiceIndex = z.strictObject({
|
|
|
289
303
|
narrator: z.string().min(1).nullable(),
|
|
290
304
|
roles: z.record(z.string(), z.string().min(1)).default({}),
|
|
291
305
|
clips: z.record(z.string(), z.string().min(1)).default({}),
|
|
306
|
+
/** 内容语言(D84)→ 这种语言的旁白与角色指纹;没有的语言用上面的默认声音。 */
|
|
307
|
+
locales: z.record(z.string(), z.strictObject({ narrator: z.string().min(1).nullable(), roles: z.record(z.string(), z.string().min(1)).default({}) })).optional(),
|
|
292
308
|
});
|
|
293
309
|
export const Project = z.strictObject({
|
|
294
310
|
schemaVersion: z.literal(SCHEMA_VERSION),
|
|
@@ -300,6 +316,8 @@ export const Project = z.strictObject({
|
|
|
300
316
|
autoFocus: z.boolean().optional(),
|
|
301
317
|
voiceConfig: VoiceConfig.optional(),
|
|
302
318
|
voiceIndex: VoiceIndex.optional(),
|
|
319
|
+
/** 作者内容多语言(D84):只有 config 写了 locales 才有。messages 只含非默认语言、这份 IR 用得到的译文;stale 只在 dev IR。 */
|
|
320
|
+
i18n: ContentI18nSchema.optional(),
|
|
303
321
|
/** 作者主题(D51):主题名 → CSS 原文(themes/<name>.css);渲染时自动限定在舞台范围内。发布站同样打包。 */
|
|
304
322
|
themes: z.record(z.string(), z.string()).default({}),
|
|
305
323
|
/** dev = 含全部方案(本地看板);publish = 只含选定方案,且去掉创作侧信息(D33);review = 评审版:全部方案,同样去掉创作侧信息(D63)。 */
|
package/dist/scope.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* - 范围外的分叉去掉;规则、情况、问题只留范围内功能(规则、问题再按方案过滤);项目说明去掉(常常概述所有功能),项目名保留。
|
|
9
9
|
* dev、publish、review 三种 IR 都能裁剪:share 用它裁剪发布 IR(上传的文件)和 dev IR(评审清单、预览图)。
|
|
10
10
|
*/
|
|
11
|
+
import { pruneMessages } from "./content-i18n.js";
|
|
11
12
|
import { orderedFeatures } from "./features.js";
|
|
12
13
|
import { JoploError } from "./result.js";
|
|
13
14
|
export const hasScope = (r) => !!r && ((r.scenarios?.length ?? 0) > 0 || (r.features?.length ?? 0) > 0);
|
|
@@ -210,7 +211,14 @@ export function scopeProject(project, scenarioIds, mode = project.mode === 'revi
|
|
|
210
211
|
const featureIds = project.featureIds?.filter((id) => F.has(id));
|
|
211
212
|
const inF = (x) => F.has(x.featureId) && (x.optionId === undefined || O.has(x.optionId));
|
|
212
213
|
const roleIds = new Set(Object.values(features).flatMap((f) => f.roles.map((r) => r.id).filter((r) => !!r)));
|
|
213
|
-
const
|
|
214
|
+
const onlyRoles = (r) => Object.fromEntries(Object.entries(r).filter(([k]) => roleIds.has(k)));
|
|
215
|
+
const keepRoles = (v) => v && (v.roles || v.locales)
|
|
216
|
+
? {
|
|
217
|
+
...v,
|
|
218
|
+
...(v.roles ? { roles: onlyRoles(v.roles) } : {}),
|
|
219
|
+
...(v.locales ? { locales: Object.fromEntries(Object.entries(v.locales).map(([l, x]) => [l, x.roles ? { ...x, roles: onlyRoles(x.roles) } : x])) } : {}),
|
|
220
|
+
}
|
|
221
|
+
: v;
|
|
214
222
|
const out = {
|
|
215
223
|
...project,
|
|
216
224
|
// 项目说明常常概述所有功能:范围分享里不带;项目名保留(分享标题与页面标题要用,作者自己决定怎么起)
|
|
@@ -228,7 +236,8 @@ export function scopeProject(project, scenarioIds, mode = project.mode === 'revi
|
|
|
228
236
|
...(project.voiceIndex ? { voiceIndex: keepRoles(project.voiceIndex) } : {}),
|
|
229
237
|
};
|
|
230
238
|
const ids = Object.keys(scenarios);
|
|
231
|
-
|
|
239
|
+
// 译文只留范围内用得到的(D84):别的功能的文字不随范围分享出去
|
|
240
|
+
return { project: pruneMessages(out), info: { key: scopeKey(ids, mode), scenarios: ids, features: Object.keys(features), borrowed: merged } };
|
|
232
241
|
}
|
|
233
242
|
/** 一条借用的说明(英文,CLI 与看板共用)。 */
|
|
234
243
|
export function borrowedLine(b) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@joplo-app/core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.17",
|
|
4
4
|
"description": "Joplo 编译器、校验器与播放器(IR v2)",
|
|
5
5
|
"license": "PolyForm-Shield-1.0.0",
|
|
6
6
|
"type": "module",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"dist"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@joplo-app/kit": "0.2.
|
|
22
|
+
"@joplo-app/kit": "0.2.17",
|
|
23
23
|
"elkjs": "0.12.1",
|
|
24
24
|
"zod": "4.6.7"
|
|
25
25
|
},
|