@ecomcx/ecomweb-theme-sdk 2.3.0 → 2.4.1

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/API.md CHANGED
@@ -1407,6 +1407,14 @@ Phóng to ảnh: bấm ảnh mở lớp phủ (Esc hoặc bấm nền để đó
1407
1407
  LightboxClient({ src, alt, children }: { src: string; alt: string; children: ReactNode; }): JSX.Element
1408
1408
  ```
1409
1409
 
1410
+ #### `LottieClient`
1411
+
1412
+ Hoạt ảnh Lottie: poster (ảnh tĩnh) hiện sẵn từ máy chủ; thư viện chỉ nạp khi khối gần vào màn hình; chạy theo `trigger` (auto / hover / click / scroll). Tôn trọng "giảm chuyển động" (không tự chạy). Mọi lỗi → giữ poster, trang không hỏng.
1413
+
1414
+ ```ts
1415
+ LottieClient({ src, poster, label, loop, autoplay, speed, trigger, className, style }: { src: string; poster?: string; label?: string; loop: boolean; autoplay: boolean; speed: number; trigger: "auto" | "hover" | "click" | "scroll"; className: string; style?: CSSProperties; }): JSX.Element
1416
+ ```
1417
+
1410
1418
  #### `NavDrawer`
1411
1419
 
1412
1420
  Menu di động của khối Menu: nút burger mở ngăn trượt từ trái (nền mờ, nút đóng, khoá cuộn trang, Esc / bấm nền / bấm liên kết để đóng, trả focus về nút). Menu con hiện thụt vào ngay dưới mục cha. Khác NavToggle (giữ nguyên cho theme cũ dùng <details>).
@@ -1513,6 +1521,14 @@ Khách đã cho phép nhóm cookie này chưa (gọi trong useEffect / handler
1513
1521
  hasConsent(category: ConsentCategory): boolean
1514
1522
  ```
1515
1523
 
1524
+ #### `loadDotLottie`
1525
+
1526
+ Nạp thư viện một lần cho cả trang, từ cùng nguồn (CSP 'self') chứ không gộp vào gói của website — nên gỡ thư viện đi thì website vẫn build và chạy bình thường. Lỗi ở bất kỳ bước nào (404, wasm bị chặn, trình duyệt cũ) → null.
1527
+
1528
+ ```ts
1529
+ loadDotLottie(base?: string): Promise<DotLottieModule | null>
1530
+ ```
1531
+
1516
1532
  #### `on`
1517
1533
 
1518
1534
  Nghe sự kiện; trả hàm huỷ. Nhận cả sự kiện từ tab khác nếu bên phát dùng crossTab.
@@ -1589,6 +1605,14 @@ Client phía trình duyệt: gọi các route proxy /api/cms/* của frontend.
1589
1605
  const browserApi: FetchKitInstance
1590
1606
  ```
1591
1607
 
1608
+ #### `LOTTIE_BASE`
1609
+
1610
+ Nơi website phục vụ thư viện (route /ecx-lottie của core); không có thư viện → 404 → khối chỉ hiện poster.
1611
+
1612
+ ```ts
1613
+ const LOTTIE_BASE: "/ecx-lottie"
1614
+ ```
1615
+
1592
1616
  ### Kiểu
1593
1617
 
1594
1618
  #### `BlockReadyFn`
package/dist/client.d.ts CHANGED
@@ -326,3 +326,37 @@ export declare function GalleryThumbsClient({ mains, thumbs, label }: {
326
326
  thumbs: ReactNode[];
327
327
  label?: string;
328
328
  }): import("react").JSX.Element;
329
+ /** Nơi website phục vụ thư viện (route /ecx-lottie của core); không có thư viện → 404 → khối chỉ hiện poster. */
330
+ export declare const LOTTIE_BASE = "/ecx-lottie";
331
+ type DotLottieCtor = new (cfg: Record<string, unknown>) => {
332
+ play(): void;
333
+ pause(): void;
334
+ destroy(): void;
335
+ addEventListener(ev: string, fn: () => void): void;
336
+ isPlaying?: boolean;
337
+ };
338
+ type DotLottieModule = {
339
+ DotLottie: DotLottieCtor & {
340
+ setWasmUrl?(url: string): void;
341
+ };
342
+ };
343
+ /**
344
+ * Nạp thư viện một lần cho cả trang, từ cùng nguồn (CSP 'self') chứ không gộp vào gói của website — nên gỡ thư viện đi thì
345
+ * website vẫn build và chạy bình thường. Lỗi ở bất kỳ bước nào (404, wasm bị chặn, trình duyệt cũ) → null.
346
+ */
347
+ export declare function loadDotLottie(base?: string): Promise<DotLottieModule | null>;
348
+ /**
349
+ * Hoạt ảnh Lottie: poster (ảnh tĩnh) hiện sẵn từ máy chủ; thư viện chỉ nạp khi khối gần vào màn hình; chạy theo `trigger`
350
+ * (auto / hover / click / scroll). Tôn trọng "giảm chuyển động" (không tự chạy). Mọi lỗi → giữ poster, trang không hỏng.
351
+ */
352
+ export declare function LottieClient({ src, poster, label, loop, autoplay, speed, trigger, className, style }: {
353
+ src: string;
354
+ poster?: string;
355
+ label?: string;
356
+ loop: boolean;
357
+ autoplay: boolean;
358
+ speed: number;
359
+ trigger: "auto" | "hover" | "click" | "scroll";
360
+ className: string;
361
+ style?: CSSProperties;
362
+ }): import("react").JSX.Element;
package/dist/client.js CHANGED
@@ -808,3 +808,93 @@ export function GalleryThumbsClient({ mains, thumbs, label }) {
808
808
  go(mains.length - 1);
809
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)) })] }));
810
810
  }
811
+ // ---------------------------------------------------------------------------
812
+ // Lottie (khối "lottie", content ≥ 1.29): thư viện @lottiefiles/dotlottie-web là TUỲ CHỌN
813
+ // ---------------------------------------------------------------------------
814
+ /** Nơi website phục vụ thư viện (route /ecx-lottie của core); không có thư viện → 404 → khối chỉ hiện poster. */
815
+ export const LOTTIE_BASE = "/ecx-lottie";
816
+ /**
817
+ * Nạp thư viện một lần cho cả trang, từ cùng nguồn (CSP 'self') chứ không gộp vào gói của website — nên gỡ thư viện đi thì
818
+ * website vẫn build và chạy bình thường. Lỗi ở bất kỳ bước nào (404, wasm bị chặn, trình duyệt cũ) → null.
819
+ */
820
+ export function loadDotLottie(base = LOTTIE_BASE) {
821
+ const g = globalThis;
822
+ g.__ecxLottie ??= (async () => {
823
+ try {
824
+ const mod = (await import(/* webpackIgnore: true */ /* turbopackIgnore: true */ /* @vite-ignore */ `${base}/index.js`));
825
+ mod.DotLottie.setWasmUrl?.(`${base}/player.wasm`);
826
+ return mod;
827
+ }
828
+ catch {
829
+ return null;
830
+ }
831
+ })();
832
+ return g.__ecxLottie;
833
+ }
834
+ /**
835
+ * Hoạt ảnh Lottie: poster (ảnh tĩnh) hiện sẵn từ máy chủ; thư viện chỉ nạp khi khối gần vào màn hình; chạy theo `trigger`
836
+ * (auto / hover / click / scroll). Tôn trọng "giảm chuyển động" (không tự chạy). Mọi lỗi → giữ poster, trang không hỏng.
837
+ */
838
+ export function LottieClient({ src, poster, label, loop, autoplay, speed, trigger, className, style }) {
839
+ const box = useRef(null);
840
+ const canvas = useRef(null);
841
+ const [ready, setReady] = useState(false);
842
+ useEffect(() => {
843
+ const el = box.current, cv = canvas.current;
844
+ if (!src || !el || !cv)
845
+ return;
846
+ let dead = false;
847
+ let player;
848
+ const reduce = typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
849
+ const visible = { now: false };
850
+ const io = typeof IntersectionObserver === "function" ? new IntersectionObserver(([e]) => {
851
+ visible.now = e.isIntersecting;
852
+ if (e.isIntersecting && !player)
853
+ void start();
854
+ if (player) {
855
+ if (e.isIntersecting && (trigger === "scroll" || (trigger === "auto" && autoplay && !reduce)))
856
+ player.play();
857
+ else if (!e.isIntersecting)
858
+ player.pause();
859
+ }
860
+ }, { rootMargin: "200px" }) : null;
861
+ async function start() {
862
+ const mod = await loadDotLottie();
863
+ if (dead || !mod || player)
864
+ return;
865
+ try {
866
+ const p = new mod.DotLottie({ canvas: cv, src, loop, speed, autoplay: !reduce && visible.now && (trigger === "scroll" || (trigger === "auto" && autoplay)) });
867
+ player = p;
868
+ p.addEventListener("load", () => { if (!dead)
869
+ setReady(true); });
870
+ p.addEventListener("loadError", () => { if (!dead)
871
+ setReady(false); });
872
+ }
873
+ catch { /* giữ poster */ }
874
+ }
875
+ if (io)
876
+ io.observe(el);
877
+ else
878
+ void start();
879
+ const on = () => player?.play(), off = () => player?.pause();
880
+ const toggle = () => (player?.isPlaying ? player.pause() : player?.play());
881
+ if (trigger === "hover") {
882
+ el.addEventListener("mouseenter", on);
883
+ el.addEventListener("mouseleave", off);
884
+ }
885
+ if (trigger === "click")
886
+ el.addEventListener("click", toggle);
887
+ return () => {
888
+ dead = true;
889
+ io?.disconnect();
890
+ el.removeEventListener("mouseenter", on);
891
+ el.removeEventListener("mouseleave", off);
892
+ el.removeEventListener("click", toggle);
893
+ try {
894
+ player?.destroy();
895
+ }
896
+ catch { /* bỏ qua */ }
897
+ };
898
+ }, [src, loop, autoplay, speed, trigger]);
899
+ return (_jsxs("div", { ref: box, className: cx(className, ready && "is-ready"), style: style, "data-trigger": trigger, role: "img", "aria-label": label || undefined, "aria-hidden": label ? undefined : true, children: [poster && _jsx("img", { className: "ecx-lottie-poster", src: poster, alt: "", loading: "lazy", decoding: "async" }), _jsx("canvas", { ref: canvas, className: "ecx-lottie-canvas" })] }));
900
+ }
package/dist/rich.js CHANGED
@@ -2,10 +2,10 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
2
2
  import { Fragment, cloneElement, createElement, isValidElement } from "react";
3
3
  import { ICON_LIBRARY } from "@ecomcx/ecomweb-content/icon-library";
4
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";
5
+ import { lottieConfig, 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";
6
6
  import { cx } from "./utils.js";
7
7
  import { SOCIAL_ICONS } from "./social-icons.js";
8
- import { GalleryThumbsClient, AudienceGate, TypedText, BgVideo, PopupClient, CarouselClient, CountdownClient, FormBlockClient, LightboxClient, Link, TabsClient, TocSpy } from "./client.js";
8
+ import { GalleryThumbsClient, AudienceGate, TypedText, BgVideo, PopupClient, LottieClient, CarouselClient, CountdownClient, FormBlockClient, LightboxClient, Link, TabsClient, TocSpy } from "./client.js";
9
9
  import { CounterClient } from "./counter-client.js";
10
10
  import { AssetScript } from "./browser.js";
11
11
  import { getT } from "./i18n.js";
@@ -546,6 +546,20 @@ async function renderNodeInner(node, key, ctx) {
546
546
  }
547
547
  return _jsx("div", { className: "ecx-testimonials", style: testimonialsVars(c), children: await children() }, key);
548
548
  }
549
+ case "lottie": {
550
+ // Hoạt ảnh Lottie: poster hiện ngay từ máy chủ; thư viện (tuỳ chọn) nạp phía trình duyệt — thiếu thư viện / tệp lỗi thì chỉ hiện poster
551
+ const c = lottieConfig(a);
552
+ const src = c.kind ? safeUrl(c.src, "") : "";
553
+ const poster = safeUrl(c.poster, "");
554
+ if (!src && !poster)
555
+ return null;
556
+ const style = {};
557
+ if (c.height)
558
+ style.height = `${c.height}px`;
559
+ if (c.maxWidth)
560
+ style.maxWidth = `${c.maxWidth}px`;
561
+ return _jsx(LottieClient, { src: src, poster: poster || undefined, label: c.label, loop: c.loop, autoplay: c.autoplay, speed: c.speed, trigger: c.trigger, className: cx("ecx-lottie", `is-align-${c.align}`), style: style }, key);
562
+ }
549
563
  case "popup": {
550
564
  // 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
565
  const c = popupConfig(a);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecomcx/ecomweb-theme-sdk",
3
- "version": "2.3.0",
3
+ "version": "2.4.1",
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.28.1",
39
+ "@ecomcx/ecomweb-content": "^1.29.0",
40
40
  "intl-messageformat": "12.1.3",
41
41
  "server-only": "0.0.1"
42
42
  },