generated at
react-wc
Shadow DOMで隠蔽したReact.Componentを生成できるpackage

script.js
import {h, Fragment} from '../preact@10.5.13/script.js';var E=1,a="wc-";function k(){const t=Math.random().toString(36).slice(2);return`${a}${t}-${E++}`}var f=`${a}text`,m=!1,v=typeof window!="undefined"&&!!window.customElements;function l(t,r,e){if(Array.isArray(t)){const n=t.map((s,o)=>l(s,r,`wc-slot-${o}`));return e?h(Fragment,{key:e},n):n}if(typeof t!="object")return m||(m=!0,v&&window.customElements.define(f,class extends HTMLElement{})),h(f,{key:e,slot:r},t);if(x(t)){const{type:n}=t;if(typeof n=="string")return{...t,props:{...t.props,slot:r},key:t.key??e};if(typeof n=="symbol"){const i=n;if(i.description==="react.fragment")return{...t,props:{...t.props,children:l(t.props.children,r)},key:t.key??e};throw new Error("Could not handle node of type "+String(i))}const{props:{children:s,...o},key:c}=t,u=g.get(n);if(u)return h(u,{...o,key:c??e,slot:r},s);const p=S(n);return g.set(n,p),h(p,{...o,key:c??e,slot:r},s)}return null}var g=new WeakMap;function S(t){return b(t)?class extends t{render(){const r=super.render();return h(Fragment,{children:l(r,this.props.slot)})}}:({slot:r,...e})=>{const n=t(e);return h(Fragment,{children:l(n,r)})}}function x(t){return t!=null&&t.type!==void 0}function b(t){return!!t.prototype&&!!t.prototype.isReactComponent}function C(t,r){if(!r||r.length===0)return t.children;const e=t,n=[];for(const s of r){const o=e[s];n.push(l(o,s,`slot-${s}`))}return n.push(t.children),n}var y=Symbol("slot");function*$(t,r){for(let e=t;e<r;e++)yield e}function F(t,r){let e=t[0];const n=[];for(const s of $(0,r.length)){const o=r[s];if(typeof o!="object")e+=d(String(o));else{const c=o[y];c&&c!=="children"?(e+=`<slot name="${d(c)}"></slot>`,n.push(c)):e+="<slot></slot>"}e+=t[s+1]}return[e,n]}function M(t){switch(t){case"&":return"&amp;";case"<":return"&lt;";case">":return"&gt;";case'"':return"&quot;";case"'":return"&#39;";default:return t}}function d(t){return t.replace(/[&<>"']/g,M)}function j(t,...r){const e=k();let n=!1;const s=document.createDocumentFragment(),[o,c]=F(t,r);return Object.assign(u=>{if(!n){n=!0;const i=document.createElement("div");i.insertAdjacentHTML("afterbegin",o),s.append(...i.childNodes);class w extends HTMLElement{constructor(){super();this.attachShadow({mode:"open"}).appendChild(s.cloneNode(!0))}}window.customElements.define(e,w)}const p=C(u,c);return h(e,{},p)},{elementName:e})}function N(t){return{[y]:t||""}}export{j as html,N as slot};