@ecomcx/ecomweb-theme-sdk 2.0.0 → 2.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.
package/dist/rich.js CHANGED
@@ -1,9 +1,11 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { Fragment, cloneElement, createElement, isValidElement } from "react";
3
- import { DYNAMIC_NODES, ICON_PATHS, countdownTarget, nodeText, buttonIcon, widgetMarkup, tabsClass, formSizeClass, widthClass, blockCitation, blockShell, buttonWrapShell, coverParts, linkRel, embedInfo, motionClasses, normalizeContent, safeUrl, styleClass, styleCss, controlsCss, CORE_CONTROLS } from "@ecomcx/ecomweb-content";
3
+ import { ICON_LIBRARY } from "@ecomcx/ecomweb-content/icon-library";
4
+ import { iconSvg } from "./icon-svg.js";
5
+ import { BINDING_URL_ATTRS, CORE_BINDABLE, registerIconLibrary, tableClass, blockBgVideo, typedConfig, coverVideo, scheduleVisible, normalizeStyle, imageFx, countdownRules, testimonialsConfig, testimonialsVars, popupClass, popupConfig, popupPlayStyle, popupVars, carouselConfig, DYNAMIC_NODES, countdownTarget, nodeText, buttonIcon, widgetMarkup, tabsClass, formSizeClass, widthClass, blockCitation, blockShell, buttonWrapShell, coverParts, linkRel, embedInfo, motionClasses, normalizeContent, safeUrl, styleClass, styleCss, controlsCss, CORE_CONTROLS } from "@ecomcx/ecomweb-content";
4
6
  import { cx } from "./utils.js";
5
7
  import { SOCIAL_ICONS } from "./social-icons.js";
6
- import { CountdownClient, FormBlockClient, LightboxClient, Link, TabsClient, TocSpy } from "./client.js";
8
+ import { GalleryThumbsClient, AudienceGate, TypedText, BgVideo, PopupClient, CarouselClient, CountdownClient, FormBlockClient, LightboxClient, Link, TabsClient, TocSpy } from "./client.js";
7
9
  import { CounterClient } from "./counter-client.js";
8
10
  import { AssetScript } from "./browser.js";
9
11
  import { getT } from "./i18n.js";
@@ -100,10 +102,11 @@ function renderMarks(text, marks, key, ctx) {
100
102
  out = _jsx("code", { children: out }, k);
101
103
  break;
102
104
  case "footnote": {
105
+ // 2 (v3): khối "Chú thích cuối trang" đã bỏ — dấu [n] giữ lại, nội dung chú thích hiện khi rê chuột
103
106
  const f = ctx?.footnotes;
104
107
  const n = f ? f.notes.findIndex((x) => x.mark === m) + 1 : 0;
105
108
  if (n > 0)
106
- out = _jsxs(Fragment, { children: [out, _jsx("sup", { className: "ecx-footnote-ref", id: `fnref-${f.prefix}-${n}`, children: _jsxs("a", { href: `#fn-${f.prefix}-${n}`, children: ["[", n, "]"] }) })] }, k);
109
+ out = _jsxs(Fragment, { children: [out, _jsxs("sup", { className: "ecx-footnote-ref", title: typeof m.attrs?.note === "string" ? m.attrs.note : undefined, children: ["[", n, "]"] })] }, k);
107
110
  break;
108
111
  }
109
112
  case "kbd":
@@ -124,7 +127,7 @@ function renderMarks(text, marks, key, ctx) {
124
127
  case "link": {
125
128
  const target = m.attrs?.target;
126
129
  const href = safeUrl(m.attrs?.href);
127
- out = href ? _jsx(Link, { href: href, target: target ?? undefined, rel: linkRel(m.attrs?.rel, target), children: out }, k) : _jsx("a", { children: out }, k);
130
+ out = ctx?.inLink ? out : href ? _jsx(Link, { href: href, target: target ?? undefined, rel: linkRel(m.attrs?.rel, target), children: out }, k) : _jsx("a", { children: out }, k);
128
131
  break;
129
132
  }
130
133
  }
@@ -201,15 +204,13 @@ function widgetEl(el, key) {
201
204
  return el.tag === "a" ? _jsx(Link, { ...props, href: String(el.props?.href ?? ""), children: kids }) : createElement(el.tag, props, ...kids);
202
205
  }
203
206
  /** Thuộc tính gắn được của khối lõi (ngoài danh sách bị bỏ qua). */
204
- const BINDABLE = { paragraph: ["content"], heading: ["content"], image: ["src", "alt", "caption"], button: ["text", "href"] };
205
- const URL_ATTRS = new Set(["src", "href"]);
206
207
  /**
207
208
  * Áp gắn dữ liệu: thay chữ / thuộc tính bằng giá trị của nguồn lúc hiển thị. Giá trị là chữ thường (không HTML), đường dẫn qua safeUrl;
208
209
  * nguồn không có / trả về rỗng → giữ nội dung gõ tay. Lỗi của nguồn (plugin) chỉ bỏ qua thuộc tính đó.
209
210
  */
210
211
  async function applyBindings(node, ctx) {
211
212
  const bindings = node.attrs?.bindings;
212
- const allowed = BINDABLE[node.type];
213
+ const allowed = CORE_BINDABLE[node.type];
213
214
  if (!bindings || !allowed || !ctx.binding)
214
215
  return node;
215
216
  let out = node;
@@ -224,12 +225,15 @@ async function applyBindings(node, ctx) {
224
225
  console.warn(`[cms] binding ${b.source} lỗi:`, e.message);
225
226
  continue;
226
227
  }
227
- if (v === null || v === undefined || v === "")
228
+ if (v === null || v === undefined || v === "") {
229
+ if (b.args?.hideIfEmpty === true)
230
+ return null; // "Ẩn khi rỗng": khối không có giá trị thì không vẽ (vd % giảm khi không giảm giá)
228
231
  continue;
232
+ }
229
233
  const text = String(v);
230
234
  if (attr === "content")
231
235
  out = { ...out, content: [{ type: "text", text }] };
232
- else if (URL_ATTRS.has(attr)) {
236
+ else if (BINDING_URL_ATTRS.has(attr)) {
233
237
  const u = safeUrl(text, "");
234
238
  if (u)
235
239
  out = { ...out, attrs: { ...out.attrs, [attr]: u } };
@@ -239,9 +243,20 @@ async function applyBindings(node, ctx) {
239
243
  }
240
244
  return out;
241
245
  }
246
+ // Thư viện ~1.900 icon: nạp một lần khi module chạy (máy chủ) → mọi khối có icon vẽ được tên trong thư viện
247
+ registerIconLibrary(ICON_LIBRARY);
248
+ /** Video nền của Section / Row / Column (style.background.video): thẻ <video> tự phát, tắt tiếng, lặp, nằm dưới nội dung. */
249
+ const bgVideoNode = (a) => { const v = a?.style ? blockBgVideo(a.style) : null; return v ? _jsx(BgVideo, { className: "ecx-bg-video", src: v }, "bgv") : null; };
242
250
  async function renderNode(node, key, ctx) {
243
- if (node.attrs?.bindings)
244
- node = await applyBindings(node, ctx);
251
+ // Lịch hiển thị (tab Nâng cao): ngoài khoảng [from, until) thì website không vẽ khối (trình soạn vẫn hiện để sửa)
252
+ if (node.type !== "text" && node.attrs?.style && typeof node.attrs.style === "object" && node.attrs.style.schedule && !scheduleVisible(normalizeStyle(node.attrs.style)))
253
+ return null;
254
+ if (node.attrs?.bindings) {
255
+ const bound = await applyBindings(node, ctx);
256
+ if (!bound)
257
+ return null;
258
+ node = bound;
259
+ }
245
260
  let el = await renderNodeInner(node, key, ctx);
246
261
  if (ctx.filterBlock && node.type !== "text" && node.type !== "doc")
247
262
  el = await ctx.filterBlock(node, el);
@@ -259,13 +274,16 @@ async function renderNode(node, key, ctx) {
259
274
  const given = pick?.filter((k) => !emptyAttr(a?.[k]));
260
275
  const data = pick && (!pick.length || given.length) ? { "data-ecx-ready": node.type, "data-ecx-attrs": JSON.stringify(Object.fromEntries(given.map((k) => [k, a[k]]))) } : undefined;
261
276
  const out = (a && (a.style || a.blockStyle || a.className || a.anchor || widthClass(node.type, a))) || ctrl || data ? decorate(el, a ?? {}, key, ctx, node.type, ctrl, data) : el;
262
- return ctx.markBlocks && ctx.source && ctx.pathRoot != null && key.startsWith(ctx.pathRoot + "-") && !UNMARKED.has(node.type)
277
+ const marked = ctx.markBlocks && ctx.source && ctx.pathRoot != null && key.startsWith(ctx.pathRoot + "-") && !UNMARKED.has(node.type)
263
278
  ? markBlock(out, ctx.source, key.slice(ctx.pathRoot.length + 1), key)
264
279
  : out;
280
+ // Nhóm người xem (tab Nâng cao): bỏ qua ở trình soạn (markBlocks) để vẫn sửa được
281
+ const aud = node.type !== "text" && !ctx.markBlocks && node.attrs?.style ? normalizeStyle(node.attrs.style)?.audience : undefined;
282
+ return aud && marked != null ? _jsx(AudienceGate, { audience: aud, children: marked }, key) : marked;
265
283
  }
266
284
  const emptyAttr = (v) => v === undefined || v === null || v === "" || (Array.isArray(v) && !v.length);
267
285
  /** Nút không chọn riêng được trong khung soạn (hoặc bọc thêm thẻ sẽ sai cấu trúc HTML: li trong ul, ô trong bảng). */
268
- const UNMARKED = new Set(["text", "hardBreak", "listItem", "taskItem", "tableRow", "tableCell", "tableHeader"]);
286
+ const UNMARKED = new Set(["text", "hardBreak", "listItem", "tableRow", "tableCell", "tableHeader"]);
269
287
  /** Gắn vị trí khối: thẻ HTML thì thêm thuộc tính, component thì bọc thẻ display:contents (không đổi bố cục). */
270
288
  function markBlock(el, source, path, key) {
271
289
  if (el == null || el === false)
@@ -296,38 +314,35 @@ async function renderNodeInner(node, key, ctx) {
296
314
  return shelled("paragraph", a, key, await children());
297
315
  }
298
316
  case "heading": {
299
- return shelled("heading", a, key, await children(), { id: headingId(node) || undefined });
317
+ // Chữ gõ ở cuối tiêu đề (heading.typedWords): HTML dựng sẵn có từ đầu tiên, trình duyệt gõ lần lượt các từ
318
+ const typed = typedConfig(a);
319
+ const hHref = safeUrl(a.href, "");
320
+ const kids = hHref ? await Promise.all((node.content ?? []).map((c, i) => renderNode(c, `${key}-${i}`, { ...ctx, inLink: true }))) : await children();
321
+ const inner = typed ? _jsxs(_Fragment, { children: [kids, " ", _jsx(TypedText, { words: typed.words, speed: typed.speed, pause: typed.pause, loop: typed.loop })] }) : kids;
322
+ // 1.32: liên kết cả tiêu đề
323
+ const body = hHref ? _jsx(Link, { className: "ecx-heading-link", href: hHref, target: a.linkTarget === "_blank" ? "_blank" : undefined, rel: linkRel(a.linkRel, a.linkTarget), children: inner }) : inner;
324
+ return shelled("heading", a, key, body, { id: headingId(node) || undefined });
300
325
  }
301
326
  case "bulletList": return _jsx("ul", { children: await children() }, key);
302
327
  case "orderedList": return _jsx("ol", { start: a.start && a.start !== 1 ? a.start : undefined, reversed: a.reversed === true || undefined, children: await children() }, key);
303
328
  case "listItem": return _jsx("li", { children: await children() }, key);
304
- case "taskList": return _jsx("ul", { className: "ecx-task-list task-list", children: await children() }, key);
305
- case "taskItem": return _jsxs("li", { className: "ecx-task-item task-item", children: [_jsx("input", { type: "checkbox", checked: !!a.checked, readOnly: true }), " ", await children()] }, key);
306
329
  case "blockquote": return shelled("blockquote", a, key, _jsxs(_Fragment, { children: [await children(), blockCitation(a) && _jsx("cite", { children: blockCitation(a) })] }));
307
330
  case "codeBlock": return _jsx("pre", { children: _jsx("code", { className: a.language ? `language-${a.language}` : undefined, children: plainText(node) }) }, key);
308
331
  case "hardBreak": return _jsx("br", {}, key);
309
- case "pageBreak": return null;
310
- case "footnotes": {
311
- const f = ctx.footnotes;
312
- if (!f?.notes.length)
313
- return null;
314
- return (_jsxs("aside", { className: "ecx-footnotes", children: [a.title && _jsx("p", { className: "ecx-footnotes-title", children: a.title }), _jsx("ol", { children: f.notes.map((x, i) => _jsxs("li", { id: `fn-${f.prefix}-${i + 1}`, children: [x.note, " ", _jsx("a", { href: `#fnref-${f.prefix}-${i + 1}`, "aria-label": "\u21A9", children: "\u21A9" })] }, i)) })] }, key));
315
- }
316
332
  case "icon": {
317
- const path = ICON_PATHS[String(a.name)];
318
- if (!path)
319
- return null;
320
333
  const size = Math.min(128, Math.max(12, Number(a.size) || 24));
321
334
  const stroke = Math.min(4, Math.max(0.5, Number(a.stroke) || 2));
322
335
  const shape = a.iconStyle === "circle" || a.iconStyle === "square" ? a.iconStyle : undefined;
323
- const svg = _jsx("svg", { width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: stroke, strokeLinecap: "round", strokeLinejoin: "round", role: a.label ? "img" : undefined, "aria-label": a.label || undefined, "aria-hidden": a.label ? undefined : true, children: _jsx("path", { d: path }) });
336
+ const tip = typeof a.tooltip === "string" && a.tooltip.trim() ? a.tooltip.trim().slice(0, 120) : undefined;
337
+ const svg = iconSvg(a.name, { size, stroke, label: a.label ? String(a.label) : undefined });
338
+ if (!svg)
339
+ return null;
324
340
  const href = safeUrl(a.href, "");
325
- const cls = `ecx-icon-shape${shape ? ` is-${shape}` : ""}`, pad = shape ? { padding: Math.round(size * 0.4) } : undefined;
341
+ const cls = `ecx-icon-shape${shape ? ` is-${shape}` : ""}`, pad = shape ? { "--ecx-icon-pad-auto": `${Math.round(size * 0.4)}px` } : undefined;
326
342
  return _jsx("div", { className: "ecx-icon-block", style: alignStyle(a), children: href
327
- ? _jsx(Link, { href: href, className: cls, style: pad, ...(a.linkTarget === "_blank" ? { target: "_blank", rel: "noopener noreferrer" } : {}), children: svg })
328
- : _jsx("span", { className: cls, style: pad, children: svg }) }, key);
343
+ ? _jsx(Link, { href: href, className: cls, style: pad, "data-ecx-tip": tip, ...(a.linkTarget === "_blank" ? { target: "_blank", rel: "noopener noreferrer" } : {}), children: svg })
344
+ : _jsx("span", { className: cls, style: pad, "data-ecx-tip": tip, children: svg }) }, key);
329
345
  }
330
- case "horizontalRule": return _jsx("hr", {}, key);
331
346
  case "image": {
332
347
  // Ảnh chèn từ thư viện mang sẵn srcset (JPEG + WebP) và kích thước → responsive, không nhảy layout
333
348
  // Bề rộng hiển thị = cỡ người viết kéo trong trình soạn → trình duyệt chọn file vừa đúng
@@ -335,7 +350,8 @@ async function renderNodeInner(node, key, ctx) {
335
350
  const imgSrc = safeUrl(a.src, "");
336
351
  if (!imgSrc)
337
352
  return null; // chưa chọn ảnh: không in <img> không có địa chỉ (hiện icon ảnh hỏng)
338
- const img = _jsx("img", { src: imgSrc, srcSet: a.srcset || undefined, sizes: a.srcset ? sizes : undefined, alt: a.alt ?? "", title: a.title ?? undefined, width: a.width ?? undefined, height: a.height ?? undefined, loading: "lazy", decoding: "async" });
353
+ const fx = imageFx(a);
354
+ const img = _jsx("img", { src: imgSrc, srcSet: a.srcset || undefined, sizes: a.srcset ? sizes : undefined, alt: a.alt ?? "", title: a.title ?? undefined, width: a.width ?? undefined, height: a.height ?? undefined, loading: "lazy", decoding: "async", className: fx.className || undefined, style: fx.style });
339
355
  const bare = a.webpSrcset ? _jsxs("picture", { children: [_jsx("source", { type: "image/webp", srcSet: a.webpSrcset, sizes: sizes }), img] }) : img;
340
356
  // next: ảnh có liên kết (href qua safeUrl; mở tab mới thì noopener)
341
357
  const pic = a.lightbox === true && !a.href ? _jsx(LightboxClient, { src: safeUrl(a.src, ""), alt: a.alt ?? "", children: bare }) : a.href ? _jsx(Link, { href: safeUrl(a.href), target: a.linkTarget === "_blank" ? "_blank" : undefined, rel: a.linkTarget === "_blank" ? "noopener noreferrer" : undefined, children: bare }) : bare;
@@ -346,11 +362,22 @@ async function renderNodeInner(node, key, ctx) {
346
362
  const items = (a.images ?? []).filter((im) => !!im?.src); // ảnh chưa chọn (không src) không vẽ <img> hỏng
347
363
  const cols = Math.min(6, Math.max(1, Number(a.columns) || 3));
348
364
  const crop = a.imageCrop !== false && a.layout !== "masonry"; // next: imageCrop=false giữ nguyên tỉ lệ ảnh; masonry luôn giữ tỉ lệ
349
- return (_jsxs("figure", { className: blockShell("gallery", a).className, style: blockShell("gallery", a).style, children: [items.map((im, i) => {
350
- const el = _jsx("img", { src: safeUrl(im.src, ""), srcSet: im.srcset || undefined, sizes: `(max-width: 768px) 50vw, ${Math.round(100 / cols)}vw`, alt: im.alt ?? "", width: im.width, height: im.height, loading: "lazy", decoding: "async", style: crop ? { width: "100%", height: "100%", objectFit: "cover", aspectRatio: "1" } : { width: "100%", height: "auto" } });
351
- const pic = im.webpSrcset ? _jsxs("picture", { children: [_jsx("source", { type: "image/webp", srcSet: im.webpSrcset, sizes: `(max-width: 768px) 50vw, ${Math.round(100 / cols)}vw` }), el] }) : el;
352
- return _jsxs("figure", { className: "ecx-gallery-item cms-gallery-item", style: { margin: 0 }, children: [a.lightbox === true ? _jsx(LightboxClient, { src: safeUrl(im.full || im.src, ""), alt: im.alt ?? "", children: pic }) : im.href && safeUrl(im.href, "") ? _jsx("a", { href: safeUrl(im.href), children: pic }) : im.full && a.linkTo !== "none" ? _jsx("a", { href: safeUrl(im.full), children: pic }) : pic, im.caption && _jsx("figcaption", { children: im.caption })] }, i);
353
- }), a.caption && _jsx("figcaption", { className: "ecx-gallery-caption cms-gallery-caption", style: { gridColumn: "1 / -1" }, children: a.caption })] }, key));
365
+ // Một ảnh (có srcset / WebP / lightbox) — dùng cho cả lưới lẫn slide
366
+ const galleryItem = (im, i) => {
367
+ const el = _jsx("img", { src: safeUrl(im.src, ""), srcSet: im.srcset || undefined, sizes: `(max-width: 768px) 50vw, ${Math.round(100 / cols)}vw`, alt: im.alt ?? "", width: im.width, height: im.height, loading: "lazy", decoding: "async", style: crop ? { width: "100%", height: "100%", objectFit: "cover", aspectRatio: "1" } : { width: "100%", height: "auto" } });
368
+ const pic = im.webpSrcset ? _jsxs("picture", { children: [_jsx("source", { type: "image/webp", srcSet: im.webpSrcset, sizes: `(max-width: 768px) 50vw, ${Math.round(100 / cols)}vw` }), el] }) : el;
369
+ return _jsxs("figure", { className: "ecx-gallery-item cms-gallery-item", style: { margin: 0 }, children: [a.lightbox === true ? _jsx(LightboxClient, { src: safeUrl(im.full || im.src, ""), alt: im.alt ?? "", children: pic }) : im.href && safeUrl(im.href, "") ? _jsx("a", { href: safeUrl(im.href), children: pic }) : im.full && a.linkTo !== "none" ? _jsx("a", { href: safeUrl(im.full), children: pic }) : pic, im.caption && _jsx("figcaption", { children: im.caption })] }, i);
370
+ };
371
+ const caption = a.caption && _jsx("figcaption", { className: "ecx-gallery-caption cms-gallery-caption", style: { gridColumn: "1 / -1" }, children: a.caption });
372
+ // Dạng slider: mỗi ảnh một slide, số ảnh thấy cùng lúc = columns (tối đa 4) — dùng chung CarouselClient với Slider
373
+ if (a.layout === "slider" && items.length > 1) {
374
+ return (_jsxs("figure", { className: "ecx-gallery cms-gallery is-slider", style: { margin: 0 }, children: [_jsx(CarouselClient, { count: items.length, config: carouselConfig({ slidesPerView: Math.min(4, cols), arrows: a.arrows, dots: a.dots, autoplay: a.autoplay, interval: a.interval, loop: a.loop, gap: "var(--ecx-gallery-gap, 8px)" }), children: items.map((im, i) => _jsx("div", { className: "ecx-carousel-slide", role: "group", "aria-roledescription": "slide", "aria-label": `${i + 1} / ${items.length}`, children: galleryItem(im, i) }, i)) }), caption] }, key));
375
+ }
376
+ // Thumbnail slider: ảnh lớn + dải ảnh nhỏ (không lightbox riêng — ảnh lớn đã là ảnh chính)
377
+ if (a.layout === "thumbs" && items.length > 1) {
378
+ return (_jsxs("figure", { className: "ecx-gallery cms-gallery is-thumbs", style: { margin: 0 }, children: [_jsx(GalleryThumbsClient, { mains: items.map((im, i) => galleryItem(im, i)), thumbs: items.map((im, i) => _jsx("img", { src: safeUrl(im.src, ""), alt: "", loading: "lazy", decoding: "async" }, i)) }), caption] }, key));
379
+ }
380
+ return _jsxs("figure", { className: blockShell("gallery", a).className, style: blockShell("gallery", a).style, children: [items.map((im, i) => galleryItem(im, i)), caption] }, key);
354
381
  }
355
382
  case "video":
356
383
  return _jsxs("figure", { className: "ecx-video cms-video", children: [_jsx("video", { src: safeUrl(a.src, ""), poster: a.poster ? safeUrl(a.poster, "") : undefined, controls: a.controls !== false, autoPlay: a.autoplay === true, loop: a.loop === true, muted: a.muted === true || a.autoplay === true, preload: ["none", "metadata", "auto"].includes(a.preload) ? a.preload : "metadata", playsInline: a.playsInline !== false, style: { width: "100%", height: "auto" } }), a.caption && _jsx("figcaption", { children: a.caption })] }, key);
@@ -369,27 +396,29 @@ async function renderNodeInner(node, key, ctx) {
369
396
  // Hàng cuối là chân bảng (attrs.footer) → <tfoot>
370
397
  const foot = a.footer === true && rows.length > (head ? 2 : 1);
371
398
  const body = rows.slice(head ? 1 : 0, foot ? -1 : undefined);
372
- return _jsx("div", { className: "ecx-table table-wrap", children: _jsxs("table", { className: a.fixed ? "is-fixed" : undefined, children: [head && _jsx("thead", { children: rows[0] }), _jsx("tbody", { children: body }), foot && _jsx("tfoot", { children: rows.at(-1) })] }) }, key);
399
+ return _jsx("div", { className: tableClass(a), children: _jsxs("table", { className: a.fixed ? "is-fixed" : undefined, children: [typeof a.caption === "string" && a.caption.trim() && _jsx("caption", { children: a.caption }), head && _jsx("thead", { children: rows[0] }), _jsx("tbody", { children: body }), foot && _jsx("tfoot", { children: rows.at(-1) })] }) }, key);
373
400
  }
374
401
  case "tableRow": return _jsx("tr", { children: await children() }, key);
375
402
  case "tableHeader": return _jsx("th", { colSpan: a.colspan > 1 ? a.colspan : undefined, rowSpan: a.rowspan > 1 ? a.rowspan : undefined, children: await children() }, key);
376
403
  case "tableCell": return _jsx("td", { colSpan: a.colspan > 1 ? a.colspan : undefined, rowSpan: a.rowspan > 1 ? a.rowspan : undefined, children: await children() }, key);
377
- case "youtube": {
378
- const m = String(a.src ?? "").match(/(?:v=|youtu\.be\/|embed\/)([\w-]{11})/);
379
- const start = Number(a.start) > 0 ? `?start=${Math.floor(Number(a.start))}` : "";
380
- return m ? _jsx("div", { className: "ecx-youtube embed", children: _jsx("iframe", { src: `https://www.youtube-nocookie.com/embed/${m[1]}${start}`, allowFullScreen: true, loading: "lazy", title: "YouTube" }) }, key) : null;
381
- }
382
404
  // Bố cục (@ecomcx/ecomweb-content 1.2). Cấu trúc dùng style trực tiếp → mọi theme hiển thị đúng; class `ecx-*` để theme tạo kiểu thêm (`cms-*` giữ tới 2.0).
383
405
  case "columns": {
384
406
  const cols = await Promise.all((node.content ?? []).map(async (c, i) => {
385
407
  const inner = await Promise.all((c.content ?? []).map((cc, j) => renderNode(cc, `${key}-${i}-${j}`, ctx)));
386
- return shelled("column", c.attrs ?? {}, `${key}-${i}`, _jsxs(_Fragment, { children: [inner, overlayLink(c.attrs ?? {})] }), undefined, { type: "columns", attrs: a });
408
+ return shelled("column", c.attrs ?? {}, `${key}-${i}`, _jsxs(_Fragment, { children: [bgVideoNode(c.attrs), inner, overlayLink(c.attrs ?? {})] }), undefined, { type: "columns", attrs: a });
387
409
  }));
388
- return shelled("columns", a, key, cols);
410
+ return shelled("columns", a, key, _jsxs(_Fragment, { children: [bgVideoNode(a), cols] }));
411
+ }
412
+ case "column": return shelled("column", a, key, _jsxs(_Fragment, { children: [bgVideoNode(a), await children(), overlayLink(a)] }));
413
+ case "group": {
414
+ const g = shelled("group", a, key, _jsxs(_Fragment, { children: [bgVideoNode(a), await children(), overlayLink(a)] }));
415
+ // Xem thêm: cắt khối ở chiều cao thu gọn, nút là <label> của ô tick ẩn (CSS thuần, không cần JS)
416
+ const ch = typeof a.collapseHeight === "string" && /^\d{1,3}(\.\d{1,2})?(rem|em|px|vh)$/.test(a.collapseHeight.trim()) ? a.collapseHeight.trim() : "";
417
+ if (!ch || ctx.markBlocks)
418
+ return g;
419
+ const id = `sm-${key.replace(/[^a-z0-9]/gi, "")}`;
420
+ return _jsxs("div", { className: `ecx-sm${a.collapseFade === false ? " is-nofade" : ""}${a.collapseOnce === true ? " is-once" : ""}`, style: { "--ecx-sm-h": ch }, children: [_jsx("input", { type: "checkbox", id: id, className: "ecx-sm-in", "aria-label": String(a.moreText || "Xem thêm") }), g, _jsxs("label", { htmlFor: id, className: "ecx-sm-btn", children: [_jsx("span", { className: "ecx-sm-more", children: String(a.moreText || "Xem thêm") }), _jsx("span", { className: "ecx-sm-less", children: String(a.lessText || "Thu gọn") })] })] }, `${key}-sm`);
389
421
  }
390
- case "column": return shelled("column", a, key, _jsxs(_Fragment, { children: [await children(), overlayLink(a)] }));
391
- case "group": return shelled("group", a, key, await children());
392
- case "callout": return shelled("callout", a, key, _jsxs(_Fragment, { children: [a.title && _jsx("p", { className: "ecx-callout-title cms-callout-title", style: { margin: 0, fontWeight: 600 }, children: a.title }), await children()] }));
393
422
  case "button": {
394
423
  if (!a.text)
395
424
  return null;
@@ -398,7 +427,7 @@ async function renderNodeInner(node, key, ctx) {
398
427
  const ic = buttonIcon(a);
399
428
  // Chỉ icon: chữ đã thành aria-label của nút (blockShell)
400
429
  const label = ic ? (a.iconOnly === true ? widgetEl(ic, "i") : a.iconPosition === "right" ? [a.text, widgetEl(ic, "i")] : [widgetEl(ic, "i"), a.text]) : a.text;
401
- const link = shelled("button", a, ctx.inButtons ? key : "", label, { href: safeUrl(a.href), target, rel: linkRel(a.rel, target) });
430
+ const link = shelled("button", a, ctx.inButtons ? key : "", label, { href: safeUrl(a.href), target, rel: linkRel(a.rel, target), title: typeof a.tooltip === "string" && a.tooltip ? a.tooltip : undefined });
402
431
  if (ctx.inButtons)
403
432
  return link;
404
433
  return createElement(buttonWrapShell(a).tag, { key, className: buttonWrapShell(a).className, style: buttonWrapShell(a).style }, link);
@@ -413,13 +442,9 @@ async function renderNodeInner(node, key, ctx) {
413
442
  case "cover": {
414
443
  const { src, fixed, overlay, imgStyle, overlayStyle } = coverParts(a);
415
444
  const url = src ? safeUrl(src, "") : "";
416
- return shelled("cover", a, key, _jsxs(_Fragment, { children: [url && !fixed && _jsx("img", { className: "ecx-cover-img", src: url, alt: a.alt ?? "", loading: "lazy", decoding: "async", style: imgStyle }), overlay && _jsx("span", { className: "ecx-cover-overlay", "aria-hidden": "true", style: overlayStyle }), _jsx("div", { className: "ecx-cover-inner", children: await children() })] }), undefined);
445
+ const video = coverVideo(a);
446
+ return shelled("cover", a, key, _jsxs(_Fragment, { children: [video && _jsx(BgVideo, { className: "ecx-cover-video", src: video, poster: url || undefined, style: imgStyle }), url && !fixed && !video && _jsx("img", { className: "ecx-cover-img", src: url, alt: a.alt ?? "", loading: "lazy", decoding: "async", style: imgStyle }), overlay && _jsx("span", { className: "ecx-cover-overlay", "aria-hidden": "true", style: overlayStyle }), _jsx("div", { className: "ecx-cover-inner", children: await children() })] }), undefined);
417
447
  }
418
- case "mediaText": return shelled("mediaText", a, key, _jsxs(_Fragment, { children: [_jsx("figure", { className: "ecx-media-text-media", style: { margin: 0 }, children: a.src && _jsx("img", { src: safeUrl(a.src, ""), alt: a.alt ?? "", loading: "lazy", decoding: "async" }) }), _jsx("div", { className: "ecx-media-text-content", children: await children() })] }));
419
- case "pullquote":
420
- // Nội dung là các khối (đoạn văn…) → không bọc <p> (<p><p> sai HTML: trình duyệt tách thẻ → React báo lệch khi hydrate);
421
- // chữ trần (dữ liệu cũ) mới cần <p>
422
- return shelled("pullquote", a, key, _jsxs(_Fragment, { children: [_jsx("blockquote", { children: (node.content ?? []).every((c) => c.type === "text" || c.type === "hardBreak") ? _jsx("p", { children: await children() }) : await children() }), blockCitation(a) && _jsx("figcaption", { children: blockCitation(a) })] }));
423
448
  case "accordion": {
424
449
  const tag = ["h2", "h3", "h4", "h5", "h6"].includes(String(a.titleTag)) ? String(a.titleTag) : undefined;
425
450
  const sub = { ...ctx, accordion: a.multiple === true ? undefined : `ecx-acc-${key}`, accTag: tag };
@@ -436,12 +461,14 @@ async function renderNodeInner(node, key, ctx) {
436
461
  return (_jsxs("div", { className: cx("ecx-accordion", Number(a.columns) === 2 && "is-cols-2", `has-icon-${["plus", "none"].includes(String(a.icon)) ? a.icon : "arrow"}`, a.iconSide === "left" && "is-icon-left"), children: [await Promise.all(items.map((c, i) => renderNode(c, `${key}-${i}`, sub))), faq && _jsx("script", { type: "application/ld+json", dangerouslySetInnerHTML: { __html: faq } })] }, key));
437
462
  }
438
463
  case "countdown": {
439
- const ms = countdownTarget(a);
464
+ const rules = countdownRules(a);
465
+ // Evergreen không cần ngày; còn lại cần mốc hợp lệ
466
+ const ms = rules.evergreenMs ? 0 : countdownTarget(a); // evergreen: mốc do client tính theo từng người xem (HTML dựng sẵn hiện đủ thời lượng)
440
467
  if (!Number.isFinite(ms))
441
468
  return null;
442
469
  const t = await getT();
443
470
  const units = { d: t("countdown.d"), h: t("countdown.h"), m: t("countdown.m"), s: t("countdown.s") }; // theo ngôn ngữ của trang (vi: ngày/giờ/phút/giây)
444
- return _jsx(CountdownClient, { target: ms, serverNow: Date.now(), units: units, label: a.label ? String(a.label) : undefined, expiredText: a.expiredText ? String(a.expiredText) : undefined, attrs: { layout: a.layout, divider: a.divider, pad: a.pad, postText: a.postText, showDays: a.showDays, showSeconds: a.showSeconds, daysLabel: a.daysLabel, hoursLabel: a.hoursLabel, minutesLabel: a.minutesLabel, secondsLabel: a.secondsLabel } }, key);
471
+ return _jsx(CountdownClient, { target: ms, rules: rules, storageKey: typeof a.anchor === "string" && a.anchor ? a.anchor : `${a.label ?? ""}|${a.evergreenHours ?? 0}|${a.evergreenMinutes ?? 0}`, serverNow: Date.now(), units: units, label: a.label ? String(a.label) : undefined, expiredText: a.expiredText ? String(a.expiredText) : undefined, attrs: { layout: a.layout, divider: a.divider, pad: a.pad, postText: a.postText, showDays: a.showDays, showSeconds: a.showSeconds, daysLabel: a.daysLabel, hoursLabel: a.hoursLabel, minutesLabel: a.minutesLabel, secondsLabel: a.secondsLabel } }, key);
445
472
  }
446
473
  case "form": {
447
474
  // Form cơ bản của lõi: ô vẽ sẵn ở máy chủ, phần gửi chạy trên trình duyệt; máy chủ tìm lại định nghĩa form theo (source, formId)
@@ -450,7 +477,7 @@ async function renderNodeInner(node, key, ctx) {
450
477
  return null;
451
478
  const t = await getT();
452
479
  const inner = await Promise.all((node.content ?? []).map((c, i) => renderNode(c, `${key}-${i}`, { ...ctx, form: formId })));
453
- return (_jsx(FormBlockClient, { formId: formId, source: ctx.source, className: formSizeClass(a) || undefined, successMessage: a.successMessage ? String(a.successMessage) : undefined, fields: (await getSlotItems("form.fields")).length ? _jsx(Slot, { name: "form.fields", props: { form: `core:${ctx.source}/${formId}`, settings: a.ext && typeof a.ext === "object" ? a.ext : {} } }) : undefined, button: { className: blockShell("button", { variant: "primary" })?.className, style: (({ background: _b, color: _c, ...rest }) => rest)(blockShell("button", { variant: "primary" })?.style) }, labels: { submit: a.submitText ? String(a.submitText) : t("form.submit"), sending: t("form.sending"), error: t("form.error") }, children: inner }, key));
480
+ return (_jsx(FormBlockClient, { formId: formId, source: ctx.source, className: formSizeClass(a) || undefined, successMessage: a.successMessage ? String(a.successMessage) : undefined, fields: (await getSlotItems("form.fields")).length ? _jsx(Slot, { name: "form.fields", props: { form: `core:${ctx.source}/${formId}`, settings: a.ext && typeof a.ext === "object" ? a.ext : {} } }) : undefined, button: { className: blockShell("button", { variant: "primary" })?.className, style: (({ background: _b, color: _c, ...rest }) => rest)(blockShell("button", { variant: "primary" })?.style) }, labels: { next: t("form.next"), back: t("form.back"), step: t("form.step"), submit: a.submitText ? String(a.submitText) : t("form.submit"), sending: t("form.sending"), error: t("form.error") }, children: inner }, key));
454
481
  }
455
482
  case "formField": {
456
483
  const name = typeof a.name === "string" && /^[a-z][a-z0-9_]{0,39}$/.test(a.name) ? a.name : "";
@@ -467,7 +494,7 @@ async function renderNodeInner(node, key, ctx) {
467
494
  const check = kind === "checkbox" || kind === "consent";
468
495
  const types = { email: "email", tel: "tel", number: "number", date: "date" };
469
496
  const choose = kind === "select" && !a.placeholder ? (await getT())("form.choose") : String(a.placeholder ?? "");
470
- return (_jsxs("div", { className: cx("ecx-field", `is-${kind}`, (a.width === "half" || a.width === "third") && `is-${a.width}`, check && "is-check"), "data-field": name, children: [check ? _jsxs("label", { htmlFor: id, children: [_jsx("input", { type: "checkbox", id: id, name: name, value: "1", required: required, "aria-describedby": describedBy }), " ", _jsxs("span", { children: [kind === "consent" ? linkedLabel(label) : label, star] })] })
497
+ return (_jsxs("div", { className: cx("ecx-field", `is-${kind}`, (a.width === "half" || a.width === "third") && `is-${a.width}`, check && "is-check"), "data-field": name, "data-showif": typeof a.showIf === "string" && /^[a-z][a-z0-9_]{0,39}(!?=[^\n]{0,100})?$/.test(a.showIf.trim()) ? a.showIf.trim() : undefined, "data-step": Number.isInteger(a.step) && a.step >= 1 && a.step <= 8 ? a.step : undefined, children: [check ? _jsxs("label", { htmlFor: id, children: [_jsx("input", { type: "checkbox", id: id, name: name, value: "1", required: required, "aria-describedby": describedBy }), " ", _jsxs("span", { children: [kind === "consent" ? linkedLabel(label) : label, star] })] })
471
498
  : kind === "radio" ? (_jsxs("fieldset", { "aria-describedby": describedBy, children: [_jsxs("legend", { children: [label, star] }), _jsx("div", { className: "ecx-field-options", children: options.map((o, i) => _jsxs("label", { children: [_jsx("input", { type: "radio", name: name, value: o, required: required }), " ", o] }, i)) })] }))
472
499
  : _jsxs("label", { htmlFor: id, children: [label, star] }), kind === "textarea" ? _jsx("textarea", { rows: 5, maxLength: 5000, ...common })
473
500
  : kind === "select" ? _jsxs("select", { ...common, defaultValue: "", children: [_jsx("option", { value: "", disabled: required, children: choose }), options.map((o, i) => _jsx("option", { value: o, children: o }, i))] })
@@ -476,6 +503,7 @@ async function renderNodeInner(node, key, ctx) {
476
503
  }
477
504
  case "iconBox":
478
505
  case "imageBox":
506
+ case "imageOverlay":
479
507
  case "iconList":
480
508
  case "counter":
481
509
  case "testimonial":
@@ -484,24 +512,20 @@ async function renderNodeInner(node, key, ctx) {
484
512
  const tree = widgetMarkup(node.type, a);
485
513
  return tree ? widgetEl(tree, key) : null;
486
514
  }
487
- case "rating": {
488
- const max = Math.min(10, Math.max(1, Math.round(Number(a.max) || 5)));
489
- const v = Math.min(max, Math.max(0, Number(a.value) || 0));
490
- return (_jsxs("div", { className: "ecx-rating", role: "img", "aria-label": `${v}/${max}`, children: [Array.from({ length: max }, (_, i) => _jsx("span", { "aria-hidden": "true", className: i < Math.round(v) ? "is-on" : "is-off", style: { color: i < Math.round(v) ? "#f59e0b" : "#d4d4d8" }, children: "\u2605" }, i)), a.label && _jsxs("span", { className: "ecx-rating-label", children: [" ", String(a.label)] })] }, key));
491
- }
492
515
  case "tabs": {
493
516
  const tabs = (node.content ?? []).filter((c) => c.type === "tab");
494
517
  if (!tabs.length)
495
518
  return null;
496
519
  const panels = await Promise.all(tabs.map(async (t, i) => _jsx(Fragment, { children: await Promise.all((t.content ?? []).map((c, j) => renderNode(c, `${key}-${i}-${j}`, ctx))) }, i)));
497
- return _jsx(TabsClient, { titles: tabs.map((t, i) => String(t.attrs?.title || `Tab ${i + 1}`)), panels: panels, initial: Math.max(0, (Number(a.initial) || 1) - 1), icons: tabs.map((t) => ICON_PATHS[String(t.attrs?.icon ?? "")]), subtitles: tabs.map((t) => (t.attrs?.subtitle ? String(t.attrs.subtitle) : undefined)), anchors: tabs.map((t) => (typeof t.attrs?.anchor === "string" && /^[\w-]{1,80}$/.test(t.attrs.anchor) ? t.attrs.anchor : undefined)), vertical: a.orientation === "vertical", mobileAccordion: a.mobileAccordion === true, extraClass: tabsClass(a) }, key);
520
+ return _jsx(TabsClient, { titles: tabs.map((t, i) => String(t.attrs?.title || `Tab ${i + 1}`)), panels: panels, initial: Math.max(0, (Number(a.initial) || 1) - 1), icons: tabs.map((t, i) => iconSvg(t.attrs?.icon, { size: 18, className: "ecx-tab-icon", key: `i${i}` }) || undefined), subtitles: tabs.map((t) => (t.attrs?.subtitle ? String(t.attrs.subtitle) : undefined)), anchors: tabs.map((t) => (typeof t.attrs?.anchor === "string" && /^[\w-]{1,80}$/.test(t.attrs.anchor) ? t.attrs.anchor : undefined)), vertical: a.orientation === "vertical", mobileAccordion: a.mobileAccordion === true, extraClass: tabsClass(a) }, key);
498
521
  }
499
522
  case "tab":
500
523
  return _jsx("div", { className: "ecx-tab", children: await children() }, key);
501
524
  case "carousel": {
502
- const per = Math.min(4, Math.max(1, Math.round(Number(a.slidesPerView) || 1)));
503
- const kids = await Promise.all((node.content ?? []).map(async (c, i) => _jsx("div", { className: "ecx-carousel-slide", style: { scrollSnapAlign: "start" }, children: await renderNode(c, `${key}-${i}`, ctx) }, i)));
504
- return _jsx("div", { className: "ecx-carousel", role: "region", "aria-roledescription": "carousel", tabIndex: 0, style: { display: "grid", gridAutoFlow: "column", gridAutoColumns: `calc((100% - ${(per - 1) * 16}px) / ${per})`, gap: 16, overflowX: "auto", scrollSnapType: "x mandatory" }, children: kids }, key);
525
+ const cfg = carouselConfig(a);
526
+ const total = (node.content ?? []).length;
527
+ const kids = await Promise.all((node.content ?? []).map(async (c, i) => _jsx("div", { className: "ecx-carousel-slide", role: "group", "aria-roledescription": "slide", "aria-label": `${i + 1} / ${total}`, children: await renderNode(c, `${key}-${i}`, ctx) }, i)));
528
+ return _jsx(CarouselClient, { count: total, config: cfg, children: kids }, key);
505
529
  }
506
530
  case "shortcode": {
507
531
  const name = String(a.name ?? "");
@@ -510,6 +534,28 @@ async function renderNodeInner(node, key, ctx) {
510
534
  const Comp = await ctx.resolve.shortcode(name);
511
535
  return Comp ? _jsx(Comp, { attrs: (a.args && typeof a.args === "object" ? a.args : {}), site: ctx.site, post: ctx.post }, key) : null;
512
536
  }
537
+ case "testimonials": {
538
+ // Nhiều lời chứng thực: lưới theo số cột từng khổ, hoặc slider (dùng chung bộ máy Slider)
539
+ const c = testimonialsConfig(a);
540
+ const items = node.content ?? [];
541
+ if (!items.length)
542
+ return null;
543
+ if (c.layout === "carousel") {
544
+ const slides = await Promise.all(items.map(async (it, i) => _jsx("div", { className: "ecx-carousel-slide", role: "group", "aria-roledescription": "slide", "aria-label": `${i + 1} / ${items.length}`, children: await renderNode(it, `${key}-${i}`, ctx) }, i)));
545
+ return _jsx(CarouselClient, { count: items.length, config: c.carousel, children: slides }, key);
546
+ }
547
+ return _jsx("div", { className: "ecx-testimonials", style: testimonialsVars(c), children: await children() }, key);
548
+ }
549
+ case "popup": {
550
+ // Nút mở (kiểu như khối Nút) + hộp thoại; không có chữ nút thì không vẽ gì (không có cách mở)
551
+ const c = popupConfig(a);
552
+ const text = typeof a.triggerText === "string" ? a.triggerText : "";
553
+ if (!text && !c.id && c.auto === "none")
554
+ return null; // không nút, không ID, không tự mở = không có cách mở
555
+ const plain = c.triggerStyle === "link" || c.triggerStyle === "play";
556
+ const shell = plain ? null : blockShell("button", { variant: c.triggerStyle });
557
+ return _jsx(PopupClient, { className: popupClass(c), style: popupVars(c), label: typeof a.label === "string" ? a.label : text, closeButton: c.closeButton, closeOnOverlay: c.closeOnOverlay, popupId: c.id || undefined, auto: c.auto, autoDelay: c.autoDelay, autoScroll: c.autoScroll, onceDays: c.onceDays, trigger: !text ? null : c.triggerStyle === "play" ? _jsx("span", { className: "ecx-visually-hidden", children: text }) : text, triggerClass: `ecx-popup-trigger ${shell ? shell.className : c.triggerStyle === "play" ? "is-play" : "is-link"}`, triggerStyle: (shell?.style ?? (c.triggerStyle === "play" ? popupPlayStyle(a) : undefined)), children: await children() }, key);
558
+ }
513
559
  case "details":
514
560
  return _jsxs("details", { className: "ecx-details", name: ctx.accordion, open: a.open === true || undefined, children: [_jsx("summary", { children: ctx.accTag ? createElement(ctx.accTag, { className: "ecx-details-title" }, a.summary || "…") : a.summary || "…" }), await children()] }, key);
515
561
  case "customHtml":
@@ -538,8 +584,6 @@ async function renderNodeInner(node, key, ctx) {
538
584
  ? _jsxs("details", { className: "ecx-toc-details", open: a.startCollapsed !== true || undefined, children: [_jsx("summary", { className: "ecx-toc-title", children: title }), list] })
539
585
  : _jsxs(_Fragment, { children: [a.showTitle !== false && _jsx("p", { className: "ecx-toc-title", children: title }), list] }), a.highlight === true && _jsx(TocSpy, {})] }, key));
540
586
  }
541
- case "preformatted":
542
- return _jsx("pre", { className: "ecx-pre", children: await children() }, key);
543
587
  case "embed": {
544
588
  // Khung nhúng chỉ cho nhà cung cấp đã biết; địa chỉ khung do embedInfo dựng → không nhúng được trang tuỳ ý
545
589
  const info = embedInfo(a.url);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecomcx/ecomweb-theme-sdk",
3
- "version": "2.0.0",
3
+ "version": "2.2.0",
4
4
  "description": "SDK để viết theme và phần frontend của plugin cho Ecomweb",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -36,7 +36,7 @@
36
36
  "API.md"
37
37
  ],
38
38
  "dependencies": {
39
- "@ecomcx/ecomweb-content": "^1.26.0",
39
+ "@ecomcx/ecomweb-content": "^1.28.1",
40
40
  "intl-messageformat": "12.1.3",
41
41
  "server-only": "0.0.1"
42
42
  },