@granite-js/image 0.1.19 → 0.1.21

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/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @granite-js/image
2
2
 
3
+ ## 0.1.21
4
+
5
+ ### Patch Changes
6
+
7
+ - @granite-js/native@0.1.21
8
+
9
+ ## 0.1.20
10
+
11
+ ### Patch Changes
12
+
13
+ - 1df5883: update package.json meta to supports any moduleResolutions
14
+ - Updated dependencies [1df5883]
15
+ - @granite-js/native@0.1.20
16
+
3
17
  ## 0.1.19
4
18
 
5
19
  ### Patch Changes
@@ -1,10 +1,13 @@
1
- import { FastImageProps, Source as FastImageSource } from '@granite-js/native/react-native-fast-image';
2
- type Source = {
3
- uri?: string;
4
- cache?: FastImageSource['cache'];
1
+ import { FastImageProps, Source } from "@granite-js/native/react-native-fast-image";
2
+ import * as react_jsx_runtime0 from "react/jsx-runtime";
3
+
4
+ //#region src/Image.d.ts
5
+ type Source$1 = {
6
+ uri?: string;
7
+ cache?: Source['cache'];
5
8
  };
6
- export interface ImageProps extends Omit<FastImageProps, 'source'> {
7
- source?: Source;
9
+ interface ImageProps extends Omit<FastImageProps, 'source'> {
10
+ source?: Source$1;
8
11
  }
9
12
  /**
10
13
  * @public
@@ -62,5 +65,6 @@ export interface ImageProps extends Omit<FastImageProps, 'source'> {
62
65
  * }
63
66
  * ```
64
67
  */
65
- declare function Image(props: ImageProps): import("react/jsx-runtime").JSX.Element;
66
- export { Image };
68
+ declare function Image(props: ImageProps): react_jsx_runtime0.JSX.Element;
69
+ //#endregion
70
+ export { Image, type ImageProps };
package/dist/index.d.ts CHANGED
@@ -1 +1,70 @@
1
- export { Image, type ImageProps } from './Image';
1
+ import * as react_jsx_runtime0 from "react/jsx-runtime";
2
+ import { FastImageProps, Source } from "@granite-js/native/react-native-fast-image";
3
+
4
+ //#region src/Image.d.ts
5
+ type Source$1 = {
6
+ uri?: string;
7
+ cache?: Source['cache'];
8
+ };
9
+ interface ImageProps extends Omit<FastImageProps, 'source'> {
10
+ source?: Source$1;
11
+ }
12
+ /**
13
+ * @public
14
+ * @category UI
15
+ * @name Image
16
+ * @description You can use the `Image` component to load and render bitmap images (such as PNG, JPG) or vector images (SVG). It automatically renders with the appropriate method depending on the image format.
17
+ * @link https://github.com/DylanVann/react-native-fast-image/tree/v8.6.3/README.md
18
+ *
19
+ * @param {object} [props] - The `props` object passed to the component.
20
+ * @param {object} [props.style] - An object that defines the style for the image component. It can include layout-related properties like `width` and `height`.
21
+ * @param {object} [props.source] - An object containing information about the image resource to load.
22
+ * @param {string} [props.source.uri] - The URI address representing the image resource to load.
23
+ * @param {'immutable' | 'web' | 'cacheOnly'} [props.source.cache = 'immutable'] - An option to set the image caching strategy. This applies only to bitmap images. The default value is `immutable`.
24
+ * @param {() => void} [props.onLoadStart] - A callback function that is called when image loading starts.
25
+ * @param {() => void} [props.onLoadEnd] - A callback function that is called when image loading finishes.
26
+ * @param {() => void} [props.onError] - A callback function that is called when an error occurs during image loading.
27
+ *
28
+ * @example
29
+ * ### Example: Loading and rendering an image
30
+ *
31
+ * The following example shows how to load bitmap and vector image resources, and how to print an error message to `console.log` if an error occurs.
32
+ *
33
+ * ```tsx
34
+ * import { Image } from '@granite-js/react-native';
35
+ * import { View } from 'react-native';
36
+ *
37
+ * export function ImageExample() {
38
+ * return (
39
+ * <View>
40
+ * <Image
41
+ * source={{ uri: 'my-image-link' }}
42
+ * style={{
43
+ * width: 300,
44
+ * height: 300,
45
+ * borderWidth: 1,
46
+ * }}
47
+ * onError={() => {
48
+ * console.log('Failed to load image');
49
+ * }}
50
+ * />
51
+ *
52
+ * <Image
53
+ * source={{ uri: 'my-svg-link' }}
54
+ * style={{
55
+ * width: 300,
56
+ * height: 300,
57
+ * borderWidth: 1,
58
+ * }}
59
+ * onError={() => {
60
+ * console.log('Failed to load image');
61
+ * }}
62
+ * />
63
+ * </View>
64
+ * );
65
+ * }
66
+ * ```
67
+ */
68
+ declare function Image(props: ImageProps): react_jsx_runtime0.JSX.Element;
69
+ //#endregion
70
+ export { Image, type ImageProps };
package/dist/index.js ADDED
@@ -0,0 +1,204 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+
23
+ //#endregion
24
+ const __granite_js_native_react_native_fast_image = __toESM(require("@granite-js/native/react-native-fast-image"));
25
+ const react_native = __toESM(require("react-native"));
26
+ const __granite_js_native_react_native_svg = __toESM(require("@granite-js/native/react-native-svg"));
27
+ const react = __toESM(require("react"));
28
+ const react_simplikit = __toESM(require("react-simplikit"));
29
+ const react_jsx_runtime = __toESM(require("react/jsx-runtime"));
30
+
31
+ //#region src/SvgImage.tsx
32
+ /**
33
+ * @name SvgImage
34
+ * @category Components
35
+ * @description The `SvgImage` component loads and renders SVG images from a given external URL.
36
+ * @link https://github.com/software-mansion/react-native-svg/tree/v13.14.0/README.md
37
+ *
38
+ * @param {object} props - The `props` object passed to the component.
39
+ * @param {string} props.url - The URI address of the SVG image to load.
40
+ * @param {number | string} [props.width = '100%'] - Sets the horizontal size of the SVG image. Default value is '`100%`'.
41
+ * @param {number | string} [props.height = '100%'] - Sets the vertical size of the SVG image. Default value is '`100%`'.
42
+ * @param {object} props.style - Sets the style of the image component.
43
+ * @param {() => void} props.onLoadStart - A callback function called when the SVG image resource starts loading.
44
+ * @param {() => void} props.onLoadEnd - A callback function called after the SVG image resource is loaded.
45
+ * @param {() => void} props.onError - A callback function called when an error occurs during SVG image loading.
46
+ *
47
+ * @example
48
+ * ```tsx
49
+ * import { SvgImage } from './SvgImage';
50
+ * import { View } from 'react-native';
51
+ *
52
+ * function MyComponent() {
53
+ * return (
54
+ * <View>
55
+ * <SvgImage
56
+ * url="https://example.com/icon.svg"
57
+ * width={100}
58
+ * height={100}
59
+ * onError={() => console.log('An error occurred while loading the SVG')}
60
+ * />
61
+ * </View>
62
+ * );
63
+ * }
64
+ * ```
65
+ */
66
+ function SvgImage({ url, width = "100%", height = "100%", style, testID, onLoadStart: _onLoadStart, onLoadEnd: _onLoadEnd, onError: _onError }) {
67
+ const svgStyle = {
68
+ width,
69
+ height
70
+ };
71
+ const [data, setData] = (0, react.useState)(void 0);
72
+ const [isError, setIsError] = (0, react.useState)(false);
73
+ const onLoadStart = (0, react_simplikit.usePreservedCallback)(() => _onLoadStart?.());
74
+ const onLoadEnd = (0, react_simplikit.usePreservedCallback)(() => _onLoadEnd?.());
75
+ const onError = (0, react_simplikit.usePreservedCallback)(() => _onError?.());
76
+ const Fallback = (0, react.useCallback)(() => (0, react.createElement)(react_native.View, { style: {
77
+ width,
78
+ height
79
+ } }, null), [width, height]);
80
+ (0, react.useEffect)(() => {
81
+ let isMounted = true;
82
+ /**
83
+ * First attempts to fetch the XML resource, and if that fails, tries to load directly by passing the URI to the Svg component
84
+ */
85
+ async function fetchSvg() {
86
+ onLoadStart();
87
+ try {
88
+ const response = await fetch(url);
89
+ const svg = await response.text();
90
+ if (isMounted) {
91
+ onLoadEnd();
92
+ setData(svg);
93
+ }
94
+ } catch {
95
+ setIsError(true);
96
+ }
97
+ }
98
+ fetchSvg();
99
+ return () => {
100
+ isMounted = false;
101
+ };
102
+ }, [
103
+ onLoadStart,
104
+ onLoadEnd,
105
+ url
106
+ ]);
107
+ if (data == null) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Fallback, {});
108
+ if (isError) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__granite_js_native_react_native_svg.SvgUri, {
109
+ testID,
110
+ uri: url,
111
+ style,
112
+ ...svgStyle,
113
+ onError,
114
+ onLoad: onLoadEnd,
115
+ fallback: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Fallback, {})
116
+ });
117
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__granite_js_native_react_native_svg.SvgXml, {
118
+ testID,
119
+ xml: data,
120
+ style,
121
+ ...svgStyle,
122
+ fallback: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Fallback, {})
123
+ });
124
+ }
125
+
126
+ //#endregion
127
+ //#region src/Image.tsx
128
+ /**
129
+ * @public
130
+ * @category UI
131
+ * @name Image
132
+ * @description You can use the `Image` component to load and render bitmap images (such as PNG, JPG) or vector images (SVG). It automatically renders with the appropriate method depending on the image format.
133
+ * @link https://github.com/DylanVann/react-native-fast-image/tree/v8.6.3/README.md
134
+ *
135
+ * @param {object} [props] - The `props` object passed to the component.
136
+ * @param {object} [props.style] - An object that defines the style for the image component. It can include layout-related properties like `width` and `height`.
137
+ * @param {object} [props.source] - An object containing information about the image resource to load.
138
+ * @param {string} [props.source.uri] - The URI address representing the image resource to load.
139
+ * @param {'immutable' | 'web' | 'cacheOnly'} [props.source.cache = 'immutable'] - An option to set the image caching strategy. This applies only to bitmap images. The default value is `immutable`.
140
+ * @param {() => void} [props.onLoadStart] - A callback function that is called when image loading starts.
141
+ * @param {() => void} [props.onLoadEnd] - A callback function that is called when image loading finishes.
142
+ * @param {() => void} [props.onError] - A callback function that is called when an error occurs during image loading.
143
+ *
144
+ * @example
145
+ * ### Example: Loading and rendering an image
146
+ *
147
+ * The following example shows how to load bitmap and vector image resources, and how to print an error message to `console.log` if an error occurs.
148
+ *
149
+ * ```tsx
150
+ * import { Image } from '@granite-js/react-native';
151
+ * import { View } from 'react-native';
152
+ *
153
+ * export function ImageExample() {
154
+ * return (
155
+ * <View>
156
+ * <Image
157
+ * source={{ uri: 'my-image-link' }}
158
+ * style={{
159
+ * width: 300,
160
+ * height: 300,
161
+ * borderWidth: 1,
162
+ * }}
163
+ * onError={() => {
164
+ * console.log('Failed to load image');
165
+ * }}
166
+ * />
167
+ *
168
+ * <Image
169
+ * source={{ uri: 'my-svg-link' }}
170
+ * style={{
171
+ * width: 300,
172
+ * height: 300,
173
+ * borderWidth: 1,
174
+ * }}
175
+ * onError={() => {
176
+ * console.log('Failed to load image');
177
+ * }}
178
+ * />
179
+ * </View>
180
+ * );
181
+ * }
182
+ * ```
183
+ */
184
+ function Image(props) {
185
+ if (typeof props.source === "object" && props.source.uri?.endsWith(".svg")) {
186
+ const style = react_native.StyleSheet.flatten(props.style);
187
+ const width = style?.width;
188
+ const height = style?.height;
189
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SvgImage, {
190
+ testID: props.testID,
191
+ url: props.source.uri,
192
+ width,
193
+ height,
194
+ style: props.style,
195
+ onLoadStart: props.onLoadStart,
196
+ onLoadEnd: props.onLoadEnd,
197
+ onError: props.onError
198
+ });
199
+ }
200
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__granite_js_native_react_native_fast_image.default, { ...props });
201
+ }
202
+
203
+ //#endregion
204
+ exports.Image = Image;
package/dist/index.mjs ADDED
@@ -0,0 +1,181 @@
1
+ import FastImage from "@granite-js/native/react-native-fast-image";
2
+ import { StyleSheet, View } from "react-native";
3
+ import { SvgUri, SvgXml } from "@granite-js/native/react-native-svg";
4
+ import { createElement, useCallback, useEffect, useState } from "react";
5
+ import { usePreservedCallback } from "react-simplikit";
6
+ import { jsx } from "react/jsx-runtime";
7
+
8
+ //#region src/SvgImage.tsx
9
+ /**
10
+ * @name SvgImage
11
+ * @category Components
12
+ * @description The `SvgImage` component loads and renders SVG images from a given external URL.
13
+ * @link https://github.com/software-mansion/react-native-svg/tree/v13.14.0/README.md
14
+ *
15
+ * @param {object} props - The `props` object passed to the component.
16
+ * @param {string} props.url - The URI address of the SVG image to load.
17
+ * @param {number | string} [props.width = '100%'] - Sets the horizontal size of the SVG image. Default value is '`100%`'.
18
+ * @param {number | string} [props.height = '100%'] - Sets the vertical size of the SVG image. Default value is '`100%`'.
19
+ * @param {object} props.style - Sets the style of the image component.
20
+ * @param {() => void} props.onLoadStart - A callback function called when the SVG image resource starts loading.
21
+ * @param {() => void} props.onLoadEnd - A callback function called after the SVG image resource is loaded.
22
+ * @param {() => void} props.onError - A callback function called when an error occurs during SVG image loading.
23
+ *
24
+ * @example
25
+ * ```tsx
26
+ * import { SvgImage } from './SvgImage';
27
+ * import { View } from 'react-native';
28
+ *
29
+ * function MyComponent() {
30
+ * return (
31
+ * <View>
32
+ * <SvgImage
33
+ * url="https://example.com/icon.svg"
34
+ * width={100}
35
+ * height={100}
36
+ * onError={() => console.log('An error occurred while loading the SVG')}
37
+ * />
38
+ * </View>
39
+ * );
40
+ * }
41
+ * ```
42
+ */
43
+ function SvgImage({ url, width = "100%", height = "100%", style, testID, onLoadStart: _onLoadStart, onLoadEnd: _onLoadEnd, onError: _onError }) {
44
+ const svgStyle = {
45
+ width,
46
+ height
47
+ };
48
+ const [data, setData] = useState(void 0);
49
+ const [isError, setIsError] = useState(false);
50
+ const onLoadStart = usePreservedCallback(() => _onLoadStart?.());
51
+ const onLoadEnd = usePreservedCallback(() => _onLoadEnd?.());
52
+ const onError = usePreservedCallback(() => _onError?.());
53
+ const Fallback = useCallback(() => createElement(View, { style: {
54
+ width,
55
+ height
56
+ } }, null), [width, height]);
57
+ useEffect(() => {
58
+ let isMounted = true;
59
+ /**
60
+ * First attempts to fetch the XML resource, and if that fails, tries to load directly by passing the URI to the Svg component
61
+ */
62
+ async function fetchSvg() {
63
+ onLoadStart();
64
+ try {
65
+ const response = await fetch(url);
66
+ const svg = await response.text();
67
+ if (isMounted) {
68
+ onLoadEnd();
69
+ setData(svg);
70
+ }
71
+ } catch {
72
+ setIsError(true);
73
+ }
74
+ }
75
+ fetchSvg();
76
+ return () => {
77
+ isMounted = false;
78
+ };
79
+ }, [
80
+ onLoadStart,
81
+ onLoadEnd,
82
+ url
83
+ ]);
84
+ if (data == null) return /* @__PURE__ */ jsx(Fallback, {});
85
+ if (isError) return /* @__PURE__ */ jsx(SvgUri, {
86
+ testID,
87
+ uri: url,
88
+ style,
89
+ ...svgStyle,
90
+ onError,
91
+ onLoad: onLoadEnd,
92
+ fallback: /* @__PURE__ */ jsx(Fallback, {})
93
+ });
94
+ return /* @__PURE__ */ jsx(SvgXml, {
95
+ testID,
96
+ xml: data,
97
+ style,
98
+ ...svgStyle,
99
+ fallback: /* @__PURE__ */ jsx(Fallback, {})
100
+ });
101
+ }
102
+
103
+ //#endregion
104
+ //#region src/Image.tsx
105
+ /**
106
+ * @public
107
+ * @category UI
108
+ * @name Image
109
+ * @description You can use the `Image` component to load and render bitmap images (such as PNG, JPG) or vector images (SVG). It automatically renders with the appropriate method depending on the image format.
110
+ * @link https://github.com/DylanVann/react-native-fast-image/tree/v8.6.3/README.md
111
+ *
112
+ * @param {object} [props] - The `props` object passed to the component.
113
+ * @param {object} [props.style] - An object that defines the style for the image component. It can include layout-related properties like `width` and `height`.
114
+ * @param {object} [props.source] - An object containing information about the image resource to load.
115
+ * @param {string} [props.source.uri] - The URI address representing the image resource to load.
116
+ * @param {'immutable' | 'web' | 'cacheOnly'} [props.source.cache = 'immutable'] - An option to set the image caching strategy. This applies only to bitmap images. The default value is `immutable`.
117
+ * @param {() => void} [props.onLoadStart] - A callback function that is called when image loading starts.
118
+ * @param {() => void} [props.onLoadEnd] - A callback function that is called when image loading finishes.
119
+ * @param {() => void} [props.onError] - A callback function that is called when an error occurs during image loading.
120
+ *
121
+ * @example
122
+ * ### Example: Loading and rendering an image
123
+ *
124
+ * The following example shows how to load bitmap and vector image resources, and how to print an error message to `console.log` if an error occurs.
125
+ *
126
+ * ```tsx
127
+ * import { Image } from '@granite-js/react-native';
128
+ * import { View } from 'react-native';
129
+ *
130
+ * export function ImageExample() {
131
+ * return (
132
+ * <View>
133
+ * <Image
134
+ * source={{ uri: 'my-image-link' }}
135
+ * style={{
136
+ * width: 300,
137
+ * height: 300,
138
+ * borderWidth: 1,
139
+ * }}
140
+ * onError={() => {
141
+ * console.log('Failed to load image');
142
+ * }}
143
+ * />
144
+ *
145
+ * <Image
146
+ * source={{ uri: 'my-svg-link' }}
147
+ * style={{
148
+ * width: 300,
149
+ * height: 300,
150
+ * borderWidth: 1,
151
+ * }}
152
+ * onError={() => {
153
+ * console.log('Failed to load image');
154
+ * }}
155
+ * />
156
+ * </View>
157
+ * );
158
+ * }
159
+ * ```
160
+ */
161
+ function Image(props) {
162
+ if (typeof props.source === "object" && props.source.uri?.endsWith(".svg")) {
163
+ const style = StyleSheet.flatten(props.style);
164
+ const width = style?.width;
165
+ const height = style?.height;
166
+ return /* @__PURE__ */ jsx(SvgImage, {
167
+ testID: props.testID,
168
+ url: props.source.uri,
169
+ width,
170
+ height,
171
+ style: props.style,
172
+ onLoadStart: props.onLoadStart,
173
+ onLoadEnd: props.onLoadEnd,
174
+ onError: props.onError
175
+ });
176
+ }
177
+ return /* @__PURE__ */ jsx(FastImage, { ...props });
178
+ }
179
+
180
+ //#endregion
181
+ export { Image };
package/package.json CHANGED
@@ -1,27 +1,38 @@
1
1
  {
2
2
  "name": "@granite-js/image",
3
- "version": "0.1.19",
3
+ "version": "0.1.21",
4
4
  "scripts": {
5
5
  "prepack": "yarn build",
6
6
  "typecheck": "tsc --noEmit",
7
7
  "lint": "eslint .",
8
- "build": "rm -rf dist && tsc -p tsconfig.build.json"
8
+ "build": "tsdown"
9
9
  },
10
- "main": "./src/index.ts",
10
+ "main": "./dist/index.js",
11
+ "module": "./dist/index.mjs",
11
12
  "types": "./dist/index.d.ts",
12
13
  "exports": {
13
14
  ".": {
14
- "types": "./dist/index.d.ts",
15
- "default": "./src/index.ts"
15
+ "import": {
16
+ "types": "./dist/index.d.mts",
17
+ "default": "./dist/index.mjs"
18
+ },
19
+ "require": {
20
+ "types": "./dist/index.d.ts",
21
+ "default": "./dist/index.js"
22
+ }
16
23
  },
17
24
  "./package.json": "./package.json"
18
25
  },
26
+ "files": [
27
+ "dist"
28
+ ],
19
29
  "devDependencies": {
20
- "@granite-js/native": "0.1.19",
30
+ "@granite-js/native": "0.1.21",
21
31
  "@types/react": "18.3.3",
22
32
  "eslint": "^9.7.0",
23
33
  "react": "18.2.0",
24
34
  "react-native": "0.72.6",
35
+ "tsdown": "^0.14.1",
25
36
  "typescript": "5.8.3"
26
37
  },
27
38
  "peerDependencies": {
package/NOTICE DELETED
@@ -1,63 +0,0 @@
1
- NOTICE
2
-
3
- This project makes use of third-party libraries that are licensed under their respective open-source licenses. Below is a list of these libraries, their licenses, and their links for further reference.
4
-
5
- ================================================================================
6
- Project Name: @granite-js/image
7
- Copyright 2025 Viva Republica, Inc
8
-
9
- Licensed under the Apache License, Version 2.0 (the "License");
10
- you may not use this file except in compliance with the License.
11
- You may obtain a copy of the License at:
12
-
13
- http://www.apache.org/licenses/LICENSE-2.0
14
-
15
- Unless required by applicable law or agreed to in writing, software
16
- distributed under the License is distributed on an "AS IS" BASIS,
17
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
- See the License for the specific language governing permissions and
19
- limitations under the License.
20
-
21
- ================================================================================
22
- Third-Party Libraries:
23
-
24
- 1. **@types/react**
25
-
26
- - License: MIT
27
- - License Text: https://opensource.org/licenses/MIT
28
- - Repository: https://github.com/DefinitelyTyped/DefinitelyTyped.git
29
-
30
- 2. **eslint**
31
-
32
- - License: MIT
33
- - License Text: https://opensource.org/licenses/MIT
34
- - Repository: git+https://github.com/eslint/eslint.git
35
-
36
- 3. **react**
37
-
38
- - License: MIT
39
- - License Text: https://opensource.org/licenses/MIT
40
- - Repository: https://github.com/facebook/react.git
41
-
42
- 4. **react-native**
43
-
44
- - License: MIT
45
- - License Text: https://opensource.org/licenses/MIT
46
- - Repository: git+https://github.com/facebook/react-native.git
47
-
48
- 5. **react-simplikit**
49
-
50
- - License: MIT
51
- - License Text: https://opensource.org/licenses/MIT
52
- - Repository: git+https://github.com/toss/react-simplikit.git
53
-
54
- 6. **typescript**
55
-
56
- - License: Apache-2.0
57
- - License Text: https://www.apache.org/licenses/LICENSE-2.0
58
- - Repository: https://github.com/microsoft/TypeScript.git
59
-
60
-
61
- ================================================================================
62
-
63
- For further details about each license, please refer to the provided links. If there are updates to these dependencies, this file should also be updated.
@@ -1,47 +0,0 @@
1
- import { type StyleProp } from 'react-native';
2
- import type { DimensionValue } from './types';
3
- export interface SvgImageProps {
4
- url: string;
5
- width?: DimensionValue;
6
- height?: DimensionValue;
7
- style?: StyleProp<any>;
8
- testID?: string;
9
- onLoadStart?: () => void;
10
- onLoadEnd?: () => void;
11
- onError?: () => void;
12
- }
13
- /**
14
- * @name SvgImage
15
- * @category Components
16
- * @description The `SvgImage` component loads and renders SVG images from a given external URL.
17
- * @link https://github.com/software-mansion/react-native-svg/tree/v13.14.0/README.md
18
- *
19
- * @param {object} props - The `props` object passed to the component.
20
- * @param {string} props.url - The URI address of the SVG image to load.
21
- * @param {number | string} [props.width = '100%'] - Sets the horizontal size of the SVG image. Default value is '`100%`'.
22
- * @param {number | string} [props.height = '100%'] - Sets the vertical size of the SVG image. Default value is '`100%`'.
23
- * @param {object} props.style - Sets the style of the image component.
24
- * @param {() => void} props.onLoadStart - A callback function called when the SVG image resource starts loading.
25
- * @param {() => void} props.onLoadEnd - A callback function called after the SVG image resource is loaded.
26
- * @param {() => void} props.onError - A callback function called when an error occurs during SVG image loading.
27
- *
28
- * @example
29
- * ```tsx
30
- * import { SvgImage } from './SvgImage';
31
- * import { View } from 'react-native';
32
- *
33
- * function MyComponent() {
34
- * return (
35
- * <View>
36
- * <SvgImage
37
- * url="https://example.com/icon.svg"
38
- * width={100}
39
- * height={100}
40
- * onError={() => console.log('An error occurred while loading the SVG')}
41
- * />
42
- * </View>
43
- * );
44
- * }
45
- * ```
46
- */
47
- export declare function SvgImage({ url, width, height, style, testID, onLoadStart: _onLoadStart, onLoadEnd: _onLoadEnd, onError: _onError, }: SvgImageProps): import("react/jsx-runtime").JSX.Element;
package/dist/types.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import type { Animated } from 'react-native';
2
- export type DimensionValue = string | number | 'auto' | `${number}%` | Animated.AnimatedNode | null;
3
- export type NumberValue = number | string;
@@ -1,18 +0,0 @@
1
- {
2
- "folders": [
3
- {
4
- "path": ".",
5
- },
6
- ],
7
- "settings": {
8
- "eslint.useFlatConfig": true,
9
- "eslint.nodePath": "../../.yarn/sdks",
10
- "typescript.enablePromptUseWorkspaceTsdk": true,
11
- "typescript.tsdk": "../../.yarn/sdks/typescript/lib",
12
- "prettier.prettierPath": "../../.yarn/sdks/prettier/index.cjs",
13
- "prettier.configPath": "../../.prettierrc",
14
- "jest.rootPath": ".",
15
- "jest.jestCommandLine": "yarn jest",
16
- "jest.enable": false,
17
- },
18
- }
package/src/Image.tsx DELETED
@@ -1,93 +0,0 @@
1
- import FastImage, { FastImageProps, Source as FastImageSource } from '@granite-js/native/react-native-fast-image';
2
- import { StyleSheet } from 'react-native';
3
- import { SvgImage } from './SvgImage';
4
-
5
- type Source = {
6
- uri?: string;
7
- cache?: FastImageSource['cache'];
8
- };
9
-
10
- export interface ImageProps extends Omit<FastImageProps, 'source'> {
11
- source?: Source;
12
- }
13
-
14
- /**
15
- * @public
16
- * @category UI
17
- * @name Image
18
- * @description You can use the `Image` component to load and render bitmap images (such as PNG, JPG) or vector images (SVG). It automatically renders with the appropriate method depending on the image format.
19
- * @link https://github.com/DylanVann/react-native-fast-image/tree/v8.6.3/README.md
20
- *
21
- * @param {object} [props] - The `props` object passed to the component.
22
- * @param {object} [props.style] - An object that defines the style for the image component. It can include layout-related properties like `width` and `height`.
23
- * @param {object} [props.source] - An object containing information about the image resource to load.
24
- * @param {string} [props.source.uri] - The URI address representing the image resource to load.
25
- * @param {'immutable' | 'web' | 'cacheOnly'} [props.source.cache = 'immutable'] - An option to set the image caching strategy. This applies only to bitmap images. The default value is `immutable`.
26
- * @param {() => void} [props.onLoadStart] - A callback function that is called when image loading starts.
27
- * @param {() => void} [props.onLoadEnd] - A callback function that is called when image loading finishes.
28
- * @param {() => void} [props.onError] - A callback function that is called when an error occurs during image loading.
29
- *
30
- * @example
31
- * ### Example: Loading and rendering an image
32
- *
33
- * The following example shows how to load bitmap and vector image resources, and how to print an error message to `console.log` if an error occurs.
34
- *
35
- * ```tsx
36
- * import { Image } from '@granite-js/react-native';
37
- * import { View } from 'react-native';
38
- *
39
- * export function ImageExample() {
40
- * return (
41
- * <View>
42
- * <Image
43
- * source={{ uri: 'my-image-link' }}
44
- * style={{
45
- * width: 300,
46
- * height: 300,
47
- * borderWidth: 1,
48
- * }}
49
- * onError={() => {
50
- * console.log('Failed to load image');
51
- * }}
52
- * />
53
- *
54
- * <Image
55
- * source={{ uri: 'my-svg-link' }}
56
- * style={{
57
- * width: 300,
58
- * height: 300,
59
- * borderWidth: 1,
60
- * }}
61
- * onError={() => {
62
- * console.log('Failed to load image');
63
- * }}
64
- * />
65
- * </View>
66
- * );
67
- * }
68
- * ```
69
- */
70
- function Image(props: ImageProps) {
71
- if (typeof props.source === 'object' && props.source.uri?.endsWith('.svg')) {
72
- const style = StyleSheet.flatten(props.style);
73
- const width = style?.width;
74
- const height = style?.height;
75
-
76
- return (
77
- <SvgImage
78
- testID={props.testID}
79
- url={props.source.uri!}
80
- width={width}
81
- height={height}
82
- style={props.style}
83
- onLoadStart={props.onLoadStart}
84
- onLoadEnd={props.onLoadEnd}
85
- onError={props.onError}
86
- />
87
- );
88
- }
89
-
90
- return <FastImage {...props} />;
91
- }
92
-
93
- export { Image };
package/src/SvgImage.tsx DELETED
@@ -1,124 +0,0 @@
1
- import { SvgUri, SvgXml } from '@granite-js/native/react-native-svg';
2
- import { createElement, useEffect, useCallback, useState } from 'react';
3
- import { View, type ViewStyle, type StyleProp } from 'react-native';
4
- import { usePreservedCallback } from 'react-simplikit';
5
- import type { DimensionValue, NumberValue } from './types';
6
-
7
- export interface SvgImageProps {
8
- url: string;
9
- width?: DimensionValue;
10
- height?: DimensionValue;
11
- style?: StyleProp<any>;
12
- testID?: string;
13
- onLoadStart?: () => void;
14
- onLoadEnd?: () => void;
15
- onError?: () => void;
16
- }
17
-
18
- /**
19
- * @name SvgImage
20
- * @category Components
21
- * @description The `SvgImage` component loads and renders SVG images from a given external URL.
22
- * @link https://github.com/software-mansion/react-native-svg/tree/v13.14.0/README.md
23
- *
24
- * @param {object} props - The `props` object passed to the component.
25
- * @param {string} props.url - The URI address of the SVG image to load.
26
- * @param {number | string} [props.width = '100%'] - Sets the horizontal size of the SVG image. Default value is '`100%`'.
27
- * @param {number | string} [props.height = '100%'] - Sets the vertical size of the SVG image. Default value is '`100%`'.
28
- * @param {object} props.style - Sets the style of the image component.
29
- * @param {() => void} props.onLoadStart - A callback function called when the SVG image resource starts loading.
30
- * @param {() => void} props.onLoadEnd - A callback function called after the SVG image resource is loaded.
31
- * @param {() => void} props.onError - A callback function called when an error occurs during SVG image loading.
32
- *
33
- * @example
34
- * ```tsx
35
- * import { SvgImage } from './SvgImage';
36
- * import { View } from 'react-native';
37
- *
38
- * function MyComponent() {
39
- * return (
40
- * <View>
41
- * <SvgImage
42
- * url="https://example.com/icon.svg"
43
- * width={100}
44
- * height={100}
45
- * onError={() => console.log('An error occurred while loading the SVG')}
46
- * />
47
- * </View>
48
- * );
49
- * }
50
- * ```
51
- */
52
- export function SvgImage({
53
- url,
54
- width = '100%',
55
- height = '100%',
56
- style,
57
- testID,
58
- onLoadStart: _onLoadStart,
59
- onLoadEnd: _onLoadEnd,
60
- onError: _onError,
61
- }: SvgImageProps) {
62
- const svgStyle = { width, height } as { width: NumberValue; height: NumberValue };
63
- const [data, setData] = useState<string | undefined>(undefined);
64
- const [isError, setIsError] = useState(false);
65
-
66
- const onLoadStart = usePreservedCallback(() => _onLoadStart?.());
67
- const onLoadEnd = usePreservedCallback(() => _onLoadEnd?.());
68
- const onError = usePreservedCallback(() => _onError?.());
69
-
70
- // Component to occupy layout space when the image is not yet rendered
71
- const Fallback = useCallback(
72
- () => createElement(View, { style: { width, height } as ViewStyle }, null),
73
- [width, height]
74
- );
75
-
76
- useEffect(() => {
77
- let isMounted = true;
78
-
79
- /**
80
- * First attempts to fetch the XML resource, and if that fails, tries to load directly by passing the URI to the Svg component
81
- */
82
- async function fetchSvg() {
83
- onLoadStart();
84
-
85
- try {
86
- const response = await fetch(url);
87
- const svg = await response.text();
88
-
89
- if (isMounted) {
90
- onLoadEnd();
91
- setData(svg);
92
- }
93
- } catch {
94
- setIsError(true);
95
- }
96
- }
97
-
98
- fetchSvg();
99
-
100
- return () => {
101
- isMounted = false;
102
- };
103
- }, [onLoadStart, onLoadEnd, url]);
104
-
105
- if (data == null) {
106
- return <Fallback />;
107
- }
108
-
109
- if (isError) {
110
- return (
111
- <SvgUri
112
- testID={testID}
113
- uri={url}
114
- style={style}
115
- {...svgStyle}
116
- onError={onError}
117
- onLoad={onLoadEnd}
118
- fallback={<Fallback />}
119
- />
120
- );
121
- }
122
-
123
- return <SvgXml testID={testID} xml={data} style={style} {...svgStyle} fallback={<Fallback />} />;
124
- }
package/src/index.ts DELETED
@@ -1 +0,0 @@
1
- export { Image, type ImageProps } from './Image';
package/src/types.ts DELETED
@@ -1,6 +0,0 @@
1
- import type { Animated } from 'react-native';
2
-
3
- // FIXME: DimensionValue type is not available in React Native 0.68, so it's defined separately
4
- export type DimensionValue = string | number | 'auto' | `${number}%` | Animated.AnimatedNode | null;
5
-
6
- export type NumberValue = number | string;
@@ -1,11 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "declaration": true,
5
- "emitDeclarationOnly": true,
6
- "rootDir": "./src",
7
- "outDir": "./dist"
8
- },
9
- "exclude": ["**/dist/*", "**/esm/*", "**/*.test.*", "**/*.spec.*", "**/*.e2e.*", "**/__fixtures__/*"],
10
- "include": ["src"]
11
- }
package/tsconfig.json DELETED
@@ -1,4 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.json",
3
- "include": ["src"]
4
- }