@plexui/vue 0.41.1 → 0.42.1
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/dist/es/components/Accordion/Accordion.js +18 -0
- package/dist/es/components/Accordion/Accordion.js.map +1 -1
- package/dist/es/components/Button/NavigationButton.js +13 -2
- package/dist/es/components/Button/NavigationButton.js.map +1 -1
- package/dist/es/components/Dialog/Dialog.js +47 -3
- package/dist/es/components/Dialog/Dialog.js.map +1 -1
- package/dist/es/components/Dialog/sheetDrag.js +45 -12
- package/dist/es/components/Dialog/sheetDrag.js.map +1 -1
- package/dist/es/components/Field/Field.js +32 -3
- package/dist/es/components/Field/Field.js.map +1 -1
- package/dist/es/components/Icon/svg/Array.js +4 -4
- package/dist/es/components/Icon/svg/Array.js.map +1 -1
- package/dist/es/components/Icon/svg/Boolean.js +4 -4
- package/dist/es/components/Icon/svg/Boolean.js.map +1 -1
- package/dist/es/components/Icon/svg/Clipboard.js +4 -4
- package/dist/es/components/Icon/svg/Clipboard.js.map +1 -1
- package/dist/es/components/Icon/svg/Comment.js +4 -4
- package/dist/es/components/Icon/svg/Comment.js.map +1 -1
- package/dist/es/components/Icon/svg/Error.js +4 -4
- package/dist/es/components/Icon/svg/Error.js.map +1 -1
- package/dist/es/components/Icon/svg/Function.js +4 -4
- package/dist/es/components/Icon/svg/Function.js.map +1 -1
- package/dist/es/components/Icon/svg/Number.js +4 -4
- package/dist/es/components/Icon/svg/Number.js.map +1 -1
- package/dist/es/components/Icon/svg/Object.js +4 -4
- package/dist/es/components/Icon/svg/Object.js.map +1 -1
- package/dist/es/components/Icon/svg/Report.js +4 -4
- package/dist/es/components/Icon/svg/Report.js.map +1 -1
- package/dist/es/components/Icon/svg/Storage.js +4 -4
- package/dist/es/components/Icon/svg/Storage.js.map +1 -1
- package/dist/es/components/Icon/svg/String.js +4 -4
- package/dist/es/components/Icon/svg/String.js.map +1 -1
- package/dist/es/components/Icon/svg/Text.js +4 -4
- package/dist/es/components/Icon/svg/Text.js.map +1 -1
- package/dist/es/components/Menu/Menu.js +29 -2
- package/dist/es/components/Menu/Menu.js.map +1 -1
- package/dist/es/components/PlexUIProvider/PlexUIProvider.js +43 -3
- package/dist/es/components/PlexUIProvider/PlexUIProvider.js.map +1 -1
- package/dist/es/components/PlexUIProvider/androidRipple.js +98 -0
- package/dist/es/components/PlexUIProvider/androidRipple.js.map +1 -0
- package/dist/es/components/PlexUIProvider/index.js.map +1 -1
- package/dist/es/components/Select/Select.js +364 -22
- package/dist/es/components/Select/Select.js.map +1 -1
- package/dist/es/components/Sidebar/Sidebar.js +8 -1
- package/dist/es/components/Sidebar/Sidebar.js.map +1 -1
- package/dist/es/components/Sidebar/index.js +1 -1
- package/dist/es/components/Sidebar/index.js.map +1 -1
- package/dist/es/components/Toolbar/Toolbar.js +276 -17
- package/dist/es/components/Toolbar/Toolbar.js.map +1 -1
- package/dist/es/components/Toolbar/index.js.map +1 -1
- package/dist/es/lib/accordionMotion.js +144 -0
- package/dist/es/lib/accordionMotion.js.map +1 -0
- package/dist/es/lib/fieldRow.js +54 -0
- package/dist/es/lib/fieldRow.js.map +1 -1
- package/dist/es/lib/presentMotion.js +151 -0
- package/dist/es/lib/presentMotion.js.map +1 -0
- package/dist/types/components/Button/NavigationButton.d.ts +30 -1
- package/dist/types/components/ContextMenu/ContextMenu.d.ts +8 -8
- package/dist/types/components/Field/Field.d.ts +12 -2
- package/dist/types/components/FloatingLabelSelect/FloatingLabelSelect.d.ts +1 -1
- package/dist/types/components/Icon/svg/Array.d.ts +2 -2
- package/dist/types/components/Icon/svg/Boolean.d.ts +2 -2
- package/dist/types/components/Icon/svg/Clipboard.d.ts +2 -2
- package/dist/types/components/Icon/svg/Comment.d.ts +2 -2
- package/dist/types/components/Icon/svg/Error.d.ts +2 -2
- package/dist/types/components/Icon/svg/Function.d.ts +2 -2
- package/dist/types/components/Icon/svg/Number.d.ts +2 -2
- package/dist/types/components/Icon/svg/Object.d.ts +2 -2
- package/dist/types/components/Icon/svg/Report.d.ts +2 -2
- package/dist/types/components/Icon/svg/Storage.d.ts +2 -2
- package/dist/types/components/Icon/svg/String.d.ts +2 -2
- package/dist/types/components/Icon/svg/Text.d.ts +2 -2
- package/dist/types/components/PlexUIProvider/PlexUIProvider.d.ts +20 -3
- package/dist/types/components/PlexUIProvider/androidRipple.d.ts +9 -0
- package/dist/types/components/PlexUIProvider/index.d.ts +1 -1
- package/dist/types/components/Select/Select.d.ts +51 -0
- package/dist/types/components/Sidebar/Sidebar.d.ts +20 -0
- package/dist/types/components/Sidebar/index.d.ts +2 -2
- package/dist/types/components/Sidebar/useSidebarContext.d.ts +1 -1
- package/dist/types/components/TabBar/TabBar.d.ts +4 -4
- package/dist/types/components/Toast/Toaster.d.ts +1 -1
- package/dist/types/components/Toolbar/Toolbar.d.ts +49 -12
- package/dist/types/components/Toolbar/index.d.ts +1 -1
- package/dist/types/lib/accordionMotion.d.ts +20 -0
- package/dist/types/lib/fieldRow.d.ts +12 -0
- package/dist/types/lib/presentMotion.d.ts +46 -0
- package/package.json +2 -2
|
@@ -1,16 +1,23 @@
|
|
|
1
|
-
import { defineComponent, provide } from "vue";
|
|
1
|
+
import { defineComponent, onBeforeUnmount, onMounted, provide, watch } from "vue";
|
|
2
|
+
import { installAndroidRipple } from "./androidRipple.js";
|
|
2
3
|
export const PlexUIContextKey = Symbol("PlexUI");
|
|
4
|
+
/** `"android"` on an Android browser, else null (the default iOS look) */
|
|
5
|
+
function detectPlatform() {
|
|
6
|
+
return typeof navigator !== "undefined" && /Android/i.test(navigator.userAgent) ? "android" : null;
|
|
7
|
+
}
|
|
3
8
|
/**
|
|
4
9
|
* Shared context for all Plex UI components - wrap your app in this
|
|
5
10
|
* provider to use Plex UI components.
|
|
6
11
|
*
|
|
7
|
-
* It
|
|
8
|
-
* provider.
|
|
12
|
+
* It holds the component used for rendering links and picks the phone look
|
|
13
|
+
* (`platform`), like the React provider.
|
|
9
14
|
*/
|
|
10
15
|
export const PlexUIProvider = defineComponent({
|
|
11
16
|
name: "PlexUIProvider",
|
|
12
17
|
props: {
|
|
13
18
|
linkComponent: { type: [String, Object, Function], required: true },
|
|
19
|
+
/** The phone look: iOS 26, the Plex Android look, or `"auto"` (Android on an Android browser) */
|
|
20
|
+
platform: { type: String, default: "auto" },
|
|
14
21
|
},
|
|
15
22
|
setup(props, { slots }) {
|
|
16
23
|
provide(PlexUIContextKey, {
|
|
@@ -18,6 +25,39 @@ export const PlexUIProvider = defineComponent({
|
|
|
18
25
|
return props.linkComponent;
|
|
19
26
|
},
|
|
20
27
|
});
|
|
28
|
+
// Sets `data-platform` on the document's root, which the phone styles read. `"auto"` leaves the root alone
|
|
29
|
+
// except on Android, so a page (or a docs frame) that sets the attribute itself keeps it.
|
|
30
|
+
let restore = null;
|
|
31
|
+
// A press ripples in the Android look (androidRipple.ts); the iOS look has no listener.
|
|
32
|
+
let stopRipple = null;
|
|
33
|
+
const apply = () => {
|
|
34
|
+
restore?.();
|
|
35
|
+
restore = null;
|
|
36
|
+
stopRipple?.();
|
|
37
|
+
stopRipple = null;
|
|
38
|
+
const resolved = props.platform === "auto" ? detectPlatform() : props.platform;
|
|
39
|
+
if (resolved === "android")
|
|
40
|
+
stopRipple = installAndroidRipple();
|
|
41
|
+
if (!resolved)
|
|
42
|
+
return;
|
|
43
|
+
const root = document.documentElement;
|
|
44
|
+
const previous = root.getAttribute("data-platform");
|
|
45
|
+
root.setAttribute("data-platform", resolved);
|
|
46
|
+
restore = () => {
|
|
47
|
+
if (previous === null)
|
|
48
|
+
root.removeAttribute("data-platform");
|
|
49
|
+
else
|
|
50
|
+
root.setAttribute("data-platform", previous);
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
onMounted(apply);
|
|
54
|
+
watch(() => props.platform, apply);
|
|
55
|
+
onBeforeUnmount(() => {
|
|
56
|
+
restore?.();
|
|
57
|
+
restore = null;
|
|
58
|
+
stopRipple?.();
|
|
59
|
+
stopRipple = null;
|
|
60
|
+
});
|
|
21
61
|
return () => slots.default?.();
|
|
22
62
|
},
|
|
23
63
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PlexUIProvider.js","sourceRoot":"","sources":["../../../../src/components/PlexUIProvider/PlexUIProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,OAAO,EAAoD,MAAM,KAAK,CAAA;
|
|
1
|
+
{"version":3,"file":"PlexUIProvider.js","sourceRoot":"","sources":["../../../../src/components/PlexUIProvider/PlexUIProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAoD,MAAM,KAAK,CAAA;AACnI,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAA;AAezD,MAAM,CAAC,MAAM,gBAAgB,GAAqC,MAAM,CAAC,QAAQ,CAAC,CAAA;AAElF,0EAA0E;AAC1E,SAAS,cAAc;IACrB,OAAO,OAAO,SAAS,KAAK,WAAW,IAAI,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAA;AACpG,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,eAAe,CAAC;IAC5C,IAAI,EAAE,gBAAgB;IACtB,KAAK,EAAE;QACL,aAAa,EAAE,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAA4B,EAAE,QAAQ,EAAE,IAAI,EAAE;QAC9F,iGAAiG;QACjG,QAAQ,EAAE,EAAE,IAAI,EAAE,MAAkC,EAAE,OAAO,EAAE,MAAM,EAAE;KACxE;IACD,KAAK,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE;QACpB,OAAO,CAAC,gBAAgB,EAAE;YACxB,IAAI,aAAa;gBACf,OAAO,KAAK,CAAC,aAAa,CAAA;YAC5B,CAAC;SACF,CAAC,C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AAC,OAAO,EAAE,EAAE,CAAA;IAChC,CAAC;CACF,CAAC,CAAA","sourcesContent":["import { defineComponent, onBeforeUnmount, onMounted, provide, watch, type Component, type InjectionKey, type PropType } from \"vue\"\nimport { installAndroidRipple } from \"./androidRipple.js\"\n\n/** Component used to render internal links: `\"a\"` or your router's link (e.g. vue-router's `RouterLink`). */\nexport type LinkComponent = Component | \"a\"\n\n/**\n * The phone look of the components (with `@plexui/styles/styles/touch.css`): `\"ios\"` draws iOS 26, `\"android\"` the\n * Plex Android look, `\"auto\"` the Android look on an Android browser and iOS elsewhere.\n */\nexport type PlexUIPlatform = \"auto\" | \"ios\" | \"android\"\n\ntype PlexUIContextValue = {\n linkComponent: LinkComponent\n}\n\nexport const PlexUIContextKey: InjectionKey<PlexUIContextValue> = Symbol(\"PlexUI\")\n\n/** `\"android\"` on an Android browser, else null (the default iOS look) */\nfunction detectPlatform(): \"android\" | null {\n return typeof navigator !== \"undefined\" && /Android/i.test(navigator.userAgent) ? \"android\" : null\n}\n\n/**\n * Shared context for all Plex UI components - wrap your app in this\n * provider to use Plex UI components.\n *\n * It holds the component used for rendering links and picks the phone look\n * (`platform`), like the React provider.\n */\nexport const PlexUIProvider = defineComponent({\n name: \"PlexUIProvider\",\n props: {\n linkComponent: { type: [String, Object, Function] as PropType<LinkComponent>, required: true },\n /** The phone look: iOS 26, the Plex Android look, or `\"auto\"` (Android on an Android browser) */\n platform: { type: String as PropType<PlexUIPlatform>, default: \"auto\" },\n },\n setup(props, { slots }) {\n provide(PlexUIContextKey, {\n get linkComponent() {\n return props.linkComponent\n },\n })\n\n // Sets `data-platform` on the document's root, which the phone styles read. `\"auto\"` leaves the root alone\n // except on Android, so a page (or a docs frame) that sets the attribute itself keeps it.\n let restore: (() => void) | null = null\n // A press ripples in the Android look (androidRipple.ts); the iOS look has no listener.\n let stopRipple: (() => void) | null = null\n const apply = () => {\n restore?.()\n restore = null\n stopRipple?.()\n stopRipple = null\n const resolved = props.platform === \"auto\" ? detectPlatform() : props.platform\n if (resolved === \"android\") stopRipple = installAndroidRipple()\n if (!resolved) return\n const root = document.documentElement\n const previous = root.getAttribute(\"data-platform\")\n root.setAttribute(\"data-platform\", resolved)\n restore = () => {\n if (previous === null) root.removeAttribute(\"data-platform\")\n else root.setAttribute(\"data-platform\", previous)\n }\n }\n onMounted(apply)\n watch(() => props.platform, apply)\n onBeforeUnmount(() => {\n restore?.()\n restore = null\n stopRipple?.()\n stopRipple = null\n })\n\n return () => slots.default?.()\n },\n})\n"]}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The press of the Plex Android look: a ripple, as Android's RippleDrawable draws one (its timing and colors are in
|
|
3
|
+
* `@plexui/styles/styles/android.css`). PlexUIProvider listens for presses while the platform is Android; a press
|
|
4
|
+
* gives the control under the finger where its circle starts and how far it grows, as custom properties, and
|
|
5
|
+
* restarts its animation (`data-ripple`). The styles decide which controls draw it, in what shape and color. The same
|
|
6
|
+
* file is in @plexui/ui.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* A control that can be pressed. A switch, a check, a radio or a value (a Select's or a date's) in a row is not one:
|
|
10
|
+
* the row takes the press. A segment of a segmented control is a radio; a row of a choice list is a radio or a check.
|
|
11
|
+
*/
|
|
12
|
+
const HOSTS = 'button:not(:is([role="switch"], [role="checkbox"], [role="radio"], [data-slot="select-control"]):where([data-row] *)), a[href], summary, [role="button"]:not([data-slot="select-control"]:where([data-row] *)), [role="menuitem"], [role="menuitemradio"], [role="menuitemcheckbox"], [role="option"], [role="tab"], :is([role="radio"], [role="checkbox"]):not(button, input), [data-row]';
|
|
13
|
+
let installs = 0;
|
|
14
|
+
let contents;
|
|
15
|
+
/**
|
|
16
|
+
* Android's start: a circle of 30% of the control's longer side round the touch, moved in so it stays inside the
|
|
17
|
+
* end circle: the one round the control's center that reaches its corners, or a fixed one (`--android-ripple-radius`,
|
|
18
|
+
* a borderless ripple of 20px) round the center of what the control shows, its symbol or label, which a row's 44px
|
|
19
|
+
* target may hold at its end. A key starts it at the center. The points are offsets from that center, so a layer of
|
|
20
|
+
* another size round it (a borderless circle, moved by --android-ripple-ox and -oy) draws them as well.
|
|
21
|
+
*/
|
|
22
|
+
function press(host, clientX, clientY, centered) {
|
|
23
|
+
// A press inside a control that drew one before ends that one, which :active would keep lit
|
|
24
|
+
for (let held = host.parentElement?.closest("[data-ripple]"); held; held = held.parentElement?.closest("[data-ripple]")) {
|
|
25
|
+
held.removeAttribute("data-ripple");
|
|
26
|
+
}
|
|
27
|
+
host.removeAttribute("data-ripple");
|
|
28
|
+
// Reading the box applies the removal, so the attribute set below starts the animation again
|
|
29
|
+
const box = host.getBoundingClientRect();
|
|
30
|
+
const halfWidth = box.width / 2;
|
|
31
|
+
const halfHeight = box.height / 2;
|
|
32
|
+
let centerX = box.left + halfWidth;
|
|
33
|
+
let centerY = box.top + halfHeight;
|
|
34
|
+
const radius = parseFloat(getComputedStyle(host).getPropertyValue("--android-ripple-radius"));
|
|
35
|
+
if (radius > 0) {
|
|
36
|
+
// What it shows: the contents of the wrapper it may hold alone (a Button's inner box), not that wrapper's box
|
|
37
|
+
let shown = host;
|
|
38
|
+
while (shown.childNodes.length === 1 && shown.firstChild instanceof Element && !(shown.firstChild instanceof SVGElement)) {
|
|
39
|
+
shown = shown.firstChild;
|
|
40
|
+
}
|
|
41
|
+
contents ??= document.createRange();
|
|
42
|
+
contents.selectNodeContents(shown);
|
|
43
|
+
const content = contents.getBoundingClientRect();
|
|
44
|
+
if (content.width > 0 && content.height > 0) {
|
|
45
|
+
centerX = content.left + content.width / 2;
|
|
46
|
+
centerY = content.top + content.height / 2;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const end = radius > 0 ? radius : Math.sqrt(halfWidth * halfWidth + halfHeight * halfHeight);
|
|
50
|
+
const start = Math.min(Math.max(box.width, box.height) * 0.3, end);
|
|
51
|
+
let dx = centered ? 0 : clientX - centerX;
|
|
52
|
+
let dy = centered ? 0 : clientY - centerY;
|
|
53
|
+
const distance = Math.sqrt(dx * dx + dy * dy);
|
|
54
|
+
const limit = Math.max(end - start, 0);
|
|
55
|
+
if (distance > limit) {
|
|
56
|
+
dx *= limit / distance;
|
|
57
|
+
dy *= limit / distance;
|
|
58
|
+
}
|
|
59
|
+
const style = host.style;
|
|
60
|
+
style.setProperty("--android-ripple-ox", `${centerX - box.left - halfWidth}px`);
|
|
61
|
+
style.setProperty("--android-ripple-oy", `${centerY - box.top - halfHeight}px`);
|
|
62
|
+
style.setProperty("--android-ripple-x", `calc(50% + ${dx}px)`);
|
|
63
|
+
style.setProperty("--android-ripple-y", `calc(50% + ${dy}px)`);
|
|
64
|
+
style.setProperty("--android-ripple-r0", `${start}px`);
|
|
65
|
+
style.setProperty("--android-ripple-r1", `${end}px`);
|
|
66
|
+
host.setAttribute("data-ripple", "");
|
|
67
|
+
}
|
|
68
|
+
function onPointerDown(event) {
|
|
69
|
+
if (event.button !== 0 || !event.isPrimary || !(event.target instanceof Element))
|
|
70
|
+
return;
|
|
71
|
+
const host = event.target.closest(HOSTS);
|
|
72
|
+
if (host)
|
|
73
|
+
press(host, event.clientX, event.clientY, false);
|
|
74
|
+
}
|
|
75
|
+
function onKeyDown(event) {
|
|
76
|
+
if (event.repeat || (event.key !== "Enter" && event.key !== " "))
|
|
77
|
+
return;
|
|
78
|
+
if (event.target instanceof Element && event.target.matches(HOSTS))
|
|
79
|
+
press(event.target, 0, 0, true);
|
|
80
|
+
}
|
|
81
|
+
/** Starts the ripple on the document; the returned function stops it once every caller has. */
|
|
82
|
+
export function installAndroidRipple() {
|
|
83
|
+
if (installs++ === 0) {
|
|
84
|
+
document.addEventListener("pointerdown", onPointerDown, { capture: true, passive: true });
|
|
85
|
+
document.addEventListener("keydown", onKeyDown, { capture: true, passive: true });
|
|
86
|
+
}
|
|
87
|
+
let installed = true;
|
|
88
|
+
return () => {
|
|
89
|
+
if (!installed)
|
|
90
|
+
return;
|
|
91
|
+
installed = false;
|
|
92
|
+
if (--installs === 0) {
|
|
93
|
+
document.removeEventListener("pointerdown", onPointerDown, { capture: true });
|
|
94
|
+
document.removeEventListener("keydown", onKeyDown, { capture: true });
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=androidRipple.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"androidRipple.js","sourceRoot":"","sources":["../../../../src/components/PlexUIProvider/androidRipple.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;GAGG;AACH,MAAM,KAAK,GACT,4XAA4X,CAAA;AAI9X,IAAI,QAAQ,GAAG,CAAC,CAAA;AAChB,IAAI,QAA2B,CAAA;AAE/B;;;;;;GAMG;AACH,SAAS,KAAK,CAAC,IAAgB,EAAE,OAAe,EAAE,OAAe,EAAE,QAAiB;IAClF,4FAA4F;IAC5F,KAAK,IAAI,IAAI,GAAG,IAAI,CAAC,aAAa,EAAE,OAAO,CAAC,eAAe,CAAC,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC,aAAa,EAAE,OAAO,CAAC,eAAe,CAAC,EAAE,CAAC;QACxH,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC,CAAA;IACrC,CAAC;IACD,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC,CAAA;IACnC,6FAA6F;IAC7F,MAAM,GAAG,GAAG,IAAI,CAAC,qBAAqB,EAAE,CAAA;IACxC,MAAM,SAAS,GAAG,GAAG,CAAC,KAAK,GAAG,CAAC,CAAA;IAC/B,MAAM,UAAU,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,CAAA;IACjC,IAAI,OAAO,GAAG,GAAG,CAAC,IAAI,GAAG,SAAS,CAAA;IAClC,IAAI,OAAO,GAAG,GAAG,CAAC,GAAG,GAAG,UAAU,CAAA;IAClC,MAAM,MAAM,GAAG,UAAU,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,gBAAgB,CAAC,yBAAyB,CAAC,CAAC,C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AC;IACH,CAAC,CAAA;AACH,CAAC","sourcesContent":["/**\n * The press of the Plex Android look: a ripple, as Android's RippleDrawable draws one (its timing and colors are in\n * `@plexui/styles/styles/android.css`). PlexUIProvider listens for presses while the platform is Android; a press\n * gives the control under the finger where its circle starts and how far it grows, as custom properties, and\n * restarts its animation (`data-ripple`). The styles decide which controls draw it, in what shape and color. The same\n * file is in @plexui/ui.\n */\n\n/**\n * A control that can be pressed. A switch, a check, a radio or a value (a Select's or a date's) in a row is not one:\n * the row takes the press. A segment of a segmented control is a radio; a row of a choice list is a radio or a check.\n */\nconst HOSTS =\n 'button:not(:is([role=\"switch\"], [role=\"checkbox\"], [role=\"radio\"], [data-slot=\"select-control\"]):where([data-row] *)), a[href], summary, [role=\"button\"]:not([data-slot=\"select-control\"]:where([data-row] *)), [role=\"menuitem\"], [role=\"menuitemradio\"], [role=\"menuitemcheckbox\"], [role=\"option\"], [role=\"tab\"], :is([role=\"radio\"], [role=\"checkbox\"]):not(button, input), [data-row]'\n\ntype RippleHost = Element & ElementCSSInlineStyle\n\nlet installs = 0\nlet contents: Range | undefined\n\n/**\n * Android's start: a circle of 30% of the control's longer side round the touch, moved in so it stays inside the\n * end circle: the one round the control's center that reaches its corners, or a fixed one (`--android-ripple-radius`,\n * a borderless ripple of 20px) round the center of what the control shows, its symbol or label, which a row's 44px\n * target may hold at its end. A key starts it at the center. The points are offsets from that center, so a layer of\n * another size round it (a borderless circle, moved by --android-ripple-ox and -oy) draws them as well.\n */\nfunction press(host: RippleHost, clientX: number, clientY: number, centered: boolean) {\n // A press inside a control that drew one before ends that one, which :active would keep lit\n for (let held = host.parentElement?.closest(\"[data-ripple]\"); held; held = held.parentElement?.closest(\"[data-ripple]\")) {\n held.removeAttribute(\"data-ripple\")\n }\n host.removeAttribute(\"data-ripple\")\n // Reading the box applies the removal, so the attribute set below starts the animation again\n const box = host.getBoundingClientRect()\n const halfWidth = box.width / 2\n const halfHeight = box.height / 2\n let centerX = box.left + halfWidth\n let centerY = box.top + halfHeight\n const radius = parseFloat(getComputedStyle(host).getPropertyValue(\"--android-ripple-radius\"))\n if (radius > 0) {\n // What it shows: the contents of the wrapper it may hold alone (a Button's inner box), not that wrapper's box\n let shown: Element = host\n while (shown.childNodes.length === 1 && shown.firstChild instanceof Element && !(shown.firstChild instanceof SVGElement)) {\n shown = shown.firstChild\n }\n contents ??= document.createRange()\n contents.selectNodeContents(shown)\n const content = contents.getBoundingClientRect()\n if (content.width > 0 && content.height > 0) {\n centerX = content.left + content.width / 2\n centerY = content.top + content.height / 2\n }\n }\n const end = radius > 0 ? radius : Math.sqrt(halfWidth * halfWidth + halfHeight * halfHeight)\n const start = Math.min(Math.max(box.width, box.height) * 0.3, end)\n let dx = centered ? 0 : clientX - centerX\n let dy = centered ? 0 : clientY - centerY\n const distance = Math.sqrt(dx * dx + dy * dy)\n const limit = Math.max(end - start, 0)\n if (distance > limit) {\n dx *= limit / distance\n dy *= limit / distance\n }\n const style = host.style\n style.setProperty(\"--android-ripple-ox\", `${centerX - box.left - halfWidth}px`)\n style.setProperty(\"--android-ripple-oy\", `${centerY - box.top - halfHeight}px`)\n style.setProperty(\"--android-ripple-x\", `calc(50% + ${dx}px)`)\n style.setProperty(\"--android-ripple-y\", `calc(50% + ${dy}px)`)\n style.setProperty(\"--android-ripple-r0\", `${start}px`)\n style.setProperty(\"--android-ripple-r1\", `${end}px`)\n host.setAttribute(\"data-ripple\", \"\")\n}\n\nfunction onPointerDown(event: PointerEvent) {\n if (event.button !== 0 || !event.isPrimary || !(event.target instanceof Element)) return\n const host = event.target.closest(HOSTS) as RippleHost | null\n if (host) press(host, event.clientX, event.clientY, false)\n}\n\nfunction onKeyDown(event: KeyboardEvent) {\n if (event.repeat || (event.key !== \"Enter\" && event.key !== \" \")) return\n if (event.target instanceof Element && event.target.matches(HOSTS)) press(event.target as RippleHost, 0, 0, true)\n}\n\n/** Starts the ripple on the document; the returned function stops it once every caller has. */\nexport function installAndroidRipple(): () => void {\n if (installs++ === 0) {\n document.addEventListener(\"pointerdown\", onPointerDown, { capture: true, passive: true })\n document.addEventListener(\"keydown\", onKeyDown, { capture: true, passive: true })\n }\n let installed = true\n return () => {\n if (!installed) return\n installed = false\n if (--installs === 0) {\n document.removeEventListener(\"pointerdown\", onPointerDown, { capture: true })\n document.removeEventListener(\"keydown\", onKeyDown, { capture: true })\n }\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/PlexUIProvider/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/PlexUIProvider/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAA2C,MAAM,qBAAqB,CAAA","sourcesContent":["export { PlexUIProvider, type LinkComponent, type PlexUIPlatform } from \"./PlexUIProvider.js\"\n"]}
|