@remix-run/ui 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 +21 -0
- package/README.md +195 -2
- package/dist/animation/animate-layout-mixin.d.ts +12 -0
- package/dist/animation/animate-layout-mixin.js +214 -0
- package/dist/animation/animate-layout-mixin.js.map +1 -0
- package/dist/animation/animate-mixins.d.ts +29 -0
- package/dist/animation/animate-mixins.js +235 -0
- package/dist/animation/animate-mixins.js.map +1 -0
- package/dist/animation/index.d.ts +6 -0
- package/dist/animation/index.js +5 -0
- package/dist/animation/index.js.map +1 -0
- package/dist/animation/spring.d.ts +75 -0
- package/dist/animation/spring.js +183 -0
- package/dist/animation/spring.js.map +1 -0
- package/dist/animation/tween.d.ts +70 -0
- package/dist/animation/tween.js +93 -0
- package/dist/animation/tween.js.map +1 -0
- package/dist/components/accordion/accordion.d.ts +92 -0
- package/dist/components/accordion/accordion.js +337 -0
- package/dist/components/accordion/accordion.js.map +1 -0
- package/dist/components/anchor/anchor.d.ts +13 -0
- package/dist/components/anchor/anchor.js +558 -0
- package/dist/components/anchor/anchor.js.map +1 -0
- package/dist/components/breadcrumbs/breadcrumbs.d.ts +11 -0
- package/dist/components/breadcrumbs/breadcrumbs.js +78 -0
- package/dist/components/breadcrumbs/breadcrumbs.js.map +1 -0
- package/dist/components/button/button.d.ts +23 -0
- package/dist/components/button/button.js +147 -0
- package/dist/components/button/button.js.map +1 -0
- package/dist/components/combobox/combobox.d.ts +101 -0
- package/dist/components/combobox/combobox.js +708 -0
- package/dist/components/combobox/combobox.js.map +1 -0
- package/dist/components/glyph/glyph.d.ts +14 -0
- package/dist/components/glyph/glyph.js +65 -0
- package/dist/components/glyph/glyph.js.map +1 -0
- package/dist/components/listbox/listbox.d.ts +67 -0
- package/dist/components/listbox/listbox.js +340 -0
- package/dist/components/listbox/listbox.js.map +1 -0
- package/dist/components/menu/hover-aim.d.ts +5 -0
- package/dist/components/menu/hover-aim.js +308 -0
- package/dist/components/menu/hover-aim.js.map +1 -0
- package/dist/components/menu/menu.d.ts +164 -0
- package/dist/components/menu/menu.js +1106 -0
- package/dist/components/menu/menu.js.map +1 -0
- package/dist/components/popover/popover.d.ts +35 -0
- package/dist/components/popover/popover.js +138 -0
- package/dist/components/popover/popover.js.map +1 -0
- package/dist/components/select/select.d.ts +67 -0
- package/dist/components/select/select.js +397 -0
- package/dist/components/select/select.js.map +1 -0
- package/dist/components/separator/separator.d.ts +2 -0
- package/dist/components/separator/separator.js +15 -0
- package/dist/components/separator/separator.js.map +1 -0
- package/dist/components/tabs/tabs.d.ts +78 -0
- package/dist/components/tabs/tabs.js +341 -0
- package/dist/components/tabs/tabs.js.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/interactions/keydown/keydown.d.ts +1 -0
- package/dist/interactions/keydown/keydown.js +8 -0
- package/dist/interactions/keydown/keydown.js.map +1 -0
- package/dist/interactions/outside-click/outside-click-mixin.d.ts +2 -0
- package/dist/interactions/outside-click/outside-click-mixin.js +29 -0
- package/dist/interactions/outside-click/outside-click-mixin.js.map +1 -0
- package/dist/interactions/typeahead/typeahead-mixin.d.ts +8 -0
- package/dist/interactions/typeahead/typeahead-mixin.js +59 -0
- package/dist/interactions/typeahead/typeahead-mixin.js.map +1 -0
- package/dist/jsx-runtime.d.ts +2 -0
- package/dist/jsx-runtime.js +3 -0
- package/dist/jsx-runtime.js.map +1 -0
- package/dist/runtime/client-entries.d.ts +91 -0
- package/dist/runtime/client-entries.js +40 -0
- package/dist/runtime/client-entries.js.map +1 -0
- package/dist/runtime/component.d.ts +223 -0
- package/dist/runtime/component.js +152 -0
- package/dist/runtime/component.js.map +1 -0
- package/dist/runtime/create-element.d.ts +10 -0
- package/dist/runtime/create-element.js +29 -0
- package/dist/runtime/create-element.js.map +1 -0
- package/dist/runtime/diff-dom.d.ts +2 -0
- package/dist/runtime/diff-dom.js +364 -0
- package/dist/runtime/diff-dom.js.map +1 -0
- package/dist/runtime/diff-props.d.ts +9 -0
- package/dist/runtime/diff-props.js +195 -0
- package/dist/runtime/diff-props.js.map +1 -0
- package/dist/runtime/document-state.d.ts +11 -0
- package/dist/runtime/document-state.js +106 -0
- package/dist/runtime/document-state.js.map +1 -0
- package/dist/runtime/dom.d.ts +3189 -0
- package/dist/runtime/dom.js +2 -0
- package/dist/runtime/dom.js.map +1 -0
- package/dist/runtime/error-event.d.ts +20 -0
- package/dist/runtime/error-event.js +19 -0
- package/dist/runtime/error-event.js.map +1 -0
- package/dist/runtime/event-listeners.d.ts +50 -0
- package/dist/runtime/event-listeners.js +31 -0
- package/dist/runtime/event-listeners.js.map +1 -0
- package/dist/runtime/frame.d.ts +119 -0
- package/dist/runtime/frame.js +915 -0
- package/dist/runtime/frame.js.map +1 -0
- package/dist/runtime/invariant.d.ts +23 -0
- package/dist/runtime/invariant.js +33 -0
- package/dist/runtime/invariant.js.map +1 -0
- package/dist/runtime/jsx.d.ts +320 -0
- package/dist/runtime/jsx.js +31 -0
- package/dist/runtime/jsx.js.map +1 -0
- package/dist/runtime/mixins/attrs-mixin.d.ts +9 -0
- package/dist/runtime/mixins/attrs-mixin.js +23 -0
- package/dist/runtime/mixins/attrs-mixin.js.map +1 -0
- package/dist/runtime/mixins/link-mixin.d.ts +17 -0
- package/dist/runtime/mixins/link-mixin.js +101 -0
- package/dist/runtime/mixins/link-mixin.js.map +1 -0
- package/dist/runtime/mixins/mixin.d.ts +145 -0
- package/dist/runtime/mixins/mixin.js +570 -0
- package/dist/runtime/mixins/mixin.js.map +1 -0
- package/dist/runtime/mixins/on-mixin.d.ts +16 -0
- package/dist/runtime/mixins/on-mixin.js +49 -0
- package/dist/runtime/mixins/on-mixin.js.map +1 -0
- package/dist/runtime/mixins/ref-mixin.d.ts +9 -0
- package/dist/runtime/mixins/ref-mixin.js +21 -0
- package/dist/runtime/mixins/ref-mixin.js.map +1 -0
- package/dist/runtime/navigation.d.ts +22 -0
- package/dist/runtime/navigation.js +102 -0
- package/dist/runtime/navigation.js.map +1 -0
- package/dist/runtime/reconcile.d.ts +11 -0
- package/dist/runtime/reconcile.js +1240 -0
- package/dist/runtime/reconcile.js.map +1 -0
- package/dist/runtime/render.d.ts +54 -0
- package/dist/runtime/render.js +50 -0
- package/dist/runtime/render.js.map +1 -0
- package/dist/runtime/run.d.ts +45 -0
- package/dist/runtime/run.js +68 -0
- package/dist/runtime/run.js.map +1 -0
- package/dist/runtime/scheduler.d.ts +30 -0
- package/dist/runtime/scheduler.js +185 -0
- package/dist/runtime/scheduler.js.map +1 -0
- package/dist/runtime/svg-attributes.d.ts +5 -0
- package/dist/runtime/svg-attributes.js +124 -0
- package/dist/runtime/svg-attributes.js.map +1 -0
- package/dist/runtime/to-vnode.d.ts +3 -0
- package/dist/runtime/to-vnode.js +43 -0
- package/dist/runtime/to-vnode.js.map +1 -0
- package/dist/runtime/typed-event-target.d.ts +50 -0
- package/dist/runtime/typed-event-target.js +6 -0
- package/dist/runtime/typed-event-target.js.map +1 -0
- package/dist/runtime/vdom.d.ts +55 -0
- package/dist/runtime/vdom.js +198 -0
- package/dist/runtime/vdom.js.map +1 -0
- package/dist/runtime/vnode.d.ts +79 -0
- package/dist/runtime/vnode.js +38 -0
- package/dist/runtime/vnode.js.map +1 -0
- package/dist/server/stream.d.ts +57 -0
- package/dist/server/stream.js +1007 -0
- package/dist/server/stream.js.map +1 -0
- package/dist/style/css-mixin.d.ts +8 -0
- package/dist/style/css-mixin.js +54 -0
- package/dist/style/css-mixin.js.map +1 -0
- package/dist/style/index.d.ts +5 -0
- package/dist/style/index.js +4 -0
- package/dist/style/index.js.map +1 -0
- package/dist/style/style.d.ts +24 -0
- package/dist/style/style.js +269 -0
- package/dist/style/style.js.map +1 -0
- package/dist/style/stylesheet.d.ts +11 -0
- package/dist/style/stylesheet.js +174 -0
- package/dist/style/stylesheet.js.map +1 -0
- package/dist/test.d.ts +2 -0
- package/dist/test.js +2 -0
- package/dist/test.js.map +1 -0
- package/dist/theme/contract.d.ts +259 -0
- package/dist/theme/contract.js +131 -0
- package/dist/theme/contract.js.map +1 -0
- package/dist/theme/glyph-contract.d.ts +13 -0
- package/dist/theme/glyph-contract.js +34 -0
- package/dist/theme/glyph-contract.js.map +1 -0
- package/dist/theme/presets/rmx-01/glyphs.d.ts +2 -0
- package/dist/theme/presets/rmx-01/glyphs.js +252 -0
- package/dist/theme/presets/rmx-01/glyphs.js.map +1 -0
- package/dist/theme/presets/rmx-01/index.d.ts +2 -0
- package/dist/theme/presets/rmx-01/index.js +119 -0
- package/dist/theme/presets/rmx-01/index.js.map +1 -0
- package/dist/theme/runtime.d.ts +2 -0
- package/dist/theme/runtime.js +81 -0
- package/dist/theme/runtime.js.map +1 -0
- package/dist/theme/theme.d.ts +6 -0
- package/dist/theme/theme.js +5 -0
- package/dist/theme/theme.js.map +1 -0
- package/dist/utils/flash-attribute.d.ts +1 -0
- package/dist/utils/flash-attribute.js +11 -0
- package/dist/utils/flash-attribute.js.map +1 -0
- package/dist/utils/scroll-lock.d.ts +3 -0
- package/dist/utils/scroll-lock.js +69 -0
- package/dist/utils/scroll-lock.js.map +1 -0
- package/dist/utils/wait-for-css-transition.d.ts +1 -0
- package/dist/utils/wait-for-css-transition.js +58 -0
- package/dist/utils/wait-for-css-transition.js.map +1 -0
- package/dist/utils/wait.d.ts +1 -0
- package/dist/utils/wait.js +6 -0
- package/dist/utils/wait.js.map +1 -0
- package/package.json +125 -5
- package/src/animation/animate-layout-mixin.ts +266 -0
- package/src/animation/animate-mixins.ts +292 -0
- package/src/animation/index.ts +6 -0
- package/src/animation/spring.ts +299 -0
- package/src/animation/tween.ts +134 -0
- package/src/components/accordion/accordion.tsx +565 -0
- package/src/components/anchor/anchor.ts +904 -0
- package/src/components/breadcrumbs/breadcrumbs.tsx +124 -0
- package/src/components/button/README.md +44 -0
- package/src/components/button/button.tsx +188 -0
- package/src/components/combobox/README.md +145 -0
- package/src/components/combobox/combobox.tsx +1014 -0
- package/src/components/glyph/glyph.tsx +110 -0
- package/src/components/listbox/listbox.ts +447 -0
- package/src/components/menu/hover-aim.ts +428 -0
- package/src/components/menu/menu.tsx +1547 -0
- package/src/components/popover/README.md +122 -0
- package/src/components/popover/popover.ts +201 -0
- package/src/components/select/select.tsx +585 -0
- package/src/components/separator/separator.ts +19 -0
- package/src/components/tabs/README.md +105 -0
- package/src/components/tabs/tabs.tsx +499 -0
- package/src/index.ts +72 -0
- package/src/interactions/keydown/keydown.ts +14 -0
- package/src/interactions/outside-click/outside-click-mixin.ts +55 -0
- package/src/interactions/typeahead/typeahead-mixin.ts +89 -0
- package/src/jsx-runtime.ts +2 -0
- package/src/runtime/client-entries.ts +137 -0
- package/src/runtime/component.ts +402 -0
- package/src/runtime/create-element.ts +38 -0
- package/src/runtime/diff-dom.ts +404 -0
- package/src/runtime/diff-props.ts +209 -0
- package/src/runtime/document-state.ts +130 -0
- package/src/runtime/dom.ts +3971 -0
- package/src/runtime/error-event.ts +26 -0
- package/src/runtime/event-listeners.ts +171 -0
- package/src/runtime/frame.ts +1211 -0
- package/src/runtime/invariant.ts +31 -0
- package/src/runtime/jsx.ts +398 -0
- package/src/runtime/mixins/attrs-mixin.ts +35 -0
- package/src/runtime/mixins/link-mixin.ts +131 -0
- package/src/runtime/mixins/mixin.ts +908 -0
- package/src/runtime/mixins/on-mixin.ts +89 -0
- package/src/runtime/mixins/ref-mixin.ts +32 -0
- package/src/runtime/navigation.ts +136 -0
- package/src/runtime/reconcile.ts +1722 -0
- package/src/runtime/render.ts +101 -0
- package/src/runtime/run.ts +100 -0
- package/src/runtime/scheduler.ts +262 -0
- package/src/runtime/svg-attributes.ts +133 -0
- package/src/runtime/to-vnode.ts +50 -0
- package/src/runtime/typed-event-target.ts +67 -0
- package/src/runtime/vdom.ts +295 -0
- package/src/runtime/vnode.ts +137 -0
- package/src/server/stream.ts +1342 -0
- package/src/style/css-mixin.ts +82 -0
- package/src/style/index.ts +10 -0
- package/src/style/style.ts +312 -0
- package/src/style/stylesheet.ts +209 -0
- package/src/test/setup.ts +7 -0
- package/src/test/utils.ts +45 -0
- package/src/test.ts +2 -0
- package/src/theme/contract.ts +183 -0
- package/src/theme/glyph-contract.ts +57 -0
- package/src/theme/presets/rmx-01/glyphs.tsx +308 -0
- package/src/theme/presets/rmx-01/index.ts +121 -0
- package/src/theme/runtime.ts +116 -0
- package/src/theme/theme.ts +15 -0
- package/src/utils/flash-attribute.ts +11 -0
- package/src/utils/scroll-lock.ts +97 -0
- package/src/utils/wait-for-css-transition.ts +66 -0
- package/src/utils/wait.ts +5 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { createElement, type Handle } from '@remix-run/ui'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
theme,
|
|
5
|
+
themeVariableNames,
|
|
6
|
+
type CreateThemeOptions,
|
|
7
|
+
type ThemeComponent,
|
|
8
|
+
type ThemeStyleProps,
|
|
9
|
+
type ThemeValues,
|
|
10
|
+
type ThemeVariableTree,
|
|
11
|
+
type ThemeVars,
|
|
12
|
+
} from './contract.ts'
|
|
13
|
+
|
|
14
|
+
export function createTheme(values: ThemeValues, options: CreateThemeOptions = {}): ThemeComponent {
|
|
15
|
+
let selector = options.selector ?? ':root'
|
|
16
|
+
let reset = options.reset ?? true
|
|
17
|
+
let vars = Object.freeze(collectThemeVars(themeVariableNames, values))
|
|
18
|
+
let cssText = serializeThemeCss(selector, vars, { reset })
|
|
19
|
+
|
|
20
|
+
function Theme(handle: Handle<ThemeStyleProps>) {
|
|
21
|
+
return () =>
|
|
22
|
+
createElement('style', {
|
|
23
|
+
nonce: handle.props.nonce,
|
|
24
|
+
'data-rmx-theme': '',
|
|
25
|
+
'data-rmx-theme-selector': selector,
|
|
26
|
+
innerHTML: escapeStyleText(cssText),
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return Object.assign(Theme, {
|
|
31
|
+
Style: Theme,
|
|
32
|
+
cssText,
|
|
33
|
+
selector,
|
|
34
|
+
values,
|
|
35
|
+
vars,
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function collectThemeVars(
|
|
40
|
+
tree: ThemeVariableTree,
|
|
41
|
+
values: ThemeValues,
|
|
42
|
+
path: string[] = [],
|
|
43
|
+
): Record<string, string> {
|
|
44
|
+
let vars: Record<string, string> = {}
|
|
45
|
+
|
|
46
|
+
for (let [key, value] of Object.entries(tree)) {
|
|
47
|
+
let nextPath = [...path, key]
|
|
48
|
+
let themeValue = (values as Record<string, unknown>)[key]
|
|
49
|
+
|
|
50
|
+
if (typeof value === 'string') {
|
|
51
|
+
if (typeof themeValue !== 'string' && typeof themeValue !== 'number') {
|
|
52
|
+
throw new TypeError(
|
|
53
|
+
`Expected theme value at "${nextPath.join('.')}" to be a string or number`,
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
vars[value] = String(themeValue)
|
|
58
|
+
continue
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (!isPlainObject(themeValue)) {
|
|
62
|
+
throw new TypeError(`Expected theme group at "${nextPath.join('.')}" to be an object`)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
Object.assign(vars, collectThemeVars(value, themeValue as ThemeValues, nextPath))
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return vars
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function serializeThemeCss(selector: string, vars: ThemeVars, options: { reset: boolean }): string {
|
|
72
|
+
let lines = Object.entries(vars)
|
|
73
|
+
.map(([name, value]) => ` ${name}: ${value};`)
|
|
74
|
+
.join('\n')
|
|
75
|
+
|
|
76
|
+
let blocks = [`${selector} {\n${lines}\n}`]
|
|
77
|
+
|
|
78
|
+
if (options.reset) {
|
|
79
|
+
blocks.push(serializeThemeResetCss(selector))
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return blocks.join('\n\n')
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function serializeThemeResetCss(selector: string): string {
|
|
86
|
+
let fontFamily = theme.fontFamily.sans
|
|
87
|
+
let fontSize = theme.fontSize.md
|
|
88
|
+
let lineHeight = theme.lineHeight.normal
|
|
89
|
+
let textColor = theme.colors.text.primary
|
|
90
|
+
let backgroundColor = theme.surface.lvl0
|
|
91
|
+
|
|
92
|
+
if (selector === ':root') {
|
|
93
|
+
return [
|
|
94
|
+
`*, *::before, *::after {\n box-sizing: border-box;\n}`,
|
|
95
|
+
`html, body {\n margin: 0;\n}`,
|
|
96
|
+
`body {\n font-family: ${fontFamily};\n font-size: ${fontSize};\n line-height: ${lineHeight};\n color: ${textColor};\n background-color: ${backgroundColor};\n}`,
|
|
97
|
+
`:where(h1, h2, h3, h4, h5, h6, p, ul, ol, dl, figure, blockquote) {\n margin: 0;\n}`,
|
|
98
|
+
`:where(img, svg) {\n display: block;\n}`,
|
|
99
|
+
].join('\n\n')
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return [
|
|
103
|
+
`${selector}, ${selector} *, ${selector} *::before, ${selector} *::after {\n box-sizing: border-box;\n}`,
|
|
104
|
+
`${selector} {\n font-family: ${fontFamily};\n font-size: ${fontSize};\n line-height: ${lineHeight};\n color: ${textColor};\n background-color: ${backgroundColor};\n}`,
|
|
105
|
+
`${selector} :where(h1, h2, h3, h4, h5, h6, p, ul, ol, dl, figure, blockquote) {\n margin: 0;\n}`,
|
|
106
|
+
`${selector} :where(img, svg) {\n display: block;\n}`,
|
|
107
|
+
].join('\n\n')
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function escapeStyleText(cssText: string): string {
|
|
111
|
+
return cssText.replace(/<\/style/gi, '<\\/style')
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function isPlainObject(value: unknown): value is Record<string, unknown> {
|
|
115
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
116
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { theme } from './contract.ts'
|
|
2
|
+
export type {
|
|
3
|
+
CreateThemeOptions,
|
|
4
|
+
ThemeComponent,
|
|
5
|
+
ThemeMix,
|
|
6
|
+
ThemeStyleProps,
|
|
7
|
+
ThemeUtility,
|
|
8
|
+
ThemeValue,
|
|
9
|
+
ThemeValues,
|
|
10
|
+
ThemeVars,
|
|
11
|
+
} from './contract.ts'
|
|
12
|
+
export { glyphContract, glyphNames } from './glyph-contract.ts'
|
|
13
|
+
export type { GlyphContract, GlyphName, GlyphSymbol, GlyphValues } from './glyph-contract.ts'
|
|
14
|
+
export { createTheme } from './runtime.ts'
|
|
15
|
+
export { RMX_01, RMX_01_GLYPHS } from './presets/rmx-01/index.ts'
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
function wait(ms: number) {
|
|
2
|
+
return new Promise<void>((resolve) => {
|
|
3
|
+
setTimeout(resolve, ms)
|
|
4
|
+
})
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export async function flashAttribute(node: HTMLElement, attributeName: string, duration: number) {
|
|
8
|
+
node.setAttribute(attributeName, 'true')
|
|
9
|
+
await wait(duration)
|
|
10
|
+
node.removeAttribute(attributeName)
|
|
11
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { createMixin, on, type ElementProps } from '@remix-run/ui'
|
|
2
|
+
|
|
3
|
+
type ScrollLockState = {
|
|
4
|
+
count: number
|
|
5
|
+
documentOverflow: string
|
|
6
|
+
documentScrollbarGutter: string
|
|
7
|
+
scrollX: number
|
|
8
|
+
scrollY: number
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const scrollLocks = new WeakMap<Document, ScrollLockState>()
|
|
12
|
+
|
|
13
|
+
export function lockScroll(targetDocument = globalThis.document) {
|
|
14
|
+
if (!targetDocument?.body || !targetDocument.defaultView) {
|
|
15
|
+
return () => {}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
let document = targetDocument
|
|
19
|
+
let documentElement = document.documentElement
|
|
20
|
+
let view = document.defaultView!
|
|
21
|
+
let state = scrollLocks.get(document)
|
|
22
|
+
|
|
23
|
+
if (!state) {
|
|
24
|
+
let scrollX = view.scrollX
|
|
25
|
+
let scrollY = view.scrollY
|
|
26
|
+
let scrollbarWidth =
|
|
27
|
+
documentElement.clientWidth > 0
|
|
28
|
+
? Math.max(view.innerWidth - documentElement.clientWidth, 0)
|
|
29
|
+
: 0
|
|
30
|
+
let computedScrollbarGutter = view.getComputedStyle(documentElement).scrollbarGutter
|
|
31
|
+
|
|
32
|
+
state = {
|
|
33
|
+
count: 0,
|
|
34
|
+
documentOverflow: documentElement.style.overflow,
|
|
35
|
+
documentScrollbarGutter: documentElement.style.scrollbarGutter,
|
|
36
|
+
scrollX,
|
|
37
|
+
scrollY,
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
documentElement.style.overflow = 'hidden'
|
|
41
|
+
if (scrollbarWidth > 0 && computedScrollbarGutter === 'auto') {
|
|
42
|
+
documentElement.style.scrollbarGutter = 'stable'
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
scrollLocks.set(document, state)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
state.count++
|
|
49
|
+
|
|
50
|
+
let unlocked = false
|
|
51
|
+
|
|
52
|
+
return () => {
|
|
53
|
+
if (unlocked) {
|
|
54
|
+
return
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
unlocked = true
|
|
58
|
+
|
|
59
|
+
let currentState = scrollLocks.get(document)
|
|
60
|
+
if (!currentState) {
|
|
61
|
+
return
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
currentState.count--
|
|
65
|
+
if (currentState.count > 0) {
|
|
66
|
+
return
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
scrollLocks.delete(document)
|
|
70
|
+
|
|
71
|
+
documentElement.style.overflow = currentState.documentOverflow
|
|
72
|
+
documentElement.style.scrollbarGutter = currentState.documentScrollbarGutter
|
|
73
|
+
view.scrollTo(currentState.scrollX, currentState.scrollY)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export const lockScrollOnToggle = createMixin<HTMLElement, [], ElementProps>((handle) => {
|
|
78
|
+
let unlockScroll = () => {}
|
|
79
|
+
|
|
80
|
+
handle.signal.addEventListener('abort', () => {
|
|
81
|
+
unlockScroll()
|
|
82
|
+
unlockScroll = () => {}
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
return () => [
|
|
86
|
+
on('beforetoggle', (event) => {
|
|
87
|
+
unlockScroll()
|
|
88
|
+
unlockScroll = () => {}
|
|
89
|
+
|
|
90
|
+
if (event.newState !== 'open') {
|
|
91
|
+
return
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
unlockScroll = lockScroll((event.currentTarget as HTMLElement).ownerDocument)
|
|
95
|
+
}),
|
|
96
|
+
]
|
|
97
|
+
})
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export function waitForCssTransition(node: HTMLElement, signal: AbortSignal, action?: () => void) {
|
|
2
|
+
return new Promise<void>((resolve) => {
|
|
3
|
+
let resolved = false
|
|
4
|
+
let sawTransitionRun = false
|
|
5
|
+
let firstFrameId = 0
|
|
6
|
+
let secondFrameId = 0
|
|
7
|
+
|
|
8
|
+
function cleanup() {
|
|
9
|
+
cancelAnimationFrame(firstFrameId)
|
|
10
|
+
cancelAnimationFrame(secondFrameId)
|
|
11
|
+
node.removeEventListener('transitionrun', handleTransitionRun)
|
|
12
|
+
node.removeEventListener('transitionend', finish)
|
|
13
|
+
node.removeEventListener('transitioncancel', finish)
|
|
14
|
+
signal.removeEventListener('abort', finish)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function handleTransitionRun(event: TransitionEvent) {
|
|
18
|
+
if (event.target !== node) {
|
|
19
|
+
return
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
sawTransitionRun = true
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function finish(event?: Event) {
|
|
26
|
+
if (event instanceof TransitionEvent && event.target !== node) {
|
|
27
|
+
return
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (resolved) {
|
|
31
|
+
return
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
resolved = true
|
|
35
|
+
cleanup()
|
|
36
|
+
resolve()
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
node.addEventListener('transitionrun', handleTransitionRun)
|
|
40
|
+
node.addEventListener('transitionend', finish)
|
|
41
|
+
node.addEventListener('transitioncancel', finish)
|
|
42
|
+
signal.addEventListener('abort', finish, { once: true })
|
|
43
|
+
|
|
44
|
+
if (action) {
|
|
45
|
+
try {
|
|
46
|
+
action()
|
|
47
|
+
} catch (error) {
|
|
48
|
+
cleanup()
|
|
49
|
+
throw error
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (signal.aborted) {
|
|
54
|
+
finish()
|
|
55
|
+
return
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
firstFrameId = requestAnimationFrame(() => {
|
|
59
|
+
secondFrameId = requestAnimationFrame(() => {
|
|
60
|
+
if (!sawTransitionRun) {
|
|
61
|
+
finish()
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
})
|
|
65
|
+
})
|
|
66
|
+
}
|