@fleox/agentphoto 0.0.0-stage → 0.1.1
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/LICENSE +143 -0
- package/README.md +334 -2
- package/changelog.json +35 -0
- package/dist/agent/agentphoto.mjs +3354 -0
- package/dist/agent/chunks/assets-BZVUUHjg.mjs +151 -0
- package/dist/agent/chunks/catalog-DIZ5dnH5.mjs +953 -0
- package/dist/agent/chunks/context-CNpRboiC.mjs +75 -0
- package/dist/agent/chunks/doc-D_v_yE07.mjs +512 -0
- package/dist/agent/chunks/export-aNJcPNbJ.mjs +140 -0
- package/dist/agent/chunks/geometry-BKIhUO9x.mjs +315 -0
- package/dist/agent/chunks/ids-DAmiNwd9.mjs +28 -0
- package/dist/agent/chunks/imageInfo-QxAfu8R6.mjs +173 -0
- package/dist/agent/chunks/jsonPath-B7vAPXsi.mjs +155 -0
- package/dist/agent/chunks/library-C_EXiphj.mjs +16 -0
- package/dist/agent/chunks/models-CxrjmA0W.mjs +387 -0
- package/dist/agent/chunks/output-3F12IR9O.mjs +130 -0
- package/dist/agent/chunks/package-Cu1GyvKL.mjs +71 -0
- package/dist/agent/chunks/project-o1DH2nOw.mjs +200 -0
- package/dist/agent/chunks/rolldown-runtime-CMQPkI6i.mjs +18 -0
- package/dist/agent/chunks/server-I0trf5tM.mjs +241 -0
- package/dist/agent/chunks/templates-BJ2me4XZ.mjs +61 -0
- package/dist/agent/chunks/tools-DKaAPEV5.mjs +1419 -0
- package/dist/agent/chunks/tree-D8qZKPAb.mjs +127 -0
- package/dist/agent/chunks/types-DOK7tAAu.mjs +30 -0
- package/dist/agent/chunks/validate-CXPFB-i6.mjs +936 -0
- package/dist/engine/agentphoto-engine.js +2833 -0
- package/dist/engine/chunks/transformers.web-D5Vsg6-A.js +18494 -0
- package/dist/engine/ort/ort-wasm-simd-threaded.asyncify.mjs +124 -0
- package/dist/engine/ort/ort-wasm-simd-threaded.asyncify.wasm +0 -0
- package/dist/studio/assets/index-CmOzzoXv.css +1 -0
- package/dist/studio/assets/index-D3Iw5q8v.js +28 -0
- package/dist/studio/assets/transformers.web-osEqoMhg.js +38 -0
- package/dist/studio/index.html +15 -0
- package/dist/studio/library/LICENSES.md +57 -0
- package/dist/studio/library/fonts/OFL.txt +90 -0
- package/dist/studio/library/fonts/anton/anton-latin-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/anton/anton-latin-ext-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/archivo-black/archivo-black-latin-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/archivo-black/archivo-black-latin-ext-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/bebas-neue/bebas-neue-latin-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/bebas-neue/bebas-neue-latin-ext-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/caveat/caveat-latin-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/caveat/caveat-latin-700-normal.woff2 +0 -0
- package/dist/studio/library/fonts/caveat/caveat-latin-ext-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/caveat/caveat-latin-ext-700-normal.woff2 +0 -0
- package/dist/studio/library/fonts/dm-serif/dm-serif-display-latin-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/dm-serif/dm-serif-display-latin-ext-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/inter/inter-latin-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/inter/inter-latin-600-normal.woff2 +0 -0
- package/dist/studio/library/fonts/inter/inter-latin-700-normal.woff2 +0 -0
- package/dist/studio/library/fonts/inter/inter-latin-800-normal.woff2 +0 -0
- package/dist/studio/library/fonts/inter/inter-latin-ext-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/inter/inter-latin-ext-600-normal.woff2 +0 -0
- package/dist/studio/library/fonts/inter/inter-latin-ext-700-normal.woff2 +0 -0
- package/dist/studio/library/fonts/inter/inter-latin-ext-800-normal.woff2 +0 -0
- package/dist/studio/library/fonts/jetbrains-mono/jetbrains-mono-latin-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/jetbrains-mono/jetbrains-mono-latin-700-normal.woff2 +0 -0
- package/dist/studio/library/fonts/jetbrains-mono/jetbrains-mono-latin-ext-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/jetbrains-mono/jetbrains-mono-latin-ext-700-normal.woff2 +0 -0
- package/dist/studio/library/fonts/lobster/lobster-latin-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/lobster/lobster-latin-ext-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/montserrat/montserrat-latin-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/montserrat/montserrat-latin-700-normal.woff2 +0 -0
- package/dist/studio/library/fonts/montserrat/montserrat-latin-800-normal.woff2 +0 -0
- package/dist/studio/library/fonts/montserrat/montserrat-latin-ext-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/montserrat/montserrat-latin-ext-700-normal.woff2 +0 -0
- package/dist/studio/library/fonts/montserrat/montserrat-latin-ext-800-normal.woff2 +0 -0
- package/dist/studio/library/fonts/oswald/oswald-latin-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/oswald/oswald-latin-600-normal.woff2 +0 -0
- package/dist/studio/library/fonts/oswald/oswald-latin-ext-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/oswald/oswald-latin-ext-600-normal.woff2 +0 -0
- package/dist/studio/library/fonts/pacifico/pacifico-latin-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/pacifico/pacifico-latin-ext-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/playfair/playfair-display-latin-400-italic.woff2 +0 -0
- package/dist/studio/library/fonts/playfair/playfair-display-latin-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/playfair/playfair-display-latin-700-normal.woff2 +0 -0
- package/dist/studio/library/fonts/playfair/playfair-display-latin-ext-400-italic.woff2 +0 -0
- package/dist/studio/library/fonts/playfair/playfair-display-latin-ext-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/playfair/playfair-display-latin-ext-700-normal.woff2 +0 -0
- package/dist/studio/library/fonts/poppins/poppins-latin-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/poppins/poppins-latin-600-normal.woff2 +0 -0
- package/dist/studio/library/fonts/poppins/poppins-latin-700-normal.woff2 +0 -0
- package/dist/studio/library/fonts/poppins/poppins-latin-ext-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/poppins/poppins-latin-ext-600-normal.woff2 +0 -0
- package/dist/studio/library/fonts/poppins/poppins-latin-ext-700-normal.woff2 +0 -0
- package/dist/studio/library/fonts/roboto-slab/LICENSE.txt +202 -0
- package/dist/studio/library/fonts/roboto-slab/roboto-slab-latin-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/roboto-slab/roboto-slab-latin-700-normal.woff2 +0 -0
- package/dist/studio/library/fonts/roboto-slab/roboto-slab-latin-ext-400-normal.woff2 +0 -0
- package/dist/studio/library/fonts/roboto-slab/roboto-slab-latin-ext-700-normal.woff2 +0 -0
- package/dist/studio/library/fonts/space-grotesk/space-grotesk-latin-500-normal.woff2 +0 -0
- package/dist/studio/library/fonts/space-grotesk/space-grotesk-latin-700-normal.woff2 +0 -0
- package/dist/studio/library/fonts/space-grotesk/space-grotesk-latin-ext-500-normal.woff2 +0 -0
- package/dist/studio/library/fonts/space-grotesk/space-grotesk-latin-ext-700-normal.woff2 +0 -0
- package/dist/studio/library/images/city.jpg +0 -0
- package/dist/studio/library/images/food.jpg +0 -0
- package/dist/studio/library/images/landscape.jpg +0 -0
- package/dist/studio/library/images/pet.jpg +0 -0
- package/dist/studio/library/images/portrait.jpg +0 -0
- package/dist/studio/library/images/product.jpg +0 -0
- package/dist/studio/library/index.json +752 -0
- package/dist/studio/templates/avatar-pro/assets/masks/photo-cutout.png +0 -0
- package/dist/studio/templates/avatar-pro/photo.json +13 -0
- package/dist/studio/templates/avatar-pro/preview.jpg +0 -0
- package/dist/studio/templates/avatar-pro/template.json +1 -0
- package/dist/studio/templates/index.json +1 -0
- package/dist/studio/templates/og-article/photo.json +13 -0
- package/dist/studio/templates/og-article/preview.jpg +0 -0
- package/dist/studio/templates/og-article/template.json +1 -0
- package/dist/studio/templates/polaroid/photo.json +13 -0
- package/dist/studio/templates/polaroid/preview.jpg +0 -0
- package/dist/studio/templates/polaroid/template.json +1 -0
- package/dist/studio/templates/product-white/assets/masks/photo-cutout.png +0 -0
- package/dist/studio/templates/product-white/photo.json +72 -0
- package/dist/studio/templates/product-white/preview.jpg +0 -0
- package/dist/studio/templates/product-white/template.json +1 -0
- package/dist/studio/templates/sale-banner/photo.json +125 -0
- package/dist/studio/templates/sale-banner/preview.jpg +0 -0
- package/dist/studio/templates/sale-banner/template.json +1 -0
- package/dist/studio/templates/social-quote/photo.json +13 -0
- package/dist/studio/templates/social-quote/preview.jpg +0 -0
- package/dist/studio/templates/social-quote/template.json +1 -0
- package/dist/studio/templates/story-promo/photo.json +13 -0
- package/dist/studio/templates/story-promo/preview.jpg +0 -0
- package/dist/studio/templates/story-promo/template.json +1 -0
- package/dist/studio/templates/youtube-thumbnail/photo.json +12 -0
- package/dist/studio/templates/youtube-thumbnail/preview.jpg +0 -0
- package/dist/studio/templates/youtube-thumbnail/template.json +1 -0
- package/library/LICENSES.md +57 -0
- package/library/fonts/OFL.txt +90 -0
- package/library/fonts/anton/anton-latin-400-normal.woff2 +0 -0
- package/library/fonts/anton/anton-latin-ext-400-normal.woff2 +0 -0
- package/library/fonts/archivo-black/archivo-black-latin-400-normal.woff2 +0 -0
- package/library/fonts/archivo-black/archivo-black-latin-ext-400-normal.woff2 +0 -0
- package/library/fonts/bebas-neue/bebas-neue-latin-400-normal.woff2 +0 -0
- package/library/fonts/bebas-neue/bebas-neue-latin-ext-400-normal.woff2 +0 -0
- package/library/fonts/caveat/caveat-latin-400-normal.woff2 +0 -0
- package/library/fonts/caveat/caveat-latin-700-normal.woff2 +0 -0
- package/library/fonts/caveat/caveat-latin-ext-400-normal.woff2 +0 -0
- package/library/fonts/caveat/caveat-latin-ext-700-normal.woff2 +0 -0
- package/library/fonts/dm-serif/dm-serif-display-latin-400-normal.woff2 +0 -0
- package/library/fonts/dm-serif/dm-serif-display-latin-ext-400-normal.woff2 +0 -0
- package/library/fonts/inter/inter-latin-400-normal.woff2 +0 -0
- package/library/fonts/inter/inter-latin-600-normal.woff2 +0 -0
- package/library/fonts/inter/inter-latin-700-normal.woff2 +0 -0
- package/library/fonts/inter/inter-latin-800-normal.woff2 +0 -0
- package/library/fonts/inter/inter-latin-ext-400-normal.woff2 +0 -0
- package/library/fonts/inter/inter-latin-ext-600-normal.woff2 +0 -0
- package/library/fonts/inter/inter-latin-ext-700-normal.woff2 +0 -0
- package/library/fonts/inter/inter-latin-ext-800-normal.woff2 +0 -0
- package/library/fonts/jetbrains-mono/jetbrains-mono-latin-400-normal.woff2 +0 -0
- package/library/fonts/jetbrains-mono/jetbrains-mono-latin-700-normal.woff2 +0 -0
- package/library/fonts/jetbrains-mono/jetbrains-mono-latin-ext-400-normal.woff2 +0 -0
- package/library/fonts/jetbrains-mono/jetbrains-mono-latin-ext-700-normal.woff2 +0 -0
- package/library/fonts/lobster/lobster-latin-400-normal.woff2 +0 -0
- package/library/fonts/lobster/lobster-latin-ext-400-normal.woff2 +0 -0
- package/library/fonts/montserrat/montserrat-latin-400-normal.woff2 +0 -0
- package/library/fonts/montserrat/montserrat-latin-700-normal.woff2 +0 -0
- package/library/fonts/montserrat/montserrat-latin-800-normal.woff2 +0 -0
- package/library/fonts/montserrat/montserrat-latin-ext-400-normal.woff2 +0 -0
- package/library/fonts/montserrat/montserrat-latin-ext-700-normal.woff2 +0 -0
- package/library/fonts/montserrat/montserrat-latin-ext-800-normal.woff2 +0 -0
- package/library/fonts/oswald/oswald-latin-400-normal.woff2 +0 -0
- package/library/fonts/oswald/oswald-latin-600-normal.woff2 +0 -0
- package/library/fonts/oswald/oswald-latin-ext-400-normal.woff2 +0 -0
- package/library/fonts/oswald/oswald-latin-ext-600-normal.woff2 +0 -0
- package/library/fonts/pacifico/pacifico-latin-400-normal.woff2 +0 -0
- package/library/fonts/pacifico/pacifico-latin-ext-400-normal.woff2 +0 -0
- package/library/fonts/playfair/playfair-display-latin-400-italic.woff2 +0 -0
- package/library/fonts/playfair/playfair-display-latin-400-normal.woff2 +0 -0
- package/library/fonts/playfair/playfair-display-latin-700-normal.woff2 +0 -0
- package/library/fonts/playfair/playfair-display-latin-ext-400-italic.woff2 +0 -0
- package/library/fonts/playfair/playfair-display-latin-ext-400-normal.woff2 +0 -0
- package/library/fonts/playfair/playfair-display-latin-ext-700-normal.woff2 +0 -0
- package/library/fonts/poppins/poppins-latin-400-normal.woff2 +0 -0
- package/library/fonts/poppins/poppins-latin-600-normal.woff2 +0 -0
- package/library/fonts/poppins/poppins-latin-700-normal.woff2 +0 -0
- package/library/fonts/poppins/poppins-latin-ext-400-normal.woff2 +0 -0
- package/library/fonts/poppins/poppins-latin-ext-600-normal.woff2 +0 -0
- package/library/fonts/poppins/poppins-latin-ext-700-normal.woff2 +0 -0
- package/library/fonts/roboto-slab/LICENSE.txt +202 -0
- package/library/fonts/roboto-slab/roboto-slab-latin-400-normal.woff2 +0 -0
- package/library/fonts/roboto-slab/roboto-slab-latin-700-normal.woff2 +0 -0
- package/library/fonts/roboto-slab/roboto-slab-latin-ext-400-normal.woff2 +0 -0
- package/library/fonts/roboto-slab/roboto-slab-latin-ext-700-normal.woff2 +0 -0
- package/library/fonts/space-grotesk/space-grotesk-latin-500-normal.woff2 +0 -0
- package/library/fonts/space-grotesk/space-grotesk-latin-700-normal.woff2 +0 -0
- package/library/fonts/space-grotesk/space-grotesk-latin-ext-500-normal.woff2 +0 -0
- package/library/fonts/space-grotesk/space-grotesk-latin-ext-700-normal.woff2 +0 -0
- package/library/images/city.jpg +0 -0
- package/library/images/food.jpg +0 -0
- package/library/images/landscape.jpg +0 -0
- package/library/images/pet.jpg +0 -0
- package/library/images/portrait.jpg +0 -0
- package/library/images/product.jpg +0 -0
- package/library/index.json +752 -0
- package/package.json +65 -4
- package/plugin/.claude-plugin/plugin.json +19 -0
- package/plugin/skills/agentphoto-cutout/SKILL.md +137 -0
- package/plugin/skills/agentphoto-design/SKILL.md +104 -0
- package/plugin/skills/agentphoto-design/references/layouts.md +60 -0
- package/plugin/skills/agentphoto-publish/SKILL.md +79 -0
- package/plugin/skills/agentphoto-retouch/SKILL.md +144 -0
- package/plugin/skills/agentphoto-retouch/references/filters.md +51 -0
- package/plugin/skills/agentphoto-retouch/references/patch-ops.md +67 -0
- package/plugin/skills/agentphoto-retouch/references/recipes.md +129 -0
- package/templates/avatar-pro/assets/masks/photo-cutout.png +0 -0
- package/templates/avatar-pro/photo.json +13 -0
- package/templates/avatar-pro/preview.jpg +0 -0
- package/templates/avatar-pro/template.json +1 -0
- package/templates/og-article/photo.json +13 -0
- package/templates/og-article/preview.jpg +0 -0
- package/templates/og-article/template.json +1 -0
- package/templates/polaroid/photo.json +13 -0
- package/templates/polaroid/preview.jpg +0 -0
- package/templates/polaroid/template.json +1 -0
- package/templates/product-white/assets/masks/photo-cutout.png +0 -0
- package/templates/product-white/photo.json +72 -0
- package/templates/product-white/preview.jpg +0 -0
- package/templates/product-white/template.json +1 -0
- package/templates/sale-banner/photo.json +125 -0
- package/templates/sale-banner/preview.jpg +0 -0
- package/templates/sale-banner/template.json +1 -0
- package/templates/social-quote/photo.json +13 -0
- package/templates/social-quote/preview.jpg +0 -0
- package/templates/social-quote/template.json +1 -0
- package/templates/story-promo/photo.json +13 -0
- package/templates/story-promo/preview.jpg +0 -0
- package/templates/story-promo/template.json +1 -0
- package/templates/youtube-thumbnail/photo.json +12 -0
- package/templates/youtube-thumbnail/preview.jpg +0 -0
- package/templates/youtube-thumbnail/template.json +1 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { createRequire as __apRequire } from "node:module";
|
|
2
|
+
import { fileURLToPath as __apPath } from "node:url";
|
|
3
|
+
import { dirname as __apDirname } from "node:path";
|
|
4
|
+
__apRequire(import.meta.url);
|
|
5
|
+
const __filename = __apPath(import.meta.url);
|
|
6
|
+
__apDirname(__filename);
|
|
7
|
+
import { t as __exportAll } from "./rolldown-runtime-CMQPkI6i.mjs";
|
|
8
|
+
import { d as sizePreset, s as SIZE_PRESETS } from "./catalog-DIZ5dnH5.mjs";
|
|
9
|
+
import { l as didYouMean, o as isValidColor, s as parseColor, t as MAX_CANVAS } from "./validate-CXPFB-i6.mjs";
|
|
10
|
+
import { r as OpsError } from "./context-CNpRboiC.mjs";
|
|
11
|
+
// src/ops/export.ts
|
|
12
|
+
var export_exports = /* @__PURE__ */ __exportAll({
|
|
13
|
+
DEFAULT_QUALITY: () => DEFAULT_QUALITY,
|
|
14
|
+
FORMAT_EXT: () => FORMAT_EXT,
|
|
15
|
+
IMAGE_FORMATS: () => IMAGE_FORMATS,
|
|
16
|
+
planExport: () => planExport
|
|
17
|
+
});
|
|
18
|
+
var IMAGE_FORMATS = [
|
|
19
|
+
"png",
|
|
20
|
+
"jpeg",
|
|
21
|
+
"webp",
|
|
22
|
+
"avif"
|
|
23
|
+
];
|
|
24
|
+
var FORMAT_EXT = {
|
|
25
|
+
png: "png",
|
|
26
|
+
jpeg: "jpg",
|
|
27
|
+
webp: "webp",
|
|
28
|
+
avif: "avif"
|
|
29
|
+
};
|
|
30
|
+
var DEFAULT_QUALITY = {
|
|
31
|
+
png: 100,
|
|
32
|
+
jpeg: 88,
|
|
33
|
+
webp: 86,
|
|
34
|
+
avif: 70
|
|
35
|
+
};
|
|
36
|
+
function planExport(doc, req = {}) {
|
|
37
|
+
const d = {
|
|
38
|
+
...doc.export ?? {},
|
|
39
|
+
...stripUndefined(req)
|
|
40
|
+
};
|
|
41
|
+
const format = d.format ?? "png";
|
|
42
|
+
if (!IMAGE_FORMATS.includes(format)) throw new OpsError("invalid", `Unknown export format "${String(d.format)}".`, `${didYouMean(String(d.format), IMAGE_FORMATS)}Formats: ${IMAGE_FORMATS.join(", ")}.`);
|
|
43
|
+
const quality = Math.max(1, Math.min(100, Math.round(d.quality ?? DEFAULT_QUALITY[format])));
|
|
44
|
+
const W = doc.canvas.width;
|
|
45
|
+
const H = doc.canvas.height;
|
|
46
|
+
let outW = W;
|
|
47
|
+
let outH = H;
|
|
48
|
+
let fit = d.fit ?? "cover";
|
|
49
|
+
if (![
|
|
50
|
+
"cover",
|
|
51
|
+
"contain",
|
|
52
|
+
"stretch"
|
|
53
|
+
].includes(fit)) throw new OpsError("invalid", `Unknown fit "${String(fit)}".`, "fit: cover (crop), contain (pad) or stretch.");
|
|
54
|
+
for (const k of [
|
|
55
|
+
"width",
|
|
56
|
+
"height",
|
|
57
|
+
"scale"
|
|
58
|
+
]) {
|
|
59
|
+
const v = d[k];
|
|
60
|
+
if (v !== void 0 && v !== null && !(typeof v === "number" && Number.isFinite(v) && v > 0)) throw new OpsError("invalid", `Export ${k} must be a positive number, got ${JSON.stringify(v)}.`, k === "scale" ? "e.g. scale: 2 (twice the canvas size) or 0.5." : `${k} in px, e.g. 1080.`);
|
|
61
|
+
}
|
|
62
|
+
if (d.preset) {
|
|
63
|
+
const p = sizePreset(d.preset);
|
|
64
|
+
if (!p) throw new OpsError("invalid", `Unknown size preset "${d.preset}".`, `${didYouMean(d.preset, SIZE_PRESETS.map((s) => s.id))}Presets: ${SIZE_PRESETS.map((s) => s.id).join(", ")}.`);
|
|
65
|
+
outW = p.width;
|
|
66
|
+
outH = p.height;
|
|
67
|
+
} else if (d.width && d.height) {
|
|
68
|
+
outW = d.width;
|
|
69
|
+
outH = d.height;
|
|
70
|
+
} else if (d.width) {
|
|
71
|
+
outW = d.width;
|
|
72
|
+
outH = d.width * H / W;
|
|
73
|
+
fit = "stretch";
|
|
74
|
+
} else if (d.height) {
|
|
75
|
+
outH = d.height;
|
|
76
|
+
outW = d.height * W / H;
|
|
77
|
+
fit = "stretch";
|
|
78
|
+
} else if (d.scale) {
|
|
79
|
+
outW = W * d.scale;
|
|
80
|
+
outH = H * d.scale;
|
|
81
|
+
fit = "stretch";
|
|
82
|
+
}
|
|
83
|
+
outW = Math.max(1, Math.round(outW));
|
|
84
|
+
outH = Math.max(1, Math.round(outH));
|
|
85
|
+
if (outW > 16384 || outH > 16384) throw new OpsError("invalid", `Export size ${outW}×${outH} exceeds ${MAX_CANVAS} px.`);
|
|
86
|
+
let source = {
|
|
87
|
+
x: 0,
|
|
88
|
+
y: 0,
|
|
89
|
+
width: W,
|
|
90
|
+
height: H
|
|
91
|
+
};
|
|
92
|
+
let dest = {
|
|
93
|
+
x: 0,
|
|
94
|
+
y: 0,
|
|
95
|
+
width: outW,
|
|
96
|
+
height: outH
|
|
97
|
+
};
|
|
98
|
+
if (fit === "cover") {
|
|
99
|
+
const s = Math.max(outW / W, outH / H);
|
|
100
|
+
const sw = outW / s;
|
|
101
|
+
const sh = outH / s;
|
|
102
|
+
source = {
|
|
103
|
+
x: (W - sw) / 2,
|
|
104
|
+
y: (H - sh) / 2,
|
|
105
|
+
width: sw,
|
|
106
|
+
height: sh
|
|
107
|
+
};
|
|
108
|
+
} else if (fit === "contain") {
|
|
109
|
+
const s = Math.min(outW / W, outH / H);
|
|
110
|
+
dest = {
|
|
111
|
+
x: (outW - W * s) / 2,
|
|
112
|
+
y: (outH - H * s) / 2,
|
|
113
|
+
width: W * s,
|
|
114
|
+
height: H * s
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
const scale = dest.width / source.width;
|
|
118
|
+
let background = d.background ?? null;
|
|
119
|
+
if (background !== null && !isValidColor(background)) throw new OpsError("invalid", `Export background ${JSON.stringify(background)} is not a colour.`);
|
|
120
|
+
if (format === "jpeg" && (!background || parseColor(background)?.a === 0)) background = "#ffffff";
|
|
121
|
+
const name = (d.name ?? doc.id ?? "photo").replace(/[^\w.-]+/g, "-");
|
|
122
|
+
const suffix = d.preset ? `-${d.preset}` : d.width || d.height || d.scale ? `-${outW}x${outH}` : "";
|
|
123
|
+
const file = d.out ?? `dist/${name}${suffix}.${FORMAT_EXT[format]}`;
|
|
124
|
+
return {
|
|
125
|
+
format,
|
|
126
|
+
mime: format === "jpeg" ? "image/jpeg" : `image/${format}`,
|
|
127
|
+
quality,
|
|
128
|
+
width: outW,
|
|
129
|
+
height: outH,
|
|
130
|
+
scale,
|
|
131
|
+
source,
|
|
132
|
+
dest,
|
|
133
|
+
background,
|
|
134
|
+
file
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function stripUndefined(o) {
|
|
138
|
+
return Object.fromEntries(Object.entries(o).filter(([, v]) => v !== void 0));
|
|
139
|
+
}
|
|
140
|
+
export { export_exports as n, planExport as r, IMAGE_FORMATS as t };
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import { createRequire as __apRequire } from "node:module";
|
|
2
|
+
import { fileURLToPath as __apPath } from "node:url";
|
|
3
|
+
import { dirname as __apDirname } from "node:path";
|
|
4
|
+
__apRequire(import.meta.url);
|
|
5
|
+
const __filename = __apPath(import.meta.url);
|
|
6
|
+
__apDirname(__filename);
|
|
7
|
+
import { t as __exportAll } from "./rolldown-runtime-CMQPkI6i.mjs";
|
|
8
|
+
import { c as filterDef, i as EFFECTS } from "./catalog-DIZ5dnH5.mjs";
|
|
9
|
+
import { a as isShapeMask, n as hasBox, r as isGradientMask } from "./types-DOK7tAAu.mjs";
|
|
10
|
+
import { r as OpsError } from "./context-CNpRboiC.mjs";
|
|
11
|
+
// src/ops/geometry.ts
|
|
12
|
+
var geometry_exports = /* @__PURE__ */ __exportAll({ cropDoc: () => cropDoc });
|
|
13
|
+
var ANCHORS = [
|
|
14
|
+
"top-left",
|
|
15
|
+
"top",
|
|
16
|
+
"top-right",
|
|
17
|
+
"left",
|
|
18
|
+
"center",
|
|
19
|
+
"right",
|
|
20
|
+
"bottom-left",
|
|
21
|
+
"bottom",
|
|
22
|
+
"bottom-right"
|
|
23
|
+
];
|
|
24
|
+
var clone = (v) => JSON.parse(JSON.stringify(v));
|
|
25
|
+
var r2 = (v) => Math.round(v * 100) / 100;
|
|
26
|
+
function estimateTextBox(l) {
|
|
27
|
+
const size = l.size ?? 64;
|
|
28
|
+
const lines = String(l.text ?? "").split("\n");
|
|
29
|
+
const longest = Math.max(1, ...lines.map((s) => s.length));
|
|
30
|
+
return {
|
|
31
|
+
width: l.width ?? longest * size * .55 + Math.max(0, longest - 1) * (l.letterSpacing ?? 0),
|
|
32
|
+
height: l.height ?? lines.length * size * (l.lineHeight ?? 1.2)
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function layerBox(l, sizes = {}) {
|
|
36
|
+
if (!hasBox(l)) return null;
|
|
37
|
+
const x = l.x ?? 0;
|
|
38
|
+
const y = l.y ?? 0;
|
|
39
|
+
if (l.type === "text") return {
|
|
40
|
+
x,
|
|
41
|
+
y,
|
|
42
|
+
...estimateTextBox(l)
|
|
43
|
+
};
|
|
44
|
+
let w = l.width;
|
|
45
|
+
let h = l.height;
|
|
46
|
+
if (l.type === "image" && (w === void 0 || h === void 0)) {
|
|
47
|
+
const nat = sizes[l.src];
|
|
48
|
+
const src = l.crop ? {
|
|
49
|
+
width: l.crop.width,
|
|
50
|
+
height: l.crop.height
|
|
51
|
+
} : nat;
|
|
52
|
+
if (src) {
|
|
53
|
+
if (w === void 0 && h === void 0) [w, h] = [src.width, src.height];
|
|
54
|
+
else if (w === void 0) w = h * src.width / src.height;
|
|
55
|
+
else h = w * src.height / src.width;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (w === void 0 || h === void 0) return null;
|
|
59
|
+
return {
|
|
60
|
+
x,
|
|
61
|
+
y,
|
|
62
|
+
width: w,
|
|
63
|
+
height: h
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function pinSize(l, sizes) {
|
|
67
|
+
if (l.type !== "image" || l.width !== void 0 && l.height !== void 0) return;
|
|
68
|
+
const b = layerBox(l, sizes);
|
|
69
|
+
if (!b) throw new OpsError("invalid", `The size of image layer "${l.id}" is unknown (its source ${l.src} could not be read).`, "Give the layer an explicit width and height, or fix its src (assets_list).");
|
|
70
|
+
l.width = r2(b.width);
|
|
71
|
+
l.height = r2(b.height);
|
|
72
|
+
}
|
|
73
|
+
function eachLayer(layers, fn) {
|
|
74
|
+
for (const l of layers) {
|
|
75
|
+
fn(l);
|
|
76
|
+
if (l.type === "group") eachLayer(l.children ?? [], fn);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function translateMask(m, dx, dy) {
|
|
80
|
+
if (m && isShapeMask(m)) {
|
|
81
|
+
m.x = r2(m.x + dx);
|
|
82
|
+
m.y = r2(m.y + dy);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function translateAll(layers, dx, dy) {
|
|
86
|
+
eachLayer(layers, (l) => {
|
|
87
|
+
if (hasBox(l)) {
|
|
88
|
+
l.x = r2((l.x ?? 0) + dx);
|
|
89
|
+
l.y = r2((l.y ?? 0) + dy);
|
|
90
|
+
} else translateMask(l.mask, dx, dy);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
function cropDoc(doc, rect) {
|
|
94
|
+
const { x, y, width, height } = rect;
|
|
95
|
+
if (![
|
|
96
|
+
x,
|
|
97
|
+
y,
|
|
98
|
+
width,
|
|
99
|
+
height
|
|
100
|
+
].every(Number.isFinite) || width < 1 || height < 1) throw new OpsError("invalid", "crop needs x, y, width ≥ 1, height ≥ 1 (canvas pixels).");
|
|
101
|
+
const out = clone(doc);
|
|
102
|
+
translateAll(out.layers, -x, -y);
|
|
103
|
+
out.canvas = {
|
|
104
|
+
...out.canvas,
|
|
105
|
+
width: Math.round(width),
|
|
106
|
+
height: Math.round(height)
|
|
107
|
+
};
|
|
108
|
+
return out;
|
|
109
|
+
}
|
|
110
|
+
function anchorOffset(anchor, dw, dh) {
|
|
111
|
+
const ax = anchor.endsWith("left") ? 0 : anchor.endsWith("right") ? 1 : .5;
|
|
112
|
+
const ay = anchor.startsWith("top") ? 0 : anchor.startsWith("bottom") ? 1 : .5;
|
|
113
|
+
return [dw * ax, dh * ay];
|
|
114
|
+
}
|
|
115
|
+
function resizeCanvasDoc(doc, width, height, anchor = "center") {
|
|
116
|
+
if (!ANCHORS.includes(anchor)) throw new OpsError("invalid", `Unknown anchor "${anchor}".`, `Anchors: ${ANCHORS.join(", ")}.`);
|
|
117
|
+
const [ox, oy] = anchorOffset(anchor, width - doc.canvas.width, height - doc.canvas.height);
|
|
118
|
+
return cropDoc(doc, {
|
|
119
|
+
x: -ox,
|
|
120
|
+
y: -oy,
|
|
121
|
+
width,
|
|
122
|
+
height
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
function scalePx(obj, keys, k) {
|
|
126
|
+
if (!obj) return;
|
|
127
|
+
for (const key of keys) if (typeof obj[key] === "number") obj[key] = r2(obj[key] * k);
|
|
128
|
+
}
|
|
129
|
+
function scaleFilters(filters, k) {
|
|
130
|
+
for (const f of filters ?? []) scalePx(f, (filterDef(f.type)?.params ?? []).filter((p) => p.px).map((p) => p.name), k);
|
|
131
|
+
}
|
|
132
|
+
function scaleDoc(doc, sx, sy, sizes = {}) {
|
|
133
|
+
if (!(sx > 0) || !(sy > 0)) throw new OpsError("invalid", "The scale must be > 0.");
|
|
134
|
+
const out = clone(doc);
|
|
135
|
+
eachLayer(out.layers, (l) => scaleLayer(l, sx, sy, sizes));
|
|
136
|
+
out.canvas = {
|
|
137
|
+
...out.canvas,
|
|
138
|
+
width: Math.max(1, Math.round(doc.canvas.width * sx)),
|
|
139
|
+
height: Math.max(1, Math.round(doc.canvas.height * sy))
|
|
140
|
+
};
|
|
141
|
+
return out;
|
|
142
|
+
}
|
|
143
|
+
function scaleLayer(l, sx, sy, sizes) {
|
|
144
|
+
const k = Math.sqrt(sx * sy);
|
|
145
|
+
pinSize(l, sizes);
|
|
146
|
+
if (hasBox(l)) {
|
|
147
|
+
l.x = r2((l.x ?? 0) * sx);
|
|
148
|
+
l.y = r2((l.y ?? 0) * sy);
|
|
149
|
+
if (l.width !== void 0) l.width = r2(l.width * sx);
|
|
150
|
+
if (l.height !== void 0) l.height = r2(l.height * sy);
|
|
151
|
+
} else if (l.mask && isShapeMask(l.mask)) {
|
|
152
|
+
const m = l.mask;
|
|
153
|
+
m.x = r2(m.x * sx);
|
|
154
|
+
m.y = r2(m.y * sy);
|
|
155
|
+
m.width = r2(m.width * sx);
|
|
156
|
+
m.height = r2(m.height * sy);
|
|
157
|
+
}
|
|
158
|
+
if (l.mask) {
|
|
159
|
+
if (hasBox(l) && isShapeMask(l.mask)) {
|
|
160
|
+
const m = l.mask;
|
|
161
|
+
m.x = r2(m.x * sx);
|
|
162
|
+
m.y = r2(m.y * sy);
|
|
163
|
+
m.width = r2(m.width * sx);
|
|
164
|
+
m.height = r2(m.height * sy);
|
|
165
|
+
}
|
|
166
|
+
scalePx(l.mask, ["feather", "radius"], k);
|
|
167
|
+
}
|
|
168
|
+
if (l.type === "text") {
|
|
169
|
+
scalePx(l, ["size", "letterSpacing"], k);
|
|
170
|
+
if (l.background) {
|
|
171
|
+
const p = l.background.padding;
|
|
172
|
+
l.background.padding = Array.isArray(p) ? [r2(p[0] * k), r2(p[1] * k)] : typeof p === "number" ? r2(p * k) : p;
|
|
173
|
+
scalePx(l.background, ["radius"], k);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (l.type === "shape") {
|
|
177
|
+
scalePx(l, ["radius"], k);
|
|
178
|
+
if (l.stroke) scalePx(l.stroke, ["width"], k);
|
|
179
|
+
}
|
|
180
|
+
scaleFilters(l.filters, k);
|
|
181
|
+
if (l.effects) for (const def of EFFECTS) {
|
|
182
|
+
const fx = l.effects[def.id];
|
|
183
|
+
scalePx(fx, def.params.filter((p) => p.px).map((p) => p.name), k);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
var isRect = (r) => !!r && typeof r === "object" && [
|
|
187
|
+
"x",
|
|
188
|
+
"y",
|
|
189
|
+
"width",
|
|
190
|
+
"height"
|
|
191
|
+
].every((k) => Number.isFinite(r[k]));
|
|
192
|
+
function fitLayerDoc(doc, id, box, opts = {}) {
|
|
193
|
+
if (!isRect(box) || box.width < 1 || box.height < 1) throw new OpsError("invalid", "fitLayer needs box { x, y, width ≥ 1, height ≥ 1 } (canvas px).");
|
|
194
|
+
const anchor = opts.anchor ?? "center";
|
|
195
|
+
if (!ANCHORS.includes(anchor)) throw new OpsError("invalid", `Unknown anchor "${anchor}".`, `Anchors: ${ANCHORS.join(", ")}.`);
|
|
196
|
+
const out = clone(doc);
|
|
197
|
+
let layer = null;
|
|
198
|
+
eachLayer(out.layers, (l) => {
|
|
199
|
+
if (l.id === id && !layer) layer = l;
|
|
200
|
+
});
|
|
201
|
+
const l = layer;
|
|
202
|
+
if (!l) throw new OpsError("notFound", `No layer "${id}".`, "layer_list lists the layer ids.");
|
|
203
|
+
if (!hasBox(l)) throw new OpsError("invalid", `"${id}" is a ${l.type} layer: fitLayer moves image, text and shape layers.`);
|
|
204
|
+
pinSize(l, opts.sizes ?? {});
|
|
205
|
+
const b = layerBox(l, opts.sizes);
|
|
206
|
+
if (!b || !(b.width > 0) || !(b.height > 0)) throw new OpsError("invalid", `The box of layer "${id}" is unknown.`, "Give the layer an explicit width and height.");
|
|
207
|
+
const subj = opts.subject ?? b;
|
|
208
|
+
if (!isRect(subj) || !(subj.width > 0) || !(subj.height > 0)) throw new OpsError("invalid", "fitLayer subject must be { x, y, width > 0, height > 0 } (canvas px).", "Pass the subject returned by remove_background, or omit it to fit the whole layer.");
|
|
209
|
+
const k = Math.min(box.width / subj.width, box.height / subj.height);
|
|
210
|
+
const [ox, oy] = anchorOffset(anchor, box.width - subj.width * k, box.height - subj.height * k);
|
|
211
|
+
const relX = subj.x - b.x;
|
|
212
|
+
const relY = subj.y - b.y;
|
|
213
|
+
scaleLayer(l, k, k, opts.sizes ?? {});
|
|
214
|
+
l.x = r2(box.x + ox - relX * k);
|
|
215
|
+
l.y = r2(box.y + oy - relY * k);
|
|
216
|
+
return out;
|
|
217
|
+
}
|
|
218
|
+
var normAngle = (deg) => {
|
|
219
|
+
const a = ((deg + 180) % 360 + 360) % 360 - 180;
|
|
220
|
+
return a === -180 ? 180 : a;
|
|
221
|
+
};
|
|
222
|
+
function transformPaint(p, fn) {
|
|
223
|
+
if (!p || typeof p !== "object") return;
|
|
224
|
+
if (p.type === "linear") p.angle = r2(normAngle(fn.angle(p.angle ?? 90)));
|
|
225
|
+
else if (p.type === "radial") {
|
|
226
|
+
const [cx, cy] = fn.point(p.cx ?? .5, p.cy ?? .5);
|
|
227
|
+
p.cx = r2(cx);
|
|
228
|
+
p.cy = r2(cy);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
function transformCanvasPaints(doc, fn) {
|
|
232
|
+
transformPaint(doc.canvas.background, fn);
|
|
233
|
+
eachLayer(doc.layers, (l) => {
|
|
234
|
+
if (hasBox(l)) return;
|
|
235
|
+
if (l.type === "fill") transformPaint(l.fill, fn);
|
|
236
|
+
if (l.mask && isGradientMask(l.mask)) transformPaint(l.mask.gradient, fn);
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
function rotateDoc(doc, angle, sizes = {}) {
|
|
240
|
+
const a = (Math.round(angle / 90) * 90 % 360 + 360) % 360;
|
|
241
|
+
if (angle % 90 !== 0) throw new OpsError("invalid", `Canvas rotation must be a multiple of 90°, got ${angle}.`, "To straighten a photo by a few degrees, set the image layer's rotation instead (and crop).");
|
|
242
|
+
if (a === 0) return clone(doc);
|
|
243
|
+
const out = clone(doc);
|
|
244
|
+
const W = doc.canvas.width;
|
|
245
|
+
const H = doc.canvas.height;
|
|
246
|
+
const map = (x, y) => a === 90 ? [H - y, x] : a === 180 ? [W - x, H - y] : [y, W - x];
|
|
247
|
+
eachLayer(out.layers, (l) => {
|
|
248
|
+
pinSize(l, sizes);
|
|
249
|
+
const box = layerBox(l, sizes);
|
|
250
|
+
if (box) {
|
|
251
|
+
const [cx, cy] = map(box.x + box.width / 2, box.y + box.height / 2);
|
|
252
|
+
const bl = l;
|
|
253
|
+
bl.x = r2(cx - box.width / 2);
|
|
254
|
+
bl.y = r2(cy - box.height / 2);
|
|
255
|
+
bl.rotation = normAngle((bl.rotation ?? 0) + a);
|
|
256
|
+
if (bl.rotation === 0) delete bl.rotation;
|
|
257
|
+
} else if (l.mask && isShapeMask(l.mask)) {
|
|
258
|
+
const m = l.mask;
|
|
259
|
+
const [cx, cy] = map(m.x + m.width / 2, m.y + m.height / 2);
|
|
260
|
+
const [w, h] = a === 180 ? [m.width, m.height] : [m.height, m.width];
|
|
261
|
+
Object.assign(m, {
|
|
262
|
+
x: r2(cx - w / 2),
|
|
263
|
+
y: r2(cy - h / 2),
|
|
264
|
+
width: w,
|
|
265
|
+
height: h
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
transformCanvasPaints(out, {
|
|
270
|
+
angle: (deg) => deg + a,
|
|
271
|
+
point: (fx, fy) => a === 90 ? [1 - fy, fx] : a === 180 ? [1 - fx, 1 - fy] : [fy, 1 - fx]
|
|
272
|
+
});
|
|
273
|
+
if (a !== 180) out.canvas = {
|
|
274
|
+
...out.canvas,
|
|
275
|
+
width: H,
|
|
276
|
+
height: W
|
|
277
|
+
};
|
|
278
|
+
return out;
|
|
279
|
+
}
|
|
280
|
+
function flipDoc(doc, axis, sizes = {}) {
|
|
281
|
+
if (axis !== "horizontal" && axis !== "vertical") throw new OpsError("invalid", `axis must be "horizontal" or "vertical".`);
|
|
282
|
+
const out = clone(doc);
|
|
283
|
+
const W = doc.canvas.width;
|
|
284
|
+
const H = doc.canvas.height;
|
|
285
|
+
eachLayer(out.layers, (l) => {
|
|
286
|
+
pinSize(l, sizes);
|
|
287
|
+
const box = layerBox(l, sizes);
|
|
288
|
+
if (box) {
|
|
289
|
+
const bl = l;
|
|
290
|
+
if (axis === "horizontal") {
|
|
291
|
+
bl.x = r2(W - box.x - box.width);
|
|
292
|
+
if (l.type !== "text") bl.flipX = !bl.flipX || void 0;
|
|
293
|
+
} else {
|
|
294
|
+
bl.y = r2(H - box.y - box.height);
|
|
295
|
+
if (l.type !== "text") bl.flipY = !bl.flipY || void 0;
|
|
296
|
+
}
|
|
297
|
+
if (bl.rotation) bl.rotation = -bl.rotation;
|
|
298
|
+
if (!bl.flipX) delete bl.flipX;
|
|
299
|
+
if (!bl.flipY) delete bl.flipY;
|
|
300
|
+
} else if (l.mask && isShapeMask(l.mask)) {
|
|
301
|
+
const m = l.mask;
|
|
302
|
+
if (axis === "horizontal") m.x = r2(W - m.x - m.width);
|
|
303
|
+
else m.y = r2(H - m.y - m.height);
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
transformCanvasPaints(out, axis === "horizontal" ? {
|
|
307
|
+
angle: (deg) => 180 - deg,
|
|
308
|
+
point: (fx, fy) => [1 - fx, fy]
|
|
309
|
+
} : {
|
|
310
|
+
angle: (deg) => -deg,
|
|
311
|
+
point: (fx, fy) => [fx, 1 - fy]
|
|
312
|
+
});
|
|
313
|
+
return out;
|
|
314
|
+
}
|
|
315
|
+
export { geometry_exports as a, rotateDoc as c, flipDoc as i, scaleDoc as l, cropDoc as n, layerBox as o, fitLayerDoc as r, resizeCanvasDoc as s, ANCHORS as t };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createRequire as __apRequire } from "node:module";
|
|
2
|
+
import { fileURLToPath as __apPath } from "node:url";
|
|
3
|
+
import { dirname as __apDirname } from "node:path";
|
|
4
|
+
__apRequire(import.meta.url);
|
|
5
|
+
const __filename = __apPath(import.meta.url);
|
|
6
|
+
__apDirname(__filename);
|
|
7
|
+
import { t as __exportAll } from "./rolldown-runtime-CMQPkI6i.mjs";
|
|
8
|
+
// src/core/ids.ts
|
|
9
|
+
var ids_exports = /* @__PURE__ */ __exportAll({
|
|
10
|
+
slugify: () => slugify,
|
|
11
|
+
uniqueId: () => uniqueId
|
|
12
|
+
});
|
|
13
|
+
var ID_RE = /^[a-zA-Z][a-zA-Z0-9_-]*$/;
|
|
14
|
+
function isValidId(id) {
|
|
15
|
+
return typeof id === "string" && ID_RE.test(id);
|
|
16
|
+
}
|
|
17
|
+
function slugify(text, fallback = "item") {
|
|
18
|
+
const s = text.normalize("NFKD").replace(/[̀-ͯ]/g, "").toLowerCase().replace(/[^a-z0-9_-]+/g, "-").replace(/^-+|-+$/g, "").replace(/-{2,}/g, "-");
|
|
19
|
+
if (!s) return fallback;
|
|
20
|
+
return /^[a-z]/.test(s) ? s : `${fallback}-${s}`;
|
|
21
|
+
}
|
|
22
|
+
function uniqueId(base, taken) {
|
|
23
|
+
const set = new Set(taken);
|
|
24
|
+
const b = isValidId(base) ? base : slugify(base);
|
|
25
|
+
if (!set.has(b)) return b;
|
|
26
|
+
for (let i = 2;; i++) if (!set.has(`${b}-${i}`)) return `${b}-${i}`;
|
|
27
|
+
}
|
|
28
|
+
export { uniqueId as i, isValidId as n, slugify as r, ids_exports as t };
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { createRequire as __apRequire } from "node:module";
|
|
2
|
+
import { fileURLToPath as __apPath } from "node:url";
|
|
3
|
+
import { dirname as __apDirname } from "node:path";
|
|
4
|
+
__apRequire(import.meta.url);
|
|
5
|
+
const __filename = __apPath(import.meta.url);
|
|
6
|
+
__apDirname(__filename);
|
|
7
|
+
import { t as __exportAll } from "./rolldown-runtime-CMQPkI6i.mjs";
|
|
8
|
+
// src/core/imageInfo.ts
|
|
9
|
+
var imageInfo_exports = /* @__PURE__ */ __exportAll({ imageInfo: () => imageInfo });
|
|
10
|
+
var IMAGE_EXTENSIONS = {
|
|
11
|
+
png: "png",
|
|
12
|
+
jpg: "jpeg",
|
|
13
|
+
jpeg: "jpeg",
|
|
14
|
+
webp: "webp",
|
|
15
|
+
gif: "gif",
|
|
16
|
+
bmp: "bmp",
|
|
17
|
+
avif: "avif",
|
|
18
|
+
svg: "svg"
|
|
19
|
+
};
|
|
20
|
+
var u16be = (b, o) => b[o] << 8 | b[o + 1];
|
|
21
|
+
var u16le = (b, o) => b[o] | b[o + 1] << 8;
|
|
22
|
+
var u24le = (b, o) => b[o] | b[o + 1] << 8 | b[o + 2] << 16;
|
|
23
|
+
var u32be = (b, o) => (b[o] << 24 >>> 0) + (b[o + 1] << 16 | b[o + 2] << 8 | b[o + 3]);
|
|
24
|
+
var i32le = (b, o) => b[o] | b[o + 1] << 8 | b[o + 2] << 16 | b[o + 3] << 24;
|
|
25
|
+
var ascii = (b, o, n) => String.fromCharCode(...b.subarray(o, o + n));
|
|
26
|
+
function imageInfo(bytes) {
|
|
27
|
+
const b = bytes;
|
|
28
|
+
if (b.length < 12) return null;
|
|
29
|
+
if (b[0] === 137 && ascii(b, 1, 3) === "PNG" && b.length >= 26) {
|
|
30
|
+
const colorType = b[25];
|
|
31
|
+
return {
|
|
32
|
+
type: "png",
|
|
33
|
+
width: u32be(b, 16),
|
|
34
|
+
height: u32be(b, 20),
|
|
35
|
+
alpha: colorType === 4 || colorType === 6
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
if (b[0] === 255 && b[1] === 216) {
|
|
39
|
+
let o = 2;
|
|
40
|
+
while (o + 9 < b.length) {
|
|
41
|
+
if (b[o] !== 255) {
|
|
42
|
+
o++;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
const marker = b[o + 1];
|
|
46
|
+
if (marker === 255) {
|
|
47
|
+
o++;
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (marker === 216 || marker === 1 || marker >= 208 && marker <= 215) {
|
|
51
|
+
o += 2;
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
const len = u16be(b, o + 2);
|
|
55
|
+
if (marker >= 192 && marker <= 207 && marker !== 196 && marker !== 200 && marker !== 204) return applyExifRotation(b, {
|
|
56
|
+
type: "jpeg",
|
|
57
|
+
height: u16be(b, o + 5),
|
|
58
|
+
width: u16be(b, o + 7),
|
|
59
|
+
alpha: false
|
|
60
|
+
});
|
|
61
|
+
o += 2 + len;
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
if (ascii(b, 0, 4) === "RIFF" && ascii(b, 8, 4) === "WEBP" && b.length >= 30) {
|
|
66
|
+
const chunk = ascii(b, 12, 4);
|
|
67
|
+
if (chunk === "VP8 ") return {
|
|
68
|
+
type: "webp",
|
|
69
|
+
width: u16le(b, 26) & 16383,
|
|
70
|
+
height: u16le(b, 28) & 16383,
|
|
71
|
+
alpha: false
|
|
72
|
+
};
|
|
73
|
+
if (chunk === "VP8L") {
|
|
74
|
+
const bits = b[21] | b[22] << 8 | b[23] << 16 | b[24] << 24;
|
|
75
|
+
return {
|
|
76
|
+
type: "webp",
|
|
77
|
+
width: (bits & 16383) + 1,
|
|
78
|
+
height: (bits >> 14 & 16383) + 1,
|
|
79
|
+
alpha: !!(bits >> 28 & 1)
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
if (chunk === "VP8X") return {
|
|
83
|
+
type: "webp",
|
|
84
|
+
width: u24le(b, 24) + 1,
|
|
85
|
+
height: u24le(b, 27) + 1,
|
|
86
|
+
alpha: !!(b[20] & 16)
|
|
87
|
+
};
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
if (ascii(b, 0, 4) === "GIF8") return {
|
|
91
|
+
type: "gif",
|
|
92
|
+
width: u16le(b, 6),
|
|
93
|
+
height: u16le(b, 8)
|
|
94
|
+
};
|
|
95
|
+
if (b[0] === 66 && b[1] === 77 && b.length >= 26) return {
|
|
96
|
+
type: "bmp",
|
|
97
|
+
width: Math.abs(i32le(b, 18)),
|
|
98
|
+
height: Math.abs(i32le(b, 22))
|
|
99
|
+
};
|
|
100
|
+
if (ascii(b, 4, 4) === "ftyp") {
|
|
101
|
+
const brand = ascii(b, 8, 4);
|
|
102
|
+
if (/avi[fs]|mif1|heic|heix/.test(brand)) {
|
|
103
|
+
for (let o = 12; o + 20 < b.length && o < 65536; o++) if (b[o] === 105 && ascii(b, o, 4) === "ispe") return {
|
|
104
|
+
type: "avif",
|
|
105
|
+
width: u32be(b, o + 8),
|
|
106
|
+
height: u32be(b, o + 12)
|
|
107
|
+
};
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const head = new TextDecoder().decode(b.subarray(0, Math.min(b.length, 4096)));
|
|
112
|
+
if (/<svg[\s>]/i.test(head)) {
|
|
113
|
+
const tag = /<svg[^>]*>/i.exec(head)?.[0] ?? "";
|
|
114
|
+
const attr = (n) => {
|
|
115
|
+
const m = new RegExp(`\\s${n}\\s*=\\s*["']([\\d.]+)(px)?["']`, "i").exec(tag);
|
|
116
|
+
return m ? Number(m[1]) : void 0;
|
|
117
|
+
};
|
|
118
|
+
let w = attr("width");
|
|
119
|
+
let h = attr("height");
|
|
120
|
+
const vb = /viewBox\s*=\s*["']\s*[-\d.]+[\s,]+[-\d.]+[\s,]+([\d.]+)[\s,]+([\d.]+)/i.exec(tag);
|
|
121
|
+
if ((!w || !h) && vb) {
|
|
122
|
+
const vw = Number(vb[1]);
|
|
123
|
+
const vh = Number(vb[2]);
|
|
124
|
+
if (w && !h) h = w * vh / vw;
|
|
125
|
+
else if (h && !w) w = h * vw / vh;
|
|
126
|
+
else {
|
|
127
|
+
w = vw;
|
|
128
|
+
h = vh;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
132
|
+
type: "svg",
|
|
133
|
+
width: Math.round(w ?? 300),
|
|
134
|
+
height: Math.round(h ?? 150),
|
|
135
|
+
alpha: true
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
function applyExifRotation(b, info) {
|
|
141
|
+
const o = exifOrientation(b);
|
|
142
|
+
return o >= 5 && o <= 8 ? {
|
|
143
|
+
...info,
|
|
144
|
+
width: info.height,
|
|
145
|
+
height: info.width
|
|
146
|
+
} : info;
|
|
147
|
+
}
|
|
148
|
+
function exifOrientation(b) {
|
|
149
|
+
let o = 2;
|
|
150
|
+
while (o + 4 < b.length) {
|
|
151
|
+
if (b[o] !== 255) return 1;
|
|
152
|
+
const marker = b[o + 1];
|
|
153
|
+
const len = u16be(b, o + 2);
|
|
154
|
+
if (marker === 225 && ascii(b, o + 4, 4) === "Exif") {
|
|
155
|
+
const t = o + 10;
|
|
156
|
+
const le = b[t] === 73;
|
|
157
|
+
const r16 = (p) => le ? u16le(b, p) : u16be(b, p);
|
|
158
|
+
const r32 = (p) => le ? (b[p] | b[p + 1] << 8 | b[p + 2] << 16 | b[p + 3] << 24) >>> 0 : u32be(b, p);
|
|
159
|
+
const ifd = t + r32(t + 4);
|
|
160
|
+
const count = r16(ifd);
|
|
161
|
+
for (let k = 0; k < count; k++) {
|
|
162
|
+
const e = ifd + 2 + k * 12;
|
|
163
|
+
if (e + 10 > b.length) break;
|
|
164
|
+
if (r16(e) === 274) return r16(e + 8);
|
|
165
|
+
}
|
|
166
|
+
return 1;
|
|
167
|
+
}
|
|
168
|
+
if (marker === 218) return 1;
|
|
169
|
+
o += 2 + len;
|
|
170
|
+
}
|
|
171
|
+
return 1;
|
|
172
|
+
}
|
|
173
|
+
export { imageInfo as n, imageInfo_exports as r, IMAGE_EXTENSIONS as t };
|