@cat-of-summer/st-script 1.0.9 → 1.0.10
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/README.md +50 -49
- package/dist/app.esm.min.js +1 -1
- package/dist/app.esm.min.js.map +3 -3
- package/dist/app.min.js +1 -1
- package/dist/app.min.js.map +3 -3
- package/dist/cookie.esm.min.js +1 -1
- package/dist/cookie.esm.min.js.map +2 -2
- package/dist/cookie.min.js +1 -1
- package/dist/cookie.min.js.map +2 -2
- package/dist/modal.esm.min.js +1 -1
- package/dist/modal.esm.min.js.map +3 -3
- package/dist/modal.min.js +1 -1
- package/dist/modal.min.js.map +3 -3
- package/dist/route.esm.min.js +1 -1
- package/dist/route.esm.min.js.map +3 -3
- package/dist/route.min.js +1 -1
- package/dist/route.min.js.map +3 -3
- package/package.json +1 -1
- package/src/app/index.js +246 -146
- package/src/cookie/index.js +9 -0
- package/src/modal/index.js +46 -7
- package/src/route/index.js +86 -3
package/README.md
CHANGED
|
@@ -9,9 +9,9 @@ two flavours per module:
|
|
|
9
9
|
|
|
10
10
|
| Module | Global / element | Notes |
|
|
11
11
|
| --------------------- | ------------------- | ------------------------------------------------ |
|
|
12
|
-
| `
|
|
12
|
+
| `modal` | `window.Modal` | Modal windows. |
|
|
13
13
|
| `typograf` | `window.Typograf` | Неразрывные пробелы: предлоги, частицы, числа, последнее слово. |
|
|
14
|
-
| `
|
|
14
|
+
| `cookie` | `window.Cookie` | Cookie helpers (JSON for non-strings). |
|
|
15
15
|
| `core` | `window.Core` | Utilities (`merge`, `getRandomChars`, `uuid`, `fetch`). |
|
|
16
16
|
| `observer` | `window.Observer` | Scroll animations: `[state]`, `--progress`, stagger, cross. |
|
|
17
17
|
| `toggle` | `window.Toggle` | State toggler (accordions, switches, hover-menus).|
|
|
@@ -22,17 +22,17 @@ two flavours per module:
|
|
|
22
22
|
| `st_button_widget` | `window.st_button_widget`| Floating button widget. |
|
|
23
23
|
| `st_links_widget` | `window.st_links_widget`| Links widget. |
|
|
24
24
|
| `loader` | `window.Loader` | Ajax list loader (cards: подгрузка/фильтр/сортировка) via `Core.fetch`. |
|
|
25
|
-
| `
|
|
26
|
-
| `
|
|
25
|
+
| `app` | `window.App`, `<st-app>` | **Web Component** — registers `<st-app>` on load. |
|
|
26
|
+
| `route` | `window.Route` | URL reactions; SPA mode (`history` / `hash`). |
|
|
27
|
+
| `app/form` | `window.Form` | Form app **config object** — register with `App.create(form)`; `app` is not bundled. |
|
|
27
28
|
|
|
28
|
-
> `st_widget` / `st_widget/button` are work-in-progress stubs (no output yet).
|
|
29
29
|
|
|
30
30
|
## Development
|
|
31
31
|
|
|
32
32
|
```bash
|
|
33
33
|
npm install # installs esbuild, builds dist/ via the prepare script
|
|
34
34
|
npm run build # compile src/ → dist/*.min.js (ESM + IIFE)
|
|
35
|
-
|
|
35
|
+
node scripts/build.mjs --watch # rebuild on change
|
|
36
36
|
```
|
|
37
37
|
|
|
38
38
|
Source layout — **every `src/**/index.js` is a bundle**; its folder path becomes
|
|
@@ -40,10 +40,10 @@ the output name:
|
|
|
40
40
|
|
|
41
41
|
```
|
|
42
42
|
src/
|
|
43
|
-
index.js # aggregate barrel
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
index.js # aggregate barrel (source only, not built into dist/)
|
|
44
|
+
modal/index.js # → dist/modal.esm.min.js + dist/modal.min.js
|
|
45
|
+
app/index.js # → dist/app.{esm.min,min}.js
|
|
46
|
+
app/form/index.js # → dist/app/form.{esm.min,min}.js
|
|
47
47
|
…
|
|
48
48
|
```
|
|
49
49
|
|
|
@@ -51,7 +51,7 @@ src/
|
|
|
51
51
|
|
|
52
52
|
- A folder with an `index.js` is a *bundle*; drop `src/<name>/index.js` and it is
|
|
53
53
|
built automatically into `dist/<name>.esm.min.js` (ESM) and `dist/<name>.min.js`
|
|
54
|
-
(IIFE global, default export
|
|
54
|
+
(IIFE global, default export exposed as `window.<ClassName>`, e.g. `window.Modal`).
|
|
55
55
|
- A file or folder whose name starts with `_` is shared content (a partial),
|
|
56
56
|
imported via `import` and never built on its own.
|
|
57
57
|
|
|
@@ -67,69 +67,70 @@ is: `import Modal from '@cat-of-summer/st-script/src/modal/index.js'`.
|
|
|
67
67
|
|
|
68
68
|
## A. Use via npm
|
|
69
69
|
|
|
70
|
-
Пакет опубликован в
|
|
71
|
-
read-only токен GitHub.
|
|
72
|
-
|
|
73
|
-
### 1. Получить токен
|
|
74
|
-
|
|
75
|
-
GitHub → Settings → Developer settings → Fine-grained personal access tokens → Generate new token:
|
|
76
|
-
|
|
77
|
-
- **Repository access**: `cat-of-summer/ST-script---framework`
|
|
78
|
-
- **Permissions**: `read:packages`
|
|
79
|
-
|
|
80
|
-
### 2. Скопировать `.npmrc` в проект потребителя
|
|
81
|
-
|
|
82
|
-
Скопируйте файл `.npmrc` из корня этого репозитория к себе в проект — токен уже вписан.
|
|
83
|
-
|
|
84
|
-
### 3. Установить
|
|
70
|
+
Пакет опубликован в публичном npm, токен не нужен:
|
|
85
71
|
|
|
86
72
|
```bash
|
|
87
73
|
npm install @cat-of-summer/st-script
|
|
88
74
|
```
|
|
89
75
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
Per-module (рекомендуется — только то, что нужно):
|
|
76
|
+
Модули импортируются по одному — подключается только нужное:
|
|
93
77
|
|
|
94
78
|
```js
|
|
95
|
-
import
|
|
79
|
+
import Modal from '@cat-of-summer/st-script/modal';
|
|
80
|
+
import Cookie from '@cat-of-summer/st-script/cookie';
|
|
96
81
|
import Typograf from '@cat-of-summer/st-script/typograf';
|
|
97
82
|
|
|
98
|
-
const modal = new
|
|
83
|
+
const modal = new Modal({ content: '#promo', overlay: true });
|
|
99
84
|
```
|
|
100
85
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
```js
|
|
104
|
-
import { st_modal, st_cookie, App } from '@cat-of-summer/st-script';
|
|
105
|
-
```
|
|
86
|
+
Общего barrel-входа в `dist/` нет. Весь набор разом доступен только из исходников:
|
|
87
|
+
`import { Modal, Cookie, App } from '@cat-of-summer/st-script/src/index.js'`.
|
|
106
88
|
|
|
107
89
|
Web Component регистрирует себя при импорте:
|
|
108
90
|
|
|
109
91
|
```js
|
|
110
|
-
import App from '@cat-of-summer/st-script/
|
|
111
|
-
import formConfig from '@cat-of-summer/st-script/
|
|
92
|
+
import App from '@cat-of-summer/st-script/app';
|
|
93
|
+
import formConfig from '@cat-of-summer/st-script/app/form';
|
|
112
94
|
App.create(formConfig); // теперь работает <st-app app="form">
|
|
113
95
|
```
|
|
114
96
|
|
|
97
|
+
## B. Use via CDN
|
|
98
|
+
|
|
99
|
+
```html
|
|
100
|
+
<script defer src="https://cdn.jsdelivr.net/npm/@cat-of-summer/st-script/dist/modal.min.js"></script>
|
|
101
|
+
<script defer src="https://cdn.jsdelivr.net/npm/@cat-of-summer/st-script/dist/app.min.js"></script>
|
|
102
|
+
```
|
|
103
|
+
|
|
115
104
|
## Releasing
|
|
116
105
|
|
|
117
|
-
|
|
106
|
+
Релиз запускается **тегом** `vX.Y.Z`, а не обычным пушем:
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
git tag v1.1.0
|
|
110
|
+
git push origin v1.1.0
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Версия пакета берётся из тега при публикации. Поле `version` в `package.json` служебное и с
|
|
114
|
+
номером в npm не совпадает. Актуальная версия — `npm view @cat-of-summer/st-script version`.
|
|
115
|
+
Сборку и публикацию выполняет `.github/workflows/ci-cd.yml` (общий workflow из
|
|
116
|
+
`cat-of-summer/git_toolkit`).
|
|
117
|
+
|
|
118
|
+
## Tests
|
|
118
119
|
|
|
119
120
|
```bash
|
|
120
|
-
#
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
node tests/core.test.mjs # и остальные tests/*.test.mjs без DOM
|
|
122
|
+
npm run build # браузерным тестам нужен dist/
|
|
123
|
+
node tests/browser.test.mjs # App, Modal, Cookie, Route — нужен Playwright с Chromium
|
|
123
124
|
```
|
|
124
125
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
126
|
+
Браузерные тесты удобно гонять в контейнере с Playwright, не ставя его на машину:
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
docker run --rm -v "$PWD:/repo" -e PLAYWRIGHT_FROM=/path/to/node_modules/ --entrypoint node <playwright-image> /repo/tests/browser.test.mjs
|
|
130
|
+
```
|
|
129
131
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
- `CI_COMMAND` (optional) — extra checks/tests in CI.
|
|
132
|
+
`PLAYWRIGHT_FROM` — каталог, из которого резолвится пакет `playwright`, если он стоит не в этом
|
|
133
|
+
репозитории.
|
|
133
134
|
|
|
134
135
|
## Examples
|
|
135
136
|
|
package/dist/app.esm.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var v=class y extends HTMLElement{static#C=new Set(["disabled","checked","readonly","required","selected","hidden","open","autofocus"]);static#d=new Map;static#p=new Set;static create(e){let{app:t,setup:i=()=>{},template:l="",events:r={}}=e;if(y.#d.has(t))throw new Error(`Application "${t}" already exists!`);y.#d.set(t,{setup:i,template:l,events:r,config:e}),y.#p.forEach(s=>{s.#i!==!0&&s.#P()})}static extend(e,t={}){let i=y.#d.get(e);if(!i)throw new Error(`Application "${e}" not found!`);let l=i.config,r={...l,...t};return(l.events||t.events)&&(r.events={...l.events,...t.events}),y.create(r)}#i=!1;#u="";#S=!1;#s=new Map;#y=null;#h=new Set;#m=!1;#e=[];#r=null;#M=new Map;#l=null;#t=[];#b=new Set;#x=!1;#n=new Map;#k=0;constructor(){super(),y.#p.add(this)}#g(e){!e||!e.length||e.forEach(t=>{if(t.type==="event"&&t.element&&t.handler)t.element.removeEventListener(t.eventName,t.handler);else if(t.type==="model"&&t.element&&t.handler){let i=t.element.tagName==="SELECT"?"change":"input";t.element.removeEventListener(i,t.handler)}else t.type==="attrSync"&&t.unwatch&&t.unwatch();t.effect&&(this.#s.forEach((i,l)=>{i.delete(t.effect),i.size===0&&this.#s.delete(l)}),this.#h.delete(t.effect))})}get template(){return this.#u}get attrs(){return{get:e=>this.getAttribute(e),set:(e,t)=>this.setAttribute(e,t),remove:e=>this.removeAttribute(e),has:e=>this.hasAttribute(e),toggle:(e,t)=>this.toggleAttribute(e,t),keys:()=>Array.from(this.attributes).map(e=>e.name),entries:()=>Array.from(this.attributes).map(e=>[e.name,e.value])}}addEventListener(e,t,i){if((e==="setup"||e==="rendered")&&this.#S){queueMicrotask(()=>t(new CustomEvent(e)));return}super.addEventListener(e,t,i)}dispatchEvent(e,t=null,i={}){if(typeof e=="string"){let l=new CustomEvent(e,{cancelable:!0,...i,detail:t});return super.dispatchEvent(l)}return super.dispatchEvent(e)}applyTemplate(e=""){let t=e||this.#u;if(this.#g(this.#e),this.#e=[],this.innerHTML="",t){let l=document.createElement("template");l.innerHTML=t.trim();let r=l.content.cloneNode(!0);Array.from(r.childNodes).forEach(s=>this.#E(s)),this.#$(r)}let i=++this.#k;new Promise(l=>{let r=null,s,n=()=>{clearTimeout(r),r=setTimeout(()=>{s.disconnect(),this.#A(Array.from(this.children)).then(l)},0)};s=new MutationObserver(h=>{h.some(a=>a.type==="childList")&&n()}),s.observe(this,{childList:!0}),n()}).then(()=>{i===this.#k&&(this.#S=!0,this.dispatchEvent("rendered"))})}#$(e){HTMLElement.prototype.appendChild.call(this,e)}clone(e={}){let t=this.attrs.get("app");return y.extend(t,e)}watch(e,t,i={}){if(typeof t!="function")return()=>{};let{deep:l=!1,immediate:r=!1}=i;if(typeof e=="string"&&e.endsWith("()")){let s=e.slice(0,-2),n=this[s];if(typeof n!="function")return()=>{};let h=this.#n.get(s);if(!h){h={original:n,handlers:[]},this.#n.set(s,h);let f=(...o)=>{let u=n.apply(this,o),c=d=>{for(let p of[...h.handlers])p.callback(o,d,p.unwatch)};return u instanceof Promise?u.then(d=>(c(d),d)):(c(u),u)};this[s]=f}let a=()=>{let f=h.handlers.findIndex(o=>o.unwatch===a);f!==-1&&h.handlers.splice(f,1),h.handlers.length===0&&(this[s]=h.original,this.#n.delete(s))};return h.handlers.push({callback:t,unwatch:a}),a}if(typeof e=="string"){let s=e,n=()=>{let a=this.#t.findIndex(f=>f.unwatch===n);a!==-1&&this.#t.splice(a,1)},h={type:"key",key:s,callback:t,deep:l,immediate:r,lastValue:void 0,unwatch:n};if(this.#t.push(h),r){let a=this.#T(s);h.lastValue=l&&a!==null&&typeof a=="object"?JSON.parse(JSON.stringify(a)):a,t(a,void 0,n)}return n}if(typeof e=="function"){let s=e,n,h={type:"getter",getter:s,callback:t,deep:l,lastValue:n,effect:null,unwatch:null};this.#t.push(h);let a=()=>{let u=this.#t.indexOf(h);u!==-1&&this.#t.splice(u,1),h.effect&&(this.#s.forEach((c,d)=>{c.delete(h.effect),c.size===0&&this.#s.delete(d)}),this.#h.delete(h.effect))};h.unwatch=a;let f=()=>{let u=s.call(this);if(l?!this.#N(u,n):u!==n){let d=n;n=l&&u!==null&&typeof u=="object"?JSON.parse(JSON.stringify(u)):u,t(u,d,h.unwatch)}},o=this.#f(f);return h.effect=o,a}return()=>{}}unwatch(){[...this.#t].forEach(e=>e.unwatch()),this.#n.forEach(e=>{[...e.handlers].forEach(t=>t.unwatch())})}hasWatchers(){let e=0;return this.#n.forEach(t=>{e+=t.handlers.length}),this.#t.length+e}watched(e,t,i={}){if(typeof e=="string"&&e.endsWith("()")){let l=e.slice(0,-2),r=this.#n.get(l);r&&[...r.handlers].forEach(s=>s.unwatch())}else typeof e=="string"?this.#t.filter(l=>l.type==="key"&&l.key===e).forEach(l=>l.unwatch()):typeof e=="function"&&this.#t.filter(l=>l.type==="getter"&&l.getter===e).forEach(l=>l.unwatch());return this.watch(e,t,i)}#v(e){this.#y&&(this.#s.has(e)||this.#s.set(e,new Set),this.#s.get(e).add(this.#y))}#a(e){this.#b.add(e);let t=this.#s.get(e);if(t&&t.forEach(l=>this.#h.add(l)),this.#m){this.#x=!0;return}this.#m=!0;let i=()=>{this.#h.forEach(s=>{try{s()}catch(n){console.error("Effect execution error:",n)}}),this.#h.clear();let l=Array.from(this.#b),r=new Set;for(let s of l)for(let n of this.#t){if(n.type!=="key")continue;(n.key===s||n.deep&&(s===n.key||s.startsWith(n.key+".")))&&r.add(n)}for(let s of r){if(s.type!=="key")continue;let n=this.#T(s.key);if(!(s.deep?!this.#N(n,s.lastValue):n!==s.lastValue))continue;let a=s.lastValue;s.lastValue=s.deep&&n!==null&&typeof n=="object"?JSON.parse(JSON.stringify(n)):n,s.callback(n,a,s.unwatch)}this.#b.clear(),this.#m=!1,this.#x&&(this.#x=!1,this.#m=!0,Promise.resolve().then(i))};Promise.resolve().then(i)}#T(e){return e.split(".").reduce((t,i)=>t?.[i],this)}#N(e,t){if(Object.is(e,t))return!0;if(e===null||t===null||typeof e!="object"||typeof t!="object")return!1;let i=Object.keys(e),l=Object.keys(t);if(i.length!==l.length)return!1;for(let r of i)if(!l.includes(r)||!this.#N(e[r],t[r]))return!1;return!0}#c(e,t=[]){if(e===null||typeof e!="object"||e.__isReactive)return e;let i=this;return new Proxy(e,{get(r,s,n){if(s==="__isReactive")return!0;let h=typeof s=="symbol"?"<symbol>":s,a=[...t,h].join(".");i.#v(a);let f=Reflect.get(r,s,n);return f!==null&&typeof f=="object"&&!f.__isReactive?i.#c(f,[...t,h]):f},set(r,s,n,h){if(r[s]===n)return!0;let f=Reflect.set(r,s,n,h),o=typeof s=="symbol"?"<symbol>":s,u=[...t,o].join(".");if(i.#a(u),Array.isArray(r)&&(s==="length"||!isNaN(s))){let c=t.join(".");c&&i.#a(c)}return f},deleteProperty(r,s){let n=Reflect.deleteProperty(r,s),h=typeof s=="symbol"?"<symbol>":s,a=[...t,h].join(".");return i.#a(a),n}})}#j(e,t){let i=this;return new Proxy(e,{apply(l,r,s){let n=Reflect.apply(l,i,s);return n instanceof Promise?n.then(h=>(i.#a(t),h)):(i.#a(t),n)}})}#f(e){let t=this.#r?{...this.#r}:null,i=()=>{let l=null;if(t){l={};for(let r of Object.keys(t))l[r]=this[r],this[r]=t[r]}this.#y=i;try{e()}finally{if(this.#y=null,l)for(let r of Object.keys(l))l[r]!==void 0?this[r]=l[r]:delete this[r]}};return i(),i}#o(e){try{return new Function("$event",`with(this) { return (${e}); }`).call(this)}catch(t){console.warn("Expression evaluation error:",e,t);return}}#L(e,t=null){try{return new Function("$event",`with(this) { ${e} }`).call(this,t)}catch(i){console.error("Statement execution error:",e,i)}}#V(e){let t=e.nodeValue,i=[],l=[],r=0,s=/\{\{(.+?)\}\}/g,n;for(;(n=s.exec(t))!==null;){n.index>r&&i.push(t.substring(r,n.index));let a=n[1].trim();i.push(null),l.push({index:i.length-1,expr:a}),r=s.lastIndex}r<t.length&&i.push(t.substring(r));let h=this.#f(()=>{l.forEach(({index:a,expr:f})=>{let o=this.#o(f);i[a]=o==null?"":String(o)}),e.nodeValue=i.join("")});this.#e.push({type:"text",node:e,effect:h})}#I(e,t){let i=t.name.slice(1),l=t.value,r=this.#r?{...this.#r}:null,s=n=>{if(r){let h={};for(let a of Object.keys(r))h[a]=this[a],this[a]=r[a];this.#L(l,n);for(let a of Object.keys(h))h[a]!==void 0?this[a]=h[a]:delete this[a]}else this.#L(l,n)};e.addEventListener(i,s),this.#e.push({type:"event",element:e,eventName:i,handler:s})}#B(e,t){let i=t.value,l=this.#f(()=>{this.#o(i)?e.style.display="":e.style.display="none"});this.#e.push({type:"show",element:e,effect:l})}#R(e,t){let i=t.value,l=this.#f(()=>{let h=this.#o(i);e.tagName==="INPUT"&&e.type==="checkbox"?e.checked=!!h:e.tagName==="INPUT"&&e.type==="radio"?e.checked=e.value===h:e.tagName==="SELECT"?e.value=h:e.value=h??""}),r=this.#r?{...this.#r}:null,s=e.tagName==="SELECT"?"change":"input",n=h=>{let a;if(e.type==="checkbox"?a=e.checked:e.type==="number"||e.type==="range"?a=e.valueAsNumber:a=e.value,r){let f={};for(let o of Object.keys(r))f[o]=this[o],this[o]=r[o];try{new Function("value",`with(this) { ${i} = value; }`).call(this,a)}catch(o){console.error("Model binding error:",i,o)}for(let o of Object.keys(f))f[o]!==void 0?this[o]=f[o]:delete this[o]}else try{new Function("value",`with(this) { ${i} = value; }`).call(this,a)}catch(f){console.error("Model binding error:",i,f)}};e.addEventListener(s,n),this.#e.push({type:"model",element:e,effect:l,handler:n})}#W(e,t){let i=t.value,l=document.createComment(`if: ${i}`);e.parentNode.insertBefore(l,e);let r=[{expr:i,element:e,bindings:[],processed:!1}],s=e.nextElementSibling;for(;s;)if(s.hasAttribute("#else-if")){let a=s.getAttribute("#else-if");r.push({expr:a,element:s,bindings:[],processed:!1}),s.removeAttribute("#else-if");let f=s.nextElementSibling;s.remove(),s=f}else if(s.hasAttribute("#else")){r.push({expr:"true",element:s,bindings:[],processed:!1}),s.removeAttribute("#else"),s.remove();break}else break;e.removeAttribute(t.name),e.remove();let n=null,h=this.#f(()=>{let a=null;for(let f of r)if(this.#o(f.expr)){a=f;break}if(n!==a){if(n&&(n.element&&n.element.parentNode&&n.element.remove(),this.#g(n.bindings),n.bindings=[]),a&&(l.parentNode.insertBefore(a.element,l.nextSibling),!a.processed)){let f=this.#e.length;this.#E(a.element),a.bindings=this.#e.slice(f),a.processed=!0}n=a}});this.#e.push({type:"conditional",placeholder:l,chain:r,effect:h})}#F(e,t){let i=t.value,l=i.match(/^\s*(\w+)\s+in\s+(.+)$/);if(!l){console.error("Invalid for syntax:",i);return}let r=l[1],s=l[2],n=e.parentNode,h=e.nextSibling;e.removeAttribute(t.name);let a=e.cloneNode(!0);e.remove();let f=[],o=this.#f(()=>{let u=this.#o(s);f.forEach(p=>{p.node&&p.node.parentNode&&p.node.remove(),this.#g(p.bindings)}),f=[];let c;if(Array.isArray(u))c=u.map((p,m)=>({value:p,key:void 0,index:m}));else if(u!==null&&typeof u=="object")c=Object.entries(u).map(([p,m],b)=>({value:m,key:p,index:b}));else return;if(c.length===0)return;let d=document.createDocumentFragment();c.forEach(({value:p,key:m,index:b})=>{let g=a.cloneNode(!0),E=this[r],w=this.$index,x=this.$key;this[r]=p,this.$index=b,m!==void 0&&(this.$key=m);let N=this.#r,A={...N,[r]:p,$index:b};m!==void 0&&(A.$key=m),this.#r=A;let O=this.#e.length;this.#E(g);let S=this.#e.slice(O);this.#r=N,E!==void 0?this[r]=E:delete this[r],w!==void 0?this.$index=w:delete this.$index,x!==void 0?this.$key=x:delete this.$key,d.appendChild(g),f.push({node:g,bindings:S})}),n.insertBefore(d,h)});this.#e.push({type:"loop",parent:n,nextSibling:h,template:a,effect:o})}#D(e,t){let i=t.name,l=t.value,r=[],s=[],n=0,h=/\{\{(.+?)\}\}/g,a;for(;(a=h.exec(l))!==null;){a.index>n&&r.push(l.substring(n,a.index));let o=a[1].trim();r.push(null),s.push({index:r.length-1,expr:o}),n=h.lastIndex}n<l.length&&r.push(l.substring(n));let f=this.#f(()=>{s.forEach(({index:u,expr:c})=>{let d=this.#o(c);r[u]=d==null?"":String(d)});let o=r.join("");y.#C.has(i)?o===""||o==="false"||o==="0"||o==="null"||o==="undefined"||!o?e.removeAttribute(i):e.setAttribute(i,""):e.setAttribute(i,o)});this.#e.push({type:"attribute",element:e,attrName:i,effect:f})}#J(e){let t=Array.from(e.attributes);for(let i of t){if(i.name==="#if")return this.#W(e,i),e.removeAttribute(i.name),!0;if(i.name==="#for")return this.#F(e,i),e.removeAttribute(i.name),!0;if(i.name==="#show")this.#B(e,i),e.removeAttribute(i.name);else if(i.name==="#model")this.#R(e,i),e.removeAttribute(i.name);else if(i.name==="#once")e.removeAttribute(i.name);else{if(i.name==="#pre")return e.removeAttribute(i.name),!0;i.name.startsWith("@")?(this.#I(e,i),e.removeAttribute(i.name)):/\{\{.+?\}\}/.test(i.value)&&this.#D(e,i)}}return!1}#E(e){if(e.nodeType===Node.ELEMENT_NODE){let t=this.#J(e);if(e.localName==="st-app")return;!t&&(e.parentNode||e.childNodes.length>0)&&Array.from(e.childNodes).forEach(i=>this.#E(i))}else e.nodeType===Node.TEXT_NODE&&/\{\{.+?\}\}/.test(e.nodeValue)&&this.#V(e)}#P(){let e=this.attrs.get("app"),t=y.#d.get(e);if(t){this.addEventListener("setup",t.setup),Object.entries(t.events).forEach(([s,n])=>this.addEventListener(s,n)),this.#u=t.template;let i=t.config,l=Object.getOwnPropertyDescriptors(i),r=new Set(["app","setup","template","events"]);Object.entries(l).forEach(([s,n])=>{if(!r.has(s)){if(n.get){let h=n.get;this.#M.set(s,h),Object.defineProperty(this,s,{get(){return this.#v(s),h.call(this)},enumerable:n.enumerable,configurable:!0})}else if(n.value!==void 0){let h=n.value,a=h;typeof h=="object"&&h!==null?a=this.#c(h,[s]):typeof h=="function"&&(a=this.#j(h,s)),Object.defineProperty(this,s,{get(){return this.#v(s),a},set(f){a!==f&&(typeof f=="object"&&f!==null?a=this.#c(f,[s]):a=f,this.#a(s))},enumerable:!0,configurable:!0})}}}),typeof this.#i=="function"&&this.#i(),this.#i=!0}else this.attrs.get("app")||(typeof this.#i=="function"&&this.#i(),this.#i=!0)}async#A(e){await Promise.all(e.map(t=>new Promise(i=>{let l=null,r=()=>{clearTimeout(l),l=setTimeout(()=>{s.disconnect(),this.#A(Array.from(t.children)).then(i)},0)},s=new MutationObserver(n=>{n.some(h=>h.type==="childList")&&r()});s.observe(t,{childList:!0}),r()})))}#O(e){return e==null?"":e===!0?"true":e===!1?"false":typeof e=="number"?String(e):typeof e=="object"?JSON.stringify(e):String(e)}#w(e){if(!e.startsWith(":")||e==="app")return;let t=e.replace(/^:+/,""),i=this.getAttribute(e),l=Object.getOwnPropertyDescriptor(this,t),r=i;if(!i&&l&&(l.get||l.value!==void 0)){let s=this[t],n=this.#O(s);this.getAttribute(e)!==n&&this.setAttribute(e,n),r=s,l=null}if(!(l&&l.set===void 0&&l.writable===!1)&&!(l&&l.get!==void 0&&l.set===void 0)){if(i)if(i==="true")r=!0;else if(i==="false")r=!1;else if(/^-?\d+(\.\d+)?$/.test(i))r=Number(i);else try{r=JSON.parse(i)}catch{r=i}if(!l||!l.set){let s=r;typeof r=="object"&&r!==null?s=this.#c(r,[t]):typeof r=="function"&&(s=this.#j(r,t));let n=e;if(Object.defineProperty(this,t,{get(){return this.#v(t),s},set(h){if(s!==h){typeof h=="object"&&h!==null?s=this.#c(h,[t]):s=h,this.#a(t);let a=this.#O(h);this.getAttribute(n)!==a&&this.setAttribute(n,a)}},enumerable:!0,configurable:!0}),typeof r=="object"&&r!==null){let h=this.watch(t,()=>{let a=this[t],f=this.#O(a);this.getAttribute(e)!==f&&this.setAttribute(e,f)},{deep:!0});this.#e.push({type:"attrSync",unwatch:h})}}else this[t]=r}}attributeChangedCallback(e,t,i){e.startsWith(":")&&e!=="app"&&t!==i&&this.#i===!0&&this.#w(e)}connectedCallback(){if(y.#p.add(this),this.#i===!0){this.#l||(this.#l=new MutationObserver(e=>{for(let t of e)t.type==="attributes"&&t.attributeName&&t.attributeName.startsWith(":")&&t.attributeName!=="app"&&this.#w(t.attributeName)}),this.#l.observe(this,{attributes:!0}));return}this.#P(),Promise.all([new Promise(e=>{if(this.#i===!0)return e();this.#i=e}),new Promise(e=>{let t=null,i=()=>{clearTimeout(t),t=setTimeout(()=>{l.disconnect(),this.#A(Array.from(this.children)).then(e)},0)},l=new MutationObserver(r=>{r.some(s=>s.type==="childList")&&i()});l.observe(this,{childList:!0}),i()})]).then(()=>{this.dispatchEvent("setup");for(let t of this.attrs.keys())!t.startsWith(":")||t==="app"||this.#w(t);let e=!1;this.childNodes.length>0&&Array.from(this.childNodes).some(i=>i.nodeType===Node.ELEMENT_NODE||i.nodeType===Node.TEXT_NODE&&i.textContent.trim()!=="")&&(this.#u?(this.applyTemplate(this.innerHTML),e=!0):this.#u=this.innerHTML),e||this.applyTemplate(),this.#i===!0&&!this.#l&&(this.#l=new MutationObserver(t=>{for(let i of t)i.type==="attributes"&&i.attributeName&&i.attributeName.startsWith(":")&&i.attributeName!=="app"&&this.#w(i.attributeName)}),this.#l.observe(this,{attributes:!0}))})}disconnectedCallback(){this.#l&&(this.#l.disconnect(),this.#l=null),this.#g(this.#e),this.#e=[];for(let e of this.#t)e.type==="getter"&&e.effect&&(this.#s.forEach((t,i)=>{t.delete(e.effect),t.size===0&&this.#s.delete(i)}),this.#h.delete(e.effect));this.#t=[],this.#n.forEach((e,t)=>{this[t]=e.original}),this.#n.clear(),this.#b.clear(),this.#s.clear(),this.#h.clear(),y.#p.delete(this)}toggleAttribute(e,t="",i=""){let l=this.getAttribute(e);this[t==""&&i==""&&(l||this.hasAttribute(e))?"removeAttribute":"setAttribute"](e,l!=t?t:i)}static{customElements.define("st-app",this)}};export{v as default};
|
|
1
|
+
var O=class p extends HTMLElement{static#z=new Set(["disabled","checked","readonly","required","selected","hidden","open","autofocus"]);static#y=new Map;static#m=new Set;static#L=new WeakMap;static create(e){let{app:t,setup:i=()=>{},template:s="",events:n={}}=e;if(p.#y.has(t))throw new Error(`Application "${t}" already exists!`);p.#y.set(t,{setup:i,template:s,events:n,config:e}),p.#m.forEach(r=>{r.#i!==!0&&r.#J()})}static extend(e,t={}){let i=p.#y.get(e);if(!i)throw new Error(`Application "${e}" not found!`);let s=i.config,n=Object.defineProperties({},{...Object.getOwnPropertyDescriptors(s),...Object.getOwnPropertyDescriptors(t)});return(s.events||t.events)&&(n.events={...s.events,...t.events}),p.create(n)}#i=!1;#c="";#M=!1;#s=new Map;#f=null;#o=new Set;#b=!1;#e=[];#r=null;#F=new Map;#l=null;#t=[];#g=new Set;#N=!1;#n=new Map;#k=0;#C="";#A=!1;constructor(){super(),p.#m.add(this)}#v(e){!e||!e.length||e.forEach(t=>{if(t.type==="event"&&t.element&&t.handler)t.element.removeEventListener(t.eventName,t.handler);else if(t.type==="model"&&t.element&&t.handler){let i=t.element.tagName==="SELECT"?"change":"input";t.element.removeEventListener(i,t.handler)}else t.type==="attrSync"&&t.unwatch&&t.unwatch();t.dispose?.(),t.effect&&(this.#s.forEach((i,s)=>{i.delete(t.effect),i.size===0&&this.#s.delete(s)}),this.#o.delete(t.effect))})}get template(){return this.#c}get attrs(){return{get:e=>this.getAttribute(e),set:(e,t)=>this.setAttribute(e,t),remove:e=>this.removeAttribute(e),has:e=>this.hasAttribute(e),toggle:(e,t)=>this.toggleAttribute(e,t),keys:()=>Array.from(this.attributes).map(e=>e.name),entries:()=>Array.from(this.attributes).map(e=>[e.name,e.value])}}addEventListener(e,t,i){if((e==="setup"||e==="rendered")&&this.#M){queueMicrotask(()=>{let s=new CustomEvent(e);typeof t=="function"?t.call(this,s):t?.handleEvent?.(s)});return}super.addEventListener(e,t,i)}dispatchEvent(e,t=null,i={}){if(typeof e=="string"){let s=new CustomEvent(e,{cancelable:!0,...i,detail:t});return super.dispatchEvent(s)}return super.dispatchEvent(e)}applyTemplate(e=""){let t=e||this.#c;if(this.#C=t,this.#v(this.#e),this.#e=[],this.innerHTML="",t){let s=document.createElement("template");s.innerHTML=t.trim();let n=s.content.cloneNode(!0);Array.from(n.childNodes).forEach(r=>this.#E(r)),this.#q(n)}let i=++this.#k;new Promise(s=>{let n=null,r,l=()=>{clearTimeout(n),n=setTimeout(()=>{r.disconnect(),this.#P(Array.from(this.children)).then(s)},0)};r=new MutationObserver(h=>{h.some(a=>a.type==="childList")&&l()}),r.observe(this,{childList:!0}),l()}).then(()=>{i===this.#k&&(this.#M=!0,this.dispatchEvent("rendered"))})}#q(e){HTMLElement.prototype.appendChild.call(this,e)}clone(e={}){let t=this.attrs.get("app");return p.extend(t,e)}watch(e,t,i={}){if(typeof t!="function")return()=>{};let{deep:s=!1,immediate:n=!1}=i;if(typeof e=="string"&&e.endsWith("()")){let r=e.slice(0,-2),l=this[r];if(typeof l!="function")return()=>{};let h=this.#n.get(r);if(!h){h={original:l,handlers:[]},this.#n.set(r,h);let o=(...u)=>{let f=l.apply(this,u),d=c=>{for(let b of[...h.handlers])b.callback(u,c,b.unwatch)};return f instanceof Promise?f.then(c=>(d(c),c)):(d(f),f)};this[r]=o}let a=()=>{let o=h.handlers.findIndex(u=>u.unwatch===a);o!==-1&&h.handlers.splice(o,1),h.handlers.length===0&&(this[r]=h.original,this.#n.delete(r))};return h.handlers.push({callback:t,unwatch:a}),a}if(typeof e=="string"){let r=e,l=()=>{let a=this.#t.findIndex(o=>o.unwatch===l);a!==-1&&this.#t.splice(a,1)},h={type:"key",key:r,callback:t,deep:s,immediate:n,lastValue:void 0,unwatch:l};if(this.#t.push(h),n){let a=this.#$(r);h.lastValue=s&&a!==null&&typeof a=="object"?JSON.parse(JSON.stringify(a)):a,t(a,void 0,l)}return l}if(typeof e=="function"){let r=e,l,h={type:"getter",getter:r,callback:t,deep:s,lastValue:l,effect:null,unwatch:null};this.#t.push(h);let a=()=>{let f=this.#t.indexOf(h);f!==-1&&this.#t.splice(f,1),h.effect&&(this.#s.forEach((d,c)=>{d.delete(h.effect),d.size===0&&this.#s.delete(c)}),this.#o.delete(h.effect))};h.unwatch=a;let o=()=>{let f=r.call(this);if(s?!this.#O(f,l):f!==l){let c=l;l=s&&f!==null&&typeof f=="object"?JSON.parse(JSON.stringify(f)):f,t(f,c,h.unwatch)}},u=this.#h(o);return h.effect=u,a}return()=>{}}unwatch(){[...this.#t].forEach(e=>e.unwatch()),this.#n.forEach(e=>{[...e.handlers].forEach(t=>t.unwatch())})}hasWatchers(){let e=0;return this.#n.forEach(t=>{e+=t.handlers.length}),this.#t.length+e}watched(e,t,i={}){if(typeof e=="string"&&e.endsWith("()")){let s=e.slice(0,-2),n=this.#n.get(s);n&&[...n.handlers].forEach(r=>r.unwatch())}else typeof e=="string"?this.#t.filter(s=>s.type==="key"&&s.key===e).forEach(s=>s.unwatch()):typeof e=="function"&&this.#t.filter(s=>s.type==="getter"&&s.getter===e).forEach(s=>s.unwatch());return this.watch(e,t,i)}#w(e){this.#f&&(this.#s.has(e)||this.#s.set(e,new Set),this.#s.get(e).add(this.#f))}#u(e){this.#g.add(e);let t=this.#s.get(e);if(t&&t.forEach(s=>this.#o.add(s)),this.#b){this.#N=!0;return}this.#b=!0;let i=()=>{this.#o.forEach(r=>{try{r()}catch(l){console.error("Effect execution error:",l)}}),this.#o.clear();let s=Array.from(this.#g),n=new Set;for(let r of s)for(let l of this.#t){if(l.type!=="key")continue;(l.key===r||l.deep&&(r===l.key||r.startsWith(l.key+".")))&&n.add(l)}for(let r of n){if(r.type!=="key")continue;let l=this.#$(r.key);if(!(r.deep?!this.#O(l,r.lastValue):l!==r.lastValue))continue;let a=r.lastValue;r.lastValue=r.deep&&l!==null&&typeof l=="object"?JSON.parse(JSON.stringify(l)):l,r.callback(l,a,r.unwatch)}this.#g.clear(),this.#b=!1,this.#N&&(this.#N=!1,this.#b=!0,Promise.resolve().then(i))};Promise.resolve().then(i)}#$(e){return e.split(".").reduce((t,i)=>t?.[i],this)}#O(e,t){if(Object.is(e,t))return!0;if(e===null||t===null||typeof e!="object"||typeof t!="object")return!1;let i=Object.keys(e),s=Object.keys(t);if(i.length!==s.length)return!1;for(let n of i)if(!s.includes(n)||!this.#O(e[n],t[n]))return!1;return!0}static#V(e){return e!==null&&typeof e=="object"?e.__raw??e:e}#I=new WeakMap;#p(e,t=[]){if(e===null||typeof e!="object"||e.__isReactive)return e;let i=t.join("."),s=this.#I.get(e);if(s||this.#I.set(e,s=new Map),s.has(i))return s.get(i);let n=this,r=new Proxy(e,{get(l,h,a){if(h==="__isReactive")return!0;if(h==="__raw")return l;let o=typeof h=="symbol"?"<symbol>":h,u=[...t,o].join(".");n.#w(u);let f=Reflect.get(l,h,a);return f!==null&&typeof f=="object"&&!f.__isReactive?n.#p(f,[...t,o]):f},set(l,h,a,o){if(l[h]===a)return!0;let f=Reflect.set(l,h,a,o),d=typeof h=="symbol"?"<symbol>":h,c=[...t,d].join(".");if(n.#u(c),Array.isArray(l)&&(h==="length"||!isNaN(h))){let b=t.join(".");b&&n.#u(b)}return f},deleteProperty(l,h){let a=Reflect.deleteProperty(l,h),o=typeof h=="symbol"?"<symbol>":h,u=[...t,o].join(".");return n.#u(u),a}});return s.set(i,r),r}#R(e,t){let i=this;return new Proxy(e,{apply(s,n,r){let l=Reflect.apply(s,i,r);return i.#f?l:l instanceof Promise?l.then(h=>(i.#u(t),h)):(i.#u(t),l)}})}#h(e){let t=this.#r?{...this.#r}:null,i=()=>{let s=this.#f;this.#f=i;try{t?this.#d(t,e):e()}finally{this.#f=s}};return i(),i}static#W=new Map;static#S(e){let t=p.#W.get(e);return t||(t=new Function("$s","$event","$__v",`with($s) { ${e} }`),p.#W.set(e,t)),t}#K=null;get#T(){return this.#K??=new Proxy(this,{has:(e,t)=>typeof t=="string"&&t in e,get:(e,t)=>{if(t===Symbol.unscopables)return;let i=Reflect.get(e,t);return typeof i=="function"&&!Object.hasOwn(e,t)?i.bind(e):i},set:(e,t,i)=>Reflect.set(e,t,i)})}#a(e){try{return p.#S(`return (${e});`).call(this,this.#T)}catch(t){console.warn("Expression evaluation error:",e,t);return}}#D(e,t=null){try{return p.#S(e).call(this,this.#T,t)}catch(i){console.error("Statement execution error:",e,i)}}#H(e,t){try{p.#S(`${e} = $__v;`).call(this,this.#T,null,t)}catch(i){console.error("Model binding error:",e,i)}}#U(e){let t=e.nodeValue,i=[],s=[],n=0,r=/\{\{(.+?)\}\}/g,l;for(;(l=r.exec(t))!==null;){l.index>n&&i.push(t.substring(n,l.index));let a=l[1].trim();i.push(null),s.push({index:i.length-1,expr:a}),n=r.lastIndex}n<t.length&&i.push(t.substring(n));let h=this.#h(()=>{s.forEach(({index:a,expr:o})=>{let u=this.#a(o);i[a]=u==null?"":String(u)}),e.nodeValue=i.join("")});this.#e.push({type:"text",node:e,effect:h})}#X(e,t){let i=t.name.slice(1),s=t.value,n=this.#r?{...this.#r}:null,r=l=>{n?this.#d(n,()=>this.#D(s,l)):this.#D(s,l)};e.addEventListener(i,r),this.#e.push({type:"event",element:e,eventName:i,handler:r})}#G(e,t){let i=t.value,s=this.#h(()=>{let n=this.#a(i);e.innerHTML=n==null?"":String(n)});this.#e.push({type:"html",element:e,effect:s})}#Q(e,t){let i=t.value,s=this.#h(()=>{this.#a(i)?e.style.display="":e.style.display="none"});this.#e.push({type:"show",element:e,effect:s})}#Y(e,t){let i=t.value,s=this.#h(()=>{let h=this.#a(i);if(e.tagName==="INPUT"&&e.type==="checkbox")e.checked=!!h;else if(e.tagName==="INPUT"&&e.type==="radio")e.checked=e.value===h;else if(e.tagName==="SELECT"){let a=()=>{e.value=h};p.#L.set(e,a),a(),queueMicrotask(a)}else e.value=h??""}),n=this.#r?{...this.#r}:null,r=e.tagName==="SELECT"?"change":"input",l=h=>{let a;e.type==="checkbox"?a=e.checked:e.type==="number"||e.type==="range"?a=e.valueAsNumber:a=e.value,n?this.#d(n,()=>this.#H(i,a)):this.#H(i,a)};e.addEventListener(r,l),this.#e.push({type:"model",element:e,effect:s,handler:l})}#Z(e,t){let i=t.value,s=document.createComment(`if: ${i}`);e.parentNode.insertBefore(s,e),e.removeAttribute(t.name);let n=[{expr:i,template:e.cloneNode(!0)}],r=e.nextElementSibling;for(;r;)if(r.hasAttribute("#else-if")){let o=r.getAttribute("#else-if");r.removeAttribute("#else-if"),n.push({expr:o,template:r.cloneNode(!0)});let u=r.nextElementSibling;r.remove(),r=u}else if(r.hasAttribute("#else")){r.removeAttribute("#else"),n.push({expr:"true",template:r.cloneNode(!0)}),r.remove();break}else break;e.remove();let l={branch:null,node:null,bindings:[]},h=()=>{l.node?.remove(),this.#v(l.bindings),l.node=null,l.bindings=[]},a=this.#h(()=>{let o=n.find(f=>this.#a(f.expr))??null;if(l.branch===o||(h(),l.branch=o,!o))return;let u=o.template.cloneNode(!0);s.parentNode.insertBefore(u,s.nextSibling),l.bindings=this.#B(()=>this.#E(u)),l.node=u});this.#e.push({type:"conditional",placeholder:s,effect:a,dispose:h})}#B(e){let t=this.#e.length;return e(),this.#e.splice(t)}#d(e,t){let i={};for(let n of Object.keys(e))i[n]=this[n],this[n]=e[n];let s=this.#r;this.#r={...s,...e};try{return t()}finally{this.#r=s;for(let n of Object.keys(i))i[n]!==void 0?this[n]=i[n]:delete this[n]}}#_(e,t){let i=t.value,s=i.match(/^\s*(\w+)\s+in\s+(.+)$/);if(!s){console.error("Invalid for syntax:",i);return}let n=s[1],r=s[2],l=e.getAttribute("#key");e.removeAttribute(t.name),e.removeAttribute("#key");let h=document.createComment(`for: ${i}`);e.parentNode.insertBefore(h,e);let a=e.cloneNode(!0);e.remove();let o=a.outerHTML.includes("$index"),u=new Map,f=c=>{c.node.remove(),this.#v(c.bindings)},d=this.#h(()=>{let c=this.#a(r),b=[];Array.isArray(c)?b=c.map((m,y)=>({value:m,key:void 0,index:y})):c!==null&&typeof c=="object"&&(b=Object.entries(c).map(([m,y],w)=>({value:y,key:m,index:w})));let E=new Map,x=[];b.forEach(({value:m,key:y,index:w})=>{let A={[n]:m,$index:w};y!==void 0&&(A.$key=y);let g=l?this.#d(A,()=>this.#a(l)):Symbol();l&&E.has(g)&&console.warn("Duplicate #key in #for:",i,g);let v=u.get(g);if(v&&p.#V(v.value)===p.#V(m)&&(v.index===w||!o&&v.key===y&&!Array.isArray(c))){u.delete(g),E.set(g,v),x.push(v);return}let T=a.cloneNode(!0),j=this.#d(A,()=>this.#B(()=>this.#E(T))),P={node:T,bindings:j,value:m,index:w,key:y};E.set(g,P),x.push(P)}),u.forEach(f),u=E;let N=h;for(let m=x.length-1;m>=0;m--){let y=x[m].node;y.nextSibling!==N&&h.parentNode.insertBefore(y,N),N=y}let S=h.parentNode?.closest?.("select");S&&p.#L.get(S)?.()});this.#e.push({type:"loop",anchor:h,template:a,effect:d,dispose:()=>{u.forEach(f),u.clear()}})}#ee(e,t){let i=t.name,s=t.value,n=[],r=[],l=0,h=/\{\{(.+?)\}\}/g,a;for(;(a=h.exec(s))!==null;){a.index>l&&n.push(s.substring(l,a.index));let u=a[1].trim();n.push(null),r.push({index:n.length-1,expr:u}),l=h.lastIndex}l<s.length&&n.push(s.substring(l));let o=this.#h(()=>{r.forEach(({index:f,expr:d})=>{let c=this.#a(d);n[f]=c==null?"":String(c)});let u=n.join("");p.#z.has(i)?u===""||u==="false"||u==="0"||u==="null"||u==="undefined"||!u?e.removeAttribute(i):e.setAttribute(i,""):e.setAttribute(i,u)});this.#e.push({type:"attribute",element:e,attrName:i,effect:o})}#te(e){let t=Array.from(e.attributes);for(let i of t){if(i.name==="#if")return this.#Z(e,i),e.removeAttribute(i.name),!0;if(i.name==="#for")return this.#_(e,i),e.removeAttribute(i.name),!0;if(i.name==="#html")return this.#G(e,i),e.removeAttribute(i.name),!0;if(i.name==="#show")this.#Q(e,i),e.removeAttribute(i.name);else if(i.name==="#model")this.#Y(e,i),e.removeAttribute(i.name);else if(i.name==="#once")e.removeAttribute(i.name);else{if(i.name==="#pre")return e.removeAttribute(i.name),!0;i.name.startsWith("@")?(this.#X(e,i),e.removeAttribute(i.name)):/\{\{.+?\}\}/.test(i.value)&&this.#ee(e,i)}}return!1}#E(e){if(e.nodeType===Node.ELEMENT_NODE){let t=this.#te(e);if(e.localName==="st-app")return;!t&&(e.parentNode||e.childNodes.length>0)&&Array.from(e.childNodes).forEach(i=>this.#E(i))}else e.nodeType===Node.TEXT_NODE&&/\{\{.+?\}\}/.test(e.nodeValue)&&this.#U(e)}#J(){let e=this.attrs.get("app"),t=p.#y.get(e);if(t){this.addEventListener("setup",t.setup),Object.entries(t.events).forEach(([r,l])=>this.addEventListener(r,l)),this.#c=t.template;let i=t.config,s=Object.getOwnPropertyDescriptors(i),n=new Set(["app","setup","template","events"]);Object.entries(s).forEach(([r,l])=>{if(!n.has(r)){if(l.get){let h=l.get;this.#F.set(r,h),Object.defineProperty(this,r,{get(){return this.#w(r),h.call(this)},enumerable:l.enumerable,configurable:!0})}else if(l.value!==void 0){let h=l.value,a=h;typeof h=="object"&&h!==null?a=this.#p(h,[r]):typeof h=="function"&&(a=this.#R(h,r)),Object.defineProperty(this,r,{get(){return this.#w(r),a},set(o){a!==o&&(typeof o=="object"&&o!==null?a=this.#p(o,[r]):a=o,this.#u(r))},enumerable:!0,configurable:!0})}}}),typeof this.#i=="function"&&this.#i(),this.#i=!0}else this.attrs.get("app")||(typeof this.#i=="function"&&this.#i(),this.#i=!0)}async#P(e){await Promise.all(e.map(t=>new Promise(i=>{let s=null,n=()=>{clearTimeout(s),s=setTimeout(()=>{r.disconnect(),this.#P(Array.from(t.children)).then(i)},0)},r=new MutationObserver(l=>{l.some(h=>h.type==="childList")&&n()});r.observe(t,{childList:!0}),n()})))}#j(e){return e==null?"":e===!0?"true":e===!1?"false":typeof e=="number"?String(e):typeof e=="object"?JSON.stringify(e):String(e)}#x(e){if(!e.startsWith(":")||e==="app")return;let t=e.replace(/^:+/,""),i=this.getAttribute(e),s=Object.getOwnPropertyDescriptor(this,t),n=i;if(!i&&s&&(s.get||s.value!==void 0)){let r=this[t],l=this.#j(r);this.getAttribute(e)!==l&&this.setAttribute(e,l),n=r,s=null}if(!(s&&s.set===void 0&&s.writable===!1)&&!(s&&s.get!==void 0&&s.set===void 0)){if(i)if(i==="true")n=!0;else if(i==="false")n=!1;else if(/^-?\d+(\.\d+)?$/.test(i))n=Number(i);else try{n=JSON.parse(i)}catch{n=i}if(!s||!s.set){let r=n;typeof n=="object"&&n!==null?r=this.#p(n,[t]):typeof n=="function"&&(r=this.#R(n,t));let l=e;if(Object.defineProperty(this,t,{get(){return this.#w(t),r},set(h){if(r!==h){typeof h=="object"&&h!==null?r=this.#p(h,[t]):r=h,this.#u(t);let a=this.#j(h);this.getAttribute(l)!==a&&this.setAttribute(l,a)}},enumerable:!0,configurable:!0}),typeof n=="object"&&n!==null){let h=this.watch(t,()=>{let a=this[t],o=this.#j(a);this.getAttribute(e)!==o&&this.setAttribute(e,o)},{deep:!0});this.#e.push({type:"attrSync",unwatch:h})}}else this[t]=n}}attributeChangedCallback(e,t,i){e.startsWith(":")&&e!=="app"&&t!==i&&this.#i===!0&&this.#x(e)}connectedCallback(){if(p.#m.add(this),this.#i===!0){this.#A&&(this.#A=!1,this.applyTemplate(this.#C)),this.#l||(this.#l=new MutationObserver(e=>{for(let t of e)t.type==="attributes"&&t.attributeName&&t.attributeName.startsWith(":")&&t.attributeName!=="app"&&this.#x(t.attributeName)}),this.#l.observe(this,{attributes:!0}));return}this.#J(),Promise.all([new Promise(e=>{if(this.#i===!0)return e();this.#i=e}),new Promise(e=>{let t=null,i=()=>{clearTimeout(t),t=setTimeout(()=>{s.disconnect(),this.#P(Array.from(this.children)).then(e)},0)},s=new MutationObserver(n=>{n.some(r=>r.type==="childList")&&i()});s.observe(this,{childList:!0}),i()})]).then(()=>{this.dispatchEvent("setup");for(let t of this.attrs.keys())!t.startsWith(":")||t==="app"||this.#x(t);let e=!1;this.childNodes.length>0&&Array.from(this.childNodes).some(i=>i.nodeType===Node.ELEMENT_NODE||i.nodeType===Node.TEXT_NODE&&i.textContent.trim()!=="")&&(this.#c?(this.applyTemplate(this.innerHTML),e=!0):this.#c=this.innerHTML),e||this.applyTemplate(),this.#i===!0&&!this.#l&&(this.#l=new MutationObserver(t=>{for(let i of t)i.type==="attributes"&&i.attributeName&&i.attributeName.startsWith(":")&&i.attributeName!=="app"&&this.#x(i.attributeName)}),this.#l.observe(this,{attributes:!0}))})}disconnectedCallback(){queueMicrotask(()=>{this.isConnected||this.#ie()})}#ie(){this.#A=!0,this.#l&&(this.#l.disconnect(),this.#l=null),this.#v(this.#e),this.#e=[];for(let e of this.#t)e.type==="getter"&&e.effect&&(this.#s.forEach((t,i)=>{t.delete(e.effect),t.size===0&&this.#s.delete(i)}),this.#o.delete(e.effect));this.#t=[],this.#n.forEach((e,t)=>{this[t]=e.original}),this.#n.clear(),this.#g.clear(),this.#s.clear(),this.#o.clear(),p.#m.delete(this)}toggleAttribute(e,...t){return t.length<=1&&(t[0]===void 0||typeof t[0]=="boolean")?super.toggleAttribute(e,...t):this.cycleAttribute(e,...t)}cycleAttribute(e,t="",i=""){let s=this.getAttribute(e);this[t==""&&i==""&&(s||this.hasAttribute(e))?"removeAttribute":"setAttribute"](e,s!=t?t:i)}static{customElements.define("st-app",this)}};export{O as default};
|
|
2
2
|
//# sourceMappingURL=app.esm.min.js.map
|