svelte4-fragment-component
Version:
Svelte component that renders its children with lifecycle hooks to simplify testing using svelte4
3 lines (2 loc) • 4.57 kB
JavaScript
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(t="undefined"!=typeof globalThis?globalThis:t||self).SvelteFragment=n()}(this,(function(){"use strict";function t(){}function n(t,n){for(const e in n)t[e]=n[e];return t}function e(t){return t()}function o(){return Object.create(null)}function r(t){t.forEach(e)}function c(t){return"function"==typeof t}function u(t,n){return t!=t?n==n:t!==n||t&&"object"==typeof t||"function"==typeof t}function f(t,e,o,r){return t[1]&&r?n(o.ctx.slice(),t[1](r(e))):o.ctx}function i(t,n,e,o,r,c,u){const i=function(t,n,e,o){if(t[2]&&o){const r=t[2](o(e));if(void 0===n.dirty)return r;if("object"==typeof r){const t=[],e=Math.max(n.dirty.length,r.length);for(let o=0;o<e;o+=1)t[o]=n.dirty[o]|r[o];return t}return n.dirty|r}return n.dirty}(n,o,r,c);if(i){const r=f(n,e,o,u);t.p(r,i)}}function s(t,n){const e={};n=new Set(n);for(const o in t)n.has(o)||"$"===o[0]||(e[o]=t[o]);return e}function a(t){t.parentNode.removeChild(t)}let l;function d(t){l=t}function p(){if(!l)throw new Error("Function called outside component initialization");return l}const $=[],h=[],y=[],m=[],g=Promise.resolve();let x=!1;function b(t){y.push(t)}let _=!1;const U=new Set;function w(){if(!_){_=!0;do{for(let t=0;t<$.length;t+=1){const n=$[t];d(n),M(n.$$)}for($.length=0;h.length;)h.pop()();for(let t=0;t<y.length;t+=1){const n=y[t];U.has(n)||(U.add(n),n())}y.length=0}while($.length);for(;m.length;)m.pop()();x=!1,_=!1,U.clear()}}function M(t){if(null!==t.fragment){t.update(),r(t.before_update);const n=t.dirty;t.dirty=[-1],t.fragment&&t.fragment.p(t.ctx,n),t.after_update.forEach(b)}}const v=new Set;let C;function E(t,n){t&&t.i&&(v.delete(t),t.i(n))}function j(t,n){-1===t.$$.dirty[0]&&($.push(t),x||(x=!0,g.then(w)),t.$$.dirty.fill(0)),t.$$.dirty[n/31|0]|=1<<n%31}function D(n,u,f,i,s,p,$=[-1]){const h=l;d(n);const y=u.props||{},m=n.$$={fragment:null,ctx:null,props:p,update:t,not_equal:s,bound:o(),on_mount:[],on_destroy:[],before_update:[],after_update:[],context:new Map(h?h.$$.context:[]),callbacks:o(),dirty:$};let g=!1;if(m.ctx=f?f(n,y,((t,e,...o)=>{const r=o.length?o[0]:e;return m.ctx&&s(m.ctx[t],m.ctx[t]=r)&&(m.bound[t]&&m.bound[t](r),g&&j(n,t)),e})):[],m.update(),g=!0,r(m.before_update),m.fragment=!!i&&i(m.ctx),u.target){if(u.hydrate){const t=(x=u.target,Array.from(x.childNodes));m.fragment&&m.fragment.l(t),t.forEach(a)}else m.fragment&&m.fragment.c();u.intro&&E(n.$$.fragment),function(t,n,o){const{fragment:u,on_mount:f,on_destroy:i,after_update:s}=t.$$;u&&u.m(n,o),b((()=>{const n=f.map(e).filter(c);i?i.push(...n):r(n),t.$$.on_mount=[]})),s.forEach(b)}(n,u.target,u.anchor),w()}var x;d(h)}class k{$destroy(){!function(t,n){const e=t.$$;null!==e.fragment&&(r(e.on_destroy),e.fragment&&e.fragment.d(n),e.on_destroy=e.fragment=null,e.ctx=[])}(this,1),this.$destroy=t}$on(t,n){const e=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return e.push(n),()=>{const t=e.indexOf(n);-1!==t&&e.splice(t,1)}}$set(){}}function S(t){let n;const e=t[7].default,o=function(t,n,e,o){if(t){const r=f(t,n,e,o);return t[0](r)}}(e,t,t[6],null);return{c(){o&&o.c()},m(t,e){o&&o.m(t,e),n=!0},p(t,[n]){o&&o.p&&64&n&&i(o,e,t,t[6],n,null,null)},i(t){n||(E(o,t),n=!0)},o(t){!function(t,n,e,o){if(t&&t.o){if(v.has(t))return;v.add(t),C.c.push((()=>{v.delete(t),o&&(e&&t.d(1),o())})),t.o(n)}}(o,t),n=!1},d(t){o&&o.d(t)}}}function O(t,e,o){const r=["context","onCreate","onMount","beforeUpdate","afterUpdate","onDestroy"];let c=s(e,r),{context:u=null}=e,{onCreate:f=null}=e,{onMount:i=null}=e,{beforeUpdate:a=null}=e,{afterUpdate:l=null}=e,{onDestroy:d=null}=e;var $;function h(t){return()=>t({props:c})}u&&Object.keys(u).forEach((t=>{!function(t,n){p().$$.context.set(t,n)}(t,u[t])})),f&&h(f)(),i&&($=h(i),p().$$.on_mount.push($)),a&&function(t){p().$$.before_update.push(t)}(h(a)),l&&function(t){p().$$.after_update.push(t)}(h(l)),d&&function(t){p().$$.on_destroy.push(t)}(h(d));let{$$slots:y={},$$scope:m}=e;return t.$set=t=>{e=n(n({},e),function(t){const n={};for(const e in t)"$"!==e[0]&&(n[e]=t[e]);return n}(t)),o(9,c=s(e,r)),"context"in t&&o(0,u=t.context),"onCreate"in t&&o(1,f=t.onCreate),"onMount"in t&&o(2,i=t.onMount),"beforeUpdate"in t&&o(3,a=t.beforeUpdate),"afterUpdate"in t&&o(4,l=t.afterUpdate),"onDestroy"in t&&o(5,d=t.onDestroy),"$$scope"in t&&o(6,m=t.$$scope)},[u,f,i,a,l,d,m,y]}return class extends k{constructor(t){super(),D(this,t,O,S,u,{context:0,onCreate:1,onMount:2,beforeUpdate:3,afterUpdate:4,onDestroy:5})}}}));
//# sourceMappingURL=fragment.js.map