@agimon-ai/po-cloudflare 0.0.2-alpha.11 → 0.0.2-alpha.13
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/dist/agent-DYFqCLl2.js +6850 -0
- package/dist/assets/plugins/assets/base-C3j1WCCq.css +2 -0
- package/dist/assets/plugins/chunks/po-web-runtime-Czm_C4SJ.js +1 -0
- package/dist/assets/plugins/compositions.json +1 -1
- package/dist/assets/plugins/slots/approval.8b3f37d9-CqQk6XG_.js +2 -0
- package/dist/assets/plugins/slots/artifacts.47d00f81-D-vQ-7Iz.js +1 -0
- package/dist/assets/plugins/slots/autocompact.9a92993d-B3KTYwW1.js +1 -0
- package/dist/assets/plugins/slots/builtin-tools.939bbfff-CZRYQVIP.js +7 -0
- package/dist/assets/plugins/slots/codemode.782e5bb1-Bzl_K_vt.js +10 -0
- package/dist/assets/plugins/slots/domain.21790b66-CvnpuKCY.js +1 -0
- package/dist/assets/plugins/slots/edit.c7c85129-kaxIknZ-.js +7 -0
- package/dist/assets/plugins/slots/files.bbcef824-wuB8gcQA.js +2 -0
- package/dist/assets/plugins/slots/grep.3dfd3214-3FnU8p-d.js +1 -0
- package/dist/assets/plugins/slots/log.33bc7d38-C0PXQ0O1.js +4 -0
- package/dist/assets/plugins/slots/mcp.59c68bcb-D0CkHnIw.js +109 -0
- package/dist/assets/plugins/slots/{profile.ab16dcec-B5yt7eny.js → profile.ea55f5e1-BSY3iYfJ.js} +1 -1
- package/dist/assets/plugins/slots/prompts.9957cc84-xdCkNkoA.js +3 -0
- package/dist/assets/plugins/slots/read.30a617e7-qqaxVlEX.js +1 -0
- package/dist/assets/plugins/slots/runner.9f3559b0-DfO2Z9HG.js +8 -0
- package/dist/assets/plugins/slots/skill.f506a5ea-CL_n-l4h.js +4 -0
- package/dist/assets/plugins/slots/vault.01657352-DbG3F_on.js +1 -0
- package/dist/{atomicJson-C_lN9leA.js → atomicJson-BF1fVXy1.js} +1 -1
- package/dist/browser-BWf8OMfl.js +3 -0
- package/dist/childSession-Cf2-kH4O.js +22 -0
- package/dist/{server-D190dXDN.js → dist-B-vqs6tA.js} +1 -546
- package/dist/{domains-CPX1dEVa.js → domains-Bl6T2dKV.js} +2 -2
- package/dist/{server-C5wixba6.js → esm-BKJy3O9-.js} +3 -296
- package/dist/{exports-2Vv52b9v.js → exports-CxkWsXI9.js} +7 -6
- package/dist/{exports-BF12Ftrd.js → exports-DlcCEAe3.js} +2 -9
- package/dist/{extensionFile-DpVvh-ud.js → extensionFile-D7wk8tFr.js} +11 -1
- package/dist/harnessStore-Bap8lsAg.js +1 -0
- package/dist/{harnessStore-Ct329wxJ.js → harnessStore-flLz1I0F.js} +2 -2
- package/dist/help-DjybmnPW.js +91 -0
- package/dist/{hubChannel-kFgtfJnv.js → hubChannel-Bi3PQrfD.js} +3 -27
- package/dist/hubRevisions-58pU2dW5.js +363 -0
- package/dist/index.edge-C9_xuXyy.js +57 -0
- package/dist/{index.edge-DhV_hfZA.js → index.edge-CJ2TFpgF.js} +2 -2
- package/dist/index.edge-COJJ_Dv2.js +937 -0
- package/dist/index.edge-ChYa2LU4.js +14 -0
- package/dist/index.edge-ClLTmPFz.js +191 -0
- package/dist/{index.edge-BNElrrHY.js → index.edge-uSjRpm6Z.js} +5 -0
- package/dist/iso-BPQViXM8.js +10 -0
- package/dist/{layeredConfig-BhFC6TBD.js → layeredConfig-B4s0eZ5o.js} +11 -4
- package/dist/{majorModes-CZqrWarh.js → majorModes-IygGmbb8.js} +2 -2
- package/dist/majorModes-xpLK9HpD.js +1 -0
- package/dist/notification-bGq1frYG.js +99 -0
- package/dist/piConfig-CcoMX-1L.js +127 -0
- package/dist/{platformFiles-BTDsAsmT.js → platformFiles-Ccj9HCvA.js} +24 -2
- package/dist/pluginContributions-Be9EnCAW.js +16 -0
- package/dist/sealedChannel-BeWNTWys.js +27 -0
- package/dist/server-4CmqIbH2.js +1476 -0
- package/dist/{server-DesPQYzJ.js → server-5vLvBTTs.js} +1 -1
- package/dist/server-BHhb0oir.js +505 -0
- package/dist/server-Bm6pAAw8.js +935 -0
- package/dist/server-C82Qzoh3.js +2658 -0
- package/dist/server-C8HyW7wN.js +489 -0
- package/dist/{server-DSusAvqK.js → server-C9gff7gU.js} +1 -1
- package/dist/{server-CTIkoJXM.js → server-CIhwIcbA.js} +4 -4
- package/dist/{server-DbmCxFL-.js → server-CMaTba5B.js} +1 -1
- package/dist/{server-DolHpEoY.js → server-COE7BKSa.js} +1 -1
- package/dist/server-CQXqMpeC.js +1744 -0
- package/dist/{server-BG6gwBcv.js → server-CTSvwoDy.js} +5 -4
- package/dist/server-C_34VM3M.js +217 -0
- package/dist/{server-CuGXhVFA.js → server-C_3jK2WM.js} +5 -5
- package/dist/server-CcNMwEFQ.js +190 -0
- package/dist/{server-D-zQp04y.js → server-CjsKNdSN.js} +1 -1
- package/dist/{server-DQy8hVXg.js → server-ClsNJwdv.js} +8 -8
- package/dist/{server-DfBHHyQo.js → server-Co57A8MH.js} +2 -9
- package/dist/{server-CRtXiNBP.js → server-CpJNq249.js} +5 -5
- package/dist/{server-zYYAg7ki.js → server-CxGGQFJs.js} +5 -16
- package/dist/{server-DpVsUiA-.js → server-DSu_uLDX.js} +4 -4
- package/dist/server-DeSuziRK.js +680 -0
- package/dist/{server-BIjpcE0Y.js → server-ZsazKk-n.js} +3 -3
- package/dist/{server-CZoHLCxk.js → server-il_s2Ycz.js} +5 -93
- package/dist/server-ziNfBZ2M.js +295 -0
- package/dist/{sessionConfig-BLmM5XLM.js → sessionConfig-DzAs6Pt-.js} +64 -499
- package/dist/{notification-qvyJJ_Df.js → telemetry-Csv1ZxAn.js} +1 -99
- package/dist/truncate-M3KbFyVj.js +89 -0
- package/dist/web-Cfvbn9H1.js +3 -0
- package/dist/worker.js +4545 -12244
- package/dist/workflow-w5JPZXgc.js +23 -0
- package/package.json +32 -24
- package/dist/assets/plugins/assets/base-_m1hGahv.css +0 -2
- package/dist/assets/plugins/chunks/po-web-runtime-CGjOl_1I.js +0 -1
- package/dist/assets/plugins/slots/approval.09e72f36-BW92gZQg.js +0 -2
- package/dist/assets/plugins/slots/artifacts.50b639bb-B6zDJhex.js +0 -1
- package/dist/assets/plugins/slots/builtin-tools.75108f21-DS-dJ07p.js +0 -7
- package/dist/assets/plugins/slots/codemode.c58fb583--t-nrGeQ.js +0 -10
- package/dist/assets/plugins/slots/domain.753f9f92-DWSqP3Jw.js +0 -1
- package/dist/assets/plugins/slots/mcp.82cc1ff5-jPY2OCuu.js +0 -109
- package/dist/assets/plugins/slots/skill.62a0a1b3-GtWLT33O.js +0 -4
- package/dist/assets/plugins/slots/vault.3cbfcdc3-B7BKfR_H.js +0 -1
- package/dist/harnessStore-BDI-s999.js +0 -1
- package/dist/majorModes-CzAWXyaf.js +0 -1
|
@@ -0,0 +1,937 @@
|
|
|
1
|
+
import photonWasm from "./photon_rs_bg.wasm";
|
|
2
|
+
//#region ../../../node_modules/.pnpm/@silvia-odwyer+photon@0.3.3/node_modules/@silvia-odwyer/photon/photon_rs.js
|
|
3
|
+
let wasm;
|
|
4
|
+
function debugString(val) {
|
|
5
|
+
const type = typeof val;
|
|
6
|
+
if (type == "number" || type == "boolean" || val == null) return `${val}`;
|
|
7
|
+
if (type == "string") return `"${val}"`;
|
|
8
|
+
if (type == "symbol") {
|
|
9
|
+
const description = val.description;
|
|
10
|
+
if (description == null) return "Symbol";
|
|
11
|
+
else return `Symbol(${description})`;
|
|
12
|
+
}
|
|
13
|
+
if (type == "function") {
|
|
14
|
+
const name = val.name;
|
|
15
|
+
if (typeof name == "string" && name.length > 0) return `Function(${name})`;
|
|
16
|
+
else return "Function";
|
|
17
|
+
}
|
|
18
|
+
if (Array.isArray(val)) {
|
|
19
|
+
const length = val.length;
|
|
20
|
+
let debug = "[";
|
|
21
|
+
if (length > 0) debug += debugString(val[0]);
|
|
22
|
+
for (let i = 1; i < length; i++) debug += ", " + debugString(val[i]);
|
|
23
|
+
debug += "]";
|
|
24
|
+
return debug;
|
|
25
|
+
}
|
|
26
|
+
const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
|
|
27
|
+
let className;
|
|
28
|
+
if (builtInMatches.length > 1) className = builtInMatches[1];
|
|
29
|
+
else return toString.call(val);
|
|
30
|
+
if (className == "Object") try {
|
|
31
|
+
return "Object(" + JSON.stringify(val) + ")";
|
|
32
|
+
} catch (_) {
|
|
33
|
+
return "Object";
|
|
34
|
+
}
|
|
35
|
+
if (val instanceof Error) return `${val.name}: ${val.message}\n${val.stack}`;
|
|
36
|
+
return className;
|
|
37
|
+
}
|
|
38
|
+
let WASM_VECTOR_LEN = 0;
|
|
39
|
+
let cachedUint8ArrayMemory0 = null;
|
|
40
|
+
function getUint8ArrayMemory0() {
|
|
41
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
42
|
+
return cachedUint8ArrayMemory0;
|
|
43
|
+
}
|
|
44
|
+
const cachedTextEncoder = typeof TextEncoder !== "undefined" ? new TextEncoder("utf-8") : { encode: () => {
|
|
45
|
+
throw Error("TextEncoder not available");
|
|
46
|
+
} };
|
|
47
|
+
const encodeString = typeof cachedTextEncoder.encodeInto === "function" ? function(arg, view) {
|
|
48
|
+
return cachedTextEncoder.encodeInto(arg, view);
|
|
49
|
+
} : function(arg, view) {
|
|
50
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
51
|
+
view.set(buf);
|
|
52
|
+
return {
|
|
53
|
+
read: arg.length,
|
|
54
|
+
written: buf.length
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
58
|
+
if (realloc === void 0) {
|
|
59
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
60
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
61
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
62
|
+
WASM_VECTOR_LEN = buf.length;
|
|
63
|
+
return ptr;
|
|
64
|
+
}
|
|
65
|
+
let len = arg.length;
|
|
66
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
67
|
+
const mem = getUint8ArrayMemory0();
|
|
68
|
+
let offset = 0;
|
|
69
|
+
for (; offset < len; offset++) {
|
|
70
|
+
const code = arg.charCodeAt(offset);
|
|
71
|
+
if (code > 127) break;
|
|
72
|
+
mem[ptr + offset] = code;
|
|
73
|
+
}
|
|
74
|
+
if (offset !== len) {
|
|
75
|
+
if (offset !== 0) arg = arg.slice(offset);
|
|
76
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
77
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
78
|
+
const ret = encodeString(arg, view);
|
|
79
|
+
offset += ret.written;
|
|
80
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
81
|
+
}
|
|
82
|
+
WASM_VECTOR_LEN = offset;
|
|
83
|
+
return ptr;
|
|
84
|
+
}
|
|
85
|
+
let cachedDataViewMemory0 = null;
|
|
86
|
+
function getDataViewMemory0() {
|
|
87
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || cachedDataViewMemory0.buffer.detached === void 0 && cachedDataViewMemory0.buffer !== wasm.memory.buffer) cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
88
|
+
return cachedDataViewMemory0;
|
|
89
|
+
}
|
|
90
|
+
const cachedTextDecoder = typeof TextDecoder !== "undefined" ? new TextDecoder("utf-8", {
|
|
91
|
+
ignoreBOM: true,
|
|
92
|
+
fatal: true
|
|
93
|
+
}) : { decode: () => {
|
|
94
|
+
throw Error("TextDecoder not available");
|
|
95
|
+
} };
|
|
96
|
+
if (typeof TextDecoder !== "undefined") cachedTextDecoder.decode();
|
|
97
|
+
function getStringFromWasm0(ptr, len) {
|
|
98
|
+
ptr = ptr >>> 0;
|
|
99
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
100
|
+
}
|
|
101
|
+
function _assertClass(instance, klass) {
|
|
102
|
+
if (!(instance instanceof klass)) throw new Error(`expected instance of ${klass.name}`);
|
|
103
|
+
return instance.ptr;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Flip an image horizontally.
|
|
107
|
+
*
|
|
108
|
+
* # Arguments
|
|
109
|
+
* * `img` - A PhotonImage.
|
|
110
|
+
*
|
|
111
|
+
* # Example
|
|
112
|
+
*
|
|
113
|
+
* ```no_run
|
|
114
|
+
* // For example, to flip an image horizontally:
|
|
115
|
+
* use photon_rs::native::open_image;
|
|
116
|
+
* use photon_rs::transform::fliph;
|
|
117
|
+
*
|
|
118
|
+
* let mut img = open_image("img.jpg").expect("File should open");
|
|
119
|
+
* fliph(&mut img);
|
|
120
|
+
* ```
|
|
121
|
+
* @param {PhotonImage} photon_image
|
|
122
|
+
*/
|
|
123
|
+
function fliph(photon_image) {
|
|
124
|
+
_assertClass(photon_image, PhotonImage);
|
|
125
|
+
wasm.fliph(photon_image.__wbg_ptr);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Flip an image vertically.
|
|
129
|
+
*
|
|
130
|
+
* # Arguments
|
|
131
|
+
* * `img` - A PhotonImage.
|
|
132
|
+
*
|
|
133
|
+
* # Example
|
|
134
|
+
*
|
|
135
|
+
* ```no_run
|
|
136
|
+
* // For example, to flip an image vertically:
|
|
137
|
+
* use photon_rs::native::open_image;
|
|
138
|
+
* use photon_rs::transform::flipv;
|
|
139
|
+
*
|
|
140
|
+
* let mut img = open_image("img.jpg").expect("File should open");
|
|
141
|
+
* flipv(&mut img);
|
|
142
|
+
* ```
|
|
143
|
+
* @param {PhotonImage} photon_image
|
|
144
|
+
*/
|
|
145
|
+
function flipv(photon_image) {
|
|
146
|
+
_assertClass(photon_image, PhotonImage);
|
|
147
|
+
wasm.flipv(photon_image.__wbg_ptr);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Resize an image.
|
|
151
|
+
*
|
|
152
|
+
* # Arguments
|
|
153
|
+
* * `img` - A PhotonImage.
|
|
154
|
+
* * `width` - New width.
|
|
155
|
+
* * `height` - New height.
|
|
156
|
+
* * `sampling_filter` - Nearest = 1, Triangle = 2, CatmullRom = 3, Gaussian = 4, Lanczos3 = 5
|
|
157
|
+
* @param {PhotonImage} photon_img
|
|
158
|
+
* @param {number} width
|
|
159
|
+
* @param {number} height
|
|
160
|
+
* @param {SamplingFilter} sampling_filter
|
|
161
|
+
* @returns {PhotonImage}
|
|
162
|
+
*/
|
|
163
|
+
function resize(photon_img, width, height, sampling_filter) {
|
|
164
|
+
_assertClass(photon_img, PhotonImage);
|
|
165
|
+
const ret = wasm.resize(photon_img.__wbg_ptr, width, height, sampling_filter);
|
|
166
|
+
return PhotonImage.__wrap(ret);
|
|
167
|
+
}
|
|
168
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
169
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
170
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
171
|
+
WASM_VECTOR_LEN = arg.length;
|
|
172
|
+
return ptr;
|
|
173
|
+
}
|
|
174
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
175
|
+
ptr = ptr >>> 0;
|
|
176
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
177
|
+
}
|
|
178
|
+
function isLikeNone(x) {
|
|
179
|
+
return x === void 0 || x === null;
|
|
180
|
+
}
|
|
181
|
+
function addToExternrefTable0(obj) {
|
|
182
|
+
const idx = wasm.__externref_table_alloc();
|
|
183
|
+
wasm.__wbindgen_export_2.set(idx, obj);
|
|
184
|
+
return idx;
|
|
185
|
+
}
|
|
186
|
+
function handleError(f, args) {
|
|
187
|
+
try {
|
|
188
|
+
return f.apply(this, args);
|
|
189
|
+
} catch (e) {
|
|
190
|
+
const idx = addToExternrefTable0(e);
|
|
191
|
+
wasm.__wbindgen_exn_store(idx);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
let cachedUint8ClampedArrayMemory0 = null;
|
|
195
|
+
function getUint8ClampedArrayMemory0() {
|
|
196
|
+
if (cachedUint8ClampedArrayMemory0 === null || cachedUint8ClampedArrayMemory0.byteLength === 0) cachedUint8ClampedArrayMemory0 = new Uint8ClampedArray(wasm.memory.buffer);
|
|
197
|
+
return cachedUint8ClampedArrayMemory0;
|
|
198
|
+
}
|
|
199
|
+
function getClampedArrayU8FromWasm0(ptr, len) {
|
|
200
|
+
ptr = ptr >>> 0;
|
|
201
|
+
return getUint8ClampedArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
202
|
+
}
|
|
203
|
+
const SamplingFilter = Object.freeze({
|
|
204
|
+
Nearest: 1,
|
|
205
|
+
"1": "Nearest",
|
|
206
|
+
Triangle: 2,
|
|
207
|
+
"2": "Triangle",
|
|
208
|
+
CatmullRom: 3,
|
|
209
|
+
"3": "CatmullRom",
|
|
210
|
+
Gaussian: 4,
|
|
211
|
+
"4": "Gaussian",
|
|
212
|
+
Lanczos3: 5,
|
|
213
|
+
"5": "Lanczos3"
|
|
214
|
+
});
|
|
215
|
+
const PhotonImageFinalization = typeof FinalizationRegistry === "undefined" ? {
|
|
216
|
+
register: () => {},
|
|
217
|
+
unregister: () => {}
|
|
218
|
+
} : new FinalizationRegistry((ptr) => wasm.__wbg_photonimage_free(ptr >>> 0, 1));
|
|
219
|
+
/**
|
|
220
|
+
* Provides the image's height, width, and contains the image's raw pixels.
|
|
221
|
+
* For use when communicating between JS and WASM, and also natively.
|
|
222
|
+
*/
|
|
223
|
+
var PhotonImage = class PhotonImage {
|
|
224
|
+
static __wrap(ptr) {
|
|
225
|
+
ptr = ptr >>> 0;
|
|
226
|
+
const obj = Object.create(PhotonImage.prototype);
|
|
227
|
+
obj.__wbg_ptr = ptr;
|
|
228
|
+
PhotonImageFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
229
|
+
return obj;
|
|
230
|
+
}
|
|
231
|
+
__destroy_into_raw() {
|
|
232
|
+
const ptr = this.__wbg_ptr;
|
|
233
|
+
this.__wbg_ptr = 0;
|
|
234
|
+
PhotonImageFinalization.unregister(this);
|
|
235
|
+
return ptr;
|
|
236
|
+
}
|
|
237
|
+
free() {
|
|
238
|
+
const ptr = this.__destroy_into_raw();
|
|
239
|
+
wasm.__wbg_photonimage_free(ptr, 0);
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Create a new PhotonImage from a Vec of u8s, which represent raw pixels.
|
|
243
|
+
* @param {Uint8Array} raw_pixels
|
|
244
|
+
* @param {number} width
|
|
245
|
+
* @param {number} height
|
|
246
|
+
*/
|
|
247
|
+
constructor(raw_pixels, width, height) {
|
|
248
|
+
const ptr0 = passArray8ToWasm0(raw_pixels, wasm.__wbindgen_malloc);
|
|
249
|
+
const len0 = WASM_VECTOR_LEN;
|
|
250
|
+
const ret = wasm.photonimage_new(ptr0, len0, width, height);
|
|
251
|
+
this.__wbg_ptr = ret >>> 0;
|
|
252
|
+
PhotonImageFinalization.register(this, this.__wbg_ptr, this);
|
|
253
|
+
return this;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Create a new PhotonImage from a base64 string.
|
|
257
|
+
* @param {string} base64
|
|
258
|
+
* @returns {PhotonImage}
|
|
259
|
+
*/
|
|
260
|
+
static new_from_base64(base64) {
|
|
261
|
+
const ptr0 = passStringToWasm0(base64, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
262
|
+
const len0 = WASM_VECTOR_LEN;
|
|
263
|
+
const ret = wasm.base64_to_image(ptr0, len0);
|
|
264
|
+
return PhotonImage.__wrap(ret);
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Create a new PhotonImage from a byteslice.
|
|
268
|
+
* @param {Uint8Array} vec
|
|
269
|
+
* @returns {PhotonImage}
|
|
270
|
+
*/
|
|
271
|
+
static new_from_byteslice(vec) {
|
|
272
|
+
const ptr0 = passArray8ToWasm0(vec, wasm.__wbindgen_malloc);
|
|
273
|
+
const len0 = WASM_VECTOR_LEN;
|
|
274
|
+
const ret = wasm.photonimage_new_from_byteslice(ptr0, len0);
|
|
275
|
+
return PhotonImage.__wrap(ret);
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Create a new PhotonImage from a Blob/File.
|
|
279
|
+
* @param {Blob} blob
|
|
280
|
+
* @returns {PhotonImage}
|
|
281
|
+
*/
|
|
282
|
+
static new_from_blob(blob) {
|
|
283
|
+
const ret = wasm.photonimage_new_from_blob(blob);
|
|
284
|
+
return PhotonImage.__wrap(ret);
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Create a new PhotonImage from a HTMLImageElement
|
|
288
|
+
* @param {HTMLImageElement} image
|
|
289
|
+
* @returns {PhotonImage}
|
|
290
|
+
*/
|
|
291
|
+
static new_from_image(image) {
|
|
292
|
+
const ret = wasm.photonimage_new_from_image(image);
|
|
293
|
+
return PhotonImage.__wrap(ret);
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Get the width of the PhotonImage.
|
|
297
|
+
* @returns {number}
|
|
298
|
+
*/
|
|
299
|
+
get_width() {
|
|
300
|
+
return wasm.photonimage_get_width(this.__wbg_ptr) >>> 0;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Get the PhotonImage's pixels as a Vec of u8s.
|
|
304
|
+
* @returns {Uint8Array}
|
|
305
|
+
*/
|
|
306
|
+
get_raw_pixels() {
|
|
307
|
+
const ret = wasm.photonimage_get_raw_pixels(this.__wbg_ptr);
|
|
308
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
309
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
310
|
+
return v1;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Get the height of the PhotonImage.
|
|
314
|
+
* @returns {number}
|
|
315
|
+
*/
|
|
316
|
+
get_height() {
|
|
317
|
+
return wasm.photonimage_get_height(this.__wbg_ptr) >>> 0;
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Convert the PhotonImage to base64.
|
|
321
|
+
* @returns {string}
|
|
322
|
+
*/
|
|
323
|
+
get_base64() {
|
|
324
|
+
let deferred1_0;
|
|
325
|
+
let deferred1_1;
|
|
326
|
+
try {
|
|
327
|
+
const ret = wasm.photonimage_get_base64(this.__wbg_ptr);
|
|
328
|
+
deferred1_0 = ret[0];
|
|
329
|
+
deferred1_1 = ret[1];
|
|
330
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
331
|
+
} finally {
|
|
332
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Convert the PhotonImage to raw bytes. Returns PNG.
|
|
337
|
+
* @returns {Uint8Array}
|
|
338
|
+
*/
|
|
339
|
+
get_bytes() {
|
|
340
|
+
const ret = wasm.photonimage_get_bytes(this.__wbg_ptr);
|
|
341
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
342
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
343
|
+
return v1;
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Convert the PhotonImage to raw bytes. Returns a JPEG.
|
|
347
|
+
* @param {number} quality
|
|
348
|
+
* @returns {Uint8Array}
|
|
349
|
+
*/
|
|
350
|
+
get_bytes_jpeg(quality) {
|
|
351
|
+
const ret = wasm.photonimage_get_bytes_jpeg(this.__wbg_ptr, quality);
|
|
352
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
353
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
354
|
+
return v1;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Convert the PhotonImage to raw bytes. Returns a WEBP.
|
|
358
|
+
* @returns {Uint8Array}
|
|
359
|
+
*/
|
|
360
|
+
get_bytes_webp() {
|
|
361
|
+
const ret = wasm.photonimage_get_bytes_webp(this.__wbg_ptr);
|
|
362
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
363
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
364
|
+
return v1;
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Convert the PhotonImage's raw pixels to JS-compatible ImageData.
|
|
368
|
+
* @returns {ImageData}
|
|
369
|
+
*/
|
|
370
|
+
get_image_data() {
|
|
371
|
+
return wasm.photonimage_get_image_data(this.__wbg_ptr);
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Convert ImageData to raw pixels, and update the PhotonImage's raw pixels to this.
|
|
375
|
+
* @param {ImageData} img_data
|
|
376
|
+
*/
|
|
377
|
+
set_imgdata(img_data) {
|
|
378
|
+
wasm.photonimage_set_imgdata(this.__wbg_ptr, img_data);
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Calculates estimated filesize and returns number of bytes
|
|
382
|
+
* @returns {bigint}
|
|
383
|
+
*/
|
|
384
|
+
get_estimated_filesize() {
|
|
385
|
+
const ret = wasm.photonimage_get_estimated_filesize(this.__wbg_ptr);
|
|
386
|
+
return BigInt.asUintN(64, ret);
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
typeof FinalizationRegistry === "undefined" || new FinalizationRegistry((ptr) => wasm.__wbg_rgb_free(ptr >>> 0, 1));
|
|
390
|
+
typeof FinalizationRegistry === "undefined" || new FinalizationRegistry((ptr) => wasm.__wbg_rgba_free(ptr >>> 0, 1));
|
|
391
|
+
async function __wbg_load(module, imports) {
|
|
392
|
+
if (typeof Response === "function" && module instanceof Response) {
|
|
393
|
+
if (typeof WebAssembly.instantiateStreaming === "function") try {
|
|
394
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
395
|
+
} catch (e) {
|
|
396
|
+
if (module.headers.get("Content-Type") != "application/wasm") console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
397
|
+
else throw e;
|
|
398
|
+
}
|
|
399
|
+
const bytes = await module.arrayBuffer();
|
|
400
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
401
|
+
} else {
|
|
402
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
403
|
+
if (instance instanceof WebAssembly.Instance) return {
|
|
404
|
+
instance,
|
|
405
|
+
module
|
|
406
|
+
};
|
|
407
|
+
else return instance;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
function __wbg_get_imports() {
|
|
411
|
+
const imports = {};
|
|
412
|
+
imports.wbg = {};
|
|
413
|
+
imports.wbg.__wbg_new_abda76e883ba8a5f = function() {
|
|
414
|
+
return /* @__PURE__ */ new Error();
|
|
415
|
+
};
|
|
416
|
+
imports.wbg.__wbg_stack_658279fe44541cf6 = function(arg0, arg1) {
|
|
417
|
+
const ret = arg1.stack;
|
|
418
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
419
|
+
const len1 = WASM_VECTOR_LEN;
|
|
420
|
+
getDataViewMemory0().setInt32(arg0 + 4, len1, true);
|
|
421
|
+
getDataViewMemory0().setInt32(arg0 + 0, ptr1, true);
|
|
422
|
+
};
|
|
423
|
+
imports.wbg.__wbg_error_f851667af71bcfc6 = function(arg0, arg1) {
|
|
424
|
+
let deferred0_0;
|
|
425
|
+
let deferred0_1;
|
|
426
|
+
try {
|
|
427
|
+
deferred0_0 = arg0;
|
|
428
|
+
deferred0_1 = arg1;
|
|
429
|
+
console.error(getStringFromWasm0(arg0, arg1));
|
|
430
|
+
} finally {
|
|
431
|
+
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
|
|
432
|
+
}
|
|
433
|
+
};
|
|
434
|
+
imports.wbg.__wbg_instanceof_Window_c4b70662a0d2c5ec = function(arg0) {
|
|
435
|
+
let result;
|
|
436
|
+
try {
|
|
437
|
+
result = arg0 instanceof Window;
|
|
438
|
+
} catch (_) {
|
|
439
|
+
result = false;
|
|
440
|
+
}
|
|
441
|
+
return result;
|
|
442
|
+
};
|
|
443
|
+
imports.wbg.__wbg_document_e5c1786dea6542e4 = function(arg0) {
|
|
444
|
+
const ret = arg0.document;
|
|
445
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
446
|
+
};
|
|
447
|
+
imports.wbg.__wbg_body_e70ae6abd01ae584 = function(arg0) {
|
|
448
|
+
const ret = arg0.body;
|
|
449
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
450
|
+
};
|
|
451
|
+
imports.wbg.__wbg_createElement_5d4c76f218b78145 = function() {
|
|
452
|
+
return handleError(function(arg0, arg1, arg2) {
|
|
453
|
+
return arg0.createElement(getStringFromWasm0(arg1, arg2));
|
|
454
|
+
}, arguments);
|
|
455
|
+
};
|
|
456
|
+
imports.wbg.__wbg_width_4c6f0048d64cf86b = function(arg0) {
|
|
457
|
+
return arg0.width;
|
|
458
|
+
};
|
|
459
|
+
imports.wbg.__wbg_height_21f0d3fd8f753394 = function(arg0) {
|
|
460
|
+
return arg0.height;
|
|
461
|
+
};
|
|
462
|
+
imports.wbg.__wbg_width_79e0847ed5883b03 = function(arg0) {
|
|
463
|
+
return arg0.width;
|
|
464
|
+
};
|
|
465
|
+
imports.wbg.__wbg_height_e4e4e4779f8feac0 = function(arg0) {
|
|
466
|
+
return arg0.height;
|
|
467
|
+
};
|
|
468
|
+
imports.wbg.__wbg_data_fda507064d127f5b = function(arg0, arg1) {
|
|
469
|
+
const ret = arg1.data;
|
|
470
|
+
const ptr1 = passArray8ToWasm0(ret, wasm.__wbindgen_malloc);
|
|
471
|
+
const len1 = WASM_VECTOR_LEN;
|
|
472
|
+
getDataViewMemory0().setInt32(arg0 + 4, len1, true);
|
|
473
|
+
getDataViewMemory0().setInt32(arg0 + 0, ptr1, true);
|
|
474
|
+
};
|
|
475
|
+
imports.wbg.__wbg_newwithu8clampedarrayandsh_1fddccb3a94a5e05 = function() {
|
|
476
|
+
return handleError(function(arg0, arg1, arg2, arg3) {
|
|
477
|
+
return new ImageData(getClampedArrayU8FromWasm0(arg0, arg1), arg2 >>> 0, arg3 >>> 0);
|
|
478
|
+
}, arguments);
|
|
479
|
+
};
|
|
480
|
+
imports.wbg.__wbg_instanceof_CanvasRenderingContext2d_3abbe7ec7af32cae = function(arg0) {
|
|
481
|
+
let result;
|
|
482
|
+
try {
|
|
483
|
+
result = arg0 instanceof CanvasRenderingContext2D;
|
|
484
|
+
} catch (_) {
|
|
485
|
+
result = false;
|
|
486
|
+
}
|
|
487
|
+
return result;
|
|
488
|
+
};
|
|
489
|
+
imports.wbg.__wbg_drawImage_fede06db74e39a60 = function() {
|
|
490
|
+
return handleError(function(arg0, arg1, arg2, arg3) {
|
|
491
|
+
arg0.drawImage(arg1, arg2, arg3);
|
|
492
|
+
}, arguments);
|
|
493
|
+
};
|
|
494
|
+
imports.wbg.__wbg_drawImage_f395c8e43c79a909 = function() {
|
|
495
|
+
return handleError(function(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) {
|
|
496
|
+
arg0.drawImage(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
|
|
497
|
+
}, arguments);
|
|
498
|
+
};
|
|
499
|
+
imports.wbg.__wbg_getImageData_5e1c242046e6b59e = function() {
|
|
500
|
+
return handleError(function(arg0, arg1, arg2, arg3, arg4) {
|
|
501
|
+
return arg0.getImageData(arg1, arg2, arg3, arg4);
|
|
502
|
+
}, arguments);
|
|
503
|
+
};
|
|
504
|
+
imports.wbg.__wbg_putImageData_a8b3e177ee06d521 = function() {
|
|
505
|
+
return handleError(function(arg0, arg1, arg2, arg3) {
|
|
506
|
+
arg0.putImageData(arg1, arg2, arg3);
|
|
507
|
+
}, arguments);
|
|
508
|
+
};
|
|
509
|
+
imports.wbg.__wbg_instanceof_HtmlCanvasElement_25d964a0dde6717e = function(arg0) {
|
|
510
|
+
let result;
|
|
511
|
+
try {
|
|
512
|
+
result = arg0 instanceof HTMLCanvasElement;
|
|
513
|
+
} catch (_) {
|
|
514
|
+
result = false;
|
|
515
|
+
}
|
|
516
|
+
return result;
|
|
517
|
+
};
|
|
518
|
+
imports.wbg.__wbg_width_dc225e55343b745e = function(arg0) {
|
|
519
|
+
return arg0.width;
|
|
520
|
+
};
|
|
521
|
+
imports.wbg.__wbg_setwidth_488780db69b08846 = function(arg0, arg1) {
|
|
522
|
+
arg0.width = arg1 >>> 0;
|
|
523
|
+
};
|
|
524
|
+
imports.wbg.__wbg_height_3a8bec2f3fe71b26 = function(arg0) {
|
|
525
|
+
return arg0.height;
|
|
526
|
+
};
|
|
527
|
+
imports.wbg.__wbg_setheight_1761808c18403921 = function(arg0, arg1) {
|
|
528
|
+
arg0.height = arg1 >>> 0;
|
|
529
|
+
};
|
|
530
|
+
imports.wbg.__wbg_getContext_fc99dbd3a9a7e318 = function() {
|
|
531
|
+
return handleError(function(arg0, arg1, arg2) {
|
|
532
|
+
const ret = arg0.getContext(getStringFromWasm0(arg1, arg2));
|
|
533
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
534
|
+
}, arguments);
|
|
535
|
+
};
|
|
536
|
+
imports.wbg.__wbg_settextContent_f82a86a8df347e1c = function(arg0, arg1, arg2) {
|
|
537
|
+
arg0.textContent = arg1 === 0 ? void 0 : getStringFromWasm0(arg1, arg2);
|
|
538
|
+
};
|
|
539
|
+
imports.wbg.__wbg_appendChild_fa3b00dade9fc4cf = function() {
|
|
540
|
+
return handleError(function(arg0, arg1) {
|
|
541
|
+
return arg0.appendChild(arg1);
|
|
542
|
+
}, arguments);
|
|
543
|
+
};
|
|
544
|
+
imports.wbg.__wbg_newnoargs_e643855c6572a4a8 = function(arg0, arg1) {
|
|
545
|
+
return new Function(getStringFromWasm0(arg0, arg1));
|
|
546
|
+
};
|
|
547
|
+
imports.wbg.__wbg_call_f96b398515635514 = function() {
|
|
548
|
+
return handleError(function(arg0, arg1) {
|
|
549
|
+
return arg0.call(arg1);
|
|
550
|
+
}, arguments);
|
|
551
|
+
};
|
|
552
|
+
imports.wbg.__wbg_self_b9aad7f1c618bfaf = function() {
|
|
553
|
+
return handleError(function() {
|
|
554
|
+
return self.self;
|
|
555
|
+
}, arguments);
|
|
556
|
+
};
|
|
557
|
+
imports.wbg.__wbg_window_55e469842c98b086 = function() {
|
|
558
|
+
return handleError(function() {
|
|
559
|
+
return window.window;
|
|
560
|
+
}, arguments);
|
|
561
|
+
};
|
|
562
|
+
imports.wbg.__wbg_globalThis_d0957e302752547e = function() {
|
|
563
|
+
return handleError(function() {
|
|
564
|
+
return globalThis.globalThis;
|
|
565
|
+
}, arguments);
|
|
566
|
+
};
|
|
567
|
+
imports.wbg.__wbg_global_ae2f87312b8987fb = function() {
|
|
568
|
+
return handleError(function() {
|
|
569
|
+
return global.global;
|
|
570
|
+
}, arguments);
|
|
571
|
+
};
|
|
572
|
+
imports.wbg.__wbindgen_is_undefined = function(arg0) {
|
|
573
|
+
return arg0 === void 0;
|
|
574
|
+
};
|
|
575
|
+
imports.wbg.__wbg_buffer_fcbfb6d88b2732e9 = function(arg0) {
|
|
576
|
+
return arg0.buffer;
|
|
577
|
+
};
|
|
578
|
+
imports.wbg.__wbg_new_bc5d9aad3f9ac80e = function(arg0) {
|
|
579
|
+
return new Uint8Array(arg0);
|
|
580
|
+
};
|
|
581
|
+
imports.wbg.__wbg_set_4b3aa8445ac1e91c = function(arg0, arg1, arg2) {
|
|
582
|
+
arg0.set(arg1, arg2 >>> 0);
|
|
583
|
+
};
|
|
584
|
+
imports.wbg.__wbg_length_d9c4ded7e708c6a1 = function(arg0) {
|
|
585
|
+
return arg0.length;
|
|
586
|
+
};
|
|
587
|
+
imports.wbg.__wbindgen_debug_string = function(arg0, arg1) {
|
|
588
|
+
const ptr1 = passStringToWasm0(debugString(arg1), wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
589
|
+
const len1 = WASM_VECTOR_LEN;
|
|
590
|
+
getDataViewMemory0().setInt32(arg0 + 4, len1, true);
|
|
591
|
+
getDataViewMemory0().setInt32(arg0 + 0, ptr1, true);
|
|
592
|
+
};
|
|
593
|
+
imports.wbg.__wbindgen_throw = function(arg0, arg1) {
|
|
594
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
595
|
+
};
|
|
596
|
+
imports.wbg.__wbindgen_memory = function() {
|
|
597
|
+
return wasm.memory;
|
|
598
|
+
};
|
|
599
|
+
imports.wbg.__wbindgen_init_externref_table = function() {
|
|
600
|
+
const table = wasm.__wbindgen_export_2;
|
|
601
|
+
const offset = table.grow(4);
|
|
602
|
+
table.set(0, void 0);
|
|
603
|
+
table.set(offset + 0, void 0);
|
|
604
|
+
table.set(offset + 1, null);
|
|
605
|
+
table.set(offset + 2, true);
|
|
606
|
+
table.set(offset + 3, false);
|
|
607
|
+
};
|
|
608
|
+
return imports;
|
|
609
|
+
}
|
|
610
|
+
function __wbg_finalize_init(instance, module) {
|
|
611
|
+
wasm = instance.exports;
|
|
612
|
+
__wbg_init.__wbindgen_wasm_module = module;
|
|
613
|
+
cachedDataViewMemory0 = null;
|
|
614
|
+
cachedUint8ArrayMemory0 = null;
|
|
615
|
+
cachedUint8ClampedArrayMemory0 = null;
|
|
616
|
+
wasm.__wbindgen_start();
|
|
617
|
+
return wasm;
|
|
618
|
+
}
|
|
619
|
+
function initSync(module) {
|
|
620
|
+
if (wasm !== void 0) return wasm;
|
|
621
|
+
if (typeof module !== "undefined") {
|
|
622
|
+
if (Object.getPrototypeOf(module) === Object.prototype) ({module} = module);
|
|
623
|
+
else console.warn("using deprecated parameters for `initSync()`; pass a single object instead");
|
|
624
|
+
}
|
|
625
|
+
const imports = __wbg_get_imports();
|
|
626
|
+
if (!(module instanceof WebAssembly.Module)) module = new WebAssembly.Module(module);
|
|
627
|
+
return __wbg_finalize_init(new WebAssembly.Instance(module, imports), module);
|
|
628
|
+
}
|
|
629
|
+
async function __wbg_init(module_or_path) {
|
|
630
|
+
if (wasm !== void 0) return wasm;
|
|
631
|
+
if (typeof module_or_path !== "undefined") {
|
|
632
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) ({module_or_path} = module_or_path);
|
|
633
|
+
else console.warn("using deprecated parameters for the initialization function; pass a single object instead");
|
|
634
|
+
}
|
|
635
|
+
if (typeof module_or_path === "undefined") module_or_path = new URL("photon_rs_bg.wasm", import.meta.url);
|
|
636
|
+
const imports = __wbg_get_imports();
|
|
637
|
+
if (typeof module_or_path === "string" || typeof Request === "function" && module_or_path instanceof Request || typeof URL === "function" && module_or_path instanceof URL) module_or_path = fetch(module_or_path);
|
|
638
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
639
|
+
return __wbg_finalize_init(instance, module);
|
|
640
|
+
}
|
|
641
|
+
//#endregion
|
|
642
|
+
//#region ../../../node_modules/.pnpm/@earendil-works+pi-durable@1.5.0_patch_hash=0f5e595daa4c370af407284d99d6dba48a9e21f56aa_fbb51180c4b193ec70152883060baa79/node_modules/@earendil-works/pi-durable/dist/tools/image-processor.js
|
|
643
|
+
/** Formats every provider takes inline; others, such as BMP, need converting. */
|
|
644
|
+
const INLINE_IMAGE_TYPES = /* @__PURE__ */ new Set([
|
|
645
|
+
"image/png",
|
|
646
|
+
"image/jpeg",
|
|
647
|
+
"image/gif",
|
|
648
|
+
"image/webp"
|
|
649
|
+
]);
|
|
650
|
+
/**
|
|
651
|
+
* Standard base64 of `bytes`. `btoa` takes a binary string, built 8 KiB at a time: a single `String.fromCharCode`
|
|
652
|
+
* call with megabytes of arguments overflows the stack.
|
|
653
|
+
*/
|
|
654
|
+
function toBase64(bytes) {
|
|
655
|
+
const parts = [];
|
|
656
|
+
for (let i = 0; i < bytes.length; i += 8192) parts.push(String.fromCharCode.apply(null, bytes.subarray(i, i + 8192)));
|
|
657
|
+
return btoa(parts.join(""));
|
|
658
|
+
}
|
|
659
|
+
/** The length of the base64 of `byteLength` bytes. */
|
|
660
|
+
function base64Length(byteLength) {
|
|
661
|
+
return Math.ceil(byteLength / 3) * 4;
|
|
662
|
+
}
|
|
663
|
+
//#endregion
|
|
664
|
+
//#region ../../../node_modules/.pnpm/@earendil-works+pi-durable@1.5.0_patch_hash=0f5e595daa4c370af407284d99d6dba48a9e21f56aa_fbb51180c4b193ec70152883060baa79/node_modules/@earendil-works/pi-durable/dist/images/exif.js
|
|
665
|
+
/** The EXIF orientation of a JPEG or WebP, 1 to 8; 1 when absent or unreadable. */
|
|
666
|
+
function exifOrientation(bytes) {
|
|
667
|
+
const tiff = tiffStart(bytes);
|
|
668
|
+
if (tiff < 0 || tiff + 8 > bytes.length) return 1;
|
|
669
|
+
const little = bytes[tiff] === 73 && bytes[tiff + 1] === 73;
|
|
670
|
+
const u16 = (at) => little ? bytes[at] | bytes[at + 1] << 8 : bytes[at] << 8 | bytes[at + 1];
|
|
671
|
+
const u32 = (at) => little ? (bytes[at] | bytes[at + 1] << 8 | bytes[at + 2] << 16 | bytes[at + 3] << 24) >>> 0 : (bytes[at] << 24 | bytes[at + 1] << 16 | bytes[at + 2] << 8 | bytes[at + 3]) >>> 0;
|
|
672
|
+
const directory = tiff + u32(tiff + 4);
|
|
673
|
+
if (directory + 2 > bytes.length) return 1;
|
|
674
|
+
const entries = u16(directory);
|
|
675
|
+
for (let index = 0; index < entries; index++) {
|
|
676
|
+
const entry = directory + 2 + index * 12;
|
|
677
|
+
if (entry + 12 > bytes.length) return 1;
|
|
678
|
+
if (u16(entry) === 274) {
|
|
679
|
+
const value = u16(entry + 8);
|
|
680
|
+
return value >= 1 && value <= 8 ? value : 1;
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
return 1;
|
|
684
|
+
}
|
|
685
|
+
/** Where the TIFF header of a JPEG's APP1 or a WebP's EXIF chunk starts; -1 when there is none. */
|
|
686
|
+
function tiffStart(bytes) {
|
|
687
|
+
if (bytes[0] === 255 && bytes[1] === 216) {
|
|
688
|
+
for (let offset = 2; offset + 4 <= bytes.length;) {
|
|
689
|
+
if (bytes[offset] !== 255) return -1;
|
|
690
|
+
const marker = bytes[offset + 1];
|
|
691
|
+
if (marker === 255) {
|
|
692
|
+
offset++;
|
|
693
|
+
continue;
|
|
694
|
+
}
|
|
695
|
+
if (marker === 225 && isExifHeader(bytes, offset + 4)) return offset + 10;
|
|
696
|
+
offset += 2 + (bytes[offset + 2] << 8 | bytes[offset + 3]);
|
|
697
|
+
}
|
|
698
|
+
return -1;
|
|
699
|
+
}
|
|
700
|
+
if (ascii(bytes, 0, "RIFF") && ascii(bytes, 8, "WEBP")) for (let offset = 12; offset + 8 <= bytes.length;) {
|
|
701
|
+
const size = (bytes[offset + 4] | bytes[offset + 5] << 8 | bytes[offset + 6] << 16 | bytes[offset + 7] << 24) >>> 0;
|
|
702
|
+
if (ascii(bytes, offset, "EXIF")) return isExifHeader(bytes, offset + 8) ? offset + 14 : offset + 8;
|
|
703
|
+
offset += 8 + size + size % 2;
|
|
704
|
+
}
|
|
705
|
+
return -1;
|
|
706
|
+
}
|
|
707
|
+
function isExifHeader(bytes, offset) {
|
|
708
|
+
return ascii(bytes, offset, "Exif") && bytes[offset + 4] === 0 && bytes[offset + 5] === 0;
|
|
709
|
+
}
|
|
710
|
+
function ascii(bytes, offset, text) {
|
|
711
|
+
for (let index = 0; index < text.length; index++) if (bytes[offset + index] !== text.charCodeAt(index)) return false;
|
|
712
|
+
return true;
|
|
713
|
+
}
|
|
714
|
+
//#endregion
|
|
715
|
+
//#region ../../../node_modules/.pnpm/@earendil-works+pi-durable@1.5.0_patch_hash=0f5e595daa4c370af407284d99d6dba48a9e21f56aa_fbb51180c4b193ec70152883060baa79/node_modules/@earendil-works/pi-durable/dist/images/index.js
|
|
716
|
+
/** JPEG qualities tried in order. */
|
|
717
|
+
const JPEG_QUALITIES = [
|
|
718
|
+
80,
|
|
719
|
+
70,
|
|
720
|
+
55,
|
|
721
|
+
40
|
|
722
|
+
];
|
|
723
|
+
/**
|
|
724
|
+
* An `ImageProcessor` on Photon (Rust compiled to WebAssembly), for `createCodingTools({ images })`. `wasm` is
|
|
725
|
+
* Photon's `photon_rs_bg.wasm` as bytes or as a compiled module: `@earendil-works/pi-durable/images/node` reads it from
|
|
726
|
+
* the installed package, `@earendil-works/pi-durable/images/cloudflare` imports it as a Workers module. Elsewhere, such
|
|
727
|
+
* as a browser, fetch the file and pass its bytes. Photon loads once per process; later calls reuse the first `wasm`.
|
|
728
|
+
*
|
|
729
|
+
* An image already upright, in a format providers take inline, and within the limits is returned as it is, once it
|
|
730
|
+
* decodes. Otherwise it is turned upright by its EXIF orientation, scaled to the
|
|
731
|
+
* maximum width and height, and encoded as PNG or JPEG at falling qualities (JPEG first for JPEG sources), then at
|
|
732
|
+
* smaller dimensions, 3/4 at a time, until the base64 fits. Formats providers do not take inline (BMP) become PNG.
|
|
733
|
+
*
|
|
734
|
+
* The work runs on the calling thread: about a second and a half for a 12-megapixel photo. Decoding takes the image's
|
|
735
|
+
* RGBA size in WebAssembly memory, which does not shrink again; leave the processor out on memory-constrained hosts.
|
|
736
|
+
*/
|
|
737
|
+
function createPhotonImages(wasm) {
|
|
738
|
+
initSync({ module: wasm });
|
|
739
|
+
return { prepare: async (bytes, mimeType, limits) => prepare(bytes, mimeType, limits) };
|
|
740
|
+
}
|
|
741
|
+
function prepare(bytes, mimeType, limits) {
|
|
742
|
+
const orientation = exifOrientation(bytes);
|
|
743
|
+
const inline = INLINE_IMAGE_TYPES.has(mimeType);
|
|
744
|
+
let image;
|
|
745
|
+
try {
|
|
746
|
+
image = PhotonImage.new_from_byteslice(bytes);
|
|
747
|
+
if (inline && orientation === 1 && image.get_width() <= limits.maxWidth && image.get_height() <= limits.maxHeight && base64Length(bytes.byteLength) <= limits.maxBytes) return {
|
|
748
|
+
data: toBase64(bytes),
|
|
749
|
+
mimeType
|
|
750
|
+
};
|
|
751
|
+
if (orientation >= 5) {
|
|
752
|
+
const upright = transposed(image, orientation);
|
|
753
|
+
image.free();
|
|
754
|
+
image = void 0;
|
|
755
|
+
image = new PhotonImage(upright.pixels, upright.width, upright.height);
|
|
756
|
+
} else if (orientation !== 1) {
|
|
757
|
+
if (orientation !== 4) fliph(image);
|
|
758
|
+
if (orientation !== 2) flipv(image);
|
|
759
|
+
}
|
|
760
|
+
const width = image.get_width();
|
|
761
|
+
const height = image.get_height();
|
|
762
|
+
const scale = Math.min(1, limits.maxWidth / width, limits.maxHeight / height);
|
|
763
|
+
let target = {
|
|
764
|
+
width: Math.max(1, Math.round(width * scale)),
|
|
765
|
+
height: Math.max(1, Math.round(height * scale))
|
|
766
|
+
};
|
|
767
|
+
for (;;) {
|
|
768
|
+
const encoded = encodeWithin(image, target, limits.maxBytes, mimeType === "image/jpeg");
|
|
769
|
+
if (encoded !== void 0) {
|
|
770
|
+
const resized = target.width === width && target.height === height ? {} : { resized: {
|
|
771
|
+
from: {
|
|
772
|
+
width,
|
|
773
|
+
height
|
|
774
|
+
},
|
|
775
|
+
to: target
|
|
776
|
+
} };
|
|
777
|
+
const converted = encoded.mimeType === mimeType ? {} : { convertedFrom: mimeType };
|
|
778
|
+
return {
|
|
779
|
+
...encoded,
|
|
780
|
+
...converted,
|
|
781
|
+
...resized
|
|
782
|
+
};
|
|
783
|
+
}
|
|
784
|
+
if (target.width === 1 && target.height === 1) return void 0;
|
|
785
|
+
target = {
|
|
786
|
+
width: Math.max(1, Math.floor(target.width * .75)),
|
|
787
|
+
height: Math.max(1, Math.floor(target.height * .75))
|
|
788
|
+
};
|
|
789
|
+
}
|
|
790
|
+
} catch {
|
|
791
|
+
return;
|
|
792
|
+
} finally {
|
|
793
|
+
image?.free();
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
/**
|
|
797
|
+
* `image` at `size` in the first encoding whose base64 fits `maxBytes`: PNG, then JPEG at falling qualities, or the
|
|
798
|
+
* JPEG qualities first when `jpegFirst`; `undefined` if none fits.
|
|
799
|
+
*/
|
|
800
|
+
function encodeWithin(image, size, maxBytes, jpegFirst) {
|
|
801
|
+
const same = size.width === image.get_width() && size.height === image.get_height();
|
|
802
|
+
const scaled = same ? image : resize(image, size.width, size.height, SamplingFilter.Lanczos3);
|
|
803
|
+
try {
|
|
804
|
+
const png = {
|
|
805
|
+
mimeType: "image/png",
|
|
806
|
+
encode: () => scaled.get_bytes()
|
|
807
|
+
};
|
|
808
|
+
const jpegs = JPEG_QUALITIES.map((quality) => ({
|
|
809
|
+
mimeType: "image/jpeg",
|
|
810
|
+
encode: () => scaled.get_bytes_jpeg(quality)
|
|
811
|
+
}));
|
|
812
|
+
for (const candidate of jpegFirst ? [...jpegs, png] : [png, ...jpegs]) {
|
|
813
|
+
const bytes = candidate.encode();
|
|
814
|
+
if (base64Length(bytes.byteLength) <= maxBytes) return {
|
|
815
|
+
data: toBase64(bytes),
|
|
816
|
+
mimeType: candidate.mimeType
|
|
817
|
+
};
|
|
818
|
+
}
|
|
819
|
+
return;
|
|
820
|
+
} finally {
|
|
821
|
+
if (!same) scaled.free();
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
/**
|
|
825
|
+
* The RGBA pixels of `image` turned upright for EXIF `orientation` 5 to 8, the orientations that swap width and
|
|
826
|
+
* height. Photon's own `rotate` drops pixels at right angles, so the pixels are moved here.
|
|
827
|
+
*/
|
|
828
|
+
function transposed(image, orientation) {
|
|
829
|
+
const width = image.get_width();
|
|
830
|
+
const height = image.get_height();
|
|
831
|
+
const source = image.get_raw_pixels();
|
|
832
|
+
const pixels = new Uint8Array(source.length);
|
|
833
|
+
for (let y = 0; y < height; y++) for (let x = 0; x < width; x++) {
|
|
834
|
+
const outX = orientation === 5 || orientation === 8 ? y : height - 1 - y;
|
|
835
|
+
const outY = orientation === 5 || orientation === 6 ? x : width - 1 - x;
|
|
836
|
+
pixels.set(source.subarray((y * width + x) * 4, (y * width + x) * 4 + 4), (outY * height + outX) * 4);
|
|
837
|
+
}
|
|
838
|
+
return {
|
|
839
|
+
pixels,
|
|
840
|
+
width: height,
|
|
841
|
+
height: width
|
|
842
|
+
};
|
|
843
|
+
}
|
|
844
|
+
//#endregion
|
|
845
|
+
//#region ../../../node_modules/.pnpm/@earendil-works+pi-durable@1.5.0_patch_hash=0f5e595daa4c370af407284d99d6dba48a9e21f56aa_fbb51180c4b193ec70152883060baa79/node_modules/@earendil-works/pi-durable/dist/images/cloudflare.js
|
|
846
|
+
/** `createPhotonImages()` for Cloudflare Workers and Durable Objects, built with Wrangler. */
|
|
847
|
+
function createCloudflarePhotonImages() {
|
|
848
|
+
return createPhotonImages(photonWasm);
|
|
849
|
+
}
|
|
850
|
+
//#endregion
|
|
851
|
+
//#region ../../core/po-core/src/services/providerImages/fitter.ts
|
|
852
|
+
/**
|
|
853
|
+
* Pi's own cap. Providers reject the whole request when one image is larger than their
|
|
854
|
+
* many-image limit (Anthropic: 2000px), so one oversized attachment breaks every later turn.
|
|
855
|
+
*/
|
|
856
|
+
const MAX_DIMENSION = 2e3;
|
|
857
|
+
/** Bytes of base64, Pi's default: headroom below Anthropic's 5 MB image limit. */
|
|
858
|
+
const MAX_IMAGE_BYTES = 4718592;
|
|
859
|
+
/**
|
|
860
|
+
* Fits every image in a provider request with `resize`. Runs on the request, not on entry, so
|
|
861
|
+
* images already stored in history (user attachments, tool results) are fixed too. An image that
|
|
862
|
+
* cannot be resized (no image backend, undecodable) is kept as it is, as Pi does.
|
|
863
|
+
*
|
|
864
|
+
* ponytail: the cache lives as long as the session and holds one copy of each image it saw.
|
|
865
|
+
* Resize on admission instead if image-heavy sessions show memory pressure.
|
|
866
|
+
*/
|
|
867
|
+
function createImageFitter(resize) {
|
|
868
|
+
const fitted = /* @__PURE__ */ new Map();
|
|
869
|
+
const fit = (image) => {
|
|
870
|
+
let result = fitted.get(image.data);
|
|
871
|
+
if (!result) {
|
|
872
|
+
result = resize(image).then((resized) => resized ?? image, () => image);
|
|
873
|
+
fitted.set(image.data, result);
|
|
874
|
+
}
|
|
875
|
+
return result;
|
|
876
|
+
};
|
|
877
|
+
return async (messages) => Promise.all(messages.map(async (message) => {
|
|
878
|
+
if (message.role !== "user" && message.role !== "toolResult" || typeof message.content === "string") return message;
|
|
879
|
+
if (!message.content.some((part) => part.type === "image")) return message;
|
|
880
|
+
const content = await Promise.all(message.content.map((part) => part.type === "image" ? fit(part) : Promise.resolve(part)));
|
|
881
|
+
return content.every((part, index) => part === message.content[index]) ? message : {
|
|
882
|
+
...message,
|
|
883
|
+
content
|
|
884
|
+
};
|
|
885
|
+
}));
|
|
886
|
+
}
|
|
887
|
+
//#endregion
|
|
888
|
+
//#region ../../core/po-core/src/services/providerImages/index.edge.ts
|
|
889
|
+
const LIMITS = {
|
|
890
|
+
maxWidth: MAX_DIMENSION,
|
|
891
|
+
maxHeight: MAX_DIMENSION,
|
|
892
|
+
maxBytes: MAX_IMAGE_BYTES
|
|
893
|
+
};
|
|
894
|
+
/** Photon loads once per isolate, on the first image, so sessions without images pay nothing. */
|
|
895
|
+
let photon;
|
|
896
|
+
/** Fits an inline image with the isolate's Photon instance, without Node workers or filesystem access. */
|
|
897
|
+
async function resizeImage(inputBytes, mimeType, options) {
|
|
898
|
+
photon ??= createCloudflarePhotonImages();
|
|
899
|
+
const prepared = await photon.prepare(inputBytes, mimeType, {
|
|
900
|
+
maxWidth: options?.maxWidth ?? 2e3,
|
|
901
|
+
maxHeight: options?.maxHeight ?? 2e3,
|
|
902
|
+
maxBytes: options?.maxBytes ?? 4718592
|
|
903
|
+
});
|
|
904
|
+
if (!prepared) return null;
|
|
905
|
+
const { resized } = prepared;
|
|
906
|
+
return {
|
|
907
|
+
data: prepared.data,
|
|
908
|
+
mimeType: prepared.mimeType,
|
|
909
|
+
originalWidth: resized?.from.width ?? 0,
|
|
910
|
+
originalHeight: resized?.from.height ?? 0,
|
|
911
|
+
width: resized?.to.width ?? 0,
|
|
912
|
+
height: resized?.to.height ?? 0,
|
|
913
|
+
wasResized: resized !== void 0
|
|
914
|
+
};
|
|
915
|
+
}
|
|
916
|
+
function formatDimensionNote(result) {
|
|
917
|
+
if (!result.wasResized) return void 0;
|
|
918
|
+
const scale = result.originalWidth / result.width;
|
|
919
|
+
return `[Image: original ${result.originalWidth}x${result.originalHeight}, displayed at ${result.width}x${result.height}. Multiply coordinates by ${scale.toFixed(2)} to map to original image.]`;
|
|
920
|
+
}
|
|
921
|
+
/**
|
|
922
|
+
* The edge form: Pi's resizer needs worker threads and reads its wasm from disk, so the Worker
|
|
923
|
+
* resizes with pi-durable's Photon build, whose wasm ships next to the bundle.
|
|
924
|
+
*/
|
|
925
|
+
function createProviderImageFitter() {
|
|
926
|
+
return createImageFitter(async (image) => {
|
|
927
|
+
photon ??= createCloudflarePhotonImages();
|
|
928
|
+
const prepared = await photon.prepare(Buffer.from(image.data, "base64"), image.mimeType, LIMITS);
|
|
929
|
+
return prepared && prepared.data !== image.data ? {
|
|
930
|
+
type: "image",
|
|
931
|
+
data: prepared.data,
|
|
932
|
+
mimeType: prepared.mimeType
|
|
933
|
+
} : void 0;
|
|
934
|
+
});
|
|
935
|
+
}
|
|
936
|
+
//#endregion
|
|
937
|
+
export { formatDimensionNote as n, resizeImage as r, createProviderImageFitter as t };
|