menhir 0.0.0 → 0.1.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 +0 -28
- package/README.md +44 -1
- package/dist/accordion/header/AccordionHeader.js +22 -0
- package/dist/accordion/index.js +2 -0
- package/dist/accordion/index.parts.js +6 -0
- package/dist/accordion/item/AccordionItem.js +51 -0
- package/dist/accordion/item/AccordionItemContext.js +10 -0
- package/dist/accordion/panel/AccordionPanel.js +32 -0
- package/dist/accordion/root/AccordionRoot.js +45 -0
- package/dist/accordion/root/AccordionRootContext.js +10 -0
- package/dist/accordion/trigger/AccordionTrigger.js +39 -0
- package/dist/checkbox/index.js +2 -0
- package/dist/checkbox/index.parts.js +3 -0
- package/dist/checkbox/indicator/CheckboxIndicator.js +20 -0
- package/dist/checkbox/root/CheckboxRoot.js +136 -0
- package/dist/checkbox/root/CheckboxRootContext.js +10 -0
- package/dist/collapsible/index.js +2 -0
- package/dist/collapsible/index.parts.js +4 -0
- package/dist/collapsible/panel/CollapsiblePanel.js +27 -0
- package/dist/collapsible/root/CollapsibleRoot.js +53 -0
- package/dist/collapsible/root/CollapsibleRootContext.js +10 -0
- package/dist/collapsible/trigger/CollapsibleTrigger.js +31 -0
- package/dist/color-scheme/colorScheme.js +28 -0
- package/dist/color-scheme/colorSchemeScript.js +18 -0
- package/dist/color-scheme/cookie/cookie.js +50 -0
- package/dist/color-scheme/cookie/index.js +3 -0
- package/dist/color-scheme/createColorScheme.js +41 -0
- package/dist/color-scheme/local-storage/index.js +3 -0
- package/dist/color-scheme/local-storage/localStorage.js +38 -0
- package/dist/core/button.js +56 -0
- package/dist/core/createControllableSignal.js +50 -0
- package/dist/core/listValue.js +49 -0
- package/dist/core/mergeElementProps.js +67 -0
- package/dist/core/preference/cookiePreference.js +44 -0
- package/dist/core/preference/createPreference.js +60 -0
- package/dist/core/preference/localStoragePreference.js +28 -0
- package/dist/core/preference/preference.js +21 -0
- package/dist/core/preference/preferenceScript.js +12 -0
- package/dist/core/range.js +53 -0
- package/dist/core/renderElement.js +14 -0
- package/dist/core/rovingFocus.js +50 -0
- package/dist/core/toggleButton.js +37 -0
- package/dist/meter/index.js +2 -0
- package/dist/meter/index.parts.js +3 -0
- package/dist/meter/root/MeterRoot.js +28 -0
- package/dist/meter/root/MeterRootContext.js +10 -0
- package/dist/meter/value/MeterValue.js +24 -0
- package/dist/progress/index.js +2 -0
- package/dist/progress/index.parts.js +4 -0
- package/dist/progress/indicator/ProgressIndicator.js +21 -0
- package/dist/progress/root/ProgressRoot.js +47 -0
- package/dist/progress/root/ProgressRootContext.js +10 -0
- package/dist/progress/value/ProgressValue.js +26 -0
- package/dist/separator/index.js +2 -0
- package/dist/separator/index.parts.js +1 -0
- package/dist/separator/root/SeparatorRoot.js +31 -0
- package/dist/source/accordion/header/AccordionHeader.d.ts +11 -0
- package/dist/source/accordion/header/AccordionHeader.jsx +14 -0
- package/dist/source/accordion/index.d.ts +1 -0
- package/dist/source/accordion/index.js +1 -0
- package/dist/source/accordion/index.parts.d.ts +5 -0
- package/dist/source/accordion/index.parts.js +5 -0
- package/dist/source/accordion/item/AccordionItem.d.ts +17 -0
- package/dist/source/accordion/item/AccordionItem.jsx +42 -0
- package/dist/source/accordion/item/AccordionItemContext.d.ts +33 -0
- package/dist/source/accordion/item/AccordionItemContext.js +12 -0
- package/dist/source/accordion/panel/AccordionPanel.d.ts +11 -0
- package/dist/source/accordion/panel/AccordionPanel.jsx +27 -0
- package/dist/source/accordion/root/AccordionRoot.d.ts +26 -0
- package/dist/source/accordion/root/AccordionRoot.jsx +37 -0
- package/dist/source/accordion/root/AccordionRootContext.d.ts +11 -0
- package/dist/source/accordion/root/AccordionRootContext.js +13 -0
- package/dist/source/accordion/trigger/AccordionTrigger.d.ts +10 -0
- package/dist/source/accordion/trigger/AccordionTrigger.jsx +35 -0
- package/dist/source/checkbox/index.d.ts +1 -0
- package/dist/source/checkbox/index.js +1 -0
- package/dist/source/checkbox/index.parts.d.ts +2 -0
- package/dist/source/checkbox/index.parts.js +2 -0
- package/dist/source/checkbox/indicator/CheckboxIndicator.d.ts +10 -0
- package/dist/source/checkbox/indicator/CheckboxIndicator.jsx +12 -0
- package/dist/source/checkbox/root/CheckboxRoot.d.ts +37 -0
- package/dist/source/checkbox/root/CheckboxRoot.jsx +135 -0
- package/dist/source/checkbox/root/CheckboxRootContext.d.ts +16 -0
- package/dist/source/checkbox/root/CheckboxRootContext.js +13 -0
- package/dist/source/collapsible/index.d.ts +1 -0
- package/dist/source/collapsible/index.js +1 -0
- package/dist/source/collapsible/index.parts.d.ts +3 -0
- package/dist/source/collapsible/index.parts.js +3 -0
- package/dist/source/collapsible/panel/CollapsiblePanel.d.ts +10 -0
- package/dist/source/collapsible/panel/CollapsiblePanel.jsx +22 -0
- package/dist/source/collapsible/root/CollapsibleRoot.d.ts +21 -0
- package/dist/source/collapsible/root/CollapsibleRoot.jsx +42 -0
- package/dist/source/collapsible/root/CollapsibleRootContext.d.ts +26 -0
- package/dist/source/collapsible/root/CollapsibleRootContext.js +13 -0
- package/dist/source/collapsible/trigger/CollapsibleTrigger.d.ts +10 -0
- package/dist/source/collapsible/trigger/CollapsibleTrigger.jsx +23 -0
- package/dist/source/color-scheme/colorScheme.d.ts +35 -0
- package/dist/source/color-scheme/colorScheme.js +30 -0
- package/dist/source/color-scheme/colorSchemeScript.d.ts +8 -0
- package/dist/source/color-scheme/colorSchemeScript.js +16 -0
- package/dist/source/color-scheme/cookie/cookie.d.ts +39 -0
- package/dist/source/color-scheme/cookie/cookie.js +48 -0
- package/dist/source/color-scheme/cookie/index.d.ts +4 -0
- package/dist/source/color-scheme/cookie/index.js +2 -0
- package/dist/source/color-scheme/createColorScheme.d.ts +26 -0
- package/dist/source/color-scheme/createColorScheme.js +44 -0
- package/dist/source/color-scheme/local-storage/index.d.ts +4 -0
- package/dist/source/color-scheme/local-storage/index.js +2 -0
- package/dist/source/color-scheme/local-storage/localStorage.d.ts +30 -0
- package/dist/source/color-scheme/local-storage/localStorage.js +36 -0
- package/dist/source/core/button.d.ts +53 -0
- package/dist/source/core/button.js +61 -0
- package/dist/source/core/createControllableSignal.d.ts +27 -0
- package/dist/source/core/createControllableSignal.js +74 -0
- package/dist/source/core/index.d.ts +1 -0
- package/dist/source/core/index.js +1 -0
- package/dist/source/core/listValue.d.ts +32 -0
- package/dist/source/core/listValue.js +51 -0
- package/dist/source/core/mergeElementProps.d.ts +19 -0
- package/dist/source/core/mergeElementProps.js +91 -0
- package/dist/source/core/preference/cookiePreference.d.ts +10 -0
- package/dist/source/core/preference/cookiePreference.js +57 -0
- package/dist/source/core/preference/createPreference.d.ts +44 -0
- package/dist/source/core/preference/createPreference.js +60 -0
- package/dist/source/core/preference/localStoragePreference.d.ts +3 -0
- package/dist/source/core/preference/localStoragePreference.js +36 -0
- package/dist/source/core/preference/preference.d.ts +40 -0
- package/dist/source/core/preference/preference.js +22 -0
- package/dist/source/core/preference/preferenceScript.d.ts +17 -0
- package/dist/source/core/preference/preferenceScript.js +13 -0
- package/dist/source/core/range.d.ts +52 -0
- package/dist/source/core/range.js +60 -0
- package/dist/source/core/renderElement.d.ts +25 -0
- package/dist/source/core/renderElement.jsx +11 -0
- package/dist/source/core/rovingFocus.d.ts +42 -0
- package/dist/source/core/rovingFocus.js +71 -0
- package/dist/source/core/toggleButton.d.ts +22 -0
- package/dist/source/core/toggleButton.js +35 -0
- package/dist/source/meter/index.d.ts +1 -0
- package/dist/source/meter/index.js +1 -0
- package/dist/source/meter/index.parts.d.ts +2 -0
- package/dist/source/meter/index.parts.js +2 -0
- package/dist/source/meter/root/MeterRoot.d.ts +27 -0
- package/dist/source/meter/root/MeterRoot.jsx +15 -0
- package/dist/source/meter/root/MeterRootContext.d.ts +9 -0
- package/dist/source/meter/root/MeterRootContext.js +13 -0
- package/dist/source/meter/value/MeterValue.d.ts +11 -0
- package/dist/source/meter/value/MeterValue.jsx +19 -0
- package/dist/source/progress/index.d.ts +1 -0
- package/dist/source/progress/index.js +1 -0
- package/dist/source/progress/index.parts.d.ts +3 -0
- package/dist/source/progress/index.parts.js +3 -0
- package/dist/source/progress/indicator/ProgressIndicator.d.ts +11 -0
- package/dist/source/progress/indicator/ProgressIndicator.jsx +13 -0
- package/dist/source/progress/root/ProgressRoot.d.ts +30 -0
- package/dist/source/progress/root/ProgressRoot.jsx +32 -0
- package/dist/source/progress/root/ProgressRootContext.d.ts +20 -0
- package/dist/source/progress/root/ProgressRootContext.js +13 -0
- package/dist/source/progress/value/ProgressValue.d.ts +12 -0
- package/dist/source/progress/value/ProgressValue.jsx +20 -0
- package/dist/source/separator/index.d.ts +1 -0
- package/dist/source/separator/index.js +1 -0
- package/dist/source/separator/index.parts.d.ts +1 -0
- package/dist/source/separator/index.parts.js +1 -0
- package/dist/source/separator/root/SeparatorRoot.d.ts +12 -0
- package/dist/source/separator/root/SeparatorRoot.jsx +26 -0
- package/dist/source/switch/index.d.ts +1 -0
- package/dist/source/switch/index.js +1 -0
- package/dist/source/switch/index.parts.d.ts +2 -0
- package/dist/source/switch/index.parts.js +2 -0
- package/dist/source/switch/root/SwitchRoot.d.ts +31 -0
- package/dist/source/switch/root/SwitchRoot.jsx +124 -0
- package/dist/source/switch/root/SwitchRootContext.d.ts +14 -0
- package/dist/source/switch/root/SwitchRootContext.js +13 -0
- package/dist/source/switch/thumb/SwitchThumb.d.ts +10 -0
- package/dist/source/switch/thumb/SwitchThumb.jsx +12 -0
- package/dist/source/tabs/index.d.ts +1 -0
- package/dist/source/tabs/index.js +1 -0
- package/dist/source/tabs/index.parts.d.ts +4 -0
- package/dist/source/tabs/index.parts.js +4 -0
- package/dist/source/tabs/list/TabsList.d.ts +11 -0
- package/dist/source/tabs/list/TabsList.jsx +27 -0
- package/dist/source/tabs/panel/TabsPanel.d.ts +12 -0
- package/dist/source/tabs/panel/TabsPanel.jsx +38 -0
- package/dist/source/tabs/root/TabsRoot.d.ts +30 -0
- package/dist/source/tabs/root/TabsRoot.jsx +74 -0
- package/dist/source/tabs/root/TabsRootContext.d.ts +47 -0
- package/dist/source/tabs/root/TabsRootContext.js +13 -0
- package/dist/source/tabs/tab/TabsTab.d.ts +20 -0
- package/dist/source/tabs/tab/TabsTab.jsx +77 -0
- package/dist/source/theme/cookie/cookie.d.ts +34 -0
- package/dist/source/theme/cookie/cookie.js +42 -0
- package/dist/source/theme/cookie/index.d.ts +2 -0
- package/dist/source/theme/cookie/index.js +1 -0
- package/dist/source/theme/local-storage/index.d.ts +2 -0
- package/dist/source/theme/local-storage/index.js +1 -0
- package/dist/source/theme/local-storage/localStorage.d.ts +28 -0
- package/dist/source/theme/local-storage/localStorage.js +34 -0
- package/dist/source/theme/theme.d.ts +46 -0
- package/dist/source/theme/theme.js +57 -0
- package/dist/source/toggle/index.d.ts +1 -0
- package/dist/source/toggle/index.js +1 -0
- package/dist/source/toggle/index.parts.d.ts +1 -0
- package/dist/source/toggle/index.parts.js +1 -0
- package/dist/source/toggle/root/ToggleRoot.d.ts +20 -0
- package/dist/source/toggle/root/ToggleRoot.jsx +30 -0
- package/dist/source/toggle-group/index.d.ts +1 -0
- package/dist/source/toggle-group/index.js +1 -0
- package/dist/source/toggle-group/index.parts.d.ts +2 -0
- package/dist/source/toggle-group/index.parts.js +2 -0
- package/dist/source/toggle-group/item/ToggleGroupItem.d.ts +14 -0
- package/dist/source/toggle-group/item/ToggleGroupItem.jsx +39 -0
- package/dist/source/toggle-group/root/ToggleGroupRoot.d.ts +28 -0
- package/dist/source/toggle-group/root/ToggleGroupRoot.jsx +68 -0
- package/dist/source/toggle-group/root/ToggleGroupRootContext.d.ts +25 -0
- package/dist/source/toggle-group/root/ToggleGroupRootContext.js +13 -0
- package/dist/switch/index.js +2 -0
- package/dist/switch/index.parts.js +3 -0
- package/dist/switch/root/SwitchRoot.js +129 -0
- package/dist/switch/root/SwitchRootContext.js +10 -0
- package/dist/switch/thumb/SwitchThumb.js +20 -0
- package/dist/tabs/index.js +2 -0
- package/dist/tabs/index.parts.js +5 -0
- package/dist/tabs/list/TabsList.js +33 -0
- package/dist/tabs/panel/TabsPanel.js +40 -0
- package/dist/tabs/root/TabsRoot.js +74 -0
- package/dist/tabs/root/TabsRootContext.js +10 -0
- package/dist/tabs/tab/TabsTab.js +74 -0
- package/dist/theme/cookie/cookie.js +44 -0
- package/dist/theme/cookie/index.js +1 -0
- package/dist/theme/local-storage/index.js +1 -0
- package/dist/theme/local-storage/localStorage.js +36 -0
- package/dist/theme/theme.js +52 -0
- package/dist/toggle/index.js +2 -0
- package/dist/toggle/index.parts.js +1 -0
- package/dist/toggle/root/ToggleRoot.js +38 -0
- package/dist/toggle-group/index.js +2 -0
- package/dist/toggle-group/index.parts.js +3 -0
- package/dist/toggle-group/item/ToggleGroupItem.js +48 -0
- package/dist/toggle-group/root/ToggleGroupRoot.js +71 -0
- package/dist/toggle-group/root/ToggleGroupRootContext.js +10 -0
- package/package.json +99 -6
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { scriptLiteral } from "../core/preference/preference.js";
|
|
2
|
+
import { preferenceScript } from "../core/preference/preferenceScript.js";
|
|
3
|
+
import { darkQuery, resolvedSchemes } from "./colorScheme.js";
|
|
4
|
+
// src/color-scheme/colorSchemeScript.ts
|
|
5
|
+
/**
|
|
6
|
+
* `colorSchemeScript` of each entry point, with the entry point's storage: the
|
|
7
|
+
* source of a script for the document head that applies the saved choice,
|
|
8
|
+
* or the system preference, before the page first paints.
|
|
9
|
+
*/
|
|
10
|
+
function colorSchemeScriptWithStorage(storage, options = {}) {
|
|
11
|
+
return preferenceScript(storage, {
|
|
12
|
+
storageKey: options.storageKey ?? "color-scheme",
|
|
13
|
+
attribute: options.attribute ?? "data-color-scheme",
|
|
14
|
+
values: resolvedSchemes,
|
|
15
|
+
fallback: `matchMedia(${scriptLiteral(darkQuery)}).matches?"dark":"light"`
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
export { colorSchemeScriptWithStorage };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { cookiePreference, cookieValue } from "../../core/preference/cookiePreference.js";
|
|
2
|
+
import { parseColorScheme } from "../colorScheme.js";
|
|
3
|
+
import { colorSchemeScriptWithStorage } from "../colorSchemeScript.js";
|
|
4
|
+
import { createColorSchemeWithStorage } from "../createColorScheme.js";
|
|
5
|
+
// src/color-scheme/cookie/cookie.ts
|
|
6
|
+
var storage = cookiePreference;
|
|
7
|
+
/**
|
|
8
|
+
* The reader's light, dark or system choice, saved in a cookie and applied
|
|
9
|
+
* to `<html>` (`ColorSchemeOptions.attribute`). Follows the system preference
|
|
10
|
+
* while the choice is `system`, and stays in step with the other instances
|
|
11
|
+
* in this tab, and with other tabs once they are shown again.
|
|
12
|
+
*
|
|
13
|
+
* Call it in a component. The cookie is read during the first render, on
|
|
14
|
+
* the server from the request (`getRequestEvent()`), so the server's HTML
|
|
15
|
+
* shows the choice and hydration agrees. Only `system` waits until the page
|
|
16
|
+
* has settled, since the server cannot see the system's preference. The
|
|
17
|
+
* page has to be rendered for each request: a prerendered page has no
|
|
18
|
+
* cookie to read. The head script from `colorSchemeScript`, with the same
|
|
19
|
+
* options, applies a `system` choice before the first paint.
|
|
20
|
+
*/
|
|
21
|
+
function createColorScheme(options) {
|
|
22
|
+
return createColorSchemeWithStorage(storage, options);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The source of a script for the document head that applies the choice
|
|
26
|
+
* saved in the cookie, or the system preference, before the page first
|
|
27
|
+
* paints. Pass the options given to `createColorScheme`. Render it inline,
|
|
28
|
+
* before any styles that depend on the scheme, even when the server renders
|
|
29
|
+
* the choice: it is what applies `system`.
|
|
30
|
+
*
|
|
31
|
+
* ```tsx
|
|
32
|
+
* <script innerHTML={colorSchemeScript()} />
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* Under a Content Security Policy without `'unsafe-inline'`, put the
|
|
36
|
+
* policy's nonce on the element (`<script nonce={nonce} …>`), or allow the
|
|
37
|
+
* SHA-256 hash of the returned source.
|
|
38
|
+
*/
|
|
39
|
+
function colorSchemeScript(options) {
|
|
40
|
+
return colorSchemeScriptWithStorage(storage, options);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The scheme saved in a `Cookie` request header, for a server that puts the
|
|
44
|
+
* attribute on its own `<html>`. Pass the options given to
|
|
45
|
+
* `createColorScheme`.
|
|
46
|
+
*/
|
|
47
|
+
function colorSchemeFromCookie(cookieHeader, options = {}) {
|
|
48
|
+
return parseColorScheme(cookieValue(cookieHeader, options.storageKey ?? "color-scheme"));
|
|
49
|
+
}
|
|
50
|
+
export { colorSchemeFromCookie, colorSchemeScript, createColorScheme };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { nextColorScheme, resolveColorScheme } from "../colorScheme.js";
|
|
2
|
+
import { colorSchemeFromCookie, colorSchemeScript, createColorScheme } from "./cookie.js";
|
|
3
|
+
export { colorSchemeFromCookie, colorSchemeScript, createColorScheme, nextColorScheme, resolveColorScheme };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { createPreference } from "../core/preference/createPreference.js";
|
|
2
|
+
import { darkQuery, resolveColorScheme, resolvedSchemes } from "./colorScheme.js";
|
|
3
|
+
import { createSignal, onSettled } from "solid-js";
|
|
4
|
+
// src/color-scheme/createColorScheme.ts
|
|
5
|
+
/**
|
|
6
|
+
* `createColorScheme` of each entry point, with the entry point's storage.
|
|
7
|
+
*
|
|
8
|
+
* The reader's light, dark or system choice, saved in `storage` and applied
|
|
9
|
+
* to `<html>` (`ColorSchemeOptions.attribute`), through `createPreference`.
|
|
10
|
+
* Follows the system preference while the choice is `system`. `system`
|
|
11
|
+
* waits until the page has settled, since the server cannot see it; until
|
|
12
|
+
* then it is `light`.
|
|
13
|
+
*/
|
|
14
|
+
function createColorSchemeWithStorage(storage, options = {}) {
|
|
15
|
+
const [system, setSystem] = createSignal("light");
|
|
16
|
+
let currentSystem = "light";
|
|
17
|
+
const preference = createPreference(storage, {
|
|
18
|
+
storageKey: options.storageKey ?? "color-scheme",
|
|
19
|
+
attribute: options.attribute ?? "data-color-scheme",
|
|
20
|
+
values: resolvedSchemes,
|
|
21
|
+
unset: "system",
|
|
22
|
+
resolve: (scheme) => resolveColorScheme(scheme, currentSystem)
|
|
23
|
+
});
|
|
24
|
+
onSettled(() => {
|
|
25
|
+
const media = window.matchMedia(darkQuery);
|
|
26
|
+
const onMediaChange = () => {
|
|
27
|
+
setSystem(currentSystem = media.matches ? "dark" : "light");
|
|
28
|
+
preference.apply();
|
|
29
|
+
};
|
|
30
|
+
onMediaChange();
|
|
31
|
+
media.addEventListener("change", onMediaChange);
|
|
32
|
+
return () => media.removeEventListener("change", onMediaChange);
|
|
33
|
+
});
|
|
34
|
+
return {
|
|
35
|
+
scheme: preference.value,
|
|
36
|
+
system,
|
|
37
|
+
resolved: () => resolveColorScheme(preference.value(), system()),
|
|
38
|
+
setScheme: preference.set
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export { createColorSchemeWithStorage };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { localStoragePreference } from "../../core/preference/localStoragePreference.js";
|
|
2
|
+
import { colorSchemeScriptWithStorage } from "../colorSchemeScript.js";
|
|
3
|
+
import { createColorSchemeWithStorage } from "../createColorScheme.js";
|
|
4
|
+
// src/color-scheme/local-storage/localStorage.ts
|
|
5
|
+
var storage = localStoragePreference;
|
|
6
|
+
/**
|
|
7
|
+
* The reader's light, dark or system choice, saved in `localStorage` and
|
|
8
|
+
* applied to `<html>` (`ColorSchemeOptions.attribute`). Follows the system
|
|
9
|
+
* preference while the choice is `system`, and stays in step with the other
|
|
10
|
+
* instances in this tab and with other tabs.
|
|
11
|
+
*
|
|
12
|
+
* Call it in a component. The saved choice is read once the page has
|
|
13
|
+
* settled, so the server's HTML and the first client render agree; until
|
|
14
|
+
* then the state is `system` and `light`. The head script from
|
|
15
|
+
* `colorSchemeScript`, with the same options, applies the choice before the
|
|
16
|
+
* first paint, so the page does not flash in between.
|
|
17
|
+
*/
|
|
18
|
+
function createColorScheme(options) {
|
|
19
|
+
return createColorSchemeWithStorage(storage, options);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The source of a script for the document head that applies the choice
|
|
23
|
+
* saved in `localStorage`, or the system preference, before the page first
|
|
24
|
+
* paints. Pass the options given to `createColorScheme`. Render it inline,
|
|
25
|
+
* before any styles that depend on the scheme:
|
|
26
|
+
*
|
|
27
|
+
* ```tsx
|
|
28
|
+
* <script innerHTML={colorSchemeScript()} />
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* Under a Content Security Policy without `'unsafe-inline'`, put the
|
|
32
|
+
* policy's nonce on the element (`<script nonce={nonce} …>`), or allow the
|
|
33
|
+
* SHA-256 hash of the returned source.
|
|
34
|
+
*/
|
|
35
|
+
function colorSchemeScript(options) {
|
|
36
|
+
return colorSchemeScriptWithStorage(storage, options);
|
|
37
|
+
}
|
|
38
|
+
export { colorSchemeScript, createColorScheme };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { isDev } from "@solidjs/web";
|
|
2
|
+
// src/core/button.ts
|
|
3
|
+
/**
|
|
4
|
+
* Warns when the consumer's `render` function rendered a part that must be
|
|
5
|
+
* a native button as another element: its keyboard support, focus and name
|
|
6
|
+
* come from the element being a button. Call it from the part's ref behind
|
|
7
|
+
* `isDev`, so that production builds drop the call and this module:
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* ref: (element) => {
|
|
11
|
+
* if (isDev) warnUnlessButton(element, "Switch.Root");
|
|
12
|
+
* },
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
function warnUnlessButton(element, part) {
|
|
16
|
+
if (element.tagName === "BUTTON") return;
|
|
17
|
+
console.warn(`[menhir] ${part}'s render function rendered a <${element.tagName.toLowerCase()}>. Render a <button>, which gives the part its keyboard support, focus and name.`);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The own props of a part that is a native `<button type="button">` whose
|
|
21
|
+
* click flips a state it announces in `attribute`: `aria-pressed` on a
|
|
22
|
+
* toggle button (`toggleButton.ts`), `aria-expanded` on a disclosure's
|
|
23
|
+
* trigger. Pass the state as getters, so it is read where the props are
|
|
24
|
+
* used:
|
|
25
|
+
*
|
|
26
|
+
* ```ts
|
|
27
|
+
* const own = twoStateButtonProps(
|
|
28
|
+
* {
|
|
29
|
+
* get value() { return open(); },
|
|
30
|
+
* get disabled() { return props.disabled; },
|
|
31
|
+
* setValue: setOpen,
|
|
32
|
+
* },
|
|
33
|
+
* "aria-expanded",
|
|
34
|
+
* "Collapsible.Trigger",
|
|
35
|
+
* );
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* `part` names the part in the development warning of a `render` that is
|
|
39
|
+
* not a button. The part adds its own `data-*` attributes.
|
|
40
|
+
*/
|
|
41
|
+
function twoStateButtonProps(state, attribute, part) {
|
|
42
|
+
return {
|
|
43
|
+
type: "button",
|
|
44
|
+
get disabled() {
|
|
45
|
+
return state.disabled;
|
|
46
|
+
},
|
|
47
|
+
get [attribute]() {
|
|
48
|
+
return state.value ? "true" : "false";
|
|
49
|
+
},
|
|
50
|
+
onClick: () => state.setValue(!state.value),
|
|
51
|
+
ref: (element) => {
|
|
52
|
+
if (isDev) warnUnlessButton(element, part);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export { twoStateButtonProps, warnUnlessButton };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { isDev } from "@solidjs/web";
|
|
2
|
+
import { createSignal, onFlush, untrack } from "solid-js";
|
|
3
|
+
// src/core/createControllableSignal.ts
|
|
4
|
+
/**
|
|
5
|
+
* A part's value that the consumer may control. Pass the props as getters,
|
|
6
|
+
* so they are read where they are used:
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* const [checked, setChecked] = createControllableSignal({
|
|
10
|
+
* get value() { return props.checked; },
|
|
11
|
+
* get defaultValue() { return props.defaultChecked ?? false; },
|
|
12
|
+
* onChange: (value) => props.onCheckedChange?.(value),
|
|
13
|
+
* });
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* Controlled while `value` is not `undefined`: the value follows it, and a
|
|
17
|
+
* set only calls `onChange`, for the consumer to decide. Otherwise the value
|
|
18
|
+
* starts at `defaultValue`, read once, and a set calls `onChange` and
|
|
19
|
+
* changes the value right after the pending flush, in an update of its own
|
|
20
|
+
* (`onFlush`), so async work that `onChange` starts does not hold it back.
|
|
21
|
+
* Setting the value it already has, counting earlier sets in the same turn,
|
|
22
|
+
* does nothing. Set from event handlers, not from a component body or a
|
|
23
|
+
* memo.
|
|
24
|
+
*/
|
|
25
|
+
function createControllableSignal(options) {
|
|
26
|
+
const [internal, setInternal] = createSignal(() => untrack(() => options.defaultValue));
|
|
27
|
+
let wasControlled;
|
|
28
|
+
const isControlled = () => {
|
|
29
|
+
const controlled = options.value !== void 0;
|
|
30
|
+
if (isDev) {
|
|
31
|
+
if (wasControlled !== void 0 && controlled !== wasControlled) console.warn(`[menhir] A part switched from ${wasControlled ? "controlled" : "uncontrolled"} to ${controlled ? "controlled" : "uncontrolled"}. Keep it one or the other for its lifetime; for an empty controlled value, pass null, not undefined.`);
|
|
32
|
+
wasControlled = controlled;
|
|
33
|
+
}
|
|
34
|
+
return controlled;
|
|
35
|
+
};
|
|
36
|
+
const value = () => isControlled() ? options.value : internal();
|
|
37
|
+
let pending;
|
|
38
|
+
const setValue = (next) => {
|
|
39
|
+
if (Object.is(next, pending ? pending[0] : untrack(value))) return;
|
|
40
|
+
if (!untrack(isControlled)) onFlush(() => setInternal(() => next));
|
|
41
|
+
options.onChange?.(next);
|
|
42
|
+
const set = [next];
|
|
43
|
+
pending = set;
|
|
44
|
+
onFlush(() => {
|
|
45
|
+
if (pending === set) pending = void 0;
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
return [value, setValue];
|
|
49
|
+
}
|
|
50
|
+
export { createControllableSignal };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { createControllableSignal } from "./createControllableSignal.js";
|
|
2
|
+
import { onFlush } from "solid-js";
|
|
3
|
+
// src/core/listValue.ts
|
|
4
|
+
/**
|
|
5
|
+
* A part's value that lists items and that the consumer may control, as an
|
|
6
|
+
* array in every mode, `[]` when empty (PLAN.md section 8, "Controlled
|
|
7
|
+
* state"): Toggle Group's pressed items, Accordion's open ones. Pass the
|
|
8
|
+
* props as getters, so they are read where they are used:
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* const list = createListValue({
|
|
12
|
+
* get value() { return props.value; },
|
|
13
|
+
* get defaultValue() { return props.defaultValue; },
|
|
14
|
+
* get multiple() { return props.multiple; },
|
|
15
|
+
* onChange: (value) => props.onValueChange?.(value),
|
|
16
|
+
* });
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* By default the list holds one item at most: adding an item replaces the
|
|
20
|
+
* one before. With `multiple`, items are added and taken out on their own.
|
|
21
|
+
* Sets in one turn build on each other, before the flush.
|
|
22
|
+
*/
|
|
23
|
+
function createListValue(options) {
|
|
24
|
+
const [value, setValue] = createControllableSignal({
|
|
25
|
+
get value() {
|
|
26
|
+
return options.value;
|
|
27
|
+
},
|
|
28
|
+
get defaultValue() {
|
|
29
|
+
return options.defaultValue ?? [];
|
|
30
|
+
},
|
|
31
|
+
onChange: (value) => options.onChange?.(value)
|
|
32
|
+
});
|
|
33
|
+
let pending;
|
|
34
|
+
return {
|
|
35
|
+
has: (item) => value().includes(item),
|
|
36
|
+
set: (item, included) => {
|
|
37
|
+
const current = pending ?? value();
|
|
38
|
+
let next = included ? [item] : [];
|
|
39
|
+
if (options.multiple) {
|
|
40
|
+
next = current.filter((other) => other !== item);
|
|
41
|
+
if (included) next.push(item);
|
|
42
|
+
}
|
|
43
|
+
if (!pending) onFlush(() => pending = void 0);
|
|
44
|
+
pending = next;
|
|
45
|
+
setValue(next);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export { createListValue };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { merge } from "solid-js";
|
|
2
|
+
// src/core/mergeElementProps.ts
|
|
3
|
+
function callHandler(handler, event) {
|
|
4
|
+
if (typeof handler === "function") handler(event);
|
|
5
|
+
else if (handler) handler[0](handler[1], event);
|
|
6
|
+
}
|
|
7
|
+
function toCss(style) {
|
|
8
|
+
if (typeof style === "string") return style;
|
|
9
|
+
if (!style) return "";
|
|
10
|
+
return Object.entries(style).filter(([, value]) => value != null).map(([name, value]) => `${name}:${value}`).join(";");
|
|
11
|
+
}
|
|
12
|
+
function mergeStyles(own, consumer) {
|
|
13
|
+
if (consumer == null) return own;
|
|
14
|
+
if (typeof own === "object" && typeof consumer === "object") return {
|
|
15
|
+
...own,
|
|
16
|
+
...consumer
|
|
17
|
+
};
|
|
18
|
+
const ownCss = toCss(own);
|
|
19
|
+
const consumerCss = toCss(consumer);
|
|
20
|
+
return ownCss && consumerCss ? `${ownCss};${consumerCss}` : ownCss || consumerCss;
|
|
21
|
+
}
|
|
22
|
+
function applyRef(ref, element) {
|
|
23
|
+
if (typeof ref === "function") ref(element);
|
|
24
|
+
else if (Array.isArray(ref)) for (const entry of ref) applyRef(entry, element);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Merges a part's own props with the consumer's, for one element. The
|
|
28
|
+
* consumer's props win, except for these, where both apply:
|
|
29
|
+
*
|
|
30
|
+
* - Event handlers both run, the consumer's first.
|
|
31
|
+
* - `class` keeps both, in any of Solid's class forms.
|
|
32
|
+
* - `style` keeps both; the consumer's wins a conflict.
|
|
33
|
+
* - `ref` runs both, the consumer's first. The result's `ref` is one
|
|
34
|
+
* callback, so it spreads onto any element (see `ElementProps`).
|
|
35
|
+
*
|
|
36
|
+
* Only keys the part sets are merged this way; any other prop of the
|
|
37
|
+
* consumer passes through unchanged. The part's handlers and ref are read
|
|
38
|
+
* once, here; its other props, and all of the consumer's, are read where
|
|
39
|
+
* they are used, so they stay reactive. Call it in the part's body, not
|
|
40
|
+
* inline in a spread, which would run it again on every change.
|
|
41
|
+
*/
|
|
42
|
+
function mergeElementProps(own, props) {
|
|
43
|
+
const overrides = {};
|
|
44
|
+
if ("class" in own) Object.defineProperty(overrides, "class", {
|
|
45
|
+
enumerable: true,
|
|
46
|
+
get: () => [own.class, props.class]
|
|
47
|
+
});
|
|
48
|
+
if ("style" in own) Object.defineProperty(overrides, "style", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: () => mergeStyles(own.style, props.style)
|
|
51
|
+
});
|
|
52
|
+
const ownRef = own.ref;
|
|
53
|
+
overrides.ref = (element) => {
|
|
54
|
+
applyRef(props.ref, element);
|
|
55
|
+
ownRef?.(element);
|
|
56
|
+
};
|
|
57
|
+
for (const key of Object.keys(own)) {
|
|
58
|
+
if (!key.startsWith("on")) continue;
|
|
59
|
+
const ownHandler = own[key];
|
|
60
|
+
overrides[key] = (event) => {
|
|
61
|
+
callHandler(props[key], event);
|
|
62
|
+
callHandler(ownHandler, event);
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
return merge(own, props, overrides);
|
|
66
|
+
}
|
|
67
|
+
export { mergeElementProps };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { scriptLiteral } from "./preference.js";
|
|
2
|
+
import { getRequestEvent, isServer, parseCookieHeader, serializeCookie } from "@solidjs/web";
|
|
3
|
+
// src/core/preference/cookiePreference.ts
|
|
4
|
+
/** A year, in seconds: how long a saved choice lasts without a visit. */
|
|
5
|
+
var maxAge = 31536e3;
|
|
6
|
+
/** The value of the cookie `key` in a `Cookie` header. */
|
|
7
|
+
function cookieValue(cookieHeader, key) {
|
|
8
|
+
return parseCookieHeader(cookieHeader)[key];
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* A cookie named by the key, which the browser sends with every request:
|
|
12
|
+
* read on the server through `getRequestEvent()`, and in the browser from
|
|
13
|
+
* `document.cookie`. Cookies have no `storage` event, so another tab's
|
|
14
|
+
* choice is read when this tab is shown again.
|
|
15
|
+
*/
|
|
16
|
+
var cookiePreference = {
|
|
17
|
+
read: (key) => {
|
|
18
|
+
try {
|
|
19
|
+
return cookieValue(isServer ? getRequestEvent()?.request.headers.get("cookie") : document.cookie, key);
|
|
20
|
+
} catch {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
write: (key, value) => {
|
|
25
|
+
try {
|
|
26
|
+
document.cookie = serializeCookie(key, value ?? "", {
|
|
27
|
+
path: "/",
|
|
28
|
+
maxAge: value === null ? 0 : maxAge,
|
|
29
|
+
sameSite: "lax",
|
|
30
|
+
secure: /^__(Host|Secure)-/.test(key)
|
|
31
|
+
});
|
|
32
|
+
} catch {}
|
|
33
|
+
},
|
|
34
|
+
watch: (key, onChange) => {
|
|
35
|
+
const onVisibilityChange = () => {
|
|
36
|
+
if (document.visibilityState !== "hidden") onChange(cookiePreference.read(key));
|
|
37
|
+
};
|
|
38
|
+
document.addEventListener("visibilitychange", onVisibilityChange);
|
|
39
|
+
return () => document.removeEventListener("visibilitychange", onVisibilityChange);
|
|
40
|
+
},
|
|
41
|
+
readsOnServer: true,
|
|
42
|
+
script: (key) => `var c=document.cookie.split(";"),n=${scriptLiteral(`${encodeURIComponent(key)}=`)};for(var i=0;i<c.length;i++){var p=c[i].trim();if(p.indexOf(n)===0)m=p.slice(n.length)}`
|
|
43
|
+
};
|
|
44
|
+
export { cookiePreference, cookieValue };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { applyPreference, parsePreference } from "./preference.js";
|
|
2
|
+
import { createSignal, onSettled } from "solid-js";
|
|
3
|
+
// src/core/preference/createPreference.ts
|
|
4
|
+
/** Tells the other instances in the same tab about a choice. */
|
|
5
|
+
var changeEvent = "menhir:preference";
|
|
6
|
+
/**
|
|
7
|
+
* A preference of the reader's, saved in `storage` and applied to `<html>`,
|
|
8
|
+
* that stays in step with the other instances in this tab and with other
|
|
9
|
+
* tabs: what color scheme and theme share.
|
|
10
|
+
*
|
|
11
|
+
* A storage only the browser can read, such as `localStorage`, is read once
|
|
12
|
+
* the page has settled, so the server's HTML and the first client render
|
|
13
|
+
* agree; until then the value is `unset`. One the server can read too, such
|
|
14
|
+
* as a cookie, is read during the first render. The head script applies the
|
|
15
|
+
* value before the first paint, so the page does not flash in between.
|
|
16
|
+
*
|
|
17
|
+
* The DOM is written imperatively, from `set` and the listeners, not from
|
|
18
|
+
* an effect: an effect's first run would apply `unset` before the saved
|
|
19
|
+
* value is read, undoing the head script.
|
|
20
|
+
*/
|
|
21
|
+
function createPreference(storage, options) {
|
|
22
|
+
const { storageKey, attribute, values, unset } = options;
|
|
23
|
+
const resolve = options.resolve ?? ((value) => value);
|
|
24
|
+
const parse = (raw) => parsePreference(raw, values, unset);
|
|
25
|
+
const initial = storage.readsOnServer ? parse(storage.read(storageKey)) : unset;
|
|
26
|
+
const [value, setValue] = createSignal(initial);
|
|
27
|
+
let current = initial;
|
|
28
|
+
const apply = () => applyPreference(attribute, resolve(current), values);
|
|
29
|
+
const update = (next) => {
|
|
30
|
+
setValue(() => current = next);
|
|
31
|
+
apply();
|
|
32
|
+
};
|
|
33
|
+
onSettled(() => {
|
|
34
|
+
update(parse(storage.read(storageKey)));
|
|
35
|
+
const onChange = (event) => {
|
|
36
|
+
const detail = event.detail;
|
|
37
|
+
if (detail.storageKey === storageKey) update(parse(detail.value));
|
|
38
|
+
};
|
|
39
|
+
const unwatch = storage.watch(storageKey, (raw) => update(parse(raw)));
|
|
40
|
+
window.addEventListener(changeEvent, onChange);
|
|
41
|
+
return () => {
|
|
42
|
+
unwatch();
|
|
43
|
+
window.removeEventListener(changeEvent, onChange);
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
const set = (next) => {
|
|
47
|
+
storage.write(storageKey, next === unset ? null : next);
|
|
48
|
+
update(next);
|
|
49
|
+
window.dispatchEvent(new CustomEvent(changeEvent, { detail: {
|
|
50
|
+
storageKey,
|
|
51
|
+
value: next
|
|
52
|
+
} }));
|
|
53
|
+
};
|
|
54
|
+
return {
|
|
55
|
+
value,
|
|
56
|
+
set,
|
|
57
|
+
apply
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export { createPreference };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { scriptLiteral } from "./preference.js";
|
|
2
|
+
// src/core/preference/localStoragePreference.ts
|
|
3
|
+
/** `localStorage`, which only the browser can read. */
|
|
4
|
+
var localStoragePreference = {
|
|
5
|
+
read: (key) => {
|
|
6
|
+
try {
|
|
7
|
+
return localStorage.getItem(key);
|
|
8
|
+
} catch {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
write: (key, value) => {
|
|
13
|
+
try {
|
|
14
|
+
if (value === null) localStorage.removeItem(key);
|
|
15
|
+
else localStorage.setItem(key, value);
|
|
16
|
+
} catch {}
|
|
17
|
+
},
|
|
18
|
+
watch: (key, onChange) => {
|
|
19
|
+
const onStorage = (event) => {
|
|
20
|
+
if (event.key === key || event.key === null) onChange(event.newValue);
|
|
21
|
+
};
|
|
22
|
+
window.addEventListener("storage", onStorage);
|
|
23
|
+
return () => window.removeEventListener("storage", onStorage);
|
|
24
|
+
},
|
|
25
|
+
readsOnServer: false,
|
|
26
|
+
script: (key) => `m=localStorage.getItem(${scriptLiteral(key)})`
|
|
27
|
+
};
|
|
28
|
+
export { localStoragePreference };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// src/core/preference/preference.ts
|
|
2
|
+
/** A saved value, if it is one of `values`; otherwise `unset`. */
|
|
3
|
+
function parsePreference(raw, values, unset) {
|
|
4
|
+
return raw && values.includes(raw) ? raw : unset;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Puts a preference's value on `<html>`. With `"class"`, first removes the
|
|
8
|
+
* classes of every value in `values`, so only one is on at a time.
|
|
9
|
+
*/
|
|
10
|
+
function applyPreference(attribute, value, values) {
|
|
11
|
+
const root = document.documentElement;
|
|
12
|
+
if (attribute === "class") {
|
|
13
|
+
root.classList.remove(...values);
|
|
14
|
+
root.classList.add(value);
|
|
15
|
+
} else root.setAttribute(attribute, value);
|
|
16
|
+
}
|
|
17
|
+
/** A string as a JavaScript literal that cannot close the script element. */
|
|
18
|
+
function scriptLiteral(value) {
|
|
19
|
+
return JSON.stringify(value).replaceAll("<", "\\u003c");
|
|
20
|
+
}
|
|
21
|
+
export { applyPreference, parsePreference, scriptLiteral };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { scriptLiteral } from "./preference.js";
|
|
2
|
+
// src/core/preference/preferenceScript.ts
|
|
3
|
+
/**
|
|
4
|
+
* The source of a script for the document head that applies a saved
|
|
5
|
+
* preference, or `fallback`, to `<html>` before the page first paints.
|
|
6
|
+
*/
|
|
7
|
+
function preferenceScript(storage, options) {
|
|
8
|
+
const values = options.values.map(scriptLiteral).join(",");
|
|
9
|
+
const apply = options.attribute === "class" ? "d.classList.remove.apply(d.classList,l);d.classList.add(r)" : `d.setAttribute(${scriptLiteral(options.attribute)},r)`;
|
|
10
|
+
return `(function(){var m,l=[${values}];try{${storage.script(options.storageKey)}}catch(e){}var r=l.indexOf(m)>=0?m:${options.fallback},d=document.documentElement;${apply}})()`;
|
|
11
|
+
}
|
|
12
|
+
export { preferenceScript };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { createMemo } from "solid-js";
|
|
2
|
+
// src/core/range.ts
|
|
3
|
+
/**
|
|
4
|
+
* The value, attributes and text of a part along a range, shared by
|
|
5
|
+
* Progress and Meter (PLAN.md section 8, "API conventions"). Call it in the
|
|
6
|
+
* part's body with the element's role; `property` names the custom
|
|
7
|
+
* property, such as `--progress`.
|
|
8
|
+
* Omit `value`, `min`, `max`, `format` and `locale` from the props the part
|
|
9
|
+
* merges onto its element.
|
|
10
|
+
*/
|
|
11
|
+
function createRange(props, role, property) {
|
|
12
|
+
const min = () => props.min ?? 0;
|
|
13
|
+
const max = () => props.max ?? 100;
|
|
14
|
+
const value = () => props.value == null ? void 0 : Math.min(Math.max(props.value, min()), max());
|
|
15
|
+
const fraction = () => {
|
|
16
|
+
const current = value();
|
|
17
|
+
return current === void 0 ? void 0 : (current - min()) / (max() - min());
|
|
18
|
+
};
|
|
19
|
+
const text = createMemo(() => {
|
|
20
|
+
const current = value();
|
|
21
|
+
if (current === void 0) return void 0;
|
|
22
|
+
const format = props.format;
|
|
23
|
+
const percent = !format || format.style === "percent";
|
|
24
|
+
return new Intl.NumberFormat(props.locale, format ?? { style: "percent" }).format(percent ? fraction() : current);
|
|
25
|
+
});
|
|
26
|
+
return {
|
|
27
|
+
fraction,
|
|
28
|
+
props: {
|
|
29
|
+
role,
|
|
30
|
+
get "aria-valuemin"() {
|
|
31
|
+
return min();
|
|
32
|
+
},
|
|
33
|
+
get "aria-valuemax"() {
|
|
34
|
+
return max();
|
|
35
|
+
},
|
|
36
|
+
get "aria-valuenow"() {
|
|
37
|
+
return value();
|
|
38
|
+
},
|
|
39
|
+
get "aria-valuetext"() {
|
|
40
|
+
return text();
|
|
41
|
+
},
|
|
42
|
+
get style() {
|
|
43
|
+
const current = fraction();
|
|
44
|
+
return { [property]: current === void 0 ? void 0 : `${current * 100}%` };
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
valueText: () => {
|
|
48
|
+
const own = props["aria-valuetext"];
|
|
49
|
+
return typeof own === "string" ? own : text();
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export { createRange };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createComponent } from "@solidjs/web";
|
|
2
|
+
import { untrack } from "solid-js";
|
|
3
|
+
// src/core/renderElement.tsx
|
|
4
|
+
/**
|
|
5
|
+
* Renders a part's element: the consumer's `render` if there is one, else
|
|
6
|
+
* the part's `fallback`. `render` is read once, untracked, when the part is
|
|
7
|
+
* created, as an event handler is. Call it in the part's body, with
|
|
8
|
+
* `elementProps` already merged (`mergeElementProps`).
|
|
9
|
+
*/
|
|
10
|
+
function renderElement(props, elementProps, fallback) {
|
|
11
|
+
const Render = untrack(() => props.render) ?? fallback;
|
|
12
|
+
return createComponent(Render, elementProps);
|
|
13
|
+
}
|
|
14
|
+
export { renderElement };
|