snice 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,8 @@
1
+ (function(g,q){typeof exports=="object"&&typeof module<"u"?q(exports):typeof define=="function"&&define.amd?define(["exports"],q):(g=typeof globalThis<"u"?globalThis:g||self,q(g.DarkTS={}))})(this,function(g){"use strict";function q(){return globalThis.snice||(globalThis.snice={controllerRegistry:new Map,controllerIdCounter:0,symbols:new Map}),globalThis.snice}const A=q();function R(t){return A.symbols.has(t)||A.symbols.set(t,Symbol(t)),A.symbols.get(t)}const mt=R("is-controller-class"),lt=R("is-element-class"),G=R("channel-handlers"),F=R("ready-promise"),H=R("ready-resolve"),B=R("controller"),J=R("on-handlers"),V=R("controller-key"),Q=R("controller-name"),gt=R("controller-id"),et=R("controller-operations"),nt=R("native-controller"),S=R("cleanup"),rt=R("properties"),T=R("property-values");function vt(t,e){return function(n,o,c){return n[J]||(n[J]=[]),n[J].push({eventName:t,selector:e,methodName:o,method:c.value}),c}}function st(t,e){const n=t.constructor.prototype[J];if(n){t[S]||(t[S]={events:[],channels:[]});for(const o of n){const c=o.method.bind(t),h=u=>{try{return c(u)}catch(f){console.error(`Error in event handler ${o.methodName}:`,f)}};if(o.selector){const u=e.shadowRoot||e,f=d=>{const p=d.target;(p.matches&&p.matches(o.selector)||p.closest&&p.closest(o.selector))&&h(d)};u.addEventListener(o.eventName,f),t[S].events.push(()=>{u.removeEventListener(o.eventName,f)})}else e.addEventListener(o.eventName,h),t[S].events.push(()=>{e.removeEventListener(o.eventName,h)})}}}function W(t){var e;if((e=t[S])!=null&&e.events){for(const n of t[S].events)n();t[S].events=[]}}function bt(t,e){return function(n,o,c){const h=c.value;return c.value=function(...u){const f=h.apply(this,u);if(f instanceof Promise)return f.then(p=>{if(p===void 0&&(e==null?void 0:e.dispatchOnUndefined)===!1)return p;const _=new CustomEvent(t,{bubbles:!0,composed:!0,...e,detail:p});return this.dispatchEvent(_),p});if(f===void 0&&(e==null?void 0:e.dispatchOnUndefined)===!1)return f;const d=new CustomEvent(t,{bubbles:!0,composed:!0,...e,detail:f});return this.dispatchEvent(d),f},c}}function _t(t,e){return function(n,o,c){const h=c.value;return c.value=async function(...u){if(this instanceof HTMLElement){const f=(e==null?void 0:e.timeout)??100,d=h.apply(this,u),{value:p,done:_}=await d.next();if(_)return p;let b,s;const r=new Promise((k,O)=>{b=k,s=O});let i,l,a;const y=new Promise((k,O)=>{i=k,l=O,a=setTimeout(()=>{O(new Error(`Channel timeout after ${f}ms`))},f)}),P=`@channel:${t}`,m=new CustomEvent(P,{bubbles:(e==null?void 0:e.bubbles)!==void 0?e.bubbles:!0,cancelable:(e==null?void 0:e.cancelable)||!1,composed:!0,detail:{payload:p,timeout:{resolve:()=>{clearTimeout(a),i()},reject:l},data:{resolve:b,reject:s}}});this.dispatchEvent(m);try{await y;const k=await r,{value:O}=await d.next(k);return O}catch(k){try{await d.throw(k)}catch(O){throw O}}}else return h.apply(this,u)},n[G]||(n[G]=[]),n[G].push({channelName:t,methodName:o,method:h}),c}}function Et(t,e){const n=t.constructor.prototype[G];if(n){t[S]||(t[S]={events:[],channels:[]});for(const o of n){const c=o.method.bind(t),h=`@channel:${o.channelName}`,u=f=>{const{data:d,timeout:p,payload:_}=f.detail;f.preventDefault(),f.stopImmediatePropagation(),f.stopPropagation(),Promise.resolve(c(_)).then(b=>{p.resolve(),d.resolve(b)}).catch(b=>{p.resolve(),d.reject(b),console.error(`Error in channel handler ${o.methodName}:`,b)})};e.addEventListener(h,u),t[S].channels.push(()=>{e.removeEventListener(h,u)})}}}function wt(t){var e;if((e=t[S])!=null&&e.channels){for(const n of t[S].channels)n();t[S].channels=[]}}class Rt{constructor(){this.cleanupFns=new Map,this.pendingOperations=new Set}register(e,n){this.cleanupFns.set(e,n)}unregister(e){this.cleanupFns.delete(e)}async cleanup(){await Promise.all(this.pendingOperations);for(const e of this.cleanupFns.values())try{await e()}catch(n){console.error("Error during cleanup:",n)}this.cleanupFns.clear()}async runOperation(e){const n=e(),o=n.then(()=>{},()=>{});this.pendingOperations.add(o);try{const c=await n;return this.pendingOperations.delete(o),c}catch(c){throw this.pendingOperations.delete(o),c}}}function St(t){return function(e){return A.controllerRegistry.set(t,e),e.prototype[mt]=!0,e}}async function it(t,e){const n=t[V];if(t[Q]===e)return;n&&await D(t);const c=A.controllerRegistry.get(e);if(!c)throw new Error(`Controller "${e}" not found in registry`);const h=new c;A.controllerIdCounter+=1;const u=A.controllerIdCounter,f=new Rt;h[gt]=u,h.element=t,t[V]=h,t[Q]=e,t[et]=f,await t.ready,await f.runOperation(async()=>{await h.attach(t)}),st(h,t),Et(h,t),t.dispatchEvent(new CustomEvent("controller.attached",{detail:{name:e,controller:h}}))}async function D(t){const e=t[V],n=t[Q],o=t[et];e&&(o?await o.runOperation(async()=>{await e.detach(t)}):await e.detach(t),e.element=null,W(e),wt(e),o&&await o.cleanup(),delete t[V],delete t[Q],delete t[et],t.dispatchEvent(new CustomEvent("controller.detached",{detail:{name:n,controller:e}})))}function kt(t){return t[V]}function Ot(){if(globalThis.sniceNativeControllersInitialized)return;globalThis.sniceNativeControllersInitialized=!0;function t(n){if(!(n instanceof HTMLElement)||n.tagName.includes("-")||n[lt])return;const o=n.getAttribute("controller"),c=n[nt];o&&!c?(n[nt]=!0,n.ready||(n.ready=Promise.resolve()),it(n,o).catch(h=>{console.error(`Failed to attach controller "${o}" to native element:`,h)})):!o&&c&&(delete n[nt],D(n).catch(h=>{console.error("Failed to detach controller from native element:",h)}))}const e=new MutationObserver(n=>{for(const o of n)o.type==="attributes"&&o.attributeName==="controller"?t(o.target):o.type==="childList"&&o.addedNodes.forEach(c=>{c instanceof HTMLElement&&(t(c),c.querySelectorAll('[controller]:not([class*="-"])').forEach(t))})});document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>{document.querySelectorAll('[controller]:not([class*="-"])').forEach(t),e.observe(document.body,{attributes:!0,attributeFilter:["controller"],childList:!0,subtree:!0})}):(document.querySelectorAll('[controller]:not([class*="-"])').forEach(t),e.observe(document.body,{attributes:!0,attributeFilter:["controller"],childList:!0,subtree:!0})),globalThis.sniceNativeControllerObserver=e}function Lt(){const t=globalThis.sniceNativeControllerObserver;t&&(t.disconnect(),delete globalThis.sniceNativeControllerObserver,delete globalThis.sniceNativeControllersInitialized)}function ct(t){return function(e){e.prototype[lt]=!0;const n=e.prototype.connectedCallback,o=e.prototype.disconnectedCallback,c=e.prototype.attributeChangedCallback,h=e.observedAttributes||[];h.includes("controller")||h.push("controller"),Object.defineProperty(e,"observedAttributes",{get(){return h},configurable:!0}),Object.defineProperty(e.prototype,"ready",{get(){return this[F]||(this[F]=new Promise(u=>{this[H]=u})),this[F]},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"controller",{get(){return this[B]},set(u){const f=this[B];this[B]=u,u!==f&&u?it(this,u).catch(d=>{console.error(`Failed to attach controller "${u}":`,d)}):!u&&f&&D(this).catch(d=>{console.error("Failed to detach controller:",d)})},enumerable:!0,configurable:!0}),e.prototype.connectedCallback=async function(){this[F]||(this[F]=new Promise(u=>{this[H]=u}));try{W(this),this.shadowRoot||this.attachShadow({mode:"open"});let u="";if(this.html)try{const d=this.html(),p=d instanceof Promise?await d:d;p!==void 0&&(u+=p)}catch(d){console.error(`Error in html() method for ${this.tagName}:`,d)}if(this.css)try{const d=this.css(),p=d instanceof Promise?await d:d;if(p){const _=Array.isArray(p)?p.join(`
2
+ `):p;u+=`<style data-component-css>${_}</style>`}}catch(d){console.error(`Error in css() method for ${this.tagName}:`,d)}u&&(this.shadowRoot.innerHTML=u),n==null||n.call(this);const f=this.getAttribute("controller");f&&(this.controller=f),st(this,this)}finally{this[H]&&(this[H](),this[H]=null)}},e.prototype.disconnectedCallback=function(){o==null||o.call(this),this[B]&&D(this).catch(u=>{console.error("Failed to detach controller:",u)}),W(this)},e.prototype.attributeChangedCallback=function(u,f,d){c==null||c.call(this,u,f,d),u==="controller"&&(this.controller=d)},customElements.define(t,e)}}const Pt=ct;function Ct(t){return function(e,n){const o=e.constructor;o[rt]||(o[rt]=new Map),o[rt].set(n,t||{}),Object.defineProperty(e,n,{get(){return this[T]||(this[T]={}),this[T][n]},set(h){this[T]||(this[T]={});const u=this[T][n];u!==h&&(this[T][n]=h,t!=null&&t.reflect&&this.setAttribute&&(h==null||h===!1?this.removeAttribute(t.attribute||n):this.setAttribute(t.attribute||n,String(h))),this.requestUpdate&&this.requestUpdate(n,u))},enumerable:!0,configurable:!0})}}function At(t){return function(e,n){Object.defineProperty(e,n,{get(){const o=this.element||this;return o.shadowRoot?o.shadowRoot.querySelector(t):o.querySelector(t)},enumerable:!0,configurable:!0})}}function Tt(t){return function(e,n){Object.defineProperty(e,n,{get(){const o=this.element||this;return o.shadowRoot?o.shadowRoot.querySelectorAll(t):o.querySelectorAll(t)},enumerable:!0,configurable:!0})}}function Nt(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function It(t){throw new Error('Could not dynamically require "'+t+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var ht={};(function(t){var e=function(){var n=function(b,s,r,i){for(r=r||{},i=b.length;i--;r[b[i]]=s);return r},o=[1,9],c=[1,10],h=[1,11],u=[1,12],f=[5,11,12,13,14,15],d={trace:function(){},yy:{},symbols_:{error:2,root:3,expressions:4,EOF:5,expression:6,optional:7,literal:8,splat:9,param:10,"(":11,")":12,LITERAL:13,SPLAT:14,PARAM:15,$accept:0,$end:1},terminals_:{2:"error",5:"EOF",11:"(",12:")",13:"LITERAL",14:"SPLAT",15:"PARAM"},productions_:[0,[3,2],[3,1],[4,2],[4,1],[6,1],[6,1],[6,1],[6,1],[7,3],[8,1],[9,1],[10,1]],performAction:function(s,r,i,l,a,y,P){var m=y.length-1;switch(a){case 1:return new l.Root({},[y[m-1]]);case 2:return new l.Root({},[new l.Literal({value:""})]);case 3:this.$=new l.Concat({},[y[m-1],y[m]]);break;case 4:case 5:this.$=y[m];break;case 6:this.$=new l.Literal({value:y[m]});break;case 7:this.$=new l.Splat({name:y[m]});break;case 8:this.$=new l.Param({name:y[m]});break;case 9:this.$=new l.Optional({},[y[m-1]]);break;case 10:this.$=s;break;case 11:case 12:this.$=s.slice(1);break}},table:[{3:1,4:2,5:[1,3],6:4,7:5,8:6,9:7,10:8,11:o,13:c,14:h,15:u},{1:[3]},{5:[1,13],6:14,7:5,8:6,9:7,10:8,11:o,13:c,14:h,15:u},{1:[2,2]},n(f,[2,4]),n(f,[2,5]),n(f,[2,6]),n(f,[2,7]),n(f,[2,8]),{4:15,6:4,7:5,8:6,9:7,10:8,11:o,13:c,14:h,15:u},n(f,[2,10]),n(f,[2,11]),n(f,[2,12]),{1:[2,1]},n(f,[2,3]),{6:14,7:5,8:6,9:7,10:8,11:o,12:[1,16],13:c,14:h,15:u},n(f,[2,9])],defaultActions:{3:[2,2],13:[2,1]},parseError:function(s,r){if(r.recoverable)this.trace(s);else{let i=function(l,a){this.message=l,this.hash=a};throw i.prototype=Error,new i(s,r)}},parse:function(s){var r=this,i=[0],l=[null],a=[],y=this.table,P="",m=0,k=0,O=2,x=1,Y=a.slice.call(arguments,1),v=Object.create(this.lexer),E={yy:{}};for(var j in this.yy)Object.prototype.hasOwnProperty.call(this.yy,j)&&(E.yy[j]=this.yy[j]);v.setInput(s,E.yy),E.yy.lexer=v,E.yy.parser=this,typeof v.yylloc>"u"&&(v.yylloc={});var z=v.yylloc;a.push(z);var X=v.options&&v.options.ranges;typeof E.yy.parseError=="function"?this.parseError=E.yy.parseError:this.parseError=Object.getPrototypeOf(this).parseError;for(var Z=function(){var M;return M=v.lex()||x,typeof M!="number"&&(M=r.symbols_[M]||M),M},w,N,L,ot,$={},K,C,pt,tt;;){if(N=i[i.length-1],this.defaultActions[N]?L=this.defaultActions[N]:((w===null||typeof w>"u")&&(w=Z()),L=y[N]&&y[N][w]),typeof L>"u"||!L.length||!L[0]){var at="";tt=[];for(K in y[N])this.terminals_[K]&&K>O&&tt.push("'"+this.terminals_[K]+"'");v.showPosition?at="Parse error on line "+(m+1)+`:
3
+ `+v.showPosition()+`
4
+ Expecting `+tt.join(", ")+", got '"+(this.terminals_[w]||w)+"'":at="Parse error on line "+(m+1)+": Unexpected "+(w==x?"end of input":"'"+(this.terminals_[w]||w)+"'"),this.parseError(at,{text:v.match,token:this.terminals_[w]||w,line:v.yylineno,loc:z,expected:tt})}if(L[0]instanceof Array&&L.length>1)throw new Error("Parse Error: multiple actions possible at state: "+N+", token: "+w);switch(L[0]){case 1:i.push(w),l.push(v.yytext),a.push(v.yylloc),i.push(L[1]),w=null,k=v.yyleng,P=v.yytext,m=v.yylineno,z=v.yylloc;break;case 2:if(C=this.productions_[L[1]][1],$.$=l[l.length-C],$._$={first_line:a[a.length-(C||1)].first_line,last_line:a[a.length-1].last_line,first_column:a[a.length-(C||1)].first_column,last_column:a[a.length-1].last_column},X&&($._$.range=[a[a.length-(C||1)].range[0],a[a.length-1].range[1]]),ot=this.performAction.apply($,[P,k,m,E.yy,L[1],l,a].concat(Y)),typeof ot<"u")return ot;C&&(i=i.slice(0,-1*C*2),l=l.slice(0,-1*C),a=a.slice(0,-1*C)),i.push(this.productions_[L[1]][0]),l.push($.$),a.push($._$),pt=y[i[i.length-2]][i[i.length-1]],i.push(pt);break;case 3:return!0}}return!0}},p=function(){var b={EOF:1,parseError:function(r,i){if(this.yy.parser)this.yy.parser.parseError(r,i);else throw new Error(r)},setInput:function(s,r){return this.yy=r||this.yy||{},this._input=s,this._more=this._backtrack=this.done=!1,this.yylineno=this.yyleng=0,this.yytext=this.matched=this.match="",this.conditionStack=["INITIAL"],this.yylloc={first_line:1,first_column:0,last_line:1,last_column:0},this.options.ranges&&(this.yylloc.range=[0,0]),this.offset=0,this},input:function(){var s=this._input[0];this.yytext+=s,this.yyleng++,this.offset++,this.match+=s,this.matched+=s;var r=s.match(/(?:\r\n?|\n).*/g);return r?(this.yylineno++,this.yylloc.last_line++):this.yylloc.last_column++,this.options.ranges&&this.yylloc.range[1]++,this._input=this._input.slice(1),s},unput:function(s){var r=s.length,i=s.split(/(?:\r\n?|\n)/g);this._input=s+this._input,this.yytext=this.yytext.substr(0,this.yytext.length-r),this.offset-=r;var l=this.match.split(/(?:\r\n?|\n)/g);this.match=this.match.substr(0,this.match.length-1),this.matched=this.matched.substr(0,this.matched.length-1),i.length-1&&(this.yylineno-=i.length-1);var a=this.yylloc.range;return this.yylloc={first_line:this.yylloc.first_line,last_line:this.yylineno+1,first_column:this.yylloc.first_column,last_column:i?(i.length===l.length?this.yylloc.first_column:0)+l[l.length-i.length].length-i[0].length:this.yylloc.first_column-r},this.options.ranges&&(this.yylloc.range=[a[0],a[0]+this.yyleng-r]),this.yyleng=this.yytext.length,this},more:function(){return this._more=!0,this},reject:function(){if(this.options.backtrack_lexer)this._backtrack=!0;else return this.parseError("Lexical error on line "+(this.yylineno+1)+`. You can only invoke reject() in the lexer when the lexer is of the backtracking persuasion (options.backtrack_lexer = true).
5
+ `+this.showPosition(),{text:"",token:null,line:this.yylineno});return this},less:function(s){this.unput(this.match.slice(s))},pastInput:function(){var s=this.matched.substr(0,this.matched.length-this.match.length);return(s.length>20?"...":"")+s.substr(-20).replace(/\n/g,"")},upcomingInput:function(){var s=this.match;return s.length<20&&(s+=this._input.substr(0,20-s.length)),(s.substr(0,20)+(s.length>20?"...":"")).replace(/\n/g,"")},showPosition:function(){var s=this.pastInput(),r=new Array(s.length+1).join("-");return s+this.upcomingInput()+`
6
+ `+r+"^"},test_match:function(s,r){var i,l,a;if(this.options.backtrack_lexer&&(a={yylineno:this.yylineno,yylloc:{first_line:this.yylloc.first_line,last_line:this.last_line,first_column:this.yylloc.first_column,last_column:this.yylloc.last_column},yytext:this.yytext,match:this.match,matches:this.matches,matched:this.matched,yyleng:this.yyleng,offset:this.offset,_more:this._more,_input:this._input,yy:this.yy,conditionStack:this.conditionStack.slice(0),done:this.done},this.options.ranges&&(a.yylloc.range=this.yylloc.range.slice(0))),l=s[0].match(/(?:\r\n?|\n).*/g),l&&(this.yylineno+=l.length),this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+1,first_column:this.yylloc.last_column,last_column:l?l[l.length-1].length-l[l.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+s[0].length},this.yytext+=s[0],this.match+=s[0],this.matches=s,this.yyleng=this.yytext.length,this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]),this._more=!1,this._backtrack=!1,this._input=this._input.slice(s[0].length),this.matched+=s[0],i=this.performAction.call(this,this.yy,this,r,this.conditionStack[this.conditionStack.length-1]),this.done&&this._input&&(this.done=!1),i)return i;if(this._backtrack){for(var y in a)this[y]=a[y];return!1}return!1},next:function(){if(this.done)return this.EOF;this._input||(this.done=!0);var s,r,i,l;this._more||(this.yytext="",this.match="");for(var a=this._currentRules(),y=0;y<a.length;y++)if(i=this._input.match(this.rules[a[y]]),i&&(!r||i[0].length>r[0].length)){if(r=i,l=y,this.options.backtrack_lexer){if(s=this.test_match(i,a[y]),s!==!1)return s;if(this._backtrack){r=!1;continue}else return!1}else if(!this.options.flex)break}return r?(s=this.test_match(r,a[l]),s!==!1?s:!1):this._input===""?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+`. Unrecognized text.
7
+ `+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){var r=this.next();return r||this.lex()},begin:function(r){this.conditionStack.push(r)},popState:function(){var r=this.conditionStack.length-1;return r>0?this.conditionStack.pop():this.conditionStack[0]},_currentRules:function(){return this.conditionStack.length&&this.conditionStack[this.conditionStack.length-1]?this.conditions[this.conditionStack[this.conditionStack.length-1]].rules:this.conditions.INITIAL.rules},topState:function(r){return r=this.conditionStack.length-1-Math.abs(r||0),r>=0?this.conditionStack[r]:"INITIAL"},pushState:function(r){this.begin(r)},stateStackSize:function(){return this.conditionStack.length},options:{},performAction:function(r,i,l,a){switch(l){case 0:return"(";case 1:return")";case 2:return"SPLAT";case 3:return"PARAM";case 4:return"LITERAL";case 5:return"LITERAL";case 6:return"EOF"}},rules:[/^(?:\()/,/^(?:\))/,/^(?:\*+\w+)/,/^(?::+\w+)/,/^(?:[\w%\-~\n]+)/,/^(?:.)/,/^(?:$)/],conditions:{INITIAL:{rules:[0,1,2,3,4,5,6],inclusive:!0}}};return b}();d.lexer=p;function _(){this.yy={}}return _.prototype=d,d.Parser=_,new _}();typeof It<"u"&&(t.parser=e,t.Parser=e.Parser,t.parse=function(){return e.parse.apply(e,arguments)})})(ht);function I(t){return function(e,n){return{displayName:t,props:e,children:n||[]}}}var ut={Root:I("Root"),Concat:I("Concat"),Literal:I("Literal"),Splat:I("Splat"),Param:I("Param"),Optional:I("Optional")},ft=ht.parser;ft.yy=ut;var xt=ft,jt=Object.keys(ut);function $t(t){return jt.forEach(function(e){if(typeof t[e]>"u")throw new Error("No handler defined for "+e.displayName)}),{visit:function(e,n){return this.handlers[e.displayName].call(this,e,n)},handlers:t}}var yt=$t,Mt=yt,qt=/[\-{}\[\]+?.,\\\^$|#\s]/g;function dt(t){this.captures=t.captures,this.re=t.re}dt.prototype.match=function(t){var e=this.re.exec(t),n={};if(e)return this.captures.forEach(function(o,c){typeof e[c+1]>"u"?n[o]=void 0:n[o]=decodeURIComponent(e[c+1])}),n};var Ft=Mt({Concat:function(t){return t.children.reduce((function(e,n){var o=this.visit(n);return{re:e.re+o.re,captures:e.captures.concat(o.captures)}}).bind(this),{re:"",captures:[]})},Literal:function(t){return{re:t.props.value.replace(qt,"\\$&"),captures:[]}},Splat:function(t){return{re:"([^?]*?)",captures:[t.props.name]}},Param:function(t){return{re:"([^\\/\\?]+)",captures:[t.props.name]}},Optional:function(t){var e=this.visit(t.children[0]);return{re:"(?:"+e.re+")?",captures:e.captures}},Root:function(t){var e=this.visit(t.children[0]);return new dt({re:new RegExp("^"+e.re+"(?=\\?|$)"),captures:e.captures})}}),Ht=Ft,Vt=yt,Dt=Vt({Concat:function(t,e){var n=t.children.map((function(o){return this.visit(o,e)}).bind(this));return n.some(function(o){return o===!1})?!1:n.join("")},Literal:function(t){return decodeURI(t.props.value)},Splat:function(t,e){return e[t.props.name]?e[t.props.name]:!1},Param:function(t,e){return e[t.props.name]?e[t.props.name]:!1},Optional:function(t,e){var n=this.visit(t.children[0],e);return n||""},Root:function(t,e){e=e||{};var n=this.visit(t.children[0],e);return n?encodeURI(n):!1}}),Ut=Dt,Yt=xt,zt=Ht,Gt=Ut;U.prototype=Object.create(null),U.prototype.match=function(t){var e=zt.visit(this.ast),n=e.match(t);return n||!1},U.prototype.reverse=function(t){return Gt.visit(this.ast,t)};function U(t){var e;if(this?e=this:e=Object.create(U.prototype),typeof t>"u")throw new Error("A route spec is required");return e.spec=t,e.ast=Yt.parse(t),e}var Bt=U,Jt=Bt,Qt=Jt;const Wt=Nt(Qt);function Xt(t){const e=[];let n=!1,o,c,h=null;function u(s){return function(r){r.__transition=s.transition;const i=r.prototype.connectedCallback,l=r.prototype.disconnectedCallback;r.prototype.connectedCallback=function(){this.shadowRoot||this.attachShadow({mode:"open"});let a="";if(this.html){const y=this.html();y!==void 0&&(a+=y)}if(this.css){const y=this.css();if(y){const P=Array.isArray(y)?y.join(`
8
+ `):y;a+=`<style data-component-css>${P}</style>`}}a&&(this.shadowRoot.innerHTML=a),i==null||i.call(this),st(this,this)},r.prototype.disconnectedCallback=function(){l==null||l.call(this),W(this)},customElements.define(s.tag,r),s.routes.forEach(a=>f(a,s.tag))}}function f(s,r,i){e.push({route:new Wt(s),tag:r,transition:i}),n=!1,s==="/404"&&(o=r),s==="/"&&(c=r)}function d(){if(!document.querySelector(t.target))throw new Error(`Target element not found: ${t.target}`);switch(n||(e.sort((r,i)=>i.route.spec.length-r.route.spec.length),n=!0),t.routing_type){case"hash":window.addEventListener("hashchange",()=>{if(document.querySelector(t.target)){const r=p();_(r)}});break;case"pushstate":window.addEventListener("popstate",()=>{if(document.querySelector(t.target)){const r=p();_(r)}});break}const s=p();_(s)}function p(){switch(t.routing_type){case"hash":return window.location.hash.slice(1);case"pushstate":return window.location.pathname}}async function _(s){const r=document.querySelector(t.target);if(!r)throw new Error(`Target element not found: ${t.target}`);let i=null,l;if((s.trim()===""||s==="/")&&c){i=document.createElement(c);const a=customElements.get(c);l=a==null?void 0:a.__transition}else for(const a of e){const y=a.route.match(s);if(y!==!1){i=document.createElement(a.tag),Object.keys(y).forEach(m=>i.setAttribute(m,y[m])),l=a.transition;break}}if(!i)if(o){i=document.createElement(o);const a=customElements.get(o);l=a==null?void 0:a.__transition}else{const a=document.createElement("div");a.className="default-404",a.innerHTML="<h1>404</h1><p>Page not found</p>",i=a}l=l||t.transition,l&&h&&h.parentElement?await b(r,h,i,l):(r.innerHTML="",i&&r.appendChild(i)),h=i}async function b(s,r,i,l){const a=l.outDuration||300,y=l.inDuration||300,P=l.mode||"sequential",m=E=>{const j={};return E.split(";").forEach(z=>{const[X,Z]=z.split(":").map(w=>w.trim());X&&Z&&(j[X]=Z)}),j},k=l.out?m(l.out):{opacity:"0"},O={opacity:"0"},x=l.in?m(l.in):{opacity:"1"},Y=s.style,v=Y.position;Y.position="relative",r.style.position="absolute",r.style.top="0",r.style.left="0",r.style.width="100%",r.style.transition=`all ${a}ms ease-in-out`,i.style.position="absolute",i.style.top="0",i.style.left="0",i.style.width="100%",Object.assign(i.style,O),i.style.transition=`all ${y}ms ease-in-out`,s.appendChild(i),i.offsetHeight,P==="simultaneous"?(Object.assign(r.style,k),Object.assign(i.style,x),await new Promise(E=>setTimeout(E,Math.max(a,y)))):(Object.assign(r.style,k),await new Promise(E=>setTimeout(E,a)),Object.assign(i.style,x),await new Promise(E=>setTimeout(E,y))),r.remove(),i.style.position="",i.style.top="",i.style.left="",i.style.width="",i.style.transition="",Object.keys({...O,...x}).forEach(E=>{i.style[E]=""}),Y.position=v}return{page:u,initialize:d,navigate:_,register:f}}g.Router=Xt,g.attachController=it,g.channel=_t,g.cleanupNativeElementControllers=Lt,g.controller=St,g.customElement=Pt,g.detachController=D,g.dispatch=bt,g.element=ct,g.getController=kt,g.on=vt,g.property=Ct,g.query=At,g.queryAll=Tt,g.useNativeElementControllers=Ot,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})});
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "snice",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "description": "A TypeScript library",
6
+ "main": "dist/index.js",
7
+ "module": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "files": [
10
+ "dist"
11
+ ],
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
15
+ "scripts": {
16
+ "dev": "vite",
17
+ "build": "tsc && vite build",
18
+ "preview": "vite preview",
19
+ "test": "vitest run",
20
+ "test:watch": "vitest",
21
+ "test:ui": "vitest --ui",
22
+ "test:coverage": "vitest --coverage",
23
+ "release": "semantic-release --no-ci",
24
+ "release:dry": "semantic-release --dry-run --no-ci"
25
+ },
26
+ "dependencies": {
27
+ "route-parser": "^0.0.5"
28
+ },
29
+ "devDependencies": {
30
+ "@semantic-release/changelog": "^6.0.3",
31
+ "@semantic-release/commit-analyzer": "^13.0.1",
32
+ "@semantic-release/git": "^10.0.1",
33
+ "@semantic-release/gitlab": "^13.2.6",
34
+ "@semantic-release/npm": "^12.0.2",
35
+ "@semantic-release/release-notes-generator": "^14.0.3",
36
+ "@types/node": "^20.0.0",
37
+ "@types/route-parser": "^0.1.7",
38
+ "@vitest/ui": "^1.0.0",
39
+ "happy-dom": "^12.0.0",
40
+ "semantic-release": "^24.2.7",
41
+ "typescript": "^5.3.3",
42
+ "vite": "^5.0.10",
43
+ "vitest": "^1.0.0"
44
+ }
45
+ }