@ui-doc/html-renderer 0.3.0 → 0.4.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/dist/HtmlCurlyBraceLexer.d.ts +4 -1
- package/dist/HtmlRenderer.d.ts +2 -2
- package/dist/InlineReader.d.ts +2 -1
- package/dist/{types/lexer.d.ts → Lexer.types.d.ts} +3 -1
- package/dist/NodeParser.d.ts +2 -1
- package/dist/{types/parser.d.ts → Parser.types.d.ts} +3 -3
- package/dist/{types/reader.d.ts → Reader.types.d.ts} +1 -1
- package/dist/{types/renderer.d.ts → Renderer.types.d.ts} +1 -1
- package/dist/TemplateLoader.d.ts +3 -2
- package/dist/{types/token.d.ts → Token.types.d.ts} +1 -1
- package/dist/assets/services/expand.d.ts +17 -0
- package/dist/assets/ui-doc.cjs +272 -9
- package/dist/assets/ui-doc.cjs.map +1 -1
- package/dist/assets/ui-doc.css +1169 -250
- package/dist/assets/ui-doc.css.map +1 -1
- package/dist/assets/ui-doc.min.css +9 -1
- package/dist/assets/ui-doc.min.js +1 -1
- package/dist/assets/ui-doc.mjs +272 -9
- package/dist/assets/ui-doc.mjs.map +1 -1
- package/dist/assets/{src/utils.d.ts → utils/delay.d.ts} +0 -1
- package/dist/assets/utils/dom.d.ts +28 -0
- package/dist/assets/utils/select.d.ts +12 -0
- package/dist/index.cjs +21 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.mjs +21 -18
- package/dist/index.mjs.map +1 -1
- package/dist/nodes/Node.d.ts +1 -1
- package/dist/nodes/tags/debug.d.ts +2 -1
- package/dist/nodes/tags/for.d.ts +2 -1
- package/dist/nodes/tags/if.d.ts +2 -1
- package/dist/nodes/tags/index.d.ts +1 -1
- package/dist/nodes/tags/page.d.ts +2 -1
- package/dist/nodes/tags/partial.d.ts +2 -1
- package/dist/nodes/tags/var.d.ts +2 -1
- package/package.json +3 -3
- package/scripts/app.ts +5 -3
- package/scripts/services/expand.ts +207 -0
- package/scripts/{src/utils.ts → utils/delay.ts} +0 -8
- package/scripts/utils/dom.ts +73 -0
- package/scripts/utils/select.ts +46 -0
- package/styles/01_resets/initial.css +8 -3
- package/styles/01_resets/root/color.css +19 -0
- package/styles/01_resets/root/font.css +28 -0
- package/styles/01_resets/root/space.css +30 -0
- package/styles/01_resets/root/witdh.css +12 -0
- package/styles/01_resets/root.css +61 -23
- package/styles/01_resets/typography.css +105 -8
- package/styles/02_utils/background.css +14 -0
- package/styles/02_utils/control.css +41 -0
- package/styles/02_utils/margin.css +150 -0
- package/styles/02_utils/padding.css +134 -0
- package/styles/02_utils/width.css +39 -0
- package/styles/03_components/button.css +42 -0
- package/styles/03_components/colors.css +7 -19
- package/styles/03_components/container.css +16 -0
- package/styles/03_components/example-markup.css +1 -6
- package/styles/03_components/grid-auto.css +49 -0
- package/styles/03_components/icons.css +7 -19
- package/styles/03_components/navigation/burger-control.css +75 -0
- package/styles/03_components/{nav → navigation}/list.css +9 -11
- package/styles/03_components/navigation/main.css +102 -0
- package/styles/03_components/spaces.css +8 -7
- package/styles/04_layout/body.css +22 -0
- package/styles/04_layout/inline-code.css +6 -0
- package/styles/04_layout/page.css +73 -0
- package/styles/index.css +58 -17
- package/templates/layouts/default.html +4 -6
- package/templates/layouts/example.html +1 -1
- package/templates/pages/default.html +13 -13
- package/templates/pages/index.html +9 -3
- package/templates/partials/code.html +1 -1
- package/templates/partials/colors.html +2 -2
- package/templates/partials/content.html +1 -1
- package/templates/partials/icons.html +3 -3
- package/templates/partials/nav-main.html +19 -8
- package/templates/partials/section.html +1 -1
- package/templates/partials/spaces.html +2 -2
- package/dist/types/index.d.ts +0 -6
- package/styles/02_objects/background.css +0 -7
- package/styles/02_objects/control.css +0 -25
- package/styles/02_objects/margin.css +0 -44
- package/styles/02_objects/padding.css +0 -44
- package/styles/02_objects/text.css +0 -3
- package/styles/02_objects/width.css +0 -16
- package/styles/03_components/nav/main.css +0 -39
- package/styles/03_components/text-flow.css +0 -5
- package/styles/04_layouts/page.css +0 -70
- /package/dist/{types/base.d.ts → Primitive.types.d.ts} +0 -0
- /package/dist/assets/{src → services}/example.d.ts +0 -0
- /package/dist/assets/{src → services}/sidebar.d.ts +0 -0
- /package/scripts/{src → services}/example.ts +0 -0
- /package/scripts/{src → services}/sidebar.ts +0 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ui-doc/html-renderer",
|
|
3
3
|
"description": "HTML renderer for UI-Doc.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.4.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"ui-doc",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
},
|
|
56
56
|
"sideEffects": false,
|
|
57
57
|
"peerDependencies": {
|
|
58
|
-
"@ui-doc/core": "^0.3.
|
|
58
|
+
"@ui-doc/core": "^0.3.1"
|
|
59
59
|
},
|
|
60
60
|
"optionalDependencies": {
|
|
61
61
|
"@highlightjs/cdn-assets": "^11.9.0"
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"scripts": {
|
|
64
64
|
"build": "rollup -c",
|
|
65
65
|
"prebuild": "rm -rf dist dist",
|
|
66
|
-
"
|
|
66
|
+
"prepublish": "pnpm build",
|
|
67
67
|
"release": "pnpm --workspace-root package:release $(pwd)",
|
|
68
68
|
"release:dry": "pnpm --workspace-root package:release-dry $(pwd)",
|
|
69
69
|
"test": "jest"
|
package/scripts/app.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { initExample } from './
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { initExample } from './services/example'
|
|
2
|
+
import { initExpand } from './services/expand'
|
|
3
|
+
import { initSidebar } from './services/sidebar'
|
|
4
|
+
import { ready } from './utils/dom'
|
|
4
5
|
|
|
5
6
|
ready(() => {
|
|
7
|
+
initExpand()
|
|
6
8
|
initExample()
|
|
7
9
|
initSidebar()
|
|
8
10
|
})
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { animate } from '../utils/dom'
|
|
2
|
+
import { queryParentSelector } from '../utils/select'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Sometimes you need to prevent the user from interacting with other elements while an element is expanded. Then you need the [inert](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/inert) attribute.
|
|
6
|
+
* You can set the `data-inert` attribute with selectors (comma separated) to control the `inert` attribute of elements matching your selectors.
|
|
7
|
+
* @location functions.expand.with-inerts Expand controlling inert
|
|
8
|
+
* @order 30
|
|
9
|
+
* @example
|
|
10
|
+
* <style>
|
|
11
|
+
* button::after {
|
|
12
|
+
* content: ' ' attr(aria-expanded);
|
|
13
|
+
* }
|
|
14
|
+
* </style>
|
|
15
|
+
* <button aria-expanded="false" aria-controls="target">Expanded:</button>
|
|
16
|
+
* <div id="target" hidden data-inert="[data-inert-controlled],#inert-controlled-2">Controlled Target</div>
|
|
17
|
+
* <div data-inert-controlled=""><button>Button 1.1</button><button>Button 1.2</button></div>
|
|
18
|
+
* <div id="inert-controlled-2"><button>Button 2.1</button><button>Button 2.2</button></div>
|
|
19
|
+
* @code
|
|
20
|
+
* <button aria-expanded="false" aria-controls="target">Expanded:</button>
|
|
21
|
+
* <div id="target" hidden data-inert="[data-inert-controlled],#inert-controlled-2">Controlled Target</div>
|
|
22
|
+
* <div data-inert-controlled="1"><button>Button 1.1</button><button>Button 1.2</button></div>
|
|
23
|
+
* <div id="inert-controlled-2"><button>Button 2.1</button><button>Button 2.2</button></div>
|
|
24
|
+
*/
|
|
25
|
+
function toggleInert(target: HTMLElement, show: boolean): void {
|
|
26
|
+
const inertSelector = target.getAttribute('data-inert')
|
|
27
|
+
|
|
28
|
+
if (!inertSelector) {
|
|
29
|
+
return
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
inertSelector.split(',').forEach(selector => {
|
|
33
|
+
// if the target is inside an element with the same selector, we don't want to remove the inert attribute
|
|
34
|
+
const activeParentWithSameSelector = !show
|
|
35
|
+
? queryParentSelector(
|
|
36
|
+
target.parentElement,
|
|
37
|
+
`[data-inert="${selector}"],[data-inert^="${selector},"],[data-inert$=",${selector}"],[data-inert*=",${selector},"]`,
|
|
38
|
+
)
|
|
39
|
+
: null
|
|
40
|
+
|
|
41
|
+
if (activeParentWithSameSelector) {
|
|
42
|
+
return
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
document.querySelectorAll(selector).forEach(invertOn => {
|
|
46
|
+
if (show) {
|
|
47
|
+
invertOn.setAttribute('inert', '')
|
|
48
|
+
} else {
|
|
49
|
+
invertOn.removeAttribute('inert')
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* If you want to control a specific aria you can combine [aria-expanded](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-expanded) attribute with [aria-controls](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-controls) attribute.
|
|
57
|
+
*
|
|
58
|
+
* When an element with the `aria-expanded` attribute is clicked, the value of the attribute will be toggled between `true` and `false`. Also the element with the id specified in the `aria-controls` attribute will be toggled between `aria-hidden="true"` and `aria-hidden="false"`. If no `aria-hidden` attribute is present, the `hidden` attribute will be used.`
|
|
59
|
+
*
|
|
60
|
+
* @location functions.expand.with-controls Expand with controls
|
|
61
|
+
* @order 10
|
|
62
|
+
* @example
|
|
63
|
+
* <style>
|
|
64
|
+
* button::after {
|
|
65
|
+
* content: ' ' attr(aria-expanded);
|
|
66
|
+
* }
|
|
67
|
+
* </style>
|
|
68
|
+
* <button aria-expanded="true" aria-controls="target-aria-hidden">Expanded:</button>
|
|
69
|
+
* <div id="target-aria-hidden" aria-hidden="false">Controlled Target</div>
|
|
70
|
+
* <hr>
|
|
71
|
+
* <button aria-expanded="true" aria-controls="target-hidden">Expanded:</button>
|
|
72
|
+
* <div id="target-hidden">Controlled Target</div>
|
|
73
|
+
* @code
|
|
74
|
+
* <button aria-expanded="true" aria-controls="target-aria-hidden">Expanded:</button>
|
|
75
|
+
* <div id="target-aria-hidden" aria-hidden="false">Controlled Target</div>
|
|
76
|
+
* <hr>
|
|
77
|
+
* <button aria-expanded="true" aria-controls="target-hidden">Expanded:</button>
|
|
78
|
+
* <div id="target-hidden">Controlled Target</div>
|
|
79
|
+
*/
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* You can add animations/transitions on the controlled element by adding the `data-animate` attribute with the animation name.
|
|
83
|
+
* The animation name will be used to add the necessary classes to the element to trigger the animation.
|
|
84
|
+
* Please refer to the animate function for more information, what classes will be added and when.
|
|
85
|
+
*
|
|
86
|
+
* @location functions.expand.with-animation Expand with animation
|
|
87
|
+
* @order 20
|
|
88
|
+
* @example
|
|
89
|
+
* <style>
|
|
90
|
+
* .fade-enter-active,
|
|
91
|
+
* .fade-leave-active {
|
|
92
|
+
* transition: opacity 0.5s ease;
|
|
93
|
+
* }
|
|
94
|
+
*
|
|
95
|
+
* .fade-enter-from,
|
|
96
|
+
* .fade-leave-to {
|
|
97
|
+
* opacity: 0;
|
|
98
|
+
* }
|
|
99
|
+
* </style>
|
|
100
|
+
* <button aria-expanded="true" aria-controls="target-hidden">Toggle Controlled Area</button>
|
|
101
|
+
* <div id="target-hidden" data-animate="fade">Controlled Target</div>
|
|
102
|
+
*/
|
|
103
|
+
function toggleControlTarget(selector: string, show: boolean, callback: () => void): void {
|
|
104
|
+
const target = document.querySelector<HTMLElement>(selector)
|
|
105
|
+
|
|
106
|
+
if (!target) {
|
|
107
|
+
return
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const animationName = target.getAttribute('data-animate')
|
|
111
|
+
const toggleHide = () => {
|
|
112
|
+
if (target.hasAttribute('aria-hidden')) {
|
|
113
|
+
target.setAttribute('aria-hidden', show ? 'false' : 'true')
|
|
114
|
+
} else if (show) {
|
|
115
|
+
target.removeAttribute('hidden')
|
|
116
|
+
} else {
|
|
117
|
+
target.setAttribute('hidden', '')
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
callback()
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (show) {
|
|
124
|
+
// set tabindex=0 for all elements with tabindex=-1 that are not inside an aria-hidden element
|
|
125
|
+
target
|
|
126
|
+
.querySelectorAll<HTMLElement>(
|
|
127
|
+
':scope > [tabindex="-1"], [tabindex="-1"]:not([aria-hidden="true"] [tabindex="-1"], [hidden] [tabindex="-1"])',
|
|
128
|
+
)
|
|
129
|
+
.forEach(el => {
|
|
130
|
+
el.setAttribute('tabindex', '0')
|
|
131
|
+
})
|
|
132
|
+
} else {
|
|
133
|
+
// set tabindex=-1 for all elements with tabindex=0
|
|
134
|
+
target.querySelectorAll<HTMLElement>('[tabindex="0"]').forEach(el => {
|
|
135
|
+
el.setAttribute('tabindex', '-1')
|
|
136
|
+
})
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
toggleInert(target, show)
|
|
140
|
+
|
|
141
|
+
if (animationName) {
|
|
142
|
+
if (show) {
|
|
143
|
+
toggleHide()
|
|
144
|
+
animate(target, animationName, show)
|
|
145
|
+
} else {
|
|
146
|
+
animate(target, animationName, show, toggleHide)
|
|
147
|
+
}
|
|
148
|
+
} else {
|
|
149
|
+
toggleHide()
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Initialize expandable/collapsable elements by using the [aria-expanded](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-expanded) attribute.
|
|
155
|
+
*
|
|
156
|
+
* When an element with the `aria-expanded` attribute is clicked, the value of the attribute will be toggled between `true` and `false`.
|
|
157
|
+
*
|
|
158
|
+
* @location functions.expand Expand
|
|
159
|
+
* @example
|
|
160
|
+
* <style>
|
|
161
|
+
* button::after {
|
|
162
|
+
* content: ' ' attr(aria-expanded);
|
|
163
|
+
* }
|
|
164
|
+
* </style>
|
|
165
|
+
* <button aria-expanded="false">Expanded:</button>
|
|
166
|
+
* @code
|
|
167
|
+
* <button aria-expanded="false">Expanded:</button>
|
|
168
|
+
*/
|
|
169
|
+
export function initExpand(): void {
|
|
170
|
+
document.querySelectorAll<HTMLElement>('[aria-expanded]').forEach(expander => {
|
|
171
|
+
const controlTarget = expander.getAttribute('aria-controls')
|
|
172
|
+
const toggle = (e: MouseEvent) => {
|
|
173
|
+
const expanded = expander.getAttribute('aria-expanded') === 'true'
|
|
174
|
+
const toggleExpanded = () => {
|
|
175
|
+
expander.setAttribute('aria-expanded', expanded ? 'false' : 'true') // when expanded we need to set false
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// if data-hide-same-level is set, we need to klick all other expanded elements to close them
|
|
179
|
+
if (expander.parentElement && expander.hasAttribute('data-hide-same-level')) {
|
|
180
|
+
Array.from(expander.parentElement.querySelectorAll(':scope > [aria-expanded="true"]'))
|
|
181
|
+
.filter(el => el !== expander && el !== e.relatedTarget)
|
|
182
|
+
.forEach(sibling => {
|
|
183
|
+
sibling.dispatchEvent(
|
|
184
|
+
new MouseEvent('click', { bubbles: true, relatedTarget: expander }),
|
|
185
|
+
)
|
|
186
|
+
})
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (controlTarget) {
|
|
190
|
+
toggleControlTarget(`#${controlTarget}`, !expanded, toggleExpanded)
|
|
191
|
+
} else {
|
|
192
|
+
toggleExpanded()
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
expander.addEventListener('click', toggle)
|
|
197
|
+
|
|
198
|
+
if (controlTarget) {
|
|
199
|
+
// select all controls inside the controlled area that have the same aria-controls attribute
|
|
200
|
+
document
|
|
201
|
+
.querySelectorAll<HTMLElement>(`#${controlTarget} [aria-controls="${controlTarget}"]`)
|
|
202
|
+
.forEach(control => {
|
|
203
|
+
control.addEventListener('click', toggle)
|
|
204
|
+
})
|
|
205
|
+
}
|
|
206
|
+
})
|
|
207
|
+
}
|
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
export function ready(callback: () => void) {
|
|
2
|
-
if (document.readyState !== 'loading') {
|
|
3
|
-
callback()
|
|
4
|
-
} else {
|
|
5
|
-
document.addEventListener('DOMContentLoaded', callback)
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
|
|
9
1
|
export function throttle(callback: (...args: any[]) => void, delay: number) {
|
|
10
2
|
let timerFlag: number | null = null
|
|
11
3
|
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Run function when dom is ready
|
|
3
|
+
*
|
|
4
|
+
* @param callback function to run when dom is ready
|
|
5
|
+
*/
|
|
6
|
+
export function ready(callback: (this: Document) => void): void {
|
|
7
|
+
if (document.readyState !== 'loading') {
|
|
8
|
+
callback.call(document)
|
|
9
|
+
} else {
|
|
10
|
+
document.addEventListener('DOMContentLoaded', callback)
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Animate an element using css animations/transitions. This function will add the necessary classes to the element to trigger the animation.
|
|
16
|
+
* When doing an entering animation following classes will be added:
|
|
17
|
+
* - `[animation-name]-enter-active`
|
|
18
|
+
* - `[animation-name]-enter-from`
|
|
19
|
+
* - `[animation-name]-enter-to`
|
|
20
|
+
* When doing a leaving animation following classes will be added:
|
|
21
|
+
* - `[animation-name]-leave-active`
|
|
22
|
+
* - `[animation-name]-leave-from`
|
|
23
|
+
* - `[animation-name]-leave-to`
|
|
24
|
+
*
|
|
25
|
+
* The animation classes will be removed after the animation is done. If a callback is provided it will be called after the animation is done.
|
|
26
|
+
*
|
|
27
|
+
* The `-active` class will stay on the element until the animation is done. The `-from` class will be removed after the first frame and the `-to`
|
|
28
|
+
* class will be added after the first frame.
|
|
29
|
+
*
|
|
30
|
+
* @param target html element to animate
|
|
31
|
+
* @param animationName animation name to be used
|
|
32
|
+
* @param entering determine if the elements animation should be entering or leaving
|
|
33
|
+
* @param callback to be called after the animation is done
|
|
34
|
+
*/
|
|
35
|
+
export function animate(
|
|
36
|
+
target: HTMLElement,
|
|
37
|
+
animationName: string,
|
|
38
|
+
entering: boolean,
|
|
39
|
+
callback?: () => void,
|
|
40
|
+
): void {
|
|
41
|
+
const animationState = entering ? 'enter' : 'leave'
|
|
42
|
+
const animateClassActive = `${animationName}-${animationState}-active`
|
|
43
|
+
const animateClassTo = `${animationName}-${animationState}-to`
|
|
44
|
+
const animateClassFrom = `${animationName}-${animationState}-from`
|
|
45
|
+
const afterAnimation = () => {
|
|
46
|
+
target.classList.remove(animateClassTo, animateClassActive)
|
|
47
|
+
target.removeEventListener('animationend', afterAnimation)
|
|
48
|
+
target.removeEventListener('transitionend', afterAnimation)
|
|
49
|
+
|
|
50
|
+
if (callback) {
|
|
51
|
+
callback()
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
target.addEventListener('animationend', afterAnimation)
|
|
56
|
+
target.addEventListener('transitionend', afterAnimation)
|
|
57
|
+
|
|
58
|
+
target.addEventListener('animationcancel', afterAnimation)
|
|
59
|
+
target.addEventListener('transitioncancel', afterAnimation)
|
|
60
|
+
|
|
61
|
+
target.classList.add(animateClassActive, animateClassFrom)
|
|
62
|
+
requestAnimationFrame(() => {
|
|
63
|
+
const styles = window.getComputedStyle(target)
|
|
64
|
+
|
|
65
|
+
// if the element has no transition or animation we can call the afterAnimation function in the next frame
|
|
66
|
+
if (['all', 'none'].includes(styles.transition) && styles.animationName === 'none') {
|
|
67
|
+
requestAnimationFrame(afterAnimation)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
target.classList.remove(animateClassFrom)
|
|
71
|
+
target.classList.add(animateClassTo)
|
|
72
|
+
})
|
|
73
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Query the first parent element that matches the selector
|
|
3
|
+
*
|
|
4
|
+
* @param element to search in
|
|
5
|
+
* @param selector to be matched
|
|
6
|
+
* @param maxDepth maximum depth to search
|
|
7
|
+
* @returns element that matches the selector
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export function queryParentSelector<K extends keyof HTMLElementTagNameMap>(
|
|
11
|
+
element: HTMLElement | null,
|
|
12
|
+
selector: K,
|
|
13
|
+
maxDepth?: number,
|
|
14
|
+
): HTMLElementTagNameMap[K] | null
|
|
15
|
+
export function queryParentSelector<K extends keyof SVGElementTagNameMap>(
|
|
16
|
+
element: HTMLElement | null,
|
|
17
|
+
selector: K,
|
|
18
|
+
maxDepth?: number,
|
|
19
|
+
): SVGElementTagNameMap[K] | null
|
|
20
|
+
export function queryParentSelector<K extends keyof MathMLElementTagNameMap>(
|
|
21
|
+
element: HTMLElement | null,
|
|
22
|
+
selectors: K,
|
|
23
|
+
maxDepth?: number,
|
|
24
|
+
): MathMLElementTagNameMap[K] | null
|
|
25
|
+
export function queryParentSelector<E extends Element = Element>(
|
|
26
|
+
element: HTMLElement | null,
|
|
27
|
+
selector: string,
|
|
28
|
+
maxDepth?: number,
|
|
29
|
+
): E | null
|
|
30
|
+
export function queryParentSelector(
|
|
31
|
+
element: HTMLElement | null,
|
|
32
|
+
selector: string,
|
|
33
|
+
maxDepth = 10,
|
|
34
|
+
): Element | null {
|
|
35
|
+
if (maxDepth <= 0 || element === null) {
|
|
36
|
+
return null
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (element.matches(selector)) {
|
|
40
|
+
return element as Element
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return element.parentElement
|
|
44
|
+
? queryParentSelector(element.parentElement, selector, maxDepth - 1)
|
|
45
|
+
: null
|
|
46
|
+
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
* {
|
|
2
2
|
box-sizing: border-box;
|
|
3
|
-
margin: 0;
|
|
4
3
|
}
|
|
5
4
|
|
|
6
5
|
*::after,
|
|
@@ -10,9 +9,15 @@
|
|
|
10
9
|
|
|
11
10
|
::selection {
|
|
12
11
|
color: rgb(var(--selection-color));
|
|
13
|
-
background
|
|
12
|
+
background: rgb(var(--selection-bg-color));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
html {
|
|
16
|
+
scroll-behavior: smooth;
|
|
17
|
+
scroll-padding-top: var(--scroll-padding-top, 0);
|
|
14
18
|
}
|
|
15
19
|
|
|
16
20
|
body {
|
|
17
|
-
|
|
21
|
+
margin: 0;
|
|
22
|
+
background: rgb(var(--bg-color));
|
|
18
23
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The color variables are used to define the color palette.
|
|
3
|
+
*
|
|
4
|
+
* The color variables are defined by RGB value. When you want to use a color you need use the `rgb()` function. For example: `rgb(var(--color-black))`.
|
|
5
|
+
*
|
|
6
|
+
* @location variables.colors Colors
|
|
7
|
+
* @color {0 0 0|255 255 255} --color-black | Black
|
|
8
|
+
* @color {20 33 61|255 255 255} --color-blue | Blue
|
|
9
|
+
* @color {252 163 17} --color-yellow | Yellow
|
|
10
|
+
* @color {229 229 229} --color-gray | Gray
|
|
11
|
+
* @color {255 255 255} --color-white | White
|
|
12
|
+
*/
|
|
13
|
+
:root {
|
|
14
|
+
--color-black: 0 0 0;
|
|
15
|
+
--color-blue: 20 33 61;
|
|
16
|
+
--color-yellow: 252 163 17;
|
|
17
|
+
--color-gray: 229 229 229;
|
|
18
|
+
--color-white: 255 255 255;
|
|
19
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Set of predefined font variables.
|
|
3
|
+
*
|
|
4
|
+
* @location variables.font Font
|
|
5
|
+
*/
|
|
6
|
+
:root {
|
|
7
|
+
/**
|
|
8
|
+
* Font weights are a set of predefined values that can be used to define the weight of a font:
|
|
9
|
+
* - **--font-weight-normal**
|
|
10
|
+
* - **--font-weight-bold**
|
|
11
|
+
*
|
|
12
|
+
* @location variables.font.weight Font weight
|
|
13
|
+
*/
|
|
14
|
+
--font-weight-normal: 400;
|
|
15
|
+
--font-weight-bold: 700;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Font sizes are a set of predefined values that can be used to define the size of a font:
|
|
19
|
+
* - **--font-size-sm**
|
|
20
|
+
* - **--font-size-normal**
|
|
21
|
+
* - **--font-size-md**
|
|
22
|
+
*
|
|
23
|
+
* @location variables.font.size Font size
|
|
24
|
+
*/
|
|
25
|
+
--font-size-sm: 0.85em;
|
|
26
|
+
--font-size-normal: 1em;
|
|
27
|
+
--font-size-md: 1.2em;
|
|
28
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Space are a set of predefined values that can be used to define the space of an element.
|
|
3
|
+
* When spaces are used there is always a set of two variables you can use the `--space-unit` and `--space-<size>`.
|
|
4
|
+
* The `--space-unit` is the base unit that will be multiplied by the `--space-<size>`. Depending on the context
|
|
5
|
+
* you are using the space `<size>` changes.
|
|
6
|
+
*
|
|
7
|
+
* The predefined space can the be set in a specific context by defining the `--space-<size>` variable.
|
|
8
|
+
* For example the space unit is `1rem` and we are in the padding context, we can use `--space-pt: var(--space-md);` to change the padding
|
|
9
|
+
* top to the medium space.
|
|
10
|
+
*
|
|
11
|
+
* @location variables.spaces Spaces
|
|
12
|
+
* @space {0.35em} --space-xxs | Extra extra small
|
|
13
|
+
* @space {0.5em} --space-xs | Extra small
|
|
14
|
+
* @space {0.7em} --space-sm | Small
|
|
15
|
+
* @space {1em} --space-normal | Normal
|
|
16
|
+
* @space {1.3em} --space-md | Medium
|
|
17
|
+
* @space {1.8em} --space-lg | Large
|
|
18
|
+
* @space {3.2em} --space-xl | Extra large
|
|
19
|
+
* @space {4.8em} --space-xxl | Extra extra large
|
|
20
|
+
*/
|
|
21
|
+
:root {
|
|
22
|
+
--space-xxs: 0.35;
|
|
23
|
+
--space-xs: 0.5;
|
|
24
|
+
--space-sm: 0.7;
|
|
25
|
+
--space-normal: 1;
|
|
26
|
+
--space-md: 1.3;
|
|
27
|
+
--space-lg: 1.8;
|
|
28
|
+
--space-xl: 3.2;
|
|
29
|
+
--space-xxl: 4.8;
|
|
30
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Widths are a set of predefined values that can be used to limit the content width.
|
|
3
|
+
*
|
|
4
|
+
* - `--width-min-offset-x` - The minimum space on the left and right side.
|
|
5
|
+
* - `--width-content` - The width of the content.
|
|
6
|
+
*
|
|
7
|
+
* @location variables.width Width (Content)
|
|
8
|
+
*/
|
|
9
|
+
:root {
|
|
10
|
+
--width-min-offset-x: 22px;
|
|
11
|
+
--width-content: 1200px;
|
|
12
|
+
}
|
|
@@ -1,36 +1,74 @@
|
|
|
1
|
+
@import url("./root/color.css");
|
|
2
|
+
@import url("./root/font.css");
|
|
3
|
+
@import url("./root/space.css");
|
|
4
|
+
@import url("./root/witdh.css");
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* There are some global veriables that are used in the project. These variables are a base set and can be changed depending on context and requirements. All components are using these variables to define the style or as a fallback if there more specific named variable is not present.
|
|
8
|
+
*
|
|
9
|
+
* @location variables.global Globals
|
|
10
|
+
*/
|
|
1
11
|
:root {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
12
|
+
/**
|
|
13
|
+
* - `--font-space-unit` - The spacing unit when using font related spaces (see the spaces documentation for mor details).
|
|
14
|
+
* - `--font-size-base` - The base font size.
|
|
15
|
+
* - `--font-color` - used font color.
|
|
16
|
+
* - `--font-family` - uded font family.
|
|
17
|
+
* - `--font-weight` - used font weight.
|
|
18
|
+
* - `--font-size` - used font size.
|
|
19
|
+
* - `--font-line-height` - used font line height.
|
|
20
|
+
*
|
|
21
|
+
* @location variables.global.font Font
|
|
22
|
+
*/
|
|
23
|
+
--font-space-unit: 1em;
|
|
8
24
|
--font-size-base: 16px;
|
|
9
|
-
--font-color:
|
|
25
|
+
--font-color: var(--color-black);
|
|
10
26
|
--font-family: system-ui, "Segoe UI", roboto, helvetica, arial, sans-serif, "Apple Color Emoji",
|
|
11
27
|
"Segoe UI Emoji", "Segoe UI Symbol";
|
|
12
28
|
--font-weight: var(--font-weight-normal);
|
|
13
29
|
--font-size: var(--font-size-normal);
|
|
14
30
|
--font-line-height: 1.4;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* - `--bg-color` - used background color
|
|
34
|
+
* - `--accent-color` - used accent color
|
|
35
|
+
* - `--selection-color` - used selection color
|
|
36
|
+
* - `--selection-bg-color` - used selection background color
|
|
37
|
+
* - `--animation-time` - used animation time
|
|
38
|
+
*
|
|
39
|
+
* @location variables.global.colors Colors
|
|
40
|
+
*/
|
|
41
|
+
--bg-color: var(--color-white);
|
|
42
|
+
--accent-color: var(--color-yellow);
|
|
19
43
|
--selection-color: var(--bg-color);
|
|
20
44
|
--selection-bg-color: var(--font-color);
|
|
21
|
-
--
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
--
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
45
|
+
--space-unit: 1em;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
*
|
|
49
|
+
* - `--animation-time` - used animation time
|
|
50
|
+
*
|
|
51
|
+
* @location variables.global.animation Animation
|
|
52
|
+
*/
|
|
53
|
+
--animation-time: 0.25s;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @location variables.global.nav-main Main navigation
|
|
57
|
+
*/
|
|
58
|
+
--nav-main-bar-item-space-x: var(--space-normal);
|
|
59
|
+
--nav-main-bar-item-space-y: var(--space-sm);
|
|
60
|
+
--nav-main-bar-item-height: calc(
|
|
61
|
+
(var(--font-size) * var(--font-line-height)) +
|
|
62
|
+
(var(--space-unit) * var(--nav-main-bar-item-space-y) * 2)
|
|
33
63
|
);
|
|
64
|
+
--nav-main-menu-space-t: var(--space-sm);
|
|
65
|
+
--nav-main-menu-space-b: var(--space-normal);
|
|
66
|
+
--nav-main-height: var(--nav-main-bar-item-height);
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @location variables.global.nav-main Main navigation
|
|
70
|
+
*/
|
|
71
|
+
--scroll-padding-top: var(--nav-main-height);
|
|
34
72
|
|
|
35
73
|
color-scheme: light;
|
|
36
74
|
}
|