@uibot/web-preview 0.15.1 → 0.16.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/dist/index.d.ts CHANGED
@@ -8,4 +8,5 @@ export { type AssembleInput, assembleErrorPage, assemblePreviewHtml, } from "./a
8
8
  export { detectProject, entryFromIndexHtml, findPreviewEntry, findProjectRoot, isBuildableFile, isProjectEntry, type PreviewKind, type ProjectInfo, } from "./detect.js";
9
9
  export { assessHtmlDocument, type HtmlDocumentIssue, type HtmlDocumentIssueCode, } from "./document.js";
10
10
  export { stripHtmlEnvelope } from "./html-envelope.js";
11
+ export { buildThemePreviewPageScript, THEME_PREVIEW_SHELL_SCRIPT, THEME_PREVIEW_SOURCE, type ThemePreviewMessage, themePreviewMessage, } from "./theme-preview.js";
11
12
  export { APP_SRCDOC_CSP, buildErrorBridgeScript, cspMetaTag, escapeAttr, escapeHtml, injectBeforeBodyEnd, injectBeforeHeadEnd, NETWORK_PREVIEW_CSP, PREVIEW_ERROR_MESSAGE, SANDBOX_LINK_SHIM_SCRIPT, SANDBOX_SHIM_SCRIPT, SANDBOX_STORAGE_SHIM_SCRIPT, STATIC_SRCDOC_CSP, STRICT_PREVIEW_CSP, } from "./srcdoc.js";
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- function a(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function y(t){return t.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function H(t,e){let n=t.toLowerCase(),r=n.indexOf("<body"),s=r>=0?r:n.length,i=n.lastIndexOf("</head>",s-1);if(i>=0)return t.slice(0,i)+e+t.slice(i);if(/<head[^>]*>/i.test(t))return t.replace(/<head[^>]*>/i,(c)=>`${c}${e}`);if(/<html[^>]*>/i.test(t))return t.replace(/<html[^>]*>/i,(c)=>`${c}<head>${e}</head>`);return e+t}function N(t,e){let n=t.toLowerCase(),r=n.lastIndexOf("</html>"),s=r>=0?r:n.length,i=n.lastIndexOf("</body>",s-1);if(i>=0)return t.slice(0,i)+e+t.slice(i);if(/<body[^>]*>/i.test(t))return t.replace(/<body[^>]*>/i,(c)=>`${c}${e}`);return t+e}var x=`<script data-uibot-storage-shim>(function(){
1
+ function a(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function y(t){return t.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function V(t,e){let n=t.toLowerCase(),r=n.indexOf("<body"),s=r>=0?r:n.length,i=n.lastIndexOf("</head>",s-1);if(i>=0)return t.slice(0,i)+e+t.slice(i);if(/<head[^>]*>/i.test(t))return t.replace(/<head[^>]*>/i,(c)=>`${c}${e}`);if(/<html[^>]*>/i.test(t))return t.replace(/<html[^>]*>/i,(c)=>`${c}<head>${e}</head>`);return e+t}function L(t,e){let n=t.toLowerCase(),r=n.lastIndexOf("</html>"),s=r>=0?r:n.length,i=n.lastIndexOf("</body>",s-1);if(i>=0)return t.slice(0,i)+e+t.slice(i);if(/<body[^>]*>/i.test(t))return t.replace(/<body[^>]*>/i,(c)=>`${c}${e}`);return t+e}var v=`<script data-uibot-storage-shim>(function(){
2
2
  function makeStore(){
3
3
  var data = {};
4
4
  var api = {
@@ -21,7 +21,7 @@ function a(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"
21
21
  }
22
22
  tryShim('localStorage');
23
23
  tryShim('sessionStorage');
24
- })();</script>`,_=`<script data-uibot-link-shim>(function(){
24
+ })();</script>`,b=`<script data-uibot-link-shim>(function(){
25
25
  document.addEventListener('click', function(e){
26
26
  if (!e.target || !(e.target instanceof Element)) return;
27
27
  var link = e.target.closest('a[href]');
@@ -43,7 +43,7 @@ function a(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"
43
43
  } catch (_) {}
44
44
  }
45
45
  });
46
- })();</script>`,g=x+_,S="uibot:preview-error";function h(){return`<script data-uibot-error-bridge>(function(){
46
+ })();</script>`,g=v+b,_="uibot:preview-error";function h(){return`<script data-uibot-error-bridge>(function(){
47
47
  function show(msg){
48
48
  try {
49
49
  var bar = document.getElementById('__uibot_err__');
@@ -57,7 +57,7 @@ function a(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"
57
57
  }
58
58
  bar.textContent = '预览运行时错误:\\n' + msg;
59
59
  } catch (_) {}
60
- try { if (window.parent && window.parent !== window) window.parent.postMessage({ type: ${JSON.stringify(S)}, message: String(msg) }, '*'); } catch (_) {}
60
+ try { if (window.parent && window.parent !== window) window.parent.postMessage({ type: ${JSON.stringify(_)}, message: String(msg) }, '*'); } catch (_) {}
61
61
  }
62
62
  window.addEventListener('error', function(ev){
63
63
  var m = ev && ev.error && ev.error.stack ? ev.error.stack : (ev && ev.message) || 'unknown error';
@@ -67,31 +67,31 @@ function a(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"
67
67
  var r = ev && ev.reason;
68
68
  show(r && r.stack ? r.stack : String(r));
69
69
  });
70
- })();</script>`}var B="default-src 'none'; script-src 'none'; style-src 'unsafe-inline'; img-src data:; font-src data:; connect-src 'none'; frame-src 'none'",M="default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline' https:; img-src data: blob: https:; font-src data: https:; connect-src 'none'; frame-src 'none'",u="default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; img-src data: blob:; font-src data:; connect-src 'none'; frame-src 'none'",b="default-src 'none'; script-src 'unsafe-inline' https://esm.sh https://cdn.jsdelivr.net; style-src 'unsafe-inline' https:; img-src data: blob: https:; font-src data: https:; connect-src 'none'; frame-src 'none'";function d(t){return`<meta http-equiv="Content-Security-Policy" content="${y(t)}">`}var W="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4";function L(t){let{js:e,css:n="",importMap:r={},tailwind:s=!1,title:i="Preview",rootId:c="root",notices:l=[]}=t,o=Object.keys(r).length>0,T=o||s?b:u,j=o?`<script type="importmap">${JSON.stringify({imports:r})}</script>`:"",O=s?`<script src="${W}"></script>`:"",k=n?`<style>${n}</style>`:"",A=l.length?K(l):"",D=e.replace(/<\/(script)/gi,"<\\/$1").replace(/<!--/g,"<\\!--");return`<!doctype html>
70
+ })();</script>`}var K="default-src 'none'; script-src 'none'; style-src 'unsafe-inline'; img-src data:; font-src data:; connect-src 'none'; frame-src 'none'",F="default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline' https:; img-src data: blob: https:; font-src data: https:; connect-src 'none'; frame-src 'none'",d="default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; img-src data: blob:; font-src data:; connect-src 'none'; frame-src 'none'",E="default-src 'none'; script-src 'unsafe-inline' https://esm.sh https://cdn.jsdelivr.net; style-src 'unsafe-inline' https:; img-src data: blob: https:; font-src data: https:; connect-src 'none'; frame-src 'none'";function u(t){return`<meta http-equiv="Content-Security-Policy" content="${y(t)}">`}var J="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4";function U(t){let{js:e,css:n="",importMap:r={},tailwind:s=!1,title:i="Preview",rootId:c="root",notices:l=[]}=t,o=Object.keys(r).length>0,H=o||s?E:d,M=o?`<script type="importmap">${JSON.stringify({imports:r})}</script>`:"",k=s?`<script src="${J}"></script>`:"",D=n?`<style>${n}</style>`:"",W=l.length?X(l):"",B=e.replace(/<\/(script)/gi,"<\\/$1").replace(/<!--/g,"<\\!--");return`<!doctype html>
71
71
  <html lang="zh-CN">
72
72
  <head>
73
73
  <meta charset="utf-8" />
74
74
  <meta name="viewport" content="width=device-width, initial-scale=1" />
75
- ${d(T)}
75
+ ${u(H)}
76
76
  <title>${a(i)}</title>
77
77
  ${g}
78
78
  ${h()}
79
- ${O}
80
- ${j}
81
79
  ${k}
80
+ ${M}
81
+ ${D}
82
82
  </head>
83
83
  <body>
84
- ${A}
84
+ ${W}
85
85
  <div id="${a(c)}"></div>
86
- <script type="module">${D}</script>
86
+ <script type="module">${B}</script>
87
87
  </body>
88
- </html>`}function K(t){return`<div id="__uibot_notice__" style="font:12px/1.5 ui-sans-serif,system-ui;background:#fef3c7;color:#92400e;padding:6px 12px;border-bottom:1px solid #fde68a" onclick="this.remove()" title="点击关闭">⚠ ${t.map((n)=>a(n)).join(" · ")}</div>`}function V(t,e){let n=e?`${t}
88
+ </html>`}function X(t){return`<div id="__uibot_notice__" style="font:12px/1.5 ui-sans-serif,system-ui;background:#fef3c7;color:#92400e;padding:6px 12px;border-bottom:1px solid #fde68a" onclick="this.remove()" title="点击关闭">⚠ ${t.map((n)=>a(n)).join(" · ")}</div>`}function z(t,e){let n=e?`${t}
89
89
 
90
90
  ${e}`:t;return`<!doctype html>
91
91
  <html lang="zh-CN">
92
92
  <head>
93
93
  <meta charset="utf-8" />
94
- ${d(u)}
94
+ ${u(d)}
95
95
  <title>预览构建失败</title>
96
96
  </head>
97
97
  <body style="margin:0;font:13px/1.6 ui-monospace,Menlo,monospace;background:#1f2937;color:#fca5a5">
@@ -100,4 +100,46 @@ ${d(u)}
100
100
  <pre style="white-space:pre-wrap;margin:0;color:#fda4af">${a(n)}</pre>
101
101
  </div>
102
102
  </body>
103
- </html>`}var F=["src/main.tsx","src/main.jsx","src/main.ts","src/main.js","src/index.tsx","src/index.jsx","src/index.ts","src/index.js","src/routes/__root.tsx","src/routes/__root.jsx","main.tsx","main.jsx","index.tsx","index.jsx"],G=/(^|\/)tailwind\.config\.(?:js|ts|cjs|mjs)$/i,X=/(^|\/)vite\.config\.(?:js|ts|mjs|cjs|mts)$/i,z=/(^|\/)src\/routes\/__root\.(?:tsx|jsx|ts|js)$/i,J=/(^|\/)app\.config\.(?:js|ts|mjs)$/i;function w(t){let e=t.lastIndexOf("/");return e<0?"":t.slice(0,e)}function p(t,e){return t?`${t}/${e}`:e}function v(t,e){return e===""?!0:t===e||t.startsWith(`${e}/`)}function I(t,e){let n=new Set(e),r=w(t);for(;;){if(n.has(p(r,"package.json")))return r;if(r==="")return null;r=w(r)}}function m(t,e){let n=I(t,e);if(n===null)return null;let r=new Set(e),s=r.has(p(n,"index.html"))?p(n,"index.html"):null,i=null;for(let o of F){let f=p(n,o);if(r.has(f)){i=f;break}}if(!s&&!i)return null;let c=e.some((o)=>v(o,n)&&G.test(o)),l=e.some((o)=>v(o,n)&&(X.test(o)||z.test(o)||J.test(o)))?"dev-server":"html";return{root:n,entry:s??i,htmlEntry:s,codeEntry:i,needsTailwind:c,previewKind:l}}function q(t,e){return m(t,e)!==null}function P(t,e){let n=m(t,e);if(!n)return!1;return t===n.htmlEntry||t===n.codeEntry}function U(t){let e=t.find((n)=>P(n,t));if(e)return e;for(let n of t){let r=m(n,t);if(r)return r.entry}return t.find((n)=>/(^|\/)index\.html?$/i.test(n))??t.find((n)=>/\.html?$/i.test(n))??null}function Y(t){let n=/<script\b[^>]*\btype\s*=\s*["']module["'][^>]*\bsrc\s*=\s*["']([^"']+)["']/i.exec(t);if(!n){let s=/<script\b[^>]*\bsrc\s*=\s*["']([^"']+)["'][^>]*\btype\s*=\s*["']module["']/i.exec(t);if(!s)return null;return E(s[1])}return E(n[1])}function E(t){if(/^(?:https?:)?\/\//i.test(t))return null;return t.replace(/^\.?\//,"")}var Z=/<(img|svg|canvas|video|input|textarea|button|select|iframe|picture)\b/i;function Q(t){return t.replace(/<!--[\s\S]*?-->/g,"")}function C(t){return/<body\b[^>]*>([\s\S]*?)<\/body\s*>/i.exec(t)?.[1]??null}function R(t){return t.replace(/<(script|style|template|noscript)\b[\s\S]*?<\/\1\s*>/gi," ").replace(/<[^>]+>/g," ").replace(/&nbsp;/gi," ").replace(/\s+/g," ").trim()}function tt(t){let e=[];for(let n of t.matchAll(/<script\b([^>]*)>/gi)){let r=/\bsrc\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/i.exec(n[1]??""),s=(r?.[1]??r?.[2]??r?.[3]??"").trim();if(/^(?:https?:)?\/\//i.test(s))e.push(s)}return e}function et(t){let e=Q(t),n=[];if(!/<html\b[^>]*>[\s\S]*<\/html\s*>\s*$/i.test(e.trim())||C(e)===null)n.push({code:"not-a-document",detail:"expected a complete <html> document with <body>…</body>"});if(!/^\s*<!doctype\s+html\b/i.test(e))n.push({code:"missing-doctype",detail:"missing <!doctype html>"});let r=/<title\b[^>]*>([\s\S]*?)<\/title\s*>/i.exec(e)?.[1];if(!r||!R(r))n.push({code:"missing-title",detail:"missing <title>"});let s=C(e);if(s!==null&&!R(s)&&!Z.test(s))n.push({code:"empty-body",detail:"the body has no visible content"});for(let i of tt(e))n.push({code:"external-script",detail:`script loaded from ${i}`});return n}function nt(t){let e=t.trim(),r=/^```[a-zA-Z]*\n([\s\S]*?)\n?```$/.exec(e);if(r?.[1])e=r[1].trim();if(e.startsWith("<![CDATA[")&&e.endsWith("]]>"))e=e.slice(9,-3).trim();return e}export{M as APP_SRCDOC_CSP,b as NETWORK_PREVIEW_CSP,S as PREVIEW_ERROR_MESSAGE,_ as SANDBOX_LINK_SHIM_SCRIPT,g as SANDBOX_SHIM_SCRIPT,x as SANDBOX_STORAGE_SHIM_SCRIPT,B as STATIC_SRCDOC_CSP,u as STRICT_PREVIEW_CSP,V as assembleErrorPage,L as assemblePreviewHtml,et as assessHtmlDocument,h as buildErrorBridgeScript,d as cspMetaTag,m as detectProject,Y as entryFromIndexHtml,y as escapeAttr,a as escapeHtml,U as findPreviewEntry,I as findProjectRoot,N as injectBeforeBodyEnd,H as injectBeforeHeadEnd,q as isBuildableFile,P as isProjectEntry,nt as stripHtmlEnvelope};
103
+ </html>`}var G=["src/main.tsx","src/main.jsx","src/main.ts","src/main.js","src/index.tsx","src/index.jsx","src/index.ts","src/index.js","src/routes/__root.tsx","src/routes/__root.jsx","main.tsx","main.jsx","index.tsx","index.jsx"],q=/(^|\/)tailwind\.config\.(?:js|ts|cjs|mjs)$/i,Y=/(^|\/)vite\.config\.(?:js|ts|mjs|cjs|mts)$/i,Z=/(^|\/)src\/routes\/__root\.(?:tsx|jsx|ts|js)$/i,Q=/(^|\/)app\.config\.(?:js|ts|mjs)$/i;function S(t){let e=t.lastIndexOf("/");return e<0?"":t.slice(0,e)}function p(t,e){return t?`${t}/${e}`:e}function x(t,e){return e===""?!0:t===e||t.startsWith(`${e}/`)}function P(t,e){let n=new Set(e),r=S(t);for(;;){if(n.has(p(r,"package.json")))return r;if(r==="")return null;r=S(r)}}function f(t,e){let n=P(t,e);if(n===null)return null;let r=new Set(e),s=r.has(p(n,"index.html"))?p(n,"index.html"):null,i=null;for(let o of G){let m=p(n,o);if(r.has(m)){i=m;break}}if(!s&&!i)return null;let c=e.some((o)=>x(o,n)&&q.test(o)),l=e.some((o)=>x(o,n)&&(Y.test(o)||Z.test(o)||Q.test(o)))?"dev-server":"html";return{root:n,entry:s??i,htmlEntry:s,codeEntry:i,needsTailwind:c,previewKind:l}}function tt(t,e){return f(t,e)!==null}function I(t,e){let n=f(t,e);if(!n)return!1;return t===n.htmlEntry||t===n.codeEntry}function et(t){let e=t.find((n)=>I(n,t));if(e)return e;for(let n of t){let r=f(n,t);if(r)return r.entry}return t.find((n)=>/(^|\/)index\.html?$/i.test(n))??t.find((n)=>/\.html?$/i.test(n))??null}function nt(t){let n=/<script\b[^>]*\btype\s*=\s*["']module["'][^>]*\bsrc\s*=\s*["']([^"']+)["']/i.exec(t);if(!n){let s=/<script\b[^>]*\bsrc\s*=\s*["']([^"']+)["'][^>]*\btype\s*=\s*["']module["']/i.exec(t);if(!s)return null;return w(s[1])}return w(n[1])}function w(t){if(/^(?:https?:)?\/\//i.test(t))return null;return t.replace(/^\.?\//,"")}var rt=/<(img|svg|canvas|video|input|textarea|button|select|iframe|picture)\b/i;function st(t){return t.replace(/<!--[\s\S]*?-->/g,"")}function R(t){return/<body\b[^>]*>([\s\S]*?)<\/body\s*>/i.exec(t)?.[1]??null}function T(t){return t.replace(/<(script|style|template|noscript)\b[\s\S]*?<\/\1\s*>/gi," ").replace(/<[^>]+>/g," ").replace(/&nbsp;/gi," ").replace(/\s+/g," ").trim()}function it(t){let e=[];for(let n of t.matchAll(/<script\b([^>]*)>/gi)){let r=/\bsrc\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/i.exec(n[1]??""),s=(r?.[1]??r?.[2]??r?.[3]??"").trim();if(/^(?:https?:)?\/\//i.test(s))e.push(s)}return e}function ot(t){let e=st(t),n=[];if(!/<html\b[^>]*>[\s\S]*<\/html\s*>\s*$/i.test(e.trim())||R(e)===null)n.push({code:"not-a-document",detail:"expected a complete <html> document with <body>…</body>"});if(!/^\s*<!doctype\s+html\b/i.test(e))n.push({code:"missing-doctype",detail:"missing <!doctype html>"});let r=/<title\b[^>]*>([\s\S]*?)<\/title\s*>/i.exec(e)?.[1];if(!r||!T(r))n.push({code:"missing-title",detail:"missing <title>"});let s=R(e);if(s!==null&&!T(s)&&!rt.test(s))n.push({code:"empty-body",detail:"the body has no visible content"});for(let i of it(e))n.push({code:"external-script",detail:`script loaded from ${i}`});return n}function ct(t){let e=t.trim(),r=/^```[a-zA-Z]*\n([\s\S]*?)\n?```$/.exec(e);if(r?.[1])e=r[1].trim();if(e.startsWith("<![CDATA[")&&e.endsWith("]]>"))e=e.slice(9,-3).trim();return e}var at="uibot.theme-preview.v1",C=/^#(?:[\da-f]{3,4}|[\da-f]{6}|[\da-f]{8})$/i,O=/^oklch\(\s*(?:\d+\.?\d*|\.\d+)%?\s+(?:\d+\.?\d*|\.\d+)\s+(?:\d+\.?\d*|\.\d+)(?:deg)?(?:\s*\/\s*(?:\d+\.?\d*|\.\d+)%?)?\s*\)$/i,j=/^(?:0|\d{1,2}(?:\.\d{1,3})?rem)$/,A=/^[\w\s,"'.-]{1,200}$/,N=/^[a-z][a-z0-9-]{0,40}$/;function lt(t){if(C.test(t)||O.test(t)||j.test(t))return!0;if(!A.test(t))return!1;return(t.match(/"/g)?.length??0)%2===0&&(t.match(/'/g)?.length??0)%2===0}function dt(t,e){if(!t)return{source:"uibot.theme-preview.v1",variables:null};let n=new Set(e);return{source:"uibot.theme-preview.v1",variables:Object.fromEntries(Object.entries(t).filter(([r,s])=>n.has(r)&&N.test(r)&&typeof s==="string"&&lt(s)))}}function ut(t){let e=JSON.stringify(t.filter((r)=>N.test(r))),n=JSON.stringify([C.source,O.source,j.source]);return`<script data-uibot-theme-preview>(function(){
104
+ var NAMES=${e};
105
+ var PATTERNS=${n}.map(function(p){return new RegExp(p,"i");});
106
+ var FONT=new RegExp(${JSON.stringify(A.source)});
107
+ var applied=[];
108
+ function valid(v){
109
+ if(typeof v!=="string")return false;
110
+ for(var i=0;i<PATTERNS.length;i++)if(PATTERNS[i].test(v))return true;
111
+ if(!FONT.test(v))return false;
112
+ return (v.split('"').length-1)%2===0&&(v.split("'").length-1)%2===0;
113
+ }
114
+ function clear(){
115
+ var style=document.documentElement.style;
116
+ for(var i=0;i<applied.length;i++)style.removeProperty("--"+applied[i]);
117
+ applied=[];
118
+ }
119
+ window.addEventListener("message",function(e){
120
+ if(e.source!==window.parent)return;
121
+ var d=e.data;
122
+ if(!d||typeof d!=="object"||d.source!==${JSON.stringify("uibot.theme-preview.v1")})return;
123
+ clear();
124
+ var vars=d.variables;
125
+ if(!vars||typeof vars!=="object")return;
126
+ var style=document.documentElement.style;
127
+ for(var i=0;i<NAMES.length;i++){
128
+ var name=NAMES[i];
129
+ if(Object.prototype.hasOwnProperty.call(vars,name)&&valid(vars[name])){
130
+ style.setProperty("--"+name,vars[name]);
131
+ applied.push(name);
132
+ }
133
+ }
134
+ });
135
+ })();</script>`}var pt=`<script data-uibot-theme-preview-relay>(function(){
136
+ window.addEventListener("message",function(e){
137
+ if(e.source!==window.parent)return;
138
+ var d=e.data;
139
+ if(!d||typeof d!=="object"||d.source!==${JSON.stringify("uibot.theme-preview.v1")})return;
140
+ var frames=document.querySelectorAll("iframe");
141
+ for(var i=0;i<frames.length;i++){
142
+ try{frames[i].contentWindow&&frames[i].contentWindow.postMessage(d,"*");}catch(_){}
143
+ }
144
+ });
145
+ })();</script>`;export{F as APP_SRCDOC_CSP,E as NETWORK_PREVIEW_CSP,_ as PREVIEW_ERROR_MESSAGE,b as SANDBOX_LINK_SHIM_SCRIPT,g as SANDBOX_SHIM_SCRIPT,v as SANDBOX_STORAGE_SHIM_SCRIPT,K as STATIC_SRCDOC_CSP,d as STRICT_PREVIEW_CSP,pt as THEME_PREVIEW_SHELL_SCRIPT,at as THEME_PREVIEW_SOURCE,z as assembleErrorPage,U as assemblePreviewHtml,ot as assessHtmlDocument,h as buildErrorBridgeScript,ut as buildThemePreviewPageScript,u as cspMetaTag,f as detectProject,nt as entryFromIndexHtml,y as escapeAttr,a as escapeHtml,et as findPreviewEntry,P as findProjectRoot,L as injectBeforeBodyEnd,V as injectBeforeHeadEnd,tt as isBuildableFile,I as isProjectEntry,ct as stripHtmlEnvelope,dt as themePreviewMessage};
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Live theme preview: a host posts CSS variable values into a sandboxed preview and the page
3
+ * applies them to `<html>` inline, over the stylesheet theme, without touching the document source.
4
+ * One way only (host → page). Names come from an allow-list; values must be a color (hex or
5
+ * oklch), a rem length or a font stack, checked on both sides with the same patterns.
6
+ */
7
+ export declare const THEME_PREVIEW_SOURCE = "uibot.theme-preview.v1";
8
+ /** `{ source, variables }`; `variables: null` clears every override the page applied. */
9
+ export interface ThemePreviewMessage {
10
+ source: typeof THEME_PREVIEW_SOURCE;
11
+ variables: Record<string, string> | null;
12
+ }
13
+ /** The message for `variables`, keeping only allowed names with valid values (`null` clears). */
14
+ export declare function themePreviewMessage(variables: Record<string, string> | null, allowed: readonly string[]): ThemePreviewMessage;
15
+ /**
16
+ * Page script: applies messages from the parent window only, re-validating every entry, with
17
+ * `style.setProperty` (no CSS text is ever built from message data).
18
+ */
19
+ export declare function buildThemePreviewPageScript(allowed: readonly string[]): string;
20
+ /** Shell script: forwards theme-preview messages from the parent to every page frame. */
21
+ export declare const THEME_PREVIEW_SHELL_SCRIPT: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uibot/web-preview",
3
- "version": "0.15.1",
3
+ "version": "0.16.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",