@vtex/ads-stories 0.1.0 → 0.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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @vtex/ads-stories
2
2
 
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Add TypeScript types for using `<vtex-ads-story>` in React: opt in with `import type {} from "@vtex/ads-stories/react"`. `document.createElement("vtex-ads-story")` and `querySelector("vtex-ads-story")` are now typed as `VtexAdsStoryElement`.
8
+ - The bare CDN URLs (`https://unpkg.com/@vtex/ads-stories@<version>` and `https://cdn.jsdelivr.net/npm/@vtex/ads-stories@<version>`) now serve the standalone browser script (`dist/cdn/vtex-ads-stories.js`) instead of the CommonJS build.
9
+
3
10
  ## 0.1.0
4
11
 
5
12
  ### Minor Changes
package/README.md CHANGED
@@ -28,9 +28,63 @@ Importing the package has no side effects: nothing is registered until
28
28
  rendering, where `defineVtexAdsStories()` does nothing. Both ESM (`import`) and
29
29
  CommonJS (`require`) builds are published, with type declarations.
30
30
 
31
+ ### TypeScript and React
32
+
33
+ `document.createElement("vtex-ads-story")` and
34
+ `document.querySelector("vtex-ads-story")` are typed as `VtexAdsStoryElement`
35
+ out of the box.
36
+
37
+ To use `<vtex-ads-story>` in `.tsx` files, enable its JSX types once in your
38
+ project (requires `@types/react` 18.2.6 or newer, including 19):
39
+
40
+ ```tsx
41
+ // e.g. in your app's entry file or a .d.ts file
42
+ import type {} from "@vtex/ads-stories/react";
43
+
44
+ export const Ad = () => <vtex-ads-story name="VTEX Ads" />;
45
+ ```
46
+
47
+ Or add `"@vtex/ads-stories/react"` to `compilerOptions.types` in `tsconfig.json`.
48
+ Without it, TypeScript reports
49
+ `Property 'vtex-ads-story' does not exist on type 'JSX.IntrinsicElements'`.
50
+ The types are opt-in so projects without React don't need `@types/react`.
51
+
31
52
  ## CDN
32
53
 
33
- WIP: To be defined
54
+ The same build is available as a standalone script from
55
+ [unpkg](https://unpkg.com) and [jsDelivr](https://www.jsdelivr.com). It
56
+ registers `<vtex-ads-story>` when it loads, so no JavaScript is needed in the
57
+ page. Always pin an exact version: a pinned URL never changes.
58
+
59
+ ```html
60
+ <script
61
+ src="https://unpkg.com/@vtex/ads-stories@0.2.0"
62
+ integrity="sha384-<hash>"
63
+ crossorigin="anonymous"
64
+ ></script>
65
+
66
+ <vtex-ads-story name="VTEX Ads"></vtex-ads-story>
67
+ ```
68
+
69
+ - The full file URL works too:
70
+ `https://unpkg.com/@vtex/ads-stories@<version>/dist/cdn/vtex-ads-stories.js`.
71
+ - jsDelivr serves the same file:
72
+ `https://cdn.jsdelivr.net/npm/@vtex/ads-stories@<version>`.
73
+ - `integrity` is optional. With it, the browser refuses the file if its content
74
+ is not exactly the published one. Get the hash for a version with:
75
+
76
+ ```bash
77
+ curl -fsSLo vtex-ads-stories.js https://unpkg.com/@vtex/ads-stories@<version>/dist/cdn/vtex-ads-stories.js \
78
+ && openssl dgst -sha384 -binary vtex-ads-stories.js | openssl base64 -A
79
+ ```
80
+
81
+ The hash is only printed if the download succeeded, so a wrong version
82
+ shows an error instead of a hash of an error page.
83
+
84
+ - Stores with a Content-Security-Policy must allow the CDN host in
85
+ `script-src` (`https://unpkg.com` or `https://cdn.jsdelivr.net`).
86
+ - The script also exposes `window.VtexAdsStories` with the same API as the npm
87
+ package.
34
88
 
35
89
  ## Customization
36
90
 
@@ -1,8 +1,8 @@
1
- "use strict";var VtexAdsStories=(()=>{var a=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var f=(r,t)=>{for(var e in t)a(r,e,{get:t[e],enumerable:!0})},u=(r,t,e,d)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of m(t))!h.call(r,s)&&s!==e&&a(r,s,{get:()=>t[s],enumerable:!(d=c(t,s))||d.enumerable});return r};var y=r=>u(a({},"__esModule",{value:!0}),r);var E={};f(E,{TAG_NAME:()=>n,VtexAdsStoryElement:()=>o,defineVtexAdsStories:()=>i});var n="vtex-ads-story",l,p=(l=globalThis.HTMLElement)!=null?l:Object,x=`
1
+ "use strict";var VtexAdsStories=(()=>{var a=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var h=(r,t)=>{for(var e in t)a(r,e,{get:t[e],enumerable:!0})},y=(r,t,e,l)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of m(t))!f.call(r,s)&&s!==e&&a(r,s,{get:()=>t[s],enumerable:!(l=c(t,s))||l.enumerable});return r};var u=r=>y(a({},"__esModule",{value:!0}),r);var E={};h(E,{TAG_NAME:()=>n,VtexAdsStoryElement:()=>o,defineVtexAdsStories:()=>i});var n="vtex-ads-story",d,x=(d=globalThis.HTMLElement)!=null?d:Object,p=`
2
2
  :host {
3
3
  display: block;
4
4
  font-family: var(--vtex-ads-story-font-family, inherit);
5
5
  color: var(--vtex-ads-story-color-text, inherit);
6
6
  }
7
- `,A="world",o=class extends p{static get observedAttributes(){return["name"]}get name(){var t,e;return(e=(t=this.getAttribute("name"))==null?void 0:t.trim())!=null?e:""}set name(t){this.setAttribute("name",t)}render(){var e;let t=(e=this.shadowRoot)==null?void 0:e.querySelector("[part='root']");t&&(t.textContent=`Hello ${this.name||A}!`)}connectedCallback(){if(!this.shadowRoot){let t=this.attachShadow({mode:"open"});t.innerHTML=`<style>${x}</style><div part="root"></div>`}this.upgradeProperty("name"),this.render()}upgradeProperty(t){if(!Object.prototype.hasOwnProperty.call(this,t))return;let e=this[t];Reflect.deleteProperty(this,t),this[t]=e}attributeChangedCallback(){this.render()}};function i(){typeof customElements!="undefined"&&(customElements.get(n)||customElements.define(n,o))}i();return y(E);})();
7
+ `,A="world",o=class extends x{static get observedAttributes(){return["name"]}get name(){var t,e;return(e=(t=this.getAttribute("name"))==null?void 0:t.trim())!=null?e:""}set name(t){this.setAttribute("name",t)}render(){var e;let t=(e=this.shadowRoot)==null?void 0:e.querySelector("[part='root']");t&&(t.textContent=`Hello ${this.name||A}!`)}connectedCallback(){if(!this.shadowRoot){let t=this.attachShadow({mode:"open"});t.innerHTML=`<style>${p}</style><div part="root"></div>`}this.upgradeProperty("name"),this.render()}upgradeProperty(t){if(!Object.prototype.hasOwnProperty.call(this,t))return;let e=this[t];Reflect.deleteProperty(this,t),this[t]=e}attributeChangedCallback(){this.render()}};function i(){typeof customElements!="undefined"&&(customElements.get(n)||customElements.define(n,o))}i();return u(E);})();
8
8
  //# sourceMappingURL=vtex-ads-stories.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/cdn.ts","../../src/story/story.ts"],"sourcesContent":["import { defineVtexAdsStories } from \"./story\";\n\ndefineVtexAdsStories();\n\nexport { VtexAdsStoryElement, defineVtexAdsStories, TAG_NAME } from \"./story\";\n","export const TAG_NAME = \"vtex-ads-story\";\n\n// Keeps the module importable where HTMLElement doesn't exist (SSR, Node).\nconst BaseElement: typeof HTMLElement = globalThis.HTMLElement ?? Object;\n\nconst styles = `\n :host {\n display: block;\n font-family: var(--vtex-ads-story-font-family, inherit);\n color: var(--vtex-ads-story-color-text, inherit);\n }\n`;\n\nconst DEFAULT_NAME = \"world\";\n\nexport class VtexAdsStoryElement extends BaseElement {\n static get observedAttributes() {\n return [\"name\"];\n }\n\n get name(): string {\n return this.getAttribute(\"name\")?.trim() ?? \"\";\n }\n\n set name(value: string) {\n this.setAttribute(\"name\", value);\n }\n\n private render() {\n const container = this.shadowRoot?.querySelector(\"[part='root']\");\n if (!container) return;\n\n // textContent keeps the name as plain text (no HTML injection).\n container.textContent = `Hello ${this.name || DEFAULT_NAME}!`;\n }\n\n connectedCallback() {\n if (!this.shadowRoot) {\n const root = this.attachShadow({ mode: \"open\" });\n root.innerHTML = `<style>${styles}</style><div part=\"root\"></div>`;\n }\n\n this.upgradeProperty(\"name\");\n this.render();\n }\n\n // A property set before the element is defined (e.g. while the CDN script\n // loads) becomes an own property that shadows the class getter/setter.\n // Remove it and set it again so it goes through the setter.\n private upgradeProperty(prop: \"name\") {\n if (!Object.prototype.hasOwnProperty.call(this, prop)) return;\n\n const value = this[prop];\n Reflect.deleteProperty(this, prop);\n this[prop] = value;\n }\n\n attributeChangedCallback() {\n this.render();\n }\n}\n\nexport function defineVtexAdsStories() {\n if (typeof customElements === \"undefined\") return;\n if (customElements.get(TAG_NAME)) return;\n\n customElements.define(TAG_NAME, VtexAdsStoryElement);\n}\n"],"mappings":"kcAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,cAAAE,EAAA,wBAAAC,EAAA,yBAAAC,ICAO,IAAMC,EAAW,iBAAxBC,EAGMC,GAAkCD,EAAA,WAAW,cAAX,KAAAA,EAA0B,OAE5DE,EAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQTC,EAAe,QAERC,EAAN,cAAkCH,CAAY,CACnD,WAAW,oBAAqB,CAC9B,MAAO,CAAC,MAAM,CAChB,CAEA,IAAI,MAAe,CApBrB,IAAAD,EAAAK,EAqBI,OAAOA,GAAAL,EAAA,KAAK,aAAa,MAAM,IAAxB,YAAAA,EAA2B,SAA3B,KAAAK,EAAqC,EAC9C,CAEA,IAAI,KAAKC,EAAe,CACtB,KAAK,aAAa,OAAQA,CAAK,CACjC,CAEQ,QAAS,CA5BnB,IAAAN,EA6BI,IAAMO,GAAYP,EAAA,KAAK,aAAL,YAAAA,EAAiB,cAAc,iBAC5CO,IAGLA,EAAU,YAAc,SAAS,KAAK,MAAQJ,CAAY,IAC5D,CAEA,mBAAoB,CAClB,GAAI,CAAC,KAAK,WAAY,CACpB,IAAMK,EAAO,KAAK,aAAa,CAAE,KAAM,MAAO,CAAC,EAC/CA,EAAK,UAAY,UAAUN,CAAM,iCACnC,CAEA,KAAK,gBAAgB,MAAM,EAC3B,KAAK,OAAO,CACd,CAKQ,gBAAgBO,EAAc,CACpC,GAAI,CAAC,OAAO,UAAU,eAAe,KAAK,KAAMA,CAAI,EAAG,OAEvD,IAAMH,EAAQ,KAAKG,CAAI,EACvB,QAAQ,eAAe,KAAMA,CAAI,EACjC,KAAKA,CAAI,EAAIH,CACf,CAEA,0BAA2B,CACzB,KAAK,OAAO,CACd,CACF,EAEO,SAASI,GAAuB,CACjC,OAAO,gBAAmB,cAC1B,eAAe,IAAIX,CAAQ,GAE/B,eAAe,OAAOA,EAAUK,CAAmB,EACrD,CDjEAO,EAAqB","names":["cdn_exports","__export","TAG_NAME","VtexAdsStoryElement","defineVtexAdsStories","TAG_NAME","_a","BaseElement","styles","DEFAULT_NAME","VtexAdsStoryElement","_b","value","container","root","prop","defineVtexAdsStories","defineVtexAdsStories"]}
1
+ {"version":3,"sources":["../../src/cdn.ts","../../src/story/story.ts"],"sourcesContent":["import { defineVtexAdsStories } from \"./story\";\n\ndefineVtexAdsStories();\n\nexport { VtexAdsStoryElement, defineVtexAdsStories, TAG_NAME } from \"./story\";\n","export const TAG_NAME = \"vtex-ads-story\";\n\n// Keeps the module importable where HTMLElement doesn't exist (SSR, Node).\nconst BaseElement: typeof HTMLElement = globalThis.HTMLElement ?? Object;\n\nconst styles = `\n :host {\n display: block;\n font-family: var(--vtex-ads-story-font-family, inherit);\n color: var(--vtex-ads-story-color-text, inherit);\n }\n`;\n\nconst DEFAULT_NAME = \"world\";\n\nexport class VtexAdsStoryElement extends BaseElement {\n static get observedAttributes() {\n return [\"name\"];\n }\n\n get name(): string {\n return this.getAttribute(\"name\")?.trim() ?? \"\";\n }\n\n set name(value: string) {\n this.setAttribute(\"name\", value);\n }\n\n private render() {\n const container = this.shadowRoot?.querySelector(\"[part='root']\");\n if (!container) return;\n\n // textContent keeps the name as plain text (no HTML injection).\n container.textContent = `Hello ${this.name || DEFAULT_NAME}!`;\n }\n\n connectedCallback() {\n if (!this.shadowRoot) {\n const root = this.attachShadow({ mode: \"open\" });\n root.innerHTML = `<style>${styles}</style><div part=\"root\"></div>`;\n }\n\n this.upgradeProperty(\"name\");\n this.render();\n }\n\n // A property set before the element is defined (e.g. while the CDN script\n // loads) becomes an own property that shadows the class getter/setter.\n // Remove it and set it again so it goes through the setter.\n private upgradeProperty(prop: \"name\") {\n if (!Object.prototype.hasOwnProperty.call(this, prop)) return;\n\n const value = this[prop];\n Reflect.deleteProperty(this, prop);\n this[prop] = value;\n }\n\n attributeChangedCallback() {\n this.render();\n }\n}\n\n// Types `document.createElement(\"vtex-ads-story\")` and `querySelector` results\n// as VtexAdsStoryElement in any TypeScript project, no framework needed.\ndeclare global {\n interface HTMLElementTagNameMap {\n \"vtex-ads-story\": VtexAdsStoryElement;\n }\n}\n\nexport function defineVtexAdsStories() {\n if (typeof customElements === \"undefined\") return;\n if (customElements.get(TAG_NAME)) return;\n\n customElements.define(TAG_NAME, VtexAdsStoryElement);\n}\n"],"mappings":"kcAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,cAAAE,EAAA,wBAAAC,EAAA,yBAAAC,ICAO,IAAMC,EAAW,iBAAxBC,EAGMC,GAAkCD,EAAA,WAAW,cAAX,KAAAA,EAA0B,OAE5DE,EAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQTC,EAAe,QAERC,EAAN,cAAkCH,CAAY,CACnD,WAAW,oBAAqB,CAC9B,MAAO,CAAC,MAAM,CAChB,CAEA,IAAI,MAAe,CApBrB,IAAAD,EAAAK,EAqBI,OAAOA,GAAAL,EAAA,KAAK,aAAa,MAAM,IAAxB,YAAAA,EAA2B,SAA3B,KAAAK,EAAqC,EAC9C,CAEA,IAAI,KAAKC,EAAe,CACtB,KAAK,aAAa,OAAQA,CAAK,CACjC,CAEQ,QAAS,CA5BnB,IAAAN,EA6BI,IAAMO,GAAYP,EAAA,KAAK,aAAL,YAAAA,EAAiB,cAAc,iBAC5CO,IAGLA,EAAU,YAAc,SAAS,KAAK,MAAQJ,CAAY,IAC5D,CAEA,mBAAoB,CAClB,GAAI,CAAC,KAAK,WAAY,CACpB,IAAMK,EAAO,KAAK,aAAa,CAAE,KAAM,MAAO,CAAC,EAC/CA,EAAK,UAAY,UAAUN,CAAM,iCACnC,CAEA,KAAK,gBAAgB,MAAM,EAC3B,KAAK,OAAO,CACd,CAKQ,gBAAgBO,EAAc,CACpC,GAAI,CAAC,OAAO,UAAU,eAAe,KAAK,KAAMA,CAAI,EAAG,OAEvD,IAAMH,EAAQ,KAAKG,CAAI,EACvB,QAAQ,eAAe,KAAMA,CAAI,EACjC,KAAKA,CAAI,EAAIH,CACf,CAEA,0BAA2B,CACzB,KAAK,OAAO,CACd,CACF,EAUO,SAASI,GAAuB,CACjC,OAAO,gBAAmB,cAC1B,eAAe,IAAIX,CAAQ,GAE/B,eAAe,OAAOA,EAAUK,CAAmB,EACrD,CDzEAO,EAAqB","names":["cdn_exports","__export","TAG_NAME","VtexAdsStoryElement","defineVtexAdsStories","TAG_NAME","_a","BaseElement","styles","DEFAULT_NAME","VtexAdsStoryElement","_b","value","container","root","prop","defineVtexAdsStories","defineVtexAdsStories"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts","../../src/story/story.ts"],"sourcesContent":["export { VtexAdsStoryElement, defineVtexAdsStories, TAG_NAME } from \"./story\";\n","export const TAG_NAME = \"vtex-ads-story\";\n\n// Keeps the module importable where HTMLElement doesn't exist (SSR, Node).\nconst BaseElement: typeof HTMLElement = globalThis.HTMLElement ?? Object;\n\nconst styles = `\n :host {\n display: block;\n font-family: var(--vtex-ads-story-font-family, inherit);\n color: var(--vtex-ads-story-color-text, inherit);\n }\n`;\n\nconst DEFAULT_NAME = \"world\";\n\nexport class VtexAdsStoryElement extends BaseElement {\n static get observedAttributes() {\n return [\"name\"];\n }\n\n get name(): string {\n return this.getAttribute(\"name\")?.trim() ?? \"\";\n }\n\n set name(value: string) {\n this.setAttribute(\"name\", value);\n }\n\n private render() {\n const container = this.shadowRoot?.querySelector(\"[part='root']\");\n if (!container) return;\n\n // textContent keeps the name as plain text (no HTML injection).\n container.textContent = `Hello ${this.name || DEFAULT_NAME}!`;\n }\n\n connectedCallback() {\n if (!this.shadowRoot) {\n const root = this.attachShadow({ mode: \"open\" });\n root.innerHTML = `<style>${styles}</style><div part=\"root\"></div>`;\n }\n\n this.upgradeProperty(\"name\");\n this.render();\n }\n\n // A property set before the element is defined (e.g. while the CDN script\n // loads) becomes an own property that shadows the class getter/setter.\n // Remove it and set it again so it goes through the setter.\n private upgradeProperty(prop: \"name\") {\n if (!Object.prototype.hasOwnProperty.call(this, prop)) return;\n\n const value = this[prop];\n Reflect.deleteProperty(this, prop);\n this[prop] = value;\n }\n\n attributeChangedCallback() {\n this.render();\n }\n}\n\nexport function defineVtexAdsStories() {\n if (typeof customElements === \"undefined\") return;\n if (customElements.get(TAG_NAME)) return;\n\n customElements.define(TAG_NAME, VtexAdsStoryElement);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,WAAW;AAAxB;AAGA,IAAM,eAAkC,gBAAW,gBAAX,YAA0B;AAElE,IAAM,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQf,IAAM,eAAe;AAEd,IAAM,sBAAN,cAAkC,YAAY;AAAA,EACnD,WAAW,qBAAqB;AAC9B,WAAO,CAAC,MAAM;AAAA,EAChB;AAAA,EAEA,IAAI,OAAe;AApBrB,QAAAA,KAAA;AAqBI,YAAO,MAAAA,MAAA,KAAK,aAAa,MAAM,MAAxB,gBAAAA,IAA2B,WAA3B,YAAqC;AAAA,EAC9C;AAAA,EAEA,IAAI,KAAK,OAAe;AACtB,SAAK,aAAa,QAAQ,KAAK;AAAA,EACjC;AAAA,EAEQ,SAAS;AA5BnB,QAAAA;AA6BI,UAAM,aAAYA,MAAA,KAAK,eAAL,gBAAAA,IAAiB,cAAc;AACjD,QAAI,CAAC,UAAW;AAGhB,cAAU,cAAc,SAAS,KAAK,QAAQ,YAAY;AAAA,EAC5D;AAAA,EAEA,oBAAoB;AAClB,QAAI,CAAC,KAAK,YAAY;AACpB,YAAM,OAAO,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;AAC/C,WAAK,YAAY,UAAU,MAAM;AAAA,IACnC;AAEA,SAAK,gBAAgB,MAAM;AAC3B,SAAK,OAAO;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAKQ,gBAAgB,MAAc;AACpC,QAAI,CAAC,OAAO,UAAU,eAAe,KAAK,MAAM,IAAI,EAAG;AAEvD,UAAM,QAAQ,KAAK,IAAI;AACvB,YAAQ,eAAe,MAAM,IAAI;AACjC,SAAK,IAAI,IAAI;AAAA,EACf;AAAA,EAEA,2BAA2B;AACzB,SAAK,OAAO;AAAA,EACd;AACF;AAEO,SAAS,uBAAuB;AACrC,MAAI,OAAO,mBAAmB,YAAa;AAC3C,MAAI,eAAe,IAAI,QAAQ,EAAG;AAElC,iBAAe,OAAO,UAAU,mBAAmB;AACrD;","names":["_a"]}
1
+ {"version":3,"sources":["../../src/index.ts","../../src/story/story.ts"],"sourcesContent":["export { VtexAdsStoryElement, defineVtexAdsStories, TAG_NAME } from \"./story\";\n","export const TAG_NAME = \"vtex-ads-story\";\n\n// Keeps the module importable where HTMLElement doesn't exist (SSR, Node).\nconst BaseElement: typeof HTMLElement = globalThis.HTMLElement ?? Object;\n\nconst styles = `\n :host {\n display: block;\n font-family: var(--vtex-ads-story-font-family, inherit);\n color: var(--vtex-ads-story-color-text, inherit);\n }\n`;\n\nconst DEFAULT_NAME = \"world\";\n\nexport class VtexAdsStoryElement extends BaseElement {\n static get observedAttributes() {\n return [\"name\"];\n }\n\n get name(): string {\n return this.getAttribute(\"name\")?.trim() ?? \"\";\n }\n\n set name(value: string) {\n this.setAttribute(\"name\", value);\n }\n\n private render() {\n const container = this.shadowRoot?.querySelector(\"[part='root']\");\n if (!container) return;\n\n // textContent keeps the name as plain text (no HTML injection).\n container.textContent = `Hello ${this.name || DEFAULT_NAME}!`;\n }\n\n connectedCallback() {\n if (!this.shadowRoot) {\n const root = this.attachShadow({ mode: \"open\" });\n root.innerHTML = `<style>${styles}</style><div part=\"root\"></div>`;\n }\n\n this.upgradeProperty(\"name\");\n this.render();\n }\n\n // A property set before the element is defined (e.g. while the CDN script\n // loads) becomes an own property that shadows the class getter/setter.\n // Remove it and set it again so it goes through the setter.\n private upgradeProperty(prop: \"name\") {\n if (!Object.prototype.hasOwnProperty.call(this, prop)) return;\n\n const value = this[prop];\n Reflect.deleteProperty(this, prop);\n this[prop] = value;\n }\n\n attributeChangedCallback() {\n this.render();\n }\n}\n\n// Types `document.createElement(\"vtex-ads-story\")` and `querySelector` results\n// as VtexAdsStoryElement in any TypeScript project, no framework needed.\ndeclare global {\n interface HTMLElementTagNameMap {\n \"vtex-ads-story\": VtexAdsStoryElement;\n }\n}\n\nexport function defineVtexAdsStories() {\n if (typeof customElements === \"undefined\") return;\n if (customElements.get(TAG_NAME)) return;\n\n customElements.define(TAG_NAME, VtexAdsStoryElement);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,WAAW;AAAxB;AAGA,IAAM,eAAkC,gBAAW,gBAAX,YAA0B;AAElE,IAAM,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQf,IAAM,eAAe;AAEd,IAAM,sBAAN,cAAkC,YAAY;AAAA,EACnD,WAAW,qBAAqB;AAC9B,WAAO,CAAC,MAAM;AAAA,EAChB;AAAA,EAEA,IAAI,OAAe;AApBrB,QAAAA,KAAA;AAqBI,YAAO,MAAAA,MAAA,KAAK,aAAa,MAAM,MAAxB,gBAAAA,IAA2B,WAA3B,YAAqC;AAAA,EAC9C;AAAA,EAEA,IAAI,KAAK,OAAe;AACtB,SAAK,aAAa,QAAQ,KAAK;AAAA,EACjC;AAAA,EAEQ,SAAS;AA5BnB,QAAAA;AA6BI,UAAM,aAAYA,MAAA,KAAK,eAAL,gBAAAA,IAAiB,cAAc;AACjD,QAAI,CAAC,UAAW;AAGhB,cAAU,cAAc,SAAS,KAAK,QAAQ,YAAY;AAAA,EAC5D;AAAA,EAEA,oBAAoB;AAClB,QAAI,CAAC,KAAK,YAAY;AACpB,YAAM,OAAO,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;AAC/C,WAAK,YAAY,UAAU,MAAM;AAAA,IACnC;AAEA,SAAK,gBAAgB,MAAM;AAC3B,SAAK,OAAO;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAKQ,gBAAgB,MAAc;AACpC,QAAI,CAAC,OAAO,UAAU,eAAe,KAAK,MAAM,IAAI,EAAG;AAEvD,UAAM,QAAQ,KAAK,IAAI;AACvB,YAAQ,eAAe,MAAM,IAAI;AACjC,SAAK,IAAI,IAAI;AAAA,EACf;AAAA,EAEA,2BAA2B;AACzB,SAAK,OAAO;AAAA,EACd;AACF;AAUO,SAAS,uBAAuB;AACrC,MAAI,OAAO,mBAAmB,YAAa;AAC3C,MAAI,eAAe,IAAI,QAAQ,EAAG;AAElC,iBAAe,OAAO,UAAU,mBAAmB;AACrD;","names":["_a"]}
@@ -9,6 +9,11 @@ declare class VtexAdsStoryElement extends BaseElement {
9
9
  private upgradeProperty;
10
10
  attributeChangedCallback(): void;
11
11
  }
12
+ declare global {
13
+ interface HTMLElementTagNameMap {
14
+ "vtex-ads-story": VtexAdsStoryElement;
15
+ }
16
+ }
12
17
  declare function defineVtexAdsStories(): void;
13
18
 
14
19
  export { TAG_NAME, VtexAdsStoryElement, defineVtexAdsStories };
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+
16
+ // src/react.ts
17
+ var react_exports = {};
18
+ module.exports = __toCommonJS(react_exports);
19
+ //# sourceMappingURL=react.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/react.ts"],"sourcesContent":["/**\n * React JSX types for <vtex-ads-story>. Types only: the JS output is empty.\n *\n * Opt in once per project, so non-React projects never need @types/react:\n *\n * import type {} from \"@vtex/ads-stories/react\";\n *\n * or add \"@vtex/ads-stories/react\" to `compilerOptions.types` in tsconfig.\n */\nimport type { DetailedHTMLProps, HTMLAttributes } from \"react\";\nimport type { VtexAdsStoryElement } from \"./story\";\n\nexport type VtexAdsStoryProps = DetailedHTMLProps<\n HTMLAttributes<VtexAdsStoryElement>,\n VtexAdsStoryElement\n> & {\n /** Name shown in the greeting; falls back to \"world\" when empty. */\n name?: string;\n};\n\ndeclare module \"react\" {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace JSX {\n interface IntrinsicElements {\n \"vtex-ads-story\": VtexAdsStoryProps;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -0,0 +1,26 @@
1
+ import { DetailedHTMLProps, HTMLAttributes } from 'react';
2
+ import { VtexAdsStoryElement } from './index.cjs';
3
+
4
+ /**
5
+ * React JSX types for <vtex-ads-story>. Types only: the JS output is empty.
6
+ *
7
+ * Opt in once per project, so non-React projects never need @types/react:
8
+ *
9
+ * import type {} from "@vtex/ads-stories/react";
10
+ *
11
+ * or add "@vtex/ads-stories/react" to `compilerOptions.types` in tsconfig.
12
+ */
13
+
14
+ type VtexAdsStoryProps = DetailedHTMLProps<HTMLAttributes<VtexAdsStoryElement>, VtexAdsStoryElement> & {
15
+ /** Name shown in the greeting; falls back to "world" when empty. */
16
+ name?: string;
17
+ };
18
+ declare module "react" {
19
+ namespace JSX {
20
+ interface IntrinsicElements {
21
+ "vtex-ads-story": VtexAdsStoryProps;
22
+ }
23
+ }
24
+ }
25
+
26
+ export type { VtexAdsStoryProps };
@@ -9,6 +9,11 @@ declare class VtexAdsStoryElement extends BaseElement {
9
9
  private upgradeProperty;
10
10
  attributeChangedCallback(): void;
11
11
  }
12
+ declare global {
13
+ interface HTMLElementTagNameMap {
14
+ "vtex-ads-story": VtexAdsStoryElement;
15
+ }
16
+ }
12
17
  declare function defineVtexAdsStories(): void;
13
18
 
14
19
  export { TAG_NAME, VtexAdsStoryElement, defineVtexAdsStories };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/story/story.ts"],"sourcesContent":["export const TAG_NAME = \"vtex-ads-story\";\n\n// Keeps the module importable where HTMLElement doesn't exist (SSR, Node).\nconst BaseElement: typeof HTMLElement = globalThis.HTMLElement ?? Object;\n\nconst styles = `\n :host {\n display: block;\n font-family: var(--vtex-ads-story-font-family, inherit);\n color: var(--vtex-ads-story-color-text, inherit);\n }\n`;\n\nconst DEFAULT_NAME = \"world\";\n\nexport class VtexAdsStoryElement extends BaseElement {\n static get observedAttributes() {\n return [\"name\"];\n }\n\n get name(): string {\n return this.getAttribute(\"name\")?.trim() ?? \"\";\n }\n\n set name(value: string) {\n this.setAttribute(\"name\", value);\n }\n\n private render() {\n const container = this.shadowRoot?.querySelector(\"[part='root']\");\n if (!container) return;\n\n // textContent keeps the name as plain text (no HTML injection).\n container.textContent = `Hello ${this.name || DEFAULT_NAME}!`;\n }\n\n connectedCallback() {\n if (!this.shadowRoot) {\n const root = this.attachShadow({ mode: \"open\" });\n root.innerHTML = `<style>${styles}</style><div part=\"root\"></div>`;\n }\n\n this.upgradeProperty(\"name\");\n this.render();\n }\n\n // A property set before the element is defined (e.g. while the CDN script\n // loads) becomes an own property that shadows the class getter/setter.\n // Remove it and set it again so it goes through the setter.\n private upgradeProperty(prop: \"name\") {\n if (!Object.prototype.hasOwnProperty.call(this, prop)) return;\n\n const value = this[prop];\n Reflect.deleteProperty(this, prop);\n this[prop] = value;\n }\n\n attributeChangedCallback() {\n this.render();\n }\n}\n\nexport function defineVtexAdsStories() {\n if (typeof customElements === \"undefined\") return;\n if (customElements.get(TAG_NAME)) return;\n\n customElements.define(TAG_NAME, VtexAdsStoryElement);\n}\n"],"mappings":";AAAO,IAAM,WAAW;AAAxB;AAGA,IAAM,eAAkC,gBAAW,gBAAX,YAA0B;AAElE,IAAM,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQf,IAAM,eAAe;AAEd,IAAM,sBAAN,cAAkC,YAAY;AAAA,EACnD,WAAW,qBAAqB;AAC9B,WAAO,CAAC,MAAM;AAAA,EAChB;AAAA,EAEA,IAAI,OAAe;AApBrB,QAAAA,KAAA;AAqBI,YAAO,MAAAA,MAAA,KAAK,aAAa,MAAM,MAAxB,gBAAAA,IAA2B,WAA3B,YAAqC;AAAA,EAC9C;AAAA,EAEA,IAAI,KAAK,OAAe;AACtB,SAAK,aAAa,QAAQ,KAAK;AAAA,EACjC;AAAA,EAEQ,SAAS;AA5BnB,QAAAA;AA6BI,UAAM,aAAYA,MAAA,KAAK,eAAL,gBAAAA,IAAiB,cAAc;AACjD,QAAI,CAAC,UAAW;AAGhB,cAAU,cAAc,SAAS,KAAK,QAAQ,YAAY;AAAA,EAC5D;AAAA,EAEA,oBAAoB;AAClB,QAAI,CAAC,KAAK,YAAY;AACpB,YAAM,OAAO,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;AAC/C,WAAK,YAAY,UAAU,MAAM;AAAA,IACnC;AAEA,SAAK,gBAAgB,MAAM;AAC3B,SAAK,OAAO;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAKQ,gBAAgB,MAAc;AACpC,QAAI,CAAC,OAAO,UAAU,eAAe,KAAK,MAAM,IAAI,EAAG;AAEvD,UAAM,QAAQ,KAAK,IAAI;AACvB,YAAQ,eAAe,MAAM,IAAI;AACjC,SAAK,IAAI,IAAI;AAAA,EACf;AAAA,EAEA,2BAA2B;AACzB,SAAK,OAAO;AAAA,EACd;AACF;AAEO,SAAS,uBAAuB;AACrC,MAAI,OAAO,mBAAmB,YAAa;AAC3C,MAAI,eAAe,IAAI,QAAQ,EAAG;AAElC,iBAAe,OAAO,UAAU,mBAAmB;AACrD;","names":["_a"]}
1
+ {"version":3,"sources":["../../src/story/story.ts"],"sourcesContent":["export const TAG_NAME = \"vtex-ads-story\";\n\n// Keeps the module importable where HTMLElement doesn't exist (SSR, Node).\nconst BaseElement: typeof HTMLElement = globalThis.HTMLElement ?? Object;\n\nconst styles = `\n :host {\n display: block;\n font-family: var(--vtex-ads-story-font-family, inherit);\n color: var(--vtex-ads-story-color-text, inherit);\n }\n`;\n\nconst DEFAULT_NAME = \"world\";\n\nexport class VtexAdsStoryElement extends BaseElement {\n static get observedAttributes() {\n return [\"name\"];\n }\n\n get name(): string {\n return this.getAttribute(\"name\")?.trim() ?? \"\";\n }\n\n set name(value: string) {\n this.setAttribute(\"name\", value);\n }\n\n private render() {\n const container = this.shadowRoot?.querySelector(\"[part='root']\");\n if (!container) return;\n\n // textContent keeps the name as plain text (no HTML injection).\n container.textContent = `Hello ${this.name || DEFAULT_NAME}!`;\n }\n\n connectedCallback() {\n if (!this.shadowRoot) {\n const root = this.attachShadow({ mode: \"open\" });\n root.innerHTML = `<style>${styles}</style><div part=\"root\"></div>`;\n }\n\n this.upgradeProperty(\"name\");\n this.render();\n }\n\n // A property set before the element is defined (e.g. while the CDN script\n // loads) becomes an own property that shadows the class getter/setter.\n // Remove it and set it again so it goes through the setter.\n private upgradeProperty(prop: \"name\") {\n if (!Object.prototype.hasOwnProperty.call(this, prop)) return;\n\n const value = this[prop];\n Reflect.deleteProperty(this, prop);\n this[prop] = value;\n }\n\n attributeChangedCallback() {\n this.render();\n }\n}\n\n// Types `document.createElement(\"vtex-ads-story\")` and `querySelector` results\n// as VtexAdsStoryElement in any TypeScript project, no framework needed.\ndeclare global {\n interface HTMLElementTagNameMap {\n \"vtex-ads-story\": VtexAdsStoryElement;\n }\n}\n\nexport function defineVtexAdsStories() {\n if (typeof customElements === \"undefined\") return;\n if (customElements.get(TAG_NAME)) return;\n\n customElements.define(TAG_NAME, VtexAdsStoryElement);\n}\n"],"mappings":";AAAO,IAAM,WAAW;AAAxB;AAGA,IAAM,eAAkC,gBAAW,gBAAX,YAA0B;AAElE,IAAM,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQf,IAAM,eAAe;AAEd,IAAM,sBAAN,cAAkC,YAAY;AAAA,EACnD,WAAW,qBAAqB;AAC9B,WAAO,CAAC,MAAM;AAAA,EAChB;AAAA,EAEA,IAAI,OAAe;AApBrB,QAAAA,KAAA;AAqBI,YAAO,MAAAA,MAAA,KAAK,aAAa,MAAM,MAAxB,gBAAAA,IAA2B,WAA3B,YAAqC;AAAA,EAC9C;AAAA,EAEA,IAAI,KAAK,OAAe;AACtB,SAAK,aAAa,QAAQ,KAAK;AAAA,EACjC;AAAA,EAEQ,SAAS;AA5BnB,QAAAA;AA6BI,UAAM,aAAYA,MAAA,KAAK,eAAL,gBAAAA,IAAiB,cAAc;AACjD,QAAI,CAAC,UAAW;AAGhB,cAAU,cAAc,SAAS,KAAK,QAAQ,YAAY;AAAA,EAC5D;AAAA,EAEA,oBAAoB;AAClB,QAAI,CAAC,KAAK,YAAY;AACpB,YAAM,OAAO,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;AAC/C,WAAK,YAAY,UAAU,MAAM;AAAA,IACnC;AAEA,SAAK,gBAAgB,MAAM;AAC3B,SAAK,OAAO;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAKQ,gBAAgB,MAAc;AACpC,QAAI,CAAC,OAAO,UAAU,eAAe,KAAK,MAAM,IAAI,EAAG;AAEvD,UAAM,QAAQ,KAAK,IAAI;AACvB,YAAQ,eAAe,MAAM,IAAI;AACjC,SAAK,IAAI,IAAI;AAAA,EACf;AAAA,EAEA,2BAA2B;AACzB,SAAK,OAAO;AAAA,EACd;AACF;AAUO,SAAS,uBAAuB;AACrC,MAAI,OAAO,mBAAmB,YAAa;AAC3C,MAAI,eAAe,IAAI,QAAQ,EAAG;AAElC,iBAAe,OAAO,UAAU,mBAAmB;AACrD;","names":["_a"]}
@@ -0,0 +1,26 @@
1
+ import { DetailedHTMLProps, HTMLAttributes } from 'react';
2
+ import { VtexAdsStoryElement } from './index.js';
3
+
4
+ /**
5
+ * React JSX types for <vtex-ads-story>. Types only: the JS output is empty.
6
+ *
7
+ * Opt in once per project, so non-React projects never need @types/react:
8
+ *
9
+ * import type {} from "@vtex/ads-stories/react";
10
+ *
11
+ * or add "@vtex/ads-stories/react" to `compilerOptions.types` in tsconfig.
12
+ */
13
+
14
+ type VtexAdsStoryProps = DetailedHTMLProps<HTMLAttributes<VtexAdsStoryElement>, VtexAdsStoryElement> & {
15
+ /** Name shown in the greeting; falls back to "world" when empty. */
16
+ name?: string;
17
+ };
18
+ declare module "react" {
19
+ namespace JSX {
20
+ interface IntrinsicElements {
21
+ "vtex-ads-story": VtexAdsStoryProps;
22
+ }
23
+ }
24
+ }
25
+
26
+ export type { VtexAdsStoryProps };
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=react.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/package.json CHANGED
@@ -1,11 +1,13 @@
1
1
  {
2
2
  "name": "@vtex/ads-stories",
3
3
  "type": "module",
4
- "version": "0.1.0",
4
+ "version": "0.2.0",
5
5
  "description": "VTEX Ads Stories web component",
6
6
  "main": "dist/cjs/index.cjs",
7
7
  "module": "dist/esm/index.js",
8
8
  "types": "dist/esm/index.d.ts",
9
+ "unpkg": "dist/cdn/vtex-ads-stories.js",
10
+ "jsdelivr": "dist/cdn/vtex-ads-stories.js",
9
11
  "exports": {
10
12
  ".": {
11
13
  "import": {
@@ -17,6 +19,16 @@
17
19
  "default": "./dist/cjs/index.cjs"
18
20
  }
19
21
  },
22
+ "./react": {
23
+ "import": {
24
+ "types": "./dist/esm/react.d.ts",
25
+ "default": "./dist/esm/react.js"
26
+ },
27
+ "require": {
28
+ "types": "./dist/cjs/react.d.cts",
29
+ "default": "./dist/cjs/react.cjs"
30
+ }
31
+ },
20
32
  "./cdn": "./dist/cdn/vtex-ads-stories.js"
21
33
  },
22
34
  "sideEffects": [
@@ -38,8 +50,17 @@
38
50
  "directory": "packages/ads-stories"
39
51
  },
40
52
  "homepage": "https://github.com/vtex/ads-js/tree/main/packages/ads-stories#readme",
53
+ "peerDependencies": {
54
+ "@types/react": ">=18.2.6"
55
+ },
56
+ "peerDependenciesMeta": {
57
+ "@types/react": {
58
+ "optional": true
59
+ }
60
+ },
41
61
  "devDependencies": {
42
62
  "@types/node": "^22.15.21",
63
+ "@types/react": "^19.1.2",
43
64
  "tsup": "^8.5.0",
44
65
  "vite": "^5.0.0"
45
66
  },
package/src/react.ts ADDED
@@ -0,0 +1,28 @@
1
+ /**
2
+ * React JSX types for <vtex-ads-story>. Types only: the JS output is empty.
3
+ *
4
+ * Opt in once per project, so non-React projects never need @types/react:
5
+ *
6
+ * import type {} from "@vtex/ads-stories/react";
7
+ *
8
+ * or add "@vtex/ads-stories/react" to `compilerOptions.types` in tsconfig.
9
+ */
10
+ import type { DetailedHTMLProps, HTMLAttributes } from "react";
11
+ import type { VtexAdsStoryElement } from "./story";
12
+
13
+ export type VtexAdsStoryProps = DetailedHTMLProps<
14
+ HTMLAttributes<VtexAdsStoryElement>,
15
+ VtexAdsStoryElement
16
+ > & {
17
+ /** Name shown in the greeting; falls back to "world" when empty. */
18
+ name?: string;
19
+ };
20
+
21
+ declare module "react" {
22
+ // eslint-disable-next-line @typescript-eslint/no-namespace
23
+ namespace JSX {
24
+ interface IntrinsicElements {
25
+ "vtex-ads-story": VtexAdsStoryProps;
26
+ }
27
+ }
28
+ }
@@ -60,6 +60,14 @@ export class VtexAdsStoryElement extends BaseElement {
60
60
  }
61
61
  }
62
62
 
63
+ // Types `document.createElement("vtex-ads-story")` and `querySelector` results
64
+ // as VtexAdsStoryElement in any TypeScript project, no framework needed.
65
+ declare global {
66
+ interface HTMLElementTagNameMap {
67
+ "vtex-ads-story": VtexAdsStoryElement;
68
+ }
69
+ }
70
+
63
71
  export function defineVtexAdsStories() {
64
72
  if (typeof customElements === "undefined") return;
65
73
  if (customElements.get(TAG_NAME)) return;