@funny-booth/langley-video-mcp 0.13.0 → 0.14.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/blueprint.js +633 -0
- package/dist/client.js +1 -1
- package/dist/index.js +125 -0
- package/dist/photoshop.js +87 -0
- package/dist/still.js +370 -0
- package/package.json +1 -1
|
@@ -0,0 +1,633 @@
|
|
|
1
|
+
// 静止画の設計図(設計書 §5.1)を、その Mac の Photoshop で仕上げるための純粋な部分。
|
|
2
|
+
// 外とやり取りしない(ファイル・osascript は photoshop.ts)。
|
|
3
|
+
// - validate: 設計図の検査(VPS の still_blueprint.py と同じ決まり。文言と訴求の照合は VPS 側だけ)
|
|
4
|
+
// - resolveFont / planFonts: 書体の解決(prefer → 同じ種類と太さの対応表 → 小塚ゴシックにして「置き換えた」と報告)
|
|
5
|
+
// - toJsx: 設計図から Photoshop に渡す JSX(全体が ASCII。文字は \uXXXX)
|
|
6
|
+
// - checkResult: Photoshop の返り値の検査(枠から 10% 以上はみ出した層・置き換えた書体)
|
|
7
|
+
export const FONT_CLASSES = ["gothic", "mincho", "maru", "hand", "display", "latin"];
|
|
8
|
+
export const FONT_WEIGHTS = ["light", "regular", "bold", "heavy", "black"];
|
|
9
|
+
export const PLATE_LAYER = "背景|土台";
|
|
10
|
+
const LAYER_NAME = /^[^|]+|[^|]+$/;
|
|
11
|
+
const COLOR = /^#[0-9A-Fa-f]{6}$/;
|
|
12
|
+
const SIZE_MIN = 6;
|
|
13
|
+
const SIZE_MAX = 400;
|
|
14
|
+
/** 位置が絵文字(サロゲートの対)の真ん中なら true */
|
|
15
|
+
const splitsPair = (s, i) => i > 0 && i < s.length && /[\uD800-\uDBFF]/.test(s[i - 1]) && /[\uDC00-\uDFFF]/.test(s[i]);
|
|
16
|
+
const isObj = (x) => typeof x === "object" && x !== null && !Array.isArray(x);
|
|
17
|
+
const isNum = (x) => typeof x === "number" && Number.isFinite(x);
|
|
18
|
+
const oneOf = (xs, x) => typeof x === "string" && xs.includes(x);
|
|
19
|
+
function checkFont(f, at, errs) {
|
|
20
|
+
if (!isObj(f))
|
|
21
|
+
return void errs.push(`${at}: font が {class, weight} ではありません`);
|
|
22
|
+
if (!oneOf(FONT_CLASSES, f.class))
|
|
23
|
+
errs.push(`${at}: font.class が ${FONT_CLASSES.join("/")} のどれでもありません`);
|
|
24
|
+
if (!oneOf(FONT_WEIGHTS, f.weight))
|
|
25
|
+
errs.push(`${at}: font.weight が ${FONT_WEIGHTS.join("/")} のどれでもありません`);
|
|
26
|
+
if (f.prefer !== undefined && !(Array.isArray(f.prefer) && f.prefer.every((p) => typeof p === "string" && p !== "")))
|
|
27
|
+
errs.push(`${at}: font.prefer は PostScript 名の並びにしてください`);
|
|
28
|
+
}
|
|
29
|
+
function checkSize(v, at, errs) {
|
|
30
|
+
if (!isNum(v) || v < SIZE_MIN || v > SIZE_MAX)
|
|
31
|
+
errs.push(`${at}: 大きさは ${SIZE_MIN}〜${SIZE_MAX} にしてください(${String(v)})`);
|
|
32
|
+
}
|
|
33
|
+
function checkColor(v, at, errs) {
|
|
34
|
+
if (typeof v !== "string" || !COLOR.test(v))
|
|
35
|
+
errs.push(`${at}: 色は #RRGGBB にしてください(${String(v)})`);
|
|
36
|
+
}
|
|
37
|
+
/** 設計図の検査。問題を全部並べて返す(空なら合格) */
|
|
38
|
+
export function validate(x) {
|
|
39
|
+
const errs = [];
|
|
40
|
+
if (!isObj(x))
|
|
41
|
+
return ["設計図が JSON のオブジェクトではありません"];
|
|
42
|
+
if (x.v !== 1)
|
|
43
|
+
errs.push(`版 v=${String(x.v)} は読めません(1 だけ)`);
|
|
44
|
+
if (typeof x.id !== "string" || !x.id)
|
|
45
|
+
errs.push("id がありません");
|
|
46
|
+
// バナー名はファイル名になる
|
|
47
|
+
if (typeof x.banner !== "string" || !/^[A-Za-z0-9_-]+$/.test(x.banner))
|
|
48
|
+
errs.push("banner は英数字・_・- だけにしてください");
|
|
49
|
+
if (x.size !== "1x1" && x.size !== "9x16")
|
|
50
|
+
errs.push("size は 1x1 か 9x16 です");
|
|
51
|
+
const c = x.canvas;
|
|
52
|
+
const canvasOk = isObj(c) && Number.isInteger(c.w) && Number.isInteger(c.h) && c.w > 0 && c.h > 0;
|
|
53
|
+
if (!canvasOk)
|
|
54
|
+
errs.push("canvas の w・h は正の整数にしてください");
|
|
55
|
+
const p = x.plate;
|
|
56
|
+
if (!isObj(p))
|
|
57
|
+
errs.push("plate がありません");
|
|
58
|
+
else {
|
|
59
|
+
if (typeof p.name !== "string" || !/^[A-Za-z0-9_.-]+\.png$/.test(p.name))
|
|
60
|
+
errs.push("plate.name は英数字の .png にしてください");
|
|
61
|
+
if (typeof p.sha256 !== "string" || !/^[0-9a-f]{64}$/.test(p.sha256))
|
|
62
|
+
errs.push("plate.sha256 は小文字16進の64字にしてください");
|
|
63
|
+
if (p.layer !== PLATE_LAYER)
|
|
64
|
+
errs.push(`plate.layer は「${PLATE_LAYER}」にしてください`);
|
|
65
|
+
}
|
|
66
|
+
if (!Array.isArray(x.layers))
|
|
67
|
+
return [...errs, "layers が並びではありません"];
|
|
68
|
+
const seen = new Set([PLATE_LAYER]);
|
|
69
|
+
x.layers.forEach((l, i) => {
|
|
70
|
+
if (!isObj(l))
|
|
71
|
+
return void errs.push(`layers[${i}] がオブジェクトではありません`);
|
|
72
|
+
const at = typeof l.name === "string" ? `層「${l.name}」` : `layers[${i}]`;
|
|
73
|
+
if (typeof l.name !== "string" || !LAYER_NAME.test(l.name))
|
|
74
|
+
errs.push(`${at}: 名前は「種類|名前」の形にしてください(|はちょうど1つ)`);
|
|
75
|
+
else if (seen.has(l.name))
|
|
76
|
+
errs.push(`${at}: 同じ名前の層があります`);
|
|
77
|
+
else
|
|
78
|
+
seen.add(l.name);
|
|
79
|
+
if (typeof l.text !== "string" || l.text === "")
|
|
80
|
+
errs.push(`${at}: text が空です`);
|
|
81
|
+
const b = l.box;
|
|
82
|
+
if (!isObj(b) || ![b.x, b.y, b.w, b.h].every(isNum) || b.w <= 0 || b.h <= 0)
|
|
83
|
+
errs.push(`${at}: box は x・y・w・h(w・h は正)にしてください`);
|
|
84
|
+
else if (canvasOk) {
|
|
85
|
+
const { x: bx, y: by, w: bw, h: bh } = b;
|
|
86
|
+
const cv = c;
|
|
87
|
+
if (bx < 0 || by < 0 || bx + bw > cv.w || by + bh > cv.h)
|
|
88
|
+
errs.push(`${at}: 枠が画面(${cv.w}×${cv.h})からはみ出しています`);
|
|
89
|
+
}
|
|
90
|
+
if (l.orientation !== "vertical" && l.orientation !== "horizontal")
|
|
91
|
+
errs.push(`${at}: orientation は vertical か horizontal です`);
|
|
92
|
+
if (!oneOf(["left", "center", "right"], l.align))
|
|
93
|
+
errs.push(`${at}: align は left・center・right(縦書きでは上・中・下)です`);
|
|
94
|
+
if (l.kind !== "point" && l.kind !== "paragraph")
|
|
95
|
+
errs.push(`${at}: kind は point か paragraph です`);
|
|
96
|
+
if (!isNum(l.rotate) || Math.abs(l.rotate) > 360)
|
|
97
|
+
errs.push(`${at}: rotate は -360〜360 の度にしてください`);
|
|
98
|
+
if (!isNum(l.tracking))
|
|
99
|
+
errs.push(`${at}: tracking は数にしてください`);
|
|
100
|
+
if (l.leading !== null && !(isNum(l.leading) && l.leading > 0))
|
|
101
|
+
errs.push(`${at}: leading は正の数か null にしてください`);
|
|
102
|
+
checkFont(l.font, at, errs);
|
|
103
|
+
checkSize(l.size, at, errs);
|
|
104
|
+
checkColor(l.color, at, errs);
|
|
105
|
+
if (l.stroke !== null) {
|
|
106
|
+
const st = l.stroke;
|
|
107
|
+
if (!isObj(st))
|
|
108
|
+
errs.push(`${at}: stroke は {color, width} か null にしてください`);
|
|
109
|
+
else {
|
|
110
|
+
checkColor(st.color, `${at} stroke`, errs);
|
|
111
|
+
if (!isNum(st.width) || st.width <= 0)
|
|
112
|
+
errs.push(`${at}: stroke.width は正の数にしてください`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (l.shadow !== null) {
|
|
116
|
+
const sh = l.shadow;
|
|
117
|
+
if (!isObj(sh))
|
|
118
|
+
errs.push(`${at}: shadow は {color, dx, dy, blur} か null にしてください`);
|
|
119
|
+
else {
|
|
120
|
+
checkColor(sh.color, `${at} shadow`, errs);
|
|
121
|
+
if (!isNum(sh.dx) || !isNum(sh.dy))
|
|
122
|
+
errs.push(`${at}: shadow.dx・dy は数にしてください`);
|
|
123
|
+
if (!isNum(sh.blur) || sh.blur < 0)
|
|
124
|
+
errs.push(`${at}: shadow.blur は 0 以上にしてください`);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (!Array.isArray(l.runs))
|
|
128
|
+
return void errs.push(`${at}: runs が並びではありません`);
|
|
129
|
+
const text = typeof l.text === "string" ? l.text : "";
|
|
130
|
+
const len = text.length;
|
|
131
|
+
const ranges = [];
|
|
132
|
+
l.runs.forEach((r, j) => {
|
|
133
|
+
const ra = `${at} runs[${j}]`;
|
|
134
|
+
if (!isObj(r))
|
|
135
|
+
return void errs.push(`${ra}: オブジェクトではありません`);
|
|
136
|
+
if (!Number.isInteger(r.from) || !Number.isInteger(r.to) || r.from < 0 || r.from >= r.to || r.to > len)
|
|
137
|
+
return void errs.push(`${ra}: 0 ≤ from < to ≤ ${len}(UTF-16 の長さ)にしてください(from=${String(r.from)} to=${String(r.to)})`);
|
|
138
|
+
if (splitsPair(text, r.from) || splitsPair(text, r.to))
|
|
139
|
+
return void errs.push(`${ra}: 絵文字の途中で切れています(from=${String(r.from)} to=${String(r.to)})`);
|
|
140
|
+
ranges.push([r.from, r.to]);
|
|
141
|
+
if (r.size != null)
|
|
142
|
+
checkSize(r.size, ra, errs);
|
|
143
|
+
if (r.color != null)
|
|
144
|
+
checkColor(r.color, ra, errs);
|
|
145
|
+
if (r.font != null)
|
|
146
|
+
checkFont(r.font, ra, errs);
|
|
147
|
+
});
|
|
148
|
+
ranges.sort((a, b) => a[0] - b[0]);
|
|
149
|
+
for (let k = 1; k < ranges.length; k++)
|
|
150
|
+
if (ranges[k][0] < ranges[k - 1][1])
|
|
151
|
+
errs.push(`${at}: runs が重なっています(${ranges[k - 1].join("-")} と ${ranges[k].join("-")})`);
|
|
152
|
+
});
|
|
153
|
+
return errs;
|
|
154
|
+
}
|
|
155
|
+
/** 検査を通したものだけを Blueprint として返す */
|
|
156
|
+
export function parseBlueprint(x) {
|
|
157
|
+
const errs = validate(x);
|
|
158
|
+
if (errs.length)
|
|
159
|
+
throw new Error(`設計図に問題があります:\n- ${errs.join("\n- ")}`);
|
|
160
|
+
return x;
|
|
161
|
+
}
|
|
162
|
+
// ---- 書体 ----
|
|
163
|
+
/** 同じ種類と太さの対応表(左から順に、その Mac にあるものを使う)。名前は macOS・Adobe Fonts の PostScript 名 */
|
|
164
|
+
export const FONT_TABLE = {
|
|
165
|
+
gothic: {
|
|
166
|
+
light: ["HiraginoSans-W2", "SourceHanSans-Light", "KozGoPr6N-Light"],
|
|
167
|
+
regular: ["HiraginoSans-W3", "SourceHanSans-Regular", "KozGoPr6N-Regular"],
|
|
168
|
+
bold: ["HiraginoSans-W6", "SourceHanSans-Bold", "KozGoPr6N-Bold"],
|
|
169
|
+
heavy: ["HiraginoSans-W7", "SourceHanSans-Heavy", "KozGoPr6N-Heavy"],
|
|
170
|
+
black: ["HiraginoSans-W8", "SourceHanSans-Heavy", "KozGoPr6N-Heavy"],
|
|
171
|
+
},
|
|
172
|
+
mincho: {
|
|
173
|
+
light: ["HiraMinProN-W3", "SourceHanSerif-Light", "KozMinPr6N-Light"],
|
|
174
|
+
regular: ["HiraMinProN-W3", "SourceHanSerif-Regular", "KozMinPr6N-Regular"],
|
|
175
|
+
bold: ["HiraMinProN-W6", "SourceHanSerif-Bold", "KozMinPr6N-Bold"],
|
|
176
|
+
heavy: ["HiraMinProN-W6", "SourceHanSerif-Heavy", "KozMinPr6N-Heavy"],
|
|
177
|
+
black: ["HiraMinProN-W6", "SourceHanSerif-Heavy", "KozMinPr6N-Heavy"],
|
|
178
|
+
},
|
|
179
|
+
maru: {
|
|
180
|
+
regular: ["HiraMaruProN-W4"],
|
|
181
|
+
bold: ["HiraMaruProN-W4"],
|
|
182
|
+
},
|
|
183
|
+
hand: {},
|
|
184
|
+
display: {},
|
|
185
|
+
latin: {
|
|
186
|
+
light: ["HelveticaNeue-Light"],
|
|
187
|
+
regular: ["HelveticaNeue"],
|
|
188
|
+
bold: ["HelveticaNeue-Bold"],
|
|
189
|
+
heavy: ["HelveticaNeue-Bold"],
|
|
190
|
+
black: ["HelveticaNeue-CondensedBlack"],
|
|
191
|
+
},
|
|
192
|
+
};
|
|
193
|
+
/** 見つからないときの小塚ゴシック(太さの近い順) */
|
|
194
|
+
const KOZUKA = {
|
|
195
|
+
light: ["KozGoPr6N-Light", "KozGoPr6N-ExtraLight", "KozGoPr6N-Regular", "KozGoPr6N-Medium"],
|
|
196
|
+
regular: ["KozGoPr6N-Regular", "KozGoPr6N-Medium", "KozGoPr6N-Light"],
|
|
197
|
+
bold: ["KozGoPr6N-Bold", "KozGoPr6N-Heavy", "KozGoPr6N-Medium", "KozGoPr6N-Regular"],
|
|
198
|
+
heavy: ["KozGoPr6N-Heavy", "KozGoPr6N-Bold", "KozGoPr6N-Medium", "KozGoPr6N-Regular"],
|
|
199
|
+
black: ["KozGoPr6N-Heavy", "KozGoPr6N-Bold", "KozGoPr6N-Medium", "KozGoPr6N-Regular"],
|
|
200
|
+
};
|
|
201
|
+
const describe = (spec) => `${spec.class}/${spec.weight}${spec.prefer?.length ? `(${spec.prefer.join("・")})` : ""}`;
|
|
202
|
+
/** ①prefer にあればそれ ②同じ種類と太さの対応表 ③小塚ゴシックにして置き換えを報告。小塚ゴシックも無ければ止める */
|
|
203
|
+
export function resolveFont(spec, available) {
|
|
204
|
+
const have = available instanceof Set ? available : new Set(available);
|
|
205
|
+
const want = describe(spec);
|
|
206
|
+
for (const ps of [...(spec.prefer ?? []), ...(FONT_TABLE[spec.class][spec.weight] ?? [])])
|
|
207
|
+
if (have.has(ps))
|
|
208
|
+
return { ps, substituted: false, want };
|
|
209
|
+
const koz = KOZUKA[spec.weight].find((ps) => have.has(ps));
|
|
210
|
+
if (koz)
|
|
211
|
+
return { ps: koz, substituted: true, want };
|
|
212
|
+
throw new Error(`書体 ${want} も、代わりの小塚ゴシックも、この Mac の Photoshop にありません`);
|
|
213
|
+
}
|
|
214
|
+
export function planFonts(bp, available) {
|
|
215
|
+
const have = new Set(available);
|
|
216
|
+
const plan = { layers: {}, substituted: [] };
|
|
217
|
+
const use = (layer, spec) => {
|
|
218
|
+
const r = resolveFont(spec, have);
|
|
219
|
+
if (r.substituted && !plan.substituted.some((s) => s.layer === layer && s.want === r.want && s.got === r.ps))
|
|
220
|
+
plan.substituted.push({ layer, want: r.want, got: r.ps });
|
|
221
|
+
return r.ps;
|
|
222
|
+
};
|
|
223
|
+
for (const l of bp.layers)
|
|
224
|
+
plan.layers[l.name] = { font: use(l.name, l.font), runs: l.runs.map((r) => (r.font ? use(l.name, r.font) : null)) };
|
|
225
|
+
return plan;
|
|
226
|
+
}
|
|
227
|
+
/** 層の文字全体を、runs の切れ目で区切った並び(UTF-16 の位置のまま)。Photoshop の textStyleRange にそのまま入る */
|
|
228
|
+
export function segments(layer, fonts) {
|
|
229
|
+
const base = { size: layer.size, color: layer.color, font: fonts.font };
|
|
230
|
+
const runs = layer.runs.map((r, i) => ({ r, font: fonts.runs[i] })).sort((a, b) => a.r.from - b.r.from);
|
|
231
|
+
const out = [];
|
|
232
|
+
const end = layer.text.length;
|
|
233
|
+
let at = 0;
|
|
234
|
+
for (const { r, font } of runs) {
|
|
235
|
+
const { from, to } = r;
|
|
236
|
+
if (from > at)
|
|
237
|
+
out.push({ from: at, to: from, ...base });
|
|
238
|
+
out.push({ from, to, size: r.size ?? base.size, color: r.color ?? base.color, font: font ?? base.font });
|
|
239
|
+
at = to;
|
|
240
|
+
}
|
|
241
|
+
if (at < end)
|
|
242
|
+
out.push({ from: at, to: end, ...base });
|
|
243
|
+
return out;
|
|
244
|
+
}
|
|
245
|
+
/** JSON を、ExtendScript でそのまま読める ASCII だけの文字列にする(非 ASCII・
|
|
246
|
+
などは \uXXXX) */
|
|
247
|
+
export function asciiJson(v) {
|
|
248
|
+
return JSON.stringify(v).replace(/[^\x20-\x7e]/g, (ch) => `\\u${ch.charCodeAt(0).toString(16).padStart(4, "0")}`);
|
|
249
|
+
}
|
|
250
|
+
const ASCII_PATH = /^\/[\x20-\x7e]*$/;
|
|
251
|
+
/** 文字が枠より大きいときに縮める下限(12/4 の決まり)。これより縮めないと収まらなければ縮めずに置き、overflow で人に返す */
|
|
252
|
+
export const MIN_SCALE = 0.85;
|
|
253
|
+
/**
|
|
254
|
+
* 文字の外形 (tw×th) を枠 (bw×bh) に収める倍率。収まっていれば 1。min より縮める必要があれば 1(縮めない)。
|
|
255
|
+
* 0.001 単位で切り下げる。JSX の中でもこの関数をそのまま使う(ES3 で書く・中にコメントを書かない)
|
|
256
|
+
*/
|
|
257
|
+
export function fitScale(tw, th, bw, bh, min) {
|
|
258
|
+
var r = Math.min(bw / tw, bh / th);
|
|
259
|
+
if (r >= 1)
|
|
260
|
+
return 1;
|
|
261
|
+
r = Math.floor(r * 1000) / 1000;
|
|
262
|
+
return r >= min ? r : 1;
|
|
263
|
+
}
|
|
264
|
+
/** 影の (dx, dy) を Photoshop のドロップシャドウの角度(光の来る向き・度)と距離にする。y は下が正 */
|
|
265
|
+
export function shadowAngle(dx, dy) {
|
|
266
|
+
const distance = Math.hypot(dx, dy);
|
|
267
|
+
return { angle: distance ? (Math.atan2(dy, -dx) * 180) / Math.PI : 90, distance };
|
|
268
|
+
}
|
|
269
|
+
export const outputName = (bp, ext) => `${bp.banner}_${bp.canvas.w}x${bp.canvas.h}.${ext}`;
|
|
270
|
+
/** Photoshop に渡す JSX(全体が ASCII)。outDir に土台の PNG(bp.plate.name)を置いてから動かす。PSD・PNG も outDir に書く */
|
|
271
|
+
/**
|
|
272
|
+
* 縦書きの層の半角英数字・記号を全角にする(縦書きの半角は横に寝て「1」が「ー」に見える・12/4 の試し)。
|
|
273
|
+
* 1字は1字のまま(UTF-16 の長さが変わらない)なので、runs の位置はそのまま使える
|
|
274
|
+
*/
|
|
275
|
+
export function uprightText(text) {
|
|
276
|
+
return text.replace(/[!-~]/g, (ch) => String.fromCharCode(ch.charCodeAt(0) + 0xfee0));
|
|
277
|
+
}
|
|
278
|
+
export function toJsx(bp, fonts, outDir) {
|
|
279
|
+
if (!ASCII_PATH.test(outDir))
|
|
280
|
+
throw new Error(`作業の場所は ASCII だけの絶対パスにしてください: ${outDir}`);
|
|
281
|
+
const dir = outDir.replace(/\/$/, "");
|
|
282
|
+
const data = {
|
|
283
|
+
plate: `${dir}/${bp.plate.name}`,
|
|
284
|
+
psd: `${dir}/${outputName(bp, "psd")}`,
|
|
285
|
+
png: `${dir}/${outputName(bp, "png")}`,
|
|
286
|
+
canvas: bp.canvas,
|
|
287
|
+
plateLayer: PLATE_LAYER,
|
|
288
|
+
minScale: MIN_SCALE,
|
|
289
|
+
layers: bp.layers.map((l) => {
|
|
290
|
+
const f = fonts.layers[l.name];
|
|
291
|
+
if (!f)
|
|
292
|
+
throw new Error(`層「${l.name}」の書体が決まっていません`);
|
|
293
|
+
return {
|
|
294
|
+
name: l.name, text: l.orientation === "vertical" ? uprightText(l.text) : l.text, box: l.box,
|
|
295
|
+
vertical: l.orientation === "vertical", align: l.align,
|
|
296
|
+
paragraph: l.kind === "paragraph", rotate: l.rotate, tracking: l.tracking, leading: l.leading,
|
|
297
|
+
font: f.font, size: l.size, color: l.color.slice(1).toUpperCase(),
|
|
298
|
+
// runs が無ければ ActionManager は使わない(DOM で足りる)
|
|
299
|
+
segments: l.runs.length ? segments(l, f).map((s) => ({ ...s, color: s.color.slice(1).toUpperCase() })) : [],
|
|
300
|
+
stroke: l.stroke ? { color: l.stroke.color.slice(1).toUpperCase(), width: l.stroke.width } : null,
|
|
301
|
+
shadow: l.shadow ? { color: l.shadow.color.slice(1).toUpperCase(), blur: l.shadow.blur, ...shadowAngle(l.shadow.dx, l.shadow.dy) } : null,
|
|
302
|
+
};
|
|
303
|
+
}),
|
|
304
|
+
};
|
|
305
|
+
return `var BP = ${asciiJson(data)};\n${JSX_RUNTIME}`;
|
|
306
|
+
}
|
|
307
|
+
/** JSX の本体(データは BP)。ExtendScript(ES3)で書く。返り値は ASCII の JSON 文字列。中のコメントも ASCII だけ(JSX 全体を ASCII に保つ) */
|
|
308
|
+
const JSX_RUNTIME = String.raw `
|
|
309
|
+
(function () {
|
|
310
|
+
function enc(v) {
|
|
311
|
+
if (v === null || v === undefined) return "null";
|
|
312
|
+
if (typeof v === "number") return isFinite(v) ? String(v) : "null";
|
|
313
|
+
if (typeof v === "boolean") return v ? "true" : "false";
|
|
314
|
+
if (typeof v === "string") {
|
|
315
|
+
var s = "";
|
|
316
|
+
for (var i = 0; i < v.length; i++) {
|
|
317
|
+
var c = v.charCodeAt(i);
|
|
318
|
+
if (c < 32 || c > 126 || c === 34 || c === 92) { var h = c.toString(16); while (h.length < 4) h = "0" + h; s += "\\u" + h; }
|
|
319
|
+
else s += v.charAt(i);
|
|
320
|
+
}
|
|
321
|
+
return '"' + s + '"';
|
|
322
|
+
}
|
|
323
|
+
if (v instanceof Array) { var a = []; for (var j = 0; j < v.length; j++) a.push(enc(v[j])); return "[" + a.join(",") + "]"; }
|
|
324
|
+
var o = []; for (var k in v) if (v.hasOwnProperty(k)) o.push(enc(k) + ":" + enc(v[k])); return "{" + o.join(",") + "}";
|
|
325
|
+
}
|
|
326
|
+
function s2t(s) { return stringIDToTypeID(s); }
|
|
327
|
+
function c2t(s) { return charIDToTypeID(s); }
|
|
328
|
+
function px(u) { return u.as("px"); }
|
|
329
|
+
function color(hex) { var c = new SolidColor(); c.rgb.hexValue = hex; return c; }
|
|
330
|
+
function bounds(l) { var b = l.bounds; return [px(b[0]), px(b[1]), px(b[2]), px(b[3])]; }
|
|
331
|
+
|
|
332
|
+
// runs: rewrite the textStyleRange list (size / color / font inside one line)
|
|
333
|
+
function rgbDesc(hex) {
|
|
334
|
+
var rgb = new ActionDescriptor();
|
|
335
|
+
rgb.putDouble(s2t("red"), parseInt(hex.substr(0, 2), 16));
|
|
336
|
+
rgb.putDouble(s2t("grain"), parseInt(hex.substr(2, 2), 16));
|
|
337
|
+
rgb.putDouble(s2t("blue"), parseInt(hex.substr(4, 2), 16));
|
|
338
|
+
return rgb;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// stroke / shadow as layer effects (one setd: setting layerEffects replaces all effects of the layer)
|
|
342
|
+
function applyEffects(s) {
|
|
343
|
+
var fx = new ActionDescriptor();
|
|
344
|
+
fx.putUnitDouble(s2t("scale"), s2t("percentUnit"), 100);
|
|
345
|
+
if (s.stroke) {
|
|
346
|
+
var st = new ActionDescriptor();
|
|
347
|
+
st.putBoolean(s2t("enabled"), true);
|
|
348
|
+
st.putEnumerated(s2t("style"), s2t("frameStyle"), s2t("outsetFrame"));
|
|
349
|
+
st.putEnumerated(s2t("paintType"), s2t("frameFill"), s2t("solidColor"));
|
|
350
|
+
st.putEnumerated(s2t("mode"), s2t("blendMode"), s2t("normal"));
|
|
351
|
+
st.putUnitDouble(s2t("opacity"), s2t("percentUnit"), 100);
|
|
352
|
+
st.putUnitDouble(s2t("size"), s2t("pixelsUnit"), s.stroke.width);
|
|
353
|
+
st.putObject(s2t("color"), s2t("RGBColor"), rgbDesc(s.stroke.color));
|
|
354
|
+
fx.putObject(s2t("frameFX"), s2t("frameFX"), st);
|
|
355
|
+
}
|
|
356
|
+
if (s.shadow) {
|
|
357
|
+
var sh = new ActionDescriptor();
|
|
358
|
+
sh.putBoolean(s2t("enabled"), true);
|
|
359
|
+
sh.putEnumerated(s2t("mode"), s2t("blendMode"), s2t("normal"));
|
|
360
|
+
sh.putObject(s2t("color"), s2t("RGBColor"), rgbDesc(s.shadow.color));
|
|
361
|
+
sh.putUnitDouble(s2t("opacity"), s2t("percentUnit"), 100);
|
|
362
|
+
sh.putBoolean(s2t("useGlobalAngle"), false);
|
|
363
|
+
sh.putUnitDouble(s2t("localLightingAngle"), s2t("angleUnit"), s.shadow.angle);
|
|
364
|
+
sh.putUnitDouble(s2t("distance"), s2t("pixelsUnit"), s.shadow.distance);
|
|
365
|
+
sh.putUnitDouble(s2t("chokeMatte"), s2t("pixelsUnit"), 0);
|
|
366
|
+
sh.putUnitDouble(s2t("blur"), s2t("pixelsUnit"), s.shadow.blur);
|
|
367
|
+
sh.putUnitDouble(s2t("noise"), s2t("percentUnit"), 0);
|
|
368
|
+
sh.putBoolean(s2t("antiAlias"), false);
|
|
369
|
+
sh.putBoolean(s2t("layerConceals"), true);
|
|
370
|
+
fx.putObject(s2t("dropShadow"), s2t("dropShadow"), sh);
|
|
371
|
+
}
|
|
372
|
+
var ref = new ActionReference();
|
|
373
|
+
ref.putProperty(c2t("Prpr"), s2t("layerEffects"));
|
|
374
|
+
ref.putEnumerated(c2t("Lyr "), c2t("Ordn"), c2t("Trgt"));
|
|
375
|
+
var d = new ActionDescriptor();
|
|
376
|
+
d.putReference(c2t("null"), ref);
|
|
377
|
+
d.putObject(c2t("T "), s2t("layerEffects"), fx);
|
|
378
|
+
executeAction(c2t("setd"), d, DialogModes.NO);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
function applySegments(segs) {
|
|
382
|
+
var ref = new ActionReference();
|
|
383
|
+
ref.putEnumerated(c2t("Lyr "), c2t("Ordn"), c2t("Trgt"));
|
|
384
|
+
var textDesc = executeActionGet(ref).getObjectValue(s2t("textKey"));
|
|
385
|
+
var styles = textDesc.getList(s2t("textStyleRange"));
|
|
386
|
+
var list = new ActionList();
|
|
387
|
+
for (var i = 0; i < segs.length; i++) {
|
|
388
|
+
var g = segs[i];
|
|
389
|
+
var st = styles.getObjectValue(0).getObjectValue(s2t("textStyle"));
|
|
390
|
+
st.putUnitDouble(s2t("size"), s2t("pointsUnit"), g.size);
|
|
391
|
+
if (st.hasKey(s2t("impliedFontSize"))) st.putUnitDouble(s2t("impliedFontSize"), s2t("pointsUnit"), g.size);
|
|
392
|
+
if (st.hasKey(s2t("fontName"))) st.erase(s2t("fontName"));
|
|
393
|
+
if (st.hasKey(s2t("fontStyleName"))) st.erase(s2t("fontStyleName"));
|
|
394
|
+
st.putString(s2t("fontPostScriptName"), g.font);
|
|
395
|
+
st.putObject(s2t("color"), s2t("RGBColor"), rgbDesc(g.color));
|
|
396
|
+
var r = new ActionDescriptor();
|
|
397
|
+
r.putInteger(s2t("from"), g.from);
|
|
398
|
+
r.putInteger(s2t("to"), g.to);
|
|
399
|
+
r.putObject(s2t("textStyle"), s2t("textStyle"), st);
|
|
400
|
+
list.putObject(s2t("textStyleRange"), r);
|
|
401
|
+
}
|
|
402
|
+
textDesc.putList(s2t("textStyleRange"), list);
|
|
403
|
+
var set = new ActionDescriptor();
|
|
404
|
+
set.putReference(c2t("null"), ref);
|
|
405
|
+
set.putObject(c2t("T "), s2t("textLayer"), textDesc);
|
|
406
|
+
executeAction(c2t("setd"), set, DialogModes.NO);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
${fitScale.toString()}
|
|
410
|
+
|
|
411
|
+
// text size (and leading, runs) times k; runs are re-applied because t.size resets them
|
|
412
|
+
function style(l, s, k) {
|
|
413
|
+
var t = l.textItem;
|
|
414
|
+
t.size = s.size * k;
|
|
415
|
+
if (s.leading !== null) t.leading = s.leading * k;
|
|
416
|
+
if (s.segments.length) {
|
|
417
|
+
var g = [];
|
|
418
|
+
for (var i = 0; i < s.segments.length; i++) {
|
|
419
|
+
var o = s.segments[i];
|
|
420
|
+
g.push({ from: o.from, to: o.to, size: o.size * k, color: o.color, font: o.font });
|
|
421
|
+
}
|
|
422
|
+
app.activeDocument.activeLayer = l;
|
|
423
|
+
applySegments(g);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
// point text larger than the box: shrink all sizes by the same ratio, down to BP.minScale.
|
|
428
|
+
// if it still does not fit, put it back to 100% (checkResult reports overflow)
|
|
429
|
+
function fit(l, s) {
|
|
430
|
+
var k = 1, b, n;
|
|
431
|
+
for (n = 0; n < 3; n++) {
|
|
432
|
+
b = bounds(l);
|
|
433
|
+
if (b[2] - b[0] <= s.box.w && b[3] - b[1] <= s.box.h) return k;
|
|
434
|
+
var f = fitScale(b[2] - b[0], b[3] - b[1], s.box.w, s.box.h, BP.minScale / k);
|
|
435
|
+
if (f >= 1) break;
|
|
436
|
+
k = Math.floor(k * f * 1000) / 1000;
|
|
437
|
+
style(l, s, k);
|
|
438
|
+
}
|
|
439
|
+
b = bounds(l);
|
|
440
|
+
if (b[2] - b[0] <= s.box.w && b[3] - b[1] <= s.box.h) return k;
|
|
441
|
+
if (k !== 1) style(l, s, 1);
|
|
442
|
+
return 1;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
// point text: move the drawn bounds so the aligned edge sits on the box edge
|
|
446
|
+
// (horizontal: align axis + top / vertical: right + align axis).
|
|
447
|
+
// translate() was seen to move only ~96% of the asked distance (12/4 probe), so measure again and correct
|
|
448
|
+
function place(l, s) {
|
|
449
|
+
var x = s.box.x, y = s.box.y, w = s.box.w, h = s.box.h;
|
|
450
|
+
for (var n = 0; n < 4; n++) {
|
|
451
|
+
var b = bounds(l), dx, dy;
|
|
452
|
+
if (!s.vertical) {
|
|
453
|
+
dx = s.align === "left" ? x - b[0] : s.align === "right" ? x + w - b[2] : x + w / 2 - (b[0] + b[2]) / 2;
|
|
454
|
+
dy = y - b[1];
|
|
455
|
+
} else {
|
|
456
|
+
dx = x + w - b[2];
|
|
457
|
+
dy = s.align === "left" ? y - b[1] : s.align === "right" ? y + h - b[3] : y + h / 2 - (b[1] + b[3]) / 2;
|
|
458
|
+
}
|
|
459
|
+
if (Math.abs(dx) < 0.5 && Math.abs(dy) < 0.5) return;
|
|
460
|
+
l.translate(dx, dy);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
var R = { ok: false, photoshop: app.version, layers: [], effects: [], scaled: [] };
|
|
465
|
+
var keep = { dialogs: app.displayDialogs, ruler: app.preferences.rulerUnits, type: app.preferences.typeUnits };
|
|
466
|
+
var doc = null, at = "";
|
|
467
|
+
try {
|
|
468
|
+
app.displayDialogs = DialogModes.NO;
|
|
469
|
+
app.preferences.rulerUnits = Units.PIXELS;
|
|
470
|
+
app.preferences.typeUnits = TypeUnits.POINTS;
|
|
471
|
+
at = "plate";
|
|
472
|
+
doc = app.open(new File(BP.plate));
|
|
473
|
+
if (px(doc.width) !== BP.canvas.w || px(doc.height) !== BP.canvas.h)
|
|
474
|
+
throw new Error("plate size " + px(doc.width) + "x" + px(doc.height) + " != canvas " + BP.canvas.w + "x" + BP.canvas.h);
|
|
475
|
+
// 72ppi so that pt == px (pixels unchanged)
|
|
476
|
+
if (doc.resolution !== 72) doc.resizeImage(undefined, undefined, 72, ResampleMethod.NONE);
|
|
477
|
+
var base = doc.artLayers[doc.artLayers.length - 1];
|
|
478
|
+
if (base.isBackgroundLayer) base.isBackgroundLayer = false;
|
|
479
|
+
base.name = BP.plateLayer;
|
|
480
|
+
for (var i = 0; i < BP.layers.length; i++) {
|
|
481
|
+
var s = BP.layers[i];
|
|
482
|
+
at = s.name;
|
|
483
|
+
app.activeDocument = doc;
|
|
484
|
+
var l = doc.artLayers.add();
|
|
485
|
+
l.kind = LayerKind.TEXT;
|
|
486
|
+
var t = l.textItem;
|
|
487
|
+
if (s.paragraph) { t.kind = TextType.PARAGRAPHTEXT; }
|
|
488
|
+
t.direction = s.vertical ? Direction.VERTICAL : Direction.HORIZONTAL;
|
|
489
|
+
t.contents = s.text;
|
|
490
|
+
t.font = s.font;
|
|
491
|
+
t.size = s.size;
|
|
492
|
+
t.color = color(s.color);
|
|
493
|
+
t.justification = s.align === "left" ? Justification.LEFT : s.align === "right" ? Justification.RIGHT : Justification.CENTER;
|
|
494
|
+
t.tracking = s.tracking;
|
|
495
|
+
if (s.leading === null) t.useAutoLeading = true; else { t.useAutoLeading = false; t.leading = s.leading; }
|
|
496
|
+
if (s.paragraph) {
|
|
497
|
+
t.width = new UnitValue(s.box.w, "px");
|
|
498
|
+
t.height = new UnitValue(s.box.h, "px");
|
|
499
|
+
t.position = [new UnitValue(s.box.x, "px"), new UnitValue(s.box.y, "px")];
|
|
500
|
+
} else {
|
|
501
|
+
t.position = [new UnitValue(s.box.x, "px"), new UnitValue(s.box.y + s.size, "px")];
|
|
502
|
+
}
|
|
503
|
+
if (s.segments.length) { doc.activeLayer = l; applySegments(s.segments); }
|
|
504
|
+
if (!s.paragraph) {
|
|
505
|
+
var k = fit(l, s);
|
|
506
|
+
if (k < 1) R.scaled.push({ layer: s.name, ratio: k });
|
|
507
|
+
place(l, s);
|
|
508
|
+
}
|
|
509
|
+
if (s.stroke || s.shadow) {
|
|
510
|
+
// a failed effect does not stop the layer: it is reported and a person adds it by hand
|
|
511
|
+
doc.activeLayer = l;
|
|
512
|
+
try { applyEffects(s); R.effects.push({ layer: s.name, ok: true }); }
|
|
513
|
+
catch (fxErr) { R.effects.push({ layer: s.name, ok: false, error: String(fxErr) }); }
|
|
514
|
+
}
|
|
515
|
+
if (s.rotate) l.rotate(s.rotate, AnchorPosition.MIDDLECENTER);
|
|
516
|
+
l.name = s.name;
|
|
517
|
+
}
|
|
518
|
+
at = "save";
|
|
519
|
+
doc.saveAs(new File(BP.psd), new PhotoshopSaveOptions(), true);
|
|
520
|
+
doc.saveAs(new File(BP.png), new PNGSaveOptions(), true);
|
|
521
|
+
for (var j = 0; j < doc.artLayers.length; j++) {
|
|
522
|
+
var a = doc.artLayers[j];
|
|
523
|
+
var isText = a.kind === LayerKind.TEXT;
|
|
524
|
+
R.layers.push({ name: a.name, text: isText, bounds: bounds(a), font: isText ? a.textItem.font : null,
|
|
525
|
+
justification: isText ? String(a.textItem.justification) : null });
|
|
526
|
+
}
|
|
527
|
+
R.ok = true;
|
|
528
|
+
} catch (e) {
|
|
529
|
+
R.error = String(e);
|
|
530
|
+
R.line = e.line;
|
|
531
|
+
R.at = at;
|
|
532
|
+
} finally {
|
|
533
|
+
// close only the document this script opened (never touch documents a person has open)
|
|
534
|
+
if (doc) { try { doc.close(SaveOptions.DONOTSAVECHANGES); } catch (e2) {} }
|
|
535
|
+
app.displayDialogs = keep.dialogs;
|
|
536
|
+
app.preferences.rulerUnits = keep.ruler;
|
|
537
|
+
app.preferences.typeUnits = keep.type;
|
|
538
|
+
}
|
|
539
|
+
return enc(R);
|
|
540
|
+
})();
|
|
541
|
+
`;
|
|
542
|
+
/** 位置のずれの許し: 16px か、揃えの向きの枠の長さの 3% の大きい方まで */
|
|
543
|
+
export const DRIFT_MIN_PX = 16;
|
|
544
|
+
export const DRIFT_RATIO = 0.03;
|
|
545
|
+
/** 揃えの向きで、外形と枠の端の差を測る。回した層は外形が回転で変わるので測らない(null) */
|
|
546
|
+
export function measureDrift(l, bounds) {
|
|
547
|
+
if (l.rotate)
|
|
548
|
+
return null;
|
|
549
|
+
const [left, top, right, bottom] = bounds;
|
|
550
|
+
const { x, y, w, h } = l.box;
|
|
551
|
+
let edge;
|
|
552
|
+
let px;
|
|
553
|
+
let span;
|
|
554
|
+
if (l.orientation === "horizontal") {
|
|
555
|
+
span = w;
|
|
556
|
+
if (l.align === "left")
|
|
557
|
+
[edge, px] = ["left", left - x];
|
|
558
|
+
else if (l.align === "right")
|
|
559
|
+
[edge, px] = ["right", right - (x + w)];
|
|
560
|
+
else
|
|
561
|
+
[edge, px] = ["center", (left + right) / 2 - (x + w / 2)];
|
|
562
|
+
}
|
|
563
|
+
else {
|
|
564
|
+
span = h;
|
|
565
|
+
if (l.align === "left")
|
|
566
|
+
[edge, px] = ["top", top - y];
|
|
567
|
+
else if (l.align === "right")
|
|
568
|
+
[edge, px] = ["bottom", bottom - (y + h)];
|
|
569
|
+
else
|
|
570
|
+
[edge, px] = ["middle", (top + bottom) / 2 - (y + h / 2)];
|
|
571
|
+
}
|
|
572
|
+
return Math.abs(px) > Math.max(DRIFT_MIN_PX, span * DRIFT_RATIO) ? { layer: l.name, edge, px } : null;
|
|
573
|
+
}
|
|
574
|
+
/** はみ出しの許し: 枠の幅(高さ)の 10% まで */
|
|
575
|
+
export const OVERFLOW_RATIO = 0.1;
|
|
576
|
+
/** 回した枠を囲む、軸にそろった枠(中心で回す) */
|
|
577
|
+
export function rotatedBox(b, deg) {
|
|
578
|
+
if (!deg)
|
|
579
|
+
return b;
|
|
580
|
+
const r = (deg * Math.PI) / 180;
|
|
581
|
+
const w = Math.abs(b.w * Math.cos(r)) + Math.abs(b.h * Math.sin(r));
|
|
582
|
+
const h = Math.abs(b.w * Math.sin(r)) + Math.abs(b.h * Math.cos(r));
|
|
583
|
+
return { x: b.x + b.w / 2 - w / 2, y: b.y + b.h / 2 - h / 2, w, h };
|
|
584
|
+
}
|
|
585
|
+
export function checkResult(bp, result, fonts) {
|
|
586
|
+
const problems = [];
|
|
587
|
+
if (!result.ok) {
|
|
588
|
+
problems.push(`Photoshop で止まりました(${result.at ?? "?"}・${result.line ?? "?"}行目): ${result.error ?? "理由不明"}`);
|
|
589
|
+
return { ok: false, overflow: [], drift: [], scaled: [], effectsMissing: [], substituted: fonts.substituted, problems };
|
|
590
|
+
}
|
|
591
|
+
const byName = new Map(result.layers.map((l) => [l.name, l]));
|
|
592
|
+
const bottom = result.layers[result.layers.length - 1];
|
|
593
|
+
if (bottom?.name !== PLATE_LAYER)
|
|
594
|
+
problems.push(`一番下の層が「${PLATE_LAYER}」ではありません(${bottom?.name ?? "層がありません"})`);
|
|
595
|
+
if (result.layers.length !== bp.layers.length + 1)
|
|
596
|
+
problems.push(`層の数が ${result.layers.length} です(設計図では ${bp.layers.length + 1})`);
|
|
597
|
+
const overflow = [];
|
|
598
|
+
const drift = [];
|
|
599
|
+
for (const l of bp.layers) {
|
|
600
|
+
const got = byName.get(l.name);
|
|
601
|
+
if (!got) {
|
|
602
|
+
problems.push(`層「${l.name}」がありません`);
|
|
603
|
+
continue;
|
|
604
|
+
}
|
|
605
|
+
if (!got.text)
|
|
606
|
+
problems.push(`層「${l.name}」が文字の層ではありません`);
|
|
607
|
+
// Photoshop の textItem.font は先頭の字の書体を返す
|
|
608
|
+
const f = fonts.layers[l.name];
|
|
609
|
+
const head = l.runs.findIndex((r) => r.from === 0);
|
|
610
|
+
const want = f && (head >= 0 ? f.runs[head] ?? f.font : f.font);
|
|
611
|
+
if (want && got.font !== want)
|
|
612
|
+
problems.push(`層「${l.name}」の書体が ${got.font} です(${want} のはず)`);
|
|
613
|
+
const b = rotatedBox(l.box, l.rotate);
|
|
614
|
+
const [left, top, right, bot] = got.bounds;
|
|
615
|
+
const mx = b.w * OVERFLOW_RATIO;
|
|
616
|
+
const my = b.h * OVERFLOW_RATIO;
|
|
617
|
+
if (b.x - left >= mx || right - (b.x + b.w) >= mx || b.y - top >= my || bot - (b.y + b.h) >= my)
|
|
618
|
+
overflow.push(l.name);
|
|
619
|
+
const d = measureDrift(l, got.bounds);
|
|
620
|
+
if (d)
|
|
621
|
+
drift.push(d);
|
|
622
|
+
}
|
|
623
|
+
const effectsMissing = [];
|
|
624
|
+
for (const l of bp.layers) {
|
|
625
|
+
const want = [...(l.stroke ? ["stroke"] : []), ...(l.shadow ? ["shadow"] : [])];
|
|
626
|
+
if (!want.length)
|
|
627
|
+
continue;
|
|
628
|
+
const got = result.effects?.find((e) => e.layer === l.name);
|
|
629
|
+
if (!got?.ok)
|
|
630
|
+
effectsMissing.push({ layer: l.name, want, ...(got?.error ? { error: got.error } : {}) });
|
|
631
|
+
}
|
|
632
|
+
return { ok: problems.length === 0, overflow, drift, scaled: result.scaled ?? [], effectsMissing, substituted: fonts.substituted, problems };
|
|
633
|
+
}
|
package/dist/client.js
CHANGED
|
@@ -27,7 +27,7 @@ export function explain(status, body) {
|
|
|
27
27
|
? body.error
|
|
28
28
|
: `サーバーが ${status} を返しました`;
|
|
29
29
|
}
|
|
30
|
-
async function call(path, token, init = {}, f = fetch) {
|
|
30
|
+
export async function call(path, token, init = {}, f = fetch) {
|
|
31
31
|
const get = typeof token === "function" ? token : async () => token;
|
|
32
32
|
const send = (t) => f(`${base()}${path}`, {
|
|
33
33
|
...init,
|
package/dist/index.js
CHANGED
|
@@ -7,6 +7,7 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
|
7
7
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
8
8
|
import { z } from "zod";
|
|
9
9
|
import { withdrawChange, AgentError, CHANGE_AREAS, CHANGE_URGENCIES, appeals, delivery, myRequests, planAct, planStart, planStatus, productions, request, requestChange, productionText } from "./client.js";
|
|
10
|
+
import { MODES, PHOTO_ANSWERS, SIZES, fetchSamples, finishPsd, finishText, stillAct, stillPhoto, stillPlanText, stillStart, stillStatus } from "./still.js";
|
|
10
11
|
// agent-core は CommonJS なので、名前つきの import では起動のときに落ちる(default から取る)
|
|
11
12
|
import portalClient from "@funny-booth/agent-core/dist/portalClient.js";
|
|
12
13
|
const portal = portalClient.portalClientFromEnv(); // PORTAL_URL・TOOL_TOKEN が無ければ null
|
|
@@ -170,6 +171,130 @@ server.registerTool("video_plan_approve", {
|
|
|
170
171
|
return fail(e);
|
|
171
172
|
}
|
|
172
173
|
});
|
|
174
|
+
// ---- 静止画の制作(設計書 still-design.md §2.2・動画の video_plan_* と名前と書き方をそろえる) ----
|
|
175
|
+
server.registerTool("still_plan_start", {
|
|
176
|
+
description: "静止画(バナー広告)の企画を始める。訴求 → トンマナ → 構図 → 色味 → 装飾 → その他 → お手本(AI が作る見本の画像)の7段で進む。" +
|
|
177
|
+
"呼ぶ前に、進め方(mode)を必ず聞く:「お任せ(お手本まで一気に作る)か、一段ずつ(段ごとに OK をもらって進む)か、どちらにしますか」。聞かずに決めない。" +
|
|
178
|
+
"企画はシート(Google スプレッドシート)に書き出す。数分かかるので、still_plan_status で確かめる。" +
|
|
179
|
+
"お任せでも、お手本への OK(still_plan_approve)は任意。Photoshop の仕上げ(still_finish_psd)は OK の前でもできる。" +
|
|
180
|
+
"依頼の文章(wish)と、人が出した案(human_plan)は言葉のまま渡す(要約・言い換えをしない)",
|
|
181
|
+
inputSchema: {
|
|
182
|
+
sku: z.string().describe("商品の名前(例: ブラトップ・ヒートインナー)"),
|
|
183
|
+
mode: z.enum(MODES).describe("omakase=お任せ(お手本まで止まらずに作る。写真や要確認があればそこで止まって聞く) / step=一段ずつ(段ごとに止まって OK を待つ)"),
|
|
184
|
+
wish: z.string().min(1).max(2000).optional().describe("依頼した人の文章(そのまま・要約しない)"),
|
|
185
|
+
human_plan: z.union([z.string().min(1).max(4000), z.record(z.string(), z.string().max(2000))]).optional()
|
|
186
|
+
.describe("依頼した人が出した案(言葉のまま)。段ごとなら {\"訴求\": \"…\", \"構図\": \"…\"} の形(訴求・トンマナ・構図・色味・装飾・その他)、まとめて話されたら文章のまま"),
|
|
187
|
+
references: z.array(z.string().min(1).max(500)).max(5).optional().describe("参考にしたい広告(DPro の URL か番号・5つまで)。無ければ AI が伸びている広告から選ぶ"),
|
|
188
|
+
assignee: z.string().max(100).optional().describe("企画を頼む相手(ご本人が言った呼び名のまま)。自分で進めるときは渡さない"),
|
|
189
|
+
test: z.boolean().optional().describe("動作確認の試験のときだけ true(依頼した人が「試験」「動作確認」と言ったとき)。ふだんは渡さない"),
|
|
190
|
+
},
|
|
191
|
+
}, async (args) => {
|
|
192
|
+
try {
|
|
193
|
+
const r = await stillStart(token(), args);
|
|
194
|
+
return text([r.message, `企画の番号: ${r.id}(バナー名 ${r.banner})`, ...(r.sheet ? [`シート: ${r.sheet}`] : [])].join("\n"));
|
|
195
|
+
}
|
|
196
|
+
catch (e) {
|
|
197
|
+
return fail(e);
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
server.registerTool("still_plan_status", {
|
|
201
|
+
description: "静止画の企画の様子(今の段・作っている途中か・最新の案の要点・OK 済みの段・聞くこと(写真・要確認)・写真待ち・お手本の画像・Photoshop の仕上げができるか・シートと共有タブの URL)。" +
|
|
202
|
+
"番号を渡せばその1件(お手本ができていれば、画像をこの Mac に取ってきてその場所を返す)、渡さなければ新しい順に10件。" +
|
|
203
|
+
"「聞くこと」があれば、そのまま相手に聞き、still_photo_answer で答える。「写真待ち」は、撮れたら写真を送ってもらう",
|
|
204
|
+
inputSchema: {
|
|
205
|
+
id: z.string().optional().describe("企画の番号(still_plan_start が返したもの)"),
|
|
206
|
+
wait: z.boolean().optional().describe("true なら、作っている途中のとき、できるまで最大50秒待ってから返す(番号が要る)。" +
|
|
207
|
+
"まだなら、もう一度 wait: true で呼ぶ。相手に「できた?」と声をかけてもらわずに待てる"),
|
|
208
|
+
},
|
|
209
|
+
}, async ({ id, wait }) => {
|
|
210
|
+
try {
|
|
211
|
+
const list = await stillStatus(token(), id, fetch, Boolean(id && wait));
|
|
212
|
+
if (id)
|
|
213
|
+
return text(stillPlanText(list[0], await fetchSamples(token(), list[0])));
|
|
214
|
+
return text(list.length ? list.map((p) => stillPlanText(p)).join("\n\n") : "静止画の企画はまだありません");
|
|
215
|
+
}
|
|
216
|
+
catch (e) {
|
|
217
|
+
return fail(e);
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
server.registerTool("still_plan_revise", {
|
|
221
|
+
description: "静止画の企画の、今の段の案を直す。会話で言われたこと(note・言葉のまま)と、シートで書き換えられたセルを AI が読んで、直した案を新しい版として出す(前の版は残る)。数分かかる",
|
|
222
|
+
inputSchema: { id: z.string(), note: z.string().max(2000).optional().describe("会話で言われた直し(言葉のまま)") },
|
|
223
|
+
}, async ({ id, note }) => {
|
|
224
|
+
try {
|
|
225
|
+
return text((await stillAct(token(), "revise", { id, note })).message);
|
|
226
|
+
}
|
|
227
|
+
catch (e) {
|
|
228
|
+
return fail(e);
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
server.registerTool("still_plan_redo", {
|
|
232
|
+
description: "静止画の企画の、今の段の案を、前の案とは違う方向で作り直す(進めている方が「まるっと変えたい」と言ったとき)。note に理由を言葉のまま",
|
|
233
|
+
inputSchema: { id: z.string(), note: z.string().max(2000).optional() },
|
|
234
|
+
}, async ({ id, note }) => {
|
|
235
|
+
try {
|
|
236
|
+
return text((await stillAct(token(), "redo", { id, note })).message);
|
|
237
|
+
}
|
|
238
|
+
catch (e) {
|
|
239
|
+
return fail(e);
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
server.registerTool("still_plan_approve", {
|
|
243
|
+
description: "静止画の企画の、今の段の最新の案に OK を出して次の段へ進む(お任せのときは、お手本への OK を記録する)。" +
|
|
244
|
+
"目の前の方が会話ではっきり OK と言ったときだけ呼ぶ(あいまいなら聞き直す・あなたが判断して呼ばない)。" +
|
|
245
|
+
"OK を出せるのは受け口が許した方だけ(許されていなければ断りの文が返るので、そのまま伝える)",
|
|
246
|
+
inputSchema: {
|
|
247
|
+
id: z.string(),
|
|
248
|
+
test: z.boolean().optional().describe("動作確認の試験のときだけ true"),
|
|
249
|
+
},
|
|
250
|
+
}, async ({ id, test }) => {
|
|
251
|
+
try {
|
|
252
|
+
const r = await stillAct(token(), "approve", { id, test: test === true });
|
|
253
|
+
return text(r.message);
|
|
254
|
+
}
|
|
255
|
+
catch (e) {
|
|
256
|
+
return fail(e);
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
server.registerTool("still_photo_answer", {
|
|
260
|
+
description: "静止画の企画で聞いたこと(still_plan_status の「聞くこと」「写真待ち」)に答える。" +
|
|
261
|
+
"写真には can_shoot=これから撮れる(届くまで「写真待ち」で止まる) / cannot=撮れない(その写真を使わない構図に作り直す) / " +
|
|
262
|
+
"upload=手元の写真を送る(file にこの Mac の写真の場所を渡す・PNG・JPEG・HEIC。長い辺 2400px の JPEG に縮めて送り、1.9MB に収まらなければ品質・大きさを下げる)。" +
|
|
263
|
+
"「写真待ち」には upload か cannot だけ。要確認には confirmed=確かめた・そのままでよい(直すなら still_plan_revise)。" +
|
|
264
|
+
"相手が写真をこの会話に貼ったときは、保存されている場所を file に渡す",
|
|
265
|
+
inputSchema: {
|
|
266
|
+
id: z.string(),
|
|
267
|
+
ask: z.number().int().min(1).describe("聞くことの番号"),
|
|
268
|
+
answer: z.enum(PHOTO_ANSWERS).describe("写真: can_shoot / cannot / upload、要確認: confirmed"),
|
|
269
|
+
file: z.string().min(1).max(1000).optional().describe("answer が upload のときだけ: 写真のファイルの場所(例 ~/Desktop/カップ.jpg)"),
|
|
270
|
+
},
|
|
271
|
+
}, async (args) => {
|
|
272
|
+
try {
|
|
273
|
+
return text((await stillPhoto(token(), args)).message);
|
|
274
|
+
}
|
|
275
|
+
catch (e) {
|
|
276
|
+
return fail(e);
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
server.registerTool("still_finish_psd", {
|
|
280
|
+
description: "お手本ができた静止画の企画を、このパソコンの Photoshop で仕上げる。文字を消した土台の上に、Photoshop の文字の層を置いた PSD と PNG を、" +
|
|
281
|
+
"ダウンロードフォルダの「静止画_<バナー名>」に保存する(1サイズ1分ほど。初めての回は書体の一覧を集めるので数分かかる)。" +
|
|
282
|
+
"返ってきた「人が直す所」(置き換えた書体・枠からはみ出した文字・ずれた位置・縮めた文字・入らなかった縁取りや影)は、省かずにそのまま伝える。" +
|
|
283
|
+
"初めての回に macOS の「Photoshop の操作を許可」の確認が出たら、許可を押してもらう。止まったときは返ってきた文のとおりに案内し、済んだらもう一度呼ぶ",
|
|
284
|
+
inputSchema: {
|
|
285
|
+
id: z.string().describe("企画の番号"),
|
|
286
|
+
sizes: z.array(z.enum(SIZES)).min(1).max(2).optional().describe("作る大きさ(1x1=正方形・9x16=縦長)。渡さなければ両方"),
|
|
287
|
+
},
|
|
288
|
+
}, async ({ id, sizes }) => {
|
|
289
|
+
try {
|
|
290
|
+
const r = await finishPsd(id, sizes ?? SIZES, { token: token() });
|
|
291
|
+
const t = finishText(r);
|
|
292
|
+
return r.stopped ? { ...text(t), isError: true } : text(t);
|
|
293
|
+
}
|
|
294
|
+
catch (e) {
|
|
295
|
+
return fail(e);
|
|
296
|
+
}
|
|
297
|
+
});
|
|
173
298
|
server.registerTool("video_delivery", {
|
|
174
299
|
description: "最終確認(ゲート②)で承認された動画の納品セット(Premiere の編集データ・素材・テロップ一式)を、このパソコンのダウンロードフォルダに zip で保存する",
|
|
175
300
|
inputSchema: { name: z.string().describe("制作名(video_productions で分かる)") },
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// その Mac の Photoshop を動かす部分(外とやり取りする)。中身を決めるのは blueprint.ts(純粋)。
|
|
2
|
+
// - findPhotoshop: /Applications/Adobe Photoshop 20xx/ の一番新しいもの
|
|
3
|
+
// - runJsx: osascript の do javascript を時間の上限つきで動かす(返り値は JSX の最後の値)
|
|
4
|
+
// - listFonts: app.fonts の PostScript 名・ファミリー・スタイル
|
|
5
|
+
// - render: 設計図から PSD と PNG を作る(土台の PNG は outDir に置いてから呼ぶ)
|
|
6
|
+
import { execFile } from "node:child_process";
|
|
7
|
+
import { existsSync } from "node:fs";
|
|
8
|
+
import { readdir, writeFile } from "node:fs/promises";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
import { checkResult, toJsx } from "./blueprint.js";
|
|
11
|
+
export const NOT_FOUND_MESSAGE = "Photoshop が見つかりません(/Applications/Adobe Photoshop 20xx/)";
|
|
12
|
+
/** 一番新しい Photoshop。無ければ null */
|
|
13
|
+
export async function findPhotoshop(apps = "/Applications") {
|
|
14
|
+
let names;
|
|
15
|
+
try {
|
|
16
|
+
names = await readdir(apps);
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
const found = names
|
|
22
|
+
.map((n) => ({ n, m: /^Adobe Photoshop (20\d\d)$/.exec(n) }))
|
|
23
|
+
.filter((x) => x.m !== null && existsSync(join(apps, x.n, `${x.n}.app`)))
|
|
24
|
+
.map((x) => ({ name: x.n, year: Number(x.m[1]), path: join(apps, x.n, `${x.n}.app`) }))
|
|
25
|
+
.sort((a, b) => b.year - a.year);
|
|
26
|
+
return found[0] ?? null;
|
|
27
|
+
}
|
|
28
|
+
export class PhotoshopError extends Error {
|
|
29
|
+
}
|
|
30
|
+
/** osascript のエラーを、人に返す文にする(設計書 §5.2 の表) */
|
|
31
|
+
export function explainOsascript(stderr, timedOut) {
|
|
32
|
+
if (/-1743|not allowed|許可されていません/.test(stderr))
|
|
33
|
+
return "macOS が Photoshop の操作を許可していません。「システム設定 > プライバシーとセキュリティ > オートメーション」で、この MCP を動かしているアプリに Photoshop の操作を許可してください";
|
|
34
|
+
if (timedOut || /-1712|timed out|タイムアウト/.test(stderr))
|
|
35
|
+
return "Photoshop が時間内に返事をしませんでした。Photoshop に開いている画面(ダイアログ)があれば閉じてください。macOS の許可の確認が出ていれば許可してください";
|
|
36
|
+
return `Photoshop を動かせませんでした: ${stderr.trim()}`;
|
|
37
|
+
}
|
|
38
|
+
/** JSX のファイルを Photoshop で動かし、最後の値(文字列)を返す。jsxPath は ASCII だけの絶対パス */
|
|
39
|
+
export function runJsx(app, jsxPath, timeoutSec = 120) {
|
|
40
|
+
if (!/^\/[\x20-\x7e]+$/.test(jsxPath) || /["\\]/.test(jsxPath))
|
|
41
|
+
return Promise.reject(new PhotoshopError(`JSX の場所は ASCII だけにしてください(" と \\ も不可): ${jsxPath}`));
|
|
42
|
+
const script = [
|
|
43
|
+
`with timeout of ${timeoutSec} seconds`,
|
|
44
|
+
`tell application "${app.name}" to do javascript file (POSIX file "${jsxPath}")`,
|
|
45
|
+
"end timeout",
|
|
46
|
+
];
|
|
47
|
+
return new Promise((resolve, reject) => {
|
|
48
|
+
execFile("osascript", script.flatMap((l) => ["-e", l]), { timeout: (timeoutSec + 10) * 1000, maxBuffer: 64 * 1024 * 1024 }, (err, stdout, stderr) => {
|
|
49
|
+
if (err)
|
|
50
|
+
reject(new PhotoshopError(explainOsascript(String(stderr), err.killed === true)));
|
|
51
|
+
else
|
|
52
|
+
resolve(stdout.replace(/\n$/, ""));
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
const FONTS_JSX = String.raw `
|
|
57
|
+
(function () {
|
|
58
|
+
function q(v) { var s = ""; for (var i = 0; i < v.length; i++) { var c = v.charCodeAt(i);
|
|
59
|
+
if (c < 32 || c > 126 || c === 34 || c === 92) { var h = c.toString(16); while (h.length < 4) h = "0" + h; s += "\\u" + h; } else s += v.charAt(i); }
|
|
60
|
+
return '"' + s + '"'; }
|
|
61
|
+
var out = [], fs = app.fonts;
|
|
62
|
+
for (var i = 0; i < fs.length; i++) { var f = fs[i]; out.push("[" + q(f.postScriptName) + "," + q(f.family) + "," + q(f.style) + "]"); }
|
|
63
|
+
return "[" + out.join(",") + "]";
|
|
64
|
+
})();
|
|
65
|
+
`;
|
|
66
|
+
/** その Mac の Photoshop の書体の一覧。数千あると時間がかかるので上限は長め */
|
|
67
|
+
export async function listFonts(app, workDir, timeoutSec = 180) {
|
|
68
|
+
const path = join(workDir, "fonts.jsx");
|
|
69
|
+
await writeFile(path, FONTS_JSX);
|
|
70
|
+
const rows = JSON.parse(await runJsx(app, path, timeoutSec));
|
|
71
|
+
return rows.map(([ps, family, style]) => ({ ps, family, style }));
|
|
72
|
+
}
|
|
73
|
+
/** 設計図から PSD と PNG を outDir に作る。土台(bp.plate.name)は先に outDir に置いておく */
|
|
74
|
+
export async function render(app, bp, fonts, outDir, timeoutSec = 120) {
|
|
75
|
+
const started = Date.now();
|
|
76
|
+
const path = join(outDir, `${bp.banner}_${bp.size}.jsx`);
|
|
77
|
+
await writeFile(path, toJsx(bp, fonts, outDir));
|
|
78
|
+
const out = await runJsx(app, path, timeoutSec);
|
|
79
|
+
let result;
|
|
80
|
+
try {
|
|
81
|
+
result = JSON.parse(out);
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
throw new PhotoshopError(`Photoshop の返事が読めません: ${out.slice(0, 200)}`);
|
|
85
|
+
}
|
|
86
|
+
return { result, check: checkResult(bp, result, fonts), seconds: Math.round((Date.now() - started) / 100) / 10 };
|
|
87
|
+
}
|
package/dist/still.js
ADDED
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
// 静止画の制作の受け口(/video-agent-api/still/*・設計書 §2.1)を呼ぶ部分と、Mac での仕上げ(§5.2)の進め方。
|
|
2
|
+
// 決まりは client.ts と同じ(トークン・401 の1回だけのやり直し・サーバーの文言をそのまま返す)。
|
|
3
|
+
// Photoshop を動かすのは photoshop.ts、中身を決めるのは blueprint.ts(純粋)。ここはその間をつなぐ。
|
|
4
|
+
// 設計図と土台は ~/Library/Caches/langley-video-mcp/still/<id>/ に置き、できた PSD・PNG を ~/Downloads/静止画_<バナー名>/ に写す。
|
|
5
|
+
import { execFile } from "node:child_process";
|
|
6
|
+
import { createHash } from "node:crypto";
|
|
7
|
+
import { copyFile, mkdir, mkdtemp, readFile, rm, stat, writeFile } from "node:fs/promises";
|
|
8
|
+
import { homedir, tmpdir } from "node:os";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
import { AgentError, call } from "./client.js";
|
|
11
|
+
import { outputName, parseBlueprint, planFonts } from "./blueprint.js";
|
|
12
|
+
import { NOT_FOUND_MESSAGE, PhotoshopError, findPhotoshop, listFonts, render } from "./photoshop.js";
|
|
13
|
+
export const SIZES = ["1x1", "9x16"];
|
|
14
|
+
export const MODES = ["omakase", "step"];
|
|
15
|
+
/** 聞くことへの答え。写真(kind=photo)は can_shoot・cannot・upload、要確認(kind=confirm)は confirmed */
|
|
16
|
+
export const PHOTO_ANSWERS = ["can_shoot", "cannot", "upload", "confirmed"];
|
|
17
|
+
async function json(path, token, f, body) {
|
|
18
|
+
const init = body === undefined ? {} : { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body) };
|
|
19
|
+
return (await (await call(path, token, init, f)).json());
|
|
20
|
+
}
|
|
21
|
+
/** 静止画の企画を始める(POST /still/plan)。空の任意の値は送らない */
|
|
22
|
+
export function stillStart(token, body, f = fetch) {
|
|
23
|
+
const sent = Object.fromEntries(Object.entries(body).filter(([k, v]) => v !== undefined && v !== "" && !(Array.isArray(v) && !v.length) && !(k === "test" && v !== true)));
|
|
24
|
+
return json("/still/plan", token, f, sent);
|
|
25
|
+
}
|
|
26
|
+
/** id があればその1件(wait なら作っている途中は最大50秒待つ)、無ければ新しい順に10件 */
|
|
27
|
+
export async function stillStatus(token, id, f = fetch, wait = false) {
|
|
28
|
+
if (id)
|
|
29
|
+
return [await json(`/still/plan?id=${encodeURIComponent(id)}${wait ? "&wait=50" : ""}`, token, f)];
|
|
30
|
+
return (await json("/still/plans", token, f)).plans;
|
|
31
|
+
}
|
|
32
|
+
/** 今の段を直す・作り直す・OK する */
|
|
33
|
+
export function stillAct(token, action, body, f = fetch) {
|
|
34
|
+
const sent = { id: body.id, ...(body.note ? { note: body.note } : {}), ...(body.test ? { test: true } : {}) };
|
|
35
|
+
return json(`/still/plan/${action}`, token, f, sent);
|
|
36
|
+
}
|
|
37
|
+
/** ~/ で始まるパスを家のフォルダにする */
|
|
38
|
+
export const expandHome = (p) => (p === "~" ? homedir() : p.startsWith("~/") ? join(homedir(), p.slice(2)) : p);
|
|
39
|
+
/** その聞くことに出せる答え(still_api.photo と同じ。「撮れる」の後は、届けるか撮れなかったかだけ) */
|
|
40
|
+
export function answersFor(a) {
|
|
41
|
+
if (a.kind === "confirm")
|
|
42
|
+
return ["confirmed"];
|
|
43
|
+
return a.status === "can_shoot" ? ["upload", "cannot"] : ["can_shoot", "cannot", "upload"];
|
|
44
|
+
}
|
|
45
|
+
/** 送る写真の base64 の上限(still_api の上限 1.9MB・前の nginx が 2m のため) */
|
|
46
|
+
export const PHOTO_B64_MAX = 1_900_000;
|
|
47
|
+
/** 縮め方の段。最初は長い辺 2400px・品質 85、base64 が上限を超えたら品質、次に大きさを下げる */
|
|
48
|
+
export const SHRINK_STEPS = [
|
|
49
|
+
{ max: 2400, quality: 85 }, { max: 2400, quality: 70 }, { max: 2000, quality: 70 }, { max: 1600, quality: 70 }, { max: 1200, quality: 60 },
|
|
50
|
+
];
|
|
51
|
+
const b64Len = (n) => Math.ceil(n / 3) * 4;
|
|
52
|
+
const mb = (n) => `${(n / 1_000_000).toFixed(1)}MB`;
|
|
53
|
+
const isPng = (b) => b.subarray(0, 8).equals(Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]));
|
|
54
|
+
const isJpeg = (b) => b.length >= 3 && b[0] === 0xff && b[1] === 0xd8 && b[2] === 0xff;
|
|
55
|
+
/** HEIC・HEIF(iPhone の写真)。ftyp の箱の種類で見分ける */
|
|
56
|
+
const isHeif = (b) => b.subarray(4, 8).toString("latin1") === "ftyp" && /^(heic|heix|hevc|hevx|heim|heis|mif1|msf1)$/.test(b.subarray(8, 12).toString("latin1"));
|
|
57
|
+
function sips(args) {
|
|
58
|
+
return new Promise((ok, ng) => {
|
|
59
|
+
execFile("sips", args, { timeout: 60_000 }, (e, out, err) => e ? ng(new AgentError(`写真を JPEG にできませんでした(sips): ${String(err || e.message).trim()}`)) : ok(String(out)));
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
export const sipsJpeg = async (from, to, { max, quality }) => {
|
|
63
|
+
// -Z は小さい写真を引き伸ばすので、長い辺が上限を超えるときだけ付ける
|
|
64
|
+
const out = await sips(["-g", "pixelWidth", "-g", "pixelHeight", from]);
|
|
65
|
+
const long = Math.max(...[...out.matchAll(/pixel(?:Width|Height):\s*(\d+)/g)].map((m) => Number(m[1])));
|
|
66
|
+
if (!Number.isFinite(long))
|
|
67
|
+
throw new AgentError(`写真の大きさが読めませんでした(sips): ${from}`);
|
|
68
|
+
await sips(["-s", "format", "jpeg", "-s", "formatOptions", String(quality), ...(long > max ? ["-Z", String(max)] : []), from, "--out", to]);
|
|
69
|
+
};
|
|
70
|
+
/** 送る写真の中身。PNG・JPEG・HEIC を sips で縮めた JPEG にし、base64 が 1.9MB 以下になるまで品質・大きさを下げる。それ以外の形と、縮めても収まらないものは止める */
|
|
71
|
+
export async function photoBytes(file, toJpeg = sipsJpeg) {
|
|
72
|
+
const path = expandHome(file);
|
|
73
|
+
let b;
|
|
74
|
+
try {
|
|
75
|
+
b = await readFile(path);
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
throw new AgentError(`写真のファイルが読めません: ${path}`);
|
|
79
|
+
}
|
|
80
|
+
if (!isPng(b) && !isJpeg(b) && !isHeif(b))
|
|
81
|
+
throw new AgentError(`写真は PNG・JPEG・HEIC のどれかにしてください: ${path}`);
|
|
82
|
+
const tmp = await mkdtemp(join(tmpdir(), "lvm-photo-"));
|
|
83
|
+
try {
|
|
84
|
+
const out = join(tmp, "photo.jpg");
|
|
85
|
+
let last = 0;
|
|
86
|
+
for (const step of SHRINK_STEPS) {
|
|
87
|
+
await rm(out, { force: true });
|
|
88
|
+
await toJpeg(path, out, step);
|
|
89
|
+
const j = await readFile(out).catch(() => null);
|
|
90
|
+
if (!j || !isJpeg(j))
|
|
91
|
+
throw new AgentError(`写真を JPEG にできませんでした(sips の出力がありません): ${path}`);
|
|
92
|
+
last = b64Len(j.length);
|
|
93
|
+
if (last <= PHOTO_B64_MAX)
|
|
94
|
+
return j;
|
|
95
|
+
}
|
|
96
|
+
const s = SHRINK_STEPS[SHRINK_STEPS.length - 1];
|
|
97
|
+
throw new AgentError(`写真を ${mb(PHOTO_B64_MAX)} 以下に縮められなかったので送っていません(長い辺 ${s.max}px・品質 ${s.quality} でも ${mb(last)})。別の写真にしてください: ${path}`);
|
|
98
|
+
}
|
|
99
|
+
finally {
|
|
100
|
+
await rm(tmp, { recursive: true, force: true });
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/** 聞くことに答える。先に様子を見て、その聞くことに出せる答えか確かめる(写真を読む前に止める)。upload は写真を base64 で送る */
|
|
104
|
+
export async function stillPhoto(token, body, f = fetch, toJpeg = sipsJpeg) {
|
|
105
|
+
if (body.answer === "upload" && !body.file)
|
|
106
|
+
throw new AgentError("写真を送るときは、写真のファイルの場所(file)を渡してください");
|
|
107
|
+
if (body.answer !== "upload" && body.file)
|
|
108
|
+
throw new AgentError("写真のファイルを送るのは answer が upload のときだけです");
|
|
109
|
+
const [plan] = await stillStatus(token, body.id, f);
|
|
110
|
+
const a = (plan.asks ?? []).find((x) => x.n === body.ask);
|
|
111
|
+
if (!a)
|
|
112
|
+
throw new AgentError(`${body.ask}番の聞くことは、答え待ちの中にありません(still_plan_status で確かめてください)`);
|
|
113
|
+
const allowed = answersFor(a);
|
|
114
|
+
if (!allowed.includes(body.answer)) {
|
|
115
|
+
throw new AgentError(`${a.n}番(${a.kind === "photo" ? "写真" : "要確認"}${a.status === "can_shoot" ? "・写真待ち" : ""})への答えは ${allowed.join(" か ")} です`);
|
|
116
|
+
}
|
|
117
|
+
const image = body.file ? (await photoBytes(body.file, toJpeg)).toString("base64") : undefined;
|
|
118
|
+
return json("/still/plan/photo", token, f, { id: body.id, ask: body.ask, answer: body.answer, ...(image ? { image } : {}) });
|
|
119
|
+
}
|
|
120
|
+
const hm = (iso) => (iso.length >= 16 ? `${iso.slice(5, 10).replace("-", "/")} ${iso.slice(11, 16)}` : iso);
|
|
121
|
+
/** お手本の画像(受け口の相対パス・人は開けない)を stillAsset で落とし、cacheRoot/<id>/sample_*.png に置く */
|
|
122
|
+
export async function fetchSamples(token, p, f = fetch, cacheRoot = CACHE_ROOT) {
|
|
123
|
+
const out = {};
|
|
124
|
+
if (!p.sample)
|
|
125
|
+
return out;
|
|
126
|
+
if (!/^[A-Za-z0-9_-]+$/.test(p.id))
|
|
127
|
+
throw new AgentError(`企画の番号の形が違います: ${p.id}`);
|
|
128
|
+
for (const [size, rel] of Object.entries(p.sample)) {
|
|
129
|
+
const name = new URLSearchParams(rel.split("?")[1] ?? "").get("name") ?? "";
|
|
130
|
+
if (!/^sample_[0-9]+x[0-9]+\.png$/.test(name)) {
|
|
131
|
+
out[size] = { error: `受け口のお手本の場所が読めません: ${rel}` };
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
try {
|
|
135
|
+
const b = await stillAsset(token, p.id, name, f);
|
|
136
|
+
const dir = join(cacheRoot, p.id);
|
|
137
|
+
await mkdir(dir, { recursive: true });
|
|
138
|
+
await writeFile(join(dir, name), b);
|
|
139
|
+
out[size] = { path: join(dir, name) };
|
|
140
|
+
}
|
|
141
|
+
catch (e) {
|
|
142
|
+
if (!(e instanceof AgentError))
|
|
143
|
+
throw e;
|
|
144
|
+
out[size] = { error: e.message };
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return out;
|
|
148
|
+
}
|
|
149
|
+
/** 様子を、エージェントが読んでそのまま伝えられる文にする。samples はこの Mac に落としたお手本(無ければ「番号を渡すと取ってくる」) */
|
|
150
|
+
export function stillPlanText(p, samples) {
|
|
151
|
+
const who = p.for_me ? `・${p.from_name ?? ""}さんからあなたへのお願い` : p.assignee_name ? `・${p.assignee_name}さんへのお願い` : "";
|
|
152
|
+
const open = (p.asks ?? []).filter((a) => a.status !== "can_shoot");
|
|
153
|
+
const waiting = (p.asks ?? []).filter((a) => a.status === "can_shoot");
|
|
154
|
+
const hasSample = Boolean(p.sample && Object.keys(p.sample).length);
|
|
155
|
+
return [
|
|
156
|
+
`${p.test ? "【試験】" : ""}静止画の企画 ${p.id}(${p.banner}・${p.sku}・${p.mode_ja}${p.mine ? "・あなたが始めた" : ""}${who}): 今の段 ${p.stage_ja}` +
|
|
157
|
+
(p.working ? "(いま作っています。wait: true でもう一度確かめてください)" : ""),
|
|
158
|
+
...(p.error ? [`前回の作業が止まりました: ${p.error}`] : []),
|
|
159
|
+
...Object.values(p.approved ?? {}).map((a) => `OK 済み: ${a.summary}(${a.who_name}・${hm(a.at)})`),
|
|
160
|
+
...(p.latest ? [`最新の案(第${p.latest.version}版・シートのタブ「${p.latest.tab}」):`, ...p.latest.summary.map((s) => ` ${s}`)] : []),
|
|
161
|
+
...(open.length ? ["聞くこと(答えをもらってから進みます):",
|
|
162
|
+
...open.map((a) => ` ${a.n}. ${a.kind === "photo" ? "写真" : "要確認"}: ${a.text}`)] : []),
|
|
163
|
+
...(waiting.length ? ["写真待ち(撮れたら写真を送る・撮れなかったら cannot):", ...waiting.map((a) => ` ${a.n}. ${a.text}`)] : []),
|
|
164
|
+
...(hasSample ? (samples
|
|
165
|
+
? ["お手本(この Mac に置きました):", ...Object.entries(samples).map(([k, v]) => ` ${k}: ${"path" in v ? v.path : `取れませんでした: ${v.error}`}`)]
|
|
166
|
+
: ["お手本: できています(番号を渡して still_plan_status を呼ぶと、画像をこの Mac に取ってきます)"]) : []),
|
|
167
|
+
...(p.finish_ready ? ["Photoshop の仕上げができます(still_finish_psd)"] : []),
|
|
168
|
+
...(p.finish ?? []).map((x) => `Photoshop で仕上げ済み: ${x.size}(${hm(x.at)})`),
|
|
169
|
+
...(p.sheet ? [`シート: ${p.sheet}`] : []),
|
|
170
|
+
...(p.share ? [`共有タブ: ${p.share}`] : []),
|
|
171
|
+
].join("\n");
|
|
172
|
+
}
|
|
173
|
+
// ---- 仕上げ(§2.1 の下の4つと §5.2) ----
|
|
174
|
+
/** 設計図(GET /still/blueprint)。検査を通らなければ止める */
|
|
175
|
+
export async function stillBlueprint(token, id, size, f = fetch) {
|
|
176
|
+
const raw = await json(`/still/blueprint?id=${encodeURIComponent(id)}&size=${size}`, token, f);
|
|
177
|
+
let bp;
|
|
178
|
+
try {
|
|
179
|
+
bp = parseBlueprint(raw);
|
|
180
|
+
}
|
|
181
|
+
catch (e) {
|
|
182
|
+
throw new AgentError(`受け口の設計図が読めません(担当に伝えてください)。${e.message}`);
|
|
183
|
+
}
|
|
184
|
+
if (bp.id !== id || bp.size !== size)
|
|
185
|
+
throw new AgentError(`受け口の設計図が違う企画のものです(${bp.id}・${bp.size})。担当に伝えてください`);
|
|
186
|
+
return bp;
|
|
187
|
+
}
|
|
188
|
+
/** 画像(GET /still/asset)の中身 */
|
|
189
|
+
export async function stillAsset(token, id, name, f = fetch) {
|
|
190
|
+
const res = await call(`/still/asset?id=${encodeURIComponent(id)}&name=${encodeURIComponent(name)}`, token, {}, f);
|
|
191
|
+
return Buffer.from(await res.arrayBuffer());
|
|
192
|
+
}
|
|
193
|
+
export const sha256 = (b) => createHash("sha256").update(b).digest("hex");
|
|
194
|
+
/** 土台を dir に置く。置いてあるものの sha が合えばそのまま。合わなければ取り直し、2回続けて合わなければ止める */
|
|
195
|
+
export async function fetchPlate(token, bp, dir, f = fetch) {
|
|
196
|
+
const path = join(dir, bp.plate.name);
|
|
197
|
+
try {
|
|
198
|
+
if (sha256(await readFile(path)) === bp.plate.sha256)
|
|
199
|
+
return path;
|
|
200
|
+
}
|
|
201
|
+
catch {
|
|
202
|
+
/* まだ無い */
|
|
203
|
+
}
|
|
204
|
+
for (let i = 0; i < 2; i++) {
|
|
205
|
+
const b = await stillAsset(token, bp.id, bp.plate.name, f);
|
|
206
|
+
if (sha256(b) === bp.plate.sha256) {
|
|
207
|
+
await writeFile(path, b);
|
|
208
|
+
return path;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
throw new AgentError(`土台の画像(${bp.plate.name})が設計図と合いません(2回取り直しても同じ)。担当に伝えてください`);
|
|
212
|
+
}
|
|
213
|
+
/** /still/fonts が受ける大きさの上限(still_api の 1.5MB) */
|
|
214
|
+
export const FONTS_BODY_MAX = 1_500_000;
|
|
215
|
+
/** 書体の一覧を受け口に送る(統計用)。送るのは ps・family・style だけ */
|
|
216
|
+
export function stillFonts(token, fonts, f = fetch) {
|
|
217
|
+
const body = { fonts: fonts.map(({ ps, family, style }) => ({ ps, family, style })) };
|
|
218
|
+
const size = Buffer.byteLength(JSON.stringify(body));
|
|
219
|
+
if (size > FONTS_BODY_MAX)
|
|
220
|
+
return Promise.reject(new AgentError(`一覧が大きすぎます(${mb(size)}・${mb(FONTS_BODY_MAX)} まで)`));
|
|
221
|
+
return json("/still/fonts", token, f, body);
|
|
222
|
+
}
|
|
223
|
+
/** 仕上げの結果の報告。共有タブに書けなかったときは message が返る */
|
|
224
|
+
export function stillFinish(token, report, f = fetch) {
|
|
225
|
+
return json("/still/finish", token, f, report);
|
|
226
|
+
}
|
|
227
|
+
export const realPhotoshop = { find: () => findPhotoshop(), listFonts, render };
|
|
228
|
+
export const CACHE_ROOT = join(homedir(), "Library", "Caches", "langley-video-mcp", "still");
|
|
229
|
+
export const FONTS_MAX_AGE_DAYS = 30;
|
|
230
|
+
/** 1サイズの上限(秒)。その回で最初に Photoshop を呼ぶときは、起動を待つので長め(§5.2) */
|
|
231
|
+
export const RENDER_TIMEOUT = 120;
|
|
232
|
+
export const FIRST_TIMEOUT = 180;
|
|
233
|
+
/** 書体の一覧を集め直すか: 無い・Photoshop が変わった・30日より古い(ちょうど30日はまだ使う) */
|
|
234
|
+
export function fontsStale(cache, app, now) {
|
|
235
|
+
if (!cache || cache.photoshop !== app || !Array.isArray(cache.fonts) || !cache.fonts.length)
|
|
236
|
+
return true;
|
|
237
|
+
const age = now.getTime() - Date.parse(cache.at);
|
|
238
|
+
return !(age >= 0 && age <= FONTS_MAX_AGE_DAYS * 86400_000);
|
|
239
|
+
}
|
|
240
|
+
const PS_RETRY = "済んだら、もう一度 still_finish_psd を呼んでください";
|
|
241
|
+
/** ①設計図 ②書体の一覧(初回か30日より古いとき集めて控える。送れていなければ送る・送れなくても続ける) ③土台 ④Photoshop で PSD・PNG ⑤受け口に報告 */
|
|
242
|
+
export async function finishPsd(id, sizes, deps) {
|
|
243
|
+
const { token, f = fetch, ps = realPhotoshop, cacheRoot = CACHE_ROOT, downloads = join(homedir(), "Downloads"), now = () => new Date() } = deps;
|
|
244
|
+
if (!/^[A-Za-z0-9_-]+$/.test(id))
|
|
245
|
+
throw new AgentError(`企画の番号の形が違います: ${id}`);
|
|
246
|
+
const app = await ps.find();
|
|
247
|
+
if (!app)
|
|
248
|
+
throw new AgentError(NOT_FOUND_MESSAGE);
|
|
249
|
+
const work = join(cacheRoot, id);
|
|
250
|
+
await mkdir(work, { recursive: true });
|
|
251
|
+
// 先に設計図を取る(まだできていなければ、Photoshop を動かす前に受け口の文で止まる)
|
|
252
|
+
const bps = [];
|
|
253
|
+
for (const size of [...new Set(sizes)]) {
|
|
254
|
+
const bp = await stillBlueprint(token, id, size, f);
|
|
255
|
+
await writeFile(join(work, `blueprint_${size}.json`), JSON.stringify(bp, null, 2));
|
|
256
|
+
bps.push(bp);
|
|
257
|
+
}
|
|
258
|
+
const banner = bps[0].banner;
|
|
259
|
+
const dir = join(downloads, `静止画_${banner}`);
|
|
260
|
+
const result = { banner, dir, photoshop: app.name, fontsSent: false, done: [] };
|
|
261
|
+
let timeout = FIRST_TIMEOUT;
|
|
262
|
+
try {
|
|
263
|
+
const cachePath = join(cacheRoot, "fonts.json");
|
|
264
|
+
let cache = null;
|
|
265
|
+
try {
|
|
266
|
+
cache = JSON.parse(await readFile(cachePath, "utf8"));
|
|
267
|
+
}
|
|
268
|
+
catch {
|
|
269
|
+
/* 初回 */
|
|
270
|
+
}
|
|
271
|
+
if (fontsStale(cache, app.name, now())) {
|
|
272
|
+
const fonts = await ps.listFonts(app, cacheRoot, FIRST_TIMEOUT);
|
|
273
|
+
timeout = RENDER_TIMEOUT;
|
|
274
|
+
cache = { at: now().toISOString(), photoshop: app.name, fonts, unsent: true };
|
|
275
|
+
await writeFile(cachePath, JSON.stringify(cache));
|
|
276
|
+
}
|
|
277
|
+
if (cache.unsent) {
|
|
278
|
+
try {
|
|
279
|
+
await stillFonts(token, cache.fonts, f);
|
|
280
|
+
cache = { ...cache, unsent: false };
|
|
281
|
+
await writeFile(cachePath, JSON.stringify(cache));
|
|
282
|
+
result.fontsSent = true;
|
|
283
|
+
}
|
|
284
|
+
catch (e) {
|
|
285
|
+
// 統計用なので、通信が切れた場合も含めて仕上げは止めない(最後に一言伝える)
|
|
286
|
+
result.fontsError = e instanceof AgentError ? e.message : String(e);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
const available = cache.fonts.map((x) => x.ps);
|
|
290
|
+
for (const bp of bps) {
|
|
291
|
+
await fetchPlate(token, bp, work, f);
|
|
292
|
+
let plan;
|
|
293
|
+
try {
|
|
294
|
+
plan = planFonts(bp, available);
|
|
295
|
+
}
|
|
296
|
+
catch (e) {
|
|
297
|
+
throw new AgentError(e.message);
|
|
298
|
+
}
|
|
299
|
+
const psd = join(work, outputName(bp, "psd"));
|
|
300
|
+
const png = join(work, outputName(bp, "png"));
|
|
301
|
+
// 前回の PSD・PNG を、今回できたものと取り違えない
|
|
302
|
+
await rm(psd, { force: true });
|
|
303
|
+
await rm(png, { force: true });
|
|
304
|
+
const r = await ps.render(app, bp, plan, work, timeout);
|
|
305
|
+
timeout = RENDER_TIMEOUT;
|
|
306
|
+
await mkdir(dir, { recursive: true });
|
|
307
|
+
const copied = async (from) => {
|
|
308
|
+
if (!(await stat(from).catch(() => null)))
|
|
309
|
+
return null;
|
|
310
|
+
const to = join(dir, from.slice(work.length + 1));
|
|
311
|
+
await copyFile(from, to);
|
|
312
|
+
return to;
|
|
313
|
+
};
|
|
314
|
+
const done = { size: bp.size, psd: await copied(psd), png: await copied(png), check: r.check, seconds: r.seconds };
|
|
315
|
+
const ok = r.check.ok && done.psd !== null && done.png !== null;
|
|
316
|
+
if (r.check.ok && !ok)
|
|
317
|
+
r.check.problems.push("Photoshop は終わりましたが、PSD か PNG ができていません");
|
|
318
|
+
try {
|
|
319
|
+
const res = await stillFinish(token, { id, size: bp.size, ok, substituted: r.check.substituted, overflow: r.check.overflow, seconds: r.seconds, photoshop: r.result.photoshop || app.name }, f);
|
|
320
|
+
if (res.message)
|
|
321
|
+
done.reportMessage = res.message;
|
|
322
|
+
}
|
|
323
|
+
catch (e) {
|
|
324
|
+
done.reportError = e instanceof AgentError ? e.message : String(e);
|
|
325
|
+
}
|
|
326
|
+
result.done.push(done);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
catch (e) {
|
|
330
|
+
if (!(e instanceof PhotoshopError || e instanceof AgentError))
|
|
331
|
+
throw e;
|
|
332
|
+
result.stopped = e instanceof PhotoshopError ? `${e.message}。${PS_RETRY}` : e.message;
|
|
333
|
+
}
|
|
334
|
+
return result;
|
|
335
|
+
}
|
|
336
|
+
const SIZE_JA = { "1x1": "1:1(1080×1080)", "9x16": "9:16(1080×1920)" };
|
|
337
|
+
const EDGE_JA = { left: "左端", center: "真ん中", right: "右端", top: "上端", middle: "真ん中", bottom: "下端" };
|
|
338
|
+
/** 仕上げの結果を、保存した場所と「人が直す所」の文にする */
|
|
339
|
+
export function finishText(r) {
|
|
340
|
+
const lines = [];
|
|
341
|
+
if (r.done.length)
|
|
342
|
+
lines.push(`保存した場所: ${r.dir}`);
|
|
343
|
+
for (const d of r.done) {
|
|
344
|
+
const c = d.check;
|
|
345
|
+
lines.push("", `■ ${SIZE_JA[d.size]}(${d.seconds}秒)`);
|
|
346
|
+
for (const p of [d.psd, d.png])
|
|
347
|
+
if (p)
|
|
348
|
+
lines.push(` ${p}`);
|
|
349
|
+
const fix = [
|
|
350
|
+
...c.problems.map((p) => `うまくいかなかった所: ${p}`),
|
|
351
|
+
...c.substituted.map((s) => `書体を置き換えた: 「${s.layer}」 ${s.want} → ${s.got}`),
|
|
352
|
+
...c.overflow.map((l) => `枠からはみ出した: 「${l}」`),
|
|
353
|
+
...c.drift.map((x) => `位置がずれた: 「${x.layer}」 ${EDGE_JA[x.edge]}が ${Math.round(x.px)}px`),
|
|
354
|
+
...c.scaled.map((s) => `枠に収めるために縮めた: 「${s.layer}」 ${Math.round(s.ratio * 100)}%`),
|
|
355
|
+
...c.effectsMissing.map((m) => `入らなかった効果: 「${m.layer}」 ${m.want.map((w) => (w === "stroke" ? "縁取り" : "影")).join("・")}${m.error ? `(${m.error})` : ""}`),
|
|
356
|
+
];
|
|
357
|
+
lines.push(fix.length ? " 人が直す所:" : " 人が直す所: ありません", ...fix.map((x) => ` ・${x}`));
|
|
358
|
+
if (d.reportError)
|
|
359
|
+
lines.push(` 受け口への報告ができませんでした(ファイルは保存済み): ${d.reportError}`);
|
|
360
|
+
if (d.reportMessage)
|
|
361
|
+
lines.push(` 受け口から: ${d.reportMessage}`);
|
|
362
|
+
}
|
|
363
|
+
if (r.fontsSent)
|
|
364
|
+
lines.push("", `この Mac の Photoshop の書体の一覧を受け口に送りました(${r.photoshop})`);
|
|
365
|
+
if (r.stopped)
|
|
366
|
+
lines.push("", `止まりました: ${r.stopped}`);
|
|
367
|
+
if (r.fontsError)
|
|
368
|
+
lines.push("", `書体の一覧を受け口に送れませんでした(次の回にまた送ります): ${r.fontsError}`);
|
|
369
|
+
return lines.join("\n").trim();
|
|
370
|
+
}
|