@perkyzz/emvb 0.5.0 → 0.6.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.md +4 -0
- package/THIRD_PARTY_NOTICES.md +23 -1
- package/licenses/exif-js.LICENSE +21 -0
- package/licenses/fflate.LICENSE +21 -0
- package/licenses/glfx.js.LICENSE +19 -0
- package/licenses/mini-photo-editor.LICENSE +21 -0
- package/licenses/photocn.LICENSE +21 -0
- package/package.json +2 -1
- package/src/admin/editor/Editor.tsx +6 -0
- package/src/admin/editor/collection-previews.ts +6 -1
- package/src/admin/editor/editor-chrome.tsx +49 -0
- package/src/admin/editor/editor-commands.ts +13 -0
- package/src/admin/editor/editor-css.ts +3 -0
- package/src/admin/editor/panels/ColorControl.tsx +5 -4
- package/src/admin/editor/panels/LayersPanel.tsx +13 -3
- package/src/admin/editor/panels/VariableSection.tsx +5 -3
- package/src/admin/editor/panels/settings/FieldControl.tsx +18 -7
- package/src/admin/editor/panels/settings/MediaPicker.tsx +154 -4
- package/src/admin/editor/panels/settings/RequiredFieldsNotice.tsx +76 -0
- package/src/admin/editor/panels/variable-values.ts +14 -0
- package/src/admin/editor/store.ts +7 -3
- package/src/admin/image-editor/BlurFocus.tsx +112 -0
- package/src/admin/image-editor/Canvas.tsx +261 -0
- package/src/admin/image-editor/CropOverlay.tsx +390 -0
- package/src/admin/image-editor/CurvesPanel.tsx +394 -0
- package/src/admin/image-editor/ExportDialog.tsx +354 -0
- package/src/admin/image-editor/ImageEditButton.tsx +83 -0
- package/src/admin/image-editor/ImageEditorDialog.tsx +786 -0
- package/src/admin/image-editor/MetadataPanel.tsx +183 -0
- package/src/admin/image-editor/announce.tsx +65 -0
- package/src/admin/image-editor/crop-geometry.ts +161 -0
- package/src/admin/image-editor/curve-math.ts +177 -0
- package/src/admin/image-editor/data-url-fetch.ts +59 -0
- package/src/admin/image-editor/engine.ts +55 -0
- package/src/admin/image-editor/exif.ts +82 -0
- package/src/admin/image-editor/flatten.ts +54 -0
- package/src/admin/image-editor/gpu-fit.ts +81 -0
- package/src/admin/image-editor/image-editor-css.ts +398 -0
- package/src/admin/image-editor/load.ts +109 -0
- package/src/admin/image-editor/panels.tsx +287 -0
- package/src/admin/image-editor/parts.tsx +565 -0
- package/src/admin/image-editor/save.ts +125 -0
- package/src/admin/image-editor/tone-panels.tsx +338 -0
- package/src/admin/image-editor/tools.ts +59 -0
- package/src/admin/image-editor/worker.ts +111 -0
- package/src/admin/media-api.ts +113 -3
- package/src/admin/ui.ts +5 -0
- package/src/astro/EmVBPage.astro +11 -2
- package/src/astro/render.ts +3 -0
- package/src/astro/resolve-theme.ts +15 -4
- package/src/astro/visitor.ts +4 -3
- package/src/constants.ts +1 -1
- package/src/core/arrange.ts +2 -0
- package/src/core/data/bindings.ts +12 -6
- package/src/core/design/classes.ts +5 -3
- package/src/core/design/diff.ts +3 -1
- package/src/core/design/merge.ts +3 -1
- package/src/core/design/transfer.ts +13 -2
- package/src/core/design/variables.ts +2 -1
- package/src/core/elements/dynamic-elements.ts +9 -1
- package/src/core/elements/form-elements.ts +16 -17
- package/src/core/elements/plain-text.ts +2 -2
- package/src/core/forms/binding.ts +148 -1
- package/src/core/history/diff.ts +32 -4
- package/src/core/image-edit/schema.ts +145 -0
- package/src/core/image-edit/summary.ts +58 -0
- package/src/core/index.ts +14 -0
- package/src/core/limits.ts +10 -0
- package/src/core/migrate/index.ts +3 -1
- package/src/core/perf/meter.ts +9 -1
- package/src/core/render/dynamic-post.ts +2 -1
- package/src/core/render/form.ts +24 -6
- package/src/core/render/index.ts +26 -5
- package/src/core/schema/layout.ts +11 -1
- package/src/core/share/link.ts +5 -2
- package/src/core/stable-json.ts +15 -0
- package/src/core/theme/dynamic.ts +21 -18
- package/src/core/theme/pagination.ts +30 -3
- package/src/core/theme/popup-rules.ts +10 -5
- package/src/mcp/ports.ts +8 -1
- package/src/mcp/read.ts +68 -1
- package/src/mcp/tools.ts +1 -1
- package/src/mcp/write.ts +100 -18
- package/src/server/agent-settings.ts +28 -3
- package/src/server/icon-routes.ts +8 -5
- package/src/server/mcp-routes.ts +68 -10
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EmVB's only door into photocn (D-062): the image editor reaches photocn through this file, so a
|
|
3
|
+
* photocn update touches one place and tests can swap the engine out. Lazily loaded with the
|
|
4
|
+
* dialog; never in the main chunk.
|
|
5
|
+
*
|
|
6
|
+
* W-483 moved the dialog from `photocn/photo` to `photocn/react`: its `useImageEditorState` already
|
|
7
|
+
* has the crop view (whole image under a frame), transient slider edits folded into one undo step,
|
|
8
|
+
* the crop keyboard and the live histogram, which the photocn-style layout needs.
|
|
9
|
+
*/
|
|
10
|
+
import { hasWebGL2, planRendering, type RenderMode } from "./worker.ts";
|
|
11
|
+
|
|
12
|
+
export {
|
|
13
|
+
type CurveChannels,
|
|
14
|
+
type CurvePoint,
|
|
15
|
+
fitRectInPolygon,
|
|
16
|
+
rectInsidePolygon,
|
|
17
|
+
type NormalizedRect,
|
|
18
|
+
type Quad,
|
|
19
|
+
type Vec2,
|
|
20
|
+
} from "photocn";
|
|
21
|
+
export {
|
|
22
|
+
aspectRatioOptions,
|
|
23
|
+
errorMessage,
|
|
24
|
+
ImageEditorProvider,
|
|
25
|
+
useImageEditor,
|
|
26
|
+
useImageEditorState,
|
|
27
|
+
type AdjustSection,
|
|
28
|
+
type AdjustValue,
|
|
29
|
+
type BlurValue,
|
|
30
|
+
type ImageEditorGeometryApi,
|
|
31
|
+
} from "photocn/react";
|
|
32
|
+
export { drawRgbHistogram } from "photocn/dom";
|
|
33
|
+
|
|
34
|
+
export type EnginePlan =
|
|
35
|
+
| { ok: true; renderMode: RenderMode; spawnWorker?: () => Worker; reason?: string }
|
|
36
|
+
| { ok: false; message: string };
|
|
37
|
+
|
|
38
|
+
const NO_WEBGL =
|
|
39
|
+
"This browser can't edit images: it has no WebGL 2. Try an up-to-date Chrome, Edge, Firefox or Safari.";
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Decides where the editor renders before its canvas mounts (worker first, D-059): a canvas handed
|
|
43
|
+
* to the worker can't come back (W-480 #4).
|
|
44
|
+
*/
|
|
45
|
+
export async function planEngine(options: { force?: RenderMode } = {}): Promise<EnginePlan> {
|
|
46
|
+
const plan = await planRendering(options.force ? { force: options.force } : {});
|
|
47
|
+
// The worker has its own WebGL 2 (OffscreenCanvas); the main thread needs one here (W-480 #5).
|
|
48
|
+
if (plan.renderMode === "main" && !hasWebGL2()) return { ok: false, message: NO_WEBGL };
|
|
49
|
+
return {
|
|
50
|
+
ok: true,
|
|
51
|
+
renderMode: plan.renderMode,
|
|
52
|
+
spawnWorker: plan.spawnWorker,
|
|
53
|
+
reason: plan.reason,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GPS stripping for exported JPEGs (D-060).
|
|
3
|
+
*
|
|
4
|
+
* photocn copies the source EXIF block into JPEG exports
|
|
5
|
+
* (`preserveExif`, default on) and keeps GPS. We remove the GPS IFD
|
|
6
|
+
* pointer (tag 0x8825) and zero its IFD so no location survives, while
|
|
7
|
+
* keeping orientation, camera and date tags. WebP/PNG exports carry no
|
|
8
|
+
* EXIF from photocn, so only JPEG needs this.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const GPS_POINTER = 0x8825;
|
|
12
|
+
|
|
13
|
+
/** Returns a copy of the JPEG with GPS removed, and whether any was found. */
|
|
14
|
+
export function stripJpegGps(input: ArrayBuffer): { bytes: ArrayBuffer; removed: boolean } {
|
|
15
|
+
const out = input.slice(0);
|
|
16
|
+
const view = new DataView(out);
|
|
17
|
+
if (view.byteLength < 4 || view.getUint16(0) !== 0xffd8) return { bytes: out, removed: false };
|
|
18
|
+
let offset = 2;
|
|
19
|
+
let removed = false;
|
|
20
|
+
while (offset + 4 <= view.byteLength) {
|
|
21
|
+
if (view.getUint8(offset) !== 0xff) break;
|
|
22
|
+
const marker = view.getUint8(offset + 1);
|
|
23
|
+
if (marker === 0xda || marker === 0xd9) break; // start of scan / end
|
|
24
|
+
const size = view.getUint16(offset + 2);
|
|
25
|
+
if (size < 2) break;
|
|
26
|
+
const start = offset + 4;
|
|
27
|
+
const end = Math.min(offset + 2 + size, view.byteLength);
|
|
28
|
+
if (marker === 0xe1 && end - start >= 6 && readAscii(view, start, 6) === "Exif\0\0") {
|
|
29
|
+
removed = stripTiffGps(view, start + 6, end) || removed;
|
|
30
|
+
}
|
|
31
|
+
offset = offset + 2 + size;
|
|
32
|
+
}
|
|
33
|
+
return { bytes: out, removed };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function stripTiffGps(view: DataView, tiff: number, end: number): boolean {
|
|
37
|
+
if (tiff + 8 > end) return false;
|
|
38
|
+
const order = view.getUint16(tiff);
|
|
39
|
+
if (order !== 0x4949 && order !== 0x4d4d) return false;
|
|
40
|
+
const le = order === 0x4949;
|
|
41
|
+
const ifd0 = tiff + view.getUint32(tiff + 4, le);
|
|
42
|
+
if (ifd0 + 2 > end) return false;
|
|
43
|
+
const count = view.getUint16(ifd0, le);
|
|
44
|
+
for (let i = 0; i < count; i++) {
|
|
45
|
+
const entry = ifd0 + 2 + i * 12;
|
|
46
|
+
if (entry + 12 > end) return false;
|
|
47
|
+
if (view.getUint16(entry, le) !== GPS_POINTER) continue;
|
|
48
|
+
const gps = tiff + view.getUint32(entry + 8, le);
|
|
49
|
+
wipeIfd(view, gps, tiff, end, le);
|
|
50
|
+
// Drop the pointer entry; the entries after it and the next-IFD link move up 12 bytes.
|
|
51
|
+
const last = ifd0 + 2 + count * 12 + 4;
|
|
52
|
+
if (last > end) return false;
|
|
53
|
+
const bytes = new Uint8Array(view.buffer, view.byteOffset);
|
|
54
|
+
bytes.copyWithin(entry, entry + 12, last);
|
|
55
|
+
bytes.fill(0, last - 12, last);
|
|
56
|
+
view.setUint16(ifd0, count - 1, le);
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function wipeIfd(view: DataView, ifd: number, tiff: number, end: number, le: boolean): void {
|
|
63
|
+
if (ifd + 2 > end) return;
|
|
64
|
+
const count = view.getUint16(ifd, le);
|
|
65
|
+
const sizes: Record<number, number> = { 1: 1, 2: 1, 3: 2, 4: 4, 5: 8, 7: 1, 9: 4, 10: 8 };
|
|
66
|
+
for (let i = 0; i < count; i++) {
|
|
67
|
+
const entry = ifd + 2 + i * 12;
|
|
68
|
+
if (entry + 12 > end) break;
|
|
69
|
+
const bytes = (sizes[view.getUint16(entry + 2, le)] ?? 1) * view.getUint32(entry + 4, le);
|
|
70
|
+
if (bytes > 4) {
|
|
71
|
+
const at = tiff + view.getUint32(entry + 8, le);
|
|
72
|
+
for (let p = at; p < at + bytes && p < end; p++) view.setUint8(p, 0);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
for (let p = ifd; p < ifd + 2 + count * 12 + 4 && p < end; p++) view.setUint8(p, 0);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function readAscii(view: DataView, at: number, n: number): string {
|
|
79
|
+
let s = "";
|
|
80
|
+
for (let i = 0; i < n; i++) s += String.fromCharCode(view.getUint8(at + i));
|
|
81
|
+
return s;
|
|
82
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* W-495: JPEG has no transparency, and photocn's JPEG export leaves transparent pixels black.
|
|
3
|
+
* Pictures that may have transparency (anything but a JPEG) are exported as PNG and then
|
|
4
|
+
* flattened onto white before the single JPEG encode.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** True when a JPEG copy of this source must be flattened onto a background first. */
|
|
8
|
+
export function needsFlatten(format: string, sourceType: string): boolean {
|
|
9
|
+
return format === "jpeg" && !/^image\/jpe?g$/i.test(sourceType);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** Draws a PNG export onto white and encodes it as JPEG. */
|
|
13
|
+
export async function flattenToJpeg(png: Blob, quality: number | undefined): Promise<Blob> {
|
|
14
|
+
const bitmap = await createImageBitmap(png);
|
|
15
|
+
try {
|
|
16
|
+
const { width, height } = bitmap;
|
|
17
|
+
if (typeof OffscreenCanvas !== "undefined") {
|
|
18
|
+
const canvas = new OffscreenCanvas(width, height);
|
|
19
|
+
const ctx = canvas.getContext("2d");
|
|
20
|
+
if (!ctx) throw new Error("Export failed.");
|
|
21
|
+
ctx.fillStyle = "#ffffff";
|
|
22
|
+
ctx.fillRect(0, 0, width, height);
|
|
23
|
+
ctx.drawImage(bitmap, 0, 0);
|
|
24
|
+
return await canvas.convertToBlob({ type: "image/jpeg", quality });
|
|
25
|
+
}
|
|
26
|
+
const canvas = document.createElement("canvas");
|
|
27
|
+
canvas.width = width;
|
|
28
|
+
canvas.height = height;
|
|
29
|
+
const ctx = canvas.getContext("2d");
|
|
30
|
+
if (!ctx) throw new Error("Export failed.");
|
|
31
|
+
ctx.fillStyle = "#ffffff";
|
|
32
|
+
ctx.fillRect(0, 0, width, height);
|
|
33
|
+
ctx.drawImage(bitmap, 0, 0);
|
|
34
|
+
return await new Promise<Blob>((resolve, reject) =>
|
|
35
|
+
canvas.toBlob(
|
|
36
|
+
(b) => (b ? resolve(b) : reject(new Error("Export failed."))),
|
|
37
|
+
"image/jpeg",
|
|
38
|
+
quality,
|
|
39
|
+
),
|
|
40
|
+
);
|
|
41
|
+
} finally {
|
|
42
|
+
bitmap.close();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Saves a blob under a name, for Download when the file was flattened here. */
|
|
47
|
+
export function downloadBlob(blob: Blob, name: string): void {
|
|
48
|
+
const url = URL.createObjectURL(blob);
|
|
49
|
+
const a = document.createElement("a");
|
|
50
|
+
a.href = url;
|
|
51
|
+
a.download = name;
|
|
52
|
+
a.click();
|
|
53
|
+
setTimeout(() => URL.revokeObjectURL(url), 1000);
|
|
54
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* W-496: photocn renders with WebGL, which can't hold a picture wider or taller than the GPU's
|
|
3
|
+
* texture limit (often 8192 or 16384 px). Past it the preview stayed empty and Save copy wrote a
|
|
4
|
+
* flat grey file. Such pictures are scaled down to the limit before editing, and the editor says
|
|
5
|
+
* so. Crops in the recipe are fractions of the picture, so a re-open still lines up.
|
|
6
|
+
*/
|
|
7
|
+
import type { LoadedSource } from "./load.ts";
|
|
8
|
+
|
|
9
|
+
type Size = { width: number; height: number };
|
|
10
|
+
|
|
11
|
+
/** The largest side this device's WebGL can render, or null without WebGL. */
|
|
12
|
+
function gpuMaxSide(): number | null {
|
|
13
|
+
try {
|
|
14
|
+
const canvas = document.createElement("canvas");
|
|
15
|
+
const gl = (canvas.getContext("webgl2") ??
|
|
16
|
+
canvas.getContext("webgl")) as WebGLRenderingContext | null;
|
|
17
|
+
if (!gl) return null;
|
|
18
|
+
const viewport = gl.getParameter(gl.MAX_VIEWPORT_DIMS) as Int32Array | null;
|
|
19
|
+
const limits = [
|
|
20
|
+
gl.getParameter(gl.MAX_TEXTURE_SIZE) as number,
|
|
21
|
+
gl.getParameter(gl.MAX_RENDERBUFFER_SIZE) as number,
|
|
22
|
+
viewport?.[0] ?? Infinity,
|
|
23
|
+
viewport?.[1] ?? Infinity,
|
|
24
|
+
].filter((n) => Number.isFinite(n) && n > 0);
|
|
25
|
+
gl.getExtension("WEBGL_lose_context")?.loseContext();
|
|
26
|
+
return limits.length ? Math.min(...limits) : null;
|
|
27
|
+
} catch {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** The size to edit at: null when the picture already fits. */
|
|
33
|
+
export function fitWithin(size: Size, maxSide: number | null): Size | null {
|
|
34
|
+
if (!maxSide || (size.width <= maxSide && size.height <= maxSide)) return null;
|
|
35
|
+
const scale = maxSide / Math.max(size.width, size.height);
|
|
36
|
+
return {
|
|
37
|
+
width: Math.max(1, Math.min(maxSide, Math.floor(size.width * scale))),
|
|
38
|
+
height: Math.max(1, Math.min(maxSide, Math.floor(size.height * scale))),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
type Ready = Extract<LoadedSource, { ok: true }>;
|
|
43
|
+
|
|
44
|
+
/** Scales a picture past the GPU limit down to it; other pictures are returned as they are. */
|
|
45
|
+
export async function fitSourceToGpu(
|
|
46
|
+
source: Ready,
|
|
47
|
+
maxSide: number | null = gpuMaxSide(),
|
|
48
|
+
): Promise<Ready> {
|
|
49
|
+
if (!maxSide || typeof createImageBitmap !== "function") return source;
|
|
50
|
+
const full = await createImageBitmap(source.blob);
|
|
51
|
+
const original = { width: full.width, height: full.height };
|
|
52
|
+
full.close();
|
|
53
|
+
const target = fitWithin(original, maxSide);
|
|
54
|
+
if (!target) return source;
|
|
55
|
+
const bitmap = await createImageBitmap(source.blob, {
|
|
56
|
+
resizeWidth: target.width,
|
|
57
|
+
resizeHeight: target.height,
|
|
58
|
+
resizeQuality: "high",
|
|
59
|
+
});
|
|
60
|
+
const jpeg = /^image\/jpe?g$/i.test(source.type);
|
|
61
|
+
const type = jpeg ? "image/jpeg" : "image/png";
|
|
62
|
+
let blob: Blob;
|
|
63
|
+
try {
|
|
64
|
+
if (typeof OffscreenCanvas !== "undefined") {
|
|
65
|
+
const canvas = new OffscreenCanvas(target.width, target.height);
|
|
66
|
+
canvas.getContext("2d")?.drawImage(bitmap, 0, 0);
|
|
67
|
+
blob = await canvas.convertToBlob({ type, quality: 0.95 });
|
|
68
|
+
} else {
|
|
69
|
+
const canvas = document.createElement("canvas");
|
|
70
|
+
canvas.width = target.width;
|
|
71
|
+
canvas.height = target.height;
|
|
72
|
+
canvas.getContext("2d")?.drawImage(bitmap, 0, 0);
|
|
73
|
+
blob = await new Promise<Blob>((resolve, reject) =>
|
|
74
|
+
canvas.toBlob((b) => (b ? resolve(b) : reject(new Error("too large"))), type, 0.95),
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
} finally {
|
|
78
|
+
bitmap.close();
|
|
79
|
+
}
|
|
80
|
+
return { ...source, blob, type, reducedFrom: original };
|
|
81
|
+
}
|