@cedx/ui 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.md +20 -0
- package/ReadMe.md +17 -0
- package/lib/Alignment.d.ts +22 -0
- package/lib/Alignment.d.ts.map +1 -0
- package/lib/Alignment.js +17 -0
- package/lib/AppTheme.d.ts +34 -0
- package/lib/AppTheme.d.ts.map +1 -0
- package/lib/AppTheme.js +41 -0
- package/lib/Components/BackButton.d.ts +27 -0
- package/lib/Components/BackButton.d.ts.map +1 -0
- package/lib/Components/BackButton.js +29 -0
- package/lib/Components/DialogBox.d.ts +151 -0
- package/lib/Components/DialogBox.d.ts.map +1 -0
- package/lib/Components/DialogBox.js +268 -0
- package/lib/Components/FullScreenToggler.d.ts +42 -0
- package/lib/Components/FullScreenToggler.d.ts.map +1 -0
- package/lib/Components/FullScreenToggler.js +103 -0
- package/lib/Components/KeyboardAccelerator.d.ts +36 -0
- package/lib/Components/KeyboardAccelerator.d.ts.map +1 -0
- package/lib/Components/KeyboardAccelerator.js +78 -0
- package/lib/Components/LoadingIndicator.d.ts +58 -0
- package/lib/Components/LoadingIndicator.d.ts.map +1 -0
- package/lib/Components/LoadingIndicator.js +93 -0
- package/lib/Components/MenuActivator.d.ts +26 -0
- package/lib/Components/MenuActivator.d.ts.map +1 -0
- package/lib/Components/MenuActivator.js +42 -0
- package/lib/Components/OfflineIndicator.d.ts +59 -0
- package/lib/Components/OfflineIndicator.d.ts.map +1 -0
- package/lib/Components/OfflineIndicator.js +106 -0
- package/lib/Components/TabActivator.d.ts +49 -0
- package/lib/Components/TabActivator.d.ts.map +1 -0
- package/lib/Components/TabActivator.js +70 -0
- package/lib/Components/ThemeDropdown.d.ts +86 -0
- package/lib/Components/ThemeDropdown.d.ts.map +1 -0
- package/lib/Components/ThemeDropdown.js +207 -0
- package/lib/Components/Toast.d.ts +94 -0
- package/lib/Components/Toast.d.ts.map +1 -0
- package/lib/Components/Toast.js +284 -0
- package/lib/Components/Toaster.d.ts +119 -0
- package/lib/Components/Toaster.d.ts.map +1 -0
- package/lib/Components/Toaster.js +153 -0
- package/lib/Components/TypeAhead.d.ts +53 -0
- package/lib/Components/TypeAhead.d.ts.map +1 -0
- package/lib/Components/TypeAhead.js +138 -0
- package/lib/Context.d.ts +38 -0
- package/lib/Context.d.ts.map +1 -0
- package/lib/Context.js +42 -0
- package/lib/DialogResult.d.ts +30 -0
- package/lib/DialogResult.d.ts.map +1 -0
- package/lib/DialogResult.js +29 -0
- package/lib/File.d.ts +25 -0
- package/lib/File.d.ts.map +1 -0
- package/lib/File.js +66 -0
- package/lib/Form.d.ts +33 -0
- package/lib/Form.d.ts.map +1 -0
- package/lib/Form.js +50 -0
- package/lib/Htmx.d.ts +12 -0
- package/lib/Htmx.d.ts.map +1 -0
- package/lib/Htmx.js +2 -0
- package/lib/KeyboardModifiers.d.ts +26 -0
- package/lib/KeyboardModifiers.d.ts.map +1 -0
- package/lib/KeyboardModifiers.js +25 -0
- package/lib/Position.d.ts +52 -0
- package/lib/Position.d.ts.map +1 -0
- package/lib/Position.js +59 -0
- package/lib/Size.d.ts +40 -0
- package/lib/Size.d.ts.map +1 -0
- package/lib/Size.js +44 -0
- package/lib/StorageArea.d.ts +18 -0
- package/lib/StorageArea.d.ts.map +1 -0
- package/lib/StorageArea.js +13 -0
- package/lib/Tags.d.ts +15 -0
- package/lib/Tags.d.ts.map +1 -0
- package/lib/Tags.js +48 -0
- package/lib/Variant.d.ts +36 -0
- package/lib/Variant.d.ts.map +1 -0
- package/lib/Variant.js +31 -0
- package/lib/ViewportScroller.d.ts +49 -0
- package/lib/ViewportScroller.d.ts.map +1 -0
- package/lib/ViewportScroller.js +69 -0
- package/package.json +58 -0
- package/src/Client/Alignment.ts +25 -0
- package/src/Client/AppTheme.ts +51 -0
- package/src/Client/Components/BackButton.ts +45 -0
- package/src/Client/Components/DialogBox.ts +344 -0
- package/src/Client/Components/FullScreenToggler.ts +122 -0
- package/src/Client/Components/KeyboardAccelerator.ts +97 -0
- package/src/Client/Components/LoadingIndicator.ts +113 -0
- package/src/Client/Components/MenuActivator.ts +58 -0
- package/src/Client/Components/OfflineIndicator.ts +125 -0
- package/src/Client/Components/TabActivator.ts +93 -0
- package/src/Client/Components/ThemeDropdown.ts +235 -0
- package/src/Client/Components/Toast.ts +319 -0
- package/src/Client/Components/Toaster.ts +224 -0
- package/src/Client/Components/TypeAhead.ts +153 -0
- package/src/Client/Context.ts +53 -0
- package/src/Client/DialogResult.ts +35 -0
- package/src/Client/File.ts +73 -0
- package/src/Client/Form.ts +55 -0
- package/src/Client/Htmx.ts +13 -0
- package/src/Client/KeyboardModifiers.ts +30 -0
- package/src/Client/Position.ts +74 -0
- package/src/Client/Size.ts +56 -0
- package/src/Client/StorageArea.ts +20 -0
- package/src/Client/Tags.ts +58 -0
- package/src/Client/Variant.ts +42 -0
- package/src/Client/ViewportScroller.ts +89 -0
- package/src/Client/tsconfig.json +19 -0
package/lib/Size.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defines the size of an element.
|
|
3
|
+
*/
|
|
4
|
+
export declare const Size: Readonly<{
|
|
5
|
+
/**
|
|
6
|
+
* An extra small size.
|
|
7
|
+
*/
|
|
8
|
+
ExtraSmall: "ExtraSmall";
|
|
9
|
+
/**
|
|
10
|
+
* A small size.
|
|
11
|
+
*/
|
|
12
|
+
Small: "Small";
|
|
13
|
+
/**
|
|
14
|
+
* A medium size.
|
|
15
|
+
*/
|
|
16
|
+
Medium: "Medium";
|
|
17
|
+
/**
|
|
18
|
+
* A large size.
|
|
19
|
+
*/
|
|
20
|
+
Large: "Large";
|
|
21
|
+
/**
|
|
22
|
+
* An extra large size.
|
|
23
|
+
*/
|
|
24
|
+
ExtraLarge: "ExtraLarge";
|
|
25
|
+
/**
|
|
26
|
+
* An extra extra large size.
|
|
27
|
+
*/
|
|
28
|
+
ExtraExtraLarge: "ExtraExtraLarge";
|
|
29
|
+
}>;
|
|
30
|
+
/**
|
|
31
|
+
* Defines the size of an element.
|
|
32
|
+
*/
|
|
33
|
+
export type Size = typeof Size[keyof typeof Size];
|
|
34
|
+
/**
|
|
35
|
+
* Returns the CSS class of the specified size.
|
|
36
|
+
* @param size The size.
|
|
37
|
+
* @returns The CSS class of the specified size.
|
|
38
|
+
*/
|
|
39
|
+
export declare function cssClass(size: Size): string;
|
|
40
|
+
//# sourceMappingURL=Size.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Size.d.ts","sourceRoot":"","sources":["../src/Client/Size.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,IAAI;IAEhB;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;EAEF,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,IAAI,GAAG,OAAO,IAAI,CAAC,MAAM,OAAO,IAAI,CAAC,CAAC;AAElD;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAS3C"}
|
package/lib/Size.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defines the size of an element.
|
|
3
|
+
*/
|
|
4
|
+
export const Size = Object.freeze({
|
|
5
|
+
/**
|
|
6
|
+
* An extra small size.
|
|
7
|
+
*/
|
|
8
|
+
ExtraSmall: "ExtraSmall",
|
|
9
|
+
/**
|
|
10
|
+
* A small size.
|
|
11
|
+
*/
|
|
12
|
+
Small: "Small",
|
|
13
|
+
/**
|
|
14
|
+
* A medium size.
|
|
15
|
+
*/
|
|
16
|
+
Medium: "Medium",
|
|
17
|
+
/**
|
|
18
|
+
* A large size.
|
|
19
|
+
*/
|
|
20
|
+
Large: "Large",
|
|
21
|
+
/**
|
|
22
|
+
* An extra large size.
|
|
23
|
+
*/
|
|
24
|
+
ExtraLarge: "ExtraLarge",
|
|
25
|
+
/**
|
|
26
|
+
* An extra extra large size.
|
|
27
|
+
*/
|
|
28
|
+
ExtraExtraLarge: "ExtraExtraLarge"
|
|
29
|
+
});
|
|
30
|
+
/**
|
|
31
|
+
* Returns the CSS class of the specified size.
|
|
32
|
+
* @param size The size.
|
|
33
|
+
* @returns The CSS class of the specified size.
|
|
34
|
+
*/
|
|
35
|
+
export function cssClass(size) {
|
|
36
|
+
switch (size) {
|
|
37
|
+
case Size.ExtraSmall: return "xs";
|
|
38
|
+
case Size.Small: return "sm";
|
|
39
|
+
case Size.Large: return "lg";
|
|
40
|
+
case Size.ExtraLarge: return "xl";
|
|
41
|
+
case Size.ExtraExtraLarge: return "xxl";
|
|
42
|
+
default: return "md";
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Identifies the web storage area.
|
|
3
|
+
*/
|
|
4
|
+
export declare const StorageArea: Readonly<{
|
|
5
|
+
/**
|
|
6
|
+
* Indicates the local storage.
|
|
7
|
+
*/
|
|
8
|
+
Local: "Local";
|
|
9
|
+
/**
|
|
10
|
+
* Indicates the session storage.
|
|
11
|
+
*/
|
|
12
|
+
Session: "Session";
|
|
13
|
+
}>;
|
|
14
|
+
/**
|
|
15
|
+
* Identifies the web storage area.
|
|
16
|
+
*/
|
|
17
|
+
export type StorageArea = typeof StorageArea[keyof typeof StorageArea];
|
|
18
|
+
//# sourceMappingURL=StorageArea.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StorageArea.d.ts","sourceRoot":"","sources":["../src/Client/StorageArea.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,WAAW;IAEvB;;OAEG;;IAGH;;OAEG;;EAEF,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,OAAO,WAAW,CAAC,MAAM,OAAO,WAAW,CAAC,CAAC"}
|
package/lib/Tags.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a CSS stylesheet from the specified template literal.
|
|
3
|
+
* @param fragments The string fragments.
|
|
4
|
+
* @param values The interpolated values.
|
|
5
|
+
* @returns The CSS stylesheet corresponding to the specified template literal.
|
|
6
|
+
*/
|
|
7
|
+
export declare function css(fragments: TemplateStringsArray, ...values: unknown[]): CSSStyleSheet;
|
|
8
|
+
/**
|
|
9
|
+
* Creates a document fragment from the specified template literal.
|
|
10
|
+
* @param fragments The string fragments.
|
|
11
|
+
* @param values The interpolated values.
|
|
12
|
+
* @returns The document fragment corresponding to the specified template literal.
|
|
13
|
+
*/
|
|
14
|
+
export declare function html(fragments: TemplateStringsArray, ...values: unknown[]): DocumentFragment;
|
|
15
|
+
//# sourceMappingURL=Tags.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Tags.d.ts","sourceRoot":"","sources":["../src/Client/Tags.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,GAAG,CAAC,SAAS,EAAE,oBAAoB,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,aAAa,CAQxF;AAED;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,SAAS,EAAE,oBAAoB,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,gBAAgB,CAK5F"}
|
package/lib/Tags.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a CSS stylesheet from the specified template literal.
|
|
3
|
+
* @param fragments The string fragments.
|
|
4
|
+
* @param values The interpolated values.
|
|
5
|
+
* @returns The CSS stylesheet corresponding to the specified template literal.
|
|
6
|
+
*/
|
|
7
|
+
export function css(fragments, ...values) {
|
|
8
|
+
const styleSheet = new CSSStyleSheet;
|
|
9
|
+
styleSheet.replaceSync(fragments.length == 1 ? fragments[0] : values.reduce((fragment, value, index) => fragment + stringFromCss(value) + fragments[index + 1], fragments[0]));
|
|
10
|
+
return styleSheet;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Creates a document fragment from the specified template literal.
|
|
14
|
+
* @param fragments The string fragments.
|
|
15
|
+
* @param values The interpolated values.
|
|
16
|
+
* @returns The document fragment corresponding to the specified template literal.
|
|
17
|
+
*/
|
|
18
|
+
export function html(fragments, ...values) {
|
|
19
|
+
return document.createRange().createContextualFragment(fragments.length == 1 ? fragments[0] : values.reduce((fragment, value, index) => fragment + stringFromHtml(value) + fragments[index + 1], fragments[0]));
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Converts the specified value to a CSS string.
|
|
23
|
+
* @param value A value representing a CSS fragment.
|
|
24
|
+
* @returns The CSS string corresponding to the specified value.
|
|
25
|
+
*/
|
|
26
|
+
function stringFromCss(value) {
|
|
27
|
+
if (!(value instanceof CSSStyleSheet)) {
|
|
28
|
+
if (Array.isArray(value))
|
|
29
|
+
return value.map(stringFromCss).join("\n");
|
|
30
|
+
return value === null || typeof value == "undefined" ? "" : String(value); // eslint-disable-line @typescript-eslint/no-base-to-string
|
|
31
|
+
}
|
|
32
|
+
return Array.from(value.cssRules).map(cssRule => cssRule.cssText).join("\n");
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Converts the specified value to an HTML string.
|
|
36
|
+
* @param value A value representing an HTML fragment.
|
|
37
|
+
* @returns The HTML string corresponding to the specified value.
|
|
38
|
+
*/
|
|
39
|
+
function stringFromHtml(value) {
|
|
40
|
+
if (!(value instanceof DocumentFragment)) {
|
|
41
|
+
if (Array.isArray(value))
|
|
42
|
+
return value.map(stringFromHtml).join("");
|
|
43
|
+
return value === null || typeof value == "undefined" ? "" : String(value); // eslint-disable-line @typescript-eslint/no-base-to-string
|
|
44
|
+
}
|
|
45
|
+
const element = document.createElement("div");
|
|
46
|
+
element.appendChild(value);
|
|
47
|
+
return element.innerHTML;
|
|
48
|
+
}
|
package/lib/Variant.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defines tone variants.
|
|
3
|
+
*/
|
|
4
|
+
export declare const Variant: Readonly<{
|
|
5
|
+
/**
|
|
6
|
+
* A primary tone.
|
|
7
|
+
*/
|
|
8
|
+
Primary: "Primary";
|
|
9
|
+
/**
|
|
10
|
+
* A secondary tone.
|
|
11
|
+
*/
|
|
12
|
+
Secondary: "Secondary";
|
|
13
|
+
/**
|
|
14
|
+
* A light tone.
|
|
15
|
+
*/
|
|
16
|
+
Light: "Light";
|
|
17
|
+
/**
|
|
18
|
+
* A dark tone.
|
|
19
|
+
*/
|
|
20
|
+
Dark: "Dark";
|
|
21
|
+
Danger: "Danger";
|
|
22
|
+
Warning: "Warning";
|
|
23
|
+
Info: "Info";
|
|
24
|
+
Success: "Success";
|
|
25
|
+
}>;
|
|
26
|
+
/**
|
|
27
|
+
* Defines tone variants.
|
|
28
|
+
*/
|
|
29
|
+
export type Variant = typeof Variant[keyof typeof Variant];
|
|
30
|
+
/**
|
|
31
|
+
* Returns the CSS class of the specified variant.
|
|
32
|
+
* @param variant The variant.
|
|
33
|
+
* @returns The CSS class of the specified variant.
|
|
34
|
+
*/
|
|
35
|
+
export declare function cssClass(variant: Variant): string;
|
|
36
|
+
//# sourceMappingURL=Variant.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Variant.d.ts","sourceRoot":"","sources":["../src/Client/Variant.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,OAAO;IAGnB;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;;;;;EAEF,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG,OAAO,OAAO,CAAC,MAAM,OAAO,OAAO,CAAC,CAAC;AAE3D;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAEjD"}
|
package/lib/Variant.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Context } from "./Context.js";
|
|
2
|
+
/**
|
|
3
|
+
* Defines tone variants.
|
|
4
|
+
*/
|
|
5
|
+
export const Variant = Object.freeze({
|
|
6
|
+
...Context,
|
|
7
|
+
/**
|
|
8
|
+
* A primary tone.
|
|
9
|
+
*/
|
|
10
|
+
Primary: "Primary",
|
|
11
|
+
/**
|
|
12
|
+
* A secondary tone.
|
|
13
|
+
*/
|
|
14
|
+
Secondary: "Secondary",
|
|
15
|
+
/**
|
|
16
|
+
* A light tone.
|
|
17
|
+
*/
|
|
18
|
+
Light: "Light",
|
|
19
|
+
/**
|
|
20
|
+
* A dark tone.
|
|
21
|
+
*/
|
|
22
|
+
Dark: "Dark"
|
|
23
|
+
});
|
|
24
|
+
/**
|
|
25
|
+
* Returns the CSS class of the specified variant.
|
|
26
|
+
* @param variant The variant.
|
|
27
|
+
* @returns The CSS class of the specified variant.
|
|
28
|
+
*/
|
|
29
|
+
export function cssClass(variant) {
|
|
30
|
+
return variant.toLowerCase();
|
|
31
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defines the scrolling options.
|
|
3
|
+
*/
|
|
4
|
+
export type ScrollOptions = Partial<{
|
|
5
|
+
/**
|
|
6
|
+
* Value indicating whether scrolling is instant or animates smoothly.
|
|
7
|
+
*/
|
|
8
|
+
behavior: ScrollBehavior;
|
|
9
|
+
}>;
|
|
10
|
+
/**
|
|
11
|
+
* Manages the scroll position.
|
|
12
|
+
*/
|
|
13
|
+
export declare class ViewportScroller {
|
|
14
|
+
#private;
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new viewport scroller.
|
|
17
|
+
* @param viewport A function that returns the element used as viewport.
|
|
18
|
+
*/
|
|
19
|
+
constructor(viewport?: () => Element);
|
|
20
|
+
/**
|
|
21
|
+
* The top offset used when scrolling to an element.
|
|
22
|
+
*/
|
|
23
|
+
get scrollOffset(): number;
|
|
24
|
+
/**
|
|
25
|
+
* Scrolls to the specified anchor.
|
|
26
|
+
* @param anchor The identifier or name of an element.
|
|
27
|
+
* @param options Value indicating whether scrolling is instant or animates smoothly.
|
|
28
|
+
*/
|
|
29
|
+
scrollToAnchor(anchor: string, options?: ScrollOptions): void;
|
|
30
|
+
/**
|
|
31
|
+
* Scrolls to the specified element.
|
|
32
|
+
* @param element The element to scroll to.
|
|
33
|
+
* @param options Value indicating whether scrolling is instant or animates smoothly.
|
|
34
|
+
*/
|
|
35
|
+
scrollToElement(element: Element, options?: ScrollOptions): void;
|
|
36
|
+
/**
|
|
37
|
+
* Scrolls to the specified position.
|
|
38
|
+
* @param x The pixel along the horizontal axis.
|
|
39
|
+
* @param y The pixel along the vertical axis.
|
|
40
|
+
* @param options Value indicating whether scrolling is instant or animates smoothly.
|
|
41
|
+
*/
|
|
42
|
+
scrollToPosition(x: number, y: number, options?: ScrollOptions): void;
|
|
43
|
+
/**
|
|
44
|
+
* Scrolls to the top.
|
|
45
|
+
* @param options Value indicating whether scrolling is instant or animates smoothly.
|
|
46
|
+
*/
|
|
47
|
+
scrollToTop(options?: ScrollOptions): void;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=ViewportScroller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ViewportScroller.d.ts","sourceRoot":"","sources":["../src/Client/ViewportScroller.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,OAAO,CAAC;IAEnC;;OAEG;IACH,QAAQ,EAAE,cAAc,CAAA;CACxB,CAAC,CAAC;AAEH;;GAEG;AACH,qBAAa,gBAAgB;;IAY5B;;;OAGG;gBACS,QAAQ,GAAE,MAAM,OAAqE;IAIjG;;OAEG;IACH,IAAI,YAAY,IAAI,MAAM,CAWzB;IAED;;;;OAIG;IACH,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,IAAI;IAKjE;;;;OAIG;IACH,eAAe,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,GAAE,aAAkB,GAAG,IAAI;IAMpE;;;;;OAKG;IACH,gBAAgB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,IAAI;IAIzE;;;OAGG;IACH,WAAW,CAAC,OAAO,GAAE,aAAkB,GAAG,IAAI;CAG9C"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manages the scroll position.
|
|
3
|
+
*/
|
|
4
|
+
export class ViewportScroller {
|
|
5
|
+
/**
|
|
6
|
+
* The top offset used when scrolling to an element.
|
|
7
|
+
*/
|
|
8
|
+
#scrollOffset = -1;
|
|
9
|
+
/**
|
|
10
|
+
* The function returning the element used as viewport.
|
|
11
|
+
*/
|
|
12
|
+
#viewport;
|
|
13
|
+
/**
|
|
14
|
+
* Creates a new viewport scroller.
|
|
15
|
+
* @param viewport A function that returns the element used as viewport.
|
|
16
|
+
*/
|
|
17
|
+
constructor(viewport = () => document.scrollingElement ?? document.documentElement) {
|
|
18
|
+
this.#viewport = viewport;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The top offset used when scrolling to an element.
|
|
22
|
+
*/
|
|
23
|
+
get scrollOffset() {
|
|
24
|
+
if (this.#scrollOffset < 0) {
|
|
25
|
+
const fontSize = Number.parseInt(getComputedStyle(document.body).fontSize, 10);
|
|
26
|
+
this.#scrollOffset = Number.isNaN(fontSize) ? 0 : fontSize * 2;
|
|
27
|
+
const navbar = document.body.querySelector(".navbar");
|
|
28
|
+
this.#scrollOffset += (navbar?.offsetHeight ?? 0);
|
|
29
|
+
}
|
|
30
|
+
const actionBar = document.body.querySelector("action-bar");
|
|
31
|
+
return this.#scrollOffset + (actionBar?.offsetHeight ?? 0);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Scrolls to the specified anchor.
|
|
35
|
+
* @param anchor The identifier or name of an element.
|
|
36
|
+
* @param options Value indicating whether scrolling is instant or animates smoothly.
|
|
37
|
+
*/
|
|
38
|
+
scrollToAnchor(anchor, options = {}) {
|
|
39
|
+
const element = document.getElementById(anchor) ?? this.#viewport().querySelector(`[name="${anchor}"]`);
|
|
40
|
+
if (element)
|
|
41
|
+
this.scrollToElement(element, options);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Scrolls to the specified element.
|
|
45
|
+
* @param element The element to scroll to.
|
|
46
|
+
* @param options Value indicating whether scrolling is instant or animates smoothly.
|
|
47
|
+
*/
|
|
48
|
+
scrollToElement(element, options = {}) {
|
|
49
|
+
const { left, top } = element.getBoundingClientRect();
|
|
50
|
+
const { scrollLeft, scrollTop } = this.#viewport();
|
|
51
|
+
this.scrollToPosition(left + scrollLeft, top + scrollTop - this.scrollOffset, options);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Scrolls to the specified position.
|
|
55
|
+
* @param x The pixel along the horizontal axis.
|
|
56
|
+
* @param y The pixel along the vertical axis.
|
|
57
|
+
* @param options Value indicating whether scrolling is instant or animates smoothly.
|
|
58
|
+
*/
|
|
59
|
+
scrollToPosition(x, y, options = {}) {
|
|
60
|
+
this.#viewport().scrollTo({ left: x, top: y, behavior: options.behavior ?? "auto" });
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Scrolls to the top.
|
|
64
|
+
* @param options Value indicating whether scrolling is instant or animates smoothly.
|
|
65
|
+
*/
|
|
66
|
+
scrollToTop(options = {}) {
|
|
67
|
+
this.scrollToPosition(0, 0, options);
|
|
68
|
+
}
|
|
69
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"author": "Cédric Belin <cedx@outlook.com>",
|
|
3
|
+
"bugs": "https://github.com/cedx/ui/issues",
|
|
4
|
+
"description": "Component library by Cédric Belin, full stack developer.",
|
|
5
|
+
"homepage": "https://github.com/cedx/ui",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"name": "@cedx/ui",
|
|
8
|
+
"repository": "cedx/ui",
|
|
9
|
+
"type": "module",
|
|
10
|
+
"version": "0.1.0",
|
|
11
|
+
"devDependencies": {
|
|
12
|
+
"@eslint/js": "^10.0.1",
|
|
13
|
+
"@types/bootstrap": "^5.2.10",
|
|
14
|
+
"@types/chai": "^5.2.3",
|
|
15
|
+
"@types/mocha": "^10.0.10",
|
|
16
|
+
"@types/node": "^25.6.0",
|
|
17
|
+
"@types/serve-handler": "^6.1.4",
|
|
18
|
+
"bootstrap": "^5.3.8",
|
|
19
|
+
"chai": "^6.2.2",
|
|
20
|
+
"esbuild": "^0.28.0",
|
|
21
|
+
"globals": "^17.4.0",
|
|
22
|
+
"htmx.org": "^2.0.8",
|
|
23
|
+
"mocha": "^11.7.5",
|
|
24
|
+
"playwright": "^1.59.1",
|
|
25
|
+
"playwright-chromium": "^1.59.1",
|
|
26
|
+
"serve-handler": "^6.1.7",
|
|
27
|
+
"typescript": "^6.0.2",
|
|
28
|
+
"typescript-eslint": "^8.58.1"
|
|
29
|
+
},
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=24.0.0"
|
|
32
|
+
},
|
|
33
|
+
"exports": {
|
|
34
|
+
"./*.js": {
|
|
35
|
+
"types": "./lib/*.d.ts",
|
|
36
|
+
"default": "./lib/*.js"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"files": [
|
|
40
|
+
"lib/",
|
|
41
|
+
"src/Client/"
|
|
42
|
+
],
|
|
43
|
+
"keywords": [
|
|
44
|
+
"belin",
|
|
45
|
+
"blazor",
|
|
46
|
+
"components",
|
|
47
|
+
"html",
|
|
48
|
+
"library",
|
|
49
|
+
"ui"
|
|
50
|
+
],
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"bootstrap": ">=5.3.0",
|
|
53
|
+
"htmx.org": ">=2.0.0"
|
|
54
|
+
},
|
|
55
|
+
"publishConfig": {
|
|
56
|
+
"access": "public"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defines the alignment of a component.
|
|
3
|
+
*/
|
|
4
|
+
export const Alignment = Object.freeze({
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The element is aligned at the start.
|
|
8
|
+
*/
|
|
9
|
+
Start: "Start",
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The element is aligned in the center.
|
|
13
|
+
*/
|
|
14
|
+
Center: "Center",
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The element is aligned at the end.
|
|
18
|
+
*/
|
|
19
|
+
End: "End"
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Defines the alignment of a component.
|
|
24
|
+
*/
|
|
25
|
+
export type Alignment = typeof Alignment[keyof typeof Alignment];
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enumerates different themes an operating system or application can show.
|
|
3
|
+
*/
|
|
4
|
+
export const AppTheme = Object.freeze({
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The system theme.
|
|
8
|
+
*/
|
|
9
|
+
System: "System",
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The light theme.
|
|
13
|
+
*/
|
|
14
|
+
Light: "Light",
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The dark theme.
|
|
18
|
+
*/
|
|
19
|
+
Dark: "Dark"
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Enumerates different themes an operating system or application can show.
|
|
24
|
+
*/
|
|
25
|
+
export type AppTheme = typeof AppTheme[keyof typeof AppTheme];
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Gets the icon corresponding to the specified theme.
|
|
29
|
+
* @param theme The application theme.
|
|
30
|
+
* @returns The icon corresponding to the specified theme.
|
|
31
|
+
*/
|
|
32
|
+
export function icon(theme: AppTheme): string {
|
|
33
|
+
switch (theme) {
|
|
34
|
+
case AppTheme.Dark: return "dark_mode";
|
|
35
|
+
case AppTheme.Light: return "light_mode";
|
|
36
|
+
default: return "contrast";
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Gets the label corresponding to the specified theme.
|
|
42
|
+
* @param theme The application theme.
|
|
43
|
+
* @returns The label corresponding to the specified theme.
|
|
44
|
+
*/
|
|
45
|
+
export function label(theme: AppTheme): string {
|
|
46
|
+
switch (theme) {
|
|
47
|
+
case AppTheme.Dark: return "Sombre";
|
|
48
|
+
case AppTheme.Light: return "Clair";
|
|
49
|
+
default: return "Auto";
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A component that moves back in the session history when clicked.
|
|
3
|
+
*/
|
|
4
|
+
export class BackButton extends HTMLElement {
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Registers the component.
|
|
8
|
+
*/
|
|
9
|
+
static {
|
|
10
|
+
customElements.define("back-button", this);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The number of pages to go back.
|
|
15
|
+
*/
|
|
16
|
+
get steps(): number {
|
|
17
|
+
const value = Number(this.getAttribute("steps"));
|
|
18
|
+
return Math.max(0, Number.isNaN(value) ? 1 : value);
|
|
19
|
+
}
|
|
20
|
+
set steps(value: number) {
|
|
21
|
+
this.setAttribute("steps", value.toString());
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Moves back in the session history.
|
|
26
|
+
* @param event The dispatched event.
|
|
27
|
+
*/
|
|
28
|
+
goBack(event?: Event): void {
|
|
29
|
+
event?.preventDefault();
|
|
30
|
+
history.go(-this.steps);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Declaration merging.
|
|
36
|
+
*/
|
|
37
|
+
declare global {
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The map of HTML tag names.
|
|
41
|
+
*/
|
|
42
|
+
interface HTMLElementTagNameMap {
|
|
43
|
+
"back-button": BackButton;
|
|
44
|
+
}
|
|
45
|
+
}
|