@lancar/lxui 1.0.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/CHANGELOG.md +88 -0
- package/LICENSE +21 -0
- package/README.md +5072 -0
- package/css/base/reset.css +91 -0
- package/css/base/tokens-extended.css +119 -0
- package/css/base/tokens.css +105 -0
- package/css/base/typography.css +35 -0
- package/css/base/utils.css +26 -0
- package/css/components/accordion.css +25 -0
- package/css/components/alert.css +22 -0
- package/css/components/animations.css +26 -0
- package/css/components/avatar.css +38 -0
- package/css/components/back-top.css +32 -0
- package/css/components/badge.css +37 -0
- package/css/components/breadcrumb.css +13 -0
- package/css/components/button.css +103 -0
- package/css/components/callout.css +20 -0
- package/css/components/card.css +42 -0
- package/css/components/carousel.css +31 -0
- package/css/components/chip.css +52 -0
- package/css/components/code-block.css +22 -0
- package/css/components/collapse.css +6 -0
- package/css/components/compat.css +27 -0
- package/css/components/dark-mode.css +35 -0
- package/css/components/divider.css +36 -0
- package/css/components/dropdown.css +39 -0
- package/css/components/empty.css +34 -0
- package/css/components/fab.css +28 -0
- package/css/components/file-drop.css +47 -0
- package/css/components/forms.css +107 -0
- package/css/components/kbd.css +5 -0
- package/css/components/list-group.css +17 -0
- package/css/components/modal.css +50 -0
- package/css/components/nav.css +25 -0
- package/css/components/navbar.css +44 -0
- package/css/components/number-input.css +52 -0
- package/css/components/offcanvas.css +25 -0
- package/css/components/pagination.css +17 -0
- package/css/components/popover.css +12 -0
- package/css/components/progress.css +26 -0
- package/css/components/rating.css +28 -0
- package/css/components/section.css +18 -0
- package/css/components/skeleton.css +19 -0
- package/css/components/spinner.css +38 -0
- package/css/components/stat.css +58 -0
- package/css/components/steps.css +76 -0
- package/css/components/table.css +29 -0
- package/css/components/tag.css +29 -0
- package/css/components/timeline.css +11 -0
- package/css/components/toast.css +14 -0
- package/css/components/toggler.css +20 -0
- package/css/components/tooltip.css +10 -0
- package/css/index.css +59 -0
- package/css/layout/grid.css +71 -0
- package/css/layout/utilities.css +257 -0
- package/js/breakpoint.js +13 -0
- package/js/carousel.js +62 -0
- package/js/clipboard.js +28 -0
- package/js/collapse.js +36 -0
- package/js/counter.js +38 -0
- package/js/dropdown.js +27 -0
- package/js/index.js +19 -0
- package/js/init.js +89 -0
- package/js/modal.js +44 -0
- package/js/number-input.js +44 -0
- package/js/offcanvas.js +28 -0
- package/js/popover.js +39 -0
- package/js/rating.js +39 -0
- package/js/scrollspy.js +24 -0
- package/js/tab.js +18 -0
- package/js/theme.js +9 -0
- package/js/toast.js +73 -0
- package/js/tooltip.js +39 -0
- package/js/utils.js +20 -0
- package/lx-grid.min.css +2 -0
- package/lx-utilities.min.css +2 -0
- package/lxeditor.min.css +2 -0
- package/lxfonts.min.css +2 -0
- package/lxicons.min.css +2 -0
- package/lxmarked.js +276 -0
- package/lxthemes.min.css +2 -0
- package/lxui.bundle.js +540 -0
- package/lxui.bundle.min.js +13 -0
- package/lxui.css +2163 -0
- package/lxui.esm.js +669 -0
- package/lxui.esm.min.js +8 -0
- package/lxui.js +859 -0
- package/lxui.min.css +2 -0
- package/lxui.min.js +7 -0
- package/lxui.rtl.css +2466 -0
- package/lxui.rtl.min.css +2 -0
- package/marked.min.js +69 -0
- package/package.json +183 -0
- package/types/index.d.ts +284 -0
package/lxui.bundle.js
ADDED
|
@@ -0,0 +1,540 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* LxUI v1.0.0 Bundle — Modern CSS Framework
|
|
3
|
+
* Includes: LxUI core + all components
|
|
4
|
+
* https://ui.lancar.id | https://cdn.lancar.id/ui/lxui.bundle.js
|
|
5
|
+
* Copyright (c) 2025 lancar.id — MIT License
|
|
6
|
+
*/
|
|
7
|
+
/*!
|
|
8
|
+
* LxUI v1.0.0 — Modern CSS Framework
|
|
9
|
+
* https://ui.lancar.id | https://cdn.lancar.id/ui/lxui.js
|
|
10
|
+
* Copyright (c) 2025 lancar.id
|
|
11
|
+
* Licensed under MIT
|
|
12
|
+
*/
|
|
13
|
+
(function (global, factory) {
|
|
14
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
15
|
+
typeof define === 'function' && define.amd ? define(factory) :
|
|
16
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.LxUI = factory());
|
|
17
|
+
})(this, function () {
|
|
18
|
+
'use strict';
|
|
19
|
+
|
|
20
|
+
/* ── Helpers ── */
|
|
21
|
+
function qs(sel, ctx) { return (ctx || document).querySelector(sel); }
|
|
22
|
+
function qsa(sel, ctx) { return Array.from((ctx || document).querySelectorAll(sel)); }
|
|
23
|
+
function on(el, ev, fn) { el && el.addEventListener(ev, fn); }
|
|
24
|
+
function off(el, ev, fn) { el && el.removeEventListener(ev, fn); }
|
|
25
|
+
function emit(el, name, detail) {
|
|
26
|
+
el.dispatchEvent(new CustomEvent('lx.' + name, { bubbles: true, cancelable: true, detail }));
|
|
27
|
+
}
|
|
28
|
+
function trap(el) {
|
|
29
|
+
const focusable = qsa('button,a,[href],[tabindex]:not([tabindex="-1"]),input,select,textarea', el)
|
|
30
|
+
.filter(e => !e.disabled && e.offsetParent !== null);
|
|
31
|
+
if (!focusable.length) return;
|
|
32
|
+
const first = focusable[0], last = focusable[focusable.length - 1];
|
|
33
|
+
on(el, 'keydown', e => {
|
|
34
|
+
if (e.key !== 'Tab') return;
|
|
35
|
+
if (e.shiftKey) { if (document.activeElement === first) { e.preventDefault(); last.focus(); } }
|
|
36
|
+
else { if (document.activeElement === last) { e.preventDefault(); first.focus(); } }
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/* ================================================================
|
|
41
|
+
* Modal
|
|
42
|
+
* ================================================================ */
|
|
43
|
+
class Modal {
|
|
44
|
+
constructor(sel, opts = {}) {
|
|
45
|
+
this.el = typeof sel === 'string' ? qs(sel) : sel;
|
|
46
|
+
if (!this.el) return;
|
|
47
|
+
this.opts = Object.assign({ backdrop: true, keyboard: true, focus: true }, opts);
|
|
48
|
+
this._backdrop = null;
|
|
49
|
+
this._prevFocus = null;
|
|
50
|
+
}
|
|
51
|
+
show() {
|
|
52
|
+
if (!this.el) return;
|
|
53
|
+
emit(this.el, 'modal.show');
|
|
54
|
+
this._prevFocus = document.activeElement;
|
|
55
|
+
this._backdrop = document.createElement('div');
|
|
56
|
+
this._backdrop.className = 'lx-modal-backdrop lx-fade lx-show';
|
|
57
|
+
document.body.appendChild(this._backdrop);
|
|
58
|
+
document.body.classList.add('lx-modal-open');
|
|
59
|
+
this.el.classList.add('lx-show');
|
|
60
|
+
this.el.style.display = 'flex';
|
|
61
|
+
this.el.removeAttribute('aria-hidden');
|
|
62
|
+
if (this.opts.focus) trap(this.el);
|
|
63
|
+
if (this.opts.keyboard) {
|
|
64
|
+
this._keyHandler = e => { if (e.key === 'Escape') this.hide(); };
|
|
65
|
+
on(document, 'keydown', this._keyHandler);
|
|
66
|
+
}
|
|
67
|
+
if (this.opts.backdrop) on(this._backdrop, 'click', () => this.hide());
|
|
68
|
+
requestAnimationFrame(() => emit(this.el, 'modal.shown'));
|
|
69
|
+
}
|
|
70
|
+
hide() {
|
|
71
|
+
if (!this.el) return;
|
|
72
|
+
emit(this.el, 'modal.hide');
|
|
73
|
+
this.el.classList.remove('lx-show');
|
|
74
|
+
this.el.style.display = '';
|
|
75
|
+
this.el.setAttribute('aria-hidden', 'true');
|
|
76
|
+
if (this._backdrop) { this._backdrop.remove(); this._backdrop = null; }
|
|
77
|
+
document.body.classList.remove('lx-modal-open');
|
|
78
|
+
if (this._keyHandler) off(document, 'keydown', this._keyHandler);
|
|
79
|
+
if (this._prevFocus) this._prevFocus.focus();
|
|
80
|
+
emit(this.el, 'modal.hidden');
|
|
81
|
+
}
|
|
82
|
+
toggle() { this.el.classList.contains('lx-show') ? this.hide() : this.show(); }
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/* ================================================================
|
|
86
|
+
* Toast
|
|
87
|
+
* ================================================================ */
|
|
88
|
+
const Toast = {
|
|
89
|
+
_container(pos) {
|
|
90
|
+
const id = 'lx-toast-' + pos;
|
|
91
|
+
let c = document.getElementById(id);
|
|
92
|
+
if (!c) {
|
|
93
|
+
c = document.createElement('div');
|
|
94
|
+
c.id = id;
|
|
95
|
+
const posMap = {
|
|
96
|
+
'top-right':'top:1rem;right:1rem', 'top-left':'top:1rem;left:1rem',
|
|
97
|
+
'bottom-right':'bottom:1rem;right:1rem', 'bottom-left':'bottom:1rem;left:1rem',
|
|
98
|
+
'top-center':'top:1rem;left:50%;transform:translateX(-50%)'
|
|
99
|
+
};
|
|
100
|
+
c.setAttribute('style', `position:fixed;z-index:1090;display:flex;flex-direction:column;gap:.5rem;${posMap[pos]||posMap['top-right']}`);
|
|
101
|
+
document.body.appendChild(c);
|
|
102
|
+
}
|
|
103
|
+
return c;
|
|
104
|
+
},
|
|
105
|
+
show(opts = {}) {
|
|
106
|
+
const { message = '', type = 'default', duration = 4000, position = 'top-right', title = '' } = opts;
|
|
107
|
+
const colors = { success:'#22c55e', warning:'#f59e0b', danger:'#ef4444', info:'#06b6d4', default:'#3b82f6' };
|
|
108
|
+
const t = document.createElement('div');
|
|
109
|
+
t.setAttribute('role','alert');
|
|
110
|
+
t.setAttribute('aria-live','assertive');
|
|
111
|
+
t.setAttribute('aria-atomic','true');
|
|
112
|
+
t.style.cssText = `background:var(--surface,#fff);border:1px solid var(--border-default,#e5e7eb);border-radius:8px;box-shadow:0 8px 24px rgba(0,0,0,.12);padding:.875rem 1rem;min-width:280px;max-width:380px;display:flex;align-items:flex-start;gap:.75rem;animation:lxSlideIn .2s ease`;
|
|
113
|
+
const dot = `<span style="width:8px;height:8px;border-radius:50%;background:${colors[type]||colors.default};flex-shrink:0;margin-top:4px"></span>`;
|
|
114
|
+
const body = title ? `<div><strong style="display:block;margin-bottom:2px;font-size:.875rem">${title}</strong><span style="font-size:.875rem;color:var(--text-secondary,#6b7280)">${message}</span></div>` : `<span style="font-size:.875rem;color:var(--text-primary,#111827);flex:1">${message}</span>`;
|
|
115
|
+
const close = `<button onclick="this.closest('[role=alert]').remove()" style="background:none;border:none;cursor:pointer;padding:0;color:var(--text-muted,#9ca3af);font-size:1.125rem;line-height:1;margin-left:auto" aria-label="Tutup">×</button>`;
|
|
116
|
+
t.innerHTML = dot + body + close;
|
|
117
|
+
this._container(position).appendChild(t);
|
|
118
|
+
if (!document.getElementById('lx-toast-style')) {
|
|
119
|
+
const s = document.createElement('style');
|
|
120
|
+
s.id = 'lx-toast-style';
|
|
121
|
+
s.textContent = '@keyframes lxSlideIn{from{opacity:0;transform:translateY(-8px)}to{opacity:1;transform:translateY(0)}}';
|
|
122
|
+
document.head.appendChild(s);
|
|
123
|
+
}
|
|
124
|
+
if (duration > 0) setTimeout(() => { t.style.opacity='0'; t.style.transition='opacity .2s'; setTimeout(()=>t.remove(), 200); }, duration);
|
|
125
|
+
},
|
|
126
|
+
success(msg, opts={}) { this.show({...opts, message:msg, type:'success'}); },
|
|
127
|
+
error(msg, opts={}) { this.show({...opts, message:msg, type:'danger'}); },
|
|
128
|
+
warning(msg, opts={}) { this.show({...opts, message:msg, type:'warning'}); },
|
|
129
|
+
info(msg, opts={}) { this.show({...opts, message:msg, type:'info'}); },
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
/* ================================================================
|
|
133
|
+
* Collapse / Accordion
|
|
134
|
+
* ================================================================ */
|
|
135
|
+
class Collapse {
|
|
136
|
+
constructor(sel) {
|
|
137
|
+
this.el = typeof sel === 'string' ? qs(sel) : sel;
|
|
138
|
+
}
|
|
139
|
+
show() {
|
|
140
|
+
if (!this.el) return;
|
|
141
|
+
emit(this.el, 'collapse.show');
|
|
142
|
+
this.el.style.height = '0px';
|
|
143
|
+
this.el.classList.add('lx-collapsing');
|
|
144
|
+
this.el.classList.remove('lx-collapse', 'lx-show');
|
|
145
|
+
const h = this.el.scrollHeight;
|
|
146
|
+
this.el.style.height = h + 'px';
|
|
147
|
+
this.el.addEventListener('transitionend', () => {
|
|
148
|
+
this.el.classList.remove('lx-collapsing');
|
|
149
|
+
this.el.classList.add('lx-collapse', 'lx-show');
|
|
150
|
+
this.el.style.height = '';
|
|
151
|
+
emit(this.el, 'collapse.shown');
|
|
152
|
+
}, { once: true });
|
|
153
|
+
}
|
|
154
|
+
hide() {
|
|
155
|
+
if (!this.el) return;
|
|
156
|
+
emit(this.el, 'collapse.hide');
|
|
157
|
+
this.el.style.height = this.el.scrollHeight + 'px';
|
|
158
|
+
this.el.classList.add('lx-collapsing');
|
|
159
|
+
this.el.classList.remove('lx-collapse', 'lx-show');
|
|
160
|
+
requestAnimationFrame(() => { this.el.style.height = '0px'; });
|
|
161
|
+
this.el.addEventListener('transitionend', () => {
|
|
162
|
+
this.el.classList.remove('lx-collapsing');
|
|
163
|
+
this.el.classList.add('lx-collapse');
|
|
164
|
+
this.el.style.height = '';
|
|
165
|
+
emit(this.el, 'collapse.hidden');
|
|
166
|
+
}, { once: true });
|
|
167
|
+
}
|
|
168
|
+
toggle() { this.el && this.el.classList.contains('lx-show') ? this.hide() : this.show(); }
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/* ================================================================
|
|
172
|
+
* Dropdown
|
|
173
|
+
* ================================================================ */
|
|
174
|
+
class Dropdown {
|
|
175
|
+
constructor(trigger) {
|
|
176
|
+
this.trigger = typeof trigger === 'string' ? qs(trigger) : trigger;
|
|
177
|
+
this.menu = this.trigger && this.trigger.nextElementSibling;
|
|
178
|
+
this._outside = e => { if (!this.trigger.closest('.lx-dropdown').contains(e.target)) this.hide(); };
|
|
179
|
+
}
|
|
180
|
+
show() {
|
|
181
|
+
if (!this.menu) return;
|
|
182
|
+
emit(this.trigger, 'dropdown.show');
|
|
183
|
+
this.menu.classList.add('lx-show');
|
|
184
|
+
this.trigger.setAttribute('aria-expanded', 'true');
|
|
185
|
+
setTimeout(() => on(document, 'click', this._outside), 0);
|
|
186
|
+
emit(this.trigger, 'dropdown.shown');
|
|
187
|
+
}
|
|
188
|
+
hide() {
|
|
189
|
+
if (!this.menu) return;
|
|
190
|
+
emit(this.trigger, 'dropdown.hide');
|
|
191
|
+
this.menu.classList.remove('lx-show');
|
|
192
|
+
this.trigger.setAttribute('aria-expanded', 'false');
|
|
193
|
+
off(document, 'click', this._outside);
|
|
194
|
+
emit(this.trigger, 'dropdown.hidden');
|
|
195
|
+
}
|
|
196
|
+
toggle() { this.menu && this.menu.classList.contains('lx-show') ? this.hide() : this.show(); }
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/* ================================================================
|
|
200
|
+
* Offcanvas / Drawer
|
|
201
|
+
* ================================================================ */
|
|
202
|
+
class Offcanvas {
|
|
203
|
+
constructor(sel) {
|
|
204
|
+
this.el = typeof sel === 'string' ? qs(sel) : sel;
|
|
205
|
+
this._backdrop = null;
|
|
206
|
+
}
|
|
207
|
+
show() {
|
|
208
|
+
if (!this.el) return;
|
|
209
|
+
this._backdrop = document.createElement('div');
|
|
210
|
+
this._backdrop.className = 'lx-offcanvas-backdrop';
|
|
211
|
+
this._backdrop.style.cssText = 'position:fixed;inset:0;z-index:1039;background:rgba(0,0,0,.5)';
|
|
212
|
+
document.body.appendChild(this._backdrop);
|
|
213
|
+
document.body.style.overflow = 'hidden';
|
|
214
|
+
this.el.classList.add('lx-show');
|
|
215
|
+
this.el.removeAttribute('aria-hidden');
|
|
216
|
+
trap(this.el);
|
|
217
|
+
on(this._backdrop, 'click', () => this.hide());
|
|
218
|
+
on(document, 'keydown', this._esc = e => { if (e.key === 'Escape') this.hide(); });
|
|
219
|
+
}
|
|
220
|
+
hide() {
|
|
221
|
+
if (!this.el) return;
|
|
222
|
+
this.el.classList.remove('lx-show');
|
|
223
|
+
this.el.setAttribute('aria-hidden', 'true');
|
|
224
|
+
if (this._backdrop) { this._backdrop.remove(); this._backdrop = null; }
|
|
225
|
+
document.body.style.overflow = '';
|
|
226
|
+
off(document, 'keydown', this._esc);
|
|
227
|
+
}
|
|
228
|
+
toggle() { this.el && this.el.classList.contains('lx-show') ? this.hide() : this.show(); }
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/* ================================================================
|
|
232
|
+
* Tooltip
|
|
233
|
+
* ================================================================ */
|
|
234
|
+
class Tooltip {
|
|
235
|
+
constructor(el, opts = {}) {
|
|
236
|
+
this.el = typeof el === 'string' ? qs(el) : el;
|
|
237
|
+
if (!this.el) return;
|
|
238
|
+
this.opts = Object.assign({ placement: 'top', trigger: 'hover', html: false, delay: { show: 0, hide: 0 } }, opts);
|
|
239
|
+
this._tip = null;
|
|
240
|
+
this._attach();
|
|
241
|
+
}
|
|
242
|
+
_attach() {
|
|
243
|
+
const show = () => { clearTimeout(this._hideTimer); this._showTimer = setTimeout(() => this._show(), this.opts.delay.show); };
|
|
244
|
+
const hide = () => { clearTimeout(this._showTimer); this._hideTimer = setTimeout(() => this._hide(), this.opts.delay.hide); };
|
|
245
|
+
if (this.opts.trigger.includes('hover')) { on(this.el, 'mouseenter', show); on(this.el, 'mouseleave', hide); }
|
|
246
|
+
if (this.opts.trigger.includes('focus')) { on(this.el, 'focusin', show); on(this.el, 'focusout', hide); }
|
|
247
|
+
}
|
|
248
|
+
_show() {
|
|
249
|
+
const text = this.el.getAttribute('title') || this.el.dataset.lxOrigTitle || '';
|
|
250
|
+
if (!text) return;
|
|
251
|
+
if (this.el.getAttribute('title')) { this.el.dataset.lxOrigTitle = text; this.el.removeAttribute('title'); }
|
|
252
|
+
this._tip = document.createElement('div');
|
|
253
|
+
this._tip.className = 'lx-tooltip lx-tooltip-' + this.opts.placement;
|
|
254
|
+
this._tip.setAttribute('role','tooltip');
|
|
255
|
+
this._tip.style.cssText = 'position:absolute;z-index:1080;padding:4px 8px;background:rgba(0,0,0,.85);color:#fff;border-radius:4px;font-size:.75rem;white-space:nowrap;pointer-events:none';
|
|
256
|
+
this._tip.textContent = text;
|
|
257
|
+
document.body.appendChild(this._tip);
|
|
258
|
+
const r = this.el.getBoundingClientRect(), t = this._tip.getBoundingClientRect(), s = window.scrollY;
|
|
259
|
+
const p = this.opts.placement;
|
|
260
|
+
let top = 0, left = 0;
|
|
261
|
+
if (p === 'top') { top = r.top + s - t.height - 6; left = r.left + (r.width - t.width) / 2; }
|
|
262
|
+
else if (p === 'bottom') { top = r.bottom + s + 6; left = r.left + (r.width - t.width) / 2; }
|
|
263
|
+
else if (p === 'left') { top = r.top + s + (r.height - t.height) / 2; left = r.left - t.width - 6; }
|
|
264
|
+
else { top = r.top + s + (r.height - t.height) / 2; left = r.right + 6; }
|
|
265
|
+
this._tip.style.top = top + 'px';
|
|
266
|
+
this._tip.style.left = left + 'px';
|
|
267
|
+
}
|
|
268
|
+
_hide() { if (this._tip) { this._tip.remove(); this._tip = null; } }
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/* ================================================================
|
|
272
|
+
* Popover
|
|
273
|
+
* ================================================================ */
|
|
274
|
+
class Popover {
|
|
275
|
+
constructor(el, opts = {}) {
|
|
276
|
+
this.el = typeof el === 'string' ? qs(el) : el;
|
|
277
|
+
if (!this.el) return;
|
|
278
|
+
this.opts = Object.assign({ placement: 'top', trigger: 'click', html: false }, opts);
|
|
279
|
+
this._pop = null;
|
|
280
|
+
const toggle = () => this._pop ? this._hide() : this._show();
|
|
281
|
+
if (this.opts.trigger.includes('click')) on(this.el, 'click', toggle);
|
|
282
|
+
}
|
|
283
|
+
_show() {
|
|
284
|
+
const title = this.el.dataset.lxTitle || '';
|
|
285
|
+
const content = this.el.dataset.lxContent || '';
|
|
286
|
+
this._pop = document.createElement('div');
|
|
287
|
+
this._pop.className = 'lx-popover';
|
|
288
|
+
this._pop.setAttribute('role','tooltip');
|
|
289
|
+
this._pop.style.cssText = 'position:absolute;z-index:1070;background:var(--surface,#fff);border:1px solid var(--border-default,#e5e7eb);border-radius:8px;box-shadow:0 8px 24px rgba(0,0,0,.12);padding:.75rem 1rem;min-width:200px;max-width:300px';
|
|
290
|
+
this._pop.innerHTML = (title ? `<strong style="display:block;margin-bottom:.5rem;font-size:.875rem">${title}</strong>` : '') + `<p style="margin:0;font-size:.875rem;color:var(--text-secondary,#6b7280)">${content}</p>`;
|
|
291
|
+
document.body.appendChild(this._pop);
|
|
292
|
+
const r = this.el.getBoundingClientRect(), s = window.scrollY;
|
|
293
|
+
this._pop.style.top = (r.bottom + s + 8) + 'px';
|
|
294
|
+
this._pop.style.left = r.left + 'px';
|
|
295
|
+
setTimeout(() => on(document, 'click', this._outside = e => { if (!this.el.contains(e.target) && !this._pop?.contains(e.target)) this._hide(); }), 0);
|
|
296
|
+
}
|
|
297
|
+
_hide() { if (this._pop) { this._pop.remove(); this._pop = null; off(document, 'click', this._outside); } }
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/* ================================================================
|
|
301
|
+
* Scrollspy
|
|
302
|
+
* ================================================================ */
|
|
303
|
+
class Scrollspy {
|
|
304
|
+
constructor(el, opts = {}) {
|
|
305
|
+
this.el = typeof el === 'string' ? qs(el) : el;
|
|
306
|
+
if (!this.el) return;
|
|
307
|
+
this.opts = Object.assign({ offset: 70 }, opts);
|
|
308
|
+
const targetSel = this.el.dataset.lxTarget;
|
|
309
|
+
this.nav = targetSel ? qs(targetSel) : null;
|
|
310
|
+
this._update = this._update.bind(this);
|
|
311
|
+
on(this.el === document.body ? window : this.el, 'scroll', this._update);
|
|
312
|
+
this._update();
|
|
313
|
+
}
|
|
314
|
+
_update() {
|
|
315
|
+
if (!this.nav) return;
|
|
316
|
+
const links = qsa('a[href^="#"]', this.nav);
|
|
317
|
+
const scrollTop = (this.el === document.body ? window.scrollY : this.el.scrollTop) + this.opts.offset;
|
|
318
|
+
let active = null;
|
|
319
|
+
links.forEach(a => {
|
|
320
|
+
const target = qs(a.getAttribute('href'));
|
|
321
|
+
if (target && target.offsetTop <= scrollTop) active = a;
|
|
322
|
+
});
|
|
323
|
+
links.forEach(a => a.classList.remove('lx-active'));
|
|
324
|
+
if (active) active.classList.add('lx-active');
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/* ================================================================
|
|
329
|
+
* Tabs
|
|
330
|
+
* ================================================================ */
|
|
331
|
+
class Tab {
|
|
332
|
+
constructor(trigger) {
|
|
333
|
+
this.trigger = typeof trigger === 'string' ? qs(trigger) : trigger;
|
|
334
|
+
}
|
|
335
|
+
show() {
|
|
336
|
+
if (!this.trigger) return;
|
|
337
|
+
const targetSel = this.trigger.dataset.lxTarget;
|
|
338
|
+
const target = targetSel ? qs(targetSel) : null;
|
|
339
|
+
if (!target) return;
|
|
340
|
+
const tablist = this.trigger.closest('[role="tablist"]') || this.trigger.parentElement.parentElement;
|
|
341
|
+
qsa('.lx-nav-link, .lx-tab-item', tablist).forEach(t => { t.classList.remove('lx-active'); t.setAttribute('aria-selected','false'); });
|
|
342
|
+
qsa('.lx-tab-pane', target.parentElement).forEach(p => p.classList.remove('lx-active', 'lx-show'));
|
|
343
|
+
this.trigger.classList.add('lx-active');
|
|
344
|
+
this.trigger.setAttribute('aria-selected','true');
|
|
345
|
+
target.classList.add('lx-active', 'lx-show');
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/* ================================================================
|
|
350
|
+
* Carousel
|
|
351
|
+
* ================================================================ */
|
|
352
|
+
class Carousel {
|
|
353
|
+
constructor(sel, opts = {}) {
|
|
354
|
+
this.el = typeof sel === 'string' ? qs(sel) : sel;
|
|
355
|
+
if (!this.el) return;
|
|
356
|
+
this.opts = Object.assign({ interval: 5000, pause: 'hover', wrap: true, touch: true }, opts);
|
|
357
|
+
this.items = qsa('.lx-carousel-item', this.el);
|
|
358
|
+
this.current = this.items.findIndex(i => i.classList.contains('lx-active'));
|
|
359
|
+
if (this.current < 0) { this.current = 0; this.items[0]?.classList.add('lx-active'); }
|
|
360
|
+
this._timer = null;
|
|
361
|
+
if (this.opts.interval) this.cycle();
|
|
362
|
+
if (this.opts.pause === 'hover') { on(this.el, 'mouseenter', () => this.pause()); on(this.el, 'mouseleave', () => this.cycle()); }
|
|
363
|
+
if (this.opts.touch) this._initTouch();
|
|
364
|
+
this._updateIndicators();
|
|
365
|
+
}
|
|
366
|
+
_go(idx) {
|
|
367
|
+
const n = this.items.length;
|
|
368
|
+
if (!this.opts.wrap && (idx < 0 || idx >= n)) return;
|
|
369
|
+
this.current = ((idx % n) + n) % n;
|
|
370
|
+
this.items.forEach((item, i) => item.classList.toggle('lx-active', i === this.current));
|
|
371
|
+
this._updateIndicators();
|
|
372
|
+
}
|
|
373
|
+
_updateIndicators() {
|
|
374
|
+
qsa('.lx-carousel-indicators button, .lx-carousel-indicators [data-lx-slide-to]', this.el).forEach((btn, i) => {
|
|
375
|
+
btn.classList.toggle('lx-active', i === this.current);
|
|
376
|
+
btn.setAttribute('aria-current', i === this.current ? 'true' : 'false');
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
next() { this._go(this.current + 1); }
|
|
380
|
+
prev() { this._go(this.current - 1); }
|
|
381
|
+
to(idx) { this._go(idx); }
|
|
382
|
+
cycle() { this.pause(); if (this.opts.interval) this._timer = setInterval(() => this.next(), this.opts.interval); }
|
|
383
|
+
pause() { clearInterval(this._timer); this._timer = null; }
|
|
384
|
+
_initTouch() {
|
|
385
|
+
let startX = 0;
|
|
386
|
+
on(this.el, 'touchstart', e => { startX = e.touches[0].clientX; }, { passive: true });
|
|
387
|
+
on(this.el, 'touchend', e => {
|
|
388
|
+
const dx = e.changedTouches[0].clientX - startX;
|
|
389
|
+
if (Math.abs(dx) > 40) dx > 0 ? this.prev() : this.next();
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/* ================================================================
|
|
395
|
+
* Alert dismiss
|
|
396
|
+
* ================================================================ */
|
|
397
|
+
function initAlerts() {
|
|
398
|
+
on(document, 'click', e => {
|
|
399
|
+
const btn = e.target.closest('[data-lx-dismiss="alert"]');
|
|
400
|
+
if (btn) { const alert = btn.closest('.lx-alert'); if (alert) { alert.style.opacity = '0'; alert.style.transition = 'opacity .15s'; setTimeout(() => alert.remove(), 150); } }
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/* ================================================================
|
|
405
|
+
* Breakpoint utilities
|
|
406
|
+
* ================================================================ */
|
|
407
|
+
const breakpoint = {
|
|
408
|
+
_bp: { xs: 0, sm: 640, md: 768, lg: 1024, xl: 1280, '2xl': 1536 },
|
|
409
|
+
current() {
|
|
410
|
+
const w = window.innerWidth;
|
|
411
|
+
return Object.entries(this._bp).reverse().find(([, v]) => w >= v)?.[0] || 'xs';
|
|
412
|
+
},
|
|
413
|
+
on(bp, fn) {
|
|
414
|
+
const mq = window.matchMedia(`(min-width: ${this._bp[bp]}px)`);
|
|
415
|
+
mq.addEventListener('change', e => { if (e.matches) fn(); });
|
|
416
|
+
if (mq.matches) fn();
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
|
|
420
|
+
/* ================================================================
|
|
421
|
+
* Theme switcher
|
|
422
|
+
* ================================================================ */
|
|
423
|
+
const theme = {
|
|
424
|
+
set(t, mode) {
|
|
425
|
+
document.documentElement.dataset.theme = t;
|
|
426
|
+
if (mode) document.documentElement.dataset.mode = mode;
|
|
427
|
+
},
|
|
428
|
+
setMode(mode) { document.documentElement.dataset.mode = mode; },
|
|
429
|
+
toggle() {
|
|
430
|
+
const cur = document.documentElement.dataset.mode || 'light';
|
|
431
|
+
this.setMode(cur === 'dark' ? 'light' : 'dark');
|
|
432
|
+
},
|
|
433
|
+
current() { return { theme: document.documentElement.dataset.theme, mode: document.documentElement.dataset.mode }; },
|
|
434
|
+
save(t, mode) { this.set(t, mode); localStorage.setItem('lx-theme', t); if (mode) localStorage.setItem('lx-mode', mode); },
|
|
435
|
+
restore() {
|
|
436
|
+
const t = localStorage.getItem('lx-theme'); const m = localStorage.getItem('lx-mode');
|
|
437
|
+
if (t) this.set(t, m || undefined);
|
|
438
|
+
}
|
|
439
|
+
};
|
|
440
|
+
|
|
441
|
+
/* ================================================================
|
|
442
|
+
* Data-attribute bridge (no-JS approach)
|
|
443
|
+
* ================================================================ */
|
|
444
|
+
function initDataBridge() {
|
|
445
|
+
on(document, 'click', e => {
|
|
446
|
+
const el = e.target.closest('[data-lx-toggle], [data-lx-dismiss], [data-lx-slide], [data-lx-slide-to]');
|
|
447
|
+
if (!el) return;
|
|
448
|
+
const toggle = el.dataset.lxToggle;
|
|
449
|
+
const dismiss = el.dataset.lxDismiss;
|
|
450
|
+
const target = el.dataset.lxTarget ? qs(el.dataset.lxTarget) : null;
|
|
451
|
+
|
|
452
|
+
if (dismiss === 'modal') { const m = el.closest('.lx-modal'); if (m) new Modal(m).hide(); }
|
|
453
|
+
else if (dismiss === 'offcanvas') { const o = el.closest('.lx-offcanvas'); if (o) new Offcanvas(o).hide(); }
|
|
454
|
+
else if (dismiss === 'alert') { const a = el.closest('.lx-alert'); if (a) { a.style.opacity='0'; a.style.transition='opacity .15s'; setTimeout(()=>a.remove(),150); } }
|
|
455
|
+
else if (dismiss === 'toast') { const t = el.closest('.lx-toast'); if (t) { t.style.opacity='0'; t.style.transition='opacity .15s'; setTimeout(()=>t.remove(),150); } }
|
|
456
|
+
|
|
457
|
+
if (toggle === 'modal' && target) { e.preventDefault(); new Modal(target).toggle(); }
|
|
458
|
+
else if (toggle === 'collapse' && target) { e.preventDefault(); new Collapse(target).toggle(); const expanded = target.classList.contains('lx-show'); el.setAttribute('aria-expanded', (!expanded).toString()); }
|
|
459
|
+
else if (toggle === 'accordion' && target) {
|
|
460
|
+
e.preventDefault();
|
|
461
|
+
const isOpen = target.classList.contains('lx-show');
|
|
462
|
+
const accordion = el.closest('.lx-accordion');
|
|
463
|
+
if (accordion) {
|
|
464
|
+
qsa('.lx-accordion-body.lx-show', accordion).forEach(b => { if (b !== target) new Collapse(b).hide(); });
|
|
465
|
+
qsa('.lx-accordion-trigger', accordion).forEach(t => { if (t !== el) { t.classList.remove('lx-active'); t.setAttribute('aria-expanded','false'); } });
|
|
466
|
+
}
|
|
467
|
+
new Collapse(target)[isOpen ? 'hide' : 'show']();
|
|
468
|
+
el.classList.toggle('lx-active', !isOpen);
|
|
469
|
+
el.setAttribute('aria-expanded', (!isOpen).toString());
|
|
470
|
+
}
|
|
471
|
+
else if (toggle === 'dropdown') { e.preventDefault(); e.stopPropagation(); new Dropdown(el).toggle(); }
|
|
472
|
+
else if (toggle === 'offcanvas' && target) { e.preventDefault(); new Offcanvas(target).toggle(); }
|
|
473
|
+
else if (toggle === 'tab' && target) { e.preventDefault(); new Tab(el).show(); }
|
|
474
|
+
else if (toggle === 'popover') { /* handled by Popover instance */ }
|
|
475
|
+
|
|
476
|
+
const slideTo = el.dataset.lxSlideTo;
|
|
477
|
+
const slideDir = el.dataset.lxSlide;
|
|
478
|
+
if (slideTo !== undefined || slideDir) {
|
|
479
|
+
const carouselEl = qs(el.dataset.lxTarget) || el.closest('.lx-carousel');
|
|
480
|
+
if (carouselEl && carouselEl._lxCarousel) {
|
|
481
|
+
if (slideDir === 'next') carouselEl._lxCarousel.next();
|
|
482
|
+
else if (slideDir === 'prev') carouselEl._lxCarousel.prev();
|
|
483
|
+
else if (slideTo !== undefined) carouselEl._lxCarousel.to(parseInt(slideTo));
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
/* ================================================================
|
|
490
|
+
* Scrollspy auto-init
|
|
491
|
+
* ================================================================ */
|
|
492
|
+
function initScrollspy() {
|
|
493
|
+
qsa('[data-lx-spy="scroll"]').forEach(el => new Scrollspy(el));
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/* ================================================================
|
|
497
|
+
* Tooltip auto-init
|
|
498
|
+
* ================================================================ */
|
|
499
|
+
function initTooltips() {
|
|
500
|
+
qsa('[data-lx-toggle="tooltip"]').forEach(el => new Tooltip(el, {
|
|
501
|
+
placement: el.dataset.lxPlacement || 'top',
|
|
502
|
+
trigger: 'hover focus',
|
|
503
|
+
delay: { show: 100, hide: 0 }
|
|
504
|
+
}));
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
/* ================================================================
|
|
508
|
+
* Carousel auto-init
|
|
509
|
+
* ================================================================ */
|
|
510
|
+
function initCarousels() {
|
|
511
|
+
qsa('.lx-carousel').forEach(el => {
|
|
512
|
+
const c = new Carousel(el, { interval: parseInt(el.dataset.lxInterval) || 5000 });
|
|
513
|
+
el._lxCarousel = c;
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
/* ================================================================
|
|
518
|
+
* LxUI.init() — initialize everything
|
|
519
|
+
* ================================================================ */
|
|
520
|
+
function init() {
|
|
521
|
+
initDataBridge();
|
|
522
|
+
initAlerts();
|
|
523
|
+
initScrollspy();
|
|
524
|
+
initTooltips();
|
|
525
|
+
initCarousels();
|
|
526
|
+
theme.restore();
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
if (document.readyState === 'loading') { on(document, 'DOMContentLoaded', init); }
|
|
530
|
+
else { init(); }
|
|
531
|
+
|
|
532
|
+
return {
|
|
533
|
+
init,
|
|
534
|
+
Modal, Toast, Collapse, Dropdown, Offcanvas, Tooltip, Popover, Tab, Carousel, Scrollspy,
|
|
535
|
+
breakpoint, theme,
|
|
536
|
+
LxToast: Toast,
|
|
537
|
+
version: '1.0.0',
|
|
538
|
+
homepage: 'https://ui.lancar.id'
|
|
539
|
+
};
|
|
540
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* LxUI v1.0.0 Bundle — Modern CSS Framework
|
|
3
|
+
* Includes: LxUI core + all components
|
|
4
|
+
* https://ui.lancar.id | https://cdn.lancar.id/ui/lxui.bundle.js
|
|
5
|
+
* Copyright (c) 2025 lancar.id — MIT License
|
|
6
|
+
*/
|
|
7
|
+
/*!
|
|
8
|
+
* LxUI v1.0.0 — Modern CSS Framework
|
|
9
|
+
* https://ui.lancar.id | https://cdn.lancar.id/ui/lxui.js
|
|
10
|
+
* Copyright (c) 2025 lancar.id
|
|
11
|
+
* Licensed under MIT
|
|
12
|
+
*/
|
|
13
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).LxUI=e()}(this,function(){"use strict";function t(t,e){return(e||document).querySelector(t)}function e(t,e){return Array.from((e||document).querySelectorAll(t))}function s(t,e,s){t&&t.addEventListener(e,s)}function i(t,e,s){t&&t.removeEventListener(e,s)}function o(t,e,s){t.dispatchEvent(new CustomEvent("lx."+e,{bubbles:!0,cancelable:!0,detail:s}))}function l(t){const i=e('button,a,[href],[tabindex]:not([tabindex="-1"]),input,select,textarea',t).filter(t=>!t.disabled&&null!==t.offsetParent);if(!i.length)return;const o=i[0],l=i[i.length-1];s(t,"keydown",t=>{"Tab"===t.key&&(t.shiftKey?document.activeElement===o&&(t.preventDefault(),l.focus()):document.activeElement===l&&(t.preventDefault(),o.focus()))})}class a{constructor(e,s={}){this.el="string"==typeof e?t(e):e,this.el&&(this.opts=Object.assign({backdrop:!0,keyboard:!0,focus:!0},s),this._backdrop=null,this._prevFocus=null)}show(){this.el&&(o(this.el,"modal.show"),this._prevFocus=document.activeElement,this._backdrop=document.createElement("div"),this._backdrop.className="lx-modal-backdrop lx-fade lx-show",document.body.appendChild(this._backdrop),document.body.classList.add("lx-modal-open"),this.el.classList.add("lx-show"),this.el.style.display="flex",this.el.removeAttribute("aria-hidden"),this.opts.focus&&l(this.el),this.opts.keyboard&&(this._keyHandler=t=>{"Escape"===t.key&&this.hide()},s(document,"keydown",this._keyHandler)),this.opts.backdrop&&s(this._backdrop,"click",()=>this.hide()),requestAnimationFrame(()=>o(this.el,"modal.shown")))}hide(){this.el&&(o(this.el,"modal.hide"),this.el.classList.remove("lx-show"),this.el.style.display="",this.el.setAttribute("aria-hidden","true"),this._backdrop&&(this._backdrop.remove(),this._backdrop=null),document.body.classList.remove("lx-modal-open"),this._keyHandler&&i(document,"keydown",this._keyHandler),this._prevFocus&&this._prevFocus.focus(),o(this.el,"modal.hidden"))}toggle(){this.el.classList.contains("lx-show")?this.hide():this.show()}}const n={_container(t){const e="lx-toast-"+t;let s=document.getElementById(e);if(!s){s=document.createElement("div"),s.id=e;const i={"top-right":"top:1rem;right:1rem","top-left":"top:1rem;left:1rem","bottom-right":"bottom:1rem;right:1rem","bottom-left":"bottom:1rem;left:1rem","top-center":"top:1rem;left:50%;transform:translateX(-50%)"};s.setAttribute("style",`position:fixed;z-index:1090;display:flex;flex-direction:column;gap:.5rem;${i[t]||i["top-right"]}`),document.body.appendChild(s)}return s},show(t={}){const{message:e="",type:s="default",duration:i=4e3,position:o="top-right",title:l=""}=t,a={success:"#22c55e",warning:"#f59e0b",danger:"#ef4444",info:"#06b6d4",default:"#3b82f6"},n=document.createElement("div");if(n.setAttribute("role","alert"),n.setAttribute("aria-live","assertive"),n.setAttribute("aria-atomic","true"),n.style.cssText="background:var(--surface,#fff);border:1px solid var(--border-default,#e5e7eb);border-radius:8px;box-shadow:0 8px 24px rgba(0,0,0,.12);padding:.875rem 1rem;min-width:280px;max-width:380px;display:flex;align-items:flex-start;gap:.75rem;animation:lxSlideIn .2s ease",n.innerHTML=`<span style="width:8px;height:8px;border-radius:50%;background:${a[s]||a.default};flex-shrink:0;margin-top:4px"></span>`+(l?`<div><strong style="display:block;margin-bottom:2px;font-size:.875rem">${l}</strong><span style="font-size:.875rem;color:var(--text-secondary,#6b7280)">${e}</span></div>`:`<span style="font-size:.875rem;color:var(--text-primary,#111827);flex:1">${e}</span>`)+'<button onclick="this.closest(\'[role=alert]\').remove()" style="background:none;border:none;cursor:pointer;padding:0;color:var(--text-muted,#9ca3af);font-size:1.125rem;line-height:1;margin-left:auto" aria-label="Tutup">×</button>',this._container(o).appendChild(n),!document.getElementById("lx-toast-style")){const t=document.createElement("style");t.id="lx-toast-style",t.textContent="@keyframes lxSlideIn{from{opacity:0;transform:translateY(-8px)}to{opacity:1;transform:translateY(0)}}",document.head.appendChild(t)}i>0&&setTimeout(()=>{n.style.opacity="0",n.style.transition="opacity .2s",setTimeout(()=>n.remove(),200)},i)},success(t,e={}){this.show({...e,message:t,type:"success"})},error(t,e={}){this.show({...e,message:t,type:"danger"})},warning(t,e={}){this.show({...e,message:t,type:"warning"})},info(t,e={}){this.show({...e,message:t,type:"info"})}};class r{constructor(e){this.el="string"==typeof e?t(e):e}show(){this.el&&(o(this.el,"collapse.show"),this.el.style.height="0px",this.el.classList.add("lx-collapsing"),this.el.classList.remove("lx-collapse","lx-show"),this.el.style.height=this.el.scrollHeight+"px",this.el.addEventListener("transitionend",()=>{this.el.classList.remove("lx-collapsing"),this.el.classList.add("lx-collapse","lx-show"),this.el.style.height="",o(this.el,"collapse.shown")},{once:!0}))}hide(){this.el&&(o(this.el,"collapse.hide"),this.el.style.height=this.el.scrollHeight+"px",this.el.classList.add("lx-collapsing"),this.el.classList.remove("lx-collapse","lx-show"),requestAnimationFrame(()=>{this.el.style.height="0px"}),this.el.addEventListener("transitionend",()=>{this.el.classList.remove("lx-collapsing"),this.el.classList.add("lx-collapse"),this.el.style.height="",o(this.el,"collapse.hidden")},{once:!0}))}toggle(){this.el&&this.el.classList.contains("lx-show")?this.hide():this.show()}}class h{constructor(e){this.trigger="string"==typeof e?t(e):e,this.menu=this.trigger&&this.trigger.nextElementSibling,this._outside=t=>{this.trigger.closest(".lx-dropdown").contains(t.target)||this.hide()}}show(){this.menu&&(o(this.trigger,"dropdown.show"),this.menu.classList.add("lx-show"),this.trigger.setAttribute("aria-expanded","true"),setTimeout(()=>s(document,"click",this._outside),0),o(this.trigger,"dropdown.shown"))}hide(){this.menu&&(o(this.trigger,"dropdown.hide"),this.menu.classList.remove("lx-show"),this.trigger.setAttribute("aria-expanded","false"),i(document,"click",this._outside),o(this.trigger,"dropdown.hidden"))}toggle(){this.menu&&this.menu.classList.contains("lx-show")?this.hide():this.show()}}class c{constructor(e){this.el="string"==typeof e?t(e):e,this._backdrop=null}show(){this.el&&(this._backdrop=document.createElement("div"),this._backdrop.className="lx-offcanvas-backdrop",this._backdrop.style.cssText="position:fixed;inset:0;z-index:1039;background:rgba(0,0,0,.5)",document.body.appendChild(this._backdrop),document.body.style.overflow="hidden",this.el.classList.add("lx-show"),this.el.removeAttribute("aria-hidden"),l(this.el),s(this._backdrop,"click",()=>this.hide()),s(document,"keydown",this._esc=t=>{"Escape"===t.key&&this.hide()}))}hide(){this.el&&(this.el.classList.remove("lx-show"),this.el.setAttribute("aria-hidden","true"),this._backdrop&&(this._backdrop.remove(),this._backdrop=null),document.body.style.overflow="",i(document,"keydown",this._esc))}toggle(){this.el&&this.el.classList.contains("lx-show")?this.hide():this.show()}}class d{constructor(e,s={}){this.el="string"==typeof e?t(e):e,this.el&&(this.opts=Object.assign({placement:"top",trigger:"hover",html:!1,delay:{show:0,hide:0}},s),this._tip=null,this._attach())}_attach(){const t=()=>{clearTimeout(this._hideTimer),this._showTimer=setTimeout(()=>this._show(),this.opts.delay.show)},e=()=>{clearTimeout(this._showTimer),this._hideTimer=setTimeout(()=>this._hide(),this.opts.delay.hide)};this.opts.trigger.includes("hover")&&(s(this.el,"mouseenter",t),s(this.el,"mouseleave",e)),this.opts.trigger.includes("focus")&&(s(this.el,"focusin",t),s(this.el,"focusout",e))}_show(){const t=this.el.getAttribute("title")||this.el.dataset.lxOrigTitle||"";if(!t)return;this.el.getAttribute("title")&&(this.el.dataset.lxOrigTitle=t,this.el.removeAttribute("title")),this._tip=document.createElement("div"),this._tip.className="lx-tooltip lx-tooltip-"+this.opts.placement,this._tip.setAttribute("role","tooltip"),this._tip.style.cssText="position:absolute;z-index:1080;padding:4px 8px;background:rgba(0,0,0,.85);color:#fff;border-radius:4px;font-size:.75rem;white-space:nowrap;pointer-events:none",this._tip.textContent=t,document.body.appendChild(this._tip);const e=this.el.getBoundingClientRect(),s=this._tip.getBoundingClientRect(),i=window.scrollY,o=this.opts.placement;let l=0,a=0;"top"===o?(l=e.top+i-s.height-6,a=e.left+(e.width-s.width)/2):"bottom"===o?(l=e.bottom+i+6,a=e.left+(e.width-s.width)/2):"left"===o?(l=e.top+i+(e.height-s.height)/2,a=e.left-s.width-6):(l=e.top+i+(e.height-s.height)/2,a=e.right+6),this._tip.style.top=l+"px",this._tip.style.left=a+"px"}_hide(){this._tip&&(this._tip.remove(),this._tip=null)}}class p{constructor(e,i={}){if(this.el="string"==typeof e?t(e):e,!this.el)return;this.opts=Object.assign({offset:70},i);const o=this.el.dataset.lxTarget;this.nav=o?t(o):null,this._update=this._update.bind(this),s(this.el===document.body?window:this.el,"scroll",this._update),this._update()}_update(){if(!this.nav)return;const s=e('a[href^="#"]',this.nav),i=(this.el===document.body?window.scrollY:this.el.scrollTop)+this.opts.offset;let o=null;s.forEach(e=>{const s=t(e.getAttribute("href"));s&&s.offsetTop<=i&&(o=e)}),s.forEach(t=>t.classList.remove("lx-active")),o&&o.classList.add("lx-active")}}class u{constructor(e){this.trigger="string"==typeof e?t(e):e}show(){if(!this.trigger)return;const s=this.trigger.dataset.lxTarget,i=s?t(s):null;i&&(e(".lx-nav-link, .lx-tab-item",this.trigger.closest('[role="tablist"]')||this.trigger.parentElement.parentElement).forEach(t=>{t.classList.remove("lx-active"),t.setAttribute("aria-selected","false")}),e(".lx-tab-pane",i.parentElement).forEach(t=>t.classList.remove("lx-active","lx-show")),this.trigger.classList.add("lx-active"),this.trigger.setAttribute("aria-selected","true"),i.classList.add("lx-active","lx-show"))}}class m{constructor(i,o={}){this.el="string"==typeof i?t(i):i,this.el&&(this.opts=Object.assign({interval:5e3,pause:"hover",wrap:!0,touch:!0},o),this.items=e(".lx-carousel-item",this.el),this.current=this.items.findIndex(t=>t.classList.contains("lx-active")),this.current<0&&(this.current=0,this.items[0]?.classList.add("lx-active")),this._timer=null,this.opts.interval&&this.cycle(),"hover"===this.opts.pause&&(s(this.el,"mouseenter",()=>this.pause()),s(this.el,"mouseleave",()=>this.cycle())),this.opts.touch&&this._initTouch(),this._updateIndicators())}_go(t){const e=this.items.length;!this.opts.wrap&&(t<0||t>=e)||(this.current=(t%e+e)%e,this.items.forEach((t,e)=>t.classList.toggle("lx-active",e===this.current)),this._updateIndicators())}_updateIndicators(){e(".lx-carousel-indicators button, .lx-carousel-indicators [data-lx-slide-to]",this.el).forEach((t,e)=>{t.classList.toggle("lx-active",e===this.current),t.setAttribute("aria-current",e===this.current?"true":"false")})}next(){this._go(this.current+1)}prev(){this._go(this.current-1)}to(t){this._go(t)}cycle(){this.pause(),this.opts.interval&&(this._timer=setInterval(()=>this.next(),this.opts.interval))}pause(){clearInterval(this._timer),this._timer=null}_initTouch(){let t=0;s(this.el,"touchstart",e=>{t=e.touches[0].clientX}),s(this.el,"touchend",e=>{const s=e.changedTouches[0].clientX-t;Math.abs(s)>40&&(s>0?this.prev():this.next())})}}const g={_bp:{xs:0,sm:640,md:768,lg:1024,xl:1280,"2xl":1536},current(){const t=window.innerWidth;return Object.entries(this._bp).reverse().find(([,e])=>t>=e)?.[0]||"xs"},on(t,e){const s=window.matchMedia(`(min-width: ${this._bp[t]}px)`);s.addEventListener("change",t=>{t.matches&&e()}),s.matches&&e()}},x={set(t,e){document.documentElement.dataset.theme=t,e&&(document.documentElement.dataset.mode=e)},setMode(t){document.documentElement.dataset.mode=t},toggle(){const t=document.documentElement.dataset.mode||"light";this.setMode("dark"===t?"light":"dark")},current:()=>({theme:document.documentElement.dataset.theme,mode:document.documentElement.dataset.mode}),save(t,e){this.set(t,e),localStorage.setItem("lx-theme",t),e&&localStorage.setItem("lx-mode",e)},restore(){const t=localStorage.getItem("lx-theme"),e=localStorage.getItem("lx-mode");t&&this.set(t,e||void 0)}};function f(){s(document,"click",s=>{const i=s.target.closest("[data-lx-toggle], [data-lx-dismiss], [data-lx-slide], [data-lx-slide-to]");if(!i)return;const o=i.dataset.lxToggle,l=i.dataset.lxDismiss,n=i.dataset.lxTarget?t(i.dataset.lxTarget):null;if("modal"===l){const t=i.closest(".lx-modal");t&&new a(t).hide()}else if("offcanvas"===l){const t=i.closest(".lx-offcanvas");t&&new c(t).hide()}else if("alert"===l){const t=i.closest(".lx-alert");t&&(t.style.opacity="0",t.style.transition="opacity .15s",setTimeout(()=>t.remove(),150))}else if("toast"===l){const t=i.closest(".lx-toast");t&&(t.style.opacity="0",t.style.transition="opacity .15s",setTimeout(()=>t.remove(),150))}if("modal"===o&&n)s.preventDefault(),new a(n).toggle();else if("collapse"===o&&n){s.preventDefault(),new r(n).toggle();const t=n.classList.contains("lx-show");i.setAttribute("aria-expanded",(!t).toString())}else if("accordion"===o&&n){s.preventDefault();const t=n.classList.contains("lx-show"),o=i.closest(".lx-accordion");o&&(e(".lx-accordion-body.lx-show",o).forEach(t=>{t!==n&&new r(t).hide()}),e(".lx-accordion-trigger",o).forEach(t=>{t!==i&&(t.classList.remove("lx-active"),t.setAttribute("aria-expanded","false"))})),new r(n)[t?"hide":"show"](),i.classList.toggle("lx-active",!t),i.setAttribute("aria-expanded",(!t).toString())}else"dropdown"===o?(s.preventDefault(),s.stopPropagation(),new h(i).toggle()):"offcanvas"===o&&n?(s.preventDefault(),new c(n).toggle()):"tab"===o&&n&&(s.preventDefault(),new u(i).show());const d=i.dataset.lxSlideTo,p=i.dataset.lxSlide;if(void 0!==d||p){const e=t(i.dataset.lxTarget)||i.closest(".lx-carousel");e&&e._lxCarousel&&("next"===p?e._lxCarousel.next():"prev"===p?e._lxCarousel.prev():void 0!==d&&e._lxCarousel.to(parseInt(d)))}}),s(document,"click",t=>{const e=t.target.closest('[data-lx-dismiss="alert"]');if(e){const t=e.closest(".lx-alert");t&&(t.style.opacity="0",t.style.transition="opacity .15s",setTimeout(()=>t.remove(),150))}}),e('[data-lx-spy="scroll"]').forEach(t=>new p(t)),e('[data-lx-toggle="tooltip"]').forEach(t=>new d(t,{placement:t.dataset.lxPlacement||"top",trigger:"hover focus",delay:{show:100,hide:0}})),e(".lx-carousel").forEach(t=>{const e=new m(t,{interval:parseInt(t.dataset.lxInterval)||5e3});t._lxCarousel=e}),x.restore()}return"loading"===document.readyState?s(document,"DOMContentLoaded",f):f(),{init:f,Modal:a,Toast:n,Collapse:r,Dropdown:h,Offcanvas:c,Tooltip:d,Popover:class{constructor(e,i={}){this.el="string"==typeof e?t(e):e,this.el&&(this.opts=Object.assign({placement:"top",trigger:"click",html:!1},i),this._pop=null,this.opts.trigger.includes("click")&&s(this.el,"click",()=>this._pop?this._hide():this._show()))}_show(){const t=this.el.dataset.lxTitle||"",e=this.el.dataset.lxContent||"";this._pop=document.createElement("div"),this._pop.className="lx-popover",this._pop.setAttribute("role","tooltip"),this._pop.style.cssText="position:absolute;z-index:1070;background:var(--surface,#fff);border:1px solid var(--border-default,#e5e7eb);border-radius:8px;box-shadow:0 8px 24px rgba(0,0,0,.12);padding:.75rem 1rem;min-width:200px;max-width:300px",this._pop.innerHTML=(t?`<strong style="display:block;margin-bottom:.5rem;font-size:.875rem">${t}</strong>`:"")+`<p style="margin:0;font-size:.875rem;color:var(--text-secondary,#6b7280)">${e}</p>`,document.body.appendChild(this._pop);const i=this.el.getBoundingClientRect(),o=window.scrollY;this._pop.style.top=i.bottom+o+8+"px",this._pop.style.left=i.left+"px",setTimeout(()=>s(document,"click",this._outside=t=>{this.el.contains(t.target)||this._pop?.contains(t.target)||this._hide()}),0)}_hide(){this._pop&&(this._pop.remove(),this._pop=null,i(document,"click",this._outside))}},Tab:u,Carousel:m,Scrollspy:p,breakpoint:g,theme:x,LxToast:n,version:"1.0.0",homepage:"https://ui.lancar.id"}});
|