@tapuz/tpz 0.2.4 → 0.2.5
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.cjs.js +1 -1
- package/dist/index.esm.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -70,4 +70,4 @@ var l=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var y=Object.g
|
|
|
70
70
|
`)}return r}var S=new Set(["sans-serif","serif","monospace","system-ui","ui-sans-serif","ui-serif","ui-monospace","inherit","initial","arial","helvetica","times new roman","georgia","courier new","verdana","tahoma"]),$="100,100italic,200,200italic,300,300italic,400,400italic,500,500italic,600,600italic,700,700italic,800,800italic,900,900italic";function m(t,r){let o=String(r||"").split(",")[0].replace(/['"]/g,"").trim(),e=document.getElementById(t);if(!o||S.has(o.toLowerCase())){e&&e.remove();return}let a=`https://fonts.googleapis.com/css?family=${encodeURIComponent(o).replace(/%20/g,"+")}:${$}&display=swap`,n=e;n||(n=document.createElement("link"),n.id=t,n.rel="stylesheet",document.head.appendChild(n)),n.href!==a&&(n.href=a)}function T(t){m("__tpz_font_heading",t["heading-family"]),m("__tpz_font_body",t["body-font-family"])}function h(t){let r=Object.entries(t).map(([o,e])=>` --tpz-${o}: ${e};`).join(`
|
|
71
71
|
`);z("__tpz_tokens",`:root {
|
|
72
72
|
${r}
|
|
73
|
-
}`),T(t)}function I(t,r){if(document.getElementById("__tpz_auth_script")||document.getElementById("__tpz_editor_script")||document.getElementById("__tpz_code_box"))return;let o=t||d;window.__tpz_config={...window.__tpz_config,apiKey:r,apiUrl:o};let e=document.createElement("script");e.id="__tpz_auth_script",e.src=`${o}/live-edit-auth.js`,e.async=!0,document.head.appendChild(e)}function B(t,r){if(document.getElementById("lab-editor-script")||document.getElementById("lab-editor-panel"))return;let o=t||d;window.__tpz_config={...window.__tpz_config,apiKey:r,apiUrl:o};let e=document.createElement("script");e.id="lab-editor-script",e.src=`${o}/lab-editor.js`,e.async=!0,document.head.appendChild(e)}async function j(t,r){let o=new URLSearchParams(window.location.search).has("tapuz-lab"),e=Array.from(document.querySelectorAll("[data-tapuz-zone]"));if(e.length)try{let a=await fetch(`${t}/api/zones?key=${encodeURIComponent(r)}`).then(c=>c.json()),n={};for(let c of a.zones??[])n[c.name]=c;await Promise.all(e.map(async c=>{let s=c.getAttribute("data-tapuz-zone"),i=n[s];if(!i?.id)return;let u=(await fetch(`${t}/api/zones/${encodeURIComponent(i.id)}?key=${encodeURIComponent(r)}`).then(g=>g.json())).html??""
|
|
73
|
+
}`),T(t)}function I(t,r){if(document.getElementById("__tpz_auth_script")||document.getElementById("__tpz_editor_script")||document.getElementById("__tpz_code_box"))return;let o=t||d;window.__tpz_config={...window.__tpz_config,apiKey:r,apiUrl:o};let e=document.createElement("script");e.id="__tpz_auth_script",e.src=`${o}/live-edit-auth.js`,e.async=!0,document.head.appendChild(e)}function B(t,r){if(document.getElementById("lab-editor-script")||document.getElementById("lab-editor-panel"))return;let o=t||d;window.__tpz_config={...window.__tpz_config,apiKey:r,apiUrl:o};let e=document.createElement("script");e.id="lab-editor-script",e.src=`${o}/lab-editor.js`,e.async=!0,document.head.appendChild(e)}async function j(t,r){let o=new URLSearchParams(window.location.search).has("tapuz-lab"),e=Array.from(document.querySelectorAll("[data-tapuz-zone]"));if(e.length)try{let a=await fetch(`${t}/api/zones?key=${encodeURIComponent(r)}`).then(c=>c.json()),n={};for(let c of a.zones??[])n[c.name]=c;await Promise.all(e.map(async c=>{let s=c.getAttribute("data-tapuz-zone"),i=n[s];if(!i?.id)return;let u=(await fetch(`${t}/api/zones/${encodeURIComponent(i.id)}?key=${encodeURIComponent(r)}`).then(g=>g.json())).html??"";!u||o||(c.innerHTML=u)}))}catch{}}function b({apiKey:t,children:r,apiUrl:o}){return(0,p.useEffect)(()=>{if(z("__tpz_base",x),typeof window<"u"){let e=new URLSearchParams(window.location.search);e.has("tapuz-edit")&&I(o,t),e.has("tapuz-lab")&&B(o,t)}},[]),(0,p.useEffect)(()=>{t&&j(o||d,t)},[t,o]),(0,p.useEffect)(()=>{if(!t)return;let e={};function a(){return fetch(`${o||d}/api/tokens?key=${encodeURIComponent(t)}`).then(s=>s.json()).then(({tokens:s,defaults:i,classDefs:f})=>{e={...i&&typeof i=="object"?i:{},...s&&typeof s=="object"?s:{}},h(e),z("__tpz_classes",C(f))}).catch(()=>{})}a();let n;function c(){n=new EventSource(`${o||d}/api/token-stream?key=${encodeURIComponent(t)}`),n.onmessage=s=>{try{let i=JSON.parse(s.data);if(i&&(i.type==="definitions_changed"||i.type==="feature_released")){a();return}if(!i||!i.tokens||typeof i.tokens!="object")return;e={...e,...i.tokens},h(e)}catch{}},n.onerror=()=>{n.close(),setTimeout(c,3e3)}}return c(),()=>{n&&n.close()}},[t,o]),(0,p.createElement)(p.Fragment,null,r)}var A=b;
|
package/dist/index.esm.js
CHANGED
|
@@ -70,4 +70,4 @@ import{useEffect as d,Fragment as b,createElement as g}from"react";var p="https:
|
|
|
70
70
|
`)}return r}var w=new Set(["sans-serif","serif","monospace","system-ui","ui-sans-serif","ui-serif","ui-monospace","inherit","initial","arial","helvetica","times new roman","georgia","courier new","verdana","tahoma"]),_="100,100italic,200,200italic,300,300italic,400,400italic,500,500italic,600,600italic,700,700italic,800,800italic,900,900italic";function u(t,r){let o=String(r||"").split(",")[0].replace(/['"]/g,"").trim(),e=document.getElementById(t);if(!o||w.has(o.toLowerCase())){e&&e.remove();return}let s=`https://fonts.googleapis.com/css?family=${encodeURIComponent(o).replace(/%20/g,"+")}:${_}&display=swap`,n=e;n||(n=document.createElement("link"),n.id=t,n.rel="stylesheet",document.head.appendChild(n)),n.href!==s&&(n.href=s)}function E(t){u("__tpz_font_heading",t["heading-family"]),u("__tpz_font_body",t["body-font-family"])}function m(t){let r=Object.entries(t).map(([o,e])=>` --tpz-${o}: ${e};`).join(`
|
|
71
71
|
`);l("__tpz_tokens",`:root {
|
|
72
72
|
${r}
|
|
73
|
-
}`),E(t)}function k(t,r){if(document.getElementById("__tpz_auth_script")||document.getElementById("__tpz_editor_script")||document.getElementById("__tpz_code_box"))return;let o=t||p;window.__tpz_config={...window.__tpz_config,apiKey:r,apiUrl:o};let e=document.createElement("script");e.id="__tpz_auth_script",e.src=`${o}/live-edit-auth.js`,e.async=!0,document.head.appendChild(e)}function x(t,r){if(document.getElementById("lab-editor-script")||document.getElementById("lab-editor-panel"))return;let o=t||p;window.__tpz_config={...window.__tpz_config,apiKey:r,apiUrl:o};let e=document.createElement("script");e.id="lab-editor-script",e.src=`${o}/lab-editor.js`,e.async=!0,document.head.appendChild(e)}async function C(t,r){let o=new URLSearchParams(window.location.search).has("tapuz-lab"),e=Array.from(document.querySelectorAll("[data-tapuz-zone]"));if(e.length)try{let s=await fetch(`${t}/api/zones?key=${encodeURIComponent(r)}`).then(a=>a.json()),n={};for(let a of s.zones??[])n[a.name]=a;await Promise.all(e.map(async a=>{let c=a.getAttribute("data-tapuz-zone"),i=n[c];if(!i?.id)return;let f=(await fetch(`${t}/api/zones/${encodeURIComponent(i.id)}?key=${encodeURIComponent(r)}`).then(h=>h.json())).html??""
|
|
73
|
+
}`),E(t)}function k(t,r){if(document.getElementById("__tpz_auth_script")||document.getElementById("__tpz_editor_script")||document.getElementById("__tpz_code_box"))return;let o=t||p;window.__tpz_config={...window.__tpz_config,apiKey:r,apiUrl:o};let e=document.createElement("script");e.id="__tpz_auth_script",e.src=`${o}/live-edit-auth.js`,e.async=!0,document.head.appendChild(e)}function x(t,r){if(document.getElementById("lab-editor-script")||document.getElementById("lab-editor-panel"))return;let o=t||p;window.__tpz_config={...window.__tpz_config,apiKey:r,apiUrl:o};let e=document.createElement("script");e.id="lab-editor-script",e.src=`${o}/lab-editor.js`,e.async=!0,document.head.appendChild(e)}async function C(t,r){let o=new URLSearchParams(window.location.search).has("tapuz-lab"),e=Array.from(document.querySelectorAll("[data-tapuz-zone]"));if(e.length)try{let s=await fetch(`${t}/api/zones?key=${encodeURIComponent(r)}`).then(a=>a.json()),n={};for(let a of s.zones??[])n[a.name]=a;await Promise.all(e.map(async a=>{let c=a.getAttribute("data-tapuz-zone"),i=n[c];if(!i?.id)return;let f=(await fetch(`${t}/api/zones/${encodeURIComponent(i.id)}?key=${encodeURIComponent(r)}`).then(h=>h.json())).html??"";!f||o||(a.innerHTML=f)}))}catch{}}function S({apiKey:t,children:r,apiUrl:o}){return d(()=>{if(l("__tpz_base",v),typeof window<"u"){let e=new URLSearchParams(window.location.search);e.has("tapuz-edit")&&k(o,t),e.has("tapuz-lab")&&x(o,t)}},[]),d(()=>{t&&C(o||p,t)},[t,o]),d(()=>{if(!t)return;let e={};function s(){return fetch(`${o||p}/api/tokens?key=${encodeURIComponent(t)}`).then(c=>c.json()).then(({tokens:c,defaults:i,classDefs:z})=>{e={...i&&typeof i=="object"?i:{},...c&&typeof c=="object"?c:{}},m(e),l("__tpz_classes",y(z))}).catch(()=>{})}s();let n;function a(){n=new EventSource(`${o||p}/api/token-stream?key=${encodeURIComponent(t)}`),n.onmessage=c=>{try{let i=JSON.parse(c.data);if(i&&(i.type==="definitions_changed"||i.type==="feature_released")){s();return}if(!i||!i.tokens||typeof i.tokens!="object")return;e={...e,...i.tokens},m(e)}catch{}},n.onerror=()=>{n.close(),setTimeout(a,3e3)}}return a(),()=>{n&&n.close()}},[t,o]),g(b,null,r)}var I=S;export{S as TapuzEngineProvider,I as TokensEngineProvider};
|