@number10/jsx-components 5.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 +667 -0
- package/README.md +43 -0
- package/dist/Accordion.cjs +1 -0
- package/dist/Accordion.d.ts +43 -0
- package/dist/Accordion.d.ts.map +1 -0
- package/dist/Accordion.js +71 -0
- package/dist/Accordion.test.d.ts +2 -0
- package/dist/Accordion.test.d.ts.map +1 -0
- package/dist/ActivityIndicator.cjs +1 -0
- package/dist/ActivityIndicator.d.ts +21 -0
- package/dist/ActivityIndicator.d.ts.map +1 -0
- package/dist/ActivityIndicator.js +133 -0
- package/dist/AlertDialog.cjs +1 -0
- package/dist/AlertDialog.d.ts +53 -0
- package/dist/AlertDialog.d.ts.map +1 -0
- package/dist/AlertDialog.js +76 -0
- package/dist/Badge.cjs +1 -0
- package/dist/Badge.d.ts +96 -0
- package/dist/Badge.d.ts.map +1 -0
- package/dist/Badge.js +238 -0
- package/dist/Badge.test.d.ts +2 -0
- package/dist/Badge.test.d.ts.map +1 -0
- package/dist/BottomSheet.cjs +1 -0
- package/dist/BottomSheet.d.ts +72 -0
- package/dist/BottomSheet.d.ts.map +1 -0
- package/dist/BottomSheet.js +132 -0
- package/dist/Button.cjs +1 -0
- package/dist/Button.d.ts +61 -0
- package/dist/Button.d.ts.map +1 -0
- package/dist/Button.js +251 -0
- package/dist/Checkbox.cjs +1 -0
- package/dist/Checkbox.d.ts +40 -0
- package/dist/Checkbox.d.ts.map +1 -0
- package/dist/Checkbox.js +84 -0
- package/dist/Checkbox.test.d.ts +2 -0
- package/dist/Checkbox.test.d.ts.map +1 -0
- package/dist/ColorPicker.cjs +1 -0
- package/dist/ColorPicker.d.ts +48 -0
- package/dist/ColorPicker.d.ts.map +1 -0
- package/dist/ColorPicker.js +256 -0
- package/dist/DebugPanel.cjs +1 -0
- package/dist/DebugPanel.d.ts +63 -0
- package/dist/DebugPanel.d.ts.map +1 -0
- package/dist/DebugPanel.js +116 -0
- package/dist/Dialog.cjs +1 -0
- package/dist/Dialog.d.ts +59 -0
- package/dist/Dialog.d.ts.map +1 -0
- package/dist/Dialog.js +142 -0
- package/dist/Divider.cjs +1 -0
- package/dist/Divider.d.ts +19 -0
- package/dist/Divider.d.ts.map +1 -0
- package/dist/Divider.js +15 -0
- package/dist/Divider.test.d.ts +2 -0
- package/dist/Divider.test.d.ts.map +1 -0
- package/dist/Dropdown.cjs +1 -0
- package/dist/Dropdown.d.ts +35 -0
- package/dist/Dropdown.d.ts.map +1 -0
- package/dist/Dropdown.js +222 -0
- package/dist/Icon.cjs +1 -0
- package/dist/Icon.d.ts +71 -0
- package/dist/Icon.d.ts.map +1 -0
- package/dist/Icon.js +57 -0
- package/dist/Icon.test.d.ts +2 -0
- package/dist/Icon.test.d.ts.map +1 -0
- package/dist/Image.cjs +1 -0
- package/dist/Image.d.ts +10 -0
- package/dist/Image.d.ts.map +1 -0
- package/dist/Image.js +18 -0
- package/dist/Joystick.cjs +1 -0
- package/dist/Joystick.d.ts +32 -0
- package/dist/Joystick.d.ts.map +1 -0
- package/dist/Joystick.js +185 -0
- package/dist/ListBox.cjs +1 -0
- package/dist/ListBox.d.ts +67 -0
- package/dist/ListBox.d.ts.map +1 -0
- package/dist/ListBox.js +104 -0
- package/dist/ListBox.test.d.ts +2 -0
- package/dist/ListBox.test.d.ts.map +1 -0
- package/dist/MenuButton.cjs +1 -0
- package/dist/MenuButton.d.ts +33 -0
- package/dist/MenuButton.d.ts.map +1 -0
- package/dist/MenuButton.js +63 -0
- package/dist/Modal.cjs +1 -0
- package/dist/Modal.d.ts +27 -0
- package/dist/Modal.d.ts.map +1 -0
- package/dist/Modal.js +174 -0
- package/dist/Modal.test.d.ts +2 -0
- package/dist/Modal.test.d.ts.map +1 -0
- package/dist/NineSlice.cjs +1 -0
- package/dist/NineSlice.d.ts +40 -0
- package/dist/NineSlice.d.ts.map +1 -0
- package/dist/NineSlice.js +314 -0
- package/dist/NineSlice.props.test.d.ts +2 -0
- package/dist/NineSlice.props.test.d.ts.map +1 -0
- package/dist/NineSlice.test.d.ts +2 -0
- package/dist/NineSlice.test.d.ts.map +1 -0
- package/dist/NineSliceButton.cjs +1 -0
- package/dist/NineSliceButton.d.ts +94 -0
- package/dist/NineSliceButton.d.ts.map +1 -0
- package/dist/NineSliceButton.js +61 -0
- package/dist/NineSliceButton.test.d.ts +2 -0
- package/dist/NineSliceButton.test.d.ts.map +1 -0
- package/dist/NumberInput.cjs +1 -0
- package/dist/NumberInput.d.ts +90 -0
- package/dist/NumberInput.d.ts.map +1 -0
- package/dist/NumberInput.js +222 -0
- package/dist/NumberInput.test.d.ts +2 -0
- package/dist/NumberInput.test.d.ts.map +1 -0
- package/dist/PalettePicker.cjs +1 -0
- package/dist/PalettePicker.d.ts +49 -0
- package/dist/PalettePicker.d.ts.map +1 -0
- package/dist/PalettePicker.js +152 -0
- package/dist/PalettePicker.test.d.ts +2 -0
- package/dist/PalettePicker.test.d.ts.map +1 -0
- package/dist/Popover.cjs +1 -0
- package/dist/Popover.d.ts +95 -0
- package/dist/Popover.d.ts.map +1 -0
- package/dist/Popover.js +267 -0
- package/dist/Portal.cjs +1 -0
- package/dist/Portal.d.ts +30 -0
- package/dist/Portal.d.ts.map +1 -0
- package/dist/Portal.js +64 -0
- package/dist/Portal.test.d.ts +2 -0
- package/dist/Portal.test.d.ts.map +1 -0
- package/dist/ProgressBar.cjs +1 -0
- package/dist/ProgressBar.d.ts +61 -0
- package/dist/ProgressBar.d.ts.map +1 -0
- package/dist/ProgressBar.js +80 -0
- package/dist/ProgressBar.test.d.ts +2 -0
- package/dist/ProgressBar.test.d.ts.map +1 -0
- package/dist/ProgressView.cjs +1 -0
- package/dist/ProgressView.d.ts +37 -0
- package/dist/ProgressView.d.ts.map +1 -0
- package/dist/ProgressView.js +71 -0
- package/dist/RadioButton.cjs +1 -0
- package/dist/RadioButton.d.ts +21 -0
- package/dist/RadioButton.d.ts.map +1 -0
- package/dist/RadioButton.js +53 -0
- package/dist/RadioGroup.cjs +1 -0
- package/dist/RadioGroup.d.ts +26 -0
- package/dist/RadioGroup.d.ts.map +1 -0
- package/dist/RadioGroup.js +32 -0
- package/dist/RatingBar.cjs +1 -0
- package/dist/RatingBar.d.ts +24 -0
- package/dist/RatingBar.d.ts.map +1 -0
- package/dist/RatingBar.js +84 -0
- package/dist/ScrollSlider.cjs +1 -0
- package/dist/ScrollSlider.d.ts +48 -0
- package/dist/ScrollSlider.d.ts.map +1 -0
- package/dist/ScrollSlider.js +93 -0
- package/dist/ScrollView.cjs +1 -0
- package/dist/ScrollView.d.ts +121 -0
- package/dist/ScrollView.d.ts.map +1 -0
- package/dist/ScrollView.js +541 -0
- package/dist/ScrollView.test.d.ts +2 -0
- package/dist/ScrollView.test.d.ts.map +1 -0
- package/dist/SegmentedControl.cjs +1 -0
- package/dist/SegmentedControl.d.ts +50 -0
- package/dist/SegmentedControl.d.ts.map +1 -0
- package/dist/SegmentedControl.js +201 -0
- package/dist/SegmentedControl.test.d.ts +2 -0
- package/dist/SegmentedControl.test.d.ts.map +1 -0
- package/dist/Sidebar.cjs +1 -0
- package/dist/Sidebar.d.ts +36 -0
- package/dist/Sidebar.d.ts.map +1 -0
- package/dist/Sidebar.js +122 -0
- package/dist/Slider.cjs +1 -0
- package/dist/Slider.d.ts +80 -0
- package/dist/Slider.d.ts.map +1 -0
- package/dist/Slider.js +233 -0
- package/dist/Tabs.cjs +1 -0
- package/dist/Tabs.d.ts +23 -0
- package/dist/Tabs.d.ts.map +1 -0
- package/dist/Tabs.js +101 -0
- package/dist/TextInput.cjs +17 -0
- package/dist/TextInput.d.ts +82 -0
- package/dist/TextInput.d.ts.map +1 -0
- package/dist/TextInput.js +441 -0
- package/dist/Toast.cjs +1 -0
- package/dist/Toast.d.ts +66 -0
- package/dist/Toast.d.ts.map +1 -0
- package/dist/Toast.js +188 -0
- package/dist/Toast.test.d.ts +2 -0
- package/dist/Toast.test.d.ts.map +1 -0
- package/dist/Toggle.cjs +1 -0
- package/dist/Toggle.d.ts +14 -0
- package/dist/Toggle.d.ts.map +1 -0
- package/dist/Toggle.js +135 -0
- package/dist/Toolbar.cjs +1 -0
- package/dist/Toolbar.d.ts +129 -0
- package/dist/Toolbar.d.ts.map +1 -0
- package/dist/Toolbar.js +159 -0
- package/dist/Toolbar.test.d.ts +2 -0
- package/dist/Toolbar.test.d.ts.map +1 -0
- package/dist/TransformOriginView.cjs +1 -0
- package/dist/TransformOriginView.d.ts +8 -0
- package/dist/TransformOriginView.d.ts.map +1 -0
- package/dist/TransformOriginView.js +38 -0
- package/dist/WheelPicker.cjs +1 -0
- package/dist/WheelPicker.d.ts +58 -0
- package/dist/WheelPicker.d.ts.map +1 -0
- package/dist/WheelPicker.js +167 -0
- package/dist/WrapText.cjs +1 -0
- package/dist/WrapText.d.ts +83 -0
- package/dist/WrapText.d.ts.map +1 -0
- package/dist/WrapText.js +93 -0
- package/dist/WrapText.test.d.ts +2 -0
- package/dist/WrapText.test.d.ts.map +1 -0
- package/dist/contrast-slot-map.d.ts +33 -0
- package/dist/contrast-slot-map.d.ts.map +1 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +64 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +54 -0
- package/dist/primitives/Image.cjs +1 -0
- package/dist/primitives/Image.d.ts +11 -0
- package/dist/primitives/Image.d.ts.map +1 -0
- package/dist/primitives/Image.js +7 -0
- package/dist/primitives/Sprite.cjs +1 -0
- package/dist/primitives/Sprite.d.ts +11 -0
- package/dist/primitives/Sprite.d.ts.map +1 -0
- package/dist/primitives/Sprite.js +7 -0
- package/dist/primitives/Text.cjs +1 -0
- package/dist/primitives/Text.d.ts +14 -0
- package/dist/primitives/Text.d.ts.map +1 -0
- package/dist/primitives/Text.js +15 -0
- package/dist/primitives/VectorDrawContent.cjs +1 -0
- package/dist/primitives/VectorDrawContent.d.ts +3 -0
- package/dist/primitives/VectorDrawContent.d.ts.map +1 -0
- package/dist/primitives/VectorDrawContent.js +7 -0
- package/dist/primitives/View.cjs +1 -0
- package/dist/primitives/View.d.ts +13 -0
- package/dist/primitives/View.d.ts.map +1 -0
- package/dist/primitives/View.js +7 -0
- package/dist/primitives/index.d.ts +13 -0
- package/dist/primitives/index.d.ts.map +1 -0
- package/dist/primitives/primitives.test.d.ts +2 -0
- package/dist/primitives/primitives.test.d.ts.map +1 -0
- package/dist/primitives.cjs +1 -0
- package/dist/primitives.d.ts +2 -0
- package/dist/primitives.js +6 -0
- package/dist/theme-defaults.cjs +1 -0
- package/dist/theme-defaults.d.ts +12 -0
- package/dist/theme-defaults.d.ts.map +1 -0
- package/dist/theme-defaults.js +1288 -0
- package/dist/theme-defaults.test.d.ts +2 -0
- package/dist/theme-defaults.test.d.ts.map +1 -0
- package/dist/theme-types.cjs +0 -0
- package/dist/theme-types.d.ts +708 -0
- package/dist/theme-types.d.ts.map +1 -0
- package/dist/theme-types.js +0 -0
- package/dist/useOverlayPresence.cjs +1 -0
- package/dist/useOverlayPresence.d.ts +24 -0
- package/dist/useOverlayPresence.d.ts.map +1 -0
- package/dist/useOverlayPresence.js +19 -0
- package/package.json +83 -0
package/dist/Modal.js
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { View as e } from "./primitives/View.js";
|
|
2
|
+
import "./primitives.js";
|
|
3
|
+
import { Portal as t } from "./Portal.js";
|
|
4
|
+
import { useOverlayPresence as n } from "./useOverlayPresence.js";
|
|
5
|
+
import { KNOWN_COMPONENTS as r, applyEffect as i, getGlobalThemeDefaults as a, registerComponentDefaultsIfMissing as o, resolveComponentTheme as s, stopAnimationEffect as c, useCallback as l, useEffect as u, useRef as d, useTheme as f, useViewportSize as p } from "@number10/jsx-core";
|
|
6
|
+
import { Fragment as m, jsx as h, jsxs as g } from "@number10/jsx-core/jsx-runtime";
|
|
7
|
+
//#region src/Modal.tsx
|
|
8
|
+
function _(e, t) {
|
|
9
|
+
if (!e || typeof e != "object") return;
|
|
10
|
+
let n = e;
|
|
11
|
+
if (typeof n.setVisible == "function") {
|
|
12
|
+
n.setVisible(t);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
"visible" in n && (n.visible = t);
|
|
16
|
+
}
|
|
17
|
+
o("Modal", {
|
|
18
|
+
backdropColor: 0,
|
|
19
|
+
backdropOpacity: .5,
|
|
20
|
+
openDuration: 320,
|
|
21
|
+
closeDuration: 260
|
|
22
|
+
});
|
|
23
|
+
function v(t) {
|
|
24
|
+
let n = p(), r = d(null), a = d(null), o = d(!1), s = d(!1), f = d(0), v = d(null), y = d(null), b = d(t.onOpen), x = d(t.onClosed), S = d(t.onRequestClose), C = l((e) => {
|
|
25
|
+
r.current = e;
|
|
26
|
+
}, []), w = l((e) => {
|
|
27
|
+
a.current = e;
|
|
28
|
+
}, []), T = l(() => {
|
|
29
|
+
v.current !== null && (window.clearTimeout(v.current), v.current = null);
|
|
30
|
+
}, []), E = l(() => {
|
|
31
|
+
y.current !== null && (window.clearTimeout(y.current), y.current = null);
|
|
32
|
+
}, []), D = l((e) => {
|
|
33
|
+
e && typeof e == "object" && c(e);
|
|
34
|
+
}, []);
|
|
35
|
+
return u(() => {
|
|
36
|
+
b.current = t.onOpen, x.current = t.onClosed, S.current = t.onRequestClose;
|
|
37
|
+
}, [
|
|
38
|
+
t.onClosed,
|
|
39
|
+
t.onOpen,
|
|
40
|
+
t.onRequestClose
|
|
41
|
+
]), u(() => {
|
|
42
|
+
t.show || (o.current = !1, s.current = !1);
|
|
43
|
+
}, [t.show]), u(() => {
|
|
44
|
+
let e = r.current, n = a.current;
|
|
45
|
+
if (!e || !n) return;
|
|
46
|
+
T(), E(), D(n), D(e);
|
|
47
|
+
let c = () => {
|
|
48
|
+
let r = ++f.current;
|
|
49
|
+
o.current = !0, s.current = !1, t.closeRequestedRef.current = !1, _(e, !0), _(n, !0), b.current?.();
|
|
50
|
+
let a = () => {
|
|
51
|
+
r === f.current && (T(), t.finishEnter());
|
|
52
|
+
};
|
|
53
|
+
return v.current = window.setTimeout(() => {
|
|
54
|
+
a();
|
|
55
|
+
}, t.openDurationMs), i(n, t.viewOpenEffect, {
|
|
56
|
+
time: t.openDurationMs,
|
|
57
|
+
onComplete: a
|
|
58
|
+
}), i(e, "fadeIn", { time: t.openDurationMs }), () => {
|
|
59
|
+
r === f.current && T();
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
if (t.show && t.phase === "entering" && !o.current) return c();
|
|
63
|
+
if (t.show && t.phase === "entered" && !o.current) return console.warn("[Modal] starting enter animation on entered phase (likely async portal timing)"), c();
|
|
64
|
+
if (!t.show && t.phase === "exiting" && !s.current) {
|
|
65
|
+
let r = ++f.current;
|
|
66
|
+
s.current = !0, _(e, !0), _(n, !0);
|
|
67
|
+
let a = () => {
|
|
68
|
+
r === f.current && (E(), _(e, !1), _(n, !1), t.finishExit(), (S.current !== void 0 || !t.closeRequestedRef.current) && x.current?.(), t.closeRequestedRef.current = !1);
|
|
69
|
+
};
|
|
70
|
+
return y.current = window.setTimeout(() => {
|
|
71
|
+
a();
|
|
72
|
+
}, t.closeDurationMs), i(n, t.viewCloseEffect, {
|
|
73
|
+
time: t.closeDurationMs,
|
|
74
|
+
onComplete: a
|
|
75
|
+
}), i(e, "fadeOut", { time: t.closeDurationMs }), () => {
|
|
76
|
+
r === f.current && E();
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}, [
|
|
80
|
+
E,
|
|
81
|
+
T,
|
|
82
|
+
t.closeDurationMs,
|
|
83
|
+
t.closeRequestedRef,
|
|
84
|
+
t.finishEnter,
|
|
85
|
+
t.finishExit,
|
|
86
|
+
t.openDurationMs,
|
|
87
|
+
t.phase,
|
|
88
|
+
t.show,
|
|
89
|
+
t.viewCloseEffect,
|
|
90
|
+
t.viewOpenEffect,
|
|
91
|
+
D
|
|
92
|
+
]), u(() => () => {
|
|
93
|
+
T(), E(), D(a.current), D(r.current);
|
|
94
|
+
}, [
|
|
95
|
+
E,
|
|
96
|
+
T,
|
|
97
|
+
D
|
|
98
|
+
]), /* @__PURE__ */ g(m, { children: [/* @__PURE__ */ h(e, {
|
|
99
|
+
ref: C,
|
|
100
|
+
width: n.width,
|
|
101
|
+
height: n.height,
|
|
102
|
+
backgroundColor: t.themedModal.backdropColor ?? 0,
|
|
103
|
+
alpha: t.themedModal.backdropOpacity ?? .5,
|
|
104
|
+
onTouch: (e) => {
|
|
105
|
+
e.stopPropagation(), t.closeOnBackdrop && t.requestClose();
|
|
106
|
+
},
|
|
107
|
+
onTouchMove: (e) => {
|
|
108
|
+
e.stopPropagation();
|
|
109
|
+
}
|
|
110
|
+
}), /* @__PURE__ */ h(e, {
|
|
111
|
+
width: n.width,
|
|
112
|
+
height: n.height,
|
|
113
|
+
direction: "row",
|
|
114
|
+
justifyContent: "center",
|
|
115
|
+
alignItems: "center",
|
|
116
|
+
children: /* @__PURE__ */ h(e, {
|
|
117
|
+
ref: w,
|
|
118
|
+
onTouch: (e) => e.stopPropagation(),
|
|
119
|
+
onTouchMove: (e) => e.stopPropagation(),
|
|
120
|
+
theme: t.nestedTheme,
|
|
121
|
+
children: t.children
|
|
122
|
+
})
|
|
123
|
+
})] });
|
|
124
|
+
}
|
|
125
|
+
function y(e) {
|
|
126
|
+
let i = f(), { props: o, nestedTheme: c } = s({
|
|
127
|
+
componentName: "Modal",
|
|
128
|
+
globalTheme: a(),
|
|
129
|
+
localTheme: i,
|
|
130
|
+
knownComponents: r
|
|
131
|
+
}), p = o, m = e.closeOnBackdrop ?? !0, g = e.closeOnEscape ?? !0, _ = p.openDuration ?? 320, y = p.closeDuration ?? 260, b = n(e.show), x = d(!1), S = e.viewOpenEffect ?? "fadeIn", C = e.viewCloseEffect ?? "fadeOut", w = l(() => {
|
|
132
|
+
if (x.current = !0, e.onRequestClose) {
|
|
133
|
+
e.onRequestClose();
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
e.onClosed?.();
|
|
137
|
+
}, [e.onClosed, e.onRequestClose]);
|
|
138
|
+
return u(() => {
|
|
139
|
+
if (!g || !e.show) return;
|
|
140
|
+
let t = (e) => {
|
|
141
|
+
e.key === "Escape" && w();
|
|
142
|
+
};
|
|
143
|
+
return window.addEventListener("keydown", t), () => window.removeEventListener("keydown", t);
|
|
144
|
+
}, [
|
|
145
|
+
g,
|
|
146
|
+
e.show,
|
|
147
|
+
w
|
|
148
|
+
]), b.isPresent ? /* @__PURE__ */ h(t, {
|
|
149
|
+
...e.key && { key: e.key },
|
|
150
|
+
depth: e.depth ?? 1e3,
|
|
151
|
+
blockEvents: !1,
|
|
152
|
+
children: /* @__PURE__ */ h(v, {
|
|
153
|
+
show: e.show,
|
|
154
|
+
phase: b.phase,
|
|
155
|
+
finishEnter: b.finishEnter,
|
|
156
|
+
finishExit: b.finishExit,
|
|
157
|
+
closeOnBackdrop: m,
|
|
158
|
+
themedModal: p,
|
|
159
|
+
nestedTheme: c,
|
|
160
|
+
openDurationMs: _,
|
|
161
|
+
closeDurationMs: y,
|
|
162
|
+
viewOpenEffect: S,
|
|
163
|
+
viewCloseEffect: C,
|
|
164
|
+
onOpen: e.onOpen,
|
|
165
|
+
onClosed: e.onClosed,
|
|
166
|
+
onRequestClose: e.onRequestClose,
|
|
167
|
+
requestClose: w,
|
|
168
|
+
closeRequestedRef: x,
|
|
169
|
+
children: e.children
|
|
170
|
+
})
|
|
171
|
+
}) : null;
|
|
172
|
+
}
|
|
173
|
+
//#endregion
|
|
174
|
+
export { y as Modal };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Modal.test.d.ts","sourceRoot":"","sources":["../src/Modal.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require(`./primitives/Image.cjs`),t=require(`./primitives/View.cjs`);require(`./primitives.cjs`);let n=require(`@number10/jsx-core`),r=require(`@number10/jsx-core/jsx-runtime`);function i(e,t,r,i,a,o){return(0,n.computeSourceSlices)(e,t,r,i,a,o).map(e=>({...e}))}function a(){return(0,n.getCurrentOrThrow)().surface?.capabilities?.has(`nineslice`)===!0}function o(e,t=!0){return!(e===`fallback`||!a()||!t)}function s(e,t,r){let i={...e,...t===void 0?{}:{key:t},...r===void 0?{}:{theme:r}};return(0,n.jsx)(n.PRIMITIVE_NODES.NineSlice,i)}function c(t,n,i,a,c,l,u,d,f,p,m){if(o(a))return s({texture:t,frame:n,tint:i,width:l,height:u,leftWidth:d,rightWidth:f,topHeight:p,bottomHeight:m,depth:0});let h=Math.max(0,l-d-f),g=Math.max(0,u-p-m),_=p===0&&m===0,v=(a,o,s,c,l,u)=>(0,r.jsx)(e.Image,{headless:!0,depth:0,x:s,y:c,originX:0,originY:0,texture:t,frame:n,tint:i,sourceRect:o,width:l,height:u,displayWidth:l,displayHeight:u},a);if(_){let e=c[3],t=c[4],n=c[5];return[v(`l`,e,0,0,d,u),v(`c`,t,d,0,h,u),v(`r`,n,l-f,0,f,u)]}let y=c[0],b=c[1],x=c[2],S=c[3],C=c[4],w=c[5],T=c[6],E=c[7],D=c[8];return[v(`tl`,y,0,0,d,p),v(`t`,b,d,0,h,p),v(`tr`,x,l-f,0,f,p),v(`l`,S,0,p,d,g),v(`c`,C,d,p,h,g),v(`r`,w,l-f,p,f,g),v(`bl`,T,0,u-m,d,m),v(`b`,E,d,u-m,h,m),v(`br`,D,l-f,u-m,f,m)]}function l(e,t){let r=(0,n.getCurrentOrThrow)().surface?.textureLoader,[i,a]=(0,n.useState)(null);return(0,n.useEffect)(()=>{if(!r)return;let n;if(t){let i=r.getFrameRect(e,t);i&&(n={w:i.width,h:i.height})}if(!n){let t=r.getTextureSize(e);t&&(n={w:t.width,h:t.height})}a(n??null)},[e,t,r]),i}function u(e){let{texture:t,frame:n,leftWidth:r,rightWidth:i,topHeight:a,bottomHeight:o,width:c,height:l,tint:u,theme:d,key:f}=e;return s({texture:t,frame:n,tint:u,leftWidth:r,rightWidth:i,topHeight:a,bottomHeight:o,width:c,height:l},f,d)}function d(a){if(o(a.renderMode,a.width!==void 0&&a.height!==void 0))return(0,r.jsx)(u,{...a});let{texture:s,frame:c,leftWidth:d,rightWidth:f,topHeight:p,bottomHeight:m,width:h,height:g,tint:_,theme:v,key:y}=a,b=p===0&&m===0,x=l(s,c),S=(0,n.useMemo)(()=>x?i(x.w,x.h,d,f,p,m):null,[x,d,f,p,m]);if(!S)return(0,r.jsx)(t.View,{width:h,height:g,theme:v},y);let C=typeof h==`number`?h:void 0,w=typeof g==`number`?g:void 0,T=C==null?void 0:C-d-f,E=w==null?void 0:w-p-m,D=(e,t,n)=>({texture:s,frame:c,tint:_,sourceRect:e,...t==null?{}:{displayWidth:t},...n==null?{}:{displayHeight:n}});if(b){let i=S[3],a=S[4],o=S[5];return(0,r.jsxs)(t.View,{direction:`row`,width:h,height:g,theme:v,children:[(0,n.createElement)(e.Image,{...D(i,d,w),width:d,height:`100%`,key:`l`}),(0,n.createElement)(e.Image,{...D(a,T,w),flex:1,height:`100%`,key:`c`}),(0,n.createElement)(e.Image,{...D(o,f,w),width:f,height:`100%`,key:`r`})]},y)}let O=S[0],k=S[1],A=S[2],j=S[3],M=S[4],N=S[5],P=S[6],F=S[7],I=S[8];return(0,r.jsxs)(t.View,{direction:`column`,width:h,height:g,theme:v,children:[(0,r.jsxs)(t.View,{direction:`row`,width:`fill`,height:p,children:[(0,n.createElement)(e.Image,{...D(O,d,p),width:d,height:p,key:`tl`}),(0,n.createElement)(e.Image,{...D(k,T,p),flex:1,height:p,key:`t`}),(0,n.createElement)(e.Image,{...D(A,f,p),width:f,height:p,key:`tr`})]},`row-t`),(0,r.jsxs)(t.View,{direction:`row`,width:`fill`,flex:1,children:[(0,n.createElement)(e.Image,{...D(j,d,E),width:d,height:`100%`,key:`l`}),(0,n.createElement)(e.Image,{...D(M,T,E),flex:1,height:`100%`,key:`c`}),(0,n.createElement)(e.Image,{...D(N,f,E),width:f,height:`100%`,key:`r`})]},`row-m`),(0,r.jsxs)(t.View,{direction:`row`,width:`fill`,height:m,children:[(0,n.createElement)(e.Image,{...D(P,d,m),width:d,height:m,key:`bl`}),(0,n.createElement)(e.Image,{...D(F,T,m),flex:1,height:m,key:`b`}),(0,n.createElement)(e.Image,{...D(I,f,m),width:f,height:m,key:`br`})]},`row-b`)]},y)}function f(e){let{texture:a,frame:o,leftWidth:s,rightWidth:u,topHeight:d,bottomHeight:f,width:p,height:m,tint:h,children:g,renderMode:_,alignItems:v=`start`,justifyContent:y=`start`,gap:b,padding:x,theme:S,key:C}=e,w=l(a,o),T=(0,n.useMemo)(()=>w?i(w.w,w.h,s,u,d,f):null,[w,s,u,d,f]),E={left:s+(x?.left??0),right:u+(x?.right??0),top:d+(x?.top??0),bottom:f+(x?.bottom??0)};return(0,r.jsxs)(t.View,{direction:`stack`,width:p,height:m,theme:S,children:[T?c(a,o,h,_,T,p,m,s,u,d,f):null,(0,r.jsx)(t.View,{direction:`column`,depth:1,width:`100%`,height:`100%`,alignItems:v,justifyContent:y,gap:b,padding:E,children:g})]},C)}function p(e){return e.children===void 0?(0,r.jsx)(d,{texture:e.texture,frame:e.frame,leftWidth:e.leftWidth,rightWidth:e.rightWidth,topHeight:e.topHeight??0,bottomHeight:e.bottomHeight??0,width:e.width,height:e.height,tint:e.tint,renderMode:e.renderMode,theme:e.theme},e.key):(0,r.jsx)(f,{texture:e.texture,frame:e.frame,leftWidth:e.leftWidth,rightWidth:e.rightWidth,topHeight:e.topHeight??0,bottomHeight:e.bottomHeight??0,width:e.width,height:e.height,tint:e.tint,renderMode:e.renderMode,children:e.children,alignItems:e.alignItems,justifyContent:e.justifyContent,gap:e.gap,padding:e.padding,theme:e.theme},e.key)}exports.NineSlice=p;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ChildrenType, EdgeInsets, GapInsets, SizeValue, VNodeLike } from '@number10/jsx-core';
|
|
2
|
+
import { PortablePartialTheme } from './theme-types';
|
|
3
|
+
type NineSliceAlignItems = 'start' | 'center' | 'end' | 'stretch';
|
|
4
|
+
type NineSliceJustifyContent = 'start' | 'center' | 'end' | 'space-between' | 'space-around' | 'space-evenly';
|
|
5
|
+
type NineSliceRenderMode = 'auto' | 'native' | 'fallback';
|
|
6
|
+
interface NineSliceBaseProps {
|
|
7
|
+
texture: string;
|
|
8
|
+
frame?: string | undefined;
|
|
9
|
+
leftWidth: number;
|
|
10
|
+
rightWidth: number;
|
|
11
|
+
topHeight?: number | undefined;
|
|
12
|
+
bottomHeight?: number | undefined;
|
|
13
|
+
tint?: number | undefined;
|
|
14
|
+
/** Select native vs fallback rendering explicitly for testing/debugging. */
|
|
15
|
+
renderMode?: NineSliceRenderMode | undefined;
|
|
16
|
+
theme?: PortablePartialTheme | undefined;
|
|
17
|
+
key?: string | number | undefined;
|
|
18
|
+
}
|
|
19
|
+
interface NineSliceDecorativeProps extends NineSliceBaseProps {
|
|
20
|
+
width?: SizeValue | undefined;
|
|
21
|
+
height?: SizeValue | undefined;
|
|
22
|
+
children?: undefined;
|
|
23
|
+
alignItems?: undefined;
|
|
24
|
+
justifyContent?: undefined;
|
|
25
|
+
gap?: undefined;
|
|
26
|
+
padding?: undefined;
|
|
27
|
+
}
|
|
28
|
+
interface NineSliceContentProps extends NineSliceBaseProps {
|
|
29
|
+
width: number;
|
|
30
|
+
height: number;
|
|
31
|
+
children: ChildrenType;
|
|
32
|
+
alignItems?: NineSliceAlignItems | undefined;
|
|
33
|
+
justifyContent?: NineSliceJustifyContent | undefined;
|
|
34
|
+
gap?: number | GapInsets | undefined;
|
|
35
|
+
padding?: EdgeInsets | undefined;
|
|
36
|
+
}
|
|
37
|
+
export type NineSliceProps = NineSliceDecorativeProps | NineSliceContentProps;
|
|
38
|
+
export declare function NineSlice(props: NineSliceProps): VNodeLike;
|
|
39
|
+
export {};
|
|
40
|
+
//# sourceMappingURL=NineSlice.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NineSlice.d.ts","sourceRoot":"","sources":["../src/NineSlice.tsx"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C;;;;;;;;;;;;GAYG;AAEH,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AU,qBAAsB,SAAQ,kBAAkB;IACxD,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,YAAY,CAAA;IACtB,UAAU,CAAC,EAAE,mBAAmB,GAAG,SAAS,CAAA;IAC5C,cAAc,CAAC,EAAE,uBAAuB,GAAG,SAAS,CAAA;IACpD,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,CAAA;IACpC,OAAO,CAAC,EAAE,UAAU,GAAG,SAAS,CAAA;CACjC;AAED,MAAM,MAAM,cAAc,GAAG,wBAAwB,GAAG,qBAAqB,CAAA;AA4Z7E,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,GAAG,SAAS,CAyC1D"}
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import { Image as e } from "./primitives/Image.js";
|
|
2
|
+
import { View as t } from "./primitives/View.js";
|
|
3
|
+
import "./primitives.js";
|
|
4
|
+
import { PRIMITIVE_NODES as n, computeSourceSlices as r, createElement as i, getCurrentOrThrow as a, jsx as o, useEffect as s, useMemo as c, useState as l } from "@number10/jsx-core";
|
|
5
|
+
import { jsx as u, jsxs as d } from "@number10/jsx-core/jsx-runtime";
|
|
6
|
+
//#region src/NineSlice.tsx
|
|
7
|
+
function f(e, t, n, i, a, o) {
|
|
8
|
+
return r(e, t, n, i, a, o).map((e) => ({ ...e }));
|
|
9
|
+
}
|
|
10
|
+
function p() {
|
|
11
|
+
return a().surface?.capabilities?.has("nineslice") === !0;
|
|
12
|
+
}
|
|
13
|
+
function m(e, t = !0) {
|
|
14
|
+
return !(e === "fallback" || !p() || !t);
|
|
15
|
+
}
|
|
16
|
+
function h(e, t, r) {
|
|
17
|
+
let i = {
|
|
18
|
+
...e,
|
|
19
|
+
...t === void 0 ? {} : { key: t },
|
|
20
|
+
...r === void 0 ? {} : { theme: r }
|
|
21
|
+
};
|
|
22
|
+
return o(n.NineSlice, i);
|
|
23
|
+
}
|
|
24
|
+
function g(t, n, r, i, a, o, s, c, l, d, f) {
|
|
25
|
+
if (m(i)) return h({
|
|
26
|
+
texture: t,
|
|
27
|
+
frame: n,
|
|
28
|
+
tint: r,
|
|
29
|
+
width: o,
|
|
30
|
+
height: s,
|
|
31
|
+
leftWidth: c,
|
|
32
|
+
rightWidth: l,
|
|
33
|
+
topHeight: d,
|
|
34
|
+
bottomHeight: f,
|
|
35
|
+
depth: 0
|
|
36
|
+
});
|
|
37
|
+
let p = Math.max(0, o - c - l), g = Math.max(0, s - d - f), _ = d === 0 && f === 0, v = (i, a, o, s, c, l) => /* @__PURE__ */ u(e, {
|
|
38
|
+
headless: !0,
|
|
39
|
+
depth: 0,
|
|
40
|
+
x: o,
|
|
41
|
+
y: s,
|
|
42
|
+
originX: 0,
|
|
43
|
+
originY: 0,
|
|
44
|
+
texture: t,
|
|
45
|
+
frame: n,
|
|
46
|
+
tint: r,
|
|
47
|
+
sourceRect: a,
|
|
48
|
+
width: c,
|
|
49
|
+
height: l,
|
|
50
|
+
displayWidth: c,
|
|
51
|
+
displayHeight: l
|
|
52
|
+
}, i);
|
|
53
|
+
if (_) {
|
|
54
|
+
let e = a[3], t = a[4], n = a[5];
|
|
55
|
+
return [
|
|
56
|
+
v("l", e, 0, 0, c, s),
|
|
57
|
+
v("c", t, c, 0, p, s),
|
|
58
|
+
v("r", n, o - l, 0, l, s)
|
|
59
|
+
];
|
|
60
|
+
}
|
|
61
|
+
let y = a[0], b = a[1], x = a[2], S = a[3], C = a[4], w = a[5], T = a[6], E = a[7], D = a[8];
|
|
62
|
+
return [
|
|
63
|
+
v("tl", y, 0, 0, c, d),
|
|
64
|
+
v("t", b, c, 0, p, d),
|
|
65
|
+
v("tr", x, o - l, 0, l, d),
|
|
66
|
+
v("l", S, 0, d, c, g),
|
|
67
|
+
v("c", C, c, d, p, g),
|
|
68
|
+
v("r", w, o - l, d, l, g),
|
|
69
|
+
v("bl", T, 0, s - f, c, f),
|
|
70
|
+
v("b", E, c, s - f, p, f),
|
|
71
|
+
v("br", D, o - l, s - f, l, f)
|
|
72
|
+
];
|
|
73
|
+
}
|
|
74
|
+
function _(e, t) {
|
|
75
|
+
let n = a().surface?.textureLoader, [r, i] = l(null);
|
|
76
|
+
return s(() => {
|
|
77
|
+
if (!n) return;
|
|
78
|
+
let r;
|
|
79
|
+
if (t) {
|
|
80
|
+
let i = n.getFrameRect(e, t);
|
|
81
|
+
i && (r = {
|
|
82
|
+
w: i.width,
|
|
83
|
+
h: i.height
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
if (!r) {
|
|
87
|
+
let t = n.getTextureSize(e);
|
|
88
|
+
t && (r = {
|
|
89
|
+
w: t.width,
|
|
90
|
+
h: t.height
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
i(r ?? null);
|
|
94
|
+
}, [
|
|
95
|
+
e,
|
|
96
|
+
t,
|
|
97
|
+
n
|
|
98
|
+
]), r;
|
|
99
|
+
}
|
|
100
|
+
function v(e) {
|
|
101
|
+
let { texture: t, frame: n, leftWidth: r, rightWidth: i, topHeight: a, bottomHeight: o, width: s, height: c, tint: l, theme: u, key: d } = e;
|
|
102
|
+
return h({
|
|
103
|
+
texture: t,
|
|
104
|
+
frame: n,
|
|
105
|
+
tint: l,
|
|
106
|
+
leftWidth: r,
|
|
107
|
+
rightWidth: i,
|
|
108
|
+
topHeight: a,
|
|
109
|
+
bottomHeight: o,
|
|
110
|
+
width: s,
|
|
111
|
+
height: c
|
|
112
|
+
}, d, u);
|
|
113
|
+
}
|
|
114
|
+
function y(n) {
|
|
115
|
+
if (m(n.renderMode, n.width !== void 0 && n.height !== void 0)) return /* @__PURE__ */ u(v, { ...n });
|
|
116
|
+
let { texture: r, frame: a, leftWidth: o, rightWidth: s, topHeight: l, bottomHeight: p, width: h, height: g, tint: y, theme: b, key: x } = n, S = l === 0 && p === 0, C = _(r, a), w = c(() => C ? f(C.w, C.h, o, s, l, p) : null, [
|
|
117
|
+
C,
|
|
118
|
+
o,
|
|
119
|
+
s,
|
|
120
|
+
l,
|
|
121
|
+
p
|
|
122
|
+
]);
|
|
123
|
+
if (!w) return /* @__PURE__ */ u(t, {
|
|
124
|
+
width: h,
|
|
125
|
+
height: g,
|
|
126
|
+
theme: b
|
|
127
|
+
}, x);
|
|
128
|
+
let T = typeof h == "number" ? h : void 0, E = typeof g == "number" ? g : void 0, D = T == null ? void 0 : T - o - s, O = E == null ? void 0 : E - l - p, k = (e, t, n) => ({
|
|
129
|
+
texture: r,
|
|
130
|
+
frame: a,
|
|
131
|
+
tint: y,
|
|
132
|
+
sourceRect: e,
|
|
133
|
+
...t == null ? {} : { displayWidth: t },
|
|
134
|
+
...n == null ? {} : { displayHeight: n }
|
|
135
|
+
});
|
|
136
|
+
if (S) {
|
|
137
|
+
let n = w[3], r = w[4], a = w[5];
|
|
138
|
+
return /* @__PURE__ */ d(t, {
|
|
139
|
+
direction: "row",
|
|
140
|
+
width: h,
|
|
141
|
+
height: g,
|
|
142
|
+
theme: b,
|
|
143
|
+
children: [
|
|
144
|
+
/* @__PURE__ */ i(e, {
|
|
145
|
+
...k(n, o, E),
|
|
146
|
+
width: o,
|
|
147
|
+
height: "100%",
|
|
148
|
+
key: "l"
|
|
149
|
+
}),
|
|
150
|
+
/* @__PURE__ */ i(e, {
|
|
151
|
+
...k(r, D, E),
|
|
152
|
+
flex: 1,
|
|
153
|
+
height: "100%",
|
|
154
|
+
key: "c"
|
|
155
|
+
}),
|
|
156
|
+
/* @__PURE__ */ i(e, {
|
|
157
|
+
...k(a, s, E),
|
|
158
|
+
width: s,
|
|
159
|
+
height: "100%",
|
|
160
|
+
key: "r"
|
|
161
|
+
})
|
|
162
|
+
]
|
|
163
|
+
}, x);
|
|
164
|
+
}
|
|
165
|
+
let A = w[0], j = w[1], M = w[2], N = w[3], P = w[4], F = w[5], I = w[6], L = w[7], R = w[8];
|
|
166
|
+
return /* @__PURE__ */ d(t, {
|
|
167
|
+
direction: "column",
|
|
168
|
+
width: h,
|
|
169
|
+
height: g,
|
|
170
|
+
theme: b,
|
|
171
|
+
children: [
|
|
172
|
+
/* @__PURE__ */ d(t, {
|
|
173
|
+
direction: "row",
|
|
174
|
+
width: "fill",
|
|
175
|
+
height: l,
|
|
176
|
+
children: [
|
|
177
|
+
/* @__PURE__ */ i(e, {
|
|
178
|
+
...k(A, o, l),
|
|
179
|
+
width: o,
|
|
180
|
+
height: l,
|
|
181
|
+
key: "tl"
|
|
182
|
+
}),
|
|
183
|
+
/* @__PURE__ */ i(e, {
|
|
184
|
+
...k(j, D, l),
|
|
185
|
+
flex: 1,
|
|
186
|
+
height: l,
|
|
187
|
+
key: "t"
|
|
188
|
+
}),
|
|
189
|
+
/* @__PURE__ */ i(e, {
|
|
190
|
+
...k(M, s, l),
|
|
191
|
+
width: s,
|
|
192
|
+
height: l,
|
|
193
|
+
key: "tr"
|
|
194
|
+
})
|
|
195
|
+
]
|
|
196
|
+
}, "row-t"),
|
|
197
|
+
/* @__PURE__ */ d(t, {
|
|
198
|
+
direction: "row",
|
|
199
|
+
width: "fill",
|
|
200
|
+
flex: 1,
|
|
201
|
+
children: [
|
|
202
|
+
/* @__PURE__ */ i(e, {
|
|
203
|
+
...k(N, o, O),
|
|
204
|
+
width: o,
|
|
205
|
+
height: "100%",
|
|
206
|
+
key: "l"
|
|
207
|
+
}),
|
|
208
|
+
/* @__PURE__ */ i(e, {
|
|
209
|
+
...k(P, D, O),
|
|
210
|
+
flex: 1,
|
|
211
|
+
height: "100%",
|
|
212
|
+
key: "c"
|
|
213
|
+
}),
|
|
214
|
+
/* @__PURE__ */ i(e, {
|
|
215
|
+
...k(F, s, O),
|
|
216
|
+
width: s,
|
|
217
|
+
height: "100%",
|
|
218
|
+
key: "r"
|
|
219
|
+
})
|
|
220
|
+
]
|
|
221
|
+
}, "row-m"),
|
|
222
|
+
/* @__PURE__ */ d(t, {
|
|
223
|
+
direction: "row",
|
|
224
|
+
width: "fill",
|
|
225
|
+
height: p,
|
|
226
|
+
children: [
|
|
227
|
+
/* @__PURE__ */ i(e, {
|
|
228
|
+
...k(I, o, p),
|
|
229
|
+
width: o,
|
|
230
|
+
height: p,
|
|
231
|
+
key: "bl"
|
|
232
|
+
}),
|
|
233
|
+
/* @__PURE__ */ i(e, {
|
|
234
|
+
...k(L, D, p),
|
|
235
|
+
flex: 1,
|
|
236
|
+
height: p,
|
|
237
|
+
key: "b"
|
|
238
|
+
}),
|
|
239
|
+
/* @__PURE__ */ i(e, {
|
|
240
|
+
...k(R, s, p),
|
|
241
|
+
width: s,
|
|
242
|
+
height: p,
|
|
243
|
+
key: "br"
|
|
244
|
+
})
|
|
245
|
+
]
|
|
246
|
+
}, "row-b")
|
|
247
|
+
]
|
|
248
|
+
}, x);
|
|
249
|
+
}
|
|
250
|
+
function b(e) {
|
|
251
|
+
let { texture: n, frame: r, leftWidth: i, rightWidth: a, topHeight: o, bottomHeight: s, width: l, height: p, tint: m, children: h, renderMode: v, alignItems: y = "start", justifyContent: b = "start", gap: x, padding: S, theme: C, key: w } = e, T = _(n, r), E = c(() => T ? f(T.w, T.h, i, a, o, s) : null, [
|
|
252
|
+
T,
|
|
253
|
+
i,
|
|
254
|
+
a,
|
|
255
|
+
o,
|
|
256
|
+
s
|
|
257
|
+
]), D = {
|
|
258
|
+
left: i + (S?.left ?? 0),
|
|
259
|
+
right: a + (S?.right ?? 0),
|
|
260
|
+
top: o + (S?.top ?? 0),
|
|
261
|
+
bottom: s + (S?.bottom ?? 0)
|
|
262
|
+
};
|
|
263
|
+
return /* @__PURE__ */ d(t, {
|
|
264
|
+
direction: "stack",
|
|
265
|
+
width: l,
|
|
266
|
+
height: p,
|
|
267
|
+
theme: C,
|
|
268
|
+
children: [E ? g(n, r, m, v, E, l, p, i, a, o, s) : null, /* @__PURE__ */ u(t, {
|
|
269
|
+
direction: "column",
|
|
270
|
+
depth: 1,
|
|
271
|
+
width: "100%",
|
|
272
|
+
height: "100%",
|
|
273
|
+
alignItems: y,
|
|
274
|
+
justifyContent: b,
|
|
275
|
+
gap: x,
|
|
276
|
+
padding: D,
|
|
277
|
+
children: h
|
|
278
|
+
})]
|
|
279
|
+
}, w);
|
|
280
|
+
}
|
|
281
|
+
function x(e) {
|
|
282
|
+
return e.children === void 0 ? /* @__PURE__ */ u(y, {
|
|
283
|
+
texture: e.texture,
|
|
284
|
+
frame: e.frame,
|
|
285
|
+
leftWidth: e.leftWidth,
|
|
286
|
+
rightWidth: e.rightWidth,
|
|
287
|
+
topHeight: e.topHeight ?? 0,
|
|
288
|
+
bottomHeight: e.bottomHeight ?? 0,
|
|
289
|
+
width: e.width,
|
|
290
|
+
height: e.height,
|
|
291
|
+
tint: e.tint,
|
|
292
|
+
renderMode: e.renderMode,
|
|
293
|
+
theme: e.theme
|
|
294
|
+
}, e.key) : /* @__PURE__ */ u(b, {
|
|
295
|
+
texture: e.texture,
|
|
296
|
+
frame: e.frame,
|
|
297
|
+
leftWidth: e.leftWidth,
|
|
298
|
+
rightWidth: e.rightWidth,
|
|
299
|
+
topHeight: e.topHeight ?? 0,
|
|
300
|
+
bottomHeight: e.bottomHeight ?? 0,
|
|
301
|
+
width: e.width,
|
|
302
|
+
height: e.height,
|
|
303
|
+
tint: e.tint,
|
|
304
|
+
renderMode: e.renderMode,
|
|
305
|
+
children: e.children,
|
|
306
|
+
alignItems: e.alignItems,
|
|
307
|
+
justifyContent: e.justifyContent,
|
|
308
|
+
gap: e.gap,
|
|
309
|
+
padding: e.padding,
|
|
310
|
+
theme: e.theme
|
|
311
|
+
}, e.key);
|
|
312
|
+
}
|
|
313
|
+
//#endregion
|
|
314
|
+
export { x as NineSlice };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NineSlice.props.test.d.ts","sourceRoot":"","sources":["../src/NineSlice.props.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NineSlice.test.d.ts","sourceRoot":"","sources":["../src/NineSlice.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require(`./primitives/View.cjs`);require(`./primitives.cjs`);const t=require(`./NineSlice.cjs`);let n=require(`@number10/jsx-core`),r=require(`@number10/jsx-core/jsx-runtime`);function i(i){let{texture:a,frame:o,leftWidth:s,rightWidth:c,topHeight:l=0,bottomHeight:u=0,width:d,height:f,tint:p,onClick:m,disabled:h,children:g,alignItems:_=`center`,justifyContent:v=`center`,gap:y,padding:b,renderMode:x,theme:S,key:C,effect:w,effectConfig:T}=i,E=(0,n.useRef)(null),[D,O]=(0,n.useState)(!1);(0,n.useEffect)(()=>{O(!0)},[]);let k=h?void 0:e=>{let t=(0,n.resolveEffect)({effect:w,effectConfig:T},{});(0,n.applyEffect)(E.current,t.effect,t.effectConfig),m?.()},A=k?{onTouch:k}:{},j=g!=null&&g!==!1;return(0,n.createElement)(e.View,{ref:E,direction:`stack`,width:d,height:f,visible:D,enableGestures:!h,...A,key:C,theme:S},j?(0,r.jsx)(t.NineSlice,{texture:a,frame:o,leftWidth:s,rightWidth:c,topHeight:l,bottomHeight:u,width:d,height:f,tint:p,renderMode:x,alignItems:_,justifyContent:v,gap:y,padding:b,theme:S,children:g}):(0,r.jsx)(t.NineSlice,{texture:a,frame:o,leftWidth:s,rightWidth:c,topHeight:l,bottomHeight:u,width:d,height:f,tint:p,renderMode:x,theme:S}))}exports.NineSliceButton=i;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { ChildrenType, EdgeInsets, EffectConfig, EffectName, GapInsets, VNodeLike } from '@number10/jsx-core';
|
|
2
|
+
import { PortablePartialTheme } from './theme-types';
|
|
3
|
+
type NineSliceRenderMode = 'auto' | 'native' | 'fallback';
|
|
4
|
+
/**
|
|
5
|
+
* Props for the portable NineSliceButton component.
|
|
6
|
+
*/
|
|
7
|
+
interface NineSliceButtonBaseProps {
|
|
8
|
+
/** Texture key (atlas name or standalone texture) */
|
|
9
|
+
texture: string;
|
|
10
|
+
/** Optional atlas frame name */
|
|
11
|
+
frame?: string | undefined;
|
|
12
|
+
/** Width of the left non-stretching edge (source pixels) */
|
|
13
|
+
leftWidth: number;
|
|
14
|
+
/** Width of the right non-stretching edge (source pixels) */
|
|
15
|
+
rightWidth: number;
|
|
16
|
+
/** Height of the top non-stretching edge (source pixels).
|
|
17
|
+
* Omit for 3-slice horizontal-only mode. */
|
|
18
|
+
topHeight?: number | undefined;
|
|
19
|
+
/** Height of the bottom non-stretching edge (source pixels).
|
|
20
|
+
* Omit for 3-slice horizontal-only mode. */
|
|
21
|
+
bottomHeight?: number | undefined;
|
|
22
|
+
/** Optional tint color applied to the NineSlice background */
|
|
23
|
+
tint?: number | undefined;
|
|
24
|
+
/** Click handler */
|
|
25
|
+
onClick?: () => void;
|
|
26
|
+
/** Disabled state — suppresses click */
|
|
27
|
+
disabled?: boolean | undefined;
|
|
28
|
+
/** Inner content horizontal alignment */
|
|
29
|
+
alignItems?: 'start' | 'center' | 'end' | 'stretch' | undefined;
|
|
30
|
+
/** Inner content vertical alignment */
|
|
31
|
+
justifyContent?: 'start' | 'center' | 'end' | 'space-between' | 'space-around' | 'space-evenly' | undefined;
|
|
32
|
+
/** Gap between multiple children */
|
|
33
|
+
gap?: number | GapInsets | undefined;
|
|
34
|
+
/** Additional inner padding beyond slice margins */
|
|
35
|
+
padding?: EdgeInsets | undefined;
|
|
36
|
+
/** Select native vs fallback 9-slice rendering explicitly for testing/debugging. */
|
|
37
|
+
renderMode?: NineSliceRenderMode | undefined;
|
|
38
|
+
/** Nested theme for child components */
|
|
39
|
+
theme?: PortablePartialTheme | undefined;
|
|
40
|
+
/** Unique key for VDOM identification */
|
|
41
|
+
key?: string | number | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Visual effect name (e.g. 'press', 'jello', 'bounce').
|
|
44
|
+
* Applied on click via @number10/jsx-core effect system.
|
|
45
|
+
* @default 'press'
|
|
46
|
+
*/
|
|
47
|
+
effect?: EffectName | undefined;
|
|
48
|
+
/** Effect configuration (intensity, time, etc.) */
|
|
49
|
+
effectConfig?: EffectConfig | undefined;
|
|
50
|
+
}
|
|
51
|
+
interface NineSliceButtonDecorativeProps extends NineSliceButtonBaseProps {
|
|
52
|
+
/** Target display width */
|
|
53
|
+
width: number;
|
|
54
|
+
/** Target display height */
|
|
55
|
+
height: number;
|
|
56
|
+
/** Content rendered inside the button */
|
|
57
|
+
children?: undefined;
|
|
58
|
+
}
|
|
59
|
+
interface NineSliceButtonContentProps extends NineSliceButtonBaseProps {
|
|
60
|
+
/** Target display width */
|
|
61
|
+
width: number;
|
|
62
|
+
/** Target display height */
|
|
63
|
+
height: number;
|
|
64
|
+
/** Content rendered inside the button */
|
|
65
|
+
children: ChildrenType;
|
|
66
|
+
}
|
|
67
|
+
export type NineSliceButtonProps = NineSliceButtonDecorativeProps | NineSliceButtonContentProps;
|
|
68
|
+
/**
|
|
69
|
+
* Portable NineSliceButton component.
|
|
70
|
+
*
|
|
71
|
+
* Renders a NineSlice background with a content area inset by the
|
|
72
|
+
* slice margins. Supports click handling, disabled state, and
|
|
73
|
+
* inner content layout.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```tsx
|
|
77
|
+
* <NineSliceButton
|
|
78
|
+
* texture="ui"
|
|
79
|
+
* frame="ButtonRoundGreen"
|
|
80
|
+
* width={250}
|
|
81
|
+
* height={80}
|
|
82
|
+
* leftWidth={20}
|
|
83
|
+
* rightWidth={20}
|
|
84
|
+
* topHeight={15}
|
|
85
|
+
* bottomHeight={15}
|
|
86
|
+
* onClick={() => console.log('clicked')}
|
|
87
|
+
* >
|
|
88
|
+
* <Text text="Click Me" />
|
|
89
|
+
* </NineSliceButton>
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
export declare function NineSliceButton(props: NineSliceButtonProps): VNodeLike;
|
|
93
|
+
export {};
|
|
94
|
+
//# sourceMappingURL=NineSliceButton.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NineSliceButton.d.ts","sourceRoot":"","sources":["../src/NineS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