@perkyzz/emvb 0.5.0 → 0.7.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/access/RequireEditor.tsx +7 -7
- package/src/admin/access/role.ts +5 -2
- package/src/admin/content-api.ts +10 -3
- package/src/admin/content-item.ts +1 -1
- package/src/admin/editor/A11yCopilot.tsx +104 -56
- package/src/admin/editor/CommandPalette.tsx +29 -13
- package/src/admin/editor/Editor.tsx +88 -20
- package/src/admin/editor/EditorToasts.tsx +26 -0
- package/src/admin/editor/PerfMeter.tsx +97 -72
- package/src/admin/editor/ShareLink.tsx +107 -72
- package/src/admin/editor/ShortcutsDialog.tsx +27 -16
- package/src/admin/editor/Timeline.tsx +255 -160
- package/src/admin/editor/TopBar.tsx +71 -14
- package/src/admin/editor/canvas/CanvasFrame.tsx +10 -1
- package/src/admin/editor/canvas/CanvasTextEdit.tsx +8 -2
- package/src/admin/editor/canvas/drop-line.ts +11 -3
- package/src/admin/editor/canvas/frame-focus-ring.ts +37 -0
- package/src/admin/editor/canvas/use-canvas-dnd.ts +32 -3
- package/src/admin/editor/canvas/vnode-react.tsx +7 -0
- package/src/admin/editor/collection-previews.ts +16 -1
- package/src/admin/editor/dialogs.tsx +38 -14
- package/src/admin/editor/dnd/drop-target.ts +26 -1
- package/src/admin/editor/edited-noun.ts +15 -0
- package/src/admin/editor/editor-chrome.tsx +108 -7
- package/src/admin/editor/editor-commands.ts +15 -1
- package/src/admin/editor/editor-css.ts +75 -22
- package/src/admin/editor/element-chrome.ts +21 -11
- package/src/admin/editor/feature-css.ts +45 -13
- package/src/admin/editor/icons/IconLibraryDialog.tsx +52 -11
- package/src/admin/editor/icons/library.ts +1 -1
- package/src/admin/editor/icons/use-icon-library.ts +5 -2
- package/src/admin/editor/ime.ts +29 -0
- package/src/admin/editor/palette-items.ts +10 -3
- package/src/admin/editor/panels/AddPanel.tsx +35 -10
- package/src/admin/editor/panels/ClassesSection.tsx +18 -7
- package/src/admin/editor/panels/ColorControl.tsx +135 -27
- package/src/admin/editor/panels/ConditionsEditor.tsx +52 -26
- package/src/admin/editor/panels/ElementPanel.tsx +134 -24
- package/src/admin/editor/panels/LayersPanel.tsx +68 -22
- package/src/admin/editor/panels/PageSettings.tsx +66 -35
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +170 -32
- package/src/admin/editor/panels/TokenScales.tsx +76 -36
- package/src/admin/editor/panels/TriggerSettings.tsx +50 -12
- package/src/admin/editor/panels/TriggersEditor.tsx +2 -1
- package/src/admin/editor/panels/VariableSection.tsx +53 -21
- package/src/admin/editor/panels/color-space.ts +9 -3
- package/src/admin/editor/panels/settings/AdvancedFields.tsx +12 -2
- package/src/admin/editor/panels/settings/AudienceEditor.tsx +51 -35
- package/src/admin/editor/panels/settings/BackgroundControls.tsx +55 -11
- package/src/admin/editor/panels/settings/BackgroundFill.tsx +3 -2
- package/src/admin/editor/panels/settings/BindingsEditor.tsx +15 -18
- package/src/admin/editor/panels/settings/BoxControl.tsx +2 -1
- package/src/admin/editor/panels/settings/ClassChip.tsx +21 -9
- package/src/admin/editor/panels/settings/ClassChipInput.tsx +24 -16
- package/src/admin/editor/panels/settings/DraftTextField.tsx +41 -3
- package/src/admin/editor/panels/settings/EffectsControls.tsx +38 -14
- package/src/admin/editor/panels/settings/FieldBindControl.tsx +46 -28
- package/src/admin/editor/panels/settings/FieldControl.tsx +38 -15
- package/src/admin/editor/panels/settings/FormBindControl.tsx +2 -2
- package/src/admin/editor/panels/settings/HintedSwitch.tsx +33 -0
- package/src/admin/editor/panels/settings/IconControls.tsx +12 -8
- package/src/admin/editor/panels/settings/IconPicker.tsx +2 -0
- package/src/admin/editor/panels/settings/ImageSourcesField.tsx +3 -1
- package/src/admin/editor/panels/settings/ItemList.tsx +15 -2
- package/src/admin/editor/panels/settings/LengthRow.tsx +8 -6
- package/src/admin/editor/panels/settings/MediaPicker.tsx +274 -20
- package/src/admin/editor/panels/settings/MotionControl.tsx +28 -15
- package/src/admin/editor/panels/settings/NumberRow.tsx +9 -3
- package/src/admin/editor/panels/settings/PanelSelect.tsx +50 -0
- package/src/admin/editor/panels/settings/QueryStyleRows.tsx +25 -18
- package/src/admin/editor/panels/settings/RequiredFieldsNotice.tsx +141 -0
- package/src/admin/editor/panels/settings/StyleRow.tsx +10 -3
- package/src/admin/editor/panels/settings/StyleSources.tsx +4 -1
- package/src/admin/editor/panels/settings/VariantEditor.tsx +10 -1
- package/src/admin/editor/panels/settings/box-link-name.ts +6 -2
- package/src/admin/editor/panels/settings/class-suggest.ts +7 -7
- package/src/admin/editor/panels/settings/query-style.ts +38 -9
- package/src/admin/editor/panels/settings/svg-images.ts +13 -0
- package/src/admin/editor/panels/site-list.tsx +20 -6
- package/src/admin/editor/panels/variable-values.ts +25 -4
- package/src/admin/editor/restore-deleted.ts +21 -2
- package/src/admin/editor/section-templates.ts +81 -12
- package/src/admin/editor/shortcuts.ts +17 -2
- package/src/admin/editor/store.ts +14 -3
- package/src/admin/editor/useEditorCommands.ts +61 -15
- package/src/admin/editor/useEditorData.ts +4 -2
- package/src/admin/editor/useEditorShortcuts.ts +17 -7
- package/src/admin/editor/useNodeActions.ts +61 -6
- package/src/admin/editor/useSave.ts +22 -7
- package/src/admin/forms-api.ts +2 -0
- 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 +395 -0
- package/src/admin/image-editor/ExportDialog.tsx +384 -0
- package/src/admin/image-editor/ImageEditButton.tsx +83 -0
- package/src/admin/image-editor/ImageEditorDialog.tsx +828 -0
- package/src/admin/image-editor/MetadataPanel.tsx +194 -0
- package/src/admin/image-editor/announce.tsx +65 -0
- package/src/admin/image-editor/crop-geometry.ts +162 -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 +400 -0
- package/src/admin/image-editor/load.ts +116 -0
- package/src/admin/image-editor/panels.tsx +287 -0
- package/src/admin/image-editor/parts.tsx +614 -0
- package/src/admin/image-editor/save.ts +141 -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 +114 -3
- package/src/admin/pages/AgentsPage.tsx +138 -27
- package/src/admin/pages/CreateDialog.tsx +97 -30
- package/src/admin/pages/NewPageDialog.tsx +21 -3
- package/src/admin/pages/NewThemePartDialog.tsx +11 -3
- package/src/admin/pages/PageList.tsx +14 -6
- package/src/admin/pages/SetupShell.tsx +28 -12
- package/src/admin/pages/ThemePartList.tsx +27 -7
- package/src/admin/pages/list-kit.tsx +106 -24
- package/src/admin/search.ts +15 -0
- package/src/admin/setup/useSetupStatus.ts +1 -1
- package/src/admin/theme-api.ts +13 -3
- package/src/admin/ui.ts +78 -22
- package/src/astro/EmVBPage.astro +11 -2
- package/src/astro/floats/runtime.ts +21 -0
- package/src/astro/menu/runtime.ts +34 -1
- package/src/astro/popups/runtime.ts +33 -3
- package/src/astro/render.ts +6 -0
- package/src/astro/resolve-theme.ts +67 -14
- package/src/astro/resolve.ts +9 -1
- package/src/astro/tabs/runtime.ts +12 -0
- package/src/astro/theme-posts.ts +2 -2
- package/src/astro/visitor.ts +6 -3
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +171 -24
- package/src/core/arrange.ts +29 -6
- package/src/core/audience/rules.ts +5 -1
- package/src/core/audience/variants.ts +29 -3
- package/src/core/clipboard.ts +7 -0
- package/src/core/css/generate.ts +31 -6
- package/src/core/data/bindings.ts +19 -6
- package/src/core/design/classes.ts +20 -9
- package/src/core/design/diff.ts +9 -1
- package/src/core/design/merge.ts +93 -3
- package/src/core/design/tokens.ts +16 -2
- package/src/core/design/transfer.ts +46 -8
- package/src/core/design/variables.ts +32 -10
- package/src/core/elements/dynamic-elements.ts +53 -6
- package/src/core/elements/form-elements.ts +68 -30
- package/src/core/elements/index.ts +83 -38
- package/src/core/elements/menu.ts +37 -19
- package/src/core/elements/plain-text.ts +2 -2
- package/src/core/elements/select-prompt.ts +3 -0
- package/src/core/elements/svg-ids.ts +39 -0
- package/src/core/forms/binding.ts +190 -2
- package/src/core/forms/definition.ts +72 -0
- package/src/core/history/diff.ts +49 -4
- package/src/core/icons/catalog.ts +3 -2
- package/src/core/image-edit/schema.ts +155 -0
- package/src/core/image-edit/summary.ts +61 -0
- package/src/core/index.ts +29 -1
- package/src/core/limits.ts +21 -0
- package/src/core/migrate/index.ts +3 -1
- package/src/core/perf/meter.ts +51 -8
- package/src/core/recipes/index.ts +5 -4
- package/src/core/render/context.ts +8 -0
- package/src/core/render/dynamic-post.ts +71 -13
- package/src/core/render/extras.ts +77 -4
- package/src/core/render/form.ts +164 -12
- package/src/core/render/index.ts +179 -22
- package/src/core/render/loop.ts +43 -7
- package/src/core/render/pagination.ts +18 -4
- package/src/core/render/section.ts +27 -0
- package/src/core/render/tabs.ts +12 -3
- package/src/core/render/vnode.ts +1 -1
- package/src/core/sanitize/css.ts +15 -2
- package/src/core/sanitize/embed-url.ts +42 -5
- package/src/core/sanitize/url.ts +2 -1
- package/src/core/schema/layout.ts +26 -7
- package/src/core/share/link.ts +5 -2
- package/src/core/stable-json.ts +15 -0
- package/src/core/stats.ts +2 -1
- package/src/core/theme/conditions.ts +3 -1
- package/src/core/theme/dynamic.ts +57 -23
- package/src/core/theme/float.ts +9 -2
- package/src/core/theme/pagination.ts +57 -10
- package/src/core/theme/popup-markup.ts +23 -5
- package/src/core/theme/popup-rules.ts +11 -5
- package/src/core/theme/triggers.ts +3 -2
- package/src/core/tree-ops.ts +27 -0
- package/src/mcp/ports.ts +8 -1
- package/src/mcp/rate-limit.ts +2 -1
- package/src/mcp/read.ts +82 -3
- package/src/mcp/refs.ts +18 -0
- package/src/mcp/tools.ts +1 -1
- package/src/mcp/write.ts +271 -25
- package/src/server/agent-settings.ts +29 -4
- package/src/server/hooks.ts +5 -3
- package/src/server/icon-routes.ts +33 -9
- package/src/server/mcp-routes.ts +74 -11
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Metadata tool (W-486): photocn's `metadata-panel.tsx`
|
|
3
|
+
* (https://github.com/rbbydotdev/photocn, apps/www/src/registry/image-editor), MIT License,
|
|
4
|
+
* Copyright (c) 2026 rbbydotdev: a title with the EXIF status badge, an alert when EXIF can't be
|
|
5
|
+
* read, a rule, then Name, Type, Size, Dimensions, Modified, Format, Color, Captured, Camera,
|
|
6
|
+
* Lens and GPS. Rebuilt with Kumo and EmVB tokens. EmVB adds what a saved copy keeps (D-060): a
|
|
7
|
+
* photo with a location gets a note that JPEG copies drop it and WebP/PNG copies carry no EXIF.
|
|
8
|
+
*/
|
|
9
|
+
import { Badge } from "@cloudflare/kumo";
|
|
10
|
+
import { MapPinIcon } from "@phosphor-icons/react";
|
|
11
|
+
import * as React from "react";
|
|
12
|
+
import { useEditSummary } from "./announce.tsx";
|
|
13
|
+
import { useImageEditor } from "./engine.ts";
|
|
14
|
+
|
|
15
|
+
type Tag = { hvalue?: unknown; value?: unknown } | undefined;
|
|
16
|
+
type Meta = {
|
|
17
|
+
format?: string;
|
|
18
|
+
icc?: Record<string, unknown>;
|
|
19
|
+
exif?: Record<string, Tag>;
|
|
20
|
+
tiff?: Record<string, Tag>;
|
|
21
|
+
gps?: Record<string, Tag>;
|
|
22
|
+
};
|
|
23
|
+
type FileInfo = { name?: string; type?: string; size?: number; lastModified?: number };
|
|
24
|
+
type Engine = {
|
|
25
|
+
imageInput: {
|
|
26
|
+
fileInfo: FileInfo | null;
|
|
27
|
+
image: HTMLImageElement | null;
|
|
28
|
+
blob: Blob | null;
|
|
29
|
+
};
|
|
30
|
+
exif: { status: string; metadata: unknown; error: unknown };
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export type MetadataRow = { label: string; value: string };
|
|
34
|
+
|
|
35
|
+
/** photocn's rows, in its order; empty values are left out. */
|
|
36
|
+
export function metadataRows(input: {
|
|
37
|
+
fileInfo: FileInfo | null;
|
|
38
|
+
image: { naturalWidth: number; naturalHeight: number } | null;
|
|
39
|
+
blobType?: string;
|
|
40
|
+
metadata: Meta | undefined;
|
|
41
|
+
displayName?: string;
|
|
42
|
+
}): MetadataRow[] {
|
|
43
|
+
const { fileInfo, image, metadata } = input;
|
|
44
|
+
const rows: MetadataRow[] = [];
|
|
45
|
+
add(rows, "Name", input.displayName ?? fileInfo?.name);
|
|
46
|
+
add(rows, "Type", fileInfo?.type || input.blobType);
|
|
47
|
+
add(rows, "Size", fileInfo?.size ? formatBytes(fileInfo.size) : undefined);
|
|
48
|
+
add(rows, "Dimensions", image ? `${image.naturalWidth} x ${image.naturalHeight}` : undefined);
|
|
49
|
+
add(rows, "Modified", fileInfo?.lastModified ? formatDate(fileInfo.lastModified) : undefined);
|
|
50
|
+
add(rows, "Format", metadata?.format);
|
|
51
|
+
add(rows, "Color", colorProfile(metadata?.icc));
|
|
52
|
+
add(rows, "Captured", tagValue(metadata?.exif?.["DateTimeOriginal"]));
|
|
53
|
+
add(rows, "Camera", camera(metadata?.tiff?.["Make"], metadata?.tiff?.["Model"]));
|
|
54
|
+
add(rows, "Lens", tagValue(metadata?.exif?.["LensModel"]));
|
|
55
|
+
add(rows, "GPS", gps(metadata?.gps));
|
|
56
|
+
return rows;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function add(rows: MetadataRow[], label: string, value: string | undefined) {
|
|
60
|
+
if (value === undefined || value === "") return;
|
|
61
|
+
rows.push({ label, value });
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function tagValue(tag: Tag): string | undefined {
|
|
65
|
+
return formatValue(tag?.hvalue ?? tag?.value);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** An EXIF string without its trailing spaces or NULs. */
|
|
69
|
+
const clean = (text: string | undefined) => text?.replace(/[\s\0]+$/u, "") || undefined;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* W-698: most cameras repeat the make in the model ("Canon" + "Canon EOS R5"), which read
|
|
73
|
+
* "Canon Canon EOS R5"; the model alone is shown then. EXIF strings may end in spaces or NULs.
|
|
74
|
+
*/
|
|
75
|
+
function camera(make: Tag, model: Tag): string | undefined {
|
|
76
|
+
const a = clean(tagValue(make));
|
|
77
|
+
const b = clean(tagValue(model));
|
|
78
|
+
if (a && b) {
|
|
79
|
+
const brand = a.split(/\s+/)[0]?.toLowerCase() ?? "";
|
|
80
|
+
return b.toLowerCase().startsWith(brand) ? b : `${a} ${b}`;
|
|
81
|
+
}
|
|
82
|
+
return a ?? b;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function gps(tags: Record<string, Tag> | undefined): string | undefined {
|
|
86
|
+
const lon = tagValue(tags?.["GPSLongitude"]);
|
|
87
|
+
const lat = tagValue(tags?.["GPSLatitude"]);
|
|
88
|
+
if (lon && lat) return `${lat}, ${lon}`;
|
|
89
|
+
return lat ?? lon;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function colorProfile(icc: Record<string, unknown> | undefined): string | undefined {
|
|
93
|
+
const profile = icc?.["ColorProfile"];
|
|
94
|
+
return formatValue(Array.isArray(profile) ? profile[0] : profile);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function formatValue(value: unknown): string | undefined {
|
|
98
|
+
if (value === undefined || value === null || value === "") return undefined;
|
|
99
|
+
if (Array.isArray(value)) return value.map(formatValue).filter(Boolean).join(", ");
|
|
100
|
+
if (value instanceof Date) return value.toLocaleString();
|
|
101
|
+
if (typeof value === "object") return JSON.stringify(value);
|
|
102
|
+
return String(value);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const formatDate = (value: number) => new Date(value).toLocaleString();
|
|
106
|
+
|
|
107
|
+
export function formatBytes(size: number): string {
|
|
108
|
+
if (!Number.isFinite(size) || size <= 0) return "0 B";
|
|
109
|
+
const units = ["B", "KB", "MB", "GB"] as const;
|
|
110
|
+
let value = size;
|
|
111
|
+
let unit = 0;
|
|
112
|
+
// W-698: a value that rounds up to 1024 moves to the next unit ("1.0 MB", not "1024.0 KB").
|
|
113
|
+
while (unit < units.length - 1 && Number(value.toFixed(unit === 0 ? 0 : 1)) >= 1024) {
|
|
114
|
+
value /= 1024;
|
|
115
|
+
unit += 1;
|
|
116
|
+
}
|
|
117
|
+
return `${value.toFixed(unit === 0 ? 0 : 1)} ${units[unit]}`;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function errorText(error: unknown): string {
|
|
121
|
+
if (error instanceof Error) return error.message;
|
|
122
|
+
if (typeof error === "string") return error;
|
|
123
|
+
return "Unable to read metadata.";
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** The picture's name as the editor shows it (alt text for storage-key file names). */
|
|
127
|
+
export const ImageNameContext = React.createContext<string | undefined>(undefined);
|
|
128
|
+
|
|
129
|
+
export function MetadataPanel() {
|
|
130
|
+
const displayName = React.useContext(ImageNameContext);
|
|
131
|
+
const editor = useImageEditor();
|
|
132
|
+
const engine = editor.engine as unknown as Engine;
|
|
133
|
+
const { status, error } = engine.exif;
|
|
134
|
+
const metadata = engine.exif.metadata as Meta | undefined;
|
|
135
|
+
const rows = metadataRows({
|
|
136
|
+
fileInfo: engine.imageInput.fileInfo,
|
|
137
|
+
image: engine.imageInput.image,
|
|
138
|
+
blobType: engine.imageInput.blob?.type,
|
|
139
|
+
metadata,
|
|
140
|
+
...(displayName ? { displayName } : {}),
|
|
141
|
+
});
|
|
142
|
+
const edits = useEditSummary();
|
|
143
|
+
const hasGps = rows.some((r) => r.label === "GPS");
|
|
144
|
+
const badge: { text: string; variant: React.ComponentProps<typeof Badge>["variant"] } =
|
|
145
|
+
status === "loading"
|
|
146
|
+
? { text: "Reading", variant: "outline" }
|
|
147
|
+
: status === "loaded"
|
|
148
|
+
? { text: "EXIF ready", variant: "secondary" }
|
|
149
|
+
: { text: "File", variant: "outline" };
|
|
150
|
+
return (
|
|
151
|
+
<section aria-label="Metadata" className="emvb-ie-panel" data-emvb-image-panel="metadata">
|
|
152
|
+
<div className="emvb-ie-meta" data-slot="metadata-panel">
|
|
153
|
+
<div className="emvb-ie-meta-head">
|
|
154
|
+
<h2>Metadata</h2>
|
|
155
|
+
<span data-emvb-image-exif={status}>
|
|
156
|
+
<Badge variant={badge.variant}>{badge.text}</Badge>
|
|
157
|
+
</span>
|
|
158
|
+
</div>
|
|
159
|
+
{status === "error" ? (
|
|
160
|
+
<div className="emvb-ie-alert emvb-ie-alert-neutral" role="status">
|
|
161
|
+
<span>{errorText(error)}</span>
|
|
162
|
+
</div>
|
|
163
|
+
) : null}
|
|
164
|
+
<hr className="emvb-ie-rule" />
|
|
165
|
+
{rows.length ? (
|
|
166
|
+
<table className="emvb-ie-meta-table">
|
|
167
|
+
<tbody>
|
|
168
|
+
{rows.map((row) => (
|
|
169
|
+
<tr key={row.label} data-emvb-image-meta={row.label}>
|
|
170
|
+
<th scope="row">{row.label}</th>
|
|
171
|
+
<td>{row.value}</td>
|
|
172
|
+
</tr>
|
|
173
|
+
))}
|
|
174
|
+
</tbody>
|
|
175
|
+
</table>
|
|
176
|
+
) : (
|
|
177
|
+
<p className="emvb-ie-subtle">No image metadata loaded.</p>
|
|
178
|
+
)}
|
|
179
|
+
<p className="emvb-ie-meta-edits" data-emvb-image-meta-edits="">
|
|
180
|
+
<span className="emvb-ie-subtle">Edits</span> {edits}
|
|
181
|
+
</p>
|
|
182
|
+
{hasGps ? (
|
|
183
|
+
<p className="emvb-ie-meta-gps" data-emvb-image-meta-gps="">
|
|
184
|
+
<MapPinIcon aria-hidden="true" />
|
|
185
|
+
<span>
|
|
186
|
+
This photo has a location. A JPEG copy has it removed unless you turn that off when
|
|
187
|
+
saving; WebP and PNG copies keep no camera data.
|
|
188
|
+
</span>
|
|
189
|
+
</p>
|
|
190
|
+
) : null}
|
|
191
|
+
</div>
|
|
192
|
+
</section>
|
|
193
|
+
);
|
|
194
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Screen reader announcements and the plain-text summary of edits (W-487). A polite live region
|
|
3
|
+
* says which tool opened and, after a pause, what the picture's edits now are (so undo, redo and
|
|
4
|
+
* Reset all are heard too). Slider drags are not announced on every step.
|
|
5
|
+
*/
|
|
6
|
+
import * as React from "react";
|
|
7
|
+
import { summarizeImageEdit } from "../../core/image-edit/summary.ts";
|
|
8
|
+
import type { ImageEditRecipe } from "../../core/image-edit/schema.ts";
|
|
9
|
+
import { useImageEditor } from "./engine.ts";
|
|
10
|
+
import { IMAGE_EDITOR_TOOLS } from "./tools.ts";
|
|
11
|
+
|
|
12
|
+
/** How long the edits must stay unchanged before they are announced. */
|
|
13
|
+
export const ANNOUNCE_DELAY_MS = 700;
|
|
14
|
+
|
|
15
|
+
/** "Cropped · Exposure +20 · …", or "No changes", for whatever recipe the editor holds. */
|
|
16
|
+
export function editSummary(recipe: unknown): string {
|
|
17
|
+
if (!recipe || typeof recipe !== "object") return "No changes";
|
|
18
|
+
try {
|
|
19
|
+
return summarizeImageEdit(recipe as ImageEditRecipe, 12);
|
|
20
|
+
} catch {
|
|
21
|
+
return "No changes";
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function toolLabel(tool: string): string {
|
|
26
|
+
return IMAGE_EDITOR_TOOLS.find((t) => t.id === tool)?.label ?? tool;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** The current edits as text, for the Metadata panel. */
|
|
30
|
+
export function useEditSummary(): string {
|
|
31
|
+
return editSummary(useImageEditor().recipes.current);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function Announcer() {
|
|
35
|
+
const editor = useImageEditor();
|
|
36
|
+
const summary = editSummary(editor.recipes.current);
|
|
37
|
+
const tool = editor.tool;
|
|
38
|
+
const [text, setText] = React.useState("");
|
|
39
|
+
const seen = React.useRef({ tool, summary, ready: editor.isReady });
|
|
40
|
+
React.useEffect(() => {
|
|
41
|
+
if (seen.current.tool === tool) return;
|
|
42
|
+
seen.current.tool = tool;
|
|
43
|
+
setText(`${toolLabel(tool)} tool`);
|
|
44
|
+
}, [tool]);
|
|
45
|
+
React.useEffect(() => {
|
|
46
|
+
// The first summary after loading (a re-applied recipe) is part of opening, not news.
|
|
47
|
+
if (!editor.isReady) return;
|
|
48
|
+
if (!seen.current.ready) {
|
|
49
|
+
seen.current = { ...seen.current, ready: true, summary };
|
|
50
|
+
if (summary !== "No changes") setText(`Edits: ${summary}`);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (seen.current.summary === summary) return;
|
|
54
|
+
const timer = window.setTimeout(() => {
|
|
55
|
+
seen.current.summary = summary;
|
|
56
|
+
setText(`Edits: ${summary}`);
|
|
57
|
+
}, ANNOUNCE_DELAY_MS);
|
|
58
|
+
return () => window.clearTimeout(timer);
|
|
59
|
+
}, [summary, editor.isReady]);
|
|
60
|
+
return (
|
|
61
|
+
<div className="emvb-ie-sr" role="status" aria-live="polite" data-emvb-image-live="">
|
|
62
|
+
{text}
|
|
63
|
+
</div>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Crop-frame maths for the image editor's crop view (W-483).
|
|
3
|
+
*
|
|
4
|
+
* Ported from photocn's `crop-overlay.tsx` (https://github.com/rbbydotdev/photocn,
|
|
5
|
+
* apps/www/src/registry/image-editor), MIT License, Copyright (c) 2026 rbbydotdev.
|
|
6
|
+
* Split out of the component so it can be unit tested.
|
|
7
|
+
*/
|
|
8
|
+
import type { NormalizedRect, Vec2 } from "./engine.ts";
|
|
9
|
+
|
|
10
|
+
/** Maps oriented px (X, Y) to stage px: (ox + X·k, oy + Y·k). */
|
|
11
|
+
export interface StageView {
|
|
12
|
+
k: number;
|
|
13
|
+
ox: number;
|
|
14
|
+
oy: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface StageSize {
|
|
18
|
+
width: number;
|
|
19
|
+
height: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
type Size = { width: number; height: number };
|
|
23
|
+
|
|
24
|
+
/** View that fits `rect` (normalized oriented) inside the stage with padding. */
|
|
25
|
+
export function fitView(
|
|
26
|
+
rect: NormalizedRect,
|
|
27
|
+
oriented: Size,
|
|
28
|
+
stage: StageSize,
|
|
29
|
+
padding: number,
|
|
30
|
+
): StageView {
|
|
31
|
+
const rw = Math.max(1e-6, rect.width * oriented.width);
|
|
32
|
+
const rh = Math.max(1e-6, rect.height * oriented.height);
|
|
33
|
+
const k = Math.max(
|
|
34
|
+
1e-6,
|
|
35
|
+
Math.min((stage.width - padding * 2) / rw, (stage.height - padding * 2) / rh),
|
|
36
|
+
);
|
|
37
|
+
return {
|
|
38
|
+
k,
|
|
39
|
+
ox: stage.width / 2 - (rect.x * oriented.width + rw / 2) * k,
|
|
40
|
+
oy: stage.height / 2 - (rect.y * oriented.height + rh / 2) * k,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function toStage(view: StageView, oriented: Size, [x, y]: Vec2): Vec2 {
|
|
45
|
+
return [view.ox + x * oriented.width * view.k, view.oy + y * oriented.height * view.k];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function toNormalized(view: StageView, oriented: Size, [x, y]: Vec2): Vec2 {
|
|
49
|
+
return [(x - view.ox) / (oriented.width * view.k), (y - view.oy) / (oriented.height * view.k)];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function rectToStage(view: StageView, oriented: Size, rect: NormalizedRect) {
|
|
53
|
+
const [left, top] = toStage(view, oriented, [rect.x, rect.y]);
|
|
54
|
+
return {
|
|
55
|
+
left,
|
|
56
|
+
top,
|
|
57
|
+
width: rect.width * oriented.width * view.k,
|
|
58
|
+
height: rect.height * oriented.height * view.k,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Blend two views so the point under the stage center travels in a straight line and the zoom
|
|
64
|
+
* changes geometrically (no wobble).
|
|
65
|
+
*/
|
|
66
|
+
export function blendViews(from: StageView, to: StageView, stage: StageSize, t: number): StageView {
|
|
67
|
+
const cx = stage.width / 2;
|
|
68
|
+
const cy = stage.height / 2;
|
|
69
|
+
const fromX = (cx - from.ox) / from.k;
|
|
70
|
+
const fromY = (cy - from.oy) / from.k;
|
|
71
|
+
const toX = (cx - to.ox) / to.k;
|
|
72
|
+
const toY = (cy - to.oy) / to.k;
|
|
73
|
+
const k = from.k * (to.k / from.k) ** t;
|
|
74
|
+
const x = fromX + (toX - fromX) * t;
|
|
75
|
+
const y = fromY + (toY - fromY) * t;
|
|
76
|
+
return { k, ox: cx - x * k, oy: cy - y * k };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export type Handle = "n" | "s" | "e" | "w" | "ne" | "nw" | "se" | "sw";
|
|
80
|
+
|
|
81
|
+
export const HANDLES: readonly { id: Handle; label: string }[] = [
|
|
82
|
+
{ id: "nw", label: "Resize from top left" },
|
|
83
|
+
{ id: "n", label: "Resize from top" },
|
|
84
|
+
{ id: "ne", label: "Resize from top right" },
|
|
85
|
+
{ id: "e", label: "Resize from right" },
|
|
86
|
+
{ id: "se", label: "Resize from bottom right" },
|
|
87
|
+
{ id: "s", label: "Resize from bottom" },
|
|
88
|
+
{ id: "sw", label: "Resize from bottom left" },
|
|
89
|
+
{ id: "w", label: "Resize from left" },
|
|
90
|
+
];
|
|
91
|
+
|
|
92
|
+
export type PxRect = { x: number; y: number; w: number; h: number };
|
|
93
|
+
|
|
94
|
+
/** Resize a px rect by a pointer delta from one handle, honoring a locked ratio. */
|
|
95
|
+
export function resizeRect(
|
|
96
|
+
start: PxRect,
|
|
97
|
+
handle: Handle,
|
|
98
|
+
dx: number,
|
|
99
|
+
dy: number,
|
|
100
|
+
ratio: number | null,
|
|
101
|
+
min: number,
|
|
102
|
+
): PxRect {
|
|
103
|
+
let { x, y, w, h } = start;
|
|
104
|
+
const east = handle.includes("e");
|
|
105
|
+
const west = handle.includes("w");
|
|
106
|
+
const north = handle.includes("n");
|
|
107
|
+
const south = handle.includes("s");
|
|
108
|
+
|
|
109
|
+
if (!ratio) {
|
|
110
|
+
if (east) w = Math.max(min, start.w + dx);
|
|
111
|
+
if (west) {
|
|
112
|
+
w = Math.max(min, start.w - dx);
|
|
113
|
+
x = start.x + start.w - w;
|
|
114
|
+
}
|
|
115
|
+
if (south) h = Math.max(min, start.h + dy);
|
|
116
|
+
if (north) {
|
|
117
|
+
h = Math.max(min, start.h - dy);
|
|
118
|
+
y = start.y + start.h - h;
|
|
119
|
+
}
|
|
120
|
+
return { x, y, w, h };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const isCorner = (east || west) && (north || south);
|
|
124
|
+
if (isCorner) {
|
|
125
|
+
// Follow whichever axis moved more, keep the opposite corner anchored.
|
|
126
|
+
const dw = east ? dx : -dx;
|
|
127
|
+
const dh = south ? dy : -dy;
|
|
128
|
+
w = Math.max(min, Math.abs(dw) >= Math.abs(dh * ratio) ? start.w + dw : start.w + dh * ratio);
|
|
129
|
+
h = w / ratio;
|
|
130
|
+
if (h < min) {
|
|
131
|
+
h = min;
|
|
132
|
+
w = h * ratio;
|
|
133
|
+
}
|
|
134
|
+
x = west ? start.x + start.w - w : start.x;
|
|
135
|
+
y = north ? start.y + start.h - h : start.y;
|
|
136
|
+
} else if (east || west) {
|
|
137
|
+
// W-693: the other side keeps the minimum too (a wide ratio made a sliver of a height).
|
|
138
|
+
w = Math.max(min, min * ratio, start.w + (east ? dx : -dx));
|
|
139
|
+
h = w / ratio;
|
|
140
|
+
x = west ? start.x + start.w - w : start.x;
|
|
141
|
+
y = start.y + start.h / 2 - h / 2;
|
|
142
|
+
} else {
|
|
143
|
+
h = Math.max(min, min / ratio, start.h + (south ? dy : -dy));
|
|
144
|
+
w = h * ratio;
|
|
145
|
+
y = north ? start.y + start.h - h : start.y;
|
|
146
|
+
x = start.x + start.w / 2 - w / 2;
|
|
147
|
+
}
|
|
148
|
+
return { x, y, w, h };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** Largest t in [0, 1] for which `candidate(t)` is valid (binary search). */
|
|
152
|
+
export function constrain<T>(candidate: (t: number) => T, valid: (value: T) => boolean): T {
|
|
153
|
+
if (valid(candidate(1))) return candidate(1);
|
|
154
|
+
let lo = 0;
|
|
155
|
+
let hi = 1;
|
|
156
|
+
for (let i = 0; i < 24; i++) {
|
|
157
|
+
const mid = (lo + hi) / 2;
|
|
158
|
+
if (valid(candidate(mid))) lo = mid;
|
|
159
|
+
else hi = mid;
|
|
160
|
+
}
|
|
161
|
+
return candidate(lo);
|
|
162
|
+
}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tone-curve maths for the Curves panel (W-484): the smooth path, point insertion, moves and
|
|
3
|
+
* removal, plus the keyboard nudges EmVB adds.
|
|
4
|
+
*
|
|
5
|
+
* Ported from photocn's `curves-panel.tsx` (https://github.com/rbbydotdev/photocn,
|
|
6
|
+
* apps/www/src/registry/image-editor), MIT License, Copyright (c) 2026 rbbydotdev.
|
|
7
|
+
*/
|
|
8
|
+
import type { CurveChannels, CurvePoint } from "./engine.ts";
|
|
9
|
+
|
|
10
|
+
export type CurvesChannel = "rgb" | "r" | "g" | "b";
|
|
11
|
+
export const CHANNEL_ORDER: readonly CurvesChannel[] = ["rgb", "r", "g", "b"];
|
|
12
|
+
export const CHANNEL_INDEX: Record<CurvesChannel, 0 | 1 | 2 | 3> = { rgb: 0, r: 1, g: 2, b: 3 };
|
|
13
|
+
|
|
14
|
+
/** Handles on the quarter grid, on y = x, so there is something to drag before any click. */
|
|
15
|
+
export const IDENTITY_POINTS: readonly CurvePoint[] = [
|
|
16
|
+
[0, 0],
|
|
17
|
+
[0.25, 0.25],
|
|
18
|
+
[0.5, 0.5],
|
|
19
|
+
[0.75, 0.75],
|
|
20
|
+
[1, 1],
|
|
21
|
+
];
|
|
22
|
+
/** One byte of LUT precision: neighbours never collide. */
|
|
23
|
+
export const POINT_EPSILON = 1 / 255;
|
|
24
|
+
/** The image edit record keeps at most 32 points per channel (W-481). */
|
|
25
|
+
export const MAX_CURVE_POINTS = 32;
|
|
26
|
+
|
|
27
|
+
const clamp = (v: number, lo: number, hi: number) => Math.min(hi, Math.max(lo, v));
|
|
28
|
+
const at = (a: number[], i: number) => a[i] ?? 0;
|
|
29
|
+
const sortPoints = (points: readonly CurvePoint[]): CurvePoint[] =>
|
|
30
|
+
points.map((p): CurvePoint => [p[0], p[1]]).toSorted((a, b) => a[0] - b[0]);
|
|
31
|
+
|
|
32
|
+
export function getActivePoints(value: CurveChannels | null, channel: CurvesChannel): CurvePoint[] {
|
|
33
|
+
const existing = value?.[CHANNEL_INDEX[channel]];
|
|
34
|
+
return sortPoints(existing && existing.length >= 2 ? existing : IDENTITY_POINTS);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Every point on y = x. */
|
|
38
|
+
export function isIdentity(points: readonly CurvePoint[] | null | undefined): boolean {
|
|
39
|
+
return !points || points.every(([x, y]) => Math.abs(y - x) < POINT_EPSILON);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function hasAnyEdits(value: CurveChannels | null): boolean {
|
|
43
|
+
return Boolean(value?.some((channel) => channel !== null && !isIdentity(channel)));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** `value` with one channel's points replaced. */
|
|
47
|
+
export function withChannel(
|
|
48
|
+
value: CurveChannels | null,
|
|
49
|
+
channel: CurvesChannel,
|
|
50
|
+
points: CurvePoint[],
|
|
51
|
+
): CurveChannels {
|
|
52
|
+
const next: CurveChannels = value
|
|
53
|
+
? [value[0], value[1], value[2], value[3]]
|
|
54
|
+
: [null, null, null, null];
|
|
55
|
+
next[CHANNEL_INDEX[channel]] = points;
|
|
56
|
+
return next;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** A monotonic cubic (Fritsch–Carlson) through the points: smooth, never overshooting. */
|
|
60
|
+
export function buildSmoothPath(points: readonly CurvePoint[], size: number): string {
|
|
61
|
+
if (points.length < 2) return "";
|
|
62
|
+
const sorted = sortPoints(points);
|
|
63
|
+
const n = sorted.length;
|
|
64
|
+
const xs = sorted.map((p) => p[0]);
|
|
65
|
+
const ys = sorted.map((p) => p[1]);
|
|
66
|
+
const dx: number[] = [];
|
|
67
|
+
const slopes: number[] = [];
|
|
68
|
+
for (let i = 0; i < n - 1; i++) {
|
|
69
|
+
dx[i] = at(xs, i + 1) - at(xs, i) || 1e-9;
|
|
70
|
+
slopes[i] = (at(ys, i + 1) - at(ys, i)) / at(dx, i);
|
|
71
|
+
}
|
|
72
|
+
const t: number[] = [];
|
|
73
|
+
t[0] = at(slopes, 0);
|
|
74
|
+
t[n - 1] = at(slopes, n - 2);
|
|
75
|
+
for (let i = 1; i < n - 1; i++) {
|
|
76
|
+
const a = at(slopes, i - 1);
|
|
77
|
+
const b = at(slopes, i);
|
|
78
|
+
t[i] = a * b <= 0 ? 0 : (a + b) / 2;
|
|
79
|
+
}
|
|
80
|
+
for (let i = 0; i < n - 1; i++) {
|
|
81
|
+
const s = at(slopes, i);
|
|
82
|
+
if (s === 0) {
|
|
83
|
+
t[i] = 0;
|
|
84
|
+
t[i + 1] = 0;
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
const a = at(t, i) / s;
|
|
88
|
+
const b = at(t, i + 1) / s;
|
|
89
|
+
const h = a * a + b * b;
|
|
90
|
+
if (h > 9) {
|
|
91
|
+
const k = 3 / Math.sqrt(h);
|
|
92
|
+
t[i] = k * a * s;
|
|
93
|
+
t[i + 1] = k * b * s;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const sx = (x: number) => (x * size).toFixed(2);
|
|
97
|
+
const sy = (y: number) => (size - y * size).toFixed(2);
|
|
98
|
+
let d = `M ${sx(at(xs, 0))} ${sy(at(ys, 0))}`;
|
|
99
|
+
for (let i = 0; i < n - 1; i++) {
|
|
100
|
+
const h = at(dx, i);
|
|
101
|
+
const x0 = at(xs, i);
|
|
102
|
+
const x1 = at(xs, i + 1);
|
|
103
|
+
const y0 = at(ys, i);
|
|
104
|
+
const y1 = at(ys, i + 1);
|
|
105
|
+
d += ` C ${sx(x0 + h / 3)} ${sy(y0 + (at(t, i) * h) / 3)}, ${sx(x1 - h / 3)} ${sy(y1 - (at(t, i + 1) * h) / 3)}, ${sx(x1)} ${sy(y1)}`;
|
|
106
|
+
}
|
|
107
|
+
return d;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Straight-line y at x between the neighbouring points, so a new point starts on the curve. */
|
|
111
|
+
function interpolateY(points: readonly CurvePoint[], x: number): number {
|
|
112
|
+
const first = points[0];
|
|
113
|
+
const last = points.at(-1);
|
|
114
|
+
if (!first || !last) return x;
|
|
115
|
+
if (x <= first[0]) return first[1];
|
|
116
|
+
if (x >= last[0]) return last[1];
|
|
117
|
+
for (let i = 0; i < points.length - 1; i++) {
|
|
118
|
+
const a = points[i];
|
|
119
|
+
const b = points[i + 1];
|
|
120
|
+
if (a && b && x >= a[0] && x <= b[0])
|
|
121
|
+
return a[1] + ((x - a[0]) / (b[0] - a[0] || 1)) * (b[1] - a[1]);
|
|
122
|
+
}
|
|
123
|
+
return x;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Adds a point (on the curve unless `y` is given); null when the channel is full. */
|
|
127
|
+
export function insertPoint(
|
|
128
|
+
points: readonly CurvePoint[],
|
|
129
|
+
x: number,
|
|
130
|
+
y?: number,
|
|
131
|
+
): { points: CurvePoint[]; index: number } | null {
|
|
132
|
+
if (points.length >= MAX_CURVE_POINTS) return null;
|
|
133
|
+
const sorted = sortPoints(points);
|
|
134
|
+
const lo = POINT_EPSILON;
|
|
135
|
+
const hi = 1 - POINT_EPSILON;
|
|
136
|
+
let ix = clamp(x, lo, hi);
|
|
137
|
+
while (sorted.some((p) => Math.abs(p[0] - ix) < POINT_EPSILON / 2)) {
|
|
138
|
+
ix = clamp(ix + POINT_EPSILON, lo, hi);
|
|
139
|
+
if (ix >= hi) break;
|
|
140
|
+
}
|
|
141
|
+
const point: CurvePoint = [ix, clamp(y ?? interpolateY(sorted, ix), 0, 1)];
|
|
142
|
+
const next = sortPoints([...sorted, point]);
|
|
143
|
+
return { points: next, index: next.findIndex((p) => p[0] === ix) };
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** Moves one point, keeping it between its neighbours; the end points only move up and down. */
|
|
147
|
+
export function movePoint(
|
|
148
|
+
points: readonly CurvePoint[],
|
|
149
|
+
index: number,
|
|
150
|
+
x: number,
|
|
151
|
+
y: number,
|
|
152
|
+
): CurvePoint[] {
|
|
153
|
+
const next = sortPoints(points);
|
|
154
|
+
const last = next.length - 1;
|
|
155
|
+
if (index < 0 || index > last) return next;
|
|
156
|
+
const prev = next[index - 1];
|
|
157
|
+
const after = next[index + 1];
|
|
158
|
+
const nx =
|
|
159
|
+
index === 0
|
|
160
|
+
? 0
|
|
161
|
+
: index === last
|
|
162
|
+
? 1
|
|
163
|
+
: clamp(x, (prev?.[0] ?? 0) + POINT_EPSILON, (after?.[0] ?? 1) - POINT_EPSILON);
|
|
164
|
+
next[index] = [nx, clamp(y, 0, 1)];
|
|
165
|
+
return next;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** Removes a point; null for the two end points, which hold the curve's ends. */
|
|
169
|
+
export function removePoint(points: readonly CurvePoint[], index: number): CurvePoint[] | null {
|
|
170
|
+
const sorted = sortPoints(points);
|
|
171
|
+
if (index <= 0 || index >= sorted.length - 1) return null;
|
|
172
|
+
return sorted.filter((_, i) => i !== index);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** 0..1 as the 0..255 level photo apps show. */
|
|
176
|
+
export const toLevel = (v: number) => Math.round(clamp(v, 0, 1) * 255);
|
|
177
|
+
export const fromLevel = (level: number) => clamp(level, 0, 255) / 255;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* photocn's main-thread export encodes with `canvas.toDataURL()` and reads
|
|
3
|
+
* it back with `fetch(dataUrl)`. The `/_emdash` CSP has `connect-src 'self'`,
|
|
4
|
+
* which blocks `fetch("data:…")`, so main-thread exports fail in the admin.
|
|
5
|
+
* While an export runs we answer `data:` fetches locally; every other
|
|
6
|
+
* request goes to the real `fetch` untouched. (W-480 finding; upstream ask:
|
|
7
|
+
* use `canvas.toBlob()`.)
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export function decodeDataUrl(url: string): Response | null {
|
|
11
|
+
const match = /^data:([^,]*?),(.*)$/s.exec(url);
|
|
12
|
+
if (!match) return null;
|
|
13
|
+
const meta = match[1] ?? "";
|
|
14
|
+
const body = match[2] ?? "";
|
|
15
|
+
const base64 = /;base64$/i.test(meta);
|
|
16
|
+
const type = (base64 ? meta.slice(0, -7) : meta) || "text/plain";
|
|
17
|
+
let bytes: Uint8Array<ArrayBuffer>;
|
|
18
|
+
if (base64) {
|
|
19
|
+
const bin = atob(body);
|
|
20
|
+
bytes = new Uint8Array(bin.length);
|
|
21
|
+
for (let i = 0; i < bin.length; i++) bytes[i] = bin.charCodeAt(i);
|
|
22
|
+
} else {
|
|
23
|
+
bytes = new TextEncoder().encode(decodeURIComponent(body)) as Uint8Array<ArrayBuffer>;
|
|
24
|
+
}
|
|
25
|
+
return new Response(new Blob([bytes], { type }), {
|
|
26
|
+
status: 200,
|
|
27
|
+
headers: { "content-type": type },
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let depth = 0;
|
|
32
|
+
let realFetch: typeof fetch | undefined;
|
|
33
|
+
|
|
34
|
+
/** Run `task` with `data:` fetches served locally. Nested calls share one shim. */
|
|
35
|
+
export async function withDataUrlFetch<T>(
|
|
36
|
+
task: () => Promise<T>,
|
|
37
|
+
g: typeof globalThis = globalThis,
|
|
38
|
+
): Promise<T> {
|
|
39
|
+
if (depth++ === 0) {
|
|
40
|
+
realFetch = g.fetch;
|
|
41
|
+
const original = realFetch;
|
|
42
|
+
g.fetch = ((input: RequestInfo | URL, init?: RequestInit) => {
|
|
43
|
+
const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
44
|
+
if (url.startsWith("data:")) {
|
|
45
|
+
const res = decodeDataUrl(url);
|
|
46
|
+
if (res) return Promise.resolve(res);
|
|
47
|
+
}
|
|
48
|
+
return original.call(g, input, init);
|
|
49
|
+
}) as typeof fetch;
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
return await task();
|
|
53
|
+
} finally {
|
|
54
|
+
if (--depth === 0 && realFetch) {
|
|
55
|
+
g.fetch = realFetch;
|
|
56
|
+
realFetch = undefined;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|