@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.
Files changed (94) hide show
  1. package/CHANGELOG.md +88 -0
  2. package/LICENSE +21 -0
  3. package/README.md +5072 -0
  4. package/css/base/reset.css +91 -0
  5. package/css/base/tokens-extended.css +119 -0
  6. package/css/base/tokens.css +105 -0
  7. package/css/base/typography.css +35 -0
  8. package/css/base/utils.css +26 -0
  9. package/css/components/accordion.css +25 -0
  10. package/css/components/alert.css +22 -0
  11. package/css/components/animations.css +26 -0
  12. package/css/components/avatar.css +38 -0
  13. package/css/components/back-top.css +32 -0
  14. package/css/components/badge.css +37 -0
  15. package/css/components/breadcrumb.css +13 -0
  16. package/css/components/button.css +103 -0
  17. package/css/components/callout.css +20 -0
  18. package/css/components/card.css +42 -0
  19. package/css/components/carousel.css +31 -0
  20. package/css/components/chip.css +52 -0
  21. package/css/components/code-block.css +22 -0
  22. package/css/components/collapse.css +6 -0
  23. package/css/components/compat.css +27 -0
  24. package/css/components/dark-mode.css +35 -0
  25. package/css/components/divider.css +36 -0
  26. package/css/components/dropdown.css +39 -0
  27. package/css/components/empty.css +34 -0
  28. package/css/components/fab.css +28 -0
  29. package/css/components/file-drop.css +47 -0
  30. package/css/components/forms.css +107 -0
  31. package/css/components/kbd.css +5 -0
  32. package/css/components/list-group.css +17 -0
  33. package/css/components/modal.css +50 -0
  34. package/css/components/nav.css +25 -0
  35. package/css/components/navbar.css +44 -0
  36. package/css/components/number-input.css +52 -0
  37. package/css/components/offcanvas.css +25 -0
  38. package/css/components/pagination.css +17 -0
  39. package/css/components/popover.css +12 -0
  40. package/css/components/progress.css +26 -0
  41. package/css/components/rating.css +28 -0
  42. package/css/components/section.css +18 -0
  43. package/css/components/skeleton.css +19 -0
  44. package/css/components/spinner.css +38 -0
  45. package/css/components/stat.css +58 -0
  46. package/css/components/steps.css +76 -0
  47. package/css/components/table.css +29 -0
  48. package/css/components/tag.css +29 -0
  49. package/css/components/timeline.css +11 -0
  50. package/css/components/toast.css +14 -0
  51. package/css/components/toggler.css +20 -0
  52. package/css/components/tooltip.css +10 -0
  53. package/css/index.css +59 -0
  54. package/css/layout/grid.css +71 -0
  55. package/css/layout/utilities.css +257 -0
  56. package/js/breakpoint.js +13 -0
  57. package/js/carousel.js +62 -0
  58. package/js/clipboard.js +28 -0
  59. package/js/collapse.js +36 -0
  60. package/js/counter.js +38 -0
  61. package/js/dropdown.js +27 -0
  62. package/js/index.js +19 -0
  63. package/js/init.js +89 -0
  64. package/js/modal.js +44 -0
  65. package/js/number-input.js +44 -0
  66. package/js/offcanvas.js +28 -0
  67. package/js/popover.js +39 -0
  68. package/js/rating.js +39 -0
  69. package/js/scrollspy.js +24 -0
  70. package/js/tab.js +18 -0
  71. package/js/theme.js +9 -0
  72. package/js/toast.js +73 -0
  73. package/js/tooltip.js +39 -0
  74. package/js/utils.js +20 -0
  75. package/lx-grid.min.css +2 -0
  76. package/lx-utilities.min.css +2 -0
  77. package/lxeditor.min.css +2 -0
  78. package/lxfonts.min.css +2 -0
  79. package/lxicons.min.css +2 -0
  80. package/lxmarked.js +276 -0
  81. package/lxthemes.min.css +2 -0
  82. package/lxui.bundle.js +540 -0
  83. package/lxui.bundle.min.js +13 -0
  84. package/lxui.css +2163 -0
  85. package/lxui.esm.js +669 -0
  86. package/lxui.esm.min.js +8 -0
  87. package/lxui.js +859 -0
  88. package/lxui.min.css +2 -0
  89. package/lxui.min.js +7 -0
  90. package/lxui.rtl.css +2466 -0
  91. package/lxui.rtl.min.css +2 -0
  92. package/marked.min.js +69 -0
  93. package/package.json +183 -0
  94. package/types/index.d.ts +284 -0
package/lxui.esm.js ADDED
@@ -0,0 +1,669 @@
1
+ /*!
2
+ * LxUI v1.0.0 ESM — Modern CSS Framework
3
+ * https://ui.lancar.id
4
+ * Copyright (c) 2025 lancar.id — MIT License
5
+ *
6
+ * ES Module — import { Modal, Toast, theme } from 'lxui'
7
+ */
8
+ 'use strict';
9
+
10
+ /* ── Helpers ── */
11
+ function qs(sel, ctx) { return (ctx || document).querySelector(sel); }
12
+ function qsa(sel, ctx) { return Array.from((ctx || document).querySelectorAll(sel)); }
13
+ function on(el, ev, fn, opts) { el && el.addEventListener(ev, fn, opts); }
14
+ function off(el, ev, fn) { el && el.removeEventListener(ev, fn); }
15
+ function emit(el, name, detail) {
16
+ el.dispatchEvent(new CustomEvent('lx.' + name, { bubbles: true, cancelable: true, detail }));
17
+ }
18
+ function trap(el) {
19
+ const focusable = qsa('button,a,[href],[tabindex]:not([tabindex="-1"]),input,select,textarea', el)
20
+ .filter(e => !e.disabled && e.offsetParent !== null);
21
+ if (!focusable.length) return;
22
+ const first = focusable[0], last = focusable[focusable.length - 1];
23
+ on(el, 'keydown', e => {
24
+ if (e.key !== 'Tab') return;
25
+ if (e.shiftKey) { if (document.activeElement === first) { e.preventDefault(); last.focus(); } }
26
+ else { if (document.activeElement === last) { e.preventDefault(); first.focus(); } }
27
+ });
28
+ }
29
+
30
+ /* ── Modal ── */
31
+ export class Modal {
32
+ constructor(sel, opts = {}) {
33
+ this.el = typeof sel === 'string' ? qs(sel) : sel;
34
+ if (!this.el) return;
35
+ this.opts = Object.assign({ backdrop: true, keyboard: true, focus: true }, opts);
36
+ this._backdrop = null;
37
+ this._prevFocus = null;
38
+ }
39
+ show() {
40
+ if (!this.el) return;
41
+ emit(this.el, 'modal.show');
42
+ this._prevFocus = document.activeElement;
43
+ this._backdrop = document.createElement('div');
44
+ this._backdrop.className = 'lx-modal-backdrop lx-fade lx-show';
45
+ document.body.appendChild(this._backdrop);
46
+ document.body.classList.add('lx-modal-open');
47
+ this.el.classList.add('lx-show');
48
+ this.el.style.display = 'flex';
49
+ this.el.removeAttribute('aria-hidden');
50
+ if (this.opts.focus) trap(this.el);
51
+ if (this.opts.keyboard) {
52
+ this._keyHandler = e => { if (e.key === 'Escape') this.hide(); };
53
+ on(document, 'keydown', this._keyHandler);
54
+ }
55
+ if (this.opts.backdrop) on(this._backdrop, 'click', () => this.hide());
56
+ requestAnimationFrame(() => emit(this.el, 'modal.shown'));
57
+ }
58
+ hide() {
59
+ if (!this.el) return;
60
+ emit(this.el, 'modal.hide');
61
+ this.el.classList.remove('lx-show');
62
+ this.el.style.display = '';
63
+ this.el.setAttribute('aria-hidden', 'true');
64
+ if (this._backdrop) { this._backdrop.remove(); this._backdrop = null; }
65
+ document.body.classList.remove('lx-modal-open');
66
+ if (this._keyHandler) off(document, 'keydown', this._keyHandler);
67
+ if (this._prevFocus) this._prevFocus.focus();
68
+ emit(this.el, 'modal.hidden');
69
+ }
70
+ toggle() { this.el.classList.contains('lx-show') ? this.hide() : this.show(); }
71
+ }
72
+
73
+ /* ── Toast ── */
74
+ export const Toast = {
75
+ _container(pos) {
76
+ const id = 'lx-toast-' + pos;
77
+ let c = document.getElementById(id);
78
+ if (!c) {
79
+ c = document.createElement('div');
80
+ c.id = id;
81
+ const posMap = {
82
+ 'top-right': 'top:1rem;right:1rem',
83
+ 'top-left': 'top:1rem;left:1rem',
84
+ 'bottom-right': 'bottom:1rem;right:1rem',
85
+ 'bottom-left': 'bottom:1rem;left:1rem',
86
+ 'top-center': 'top:1rem;left:50%;transform:translateX(-50%)',
87
+ 'bottom-center':'bottom:1rem;left:50%;transform:translateX(-50%)'
88
+ };
89
+ c.setAttribute('style', `position:fixed;z-index:1090;display:flex;flex-direction:column;gap:.5rem;${posMap[pos] || posMap['top-right']}`);
90
+ document.body.appendChild(c);
91
+ }
92
+ return c;
93
+ },
94
+ show(opts = {}) {
95
+ const { message = '', type = 'default', duration = 4000, position = 'top-right', title = '' } = opts;
96
+ const colors = { success: '#22c55e', warning: '#f59e0b', danger: '#ef4444', info: '#06b6d4', default: '#3b82f6' };
97
+ const t = document.createElement('div');
98
+ t.setAttribute('role', 'alert');
99
+ t.setAttribute('aria-live', 'assertive');
100
+ t.setAttribute('aria-atomic', 'true');
101
+ 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';
102
+ const dot = document.createElement('span');
103
+ dot.style.cssText = 'width:8px;height:8px;border-radius:50%;background:' + (colors[type] || colors.default) + ';flex-shrink:0;margin-top:4px';
104
+ t.appendChild(dot);
105
+ if (title) {
106
+ const wrap = document.createElement('div');
107
+ const strong = document.createElement('strong');
108
+ strong.style.cssText = 'display:block;margin-bottom:2px;font-size:.875rem';
109
+ strong.textContent = title;
110
+ const span = document.createElement('span');
111
+ span.style.cssText = 'font-size:.875rem;color:var(--text-secondary,#6b7280)';
112
+ span.textContent = message;
113
+ wrap.appendChild(strong); wrap.appendChild(span);
114
+ t.appendChild(wrap);
115
+ } else {
116
+ const span = document.createElement('span');
117
+ span.style.cssText = 'font-size:.875rem;color:var(--text-primary,#111827);flex:1';
118
+ span.textContent = message;
119
+ t.appendChild(span);
120
+ }
121
+ const close = document.createElement('button');
122
+ close.style.cssText = 'background:none;border:none;cursor:pointer;padding:0;color:var(--text-muted,#9ca3af);font-size:1.125rem;line-height:1;margin-left:auto';
123
+ close.setAttribute('aria-label', 'Close');
124
+ close.textContent = '×';
125
+ close.addEventListener('click', () => t.remove());
126
+ t.appendChild(close);
127
+ this._container(position).appendChild(t);
128
+ if (!document.getElementById('lx-toast-style')) {
129
+ const s = document.createElement('style');
130
+ s.id = 'lx-toast-style';
131
+ s.textContent = '@keyframes lxSlideIn{from{opacity:0;transform:translateY(-8px)}to{opacity:1;transform:translateY(0)}}';
132
+ document.head.appendChild(s);
133
+ }
134
+ if (duration > 0) setTimeout(() => {
135
+ t.style.opacity = '0'; t.style.transition = 'opacity .2s';
136
+ setTimeout(() => t.remove(), 200);
137
+ }, duration);
138
+ },
139
+ success(msg, opts = {}) { this.show({ ...opts, message: msg, type: 'success' }); },
140
+ error(msg, opts = {}) { this.show({ ...opts, message: msg, type: 'danger' }); },
141
+ warning(msg, opts = {}) { this.show({ ...opts, message: msg, type: 'warning' }); },
142
+ info(msg, opts = {}) { this.show({ ...opts, message: msg, type: 'info' }); },
143
+ };
144
+
145
+ /* ── Collapse ── */
146
+ export class Collapse {
147
+ constructor(sel) { this.el = typeof sel === 'string' ? qs(sel) : sel; }
148
+ show() {
149
+ if (!this.el) return;
150
+ emit(this.el, 'collapse.show');
151
+ this.el.style.height = '0px';
152
+ this.el.classList.add('lx-collapsing');
153
+ this.el.classList.remove('lx-collapse', 'lx-show');
154
+ const h = this.el.scrollHeight;
155
+ this.el.style.height = h + 'px';
156
+ this.el.addEventListener('transitionend', () => {
157
+ this.el.classList.remove('lx-collapsing');
158
+ this.el.classList.add('lx-collapse', 'lx-show');
159
+ this.el.style.height = '';
160
+ emit(this.el, 'collapse.shown');
161
+ }, { once: true });
162
+ }
163
+ hide() {
164
+ if (!this.el) return;
165
+ emit(this.el, 'collapse.hide');
166
+ this.el.style.height = this.el.scrollHeight + 'px';
167
+ this.el.classList.add('lx-collapsing');
168
+ this.el.classList.remove('lx-collapse', 'lx-show');
169
+ requestAnimationFrame(() => { this.el.style.height = '0px'; });
170
+ this.el.addEventListener('transitionend', () => {
171
+ this.el.classList.remove('lx-collapsing');
172
+ this.el.classList.add('lx-collapse');
173
+ this.el.style.height = '';
174
+ emit(this.el, 'collapse.hidden');
175
+ }, { once: true });
176
+ }
177
+ toggle() { this.el && this.el.classList.contains('lx-show') ? this.hide() : this.show(); }
178
+ }
179
+
180
+ /* ── Dropdown ── */
181
+ export class Dropdown {
182
+ constructor(trigger) {
183
+ this.trigger = typeof trigger === 'string' ? qs(trigger) : trigger;
184
+ this.menu = this.trigger && this.trigger.nextElementSibling;
185
+ this._outside = e => { if (!this.trigger.closest('.lx-dropdown').contains(e.target)) this.hide(); };
186
+ }
187
+ show() {
188
+ if (!this.menu) return;
189
+ emit(this.trigger, 'dropdown.show');
190
+ this.menu.classList.add('lx-show');
191
+ this.trigger.setAttribute('aria-expanded', 'true');
192
+ setTimeout(() => on(document, 'click', this._outside), 0);
193
+ emit(this.trigger, 'dropdown.shown');
194
+ }
195
+ hide() {
196
+ if (!this.menu) return;
197
+ emit(this.trigger, 'dropdown.hide');
198
+ this.menu.classList.remove('lx-show');
199
+ this.trigger.setAttribute('aria-expanded', 'false');
200
+ off(document, 'click', this._outside);
201
+ emit(this.trigger, 'dropdown.hidden');
202
+ }
203
+ toggle() { this.menu && this.menu.classList.contains('lx-show') ? this.hide() : this.show(); }
204
+ }
205
+
206
+ /* ── Offcanvas ── */
207
+ export class Offcanvas {
208
+ constructor(sel) { this.el = typeof sel === 'string' ? qs(sel) : sel; this._backdrop = null; }
209
+ show() {
210
+ if (!this.el) return;
211
+ this._backdrop = document.createElement('div');
212
+ this._backdrop.className = 'lx-offcanvas-backdrop';
213
+ this._backdrop.style.cssText = 'position:fixed;inset:0;z-index:1039;background:rgba(0,0,0,.5)';
214
+ document.body.appendChild(this._backdrop);
215
+ document.body.style.overflow = 'hidden';
216
+ this.el.classList.add('lx-show');
217
+ this.el.removeAttribute('aria-hidden');
218
+ trap(this.el);
219
+ on(this._backdrop, 'click', () => this.hide());
220
+ on(document, 'keydown', this._esc = e => { if (e.key === 'Escape') this.hide(); });
221
+ }
222
+ hide() {
223
+ if (!this.el) return;
224
+ this.el.classList.remove('lx-show');
225
+ this.el.setAttribute('aria-hidden', 'true');
226
+ if (this._backdrop) { this._backdrop.remove(); this._backdrop = null; }
227
+ document.body.style.overflow = '';
228
+ off(document, 'keydown', this._esc);
229
+ }
230
+ toggle() { this.el && this.el.classList.contains('lx-show') ? this.hide() : this.show(); }
231
+ }
232
+
233
+ /* ── Tooltip ── */
234
+ export 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', 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
+ /* ── Popover ── */
272
+ export class Popover {
273
+ constructor(el, opts = {}) {
274
+ this.el = typeof el === 'string' ? qs(el) : el;
275
+ if (!this.el) return;
276
+ this.opts = Object.assign({ placement: 'top', trigger: 'click' }, opts);
277
+ this._pop = null;
278
+ const toggle = () => this._pop ? this._hide() : this._show();
279
+ if (this.opts.trigger.includes('click')) on(this.el, 'click', toggle);
280
+ }
281
+ _show() {
282
+ const title = this.el.dataset.lxTitle || '';
283
+ const content = this.el.dataset.lxContent || '';
284
+ this._pop = document.createElement('div');
285
+ this._pop.className = 'lx-popover';
286
+ this._pop.setAttribute('role', 'tooltip');
287
+ 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';
288
+ if (title) {
289
+ const h = document.createElement('strong');
290
+ h.style.cssText = 'display:block;margin-bottom:.5rem;font-size:.875rem';
291
+ h.textContent = title;
292
+ this._pop.appendChild(h);
293
+ }
294
+ const pb = document.createElement('p');
295
+ pb.style.cssText = 'margin:0;font-size:.875rem;color:var(--text-secondary,#6b7280)';
296
+ pb.textContent = content;
297
+ this._pop.appendChild(pb);
298
+ document.body.appendChild(this._pop);
299
+ const r = this.el.getBoundingClientRect(), s = window.scrollY;
300
+ this._pop.style.top = (r.bottom + s + 8) + 'px';
301
+ this._pop.style.left = r.left + 'px';
302
+ setTimeout(() => on(document, 'click', this._outside = e => {
303
+ if (!this.el.contains(e.target) && !this._pop?.contains(e.target)) this._hide();
304
+ }), 0);
305
+ }
306
+ _hide() { if (this._pop) { this._pop.remove(); this._pop = null; off(document, 'click', this._outside); } }
307
+ }
308
+
309
+ /* ── Scrollspy ── */
310
+ export class Scrollspy {
311
+ constructor(el, opts = {}) {
312
+ this.el = typeof el === 'string' ? qs(el) : el;
313
+ if (!this.el) return;
314
+ this.opts = Object.assign({ offset: 70 }, opts);
315
+ const targetSel = this.el.dataset.lxTarget;
316
+ this.nav = targetSel ? qs(targetSel) : null;
317
+ this._update = this._update.bind(this);
318
+ on(this.el === document.body ? window : this.el, 'scroll', this._update);
319
+ this._update();
320
+ }
321
+ _update() {
322
+ if (!this.nav) return;
323
+ const links = qsa('a[href^="#"]', this.nav);
324
+ const scrollTop = (this.el === document.body ? window.scrollY : this.el.scrollTop) + this.opts.offset;
325
+ let active = null;
326
+ links.forEach(a => { const t = qs(a.getAttribute('href')); if (t && t.offsetTop <= scrollTop) active = a; });
327
+ links.forEach(a => a.classList.remove('lx-active'));
328
+ if (active) active.classList.add('lx-active');
329
+ }
330
+ }
331
+
332
+ /* ── Tab ── */
333
+ export class Tab {
334
+ constructor(trigger) { this.trigger = typeof trigger === 'string' ? qs(trigger) : trigger; }
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
+ /* ── Carousel ── */
350
+ export class Carousel {
351
+ constructor(sel, opts = {}) {
352
+ this.el = typeof sel === 'string' ? qs(sel) : sel;
353
+ if (!this.el) return;
354
+ this.opts = Object.assign({ interval: 5000, pause: 'hover', wrap: true, touch: true }, opts);
355
+ this.inner = qs('.lx-carousel-inner', this.el);
356
+ this.items = qsa('.lx-carousel-item', this.el);
357
+ this.current = this.items.findIndex(i => i.classList.contains('lx-active'));
358
+ if (this.current < 0) { this.current = 0; if (this.items[0]) this.items[0].classList.add('lx-active'); }
359
+ this._timer = null;
360
+ this._sliding = false;
361
+ if (this.inner) this._applyTransform(this.current, false);
362
+ if (this.opts.interval) this.cycle();
363
+ if (this.opts.pause === 'hover') { on(this.el, 'mouseenter', () => this.pause()); on(this.el, 'mouseleave', () => this.cycle()); }
364
+ if (this.opts.touch) this._initTouch();
365
+ this._updateIndicators();
366
+ }
367
+ _applyTransform(idx, animate) {
368
+ if (!this.inner) return;
369
+ if (!animate) this.inner.style.transition = 'none';
370
+ this.inner.style.transform = 'translateX(-' + (idx * 100) + '%)';
371
+ if (!animate) { this.inner.getBoundingClientRect(); this.inner.style.transition = ''; }
372
+ }
373
+ _go(idx) {
374
+ const n = this.items.length;
375
+ if (!this.opts.wrap && (idx < 0 || idx >= n)) return;
376
+ if (this._sliding) return;
377
+ this._sliding = true;
378
+ this.current = ((idx % n) + n) % n;
379
+ this.items.forEach((item, i) => item.classList.toggle('lx-active', i === this.current));
380
+ if (this.inner) {
381
+ this._applyTransform(this.current, true);
382
+ this.inner.addEventListener('transitionend', () => { this._sliding = false; emit(this.el, 'carousel.slid'); }, { once: true });
383
+ setTimeout(() => { this._sliding = false; }, 400);
384
+ } else { this._sliding = false; }
385
+ this._updateIndicators();
386
+ emit(this.el, 'carousel.slide');
387
+ }
388
+ _updateIndicators() {
389
+ qsa('.lx-carousel-indicators button, .lx-carousel-indicators [data-lx-slide-to]', this.el).forEach((btn, i) => {
390
+ btn.classList.toggle('lx-active', i === this.current);
391
+ btn.setAttribute('aria-current', i === this.current ? 'true' : 'false');
392
+ });
393
+ }
394
+ next() { this._go(this.current + 1); }
395
+ prev() { this._go(this.current - 1); }
396
+ to(idx) { this._go(idx); }
397
+ cycle() { this.pause(); if (this.opts.interval) this._timer = setInterval(() => this.next(), this.opts.interval); }
398
+ pause() { clearInterval(this._timer); this._timer = null; }
399
+ _initTouch() {
400
+ let startX = 0, startY = 0;
401
+ on(this.el, 'touchstart', e => { startX = e.touches[0].clientX; startY = e.touches[0].clientY; }, { passive: true });
402
+ on(this.el, 'touchend', e => {
403
+ const dx = e.changedTouches[0].clientX - startX;
404
+ const dy = e.changedTouches[0].clientY - startY;
405
+ if (Math.abs(dx) > Math.abs(dy) && Math.abs(dx) > 40) dx > 0 ? this.prev() : this.next();
406
+ });
407
+ }
408
+ }
409
+
410
+ /* ── Clipboard ── */
411
+ export const Clipboard = {
412
+ copy(text) {
413
+ if (navigator.clipboard && window.isSecureContext) return navigator.clipboard.writeText(text);
414
+ const el = document.createElement('textarea');
415
+ el.value = text;
416
+ el.style.cssText = 'position:fixed;top:-9999px;left:-9999px;opacity:0';
417
+ document.body.appendChild(el);
418
+ el.focus(); el.select();
419
+ try { document.execCommand('copy'); } catch (e) {}
420
+ el.remove();
421
+ return Promise.resolve();
422
+ },
423
+ bind(sel, getText) {
424
+ qsa(sel).forEach(btn => {
425
+ on(btn, 'click', async () => {
426
+ const text = typeof getText === 'function' ? getText(btn) : (btn.dataset.lxCopy || btn.textContent);
427
+ await this.copy(text);
428
+ const orig = btn.textContent;
429
+ btn.textContent = btn.dataset.lxCopiedText || 'Copied!';
430
+ btn.classList.add('lx-copied');
431
+ setTimeout(() => { btn.textContent = orig; btn.classList.remove('lx-copied'); }, 2000);
432
+ });
433
+ });
434
+ }
435
+ };
436
+
437
+ /* ── Counter ── */
438
+ export class Counter {
439
+ constructor(el, opts = {}) {
440
+ this.el = typeof el === 'string' ? qs(el) : el;
441
+ if (!this.el) return;
442
+ this.opts = Object.assign({
443
+ start: 0, end: parseInt(this.el.dataset.lxEnd || this.el.textContent) || 0,
444
+ duration: parseInt(this.el.dataset.lxDuration) || 2000,
445
+ prefix: this.el.dataset.lxPrefix || '', suffix: this.el.dataset.lxSuffix || '',
446
+ decimals: parseInt(this.el.dataset.lxDecimals) || 0, easing: true
447
+ }, opts);
448
+ }
449
+ _ease(t) { return t < .5 ? 2 * t * t : -1 + (4 - 2 * t) * t; }
450
+ _format(n) { return this.opts.prefix + n.toFixed(this.opts.decimals).replace(/\B(?=(\d{3})+(?!\d))/g, ',') + this.opts.suffix; }
451
+ start() {
452
+ const { start, end, duration, easing } = this.opts, range = end - start;
453
+ let startTime = null;
454
+ const step = ts => {
455
+ if (!startTime) startTime = ts;
456
+ const elapsed = Math.min(ts - startTime, duration);
457
+ const progress = easing ? this._ease(elapsed / duration) : elapsed / duration;
458
+ this.el.textContent = this._format(start + range * progress);
459
+ if (elapsed < duration) requestAnimationFrame(step);
460
+ else this.el.textContent = this._format(end);
461
+ };
462
+ requestAnimationFrame(step);
463
+ }
464
+ static observeAll(sel, opts) {
465
+ if ('IntersectionObserver' in window) {
466
+ const io = new IntersectionObserver(entries => {
467
+ entries.forEach(e => { if (e.isIntersecting) { new Counter(e.target, opts).start(); io.unobserve(e.target); } });
468
+ }, { threshold: .5 });
469
+ qsa(sel).forEach(el => io.observe(el));
470
+ } else { qsa(sel).forEach(el => new Counter(el, opts).start()); }
471
+ }
472
+ }
473
+
474
+ /* ── NumberInput ── */
475
+ export class NumberInput {
476
+ constructor(el, opts = {}) {
477
+ this.wrap = typeof el === 'string' ? qs(el) : el;
478
+ if (!this.wrap) return;
479
+ this.input = qs('input', this.wrap);
480
+ if (!this.input) return;
481
+ this.opts = Object.assign({ step: 1, min: -Infinity, max: Infinity }, opts);
482
+ this.opts.min = parseFloat(this.input.min || this.opts.min);
483
+ this.opts.max = parseFloat(this.input.max || this.opts.max);
484
+ this.opts.step = parseFloat(this.input.step || this.opts.step) || 1;
485
+ this._attach();
486
+ }
487
+ _val() { return parseFloat(this.input.value) || 0; }
488
+ _set(v) {
489
+ const clamped = Math.min(this.opts.max, Math.max(this.opts.min, v));
490
+ this.input.value = clamped;
491
+ emit(this.input, 'change', { value: clamped });
492
+ this._updateBtns();
493
+ }
494
+ _updateBtns() {
495
+ const v = this._val();
496
+ const dec = qs('.lx-number-btn[data-lx-dec]', this.wrap) || qs('.lx-number-dec', this.wrap);
497
+ const inc = qs('.lx-number-btn[data-lx-inc]', this.wrap) || qs('.lx-number-inc', this.wrap);
498
+ if (dec) dec.disabled = v <= this.opts.min;
499
+ if (inc) inc.disabled = v >= this.opts.max;
500
+ }
501
+ _attach() {
502
+ on(this.wrap, 'click', e => {
503
+ const btn = e.target.closest('[data-lx-dec],[data-lx-inc],.lx-number-dec,.lx-number-inc');
504
+ if (!btn) return;
505
+ if (btn.matches('[data-lx-dec],.lx-number-dec')) this._set(this._val() - this.opts.step);
506
+ if (btn.matches('[data-lx-inc],.lx-number-inc')) this._set(this._val() + this.opts.step);
507
+ });
508
+ on(this.input, 'change', () => this._set(this._val()));
509
+ on(this.input, 'keydown', e => {
510
+ if (e.key === 'ArrowUp') { e.preventDefault(); this._set(this._val() + this.opts.step); }
511
+ if (e.key === 'ArrowDown') { e.preventDefault(); this._set(this._val() - this.opts.step); }
512
+ });
513
+ this._updateBtns();
514
+ }
515
+ }
516
+
517
+ /* ── Rating ── */
518
+ export class Rating {
519
+ constructor(el, opts = {}) {
520
+ this.el = typeof el === 'string' ? qs(el) : el;
521
+ if (!this.el) return;
522
+ this.opts = Object.assign({ stars: 5, value: 0, readonly: this.el.dataset.lxReadonly !== undefined }, opts);
523
+ this.value = parseFloat(this.el.dataset.lxValue || this.opts.value) || 0;
524
+ this._render();
525
+ }
526
+ _render() {
527
+ this.el.innerHTML = '';
528
+ this.el.setAttribute('role', 'radiogroup');
529
+ for (let i = 1; i <= this.opts.stars; i++) {
530
+ const s = document.createElement('span');
531
+ s.className = 'lx-rating-star' + (i <= this.value ? ' lx-filled' : '');
532
+ s.setAttribute('role', 'radio');
533
+ s.setAttribute('aria-label', i + ' star' + (i !== 1 ? 's' : ''));
534
+ s.setAttribute('aria-checked', i <= this.value ? 'true' : 'false');
535
+ s.dataset.value = i;
536
+ this.el.appendChild(s);
537
+ }
538
+ if (this.opts.readonly) { this.el.dataset.readonly = ''; return; }
539
+ on(this.el, 'click', e => {
540
+ const s = e.target.closest('.lx-rating-star');
541
+ if (!s) return;
542
+ this.value = parseInt(s.dataset.value);
543
+ qsa('.lx-rating-star', this.el).forEach((st, i) => {
544
+ const filled = i + 1 <= this.value;
545
+ st.classList.toggle('lx-filled', filled);
546
+ st.setAttribute('aria-checked', filled ? 'true' : 'false');
547
+ });
548
+ emit(this.el, 'rating.change', { value: this.value });
549
+ });
550
+ }
551
+ setValue(v) { this.value = v; this._render(); }
552
+ getValue() { return this.value; }
553
+ }
554
+
555
+ /* ── Breakpoint ── */
556
+ export const breakpoint = {
557
+ _bp: { xs: 0, sm: 640, md: 768, lg: 1024, xl: 1280, '2xl': 1536 },
558
+ current() {
559
+ const w = window.innerWidth;
560
+ return Object.entries(this._bp).reverse().find(([, v]) => w >= v)?.[0] || 'xs';
561
+ },
562
+ on(bp, fn) {
563
+ const mq = window.matchMedia(`(min-width: ${this._bp[bp]}px)`);
564
+ mq.addEventListener('change', e => { if (e.matches) fn(); });
565
+ if (mq.matches) fn();
566
+ }
567
+ };
568
+
569
+ /* ── Theme ── */
570
+ export const theme = {
571
+ set(t, mode) { document.documentElement.dataset.theme = t; if (mode) document.documentElement.dataset.mode = mode; },
572
+ setMode(mode) { document.documentElement.dataset.mode = mode; },
573
+ toggle() { const cur = document.documentElement.dataset.mode || 'light'; this.setMode(cur === 'dark' ? 'light' : 'dark'); },
574
+ current() { return { theme: document.documentElement.dataset.theme, mode: document.documentElement.dataset.mode }; },
575
+ save(t, mode) { this.set(t, mode); localStorage.setItem('lx-theme', t); if (mode) localStorage.setItem('lx-mode', mode); },
576
+ restore() { const t = localStorage.getItem('lx-theme'), m = localStorage.getItem('lx-mode'); if (t) this.set(t, m || undefined); }
577
+ };
578
+
579
+ /* ── Init ── */
580
+ export function init() {
581
+ // Data-attribute bridge
582
+ on(document, 'click', e => {
583
+ const el = e.target.closest('[data-lx-toggle],[data-lx-dismiss],[data-lx-slide],[data-lx-slide-to]');
584
+ if (!el) return;
585
+ const toggle = el.dataset.lxToggle, dismiss = el.dataset.lxDismiss;
586
+ const target = el.dataset.lxTarget ? qs(el.dataset.lxTarget) : null;
587
+ if (dismiss === 'modal') { const m = el.closest('.lx-modal'); if (m) new Modal(m).hide(); }
588
+ if (dismiss === 'offcanvas'){ const o = el.closest('.lx-offcanvas');if (o) new Offcanvas(o).hide(); }
589
+ if (dismiss === 'alert') { const a = el.closest('.lx-alert'); if (a) { a.style.opacity='0'; a.style.transition='opacity .15s'; setTimeout(()=>a.remove(),150); } }
590
+ if (dismiss === 'toast') { const t = el.closest('.lx-toast'); if (t) { t.style.opacity='0'; t.style.transition='opacity .15s'; setTimeout(()=>t.remove(),150); } }
591
+ if (toggle === 'modal' && target) { e.preventDefault(); new Modal(target).toggle(); }
592
+ else if (toggle === 'collapse' && target) { e.preventDefault(); new Collapse(target).toggle(); el.setAttribute('aria-expanded', (!target.classList.contains('lx-show')).toString()); }
593
+ else if (toggle === 'accordion' && target) {
594
+ e.preventDefault();
595
+ const isOpen = target.classList.contains('lx-show'), accordion = el.closest('.lx-accordion');
596
+ if (accordion) {
597
+ qsa('.lx-accordion-body.lx-show', accordion).forEach(b => { if (b !== target) new Collapse(b).hide(); });
598
+ qsa('.lx-accordion-trigger', accordion).forEach(t => { if (t !== el) { t.classList.remove('lx-active'); t.setAttribute('aria-expanded','false'); } });
599
+ }
600
+ new Collapse(target)[isOpen ? 'hide' : 'show']();
601
+ el.classList.toggle('lx-active', !isOpen); el.setAttribute('aria-expanded', (!isOpen).toString());
602
+ }
603
+ else if (toggle === 'dropdown') { e.preventDefault(); e.stopPropagation(); new Dropdown(el).toggle(); }
604
+ else if (toggle === 'offcanvas' && target) { e.preventDefault(); new Offcanvas(target).toggle(); }
605
+ else if (toggle === 'tab' && target) { e.preventDefault(); new Tab(el).show(); }
606
+ const slideTo = el.dataset.lxSlideTo, slideDir = el.dataset.lxSlide;
607
+ if (slideTo !== undefined || slideDir) {
608
+ const c = (qs(el.dataset.lxTarget) || el.closest('.lx-carousel'))?._lxCarousel;
609
+ if (c) { if (slideDir === 'next') c.next(); else if (slideDir === 'prev') c.prev(); else if (slideTo !== undefined) c.to(parseInt(slideTo)); }
610
+ }
611
+ });
612
+ // Scrollspy
613
+ qsa('[data-lx-spy="scroll"]').forEach(el => new Scrollspy(el));
614
+ // Tooltips
615
+ qsa('[data-lx-toggle="tooltip"]').forEach(el => new Tooltip(el, { placement: el.dataset.lxPlacement || 'top', trigger: 'hover focus', delay: { show: 100, hide: 0 } }));
616
+ // Carousels
617
+ qsa('.lx-carousel').forEach(el => { const c = new Carousel(el, { interval: parseInt(el.dataset.lxInterval) || 5000 }); el._lxCarousel = c; });
618
+ // Number inputs
619
+ qsa('.lx-number-input').forEach(el => new NumberInput(el));
620
+ // Ratings
621
+ qsa('.lx-rating').forEach(el => new Rating(el));
622
+ // Back to top
623
+ const btns = qsa('.lx-back-top');
624
+ if (btns.length) {
625
+ const toggle = () => btns.forEach(b => b.classList.toggle('lx-show', window.scrollY > 300));
626
+ on(window, 'scroll', toggle, { passive: true });
627
+ btns.forEach(btn => on(btn, 'click', e => { e.preventDefault(); window.scrollTo({ top: 0, behavior: 'smooth' }); }));
628
+ toggle();
629
+ }
630
+ // Lazy load
631
+ if ('IntersectionObserver' in window) {
632
+ const io = new IntersectionObserver(entries => {
633
+ entries.forEach(e => {
634
+ if (!e.isIntersecting) return;
635
+ const el = e.target;
636
+ if (el.dataset.lxSrc) el.src = el.dataset.lxSrc;
637
+ if (el.dataset.lxBg) el.style.backgroundImage = 'url(' + el.dataset.lxBg + ')';
638
+ el.classList.add('lx-lazy-loaded'); io.unobserve(el);
639
+ });
640
+ }, { rootMargin: '200px' });
641
+ qsa('[data-lx-lazy]').forEach(el => io.observe(el));
642
+ }
643
+ // File drops
644
+ qsa('.lx-file-drop').forEach(zone => {
645
+ const input = qs('input[type="file"]', zone);
646
+ ['dragenter','dragover'].forEach(ev => on(zone, ev, e => { e.preventDefault(); zone.classList.add('lx-drag-over'); }));
647
+ ['dragleave','drop'].forEach(ev => on(zone, ev, e => { e.preventDefault(); zone.classList.remove('lx-drag-over'); }));
648
+ on(zone, 'drop', e => { const files = e.dataTransfer.files; if (input) { try { input.files = files; } catch(x){} } emit(zone, 'file.drop', { files }); });
649
+ on(zone, 'click', () => input && input.click());
650
+ if (input) on(input, 'change', () => emit(zone, 'file.select', { files: input.files }));
651
+ });
652
+ theme.restore();
653
+ }
654
+
655
+ if (typeof document !== 'undefined') {
656
+ if (document.readyState === 'loading') { on(document, 'DOMContentLoaded', init); }
657
+ else { init(); }
658
+ }
659
+
660
+ /* ── Default export ── */
661
+ export default {
662
+ version: '1.0.0',
663
+ homepage: 'https://ui.lancar.id',
664
+ init,
665
+ Modal, Toast, Collapse, Dropdown, Offcanvas, Tooltip, Popover,
666
+ Tab, Carousel, Scrollspy, Clipboard, Counter, NumberInput, Rating,
667
+ breakpoint, theme,
668
+ LxToast: Toast
669
+ };