@ui-doc/html-renderer 0.2.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 +288 -15
- 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 +288 -15
- package/dist/assets/ui-doc.mjs.map +1 -1
- package/dist/assets/utils/delay.d.ts +1 -0
- 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/example.ts +44 -0
- package/scripts/services/expand.ts +207 -0
- package/scripts/utils/delay.ts +12 -0
- 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/assets/src/base.d.ts +0 -1
- package/dist/types/index.d.ts +0 -6
- package/scripts/src/base.ts +0 -7
- package/scripts/src/example.ts +0 -31
- 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}/sidebar.ts +0 -0
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import type { Lexer
|
|
1
|
+
import type { Lexer } from './Lexer.types';
|
|
2
|
+
import type { PositiveInteger } from './Primitive.types';
|
|
3
|
+
import type { Reader } from './Reader.types';
|
|
4
|
+
import type { Token, TokenBoolean, TokenComment, TokenIdentifier, TokenNumber, TokenOperator, TokenReturn, TokenString, TokenTemplate, TokenTypeIdentifier } from './Token.types';
|
|
2
5
|
export declare class HtmlCurlyBraceLexer implements Lexer {
|
|
3
6
|
protected reader: Reader;
|
|
4
7
|
protected currentTokens: (Token | undefined)[];
|
package/dist/HtmlRenderer.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { GenerateContext } from '@ui-doc/core';
|
|
2
2
|
import type { Node } from './nodes';
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
3
|
+
import type { Parser } from './Parser.types';
|
|
4
|
+
import type { RenderContext, Renderer, SourceInput } from './Renderer.types';
|
|
5
5
|
export declare class HtmlRenderer implements Renderer {
|
|
6
6
|
protected parser: Parser;
|
|
7
7
|
protected layouts: Record<string, Node>;
|
package/dist/InlineReader.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { PositiveInteger
|
|
1
|
+
import type { PositiveInteger } from './Primitive.types';
|
|
2
|
+
import type { Reader } from './Reader.types';
|
|
2
3
|
export declare class InlineReader implements Reader {
|
|
3
4
|
protected input: string;
|
|
4
5
|
protected source: string;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import type { PositiveInteger
|
|
1
|
+
import type { PositiveInteger } from './Primitive.types';
|
|
2
|
+
import type { Reader } from './Reader.types';
|
|
3
|
+
import type { TokenReturn } from './Token.types';
|
|
2
4
|
export interface Lexer {
|
|
3
5
|
/**
|
|
4
6
|
* Get the next token /next k-th token.
|
package/dist/NodeParser.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { HtmlCurlyBraceLexer } from './HtmlCurlyBraceLexer';
|
|
2
2
|
import type { TagNode } from './nodes';
|
|
3
3
|
import { Node } from './nodes/Node';
|
|
4
|
-
import type { Parser,
|
|
4
|
+
import type { Parser, TagNodeParse } from './Parser.types';
|
|
5
|
+
import type { Reader } from './Reader.types';
|
|
5
6
|
export declare class NodeParser implements Parser {
|
|
6
7
|
protected tags: Record<string, TagNodeParse>;
|
|
7
8
|
static init(): NodeParser;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Node, TagNode } from '
|
|
2
|
-
import type { Reader } from './
|
|
3
|
-
import type { Token } from './
|
|
1
|
+
import type { Node, TagNode } from './nodes';
|
|
2
|
+
import type { Reader } from './Reader.types';
|
|
3
|
+
import type { Token } from './Token.types';
|
|
4
4
|
export interface TagNodeParse {
|
|
5
5
|
identifier: string;
|
|
6
6
|
example: string;
|
package/dist/TemplateLoader.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { FileSystem } from '@ui-doc/core';
|
|
2
2
|
import type { HtmlRenderer } from './HtmlRenderer';
|
|
3
3
|
export declare class TemplateLoader {
|
|
4
|
-
static
|
|
4
|
+
static readonly TEMPLATES_PACKAGE: string;
|
|
5
|
+
static load({ renderer, fileSystem, templatePath, }: {
|
|
5
6
|
renderer: HtmlRenderer;
|
|
6
7
|
fileSystem: FileSystem;
|
|
7
|
-
|
|
8
|
+
templatePath: string;
|
|
8
9
|
}): Promise<void>;
|
|
9
10
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PositiveInteger } from './
|
|
1
|
+
import type { PositiveInteger } from './Primitive.types';
|
|
2
2
|
export type TokenTypeIdentifier = 'tag-identifier' | 'identifier';
|
|
3
3
|
export type TokenTagType = 'tag-open' | 'tag-close' | 'tag-end' | 'tag-separator';
|
|
4
4
|
export type TokenType = 'comment' | 'template' | 'operator' | 'number' | 'string' | 'boolean' | TokenTypeIdentifier | TokenTagType;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Initialize expandable/collapsable elements by using the [aria-expanded](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-expanded) attribute.
|
|
3
|
+
*
|
|
4
|
+
* When an element with the `aria-expanded` attribute is clicked, the value of the attribute will be toggled between `true` and `false`.
|
|
5
|
+
*
|
|
6
|
+
* @location functions.expand Expand
|
|
7
|
+
* @example
|
|
8
|
+
* <style>
|
|
9
|
+
* button::after {
|
|
10
|
+
* content: ' ' attr(aria-expanded);
|
|
11
|
+
* }
|
|
12
|
+
* </style>
|
|
13
|
+
* <button aria-expanded="false">Expanded:</button>
|
|
14
|
+
* @code
|
|
15
|
+
* <button aria-expanded="false">Expanded:</button>
|
|
16
|
+
*/
|
|
17
|
+
export declare function initExpand(): void;
|
package/dist/assets/ui-doc.cjs
CHANGED
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
function ready(callback) {
|
|
4
|
-
if (document.readyState !== 'loading') {
|
|
5
|
-
callback();
|
|
6
|
-
}
|
|
7
|
-
else {
|
|
8
|
-
document.addEventListener('DOMContentLoaded', callback);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
3
|
function initExample() {
|
|
13
4
|
document.querySelectorAll('[data-example] > iframe').forEach(iframe => {
|
|
14
5
|
var _a, _b;
|
|
@@ -16,23 +7,304 @@ function initExample() {
|
|
|
16
7
|
if (!document) {
|
|
17
8
|
return;
|
|
18
9
|
}
|
|
19
|
-
const
|
|
10
|
+
const initHeightChange = () => {
|
|
11
|
+
let currentHeight = 0;
|
|
20
12
|
const changeHeight = () => {
|
|
21
|
-
|
|
13
|
+
if (document.body.scrollHeight === currentHeight) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
currentHeight = document.body.scrollHeight;
|
|
17
|
+
iframe.style.height = `${currentHeight}px`;
|
|
22
18
|
};
|
|
19
|
+
// Initial height change
|
|
23
20
|
changeHeight();
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
// Use MutationObserver to detect changes in the DOM and change height if required
|
|
22
|
+
const mutationObserver = new MutationObserver(changeHeight);
|
|
23
|
+
mutationObserver.observe(document.body, {
|
|
26
24
|
attributes: true,
|
|
27
25
|
childList: true,
|
|
28
26
|
subtree: true,
|
|
29
27
|
});
|
|
28
|
+
// Use ResizeObserver to detect changes in the viewport and change height if required
|
|
29
|
+
const resizeObserver = new ResizeObserver(changeHeight);
|
|
30
|
+
resizeObserver.observe(document.body);
|
|
30
31
|
};
|
|
31
32
|
if (document.readyState === 'complete') {
|
|
32
|
-
|
|
33
|
+
initHeightChange();
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
iframe.addEventListener('load', initHeightChange);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Run function when dom is ready
|
|
43
|
+
*
|
|
44
|
+
* @param callback function to run when dom is ready
|
|
45
|
+
*/
|
|
46
|
+
function ready(callback) {
|
|
47
|
+
if (document.readyState !== 'loading') {
|
|
48
|
+
callback.call(document);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
document.addEventListener('DOMContentLoaded', callback);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Animate an element using css animations/transitions. This function will add the necessary classes to the element to trigger the animation.
|
|
56
|
+
* When doing an entering animation following classes will be added:
|
|
57
|
+
* - `[animation-name]-enter-active`
|
|
58
|
+
* - `[animation-name]-enter-from`
|
|
59
|
+
* - `[animation-name]-enter-to`
|
|
60
|
+
* When doing a leaving animation following classes will be added:
|
|
61
|
+
* - `[animation-name]-leave-active`
|
|
62
|
+
* - `[animation-name]-leave-from`
|
|
63
|
+
* - `[animation-name]-leave-to`
|
|
64
|
+
*
|
|
65
|
+
* 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.
|
|
66
|
+
*
|
|
67
|
+
* 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`
|
|
68
|
+
* class will be added after the first frame.
|
|
69
|
+
*
|
|
70
|
+
* @param target html element to animate
|
|
71
|
+
* @param animationName animation name to be used
|
|
72
|
+
* @param entering determine if the elements animation should be entering or leaving
|
|
73
|
+
* @param callback to be called after the animation is done
|
|
74
|
+
*/
|
|
75
|
+
function animate(target, animationName, entering, callback) {
|
|
76
|
+
const animationState = entering ? 'enter' : 'leave';
|
|
77
|
+
const animateClassActive = `${animationName}-${animationState}-active`;
|
|
78
|
+
const animateClassTo = `${animationName}-${animationState}-to`;
|
|
79
|
+
const animateClassFrom = `${animationName}-${animationState}-from`;
|
|
80
|
+
const afterAnimation = () => {
|
|
81
|
+
target.classList.remove(animateClassTo, animateClassActive);
|
|
82
|
+
target.removeEventListener('animationend', afterAnimation);
|
|
83
|
+
target.removeEventListener('transitionend', afterAnimation);
|
|
84
|
+
if (callback) {
|
|
85
|
+
callback();
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
target.addEventListener('animationend', afterAnimation);
|
|
89
|
+
target.addEventListener('transitionend', afterAnimation);
|
|
90
|
+
target.addEventListener('animationcancel', afterAnimation);
|
|
91
|
+
target.addEventListener('transitioncancel', afterAnimation);
|
|
92
|
+
target.classList.add(animateClassActive, animateClassFrom);
|
|
93
|
+
requestAnimationFrame(() => {
|
|
94
|
+
const styles = window.getComputedStyle(target);
|
|
95
|
+
// if the element has no transition or animation we can call the afterAnimation function in the next frame
|
|
96
|
+
if (['all', 'none'].includes(styles.transition) && styles.animationName === 'none') {
|
|
97
|
+
requestAnimationFrame(afterAnimation);
|
|
98
|
+
}
|
|
99
|
+
target.classList.remove(animateClassFrom);
|
|
100
|
+
target.classList.add(animateClassTo);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Query the first parent element that matches the selector
|
|
106
|
+
*
|
|
107
|
+
* @param element to search in
|
|
108
|
+
* @param selector to be matched
|
|
109
|
+
* @param maxDepth maximum depth to search
|
|
110
|
+
* @returns element that matches the selector
|
|
111
|
+
*/
|
|
112
|
+
function queryParentSelector(element, selector, maxDepth = 10) {
|
|
113
|
+
if (maxDepth <= 0 || element === null) {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
if (element.matches(selector)) {
|
|
117
|
+
return element;
|
|
118
|
+
}
|
|
119
|
+
return element.parentElement
|
|
120
|
+
? queryParentSelector(element.parentElement, selector, maxDepth - 1)
|
|
121
|
+
: null;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* 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.
|
|
126
|
+
* You can set the `data-inert` attribute with selectors (comma separated) to control the `inert` attribute of elements matching your selectors.
|
|
127
|
+
* @location functions.expand.with-inerts Expand controlling inert
|
|
128
|
+
* @order 30
|
|
129
|
+
* @example
|
|
130
|
+
* <style>
|
|
131
|
+
* button::after {
|
|
132
|
+
* content: ' ' attr(aria-expanded);
|
|
133
|
+
* }
|
|
134
|
+
* </style>
|
|
135
|
+
* <button aria-expanded="false" aria-controls="target">Expanded:</button>
|
|
136
|
+
* <div id="target" hidden data-inert="[data-inert-controlled],#inert-controlled-2">Controlled Target</div>
|
|
137
|
+
* <div data-inert-controlled=""><button>Button 1.1</button><button>Button 1.2</button></div>
|
|
138
|
+
* <div id="inert-controlled-2"><button>Button 2.1</button><button>Button 2.2</button></div>
|
|
139
|
+
* @code
|
|
140
|
+
* <button aria-expanded="false" aria-controls="target">Expanded:</button>
|
|
141
|
+
* <div id="target" hidden data-inert="[data-inert-controlled],#inert-controlled-2">Controlled Target</div>
|
|
142
|
+
* <div data-inert-controlled="1"><button>Button 1.1</button><button>Button 1.2</button></div>
|
|
143
|
+
* <div id="inert-controlled-2"><button>Button 2.1</button><button>Button 2.2</button></div>
|
|
144
|
+
*/
|
|
145
|
+
function toggleInert(target, show) {
|
|
146
|
+
const inertSelector = target.getAttribute('data-inert');
|
|
147
|
+
if (!inertSelector) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
inertSelector.split(',').forEach(selector => {
|
|
151
|
+
// if the target is inside an element with the same selector, we don't want to remove the inert attribute
|
|
152
|
+
const activeParentWithSameSelector = !show
|
|
153
|
+
? queryParentSelector(target.parentElement, `[data-inert="${selector}"],[data-inert^="${selector},"],[data-inert$=",${selector}"],[data-inert*=",${selector},"]`)
|
|
154
|
+
: null;
|
|
155
|
+
if (activeParentWithSameSelector) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
document.querySelectorAll(selector).forEach(invertOn => {
|
|
159
|
+
if (show) {
|
|
160
|
+
invertOn.setAttribute('inert', '');
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
invertOn.removeAttribute('inert');
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* 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.
|
|
170
|
+
*
|
|
171
|
+
* 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.`
|
|
172
|
+
*
|
|
173
|
+
* @location functions.expand.with-controls Expand with controls
|
|
174
|
+
* @order 10
|
|
175
|
+
* @example
|
|
176
|
+
* <style>
|
|
177
|
+
* button::after {
|
|
178
|
+
* content: ' ' attr(aria-expanded);
|
|
179
|
+
* }
|
|
180
|
+
* </style>
|
|
181
|
+
* <button aria-expanded="true" aria-controls="target-aria-hidden">Expanded:</button>
|
|
182
|
+
* <div id="target-aria-hidden" aria-hidden="false">Controlled Target</div>
|
|
183
|
+
* <hr>
|
|
184
|
+
* <button aria-expanded="true" aria-controls="target-hidden">Expanded:</button>
|
|
185
|
+
* <div id="target-hidden">Controlled Target</div>
|
|
186
|
+
* @code
|
|
187
|
+
* <button aria-expanded="true" aria-controls="target-aria-hidden">Expanded:</button>
|
|
188
|
+
* <div id="target-aria-hidden" aria-hidden="false">Controlled Target</div>
|
|
189
|
+
* <hr>
|
|
190
|
+
* <button aria-expanded="true" aria-controls="target-hidden">Expanded:</button>
|
|
191
|
+
* <div id="target-hidden">Controlled Target</div>
|
|
192
|
+
*/
|
|
193
|
+
/**
|
|
194
|
+
* You can add animations/transitions on the controlled element by adding the `data-animate` attribute with the animation name.
|
|
195
|
+
* The animation name will be used to add the necessary classes to the element to trigger the animation.
|
|
196
|
+
* Please refer to the animate function for more information, what classes will be added and when.
|
|
197
|
+
*
|
|
198
|
+
* @location functions.expand.with-animation Expand with animation
|
|
199
|
+
* @order 20
|
|
200
|
+
* @example
|
|
201
|
+
* <style>
|
|
202
|
+
* .fade-enter-active,
|
|
203
|
+
* .fade-leave-active {
|
|
204
|
+
* transition: opacity 0.5s ease;
|
|
205
|
+
* }
|
|
206
|
+
*
|
|
207
|
+
* .fade-enter-from,
|
|
208
|
+
* .fade-leave-to {
|
|
209
|
+
* opacity: 0;
|
|
210
|
+
* }
|
|
211
|
+
* </style>
|
|
212
|
+
* <button aria-expanded="true" aria-controls="target-hidden">Toggle Controlled Area</button>
|
|
213
|
+
* <div id="target-hidden" data-animate="fade">Controlled Target</div>
|
|
214
|
+
*/
|
|
215
|
+
function toggleControlTarget(selector, show, callback) {
|
|
216
|
+
const target = document.querySelector(selector);
|
|
217
|
+
if (!target) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
const animationName = target.getAttribute('data-animate');
|
|
221
|
+
const toggleHide = () => {
|
|
222
|
+
if (target.hasAttribute('aria-hidden')) {
|
|
223
|
+
target.setAttribute('aria-hidden', show ? 'false' : 'true');
|
|
224
|
+
}
|
|
225
|
+
else if (show) {
|
|
226
|
+
target.removeAttribute('hidden');
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
target.setAttribute('hidden', '');
|
|
230
|
+
}
|
|
231
|
+
callback();
|
|
232
|
+
};
|
|
233
|
+
if (show) {
|
|
234
|
+
// set tabindex=0 for all elements with tabindex=-1 that are not inside an aria-hidden element
|
|
235
|
+
target
|
|
236
|
+
.querySelectorAll(':scope > [tabindex="-1"], [tabindex="-1"]:not([aria-hidden="true"] [tabindex="-1"], [hidden] [tabindex="-1"])')
|
|
237
|
+
.forEach(el => {
|
|
238
|
+
el.setAttribute('tabindex', '0');
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
// set tabindex=-1 for all elements with tabindex=0
|
|
243
|
+
target.querySelectorAll('[tabindex="0"]').forEach(el => {
|
|
244
|
+
el.setAttribute('tabindex', '-1');
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
toggleInert(target, show);
|
|
248
|
+
if (animationName) {
|
|
249
|
+
if (show) {
|
|
250
|
+
toggleHide();
|
|
251
|
+
animate(target, animationName, show);
|
|
33
252
|
}
|
|
34
253
|
else {
|
|
35
|
-
|
|
254
|
+
animate(target, animationName, show, toggleHide);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
toggleHide();
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Initialize expandable/collapsable elements by using the [aria-expanded](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-expanded) attribute.
|
|
263
|
+
*
|
|
264
|
+
* When an element with the `aria-expanded` attribute is clicked, the value of the attribute will be toggled between `true` and `false`.
|
|
265
|
+
*
|
|
266
|
+
* @location functions.expand Expand
|
|
267
|
+
* @example
|
|
268
|
+
* <style>
|
|
269
|
+
* button::after {
|
|
270
|
+
* content: ' ' attr(aria-expanded);
|
|
271
|
+
* }
|
|
272
|
+
* </style>
|
|
273
|
+
* <button aria-expanded="false">Expanded:</button>
|
|
274
|
+
* @code
|
|
275
|
+
* <button aria-expanded="false">Expanded:</button>
|
|
276
|
+
*/
|
|
277
|
+
function initExpand() {
|
|
278
|
+
document.querySelectorAll('[aria-expanded]').forEach(expander => {
|
|
279
|
+
const controlTarget = expander.getAttribute('aria-controls');
|
|
280
|
+
const toggle = (e) => {
|
|
281
|
+
const expanded = expander.getAttribute('aria-expanded') === 'true';
|
|
282
|
+
const toggleExpanded = () => {
|
|
283
|
+
expander.setAttribute('aria-expanded', expanded ? 'false' : 'true'); // when expanded we need to set false
|
|
284
|
+
};
|
|
285
|
+
// if data-hide-same-level is set, we need to klick all other expanded elements to close them
|
|
286
|
+
if (expander.parentElement && expander.hasAttribute('data-hide-same-level')) {
|
|
287
|
+
Array.from(expander.parentElement.querySelectorAll(':scope > [aria-expanded="true"]'))
|
|
288
|
+
.filter(el => el !== expander && el !== e.relatedTarget)
|
|
289
|
+
.forEach(sibling => {
|
|
290
|
+
sibling.dispatchEvent(new MouseEvent('click', { bubbles: true, relatedTarget: expander }));
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
if (controlTarget) {
|
|
294
|
+
toggleControlTarget(`#${controlTarget}`, !expanded, toggleExpanded);
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
toggleExpanded();
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
expander.addEventListener('click', toggle);
|
|
301
|
+
if (controlTarget) {
|
|
302
|
+
// select all controls inside the controlled area that have the same aria-controls attribute
|
|
303
|
+
document
|
|
304
|
+
.querySelectorAll(`#${controlTarget} [aria-controls="${controlTarget}"]`)
|
|
305
|
+
.forEach(control => {
|
|
306
|
+
control.addEventListener('click', toggle);
|
|
307
|
+
});
|
|
36
308
|
}
|
|
37
309
|
});
|
|
38
310
|
}
|
|
@@ -75,6 +347,7 @@ function initSidebar() {
|
|
|
75
347
|
}
|
|
76
348
|
|
|
77
349
|
ready(() => {
|
|
350
|
+
initExpand();
|
|
78
351
|
initExample();
|
|
79
352
|
initSidebar();
|
|
80
353
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ui-doc.cjs","sources":["../../../scripts/src/base.ts","../../../scripts/src/example.ts","../../../scripts/src/sidebar.ts","../../../scripts/app.ts"],"sourcesContent":["export function ready(callback: () => void) {\n if (document.readyState !== 'loading') {\n callback()\n } else {\n document.addEventListener('DOMContentLoaded', callback)\n }\n}\n","export function initExample() {\n document.querySelectorAll<HTMLIFrameElement>('[data-example] > iframe').forEach(iframe => {\n const document = iframe.contentDocument ?? iframe.contentWindow?.document\n\n if (!document) {\n return\n }\n\n const action = () => {\n const changeHeight = () => {\n iframe.style.height = `${document.body.scrollHeight}px`\n }\n\n changeHeight()\n\n const observer = new MutationObserver(changeHeight)\n\n observer.observe(document.body, {\n attributes: true,\n childList: true,\n subtree: true,\n })\n }\n\n if (document.readyState === 'complete') {\n action()\n } else {\n iframe.addEventListener('load', action)\n }\n })\n}\n","function createSidebar(sidebar: HTMLElement) {\n const links: Record<string, HTMLLinkElement> = {}\n const observer = new IntersectionObserver(\n entries => {\n const activeEntries = entries.filter(entry => entry.isIntersecting)\n\n if (activeEntries.length <= 0) {\n return\n }\n\n Object.keys(links).forEach(id => {\n links[id].classList.remove('active')\n })\n\n const activeLink = links[activeEntries[0].target.id]\n\n activeLink.classList.add('active')\n if (activeLink?.parentElement?.parentElement?.parentElement instanceof HTMLLIElement) {\n activeLink.parentElement.parentElement.parentElement\n .querySelector('a')\n ?.classList.add('active')\n }\n },\n {\n root: null,\n rootMargin: '0px 0px -90% 0px',\n threshold: 0.5,\n },\n )\n\n sidebar.querySelectorAll<HTMLLinkElement>('a[href^=\"#\"]').forEach(link => {\n const id = link.href.split('#')[1]\n const target = document.getElementById(id)\n\n if (target) {\n observer.observe(target)\n links[id] = link\n }\n })\n}\n\nexport function initSidebar() {\n document.querySelectorAll('[data-sidebar]').forEach(sidebar => {\n createSidebar(sidebar as HTMLElement)\n })\n}\n","import { ready } from './src/base'\nimport { initExample } from './src/example'\nimport { initSidebar } from './src/sidebar'\n\nready(() => {\n initExample()\n initSidebar()\n})\n"],"names":[],"mappings":";;AAAM,SAAU,KAAK,CAAC,QAAoB,EAAA;AACxC,IAAA,IAAI,QAAQ,CAAC,UAAU,KAAK,SAAS,EAAE;AACrC,QAAA,QAAQ,EAAE,CAAA;KACX;SAAM;AACL,QAAA,QAAQ,CAAC,gBAAgB,CAAC,kBAAkB,EAAE,QAAQ,CAAC,CAAA;KACxD;AACH;;SCNgB,WAAW,GAAA;IACzB,QAAQ,CAAC,gBAAgB,CAAoB,yBAAyB,CAAC,CAAC,OAAO,CAAC,MAAM,IAAG;;AACvF,QAAA,MAAM,QAAQ,GAAG,CAAA,EAAA,GAAA,MAAM,CAAC,eAAe,MAAI,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,EAAA,GAAA,CAAA,EAAA,GAAA,MAAM,CAAC,aAAa,MAAA,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAE,QAAQ,CAAA;QAEzE,IAAI,CAAC,QAAQ,EAAE;YACb,OAAM;SACP;QAED,MAAM,MAAM,GAAG,MAAK;YAClB,MAAM,YAAY,GAAG,MAAK;AACxB,gBAAA,MAAM,CAAC,KAAK,CAAC,MAAM,GAAG,CAAA,EAAG,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAA,EAAA,CAAI,CAAA;AACzD,aAAC,CAAA;AAED,YAAA,YAAY,EAAE,C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file":"ui-doc.cjs","sources":["../../../scripts/services/example.ts","../../../scripts/utils/dom.ts","../../../scripts/utils/select.ts","../../../scripts/services/expand.ts","../../../scripts/services/sidebar.ts","../../../scripts/app.ts"],"sourcesContent":["export function initExample() {\n document.querySelectorAll<HTMLIFrameElement>('[data-example] > iframe').forEach(iframe => {\n const document = iframe.contentDocument ?? iframe.contentWindow?.document\n\n if (!document) {\n return\n }\n\n const initHeightChange = () => {\n let currentHeight = 0\n const changeHeight = () => {\n if (document.body.scrollHeight === currentHeight) {\n return\n }\n\n currentHeight = document.body.scrollHeight\n iframe.style.height = `${currentHeight}px`\n }\n\n // Initial height change\n changeHeight()\n\n // Use MutationObserver to detect changes in the DOM and change height if required\n const mutationObserver = new MutationObserver(changeHeight)\n\n mutationObserver.observe(document.body, {\n attributes: true,\n childList: true,\n subtree: true,\n })\n\n // Use ResizeObserver to detect changes in the viewport and change height if required\n const resizeObserver = new ResizeObserver(changeHeight)\n\n resizeObserver.observe(document.body)\n }\n\n if (document.readyState === 'complete') {\n initHeightChange()\n } else {\n iframe.addEventListener('load', initHeightChange)\n }\n })\n}\n","/**\n * Run function when dom is ready\n *\n * @param callback function to run when dom is ready\n */\nexport function ready(callback: (this: Document) => void): void {\n if (document.readyState !== 'loading') {\n callback.call(document)\n } else {\n document.addEventListener('DOMContentLoaded', callback)\n }\n}\n\n/**\n * Animate an element using css animations/transitions. This function will add the necessary classes to the element to trigger the animation.\n * When doing an entering animation following classes will be added:\n * - `[animation-name]-enter-active`\n * - `[animation-name]-enter-from`\n * - `[animation-name]-enter-to`\n * When doing a leaving animation following classes will be added:\n * - `[animation-name]-leave-active`\n * - `[animation-name]-leave-from`\n * - `[animation-name]-leave-to`\n *\n * 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.\n *\n * 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`\n * class will be added after the first frame.\n *\n * @param target html element to animate\n * @param animationName animation name to be used\n * @param entering determine if the elements animation should be entering or leaving\n * @param callback to be called after the animation is done\n */\nexport function animate(\n target: HTMLElement,\n animationName: string,\n entering: boolean,\n callback?: () => void,\n): void {\n const animationState = entering ? 'enter' : 'leave'\n const animateClassActive = `${animationName}-${animationState}-active`\n const animateClassTo = `${animationName}-${animationState}-to`\n const animateClassFrom = `${animationName}-${animationState}-from`\n const afterAnimation = () => {\n target.classList.remove(animateClassTo, animateClassActive)\n target.removeEventListener('animationend', afterAnimation)\n target.removeEventListener('transitionend', afterAnimation)\n\n if (callback) {\n callback()\n }\n }\n\n target.addEventListener('animationend', afterAnimation)\n target.addEventListener('transitionend', afterAnimation)\n\n target.addEventListener('animationcancel', afterAnimation)\n target.addEventListener('transitioncancel', afterAnimation)\n\n target.classList.add(animateClassActive, animateClassFrom)\n requestAnimationFrame(() => {\n const styles = window.getComputedStyle(target)\n\n // if the element has no transition or animation we can call the afterAnimation function in the next frame\n if (['all', 'none'].includes(styles.transition) && styles.animationName === 'none') {\n requestAnimationFrame(afterAnimation)\n }\n\n target.classList.remove(animateClassFrom)\n target.classList.add(animateClassTo)\n })\n}\n","/**\n * Query the first parent element that matches the selector\n *\n * @param element to search in\n * @param selector to be matched\n * @param maxDepth maximum depth to search\n * @returns element that matches the selector\n */\n\nexport function queryParentSelector<K extends keyof HTMLElementTagNameMap>(\n element: HTMLElement | null,\n selector: K,\n maxDepth?: number,\n): HTMLElementTagNameMap[K] | null\nexport function queryParentSelector<K extends keyof SVGElementTagNameMap>(\n element: HTMLElement | null,\n selector: K,\n maxDepth?: number,\n): SVGElementTagNameMap[K] | null\nexport function queryParentSelector<K extends keyof MathMLElementTagNameMap>(\n element: HTMLElement | null,\n selectors: K,\n maxDepth?: number,\n): MathMLElementTagNameMap[K] | null\nexport function queryParentSelector<E extends Element = Element>(\n element: HTMLElement | null,\n selector: string,\n maxDepth?: number,\n): E | null\nexport function queryParentSelector(\n element: HTMLElement | null,\n selector: string,\n maxDepth = 10,\n): Element | null {\n if (maxDepth <= 0 || element === null) {\n return null\n }\n\n if (element.matches(selector)) {\n return element as Element\n }\n\n return element.parentElement\n ? queryParentSelector(element.parentElement, selector, maxDepth - 1)\n : null\n}\n","import { animate } from '../utils/dom'\nimport { queryParentSelector } from '../utils/select'\n\n/**\n * 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.\n * You can set the `data-inert` attribute with selectors (comma separated) to control the `inert` attribute of elements matching your selectors.\n * @location functions.expand.with-inerts Expand controlling inert\n * @order 30\n * @example\n * <style>\n * button::after {\n * content: ' ' attr(aria-expanded);\n * }\n * </style>\n * <button aria-expanded=\"false\" aria-controls=\"target\">Expanded:</button>\n * <div id=\"target\" hidden data-inert=\"[data-inert-controlled],#inert-controlled-2\">Controlled Target</div>\n * <div data-inert-controlled=\"\"><button>Button 1.1</button><button>Button 1.2</button></div>\n * <div id=\"inert-controlled-2\"><button>Button 2.1</button><button>Button 2.2</button></div>\n * @code\n * <button aria-expanded=\"false\" aria-controls=\"target\">Expanded:</button>\n * <div id=\"target\" hidden data-inert=\"[data-inert-controlled],#inert-controlled-2\">Controlled Target</div>\n * <div data-inert-controlled=\"1\"><button>Button 1.1</button><button>Button 1.2</button></div>\n * <div id=\"inert-controlled-2\"><button>Button 2.1</button><button>Button 2.2</button></div>\n */\nfunction toggleInert(target: HTMLElement, show: boolean): void {\n const inertSelector = target.getAttribute('data-inert')\n\n if (!inertSelector) {\n return\n }\n\n inertSelector.split(',').forEach(selector => {\n // if the target is inside an element with the same selector, we don't want to remove the inert attribute\n const activeParentWithSameSelector = !show\n ? queryParentSelector(\n target.parentElement,\n `[data-inert=\"${selector}\"],[data-inert^=\"${selector},\"],[data-inert$=\",${selector}\"],[data-inert*=\",${selector},\"]`,\n )\n : null\n\n if (activeParentWithSameSelector) {\n return\n }\n\n document.querySelectorAll(selector).forEach(invertOn => {\n if (show) {\n invertOn.setAttribute('inert', '')\n } else {\n invertOn.removeAttribute('inert')\n }\n })\n })\n}\n\n/**\n * 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.\n *\n * 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.`\n *\n * @location functions.expand.with-controls Expand with controls\n * @order 10\n * @example\n * <style>\n * button::after {\n * content: ' ' attr(aria-expanded);\n * }\n * </style>\n * <button aria-expanded=\"true\" aria-controls=\"target-aria-hidden\">Expanded:</button>\n * <div id=\"target-aria-hidden\" aria-hidden=\"false\">Controlled Target</div>\n * <hr>\n * <button aria-expanded=\"true\" aria-controls=\"target-hidden\">Expanded:</button>\n * <div id=\"target-hidden\">Controlled Target</div>\n * @code\n * <button aria-expanded=\"true\" aria-controls=\"target-aria-hidden\">Expanded:</button>\n * <div id=\"target-aria-hidden\" aria-hidden=\"false\">Controlled Target</div>\n * <hr>\n * <button aria-expanded=\"true\" aria-controls=\"target-hidden\">Expanded:</button>\n * <div id=\"target-hidden\">Controlled Target</div>\n */\n\n/**\n * You can add animations/transitions on the controlled element by adding the `data-animate` attribute with the animation name.\n * The animation name will be used to add the necessary classes to the element to trigger the animation.\n * Please refer to the animate function for more information, what classes will be added and when.\n *\n * @location functions.expand.with-animation Expand with animation\n * @order 20\n * @example\n * <style>\n * .fade-enter-active,\n * .fade-leave-active {\n * transition: opacity 0.5s ease;\n * }\n *\n * .fade-enter-from,\n * .fade-leave-to {\n * opacity: 0;\n * }\n * </style>\n * <button aria-expanded=\"true\" aria-controls=\"target-hidden\">Toggle Controlled Area</button>\n * <div id=\"target-hidden\" data-animate=\"fade\">Controlled Target</div>\n */\nfunction toggleControlTarget(selector: string, show: boolean, callback: () => void): void {\n const target = document.querySelector<HTMLElement>(selector)\n\n if (!target) {\n return\n }\n\n const animationName = target.getAttribute('data-animate')\n const toggleHide = () => {\n if (target.hasAttribute('aria-hidden')) {\n target.setAttribute('aria-hidden', show ? 'false' : 'true')\n } else if (show) {\n target.removeAttribute('hidden')\n } else {\n target.setAttribute('hidden', '')\n }\n\n callback()\n }\n\n if (show) {\n // set tabindex=0 for all elements with tabindex=-1 that are not inside an aria-hidden element\n target\n .querySelectorAll<HTMLElement>(\n ':scope > [tabindex=\"-1\"], [tabindex=\"-1\"]:not([aria-hidden=\"true\"] [tabindex=\"-1\"], [hidden] [tabindex=\"-1\"])',\n )\n .forEach(el => {\n el.setAttribute('tabindex', '0')\n })\n } else {\n // set tabindex=-1 for all elements with tabindex=0\n target.querySelectorAll<HTMLElement>('[tabindex=\"0\"]').forEach(el => {\n el.setAttribute('tabindex', '-1')\n })\n }\n\n toggleInert(target, show)\n\n if (animationName) {\n if (show) {\n toggleHide()\n animate(target, animationName, show)\n } else {\n animate(target, animationName, show, toggleHide)\n }\n } else {\n toggleHide()\n }\n}\n\n/**\n * Initialize expandable/collapsable elements by using the [aria-expanded](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-expanded) attribute.\n *\n * When an element with the `aria-expanded` attribute is clicked, the value of the attribute will be toggled between `true` and `false`.\n *\n * @location functions.expand Expand\n * @example\n * <style>\n * button::after {\n * content: ' ' attr(aria-expanded);\n * }\n * </style>\n * <button aria-expanded=\"false\">Expanded:</button>\n * @code\n * <button aria-expanded=\"false\">Expanded:</button>\n */\nexport function initExpand(): void {\n document.querySelectorAll<HTMLElement>('[aria-expanded]').forEach(expander => {\n const controlTarget = expander.getAttribute('aria-controls')\n const toggle = (e: MouseEvent) => {\n const expanded = expander.getAttribute('aria-expanded') === 'true'\n const toggleExpanded = () => {\n expander.setAttribute('aria-expanded', expanded ? 'false' : 'true') // when expanded we need to set false\n }\n\n // if data-hide-same-level is set, we need to klick all other expanded elements to close them\n if (expander.parentElement && expander.hasAttribute('data-hide-same-level')) {\n Array.from(expander.parentElement.querySelectorAll(':scope > [aria-expanded=\"true\"]'))\n .filter(el => el !== expander && el !== e.relatedTarget)\n .forEach(sibling => {\n sibling.dispatchEvent(\n new MouseEvent('click', { bubbles: true, relatedTarget: expander }),\n )\n })\n }\n\n if (controlTarget) {\n toggleControlTarget(`#${controlTarget}`, !expanded, toggleExpanded)\n } else {\n toggleExpanded()\n }\n }\n\n expander.addEventListener('click', toggle)\n\n if (controlTarget) {\n // select all controls inside the controlled area that have the same aria-controls attribute\n document\n .querySelectorAll<HTMLElement>(`#${controlTarget} [aria-controls=\"${controlTarget}\"]`)\n .forEach(control => {\n control.addEventListener('click', toggle)\n })\n }\n })\n}\n","function createSidebar(sidebar: HTMLElement) {\n const links: Record<string, HTMLLinkElement> = {}\n const observer = new IntersectionObserver(\n entries => {\n const activeEntries = entries.filter(entry => entry.isIntersecting)\n\n if (activeEntries.length <= 0) {\n return\n }\n\n Object.keys(links).forEach(id => {\n links[id].classList.remove('active')\n })\n\n const activeLink = links[activeEntries[0].target.id]\n\n activeLink.classList.add('active')\n if (activeLink?.parentElement?.parentElement?.parentElement instanceof HTMLLIElement) {\n activeLink.parentElement.parentElement.parentElement\n .querySelector('a')\n ?.classList.add('active')\n }\n },\n {\n root: null,\n rootMargin: '0px 0px -90% 0px',\n threshold: 0.5,\n },\n )\n\n sidebar.querySelectorAll<HTMLLinkElement>('a[href^=\"#\"]').forEach(link => {\n const id = link.href.split('#')[1]\n const target = document.getElementById(id)\n\n if (target) {\n observer.observe(target)\n links[id] = link\n }\n })\n}\n\nexport function initSidebar() {\n document.querySelectorAll('[data-sidebar]').forEach(sidebar => {\n createSidebar(sidebar as HTMLElement)\n })\n}\n","import { initExample } from './services/example'\nimport { initExpand } from './services/expand'\nimport { initSidebar } from './services/sidebar'\nimport { ready } from './utils/dom'\n\nready(() => {\n initExpand()\n initExample()\n initSidebar()\n})\n"],"names":[],"mappings":";;SAAgB,WAAW,G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