@tamagui/linear-gradient 1.94.3 → 1.94.5

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.
@@ -1,7 +1,8 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
5
6
  var __export = (target, all) => {
6
7
  for (var name in all)
7
8
  __defProp(target, name, { get: all[name], enumerable: !0 });
@@ -11,11 +12,80 @@ var __export = (target, all) => {
11
12
  !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
13
  return to;
13
14
  };
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
15
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
16
+ // If the importer is in node compatibility mode or this is not an ESM
17
+ // file that has been converted to a CommonJS file using a Babel-
18
+ // compatible transform (i.e. "__esModule" has not been set), then set
19
+ // "default" to the CommonJS "module.exports" for node compatibility.
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
21
+ mod
22
+ )), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
15
23
  var linear_gradient_exports = {};
16
24
  __export(linear_gradient_exports, {
17
- LinearGradient: () => import_expo_linear_gradient.LinearGradient
25
+ LinearGradient: () => LinearGradient
18
26
  });
19
27
  module.exports = __toCommonJS(linear_gradient_exports);
20
- var import_expo_linear_gradient = require("expo-linear-gradient");
28
+ var import_core = require("@tamagui/core"), React = __toESM(require("react")), import_react_native = require("react-native-web"), import_jsx_runtime = require("react/jsx-runtime");
29
+ function LinearGradient({
30
+ colors,
31
+ locations,
32
+ start,
33
+ end,
34
+ ...props
35
+ }) {
36
+ const [{ height, width }, setLayout] = React.useState({
37
+ height: 1,
38
+ width: 1
39
+ }), linearGradientBackgroundImage = React.useMemo(() => getLinearGradientBackgroundImage(colors, locations, start, end, width, height), [colors, locations, start, end, width, height]);
40
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
41
+ import_react_native.View,
42
+ {
43
+ ...props,
44
+ style: [
45
+ props.style,
46
+ // @ts-ignore: [ts] Property 'backgroundImage' does not exist on type 'ViewStyle'.
47
+ { backgroundImage: linearGradientBackgroundImage }
48
+ ],
49
+ onLayout: (event) => {
50
+ const { width: width2, height: height2 } = event.nativeEvent.layout;
51
+ setLayout((oldLayout) => width2 !== oldLayout.width || height2 !== oldLayout.height ? { height: height2, width: width2 } : oldLayout), props.onLayout && props.onLayout(event);
52
+ }
53
+ }
54
+ );
55
+ }
56
+ function getLinearGradientBackgroundImage(colors, locations, startPoint, endPoint, width = 1, height = 1) {
57
+ const gradientColors = calculateGradientColors(
58
+ // @ts-expect-error TODO fix numbers
59
+ colors,
60
+ locations
61
+ );
62
+ return `linear-gradient(${calculatePseudoAngle(width, height, startPoint, endPoint)}deg, ${gradientColors.join(", ")})`;
63
+ }
64
+ function calculatePseudoAngle(width, height, startPoint, endPoint) {
65
+ const getControlPoints = () => {
66
+ let correctedStartPoint = [0, 0];
67
+ Array.isArray(startPoint) && (correctedStartPoint = [
68
+ startPoint[0] != null ? startPoint[0] : 0,
69
+ startPoint[1] != null ? startPoint[1] : 0
70
+ ]);
71
+ let correctedEndPoint = [0, 1];
72
+ return Array.isArray(endPoint) && (correctedEndPoint = [
73
+ endPoint[0] != null ? endPoint[0] : 0,
74
+ endPoint[1] != null ? endPoint[1] : 1
75
+ ]), [correctedStartPoint, correctedEndPoint];
76
+ }, [start, end] = getControlPoints();
77
+ start[0] *= width, end[0] *= width, start[1] *= height, end[1] *= height;
78
+ const py = end[1] - start[1], px = end[0] - start[0];
79
+ return 90 + Math.atan2(py, px) * 180 / Math.PI;
80
+ }
81
+ function calculateGradientColors(colors, locations) {
82
+ return colors.map((color, index) => {
83
+ const output = (0, import_core.normalizeColor)(color);
84
+ if (locations && locations[index]) {
85
+ const percentage = Math.max(0, Math.min(1, locations[index])) * 100;
86
+ return `${output} ${percentage}%`;
87
+ }
88
+ return output;
89
+ });
90
+ }
21
91
  //# sourceMappingURL=linear-gradient.js.map
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/linear-gradient.ts"],
4
- "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kCAA+B;",
5
- "names": []
3
+ "sources": ["../../src/linear-gradient.tsx"],
4
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,kBAA+B,0BAK/B,QAAuB,2BACvB,sBAAqB,yBAmBjB;AAjBG,SAAS,eAAe;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAAwB;AACtB,QAAM,CAAC,EAAE,QAAQ,MAAM,GAAG,SAAS,IAAI,MAAM,SAAS;AAAA,IACpD,QAAQ;AAAA,IACR,OAAO;AAAA,EACT,CAAC,GAEK,gCAAgC,MAAM,QAAQ,MAC3C,iCAAiC,QAAQ,WAAW,OAAO,KAAK,OAAO,MAAM,GACnF,CAAC,QAAQ,WAAW,OAAO,KAAK,OAAO,MAAM,CAAC;AAEjD,SACE;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACJ,OAAO;AAAA,QACL,MAAM;AAAA;AAAA,QAEN,EAAE,iBAAiB,8BAA8B;AAAA,MACnD;AAAA,MACA,UAAU,CAAC,UAAU;AACnB,cAAM,EAAE,OAAAA,QAAO,QAAAC,QAAO,IAAI,MAAM,YAAY;AAE5C,kBAAU,CAAC,cAELD,WAAU,UAAU,SAASC,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AAiC;AACjE,UAAM,aAAS,4BAAe,KAAK;AACnC,QAAI,aAAa,UAAU,KAAK,GAAG;AAGjC,YAAM,aAFW,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,UAAU,KAAK,CAAC,CAAC,IAE5B;AAC9B,aAAO,GAAG,MAAM,IAAI,UAAU;AAAA,IAChC;AACA,WAAO;AAAA,EACT,CAAC;AACH;",
5
+ "names": ["width", "height"]
6
6
  }
@@ -13,14 +13,14 @@ var __export = (target, all) => {
13
13
  return to;
14
14
  };
15
15
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
16
- var linear_gradient_exports = {};
17
- __export(linear_gradient_exports, {
16
+ var linear_gradient_native_exports = {};
17
+ __export(linear_gradient_native_exports, {
18
18
  LinearGradient: () => import_expo_linear_gradient.LinearGradient
19
19
  });
20
- module.exports = __toCommonJS(linear_gradient_exports);
20
+ module.exports = __toCommonJS(linear_gradient_native_exports);
21
21
  var import_expo_linear_gradient = require("expo-linear-gradient");
22
22
  // Annotate the CommonJS export names for ESM import in node:
23
23
  0 && (module.exports = {
24
24
  LinearGradient
25
25
  });
26
- //# sourceMappingURL=linear-gradient.js.map
26
+ //# sourceMappingURL=linear-gradient.native.js.map
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/Users/n8/tamagui/packages/linear-gradient/src/linear-gradient.ts"],
3
+ "sources": ["../../src/Users/n8/tamagui/packages/linear-gradient/src/linear-gradient.native.tsx"],
4
4
  "mappings": ";;;;;;;;;;;;;;;AAAA;;;;;kCAA+B;",
5
5
  "names": []
6
6
  }
@@ -1,4 +1,69 @@
1
- import { LinearGradient } from "expo-linear-gradient";
1
+ import { normalizeColor } from "@tamagui/core";
2
+ import * as React from "react";
3
+ import { View } from "react-native-web";
4
+ import { jsx } from "react/jsx-runtime";
5
+ function LinearGradient({
6
+ colors,
7
+ locations,
8
+ start,
9
+ end,
10
+ ...props
11
+ }) {
12
+ const [{ height, width }, setLayout] = React.useState({
13
+ height: 1,
14
+ width: 1
15
+ }), linearGradientBackgroundImage = React.useMemo(() => getLinearGradientBackgroundImage(colors, locations, start, end, width, height), [colors, locations, start, end, width, height]);
16
+ return /* @__PURE__ */ jsx(
17
+ View,
18
+ {
19
+ ...props,
20
+ style: [
21
+ props.style,
22
+ // @ts-ignore: [ts] Property 'backgroundImage' does not exist on type 'ViewStyle'.
23
+ { backgroundImage: linearGradientBackgroundImage }
24
+ ],
25
+ onLayout: (event) => {
26
+ const { width: width2, height: height2 } = event.nativeEvent.layout;
27
+ setLayout((oldLayout) => width2 !== oldLayout.width || height2 !== oldLayout.height ? { height: height2, width: width2 } : oldLayout), props.onLayout && props.onLayout(event);
28
+ }
29
+ }
30
+ );
31
+ }
32
+ function getLinearGradientBackgroundImage(colors, locations, startPoint, endPoint, width = 1, height = 1) {
33
+ const gradientColors = calculateGradientColors(
34
+ // @ts-expect-error TODO fix numbers
35
+ colors,
36
+ locations
37
+ );
38
+ return `linear-gradient(${calculatePseudoAngle(width, height, startPoint, endPoint)}deg, ${gradientColors.join(", ")})`;
39
+ }
40
+ function calculatePseudoAngle(width, height, startPoint, endPoint) {
41
+ const getControlPoints = () => {
42
+ let correctedStartPoint = [0, 0];
43
+ Array.isArray(startPoint) && (correctedStartPoint = [
44
+ startPoint[0] != null ? startPoint[0] : 0,
45
+ startPoint[1] != null ? startPoint[1] : 0
46
+ ]);
47
+ let correctedEndPoint = [0, 1];
48
+ return Array.isArray(endPoint) && (correctedEndPoint = [
49
+ endPoint[0] != null ? endPoint[0] : 0,
50
+ endPoint[1] != null ? endPoint[1] : 1
51
+ ]), [correctedStartPoint, correctedEndPoint];
52
+ }, [start, end] = getControlPoints();
53
+ start[0] *= width, end[0] *= width, start[1] *= height, end[1] *= height;
54
+ const py = end[1] - start[1], px = end[0] - start[0];
55
+ return 90 + Math.atan2(py, px) * 180 / Math.PI;
56
+ }
57
+ function calculateGradientColors(colors, locations) {
58
+ return colors.map((color, index) => {
59
+ const output = normalizeColor(color);
60
+ if (locations && locations[index]) {
61
+ const percentage = Math.max(0, Math.min(1, locations[index])) * 100;
62
+ return `${output} ${percentage}%`;
63
+ }
64
+ return output;
65
+ });
66
+ }
2
67
  export {
3
68
  LinearGradient
4
69
  };
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/linear-gradient.ts"],
4
- "mappings": "AAAA,SAAS,sBAAsB;",
5
- "names": []
3
+ "sources": ["../../src/linear-gradient.tsx"],
4
+ "mappings": "AACA,SAAS,sBAAsB;AAK/B,YAAY,WAAW;AACvB,SAAS,YAAY;AAmBjB;AAjBG,SAAS,eAAe;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAAwB;AACtB,QAAM,CAAC,EAAE,QAAQ,MAAM,GAAG,SAAS,IAAI,MAAM,SAAS;AAAA,IACpD,QAAQ;AAAA,IACR,OAAO;AAAA,EACT,CAAC,GAEK,gCAAgC,MAAM,QAAQ,MAC3C,iCAAiC,QAAQ,WAAW,OAAO,KAAK,OAAO,MAAM,GACnF,CAAC,QAAQ,WAAW,OAAO,KAAK,OAAO,MAAM,CAAC;AAEjD,SACE;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACJ,OAAO;AAAA,QACL,MAAM;AAAA;AAAA,QAEN,EAAE,iBAAiB,8BAA8B;AAAA,MACnD;AAAA,MACA,UAAU,CAAC,UAAU;AACnB,cAAM,EAAE,OAAAA,QAAO,QAAAC,QAAO,IAAI,MAAM,YAAY;AAE5C,kBAAU,CAAC,cAELD,WAAU,UAAU,SAASC,YAAW,UAAU,SAC7C,EAAE,QAAAA,SAAQ,OAAAD,OAAM,IAGlB,SACR,GAEG,MAAM,YACR,MAAM,SAAS,KAAK;AAAA,MAExB;AAAA;AAAA,EACF;AAEJ;AAEA,SAAS,iCACP,QACA,WACA,YACA,UACA,QAAQ,GACR,SAAS,GACT;AACA,QAAM,iBAAiB;AAA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AAAA,EACT,CAAC;AACH;",
5
+ "names": ["width", "height"]
6
6
  }
@@ -1,2 +1,68 @@
1
- import { LinearGradient } from "expo-linear-gradient";
1
+ import { normalizeColor } from "@tamagui/core";
2
+ import * as React from "react";
3
+ import { View } from "react-native-web";
4
+ import { jsx } from "react/jsx-runtime";
5
+ function LinearGradient({
6
+ colors,
7
+ locations,
8
+ start,
9
+ end,
10
+ ...props
11
+ }) {
12
+ const [{
13
+ height,
14
+ width
15
+ }, setLayout] = React.useState({
16
+ height: 1,
17
+ width: 1
18
+ }),
19
+ linearGradientBackgroundImage = React.useMemo(() => getLinearGradientBackgroundImage(colors, locations, start, end, width, height), [colors, locations, start, end, width, height]);
20
+ return /* @__PURE__ */jsx(View, {
21
+ ...props,
22
+ style: [props.style,
23
+ // @ts-ignore: [ts] Property 'backgroundImage' does not exist on type 'ViewStyle'.
24
+ {
25
+ backgroundImage: linearGradientBackgroundImage
26
+ }],
27
+ onLayout: event => {
28
+ const {
29
+ width: width2,
30
+ height: height2
31
+ } = event.nativeEvent.layout;
32
+ setLayout(oldLayout => width2 !== oldLayout.width || height2 !== oldLayout.height ? {
33
+ height: height2,
34
+ width: width2
35
+ } : oldLayout), props.onLayout && props.onLayout(event);
36
+ }
37
+ });
38
+ }
39
+ function getLinearGradientBackgroundImage(colors, locations, startPoint, endPoint, width = 1, height = 1) {
40
+ const gradientColors = calculateGradientColors(
41
+ // @ts-expect-error TODO fix numbers
42
+ colors, locations);
43
+ return `linear-gradient(${calculatePseudoAngle(width, height, startPoint, endPoint)}deg, ${gradientColors.join(", ")})`;
44
+ }
45
+ function calculatePseudoAngle(width, height, startPoint, endPoint) {
46
+ const getControlPoints = () => {
47
+ let correctedStartPoint = [0, 0];
48
+ Array.isArray(startPoint) && (correctedStartPoint = [startPoint[0] != null ? startPoint[0] : 0, startPoint[1] != null ? startPoint[1] : 0]);
49
+ let correctedEndPoint = [0, 1];
50
+ return Array.isArray(endPoint) && (correctedEndPoint = [endPoint[0] != null ? endPoint[0] : 0, endPoint[1] != null ? endPoint[1] : 1]), [correctedStartPoint, correctedEndPoint];
51
+ },
52
+ [start, end] = getControlPoints();
53
+ start[0] *= width, end[0] *= width, start[1] *= height, end[1] *= height;
54
+ const py = end[1] - start[1],
55
+ px = end[0] - start[0];
56
+ return 90 + Math.atan2(py, px) * 180 / Math.PI;
57
+ }
58
+ function calculateGradientColors(colors, locations) {
59
+ return colors.map((color, index) => {
60
+ const output = normalizeColor(color);
61
+ if (locations && locations[index]) {
62
+ const percentage = Math.max(0, Math.min(1, locations[index])) * 100;
63
+ return `${output} ${percentage}%`;
64
+ }
65
+ return output;
66
+ });
67
+ }
2
68
  export { LinearGradient };
@@ -2,4 +2,4 @@ import { LinearGradient } from "expo-linear-gradient";
2
2
  export {
3
3
  LinearGradient
4
4
  };
5
- //# sourceMappingURL=linear-gradient.js.map
5
+ //# sourceMappingURL=linear-gradient.native.js.map
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/Users/n8/tamagui/packages/linear-gradient/src/linear-gradient.ts"],
3
+ "sources": ["../../src/Users/n8/tamagui/packages/linear-gradient/src/linear-gradient.native.tsx"],
4
4
  "mappings": "AAAA,SAASA,sBAAsB;",
5
5
  "names": ["LinearGradient"]
6
6
  }
@@ -1,4 +1,69 @@
1
- import { LinearGradient } from "expo-linear-gradient";
1
+ import { normalizeColor } from "@tamagui/core";
2
+ import * as React from "react";
3
+ import { View } from "react-native-web";
4
+ import { jsx } from "react/jsx-runtime";
5
+ function LinearGradient({
6
+ colors,
7
+ locations,
8
+ start,
9
+ end,
10
+ ...props
11
+ }) {
12
+ const [{ height, width }, setLayout] = React.useState({
13
+ height: 1,
14
+ width: 1
15
+ }), linearGradientBackgroundImage = React.useMemo(() => getLinearGradientBackgroundImage(colors, locations, start, end, width, height), [colors, locations, start, end, width, height]);
16
+ return /* @__PURE__ */ jsx(
17
+ View,
18
+ {
19
+ ...props,
20
+ style: [
21
+ props.style,
22
+ // @ts-ignore: [ts] Property 'backgroundImage' does not exist on type 'ViewStyle'.
23
+ { backgroundImage: linearGradientBackgroundImage }
24
+ ],
25
+ onLayout: (event) => {
26
+ const { width: width2, height: height2 } = event.nativeEvent.layout;
27
+ setLayout((oldLayout) => width2 !== oldLayout.width || height2 !== oldLayout.height ? { height: height2, width: width2 } : oldLayout), props.onLayout && props.onLayout(event);
28
+ }
29
+ }
30
+ );
31
+ }
32
+ function getLinearGradientBackgroundImage(colors, locations, startPoint, endPoint, width = 1, height = 1) {
33
+ const gradientColors = calculateGradientColors(
34
+ // @ts-expect-error TODO fix numbers
35
+ colors,
36
+ locations
37
+ );
38
+ return `linear-gradient(${calculatePseudoAngle(width, height, startPoint, endPoint)}deg, ${gradientColors.join(", ")})`;
39
+ }
40
+ function calculatePseudoAngle(width, height, startPoint, endPoint) {
41
+ const getControlPoints = () => {
42
+ let correctedStartPoint = [0, 0];
43
+ Array.isArray(startPoint) && (correctedStartPoint = [
44
+ startPoint[0] != null ? startPoint[0] : 0,
45
+ startPoint[1] != null ? startPoint[1] : 0
46
+ ]);
47
+ let correctedEndPoint = [0, 1];
48
+ return Array.isArray(endPoint) && (correctedEndPoint = [
49
+ endPoint[0] != null ? endPoint[0] : 0,
50
+ endPoint[1] != null ? endPoint[1] : 1
51
+ ]), [correctedStartPoint, correctedEndPoint];
52
+ }, [start, end] = getControlPoints();
53
+ start[0] *= width, end[0] *= width, start[1] *= height, end[1] *= height;
54
+ const py = end[1] - start[1], px = end[0] - start[0];
55
+ return 90 + Math.atan2(py, px) * 180 / Math.PI;
56
+ }
57
+ function calculateGradientColors(colors, locations) {
58
+ return colors.map((color, index) => {
59
+ const output = normalizeColor(color);
60
+ if (locations && locations[index]) {
61
+ const percentage = Math.max(0, Math.min(1, locations[index])) * 100;
62
+ return `${output} ${percentage}%`;
63
+ }
64
+ return output;
65
+ });
66
+ }
2
67
  export {
3
68
  LinearGradient
4
69
  };
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/linear-gradient.ts"],
4
- "mappings": "AAAA,SAAS,sBAAsB;",
5
- "names": []
3
+ "sources": ["../../src/linear-gradient.tsx"],
4
+ "mappings": "AACA,SAAS,sBAAsB;AAK/B,YAAY,WAAW;AACvB,SAAS,YAAY;AAmBjB;AAjBG,SAAS,eAAe;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAAwB;AACtB,QAAM,CAAC,EAAE,QAAQ,MAAM,GAAG,SAAS,IAAI,MAAM,SAAS;AAAA,IACpD,QAAQ;AAAA,IACR,OAAO;AAAA,EACT,CAAC,GAEK,gCAAgC,MAAM,QAAQ,MAC3C,iCAAiC,QAAQ,WAAW,OAAO,KAAK,OAAO,MAAM,GACnF,CAAC,QAAQ,WAAW,OAAO,KAAK,OAAO,MAAM,CAAC;AAEjD,SACE;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACJ,OAAO;AAAA,QACL,MAAM;AAAA;AAAA,QAEN,EAAE,iBAAiB,8BAA8B;AAAA,MACnD;AAAA,MACA,UAAU,CAAC,UAAU;AACnB,cAAM,EAAE,OAAAA,QAAO,QAAAC,QAAO,IAAI,MAAM,YAAY;AAE5C,kBAAU,CAAC,cAELD,WAAU,UAAU,SAASC,YAAW,UAAU,SAC7C,EAAE,QAAAA,SAAQ,OAAAD,OAAM,IAGlB,SACR,GAEG,MAAM,YACR,MAAM,SAAS,KAAK;AAAA,MAExB;AAAA;AAAA,EACF;AAEJ;AAEA,SAAS,iCACP,QACA,WACA,YACA,UACA,QAAQ,GACR,SAAS,GACT;AACA,QAAM,iBAAiB;AAAA;AAAA,IAErB;AAAA,IACA;AAAA,EACF;AAEA,SAAO,mBADO,qBAAqB,OAAO,QAAQ,YAAY,QAAQ,CACvC,QAAQ,eAAe,KAAK,IAAI,CAAC;AAClE;AAEA,SAAS,qBACP,OACA,QACA,YACA,UACA;AACA,QAAM,mBAAmB,MAA6B;AACpD,QAAI,sBAA2C,CAAC,GAAG,CAAC;AACpD,IAAI,MAAM,QAAQ,UAAU,MAC1B,sBAAsB;AAAA,MACpB,WAAW,CAAC,KAAK,OAAO,WAAW,CAAC,IAAI;AAAA,MACxC,WAAW,CAAC,KAAK,OAAO,WAAW,CAAC,IAAI;AAAA,IAC1C;AAEF,QAAI,oBAAyC,CAAC,GAAK,CAAG;AACtD,WAAI,MAAM,QAAQ,QAAQ,MACxB,oBAAoB;AAAA,MAClB,SAAS,CAAC,KAAK,OAAO,SAAS,CAAC,IAAI;AAAA,MACpC,SAAS,CAAC,KAAK,OAAO,SAAS,CAAC,IAAI;AAAA,IACtC,IAEK,CAAC,qBAAqB,iBAAiB;AAAA,EAChD,GAEM,CAAC,OAAO,GAAG,IAAI,iBAAiB;AACtC,QAAM,CAAC,KAAK,OACZ,IAAI,CAAC,KAAK,OACV,MAAM,CAAC,KAAK,QACZ,IAAI,CAAC,KAAK;AACV,QAAM,KAAK,IAAI,CAAC,IAAI,MAAM,CAAC,GACrB,KAAK,IAAI,CAAC,IAAI,MAAM,CAAC;AAE3B,SAAO,KAAM,KAAK,MAAM,IAAI,EAAE,IAAI,MAAO,KAAK;AAChD;AAEA,SAAS,wBAAwB,QAAkB,WAA6B;AAC9E,SAAO,OAAO,IAAI,CAAC,OAAe,UAAiC;AACjE,UAAM,SAAS,eAAe,KAAK;AACnC,QAAI,aAAa,UAAU,KAAK,GAAG;AAGjC,YAAM,aAFW,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,UAAU,KAAK,CAAC,CAAC,IAE5B;AAC9B,aAAO,GAAG,MAAM,IAAI,UAAU;AAAA,IAChC;AACA,WAAO;AAAA,EACT,CAAC;AACH;",
5
+ "names": ["width", "height"]
6
6
  }
@@ -1,2 +1,68 @@
1
- import { LinearGradient } from "expo-linear-gradient";
1
+ import { normalizeColor } from "@tamagui/core";
2
+ import * as React from "react";
3
+ import { View } from "react-native-web";
4
+ import { jsx } from "react/jsx-runtime";
5
+ function LinearGradient({
6
+ colors,
7
+ locations,
8
+ start,
9
+ end,
10
+ ...props
11
+ }) {
12
+ const [{
13
+ height,
14
+ width
15
+ }, setLayout] = React.useState({
16
+ height: 1,
17
+ width: 1
18
+ }),
19
+ linearGradientBackgroundImage = React.useMemo(() => getLinearGradientBackgroundImage(colors, locations, start, end, width, height), [colors, locations, start, end, width, height]);
20
+ return /* @__PURE__ */jsx(View, {
21
+ ...props,
22
+ style: [props.style,
23
+ // @ts-ignore: [ts] Property 'backgroundImage' does not exist on type 'ViewStyle'.
24
+ {
25
+ backgroundImage: linearGradientBackgroundImage
26
+ }],
27
+ onLayout: event => {
28
+ const {
29
+ width: width2,
30
+ height: height2
31
+ } = event.nativeEvent.layout;
32
+ setLayout(oldLayout => width2 !== oldLayout.width || height2 !== oldLayout.height ? {
33
+ height: height2,
34
+ width: width2
35
+ } : oldLayout), props.onLayout && props.onLayout(event);
36
+ }
37
+ });
38
+ }
39
+ function getLinearGradientBackgroundImage(colors, locations, startPoint, endPoint, width = 1, height = 1) {
40
+ const gradientColors = calculateGradientColors(
41
+ // @ts-expect-error TODO fix numbers
42
+ colors, locations);
43
+ return `linear-gradient(${calculatePseudoAngle(width, height, startPoint, endPoint)}deg, ${gradientColors.join(", ")})`;
44
+ }
45
+ function calculatePseudoAngle(width, height, startPoint, endPoint) {
46
+ const getControlPoints = () => {
47
+ let correctedStartPoint = [0, 0];
48
+ Array.isArray(startPoint) && (correctedStartPoint = [startPoint[0] != null ? startPoint[0] : 0, startPoint[1] != null ? startPoint[1] : 0]);
49
+ let correctedEndPoint = [0, 1];
50
+ return Array.isArray(endPoint) && (correctedEndPoint = [endPoint[0] != null ? endPoint[0] : 0, endPoint[1] != null ? endPoint[1] : 1]), [correctedStartPoint, correctedEndPoint];
51
+ },
52
+ [start, end] = getControlPoints();
53
+ start[0] *= width, end[0] *= width, start[1] *= height, end[1] *= height;
54
+ const py = end[1] - start[1],
55
+ px = end[0] - start[0];
56
+ return 90 + Math.atan2(py, px) * 180 / Math.PI;
57
+ }
58
+ function calculateGradientColors(colors, locations) {
59
+ return colors.map((color, index) => {
60
+ const output = normalizeColor(color);
61
+ if (locations && locations[index]) {
62
+ const percentage = Math.max(0, Math.min(1, locations[index])) * 100;
63
+ return `${output} ${percentage}%`;
64
+ }
65
+ return output;
66
+ });
67
+ }
2
68
  export { LinearGradient };
@@ -2,4 +2,4 @@ import { LinearGradient } from "expo-linear-gradient";
2
2
  export {
3
3
  LinearGradient
4
4
  };
5
- //# sourceMappingURL=linear-gradient.js.map
5
+ //# sourceMappingURL=linear-gradient.native.js.map
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/Users/n8/tamagui/packages/linear-gradient/src/linear-gradient.ts"],
3
+ "sources": ["../../src/Users/n8/tamagui/packages/linear-gradient/src/linear-gradient.native.tsx"],
4
4
  "mappings": "AAAA,SAASA,sBAAsB;",
5
5
  "names": ["LinearGradient"]
6
6
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/linear-gradient",
3
- "version": "1.94.3",
3
+ "version": "1.94.5",
4
4
  "sideEffects": [
5
5
  "*.css"
6
6
  ],
@@ -32,14 +32,14 @@
32
32
  }
33
33
  },
34
34
  "dependencies": {
35
- "@tamagui/core": "1.94.3",
36
- "@tamagui/stacks": "1.94.3"
35
+ "@tamagui/core": "1.94.5",
36
+ "@tamagui/stacks": "1.94.5"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "react": "*"
40
40
  },
41
41
  "devDependencies": {
42
- "@tamagui/build": "1.94.3",
42
+ "@tamagui/build": "1.94.5",
43
43
  "expo-linear-gradient": "^12.7.1",
44
44
  "react": "^18.2.0"
45
45
  },
@@ -0,0 +1,117 @@
1
+ export type { LinearGradientProps, LinearGradientPoint } from 'expo-linear-gradient'
2
+ import { normalizeColor } from '@tamagui/core'
3
+ import type { LinearGradientProps, LinearGradientPoint } from 'expo-linear-gradient'
4
+
5
+ // copied from https://raw.githubusercontent.com/expo/expo/main/packages/expo-linear-gradient/src/LinearGradient.web.tsx
6
+
7
+ import * as React from 'react'
8
+ import { View } from 'react-native'
9
+
10
+ export function LinearGradient({
11
+ colors,
12
+ locations,
13
+ start,
14
+ end,
15
+ ...props
16
+ }: LinearGradientProps) {
17
+ const [{ height, width }, setLayout] = React.useState({
18
+ height: 1,
19
+ width: 1,
20
+ })
21
+
22
+ const linearGradientBackgroundImage = React.useMemo(() => {
23
+ return getLinearGradientBackgroundImage(colors, locations, start, end, width, height)
24
+ }, [colors, locations, start, end, width, height])
25
+
26
+ return (
27
+ <View
28
+ {...props}
29
+ style={[
30
+ props.style,
31
+ // @ts-ignore: [ts] Property 'backgroundImage' does not exist on type 'ViewStyle'.
32
+ { backgroundImage: linearGradientBackgroundImage },
33
+ ]}
34
+ onLayout={(event) => {
35
+ const { width, height } = event.nativeEvent.layout
36
+
37
+ setLayout((oldLayout) => {
38
+ // don't set new layout state unless the layout has actually changed
39
+ if (width !== oldLayout.width || height !== oldLayout.height) {
40
+ return { height, width }
41
+ }
42
+
43
+ return oldLayout
44
+ })
45
+
46
+ if (props.onLayout) {
47
+ props.onLayout(event)
48
+ }
49
+ }}
50
+ />
51
+ )
52
+ }
53
+
54
+ function getLinearGradientBackgroundImage(
55
+ colors: number[] | string[],
56
+ locations?: number[] | null,
57
+ startPoint?: LinearGradientPoint | null,
58
+ endPoint?: LinearGradientPoint | null,
59
+ width = 1,
60
+ height = 1
61
+ ) {
62
+ const gradientColors = calculateGradientColors(
63
+ // @ts-expect-error TODO fix numbers
64
+ colors,
65
+ locations
66
+ )
67
+ const angle = calculatePseudoAngle(width, height, startPoint, endPoint)
68
+ return `linear-gradient(${angle}deg, ${gradientColors.join(', ')})`
69
+ }
70
+
71
+ function calculatePseudoAngle(
72
+ width: number,
73
+ height: number,
74
+ startPoint?: LinearGradientPoint | null,
75
+ endPoint?: LinearGradientPoint | null
76
+ ) {
77
+ const getControlPoints = (): LinearGradientPoint[] => {
78
+ let correctedStartPoint: LinearGradientPoint = [0, 0]
79
+ if (Array.isArray(startPoint)) {
80
+ correctedStartPoint = [
81
+ startPoint[0] != null ? startPoint[0] : 0.0,
82
+ startPoint[1] != null ? startPoint[1] : 0.0,
83
+ ]
84
+ }
85
+ let correctedEndPoint: LinearGradientPoint = [0.0, 1.0]
86
+ if (Array.isArray(endPoint)) {
87
+ correctedEndPoint = [
88
+ endPoint[0] != null ? endPoint[0] : 0.0,
89
+ endPoint[1] != null ? endPoint[1] : 1.0,
90
+ ]
91
+ }
92
+ return [correctedStartPoint, correctedEndPoint]
93
+ }
94
+
95
+ const [start, end] = getControlPoints()
96
+ start[0] *= width
97
+ end[0] *= width
98
+ start[1] *= height
99
+ end[1] *= height
100
+ const py = end[1] - start[1]
101
+ const px = end[0] - start[0]
102
+
103
+ return 90 + (Math.atan2(py, px) * 180) / Math.PI
104
+ }
105
+
106
+ function calculateGradientColors(colors: string[], locations?: number[] | null) {
107
+ return colors.map((color: string, index: number): string | void => {
108
+ const output = normalizeColor(color)
109
+ if (locations && locations[index]) {
110
+ const location = Math.max(0, Math.min(1, locations[index]))
111
+ // Convert 0...1 to 0...100
112
+ const percentage = location * 100
113
+ return `${output} ${percentage}%`
114
+ }
115
+ return output
116
+ })
117
+ }
@@ -1,3 +1,4 @@
1
- export { LinearGradient } from 'expo-linear-gradient';
2
1
  export type { LinearGradientProps, LinearGradientPoint } from 'expo-linear-gradient';
2
+ import type { LinearGradientProps } from 'expo-linear-gradient';
3
+ export declare function LinearGradient({ colors, locations, start, end, ...props }: LinearGradientProps): import("react/jsx-runtime").JSX.Element;
3
4
  //# sourceMappingURL=linear-gradient.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"linear-gradient.d.ts","sourceRoot":"","sources":["../src/linear-gradient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,YAAY,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA"}
1
+ {"version":3,"file":"linear-gradient.d.ts","sourceRoot":"","sources":["../src/linear-gradient.tsx"],"names":[],"mappings":"AAAA,YAAY,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAEpF,OAAO,KAAK,EAAE,mBAAmB,EAAuB,MAAM,sBAAsB,CAAA;AAOpF,wBAAgB,cAAc,CAAC,EAC7B,MAAM,EACN,SAAS,EACT,KAAK,EACL,GAAG,EACH,GAAG,KAAK,EACT,EAAE,mBAAmB,2CAoCrB"}
@@ -0,0 +1,3 @@
1
+ export { LinearGradient } from 'expo-linear-gradient';
2
+ export type { LinearGradientProps, LinearGradientPoint } from 'expo-linear-gradient';
3
+ //# sourceMappingURL=linear-gradient.native.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"linear-gradient.native.d.ts","sourceRoot":"","sources":["../src/linear-gradient.native.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,YAAY,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA"}