@hanzogui/progress 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Nate Wienert
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,171 @@
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 Progress_exports = {};
22
+ __export(Progress_exports, {
23
+ Progress: () => Progress,
24
+ ProgressFrame: () => ProgressFrame,
25
+ ProgressIndicator: () => ProgressIndicator,
26
+ ProgressIndicatorFrame: () => ProgressIndicatorFrame,
27
+ createProgressScope: () => createProgressScope
28
+ });
29
+ module.exports = __toCommonJS(Progress_exports);
30
+ var import_gui_core = require("@hanzo/gui-core"),
31
+ import_gui_create_context = require("@hanzo/gui-create-context"),
32
+ import_gui_get_token = require("@hanzo/gui-get-token"),
33
+ import_gui_helpers = require("@hanzo/gui-helpers"),
34
+ import_gui_stacks = require("@hanzo/gui-stacks"),
35
+ import_react = require("react"),
36
+ import_jsx_runtime = require("react/jsx-runtime");
37
+ const PROGRESS_NAME = "Progress",
38
+ [createProgressContext, createProgressScope] = (0, import_gui_create_context.createContextScope)(PROGRESS_NAME),
39
+ [ProgressProvider, useProgressContext] = createProgressContext(PROGRESS_NAME),
40
+ INDICATOR_NAME = "ProgressIndicator",
41
+ ProgressIndicatorFrame = (0, import_gui_core.styled)(import_gui_stacks.YStack, {
42
+ name: INDICATOR_NAME,
43
+ variants: {
44
+ unstyled: {
45
+ false: {
46
+ height: "100%",
47
+ width: "100%",
48
+ backgroundColor: "$background"
49
+ }
50
+ }
51
+ },
52
+ defaultVariants: {
53
+ unstyled: process.env.HANZO_GUI_HEADLESS === "1"
54
+ }
55
+ }),
56
+ ProgressIndicator = ProgressIndicatorFrame.styleable(function (props, forwardedRef) {
57
+ const {
58
+ __scopeProgress,
59
+ transition,
60
+ ...indicatorProps
61
+ } = props,
62
+ context = useProgressContext(INDICATOR_NAME, __scopeProgress),
63
+ progressRatio = (context.value ?? 0) / context.max;
64
+ let x;
65
+ if (import_gui_core.isWeb) x = `${-100 + progressRatio * 50}%`;else {
66
+ const baseWidth = context.width || 0;
67
+ x = Math.ceil(-baseWidth * (2 - progressRatio));
68
+ }
69
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ProgressIndicatorFrame, {
70
+ "data-state": getProgressState(context.value, context.max),
71
+ "data-value": context.value ?? void 0,
72
+ "data-max": context.max,
73
+ x,
74
+ width: "200%",
75
+ ...(!props.unstyled && {
76
+ animateOnly: ["transform"],
77
+ // on native, hide until we have width measurement
78
+ ...(!import_gui_core.isWeb && context.width === 0 && {
79
+ opacity: 0
80
+ })
81
+ }),
82
+ ...indicatorProps,
83
+ ref: forwardedRef,
84
+ transition: !import_gui_core.isWeb && !context.width ? null : transition
85
+ });
86
+ });
87
+ function defaultGetValueLabel(value, max) {
88
+ return `${Math.round(value / max * 100)}%`;
89
+ }
90
+ function getProgressState(value, maxValue) {
91
+ return value == null ? "indeterminate" : value === maxValue ? "complete" : "loading";
92
+ }
93
+ function isNumber(value) {
94
+ return typeof value == "number";
95
+ }
96
+ function isValidMaxNumber(max) {
97
+ return isNumber(max) && !Number.isNaN(max) && max > 0;
98
+ }
99
+ function isValidValueNumber(value, max) {
100
+ return isNumber(value) && !Number.isNaN(value) && value <= max && value >= 0;
101
+ }
102
+ const DEFAULT_MAX = 100,
103
+ ProgressFrame = (0, import_gui_core.styled)(import_gui_stacks.YStack, {
104
+ name: "Progress",
105
+ variants: {
106
+ unstyled: {
107
+ false: {
108
+ borderRadius: 1e5,
109
+ overflow: "hidden",
110
+ backgroundColor: "$background"
111
+ }
112
+ },
113
+ size: {
114
+ "...size": val => {
115
+ const size = Math.round((0, import_gui_core.getVariableValue)((0, import_gui_get_token.getSize)(val)) * 0.25);
116
+ return {
117
+ height: size,
118
+ minWidth: (0, import_gui_core.getVariableValue)(size) * 20,
119
+ width: "100%"
120
+ };
121
+ }
122
+ }
123
+ },
124
+ defaultVariants: {
125
+ unstyled: process.env.HANZO_GUI_HEADLESS === "1"
126
+ }
127
+ }),
128
+ Progress = (0, import_gui_helpers.withStaticProperties)(ProgressFrame.styleable(function (props, forwardedRef) {
129
+ const {
130
+ // @ts-expect-error
131
+ __scopeProgress,
132
+ value: valueProp,
133
+ max: maxProp,
134
+ getValueLabel = defaultGetValueLabel,
135
+ size = "$true",
136
+ ...progressProps
137
+ } = props,
138
+ max = isValidMaxNumber(maxProp) ? maxProp : DEFAULT_MAX,
139
+ value = isValidValueNumber(valueProp, max) ? Math.round(valueProp) : null,
140
+ valueLabel = isNumber(value) ? getValueLabel(value, max) : void 0,
141
+ [width, setWidth] = (0, import_react.useState)(0);
142
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ProgressProvider, {
143
+ scope: __scopeProgress,
144
+ value,
145
+ max,
146
+ width,
147
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(ProgressFrame, {
148
+ "aria-valuemax": max,
149
+ "aria-valuemin": 0,
150
+ "aria-valuenow": isNumber(value) ? value : void 0,
151
+ "aria-valuetext": valueLabel,
152
+ role: "progressbar",
153
+ "data-state": getProgressState(value, max),
154
+ "data-value": value ?? void 0,
155
+ "data-max": max,
156
+ ...(progressProps.unstyled !== !0 && {
157
+ size
158
+ }),
159
+ ...progressProps,
160
+ ...(!import_gui_core.isWeb && {
161
+ onLayout: e => {
162
+ const newWidth = Math.round(e.nativeEvent.layout.width);
163
+ newWidth !== width && setWidth(newWidth), progressProps.onLayout?.(e);
164
+ }
165
+ }),
166
+ ref: forwardedRef
167
+ })
168
+ });
169
+ }), {
170
+ Indicator: ProgressIndicator
171
+ });
@@ -0,0 +1,178 @@
1
+ "use strict";
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
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, {
15
+ get: () => from[key],
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ return to;
19
+ };
20
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
21
+ value: !0
22
+ }), mod);
23
+ var Progress_exports = {};
24
+ __export(Progress_exports, {
25
+ Progress: () => Progress,
26
+ ProgressFrame: () => ProgressFrame,
27
+ ProgressIndicator: () => ProgressIndicator,
28
+ ProgressIndicatorFrame: () => ProgressIndicatorFrame,
29
+ createProgressScope: () => createProgressScope
30
+ });
31
+ module.exports = __toCommonJS(Progress_exports);
32
+ var import_jsx_runtime = require("react/jsx-runtime"),
33
+ import_gui_core = require("@hanzo/gui-core"),
34
+ import_gui_create_context = require("@hanzo/gui-create-context"),
35
+ import_gui_get_token = require("@hanzo/gui-get-token"),
36
+ import_gui_helpers = require("@hanzo/gui-helpers"),
37
+ import_gui_stacks = require("@hanzo/gui-stacks"),
38
+ import_react = require("react"),
39
+ PROGRESS_NAME = "Progress",
40
+ [createProgressContext, createProgressScope] = (0, import_gui_create_context.createContextScope)(PROGRESS_NAME),
41
+ [ProgressProvider, useProgressContext] = createProgressContext(PROGRESS_NAME),
42
+ INDICATOR_NAME = "ProgressIndicator",
43
+ ProgressIndicatorFrame = (0, import_gui_core.styled)(import_gui_stacks.YStack, {
44
+ name: INDICATOR_NAME,
45
+ variants: {
46
+ unstyled: {
47
+ false: {
48
+ height: "100%",
49
+ width: "100%",
50
+ backgroundColor: "$background"
51
+ }
52
+ }
53
+ },
54
+ defaultVariants: {
55
+ unstyled: process.env.HANZO_GUI_HEADLESS === "1"
56
+ }
57
+ }),
58
+ ProgressIndicator = ProgressIndicatorFrame.styleable(function (props, forwardedRef) {
59
+ var {
60
+ __scopeProgress,
61
+ transition,
62
+ ...indicatorProps
63
+ } = props,
64
+ context = useProgressContext(INDICATOR_NAME, __scopeProgress),
65
+ _context_value,
66
+ progressRatio = ((_context_value = context.value) !== null && _context_value !== void 0 ? _context_value : 0) / context.max,
67
+ x;
68
+ if (import_gui_core.isWeb) x = `${-100 + progressRatio * 50}%`;else {
69
+ var baseWidth = context.width || 0;
70
+ x = Math.ceil(-baseWidth * (2 - progressRatio));
71
+ }
72
+ var _context_value1;
73
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ProgressIndicatorFrame, {
74
+ "data-state": getProgressState(context.value, context.max),
75
+ "data-value": (_context_value1 = context.value) !== null && _context_value1 !== void 0 ? _context_value1 : void 0,
76
+ "data-max": context.max,
77
+ x,
78
+ width: "200%",
79
+ ...(!props.unstyled && {
80
+ animateOnly: ["transform"],
81
+ // on native, hide until we have width measurement
82
+ ...(!import_gui_core.isWeb && context.width === 0 && {
83
+ opacity: 0
84
+ })
85
+ }),
86
+ ...indicatorProps,
87
+ ref: forwardedRef,
88
+ transition: !import_gui_core.isWeb && !context.width ? null : transition
89
+ });
90
+ });
91
+ function defaultGetValueLabel(value, max) {
92
+ return `${Math.round(value / max * 100)}%`;
93
+ }
94
+ function getProgressState(value, maxValue) {
95
+ return value == null ? "indeterminate" : value === maxValue ? "complete" : "loading";
96
+ }
97
+ function isNumber(value) {
98
+ return typeof value == "number";
99
+ }
100
+ function isValidMaxNumber(max) {
101
+ return isNumber(max) && !Number.isNaN(max) && max > 0;
102
+ }
103
+ function isValidValueNumber(value, max) {
104
+ return isNumber(value) && !Number.isNaN(value) && value <= max && value >= 0;
105
+ }
106
+ var DEFAULT_MAX = 100,
107
+ ProgressFrame = (0, import_gui_core.styled)(import_gui_stacks.YStack, {
108
+ name: "Progress",
109
+ variants: {
110
+ unstyled: {
111
+ false: {
112
+ borderRadius: 1e5,
113
+ overflow: "hidden",
114
+ backgroundColor: "$background"
115
+ }
116
+ },
117
+ size: {
118
+ "...size": function (val) {
119
+ var size = Math.round((0, import_gui_core.getVariableValue)((0, import_gui_get_token.getSize)(val)) * 0.25);
120
+ return {
121
+ height: size,
122
+ minWidth: (0, import_gui_core.getVariableValue)(size) * 20,
123
+ width: "100%"
124
+ };
125
+ }
126
+ }
127
+ },
128
+ defaultVariants: {
129
+ unstyled: process.env.HANZO_GUI_HEADLESS === "1"
130
+ }
131
+ }),
132
+ Progress = (0, import_gui_helpers.withStaticProperties)(ProgressFrame.styleable(function (props, forwardedRef) {
133
+ var {
134
+ // @ts-expect-error
135
+ __scopeProgress,
136
+ value: valueProp,
137
+ max: maxProp,
138
+ getValueLabel = defaultGetValueLabel,
139
+ size = "$true",
140
+ ...progressProps
141
+ } = props,
142
+ max = isValidMaxNumber(maxProp) ? maxProp : DEFAULT_MAX,
143
+ value = isValidValueNumber(valueProp, max) ? Math.round(valueProp) : null,
144
+ valueLabel = isNumber(value) ? getValueLabel(value, max) : void 0,
145
+ [width, setWidth] = (0, import_react.useState)(0);
146
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ProgressProvider, {
147
+ scope: __scopeProgress,
148
+ value,
149
+ max,
150
+ width,
151
+ children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(ProgressFrame, {
152
+ "aria-valuemax": max,
153
+ "aria-valuemin": 0,
154
+ "aria-valuenow": isNumber(value) ? value : void 0,
155
+ "aria-valuetext": valueLabel,
156
+ // @ts-ignore
157
+ role: "progressbar",
158
+ "data-state": getProgressState(value, max),
159
+ "data-value": value ?? void 0,
160
+ "data-max": max,
161
+ ...(progressProps.unstyled !== !0 && {
162
+ size
163
+ }),
164
+ ...progressProps,
165
+ ...(!import_gui_core.isWeb && {
166
+ onLayout: function (e) {
167
+ var _progressProps_onLayout,
168
+ newWidth = Math.round(e.nativeEvent.layout.width);
169
+ newWidth !== width && setWidth(newWidth), (_progressProps_onLayout = progressProps.onLayout) === null || _progressProps_onLayout === void 0 || _progressProps_onLayout.call(progressProps, e);
170
+ }
171
+ }),
172
+ ref: forwardedRef
173
+ })
174
+ });
175
+ }), {
176
+ Indicator: ProgressIndicator
177
+ });
178
+ //# sourceMappingURL=Progress.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","Progress_exports","__export","Progress","ProgressFrame","ProgressIndicator","ProgressIndicatorFrame","createProgressScope","module","exports","import_jsx_runtime","require","import_gui_core","import_gui_create_context","import_gui_get_token","import_gui_helpers","import_gui_stacks","import_react","PROGRESS_NAME","createProgressContext","createContextScope","ProgressProvider","useProgressContext","INDICATOR_NAME","styled","YStack","name","variants","unstyled","false","height","width","backgroundColor","defaultVariants","process","env","HANZO_GUI_HEADLESS","styleable","props","forwardedRef","__scopeProgress","transition","indicatorProps","context","_context_value","progressRatio","max","x","isWeb","baseWidth","Math","ceil","_context_value1","jsx","getProgressState","animateOnly","opacity","ref","defaultGetValueLabel","round","maxValue","isNumber","isValidMaxNumber","Number","isNaN","isValidValueNumber","DEFAULT_MAX","borderRadius","overflow","size","...size","val","getVariableValue","getSize","minWidth","withStaticProperties","valueProp","maxProp","getValueLabel","progressProps","valueLabel","setWidth","useState","scope","children","role","onLayout","e","_progressProps_onLayout","newWidth","nativeEvent","layout","call"],"sources":["../../src/Progress.tsx"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,gBAAA;AAAAC,QAAA,CAAAD,gBAAA;EAAAE,QAAA,EAAAA,CAAA,KAAAA,QAAA;EAAAC,aAAA,EAAAA,CAAA,KAAAA,aAAA;EAAAC,iBAAA,EAAAA,CAAA,KAAAA,iBAAA;EAAAC,sBAAA,EAAAA,CAAA,KAAAA,sBAAA;EAAAC,mBAAA,EAAAA,CAAA,KAAAA;AAAA;AAIAC,MAAA,CAAAC,OAAA,GAAAb,YAAgD,CAAAK,gBAAA;AAQhD,IAAAS,kBAAsB,GAAAC,OAAA,oBAEf;EAAAC,eAAuB,GAAAD,OAAmB,kBAAI;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AhC,gBAAC;MACC8D,KAAC,EAAA3C,eAAA;MAAAxC,KAAA;MAAA8C,GAAA;MACgBf,KACf;MAAeqD,QACf,iBAAe,IAAS1E,kBAAiB,CAAA2C,GAAA,EAAAjD,aAAA;QAAA,eACzC,EAAA0C,GAAgB;QAAA,eAEX;QAAA,eACL,EAAYe,QAAA,CAAA7D,KAAA,IAAiBA,KAAO,GAAG;QAAA,gBAC3B,EAAAgF,UAAS;QAAA;QACXK,IACT,EAAI,aAAc;QAAqB,YACtC,EAAA/B,gBAAA,CAAAtD,KAAA,EAAA8C,GAAA;QAAA,YACF,EAAA9C,KAAA;QAAA,UACI,EAAA8C,GAAA;QAAA,IACHiC,aAAK,CAAAnD,QAAA,MAAS;UAAAyC;QAEX;QACA,GAAAU,aAAI;QAGsB,KAC5BnE,eAAA,CAAAoC,KAAA;UACFsC,QAAA,WAAAA,CAAAC,CAAA;YACA,IAAKC,uBAAA;cAAAC,QAAA,GAAAvC,IAAA,CAAAS,KAAA,CAAA4B,CAAA,CAAAG,WAAA,CAAAC,MAAA,CAAA5D,KAAA;YAAA0D,QAAA,KAAA1D,KAAA,IAAAkD,QAAA,CAAAQ,QAAA,IAAAD,uBAAA,GAAAT,aAAA,CAAAO,QAAA,cAAAE,uBAAA,eAAAA,uBAAA,CAAAI,IAAA,CAAAb,aAAA,EAAAQ,CAAA;UAET;QAEH;QACD9B,GAAA,EAAAlB;MACE;IACF;EACF","ignoreList":[]}
@@ -0,0 +1,18 @@
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") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
7
+ get: () => from[key],
8
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
9
+ });
10
+ return to;
11
+ },
12
+ __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
13
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
14
+ value: !0
15
+ }), mod);
16
+ var index_exports = {};
17
+ module.exports = __toCommonJS(index_exports);
18
+ __reExport(index_exports, require("./Progress.cjs"), module.exports);
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __copyProps = (to, from, except, desc) => {
8
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
9
+ get: () => from[key],
10
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
11
+ });
12
+ return to;
13
+ },
14
+ __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
16
+ value: !0
17
+ }), mod);
18
+ var index_exports = {};
19
+ module.exports = __toCommonJS(index_exports);
20
+ __reExport(index_exports, require("./Progress.native.js"), module.exports);
21
+ //# sourceMappingURL=index.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","index_exports","module","exports"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,aAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAP,YAAc,CAAAK,aAAA","ignoreList":[]}
@@ -0,0 +1,144 @@
1
+ import { getVariableValue, isWeb, styled } from "@hanzo/gui-core";
2
+ import { createContextScope } from "@hanzo/gui-create-context";
3
+ import { getSize } from "@hanzo/gui-get-token";
4
+ import { withStaticProperties } from "@hanzo/gui-helpers";
5
+ import { YStack } from "@hanzo/gui-stacks";
6
+ import { useState } from "react";
7
+ import { jsx } from "react/jsx-runtime";
8
+ const PROGRESS_NAME = "Progress",
9
+ [createProgressContext, createProgressScope] = createContextScope(PROGRESS_NAME),
10
+ [ProgressProvider, useProgressContext] = createProgressContext(PROGRESS_NAME),
11
+ INDICATOR_NAME = "ProgressIndicator",
12
+ ProgressIndicatorFrame = styled(YStack, {
13
+ name: INDICATOR_NAME,
14
+ variants: {
15
+ unstyled: {
16
+ false: {
17
+ height: "100%",
18
+ width: "100%",
19
+ backgroundColor: "$background"
20
+ }
21
+ }
22
+ },
23
+ defaultVariants: {
24
+ unstyled: process.env.HANZO_GUI_HEADLESS === "1"
25
+ }
26
+ }),
27
+ ProgressIndicator = ProgressIndicatorFrame.styleable(function (props, forwardedRef) {
28
+ const {
29
+ __scopeProgress,
30
+ transition,
31
+ ...indicatorProps
32
+ } = props,
33
+ context = useProgressContext(INDICATOR_NAME, __scopeProgress),
34
+ progressRatio = (context.value ?? 0) / context.max;
35
+ let x;
36
+ if (isWeb) x = `${-100 + progressRatio * 50}%`;else {
37
+ const baseWidth = context.width || 0;
38
+ x = Math.ceil(-baseWidth * (2 - progressRatio));
39
+ }
40
+ return /* @__PURE__ */jsx(ProgressIndicatorFrame, {
41
+ "data-state": getProgressState(context.value, context.max),
42
+ "data-value": context.value ?? void 0,
43
+ "data-max": context.max,
44
+ x,
45
+ width: "200%",
46
+ ...(!props.unstyled && {
47
+ animateOnly: ["transform"],
48
+ // on native, hide until we have width measurement
49
+ ...(!isWeb && context.width === 0 && {
50
+ opacity: 0
51
+ })
52
+ }),
53
+ ...indicatorProps,
54
+ ref: forwardedRef,
55
+ transition: !isWeb && !context.width ? null : transition
56
+ });
57
+ });
58
+ function defaultGetValueLabel(value, max) {
59
+ return `${Math.round(value / max * 100)}%`;
60
+ }
61
+ function getProgressState(value, maxValue) {
62
+ return value == null ? "indeterminate" : value === maxValue ? "complete" : "loading";
63
+ }
64
+ function isNumber(value) {
65
+ return typeof value == "number";
66
+ }
67
+ function isValidMaxNumber(max) {
68
+ return isNumber(max) && !Number.isNaN(max) && max > 0;
69
+ }
70
+ function isValidValueNumber(value, max) {
71
+ return isNumber(value) && !Number.isNaN(value) && value <= max && value >= 0;
72
+ }
73
+ const DEFAULT_MAX = 100,
74
+ ProgressFrame = styled(YStack, {
75
+ name: "Progress",
76
+ variants: {
77
+ unstyled: {
78
+ false: {
79
+ borderRadius: 1e5,
80
+ overflow: "hidden",
81
+ backgroundColor: "$background"
82
+ }
83
+ },
84
+ size: {
85
+ "...size": val => {
86
+ const size = Math.round(getVariableValue(getSize(val)) * 0.25);
87
+ return {
88
+ height: size,
89
+ minWidth: getVariableValue(size) * 20,
90
+ width: "100%"
91
+ };
92
+ }
93
+ }
94
+ },
95
+ defaultVariants: {
96
+ unstyled: process.env.HANZO_GUI_HEADLESS === "1"
97
+ }
98
+ }),
99
+ Progress = withStaticProperties(ProgressFrame.styleable(function (props, forwardedRef) {
100
+ const {
101
+ // @ts-expect-error
102
+ __scopeProgress,
103
+ value: valueProp,
104
+ max: maxProp,
105
+ getValueLabel = defaultGetValueLabel,
106
+ size = "$true",
107
+ ...progressProps
108
+ } = props,
109
+ max = isValidMaxNumber(maxProp) ? maxProp : DEFAULT_MAX,
110
+ value = isValidValueNumber(valueProp, max) ? Math.round(valueProp) : null,
111
+ valueLabel = isNumber(value) ? getValueLabel(value, max) : void 0,
112
+ [width, setWidth] = useState(0);
113
+ return /* @__PURE__ */jsx(ProgressProvider, {
114
+ scope: __scopeProgress,
115
+ value,
116
+ max,
117
+ width,
118
+ children: /* @__PURE__ */jsx(ProgressFrame, {
119
+ "aria-valuemax": max,
120
+ "aria-valuemin": 0,
121
+ "aria-valuenow": isNumber(value) ? value : void 0,
122
+ "aria-valuetext": valueLabel,
123
+ role: "progressbar",
124
+ "data-state": getProgressState(value, max),
125
+ "data-value": value ?? void 0,
126
+ "data-max": max,
127
+ ...(progressProps.unstyled !== !0 && {
128
+ size
129
+ }),
130
+ ...progressProps,
131
+ ...(!isWeb && {
132
+ onLayout: e => {
133
+ const newWidth = Math.round(e.nativeEvent.layout.width);
134
+ newWidth !== width && setWidth(newWidth), progressProps.onLayout?.(e);
135
+ }
136
+ }),
137
+ ref: forwardedRef
138
+ })
139
+ });
140
+ }), {
141
+ Indicator: ProgressIndicator
142
+ });
143
+ export { Progress, ProgressFrame, ProgressIndicator, ProgressIndicatorFrame, createProgressScope };
144
+ //# sourceMappingURL=Progress.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["getVariableValue","isWeb","styled","createContextScope","getSize","withStaticProperties","YStack","useState","jsx","PROGRESS_NAME","createProgressContext","createProgressScope","ProgressProvider","useProgressContext","INDICATOR_NAME","ProgressIndicatorFrame","name","variants","unstyled","false","height","width","backgroundColor","defaultVariants","process","env","HANZO_GUI_HEADLESS","ProgressIndicator","styleable","props","forwardedRef","__scopeProgress","transition","indicatorProps","context","progressRatio","value","max","x","baseWidth","Math","ceil","getProgressState","animateOnly","opacity","ref","defaultGetValueLabel","round","maxValue","isNumber","isValidMaxNumber","Number","isNaN","isValidValueNumber","DEFAULT_MAX","ProgressFrame","borderRadius","overflow","size","val","minWidth","Progress","valueProp","maxProp","getValueLabel","progressProps","valueLabel","setWidth","scope","children","role","onLayout","e","newWidth","nativeEvent","layout","Indicator"],"sources":["../../src/Progress.tsx"],"sourcesContent":[null],"mappings":"AAIA,SAASA,gBAAA,EAAkBC,KAAA,EAAOC,MAAA,QAAc;AAEhD,SAASC,kBAAA,QAA0B;AACnC,SAASC,OAAA,QAAe;AACxB,SAASC,oBAAA,QAA4B;AACrC,SAASC,MAAA,QAAc;AACvB,SAASC,QAAA,QAAgB;AAoErB,SAAAC,GAAA;AAlEJ,MAAMC,aAAA,GAAgB;E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