amateras 0.12.0 → 0.13.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.
Files changed (86) hide show
  1. package/README.md +55 -79
  2. package/build/core.js +1 -1
  3. package/build/css.js +1 -1
  4. package/build/for.js +1 -1
  5. package/build/i18n.js +1 -1
  6. package/build/if.js +1 -1
  7. package/build/import-map.js +1 -1
  8. package/build/markdown.js +1 -1
  9. package/build/match.js +1 -1
  10. package/build/meta.js +1 -1
  11. package/build/prefetch.js +1 -1
  12. package/build/router.js +1 -1
  13. package/build/signal.js +1 -1
  14. package/build/store.js +1 -0
  15. package/build/ui.js +1 -1
  16. package/build/utils.js +1 -1
  17. package/build/widget.js +1 -1
  18. package/index.ts +1 -1
  19. package/package.json +5 -4
  20. package/packages/core/src/index.ts +52 -34
  21. package/packages/core/src/lib/hmr.ts +3 -3
  22. package/packages/core/src/lib/symbols.ts +2 -1
  23. package/packages/core/src/structure/ElementProto.ts +39 -14
  24. package/packages/core/src/structure/GlobalState.ts +14 -2
  25. package/packages/core/src/structure/NodeProto.ts +9 -2
  26. package/packages/core/src/structure/Proto.ts +129 -19
  27. package/packages/core/src/structure/TextProto.ts +17 -4
  28. package/packages/css/src/ext/variable.ts +12 -8
  29. package/packages/css/src/index.ts +15 -9
  30. package/packages/css/src/lib/cache.ts +1 -1
  31. package/packages/css/src/structure/$CSSRule.ts +2 -0
  32. package/packages/for/src/global.ts +1 -1
  33. package/packages/for/src/index.ts +1 -1
  34. package/packages/for/src/structure/For.ts +45 -35
  35. package/packages/i18n/src/index.ts +4 -0
  36. package/packages/i18n/src/structure/I18nDictionary.ts +12 -3
  37. package/packages/i18n/src/structure/I18nTranslation.ts +8 -2
  38. package/packages/if/src/global.ts +4 -3
  39. package/packages/if/src/index.ts +17 -13
  40. package/packages/if/src/structure/Condition.ts +13 -5
  41. package/packages/if/src/structure/ConditionStatement.ts +4 -6
  42. package/packages/if/src/structure/ElseIf.ts +0 -2
  43. package/packages/if/src/structure/If.ts +0 -2
  44. package/packages/markdown/src/syntax/list.ts +2 -2
  45. package/packages/match/src/index.ts +3 -3
  46. package/packages/match/src/structure/Match.ts +14 -7
  47. package/packages/prefetch/src/index.ts +21 -15
  48. package/packages/router/src/index.ts +1 -1
  49. package/packages/router/src/structure/Page.ts +0 -11
  50. package/packages/router/src/structure/Route.ts +2 -3
  51. package/packages/router/src/structure/RouteNode.ts +7 -3
  52. package/packages/router/src/structure/RouteSlot.ts +1 -1
  53. package/packages/router/src/structure/Router.ts +9 -6
  54. package/packages/router/src/types.ts +2 -2
  55. package/packages/signal/src/index.ts +61 -25
  56. package/packages/signal/src/lib/track.ts +5 -1
  57. package/packages/signal/src/structure/Signal.ts +79 -31
  58. package/packages/store/README.md +31 -0
  59. package/packages/store/package.json +15 -0
  60. package/packages/store/src/index.ts +14 -0
  61. package/packages/store/src/structure/Store.ts +38 -0
  62. package/packages/ui/package.json +2 -1
  63. package/packages/ui/src/icon/chevron_down.svg.ts +1 -0
  64. package/packages/ui/src/index.ts +13 -1
  65. package/packages/ui/src/lib/float.ts +47 -0
  66. package/packages/ui/src/lib/toCSS.ts +12 -0
  67. package/packages/ui/src/structure/Badge.ts +91 -0
  68. package/packages/ui/src/structure/Button.ts +132 -0
  69. package/packages/ui/src/structure/Card.ts +90 -0
  70. package/packages/ui/src/structure/DescriptionList.ts +59 -0
  71. package/packages/ui/src/structure/Icon.ts +36 -0
  72. package/packages/ui/src/structure/Select/Select.ts +105 -0
  73. package/packages/ui/src/structure/Select/SelectArrow.ts +15 -0
  74. package/packages/ui/src/structure/Select/SelectContent.ts +34 -0
  75. package/packages/ui/src/structure/Select/SelectGroup.ts +8 -0
  76. package/packages/ui/src/structure/Select/SelectItem.ts +115 -0
  77. package/packages/ui/src/structure/Select/SelectTrigger.ts +70 -0
  78. package/packages/ui/src/structure/Select/SelectValue.ts +51 -0
  79. package/packages/ui/src/structure/Slideshow.ts +2 -2
  80. package/packages/utils/src/lib/utils.ts +27 -13
  81. package/packages/utils/src/structure/UID.ts +1 -1
  82. package/packages/widget/README.md +7 -22
  83. package/packages/widget/src/index.ts +14 -69
  84. package/packages/widget/src/structure/Widget.ts +9 -33
  85. package/packages/core/src/structure/WidgetEvent.ts +0 -17
  86. package/packages/signal/src/lib/objectSignal.ts +0 -21
package/README.md CHANGED
@@ -1,105 +1,81 @@
1
1
  # Amateras
2
- Amateras 是一个构建用户界面的 JavaScript 库,目标是无需编译器也能直接编写和运行,让开发者只需用 JavaScript TypeScript 的语法就能高效地构建用户界面。
3
-
4
- ## 优势
5
- - **极简开发**:无需 JSX,无需编译器。
6
- - **原生性能**:没有 Diff 开销,没有 VDOM,细粒度响应式框架。
7
- - **类型安全**:提供 TypeScript 类型安全的编写体验。
8
- - **两端运行**:能够在客户端和服务端运行。
9
- - **轻量体积**:极小的包体积,所有功能模块化,按需导入项目。
10
-
11
- ## 功能
12
- - 组件化模块(Widget)
13
- - 支持控制流(If、Match、For)
14
- - 页面路由器(Router
15
- - 响应式数据(Signal)
16
- - 热模块更新(HMR)
17
- - 多语言切换(I18n)
18
- - 样式表直写(CSS-in-JS)
19
- - 服务端渲染(SSR)
20
-
21
- ## 如何使用
22
- Amateras 提供了两种导入库的方式
23
- ### 使用导入映射(Import Map
24
- 这个代码将会为你的网页自动创建一个导入映射脚本,将这段代码安插在你的项目代码之前即可。
2
+ Amateras is a JavaScript library for building user interface, write native JavaScript code and run it without compiler.
3
+
4
+ ## Before You Ask Why
5
+ - **Simplfied Develop**: No JSX, no compiler.
6
+ - **Fast Performance**:No cost of VDOM diff, Fine-grained Reactive Framework.
7
+ - **Typesafe**:TypeScript first class framework.
8
+ - **Server and Client**:You can directly run client code on server-side。
9
+ - **Light**:High modularity design, only import the code that you need.
10
+
11
+ ## Features
12
+ - Componentization (widget)
13
+ - Control-flow (if, match, for)
14
+ - Build-in Router (router)
15
+ - Reactive Data (signal)
16
+ - Multi Languages (I18n)
17
+ - CSS-in-JS (css)
18
+ - Server-side Render ([tsukimi](https://github.com/defaultkavy/tsukimi))
19
+
20
+ ## Import
21
+ Amateras provide two ways to import library.
22
+
23
+ ### Import Map
24
+ This script will create a import map in your page, insert this line before your project code.
25
25
  ```html
26
26
  <script src="https://unpkg.com/amateras"></script>
27
27
  ```
28
28
 
29
- ### 安装代码库
30
- ```
29
+ ### Install via Package Manager
30
+ ```sh
31
31
  bun add amateras
32
32
  ```
33
33
 
34
- ## 基础范例
34
+ ## Example
35
35
  ```ts
36
36
  import 'amateras';
37
37
 
38
38
  const $h1 = $('h1', {class: 'title'}, () => $`Hello World!`)
39
39
 
40
- $.render($h1, () => document.body);
40
+ $.render($h1, 'body');
41
41
  ```
42
42
 
43
- ## 计数组件范例
43
+ ## Counter Widget Example
44
44
  ```ts
45
45
  import 'amateras';
46
46
  import 'amateras/signal';
47
47
  import 'amateras/widget';
48
48
 
49
- const Counter = $.widget(() => ({
50
- layout() {
51
- const count$ = $.signal(0);
52
- const double$ = $.compute(() => count$() * 2);
49
+ const Counter = $.widget(() => {
50
+ const count$ = $.signal(0);
51
+ const double$ = $.compute(() => count$() * 2);
53
52
 
54
- console.log('This template only run once.');
53
+ console.log('This template only run once.');
55
54
 
56
- $('button', $$ => {
57
- $([ double$ ])
58
- $$.on('click', () => count$.set(val => val + 1));
59
- })
60
- }
61
- }))
55
+ $('button', $$ => {
56
+ $([ double$ ])
57
+ $$.on('click', () => count$.set(val => val + 1));
58
+ })
59
+ })
62
60
 
63
- $.render($(Counter), () => document.body);
61
+ $.render(Counter, 'body');
64
62
  ```
65
63
 
66
- ## 为什么是 Amateras?
67
- 我喜欢纯粹的开发环境,而对我来说目前主流的前端框架都过于复杂。它们依赖复杂的工具链,使用类似 JSX 这种非原生的文件格式,编写的是脱离 JavaScript 语法的代码。这并没有什么不好,但我更喜欢纯粹的 JavaScript,所有的逻辑都能从代码表面推导出来。为此,我一次又一次地研发这样的库,而经历多次重构的结果就是 Amateras。
68
-
69
- ### 不是 JSX
70
- Amateras 能让你编写接近 HTML 排版的模板代码,实现了在原生 JavaScript 语法下也能写出高可读性的 UI 代码。配合 TypeScript 的类型检查,能大幅减少新手编写时的疑惑。
71
-
72
- ### 高性能
73
- 我们都不知道用户究竟用的是什么样的设备使用我们的应用,因此一个足够高性能的构建工具必不可少。Amateras 只会将模板构建一次,任何的更新都只会改动必要的元素。
74
-
75
- ### 模块化与拓展性
76
- 这是一个贯彻模块化风格的 JavaScript 库,除了核心功能(amateras/core)之外的所有功能几乎都能分割成不同的模块库。例如 `If` 和 `Signal` 都能够按项目需求来导入,就连组件功能 `Widget` 也被模块化。模块化风格让 Amateras 拥有极强的拓展性,只要理解 Amateras 的运作原理就能写出一个配合 Amateras 类型系统的自定义模块。
77
-
78
- ### 小体积
79
- 得益于模块化风格,开发者能按照自己的需求导入模块,这使得项目依赖工具可以进一步缩小代码体积。
80
-
81
- | 模块库 | 体积 | Gzip | 简介 |
64
+ | Modules | Size | Gziped | Description |
82
65
  | --- | --- | --- | --- |
83
- | core | 5.47 kB | 2.32 kB | 核心模块 |
84
- | widget | 0.35 kB | 0.17 kB | 组件模块 |
85
- | signal | 1.78 kB | 0.74 kB | 响应式数据模块 |
86
- | css | 1.56 kB | 0.71 kB | 样式模块 |
87
- | for | 1.05 kB | 0.35 kB | 控制流 For 模块 |
88
- | if | 3.08 kB | 1.15 kB | 控制流 If 模块 |
89
- | match | 1.31 kB | 0.39 kB | 控制流 Match 模块 |
90
- | router | 6.03 kB | 2.24 kB | 页面路由器模块 |
91
- | i18n | 2.92 kB | 0.98 kB | 多语言界面模块 |
92
- | idb | 5.26 kB | 1.99 kB | IndexedDB 模块 |
93
- | markdown | 7.48 kB | 2.93 kB | Markdown 转换 HTML 模块 |
94
- | prefetch | 0.41 kB | 0.20 kB | SSR 数据预取 |
95
- | meta | 0.18 kB | 0.08 kB | SSR 页面 `meta` 标签管理 |
96
- | ui | 6.50 kB | 2.25 kB | UI 组件模块 |
97
- | utils | 0.00 kB | 0.00 kB | 通用工具库 |
98
-
99
- ## 文档
100
- 1. [基础入门](/docs/Basic.md)
101
- 2. [理解原型树](/docs/ProtoTree.md)
102
- 3. [组件](/docs/Widget.md)
103
- 4. [组件数据仓库](/docs/WidgetStore.md)
104
- 5. [控制流](/docs/ControlFlow.md)
105
- 6. [路由器](/docs/Router.md)
66
+ | core | 7.45 kB | 2.91 kB | Core module |
67
+ | widget | 0.14 kB | 0.06 kB | Component module |
68
+ | signal | 2.50 kB | 0.97 kB | Reactive data module |
69
+ | store | 0.50 kB | 0.19 kB | Access data between widgets |
70
+ | css | 1.63 kB | 0.73 kB | CSS-in-JS module |
71
+ | for | 1.20 kB | 0.39 kB | For loop control-flow |
72
+ | if | 3.86 kB | 1.38 kB | If/Else/ElseIf control-flow |
73
+ | match | 1.44 kB | 0.44 kB | Match/Case/Default control-flow |
74
+ | router | 6.02 kB | 2.24 kB | Router module |
75
+ | i18n | 3.12 kB | 1.04 kB | Translation module |
76
+ | idb | 5.26 kB | 2.00 kB | IndexedDB module |
77
+ | markdown | 7.48 kB | 2.93 kB | Markdown to HTML module |
78
+ | prefetch | 0.45 kB | 0.22 kB | SSR data prefetch |
79
+ | meta | 0.18 kB | 0.09 kB | SSR `meta` tag manager |
80
+ | ui | 18.70 kB | 5.19 kB | UI components |
81
+ | utils | 0.00 kB | 0.00 kB | Utilities module |
package/build/core.js CHANGED
@@ -1 +1 @@
1
- import{forEach as t,_null as e,map as s,_Object_entries as r,isUndefined as o,isNull as n,_Array_from as i,isFunction as a,_instanceof as l,isString as h,isArray as d}from"@amateras/utils";const p=window,c=document,u=t=>!t||t(),f=t=>!1,m=/* @__PURE__ */Symbol("ProtoType"),w=/* @__PURE__ */Symbol("Statement");class g{static disposers=/* @__PURE__ */new Set;dispose(){t(g.disposers,t=>t(this))}}class M{static proto=e;static[m]="Proto";static[w]=!1;protos=/* @__PURE__ */new Set;disposers=/* @__PURE__ */new Set;layout;#t=e;global=M.proto?.global??new g;constructor(t){this.layout=t??e}set parent(t){this.#t?.protos.delete(this),this.#t=t,t&&(this.global=t.global),t?.protos.add(this)}get parent(){return this.#t}get children(){return s(this.protos,t=>t.constructor[w]?t.children:t).flat()}build(e=!0){return this.clear(!0),$.context(M,this,()=>this.layout?.(this)),e&&t(this.protos,t=>{t.build()}),this}toString(){return s(this.protos,t=>`${t}`).join("")}toDOM(t=!0){return t?s(this.protos,e=>e.toDOM(t)).flat():[]}dispose(){t(this.disposers,t=>t()),t(this.protos,t=>t.dispose())}removeNode(){t(this.protos,t=>t.removeNode())}clear(e=!1){this.protos.clear(),e&&t(this.protos,t=>t.dispose())}findAbove(t){let s=this.parent;return s?t(s)?s:s.findAbove(t):e}findBelow(t){for(let e of this.protos){if(t(e))return e;let s=e.findBelow(t);if(s)return s}return e}}class S extends M{node=e;modifiers=/* @__PURE__ */new Set;constructor(t){super(t)}ondom(t){this.modifiers.add(t)}removeNode(){this.node?.remove()}}const v=["img","hr","br","input","link","meta"];class y extends S{tagname;#e=/* @__PURE__ */new Map;#s="";constructor(t,e,s){super(()=>s?.(this)),this.tagname=t,e&&this.attrProcess(e)}on(t,e){this.ondom(s=>{s.addEventListener(t,e),this.disposers.add(()=>s.removeEventListener(t,e))})}toString(){return this.parseHTML()}parseHTML(t){let e=this.tagname,r=t?.children??(this.#s||s(this.protos,t=>`${t}`).join("")),o=t?.attr??s(this.#e,([t,e])=>e.length?`${t}="${e}"`:t).join(" "),n=o.length?" "+o:"";return v.includes(e)?`<${e}${n} />`:`<${e}${n}>${r}</${e}>`}toDOM(e=!0){if(this.node)return[this.node];let r=document.createElement(this.tagname);return this.node=r,this.#s?this.node.innerHTML=this.#s:e&&r.append(...s(this.protos,t=>t.toDOM(e)).flat()),t(this.#e,([t,e])=>r.setAttribute(t,e)),t(this.modifiers,t=>t(r)),[r]}attrProcess(e){t(r(e),([t,e])=>{for(let s of $.process.attr){let r=s(t,e,this);if(!o(r))return}this.attr(t,e)})}innerHTML(t){this.#s=t}attr(t,e){return arguments.length?o(e)?this.#e.get(t):(n(e)?(this.#e.delete(t),this.node?.removeAttribute(t)):(this.#e.set(t,e),this.node?.setAttribute(t,e)),this):this.#e}addClass(...t){this.token("add","class",...t),this.node?.classList.add(...t)}removeClass(...t){this.token("delete","class",...t),this.node?.classList.remove(...t)}token(e,s,...r){let o=this.#e.get(s),n=new Set(o?.split(" ")??[]);t(r,t=>n[e](t)),this.#e.set(s,i(n).join(" "))}}class b extends S{constructor(t){super(t),u()&&(this.node=new Text)}toDOM(){return[this.node,...super.toDOM()]}removeNode(){super.removeNode(),t(this.protos,t=>t.removeNode())}}class L extends S{content;constructor(t){super(),this.content=t}toString(){return this.content}toDOM(){if(this.node)return[this.node];let e=new Text(this.content);return this.node=e,t(this.modifiers,t=>t(e)),[e]}}function T(...s){const r=M.proto;let n=[];const i=t=>{t.parent=r,n.push(t)};for(let t of T.process.craft){let e=t(...s);if(!o(e))return e}const[p,c,u]=s;if(l(p,M))return i(p),p;if(h(p)){let t=a(c)?[,c]:[c,u],e=new y(p,...t);return i(e),e}if(a(p)){let t=new p(...a(c)?[{},c]:[c,u]);if(l(t,M))return i(t),t}if(d(p)){let r=t=>{for(let e of T.process.text){let s=e(t);if(!o(s))return i(s)}let s=o(t)?e:new L(`${t}`);s&&i(s)},[a,...l]=s;return a.raw?t(a,(t,s)=>{let o=t.length?new L(t):e,n=l[s];o&&i(o),r(n)}):t(a,t=>r(t)),n}}var x;(x=T||(T={})).process={craft:/* @__PURE__ */new Set,text:/* @__PURE__ */new Set,attr:/* @__PURE__ */new Set},x.dispose=t=>{M.proto?.disposers.add(t)},x.render=(t,e)=>{e=a(e)?e():e;{let s=t.build().toDOM();e.replaceChildren(...s)}},x.context=(t,e,s)=>{let r=t.proto;t.proto=e,s(),t.proto=r},x.call=t=>t(),x.match=(t,e)=>{var s=/* @__PURE__ */new Map,r=/* @__PURE__ */Symbol("default"),o={case:(t,e)=>(s.set(t,e),o),default:t=>(s.set(r,t),o)};return e(o),s.get(t)?.()??s.get(r)?.()},x.stylesheet=u()?new CSSStyleSheet:e,x.styleMap=/* @__PURE__ */new Map,x.style=(t,e)=>{t&&x.styleMap.set(t,e),x.stylesheet?.insertRule(e)},x.stylesheet&&document.adoptedStyleSheets.push(x.stylesheet),u()&&document.querySelector("style#__ssr__")?.remove(),globalThis.$=T;export{T as $,y as ElementProto,g as GlobalState,S as NodeProto,M as Proto,b as ProxyProto,L as TextProto,c as _document,p as _window,u as onclient,f as onserver,m as symbol_ProtoType,w as symbol_Statement};
1
+ import{_null as t,forEach as s,_Object_assign as e,map as o,_Array_from as i,_Object_entries as r,isUndefined as n,isNull as l,toArray as h,_instanceof as a,isString as d,isFunction as p,isArray as u}from"@amateras/utils";const c=window,f=document,m=t=>!t||t(),g=t=>!1,b=/* @__PURE__ */Symbol("ProtoType"),y=/* @__PURE__ */Symbol("Statement"),P=/* @__PURE__ */Symbol("Signal");class w{static disposers=/* @__PURE__ */new Set;promises=/* @__PURE__ */new Set;root;constructor(t){this.root=t,t.ondispose(()=>this.dispose())}dispose(){this.promises.clear(),this.root=t,s(w.disposers,t=>t(this))}static assign(t){e(w.prototype,t)}asyncTask(t){this.promises.add(t),t.finally(()=>this.promises.delete(t))}}class S{static proto=t;static[b]="Proto";static[y]=!1;static disposer=[];disposers=t;layout;parent=t;global=S.proto?.global??new w(this);sibling=t;firstProto=t;lastProto=t;builded=!1;listeners=t;constructor(s){this.layout=s??t}dispose(){s(S.disposer,t=>t(this)),s(this.disposers,t=>t()),s(this.protos,t=>t.dispose()),this.global=t,this.sibling=t,this.firstProto=t,this.lastProto=t,this.disposers=t,this.parent=t,this.layout=t}get children(){return o(this.protos,t=>t.constructor[y]?t.children:t).flat()}get protos(){let t=/* @__PURE__ */new Set,s=this.firstProto;if(s){let e=s;for(;e;)t.add(e),e=e.sibling}return t}append(...e){s(e,s=>{if(s.parent!==this&&s.parent?.removeProtos(s),this.lastProto){if(this.lastProto===s)return;this.firstProto===s&&(this.firstProto=s.sibling),s.sibling=t,this.lastProto.sibling=s,this.lastProto=s}else this.firstProto=s,this.lastProto=s;s.parent=this,s.global=this.global})}replaceProtos(...t){this.clear(),this.processProtos(...t)}insert(t,s=-1){if(0===s)this.firstProto&&(t.sibling=this.firstProto),this.firstProto=t;else{let e=i(this.protos),o=s<0?e.length+s+1:s;e.splice(o,0,t),this.processProtos(...e)}t.parent=this,t.global=this.global}removeProtos(...t){let e=this.protos;s(t,t=>{t.parent=null,t.sibling=null,e.delete(t)}),this.processProtos(...e)}processProtos(...e){let o=null;e.length?s(e,(t,s)=>{0===s&&(this.firstProto=t),o&&(o.sibling=t),o=t,t.parent=this}):this.firstProto=t,this.lastProto=o}build(t=!0){return this.clear(!0),$.context(S,this,()=>this.layout?.(this)),this.builded=!0,t&&s(this.protos,t=>{t.build()}),this.dispatch("builded",this),this}toString(){return o(this.protos,t=>`${t}`).join("")}toDOM(t=!0){return t?o(this.protos,s=>s.toDOM(t)).flat():[]}ondispose(t){this.disposers=this.disposers??[],this.disposers.push(t)}removeNode(){s(this.protos,t=>t.removeNode())}clear(t=!1){let e=this.protos;this.removeProtos(...e),t&&s(e,t=>t.dispose())}findAbove(s){let e=this.parent;return e?s(e)?e:e.findAbove(s):t}findBelow(s){for(let t of this.protos){if(s(t))return t;let e=t.findBelow(s);if(e)return e}return t}findBelowAll(t){let s=[];for(let e of this.protos)t(e)&&s.push(e),s.push(...e.findBelowAll(t));return s}mutate(){}get text(){return this.children.map(t=>t.text).join("")}dispatch(t,e,o){o?.bubbles&&this.parent?.dispatch(t,e,o);let i=this.listeners?.[t];s(i,t=>t(e))}listen(t,s){let e=this.listeners??{};this.listeners=e;let o=e[t]??/* @__PURE__ */new Set;this.listeners[t]=o,o.add(s)}}class M extends S{node=t;modifiers=t;constructor(t){super(t)}ondom(t){this.modifiers=this.modifiers??[],this.modifiers.push(t)}dispose(){super.dispose(),this.node=t,this.modifiers=t}inDOM(){return!!m()&&document.contains(this.node)}removeNode(){this.node?.remove()}}const _=["img","hr","br","input","link","meta"];class v extends M{tagname;#t={};#s="";__props__;constructor(t,s,e){super(()=>e?.(this)),this.tagname=t,this.__props__=s}dispose(){super.dispose(),this.layout=null}build(s){return this.__props__&&(this.props(this.__props__),this.__props__=t),super.build(s),this}props({...t}){let{class:s,...e}=t;s&&this.addClass(...s.split(" ")),this.attrProcess(e)}on(t,s,e){let o=o=>{o.addEventListener(t,s,e),this.ondispose(()=>this.node?.removeEventListener(t,s))};this.node?o(this.node):this.ondom(o)}toString(){return this.parseHTML()}parseHTML(t){let s=this.tagname,e=t?.children??(this.#s||o(this.protos,t=>`${t}`).join("")),i=t?.attr??o(r(this.#t),([t,s])=>s.length?`${t}="${s}"`:t).join(" "),n=i.length?" "+i:"";return _.includes(s)?`<${s}${n} />`:`<${s}${n}>${e}</${s}>`}toDOM(t=!0){if(this.node)return[this.node];let e=document.createElement(this.tagname);return this.node=e,this.#s?this.node.innerHTML=this.#s:t&&e.append(...o(this.protos,s=>s.toDOM(t)).flat()),s(r(this.#t),([t,s])=>e.setAttribute(t,s)),s(this.modifiers,t=>t(e)),[e]}attrProcess(t){s(r(t),([t,s])=>{for(let e of $.process.attr){let o=e(t,s,this);if(!n(o))return}this.attr(t,s)})}innerHTML(t){this.#s=t,this.node&&(this.node.innerHTML=t)}attr(s,e){return arguments.length?n(e)?this.#t[s]??t:(l(e)?(delete this.#t[s],this.node?.removeAttribute(s)):(this.#t[s]=e,this.node?.setAttribute(s,e)),this):this.#t}addClass(...t){this.token("add","class",...t),this.node?.classList.add(...t)}removeClass(...t){this.token("delete","class",...t),this.node?.classList.remove(...t)}style(t){let s=()=>this.node&&e(this.node.style,t);s(),this.node||this.ondom(s)}token(t,e,...o){let r=this.#t[e],n=new Set(r?.split(" ")??[]);s(o,s=>n[t](s)),this.#t[e]=i(n).join(" ")}}class T extends M{#e;constructor(t){super(),this.#e=t}get content(){return this.#e}set content(t){this.#e=t,this.node&&(this.node.textContent=t)}toString(){return this.#e}toDOM(){if(this.node)return[this.node];let t=new Text(this.#e);return this.node=t,s(this.modifiers,s=>s(t)),[t]}get text(){return this.#e}}class x extends M{constructor(t){super(t),m()&&(this.node=new Text)}toDOM(){return[this.node,...super.toDOM()]}removeNode(){super.removeNode(),s(this.protos,t=>t.removeNode())}}function L(e,...o){const i=S.proto,r=[],l=t=>{e&&i?.append(t),r.push(t)};for(let t of H.process.craft){let s=t(...o);if(!n(s))return s}const[h,c,f]=o;if(a(h,S))return l(h),h;if(d(h)){let t=p(c)?[,c]:[c,f],s=new v(h,...t);return l(s),s}if(p(h)){let t=new h(...p(c)?[{},c]:[c,f]);if(a(t,S))return l(t),t}if(u(h)){let e=s=>{for(let t of H.process.text){let e=t(s);if(!n(e))return l(e)}let e=n(s)?t:new T(`${s}`);e&&l(e)},[i,...h]=o;return i.raw?s(i,(s,o)=>{let i=s.length?new T(s):t,r=h[o];i&&l(i),e(r)}):s(i,t=>e(t)),r}}function H(...t){return L(!0,...t)}var D;(D=H||(H={})).process={craft:/* @__PURE__ */new Set,text:/* @__PURE__ */new Set,attr:/* @__PURE__ */new Set},D.craft=(...t)=>L(!1,...t),D.dispose=t=>{S.proto?.ondispose(t)},D.render=(t,s)=>{let e=D(t).build().toDOM();document.querySelector(s)?.replaceChildren(...e)},D.context=(t,s,e)=>{let o=t.proto;t.proto=s,e(),t.proto=o},D.call=t=>t(),D.match=(t,s)=>{var e=/* @__PURE__ */new Map,o=/* @__PURE__ */Symbol("default"),i={case:(t,s)=>(e.set(t,s),i),default:t=>(e.set(o,t),i)};return s(i),e.get(t)?.()??e.get(o)?.()},D.async=t=>{S.proto?.global.asyncTask(t())},D.stylesheet=m()?new CSSStyleSheet:t,D.styleMap=/* @__PURE__ */new Map,D.style=(t,e)=>{let o=h(e);if(t){let e=D.styleMap.get(t)??/* @__PURE__ */new Set;s(o,t=>e.add(t)),D.styleMap.set(t,e)}D.stylesheet&&s(o,t=>D.stylesheet.insertRule(t))},D.stylesheet&&document.adoptedStyleSheets.push(D.stylesheet),m()&&document.querySelector("style#__ssr__")?.remove(),globalThis.$=H;export{H as $,v as ElementProto,w as GlobalState,M as NodeProto,S as Proto,x as ProxyProto,T as TextProto,f as _document,c as _window,m as onclient,g as onserver,b as symbol_ProtoType,P as symbol_Signal,y as symbol_Statement};
package/build/css.js CHANGED
@@ -1 +1 @@
1
- import{_null as e,map as t,_Object_entries as s,isString as r,isNumber as l,_instanceof as a,_JSON_stringify as n,_Object_assign as o,forEach as c,_Array_from as i,UID as u}from"@amateras/utils";import{ElementProto as p,onserver as d}from"@amateras/core";const h=/* @__PURE__ */new WeakMap,w=/* @__PURE__ */new Set,f=/* @__PURE__ */new Map;class S{}class m extends S{declarations=/* @__PURE__ */new Map;rules=/* @__PURE__ */new Map;selector;parent=e;css;constructor(e,t,s){super(),this.selector=e,this.parent=s,t&&g(this,t),this.css=t}toString(){let e=t(this.declarations,([e,t])=>`${e.replaceAll(/[A-Z]/g,e=>`-${e.toLowerCase()}`)}: ${t};`),s=t(this.rules,([e,t])=>`${t}`);return`${this.selector} { ${[...e,...s].join(" ")} }`}}const g=(e,t)=>{for(let[n,o]of s(t))if(r(o)||l(o)||a(o,S))e.declarations.set(n,`${o}`);else{let t=e.selector.startsWith("@")&&!e.parent?n:`${/^[@]|&/.test(n)?n:`& ${n}`}`;e.rules.set(t,new m(t,o,e))}},C=(t,s,r=!0)=>{let l=r?n(s):"";if(r){let e=f.get(l);if(e)return e}let a=new m(t(),s,e);return $.style(e,`${a}`),r&&f.set(l,a),a};o($,{css:e=>a(e,m)?e:C(()=>`.${u.generate("css")}`,e),CSS:e=>t(s(e),([e,t])=>{let s=C(()=>e,{...t,__selector__:e});return w.add(s),s})}),o(p.prototype,{css(...e){return c(e,e=>M(this,e)),this}});const M=(e,t)=>{let s=$.css(t),r=s.selector.slice(1);e.addClass(r),h.set(e,s)};d()&&o($.CSS,{rules(e){let t=/* @__PURE__ */new Set;return c([e,...e.protos],s=>{let r=h.get(s);r&&t.add(r),e!==s&&c(this.rules(s),e=>t.add(e))}),i(t)},text(e){return[...w,...this.rules(e)].join("\n")}}),$.process.attr.add((e,t,s)=>{if("css"===e)return M(s,t),!0});export{S as $CSS,m as $CSSRule,M as assignCSS};
1
+ import{_null as e,map as t,_Object_entries as s,isString as r,isNumber as l,_instanceof as a,_JSON_stringify as n,_Object_assign as o,forEach as c,_Array_from as i,toArray as u,UID as d}from"@amateras/utils";import{ElementProto as p,onserver as h}from"@amateras/core";const w=/* @__PURE__ */new WeakMap,f=/* @__PURE__ */new Set,S=$.call(()=>/* @__PURE__ */new Map);class _{}class g extends _{declarations=/* @__PURE__ */new Map;rules=/* @__PURE__ */new Map;selector;parent=e;css;constructor(e,t,s){super(),this.selector=e,this.parent=s,t&&m(this,t),this.css=t}toString(){let e=t(this.declarations,([e,t])=>`${e.replaceAll(/[A-Z]/g,e=>`-${e.toLowerCase()}`)}: ${t};`),s=t(this.rules,([e,t])=>`${t}`);return`${this.selector} { ${[...e,...s].join(" ")} }`}}const m=(e,t)=>{for(let[n,o]of s(t))if("__selector__"!==n)if(r(o)||l(o)||a(o,_))e.declarations.set(n,`${o}`);else{let t=e.selector.startsWith("@")&&!e.parent?n:`${/^[@]|&/.test(n)?n:`& ${n}`}`;e.rules.set(t,new g(t,o,e))}},C=(t,s,r=!0)=>{let l=r?n(s):"";if(r){let e=S.get(l);if(e)return e}let a=new g(t(),s,e);return $.style(e,`${a}`),r&&S.set(l,a),a};o($,{css:e=>a(e,g)?e:C(()=>`.${d.generate("css")}`,e),CSS:e=>t(s(e),([e,t])=>{let s=C(()=>e,{...t,__selector__:e});return f.add(s),s})}),o(p.prototype,{css(...e){return c(e,e=>M(this,e)),this}});const M=(e,t)=>{let s=$.css(t),r=s.selector.slice(1);e.addClass(r);const l=w.get(e)??/* @__PURE__ */new Set;l.add(s),w.set(e,l)};h()&&o($.CSS,{rules(e){let t=/* @__PURE__ */new Set;return c([e,...e.protos],s=>{let r=w.get(s);c(r,e=>t.add(e)),e!==s&&c(this.rules(s),e=>t.add(e))}),i(t)},text(e){return[...f,...this.rules(e)].join("\n")}}),$.process.attr.add((e,t,s)=>{if("css"===e)return c(u(t),e=>M(s,e)),!0});export{_ as $CSS,g as $CSSRule,M as assignCSS};
package/build/for.js CHANGED
@@ -1 +1 @@
1
- import{ProxyProto as t,symbol_Statement as e,onclient as s,Proto as r}from"@amateras/core";import{forEach as i}from"@amateras/utils";class o extends t{static[e]=!0;#t;list$;#e=/* @__PURE__ */new WeakMap;constructor(t,e){super(),this.list$=t,this.#t=e;let r=()=>{let{n:t,d:e}=this.run();if(i(t,t=>t.build()),!this.node?.parentNode)return;i(e,t=>t.removeNode());let r,o=s()?this.toDOM():[];i(o,t=>{r=t.parentNode?t:r?.parentNode?.insertBefore(t,r.nextSibling)})};this.list$.subscribe(r),this.disposers.add(()=>this.list$.unsubscribe(r))}build(){return this.#e=/* @__PURE__ */new WeakMap,this.run(),i(this.protos,t=>t.build()),this}run(){let t=[],e=new Set(this.protos);return this.clear(),i(this.list$.value,(s,r)=>{let i=this.#e.get(s);i?e.delete(i):(i=new a,t.push(i),this.#e.set(s,i),i.layout=()=>this.#t(s,r)),i.parent=this}),{n:t,d:e}}removeNode(){this.node?.remove(),i(this.protos,t=>t.removeNode())}}class a extends r{static[e]=!0}globalThis.For=o,$.process.craft.add((t,e,s)=>{if(t===o){let t=new o(e,s);return t.parent=r.proto,t}});export{o as For,a as ForItem};
1
+ import{ProxyProto as t,symbol_Statement as e,Proto as s}from"@amateras/core";import{forEach as i,_Array_from as o,_null as r}from"@amateras/utils";class a extends t{static[e]=!0;#t;list$;#e=/* @__PURE__ */new Map;constructor(t,e){super(),this.list$=t,this.#t=e;let s=()=>{const t=this.exec();i(this.protos,t=>t.builded||t.build()),i(t,t=>t.removeNode());let e=this.node,s=e?.parentNode;if(e&&s){let t=this.toDOM(),a=o(s.childNodes).indexOf(e);i(t,t=>{if(t!==e){if(s.childNodes[a]!==t){let e=s.childNodes[a+1]??r;s.insertBefore(t,e)}}a++})}this.parent?.mutate()};this.list$.subscribe(s),this.ondispose(()=>this.list$.unsubscribe(s))}build(){return this.#e=/* @__PURE__ */new Map,this.exec(),this.protos.forEach(t=>t.builded||t.build()),this}exec(){let t=this.protos,e=/* @__PURE__ */new Set;return i(this.list$.value,(i,o)=>{$.context(s,this,()=>{let s=this.#t,r=this.#e.get(i)??new l(()=>s(i,o));this.#e.set(i,r),t.delete(r),e.add(r)})}),this.replaceProtos(...e),t}removeNode(){this.node?.remove(),i(this.protos,t=>t.removeNode())}dispose(){super.dispose(),i(this.#e.values(),t=>t.dispose()),this.#e.clear()}}class l extends s{static[e]=!0}globalThis.For=a,$.process.craft.add((t,e,i)=>{if(t===a){let t=new a(e,i);return s.proto?.append(t),t}});export{a as For,l as ForItem};
package/build/i18n.js CHANGED
@@ -1 +1 @@
1
- import{isFunction as t,isObject as e,isUndefined as s,map as i,forEach as a,_null as n,_Object_assign as r,_instanceof as o}from"@amateras/utils";import{ProxyProto as l,GlobalState as c}from"@amateras/core";class h{#t=null;#e=null;constructor(e){t(e)?this.#e=e:this.#t=e}async context(){if(this.#t)return await this.#t;if(!this.#e)throw"I18n Context Fetch Error";return this.#t=this.#e().then(t=>t.default)}async find(t,s){s||(s=await this.context());const[i,...a]=t.split("."),n=s[i];return e(n)?a.length?this.find(a.join("."),n):n._:a.length?t:n}}class u extends l{i18n;key;options;constructor(t,e,s){super(),this.i18n=t,this.key=e,this.options=s,this.i18n.translations.add(this)}build(){return this.update(),this}async update(){const{key:t,i18n:e,options:n}=this,r=(t,e=[])=>{this.layout=()=>{t.raw=t,$(t,...e)},a(this.protos,t=>t.removeNode()),super.build(),this.node?.replaceWith(...this.toDOM())};t:{const a=e.dictionary();if(!a){r([t]);break t}const o=a.find(t);this.global.i18n.promises.push(o);const l=await o;if(s(l))break t;const c=l.split(/\$[a-zA-Z0-9_]+\$/);if(1===c.length||!n){r([l]);break t}const h=l.matchAll(/(\$([a-zA-Z0-9_]+)\$)/g);r(c,i(h,([,,t])=>n[t]))}return this}}class d{map=/* @__PURE__ */new Map;#s;translations=/* @__PURE__ */new Set;locale;constructor(t){this.#s=t,this.locale=t}defaultLocale(t){return arguments.length?(t&&(this.#s=t),this):this.#s}async setLocale(t){if(!arguments.length)return this.locale;if(t){if(!this.map.get(t))return t=t.split("-")[0],this.setLocale(t);t!==this.locale&&(this.locale=t,await Promise.all(i(this.translations,t=>t.update())))}return this}dictionary(t=this.locale){if(!t)return n;return this.map.get(t)}translate(t,e){return new u(this,t,e)}}r(c.prototype,{i18n:{promises:[]}}),c.disposers.add(t=>{t.i18n.promises=[]}),r($,{i18n(t){const e=new d(t),s=(t,s)=>e.translate(t,s);return r(s,{i18n:e,async locale(t){await e.setLocale(t)},add(t,s){return e.map.set(t,new h(s)),this},delete(t){return e.map.delete(t),this},dir:t=>(s,i)=>e.translate(`${t}.${s}`,i)}),s}}),$.process.text.add(t=>{if(o(t,u))return t});export{d as I18n,h as I18nDictionary,u as I18nTranslation};
1
+ import{onclient as t,ProxyProto as e,Proto as s,GlobalState as i}from"@amateras/core";import{isFunction as n,isAsyncFunction as o,isObject as a,forEach as r,isUndefined as l,map as h,_null as c,_Object_assign as u,_instanceof as d}from"@amateras/utils";class f{#t=null;#e=null;constructor(t){n(t)?this.#e=t:this.#t=t}async context(){let e=()=>t()&&window.dispatchEvent(new Event("i18ncontext"));if(this.#t)return o(this.#t)?await this.#t.finally(e):this.#t;if(!this.#e)throw"I18n Context Fetch Error";return this.#t=this.#e().then(t=>t.default).finally(e)}async find(t,e){e||(e=await this.context());const[s,...i]=t.split("."),n=e[s];return a(n)?i.length?this.find(i.join("."),n):n._:i.length?t:n}}class p extends e{session;key;options;constructor(t,e,s){super(),this.session=t,this.key=e,this.options=s,t.translations.add(this)}dispose(){super.dispose(),this.session.translations.delete(this)}build(){return this.update(),this}async update(){const t=this.session.fetch(this.key,this.options);this.global.asyncTask(t);const{text:e,args:s}=await t;return this.layout=()=>{e.raw=e,$(e,...s)},r(this.protos,t=>t.removeNode()),super.build(),this.node?.replaceWith(...this.toDOM()),this.dispatch("i18nupdate",this,{bubbles:!0}),this}}class g{translations=/* @__PURE__ */new Set;i18n;#s;constructor(t){this.i18n=t,this.#s=t.locale(),t.sessions.add(this)}async fetch(t,e){const s=this.i18n.dictionaries.get(this.#s);if(!s)return{text:[t],args:[]};const i=await s.find(t);if(l(i))return{text:[t],args:[]};const n=i.split(/\$[a-zA-Z0-9_]+\$/);if(1===n.length||!e)return{text:[i],args:[]};const o=i.matchAll(/(\$([a-zA-Z0-9_]+)\$)/g);return{text:n,args:h(o,([,,t])=>e[t])}}locale(e){if(!arguments.length)return this.#s;if(e){if(!this.i18n.dictionaries.get(e)){let t=e.split("-");if(1===t.length)return;return this.locale(t[0])}}return e&&e!==this.#s?(this.#s=e,new Promise(async e=>{await Promise.all(h(this.translations,t=>t.update())),e(),t()&&dispatchEvent(new Event("localeupdate"))})):void 0}}class w{#s;dictionaries=/* @__PURE__ */new Map;defaultLocale;sessions=/* @__PURE__ */new Set;session=new g(this);path="";static key="__locale__";constructor(t){this.defaultLocale=t,this.#s=t,this.sessions.add(this.session)}add(t,e){return this.dictionaries.set(t,new f(e)),this}delete(t){return this.dictionaries.delete(t),this}t(t,e){return new p(this.getSession(),this.getFullPath(t),e)}async text(t,e){let s=await this.getSession().fetch(this.getFullPath(t),e);return s.text.reduce((t,e,i)=>t+e+(s.args[i]||""),"")}dir(t){let e=this;return{t:(s,i)=>e.t(`${t}.${s}`,i),text:(s,i)=>e.text(`${t}.${s}`,i),dir:s=>e.dir(`${t}.${s}`)}}locale(t){if(!arguments.length)return this.readStoreLocale(),this.#s;if(!t)return;if(!this.dictionaries.get(t)){let e=t.split("-");if(1===e.length)return;return this.locale(e[0])}return this.#s=t,this.writeStoreLocale(t),Promise.all(h(this.sessions,e=>e.locale(t)))}getFullPath(t){return this.path?`${this.path}.${t}`:t}getSession(){let t=s.proto;if(t){let e=t.global.i18n.session??new g(this);return t.global.i18n.session=e,e}return this.session}readStoreLocale(){t()&&(this.#s=localStorage.getItem(w.key)??this.defaultLocale)}writeStoreLocale(e){t()&&localStorage.setItem(w.key,e)}}i.assign({i18n:{session:c}}),u($,{i18n:t=>new w(t)}),$.process.text.add(t=>{if(d(t,p))return t});export{w as I18n,f as I18nDictionary,p as I18nTranslation};
package/build/if.js CHANGED
@@ -1 +1 @@
1
- import{Proto as e,symbol_Statement as t,ProxyProto as s}from"@amateras/core";import{_null as a,forEach as i,_instanceof as l,isEqual as r}from"@amateras/utils";import{Signal as d}from"@amateras/signal";class n extends e{static[t]=!0;exp$;builded=!1;constructor(e,t){super(t),this.exp$=e}build(e){return super.build(e),this.builded=!0,this}validate(){return!this.exp$||!!this.exp$.value}}class o extends n{}class u extends n{}class h extends n{}class m extends s{static[t]=!0;statements=/* @__PURE__ */new Set;statement=a;build(){super.build(!1),this.validate()?.build();let e=()=>{let e=this.validate();e?.builded||e?.build(),this.statement!==e&&(this.statement=e??a,i(this.statements,t=>t!==e&&t.removeNode()),this.node?.replaceWith(...this.toDOM()))};return i(this.statements,t=>{t.exp$?.subscribe(e),t.disposers.add(()=>t.exp$?.unsubscribe(e))}),this}validate(){this.clear();for(let e of this.statements)if(e.validate())return e.parent=this,e}}globalThis.If=h,globalThis.Else=o,globalThis.ElseIf=u;let p=/* @__PURE__ */new WeakMap;$.process.craft.add((t,s,i)=>{let n=e.proto,b=n?p.get(n):a;if(t===h&&(b=new m,n&&(b.parent=n,p.set(n,b))),l(b,m)){if(r(t,[h,o,u])){{let e=new t(...l(s,d)?[s,i]:[a,s]);b.statements.add(e)}return b}n&&p.delete(n)}else if(r(t,[o,u]))throw"ElseIf/Else must be after If or ElseIf"});
1
+ import{Proto as t,symbol_Statement as e,ProxyProto as s}from"@amateras/core";import{_null as i,forEach as a,_instanceof as l,isIncluded as r}from"@amateras/utils";import{Signal as n}from"@amateras/signal";class o extends t{static[e]=!0;exp$;constructor(t,e){super(()=>e(this.exp$)),this.exp$=t}dispose(){super.dispose(),this.exp$=i}validate(){return!this.exp$||!!this.exp$.value}}class p extends o{}class d extends o{}class h extends o{}class m extends s{static[e]=!0;statements=i;statement=i;build(){super.build(!1),this.validate()?.build();let t=()=>{let t=this.validate();t?.builded||t?.build(),this.statement!==t&&(this.statement=t??i,a(this.statements,e=>e!==t&&e.removeNode()),this.node?.replaceWith(...this.toDOM()),this.parent?.mutate())};return a(this.statements,e=>{e.exp$?.subscribe(t),e.ondispose(()=>{e.exp$?.unsubscribe(t)})}),this}dispose(){super.dispose(),a(this.statements,t=>t.dispose()),this.statement=i,this.statements=i}validate(){if(this.clear(),this.statements)for(let t of this.statements)if(t.validate())return this.append(t),t}}globalThis.If=h,globalThis.Else=p,globalThis.ElseIf=d;let u=null;$.process.craft.add((e,s,a)=>{let o=t.proto;if(e===h&&(u=new m,o?.append(u)),l(u,m)){if(r(e,[h,p,d])){{let t=new e(...l(s,n)?[s,a]:[i,s]);u.statements=u.statements??[],u.statements?.push(t)}return u}u=i}else if(r(e,[p,d]))throw"ElseIf/Else must be after If or ElseIf"});
@@ -1 +1 @@
1
- const t=`https://unpkg.com/amateras@${"0.11.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 t=`https://unpkg.com/amateras@${"0.12.0"}/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)}
package/build/markdown.js CHANGED
@@ -1 +1 @@
1
- import{isString as t,forEach as e,uppercase as n,isUndefined as o,isEqual as a,_Array_from as s}from"@amateras/utils";const r="BLOCK",l="IMAGE",i="LINK",c="QUICK_LINK",h="CODE",p="ITALIC",u="BOLD",d="TEXT_LINE",k="HEADING",T="CODE_START",g="CODE_END",f="UNORDERED_LIST_ITEM",m="ORDERED_LIST_ITEM",E="BLOCKQUOTE",y="ALERT",w="ALERT_LINE",L="HORIZONTAL_RULE",b="TABLE",x="EMPTY_LINE",I="INLINE_TEXT";class ${blockTokenizers=/* @__PURE__ */new Map;inlineTokenizers=/* @__PURE__ */new Map;blockTokenize(t){const e=t?.split(/\r?\n/)??[],n=[];let o=0;t:for(;o<e.length;){let t,a=e[o];if(void 0===a)throw"LINE ERROR";for(const[s,l]of this.blockTokenizers){const i=a.match(l.regex);if(i){const{content:a,multiLine:c,data:h}=l.handle(i,o,e);if(t={layout:r,type:s,content:a,data:h},c){n.push(t),n.push(...c.tokens),o=c.skip;continue t}break}}t||(t={layout:r,...a.length?{type:d,content:this.inlineTokenize(a)}:{type:x,content:[]}}),n.push(t),o++}return n}inlineTokenize(e){const n=[];let o=e;for(;o.length;){let e;for(const[a,s]of this.inlineTokenizers){const r=o.match(s.regex);if(r){const{index:l,0:i}=r;0!=l&&n.push(...this.inlineTokenize(o.substring(0,l)));const{content:c,data:h}=s.handle(r);e={type:a,...t(c)?{layout:I,text:c}:{layout:"INLINE_CONTENT",content:c}},h&&(e.data=h),o=o.substring(l+i.length);break}}e||(e={type:"TEXT",layout:I,text:o},o=""),n.push(e)}return n}use(...t){return e(t,t=>t(this)),this}}class N{processors=/* @__PURE__ */new Map;parse(e){let n="",o=0;if(!e)return n;for(;o<e.length;){const a=e[o],s=this.processors.get(a.type);if(s){const r=s(a,e.slice(o));t(r)?n+=r:(n+=r.html,o+=r.skipTokens)}o++}return n}use(...t){return e(t,t=>t(this)),this}}const z=(t,e,n)=>t.blockTokenizers.set(e,n),O=(t,e,n)=>t.inlineTokenizers.set(e,n),_=(t,e,n)=>t.processors.set(e,n),A=(t,e)=>`<${t}>${e}</${t}>`,R=t=>(e([["&","&amp;"],["<","&lt;"],[">","&gt;"],['"',"&quot;"],["'","&#39;"]],e=>t=t.replaceAll(...e)),t),C=t=>_(t,y,(e,o)=>{let a="",s=1;for(;s<o.length;){const e=o[s];if(e.type!==w)break;a+=t.parse(e.content[0].content),s++}const r=e.data?.alertType;return{html:`<blockquote class="alert alert-${r}"><p class="alert-title">${n(r,0,1)}</p>${a}</blockquote>`,skipTokens:s}}),M=t=>z(t,y,{regex:/^> ?\[!(?:(?:NOTE)|(?:TIP)|(?:IMPORTANT)|(?:WARNING)|(?:CAUTION))\]/,handle(e,n,o){const a=[],s=o[n].match(/> ?\[!(.+?)\]/),l=s?.[1]?.toLowerCase();for(n++;n<o.length;){const e=o[n].match(/^> ?(.+)/);if(!e)break;a.push({layout:r,type:w,content:t.blockTokenize(e[1])}),n++}return{content:[],data:{alertType:l},multiLine:{skip:n,tokens:a}}}}),D=t=>_(t,E,(e,n)=>{let o=0;const a=e=>{let s="";for(;o<n.length;){const{type:r,content:l,data:i}=n[o];if(r!==E)break;if(i.deep>e)s+=a(i.deep);else{if(i.deep<e)break;s+=t.parse(l),o++}}return A("blockquote",s)};return{html:a(e.data.deep),skipTokens:o}}),B=t=>z(t,E,{regex:/^(>+) ?(.+)?/,handle:e=>({content:t.blockTokenize(e[2]??""),data:{deep:e[1].length-1}})}),U=t=>_(t,u,e=>A("b",t.parse(e.content))),X=t=>O(t,u,{regex:/\*\*(.+?\*?)\*\*/,handle:e=>({content:t.inlineTokenize(e[1])})}),K=t=>_(t,h,t=>A("code",R(t.text))),S=t=>O(t,h,{regex:/`(.+?)`/,handle:t=>({content:t[1]})}),q=t=>_(t,T,(t,e)=>{let n="",o=1;for(;o<e.length;){const t=e[o];if(t.type===g)break;n+=t.content[0].text,o++}return{html:`<pre><code${t.data?.lang?` lang="${t.data.lang}"`:""}>${R(n)}</code></pre>`,skipTokens:o}}),v=t=>z(t,T,{regex:/^```(\w+)?/,handle:(t,e,n)=>{const o=[];for(e++;e<n.length;){const t=n[e];if(e++,t.includes("```")){o.push({layout:r,type:g,content:[]});break}o.push({layout:r,type:"CODE_LINE",content:[{layout:"INLINE_TEXT",type:"CODE_TEXT",text:`${t}\n`}]})}return{content:[],data:{lang:t[1]},multiLine:{skip:e,tokens:o}}}}),G=t=>_(t,k,e=>{const n=`h${e.data.level}`;return A(n,t.parse(e.content))}),H=t=>z(t,k,{regex:/^(#+) (.+)/,handle:e=>({content:t.inlineTokenize(e[2]),data:{level:e[1].length}})}),P=t=>_(t,L,t=>"<hr>"),j=t=>z(t,L,{regex:/^---/,handle:t=>({content:[]})}),Q=t=>_(t,l,e=>{const{url:n,title:o}=e.data;return`<img alt="${t.parse(e.content)}" src="${n}"${o?` title="${o}"`:""}>`}),W=t=>O(t,l,{regex:/^!\[(.+?)\]\((.+?)\)/,handle:e=>{const[n,o,a]=e,[s,r,l]=a.match(/(\w\w+?:\/\/[^\s]+)(?: "(.+?)")?/);return{content:t.inlineTokenize(o),data:{url:r,title:l}}}}),Y=t=>_(t,p,e=>`<i>${t.parse(e.content)}</i>`),Z=t=>O(t,p,{regex:/\*(.+?)\*/,handle:e=>({content:t.inlineTokenize(e[1])})}),F=t=>{const e=e=>{const{href:n,email:a,title:s}=e.data;return`<a href="${o(n)?`mailto:${a}`:n}"${s?` title="${s}"`:""}>${e.text??t.parse(e.content)}</a>`};_(t,c,e),_(t,i,e)},J=t=>{O(t,i,{regex:/\[(.+?)\]\(((?:\w+?@(?:\w|\.\w)+)|(?:\w\w+?:[^\s)]+))(?: "(.+)?")?\)/,handle:e=>{const[n,o,a,s]=e,r=a.match(/(?:\w+?@(?:\w|\.\w)+)|(?:\w\w+?:\/\/[^\s]+)/),[l]=r,i=l.includes("@")?{email:l}:{href:l};return{content:t.inlineTokenize(o),data:{title:s,...i}}}}),O(t,c,{regex:/<((?:\w+?@(?:\w|\.\w)+)|(?:\w\w+?:[^\s>]+))>/,handle:t=>{const[e,n]=t,o=n.match(/(?:\w+?@(?:\w|\.\w)+)|(?:\w\w+?:\/\/[^\s]+)/),[a]=o,s=a.includes("@")?{email:a}:{href:a};return{content:a,data:s}}})},V=e=>{const n=t=>t===m?"ol":"ul",o=(t,o)=>{let l=0;const i=/* @__PURE__ */new Map,c=(t,h)=>{const p=i.get(h),u=p&&n(t)===p.tagname?p:r(n(t),[]);for(i.set(h,u);l<o.length;){const n=o[l],r=n.type;if(!a(r,[m,f,x,d])){l--;break}if(r===d){const t=n.content[0]?.text;if(t?.match(/^\s\s/)){const e=t.match(/^(\s+)(.+)?/);if(!e[2]){l++;continue}n.data={deep:Math.trunc(e[1].length/2)-1}}else{if(!t?.match(/^\t/)){l--;break}{const e=t.match(/^(\t+)(.+)?/);if(!e[2]){l++;continue}n.data={deep:e[1].length-1}}}}if(r===x)l++;else if(n.data.deep!==h){if(!(n.data.deep>h)){i.delete(h);break}i.get(h)?.items.at(-1)?.content.push(c(r,n.data.deep))}else if(r===d)u.paragraph=!0,u.items.at(-1)?.content.push(e.parse(n.content)),l++;else{if(r!==t){i.delete(h);break}u.items.push(s([e.parse(n.content)])),l++}}return u};return{html:`${c(t.type,t.data.deep)}`,skipTokens:l}},s=t=>({content:t,toString(){return A("li",this.content.join(""))}}),r=(e,n)=>({tagname:e,items:n,paragraph:!1,toString(){return this.paragraph&&this.items.forEach(e=>e.content.forEach((n,o)=>t(n)&&(e.content[o]=A("p",n)))),A(this.tagname,this.items.join(""))}});_(e,f,o),_(e,m,o)},tt=t=>{const e=e=>{const n=e[0].split(/[-*]/)[0],o=n.match(/\s/)?.length??0,a=n.match(/\t/)?.length??0;return{content:t.inlineTokenize(e[1]),data:{deep:Math.trunc(a+o/2)}}};z(t,f,{regex:/^(?:[\s\t]+)?[-*] (.+)/,handle:e}),z(t,m,{regex:/^(?:[\s\t]+)?\d+\. (.+)/,handle:e})},et=t=>_(t,b,e=>{let n="",o="",a=0;for(const s of e.content){let r="";for(let n=0;n<s.content.length;n++){const o=s.content[n],l=0===a?"th":"td";r+=`<${l} align="${e.data.align[n]??"left"}">${t.parse(o.content)}</${l}>`}0===a?n+=A("thead",A("tr",r)):o+=A("tr",r),a++}return o=A("tbody",o),A("table",n+o)}),nt=t=>z(t,b,{regex:/\|(?:.+\|)+/,handle(e,n,o){const a=[],l=[];for(;n<o.length;){const e={type:"TABLE_ROW",layout:r,content:[]},i=o[n],c=s(i.matchAll(/\| ([^|]+)/g));if(!c.length)break;for(const n of c){const o=n[1],a=o.match(/(:)?---+(:)?/);if(a){const[t,e,n]=a;l.push(n?e?"center":"right":"left");continue}e.content.push({type:"TABLE_COLUMN",content:t.inlineTokenize(o.trim()),layout:r})}e.content.length&&a.push(e),n++}return{content:a,data:{align:l},multiLine:{skip:n,tokens:[]}}}}),ot=t=>_(t,"TEXT",t=>t.text),at=t=>_(t,d,(e,n)=>{let o="",a=0;for(const s of n){if(s.type===x)break;o+=t.parse(s.content),a++}return{html:A("p",o),skipTokens:a}});class st{lexer=new $;parser=new N;constructor(){this.lexer.use(H,v,tt,nt,M,B,j,W,J,S,X,Z),this.parser.use(ot,Q,F,K,Y,U,at,G,q,V,et,C,D,P)}parseHTML(t){return this.parser.parse(this.lexer.blockTokenize(t))}}export{st as Markdown,$ as MarkdownLexer,N as MarkdownParser};
1
+ import{isString as t,forEach as e,uppercase as n,isUndefined as o,isIncluded as a,_Array_from as s}from"@amateras/utils";const r="BLOCK",l="IMAGE",i="LINK",c="QUICK_LINK",h="CODE",p="ITALIC",u="BOLD",d="TEXT_LINE",k="HEADING",T="CODE_START",g="CODE_END",f="UNORDERED_LIST_ITEM",m="ORDERED_LIST_ITEM",E="BLOCKQUOTE",y="ALERT",w="ALERT_LINE",L="HORIZONTAL_RULE",b="TABLE",x="EMPTY_LINE",I="INLINE_TEXT";class ${blockTokenizers=/* @__PURE__ */new Map;inlineTokenizers=/* @__PURE__ */new Map;blockTokenize(t){const e=t?.split(/\r?\n/)??[],n=[];let o=0;t:for(;o<e.length;){let t,a=e[o];if(void 0===a)throw"LINE ERROR";for(const[s,l]of this.blockTokenizers){const i=a.match(l.regex);if(i){const{content:a,multiLine:c,data:h}=l.handle(i,o,e);if(t={layout:r,type:s,content:a,data:h},c){n.push(t),n.push(...c.tokens),o=c.skip;continue t}break}}t||(t={layout:r,...a.length?{type:d,content:this.inlineTokenize(a)}:{type:x,content:[]}}),n.push(t),o++}return n}inlineTokenize(e){const n=[];let o=e;for(;o.length;){let e;for(const[a,s]of this.inlineTokenizers){const r=o.match(s.regex);if(r){const{index:l,0:i}=r;0!=l&&n.push(...this.inlineTokenize(o.substring(0,l)));const{content:c,data:h}=s.handle(r);e={type:a,...t(c)?{layout:I,text:c}:{layout:"INLINE_CONTENT",content:c}},h&&(e.data=h),o=o.substring(l+i.length);break}}e||(e={type:"TEXT",layout:I,text:o},o=""),n.push(e)}return n}use(...t){return e(t,t=>t(this)),this}}class N{processors=/* @__PURE__ */new Map;parse(e){let n="",o=0;if(!e)return n;for(;o<e.length;){const a=e[o],s=this.processors.get(a.type);if(s){const r=s(a,e.slice(o));t(r)?n+=r:(n+=r.html,o+=r.skipTokens)}o++}return n}use(...t){return e(t,t=>t(this)),this}}const z=(t,e,n)=>t.blockTokenizers.set(e,n),O=(t,e,n)=>t.inlineTokenizers.set(e,n),_=(t,e,n)=>t.processors.set(e,n),A=(t,e)=>`<${t}>${e}</${t}>`,R=t=>(e([["&","&amp;"],["<","&lt;"],[">","&gt;"],['"',"&quot;"],["'","&#39;"]],e=>t=t.replaceAll(...e)),t),C=t=>_(t,y,(e,o)=>{let a="",s=1;for(;s<o.length;){const e=o[s];if(e.type!==w)break;a+=t.parse(e.content[0].content),s++}const r=e.data?.alertType;return{html:`<blockquote class="alert alert-${r}"><p class="alert-title">${n(r,0,1)}</p>${a}</blockquote>`,skipTokens:s}}),M=t=>z(t,y,{regex:/^> ?\[!(?:(?:NOTE)|(?:TIP)|(?:IMPORTANT)|(?:WARNING)|(?:CAUTION))\]/,handle(e,n,o){const a=[],s=o[n].match(/> ?\[!(.+?)\]/),l=s?.[1]?.toLowerCase();for(n++;n<o.length;){const e=o[n].match(/^> ?(.+)/);if(!e)break;a.push({layout:r,type:w,content:t.blockTokenize(e[1])}),n++}return{content:[],data:{alertType:l},multiLine:{skip:n,tokens:a}}}}),D=t=>_(t,E,(e,n)=>{let o=0;const a=e=>{let s="";for(;o<n.length;){const{type:r,content:l,data:i}=n[o];if(r!==E)break;if(i.deep>e)s+=a(i.deep);else{if(i.deep<e)break;s+=t.parse(l),o++}}return A("blockquote",s)};return{html:a(e.data.deep),skipTokens:o}}),B=t=>z(t,E,{regex:/^(>+) ?(.+)?/,handle:e=>({content:t.blockTokenize(e[2]??""),data:{deep:e[1].length-1}})}),U=t=>_(t,u,e=>A("b",t.parse(e.content))),X=t=>O(t,u,{regex:/\*\*(.+?\*?)\*\*/,handle:e=>({content:t.inlineTokenize(e[1])})}),K=t=>_(t,h,t=>A("code",R(t.text))),S=t=>O(t,h,{regex:/`(.+?)`/,handle:t=>({content:t[1]})}),q=t=>_(t,T,(t,e)=>{let n="",o=1;for(;o<e.length;){const t=e[o];if(t.type===g)break;n+=t.content[0].text,o++}return{html:`<pre><code${t.data?.lang?` lang="${t.data.lang}"`:""}>${R(n)}</code></pre>`,skipTokens:o}}),v=t=>z(t,T,{regex:/^```(\w+)?/,handle:(t,e,n)=>{const o=[];for(e++;e<n.length;){const t=n[e];if(e++,t.includes("```")){o.push({layout:r,type:g,content:[]});break}o.push({layout:r,type:"CODE_LINE",content:[{layout:"INLINE_TEXT",type:"CODE_TEXT",text:`${t}\n`}]})}return{content:[],data:{lang:t[1]},multiLine:{skip:e,tokens:o}}}}),G=t=>_(t,k,e=>{const n=`h${e.data.level}`;return A(n,t.parse(e.content))}),H=t=>z(t,k,{regex:/^(#+) (.+)/,handle:e=>({content:t.inlineTokenize(e[2]),data:{level:e[1].length}})}),P=t=>_(t,L,t=>"<hr>"),j=t=>z(t,L,{regex:/^---/,handle:t=>({content:[]})}),Q=t=>_(t,l,e=>{const{url:n,title:o}=e.data;return`<img alt="${t.parse(e.content)}" src="${n}"${o?` title="${o}"`:""}>`}),W=t=>O(t,l,{regex:/^!\[(.+?)\]\((.+?)\)/,handle:e=>{const[n,o,a]=e,[s,r,l]=a.match(/(\w\w+?:\/\/[^\s]+)(?: "(.+?)")?/);return{content:t.inlineTokenize(o),data:{url:r,title:l}}}}),Y=t=>_(t,p,e=>`<i>${t.parse(e.content)}</i>`),Z=t=>O(t,p,{regex:/\*(.+?)\*/,handle:e=>({content:t.inlineTokenize(e[1])})}),F=t=>{const e=e=>{const{href:n,email:a,title:s}=e.data;return`<a href="${o(n)?`mailto:${a}`:n}"${s?` title="${s}"`:""}>${e.text??t.parse(e.content)}</a>`};_(t,c,e),_(t,i,e)},J=t=>{O(t,i,{regex:/\[(.+?)\]\(((?:\w+?@(?:\w|\.\w)+)|(?:\w\w+?:[^\s)]+))(?: "(.+)?")?\)/,handle:e=>{const[n,o,a,s]=e,r=a.match(/(?:\w+?@(?:\w|\.\w)+)|(?:\w\w+?:\/\/[^\s]+)/),[l]=r,i=l.includes("@")?{email:l}:{href:l};return{content:t.inlineTokenize(o),data:{title:s,...i}}}}),O(t,c,{regex:/<((?:\w+?@(?:\w|\.\w)+)|(?:\w\w+?:[^\s>]+))>/,handle:t=>{const[e,n]=t,o=n.match(/(?:\w+?@(?:\w|\.\w)+)|(?:\w\w+?:\/\/[^\s]+)/),[a]=o,s=a.includes("@")?{email:a}:{href:a};return{content:a,data:s}}})},V=e=>{const n=t=>t===m?"ol":"ul",o=(t,o)=>{let l=0;const i=/* @__PURE__ */new Map,c=(t,h)=>{const p=i.get(h),u=p&&n(t)===p.tagname?p:r(n(t),[]);for(i.set(h,u);l<o.length;){const n=o[l],r=n.type;if(!a(r,[m,f,x,d])){l--;break}if(r===d){const t=n.content[0]?.text;if(t?.match(/^\s\s/)){const e=t.match(/^(\s+)(.+)?/);if(!e[2]){l++;continue}n.data={deep:Math.trunc(e[1].length/2)-1}}else{if(!t?.match(/^\t/)){l--;break}{const e=t.match(/^(\t+)(.+)?/);if(!e[2]){l++;continue}n.data={deep:e[1].length-1}}}}if(r===x)l++;else if(n.data.deep!==h){if(!(n.data.deep>h)){i.delete(h);break}i.get(h)?.items.at(-1)?.content.push(c(r,n.data.deep))}else if(r===d)u.paragraph=!0,u.items.at(-1)?.content.push(e.parse(n.content)),l++;else{if(r!==t){i.delete(h);break}u.items.push(s([e.parse(n.content)])),l++}}return u};return{html:`${c(t.type,t.data.deep)}`,skipTokens:l}},s=t=>({content:t,toString(){return A("li",this.content.join(""))}}),r=(e,n)=>({tagname:e,items:n,paragraph:!1,toString(){return this.paragraph&&this.items.forEach(e=>e.content.forEach((n,o)=>t(n)&&(e.content[o]=A("p",n)))),A(this.tagname,this.items.join(""))}});_(e,f,o),_(e,m,o)},tt=t=>{const e=e=>{const n=e[0].split(/[-*]/)[0],o=n.match(/\s/)?.length??0,a=n.match(/\t/)?.length??0;return{content:t.inlineTokenize(e[1]),data:{deep:Math.trunc(a+o/2)}}};z(t,f,{regex:/^(?:[\s\t]+)?[-*] (.+)/,handle:e}),z(t,m,{regex:/^(?:[\s\t]+)?\d+\. (.+)/,handle:e})},et=t=>_(t,b,e=>{let n="",o="",a=0;for(const s of e.content){let r="";for(let n=0;n<s.content.length;n++){const o=s.content[n],l=0===a?"th":"td";r+=`<${l} align="${e.data.align[n]??"left"}">${t.parse(o.content)}</${l}>`}0===a?n+=A("thead",A("tr",r)):o+=A("tr",r),a++}return o=A("tbody",o),A("table",n+o)}),nt=t=>z(t,b,{regex:/\|(?:.+\|)+/,handle(e,n,o){const a=[],l=[];for(;n<o.length;){const e={type:"TABLE_ROW",layout:r,content:[]},i=o[n],c=s(i.matchAll(/\| ([^|]+)/g));if(!c.length)break;for(const n of c){const o=n[1],a=o.match(/(:)?---+(:)?/);if(a){const[t,e,n]=a;l.push(n?e?"center":"right":"left");continue}e.content.push({type:"TABLE_COLUMN",content:t.inlineTokenize(o.trim()),layout:r})}e.content.length&&a.push(e),n++}return{content:a,data:{align:l},multiLine:{skip:n,tokens:[]}}}}),ot=t=>_(t,"TEXT",t=>t.text),at=t=>_(t,d,(e,n)=>{let o="",a=0;for(const s of n){if(s.type===x)break;o+=t.parse(s.content),a++}return{html:A("p",o),skipTokens:a}});class st{lexer=new $;parser=new N;constructor(){this.lexer.use(H,v,tt,nt,M,B,j,W,J,S,X,Z),this.parser.use(ot,Q,F,K,Y,U,at,G,q,V,et,C,D,P)}parseHTML(t){return this.parser.parse(this.lexer.blockTokenize(t))}}export{st as Markdown,$ as MarkdownLexer,N as MarkdownParser};
package/build/match.js CHANGED
@@ -1 +1 @@
1
- import{Proto as t,symbol_Statement as e,ProxyProto as s}from"@amateras/core";import{isArray as i,_null as a,forEach as r,is as d}from"@amateras/utils";class l extends t{static[e]=!0;condition;constructor(t,e){super(e),this.condition=i(t)?t:[t]}}class o extends t{static[e]=!0;constructor(t){super(t)}}class h extends s{static[e]=!0;exp$;cases=/* @__PURE__ */new Set;matched=a;#t=a;constructor(t,e){super(()=>{e((t,e,s)=>{$(t,e,s)})}),this.exp$=t}build(){super.build(),this.validate();let t=()=>{let t=this.matched,e=this.validate();t!==e&&(r(this.cases,t=>t!==e&&t.removeNode()),e!==this.#t&&this.#t?.removeNode(),this.node?.replaceWith(...this.toDOM()))};return r(this.cases,e=>{e.build(),this.exp$.subscribe(t),e.disposers.add(()=>this.exp$.unsubscribe(t))}),this.#t?.build(),this}case(t,e){let s=new l(t,e);return this.cases.add(s),s}default(t){let e=new o(t);return this.#t=e,e}validate(){this.clear();for(let t of this.cases)if(t.condition.includes(this.exp$.value))return t.parent=this,this.matched=t;if(this.#t)return this.#t.parent=this,this.matched=this.#t}}globalThis.Match=h,globalThis.Case=l,globalThis.Default=o,$.process.craft.add((e,s,i)=>{if(e===h){let e=new h(s,i);return e.parent=t.proto,e}return e===l?d(t.proto,h)?.case(s,i):e===o?d(t.proto,h)?.default(s):void 0});
1
+ import{Proto as t,symbol_Statement as e,ProxyProto as s}from"@amateras/core";import{isArray as i,_null as a,forEach as d,is as r}from"@amateras/utils";class h extends t{static[e]=!0;condition;constructor(t,e){super(e),this.condition=i(t)?t:[t]}}class l extends t{static[e]=!0;constructor(t){super(t)}}class o extends s{static[e]=!0;exp$;cases=/* @__PURE__ */new Set;matched=a;#t=a;constructor(t,e){super(()=>{e((t,e,s)=>{$(t,e,s)})}),this.exp$=t}dispose(){d(this.cases,t=>t.dispose()),this.#t?.dispose(),this.matched=a,this.#t=a,this.cases.clear()}build(){super.build(!1),this.validate();let t=()=>{let t=this.matched,e=this.validate();t!==e&&(d(this.cases,t=>t!==e&&t.removeNode()),e!==this.#t&&this.#t?.removeNode(),this.node?.replaceWith(...this.toDOM()),this.parent?.mutate())};return d(this.cases,e=>{this.exp$.subscribe(t),e.ondispose(()=>this.exp$.unsubscribe(t))}),this}case(t,e){let s=new h(t,e);return this.cases.add(s),s}default(t){let e=new l(t);return this.#t=e,e}validate(){this.clear();for(let t of this.cases)if(t.condition.includes(this.exp$.value))return this.append(t),t.builded||t.build(),this.matched=t;if(this.#t)return this.append(this.#t),this.#t.builded||this.#t.build(),this.matched=this.#t}}globalThis.Match=o,globalThis.Case=h,globalThis.Default=l,$.process.craft.add((e,s,i)=>{if(e===o){let e=new o(s,i);return t.proto?.append(e),e}return e===h?r(t.proto,o)?.case(s,i):e===l?r(t.proto,o)?.default(s):void 0});
package/build/meta.js CHANGED
@@ -1 +1 @@
1
- import{_Object_entries as t,isString as e,isArray as o,forEach as r,_Object_assign as n}from"@amateras/utils";import{onclient as a,Proto as i,onserver as m}from"@amateras/core";const s=(n,a,i,m)=>{let p=t=>i?`${i}:${t}`:t,c=(t,e)=>a.push({[m]:p(t),content:e});for(const[l,f]of t(n))e(f)?c(l,f):o(f)?r(f,t=>{e(t)?c(l,t):s(t,a,p(l),m)}):s(f,a,p(l),m)};n($,{meta(t){if(a())return;let e=i.proto;e&&(e.global.meta=t)}}),m()&&n($.meta,{resolve:function(t){let e=[],{description:o,og:r,twitter:n}=t;return o&&e.push({name:"description",content:o}),r&&s(r,e,"og","property"),n&&s(n,e,"twitter","name"),e}});
1
+ import{_Object_entries as t,isString as o,isArray as e,forEach as r,_Object_assign as n,isNull as a,isObject as i}from"@amateras/utils";import{onclient as m,Proto as s,onserver as c}from"@amateras/core";const f=(n,a,i,m)=>{let s=t=>i?`${i}:${t}`:t,c=(t,o)=>a.push({[m]:s(t),content:o});for(const[l,p]of t(n))o(p)?c(l,p):e(p)?r(p,t=>{o(t)?c(l,t):f(t,a,s(l),m)}):f(p,a,s(l),m)};function l(o,e){for(const[r,n]of t(e))!a(n)&&i(n)&&o[r]?l(o[r],n):o[r]=n;return o}n($,{meta(t){if(m())return;let o=s.proto;o&&(o.global.meta=l(o.global.meta??{},t))}}),c()&&n($.meta,{resolve:function(t){let o=[],{description:e,og:r,twitter:n}=t;return e&&o.push({name:"description",content:e}),r&&f(r,o,"og","property"),n&&f(n,o,"twitter","name"),o}});
package/build/prefetch.js CHANGED
@@ -1 +1 @@
1
- import{GlobalState as e,Proto as t,onclient as r,onserver as a}from"@amateras/core";import{_Object_assign as c,toURL as o,_null as h,isAsyncFunction as f}from"@amateras/utils";c(e.prototype,{prefetch:{fetches:/* @__PURE__ */new Set,caches:{}}}),e.disposers.add(e=>{e.prefetch.fetches.clear()}),globalThis.prefetch||(globalThis.prefetch={}),c($,{async fetch(e,c){e=o(e);let s=t.proto,p=r()?prefetch[e.href]:h,i=c?.then,l=new Promise(async r=>{if(p&&Date.now()<p.expired)return i?.(p.data),void r(p);let o=await fetch(e,c),h=c?.record;if(h){const c=f(h)?await h(o):h(o);a()&&s&&(s.global.prefetch.caches[e.href]={data:c,expired:Date.now()+3e4}),$.context(t,s,()=>{i?.(c)}),r(c)}});return a()&&s?.global.prefetch.fetches.add(l),l}});
1
+ import{GlobalState as e,Proto as t,onclient as r,onserver as a}from"@amateras/core";import{_Object_assign as c,toURL as o,_null as s,isAsyncFunction as l}from"@amateras/utils";e.assign({prefetch:{caches:{}}}),globalThis.prefetch||(globalThis.prefetch={}),c($,{async fetch(e,c){e=o(e);let h=t.proto,i=r()?prefetch[e.href]:s,f=c?.then,n=new Promise(async r=>{if(i&&Date.now()<i.expired){let e=f?.(i.data);return void r({record:i.data,result:e})}let o=await fetch(e,c),s=c?.record;if(s){let c,i=l(s)?await s(o):s(o);a()&&h&&(h.global.prefetch.caches[e.href]={data:i,expired:Date.now()+3e4}),$.context(t,h,()=>{c=f?.(i)}),r({record:i,result:c})}});return a()&&h?.global.asyncTask(n),n}});
package/build/router.js CHANGED
@@ -1 +1 @@
1
- import{ElementProto as t,ProxyProto as e,onserver as s,Proto as r,symbol_ProtoType as i,onclient as o,GlobalState as l}from"@amateras/core";import{toURL as a,_null as n,_undefined as h,isUndefined as c,isFunction as u,map as p,isArray as d,forEach as f,_JSON_parse as v,_Object_entries as g,_JSON_stringify as w,_Object_assign as b,_instanceof as y}from"@amateras/utils";class m extends t{constructor(t,e){super("a",t,e),this.on("click",t=>{if(t.shiftKey||t.ctrlKey)return;t.preventDefault();let e=this.attr("target"),s=this.attr("href");s&&("_replace"===e?$.replace(s):$.open(s,e))})}}class k extends e{page=n;constructor(){super()}render(t){if(this.page!==t){if(this.clear(),this.layout=()=>$(t),t.parent=this,this.page!==t&&this.page?.removeNode(),this.page=t,this.node){t.builded||t.build();let e=this.toDOM();this.node.replaceWith(...e),t.title&&(document.title=t.title,t.global.title=t.title)}s()&&(t.builded||t.build(),t.global.title=t.title)}}}class x extends r{slot=new k;builded=!1;route;title=n;constructor(t,e,s){super(()=>e({params:s,slot:this.slot})),this.route=t}build(){return this.builded||(this.builded=!0),super.build()}}class P{routes=/* @__PURE__ */new Map;path;paths=/* @__PURE__ */new Map;validPaths=[];constructor(t){this.path=t,this.paths.set(t,h)}routing(t){let e=t.split("/"),s={},r="";t:for(let[o,l]of this.paths){s={};let t=o.split("/"),i=[];for(let s=0;s<Math.max(e.length,t.length);s++)i.push([t[s],e[s]]);e:for(let[e,o]of i){let t=()=>{r=""},i=()=>{r+=("/"!==r?"/":"")+o};if(c(e))break e;if(c(o)){t();continue t}if(e?.includes(":")){let[r,l]=e.split(":");if(!o.startsWith(r)){t();continue t}s[l]=o.replace(r,""),i();continue e}if(e!==o){t();continue t}i()}if(r){s={...s,...u(l)?l():l};break t}}if(!r)return;let i=P.resolvePath(this.path,s);return this.validPaths=p(this.paths,t=>P.resolvePath(t[0],s)),[i,r,s]}static resolvePath(t,e){return t.replaceAll(/:([^/]+)/g,(t,s)=>`${e[s]}`)}alias(t,e){this.paths.set(t,e)}}class S extends P{constructor(t){super(t)}async resolve(t,e,s){let r=this.routing(t);if(!r)return;let[,i,o]=r;s={...s,...o};let l=t.replace(i,"");for(let[a,n]of this.routes){let t=await n.resolve(l||"/",e,s);if(t)return[this,...t]}return[this]}}class R extends P{pages=/* @__PURE__ */new Map;page=n;#t;constructor(t,e){super(t),this.#t=e}async resolve(t,e,s){let r=this.routing(t);if(!r)return;let[i,o,l]=r;s={...s,...l};let a=await this.usePage(i,s,e),n=t.replace(o,"");for(let[h,c]of this.routes){let t=await c.resolve(n||"/",a.slot,s);if(t)return[this,...t]}return n?void 0:[this]}async usePage(t,e,s){let r=this.pages.get(t);if(!r){let s,o=this.#t;if(d(o)){let t=await o[0]().then(t=>t.default);s=()=>$(t,e,()=>$(r.slot))}else s="Widget"===this.#t[i]?()=>$(this.#t,e,()=>$(r.slot)):this.#t;r=new x(this,s,e),this.pages.set(t,r)}return this.page=r,s.render(r),r}}let E=0;const[_,L]=[1,2],[M,D]=["forward","back"],T="__scroll_history__",A=o()?sessionStorage:n,H=o()?window.addEventListener:n,W=o()?window.removeEventListener:n;o()&&(history.scrollRestoration="manual");const I=t=>{const e=K.scrollHistory;if(t){let s=t.target;if(""===s.id)return;e[E]={[s.id]:{x:s.scrollLeft,y:s.scrollTop}}}else f(g(e),([t])=>+t>=E&&delete e[+t]);A?.setItem(T,w(e))};class K extends r{direction=M;prev=n;routes=/* @__PURE__ */new Map;slot=new k;static routers=/* @__PURE__ */new Set;constructor(){super(()=>$(this.slot)),o()&&K.routers.add(this)}set href(t){this.global.router.href=t}build(){if(o()){const t=()=>{const t=history.state?.index??0;E>t&&(this.direction=D),E<t&&(this.direction=M),E=t,this.prev=this.href,this.href=a(location.href),this.resolve(location.href)};t(),H?.("popstate",t),H?.("scroll",I,{capture:!0,passive:!1}),this.disposers.add(()=>{W?.("popstate",t),W?.("scroll",I,{capture:!0})})}return super.build()}async resolve(t){if(!t)return;let e=a(t);for(let[,s]of this.routes){let t=await s.resolve(e.pathname,this.slot,{});if(t){this.global.router.routes=t;let e=[""],s=[];f(t,t=>(e=p(t.validPaths,t=>p(e,e=>e+t)).flat(),s.push(...e),e)),this.global.router.matchPaths=s;break}}f(this.global.router.navlinks,t=>t.checkActive()),K.dispatchEvent(),K.scrollRestoration()}static open(t,e){K.writeState(t,_,e)}static forward(){history.forward()}static back(){history.back()}static replace(t){K.writeState(t,L)}static get scrollData(){return this.scrollHistory[E]??{}}static get scrollHistory(){return v(A?.getItem(T)??"{}")}static scrollRestoration(){if(o()){let t=K.scrollData??{x:0,y:0};f(g(t),([t,{x:e,y:s}])=>document.querySelector(`#${t}`)?.scrollTo(e,s))}}static writeState(t,e,s){if(!t)return;let r=a(t);if(!o()||r.href!==location.href){if(s&&"_self"!==s)return open(r,s);e===_&&E++,o()&&I(),f(this.routers,s=>{s.direction=M,o()&&(s.prev=a(location.href),history[e===_?"pushState":"replaceState"]({index:E},"",r)),s.href=r,s.resolve(t)}),K.dispatchEvent()}}static dispatchEvent(){o()&&window.dispatchEvent(new Event("pathchange"))}}const N=t=>class extends K{static[i]="Router";constructor(){super(),t(this)}};let q={route(t,e,s){let r=new R(t,e);this.routes.set(t,r),s?.(r)},group(t,e){let s=new S(t);this.routes.set(t,s),e?.(s)},notfound(){}};b(P.prototype,q),b(K.prototype,q),b(l.prototype,{router:{routers:/* @__PURE__ */new Set,resolve(t){return p(this.routers,e=>e.resolve(t))},href:new URL("http://localhost"),routes:[],matchPaths:[],navlinks:/* @__PURE__ */new Set}}),l.disposers.add(({router:t})=>{t.routers.clear(),t.routes=[],t.matchPaths=[],t.navlinks.clear()}),b($,{router:t=>N(t),open:K.open,replace:K.replace,back:K.back,forward:K.forward,scrollRestoration:K.scrollRestoration,title(t){let e=r.proto;y(e,x)&&(e.title=t)}}),globalThis.Link=m,globalThis.NavLink=class extends m{constructor(t,e){super(t,e),this.global.router.navlinks.add(this)}checkActive(){let t=this.attr("href");if(t){for(let e of this.global.router.matchPaths)if(a(e).href===a(t).href)return this.attr("active","");this.attr("active",n)}}},$.process.craft.add(t=>{if(u(t)&&"Router"===t[i]){let e=r.proto,s=new t;return e?.global.router.routers.add(s),s.parent=e,s}});export{m as Link,x as Page,P as Route,S as RouteGroup,R as RouteNode,k as RouteSlot,K as RouterProto};
1
+ import{ElementProto as t,ProxyProto as e,onclient as s,Proto as r,symbol_ProtoType as o,GlobalState as i}from"@amateras/core";import{_undefined as l,toURL as a,_null as n,is as h,_instanceof as c,isUndefined as u,isFunction as p,map as d,isArray as f,forEach as w,_JSON_parse as v,_Object_entries as g,_JSON_stringify as y,_Object_assign as m}from"@amateras/utils";class b extends t{constructor(t,e){super("a",t,e),this.on("click",t=>{if(t.shiftKey||t.ctrlKey)return;t.preventDefault();let e=this.attr("target"),s=this.attr("href");s&&("_replace"===e?$.replace(s):$.open(s,e??l))})}}class k extends e{page=n;constructor(){super()}switch(t){if(this.page!==t&&(this.clear(),this.layout=()=>$(t),this.append(t),this.page!==t&&this.page?.removeNode(),this.page=t,t.builded||t.build(),t.updateTitle(),s())){let t=this.toDOM();this.node?.replaceWith(...t)}}}class x extends r{slot=new k;route;title=n;constructor(t,e,s){super(()=>e({params:s,slot:this.slot})),this.route=t}updateTitle(){let t=this.title??this.findAbove(t=>h(t,x)?.title)?.title??n,e=t=>{s()&&(document.title=t),this.global.title=t};t&&(c(t,Promise)?t.then(t=>{this.title=t,e(t)}):e(t))}}class P{routes=/* @__PURE__ */new Map;path;paths=/* @__PURE__ */new Map;validPaths=[];constructor(t){this.path=t,this.paths.set(t,l)}routing(t){let e=t.split("/"),s={},r="";t:for(let[i,l]of this.paths){s={};let t=i.split("/"),o=[];for(let s=0;s<Math.max(e.length,t.length);s++)o.push([t[s],e[s]]);e:for(let[e,i]of o){let t=()=>{r=""},o=()=>{r+=("/"!==r?"/":"")+i};if(u(e))break e;if(u(i)){t();continue t}if(e?.includes(":")){let[r,l]=e.split(":");if(!i.startsWith(r)){t();continue t}s[l]=i.replace(r,""),o();continue e}if(e!==i){t();continue t}o()}if(r){s={...s,...p(l)?l():l};break t}}if(!r)return;let o=P.resolvePath(this.path,s);return this.validPaths=d(this.paths,t=>P.resolvePath(t[0],s)),[o,r,s]}static resolvePath(t,e){return t.replaceAll(/:([^/]+)/g,(t,s)=>`${e[s]}`)}alias(t,e){this.paths.set(t,e)}}class S extends P{constructor(t){super(t)}async resolve(t,e,s){let r=this.routing(t);if(!r)return;let[,o,i]=r;s={...s,...i};let l=t.replace(o,"");for(let[a,n]of this.routes){let t=await n.resolve(l||"/",e,s);if(t)return[this,...t]}return[this]}}class T extends P{pages=/* @__PURE__ */new Map;page=n;#t;constructor(t,e){super(t),this.#t=e}async resolve(t,e,s){let r=this.routing(t);if(!r)return;let[o,i,l]=r;s={...s,...l};let a=await this.usePage(o,s,e),n=t.replace(i,"");for(let[h,c]of this.routes){let t=await c.resolve(n||"/",a.slot,s);if(t)return[this,...t]}return n?void 0:[this]}async usePage(t,e,s){let i=this.pages.get(t);if(!i){let l,a=this.#t;if(f(a)){let t=await a[0]().then(t=>t.default);l=()=>$(t,e,()=>$(i.slot))}else l="Widget"===this.#t[o]?()=>$(this.#t,e,()=>$(i.slot)):this.#t;$.context(r,s,()=>{i=new x(this,l,e)}),this.pages.set(t,i)}return this.page=i,s.switch(i),i}}let R=0;const[_,E]=[1,2],[L,M]=["forward","back"],A="__scroll_history__",D=s()?sessionStorage:n,N=s()?window.addEventListener:n,H=s()?window.removeEventListener:n;s()&&(history.scrollRestoration="manual");const W=t=>{const e=I.scrollHistory;if(t){let s=t.target;"#document"===s.nodeName?e[R]={[s.nodeName]:{x:window.scrollX,y:window.scrollY}}:""!==s.id&&(e[R]={[s.id]:{x:s.scrollLeft,y:s.scrollTop}})}else w(g(e),([t])=>+t>=R&&delete e[+t]);D?.setItem(A,y(e))};class I extends r{direction=L;prev=n;routes=/* @__PURE__ */new Map;slot=new k;static routers=/* @__PURE__ */new Set;constructor(){super(()=>$(this.slot)),s()&&I.routers.add(this)}set href(t){this.global.router.href=t}build(){if(s()){const t=()=>{const t=history.state?.index??0;R>t&&(this.direction=M),R<t&&(this.direction=L),R=t,this.prev=this.href,this.href=a(location.href),this.resolve(location.href)};t(),N?.("popstate",t),N?.("scroll",W,{capture:!0,passive:!1}),this.ondispose(()=>{H?.("popstate",t),H?.("scroll",W,{capture:!0})})}return super.build()}async resolve(t){if(!t)return;let e=a(t);for(let[,s]of this.routes){let t=await s.resolve(e.pathname,this.slot,{});if(t){this.global.router.routes=t;let e=[""],s=[];w(t,t=>(e=d(t.validPaths,t=>d(e,e=>e+t)).flat(),s.push(...e),e)),this.global.router.matchPaths=s;break}}w(this.global.router.navlinks,t=>t.checkActive()),I.dispatchEvent(),I.scrollRestoration()}static open(t,e="_self"){a(t).origin!==origin?open(t,e):I.writeState(t,_,e)}static forward(){history.forward()}static back(){history.back()}static replace(t){I.writeState(t,E)}static get scrollData(){return this.scrollHistory[R]??{}}static get scrollHistory(){return v(D?.getItem(A)??"{}")}static scrollRestoration(){if(s()){let t=I.scrollData??{x:0,y:0},e=g(t);e.length?w(e,([t,{x:e,y:s}])=>{"#document"===t?window.scrollTo(e,s):document.querySelector(`#${t}`)?.scrollTo(e,s)}):window.scrollTo(0,0)}}static writeState(t,e,r){if(!t)return;let o=a(t);if(!s()||o.href!==location.href){if(r&&"_self"!==r)return open(o,r);e===_&&R++,s()&&W(),w(this.routers,r=>{r.direction=L,s()&&(r.prev=a(location.href),history[e===_?"pushState":"replaceState"]({index:R},"",o)),r.href=o,r.resolve(t)}),I.dispatchEvent()}}static dispatchEvent(){s()&&window.dispatchEvent(new Event("pathchange"))}}const K=t=>class extends I{static[o]="Router";constructor(){super(),t(this)}};let q={route(t,e,s){let r=new T(t,e);return this.routes.set(t,r),s?.(r),this},group(t,e){let s=new S(t);return this.routes.set(t,s),e?.(s),this},notfound(){}};m(P.prototype,q),m(I.prototype,q),m(i.prototype,{router:{routers:/* @__PURE__ */new Set,resolve(t){return d(this.routers,e=>e.resolve(t))},href:new URL("http://localhost"),routes:[],matchPaths:[],navlinks:/* @__PURE__ */new Set}}),i.disposers.add(({router:t})=>{t.routers.clear(),t.routes=[],t.matchPaths=[],t.navlinks.clear()}),m($,{router:t=>K(t),open:I.open,replace:I.replace,back:I.back,forward:I.forward,scrollRestoration:I.scrollRestoration,title(t){let e=r.proto?.findAbove(t=>h(t,x));e&&(e.title=t,e.updateTitle())}}),globalThis.Link=b,globalThis.NavLink=class extends b{constructor(t,e){super(t,e),this.global.router.navlinks.add(this)}checkActive(){let t=this.attr("href");if(t){for(let e of this.global.router.matchPaths)if(a(e).href===a(t).href)return this.attr("active","");this.attr("active",n)}}},$.process.craft.add(t=>{if(p(t)&&"Router"===t[o]){let e=r.proto,s=new t;return e?.global.router.routers.add(s),e?.append(s),s}});export{b as Link,x as Page,P as Route,S as RouteGroup,T as RouteNode,k as RouteSlot,I as RouterProto};
package/build/signal.js CHANGED
@@ -1 +1 @@
1
- import{isFunction as e,forEach as t,_Object_assign as s,_instanceof as r,isEqual as u,isBoolean as i}from"@amateras/utils";import{TextProto as a,Proto as n}from"@amateras/core";let l=!1,o=/* @__PURE__ */new Set,c=e=>{l=!1;let t=e();return l=!0,t},b=e=>{l=!0;let t=e(c);return l=!1,t},d=/* @__PURE__ */new WeakMap,h=e=>d.get(e);class p{key;constructor(e){const t=()=>(l&&o.add(this),h(t).value);return Object.setPrototypeOf(t,this),d.set(t,{value:e,subs:/* @__PURE__ */new Set}),this.key=t,t}get value(){return h(this.key).value}get subs(){return h(this.key).subs}set(t){e(t)?this.set(t(this.value)):this.value!==t&&(h(this).value=t,this.emit())}modify(e){e(this.value),this.emit()}emit(){t(h(this).subs,e=>e(this.value))}subscribe(e){this.subs.add(e)}unsubscribe(e){this.subs.delete(e)}toString(){return`${this.value}`}}s($,{signal:e=>new p(e),effect(e){b(e),t(o,t=>t.subscribe(t=>e(c))),o.clear()},compute(e){let s=b(e),r=new p(s);return t(o,t=>t.subscribe(t=>r.set(e(c)))),o.clear(),r}});let m=e=>{if(r(e,p)){let t=new a(`${e}`);t.ondom(s=>{let r=e=>s.textContent=`${e}`;e.subscribe(r),t.disposers.add(()=>e.unsubscribe(r))});let s=e=>t.content=`${e}`;return e.subscribe(s),s(e.value),t.parent=n.proto,t}};$.process.text.add(m),$.process.craft.add(m),$.process.attr.add((e,t,s)=>{if(r(t,p)){if("input"===s.tagname){if(u(e,["value","checked"])){s.on("input",s=>t.set(s.currentTarget[e]));let r=t.value;i(r)?r&&s.attr(e,""):s.attr(e,`${r}`)}}else s.ondom(r=>{let u=()=>((e,t,s)=>{e in t?t[e]=s.value:t.setAttribute(e,`${s}`)})(e,r,t);t.subscribe(u),u(),s.disposers.add(()=>t.unsubscribe(u))});return!0}});export{p 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,isObject as n,isNull as l,_Object_assign as h,_instanceof as c,isIncluded as o,isBoolean as p}from"@amateras/utils";import{symbol_Signal as d,Proto as m,GlobalState as v,TextProto as b}from"@amateras/core";let g=!1,f=/* @__PURE__ */new Set,x=e=>{g=!1;let s=e();return g=!0,s},w=e=>{g=!0;let s=e(x);return g=!1,s},k=new FinalizationRegistry(({signal:e,ref:s})=>{e.computes?.delete(s)});class _ extends Function{[d]=!0;linked=e;_value;subs=e;converts;map=e;exec=e;computes=e;constructor(i,r=e){return super(),m.proto?.global.signals.add(this),this._value=i,this.converts=r,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 _(r);return this.map[i]=u,u}})}_exec(){return g&&f.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){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){this.linked=e,this.converts=e.converts,this.emit(),e.subscribe(()=>this.emit())}is(e){return e(this)}assignProperties(e){n(this.value)&&!l(this.value)&&this.converts&&i(r(this.converts),([s,t])=>{let i=e?.[`${s}$`]??t(this.value[s]);h(this,{[`${s}$`]:i})})}toString(){return`${this.value}`}}v.assign({signals:/* @__PURE__ */new Set}),v.disposers.add(e=>{i(e.signals,e=>e.dispose()),e.signals.clear()}),h($,{signal:(e,s)=>new _(e,s),effect(e){w(e),i(f,s=>s.subscribe(s=>e(x))),f.clear()},compute(e){let s=w(e),t=$.signal(s);return t.exec=()=>t.set(e(x)),i(f,e=>{e.computes=e.computes??/* @__PURE__ */new Set;let s=new WeakRef(t);e.computes.add(s),k.register(t,{signal:e,ref:s})}),f.clear(),t},optional:s=>s.value?s:e,resolve:(e,s)=>c(e,_)?(s&&(e.subscribe(s),s(e)),e.value):(s?.(e),e)});let y=e=>{if(c(e,_)){let s=new b(`${e}`),t=e=>s.content=`${e}`;return e.subscribe(t),s.ondispose(()=>e.unsubscribe(t)),t(e.value),s}};$.process.text.add(y),$.process.craft.add(y),$.process.attr.add((e,s,t)=>{if(c(s,_)){if("input"===t.tagname){if(o(e,["value","checked"])){t.on("input",t=>s.set(t.currentTarget[e]));let i=s.value;p(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{_ as Signal};
package/build/store.js ADDED
@@ -0,0 +1 @@
1
+ import{Proto as t}from"@amateras/core";import{isUndefined as o,_Object_assign as e}from"@amateras/utils";class r{init;map=/* @__PURE__ */new WeakMap;constructor(t){this.init=t}create(...o){const e=t.proto;if(!e)throw`Store.create(): ${i}`;const r=this.init(...o);return this.map.set(e,r),e.ondispose(()=>this.map.delete(e)),r}get(){const e=t.proto;if(!e)throw`Store.get(): ${i}`;const r=this.getValueFromProto(e);if(o(r))throw"Store.get(): value not found";return r}getValueFromProto(t){if(!t)return;return this.map.get(t)??this.getValueFromProto(t.parent)}}const i="should be called inside proto layout function";e($,{store:t=>new r(t)});export{r as Store};
package/build/ui.js CHANGED
@@ -1 +1 @@
1
- var t,e=Object.defineProperty,i=t=>{throw TypeError(t)},s=(t,i,s)=>((t,i,s)=>i in t?e(t,i,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[i]=s)(t,"symbol"!=typeof i?i+"":i,s),a=(t,e,s)=>e.has(t)||i("Cannot "+s),n=(t,e,i)=>(a(t,e,"read from private field"),i?i.call(t):e.get(t)),r=(t,e,i,s)=>(a(t,e,"write to private field"),s?s.call(t,i):e.set(t,i),i);import{onclient as l,ElementProto as o}from"@amateras/core";import{_null as h,is as d,UID as u}from"@amateras/utils";const p=t=>(e,i,s)=>{if(e.slide=i,!l())return;let a=i.toDOM();e.node?.append(...a);let n={duration:t?.duration??500,easing:t?.easing??"ease"},r=$.match(t?.direction,t=>t.case("up",()=>[["0 100%","0 0"],["0 0","0 -100%"]]).case("down",()=>[["0 -100%","0 0"],["0 0","0 100%"]]).case("left",()=>[["100% 0","0 0"],["0 0","-100% 0"]]).case("right",()=>[["-100% 0","0 0"],["0 0","100% 0"]]).default(()=>[["100% 0","0 0"],["0 0","-100% 0"]]));i.node?.animate({translate:r[0]},n);const o=s?.node?.animate({translate:r[1]},n);o&&(o.onfinish=()=>s?.node?.remove())},c=class extends o{constructor(t,e){super("slide",t,e)}};$.style(c,"slide{display:block;height:100%;width:100%;position:absolute}");let m=c;const v=class extends o{constructor({index:e,interval:a,autoplay:n,animation:r,...l},o){var d,u,p;super("slideshow",l,o),s(this,"slide",h),s(this,"index"),s(this,"timer",h),s(this,"interval"),s(this,"autoplay"),s(this,"animation"),d=this,p=0,(u=t).has(d)?i("Cannot add the same private member more than once"):u instanceof WeakSet?u.add(d):u.set(d,p),this.index=e??0,this.interval=a??5,this.autoplay=n??!1,this.animation=r??h,this.disposers.add(()=>this.pause()),this.ondom(()=>{this.autoplay&&this.play()})}build(){return super.build(),this.switch(this.index),this}toString(){return this.parseHTML({children:this.slide?.toString()})}toDOM(t=!0){return super.toDOM(!1),t&&this.slide&&this.node?.append(...this.slide.toDOM()),[this.node]}play(){this.timer=setInterval(()=>{var e,i,s,a;(e=this,i=t,{set _(t){r(e,i,t,s)},get _(){return n(e,i,a)}})._++,n(this,t)>=100*this.interval&&(this.next(),r(this,t,0))},10)}pause(){this.timer&&clearTimeout(this.timer)}next(){let t=this.children.length,e=this.index+1;e>=t&&(e=0),this.switch(e)}prev(){let t=this.children.length,e=this.index-1;e<=0&&(e=t-1),this.switch(e)}switch(t){this.index=t;let e=this.children.at(t);this.slide!==e&&e&&(this.animation?this.animation(this,e,this.slide):(e.parent=this,this.slide=e,this.node?.replaceChildren(...e.toDOM())))}};t=new WeakMap,$.style(v,"slideshow{display:block;position:relative;overflow:clip}");let b=v;const y=class extends o{value;constructor({value:t,...e},i){super("radio-group",e,i),this.value=t,this.on("input",t=>{this.value=d(t.target,HTMLInputElement)?.value})}};$.style(y,"radio-group{display:block}");let f=y;const x=class extends o{inputId;name;value;constructor({inputId:t,name:e,value:i,...s},a){super("radio-item",s,a),this.inputId=t??`input-${u.persistInProto(this,"radio-item")}`,this.name=e??h,this.value=i}};$.style(x,"radio-item{display:block}");let g=x;class w extends o{constructor(t,e){super("input",{type:"radio",...t},e)}build(t){let e=this.findAbove(t=>d(t,g));return e&&(this.attr("id",e.inputId),this.attr("name",e.name)),super.build(t)}}class I extends o{constructor(t,e){super("label",t,e)}build(t){let e=this.findAbove(t=>d(t,g));return e&&this.attr("for",e.inputId),super.build(t)}}export{I as Label,w as Radio,f as RadioGroup,g as RadioItem,m as Slide,b as Slideshow,p as slideInOut};
1
+ var t,e,s,i,r=Object.defineProperty,n=t=>{throw TypeError(t)},a=(t,e,s)=>((t,e,s)=>e in t?r(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s)(t,"symbol"!=typeof e?e+"":e,s),o=(t,e,s)=>e.has(t)||n("Cannot "+s),l=(t,e,s)=>(o(t,e,"read from private field"),s?s.call(t):e.get(t)),c=(t,e,s)=>e.has(t)?n("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,s),h=(t,e,s,i)=>(o(t,e,"write to private field"),i?i.call(t,s):e.set(t,s),s);import{onclient as d,ElementProto as u,TextProto as p,Proto as g}from"@amateras/core";import{_null as v,is as b,UID as m,forEach as f,isEqual as k,_Object_assign as x,_Object_entries as y,isObject as w,isUndefined as M,isNull as D,_instanceof as z,isString as I}from"@amateras/utils";const O=t=>(e,s,i)=>{if(e.slide=s,!d())return;let r=s.toDOM();e.node?.append(...r);let n={duration:t?.duration??500,easing:t?.easing??"ease"},a=$.match(t?.direction,t=>t.case("up",()=>[["0 100%","0 0"],["0 0","0 -100%"]]).case("down",()=>[["0 -100%","0 0"],["0 0","0 100%"]]).case("left",()=>[["100% 0","0 0"],["0 0","-100% 0"]]).case("right",()=>[["-100% 0","0 0"],["0 0","100% 0"]]).default(()=>[["100% 0","0 0"],["0 0","-100% 0"]]));s.node?.animate({translate:a[0]},n);const o=i?.node?.animate({translate:a[1]},n);o&&(o.onfinish=()=>i?.node?.remove())},S=class extends u{constructor(t,e){super("slide",t,e)}};$.style(S,"slide{display:block;height:100%;width:100%;position:absolute}");let A=S;const C=class extends u{constructor({index:s,interval:i,autoplay:r,autopause:n,animation:o,...l},h){super("slideshow",l,h),a(this,"slide",v),a(this,"index"),a(this,"timer",v),a(this,"interval"),a(this,"autoplay"),a(this,"autopause"),a(this,"animation"),c(this,t,0),c(this,e,v),a(this,"playing",!1),this.index=s??0,this.interval=i??5,this.autoplay=r??!1,this.autopause=n??!0,this.animation=o??v,this.ondispose(()=>this.pause()),this.ondom(()=>{this.autoplay&&this.play()})}build(){return super.build(),this.switch(this.index),this}toString(){return this.parseHTML({children:this.slide?.toString()})}toDOM(t=!0){return super.toDOM(!1),this.node&&!l(this,e)&&(h(this,e,new ResizeObserver(()=>{this.autopause&&(this.inDOM()?this.play():this.pause())})),l(this,e).observe(this.node)),t&&this.slide&&this.node?.append(...this.slide.toDOM()),[this.node]}play(){this.playing||(this.playing=!0,this.timer=setInterval(()=>{var e,s,i,r;(e=this,s=t,{set _(t){h(e,s,t,i)},get _(){return l(e,s,r)}})._++,l(this,t)>=100*this.interval&&(this.next(),h(this,t,0))},10))}pause(){this.playing=!1,this.timer&&clearTimeout(this.timer)}next(){let t=this.children.length,e=this.index+1;e>=t&&(e=0),this.switch(e)}prev(){let t=this.children.length,e=this.index-1;e<=0&&(e=t-1),this.switch(e)}switch(t){this.index=t;let e=this.children.at(t);this.slide!==e&&e&&(this.animation?this.animation(this,e,this.slide):(this.append(e),this.slide=e,this.node?.replaceChildren(...e.toDOM())),e.node?.dispatchEvent(new Event("showslide")))}};t=new WeakMap,e=new WeakMap,$.style(C,"slideshow{display:block;position:relative;overflow:clip}");let E=C;const L=class extends u{value;constructor({value:t,...e},s){super("radio-group",e,s),this.value=t,this.on("input",t=>{this.value=b(t.target,HTMLInputElement)?.value})}};$.style(L,"radio-group{display:block}");let W=L;const H=class extends u{inputId;name;value;constructor({inputId:t,name:e,value:s,...i},r){super("radio-item",i,r),this.inputId=t??`input-${m.persistInProto(this,"radio-item")}`,this.name=e??v,this.value=s}};$.style(H,"radio-item{display:block}");let R=H;class T extends u{constructor(t,e){super("input",{type:"radio",...t},e)}build(t){let e=this.findAbove(t=>b(t,R));return e&&(this.attr("id",e.inputId),this.attr("name",e.name)),super.build(t)}}class B extends u{constructor(t,e){super("label",t,e)}build(t){let e=this.findAbove(t=>b(t,R));return e&&this.attr("for",e.inputId),super.build(t)}}const _=class extends u{constructor(t,e){super("text-block",t,e)}};$.style(_,"text-block{display:block}");let j=_;const[F,P,U,q,N]=["accordion","accordion-item","accordion-trigger","accordion-content","accordion-container"],X=class extends u{$trigger=v;$container=v;constructor(t,e){super(F,t,e)}open(){this.attr("opened","")}close(){this.attr("opened",null)}switch(){""===this.attr("opened")?this.close():this.open()}};$.style(X,[`${F},${P},${U}{display:block}`,`${N}{display:grid;grid-template-rows:0fr}`,`${F}[opened] ${N}{grid-template-rows:1fr}`,`${q}{overflow:hidden}`]);let Y=X;class Z extends u{constructor(t,e){super(N,t,e)}build(t){let e=this.findAbove(t=>b(t,Y));return e&&(e.$container=this),super.build(t)}}class G extends u{constructor(t,e){super(q,t,e)}}class J extends u{constructor(t,e){super(U,t,e)}build(t){let e=this.findAbove(t=>b(t,Y));return e&&(e.$trigger=this,this.on("click",()=>e.switch())),super.build(t)}}const K=class extends u{gap;columns;size;observer=null;constructor({gap:t,columns:e,autosize:s,size:i,...r},n){super("waterfall",r,n),this.gap=t??0,this.columns=e??1,this.size=i??0,d()&&(this.observer=new ResizeObserver(()=>{this.inDOM()&&requestAnimationFrame(()=>this.refresh())}))}toDOM(t){return super.toDOM(t),this.node&&this.observer?.observe(this.node),[this.node]}refresh(){if(!this.node)return;const t=[],e=this.node.offsetWidth;let s=this.columns;this.size&&(s=Math.trunc(e/(this.size+this.gap))||1);const i=(e-this.gap*(s-1))/s;for(let r=0;r<s;r++)t.push({items:[],height:0,width:i,left:r*(i+this.gap)});f(this.children,e=>{if(!e.node)return;e.ratio||e.node.offsetHeight&&e.node.offsetWidth&&(e.ratio=e.node.offsetWidth/e.node.offsetHeight);const s=i/e.ratio,r=t.sort((t,e)=>t.height-e.height)[0];e.style({height:`${s}px`,width:`${i}px`,top:`${r.height}px`,left:`${r.left}px`}),r.height+=s+this.gap})}mutate(){this.refresh()}};$.style(K,"waterfall{display:block;position:relative;min-height:100dvh}");let Q=K;const V=class extends u{ratio=0;constructor(t,e){super("waterfall-item",t,e)}toDOM(t){super.toDOM(t);const e=this.findAbove(t=>b(t,Q));return this.node?.querySelectorAll("img").forEach(t=>e?.observer?.observe(t)),[this.node]}};$.style(V,"waterfall-item{display:block;position:absolute}");let tt=V;const et=class extends u{targetId;$container=v;triggers=/* @__PURE__ */new Map;constructor({targetId:t,...e},s){super("tabs",e,s),this.targetId=t}switch(t){this.targetId!==t&&(this.targetId=t,this.$container?.renderContent())}};$.style(et,"tabs{display:block;}");let st=et;class it extends u{tabId;tabs=v;constructor({tabId:t,...e},s){super("tab-trigger",e,s),this.tabId=t,this.on("click",()=>this.tabs?.switch(this.tabId))}build(t){return super.build(t),this.tabs=this.findAbove(t=>b(t,st)),this.tabs?.triggers.set(this.tabId,this),this}}$.style(st,"tab-trigger{cursor:pointer;}");class rt extends u{tabs=null;constructor({...t},e){super("tab-container",t,e)}build(t){return super.build(t),this.tabs=this.findAbove(t=>b(t,st)),this.tabs&&(this.tabs.$container=this),this}toDOM(t=!0){return super.toDOM(!1),this.renderContent(t),[this.node]}toString(){return this.parseHTML({children:this.renderContent()?.toString()})}mutate(){this.renderContent()}getContent(t){return this.children.find(e=>e.tabId===t)}renderContent(t=!0){const e=this.tabs?.targetId,s=e?this.getContent(e):this.children.at(0);return t&&s&&(this.node?.replaceChildren(...s.toDOM()),this.tabs?.triggers.forEach(t=>{t.attr("active",t.tabId===s.tabId?"":v)})),s}}$.style(st,"tab-container{display:block;}");class nt extends u{tabId;tabs=null;constructor({tabId:t,...e},s){super("tab-content",e,s),this.tabId=t}build(t){return super.build(t),this.tabs=this.findAbove(t=>b(t,st)),this}}$.style(st,"tab-content{display:block;}");const at=(t,{style:e},s)=>{let i=t.getBoundingClientRect(),r={top:i.top+window.scrollY,left:i.left+window.scrollX,width:i.width,height:i.height},{top:n,left:a,width:o,height:l}=r;k(s,r,["top","left","height","width"])||(x(s,{top:n,left:a,width:o,height:l}),e.top=`${l+n}px`,e.left=`${a}px`,e.width=`${o}px`)},ot=(t,e)=>{let s=[];for(let[i,r]of y(e))w(r)?s.push(ot(i,r)):s.push(`${i.replaceAll(/[A-Z]/g,t=>`-${t.toLowerCase()}`)}: ${r};`);return`${t} { ${s.join(" ")} }`},lt=class t extends u{constructor(e,i){super(t.tagname,e,i),a(this,"$trigger",v),a(this,"$content",v),a(this,"clickListener",v),c(this,s,v),a(this,"selected",v),a(this,"itemMap",/* @__PURE__ */new Map),a(this,"$value",v),a(this,"disconnect",v),this.listen("i18nupdate",()=>this.$value?.render())}props({value:t,disabled:e,...s}){super.props(s),e&&this.disabled(e),this.value(t)}disabled(t){if(!arguments.length)return""===this.attr("disabled");$.resolve(t,t=>{this.attr("disabled",t?"":v)})}value(t){if(!arguments.length)return l(this,s);M(t)||($.resolve(t,t=>{h(this,s,t);let e=this.itemMap.get(t);this.selected=e??v,this.$value?.render()}),this.node?.dispatchEvent(new Event("select-value")))}open(){this.attr("opened",""),d()&&this.$content&&(this.disconnect=((t,e)=>{let s={top:0,left:0,height:0,width:0},i=new ResizeObserver(()=>at(t,e,s)),r=()=>at(t,e,s);return i.observe(t),window.addEventListener("resize",r),()=>{i.disconnect(),window.removeEventListener("resize",r)}})(this.$trigger?.node,this.$content.node),document.body.append(...this.$content.toDOM()),this.clickListener=t=>{t.target!==this.$trigger?.node&&(t.target&&this.$content?.node?.contains(t.target)||this.close())},this.selected?.node?.focus(),window.addEventListener("click",this.clickListener))}close(){this.attr("opened",v),d()&&(this.$content?.removeNode(),this.clickListener&&window.removeEventListener("click",this.clickListener),this.disconnect?.(),this.disconnect=v)}toDOM(t){return super.toDOM(!1),t&&this.$trigger&&(this.node?.append(...this.$trigger.toDOM()),this.$content?.toDOM(),this.$value?.render()),[this.node]}toString(){let t=this.$trigger?.toString()??"";return this.parseHTML({children:t})}};s=new WeakMap,a(lt,"tagname","select-proto"),$.style(lt,ot(lt.tagname,{display:"inline-block",width:"10rem",userSelect:"none"}));let ct=lt;const ht=class t extends u{$select=v;constructor(e,s){super(t.tagname,{tabindex:0,...e},s),this.on("click",t=>D(this.$select?.attr("opened"))?this.$select.open():this.$select?.close()),this.on("keydown",t=>{if(" "===t.key)t.preventDefault()}),this.on("keyup",t=>{switch(t.key){case" ":case"Enter":t.preventDefault(),this.$select?.open()}})}build(t){return super.build(t),this.$select=this.findAbove(t=>z(t,ct)),this.$select&&(this.$select.$trigger=this),this}};a(ht,"tagname","select-trigger"),$.style(ht,ot(ht.tagname,{display:"flex",gap:"0.5rem",placeContent:"space-between",placeItems:"center",boxSizing:"border-box",border:"1px solid var(--input)",background:"color-mix(in oklch, var(--input) 30%, transparent)",padding:"calc(var(--spacing) * 2) calc(var(--spacing) * 2.5)",borderRadius:"var(--radius)",fontSize:"0.875rem",fontWeight:"var(--font-weight-medium)",lineHeight:"1","&:hover":{background:"color-mix(in oklch, var(--input) 50%, transparent)"},"&:focus":{outline:"0.1rem solid var(--border)"},"*":{pointerEvents:"none"}}));let dt=ht;class ut extends u{static tagname="select-value";$select=v;$placeholder=v;$text=new p("");constructor(t,e){super(ut.tagname,t,e)}props({placeholder:t,...e}){super.props(e),this.placeholder(t??v)}build(t){return super.build(t),this.$select=this.findAbove(t=>z(t,ct)),this.$select&&(this.$select.$value=this),this}placeholder(t){$.resolve(t,t=>{I(t)?$.context(g,this,()=>this.$placeholder=new p(t)):this.$placeholder=t,this.render()})}render(){let t=v;this.$select?.selected?(t=this.$text,this.$text.content=this.$select.selected.text):this.$placeholder&&(t=this.$placeholder),t&&(t.builded||t.build(),this.replaceProtos(t),this.node?.replaceChildren(...t.toDOM()))}}const pt=class t extends u{$select=v;constructor(e,s){super(t.tagname,e,s)}build(t){return super.build(t),this.$select=this.findAbove(t=>z(t,ct)),this.$select&&(this.$select.$content=this),this}};a(pt,"tagname","select-content"),$.style(pt,ot(pt.tagname,{position:"absolute",top:"0",left:"0",display:"block",boxSizing:"border-box",border:"1px solid var(--input)",background:"oklch(from var(--bg) l c h)",padding:"calc(var(--spacing) * 2) calc(var(--spacing) * 1.25)",borderRadius:"var(--radius)",userSelect:"none"}));let gt=pt;const vt=class t extends u{constructor(e,s){super(t.tagname,{tabindex:0,...e},s),a(this,"$select",v),a(this,"$content",v),c(this,i,v),this.on("click",()=>{this.$select?.close(),this.select()}),this.on("keydown",e=>{let s=s=>{if(e.preventDefault(),!this.$content)return;let i=this.$content?.findBelowAll(e=>z(e,t)),r=i.indexOf(this),n="up"===s?r-1:r+1;(n<0||n>=i.length)&&(n="up"===s?-1:0);let a=i.at(n);a?.node?.focus()};switch(e.key){case"ArrowDown":s("down");break;case"ArrowUp":s("up");break;case" ":e.preventDefault()}}),this.on("keyup",t=>{switch(t.key){case"Escape":t.preventDefault(),this.$select?.close(),this.$select?.$trigger?.node?.focus();break;case" ":case"Enter":t.preventDefault(),this.select(),this.$select?.close(),this.$select?.$trigger?.node?.focus()}})}value(t){if(!arguments.length)return l(this,i);M(t)||$.resolve(t,t=>{h(this,i,t)})}select(){this.$select&&this.$select.value(this.value())}props({value:t,...e}){super.props(e),this.value(t)}build(t){return super.build(t),this.$select=this.findAbove(t=>z(t,ct)),this.$content=this.findAbove(t=>z(t,gt)),this.$select?.itemMap.set(l(this,i),this),this}};i=new WeakMap,a(vt,"tagname","select-item"),$.style(vt,ot(vt.tagname,{display:"block",boxSizing:"border-box",padding:"calc(var(--spacing) * 2) calc(var(--spacing) * 1.25)",borderRadius:"var(--radius)",fontSize:"0.875rem",fontWeight:"500",lineHeight:"1","&:hover, :not(:has(select-item:hover)) &:focus":{background:"oklch(from var(--input) l c h / .1)"},"&:focus":{outline:"none"}}));let bt=vt;class mt extends u{constructor(t,e){super("selector-group",t,e)}}const ft=class t extends u{constructor(e,s){super(t.tagname,e,s)}props({svg:t,...e}){super.props(e),this.svg(t)}svg(t){$.resolve(t,t=>{this.innerHTML(t)})}};a(ft,"tagname","icon"),$.style(ft,ot(ft.tagname,{display:"inline-block",verticalAlign:"middle",svg:{display:"block",height:"1rem",width:"1rem"}}));let $t=ft;const kt=class extends $t{constructor(t){super({svg:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-chevron-down-icon lucide-chevron-down"><path d="m6 9 6 6 6-6"/></svg>',...t})}};$.style(kt,ot(`select-proto[opened] ${kt.tagname}`,{rotate:"180deg"}));let xt=kt;const yt=class t extends u{constructor(e,s){super(t.tagname,e,s)}};a(yt,"tagname","button"),$.style(yt,ot(yt.tagname,{display:"inline-flex",placeContent:"center",placeItems:"center",padding:"0 calc(var(--spacing) * 2.5)",borderRadius:"var(--radius)",height:"calc(var(--spacing) * 8)",transition:"0.2s all ease",fontWeight:"var(--font-weight-medium)",fontFamily:"inherit",outline:"0.1rem solid oklch(from var(--border) l c h / 0)",border:"1px solid oklch(from var(--input) l c h / .2)",background:"oklch(from var(--input) l c h / .025)",color:"oklch(from var(--fg) l c h / .9)","&:focus-visible":{outline:"0.1rem solid var(--border)"},"&:active":{translate:"0 0.125rem"},"&:not([disabled]):hover":{background:"oklch(from var(--input) l c h / .1)",color:"oklch(from var(--fg) l c h / 1)"},'&[variant="primary"]':{border:"none",color:"oklch(from var(--primary-fg) l c h)",background:"var(--primary-bg)"},'&[variant="secondary"]':{border:"none",color:"oklch(from var(--secondary-fg) l c h)",background:"var(--secondary-bg)","&:not([disabled]):hover":{background:"oklch(from var(--secondary-bg) l c h / .8)"}},'&[variant="destructive"]':{border:"none",color:"oklch(from var(--destructive-fg) l c h)",background:"oklch(from var(--destructive-bg) l c h / .3)","&:not([disabled]):hover":{background:"oklch(from var(--destructive-bg) l c h / .5)"}},'&[variant="ghost"]':{border:"none",color:"oklch(from var(--fg) l c h)",background:"oklch(from var(--input) l c h / 0)","&:not([disabled]):hover":{background:"oklch(from var(--input) l c h / .1)"}},'&[variant="link"]':{border:"none",color:"oklch(from var(--fg) l c h)",background:"oklch(from var(--input) l c h / 0)","&:not([disabled]):hover":{textDecoration:"underline",textUnderlineOffset:"0.2rem"}},'&[size="icon"]':{width:"calc(var(--spacing) * 8)",padding:"0"},'&[size="xs"]':{padding:"calc(var(--spacing) * 2)",fontSize:"var(--text_xs)",height:"calc(var(--spacing) * 6)"},'&[size="icon-xs"]':{width:"calc(var(--spacing) * 6)",height:"calc(var(--spacing) * 6)",svg:{width:"calc(var(--spacing) * 3)",height:"calc(var(--spacing) * 3)"}},'&[size="sm"]':{height:"calc(var(--spacing) * 7)"},'&[size="icon-sm"]':{width:"calc(var(--spacing) * 7)",height:"calc(var(--spacing) * 7)"},'&[size="lg"]':{height:"calc(var(--spacing) * 9)"},'&[size="icon-lg"]':{width:"calc(var(--spacing) * 9)",height:"calc(var(--spacing) * 9)"},"&[disabled]":{opacity:".5"}}));let wt=yt;const Mt=class t extends u{constructor(e,s){super(t.tagname,e,s)}};a(Mt,"tagname","badge"),$.style(Mt,ot(Mt.tagname,{display:"inline-flex",placeContent:"center",placeItems:"center",padding:"0 calc(var(--spacing) * 2)",borderRadius:"calc(var(--radius) * 2.6)",height:"calc(var(--spacing) * 5)",transition:"0.2s all ease",fontSize:"var(--text-xs)",fontWeight:"var(--font-weight-medium)",fontFamily:"inherit",outline:"0.1rem solid oklch(from var(--border) l c h / 0)",whiteSpace:"nowrap",border:"1px solid oklch(from var(--input) l c h / .2)",background:"oklch(from var(--input) l c h / .025)",color:"oklch(from var(--fg) l c h / .9)","&:focus-visible":{outline:"0.1rem solid var(--border)"},"a:not([disabled]) &:hover":{background:"oklch(from var(--input) l c h / .1)",color:"oklch(from var(--fg) l c h / 1)"},'&[variant="primary"]':{border:"none",color:"oklch(from var(--primary-fg) l c h)",background:"var(--primary-bg)"},'&[variant="secondary"]':{border:"none",color:"oklch(from var(--secondary-fg) l c h)",background:"var(--secondary-bg)","a:not([disabled]) &:hover":{background:"oklch(from var(--secondary-bg) l c h / .8)"}},'&[variant="destructive"]':{border:"none",color:"oklch(from var(--destructive-fg) l c h)",background:"oklch(from var(--destructive-bg) l c h / .3)","a:not([disabled]) &:hover":{background:"oklch(from var(--destructive-bg) l c h / .5)"}},'&[variant="ghost"]':{border:"none",color:"oklch(from var(--fg) l c h)",background:"oklch(from var(--input) l c h / 0)","a:not([disabled]) &:hover":{background:"oklch(from var(--input) l c h / .1)"}},'&[variant="link"]':{border:"none",color:"oklch(from var(--fg) l c h)",background:"oklch(from var(--input) l c h / 0)","a:not([disabled]) &:hover":{textDecoration:"underline",textUnderlineOffset:"0.2rem"}},"a[disabled] &":{opacity:".5"}}));let Dt=Mt;const zt=class t extends u{constructor(e,s){super(t.tagname,e,s)}};a(zt,"tagname","card"),$.style(zt,ot(zt.tagname,{display:"flex",flexDirection:"column",gap:"calc(var(--spacing))",paddingBlock:"calc(var(--spacing) * 4)",background:"var(--secondary-bg)",borderRadius:"calc(var(--radius) * 1.4)"}));let It=zt;const Ot=class t extends u{constructor(e,s){super(t.tagname,e,s)}};a(Ot,"tagname","card-header"),$.style(Ot,ot(Ot.tagname,{display:"grid",width:"100%",gridTemplateRows:"auto auto",gap:"var(--spacing)",container:"card-header / inline-size ",paddingInline:"calc(var(--spacing) * 4)"}));let St=Ot;const At=class t extends u{constructor(e,s){super(t.tagname,e,s)}};a(At,"tagname","card-content"),$.style(At,ot(At.tagname,{paddingInline:"calc(var(--spacing) * 4)"}));let Ct=At;const Et=class t extends u{constructor(e,s){super(t.tagname,e,s)}};a(Et,"tagname","h3"),$.style(Et,ot(`card ${Et.tagname}`,{fontWeight:"var(--font-weight-medium)",lineHeight:"1.375",fontSize:"var(--text-base)",color:"var(--fg)"}));let Lt=Et;const Wt=class t extends u{constructor(e,s){super(t.tagname,e,s)}};a(Wt,"tagname","p"),$.style(Wt,ot(`card ${Wt.tagname}`,{fontWeight:"var(--font-weight-medium)",lineHeight:"var(--line-height-sm)",fontSize:"var(--text-sm)",color:"var(--muted)"}));let Ht=Wt;const Rt=class t extends u{constructor(e,s){super(t.tagname,e,s)}};a(Rt,"tagname","dl"),$.style(Rt,ot(Rt.tagname,{display:"flex",flexDirection:"column"}));let Tt=Rt;const Bt=class t extends u{constructor(e,s){super(t.tagname,e,s)}};a(Bt,"tagname","dc"),$.style(Bt,ot(Bt.tagname,{paddingBlock:"1rem",borderBottom:"1px solid color-mix(in oklch, var(--input) 50%, transparent)"}));let _t=Bt;const jt=class t extends u{constructor(e,s){super(t.tagname,e,s)}};a(jt,"tagname","dt"),$.style(jt,ot(jt.tagname,{fontSize:"var(--text-sm)",fontWeight:"var(--font-weight-medium)"}));let Ft=jt;const Pt=class t extends u{constructor(e,s){super(t.tagname,e,s)}};a(Pt,"tagname","dd"),$.style(Pt,ot(Pt.tagname,{margin:"0",fontSize:"var(--text-sm)",color:"var(--muted)"}));let Ut=Pt;export{Y as Accordion,Z as AccordionContainer,G as AccordionContent,J as AccordionTrigger,Dt as Badge,wt as Button,It as Card,Ct as CardContent,Ht as CardDescription,St as CardHeader,Lt as CardTitle,_t as DescriptionContent,Ut as DescriptionDetail,Tt as DescriptionList,Ft as DescriptionTerm,$t as Icon,B as Label,T as Radio,W as RadioGroup,R as RadioItem,ct as Select,xt as SelectArrow,gt as SelectContent,mt as SelectGroup,bt as SelectItem,dt as SelectTrigger,ut as SelectValue,A as Slide,E as Slideshow,nt as TabContent,it as TabTrigger,st as Tabs,rt as TabsContainer,j as TextBlock,Q as Waterfall,tt as WaterfallItem,O as slideInOut};
package/build/utils.js CHANGED
@@ -1 +1 @@
1
- import{onclient as e}from"@amateras/core";const t=null,r=void 0,n=Object,s=n.fromEntries,o=n.entries,a=n.assign,i=n.values,c=n.defineProperty,l=n.getOwnPropertyDescriptors,p=Array,u=p.from,g=async(e,t)=>{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++})()},m=(e,t)=>u(e).map(t),f=(e,t)=>typeof e===t,y=(e,t)=>t.includes(e),d=e=>f(e,"string"),h=e=>f(e,"boolean"),w=e=>f(e,"number"),b=e=>f(e,"object"),j=e=>f(e,"function"),v=e=>E(e,(async()=>0).constructor),O=e=>void 0===e,P=e=>e===t,A=p.isArray,E=(e,...t)=>!!t.find(t=>e instanceof t),M=(e,r)=>E(e,r)?e:t,S=JSON.stringify,T=JSON.parse,U=(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)}},N="abcdefghijklmnopqrstuvwxyz",k=N.toUpperCase(),q=e=>{const t="any"===(e={length:5,lettercase:"any",...e}).lettercase?N+k:"lower"===e.lettercase?N:k;return u({length:e.length},(e,r)=>t[Math.round(Math.random()*t.length)]).join("")},z=async e=>new C(t=>setTimeout(t,e)),D=e=>E(e,Array)?e:[e],I=e=>{try{return[e(),t]}catch(r){return[t,E(r,Error)?r:new Error(S(r))]}},L=(e,t,r)=>`${$(e,0,t)}${$(e,t,r).toUpperCase()}${r?$(e,r):""}`,R=URL,W=t=>E(t,R)?t:U(t,"http")?new R(t):e()?new R(U(t,origin)?t:origin+t):new R("https://localhost"+t);class B{static map=/* @__PURE__ */new Map;static generate(e,t){const r=B.map.get(e)??/* @__PURE__ */new Set,n=q(t);return r.has(n)?B.generate(e):n}static persistInProto(e,t,r){const n=B.generate(t,r);e.disposers.add(()=>B.map.get(t)?.delete(n))}}export{B as UID,u as _Array_from,T as _JSON_parse,S as _JSON_stringify,a as _Object_assign,c as _Object_defineProperty,o as _Object_entries,s as _Object_fromEntries,l as _Object_getOwnPropertyDescriptors,i as _Object_values,C as _Promise,x as _bind,E as _instanceof,t as _null,f as _typeof,r as _undefined,J as debounce,g as forEach,M as is,A as isArray,v as isAsyncFunction,h as isBoolean,y as isEqual,j as isFunction,P as isNull,w as isNumber,b as isObject,d as isString,O as isUndefined,m as map,q as randomId,z as sleep,$ as slice,U as startsWith,D as toArray,W as toURL,I as trycatch,L as uppercase};
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};
package/build/widget.js CHANGED
@@ -1 +1 @@
1
- import{Proto as t,symbol_ProtoType as e}from"@amateras/core";import{forEach as s,_Object_assign as r}from"@amateras/utils";const o=o=>{let a=/* @__PURE__ */new WeakMap;return class extends t{static[e]="Widget";static stores=a;constructor(...t){super(()=>{let e=t[0]??{},i=t[1],{store:c,layout:n,ancestors:l}=o(e);c||(c={}),l&&s(l,t=>{let e=this.findAbove(e=>e.constructor===t&&e);if(e){let s=t.stores.get(e);r(c,s)}}),a.set(this,c),n({store:c,children:t=>i?.(t)})})}}};r($,{widget:t=>o(t)});export{o as WidgetConstructor};
1
+ import{Proto as t,symbol_ProtoType as r}from"@amateras/core";import{_Object_assign as s}from"@amateras/utils";const a=s=>class extends t{static[r]="Widget";static name="Block";constructor(t,r){super(()=>s(t,t=>r?.(t)))}};s($,{widget:t=>a(t)});export{a as WidgetConstructor};
package/index.ts CHANGED
@@ -1 +1 @@
1
- import '@amateras/core';
1
+ import './packages/core/src/index';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "amateras",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "description": "Amateras is a JavaScript library for building user interface.",
5
5
  "module": "index.ts",
6
6
  "type": "module",
@@ -15,6 +15,10 @@
15
15
  "homepage": "https://github.com/defaultkavy/amateras",
16
16
  "license": "MIT",
17
17
  "unpkg": "./build/import-map.js",
18
+ "scripts": {
19
+ "build": "bun ./scripts/build.ts",
20
+ "size": "bun ./scripts/vite-bundler-size.ts"
21
+ },
18
22
  "exports": {
19
23
  ".": {
20
24
  "default": "./index.ts"
@@ -34,9 +38,6 @@
34
38
  "./markdown/syntax/*": "./packages/markdown/src/syntax/*.ts",
35
39
  "./*": "./packages/*/src/index.ts"
36
40
  },
37
- "dependencies": {
38
- "@amateras/core": "./packages/core"
39
- },
40
41
  "workspaces": {
41
42
  "packages": [
42
43
  "packages/*"