@nuvler/theme-sdk 1.2.1 → 1.2.2

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/README.md CHANGED
@@ -38,3 +38,7 @@ protocolo `mount/unmount` e `sdkVersion` declara a faixa do SDK aceita.
38
38
  `primary`, `secondary`, `background` e `text` permanecem obrigatórios para
39
39
  compatibilidade. Os demais tokens semânticos são opcionais no contrato, mas o
40
40
  starter atual já os declara e os runtimes aplicam fallbacks para temas antigos.
41
+
42
+ Use `productUrl(product)` ao gerar links de produto. Quando `categoryPath`
43
+ estiver presente, a URL inclui toda a hierarquia da categoria principal; com
44
+ APIs antigas, o helper mantém o fallback `/produto/slug`.
package/dist/index.d.ts CHANGED
@@ -1,7 +1,11 @@
1
1
  import type { ComponentType, ReactNode } from "react";
2
2
  export declare const THEME_SCHEMA_VERSION: 1;
3
- export declare const THEME_API_VERSION: "1.2.1";
3
+ export declare const THEME_API_VERSION: "1.2.2";
4
4
  export declare const THEME_RUNTIME_VERSION: "1";
5
+ /** Decodifica entidades HTML comuns, inclusive conteúdo legado duplamente codificado. */
6
+ export declare function decodeHtmlEntities(value: string): string;
7
+ /** Converte HTML em texto adequado para resumos, cards e metadados. */
8
+ export declare function htmlToPlainText(value: string): string;
5
9
  export interface ThemeApiCompatibility {
6
10
  themeApi: string;
7
11
  }
@@ -159,6 +163,8 @@ export interface ThemeProduct {
159
163
  image: ThemeImage | null;
160
164
  images: ThemeImage[];
161
165
  categories: ThemeCategory[];
166
+ /** Caminho da categoria principal, da raiz até a categoria atribuída. */
167
+ categoryPath?: string[];
162
168
  variantOptions: Array<{
163
169
  name: string;
164
170
  values: string[];
@@ -281,6 +287,7 @@ export interface ProductGridProps {
281
287
  }
282
288
  export interface ThemeCartItem {
283
289
  productSlug: string;
290
+ productUrl?: string;
284
291
  title: string;
285
292
  sku: string;
286
293
  variantId?: string | null;
@@ -288,6 +295,8 @@ export interface ThemeCartItem {
288
295
  image?: ThemeImage | null;
289
296
  unitPrice?: number | null;
290
297
  }
298
+ /** URL canônica relativa do produto, com fallback para lojas/APIs antigas. */
299
+ export declare function productUrl(product: Pick<ThemeProduct, "slug" | "categoryPath">): string;
291
300
  export interface ProductDetailProps {
292
301
  product: ThemeProduct;
293
302
  contact?: ThemeContact;
package/dist/index.js CHANGED
@@ -1,6 +1,60 @@
1
1
  export const THEME_SCHEMA_VERSION = 1;
2
- export const THEME_API_VERSION = "1.2.1";
2
+ export const THEME_API_VERSION = "1.2.2";
3
3
  export const THEME_RUNTIME_VERSION = "1";
4
+ const HTML_NAMED_ENTITIES = {
5
+ amp: "&", apos: "'", gt: ">", lt: "<", nbsp: " ", quot: '"',
6
+ agrave: "à", aacute: "á", acirc: "â", atilde: "ã", auml: "ä", aring: "å", aelig: "æ",
7
+ ccedil: "ç", egrave: "è", eacute: "é", ecirc: "ê", euml: "ë",
8
+ igrave: "ì", iacute: "í", icirc: "î", iuml: "ï", ntilde: "ñ",
9
+ ograve: "ò", oacute: "ó", ocirc: "ô", otilde: "õ", ouml: "ö", oslash: "ø",
10
+ ugrave: "ù", uacute: "ú", ucirc: "û", uuml: "ü", yacute: "ý", yuml: "ÿ",
11
+ laquo: "«", raquo: "»", lsquo: "‘", rsquo: "’", ldquo: "“", rdquo: "”",
12
+ ndash: "–", mdash: "—", hellip: "…", bull: "•", middot: "·",
13
+ copy: "©", reg: "®", trade: "™", deg: "°", plusmn: "±", times: "×", divide: "÷",
14
+ };
15
+ function decodeHtmlEntitiesOnce(value) {
16
+ return value.replace(/&(#(?:x[\da-f]+|\d+)|[a-z][a-z\d]+);/gi, (entity, code) => {
17
+ if (!code.startsWith("#"))
18
+ return HTML_NAMED_ENTITIES[code.toLowerCase()] ?? entity;
19
+ const hexadecimal = code[1]?.toLowerCase() === "x";
20
+ const codePoint = Number.parseInt(code.slice(hexadecimal ? 2 : 1), hexadecimal ? 16 : 10);
21
+ if (!Number.isFinite(codePoint))
22
+ return entity;
23
+ try {
24
+ return String.fromCodePoint(codePoint);
25
+ }
26
+ catch {
27
+ return entity;
28
+ }
29
+ });
30
+ }
31
+ /** Decodifica entidades HTML comuns, inclusive conteúdo legado duplamente codificado. */
32
+ export function decodeHtmlEntities(value) {
33
+ let decoded = value;
34
+ for (let pass = 0; pass < 2; pass += 1) {
35
+ const next = decodeHtmlEntitiesOnce(decoded);
36
+ if (next === decoded)
37
+ break;
38
+ decoded = next;
39
+ }
40
+ return decoded;
41
+ }
42
+ /** Converte HTML em texto adequado para resumos, cards e metadados. */
43
+ export function htmlToPlainText(value) {
44
+ return decodeHtmlEntities(value)
45
+ .replace(/<(script|style)\b[^>]*>[\s\S]*?<\/\1>/gi, " ")
46
+ .replace(/<br\s*\/?>/gi, " ")
47
+ .replace(/<\/(p|div|li|h[1-6]|blockquote|tr)>/gi, " ")
48
+ .replace(/<[^>]+>/g, " ")
49
+ .replace(/\s+/g, " ")
50
+ .trim();
51
+ }
52
+ /** URL canônica relativa do produto, com fallback para lojas/APIs antigas. */
53
+ export function productUrl(product) {
54
+ const categoryPath = product.categoryPath?.filter(Boolean) ?? [];
55
+ const segments = categoryPath.length ? [...categoryPath, product.slug] : ["produto", product.slug];
56
+ return `/${segments.map(encodeURIComponent).join("/")}`;
57
+ }
4
58
  export function defineTheme(theme) {
5
59
  return theme;
6
60
  }
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAU,CAAC;AAC/C,MAAM,CAAC,MAAM,iBAAiB,GAAG,OAAgB,CAAC;AAClD,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAY,CAAC;AA2clD,MAAM,UAAU,WAAW,CAAkD,KAAa;IACxF,OAAO,KAAK,CAAC;AACf,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,oBAAoB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AAC,CAAC;QAC7C,IAAI,IAAI,KAAK,OAAO;YAAE,MAAM;QAC5B,OAAO,GAAG,IAAI,CAAC;IACjB,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,uEAAuE;AACvE,MAAM,UAAU,eAAe,CAAC,KAAa;IAC3C,OAAO,kBAAkB,CAAC,KAAK,CAAC;SAC7B,OAAO,CAAC,yCAAyC,EAAE,GAAG,CAAC;SACvD,OAAO,CAAC,cAAc,EAAE,GAAG,CAAC;SAC5B,OAAO,CAAC,uCAAuC,EAAE,GAAG,CAAC;SACrD,OAAO,CAAC,UAAU,EAAE,GAAG,CAAC;SACxB,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;SACpB,IAAI,EAAE,CAAC;AACZ,CAAC;AA+TD,8EAA8E;AAC9E,MAAM,UAAU,UAAU,CAAC,OAAoD;IAC7E,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,EAAE,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;IACjE,MAAM,QAAQ,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,YAAY,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IACnG,OAAO,IAAI,QAAQ,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;AAC1D,CAAC;AAiJD,MAAM,UAAU,WAAW,CAAkD,KAAa;IACxF,OAAO,KAAK,CAAC;AACf,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuvler/theme-sdk",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "Contrato público para temas da plataforma Nuvler",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",