@tamagui/image 2.0.0-rc.4 → 2.0.0-rc.40

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 (87) hide show
  1. package/dist/cjs/Image.cjs +42 -40
  2. package/dist/cjs/Image.native.js +17 -15
  3. package/dist/cjs/Image.native.js.map +1 -1
  4. package/dist/cjs/createImage.cjs +123 -88
  5. package/dist/cjs/createImage.native.js +128 -95
  6. package/dist/cjs/createImage.native.js.map +1 -1
  7. package/dist/cjs/index.cjs +7 -5
  8. package/dist/cjs/index.native.js +7 -5
  9. package/dist/cjs/index.native.js.map +1 -1
  10. package/dist/cjs/types.cjs +7 -5
  11. package/dist/cjs/types.native.js +7 -5
  12. package/dist/cjs/types.native.js.map +1 -1
  13. package/dist/cjs/v1/Image.cjs +63 -48
  14. package/dist/cjs/v1/Image.native.js +91 -73
  15. package/dist/cjs/v1/Image.native.js.map +1 -1
  16. package/dist/cjs/v1/index.cjs +7 -5
  17. package/dist/cjs/v1/index.native.js +7 -5
  18. package/dist/cjs/v1/index.native.js.map +1 -1
  19. package/dist/esm/Image.mjs +28 -28
  20. package/dist/esm/Image.mjs.map +1 -1
  21. package/dist/esm/createImage.mjs +109 -76
  22. package/dist/esm/createImage.mjs.map +1 -1
  23. package/dist/esm/createImage.native.js +113 -82
  24. package/dist/esm/createImage.native.js.map +1 -1
  25. package/dist/esm/index.js +2 -2
  26. package/dist/esm/index.js.map +1 -6
  27. package/dist/esm/v1/Image.mjs +34 -21
  28. package/dist/esm/v1/Image.mjs.map +1 -1
  29. package/dist/esm/v1/Image.native.js +62 -46
  30. package/dist/esm/v1/Image.native.js.map +1 -1
  31. package/dist/jsx/Image.mjs +28 -28
  32. package/dist/jsx/Image.mjs.map +1 -1
  33. package/dist/jsx/Image.native.js +17 -15
  34. package/dist/jsx/Image.native.js.map +1 -1
  35. package/dist/jsx/createImage.mjs +109 -76
  36. package/dist/jsx/createImage.mjs.map +1 -1
  37. package/dist/jsx/createImage.native.js +128 -95
  38. package/dist/jsx/createImage.native.js.map +1 -1
  39. package/dist/jsx/index.js +2 -2
  40. package/dist/jsx/index.js.map +1 -6
  41. package/dist/jsx/index.native.js +7 -5
  42. package/dist/jsx/types.native.js +7 -5
  43. package/dist/jsx/v1/Image.mjs +34 -21
  44. package/dist/jsx/v1/Image.mjs.map +1 -1
  45. package/dist/jsx/v1/Image.native.js +91 -73
  46. package/dist/jsx/v1/Image.native.js.map +1 -1
  47. package/dist/jsx/v1/index.native.js +7 -5
  48. package/package.json +9 -12
  49. package/src/createImage.tsx +20 -6
  50. package/src/types.ts +1 -1
  51. package/types/Image.native.d.ts +1 -1
  52. package/types/createImage.d.ts +2 -2
  53. package/types/createImage.d.ts.map +1 -1
  54. package/types/types.d.ts +1 -1
  55. package/types/types.d.ts.map +1 -1
  56. package/dist/cjs/Image.js +0 -55
  57. package/dist/cjs/Image.js.map +0 -6
  58. package/dist/cjs/createImage.js +0 -127
  59. package/dist/cjs/createImage.js.map +0 -6
  60. package/dist/cjs/index.js +0 -16
  61. package/dist/cjs/index.js.map +0 -6
  62. package/dist/cjs/types.js +0 -14
  63. package/dist/cjs/types.js.map +0 -6
  64. package/dist/cjs/v1/Image.js +0 -72
  65. package/dist/cjs/v1/Image.js.map +0 -6
  66. package/dist/cjs/v1/index.js +0 -15
  67. package/dist/cjs/v1/index.js.map +0 -6
  68. package/dist/esm/Image.js +0 -40
  69. package/dist/esm/Image.js.map +0 -6
  70. package/dist/esm/createImage.js +0 -112
  71. package/dist/esm/createImage.js.map +0 -6
  72. package/dist/esm/types.js +0 -1
  73. package/dist/esm/types.js.map +0 -6
  74. package/dist/esm/v1/Image.js +0 -52
  75. package/dist/esm/v1/Image.js.map +0 -6
  76. package/dist/esm/v1/index.js +0 -2
  77. package/dist/esm/v1/index.js.map +0 -6
  78. package/dist/jsx/Image.js +0 -40
  79. package/dist/jsx/Image.js.map +0 -6
  80. package/dist/jsx/createImage.js +0 -112
  81. package/dist/jsx/createImage.js.map +0 -6
  82. package/dist/jsx/types.js +0 -1
  83. package/dist/jsx/types.js.map +0 -6
  84. package/dist/jsx/v1/Image.js +0 -52
  85. package/dist/jsx/v1/Image.js.map +0 -6
  86. package/dist/jsx/v1/index.js +0 -2
  87. package/dist/jsx/v1/index.js.map +0 -6
@@ -3,57 +3,59 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
5
  var __export = (target, all) => {
6
- for (var name in all) __defProp(target, name, {
7
- get: all[name],
8
- enumerable: !0
9
- });
10
- },
11
- __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
6
+ for (var name in all) __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: true
9
+ });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
14
  get: () => from[key],
14
15
  enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
16
  });
16
- return to;
17
- };
17
+ }
18
+ return to;
19
+ };
18
20
  var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
19
- value: !0
21
+ value: true
20
22
  }), mod);
21
23
  var Image_exports = {};
22
24
  __export(Image_exports, {
23
25
  Image: () => Image
24
26
  });
25
27
  module.exports = __toCommonJS(Image_exports);
26
- var import_web = require("@tamagui/web"),
27
- import_jsx_runtime = require("react/jsx-runtime");
28
+ var import_web = require("@tamagui/web");
29
+ var import_jsx_runtime = require("react/jsx-runtime");
28
30
  const StyledImage = (0, import_web.styled)(import_web.View, {
29
- name: "Image",
30
- render: "img"
31
- }),
32
- Image = StyledImage.styleable((inProps, ref) => {
33
- const {
34
- // exclude native only props
35
- blurRadius,
36
- capInsets,
37
- defaultSource,
38
- fadeDuration,
39
- loadingIndicatorSource,
40
- onLoadEnd,
41
- onPartialLoad,
42
- progressiveRenderingEnabled,
43
- resizeMethod,
44
- tintColor,
45
- ...rest
46
- } = inProps;
47
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(StyledImage, {
48
- ref,
49
- ...rest
50
- });
51
- }, {
52
- staticConfig: {
53
- memo: !0
54
- }
55
- }),
56
- func = () => {};
31
+ name: "Image",
32
+ render: "img"
33
+ });
34
+ const Image = StyledImage.styleable((inProps, ref) => {
35
+ const {
36
+ // exclude native only props
37
+ blurRadius,
38
+ capInsets,
39
+ defaultSource,
40
+ fadeDuration,
41
+ loadingIndicatorSource,
42
+ onLoadEnd,
43
+ onPartialLoad,
44
+ progressiveRenderingEnabled,
45
+ resizeMethod,
46
+ tintColor,
47
+ ...rest
48
+ } = inProps;
49
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(StyledImage, {
50
+ ref,
51
+ ...rest
52
+ });
53
+ }, {
54
+ staticConfig: {
55
+ memo: true
56
+ }
57
+ });
58
+ const func = () => {};
57
59
  Image.getSize = func;
58
60
  Image.getSizeWithHeaders = func;
59
61
  Image.prefetch = func;
@@ -5,29 +5,31 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
7
  var __export = (target, all) => {
8
- for (var name in all) __defProp(target, name, {
9
- get: all[name],
10
- enumerable: !0
11
- });
12
- },
13
- __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
15
16
  get: () => from[key],
16
17
  enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
18
  });
18
- return to;
19
- };
19
+ }
20
+ return to;
21
+ };
20
22
  var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
21
- value: !0
23
+ value: true
22
24
  }), mod);
23
25
  var Image_native_exports = {};
24
26
  __export(Image_native_exports, {
25
27
  Image: () => Image
26
28
  });
27
29
  module.exports = __toCommonJS(Image_native_exports);
28
- var import_react_native = require("react-native"),
29
- import_createImage = require("./createImage.native.js"),
30
- Image = (0, import_createImage.createImage)({
31
- Component: import_react_native.Image
32
- });
30
+ var import_react_native = require("react-native");
31
+ var import_createImage = require("./createImage.native.js");
32
+ var Image = (0, import_createImage.createImage)({
33
+ Component: import_react_native.Image
34
+ });
33
35
  //# sourceMappingURL=Image.native.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["Image_native_exports","__export","Image","module","exports","__toCommonJS","import_react_native","require","import_createImage","createImage","Component"],"sources":["../../src/Image.native.tsx"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,oBAAA;AAAAC,QAAA,CAAAD,oBAAA;EAAAE,KAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAC,YAAA,CAAAL,oBAAA;AAAA,IAAAM,mBAAA,GAAiCC,OAAA;EACjCC,kBAAA,GAA4BD,OAAA;EACjBL,KAAA,OAAQM,kBAAA,CAAAC,WAAA,EAAY;IAC3BC,SAAA,EAAWJ,mBAAA,CAAAJ;EACf,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["Image_native_exports","__export","Image","module","exports","__toCommonJS","import_react_native","require","import_createImage","createImage","Component"],"sources":["../../src/Image.native.tsx"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,oBAAA;AAAAC,QAAA,CAAAD,oBAAA;EAAAE,KAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAC,YAAA,CAAAL,oBAAA;AAAA,IAAAM,mBAAA,GAAiCC,OAAA;AACjC,IAAAC,kBAAA,GAA4BD,OAAA;AACrB,IAAIL,KAAA,OAAQM,kBAAA,CAAAC,WAAA,EAAY;EAC3BC,SAAA,EAAWJ,mBAAA,CAAAJ;AACf,CAAC","ignoreList":[]}
@@ -3,103 +3,127 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
5
  var __export = (target, all) => {
6
- for (var name in all) __defProp(target, name, {
7
- get: all[name],
8
- enumerable: !0
9
- });
10
- },
11
- __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
6
+ for (var name in all) __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: true
9
+ });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
14
  get: () => from[key],
14
15
  enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
16
  });
16
- return to;
17
- };
17
+ }
18
+ return to;
19
+ };
18
20
  var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
19
- value: !0
21
+ value: true
20
22
  }), mod);
21
23
  var createImage_exports = {};
22
24
  __export(createImage_exports, {
23
25
  createImage: () => createImage
24
26
  });
25
27
  module.exports = __toCommonJS(createImage_exports);
26
- var import_web = require("@tamagui/web"),
27
- import_jsx_runtime = require("react/jsx-runtime");
28
+ var import_web = require("@tamagui/web");
29
+ var import_jsx_runtime = require("react/jsx-runtime");
28
30
  const defaultObjectFitMap = objectFit => {
29
- switch (objectFit) {
30
- case "fill":
31
- return "stretch";
32
- case "none":
33
- return "center";
34
- case "scale-down":
35
- return "contain";
36
- case "contain":
37
- return "contain";
38
- default:
39
- return "cover";
40
- }
41
- },
42
- defaultTransformSource = props => {
31
+ switch (objectFit) {
32
+ case "fill":
33
+ return "stretch";
34
+ case "none":
35
+ return "center";
36
+ case "scale-down":
37
+ return "contain";
38
+ case "contain":
39
+ return "contain";
40
+ default:
41
+ return "cover";
42
+ }
43
+ };
44
+ const defaultTransformSource = props => {
45
+ const {
46
+ src,
47
+ source,
48
+ width,
49
+ height
50
+ } = props;
51
+ if (source) return source;
52
+ if (src && typeof src !== "string") return src;
53
+ return {
54
+ uri: src,
55
+ width,
56
+ height
57
+ };
58
+ };
59
+ function createImage(options) {
60
+ const {
61
+ Component,
62
+ mapObjectFitToResizeMode = defaultObjectFitMap,
63
+ resizeModePropName = "resizeMode",
64
+ objectPositionPropName,
65
+ transformSource = defaultTransformSource
66
+ } = options;
67
+ const inlinePropsSet = /* @__PURE__ */new Set(["source", "placeholder", "transition", "contentFit", "contentPosition", "cachePolicy", "recyclingKey", "allowDownscaling", "autoplay", "blurRadius", "priority", "placeholderContentFit", "responsivePolicy", "onLoadStart", "onProgress", "onLoadEnd"]);
68
+ const StyledImage = (0, import_web.styled)(Component, {
69
+ name: "Image"
70
+ }, {
71
+ inlineProps: inlinePropsSet
72
+ });
73
+ const ImageComponent = StyledImage.styleable((incomingProps, ref) => {
74
+ const props = incomingProps;
43
75
  const {
44
76
  src,
45
- source,
46
77
  width,
47
- height
78
+ height,
79
+ borderRadius,
80
+ objectFit,
81
+ objectPosition,
82
+ // web only props - filter out on native
83
+ decoding,
84
+ elementTiming,
85
+ fetchpriority,
86
+ isMap,
87
+ loading,
88
+ sizes,
89
+ useMap,
90
+ onLoad,
91
+ onError,
92
+ ...rest
48
93
  } = props;
49
- return source || (src && typeof src != "string" ? src : {
50
- uri: src,
51
- width,
52
- height
94
+ const resolvedWidth = typeof width === "string" && width[0] === "$" ? (0, import_web.getTokenValue)(width, "size") : width;
95
+ const resolvedHeight = typeof height === "string" && height[0] === "$" ? (0, import_web.getTokenValue)(height, "size") : height;
96
+ const finalSource = transformSource({
97
+ src,
98
+ width: resolvedWidth,
99
+ height: resolvedHeight
53
100
  });
54
- };
55
- function createImage(options) {
56
- const {
57
- Component,
58
- mapObjectFitToResizeMode = defaultObjectFitMap,
59
- resizeModePropName = "resizeMode",
60
- objectPositionPropName,
61
- transformSource = defaultTransformSource
62
- } = options,
63
- ImageComponent = (0, import_web.styled)(Component, {
64
- name: "Image"
65
- }, {
66
- inlineProps: /* @__PURE__ */new Set(["source", "placeholder", "transition", "contentFit", "contentPosition", "cachePolicy", "recyclingKey", "allowDownscaling", "autoplay", "blurRadius", "priority", "placeholderContentFit", "responsivePolicy", "onLoadStart", "onProgress", "onLoadEnd"])
67
- }).styleable((incomingProps, ref) => {
68
- const props = incomingProps,
69
- {
70
- src,
71
- width,
72
- height,
73
- objectFit,
74
- objectPosition,
75
- // web only props - filter out on native
76
- decoding,
77
- elementTiming,
78
- fetchpriority,
79
- isMap,
80
- loading,
81
- sizes,
82
- useMap,
83
- onLoad,
84
- onError,
85
- ...rest
86
- } = props,
87
- resolvedWidth = typeof width == "string" && width[0] === "$" ? (0, import_web.getTokenValue)(width) : width,
88
- resolvedHeight = typeof height == "string" && height[0] === "$" ? (0, import_web.getTokenValue)(height) : height,
89
- finalSource = transformSource({
90
- src,
91
- width: resolvedWidth,
92
- height: resolvedHeight
101
+ const incomingStyle = Array.isArray(rest.style) ? Object.assign({}, ...rest.style.flat()) : rest.style;
102
+ const resolvedBorderRadius = typeof borderRadius === "string" && borderRadius[0] === "$" ? (0, import_web.getTokenValue)(borderRadius, "radius") : borderRadius;
103
+ const finalProps = {
104
+ ...rest,
105
+ source: finalSource,
106
+ style: {
107
+ ...incomingStyle,
108
+ ...(resolvedBorderRadius !== void 0 && {
109
+ borderRadius: resolvedBorderRadius
93
110
  }),
94
- finalProps = {
95
- ...rest,
96
- source: finalSource,
97
- style: {
98
- width: resolvedWidth,
99
- height: resolvedHeight
100
- }
101
- };
102
- return objectFit && (finalProps[resizeModePropName] = mapObjectFitToResizeMode(objectFit)), objectPositionPropName && objectPosition && (finalProps[objectPositionPropName] = objectPosition), onLoad && (finalProps.onLoad = e => {
111
+ ...(resolvedWidth !== void 0 && {
112
+ width: resolvedWidth
113
+ }),
114
+ ...(resolvedHeight !== void 0 && {
115
+ height: resolvedHeight
116
+ })
117
+ }
118
+ };
119
+ if (objectFit) {
120
+ finalProps[resizeModePropName] = mapObjectFitToResizeMode(objectFit);
121
+ }
122
+ if (objectPositionPropName && objectPosition) {
123
+ finalProps[objectPositionPropName] = objectPosition;
124
+ }
125
+ if (onLoad) {
126
+ finalProps.onLoad = e => {
103
127
  const source = e?.nativeEvent?.source || e?.source || {};
104
128
  onLoad({
105
129
  target: {
@@ -108,15 +132,26 @@ function createImage(options) {
108
132
  },
109
133
  type: "load"
110
134
  });
111
- }), onError && (finalProps.onError = () => {
135
+ };
136
+ }
137
+ if (onError) {
138
+ finalProps.onError = () => {
112
139
  onError({
113
140
  type: "error"
114
141
  });
115
- }), /* @__PURE__ */(0, import_jsx_runtime.jsx)(Component, {
116
- ref,
117
- ...finalProps
118
- });
119
- }),
120
- comp = Component;
121
- return ImageComponent.getSize = comp.getSize || (() => {}), ImageComponent.getSizeWithHeaders = comp.getSizeWithHeaders || (() => {}), ImageComponent.prefetch = comp.prefetch || (() => {}), ImageComponent.prefetchWithMetadata = comp.prefetchWithMetadata || (() => {}), ImageComponent.abortPrefetch = comp.abortPrefetch || (() => {}), ImageComponent.queryCache = comp.queryCache || (() => {}), ImageComponent;
142
+ };
143
+ }
144
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(Component, {
145
+ ref,
146
+ ...finalProps
147
+ });
148
+ });
149
+ const comp = Component;
150
+ ImageComponent.getSize = comp.getSize || (() => {});
151
+ ImageComponent.getSizeWithHeaders = comp.getSizeWithHeaders || (() => {});
152
+ ImageComponent.prefetch = comp.prefetch || (() => {});
153
+ ImageComponent.prefetchWithMetadata = comp.prefetchWithMetadata || (() => {});
154
+ ImageComponent.abortPrefetch = comp.abortPrefetch || (() => {});
155
+ ImageComponent.queryCache = comp.queryCache || (() => {});
156
+ return ImageComponent;
122
157
  }
@@ -5,124 +5,157 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
7
  var __export = (target, all) => {
8
- for (var name in all) __defProp(target, name, {
9
- get: all[name],
10
- enumerable: !0
11
- });
12
- },
13
- __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
15
16
  get: () => from[key],
16
17
  enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
18
  });
18
- return to;
19
- };
19
+ }
20
+ return to;
21
+ };
20
22
  var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
21
- value: !0
23
+ value: true
22
24
  }), mod);
23
25
  var createImage_exports = {};
24
26
  __export(createImage_exports, {
25
27
  createImage: () => createImage
26
28
  });
27
29
  module.exports = __toCommonJS(createImage_exports);
28
- var import_jsx_runtime = require("react/jsx-runtime"),
29
- import_web = require("@tamagui/web"),
30
- defaultObjectFitMap = function (objectFit) {
31
- switch (objectFit) {
32
- case "fill":
33
- return "stretch";
34
- case "none":
35
- return "center";
36
- case "scale-down":
37
- return "contain";
38
- case "contain":
39
- return "contain";
40
- default:
41
- return "cover";
42
- }
43
- },
44
- defaultTransformSource = function (props) {
30
+ var import_jsx_runtime = require("react/jsx-runtime");
31
+ var import_web = require("@tamagui/web");
32
+ var defaultObjectFitMap = function (objectFit) {
33
+ switch (objectFit) {
34
+ case "fill":
35
+ return "stretch";
36
+ case "none":
37
+ return "center";
38
+ case "scale-down":
39
+ return "contain";
40
+ case "contain":
41
+ return "contain";
42
+ default:
43
+ return "cover";
44
+ }
45
+ };
46
+ var defaultTransformSource = function (props) {
47
+ var {
48
+ src,
49
+ source,
50
+ width,
51
+ height
52
+ } = props;
53
+ if (source) return source;
54
+ if (src && typeof src !== "string") return src;
55
+ return {
56
+ uri: src,
57
+ width,
58
+ height
59
+ };
60
+ };
61
+ function createImage(options) {
62
+ var {
63
+ Component,
64
+ mapObjectFitToResizeMode = defaultObjectFitMap,
65
+ resizeModePropName = "resizeMode",
66
+ objectPositionPropName,
67
+ transformSource = defaultTransformSource
68
+ } = options;
69
+ var inlinePropsSet = /* @__PURE__ */new Set(["source", "placeholder", "transition", "contentFit", "contentPosition", "cachePolicy", "recyclingKey", "allowDownscaling", "autoplay", "blurRadius", "priority", "placeholderContentFit", "responsivePolicy", "onLoadStart", "onProgress", "onLoadEnd"]);
70
+ var StyledImage = (0, import_web.styled)(Component, {
71
+ name: "Image"
72
+ }, {
73
+ inlineProps: inlinePropsSet
74
+ });
75
+ var ImageComponent = StyledImage.styleable(function (incomingProps, ref) {
76
+ var props = incomingProps;
45
77
  var {
46
78
  src,
47
- source,
48
79
  width,
49
- height
80
+ height,
81
+ borderRadius,
82
+ objectFit,
83
+ objectPosition,
84
+ // web only props - filter out on native
85
+ decoding,
86
+ elementTiming,
87
+ fetchpriority,
88
+ isMap,
89
+ loading,
90
+ sizes,
91
+ useMap,
92
+ onLoad,
93
+ onError,
94
+ ...rest
50
95
  } = props;
51
- return source || (src && typeof src != "string" ? src : {
52
- uri: src,
53
- width,
54
- height
96
+ var resolvedWidth = typeof width === "string" && width[0] === "$" ? (0, import_web.getTokenValue)(width, "size") : width;
97
+ var resolvedHeight = typeof height === "string" && height[0] === "$" ? (0, import_web.getTokenValue)(height, "size") : height;
98
+ var finalSource = transformSource({
99
+ src,
100
+ width: resolvedWidth,
101
+ height: resolvedHeight
55
102
  });
56
- };
57
- function createImage(options) {
58
- var {
59
- Component,
60
- mapObjectFitToResizeMode = defaultObjectFitMap,
61
- resizeModePropName = "resizeMode",
62
- objectPositionPropName,
63
- transformSource = defaultTransformSource
64
- } = options,
65
- inlinePropsSet = /* @__PURE__ */new Set(["source", "placeholder", "transition", "contentFit", "contentPosition", "cachePolicy", "recyclingKey", "allowDownscaling", "autoplay", "blurRadius", "priority", "placeholderContentFit", "responsivePolicy", "onLoadStart", "onProgress", "onLoadEnd"]),
66
- StyledImage = (0, import_web.styled)(Component, {
67
- name: "Image"
68
- }, {
69
- inlineProps: inlinePropsSet
70
- }),
71
- ImageComponent = StyledImage.styleable(function (incomingProps, ref) {
72
- var props = incomingProps,
73
- {
74
- src,
75
- width,
76
- height,
77
- objectFit,
78
- objectPosition,
79
- // web only props - filter out on native
80
- decoding,
81
- elementTiming,
82
- fetchpriority,
83
- isMap,
84
- loading,
85
- sizes,
86
- useMap,
87
- onLoad,
88
- onError,
89
- ...rest
90
- } = props,
91
- resolvedWidth = typeof width == "string" && width[0] === "$" ? (0, import_web.getTokenValue)(width) : width,
92
- resolvedHeight = typeof height == "string" && height[0] === "$" ? (0, import_web.getTokenValue)(height) : height,
93
- finalSource = transformSource({
94
- src,
95
- width: resolvedWidth,
96
- height: resolvedHeight
103
+ var incomingStyle = Array.isArray(rest.style) ? Object.assign({}, ...rest.style.flat()) : rest.style;
104
+ var resolvedBorderRadius = typeof borderRadius === "string" && borderRadius[0] === "$" ? (0, import_web.getTokenValue)(borderRadius, "radius") : borderRadius;
105
+ var finalProps = {
106
+ ...rest,
107
+ source: finalSource,
108
+ style: {
109
+ ...incomingStyle,
110
+ ...(resolvedBorderRadius !== void 0 && {
111
+ borderRadius: resolvedBorderRadius
97
112
  }),
98
- finalProps = {
99
- ...rest,
100
- source: finalSource,
101
- style: {
102
- width: resolvedWidth,
103
- height: resolvedHeight
104
- }
105
- };
106
- return objectFit && (finalProps[resizeModePropName] = mapObjectFitToResizeMode(objectFit)), objectPositionPropName && objectPosition && (finalProps[objectPositionPropName] = objectPosition), onLoad && (finalProps.onLoad = function (e) {
107
- var _e_nativeEvent,
108
- source = (e == null || (_e_nativeEvent = e.nativeEvent) === null || _e_nativeEvent === void 0 ? void 0 : _e_nativeEvent.source) || e?.source || {};
113
+ ...(resolvedWidth !== void 0 && {
114
+ width: resolvedWidth
115
+ }),
116
+ ...(resolvedHeight !== void 0 && {
117
+ height: resolvedHeight
118
+ })
119
+ }
120
+ };
121
+ if (objectFit) {
122
+ finalProps[resizeModePropName] = mapObjectFitToResizeMode(objectFit);
123
+ }
124
+ if (objectPositionPropName && objectPosition) {
125
+ finalProps[objectPositionPropName] = objectPosition;
126
+ }
127
+ if (onLoad) {
128
+ finalProps.onLoad = function (e) {
129
+ var _e_nativeEvent;
130
+ var source = (e === null || e === void 0 ? void 0 : (_e_nativeEvent = e.nativeEvent) === null || _e_nativeEvent === void 0 ? void 0 : _e_nativeEvent.source) || (e === null || e === void 0 ? void 0 : e.source) || {};
109
131
  onLoad({
110
132
  target: {
111
- naturalHeight: source?.height,
112
- naturalWidth: source?.width
133
+ naturalHeight: source === null || source === void 0 ? void 0 : source.height,
134
+ naturalWidth: source === null || source === void 0 ? void 0 : source.width
113
135
  },
114
136
  type: "load"
115
137
  });
116
- }), onError && (finalProps.onError = function () {
138
+ };
139
+ }
140
+ if (onError) {
141
+ finalProps.onError = function () {
117
142
  onError({
118
143
  type: "error"
119
144
  });
120
- }), /* @__PURE__ */(0, import_jsx_runtime.jsx)(Component, {
121
- ref,
122
- ...finalProps
123
- });
124
- }),
125
- comp = Component;
126
- return ImageComponent.getSize = comp.getSize || function () {}, ImageComponent.getSizeWithHeaders = comp.getSizeWithHeaders || function () {}, ImageComponent.prefetch = comp.prefetch || function () {}, ImageComponent.prefetchWithMetadata = comp.prefetchWithMetadata || function () {}, ImageComponent.abortPrefetch = comp.abortPrefetch || function () {}, ImageComponent.queryCache = comp.queryCache || function () {}, ImageComponent;
145
+ };
146
+ }
147
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(Component, {
148
+ ref,
149
+ ...finalProps
150
+ });
151
+ });
152
+ var comp = Component;
153
+ ImageComponent.getSize = comp.getSize || function () {};
154
+ ImageComponent.getSizeWithHeaders = comp.getSizeWithHeaders || function () {};
155
+ ImageComponent.prefetch = comp.prefetch || function () {};
156
+ ImageComponent.prefetchWithMetadata = comp.prefetchWithMetadata || function () {};
157
+ ImageComponent.abortPrefetch = comp.abortPrefetch || function () {};
158
+ ImageComponent.queryCache = comp.queryCache || function () {};
159
+ return ImageComponent;
127
160
  }
128
161
  //# sourceMappingURL=createImage.native.js.map