@octane-xplat/image 0.0.0-stage → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +123 -2
  3. package/dist/native/Image.tsrx.js +264 -0
  4. package/dist/native/cache.js +64 -0
  5. package/dist/native/hash-image.js +285 -0
  6. package/dist/native/image-binding.js +103 -0
  7. package/dist/native/image-content.js +207 -0
  8. package/dist/native/index.js +3 -0
  9. package/dist/native/octane-client-build.json +8 -0
  10. package/dist/native/prefetch-batch.js +27 -0
  11. package/dist/web/Image.web.tsrx.js +123 -0
  12. package/dist/web/cache.web.js +35 -0
  13. package/dist/web/hash-image.js +285 -0
  14. package/dist/web/image-content.js +134 -0
  15. package/dist/web/index.js +3 -0
  16. package/dist/web/octane-client-build.json +8 -0
  17. package/dist/web/prefetch-batch.js +27 -0
  18. package/package.json +83 -3
  19. package/src/Image.macos.tsrx +24 -0
  20. package/src/Image.tsrx +269 -0
  21. package/src/Image.web.tsrx +176 -0
  22. package/src/cache.macos.ts +31 -0
  23. package/src/cache.ts +93 -0
  24. package/src/cache.web.ts +49 -0
  25. package/src/hash-image.ts +313 -0
  26. package/src/image-binding.ts +170 -0
  27. package/src/image-content.ts +310 -0
  28. package/src/index.macos.ts +26 -0
  29. package/src/index.ts +28 -0
  30. package/src/index.web.ts +28 -0
  31. package/src/native-elements.d.ts +8 -0
  32. package/src/prefetch-batch.ts +50 -0
  33. package/src/prefetch.web.test.ts +105 -0
  34. package/src/props.ts +119 -0
  35. package/types/generated/.tsrx-typegen-manifest.json +16 -0
  36. package/types/generated/Image.d.ts +16 -0
  37. package/types/generated/Image.web.d.ts +12 -0
  38. package/types/generated/cache.d.ts +28 -0
  39. package/types/generated/cache.web.d.ts +16 -0
  40. package/types/generated/hash-image.d.ts +14 -0
  41. package/types/generated/image-binding.d.ts +40 -0
  42. package/types/generated/image-content.d.ts +57 -0
  43. package/types/generated/index.d.ts +3 -0
  44. package/types/generated/index.web.d.ts +3 -0
  45. package/types/generated/prefetch-batch.d.ts +10 -0
  46. package/types/generated/props.d.ts +99 -0
  47. package/types/index.macos.d.ts +28 -0
@@ -0,0 +1,123 @@
1
+ import { imageSrcSet, objectPositionCSSValue, resolveContentFit, resolveContentPosition } from "./image-content.js";
2
+ import { hashToPngBase64 } from "./hash-image.js";
3
+ import { __s, bag9, clone, delegateEvents, hookSlots, queueRefAttach, queueRefDetach, setEventHandler, setStyle, template, useLayoutEffect, useRef } from "octane";
4
+ import { bindSignalAttribute, enableSignalBindings, replaceRef, setPlainAttribute, setURLAttribute } from "octane/internal/client";
5
+ //#region src/Image.web.tsrx
6
+ enableSignalBindings(1, true);
7
+ delegateEvents(["error", "load"]);
8
+ var _t$0 = /* @__PURE__ */ template("<img/>");
9
+ var _hs$ = /* @__PURE__ */ hookSlots(2);
10
+ var _rm$0 = [
11
+ "r",
12
+ "b",
13
+ "a"
14
+ ];
15
+ function layoutChildStyle(props) {
16
+ const style = {};
17
+ if (props.row !== void 0) style.gridRow = `${props.row + 1} / span ${props.rowSpan ?? 1}`;
18
+ else if (props.rowSpan !== void 0) style.gridRow = `span ${props.rowSpan}`;
19
+ if (props.col !== void 0) style.gridColumn = `${props.col + 1} / span ${props.colSpan ?? 1}`;
20
+ else if (props.colSpan !== void 0) style.gridColumn = `span ${props.colSpan}`;
21
+ if (props.left !== void 0) style.left = props.left;
22
+ if (props.top !== void 0) style.top = props.top;
23
+ if (props.flexGrow !== void 0) style.flexGrow = props.flexGrow;
24
+ if (props.flexShrink !== void 0) style.flexShrink = props.flexShrink;
25
+ if (props.alignSelf !== void 0) style.alignSelf = props.alignSelf;
26
+ if (props.order !== void 0) style.order = props.order;
27
+ return style;
28
+ }
29
+ function applyEscapeProps(element, props) {
30
+ if (!element || !props.web) return;
31
+ for (const [key, value] of Object.entries(props.web)) if (key.includes("-")) {
32
+ if (value == null || value === false) element.removeAttribute(key);
33
+ else element.setAttribute(key, String(value));
34
+ } else if (key in element) element[key] = value;
35
+ else if (value != null && value !== false) element.setAttribute(key, String(value));
36
+ }
37
+ function placeholderUrl(placeholder) {
38
+ const png = hashToPngBase64(placeholder);
39
+ return png ? `data:image/png;base64,${png}` : placeholder;
40
+ }
41
+ var Image = /* @__PURE__ */ __s(function Image(props, __s, __extra) {
42
+ const imgRef = useRef(null, _hs$ + 0);
43
+ const sources = Array.isArray(props.src) ? props.src : null;
44
+ const selected = sources ? imageSrcSet(sources) : {
45
+ src: props.src,
46
+ srcSet: void 0
47
+ };
48
+ useLayoutEffect(() => {
49
+ const img = imgRef.current;
50
+ if (!img || !props.placeholder || img.complete) return;
51
+ const placeholder = placeholderUrl(props.placeholder);
52
+ const { src: final, srcSet: finalSrcSet } = selected;
53
+ const warm = document.createElement("img");
54
+ warm.src = final;
55
+ if (finalSrcSet) warm.srcset = finalSrcSet;
56
+ const swap = () => {
57
+ img.src = final;
58
+ if (finalSrcSet) img.srcset = finalSrcSet;
59
+ };
60
+ img.addEventListener("load", swap, { once: true });
61
+ img.addEventListener("error", swap, { once: true });
62
+ if (finalSrcSet) img.srcset = "";
63
+ img.src = placeholder;
64
+ return () => {
65
+ img.removeEventListener("load", swap);
66
+ img.removeEventListener("error", swap);
67
+ };
68
+ }, [props.src, props.placeholder], _hs$ + 1);
69
+ const style = {
70
+ objectFit: "cover",
71
+ objectPosition: "50% 50%",
72
+ ...layoutChildStyle(props),
73
+ ...typeof props.style === "object" ? props.style : {},
74
+ ...props.contentFit !== void 0 ? { objectFit: resolveContentFit(props.contentFit) } : null,
75
+ ...props.contentPosition !== void 0 ? { objectPosition: objectPositionCSSValue(resolveContentPosition(props.contentPosition)) } : null
76
+ };
77
+ if (__s.block.pending && !__s.block.crossRenderUpdate) return;
78
+ let _b = __s.slots[0];
79
+ if (_b === void 0) {
80
+ let _m0, _m1;
81
+ const _root = clone(_t$0);
82
+ queueRefAttach(__s, _m1 = (e) => {
83
+ imgRef.current = e;
84
+ applyEscapeProps(e, props);
85
+ }, _m0 = _root);
86
+ (__s.cleanups ??= []).push(() => _b && queueRefDetach(_b.b, _b.a));
87
+ setEventHandler(_root, "$$load", (e) => props.onLoad?.({
88
+ width: e.currentTarget.naturalWidth ?? 0,
89
+ height: e.currentTarget.naturalHeight ?? 0
90
+ }));
91
+ setEventHandler(_root, "$$error", () => props.onError?.({ error: /* @__PURE__ */ new Error(`Failed to load image: ${props.src}`) }));
92
+ _b = bag9(__s, _root, _m0, _m1, void 0, void 0, void 0, void 0, void 0, void 0, void 0);
93
+ __s.refFields = _rm$0;
94
+ } else {
95
+ {
96
+ const _r = (e) => {
97
+ imgRef.current = e;
98
+ applyEscapeProps(e, props);
99
+ };
100
+ if (_r !== _b.b) _b.b = replaceRef(__s, _b.b, _r, _b.a);
101
+ }
102
+ setEventHandler(_b.a, "$$load", (e) => props.onLoad?.({
103
+ width: e.currentTarget.naturalWidth ?? 0,
104
+ height: e.currentTarget.naturalHeight ?? 0
105
+ }));
106
+ setEventHandler(_b.a, "$$error", () => props.onError?.({ error: /* @__PURE__ */ new Error(`Failed to load image: ${props.src}`) }));
107
+ }
108
+ _b.c = bindSignalAttribute(__s, _b.c, _b.a, "id", props.id, "b:ef70d73b", setPlainAttribute);
109
+ _b.d = bindSignalAttribute(__s, _b.d, _b.a, "class", props.className, "b:86dd0ebb", "class");
110
+ _b.e = bindSignalAttribute(__s, _b.e, _b.a, "src", selected.src, "b:ee7c1582", setURLAttribute);
111
+ _b.f = bindSignalAttribute(__s, _b.f, _b.a, "srcSet", selected.srcSet, "b:745cb663", setPlainAttribute);
112
+ _b.g = bindSignalAttribute(__s, _b.g, _b.a, "decoding", props.decoding ?? "async", "b:e2e0b95a", setPlainAttribute);
113
+ _b.h = bindSignalAttribute(__s, _b.h, _b.a, "alt", props.alt, "b:b12e1248", setPlainAttribute);
114
+ {
115
+ const _v = style;
116
+ if (_b.i !== _v) {
117
+ setStyle(_b.a, _v, _b.i);
118
+ _b.i = _v;
119
+ }
120
+ }
121
+ });
122
+ //#endregion
123
+ export { Image };
@@ -0,0 +1,35 @@
1
+ import { prefetchBatch } from "./prefetch-batch.js";
2
+ //#region src/cache.web.ts
3
+ /** No-op — the browser owns its HTTP cache; there is no sizing API. */
4
+ function initializeImageCache(_config) {}
5
+ /** Warm the browser HTTP cache by loading each `src` through a throwaway
6
+ * <img> — the response must land (`load`/`error` awaited) before the promise
7
+ * resolves. Decode still happens at display, matching the native
8
+ * disk-prefetch contract. `options.headers` is ignored — an <img> request
9
+ * cannot carry custom headers. Resolves `false` when any URL fails. */
10
+ function prefetch(srcs, options) {
11
+ return prefetchBatch(srcs, options?.concurrency, (url) => new Promise((resolve) => {
12
+ const image = new globalThis.Image();
13
+ image.onload = () => resolve(true);
14
+ image.onerror = () => resolve(false);
15
+ image.src = url;
16
+ }));
17
+ }
18
+ /** No-op — browsers expose no per-URL cache eviction for <img>. */
19
+ function evictImage(_src) {
20
+ return Promise.resolve(false);
21
+ }
22
+ /** No-op — browsers expose no cache clearing for <img>. */
23
+ function clearImageCaches() {
24
+ return Promise.resolve();
25
+ }
26
+ /** Always 'none' — the browser cache is not queryable. Returns the same
27
+ * `Record` shape as native, keyed by each requested URL. */
28
+ function isImageCached(srcs, _options) {
29
+ const list = typeof srcs === "string" ? [srcs] : srcs;
30
+ const states = {};
31
+ for (const src of list) states[src] = "none";
32
+ return Promise.resolve(states);
33
+ }
34
+ //#endregion
35
+ export { clearImageCaches, evictImage, initializeImageCache, isImageCached, prefetch };
@@ -0,0 +1,285 @@
1
+ //#region src/hash-image.ts
2
+ /** `blurhash:<hash>` / `thumbhash:<base64>` → PNG bytes as base64, or null. */
3
+ function hashToPngBase64(src) {
4
+ if (src.startsWith("blurhash:")) {
5
+ const rgba = decodeBlurHash(src.slice(9), 32, 32);
6
+ return rgba ? base64Encode(rgbaToPng(32, 32, rgba)) : null;
7
+ }
8
+ if (src.startsWith("thumbhash:")) {
9
+ const hash = base64Decode(src.slice(10));
10
+ const decoded = hash ? thumbHashToRGBA(hash) : null;
11
+ return decoded ? base64Encode(rgbaToPng(decoded.w, decoded.h, decoded.rgba)) : null;
12
+ }
13
+ return null;
14
+ }
15
+ var BASE83 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz#$%*+,-.:;=?@[]^_{|}~";
16
+ function decode83(str, start, end) {
17
+ let value = 0;
18
+ for (let i = start; i < end; i++) {
19
+ const digit = BASE83.indexOf(str[i]);
20
+ if (digit === -1) return -1;
21
+ value = value * 83 + digit;
22
+ }
23
+ return value;
24
+ }
25
+ function srgbToLinear(value) {
26
+ const v = value / 255;
27
+ return v <= .04045 ? v / 12.92 : Math.pow((v + .055) / 1.055, 2.4);
28
+ }
29
+ function linearToSrgb(value) {
30
+ const v = Math.max(0, Math.min(1, value));
31
+ return v <= .0031308 ? Math.round(v * 12.92 * 255 + .5) : Math.round((1.055 * Math.pow(v, 1 / 2.4) - .055) * 255 + .5);
32
+ }
33
+ function signPow(value, exp) {
34
+ return Math.sign(value) * Math.pow(Math.abs(value), exp);
35
+ }
36
+ function decodeBlurHash(hash, width, height) {
37
+ if (hash.length < 6) return null;
38
+ const sizeFlag = decode83(hash, 0, 1);
39
+ const quantisedMax = decode83(hash, 1, 2);
40
+ const dcValue = decode83(hash, 2, 6);
41
+ if (sizeFlag < 0 || quantisedMax < 0 || dcValue < 0) return null;
42
+ const numY = Math.floor(sizeFlag / 9) + 1;
43
+ const numX = sizeFlag % 9 + 1;
44
+ if (hash.length !== 4 + 2 * numX * numY) return null;
45
+ const maximumValue = (quantisedMax + 1) / 166;
46
+ const colors = new Array(numX * numY);
47
+ colors[0] = [
48
+ srgbToLinear(dcValue >> 16),
49
+ srgbToLinear(dcValue >> 8 & 255),
50
+ srgbToLinear(dcValue & 255)
51
+ ];
52
+ for (let i = 1; i < numX * numY; i++) {
53
+ const value = decode83(hash, 4 + i * 2, 6 + i * 2);
54
+ if (value < 0) return null;
55
+ const quantR = Math.floor(value / 361);
56
+ const quantG = Math.floor(value / 19) % 19;
57
+ const quantB = value % 19;
58
+ colors[i] = [
59
+ signPow((quantR - 9) / 9, 2) * maximumValue,
60
+ signPow((quantG - 9) / 9, 2) * maximumValue,
61
+ signPow((quantB - 9) / 9, 2) * maximumValue
62
+ ];
63
+ }
64
+ const pixels = new Uint8ClampedArray(width * height * 4);
65
+ for (let y = 0; y < height; y++) for (let x = 0; x < width; x++) {
66
+ let r = 0;
67
+ let g = 0;
68
+ let b = 0;
69
+ for (let j = 0; j < numY; j++) for (let i = 0; i < numX; i++) {
70
+ const basis = Math.cos(Math.PI * x * i / width) * Math.cos(Math.PI * y * j / height);
71
+ const color = colors[i + j * numX];
72
+ r += color[0] * basis;
73
+ g += color[1] * basis;
74
+ b += color[2] * basis;
75
+ }
76
+ const o = (x + y * width) * 4;
77
+ pixels[o] = linearToSrgb(r);
78
+ pixels[o + 1] = linearToSrgb(g);
79
+ pixels[o + 2] = linearToSrgb(b);
80
+ pixels[o + 3] = 255;
81
+ }
82
+ return pixels;
83
+ }
84
+ function thumbHashToApproximateAspectRatio(hash) {
85
+ const header = hash[3];
86
+ const hasAlpha = (hash[2] & 128) !== 0;
87
+ const isLandscape = (hash[4] & 128) !== 0;
88
+ return (isLandscape ? hasAlpha ? 5 : 7 : header & 7) / (isLandscape ? header & 7 : hasAlpha ? 5 : 7);
89
+ }
90
+ function thumbHashToRGBA(hash) {
91
+ if (hash.length < 5) return null;
92
+ const { PI, min, max, cos, round } = Math;
93
+ const header24 = hash[0] | hash[1] << 8 | hash[2] << 16;
94
+ const header16 = hash[3] | hash[4] << 8;
95
+ const l_dc = (header24 & 63) / 63;
96
+ const p_dc = (header24 >> 6 & 63) / 31.5 - 1;
97
+ const q_dc = (header24 >> 12 & 63) / 31.5 - 1;
98
+ const l_scale = (header24 >> 18 & 31) / 31;
99
+ const hasAlpha = header24 >> 23 !== 0;
100
+ const p_scale = (header16 >> 3 & 63) / 63;
101
+ const q_scale = (header16 >> 9 & 63) / 63;
102
+ const isLandscape = header16 >> 15 !== 0;
103
+ const lx = max(3, isLandscape ? hasAlpha ? 5 : 7 : header16 & 7);
104
+ const ly = max(3, isLandscape ? header16 & 7 : hasAlpha ? 5 : 7);
105
+ const a_dc = hasAlpha ? (hash[5] & 15) / 15 : 1;
106
+ const a_scale = (hash[5] >> 4) / 15;
107
+ const ac_start = hasAlpha ? 6 : 5;
108
+ let ac_index = 0;
109
+ const decodeChannel = (nx, ny, scale) => {
110
+ const ac = [];
111
+ for (let cy = 0; cy < ny; cy++) for (let cx = cy ? 0 : 1; cx * ny < nx * (ny - cy); cx++) {
112
+ const byte = hash[ac_start + (ac_index >> 1)];
113
+ if (byte === void 0) return null;
114
+ ac.push(((byte >> ((ac_index++ & 1) << 2) & 15) / 7.5 - 1) * scale);
115
+ }
116
+ return ac;
117
+ };
118
+ const l_ac = decodeChannel(lx, ly, l_scale);
119
+ const p_ac = decodeChannel(3, 3, p_scale * 1.25);
120
+ const q_ac = decodeChannel(3, 3, q_scale * 1.25);
121
+ const a_ac = hasAlpha ? decodeChannel(5, 5, a_scale) : null;
122
+ if (!l_ac || !p_ac || !q_ac || hasAlpha && !a_ac) return null;
123
+ const ratio = thumbHashToApproximateAspectRatio(hash);
124
+ const w = round(ratio > 1 ? 32 : 32 * ratio);
125
+ const h = round(ratio > 1 ? 32 / ratio : 32);
126
+ const rgba = new Uint8Array(w * h * 4);
127
+ const fx = [];
128
+ const fy = [];
129
+ for (let y = 0, i = 0; y < h; y++) for (let x = 0; x < w; x++, i += 4) {
130
+ let l = l_dc;
131
+ let p = p_dc;
132
+ let q = q_dc;
133
+ let a = a_dc;
134
+ for (let cx = 0, n = max(lx, hasAlpha ? 5 : 3); cx < n; cx++) fx[cx] = cos(PI / w * (x + .5) * cx);
135
+ for (let cy = 0, n = max(ly, hasAlpha ? 5 : 3); cy < n; cy++) fy[cy] = cos(PI / h * (y + .5) * cy);
136
+ for (let cy = 0, j = 0; cy < ly; cy++) for (let cx = cy ? 0 : 1, fy2 = fy[cy] * 2; cx * ly < lx * (ly - cy); cx++, j++) l += l_ac[j] * fx[cx] * fy2;
137
+ for (let cy = 0, j = 0; cy < 3; cy++) for (let cx = cy ? 0 : 1, fy2 = fy[cy] * 2; cx < 3 - cy; cx++, j++) {
138
+ const f = fx[cx] * fy2;
139
+ p += p_ac[j] * f;
140
+ q += q_ac[j] * f;
141
+ }
142
+ if (hasAlpha && a_ac) for (let cy = 0, j = 0; cy < 5; cy++) for (let cx = cy ? 0 : 1, fy2 = fy[cy] * 2; cx < 5 - cy; cx++, j++) a += a_ac[j] * fx[cx] * fy2;
143
+ const b = l - 2 / 3 * p;
144
+ const r = (3 * l - b + q) / 2;
145
+ const g = r - q;
146
+ rgba[i] = max(0, 255 * min(1, r));
147
+ rgba[i + 1] = max(0, 255 * min(1, g));
148
+ rgba[i + 2] = max(0, 255 * min(1, b));
149
+ rgba[i + 3] = max(0, 255 * min(1, a));
150
+ }
151
+ return {
152
+ w,
153
+ h,
154
+ rgba
155
+ };
156
+ }
157
+ var PNG_CRC_TABLE = [
158
+ 0,
159
+ 498536548,
160
+ 997073096,
161
+ 651767980,
162
+ 1994146192,
163
+ 1802195444,
164
+ 1303535960,
165
+ 1342533948,
166
+ -306674912,
167
+ -267414716,
168
+ -690576408,
169
+ -882789492,
170
+ -1687895376,
171
+ -2032938284,
172
+ -1609899400,
173
+ -1111625188
174
+ ];
175
+ /** Uncompressed PNG (zlib store blocks) — correctness over size; inputs are
176
+ * ~32px placeholders so the payload stays small. */
177
+ function rgbaToPng(w, h, rgba) {
178
+ const row = w * 4 + 1;
179
+ const idat = 6 + h * (5 + row);
180
+ const bytes = [
181
+ 137,
182
+ 80,
183
+ 78,
184
+ 71,
185
+ 13,
186
+ 10,
187
+ 26,
188
+ 10,
189
+ 0,
190
+ 0,
191
+ 0,
192
+ 13,
193
+ 73,
194
+ 72,
195
+ 68,
196
+ 82,
197
+ 0,
198
+ 0,
199
+ w >> 8,
200
+ w & 255,
201
+ 0,
202
+ 0,
203
+ h >> 8,
204
+ h & 255,
205
+ 8,
206
+ 6,
207
+ 0,
208
+ 0,
209
+ 0,
210
+ 0,
211
+ 0,
212
+ 0,
213
+ 0,
214
+ idat >>> 24,
215
+ idat >> 16 & 255,
216
+ idat >> 8 & 255,
217
+ idat & 255,
218
+ 73,
219
+ 68,
220
+ 65,
221
+ 84,
222
+ 120,
223
+ 1
224
+ ];
225
+ let a = 1;
226
+ let b = 0;
227
+ for (let y = 0, i = 0, end = row - 1; y < h; y++, end += row - 1) {
228
+ bytes.push(y + 1 < h ? 0 : 1, row & 255, row >> 8, ~row & 255, row >> 8 ^ 255, 0);
229
+ for (b = (b + a) % 65521; i < end; i++) {
230
+ const u = rgba[i] & 255;
231
+ bytes.push(u);
232
+ a = (a + u) % 65521;
233
+ b = (b + a) % 65521;
234
+ }
235
+ }
236
+ bytes.push(b >> 8, b & 255, a >> 8, a & 255, 0, 0, 0, 0, 0, 0, 0, 0, 73, 69, 78, 68, 174, 66, 96, 130);
237
+ for (let [start, end] of [[12, 29], [37, 41 + idat]]) {
238
+ let c = -1;
239
+ for (let i = start; i < end; i++) {
240
+ c ^= bytes[i];
241
+ c = c >>> 4 ^ PNG_CRC_TABLE[c & 15];
242
+ c = c >>> 4 ^ PNG_CRC_TABLE[c & 15];
243
+ }
244
+ c = ~c;
245
+ bytes[end++] = c >>> 24;
246
+ bytes[end++] = c >> 16 & 255;
247
+ bytes[end++] = c >> 8 & 255;
248
+ bytes[end++] = c & 255;
249
+ }
250
+ return bytes;
251
+ }
252
+ var BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
253
+ function base64Encode(bytes) {
254
+ let out = "";
255
+ for (let i = 0; i < bytes.length; i += 3) {
256
+ const b0 = bytes[i];
257
+ const b1 = i + 1 < bytes.length ? bytes[i + 1] : 0;
258
+ const b2 = i + 2 < bytes.length ? bytes[i + 2] : 0;
259
+ out += BASE64_CHARS[b0 >> 2];
260
+ out += BASE64_CHARS[(b0 & 3) << 4 | b1 >> 4];
261
+ out += i + 1 < bytes.length ? BASE64_CHARS[(b1 & 15) << 2 | b2 >> 6] : "=";
262
+ out += i + 2 < bytes.length ? BASE64_CHARS[b2 & 63] : "=";
263
+ }
264
+ return out;
265
+ }
266
+ function base64Decode(text) {
267
+ const clean = text.replace(/-/g, "+").replace(/_/g, "/").replace(/[\s=]/g, "");
268
+ const bytes = new Uint8Array(Math.floor(clean.length * 3 / 4));
269
+ let out = 0;
270
+ let acc = 0;
271
+ let bits = 0;
272
+ for (const ch of clean) {
273
+ const digit = BASE64_CHARS.indexOf(ch);
274
+ if (digit === -1) return null;
275
+ acc = acc << 6 | digit;
276
+ bits += 6;
277
+ if (bits >= 8) {
278
+ bits -= 8;
279
+ if (out < bytes.length) bytes[out++] = acc >> bits & 255;
280
+ }
281
+ }
282
+ return bytes.subarray(0, out);
283
+ }
284
+ //#endregion
285
+ export { hashToPngBase64 };
@@ -0,0 +1,134 @@
1
+ //#region src/image-content.ts
2
+ /** VENDORED from packages/ui/src/image-content.ts — keep in sync.
3
+ * Shared `contentFit`/`contentPosition` + multi-source math for `Image` —
4
+ * pure functions used by every leaf (docs/notes/expo-image-study.md L7/L8).
5
+ * Semantics mirror CSS `object-fit`/`object-position`, which is also
6
+ * expo-image's contract: the leaves compute the drawn-content rect
7
+ * themselves instead of delegating to platform scaleType/contentMode,
8
+ * so all platforms get the same answer.
9
+ *
10
+ * The default fit is 'cover' everywhere (the expo/RN default). Today's
11
+ * platform defaults disagree — web <img> is 'fill' and NS stretch is
12
+ * 'aspectFit' — so an un-propped Image was silently divergent. */
13
+ var DEFAULT_CONTENT_FIT = "cover";
14
+ function resolveContentFit(fit) {
15
+ return fit ?? "cover";
16
+ }
17
+ /** expo-image's keyword shorthands; the object form positions relative to
18
+ * any corner pair ({top,left}, {top,right}, {bottom,left}, {bottom,right}). */
19
+ var POSITION_KEYWORDS = {
20
+ center: {
21
+ top: "50%",
22
+ left: "50%"
23
+ },
24
+ top: {
25
+ top: 0,
26
+ left: "50%"
27
+ },
28
+ right: {
29
+ top: "50%",
30
+ right: 0
31
+ },
32
+ bottom: {
33
+ bottom: 0,
34
+ left: "50%"
35
+ },
36
+ left: {
37
+ top: "50%",
38
+ left: 0
39
+ },
40
+ "top center": {
41
+ top: 0,
42
+ left: "50%"
43
+ },
44
+ "top right": {
45
+ top: 0,
46
+ right: 0
47
+ },
48
+ "top left": {
49
+ top: 0,
50
+ left: 0
51
+ },
52
+ "right center": {
53
+ top: "50%",
54
+ right: 0
55
+ },
56
+ "right top": {
57
+ top: 0,
58
+ right: 0
59
+ },
60
+ "right bottom": {
61
+ bottom: 0,
62
+ right: 0
63
+ },
64
+ "bottom center": {
65
+ bottom: 0,
66
+ left: "50%"
67
+ },
68
+ "bottom right": {
69
+ bottom: 0,
70
+ right: 0
71
+ },
72
+ "bottom left": {
73
+ bottom: 0,
74
+ left: 0
75
+ },
76
+ "left center": {
77
+ top: "50%",
78
+ left: 0
79
+ },
80
+ "left top": {
81
+ top: 0,
82
+ left: 0
83
+ },
84
+ "left bottom": {
85
+ bottom: 0,
86
+ left: 0
87
+ }
88
+ };
89
+ function resolveContentPosition(position) {
90
+ if (typeof position === "string") return POSITION_KEYWORDS[position] ?? POSITION_KEYWORDS.center;
91
+ return position ?? POSITION_KEYWORDS.center;
92
+ }
93
+ function ensureWebUnits(value) {
94
+ const text = String(value).trim();
95
+ return text.endsWith("%") ? text : `${text}px`;
96
+ }
97
+ /** Browser `object-position` for a resolved position — mirrors expo-image
98
+ * web's `getObjectPositionFromContentPositionObject`. */
99
+ function objectPositionCSSValue(position) {
100
+ const resolved = { ...position };
101
+ if (resolved.top == null && resolved.bottom == null) resolved.top = "50%";
102
+ if (resolved.left == null && resolved.right == null) resolved.left = "50%";
103
+ return [
104
+ "top",
105
+ "bottom",
106
+ "left",
107
+ "right"
108
+ ].map((edge) => resolved[edge] != null ? `${edge} ${ensureWebUnits(resolved[edge])}` : "").filter((part) => part !== "").join(" ") || "50% 50%";
109
+ }
110
+ /** Browser `srcset` candidates for a source array: `w` descriptors (real
111
+ * file px = width·scale) when every source is sized, `x` descriptors when
112
+ * every source only carries density. `src` falls back to the largest
113
+ * declared pixel count — guaranteed coverage where srcset is ignored. */
114
+ function imageSrcSet(sources) {
115
+ if (sources.length === 0) return { src: "" };
116
+ const everyWidth = sources.every((source) => typeof source.width === "number" && source.width > 0);
117
+ const everyScale = !everyWidth && sources.every((source) => typeof source.scale === "number" && source.scale > 0);
118
+ const srcSet = everyWidth ? sources.map((source) => `${source.uri} ${Math.round(source.width * (source.scale ?? 1))}w`).join(", ") : everyScale ? sources.map((source) => `${source.uri} ${source.scale}x`).join(", ") : void 0;
119
+ let fallback = sources[0];
120
+ let bestCount = -Infinity;
121
+ for (const source of sources) {
122
+ const count = (source.width ?? 0) * (source.height ?? 0) * (source.scale ?? 1) ** 2;
123
+ if (count > bestCount) {
124
+ bestCount = count;
125
+ fallback = source;
126
+ }
127
+ }
128
+ return {
129
+ src: fallback.uri,
130
+ srcSet
131
+ };
132
+ }
133
+ //#endregion
134
+ export { DEFAULT_CONTENT_FIT, imageSrcSet, objectPositionCSSValue, resolveContentFit, resolveContentPosition };
@@ -0,0 +1,3 @@
1
+ import { Image } from "./Image.web.tsrx.js";
2
+ import { clearImageCaches, evictImage, initializeImageCache, isImageCached, prefetch } from "./cache.web.js";
3
+ export { Image, clearImageCaches, evictImage, initializeImageCache, isImageCached, prefetch };
@@ -0,0 +1,8 @@
1
+ {
2
+ "version": 1,
3
+ "buildId": "ffc5c92c-3485-4ca7-8f6c-48b323e0460a",
4
+ "mode": "production",
5
+ "capabilities": {
6
+ "independentHydration": false
7
+ }
8
+ }
@@ -0,0 +1,27 @@
1
+ function prefetchBatch(srcs, concurrency, warm) {
2
+ const urls = Array.isArray(srcs) ? srcs : [srcs];
3
+ if (urls.length === 0) return Promise.resolve(true);
4
+ const requested = Math.floor(concurrency ?? 5);
5
+ const limit = Number.isFinite(requested) && requested > 0 ? requested : 5;
6
+ return new Promise((resolve) => {
7
+ let next = 0;
8
+ let active = Math.min(limit, urls.length);
9
+ for (let i = 0; i < active; i++) (async () => {
10
+ while (next < urls.length) {
11
+ const url = urls[next++];
12
+ try {
13
+ if (!await warm(url)) {
14
+ resolve(false);
15
+ return;
16
+ }
17
+ } catch {
18
+ resolve(false);
19
+ return;
20
+ }
21
+ }
22
+ if (--active === 0) resolve(true);
23
+ })();
24
+ });
25
+ }
26
+ //#endregion
27
+ export { prefetchBatch };