@plexui/ui 0.45.0 → 0.47.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.
@@ -0,0 +1,133 @@
1
+ /**
2
+ * The widths of a phone's segmented control. Shared by the React and Vue packages (the Vue copy must match).
3
+ *
4
+ * UISegmentedControl at its own width gives every segment the widest one's width (iOS 27.2); where that does not fit,
5
+ * each segment takes its label and the same air around it, as apportionsSegmentWidthsByContent does (ref-app
6
+ * segmented-hug, 13.11), and where even that does not fit, the air beside each label narrows, to 4px, before the
7
+ * segments scroll, as UIKit narrows a squeezed control's (Calendar's Напоминание stands 4pt inside its segment). A grid
8
+ * that hugs its content cannot size its tracks to the widest one by itself (the browser sizes it by the sum of its
9
+ * labels), so the widest is measured here and set as the track. Tabs.module.css asks for one width with
10
+ * `--tabs-equal-segments: 1` and for the narrowing with `--tabs-fit-segments: 1`, on a phone's horizontal control that
11
+ * is not `block`; elsewhere nothing is set.
12
+ */
13
+ const TRACK = "--tabs-segment-track";
14
+ const GUTTER = "--tabs-segment-gutter";
15
+ /** The least air beside a label of a squeezed control: the large control's widest label, 4pt in Calendar */
16
+ const MIN_GUTTER_PX = 4;
17
+ /** The phone block of Tabs.module.css, where a control starts or stops asking for one width */
18
+ const PHONE_QUERY = "(max-width: 767px)";
19
+ /** Slack for the rounding of clientWidth */
20
+ const FIT_TOLERANCE_PX = 1;
21
+ const px = (style, name) => Number.parseFloat(style.getPropertyValue(name)) || 0;
22
+ /** The control's border box as laid out, unscaled and unrounded (offsetWidth rounds to whole pixels) */
23
+ const laidOutWidth = (root, style) => {
24
+ const width = px(style, "width");
25
+ if (!width)
26
+ return root.offsetWidth;
27
+ if (style.getPropertyValue("box-sizing") === "border-box")
28
+ return width;
29
+ const sides = ["padding-left", "padding-right", "border-left-width", "border-right-width"];
30
+ return sides.reduce((sum, side) => sum + px(style, side), width);
31
+ };
32
+ const sizing = (root) => `${root.style.getPropertyValue(TRACK)}|${root.style.getPropertyValue(GUTTER)}`;
33
+ /** Sets the track and the air of the segments and says whether they changed, so a thumb on a segment that moved can
34
+ * follow. */
35
+ export function equalizeSegments(root, thumb) {
36
+ if (!root)
37
+ return false;
38
+ const before = sizing(root);
39
+ const style = getComputedStyle(root);
40
+ const equal = style.getPropertyValue("--tabs-equal-segments").trim() === "1";
41
+ const fit = style.getPropertyValue("--tabs-fit-segments").trim() === "1";
42
+ // The segments of the row: a tab that is not drawn takes no track
43
+ const segments = Array.from(root.children).filter((child) => child instanceof HTMLElement && child !== thumb && getComputedStyle(child).getPropertyValue("display") !== "none");
44
+ root.style.removeProperty(GUTTER);
45
+ if ((!equal && !fit) || root.getAttribute("data-orientation") !== "horizontal" || segments.length < 2 || !root.offsetWidth) {
46
+ root.style.removeProperty(TRACK);
47
+ return sizing(root) !== before;
48
+ }
49
+ // Each segment at its label's width and full air, unscaled while the control is held (it grows under the finger)
50
+ root.style.setProperty(TRACK, "max-content");
51
+ const width = laidOutWidth(root, style);
52
+ const scale = width / (root.getBoundingClientRect().width || width);
53
+ const widths = segments.map((segment) => segment.getBoundingClientRect().width * scale);
54
+ const widest = Math.max(...widths);
55
+ const gaps = px(style, "column-gap") * (segments.length - 1);
56
+ // Equal segments as wide as the control may grow: they fit, or the control stops at its room. Counted, not read
57
+ // from scrollWidth, which a thumb still standing where its segment was would widen.
58
+ root.style.setProperty(TRACK, `minmax(${widest}px, 1fr)`);
59
+ const room = root.clientWidth - px(style, "padding-left") - px(style, "padding-right");
60
+ const fitsEqual = widest * segments.length + gaps <= room + FIT_TOLERANCE_PX;
61
+ if (equal && fitsEqual)
62
+ return sizing(root) !== before;
63
+ root.style.removeProperty(TRACK);
64
+ const over = widths.reduce((sum, segment) => sum + segment, gaps) - room;
65
+ if (fit && !fitsEqual && over > FIT_TOLERANCE_PX) {
66
+ // Labels by their widths still overflow: the air beside each narrows by its share, to the least. The air is read
67
+ // laid out, in pixels: the token may be set in rem (0.75rem without touch.css)
68
+ const gutter = px(getComputedStyle(segments[0]), "padding-left");
69
+ const floors = segments.map((segment) => px(getComputedStyle(segment), "min-width"));
70
+ const narrowed = Math.max(MIN_GUTTER_PX, airThatFits(widths, floors, gutter, room - gaps));
71
+ if (narrowed < gutter)
72
+ root.style.setProperty(GUTTER, `${narrowed}px`);
73
+ }
74
+ return sizing(root) !== before;
75
+ }
76
+ /**
77
+ * The air beside each label that brings the segments into the room: each narrows by the same amount on both sides,
78
+ * except a segment held at its least width (a short label in a pill segment), which gives up no more, so the others
79
+ * narrow further. -Infinity where nothing can narrow.
80
+ */
81
+ function airThatFits(widths, floors, gutter, room) {
82
+ const held = new Set();
83
+ for (;;) {
84
+ const free = widths.filter((_, index) => !held.has(index));
85
+ if (!free.length)
86
+ return Number.NEGATIVE_INFINITY;
87
+ const fixed = [...held].reduce((sum, index) => sum + floors[index], 0);
88
+ const air = gutter - (free.reduce((sum, width) => sum + width, fixed) - room) / (2 * free.length);
89
+ const reached = widths.map((_, index) => index).filter((index) => !held.has(index) && widths[index] - 2 * (gutter - air) < floors[index]);
90
+ if (!reached.length)
91
+ return air;
92
+ for (const index of reached)
93
+ held.add(index);
94
+ }
95
+ }
96
+ /**
97
+ * Measures again when the room changes (the segments may fit one width now), when the screen crosses into or out of
98
+ * the phone block (the control starts or stops asking, its room unchanged) and when the font loads and the labels
99
+ * widen. `moved` runs when the track changed, so the thumb can follow its segment, and always once the font has
100
+ * loaded: segments sized by their labels move then with no track and no size changing. Returns the cleanup.
101
+ */
102
+ export function watchSegments(root, thumb, moved) {
103
+ const refit = () => {
104
+ if (equalizeSegments(root, thumb()))
105
+ moved();
106
+ };
107
+ const box = root.parentElement;
108
+ const observer = box && typeof ResizeObserver !== "undefined" ? new ResizeObserver(refit) : undefined;
109
+ if (box)
110
+ observer?.observe(box);
111
+ const phone = typeof window.matchMedia === "function" ? window.matchMedia(PHONE_QUERY) : undefined;
112
+ // Browsers before 2020 offer only addListener
113
+ if (phone?.addEventListener)
114
+ phone.addEventListener("change", refit);
115
+ else
116
+ phone?.addListener?.(refit);
117
+ let live = true;
118
+ document.fonts?.ready.then(() => {
119
+ if (!live)
120
+ return;
121
+ equalizeSegments(root, thumb());
122
+ moved();
123
+ });
124
+ return () => {
125
+ live = false;
126
+ observer?.disconnect();
127
+ if (phone?.removeEventListener)
128
+ phone.removeEventListener("change", refit);
129
+ else
130
+ phone?.removeListener?.(refit);
131
+ };
132
+ }
133
+ //# sourceMappingURL=segments.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"segments.js","sourceRoot":"","sources":["../../../../src/components/Tabs/segments.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,MAAM,KAAK,GAAG,sBAAsB,CAAA;AACpC,MAAM,MAAM,GAAG,uBAAuB,CAAA;AAEtC,4GAA4G;AAC5G,MAAM,aAAa,GAAG,CAAC,CAAA;AAEvB,+FAA+F;AAC/F,MAAM,WAAW,GAAG,oBAAoB,CAAA;AAExC,4CAA4C;AAC5C,MAAM,gBAAgB,GAAG,CAAC,CAAA;AAE1B,MAAM,EAAE,GAAG,CAAC,KAA0B,EAAE,IAAY,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAA;AAE7G,wGAAwG;AACxG,MAAM,YAAY,GAAG,CAAC,IAAiB,EAAE,KAA0B,EAAE,EAAE;IACrE,MAAM,KAAK,GAAG,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;IAChC,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAC,WAAW,CAAA;IACnC,IAAI,KAAK,CAAC,gBAAgB,CAAC,YAAY,CAAC,KAAK,YAAY;QAAE,OAAO,KAAK,CAAA;IACvE,MAAM,KAAK,GAAG,CAAC,cAAc,EAAE,eAAe,EAAE,mBAAmB,EAAE,oBAAoB,CAAC,CAAA;IAC1F,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,E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AAG;QAAE,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,CAAA;IAC/B,MAAM,KAAK,GAAG,OAAO,MAAM,CAAC,UAAU,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;IAClG,8CAA8C;IAC9C,IAAI,KAAK,EAAE,gBAAgB;QAAE,KAAK,CAAC,gBAAgB,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAA;;QAC/D,KAAK,EAAE,WAAW,EAAE,CAAC,KAAK,CAAC,CAAA;IAChC,IAAI,IAAI,GAAG,IAAI,CAAA;IACf,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE;QAC9B,IAAI,CAAC,IAAI;YAAE,OAAM;QACjB,gBAAgB,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAA;QAC/B,KAAK,EAAE,CAAA;IACT,CAAC,CAAC,CAAA;IACF,OAAO,GAAG,EAAE;QACV,IAAI,GAAG,KAAK,CAAA;QACZ,QAAQ,EAAE,UAAU,EAAE,CAAA;QACtB,IAAI,KAAK,EAAE,mBAAmB;YAAE,KAAK,CAAC,mBAAmB,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAA;;YACrE,KAAK,EAAE,cAAc,EAAE,CAAC,KAAK,CAAC,CAAA;IACrC,CAAC,CAAA;AACH,CAAC","sourcesContent":["/**\n * The widths of a phone's segmented control. Shared by the React and Vue packages (the Vue copy must match).\n *\n * UISegmentedControl at its own width gives every segment the widest one's width (iOS 27.2); where that does not fit,\n * each segment takes its label and the same air around it, as apportionsSegmentWidthsByContent does (ref-app\n * segmented-hug, 13.11), and where even that does not fit, the air beside each label narrows, to 4px, before the\n * segments scroll, as UIKit narrows a squeezed control's (Calendar's Напоминание stands 4pt inside its segment). A grid\n * that hugs its content cannot size its tracks to the widest one by itself (the browser sizes it by the sum of its\n * labels), so the widest is measured here and set as the track. Tabs.module.css asks for one width with\n * `--tabs-equal-segments: 1` and for the narrowing with `--tabs-fit-segments: 1`, on a phone's horizontal control that\n * is not `block`; elsewhere nothing is set.\n */\n\nconst TRACK = \"--tabs-segment-track\"\nconst GUTTER = \"--tabs-segment-gutter\"\n\n/** The least air beside a label of a squeezed control: the large control's widest label, 4pt in Calendar */\nconst MIN_GUTTER_PX = 4\n\n/** The phone block of Tabs.module.css, where a control starts or stops asking for one width */\nconst PHONE_QUERY = \"(max-width: 767px)\"\n\n/** Slack for the rounding of clientWidth */\nconst FIT_TOLERANCE_PX = 1\n\nconst px = (style: CSSStyleDeclaration, name: string) => Number.parseFloat(style.getPropertyValue(name)) || 0\n\n/** The control's border box as laid out, unscaled and unrounded (offsetWidth rounds to whole pixels) */\nconst laidOutWidth = (root: HTMLElement, style: CSSStyleDeclaration) => {\n const width = px(style, \"width\")\n if (!width) return root.offsetWidth\n if (style.getPropertyValue(\"box-sizing\") === \"border-box\") return width\n const sides = [\"padding-left\", \"padding-right\", \"border-left-width\", \"border-right-width\"]\n return sides.reduce((sum, side) => sum + px(style, side), width)\n}\n\nconst sizing = (root: HTMLElement) => `${root.style.getPropertyValue(TRACK)}|${root.style.getPropertyValue(GUTTER)}`\n\n/** Sets the track and the air of the segments and says whether they changed, so a thumb on a segment that moved can\n * follow. */\nexport function equalizeSegments(root: HTMLElement | null, thumb: HTMLElement | null): boolean {\n if (!root) return false\n const before = sizing(root)\n const style = getComputedStyle(root)\n const equal = style.getPropertyValue(\"--tabs-equal-segments\").trim() === \"1\"\n const fit = style.getPropertyValue(\"--tabs-fit-segments\").trim() === \"1\"\n // The segments of the row: a tab that is not drawn takes no track\n const segments = Array.from(root.children).filter(\n (child): child is HTMLElement =>\n child instanceof HTMLElement && child !== thumb && getComputedStyle(child).getPropertyValue(\"display\") !== \"none\",\n )\n root.style.removeProperty(GUTTER)\n if ((!equal && !fit) || root.getAttribute(\"data-orientation\") !== \"horizontal\" || segments.length < 2 || !root.offsetWidth) {\n root.style.removeProperty(TRACK)\n return sizing(root) !== before\n }\n // Each segment at its label's width and full air, unscaled while the control is held (it grows under the finger)\n root.style.setProperty(TRACK, \"max-content\")\n const width = laidOutWidth(root, style)\n const scale = width / (root.getBoundingClientRect().width || width)\n const widths = segments.map((segment) => segment.getBoundingClientRect().width * scale)\n const widest = Math.max(...widths)\n const gaps = px(style, \"column-gap\") * (segments.length - 1)\n // Equal segments as wide as the control may grow: they fit, or the control stops at its room. Counted, not read\n // from scrollWidth, which a thumb still standing where its segment was would widen.\n root.style.setProperty(TRACK, `minmax(${widest}px, 1fr)`)\n const room = root.clientWidth - px(style, \"padding-left\") - px(style, \"padding-right\")\n const fitsEqual = widest * segments.length + gaps <= room + FIT_TOLERANCE_PX\n if (equal && fitsEqual) return sizing(root) !== before\n root.style.removeProperty(TRACK)\n const over = widths.reduce((sum, segment) => sum + segment, gaps) - room\n if (fit && !fitsEqual && over > FIT_TOLERANCE_PX) {\n // Labels by their widths still overflow: the air beside each narrows by its share, to the least. The air is read\n // laid out, in pixels: the token may be set in rem (0.75rem without touch.css)\n const gutter = px(getComputedStyle(segments[0]), \"padding-left\")\n const floors = segments.map((segment) => px(getComputedStyle(segment), \"min-width\"))\n const narrowed = Math.max(MIN_GUTTER_PX, airThatFits(widths, floors, gutter, room - gaps))\n if (narrowed < gutter) root.style.setProperty(GUTTER, `${narrowed}px`)\n }\n return sizing(root) !== before\n}\n\n/**\n * The air beside each label that brings the segments into the room: each narrows by the same amount on both sides,\n * except a segment held at its least width (a short label in a pill segment), which gives up no more, so the others\n * narrow further. -Infinity where nothing can narrow.\n */\nfunction airThatFits(widths: number[], floors: number[], gutter: number, room: number): number {\n const held = new Set<number>()\n for (;;) {\n const free = widths.filter((_, index) => !held.has(index))\n if (!free.length) return Number.NEGATIVE_INFINITY\n const fixed = [...held].reduce((sum, index) => sum + floors[index], 0)\n const air = gutter - (free.reduce((sum, width) => sum + width, fixed) - room) / (2 * free.length)\n const reached = widths.map((_, index) => index).filter(\n (index) => !held.has(index) && widths[index] - 2 * (gutter - air) < floors[index],\n )\n if (!reached.length) return air\n for (const index of reached) held.add(index)\n }\n}\n\n/**\n * Measures again when the room changes (the segments may fit one width now), when the screen crosses into or out of\n * the phone block (the control starts or stops asking, its room unchanged) and when the font loads and the labels\n * widen. `moved` runs when the track changed, so the thumb can follow its segment, and always once the font has\n * loaded: segments sized by their labels move then with no track and no size changing. Returns the cleanup.\n */\nexport function watchSegments(root: HTMLElement, thumb: () => HTMLElement | null, moved: () => void): () => void {\n const refit = () => {\n if (equalizeSegments(root, thumb())) moved()\n }\n const box = root.parentElement\n const observer = box && typeof ResizeObserver !== \"undefined\" ? new ResizeObserver(refit) : undefined\n if (box) observer?.observe(box)\n const phone = typeof window.matchMedia === \"function\" ? window.matchMedia(PHONE_QUERY) : undefined\n // Browsers before 2020 offer only addListener\n if (phone?.addEventListener) phone.addEventListener(\"change\", refit)\n else phone?.addListener?.(refit)\n let live = true\n document.fonts?.ready.then(() => {\n if (!live) return\n equalizeSegments(root, thumb())\n moved()\n })\n return () => {\n live = false\n observer?.disconnect()\n if (phone?.removeEventListener) phone.removeEventListener(\"change\", refit)\n else phone?.removeListener?.(refit)\n }\n}\n"]}
@@ -362,6 +362,7 @@ export { default as MinimizeTop } from "./svg/MinimizeTop.js";
362
362
  export { default as Minus } from "./svg/Minus.js";
363
363
  export { default as MinusCircle } from "./svg/MinusCircle.js";
364
364
  export { default as MinusCircleFilled } from "./svg/MinusCircleFilled.js";
365
+ export { default as MinusLg } from "./svg/MinusLg.js";
365
366
  export { default as Mobile } from "./svg/Mobile.js";
366
367
  export { default as Moon } from "./svg/Moon.js";
367
368
  export { default as MoonSun } from "./svg/MoonSun.js";
@@ -0,0 +1,6 @@
1
+ import type { SVGProps } from "react";
2
+ declare const MinusLg: {
3
+ (props: SVGProps<SVGSVGElement>): import("react/jsx-runtime").JSX.Element;
4
+ displayName: string;
5
+ };
6
+ export default MinusLg;
@@ -91,6 +91,15 @@ export type TabsProps<T extends string> = {
91
91
  * @default "glass" at md and larger, "flat" at sm and smaller
92
92
  */
93
93
  "mobileMaterial"?: "glass" | "flat";
94
+ /**
95
+ * Widths of the segments of horizontal tabs on a phone, as UISegmentedControl sets them. `equal` gives every
96
+ * segment the widest one's width, its default; `content` gives each its label and the same air around it, as
97
+ * `apportionsSegmentWidthsByContent` does, for a compact control. Equal segments that do not fit take their labels'
98
+ * widths anyway; where those still do not fit, the air beside each label narrows, to 4px, and what still does not
99
+ * fit scrolls. A `block` control fills its row either way. Desktop tabs always take their labels' widths.
100
+ * @default "equal"
101
+ */
102
+ "mobileSegmentWidth"?: "equal" | "content";
94
103
  "className"?: string;
95
104
  "children": React.ReactNode;
96
105
  };
@@ -0,0 +1,22 @@
1
+ /**
2
+ * The widths of a phone's segmented control. Shared by the React and Vue packages (the Vue copy must match).
3
+ *
4
+ * UISegmentedControl at its own width gives every segment the widest one's width (iOS 27.2); where that does not fit,
5
+ * each segment takes its label and the same air around it, as apportionsSegmentWidthsByContent does (ref-app
6
+ * segmented-hug, 13.11), and where even that does not fit, the air beside each label narrows, to 4px, before the
7
+ * segments scroll, as UIKit narrows a squeezed control's (Calendar's Напоминание stands 4pt inside its segment). A grid
8
+ * that hugs its content cannot size its tracks to the widest one by itself (the browser sizes it by the sum of its
9
+ * labels), so the widest is measured here and set as the track. Tabs.module.css asks for one width with
10
+ * `--tabs-equal-segments: 1` and for the narrowing with `--tabs-fit-segments: 1`, on a phone's horizontal control that
11
+ * is not `block`; elsewhere nothing is set.
12
+ */
13
+ /** Sets the track and the air of the segments and says whether they changed, so a thumb on a segment that moved can
14
+ * follow. */
15
+ export declare function equalizeSegments(root: HTMLElement | null, thumb: HTMLElement | null): boolean;
16
+ /**
17
+ * Measures again when the room changes (the segments may fit one width now), when the screen crosses into or out of
18
+ * the phone block (the control starts or stops asking, its room unchanged) and when the font loads and the labels
19
+ * widen. `moved` runs when the track changed, so the thumb can follow its segment, and always once the font has
20
+ * loaded: segments sized by their labels move then with no track and no size changing. Returns the cleanup.
21
+ */
22
+ export declare function watchSegments(root: HTMLElement, thumb: () => HTMLElement | null, moved: () => void): () => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plexui/ui",
3
- "version": "0.45.0",
3
+ "version": "0.47.0",
4
4
  "description": "Modern design system for building high-quality applications",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -99,7 +99,7 @@
99
99
  "@maskito/core": "^5.2.2",
100
100
  "@maskito/kit": "^5.2.2",
101
101
  "@maskito/react": "^5.2.2",
102
- "@plexui/styles": "^0.4.0",
102
+ "@plexui/styles": "^0.6.0",
103
103
  "@radix-ui/react-dismissable-layer": "1.2.1",
104
104
  "@radix-ui/react-focus-guards": "1.2.0",
105
105
  "@radix-ui/react-focus-scope": "1.3.1",