@beeintel/batch-image 0.0.0-stage → 1.0.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/FONT-LICENSE.txt +93 -0
- package/README.md +184 -3
- package/dist/assets/11st-D7qGO5e4.webp +0 -0
- package/dist/assets/UPNG-CPfdwFSy.js +2298 -0
- package/dist/assets/adjust-card-B63b81iV.webp +0 -0
- package/dist/assets/adjust-final.worker-C2JbTvv5.js +6945 -0
- package/dist/assets/amazon-CjTtpZTq.webp +0 -0
- package/dist/assets/ascii_art-B4UGbtGs.webp +0 -0
- package/dist/assets/auction-j26eVUQO.webp +0 -0
- package/dist/assets/background-DGdZUdkL.webp +0 -0
- package/dist/assets/background-card-wK7DRpvM.png +0 -0
- package/dist/assets/body-CUFdRg8w.webp +0 -0
- package/dist/assets/bounded-cutout.worker-BZR6mbaI.js +9615 -0
- package/dist/assets/brand-mark-card-cFUeDeO2.webp +0 -0
- package/dist/assets/buyma-dAxYNjow.webp +0 -0
- package/dist/assets/codec.worker-7W6hmsm6.js +7349 -0
- package/dist/assets/contour_lines-C_CqrgV1.webp +0 -0
- package/dist/assets/creema-B1tWyCPx.webp +0 -0
- package/dist/assets/crop-final.worker-Owin7TvX.js +7035 -0
- package/dist/assets/cutout-CzMvV5An.webp +0 -0
- package/dist/assets/cutout-card-CN4gNFBz.png +0 -0
- package/dist/assets/cutout.worker-DyH6Prbn.js +3894 -0
- package/dist/assets/depop-CkVC5Fn1.webp +0 -0
- package/dist/assets/dewrinkle-kFzP6LqD.webp +0 -0
- package/dist/assets/dither-CcxmO2e6.webp +0 -0
- package/dist/assets/douyin-CP_HwBDF.webp +0 -0
- package/dist/assets/download.worker-DnGSB6P_.js +17779 -0
- package/dist/assets/duotone-Cdg_3fQf.webp +0 -0
- package/dist/assets/ebay-CxLfrRAf.webp +0 -0
- package/dist/assets/edit-Cv-txfZm.webp +0 -0
- package/dist/assets/effect.worker-qu1eCcII.js +9227 -0
- package/dist/assets/engraving-BENh1O2O.webp +0 -0
- package/dist/assets/etsy-CSvz9GpY.webp +0 -0
- package/dist/assets/expand-C60VE9nK.webp +0 -0
- package/dist/assets/facebook-Ca2nJJiQ.webp +0 -0
- package/dist/assets/film_stock-Bqauwcq4.webp +0 -0
- package/dist/assets/final.worker-BnzJ3N5C.js +7035 -0
- package/dist/assets/final.worker-Csc1zoYS.js +7054 -0
- package/dist/assets/final.worker-DzBFT9xk.js +6922 -0
- package/dist/assets/final.worker-XpgKnlaz.js +7217 -0
- package/dist/assets/flatlay-CPiVmlAa.webp +0 -0
- package/dist/assets/flatlay-fold-B-CRYy87.webp +0 -0
- package/dist/assets/flatlay-open-Dzas8okC.webp +0 -0
- package/dist/assets/g-market-DXuYK_JH.webp +0 -0
- package/dist/assets/ghost-BCEAx_Zx.webp +0 -0
- package/dist/assets/ghost-front-WFgA4sUo.webp +0 -0
- package/dist/assets/ghost-three-quarter-Rt8cXj34.webp +0 -0
- package/dist/assets/gif-CObOIITx.js +303 -0
- package/dist/assets/glass_tiles-3IXP-Hmg.webp +0 -0
- package/dist/assets/glitch_art-D1i3qben.webp +0 -0
- package/dist/assets/glitch_blur-C4q_9zyq.webp +0 -0
- package/dist/assets/glow-Bv9EHBU5.webp +0 -0
- package/dist/assets/gradient_map-BR-UVYMP.webp +0 -0
- package/dist/assets/halftone-CWdKu2_6.webp +0 -0
- package/dist/assets/holo_sticker-BQDikLg2.webp +0 -0
- package/dist/assets/idus-7diqRNPs.webp +0 -0
- package/dist/assets/imagetracer.worker-CgunQTPG.js +7096 -0
- package/dist/assets/instagram-Bf0IVidT.webp +0 -0
- package/dist/assets/kakao-talk-Df79L_Mv.webp +0 -0
- package/dist/assets/kaleidoscope-BxqMZuWo.webp +0 -0
- package/dist/assets/karrot-BXFPhDwt.webp +0 -0
- package/dist/assets/kaufland-BDDy6e0C.webp +0 -0
- package/dist/assets/lazada-ConR4e1O.webp +0 -0
- package/dist/assets/lens_flare-DgyiAv_j.webp +0 -0
- package/dist/assets/light_leak-kUdpoFuC.webp +0 -0
- package/dist/assets/line-Dr1j___B.webp +0 -0
- package/dist/assets/linkedin-4s_9Wh03.webp +0 -0
- package/dist/assets/lo_fi-DSdl3yY_.webp +0 -0
- package/dist/assets/logo-preparation.worker-D9oa7SME.js +420 -0
- package/dist/assets/mercado-libre-C8CskEiS.webp +0 -0
- package/dist/assets/mercari-jp-DHj7nz4O.webp +0 -0
- package/dist/assets/metadata.worker-B_9_BgN1.js +6456 -0
- package/dist/assets/mirror_collage-JtSKCeSh.webp +0 -0
- package/dist/assets/model-BbeF-fsf.webp +0 -0
- package/dist/assets/model-BjWhieit.webp +0 -0
- package/dist/assets/momo-BWXO_8Df.webp +0 -0
- package/dist/assets/motion_blur-B8YUHeSg.webp +0 -0
- package/dist/assets/naver-xQKL8lWg.webp +0 -0
- package/dist/assets/nuvemshop-DPt6rnA-.webp +0 -0
- package/dist/assets/olx-B87gp-Il.webp +0 -0
- package/dist/assets/orient-card-Da0ii6mX.webp +0 -0
- package/dist/assets/orient-final.worker-CdF5Y5zD.js +6909 -0
- package/dist/assets/orientation-preview.worker-B7uFzz3J.js +6865 -0
- package/dist/assets/ort.bundle.min-CreFV8V1.js +9311 -0
- package/dist/assets/ort.webgpu.bundle.min-CAudaHZO.js +9311 -0
- package/dist/assets/otto-market-DWZyNKJn.webp +0 -0
- package/dist/assets/paper_texture-CXphyIrs.webp +0 -0
- package/dist/assets/pinterest-ByZqih2J.webp +0 -0
- package/dist/assets/polish-DFy6LNG7.webp +0 -0
- package/dist/assets/poshmark-DnZi2vA1.webp +0 -0
- package/dist/assets/posterize-SpLVGq1s.webp +0 -0
- package/dist/assets/preview.worker-DcrCKKWl.js +380 -0
- package/dist/assets/qoo10-C1pq81Jx.webp +0 -0
- package/dist/assets/rakuten-ulYog1hL.webp +0 -0
- package/dist/assets/recolor-mBX7vdFT.webp +0 -0
- package/dist/assets/resize-DVEAl0Um.webp +0 -0
- package/dist/assets/runtime-0663b902fb3937883a34.wasm +0 -0
- package/dist/assets/runtime-355a5c80c7bfdf8737de.mjs +2817 -0
- package/dist/assets/runtime-49871f5a4409519797e1.wasm +0 -0
- package/dist/assets/runtime-74cf72f9a2b7befc115a.mjs +2817 -0
- package/dist/assets/shadow-card-DTZEH60r.png +0 -0
- package/dist/assets/shopee-Bxfei6sj.webp +0 -0
- package/dist/assets/shopify-wVaBafcF.webp +0 -0
- package/dist/assets/shopline-DMoaJ7Bh.webp +0 -0
- package/dist/assets/sparkle-CD5GSGip.webp +0 -0
- package/dist/assets/ssg-DQoFx5u5.webp +0 -0
- package/dist/assets/staging-CIc8pQJ6.webp +0 -0
- package/dist/assets/standard-cutout.worker-BYLzdpR-.js +1261 -0
- package/dist/assets/text-DQW2mBGp.webp +0 -0
- package/dist/assets/textured_glass-D2coxp7n.webp +0 -0
- package/dist/assets/tga-VGxWDes0.js +752 -0
- package/dist/assets/tilt_shift-BKs46yeX.webp +0 -0
- package/dist/assets/transformers.web-DB57cIO5.js +28891 -0
- package/dist/assets/tritone-CcR4qizk.webp +0 -0
- package/dist/assets/upscale-BrLadyUk.webp +0 -0
- package/dist/assets/upscale-creative-DnZnQufJ.webp +0 -0
- package/dist/assets/upscale-crisp-Ckdmbsnn.webp +0 -0
- package/dist/assets/vinted-1QDsxvC6.webp +0 -0
- package/dist/assets/watercolor-CV67zYNE.webp +0 -0
- package/dist/assets/watermark-CpPrxaT5.webp +0 -0
- package/dist/assets/wave_distortion-CV5jVfK4.webp +0 -0
- package/dist/assets/whatsapp-CWJxqzR6.webp +0 -0
- package/dist/assets/worker-DfrCFP3O.js +55 -0
- package/dist/assets/xerox_noise-CbbHY1S1.webp +0 -0
- package/dist/assets/youtube-DS12d5mi.webp +0 -0
- package/dist/assets/zalando-CenfWOwz.webp +0 -0
- package/dist/browser-adapter.d.ts +4 -0
- package/dist/browser-cutout-capability.d.ts +4 -0
- package/dist/browser-cutout-resources.d.ts +3 -0
- package/dist/browser-local-capabilities.d.ts +5 -0
- package/dist/capabilities.d.ts +18 -0
- package/dist/chunks/AdjustToolPanel-BELqYSUR.js +195 -0
- package/dist/chunks/BackgroundToolPanel-Dy_l8KFl.js +41 -0
- package/dist/chunks/BatchMaterials-niGKrga3.js +806 -0
- package/dist/chunks/BatchModeChoices-BRqn6zNI.js +111 -0
- package/dist/chunks/BatchOutputColorPicker-CCvmIF-b.js +75 -0
- package/dist/chunks/BatchReferenceFields-C4t7OSTw.js +316 -0
- package/dist/chunks/BeautifyToolPanel-Dc-ddaBC.js +215 -0
- package/dist/chunks/BrandMarkToolPanel-FKxXth_3.js +1179 -0
- package/dist/chunks/ContentTrimControl-BQfigZPq.js +297 -0
- package/dist/chunks/CropToolPanel-BhSuHkYm.js +218 -0
- package/dist/chunks/CutoutToolPanel-BfaZZSE_.js +73 -0
- package/dist/chunks/DisclosureToolPanel-B_oc5fld.js +76 -0
- package/dist/chunks/ExpandToolPanel-D_ZODTUZ.js +67 -0
- package/dist/chunks/ImageEffectsToolPanel-BRLPIt4q.js +966 -0
- package/dist/chunks/IpAuditToolPanel-DfY-mBSe.js +96 -0
- package/dist/chunks/ListingToolPanel-B9Yh3LBK.js +783 -0
- package/dist/chunks/MaterialSelectionPlate-DhioUjdW.js +30 -0
- package/dist/chunks/MetadataToolPanel-KVrtb3K0.js +104 -0
- package/dist/chunks/OrientToolPanel-BTrwaWBm.js +161 -0
- package/dist/chunks/PluginActionFooter.vue_vue_type_script_setup_true_lang-C2kJCYeA.js +102 -0
- package/dist/chunks/ResizeToolPanel-Ch_-WR74.js +1178 -0
- package/dist/chunks/RetouchToolPanel-BTS33Dsd.js +350 -0
- package/dist/chunks/ShadowToolPanel-DxJE4eyV.js +254 -0
- package/dist/chunks/SvgExportToolPanel-RHmuQARH.js +219 -0
- package/dist/chunks/TranslationToolPanel-B_qTA1hM.js +125 -0
- package/dist/chunks/UpscaleToolPanel-D0H-j2Tr.js +127 -0
- package/dist/chunks/engine-D-T-1RSx.js +69 -0
- package/dist/chunks/entry-DK9FjQZ_.js +42946 -0
- package/dist/chunks/gpu-CScw5MNG.js +231 -0
- package/dist/chunks/hosted-resources-COzZ7nZY.js +8196 -0
- package/dist/chunks/loader-circle-UFoEem2a.js +16 -0
- package/dist/chunks/motionFeatures-D4miwXxc.js +4405 -0
- package/dist/chunks/search-BjTSm1KS.js +18 -0
- package/dist/chunks/standard-cutout-vPpP6xBc.js +45 -0
- package/dist/chunks/static-logo-2F9ORZWc.js +34 -0
- package/dist/config.d.ts +66 -0
- package/dist/contracts.d.ts +272 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +13 -0
- package/dist/node/catalog.mjs +45 -0
- package/dist/node/cli.mjs +11 -0
- package/dist/node/index.d.mts +20 -0
- package/dist/node/index.mjs +2 -0
- package/dist/node/prepare.mjs +114 -0
- package/dist/node/vite.mjs +46 -0
- package/dist/processing.d.ts +1 -0
- package/dist/processing.js +12105 -0
- package/dist/remote-contracts.d.ts +114 -0
- package/dist/resource-contracts.d.ts +40 -0
- package/dist/resources/cutout/9ae2e5375a34fa413530954dc20d085d175faffc86108c13619220d0557f80bf.json +1 -0
- package/dist/resources/cutout/f119dabecc64bc436d3d08425dde96ec2598fd40541eba97d8d53a4e8bbdcaea.json +1 -0
- package/dist/resources/cutout/resources.json +195 -0
- package/dist/resources/cutout/sources.json +294 -0
- package/dist/resources.json +1191 -0
- package/dist/service-contracts.d.ts +43 -0
- package/dist/slots.d.ts +21 -0
- package/dist/style.css +1 -0
- package/dist/types/batch/api.d.ts +89 -0
- package/dist/types/batch/cutout-output.d.ts +2 -0
- package/dist/types/batch/features/background/engine.d.mts +12 -0
- package/dist/types/batch/features/basic-edit/contracts.d.ts +87 -0
- package/dist/types/batch/features/basic-edit/engine.d.mts +96 -0
- package/dist/types/batch/features/brand-mark/contracts.d.ts +84 -0
- package/dist/types/batch/features/brand-mark/engine.d.mts +68 -0
- package/dist/types/batch/features/export-compression/contracts.d.ts +44 -0
- package/dist/types/batch/features/export-compression/gifenc.d.ts +33 -0
- package/dist/types/batch/features/export-compression/plan.d.ts +45 -0
- package/dist/types/batch/features/export-compression/presentation.d.ts +70 -0
- package/dist/types/batch/features/export-compression/upng.d.ts +6 -0
- package/dist/types/batch/features/final-image/resize.d.mts +15 -0
- package/dist/types/batch/features/image-effects/contracts.d.ts +58 -0
- package/dist/types/batch/features/image-effects/gpu-pixel-runtime.d.ts +15 -0
- package/dist/types/batch/features/image-effects/photo-audit.d.ts +21 -0
- package/dist/types/batch/features/image-effects/photo-v7-cpu.d.ts +9 -0
- package/dist/types/batch/features/image-effects/profiles-v4.d.ts +157 -0
- package/dist/types/batch/features/image-effects/profiles-v5.d.ts +20 -0
- package/dist/types/batch/features/image-effects/profiles-v6.d.ts +14 -0
- package/dist/types/batch/features/image-effects/profiles-v7.d.ts +53 -0
- package/dist/types/batch/features/image-effects/profiles-v8.d.ts +113 -0
- package/dist/types/batch/features/image-effects/profiles-v9.d.ts +20 -0
- package/dist/types/batch/features/image-translation/params.d.ts +257 -0
- package/dist/types/batch/features/listing-remake/transport.d.ts +21 -0
- package/dist/types/batch/features/metadata/bytes.d.mts +13 -0
- package/dist/types/batch/features/metadata/containers.d.mts +20 -0
- package/dist/types/batch/features/metadata/declaration.d.mts +5 -0
- package/dist/types/batch/features/metadata/engine.d.mts +9 -0
- package/dist/types/batch/features/metadata/exchange.d.mts +48 -0
- package/dist/types/batch/features/shadow/contracts.d.ts +43 -0
- package/dist/types/batch/features/shadow/engine.d.mts +33 -0
- package/dist/types/batch/features/svg-export/download-contract.d.ts +33 -0
- package/dist/types/batch/features/svg-export/download-prepare.d.ts +2 -0
- package/dist/types/batch/features/svg-export/download.d.ts +7 -0
- package/dist/types/batch/features/svg-export/imagetracer.d.ts +6 -0
- package/dist/types/batch/features/svg-export/optimizer.d.ts +2 -0
- package/dist/types/batch/ids.d.ts +1 -0
- package/dist/types/batch/model.d.ts +317 -0
- package/dist/types/batch/public/config.d.ts +66 -0
- package/dist/types/batch/public/contracts.d.ts +272 -0
- package/dist/types/batch/public/remote-contracts.d.ts +114 -0
- package/dist/types/batch/public/resource-contracts.d.ts +40 -0
- package/dist/types/batch/public/service-contracts.d.ts +43 -0
- package/dist/types/batch/queue.d.ts +34 -0
- package/dist/types/batch/receipts.d.ts +85 -0
- package/dist/types/batch/retention.d.ts +13 -0
- package/dist/types/onnxruntime-web.d.ts +5 -0
- package/dist/types/plugins/cutout/core/hosted-resources.d.ts +11 -0
- package/dist/types/processing.d.ts +18 -0
- package/dist/types/shared/svg-security.d.mts +4 -0
- package/dist/types/workspace-worker.d.ts +2 -0
- package/package.json +95 -6
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
const y = Object.freeze({
|
|
2
|
+
version: 1,
|
|
3
|
+
brightness: 0,
|
|
4
|
+
contrast: 1,
|
|
5
|
+
saturation: 1,
|
|
6
|
+
vibrance: 0,
|
|
7
|
+
temperature: 0,
|
|
8
|
+
tint: 0
|
|
9
|
+
}), _ = Object.freeze({ version: 1, ratio: "original", anchor: "center" }), z = Object.freeze({
|
|
10
|
+
version: 1,
|
|
11
|
+
upright: !0,
|
|
12
|
+
rotation: 0,
|
|
13
|
+
flipHorizontal: !1,
|
|
14
|
+
flipVertical: !1
|
|
15
|
+
}), N = [
|
|
16
|
+
"top-left",
|
|
17
|
+
"top",
|
|
18
|
+
"top-right",
|
|
19
|
+
"left",
|
|
20
|
+
"center",
|
|
21
|
+
"right",
|
|
22
|
+
"bottom-left",
|
|
23
|
+
"bottom",
|
|
24
|
+
"bottom-right"
|
|
25
|
+
], C = (t) => Math.max(0, Math.min(1, t));
|
|
26
|
+
function F(t, o) {
|
|
27
|
+
if (!t || typeof t != "object" || Object.getPrototypeOf(t) !== Object.prototype && Object.getPrototypeOf(t) !== null)
|
|
28
|
+
throw new Error("图片参数无效");
|
|
29
|
+
const r = Reflect.ownKeys(t);
|
|
30
|
+
if (r.length !== o.length || r.some((c) => !o.includes(c)))
|
|
31
|
+
throw new Error("图片参数字段无效");
|
|
32
|
+
}
|
|
33
|
+
function O(t) {
|
|
34
|
+
if (F(t, Object.keys(y)), t.version !== 1) throw new Error("调色版本不受支持");
|
|
35
|
+
const o = { version: 1 };
|
|
36
|
+
for (const r of ["brightness", "contrast", "saturation", "vibrance", "temperature", "tint"]) {
|
|
37
|
+
const c = r === "contrast" || r === "saturation" ? 0 : -1, n = r === "contrast" || r === "saturation" ? 2 : 1;
|
|
38
|
+
if (typeof t[r] != "number" || !Number.isFinite(t[r]) || t[r] < c || t[r] > n)
|
|
39
|
+
throw new Error("调色参数超出范围");
|
|
40
|
+
o[r] = t[r] === 0 ? 0 : t[r];
|
|
41
|
+
}
|
|
42
|
+
return o;
|
|
43
|
+
}
|
|
44
|
+
function A(t) {
|
|
45
|
+
const o = Object.keys(_);
|
|
46
|
+
if (t?.ratio === "alpha-bounds")
|
|
47
|
+
for (const a of ["padding", "paddingColor"]) Object.hasOwn(t, a) && o.push(a);
|
|
48
|
+
if (F(t, o), t.version !== 1) throw new Error("裁切版本不受支持");
|
|
49
|
+
if (!N.includes(t.anchor)) throw new Error("裁切位置无效");
|
|
50
|
+
let r = t.ratio;
|
|
51
|
+
if (r !== "original" && r !== "alpha-bounds") {
|
|
52
|
+
const [a, s] = R(r);
|
|
53
|
+
let e = a, i = s;
|
|
54
|
+
for (; i; ) {
|
|
55
|
+
const l = e % i;
|
|
56
|
+
e = i, i = l;
|
|
57
|
+
}
|
|
58
|
+
r = `${a / e}:${s / e}`;
|
|
59
|
+
}
|
|
60
|
+
const c = t.padding === void 0 ? 0 : B(t.padding), n = t.paddingColor === void 0 ? "transparent" : t.paddingColor;
|
|
61
|
+
if (n !== "transparent" && (typeof n != "string" || !/^#[0-9a-f]{6}$/i.test(n)))
|
|
62
|
+
throw new Error("留白颜色无效");
|
|
63
|
+
return {
|
|
64
|
+
version: 1,
|
|
65
|
+
ratio: r,
|
|
66
|
+
anchor: r === "alpha-bounds" ? "center" : t.anchor,
|
|
67
|
+
...c > 0 ? {
|
|
68
|
+
padding: c,
|
|
69
|
+
...n !== "transparent" ? { paddingColor: n.toLowerCase() } : {}
|
|
70
|
+
} : {}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function B(t) {
|
|
74
|
+
if (!Number.isSafeInteger(t) || t < 0 || t > 4096)
|
|
75
|
+
throw new Error("透明边距须为0至4096的整数");
|
|
76
|
+
return t;
|
|
77
|
+
}
|
|
78
|
+
function R(t) {
|
|
79
|
+
if (typeof t != "string") throw new Error("裁切比例无效");
|
|
80
|
+
const o = /^([1-9]\d{0,3}):([1-9]\d{0,3})$/.exec(t);
|
|
81
|
+
if (!o || o[0] !== t || Number(o[1]) > 4096 || Number(o[2]) > 4096)
|
|
82
|
+
throw new Error("裁切比例无效");
|
|
83
|
+
return [Number(o[1]), Number(o[2])];
|
|
84
|
+
}
|
|
85
|
+
function P(t) {
|
|
86
|
+
return t.brightness === 0 && t.contrast === 1 && t.saturation === 1 && t.vibrance === 0 && t.temperature === 0 && t.tint === 0;
|
|
87
|
+
}
|
|
88
|
+
function k(t, o) {
|
|
89
|
+
if (!Number.isSafeInteger(t) || !Number.isSafeInteger(o) || t < 1 || o < 1 || t * o > 24e6)
|
|
90
|
+
throw new Error("图片像素尺寸无效或超过24MP");
|
|
91
|
+
}
|
|
92
|
+
function S(t, o, r) {
|
|
93
|
+
if (k(o, r), !(t instanceof Uint8ClampedArray) || t.length !== o * r * 4)
|
|
94
|
+
throw new Error("图片RGBA数据无效");
|
|
95
|
+
}
|
|
96
|
+
function X(t, o, r, c) {
|
|
97
|
+
const n = O(c);
|
|
98
|
+
S(t, o, r);
|
|
99
|
+
const a = new Uint8ClampedArray(t);
|
|
100
|
+
if (P(n)) return a;
|
|
101
|
+
const s = 0.25 * n.brightness;
|
|
102
|
+
for (let e = 0; e < t.length; e += 4) {
|
|
103
|
+
if (t[e + 3] === 0) continue;
|
|
104
|
+
let i = (t[e] / 255 + s - 0.5) * n.contrast + 0.5, l = (t[e + 1] / 255 + s - 0.5) * n.contrast + 0.5, f = (t[e + 2] / 255 + s - 0.5) * n.contrast + 0.5;
|
|
105
|
+
const h = 0.2126 * i + 0.7152 * l + 0.0722 * f;
|
|
106
|
+
if (i = h + (i - h) * n.saturation, l = h + (l - h) * n.saturation, f = h + (f - h) * n.saturation, n.vibrance !== 0) {
|
|
107
|
+
const d = Math.max(i, l, f), p = Math.min(i, l, f), w = d > 0 ? C((d - p) / d) : 0, g = 1 + n.vibrance * (n.vibrance > 0 ? 1 - w : 1), m = 0.2126 * i + 0.7152 * l + 0.0722 * f;
|
|
108
|
+
i = m + (i - m) * g, l = m + (l - m) * g, f = m + (f - m) * g;
|
|
109
|
+
}
|
|
110
|
+
i *= 1 + 0.15 * n.temperature, f *= 1 - 0.15 * n.temperature, i *= 1 + 0.075 * n.tint, l *= 1 - 0.15 * n.tint, f *= 1 + 0.075 * n.tint, a[e] = C(i) * 255, a[e + 1] = C(l) * 255, a[e + 2] = C(f) * 255;
|
|
111
|
+
}
|
|
112
|
+
return a;
|
|
113
|
+
}
|
|
114
|
+
function H(t, o, r) {
|
|
115
|
+
k(t, o);
|
|
116
|
+
const c = A(r);
|
|
117
|
+
if (c.ratio === "alpha-bounds") throw new Error("透明边裁切须读取原尺寸alpha,请查看单图预览");
|
|
118
|
+
if (c.ratio === "original") return { x: 0, y: 0, width: t, height: o };
|
|
119
|
+
const [n, a] = R(c.ratio);
|
|
120
|
+
let s = t, e = o;
|
|
121
|
+
if (t * a > o * n ? s = Math.floor(o * n / a) : e = Math.floor(t * a / n), s < 1 || e < 1) throw new Error("图片太小,无法形成非空裁切框");
|
|
122
|
+
const i = N.indexOf(c.anchor), l = i % 3, f = Math.floor(i / 3), h = t - s, d = o - e, p = l === 0 ? 0 : l === 1 ? Math.floor(h / 2) : h, w = f === 0 ? 0 : f === 1 ? Math.floor(d / 2) : d;
|
|
123
|
+
return { x: p, y: w, width: s, height: e };
|
|
124
|
+
}
|
|
125
|
+
function V(t, o, r) {
|
|
126
|
+
S(t, o, r);
|
|
127
|
+
let c = o, n = r, a = -1, s = -1;
|
|
128
|
+
for (let e = 0; e < r; e++)
|
|
129
|
+
for (let i = 0; i < o; i++)
|
|
130
|
+
t[(e * o + i) * 4 + 3] !== 0 && (c = Math.min(c, i), n = Math.min(n, e), a = Math.max(a, i), s = Math.max(s, e));
|
|
131
|
+
return a < 0 ? { kind: "skip", reason: "fully-transparent" } : c === 0 && n === 0 && a === o - 1 && s === r - 1 ? { kind: "skip", reason: "no-transparent-border" } : {
|
|
132
|
+
kind: "crop",
|
|
133
|
+
rect: { x: c, y: n, width: a - c + 1, height: s - n + 1 }
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
const L = {
|
|
137
|
+
0: [1, 0, 0, 1],
|
|
138
|
+
90: [0, 1, -1, 0],
|
|
139
|
+
180: [-1, 0, 0, -1],
|
|
140
|
+
270: [0, -1, 1, 0]
|
|
141
|
+
}, Y = [
|
|
142
|
+
[1, 0, 0, 1],
|
|
143
|
+
[-1, 0, 0, 1],
|
|
144
|
+
[-1, 0, 0, -1],
|
|
145
|
+
[1, 0, 0, -1],
|
|
146
|
+
[0, 1, 1, 0],
|
|
147
|
+
[0, 1, -1, 0],
|
|
148
|
+
[0, -1, -1, 0],
|
|
149
|
+
[0, -1, 1, 0]
|
|
150
|
+
];
|
|
151
|
+
function U(t) {
|
|
152
|
+
if (F(t, Object.keys(z)), t.version !== 1) throw new Error("旋转版本不受支持");
|
|
153
|
+
if (![0, 90, 180, 270].includes(t.rotation)) throw new Error("旋转角度无效");
|
|
154
|
+
if (["upright", "flipHorizontal", "flipVertical"].some((o) => typeof t[o] != "boolean"))
|
|
155
|
+
throw new Error("旋转参数无效");
|
|
156
|
+
return {
|
|
157
|
+
version: 1,
|
|
158
|
+
upright: t.upright,
|
|
159
|
+
rotation: t.rotation === 0 ? 0 : t.rotation,
|
|
160
|
+
flipHorizontal: t.flipHorizontal,
|
|
161
|
+
flipVertical: t.flipVertical
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
function v(t) {
|
|
165
|
+
const [o, r, c, n] = L[t.rotation], a = t.flipHorizontal ? -1 : 1, s = t.flipVertical ? -1 : 1;
|
|
166
|
+
return [o * a, r * s, c * a, n * s].map(
|
|
167
|
+
(e) => e === 0 ? 0 : e
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
function W(t, o, r, c, n) {
|
|
171
|
+
const a = U(c);
|
|
172
|
+
if (S(t, o, r), !Number.isInteger(n) || n < 1 || n > 8)
|
|
173
|
+
throw new Error("图片Exif方向未知或无效");
|
|
174
|
+
let s = v(a);
|
|
175
|
+
if (a.upright) {
|
|
176
|
+
const [e, i, l, f] = Y[n - 1], [h, d, p, w] = s;
|
|
177
|
+
s = [h * e + p * i, d * e + w * i, h * l + p * f, d * l + w * f].map(
|
|
178
|
+
(g) => g === 0 ? 0 : g
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
return $(t, o, r, s);
|
|
182
|
+
}
|
|
183
|
+
function $(t, o, r, c) {
|
|
184
|
+
const [n, a, s, e] = c, i = Math.abs(n) * o + Math.abs(s) * r, l = Math.abs(a) * o + Math.abs(e) * r;
|
|
185
|
+
if (n === 1 && a === 0 && s === 0 && e === 1)
|
|
186
|
+
return { data: new Uint8ClampedArray(t), width: o, height: r };
|
|
187
|
+
const f = new Uint8ClampedArray(t.length), h = (n < 0 ? o - 1 : 0) + (s < 0 ? r - 1 : 0), d = (a < 0 ? o - 1 : 0) + (e < 0 ? r - 1 : 0);
|
|
188
|
+
for (let p = 0; p < r; p++)
|
|
189
|
+
for (let w = 0; w < o; w++) {
|
|
190
|
+
const g = (p * o + w) * 4, m = n * w + s * p + h, M = ((a * w + e * p + d) * i + m) * 4;
|
|
191
|
+
f[M] = t[g], f[M + 1] = t[g + 1], f[M + 2] = t[g + 2], f[M + 3] = t[g + 3];
|
|
192
|
+
}
|
|
193
|
+
return { data: f, width: i, height: l };
|
|
194
|
+
}
|
|
195
|
+
const D = 25 * 1024 * 1024, q = Math.ceil(D / 4096), G = 1024 * 1024, u = () => new Error("图片方向元数据无效或不完整,无法预览原始方向"), E = (t, o, r) => o + r.length <= t.length && [...r].every((c, n) => t[o + n] === c.charCodeAt(0));
|
|
196
|
+
function K(t) {
|
|
197
|
+
if (t.length < 8 || t.length > G) throw u();
|
|
198
|
+
const o = E(t, 0, "II");
|
|
199
|
+
if (!o && !E(t, 0, "MM")) throw u();
|
|
200
|
+
const r = new DataView(t.buffer, t.byteOffset, t.byteLength);
|
|
201
|
+
if (r.getUint16(2, o) !== 42) throw u();
|
|
202
|
+
const c = r.getUint32(4, o);
|
|
203
|
+
if (c < 8 || c + 2 > t.length) throw u();
|
|
204
|
+
const n = r.getUint16(c, o);
|
|
205
|
+
if (c + 2 + n * 12 + 4 > t.length) throw u();
|
|
206
|
+
let a = 1, s = !1;
|
|
207
|
+
for (let e = 0; e < n; e++) {
|
|
208
|
+
const i = c + 2 + e * 12;
|
|
209
|
+
if (r.getUint16(i, o) === 274) {
|
|
210
|
+
if (s || r.getUint16(i + 2, o) !== 3 || r.getUint32(i + 4, o) !== 1 || (a = r.getUint16(i + 8, o), a < 1 || a > 8)) throw u();
|
|
211
|
+
s = !0;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return a;
|
|
215
|
+
}
|
|
216
|
+
function J(t) {
|
|
217
|
+
if (t.length > D) throw new Error("图片超过25 MiB");
|
|
218
|
+
const o = new DataView(t.buffer, t.byteOffset, t.byteLength), r = { orientation: 1, ranges: [], webp: !1 }, c = (n, a, s) => {
|
|
219
|
+
if (r.ranges.length) throw u();
|
|
220
|
+
r.orientation = K(s), r.ranges.push({ start: n, end: a });
|
|
221
|
+
};
|
|
222
|
+
if (t[0] === 255 && t[1] === 216) {
|
|
223
|
+
let n = 2, a = 0;
|
|
224
|
+
for (; n < t.length; ) {
|
|
225
|
+
if (++a > 4096 || t[n] !== 255) throw u();
|
|
226
|
+
const s = n;
|
|
227
|
+
for (; t[n] === 255; ) n++;
|
|
228
|
+
if (n >= t.length) throw u();
|
|
229
|
+
const e = t[n++];
|
|
230
|
+
if (e === 217) return r;
|
|
231
|
+
if (e === 1 || e >= 208 && e <= 215) continue;
|
|
232
|
+
if (!e || e === 216 || n + 2 > t.length) throw u();
|
|
233
|
+
const i = o.getUint16(n), l = n + i;
|
|
234
|
+
if (i < 2 || l > t.length) throw u();
|
|
235
|
+
if (e === 218) return r;
|
|
236
|
+
const f = n + 2;
|
|
237
|
+
if (e === 225 && E(t, f, "Exif")) {
|
|
238
|
+
if (i < 8 || !E(t, f, "Exif\0\0")) throw u();
|
|
239
|
+
c(s, l, t.subarray(f + 6, l));
|
|
240
|
+
}
|
|
241
|
+
n = l;
|
|
242
|
+
}
|
|
243
|
+
throw u();
|
|
244
|
+
}
|
|
245
|
+
if (t.length >= 8 && t.subarray(0, 8).every((n, a) => n === [137, 80, 78, 71, 13, 10, 26, 10][a])) {
|
|
246
|
+
let n = 8, a = 0, s = 0;
|
|
247
|
+
for (; n < t.length; ) {
|
|
248
|
+
if (n + 12 > t.length || (E(t, n + 4, "IDAT") ? ++a > q : ++s > 4096))
|
|
249
|
+
throw u();
|
|
250
|
+
const e = o.getUint32(n), i = n + 12 + e;
|
|
251
|
+
if (i > t.length) throw u();
|
|
252
|
+
if (E(t, n + 4, "eXIf") && c(n, i, t.subarray(n + 8, i - 4)), E(t, n + 4, "IEND")) {
|
|
253
|
+
if (e !== 0 || i !== t.length) throw u();
|
|
254
|
+
return r;
|
|
255
|
+
}
|
|
256
|
+
n = i;
|
|
257
|
+
}
|
|
258
|
+
throw u();
|
|
259
|
+
}
|
|
260
|
+
if (E(t, 0, "RIFF") && E(t, 8, "WEBP")) {
|
|
261
|
+
if (o.getUint32(4, !0) + 8 !== t.length) throw u();
|
|
262
|
+
r.webp = !0;
|
|
263
|
+
let n = 12, a = 0;
|
|
264
|
+
for (; n < t.length; ) {
|
|
265
|
+
if (++a > 4096 || n + 8 > t.length) throw u();
|
|
266
|
+
const s = o.getUint32(n + 4, !0), e = n + 8 + s, i = e + s % 2;
|
|
267
|
+
if (i > t.length) throw u();
|
|
268
|
+
if (E(t, n, "VP8X")) {
|
|
269
|
+
if (s !== 10 || r.webpFlags !== void 0) throw u();
|
|
270
|
+
r.webpFlags = n + 8;
|
|
271
|
+
}
|
|
272
|
+
if (E(t, n, "EXIF")) {
|
|
273
|
+
const l = n + 8;
|
|
274
|
+
c(
|
|
275
|
+
n,
|
|
276
|
+
i,
|
|
277
|
+
t.subarray(E(t, l, "Exif\0\0") ? l + 6 : l, e)
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
n = i;
|
|
281
|
+
}
|
|
282
|
+
if (r.webpFlags !== void 0 && t[r.webpFlags] & 8 && !r.ranges.length)
|
|
283
|
+
throw u();
|
|
284
|
+
return r;
|
|
285
|
+
}
|
|
286
|
+
throw u();
|
|
287
|
+
}
|
|
288
|
+
async function Q(t) {
|
|
289
|
+
if (t.size > D) throw new Error("图片超过25 MiB");
|
|
290
|
+
const o = new Uint8Array(await t.arrayBuffer()), r = J(o);
|
|
291
|
+
if (!r.ranges.length) return { blob: t, orientation: r.orientation };
|
|
292
|
+
const c = r.ranges.reduce((e, i) => e + i.end - i.start, 0), n = new Uint8Array(o.length - c);
|
|
293
|
+
let a = 0, s = 0;
|
|
294
|
+
for (const e of r.ranges)
|
|
295
|
+
n.set(o.subarray(a, e.start), s), s += e.start - a, a = e.end;
|
|
296
|
+
if (n.set(o.subarray(a), s), r.webp && (new DataView(n.buffer).setUint32(4, n.length - 8, !0), r.webpFlags !== void 0)) {
|
|
297
|
+
const e = r.ranges.reduce(
|
|
298
|
+
(i, l) => i + (l.end <= r.webpFlags ? l.end - l.start : 0),
|
|
299
|
+
0
|
|
300
|
+
);
|
|
301
|
+
n[r.webpFlags - e] &= -9;
|
|
302
|
+
}
|
|
303
|
+
return { blob: new Blob([n.buffer], { type: t.type }), orientation: r.orientation };
|
|
304
|
+
}
|
|
305
|
+
async function Z(t) {
|
|
306
|
+
const { blob: o, recipe: r, maxEdge: c } = t;
|
|
307
|
+
if (!Number.isInteger(c) || c < 1 || c > 768)
|
|
308
|
+
throw new Error("预览尺寸须为1至768的整数");
|
|
309
|
+
if (o.size > 25 * 1024 * 1024) throw new Error("图片超过25 MiB");
|
|
310
|
+
const n = r.tool === "adjust" ? O(r.params) : r.tool === "orient" ? U(r.params) : A(r.params);
|
|
311
|
+
let a;
|
|
312
|
+
try {
|
|
313
|
+
const s = r.tool === "orient" ? await Q(o) : { blob: o, orientation: 1 };
|
|
314
|
+
a = await createImageBitmap(s.blob, {
|
|
315
|
+
// Match the final orient decoder's alpha rounding on the raw EXIF-free copy.
|
|
316
|
+
imageOrientation: r.tool === "orient" ? "none" : "from-image",
|
|
317
|
+
colorSpaceConversion: "default",
|
|
318
|
+
premultiplyAlpha: r.tool === "orient" ? "default" : "none"
|
|
319
|
+
});
|
|
320
|
+
const e = a.width, i = a.height;
|
|
321
|
+
if (e * i > 24e6) throw new Error("图片超过2400万像素");
|
|
322
|
+
if (!e || !i) throw new Error("无法解码图片尺寸");
|
|
323
|
+
const l = Math.min(1, c / Math.max(e, i));
|
|
324
|
+
let f = Math.max(1, Math.round(e * l)), h = Math.max(1, Math.round(i * l));
|
|
325
|
+
const d = new OffscreenCanvas(f, h), p = d.getContext("2d", {
|
|
326
|
+
willReadFrequently: r.tool !== "crop",
|
|
327
|
+
colorSpace: "srgb"
|
|
328
|
+
});
|
|
329
|
+
if (!p) throw new Error("当前浏览器无法生成图片预览");
|
|
330
|
+
p.drawImage(a, 0, 0, f, h);
|
|
331
|
+
let w, g, m;
|
|
332
|
+
if (r.tool === "adjust") {
|
|
333
|
+
const M = p.getImageData(0, 0, f, h), x = X(M.data, f, h, O(n));
|
|
334
|
+
p.putImageData(new ImageData(new Uint8ClampedArray(x), f, h), 0, 0);
|
|
335
|
+
} else if (r.tool === "orient") {
|
|
336
|
+
const M = p.getImageData(0, 0, f, h), x = U(n), b = W(M.data, f, h, x, s.orientation), I = x.upright && s.orientation >= 5, j = x.rotation === 90 || x.rotation === 270;
|
|
337
|
+
g = I !== j ? { width: i, height: e } : { width: e, height: i }, f = b.width, h = b.height, d.width = f, d.height = h, p.putImageData(
|
|
338
|
+
new ImageData(new Uint8ClampedArray(b.data), f, h),
|
|
339
|
+
0,
|
|
340
|
+
0
|
|
341
|
+
);
|
|
342
|
+
} else {
|
|
343
|
+
const M = A(n);
|
|
344
|
+
if (M.ratio === "alpha-bounds") {
|
|
345
|
+
const x = new OffscreenCanvas(e, i), b = x.getContext("2d", {
|
|
346
|
+
willReadFrequently: !0,
|
|
347
|
+
colorSpace: "srgb"
|
|
348
|
+
});
|
|
349
|
+
if (!b) throw new Error("无法读取原尺寸alpha");
|
|
350
|
+
b.drawImage(a, 0, 0);
|
|
351
|
+
const I = V(
|
|
352
|
+
b.getImageData(0, 0, e, i).data,
|
|
353
|
+
e,
|
|
354
|
+
i
|
|
355
|
+
);
|
|
356
|
+
m = I, w = I.kind === "crop" ? I.rect : { x: 0, y: 0, width: e, height: i }, x.width = x.height = 1;
|
|
357
|
+
} else w = H(e, i, M);
|
|
358
|
+
}
|
|
359
|
+
return {
|
|
360
|
+
blob: await d.convertToBlob({ type: "image/png" }),
|
|
361
|
+
width: f,
|
|
362
|
+
height: h,
|
|
363
|
+
sourceWidth: e,
|
|
364
|
+
sourceHeight: i,
|
|
365
|
+
...w ? { cropRect: w } : {},
|
|
366
|
+
...m ? { alphaBounds: m } : {},
|
|
367
|
+
...g ? { orientationSize: g } : {}
|
|
368
|
+
};
|
|
369
|
+
} finally {
|
|
370
|
+
a?.close();
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
self.onmessage = async (t) => {
|
|
374
|
+
const { id: o } = t.data;
|
|
375
|
+
try {
|
|
376
|
+
self.postMessage({ id: o, ...await Z(t.data) });
|
|
377
|
+
} catch (r) {
|
|
378
|
+
self.postMessage({ id: o, error: r instanceof Error ? r.message : "图片预览失败" });
|
|
379
|
+
}
|
|
380
|
+
};
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|