@weaverse/core 0.7.37 → 0.7.39

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/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var y=Object.create;var p=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty;var j=(e,t)=>{for(var i in t)p(e,i,{get:t[i],enumerable:!0})},m=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of w(t))!D.call(e,s)&&s!==i&&p(e,s,{get:()=>t[s],enumerable:!(n=b(t,s))||n.enumerable});return e};var S=(e,t,i)=>(i=e!=null?y(x(e)):{},m(t||!e||!e.__esModule?p(i,"default",{value:e,enumerable:!0}):i,e)),E=e=>m(p({},"__esModule",{value:!0}),e);var v={};j(v,{Weaverse:()=>c,WeaverseItemStore:()=>o,createGlobalStyles:()=>l,isBrowser:()=>u,isIframe:()=>h,isReactNative:()=>g,loadScript:()=>I,stichesUtils:()=>d});module.exports=E(v);var f=S(require("@stitches/core"));function I(e){return new Promise(function(t){let i=document.createElement("script");i.src=e,i.addEventListener("load",function(){t(!0)}),document.head.appendChild(i)})}var d={m:e=>({margin:e}),mt:e=>({marginTop:e}),mr:e=>({marginRight:e}),mb:e=>({marginBottom:e}),ml:e=>({marginLeft:e}),mx:e=>({marginLeft:e,marginRight:e}),my:e=>({marginTop:e,marginBottom:e}),size:e=>({width:e,height:e}),px:e=>({paddingLeft:e,paddingRight:e}),py:e=>({paddingTop:e,paddingBottom:e})};function l(e){e.globalCss({"@keyframes spin":{from:{transform:"rotate(0deg)"},to:{transform:"rotate(360deg)"}},"@keyframes pulse":{"0%, 100%":{opacity:1},"50%":{opacity:.5}},".wv-spinner-wrapper":{position:"absolute",inset:"0px",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"inherit",".wv-spinner":{width:"20px",height:"20px",animation:"spin .75s linear infinite"}},"[data-wv-placeholder]":{height:"100%",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(236, 236, 236, 0.5)",backgroundClip:"content-box",padding:"10px"},body:{"&.wv-modal-open":{".weaverse-content-root":{zIndex:9999}}},".weaverse-content-root":{position:"relative",zIndex:0,"*":{WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"auto",textRendering:"optimizeLegibility",boxSizing:"border-box"},input:{"&::-webkit-outer-spin-button, &::-webkit-inner-spin-button":{"-webkit-appearance":"none",margin:0},"&[type=number]":{"-moz-appearance":"textfield"}},select:{WebkitAppearance:"none",MozAppearance:"none",appearance:"none",outline:"none",boxShadow:"none",color:"currentColor",verticalAlign:"middle",backgroundColor:"transparent",backgroundPosition:"center",backgroundRepeat:"no-repeat",backgroundImage:"url(https://ucarecdn.com/4bb6a6e7-1ce8-4201-8f2d-da00a50105f3/)",backgroundSize:"10px",backgroundPositionX:"calc(100% - 12px)",paddingLeft:"12px",paddingRight:"35px !important",cursor:"pointer"},button:{outline:"none",boxShadow:"none",cursor:"pointer",border:"none","&:focus":{outline:"none",boxShadow:"none"}},".animate-pulse":{animation:"pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite"}}})()}var g=typeof navigator=="object"&&navigator.product==="ReactNative",u=typeof window<"u"&&!g,h=u&&window.top!==window.self;var o=class{constructor(t,i){this.listeners=new Set;this.ref={current:null};this.stitchesClass="";this._data={id:"",type:""};this._flags={};this.setData=t=>(this.data=Object.assign(this.data,t),this.triggerUpdate(),this.data);this.subscribe=t=>{this.listeners.add(t)};this.unsubscribe=t=>{this.listeners.delete(t)};this.triggerUpdate=()=>{this.listeners.forEach(t=>t(this.data))};let{type:n,id:s}=t;this.weaverse=i,s&&n&&(i.itemInstances.set(s,this),this.data={...t})}get _id(){return this._data.id}get _element(){return this.ref.current}get Element(){return this.weaverse.elementInstances.get(this._data.type)}set data(t){this._data={...this.data,...t}}get data(){let t=this.Element?.defaultCss;return{...{...this.Element?.Component?.defaultProps,...t&&{css:t}},...this._data}}},c=class{constructor({appUrl:t,projectKey:i,projectData:n,mediaBreakPoints:s,isDesignMode:r,ssrMode:a}={}){this.elementInstances=new Map;this.itemInstances=new Map;this.appUrl=process.env.NODE_ENV==="development"?"http://localhost:3000":"https://studio.weaverse.io";this.projectKey="";this.projectData={rootId:"",items:[],script:{css:"",js:""}};this.listeners=new Set;this.isDesignMode=!1;this.ssrMode=!1;this.mediaBreakPoints={desktop:"all",mobile:"(max-width: 767.98px)"};this.initialized=!1;this.initializeData=t=>{if(!this.initialized){let{data:i,published:n,id:s,projectKey:r,studioUrl:a}=t;this.projectKey=r||this.projectKey,this.appUrl=a||this.appUrl,this.projectData={...i,pageId:s},this.isDesignMode=!n,this.initProjectItemData(),this.isDesignMode&&(this.triggerUpdate(),this.loadStudio())}this.initialized=!0};this.initStitches=()=>{this.stitchesInstance=this.stitchesInstance||f.createStitches({prefix:"weaverse",media:this.mediaBreakPoints,utils:d}),l(this.stitchesInstance)};this.init({appUrl:t,projectKey:i,projectData:n,mediaBreakPoints:s,isDesignMode:r,ssrMode:a})}init({appUrl:t,projectKey:i,projectData:n,mediaBreakPoints:s,isDesignMode:r,ssrMode:a}={}){this.appUrl=t||this.appUrl,this.projectKey=i||this.projectKey,this.mediaBreakPoints=s||this.mediaBreakPoints,this.isDesignMode=r||this.isDesignMode,this.ssrMode=a||this.ssrMode,this.projectData=n||this.projectData,this.initStitches(),this.initProjectItemData()}loadStudio(){setTimeout(()=>{if(h&&this.isDesignMode&&!this.studioBridge){let t=()=>{this.studioBridge=new window.WeaverseStudioBridge(this),this.triggerUpdate()};if(window.WeaverseStudioBridge)t();else{let i=document.createElement("script");i.src=`${this.appUrl}/assets/studio/studio-bridge.js`,i.type="module",i.onload=t,document.body.appendChild(i)}}},2e3)}registerElement(t){if(t?.type){if(this.elementInstances.has(t.type))throw new Error(`Weaverse: Element '${t.type}' already registered`);this.elementInstances.set(t?.type,t)}else throw new Error("Weaverse: registerElement: `type` is required")}subscribe(t){this.listeners.add(t)}unsubscribe(t){this.listeners.delete(t)}triggerUpdate(){this.listeners.forEach(t=>t())}static fetchProjectData({fetch:t=globalThis.fetch,appUrl:i,projectKey:n}){return t(i+`/api/public/project/${n}`).then(s=>s.json()).catch(console.error)}setProjectData(t){this.projectData=t,this.initProjectItemData(),this.triggerUpdate()}initProjectItemData(){let t=this.projectData;t?.items&&t.items.forEach(i=>{this.itemInstances.get(i.id)||new o(i,this)})}};c.WeaverseItemStore=o;0&&(module.exports={Weaverse,WeaverseItemStore,createGlobalStyles,isBrowser,isIframe,isReactNative,loadScript,stichesUtils});
1
+ "use strict";var y=Object.create;var p=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty;var j=(e,t)=>{for(var i in t)p(e,i,{get:t[i],enumerable:!0})},m=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of w(t))!D.call(e,s)&&s!==i&&p(e,s,{get:()=>t[s],enumerable:!(n=b(t,s))||n.enumerable});return e};var S=(e,t,i)=>(i=e!=null?y(x(e)):{},m(t||!e||!e.__esModule?p(i,"default",{value:e,enumerable:!0}):i,e)),E=e=>m(p({},"__esModule",{value:!0}),e);var v={};j(v,{Weaverse:()=>c,WeaverseItemStore:()=>o,createGlobalStyles:()=>l,isBrowser:()=>u,isIframe:()=>h,isReactNative:()=>g,loadScript:()=>I,stichesUtils:()=>d});module.exports=E(v);var f=S(require("@stitches/core"));function I(e){return new Promise(function(t){let i=document.createElement("script");i.src=e,i.addEventListener("load",function(){t(!0)}),document.head.appendChild(i)})}var d={m:e=>({margin:e}),mt:e=>({marginTop:e}),mr:e=>({marginRight:e}),mb:e=>({marginBottom:e}),ml:e=>({marginLeft:e}),mx:e=>({marginLeft:e,marginRight:e}),my:e=>({marginTop:e,marginBottom:e}),size:e=>({width:e,height:e}),px:e=>({paddingLeft:e,paddingRight:e}),py:e=>({paddingTop:e,paddingBottom:e})};function l(e){e.globalCss({"@keyframes spin":{from:{transform:"rotate(0deg)"},to:{transform:"rotate(360deg)"}},"@keyframes pulse":{"0%, 100%":{opacity:1},"50%":{opacity:.5}},".wv-spinner-wrapper":{position:"absolute",inset:"0px",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"inherit",".wv-spinner":{width:"20px",height:"20px",animation:"spin .75s linear infinite"}},"[data-wv-placeholder]":{height:"100%",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(236, 236, 236, 0.5)",backgroundClip:"content-box",padding:"10px"},body:{"&.wv-modal-open":{".weaverse-content-root":{zIndex:9999}}},".weaverse-content-root":{position:"relative",zIndex:0,"*":{WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"auto",textRendering:"optimizeLegibility",boxSizing:"border-box"},input:{"&::-webkit-outer-spin-button, &::-webkit-inner-spin-button":{"-webkit-appearance":"none",margin:0},"&[type=number]":{"-moz-appearance":"textfield"}},select:{WebkitAppearance:"none",MozAppearance:"none",appearance:"none",outline:"none",boxShadow:"none",color:"currentColor",verticalAlign:"middle",backgroundColor:"transparent",backgroundPosition:"center",backgroundRepeat:"no-repeat",backgroundImage:"url(https://ucarecdn.com/4bb6a6e7-1ce8-4201-8f2d-da00a50105f3/)",backgroundSize:"10px",backgroundPositionX:"calc(100% - 12px)",paddingLeft:"12px",paddingRight:"35px !important",cursor:"pointer"},button:{outline:"none",boxShadow:"none",cursor:"pointer",border:"none","&:focus":{outline:"none",boxShadow:"none"}},".animate-pulse":{animation:"pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite"}}})()}var g=typeof navigator=="object"&&navigator.product==="ReactNative",u=typeof window<"u"&&!g,h=u&&window.top!==window.self;var o=class{constructor(t,i){this.listeners=new Set;this.ref={current:null};this.stitchesClass="";this._data={id:"",type:""};this._flags={};this.setData=t=>(this.data=Object.assign(this.data,t),this.triggerUpdate(),this.data);this.subscribe=t=>{this.listeners.add(t)};this.unsubscribe=t=>{this.listeners.delete(t)};this.triggerUpdate=()=>{this.listeners.forEach(t=>t(this.data))};let{type:n,id:s}=t;this.weaverse=i,s&&n&&(i.itemInstances.set(s,this),this.data={...t})}get _id(){return this._data.id}get _element(){return this.ref.current}get Element(){return this.weaverse.elementInstances.get(this._data.type)}set data(t){this._data={...this.data,...t}}get data(){let t=this.Element?.defaultCss;return{...{...this.Element?.Component?.defaultProps,...t&&{css:t}},...this._data}}},c=class{constructor({appUrl:t,projectKey:i,projectData:n,mediaBreakPoints:s,isDesignMode:a,ssrMode:r}={}){this.elementInstances=new Map;this.itemInstances=new Map;this.appUrl=process.env.NODE_ENV==="development"?"http://localhost:3000":"https://studio.weaverse.io";this.projectKey="";this.projectData={rootId:"",items:[],script:{css:"",js:""}};this.listeners=new Set;this.isDesignMode=!1;this.ssrMode=!1;this.mediaBreakPoints={desktop:"all",mobile:"(max-width: 767.98px)"};this.initialized=!1;this.initializeData=t=>{if(!this.initialized){let{data:i,published:n,id:s,projectKey:a,studioUrl:r}=t;this.projectKey=a||this.projectKey,this.appUrl=r||this.appUrl,this.projectData={...i,pageId:s},this.isDesignMode=!n,this.initProjectItemData(),this.isDesignMode&&(this.triggerUpdate(),this.loadStudio())}this.initialized=!0};this.initStitches=()=>{this.stitchesInstance=this.stitchesInstance||f.createStitches({prefix:"weaverse",media:this.mediaBreakPoints,utils:d}),l(this.stitchesInstance)};this.init({appUrl:t,projectKey:i,projectData:n,mediaBreakPoints:s,isDesignMode:a,ssrMode:r})}init({appUrl:t,projectKey:i,projectData:n,mediaBreakPoints:s,isDesignMode:a,ssrMode:r}={}){this.appUrl=t||this.appUrl,this.projectKey=i||this.projectKey,this.mediaBreakPoints=s||this.mediaBreakPoints,this.isDesignMode=a||this.isDesignMode,this.ssrMode=r||this.ssrMode,this.projectData=n||this.projectData,this.initStitches(),this.initProjectItemData()}loadStudio(){setTimeout(()=>{if(h&&this.isDesignMode&&!this.studioBridge){let t=()=>{this.studioBridge=new window.WeaverseStudioBridge(this),this.triggerUpdate()};if(window.WeaverseStudioBridge)t();else{let i=document.createElement("script"),n=new Date().getTime();i.src=`${this.appUrl}/assets/studio/studio-bridge.js?t=${n}`,i.type="module",i.onload=t,document.body.appendChild(i)}}},2e3)}registerElement(t){if(t?.type){if(this.elementInstances.has(t.type))throw new Error(`Weaverse: Element '${t.type}' already registered`);this.elementInstances.set(t?.type,t)}else throw new Error("Weaverse: registerElement: `type` is required")}subscribe(t){this.listeners.add(t)}unsubscribe(t){this.listeners.delete(t)}triggerUpdate(){this.listeners.forEach(t=>t())}static fetchProjectData({fetch:t=globalThis.fetch,appUrl:i,projectKey:n}){return t(i+`/api/public/project/${n}`).then(s=>s.json()).catch(console.error)}setProjectData(t){this.projectData=t,this.initProjectItemData(),this.triggerUpdate()}initProjectItemData(){let t=this.projectData;t?.items&&t.items.forEach(i=>{this.itemInstances.get(i.id)||new o(i,this)})}};c.WeaverseItemStore=o;0&&(module.exports={Weaverse,WeaverseItemStore,createGlobalStyles,isBrowser,isIframe,isReactNative,loadScript,stichesUtils});
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import*as h from"@stitches/core";function u(e){return new Promise(function(t){let i=document.createElement("script");i.src=e,i.addEventListener("load",function(){t(!0)}),document.head.appendChild(i)})}var c={m:e=>({margin:e}),mt:e=>({marginTop:e}),mr:e=>({marginRight:e}),mb:e=>({marginBottom:e}),ml:e=>({marginLeft:e}),mx:e=>({marginLeft:e,marginRight:e}),my:e=>({marginTop:e,marginBottom:e}),size:e=>({width:e,height:e}),px:e=>({paddingLeft:e,paddingRight:e}),py:e=>({paddingTop:e,paddingBottom:e})};function d(e){e.globalCss({"@keyframes spin":{from:{transform:"rotate(0deg)"},to:{transform:"rotate(360deg)"}},"@keyframes pulse":{"0%, 100%":{opacity:1},"50%":{opacity:.5}},".wv-spinner-wrapper":{position:"absolute",inset:"0px",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"inherit",".wv-spinner":{width:"20px",height:"20px",animation:"spin .75s linear infinite"}},"[data-wv-placeholder]":{height:"100%",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(236, 236, 236, 0.5)",backgroundClip:"content-box",padding:"10px"},body:{"&.wv-modal-open":{".weaverse-content-root":{zIndex:9999}}},".weaverse-content-root":{position:"relative",zIndex:0,"*":{WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"auto",textRendering:"optimizeLegibility",boxSizing:"border-box"},input:{"&::-webkit-outer-spin-button, &::-webkit-inner-spin-button":{"-webkit-appearance":"none",margin:0},"&[type=number]":{"-moz-appearance":"textfield"}},select:{WebkitAppearance:"none",MozAppearance:"none",appearance:"none",outline:"none",boxShadow:"none",color:"currentColor",verticalAlign:"middle",backgroundColor:"transparent",backgroundPosition:"center",backgroundRepeat:"no-repeat",backgroundImage:"url(https://ucarecdn.com/4bb6a6e7-1ce8-4201-8f2d-da00a50105f3/)",backgroundSize:"10px",backgroundPositionX:"calc(100% - 12px)",paddingLeft:"12px",paddingRight:"35px !important",cursor:"pointer"},button:{outline:"none",boxShadow:"none",cursor:"pointer",border:"none","&:focus":{outline:"none",boxShadow:"none"}},".animate-pulse":{animation:"pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite"}}})()}var m=typeof navigator=="object"&&navigator.product==="ReactNative",g=typeof window<"u"&&!m,l=g&&window.top!==window.self;var o=class{constructor(t,i){this.listeners=new Set;this.ref={current:null};this.stitchesClass="";this._data={id:"",type:""};this._flags={};this.setData=t=>(this.data=Object.assign(this.data,t),this.triggerUpdate(),this.data);this.subscribe=t=>{this.listeners.add(t)};this.unsubscribe=t=>{this.listeners.delete(t)};this.triggerUpdate=()=>{this.listeners.forEach(t=>t(this.data))};let{type:n,id:s}=t;this.weaverse=i,s&&n&&(i.itemInstances.set(s,this),this.data={...t})}get _id(){return this._data.id}get _element(){return this.ref.current}get Element(){return this.weaverse.elementInstances.get(this._data.type)}set data(t){this._data={...this.data,...t}}get data(){let t=this.Element?.defaultCss;return{...{...this.Element?.Component?.defaultProps,...t&&{css:t}},...this._data}}},p=class{constructor({appUrl:t,projectKey:i,projectData:n,mediaBreakPoints:s,isDesignMode:r,ssrMode:a}={}){this.elementInstances=new Map;this.itemInstances=new Map;this.appUrl=process.env.NODE_ENV==="development"?"http://localhost:3000":"https://studio.weaverse.io";this.projectKey="";this.projectData={rootId:"",items:[],script:{css:"",js:""}};this.listeners=new Set;this.isDesignMode=!1;this.ssrMode=!1;this.mediaBreakPoints={desktop:"all",mobile:"(max-width: 767.98px)"};this.initialized=!1;this.initializeData=t=>{if(!this.initialized){let{data:i,published:n,id:s,projectKey:r,studioUrl:a}=t;this.projectKey=r||this.projectKey,this.appUrl=a||this.appUrl,this.projectData={...i,pageId:s},this.isDesignMode=!n,this.initProjectItemData(),this.isDesignMode&&(this.triggerUpdate(),this.loadStudio())}this.initialized=!0};this.initStitches=()=>{this.stitchesInstance=this.stitchesInstance||h.createStitches({prefix:"weaverse",media:this.mediaBreakPoints,utils:c}),d(this.stitchesInstance)};this.init({appUrl:t,projectKey:i,projectData:n,mediaBreakPoints:s,isDesignMode:r,ssrMode:a})}init({appUrl:t,projectKey:i,projectData:n,mediaBreakPoints:s,isDesignMode:r,ssrMode:a}={}){this.appUrl=t||this.appUrl,this.projectKey=i||this.projectKey,this.mediaBreakPoints=s||this.mediaBreakPoints,this.isDesignMode=r||this.isDesignMode,this.ssrMode=a||this.ssrMode,this.projectData=n||this.projectData,this.initStitches(),this.initProjectItemData()}loadStudio(){setTimeout(()=>{if(l&&this.isDesignMode&&!this.studioBridge){let t=()=>{this.studioBridge=new window.WeaverseStudioBridge(this),this.triggerUpdate()};if(window.WeaverseStudioBridge)t();else{let i=document.createElement("script");i.src=`${this.appUrl}/assets/studio/studio-bridge.js`,i.type="module",i.onload=t,document.body.appendChild(i)}}},2e3)}registerElement(t){if(t?.type){if(this.elementInstances.has(t.type))throw new Error(`Weaverse: Element '${t.type}' already registered`);this.elementInstances.set(t?.type,t)}else throw new Error("Weaverse: registerElement: `type` is required")}subscribe(t){this.listeners.add(t)}unsubscribe(t){this.listeners.delete(t)}triggerUpdate(){this.listeners.forEach(t=>t())}static fetchProjectData({fetch:t=globalThis.fetch,appUrl:i,projectKey:n}){return t(i+`/api/public/project/${n}`).then(s=>s.json()).catch(console.error)}setProjectData(t){this.projectData=t,this.initProjectItemData(),this.triggerUpdate()}initProjectItemData(){let t=this.projectData;t?.items&&t.items.forEach(i=>{this.itemInstances.get(i.id)||new o(i,this)})}};p.WeaverseItemStore=o;export{p as Weaverse,o as WeaverseItemStore,d as createGlobalStyles,g as isBrowser,l as isIframe,m as isReactNative,u as loadScript,c as stichesUtils};
1
+ import*as h from"@stitches/core";function u(e){return new Promise(function(t){let i=document.createElement("script");i.src=e,i.addEventListener("load",function(){t(!0)}),document.head.appendChild(i)})}var c={m:e=>({margin:e}),mt:e=>({marginTop:e}),mr:e=>({marginRight:e}),mb:e=>({marginBottom:e}),ml:e=>({marginLeft:e}),mx:e=>({marginLeft:e,marginRight:e}),my:e=>({marginTop:e,marginBottom:e}),size:e=>({width:e,height:e}),px:e=>({paddingLeft:e,paddingRight:e}),py:e=>({paddingTop:e,paddingBottom:e})};function d(e){e.globalCss({"@keyframes spin":{from:{transform:"rotate(0deg)"},to:{transform:"rotate(360deg)"}},"@keyframes pulse":{"0%, 100%":{opacity:1},"50%":{opacity:.5}},".wv-spinner-wrapper":{position:"absolute",inset:"0px",display:"flex",alignItems:"center",justifyContent:"center",backgroundColor:"inherit",".wv-spinner":{width:"20px",height:"20px",animation:"spin .75s linear infinite"}},"[data-wv-placeholder]":{height:"100%",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",backgroundColor:"rgba(236, 236, 236, 0.5)",backgroundClip:"content-box",padding:"10px"},body:{"&.wv-modal-open":{".weaverse-content-root":{zIndex:9999}}},".weaverse-content-root":{position:"relative",zIndex:0,"*":{WebkitFontSmoothing:"antialiased",MozOsxFontSmoothing:"auto",textRendering:"optimizeLegibility",boxSizing:"border-box"},input:{"&::-webkit-outer-spin-button, &::-webkit-inner-spin-button":{"-webkit-appearance":"none",margin:0},"&[type=number]":{"-moz-appearance":"textfield"}},select:{WebkitAppearance:"none",MozAppearance:"none",appearance:"none",outline:"none",boxShadow:"none",color:"currentColor",verticalAlign:"middle",backgroundColor:"transparent",backgroundPosition:"center",backgroundRepeat:"no-repeat",backgroundImage:"url(https://ucarecdn.com/4bb6a6e7-1ce8-4201-8f2d-da00a50105f3/)",backgroundSize:"10px",backgroundPositionX:"calc(100% - 12px)",paddingLeft:"12px",paddingRight:"35px !important",cursor:"pointer"},button:{outline:"none",boxShadow:"none",cursor:"pointer",border:"none","&:focus":{outline:"none",boxShadow:"none"}},".animate-pulse":{animation:"pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite"}}})()}var m=typeof navigator=="object"&&navigator.product==="ReactNative",g=typeof window<"u"&&!m,l=g&&window.top!==window.self;var o=class{constructor(t,i){this.listeners=new Set;this.ref={current:null};this.stitchesClass="";this._data={id:"",type:""};this._flags={};this.setData=t=>(this.data=Object.assign(this.data,t),this.triggerUpdate(),this.data);this.subscribe=t=>{this.listeners.add(t)};this.unsubscribe=t=>{this.listeners.delete(t)};this.triggerUpdate=()=>{this.listeners.forEach(t=>t(this.data))};let{type:s,id:n}=t;this.weaverse=i,n&&s&&(i.itemInstances.set(n,this),this.data={...t})}get _id(){return this._data.id}get _element(){return this.ref.current}get Element(){return this.weaverse.elementInstances.get(this._data.type)}set data(t){this._data={...this.data,...t}}get data(){let t=this.Element?.defaultCss;return{...{...this.Element?.Component?.defaultProps,...t&&{css:t}},...this._data}}},p=class{constructor({appUrl:t,projectKey:i,projectData:s,mediaBreakPoints:n,isDesignMode:a,ssrMode:r}={}){this.elementInstances=new Map;this.itemInstances=new Map;this.appUrl=process.env.NODE_ENV==="development"?"http://localhost:3000":"https://studio.weaverse.io";this.projectKey="";this.projectData={rootId:"",items:[],script:{css:"",js:""}};this.listeners=new Set;this.isDesignMode=!1;this.ssrMode=!1;this.mediaBreakPoints={desktop:"all",mobile:"(max-width: 767.98px)"};this.initialized=!1;this.initializeData=t=>{if(!this.initialized){let{data:i,published:s,id:n,projectKey:a,studioUrl:r}=t;this.projectKey=a||this.projectKey,this.appUrl=r||this.appUrl,this.projectData={...i,pageId:n},this.isDesignMode=!s,this.initProjectItemData(),this.isDesignMode&&(this.triggerUpdate(),this.loadStudio())}this.initialized=!0};this.initStitches=()=>{this.stitchesInstance=this.stitchesInstance||h.createStitches({prefix:"weaverse",media:this.mediaBreakPoints,utils:c}),d(this.stitchesInstance)};this.init({appUrl:t,projectKey:i,projectData:s,mediaBreakPoints:n,isDesignMode:a,ssrMode:r})}init({appUrl:t,projectKey:i,projectData:s,mediaBreakPoints:n,isDesignMode:a,ssrMode:r}={}){this.appUrl=t||this.appUrl,this.projectKey=i||this.projectKey,this.mediaBreakPoints=n||this.mediaBreakPoints,this.isDesignMode=a||this.isDesignMode,this.ssrMode=r||this.ssrMode,this.projectData=s||this.projectData,this.initStitches(),this.initProjectItemData()}loadStudio(){setTimeout(()=>{if(l&&this.isDesignMode&&!this.studioBridge){let t=()=>{this.studioBridge=new window.WeaverseStudioBridge(this),this.triggerUpdate()};if(window.WeaverseStudioBridge)t();else{let i=document.createElement("script"),s=new Date().getTime();i.src=`${this.appUrl}/assets/studio/studio-bridge.js?t=${s}`,i.type="module",i.onload=t,document.body.appendChild(i)}}},2e3)}registerElement(t){if(t?.type){if(this.elementInstances.has(t.type))throw new Error(`Weaverse: Element '${t.type}' already registered`);this.elementInstances.set(t?.type,t)}else throw new Error("Weaverse: registerElement: `type` is required")}subscribe(t){this.listeners.add(t)}unsubscribe(t){this.listeners.delete(t)}triggerUpdate(){this.listeners.forEach(t=>t())}static fetchProjectData({fetch:t=globalThis.fetch,appUrl:i,projectKey:s}){return t(i+`/api/public/project/${s}`).then(n=>n.json()).catch(console.error)}setProjectData(t){this.projectData=t,this.initProjectItemData(),this.triggerUpdate()}initProjectItemData(){let t=this.projectData;t?.items&&t.items.forEach(i=>{this.itemInstances.get(i.id)||new o(i,this)})}};p.WeaverseItemStore=o;export{p as Weaverse,o as WeaverseItemStore,d as createGlobalStyles,g as isBrowser,l as isIframe,m as isReactNative,u as loadScript,c as stichesUtils};
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.7.37",
2
+ "version": "0.7.39",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",