@slurp-ui/react 0.0.0-stage → 1.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 +21 -0
- package/README.md +86 -2
- package/dist/AccentScope/AccentScope.d.ts +15 -0
- package/dist/AccentScope/AccentScope.js +31 -0
- package/dist/AccentScope/AccentScope.js.map +1 -0
- package/dist/AccentScope/index.d.ts +3 -0
- package/dist/AccentScope/index.js +2 -0
- package/dist/Avatar/Avatar.d.ts +17 -0
- package/dist/Avatar/Avatar.js +42 -0
- package/dist/Avatar/Avatar.js.map +1 -0
- package/dist/Avatar/index.d.ts +3 -0
- package/dist/Avatar/index.js +2 -0
- package/dist/Bento/Bento.d.ts +14 -0
- package/dist/Bento/Bento.js +42 -0
- package/dist/Bento/Bento.js.map +1 -0
- package/dist/Bento/index.d.ts +3 -0
- package/dist/Bento/index.js +2 -0
- package/dist/Bloom/Bloom.d.ts +42 -0
- package/dist/Bloom/Bloom.js +183 -0
- package/dist/Bloom/Bloom.js.map +1 -0
- package/dist/Bloom/index.d.ts +3 -0
- package/dist/Bloom/index.js +2 -0
- package/dist/Bubble/Bubble.d.ts +20 -0
- package/dist/Bubble/Bubble.js +30 -0
- package/dist/Bubble/Bubble.js.map +1 -0
- package/dist/Bubble/index.d.ts +3 -0
- package/dist/Bubble/index.js +2 -0
- package/dist/Button/Button.d.ts +26 -0
- package/dist/Button/Button.js +50 -0
- package/dist/Button/Button.js.map +1 -0
- package/dist/Button/index.d.ts +3 -0
- package/dist/Button/index.js +2 -0
- package/dist/Card/Card.d.ts +26 -0
- package/dist/Card/Card.js +70 -0
- package/dist/Card/Card.js.map +1 -0
- package/dist/Card/index.d.ts +3 -0
- package/dist/Card/index.js +2 -0
- package/dist/Cell/Cell.d.ts +7 -0
- package/dist/Cell/Cell.js +20 -0
- package/dist/Cell/Cell.js.map +1 -0
- package/dist/Cell/index.d.ts +3 -0
- package/dist/Cell/index.js +2 -0
- package/dist/Checkbox/Checkbox.d.ts +27 -0
- package/dist/Checkbox/Checkbox.js +82 -0
- package/dist/Checkbox/Checkbox.js.map +1 -0
- package/dist/Checkbox/index.d.ts +3 -0
- package/dist/Checkbox/index.js +2 -0
- package/dist/Chip/Chip.d.ts +15 -0
- package/dist/Chip/Chip.js +40 -0
- package/dist/Chip/Chip.js.map +1 -0
- package/dist/Chip/index.d.ts +3 -0
- package/dist/Chip/index.js +2 -0
- package/dist/Choice/Choice.d.ts +37 -0
- package/dist/Choice/Choice.js +134 -0
- package/dist/Choice/Choice.js.map +1 -0
- package/dist/Choice/index.d.ts +3 -0
- package/dist/Choice/index.js +2 -0
- package/dist/Count/Count.d.ts +19 -0
- package/dist/Count/Count.js +30 -0
- package/dist/Count/Count.js.map +1 -0
- package/dist/Count/index.d.ts +3 -0
- package/dist/Count/index.js +2 -0
- package/dist/Dialog/Dialog.d.ts +26 -0
- package/dist/Dialog/Dialog.js +152 -0
- package/dist/Dialog/Dialog.js.map +1 -0
- package/dist/Dialog/index.d.ts +3 -0
- package/dist/Dialog/index.js +2 -0
- package/dist/Dock/Dock.d.ts +124 -0
- package/dist/Dock/Dock.js +359 -0
- package/dist/Dock/Dock.js.map +1 -0
- package/dist/Dock/index.d.ts +3 -0
- package/dist/Dock/index.js +2 -0
- package/dist/Empty/Empty.d.ts +17 -0
- package/dist/Empty/Empty.js +40 -0
- package/dist/Empty/Empty.js.map +1 -0
- package/dist/Empty/index.d.ts +3 -0
- package/dist/Empty/index.js +2 -0
- package/dist/Fact/Fact.d.ts +11 -0
- package/dist/Fact/Fact.js +27 -0
- package/dist/Fact/Fact.js.map +1 -0
- package/dist/Fact/index.d.ts +3 -0
- package/dist/Fact/index.js +2 -0
- package/dist/Field/Field.d.ts +44 -0
- package/dist/Field/Field.js +105 -0
- package/dist/Field/Field.js.map +1 -0
- package/dist/Field/index.d.ts +3 -0
- package/dist/Field/index.js +2 -0
- package/dist/Filters/Filters.d.ts +37 -0
- package/dist/Filters/Filters.js +64 -0
- package/dist/Filters/Filters.js.map +1 -0
- package/dist/Filters/index.d.ts +3 -0
- package/dist/Filters/index.js +2 -0
- package/dist/Flow/Flow.d.ts +17 -0
- package/dist/Flow/Flow.js +26 -0
- package/dist/Flow/Flow.js.map +1 -0
- package/dist/Flow/index.d.ts +3 -0
- package/dist/Flow/index.js +2 -0
- package/dist/Fold/Fold.d.ts +17 -0
- package/dist/Fold/Fold.js +64 -0
- package/dist/Fold/Fold.js.map +1 -0
- package/dist/Fold/index.d.ts +3 -0
- package/dist/Fold/index.js +2 -0
- package/dist/Frame/Frame.d.ts +7 -0
- package/dist/Frame/Frame.js +20 -0
- package/dist/Frame/Frame.js.map +1 -0
- package/dist/Frame/index.d.ts +3 -0
- package/dist/Frame/index.js +2 -0
- package/dist/Ground/Ground.d.ts +7 -0
- package/dist/Ground/Ground.js +19 -0
- package/dist/Ground/Ground.js.map +1 -0
- package/dist/Ground/index.d.ts +3 -0
- package/dist/Ground/index.js +2 -0
- package/dist/Hint/Hint.d.ts +21 -0
- package/dist/Hint/Hint.js +104 -0
- package/dist/Hint/Hint.js.map +1 -0
- package/dist/Hint/index.d.ts +3 -0
- package/dist/Hint/index.js +2 -0
- package/dist/Link/Link.d.ts +7 -0
- package/dist/Link/Link.js +20 -0
- package/dist/Link/Link.js.map +1 -0
- package/dist/Link/index.d.ts +3 -0
- package/dist/Link/index.js +2 -0
- package/dist/ListRow/ListRow.d.ts +25 -0
- package/dist/ListRow/ListRow.js +80 -0
- package/dist/ListRow/ListRow.js.map +1 -0
- package/dist/ListRow/index.d.ts +3 -0
- package/dist/ListRow/index.js +2 -0
- package/dist/Mark/Mark.d.ts +14 -0
- package/dist/Mark/Mark.js +28 -0
- package/dist/Mark/Mark.js.map +1 -0
- package/dist/Mark/index.d.ts +3 -0
- package/dist/Mark/index.js +2 -0
- package/dist/Menu/Menu.d.ts +29 -0
- package/dist/Menu/Menu.js +64 -0
- package/dist/Menu/Menu.js.map +1 -0
- package/dist/Menu/index.d.ts +3 -0
- package/dist/Menu/index.js +2 -0
- package/dist/Notice/Notice.d.ts +31 -0
- package/dist/Notice/Notice.js +82 -0
- package/dist/Notice/Notice.js.map +1 -0
- package/dist/Notice/index.d.ts +3 -0
- package/dist/Notice/index.js +2 -0
- package/dist/Placeholder/Placeholder.d.ts +15 -0
- package/dist/Placeholder/Placeholder.js +28 -0
- package/dist/Placeholder/Placeholder.js.map +1 -0
- package/dist/Placeholder/index.d.ts +3 -0
- package/dist/Placeholder/index.js +2 -0
- package/dist/Portal/Portal.d.ts +10 -0
- package/dist/Portal/Portal.js +13 -0
- package/dist/Portal/Portal.js.map +1 -0
- package/dist/Portal/index.d.ts +3 -0
- package/dist/Portal/index.js +2 -0
- package/dist/Progress/Progress.d.ts +22 -0
- package/dist/Progress/Progress.js +65 -0
- package/dist/Progress/Progress.js.map +1 -0
- package/dist/Progress/index.d.ts +3 -0
- package/dist/Progress/index.js +2 -0
- package/dist/Radio/Radio.d.ts +39 -0
- package/dist/Radio/Radio.js +118 -0
- package/dist/Radio/Radio.js.map +1 -0
- package/dist/Radio/index.d.ts +3 -0
- package/dist/Radio/index.js +2 -0
- package/dist/Range/Range.d.ts +26 -0
- package/dist/Range/Range.js +68 -0
- package/dist/Range/Range.js.map +1 -0
- package/dist/Range/index.d.ts +3 -0
- package/dist/Range/index.js +2 -0
- package/dist/ResultRow/ResultRow.d.ts +17 -0
- package/dist/ResultRow/ResultRow.js +46 -0
- package/dist/ResultRow/ResultRow.js.map +1 -0
- package/dist/ResultRow/index.d.ts +3 -0
- package/dist/ResultRow/index.js +2 -0
- package/dist/Score/Score.d.ts +16 -0
- package/dist/Score/Score.js +55 -0
- package/dist/Score/Score.js.map +1 -0
- package/dist/Score/index.d.ts +3 -0
- package/dist/Score/index.js +2 -0
- package/dist/Search/Search.d.ts +29 -0
- package/dist/Search/Search.js +94 -0
- package/dist/Search/Search.js.map +1 -0
- package/dist/Search/index.d.ts +3 -0
- package/dist/Search/index.js +2 -0
- package/dist/Segmented/Segmented.d.ts +24 -0
- package/dist/Segmented/Segmented.js +69 -0
- package/dist/Segmented/Segmented.js.map +1 -0
- package/dist/Segmented/index.d.ts +3 -0
- package/dist/Segmented/index.js +2 -0
- package/dist/Settings/Settings.d.ts +49 -0
- package/dist/Settings/Settings.js +93 -0
- package/dist/Settings/Settings.js.map +1 -0
- package/dist/Settings/index.d.ts +3 -0
- package/dist/Settings/index.js +2 -0
- package/dist/Sheet/Sheet.d.ts +7 -0
- package/dist/Sheet/Sheet.js +11 -0
- package/dist/Sheet/Sheet.js.map +1 -0
- package/dist/Sheet/index.d.ts +3 -0
- package/dist/Sheet/index.js +2 -0
- package/dist/Shelf/Shelf.d.ts +7 -0
- package/dist/Shelf/Shelf.js +23 -0
- package/dist/Shelf/Shelf.js.map +1 -0
- package/dist/Shelf/index.d.ts +3 -0
- package/dist/Shelf/index.js +2 -0
- package/dist/SlurpProvider/ColorSchemeScript.d.ts +15 -0
- package/dist/SlurpProvider/ColorSchemeScript.js +18 -0
- package/dist/SlurpProvider/ColorSchemeScript.js.map +1 -0
- package/dist/SlurpProvider/SlurpProvider.d.ts +18 -0
- package/dist/SlurpProvider/SlurpProvider.js +106 -0
- package/dist/SlurpProvider/SlurpProvider.js.map +1 -0
- package/dist/SlurpProvider/index.d.ts +5 -0
- package/dist/SlurpProvider/index.js +5 -0
- package/dist/Stage/Stage.d.ts +14 -0
- package/dist/Stage/Stage.js +38 -0
- package/dist/Stage/Stage.js.map +1 -0
- package/dist/Stage/index.d.ts +3 -0
- package/dist/Stage/index.js +2 -0
- package/dist/Surface/Surface.d.ts +16 -0
- package/dist/Surface/Surface.js +25 -0
- package/dist/Surface/Surface.js.map +1 -0
- package/dist/Surface/index.d.ts +3 -0
- package/dist/Surface/index.js +2 -0
- package/dist/Swatch/Swatch.d.ts +31 -0
- package/dist/Swatch/Swatch.js +72 -0
- package/dist/Swatch/Swatch.js.map +1 -0
- package/dist/Swatch/index.d.ts +3 -0
- package/dist/Swatch/index.js +2 -0
- package/dist/Switch/Switch.d.ts +15 -0
- package/dist/Switch/Switch.js +62 -0
- package/dist/Switch/Switch.js.map +1 -0
- package/dist/Switch/index.d.ts +3 -0
- package/dist/Switch/index.js +2 -0
- package/dist/Tabs/Tabs.d.ts +21 -0
- package/dist/Tabs/Tabs.js +105 -0
- package/dist/Tabs/Tabs.js.map +1 -0
- package/dist/Tabs/index.d.ts +3 -0
- package/dist/Tabs/index.js +2 -0
- package/dist/Text/Text.d.ts +17 -0
- package/dist/Text/Text.js +33 -0
- package/dist/Text/Text.js.map +1 -0
- package/dist/Text/index.d.ts +3 -0
- package/dist/Text/index.js +2 -0
- package/dist/Tile/Tile.d.ts +25 -0
- package/dist/Tile/Tile.js +67 -0
- package/dist/Tile/Tile.js.map +1 -0
- package/dist/Tile/index.d.ts +3 -0
- package/dist/Tile/index.js +2 -0
- package/dist/Toast/Toast.d.ts +43 -0
- package/dist/Toast/Toast.js +132 -0
- package/dist/Toast/Toast.js.map +1 -0
- package/dist/Toast/index.d.ts +3 -0
- package/dist/Toast/index.js +2 -0
- package/dist/VisuallyHidden/VisuallyHidden.d.ts +7 -0
- package/dist/VisuallyHidden/VisuallyHidden.js +15 -0
- package/dist/VisuallyHidden/VisuallyHidden.js.map +1 -0
- package/dist/VisuallyHidden/index.d.ts +3 -0
- package/dist/VisuallyHidden/index.js +2 -0
- package/dist/fonts/poppins-latin-400-normal.woff2 +0 -0
- package/dist/fonts/poppins-latin-500-normal.woff2 +0 -0
- package/dist/fonts/poppins-latin-600-normal.woff2 +0 -0
- package/dist/fonts/poppins-latin-700-normal.woff2 +0 -0
- package/dist/icons/index.d.ts +2 -0
- package/dist/icons/index.js +2 -0
- package/dist/index.d.ts +121 -0
- package/dist/index.js +69 -0
- package/dist/internal/animation.js +26 -0
- package/dist/internal/animation.js.map +1 -0
- package/dist/internal/context.d.ts +14 -0
- package/dist/internal/context.js +21 -0
- package/dist/internal/context.js.map +1 -0
- package/dist/internal/styled.js +79 -0
- package/dist/internal/styled.js.map +1 -0
- package/dist/lib/color.d.ts +21 -0
- package/dist/lib/color.js +151 -0
- package/dist/lib/color.js.map +1 -0
- package/dist/lib/crumb.d.ts +9 -0
- package/dist/lib/crumb.js +69 -0
- package/dist/lib/crumb.js.map +1 -0
- package/dist/lib/css.d.ts +53 -0
- package/dist/lib/css.js +142 -0
- package/dist/lib/css.js.map +1 -0
- package/dist/lib/ground.js +15 -0
- package/dist/lib/ground.js.map +1 -0
- package/dist/lib/layout.d.ts +24 -0
- package/dist/lib/layout.js +88 -0
- package/dist/lib/layout.js.map +1 -0
- package/dist/lib/polymorphic.d.ts +28 -0
- package/dist/lib/theme.d.ts +292 -0
- package/dist/lib/theme.js +90 -0
- package/dist/lib/theme.js.map +1 -0
- package/dist/motion/AnimationGroup.d.ts +10 -0
- package/dist/motion/AnimationGroup.js +14 -0
- package/dist/motion/AnimationGroup.js.map +1 -0
- package/dist/motion/context.js +8 -0
- package/dist/motion/context.js.map +1 -0
- package/dist/motion/index.d.ts +7 -0
- package/dist/motion/index.js +7 -0
- package/dist/motion/navigation.d.ts +51 -0
- package/dist/motion/navigation.js +122 -0
- package/dist/motion/navigation.js.map +1 -0
- package/dist/motion/useAnimationTarget.d.ts +22 -0
- package/dist/motion/useAnimationTarget.js +34 -0
- package/dist/motion/useAnimationTarget.js.map +1 -0
- package/dist/motion/useSlurp.d.ts +18 -0
- package/dist/motion/useSlurp.js +48 -0
- package/dist/motion/useSlurp.js.map +1 -0
- package/dist/styles.css +3439 -0
- package/dist/tokens/index.d.ts +2 -0
- package/dist/tokens/index.js +2 -0
- package/dist/tokens.css +178 -0
- package/dist/utils/focus.d.ts +20 -0
- package/dist/utils/focus.js +50 -0
- package/dist/utils/focus.js.map +1 -0
- package/dist/utils/index.d.ts +10 -0
- package/dist/utils/index.js +10 -0
- package/dist/utils/src/index.js +9 -0
- package/dist/utils/src/index.js.map +1 -0
- package/dist/utils/useControlled.d.ts +14 -0
- package/dist/utils/useControlled.js +23 -0
- package/dist/utils/useControlled.js.map +1 -0
- package/dist/utils/useDismiss.d.ts +24 -0
- package/dist/utils/useDismiss.js +60 -0
- package/dist/utils/useDismiss.js.map +1 -0
- package/dist/utils/useFindInPage.d.ts +18 -0
- package/dist/utils/useFindInPage.js +51 -0
- package/dist/utils/useFindInPage.js.map +1 -0
- package/dist/utils/useForkRef.d.ts +5 -0
- package/dist/utils/useForkRef.js +33 -0
- package/dist/utils/useForkRef.js.map +1 -0
- package/dist/utils/useMediaQuery.d.ts +11 -0
- package/dist/utils/useMediaQuery.js +21 -0
- package/dist/utils/useMediaQuery.js.map +1 -0
- package/dist/utils/useRovingFocus.d.ts +17 -0
- package/dist/utils/useRovingFocus.js +26 -0
- package/dist/utils/useRovingFocus.js.map +1 -0
- package/package.json +107 -3
package/dist/index.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
|
|
2
|
+
import { CONTRAST_MIN, alpha, contrast, meetsContrast, onColor, vivid } from "./lib/color.js";
|
|
3
|
+
import { DEFAULT_STORAGE_KEY, createTheme } from "./lib/theme.js";
|
|
4
|
+
import { useColorScheme, useTheme } from "./internal/context.js";
|
|
5
|
+
import { SlurpProvider } from "./SlurpProvider/SlurpProvider.js";
|
|
6
|
+
import { ColorSchemeScript } from "./SlurpProvider/ColorSchemeScript.js";
|
|
7
|
+
import { AnimationGroup } from "./motion/AnimationGroup.js";
|
|
8
|
+
import { useAnimationTarget } from "./motion/useAnimationTarget.js";
|
|
9
|
+
import { useSlurp } from "./motion/useSlurp.js";
|
|
10
|
+
import { useSlurpEnter, useSlurpNavigate } from "./motion/navigation.js";
|
|
11
|
+
import { useForkRef } from "./utils/useForkRef.js";
|
|
12
|
+
import { AccentScope } from "./AccentScope/AccentScope.js";
|
|
13
|
+
import { Cell } from "./Cell/Cell.js";
|
|
14
|
+
import { Flow } from "./Flow/Flow.js";
|
|
15
|
+
import { Frame } from "./Frame/Frame.js";
|
|
16
|
+
import { Ground } from "./Ground/Ground.js";
|
|
17
|
+
import { Surface } from "./Surface/Surface.js";
|
|
18
|
+
import { Text } from "./Text/Text.js";
|
|
19
|
+
import { VisuallyHidden } from "./VisuallyHidden/VisuallyHidden.js";
|
|
20
|
+
import { Portal } from "./Portal/Portal.js";
|
|
21
|
+
import { Button } from "./Button/Button.js";
|
|
22
|
+
import { Bubble } from "./Bubble/Bubble.js";
|
|
23
|
+
import { useControlled } from "./utils/useControlled.js";
|
|
24
|
+
import { Chip } from "./Chip/Chip.js";
|
|
25
|
+
import { FOCUSABLE, focusFirst, moveFocus } from "./utils/focus.js";
|
|
26
|
+
import { useRovingFocus } from "./utils/useRovingFocus.js";
|
|
27
|
+
import { Segmented } from "./Segmented/Segmented.js";
|
|
28
|
+
import { Count } from "./Count/Count.js";
|
|
29
|
+
import { Avatar } from "./Avatar/Avatar.js";
|
|
30
|
+
import { Swatch, SwatchGroup } from "./Swatch/Swatch.js";
|
|
31
|
+
import { Progress } from "./Progress/Progress.js";
|
|
32
|
+
import { Placeholder } from "./Placeholder/Placeholder.js";
|
|
33
|
+
import { NOTICE_LABELS, Notice } from "./Notice/Notice.js";
|
|
34
|
+
import { Field } from "./Field/Field.js";
|
|
35
|
+
import { SEARCH_LABELS, Search } from "./Search/Search.js";
|
|
36
|
+
import { Checkbox } from "./Checkbox/Checkbox.js";
|
|
37
|
+
import { Radio, RadioGroup } from "./Radio/Radio.js";
|
|
38
|
+
import { Switch } from "./Switch/Switch.js";
|
|
39
|
+
import { Range } from "./Range/Range.js";
|
|
40
|
+
import { useDismiss } from "./utils/useDismiss.js";
|
|
41
|
+
import { Bloom } from "./Bloom/Bloom.js";
|
|
42
|
+
import { CHOICE_LABELS, Choice } from "./Choice/Choice.js";
|
|
43
|
+
import { Tabs } from "./Tabs/Tabs.js";
|
|
44
|
+
import { Fold } from "./Fold/Fold.js";
|
|
45
|
+
import { Hint } from "./Hint/Hint.js";
|
|
46
|
+
import { Menu, MenuItem } from "./Menu/Menu.js";
|
|
47
|
+
import { DIALOG_LABELS, Dialog } from "./Dialog/Dialog.js";
|
|
48
|
+
import { Sheet } from "./Sheet/Sheet.js";
|
|
49
|
+
import { TOAST_LABELS, ToastProvider, useToast } from "./Toast/Toast.js";
|
|
50
|
+
import { Tile } from "./Tile/Tile.js";
|
|
51
|
+
import { bentoLayout, matchRanges, matchesAll, normalizeText } from "./lib/layout.js";
|
|
52
|
+
import { Bento } from "./Bento/Bento.js";
|
|
53
|
+
import { Card } from "./Card/Card.js";
|
|
54
|
+
import { Shelf } from "./Shelf/Shelf.js";
|
|
55
|
+
import { Stage } from "./Stage/Stage.js";
|
|
56
|
+
import { Fact } from "./Fact/Fact.js";
|
|
57
|
+
import { Score } from "./Score/Score.js";
|
|
58
|
+
import { List, ListRow } from "./ListRow/ListRow.js";
|
|
59
|
+
import { ResultRow } from "./ResultRow/ResultRow.js";
|
|
60
|
+
import { Mark } from "./Mark/Mark.js";
|
|
61
|
+
import { Empty } from "./Empty/Empty.js";
|
|
62
|
+
import { Link } from "./Link/Link.js";
|
|
63
|
+
import { crumbPath } from "./lib/crumb.js";
|
|
64
|
+
import { COMPACT_QUERY, useMediaQuery } from "./utils/useMediaQuery.js";
|
|
65
|
+
import { DOCK_LABELS, Dock } from "./Dock/Dock.js";
|
|
66
|
+
import { SETTINGS_LABELS, Settings } from "./Settings/Settings.js";
|
|
67
|
+
import { FILTERS_LABELS, Filters } from "./Filters/Filters.js";
|
|
68
|
+
import { focusHit, useFindInPage } from "./utils/useFindInPage.js";
|
|
69
|
+
export { AccentScope, AnimationGroup, Avatar, Bento, Bloom, Bubble, Button, CHOICE_LABELS, COMPACT_QUERY, CONTRAST_MIN, Card, Cell, Checkbox, Chip, Choice, ColorSchemeScript, Count, DEFAULT_STORAGE_KEY, DIALOG_LABELS, DOCK_LABELS, Dialog, Dock, Empty, FILTERS_LABELS, FOCUSABLE, Fact, Field, Filters, Flow, Fold, Frame, Ground, Hint, Link, List, ListRow, Mark, Menu, MenuItem, NOTICE_LABELS, Notice, Placeholder, Portal, Progress, Radio, RadioGroup, Range, ResultRow, SEARCH_LABELS, SETTINGS_LABELS, Score, Search, Segmented, Settings, Sheet, Shelf, SlurpProvider, Stage, Surface, Swatch, SwatchGroup, Switch, TOAST_LABELS, Tabs, Text, Tile, ToastProvider, VisuallyHidden, alpha, bentoLayout, contrast, createTheme, crumbPath, focusFirst, focusHit, matchRanges, matchesAll, meetsContrast, moveFocus, normalizeText, onColor, useAnimationTarget, useColorScheme, useControlled, useDismiss, useFindInPage, useForkRef, useMediaQuery, useRovingFocus, useSlurp, useSlurpEnter, useSlurpNavigate, useTheme, useToast, vivid };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useAnimationTarget } from "../motion/useAnimationTarget.js";
|
|
3
|
+
import { useForkRef } from "../utils/useForkRef.js";
|
|
4
|
+
// src/internal/animation.ts
|
|
5
|
+
/**
|
|
6
|
+
* Root props of a component without its animation* props, with the element registered for motion when asked.
|
|
7
|
+
* Without animation props the ref passes through untouched.
|
|
8
|
+
*/
|
|
9
|
+
function useAnimationRoot(props) {
|
|
10
|
+
const { animationId, animationGroup, animationLead, animationDisabled, animationGhost, ref, ...rest } = props;
|
|
11
|
+
const target = useAnimationTarget({
|
|
12
|
+
animationId,
|
|
13
|
+
animationGroup,
|
|
14
|
+
animationLead,
|
|
15
|
+
animationDisabled,
|
|
16
|
+
animationGhost
|
|
17
|
+
});
|
|
18
|
+
const merged = useForkRef(ref, target);
|
|
19
|
+
return merged ? {
|
|
20
|
+
...rest,
|
|
21
|
+
ref: merged
|
|
22
|
+
} : rest;
|
|
23
|
+
}
|
|
24
|
+
export { useAnimationRoot };
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=animation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"animation.js","names":[],"sources":["../../src/internal/animation.ts"],"sourcesContent":["import type { Ref } from 'react';\n\nimport { useAnimationTarget, type AnimationProps } from '../motion/useAnimationTarget';\nimport { useForkRef } from '../utils/useForkRef';\n\n/**\n * Root props of a component without its animation* props, with the element registered for motion when asked.\n * Without animation props the ref passes through untouched.\n */\nexport function useAnimationRoot<P extends AnimationProps & { ref?: unknown }>(\n props: P,\n): Omit<P, keyof AnimationProps> {\n const {\n animationId,\n animationGroup,\n animationLead,\n animationDisabled,\n animationGhost,\n ref,\n ...rest\n } = props;\n const target = useAnimationTarget({\n animationId,\n animationGroup,\n animationLead,\n animationDisabled,\n animationGhost,\n });\n const merged = useForkRef(ref as Ref<HTMLElement> | undefined, target);\n return (merged ? { ...rest, ref: merged } : rest) as Omit<P, keyof AnimationProps>;\n}\n"],"mappings":";;;;;;;;AASA,SAAgB,iBACd,OAC+B;CAC/B,MAAM,EACJ,aACA,gBACA,eACA,mBACA,gBACA,KACA,GAAG,SACD;CACJ,MAAM,SAAS,mBAAmB;EAChC;EACA;EACA;EACA;EACA;CACF,CAAC;CACD,MAAM,SAAS,WAAW,KAAqC,MAAM;CACrE,OAAQ,SAAS;EAAE,GAAG;EAAM,KAAK;CAAO,IAAI;AAC9C"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
|
|
2
|
+
import { ColorSchemeMode, ResolvedColorScheme, Theme } from "../lib/theme.js";
|
|
3
|
+
export interface ColorSchemeState {
|
|
4
|
+
/** What the person chose (or the theme default): `light`, `dark` or `system`. */
|
|
5
|
+
mode: ColorSchemeMode;
|
|
6
|
+
setMode: (mode: ColorSchemeMode) => void;
|
|
7
|
+
/** The scheme actually shown. `system` resolves through prefers-color-scheme (light during SSR). */
|
|
8
|
+
resolved: ResolvedColorScheme;
|
|
9
|
+
}
|
|
10
|
+
/** The active theme; the default theme outside a SlurpProvider. */
|
|
11
|
+
export declare function useTheme(): Theme;
|
|
12
|
+
/** Colour scheme of the nearest SlurpProvider: `{ mode, setMode, resolved }`. */
|
|
13
|
+
export declare function useColorScheme(): ColorSchemeState;
|
|
14
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { defaultTheme } from "../lib/theme.js";
|
|
3
|
+
import { createContext, useContext } from "react";
|
|
4
|
+
// src/internal/context.ts
|
|
5
|
+
const SlurpContext = createContext({
|
|
6
|
+
theme: defaultTheme,
|
|
7
|
+
colorScheme: null
|
|
8
|
+
});
|
|
9
|
+
/** The active theme; the default theme outside a SlurpProvider. */
|
|
10
|
+
function useTheme() {
|
|
11
|
+
return useContext(SlurpContext).theme;
|
|
12
|
+
}
|
|
13
|
+
/** Colour scheme of the nearest SlurpProvider: `{ mode, setMode, resolved }`. */
|
|
14
|
+
function useColorScheme() {
|
|
15
|
+
const state = useContext(SlurpContext).colorScheme;
|
|
16
|
+
if (!state) throw new Error("Slurp: useColorScheme() needs a <SlurpProvider> above it.");
|
|
17
|
+
return state;
|
|
18
|
+
}
|
|
19
|
+
export { SlurpContext, useColorScheme, useTheme };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","names":[],"sources":["../../src/internal/context.ts"],"sourcesContent":["import { createContext, useContext } from 'react';\n\nimport {\n defaultTheme,\n type ColorSchemeMode,\n type ResolvedColorScheme,\n type Theme,\n} from '../lib/theme';\n\nexport interface ColorSchemeState {\n /** What the person chose (or the theme default): `light`, `dark` or `system`. */\n mode: ColorSchemeMode;\n setMode: (mode: ColorSchemeMode) => void;\n /** The scheme actually shown. `system` resolves through prefers-color-scheme (light during SSR). */\n resolved: ResolvedColorScheme;\n}\n\ninterface SlurpContextValue {\n theme: Theme;\n colorScheme: ColorSchemeState | null;\n}\n\nexport const SlurpContext = createContext<SlurpContextValue>({\n theme: defaultTheme,\n colorScheme: null,\n});\n\n/** The active theme; the default theme outside a SlurpProvider. */\nexport function useTheme(): Theme {\n return useContext(SlurpContext).theme;\n}\n\n/** Colour scheme of the nearest SlurpProvider: `{ mode, setMode, resolved }`. */\nexport function useColorScheme(): ColorSchemeState {\n const state = useContext(SlurpContext).colorScheme;\n if (!state) throw new Error('Slurp: useColorScheme() needs a <SlurpProvider> above it.');\n return state;\n}\n"],"mappings":";;;;AAsBA,MAAa,eAAe,cAAiC;CAC3D,OAAO;CACP,aAAa;AACf,CAAC;;AAGD,SAAgB,WAAkB;CAChC,OAAO,WAAW,YAAY,CAAC,CAAC;AAClC;;AAGA,SAAgB,iBAAmC;CACjD,MAAM,QAAQ,WAAW,YAAY,CAAC,CAAC;CACvC,IAAI,CAAC,OAAO,MAAM,IAAI,MAAM,2DAA2D;CACvF,OAAO;AACT"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { compileCss, mergeCss } from "../lib/css.js";
|
|
3
|
+
import { styleId } from "../lib/theme.js";
|
|
4
|
+
import { useTheme } from "./context.js";
|
|
5
|
+
import { cx } from "../utils/src/index.js";
|
|
6
|
+
import { useMemo } from "react";
|
|
7
|
+
import { jsx } from "react/jsx-runtime";
|
|
8
|
+
// src/internal/styled.tsx
|
|
9
|
+
/** Props with the theme's `components.<name>.defaults` filled in (explicit props win, `undefined` does not). */
|
|
10
|
+
function useThemeProps(name, props) {
|
|
11
|
+
const defaults = useTheme().components[name]?.defaults;
|
|
12
|
+
if (!defaults) return props;
|
|
13
|
+
const out = { ...defaults };
|
|
14
|
+
for (const [k, v] of Object.entries(props)) if (v !== void 0) out[k] = v;
|
|
15
|
+
return out;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Compiles the `css` of one part: theme `components.<name>.css.<part>` first, then the component's own layout css,
|
|
19
|
+
* then the instance `css`. Returns the class names and the <style> to render (React hoists it into <head>).
|
|
20
|
+
*/
|
|
21
|
+
function useCss(name, part, ...css) {
|
|
22
|
+
const themed = (useTheme().components[name]?.css)?.[part];
|
|
23
|
+
const merged = mergeCss(themed, ...css);
|
|
24
|
+
const key = merged ? JSON.stringify(merged) : "";
|
|
25
|
+
return useMemo(() => {
|
|
26
|
+
const { className, css: text } = compileCss(key ? JSON.parse(key) : void 0);
|
|
27
|
+
return {
|
|
28
|
+
className,
|
|
29
|
+
style: text ? /* @__PURE__ */ jsx("style", {
|
|
30
|
+
href: styleId("css", text),
|
|
31
|
+
precedence: "slurp",
|
|
32
|
+
children: text
|
|
33
|
+
}) : null
|
|
34
|
+
};
|
|
35
|
+
}, [key]);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Inner parts of a component: `parts` replaces the element, `partProps` adds props, `classNames` adds classes, and the
|
|
39
|
+
* theme's `components.<name>.css.<part>` styles it. `part(name, Default, own)` renders one part.
|
|
40
|
+
*/
|
|
41
|
+
function useParts(name, { parts, partProps, classNames }) {
|
|
42
|
+
const themed = useTheme().components[name]?.css;
|
|
43
|
+
const key = themed ? JSON.stringify(themed) : "";
|
|
44
|
+
const compiled = useMemo(() => {
|
|
45
|
+
const classes = {};
|
|
46
|
+
const rules = [];
|
|
47
|
+
if (key) for (const [p, style] of Object.entries(JSON.parse(key))) {
|
|
48
|
+
if (p === "root") continue;
|
|
49
|
+
const c = compileCss(style);
|
|
50
|
+
classes[p] = c.className;
|
|
51
|
+
if (c.css) rules.push(c.css);
|
|
52
|
+
}
|
|
53
|
+
const text = rules.join("");
|
|
54
|
+
return {
|
|
55
|
+
classes,
|
|
56
|
+
style: text ? /* @__PURE__ */ jsx("style", {
|
|
57
|
+
href: styleId("parts", text),
|
|
58
|
+
precedence: "slurp",
|
|
59
|
+
children: text
|
|
60
|
+
}) : null
|
|
61
|
+
};
|
|
62
|
+
}, [key]);
|
|
63
|
+
const part = (p, Default, own = {}) => {
|
|
64
|
+
const Tag = parts?.[p] ?? Default;
|
|
65
|
+
const extra = partProps?.[p];
|
|
66
|
+
return /* @__PURE__ */ jsx(Tag, {
|
|
67
|
+
...own,
|
|
68
|
+
...extra,
|
|
69
|
+
className: cx(own.className, compiled.classes[p], classNames?.[p], extra?.className)
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
return {
|
|
73
|
+
part,
|
|
74
|
+
style: compiled.style
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
export { useCss, useParts, useThemeProps };
|
|
78
|
+
|
|
79
|
+
//# sourceMappingURL=styled.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styled.js","names":[],"sources":["../../src/internal/styled.tsx"],"sourcesContent":["import { cx } from '@slurp-ui/utils';\nimport { useMemo, type ElementType, type ReactElement, type ReactNode } from 'react';\n\nimport { compileCss, mergeCss, type SlurpCss } from '../lib/css';\nimport type { PartsProps } from '../lib/polymorphic';\nimport { styleId, type ComponentName, type ThemeComponents } from '../lib/theme';\nimport { useTheme } from './context';\n\n/** Props with the theme's `components.<name>.defaults` filled in (explicit props win, `undefined` does not). */\nexport function useThemeProps<N extends ComponentName, P extends object>(name: N, props: P): P {\n const defaults = useTheme().components[name]?.defaults;\n if (!defaults) return props;\n const out: Record<string, unknown> = { ...defaults };\n for (const [k, v] of Object.entries(props)) if (v !== undefined) out[k] = v;\n return out as P;\n}\n\n/**\n * Compiles the `css` of one part: theme `components.<name>.css.<part>` first, then the component's own layout css,\n * then the instance `css`. Returns the class names and the <style> to render (React hoists it into <head>).\n */\nexport function useCss<N extends ComponentName>(\n name: N,\n part: ThemeComponents[N]['parts'],\n ...css: (SlurpCss | undefined)[]\n): { className: string; style: ReactNode } {\n const themed = (\n useTheme().components[name]?.css as Partial<Record<string, SlurpCss>> | undefined\n )?.[part];\n const merged = mergeCss(themed, ...css);\n // Serialising is cheaper than a deep comparison and keeps the memo stable across renders.\n const key = merged ? JSON.stringify(merged) : '';\n return useMemo(() => {\n const { className, css: text } = compileCss(key ? (JSON.parse(key) as SlurpCss) : undefined);\n return {\n className,\n style: text ? (\n <style href={styleId('css', text)} precedence=\"slurp\">\n {text}\n </style>\n ) : null,\n };\n }, [key]);\n}\n\ntype AnyProps = Record<string, unknown> & { className?: string };\n\n/**\n * Inner parts of a component: `parts` replaces the element, `partProps` adds props, `classNames` adds classes, and the\n * theme's `components.<name>.css.<part>` styles it. `part(name, Default, own)` renders one part.\n */\nexport function useParts<N extends ComponentName>(\n name: N,\n { parts, partProps, classNames }: PartsProps<Exclude<ThemeComponents[N]['parts'], 'root'>>,\n) {\n const themed = useTheme().components[name]?.css as Partial<Record<string, SlurpCss>> | undefined;\n const key = themed ? JSON.stringify(themed) : '';\n const compiled = useMemo(() => {\n const classes: Record<string, string> = {};\n const rules: string[] = [];\n if (key) {\n for (const [p, style] of Object.entries(JSON.parse(key) as Record<string, SlurpCss>)) {\n if (p === 'root') continue;\n const c = compileCss(style);\n classes[p] = c.className;\n if (c.css) rules.push(c.css);\n }\n }\n const text = rules.join('');\n return {\n classes,\n style: text ? (\n <style href={styleId('parts', text)} precedence=\"slurp\">\n {text}\n </style>\n ) : null,\n };\n }, [key]);\n\n const part = (\n p: Exclude<ThemeComponents[N]['parts'], 'root'>,\n Default: ElementType,\n own: AnyProps = {},\n ): ReactElement => {\n const Tag: ElementType =\n (parts as Partial<Record<string, ElementType>> | undefined)?.[p] ?? Default;\n const extra = (partProps as Partial<Record<string, AnyProps>> | undefined)?.[p];\n return (\n <Tag\n {...own}\n {...extra}\n className={cx(\n own.className,\n compiled.classes[p],\n (classNames as Partial<Record<string, string>> | undefined)?.[p],\n extra?.className,\n )}\n />\n );\n };\n return { part, style: compiled.style };\n}\n"],"mappings":";;;;;;;;;AASA,SAAgB,cAAyD,MAAS,OAAa;CAC7F,MAAM,WAAW,SAAS,CAAC,CAAC,WAAW,KAAK,EAAE;CAC9C,IAAI,CAAC,UAAU,OAAO;CACtB,MAAM,MAA+B,EAAE,GAAG,SAAS;CACnD,KAAK,MAAM,CAAC,GAAG,MAAM,OAAO,QAAQ,KAAK,GAAG,IAAI,MAAM,KAAA,GAAW,IAAI,KAAK;CAC1E,OAAO;AACT;;;;;AAMA,SAAgB,OACd,MACA,MACA,GAAG,KACsC;CACzC,MAAM,UACJ,SAAS,CAAC,CAAC,WAAW,KAAK,EAAE,IAAA,GAC3B;CACJ,MAAM,SAAS,SAAS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E;EAAM,OAAO,SAAS;CAAM;AACvC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
|
|
2
|
+
/** WCAG 2.x contrast ratio between two opaque colours (1–21). */
|
|
3
|
+
export declare function contrast(a: string, b: string): number;
|
|
4
|
+
/** Minimum ratios of WCAG 2.2 AA: text 4.5:1, large text (24px+, 19px bold) and non-text (boundaries, focus, marks) 3:1. */
|
|
5
|
+
export declare const CONTRAST_MIN: {
|
|
6
|
+
readonly text: 4.5;
|
|
7
|
+
readonly large: 3;
|
|
8
|
+
readonly ui: 3;
|
|
9
|
+
};
|
|
10
|
+
/** Whether `a` on `b` meets WCAG 2.2 AA for the given use. */
|
|
11
|
+
export declare function meetsContrast(a: string, b: string, use?: keyof typeof CONTRAST_MIN): boolean;
|
|
12
|
+
/** Ink for content on a fill: dark or white, whichever contrasts more. */
|
|
13
|
+
export declare function onColor(fill: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* Any source colour → a vivid, accessible accent: same hue, OKLCH chroma ×1.6 (within 0.17–0.26), lightness 0.64–0.74.
|
|
16
|
+
* Near-greys get chroma 0.14. Chroma is lowered until the colour fits sRGB.
|
|
17
|
+
*/
|
|
18
|
+
export declare function vivid(color: string): string;
|
|
19
|
+
/** CSS colour with `amount` (0–1) opacity: `color-mix(in oklab, <color> N%, transparent)`. Works with `var()` too. */
|
|
20
|
+
export declare function alpha(color: string, amount: number): string;
|
|
21
|
+
//# sourceMappingURL=color.d.ts.map
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
|
|
2
|
+
import { hue } from "@slurp-ui/tokens";
|
|
3
|
+
// src/lib/color.ts
|
|
4
|
+
/** Dark ink used on light fills (design system: `on-accent` dark). */
|
|
5
|
+
const INK = "#111114";
|
|
6
|
+
const WHITE = "#ffffff";
|
|
7
|
+
const clamp = (v, min, max) => Math.min(max, Math.max(min, v));
|
|
8
|
+
const lin = (c) => c <= .04045 ? c / 12.92 : ((c + .055) / 1.055) ** 2.4;
|
|
9
|
+
const delin = (c) => c <= .0031308 ? 12.92 * c : 1.055 * c ** (1 / 2.4) - .055;
|
|
10
|
+
const HEX = /^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
|
|
11
|
+
const RGB = /^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)(?:[\s,/]+([\d.]+%?))?\s*\)$/i;
|
|
12
|
+
/** Parses `#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa`, `rgb()` and `rgba()` into gamma-encoded 0–1 channels. */
|
|
13
|
+
function parse(color) {
|
|
14
|
+
const hex = HEX.exec(color.trim())?.[1];
|
|
15
|
+
if (hex) {
|
|
16
|
+
const full = hex.length <= 4 ? [...hex].map((c) => c + c).join("") : hex;
|
|
17
|
+
const n = (i) => parseInt(full.slice(i, i + 2), 16) / 255;
|
|
18
|
+
return {
|
|
19
|
+
r: n(0),
|
|
20
|
+
g: n(2),
|
|
21
|
+
b: n(4),
|
|
22
|
+
a: full.length === 8 ? n(6) : 1
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
const rgb = RGB.exec(color.trim());
|
|
26
|
+
if (rgb) {
|
|
27
|
+
const alpha = rgb[4];
|
|
28
|
+
const a = alpha === void 0 ? 1 : alpha.endsWith("%") ? parseFloat(alpha) / 100 : parseFloat(alpha);
|
|
29
|
+
return {
|
|
30
|
+
r: Number(rgb[1]) / 255,
|
|
31
|
+
g: Number(rgb[2]) / 255,
|
|
32
|
+
b: Number(rgb[3]) / 255,
|
|
33
|
+
a
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
throw new Error(`Slurp: unsupported colour "${color}" (use #hex or rgb()/rgba())`);
|
|
37
|
+
}
|
|
38
|
+
const toHex = ({ r, g, b }) => `#${[
|
|
39
|
+
r,
|
|
40
|
+
g,
|
|
41
|
+
b
|
|
42
|
+
].map((v) => Math.round(clamp(v, 0, 1) * 255).toString(16).padStart(2, "0")).join("")}`;
|
|
43
|
+
function luminance(color) {
|
|
44
|
+
const { r, g, b, a } = parse(color);
|
|
45
|
+
if (a < 1) throw new Error(`Slurp: contrast needs an opaque colour, got "${color}" (composite it first)`);
|
|
46
|
+
return .2126 * lin(r) + .7152 * lin(g) + .0722 * lin(b);
|
|
47
|
+
}
|
|
48
|
+
/** WCAG 2.x contrast ratio between two opaque colours (1–21). */
|
|
49
|
+
function contrast(a, b) {
|
|
50
|
+
const la = luminance(a);
|
|
51
|
+
const lb = luminance(b);
|
|
52
|
+
return (Math.max(la, lb) + .05) / (Math.min(la, lb) + .05);
|
|
53
|
+
}
|
|
54
|
+
/** Minimum ratios of WCAG 2.2 AA: text 4.5:1, large text (24px+, 19px bold) and non-text (boundaries, focus, marks) 3:1. */
|
|
55
|
+
const CONTRAST_MIN = {
|
|
56
|
+
text: 4.5,
|
|
57
|
+
large: 3,
|
|
58
|
+
ui: 3
|
|
59
|
+
};
|
|
60
|
+
/** Whether `a` on `b` meets WCAG 2.2 AA for the given use. */
|
|
61
|
+
function meetsContrast(a, b, use = "text") {
|
|
62
|
+
return contrast(a, b) >= CONTRAST_MIN[use];
|
|
63
|
+
}
|
|
64
|
+
/** Ink for content on a fill: dark or white, whichever contrasts more. */
|
|
65
|
+
function onColor(fill) {
|
|
66
|
+
return contrast(fill, INK) >= contrast(fill, WHITE) ? INK : WHITE;
|
|
67
|
+
}
|
|
68
|
+
function toOklab(color) {
|
|
69
|
+
const { r, g, b } = parse(color);
|
|
70
|
+
const [R, G, B] = [
|
|
71
|
+
lin(r),
|
|
72
|
+
lin(g),
|
|
73
|
+
lin(b)
|
|
74
|
+
];
|
|
75
|
+
const l = Math.cbrt(.4122214708 * R + .5363325363 * G + .0514459929 * B);
|
|
76
|
+
const m = Math.cbrt(.2119034982 * R + .6806995451 * G + .1073969566 * B);
|
|
77
|
+
const s = Math.cbrt(.0883024619 * R + .2817188376 * G + .6299787005 * B);
|
|
78
|
+
return [
|
|
79
|
+
.2104542553 * l + .793617785 * m - .0040720468 * s,
|
|
80
|
+
1.9779984951 * l - 2.428592205 * m + .4505937099 * s,
|
|
81
|
+
.0259040371 * l + .7827717662 * m - .808675766 * s
|
|
82
|
+
];
|
|
83
|
+
}
|
|
84
|
+
/** OKLab → gamma sRGB channels; `null` when out of gamut (unless `clip`). */
|
|
85
|
+
function fromOklab([L, A, B], clip = false) {
|
|
86
|
+
const l = (L + .3963377774 * A + .2158037573 * B) ** 3;
|
|
87
|
+
const m = (L - .1055613458 * A - .0638541728 * B) ** 3;
|
|
88
|
+
const s = (L - .0894841775 * A - 1.291485548 * B) ** 3;
|
|
89
|
+
const rgb = [
|
|
90
|
+
4.0767416621 * l - 3.3077115913 * m + .2309699292 * s,
|
|
91
|
+
-1.2684380046 * l + 2.6097574011 * m - .3413193965 * s,
|
|
92
|
+
-.0041960863 * l - .7034186147 * m + 1.707614701 * s
|
|
93
|
+
];
|
|
94
|
+
if (!clip && rgb.some((v) => v < -1e-4 || v > 1.0001)) return null;
|
|
95
|
+
const [r = 0, g = 0, b = 0] = rgb.map((v) => delin(clamp(v, 0, 1)));
|
|
96
|
+
return toHex({
|
|
97
|
+
r,
|
|
98
|
+
g,
|
|
99
|
+
b
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Any source colour → a vivid, accessible accent: same hue, OKLCH chroma ×1.6 (within 0.17–0.26), lightness 0.64–0.74.
|
|
104
|
+
* Near-greys get chroma 0.14. Chroma is lowered until the colour fits sRGB.
|
|
105
|
+
*/
|
|
106
|
+
function vivid(color) {
|
|
107
|
+
const [l, a, b] = toOklab(color);
|
|
108
|
+
const c = Math.hypot(a, b);
|
|
109
|
+
const h = Math.atan2(b, a);
|
|
110
|
+
const L = clamp(l, .64, .74);
|
|
111
|
+
let C = c < .02 ? .14 : clamp(c * 1.6, .17, .26);
|
|
112
|
+
let out = fromOklab([
|
|
113
|
+
L,
|
|
114
|
+
C * Math.cos(h),
|
|
115
|
+
C * Math.sin(h)
|
|
116
|
+
]);
|
|
117
|
+
while (!out && C > .02) {
|
|
118
|
+
C -= .005;
|
|
119
|
+
out = fromOklab([
|
|
120
|
+
L,
|
|
121
|
+
C * Math.cos(h),
|
|
122
|
+
C * Math.sin(h)
|
|
123
|
+
]);
|
|
124
|
+
}
|
|
125
|
+
return out ?? toHex(parse(color));
|
|
126
|
+
}
|
|
127
|
+
/** CSS colour with `amount` (0–1) opacity: `color-mix(in oklab, <color> N%, transparent)`. Works with `var()` too. */
|
|
128
|
+
function alpha(color, amount) {
|
|
129
|
+
return `color-mix(in oklab, ${color} ${Math.round(clamp(amount, 0, 1) * 1e3) / 10}%, transparent)`;
|
|
130
|
+
}
|
|
131
|
+
const isHue = (value) => value.startsWith("hue-") && value.slice(4) in hue;
|
|
132
|
+
/** `hue-*` preset → its value as is; any other colour → `vivid(colour)`. */
|
|
133
|
+
function resolveAccent(color) {
|
|
134
|
+
return isHue(color) ? hue[color.slice(4)] : vivid(color);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* The accent custom properties for one (already resolved) accent. Derived values reference `--slurp-accent`,
|
|
138
|
+
* so they follow it while it transitions and re-resolve `--slurp-fg` on the element that declares them.
|
|
139
|
+
*/
|
|
140
|
+
function accentVars(accent) {
|
|
141
|
+
return {
|
|
142
|
+
"--slurp-accent": accent,
|
|
143
|
+
"--slurp-on-accent": onColor(accent),
|
|
144
|
+
"--slurp-accent-soft": "color-mix(in oklab, var(--slurp-accent) 16%, transparent)",
|
|
145
|
+
"--slurp-accent-ink": "color-mix(in oklab, var(--slurp-accent) 45%, var(--slurp-fg))",
|
|
146
|
+
"--slurp-focus": "var(--slurp-accent-ink)"
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
export { CONTRAST_MIN, accentVars, alpha, contrast, meetsContrast, onColor, resolveAccent, vivid };
|
|
150
|
+
|
|
151
|
+
//# sourceMappingURL=color.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color.js","names":[],"sources":["../../src/lib/color.ts"],"sourcesContent":["// Colour math of the Slurp design system: WCAG contrast, OKLCH, the vivid() accent rule and the runtime accent variables.\n// Server-safe (no React, no DOM).\nimport { hue, type HueToken } from '@slurp-ui/tokens';\n\n/** Linear-light sRGB channel in 0–1 plus alpha. */\ninterface Rgba {\n r: number;\n g: number;\n b: number;\n a: number;\n}\n\n/** Dark ink used on light fills (design system: `on-accent` dark). */\nconst INK = '#111114';\nconst WHITE = '#ffffff';\n\nconst clamp = (v: number, min: number, max: number) => Math.min(max, Math.max(min, v));\nconst lin = (c: number) => (c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4);\nconst delin = (c: number) => (c <= 0.0031308 ? 12.92 * c : 1.055 * c ** (1 / 2.4) - 0.055);\n\nconst HEX = /^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;\nconst RGB = /^rgba?\\(\\s*([\\d.]+)[\\s,]+([\\d.]+)[\\s,]+([\\d.]+)(?:[\\s,/]+([\\d.]+%?))?\\s*\\)$/i;\n\n/** Parses `#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa`, `rgb()` and `rgba()` into gamma-encoded 0–1 channels. */\nfunction parse(color: string): Rgba {\n const hex = HEX.exec(color.trim())?.[1];\n if (hex) {\n const full = hex.length <= 4 ? [...hex].map((c) => c + c).join('') : hex;\n const n = (i: number) => parseInt(full.slice(i, i + 2), 16) / 255;\n return { r: n(0), g: n(2), b: n(4), a: full.length === 8 ? n(6) : 1 };\n }\n const rgb = RGB.exec(color.trim());\n if (rgb) {\n const alpha = rgb[4];\n const a =\n alpha === undefined ? 1 : alpha.endsWith('%') ? parseFloat(alpha) / 100 : parseFloat(alpha);\n return { r: Number(rgb[1]) / 255, g: Number(rgb[2]) / 255, b: Number(rgb[3]) / 255, a };\n }\n throw new Error(`Slurp: unsupported colour \"${color}\" (use #hex or rgb()/rgba())`);\n}\n\nconst toHex = ({ r, g, b }: Pick<Rgba, 'r' | 'g' | 'b'>): string =>\n `#${[r, g, b]\n .map((v) =>\n Math.round(clamp(v, 0, 1) * 255)\n .toString(16)\n .padStart(2, '0'),\n )\n .join('')}`;\n\nfunction luminance(color: string): number {\n const { r, g, b, a } = parse(color);\n if (a < 1)\n throw new Error(`Slurp: contrast needs an opaque colour, got \"${color}\" (composite it first)`);\n return 0.2126 * lin(r) + 0.7152 * lin(g) + 0.0722 * lin(b);\n}\n\n/** WCAG 2.x contrast ratio between two opaque colours (1–21). */\nexport function contrast(a: string, b: string): number {\n const la = luminance(a);\n const lb = luminance(b);\n return (Math.max(la, lb) + 0.05) / (Math.min(la, lb) + 0.05);\n}\n\n/** Minimum ratios of WCAG 2.2 AA: text 4.5:1, large text (24px+, 19px bold) and non-text (boundaries, focus, marks) 3:1. */\nexport const CONTRAST_MIN = { text: 4.5, large: 3, ui: 3 } as const;\n\n/** Whether `a` on `b` meets WCAG 2.2 AA for the given use. */\nexport function meetsContrast(\n a: string,\n b: string,\n use: keyof typeof CONTRAST_MIN = 'text',\n): boolean {\n return contrast(a, b) >= CONTRAST_MIN[use];\n}\n\n/** Ink for content on a fill: dark or white, whichever contrasts more. */\nexport function onColor(fill: string): string {\n return contrast(fill, INK) >= contrast(fill, WHITE) ? INK : WHITE;\n}\n\ntype Lab = [l: number, a: number, b: number];\n\nfunction toOklab(color: string): Lab {\n const { r, g, b } = parse(color);\n const [R, G, B] = [lin(r), lin(g), lin(b)];\n const l = Math.cbrt(0.4122214708 * R + 0.5363325363 * G + 0.0514459929 * B);\n const m = Math.cbrt(0.2119034982 * R + 0.6806995451 * G + 0.1073969566 * B);\n const s = Math.cbrt(0.0883024619 * R + 0.2817188376 * G + 0.6299787005 * B);\n return [\n 0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s,\n 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s,\n 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s,\n ];\n}\n\n/** OKLab → gamma sRGB channels; `null` when out of gamut (unless `clip`). */\nfunction fromOklab([L, A, B]: Lab, clip = false): string | null {\n const l = (L + 0.3963377774 * A + 0.2158037573 * B) ** 3;\n const m = (L - 0.1055613458 * A - 0.0638541728 * B) ** 3;\n const s = (L - 0.0894841775 * A - 1.291485548 * B) ** 3;\n const rgb = [\n 4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,\n -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,\n -0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s,\n ];\n if (!clip && rgb.some((v) => v < -0.0001 || v > 1.0001)) return null;\n const [r = 0, g = 0, b = 0] = rgb.map((v) => delin(clamp(v, 0, 1)));\n return toHex({ r, g, b });\n}\n\n/**\n * Any source colour → a vivid, accessible accent: same hue, OKLCH chroma ×1.6 (within 0.17–0.26), lightness 0.64–0.74.\n * Near-greys get chroma 0.14. Chroma is lowered until the colour fits sRGB.\n */\nexport function vivid(color: string): string {\n const [l, a, b] = toOklab(color);\n const c = Math.hypot(a, b);\n const h = Math.atan2(b, a);\n const L = clamp(l, 0.64, 0.74);\n let C = c < 0.02 ? 0.14 : clamp(c * 1.6, 0.17, 0.26);\n let out = fromOklab([L, C * Math.cos(h), C * Math.sin(h)]);\n while (!out && C > 0.02) {\n C -= 0.005;\n out = fromOklab([L, C * Math.cos(h), C * Math.sin(h)]);\n }\n return out ?? toHex(parse(color));\n}\n\n/** CSS colour with `amount` (0–1) opacity: `color-mix(in oklab, <color> N%, transparent)`. Works with `var()` too. */\nexport function alpha(color: string, amount: number): string {\n return `color-mix(in oklab, ${color} ${Math.round(clamp(amount, 0, 1) * 1000) / 10}%, transparent)`;\n}\n\n/** `color-mix(in oklab, a weight, b)` computed in JS (for checks; the browser does it at runtime). */\nexport function mix(a: string, b: string, weight: number): string {\n const [la, aa, ba] = toOklab(a);\n const [lb, ab, bb] = toOklab(b);\n const t = clamp(weight, 0, 1);\n return fromOklab([lb + (la - lb) * t, ab + (aa - ab) * t, bb + (ba - bb) * t], true) as string;\n}\n\n/** A translucent colour painted over an opaque one (sRGB source-over), e.g. `surface` over the ground. */\nexport function composite(top: string, bottom: string): string {\n const t = parse(top);\n const u = parse(bottom);\n return toHex({\n r: t.r * t.a + u.r * (1 - t.a),\n g: t.g * t.a + u.g * (1 - t.a),\n b: t.b * t.a + u.b * (1 - t.a),\n });\n}\n\nconst isHue = (value: string): value is `hue-${HueToken}` =>\n value.startsWith('hue-') && value.slice(4) in hue;\n\n/** `hue-*` preset → its value as is; any other colour → `vivid(colour)`. */\nexport function resolveAccent(color: string): string {\n return isHue(color) ? hue[color.slice(4) as HueToken] : vivid(color);\n}\n\n/**\n * The accent custom properties for one (already resolved) accent. Derived values reference `--slurp-accent`,\n * so they follow it while it transitions and re-resolve `--slurp-fg` on the element that declares them.\n */\nexport function accentVars(accent: string): Record<string, string> {\n return {\n '--slurp-accent': accent,\n '--slurp-on-accent': onColor(accent),\n '--slurp-accent-soft': 'color-mix(in oklab, var(--slurp-accent) 16%, transparent)',\n '--slurp-accent-ink': 'color-mix(in oklab, var(--slurp-accent) 45%, var(--slurp-fg))',\n '--slurp-focus': 'var(--slurp-accent-ink)',\n };\n}\n"],"mappings":";;;;AAaA,MAAM,MAAM;AACZ,MAAM,QAAQ;AAEd,MAAM,SAAS,GAAW,KAAa,QAAgB,KAAK,IAAI,KAAK,KAAK,IAAI,KAAK,CAAC,CAAC;AACrF,MAAM,OAAO,MAAe,KAAK,SAAU,IAAI,UAAU,IAAI,QAAS,UAAU;AAChF,MAAM,SAAS,MAAe,KAAK,WAAY,QAAQ,IAAI,QAAQ,MAAM,IAAI,OAAO;AAEpF,MAAM,MAAM;AACZ,MAAM,MAAM;;AAGZ,SAAS,MAAM,OAAqB;CAClC,MAAM,MAAM,IAAI,KAAK,MAAM,KAAK,CAAC,CAAC,GAAG;CACrC,IAAI,KAAK;EACP,MAAM,OAAO,IAAI,UAAU,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,KAAK,MAAM,IAAI,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI;EACrE,MAAM,KAAK,M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4
|
+
* One SVG path for a breadcrumb piece of size w×h. Each end is `round` (a semicircle) or `slant` (a 20° cut with
|
|
5
|
+
* rounded corners), centred on the box edge like skewX, so two neighbouring cuts stay parallel. The SVG is
|
|
6
|
+
* w + h·tan20° wide, shifted left by half of that.
|
|
7
|
+
*/
|
|
8
|
+
export declare function crumbPath(w: number, h: number, left: CrumbEnd, right: CrumbEnd, radius?: number): string;
|
|
9
|
+
//# sourceMappingURL=crumb.d.ts.map
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
|
|
2
|
+
// src/lib/crumb.ts
|
|
3
|
+
/** Slant of the cut between two crumbs: 20°. */
|
|
4
|
+
const CRUMB_TAN = Math.tan(20 * Math.PI / 180);
|
|
5
|
+
/**
|
|
6
|
+
* One SVG path for a breadcrumb piece of size w×h. Each end is `round` (a semicircle) or `slant` (a 20° cut with
|
|
7
|
+
* rounded corners), centred on the box edge like skewX, so two neighbouring cuts stay parallel. The SVG is
|
|
8
|
+
* w + h·tan20° wide, shifted left by half of that.
|
|
9
|
+
*/
|
|
10
|
+
function crumbPath(w, h, left, right, radius = 12) {
|
|
11
|
+
const s = h * CRUMB_TAN;
|
|
12
|
+
const o = s / 2;
|
|
13
|
+
const cap = h / 2;
|
|
14
|
+
const pts = [
|
|
15
|
+
left === "round" ? [
|
|
16
|
+
o,
|
|
17
|
+
0,
|
|
18
|
+
cap
|
|
19
|
+
] : [
|
|
20
|
+
s,
|
|
21
|
+
0,
|
|
22
|
+
radius
|
|
23
|
+
],
|
|
24
|
+
right === "round" ? [
|
|
25
|
+
o + w,
|
|
26
|
+
0,
|
|
27
|
+
cap
|
|
28
|
+
] : [
|
|
29
|
+
o + w + o,
|
|
30
|
+
0,
|
|
31
|
+
radius
|
|
32
|
+
],
|
|
33
|
+
right === "round" ? [
|
|
34
|
+
o + w,
|
|
35
|
+
h,
|
|
36
|
+
cap
|
|
37
|
+
] : [
|
|
38
|
+
w,
|
|
39
|
+
h,
|
|
40
|
+
radius
|
|
41
|
+
],
|
|
42
|
+
left === "round" ? [
|
|
43
|
+
o,
|
|
44
|
+
h,
|
|
45
|
+
cap
|
|
46
|
+
] : [
|
|
47
|
+
0,
|
|
48
|
+
h,
|
|
49
|
+
radius
|
|
50
|
+
]
|
|
51
|
+
];
|
|
52
|
+
const k = .5523;
|
|
53
|
+
const f = (v) => v.toFixed(2);
|
|
54
|
+
let d = "";
|
|
55
|
+
pts.forEach((p, i) => {
|
|
56
|
+
const pr = pts[(i + pts.length - 1) % pts.length];
|
|
57
|
+
const nx = pts[(i + 1) % pts.length];
|
|
58
|
+
const lp = Math.hypot(pr[0] - p[0], pr[1] - p[1]);
|
|
59
|
+
const ln = Math.hypot(nx[0] - p[0], nx[1] - p[1]);
|
|
60
|
+
const r = Math.min(p[2], lp / 2, ln / 2);
|
|
61
|
+
const a = [p[0] + (pr[0] - p[0]) / lp * r, p[1] + (pr[1] - p[1]) / lp * r];
|
|
62
|
+
const b = [p[0] + (nx[0] - p[0]) / ln * r, p[1] + (nx[1] - p[1]) / ln * r];
|
|
63
|
+
d += `${i ? "L" : "M"}${f(a[0])} ${f(a[1])}C${f(a[0] + (p[0] - a[0]) * k)} ${f(a[1] + (p[1] - a[1]) * k)} ${f(b[0] + (p[0] - b[0]) * k)} ${f(b[1] + (p[1] - b[1]) * k)} ${f(b[0])} ${f(b[1])}`;
|
|
64
|
+
});
|
|
65
|
+
return `${d}Z`;
|
|
66
|
+
}
|
|
67
|
+
export { CRUMB_TAN, crumbPath };
|
|
68
|
+
|
|
69
|
+
//# sourceMappingURL=crumb.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crumb.js","names":[],"sources":["../../src/lib/crumb.ts"],"sourcesContent":["/** Slant of the cut between two crumbs: 20°. */\nexport const CRUMB_TAN = Math.tan((20 * Math.PI) / 180);\n\nexport type CrumbEnd = 'round' | 'slant';\n\n/**\n * One SVG path for a breadcrumb piece of size w×h. Each end is `round` (a semicircle) or `slant` (a 20° cut with\n * rounded corners), centred on the box edge like skewX, so two neighbouring cuts stay parallel. The SVG is\n * w + h·tan20° wide, shifted left by half of that.\n */\nexport function crumbPath(\n w: number,\n h: number,\n left: CrumbEnd,\n right: CrumbEnd,\n radius = 12,\n): string {\n const s = h * CRUMB_TAN;\n const o = s / 2;\n const cap = h / 2;\n const pts: [number, number, number][] = [\n left === 'round' ? [o, 0, cap] : [s, 0, radius],\n right === 'round' ? [o + w, 0, cap] : [o + w + o, 0, radius],\n right === 'round' ? [o + w, h, cap] : [w, h, radius],\n left === 'round' ? [o, h, cap] : [0, h, radius],\n ];\n const k = 0.5523;\n const f = (v: number) => v.toFixed(2);\n let d = '';\n pts.forEach((p, i) => {\n const pr = pts[(i + pts.length - 1) % pts.length] as [number, number, number];\n const nx = pts[(i + 1) % pts.length] as [number, number, number];\n const lp = Math.hypot(pr[0] - p[0], pr[1] - p[1]);\n const ln = Math.hypot(nx[0] - p[0], nx[1] - p[1]);\n const r = Math.min(p[2], lp / 2, ln / 2);\n const a = [p[0] + ((pr[0] - p[0]) / lp) * r, p[1] + ((pr[1] - p[1]) / lp) * r] as const;\n const b = [p[0] + ((nx[0] - p[0]) / ln) * r, p[1] + ((nx[1] - p[1]) / ln) * r] as const;\n d +=\n `${i ? 'L' : 'M'}${f(a[0])} ${f(a[1])}` +\n `C${f(a[0] + (p[0] - a[0]) * k)} ${f(a[1] + (p[1] - a[1]) * k)} ` +\n `${f(b[0] + (p[0] - b[0]) * k)} ${f(b[1] + (p[1] - b[1]) * k)} ${f(b[0])} ${f(b[1])}`;\n });\n return `${d}Z`;\n}\n"],"mappings":";;;AACA,MAAa,YAAY,KAAK,IAAK,KAAK,KAAK,KAAM,GAAG;;;;;;AAStD,SAAgB,UACd,GACA,GACA,MACA,OACA,SAAS,IACD;CACR,MAAM,IAAI,IAAI;CACd,MAAM,IAAI,IAAI;CACd,MAAM,MAAM,IAAI;CAChB,MAAM,MAAkC;EACtC,SAAS,UAAU;GAAC;GAAG;GAAG;EAAG,IAAI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,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE;CACtF,CAAC;CACD,OAAO,GAAG,EAAE;AACd"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
|
|
2
|
+
import { CSSProperties } from "react";
|
|
3
|
+
import { ColorToken, FontToken, HueToken, RadiusToken, SpaceToken, shadow } from "@slurp-ui/tokens";
|
|
4
|
+
/** Breakpoint keys: `compact` is the design system's phone layout (COMPACT_QUERY), `wide` everything above it. */
|
|
5
|
+
export interface Responsive<T> {
|
|
6
|
+
base?: T;
|
|
7
|
+
compact?: T;
|
|
8
|
+
wide?: T;
|
|
9
|
+
}
|
|
10
|
+
export type MaybeResponsive<T> = T | Responsive<T>;
|
|
11
|
+
type SpaceStep = SpaceToken extends `${infer N extends number}` ? N : never;
|
|
12
|
+
/** A step of the space scale (`4` → `var(--slurp-space-4)`), or any CSS length. */
|
|
13
|
+
export type SpaceValue = SpaceStep | (string & {}) | (number & {});
|
|
14
|
+
/** A colour token (`'accent-soft'`, `'hue-teal'`), or any CSS colour. */
|
|
15
|
+
export type ColorValue = ColorToken | `hue-${HueToken}` | (string & {});
|
|
16
|
+
export type RadiusValue = RadiusToken | (string & {}) | (number & {});
|
|
17
|
+
interface TokenProps {
|
|
18
|
+
p?: MaybeResponsive<SpaceValue>;
|
|
19
|
+
px?: MaybeResponsive<SpaceValue>;
|
|
20
|
+
py?: MaybeResponsive<SpaceValue>;
|
|
21
|
+
pt?: MaybeResponsive<SpaceValue>;
|
|
22
|
+
pr?: MaybeResponsive<SpaceValue>;
|
|
23
|
+
pb?: MaybeResponsive<SpaceValue>;
|
|
24
|
+
pl?: MaybeResponsive<SpaceValue>;
|
|
25
|
+
m?: MaybeResponsive<SpaceValue>;
|
|
26
|
+
mx?: MaybeResponsive<SpaceValue>;
|
|
27
|
+
my?: MaybeResponsive<SpaceValue>;
|
|
28
|
+
mt?: MaybeResponsive<SpaceValue>;
|
|
29
|
+
mr?: MaybeResponsive<SpaceValue>;
|
|
30
|
+
mb?: MaybeResponsive<SpaceValue>;
|
|
31
|
+
ml?: MaybeResponsive<SpaceValue>;
|
|
32
|
+
gap?: MaybeResponsive<SpaceValue>;
|
|
33
|
+
rowGap?: MaybeResponsive<SpaceValue>;
|
|
34
|
+
columnGap?: MaybeResponsive<SpaceValue>;
|
|
35
|
+
bg?: MaybeResponsive<ColorValue>;
|
|
36
|
+
color?: MaybeResponsive<ColorValue>;
|
|
37
|
+
borderColor?: MaybeResponsive<ColorValue>;
|
|
38
|
+
outlineColor?: MaybeResponsive<ColorValue>;
|
|
39
|
+
fill?: MaybeResponsive<ColorValue>;
|
|
40
|
+
stroke?: MaybeResponsive<ColorValue>;
|
|
41
|
+
radius?: MaybeResponsive<RadiusValue>;
|
|
42
|
+
/** A type style: sets `font` and `letter-spacing`. */
|
|
43
|
+
font?: MaybeResponsive<FontToken>;
|
|
44
|
+
shadow?: MaybeResponsive<keyof typeof shadow | (string & {})>;
|
|
45
|
+
}
|
|
46
|
+
type PlainProps = { [K in Exclude<keyof CSSProperties, keyof TokenProps>]?: MaybeResponsive<CSSProperties[K]>; };
|
|
47
|
+
/** Style object of the `css` prop. Keys starting with `&` are nested selectors (`'&:hover'`, `'& .slurp-card-media'`). */
|
|
48
|
+
export type SlurpCss = TokenProps & PlainProps & {
|
|
49
|
+
[selector: `&${string}`]: SlurpCss | undefined;
|
|
50
|
+
[customProperty: `--${string}`]: MaybeResponsive<string | number> | undefined;
|
|
51
|
+
};
|
|
52
|
+
export {};
|
|
53
|
+
//# sourceMappingURL=css.d.ts.map
|