@tamagui/linear-gradient 1.116.1 → 1.116.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,57 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: !0 });
8
+ }, __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from == "object" || typeof from == "function")
10
+ for (let key of __getOwnPropNames(from))
11
+ !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
15
+ var LinearGradient_exports = {};
16
+ __export(LinearGradient_exports, {
17
+ LinearGradient: () => LinearGradient
18
+ });
19
+ module.exports = __toCommonJS(LinearGradient_exports);
20
+ var import_core = require("@tamagui/core"), import_stacks = require("@tamagui/stacks"), import_linear_gradient = require("./linear-gradient"), import_jsx_runtime = require("react/jsx-runtime");
21
+ const LinearGradientFrame = (0, import_core.styled)(import_stacks.YStack, {
22
+ name: "LinearGradient",
23
+ overflow: "hidden",
24
+ position: "relative"
25
+ }), LinearGradient = LinearGradientFrame.styleable(
26
+ (propsIn, ref) => {
27
+ const props = (0, import_core.useProps)(propsIn), { start, end, colors: colorsProp, locations, children, ...stackProps } = props, theme = (0, import_core.useTheme)();
28
+ let colors = props.colors?.map((c) => theme[c]?.get("web") ?? c) || [];
29
+ return process.env.NODE_ENV !== "production" && colors.some((c) => {
30
+ const normalized = (0, import_core.normalizeColor)(c);
31
+ if (!normalized || normalized.startsWith("$"))
32
+ return !0;
33
+ }) && (console.error(
34
+ `LinearGradient: "colors" prop contains invalid color tokens: ${colors} fallback to default colors: ["#000", "#fff"]`
35
+ ), colors = ["#000", "#fff"]), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(LinearGradientFrame, { ref, ...stackProps, children: [
36
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
37
+ import_linear_gradient.LinearGradient,
38
+ {
39
+ start,
40
+ end,
41
+ colors,
42
+ locations,
43
+ style: gradientStyle
44
+ }
45
+ ),
46
+ children
47
+ ] });
48
+ }
49
+ ), gradientStyle = {
50
+ position: "absolute",
51
+ top: 0,
52
+ left: 0,
53
+ right: 0,
54
+ bottom: 0,
55
+ zIndex: 0
56
+ };
57
+ //# sourceMappingURL=LinearGradient.js.map
@@ -0,0 +1,15 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from == "object" || typeof from == "function")
7
+ for (let key of __getOwnPropNames(from))
8
+ !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
9
+ return to;
10
+ }, __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
11
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
12
+ var src_exports = {};
13
+ module.exports = __toCommonJS(src_exports);
14
+ __reExport(src_exports, require("./LinearGradient"), module.exports);
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,99 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: !0 });
9
+ }, __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from == "object" || typeof from == "function")
11
+ for (let key of __getOwnPropNames(from))
12
+ !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
+ return to;
14
+ };
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);
23
+ var linear_gradient_exports = {};
24
+ __export(linear_gradient_exports, {
25
+ LinearGradient: () => LinearGradient
26
+ });
27
+ module.exports = __toCommonJS(linear_gradient_exports);
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(
40
+ // @ts-expect-error ok
41
+ colors,
42
+ locations,
43
+ start,
44
+ end,
45
+ width,
46
+ height
47
+ ), [colors, locations, start, end, width, height]);
48
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
49
+ import_react_native.View,
50
+ {
51
+ ...props,
52
+ style: [
53
+ props.style,
54
+ // @ts-ignore: [ts] Property 'backgroundImage' does not exist on type 'ViewStyle'.
55
+ { backgroundImage: linearGradientBackgroundImage }
56
+ ],
57
+ onLayout: (event) => {
58
+ const { width: width2, height: height2 } = event.nativeEvent.layout;
59
+ setLayout((oldLayout) => width2 !== oldLayout.width || height2 !== oldLayout.height ? { height: height2, width: width2 } : oldLayout), props.onLayout && props.onLayout(event);
60
+ }
61
+ }
62
+ );
63
+ }
64
+ function getLinearGradientBackgroundImage(colors, locations, startPoint, endPoint, width = 1, height = 1) {
65
+ const gradientColors = calculateGradientColors(
66
+ // @ts-expect-error TODO fix numbers
67
+ colors,
68
+ locations
69
+ );
70
+ return `linear-gradient(${calculatePseudoAngle(width, height, startPoint, endPoint)}deg, ${gradientColors.join(", ")})`;
71
+ }
72
+ function calculatePseudoAngle(width, height, startPoint, endPoint) {
73
+ const getControlPoints = () => {
74
+ let correctedStartPoint = [0, 0];
75
+ Array.isArray(startPoint) && (correctedStartPoint = [
76
+ startPoint[0] != null ? startPoint[0] : 0,
77
+ startPoint[1] != null ? startPoint[1] : 0
78
+ ]);
79
+ let correctedEndPoint = [0, 1];
80
+ return Array.isArray(endPoint) && (correctedEndPoint = [
81
+ endPoint[0] != null ? endPoint[0] : 0,
82
+ endPoint[1] != null ? endPoint[1] : 1
83
+ ]), [correctedStartPoint, correctedEndPoint];
84
+ }, [start, end] = getControlPoints();
85
+ start[0] *= width, end[0] *= width, start[1] *= height, end[1] *= height;
86
+ const py = end[1] - start[1], px = end[0] - start[0];
87
+ return 90 + Math.atan2(py, px) * 180 / Math.PI;
88
+ }
89
+ function calculateGradientColors(colors, locations) {
90
+ return colors.map((color, index) => {
91
+ const output = (0, import_core.normalizeColor)(color);
92
+ if (locations && locations[index]) {
93
+ const percentage = Math.max(0, Math.min(1, locations[index])) * 100;
94
+ return `${output} ${percentage}%`;
95
+ }
96
+ return output;
97
+ });
98
+ }
99
+ //# sourceMappingURL=linear-gradient.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/linear-gradient",
3
- "version": "1.116.1",
3
+ "version": "1.116.3",
4
4
  "sideEffects": [
5
5
  "*.css"
6
6
  ],
@@ -34,11 +34,11 @@
34
34
  }
35
35
  },
36
36
  "dependencies": {
37
- "@tamagui/core": "1.116.1",
38
- "@tamagui/stacks": "1.116.1"
37
+ "@tamagui/core": "1.116.3",
38
+ "@tamagui/stacks": "1.116.3"
39
39
  },
40
40
  "devDependencies": {
41
- "@tamagui/build": "1.116.1",
41
+ "@tamagui/build": "1.116.3",
42
42
  "expo-linear-gradient": "~13.0.2",
43
43
  "react": "^18.2.0 || ^19.0.0"
44
44
  },
@@ -1,26 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
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, {
13
- get: () => from[key],
14
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
- });
16
- return to;
17
- };
18
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
19
- value: !0
20
- }), mod);
21
- var linear_gradient_native_exports = {};
22
- __export(linear_gradient_native_exports, {
23
- LinearGradient: () => import_expo_linear_gradient.LinearGradient
24
- });
25
- module.exports = __toCommonJS(linear_gradient_native_exports);
26
- var import_expo_linear_gradient = require("expo-linear-gradient");
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/linear-gradient.native.tsx"],
4
- "mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kCAA+B;",
5
- "names": []
6
- }
File without changes