@orunelle/theme-engine 0.0.0-stage → 2.0.0-alpha.13
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/commerce/account.d.ts +4 -0
- package/dist/commerce/account.d.ts.map +1 -0
- package/dist/commerce/account.js +198 -0
- package/dist/commerce/cart.d.ts +6 -0
- package/dist/commerce/cart.d.ts.map +1 -0
- package/dist/commerce/cart.js +66 -0
- package/dist/commerce/checkout.d.ts +4 -0
- package/dist/commerce/checkout.d.ts.map +1 -0
- package/dist/commerce/checkout.js +152 -0
- package/dist/commerce/orders.d.ts +8 -0
- package/dist/commerce/orders.d.ts.map +1 -0
- package/dist/commerce/orders.js +19 -0
- package/dist/commerce/public-pages.d.ts +17 -0
- package/dist/commerce/public-pages.d.ts.map +1 -0
- package/dist/commerce/public-pages.js +19 -0
- package/dist/commerce/shared.d.ts +31 -0
- package/dist/commerce/shared.d.ts.map +1 -0
- package/dist/commerce/shared.js +81 -0
- package/dist/commerce-pages.d.ts +5 -0
- package/dist/commerce-pages.d.ts.map +1 -0
- package/dist/commerce-pages.js +4 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +112 -0
- package/dist/library.d.ts +78 -0
- package/dist/library.d.ts.map +1 -0
- package/dist/library.js +277 -0
- package/dist/product.d.ts +77 -0
- package/dist/product.d.ts.map +1 -0
- package/dist/product.js +241 -0
- package/dist/sections.d.ts +48 -0
- package/dist/sections.d.ts.map +1 -0
- package/dist/sections.js +98 -0
- package/package.json +45 -3
- package/sections.css +781 -0
- package/styles.css +1274 -0
- package/README.md +0 -3
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { Link, useLocation } from "@tanstack/react-router";
|
|
4
|
+
import { useCommerce, useStorefront } from "@orunelle/theme-sdk";
|
|
5
|
+
import { CommerceError } from "@orunelle/theme-sdk/commerce";
|
|
6
|
+
export function useCopy() {
|
|
7
|
+
const { locale } = useStorefront();
|
|
8
|
+
return (en, ar) => (locale === "ar" ? ar : en);
|
|
9
|
+
}
|
|
10
|
+
export function useAction() {
|
|
11
|
+
const [pending, setPending] = useState(false), [error, setError] = useState(), [notice, setNotice] = useState("");
|
|
12
|
+
return {
|
|
13
|
+
pending,
|
|
14
|
+
error,
|
|
15
|
+
notice,
|
|
16
|
+
setNotice,
|
|
17
|
+
async run(action) {
|
|
18
|
+
if (pending)
|
|
19
|
+
return;
|
|
20
|
+
setPending(true);
|
|
21
|
+
setError(undefined);
|
|
22
|
+
setNotice("");
|
|
23
|
+
try {
|
|
24
|
+
await action();
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
setError(error);
|
|
28
|
+
}
|
|
29
|
+
finally {
|
|
30
|
+
setPending(false);
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export function Failure({ error }) {
|
|
36
|
+
const t = useCopy();
|
|
37
|
+
if (!error)
|
|
38
|
+
return null;
|
|
39
|
+
const uncertain = error instanceof CommerceError && error.recovery;
|
|
40
|
+
return (_jsxs("p", { className: "form-error", role: "alert", children: [uncertain
|
|
41
|
+
? t("We could not confirm the result. Refresh the resource before trying again. For an order, use Recover order to reuse its original request.", "تعذر تأكيد النتيجة. حدّث البيانات قبل المحاولة مجددًا. للطلب، استخدم استعادة الطلب لإعادة استخدام نفس الطلب.")
|
|
42
|
+
: t("The request could not be completed. Check your details and try again.", "تعذر إكمال الطلب. راجع البيانات وحاول مرة أخرى."), error instanceof CommerceError && (_jsxs("span", { className: "request-reference", children: [t("Reference", "المرجع"), ": ", error.code, " ", error.requestId] }))] }));
|
|
43
|
+
}
|
|
44
|
+
export function Field({ label, name, type = "text", required = true, value, autoComplete, }) {
|
|
45
|
+
return (_jsxs("label", { className: "form-field", children: [_jsx("span", { children: label }), _jsx("input", { name: name, type: type, required: required, defaultValue: value, autoComplete: autoComplete, minLength: type === "password"
|
|
46
|
+
? autoComplete === "current-password"
|
|
47
|
+
? 1
|
|
48
|
+
: 12
|
|
49
|
+
: undefined })] }));
|
|
50
|
+
}
|
|
51
|
+
export function values(event) {
|
|
52
|
+
event.preventDefault();
|
|
53
|
+
return new FormData(event.currentTarget);
|
|
54
|
+
}
|
|
55
|
+
export const val = (data, name) => String(data.get(name) ?? "");
|
|
56
|
+
export function FixtureNotice() {
|
|
57
|
+
const t = useCopy();
|
|
58
|
+
return (_jsx("p", { className: "sample-notice", role: "status", children: t("This reference preview uses sample data. Purchases and account changes are unavailable.", "تستخدم هذه المعاينة بيانات تجريبية. الشراء وتعديل الحساب غير متاحين.") }));
|
|
59
|
+
}
|
|
60
|
+
export function Guard({ children }) {
|
|
61
|
+
const context = useStorefront(), session = useCommerce(), t = useCopy();
|
|
62
|
+
if (context.commerce !== "api" || context.mode === "preview")
|
|
63
|
+
return _jsx(FixtureNotice, {});
|
|
64
|
+
if (!session.ready)
|
|
65
|
+
return (_jsx("p", { role: "status", children: t("Loading your session…", "جارٍ تحميل الجلسة…") }));
|
|
66
|
+
if (!session.authenticated)
|
|
67
|
+
return (_jsxs("p", { children: [t("Sign in to continue.", "سجل الدخول للمتابعة."), " ", _jsx(Link, { to: `/${context.locale}/login`, children: t("Sign in", "تسجيل الدخول") })] }));
|
|
68
|
+
return children;
|
|
69
|
+
}
|
|
70
|
+
export function Pagination({ page, pages }) {
|
|
71
|
+
const { pathname, searchStr } = useLocation();
|
|
72
|
+
const t = useCopy();
|
|
73
|
+
function href(target) {
|
|
74
|
+
const params = new URLSearchParams(searchStr);
|
|
75
|
+
params.set("page", String(target));
|
|
76
|
+
return `${pathname}?${params}`;
|
|
77
|
+
}
|
|
78
|
+
if (pages <= 1)
|
|
79
|
+
return null;
|
|
80
|
+
return (_jsxs("nav", { className: "pagination", "aria-label": t("Pagination", "الصفحات"), children: [page > 1 && _jsx(Link, { to: href(page - 1), children: t("Previous", "السابق") }), _jsxs("span", { children: [page, " / ", pages] }), page < pages && _jsx(Link, { to: href(page + 1), children: t("Next", "التالي") })] }));
|
|
81
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { DefaultCatalogPage, DefaultCollectionsPage, DefaultContentPage, } from "./commerce/public-pages.js";
|
|
2
|
+
export { DefaultProductActions, DefaultCartPage } from "./commerce/cart.js";
|
|
3
|
+
export { DefaultAccountPage } from "./commerce/account.js";
|
|
4
|
+
export { DefaultCheckoutPage, DefaultPaymentCallback, } from "./commerce/checkout.js";
|
|
5
|
+
//# sourceMappingURL=commerce-pages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commerce-pages.d.ts","sourceRoot":"","sources":["../src/commerce-pages.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,sBAAsB,EACtB,kBAAkB,GACnB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EACL,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { DefaultCatalogPage, DefaultCollectionsPage, DefaultContentPage, } from "./commerce/public-pages.js";
|
|
2
|
+
export { DefaultProductActions, DefaultCartPage } from "./commerce/cart.js";
|
|
3
|
+
export { DefaultAccountPage } from "./commerce/account.js";
|
|
4
|
+
export { DefaultCheckoutPage, DefaultPaymentCallback, } from "./commerce/checkout.js";
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export { BuyButtons, DefaultProductLayout, ProductDescription, ProductFields, ProductFormProvider, ProductGallery, ProductPrice, ProductTitle, VariantPicker, useProductForm, } from "./product.js";
|
|
3
|
+
export { RichText, SmartLink, ThemeImage, schemeOf, textOf, useMediaImage, videoEmbed, } from "./library.js";
|
|
4
|
+
import type { Variant } from "@orunelle/theme-sdk/commerce";
|
|
5
|
+
export { DefaultCheckoutPage, DefaultPaymentCallback, } from "./commerce-pages.js";
|
|
6
|
+
import { type MenuItem, type PublicProduct, type ResolvedTheme, type ThemeResources, type OptionVisuals, type ThemeComponents, type ThemeDefinition } from "@orunelle/theme-sdk";
|
|
7
|
+
/** Renders a merchant menu; nested links open from a disclosure button. */
|
|
8
|
+
export declare function MenuLinks({ items, flat, }: {
|
|
9
|
+
items: readonly MenuItem[];
|
|
10
|
+
flat?: boolean;
|
|
11
|
+
}): import("react").JSX.Element;
|
|
12
|
+
export declare function DefaultLayout({ children }: {
|
|
13
|
+
children: ReactNode;
|
|
14
|
+
}): import("react").JSX.Element;
|
|
15
|
+
export declare function DefaultProductCard({ product }: {
|
|
16
|
+
product: PublicProduct;
|
|
17
|
+
}): import("react").JSX.Element;
|
|
18
|
+
export declare function DefaultHomePage({ products, resources, }: {
|
|
19
|
+
products: readonly PublicProduct[];
|
|
20
|
+
resources?: ThemeResources;
|
|
21
|
+
}): import("react").JSX.Element;
|
|
22
|
+
export declare function ProductImage({ product, detail, }: {
|
|
23
|
+
product: PublicProduct;
|
|
24
|
+
detail?: boolean;
|
|
25
|
+
}): import("react").JSX.Element;
|
|
26
|
+
export declare function DefaultProductPage({ product, variants, related, optionVisuals, }: {
|
|
27
|
+
product: PublicProduct;
|
|
28
|
+
variants?: readonly Variant[];
|
|
29
|
+
related?: readonly PublicProduct[];
|
|
30
|
+
optionVisuals?: OptionVisuals;
|
|
31
|
+
}): import("react").JSX.Element;
|
|
32
|
+
export declare const defaultComponents: Readonly<ThemeComponents>;
|
|
33
|
+
export declare function resolveTheme(definition: ThemeDefinition): ResolvedTheme;
|
|
34
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceR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E;IACD,OAAO,EAAE,aAAa,CAAC;IACvB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,+BAsCA;AACD,wBAAgB,kBAAkB,CAAC,EACjC,OAAO,EACP,QAAa,EACb,OAAO,EACP,aAAa,GACd,EAAE;IACD,OAAO,EAAE,aAAa,CAAC;IACvB,QAAQ,CAAC,EAAE,SAAS,OAAO,EAAE,CAAC;IAC9B,OAAO,CAAC,EAAE,SAAS,aAAa,EAAE,CAAC;IACnC,aAAa,CAAC,EAAE,aAAa,CAAC;CAC/B,+BAWA;AAED,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,eAAe,CAWtD,CAAC;AACH,wBAAgB,YAAY,CAAC,UAAU,EAAE,eAAe,GAAG,aAAa,CAWvE"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
import { Link, useLocation } from "@tanstack/react-router";
|
|
4
|
+
import { ThemeComposition, ThemeSlot } from "@orunelle/theme-sdk";
|
|
5
|
+
import { defaultSections, defaultBlocks } from "./sections.js";
|
|
6
|
+
export { BuyButtons, DefaultProductLayout, ProductDescription, ProductFields, ProductFormProvider, ProductGallery, ProductPrice, ProductTitle, VariantPicker, useProductForm, } from "./product.js";
|
|
7
|
+
import { DefaultProductLayout } from "./product.js";
|
|
8
|
+
export { RichText, SmartLink, ThemeImage, schemeOf, textOf, useMediaImage, videoEmbed, } from "./library.js";
|
|
9
|
+
import { DefaultAccountPage, DefaultCartPage, DefaultCatalogPage, DefaultCollectionsPage, DefaultContentPage, DefaultProductActions, } from "./commerce-pages.js";
|
|
10
|
+
export { DefaultCheckoutPage, DefaultPaymentCallback, } from "./commerce-pages.js";
|
|
11
|
+
import { SmartLink, ThemeImage } from "./library.js";
|
|
12
|
+
import { Editable, emitStorefrontEvent, eventProduct, formatMoney, formatPrice, localizedHref, useStoreText, useThemeSettings, useStorefront, useThemeComponents, useThemeRuntime, ThemePageData, } from "@orunelle/theme-sdk";
|
|
13
|
+
function menuSetting(value) {
|
|
14
|
+
return Array.isArray(value) ? value : undefined;
|
|
15
|
+
}
|
|
16
|
+
function MenuLink({ link }) {
|
|
17
|
+
const { locale } = useStorefront();
|
|
18
|
+
const href = localizedHref(link.href, locale);
|
|
19
|
+
const text = link.label[locale] || link.label[locale === "ar" ? "en" : "ar"];
|
|
20
|
+
return href.startsWith("/") ? (_jsx(Link, { to: href, children: text })) : (_jsx("a", { href: href, children: text }));
|
|
21
|
+
}
|
|
22
|
+
/** Renders a merchant menu; nested links open from a disclosure button. */
|
|
23
|
+
export function MenuLinks({ items, flat = false, }) {
|
|
24
|
+
const { locale } = useStorefront();
|
|
25
|
+
return (_jsx(_Fragment, { children: items.map((item, index) => item.children?.length && !flat ? (_jsxs("details", { className: "storefront-submenu", children: [_jsx("summary", { children: item.label[locale] }), _jsxs("div", { children: [_jsx(MenuLink, { link: item }), item.children.map((child, childIndex) => (_jsx(MenuLink, { link: child }, childIndex)))] })] }, index)) : (_jsx(MenuLink, { link: item }, index))) }));
|
|
26
|
+
}
|
|
27
|
+
export function DefaultLayout({ children }) {
|
|
28
|
+
const { store, locale, commerce, navigation } = useStorefront();
|
|
29
|
+
const location = useLocation();
|
|
30
|
+
const settings = useThemeSettings();
|
|
31
|
+
const t = useStoreText();
|
|
32
|
+
const [menuOpen, setMenuOpen] = useState(false);
|
|
33
|
+
// Close the mobile menu after every navigation.
|
|
34
|
+
useEffect(() => setMenuOpen(false), [location.pathname]);
|
|
35
|
+
// Themes that do not declare these settings keep the built-in links.
|
|
36
|
+
const headerMenu = menuSetting(settings["header-menu"]);
|
|
37
|
+
const footerMenu = menuSetting(settings["footer-menu"]);
|
|
38
|
+
return (_jsxs("div", { className: "storefront-shell", children: [_jsx("a", { className: "skip-link", href: "#content", children: t("header.skip") }), _jsxs("header", { className: "storefront-header", children: [_jsx(Link, { to: `/${locale}`, className: "storefront-brand", children: store.logo ? (_jsx(ThemeImage, { value: store.logo, className: "storefront-logo", priority: true, fallback: store.name[locale] })) : (_jsxs(_Fragment, { children: [store.name[locale], _jsx("span", { "aria-hidden": "true", children: "." })] })) }), _jsxs("button", { type: "button", className: "storefront-menu-toggle", "aria-expanded": menuOpen, "aria-controls": "storefront-nav", onClick: () => setMenuOpen((open) => !open), children: [_jsx("span", { "aria-hidden": "true", children: menuOpen ? "✕" : "☰" }), _jsx("span", { className: "visually-hidden", children: locale === "ar" ? "القائمة" : "Menu" })] }), _jsxs("nav", { id: "storefront-nav", "data-open": menuOpen ? "true" : undefined, "aria-label": locale === "ar" ? "التنقل الرئيسي" : "Main navigation", children: [headerMenu ? (_jsx(MenuLinks, { items: headerMenu })) : (_jsxs(_Fragment, { children: [_jsx(Link, { to: `/${locale}/products`, children: t("nav.products") }), _jsx(Link, { to: `/${locale}/categories`, children: t("nav.categories") }), _jsx(Link, { to: `/${locale}/collections`, children: t("nav.collections") }), _jsx(Link, { to: `/${locale}/search`, children: t("nav.search") })] })), _jsx(Link, { to: `/${locale}/cart`, children: t("nav.cart") }), _jsx(Link, { to: `/${locale}/account`, children: t("nav.account") }), _jsx(Link, { to: location.pathname.replace(/^\/(en|ar)(?=\/|$)/, locale === "ar" ? "/en" : "/ar") + location.searchStr, lang: locale === "ar" ? "en" : "ar", children: locale === "ar" ? "English" : "العربية" })] })] }), _jsx(ThemeComposition, { scope: "group", name: "header" }), _jsx(ThemeSlot, { name: "header.after" }), _jsx("main", { id: "content", children: children }), _jsx(ThemeComposition, { scope: "group", name: "footer" }), _jsx(ThemeSlot, { name: "footer.before" }), _jsxs("footer", { className: "storefront-footer", children: [footerMenu?.length ? (_jsx("nav", { "aria-label": locale === "ar" ? "روابط التذييل" : "Footer links", children: _jsx(MenuLinks, { items: footerMenu, flat: true }) })) : (navigation?.map((item) => (_jsx(Link, { to: `/${locale}/${item.path}`, children: item.label[locale] }, item.path)))), _jsx("span", { children: commerce === "api"
|
|
39
|
+
? store.name[locale]
|
|
40
|
+
: locale === "ar"
|
|
41
|
+
? "متجر تجريبي من أورونيل"
|
|
42
|
+
: "An Orunelle reference store" }), _jsx("span", { children: commerce === "api"
|
|
43
|
+
? t("footer.powered_by")
|
|
44
|
+
: locale === "ar"
|
|
45
|
+
? "منتجات تجريبية · الشراء غير متاح"
|
|
46
|
+
: "Sample products · Purchases unavailable" })] })] }));
|
|
47
|
+
}
|
|
48
|
+
export function DefaultProductCard({ product }) {
|
|
49
|
+
const { locale } = useStorefront();
|
|
50
|
+
return (_jsxs("article", { className: "product-card", "data-component": "default-product-card", children: [_jsx(ProductImage, { product: product }), _jsx("h2", { children: _jsx(Link, { to: `/${locale}/products/${product.handle}`, children: product.name[locale] }) }), _jsxs("p", { className: "product-price", children: [formatPrice(product, locale), product.compareAtPrice && (_jsx("s", { className: "product-compare-price", children: formatMoney(product.compareAtPrice.amountMinor, product.compareAtPrice.currency, locale) }))] })] }));
|
|
51
|
+
}
|
|
52
|
+
export function DefaultHomePage({ products, resources, }) {
|
|
53
|
+
const { locale, commerce } = useStorefront();
|
|
54
|
+
const { ProductCard } = useThemeComponents();
|
|
55
|
+
const runtime = useThemeRuntime();
|
|
56
|
+
const t = useStoreText();
|
|
57
|
+
if (runtime.configuration && runtime.theme.manifest.editor?.templates.home)
|
|
58
|
+
return (_jsx(ThemePageData, { products: products, resources: resources, children: _jsx(ThemeComposition, { scope: "template", name: "home" }) }));
|
|
59
|
+
return (_jsxs("section", { className: "catalog-section", "data-component": "default-home-page", children: [_jsxs(Editable, { id: "home.intro", type: "intro", children: [_jsx("h1", { children: commerce === "api"
|
|
60
|
+
? t("home.title")
|
|
61
|
+
: locale === "ar"
|
|
62
|
+
? "اختيارات لحياتك اليومية"
|
|
63
|
+
: "Considered essentials for every day" }), _jsx("p", { className: "storefront-intro", children: commerce === "api"
|
|
64
|
+
? t("home.intro")
|
|
65
|
+
: locale === "ar"
|
|
66
|
+
? "اكتشف مجموعة المنتجات التجريبية. هذا المتجر مخصص للمعاينة ولا يقبل الطلبات."
|
|
67
|
+
: "Explore a small collection of sample products. This reference store does not accept orders." })] }), products.length ? (_jsx("div", { className: "product-grid", children: products.map((product) => (_jsx(Editable, { id: `home.products.${product.id}`, type: "product-card", children: _jsx(ProductCard, { product: product }) }, product.id))) })) : (_jsx("p", { role: "status", children: t("home.empty") }))] }));
|
|
68
|
+
}
|
|
69
|
+
export function ProductImage({ product, detail = false, }) {
|
|
70
|
+
const { locale, commerce } = useStorefront();
|
|
71
|
+
const image = product.image;
|
|
72
|
+
const safe = image && (/^https:\/\//.test(image.url) || /^\/(?!\/)/.test(image.url));
|
|
73
|
+
if (safe)
|
|
74
|
+
return (_jsx("img", { className: detail ? "product-photo product-detail-image" : "product-photo", src: image.url, alt: image.alt || product.name[locale], width: image.width, height: image.height,
|
|
75
|
+
// The product photo is the page's largest paint; fetch it first.
|
|
76
|
+
loading: detail ? "eager" : "lazy", fetchPriority: detail ? "high" : "auto", decoding: detail ? "sync" : "async" }));
|
|
77
|
+
return (_jsx("div", { className: `product-image-empty${detail ? " product-detail-image" : ""}`, role: "img", "aria-label": locale === "ar" ? "لا توجد صورة للمنتج" : "No product image", children: _jsx("span", { children: commerce === "api"
|
|
78
|
+
? locale === "ar"
|
|
79
|
+
? "لا توجد صورة"
|
|
80
|
+
: "No image"
|
|
81
|
+
: locale === "ar"
|
|
82
|
+
? "منتج تجريبي"
|
|
83
|
+
: "Sample product" }) }));
|
|
84
|
+
}
|
|
85
|
+
export function DefaultProductPage({ product, variants = [], related, optionVisuals, }) {
|
|
86
|
+
const runtime = useThemeRuntime();
|
|
87
|
+
return (_jsx(DefaultProductLayout, { product: product, variants: variants, related: related ?? runtime.related ?? [], optionVisuals: optionVisuals ?? runtime.optionVisuals ?? {}, after: _jsx(ThemeSlot, { name: "product.after" }) }));
|
|
88
|
+
}
|
|
89
|
+
export const defaultComponents = Object.freeze({
|
|
90
|
+
Layout: DefaultLayout,
|
|
91
|
+
HomePage: DefaultHomePage,
|
|
92
|
+
ProductCard: DefaultProductCard,
|
|
93
|
+
ProductPage: DefaultProductPage,
|
|
94
|
+
ProductActions: DefaultProductActions,
|
|
95
|
+
CatalogPage: DefaultCatalogPage,
|
|
96
|
+
CollectionsPage: DefaultCollectionsPage,
|
|
97
|
+
ContentPage: DefaultContentPage,
|
|
98
|
+
AccountPage: DefaultAccountPage,
|
|
99
|
+
CartPage: DefaultCartPage,
|
|
100
|
+
});
|
|
101
|
+
export function resolveTheme(definition) {
|
|
102
|
+
return Object.freeze({
|
|
103
|
+
...definition,
|
|
104
|
+
manifest: definition.manifest,
|
|
105
|
+
components: Object.freeze({
|
|
106
|
+
...defaultComponents,
|
|
107
|
+
...definition.components,
|
|
108
|
+
}),
|
|
109
|
+
sections: Object.freeze({ ...defaultSections, ...definition.sections }),
|
|
110
|
+
blocks: Object.freeze({ ...defaultBlocks, ...definition.blocks }),
|
|
111
|
+
});
|
|
112
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import { type ThemeNodeProps } from "@orunelle/theme-sdk";
|
|
3
|
+
type Settings = ThemeNodeProps["settings"];
|
|
4
|
+
export declare function textOf(value: unknown, locale: "en" | "ar"): string;
|
|
5
|
+
/** Color schemes are declared as select values like "scheme-2". */
|
|
6
|
+
export declare function schemeOf(settings: Settings): string | undefined;
|
|
7
|
+
/** Resolves an image setting against the media the platform allowed. */
|
|
8
|
+
export declare function useMediaImage(value: unknown): {
|
|
9
|
+
url: string;
|
|
10
|
+
alt: string;
|
|
11
|
+
position: string;
|
|
12
|
+
} | undefined;
|
|
13
|
+
export declare function ThemeImage({ value, className, priority, fallback, }: {
|
|
14
|
+
value: unknown;
|
|
15
|
+
className?: string;
|
|
16
|
+
priority?: boolean;
|
|
17
|
+
fallback?: ReactNode;
|
|
18
|
+
}): import("react").JSX.Element;
|
|
19
|
+
export declare function RichText({ value, field }: {
|
|
20
|
+
value: unknown;
|
|
21
|
+
field?: string;
|
|
22
|
+
}): import("react").JSX.Element;
|
|
23
|
+
/** Store links use client navigation; anything else is a plain anchor. */
|
|
24
|
+
export declare function SmartLink({ href, className, children, }: {
|
|
25
|
+
href: string;
|
|
26
|
+
className?: string;
|
|
27
|
+
children: ReactNode;
|
|
28
|
+
}): import("react").JSX.Element;
|
|
29
|
+
declare function AnnouncementBar({ settings }: ThemeNodeProps): import("react").JSX.Element | null;
|
|
30
|
+
declare function ImageBanner({ settings, children }: ThemeNodeProps): import("react").JSX.Element;
|
|
31
|
+
declare function Slideshow({ settings, children }: ThemeNodeProps): import("react").JSX.Element;
|
|
32
|
+
declare function RichTextSection({ settings, children }: ThemeNodeProps): import("react").JSX.Element;
|
|
33
|
+
declare function ImageWithText({ settings, children }: ThemeNodeProps): import("react").JSX.Element;
|
|
34
|
+
declare function Multicolumn({ settings, children }: ThemeNodeProps): import("react").JSX.Element;
|
|
35
|
+
declare function FeaturedProducts({ settings }: ThemeNodeProps): import("react").JSX.Element;
|
|
36
|
+
declare function FeaturedCollection({ settings }: ThemeNodeProps): import("react").JSX.Element;
|
|
37
|
+
declare function CollectionList({ settings }: ThemeNodeProps): import("react").JSX.Element;
|
|
38
|
+
declare function Testimonials({ settings, children }: ThemeNodeProps): import("react").JSX.Element;
|
|
39
|
+
declare function Faq({ settings, children }: ThemeNodeProps): import("react").JSX.Element;
|
|
40
|
+
/** Only these hosts may be embedded; everything else plays as a file or not at all. */
|
|
41
|
+
export declare function videoEmbed(url: string): {
|
|
42
|
+
kind: "iframe";
|
|
43
|
+
src: string;
|
|
44
|
+
} | {
|
|
45
|
+
kind: "file";
|
|
46
|
+
src: string;
|
|
47
|
+
} | undefined;
|
|
48
|
+
declare function Video({ settings }: ThemeNodeProps): import("react").JSX.Element;
|
|
49
|
+
declare function LogoList({ settings, children }: ThemeNodeProps): import("react").JSX.Element;
|
|
50
|
+
declare function Slide({ settings }: ThemeNodeProps): import("react").JSX.Element;
|
|
51
|
+
declare function Column({ settings }: ThemeNodeProps): import("react").JSX.Element;
|
|
52
|
+
declare function Testimonial({ settings }: ThemeNodeProps): import("react").JSX.Element;
|
|
53
|
+
declare function FaqItem({ settings }: ThemeNodeProps): import("react").JSX.Element;
|
|
54
|
+
declare function Logo({ settings }: ThemeNodeProps): import("react").JSX.Element;
|
|
55
|
+
export declare const librarySections: Readonly<{
|
|
56
|
+
"announcement-bar": typeof AnnouncementBar;
|
|
57
|
+
"image-banner": typeof ImageBanner;
|
|
58
|
+
slideshow: typeof Slideshow;
|
|
59
|
+
"rich-text": typeof RichTextSection;
|
|
60
|
+
"image-with-text": typeof ImageWithText;
|
|
61
|
+
multicolumn: typeof Multicolumn;
|
|
62
|
+
"featured-products": typeof FeaturedProducts;
|
|
63
|
+
"featured-collection": typeof FeaturedCollection;
|
|
64
|
+
"collection-list": typeof CollectionList;
|
|
65
|
+
testimonials: typeof Testimonials;
|
|
66
|
+
faq: typeof Faq;
|
|
67
|
+
video: typeof Video;
|
|
68
|
+
"logo-list": typeof LogoList;
|
|
69
|
+
}>;
|
|
70
|
+
export declare const libraryBlocks: Readonly<{
|
|
71
|
+
slide: typeof Slide;
|
|
72
|
+
column: typeof Column;
|
|
73
|
+
testimonial: typeof Testimonial;
|
|
74
|
+
"faq-item": typeof FaqItem;
|
|
75
|
+
logo: typeof Logo;
|
|
76
|
+
}>;
|
|
77
|
+
export {};
|
|
78
|
+
//# sourceMappingURL=library.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"library.d.ts","sourceRoot":"","sources":["../src/library.tsx"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAEf,OAAO,EAUL,KAAK,cAAc,EACpB,MAAM,qBAAqB,CAAC;AAG7B,KAAK,QAAQ,GAAG,cAAc,CAAC,UAAU,CAAC,CAAC;AAI3C,wBAAgB,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,GAAG,IA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, } from "react";
|
|
3
|
+
import { Link } from "@tanstack/react-router";
|
|
4
|
+
import { EditableField, localizedHref, usePickedCollections, usePickedProducts, useStoreText, useStorefront, useThemeComponents, useThemeRuntime, } from "@orunelle/theme-sdk";
|
|
5
|
+
// ── Shared helpers ──────────────────────────────────────────────────────────
|
|
6
|
+
export function textOf(value, locale) {
|
|
7
|
+
if (typeof value === "string")
|
|
8
|
+
return value;
|
|
9
|
+
if (value && typeof value === "object" && locale in value)
|
|
10
|
+
return String(value[locale]);
|
|
11
|
+
return "";
|
|
12
|
+
}
|
|
13
|
+
const numberOf = (value, fallback) => typeof value === "number" && Number.isFinite(value) ? value : fallback;
|
|
14
|
+
const choice = (value, options, fallback) => (options.includes(value) ? value : fallback);
|
|
15
|
+
/** Color schemes are declared as select values like "scheme-2". */
|
|
16
|
+
export function schemeOf(settings) {
|
|
17
|
+
return typeof settings.scheme === "string" &&
|
|
18
|
+
/^scheme-[a-z0-9-]+$/.test(settings.scheme)
|
|
19
|
+
? settings.scheme
|
|
20
|
+
: undefined;
|
|
21
|
+
}
|
|
22
|
+
/** Resolves an image setting against the media the platform allowed. */
|
|
23
|
+
export function useMediaImage(value) {
|
|
24
|
+
const { media, storefront } = useThemeRuntime();
|
|
25
|
+
const image = value;
|
|
26
|
+
const asset = image && typeof image === "object" && "assetId" in image
|
|
27
|
+
? media.find((item) => item.id === image.assetId)
|
|
28
|
+
: undefined;
|
|
29
|
+
if (!asset || !image)
|
|
30
|
+
return undefined;
|
|
31
|
+
return {
|
|
32
|
+
url: asset.url,
|
|
33
|
+
alt: image.alt?.[storefront.locale] || asset.alt,
|
|
34
|
+
position: `${(image.focalPoint?.x ?? 0.5) * 100}% ${(image.focalPoint?.y ?? 0.5) * 100}%`,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export function ThemeImage({ value, className, priority = false, fallback = null, }) {
|
|
38
|
+
const image = useMediaImage(value);
|
|
39
|
+
const [failed, setFailed] = useState(false);
|
|
40
|
+
if (!image || failed)
|
|
41
|
+
return _jsx(_Fragment, { children: fallback });
|
|
42
|
+
return (_jsx("img", { className: className, src: image.url, alt: image.alt, loading: priority ? "eager" : "lazy", fetchPriority: priority ? "high" : "auto", decoding: "async", style: { objectPosition: image.position }, onError: () => setFailed(true) }));
|
|
43
|
+
}
|
|
44
|
+
export function RichText({ value, field }) {
|
|
45
|
+
const paragraphs = Array.isArray(value) ? value : [];
|
|
46
|
+
return (_jsx("div", { className: "theme-copy", "data-orunelle-field": field, children: paragraphs.map((paragraph, index) => (_jsx("p", { children: paragraph.children.map((run, n) => {
|
|
47
|
+
let node = run.text;
|
|
48
|
+
if (run.marks.includes("bold"))
|
|
49
|
+
node = _jsx("strong", { children: node });
|
|
50
|
+
if (run.marks.includes("italic"))
|
|
51
|
+
node = _jsx("em", { children: node });
|
|
52
|
+
return _jsx("span", { children: node }, n);
|
|
53
|
+
}) }, index))) }));
|
|
54
|
+
}
|
|
55
|
+
/** Store links use client navigation; anything else is a plain anchor. */
|
|
56
|
+
export function SmartLink({ href, className, children, }) {
|
|
57
|
+
const { locale } = useStorefront();
|
|
58
|
+
const destination = localizedHref(href, locale);
|
|
59
|
+
return destination.startsWith("/") ? (_jsx(Link, { to: destination, className: className, children: children })) : (_jsx("a", { href: destination, className: className, children: children }));
|
|
60
|
+
}
|
|
61
|
+
function SectionTitle({ settings }) {
|
|
62
|
+
const { locale } = useStorefront();
|
|
63
|
+
const title = textOf(settings.title, locale);
|
|
64
|
+
return title ? (_jsx("h2", { className: "theme-section-title", children: _jsx(EditableField, { name: "title", children: title }) })) : null;
|
|
65
|
+
}
|
|
66
|
+
/** Shown only in the editor preview, where an empty section needs a hint. */
|
|
67
|
+
function EditorHint({ en, ar }) {
|
|
68
|
+
const { mode, locale } = useStorefront();
|
|
69
|
+
return mode === "preview" ? (_jsx("p", { className: "theme-editor-hint", role: "status", children: locale === "ar" ? ar : en })) : null;
|
|
70
|
+
}
|
|
71
|
+
function Section({ name, settings, className = "", style, children, }) {
|
|
72
|
+
return (_jsx("section", { className: `theme-section theme-${name} ${className}`.trim(), "data-scheme": schemeOf(settings), style: style, children: children }));
|
|
73
|
+
}
|
|
74
|
+
const columnsStyle = (settings, fallback) => ({
|
|
75
|
+
"--columns": Math.min(6, Math.max(1, numberOf(settings.columns, fallback))),
|
|
76
|
+
});
|
|
77
|
+
function ProductGrid({ products, settings, }) {
|
|
78
|
+
const { ProductCard } = useThemeComponents();
|
|
79
|
+
return (_jsx("div", { className: "theme-grid", style: columnsStyle(settings, 4), children: products.map((product) => (_jsx(ProductCard, { product: product }, product.id))) }));
|
|
80
|
+
}
|
|
81
|
+
// ── Sections ────────────────────────────────────────────────────────────────
|
|
82
|
+
function AnnouncementBar({ settings }) {
|
|
83
|
+
const { locale } = useStorefront();
|
|
84
|
+
const text = textOf(settings.text, locale);
|
|
85
|
+
const href = typeof settings.link === "string" ? settings.link : "";
|
|
86
|
+
if (!text)
|
|
87
|
+
return null;
|
|
88
|
+
const content = _jsx(EditableField, { name: "text", children: text });
|
|
89
|
+
return (_jsx(Section, { name: "announcement", settings: settings, children: href ? _jsx(SmartLink, { href: href, children: content }) : _jsx("p", { children: content }) }));
|
|
90
|
+
}
|
|
91
|
+
function ImageBanner({ settings, children }) {
|
|
92
|
+
const height = choice(settings.height, ["small", "medium", "large"], "medium");
|
|
93
|
+
const overlay = Math.min(90, Math.max(0, numberOf(settings.overlay, 30)));
|
|
94
|
+
return (_jsxs(Section, { name: "banner", settings: settings, className: `theme-height-${height}${settings.align === "start" ? "" : " theme-align-center"}`, style: { "--overlay": overlay / 100 }, children: [_jsx(ThemeImage, { value: settings.image, className: "theme-banner-media", priority: true, fallback: _jsx("div", { className: "theme-banner-media theme-media-empty" }) }), _jsx("div", { className: "theme-banner-content", children: children })] }));
|
|
95
|
+
}
|
|
96
|
+
function Slideshow({ settings, children }) {
|
|
97
|
+
const { locale } = useStorefront();
|
|
98
|
+
const track = useRef(null);
|
|
99
|
+
const [active, setActive] = useState(0);
|
|
100
|
+
const [paused, setPaused] = useState(false);
|
|
101
|
+
const slides = Array.isArray(children) ? children.length : children ? 1 : 0;
|
|
102
|
+
const autoplay = settings.autoplay === true && slides > 1;
|
|
103
|
+
const interval = Math.min(10, Math.max(3, numberOf(settings.interval, 5)));
|
|
104
|
+
const height = choice(settings.height, ["small", "medium", "large"], "medium");
|
|
105
|
+
const go = (index) => {
|
|
106
|
+
const element = track.current;
|
|
107
|
+
if (!element || !slides)
|
|
108
|
+
return;
|
|
109
|
+
const next = (index + slides) % slides;
|
|
110
|
+
// scrollIntoView handles right-to-left tracks, unlike offset arithmetic.
|
|
111
|
+
const slide = element.children[next];
|
|
112
|
+
slide?.scrollIntoView({
|
|
113
|
+
behavior: "smooth",
|
|
114
|
+
block: "nearest",
|
|
115
|
+
inline: "start",
|
|
116
|
+
});
|
|
117
|
+
setActive(next);
|
|
118
|
+
};
|
|
119
|
+
useEffect(() => {
|
|
120
|
+
if (!autoplay || paused)
|
|
121
|
+
return;
|
|
122
|
+
if (window.matchMedia?.("(prefers-reduced-motion: reduce)").matches)
|
|
123
|
+
return;
|
|
124
|
+
const timer = window.setInterval(() => go(active + 1), interval * 1000);
|
|
125
|
+
return () => window.clearInterval(timer);
|
|
126
|
+
});
|
|
127
|
+
// Keep the dots in sync when visitors swipe instead of using the buttons.
|
|
128
|
+
useEffect(() => {
|
|
129
|
+
const element = track.current;
|
|
130
|
+
if (!element)
|
|
131
|
+
return;
|
|
132
|
+
const onScroll = () => {
|
|
133
|
+
const width = element.clientWidth || 1;
|
|
134
|
+
setActive(Math.round(Math.abs(element.scrollLeft) / width));
|
|
135
|
+
};
|
|
136
|
+
element.addEventListener("scroll", onScroll, { passive: true });
|
|
137
|
+
return () => element.removeEventListener("scroll", onScroll);
|
|
138
|
+
}, []);
|
|
139
|
+
return (_jsxs(Section, { name: "slideshow", settings: settings, className: `theme-height-${height}`, children: [_jsx("div", { className: "theme-slides", ref: track, "aria-roledescription": "carousel", "aria-label": locale === "ar" ? "عرض الشرائح" : "Slideshow", onMouseEnter: () => setPaused(true), onMouseLeave: () => setPaused(false), onFocus: () => setPaused(true), onBlur: () => setPaused(false), children: children }), slides > 1 && (_jsxs("div", { className: "theme-slide-controls", children: [_jsx("button", { type: "button", onClick: () => go(active - 1), "aria-label": locale === "ar" ? "الشريحة السابقة" : "Previous slide", children: "\u2039" }), Array.from({ length: slides }, (_, index) => (_jsx("button", { type: "button", className: "theme-slide-dot", "aria-current": index === active, "aria-label": `${locale === "ar" ? "الشريحة" : "Slide"} ${index + 1}`, onClick: () => go(index) }, index))), _jsx("button", { type: "button", onClick: () => go(active + 1), "aria-label": locale === "ar" ? "الشريحة التالية" : "Next slide", children: "\u203A" })] }))] }));
|
|
140
|
+
}
|
|
141
|
+
function RichTextSection({ settings, children }) {
|
|
142
|
+
return (_jsx(Section, { name: "rich-text", settings: settings, className: `${settings.width === "wide" ? "theme-wide" : "theme-narrow"}${settings.align === "start" ? "" : " theme-align-center"}`, children: children }));
|
|
143
|
+
}
|
|
144
|
+
function ImageWithText({ settings, children }) {
|
|
145
|
+
return (_jsxs(Section, { name: "image-with-text", settings: settings, className: settings.layout === "image-end" ? "theme-image-end" : "", children: [_jsx(ThemeImage, { value: settings.image, className: "theme-split-media", fallback: _jsx("div", { className: "theme-split-media theme-media-empty" }) }), _jsx("div", { className: "theme-split-content", children: children })] }));
|
|
146
|
+
}
|
|
147
|
+
function Multicolumn({ settings, children }) {
|
|
148
|
+
return (_jsxs(Section, { name: "multicolumn", settings: settings, children: [_jsx(SectionTitle, { settings: settings }), _jsx("div", { className: "theme-grid", style: columnsStyle(settings, 3), children: children })] }));
|
|
149
|
+
}
|
|
150
|
+
function FeaturedProducts({ settings }) {
|
|
151
|
+
const products = usePickedProducts(settings.products);
|
|
152
|
+
return (_jsxs(Section, { name: "featured-products", settings: settings, children: [_jsx(SectionTitle, { settings: settings }), products.length ? (_jsx(ProductGrid, { products: products, settings: settings })) : (_jsx(EditorHint, { en: "Choose products to feature in this section.", ar: "\u0627\u062E\u062A\u0631 \u0627\u0644\u0645\u0646\u062A\u062C\u0627\u062A \u0627\u0644\u062A\u064A \u062A\u0631\u064A\u062F \u0639\u0631\u0636\u0647\u0627 \u0641\u064A \u0647\u0630\u0627 \u0627\u0644\u0642\u0633\u0645." }))] }));
|
|
153
|
+
}
|
|
154
|
+
function FeaturedCollection({ settings }) {
|
|
155
|
+
const { locale } = useStorefront();
|
|
156
|
+
const text = useStoreText();
|
|
157
|
+
const [collection] = usePickedCollections(settings.collection);
|
|
158
|
+
const limit = Math.min(12, Math.max(1, numberOf(settings.limit, 4)));
|
|
159
|
+
const products = collection?.products?.slice(0, limit) ?? [];
|
|
160
|
+
const title = textOf(settings.title, locale) || collection?.name;
|
|
161
|
+
return (_jsxs(Section, { name: "featured-collection", settings: settings, children: [title && (_jsxs("div", { className: "theme-section-head", children: [_jsx("h2", { className: "theme-section-title", children: title }), collection && (_jsx(SmartLink, { href: `/collections/${collection.slug}`, children: text("general.view_all") }))] })), products.length ? (_jsx(ProductGrid, { products: products, settings: settings })) : (_jsx(EditorHint, { en: "Choose a collection with published products.", ar: "\u0627\u062E\u062A\u0631 \u0645\u062C\u0645\u0648\u0639\u0629 \u062A\u062D\u062A\u0648\u064A \u0639\u0644\u0649 \u0645\u0646\u062A\u062C\u0627\u062A \u0645\u0646\u0634\u0648\u0631\u0629." }))] }));
|
|
162
|
+
}
|
|
163
|
+
function CollectionList({ settings }) {
|
|
164
|
+
const collections = usePickedCollections(settings.collections);
|
|
165
|
+
return (_jsxs(Section, { name: "collection-list", settings: settings, children: [_jsx(SectionTitle, { settings: settings }), collections.length ? (_jsx("div", { className: "theme-grid", style: columnsStyle(settings, 3), children: collections.map((collection) => (_jsxs(SmartLink, { href: `/collections/${collection.slug}`, className: "theme-collection-card", children: [_jsx("strong", { children: collection.name }), collection.description && _jsx("span", { children: collection.description })] }, collection.id))) })) : (_jsx(EditorHint, { en: "Choose collections to show.", ar: "\u0627\u062E\u062A\u0631 \u0627\u0644\u0645\u062C\u0645\u0648\u0639\u0627\u062A \u0627\u0644\u062A\u064A \u062A\u0631\u064A\u062F \u0639\u0631\u0636\u0647\u0627." }))] }));
|
|
166
|
+
}
|
|
167
|
+
function Testimonials({ settings, children }) {
|
|
168
|
+
return (_jsxs(Section, { name: "testimonials", settings: settings, children: [_jsx(SectionTitle, { settings: settings }), _jsx("div", { className: "theme-grid", style: columnsStyle(settings, 3), children: children })] }));
|
|
169
|
+
}
|
|
170
|
+
function Faq({ settings, children }) {
|
|
171
|
+
return (_jsxs(Section, { name: "faq", settings: settings, className: "theme-narrow", children: [_jsx(SectionTitle, { settings: settings }), _jsx("div", { className: "theme-faq-list", children: children })] }));
|
|
172
|
+
}
|
|
173
|
+
/** Only these hosts may be embedded; everything else plays as a file or not at all. */
|
|
174
|
+
export function videoEmbed(url) {
|
|
175
|
+
let parsed;
|
|
176
|
+
try {
|
|
177
|
+
parsed = new URL(url);
|
|
178
|
+
}
|
|
179
|
+
catch {
|
|
180
|
+
return undefined;
|
|
181
|
+
}
|
|
182
|
+
if (parsed.protocol !== "https:")
|
|
183
|
+
return undefined;
|
|
184
|
+
const host = parsed.hostname.replace(/^www\./, "");
|
|
185
|
+
let id;
|
|
186
|
+
if (host === "youtube.com" || host === "m.youtube.com")
|
|
187
|
+
id = parsed.pathname.startsWith("/shorts/")
|
|
188
|
+
? parsed.pathname.split("/")[2]
|
|
189
|
+
: parsed.searchParams.get("v");
|
|
190
|
+
else if (host === "youtu.be")
|
|
191
|
+
id = parsed.pathname.slice(1);
|
|
192
|
+
if (id && /^[\w-]{6,20}$/.test(id))
|
|
193
|
+
return {
|
|
194
|
+
kind: "iframe",
|
|
195
|
+
src: `https://www.youtube-nocookie.com/embed/${id}?autoplay=1&rel=0`,
|
|
196
|
+
};
|
|
197
|
+
if (host === "vimeo.com") {
|
|
198
|
+
const vimeo = parsed.pathname.split("/")[1];
|
|
199
|
+
if (vimeo && /^\d{4,12}$/.test(vimeo))
|
|
200
|
+
return {
|
|
201
|
+
kind: "iframe",
|
|
202
|
+
src: `https://player.vimeo.com/video/${vimeo}?autoplay=1`,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
if (/\.(mp4|webm)$/i.test(parsed.pathname))
|
|
206
|
+
return { kind: "file", src: parsed.href };
|
|
207
|
+
return undefined;
|
|
208
|
+
}
|
|
209
|
+
function Video({ settings }) {
|
|
210
|
+
const { locale } = useStorefront();
|
|
211
|
+
const [playing, setPlaying] = useState(false);
|
|
212
|
+
const embed = videoEmbed(typeof settings.url === "string" ? settings.url : "");
|
|
213
|
+
const title = textOf(settings.title, locale) || (locale === "ar" ? "فيديو" : "Video");
|
|
214
|
+
const poster = useMediaImage(settings.poster);
|
|
215
|
+
if (!embed)
|
|
216
|
+
return (_jsx(EditorHint, { en: "Add a YouTube, Vimeo or MP4 link.", ar: "\u0623\u0636\u0641 \u0631\u0627\u0628\u0637 \u064A\u0648\u062A\u064A\u0648\u0628 \u0623\u0648 \u0641\u064A\u0645\u064A\u0648 \u0623\u0648 \u0645\u0644\u0641 MP4." }));
|
|
217
|
+
return (_jsx(Section, { name: "video", settings: settings, children: _jsx("div", { className: "theme-video-frame", children: embed.kind === "file" ? (_jsx("video", { src: embed.src, poster: poster?.url, controls: true, preload: "none", playsInline: true, "aria-label": title })) : playing ? (_jsx("iframe", { src: embed.src, title: title, allow: "autoplay; encrypted-media; picture-in-picture; fullscreen", referrerPolicy: "strict-origin-when-cross-origin", loading: "lazy" })) : (
|
|
218
|
+
// The player loads only after a click, keeping the page light.
|
|
219
|
+
_jsxs("button", { type: "button", className: "theme-video-facade", onClick: () => setPlaying(true), "aria-label": `${locale === "ar" ? "تشغيل" : "Play"}: ${title}`, children: [poster && _jsx("img", { src: poster.url, alt: "", loading: "lazy" }), _jsx("span", { "aria-hidden": "true", children: "\u25B6" })] })) }) }));
|
|
220
|
+
}
|
|
221
|
+
function LogoList({ settings, children }) {
|
|
222
|
+
return (_jsxs(Section, { name: "logo-list", settings: settings, children: [_jsx(SectionTitle, { settings: settings }), _jsx("div", { className: "theme-logos", children: children })] }));
|
|
223
|
+
}
|
|
224
|
+
// ── Blocks ──────────────────────────────────────────────────────────────────
|
|
225
|
+
function Slide({ settings }) {
|
|
226
|
+
const { locale } = useStorefront();
|
|
227
|
+
const heading = textOf(settings.heading, locale);
|
|
228
|
+
const text = textOf(settings.text, locale);
|
|
229
|
+
const label = textOf(settings["button-label"], locale);
|
|
230
|
+
const href = typeof settings.link === "string" ? settings.link : "";
|
|
231
|
+
return (_jsxs("div", { className: "theme-slide", "aria-roledescription": "slide", children: [_jsx(ThemeImage, { value: settings.image, className: "theme-banner-media", fallback: _jsx("div", { className: "theme-banner-media theme-media-empty" }) }), _jsxs("div", { className: "theme-banner-content", children: [heading && (_jsx("h2", { children: _jsx(EditableField, { name: "heading", children: heading }) })), text && _jsx("p", { children: text }), label && href && (_jsx(SmartLink, { href: href, className: "theme-link-button", children: label }))] })] }));
|
|
232
|
+
}
|
|
233
|
+
function Column({ settings }) {
|
|
234
|
+
const { locale } = useStorefront();
|
|
235
|
+
const title = textOf(settings.title, locale);
|
|
236
|
+
const text = textOf(settings.text, locale);
|
|
237
|
+
const href = typeof settings.link === "string" ? settings.link : "";
|
|
238
|
+
return (_jsxs("div", { className: "theme-column", children: [_jsx(ThemeImage, { value: settings.image, className: "theme-column-media" }), title && (_jsx("h3", { children: href ? _jsx(SmartLink, { href: href, children: title }) : title })), text && _jsx("p", { children: text })] }));
|
|
239
|
+
}
|
|
240
|
+
function Testimonial({ settings }) {
|
|
241
|
+
const { locale } = useStorefront();
|
|
242
|
+
const rating = Math.min(5, Math.max(0, Math.round(numberOf(settings.rating, 5))));
|
|
243
|
+
return (_jsxs("figure", { className: "theme-testimonial", children: [rating > 0 && (_jsxs("p", { className: "theme-rating", "aria-label": locale === "ar"
|
|
244
|
+
? `التقييم ${rating} من 5`
|
|
245
|
+
: `Rated ${rating} out of 5`, children: ["★".repeat(rating), _jsx("span", { "aria-hidden": "true", children: "★".repeat(5 - rating) })] })), _jsx("blockquote", { children: _jsx(EditableField, { name: "quote", children: textOf(settings.quote, locale) }) }), _jsx("figcaption", { children: textOf(settings.author, locale) })] }));
|
|
246
|
+
}
|
|
247
|
+
function FaqItem({ settings }) {
|
|
248
|
+
const { locale } = useStorefront();
|
|
249
|
+
return (_jsxs("details", { className: "theme-faq-item", children: [_jsx("summary", { children: _jsx(EditableField, { name: "question", children: textOf(settings.question, locale) }) }), _jsx(RichText, { value: settings.answer, field: "answer" })] }));
|
|
250
|
+
}
|
|
251
|
+
function Logo({ settings }) {
|
|
252
|
+
const href = typeof settings.link === "string" ? settings.link : "";
|
|
253
|
+
const image = _jsx(ThemeImage, { value: settings.image, className: "theme-logo" });
|
|
254
|
+
return href ? _jsx(SmartLink, { href: href, children: image }) : image;
|
|
255
|
+
}
|
|
256
|
+
export const librarySections = Object.freeze({
|
|
257
|
+
"announcement-bar": AnnouncementBar,
|
|
258
|
+
"image-banner": ImageBanner,
|
|
259
|
+
slideshow: Slideshow,
|
|
260
|
+
"rich-text": RichTextSection,
|
|
261
|
+
"image-with-text": ImageWithText,
|
|
262
|
+
multicolumn: Multicolumn,
|
|
263
|
+
"featured-products": FeaturedProducts,
|
|
264
|
+
"featured-collection": FeaturedCollection,
|
|
265
|
+
"collection-list": CollectionList,
|
|
266
|
+
testimonials: Testimonials,
|
|
267
|
+
faq: Faq,
|
|
268
|
+
video: Video,
|
|
269
|
+
"logo-list": LogoList,
|
|
270
|
+
});
|
|
271
|
+
export const libraryBlocks = Object.freeze({
|
|
272
|
+
slide: Slide,
|
|
273
|
+
column: Column,
|
|
274
|
+
testimonial: Testimonial,
|
|
275
|
+
"faq-item": FaqItem,
|
|
276
|
+
logo: Logo,
|
|
277
|
+
});
|