lutra 0.0.20 → 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/README.md +4 -24
- package/dist/components/AspectRatio.svelte +26 -0
- package/dist/components/AspectRatio.svelte.d.ts +8 -0
- package/dist/components/Dialog.svelte +78 -0
- package/dist/components/Dialog.svelte.d.ts +14 -0
- package/dist/components/Layout.svelte +32 -0
- package/dist/components/Layout.svelte.d.ts +11 -0
- package/dist/components/PageContent.svelte +108 -0
- package/dist/components/PageContent.svelte.d.ts +38 -0
- package/dist/components/Theme.svelte +87 -0
- package/dist/components/Theme.svelte.d.ts +17 -0
- package/dist/{display → components}/Tooltip.svelte +37 -11
- package/dist/components/Tooltip.svelte.d.ts +12 -0
- package/dist/config.d.ts +30 -0
- package/dist/config.js +18 -0
- package/dist/css/0-layers.css +1 -0
- package/dist/css/1-props.css +775 -0
- package/dist/css/2-base.css +209 -0
- package/dist/css/3-typo.css +65 -0
- package/dist/css/4-layout.css +5 -0
- package/dist/css/5-media.css +21 -0
- package/dist/css/lutra.css +6 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.js +5 -2
- package/dist/types.d.ts +39 -0
- package/dist/types.js +25 -0
- package/package.json +29 -75
- package/dist/data/Stat.svelte +0 -89
- package/dist/data/Stat.svelte.d.ts +0 -39
- package/dist/data/index.d.ts +0 -1
- package/dist/data/index.js +0 -1
- package/dist/display/Avatar.svelte +0 -61
- package/dist/display/Avatar.svelte.d.ts +0 -23
- package/dist/display/Badge.svelte +0 -93
- package/dist/display/Badge.svelte.d.ts +0 -34
- package/dist/display/Callout.svelte +0 -109
- package/dist/display/Callout.svelte.d.ts +0 -36
- package/dist/display/Close.svelte +0 -58
- package/dist/display/Close.svelte.d.ts +0 -21
- package/dist/display/Code.svelte +0 -195
- package/dist/display/Code.svelte.d.ts +0 -31
- package/dist/display/ContextTip.svelte +0 -26
- package/dist/display/ContextTip.svelte.d.ts +0 -22
- package/dist/display/Details.svelte +0 -49
- package/dist/display/Details.svelte.d.ts +0 -32
- package/dist/display/Hero.svelte +0 -50
- package/dist/display/Hero.svelte.d.ts +0 -30
- package/dist/display/Icon.svelte +0 -40
- package/dist/display/Icon.svelte.d.ts +0 -24
- package/dist/display/IconButton.svelte +0 -84
- package/dist/display/IconButton.svelte.d.ts +0 -30
- package/dist/display/Image.svelte +0 -91
- package/dist/display/Image.svelte.d.ts +0 -37
- package/dist/display/Indicator.svelte +0 -352
- package/dist/display/Indicator.svelte.d.ts +0 -24
- package/dist/display/Inset.svelte +0 -18
- package/dist/display/Inset.svelte.d.ts +0 -22
- package/dist/display/Notification.svelte +0 -104
- package/dist/display/Notification.svelte.d.ts +0 -42
- package/dist/display/Popup.svelte +0 -111
- package/dist/display/Popup.svelte.d.ts +0 -30
- package/dist/display/Table.svelte +0 -24
- package/dist/display/Table.svelte.d.ts +0 -34
- package/dist/display/Tag.svelte +0 -90
- package/dist/display/Tag.svelte.d.ts +0 -35
- package/dist/display/Tooltip.svelte.d.ts +0 -28
- package/dist/display/index.d.ts +0 -14
- package/dist/display/index.js +0 -14
- package/dist/display/notifications.svelte.d.ts +0 -21
- package/dist/display/notifications.svelte.js +0 -31
- package/dist/form/Button.svelte +0 -34
- package/dist/form/Button.svelte.d.ts +0 -36
- package/dist/form/FieldActions.svelte +0 -46
- package/dist/form/FieldActions.svelte.d.ts +0 -24
- package/dist/form/FieldContainer.svelte +0 -37
- package/dist/form/FieldContainer.svelte.d.ts +0 -24
- package/dist/form/FieldContent.svelte +0 -134
- package/dist/form/FieldContent.svelte.d.ts +0 -59
- package/dist/form/FieldError.svelte +0 -14
- package/dist/form/FieldError.svelte.d.ts +0 -21
- package/dist/form/FieldSection.svelte +0 -86
- package/dist/form/FieldSection.svelte.d.ts +0 -34
- package/dist/form/Fieldset.svelte +0 -68
- package/dist/form/Fieldset.svelte.d.ts +0 -42
- package/dist/form/Form.svelte +0 -98
- package/dist/form/Form.svelte.d.ts +0 -33
- package/dist/form/Input.svelte +0 -287
- package/dist/form/Input.svelte.d.ts +0 -142
- package/dist/form/InputLength.svelte +0 -32
- package/dist/form/InputLength.svelte.d.ts +0 -21
- package/dist/form/Label.svelte +0 -27
- package/dist/form/Label.svelte.d.ts +0 -31
- package/dist/form/Select.svelte +0 -88
- package/dist/form/Select.svelte.d.ts +0 -97
- package/dist/form/client.svelte.d.ts +0 -45
- package/dist/form/client.svelte.js +0 -90
- package/dist/form/form.d.ts +0 -52
- package/dist/form/form.js +0 -326
- package/dist/form/index.d.ts +0 -15
- package/dist/form/index.js +0 -15
- package/dist/form/types.d.ts +0 -52
- package/dist/form/types.js +0 -1
- package/dist/grid/Column.svelte +0 -11
- package/dist/grid/Column.svelte.d.ts +0 -22
- package/dist/grid/Grid.svelte +0 -19
- package/dist/grid/Grid.svelte.d.ts +0 -24
- package/dist/grid/Row.svelte +0 -44
- package/dist/grid/Row.svelte.d.ts +0 -24
- package/dist/icons/Alert.svelte +0 -3
- package/dist/icons/Alert.svelte.d.ts +0 -23
- package/dist/icons/Copy.svelte +0 -3
- package/dist/icons/Copy.svelte.d.ts +0 -23
- package/dist/icons/Done.svelte +0 -3
- package/dist/icons/Done.svelte.d.ts +0 -23
- package/dist/icons/Error.svelte +0 -3
- package/dist/icons/Error.svelte.d.ts +0 -23
- package/dist/icons/Help.svelte +0 -3
- package/dist/icons/Help.svelte.d.ts +0 -23
- package/dist/icons/Hide.svelte +0 -3
- package/dist/icons/Hide.svelte.d.ts +0 -23
- package/dist/icons/Info.svelte +0 -3
- package/dist/icons/Info.svelte.d.ts +0 -23
- package/dist/icons/Link.svelte +0 -3
- package/dist/icons/Link.svelte.d.ts +0 -23
- package/dist/icons/MenuBurger.svelte +0 -3
- package/dist/icons/MenuBurger.svelte.d.ts +0 -23
- package/dist/icons/MenuDots.svelte +0 -3
- package/dist/icons/MenuDots.svelte.d.ts +0 -23
- package/dist/icons/Show.svelte +0 -3
- package/dist/icons/Show.svelte.d.ts +0 -23
- package/dist/icons/Success.svelte +0 -3
- package/dist/icons/Success.svelte.d.ts +0 -23
- package/dist/icons/Warning.svelte +0 -3
- package/dist/icons/Warning.svelte.d.ts +0 -23
- package/dist/icons/index.d.ts +0 -11
- package/dist/icons/index.js +0 -11
- package/dist/layout/Layout.svelte +0 -45
- package/dist/layout/Layout.svelte.d.ts +0 -25
- package/dist/layout/LayoutFooter.svelte +0 -21
- package/dist/layout/LayoutFooter.svelte.d.ts +0 -19
- package/dist/layout/LayoutGrid.svelte +0 -51
- package/dist/layout/LayoutGrid.svelte.d.ts +0 -38
- package/dist/layout/LayoutHeader.svelte +0 -94
- package/dist/layout/LayoutHeader.svelte.d.ts +0 -39
- package/dist/layout/LayoutSideMenu.svelte +0 -54
- package/dist/layout/LayoutSideMenu.svelte.d.ts +0 -25
- package/dist/layout/LayoutTypes.d.ts +0 -15
- package/dist/layout/LayoutTypes.js +0 -9
- package/dist/layout/Overlay.svelte +0 -20
- package/dist/layout/Overlay.svelte.d.ts +0 -35
- package/dist/layout/OverlayContainer.svelte +0 -28
- package/dist/layout/OverlayContainer.svelte.d.ts +0 -16
- package/dist/layout/OverlayLayer.svelte +0 -145
- package/dist/layout/OverlayLayer.svelte.d.ts +0 -22
- package/dist/layout/PageContent.svelte +0 -97
- package/dist/layout/PageContent.svelte.d.ts +0 -28
- package/dist/layout/Theme.svelte +0 -228
- package/dist/layout/Theme.svelte.d.ts +0 -24
- package/dist/layout/UIContent.svelte +0 -15
- package/dist/layout/UIContent.svelte.d.ts +0 -22
- package/dist/layout/index.d.ts +0 -7
- package/dist/layout/index.js +0 -7
- package/dist/layout/overlays.svelte.d.ts +0 -34
- package/dist/layout/overlays.svelte.js +0 -44
- package/dist/nav/Breadcrumb.svelte +0 -82
- package/dist/nav/Breadcrumb.svelte.d.ts +0 -33
- package/dist/nav/Menu.svelte +0 -177
- package/dist/nav/Menu.svelte.d.ts +0 -33
- package/dist/nav/MenuItem.svelte +0 -140
- package/dist/nav/MenuItem.svelte.d.ts +0 -26
- package/dist/nav/MenuTypes.d.ts +0 -58
- package/dist/nav/MenuTypes.js +0 -1
- package/dist/nav/NavMenu.svelte +0 -183
- package/dist/nav/NavMenu.svelte.d.ts +0 -20
- package/dist/nav/TabbedContent.svelte +0 -43
- package/dist/nav/TabbedContent.svelte.d.ts +0 -24
- package/dist/nav/Tabs.svelte +0 -118
- package/dist/nav/Tabs.svelte.d.ts +0 -26
- package/dist/nav/index.d.ts +0 -6
- package/dist/nav/index.js +0 -5
- package/dist/style.css +0 -853
- package/dist/typo/Clamp.svelte +0 -25
- package/dist/typo/Clamp.svelte.d.ts +0 -28
- package/dist/typo/H.svelte +0 -52
- package/dist/typo/H.svelte.d.ts +0 -32
- package/dist/typo/H1.svelte +0 -14
- package/dist/typo/H1.svelte.d.ts +0 -30
- package/dist/typo/H2.svelte +0 -14
- package/dist/typo/H2.svelte.d.ts +0 -30
- package/dist/typo/H3.svelte +0 -14
- package/dist/typo/H3.svelte.d.ts +0 -30
- package/dist/typo/H4.svelte +0 -14
- package/dist/typo/H4.svelte.d.ts +0 -30
- package/dist/typo/H5.svelte +0 -14
- package/dist/typo/H5.svelte.d.ts +0 -30
- package/dist/typo/H6.svelte +0 -14
- package/dist/typo/H6.svelte.d.ts +0 -30
- package/dist/typo/P.svelte +0 -34
- package/dist/typo/P.svelte.d.ts +0 -30
- package/dist/typo/index.d.ts +0 -9
- package/dist/typo/index.js +0 -9
- package/dist/utils/StringOrComponentOrSnippet.svelte +0 -14
- package/dist/utils/StringOrComponentOrSnippet.svelte.d.ts +0 -24
- package/dist/utils/attr.d.ts +0 -5
- package/dist/utils/attr.js +0 -21
- package/dist/utils/color.d.ts +0 -51
- package/dist/utils/color.js +0 -97
- package/dist/utils/defaults.d.ts +0 -4
- package/dist/utils/defaults.js +0 -1
- package/dist/utils/dom.d.ts +0 -15
- package/dist/utils/dom.js +0 -74
- package/dist/utils/hooks.server.d.ts +0 -2
- package/dist/utils/hooks.server.js +0 -16
- package/dist/utils/id.d.ts +0 -1
- package/dist/utils/id.js +0 -3
- package/dist/utils/index.d.ts +0 -8
- package/dist/utils/index.js +0 -5
- package/dist/utils/isSnippet.d.ts +0 -5
- package/dist/utils/isSnippet.js +0 -6
- package/dist/utils/keyboard.svelte.d.ts +0 -22
- package/dist/utils/keyboard.svelte.js +0 -161
- /package/dist/{utils → util}/transitions.d.ts +0 -0
- /package/dist/{utils → util}/transitions.js +0 -0
package/dist/utils/color.js
DELETED
@@ -1,97 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Convert a string to a color
|
3
|
-
* @param {string} str - The string to convert
|
4
|
-
* @returns {string} The color
|
5
|
-
*/
|
6
|
-
export function stringToColor(str) {
|
7
|
-
let hash = 0;
|
8
|
-
for (let i = 0; i < str.length; i++) {
|
9
|
-
hash = str.charCodeAt(i) + ((hash << 5) - hash);
|
10
|
-
}
|
11
|
-
let color = '#';
|
12
|
-
for (let i = 0; i < 3; i++) {
|
13
|
-
const value = (hash >> (i * 8)) & 0xFF;
|
14
|
-
color += ('00' + value.toString(16)).substr(-2);
|
15
|
-
}
|
16
|
-
return color;
|
17
|
-
}
|
18
|
-
/**
|
19
|
-
* Convert a hex color to rgb
|
20
|
-
* @param {string} hex - The hex color
|
21
|
-
* @returns {number[]} The rgb color
|
22
|
-
*/
|
23
|
-
export function hexToRgb(hex) {
|
24
|
-
// Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF")
|
25
|
-
var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
|
26
|
-
hex = hex.replace(shorthandRegex, function (m, r, g, b) {
|
27
|
-
return r + r + g + g + b + b;
|
28
|
-
});
|
29
|
-
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
30
|
-
if (!result) {
|
31
|
-
throw new Error('Invalid hex color');
|
32
|
-
}
|
33
|
-
return [
|
34
|
-
parseInt(result[1], 16),
|
35
|
-
parseInt(result[2], 16),
|
36
|
-
parseInt(result[3], 16)
|
37
|
-
];
|
38
|
-
}
|
39
|
-
/**
|
40
|
-
* Get the relative luminance of a color from a hex color
|
41
|
-
* @param {string} hex - The hex color
|
42
|
-
* @returns {number} The relative luminance
|
43
|
-
*/
|
44
|
-
export function hexRelativeLuminance(hex) {
|
45
|
-
const rgb = hexToRgb(hex);
|
46
|
-
return relativeLuminanceW3C(rgb[0], rgb[1], rgb[2]);
|
47
|
-
}
|
48
|
-
/**
|
49
|
-
* Get the relative luminance of a color according to the W3C
|
50
|
-
* @param {number} R8bit - The red value
|
51
|
-
* @param {number} G8bit - The green value
|
52
|
-
* @param {number} B8bit - The blue value
|
53
|
-
* @returns
|
54
|
-
*/
|
55
|
-
export function relativeLuminanceW3C(R8bit, G8bit, B8bit) {
|
56
|
-
var RsRGB = R8bit / 255;
|
57
|
-
var GsRGB = G8bit / 255;
|
58
|
-
var BsRGB = B8bit / 255;
|
59
|
-
var R = (RsRGB <= 0.03928) ? RsRGB / 12.92 : Math.pow((RsRGB + 0.055) / 1.055, 2.4);
|
60
|
-
var G = (GsRGB <= 0.03928) ? GsRGB / 12.92 : Math.pow((GsRGB + 0.055) / 1.055, 2.4);
|
61
|
-
var B = (BsRGB <= 0.03928) ? BsRGB / 12.92 : Math.pow((BsRGB + 0.055) / 1.055, 2.4);
|
62
|
-
// For the sRGB colorspace, the relative luminance of a color is defined as:
|
63
|
-
var L = 0.2126 * R + 0.7152 * G + 0.0722 * B;
|
64
|
-
return L;
|
65
|
-
}
|
66
|
-
/**
|
67
|
-
* Status colors
|
68
|
-
*/
|
69
|
-
export const StatusColors = {
|
70
|
-
default: "default",
|
71
|
-
ok: "ok",
|
72
|
-
alert: "alert",
|
73
|
-
warn: "warn",
|
74
|
-
info: "info",
|
75
|
-
task: "task"
|
76
|
-
};
|
77
|
-
/**
|
78
|
-
* Check if the value is a valid StatusColor
|
79
|
-
* @param {string} value - The value to check
|
80
|
-
* @returns {boolean} - If the value is a valid StatusColor
|
81
|
-
*/
|
82
|
-
export const isStatusColor = (value) => {
|
83
|
-
if (!value)
|
84
|
-
return false;
|
85
|
-
return Object.keys(StatusColors).includes(value);
|
86
|
-
};
|
87
|
-
/**
|
88
|
-
* Get the CSS variable for a status color
|
89
|
-
* @param {StatusColorOrString} color - The status color
|
90
|
-
* @returns {string} - The CSS variable for the status color
|
91
|
-
*/
|
92
|
-
export function getStatusColorVar(color, fallback) {
|
93
|
-
if (isStatusColor(color)) {
|
94
|
-
return `var(--status-${color})`;
|
95
|
-
}
|
96
|
-
return color || fallback || "var(--status-default)";
|
97
|
-
}
|
package/dist/utils/defaults.d.ts
DELETED
package/dist/utils/defaults.js
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|
package/dist/utils/dom.d.ts
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Find the containing block of a given element. The containing block is the nearest ancestor element that is a containing block for positioned elements.
|
3
|
-
* @param {HTMLElement | null} element - The element to find the containing block for.
|
4
|
-
* @returns {HTMLElement | null} - The containing block element, or null if none is found.
|
5
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block
|
6
|
-
*/
|
7
|
-
export declare function findContainingBlock(element: HTMLElement | null, id?: string): HTMLElement | null;
|
8
|
-
export declare function findAllContainingBlocks(element: HTMLElement | null): HTMLElement[];
|
9
|
-
/**
|
10
|
-
* Get the total offset of an element, including all its containing blocks.
|
11
|
-
*/
|
12
|
-
export declare function getPossiblyContainedPosition(element: HTMLElement | null): {
|
13
|
-
left: number;
|
14
|
-
top: number;
|
15
|
-
};
|
package/dist/utils/dom.js
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
import { createId } from "./id.js";
|
2
|
-
let initialElements = {};
|
3
|
-
let initialStyles = {};
|
4
|
-
/**
|
5
|
-
* Find the containing block of a given element. The containing block is the nearest ancestor element that is a containing block for positioned elements.
|
6
|
-
* @param {HTMLElement | null} element - The element to find the containing block for.
|
7
|
-
* @returns {HTMLElement | null} - The containing block element, or null if none is found.
|
8
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block
|
9
|
-
*/
|
10
|
-
export function findContainingBlock(element, id = createId()) {
|
11
|
-
const elementToLookAt = element?.parentElement;
|
12
|
-
// Base case for recursion: if the element is the body or null, return null as no containing block was found
|
13
|
-
if (!elementToLookAt || !element || element.tagName === "BODY" || elementToLookAt.tagName === "BODY") {
|
14
|
-
return null;
|
15
|
-
}
|
16
|
-
if (!initialElements[id]) {
|
17
|
-
initialElements[id] = element;
|
18
|
-
initialStyles[id] = getComputedStyle(element);
|
19
|
-
}
|
20
|
-
// Get computed styles of the current element
|
21
|
-
const style = getComputedStyle(elementToLookAt);
|
22
|
-
// Check for properties that make this element a containing block for positioned elements
|
23
|
-
if ((style.position !== 'static' && (initialStyles[id].position === 'fixed' ||
|
24
|
-
initialStyles[id].position === 'absolute' ||
|
25
|
-
initialStyles[id].position === 'sticky')) ||
|
26
|
-
(style.transform !== 'none' && style.transform !== undefined) ||
|
27
|
-
style.perspective !== 'none' && style.perspective !== undefined ||
|
28
|
-
style.filter !== 'none' && style.filter !== undefined ||
|
29
|
-
style.willChange === 'transform' || style.willChange === 'perspective' ||
|
30
|
-
style.willChange === 'filter' || // Firefox specific for filters
|
31
|
-
(style.contain.includes('layout') || style.contain.includes('paint') || style.contain.includes('strict') || style.contain.includes('content')) ||
|
32
|
-
style.containerType !== 'normal' ||
|
33
|
-
(style.backdropFilter !== 'none' && style.backdropFilter !== undefined)) {
|
34
|
-
delete initialElements[id];
|
35
|
-
delete initialStyles[id];
|
36
|
-
return element;
|
37
|
-
}
|
38
|
-
// Recurse up the DOM tree if no containing block found
|
39
|
-
return findContainingBlock(elementToLookAt, id);
|
40
|
-
}
|
41
|
-
export function findAllContainingBlocks(element) {
|
42
|
-
let currentElement = findContainingBlock(element);
|
43
|
-
if (!currentElement)
|
44
|
-
return [];
|
45
|
-
const blocks = [currentElement];
|
46
|
-
let i = 0;
|
47
|
-
while (currentElement !== null && currentElement.tagName !== 'BODY' && i < 50) {
|
48
|
-
const block = findContainingBlock(currentElement.parentElement);
|
49
|
-
if (block) {
|
50
|
-
blocks.push(block.parentElement);
|
51
|
-
}
|
52
|
-
currentElement = block;
|
53
|
-
i++;
|
54
|
-
}
|
55
|
-
return blocks;
|
56
|
-
}
|
57
|
-
/**
|
58
|
-
* Get the total offset of an element, including all its containing blocks.
|
59
|
-
*/
|
60
|
-
export function getPossiblyContainedPosition(element) {
|
61
|
-
const blocks = findAllContainingBlocks(element);
|
62
|
-
let left = 0;
|
63
|
-
let top = 0;
|
64
|
-
for (const block of blocks) {
|
65
|
-
const rect = block.getBoundingClientRect();
|
66
|
-
console.log('block', block, rect);
|
67
|
-
left += rect.left;
|
68
|
-
top += rect.top;
|
69
|
-
}
|
70
|
-
return {
|
71
|
-
left: left,
|
72
|
-
top: top
|
73
|
-
};
|
74
|
-
}
|
@@ -1,16 +0,0 @@
|
|
1
|
-
const acceptCh = [
|
2
|
-
'Sec-CH-Prefers-Color-Scheme',
|
3
|
-
'Sec-CH-Prefers-Reduced-Transparency',
|
4
|
-
'Sec-CH-Prefers-Reduced-Motion',
|
5
|
-
'Sec-CH-UA-Arch',
|
6
|
-
'Sec-CH-UA-Bitness',
|
7
|
-
'Sec-CH-UA-Mobile',
|
8
|
-
'Sec-CH-UA-Model',
|
9
|
-
'Sec-CH-UA-Platform',
|
10
|
-
'Sec-CH-UA-Platform-Version',
|
11
|
-
];
|
12
|
-
export const addAcceptCh = (event) => {
|
13
|
-
event.setHeaders({
|
14
|
-
'Accept-CH': acceptCh.join(', ')
|
15
|
-
});
|
16
|
-
};
|
package/dist/utils/id.d.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export declare function createId(): string;
|
package/dist/utils/id.js
DELETED
package/dist/utils/index.d.ts
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
export { attr } from './attr.js';
|
2
|
-
export { stringToColor, hexToRgb, hexRelativeLuminance, relativeLuminanceW3C, StatusColors, isStatusColor, getStatusColorVar } from './color.js';
|
3
|
-
export type { Defaults } from './defaults.js';
|
4
|
-
export { createId } from './id.js';
|
5
|
-
export { isSnippet, isComponent } from './isSnippet.js';
|
6
|
-
export type { StatusColor, StatusColorOrString } from './color.js';
|
7
|
-
export { popBezier, popBezierInverse, slidefade, solve_spring, cubicBezier } from './transitions.js';
|
8
|
-
export type { SpringParams } from './transitions.js';
|
package/dist/utils/index.js
DELETED
@@ -1,5 +0,0 @@
|
|
1
|
-
export { attr } from './attr.js';
|
2
|
-
export { stringToColor, hexToRgb, hexRelativeLuminance, relativeLuminanceW3C, StatusColors, isStatusColor, getStatusColorVar } from './color.js';
|
3
|
-
export { createId } from './id.js';
|
4
|
-
export { isSnippet, isComponent } from './isSnippet.js';
|
5
|
-
export { popBezier, popBezierInverse, slidefade, solve_spring, cubicBezier } from './transitions.js';
|
@@ -1,5 +0,0 @@
|
|
1
|
-
import type { ComponentType } from "svelte";
|
2
|
-
export declare const isSnippet: (object: unknown) => object is (this: void) => typeof import("svelte").SnippetReturn & {
|
3
|
-
_: "functions passed to {@render ...} tags must use the `Snippet` type imported from \"svelte\"";
|
4
|
-
};
|
5
|
-
export declare const isComponent: (object: unknown) => object is ComponentType;
|
package/dist/utils/isSnippet.js
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Get the next focusable element in the specified direction
|
3
|
-
* @param {HTMLElement | null} startingElement - The element to start the search from.
|
4
|
-
* @param {HTMLElement | null} triggerElement - The element that triggered the search.
|
5
|
-
* @param {string} direction - The direction to search in, either 'next' or 'previous'.
|
6
|
-
* @returns {HTMLElement | null} - The next focusable element, or null if none are found.
|
7
|
-
*/
|
8
|
-
export declare function getNextFocusableElement(startingElement: HTMLElement | null, triggerElement: HTMLElement | null, direction: "next" | "previous"): HTMLElement | null;
|
9
|
-
/**
|
10
|
-
* Navigate through a list of elements using the arrow keys
|
11
|
-
* @param {HTMLElement | null} el - The element containing the list of elements to navigate.
|
12
|
-
* @param {string} direction - The direction to navigate in, either 'up' or 'down'.
|
13
|
-
* @returns {void}
|
14
|
-
*/
|
15
|
-
export declare function arrowNavigation(el: HTMLElement | null, direction: "up" | "down"): void;
|
16
|
-
/**
|
17
|
-
* Match the key pressed to the first letter of an element in the list
|
18
|
-
* @param {HTMLElement | null} el - The element containing the list of elements to search through.
|
19
|
-
* @param {KeyboardEvent} e - The keyboard event to match the key from.
|
20
|
-
* @returns {void}
|
21
|
-
*/
|
22
|
-
export declare function matchOnType(el: HTMLElement | null, e: KeyboardEvent): void;
|
@@ -1,161 +0,0 @@
|
|
1
|
-
const ignoreKeys = ['backspace', 'tab', 'shift', 'control', 'alt', 'meta', 'arrowup', 'arrowdown', 'arrowleft', 'arrowright', 'home', 'end', 'pageup', 'pagedown', 'escape', 'capslock', 'numlock', 'scrolllock', 'pause', 'contextmenu', 'printscreen', 'help', 'clear', 'os', 'f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9', 'f10', 'f12', 'insert', 'delete', 'enter', 'space', 'escape'];
|
2
|
-
let keyMemory = $state("");
|
3
|
-
let timeout;
|
4
|
-
/**
|
5
|
-
* Get the next focusable element in the specified direction
|
6
|
-
* @param {HTMLElement | null} startingElement - The element to start the search from.
|
7
|
-
* @param {HTMLElement | null} triggerElement - The element that triggered the search.
|
8
|
-
* @param {string} direction - The direction to search in, either 'next' or 'previous'.
|
9
|
-
* @returns {HTMLElement | null} - The next focusable element, or null if none are found.
|
10
|
-
*/
|
11
|
-
export function getNextFocusableElement(startingElement, triggerElement, direction) {
|
12
|
-
if (!startingElement)
|
13
|
-
return null;
|
14
|
-
// Define selectors for focusable elements
|
15
|
-
const focusableSelectors = 'a, button, textarea, input, select';
|
16
|
-
// Get all focusable elements
|
17
|
-
const allFocusableElements = Array.from(document.querySelectorAll(focusableSelectors)).filter(el => !el.disabled && el.tabIndex >= 0);
|
18
|
-
console.log('allFocusableElements', allFocusableElements);
|
19
|
-
// Filter out elements inside the startingElement
|
20
|
-
const focusableElements = allFocusableElements.filter(el => !triggerElement.contains(el) && el !== startingElement);
|
21
|
-
console.log('focusableElements', focusableElements);
|
22
|
-
// Find the index of the starting element among all focusable elements
|
23
|
-
let startingIndex = allFocusableElements.indexOf(triggerElement);
|
24
|
-
console.log('startingIndex', startingIndex);
|
25
|
-
if (startingIndex === -1) {
|
26
|
-
// If the starting element is not focusable or not found, consider the document's active element if it's focusable.
|
27
|
-
const activeElement = document.activeElement;
|
28
|
-
if (activeElement && allFocusableElements.includes(activeElement)) {
|
29
|
-
startingIndex = allFocusableElements.indexOf(activeElement);
|
30
|
-
}
|
31
|
-
else {
|
32
|
-
// No valid starting point found
|
33
|
-
return null;
|
34
|
-
}
|
35
|
-
}
|
36
|
-
// Determine the next index based on the direction, skipping children of startingElement
|
37
|
-
let nextIndex = -1;
|
38
|
-
if (direction === 'next') {
|
39
|
-
for (let i = startingIndex + 1; i < allFocusableElements.length; i++) {
|
40
|
-
if (focusableElements.includes(allFocusableElements[i])) {
|
41
|
-
nextIndex = focusableElements.indexOf(allFocusableElements[i]);
|
42
|
-
break;
|
43
|
-
}
|
44
|
-
}
|
45
|
-
}
|
46
|
-
else {
|
47
|
-
for (let i = startingIndex - 1; i >= 0; i--) {
|
48
|
-
if (focusableElements.includes(allFocusableElements[i])) {
|
49
|
-
nextIndex = focusableElements.indexOf(allFocusableElements[i]);
|
50
|
-
break;
|
51
|
-
}
|
52
|
-
}
|
53
|
-
}
|
54
|
-
// If no next element is found in the direction, wrap around.
|
55
|
-
if (nextIndex === -1) {
|
56
|
-
if (direction === 'next') {
|
57
|
-
// Wrap to the first element in the list
|
58
|
-
nextIndex = 0;
|
59
|
-
}
|
60
|
-
else {
|
61
|
-
// Wrap to the last element in the list
|
62
|
-
nextIndex = focusableElements.length - 1;
|
63
|
-
}
|
64
|
-
}
|
65
|
-
// Return the next focusable element, or null if none are found
|
66
|
-
return focusableElements[nextIndex] || null;
|
67
|
-
}
|
68
|
-
/**
|
69
|
-
* Navigate through a list of elements using the arrow keys
|
70
|
-
* @param {HTMLElement | null} el - The element containing the list of elements to navigate.
|
71
|
-
* @param {string} direction - The direction to navigate in, either 'up' or 'down'.
|
72
|
-
* @returns {void}
|
73
|
-
*/
|
74
|
-
export function arrowNavigation(el, direction) {
|
75
|
-
const items = el?.querySelectorAll("a, button, input, textarea, select");
|
76
|
-
if (!items)
|
77
|
-
return;
|
78
|
-
const index = Array.from(items).findIndex((el) => el === document.activeElement);
|
79
|
-
if (index === -1) {
|
80
|
-
items[0].focus();
|
81
|
-
}
|
82
|
-
else if (direction === "down" && index < items.length - 1) {
|
83
|
-
items[index + 1].focus();
|
84
|
-
}
|
85
|
-
else if (direction === "up" && index > 0) {
|
86
|
-
items[index - 1].focus();
|
87
|
-
}
|
88
|
-
}
|
89
|
-
/**
|
90
|
-
* Match the key pressed to the first letter of an element in the list
|
91
|
-
* @param {HTMLElement | null} el - The element containing the list of elements to search through.
|
92
|
-
* @param {KeyboardEvent} e - The keyboard event to match the key from.
|
93
|
-
* @returns {void}
|
94
|
-
*/
|
95
|
-
export function matchOnType(el, e) {
|
96
|
-
const items = el?.querySelectorAll("a, button, label");
|
97
|
-
if (!items)
|
98
|
-
return;
|
99
|
-
const index = Array.from(items).findIndex((el) => el === document.activeElement);
|
100
|
-
const search = e.key.toLowerCase();
|
101
|
-
if (timeout)
|
102
|
-
clearTimeout(timeout);
|
103
|
-
function removeUls() {
|
104
|
-
items.forEach((el) => {
|
105
|
-
const contentEl = el.querySelector("span.Content") ?? el.querySelector("label");
|
106
|
-
if (contentEl) {
|
107
|
-
contentEl.innerHTML = contentEl.textContent;
|
108
|
-
}
|
109
|
-
});
|
110
|
-
}
|
111
|
-
const currentlyFocusedElement = document.activeElement;
|
112
|
-
// return if the key is not a letter or number
|
113
|
-
if (ignoreKeys.includes(search) || currentlyFocusedElement.tagName === "INPUT" || currentlyFocusedElement.tagName === "TEXTAREA") {
|
114
|
-
keyMemory = '';
|
115
|
-
removeUls();
|
116
|
-
return;
|
117
|
-
}
|
118
|
-
// clear the memory after 1 second
|
119
|
-
timeout = setTimeout(() => {
|
120
|
-
keyMemory = '';
|
121
|
-
removeUls();
|
122
|
-
}, 1000);
|
123
|
-
// only add if the last key is not the same
|
124
|
-
if (keyMemory[keyMemory.length - 1] !== search) {
|
125
|
-
keyMemory += search;
|
126
|
-
}
|
127
|
-
const matches = Array.from(items).filter((el) => {
|
128
|
-
const text = el.textContent?.trim().toLowerCase();
|
129
|
-
return text?.startsWith(keyMemory);
|
130
|
-
});
|
131
|
-
if (matches.length) {
|
132
|
-
// add underline to the matched text
|
133
|
-
matches.forEach((el) => {
|
134
|
-
const contentEl = el.querySelector("span.Content, label");
|
135
|
-
const text = contentEl?.textContent?.trim();
|
136
|
-
if (text) {
|
137
|
-
const index = text.toLowerCase().indexOf(keyMemory);
|
138
|
-
const first = text.slice(0, index);
|
139
|
-
const last = text.slice(index + keyMemory.length);
|
140
|
-
const middle = text.slice(index, index + keyMemory.length);
|
141
|
-
contentEl.innerHTML = `${first}<u>${middle}</u>${last}`;
|
142
|
-
}
|
143
|
-
});
|
144
|
-
if (keyMemory.length === 1) {
|
145
|
-
// if this element is already focused, move to the next one if memory is at one character
|
146
|
-
const nextMatches = Array.from(items).filter((el) => el.textContent?.trim().toLowerCase().startsWith(keyMemory));
|
147
|
-
if (nextMatches) {
|
148
|
-
const nextIndex = nextMatches.findIndex((el) => el === document.activeElement);
|
149
|
-
if (nextIndex < nextMatches.length - 1) {
|
150
|
-
nextMatches[nextIndex + 1].focus();
|
151
|
-
}
|
152
|
-
else {
|
153
|
-
nextMatches[0].focus();
|
154
|
-
}
|
155
|
-
}
|
156
|
-
}
|
157
|
-
else {
|
158
|
-
matches[0].focus();
|
159
|
-
}
|
160
|
-
}
|
161
|
-
}
|
File without changes
|
File without changes
|