@knitui/components 0.13.0 → 0.14.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Image.native.d.ts","sourceRoot":"","sources":["../../../src/Image/Image.native.tsx"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4LAKhB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"createImage.d.ts","sourceRoot":"","sources":["../../../src/Image/createImage.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAkB,aAAa,EAAE,MAAM,OAAO,CAAC;AAE3D,OAAO,EACL,KAAK,QAAQ,EAIb,IAAI,EAEL,MAAM,cAAc,CAAC;AAGtB,OAAO,EAAc,KAAK,UAAU,EAAE,MAAM,oBAAoB,CAAC;AASjE,OAAO,KAAK,EAAE,UAAU,EAAa,MAAM,SAAS,CAAC;AAErD,KAAK,cAAc,GAAG,UAAU,CAAC,OAAO,CAAC,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC;AACjE,KAAK,oBAAoB,GAAG;IAC1B,GAAG,CAAC,EAAE,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;;;;;IAHnC,kEAAkE;aACzD,UAAU,CAAC,WAAW,CAAC;IAChC,sEAAsE;oBACtD,OAAO,CAAC,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAHnC,kEAAkE;aACzD,UAAU,CAAC,WAAW,CAAC;IAChC,sEAAsE;oBACtD,OAAO,CAAC,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAHnC,kEAAkE;iBACzD,UAAU,CAAC,WAAW,CAAC;QAChC,sEAAsE;wBACtD,OAAO,CAAC,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAHnC,kEAAkE;iBACzD,UAAU,CAAC,WAAW,CAAC;QAChC,sEAAsE;wBACtD,OAAO,CAAC,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAHnC,kEAAkE;iBACzD,UAAU,CAAC,WAAW,CAAC;QAChC,sEAAsE;wBACtD,OAAO,CAAC,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAnHxB,KAAK,CAAC,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAAf,KAAK,CAAC,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAAf,KAAK,CAAC,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uJAiJ7B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knitui/components",
3
- "version": "0.13.0",
3
+ "version": "0.14.0",
4
4
  "description": "Cross-platform (React Native + Web) component kit for Knit UI.",
5
5
  "license": "MIT",
6
6
  "author": "The Haus <joost@the.haus>",
@@ -61,9 +61,9 @@
61
61
  "sideEffects": false,
62
62
  "dependencies": {
63
63
  "expo-image": "~57.0.5",
64
- "@knitui/core": "0.13.0",
65
- "@knitui/hooks": "0.13.0",
66
- "@knitui/icons": "0.13.0"
64
+ "@knitui/core": "0.14.0",
65
+ "@knitui/hooks": "0.14.0",
66
+ "@knitui/icons": "0.14.0"
67
67
  },
68
68
  "peerDependencies": {
69
69
  "react": "*",
@@ -0,0 +1,36 @@
1
+ import { Image as ExpoImage } from "expo-image";
2
+
3
+ import { createImage } from "./createImage";
4
+ import { objectFitToContentFit } from "./shared";
5
+
6
+ /**
7
+ * Native `Image` (iOS / Android), backed by
8
+ * [expo-image](https://docs.expo.dev/versions/latest/sdk/image/). The web twin
9
+ * (`Image.tsx`) renders its own `<img>` with the same props: expo-image's web
10
+ * build mounts its `<img>` only after an effect and replays the fade on every
11
+ * mount, so an image the browser already had blinked each time it came back.
12
+ *
13
+ * On top of expo-image's full prop surface (`transition`, `placeholder`,
14
+ * `cachePolicy`, `tintColor`, `blurRadius`, `priority`, …) it adds the unified,
15
+ * Mantine-compatible API: `src`, `fit`/`objectFit` (→ `contentFit`),
16
+ * `objectPosition` (→ `contentPosition`), `radius`, `fallbackSrc`, plus Tamagui
17
+ * styling props (`w`, `h`, `bg`, `$token`s). expo-image's static methods
18
+ * (`Image.prefetch`, `Image.clearMemoryCache`, …) are forwarded as-is.
19
+ *
20
+ * @example
21
+ * <Image
22
+ * src="https://example.com/photo.jpg"
23
+ * fallbackSrc="https://example.com/placeholder.jpg"
24
+ * fit="cover"
25
+ * radius="md"
26
+ * transition={300}
27
+ * w={320}
28
+ * h={180}
29
+ * />
30
+ */
31
+ export const Image = createImage({
32
+ Component: ExpoImage,
33
+ resizeModePropName: "contentFit",
34
+ objectPositionPropName: "contentPosition",
35
+ mapObjectFitToResizeMode: objectFitToContentFit,
36
+ });
@@ -1,34 +1,251 @@
1
- import { Image as ExpoImage } from "expo-image";
1
+ /// <reference lib="dom" />
2
+ import type { Image as ExpoImage } from "expo-image";
3
+ import * as React from "react";
4
+ import { View } from "react-native";
2
5
 
3
6
  import { createImage } from "./createImage";
4
- import { objectFitToContentFit } from "./shared";
7
+ import { normalizeContentPosition, objectFitToContentFit } from "./shared";
8
+ import type { ImageObjectFit, ImageObjectPosition, ImageType } from "./types";
5
9
 
6
10
  /**
7
- * Cross-platform `Image`, backed by [expo-image](https://docs.expo.dev/versions/latest/sdk/image/)
8
- * on web, iOS, and Android. The same file resolves on every platform because
9
- * expo-image ships platform builds (a real `<img>` on web, native views on
10
- * device), so there is no `.native` split.
11
+ * Web `Image`: the same component and props as the native one (`Image.native.tsx`,
12
+ * expo-image), rendered as a wrapper view plus a real `<img>` that is in the
13
+ * very first render — so it is in the server HTML, and an image the browser
14
+ * already has paints on the frame it mounts.
11
15
  *
12
- * On top of expo-image's full prop surface (`transition`, `placeholder`,
13
- * `cachePolicy`, `tintColor`, `blurRadius`, `priority`, …) it adds the unified,
14
- * Mantine-compatible API: `src`, `fit`/`objectFit` (→ `contentFit`),
15
- * `objectPosition` (→ `contentPosition`), `radius`, `fallbackSrc`, plus Tamagui
16
- * styling props (`w`, `h`, `bg`, `$token`s). expo-image's static methods
17
- * (`Image.prefetch`, `Image.clearMemoryCache`, …) are forwarded as-is.
16
+ * Why not expo-image's own web build: it renders NOTHING until an effect adds
17
+ * its `<img>` (one blank frame per mount, an empty box in the SSR markup), and
18
+ * its fade starts every mount at `opacity: 0` — cached or not. A virtualized
19
+ * list, a revisited page or a hydrating one remounts images all the time, so
20
+ * every one of them blinked.
18
21
  *
19
- * @example
20
- * <Image
21
- * src="https://example.com/photo.jpg"
22
- * fallbackSrc="https://example.com/placeholder.jpg"
23
- * fit="cover"
24
- * radius="md"
25
- * transition={300}
26
- * w={320}
27
- * h={180}
28
- * />
22
+ * Shown as soon as the browser can: `transition` is a NATIVE fade. On the web
23
+ * the `<img>` is never held hidden; the browser paints it as it decodes (a
24
+ * cached one at once), over whatever backdrop the caller gives the box.
25
+ *
26
+ * Kept from expo-image's web behaviour: `contentFit` → `object-fit` (default
27
+ * `cover`), `contentPosition` → `object-position`, lazy loading (the browser
28
+ * fetches an image as it nears the viewport), `priority` → `fetchpriority`,
29
+ * `blurRadius` → a CSS blur, a URL `placeholder` shown until the image loads
30
+ * (`placeholderContentFit`, default `scale-down`), and the load / error /
31
+ * display events with expo-image's payloads. `Image.prefetch` preloads through
32
+ * the browser cache.
33
+ *
34
+ * Not on web: BlurHash / ThumbHash placeholders (only URL placeholders render),
35
+ * `tintColor`, `transition`, and the cache-management statics
36
+ * (`clearMemoryCache` / `clearDiskCache` / `getCachePathAsync` /
37
+ * `generateBlurhashAsync` / `loadAsync` resolve as the no-ops `createImage`
38
+ * provides).
39
+ */
40
+
41
+ type Source = { uri?: string; width?: number; height?: number } | string | number | null;
42
+ type ContentPosition = Exclude<ImageObjectPosition, string> | string;
43
+
44
+ type WebImageProps = {
45
+ source?: Source | Source[];
46
+ placeholder?: Source | Source[];
47
+ contentFit?: ImageObjectFit;
48
+ contentPosition?: ContentPosition;
49
+ placeholderContentFit?: ImageObjectFit;
50
+ blurRadius?: number;
51
+ priority?: "low" | "normal" | "high" | null;
52
+ loading?: "lazy" | "eager";
53
+ responsivePolicy?: string;
54
+ accessibilityLabel?: string;
55
+ alt?: string;
56
+ draggable?: boolean;
57
+ onLoadStart?: () => void;
58
+ onLoad?: (event: {
59
+ source: { url: string; width: number; height: number; mediaType: null };
60
+ cacheType: "none";
61
+ }) => void;
62
+ onError?: (event: { error: string }) => void;
63
+ onLoadEnd?: () => void;
64
+ onDisplay?: () => void;
65
+ // Accepted for parity with the native surface; no web effect.
66
+ transition?: unknown;
67
+ tintColor?: unknown;
68
+ cachePolicy?: unknown;
69
+ recyclingKey?: unknown;
70
+ style?: unknown;
71
+ };
72
+
73
+ const FILL: React.CSSProperties = {
74
+ position: "absolute",
75
+ left: 0,
76
+ top: 0,
77
+ width: "100%",
78
+ height: "100%",
79
+ };
80
+
81
+ /** The first renderable URL of an expo-image source (string, `{ uri }`, list). */
82
+ function sourceUri(source: Source | Source[] | undefined): string | undefined {
83
+ const first = Array.isArray(source) ? source[0] : source;
84
+ if (first == null || typeof first === "number") return undefined;
85
+ if (typeof first === "string") return first;
86
+ return first.uri;
87
+ }
88
+
89
+ /** A placeholder string is a URL, not a BlurHash / ThumbHash. */
90
+ function isUrlLike(value: string): boolean {
91
+ return /^(https?:|data:|blob:|file:|\/|\.\.?\/)/.test(value) || value.includes("://");
92
+ }
93
+
94
+ /** expo-image's web units: numbers are px, percentages pass through. */
95
+ function webUnits(value: string | number): string {
96
+ const text = String(value).trim();
97
+ return text.endsWith("%") ? text : `${text}px`;
98
+ }
99
+
100
+ /** expo-image's `contentPosition` (object or CSS string) → CSS `object-position`. */
101
+ export function objectPositionOf(position: ContentPosition | undefined): string {
102
+ const object = normalizeContentPosition(position as ImageObjectPosition | undefined) as
103
+ Record<string, string | number> | undefined;
104
+ if (!object) return "50% 50%";
105
+ const resolved = { ...object };
106
+ if (resolved.top == null && resolved.bottom == null) resolved.top = "50%";
107
+ if (resolved.left == null && resolved.right == null) resolved.left = "50%";
108
+ return (
109
+ (["top", "bottom", "left", "right"] as const)
110
+ .filter((key) => resolved[key] != null)
111
+ .map((key) => `${key} ${webUnits(resolved[key]!)}`)
112
+ .join(" ") || "50% 50%"
113
+ );
114
+ }
115
+
116
+ const WebImage = React.forwardRef<unknown, WebImageProps>(function WebImage(props, ref) {
117
+ const {
118
+ source,
119
+ placeholder,
120
+ contentFit = "cover",
121
+ contentPosition,
122
+ placeholderContentFit = "scale-down",
123
+ blurRadius,
124
+ priority,
125
+ loading,
126
+ responsivePolicy,
127
+ accessibilityLabel,
128
+ alt,
129
+ draggable,
130
+ onLoadStart,
131
+ onLoad,
132
+ onError,
133
+ onLoadEnd,
134
+ onDisplay,
135
+ transition: _transition,
136
+ tintColor: _tintColor,
137
+ cachePolicy: _cachePolicy,
138
+ recyclingKey: _recyclingKey,
139
+ style,
140
+ ...rest
141
+ } = props as WebImageProps & Record<string, unknown>;
142
+
143
+ const uri = sourceUri(source);
144
+ const placeholderValue = sourceUri(placeholder);
145
+ const placeholderUri =
146
+ placeholderValue && isUrlLike(placeholderValue) ? placeholderValue : undefined;
147
+ // Keyed on the source, so a new `uri` brings its placeholder back without an effect.
148
+ const [loadedUri, setLoadedUri] = React.useState<string>();
149
+
150
+ React.useEffect(() => {
151
+ if (uri) onLoadStart?.();
152
+ // `onLoadStart` is an event prop: a new identity is not a new load.
153
+ // eslint-disable-next-line react-hooks/exhaustive-deps
154
+ }, [uri]);
155
+
156
+ const filter = blurRadius ? `blur(${blurRadius}px)` : undefined;
157
+ const label = accessibilityLabel ?? alt;
158
+ const fetchPriority = priority === "high" || priority === "low" ? priority : undefined;
159
+ const resolvedLoading =
160
+ loading ?? (responsivePolicy == null || responsivePolicy === "static" ? "lazy" : undefined);
161
+
162
+ const handleLoad = (event: React.SyntheticEvent<HTMLImageElement>) => {
163
+ const target = event.currentTarget;
164
+ setLoadedUri(uri);
165
+ onLoad?.({
166
+ source: {
167
+ url: target.currentSrc || target.src,
168
+ width: target.naturalWidth,
169
+ height: target.naturalHeight,
170
+ mediaType: null,
171
+ },
172
+ cacheType: "none",
173
+ });
174
+ onLoadEnd?.();
175
+ // There is no "displayed" event on the web; the repaint after the load is it.
176
+ if (onDisplay && typeof requestAnimationFrame === "function") {
177
+ requestAnimationFrame(() => onDisplay());
178
+ }
179
+ };
180
+
181
+ const handleError = () => {
182
+ onError?.({ error: `Failed to load image from url: ${uri}` });
183
+ onLoadEnd?.();
184
+ };
185
+
186
+ return (
187
+ <View ref={ref as never} {...(rest as object)} style={[{ overflow: "hidden" }, style as never]}>
188
+ {placeholderUri && loadedUri !== uri ? (
189
+ <img
190
+ src={placeholderUri}
191
+ alt=""
192
+ aria-hidden
193
+ draggable={draggable}
194
+ style={{ ...FILL, objectFit: placeholderContentFit, filter }}
195
+ />
196
+ ) : null}
197
+ {uri ? (
198
+ <img
199
+ // A new source is a new element: the old bitmap never shows under the new URL.
200
+ key={uri}
201
+ src={uri}
202
+ {...(label !== undefined && { alt: label })}
203
+ loading={resolvedLoading}
204
+ // React 19 knows `fetchPriority`; older DOM typings don't.
205
+ {...(fetchPriority && ({ fetchPriority } as object))}
206
+ draggable={draggable}
207
+ onLoad={handleLoad}
208
+ onError={handleError}
209
+ style={{
210
+ ...FILL,
211
+ objectFit: contentFit,
212
+ objectPosition: objectPositionOf(contentPosition),
213
+ filter,
214
+ }}
215
+ />
216
+ ) : null}
217
+ </View>
218
+ );
219
+ });
220
+
221
+ /** Warm the browser cache for one or more URLs; resolves `true` when all loaded. */
222
+ function prefetch(urls: string | string[]): Promise<boolean> {
223
+ const list = Array.isArray(urls) ? urls : [urls];
224
+ if (typeof window === "undefined" || typeof window.Image !== "function") {
225
+ return Promise.resolve(false);
226
+ }
227
+ return Promise.all(
228
+ list.map(
229
+ (url) =>
230
+ new Promise<boolean>((resolve) => {
231
+ const image = new window.Image();
232
+ image.onload = () => resolve(true);
233
+ image.onerror = () => resolve(false);
234
+ image.src = url;
235
+ }),
236
+ ),
237
+ ).then((results) => results.every(Boolean));
238
+ }
239
+
240
+ (WebImage as unknown as Partial<ImageType>).prefetch = prefetch as ImageType["prefetch"];
241
+
242
+ /**
243
+ * Cross-platform `Image` (web build). Same API and types as on native — see
244
+ * `Image.native.tsx` for the full prop surface and examples.
29
245
  */
30
246
  export const Image = createImage({
31
- Component: ExpoImage,
247
+ // Typed as expo-image so both platforms export one prop surface.
248
+ Component: WebImage as unknown as typeof ExpoImage,
32
249
  resizeModePropName: "contentFit",
33
250
  objectPositionPropName: "contentPosition",
34
251
  mapObjectFitToResizeMode: objectFitToContentFit,
@@ -207,14 +207,17 @@ const CACHED_LOAD_MAX_FRAMES = 10;
207
207
 
208
208
  /**
209
209
  * Find the rendered `<img>` behind a backend instance on web: the instance itself
210
- * (a plain `<img>` backend), or expo-image's container `<div>` (the LAST `<img>`
211
- * in it is the current source; a placeholder node, when any, comes first).
210
+ * (a plain `<img>` backend), or the backend's container element — the kit's web
211
+ * `Image` wrapper, or expo-image's `containerViewRef` — whose LAST `<img>` is the
212
+ * current source (a placeholder node, when any, comes first).
212
213
  */
213
214
  const findWebImg = (instance: unknown): HTMLImageElement | null => {
214
215
  if (typeof HTMLElement === "undefined" || instance == null) return null;
215
216
  if (instance instanceof HTMLImageElement) return instance;
216
- const container = (instance as { containerViewRef?: { current?: unknown } }).containerViewRef
217
- ?.current;
217
+ const container =
218
+ instance instanceof HTMLElement
219
+ ? instance
220
+ : (instance as { containerViewRef?: { current?: unknown } }).containerViewRef?.current;
218
221
  if (container instanceof HTMLElement) {
219
222
  const imgs = container.querySelectorAll("img");
220
223
  return imgs.length ? imgs[imgs.length - 1]! : null;