dsh-codex-subscription 3.0.1 → 3.1.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/README.en.md +47 -66
- package/README.md +45 -89
- package/lib/client.js +1821 -145
- package/lib/index.js +260 -8
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -165,6 +165,147 @@ window.__ModuleLoader__.load({
|
|
|
165
165
|
y: a.y + .15
|
|
166
166
|
}];
|
|
167
167
|
}
|
|
168
|
+
const finite$1 = (value, min, max) => typeof value === "number" && Number.isFinite(value) && value >= min && value <= max;
|
|
169
|
+
const FILLABLE = [
|
|
170
|
+
"rectangle",
|
|
171
|
+
"circle",
|
|
172
|
+
"polygon",
|
|
173
|
+
"bezier"
|
|
174
|
+
];
|
|
175
|
+
function normalizeBlur(value) {
|
|
176
|
+
if (value === void 0 || value === null) return void 0;
|
|
177
|
+
if (!finite$1(value, 0, 64)) throw Error(`blur must be 0–64 canvas pixels`);
|
|
178
|
+
return value >= .5 ? Math.round(value * 10) / 10 : void 0;
|
|
179
|
+
}
|
|
180
|
+
function normalizeGradient(gradient) {
|
|
181
|
+
if (gradient === void 0 || gradient === null) return void 0;
|
|
182
|
+
if (!gradient || typeof gradient !== "object") throw Error("Invalid gradient");
|
|
183
|
+
if (gradient.type === "none") return void 0;
|
|
184
|
+
if (gradient.type !== "linear" && gradient.type !== "radial") throw Error("gradient.type must be linear or radial");
|
|
185
|
+
const stops = gradient.stops;
|
|
186
|
+
if (!Array.isArray(stops) || stops.length < 2 || stops.length > 8) throw Error("gradient needs 2–8 stops");
|
|
187
|
+
const clean = stops.map((stop) => {
|
|
188
|
+
if (!stop || !finite$1(stop.offset, 0, 1) || !/^#[0-9a-f]{6}$/i.test(stop.color ?? "") || stop.opacity !== void 0 && !finite$1(stop.opacity, 0, 1)) throw Error("Each gradient stop needs offset 0–1 and color #rrggbb (optional opacity 0–1)");
|
|
189
|
+
return {
|
|
190
|
+
offset: stop.offset,
|
|
191
|
+
color: stop.color.toLowerCase(),
|
|
192
|
+
...stop.opacity !== void 0 && stop.opacity < 1 ? { opacity: stop.opacity } : {}
|
|
193
|
+
};
|
|
194
|
+
}).sort((a, b) => a.offset - b.offset);
|
|
195
|
+
const number = (name, fallback, min = -8, max = 8) => {
|
|
196
|
+
const value = gradient[name] ?? fallback;
|
|
197
|
+
if (!finite$1(value, min, max)) throw Error(`gradient.${name} must be a number`);
|
|
198
|
+
return Math.round(value * 1e4) / 1e4;
|
|
199
|
+
};
|
|
200
|
+
if (gradient.type === "linear") return {
|
|
201
|
+
type: "linear",
|
|
202
|
+
x1: number("x1", 0),
|
|
203
|
+
y1: number("y1", 0),
|
|
204
|
+
x2: number("x2", 0),
|
|
205
|
+
y2: number("y2", 1),
|
|
206
|
+
stops: clean
|
|
207
|
+
};
|
|
208
|
+
const cx = number("cx", .5), cy = number("cy", .5), r = number("r", .5, 1e-4), ry = gradient.ry === void 0 ? r : number("ry", .5, 1e-4);
|
|
209
|
+
return {
|
|
210
|
+
type: "radial",
|
|
211
|
+
cx,
|
|
212
|
+
cy,
|
|
213
|
+
r,
|
|
214
|
+
...ry !== r ? { ry } : {},
|
|
215
|
+
fx: number("fx", cx),
|
|
216
|
+
fy: number("fy", cy),
|
|
217
|
+
stops: clean
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
function gradientFits(shape, fill) {
|
|
221
|
+
return fill === true && FILLABLE.includes(shape);
|
|
222
|
+
}
|
|
223
|
+
const rgba = (color, opacity = 1) => {
|
|
224
|
+
const value = Number.parseInt(color.slice(1), 16);
|
|
225
|
+
return `rgba(${value >> 16 & 255},${value >> 8 & 255},${value & 255},${opacity})`;
|
|
226
|
+
};
|
|
227
|
+
function fillSketchShape(context, stroke, size, height) {
|
|
228
|
+
const gradient = stroke.gradient;
|
|
229
|
+
const xs = stroke.points.map((point) => point.x), ys = stroke.points.map((point) => point.y);
|
|
230
|
+
const x = Math.min(...xs) * size, y = Math.min(...ys) * height;
|
|
231
|
+
const w = (Math.max(...xs) - Math.min(...xs)) * size, h = (Math.max(...ys) - Math.min(...ys)) * height;
|
|
232
|
+
if (!gradient || !(w > 0 && h > 0) || !context.createLinearGradient) {
|
|
233
|
+
context.fill();
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
let paint;
|
|
237
|
+
if (gradient.type === "linear") {
|
|
238
|
+
paint = context.createLinearGradient(x + gradient.x1 * w, y + gradient.y1 * h, x + gradient.x2 * w, y + gradient.y2 * h);
|
|
239
|
+
for (const stop of gradient.stops) paint.addColorStop(stop.offset, rgba(stop.color, stop.opacity));
|
|
240
|
+
context.fillStyle = paint;
|
|
241
|
+
context.fill();
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
const rx = gradient.r * w, ry = (gradient.ry ?? gradient.r) * h;
|
|
245
|
+
paint = context.createRadialGradient((gradient.fx - gradient.cx) / gradient.r, (gradient.fy - gradient.cy) / (gradient.ry ?? gradient.r), 0, 0, 0, 1);
|
|
246
|
+
for (const stop of gradient.stops) paint.addColorStop(stop.offset, rgba(stop.color, stop.opacity));
|
|
247
|
+
context.save();
|
|
248
|
+
context.translate(x + gradient.cx * w, y + gradient.cy * h);
|
|
249
|
+
context.scale(rx, ry);
|
|
250
|
+
context.fillStyle = paint;
|
|
251
|
+
context.fill();
|
|
252
|
+
context.restore();
|
|
253
|
+
}
|
|
254
|
+
const BLEND_MODES = [
|
|
255
|
+
"multiply",
|
|
256
|
+
"screen",
|
|
257
|
+
"overlay",
|
|
258
|
+
"soft-light",
|
|
259
|
+
"hard-light",
|
|
260
|
+
"color-dodge",
|
|
261
|
+
"color-burn",
|
|
262
|
+
"darken",
|
|
263
|
+
"lighten",
|
|
264
|
+
"lighter"
|
|
265
|
+
];
|
|
266
|
+
function normalizeBlend(value) {
|
|
267
|
+
if (value === void 0 || value === null || value === "normal") return void 0;
|
|
268
|
+
if (!BLEND_MODES.includes(value)) throw Error("blend must be one of normal, " + BLEND_MODES.join(", "));
|
|
269
|
+
return value;
|
|
270
|
+
}
|
|
271
|
+
function normalizeClip(clip) {
|
|
272
|
+
if (clip === void 0 || clip === null) return void 0;
|
|
273
|
+
if (!clip || typeof clip !== "object") throw Error("Invalid clip");
|
|
274
|
+
if (clip.shape === "none") return void 0;
|
|
275
|
+
const { shape, points } = clip;
|
|
276
|
+
if (![
|
|
277
|
+
"polygon",
|
|
278
|
+
"bezier",
|
|
279
|
+
"rectangle",
|
|
280
|
+
"circle"
|
|
281
|
+
].includes(shape)) throw Error("clip.shape must be polygon, bezier, rectangle or circle");
|
|
282
|
+
if (!Array.isArray(points) || points.some((point) => !point || !finite$1(point.x, 0, 1) || !finite$1(point.y, 0, 1))) throw Error("clip.points must be {x,y} pairs inside 0..1");
|
|
283
|
+
if ((shape === "rectangle" || shape === "circle") && points.length !== 2) throw Error("clip rectangle and circle need exactly two opposite corners");
|
|
284
|
+
if (shape === "polygon" && (points.length < 3 || points.length > 2e3)) throw Error("clip polygon needs 3–2000 points");
|
|
285
|
+
if (shape === "bezier" && (points.length < 4 || points.length > 193 || (points.length - 1) % 3 !== 0)) throw Error("clip bezier needs 4, 7, ... 193 points (start + control1/control2/end per segment)");
|
|
286
|
+
return {
|
|
287
|
+
shape,
|
|
288
|
+
points: points.map((point) => ({
|
|
289
|
+
x: Math.round(point.x * 1e5) / 1e5,
|
|
290
|
+
y: Math.round(point.y * 1e5) / 1e5
|
|
291
|
+
}))
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
function applySketchClip(context, clip, size, height) {
|
|
295
|
+
const { shape, points } = clip;
|
|
296
|
+
const first = points[0], last = points.at(-1);
|
|
297
|
+
context.beginPath();
|
|
298
|
+
if (shape === "bezier") {
|
|
299
|
+
context.moveTo(first.x * size, first.y * height);
|
|
300
|
+
for (let i = 1; i < points.length; i += 3) context.bezierCurveTo(points[i].x * size, points[i].y * height, points[i + 1].x * size, points[i + 1].y * height, points[i + 2].x * size, points[i + 2].y * height);
|
|
301
|
+
} else if (shape === "polygon") {
|
|
302
|
+
context.moveTo(first.x * size, first.y * height);
|
|
303
|
+
for (const point of points.slice(1)) context.lineTo(point.x * size, point.y * height);
|
|
304
|
+
} else if (shape === "rectangle") context.rect(first.x * size, first.y * height, (last.x - first.x) * size, (last.y - first.y) * height);
|
|
305
|
+
else context.ellipse((first.x + last.x) * size / 2, (first.y + last.y) * height / 2, Math.abs(last.x - first.x) * size / 2, Math.abs(last.y - first.y) * height / 2, 0, 0, Math.PI * 2);
|
|
306
|
+
context.closePath();
|
|
307
|
+
context.clip();
|
|
308
|
+
}
|
|
168
309
|
//#endregion
|
|
169
310
|
//#region src/sketch-document.js
|
|
170
311
|
const SKETCH_SIZE = 1024;
|
|
@@ -190,8 +331,13 @@ window.__ModuleLoader__.load({
|
|
|
190
331
|
const stroke = strokes[index];
|
|
191
332
|
const first = stroke.points[0];
|
|
192
333
|
if (!first) continue;
|
|
193
|
-
context.globalCompositeOperation = stroke.shape === "eraser" ? "destination-out" : "source-over";
|
|
334
|
+
context.globalCompositeOperation = stroke.shape === "eraser" ? "destination-out" : stroke.blend ?? "source-over";
|
|
194
335
|
configureSketchBrush(context, stroke);
|
|
336
|
+
if (stroke.blur > 0) context.filter = `blur(${stroke.blur}px)`;
|
|
337
|
+
if (stroke.clip) {
|
|
338
|
+
context.save();
|
|
339
|
+
applySketchClip(context, stroke.clip, size, height);
|
|
340
|
+
}
|
|
195
341
|
context.beginPath();
|
|
196
342
|
const last = stroke.points.at(-1);
|
|
197
343
|
if (stroke.shape === "text") {
|
|
@@ -218,7 +364,7 @@ window.__ModuleLoader__.load({
|
|
|
218
364
|
}
|
|
219
365
|
if (stroke.fill) {
|
|
220
366
|
context.closePath();
|
|
221
|
-
context
|
|
367
|
+
fillSketchShape(context, stroke, size, height);
|
|
222
368
|
} else context.stroke();
|
|
223
369
|
} else if (stroke.shape === "line") {
|
|
224
370
|
context.moveTo(first.x * size, first.y * height);
|
|
@@ -226,17 +372,17 @@ window.__ModuleLoader__.load({
|
|
|
226
372
|
context.stroke();
|
|
227
373
|
} else if (stroke.shape === "rectangle") {
|
|
228
374
|
context.rect(first.x * size, first.y * height, (last.x - first.x) * size, (last.y - first.y) * height);
|
|
229
|
-
if (stroke.fill) context
|
|
375
|
+
if (stroke.fill) fillSketchShape(context, stroke, size, height);
|
|
230
376
|
else context.stroke();
|
|
231
377
|
} else if (stroke.shape === "circle") {
|
|
232
378
|
context.ellipse((first.x + last.x) * size / 2, (first.y + last.y) * height / 2, Math.abs(last.x - first.x) * size / 2, Math.abs(last.y - first.y) * height / 2, 0, 0, Math.PI * 2);
|
|
233
|
-
if (stroke.fill) context
|
|
379
|
+
if (stroke.fill) fillSketchShape(context, stroke, size, height);
|
|
234
380
|
else context.stroke();
|
|
235
381
|
} else if (stroke.shape === "polygon") {
|
|
236
382
|
context.moveTo(first.x * size, first.y * height);
|
|
237
383
|
for (const point of stroke.points.slice(1)) context.lineTo(point.x * size, point.y * height);
|
|
238
384
|
context.closePath();
|
|
239
|
-
if (stroke.fill) context
|
|
385
|
+
if (stroke.fill) fillSketchShape(context, stroke, size, height);
|
|
240
386
|
else context.stroke();
|
|
241
387
|
} else if (stroke.points.length === 1) {
|
|
242
388
|
if (stroke.brushVersion === 2 && stroke.brush === "marker") context.rect(first.x * size - context.lineWidth / 2, first.y * height - context.lineWidth / 4, context.lineWidth, context.lineWidth / 2);
|
|
@@ -252,6 +398,8 @@ window.__ModuleLoader__.load({
|
|
|
252
398
|
context.lineTo(last.x * size, last.y * height);
|
|
253
399
|
context.stroke();
|
|
254
400
|
}
|
|
401
|
+
if (stroke.clip) context.restore();
|
|
402
|
+
if (stroke.blur > 0) context.filter = "none";
|
|
255
403
|
}
|
|
256
404
|
context.globalCompositeOperation = "source-over";
|
|
257
405
|
context.globalAlpha = 1;
|
|
@@ -316,7 +464,14 @@ window.__ModuleLoader__.load({
|
|
|
316
464
|
...layer,
|
|
317
465
|
name: String(value).trim().slice(0, 40)
|
|
318
466
|
};
|
|
319
|
-
else if (action === "
|
|
467
|
+
else if (action === "blend") {
|
|
468
|
+
const blend = normalizeBlend(value);
|
|
469
|
+
const { blend: _old, ...rest } = layer;
|
|
470
|
+
layers[index] = blend ? {
|
|
471
|
+
...rest,
|
|
472
|
+
blend
|
|
473
|
+
} : rest;
|
|
474
|
+
} else if (action === "clear") layers[index] = {
|
|
320
475
|
...layer,
|
|
321
476
|
strokes: [],
|
|
322
477
|
image: void 0
|
|
@@ -428,6 +583,7 @@ window.__ModuleLoader__.load({
|
|
|
428
583
|
undo: ref([]),
|
|
429
584
|
redo: ref([]),
|
|
430
585
|
images: ref(/* @__PURE__ */ new Map()),
|
|
586
|
+
timeline: ref([]),
|
|
431
587
|
saved: ref(null),
|
|
432
588
|
dirty: ref(false),
|
|
433
589
|
documentId: ref(crypto.randomUUID()),
|
|
@@ -2174,9 +2330,18 @@ window.__ModuleLoader__.load({
|
|
|
2174
2330
|
y: box.y + (p.y - box.y) * scaleY + dy
|
|
2175
2331
|
}));
|
|
2176
2332
|
if (points.some((p) => p.x < 0 || p.x > 1 || p.y < 0 || p.y > 1)) throw Error("Object would leave the canvas");
|
|
2333
|
+
const clip = stroke.clip && {
|
|
2334
|
+
...stroke.clip,
|
|
2335
|
+
points: stroke.clip.points.map((p) => ({
|
|
2336
|
+
x: box.x + (p.x - box.x) * scaleX + dx,
|
|
2337
|
+
y: box.y + (p.y - box.y) * scaleY + dy
|
|
2338
|
+
}))
|
|
2339
|
+
};
|
|
2340
|
+
if (clip && clip.points.some((p) => p.x < 0 || p.x > 1 || p.y < 0 || p.y > 1)) throw Error("Object clip would leave the canvas");
|
|
2177
2341
|
return {
|
|
2178
2342
|
...stroke,
|
|
2179
|
-
points
|
|
2343
|
+
points,
|
|
2344
|
+
...clip ? { clip } : {}
|
|
2180
2345
|
};
|
|
2181
2346
|
}
|
|
2182
2347
|
function sketchObjectSummary(doc) {
|
|
@@ -2536,8 +2701,6 @@ window.__ModuleLoader__.load({
|
|
|
2536
2701
|
"tspan",
|
|
2537
2702
|
"image",
|
|
2538
2703
|
"foreignObject",
|
|
2539
|
-
"filter",
|
|
2540
|
-
"clipPath",
|
|
2541
2704
|
"mask",
|
|
2542
2705
|
"pattern",
|
|
2543
2706
|
"style",
|
|
@@ -2551,9 +2714,23 @@ window.__ModuleLoader__.load({
|
|
|
2551
2714
|
"desc",
|
|
2552
2715
|
"metadata",
|
|
2553
2716
|
"defs",
|
|
2717
|
+
"clipPath",
|
|
2554
2718
|
"linearGradient",
|
|
2555
2719
|
"radialGradient",
|
|
2556
2720
|
"stop",
|
|
2721
|
+
"filter",
|
|
2722
|
+
"feGaussianBlur",
|
|
2723
|
+
"feDropShadow",
|
|
2724
|
+
"feOffset",
|
|
2725
|
+
"feColorMatrix",
|
|
2726
|
+
"feFlood",
|
|
2727
|
+
"feComposite",
|
|
2728
|
+
"feMerge",
|
|
2729
|
+
"feMergeNode",
|
|
2730
|
+
"feBlend",
|
|
2731
|
+
"feMorphology",
|
|
2732
|
+
"feTurbulence",
|
|
2733
|
+
"feComponentTransfer",
|
|
2557
2734
|
"namedview",
|
|
2558
2735
|
"sodipodi:namedview"
|
|
2559
2736
|
]);
|
|
@@ -2710,7 +2887,10 @@ window.__ModuleLoader__.load({
|
|
|
2710
2887
|
fillOpacity: number("fill-opacity", parent.fillOpacity),
|
|
2711
2888
|
strokeOpacity: number("stroke-opacity", parent.strokeOpacity),
|
|
2712
2889
|
opacity: parent.opacity * number("opacity", 1),
|
|
2713
|
-
display: own.display === "none" || own.visibility === "hidden" ? "none" : "inline"
|
|
2890
|
+
display: own.display === "none" || own.visibility === "hidden" ? "none" : "inline",
|
|
2891
|
+
blur: parent.blur ?? 0,
|
|
2892
|
+
blend: own["mix-blend-mode"] === void 0 ? parent.blend : own["mix-blend-mode"] === "normal" ? void 0 : own["mix-blend-mode"],
|
|
2893
|
+
clip: parent.clip
|
|
2714
2894
|
};
|
|
2715
2895
|
}
|
|
2716
2896
|
function arcToCubics(x1, y1, rx, ry, rotation, large, sweep, x2, y2) {
|
|
@@ -3034,12 +3214,43 @@ window.__ModuleLoader__.load({
|
|
|
3034
3214
|
y: clamp((ty - originY) / viewHeight)
|
|
3035
3215
|
};
|
|
3036
3216
|
};
|
|
3037
|
-
const
|
|
3217
|
+
const gradientNode = (reference) => {
|
|
3038
3218
|
const target = byId.get(/^url\(\s*['"]?#([^)'"]+)['"]?\s*\)/.exec(reference)?.[1] ?? "");
|
|
3039
3219
|
if (!target || !/Gradient$/.test(target.name)) throw Error(`SVG paint ${reference} does not reference a gradient defined in the same SVG`);
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
|
|
3220
|
+
return target;
|
|
3221
|
+
};
|
|
3222
|
+
const gradientChain = (target) => {
|
|
3223
|
+
const chain = [target];
|
|
3224
|
+
for (let node = target; chain.length < 5;) {
|
|
3225
|
+
const href = node.attrs.href ?? node.attrs["xlink:href"];
|
|
3226
|
+
node = href?.startsWith("#") ? byId.get(href.slice(1)) : void 0;
|
|
3227
|
+
if (!node || !/Gradient$/.test(node.name)) break;
|
|
3228
|
+
chain.push(node);
|
|
3229
|
+
}
|
|
3230
|
+
return chain;
|
|
3231
|
+
};
|
|
3232
|
+
const gradientStops = (target) => {
|
|
3233
|
+
const holder = gradientChain(target).find((node) => node.children.some((child) => child.name === "stop"));
|
|
3234
|
+
if (!holder) throw Error(`Gradient ${target.attrs.id} has no stops`);
|
|
3235
|
+
let last = 0;
|
|
3236
|
+
return holder.children.filter((child) => child.name === "stop").map((stop) => {
|
|
3237
|
+
const css = (name) => stop.attrs[name] ?? new RegExp(name + "\\s*:\\s*([^;]+)").exec(stop.attrs.style ?? "")?.[1];
|
|
3238
|
+
const raw = String(stop.attrs.offset ?? "0").trim();
|
|
3239
|
+
const offset = Math.max(last, Math.min(1, raw.endsWith("%") ? Number.parseFloat(raw) / 100 : Number.parseFloat(raw) || 0));
|
|
3240
|
+
last = offset;
|
|
3241
|
+
const opacity = Number.parseFloat(css("stop-opacity") ?? "1");
|
|
3242
|
+
return {
|
|
3243
|
+
offset,
|
|
3244
|
+
color: parseColor$1(css("stop-color") ?? "#000000"),
|
|
3245
|
+
opacity: Number.isFinite(opacity) ? Math.max(0, Math.min(1, opacity)) : 1
|
|
3246
|
+
};
|
|
3247
|
+
}).filter((stop) => stop.color !== "none");
|
|
3248
|
+
};
|
|
3249
|
+
const averageColor = (reference, warn) => {
|
|
3250
|
+
const target = gradientNode(reference);
|
|
3251
|
+
const colors = gradientStops(target).map((stop) => stop.color);
|
|
3252
|
+
if (!colors.length) throw Error(`Gradient ${target.attrs.id} has no usable stops`);
|
|
3253
|
+
const channels = colors.map((color) => [
|
|
3043
3254
|
1,
|
|
3044
3255
|
3,
|
|
3045
3256
|
5
|
|
@@ -3049,18 +3260,82 @@ window.__ModuleLoader__.load({
|
|
|
3049
3260
|
1,
|
|
3050
3261
|
2
|
|
3051
3262
|
].map((channel) => Math.round(channels.reduce((sum, item) => sum + item[channel], 0) / channels.length));
|
|
3052
|
-
warnings.add(`Gradient ${target.attrs.id} was flattened to its average color
|
|
3263
|
+
if (warn) warnings.add(`Gradient ${target.attrs.id} was flattened to its average color (a gradient on a stroke line, or on a path that had to be split).`);
|
|
3053
3264
|
return `#${mean.map((value) => value.toString(16).padStart(2, "0")).join("")}`;
|
|
3054
3265
|
};
|
|
3055
|
-
const
|
|
3266
|
+
const determinant = (m) => Math.abs(m[0] * m[3] - m[1] * m[2]);
|
|
3267
|
+
const nativeGradient = (reference, matrix, command) => {
|
|
3268
|
+
const target = gradientNode(reference);
|
|
3269
|
+
const chain = gradientChain(target);
|
|
3270
|
+
const attr = (name) => chain.find((node) => node.attrs[name] !== void 0)?.attrs[name];
|
|
3271
|
+
const stops = gradientStops(target);
|
|
3272
|
+
if (stops.length < 2) return void 0;
|
|
3273
|
+
const radial = target.name === "radialGradient";
|
|
3274
|
+
const objectBox = (attr("gradientUnits") ?? "objectBoundingBox") === "objectBoundingBox";
|
|
3275
|
+
const xs = command.points.map((point) => point.x), ys = command.points.map((point) => point.y);
|
|
3276
|
+
const bx = Math.min(...xs), by = Math.min(...ys), bw = Math.max(...xs) - bx, bh = Math.max(...ys) - by;
|
|
3277
|
+
if (!(bw > 1e-4 && bh > 1e-4)) return void 0;
|
|
3278
|
+
const gt = parseTransform(attr("gradientTransform"));
|
|
3279
|
+
const length = (name, fraction, axis) => {
|
|
3280
|
+
const raw = String(attr(name) ?? `${fraction * 100}%`).trim();
|
|
3281
|
+
if (!raw.endsWith("%")) return Number.parseFloat(raw) || 0;
|
|
3282
|
+
const part = Number.parseFloat(raw) / 100;
|
|
3283
|
+
return objectBox ? part : part * (axis === "x" ? viewWidth : axis === "y" ? viewHeight : Math.hypot(viewWidth, viewHeight) / Math.SQRT2);
|
|
3284
|
+
};
|
|
3285
|
+
const full = objectBox ? gt : multiply(matrix, gt);
|
|
3286
|
+
const place = (x, y) => {
|
|
3287
|
+
const [px, py] = apply$1(full, x, y);
|
|
3288
|
+
return objectBox ? [px, py] : [((px - originX) / viewWidth - bx) / bw, ((py - originY) / viewHeight - by) / bh];
|
|
3289
|
+
};
|
|
3290
|
+
const colors = stops.map((stop) => ({
|
|
3291
|
+
offset: stop.offset,
|
|
3292
|
+
color: stop.color,
|
|
3293
|
+
opacity: stop.opacity
|
|
3294
|
+
}));
|
|
3295
|
+
if (!radial) {
|
|
3296
|
+
const [x1, y1] = place(length("x1", 0, "x"), length("y1", 0, "y"));
|
|
3297
|
+
const [x2, y2] = place(length("x2", 1, "x"), length("y2", 0, "y"));
|
|
3298
|
+
return normalizeGradient({
|
|
3299
|
+
type: "linear",
|
|
3300
|
+
x1,
|
|
3301
|
+
y1,
|
|
3302
|
+
x2,
|
|
3303
|
+
y2,
|
|
3304
|
+
stops: colors
|
|
3305
|
+
});
|
|
3306
|
+
}
|
|
3307
|
+
const cx0 = length("cx", .5, "x"), cy0 = length("cy", .5, "y"), r0 = length("r", .5, "r");
|
|
3308
|
+
const [cx, cy] = place(cx0, cy0);
|
|
3309
|
+
const [fx, fy] = place(attr("fx") === void 0 ? cx0 : length("fx", .5, "x"), attr("fy") === void 0 ? cy0 : length("fy", .5, "y"));
|
|
3310
|
+
const k = Math.sqrt(determinant(full));
|
|
3311
|
+
return normalizeGradient({
|
|
3312
|
+
type: "radial",
|
|
3313
|
+
cx,
|
|
3314
|
+
cy,
|
|
3315
|
+
r: objectBox ? r0 * k : r0 * k / viewWidth / bw,
|
|
3316
|
+
ry: objectBox ? r0 * k : r0 * k / viewHeight / bh,
|
|
3317
|
+
fx,
|
|
3318
|
+
fy,
|
|
3319
|
+
stops: colors
|
|
3320
|
+
});
|
|
3321
|
+
};
|
|
3322
|
+
const paint = (value) => String(value).startsWith("url(") ? averageColor(value, false) : parseColor$1(value);
|
|
3056
3323
|
const emit = (subpath, matrix, style, id) => {
|
|
3057
3324
|
[subpath.start, ...subpath.curves.flatMap((curve) => [
|
|
3058
3325
|
[curve[0], curve[1]],
|
|
3059
3326
|
[curve[2], curve[3]],
|
|
3060
3327
|
[curve[4], curve[5]]
|
|
3061
3328
|
])];
|
|
3329
|
+
const fillGradient = String(style.fill).startsWith("url(");
|
|
3062
3330
|
const fill = style.fill === "none" ? "none" : paint(style.fill);
|
|
3063
|
-
const stroke = style.stroke === "none" ? "none" : paint(style.stroke);
|
|
3331
|
+
const stroke = style.stroke === "none" ? "none" : String(style.stroke).startsWith("url(") ? averageColor(style.stroke, true) : paint(style.stroke);
|
|
3332
|
+
const blur = Math.min(64, Math.round(style.blur * scale * Math.sqrt(determinant(matrix)) * 10) / 10);
|
|
3333
|
+
const add = (list) => commands.push(...list.map((item) => ({
|
|
3334
|
+
...item,
|
|
3335
|
+
...blur >= .5 ? { blur } : {},
|
|
3336
|
+
...style.clip ? { clip: style.clip } : {},
|
|
3337
|
+
...style.blend ? { blend: style.blend } : {}
|
|
3338
|
+
})));
|
|
3064
3339
|
const common = layer === void 0 ? {} : { layer };
|
|
3065
3340
|
const strokeWidth = Math.max(1, Math.min(256, (style.strokeWidth || 1) * scale * Math.hypot(matrix[0], matrix[1])));
|
|
3066
3341
|
const segments = subpath.curves.length;
|
|
@@ -3157,21 +3432,131 @@ window.__ModuleLoader__.load({
|
|
|
3157
3432
|
}
|
|
3158
3433
|
return pieces;
|
|
3159
3434
|
};
|
|
3160
|
-
if (fill !== "none" && style.fillOpacity * style.opacity > 0)
|
|
3161
|
-
|
|
3435
|
+
if (fill !== "none" && style.fillOpacity * style.opacity > 0) {
|
|
3436
|
+
let pieces = build(fill, style.fillOpacity * style.opacity, true, "");
|
|
3437
|
+
if (fillGradient) {
|
|
3438
|
+
const gradient = pieces.length === 1 && [
|
|
3439
|
+
"rectangle",
|
|
3440
|
+
"circle",
|
|
3441
|
+
"polygon",
|
|
3442
|
+
"bezier"
|
|
3443
|
+
].includes(pieces[0].shape) ? nativeGradient(style.fill, matrix, pieces[0]) : void 0;
|
|
3444
|
+
if (gradient) pieces = [{
|
|
3445
|
+
...pieces[0],
|
|
3446
|
+
gradient
|
|
3447
|
+
}];
|
|
3448
|
+
else warnings.add("A gradient fill was flattened to its average color (the path was split into several pieces, or its box is empty).");
|
|
3449
|
+
}
|
|
3450
|
+
add(pieces);
|
|
3451
|
+
}
|
|
3452
|
+
if (stroke !== "none" && style.strokeOpacity * style.opacity > 0 && style.strokeWidth > 0) add(build(stroke, style.strokeOpacity * style.opacity, false, "-line"));
|
|
3453
|
+
};
|
|
3454
|
+
const filterBlur = (reference, group) => {
|
|
3455
|
+
const target = byId.get(/^url\(\s*['"]?#([^)'"]+)['"]?\s*\)/.exec(reference)?.[1] ?? "");
|
|
3456
|
+
if (!target || target.name !== "filter") {
|
|
3457
|
+
warnings.add(`Filter ${reference} was ignored (it must be a <filter> defined in the same SVG).`);
|
|
3458
|
+
return 0;
|
|
3459
|
+
}
|
|
3460
|
+
const blurs = target.children.filter((child) => child.name === "feGaussianBlur").map((child) => Math.max(...numbers(child.attrs.stdDeviation ?? "0"), 0));
|
|
3461
|
+
if (target.children.some((child) => child.name !== "feGaussianBlur")) warnings.add(`Filter ${target.attrs.id ?? ""}: only feGaussianBlur is applied; other effects were ignored.`);
|
|
3462
|
+
if (blurs.length && group) warnings.add("A blur filter on a group softens each shape inside it separately.");
|
|
3463
|
+
return Math.max(0, ...blurs);
|
|
3464
|
+
};
|
|
3465
|
+
const clipSubpaths = (child) => {
|
|
3466
|
+
const m = (name) => Number.parseFloat(child.attrs[name] ?? 0);
|
|
3467
|
+
switch (child.name) {
|
|
3468
|
+
case "path": return parsePathData(child.attrs.d);
|
|
3469
|
+
case "rect": {
|
|
3470
|
+
const w = m("width"), h = m("height");
|
|
3471
|
+
if (!(w > 0 && h > 0)) return [];
|
|
3472
|
+
const rx = child.attrs.rx !== void 0 ? m("rx") : child.attrs.ry !== void 0 ? m("ry") : 0, ry = child.attrs.ry !== void 0 ? m("ry") : rx;
|
|
3473
|
+
return [rx > 0 || ry > 0 ? roundedRectPath(m("x"), m("y"), w, h, rx, ry) : polylinePath([
|
|
3474
|
+
[m("x"), m("y")],
|
|
3475
|
+
[m("x") + w, m("y")],
|
|
3476
|
+
[m("x") + w, m("y") + h],
|
|
3477
|
+
[m("x"), m("y") + h]
|
|
3478
|
+
], true)];
|
|
3479
|
+
}
|
|
3480
|
+
case "circle": return m("r") > 0 ? [ellipsePath(m("cx"), m("cy"), m("r"), m("r"))] : [];
|
|
3481
|
+
case "ellipse": return m("rx") > 0 && m("ry") > 0 ? [ellipsePath(m("cx"), m("cy"), m("rx"), m("ry"))] : [];
|
|
3482
|
+
case "polygon": {
|
|
3483
|
+
const values = numbers(child.attrs.points), pts = [];
|
|
3484
|
+
for (let at = 0; at + 1 < values.length; at += 2) pts.push([values[at], values[at + 1]]);
|
|
3485
|
+
return pts.length >= 3 ? [polylinePath(pts, true)] : [];
|
|
3486
|
+
}
|
|
3487
|
+
default: return [];
|
|
3488
|
+
}
|
|
3489
|
+
};
|
|
3490
|
+
const clipFor = (reference, matrix) => {
|
|
3491
|
+
const target = byId.get(/^url\(\s*['"]?#([^)'"]+)['"]?\s*\)/.exec(reference)?.[1] ?? "");
|
|
3492
|
+
if (!target || target.name !== "clipPath") {
|
|
3493
|
+
warnings.add(`clip-path ${reference} was ignored (it must be a <clipPath> defined in the same SVG).`);
|
|
3494
|
+
return;
|
|
3495
|
+
}
|
|
3496
|
+
const shapes = target.children.filter((child) => [
|
|
3497
|
+
"path",
|
|
3498
|
+
"rect",
|
|
3499
|
+
"circle",
|
|
3500
|
+
"ellipse",
|
|
3501
|
+
"polygon"
|
|
3502
|
+
].includes(child.name));
|
|
3503
|
+
if (!shapes.length) {
|
|
3504
|
+
warnings.add(`clipPath ${target.attrs.id ?? ""} has no path, rect, circle, ellipse or polygon and was ignored.`);
|
|
3505
|
+
return;
|
|
3506
|
+
}
|
|
3507
|
+
if (shapes.length > 1) warnings.add(`clipPath ${target.attrs.id ?? ""} has several shapes; only the first is used (merge them into one path).`);
|
|
3508
|
+
const placed = multiply(multiply(matrix, parseTransform(target.attrs.transform)), parseTransform(shapes[0].attrs.transform));
|
|
3509
|
+
const subpath = clipSubpaths(shapes[0])[0];
|
|
3510
|
+
if (!subpath) return void 0;
|
|
3511
|
+
const toPoint = ([px, py]) => norm(placed, px, py);
|
|
3512
|
+
const straightPoints = [subpath.start, ...subpath.curves.map((curve) => [curve[4], curve[5]])];
|
|
3513
|
+
if (subpath.straight && straightPoints.length >= 3) {
|
|
3514
|
+
const vertices = subpath.closed ? straightPoints.slice(0, -1) : straightPoints;
|
|
3515
|
+
return vertices.length >= 3 ? {
|
|
3516
|
+
shape: "polygon",
|
|
3517
|
+
points: vertices.slice(0, 2e3).map(toPoint)
|
|
3518
|
+
} : void 0;
|
|
3519
|
+
}
|
|
3520
|
+
if (subpath.curves.length <= MAX_BEZIER_SEGMENTS) return {
|
|
3521
|
+
shape: "bezier",
|
|
3522
|
+
points: [subpath.start, ...subpath.curves.flatMap((curve) => [
|
|
3523
|
+
[curve[0], curve[1]],
|
|
3524
|
+
[curve[2], curve[3]],
|
|
3525
|
+
[curve[4], curve[5]]
|
|
3526
|
+
])].map(toPoint)
|
|
3527
|
+
};
|
|
3528
|
+
const flat = [subpath.start];
|
|
3529
|
+
let [cx, cy] = subpath.start;
|
|
3530
|
+
for (const [a, b, c1, d, e, g] of subpath.curves) {
|
|
3531
|
+
for (let step = 1; step <= FLATTEN_STEPS; step++) {
|
|
3532
|
+
const t = step / FLATTEN_STEPS, u = 1 - t;
|
|
3533
|
+
flat.push([u * u * u * cx + 3 * u * u * t * a + 3 * u * t * t * c1 + t * t * t * e, u * u * u * cy + 3 * u * u * t * b + 3 * u * t * t * d + t * t * t * g]);
|
|
3534
|
+
}
|
|
3535
|
+
cx = e;
|
|
3536
|
+
cy = g;
|
|
3537
|
+
}
|
|
3538
|
+
return flat.length >= 3 && flat.length <= 2e3 ? {
|
|
3539
|
+
shape: "polygon",
|
|
3540
|
+
points: flat.map(toPoint)
|
|
3541
|
+
} : void 0;
|
|
3162
3542
|
};
|
|
3163
3543
|
const walk = (node, matrix, parentStyle, depth) => {
|
|
3164
3544
|
if (depth > 24) throw Error("SVG is nested too deeply");
|
|
3165
3545
|
if (UNSUPPORTED.has(node.name)) throw Error(`Unsupported SVG element <${node.name}>. Draw with path, rect, circle, ellipse, line, polyline, polygon, g and use; add text with a native text command.`);
|
|
3166
3546
|
if (IGNORED.has(node.name)) return;
|
|
3167
|
-
|
|
3168
|
-
"clip-path",
|
|
3169
|
-
"mask",
|
|
3170
|
-
"filter"
|
|
3171
|
-
]) if (node.attrs[name] && node.attrs[name] !== "none") throw Error(`Unsupported SVG attribute ${name}. Bake it into the shapes instead.`);
|
|
3547
|
+
if (node.attrs.mask && node.attrs.mask !== "none") throw Error("Unsupported SVG attribute mask. Bake it into the shapes instead.");
|
|
3172
3548
|
const style = styleOf(node, parentStyle);
|
|
3173
3549
|
if (style.display === "none") return;
|
|
3550
|
+
const filterValue = (node.attrs.filter ?? /(?:^|;)\s*filter\s*:\s*([^;]+)/.exec(node.attrs.style ?? "")?.[1] ?? "none").trim();
|
|
3551
|
+
if (filterValue !== "none") style.blur = Math.max(style.blur, filterBlur(filterValue, [
|
|
3552
|
+
"g",
|
|
3553
|
+
"svg",
|
|
3554
|
+
"a",
|
|
3555
|
+
"use"
|
|
3556
|
+
].includes(node.name)));
|
|
3174
3557
|
const local = multiply(matrix, parseTransform(node.attrs.transform));
|
|
3558
|
+
const clipValue = (node.attrs["clip-path"] ?? /(?:^|;)\s*clip-path\s*:\s*([^;]+)/.exec(node.attrs.style ?? "")?.[1] ?? "none").trim();
|
|
3559
|
+
if (clipValue !== "none") style.clip = clipFor(clipValue, local);
|
|
3175
3560
|
const n = (name) => Number.parseFloat(node.attrs[name] ?? 0);
|
|
3176
3561
|
const finish = (subpaths) => subpaths.forEach((subpath) => emit(subpath, local, style, node.attrs.id));
|
|
3177
3562
|
switch (node.name) {
|
|
@@ -3237,7 +3622,8 @@ window.__ModuleLoader__.load({
|
|
|
3237
3622
|
strokeWidth: 1,
|
|
3238
3623
|
fillOpacity: 1,
|
|
3239
3624
|
strokeOpacity: 1,
|
|
3240
|
-
opacity: 1
|
|
3625
|
+
opacity: 1,
|
|
3626
|
+
blur: 0
|
|
3241
3627
|
}, 0);
|
|
3242
3628
|
if (!commands.length) throw Error("The SVG contained no drawable shapes");
|
|
3243
3629
|
return {
|
|
@@ -3275,18 +3661,23 @@ window.__ModuleLoader__.load({
|
|
|
3275
3661
|
//#endregion
|
|
3276
3662
|
//#region src/sketch-commands.js
|
|
3277
3663
|
const MAX_SKETCH_POINTS = 2e5;
|
|
3664
|
+
const stale = (message) => Object.assign(Error(message), { code: "SKETCH_STALE" });
|
|
3278
3665
|
const SKETCH_COMMAND_HELP = {
|
|
3279
3666
|
coordinates: "Assign short meaningful stroke id values for later edits. Text uses two opposite box corners and text content; width is font size in pixels, automatic fitting within the box. Arrow uses two endpoints. Normalized x/y in [0,1]; width is canvas pixels. Read documentId and revision before editing.",
|
|
3280
3667
|
shapes: "line: exactly two endpoints; rectangle/circle (ellipse alias accepted): exactly two opposite bounding-box corners (circle draws an ellipse within that box); polygon: three or more vertices, closed automatically; pen: ordered path points. bezier: start point, then groups of control1/control2/end; use 4 points for one cubic curve, max 64 segments. Prefer bezier for smooth designed curves instead of many pen samples. fill:true closes and fills the curve. fill:true fills rectangle/circle/polygon. Layers and strokes paint in list order, later ones on top. All commands needed for drawing are described here; no source-code search is required.",
|
|
3668
|
+
guide: "How to draw well here. 1) Plan first: list the parts, the drawing order (back to front) and the rough position and size as fractions of the canvas; keep the plan short. 2) Work big to small and verify after every stage (apply returns progress; look:true or preview shows the result): silhouette and big colour areas, then form and shading, then outlines and small details. 3) Place by measuring, not by eye: with a reference use measure (palette, regions, points, scan) to get exact colours, sizes and edge positions; without one use preview grid and keep proportions (an 8-head figure for realistic bodies, 5–6 heads for anime, a larger head for cute). 4) Depth: every form gets five tones, a highlight, light, half-tone, form shadow and a reflected-light edge; shadows are tinted (blue, purple, teal), never pure black; use 4–8 stop gradients with hue shifts, blur for glow, haze and soft shadows. 5) Build limbs and hair as long tapered shapes (a few overlapping bezier or path shapes), cover joints with rounded shapes, draw the face last on top of the head: eyes (iris, pupil, highlight, lashes), brows, nose and mouth with the right size and spacing, check them with preview box zoomed in. 6) Group related shapes on one layer (hair, face, clothes, background) so they can be adjusted or hidden. 7) Undo a stage that made things worse instead of painting over it. 8) Repeated details (strands, pleats, stars) can be generated by a short script and sent as one svg command. 9) Refine region by region (see below). 10) Stop when the error of every region stops falling or the zoomed previews look right; do not add detail that the picture does not have. When the whole picture is roughly right, do refinement passes region by region instead of stopping: split the picture into its parts (for a figure: head and face, each mass of hair, torso, each arm, each leg, shoes and small accessories). For every part, call preview mode side with box set to that part and grid on (zoomed up to 3x) and look at reference and drawing next to each other, then measure with box on the same part and use scan along an edge to read exact positions; list the three biggest differences (edge position, size, colour, missing detail), fix them with targeted object updates or a replacement shape, and check progress. A part is done when its error stops falling or the zoomed pair looks the same; then go to the next part. Make at least one pass over every part before you finish, and never end with the first full draft.",
|
|
3281
3669
|
commands: {
|
|
3282
3670
|
preset: "triangle/diamond/star: {op:\"stroke\",id:\"badge\",shape:\"star\",points:[{x:0.1,y:0.1},{x:0.3,y:0.3}],color:\"#ffcc00\",fill:true}. Two opposite box corners; stored as editable polygon. Inspect objectId for one object without repeating full help.",
|
|
3283
|
-
stroke: "{op:\"stroke\",layer:1,shape:\"pen|line|arrow|text|rectangle|circle|polygon|bezier\",color:\"#rrggbb\",width:2,opacity:1,fill:false,points:[{x:0.1,y:0.1},...]}",
|
|
3671
|
+
stroke: "{op:\"stroke\",layer:1,shape:\"pen|line|arrow|text|rectangle|circle|polygon|bezier\",color:\"#rrggbb\",width:2,opacity:1,fill:false,points:[{x:0.1,y:0.1},...]}. Optional on any stroke: blend:\"multiply|screen|overlay|soft-light|hard-light|color-dodge|color-burn|darken|lighten|lighter\" (shadows multiply, glows screen or lighter; blends with what is already painted on the same layer; a whole layer can blend with the layers under it: {op:\"layer\",action:\"blend\",id:2,value:\"multiply\"}, value normal to clear) and clip:{shape:\"polygon|bezier|rectangle|circle\",points:[...]} keeps the stroke inside that shape, so shading and highlights stay inside the form they shade (clip.shape none removes it). Optional on filled shapes: gradient:{type:\"linear\",x1:0,y1:0,x2:0,y2:1,stops:[{offset:0,color:\"#ffcc66\"},{offset:1,color:\"#ff6644\",opacity:0.8}]} or {type:\"radial\",cx:0.5,cy:0.5,r:0.5,stops:[...]} (coordinates relative to the shape's own box, so moving or scaling the object keeps it); blur:12 softens any stroke by that many canvas pixels (glow, shadow, haze). Patch gradient:{type:\"none\"} or blur:0 to remove.",
|
|
3284
3672
|
layer: "Add: {op:\"layer\",action:\"add\",value:\"name\"}; optional id is the NEW unique integer ID, otherwise allocated automatically. after is the existing insertion anchor, defaults to active layer. Other actions: {op:\"layer\",action:\"select|rename|visible|duplicate|up|down|delete|clear\",id:1,value:\"name\"}; id targets an existing layer.",
|
|
3285
3673
|
curve: "Prefer {op:\"stroke\",shape:\"bezier\",start:{x:0,y:0},segments:[{control1:{x:0.2,y:0},control2:{x:0.8,y:1},end:{x:1,y:1}}],color:\"#123456\"}. Each segment has exactly two controls and an endpoint; no point counting required. Legacy points arrays still accepted. Do not provide both forms.",
|
|
3286
3674
|
object: "{op:\"object\",layer:1,id:\"title\",action:\"update|duplicate|delete\",patch:{color:\"#0088ff\",text:\"Title\"},transform:{dx:0.05,dy:0,scaleX:1,scaleY:1}}. All patch and transform fields optional. Inspect returns object IDs and bounds. Prefer targeted edits over redrawing layers.",
|
|
3287
3675
|
resize: "{op:\"resize\",ratio:\"1:1|4:3|3:4|16:9|9:16\"}",
|
|
3288
|
-
svg: "{op:\"svg\",svg:\"<svg viewBox=\\\"0 0 1024 768\\\">...</svg>\",layer:1}. Fastest way to draw: send a whole scene as SVG (path with M L H V C S Q T A Z, rect, circle, ellipse, line, polyline, polygon, g, use, transform, fill/stroke/opacity, style=\"...\"); it becomes native editable strokes. The viewBox must match the canvas size (use the width and height from inspect; 4:3 is 1024x768).
|
|
3676
|
+
svg: "{op:\"svg\",svg:\"<svg viewBox=\\\"0 0 1024 768\\\">...</svg>\",layer:1}. Fastest way to draw: send a whole scene as SVG (path with M L H V C S Q T A Z, rect, circle, ellipse, line, polyline, polygon, g, use, transform, fill/stroke/opacity, style=\"...\"); it becomes native editable strokes. The viewBox must match the canvas size (use the width and height from inspect; 4:3 is 1024x768). mix-blend-mode on an element becomes blend, and clip-path=\"url(#id)\" with a clipPath holding one path, rect, circle, ellipse or polygon becomes clip (use the same clipPath for all the shading of a form). Linear and radial gradients on filled shapes are kept as real gradients (fill=\"url(#id)\", objectBoundingBox or userSpaceOnUse, gradientTransform, stop-opacity); a gradient on a stroke line is flattened to its average color. A filter with feGaussianBlur becomes a soft edge on each shape it covers (glows, shadows, haze, depth of field); other filter effects are ignored with a warning. Text, image, mask, pattern and CSS classes are refused. Coordinates outside the canvas are clamped. One svg command may hold up to 200000 characters."
|
|
3289
3677
|
},
|
|
3678
|
+
measure: "Action measure (not a command): {action:\"measure\",runId,documentId,columns:6,rows:8,box:{x:0,y:0,width:1,height:1},points:[{x:0.5,y:0.3}],palette:8,regions:8,scan:{x1:0,y1:0.5,x2:1,y2:0.5}} compares the drawing with the reference picture and returns error (0 = identical, percent of the colour range), the worst cells (box in 0..1, error, reference and drawing colour as #rrggbb, tone = how much lighter (+) or darker (-) the drawing is than the reference, 0..255; cells:true returns every cell instead of the worst ten, a full colour-error map you can work through), for points the reference and drawing colour there, with palette the main colours of the reference (share of the area), with regions where each main colour sits (share, centre, box that holds most of it), and with scan a ruler laid along a line: the colour runs of the reference and of your drawing along it, with their start and end positions, so you can place edges exactly (scan a row across the hair, a column through the body). box limits it to one part. Every apply also returns progress (error now, error before, three worst cells), so you can see whether a stage helped. Fix the worst cell first, read exact colours from the reference instead of guessing.",
|
|
3679
|
+
undo: "Action undo: {action:\"undo\",runId,documentId,revision (optional),steps:1} takes back the last batches you applied (one per apply) and returns the new revision. Use it when a stage made things worse instead of painting over it.",
|
|
3680
|
+
preview: "Action preview: {action:\"preview\",mode:\"side|diff\",compare:true,grid:true,box:{x:0.3,y:0.1,width:0.4,height:0.3}}. mode side puts the reference and your drawing next to each other; mode diff adds a difference heat map (dark = matches, blue to red = increasingly different in brightness, colour or edges); compare blends both 50/50; grid labels canvas pixels; box zooms into one part (normalised x,y,width,height) so you can check eyes, hands, edges. Apply with look:true returns the side-by-side picture with the result.",
|
|
3290
3681
|
limits: {
|
|
3291
3682
|
strokes: MAX_SKETCH_STROKES,
|
|
3292
3683
|
pointsPerStroke: MAX_STROKE_POINTS,
|
|
@@ -3317,13 +3708,14 @@ window.__ModuleLoader__.load({
|
|
|
3317
3708
|
"up",
|
|
3318
3709
|
"down",
|
|
3319
3710
|
"delete",
|
|
3320
|
-
"clear"
|
|
3711
|
+
"clear",
|
|
3712
|
+
"blend"
|
|
3321
3713
|
].includes(command.action)) throw Error("Unknown layer action");
|
|
3322
3714
|
if (command.action === "add") {
|
|
3323
3715
|
const id = command.id ?? doc.nextId, after = command.after ?? doc.active;
|
|
3324
3716
|
if (!Number.isSafeInteger(id) || id < 1 || id === Number.MAX_SAFE_INTEGER || doc.layers.some((l) => l.id === id)) throw Error("New layer id must be a unique positive integer; omit id to allocate automatically");
|
|
3325
3717
|
const next = changeSketchLayer(doc, "add", after);
|
|
3326
|
-
if (next === doc) throw Error("Cannot add layer:
|
|
3718
|
+
if (next === doc) throw Error(doc.layers.length >= 8 ? "Cannot add layer: the board already has 8 layers, the most it holds. Draw on an existing layer, or delete or merge one first." : "Cannot add layer: after must be the id of an existing layer");
|
|
3327
3719
|
doc = {
|
|
3328
3720
|
...next,
|
|
3329
3721
|
active: id,
|
|
@@ -3359,7 +3751,11 @@ window.__ModuleLoader__.load({
|
|
|
3359
3751
|
"opacity",
|
|
3360
3752
|
"fill",
|
|
3361
3753
|
"text",
|
|
3362
|
-
"points"
|
|
3754
|
+
"points",
|
|
3755
|
+
"gradient",
|
|
3756
|
+
"blur",
|
|
3757
|
+
"blend",
|
|
3758
|
+
"clip"
|
|
3363
3759
|
].includes(k))) throw Error("Unsupported object property");
|
|
3364
3760
|
const changed = command.transform ? transformObject({
|
|
3365
3761
|
...original,
|
|
@@ -3384,6 +3780,7 @@ window.__ModuleLoader__.load({
|
|
|
3384
3780
|
...original.pressure !== void 0 ? { pressure: original.pressure } : {},
|
|
3385
3781
|
...original.brushVersion === 2 ? { brushVersion: 2 } : {}
|
|
3386
3782
|
};
|
|
3783
|
+
if (patch.gradient === void 0 && original.gradient && !strokes[index].gradient && original.fill) strokes[index].gradient = original.gradient;
|
|
3387
3784
|
} else throw Error("Unknown object action");
|
|
3388
3785
|
doc = {
|
|
3389
3786
|
...doc,
|
|
@@ -3436,6 +3833,8 @@ window.__ModuleLoader__.load({
|
|
|
3436
3833
|
if (shape === "text" && (typeof command.text !== "string" || !command.text.trim() || command.text.length > 500 || points[0].x === points[1].x || points[0].y === points[1].y)) throw Error("Text requires 1–500 characters and a non-empty bounding box");
|
|
3437
3834
|
const id = command.id ?? crypto.randomUUID();
|
|
3438
3835
|
if (typeof id !== "string" || !id.length || id.length > 100 || layer.strokes.some((s) => s.id === id)) throw Error("Invalid or duplicate object id");
|
|
3836
|
+
const gradient = normalizeGradient(command.gradient), blur = normalizeBlur(command.blur), blend = normalizeBlend(command.blend), clip = normalizeClip(command.clip);
|
|
3837
|
+
if (gradient && !gradientFits(shape, fill)) throw Error("A gradient needs fill:true on a rectangle, circle, polygon or bezier shape");
|
|
3439
3838
|
const stroke = {
|
|
3440
3839
|
id,
|
|
3441
3840
|
...shape === "text" ? { text: command.text } : {},
|
|
@@ -3444,6 +3843,10 @@ window.__ModuleLoader__.load({
|
|
|
3444
3843
|
width,
|
|
3445
3844
|
opacity,
|
|
3446
3845
|
fill,
|
|
3846
|
+
...gradient ? { gradient } : {},
|
|
3847
|
+
...blur ? { blur } : {},
|
|
3848
|
+
...blend ? { blend } : {},
|
|
3849
|
+
...clip ? { clip } : {},
|
|
3447
3850
|
brush: "pen",
|
|
3448
3851
|
points: points.map((p) => ({
|
|
3449
3852
|
x: p.x,
|
|
@@ -3486,17 +3889,92 @@ window.__ModuleLoader__.load({
|
|
|
3486
3889
|
}
|
|
3487
3890
|
if (request.documentId !== current.documentId) throw Error("Document changed; inspect again");
|
|
3488
3891
|
if (pending || adapter.busy()) throw Error("Sketch is being edited; retry after it settles");
|
|
3892
|
+
const boxOf = (value) => {
|
|
3893
|
+
if (value === void 0) return void 0;
|
|
3894
|
+
if (!value || typeof value !== "object" || ![
|
|
3895
|
+
"x",
|
|
3896
|
+
"y",
|
|
3897
|
+
"width",
|
|
3898
|
+
"height"
|
|
3899
|
+
].every((key) => typeof value[key] === "number" && Number.isFinite(value[key])) || value.x < 0 || value.y < 0 || value.width < .02 || value.height < .02 || value.x + value.width > 1.0001 || value.y + value.height > 1.0001) throw Error("box must be {x,y,width,height} inside 0..1, at least 0.02 wide and high");
|
|
3900
|
+
return {
|
|
3901
|
+
x: value.x,
|
|
3902
|
+
y: value.y,
|
|
3903
|
+
width: value.width,
|
|
3904
|
+
height: value.height
|
|
3905
|
+
};
|
|
3906
|
+
};
|
|
3489
3907
|
if (request.action === "preview") {
|
|
3490
3908
|
for (const key of ["compare", "grid"]) if (request[key] !== void 0 && typeof request[key] !== "boolean") throw Error(`${key} must be true or false`);
|
|
3909
|
+
if (request.mode !== void 0 && !["side", "diff"].includes(request.mode)) throw Error("mode must be side or diff");
|
|
3491
3910
|
return {
|
|
3492
3911
|
...current,
|
|
3493
3912
|
png: await adapter.preview({
|
|
3494
3913
|
compare: request.compare === true,
|
|
3495
|
-
grid: request.grid === true
|
|
3914
|
+
grid: request.grid === true,
|
|
3915
|
+
...request.mode ? { mode: request.mode } : {},
|
|
3916
|
+
...request.box ? { box: boxOf(request.box) } : {}
|
|
3496
3917
|
}),
|
|
3497
3918
|
...request.grid ? { gridStep: 100 } : {}
|
|
3498
3919
|
};
|
|
3499
3920
|
}
|
|
3921
|
+
if (request.action === "measure") {
|
|
3922
|
+
const grid = (name, fallback) => {
|
|
3923
|
+
const value = request[name] ?? fallback;
|
|
3924
|
+
if (!Number.isInteger(value) || value < 1 || value > 16) throw Error(`${name} must be an integer from 1 to 16`);
|
|
3925
|
+
return value;
|
|
3926
|
+
};
|
|
3927
|
+
const points = request.points ?? [];
|
|
3928
|
+
if (!Array.isArray(points) || points.length > 40 || points.some((point) => !point || !finite(point.x, 0, 1) || !finite(point.y, 0, 1))) throw Error("points must be at most 40 {x,y} pairs inside 0..1");
|
|
3929
|
+
if (typeof adapter.measure !== "function") throw Error("measure is not available");
|
|
3930
|
+
const palette = request.palette ?? 0;
|
|
3931
|
+
if (!Number.isInteger(palette) || palette < 0 || palette > 12) throw Error("palette must be an integer from 0 to 12");
|
|
3932
|
+
const regions = request.regions ?? 0;
|
|
3933
|
+
if (!Number.isInteger(regions) || regions < 0 || regions > 12) throw Error("regions must be an integer from 0 to 12");
|
|
3934
|
+
const scan = request.scan;
|
|
3935
|
+
if (scan !== void 0 && (!scan || ![
|
|
3936
|
+
"x1",
|
|
3937
|
+
"y1",
|
|
3938
|
+
"x2",
|
|
3939
|
+
"y2"
|
|
3940
|
+
].every((key) => finite(scan[key], 0, 1)))) throw Error("scan must be {x1,y1,x2,y2} inside 0..1");
|
|
3941
|
+
const box = boxOf(request.box);
|
|
3942
|
+
try {
|
|
3943
|
+
return {
|
|
3944
|
+
...current,
|
|
3945
|
+
measure: await adapter.measure({
|
|
3946
|
+
columns: grid("columns", 6),
|
|
3947
|
+
rows: grid("rows", 8),
|
|
3948
|
+
cells: request.cells === true,
|
|
3949
|
+
points,
|
|
3950
|
+
palette,
|
|
3951
|
+
regions,
|
|
3952
|
+
...scan ? { scan: {
|
|
3953
|
+
x1: scan.x1,
|
|
3954
|
+
y1: scan.y1,
|
|
3955
|
+
x2: scan.x2,
|
|
3956
|
+
y2: scan.y2
|
|
3957
|
+
} } : {},
|
|
3958
|
+
box
|
|
3959
|
+
})
|
|
3960
|
+
};
|
|
3961
|
+
} catch (cause) {
|
|
3962
|
+
const error = new Error(`${cause.message} Correct the request and retry with the same runId.`, { cause });
|
|
3963
|
+
error.code = "SKETCH_INVALID_BATCH";
|
|
3964
|
+
throw error;
|
|
3965
|
+
}
|
|
3966
|
+
}
|
|
3967
|
+
if (request.action === "undo") {
|
|
3968
|
+
const steps = request.steps ?? 1;
|
|
3969
|
+
if (!Number.isInteger(steps) || steps < 1 || steps > 20) throw Error("steps must be an integer from 1 to 20");
|
|
3970
|
+
if (request.revision !== void 0 && request.revision !== current.revision) throw stale("Sketch changed or is being edited; inspect again");
|
|
3971
|
+
if (typeof adapter.undo !== "function") throw Error("undo is not available");
|
|
3972
|
+
const taken = adapter.undo(steps);
|
|
3973
|
+
return {
|
|
3974
|
+
...adapter.snapshot(),
|
|
3975
|
+
undone: taken
|
|
3976
|
+
};
|
|
3977
|
+
}
|
|
3500
3978
|
if (![
|
|
3501
3979
|
"apply",
|
|
3502
3980
|
"save",
|
|
@@ -3512,11 +3990,24 @@ window.__ModuleLoader__.load({
|
|
|
3512
3990
|
if (cached.fingerprint !== fingerprint) throw Error("requestId reused with different content");
|
|
3513
3991
|
return cached.result;
|
|
3514
3992
|
}
|
|
3515
|
-
if (request.revision
|
|
3516
|
-
|
|
3993
|
+
if (request.revision === void 0) throw stale("revision is required: copy it from the last result");
|
|
3994
|
+
if (request.revision !== current.revision || adapter.busy()) throw stale("Sketch changed or is being edited; inspect again");
|
|
3995
|
+
let changedObjects, progress, previousError;
|
|
3517
3996
|
const report = {};
|
|
3997
|
+
const measureNow = async () => {
|
|
3998
|
+
try {
|
|
3999
|
+
return typeof adapter.measure === "function" ? await adapter.measure({
|
|
4000
|
+
columns: 6,
|
|
4001
|
+
rows: 8,
|
|
4002
|
+
points: []
|
|
4003
|
+
}) : void 0;
|
|
4004
|
+
} catch {
|
|
4005
|
+
return;
|
|
4006
|
+
}
|
|
4007
|
+
};
|
|
3518
4008
|
if (request.action === "apply") {
|
|
3519
4009
|
const before = adapter.document();
|
|
4010
|
+
previousError = before.layers.some((layer) => layer.image) ? (await measureNow())?.error : void 0;
|
|
3520
4011
|
let next;
|
|
3521
4012
|
try {
|
|
3522
4013
|
next = applySketchCommands(before, request.commands, report);
|
|
@@ -3531,6 +4022,14 @@ window.__ModuleLoader__.load({
|
|
|
3531
4022
|
layer: l.id,
|
|
3532
4023
|
id: s.id
|
|
3533
4024
|
})));
|
|
4025
|
+
if (previousError !== void 0) {
|
|
4026
|
+
const after = await measureNow();
|
|
4027
|
+
if (after) progress = {
|
|
4028
|
+
error: after.error,
|
|
4029
|
+
previous: previousError,
|
|
4030
|
+
worst: after.worst.slice(0, 3)
|
|
4031
|
+
};
|
|
4032
|
+
}
|
|
3534
4033
|
} else if (request.action === "reference") {
|
|
3535
4034
|
if (typeof request.image !== "string" || !/^data:image\/(png|jpeg|webp);base64,/.test(request.image) || request.image.length > 19e5) throw Error("A PNG, JPEG or WebP reference image is required");
|
|
3536
4035
|
pending = true;
|
|
@@ -3548,6 +4047,13 @@ window.__ModuleLoader__.load({
|
|
|
3548
4047
|
pending = false;
|
|
3549
4048
|
}
|
|
3550
4049
|
}
|
|
4050
|
+
if (request.action === "save") {
|
|
4051
|
+
const last = adapter.document?.().layers.some((layer) => layer.image) ? await measureNow() : void 0;
|
|
4052
|
+
if (last) progress = {
|
|
4053
|
+
error: last.error,
|
|
4054
|
+
worst: last.worst.slice(0, 3)
|
|
4055
|
+
};
|
|
4056
|
+
}
|
|
3551
4057
|
const result = {
|
|
3552
4058
|
...adapter.snapshot(),
|
|
3553
4059
|
...changedObjects ? {
|
|
@@ -3555,7 +4061,8 @@ window.__ModuleLoader__.load({
|
|
|
3555
4061
|
changedObjectCount: changedObjects.length
|
|
3556
4062
|
} : {},
|
|
3557
4063
|
...report?.warnings?.length ? { warnings: report.warnings } : {},
|
|
3558
|
-
...report?.clampedPoints ? { clampedPoints: report.clampedPoints } : {}
|
|
4064
|
+
...report?.clampedPoints ? { clampedPoints: report.clampedPoints } : {},
|
|
4065
|
+
...progress ? { progress } : {}
|
|
3559
4066
|
};
|
|
3560
4067
|
completed.set(key, {
|
|
3561
4068
|
fingerprint,
|
|
@@ -3572,6 +4079,17 @@ window.__ModuleLoader__.load({
|
|
|
3572
4079
|
cachedCharacters -= completed.get(oldest).fingerprint.length;
|
|
3573
4080
|
completed.delete(oldest);
|
|
3574
4081
|
}
|
|
4082
|
+
if (request.action === "apply" && request.look === true && typeof adapter.preview === "function") {
|
|
4083
|
+
const png = await adapter.preview({
|
|
4084
|
+
compare: false,
|
|
4085
|
+
grid: false,
|
|
4086
|
+
mode: adapter.document().layers.some((layer) => layer.image) ? "side" : void 0
|
|
4087
|
+
});
|
|
4088
|
+
return {
|
|
4089
|
+
...result,
|
|
4090
|
+
png
|
|
4091
|
+
};
|
|
4092
|
+
}
|
|
3575
4093
|
return result;
|
|
3576
4094
|
};
|
|
3577
4095
|
}
|
|
@@ -3632,6 +4150,8 @@ window.__ModuleLoader__.load({
|
|
|
3632
4150
|
const target = doc.layers.at(-1);
|
|
3633
4151
|
target.name = String(layer.name ?? "").slice(0, 40);
|
|
3634
4152
|
target.visible = layer.visible !== false;
|
|
4153
|
+
const blend = normalizeBlend(layer.blend);
|
|
4154
|
+
if (blend) target.blend = blend;
|
|
3635
4155
|
if (layer.image) {
|
|
3636
4156
|
const image = layer.image;
|
|
3637
4157
|
if (typeof image.src !== "string" || !/^data:image\/png;base64,/.test(image.src) || image.src.length > 8 * 1024 * 1024 || [
|
|
@@ -3708,6 +4228,7 @@ window.__ModuleLoader__.load({
|
|
|
3708
4228
|
cache.current.clear();
|
|
3709
4229
|
undo.current = [];
|
|
3710
4230
|
redo.current = [];
|
|
4231
|
+
if (state.timeline) state.timeline.current = [];
|
|
3711
4232
|
saved.current = identity;
|
|
3712
4233
|
dirty.current = false;
|
|
3713
4234
|
schedule();
|
|
@@ -3954,6 +4475,7 @@ window.__ModuleLoader__.load({
|
|
|
3954
4475
|
entry.image = layer.image;
|
|
3955
4476
|
entry.strokes = layer.strokes;
|
|
3956
4477
|
}
|
|
4478
|
+
context.globalCompositeOperation = layer.blend ?? "source-over";
|
|
3957
4479
|
if (moving) {
|
|
3958
4480
|
const ctx = entry.surface.getContext("2d");
|
|
3959
4481
|
ctx.clearRect(0, 0, size, height);
|
|
@@ -3961,65 +4483,240 @@ window.__ModuleLoader__.load({
|
|
|
3961
4483
|
paintSketch(ctx, layer.strokes, size, true, height, layer.strokes.length - 1);
|
|
3962
4484
|
context.drawImage(entry.surface, 0, 0);
|
|
3963
4485
|
} else context.drawImage(entry.base, 0, 0);
|
|
4486
|
+
context.globalCompositeOperation = "source-over";
|
|
4487
|
+
}
|
|
4488
|
+
}
|
|
4489
|
+
//#endregion
|
|
4490
|
+
//#region src/sketch-diff.js
|
|
4491
|
+
const luma = (data, at) => data[at] * .299 + data[at + 1] * .587 + data[at + 2] * .114;
|
|
4492
|
+
function lumaPlane(picture) {
|
|
4493
|
+
const { data, width, height } = picture, plane = new Float32Array(width * height);
|
|
4494
|
+
for (let i = 0; i < plane.length; i++) plane[i] = luma(data, i * 4);
|
|
4495
|
+
return plane;
|
|
4496
|
+
}
|
|
4497
|
+
function gradient(plane, width, height) {
|
|
4498
|
+
const out = new Float32Array(width * height);
|
|
4499
|
+
for (let y = 1; y < height - 1; y++) for (let x = 1; x < width - 1; x++) {
|
|
4500
|
+
const at = y * width + x;
|
|
4501
|
+
const gx = plane[at - width + 1] + 2 * plane[at + 1] + plane[at + width + 1] - plane[at - width - 1] - 2 * plane[at - 1] - plane[at + width - 1];
|
|
4502
|
+
const gy = plane[at + width - 1] + 2 * plane[at + width] + plane[at + width + 1] - plane[at - width - 1] - 2 * plane[at - width] - plane[at - width + 1];
|
|
4503
|
+
out[at] = Math.hypot(gx, gy) / 4;
|
|
4504
|
+
}
|
|
4505
|
+
return out;
|
|
4506
|
+
}
|
|
4507
|
+
const percentile = (values, share) => {
|
|
4508
|
+
const sample = [];
|
|
4509
|
+
const stride = Math.max(1, Math.floor(values.length / 2e4));
|
|
4510
|
+
for (let i = 0; i < values.length; i += stride) sample.push(values[i]);
|
|
4511
|
+
sample.sort((a, b) => a - b);
|
|
4512
|
+
return sample[Math.min(sample.length - 1, Math.floor(sample.length * share))] || 1e-6;
|
|
4513
|
+
};
|
|
4514
|
+
const STOPS = [
|
|
4515
|
+
[0, [
|
|
4516
|
+
24,
|
|
4517
|
+
24,
|
|
4518
|
+
28
|
|
4519
|
+
]],
|
|
4520
|
+
[.12, [
|
|
4521
|
+
24,
|
|
4522
|
+
24,
|
|
4523
|
+
28
|
|
4524
|
+
]],
|
|
4525
|
+
[.3, [
|
|
4526
|
+
40,
|
|
4527
|
+
80,
|
|
4528
|
+
230
|
|
4529
|
+
]],
|
|
4530
|
+
[.5, [
|
|
4531
|
+
30,
|
|
4532
|
+
200,
|
|
4533
|
+
220
|
|
4534
|
+
]],
|
|
4535
|
+
[.72, [
|
|
4536
|
+
250,
|
|
4537
|
+
220,
|
|
4538
|
+
40
|
|
4539
|
+
]],
|
|
4540
|
+
[1, [
|
|
4541
|
+
235,
|
|
4542
|
+
30,
|
|
4543
|
+
30
|
|
4544
|
+
]]
|
|
4545
|
+
];
|
|
4546
|
+
const heat = (value) => {
|
|
4547
|
+
for (let i = 1; i < STOPS.length; i++) if (value <= STOPS[i][0]) {
|
|
4548
|
+
const [a, ca] = STOPS[i - 1], [b, cb] = STOPS[i], part = (value - a) / (b - a || 1);
|
|
4549
|
+
return ca.map((channel, k) => channel + (cb[k] - channel) * part);
|
|
3964
4550
|
}
|
|
4551
|
+
return STOPS.at(-1)[1];
|
|
4552
|
+
};
|
|
4553
|
+
function diffHeatmap(reference, drawing) {
|
|
4554
|
+
const { width, height } = reference, count = width * height;
|
|
4555
|
+
const lumaR = lumaPlane(reference), lumaD = lumaPlane(drawing);
|
|
4556
|
+
const gradR = gradient(lumaR, width, height), gradD = gradient(lumaD, width, height);
|
|
4557
|
+
const bright = new Float32Array(count), color = new Float32Array(count), edge = new Float32Array(count);
|
|
4558
|
+
for (let i = 0; i < count; i++) {
|
|
4559
|
+
const at = i * 4;
|
|
4560
|
+
const cbR = reference.data[at + 2] - lumaR[i], crR = reference.data[at] - lumaR[i], cbD = drawing.data[at + 2] - lumaD[i], crD = drawing.data[at] - lumaD[i];
|
|
4561
|
+
bright[i] = Math.abs(lumaR[i] - lumaD[i]);
|
|
4562
|
+
color[i] = Math.hypot(cbR - cbD, crR - crD);
|
|
4563
|
+
edge[i] = Math.abs(gradR[i] - gradD[i]);
|
|
4564
|
+
}
|
|
4565
|
+
const [pb, pc, pe] = [
|
|
4566
|
+
bright,
|
|
4567
|
+
color,
|
|
4568
|
+
edge
|
|
4569
|
+
].map((values) => percentile(values, .97));
|
|
4570
|
+
const out = new Uint8ClampedArray(count * 4);
|
|
4571
|
+
for (let i = 0; i < count; i++) {
|
|
4572
|
+
const mix = .3 * bright[i] / pb + .45 * color[i] / pc + .25 * edge[i] / pe;
|
|
4573
|
+
const [r, g, b] = heat(Math.min(1, Math.pow(Math.min(1, mix / 1.3), .7)));
|
|
4574
|
+
out[i * 4] = r;
|
|
4575
|
+
out[i * 4 + 1] = g;
|
|
4576
|
+
out[i * 4 + 2] = b;
|
|
4577
|
+
out[i * 4 + 3] = 255;
|
|
4578
|
+
}
|
|
4579
|
+
return {
|
|
4580
|
+
data: out,
|
|
4581
|
+
width,
|
|
4582
|
+
height
|
|
4583
|
+
};
|
|
3965
4584
|
}
|
|
3966
4585
|
//#endregion
|
|
3967
4586
|
//#region src/sketch-preview.js
|
|
3968
4587
|
const GRID_STEP = 100;
|
|
3969
|
-
|
|
3970
|
-
|
|
4588
|
+
const PANE_WIDTH = 560;
|
|
4589
|
+
const PANE_HEIGHT = 760;
|
|
4590
|
+
const LABEL = 22;
|
|
4591
|
+
const GAP = 10;
|
|
4592
|
+
const MAX_SURFACE = 4096;
|
|
4593
|
+
const referenceOf = (doc) => ({
|
|
4594
|
+
...doc,
|
|
4595
|
+
layers: doc.layers.map((layer) => ({
|
|
4596
|
+
...layer,
|
|
4597
|
+
strokes: [],
|
|
4598
|
+
visible: Boolean(layer.image)
|
|
4599
|
+
}))
|
|
4600
|
+
});
|
|
4601
|
+
const drawingOf = (doc) => ({
|
|
4602
|
+
...doc,
|
|
4603
|
+
layers: doc.layers.map((layer) => ({
|
|
4604
|
+
...layer,
|
|
4605
|
+
image: void 0
|
|
4606
|
+
}))
|
|
4607
|
+
});
|
|
4608
|
+
function composeSketchPreview({ doc, images, width, height, options = {}, makeSurface, paintLayers, readPixels = (surface) => surface.getContext("2d").getImageData(0, 0, surface.width, surface.height) }) {
|
|
4609
|
+
const hasReference = doc.layers.some((layer) => layer.image);
|
|
4610
|
+
const mode = options.mode === "side" || options.mode === "diff" ? options.mode : void 0;
|
|
4611
|
+
if ((options.compare || mode) && !hasReference) throw Error("compare needs a reference picture layer on the board; ask the user to add the reference with the pictures button");
|
|
4612
|
+
const box = options.box;
|
|
4613
|
+
const region = box ? {
|
|
4614
|
+
x: box.x * width,
|
|
4615
|
+
y: box.y * height,
|
|
4616
|
+
w: box.width * width,
|
|
4617
|
+
h: box.height * height
|
|
4618
|
+
} : {
|
|
4619
|
+
x: 0,
|
|
4620
|
+
y: 0,
|
|
4621
|
+
w: width,
|
|
4622
|
+
h: height
|
|
4623
|
+
};
|
|
4624
|
+
const zoom = box ? Math.max(1, Math.min(3, 900 / Math.max(region.w, region.h), MAX_SURFACE / width, MAX_SURFACE / height)) : 1;
|
|
4625
|
+
const render = (variant) => {
|
|
4626
|
+
const bigWidth = Math.round(width * zoom), bigHeight = Math.round(height * zoom);
|
|
4627
|
+
const big = makeSurface(bigWidth, bigHeight);
|
|
4628
|
+
paintLayers(big.getContext("2d"), variant, /* @__PURE__ */ new Map(), bigWidth, bigHeight, void 0, images);
|
|
4629
|
+
if (!box) return big;
|
|
4630
|
+
const out = makeSurface(Math.max(1, Math.round(region.w * zoom)), Math.max(1, Math.round(region.h * zoom)));
|
|
4631
|
+
out.getContext("2d").drawImage(big, Math.round(region.x * zoom), Math.round(region.y * zoom), out.width, out.height, 0, 0, out.width, out.height);
|
|
4632
|
+
return out;
|
|
4633
|
+
};
|
|
4634
|
+
const grid = (context, w, h) => {
|
|
4635
|
+
if (options.grid) paintGrid(context, w, h, region, zoom);
|
|
4636
|
+
};
|
|
4637
|
+
if (mode) {
|
|
4638
|
+
const reference = render(referenceOf(doc)), drawing = render(drawingOf(doc));
|
|
4639
|
+
const scale = Math.min(1, PANE_WIDTH / reference.width, PANE_HEIGHT / reference.height);
|
|
4640
|
+
const paneWidth = Math.max(1, Math.round(reference.width * scale)), paneHeight = Math.max(1, Math.round(reference.height * scale));
|
|
4641
|
+
const panes = mode === "diff" ? 3 : 2;
|
|
4642
|
+
const surface = makeSurface(panes * paneWidth + (panes - 1) * GAP, paneHeight + LABEL), context = surface.getContext("2d");
|
|
4643
|
+
context.fillStyle = "#ffffff";
|
|
4644
|
+
context.fillRect(0, 0, surface.width, surface.height);
|
|
4645
|
+
const labels = [
|
|
4646
|
+
"reference",
|
|
4647
|
+
"drawing",
|
|
4648
|
+
"difference"
|
|
4649
|
+
];
|
|
4650
|
+
const place = (source, index) => {
|
|
4651
|
+
context.drawImage(source, index * (paneWidth + GAP), LABEL, paneWidth, paneHeight);
|
|
4652
|
+
context.save();
|
|
4653
|
+
context.beginPath();
|
|
4654
|
+
context.rect(index * (paneWidth + GAP), LABEL, paneWidth, paneHeight);
|
|
4655
|
+
context.clip();
|
|
4656
|
+
context.translate(index * (paneWidth + GAP), LABEL);
|
|
4657
|
+
context.scale(scale, scale);
|
|
4658
|
+
grid(context, reference.width, reference.height);
|
|
4659
|
+
context.restore();
|
|
4660
|
+
context.fillStyle = "#222222";
|
|
4661
|
+
context.font = "14px sans-serif";
|
|
4662
|
+
context.textBaseline = "top";
|
|
4663
|
+
context.fillText(labels[index], index * (paneWidth + GAP) + 4, 3);
|
|
4664
|
+
};
|
|
4665
|
+
place(reference, 0);
|
|
4666
|
+
place(drawing, 1);
|
|
4667
|
+
if (mode === "diff") {
|
|
4668
|
+
const heat = makeSurface(reference.width, reference.height);
|
|
4669
|
+
const pixels = diffHeatmap(readPixels(reference), readPixels(drawing));
|
|
4670
|
+
heat.getContext("2d").putImageData(new ImageData(pixels.data, pixels.width, pixels.height), 0, 0);
|
|
4671
|
+
place(heat, 2);
|
|
4672
|
+
}
|
|
4673
|
+
return surface.toDataURL("image/png");
|
|
4674
|
+
}
|
|
3971
4675
|
if (options.compare) {
|
|
3972
|
-
|
|
3973
|
-
const
|
|
3974
|
-
paintLayers(reference.getContext("2d"), {
|
|
3975
|
-
...doc,
|
|
3976
|
-
layers: doc.layers.map((layer) => ({
|
|
3977
|
-
...layer,
|
|
3978
|
-
strokes: [],
|
|
3979
|
-
visible: Boolean(layer.image)
|
|
3980
|
-
}))
|
|
3981
|
-
}, /* @__PURE__ */ new Map(), width, height, void 0, images);
|
|
3982
|
-
paintLayers(drawing.getContext("2d"), {
|
|
3983
|
-
...doc,
|
|
3984
|
-
layers: doc.layers.map((layer) => ({
|
|
3985
|
-
...layer,
|
|
3986
|
-
image: void 0
|
|
3987
|
-
}))
|
|
3988
|
-
}, /* @__PURE__ */ new Map(), width, height, void 0, images);
|
|
4676
|
+
const reference = render(referenceOf(doc)), drawing = render(drawingOf(doc));
|
|
4677
|
+
const surface = makeSurface(reference.width, reference.height), context = surface.getContext("2d");
|
|
3989
4678
|
context.drawImage(reference, 0, 0);
|
|
3990
4679
|
context.globalAlpha = .5;
|
|
3991
4680
|
context.drawImage(drawing, 0, 0);
|
|
3992
4681
|
context.globalAlpha = 1;
|
|
3993
|
-
|
|
3994
|
-
|
|
4682
|
+
grid(context, surface.width, surface.height);
|
|
4683
|
+
return surface.toDataURL("image/png");
|
|
4684
|
+
}
|
|
4685
|
+
const surface = render(doc);
|
|
4686
|
+
grid(surface.getContext("2d"), surface.width, surface.height);
|
|
3995
4687
|
return surface.toDataURL("image/png");
|
|
3996
4688
|
}
|
|
3997
|
-
function paintGrid(context, width, height) {
|
|
4689
|
+
function paintGrid(context, width, height, region, zoom) {
|
|
4690
|
+
const step = zoom > 1.6 ? GRID_STEP / 2 : GRID_STEP;
|
|
3998
4691
|
context.save();
|
|
3999
4692
|
context.lineWidth = 1;
|
|
4000
4693
|
context.strokeStyle = "rgba(214,0,120,0.45)";
|
|
4001
4694
|
context.fillStyle = "rgba(214,0,120,0.9)";
|
|
4002
4695
|
context.font = "12px sans-serif";
|
|
4003
4696
|
context.textBaseline = "top";
|
|
4004
|
-
for (let
|
|
4697
|
+
for (let canvasX = Math.ceil(region.x / step) * step; canvasX < region.x + region.w; canvasX += step) {
|
|
4698
|
+
if (canvasX <= 0) continue;
|
|
4699
|
+
const x = Math.round((canvasX - region.x) * zoom);
|
|
4005
4700
|
context.beginPath();
|
|
4006
4701
|
context.moveTo(x + .5, 0);
|
|
4007
4702
|
context.lineTo(x + .5, height);
|
|
4008
4703
|
context.stroke();
|
|
4009
|
-
context.fillText(String(
|
|
4704
|
+
context.fillText(String(canvasX), x + 3, 2);
|
|
4010
4705
|
}
|
|
4011
|
-
for (let
|
|
4706
|
+
for (let canvasY = Math.ceil(region.y / step) * step; canvasY < region.y + region.h; canvasY += step) {
|
|
4707
|
+
if (canvasY <= 0) continue;
|
|
4708
|
+
const y = Math.round((canvasY - region.y) * zoom);
|
|
4012
4709
|
context.beginPath();
|
|
4013
4710
|
context.moveTo(0, y + .5);
|
|
4014
4711
|
context.lineTo(width, y + .5);
|
|
4015
4712
|
context.stroke();
|
|
4016
|
-
context.fillText(String(
|
|
4713
|
+
context.fillText(String(canvasY), 3, y + 2);
|
|
4017
4714
|
}
|
|
4018
4715
|
context.restore();
|
|
4019
4716
|
}
|
|
4020
4717
|
//#endregion
|
|
4021
4718
|
//#region src/sketch-files.jsx
|
|
4022
|
-
function SketchFiles({ save, load, fresh, importImage, download, hasContent, disabled, t, runOperation }) {
|
|
4719
|
+
function SketchFiles({ save, load, fresh, importImage, download, hasContent, disabled, t, runOperation, extra }) {
|
|
4023
4720
|
const [open, setOpen] = (0, react.useState)(false), [rows, setRows] = (0, react.useState)([]), [name, setName] = (0, react.useState)(""), [remove, setRemove] = (0, react.useState)(null), [working, setWorking] = (0, react.useState)(false);
|
|
4024
4721
|
const [format, setFormat] = (0, react.useState)("png");
|
|
4025
4722
|
const input = (0, react.useRef)(null), host = (0, react.useRef)(null);
|
|
@@ -4061,6 +4758,7 @@ window.__ModuleLoader__.load({
|
|
|
4061
4758
|
},
|
|
4062
4759
|
children: t("sketchFiles")
|
|
4063
4760
|
}),
|
|
4761
|
+
extra,
|
|
4064
4762
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
4065
4763
|
ref: input,
|
|
4066
4764
|
type: "file",
|
|
@@ -4176,6 +4874,491 @@ window.__ModuleLoader__.load({
|
|
|
4176
4874
|
});
|
|
4177
4875
|
}
|
|
4178
4876
|
//#endregion
|
|
4877
|
+
//#region src/sketch-replay.js
|
|
4878
|
+
const MAX_REPLAY_STATES = 2e3;
|
|
4879
|
+
function recordReplayState(states, doc) {
|
|
4880
|
+
if (states.at(-1) === doc) return;
|
|
4881
|
+
states.push(doc);
|
|
4882
|
+
if (states.length > 2e3) states.splice(0, states.length - MAX_REPLAY_STATES);
|
|
4883
|
+
}
|
|
4884
|
+
function appendedStrokes(before, after) {
|
|
4885
|
+
for (const layer of before.layers) {
|
|
4886
|
+
const next = after.layers.find((item) => item.id === layer.id);
|
|
4887
|
+
if (!next || next.image !== layer.image || layer.strokes.length > next.strokes.length || layer.strokes.some((stroke, i) => stroke !== next.strokes[i])) return void 0;
|
|
4888
|
+
}
|
|
4889
|
+
const added = [];
|
|
4890
|
+
for (const layer of after.layers) {
|
|
4891
|
+
const old = before.layers.find((item) => item.id === layer.id)?.strokes.length ?? 0;
|
|
4892
|
+
for (let i = old; i < layer.strokes.length; i++) added.push({
|
|
4893
|
+
layer: layer.id,
|
|
4894
|
+
stroke: layer.strokes[i]
|
|
4895
|
+
});
|
|
4896
|
+
}
|
|
4897
|
+
return added;
|
|
4898
|
+
}
|
|
4899
|
+
function replaySteps(states) {
|
|
4900
|
+
const steps = [];
|
|
4901
|
+
for (let index = 1; index < states.length; index++) {
|
|
4902
|
+
const before = states[index - 1], after = states[index];
|
|
4903
|
+
if (before === after) continue;
|
|
4904
|
+
const added = appendedStrokes(before, after);
|
|
4905
|
+
steps.push(added?.length ? {
|
|
4906
|
+
type: "draw",
|
|
4907
|
+
before,
|
|
4908
|
+
after,
|
|
4909
|
+
added
|
|
4910
|
+
} : {
|
|
4911
|
+
type: "jump",
|
|
4912
|
+
before,
|
|
4913
|
+
after,
|
|
4914
|
+
added: []
|
|
4915
|
+
});
|
|
4916
|
+
}
|
|
4917
|
+
return steps;
|
|
4918
|
+
}
|
|
4919
|
+
const lengthOf = (stroke, width, height) => {
|
|
4920
|
+
const points = stroke.points;
|
|
4921
|
+
let total = 0;
|
|
4922
|
+
for (let i = 1; i < points.length; i++) total += Math.hypot((points[i].x - points[i - 1].x) * width, (points[i].y - points[i - 1].y) * height);
|
|
4923
|
+
return total;
|
|
4924
|
+
};
|
|
4925
|
+
const OUTLINE_SHARE = .3;
|
|
4926
|
+
function strokePath(stroke) {
|
|
4927
|
+
const [first, last] = [stroke.points[0], stroke.points.at(-1)];
|
|
4928
|
+
if (!first || stroke.shape === "text" || stroke.shape === "eraser") return void 0;
|
|
4929
|
+
switch (stroke.shape) {
|
|
4930
|
+
case "line":
|
|
4931
|
+
case "arrow": return [first, last];
|
|
4932
|
+
case "bezier": return flattenSketchCurve(stroke, 1024, 1024);
|
|
4933
|
+
case "polygon": return [...stroke.points, first];
|
|
4934
|
+
case "rectangle": return [
|
|
4935
|
+
first,
|
|
4936
|
+
{
|
|
4937
|
+
x: last.x,
|
|
4938
|
+
y: first.y
|
|
4939
|
+
},
|
|
4940
|
+
last,
|
|
4941
|
+
{
|
|
4942
|
+
x: first.x,
|
|
4943
|
+
y: last.y
|
|
4944
|
+
},
|
|
4945
|
+
first
|
|
4946
|
+
];
|
|
4947
|
+
case "circle": {
|
|
4948
|
+
const cx = (first.x + last.x) / 2, cy = (first.y + last.y) / 2, rx = Math.abs(last.x - first.x) / 2, ry = Math.abs(last.y - first.y) / 2;
|
|
4949
|
+
return Array.from({ length: 49 }, (_, i) => ({
|
|
4950
|
+
x: cx + rx * Math.cos(i / 48 * Math.PI * 2),
|
|
4951
|
+
y: cy + ry * Math.sin(i / 48 * Math.PI * 2)
|
|
4952
|
+
}));
|
|
4953
|
+
}
|
|
4954
|
+
default: return stroke.points;
|
|
4955
|
+
}
|
|
4956
|
+
}
|
|
4957
|
+
function partialStroke(stroke, fraction) {
|
|
4958
|
+
if (fraction >= 1) return stroke;
|
|
4959
|
+
if (!(fraction > 0)) return {
|
|
4960
|
+
...stroke,
|
|
4961
|
+
opacity: 0
|
|
4962
|
+
};
|
|
4963
|
+
const filled = stroke.fill && stroke.shape !== "pen";
|
|
4964
|
+
if (filled && !stroke.gradient && fraction >= OUTLINE_SHARE && stroke.shape !== "text") {
|
|
4965
|
+
const reveal = (fraction - OUTLINE_SHARE) / (1 - OUTLINE_SHARE);
|
|
4966
|
+
const stops = [
|
|
4967
|
+
{
|
|
4968
|
+
offset: 0,
|
|
4969
|
+
color: stroke.color
|
|
4970
|
+
},
|
|
4971
|
+
{
|
|
4972
|
+
offset: reveal,
|
|
4973
|
+
color: stroke.color
|
|
4974
|
+
},
|
|
4975
|
+
{
|
|
4976
|
+
offset: Math.min(1, reveal + .002),
|
|
4977
|
+
color: stroke.color,
|
|
4978
|
+
opacity: 0
|
|
4979
|
+
},
|
|
4980
|
+
{
|
|
4981
|
+
offset: 1,
|
|
4982
|
+
color: stroke.color,
|
|
4983
|
+
opacity: 0
|
|
4984
|
+
}
|
|
4985
|
+
];
|
|
4986
|
+
return {
|
|
4987
|
+
...stroke,
|
|
4988
|
+
gradient: {
|
|
4989
|
+
type: "linear",
|
|
4990
|
+
x1: 0,
|
|
4991
|
+
y1: 0,
|
|
4992
|
+
x2: 0,
|
|
4993
|
+
y2: 1,
|
|
4994
|
+
stops
|
|
4995
|
+
}
|
|
4996
|
+
};
|
|
4997
|
+
}
|
|
4998
|
+
const path = strokePath(stroke);
|
|
4999
|
+
if (!path || path.length < 2) return {
|
|
5000
|
+
...stroke,
|
|
5001
|
+
opacity: (stroke.opacity ?? 1) * Math.max(0, fraction)
|
|
5002
|
+
};
|
|
5003
|
+
const share = filled ? fraction / OUTLINE_SHARE : fraction;
|
|
5004
|
+
const lengths = path.slice(1).map((point, i) => Math.hypot(point.x - path[i].x, point.y - path[i].y));
|
|
5005
|
+
let remaining = lengths.reduce((sum, value) => sum + value, 0) * Math.max(0, share);
|
|
5006
|
+
const points = [path[0]];
|
|
5007
|
+
for (let i = 0; i < lengths.length; i++) {
|
|
5008
|
+
if (remaining >= lengths[i]) {
|
|
5009
|
+
points.push(path[i + 1]);
|
|
5010
|
+
remaining -= lengths[i];
|
|
5011
|
+
continue;
|
|
5012
|
+
}
|
|
5013
|
+
const part = lengths[i] ? remaining / lengths[i] : 0;
|
|
5014
|
+
points.push({
|
|
5015
|
+
x: path[i].x + (path[i + 1].x - path[i].x) * part,
|
|
5016
|
+
y: path[i].y + (path[i + 1].y - path[i].y) * part
|
|
5017
|
+
});
|
|
5018
|
+
break;
|
|
5019
|
+
}
|
|
5020
|
+
if (points.length < 2) return {
|
|
5021
|
+
...stroke,
|
|
5022
|
+
opacity: 0
|
|
5023
|
+
};
|
|
5024
|
+
const { gradient, blur, ...rest } = stroke;
|
|
5025
|
+
return filled ? {
|
|
5026
|
+
...rest,
|
|
5027
|
+
shape: "pen",
|
|
5028
|
+
fill: false,
|
|
5029
|
+
width: Math.max(2, Math.min(3, stroke.width ?? 2)),
|
|
5030
|
+
opacity: .85,
|
|
5031
|
+
points
|
|
5032
|
+
} : {
|
|
5033
|
+
...rest,
|
|
5034
|
+
shape: "pen",
|
|
5035
|
+
fill: false,
|
|
5036
|
+
points,
|
|
5037
|
+
...blur ? { blur } : {}
|
|
5038
|
+
};
|
|
5039
|
+
}
|
|
5040
|
+
function strokeWeight(stroke, width = 1024, height = 1024) {
|
|
5041
|
+
if (stroke.fill && stroke.shape !== "pen") return 2.2;
|
|
5042
|
+
return .6 + Math.min(4, Math.sqrt(lengthOf(stroke, width, height)) / 8);
|
|
5043
|
+
}
|
|
5044
|
+
function planReplay(steps, duration, width = 1024, height = 1024) {
|
|
5045
|
+
const items = steps.map((step) => ({
|
|
5046
|
+
step,
|
|
5047
|
+
weight: step.type === "jump" ? 6 : step.added.reduce((sum, item) => sum + strokeWeight(item.stroke, width, height), 0) + 6
|
|
5048
|
+
}));
|
|
5049
|
+
const total = items.reduce((sum, item) => sum + item.weight, 0) || 1;
|
|
5050
|
+
let at = 0;
|
|
5051
|
+
return items.map(({ step, weight }) => {
|
|
5052
|
+
const span = duration * weight / total;
|
|
5053
|
+
const drawing = span - Math.min(span * .12, 500);
|
|
5054
|
+
const drawWeight = step.added.reduce((sum, item) => sum + strokeWeight(item.stroke, width, height), 0) || 1;
|
|
5055
|
+
let cursor = at;
|
|
5056
|
+
const strokes = step.added.map((item) => {
|
|
5057
|
+
const own = drawing * strokeWeight(item.stroke, width, height) / drawWeight;
|
|
5058
|
+
const entry = {
|
|
5059
|
+
...item,
|
|
5060
|
+
start: cursor,
|
|
5061
|
+
end: cursor + own
|
|
5062
|
+
};
|
|
5063
|
+
cursor += own;
|
|
5064
|
+
return entry;
|
|
5065
|
+
});
|
|
5066
|
+
const planned = {
|
|
5067
|
+
step,
|
|
5068
|
+
start: at,
|
|
5069
|
+
end: at + span,
|
|
5070
|
+
strokes
|
|
5071
|
+
};
|
|
5072
|
+
at += span;
|
|
5073
|
+
return planned;
|
|
5074
|
+
});
|
|
5075
|
+
}
|
|
5076
|
+
function replayFrame(plan, time) {
|
|
5077
|
+
if (!plan.length) return void 0;
|
|
5078
|
+
const last = plan.at(-1);
|
|
5079
|
+
if (time >= last.end) return { doc: last.step.after };
|
|
5080
|
+
const item = plan.find((entry) => time < entry.end) ?? last;
|
|
5081
|
+
if (item.step.type === "jump" || !item.strokes.length) return { doc: time < item.start + (item.end - item.start) / 2 ? item.step.before : item.step.after };
|
|
5082
|
+
const done = item.strokes.filter((entry) => time >= entry.end);
|
|
5083
|
+
const current = item.strokes.find((entry) => time >= entry.start && time < entry.end);
|
|
5084
|
+
const layers = item.step.after.layers.map((layer) => {
|
|
5085
|
+
const base = item.step.before.layers.find((old) => old.id === layer.id)?.strokes ?? [];
|
|
5086
|
+
const extra = [...done.filter((entry) => entry.layer === layer.id).map((entry) => entry.stroke)];
|
|
5087
|
+
if (current?.layer === layer.id) extra.push(partialStroke(current.stroke, (time - current.start) / (current.end - current.start)));
|
|
5088
|
+
return {
|
|
5089
|
+
...layer,
|
|
5090
|
+
strokes: extra.length ? [...base, ...extra] : base
|
|
5091
|
+
};
|
|
5092
|
+
});
|
|
5093
|
+
return {
|
|
5094
|
+
doc: {
|
|
5095
|
+
...item.step.after,
|
|
5096
|
+
layers
|
|
5097
|
+
},
|
|
5098
|
+
moving: current?.layer
|
|
5099
|
+
};
|
|
5100
|
+
}
|
|
5101
|
+
//#endregion
|
|
5102
|
+
//#region src/sketch-replay.jsx
|
|
5103
|
+
const SPEEDS = [
|
|
5104
|
+
[
|
|
5105
|
+
"fast",
|
|
5106
|
+
12e3,
|
|
5107
|
+
"sketchReplayFast"
|
|
5108
|
+
],
|
|
5109
|
+
[
|
|
5110
|
+
"normal",
|
|
5111
|
+
3e4,
|
|
5112
|
+
"sketchReplayNormal"
|
|
5113
|
+
],
|
|
5114
|
+
[
|
|
5115
|
+
"slow",
|
|
5116
|
+
6e4,
|
|
5117
|
+
"sketchReplaySlow"
|
|
5118
|
+
]
|
|
5119
|
+
];
|
|
5120
|
+
const VIDEO_TYPES = [
|
|
5121
|
+
"video/webm;codecs=vp9",
|
|
5122
|
+
"video/webm;codecs=vp8",
|
|
5123
|
+
"video/webm"
|
|
5124
|
+
];
|
|
5125
|
+
function SketchReplay({ states, current, images, name, onClose, t }) {
|
|
5126
|
+
const canvas = (0, react.useRef)(null);
|
|
5127
|
+
const cache = (0, react.useRef)(/* @__PURE__ */ new Map());
|
|
5128
|
+
const clock = (0, react.useRef)({
|
|
5129
|
+
time: 0,
|
|
5130
|
+
last: 0,
|
|
5131
|
+
playing: true,
|
|
5132
|
+
recorder: null
|
|
5133
|
+
});
|
|
5134
|
+
const [speed, setSpeed] = (0, react.useState)("normal");
|
|
5135
|
+
const [playing, setPlaying] = (0, react.useState)(true);
|
|
5136
|
+
const [recording, setRecording] = (0, react.useState)(false);
|
|
5137
|
+
const [progress, setProgress] = (0, react.useState)(0);
|
|
5138
|
+
const [note, setNote] = (0, react.useState)("");
|
|
5139
|
+
const [video, setVideo] = (0, react.useState)(null);
|
|
5140
|
+
const width = current.width ?? 1024, height = current.height ?? 1024;
|
|
5141
|
+
const duration = SPEEDS.find((item) => item[0] === speed)[1];
|
|
5142
|
+
const steps = (0, react.useMemo)(() => replaySteps([...states, current]), [states, current]);
|
|
5143
|
+
const plan = (0, react.useMemo)(() => planReplay(steps, duration, width, height), [
|
|
5144
|
+
steps,
|
|
5145
|
+
duration,
|
|
5146
|
+
width,
|
|
5147
|
+
height
|
|
5148
|
+
]);
|
|
5149
|
+
const total = plan.at(-1)?.end ?? 0;
|
|
5150
|
+
const paint = (time) => {
|
|
5151
|
+
const target = canvas.current;
|
|
5152
|
+
if (!target) return;
|
|
5153
|
+
const frame = replayFrame(plan, time);
|
|
5154
|
+
paintSketchLayers(target.getContext("2d"), frame?.doc ?? current, cache.current, width, height, frame?.moving, images);
|
|
5155
|
+
};
|
|
5156
|
+
(0, react.useEffect)(() => {
|
|
5157
|
+
clock.current.time = 0;
|
|
5158
|
+
clock.current.last = 0;
|
|
5159
|
+
cache.current.clear();
|
|
5160
|
+
let frame = 0;
|
|
5161
|
+
const tick = (now) => {
|
|
5162
|
+
const state = clock.current;
|
|
5163
|
+
if (state.playing) {
|
|
5164
|
+
state.time = Math.min(total, state.time + (state.last ? now - state.last : 0));
|
|
5165
|
+
if (state.time >= total) {
|
|
5166
|
+
state.playing = false;
|
|
5167
|
+
setPlaying(false);
|
|
5168
|
+
if (state.recorder) window.setTimeout(() => state.recorder?.stop(), 600);
|
|
5169
|
+
}
|
|
5170
|
+
}
|
|
5171
|
+
state.last = now;
|
|
5172
|
+
paint(state.time);
|
|
5173
|
+
setProgress(total ? state.time / total : 1);
|
|
5174
|
+
frame = requestAnimationFrame(tick);
|
|
5175
|
+
};
|
|
5176
|
+
frame = requestAnimationFrame(tick);
|
|
5177
|
+
return () => cancelAnimationFrame(frame);
|
|
5178
|
+
}, [plan]);
|
|
5179
|
+
(0, react.useEffect)(() => () => {
|
|
5180
|
+
if (video) URL.revokeObjectURL(video.url);
|
|
5181
|
+
}, [video]);
|
|
5182
|
+
(0, react.useEffect)(() => () => {
|
|
5183
|
+
if (clock.current.recorder?.state === "recording") {
|
|
5184
|
+
clock.current.recorder.onstop = null;
|
|
5185
|
+
clock.current.recorder.stop();
|
|
5186
|
+
}
|
|
5187
|
+
}, []);
|
|
5188
|
+
const toggle = () => {
|
|
5189
|
+
const state = clock.current;
|
|
5190
|
+
if (state.time >= total) {
|
|
5191
|
+
state.time = 0;
|
|
5192
|
+
cache.current.clear();
|
|
5193
|
+
}
|
|
5194
|
+
state.playing = !state.playing;
|
|
5195
|
+
setPlaying(state.playing);
|
|
5196
|
+
};
|
|
5197
|
+
const seek = (value) => {
|
|
5198
|
+
clock.current.time = value * total;
|
|
5199
|
+
clock.current.playing = false;
|
|
5200
|
+
setPlaying(false);
|
|
5201
|
+
cache.current.clear();
|
|
5202
|
+
};
|
|
5203
|
+
const record = () => {
|
|
5204
|
+
if (recording) {
|
|
5205
|
+
clock.current.recorder?.stop();
|
|
5206
|
+
return;
|
|
5207
|
+
}
|
|
5208
|
+
const type = VIDEO_TYPES.find((item) => typeof MediaRecorder !== "undefined" && MediaRecorder.isTypeSupported(item));
|
|
5209
|
+
if (!type || !canvas.current?.captureStream) {
|
|
5210
|
+
setNote(t("sketchReplayUnsupported"));
|
|
5211
|
+
return;
|
|
5212
|
+
}
|
|
5213
|
+
setNote("");
|
|
5214
|
+
const chunks = [];
|
|
5215
|
+
const recorder = new MediaRecorder(canvas.current.captureStream(30), {
|
|
5216
|
+
mimeType: type,
|
|
5217
|
+
videoBitsPerSecond: 8e6
|
|
5218
|
+
});
|
|
5219
|
+
recorder.ondataavailable = (event) => {
|
|
5220
|
+
if (event.data.size) chunks.push(event.data);
|
|
5221
|
+
};
|
|
5222
|
+
recorder.onstop = () => {
|
|
5223
|
+
clock.current.recorder = null;
|
|
5224
|
+
setRecording(false);
|
|
5225
|
+
setVideo({
|
|
5226
|
+
url: URL.createObjectURL(new Blob(chunks, { type: "video/webm" })),
|
|
5227
|
+
file: `${(name || "sketch").replace(/[\\/:*?"<>|\u0000-\u001f]/g, "-").slice(0, 80)}-${t("sketchReplayFileSuffix")}.webm`
|
|
5228
|
+
});
|
|
5229
|
+
};
|
|
5230
|
+
clock.current.time = 0;
|
|
5231
|
+
clock.current.playing = true;
|
|
5232
|
+
cache.current.clear();
|
|
5233
|
+
clock.current.recorder = recorder;
|
|
5234
|
+
setPlaying(true);
|
|
5235
|
+
setRecording(true);
|
|
5236
|
+
recorder.start(250);
|
|
5237
|
+
};
|
|
5238
|
+
const stop = () => {
|
|
5239
|
+
if (clock.current.recorder?.state === "recording") {
|
|
5240
|
+
clock.current.recorder.onstop = null;
|
|
5241
|
+
clock.current.recorder.stop();
|
|
5242
|
+
clock.current.recorder = null;
|
|
5243
|
+
setRecording(false);
|
|
5244
|
+
}
|
|
5245
|
+
onClose();
|
|
5246
|
+
};
|
|
5247
|
+
const clock0 = Math.round(progress * total / 1e3), clock1 = Math.round(total / 1e3);
|
|
5248
|
+
const mmss = (seconds) => `${Math.floor(seconds / 60)}:${String(seconds % 60).padStart(2, "0")}`;
|
|
5249
|
+
const icon = (path) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
|
|
5250
|
+
viewBox: "0 0 24 24",
|
|
5251
|
+
width: "18",
|
|
5252
|
+
height: "18",
|
|
5253
|
+
"aria-hidden": "true",
|
|
5254
|
+
fill: "currentColor",
|
|
5255
|
+
children: path
|
|
5256
|
+
});
|
|
5257
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
5258
|
+
className: "codexSketchReplay",
|
|
5259
|
+
role: "dialog",
|
|
5260
|
+
"aria-label": t("sketchReplayTitle"),
|
|
5261
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("header", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: t("sketchReplayTitle") }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
5262
|
+
type: "button",
|
|
5263
|
+
className: "codexSketchReplayClose",
|
|
5264
|
+
onClick: stop,
|
|
5265
|
+
"aria-label": t("sketchReplayClose"),
|
|
5266
|
+
children: [icon(/* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "M6.4 5 12 10.6 17.6 5 19 6.4 13.4 12 19 17.6 17.6 19 12 13.4 6.4 19 5 17.6 10.6 12 5 6.4z" })), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t("sketchReplayClose") })]
|
|
5267
|
+
})] }), video ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
5268
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
5269
|
+
className: "codexSketchReplayStage",
|
|
5270
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("video", {
|
|
5271
|
+
src: video.url,
|
|
5272
|
+
controls: true,
|
|
5273
|
+
autoPlay: true,
|
|
5274
|
+
loop: true
|
|
5275
|
+
})
|
|
5276
|
+
}),
|
|
5277
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
5278
|
+
className: "codexSketchReplayBar",
|
|
5279
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
|
|
5280
|
+
className: "codexSketchReplaySave",
|
|
5281
|
+
href: video.url,
|
|
5282
|
+
download: video.file,
|
|
5283
|
+
children: t("sketchReplaySave")
|
|
5284
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
5285
|
+
type: "button",
|
|
5286
|
+
onClick: () => setVideo(null),
|
|
5287
|
+
children: t("sketchReplayAgain")
|
|
5288
|
+
})]
|
|
5289
|
+
}),
|
|
5290
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", { children: t("sketchReplaySaveHint") })
|
|
5291
|
+
] }) : steps.length === 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: t("sketchReplayEmpty") }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
5292
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
5293
|
+
className: "codexSketchReplayStage",
|
|
5294
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("canvas", {
|
|
5295
|
+
ref: canvas,
|
|
5296
|
+
width,
|
|
5297
|
+
height,
|
|
5298
|
+
style: {
|
|
5299
|
+
aspectRatio: `${width} / ${height}`,
|
|
5300
|
+
width: `min(100cqw, calc(100cqh * ${width / height}))`
|
|
5301
|
+
}
|
|
5302
|
+
})
|
|
5303
|
+
}),
|
|
5304
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
5305
|
+
className: "codexSketchReplayBar",
|
|
5306
|
+
children: [
|
|
5307
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
5308
|
+
type: "button",
|
|
5309
|
+
className: "codexSketchReplayPlay",
|
|
5310
|
+
disabled: recording,
|
|
5311
|
+
onClick: toggle,
|
|
5312
|
+
"aria-label": playing ? t("sketchReplayPause") : t("sketchReplayPlay"),
|
|
5313
|
+
children: playing ? icon(/* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "M7 5h3.5v14H7zM13.5 5H17v14h-3.5z" })) : icon(/* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "M8 5.2v13.6L19 12z" }))
|
|
5314
|
+
}),
|
|
5315
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
5316
|
+
className: "codexSketchReplayTime",
|
|
5317
|
+
children: [
|
|
5318
|
+
mmss(clock0),
|
|
5319
|
+
" / ",
|
|
5320
|
+
mmss(clock1)
|
|
5321
|
+
]
|
|
5322
|
+
}),
|
|
5323
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
5324
|
+
type: "range",
|
|
5325
|
+
min: "0",
|
|
5326
|
+
max: "1",
|
|
5327
|
+
step: "0.001",
|
|
5328
|
+
value: progress,
|
|
5329
|
+
disabled: recording,
|
|
5330
|
+
"aria-label": t("sketchReplayTitle"),
|
|
5331
|
+
onChange: (event) => seek(Number(event.target.value))
|
|
5332
|
+
}),
|
|
5333
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
5334
|
+
className: "codexSketchSegment",
|
|
5335
|
+
role: "group",
|
|
5336
|
+
"aria-label": t("sketchReplaySpeed"),
|
|
5337
|
+
children: SPEEDS.map(([value, , label]) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
5338
|
+
type: "button",
|
|
5339
|
+
"aria-pressed": speed === value,
|
|
5340
|
+
disabled: recording,
|
|
5341
|
+
onClick: () => setSpeed(value),
|
|
5342
|
+
children: t(label)
|
|
5343
|
+
}, value))
|
|
5344
|
+
}),
|
|
5345
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
5346
|
+
type: "button",
|
|
5347
|
+
className: "codexSketchReplayRecord",
|
|
5348
|
+
"data-recording": recording || void 0,
|
|
5349
|
+
onClick: record,
|
|
5350
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", { "aria-hidden": "true" }), recording ? t("sketchReplayStopRecording") : t("sketchReplayRecord")]
|
|
5351
|
+
})
|
|
5352
|
+
]
|
|
5353
|
+
}),
|
|
5354
|
+
note ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", {
|
|
5355
|
+
role: "alert",
|
|
5356
|
+
children: note
|
|
5357
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", { children: t("sketchReplayHint") })
|
|
5358
|
+
] })]
|
|
5359
|
+
});
|
|
5360
|
+
}
|
|
5361
|
+
//#endregion
|
|
4179
5362
|
//#region src/sketch-size-control.jsx
|
|
4180
5363
|
function SketchSizeControl({ value, onChange, onStart, onEnd, label, disabled, min = 2, max = 128, mode, modes, onModeChange, suffix = "" }) {
|
|
4181
5364
|
const active = (0, react.useRef)(false);
|
|
@@ -4233,7 +5416,7 @@ window.__ModuleLoader__.load({
|
|
|
4233
5416
|
}
|
|
4234
5417
|
//#endregion
|
|
4235
5418
|
//#region src/sketch-agent-run.js
|
|
4236
|
-
function createSketchAgentRun({ execute, open, changed, busy = () => false, idleMs =
|
|
5419
|
+
function createSketchAgentRun({ execute, open, changed, busy = () => false, idleMs = 9e5 }) {
|
|
4237
5420
|
let state = "idle", generation = 0, runNumber = 0, pending = false, runId, timer, completed;
|
|
4238
5421
|
const update = (next) => {
|
|
4239
5422
|
state = next;
|
|
@@ -4307,7 +5490,7 @@ window.__ModuleLoader__.load({
|
|
|
4307
5490
|
update("finished");
|
|
4308
5491
|
return completed.value;
|
|
4309
5492
|
} catch (error) {
|
|
4310
|
-
if (version === generation && error.code === "SKETCH_INVALID_BATCH") throw error;
|
|
5493
|
+
if (version === generation && (error.code === "SKETCH_INVALID_BATCH" || error.code === "SKETCH_STALE")) throw error;
|
|
4311
5494
|
if (version === generation) {
|
|
4312
5495
|
update("failed");
|
|
4313
5496
|
throw new Error(`${error.message} Call inspect to obtain the current runId and revision before retrying.`, { cause: error });
|
|
@@ -4420,11 +5603,260 @@ window.__ModuleLoader__.load({
|
|
|
4420
5603
|
};
|
|
4421
5604
|
}
|
|
4422
5605
|
//#endregion
|
|
5606
|
+
//#region src/sketch-measure.js
|
|
5607
|
+
const hex = (r, g, b) => "#" + [
|
|
5608
|
+
r,
|
|
5609
|
+
g,
|
|
5610
|
+
b
|
|
5611
|
+
].map((value) => Math.max(0, Math.min(255, Math.round(value))).toString(16).padStart(2, "0")).join("");
|
|
5612
|
+
function average(picture, x0, y0, x1, y1) {
|
|
5613
|
+
const { data, width, height } = picture;
|
|
5614
|
+
const left = Math.max(0, Math.floor(x0)), top = Math.max(0, Math.floor(y0)), right = Math.min(width, Math.max(left + 1, Math.ceil(x1))), bottom = Math.min(height, Math.max(top + 1, Math.ceil(y1)));
|
|
5615
|
+
let r = 0, g = 0, b = 0, n = 0;
|
|
5616
|
+
for (let y = top; y < bottom; y++) for (let x = left; x < right; x++) {
|
|
5617
|
+
const at = (y * width + x) * 4;
|
|
5618
|
+
r += data[at];
|
|
5619
|
+
g += data[at + 1];
|
|
5620
|
+
b += data[at + 2];
|
|
5621
|
+
n++;
|
|
5622
|
+
}
|
|
5623
|
+
return n ? [
|
|
5624
|
+
r / n,
|
|
5625
|
+
g / n,
|
|
5626
|
+
b / n
|
|
5627
|
+
] : [
|
|
5628
|
+
255,
|
|
5629
|
+
255,
|
|
5630
|
+
255
|
|
5631
|
+
];
|
|
5632
|
+
}
|
|
5633
|
+
function measureDifference(reference, drawing, { columns = 6, rows = 8, worst = 10 } = {}) {
|
|
5634
|
+
const { width, height } = reference;
|
|
5635
|
+
const cells = [];
|
|
5636
|
+
let total = 0;
|
|
5637
|
+
for (let row = 0; row < rows; row++) for (let column = 0; column < columns; column++) {
|
|
5638
|
+
const x0 = column * width / columns, x1 = (column + 1) * width / columns, y0 = row * height / rows, y1 = (row + 1) * height / rows;
|
|
5639
|
+
let sum = 0, n = 0;
|
|
5640
|
+
const step = Math.max(1, Math.floor(Math.min(x1 - x0, y1 - y0) / 24));
|
|
5641
|
+
for (let y = Math.floor(y0); y < y1; y += step) for (let x = Math.floor(x0); x < x1; x += step) {
|
|
5642
|
+
const at = (y * width + x) * 4;
|
|
5643
|
+
sum += Math.abs(reference.data[at] - drawing.data[at]) + Math.abs(reference.data[at + 1] - drawing.data[at + 1]) + Math.abs(reference.data[at + 2] - drawing.data[at + 2]);
|
|
5644
|
+
n++;
|
|
5645
|
+
}
|
|
5646
|
+
const error = n ? sum / n / 3 / 255 * 100 : 0;
|
|
5647
|
+
total += error;
|
|
5648
|
+
const ref = average(reference, x0, y0, x1, y1), art = average(drawing, x0, y0, x1, y1);
|
|
5649
|
+
cells.push({
|
|
5650
|
+
column,
|
|
5651
|
+
row,
|
|
5652
|
+
x: x0 / width,
|
|
5653
|
+
y: y0 / height,
|
|
5654
|
+
w: (x1 - x0) / width,
|
|
5655
|
+
h: (y1 - y0) / height,
|
|
5656
|
+
error: Math.round(error * 10) / 10,
|
|
5657
|
+
reference: hex(...ref),
|
|
5658
|
+
drawing: hex(...art),
|
|
5659
|
+
tone: Math.round((art[0] + art[1] + art[2] - ref[0] - ref[1] - ref[2]) / 3)
|
|
5660
|
+
});
|
|
5661
|
+
}
|
|
5662
|
+
cells.sort((a, b) => b.error - a.error);
|
|
5663
|
+
return {
|
|
5664
|
+
error: Math.round(total / cells.length * 10) / 10,
|
|
5665
|
+
worst: cells.slice(0, worst)
|
|
5666
|
+
};
|
|
5667
|
+
}
|
|
5668
|
+
function sampleColors(reference, drawing, points, radius = .004) {
|
|
5669
|
+
return points.map((point) => {
|
|
5670
|
+
const { width, height } = reference;
|
|
5671
|
+
const box = [
|
|
5672
|
+
(point.x - radius) * width,
|
|
5673
|
+
(point.y - radius) * height,
|
|
5674
|
+
(point.x + radius) * width,
|
|
5675
|
+
(point.y + radius) * height
|
|
5676
|
+
];
|
|
5677
|
+
return {
|
|
5678
|
+
x: point.x,
|
|
5679
|
+
y: point.y,
|
|
5680
|
+
reference: hex(...average(reference, ...box)),
|
|
5681
|
+
drawing: hex(...average(drawing, ...box))
|
|
5682
|
+
};
|
|
5683
|
+
});
|
|
5684
|
+
}
|
|
5685
|
+
function dominantColors(picture, count) {
|
|
5686
|
+
const { data, width, height } = picture;
|
|
5687
|
+
const pixels = width * height, stride = Math.max(1, Math.floor(pixels / 2e4)), sample = [];
|
|
5688
|
+
for (let i = 0; i < pixels; i += stride) sample.push([
|
|
5689
|
+
data[i * 4],
|
|
5690
|
+
data[i * 4 + 1],
|
|
5691
|
+
data[i * 4 + 2]
|
|
5692
|
+
]);
|
|
5693
|
+
const total = Math.min(count, sample.length);
|
|
5694
|
+
if (!total) return [];
|
|
5695
|
+
const mean = sample.reduce((sum, color) => [
|
|
5696
|
+
sum[0] + color[0],
|
|
5697
|
+
sum[1] + color[1],
|
|
5698
|
+
sum[2] + color[2]
|
|
5699
|
+
], [
|
|
5700
|
+
0,
|
|
5701
|
+
0,
|
|
5702
|
+
0
|
|
5703
|
+
]).map((value) => value / sample.length);
|
|
5704
|
+
const centers = [mean];
|
|
5705
|
+
const nearest = sample.map((color) => (color[0] - mean[0]) ** 2 + (color[1] - mean[1]) ** 2 + (color[2] - mean[2]) ** 2);
|
|
5706
|
+
while (centers.length < total) {
|
|
5707
|
+
let at = 0;
|
|
5708
|
+
for (let i = 1; i < sample.length; i++) if (nearest[i] > nearest[at]) at = i;
|
|
5709
|
+
if (nearest[at] === 0) break;
|
|
5710
|
+
const center = sample[at].slice();
|
|
5711
|
+
centers.push(center);
|
|
5712
|
+
for (let i = 0; i < sample.length; i++) nearest[i] = Math.min(nearest[i], (sample[i][0] - center[0]) ** 2 + (sample[i][1] - center[1]) ** 2 + (sample[i][2] - center[2]) ** 2);
|
|
5713
|
+
}
|
|
5714
|
+
let sums = centers.map(() => [
|
|
5715
|
+
0,
|
|
5716
|
+
0,
|
|
5717
|
+
0,
|
|
5718
|
+
0
|
|
5719
|
+
]);
|
|
5720
|
+
for (let round = 0; round < 8; round++) {
|
|
5721
|
+
sums = centers.map(() => [
|
|
5722
|
+
0,
|
|
5723
|
+
0,
|
|
5724
|
+
0,
|
|
5725
|
+
0
|
|
5726
|
+
]);
|
|
5727
|
+
for (const color of sample) {
|
|
5728
|
+
let best = 0, bestDistance = Infinity;
|
|
5729
|
+
for (let c = 0; c < centers.length; c++) {
|
|
5730
|
+
const d = (color[0] - centers[c][0]) ** 2 + (color[1] - centers[c][1]) ** 2 + (color[2] - centers[c][2]) ** 2;
|
|
5731
|
+
if (d < bestDistance) {
|
|
5732
|
+
bestDistance = d;
|
|
5733
|
+
best = c;
|
|
5734
|
+
}
|
|
5735
|
+
}
|
|
5736
|
+
const sum = sums[best];
|
|
5737
|
+
sum[0] += color[0];
|
|
5738
|
+
sum[1] += color[1];
|
|
5739
|
+
sum[2] += color[2];
|
|
5740
|
+
sum[3]++;
|
|
5741
|
+
}
|
|
5742
|
+
sums.forEach((sum, c) => {
|
|
5743
|
+
if (sum[3]) centers[c] = [
|
|
5744
|
+
sum[0] / sum[3],
|
|
5745
|
+
sum[1] / sum[3],
|
|
5746
|
+
sum[2] / sum[3]
|
|
5747
|
+
];
|
|
5748
|
+
});
|
|
5749
|
+
}
|
|
5750
|
+
return centers.map((center, c) => ({
|
|
5751
|
+
color: hex(...center),
|
|
5752
|
+
share: Math.round(sums[c][3] / sample.length * 1e3) / 10
|
|
5753
|
+
})).filter((item) => item.share > 0).sort((a, b) => b.share - a.share);
|
|
5754
|
+
}
|
|
5755
|
+
const distance = (a, b) => Math.hypot(a[0] - b[0], a[1] - b[1], a[2] - b[2]);
|
|
5756
|
+
function scanLine(picture, line, { tolerance = 36, maxRuns = 40 } = {}) {
|
|
5757
|
+
const { data, width, height } = picture;
|
|
5758
|
+
const length = Math.max(2, Math.round(Math.hypot((line.x2 - line.x1) * width, (line.y2 - line.y1) * height)));
|
|
5759
|
+
const runs = [];
|
|
5760
|
+
let current;
|
|
5761
|
+
for (let i = 0; i <= length; i++) {
|
|
5762
|
+
const t = i / length, x = Math.min(width - 1, Math.max(0, Math.round((line.x1 + (line.x2 - line.x1) * t) * (width - 1))));
|
|
5763
|
+
const at = (Math.min(height - 1, Math.max(0, Math.round((line.y1 + (line.y2 - line.y1) * t) * (height - 1)))) * width + x) * 4, color = [
|
|
5764
|
+
data[at],
|
|
5765
|
+
data[at + 1],
|
|
5766
|
+
data[at + 2]
|
|
5767
|
+
];
|
|
5768
|
+
if (current && distance(color, current.mean) <= tolerance) {
|
|
5769
|
+
current.to = t;
|
|
5770
|
+
current.n++;
|
|
5771
|
+
for (let k = 0; k < 3; k++) current.sum[k] += color[k];
|
|
5772
|
+
current.mean = current.sum.map((value) => value / current.n);
|
|
5773
|
+
} else {
|
|
5774
|
+
current = {
|
|
5775
|
+
from: t,
|
|
5776
|
+
to: t,
|
|
5777
|
+
n: 1,
|
|
5778
|
+
sum: [...color],
|
|
5779
|
+
mean: color
|
|
5780
|
+
};
|
|
5781
|
+
runs.push(current);
|
|
5782
|
+
}
|
|
5783
|
+
}
|
|
5784
|
+
const point = (t) => ({
|
|
5785
|
+
x: Math.round((line.x1 + (line.x2 - line.x1) * t) * 1e3) / 1e3,
|
|
5786
|
+
y: Math.round((line.y1 + (line.y2 - line.y1) * t) * 1e3) / 1e3
|
|
5787
|
+
});
|
|
5788
|
+
const merged = [];
|
|
5789
|
+
for (const run of runs) {
|
|
5790
|
+
if (merged.length && run.n < 3) {
|
|
5791
|
+
merged.at(-1).to = run.to;
|
|
5792
|
+
continue;
|
|
5793
|
+
}
|
|
5794
|
+
merged.push({ ...run });
|
|
5795
|
+
}
|
|
5796
|
+
return merged.slice(0, maxRuns).map((run) => ({
|
|
5797
|
+
from: point(run.from),
|
|
5798
|
+
to: point(run.to),
|
|
5799
|
+
color: hex(...run.mean)
|
|
5800
|
+
}));
|
|
5801
|
+
}
|
|
5802
|
+
function colorRegions(picture, count) {
|
|
5803
|
+
const colors = dominantColors(picture, count);
|
|
5804
|
+
if (!colors.length) return [];
|
|
5805
|
+
const { data, width, height } = picture;
|
|
5806
|
+
const centers = colors.map((item) => [
|
|
5807
|
+
1,
|
|
5808
|
+
3,
|
|
5809
|
+
5
|
|
5810
|
+
].map((at) => Number.parseInt(item.color.slice(at, at + 2), 16)));
|
|
5811
|
+
const xs = colors.map(() => []), ys = colors.map(() => []);
|
|
5812
|
+
const stride = Math.max(1, Math.floor(Math.sqrt(width * height / 4e4)));
|
|
5813
|
+
for (let y = 0; y < height; y += stride) for (let x = 0; x < width; x += stride) {
|
|
5814
|
+
const at = (y * width + x) * 4, pixel = [
|
|
5815
|
+
data[at],
|
|
5816
|
+
data[at + 1],
|
|
5817
|
+
data[at + 2]
|
|
5818
|
+
];
|
|
5819
|
+
let best = 0, bestDistance = Infinity;
|
|
5820
|
+
for (let c = 0; c < centers.length; c++) {
|
|
5821
|
+
const d = distance(pixel, centers[c]);
|
|
5822
|
+
if (d < bestDistance) {
|
|
5823
|
+
bestDistance = d;
|
|
5824
|
+
best = c;
|
|
5825
|
+
}
|
|
5826
|
+
}
|
|
5827
|
+
xs[best].push(x / width);
|
|
5828
|
+
ys[best].push(y / height);
|
|
5829
|
+
}
|
|
5830
|
+
const cut = (values, share) => {
|
|
5831
|
+
values.sort((a, b) => a - b);
|
|
5832
|
+
return values[Math.min(values.length - 1, Math.floor(values.length * share))];
|
|
5833
|
+
};
|
|
5834
|
+
const round = (value) => Math.round(value * 1e3) / 1e3;
|
|
5835
|
+
return colors.map((item, c) => {
|
|
5836
|
+
if (!xs[c].length) return { ...item };
|
|
5837
|
+
const x0 = cut(xs[c], .02), x1 = cut(xs[c], .98), y0 = cut(ys[c], .02), y1 = cut(ys[c], .98);
|
|
5838
|
+
const cx = xs[c].reduce((sum, value) => sum + value, 0) / xs[c].length, cy = ys[c].reduce((sum, value) => sum + value, 0) / ys[c].length;
|
|
5839
|
+
return {
|
|
5840
|
+
...item,
|
|
5841
|
+
center: {
|
|
5842
|
+
x: round(cx),
|
|
5843
|
+
y: round(cy)
|
|
5844
|
+
},
|
|
5845
|
+
box: {
|
|
5846
|
+
x: round(x0),
|
|
5847
|
+
y: round(y0),
|
|
5848
|
+
width: round(x1 - x0),
|
|
5849
|
+
height: round(y1 - y0)
|
|
5850
|
+
}
|
|
5851
|
+
};
|
|
5852
|
+
});
|
|
5853
|
+
}
|
|
5854
|
+
//#endregion
|
|
4423
5855
|
//#region src/sketch-studio.jsx
|
|
4424
5856
|
function SketchStudio({ open, agentEnabled, onOpen, onClose, attachSketch, enabled, t, incoming, sessionId, rpc, sessionState }) {
|
|
4425
5857
|
const localSession = (0, react.useRef)(null);
|
|
4426
5858
|
localSession.current ??= sessionState ?? createSketchSessionState();
|
|
4427
|
-
const { doc, undo, redo, images, saved, dirty, documentId, documentRevision, agentAdapter, agentSession, agentRun } = localSession.current;
|
|
5859
|
+
const { doc, undo, redo, images, timeline, saved, dirty, documentId, documentRevision, agentAdapter, agentSession, agentRun } = localSession.current;
|
|
4428
5860
|
const dialog = (0, react.useRef)(null), canvas = (0, react.useRef)(null), cache = (0, react.useRef)(/* @__PURE__ */ new Map());
|
|
4429
5861
|
const active = (0, react.useRef)(null), frame = (0, react.useRef)(null), updateUi = (0, react.useRef)(false);
|
|
4430
5862
|
const [agentState, setAgentState] = (0, react.useState)(agentRun.current?.state ?? "idle");
|
|
@@ -4480,6 +5912,7 @@ window.__ModuleLoader__.load({
|
|
|
4480
5912
|
const [fillShape, setFillShape] = (0, react.useState)(false);
|
|
4481
5913
|
const [hydrated, setHydrated] = (0, react.useState)(false), [recovered, setRecovered] = (0, react.useState)(false);
|
|
4482
5914
|
const [restoreAttempt, retryRestore] = (0, react.useState)(0);
|
|
5915
|
+
const [replayOpen, setReplayOpen] = (0, react.useState)(false);
|
|
4483
5916
|
const [layersOpen, setLayersOpen] = (0, react.useState)(false), [busy, setBusy] = (0, react.useState)(true), [error, setError] = (0, react.useState)("");
|
|
4484
5917
|
const cursorRing = (0, react.useRef)(null);
|
|
4485
5918
|
const cursor = useSketchCursor(canvas, cursorRing, width, tool === "pen" ? brush : "pen", navigation.view.scale, !open || navigation.space || busy || agentLocked || tool === "select" || tool === "text");
|
|
@@ -4508,6 +5941,7 @@ window.__ModuleLoader__.load({
|
|
|
4508
5941
|
const checkpoint = () => {
|
|
4509
5942
|
documentRevision.current++;
|
|
4510
5943
|
dirty.current = true;
|
|
5944
|
+
recordReplayState(timeline.current, doc.current);
|
|
4511
5945
|
undo.current.push(doc.current);
|
|
4512
5946
|
if (undo.current.length > 30) undo.current.shift();
|
|
4513
5947
|
redo.current = [];
|
|
@@ -4729,6 +6163,7 @@ window.__ModuleLoader__.load({
|
|
|
4729
6163
|
id: layer.id,
|
|
4730
6164
|
name: layer.name,
|
|
4731
6165
|
visible: layer.visible,
|
|
6166
|
+
...layer.blend ? { blend: layer.blend } : {},
|
|
4732
6167
|
strokes: layer.strokes.length,
|
|
4733
6168
|
image: Boolean(layer.image)
|
|
4734
6169
|
})),
|
|
@@ -4764,6 +6199,88 @@ window.__ModuleLoader__.load({
|
|
|
4764
6199
|
})
|
|
4765
6200
|
});
|
|
4766
6201
|
},
|
|
6202
|
+
pixels: ({ source, box = {
|
|
6203
|
+
x: 0,
|
|
6204
|
+
y: 0,
|
|
6205
|
+
width: 1,
|
|
6206
|
+
height: 1
|
|
6207
|
+
}, maxSide = 768 }) => {
|
|
6208
|
+
const layer = doc.current.layers.find((item) => source === void 0 ? item.image : item.id === source);
|
|
6209
|
+
const picture = layer?.image && images.current.get(layer.image.src);
|
|
6210
|
+
if (!picture) throw Error("There is no reference picture on the board; add one with the reference action first");
|
|
6211
|
+
const w = doc.current.width ?? 1024, h = doc.current.height ?? 1024;
|
|
6212
|
+
const scale = Math.min(1, maxSide / Math.max(box.width * w, box.height * h));
|
|
6213
|
+
const target = Object.assign(document.createElement("canvas"), {
|
|
6214
|
+
width: Math.max(1, Math.round(box.width * w * scale)),
|
|
6215
|
+
height: Math.max(1, Math.round(box.height * h * scale))
|
|
6216
|
+
});
|
|
6217
|
+
const context = target.getContext("2d", { willReadFrequently: true });
|
|
6218
|
+
context.fillStyle = "#ffffff";
|
|
6219
|
+
context.fillRect(0, 0, target.width, target.height);
|
|
6220
|
+
const at = layer.image;
|
|
6221
|
+
context.drawImage(picture, (at.x - box.x) * w * scale, (at.y - box.y) * h * scale, at.width * w * scale, at.height * h * scale);
|
|
6222
|
+
return context.getImageData(0, 0, target.width, target.height);
|
|
6223
|
+
},
|
|
6224
|
+
measure: async ({ columns, rows, cells = false, points, palette = 0, regions = 0, scan, box = {
|
|
6225
|
+
x: 0,
|
|
6226
|
+
y: 0,
|
|
6227
|
+
width: 1,
|
|
6228
|
+
height: 1
|
|
6229
|
+
} }) => {
|
|
6230
|
+
const reference = agentAdapter.current.pixels({
|
|
6231
|
+
box,
|
|
6232
|
+
maxSide: 480
|
|
6233
|
+
});
|
|
6234
|
+
const w = doc.current.width ?? 1024, h = doc.current.height ?? 1024;
|
|
6235
|
+
const scale = reference.width / (box.width * w);
|
|
6236
|
+
const whole = Object.assign(document.createElement("canvas"), {
|
|
6237
|
+
width: Math.max(1, Math.round(w * scale)),
|
|
6238
|
+
height: Math.max(1, Math.round(h * scale))
|
|
6239
|
+
});
|
|
6240
|
+
const drawn = {
|
|
6241
|
+
...doc.current,
|
|
6242
|
+
layers: doc.current.layers.map((layer) => layer.image ? {
|
|
6243
|
+
...layer,
|
|
6244
|
+
visible: false
|
|
6245
|
+
} : layer)
|
|
6246
|
+
};
|
|
6247
|
+
paintSketchLayers(whole.getContext("2d"), drawn, /* @__PURE__ */ new Map(), whole.width, whole.height, void 0, images.current);
|
|
6248
|
+
const target = Object.assign(document.createElement("canvas"), {
|
|
6249
|
+
width: reference.width,
|
|
6250
|
+
height: reference.height
|
|
6251
|
+
});
|
|
6252
|
+
const context = target.getContext("2d", { willReadFrequently: true });
|
|
6253
|
+
context.drawImage(whole, Math.round(box.x * whole.width), Math.round(box.y * whole.height), target.width, target.height, 0, 0, target.width, target.height);
|
|
6254
|
+
const drawing = context.getImageData(0, 0, target.width, target.height);
|
|
6255
|
+
return {
|
|
6256
|
+
...measureDifference(reference, drawing, {
|
|
6257
|
+
columns,
|
|
6258
|
+
rows,
|
|
6259
|
+
...cells ? { worst: columns * rows } : {}
|
|
6260
|
+
}),
|
|
6261
|
+
...points.length ? { points: sampleColors(reference, drawing, points) } : {},
|
|
6262
|
+
...palette ? { palette: dominantColors(reference, palette) } : {},
|
|
6263
|
+
...regions ? { regions: colorRegions(reference, regions) } : {},
|
|
6264
|
+
...scan ? { scan: {
|
|
6265
|
+
reference: scanLine(reference, scan),
|
|
6266
|
+
drawing: scanLine(drawing, scan)
|
|
6267
|
+
} } : {}
|
|
6268
|
+
};
|
|
6269
|
+
},
|
|
6270
|
+
undo: (steps = 1) => {
|
|
6271
|
+
let taken = 0;
|
|
6272
|
+
while (taken < steps && undo.current.length) {
|
|
6273
|
+
redo.current.push(doc.current);
|
|
6274
|
+
doc.current = undo.current.pop();
|
|
6275
|
+
taken++;
|
|
6276
|
+
}
|
|
6277
|
+
if (taken) {
|
|
6278
|
+
documentRevision.current++;
|
|
6279
|
+
dirty.current = true;
|
|
6280
|
+
schedule();
|
|
6281
|
+
}
|
|
6282
|
+
return taken;
|
|
6283
|
+
},
|
|
4767
6284
|
addReference: async (dataUrl, name) => {
|
|
4768
6285
|
const blob = await (await fetch(dataUrl)).blob();
|
|
4769
6286
|
await importImage(new File([blob], name, { type: blob.type }), { visible: false });
|
|
@@ -4931,7 +6448,14 @@ window.__ModuleLoader__.load({
|
|
|
4931
6448
|
hasContent: doc.current.layers.some((l) => l.visible && (l.image || l.strokes.length)),
|
|
4932
6449
|
disabled: agentLocked || busy,
|
|
4933
6450
|
t,
|
|
4934
|
-
runOperation: runFile
|
|
6451
|
+
runOperation: runFile,
|
|
6452
|
+
extra: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
6453
|
+
type: "button",
|
|
6454
|
+
disabled: agentLocked || busy || !timeline.current.length,
|
|
6455
|
+
title: t("sketchReplayTitle"),
|
|
6456
|
+
onClick: () => setReplayOpen(true),
|
|
6457
|
+
children: t("sketchReplay")
|
|
6458
|
+
})
|
|
4935
6459
|
}),
|
|
4936
6460
|
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
4937
6461
|
className: "codexSketchHeading",
|
|
@@ -5315,6 +6839,14 @@ window.__ModuleLoader__.load({
|
|
|
5315
6839
|
change,
|
|
5316
6840
|
t
|
|
5317
6841
|
}) : null,
|
|
6842
|
+
replayOpen && dialog.current ? (0, react_dom.createPortal)(/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SketchReplay, {
|
|
6843
|
+
states: timeline.current,
|
|
6844
|
+
current: doc.current,
|
|
6845
|
+
images: images.current,
|
|
6846
|
+
name: saved.current?.name,
|
|
6847
|
+
onClose: () => setReplayOpen(false),
|
|
6848
|
+
t
|
|
6849
|
+
}), dialog.current) : null,
|
|
5318
6850
|
layersOpen ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SketchLayerPanel, {
|
|
5319
6851
|
document: doc.current,
|
|
5320
6852
|
disabled: agentLocked || busy,
|
|
@@ -5385,6 +6917,8 @@ window.__ModuleLoader__.load({
|
|
|
5385
6917
|
.codexSketchDialog *{box-sizing:border-box}
|
|
5386
6918
|
.codexSketchDialog button{font:inherit;color:inherit;border:0;background:transparent;cursor:pointer;display:inline-flex;align-items:center;justify-content:center;gap:6px;flex-shrink:0}
|
|
5387
6919
|
.codexSketchDialog button:disabled{opacity:.35;cursor:default}
|
|
6920
|
+
.codexSketchDialog .codexSketchConfirm:disabled{background:color-mix(in srgb,var(--sketch-fg) 12%,transparent);color:var(--sketch-muted);opacity:1}
|
|
6921
|
+
.codexSketchDialog .codexSketchSwatch::before{box-shadow:0 0 0 1px color-mix(in srgb,var(--sketch-fg) 28%,transparent)}
|
|
5388
6922
|
.codexSketchDialog button:focus-visible,.codexSketchCustom:focus-within,.codexSketchDialog input:focus-visible{outline:2px solid #0a84ff;outline-offset:3px}
|
|
5389
6923
|
.codexSketchTop{display:flex;align-items:center;justify-content:space-between;gap:8px}
|
|
5390
6924
|
.codexSketchHeading{display:flex;align-items:center;gap:8px;flex:1}.codexSketchHeading strong{font-size:16px;font-weight:600}.codexSketchHeading>span{font-size:10px;color:var(--sketch-muted);border:1px solid var(--sketch-line);border-radius:6px;padding:1px 5px}
|
|
@@ -5433,6 +6967,22 @@ window.__ModuleLoader__.load({
|
|
|
5433
6967
|
.codexSketchViewControls{display:flex;gap:2px;align-items:center}.codexSketchViewControls button{min-height:32px;padding:0 7px;border-radius:8px}.codexSketchKeyPanel{position:absolute;overflow:auto;overscroll-behavior:contain;padding:12px;border:1px solid var(--sketch-line);border-radius:14px;background:var(--sketch-bg);z-index:5;box-shadow:0 8px 30px #0003;scrollbar-width:thin}.codexSketchKeyPanel header{display:flex;align-items:center;justify-content:space-between;margin-bottom:8px}.codexSketchKeyPanel header button{width:28px;height:28px;border-radius:8px;font-size:20px}.codexSketchKeyPanel label{display:flex;align-items:center;justify-content:space-between;min-height:32px;gap:8px}.codexSketchKeysEnabled{padding-bottom:8px;border-bottom:1px solid var(--sketch-line)}.codexSketchKeysEnabled input{margin:0;accent-color:#0a84ff}.codexSketchKeyGrid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:4px 16px;margin:10px 0}.codexSketchKeyPanel input:not([type=checkbox]){width:52px;min-width:0;border:1px solid var(--sketch-line);border-radius:6px;color:inherit;background:color-mix(in srgb,var(--sketch-fg) 4%,transparent);padding:4px;text-align:center;font:inherit}.codexSketchKeyPanel p,.codexSketchKeyPanel small{display:block;color:var(--sketch-muted);font-size:11px;line-height:1.5;margin:0}.codexSketchKeyPanel small{border-top:1px solid var(--sketch-line);padding-top:8px}@media(max-width:380px){.codexSketchKeyGrid{grid-template-columns:1fr}}.codexSketchControls{position:static}
|
|
5434
6968
|
|
|
5435
6969
|
.codexSketchCursor{position:fixed;left:0;top:0;z-index:100;pointer-events:none;border:1px solid #222;border-radius:50%;corner-shape:round;box-shadow:0 0 0 1px #fff;box-sizing:border-box}.codexSketchCursor[hidden]{display:none}
|
|
6970
|
+
|
|
6971
|
+
.codexSketchFiles{display:flex;gap:6px;align-items:center}.codexSketchFiles>button:disabled{opacity:.45}
|
|
6972
|
+
.codexSketchReplay{position:absolute;inset:0;z-index:20;display:flex;flex-direction:column;align-items:center;gap:12px;padding:14px 18px 16px;background:var(--sketch-bg);border-radius:inherit;overflow:hidden}
|
|
6973
|
+
.codexSketchReplay>header{display:flex;width:100%;align-items:center;justify-content:space-between;font-size:15px}
|
|
6974
|
+
.codexSketchDialog .codexSketchReplayClose{min-height:36px;padding:0 14px 0 10px;border-radius:18px;background:color-mix(in srgb,var(--sketch-fg) 7%,transparent);font-size:13px}
|
|
6975
|
+
.codexSketchReplayStage{flex:1;min-height:0;width:100%;display:flex;align-items:center;justify-content:center;container-type:size}
|
|
6976
|
+
.codexSketchReplayStage canvas,.codexSketchReplayStage video{max-width:100%;max-height:100%;border-radius:10px;background:#fff;box-shadow:0 0 0 1px var(--sketch-line),0 10px 36px #0002}
|
|
6977
|
+
.codexSketchReplayBar{display:flex;flex-wrap:wrap;width:100%;max-width:820px;align-items:center;justify-content:center;gap:10px;padding:8px 12px;border-radius:26px;background:color-mix(in srgb,var(--sketch-fg) 5%,transparent)}
|
|
6978
|
+
.codexSketchReplayBar input[type=range]{flex:1;min-width:140px;height:22px;accent-color:#0a84ff}
|
|
6979
|
+
.codexSketchDialog .codexSketchReplayBar>button{min-height:36px;padding:0 14px;border-radius:18px;background:color-mix(in srgb,var(--sketch-fg) 8%,transparent);font-size:13px}
|
|
6980
|
+
.codexSketchDialog .codexSketchReplayBar .codexSketchReplayPlay{width:40px;height:40px;min-height:40px;padding:0;border-radius:50%;background:#0a84ff;color:#fff}
|
|
6981
|
+
.codexSketchReplayTime{min-width:78px;font-variant-numeric:tabular-nums;color:var(--sketch-muted);font-size:12px}
|
|
6982
|
+
.codexSketchReplayRecord i{width:10px;height:10px;border-radius:50%;background:#ff3b30}
|
|
6983
|
+
.codexSketchDialog .codexSketchReplayRecord[data-recording]{background:#ff3b30;color:#fff}.codexSketchReplayRecord[data-recording] i{background:#fff;border-radius:2px}
|
|
6984
|
+
.codexSketchReplay small{color:var(--sketch-muted);text-align:center}
|
|
6985
|
+
.codexSketchReplaySave{display:inline-flex;align-items:center;min-height:36px;padding:0 18px;border-radius:18px;background:#0a84ff;color:#fff;font-size:13px;font-weight:600;text-decoration:none}
|
|
5436
6986
|
`;
|
|
5437
6987
|
//#endregion
|
|
5438
6988
|
//#region src/sketch-workspace.jsx
|
|
@@ -5504,7 +7054,7 @@ window.__ModuleLoader__.load({
|
|
|
5504
7054
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [settings.imageSketch && settings.imageEditing ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Tooltip, {
|
|
5505
7055
|
label: t("sketch"),
|
|
5506
7056
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Button, {
|
|
5507
|
-
variant: "
|
|
7057
|
+
variant: "ghost",
|
|
5508
7058
|
size: "sm",
|
|
5509
7059
|
"aria-label": t("sketch"),
|
|
5510
7060
|
onClick: (event) => workspace.current?.("sketch", event.currentTarget),
|
|
@@ -5639,7 +7189,7 @@ window.__ModuleLoader__.load({
|
|
|
5639
7189
|
storageTitle: "存储与缓存",
|
|
5640
7190
|
storageForecast: "额度预测缓存",
|
|
5641
7191
|
storageClear: "清除预测历史",
|
|
5642
|
-
storageHint: "
|
|
7192
|
+
storageHint: "只清理本地预测历史;原图、草稿、登录信息和共享依赖不受影响。子任务组件在“与其他模型”中管理。",
|
|
5643
7193
|
storageConfirm: "清除所有已登录账号的本地预测历史后,需要重新积累采样。服务端额度不变,后续查询会重新生成缓存。",
|
|
5644
7194
|
storageFailed: "未能读取或清除预测缓存,请重试。",
|
|
5645
7195
|
runtimeIncompatible: "检测到不兼容的 Codex 子任务组件,请卸载后重启,再安装受支持版本。",
|
|
@@ -5666,7 +7216,11 @@ window.__ModuleLoader__.load({
|
|
|
5666
7216
|
compactionTitle: "云端压缩",
|
|
5667
7217
|
compaction_dsh: "关闭",
|
|
5668
7218
|
compaction_cloud: "开启",
|
|
5669
|
-
compactionHint: "
|
|
7219
|
+
compactionHint: "长上下文由 Codex 压缩后继续请求,保留 DSH 历史与原生压缩。开启时该请求使用 SSE;历史改变后重新建立压缩状态。",
|
|
7220
|
+
otherModelsTitle: "在 DeepSeek 等其他模型的对话里使用订阅功能",
|
|
7221
|
+
otherModels_on: "开",
|
|
7222
|
+
otherModels_off: "关",
|
|
7223
|
+
otherModelsHint: "关闭后,用 DeepSeek 等非 Codex 模型对话时不再使用订阅的联网搜索(改用 DSH 搜索)、图片生成和 ChatGPT 连接器;Codex 订阅模型不受影响。手机远程控制和语音对话由你主动开启或发起,不受这个开关影响,可在本页单独设置。",
|
|
5670
7224
|
advancedModelSearch: "模型与搜索",
|
|
5671
7225
|
modelsSectionTitle: "模型",
|
|
5672
7226
|
searchSectionTitle: "搜索",
|
|
@@ -5756,7 +7310,7 @@ window.__ModuleLoader__.load({
|
|
|
5756
7310
|
voiceLang_de: "Deutsch",
|
|
5757
7311
|
voiceLang_pt: "Português",
|
|
5758
7312
|
voiceLang_ru: "Русский",
|
|
5759
|
-
remoteHint: "
|
|
7313
|
+
remoteHint: "开启后,这台电脑上的 DSH 会出现在 ChatGPT 手机 App 的 Codex 主机列表里,可用手机查看对话、发消息、切换模型和审批。需要订阅账号登录;电脑要保持开机和联网。",
|
|
5760
7314
|
remoteConnected: "电脑已连上 ChatGPT,还没有手机连接",
|
|
5761
7315
|
remoteConnecting: "正在连接",
|
|
5762
7316
|
remoteWaiting: "正在等待上一次连接释放,通常几分钟内自动连上",
|
|
@@ -5781,7 +7335,7 @@ window.__ModuleLoader__.load({
|
|
|
5781
7335
|
reviewModelTitle: "Auto review 审查模型",
|
|
5782
7336
|
reviewModel_session: "当前模型",
|
|
5783
7337
|
reviewModel_official: "Codex 官方审查模型",
|
|
5784
|
-
reviewModelHint: "
|
|
7338
|
+
reviewModelHint: "默认使用当前模型。选择官方后,DSH Auto review 用 Codex 自带的审查模型判断工具调用(账号目录提供时),审查规则与放行、拒绝流程仍由 DSH 负责;不可用时沿用当前模型。",
|
|
5785
7339
|
connectionHint: "默认 SSE。WebSocket 实验性复用连接与上下文传输;连接失败可回退 SSE。下次请求生效,不扩大上下文容量。",
|
|
5786
7340
|
streamIdleTimeoutTitle: "流无响应超时",
|
|
5787
7341
|
streamIdleTimeoutHint: "连续多久没有收到任何流式数据时中断本次请求,不是整体回答时限。调低可能中断较慢但仍在推理的回答,并交由 DSH 重试处理。默认 10 分钟。",
|
|
@@ -5860,6 +7414,24 @@ window.__ModuleLoader__.load({
|
|
|
5860
7414
|
sketchKey_zoomIn: "放大",
|
|
5861
7415
|
sketchKey_zoomOut: "缩小",
|
|
5862
7416
|
sketchKey_fit: "重置视图",
|
|
7417
|
+
sketchReplay: "回放",
|
|
7418
|
+
sketchReplayTitle: "绘制过程",
|
|
7419
|
+
sketchReplayClose: "返回",
|
|
7420
|
+
sketchReplayPlay: "播放",
|
|
7421
|
+
sketchReplayPause: "暂停",
|
|
7422
|
+
sketchReplaySpeed: "回放时长",
|
|
7423
|
+
sketchReplayFast: "12 秒",
|
|
7424
|
+
sketchReplayNormal: "30 秒",
|
|
7425
|
+
sketchReplaySlow: "60 秒",
|
|
7426
|
+
sketchReplayRecord: "录制过程视频",
|
|
7427
|
+
sketchReplaySave: "保存视频",
|
|
7428
|
+
sketchReplayAgain: "回到回放",
|
|
7429
|
+
sketchReplaySaveHint: "点「保存视频」时,系统会让你选择保存位置。",
|
|
7430
|
+
sketchReplayStopRecording: "停止录制",
|
|
7431
|
+
sketchReplayEmpty: "还没有可回放的绘制。",
|
|
7432
|
+
sketchReplayUnsupported: "当前环境不支持录制视频。",
|
|
7433
|
+
sketchReplayFileSuffix: "过程",
|
|
7434
|
+
sketchReplayHint: "按落笔顺序重放整幅画;录制会把回放生成 WebM 视频(按所选时长实时录制),录完先在这里预览,再决定是否保存。",
|
|
5863
7435
|
sketchFiles: "草稿",
|
|
5864
7436
|
sketchNew: "新建草图",
|
|
5865
7437
|
sketchImport: "导入文件",
|
|
@@ -6070,7 +7642,7 @@ window.__ModuleLoader__.load({
|
|
|
6070
7642
|
searchTitle: "搜索来源",
|
|
6071
7643
|
searchScope: "自动按当前会话模型分流;手动选择会覆盖所有模型和会话。",
|
|
6072
7644
|
searchAuto: "自动",
|
|
6073
|
-
searchAutoHint: "Codex 模型用订阅搜索,其他模型用 DSH;一方未登录或没有 Key
|
|
7645
|
+
searchAutoHint: "Codex 模型用订阅搜索,其他模型用 DSH;一方未登录或没有 Key 时自动改用另一方。",
|
|
6074
7646
|
searchDsh: "DSH 默认",
|
|
6075
7647
|
searchDshHint: "所有模型使用 DSH 当前搜索服务;没有 API Key 时用已登录的 DeepSeek 账号",
|
|
6076
7648
|
searchCodex: "Codex 订阅",
|
|
@@ -6191,7 +7763,7 @@ window.__ModuleLoader__.load({
|
|
|
6191
7763
|
quickQuotaForecast: "续航预测",
|
|
6192
7764
|
quickQuotaBeta: "Beta",
|
|
6193
7765
|
autoQuotaRetry: "额度重置后自动重试",
|
|
6194
|
-
autoQuotaRetryHint: "
|
|
7766
|
+
autoQuotaRetryHint: "开启后,等待已确认的短时额度重置;对话会显示等待原因且可停止,等待期间切换账号会立即重试。",
|
|
6195
7767
|
quickQuotaForecastHint: "按最近两小时的消耗估算;消耗不足或速度突变时重新校准,详情显示估计范围。仅供参考,历史保存在本机。",
|
|
6196
7768
|
contextTitle: "上下文窗口",
|
|
6197
7769
|
contextStandard: "标准",
|
|
@@ -6206,9 +7778,10 @@ window.__ModuleLoader__.load({
|
|
|
6206
7778
|
settingsTab_account: "账号与额度",
|
|
6207
7779
|
settingsTab_display: "使用偏好",
|
|
6208
7780
|
settingsTab_advanced: "模型与运行",
|
|
7781
|
+
settingsTab_interop: "与其他模型",
|
|
6209
7782
|
settingsTab_creative: "图片与草图",
|
|
6210
7783
|
settingsTab_maintenance: "维护",
|
|
6211
|
-
creativeSketch: "草图画板",
|
|
7784
|
+
creativeSketch: "草图画板 · Beta",
|
|
6212
7785
|
diagnosticsHint: "遇到问题时生成报告,可复制后用于反馈。不含登录凭据和账号标识。",
|
|
6213
7786
|
sketchCanvasSetting: "画板入口",
|
|
6214
7787
|
sketchAgentSetting: "Agent 绘图",
|
|
@@ -6366,7 +7939,7 @@ window.__ModuleLoader__.load({
|
|
|
6366
7939
|
storageTitle: "Storage and cache",
|
|
6367
7940
|
storageForecast: "Quota forecast cache",
|
|
6368
7941
|
storageClear: "Clear forecast history",
|
|
6369
|
-
storageHint: "Clears local forecast history only
|
|
7942
|
+
storageHint: "Clears local forecast history only; original images, drafts, sign-in data and shared dependencies are untouched. Subtask components are managed under Other models.",
|
|
6370
7943
|
storageConfirm: "This clears local forecast samples for all signed-in accounts. Forecasts will need new samples. Server quotas stay unchanged; subsequent checks recreate the cache.",
|
|
6371
7944
|
storageFailed: "Could not read or clear the forecast cache. Try again.",
|
|
6372
7945
|
runtimeIncompatible: "An incompatible Codex subtask component was found. Uninstall it, restart DSH, then install the supported version.",
|
|
@@ -6393,7 +7966,11 @@ window.__ModuleLoader__.load({
|
|
|
6393
7966
|
compactionTitle: "Cloud compaction",
|
|
6394
7967
|
compaction_dsh: "Off",
|
|
6395
7968
|
compaction_cloud: "On",
|
|
6396
|
-
compactionHint: "
|
|
7969
|
+
compactionHint: "Codex compacts long requests while DSH history and native compaction remain available. These requests use SSE; changed history invalidates previous checkpoints.",
|
|
7970
|
+
otherModelsTitle: "Use subscription features in conversations on other models (DeepSeek, …)",
|
|
7971
|
+
otherModels_on: "On",
|
|
7972
|
+
otherModels_off: "Off",
|
|
7973
|
+
otherModelsHint: "When off, conversations on DeepSeek and other non-Codex models no longer use subscription web search (DSH search is used instead), image generation or ChatGPT connectors; Codex subscription models are not affected. Phone remote control and voice calls are started by you and are not affected by this switch; set them separately on this page.",
|
|
6397
7974
|
advancedModelSearch: "Models and search",
|
|
6398
7975
|
modelsSectionTitle: "Models",
|
|
6399
7976
|
searchSectionTitle: "Search",
|
|
@@ -6483,7 +8060,7 @@ window.__ModuleLoader__.load({
|
|
|
6483
8060
|
voiceLang_de: "Deutsch",
|
|
6484
8061
|
voiceLang_pt: "Português",
|
|
6485
8062
|
voiceLang_ru: "Русский",
|
|
6486
|
-
remoteHint: "
|
|
8063
|
+
remoteHint: "When on, this computer's DSH appears as a host in the ChatGPT mobile app's Codex list, so you can follow conversations, send messages, switch models and approve actions from your phone. Needs a signed-in subscription account; the computer must stay on and online.",
|
|
6487
8064
|
remoteConnected: "This computer is online with ChatGPT; no phone connected yet",
|
|
6488
8065
|
remoteConnecting: "Connecting",
|
|
6489
8066
|
remoteWaiting: "Waiting for the previous connection to be released; usually reconnects within a few minutes",
|
|
@@ -6508,7 +8085,7 @@ window.__ModuleLoader__.load({
|
|
|
6508
8085
|
reviewModelTitle: "Auto review model",
|
|
6509
8086
|
reviewModel_session: "Current model",
|
|
6510
8087
|
reviewModel_official: "Codex reviewer",
|
|
6511
|
-
reviewModelHint: "
|
|
8088
|
+
reviewModelHint: "Uses the current model by default. With Codex reviewer, DSH Auto review judges tool calls with Codex's own review model when your account catalog offers it. DSH keeps its review policy and allow/deny flow; otherwise the current model is used.",
|
|
6512
8089
|
connectionHint: "SSE by default. Experimental WebSocket reuses connections and context transfers and can fall back to SSE on connection failure. Applies to the next request; context limits stay the same.",
|
|
6513
8090
|
streamIdleTimeoutTitle: "Stream inactivity timeout",
|
|
6514
8091
|
streamIdleTimeoutHint: "How long a request may receive no streamed data before it is aborted. This is not an overall response deadline. Lower values can abort slow but valid reasoning and hand the request to DSH retry handling. Default: 10 minutes.",
|
|
@@ -6587,6 +8164,24 @@ window.__ModuleLoader__.load({
|
|
|
6587
8164
|
sketchKey_zoomIn: "Zoom in",
|
|
6588
8165
|
sketchKey_zoomOut: "Zoom out",
|
|
6589
8166
|
sketchKey_fit: "Reset view",
|
|
8167
|
+
sketchReplay: "Replay",
|
|
8168
|
+
sketchReplayTitle: "How it was drawn",
|
|
8169
|
+
sketchReplayClose: "Back",
|
|
8170
|
+
sketchReplayPlay: "Play",
|
|
8171
|
+
sketchReplayPause: "Pause",
|
|
8172
|
+
sketchReplaySpeed: "Replay length",
|
|
8173
|
+
sketchReplayFast: "12 s",
|
|
8174
|
+
sketchReplayNormal: "30 s",
|
|
8175
|
+
sketchReplaySlow: "60 s",
|
|
8176
|
+
sketchReplayRecord: "Record process video",
|
|
8177
|
+
sketchReplaySave: "Save video",
|
|
8178
|
+
sketchReplayAgain: "Back to replay",
|
|
8179
|
+
sketchReplaySaveHint: "Choosing Save video asks where to put the file.",
|
|
8180
|
+
sketchReplayStopRecording: "Stop recording",
|
|
8181
|
+
sketchReplayEmpty: "Nothing to replay yet.",
|
|
8182
|
+
sketchReplayUnsupported: "Video recording is not available here.",
|
|
8183
|
+
sketchReplayFileSuffix: "process",
|
|
8184
|
+
sketchReplayHint: "Replays the drawing stroke by stroke; recording turns the replay into a WebM video (in real time, at the chosen length) that you can preview here before saving it.",
|
|
6590
8185
|
sketchFiles: "Drafts",
|
|
6591
8186
|
sketchNew: "New sketch",
|
|
6592
8187
|
sketchImport: "Import file",
|
|
@@ -6797,7 +8392,7 @@ window.__ModuleLoader__.load({
|
|
|
6797
8392
|
searchTitle: "Search source",
|
|
6798
8393
|
searchScope: "Auto follows the current session model; an explicit choice overrides every model and session.",
|
|
6799
8394
|
searchAuto: "Auto",
|
|
6800
|
-
searchAutoHint: "Codex models use subscription search; other models use DSH; if one side is not signed in or has no key, the other is used",
|
|
8395
|
+
searchAutoHint: "Codex models use subscription search; other models use DSH; if one side is not signed in or has no key, the other is used.",
|
|
6801
8396
|
searchDsh: "DSH default",
|
|
6802
8397
|
searchDshHint: "Use DSH's current search service for every model; without an API key the signed-in DeepSeek account is used",
|
|
6803
8398
|
searchCodex: "Codex subscription",
|
|
@@ -6918,7 +8513,7 @@ window.__ModuleLoader__.load({
|
|
|
6918
8513
|
quickQuotaForecast: "Runway",
|
|
6919
8514
|
quickQuotaBeta: "Beta",
|
|
6920
8515
|
autoQuotaRetry: "Retry after quota reset",
|
|
6921
|
-
autoQuotaRetryHint: "
|
|
8516
|
+
autoQuotaRetryHint: "Wait for confirmed short quota resets. The turn shows why it is waiting and can be stopped; switching accounts retries immediately.",
|
|
6922
8517
|
quickQuotaForecastHint: "Estimates recent two-hour consumption; recalibrates with insufficient data or changing pace. Details show a range. Indicative only; history stays local.",
|
|
6923
8518
|
contextTitle: "Context window",
|
|
6924
8519
|
contextStandard: "Standard",
|
|
@@ -6933,9 +8528,10 @@ window.__ModuleLoader__.load({
|
|
|
6933
8528
|
settingsTab_account: "Account",
|
|
6934
8529
|
settingsTab_display: "Preferences",
|
|
6935
8530
|
settingsTab_advanced: "Models & runtime",
|
|
8531
|
+
settingsTab_interop: "Other models",
|
|
6936
8532
|
settingsTab_creative: "Images & sketch",
|
|
6937
8533
|
settingsTab_maintenance: "Maintenance",
|
|
6938
|
-
creativeSketch: "Sketch board",
|
|
8534
|
+
creativeSketch: "Sketch board · Beta",
|
|
6939
8535
|
diagnosticsHint: "Generate a report to copy into a support request. Sign-in credentials and account identifiers are excluded.",
|
|
6940
8536
|
sketchCanvasSetting: "Board entry",
|
|
6941
8537
|
sketchAgentSetting: "Agent drawing",
|
|
@@ -7030,6 +8626,7 @@ window.__ModuleLoader__.load({
|
|
|
7030
8626
|
//#region src/client-styles.js
|
|
7031
8627
|
const STYLE = `
|
|
7032
8628
|
.codexSubscriptionAdvancedPreferences{display:flex;flex-direction:column;gap:10px}
|
|
8629
|
+
.codexSubscriptionAdvancedPreferences[data-others-off=true]>[data-governed=true]{opacity:.55;transition:opacity .15s}
|
|
7033
8630
|
.codexSubscriptionSearchChoices.codexSubscriptionQuotaModes{display:flex;flex:0 0 auto;gap:0;grid-template-columns:none}
|
|
7034
8631
|
.codexSubscriptionSettingsDisclosure>summary{display:flex;align-items:center;gap:10px;min-height:28px;cursor:pointer;list-style:none;font-size:14px;font-weight:500}
|
|
7035
8632
|
.codexSubscriptionSettingsDisclosure>summary::-webkit-details-marker{display:none}
|
|
@@ -7066,8 +8663,8 @@ window.__ModuleLoader__.load({
|
|
|
7066
8663
|
.codexSubscriptionPreferenceLabel{display:flex;align-items:center;gap:6px}
|
|
7067
8664
|
.codexSubscriptionPreference>.codexSubscriptionPreferenceCopy{flex:1 1 240px}
|
|
7068
8665
|
.codexSubscriptionPreferenceHint{max-width:none;font-size:11px;line-height:17px;color:var(--dsw-alias-label-tertiary)}
|
|
7069
|
-
.codexSubscriptionHintText{display
|
|
7070
|
-
.codexSubscriptionHintFold[data-
|
|
8666
|
+
.codexSubscriptionHintText{display:block}
|
|
8667
|
+
.codexSubscriptionHintFold[data-fold=true] .codexSubscriptionHintText{display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:3;overflow:hidden}
|
|
7071
8668
|
.codexSubscriptionHintToggle{display:inline-flex;align-items:center;gap:3px;margin-top:2px;padding:0;border:0;background:none;font:inherit;font-size:11px;line-height:17px;color:var(--dsw-alias-label-secondary);cursor:pointer}
|
|
7072
8669
|
.codexSubscriptionHintToggle::after{content:"";width:5px;height:5px;margin-top:-2px;border:solid currentColor;border-width:0 1.5px 1.5px 0;transform:rotate(45deg);transition:transform .15s}
|
|
7073
8670
|
.codexSubscriptionHintFold[data-open=true] .codexSubscriptionHintToggle::after{margin-top:2px;transform:rotate(-135deg)}
|
|
@@ -7105,7 +8702,7 @@ window.__ModuleLoader__.load({
|
|
|
7105
8702
|
.codexSubscriptionContextModelCopy strong{font-size:12px;line-height:18px;font-weight:500}
|
|
7106
8703
|
.codexSubscriptionContextModelCopy span{font-size:11px;line-height:16px;color:var(--dsw-alias-label-tertiary)}
|
|
7107
8704
|
.codexSubscriptionContextInput{width:116px}
|
|
7108
|
-
.codexSubscriptionSearch{display:flex;flex-direction:column;gap:
|
|
8705
|
+
.codexSubscriptionSearch{display:flex;flex-direction:column;gap:2px}
|
|
7109
8706
|
.codexSubscriptionDivider{height:1px;background:var(--dsw-alias-border-l2)}
|
|
7110
8707
|
.codexSubscriptionQuotaModes[data-saving=true] .codexSubscriptionQuotaMode:has(input:disabled){cursor:wait;opacity:1}
|
|
7111
8708
|
.codexSubscriptionSearchChoices[data-saving=true] .codexSubscriptionQuotaMode:has(input:disabled){cursor:wait;opacity:1}
|
|
@@ -7181,7 +8778,7 @@ window.__ModuleLoader__.load({
|
|
|
7181
8778
|
.codexSubscriptionLimit progress::-moz-progress-bar{background:var(--dsw-alias-brand-primary,#3964fe);border-radius:999px}
|
|
7182
8779
|
.codexSubscriptionLimitMeta{display:flex;justify-content:space-between;gap:10px;flex-wrap:wrap;font-size:11px;line-height:17px;color:var(--dsw-alias-label-tertiary)}
|
|
7183
8780
|
.codexSubscriptionLimitPeriod{display:flex;gap:8px;flex-wrap:wrap}
|
|
7184
|
-
.codexSubscriptionSearchOptions{margin-top:
|
|
8781
|
+
.codexSubscriptionSearch>.codexSubscriptionSearchOptions{margin-top:0;padding-top:2px;border-top:1px solid var(--dsw-alias-border-l2);font-size:12px}
|
|
7185
8782
|
.codexSubscriptionDivider+.codexSubscriptionDivider{display:none}
|
|
7186
8783
|
.codexSubscriptionPickerModels{display:flex;flex-direction:column;border-top:1px solid var(--dsw-alias-border-l2)}
|
|
7187
8784
|
.codexSubscriptionPickerModel{display:flex;align-items:center;justify-content:space-between;gap:12px;min-height:36px;border-bottom:1px solid var(--dsw-alias-border-l2);font-size:13px}
|
|
@@ -7239,7 +8836,7 @@ window.__ModuleLoader__.load({
|
|
|
7239
8836
|
.codexSubscriptionSpendLimit progress::-webkit-progress-bar{background:var(--dsw-alias-border-l3);border-radius:999px}
|
|
7240
8837
|
.codexSubscriptionSpendLimit progress::-webkit-progress-value{background:var(--dsw-alias-brand-primary,#3964fe);border-radius:999px}
|
|
7241
8838
|
.codexSubscriptionSpendLimit progress::-moz-progress-bar{background:var(--dsw-alias-brand-primary,#3964fe);border-radius:999px}
|
|
7242
|
-
.codexSettingsTabs{position:sticky;top:0;z-index:2;display:grid;grid-template-columns:repeat(
|
|
8839
|
+
.codexSettingsTabs{position:sticky;top:0;z-index:2;display:grid;grid-template-columns:repeat(5,minmax(0,1fr));gap:4px;padding:4px;background:var(--dsw-alias-bg-module-platform);border-radius:12px}
|
|
7243
8840
|
.codexSettingsTabs button{min-width:0;min-height:36px;border:0;border-radius:9px;padding:7px 6px;background:transparent;color:var(--dsw-alias-label-secondary);font:inherit;font-size:12px;line-height:18px;cursor:pointer}
|
|
7244
8841
|
.codexSettingsTabs button:focus-visible{outline:2px solid var(--dsw-alias-border-l3);outline-offset:1px}
|
|
7245
8842
|
.codexSettingsTabs button[aria-selected=true]{background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-primary);box-shadow:0 1px 3px #0001}
|
|
@@ -7340,7 +8937,7 @@ window.__ModuleLoader__.load({
|
|
|
7340
8937
|
.codexSubscriptionRuntime{padding-top:10px;border-top:1px solid var(--dsw-alias-border-l2);margin-top:2px}
|
|
7341
8938
|
.codexSubscriptionRuntime details{margin-top:8px}.codexSubscriptionRuntime details[open]>summary{margin-bottom:10px}
|
|
7342
8939
|
@container (max-width:480px){.codexSubscriptionPreference,.codexSubscriptionContextHead{flex-wrap:wrap}.codexSubscriptionPreferenceHint{max-width:none}.codexSubscriptionPreference>.codexSubscriptionPreferenceCopy{flex:1 1 220px}.codexSubscriptionQuotaModes{max-width:100%;flex-wrap:wrap}.codexSubscriptionQuotaMode{min-height:30px}.codexSubscriptionActions{flex-wrap:wrap}}
|
|
7343
|
-
@container (max-width:
|
|
8940
|
+
@container (max-width:420px){.codexSettingsTabs{grid-template-columns:none;grid-auto-flow:column;grid-auto-columns:minmax(max-content,1fr);overflow-x:auto;scrollbar-width:none}.codexSettingsTabs button{padding:7px 10px;white-space:nowrap}}
|
|
7344
8941
|
@media(prefers-reduced-motion:reduce){.codexSubscription *{transition:none!important}}
|
|
7345
8942
|
.codexSubscriptionLogHead{display:flex;flex-wrap:wrap;align-items:center;gap:8px 12px;margin-top:12px}.codexSubscriptionLogHead h4{margin:0;font-size:13px}.codexSubscriptionLog{max-height:320px;overflow:auto;margin:6px 0 0;padding:8px 10px;border:1px solid var(--border,#0002);border-radius:8px;font:11.5px/1.5 ui-monospace,Consolas,monospace;white-space:pre-wrap;word-break:break-word}.codexSubscriptionLog_error{color:#c0392b}.codexSubscriptionLog_warn{color:#b9770e}.codexSubscriptionLog_info{opacity:.8}
|
|
7346
8943
|
.codexSubscriptionConnectors>.codexSubscriptionQuotaModes{flex:0 0 auto;display:flex;flex-wrap:nowrap;margin-left:auto}
|
|
@@ -7382,7 +8979,7 @@ window.__ModuleLoader__.load({
|
|
|
7382
8979
|
.codexVoiceTool[aria-pressed=true]{color:var(--dsw-alias-label-tertiary)}
|
|
7383
8980
|
|
|
7384
8981
|
/* Every fold-out in the settings reads as pressable: a full-width row, a chevron on the right that turns when it opens, a hover state. */
|
|
7385
|
-
.codexSubscriptionHistory>summary,.codexSubscriptionSearchOptions>summary,.codexSubscriptionRuntime summary,.codexSubscriptionDiagnostics details>summary,.codexImageDetails summary{display:flex;align-items:center;gap:8px;width:auto;min-height:32px;margin:0 -10px;padding:4px 10px;border-radius:8px;list-style:none;cursor:pointer;user-select:none;font-size:13px;font-weight:500;color:var(--dsw-alias-label-primary);transition:background .12s}
|
|
8982
|
+
.codexSubscriptionHistory>summary,.codexSubscriptionSearchOptions>summary,.codexSubscriptionRuntime summary,.codexSubscriptionDiagnostics details>summary,.codexImageDetails summary{display:flex;align-items:center;gap:8px;width:auto;box-sizing:border-box;min-height:32px;margin:0 -10px;padding:4px 10px;border-radius:8px;list-style:none;cursor:pointer;user-select:none;font-size:13px;font-weight:500;color:var(--dsw-alias-label-primary);transition:background .12s}
|
|
7386
8983
|
.codexSubscriptionHistory>summary::-webkit-details-marker,.codexSubscriptionSearchOptions>summary::-webkit-details-marker,.codexSubscriptionRuntime summary::-webkit-details-marker,.codexSubscriptionDiagnostics details>summary::-webkit-details-marker,.codexImageDetails summary::-webkit-details-marker{display:none}
|
|
7387
8984
|
.codexSubscriptionHistory>summary::after,.codexSubscriptionSearchOptions>summary::after,.codexSubscriptionRuntime summary::after,.codexSubscriptionDiagnostics details>summary::after,.codexImageDetails summary::after{content:"";flex:none;margin-left:auto;width:7px;height:7px;border:solid var(--dsw-alias-label-tertiary);border-width:0 1.6px 1.6px 0;transform:translateY(-2px) rotate(45deg);transition:transform .15s,border-color .12s}
|
|
7388
8985
|
.codexSubscriptionHistory[open]>summary::after,.codexSubscriptionSearchOptions[open]>summary::after,.codexSubscriptionRuntime details[open]>summary::after,.codexSubscriptionDiagnostics details[open]>summary::after,.codexImageDetails[open]>summary::after{transform:translateY(2px) rotate(-135deg)}
|
|
@@ -8954,6 +10551,7 @@ window.__ModuleLoader__.load({
|
|
|
8954
10551
|
connectionMode: value?.connectionMode === "websocket" ? "websocket" : "sse",
|
|
8955
10552
|
reviewModel: value?.reviewModel === "official" ? "official" : "session",
|
|
8956
10553
|
remoteControl: value?.remoteControl === "on" ? "on" : "off",
|
|
10554
|
+
otherModels: value?.otherModels === "off" ? "off" : "on",
|
|
8957
10555
|
compactionMode: value?.compactionMode === "cloud" ? "cloud" : "dsh",
|
|
8958
10556
|
subagentBackend: value?.subagentBackend === "codex" ? "codex" : "dsh",
|
|
8959
10557
|
subagentBackendAvailable,
|
|
@@ -9017,6 +10615,8 @@ window.__ModuleLoader__.load({
|
|
|
9017
10615
|
connectionMode: value?.connectionMode === "websocket" ? "websocket" : "sse",
|
|
9018
10616
|
reviewModel: value?.reviewModel === "official" ? "official" : "session",
|
|
9019
10617
|
remoteControl: value?.remoteControl === "on" ? "on" : "off",
|
|
10618
|
+
otherModels: value?.otherModels === "off" ? "off" : "on",
|
|
10619
|
+
otherModels: value?.otherModels === "off" ? "off" : "on",
|
|
9020
10620
|
compactionMode: value?.compactionMode === "cloud" ? "cloud" : "dsh",
|
|
9021
10621
|
subagentBackend: value?.subagentBackend === "codex" ? "codex" : "dsh",
|
|
9022
10622
|
...readCapabilitySettings(value),
|
|
@@ -9516,7 +11116,7 @@ window.__ModuleLoader__.load({
|
|
|
9516
11116
|
}
|
|
9517
11117
|
//#endregion
|
|
9518
11118
|
//#region src/version.js
|
|
9519
|
-
const PACKAGE_VERSION = "3.0
|
|
11119
|
+
const PACKAGE_VERSION = "3.1.0";
|
|
9520
11120
|
//#endregion
|
|
9521
11121
|
//#region src/client-recovery.js
|
|
9522
11122
|
async function recoveryCall(rpc, endpoint, payload = {}, timeoutMs = 1e4) {
|
|
@@ -9792,7 +11392,7 @@ window.__ModuleLoader__.load({
|
|
|
9792
11392
|
left: 0,
|
|
9793
11393
|
top: 0
|
|
9794
11394
|
};
|
|
9795
|
-
function CodexModelSelect({ locked, available, directory, load, select, preference, t }) {
|
|
11395
|
+
function CodexModelSelect({ locked, available, directory, load, select, preference, t, renderSlot }) {
|
|
9796
11396
|
const state = (0, react.useSyncExternalStore)(directory.subscribe, directory.getSnapshot);
|
|
9797
11397
|
const preferenceSnapshot = usePreferenceSnapshot(preference);
|
|
9798
11398
|
const [open, setOpen] = (0, react.useState)(false);
|
|
@@ -9835,6 +11435,26 @@ window.__ModuleLoader__.load({
|
|
|
9835
11435
|
...effort.description === void 0 ? {} : { description: effort.description }
|
|
9836
11436
|
}))], [reasoning, t]);
|
|
9837
11437
|
const modelLabel = currentChoice?.model.name ?? t("selectModel");
|
|
11438
|
+
const labelOf = (group, model, placement, selected) => {
|
|
11439
|
+
if (typeof renderSlot !== "function") return model.name;
|
|
11440
|
+
try {
|
|
11441
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
11442
|
+
"data-provider-id": group.id,
|
|
11443
|
+
"data-model-id": model.id,
|
|
11444
|
+
children: renderSlot("conversation.input.model.label", {
|
|
11445
|
+
provider: {
|
|
11446
|
+
id: group.id,
|
|
11447
|
+
name: group.name
|
|
11448
|
+
},
|
|
11449
|
+
model,
|
|
11450
|
+
placement,
|
|
11451
|
+
selected
|
|
11452
|
+
}, { fallback: model.name })
|
|
11453
|
+
});
|
|
11454
|
+
} catch {
|
|
11455
|
+
return model.name;
|
|
11456
|
+
}
|
|
11457
|
+
};
|
|
9838
11458
|
const searchable = visibleGroups.reduce((total, group) => total + group.models.length, 0) > 4;
|
|
9839
11459
|
const needle = searchable ? query.trim().toLocaleLowerCase() : "";
|
|
9840
11460
|
const shownGroups = needle === "" ? visibleGroups : visibleGroups.map((group) => ({
|
|
@@ -10028,7 +11648,7 @@ window.__ModuleLoader__.load({
|
|
|
10028
11648
|
}, key);
|
|
10029
11649
|
let content = null;
|
|
10030
11650
|
if (pane === "root") content = /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
10031
|
-
cell("model", t("modelLabel"), modelLabel),
|
|
11651
|
+
cell("model", t("modelLabel"), currentChoice === void 0 ? modelLabel : labelOf(currentChoice.group, currentChoice.model, "menu", true)),
|
|
10032
11652
|
reasoning === void 0 ? null : cell("effort", t("effortLabel"), effortLabel),
|
|
10033
11653
|
(speedSupported || ultrafastSupported) && cell("speed", t("speedTitle"), t(speedKey)),
|
|
10034
11654
|
verbositySupported && cell("verbosity", t("verbosityTitle"), verbosityLabel)
|
|
@@ -10076,7 +11696,7 @@ window.__ModuleLoader__.load({
|
|
|
10076
11696
|
children: t("modelsHidden")
|
|
10077
11697
|
}) : null, entry.models.map((model) => option({
|
|
10078
11698
|
key: model.id,
|
|
10079
|
-
label: model.
|
|
11699
|
+
label: labelOf(entry, model, "option", state.current?.provider === entry.id && state.current.model === model.id),
|
|
10080
11700
|
selected: state.current?.provider === entry.id && state.current.model === model.id,
|
|
10081
11701
|
disabled: busy,
|
|
10082
11702
|
onClick: () => chooseModel({
|
|
@@ -10183,7 +11803,7 @@ window.__ModuleLoader__.load({
|
|
|
10183
11803
|
}),
|
|
10184
11804
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
10185
11805
|
className: "codexModelSelectLabel",
|
|
10186
|
-
children: modelLabel
|
|
11806
|
+
children: currentChoice === void 0 ? modelLabel : labelOf(currentChoice.group, currentChoice.model, "trigger", true)
|
|
10187
11807
|
}),
|
|
10188
11808
|
effortLabel === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
10189
11809
|
className: "codexModelSelectEffort",
|
|
@@ -10194,42 +11814,38 @@ window.__ModuleLoader__.load({
|
|
|
10194
11814
|
}), menu]
|
|
10195
11815
|
});
|
|
10196
11816
|
}
|
|
10197
|
-
|
|
10198
|
-
//#region src/client-hint.jsx
|
|
10199
|
-
/** A setting's explanation: shows up to two lines; a "More" link appears only when the text is actually cut off. */
|
|
11817
|
+
/** A setting's explanation: short text is shown whole; only text that would save several lines when folded gets a "More" link. */
|
|
10200
11818
|
function Hint({ children, t, as: Tag = "span" }) {
|
|
10201
11819
|
const [open, setOpen] = (0, react.useState)(false);
|
|
10202
|
-
const [
|
|
11820
|
+
const [lines, setLines] = (0, react.useState)(0);
|
|
10203
11821
|
const text = (0, react.useRef)(null);
|
|
10204
11822
|
const id = (0, react.useId)();
|
|
10205
11823
|
const foldable = typeof children === "string";
|
|
10206
11824
|
(0, react.useLayoutEffect)(() => {
|
|
10207
11825
|
const node = text.current;
|
|
10208
|
-
if (!foldable || node === null
|
|
10209
|
-
const measure = () =>
|
|
11826
|
+
if (!foldable || node === null) return;
|
|
11827
|
+
const measure = () => setLines(Math.round(node.scrollHeight / (Number.parseFloat(getComputedStyle(node).lineHeight) || 17)));
|
|
10210
11828
|
measure();
|
|
10211
11829
|
if (typeof ResizeObserver !== "function") return;
|
|
10212
11830
|
const observer = new ResizeObserver(measure);
|
|
10213
11831
|
observer.observe(node);
|
|
10214
11832
|
return () => observer.disconnect();
|
|
10215
|
-
}, [
|
|
10216
|
-
children,
|
|
10217
|
-
foldable,
|
|
10218
|
-
open
|
|
10219
|
-
]);
|
|
11833
|
+
}, [children, foldable]);
|
|
10220
11834
|
if (!foldable) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Tag, {
|
|
10221
11835
|
className: "codexSubscriptionPreferenceHint",
|
|
10222
11836
|
children
|
|
10223
11837
|
});
|
|
11838
|
+
const folds = lines >= 6;
|
|
10224
11839
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(Tag, {
|
|
10225
11840
|
className: "codexSubscriptionPreferenceHint codexSubscriptionHintFold",
|
|
11841
|
+
"data-fold": folds && !open ? "true" : void 0,
|
|
10226
11842
|
"data-open": open || void 0,
|
|
10227
11843
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
10228
11844
|
id,
|
|
10229
11845
|
ref: text,
|
|
10230
11846
|
className: "codexSubscriptionHintText",
|
|
10231
11847
|
children
|
|
10232
|
-
}),
|
|
11848
|
+
}), folds ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
10233
11849
|
type: "button",
|
|
10234
11850
|
className: "codexSubscriptionHintToggle",
|
|
10235
11851
|
"aria-expanded": open,
|
|
@@ -14973,7 +16589,8 @@ void main(){
|
|
|
14973
16589
|
function PreferencesCard({ preference, rpc, t, defaultModel, section = "display" }) {
|
|
14974
16590
|
const snapshot = usePreferenceSnapshot(preference);
|
|
14975
16591
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
14976
|
-
className: section === "advanced" ? "codexSubscriptionAdvancedPreferences" : "codexSubscriptionCard codexSubscriptionPreferencesCard",
|
|
16592
|
+
className: section === "advanced" || section === "interop" ? "codexSubscriptionAdvancedPreferences" : "codexSubscriptionCard codexSubscriptionPreferencesCard",
|
|
16593
|
+
"data-others-off": section === "interop" && snapshot.otherModels === "off" ? "true" : void 0,
|
|
14977
16594
|
children: [
|
|
14978
16595
|
snapshot.restartRequired ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
14979
16596
|
className: "codexSubscriptionError",
|
|
@@ -15019,21 +16636,9 @@ void main(){
|
|
|
15019
16636
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(RetryPolicyPreference, {
|
|
15020
16637
|
preference,
|
|
15021
16638
|
t
|
|
15022
|
-
}),
|
|
15023
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ConnectorsPreference, {
|
|
15024
|
-
preference,
|
|
15025
|
-
t
|
|
15026
16639
|
})
|
|
15027
16640
|
]
|
|
15028
16641
|
}),
|
|
15029
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
15030
|
-
className: "codexSubscriptionCard codexSubscriptionPreferencesCard",
|
|
15031
|
-
"aria-label": t("searchSectionTitle"),
|
|
15032
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", { children: t("searchSectionTitle") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SearchProviderPreference, {
|
|
15033
|
-
preference,
|
|
15034
|
-
t
|
|
15035
|
-
})]
|
|
15036
|
-
}),
|
|
15037
16642
|
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
|
|
15038
16643
|
className: "codexSubscriptionCard codexSubscriptionPreferencesCard",
|
|
15039
16644
|
"aria-label": t("connectionTitle"),
|
|
@@ -15081,7 +16686,7 @@ void main(){
|
|
|
15081
16686
|
}),
|
|
15082
16687
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("section", {
|
|
15083
16688
|
className: "codexSubscriptionCard codexSubscriptionPreferencesCard",
|
|
15084
|
-
"aria-label": t("
|
|
16689
|
+
"aria-label": t("compactionTitle"),
|
|
15085
16690
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
15086
16691
|
className: "codexSubscriptionPreference",
|
|
15087
16692
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
@@ -15089,49 +16694,90 @@ void main(){
|
|
|
15089
16694
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
15090
16695
|
className: "codexSubscriptionPreferenceLabel",
|
|
15091
16696
|
children: [
|
|
15092
|
-
t("
|
|
16697
|
+
t("compactionTitle"),
|
|
15093
16698
|
" ",
|
|
15094
16699
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", { children: "Beta" })
|
|
15095
16700
|
]
|
|
15096
16701
|
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Hint, {
|
|
15097
16702
|
t,
|
|
15098
|
-
children: t("
|
|
16703
|
+
children: t("compactionHint")
|
|
15099
16704
|
})]
|
|
15100
16705
|
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
15101
16706
|
className: "codexSubscriptionQuotaModes",
|
|
15102
16707
|
role: "radiogroup",
|
|
15103
|
-
"aria-label": t("
|
|
16708
|
+
"aria-label": t("compactionTitle"),
|
|
15104
16709
|
"aria-busy": snapshot.saving || void 0,
|
|
15105
|
-
children: ["
|
|
16710
|
+
children: ["dsh", "cloud"].map((value) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
|
|
15106
16711
|
className: "codexSubscriptionQuotaMode",
|
|
15107
16712
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
15108
16713
|
type: "radio",
|
|
15109
|
-
name: "codex-
|
|
15110
|
-
checked: snapshot.
|
|
16714
|
+
name: "codex-compaction-mode",
|
|
16715
|
+
checked: snapshot.compactionMode === value,
|
|
15111
16716
|
disabled: !snapshot.writable,
|
|
15112
16717
|
onChange: () => {
|
|
15113
|
-
preference.set({
|
|
16718
|
+
preference.set({ compactionMode: value });
|
|
15114
16719
|
}
|
|
15115
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t(`
|
|
16720
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t(`compaction_${value}`) })]
|
|
16721
|
+
}, value))
|
|
16722
|
+
})]
|
|
16723
|
+
})
|
|
16724
|
+
})
|
|
16725
|
+
] }) : section === "interop" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
16726
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("section", {
|
|
16727
|
+
className: "codexSubscriptionCard codexSubscriptionPreferencesCard",
|
|
16728
|
+
"aria-label": t("otherModelsTitle"),
|
|
16729
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
16730
|
+
className: "codexSubscriptionPreference",
|
|
16731
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
16732
|
+
className: "codexSubscriptionPreferenceCopy",
|
|
16733
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
16734
|
+
className: "codexSubscriptionPreferenceLabel",
|
|
16735
|
+
children: t("otherModelsTitle")
|
|
16736
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Hint, {
|
|
16737
|
+
t,
|
|
16738
|
+
children: t("otherModelsHint")
|
|
16739
|
+
})]
|
|
16740
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
16741
|
+
className: "codexSubscriptionQuotaModes",
|
|
16742
|
+
role: "radiogroup",
|
|
16743
|
+
"aria-label": t("otherModelsTitle"),
|
|
16744
|
+
"aria-busy": snapshot.saving || void 0,
|
|
16745
|
+
children: ["on", "off"].map((value) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
|
|
16746
|
+
className: "codexSubscriptionQuotaMode",
|
|
16747
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
16748
|
+
type: "radio",
|
|
16749
|
+
name: "codex-other-models",
|
|
16750
|
+
checked: snapshot.otherModels === value,
|
|
16751
|
+
disabled: !snapshot.writable,
|
|
16752
|
+
onChange: () => {
|
|
16753
|
+
preference.set({ otherModels: value });
|
|
16754
|
+
}
|
|
16755
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t(`otherModels_${value}`) })]
|
|
15116
16756
|
}, value))
|
|
15117
16757
|
})]
|
|
15118
16758
|
})
|
|
15119
16759
|
}),
|
|
15120
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(
|
|
15121
|
-
|
|
15122
|
-
|
|
15123
|
-
|
|
15124
|
-
|
|
16760
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("section", {
|
|
16761
|
+
className: "codexSubscriptionCard codexSubscriptionPreferencesCard",
|
|
16762
|
+
"data-governed": "true",
|
|
16763
|
+
"aria-label": t("searchSectionTitle"),
|
|
16764
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SearchProviderPreference, {
|
|
16765
|
+
preference,
|
|
16766
|
+
t
|
|
16767
|
+
})
|
|
15125
16768
|
}),
|
|
15126
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(
|
|
15127
|
-
|
|
15128
|
-
|
|
15129
|
-
|
|
15130
|
-
|
|
16769
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("section", {
|
|
16770
|
+
className: "codexSubscriptionCard codexSubscriptionPreferencesCard",
|
|
16771
|
+
"data-governed": "true",
|
|
16772
|
+
"aria-label": t("connectors"),
|
|
16773
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ConnectorsPreference, {
|
|
16774
|
+
preference,
|
|
16775
|
+
t
|
|
16776
|
+
})
|
|
15131
16777
|
}),
|
|
15132
16778
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("section", {
|
|
15133
16779
|
className: "codexSubscriptionCard codexSubscriptionPreferencesCard",
|
|
15134
|
-
"aria-label": t("
|
|
16780
|
+
"aria-label": t("reviewModelTitle"),
|
|
15135
16781
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
15136
16782
|
className: "codexSubscriptionPreference",
|
|
15137
16783
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
@@ -15139,30 +16785,30 @@ void main(){
|
|
|
15139
16785
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
15140
16786
|
className: "codexSubscriptionPreferenceLabel",
|
|
15141
16787
|
children: [
|
|
15142
|
-
t("
|
|
16788
|
+
t("reviewModelTitle"),
|
|
15143
16789
|
" ",
|
|
15144
16790
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", { children: "Beta" })
|
|
15145
16791
|
]
|
|
15146
16792
|
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Hint, {
|
|
15147
16793
|
t,
|
|
15148
|
-
children: t("
|
|
16794
|
+
children: t("reviewModelHint")
|
|
15149
16795
|
})]
|
|
15150
16796
|
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
15151
16797
|
className: "codexSubscriptionQuotaModes",
|
|
15152
16798
|
role: "radiogroup",
|
|
15153
|
-
"aria-label": t("
|
|
16799
|
+
"aria-label": t("reviewModelTitle"),
|
|
15154
16800
|
"aria-busy": snapshot.saving || void 0,
|
|
15155
|
-
children: ["
|
|
16801
|
+
children: ["session", "official"].map((value) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
|
|
15156
16802
|
className: "codexSubscriptionQuotaMode",
|
|
15157
16803
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
15158
16804
|
type: "radio",
|
|
15159
|
-
name: "codex-
|
|
15160
|
-
checked: snapshot.
|
|
16805
|
+
name: "codex-review-model",
|
|
16806
|
+
checked: snapshot.reviewModel === value,
|
|
15161
16807
|
disabled: !snapshot.writable,
|
|
15162
16808
|
onChange: () => {
|
|
15163
|
-
preference.set({
|
|
16809
|
+
preference.set({ reviewModel: value });
|
|
15164
16810
|
}
|
|
15165
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t(`
|
|
16811
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t(`reviewModel_${value}`) })]
|
|
15166
16812
|
}, value))
|
|
15167
16813
|
})]
|
|
15168
16814
|
})
|
|
@@ -15208,6 +16854,18 @@ void main(){
|
|
|
15208
16854
|
preference,
|
|
15209
16855
|
t
|
|
15210
16856
|
})]
|
|
16857
|
+
}),
|
|
16858
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(VoiceCallCard, {
|
|
16859
|
+
rpc,
|
|
16860
|
+
preference,
|
|
16861
|
+
snapshot,
|
|
16862
|
+
t
|
|
16863
|
+
}),
|
|
16864
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(RemoteControlCard, {
|
|
16865
|
+
rpc,
|
|
16866
|
+
preference,
|
|
16867
|
+
snapshot,
|
|
16868
|
+
t
|
|
15211
16869
|
})
|
|
15212
16870
|
] }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
15213
16871
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(QuickQuotaPreference, {
|
|
@@ -17022,6 +18680,7 @@ void main(){
|
|
|
17022
18680
|
const tabs = [
|
|
17023
18681
|
"account",
|
|
17024
18682
|
"advanced",
|
|
18683
|
+
"interop",
|
|
17025
18684
|
"creative",
|
|
17026
18685
|
"maintenance"
|
|
17027
18686
|
];
|
|
@@ -17112,6 +18771,18 @@ void main(){
|
|
|
17112
18771
|
section: "advanced"
|
|
17113
18772
|
})
|
|
17114
18773
|
}),
|
|
18774
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
18775
|
+
role: "tabpanel",
|
|
18776
|
+
id: `${id}-interop`,
|
|
18777
|
+
"aria-labelledby": `${id}-interop-tab`,
|
|
18778
|
+
hidden: tab !== "interop",
|
|
18779
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PreferencesCard, {
|
|
18780
|
+
rpc,
|
|
18781
|
+
preference,
|
|
18782
|
+
t,
|
|
18783
|
+
section: "interop"
|
|
18784
|
+
})
|
|
18785
|
+
}),
|
|
17115
18786
|
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
17116
18787
|
role: "tabpanel",
|
|
17117
18788
|
id: `${id}-creative`,
|
|
@@ -17398,6 +19069,11 @@ void main(){
|
|
|
17398
19069
|
name: "conversation.input.model",
|
|
17399
19070
|
priority: -10,
|
|
17400
19071
|
locale: NS,
|
|
19072
|
+
children: { "conversation.input.model.label": {
|
|
19073
|
+
kind: "single",
|
|
19074
|
+
scope: "session",
|
|
19075
|
+
inline: true
|
|
19076
|
+
} },
|
|
17401
19077
|
inject: (sessionId) => {
|
|
17402
19078
|
const directory = modelDirectories.directoryFor(sessionId);
|
|
17403
19079
|
const available = sessions.subagentAddress(sessionId) === void 0;
|