-
Notifications
You must be signed in to change notification settings - Fork 0
/
sb.min.js
5 lines (5 loc) · 5.6 KB
/
sb.min.js
1
2
3
4
5
/* Strawberry 0.0.0-alpha.0
* Copyright (c) 2023-present, Alan Tom (18alantom)
* MIT License
* This is a generated file. Do not edit.*/
"use strict";var sb=(()=>{var m=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var R=Object.prototype.hasOwnProperty;var k=(n,t)=>{for(var e in t)m(n,e,{get:t[e],enumerable:!0})},M=(n,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of T(t))!R.call(n,r)&&r!==e&&m(n,r,{get:()=>t[r],enumerable:!(s=E(t,r))||s.enumerable});return n};var C=n=>M(m({},"__esModule",{value:!0}),n);var K={};k(K,{init:()=>L,load:()=>D,register:()=>_,unwatch:()=>$,watch:()=>F});var P=/\w+(\??[.]\w+)+/g,u=null,h="sb-",o=n=>h+n;function b(n,t){if(typeof n!="object"||n===null)return n;for(let e of Object.keys(n)){let s=d(e,t),r=n[e];n[e]=b(r,s)}return Object.defineProperty(n,"__sb_prefix",{value:t,enumerable:!1}),new Proxy(n,l)}var l=class{static get(t,e,s){if(e==="__parent")return O(t);let r=Reflect.get(t,e,s);return r?.__sb_dependencies?r():r}static set(t,e,s,r){if(typeof e=="symbol")return Reflect.set(t,e,s,r);let i=d(e,t.__sb_prefix),c=b(s,i);typeof s=="function"&&this.updateDependents(s,i);let a=Reflect.set(t,e,c,r);return this.update(s,i,!1),Array.isArray(t)&&/\d+/.test(e)&&this.syncTree(t,e,s),this.updateDependencies(i),a}static updateDependencies(t){let e=Object.keys(this.dependents).filter(s=>s===t||t.startsWith(s+".")).map(s=>this.dependents[s]??[]).flat();for(let s of e)this.update(s.computed,s.key,!1)}static deleteProperty(t,e){if(typeof e=="symbol")return Reflect.deleteProperty(t,e);let s=d(e,t.__sb_prefix),r=Reflect.deleteProperty(t,e);this.update(void 0,s,!0);for(let i of this.dependents[s]??[])this.update(i.computed,i.key,!1);for(let i of Object.keys(this.dependents))this.dependents[i]=this.dependents[i]?.filter(c=>c.key!==s)??[];return r}static syncTree(t,e,s){let r=t.__sb_prefix,i=document.querySelectorAll(`[${o("mark")}="${r}"]`),c=d(e,r);for(let a of i){if(a.querySelector(`[${o("mark")}="${c}"]`)!==null)continue;let f=a.getAttribute(o("child"));if(!f)continue;let x=y(f,c,s);a.appendChild(x)}}static update(t,e,s){if(typeof t=="function"&&(t=t()),t instanceof Promise){t.then(r=>this.update(r,e,!1));return}this.callWatchers(t,e),this.callHandlers(t,e,s)}static callWatchers(t,e){for(let s of Object.keys(this.watchers))if(e===s)this.watchers[s]?.forEach(r=>r(t));else if(e.startsWith(s+".")&&u!==null){let r=A(s,u);this.watchers[s]?.forEach(i=>i(r))}}static callHandlers(t,e,s){for(let r in this.handlers){let i=this.handlers[r];document.querySelectorAll(`[${h+r}='${e}']`).forEach(a=>i(t,a,e,s))}}static updateDependents(t,e){var s;Object.defineProperty(t,"__sb_dependencies",{value:!1,enumerable:!1,writable:!0});for(let r of t.toString().matchAll(P)){let i=r[0]?.replace("?.",".");if(!i)continue;let c=i.indexOf(".")+1,a=i.slice(c);(s=this.dependents)[a]??(s[a]=[]),this.dependents[a].push({key:e,computed:t}),t.__sb_dependencies=!0}}};l.watchers={},l.dependents={},l.handlers={mark:g,if:(t,e,s)=>{let r=!!t,i=e instanceof HTMLTemplateElement;if(r&&i){let c=e.children[0]??e.content.children[0];if(!c)return;c.setAttribute(o("if"),s),e.replaceWith(c)}if(!r&&!i){let c=document.createElement("template");c.appendChild(e.cloneNode(!0)),c.setAttribute(o("if"),s),e.replaceWith(c)}}};function g(n,t,e,s){return s&&j(t),Array.isArray(n)?W(n,t,e):typeof n=="object"&&n!==null?S(n,t,e):H(n,t,e)}function j(n){let t=n.getAttribute(o("plc"))==="1",e=n.parentElement;if(!t||!(n instanceof HTMLElement)||!e)return n.remove();if(n.getAttribute(o("mark"))===e.getAttribute(o("mark")))return e.remove();n.remove()}function H(n,t,e){t instanceof HTMLElement&&n!==void 0&&(t.innerText=String(n)),t.setAttribute(o("mark"),e)}function W(n,t,e){let s=t.getAttribute(o("child"));if(!s){console.error("marked el with array value has no child",n,t,e);return}let r=n.map((i,c)=>y(s,d(String(c),e),i));t.setAttribute(o("mark"),e),t.replaceChildren(...r)}function S(n,t,e){let s=t.getAttribute(o("child"));if(!s)return w(t,e,n);let r=y(s,e,n);r.setAttribute(o("mark"),e),t.replaceWith(r)}function y(n,t,e){let s=document.createElement(n);return w(s,t,e),s}function w(n,t,e){let s=n.shadowRoot?.querySelectorAll("slot");if(!s?.length)return typeof e=="object"&&e!==null&&!Array.isArray(e)&&(e=void 0),g(e,n,t,!1);n.replaceChildren();for(let r of s){let i=r.getAttribute(o("child")),c=document.createElement(i??"span"),a=e,p=t,f=r.getAttribute("name");f&&(a=e?.[f],p=d(f,t),c.setAttribute("slot",f)),i||c.setAttribute(o("plc"),"1"),g(a,c,p,!1),n.appendChild(c)}n.setAttribute(o("mark"),t)}function d(n,t){return t===""?n:t+"."+n}function A(n,t){for(let e of n.split(".")){let s=typeof t;if(t===null||s!=="function"&&s!=="object")return;t=Reflect.get(t,e)}return t}function O(n){let t=n.__sb_prefix;if(!t)return;let e=t.lastIndexOf(".");return e===-1?u:A(t.slice(0,e),u)}function L(n){return u??(u=b({},"")),h=n?.prefix??h,n?.handlers&&(l.handlers={...l.handlers,...n.handlers}),_(),u}async function D(n){typeof n=="string"&&(n=[n]);for(let t of n){let e=document.createElement("div"),s=await fetch(t).then(r=>r.text()).catch(r=>console.error(r));typeof s=="string"&&(e.innerHTML=s,_(e))}}function _(n){let t=n??document;for(let e of t.getElementsByTagName("template")){let s=e.getAttribute("name");if(!s||customElements.get(s))return;let r=class extends HTMLElement{constructor(){super();let i=e.content.children[0]?.cloneNode(!0);i&&this.attachShadow({mode:"open"}).appendChild(i)}};customElements.define(s,r)}}function F(n,t){var e;(e=l.watchers)[n]??(e[n]=[]),l.watchers[n].push(t)}function $(n,t){if(!n){l.watchers={};return}if(!t){delete l.watchers[n];return}let e=l.watchers[n]??[];l.watchers[n]=e.filter(s=>s!==t)}return C(K);})();