@incursa/ui-kit 1.0.1 → 1.2.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.
Files changed (45) hide show
  1. package/AI-AGENT-INSTRUCTIONS.md +41 -28
  2. package/LLMS.txt +55 -41
  3. package/README.md +181 -68
  4. package/dist/inc-design-language.css +413 -239
  5. package/dist/inc-design-language.css.map +1 -1
  6. package/dist/inc-design-language.js +520 -0
  7. package/dist/inc-design-language.min.css +1 -1
  8. package/dist/inc-design-language.min.css.map +1 -1
  9. package/dist/web-components/README.md +92 -0
  10. package/dist/web-components/RUNTIME-NOTES.md +40 -0
  11. package/dist/web-components/base-element.js +193 -0
  12. package/dist/web-components/components/feedback.js +1074 -0
  13. package/dist/web-components/components/forms.js +979 -0
  14. package/dist/web-components/components/layout.js +408 -0
  15. package/dist/web-components/components/navigation.js +854 -0
  16. package/dist/web-components/components/overlays.js +634 -0
  17. package/dist/web-components/controllers/focus.js +101 -0
  18. package/dist/web-components/controllers/overlay.js +128 -0
  19. package/dist/web-components/controllers/selection.js +145 -0
  20. package/dist/web-components/controllers/theme.js +173 -0
  21. package/dist/web-components/index.js +886 -0
  22. package/dist/web-components/package.json +3 -0
  23. package/dist/web-components/registry.js +74 -0
  24. package/dist/web-components/shared.js +186 -0
  25. package/dist/web-components/style.css +6 -0
  26. package/package.json +11 -2
  27. package/src/inc-design-language.js +520 -0
  28. package/src/inc-design-language.scss +434 -246
  29. package/src/web-components/README.md +92 -0
  30. package/src/web-components/RUNTIME-NOTES.md +40 -0
  31. package/src/web-components/base-element.js +193 -0
  32. package/src/web-components/components/feedback.js +1074 -0
  33. package/src/web-components/components/forms.js +979 -0
  34. package/src/web-components/components/layout.js +408 -0
  35. package/src/web-components/components/navigation.js +854 -0
  36. package/src/web-components/components/overlays.js +634 -0
  37. package/src/web-components/controllers/focus.js +101 -0
  38. package/src/web-components/controllers/overlay.js +128 -0
  39. package/src/web-components/controllers/selection.js +145 -0
  40. package/src/web-components/controllers/theme.js +173 -0
  41. package/src/web-components/index.js +886 -0
  42. package/src/web-components/package.json +3 -0
  43. package/src/web-components/registry.js +74 -0
  44. package/src/web-components/shared.js +186 -0
  45. package/src/web-components/style.css +6 -0
@@ -0,0 +1,101 @@
1
+ const FOCUSABLE_SELECTOR = [
2
+ 'a[href]:not([tabindex="-1"])',
3
+ 'button:not([disabled]):not([tabindex="-1"])',
4
+ 'input:not([disabled]):not([type="hidden"]):not([tabindex="-1"])',
5
+ 'select:not([disabled]):not([tabindex="-1"])',
6
+ 'textarea:not([disabled]):not([tabindex="-1"])',
7
+ '[tabindex]:not([tabindex="-1"])',
8
+ '[contenteditable="true"]',
9
+ ].join(", ");
10
+
11
+ function getFocusableElements(root) {
12
+ if (!(root instanceof Element || root instanceof Document || root instanceof ShadowRoot)) {
13
+ return [];
14
+ }
15
+
16
+ return Array.from(root.querySelectorAll(FOCUSABLE_SELECTOR))
17
+ .filter((element) => element instanceof HTMLElement)
18
+ .filter((element) => !element.hasAttribute("inert"))
19
+ .filter((element) => element.offsetParent !== null || element === document.activeElement);
20
+ }
21
+
22
+ function getFirstFocusable(root) {
23
+ return getFocusableElements(root)[0] ?? null;
24
+ }
25
+
26
+ function getLastFocusable(root) {
27
+ const items = getFocusableElements(root);
28
+ return items.length ? items[items.length - 1] : null;
29
+ }
30
+
31
+ function focusFirst(root) {
32
+ const first = getFirstFocusable(root);
33
+ first?.focus();
34
+ return first;
35
+ }
36
+
37
+ function focusLast(root) {
38
+ const last = getLastFocusable(root);
39
+ last?.focus();
40
+ return last;
41
+ }
42
+
43
+ function trapTabKey(event, root) {
44
+ if (!(event instanceof KeyboardEvent) || event.key !== "Tab") {
45
+ return false;
46
+ }
47
+
48
+ const items = getFocusableElements(root);
49
+ if (!items.length) {
50
+ return false;
51
+ }
52
+
53
+ const first = items[0];
54
+ const last = items[items.length - 1];
55
+ const active = document.activeElement;
56
+
57
+ if (event.shiftKey && active === first) {
58
+ event.preventDefault();
59
+ last.focus();
60
+ return true;
61
+ }
62
+
63
+ if (!event.shiftKey && active === last) {
64
+ event.preventDefault();
65
+ first.focus();
66
+ return true;
67
+ }
68
+
69
+ return false;
70
+ }
71
+
72
+ function createFocusRestorer(fallback = null) {
73
+ const source = document.activeElement instanceof HTMLElement
74
+ ? document.activeElement
75
+ : (fallback instanceof HTMLElement ? fallback : null);
76
+
77
+ return () => {
78
+ if (source && source.isConnected) {
79
+ source.focus();
80
+ return source;
81
+ }
82
+
83
+ if (fallback instanceof HTMLElement && fallback.isConnected) {
84
+ fallback.focus();
85
+ return fallback;
86
+ }
87
+
88
+ return null;
89
+ };
90
+ }
91
+
92
+ export {
93
+ FOCUSABLE_SELECTOR,
94
+ createFocusRestorer,
95
+ focusFirst,
96
+ focusLast,
97
+ getFirstFocusable,
98
+ getFocusableElements,
99
+ getLastFocusable,
100
+ trapTabKey,
101
+ };
@@ -0,0 +1,128 @@
1
+ import { createFocusRestorer, focusFirst, trapTabKey } from "./focus.js";
2
+
3
+ function setOpenState(host, isOpen) {
4
+ host.toggleAttribute("open", Boolean(isOpen));
5
+ host.setAttribute("aria-hidden", isOpen ? "false" : "true");
6
+ }
7
+
8
+ function createOverlayController(host, options = {}) {
9
+ if (!(host instanceof HTMLElement)) {
10
+ throw new TypeError("Overlay controller host must be an HTMLElement.");
11
+ }
12
+
13
+ const panel = typeof options.getPanel === "function"
14
+ ? options.getPanel
15
+ : () => host;
16
+ const closeOnEscape = options.closeOnEscape !== false;
17
+ const trapFocus = options.trapFocus !== false;
18
+ let restoreFocus = null;
19
+ let isOpen = host.hasAttribute("open");
20
+
21
+ const onKeydown = (event) => {
22
+ if (!(event instanceof KeyboardEvent) || !isOpen) {
23
+ return;
24
+ }
25
+
26
+ if (closeOnEscape && event.key === "Escape") {
27
+ event.preventDefault();
28
+ api.close("escape");
29
+ return;
30
+ }
31
+
32
+ if (trapFocus) {
33
+ trapTabKey(event, panel());
34
+ }
35
+ };
36
+
37
+ const onPointerDown = (event) => {
38
+ if (!isOpen || options.closeOnOutsidePointerDown !== true) {
39
+ return;
40
+ }
41
+
42
+ const currentPanel = panel();
43
+ if (!(currentPanel instanceof HTMLElement)) {
44
+ return;
45
+ }
46
+
47
+ if (!currentPanel.contains(event.target)) {
48
+ api.close("outside-pointer");
49
+ }
50
+ };
51
+
52
+ function bind() {
53
+ document.addEventListener("keydown", onKeydown);
54
+ document.addEventListener("pointerdown", onPointerDown);
55
+ }
56
+
57
+ function unbind() {
58
+ document.removeEventListener("keydown", onKeydown);
59
+ document.removeEventListener("pointerdown", onPointerDown);
60
+ }
61
+
62
+ const api = {
63
+ get isOpen() {
64
+ return isOpen;
65
+ },
66
+ open(origin = "api") {
67
+ if (isOpen) {
68
+ return false;
69
+ }
70
+
71
+ isOpen = true;
72
+ restoreFocus = createFocusRestorer(options.fallbackFocus || null);
73
+ setOpenState(host, true);
74
+ bind();
75
+
76
+ if (typeof options.onOpen === "function") {
77
+ options.onOpen({ origin, host, panel: panel() });
78
+ }
79
+
80
+ if (options.focusFirst !== false) {
81
+ focusFirst(panel());
82
+ }
83
+
84
+ return true;
85
+ },
86
+ close(reason = "api") {
87
+ if (!isOpen) {
88
+ return false;
89
+ }
90
+
91
+ isOpen = false;
92
+ setOpenState(host, false);
93
+ unbind();
94
+
95
+ if (typeof options.onClose === "function") {
96
+ options.onClose({ reason, host, panel: panel() });
97
+ }
98
+
99
+ if (options.restoreFocus !== false) {
100
+ restoreFocus?.();
101
+ }
102
+
103
+ restoreFocus = null;
104
+ return true;
105
+ },
106
+ toggle(origin = "api") {
107
+ if (isOpen) {
108
+ this.close(origin);
109
+ return false;
110
+ }
111
+
112
+ this.open(origin);
113
+ return true;
114
+ },
115
+ dispose() {
116
+ unbind();
117
+ restoreFocus = null;
118
+ },
119
+ };
120
+
121
+ setOpenState(host, isOpen);
122
+ return api;
123
+ }
124
+
125
+ export {
126
+ createOverlayController,
127
+ setOpenState,
128
+ };
@@ -0,0 +1,145 @@
1
+ function clampIndex(value, length) {
2
+ if (!length) {
3
+ return -1;
4
+ }
5
+
6
+ if (!Number.isFinite(value)) {
7
+ return 0;
8
+ }
9
+
10
+ if (value < 0) {
11
+ return 0;
12
+ }
13
+
14
+ if (value >= length) {
15
+ return length - 1;
16
+ }
17
+
18
+ return value;
19
+ }
20
+
21
+ function resolveNextIndex(currentIndex, key, length, orientation = "horizontal") {
22
+ const horizontal = orientation === "horizontal";
23
+ const vertical = orientation === "vertical";
24
+
25
+ if (!length) {
26
+ return -1;
27
+ }
28
+
29
+ if (key === "Home") {
30
+ return 0;
31
+ }
32
+
33
+ if (key === "End") {
34
+ return length - 1;
35
+ }
36
+
37
+ if ((horizontal && key === "ArrowRight") || (vertical && key === "ArrowDown")) {
38
+ return (currentIndex + 1 + length) % length;
39
+ }
40
+
41
+ if ((horizontal && key === "ArrowLeft") || (vertical && key === "ArrowUp")) {
42
+ return (currentIndex - 1 + length) % length;
43
+ }
44
+
45
+ return currentIndex;
46
+ }
47
+
48
+ function updateRovingTabIndex(items, activeIndex) {
49
+ items.forEach((item, index) => {
50
+ if (!(item instanceof HTMLElement)) {
51
+ return;
52
+ }
53
+
54
+ item.tabIndex = index === activeIndex ? 0 : -1;
55
+ });
56
+ }
57
+
58
+ function createRovingSelection(options) {
59
+ const getItems = typeof options.getItems === "function"
60
+ ? options.getItems
61
+ : () => [];
62
+ const onChange = typeof options.onChange === "function"
63
+ ? options.onChange
64
+ : () => {};
65
+ const orientation = options.orientation || "horizontal";
66
+ const activation = options.activation || "auto";
67
+ let selectedIndex = Number.isFinite(options.initialIndex) ? options.initialIndex : 0;
68
+
69
+ function getNormalizedItems() {
70
+ return getItems().filter((item) => item instanceof HTMLElement);
71
+ }
72
+
73
+ function setSelectedIndex(nextIndex, origin = "api") {
74
+ const items = getNormalizedItems();
75
+ if (!items.length) {
76
+ selectedIndex = -1;
77
+ return -1;
78
+ }
79
+
80
+ selectedIndex = clampIndex(nextIndex, items.length);
81
+ updateRovingTabIndex(items, selectedIndex);
82
+ onChange({
83
+ index: selectedIndex,
84
+ item: items[selectedIndex],
85
+ items,
86
+ origin,
87
+ });
88
+ return selectedIndex;
89
+ }
90
+
91
+ function moveByKey(key, event = null) {
92
+ const items = getNormalizedItems();
93
+ if (!items.length) {
94
+ return -1;
95
+ }
96
+
97
+ const normalizedCurrent = clampIndex(selectedIndex, items.length);
98
+ const nextIndex = resolveNextIndex(normalizedCurrent, key, items.length, orientation);
99
+ if (nextIndex === normalizedCurrent) {
100
+ return normalizedCurrent;
101
+ }
102
+
103
+ if (event instanceof KeyboardEvent) {
104
+ event.preventDefault();
105
+ }
106
+
107
+ setSelectedIndex(nextIndex, "keyboard");
108
+ items[nextIndex]?.focus();
109
+
110
+ if (activation === "manual") {
111
+ return nextIndex;
112
+ }
113
+
114
+ return nextIndex;
115
+ }
116
+
117
+ function sync() {
118
+ const items = getNormalizedItems();
119
+ if (!items.length) {
120
+ selectedIndex = -1;
121
+ return -1;
122
+ }
123
+
124
+ return setSelectedIndex(clampIndex(selectedIndex, items.length), "sync");
125
+ }
126
+
127
+ return {
128
+ get index() {
129
+ return selectedIndex;
130
+ },
131
+ get items() {
132
+ return getNormalizedItems();
133
+ },
134
+ setSelectedIndex,
135
+ moveByKey,
136
+ sync,
137
+ };
138
+ }
139
+
140
+ export {
141
+ clampIndex,
142
+ createRovingSelection,
143
+ resolveNextIndex,
144
+ updateRovingTabIndex,
145
+ };
@@ -0,0 +1,173 @@
1
+ import { dispatchComponentEvent } from "../shared.js";
2
+
3
+ const DEFAULT_STORAGE_KEY = "inc-theme-mode";
4
+ const THEME_MODES = ["light", "dark", "system"];
5
+
6
+ function isThemeMode(value) {
7
+ return THEME_MODES.includes(value);
8
+ }
9
+
10
+ function resolveSystemTheme() {
11
+ if (typeof window === "undefined" || typeof window.matchMedia !== "function") {
12
+ return "light";
13
+ }
14
+
15
+ return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
16
+ }
17
+
18
+ function resolveThemeMode(mode) {
19
+ return mode === "system" ? resolveSystemTheme() : mode;
20
+ }
21
+
22
+ function getThemeRoot() {
23
+ return typeof document !== "undefined" ? document.documentElement : null;
24
+ }
25
+
26
+ function getStoredThemeMode(storageKey = DEFAULT_STORAGE_KEY) {
27
+ try {
28
+ const value = window.localStorage.getItem(storageKey);
29
+ return isThemeMode(value) ? value : null;
30
+ } catch {
31
+ return null;
32
+ }
33
+ }
34
+
35
+ function persistThemeMode(mode, storageKey = DEFAULT_STORAGE_KEY) {
36
+ try {
37
+ if (mode === "system") {
38
+ window.localStorage.removeItem(storageKey);
39
+ return;
40
+ }
41
+
42
+ window.localStorage.setItem(storageKey, mode);
43
+ } catch {
44
+ // Ignore storage restrictions.
45
+ }
46
+ }
47
+
48
+ function applyRootTheme(mode, options = {}) {
49
+ const root = getThemeRoot();
50
+ if (!(root instanceof HTMLElement)) {
51
+ return { mode: "system", resolved: "light" };
52
+ }
53
+
54
+ const nextMode = isThemeMode(mode) ? mode : "system";
55
+ const resolved = resolveThemeMode(nextMode);
56
+ root.setAttribute("data-inc-theme-mode", nextMode);
57
+ root.setAttribute("data-bs-theme", resolved);
58
+ root.style.colorScheme = resolved;
59
+ root.dataset.incThemeModeState = nextMode;
60
+ root.dataset.incThemeResolved = resolved;
61
+
62
+ if (options.persist !== false) {
63
+ persistThemeMode(nextMode, options.storageKey);
64
+ }
65
+
66
+ if (options.dispatch !== false) {
67
+ dispatchComponentEvent(root, "inc-theme-change", {
68
+ mode: nextMode,
69
+ resolved,
70
+ });
71
+ }
72
+
73
+ return { mode: nextMode, resolved };
74
+ }
75
+
76
+ function getRootThemeState() {
77
+ const root = getThemeRoot();
78
+ if (!(root instanceof HTMLElement)) {
79
+ return { mode: "system", resolved: "light" };
80
+ }
81
+
82
+ const configuredMode = root.getAttribute("data-inc-theme-mode")
83
+ || root.dataset.incThemeMode
84
+ || getStoredThemeMode()
85
+ || "system";
86
+ const mode = isThemeMode(configuredMode) ? configuredMode : "system";
87
+
88
+ return {
89
+ mode,
90
+ resolved: resolveThemeMode(mode),
91
+ };
92
+ }
93
+
94
+ function getLegacyThemeBridge() {
95
+ if (typeof window === "undefined") {
96
+ return null;
97
+ }
98
+
99
+ const legacy = window.IncTheme;
100
+ if (!legacy || typeof legacy !== "object") {
101
+ return null;
102
+ }
103
+
104
+ if (typeof legacy.setMode !== "function" || typeof legacy.cycleMode !== "function") {
105
+ return null;
106
+ }
107
+
108
+ return legacy;
109
+ }
110
+
111
+ function createThemeController(options = {}) {
112
+ const storageKey = options.storageKey || DEFAULT_STORAGE_KEY;
113
+ const preferLegacyBridge = options.preferLegacyBridge !== false;
114
+ let state = getRootThemeState();
115
+
116
+ function apply(mode, applyOptions = {}) {
117
+ const legacy = preferLegacyBridge ? getLegacyThemeBridge() : null;
118
+ if (legacy && applyOptions.useLegacyBridge !== false) {
119
+ legacy.setMode(mode);
120
+ state = {
121
+ mode: legacy.getMode(),
122
+ resolved: legacy.getResolvedTheme(),
123
+ };
124
+ return state;
125
+ }
126
+
127
+ state = applyRootTheme(mode, {
128
+ storageKey,
129
+ persist: applyOptions.persist,
130
+ dispatch: applyOptions.dispatch,
131
+ });
132
+ return state;
133
+ }
134
+
135
+ return {
136
+ getMode() {
137
+ return state.mode;
138
+ },
139
+ getResolvedTheme() {
140
+ return state.resolved;
141
+ },
142
+ initialize() {
143
+ const initialMode = getStoredThemeMode(storageKey)
144
+ || getThemeRoot()?.getAttribute("data-inc-theme-mode")
145
+ || "system";
146
+ return apply(initialMode, { persist: false });
147
+ },
148
+ setMode(mode) {
149
+ return apply(mode);
150
+ },
151
+ cycleMode() {
152
+ const index = THEME_MODES.indexOf(state.mode);
153
+ const nextMode = THEME_MODES[(index + 1) % THEME_MODES.length];
154
+ return apply(nextMode);
155
+ },
156
+ syncFromRoot() {
157
+ state = getRootThemeState();
158
+ return state;
159
+ },
160
+ };
161
+ }
162
+
163
+ export {
164
+ DEFAULT_STORAGE_KEY,
165
+ THEME_MODES,
166
+ applyRootTheme,
167
+ createThemeController,
168
+ getRootThemeState,
169
+ getStoredThemeMode,
170
+ isThemeMode,
171
+ resolveSystemTheme,
172
+ resolveThemeMode,
173
+ };