amateras 0.13.2 → 0.13.3

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.
@@ -1 +1 @@
1
- const t=`https://unpkg.com/amateras@${"0.13.2"}/build`,e={...{amateras:`${t}/core.js`},...Object.fromEntries(["core","utils","signal","for","if","match","css","i18n","idb","meta","prefetch","router","widget"].map(e=>{const r=`amateras/${e}`,s=`${t}/${e}.js`;return[[r,s],[`@${r}`,s]]}).flat())},r=document.querySelector('script[type="importmap"]');if(r){const t=JSON.parse(r.innerHTML);t.imports={...t.imports,...e},r.innerHTML=JSON.stringify(t,null,"\t")}else{const t=document.createElement("script");t.setAttribute("type","importmap"),t.innerHTML=JSON.stringify({imports:e},null,"\t"),document.head.prepend(t)}
1
+ const e=`https://unpkg.com/amateras@${"0.13.3"}/build`,t={amateras:`${e}/core.js`},n=[{name:"core",description:"Core module"},{name:"widget",description:"Component module"},{name:"signal",description:"Reactive data module"},{name:"store",description:"Access data between widgets"},{name:"css",description:"CSS-in-JS module"},{name:"for",description:"For loop control-flow"},{name:"if",description:"If/Else/ElseIf control-flow"},{name:"match",description:"Match/Case/Default control-flow"},{name:"router",description:"Router module"},{name:"i18n",description:"Translation module"},{name:"idb",description:"IndexedDB module"},{name:"markdown",description:"Markdown to HTML module",codeInsert:'import { Markdown } from "amateras/markdown"; new Markdown();'},{name:"prefetch",description:"SSR data prefetch"},{name:"meta",description:"SSR `meta` tag manager"},{name:"ui",description:"UI components"},{name:"utils",description:"Utilities module",codeInsert:'import * as utils from "amateras/utils";'}].map(e=>e.name),o={...t,...Object.fromEntries(n.map(t=>{const n=`amateras/${t}`,o=`${e}/${t}.js`;return[[n,o],[`@${n}`,o]]}).flat())},r=document.querySelector('script[type="importmap"]');if(r){const e=JSON.parse(r.innerHTML);e.imports={...e.imports,...o},r.innerHTML=JSON.stringify(e,null,"\t")}else{const e=document.createElement("script");e.setAttribute("type","importmap"),e.innerHTML=JSON.stringify({imports:o},null,"\t"),document.head.prepend(e)}
package/build/signal.js CHANGED
@@ -1 +1 @@
1
- import{_null as e,isSymbol as s,isString as t,forEach as i,_Object_entries as r,isFunction as a,isUndefined as u,_Object_assign as l,_instanceof as n,isIncluded as h,isBoolean as c}from"@amateras/utils";import{symbol_Signal as o,Proto as p,GlobalState as d,TextProto as m}from"@amateras/core";let b=!1,v=/* @__PURE__ */new Set,f=e=>{b=!1;let s=e();return b=!0,s},g=e=>{b=!0;let s=e(f);return b=!1,s},k=new FinalizationRegistry(({signal:e,ref:s})=>{e.computes?.delete(s)});class x extends Function{[o]=!0;linked=e;_value;subs=e;map=e;exec=e;computes=e;constructor(e){return super(),p.proto?.global.signals.add(this),this._value=e,new Proxy(this,{apply:()=>this._exec(),get:(e,i)=>{if(s(i)||t(i)&&!i.endsWith("$"))return this[i];const r=this.value[i.slice(0,-1)];this.map||(this.map={});const a=this.map[i]??new x(r);return this.map[i]=a,a}})}_exec(){return b&&v.add(this),this.value}get value(){return this.linked?this.linked.value:this._value}dispose(){this.subs=e,this.linked=e,i(this.computes,e=>e.deref()?.dispose()),this.computes=e,this.exec=e,this._value=e,this.map&&i(r(this.map),([e,s])=>s.dispose()),this.map=e}set(e){this.linked?this.linked.set(e):a(e)?this.set(e(this.value)):this.value!==e&&(this._value=e,this.emit())}modify(e){e(this.value),this.emit()}emit(){i(this.subs,e=>e(this.value)),i(this.computes,e=>{let s=e.deref();s||this.computes?.delete(e),s?.exec?.()})}subscribe(e){this.subs=this.subs??[],this.subs.push(e)}unsubscribe(e){let s=this.subs?.indexOf(e);u(s)||-1===s||this.subs?.splice(s,1)}link(e){if(this===e)throw"Signal.link(): cannot link self";this.linked=e,this.emit(),e.subscribe(()=>this.emit())}is(e){return e(this)}toString(){return`${this.value}`}}d.assign({signals:/* @__PURE__ */new Set}),d.disposers.add(e=>{i(e.signals,e=>e.dispose()),e.signals.clear()}),l($,{signal:e=>new x(e),effect(e){g(e),i(v,s=>s.subscribe(s=>e(f))),v.clear()},compute(e){let s=g(e),t=$.signal(s);return t.exec=()=>t.set(e(f)),i(v,e=>{e.computes=e.computes??/* @__PURE__ */new Set;let s=new WeakRef(t);e.computes.add(s),k.register(t,{signal:e,ref:s})}),v.clear(),t},optional:s=>s.value?s:e,resolve:(e,s)=>n(e,x)?(s&&(e.subscribe(s),s(e)),e.value):(s?.(e),e)});let w=e=>{if(n(e,x)){let s=new m(`${e}`),t=e=>s.content=`${e}`;return e.subscribe(t),s.ondispose(()=>e.unsubscribe(t)),t(e.value),s}};$.process.text.add(w),$.process.craft.add(w),$.process.attr.add((e,s,t)=>{if(n(s,x)){if("input"===t.tagname){if(h(e,["value","checked"])){t.on("input",t=>s.set(t.currentTarget[e]));let i=s.value;c(i)?i&&t.attr(e,""):t.attr(e,`${i}`)}}else{let i=()=>t.attr(e,s.value);s.subscribe(i),i(),t.ondispose(()=>s.unsubscribe(i))}return!0}});export{x as Signal};
1
+ import{_null as e,isSymbol as s,isString as t,forEach as i,_Object_entries as r,isFunction as u,isUndefined as a,_Object_assign as l,_instanceof as n,isIncluded as h,isBoolean as c}from"@amateras/utils";import{symbol_Signal as o,Proto as p,GlobalState as d,TextProto as m}from"@amateras/core";let b=!1,v=/* @__PURE__ */new Set,f=e=>{b=!1;let s=e();return b=!0,s},g=e=>{b=!0;let s=e(f);return b=!1,s},k=new FinalizationRegistry(({signal:e,ref:s})=>{e.computes?.delete(s)});class x extends Function{[o]=!0;linked=e;_value;subs=e;map=e;exec=e;computes=e;constructor(e){return super(),p.proto?.global.signals.add(this),this._value=e,new Proxy(this,{apply:()=>this._exec(),get:(e,i)=>{if(s(i)||t(i)&&!i.endsWith("$"))return this[i];const r=this.value[i.slice(0,-1)];this.map||(this.map={});const u=this.map[i]??new x(r);return this.map[i]=u,this.subscribe(()=>u.set(this.value[i.slice(0,-1)])),u}})}_exec(){return b&&v.add(this),this.value}get value(){return this.linked?this.linked.value:this._value}dispose(){this.subs=e,this.linked=e,i(this.computes,e=>e.deref()?.dispose()),this.computes=e,this.exec=e,this._value=e,this.map&&i(r(this.map),([e,s])=>s.dispose()),this.map=e}set(e){this.linked?this.linked.set(e):u(e)?this.set(e(this.value)):this.value!==e&&(this._value=e,this.emit())}modify(e){e(this.value),this.emit()}emit(){i(this.subs,e=>e(this.value)),i(this.computes,e=>{let s=e.deref();s||this.computes?.delete(e),s?.exec?.()})}subscribe(e){this.subs=this.subs??[],this.subs.push(e)}unsubscribe(e){let s=this.subs?.indexOf(e);a(s)||-1===s||this.subs?.splice(s,1)}link(e){if(this===e)throw"Signal.link(): cannot link self";this.linked=e,this.emit(),e.subscribe(()=>this.emit())}is(e){return e(this)}toString(){return`${this.value}`}}d.assign({signals:/* @__PURE__ */new Set}),d.disposers.add(e=>{i(e.signals,e=>e.dispose()),e.signals.clear()}),l($,{signal:e=>new x(e),effect(e){g(e),i(v,s=>s.subscribe(s=>e(f))),v.clear()},compute(e){let s=g(e),t=$.signal(s);return t.exec=()=>t.set(e(f)),i(v,e=>{e.computes=e.computes??/* @__PURE__ */new Set;let s=new WeakRef(t);e.computes.add(s),k.register(t,{signal:e,ref:s})}),v.clear(),t},optional:s=>s.value?s:e,resolve:(e,s)=>n(e,x)?(s&&(e.subscribe(s),s(e)),e.value):(s?.(e),e)});let w=e=>{if(n(e,x)){let s=new m(`${e}`),t=e=>s.content=`${e}`;return e.subscribe(t),s.ondispose(()=>e.unsubscribe(t)),t(e.value),s}};$.process.text.add(w),$.process.craft.add(w),$.process.attr.add((e,s,t)=>{if(n(s,x)){if("input"===t.tagname){if(h(e,["value","checked"])){t.on("input",t=>s.set(t.currentTarget[e]));let i=s.value;c(i)?i&&t.attr(e,""):t.attr(e,`${i}`)}}else{let i=()=>t.attr(e,s.value);s.subscribe(i),i(),t.ondispose(()=>s.unsubscribe(i))}return!0}});export{x as Signal};
package/build/utils.js CHANGED
@@ -1 +1 @@
1
- const e=null,t=void 0,r=Object,n=r.fromEntries,o=r.entries,s=r.assign,a=r.values,i=r.defineProperty,c=r.getOwnPropertyDescriptors,l=Array,u=l.from,p=async(e,t)=>{if(!e)return;let r=0;return v(t)?(async()=>{for(let n of e)await t(n,r,e),r++})():(()=>{for(let n of e)t(n,r,e),r++})()},f=(e,t)=>u(e).map(t),g=(e,t)=>typeof e===t,y=(e,t)=>t.includes(e),m=e=>g(e,"string"),d=e=>g(e,"boolean"),h=e=>g(e,"number"),w=e=>g(e,"object"),b=e=>g(e,"function"),j=e=>g(e,"symbol"),v=e=>U(e,(async()=>0).constructor),O=e=>void 0===e,P=t=>t===e,T=l.isArray,U=(e,...t)=>!!t.find(t=>e instanceof t),A=(t,r)=>U(t,r)?t:e,E=JSON.stringify,M=JSON.parse,S=(e,...t)=>!!t.find(t=>e.startsWith(t)),$=(e,t,r)=>e.slice(t,r),x=(e,t)=>e.bind(t),C=Promise,J=()=>{let e;return(t,r)=>{e&&clearTimeout(e),e=setTimeout(t,r)}},L="abcdefghijklmnopqrstuvwxyz",N=L.toUpperCase(),R=e=>{const t="any"===(e={length:5,lettercase:"any",...e}).lettercase?L+N:"lower"===e.lettercase?L:N;return u({length:e.length},(e,r)=>t[Math.round(Math.random()*t.length)]).join("")},k=async e=>new C(t=>setTimeout(t,e)),q=e=>U(e,Array)?e:[e],z=t=>{try{return[t(),e]}catch(r){return[e,U(r,Error)?r:new Error(E(r))]}},D=(e,t,r)=>`${$(e,0,t)}${$(e,t,r).toUpperCase()}${r?$(e,r):""}`,I=URL,W=e=>U(e,I)?e:new URL(e,globalThis.origin??"http://localhost"),B=(e,t,r)=>{for(let[n,s]of o(e))if((!r||r.includes(n))&&t[n]!==s)return!1;return!0};class F{static map=/* @__PURE__ */new Map;static generate(e,t){const r=F.map.get(e)??/* @__PURE__ */new Set,n=R(t);return r.has(n)?F.generate(e):n}static persistInProto(e,t,r){const n=F.generate(t,r);return e.ondispose(()=>F.map.get(t)?.delete(n)),n}}export{F as UID,u as _Array_from,M as _JSON_parse,E as _JSON_stringify,s as _Object_assign,i as _Object_defineProperty,o as _Object_entries,n as _Object_fromEntries,c as _Object_getOwnPropertyDescriptors,a as _Object_values,C as _Promise,x as _bind,U as _instanceof,e as _null,g as _typeof,t as _undefined,J as debounce,p as forEach,A as is,T as isArray,v as isAsyncFunction,d as isBoolean,B as isEqual,b as isFunction,y as isIncluded,P as isNull,h as isNumber,w as isObject,m as isString,j as isSymbol,O as isUndefined,f as map,R as randomId,k as sleep,$ as slice,S as startsWith,q as toArray,W as toURL,z as trycatch,D as uppercase};
1
+ const e=null,t=void 0,r=Object,n=r.fromEntries,s=r.entries,o=r.assign,a=r.values,i=r.defineProperty,c=r.getOwnPropertyDescriptors,l=Array,u=l.from,f=async(e,t)=>{if(!e)return;let r=0;return O(t)?(async()=>{for(let n of e)await t(n,r,e),r++})():(()=>{for(let n of e)t(n,r,e),r++})()},p=(e,t)=>u(e).map(t),g=(e,...t)=>e.filter(e=>!t.includes(e)),y=(e,t)=>typeof e===t,d=(e,t)=>t.includes(e),m=e=>y(e,"string"),h=e=>y(e,"boolean"),w=e=>y(e,"number"),b=e=>y(e,"object"),j=e=>y(e,"function"),v=e=>y(e,"symbol"),O=e=>A(e,(async()=>0).constructor),P=e=>void 0===e,T=t=>t===e,U=l.isArray,A=(e,...t)=>!!t.find(t=>e instanceof t),E=(t,r)=>A(t,r)?t:e,M=JSON.stringify,S=JSON.parse,$=(e,...t)=>!!t.find(t=>e.startsWith(t)),x=(e,t,r)=>e.slice(t,r),C=(e,t)=>e.bind(t),J=Promise,L=()=>{let e;return(t,r)=>{e&&clearTimeout(e),e=setTimeout(t,r)}},N="abcdefghijklmnopqrstuvwxyz",R=N.toUpperCase(),k=e=>{const t="any"===(e={length:5,lettercase:"any",...e}).lettercase?N+R:"lower"===e.lettercase?N:R;return u({length:e.length},(e,r)=>t[Math.round(Math.random()*t.length)]).join("")},q=async e=>new J(t=>setTimeout(t,e)),z=e=>A(e,Array)?e:[e],D=t=>{try{return[t(),e]}catch(r){return[e,A(r,Error)?r:new Error(M(r))]}},I=(e,t,r)=>`${x(e,0,t)}${x(e,t,r).toUpperCase()}${r?x(e,r):""}`,W=URL,B=e=>A(e,W)?e:new URL(e,globalThis.origin??"http://localhost"),F=(e,t,r)=>{for(let[n,o]of s(e))if((!r||r.includes(n))&&t[n]!==o)return!1;return!0};class G{static map=/* @__PURE__ */new Map;static generate(e,t){const r=G.map.get(e)??/* @__PURE__ */new Set,n=k(t);return r.has(n)?G.generate(e):n}static persistInProto(e,t,r){const n=G.generate(t,r);return e.ondispose(()=>G.map.get(t)?.delete(n)),n}}export{G as UID,u as _Array_from,S as _JSON_parse,M as _JSON_stringify,o as _Object_assign,i as _Object_defineProperty,s as _Object_entries,n as _Object_fromEntries,c as _Object_getOwnPropertyDescriptors,a as _Object_values,J as _Promise,C as _bind,A as _instanceof,e as _null,y as _typeof,t as _undefined,L as debounce,g as filterValue,f as forEach,E as is,U as isArray,O as isAsyncFunction,h as isBoolean,F as isEqual,j as isFunction,d as isIncluded,T as isNull,w as isNumber,b as isObject,m as isString,v as isSymbol,P as isUndefined,p as map,k as randomId,q as sleep,x as slice,$ as startsWith,z as toArray,B as toURL,D as trycatch,I as uppercase};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "amateras",
3
- "version": "0.13.2",
3
+ "version": "0.13.3",
4
4
  "description": "Amateras is a JavaScript library for building user interface.",
5
5
  "module": "index.ts",
6
6
  "type": "module",
@@ -17,7 +17,8 @@
17
17
  "unpkg": "./build/import-map.js",
18
18
  "scripts": {
19
19
  "build": "bun ./scripts/build.ts",
20
- "size": "bun ./scripts/vite-bundler-size.ts"
20
+ "size": "bun ./scripts/vite-bundler-size.ts",
21
+ "publish": "bun ./scripts/publish.ts"
21
22
  },
22
23
  "exports": {
23
24
  ".": {
@@ -27,6 +27,7 @@ export class Signal<T = any> extends Function {
27
27
  if (!this.map) this.map = {};
28
28
  const signal = this.map[propName] ?? new Signal(value);
29
29
  this.map[propName] = signal;
30
+ this.subscribe(() => signal.set(this.value[propName.slice(0, -1) as keyof T]))
30
31
  return signal;
31
32
  }
32
33
  });
@@ -48,6 +48,8 @@ interface map {
48
48
  }
49
49
  export const map: map = (arr: any, fn: any) => _Array_from(arr).map(fn);
50
50
 
51
+ export const filterValue = <T, V>(arr: Array<T>, ...values: V[]): Array<Exclude<T, V>> => arr.filter(item => !values.includes(item as any)) as any;
52
+
51
53
  // type check
52
54
  export const _typeof = (target: any, type: 'string' | 'number' | 'object' | 'boolean' | 'function' | 'bigint' | 'symbol' | 'undefined') => typeof target === type;
53
55
  export const isIncluded = <T, V>(target: T, args: V[]): target is V & T => args.includes(target as any);