@lanrenbang/basecoat-ultra 0.1.6 → 0.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.
@@ -1,5 +1,5 @@
1
1
  (() => {
2
- const l = ["latte", "frappe", "macchiato", "mocha"], p = ["frappe", "macchiato", "mocha"], i = [
2
+ const l = ["latte", "frappe", "macchiato", "mocha"], v = ["frappe", "macchiato", "mocha"], u = [
3
3
  "rosewater",
4
4
  "flamingo",
5
5
  "pink",
@@ -15,67 +15,82 @@
15
15
  "blue",
16
16
  "lavender"
17
17
  ];
18
- function f(o) {
19
- if (!l.includes(o)) return {};
20
- const a = { background: `var(--ctp-${o}-base)` };
21
- return i.forEach((t) => {
22
- a[t] = `var(--ctp-${o}-${t})`;
18
+ function w(e) {
19
+ if (!l.includes(e)) return {};
20
+ const a = { background: `var(--ctp-${e}-base)` };
21
+ return u.forEach((c) => {
22
+ a[c] = `var(--ctp-${e}-${c})`;
23
23
  }), a;
24
24
  }
25
- function u(o, a) {
26
- const t = document.documentElement;
27
- l.forEach((r) => t.classList.remove(`theme-${r}`)), i.forEach((r) => t.classList.remove(`accent-${r}`)), t.classList.add(`theme-${o}`), t.classList.add(`accent-${a}`), p.includes(o) ? t.classList.add("dark") : t.classList.remove("dark");
25
+ function f(e, a, c) {
26
+ const n = document.documentElement;
27
+ l.forEach((o) => n.classList.remove(`theme-${o}`)), u.forEach((o) => n.classList.remove(`accent-${o}`)), n.classList.add(`theme-${e}`), n.classList.add(`accent-${a}`), v.includes(e) ? n.classList.add("dark") : n.classList.remove("dark");
28
28
  try {
29
- localStorage.setItem("catppuccin-theme", o), localStorage.setItem("catppuccin-accent", a), localStorage.removeItem("basecoat-mode");
29
+ localStorage.setItem("catppuccin-theme", e), localStorage.setItem("catppuccin-accent", a), localStorage.removeItem("basecoat-mode");
30
30
  } catch {
31
31
  }
32
+ c && c.dispatchEvent(new CustomEvent("change", {
33
+ bubbles: !0,
34
+ detail: { theme: e, accent: a }
35
+ }));
32
36
  }
33
- function h() {
37
+ function E() {
34
38
  try {
35
- const o = localStorage.getItem("catppuccin-theme"), a = localStorage.getItem("catppuccin-accent"), t = localStorage.getItem("basecoat-mode");
36
- if (o && a)
37
- u(o, a);
38
- else if (t)
39
- t === "dark" ? document.documentElement.classList.add("dark") : document.documentElement.classList.remove("dark");
39
+ const e = localStorage.getItem("catppuccin-theme"), a = localStorage.getItem("catppuccin-accent"), c = localStorage.getItem("basecoat-mode");
40
+ if (e && a)
41
+ f(e, a);
42
+ else if (c)
43
+ c === "dark" ? document.documentElement.classList.add("dark") : document.documentElement.classList.remove("dark");
40
44
  else {
41
- const r = window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches;
42
- document.documentElement.classList.toggle("dark", r);
45
+ const n = window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches;
46
+ document.documentElement.classList.toggle("dark", n);
43
47
  }
44
- } catch (o) {
45
- console.error("Basecoat: Theme initialization failed", o);
48
+ } catch (e) {
49
+ console.error("Basecoat: Theme initialization failed", e);
46
50
  }
47
51
  }
48
- h();
49
- const g = (o) => {
50
- const a = o.querySelector(".theme-flavors"), t = o.querySelector(".theme-accents"), r = o.querySelector(".theme-reset");
51
- let n = localStorage.getItem("catppuccin-theme");
52
- (!n || !l.includes(n)) && (n = document.documentElement.classList.contains("dark") ? "mocha" : "latte"), a && (a.innerHTML = "", a.className = "button-group w-full", l.forEach((c) => {
53
- const e = document.createElement("button");
54
- e.type = "button", e.className = "btn btn-sm capitalize flex-1", e.textContent = c, e.dataset.flavor = c, a.appendChild(e);
52
+ typeof document < "u" && E();
53
+ const k = (e) => {
54
+ const a = e.querySelector(".theme-flavors"), c = e.querySelector(".theme-accents"), n = e.querySelector(".theme-reset");
55
+ let o = localStorage.getItem("catppuccin-theme");
56
+ (!o || !l.includes(o)) && (o = document.documentElement.classList.contains("dark") ? "mocha" : "latte"), a && (a.innerHTML = "", a.className = "button-group w-full", l.forEach((s) => {
57
+ const t = document.createElement("button");
58
+ t.type = "button", t.className = "btn btn-sm capitalize flex-1", t.textContent = s, t.dataset.flavor = s, a.appendChild(t);
55
59
  }));
56
- const d = () => {
60
+ const p = () => {
57
61
  if (!a) return;
58
- a.querySelectorAll("[data-flavor]").forEach((e) => {
59
- e.dataset.flavor === n ? (e.classList.remove("btn-outline", "btn-ghost"), e.classList.add("btn-primary")) : (e.classList.remove("btn-primary"), e.classList.add("btn-ghost"));
62
+ a.querySelectorAll("[data-flavor]").forEach((t) => {
63
+ t.dataset.flavor === o ? (t.classList.remove("btn-outline", "btn-ghost"), t.classList.add("btn-primary")) : (t.classList.remove("btn-primary"), t.classList.add("btn-ghost"));
60
64
  });
61
- }, m = () => {
62
- if (!t) return;
63
- t.innerHTML = "";
64
- const c = f(n);
65
- t.className = "theme-accents grid grid-cols-7 gap-3 place-items-center p-4 rounded-xl border border-border/50 mt-4 transition-colors duration-300", t.style.backgroundColor = c.background, i.forEach((e) => {
66
- const s = document.createElement("button");
67
- s.type = "button", s.className = "size-6 rounded-full border border-border/20 shadow-sm transition-transform hover:scale-110 focus:outline-none focus:ring-2 focus:ring-ring", s.title = e, s.style.backgroundColor = c[e], s.dataset.tooltip = e, s.dataset.side = "top", s.onclick = () => {
68
- u(n, e), d();
69
- }, t.appendChild(s);
65
+ }, h = () => {
66
+ if (!c) return;
67
+ c.innerHTML = "";
68
+ const s = w(o), t = localStorage.getItem("catppuccin-theme"), d = localStorage.getItem("catppuccin-accent");
69
+ c.className = "theme-accents grid grid-cols-7 gap-3 place-items-center p-4 rounded-xl border border-border/50 mt-4 transition-colors duration-300", c.style.backgroundColor = s.background, u.forEach((m) => {
70
+ const i = document.createElement("button");
71
+ i.type = "button";
72
+ const g = d === m && t === o;
73
+ if (i.className = `size-6 rounded-full border border-border/20 shadow-sm transition-transform hover:scale-110 focus:outline-none focus:ring-2 focus:ring-ring relative flex items-center justify-center ${g ? "ring-2 ring-white ring-offset-2 scale-110" : ""}`, i.title = m, i.style.backgroundColor = s[m], i.dataset.tooltip = m, i.dataset.side = "top", g) {
74
+ const r = document.createElementNS("http://www.w3.org/2000/svg", "svg");
75
+ r.setAttribute("class", "text-white drop-shadow-sm"), r.style.width = "12px", r.style.height = "12px", r.setAttribute("viewBox", "0 0 24 24"), r.setAttribute("fill", "none"), r.setAttribute("stroke", "currentColor"), r.setAttribute("stroke-width", "3"), r.setAttribute("stroke-linecap", "round"), r.setAttribute("stroke-linejoin", "round");
76
+ const b = document.createElementNS("http://www.w3.org/2000/svg", "path");
77
+ b.setAttribute("d", "M20 6 9 17l-5-5"), r.appendChild(b), i.appendChild(r);
78
+ }
79
+ i.onclick = (r) => {
80
+ r.stopPropagation(), f(o, m, e), p(), h();
81
+ }, c.appendChild(i);
70
82
  });
71
83
  };
72
- a && a.addEventListener("click", (c) => {
73
- const e = c.target.closest("[data-flavor]");
74
- e && (n = e.dataset.flavor, d(), m());
75
- }), r && r.addEventListener("click", () => {
76
- const c = document.documentElement, e = c.classList.contains("dark");
77
- l.forEach((s) => c.classList.remove(`theme-${s}`)), i.forEach((s) => c.classList.remove(`accent-${s}`)), localStorage.removeItem("catppuccin-theme"), localStorage.removeItem("catppuccin-accent"), localStorage.setItem("basecoat-mode", e ? "dark" : "light"), e ? c.classList.add("dark") : c.classList.remove("dark"), n = e ? "mocha" : "latte", d(), m();
78
- }), d(), m();
84
+ a && a.addEventListener("click", (s) => {
85
+ const t = s.target.closest("[data-flavor]");
86
+ t && (o = t.dataset.flavor, p(), h());
87
+ }), n && n.addEventListener("click", () => {
88
+ const s = document.documentElement, t = s.classList.contains("dark");
89
+ l.forEach((d) => s.classList.remove(`theme-${d}`)), u.forEach((d) => s.classList.remove(`accent-${d}`)), localStorage.removeItem("catppuccin-theme"), localStorage.removeItem("catppuccin-accent"), localStorage.setItem("basecoat-mode", t ? "dark" : "light"), t ? s.classList.add("dark") : s.classList.remove("dark"), o = t ? "mocha" : "latte", p(), h(), e.dispatchEvent(new CustomEvent("change", {
90
+ bubbles: !0,
91
+ detail: { theme: null, accent: null, mode: t ? "dark" : "light" }
92
+ }));
93
+ }), p(), h(), e.dataset.catppuccinThemeSwitcherInitialized = !0, e.dispatchEvent(new CustomEvent("basecoat:initialized"));
79
94
  };
80
- window.basecoat && window.basecoat.register("catppuccin-theme-switcher", ".catppuccin-theme-switcher", g);
95
+ window.basecoat && window.basecoat.register("catppuccin-theme-switcher", ".catppuccin-theme-switcher:not([data-catppuccin-theme-switcher-initialized])", k);
81
96
  })();
@@ -2313,55 +2313,220 @@ Date.prototype.fp_incr = function(days) {
2313
2313
  if (typeof window !== "undefined") {
2314
2314
  window.flatpickr = flatpickr;
2315
2315
  }
2316
- const initDatepicker = (root = document) => {
2317
- const inputs = root.querySelectorAll(".datepicker");
2318
- inputs.forEach((input) => {
2319
- if (input._flatpickr) return;
2320
- const mode = input.dataset.mode || "single";
2321
- const enableTime = input.dataset.enableTime === "true";
2322
- const noCalendar = input.dataset.noCalendar === "true";
2323
- const inline = input.dataset.inline === "true";
2324
- const dateFormat = input.dataset.dateFormat || (enableTime && noCalendar ? "H:i" : "Y-m-d");
2325
- flatpickr(input, {
2326
- mode,
2327
- enableTime,
2328
- noCalendar,
2329
- inline,
2330
- dateFormat,
2331
- allowInput: true,
2332
- // Allow manual typing
2333
- shorthandCurrentMonth: true,
2334
- // Display month shorthand (e.g. "Dec" instead of "December")
2335
- prevArrow: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="w-4 h-4"><path d="m15 18-6-6 6-6"/></svg>',
2336
- nextArrow: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="w-4 h-4"><path d="m9 18 6-6-6-6"/></svg>',
2337
- static: true
2338
- // Position relative to wrapper, helps with scroll
2339
- // Custom class names to hook into our CSS
2340
- // flatpickr doesn't fully support class replacements, but we can append
2341
- });
2342
- });
2316
+ var zh$1 = { exports: {} };
2317
+ var zh = zh$1.exports;
2318
+ var hasRequiredZh;
2319
+ function requireZh() {
2320
+ if (hasRequiredZh) return zh$1.exports;
2321
+ hasRequiredZh = 1;
2322
+ (function(module, exports$1) {
2323
+ (function(global, factory) {
2324
+ factory(exports$1);
2325
+ })(zh, (function(exports$12) {
2326
+ var fp = typeof window !== "undefined" && window.flatpickr !== void 0 ? window.flatpickr : {
2327
+ l10ns: {}
2328
+ };
2329
+ var Mandarin = {
2330
+ weekdays: {
2331
+ shorthand: ["周日", "周一", "周二", "周三", "周四", "周五", "周六"],
2332
+ longhand: [
2333
+ "星期日",
2334
+ "星期一",
2335
+ "星期二",
2336
+ "星期三",
2337
+ "星期四",
2338
+ "星期五",
2339
+ "星期六"
2340
+ ]
2341
+ },
2342
+ months: {
2343
+ shorthand: [
2344
+ "一月",
2345
+ "二月",
2346
+ "三月",
2347
+ "四月",
2348
+ "五月",
2349
+ "六月",
2350
+ "七月",
2351
+ "八月",
2352
+ "九月",
2353
+ "十月",
2354
+ "十一月",
2355
+ "十二月"
2356
+ ],
2357
+ longhand: [
2358
+ "一月",
2359
+ "二月",
2360
+ "三月",
2361
+ "四月",
2362
+ "五月",
2363
+ "六月",
2364
+ "七月",
2365
+ "八月",
2366
+ "九月",
2367
+ "十月",
2368
+ "十一月",
2369
+ "十二月"
2370
+ ]
2371
+ },
2372
+ rangeSeparator: " 至 ",
2373
+ weekAbbreviation: "周",
2374
+ scrollTitle: "滚动切换",
2375
+ toggleTitle: "点击切换 12/24 小时时制"
2376
+ };
2377
+ fp.l10ns.zh = Mandarin;
2378
+ var zh2 = fp.l10ns;
2379
+ exports$12.Mandarin = Mandarin;
2380
+ exports$12.default = zh2;
2381
+ Object.defineProperty(exports$12, "__esModule", { value: true });
2382
+ }));
2383
+ })(zh$1, zh$1.exports);
2384
+ return zh$1.exports;
2385
+ }
2386
+ var zhExports = requireZh();
2387
+ var zhTw$1 = { exports: {} };
2388
+ var zhTw = zhTw$1.exports;
2389
+ var hasRequiredZhTw;
2390
+ function requireZhTw() {
2391
+ if (hasRequiredZhTw) return zhTw$1.exports;
2392
+ hasRequiredZhTw = 1;
2393
+ (function(module, exports$1) {
2394
+ (function(global, factory) {
2395
+ factory(exports$1);
2396
+ })(zhTw, (function(exports$12) {
2397
+ var fp = typeof window !== "undefined" && window.flatpickr !== void 0 ? window.flatpickr : {
2398
+ l10ns: {}
2399
+ };
2400
+ var MandarinTraditional = {
2401
+ weekdays: {
2402
+ shorthand: ["週日", "週一", "週二", "週三", "週四", "週五", "週六"],
2403
+ longhand: [
2404
+ "星期日",
2405
+ "星期一",
2406
+ "星期二",
2407
+ "星期三",
2408
+ "星期四",
2409
+ "星期五",
2410
+ "星期六"
2411
+ ]
2412
+ },
2413
+ months: {
2414
+ shorthand: [
2415
+ "一月",
2416
+ "二月",
2417
+ "三月",
2418
+ "四月",
2419
+ "五月",
2420
+ "六月",
2421
+ "七月",
2422
+ "八月",
2423
+ "九月",
2424
+ "十月",
2425
+ "十一月",
2426
+ "十二月"
2427
+ ],
2428
+ longhand: [
2429
+ "一月",
2430
+ "二月",
2431
+ "三月",
2432
+ "四月",
2433
+ "五月",
2434
+ "六月",
2435
+ "七月",
2436
+ "八月",
2437
+ "九月",
2438
+ "十月",
2439
+ "十一月",
2440
+ "十二月"
2441
+ ]
2442
+ },
2443
+ rangeSeparator: " 至 ",
2444
+ weekAbbreviation: "週",
2445
+ scrollTitle: "滾動切換",
2446
+ toggleTitle: "點擊切換 12/24 小時時制"
2447
+ };
2448
+ fp.l10ns.zh_tw = MandarinTraditional;
2449
+ var zhTw2 = fp.l10ns;
2450
+ exports$12.MandarinTraditional = MandarinTraditional;
2451
+ exports$12.default = zhTw2;
2452
+ Object.defineProperty(exports$12, "__esModule", { value: true });
2453
+ }));
2454
+ })(zhTw$1, zhTw$1.exports);
2455
+ return zhTw$1.exports;
2456
+ }
2457
+ var zhTwExports = requireZhTw();
2458
+ const EnglishFull = {
2459
+ weekdays: {
2460
+ shorthand: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
2461
+ longhand: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
2462
+ },
2463
+ months: {
2464
+ shorthand: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
2465
+ longhand: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
2466
+ }
2343
2467
  };
2344
- if (typeof window !== "undefined") {
2345
- const observer = new MutationObserver((mutations) => {
2346
- mutations.forEach((mutation) => {
2347
- if (mutation.type === "childList") {
2348
- mutation.addedNodes.forEach((node) => {
2349
- if (node.nodeType === 1) {
2350
- if (node.classList?.contains("datepicker")) {
2351
- initDatepicker(node.parentNode);
2352
- } else if (node.querySelector?.(".datepicker")) {
2353
- initDatepicker(node);
2354
- }
2355
- }
2356
- });
2357
- }
2358
- });
2359
- });
2360
- document.addEventListener("DOMContentLoaded", () => {
2361
- initDatepicker();
2362
- observer.observe(document.body, { childList: true, subtree: true });
2468
+ const EnglishShort = {
2469
+ weekdays: {
2470
+ shorthand: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
2471
+ longhand: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
2472
+ },
2473
+ months: {
2474
+ shorthand: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
2475
+ longhand: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
2476
+ }
2477
+ };
2478
+ const locales = {
2479
+ "zh": zhExports.Mandarin,
2480
+ "zh-tw": zhTwExports.MandarinTraditional,
2481
+ "en-full": EnglishFull,
2482
+ "en-short": EnglishShort
2483
+ };
2484
+ const initDatepicker = (input) => {
2485
+ if (input._flatpickr) return;
2486
+ if (input.dataset.datepickerInitialized) return;
2487
+ const mode = input.dataset.mode || "single";
2488
+ const enableTime = input.dataset.enableTime === "true";
2489
+ const noCalendar = input.dataset.noCalendar === "true";
2490
+ const isInline = input.dataset.inline === "true";
2491
+ const dateFormat = input.dataset.dateFormat || (enableTime && noCalendar ? "H:i" : "Y-m-d");
2492
+ const locale = input.dataset.locale || "en-short";
2493
+ const localeConfig = locales[locale] || EnglishShort;
2494
+ flatpickr(input, {
2495
+ mode,
2496
+ enableTime,
2497
+ noCalendar,
2498
+ inline: isInline,
2499
+ dateFormat,
2500
+ allowInput: true,
2501
+ shorthandCurrentMonth: locale === "en-short",
2502
+ static: !isInline,
2503
+ locale: localeConfig,
2504
+ onOpen: () => {
2505
+ document.dispatchEvent(new CustomEvent("basecoat:popover", { detail: { source: input } }));
2506
+ },
2507
+ onChange: (selectedDates, dateStr) => {
2508
+ input.dispatchEvent(new CustomEvent("change", {
2509
+ bubbles: true,
2510
+ detail: { value: dateStr, dates: selectedDates }
2511
+ }));
2512
+ }
2363
2513
  });
2514
+ input.dataset.datepickerInitialized = "true";
2515
+ input.dispatchEvent(new CustomEvent("basecoat:initialized"));
2516
+ };
2517
+ if (window.basecoat) {
2518
+ window.basecoat.register("datepicker", ".datepicker:not([data-datepicker-initialized])", initDatepicker);
2519
+ if (document.readyState === "complete" || document.readyState === "interactive") {
2520
+ window.basecoat.init("datepicker");
2521
+ }
2364
2522
  }
2523
+ document.addEventListener("basecoat:popover", (event) => {
2524
+ document.querySelectorAll(".datepicker").forEach((el) => {
2525
+ if (el._flatpickr && el._flatpickr.isOpen && event.detail?.source !== el) {
2526
+ el._flatpickr.close();
2527
+ }
2528
+ });
2529
+ });
2365
2530
  export {
2366
2531
  initDatepicker
2367
2532
  };