@ecomcx/ecomweb-theme-sdk 2.1.0 → 2.3.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/dist/client.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
- import { countdownParts, SEARCH_ICON_PATH } from "@ecomcx/ecomweb-content";
4
- import { extraFields } from "./auth-forms.js";
3
+ import { carouselData, carouselVars, countdownParts, evergreenWindow, nextTarget, SEARCH_ICON_PATH } from "@ecomcx/ecomweb-content";
4
+ import { extraFields, useCurrentUser } from "./auth-forms.js";
5
5
  import { Component, Suspense, useCallback, useEffect, useId, useRef, useState } from "react";
6
6
  import { createPortal } from "react-dom";
7
7
  import { usePathname, useRouter } from "next/navigation";
@@ -250,16 +250,50 @@ export function LanguageSwitcherClient({ languages, current, defaultLocale, labe
250
250
  export { LoginForm, RegisterForm, ForgotPasswordForm, ResetPasswordForm, LogoutButton, LoginOutLink, useCurrentUser, extraFields, ProfileForm, ChangePasswordForm, DeleteAccountForm, AUTH_LABELS, AUTH_PATHS } from "./auth-forms.js";
251
251
  export { safeRedirect } from "./auth-shared.js";
252
252
  /** Khối countdown: đếm ngược tới `target` (ms). Dựng lần đầu cùng giá trị trên máy chủ, rồi cập nhật mỗi giây. */
253
- export function CountdownClient({ target, label, expiredText, units, serverNow, attrs = {} }) {
253
+ export function CountdownClient({ target, label, expiredText, units, serverNow, rules, storageKey, attrs = {} }) {
254
254
  // Lần render đầu của client dùng ĐÚNG thời điểm máy chủ đã dùng (serverNow) để khớp HTML dựng sẵn / cache; sau đó lấy giờ thật ngay (tránh hydration mismatch #418)
255
255
  const [now, setNow] = useState(() => serverNow ?? Date.now());
256
- useEffect(() => { setNow(Date.now()); }, []);
257
- useEffect(() => { const id = setInterval(() => setNow(Date.now()), 1000); return () => clearInterval(id); }, []);
258
- const left = Math.max(0, target - now);
259
- if (left === 0 && expiredText)
256
+ const [paused, setPaused] = useState(false);
257
+ const [mounted, setMounted] = useState(false);
258
+ // Evergreen: mốc bắt đầu của RIÊNG người xem này nằm trong localStorage (không có thì bắt đầu từ lúc vào trang)
259
+ const [end, setEnd] = useState(null);
260
+ useEffect(() => {
261
+ setNow(Date.now());
262
+ setMounted(true);
263
+ if (rules?.evergreenMs && storageKey) {
264
+ let saved = null;
265
+ try {
266
+ const v = localStorage.getItem(`ecx-cd:${storageKey}`);
267
+ saved = v ? Number(v) : null;
268
+ }
269
+ catch { /* trình duyệt chặn lưu: đếm từ lúc vào trang */ }
270
+ const [start, finish] = evergreenWindow(saved, Date.now(), rules.evergreenMs, rules.evergreenResetDays);
271
+ try {
272
+ if (start !== saved)
273
+ localStorage.setItem(`ecx-cd:${storageKey}`, String(start));
274
+ }
275
+ catch { /* bỏ qua */ }
276
+ setEnd(finish);
277
+ }
278
+ }, [rules?.evergreenMs, rules?.evergreenResetDays, storageKey]);
279
+ useEffect(() => { if (paused)
280
+ return; const id = setInterval(() => setNow(Date.now()), 1000); return () => clearInterval(id); }, [paused]);
281
+ const evergreen = !!rules?.evergreenMs;
282
+ const base = evergreen ? (end ?? (serverNow ?? now) + rules.evergreenMs) : target;
283
+ const live = rules && !evergreen ? nextTarget(base, rules.repeat, now) : base;
284
+ const left = Math.max(0, live - now);
285
+ const action = rules?.action ?? (expiredText ? "message" : "zero");
286
+ const expired = left === 0 && mounted;
287
+ const url = rules?.redirectUrl;
288
+ useEffect(() => { if (expired && action === "redirect" && url)
289
+ location.assign(url); }, [expired, action, url]);
290
+ if (left === 0 && action === "hide")
291
+ return null;
292
+ if (left === 0 && action === "message" && expiredText)
260
293
  return _jsx("div", { className: "ecx-countdown is-expired", children: expiredText });
261
294
  const post = typeof attrs.postText === "string" && attrs.postText ? attrs.postText : null;
262
- return (_jsxs("div", { className: cx("ecx-countdown", attrs.layout === "inline" && "is-inline", attrs.divider === true && "has-divider"), role: "timer", "aria-live": "off", suppressHydrationWarning: true, children: [label && _jsx("p", { className: "ecx-countdown-label", children: label }), _jsx("div", { className: "ecx-countdown-parts", children: countdownParts(attrs, left, units).map((p) => _jsxs("span", { className: `ecx-countdown-${p.u}`, children: [_jsx("strong", { children: p.value }), _jsx("small", { children: p.label })] }, p.u)) }), post && _jsx("p", { className: "ecx-countdown-post", children: post })] }));
295
+ return (_jsxs("div", { className: cx("ecx-countdown", attrs.layout === "inline" && "is-inline", attrs.divider === true && "has-divider", rules?.pause && "has-pause"), role: "timer", "aria-live": "off", suppressHydrationWarning: true, children: [label && _jsx("p", { className: "ecx-countdown-label", children: label }), _jsx("div", { className: "ecx-countdown-parts", children: countdownParts(attrs, left, units).map((p) => _jsxs("span", { className: `ecx-countdown-${p.u}`, children: [_jsx("strong", { children: p.value }), _jsx("small", { children: p.label })] }, p.u)) }), post && _jsx("p", { className: "ecx-countdown-post", children: post }), rules?.pause && mounted && _jsx("button", { type: "button", className: "ecx-countdown-pause", "aria-pressed": paused, "aria-label": paused ? "▶" : "⏸", onClick: () => { if (paused)
296
+ setNow(Date.now()); setPaused(!paused); }, children: paused ? "▶" : "⏸" })] }));
263
297
  }
264
298
  /** Mục lục: tô đậm mục của tiêu đề đang đọc (tiêu đề cuối cùng đã cuộn qua mép trên 120px) — aria-current="location". */
265
299
  export function TocSpy() {
@@ -326,7 +360,7 @@ export function TabsClient({ titles, panels, initial = 0, icons, subtitles, anch
326
360
  setActive(next);
327
361
  document.getElementById(`${id}-t${next}`)?.focus();
328
362
  };
329
- return (_jsxs("div", { className: extraClass ?? cx("ecx-tabs", vertical && "is-vertical", mobileAccordion && "has-mobile-accordion"), children: [_jsx("div", { role: "tablist", className: "ecx-tabs-list", "aria-orientation": vertical ? "vertical" : undefined, children: titles.map((t, i) => (_jsxs("button", { type: "button", role: "tab", id: `${id}-t${i}`, "aria-selected": i === active, "aria-controls": anchors?.[i] ?? `${id}-p${i}`, tabIndex: i === active ? 0 : -1, className: cx("ecx-tab-button", i === active && "is-active"), style: { "--i": i }, onClick: () => setActive(i), onKeyDown: (e) => move(e, i), children: [icons?.[i] && _jsx("svg", { className: "ecx-tab-icon", viewBox: "0 0 24 24", width: 18, height: 18, fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", focusable: "false", children: _jsx("path", { d: icons[i] }) }), _jsxs("span", { className: "ecx-tab-label", children: [t, subtitles?.[i] && _jsx("small", { className: "ecx-tab-subtitle", children: subtitles[i] })] })] }, i))) }), panels.map((p, i) => _jsx("div", { role: "tabpanel", id: anchors?.[i] ?? `${id}-p${i}`, "aria-labelledby": `${id}-t${i}`, hidden: i !== active, className: "ecx-tab-panel", style: { "--i": i }, children: p }, i))] }));
363
+ return (_jsxs("div", { className: extraClass ?? cx("ecx-tabs", vertical && "is-vertical", mobileAccordion && "has-mobile-accordion"), children: [_jsx("div", { role: "tablist", className: "ecx-tabs-list", "aria-orientation": vertical ? "vertical" : undefined, children: titles.map((t, i) => (_jsxs("button", { type: "button", role: "tab", id: `${id}-t${i}`, "aria-selected": i === active, "aria-controls": anchors?.[i] ?? `${id}-p${i}`, tabIndex: i === active ? 0 : -1, className: cx("ecx-tab-button", i === active && "is-active"), style: { "--i": i }, onClick: () => setActive(i), onKeyDown: (e) => move(e, i), children: [icons?.[i], _jsxs("span", { className: "ecx-tab-label", children: [t, subtitles?.[i] && _jsx("small", { className: "ecx-tab-subtitle", children: subtitles[i] })] })] }, i))) }), panels.map((p, i) => _jsx("div", { role: "tabpanel", id: anchors?.[i] ?? `${id}-p${i}`, "aria-labelledby": `${id}-t${i}`, hidden: i !== active, className: "ecx-tab-panel", style: { "--i": i }, children: p }, i))] }));
330
364
  }
331
365
  /** Phóng to ảnh: bấm ảnh mở lớp phủ (Esc hoặc bấm nền để đóng). `src` đã qua safeUrl ở máy chủ. */
332
366
  export function LightboxClient({ src, alt, children }) {
@@ -348,6 +382,57 @@ export function LightboxClient({ src, alt, children }) {
348
382
  export function FormBlockClient({ formId, source, successMessage, labels, button, className, children, fields: extraUi }) {
349
383
  const started = useRef(Date.now());
350
384
  const [state, setState] = useState({ status: "idle" });
385
+ const formEl = useRef(null);
386
+ const [step, setStep] = useState(1);
387
+ const [maxStep, setMaxStep] = useState(1);
388
+ // Hiện / ẩn ô theo điều kiện (data-showif) và theo bước (data-step); ô đang ẩn không gửi lên
389
+ const sync = useCallback((cur) => {
390
+ const form = formEl.current;
391
+ if (!form)
392
+ return;
393
+ const value = (name) => {
394
+ const els = Array.from(form.elements).filter((e) => e.name === name);
395
+ if (!els.length)
396
+ return "";
397
+ const first = els[0];
398
+ if (first.type === "checkbox")
399
+ return first.checked ? "1" : "";
400
+ if (first.type === "radio")
401
+ return els.find((r) => r.checked)?.value ?? "";
402
+ return first.value.trim();
403
+ };
404
+ let max = 1;
405
+ form.querySelectorAll("[data-field]").forEach((el) => {
406
+ const s = Number(el.dataset.step) || 1;
407
+ if (s > max)
408
+ max = s;
409
+ let condOff = false;
410
+ const m = /^([a-z][a-z0-9_]*)(!?=)?(.*)$/.exec(el.dataset.showif ?? "");
411
+ if (m) {
412
+ const v = value(m[1]);
413
+ condOff = m[2] === "=" ? v !== m[3] : m[2] === "!=" ? v === m[3] : !v;
414
+ }
415
+ el.hidden = condOff || s !== cur; // ô ở bước khác chỉ ẩn (giữ giá trị); ô bị điều kiện ẩn thì tắt hẳn để không gửi và không bắt buộc
416
+ if (condOff)
417
+ el.dataset.condOff = "1";
418
+ else
419
+ delete el.dataset.condOff;
420
+ el.querySelectorAll("input, textarea, select").forEach((i) => { i.disabled = condOff; });
421
+ });
422
+ setMaxStep((x) => (x === max ? x : max));
423
+ }, []);
424
+ useEffect(() => { sync(step); }, [sync, step, state.status]);
425
+ const goNext = () => {
426
+ const form = formEl.current;
427
+ if (!form)
428
+ return;
429
+ const bad = Array.from(form.querySelectorAll("[data-field]:not([hidden]) input:not([type=hidden]), [data-field]:not([hidden]) textarea, [data-field]:not([hidden]) select")).find((i) => !i.checkValidity());
430
+ if (bad) {
431
+ bad.reportValidity();
432
+ return;
433
+ }
434
+ setStep((s) => Math.min(maxStep, s + 1));
435
+ };
351
436
  function showErrors(form, errors) {
352
437
  form.querySelectorAll("[data-field]").forEach((el) => {
353
438
  const msg = errors[el.dataset.field ?? ""]?.join(" ") ?? "";
@@ -365,11 +450,17 @@ export function FormBlockClient({ formId, source, successMessage, labels, button
365
450
  }
366
451
  async function submit(e) {
367
452
  e.preventDefault();
453
+ if (step < maxStep) {
454
+ goNext();
455
+ return;
456
+ }
368
457
  const form = e.currentTarget;
369
458
  const data = new FormData(form);
370
459
  const fields = {};
371
460
  form.querySelectorAll("[data-field]").forEach((el) => {
372
461
  const name = el.dataset.field;
462
+ if (el.dataset.condOff)
463
+ return; // ô bị điều kiện ẩn không gửi
373
464
  const box = el.querySelector("input[type=checkbox]");
374
465
  fields[name] = box ? box.checked : String(data.get(name) ?? "");
375
466
  });
@@ -398,7 +489,236 @@ export function FormBlockClient({ formId, source, successMessage, labels, button
398
489
  }
399
490
  if (state.status === "done")
400
491
  return _jsx("p", { className: "ecx-form-status is-success", role: "status", "data-form-done": formId, children: state.message });
401
- return (_jsxs("form", { className: cx("ecx-form-blocks", className), onSubmit: submit, noValidate: true, "data-form": formId, children: [children, extraUi, _jsx("p", { className: "ecx-form-hp", "aria-hidden": "true", children: _jsxs("label", { children: ["Website", _jsx("input", { type: "text", name: "_hp", tabIndex: -1, autoComplete: "off" })] }) }), state.status === "error" && _jsx("p", { className: "ecx-form-status is-error", role: "alert", children: state.message }), _jsx("div", { className: "ecx-form-actions", children: _jsx("button", { type: "submit", className: button?.className ?? "ecx-button", style: { border: 0, cursor: "pointer", font: "inherit", ...button?.style }, disabled: state.status === "sending", children: state.status === "sending" ? labels.sending : labels.submit }) })] }));
492
+ return (_jsxs("form", { ref: formEl, className: cx("ecx-form-blocks", className), onSubmit: submit, onChange: () => sync(step), onInput: () => sync(step), noValidate: true, "data-form": formId, children: [maxStep > 1 && _jsx("p", { className: "ecx-form-step", role: "status", children: (labels.step ?? "{n}/{total}").replace("{n}", String(step)).replace("{total}", String(maxStep)) }), children, extraUi, _jsx("p", { className: "ecx-form-hp", "aria-hidden": "true", children: _jsxs("label", { children: ["Website", _jsx("input", { type: "text", name: "_hp", tabIndex: -1, autoComplete: "off" })] }) }), state.status === "error" && _jsx("p", { className: "ecx-form-status is-error", role: "alert", children: state.message }), _jsxs("div", { className: "ecx-form-actions", children: [step > 1 && _jsx("button", { type: "button", className: "ecx-form-back", onClick: () => setStep((s) => Math.max(1, s - 1)), children: labels.back ?? "←" }), _jsx("button", { type: "submit", className: button?.className ?? "ecx-button", style: { border: 0, cursor: "pointer", font: "inherit", ...button?.style }, disabled: state.status === "sending", children: state.status === "sending" ? labels.sending : step < maxStep ? (labels.next ?? "→") : labels.submit })] })] }));
493
+ }
494
+ /**
495
+ * Khối Carousel (slider): track cuộn ngang bám mép slide (vuốt được trên điện thoại, không JS vẫn cuộn), nút trước / sau, chấm theo vị trí,
496
+ * tự chạy tuỳ chọn (dừng khi rê chuột / đang focus / tab ẩn / người dùng tắt hiệu ứng chuyển động, có nút Tạm dừng). Số slide thấy cùng lúc theo khổ máy do CSS (style.css).
497
+ */
498
+ export function CarouselClient({ children, count, config: c, label }) {
499
+ const track = useRef(null);
500
+ const [pos, setPos] = useState({ index: 0, visible: c.per });
501
+ const [held, setHeld] = useState(false);
502
+ const [paused, setPaused] = useState(false);
503
+ const [reduced, setReduced] = useState(true);
504
+ const fade = c.effect === "fade";
505
+ const [ready, setReady] = useState(false);
506
+ const measure = useCallback(() => {
507
+ const el = track.current;
508
+ const first = el?.children[0];
509
+ if (!el || !first || fade)
510
+ return;
511
+ const step = (el.children[1]?.offsetLeft ?? first.offsetLeft + first.offsetWidth) - first.offsetLeft || first.offsetWidth || 1;
512
+ const gap = Math.max(0, step - first.offsetWidth);
513
+ const visible = Math.max(1, Math.min(count, Math.round((el.clientWidth + gap) / step)));
514
+ setPos((p) => { const index = Math.max(0, Math.min(count - visible, Math.round(el.scrollLeft / step))); return p.index === index && p.visible === visible ? p : { index, visible }; });
515
+ }, [count, fade]);
516
+ useEffect(() => {
517
+ setReady(true);
518
+ setReduced(typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches);
519
+ measure();
520
+ const el = track.current;
521
+ if (!el || typeof ResizeObserver === "undefined")
522
+ return;
523
+ const ro = new ResizeObserver(measure);
524
+ ro.observe(el);
525
+ return () => ro.disconnect();
526
+ }, [measure]);
527
+ // Mờ dần: không cuộn — đổi chỉ số, slide đang hiện nhận class is-active (CSS lo phần mờ)
528
+ useEffect(() => {
529
+ if (!fade)
530
+ return;
531
+ Array.from(track.current?.children ?? []).forEach((k, i) => { k.classList.toggle("is-active", i === pos.index); k.classList.toggle("is-off", i !== pos.index); k.setAttribute("aria-hidden", i === pos.index ? "false" : "true"); });
532
+ }, [fade, pos.index, count]);
533
+ const goTo = useCallback((i) => {
534
+ if (fade) {
535
+ setPos((p) => ({ ...p, index: Math.max(0, Math.min(count - 1, i)) }));
536
+ return;
537
+ }
538
+ const el = track.current, kid = el?.children[i];
539
+ if (el && kid)
540
+ el.scrollTo({ left: kid.offsetLeft - el.children[0].offsetLeft, behavior: reduced ? "auto" : "smooth" });
541
+ }, [reduced, fade, count]);
542
+ const last = Math.max(0, count - (fade ? 1 : pos.visible));
543
+ const next = useCallback(() => { if (pos.index >= last) {
544
+ if (c.loop)
545
+ goTo(0);
546
+ }
547
+ else
548
+ goTo(pos.index + 1); }, [pos.index, last, c.loop, goTo]);
549
+ const prev = useCallback(() => { if (pos.index <= 0) {
550
+ if (c.loop)
551
+ goTo(last);
552
+ }
553
+ else
554
+ goTo(pos.index - 1); }, [pos.index, last, c.loop, goTo]);
555
+ const running = c.autoplay && !reduced && !paused && !held && last > 0;
556
+ useEffect(() => {
557
+ if (!running)
558
+ return;
559
+ const t = setInterval(() => { if (document.visibilityState === "visible")
560
+ next(); }, c.interval * 1000);
561
+ return () => clearInterval(t);
562
+ }, [running, next, c.interval]);
563
+ const chevron = (d) => _jsx("svg", { viewBox: "0 0 24 24", width: 20, height: 20, fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: _jsx("path", { d: d }) });
564
+ const many = last > 0;
565
+ return (_jsxs("div", { className: "ecx-carousel", role: "region", "aria-roledescription": "carousel", "aria-label": label, style: carouselVars(c), ...carouselData(c), "data-ready": ready ? "" : undefined, onMouseEnter: () => c.hoverPause && setHeld(true), onMouseLeave: () => setHeld(false), onFocus: () => c.hoverPause && setHeld(true), onBlur: () => setHeld(false), children: [_jsx("div", { className: "ecx-carousel-track", ref: track, onScroll: measure, tabIndex: 0, "aria-live": running ? "off" : "polite", onKeyDown: (e) => { if (e.key === "ArrowRight") {
566
+ e.preventDefault();
567
+ next();
568
+ }
569
+ else if (e.key === "ArrowLeft") {
570
+ e.preventDefault();
571
+ prev();
572
+ } }, children: children }), c.arrows && many && _jsxs(_Fragment, { children: [_jsx("button", { type: "button", className: "ecx-carousel-arrow is-prev", "aria-label": "\u2190", disabled: !c.loop && pos.index <= 0, onClick: prev, children: chevron("m15 18-6-6 6-6") }), _jsx("button", { type: "button", className: "ecx-carousel-arrow is-next", "aria-label": "\u2192", disabled: !c.loop && pos.index >= last, onClick: next, children: chevron("m9 18 6-6-6-6") })] }), many && (c.dots || c.autoplay) && (_jsxs("div", { className: "ecx-carousel-dots", children: [c.dots && Array.from({ length: last + 1 }, (_, i) => _jsx("button", { type: "button", className: "ecx-carousel-dot", "aria-label": `${i + 1} / ${last + 1}`, "aria-current": i === pos.index ? "true" : undefined, onClick: () => goTo(i) }, i)), c.autoplay && !reduced && _jsx("button", { type: "button", className: "ecx-carousel-pause", "aria-label": paused ? "▶" : "⏸", "aria-pressed": paused, onClick: () => setPaused(!paused), children: paused ? "▶" : "⏸" })] }))] }));
573
+ }
574
+ /**
575
+ * Popup: nút mở + hộp thoại <dialog> gốc của trình duyệt (khoá focus trong hộp, Esc đóng, trả focus về nút) — nội dung nằm sẵn trong HTML.
576
+ * Bấm nền tối để đóng (khi cho phép), khoá cuộn trang khi mở.
577
+ */
578
+ export function PopupClient({ trigger, triggerClass, triggerStyle, className, style, label, closeButton, closeOnOverlay, children, popupId, auto, autoDelay = 5, autoScroll = 50, onceDays = 0 }) {
579
+ const dlg = useRef(null);
580
+ const root = typeof document !== "undefined" ? document.documentElement : null;
581
+ const close = useCallback(() => dlg.current?.close(), []);
582
+ const onClose = useCallback(() => root?.classList.remove("ecx-popup-open"), [root]);
583
+ useEffect(() => () => root?.classList.remove("ecx-popup-open"), [root]);
584
+ const open = useCallback(() => { const d = dlg.current; if (d && !d.open) {
585
+ d.showModal();
586
+ root?.classList.add("ecx-popup-open");
587
+ } }, [root]);
588
+ // Mở bằng liên kết #popup-<id> / phần tử data-popup-open="<id>" ở bất kỳ đâu, và khi địa chỉ trang có #popup-<id>
589
+ useEffect(() => {
590
+ if (!popupId)
591
+ return;
592
+ const hash = `#popup-${popupId}`;
593
+ const onClick = (e) => {
594
+ const el = e.target?.closest?.(`a[href="${hash}"], [data-popup-open="${popupId}"]`);
595
+ if (el) {
596
+ e.preventDefault();
597
+ open();
598
+ }
599
+ };
600
+ document.addEventListener("click", onClick);
601
+ if (location.hash === hash)
602
+ open();
603
+ return () => document.removeEventListener("click", onClick);
604
+ }, [popupId, open]);
605
+ // Tự mở (một lần theo ngày nếu đặt): trễ / cuộn % / thoát trang / không hoạt động
606
+ useEffect(() => {
607
+ if (!auto || auto === "none")
608
+ return;
609
+ const key = popupId ? `ecx-popup:${popupId}` : "";
610
+ if (key && onceDays > 0) {
611
+ try {
612
+ const t = Number(localStorage.getItem(key));
613
+ if (t && Date.now() - t < onceDays * 864e5)
614
+ return;
615
+ }
616
+ catch { /* trình duyệt chặn lưu trữ: coi như chưa hiện */ }
617
+ }
618
+ let done = false;
619
+ const fire = () => { if (done)
620
+ return; done = true; open(); if (key && onceDays > 0) {
621
+ try {
622
+ localStorage.setItem(key, String(Date.now()));
623
+ }
624
+ catch { /* bỏ qua */ }
625
+ } };
626
+ const off = [];
627
+ if (auto === "delay") {
628
+ const t = setTimeout(fire, autoDelay * 1000);
629
+ off.push(() => clearTimeout(t));
630
+ }
631
+ if (auto === "scroll") {
632
+ const on = () => { const h = document.documentElement; const pct = ((h.scrollTop + window.innerHeight) / Math.max(1, h.scrollHeight)) * 100; if (pct >= autoScroll)
633
+ fire(); };
634
+ window.addEventListener("scroll", on, { passive: true });
635
+ on();
636
+ off.push(() => window.removeEventListener("scroll", on));
637
+ }
638
+ if (auto === "exit") {
639
+ const on = (e) => { if (e.clientY <= 0 && !e.relatedTarget)
640
+ fire(); };
641
+ document.addEventListener("mouseout", on);
642
+ off.push(() => document.removeEventListener("mouseout", on));
643
+ }
644
+ if (auto === "idle") {
645
+ let t = setTimeout(fire, autoDelay * 1000);
646
+ const reset = () => { clearTimeout(t); t = setTimeout(fire, autoDelay * 1000); };
647
+ for (const ev of ["mousemove", "keydown", "scroll", "touchstart", "click"])
648
+ window.addEventListener(ev, reset, { passive: true });
649
+ off.push(() => { clearTimeout(t); for (const ev of ["mousemove", "keydown", "scroll", "touchstart", "click"])
650
+ window.removeEventListener(ev, reset); });
651
+ }
652
+ return () => off.forEach((f) => f());
653
+ }, [auto, autoDelay, autoScroll, onceDays, popupId, open]);
654
+ return (_jsxs("div", { className: className, style: style, children: [trigger !== null && trigger !== undefined && trigger !== "" && _jsx("button", { type: "button", className: triggerClass, style: triggerStyle, "aria-haspopup": "dialog", onClick: (e) => { const d = dlg.current; if (d && !d.open) {
655
+ e.currentTarget.focus(); /* Safari không lấy nét nút khi bấm chuột → đóng popup không có chỗ trả focus */
656
+ d.showModal();
657
+ root?.classList.add("ecx-popup-open");
658
+ } }, children: trigger }), _jsxs("dialog", { ref: dlg, id: popupId ? `popup-${popupId}` : undefined, className: "ecx-popup-dialog", "aria-label": label || undefined, onClose: onClose, onClick: (e) => { if (closeOnOverlay && e.target === dlg.current)
659
+ close(); }, children: [closeButton && _jsx("button", { type: "button", className: "ecx-popup-close", "aria-label": "\u00D7", onClick: close, children: _jsx("svg", { viewBox: "0 0 24 24", width: 18, height: 18, fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", "aria-hidden": "true", children: _jsx("path", { d: "M18 6 6 18M6 6l12 12" }) }) }), _jsx("div", { className: "ecx-popup-body", children: children })] })] }));
660
+ }
661
+ /**
662
+ * Chữ gõ ở cuối Tiêu đề: gõ từng ký tự, dừng, xoá, sang từ kế (lặp hoặc dừng ở từ cuối). HTML dựng sẵn là từ đầu tiên;
663
+ * người xem bật giảm chuyển động thì giữ nguyên từ đầu. Trình đọc màn hình đọc cả nhóm từ một lần (aria-label), không đọc từng ký tự.
664
+ */
665
+ export function TypedText({ words, speed, pause, loop }) {
666
+ const [text, setText] = useState(words[0] ?? "");
667
+ useEffect(() => {
668
+ if (words.length < 2 || (typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches))
669
+ return;
670
+ let i = 0, len = words[0].length, deleting = true, stop = false;
671
+ let t = setTimeout(function tick() {
672
+ if (stop)
673
+ return;
674
+ const w = words[i];
675
+ if (deleting) {
676
+ len--;
677
+ setText(w.slice(0, Math.max(0, len)));
678
+ if (len <= 0) {
679
+ deleting = false;
680
+ i = (i + 1) % words.length;
681
+ if (!loop && i === 0) {
682
+ setText(words[words.length - 1]);
683
+ return;
684
+ }
685
+ }
686
+ t = setTimeout(tick, speed / 2);
687
+ }
688
+ else {
689
+ len++;
690
+ setText(words[i].slice(0, len));
691
+ if (len >= words[i].length) {
692
+ deleting = true;
693
+ if (!loop && i === words.length - 1)
694
+ return;
695
+ t = setTimeout(tick, pause);
696
+ return;
697
+ }
698
+ t = setTimeout(tick, speed);
699
+ }
700
+ }, pause);
701
+ return () => { stop = true; clearTimeout(t); };
702
+ }, [words, speed, pause, loop]);
703
+ return _jsx("span", { className: "ecx-typed", "aria-label": words.join(", "), children: _jsx("span", { "aria-hidden": "true", children: text }) });
704
+ }
705
+ /** Video nền (Ảnh bìa): tự phát, tắt tiếng, lặp, không có điều khiển; người xem bật "giảm chuyển động" thì dừng và chỉ hiện ảnh (poster). */
706
+ export function BgVideo({ src, poster, className, style }) {
707
+ const ref = useRef(null);
708
+ useEffect(() => {
709
+ const v = ref.current;
710
+ if (!v || typeof matchMedia !== "function")
711
+ return;
712
+ const mq = matchMedia("(prefers-reduced-motion: reduce)");
713
+ const apply = () => { if (mq.matches)
714
+ v.pause();
715
+ else
716
+ void v.play().catch(() => { }); };
717
+ apply();
718
+ mq.addEventListener?.("change", apply);
719
+ return () => mq.removeEventListener?.("change", apply);
720
+ }, []);
721
+ return _jsx("video", { ref: ref, className: className, style: style, src: src, poster: poster, autoPlay: true, muted: true, loop: true, playsInline: true, preload: "metadata", "aria-hidden": "true", tabIndex: -1 });
402
722
  }
403
723
  /** Hàng cuộn ngang có nút trước / sau (Query dạng carousel): cuộn đúng một "trang" mỗi lần bấm, ẩn nút ở hai đầu. Không có JS vẫn vuốt / cuộn được. */
404
724
  export function ScrollRow({ children, arrows = true }) {
@@ -451,10 +771,40 @@ export function NavDrawer({ label, closeLabel, children }) {
451
771
  * Thanh lọc của khối Query (GET): ô tìm, mục phân loại (liên kết tới trang mục / nút lọc / ô chọn), sắp xếp.
452
772
  * Giá trị lên URL dạng ?fq_s, ?fq_sort, ?fq_<phân loại>; khối Query bật "Nhận bộ lọc từ thanh lọc" đọc lại. Ô chọn tự gửi khi đổi.
453
773
  */
454
- export function QueryFilterBar({ action, taxonomy, termStyle, terms, currentTerm, values, showSearch, showSort, sorts, labels }) {
774
+ export function QueryFilterBar({ action, taxonomy, termStyle, terms, currentTerm, values, showSearch, showSort, showYear, showReset, years, sorts, labels, range }) {
455
775
  const formRef = useRef(null);
456
776
  const termKey = taxonomy ? `fq_${taxonomy}` : "";
457
777
  const picked = termKey ? values[termKey] ?? "" : "";
458
778
  const submit = () => formRef.current?.requestSubmit();
459
- return (_jsxs(NextForm, { ref: formRef, action: action, className: "ecx-query-filter", role: "search", children: [termStyle === "links" && terms.length > 0 && (_jsxs("nav", { className: "ecx-filter-terms", "aria-label": taxonomy, children: [_jsx(NextLink, { href: action, className: !currentTerm ? "is-active" : undefined, "aria-current": !currentTerm ? "true" : undefined, children: labels.all }), terms.map((t) => _jsx(NextLink, { href: t.link, className: t.slug === currentTerm ? "is-active" : undefined, "aria-current": t.slug === currentTerm ? "true" : undefined, children: t.name }, t.slug))] })), termStyle === "chips" && terms.length > 0 && (_jsxs("fieldset", { className: "ecx-filter-terms", children: [_jsx("legend", { className: "ecx-visually-hidden", children: taxonomy }), _jsxs("label", { className: !picked ? "is-active" : undefined, children: [_jsx("input", { type: "radio", name: termKey, value: "", defaultChecked: !picked, onChange: submit }), labels.all] }), terms.map((t) => _jsxs("label", { className: picked === t.slug ? "is-active" : undefined, children: [_jsx("input", { type: "radio", name: termKey, value: t.slug, defaultChecked: picked === t.slug, onChange: submit }), t.name] }, t.slug))] })), termStyle === "select" && terms.length > 0 && (_jsxs("select", { name: termKey, "aria-label": taxonomy, defaultValue: picked, onChange: submit, children: [_jsx("option", { value: "", children: labels.all }), terms.map((t) => _jsx("option", { value: t.slug, children: t.name }, t.slug))] })), showSearch && _jsx("input", { type: "search", name: "fq_s", defaultValue: values.fq_s ?? "", placeholder: labels.placeholder, "aria-label": labels.search }), showSort && sorts.length > 0 && _jsx("select", { name: "fq_sort", "aria-label": labels.sort, defaultValue: values.fq_sort ?? sorts[0].value, onChange: submit, children: sorts.map((s) => _jsx("option", { value: s.value, children: s.label }, s.value)) }), (showSearch || termStyle === "chips") && _jsx("button", { type: "submit", children: labels.submit })] }));
779
+ // Checkbox nhiều lựa chọn: giữ tập đã chọn, gửi dạng ?fq_<phân loại>=a,b,c
780
+ const [checked, setChecked] = useState(() => picked.split(",").map((x) => x.trim()).filter(Boolean));
781
+ const toggle = (slug) => setChecked((c) => (c.includes(slug) ? c.filter((x) => x !== slug) : [...c, slug]));
782
+ return (_jsxs(NextForm, { ref: formRef, action: action, className: "ecx-query-filter", role: "search", children: [termStyle === "links" && terms.length > 0 && (_jsxs("nav", { className: "ecx-filter-terms", "aria-label": taxonomy, children: [_jsx(NextLink, { href: action, className: !currentTerm ? "is-active" : undefined, "aria-current": !currentTerm ? "true" : undefined, children: labels.all }), terms.map((t) => _jsx(NextLink, { href: t.link, className: t.slug === currentTerm ? "is-active" : undefined, "aria-current": t.slug === currentTerm ? "true" : undefined, children: t.name }, t.slug))] })), termStyle === "chips" && terms.length > 0 && (_jsxs("fieldset", { className: "ecx-filter-terms", children: [_jsx("legend", { className: "ecx-visually-hidden", children: taxonomy }), _jsxs("label", { className: !picked ? "is-active" : undefined, children: [_jsx("input", { type: "radio", name: termKey, value: "", defaultChecked: !picked, onChange: submit }), labels.all] }), terms.map((t) => _jsxs("label", { className: picked === t.slug ? "is-active" : undefined, children: [_jsx("input", { type: "radio", name: termKey, value: t.slug, defaultChecked: picked === t.slug, onChange: submit }), t.name] }, t.slug))] })), termStyle === "checks" && terms.length > 0 && (_jsxs("fieldset", { className: "ecx-filter-terms is-checks", children: [_jsx("legend", { className: "ecx-visually-hidden", children: taxonomy }), terms.map((t) => _jsxs("label", { className: checked.includes(t.slug) ? "is-active" : undefined, children: [_jsx("input", { type: "checkbox", checked: checked.includes(t.slug), onChange: () => { toggle(t.slug); setTimeout(submit, 0); } }), t.name] }, t.slug)), _jsx("input", { type: "hidden", name: termKey, value: checked.join(",") })] })), range && (_jsxs("fieldset", { className: "ecx-filter-range", children: [_jsx("legend", { children: range.label ?? "" }), _jsx("input", { type: "number", inputMode: "numeric", min: 0, max: range.max, name: `fq_${range.param}_min`, defaultValue: values[`fq_${range.param}_min`] ?? "", placeholder: labels.from ?? "Từ", "aria-label": `${range.label ?? range.param}: ${labels.from ?? "Từ"}` }), _jsx("span", { "aria-hidden": "true", children: "\u2013" }), _jsx("input", { type: "number", inputMode: "numeric", min: 0, max: range.max, name: `fq_${range.param}_max`, defaultValue: values[`fq_${range.param}_max`] ?? "", placeholder: labels.to ?? "Đến", "aria-label": `${range.label ?? range.param}: ${labels.to ?? "Đến"}` })] })), termStyle === "select" && terms.length > 0 && (_jsxs("select", { name: termKey, "aria-label": taxonomy, defaultValue: picked, onChange: submit, children: [_jsx("option", { value: "", children: labels.all }), terms.map((t) => _jsx("option", { value: t.slug, children: t.name }, t.slug))] })), showSearch && _jsx("input", { type: "search", name: "fq_s", defaultValue: values.fq_s ?? "", placeholder: labels.placeholder, "aria-label": labels.search }), showSort && sorts.length > 0 && _jsx("select", { name: "fq_sort", "aria-label": labels.sort, defaultValue: values.fq_sort ?? sorts[0].value, onChange: submit, children: sorts.map((s) => _jsx("option", { value: s.value, children: s.label }, s.value)) }), showYear && years.length > 0 && _jsxs("select", { name: "fq_year", "aria-label": labels.year, defaultValue: values.fq_year ?? "", onChange: submit, children: [_jsx("option", { value: "", children: labels.year }), years.map((y) => _jsx("option", { value: y, children: y }, y))] }), (showSearch || termStyle === "chips" || !!range) && _jsx("button", { type: "submit", children: labels.submit }), showReset && (Object.keys(values).some((k) => k.startsWith("fq_")) || !!currentTerm) && _jsx(NextLink, { href: action, className: "ecx-filter-reset", children: labels.reset })] }));
783
+ }
784
+ /** Khối theo nhóm người xem: kiểm ở trình duyệt (trang vẫn cache được). Chưa biết người xem → ẩn; khớp nhóm → hiện. */
785
+ export function AudienceGate({ audience, children }) {
786
+ const user = useCurrentUser();
787
+ const show = user !== undefined && (audience === "user") === !!user;
788
+ return _jsx("div", { className: "ecx-aud", "data-aud": audience, hidden: !show, children: children });
789
+ }
790
+ /** Gallery dạng thumbnail slider: ảnh lớn + dải ảnh nhỏ bấm / bàn phím (← → Home End) đổi ảnh lớn. */
791
+ export function GalleryThumbsClient({ mains, thumbs, label }) {
792
+ const [active, setActive] = useState(0);
793
+ const go = (n) => setActive(((n % mains.length) + mains.length) % mains.length);
794
+ return (_jsxs("div", { className: "ecx-gallery-thumbs", "aria-roledescription": "carousel", "aria-label": label, children: [_jsx("div", { className: "ecx-gt-main", role: "tabpanel", "aria-live": "polite", children: mains[active] }), _jsx("div", { className: "ecx-gt-strip", role: "tablist", "aria-label": label, onKeyDown: (e) => { const k = e.key; if (k === "ArrowRight" || k === "ArrowDown") {
795
+ e.preventDefault();
796
+ go(active + 1);
797
+ }
798
+ else if (k === "ArrowLeft" || k === "ArrowUp") {
799
+ e.preventDefault();
800
+ go(active - 1);
801
+ }
802
+ else if (k === "Home") {
803
+ e.preventDefault();
804
+ go(0);
805
+ }
806
+ else if (k === "End") {
807
+ e.preventDefault();
808
+ go(mains.length - 1);
809
+ } }, children: thumbs.map((t, i) => _jsx("button", { type: "button", role: "tab", className: "ecx-gt-thumb", "aria-selected": i === active, tabIndex: i === active ? 0 : -1, "aria-label": `${i + 1} / ${thumbs.length}`, onClick: () => setActive(i), children: t }, i)) })] }));
460
810
  }
package/dist/content.js CHANGED
@@ -1,5 +1,5 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { ExtensionBoundary, Link, PostPasswordForm } from "./client.js";
1
+ import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { ExtensionBoundary, PostPasswordForm } from "./client.js";
3
3
  import { applyFilters, findBlock, findRegion, findShortcode, getActiveExtensions, getActiveTheme } from "./runtime.js";
4
4
  import { getPattern, getSite, getTemplates } from "./api.js";
5
5
  import { CORE_BINDING_SOURCES } from "./bindings.js";
@@ -20,42 +20,10 @@ export async function PostContent({ post, content, className, page }) {
20
20
  }
21
21
  if (!doc?.blocks?.length)
22
22
  return null;
23
- // Khối pageBreak chia bài thành nhiều trang (?trang=N): chỉ vẽ trang đang xem + thanh chuyển trang
24
- let total = 1;
25
- const current = Math.max(1, Math.floor(Number(page)) || 1);
26
- const rendered = await renderContent(doc, { ...(await contentContext(site, post)), source: post ? `post:${post.id}` : undefined }, async (blocks) => {
27
- const pages = splitPages(await applyFilters("post.blocks", blocks, { site, post }, site));
28
- total = pages.length;
29
- return pages[Math.min(current, total) - 1];
30
- });
31
- const n = Math.min(current, total);
32
- const t = total > 1 ? await getT() : null;
33
- const href = (i) => (post?.link ?? "") + (i > 1 ? `?trang=${i}` : "");
34
- return (_jsxs("div", { className: cx(className ?? "entry-content", "ecx-content"), children: [rendered, t && post && (_jsxs("nav", { className: "ecx-page-links", "aria-label": t("pagination.label"), children: [n > 1 && _jsx(Link, { href: href(n - 1), rel: "prev", children: t("pagination.prev") }), Array.from({ length: total }, (_, i) => i + 1).map((i) => i === n ? _jsx("span", { "aria-current": "page", children: i }, i) : _jsx(Link, { href: href(i), children: i }, i)), n < total && _jsx(Link, { href: href(n + 1), rel: "next", children: t("pagination.next") })] }))] }));
35
- }
36
- /** Cắt khối richtext tại mỗi `pageBreak` cấp cao nhất; khối khác nằm ở trang đang mở. Không có pageBreak → một trang. */
37
- function splitPages(blocks) {
38
- const pages = [[]];
39
- for (const b of blocks) {
40
- const nodes = b.type === "richtext" ? (b.data?.content ?? []) : [];
41
- if (!nodes.some((x) => x.type === "pageBreak")) {
42
- pages[pages.length - 1].push(b);
43
- continue;
44
- }
45
- let seg = [];
46
- const flush = () => { if (seg.length)
47
- pages[pages.length - 1].push({ ...b, data: { ...b.data, content: seg } }); seg = []; };
48
- for (const x of nodes) {
49
- if (x.type === "pageBreak") {
50
- flush();
51
- pages.push([]);
52
- }
53
- else
54
- seg.push(x);
55
- }
56
- flush();
57
- }
58
- return pages.filter((p, i) => p.length || i === 0);
23
+ // 2 (v3): khối "Ngắt trang" đã bỏ — bài luôn hiện trên một trang (`page` giữ lại cho theme cũ, không còn tác dụng)
24
+ void page;
25
+ const rendered = await renderContent(doc, { ...(await contentContext(site, post)), source: post ? `post:${post.id}` : undefined }, async (blocks) => applyFilters("post.blocks", blocks, { site, post }, site));
26
+ return _jsx("div", { className: cx(className ?? "entry-content", "ecx-content"), children: rendered });
59
27
  }
60
28
  /**
61
29
  * Vùng của theme: header, footer (vùng chuẩn của core — nên luôn bọc) và vùng hybrid khai báo ở theme.json › regions.
package/dist/dynamic.js CHANGED
@@ -9,7 +9,7 @@ import { applyFilters } from "./runtime.js";
9
9
  import { localeHref } from "./locale.js";
10
10
  import { renderContent } from "./rich.js";
11
11
  import { cx } from "./utils.js";
12
- import { spacingValue } from "@ecomcx/ecomweb-content";
12
+ import { applyPatternOverrides, spacingValue } from "@ecomcx/ecomweb-content";
13
13
  const align = (a) => (a.textAlign && a.textAlign !== "left" ? { textAlign: a.textAlign } : undefined);
14
14
  const ASPECT = { "16/9": "16 / 9", "4/3": "4 / 3", "1/1": "1 / 1", "3/4": "3 / 4" };
15
15
  /**
@@ -220,10 +220,10 @@ export async function renderDynamic(node, key, ctx, children) {
220
220
  }
221
221
  case "queryFilter": {
222
222
  const taxonomy = /^[a-z0-9_-]{1,64}$/i.test(String(a.taxonomy ?? "")) ? String(a.taxonomy) : undefined;
223
- const style = ["none", "links", "chips", "select"].includes(a.termStyle) ? a.termStyle : "links";
223
+ const style = ["none", "links", "chips", "select", "checks"].includes(a.termStyle) ? a.termStyle : "links";
224
224
  const [t, terms] = await Promise.all([getT(), taxonomy && style !== "none" ? getTerms({ taxonomy, hideEmpty: true }).catch(() => []) : Promise.resolve([])]);
225
225
  const sorts = String(a.sortOptions ?? "date_desc,date_asc,title_asc,title_desc").split(",").map((x) => x.trim()).filter((x) => SORTS[x]);
226
- return _jsx(QueryFilterBar, { action: String(a.action || ctx.data?.basePath || "/"), taxonomy: taxonomy, termStyle: style, terms: terms.map((x) => ({ slug: x.slug, name: x.name, link: x.link })), currentTerm: ctx.data?.term?.slug, values: ctx.data?.query ?? {}, showSearch: a.showSearch === true, showSort: a.showSort === true, sorts: sorts.map((x) => ({ value: x, label: t(`filter.sort.${x}`) })), labels: { all: String(a.allLabel || t("filter.all")), search: t("search.label"), placeholder: String(a.placeholder || t("filter.search")), submit: String(a.submitText || t("filter.apply")), sort: t("filter.sort") } }, key);
226
+ return _jsx(QueryFilterBar, { action: String(a.action || ctx.data?.basePath || "/"), taxonomy: taxonomy, termStyle: style, terms: terms.map((x) => ({ slug: x.slug, name: x.name, link: x.link })), currentTerm: ctx.data?.term?.slug, values: ctx.data?.query ?? {}, showSearch: a.showSearch === true, showSort: a.showSort === true, range: a.showRange === true && /^[a-z][a-z0-9_]{0,30}$/.test(String(a.rangeParam ?? "")) ? { param: String(a.rangeParam), label: a.rangeLabel ? String(a.rangeLabel) : undefined, max: Number(a.rangeMax) > 0 ? Number(a.rangeMax) : undefined } : undefined, showYear: a.showYear === true, showReset: a.showReset === true, years: a.showYear === true ? Array.from({ length: 8 }, (_, i) => new Date().getUTCFullYear() - i) : [], sorts: sorts.map((x) => ({ value: x, label: t(`filter.sort.${x}`) })), labels: { all: String(a.allLabel || t("filter.all")), search: t("search.label"), placeholder: String(a.placeholder || t("filter.search")), submit: String(a.submitText || t("filter.apply")), sort: t("filter.sort"), year: t("filter.year"), reset: t("filter.reset"), from: t("filter.from"), to: t("filter.to") } }, key);
227
227
  }
228
228
  case "postTemplate": {
229
229
  const posts = ctx.query?.posts ?? [];
@@ -252,9 +252,10 @@ export async function renderDynamic(node, key, ctx, children) {
252
252
  case "syncedPattern": {
253
253
  if (typeof a.ref !== "number" || !ctx.pattern || (ctx.partDepth ?? 0) >= 4)
254
254
  return null;
255
- const doc = await ctx.pattern(a.ref);
256
- if (!doc)
255
+ const base = await ctx.pattern(a.ref);
256
+ if (!base)
257
257
  return null;
258
+ const doc = applyPatternOverrides(base, a.overrides); // 1.32: chỗ dùng mẫu sửa riêng vài ô (khối có overrideKey trong mẫu)
258
259
  return _jsx(Fragment, { children: await renderContent(doc, { ...ctx, partDepth: (ctx.partDepth ?? 0) + 1, source: `pattern:${a.ref}` }) }, key);
259
260
  }
260
261
  case "templatePart": {
package/dist/i18n.js CHANGED
@@ -5,7 +5,7 @@ import { formatMessage } from "./i18n-format.js";
5
5
  /** Chữ mặc định của các component trong SDK (theme có thể ghi đè trong locales/{code}.json). */
6
6
  export const BUILTIN = {
7
7
  vi: {
8
- "search.placeholder": "Tìm kiếm…", "search.button": "Tìm", "search.label": "Từ khoá", "filter.all": "Tất cả", "filter.search": "Tìm trong danh sách…", "filter.apply": "Lọc", "filter.sort": "Sắp xếp", "filter.sort.date_desc": "Mới nhất", "filter.sort.date_asc": "Cũ nhất", "filter.sort.title_asc": "Tên A → Z", "filter.sort.title_desc": "Tên Z → A", "filter.sort.modified_desc": "Mới cập nhật", "filter.sort.rand": "Ngẫu nhiên", "search.scope": "Phạm vi tìm kiếm", "search.all": "Tất cả", "navigation.menu": "Menu", "navigation.close": "Đóng menu", "toc.title": "Mục lục", "query.search": "Kết quả tìm kiếm: {q}", "query.category": "Chuyên mục: {name}", "query.tag": "Thẻ: {name}", "query.author": "Tác giả: {name}", "breadcrumbs.home": "Trang chủ", "breadcrumbs.label": "Đường dẫn", "postNav.previous": "Bài trước", "postNav.next": "Bài sau", "postNav.label": "Bài khác",
8
+ "search.placeholder": "Tìm kiếm…", "search.button": "Tìm", "search.label": "Từ khoá", "filter.all": "Tất cả", "filter.search": "Tìm trong danh sách…", "filter.apply": "Lọc", "form.next": "Tiếp theo", "form.back": "Quay lại", "form.step": "Bước {n}/{total}", "filter.year": "Năm", "filter.from": "Từ", "filter.to": "Đến", "filter.reset": "Xoá bộ lọc", "filter.sort": "Sắp xếp", "filter.sort.date_desc": "Mới nhất", "filter.sort.date_asc": "Cũ nhất", "filter.sort.title_asc": "Tên A → Z", "filter.sort.title_desc": "Tên Z → A", "filter.sort.modified_desc": "Mới cập nhật", "filter.sort.rand": "Ngẫu nhiên", "search.scope": "Phạm vi tìm kiếm", "search.all": "Tất cả", "navigation.menu": "Menu", "navigation.close": "Đóng menu", "toc.title": "Mục lục", "query.search": "Kết quả tìm kiếm: {q}", "query.category": "Chuyên mục: {name}", "query.tag": "Thẻ: {name}", "query.author": "Tác giả: {name}", "breadcrumbs.home": "Trang chủ", "breadcrumbs.label": "Đường dẫn", "postNav.previous": "Bài trước", "postNav.next": "Bài sau", "postNav.label": "Bài khác",
9
9
  "post.read_more": "Đọc tiếp", "pagination.prev": "« Trước", "pagination.next": "Sau »", "pagination.label": "Phân trang",
10
10
  "comments.title": "Bình luận", "comments.closed": "Bình luận đã đóng.", "countdown.d": "ngày", "countdown.h": "giờ", "countdown.m": "phút", "countdown.s": "giây",
11
11
  "comments.form.title": "Để lại bình luận", "comments.form.content": "Bình luận", "comments.form.name": "Tên",
@@ -31,7 +31,7 @@ export const BUILTIN = {
31
31
  "styleBook.title": "Mẫu kiểu dáng", "styleBook.h": "Tiêu đề", "styleBook.para": "Đoạn văn mẫu: chữ của bài viết trên website hiển thị như thế này.", "styleBook.bold": "chữ đậm", "styleBook.italic": "chữ nghiêng", "styleBook.link": "liên kết", "styleBook.item": "Mục", "styleBook.quote": "Trích dẫn mẫu: một câu đáng nhớ.", "styleBook.cite": "Tác giả", "styleBook.button": "Nút bấm", "styleBook.callout": "Hộp lưu ý: thông tin cần chú ý.", "styleBook.group": "Nhóm có nền", "styleBook.column": "Cột", "styleBook.details": "Bấm để xem thêm", "styleBook.cover": "Ảnh bìa",
32
32
  },
33
33
  en: {
34
- "search.placeholder": "Search…", "search.button": "Search", "search.label": "Keyword", "filter.all": "All", "filter.search": "Search this list…", "filter.apply": "Filter", "filter.sort": "Sort by", "filter.sort.date_desc": "Newest", "filter.sort.date_asc": "Oldest", "filter.sort.title_asc": "Name A → Z", "filter.sort.title_desc": "Name Z → A", "filter.sort.modified_desc": "Recently updated", "filter.sort.rand": "Random", "search.scope": "Search in", "search.all": "All", "navigation.menu": "Menu", "navigation.close": "Close menu", "toc.title": "Contents", "query.search": "Search results: {q}", "query.category": "Category: {name}", "query.tag": "Tag: {name}", "query.author": "Author: {name}", "breadcrumbs.home": "Home", "breadcrumbs.label": "Breadcrumb", "postNav.previous": "Previous", "postNav.next": "Next", "postNav.label": "More posts",
34
+ "search.placeholder": "Search…", "search.button": "Search", "search.label": "Keyword", "filter.all": "All", "filter.search": "Search this list…", "filter.apply": "Filter", "form.next": "Next", "form.back": "Back", "form.step": "Step {n}/{total}", "filter.year": "Year", "filter.from": "From", "filter.to": "To", "filter.reset": "Clear filters", "filter.sort": "Sort by", "filter.sort.date_desc": "Newest", "filter.sort.date_asc": "Oldest", "filter.sort.title_asc": "Name A → Z", "filter.sort.title_desc": "Name Z → A", "filter.sort.modified_desc": "Recently updated", "filter.sort.rand": "Random", "search.scope": "Search in", "search.all": "All", "navigation.menu": "Menu", "navigation.close": "Close menu", "toc.title": "Contents", "query.search": "Search results: {q}", "query.category": "Category: {name}", "query.tag": "Tag: {name}", "query.author": "Author: {name}", "breadcrumbs.home": "Home", "breadcrumbs.label": "Breadcrumb", "postNav.previous": "Previous", "postNav.next": "Next", "postNav.label": "More posts",
35
35
  "post.read_more": "Read more", "pagination.prev": "« Previous", "pagination.next": "Next »", "pagination.label": "Pagination",
36
36
  "comments.title": "Comments", "comments.closed": "Comments are closed.", "countdown.d": "d", "countdown.h": "h", "countdown.m": "m", "countdown.s": "s",
37
37
  "comments.form.title": "Leave a comment", "comments.form.content": "Comment", "comments.form.name": "Name",
@@ -0,0 +1,12 @@
1
+ import { type ReactNode } from "react";
2
+ /**
3
+ * Vẽ icon theo giá trị lưu (tên trong bảng / thư viện, hoặc SVG riêng `svg:…` đã lọc lại ở đây). Không có icon → null.
4
+ * Dùng cho khối Icon, icon của tab… (server và client).
5
+ */
6
+ export declare function iconSvg(value: unknown, o?: {
7
+ size?: number;
8
+ stroke?: number;
9
+ className?: string;
10
+ label?: string;
11
+ key?: string;
12
+ }): ReactNode;
@@ -0,0 +1,21 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createElement } from "react";
3
+ import { resolveIcon } from "@ecomcx/ecomweb-content";
4
+ const camel = (props) => Object.fromEntries(Object.entries(props).map(([k, v]) => [k.replace(/-([a-z])/g, (_, c) => c.toUpperCase()), v]));
5
+ const node = (n, key) => createElement(n.tag, { key, ...camel(n.props) }, ...n.children.map(node));
6
+ /**
7
+ * Vẽ icon theo giá trị lưu (tên trong bảng / thư viện, hoặc SVG riêng `svg:…` đã lọc lại ở đây). Không có icon → null.
8
+ * Dùng cho khối Icon, icon của tab… (server và client).
9
+ */
10
+ export function iconSvg(value, o = {}) {
11
+ const r = resolveIcon(value);
12
+ if (!r)
13
+ return null;
14
+ const size = o.size ?? 24;
15
+ const a11y = o.label ? { role: "img", "aria-label": o.label } : { "aria-hidden": true, focusable: "false" };
16
+ if (r.kind === "svg") {
17
+ const root = camel(r.icon.root);
18
+ return _jsx("svg", { className: o.className, width: size, height: size, viewBox: r.icon.viewBox, fill: root.fill ?? "currentColor", ...(root.stroke ? { stroke: root.stroke } : {}), ...(root.strokeWidth ? { strokeWidth: root.strokeWidth } : {}), ...(root.strokeLinecap ? { strokeLinecap: root.strokeLinecap } : {}), ...(root.strokeLinejoin ? { strokeLinejoin: root.strokeLinejoin } : {}), ...a11y, children: r.icon.children.map(node) }, o.key);
19
+ }
20
+ return _jsx("svg", { className: o.className, width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: o.stroke ?? 2, strokeLinecap: "round", strokeLinejoin: "round", ...a11y, children: _jsx("path", { d: r.d }) }, o.key);
21
+ }