Skip to content

Instantly share code, notes, and snippets.

@fubits1
Last active November 14, 2022 18:53
Show Gist options
  • Save fubits1/4837ee37588264290d95b1933f6ce0a5 to your computer and use it in GitHub Desktop.
Save fubits1/4837ee37588264290d95b1933f6ce0a5 to your computer and use it in GitHub Desktop.
(function(f,h){typeof exports=="object"&&typeof module<"u"?module.exports=h():typeof define=="function"&&define.amd?define(h):(f=typeof globalThis<"u"?globalThis:f||self,f.Counter=h())})(this,function(){"use strict";function f(){}function h(t){return t()}function T(){return Object.create(null)}function p(t){t.forEach(h)}function N(t){return typeof t=="function"}function O(t,e){return t!=t?e==e:t!==e||t&&typeof t=="object"||typeof t=="function"}function Q(t){return Object.keys(t).length===0}function a(t,e){t.appendChild(e)}function P(t,e,n){t.insertBefore(e,n||null)}function V(t){t.parentNode.removeChild(t)}function m(t){return document.createElement(t)}function k(t){return document.createTextNode(t)}function S(){return k(" ")}function L(t,e,n,i){return t.addEventListener(e,n,i),()=>t.removeEventListener(e,n,i)}function b(t,e,n){n==null?t.removeAttribute(e):t.getAttribute(e)!==n&&t.setAttribute(e,n)}function R(t){return Array.from(t.childNodes)}function U(t,e){e=""+e,t.wholeText!==e&&(t.data=e)}function B(t,e,n,i){n===null?t.style.removeProperty(e):t.style.setProperty(e,n,i?"important":"")}let C;function g(t){C=t}const $=[],M=[],x=[],q=[],W=Promise.resolve();let E=!1;function X(){E||(E=!0,W.then(z))}function A(t){x.push(t)}const j=new Set;let v=0;function z(){const t=C;do{for(;v<$.length;){const e=$[v];v++,g(e),Y(e.$$)}for(g(null),$.length=0,v=0;M.length;)M.pop()();for(let e=0;e<x.length;e+=1){const n=x[e];j.has(n)||(j.add(n),n())}x.length=0}while($.length);for(;q.length;)q.pop()();E=!1,j.clear(),g(t)}function Y(t){if(t.fragment!==null){t.update(),p(t.before_update);const e=t.dirty;t.dirty=[-1],t.fragment&&t.fragment.p(t.ctx,e),t.after_update.forEach(A)}}const w=new Set;let Z;function D(t,e){t&&t.i&&(w.delete(t),t.i(e))}function tt(t,e,n,i){if(t&&t.o){if(w.has(t))return;w.add(t),Z.c.push(()=>{w.delete(t),i&&(n&&t.d(1),i())}),t.o(e)}else i&&i()}function et(t){t&&t.c()}function F(t,e,n,i){const{fragment:r,after_update:l}=t.$$;r&&r.m(e,n),i||A(()=>{const o=t.$$.on_mount.map(h).filter(N);t.$$.on_destroy?t.$$.on_destroy.push(...o):p(o),t.$$.on_mount=[]}),l.forEach(A)}function G(t,e){const n=t.$$;n.fragment!==null&&(p(n.on_destroy),n.fragment&&n.fragment.d(e),n.on_destroy=n.fragment=null,n.ctx=[])}function nt(t,e){t.$$.dirty[0]===-1&&($.push(t),X(),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<<e%31}function H(t,e,n,i,r,l,o,d=[-1]){const c=C;g(t);const s=t.$$={fragment:null,ctx:[],props:l,update:f,not_equal:r,bound:T(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(e.context||(c?c.$$.context:[])),callbacks:T(),dirty:d,skip_bound:!1,root:e.target||c.$$.root};o&&o(s.root);let y=!1;if(s.ctx=n?n(t,e.props||{},(u,_,...J)=>{const K=J.length?J[0]:_;return s.ctx&&r(s.ctx[u],s.ctx[u]=K)&&(!s.skip_bound&&s.bound[u]&&s.bound[u](K),y&&nt(t,u)),_}):[],s.update(),y=!0,p(s.before_update),s.fragment=i?i(s.ctx):!1,e.target){if(e.hydrate){const u=R(e.target);s.fragment&&s.fragment.l(u),u.forEach(V)}else s.fragment&&s.fragment.c();e.intro&&D(t.$$.fragment),F(t,e.target,e.anchor,e.customElement),z()}g(c)}class I{$destroy(){G(this,1),this.$destroy=f}$on(e,n){if(!N(n))return f;const i=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return i.push(n),()=>{const r=i.indexOf(n);r!==-1&&i.splice(r,1)}}$set(e){this.$$set&&!Q(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}const ct="";function it(t){let e,n,i,r,l,o,d,c,s,y;return{c(){e=m("div"),n=m("button"),n.textContent="-",i=S(),r=m("p"),l=k("count is "),o=k(t[0]),d=S(),c=m("button"),c.textContent="+",b(n,"class","svelte-cephk2"),b(c,"class","svelte-cephk2"),b(e,"class","svelte-cephk2"),B(e,"color",t[0]<0?"red":"black")},m(u,_){P(u,e,_),a(e,n),a(e,i),a(e,r),a(r,l),a(r,o),a(e,d),a(e,c),s||(y=[L(n,"click",t[2]),L(c,"click",t[1])],s=!0)},p(u,[_]){_&1&&U(o,u[0]),_&1&&B(e,"color",u[0]<0?"red":"black")},i:f,o:f,d(u){u&&V(e),s=!1,p(y)}}}function rt(t,e,n){let{initialValue:i}=e,r=i;const l=()=>{n(0,r+=1)},o=()=>{n(0,r-=1)};return t.$$set=d=>{"initialValue"in d&&n(3,i=d.initialValue)},[r,l,o,i]}class st extends I{constructor(e){super(),H(this,e,rt,it,O,{initialValue:3})}}const ft="";function ut(t){let e,n,i;return n=new st({props:{initialValue:t[0]}}),{c(){e=m("div"),et(n.$$.fragment),b(e,"class","counter svelte-b7r1l9")},m(r,l){P(r,e,l),F(n,e,null),i=!0},p(r,[l]){const o={};l&1&&(o.initialValue=r[0]),n.$set(o)},i(r){i||(D(n.$$.fragment,r),i=!0)},o(r){tt(n.$$.fragment,r),i=!1},d(r){r&&V(e),G(n)}}}function ot(t,e,n){let{initialValue:i=0}=e;return t.$$set=r=>{"initialValue"in r&&n(0,i=r.initialValue)},[i]}class lt extends I{constructor(e){super(),H(this,e,ot,ut,O,{initialValue:0})}}return lt});
@fubits1
Copy link
Author

fubits1 commented Nov 14, 2022

instantiate with

const initialValue = 13;
const target = document.getElementById("mount-1");
target.innerHTML = "";

return new Counter({
  target: target,
  props: { initialValue: initialValue },
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment