@colixsystems/widget-sdk 0.363.0 → 0.364.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.
- package/README.md +5 -1
- package/dist/file-image-logic.js +15 -2
- package/dist/file-image.native.js +14 -1
- package/dist/host.d.ts +12 -0
- package/dist/host.js +4 -0
- package/dist/svg-image.js +18 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -93,7 +93,11 @@ See the design reference for the full architecture: [`docs/architecture/widget-m
|
|
|
93
93
|
|
|
94
94
|
## Status
|
|
95
95
|
|
|
96
|
-
`v0.
|
|
96
|
+
`v0.364.0` — pre-publish. The package surface (types, function names, export paths) is the v1 contract; runtime behaviour for some hooks is stubbed (each hook documents what's wired and what isn't). It is **not yet published to npm**.
|
|
97
|
+
|
|
98
|
+
### What's new in 0.364.0 (contract 1.299.0)
|
|
99
|
+
|
|
100
|
+
**`<FileImage>` draws an SVG in the exported app.** React Native's own Image cannot draw a vector, so a picture whose URL names an `.svg` file loads through expo-image on native, fitted as its `resizeMode` asks. Every other picture still loads through React Native's Image, and the web Player already drew both. The host-only entry (`@colixsystems/widget-sdk/host`, not for widget authors) gains `isSvgUrl` and `svgCapableImage`, which the exported app's logos draw through. Minor bump for the new host exports.
|
|
97
101
|
|
|
98
102
|
### What's new in 0.363.0 (contract 1.299.0)
|
|
99
103
|
|
package/dist/file-image-logic.js
CHANGED
|
@@ -41,6 +41,18 @@ export function normaliseFileImageResizeMode(mode) {
|
|
|
41
41
|
return FILE_IMAGE_RESIZE_MODES.includes(mode) ? mode : "cover";
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
const CONTENT_FIT_BY_RESIZE_MODE = Object.freeze({ cover: "cover", contain: "contain", stretch: "fill", center: "scale-down" });
|
|
45
|
+
|
|
46
|
+
/** expo-image's `contentFit` for a resize mode, fitting as React Native's would. */
|
|
47
|
+
export function fileImageContentFit(mode) {
|
|
48
|
+
return CONTENT_FIT_BY_RESIZE_MODE[normaliseFileImageResizeMode(mode)];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** A URL whose path names an SVG, which React Native's own Image cannot draw. */
|
|
52
|
+
export function isSvgUrl(uri) {
|
|
53
|
+
return typeof uri === "string" && /\.svg$/i.test(uri.split(/[?#]/)[0]);
|
|
54
|
+
}
|
|
55
|
+
|
|
44
56
|
/**
|
|
45
57
|
* The URL a variant loads: its rung of the size ladder, else the original
|
|
46
58
|
* (a file projected before the ladder shipped has no `urls`).
|
|
@@ -96,10 +108,11 @@ export function fileImageRadius(radius, radii) {
|
|
|
96
108
|
|
|
97
109
|
/**
|
|
98
110
|
* The loaded picture's pixel size, from either host's load event: React Native
|
|
99
|
-
* reports `nativeEvent.source`, the web the decoded
|
|
111
|
+
* reports `nativeEvent.source`, expo-image `source`, the web the decoded
|
|
112
|
+
* element's natural size.
|
|
100
113
|
*/
|
|
101
114
|
export function intrinsicSizeOf(event) {
|
|
102
|
-
const native = event && event.nativeEvent;
|
|
115
|
+
const native = event && (event.nativeEvent || event);
|
|
103
116
|
if (!native) return null;
|
|
104
117
|
const source = native.source;
|
|
105
118
|
if (source && positive(source.width) && positive(source.height)) {
|
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
// `<FileImage>` (native). Binds ./file-image-view.js to React Native and the
|
|
2
2
|
// native `<Skeleton>`; only the imports differ from ./file-image.js.
|
|
3
3
|
|
|
4
|
+
import { createElement } from "react";
|
|
4
5
|
import { View, Image } from "react-native";
|
|
5
6
|
import { Skeleton } from "./loading.native.js";
|
|
6
7
|
import { makeFileImage } from "./file-image-view.js";
|
|
8
|
+
import { svgCapableImage } from "./svg-image.js";
|
|
7
9
|
|
|
8
|
-
export
|
|
10
|
+
// Pinned in every export; only a dev client older than the pin lacks it.
|
|
11
|
+
function loadExpoImage() {
|
|
12
|
+
try {
|
|
13
|
+
return require("expo-image").Image;
|
|
14
|
+
} catch (_) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const PictureImage = svgCapableImage({ createElement, Image, ExpoImage: loadExpoImage() });
|
|
20
|
+
|
|
21
|
+
export const { FileImage } = makeFileImage({ View, Image: PictureImage }, Skeleton);
|
package/dist/host.d.ts
CHANGED
|
@@ -805,3 +805,15 @@ export function normaliseContainerPattern(
|
|
|
805
805
|
export function containerPatternTile(pattern: ContainerPattern): { size: number; paths: ContainerPatternPath[] };
|
|
806
806
|
/** The tile as standalone SVG markup, for a CSS background. */
|
|
807
807
|
export function containerPatternSvg(pattern: ContainerPattern): string;
|
|
808
|
+
|
|
809
|
+
/** Whether a URL's path names an SVG, which React Native's own Image cannot draw. */
|
|
810
|
+
export function isSvgUrl(uri: unknown): boolean;
|
|
811
|
+
/**
|
|
812
|
+
* A native image component: React Native's `Image`, or `ExpoImage` for an SVG's
|
|
813
|
+
* URL, fitted as its `resizeMode` asks. Takes React Native Image props.
|
|
814
|
+
*/
|
|
815
|
+
export function svgCapableImage<P extends { source?: { uri?: string }; resizeMode?: string }>(parts: {
|
|
816
|
+
createElement: typeof import("react").createElement;
|
|
817
|
+
Image: import("react").ComponentType<P>;
|
|
818
|
+
ExpoImage: import("react").ComponentType<any> | null;
|
|
819
|
+
}): import("react").ComponentType<P>;
|
package/dist/host.js
CHANGED
|
@@ -210,3 +210,7 @@ export {
|
|
|
210
210
|
containerPatternTile,
|
|
211
211
|
containerPatternSvg,
|
|
212
212
|
} from "./container-pattern.js";
|
|
213
|
+
|
|
214
|
+
// sc-18973: an SVG picture on native, for <FileImage> and the export's logos.
|
|
215
|
+
export { isSvgUrl } from "./file-image-logic.js";
|
|
216
|
+
export { svgCapableImage } from "./svg-image.js";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// An SVG picture on native. React Native's own Image cannot draw a vector;
|
|
2
|
+
// expo-image can. One rule for `<FileImage>` and the export's chrome logos.
|
|
3
|
+
// React-free, as host.js is: the caller passes its createElement.
|
|
4
|
+
|
|
5
|
+
import { fileImageContentFit, isSvgUrl } from "./file-image-logic.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* React Native's `Image`, or `ExpoImage` for an SVG's URL, fitted as the
|
|
9
|
+
* `resizeMode` asks. Without expo-image the Image's own failure shows.
|
|
10
|
+
*/
|
|
11
|
+
export function svgCapableImage({ createElement, Image, ExpoImage }) {
|
|
12
|
+
return function PictureImage({ resizeMode, ...props }) {
|
|
13
|
+
if (ExpoImage && isSvgUrl(props.source && props.source.uri)) {
|
|
14
|
+
return createElement(ExpoImage, { ...props, contentFit: fileImageContentFit(resizeMode) });
|
|
15
|
+
}
|
|
16
|
+
return createElement(Image, { ...props, resizeMode });
|
|
17
|
+
};
|
|
18
|
+
}
|
package/package.json
CHANGED