svelte-htm
Version:
tagged template syntax for svelte to simplify testing
3 lines (2 loc) • 12.8 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).svelteHyperscript=e()}(this,(function(){"use strict";var t=function(e,n,o,r){var s;n[0]=0;for(var c=1;c<n.length;c++){var i=n[c++],u=n[c]?(n[0]|=i?1:2,o[n[c++]]):n[++c];3===i?r[0]=u:4===i?r[1]=Object.assign(r[1]||{},u):5===i?(r[1]=r[1]||{})[n[++c]]=u:6===i?r[1][n[++c]]+=u+"":i?(s=e.apply(u,t(e,u,o,["",null])),r.push(s),u[0]?n[0]|=2:(n[c-2]=0,n[c]=s)):r.push(u)}return r},e=new Map;function n(){}const o=t=>t;function r(t,e){for(const n in e)t[n]=e[n];return t}function s(t){return t()}function c(){return Object.create(null)}function i(t){t.forEach(s)}function u(t){return"function"==typeof t}function l(t,e){return t!=t?e==e:t!==e||t&&"object"==typeof t||"function"==typeof t}function f(t,...e){if(null==t)return n;const o=t.subscribe(...e);return o.unsubscribe?()=>o.unsubscribe():o}function a(t){let e;return f(t,(t=>e=t))(),e}function d(t,e,n,o){return t[1]&&o?r(n.ctx.slice(),t[1](o(e))):n.ctx}function p(t,e){const n={};e=new Set(e);for(const o in t)e.has(o)||"$"===o[0]||(n[o]=t[o]);return n}function h(t,e){t.appendChild(e)}function $(t,e,n){t.insertBefore(e,n||null)}function g(t){t.parentNode.removeChild(t)}function b(t){return document.createElement(t)}function y(t){return document.createTextNode(t)}function m(t,e,n,o){return t.addEventListener(e,n,o),()=>t.removeEventListener(e,n,o)}let v,_;function x(){if(void 0===v){v=!1;try{"undefined"!=typeof window&&window.parent&&window.parent.document}catch(t){v=!0}}return v}function w(t){_=t}function k(){if(!_)throw new Error("Function called outside component initialization");return _}const E=[],W=[],M=[],j=[],U=Promise.resolve();let A=!1;function O(t){M.push(t)}const S=new Set;let C=0;function D(){const t=_;do{for(;C<E.length;){const t=E[C];C++,w(t),H(t.$$)}for(w(null),E.length=0,C=0;W.length;)W.pop()();for(let t=0;t<M.length;t+=1){const e=M[t];S.has(e)||(S.add(e),e())}M.length=0}while(E.length);for(;j.length;)j.pop()();A=!1,S.clear(),w(t)}function H(t){if(null!==t.fragment){t.update(),i(t.before_update);const e=t.dirty;t.dirty=[-1],t.fragment&&t.fragment.p(t.ctx,e),t.after_update.forEach(O)}}const z=new Set;function T(t,e){t&&t.i&&(z.delete(t),t.i(e))}function q(t){t&&t.c()}function L(t,e,n,o){const{fragment:r,on_mount:c,on_destroy:l,after_update:f}=t.$$;r&&r.m(e,n),o||O((()=>{const e=c.map(s).filter(u);l?l.push(...e):i(e),t.$$.on_mount=[]})),f.forEach(O)}function N(t,e){const n=t.$$;null!==n.fragment&&(i(n.on_destroy),n.fragment&&n.fragment.d(e),n.on_destroy=n.fragment=null,n.ctx=[])}function P(t,e){-1===t.$$.dirty[0]&&(E.push(t),A||(A=!0,U.then(D)),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<<e%31}function B(t,e,o,r,s,u,l,f=[-1]){const a=_;w(t);const d=t.$$={fragment:null,ctx:null,props:u,update:n,not_equal:s,bound:c(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(e.context||(a?a.$$.context:[])),callbacks:c(),dirty:f,skip_bound:!1,root:e.target||a.$$.root};l&&l(d.root);let p=!1;if(d.ctx=o?o(t,e.props||{},((e,n,...o)=>{const r=o.length?o[0]:n;return d.ctx&&s(d.ctx[e],d.ctx[e]=r)&&(!d.skip_bound&&d.bound[e]&&d.bound[e](r),p&&P(t,e)),n})):[],d.update(),p=!0,i(d.before_update),d.fragment=!!r&&r(d.ctx),e.target){if(e.hydrate){const t=function(t){return Array.from(t.childNodes)}(e.target);d.fragment&&d.fragment.l(t),t.forEach(g)}else d.fragment&&d.fragment.c();e.intro&&T(t.$$.fragment),L(t,e.target,e.anchor,e.customElement),D()}w(a)}class I{$destroy(){N(this,1),this.$destroy=n}$on(t,e){const n=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return n.push(e),()=>{const t=n.indexOf(e);-1!==t&&n.splice(t,1)}}$set(t){var e;this.$$set&&(e=t,0!==Object.keys(e).length)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}function F(t){let e;return{c(){e=y(t[1])},m(t,n){$(t,e,n)},p(t,[n]){2&n&&function(t,e){e=""+e,t.wholeText!==e&&(t.data=e)}(e,t[1])},i:n,o:n,d(t){t&&g(e)}}}function G(t,e,o){let r,s=n,c=()=>(s(),s=f(i,(t=>o(1,r=t))),i);t.$$.on_destroy.push((()=>s()));let{store:i}=e;return c(),t.$set=t=>{"store"in t&&c(o(0,i=t.store))},[i,r]}class J extends I{constructor(t){super(),B(this,t,G,F,l,{store:0})}}const K=new WeakMap;function Q(t,e,...n){const o={};let r=null;const s={};et(e,((t,e)=>{"slot"===t?r=e:t.startsWith("let:")?(r||(r="default"),s[t.slice(4)]=e):o[t]=e}));const c=()=>[t,o,n,s],i="string"!=typeof t?R:X;class u extends I{constructor(t){super(),B(this,t,c,i,l,Object.keys(o).reduce(((t,e,n)=>(t[e]=n,t)),{}))}}return r&&K.set(u,{name:r,setters:s}),u}function R([t,e,o,r]){const s={},c={},u={};et(e,((t,e)=>{if(t.startsWith("on:")){const n=t.slice(3);c[n]=e}else if(t.startsWith("bind:")){const n=t.slice(5);u[n]=e,s[n]=a(e)}else s[t]=e}));const l={},f=o.filter((t=>!K.has(t)));f.length>0&&(l.default=V(f,r)),o.forEach((t=>{const e=K.get(t);e&&(l[e.name]=V([t],e.setters))}));const d=new t({props:{...s,$$slots:l,$$scope:{ctx:[]}},$$inline:!0});let p;return et(c,((t,e)=>{d.$on(t,e)})),et(u,((t,e)=>{W.push((()=>function(t,e,n){const o=t.$$.props[e];void 0!==o&&(t.$$.bound[o]=n,n(t.$$.ctx[o]))}(d,t,(t=>e.set(t)))))})),{c(){q(d.$$.fragment)},m(t,e,n){L(d,t,e),n&&i(p),p=[],et(u,((t,e)=>{p.push(e.subscribe((e=>d.$set({[t]:e}))))}))},p:n,d(t){N(d,t),i(p)}}}function V(t,e){return[()=>function(t){const e=t.map((t=>Z(t)));let o;return{c(){o=e.map((t=>t()))},m(t,e){o.forEach((n=>tt(n,t,e)))},p:n,d(t){o.forEach((e=>{e.$$?N(e,t):g(e)}))}}}(t),t=>{et(t,((t,n)=>{const o=e[t];"function"==typeof o?o(n,t):o&&"function"==typeof o.set&&o.set(n)}))},t=>Object.keys(t).length]}function X([t,e,o]){const r=o.map((t=>Z(t)));let s,c,l;const f={},d={},p={},y={},v={};return et(e,((n,o)=>{if(n.startsWith("on:")){const t=n.slice(3);d[t]=o}else if(n.startsWith("class:")){const t=n.slice(6);y[t]=o}else if(n.startsWith("use:")){const t=n.slice(4);v[t]=o}else if(n.startsWith("bind:")){const r=n.slice(5);p[r]={store:o,handler:Y(t,r,o,e)}}else f[n]=o})),{c(){s=b(t),("option"===t||ct(t,f))&&(s.__value=f.value),et(f,((t,e)=>{!function(t,e,n){null==n?t.removeAttribute(e):t.getAttribute(e)!==n&&t.setAttribute(e,n)}(s,t,e)})),c=r.map((t=>t()))},m(o,r,f){$(o,s,r),c.forEach((t=>tt(t,s,null))),f&&i(l),l=[],et(d,((t,e)=>{l.push(function(t,e,n){const[o,...r]=e.split(/\|/g);let s;return r.forEach((t=>{switch(t){case"preventDefault":e=n,n=function(t){return t.preventDefault(),e.call(this,t)};break;case"stopPropagation":n=function(t){return function(e){return e.stopPropagation(),t.call(this,e)}}(n);break;case"self":n=function(t){return function(e){e.target===this&&t.call(this,e)}}(n);break;default:(s||(s={}))[t]=!0}var e})),m(t,o,n,s)}(s,t,e))})),et(y,((t,e)=>{l.push(function(t,e,n){return n.subscribe((n=>{!function(t,e,n){t.classList[n?"add":"remove"](e)}(t,e,n)}))}(s,t,e))})),et(p,((n,{store:o,handler:r})=>{(ot(n)||void 0===a(o))&&r.call(s),ot(n)||function(t,e,n,o,r){"group"!==e&&ct(t,r)&&(e="checked");o.subscribe((o=>{if("group"===e&&ct(t,r))"radio"===r.type?n.checked=o===n.__value:n.checked=Boolean(o)&&o.includes(n.__value);else if("select"===t)r.multiple?function(t,e){for(let n=0;n<t.options.length;n+=1){const o=t.options[n];o.selected=~e.indexOf(o.__value)}}(n,o):function(t,e){for(let n=0;n<t.options.length;n+=1){const o=t.options[n];if(o.__value===e)return void(o.selected=!0)}t.selectedIndex=-1}(n,o);else if("value"===e)!function(t,e){t.value=null==e?"":e}(n,o);else n[e]=o}))}(t,n,s,o,e),function(t,e,n,o,r,s,c){let i;!function(t){return rt.has(t)}(n)?"this"===n?i=()=>r.set(null):ct(e,c)||"select"===e?i=m(o,"change",s):("input"===e&&"range"===c.type&&t.push(m(o,"change",s)),i=m(o,"input",s)):i=function(t,e){"static"===getComputedStyle(t).position&&(t.style.position="relative");const n=b("iframe");n.setAttribute("style","display: block; position: absolute; top: 0; left: 0; width: 100%; height: 100%; overflow: hidden; border: 0; opacity: 0; pointer-events: none; z-index: -1;"),n.setAttribute("aria-hidden","true"),n.tabIndex=-1;const o=x();let r;return o?(n.src="data:text/html,<script>onresize=function(){parent.postMessage(0,'*')}<\/script>",r=m(window,"message",(t=>{t.source===n.contentWindow&&e()}))):(n.src="about:blank",n.onload=()=>{r=m(n.contentWindow,"resize",e)}),h(t,n),()=>{(o||r&&n.contentWindow)&&r(),g(n)}}(o,s.bind(o));t.push(i)}(l,t,n,s,o,r,e)})),et(v,((t,e)=>{var o;l.push((o=e(s))&&u(o.destroy)?o.destroy:n)}))},p:n,d(t){t&&g(s),c.forEach((t=>{t.$$&&N(t)})),i(l)}}}function Y(t,e,n,r){let s=t=>t[e];if("group"===e&&ct(t,r)){if("radio"===r.type)return function(){this.checked&&n.set(this.__value)};s=t=>{const e=new Set(a(n)||[]);return t.checked?e.add(t.__value):e.delete(t.__value),[...e]}}else"this"===e?s=o:"value"===e&&("select"===t?s=r.multiple?t=>{return e=t,[].map.call(e.querySelectorAll(":checked"),(t=>t.__value));var e}:t=>function(t){const e=t.querySelector(":checked")||t.options[0];return e&&e.__value}(t):ct(t,r)?s=t=>t.checked:function(t,e){return"input"===t&&("number"===e.type||"range"===e.type)}(t,r)&&(s=t=>{return""===(e=t.value)?null:+e;var e}));return function(){n.set(s(this))}}function Z(t){if(null==t||!1===t)return()=>y("");if("function"==typeof t||st(t)){const e={props:{$$scope:{ctx:[]}},$$inline:!0},n=st(t)?new J((e.props.store=t)&&e):new t(e);return()=>(q(n.$$.fragment),n)}return()=>y(t)}function tt(t,e,n){t.$$?L(t,e,n):h(e,t)}function et(t,e){t&&Object.entries(t).forEach((([n,o])=>e(n,o,t)))}const nt=new Set(["duration","buffered","played","seekable","seeking","ended","videoWidth","videoHeight","clientWidth","clientHeight","offsetWidth","offsetHeight","this"]);function ot(t){return nt.has(t)}const rt=new Set(["clientWidth","clientHeight","offsetWidth","offsetHeight"]);function st(t){return t&&"function"==typeof t.subscribe}function ct(t,e){return"input"===t&&("checkbox"===e.type||"radio"===e.type)}function it(t){let e;const n=t[7].default,o=function(t,e,n,o){if(t){const r=d(t,e,n,o);return t[0](r)}}(n,t,t[6],null);return{c(){o&&o.c()},m(t,n){o&&o.m(t,n),e=!0},p(t,[r]){o&&o.p&&(!e||64&r)&&function(t,e,n,o,r,s){if(r){const c=d(e,n,o,s);t.p(c,r)}}(o,n,t,t[6],e?function(t,e,n,o){if(t[2]&&o){const r=t[2](o(n));if(void 0===e.dirty)return r;if("object"==typeof r){const t=[],n=Math.max(e.dirty.length,r.length);for(let o=0;o<n;o+=1)t[o]=e.dirty[o]|r[o];return t}return e.dirty|r}return e.dirty}(n,t[6],r,null):function(t){if(t.ctx.length>32){const e=[],n=t.ctx.length/32;for(let t=0;t<n;t++)e[t]=-1;return e}return-1}(t[6]),null)},i(t){e||(T(o,t),e=!0)},o(t){!function(t,e,n,o){if(t&&t.o){if(z.has(t))return;z.add(t),(void 0).c.push((()=>{z.delete(t),o&&(n&&t.d(1),o())})),t.o(e)}else o&&o()}(o,t),e=!1},d(t){o&&o.d(t)}}}function ut(t,e,n){const o=["context","onCreate","onMount","beforeUpdate","afterUpdate","onDestroy"];let s=p(e,o),{$$slots:c={},$$scope:i}=e,{context:u=null}=e,{onCreate:l=null}=e,{onMount:f=null}=e,{beforeUpdate:a=null}=e,{afterUpdate:d=null}=e,{onDestroy:h=null}=e;var $;function g(t){return()=>t({props:s})}return u&&Object.keys(u).forEach((t=>{!function(t,e){k().$$.context.set(t,e)}(t,u[t])})),l&&g(l)(),f&&($=g(f),k().$$.on_mount.push($)),a&&function(t){k().$$.before_update.push(t)}(g(a)),d&&function(t){k().$$.after_update.push(t)}(g(d)),h&&function(t){k().$$.on_destroy.push(t)}(g(h)),t.$$set=t=>{e=r(r({},e),function(t){const e={};for(const n in t)"$"!==n[0]&&(e[n]=t[n]);return e}(t)),n(9,s=p(e,o)),"context"in t&&n(0,u=t.context),"onCreate"in t&&n(1,l=t.onCreate),"onMount"in t&&n(2,f=t.onMount),"beforeUpdate"in t&&n(3,a=t.beforeUpdate),"afterUpdate"in t&&n(4,d=t.afterUpdate),"onDestroy"in t&&n(5,h=t.onDestroy),"$$scope"in t&&n(6,i=t.$$scope)},[u,l,f,a,d,h,i,c]}class lt extends I{constructor(t){super(),B(this,t,ut,it,l,{context:0,onCreate:1,onMount:2,beforeUpdate:3,afterUpdate:4,onDestroy:5})}}const ft=function(n){var o=e.get(this);return o||(o=new Map,e.set(this,o)),(o=t(this,o.get(n)||(o.set(n,o=function(t){for(var e,n,o=1,r="",s="",c=[0],i=function(t){1===o&&(t||(r=r.replace(/^\s*\n\s*|\s*\n\s*$/g,"")))?c.push(0,t,r):3===o&&(t||r)?(c.push(3,t,r),o=2):2===o&&"..."===r&&t?c.push(4,t,0):2===o&&r&&!t?c.push(5,0,!0,r):o>=5&&((r||!t&&5===o)&&(c.push(o,0,r,n),o=6),t&&(c.push(o,t,0,n),o=6)),r=""},u=0;u<t.length;u++){u&&(1===o&&i(),i(u));for(var l=0;l<t[u].length;l++)e=t[u][l],1===o?"<"===e?(i(),c=[c],o=3):r+=e:4===o?"--"===r&&">"===e?(o=1,r=""):r=e+r[0]:s?e===s?s="":r+=e:'"'===e||"'"===e?s=e:">"===e?(i(),o=1):o&&("="===e?(o=5,n=r,r=""):"/"===e&&(o<5||">"===t[u][l+1])?(i(),3===o&&(c=c[0]),o=c,(c=c[0]).push(2,0,o),o=0):" "===e||"\t"===e||"\n"===e||"\r"===e?(i(),o=2):r+=e),3===o&&"!--"===r&&(o=4,c=c[0])}return i(),c}(n)),o),arguments,[])).length>1?o:o[0]}.bind(Q);return function(...t){const e=ft(...t);return Array.isArray(e)?Q(lt,null,...e):e}}));
//# sourceMappingURL=html.js.map