@abuzareal/contour-ui 0.4.0 → 0.5.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.
Files changed (136) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/CONTRACTS.md +7 -1
  3. package/NEXTJS.md +3 -1
  4. package/OVERLAYS.md +52 -0
  5. package/PUBLIC-API.md +179 -162
  6. package/README.md +40 -26
  7. package/RELEASING.md +1 -1
  8. package/SIZE.md +45 -0
  9. package/STYLING.md +68 -0
  10. package/dist/actions.css +7 -0
  11. package/dist/components/hero/Sculpture.js +2 -1
  12. package/dist/components/three/ObjectStudy.js +2 -1
  13. package/dist/components/ui/Alert.d.ts +2 -1
  14. package/dist/components/ui/Alert.js +3 -3
  15. package/dist/components/ui/Avatar.d.ts +3 -1
  16. package/dist/components/ui/Avatar.js +3 -3
  17. package/dist/components/ui/Badge.js +2 -2
  18. package/dist/components/ui/BrandMark.js +2 -1
  19. package/dist/components/ui/Breadcrumbs.d.ts +2 -1
  20. package/dist/components/ui/Breadcrumbs.js +3 -2
  21. package/dist/components/ui/Button.d.ts +2 -0
  22. package/dist/components/ui/Button.js +3 -2
  23. package/dist/components/ui/Card.js +2 -2
  24. package/dist/components/ui/Checkbox.js +3 -3
  25. package/dist/components/ui/CountUp.d.ts +2 -1
  26. package/dist/components/ui/CountUp.js +6 -3
  27. package/dist/components/ui/DataTable.d.ts +1 -0
  28. package/dist/components/ui/DataTable.js +12 -8
  29. package/dist/components/ui/DepthButton.js +2 -2
  30. package/dist/components/ui/Dialog.d.ts +5 -1
  31. package/dist/components/ui/Dialog.js +49 -18
  32. package/dist/components/ui/Disclosure.js +2 -1
  33. package/dist/components/ui/Divider.js +3 -2
  34. package/dist/components/ui/DropdownMenu.d.ts +11 -4
  35. package/dist/components/ui/DropdownMenu.js +109 -66
  36. package/dist/components/ui/EmptyState.js +2 -1
  37. package/dist/components/ui/Field.js +2 -2
  38. package/dist/components/ui/FlipCard.js +2 -2
  39. package/dist/components/ui/FloatingPortal.d.ts +10 -0
  40. package/dist/components/ui/FloatingPortal.js +51 -0
  41. package/dist/components/ui/IconButton.js +2 -2
  42. package/dist/components/ui/Kbd.js +2 -1
  43. package/dist/components/ui/Magnetic.js +2 -1
  44. package/dist/components/ui/Marquee.js +3 -2
  45. package/dist/components/ui/OverlayTrigger.d.ts +11 -0
  46. package/dist/components/ui/OverlayTrigger.js +5 -0
  47. package/dist/components/ui/Pagination.d.ts +5 -1
  48. package/dist/components/ui/Pagination.js +3 -2
  49. package/dist/components/ui/Popover.d.ts +18 -8
  50. package/dist/components/ui/Popover.js +58 -17
  51. package/dist/components/ui/ProgressBar.js +2 -2
  52. package/dist/components/ui/RadioGroup.js +5 -5
  53. package/dist/components/ui/Reveal.d.ts +0 -1
  54. package/dist/components/ui/Reveal.js +4 -3
  55. package/dist/components/ui/RevealHeading.js +2 -1
  56. package/dist/components/ui/ScrollProgress.js +2 -1
  57. package/dist/components/ui/SectionLabel.js +2 -1
  58. package/dist/components/ui/SegmentedControl.js +6 -3
  59. package/dist/components/ui/SelectField.js +3 -2
  60. package/dist/components/ui/Skeleton.js +2 -2
  61. package/dist/components/ui/Slider.js +3 -3
  62. package/dist/components/ui/Spinner.js +2 -2
  63. package/dist/components/ui/Stat.js +2 -1
  64. package/dist/components/ui/Stepper.js +3 -3
  65. package/dist/components/ui/Switch.d.ts +2 -0
  66. package/dist/components/ui/Switch.js +6 -7
  67. package/dist/components/ui/Tabs.js +7 -5
  68. package/dist/components/ui/Tag.d.ts +2 -1
  69. package/dist/components/ui/Tag.js +4 -3
  70. package/dist/components/ui/TextArea.js +2 -1
  71. package/dist/components/ui/TextField.js +3 -2
  72. package/dist/components/ui/ThemeScope.d.ts +13 -0
  73. package/dist/components/ui/ThemeScope.js +10 -0
  74. package/dist/components/ui/ThemeToggle.d.ts +3 -0
  75. package/dist/components/ui/ThemeToggle.js +4 -3
  76. package/dist/components/ui/TiltCard.js +3 -2
  77. package/dist/components/ui/Timeline.js +2 -2
  78. package/dist/components/ui/ToastProvider.d.ts +5 -2
  79. package/dist/components/ui/ToastProvider.js +5 -5
  80. package/dist/components/ui/Tooltip.d.ts +4 -4
  81. package/dist/components/ui/Tooltip.js +70 -10
  82. package/dist/data-display.css +5 -0
  83. package/dist/effects.css +6 -0
  84. package/dist/feedback.css +5 -0
  85. package/dist/fonts-latin.css +10 -4
  86. package/dist/fonts.css +8 -0
  87. package/dist/forms.css +5 -0
  88. package/dist/hooks/useDismiss.d.ts +12 -3
  89. package/dist/hooks/useDismiss.js +5 -21
  90. package/dist/hooks/useFloatingPanel.d.ts +14 -0
  91. package/dist/hooks/useFloatingPanel.js +157 -0
  92. package/dist/hooks/useLayerDismiss.d.ts +4 -0
  93. package/dist/hooks/useLayerDismiss.js +48 -0
  94. package/dist/hooks/useMobileMenu.d.ts +0 -1
  95. package/dist/hooks/useMobileMenu.js +11 -16
  96. package/dist/hooks/usePanelFocus.d.ts +10 -0
  97. package/dist/hooks/usePanelFocus.js +60 -0
  98. package/dist/hooks/useTheme.d.ts +1 -0
  99. package/dist/hooks/useTheme.js +18 -5
  100. package/dist/index.d.ts +5 -0
  101. package/dist/index.js +1 -0
  102. package/dist/kit/forms.css +11 -2
  103. package/dist/kit/navigation.css +4 -0
  104. package/dist/kit/overlays.css +8 -4
  105. package/dist/lib/classNames.d.ts +2 -0
  106. package/dist/lib/classNames.js +16 -1
  107. package/dist/lib/componentClasses.d.ts +1 -0
  108. package/dist/lib/componentClasses.js +2 -0
  109. package/dist/lib/keyboard.d.ts +1 -1
  110. package/dist/lib/keyboard.js +5 -2
  111. package/dist/lib/layers.d.ts +18 -0
  112. package/dist/lib/layers.js +128 -0
  113. package/dist/lib/themeScope.d.ts +5 -0
  114. package/dist/lib/themeScope.js +3 -0
  115. package/dist/minimal-reset.css +6 -0
  116. package/dist/navigation.css +5 -0
  117. package/dist/overlays.css +5 -0
  118. package/dist/scoped/base.css +183 -0
  119. package/dist/scoped/kit/actions.css +209 -0
  120. package/dist/scoped/kit/data-display.css +492 -0
  121. package/dist/scoped/kit/effects.css +140 -0
  122. package/dist/scoped/kit/feedback.css +309 -0
  123. package/dist/scoped/kit/forms.css +370 -0
  124. package/dist/scoped/kit/navigation.css +266 -0
  125. package/dist/scoped/kit/overlays.css +299 -0
  126. package/dist/scoped/marquee.css +58 -0
  127. package/dist/scoped/spinner.css +20 -0
  128. package/dist/scoped/theme-toggle.css +38 -0
  129. package/dist/scoped/tokens.css +119 -0
  130. package/dist/scoped/ui.css +127 -0
  131. package/dist/scoped/utilities.css +17 -0
  132. package/dist/scoped-tokens.css +1 -0
  133. package/dist/scoped.css +12 -0
  134. package/dist/theme-toggle.css +2 -2
  135. package/dist/tokens.json +710 -0
  136. package/package.json +26 -5
@@ -0,0 +1,60 @@
1
+ "use client";
2
+ import { layerOwnsFocus, isTopLayer } from "../lib/layers.js";
3
+ import { useLayoutEffect, useRef } from "react";
4
+ /** Reconcile actual node/document moves without treating new callback props as a close. */
5
+ export default function usePanelFocus(open, trigger, panel, reason, options, anchorElement, layer) {
6
+ const policy = useRef(options);
7
+ const registration = useRef(undefined);
8
+ useLayoutEffect(() => {
9
+ policy.current = options;
10
+ const node = open && anchorElement ? panel.current : null;
11
+ const old = registration.current;
12
+ if (old && (!node || old.node !== node || old.doc !== node.ownerDocument)) {
13
+ old.dispose(!open);
14
+ registration.current = undefined;
15
+ }
16
+ if (!node || registration.current)
17
+ return;
18
+ const doc = node.ownerDocument, returnTarget = trigger.current, returnReason = reason.current;
19
+ const owns = () => node.contains(doc.activeElement) ||
20
+ (layer !== undefined && layerOwnsFocus(doc, layer));
21
+ let ownedFocus = owns();
22
+ const observeFocus = () => {
23
+ ownedFocus = owns();
24
+ };
25
+ doc.addEventListener("focusin", observeFocus);
26
+ const EventType = doc.defaultView?.Event ?? Event;
27
+ const event = new EventType("contour-open-auto-focus", {
28
+ cancelable: true,
29
+ });
30
+ policy.current.onOpenAutoFocus?.(event);
31
+ if (!event.defaultPrevented &&
32
+ (layer === undefined || isTopLayer(doc, layer)) &&
33
+ policy.current.initialFocus !== false)
34
+ (policy.current.initialFocus?.current ?? node).focus();
35
+ ownedFocus = owns();
36
+ const currentPolicy = policy;
37
+ registration.current = {
38
+ node,
39
+ doc,
40
+ dispose(returnFocus) {
41
+ doc.removeEventListener("focusin", observeFocus);
42
+ if (!returnFocus)
43
+ return;
44
+ const closeEvent = new EventType("contour-close-auto-focus", {
45
+ cancelable: true,
46
+ });
47
+ currentPolicy.current.onCloseAutoFocus?.(closeEvent);
48
+ if (returnReason?.value !== "outside" &&
49
+ !closeEvent.defaultPrevented &&
50
+ returnTarget?.isConnected &&
51
+ (returnReason?.value === "escape" || ownedFocus))
52
+ returnTarget.focus();
53
+ },
54
+ };
55
+ });
56
+ useLayoutEffect(() => () => {
57
+ registration.current?.dispose(true);
58
+ registration.current = undefined;
59
+ }, []);
60
+ }
@@ -2,4 +2,5 @@ export type Theme = "light" | "dark";
2
2
  export default function useTheme(animate?: boolean): {
3
3
  theme: Theme;
4
4
  toggle: (origin: HTMLElement) => void;
5
+ canToggle: boolean;
5
6
  };
@@ -1,6 +1,7 @@
1
1
  "use client";
2
2
  /** Light/dark theme state: persisted choice, system fallback, and the animated switch. */
3
- import { useCallback, useEffect, useSyncExternalStore } from "react";
3
+ import { useCallback, useContext, useEffect, useSyncExternalStore, } from "react";
4
+ import { ThemeScopeContext } from "../lib/themeScope.js";
4
5
  import { flushSync } from "react-dom";
5
6
  import { readStorage, storageKeys, writeStorage } from "../lib/storage.js";
6
7
  import { themeColors } from "../lib/themeBootstrap.js";
@@ -63,8 +64,12 @@ function subscribe(onChange) {
63
64
  };
64
65
  }
65
66
  export default function useTheme(animate = true) {
66
- const theme = useSyncExternalStore(subscribe, readTheme, () => "light");
67
+ const scope = useContext(ThemeScopeContext);
68
+ const scopedSubscribe = useCallback((listener) => (scope ? () => { } : subscribe(listener)), [scope]);
69
+ const theme = useSyncExternalStore(scopedSubscribe, readTheme, () => "light");
67
70
  useEffect(() => {
71
+ if (scope)
72
+ return;
68
73
  const media = window.matchMedia("(prefers-color-scheme: dark)");
69
74
  const followSystem = () => {
70
75
  if (readStorage("local", storageKeys.theme) !== null)
@@ -74,8 +79,12 @@ export default function useTheme(animate = true) {
74
79
  };
75
80
  media.addEventListener("change", followSystem);
76
81
  return () => media.removeEventListener("change", followSystem);
77
- }, []);
82
+ }, [scope]);
78
83
  const toggle = useCallback((origin) => {
84
+ if (scope) {
85
+ scope.onThemeChange?.(scope.theme === "dark" ? "light" : "dark");
86
+ return;
87
+ }
79
88
  const next = readTheme() === "dark" ? "light" : "dark";
80
89
  writeStorage("local", storageKeys.theme, next);
81
90
  const commit = () => {
@@ -94,6 +103,10 @@ export default function useTheme(animate = true) {
94
103
  return;
95
104
  }
96
105
  animateReveal(document.startViewTransition(commit), origin);
97
- }, [animate]);
98
- return { theme, toggle };
106
+ }, [animate, scope]);
107
+ return {
108
+ theme: scope?.theme ?? theme,
109
+ toggle,
110
+ canToggle: scope ? !!scope.onThemeChange : true,
111
+ };
99
112
  }
package/dist/index.d.ts CHANGED
@@ -127,3 +127,8 @@ export * from "./lib/motion.js";
127
127
  export type { Section } from "./types.js";
128
128
  export { default as SceneBoundary } from "./components/hero/SceneBoundary.js";
129
129
  export { safeHref } from "./lib/safeHref.js";
130
+ export { default as ThemeScope } from "./components/ui/ThemeScope.js";
131
+ export type * from "./components/ui/ThemeScope.js";
132
+ export type { FloatingOptions } from "./hooks/useFloatingPanel.js";
133
+ export type { PanelFocusOptions } from "./hooks/usePanelFocus.js";
134
+ export type { DismissReason } from "./lib/layers.js";
package/dist/index.js CHANGED
@@ -66,3 +66,4 @@ export * from "./lib/a11y.js";
66
66
  export * from "./lib/motion.js";
67
67
  export { default as SceneBoundary } from "./components/hero/SceneBoundary.js";
68
68
  export { safeHref } from "./lib/safeHref.js";
69
+ export { default as ThemeScope } from "./components/ui/ThemeScope.js";
@@ -272,7 +272,7 @@ textarea {
272
272
  .switch-thumb {
273
273
  position: absolute;
274
274
  top: 3px;
275
- left: 3px;
275
+ inset-inline-start: 3px;
276
276
  width: 16px;
277
277
  height: 16px;
278
278
  border-radius: 50%;
@@ -287,7 +287,7 @@ textarea {
287
287
 
288
288
  .switch-track[aria-checked="true"] .switch-thumb {
289
289
  background: var(--ink);
290
- transform: translateX(20px);
290
+ inset-inline-start: 23px;
291
291
  }
292
292
 
293
293
  .switch-track:disabled {
@@ -361,3 +361,12 @@ textarea {
361
361
  outline: 2px solid var(--fg);
362
362
  outline-offset: 6px;
363
363
  }
364
+
365
+ :dir(rtl) .slider input[type="range"]::-webkit-slider-runnable-track,
366
+ :dir(rtl) .slider input[type="range"]::-moz-range-track {
367
+ background: linear-gradient(
368
+ to left,
369
+ var(--fg) var(--progress),
370
+ var(--line-strong) var(--progress)
371
+ );
372
+ }
@@ -260,3 +260,7 @@
260
260
  min-width: 14px;
261
261
  }
262
262
  }
263
+
264
+ :dir(rtl) .pagination-step svg {
265
+ transform: scaleX(-1);
266
+ }
@@ -10,10 +10,12 @@
10
10
  z-index: 40;
11
11
  width: max-content;
12
12
  max-width: 220px;
13
+ overflow: auto;
14
+ overflow-wrap: anywhere;
13
15
  padding: 6px 10px;
14
- background: var(--ink);
15
- color: var(--paper);
16
- pointer-events: none;
16
+ background: var(--invert-bg);
17
+ color: var(--invert-fg);
18
+ pointer-events: auto;
17
19
  opacity: 0;
18
20
  visibility: hidden;
19
21
  transition:
@@ -230,7 +232,9 @@
230
232
  position: absolute;
231
233
  top: calc(100% + 8px);
232
234
  z-index: 30;
233
- min-width: 220px;
235
+ min-width: min(220px, calc(100vw - 16px));
236
+ overflow: auto;
237
+ overflow-wrap: anywhere;
234
238
  padding: 6px;
235
239
  border: 1px solid var(--line);
236
240
  background: var(--surface);
@@ -1,5 +1,7 @@
1
1
  /** Builds a className string from optional parts, skipping falsy values. */
2
2
  export declare const cx: (...parts: (string | false | null | undefined)[]) => string;
3
+ /** Prefixed hooks alongside compatibility classes; never use this for IDs or ARIA references. */
4
+ export declare const ccx: (...parts: (string | false | null | undefined)[]) => string;
3
5
  export type ButtonVariant = "primary" | "accent" | "secondary" | "ghost" | "danger";
4
6
  export type ButtonSize = "sm" | "md" | "lg";
5
7
  /** Button classes, shared so anchors can look like buttons without duplicating styles. */
@@ -1,4 +1,19 @@
1
+ import { componentClasses } from "./componentClasses.js";
1
2
  /** Builds a className string from optional parts, skipping falsy values. */
2
3
  export const cx = (...parts) => parts.filter(Boolean).join(" ");
4
+ /** Prefixed hooks alongside compatibility classes; never use this for IDs or ARIA references. */
5
+ export const ccx = (...parts) => {
6
+ const names = cx(...parts)
7
+ .split(/\s+/)
8
+ .filter(Boolean);
9
+ return [
10
+ ...new Set([
11
+ ...names,
12
+ ...names
13
+ .filter((name) => componentClasses.has(name))
14
+ .map((name) => `contour-${name}`),
15
+ ]),
16
+ ].join(" ");
17
+ };
3
18
  /** Button classes, shared so anchors can look like buttons without duplicating styles. */
4
- export const buttonClassName = (variant = "primary", size = "md", className) => cx("button", `button-${variant}`, `button-${size}`, className);
19
+ export const buttonClassName = (variant = "primary", size = "md", className) => ccx("button", `button-${variant}`, `button-${size}`, className);
@@ -0,0 +1 @@
1
+ export declare const componentClasses: Set<string>;
@@ -0,0 +1,2 @@
1
+ // Generated compatibility aliases; unknown consumer classes pass through unchanged.
2
+ export const componentClasses = new Set(["alert", "alert-accent", "alert-action", "alert-banner", "alert-body", "alert-content", "alert-danger", "alert-dismiss", "alert-icon", "alert-info", "alert-success", "alert-title", "alert-warning", "avatar", "avatar-group", "avatar-initials", "avatar-lg", "avatar-sm", "avatar-status", "avatar-status-away", "avatar-status-online", "avatar-xl", "badge", "badge-danger", "badge-dot", "badge-info", "badge-invert", "badge-neutral", "badge-success", "badge-warning", "brand", "breadcrumbs", "button", "button-accent", "button-danger", "button-ghost", "button-icon", "button-lg", "button-secondary", "button-sm", "card", "card-acid", "card-body", "card-footer", "card-icon", "card-ink", "card-interactive", "card-title", "card-top", "choice", "choice-box", "choice-control", "choice-description", "choice-error", "choice-input", "choice-invalid", "choice-label", "choice-radio", "choice-text", "count-up", "css", "data-table", "data-table-idle", "depth-button", "depth-button-face", "dialog", "dialog-body", "dialog-close", "dialog-description", "dialog-footer", "dialog-header", "dialog-left", "dialog-panel", "dialog-right", "disclosure", "disclosure-icon", "divider", "divider-labelled", "empty-state", "empty-state-icon", "field", "field-chevron", "field-control", "field-counter", "field-disabled", "field-error", "field-footer", "field-icon", "field-invalid", "field-label", "field-required", "field-select", "field-trailing", "flip-back", "flip-card", "flip-face", "flip-front", "flip-stage", "flip-toggle", "hero-letter", "icon-button", "icon-button-accent", "icon-button-lg", "icon-button-sm", "icon-button-solid", "icon-button-spin", "inline-link", "is-flipped", "is-open", "is-visible", "kbd", "magnetic", "marquee", "marquee-inner", "marquee-track", "menu", "menu-chevron", "menu-end", "menu-item", "menu-item-danger", "menu-list", "menu-start", "menu-trigger", "mono", "opening-sequence", "page-width", "pagination", "pagination-gap", "pagination-page", "pagination-step", "popover", "popover-end", "popover-panel", "popover-start", "popover-title", "progress", "progress-accent", "progress-danger", "progress-fill", "progress-header", "progress-indeterminate", "progress-success", "progress-track", "radio-group", "radio-group-inline", "reveal", "scroll-progress", "sculpture-canvas", "section-label", "segmented", "segmented-option", "site-shell", "skeleton", "skeleton-block", "skeleton-circle", "skeleton-line", "skip-link", "slider", "slider-header", "spinner", "stage-canvas", "stat", "stat-suffix", "stepper", "stepper-complete", "stepper-current", "stepper-description", "stepper-label", "stepper-marker", "stepper-step", "stepper-text", "stepper-upcoming", "switch", "switch-thumb", "switch-track", "table-scroll", "tabs", "tabs-list", "tabs-panel", "tabs-tab", "tag", "tag-removable", "tag-remove", "text-link", "theme-fading", "theme-icon-moon", "theme-icon-sun", "theme-toggle", "tilt-card", "tilt-glare", "tilt-stage", "timeline", "timeline-body", "timeline-current", "timeline-date", "timeline-entry", "timeline-title", "toast", "toast-bar", "toast-close", "toast-content", "toast-danger", "toast-info", "toast-success", "toast-viewport", "toast-warning", "tooltip", "tooltip-anchor", "tooltip-bottom", "tooltip-left", "tooltip-right", "tooltip-top", "ts", "type-line", "type-run", "visually-hidden"]);
@@ -4,5 +4,5 @@ type Orientation = "horizontal" | "vertical";
4
4
  * Returns the index to move to for an arrow, Home, or End key press,
5
5
  * wrapping at both ends, or null when the key is not a navigation key.
6
6
  */
7
- export declare function nextIndexForKey(key: string, current: number, count: number, orientation?: Orientation): number | null;
7
+ export declare function nextIndexForKey(key: string, current: number, count: number, orientation?: Orientation, direction?: "ltr" | "rtl"): number | null;
8
8
  export {};
@@ -6,10 +6,13 @@ const keysFor = (orientation) => orientation === "horizontal"
6
6
  * Returns the index to move to for an arrow, Home, or End key press,
7
7
  * wrapping at both ends, or null when the key is not a navigation key.
8
8
  */
9
- export function nextIndexForKey(key, current, count, orientation = "horizontal") {
9
+ export function nextIndexForKey(key, current, count, orientation = "horizontal", direction = "ltr") {
10
10
  if (count <= 0)
11
11
  return null;
12
- const { previous, next } = keysFor(orientation);
12
+ const keys = keysFor(orientation);
13
+ const { previous, next } = orientation === "horizontal" && direction === "rtl"
14
+ ? { previous: keys.next, next: keys.previous }
15
+ : keys;
13
16
  if (key === next)
14
17
  return (current + 1) % count;
15
18
  if (key === previous)
@@ -0,0 +1,18 @@
1
+ export type DismissReason = "escape" | "outside";
2
+ export declare const LayerVisibility: import("react").Context<boolean>;
3
+ export declare const LayerParent: import("react").Context<symbol | undefined>;
4
+ type Layer = {
5
+ id: symbol;
6
+ parent?: symbol;
7
+ elements: () => (HTMLElement | null)[];
8
+ dismiss: (reason: DismissReason, event: KeyboardEvent | PointerEvent) => void;
9
+ outside: boolean;
10
+ floating?: () => HTMLElement | null;
11
+ };
12
+ export declare function layerOwnsFocus(doc: Document, id: symbol): boolean;
13
+ /** Paint order follows dismissal order, including later-opened siblings and portaled children. */
14
+ export declare function refreshLayerStack(doc: Document): void;
15
+ export declare function isTopLayer(doc: Document, id: symbol): boolean;
16
+ /** One bubble listener per owner document. Never stop propagation or cascade a dismissal. */
17
+ export declare function registerLayer(doc: Document, layer: Layer): () => void;
18
+ export {};
@@ -0,0 +1,128 @@
1
+ import { createContext } from "react";
2
+ export const LayerVisibility = createContext(true);
3
+ export const LayerParent = createContext(undefined);
4
+ const documents = new WeakMap();
5
+ function descendant(layer, ancestor, layers) {
6
+ let parent = layer.parent;
7
+ const visited = new Set();
8
+ while (parent && !visited.has(parent)) {
9
+ if (parent === ancestor.id)
10
+ return true;
11
+ visited.add(parent);
12
+ parent = layers.find((entry) => entry.id === parent)?.parent;
13
+ }
14
+ return false;
15
+ }
16
+ function topLayer(layers) {
17
+ return [...layers]
18
+ .reverse()
19
+ .find((layer) => !layers.some((entry) => entry !== layer &&
20
+ (descendant(entry, layer, layers) ||
21
+ layer
22
+ .elements()
23
+ .some((root) => entry
24
+ .elements()
25
+ .some((child) => root && child && root !== child && root.contains(child))))));
26
+ }
27
+ export function layerOwnsFocus(doc, id) {
28
+ const layers = documents.get(doc)?.layers ?? [];
29
+ const owner = layers.find((layer) => layer.id === id);
30
+ return (!!owner &&
31
+ layers.some((layer) => (layer === owner || descendant(layer, owner, layers)) &&
32
+ layer
33
+ .elements()
34
+ .some((element) => element?.contains(doc.activeElement))));
35
+ }
36
+ /** Paint order follows dismissal order, including later-opened siblings and portaled children. */
37
+ export function refreshLayerStack(doc) {
38
+ const registry = documents.get(doc);
39
+ if (!registry)
40
+ return;
41
+ const remaining = [...registry.layers];
42
+ const ordered = [];
43
+ while (remaining.length) {
44
+ const top = topLayer(remaining);
45
+ if (!top)
46
+ break;
47
+ ordered.unshift(top);
48
+ remaining.splice(remaining.indexOf(top), 1);
49
+ }
50
+ const active = new Set();
51
+ ordered.forEach((layer, index) => {
52
+ const panel = layer.floating?.();
53
+ if (panel) {
54
+ active.add(panel);
55
+ if (!registry.zStyles.has(panel))
56
+ registry.zStyles.set(panel, {
57
+ value: panel.style.getPropertyValue("z-index"),
58
+ priority: panel.style.getPropertyPriority("z-index"),
59
+ });
60
+ const value = `calc(var(--contour-z-overlay, 30) + ${index})`;
61
+ if (panel.style.zIndex !== value)
62
+ panel.style.zIndex = value;
63
+ }
64
+ });
65
+ for (const [element, old] of registry.zStyles)
66
+ if (!active.has(element)) {
67
+ if (old.value)
68
+ element.style.setProperty("z-index", old.value, old.priority);
69
+ else
70
+ element.style.removeProperty("z-index");
71
+ registry.zStyles.delete(element);
72
+ }
73
+ }
74
+ export function isTopLayer(doc, id) {
75
+ return topLayer(documents.get(doc)?.layers ?? [])?.id === id;
76
+ }
77
+ /** One bubble listener per owner document. Never stop propagation or cascade a dismissal. */
78
+ export function registerLayer(doc, layer) {
79
+ let registry = documents.get(doc);
80
+ if (!registry) {
81
+ const layers = [];
82
+ const keydown = (event) => {
83
+ if (event.key !== "Escape" || event.defaultPrevented)
84
+ return;
85
+ const top = topLayer(layers);
86
+ if (!top)
87
+ return;
88
+ top.dismiss("escape", event);
89
+ // Suppress native modal cancellation after dispatching the chosen layer.
90
+ event.preventDefault();
91
+ };
92
+ const pointerdown = (event) => {
93
+ if (event.defaultPrevented || event.button > 0)
94
+ return;
95
+ const top = topLayer(layers);
96
+ if (!top?.outside)
97
+ return;
98
+ const path = event.composedPath();
99
+ if (top.elements().some((element) => element && path.includes(element)))
100
+ return;
101
+ top.dismiss("outside", event);
102
+ };
103
+ doc.addEventListener("keydown", keydown);
104
+ doc.addEventListener("pointerdown", pointerdown);
105
+ registry = {
106
+ layers,
107
+ zStyles: new Map(),
108
+ dispose: () => {
109
+ doc.removeEventListener("keydown", keydown);
110
+ doc.removeEventListener("pointerdown", pointerdown);
111
+ },
112
+ };
113
+ documents.set(doc, registry);
114
+ }
115
+ registry.layers.push(layer);
116
+ refreshLayerStack(doc);
117
+ const owned = registry;
118
+ return () => {
119
+ const index = owned.layers.indexOf(layer);
120
+ if (index !== -1)
121
+ owned.layers.splice(index, 1);
122
+ refreshLayerStack(doc);
123
+ if (owned.layers.length === 0) {
124
+ owned.dispose();
125
+ documents.delete(doc);
126
+ }
127
+ };
128
+ }
@@ -0,0 +1,5 @@
1
+ import type { Theme } from "../hooks/useTheme.js";
2
+ export declare const ThemeScopeContext: import("react").Context<{
3
+ theme: Theme;
4
+ onThemeChange?: (theme: Theme) => void;
5
+ } | null>;
@@ -0,0 +1,3 @@
1
+ "use client";
2
+ import { createContext } from "react";
3
+ export const ThemeScopeContext = createContext(null);
@@ -0,0 +1,6 @@
1
+ /* Optional global normalization. Page layout, colors and typography belong to the application. */
2
+ *, ::before, ::after { box-sizing: border-box; }
3
+ html { -webkit-text-size-adjust: 100%; }
4
+ body { margin: 0; }
5
+ button, input, select, textarea { font: inherit; }
6
+ [hidden]:where(:not([hidden="until-found"])) { display: none; }
@@ -0,0 +1,5 @@
1
+ @import "./scoped/tokens.css";
2
+ @import "./scoped/base.css";
3
+ @import "./scoped/utilities.css";
4
+ @import "./scoped/ui.css";
5
+ @import "./scoped/kit/navigation.css";
@@ -0,0 +1,5 @@
1
+ @import "./scoped/tokens.css";
2
+ @import "./scoped/base.css";
3
+ @import "./scoped/utilities.css";
4
+ @import "./scoped/ui.css";
5
+ @import "./scoped/kit/overlays.css";
@@ -0,0 +1,183 @@
1
+ /* Owned component defaults; no page shell, global theme mutation or foreign element reset. */
2
+ :where(.contour-root, [class*="contour-"]) {
3
+ box-sizing: border-box;
4
+ }
5
+ .contour-root {
6
+ color: var(--contour-fg);
7
+ background: var(--contour-bg);
8
+ font-family: var(--contour-font-sans);
9
+ line-height: 1.5;
10
+ }
11
+ button:where([class*="contour-"]) {
12
+ font: inherit;
13
+ font-family: var(--contour-font-sans);
14
+ color: inherit;
15
+ margin: 0;
16
+ padding: 0;
17
+ background: transparent;
18
+ border: 0 solid;
19
+ text-transform: none;
20
+ cursor: pointer;
21
+ }
22
+ button:where([class*="contour-"]):disabled {
23
+ cursor: default;
24
+ }
25
+ :where([class*="contour-"])[hidden] {
26
+ display: none;
27
+ }
28
+ :where([class*="contour-"]):focus-visible {
29
+ outline: 2px solid currentColor;
30
+ outline-offset: 4px;
31
+ }
32
+ .contour-root :where(h1, h2, h3, p, dl, dd, figure, ul, ol) {
33
+ margin: 0;
34
+ }
35
+ .contour-root :where(ul, ol) {
36
+ padding: 0;
37
+ list-style: none;
38
+ }
39
+ .contour-root :where(img, svg, canvas) {
40
+ display: block;
41
+ vertical-align: middle;
42
+ }
43
+ .contour-root :where(svg) {
44
+ flex-shrink: 0;
45
+ }
46
+ .contour-root :where(a) {
47
+ color: inherit;
48
+ }
49
+ .contour-menu-list,
50
+ .contour-popover-panel,
51
+ .contour-dialog {
52
+ color: var(--contour-fg);
53
+ font-family: var(--contour-font-sans);
54
+ }
55
+ .contour-tooltip {
56
+ background: var(--contour-invert-bg);
57
+ color: var(--contour-invert-fg);
58
+ }
59
+ .contour-field-control :where(input, select, textarea),
60
+ .contour-choice-input {
61
+ font-family: var(--contour-font-sans);
62
+ }
63
+ .contour-button,
64
+ .contour-menu-trigger,
65
+ .contour-field,
66
+ .contour-tabs,
67
+ .contour-data-table {
68
+ max-inline-size: 100%;
69
+ }
70
+ .contour-button,
71
+ .contour-menu-trigger {
72
+ overflow-wrap: anywhere;
73
+ }
74
+ .contour-dialog-header h2 {
75
+ margin: 0;
76
+ font-family: var(--contour-font-display);
77
+ font-weight: 500;
78
+ }
79
+ @media (prefers-reduced-motion: reduce) {
80
+ :where([class*="contour-"]) {
81
+ animation: none !important;
82
+ transition: none !important;
83
+ scroll-behavior: auto !important;
84
+ }
85
+ :where(.contour-reveal, .contour-type-run) {
86
+ opacity: 1;
87
+ transform: none;
88
+ }
89
+ }
90
+ [data-motion="off"] :where([class*="contour-"]) {
91
+ animation: none !important;
92
+ transition: none !important;
93
+ }
94
+ @media (forced-colors: active) {
95
+ :where(
96
+ .contour-button,
97
+ .contour-menu-trigger,
98
+ .contour-card,
99
+ .contour-dialog,
100
+ .contour-popover-panel,
101
+ .contour-menu-list,
102
+ .contour-field-control,
103
+ .contour-switch,
104
+ .contour-segmented-option
105
+ ) {
106
+ border: 1px solid ButtonText !important;
107
+ }
108
+ :where(
109
+ .contour-button,
110
+ .contour-menu-item,
111
+ .contour-tabs-tab,
112
+ .contour-segmented-option
113
+ ):focus-visible {
114
+ outline: 2px solid Highlight !important;
115
+ outline-offset: 3px;
116
+ }
117
+ :where(
118
+ .contour-tabs-tab[aria-selected="true"],
119
+ .contour-segmented-option[aria-checked="true"],
120
+ .contour-switch-track[aria-checked="true"]
121
+ ) {
122
+ outline: 2px solid Highlight !important;
123
+ }
124
+ .contour-field-error,
125
+ .contour-choice-error {
126
+ color: CanvasText !important;
127
+ }
128
+ .contour-tooltip {
129
+ border: 1px solid CanvasText;
130
+ }
131
+ }
132
+
133
+ .contour-data-table :where(button) {
134
+ font: inherit;
135
+ color: inherit;
136
+ background: transparent;
137
+ border: 0;
138
+ cursor: pointer;
139
+ }
140
+
141
+ @media (forced-colors: active) {
142
+ .contour-choice-input:checked + .contour-choice-box,
143
+ .contour-choice-input:indeterminate + .contour-choice-box {
144
+ outline: 2px solid Highlight;
145
+ outline-offset: 1px;
146
+ }
147
+ .contour-choice-radio
148
+ .contour-choice-input:checked
149
+ + .contour-choice-box::after {
150
+ content: "";
151
+ inline-size: 8px;
152
+ block-size: 8px;
153
+ background: CanvasText;
154
+ forced-color-adjust: none;
155
+ border-radius: 50%;
156
+ }
157
+ .contour-switch-thumb {
158
+ background: ButtonText !important;
159
+ forced-color-adjust: none;
160
+ }
161
+ .contour-switch-track {
162
+ border: 1px solid ButtonText !important;
163
+ }
164
+ .contour-field-control:has([aria-invalid="true"]) {
165
+ border-block-end: 2px dashed CanvasText !important;
166
+ }
167
+ .contour-slider input[type="range"] {
168
+ appearance: auto !important;
169
+ }
170
+ }
171
+
172
+ .contour-tabs {
173
+ background: transparent;
174
+ }
175
+ .contour-menu,
176
+ .contour-popover {
177
+ color: var(--contour-fg);
178
+ }
179
+ .contour-menu-trigger > span {
180
+ display: inline-flex;
181
+ align-items: center;
182
+ gap: 10px;
183
+ }