snice 1.14.3 → 2.1.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.
- package/bin/templates/base/tsconfig.json +5 -4
- package/components/accordion/demo.html +403 -0
- package/components/accordion/snice-accordion-item.css +85 -0
- package/components/accordion/snice-accordion-item.ts +226 -0
- package/components/accordion/snice-accordion.css +31 -0
- package/components/accordion/snice-accordion.ts +182 -0
- package/components/accordion/snice-accordion.types.ts +32 -0
- package/components/alert/demo.html +445 -0
- package/components/alert/snice-alert.css +195 -0
- package/components/alert/snice-alert.ts +141 -0
- package/components/alert/snice-alert.types.ts +12 -0
- package/components/avatar/demo.html +598 -0
- package/components/avatar/snice-avatar.css +131 -0
- package/components/avatar/snice-avatar.ts +136 -0
- package/components/avatar/snice-avatar.types.ts +13 -0
- package/components/badge/demo.html +523 -0
- package/components/badge/snice-badge.css +161 -0
- package/components/badge/snice-badge.ts +117 -0
- package/components/badge/snice-badge.types.ts +16 -0
- package/components/breadcrumbs/demo.html +404 -0
- package/components/breadcrumbs/snice-breadcrumbs.css +133 -0
- package/components/breadcrumbs/snice-breadcrumbs.ts +191 -0
- package/components/breadcrumbs/snice-breadcrumbs.types.ts +26 -0
- package/components/breadcrumbs/snice-crumb.ts +26 -0
- package/components/button/demo.html +42 -0
- package/components/button/snice-button.css +230 -0
- package/components/button/snice-button.ts +169 -0
- package/components/button/snice-button.types.ts +25 -0
- package/components/card/demo.html +525 -0
- package/components/card/snice-card.css +140 -0
- package/components/card/snice-card.ts +102 -0
- package/components/card/snice-card.types.ts +10 -0
- package/components/checkbox/demo.html +253 -0
- package/components/checkbox/snice-checkbox.css +164 -0
- package/components/checkbox/snice-checkbox.ts +223 -0
- package/components/checkbox/snice-checkbox.types.ts +22 -0
- package/components/chip/demo.html +383 -0
- package/components/chip/snice-chip.css +195 -0
- package/components/chip/snice-chip.ts +139 -0
- package/components/chip/snice-chip.types.ts +15 -0
- package/components/date-picker/README.md +233 -0
- package/components/date-picker/demo.html +191 -0
- package/components/date-picker/snice-date-picker.css +330 -0
- package/components/date-picker/snice-date-picker.ts +777 -0
- package/components/date-picker/snice-date-picker.types.ts +83 -0
- package/components/divider/demo.html +233 -0
- package/components/divider/snice-divider.css +155 -0
- package/components/divider/snice-divider.ts +69 -0
- package/components/divider/snice-divider.types.ts +15 -0
- package/components/drawer/demo.html +328 -0
- package/components/drawer/snice-drawer.css +476 -0
- package/components/drawer/snice-drawer.ts +287 -0
- package/components/drawer/snice-drawer.types.ts +17 -0
- package/components/global.d.ts +14 -0
- package/components/input/demo.html +303 -0
- package/components/input/snice-input.css +257 -0
- package/components/input/snice-input.ts +442 -0
- package/components/input/snice-input.types.ts +59 -0
- package/components/input/test.html +77 -0
- package/components/layout/README.md +260 -0
- package/components/layout/demo.html +538 -0
- package/components/layout/snice-layout-blog.css +129 -0
- package/components/layout/snice-layout-blog.ts +48 -0
- package/components/layout/snice-layout-card.css +104 -0
- package/components/layout/snice-layout-card.ts +35 -0
- package/components/layout/snice-layout-centered.css +51 -0
- package/components/layout/snice-layout-centered.ts +22 -0
- package/components/layout/snice-layout-dashboard.css +98 -0
- package/components/layout/snice-layout-dashboard.ts +45 -0
- package/components/layout/snice-layout-fullscreen.css +72 -0
- package/components/layout/snice-layout-fullscreen.ts +34 -0
- package/components/layout/snice-layout-landing.css +92 -0
- package/components/layout/snice-layout-landing.ts +47 -0
- package/components/layout/snice-layout-minimal.css +16 -0
- package/components/layout/snice-layout-minimal.ts +19 -0
- package/components/layout/snice-layout-sidebar.css +117 -0
- package/components/layout/snice-layout-sidebar.ts +48 -0
- package/components/layout/snice-layout-split.css +103 -0
- package/components/layout/snice-layout-split.ts +29 -0
- package/components/layout/snice-layout.css +72 -0
- package/components/layout/snice-layout.ts +35 -0
- package/components/layout/snice-layout.types.ts +5 -0
- package/components/login/demo-auth-controller.ts +185 -0
- package/components/login/demo.html +470 -0
- package/components/login/snice-login.css +204 -0
- package/components/login/snice-login.ts +337 -0
- package/components/login/snice-login.types.ts +34 -0
- package/components/modal/demo.html +291 -0
- package/components/modal/snice-modal.css +203 -0
- package/components/modal/snice-modal.ts +233 -0
- package/components/modal/snice-modal.types.ts +21 -0
- package/components/pagination/demo.html +395 -0
- package/components/pagination/snice-pagination.ts +333 -0
- package/components/pagination/snice-pagination.types.ts +21 -0
- package/components/progress/demo.html +510 -0
- package/components/progress/snice-progress.css +267 -0
- package/components/progress/snice-progress.ts +247 -0
- package/components/progress/snice-progress.types.ts +19 -0
- package/components/radio/demo.html +287 -0
- package/components/radio/snice-radio.css +171 -0
- package/components/radio/snice-radio.ts +218 -0
- package/components/radio/snice-radio.types.ts +21 -0
- package/components/select/demo.html +511 -0
- package/components/select/snice-option.ts +52 -0
- package/components/select/snice-option.types.ts +14 -0
- package/components/select/snice-select.css +392 -0
- package/components/select/snice-select.ts +796 -0
- package/components/select/snice-select.types.ts +55 -0
- package/components/skeleton/demo.html +514 -0
- package/components/skeleton/snice-skeleton.css +109 -0
- package/components/skeleton/snice-skeleton.ts +126 -0
- package/components/skeleton/snice-skeleton.types.ts +11 -0
- package/components/switch/demo.html +284 -0
- package/components/switch/snice-switch.css +221 -0
- package/components/switch/snice-switch.ts +229 -0
- package/components/switch/snice-switch.types.ts +23 -0
- package/components/symbols.ts +23 -0
- package/components/table/demo-table-controller.ts +100 -0
- package/components/table/demo.html +480 -0
- package/components/table/snice-cell-boolean.ts +112 -0
- package/components/table/snice-cell-date.ts +210 -0
- package/components/table/snice-cell-duration.ts +91 -0
- package/components/table/snice-cell-filesize.ts +90 -0
- package/components/table/snice-cell-number.ts +165 -0
- package/components/table/snice-cell-progress.ts +83 -0
- package/components/table/snice-cell-rating.ts +82 -0
- package/components/table/snice-cell-sparkline.ts +253 -0
- package/components/table/snice-cell-text.ts +125 -0
- package/components/table/snice-cell.css +296 -0
- package/components/table/snice-cell.ts +473 -0
- package/components/table/snice-column.ts +353 -0
- package/components/table/snice-header.css +243 -0
- package/components/table/snice-header.ts +261 -0
- package/components/table/snice-progress.ts +66 -0
- package/components/table/snice-rating.ts +45 -0
- package/components/table/snice-row.css +255 -0
- package/components/table/snice-row.ts +331 -0
- package/components/table/snice-table.css +241 -0
- package/components/table/snice-table.ts +737 -0
- package/components/table/snice-table.types.ts +158 -0
- package/components/tabs/demo.html +487 -0
- package/components/tabs/snice-tab-panel.css +264 -0
- package/components/tabs/snice-tab-panel.ts +47 -0
- package/components/tabs/snice-tab.css +96 -0
- package/components/tabs/snice-tab.ts +65 -0
- package/components/tabs/snice-tabs.css +189 -0
- package/components/tabs/snice-tabs.ts +332 -0
- package/components/tabs/snice-tabs.types.ts +28 -0
- package/components/theme/theme.css +234 -0
- package/components/toast/demo.html +329 -0
- package/components/toast/snice-toast-container.ts +256 -0
- package/components/toast/snice-toast.css +213 -0
- package/components/toast/snice-toast.ts +276 -0
- package/components/toast/snice-toast.types.ts +35 -0
- package/components/tooltip/demo.html +350 -0
- package/components/tooltip/snice-tooltip-portal.css +79 -0
- package/components/tooltip/snice-tooltip.css +117 -0
- package/components/tooltip/snice-tooltip.ts +612 -0
- package/components/tooltip/snice-tooltip.types.ts +32 -0
- package/components/transitions.ts +94 -0
- package/components/tsconfig.json +18 -0
- package/dist/index.cjs +441 -329
- package/dist/index.cjs.map +1 -1
- package/dist/index.cjs.min.map +1 -1
- package/dist/index.esm.js +441 -329
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +3 -3
- package/dist/index.esm.min.js.map +1 -1
- package/dist/index.iife.js +441 -329
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +3 -3
- package/dist/index.iife.min.js.map +1 -1
- package/dist/symbols.esm.js +1 -1
- package/dist/transitions.esm.js +1 -1
- package/dist/types/controller.d.ts +1 -1
- package/dist/types/element.d.ts +10 -10
- package/dist/types/events.d.ts +2 -2
- package/dist/types/index.d.ts +1 -1
- package/dist/types/observe.d.ts +1 -1
- package/dist/types/request-response.d.ts +2 -3
- package/dist/types/router.d.ts +1 -1
- package/package.json +9 -3
- package/dist/index.cjs.min +0 -15
- package/dist/symbols.cjs +0 -103
- package/dist/transitions.cjs +0 -219
package/dist/index.cjs.min
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* snice v1.14.2
|
|
3
|
-
* Imperative TypeScript framework for building vanilla web components with decorators, routing, and controllers. No virtual DOM, no build complexity.
|
|
4
|
-
* (c) 2024
|
|
5
|
-
* Released under the MIT License.
|
|
6
|
-
*/
|
|
7
|
-
"use strict";const e=(globalThis.snice||(globalThis.snice={controllerRegistry:new Map,controllerIdCounter:0,symbols:new Map}),globalThis.snice);function t(t){return e.symbols.has(t)||e.symbols.set(t,Symbol(t)),e.symbols.get(t)}const n=t("is-controller-class"),o=t("is-controller-instance"),r=t("is-element-class"),s=t("channel-handlers"),i=t("ready-promise"),a=t("ready-resolve"),l=t("controller"),c=t("on-handlers"),u=t("controller-key"),h=t("controller-name"),p=t("controller-id"),d=t("controller-operations"),f=t("native-controller"),m=t("cleanup"),y=t("properties"),g=t("property-values"),b=t("properties-initialized"),v=t("property-watchers"),w=t("explicitly-set-properties"),E=t("router-context");t("current-page-marker");const S=t("context-request-handler"),x=t("page-transition"),A=t("created-at"),O=t("ready-handlers"),T=t("dispose-handlers"),N=t("observers"),C=t("parts"),P=t("part-timers");function L(e,t){const n=e.constructor.prototype[c];if(n){e[m]||(e[m]={events:[],channels:[]});for(const o of n){const n=o.method.bind(e),r=o.options||{},[s,i]=o.eventName.split(":"),a=e=>!i||"keydown"!==s&&"keyup"!==s&&"keypress"!==s?e:t=>{const n=t,o=e=>"Space"===e?" ":e;if(i.startsWith("~")){const r=o(i.slice(1));return void(n.key===r&&e(t))}if(i.includes("+")){const r=i.split("+"),s=o(r[r.length-1]),a=r.slice(0,-1);if(n.key!==s)return;const l=new Set(a.map(e=>e.toLowerCase())),c=l.has("ctrl"),u=l.has("shift"),h=l.has("alt"),p=l.has("meta")||l.has("cmd");n.ctrlKey===c&&n.shiftKey===u&&n.altKey===h&&n.metaKey===p&&e(t)}else{const r=o(i);n.key!==r||n.ctrlKey||n.shiftKey||n.altKey||n.metaKey||e(t)}},l=(e=>{if(r.debounce){let t;return function(...n){clearTimeout(t),t=setTimeout(()=>e.apply(this,n),r.debounce)}}if(r.throttle){let t,n=0;return function(...o){const s=Date.now(),i=r.throttle-(s-n);i<=0?(clearTimeout(t),n=s,e.apply(this,o)):t||(t=setTimeout(()=>{n=Date.now(),t=null,e.apply(this,o)},i))}}return e})(n),c=a(e=>{try{return r.preventDefault&&e.preventDefault(),r.stopPropagation&&e.stopPropagation(),l(e)}catch(e){console.error(`Error in event handler ${o.methodName}:`,e)}});if(o.selector){const n=t.shadowRoot||t,i=e=>{const t=e.target;let n=!1;if(t.matches&&t.matches(o.selector))n=!0;else if(t.closest){t.closest(o.selector)&&(n=!0)}n&&(r.preventDefault&&e.preventDefault(),r.stopPropagation&&(e.stopPropagation(),e.stopImmediatePropagation()),c(e))},a={capture:r.capture||!1,once:r.once||!1,passive:r.passive||!1};n.addEventListener(s,i,a),e[m].events.push(()=>{n.removeEventListener(s,i,a)})}else{const n={capture:r.capture||!1,once:r.once||!1,passive:r.passive||!1};t.addEventListener(s,c,n),e[m].events.push(()=>{t.removeEventListener(s,c,n)})}}}}function I(e){if(e[m]?.events){for(const t of e[m].events)t();e[m].events=[]}}const k=new Map,R=new WeakMap;function q(e,t){const n=e.constructor.prototype[N];if(n&&Array.isArray(n)&&0!==n.length){e[m]?e[m].observers||(e[m].observers=[]):e[m]={events:[],channels:[],observers:[]};for(const o of n){const n=o.method.bind(e),r=o.options?.throttle?F(n,o.options.throttle):n;switch(o.type){case"intersection":$(e,t,o,r);break;case"resize":D(e,t,o,r);break;case"media":M(e,t,o,r);break;case"mutation":j(e,t,o,r);break;default:console.warn(`Unknown observer type: ${o.type}`)}}}}function $(e,t,n,o){const r={threshold:n.options?.threshold??0,rootMargin:n.options?.rootMargin??"0px",root:n.options?.root??null},s=JSON.stringify(r),i=e=>{for(const t of e)try{!1===o(t)&&a&&a.unobserve(t.target)}catch(e){console.error(`Error in intersection observer ${n.methodName}:`,e)}};if("undefined"==typeof IntersectionObserver)return void console.warn("IntersectionObserver is not available in this environment");let a=R.get({instance:e,options:s});a||(a=new IntersectionObserver(i,r),R.set({instance:e,options:s},a));const l=n.selector?Array.from(t.shadowRoot?.querySelectorAll(n.selector)||[]):[t];l.forEach(e=>a.observe(e)),e[m].observers.push(()=>{l.forEach(e=>a.unobserve(e)),0===a.takeRecords().length&&a.disconnect()})}function D(e,t,n,o){const r=n.options?.box||"content-box";if("undefined"==typeof ResizeObserver)return void console.warn("ResizeObserver is not available in this environment");const s=new ResizeObserver(e=>{for(const t of e)try{o(t)}catch(e){console.error(`Error in resize observer ${n.methodName}:`,e)}});(n.selector?Array.from(t.shadowRoot?.querySelectorAll(n.selector)||[]):[t]).forEach(e=>{s.observe(e,{box:r})}),e[m].observers.push(()=>{s.disconnect()})}function M(e,t,n,o){const r=n.target;if(!r)return void console.warn("Media query observer requires a query string");let s=k.get(r);if(!s)try{s=window.matchMedia(r),k.set(r,s)}catch(e){return void console.error(`Invalid media query: ${r}`,e)}const i=e=>{try{o(e.matches)}catch(e){console.error(`Error in media query observer ${n.methodName}:`,e)}};i(s);const a=e=>i(e);s.addEventListener?(s.addEventListener("change",a),e[m].observers.push(()=>{s.removeEventListener("change",a)})):(s.addListener(a),e[m].observers.push(()=>{s.removeListener(a)}))}function j(e,t,n,r){const s=n.target.split(":"),i=s[0]||"childList",a=s[1],l={};switch(i){case"childList":l.childList=!0;break;case"attributes":l.attributes=!0,a&&(l.attributeFilter=[a]);break;default:return void console.warn(`Unknown mutation type: ${i}`)}n.options?.subtree&&(l.subtree=!0,n.options.maxDepth&&console.warn("maxDepth is set but requires custom implementation"));const c=new MutationObserver(e=>{try{if(n.options?.maxDepth&&n.options.subtree){const o=n.options.maxDepth,s=e.filter(e=>{let n=0,r=e.target;const s=t.shadowRoot||t;for(;r&&r!==s&&n<o;)r=r.parentNode,n++;return n<o});s.length>0&&r(s)}else r(e)}catch(e){console.error(`Error in mutation observer ${n.methodName}:`,e)}}),u=!0===e[o];(n.selector?Array.from(t.shadowRoot?.querySelectorAll(n.selector)||[]):u&&t.shadowRoot?[t.shadowRoot]:[t]).forEach(e=>{c.observe(e,l)}),e[m].observers.push(()=>{c.disconnect()})}function F(e,t){let n=0,o=null;return function(...r){const s=Date.now(),i=t-(s-n);if(i<=0)return o&&(clearTimeout(o),o=null),n=s,e.apply(this,r);o||(o=setTimeout(()=>{n=Date.now(),o=null,e.apply(this,r)},i))}}function U(e){if(e[m]?.observers){for(const t of e[m].observers)t();e[m].observers=[]}}function z(e,t){const n=e.constructor.prototype[s];if(n){e[m]||(e[m]={events:[],channels:[]});for(const o of n){const n=o.method.bind(e),r=`@request/${o.channelName}`;let s,i,a=0;const l=(e=>o.options?.debounce?(...t)=>new Promise((n,r)=>{clearTimeout(s),s=setTimeout(async()=>{try{const o=await e(...t);n(o)}catch(e){r(e)}},o.options.debounce)}):o.options?.throttle?(...t)=>{const n=Date.now(),r=o.options.throttle-(n-a);return r<=0?(clearTimeout(i),a=n,e(...t)):i?Promise.resolve(void 0):new Promise((n,o)=>{i=setTimeout(async()=>{a=Date.now(),i=null;try{const o=await e(...t);n(o)}catch(e){o(e)}},r)})}:e)(n),c=e=>{const{data:t,discovery:n,payload:r}=e.detail;e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation(),n.resolve(),Promise.resolve(l(r)).then(e=>{t.resolve(e)}).catch(e=>{t.reject(e),console.error(`Error in response handler ${o.methodName}:`,e)})};t.addEventListener(r,c),e[m].channels.push(()=>{t.removeEventListener(r,c)})}}}function H(e){if(e[m]?.channels){for(const t of e[m].channels)t();e[m].channels=[]}}class B{constructor(){this.cleanupFns=new Map,this.pendingOperations=new Set}register(e,t){this.cleanupFns.set(e,t)}unregister(e){this.cleanupFns.delete(e)}async cleanup(){await Promise.all(this.pendingOperations);for(const e of this.cleanupFns.values())try{await e()}catch(e){console.error("Error during cleanup:",e)}this.cleanupFns.clear()}async runOperation(e){const t=e(),n=t.then(()=>{},()=>{});this.pendingOperations.add(n);try{const e=await t;return this.pendingOperations.delete(n),e}catch(e){throw this.pendingOperations.delete(n),e}}}async function G(t,n){const r=t[u],s=t[h],i=t[f];if(void 0!==i&&i!==n)return;if(s===n&&r)return;r&&await K(t);const a=e.controllerRegistry.get(n);if(!a)throw new Error(`Controller "${n}" not found in registry`);const l=new a;e.controllerIdCounter+=1;const c=e.controllerIdCounter,m=new B;l[o]=!0,l[p]=c,l.element=t;const y=t[E];void 0!==y&&(l[E]=y),t[u]=l,t[h]=n,t[d]=m,await t.ready,await m.runOperation(async()=>{await l.attach(t)}),L(l,t),q(l,t),z(l,t),t.dispatchEvent(new CustomEvent("@snice/controller-attached",{detail:{name:n,controller:l}}))}async function K(e){const t=e[u],n=e[h],o=e[d];t&&(o?await o.runOperation(async()=>{await t.detach(e)}):await t.detach(e),t.element=null,I(t),U(t),H(t),o&&await o.cleanup(),delete t[E],delete e[u],delete e[h],delete e[d],e.dispatchEvent(new CustomEvent("@snice/controller-detached",{detail:{name:n,controller:t}})))}function W(e){e.prototype[r]=!0;const t=e.prototype.connectedCallback,n=e.prototype.disconnectedCallback,o=e.prototype.attributeChangedCallback,s=e.observedAttributes||[];s.includes("controller")||s.push("controller");const c=e[y];if(c)for(const[e,t]of c){const n="string"==typeof t.attribute?t.attribute:e.toLowerCase();s.includes(n)||s.push(n)}Object.defineProperty(e,"observedAttributes",{get:()=>s,configurable:!0}),Object.defineProperty(e.prototype,"ready",{get(){return this[i]||(this[i]=new Promise(e=>{this[a]=e})),this[i]},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"controller",{get(){return this[l]},set(e){const t=this[l];this[l]=e,e!==t&&e?G(this,e).catch(t=>{console.error(`Failed to attach controller "${e}":`,t)}):!e&&t&&K(this).catch(e=>{console.error("Failed to detach controller:",e)})},enumerable:!0,configurable:!0}),e.prototype.connectedCallback=async function(){this[i]||(this[i]=new Promise(e=>{this[a]=e}));try{const n=e[y];if(n)for(const[e,t]of n)if(this.hasAttribute(e)){const n=this.getAttribute(e);switch(this[w]||(this[w]=new Set),this[w].add(e),t.type){case Boolean:this[e]=null!==n&&"false"!==n;break;case Number:this[e]=Number(n);break;case String:this[e]=n;break;case Date:this[e]=n?new Date(n):null;break;case BigInt:n&&n.endsWith("n")?this[e]=BigInt(n.slice(0,-1)):this[e]=n?BigInt(n):null;break;case _:this[e]=_.parse(n);break;default:this[e]=n}}if(this[b]=!0,n&&this[w])for(const[e,t]of n)if(t.reflect&&this[w].has(e)&&e in this[g]){const n=this[g][e],o="string"==typeof t.attribute?t.attribute:e.toLowerCase();if(null!=n&&!1!==n&&(t.type!==_||!Array.isArray(n)||0!==n.length)){let e;e=n instanceof Date?n.toISOString():"bigint"==typeof n?n.toString()+"n":t.type===_&&Array.isArray(n)?_.serialize(n):String(n),this.setAttribute(o,e)}}I(this),this.shadowRoot||this.attachShadow({mode:"open"});let o="";if(this.html)try{const e=this.html(),t=e instanceof Promise?await e:e;void 0!==t&&(o+=t)}catch(e){console.error(`Error in html() method for ${this.tagName}:`,e)}if(this.css)try{const e=this.css(),t=e instanceof Promise?await e:e;if(t){o+=`<style data-component-css>${Array.isArray(t)?t.join("\n"):t}</style>`}}catch(e){console.error(`Error in css() method for ${this.tagName}:`,e)}o&&(this.shadowRoot.innerHTML=o);const r=e[C];if(r&&this.shadowRoot)for(const[e,t]of r)try{const n=this.shadowRoot.querySelector(`[part="${e}"]`);if(n){const e=t.method.call(this),o=e instanceof Promise?await e:e;void 0!==o&&(n.innerHTML=o)}}catch(t){console.error(`Error rendering @part('${e}') in ${this.tagName}:`,t)}t&&t.call(this);const s=this.getAttribute("controller");s&&(this.controller=s),L(this,this),z(this,this);try{q(this,this)}catch(e){console.error(`Error setting up observers for ${this.tagName}:`,e)}const i=e[O];if(i)for(const e of i)try{await e.method.call(this)}catch(t){console.error(`Error in @ready handler ${e.methodName}:`,t)}}finally{this[a]&&(this[a](),this[a]=null)}},e.prototype.disconnectedCallback=async function(){const t=e[T];if(t)for(const e of t)try{await e.method.call(this)}catch(t){console.error(`Error in @dispose handler ${e.methodName}:`,t)}n&&n.call(this),this[l]&&K(this).catch(e=>{console.error("Failed to detach controller:",e)}),I(this),H(this),U(this)},e.prototype.attributeChangedCallback=function(t,n,r){if(o?.call(this,t,n,r),"controller"===t)this.controller=r;else{const n=e[y];if(n)for(const[o,s]of n){if(("string"==typeof s.attribute?s.attribute:o.toLowerCase())===t){const t=this[g]?.[o];let n;if(n=s.type===Boolean?null!==r&&"false"!==r:s.type===Number?Number(r):s.type===Date?r?new Date(r):null:s.type===BigInt?r&&r.endsWith("n")?BigInt(r.slice(0,-1)):r?BigInt(r):null:s.type===_?_.parse(r):"number"==typeof t&&null!==r?Number(r):r,t!==n){this[w]||(this[w]=new Set),this[w].add(o),this[g]||(this[g]={}),this[g][o]=n;const r=e[v];if(r){if(r.has(o)){const e=r.get(o);for(const r of e)try{r.method.call(this,t,n,o)}catch(e){console.error(`Error in @watch('${o}') method ${r.methodName}:`,e)}}if(r.has("*")){const e=r.get("*");for(const r of e)try{r.method.call(this,t,n,o)}catch(e){console.error(`Error in @watch('*') method ${r.methodName}:`,e)}}}}break}}}}}class _{static serialize(e){return Array.isArray(e)?e.map(e=>{if("string"==typeof e){if(e.includes(_.SEPARATOR))throw new Error(`SimpleArray strings cannot contain the character "${_.SEPARATOR}" (U+FF0C)`);return e}if("number"==typeof e||"boolean"==typeof e)return String(e);throw new Error("SimpleArray only supports string, number, and boolean types. Got: "+typeof e)}).join(_.SEPARATOR):""}static parse(e){return null==e||""===e?[]:e.split(_.SEPARATOR).map(e=>{if(/^-?\d+\.?\d*$/.test(e)){const t=Number(e);if(!isNaN(t))return t}return"true"===e||"false"!==e&&e})}}_.SEPARATOR=",";
|
|
8
|
-
/*!
|
|
9
|
-
* pica-route v1.1.2
|
|
10
|
-
* A pure URL pattern matching library compatible with route-parser API
|
|
11
|
-
* (c) 2024
|
|
12
|
-
* Released under the MIT License.
|
|
13
|
-
*/
|
|
14
|
-
class Q{constructor(e){this.parsed=this.parsePattern(e)}get spec(){return this.parsed.template}parsePattern(e){let t=e,n="",o=!1;const r=e.indexOf("?");return-1!==r&&(t=e.slice(0,r),n=e.slice(r+1),t.endsWith("(")&&n.endsWith(")")&&(o=!0,t=t.slice(0,-1),n=n.slice(0,-1))),{pathSegments:this.parseSegments(t),querySegments:n?this.parseQuerySegments(n):[],queryOptional:o,template:e}}parseSegments(e){const t=[];let n=0;for(;n<e.length;){switch(e[n]){case"(":const{segments:o,endIndex:r}=this.parseOptionalGroup(e,n);t.push({type:"optional",segments:o}),n=r+1;break;case":":const{name:s,endIndex:i}=this.parseIdentifier(e,n+1);t.push({type:"param",name:s}),n=i;break;case"*":const{name:a,endIndex:l}=this.parseIdentifier(e,n+1);t.push({type:"splat",name:a}),n=l;break;default:const{value:c,endIndex:u}=this.parseLiteral(e,n);c&&t.push({type:"literal",value:c}),n=u}}return t}parseOptionalGroup(e,t){let n=1,o=t+1;for(;o<e.length&&n>0;)"("===e[o]&&n++,")"===e[o]&&n--,o++;const r=e.slice(t+1,o-1);return{segments:this.parseSegments(r),endIndex:o-1}}parseIdentifier(e,t){let n=t;for(;n<e.length&&/[\w-]/.test(e[n]);)n++;return{name:e.slice(t,n),endIndex:n}}parseLiteral(e,t){let n=t;for(;n<e.length&&!"(:*(".includes(e[n]);)n++;return{value:e.slice(t,n),endIndex:n}}parseQuerySegments(e){let t=e;t.startsWith("(")&&t.endsWith(")")&&(t=t.slice(1,-1));const n=[];let o=0;for(;o<t.length;)if(":"===t[o]){const{name:e,endIndex:r}=this.parseIdentifier(t,o+1);n.push({type:"param",name:e}),o=r}else{const{value:e,endIndex:r}=this.parseQueryLiteral(t,o);e&&n.push({type:"literal",value:e}),o=r}return n}parseQueryLiteral(e,t){let n=t;for(;n<e.length&&":"!==e[n];)n++;return{value:e.slice(t,n),endIndex:n}}getAllParamNames(){const e=new Set,t=n=>{for(const o of n)switch(o.type){case"param":case"splat":e.add(o.name);break;case"optional":t(o.segments)}};return t(this.parsed.pathSegments),t(this.parsed.querySegments),Array.from(e)}canMatchRemainingSegments(e,t,n){let o=t;for(const t of n)if("literal"===t.type){const n=e.indexOf(t.value,o);if(-1===n)return!1;o=n+t.value.length}return!0}match(e){const[t,n]=e.split("?"),o=this.matchPath(t,this.parsed.pathSegments);if(!1===o)return!1;const r=this.matchQuery(n||"",this.parsed.querySegments);if(!1===r)return!1;const s=this.getAllParamNames(),i={};for(const e of s)i[e]=void 0;return Object.assign(i,o,r),i}matchPath(e,t){const n={};let o=0;for(let r=0;r<t.length;r++){const s=t[r],i=t.slice(r+1),a=this.matchSegment(e,o,s,i);if(!1===a)return!1;Object.assign(n,a.params),o=a.nextIndex}return!(o<e.length)&&n}matchSegment(e,t,n,o=[]){switch(n.type){case"literal":return e.slice(t,t+n.value.length)===n.value&&{params:{},nextIndex:t+n.value.length};case"param":{let r=t;const s=o[0];let i,a=["/","?"];if(s&&"literal"===s.type){const n=s.value,o=e.indexOf(n,t);if(-1===o)return!1;r=o}else for(;r<e.length&&!a.includes(e[r]);)r++;if(r===t)return!1;try{i=decodeURIComponent(e.slice(t,r))}catch(n){i=e.slice(t,r)}return!(r<e.length&&"?"===e[r]&&o.length>0)&&{params:{[n.name]:i},nextIndex:r}}case"splat":{let r=e.length;const s=o[0];if(s)switch(s.type){case"literal":if("."===s.value){const n=e.indexOf(".",t);-1!==n&&(r=n)}else{const n=e.lastIndexOf(s.value);-1!==n&&n>=t&&(r=n)}break;case"param":let n=-1;for(let o=e.length-1;o>=t;o--)if("/"===e[o]){n=o;break}-1!==n&&(r=n);break;case"splat":let o=-1;for(let n=e.length-1;n>t;n--)if("/"===e[n]){o=n+1;break}if(-1!==o)r=o;else{const n=e.slice(t).split("/").filter(e=>e);r=n.length>1?t+n.slice(0,-1).join("/").length+1:t}break;case"optional":const i=e=>{for(const t of e){if("literal"===t.type)return t.value;if("optional"===t.type){const e=i(t.segments);if(e)return e}}return null},a=i(s.segments);if(a){const n=e.lastIndexOf(a);-1!==n&&n>=t&&(r=n)}}const i=e.indexOf("?",t);let a;-1!==i&&i<r&&(r=i);try{a=decodeURIComponent(e.slice(t,r))}catch(n){a=e.slice(t,r)}return{params:{[n.name]:a},nextIndex:r}}case"optional":{let r=t,s={},i=!0;for(let t=0;t<n.segments.length;t++){const o=n.segments[t],a=n.segments.slice(t+1),l=this.matchSegment(e,r,o,a);if(!1===l){i=!1;break}Object.assign(s,l.params),r=l.nextIndex}if(i){if(this.canMatchRemainingSegments(e,r,o))return{params:s,nextIndex:r}}return{params:{},nextIndex:t}}default:return!1}}findNextLiteral(e){for(const t of e){if("literal"===t.type)return t;if("optional"===t.type){const e=this.findNextLiteral(t.segments);if(e)return e}}return null}matchQuery(e,t){if(0===t.length)return{};const n={};let o=0;for(const r of t)switch(r.type){case"literal":if(e.slice(o,o+r.value.length)!==r.value)return!1;o+=r.value.length;break;case"param":{let t,s=o;for(;s<e.length&&"&"!==e[s];)s++;if(s===o)return!1;try{t=decodeURIComponent(e.slice(o,s))}catch(n){t=e.slice(o,s)}n[r.name]=t,o=s;break}}return n}reverse(e={}){const t=this.reverseSegments(this.parsed.pathSegments,e);if(!1===t)return!1;let n=t;if(this.parsed.querySegments.length>0){const t=this.reverseSegments(this.parsed.querySegments,e);if(!this.parsed.queryOptional&&!1===t)return!1;t&&""!==t&&(n+="?"+t)}return n}reverseSegments(e,t,n=!1){let o="";for(let r=0;r<e.length;r++){const s=e[r],i=e.slice(r+1);switch(s.type){case"literal":o+=s.value;break;case"param":case"splat":if(!(s.name in t))return!1;o+=String(t[s.name]);break;case"optional":if(this.hasAllParams(s.segments,t,n)||this.hasLaterOptionalGroupNeedingParams(i,t,s.segments)){const e=this.reverseSegments(s.segments,t,!0);if(!1===e)return!1;o+=e}}}return o}hasLaterOptionalGroupNeedingParams(e,t,n){for(const o of e)if("optional"===o.type&&this.hasAnyParamInSegments(o.segments,t))return this.hasOnlyLiteralsAndOptionals(n);return!1}hasOnlyLiteralsAndOptionals(e){for(const t of e)if("param"===t.type||"splat"===t.type)return!1;return!0}hasAllParams(e,t,n=!1){let o=!1,r=!1,s=!1,i=!0;for(const n of e)switch(n.type){case"param":case"splat":i=!1,n.name in t&&void 0!==t[n.name]?o=!0:s=!0}const a=n||o&&!s;for(const n of e)if("optional"===n.type){this.hasAllParams(n.segments,t,a)&&(r=!0)}return!(!o||s)||(!(!r||s)||!(!i||!n))}hasOnlyOptionalMissingParams(e,t){for(const n of e)switch(n.type){case"param":case"splat":if(!(n.name in t))return!1}return!0}hasAnyParamInSegments(e,t){for(const n of e)switch(n.type){case"param":case"splat":if(n.name in t)return!0;break;case"optional":if(this.hasAnyParamInSegments(n.segments,t))return!0}return!1}}function J(e){const t={};return e.split(";").forEach(e=>{const[n,o]=e.split(":").map(e=>e.trim());n&&o&&(t[n]=o)}),t}var V;!function(e){e.SUCCESS="success",e.GUARDS_FAILED="guards-failed",e.NOT_FOUND="not-found"}(V||(V={})),exports.IS_CONTROLLER_INSTANCE=o,exports.Router=function(e){const t=[];let n,o,r,s=!1,i=null,a=null;const l=e.context||{};function c(e){if(!i||!a)return null;const t=e.querySelectorAll(i);for(const e of t){if(e[A]===a)return e}return null}function u(e,i,a,l,c){t.push({route:new Q(e),tag:i,transition:a,guards:l,layout:c}),s=!1,"/404"===e&&(n=i),"/403"===e&&(o=i),"/"===e&&(r=i)}function h(){switch(e.type){case"hash":return window.location.hash.slice(1);case"pushstate":return window.location.pathname}}async function p(e){let t;const n=!!o;if(n&&(t=document.createElement(o),t[E]=l),!n){const e=document.createElement("div");e.className="default-403",e.innerHTML="<h1>403</h1><p>Unauthorized</p>",t=e}e.innerHTML="",e.appendChild(t),i=null,a=null}async function d(e,t,n){if(!!!e)return!0;const o=Array.isArray(e)?e:[e];for(const e of o){if(!await e(l,t))return await p(n),!1}return!0}function f(t){if(!1===t)return null;if(!!t)return t;return!!e.layout?e.layout:null}function m(e){if(!(e!==i))return{element:null,needsNewLayout:!1};i=e;if(!!e){const t=Date.now();a=t;const n=document.createElement(e);return n[E]=l,n[A]=t,{element:n,needsNewLayout:!0}}return a=null,{element:null,needsNewLayout:!0}}async function y(e,t,n,o,r){const s=o||c(e);if(!s)return;const i=s.querySelector('[slot="page"]');if(!(!n||!i))return t.setAttribute("slot","page"),await v(s,i,t,n),void(r&&(e.innerHTML="",e.appendChild(s)));s.querySelectorAll('[slot="page"]').forEach(e=>e.remove()),t.setAttribute("slot","page"),s.appendChild(t),r&&(e.innerHTML="",e.appendChild(s))}async function g(e,t,n){const o=e.children[0];!n||!o?(e.innerHTML="",e.appendChild(t)):await v(e,o,t,n)}async function b(o){const s=document.querySelector(e.target);if(!s)throw new Error(`Target element not found: ${e.target}`);window.scrollTo(0,0);if((""===o.trim()||"/"===o)&&!!r){const n=t.find(e=>e.route.match("/"));if(!await d(n?.guards,{},s))return;const{element:o,transition:i,layout:a}=function(){const e=document.createElement(r);e[E]=l;const n=customElements.get(r),o=n?.[x],s=t.find(e=>e.route.match("/"));return{element:e,transition:o,layout:s?.layout}}(),u=f(a),{element:h,needsNewLayout:p}=m(u),b=i||e.transition;return null!==h||null!==c(s)?void await y(s,o,b,h,p):void await g(s,o,b)}const i=await async function(e,n){for(const o of t){const t=o.route.match(e);if(!1===t)continue;if(!await d(o.guards,t,n))return{result:V.GUARDS_FAILED};const r=document.createElement(o.tag);r[E]=l;const s=t;return Object.keys(s).forEach(e=>r.setAttribute(e,s[e])),{result:V.SUCCESS,element:r,transition:o.transition,layout:o.layout}}return{result:V.NOT_FOUND}}(o,s);if(i.result===V.GUARDS_FAILED)return;if(i.result===V.SUCCESS){const{element:t,transition:n,layout:o}=i,r=f(o),{element:a,needsNewLayout:l}=m(r),u=n||e.transition;return null!==a||null!==c(s)?void await y(s,t,u,a,l):void await g(s,t,u)}const{element:a,transition:u,layout:h}=function(){if(n){const e=document.createElement(n);e[E]=l;const t=customElements.get(n),o=t?.[x];return{element:e,transition:o,layout:void 0}}const e=document.createElement("div");return e.className="default-404",e.innerHTML="<h1>404</h1><p>Page not found</p>",{element:e,transition:void 0,layout:void 0}}(),p=f(h),{element:b,needsNewLayout:v}=m(p),w=u||e.transition;null!==b||null!==c(s)?await y(s,a,w,b,v):await g(s,a,w)}async function v(e,t,n,o){return async function(e,t,n,o={}){const r=o.outDuration||300,s=o.inDuration||300,i=o.mode||"sequential",a=o.out?J(o.out):{opacity:"0"},l={opacity:"0"},c=o.in?J(o.in):{opacity:"1"},u=e.style,h=u.position,p=e.tagName.includes("-")&&e.shadowRoot;p||(u.position="relative");const d=t.hasAttribute("slot")||n.hasAttribute("slot");d?(t.style.position="absolute",t.style.width="100%",t.style.height="100%",t.style.transition=`opacity ${r}ms ease-in-out`,n.style.position="absolute",n.style.width="100%",n.style.height="100%",n.style.transition=`opacity ${s}ms ease-in-out`):(t.style.position="absolute",t.style.top="0",t.style.left="0",t.style.width="100%",t.style.transition=`all ${r}ms ease-in-out`,n.style.position="absolute",n.style.top="0",n.style.left="0",n.style.width="100%"),Object.assign(n.style,l),n.style.transition=`all ${s}ms ease-in-out`,e.appendChild(n),n.offsetHeight,"simultaneous"===i?(Object.assign(t.style,a),Object.assign(n.style,c),await new Promise(e=>setTimeout(e,Math.max(r,s)))):(Object.assign(t.style,a),await new Promise(e=>setTimeout(e,r)),Object.assign(n.style,c),await new Promise(e=>setTimeout(e,s))),t.remove(),d?(n.style.position="",n.style.width="",n.style.height="",n.style.transition=""):(n.style.position="",n.style.top="",n.style.left="",n.style.width="",n.style.transition=""),Object.keys({...l,...c}).forEach(e=>{n.style[e]=""}),p||(u.position=h)}(e,t,n,o)}return{page:function(e){return function(t){W(t),t[x]=e.transition;const n=t.prototype.connectedCallback;t.prototype.connectedCallback=function(){n?.call(this);const e=e=>{void 0!==this[E]&&(e.detail.context=this[E],e.stopPropagation())};this.addEventListener("@context/request",e),this[S]=e};const o=t.prototype.disconnectedCallback;t.prototype.disconnectedCallback=function(){o?.call(this);const e=this[S];e&&(this.removeEventListener("@context/request",e),delete this[S]),delete this[E]},customElements.define(e.tag,t),e.routes.forEach(t=>u(t,e.tag,e.transition,e.guards,e.layout))}},initialize:function(){if(!!!document.querySelector(e.target))throw new Error(`Target element not found: ${e.target}`);!s&&(t.sort((e,t)=>t.route.spec.length-e.route.spec.length),s=!0),function(){const t="hash"===e.type,n="pushstate"===e.type;t&&window.addEventListener("hashchange",()=>{document.querySelector(e.target)&&b(h())}),n&&window.addEventListener("popstate",()=>{document.querySelector(e.target)&&b(h())})}(),b(h())},navigate:b,register:u,context:l}},exports.SimpleArray=_,exports.applyElementFunctionality=W,exports.attachController=G,exports.cleanupNativeElementControllers=function(){const e=globalThis.sniceNativeControllerObserver;e&&(e.disconnect(),delete globalThis.sniceNativeControllerObserver,delete globalThis.sniceNativeControllersInitialized)},exports.context=function(){return function(e,t){Object.defineProperty(e,t,{get(){if(void 0!==this[E])return this[E];const e={target:this},t=new CustomEvent("@context/request",{bubbles:!0,cancelable:!0,detail:e});let n=!0===this[o]&&this.element?this.element:this;if(n&&n.dispatchEvent){if(n.getRootNode&&n.getRootNode()instanceof ShadowRoot){const e=n.getRootNode();n=e.host}return n.dispatchEvent(t),void 0!==e.context?(this[E]=e.context,e.context):void 0}},enumerable:!0,configurable:!0})}},exports.controller=function(t){return function(o){return e.controllerRegistry.set(t,o),o.prototype[n]=!0,o}},exports.detachController=K,exports.dispatch=function(e,t){return function(n,o,r){const s=r.value;let i,a,l=0;return r.value=function(...n){const o=s.apply(this,n),r=n=>{if(void 0===n&&!1===t?.dispatchOnUndefined)return;const o=new CustomEvent(e,{bubbles:!0,composed:!0,...t,detail:n});this.dispatchEvent(o)},c=e=>{if(t?.debounce)clearTimeout(i),i=setTimeout(()=>r(e),t.debounce);else if(t?.throttle){const n=Date.now(),o=t.throttle-(n-l);o<=0?(clearTimeout(a),l=n,r(e)):a||(a=setTimeout(()=>{l=Date.now(),a=null,r(e)},o))}else r(e)};return o instanceof Promise?o.then(e=>(c(e),e)):(c(o),o)},r}},exports.dispose=function(){return function(e,t,n){const o=e.constructor;return o[T]||(o[T]=[]),o[T].push({methodName:t,method:n.value}),n}},exports.element=function(e){return function(t){W(t),customElements.define(e,t)}},exports.getController=function(e){return e[u]},exports.getSymbol=t,exports.layout=function(e){return function(t){W(t),customElements.define(e,t)}},exports.observe=function(e,t,n){let o,r;return"string"==typeof t?(o=t,r=n):(o=void 0,r=t),function(t,n,s){t[N]||(t[N]=[]);const i=Array.isArray(e)?e:[e];for(const e of i){const[i,...a]=e.split(":");t[N].push({type:i,target:a.join(":"),selector:o,methodName:n,method:s.value,options:r})}return s}},exports.on=function(e,t,n){let o,r;return"string"==typeof t?(o=t,r=n):(o=void 0,r=t),function(t,n,s){t[c]||(t[c]=[]);const i=Array.isArray(e)?e:[e];for(const e of i)t[c].push({eventName:e,selector:o,methodName:n,method:s.value,options:r});return s}},exports.part=function(e,t={}){return function(n,o,r){const s=n.constructor;r||(r=Object.getOwnPropertyDescriptor(n,o)||{value:n[o],writable:!0,enumerable:!0,configurable:!0});const i=r.value;return s[C]||(s[C]=new Map),s[C].set(e,{methodName:o,method:i}),r.value=async function(...n){this[P]||(this[P]=new Map),this[P].has(e)||this[P].set(e,{throttleTimer:null,debounceTimer:null,lastThrottleCall:0});const o=this[P].get(e),r=async()=>{const t=i.apply(this,n),o=t instanceof Promise?await t:t;if(this.shadowRoot&&void 0!==o){const t=this.shadowRoot.querySelector(`[part="${e}"]`);t&&(t.innerHTML=o)}return o};if(void 0!==t.debounce&&t.debounce>0)return o.debounceTimer&&clearTimeout(o.debounceTimer),new Promise(e=>{o.debounceTimer=setTimeout(async()=>{const t=await r();e(t)},t.debounce)});if(void 0!==t.throttle&&t.throttle>0){const e=Date.now();if(0===o.lastThrottleCall||e-o.lastThrottleCall>=t.throttle)return o.lastThrottleCall=e,await r();if(!o.throttleTimer){const n=t.throttle-(e-o.lastThrottleCall);o.throttleTimer=setTimeout(async()=>{o.throttleTimer=null,o.lastThrottleCall=Date.now(),await r()},n)}return}return await r()},r}},exports.property=function(e){return function(t,n){const o=t.constructor;e?.reflect&&e?.type===Array&&console.warn(`⚠️ Property '${n}' uses reflect:true with Array type.`),e?.reflect&&e?.type===Object&&console.warn(`⚠️ Property '${n}' uses reflect:true with Object type.`),o[y]||(o[y]=new Map),o[y].set(n,e||{});const r={get(){return this[g]||(this[g]={}),this[g][n]},set(t){this[g]||(this[g]={}),this[w]||(this[w]=new Set);const r=this[g][n];if(r===t)return;const s=void 0===r&&!this[b];if((void 0!==r||s&&null!=t)&&this[w].add(n),this[g][n]=t,e?.reflect&&this.setAttribute&&this[b]&&this[w].has(n)){const o="string"==typeof e.attribute?e.attribute:n.toLowerCase();if(null==t||!1===t||e?.type===_&&Array.isArray(t)&&0===t.length)this.removeAttribute(o);else{let n;n=t instanceof Date?t.toISOString():"bigint"==typeof t?t.toString()+"n":e?.type===_&&Array.isArray(t)?_.serialize(t):String(t),this.setAttribute(o,n)}}const i=o[v];if(i){if(i.has(n)){const e=i.get(n);for(const o of e)try{o.method.call(this,r,t,n)}catch(e){console.error(`Error in @watch('${n}') method ${o.methodName}:`,e)}}if(i.has("*")){const e=i.get("*");for(const o of e)try{o.method.call(this,r,t,n)}catch(e){console.error(`Error in @watch('*') method ${o.methodName}:`,e)}}}this.requestUpdate&&this.requestUpdate(n,r)},enumerable:!0,configurable:!0};Object.defineProperty(t,n,r)}},exports.query=function(e,t={}){return function(n,r){const{light:s=!1,shadow:i=!0}=t;Object.defineProperty(n,r,{get(){const t=!0===this[o]&&this.element?this.element:this;let n=null;return i&&t.shadowRoot&&(n=t.shadowRoot.querySelector(e)),!n&&s&&(n=t.querySelector(e)),n||null},enumerable:!0,configurable:!0})}},exports.queryAll=function(e,t={}){return function(n,r){const{light:s=!1,shadow:i=!0}=t;Object.defineProperty(n,r,{get(){const t=!0===this[o]&&this.element?this.element:this,n=[];if(i&&t.shadowRoot){const o=t.shadowRoot.querySelectorAll(e);n.push(...o)}if(s){const o=t.querySelectorAll(e);n.push(...o)}return n},enumerable:!0,configurable:!0})}},exports.ready=function(){return function(e,t,n){const o=e.constructor;return o[O]||(o[O]=[]),o[O].push({methodName:t,method:n.value}),n}},exports.request=function(e,t){return function(n,r,s){const i=s.value;let a,l,c=0;return s.value=async function(...n){const r=async()=>{const r=t?.timeout??12e4,s=t?.discoveryTimeout??50,a=i.apply(this,n),{value:l,done:c}=await a.next();if(c)return l;let u,h;const p=new Promise((e,t)=>{u=e,h=t});let d,f,m;const y=new Promise((t,n)=>{d=t,f=n,m=setTimeout(()=>{n(new Error(`Request "${e}" timed out after ${s}ms - no handler found`))},s)}),g=new CustomEvent(`@request/${e}`,{bubbles:void 0===t?.bubbles||t.bubbles,cancelable:t?.cancelable||!1,composed:!0,detail:{payload:l,discovery:{resolve:()=>{clearTimeout(m),d()},reject:f},data:{resolve:u,reject:h}}});(!0===this[o]&&this.element?this.element:this).dispatchEvent(g);try{await y;const t=setTimeout(()=>{h(new Error(`Request "${e}" timed out after ${r}ms`))},r),n=await p;clearTimeout(t);const{value:o}=await a.next(n);return o}catch(e){try{await a.throw(e)}catch(e){throw e}}};if(t?.debounce)return new Promise((e,n)=>{clearTimeout(a),a=setTimeout(async()=>{try{const t=await r();e(t)}catch(e){n(e)}},t.debounce)});if(t?.throttle){const e=Date.now(),n=t.throttle-(e-c);return n<=0?(clearTimeout(l),c=e,r()):l?Promise.resolve():new Promise((e,t)=>{l=setTimeout(async()=>{c=Date.now(),l=null;try{const t=await r();e(t)}catch(e){t(e)}},n)})}return r()},s}},exports.respond=function(e,t){return function(n,o,r){const i=r.value;return n[s]||(n[s]=[]),n[s].push({channelName:e,methodName:o,method:i,options:t}),r}},exports.useNativeElementControllers=function(){if(globalThis.sniceNativeControllersInitialized)return;function e(e){if(!(e instanceof HTMLElement))return;if(e.tagName.includes("-"))return;if(e[r])return;const t=e.getAttribute("controller"),n=e[f];t&&t!==n?(e[f]=t,e.ready||(e.ready=Promise.resolve()),n&&K(e).catch(e=>{console.error("Failed to detach old controller from native element:",e)}),G(e,t).catch(e=>{console.error(`Failed to attach controller "${t}" to native element:`,e)})):!t&&n&&(delete e[f],delete e[h],K(e).catch(e=>{console.error("Failed to detach controller from native element:",e)}))}globalThis.sniceNativeControllersInitialized=!0;const t=new MutationObserver(t=>{for(const n of t)"attributes"===n.type&&"controller"===n.attributeName?e(n.target):"childList"===n.type&&n.addedNodes.forEach(t=>{t instanceof HTMLElement&&(e(t),t.querySelectorAll('[controller]:not([class*="-"])').forEach(e))})});"loading"===document.readyState?document.addEventListener("DOMContentLoaded",()=>{document.querySelectorAll('[controller]:not([class*="-"])').forEach(e),t.observe(document.body,{attributes:!0,attributeFilter:["controller"],childList:!0,subtree:!0})}):(document.querySelectorAll('[controller]:not([class*="-"])').forEach(e),t.observe(document.body,{attributes:!0,attributeFilter:["controller"],childList:!0,subtree:!0})),globalThis.sniceNativeControllerObserver=t},exports.watch=function(...e){return function(t,n,o){const r=t.constructor;r[v]||(r[v]=new Map);for(const t of e)r[v].has(t)||r[v].set(t,[]),r[v].get(t).push({methodName:n,method:o.value});return o}};
|
|
15
|
-
//# sourceMappingURL=index.cjs.min.map
|
package/dist/symbols.cjs
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* snice v1.14.2
|
|
3
|
-
* Imperative TypeScript framework for building vanilla web components with decorators, routing, and controllers. No virtual DOM, no build complexity.
|
|
4
|
-
* (c) 2024
|
|
5
|
-
* Released under the MIT License.
|
|
6
|
-
*/
|
|
7
|
-
'use strict';
|
|
8
|
-
|
|
9
|
-
// Global namespace for Snice framework
|
|
10
|
-
// Ensures all registries and symbols are shared across different JS files/modules
|
|
11
|
-
// Initialize or get the global Snice namespace
|
|
12
|
-
function initGlobalNamespace() {
|
|
13
|
-
if (!globalThis.snice) {
|
|
14
|
-
globalThis.snice = {
|
|
15
|
-
controllerRegistry: new Map(),
|
|
16
|
-
controllerIdCounter: 0,
|
|
17
|
-
symbols: new Map()
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
return globalThis.snice;
|
|
21
|
-
}
|
|
22
|
-
// Export the global namespace
|
|
23
|
-
const snice = initGlobalNamespace();
|
|
24
|
-
// Helper function to get or create a global symbol
|
|
25
|
-
function getSymbol(name) {
|
|
26
|
-
if (!snice.symbols.has(name)) {
|
|
27
|
-
snice.symbols.set(name, Symbol(name));
|
|
28
|
-
}
|
|
29
|
-
return snice.symbols.get(name);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// Central file for all symbols used in the framework
|
|
33
|
-
// All symbols are stored globally to ensure consistency across modules
|
|
34
|
-
const IS_CONTROLLER_CLASS = getSymbol('is-controller-class');
|
|
35
|
-
const IS_CONTROLLER_INSTANCE = getSymbol('is-controller-instance');
|
|
36
|
-
const IS_ELEMENT_CLASS = getSymbol('is-element-class');
|
|
37
|
-
const CHANNEL_HANDLERS = getSymbol('channel-handlers');
|
|
38
|
-
// Internal element state symbols
|
|
39
|
-
const READY_PROMISE = getSymbol('ready-promise');
|
|
40
|
-
const READY_RESOLVE = getSymbol('ready-resolve');
|
|
41
|
-
const CONTROLLER = getSymbol('controller');
|
|
42
|
-
// Event handler symbols
|
|
43
|
-
const ON_HANDLERS = getSymbol('on-handlers');
|
|
44
|
-
// Controller symbols
|
|
45
|
-
const CONTROLLER_KEY = getSymbol('controller-key');
|
|
46
|
-
const CONTROLLER_NAME_KEY = getSymbol('controller-name');
|
|
47
|
-
const CONTROLLER_ID = getSymbol('controller-id');
|
|
48
|
-
const CONTROLLER_OPERATIONS = getSymbol('controller-operations');
|
|
49
|
-
const NATIVE_CONTROLLER = getSymbol('native-controller');
|
|
50
|
-
// Cleanup symbol - holds an object with all cleanup arrays
|
|
51
|
-
const CLEANUP = getSymbol('cleanup');
|
|
52
|
-
// Property symbols
|
|
53
|
-
const PROPERTIES = getSymbol('properties');
|
|
54
|
-
const PROPERTY_VALUES = getSymbol('property-values');
|
|
55
|
-
const PROPERTIES_INITIALIZED = getSymbol('properties-initialized');
|
|
56
|
-
const PROPERTY_WATCHERS = getSymbol('property-watchers');
|
|
57
|
-
const EXPLICITLY_SET_PROPERTIES = getSymbol('explicitly-set-properties');
|
|
58
|
-
// Router context symbol
|
|
59
|
-
const ROUTER_CONTEXT = getSymbol('router-context');
|
|
60
|
-
const CURRENT_PAGE_MARKER = getSymbol('current-page-marker');
|
|
61
|
-
const CONTEXT_REQUEST_HANDLER = getSymbol('context-request-handler');
|
|
62
|
-
const PAGE_TRANSITION = getSymbol('page-transition');
|
|
63
|
-
const CREATED_AT = getSymbol('created-at');
|
|
64
|
-
// Lifecycle symbols
|
|
65
|
-
const READY_HANDLERS = getSymbol('ready-handlers');
|
|
66
|
-
const DISPOSE_HANDLERS = getSymbol('dispose-handlers');
|
|
67
|
-
// Observer symbols
|
|
68
|
-
const OBSERVERS = getSymbol('observers');
|
|
69
|
-
// Part symbols
|
|
70
|
-
const PARTS = getSymbol('parts');
|
|
71
|
-
const PART_TIMERS = getSymbol('part-timers');
|
|
72
|
-
|
|
73
|
-
exports.CHANNEL_HANDLERS = CHANNEL_HANDLERS;
|
|
74
|
-
exports.CLEANUP = CLEANUP;
|
|
75
|
-
exports.CONTEXT_REQUEST_HANDLER = CONTEXT_REQUEST_HANDLER;
|
|
76
|
-
exports.CONTROLLER = CONTROLLER;
|
|
77
|
-
exports.CONTROLLER_ID = CONTROLLER_ID;
|
|
78
|
-
exports.CONTROLLER_KEY = CONTROLLER_KEY;
|
|
79
|
-
exports.CONTROLLER_NAME_KEY = CONTROLLER_NAME_KEY;
|
|
80
|
-
exports.CONTROLLER_OPERATIONS = CONTROLLER_OPERATIONS;
|
|
81
|
-
exports.CREATED_AT = CREATED_AT;
|
|
82
|
-
exports.CURRENT_PAGE_MARKER = CURRENT_PAGE_MARKER;
|
|
83
|
-
exports.DISPOSE_HANDLERS = DISPOSE_HANDLERS;
|
|
84
|
-
exports.EXPLICITLY_SET_PROPERTIES = EXPLICITLY_SET_PROPERTIES;
|
|
85
|
-
exports.IS_CONTROLLER_CLASS = IS_CONTROLLER_CLASS;
|
|
86
|
-
exports.IS_CONTROLLER_INSTANCE = IS_CONTROLLER_INSTANCE;
|
|
87
|
-
exports.IS_ELEMENT_CLASS = IS_ELEMENT_CLASS;
|
|
88
|
-
exports.NATIVE_CONTROLLER = NATIVE_CONTROLLER;
|
|
89
|
-
exports.OBSERVERS = OBSERVERS;
|
|
90
|
-
exports.ON_HANDLERS = ON_HANDLERS;
|
|
91
|
-
exports.PAGE_TRANSITION = PAGE_TRANSITION;
|
|
92
|
-
exports.PARTS = PARTS;
|
|
93
|
-
exports.PART_TIMERS = PART_TIMERS;
|
|
94
|
-
exports.PROPERTIES = PROPERTIES;
|
|
95
|
-
exports.PROPERTIES_INITIALIZED = PROPERTIES_INITIALIZED;
|
|
96
|
-
exports.PROPERTY_VALUES = PROPERTY_VALUES;
|
|
97
|
-
exports.PROPERTY_WATCHERS = PROPERTY_WATCHERS;
|
|
98
|
-
exports.READY_HANDLERS = READY_HANDLERS;
|
|
99
|
-
exports.READY_PROMISE = READY_PROMISE;
|
|
100
|
-
exports.READY_RESOLVE = READY_RESOLVE;
|
|
101
|
-
exports.ROUTER_CONTEXT = ROUTER_CONTEXT;
|
|
102
|
-
exports.getSymbol = getSymbol;
|
|
103
|
-
//# sourceMappingURL=symbols.cjs.map
|
package/dist/transitions.cjs
DELETED
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* snice v1.14.2
|
|
3
|
-
* Imperative TypeScript framework for building vanilla web components with decorators, routing, and controllers. No virtual DOM, no build complexity.
|
|
4
|
-
* (c) 2024
|
|
5
|
-
* Released under the MIT License.
|
|
6
|
-
*/
|
|
7
|
-
'use strict';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Generic transition system for animating between elements
|
|
11
|
-
*/
|
|
12
|
-
/**
|
|
13
|
-
* Parse CSS property string into an object
|
|
14
|
-
*/
|
|
15
|
-
function parseStyles(styleString) {
|
|
16
|
-
const styles = {};
|
|
17
|
-
styleString.split(';').forEach(rule => {
|
|
18
|
-
const [prop, value] = rule.split(':').map(s => s.trim());
|
|
19
|
-
if (prop && value) {
|
|
20
|
-
styles[prop] = value;
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
return styles;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Perform a transition between two elements
|
|
27
|
-
*/
|
|
28
|
-
async function performTransition(container, oldElement, newElement, transition = {}) {
|
|
29
|
-
const outDuration = transition.outDuration || 300;
|
|
30
|
-
const inDuration = transition.inDuration || 300;
|
|
31
|
-
const mode = transition.mode || 'sequential';
|
|
32
|
-
// Default transitions
|
|
33
|
-
const outStyles = transition.out ? parseStyles(transition.out) : { opacity: '0' };
|
|
34
|
-
const inStartStyles = { opacity: '0' }; // Always start invisible
|
|
35
|
-
const inEndStyles = transition.in ? parseStyles(transition.in) : { opacity: '1' };
|
|
36
|
-
// Set container to relative positioning to allow absolute positioning
|
|
37
|
-
// Skip for layout elements to avoid jumpy transitions
|
|
38
|
-
const containerStyle = container.style;
|
|
39
|
-
const originalPosition = containerStyle.position;
|
|
40
|
-
const isLayoutElement = container.tagName.includes('-') && container.shadowRoot;
|
|
41
|
-
if (!isLayoutElement) {
|
|
42
|
-
containerStyle.position = 'relative';
|
|
43
|
-
}
|
|
44
|
-
// Check if elements are slotted (inside a layout)
|
|
45
|
-
const isSlottedTransition = oldElement.hasAttribute('slot') || newElement.hasAttribute('slot');
|
|
46
|
-
if (isSlottedTransition) {
|
|
47
|
-
// For slotted elements, use absolute with width/height for crossfade
|
|
48
|
-
oldElement.style.position = 'absolute';
|
|
49
|
-
oldElement.style.width = '100%';
|
|
50
|
-
oldElement.style.height = '100%';
|
|
51
|
-
oldElement.style.transition = `opacity ${outDuration}ms ease-in-out`;
|
|
52
|
-
newElement.style.position = 'absolute';
|
|
53
|
-
newElement.style.width = '100%';
|
|
54
|
-
newElement.style.height = '100%';
|
|
55
|
-
newElement.style.transition = `opacity ${inDuration}ms ease-in-out`;
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
// Original absolute positioning for non-slotted elements
|
|
59
|
-
oldElement.style.position = 'absolute';
|
|
60
|
-
oldElement.style.top = '0';
|
|
61
|
-
oldElement.style.left = '0';
|
|
62
|
-
oldElement.style.width = '100%';
|
|
63
|
-
oldElement.style.transition = `all ${outDuration}ms ease-in-out`;
|
|
64
|
-
newElement.style.position = 'absolute';
|
|
65
|
-
newElement.style.top = '0';
|
|
66
|
-
newElement.style.left = '0';
|
|
67
|
-
newElement.style.width = '100%';
|
|
68
|
-
}
|
|
69
|
-
Object.assign(newElement.style, inStartStyles);
|
|
70
|
-
newElement.style.transition = `all ${inDuration}ms ease-in-out`;
|
|
71
|
-
// Add new element to container
|
|
72
|
-
container.appendChild(newElement);
|
|
73
|
-
// Force browser to calculate styles
|
|
74
|
-
void newElement.offsetHeight;
|
|
75
|
-
if (mode === 'simultaneous') {
|
|
76
|
-
// Start both transitions at once
|
|
77
|
-
Object.assign(oldElement.style, outStyles);
|
|
78
|
-
Object.assign(newElement.style, inEndStyles);
|
|
79
|
-
// Wait for both transitions to complete
|
|
80
|
-
await new Promise(resolve => setTimeout(resolve, Math.max(outDuration, inDuration)));
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
// Sequential: transition out old, then transition in new
|
|
84
|
-
Object.assign(oldElement.style, outStyles);
|
|
85
|
-
await new Promise(resolve => setTimeout(resolve, outDuration));
|
|
86
|
-
Object.assign(newElement.style, inEndStyles);
|
|
87
|
-
await new Promise(resolve => setTimeout(resolve, inDuration));
|
|
88
|
-
}
|
|
89
|
-
// Cleanup
|
|
90
|
-
oldElement.remove();
|
|
91
|
-
if (isSlottedTransition) {
|
|
92
|
-
// Cleanup for slotted elements
|
|
93
|
-
newElement.style.position = '';
|
|
94
|
-
newElement.style.width = '';
|
|
95
|
-
newElement.style.height = '';
|
|
96
|
-
newElement.style.transition = '';
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
// Cleanup for non-slotted elements
|
|
100
|
-
newElement.style.position = '';
|
|
101
|
-
newElement.style.top = '';
|
|
102
|
-
newElement.style.left = '';
|
|
103
|
-
newElement.style.width = '';
|
|
104
|
-
newElement.style.transition = '';
|
|
105
|
-
}
|
|
106
|
-
// Reset any transition styles
|
|
107
|
-
Object.keys({ ...inStartStyles, ...inEndStyles }).forEach(prop => {
|
|
108
|
-
newElement.style[prop] = '';
|
|
109
|
-
});
|
|
110
|
-
if (!isLayoutElement) {
|
|
111
|
-
containerStyle.position = originalPosition;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Predefined transitions
|
|
116
|
-
*/
|
|
117
|
-
// Fade transition
|
|
118
|
-
const fadeTransition = {
|
|
119
|
-
name: 'fade',
|
|
120
|
-
outDuration: 200,
|
|
121
|
-
inDuration: 200,
|
|
122
|
-
out: 'opacity: 0',
|
|
123
|
-
in: 'opacity: 1',
|
|
124
|
-
mode: 'simultaneous'
|
|
125
|
-
};
|
|
126
|
-
// Slide transition (from left)
|
|
127
|
-
const slideTransition = {
|
|
128
|
-
name: 'slide',
|
|
129
|
-
outDuration: 300,
|
|
130
|
-
inDuration: 300,
|
|
131
|
-
out: 'transform: translateX(-100%)',
|
|
132
|
-
in: 'transform: translateX(0)',
|
|
133
|
-
mode: 'sequential'
|
|
134
|
-
};
|
|
135
|
-
// Slide from right
|
|
136
|
-
const slideRightTransition = {
|
|
137
|
-
name: 'slide-right',
|
|
138
|
-
outDuration: 300,
|
|
139
|
-
inDuration: 300,
|
|
140
|
-
out: 'transform: translateX(100%)',
|
|
141
|
-
in: 'transform: translateX(0)',
|
|
142
|
-
mode: 'sequential'
|
|
143
|
-
};
|
|
144
|
-
// Slide from top
|
|
145
|
-
const slideUpTransition = {
|
|
146
|
-
name: 'slide-up',
|
|
147
|
-
outDuration: 300,
|
|
148
|
-
inDuration: 300,
|
|
149
|
-
out: 'transform: translateY(-100%)',
|
|
150
|
-
in: 'transform: translateY(0)',
|
|
151
|
-
mode: 'sequential'
|
|
152
|
-
};
|
|
153
|
-
// Slide from bottom
|
|
154
|
-
const slideDownTransition = {
|
|
155
|
-
name: 'slide-down',
|
|
156
|
-
outDuration: 300,
|
|
157
|
-
inDuration: 300,
|
|
158
|
-
out: 'transform: translateY(100%)',
|
|
159
|
-
in: 'transform: translateY(0)',
|
|
160
|
-
mode: 'sequential'
|
|
161
|
-
};
|
|
162
|
-
// Scale transition
|
|
163
|
-
const scaleTransition = {
|
|
164
|
-
name: 'scale',
|
|
165
|
-
outDuration: 250,
|
|
166
|
-
inDuration: 250,
|
|
167
|
-
out: 'transform: scale(0.9); opacity: 0',
|
|
168
|
-
in: 'transform: scale(1); opacity: 1',
|
|
169
|
-
mode: 'simultaneous'
|
|
170
|
-
};
|
|
171
|
-
// Rotate transition
|
|
172
|
-
const rotateTransition = {
|
|
173
|
-
name: 'rotate',
|
|
174
|
-
outDuration: 400,
|
|
175
|
-
inDuration: 400,
|
|
176
|
-
out: 'transform: rotate(180deg) scale(0.5); opacity: 0',
|
|
177
|
-
in: 'transform: rotate(0) scale(1); opacity: 1',
|
|
178
|
-
mode: 'simultaneous'
|
|
179
|
-
};
|
|
180
|
-
// Flip transition
|
|
181
|
-
const flipTransition = {
|
|
182
|
-
name: 'flip',
|
|
183
|
-
outDuration: 400,
|
|
184
|
-
inDuration: 400,
|
|
185
|
-
out: 'transform: rotateY(180deg); opacity: 0',
|
|
186
|
-
in: 'transform: rotateY(0); opacity: 1',
|
|
187
|
-
mode: 'sequential'
|
|
188
|
-
};
|
|
189
|
-
// Zoom transition
|
|
190
|
-
const zoomTransition = {
|
|
191
|
-
name: 'zoom',
|
|
192
|
-
outDuration: 300,
|
|
193
|
-
inDuration: 300,
|
|
194
|
-
out: 'transform: scale(2); opacity: 0',
|
|
195
|
-
in: 'transform: scale(1); opacity: 1',
|
|
196
|
-
mode: 'simultaneous'
|
|
197
|
-
};
|
|
198
|
-
// None transition (instant swap)
|
|
199
|
-
const noneTransition = {
|
|
200
|
-
name: 'none',
|
|
201
|
-
outDuration: 0,
|
|
202
|
-
inDuration: 0,
|
|
203
|
-
out: '',
|
|
204
|
-
in: '',
|
|
205
|
-
mode: 'simultaneous'
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
exports.fadeTransition = fadeTransition;
|
|
209
|
-
exports.flipTransition = flipTransition;
|
|
210
|
-
exports.noneTransition = noneTransition;
|
|
211
|
-
exports.performTransition = performTransition;
|
|
212
|
-
exports.rotateTransition = rotateTransition;
|
|
213
|
-
exports.scaleTransition = scaleTransition;
|
|
214
|
-
exports.slideDownTransition = slideDownTransition;
|
|
215
|
-
exports.slideRightTransition = slideRightTransition;
|
|
216
|
-
exports.slideTransition = slideTransition;
|
|
217
|
-
exports.slideUpTransition = slideUpTransition;
|
|
218
|
-
exports.zoomTransition = zoomTransition;
|
|
219
|
-
//# sourceMappingURL=transitions.cjs.map
|