literaljs 7.0.2 → 8.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,31 +3,249 @@
3
3
  </p>
4
4
 
5
5
  ---
6
+
6
7
  # LiteralJS
7
- ### A small JavaScript library for building user interfaces.
8
8
 
9
- ### Links
10
- - **Documentation**: https://literaljs.com
9
+ ### A small, fast JavaScript library for building reactive user interfaces.
10
+
11
+ **v8.0.0** — Zero runtime dependencies. Modern browser targets (Chrome 90+, Firefox 90+, Safari 14+).
12
+
13
+ ---
14
+
15
+ ## Quick Start
16
+
17
+ ### npm
18
+
19
+ ```bash
20
+ npm install literaljs
21
+ ```
11
22
 
12
- Recent 7.0.2 microbundle:
13
23
  ```js
14
- Build "literaljs" to build:
15
- 1856 B: index.js.gz
16
- 1611 B: index.js.br
17
- 1859 B: index.m.js.gz
18
- 1620 B: index.m.js.br
19
- 1919 B: index.umd.js.gz
20
- 1680 B: index.umd.js.br
21
- ```
22
- ### [Features and stuff](#features)
23
-
24
- - **Small**: Under 2kB in size (using microbundle).
25
- - **Startup**: Amazing startup metrics; Great for weaker devices and weaker connections.
26
- - **Simple**: LiteralJS uses plain functions and applies structure to building components for easier development.
27
- - **Fast**: Current and previous vDOM data is diffed instead of the actual DOM for performant updates and rendering.
28
- - **Virtual DOM**: Diffing occurs only on state update for more efficient DOM updates.
29
- - **Flexible Syntax**: Freedom to use JSX, Hyperscript, or Object syntax.
30
- - **Lifecycle Methods**: Components have the ability to trigger `mounted`, `updated`, and `unmounted` lifecycle functions.
31
- - **Global Application Store**: One source of truth which makes other state management libraries (like Redux) less of a need.
32
- - **Component State**: Manage state individually per component.
33
- - **Event Delegation**: Uses event delegation for most events within the application for increased performance.
24
+ /** @jsx h */
25
+ import { h, component, App } from 'literaljs';
26
+
27
+ const Hello = component({
28
+ name: 'Hello',
29
+ state: { count: 0 },
30
+ render() {
31
+ const { count } = this.getState();
32
+ return (
33
+ <div>
34
+ <p>Count: {count}</p>
35
+ <button events={{ click: () => this.setState({ count: count + 1 }) }}>
36
+ Increment
37
+ </button>
38
+ </div>
39
+ );
40
+ }
41
+ });
42
+
43
+ new App(Hello, {}).mount('app');
44
+ ```
45
+
46
+ > **JSX setup**: Configure your build tool to use `h` as the JSX pragma. Babel example:
47
+ > ```json
48
+ > { "plugins": [["@babel/plugin-transform-react-jsx", { "pragma": "h" }]] }
49
+ > ```
50
+
51
+ ### CDN (UMD)
52
+
53
+ ```html
54
+ <script src="https://unpkg.com/literaljs/build/index.umd.js"></script>
55
+ <script>
56
+ const { h, component, App } = LiteralJS;
57
+ // ...same as above
58
+ </script>
59
+ ```
60
+
61
+ ---
62
+
63
+ ## Public API
64
+
65
+ | Export | Purpose |
66
+ |--------|---------|
67
+ | `h(tag, attrs, ...children)` | Create VNode (Hyperscript/Object syntax, or JSX pragma) |
68
+ | `component(config)` | Define a component with state, methods, lifecycle |
69
+ | `new App(rootComponent, initialStore)` | Create an app instance |
70
+ | `app.mount(domId)` | Mount to a DOM element |
71
+ | `app.unmount()` | Remove from DOM and clean up |
72
+ | `app.setStore(updates)` | Update global store |
73
+ | `render(rootComponent, domId, store)` | Legacy one-liner (backward-compatible) |
74
+
75
+ ---
76
+
77
+ ## Architecture Highlights
78
+
79
+ ### v8 Performance Features
80
+
81
+ - **Keyed reconciliation** — `key` attribute preserves DOM identity across reordering
82
+ - **WeakMap event delegation** — Fast path skips ancestor walk when no handlers exist
83
+ - **Component render memoization** — Shallow props comparison skips re-execution when props unchanged
84
+ - **Text node fast path** — Updates `textContent` in-place instead of `replaceChild`
85
+ - **Reference-equality short-circuits** — Skips diffing for unchanged VNodes, children, and attributes
86
+ - **Deferred patching** — DOM mutations complete before content patches for consistent state
87
+
88
+ ### Module Structure
89
+
90
+ ```
91
+ App (container)
92
+ ├── StateManager — global store + component state
93
+ ├── EventManager — WeakMap delegation + event cache
94
+ ├── Renderer — DOM creation + virtual DOM diff/patch
95
+ ├── LifecycleQueue — mounted/updated/unmounted hooks
96
+ ├── DiffEngine — keyed + non-keyed child reconciliation
97
+ └── MountOrchestrator — tree generation + render cycle
98
+ ```
99
+
100
+ ---
101
+
102
+ ## Bundle Size
103
+
104
+ | Format | Size | Gzipped | Brotli |
105
+ |--------|------|---------|--------|
106
+ | ESM (modern) | 13.86 kB | 4.25 kB | 3.91 kB |
107
+ | UMD | 14.06 kB | 4.34 kB | 3.96 kB |
108
+ | CJS | 14.19 kB | 4.35 kB | 3.93 kB |
109
+
110
+ Build target: Chrome 90+, Firefox 90+, Safari 14+ (ES2018). No `Object.assign` polyfill.
111
+
112
+ ---
113
+
114
+ ## Performance (JSDOM, local benchmarks)
115
+
116
+ | Benchmark | v7 Baseline | v8 Optimized | Change |
117
+ |-----------|-------------|--------------|--------|
118
+ | create 1k rows | ~45ms | ~47ms | stable |
119
+ | replace 1k rows | ~65ms | ~6ms | **-91%** |
120
+ | partial update | ~186ms | ~100ms | **-46%** |
121
+ | select row | ~22ms | ~0.05ms | **-99.8%** |
122
+ | swap rows | — | ~123ms* | *JSDOM artifact; real Chrome near-instant |
123
+ | remove row | ~74ms | ~5ms | **-93%** |
124
+ | clear rows | ~3ms | ~0.01ms | **-99.7%** |
125
+
126
+ *All benchmarks on JSDOM. Real Chrome results for `swap` are expected to be ~1ms (pointer swap).*
127
+
128
+ ---
129
+
130
+ ## Features
131
+
132
+ - **Small** — ~4.25 kB gzipped, zero dependencies
133
+ - **Fast** — Keyed diffing, WeakMap event delegation, render memoization
134
+ - **Simple** — Plain functions + structured components. No classes, no hooks, no magic.
135
+ - **Virtual DOM** — Diffed updates only on state change
136
+ - **Flexible Syntax** — JSX (with `h` pragma), Hyperscript, or Object syntax
137
+ - **Lifecycle Methods** — `mounted`, `updated`, `unmounted`
138
+ - **Global + Component State** — Built-in store; no Redux needed
139
+ - **Event Delegation** — Most events delegated to root for performance
140
+ - **Isolated Instances** — Multiple `App` instances on one page, no globals
141
+
142
+ ---
143
+
144
+ ## Component API
145
+
146
+ ```js
147
+ /** @jsx h */
148
+ import { h, component, App } from 'literaljs';
149
+
150
+ const MyComponent = component({
151
+ name: 'MyComponent', // Required, for debugging
152
+ state: { count: 0 }, // Initial component state
153
+ methods() { // Bound functions available as `this.methodName`
154
+ return {
155
+ increment() { this.setState({ count: this.getState().count + 1 }); }
156
+ };
157
+ },
158
+ mounted() { console.log('mounted'); },
159
+ updated() { console.log('updated'); },
160
+ unmounted() { console.log('unmounted'); },
161
+ render() {
162
+ const { count } = this.getState();
163
+ return (
164
+ <div>
165
+ <p>Count: {count}</p>
166
+ <button events={{ click: () => this.increment() }}>Add</button>
167
+ </div>
168
+ );
169
+ }
170
+ });
171
+
172
+ new App(MyComponent, {}).mount('app');
173
+ ```
174
+
175
+ ### Props
176
+
177
+ ```js
178
+ /** @jsx h */
179
+ // Parent passes props
180
+ <MyComponent key="unique" title="Hello" />
181
+
182
+ // Child accesses via this.props
183
+ render() {
184
+ return <h1>{this.props.title}</h1>;
185
+ }
186
+ ```
187
+
188
+ ### Keys
189
+
190
+ Use `key` for list items to enable DOM identity preservation:
191
+
192
+ ```js
193
+ /** @jsx h */
194
+ <ul>
195
+ {items.map(item => (
196
+ <li key={item.id}>{item.name}</li>
197
+ ))}
198
+ </ul>
199
+ ```
200
+
201
+ ---
202
+
203
+ ## State Management
204
+
205
+ ### Component State (private)
206
+
207
+ ```js
208
+ this.getState(); // Read current state
209
+ this.setState({ count: 5 }); // Update and trigger re-render
210
+ ```
211
+
212
+ ### Global Store (shared)
213
+
214
+ ```js
215
+ // In any component
216
+ this.setStore({ theme: 'dark' }); // Update global store
217
+
218
+ // Access in render
219
+ render() {
220
+ const theme = this.getStore().theme;
221
+ return <div class={theme}>...</div>;
222
+ }
223
+ ```
224
+
225
+ ---
226
+
227
+ ## Documentation
228
+
229
+ - **Full docs**: https://literaljs.com
230
+ - **Architecture decisions**: `docs/ADR/`
231
+ - **Phase plans**: `docs/v8-*-plan.md`
232
+
233
+ ---
234
+
235
+ ## js-framework-benchmark
236
+
237
+ A keyed benchmark entry is included in `js-framework-benchmark-entry/`.
238
+
239
+ ```bash
240
+ cd js-framework-benchmark-entry
241
+ npm install
242
+ npm run build-prod
243
+ ```
244
+
245
+ Copy to [krausest/js-framework-benchmark](https://github.com/krausest/js-framework-benchmark) `frameworks/keyed/literaljs/` and run `npm run bench`.
246
+
247
+ ---
248
+
249
+ ## License
250
+
251
+ MIT
package/build/index.js CHANGED
@@ -1,2 +1 @@
1
- var t,e,n,i={},o={},r=[],u={},d=[],f=["abort","blur","error","focus","load","mouseenter","mouseleave","resize","scroll","unload"];function c(t){return Array.isArray(t)}function s(){return Math.random().toString(36).substring(2)+(new Date).getTime().toString(36)}function a(t,e){for(var n=0,i=e.length;n<i;n++)c(e[n])?a(t,e[n]):t.push(e[n]);return t}function h(t,e){for(var n in e)t[n]=e[n];return t}function v(t,e,n){return h(h(t,e),n)}function l(t,e){return{e:t,a:h({},e),c:a([],[].slice.call(arguments,2))}}function p(o,r,u){void 0===u&&(u={}),i=h({},u),e=o,t=document.getElementById(r),n=j(o()),C(t,n),J()}function y(t){var e=void 0===t?{}:t,n=e.name,r=void 0===n?"":n,u=e.state,d=void 0===u?{}:u,f=e.mounted,c=void 0===f?function(){}:f,a=e.updated,h=void 0===a?function(){}:a,v=e.unmounted,l=void 0===v?function(){}:v,p=e.methods,y=void 0===p?function(){}:p,j=e.render,S=void 0===j?function(){}:j,N=s();return function(t){return void 0===t&&(t={}),{id:N,init:function(){return this.id=N,this.name=r+(t.key?"_"+t.key:""),this.key=this.id+(this.name||""),this.props=t,this.store=i,this.getStore=b,this.setStore=m.bind(this),this.getState=g.bind(this),this.setState=k.bind(this),this.createState=function(){void 0===o[this.key]&&(o[this.key]=d)}.bind(this)(),this.deleteState=function(){delete o[this.key]}.bind(this),this.mounted=c.bind(this),this.updated=h.bind(this),this.unmounted=l.bind(this),function(t,e){for(var n in"function"==typeof e&&(e=e.bind(t)()),e)t[n]=e[n].bind(t)}(this,y),this.render=S.bind(this),this}}}}function b(){return h({},i)}function m(t,e){"function"==typeof t&&(t=t(i)),i=v({},i,t),x(),"function"==typeof e&&e.bind(this)()}function g(){return h({},o[this.key])}function k(t,e){"function"==typeof t&&(t=t(o[this.key])),o[this.key]=v({},o[this.key],t),x(),"function"==typeof e&&e.bind(this)()}function j(t){if(void 0===t)return t;if("function"==typeof t.e){var e=h({},t.a.props);delete t.a.props,t=t.e(e)}if("function"==typeof t.init){var n=new t.init;"object"==typeof(t=n.render())&&(t.id=n.id,t.m=n.mounted,t.up=n.updated,t.un=n.unmounted,t.d=n.deleteState)}if(c(t.c))for(var i=0,o=t.c.length;i<o;i++)t.c[i]=j(t.c[i]);return t}function S(t){var e=typeof t;if("string"===e||"number"===e)return document.createTextNode(t);if("boolean"===e||"undefined"===e)return document.createTextNode("");var n=document.createElement(t.e);if("object"==typeof t.a)for(var i=Object.keys(t.a),o=i.length;o--;)"events"===i[o]?(t.eid=s(),A(t.eid,t.a[i[o]],n)):"style"===i[o]?O(t.a[i[o]],n):n.setAttribute(i[o],t.a[i[o]]);if(z(t,"m"),c(t.c))for(var r=0,u=t.c.length;r<u;r++)C(n,t.c[r]);return n}function N(t){if("#document"!==t.parentNode.nodeName){var e=t.getAttribute("data-eid");return"string"==typeof e?e:N(t.parentNode)}}function A(e,n,i){i.setAttribute("data-eid",e),u[e]=n;for(var o=Object.keys(n),d=o.length;d--;)f.includes(o[d])?i.addEventListener(o[d],u[e][o[d]]):r.includes(o[d])||(r.push(o[d]),t.addEventListener(o[d],function(t){var e=N(t.target);if("string"==typeof e&&u[e]){var n=u[e][t.type];"function"==typeof n&&n(t)}}))}function O(t,e){if(void 0!==t)for(var n=Object.keys(t),i=n.length;i--;)e.style[n[i]]=t[n[i]]}function x(i){var o=h({},n),r=j(e());n=r,E(t,t.firstChild,r,o),J()}function E(t,e,n,i){var o=typeof n,r=typeof i;if("undefined"===r)C(t,n);else if("undefined"===o)L(i),e.remove();else if(function(t,e,n,i){return n!==i||t.e!==e.e||t.id!==e.id||("string"===n||"number"===n)&&t!==e}(n,i,o,r))L(i),t.replaceChild(S(n),e);else if("object"===o){var u;!function(t,e,n){z(e,"up");for(var i,o,r=Object.keys(e.a),u=r.length;u--;)if(o=e.a[r[u]],i=n.a[r[u]],"style"===r[u]){if(void 0,void 0,a=typeof(f=i),"object"==(c=typeof(d=o))&&"object"===a&&JSON.stringify(d)===JSON.stringify(f)||"undefined"===c&&"undefined"===a)continue;t.removeAttribute(r[u]),O(o,t)}else"events"===r[u]?(w(t,n.eid),T(n.eid),e.eid=s(),A(e.eid,o,t)):"value"===r[u]&&o!==i?t.value=o:void 0!==i&&o===i||t.setAttribute(r[u],o);var d,f,c,a}(e,n,i);for(var d=i.c.length;d--&&void 0===n.c[d];)"object"==typeof(u=e.lastChild)&&(L(i.c[d]),u.remove());for(var f=0,c=n.c.length;f<c;f++)E(e,e.childNodes[f],n.c[f],i.c[f])}}function C(t,e){t.appendChild(S(e))}function L(t){if(void 0!==t&&(z(t,"un"),z(t,"d"),T(t.eid),c(t.c)))for(var e=t.c.length;e--;)L(t.c[e])}function T(t){"string"==typeof t&&delete u[t]}function w(t,e){for(var n=Object.keys(u[e]),i=n.length;i--;)f.includes(n[i])&&t.removeEventListener(n[i],u[e][n[i]])}function J(){for(var t;t=d.shift();)t()}function z(t,e){"object"==typeof t&&"function"==typeof t[e]&&d.push(t[e])}module.exports={component:y,render:p,h:l},exports.component=y,exports.h=l,exports.render=p;
2
- //# sourceMappingURL=index.js.map
1
+ class e{constructor(e,t,n){void 0===t&&(t={}),void 0===n&&(n=[]),this.e=e,this.a=t,this.c=n}withLifecycle(e){return e.mounted&&(this.m=e.mounted),e.updated&&(this.up=e.updated),e.unmounted&&(this.un=e.unmounted),e.deleteState&&(this.d=e.deleteState),this}withIdentity(e,t){return this.definitionId=e,this.instanceId=t,this.id=e+"_"+t,this}}function t(e,n){for(let s=0,i=n.length;s<i;s++)Array.isArray(n[s])?t(e,n[s]):e.push(n[s]);return e}function n(){return Math.random().toString(36).substring(2)+(new Date).getTime().toString(36)}class s{constructor(e,t,n,s,i,o){this.definitionId=e,this.instanceId=t,this.name=n,this.key=`${e}_${t}_${n}`,this.props=s,this._stateManager=o,this._config=i,o.createState(this.key,i.state),this.mounted=i.mounted.bind(this),this.updated=i.updated.bind(this),this.unmounted=i.unmounted.bind(this),this.deleteState=()=>{this._stateManager.deleteState(this.key)},this._renderedVNode=null,this._previousProps=null;const r=i.render.bind(this);this.render=()=>{if(!this.shouldUpdate())return this._renderedVNode;const e=r();return this._renderedVNode=e,this._previousProps=this.props,e}}getStore(){return this._stateManager.getStore()}setStore(e,t){this._stateManager.setStore(e,t)}getState(){return this._stateManager.getState(this.key)}setState(e,t){this._stateManager.setState(this.key,e,t)}createState(){this._stateManager.createState(this.key,this._config.state)}deleteState(){this._stateManager.deleteState(this.key)}shouldUpdate(){return!this._previousProps||!function(e,t){if(e===t)return!0;if(!e||!t||"object"!=typeof e||"object"!=typeof t)return!1;const n=Object.keys(e),s=Object.keys(t);if(n.length!==s.length)return!1;for(let s=0;s<n.length;s++)if(e[n[s]]!==t[n[s]])return!1;return!0}(this.props,this._previousProps)}bindMethods(e){"function"==typeof e&&(e=e.bind(this)());for(let t in e)this[t]=e[t].bind(this)}}function i(e,t){for(let n in t)e[n]=t[n];return e}class o{constructor(e){void 0===e&&(e={}),this.store={...e},this.componentStates={},this.listeners=[]}subscribe(e){this.listeners.push(e)}unsubscribe(e){const t=this.listeners.indexOf(e);t>-1&&this.listeners.splice(t,1)}_notify(){for(let e=0;e<this.listeners.length;e++)this.listeners[e]()}getStore(){return{...this.store}}setStore(e,t){"function"==typeof e&&(e=e(this.store)),this.store=i(i({},this.store),e),this._notify(),"function"==typeof t&&t()}createState(e,t){e in this.componentStates||(this.componentStates[e]={...t})}getState(e){return{...this.componentStates[e]}}setState(e,t,n){"function"==typeof t&&(t=t(this.componentStates[e])),this.componentStates[e]=i(i({},this.componentStates[e]),t),this._notify(),"function"==typeof n&&n()}deleteState(e){delete this.componentStates[e]}reset(){this.store={},this.componentStates={},this.listeners=[]}}class r{constructor(e,t,n){this.eventManager=e,this.lifecycleQueue=t,this.diffEngine=n}mount(e,t){const n=this.createElement(t);n&&e.appendChild(n)}createElement(e){const t=typeof e;return"string"===t||"number"===t?document.createTextNode(e):"boolean"===t||"undefined"===t?document.createTextNode(""):"object"===t&&e.e?this._createElementNode(e):null}_createElementNode(e){const t=document.createElement(e.e);if("object"==typeof e.a){const n=Object.keys(e.a);for(let s=n.length;s--;)if("events"===n[s])e.eid=this.eventManager.bindEvents(t,e.a[n[s]]);else if("style"===n[s])this._addStyles(e.a[n[s]],t);else{if("key"===n[s])continue;t.setAttribute(n[s],e.a[n[s]])}}if(this.lifecycleQueue.mounted(e),Array.isArray(e.c))for(let n=0,s=e.c.length;n<s;n++){const s=this.createElement(e.c[n]);s&&t.appendChild(s)}return t}_addStyles(e,t){if(void 0===e)return;const n=Object.keys(e);for(let s=n.length;s--;)t.style[n[s]]=e[n[s]]}patch(e,t,n,s){const i=typeof n;if(void 0===s)this._appendChild(e,n);else if("undefined"===i)this._unmountNodeAndChildren(s),t&&t.remove();else if(this.diffEngine.areNodesEqual(n,s)){if("object"===i&&n.e){if(n===s)return;if(this._updateNodes(t,n,s),n.c!==s.c)if(this.diffEngine._hasKeys(n.c)||this.diffEngine._hasKeys(s.c))this.diffEngine.reconcileChildren(t,n.c,s.c,this);else{let e;for(let i=s.c?s.c.length:0;i--&&void 0===n.c[i];)e=t.lastChild,e&&(this._unmountNodeAndChildren(s.c[i]),e.remove());if(Array.isArray(n.c))for(let e=0,i=n.c.length;e<i;e++)this.patch(t,t.childNodes[e]||null,n.c[e],s.c?s.c[e]:void 0)}}}else if(!t||3!==t.nodeType||"string"!==i&&"number"!==i)this._unmountNodeAndChildren(s),t&&e.replaceChild(this.createElement(n),t);else{const e=String(n);t.textContent!==e&&(t.textContent=e)}}_appendChild(e,t){const n=this.createElement(t);n&&e.appendChild(n)}_updateNodes(e,t,n){if(this.lifecycleQueue.updated(t),t.a===n.a)return;if(!t.a||!n.a)return;const s=Object.keys(t.a);let i,o;for(let r=s.length;r--;)if(o=t.a[s[r]],i=n.a[s[r]],"style"===s[r]){if(this._stylesAreEqual(o,i))continue;e.removeAttribute(s[r]),this._addStyles(o,e)}else if("events"===s[r])this.eventManager.unbindEvents(e,n.eid),t.eid=this.eventManager.bindEvents(e,o);else{if("key"===s[r])continue;"value"===s[r]&&o!==i?e.value=o:void 0!==i&&o===i||e.setAttribute(s[r],o)}}_stylesAreEqual(e,t){if(e===t)return!0;const n=typeof e,s=typeof t;if("undefined"===n&&"undefined"===s)return!0;if("object"!==n||"object"!==s)return!1;const i=Object.keys(e),o=Object.keys(t);if(i.length!==o.length)return!1;for(let n=i.length;n--;)if(e[i[n]]!==t[i[n]])return!1;return!0}_unmountNodeAndChildren(e){if(null!=e&&(this.lifecycleQueue.unmounted(e),this.lifecycleQueue.deleteState(e),this.eventManager.deleteCachedEvent(e.eid),Array.isArray(e.c)))for(let t=e.c.length;t--;)this._unmountNodeAndChildren(e.c[t])}unmount(e,t){this._unmountNodeAndChildren(t),e&&(e.innerHTML="")}}class h{constructor(e,t,n){this._getCache=e,this._resolveUUID=t,this._elementToUUID=n,this._attachedTypes=new Set,this._rootNode=null}attach(e,t){this._attachedTypes.has(t)||(this._attachedTypes.add(t),this._rootNode=e,e._literaljs_hasEvents=!0,e.addEventListener(t,e=>this._handle(e)))}_handle(e){if(!this._rootNode||!this._rootNode._literaljs_hasEvents)return;let t=e.target;for(;t&&t!==this._rootNode;){let n;if(this._elementToUUID&&(n=this._elementToUUID.get(t))){const t=this._getCache(n);if(t&&"function"==typeof t[e.type])return void t[e.type](e)}const s=this._resolveUUID(t);if("string"==typeof s){const t=this._getCache(s);if(t&&"function"==typeof t[e.type])return void t[e.type](e)}t=t.parentNode}}reset(){this._attachedTypes.clear()}}const d=["abort","blur","error","focus","load","mouseenter","mouseleave","resize","scroll","unload"],c="eid";class u{constructor(){this.cache={},this.rootNode=null,this._elementToUUID=new WeakMap,this.eventBus=new h(e=>this.cache[e],e=>this.getEventUUID(e),this._elementToUUID)}setRootNode(e){this.rootNode=e}getEventUUID(e){if(!e||!e.parentNode)return;if("#document"===e.parentNode.nodeName)return;const t=e.getAttribute("data-"+c);return"string"==typeof t?t:this.getEventUUID(e.parentNode)}bindEvents(e,t){const s=n();e.setAttribute("data-"+c,s),this.cache[s]=t,this._elementToUUID.set(e,s);const i=Object.keys(t);for(let t=i.length;t--;)d.includes(i[t])?e.addEventListener(i[t],this.cache[s][i[t]]):this.eventBus.attach(this.rootNode,i[t]);return s}unbindEvents(e,t){if(!this.cache[t])return;const n=Object.keys(this.cache[t]);for(let s=n.length;s--;)d.includes(n[s])&&e.removeEventListener(n[s],this.cache[t][n[s]]);this.deleteCachedEvent(t),this._elementToUUID.delete(e),e.removeAttribute("data-"+c)}addEvents(e,t,n){n.setAttribute("data-"+c,e),this.cache[e]=t,this._elementToUUID.set(n,e);const s=Object.keys(t);for(let t=s.length;t--;)d.includes(s[t])?n.addEventListener(s[t],this.cache[e][s[t]]):this.eventBus.attach(this.rootNode,s[t])}removeIndividualEvents(e,t){if(!this.cache[t])return;const n=Object.keys(this.cache[t]);for(let s=n.length;s--;)d.includes(n[s])&&e.removeEventListener(n[s],this.cache[t][n[s]])}deleteCachedEvent(e){"string"==typeof e&&delete this.cache[e]}destroy(){this.rootNode&&(this.rootNode._literaljs_hasEvents=!1),this.cache={},this.rootNode=null,this.eventBus.reset()}}class a{constructor(){this.queue=[]}mounted(e){"object"==typeof e&&"function"==typeof e.m&&this.queue.push(e.m)}updated(e){"object"==typeof e&&"function"==typeof e.up&&this.queue.push(e.up)}unmounted(e){"object"==typeof e&&"function"==typeof e.un&&this.queue.push(e.un)}deleteState(e){"object"==typeof e&&"function"==typeof e.d&&this.queue.push(e.d)}flush(){let e;for(;e=this.queue.shift();)e()}clear(){this.queue=[]}}function l(t,n){if(null==t)return t;if("function"==typeof t.e){const e={...t.a.props};delete(t={e:t.e,a:{...t.a},c:t.c}).a.props,t=t.e(e)}if(t&&"function"==typeof t.bind){const s=t.bind(n);let i;try{i=s.render()}catch(e){console.error("Component render error:",e),i={e:"div",a:{class:"error-boundary"},c:[`${e.name}: ${e.message}`]}}if("object"==typeof i&&null!==i&&i instanceof e)i.withIdentity(t.definitionId||s.definitionId,t.instanceId||s.instanceId),i.withLifecycle({mounted:s.mounted,updated:s.updated,unmounted:s.unmounted,deleteState:s.deleteState}),t=i;else if("object"==typeof i&&null!==i){const n=new e(i.e,i.a,i.c);n.withIdentity(t.definitionId||s.definitionId,t.instanceId||s.instanceId),n.withLifecycle({mounted:s.mounted,updated:s.updated,unmounted:s.unmounted,deleteState:s.deleteState}),t=n}else t=i}if(t&&Array.isArray(t.c))for(let e=0,s=t.c.length;e<s;e++)t.c[e]=l(t.c[e],n);return t}class f{areNodesEqual(e,t){const n=typeof e;return n===typeof t&&("object"===n&&e.e===t.e&&e.id===t.id||("string"===n||"number"===n)&&e===t)}reconcileChildren(e,t,n,s){return Array.isArray(t)?this._hasKeys(t)||this._hasKeys(n)?this._reconcileKeyed(e,t,n,s):this._reconcileNonKeyed(e,t,n,s):0}_reconcileNonKeyed(e,t,n,s){const i=t.length;if(0===i){if(n)for(let e=0;e<n.length;e++)s._unmountNodeAndChildren(n[e]);return e.innerHTML="",0}const o=e.childNodes;for(let r=0;r<i;r++)s.patch(e,o[r]||null,t[r],n?n[r]:void 0);return i}_hasKeys(e){if(!Array.isArray(e))return!1;for(let t=0,n=e.length;t<n;t++)if(e[t]&&e[t].a&&null!=e[t].a.key)return!0;return!1}_reconcileKeyed(e,t,n,s){const i=n?n.length:0,o=t.length;if(0===o){for(let e=0;e<i;e++)s._unmountNodeAndChildren(n[e]);return e.innerHTML="",0}const r=Object.create(null),h=Object.create(null);for(let t=0;t<i;t++){const s=n[t].a?n[t].a.key:null,i=e.childNodes[t];null!=s&&i&&(r[s]=i,h[s]=n[t])}const d=new Array(o),c=new Array(o);for(let e=0;e<o;e++){const n=t[e].a?t[e].a.key:null;null!=n&&r[n]?(d[e]=r[n],c[e]=h[n],delete r[n]):(d[e]=null,c[e]=null)}for(const t in r){const n=r[t];n&&(s.patch(e,n,void 0,h[t]),n.remove())}let u=e.firstChild;for(let n=0;n<o;n++){const i=d[n];if(i&&i===u)u=u.nextSibling;else if(i)e.insertBefore(i,u);else{const i=s.createElement(t[n]);i&&e.insertBefore(i,u)}}for(;u;){const e=u.nextSibling;u.remove(),u=e}for(let n=0;n<o;n++)c[n]&&s.patch(e,e.childNodes[n],t[n],c[n]);return o}removeExtraChildren(e,t,n,s){const i=t.c?t.c.length:0;if(!(i<=n))for(let o=i;o-- >n;){const n=e.lastChild;n&&(s._unmountNodeAndChildren(t.c[o]),n.remove())}}}class p{constructor(e,t,n){this.generateTree=e||l,this.renderer=t,this.lifecycleQueue=n}mount(e,t,n){const s=this.generateTree(t(),n);return this.renderer.mount(e,s),this.lifecycleQueue.flush(),s}update(e,t,n,s){const i=this.generateTree(t(),n);return this.renderer.patch(e,e.firstChild,i,s),this.lifecycleQueue.flush(),i}unmount(e,t){t&&(this.renderer.unmount(e,t),this.lifecycleQueue.flush())}}class y{constructor(e,t){void 0===t&&(t="microtask"),this._renderFn=e,this._scheduler=t,this._scheduled=!1}schedule(){this._scheduled||(this._scheduled=!0,"microtask"===this._scheduler?Promise.resolve().then(()=>this._execute()):"sync"===this._scheduler&&this._execute())}_execute(){this._scheduled=!1,this._renderFn()}}class m{constructor(e,t){void 0===t&&(t={}),this.rootComponent=e,this.savedTree=e,this.currentTree=null,this.rootNode=null,this.stateManager=new o(t),this.lifecycleQueue=new a,this.eventManager=new u,this.renderer=new r(this.eventManager,this.lifecycleQueue,new f),this.mountOrchestrator=new p(l,this.renderer,this.lifecycleQueue),this.updateLoop=new y(()=>this.update(),"microtask"),this._boundSchedule=()=>this.updateLoop.schedule(),this.stateManager.subscribe(this._boundSchedule)}mount(e){if(this.rootNode=document.getElementById(e),!this.rootNode)throw new Error(`Cannot mount app: element with id "${e}" not found`);return this.eventManager.setRootNode(this.rootNode),this.currentTree=this.mountOrchestrator.mount(this.rootNode,this.savedTree,this.stateManager),this}unmount(){this.mountOrchestrator.unmount(this.rootNode,this.currentTree),this.eventManager.destroy(),this.stateManager.unsubscribe(()=>this.updateLoop.schedule()),this.rootNode&&(this.rootNode.innerHTML=""),this.currentTree=null,this.rootNode=null}scheduleUpdate(){this.updateLoop.schedule()}update(){this.rootNode&&this.savedTree&&(this.currentTree=this.mountOrchestrator.update(this.rootNode,this.savedTree,this.stateManager,this.currentTree))}getStore(){return this.stateManager.getStore()}setStore(e,t){this.stateManager.setStore(e,t)}}exports.App=m,exports.EventManager=u,exports.LifecycleQueue=a,exports.Renderer=r,exports.StateManager=o,exports.component=function(e){let t=void 0===e?{}:e,i=t.name,o=void 0===i?"":i,r=t.state,h=void 0===r?{}:r,d=t.mounted,c=void 0===d?function(){}:d,u=t.updated,a=void 0===u?function(){}:u,l=t.unmounted,f=void 0===l?function(){}:l,p=t.methods,y=void 0===p?function(){}:p,m=t.render,_=void 0===m?function(){}:m;const g=n(),v=new Map;return function(e){void 0===e&&(e={});const t=e.key||"__default__";if(!v.has(t)){const i=n(),r=o+(e.key?"_"+e.key:"");v.set(t,{definitionId:g,instanceId:i,key:`${g}_${i}_${r}`,_props:null,_cachedRender:null,bind(e){const t=new s(g,i,r,this._props,{state:h,mounted:c,updated:a,unmounted:f,methods:y,render:_},e);return t.bindMethods(y),t}})}const i=v.get(t);return i._props=e,i}},exports.createApp=function(e,t,n){const s=new m(e,n);return s.mount(t),s},exports.flatten=t,exports.generateTree=l,exports.generateUUID=n,exports.h=function(n,s){const i={};for(let e in s)i[e]=s[e];return new e(n,i,t([],[].slice.call(arguments,2)))},exports.isVNode=function(t){return t instanceof e||null!==t&&"object"==typeof t&&"e"in t},exports.render=function(e,t,n){void 0===n&&(n={});const s=new m(e,n);return s.mount(t),s};
package/build/index.m.js CHANGED
@@ -1,2 +1 @@
1
- var t,e,n,i={},o={},r=[],u={},d=[],f=["abort","blur","error","focus","load","mouseenter","mouseleave","resize","scroll","unload"];function c(t){return Array.isArray(t)}function s(){return Math.random().toString(36).substring(2)+(new Date).getTime().toString(36)}function a(t,e){for(var n=0,i=e.length;n<i;n++)c(e[n])?a(t,e[n]):t.push(e[n]);return t}function h(t,e){for(var n in e)t[n]=e[n];return t}function v(t,e,n){return h(h(t,e),n)}function l(t,e){return{e:t,a:h({},e),c:a([],[].slice.call(arguments,2))}}function y(o,r,u){void 0===u&&(u={}),i=h({},u),e=o,t=document.getElementById(r),n=j(o()),C(t,n),J()}function p(t){var e=void 0===t?{}:t,n=e.name,r=void 0===n?"":n,u=e.state,d=void 0===u?{}:u,f=e.mounted,c=void 0===f?function(){}:f,a=e.updated,h=void 0===a?function(){}:a,v=e.unmounted,l=void 0===v?function(){}:v,y=e.methods,p=void 0===y?function(){}:y,j=e.render,S=void 0===j?function(){}:j,N=s();return function(t){return void 0===t&&(t={}),{id:N,init:function(){return this.id=N,this.name=r+(t.key?"_"+t.key:""),this.key=this.id+(this.name||""),this.props=t,this.store=i,this.getStore=b,this.setStore=m.bind(this),this.getState=g.bind(this),this.setState=k.bind(this),this.createState=function(){void 0===o[this.key]&&(o[this.key]=d)}.bind(this)(),this.deleteState=function(){delete o[this.key]}.bind(this),this.mounted=c.bind(this),this.updated=h.bind(this),this.unmounted=l.bind(this),function(t,e){for(var n in"function"==typeof e&&(e=e.bind(t)()),e)t[n]=e[n].bind(t)}(this,p),this.render=S.bind(this),this}}}}function b(){return h({},i)}function m(t,e){"function"==typeof t&&(t=t(i)),i=v({},i,t),E(),"function"==typeof e&&e.bind(this)()}function g(){return h({},o[this.key])}function k(t,e){"function"==typeof t&&(t=t(o[this.key])),o[this.key]=v({},o[this.key],t),E(),"function"==typeof e&&e.bind(this)()}function j(t){if(void 0===t)return t;if("function"==typeof t.e){var e=h({},t.a.props);delete t.a.props,t=t.e(e)}if("function"==typeof t.init){var n=new t.init;"object"==typeof(t=n.render())&&(t.id=n.id,t.m=n.mounted,t.up=n.updated,t.un=n.unmounted,t.d=n.deleteState)}if(c(t.c))for(var i=0,o=t.c.length;i<o;i++)t.c[i]=j(t.c[i]);return t}function S(t){var e=typeof t;if("string"===e||"number"===e)return document.createTextNode(t);if("boolean"===e||"undefined"===e)return document.createTextNode("");var n=document.createElement(t.e);if("object"==typeof t.a)for(var i=Object.keys(t.a),o=i.length;o--;)"events"===i[o]?(t.eid=s(),A(t.eid,t.a[i[o]],n)):"style"===i[o]?O(t.a[i[o]],n):n.setAttribute(i[o],t.a[i[o]]);if(z(t,"m"),c(t.c))for(var r=0,u=t.c.length;r<u;r++)C(n,t.c[r]);return n}function N(t){if("#document"!==t.parentNode.nodeName){var e=t.getAttribute("data-eid");return"string"==typeof e?e:N(t.parentNode)}}function A(e,n,i){i.setAttribute("data-eid",e),u[e]=n;for(var o=Object.keys(n),d=o.length;d--;)f.includes(o[d])?i.addEventListener(o[d],u[e][o[d]]):r.includes(o[d])||(r.push(o[d]),t.addEventListener(o[d],function(t){var e=N(t.target);if("string"==typeof e&&u[e]){var n=u[e][t.type];"function"==typeof n&&n(t)}}))}function O(t,e){if(void 0!==t)for(var n=Object.keys(t),i=n.length;i--;)e.style[n[i]]=t[n[i]]}function E(i){var o=h({},n),r=j(e());n=r,x(t,t.firstChild,r,o),J()}function x(t,e,n,i){var o=typeof n,r=typeof i;if("undefined"===r)C(t,n);else if("undefined"===o)L(i),e.remove();else if(function(t,e,n,i){return n!==i||t.e!==e.e||t.id!==e.id||("string"===n||"number"===n)&&t!==e}(n,i,o,r))L(i),t.replaceChild(S(n),e);else if("object"===o){var u;!function(t,e,n){z(e,"up");for(var i,o,r=Object.keys(e.a),u=r.length;u--;)if(o=e.a[r[u]],i=n.a[r[u]],"style"===r[u]){if(void 0,void 0,a=typeof(f=i),"object"==(c=typeof(d=o))&&"object"===a&&JSON.stringify(d)===JSON.stringify(f)||"undefined"===c&&"undefined"===a)continue;t.removeAttribute(r[u]),O(o,t)}else"events"===r[u]?(w(t,n.eid),T(n.eid),e.eid=s(),A(e.eid,o,t)):"value"===r[u]&&o!==i?t.value=o:void 0!==i&&o===i||t.setAttribute(r[u],o);var d,f,c,a}(e,n,i);for(var d=i.c.length;d--&&void 0===n.c[d];)"object"==typeof(u=e.lastChild)&&(L(i.c[d]),u.remove());for(var f=0,c=n.c.length;f<c;f++)x(e,e.childNodes[f],n.c[f],i.c[f])}}function C(t,e){t.appendChild(S(e))}function L(t){if(void 0!==t&&(z(t,"un"),z(t,"d"),T(t.eid),c(t.c)))for(var e=t.c.length;e--;)L(t.c[e])}function T(t){"string"==typeof t&&delete u[t]}function w(t,e){for(var n=Object.keys(u[e]),i=n.length;i--;)f.includes(n[i])&&t.removeEventListener(n[i],u[e][n[i]])}function J(){for(var t;t=d.shift();)t()}function z(t,e){"object"==typeof t&&"function"==typeof t[e]&&d.push(t[e])}module.exports={component:p,render:y,h:l};export{p as component,l as h,y as render};
2
- //# sourceMappingURL=index.m.js.map
1
+ class e{constructor(e,t,n){void 0===t&&(t={}),void 0===n&&(n=[]),this.e=e,this.a=t,this.c=n}withLifecycle(e){return e.mounted&&(this.m=e.mounted),e.updated&&(this.up=e.updated),e.unmounted&&(this.un=e.unmounted),e.deleteState&&(this.d=e.deleteState),this}withIdentity(e,t){return this.definitionId=e,this.instanceId=t,this.id=e+"_"+t,this}}function t(e,n){for(let s=0,i=n.length;s<i;s++)Array.isArray(n[s])?t(e,n[s]):e.push(n[s]);return e}function n(n,s){const i={};for(let e in s)i[e]=s[e];return new e(n,i,t([],[].slice.call(arguments,2)))}function s(t){return t instanceof e||null!==t&&"object"==typeof t&&"e"in t}function i(){return Math.random().toString(36).substring(2)+(new Date).getTime().toString(36)}class o{constructor(e,t,n,s,i,o){this.definitionId=e,this.instanceId=t,this.name=n,this.key=`${e}_${t}_${n}`,this.props=s,this._stateManager=o,this._config=i,o.createState(this.key,i.state),this.mounted=i.mounted.bind(this),this.updated=i.updated.bind(this),this.unmounted=i.unmounted.bind(this),this.deleteState=()=>{this._stateManager.deleteState(this.key)},this._renderedVNode=null,this._previousProps=null;const r=i.render.bind(this);this.render=()=>{if(!this.shouldUpdate())return this._renderedVNode;const e=r();return this._renderedVNode=e,this._previousProps=this.props,e}}getStore(){return this._stateManager.getStore()}setStore(e,t){this._stateManager.setStore(e,t)}getState(){return this._stateManager.getState(this.key)}setState(e,t){this._stateManager.setState(this.key,e,t)}createState(){this._stateManager.createState(this.key,this._config.state)}deleteState(){this._stateManager.deleteState(this.key)}shouldUpdate(){return!this._previousProps||!function(e,t){if(e===t)return!0;if(!e||!t||"object"!=typeof e||"object"!=typeof t)return!1;const n=Object.keys(e),s=Object.keys(t);if(n.length!==s.length)return!1;for(let s=0;s<n.length;s++)if(e[n[s]]!==t[n[s]])return!1;return!0}(this.props,this._previousProps)}bindMethods(e){"function"==typeof e&&(e=e.bind(this)());for(let t in e)this[t]=e[t].bind(this)}}function r(e){let t=void 0===e?{}:e,n=t.name,s=void 0===n?"":n,r=t.state,h=void 0===r?{}:r,d=t.mounted,c=void 0===d?function(){}:d,u=t.updated,a=void 0===u?function(){}:u,l=t.unmounted,f=void 0===l?function(){}:l,p=t.methods,y=void 0===p?function(){}:p,m=t.render,_=void 0===m?function(){}:m;const g=i(),v=new Map;return function(e){void 0===e&&(e={});const t=e.key||"__default__";if(!v.has(t)){const n=i(),r=s+(e.key?"_"+e.key:"");v.set(t,{definitionId:g,instanceId:n,key:`${g}_${n}_${r}`,_props:null,_cachedRender:null,bind(e){const t=new o(g,n,r,this._props,{state:h,mounted:c,updated:a,unmounted:f,methods:y,render:_},e);return t.bindMethods(y),t}})}const n=v.get(t);return n._props=e,n}}function h(e,t){for(let n in t)e[n]=t[n];return e}class d{constructor(e){void 0===e&&(e={}),this.store={...e},this.componentStates={},this.listeners=[]}subscribe(e){this.listeners.push(e)}unsubscribe(e){const t=this.listeners.indexOf(e);t>-1&&this.listeners.splice(t,1)}_notify(){for(let e=0;e<this.listeners.length;e++)this.listeners[e]()}getStore(){return{...this.store}}setStore(e,t){"function"==typeof e&&(e=e(this.store)),this.store=h(h({},this.store),e),this._notify(),"function"==typeof t&&t()}createState(e,t){e in this.componentStates||(this.componentStates[e]={...t})}getState(e){return{...this.componentStates[e]}}setState(e,t,n){"function"==typeof t&&(t=t(this.componentStates[e])),this.componentStates[e]=h(h({},this.componentStates[e]),t),this._notify(),"function"==typeof n&&n()}deleteState(e){delete this.componentStates[e]}reset(){this.store={},this.componentStates={},this.listeners=[]}}class c{constructor(e,t,n){this.eventManager=e,this.lifecycleQueue=t,this.diffEngine=n}mount(e,t){const n=this.createElement(t);n&&e.appendChild(n)}createElement(e){const t=typeof e;return"string"===t||"number"===t?document.createTextNode(e):"boolean"===t||"undefined"===t?document.createTextNode(""):"object"===t&&e.e?this._createElementNode(e):null}_createElementNode(e){const t=document.createElement(e.e);if("object"==typeof e.a){const n=Object.keys(e.a);for(let s=n.length;s--;)if("events"===n[s])e.eid=this.eventManager.bindEvents(t,e.a[n[s]]);else if("style"===n[s])this._addStyles(e.a[n[s]],t);else{if("key"===n[s])continue;t.setAttribute(n[s],e.a[n[s]])}}if(this.lifecycleQueue.mounted(e),Array.isArray(e.c))for(let n=0,s=e.c.length;n<s;n++){const s=this.createElement(e.c[n]);s&&t.appendChild(s)}return t}_addStyles(e,t){if(void 0===e)return;const n=Object.keys(e);for(let s=n.length;s--;)t.style[n[s]]=e[n[s]]}patch(e,t,n,s){const i=typeof n;if(void 0===s)this._appendChild(e,n);else if("undefined"===i)this._unmountNodeAndChildren(s),t&&t.remove();else if(this.diffEngine.areNodesEqual(n,s)){if("object"===i&&n.e){if(n===s)return;if(this._updateNodes(t,n,s),n.c!==s.c)if(this.diffEngine._hasKeys(n.c)||this.diffEngine._hasKeys(s.c))this.diffEngine.reconcileChildren(t,n.c,s.c,this);else{let e;for(let i=s.c?s.c.length:0;i--&&void 0===n.c[i];)e=t.lastChild,e&&(this._unmountNodeAndChildren(s.c[i]),e.remove());if(Array.isArray(n.c))for(let e=0,i=n.c.length;e<i;e++)this.patch(t,t.childNodes[e]||null,n.c[e],s.c?s.c[e]:void 0)}}}else if(!t||3!==t.nodeType||"string"!==i&&"number"!==i)this._unmountNodeAndChildren(s),t&&e.replaceChild(this.createElement(n),t);else{const e=String(n);t.textContent!==e&&(t.textContent=e)}}_appendChild(e,t){const n=this.createElement(t);n&&e.appendChild(n)}_updateNodes(e,t,n){if(this.lifecycleQueue.updated(t),t.a===n.a)return;if(!t.a||!n.a)return;const s=Object.keys(t.a);let i,o;for(let r=s.length;r--;)if(o=t.a[s[r]],i=n.a[s[r]],"style"===s[r]){if(this._stylesAreEqual(o,i))continue;e.removeAttribute(s[r]),this._addStyles(o,e)}else if("events"===s[r])this.eventManager.unbindEvents(e,n.eid),t.eid=this.eventManager.bindEvents(e,o);else{if("key"===s[r])continue;"value"===s[r]&&o!==i?e.value=o:void 0!==i&&o===i||e.setAttribute(s[r],o)}}_stylesAreEqual(e,t){if(e===t)return!0;const n=typeof e,s=typeof t;if("undefined"===n&&"undefined"===s)return!0;if("object"!==n||"object"!==s)return!1;const i=Object.keys(e),o=Object.keys(t);if(i.length!==o.length)return!1;for(let n=i.length;n--;)if(e[i[n]]!==t[i[n]])return!1;return!0}_unmountNodeAndChildren(e){if(null!=e&&(this.lifecycleQueue.unmounted(e),this.lifecycleQueue.deleteState(e),this.eventManager.deleteCachedEvent(e.eid),Array.isArray(e.c)))for(let t=e.c.length;t--;)this._unmountNodeAndChildren(e.c[t])}unmount(e,t){this._unmountNodeAndChildren(t),e&&(e.innerHTML="")}}class u{constructor(e,t,n){this._getCache=e,this._resolveUUID=t,this._elementToUUID=n,this._attachedTypes=new Set,this._rootNode=null}attach(e,t){this._attachedTypes.has(t)||(this._attachedTypes.add(t),this._rootNode=e,e._literaljs_hasEvents=!0,e.addEventListener(t,e=>this._handle(e)))}_handle(e){if(!this._rootNode||!this._rootNode._literaljs_hasEvents)return;let t=e.target;for(;t&&t!==this._rootNode;){let n;if(this._elementToUUID&&(n=this._elementToUUID.get(t))){const t=this._getCache(n);if(t&&"function"==typeof t[e.type])return void t[e.type](e)}const s=this._resolveUUID(t);if("string"==typeof s){const t=this._getCache(s);if(t&&"function"==typeof t[e.type])return void t[e.type](e)}t=t.parentNode}}reset(){this._attachedTypes.clear()}}const a=["abort","blur","error","focus","load","mouseenter","mouseleave","resize","scroll","unload"],l="eid";class f{constructor(){this.cache={},this.rootNode=null,this._elementToUUID=new WeakMap,this.eventBus=new u(e=>this.cache[e],e=>this.getEventUUID(e),this._elementToUUID)}setRootNode(e){this.rootNode=e}getEventUUID(e){if(!e||!e.parentNode)return;if("#document"===e.parentNode.nodeName)return;const t=e.getAttribute("data-"+l);return"string"==typeof t?t:this.getEventUUID(e.parentNode)}bindEvents(e,t){const n=i();e.setAttribute("data-"+l,n),this.cache[n]=t,this._elementToUUID.set(e,n);const s=Object.keys(t);for(let t=s.length;t--;)a.includes(s[t])?e.addEventListener(s[t],this.cache[n][s[t]]):this.eventBus.attach(this.rootNode,s[t]);return n}unbindEvents(e,t){if(!this.cache[t])return;const n=Object.keys(this.cache[t]);for(let s=n.length;s--;)a.includes(n[s])&&e.removeEventListener(n[s],this.cache[t][n[s]]);this.deleteCachedEvent(t),this._elementToUUID.delete(e),e.removeAttribute("data-"+l)}addEvents(e,t,n){n.setAttribute("data-"+l,e),this.cache[e]=t,this._elementToUUID.set(n,e);const s=Object.keys(t);for(let t=s.length;t--;)a.includes(s[t])?n.addEventListener(s[t],this.cache[e][s[t]]):this.eventBus.attach(this.rootNode,s[t])}removeIndividualEvents(e,t){if(!this.cache[t])return;const n=Object.keys(this.cache[t]);for(let s=n.length;s--;)a.includes(n[s])&&e.removeEventListener(n[s],this.cache[t][n[s]])}deleteCachedEvent(e){"string"==typeof e&&delete this.cache[e]}destroy(){this.rootNode&&(this.rootNode._literaljs_hasEvents=!1),this.cache={},this.rootNode=null,this.eventBus.reset()}}class p{constructor(){this.queue=[]}mounted(e){"object"==typeof e&&"function"==typeof e.m&&this.queue.push(e.m)}updated(e){"object"==typeof e&&"function"==typeof e.up&&this.queue.push(e.up)}unmounted(e){"object"==typeof e&&"function"==typeof e.un&&this.queue.push(e.un)}deleteState(e){"object"==typeof e&&"function"==typeof e.d&&this.queue.push(e.d)}flush(){let e;for(;e=this.queue.shift();)e()}clear(){this.queue=[]}}function y(t,n){if(null==t)return t;if("function"==typeof t.e){const e={...t.a.props};delete(t={e:t.e,a:{...t.a},c:t.c}).a.props,t=t.e(e)}if(t&&"function"==typeof t.bind){const s=t.bind(n);let i;try{i=s.render()}catch(e){console.error("Component render error:",e),i={e:"div",a:{class:"error-boundary"},c:[`${e.name}: ${e.message}`]}}if("object"==typeof i&&null!==i&&i instanceof e)i.withIdentity(t.definitionId||s.definitionId,t.instanceId||s.instanceId),i.withLifecycle({mounted:s.mounted,updated:s.updated,unmounted:s.unmounted,deleteState:s.deleteState}),t=i;else if("object"==typeof i&&null!==i){const n=new e(i.e,i.a,i.c);n.withIdentity(t.definitionId||s.definitionId,t.instanceId||s.instanceId),n.withLifecycle({mounted:s.mounted,updated:s.updated,unmounted:s.unmounted,deleteState:s.deleteState}),t=n}else t=i}if(t&&Array.isArray(t.c))for(let e=0,s=t.c.length;e<s;e++)t.c[e]=y(t.c[e],n);return t}class m{areNodesEqual(e,t){const n=typeof e;return n===typeof t&&("object"===n&&e.e===t.e&&e.id===t.id||("string"===n||"number"===n)&&e===t)}reconcileChildren(e,t,n,s){return Array.isArray(t)?this._hasKeys(t)||this._hasKeys(n)?this._reconcileKeyed(e,t,n,s):this._reconcileNonKeyed(e,t,n,s):0}_reconcileNonKeyed(e,t,n,s){const i=t.length;if(0===i){if(n)for(let e=0;e<n.length;e++)s._unmountNodeAndChildren(n[e]);return e.innerHTML="",0}const o=e.childNodes;for(let r=0;r<i;r++)s.patch(e,o[r]||null,t[r],n?n[r]:void 0);return i}_hasKeys(e){if(!Array.isArray(e))return!1;for(let t=0,n=e.length;t<n;t++)if(e[t]&&e[t].a&&null!=e[t].a.key)return!0;return!1}_reconcileKeyed(e,t,n,s){const i=n?n.length:0,o=t.length;if(0===o){for(let e=0;e<i;e++)s._unmountNodeAndChildren(n[e]);return e.innerHTML="",0}const r=Object.create(null),h=Object.create(null);for(let t=0;t<i;t++){const s=n[t].a?n[t].a.key:null,i=e.childNodes[t];null!=s&&i&&(r[s]=i,h[s]=n[t])}const d=new Array(o),c=new Array(o);for(let e=0;e<o;e++){const n=t[e].a?t[e].a.key:null;null!=n&&r[n]?(d[e]=r[n],c[e]=h[n],delete r[n]):(d[e]=null,c[e]=null)}for(const t in r){const n=r[t];n&&(s.patch(e,n,void 0,h[t]),n.remove())}let u=e.firstChild;for(let n=0;n<o;n++){const i=d[n];if(i&&i===u)u=u.nextSibling;else if(i)e.insertBefore(i,u);else{const i=s.createElement(t[n]);i&&e.insertBefore(i,u)}}for(;u;){const e=u.nextSibling;u.remove(),u=e}for(let n=0;n<o;n++)c[n]&&s.patch(e,e.childNodes[n],t[n],c[n]);return o}removeExtraChildren(e,t,n,s){const i=t.c?t.c.length:0;if(!(i<=n))for(let o=i;o-- >n;){const n=e.lastChild;n&&(s._unmountNodeAndChildren(t.c[o]),n.remove())}}}class _{constructor(e,t,n){this.generateTree=e||y,this.renderer=t,this.lifecycleQueue=n}mount(e,t,n){const s=this.generateTree(t(),n);return this.renderer.mount(e,s),this.lifecycleQueue.flush(),s}update(e,t,n,s){const i=this.generateTree(t(),n);return this.renderer.patch(e,e.firstChild,i,s),this.lifecycleQueue.flush(),i}unmount(e,t){t&&(this.renderer.unmount(e,t),this.lifecycleQueue.flush())}}class g{constructor(e,t){void 0===t&&(t="microtask"),this._renderFn=e,this._scheduler=t,this._scheduled=!1}schedule(){this._scheduled||(this._scheduled=!0,"microtask"===this._scheduler?Promise.resolve().then(()=>this._execute()):"sync"===this._scheduler&&this._execute())}_execute(){this._scheduled=!1,this._renderFn()}}class v{constructor(e,t){void 0===t&&(t={}),this.rootComponent=e,this.savedTree=e,this.currentTree=null,this.rootNode=null,this.stateManager=new d(t),this.lifecycleQueue=new p,this.eventManager=new f,this.renderer=new c(this.eventManager,this.lifecycleQueue,new m),this.mountOrchestrator=new _(y,this.renderer,this.lifecycleQueue),this.updateLoop=new g(()=>this.update(),"microtask"),this._boundSchedule=()=>this.updateLoop.schedule(),this.stateManager.subscribe(this._boundSchedule)}mount(e){if(this.rootNode=document.getElementById(e),!this.rootNode)throw new Error(`Cannot mount app: element with id "${e}" not found`);return this.eventManager.setRootNode(this.rootNode),this.currentTree=this.mountOrchestrator.mount(this.rootNode,this.savedTree,this.stateManager),this}unmount(){this.mountOrchestrator.unmount(this.rootNode,this.currentTree),this.eventManager.destroy(),this.stateManager.unsubscribe(()=>this.updateLoop.schedule()),this.rootNode&&(this.rootNode.innerHTML=""),this.currentTree=null,this.rootNode=null}scheduleUpdate(){this.updateLoop.schedule()}update(){this.rootNode&&this.savedTree&&(this.currentTree=this.mountOrchestrator.update(this.rootNode,this.savedTree,this.stateManager,this.currentTree))}getStore(){return this.stateManager.getStore()}setStore(e,t){this.stateManager.setStore(e,t)}}function b(e,t,n){const s=new v(e,n);return s.mount(t),s}function N(e,t,n){void 0===n&&(n={});const s=new v(e,n);return s.mount(t),s}export{v as App,f as EventManager,p as LifecycleQueue,c as Renderer,d as StateManager,r as component,b as createApp,t as flatten,y as generateTree,i as generateUUID,n as h,s as isVNode,N as render};
@@ -0,0 +1 @@
1
+ class e{constructor(e,t={},n=[]){this.e=e,this.a=t,this.c=n}withLifecycle(e){return e.mounted&&(this.m=e.mounted),e.updated&&(this.up=e.updated),e.unmounted&&(this.un=e.unmounted),e.deleteState&&(this.d=e.deleteState),this}withIdentity(e,t){return this.definitionId=e,this.instanceId=t,this.id=e+"_"+t,this}}function t(e,n){for(let s=0,i=n.length;s<i;s++)Array.isArray(n[s])?t(e,n[s]):e.push(n[s]);return e}function n(n,s,...i){const r={};for(let e in s)r[e]=s[e];return new e(n,r,t([],i))}function s(t){return t instanceof e||null!==t&&"object"==typeof t&&"e"in t}function i(){return Math.random().toString(36).substring(2)+(new Date).getTime().toString(36)}class r{constructor(e,t,n,s,i,r){this.definitionId=e,this.instanceId=t,this.name=n,this.key=`${e}_${t}_${n}`,this.props=s,this._stateManager=r,this._config=i,r.createState(this.key,i.state),this.mounted=i.mounted.bind(this),this.updated=i.updated.bind(this),this.unmounted=i.unmounted.bind(this),this.deleteState=()=>{this._stateManager.deleteState(this.key)},this._renderedVNode=null,this._previousProps=null;const o=i.render.bind(this);this.render=()=>{if(!this.shouldUpdate())return this._renderedVNode;const e=o();return this._renderedVNode=e,this._previousProps=this.props,e}}getStore(){return this._stateManager.getStore()}setStore(e,t){this._stateManager.setStore(e,t)}getState(){return this._stateManager.getState(this.key)}setState(e,t){this._stateManager.setState(this.key,e,t)}createState(){this._stateManager.createState(this.key,this._config.state)}deleteState(){this._stateManager.deleteState(this.key)}shouldUpdate(){return!this._previousProps||!function(e,t){if(e===t)return!0;if(!e||!t||"object"!=typeof e||"object"!=typeof t)return!1;const n=Object.keys(e),s=Object.keys(t);if(n.length!==s.length)return!1;for(let s=0;s<n.length;s++)if(e[n[s]]!==t[n[s]])return!1;return!0}(this.props,this._previousProps)}bindMethods(e){"function"==typeof e&&(e=e.bind(this)());for(let t in e)this[t]=e[t].bind(this)}}function o({name:e="",state:t={},mounted:n=function(){},updated:s=function(){},unmounted:o=function(){},methods:h=function(){},render:c=function(){}}={}){const u=i(),d=new Map;return function(a={}){const l=a.key||"__default__";if(!d.has(l)){const f=i(),p=e+(a.key?"_"+a.key:"");d.set(l,{definitionId:u,instanceId:f,key:`${u}_${f}_${p}`,_props:null,_cachedRender:null,bind(e){const i=new r(u,f,p,this._props,{state:t,mounted:n,updated:s,unmounted:o,methods:h,render:c},e);return i.bindMethods(h),i}})}const f=d.get(l);return f._props=a,f}}function h(){return h=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var s in n)({}).hasOwnProperty.call(n,s)&&(e[s]=n[s])}return e},h.apply(null,arguments)}function c(e,t){for(let n in t)e[n]=t[n];return e}class u{constructor(e={}){this.store=h({},e),this.componentStates={},this.listeners=[]}subscribe(e){this.listeners.push(e)}unsubscribe(e){const t=this.listeners.indexOf(e);t>-1&&this.listeners.splice(t,1)}_notify(){for(let e=0;e<this.listeners.length;e++)this.listeners[e]()}getStore(){return h({},this.store)}setStore(e,t){"function"==typeof e&&(e=e(this.store)),this.store=c(c({},this.store),e),this._notify(),"function"==typeof t&&t()}createState(e,t){e in this.componentStates||(this.componentStates[e]=h({},t))}getState(e){return h({},this.componentStates[e])}setState(e,t,n){"function"==typeof t&&(t=t(this.componentStates[e])),this.componentStates[e]=c(c({},this.componentStates[e]),t),this._notify(),"function"==typeof n&&n()}deleteState(e){delete this.componentStates[e]}reset(){this.store={},this.componentStates={},this.listeners=[]}}class d{constructor(e,t,n){this.eventManager=e,this.lifecycleQueue=t,this.diffEngine=n}mount(e,t){const n=this.createElement(t);n&&e.appendChild(n)}createElement(e){const t=typeof e;return"string"===t||"number"===t?document.createTextNode(e):"boolean"===t||"undefined"===t?document.createTextNode(""):"object"===t&&e.e?this._createElementNode(e):null}_createElementNode(e){const t=document.createElement(e.e);if("object"==typeof e.a){const n=Object.keys(e.a);for(let s=n.length;s--;)if("events"===n[s])e.eid=this.eventManager.bindEvents(t,e.a[n[s]]);else if("style"===n[s])this._addStyles(e.a[n[s]],t);else{if("key"===n[s])continue;t.setAttribute(n[s],e.a[n[s]])}}if(this.lifecycleQueue.mounted(e),Array.isArray(e.c))for(let n=0,s=e.c.length;n<s;n++){const s=this.createElement(e.c[n]);s&&t.appendChild(s)}return t}_addStyles(e,t){if(void 0===e)return;const n=Object.keys(e);for(let s=n.length;s--;)t.style[n[s]]=e[n[s]]}patch(e,t,n,s){const i=typeof n;if(void 0===s)this._appendChild(e,n);else if("undefined"===i)this._unmountNodeAndChildren(s),t&&t.remove();else if(this.diffEngine.areNodesEqual(n,s)){if("object"===i&&n.e){if(n===s)return;if(this._updateNodes(t,n,s),n.c!==s.c)if(this.diffEngine._hasKeys(n.c)||this.diffEngine._hasKeys(s.c))this.diffEngine.reconcileChildren(t,n.c,s.c,this);else{let e;for(let i=s.c?s.c.length:0;i--&&void 0===n.c[i];)e=t.lastChild,e&&(this._unmountNodeAndChildren(s.c[i]),e.remove());if(Array.isArray(n.c))for(let e=0,i=n.c.length;e<i;e++)this.patch(t,t.childNodes[e]||null,n.c[e],s.c?s.c[e]:void 0)}}}else if(!t||3!==t.nodeType||"string"!==i&&"number"!==i)this._unmountNodeAndChildren(s),t&&e.replaceChild(this.createElement(n),t);else{const e=String(n);t.textContent!==e&&(t.textContent=e)}}_appendChild(e,t){const n=this.createElement(t);n&&e.appendChild(n)}_updateNodes(e,t,n){if(this.lifecycleQueue.updated(t),t.a===n.a)return;if(!t.a||!n.a)return;const s=Object.keys(t.a);let i,r;for(let o=s.length;o--;)if(r=t.a[s[o]],i=n.a[s[o]],"style"===s[o]){if(this._stylesAreEqual(r,i))continue;e.removeAttribute(s[o]),this._addStyles(r,e)}else if("events"===s[o])this.eventManager.unbindEvents(e,n.eid),t.eid=this.eventManager.bindEvents(e,r);else{if("key"===s[o])continue;"value"===s[o]&&r!==i?e.value=r:void 0!==i&&r===i||e.setAttribute(s[o],r)}}_stylesAreEqual(e,t){if(e===t)return!0;const n=typeof e,s=typeof t;if("undefined"===n&&"undefined"===s)return!0;if("object"!==n||"object"!==s)return!1;const i=Object.keys(e),r=Object.keys(t);if(i.length!==r.length)return!1;for(let n=i.length;n--;)if(e[i[n]]!==t[i[n]])return!1;return!0}_unmountNodeAndChildren(e){if(null!=e&&(this.lifecycleQueue.unmounted(e),this.lifecycleQueue.deleteState(e),this.eventManager.deleteCachedEvent(e.eid),Array.isArray(e.c)))for(let t=e.c.length;t--;)this._unmountNodeAndChildren(e.c[t])}unmount(e,t){this._unmountNodeAndChildren(t),e&&(e.innerHTML="")}}class a{constructor(e,t,n){this._getCache=e,this._resolveUUID=t,this._elementToUUID=n,this._attachedTypes=new Set,this._rootNode=null}attach(e,t){this._attachedTypes.has(t)||(this._attachedTypes.add(t),this._rootNode=e,e._literaljs_hasEvents=!0,e.addEventListener(t,e=>this._handle(e)))}_handle(e){if(!this._rootNode||!this._rootNode._literaljs_hasEvents)return;let t=e.target;for(;t&&t!==this._rootNode;){let n;if(this._elementToUUID&&(n=this._elementToUUID.get(t))){const t=this._getCache(n);if(t&&"function"==typeof t[e.type])return void t[e.type](e)}const s=this._resolveUUID(t);if("string"==typeof s){const t=this._getCache(s);if(t&&"function"==typeof t[e.type])return void t[e.type](e)}t=t.parentNode}}reset(){this._attachedTypes.clear()}}const l=["abort","blur","error","focus","load","mouseenter","mouseleave","resize","scroll","unload"],f="eid";class p{constructor(){this.cache={},this.rootNode=null,this._elementToUUID=new WeakMap,this.eventBus=new a(e=>this.cache[e],e=>this.getEventUUID(e),this._elementToUUID)}setRootNode(e){this.rootNode=e}getEventUUID(e){if(!e||!e.parentNode)return;if("#document"===e.parentNode.nodeName)return;const t=e.getAttribute("data-"+f);return"string"==typeof t?t:this.getEventUUID(e.parentNode)}bindEvents(e,t){const n=i();e.setAttribute("data-"+f,n),this.cache[n]=t,this._elementToUUID.set(e,n);const s=Object.keys(t);for(let t=s.length;t--;)l.includes(s[t])?e.addEventListener(s[t],this.cache[n][s[t]]):this.eventBus.attach(this.rootNode,s[t]);return n}unbindEvents(e,t){if(!this.cache[t])return;const n=Object.keys(this.cache[t]);for(let s=n.length;s--;)l.includes(n[s])&&e.removeEventListener(n[s],this.cache[t][n[s]]);this.deleteCachedEvent(t),this._elementToUUID.delete(e),e.removeAttribute("data-"+f)}addEvents(e,t,n){n.setAttribute("data-"+f,e),this.cache[e]=t,this._elementToUUID.set(n,e);const s=Object.keys(t);for(let t=s.length;t--;)l.includes(s[t])?n.addEventListener(s[t],this.cache[e][s[t]]):this.eventBus.attach(this.rootNode,s[t])}removeIndividualEvents(e,t){if(!this.cache[t])return;const n=Object.keys(this.cache[t]);for(let s=n.length;s--;)l.includes(n[s])&&e.removeEventListener(n[s],this.cache[t][n[s]])}deleteCachedEvent(e){"string"==typeof e&&delete this.cache[e]}destroy(){this.rootNode&&(this.rootNode._literaljs_hasEvents=!1),this.cache={},this.rootNode=null,this.eventBus.reset()}}class y{constructor(){this.queue=[]}mounted(e){"object"==typeof e&&"function"==typeof e.m&&this.queue.push(e.m)}updated(e){"object"==typeof e&&"function"==typeof e.up&&this.queue.push(e.up)}unmounted(e){"object"==typeof e&&"function"==typeof e.un&&this.queue.push(e.un)}deleteState(e){"object"==typeof e&&"function"==typeof e.d&&this.queue.push(e.d)}flush(){let e;for(;e=this.queue.shift();)e()}clear(){this.queue=[]}}function m(t,n){if(null==t)return t;if("function"==typeof t.e){const e=h({},t.a.props);delete(t={e:t.e,a:h({},t.a),c:t.c}).a.props,t=t.e(e)}if(t&&"function"==typeof t.bind){const s=t.bind(n);let i;try{i=s.render()}catch(e){console.error("Component render error:",e),i={e:"div",a:{class:"error-boundary"},c:[`${e.name}: ${e.message}`]}}if("object"==typeof i&&null!==i&&i instanceof e)i.withIdentity(t.definitionId||s.definitionId,t.instanceId||s.instanceId),i.withLifecycle({mounted:s.mounted,updated:s.updated,unmounted:s.unmounted,deleteState:s.deleteState}),t=i;else if("object"==typeof i&&null!==i){const n=new e(i.e,i.a,i.c);n.withIdentity(t.definitionId||s.definitionId,t.instanceId||s.instanceId),n.withLifecycle({mounted:s.mounted,updated:s.updated,unmounted:s.unmounted,deleteState:s.deleteState}),t=n}else t=i}if(t&&Array.isArray(t.c))for(let e=0,s=t.c.length;e<s;e++)t.c[e]=m(t.c[e],n);return t}class _{areNodesEqual(e,t){const n=typeof e;return n===typeof t&&("object"===n&&e.e===t.e&&e.id===t.id||("string"===n||"number"===n)&&e===t)}reconcileChildren(e,t,n,s){return Array.isArray(t)?this._hasKeys(t)||this._hasKeys(n)?this._reconcileKeyed(e,t,n,s):this._reconcileNonKeyed(e,t,n,s):0}_reconcileNonKeyed(e,t,n,s){const i=t.length;if(0===i){if(n)for(let e=0;e<n.length;e++)s._unmountNodeAndChildren(n[e]);return e.innerHTML="",0}const r=e.childNodes;for(let o=0;o<i;o++)s.patch(e,r[o]||null,t[o],n?n[o]:void 0);return i}_hasKeys(e){if(!Array.isArray(e))return!1;for(let t=0,n=e.length;t<n;t++)if(e[t]&&e[t].a&&null!=e[t].a.key)return!0;return!1}_reconcileKeyed(e,t,n,s){const i=n?n.length:0,r=t.length;if(0===r){for(let e=0;e<i;e++)s._unmountNodeAndChildren(n[e]);return e.innerHTML="",0}const o=Object.create(null),h=Object.create(null);for(let t=0;t<i;t++){const s=n[t].a?n[t].a.key:null,i=e.childNodes[t];null!=s&&i&&(o[s]=i,h[s]=n[t])}const c=new Array(r),u=new Array(r);for(let e=0;e<r;e++){const n=t[e].a?t[e].a.key:null;null!=n&&o[n]?(c[e]=o[n],u[e]=h[n],delete o[n]):(c[e]=null,u[e]=null)}for(const t in o){const n=o[t];n&&(s.patch(e,n,void 0,h[t]),n.remove())}let d=e.firstChild;for(let n=0;n<r;n++){const i=c[n];if(i&&i===d)d=d.nextSibling;else if(i)e.insertBefore(i,d);else{const i=s.createElement(t[n]);i&&e.insertBefore(i,d)}}for(;d;){const e=d.nextSibling;d.remove(),d=e}for(let n=0;n<r;n++)u[n]&&s.patch(e,e.childNodes[n],t[n],u[n]);return r}removeExtraChildren(e,t,n,s){const i=t.c?t.c.length:0;if(!(i<=n))for(let r=i;r-- >n;){const n=e.lastChild;n&&(s._unmountNodeAndChildren(t.c[r]),n.remove())}}}class g{constructor(e,t,n){this.generateTree=e||m,this.renderer=t,this.lifecycleQueue=n}mount(e,t,n){const s=this.generateTree(t(),n);return this.renderer.mount(e,s),this.lifecycleQueue.flush(),s}update(e,t,n,s){const i=this.generateTree(t(),n);return this.renderer.patch(e,e.firstChild,i,s),this.lifecycleQueue.flush(),i}unmount(e,t){t&&(this.renderer.unmount(e,t),this.lifecycleQueue.flush())}}class v{constructor(e,t="microtask"){this._renderFn=e,this._scheduler=t,this._scheduled=!1}schedule(){this._scheduled||(this._scheduled=!0,"microtask"===this._scheduler?Promise.resolve().then(()=>this._execute()):"sync"===this._scheduler&&this._execute())}_execute(){this._scheduled=!1,this._renderFn()}}class b{constructor(e,t={}){this.rootComponent=e,this.savedTree=e,this.currentTree=null,this.rootNode=null,this.stateManager=new u(t),this.lifecycleQueue=new y,this.eventManager=new p,this.renderer=new d(this.eventManager,this.lifecycleQueue,new _),this.mountOrchestrator=new g(m,this.renderer,this.lifecycleQueue),this.updateLoop=new v(()=>this.update(),"microtask"),this._boundSchedule=()=>this.updateLoop.schedule(),this.stateManager.subscribe(this._boundSchedule)}mount(e){if(this.rootNode=document.getElementById(e),!this.rootNode)throw new Error(`Cannot mount app: element with id "${e}" not found`);return this.eventManager.setRootNode(this.rootNode),this.currentTree=this.mountOrchestrator.mount(this.rootNode,this.savedTree,this.stateManager),this}unmount(){this.mountOrchestrator.unmount(this.rootNode,this.currentTree),this.eventManager.destroy(),this.stateManager.unsubscribe(()=>this.updateLoop.schedule()),this.rootNode&&(this.rootNode.innerHTML=""),this.currentTree=null,this.rootNode=null}scheduleUpdate(){this.updateLoop.schedule()}update(){this.rootNode&&this.savedTree&&(this.currentTree=this.mountOrchestrator.update(this.rootNode,this.savedTree,this.stateManager,this.currentTree))}getStore(){return this.stateManager.getStore()}setStore(e,t){this.stateManager.setStore(e,t)}}function N(e,t,n){const s=new b(e,n);return s.mount(t),s}function S(e,t,n={}){const s=new b(e,n);return s.mount(t),s}export{b as App,p as EventManager,y as LifecycleQueue,d as Renderer,u as StateManager,o as component,N as createApp,t as flatten,m as generateTree,i as generateUUID,n as h,s as isVNode,S as render};
@@ -1,2 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e||self).literaljs={})}(this,function(e){var t,n,i,o={},r={},f=[],d={},u=[],s=["abort","blur","error","focus","load","mouseenter","mouseleave","resize","scroll","unload"],c="string",a="number",h="undefined",p="object",l="function",y="events",v="style";function m(e){return Array.isArray(e)}function b(){return Math.random().toString(36).substring(2)+(new Date).getTime().toString(36)}function g(e,t){for(var n=0,i=t.length;n<i;n++)m(t[n])?g(e,t[n]):e.push(t[n]);return e}function k(e,t){for(var n in t)e[n]=t[n];return e}function S(e,t,n){return k(k(e,t),n)}function j(e,t){return{e:e,a:k({},t),c:g([],[].slice.call(arguments,2))}}function N(e,r,f){void 0===f&&(f={}),o=k({},f),n=e,t=document.getElementById(r),i=C(e()),I(t,i),F()}function A(e){var t=void 0===e?{}:e,n=t.name,i=void 0===n?"":n,f=t.state,d=void 0===f?{}:f,u=t.mounted,s=void 0===u?function(){}:u,c=t.updated,a=void 0===c?function(){}:c,p=t.unmounted,y=void 0===p?function(){}:p,v=t.methods,m=void 0===v?function(){}:v,g=t.render,k=void 0===g?function(){}:g,S=b();return function(e){return void 0===e&&(e={}),{id:S,init:function(){return this.id=S,this.name=i+(e.key?"_"+e.key:""),this.key=this.id+(this.name||""),this.props=e,this.store=o,this.getStore=O,this.setStore=x.bind(this),this.getState=E.bind(this),this.setState=T.bind(this),this.createState=function(){typeof r[this.key]===h&&(r[this.key]=d)}.bind(this)(),this.deleteState=function(){delete r[this.key]}.bind(this),this.mounted=s.bind(this),this.updated=a.bind(this),this.unmounted=y.bind(this),function(e,t){for(var n in typeof t===l&&(t=t.bind(e)()),t)e[n]=t[n].bind(e)}(this,m),this.render=k.bind(this),this}}}}function O(){return k({},o)}function x(e,t){typeof e===l&&(e=e(o)),o=S({},o,e),B(),typeof t===l&&t.bind(this)()}function E(){return k({},r[this.key])}function T(e,t){typeof e===l&&(e=e(r[this.key])),r[this.key]=S({},r[this.key],e),B(),typeof t===l&&t.bind(this)()}function C(e){if(typeof e===h)return e;if(typeof e.e===l){var t=k({},e.a.props);delete e.a.props,e=e.e(t)}if(typeof e.init===l){var n=new e.init;typeof(e=n.render())===p&&(e.id=n.id,e.m=n.mounted,e.up=n.updated,e.un=n.unmounted,e.d=n.deleteState)}if(m(e.c))for(var i=0,o=e.c.length;i<o;i++)e.c[i]=C(e.c[i]);return e}function L(e){var t=typeof e;if(t===c||t===a)return document.createTextNode(e);if("boolean"===t||t===h)return document.createTextNode("");var n=document.createElement(e.e);if(typeof e.a===p)for(var i=Object.keys(e.a),o=i.length;o--;)i[o]===y?(e.eid=b(),J(e.eid,e.a[i[o]],n)):i[o]===v?z(e.a[i[o]],n):n.setAttribute(i[o],e.a[i[o]]);if(G(e,"m"),m(e.c))for(var r=0,f=e.c.length;r<f;r++)I(n,e.c[r]);return n}function w(e){if("#document"!==e.parentNode.nodeName){var t=e.getAttribute("data-eid");return typeof t===c?t:w(e.parentNode)}}function J(e,n,i){i.setAttribute("data-eid",e),d[e]=n;for(var o=Object.keys(n),r=o.length;r--;)s.includes(o[r])?i.addEventListener(o[r],d[e][o[r]]):f.includes(o[r])||(f.push(o[r]),t.addEventListener(o[r],function(e){var t=w(e.target);if(typeof t===c&&d[t]){var n=d[t][e.type];typeof n===l&&n(e)}}))}function z(e,t){if(typeof e!==h)for(var n=Object.keys(e),i=n.length;i--;)t.style[n[i]]=e[n[i]]}function B(e){var o=k({},i),r=C(n());i=r,D(t,t.firstChild,r,o),F()}function D(e,t,n,i){var o=typeof n,r=typeof i;if(r===h)I(e,n);else if(o===h)M(i),t.remove();else if(function(e,t,n,i){return n!==i||e.e!==t.e||e.id!==t.id||(n===c||n===a)&&e!==t}(n,i,o,r))M(i),e.replaceChild(L(n),t);else if(o===p){var f;!function(e,t,n){G(t,"up");for(var i,o,r=Object.keys(t.a),f=r.length;f--;)if(o=t.a[r[f]],i=n.a[r[f]],r[f]===v){if(void 0,void 0,c=typeof(u=i),(s=typeof(d=o))===p&&c===p&&JSON.stringify(d)===JSON.stringify(u)||s===h&&c===h)continue;e.removeAttribute(r[f]),z(o,e)}else r[f]===y?(q(e,n.eid),_(n.eid),t.eid=b(),J(t.eid,o,e)):"value"===r[f]&&o!==i?e.value=o:typeof i!==h&&o===i||e.setAttribute(r[f],o);var d,u,s,c}(t,n,i);for(var d=i.c.length;d--&&typeof n.c[d]===h;)typeof(f=t.lastChild)===p&&(M(i.c[d]),f.remove());for(var u=0,s=n.c.length;u<s;u++)D(t,t.childNodes[u],n.c[u],i.c[u])}}function I(e,t){e.appendChild(L(t))}function M(e){if(typeof e!==h&&(G(e,"un"),G(e,"d"),_(e.eid),m(e.c)))for(var t=e.c.length;t--;)M(e.c[t])}function _(e){typeof e===c&&delete d[e]}function q(e,t){for(var n=Object.keys(d[t]),i=n.length;i--;)s.includes(n[i])&&e.removeEventListener(n[i],d[t][n[i]])}function F(){for(var e;e=u.shift();)e()}function G(e,t){typeof e===p&&typeof e[t]===l&&u.push(e[t])}module.exports={component:A,render:N,h:j},e.component=A,e.h=j,e.render=N});
2
- //# sourceMappingURL=index.umd.js.map
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e||self).literaljs={})}(this,function(e){class t{constructor(e,t,n){void 0===t&&(t={}),void 0===n&&(n=[]),this.e=e,this.a=t,this.c=n}withLifecycle(e){return e.mounted&&(this.m=e.mounted),e.updated&&(this.up=e.updated),e.unmounted&&(this.un=e.unmounted),e.deleteState&&(this.d=e.deleteState),this}withIdentity(e,t){return this.definitionId=e,this.instanceId=t,this.id=e+"_"+t,this}}function n(e,t){for(let s=0,i=t.length;s<i;s++)Array.isArray(t[s])?n(e,t[s]):e.push(t[s]);return e}function s(){return Math.random().toString(36).substring(2)+(new Date).getTime().toString(36)}class i{constructor(e,t,n,s,i,o){this.definitionId=e,this.instanceId=t,this.name=n,this.key=`${e}_${t}_${n}`,this.props=s,this._stateManager=o,this._config=i,o.createState(this.key,i.state),this.mounted=i.mounted.bind(this),this.updated=i.updated.bind(this),this.unmounted=i.unmounted.bind(this),this.deleteState=()=>{this._stateManager.deleteState(this.key)},this._renderedVNode=null,this._previousProps=null;const r=i.render.bind(this);this.render=()=>{if(!this.shouldUpdate())return this._renderedVNode;const e=r();return this._renderedVNode=e,this._previousProps=this.props,e}}getStore(){return this._stateManager.getStore()}setStore(e,t){this._stateManager.setStore(e,t)}getState(){return this._stateManager.getState(this.key)}setState(e,t){this._stateManager.setState(this.key,e,t)}createState(){this._stateManager.createState(this.key,this._config.state)}deleteState(){this._stateManager.deleteState(this.key)}shouldUpdate(){return!this._previousProps||!function(e,t){if(e===t)return!0;if(!e||!t||"object"!=typeof e||"object"!=typeof t)return!1;const n=Object.keys(e),s=Object.keys(t);if(n.length!==s.length)return!1;for(let s=0;s<n.length;s++)if(e[n[s]]!==t[n[s]])return!1;return!0}(this.props,this._previousProps)}bindMethods(e){"function"==typeof e&&(e=e.bind(this)());for(let t in e)this[t]=e[t].bind(this)}}function o(e,t){for(let n in t)e[n]=t[n];return e}class r{constructor(e){void 0===e&&(e={}),this.store={...e},this.componentStates={},this.listeners=[]}subscribe(e){this.listeners.push(e)}unsubscribe(e){const t=this.listeners.indexOf(e);t>-1&&this.listeners.splice(t,1)}_notify(){for(let e=0;e<this.listeners.length;e++)this.listeners[e]()}getStore(){return{...this.store}}setStore(e,t){"function"==typeof e&&(e=e(this.store)),this.store=o(o({},this.store),e),this._notify(),"function"==typeof t&&t()}createState(e,t){e in this.componentStates||(this.componentStates[e]={...t})}getState(e){return{...this.componentStates[e]}}setState(e,t,n){"function"==typeof t&&(t=t(this.componentStates[e])),this.componentStates[e]=o(o({},this.componentStates[e]),t),this._notify(),"function"==typeof n&&n()}deleteState(e){delete this.componentStates[e]}reset(){this.store={},this.componentStates={},this.listeners=[]}}class h{constructor(e,t,n){this.eventManager=e,this.lifecycleQueue=t,this.diffEngine=n}mount(e,t){const n=this.createElement(t);n&&e.appendChild(n)}createElement(e){const t=typeof e;return"string"===t||"number"===t?document.createTextNode(e):"boolean"===t||"undefined"===t?document.createTextNode(""):"object"===t&&e.e?this._createElementNode(e):null}_createElementNode(e){const t=document.createElement(e.e);if("object"==typeof e.a){const n=Object.keys(e.a);for(let s=n.length;s--;)if("events"===n[s])e.eid=this.eventManager.bindEvents(t,e.a[n[s]]);else if("style"===n[s])this._addStyles(e.a[n[s]],t);else{if("key"===n[s])continue;t.setAttribute(n[s],e.a[n[s]])}}if(this.lifecycleQueue.mounted(e),Array.isArray(e.c))for(let n=0,s=e.c.length;n<s;n++){const s=this.createElement(e.c[n]);s&&t.appendChild(s)}return t}_addStyles(e,t){if(void 0===e)return;const n=Object.keys(e);for(let s=n.length;s--;)t.style[n[s]]=e[n[s]]}patch(e,t,n,s){const i=typeof n;if(void 0===s)this._appendChild(e,n);else if("undefined"===i)this._unmountNodeAndChildren(s),t&&t.remove();else if(this.diffEngine.areNodesEqual(n,s)){if("object"===i&&n.e){if(n===s)return;if(this._updateNodes(t,n,s),n.c!==s.c)if(this.diffEngine._hasKeys(n.c)||this.diffEngine._hasKeys(s.c))this.diffEngine.reconcileChildren(t,n.c,s.c,this);else{let e;for(let i=s.c?s.c.length:0;i--&&void 0===n.c[i];)e=t.lastChild,e&&(this._unmountNodeAndChildren(s.c[i]),e.remove());if(Array.isArray(n.c))for(let e=0,i=n.c.length;e<i;e++)this.patch(t,t.childNodes[e]||null,n.c[e],s.c?s.c[e]:void 0)}}}else if(!t||3!==t.nodeType||"string"!==i&&"number"!==i)this._unmountNodeAndChildren(s),t&&e.replaceChild(this.createElement(n),t);else{const e=String(n);t.textContent!==e&&(t.textContent=e)}}_appendChild(e,t){const n=this.createElement(t);n&&e.appendChild(n)}_updateNodes(e,t,n){if(this.lifecycleQueue.updated(t),t.a===n.a)return;if(!t.a||!n.a)return;const s=Object.keys(t.a);let i,o;for(let r=s.length;r--;)if(o=t.a[s[r]],i=n.a[s[r]],"style"===s[r]){if(this._stylesAreEqual(o,i))continue;e.removeAttribute(s[r]),this._addStyles(o,e)}else if("events"===s[r])this.eventManager.unbindEvents(e,n.eid),t.eid=this.eventManager.bindEvents(e,o);else{if("key"===s[r])continue;"value"===s[r]&&o!==i?e.value=o:void 0!==i&&o===i||e.setAttribute(s[r],o)}}_stylesAreEqual(e,t){if(e===t)return!0;const n=typeof e,s=typeof t;if("undefined"===n&&"undefined"===s)return!0;if("object"!==n||"object"!==s)return!1;const i=Object.keys(e),o=Object.keys(t);if(i.length!==o.length)return!1;for(let n=i.length;n--;)if(e[i[n]]!==t[i[n]])return!1;return!0}_unmountNodeAndChildren(e){if(null!=e&&(this.lifecycleQueue.unmounted(e),this.lifecycleQueue.deleteState(e),this.eventManager.deleteCachedEvent(e.eid),Array.isArray(e.c)))for(let t=e.c.length;t--;)this._unmountNodeAndChildren(e.c[t])}unmount(e,t){this._unmountNodeAndChildren(t),e&&(e.innerHTML="")}}class d{constructor(e,t,n){this._getCache=e,this._resolveUUID=t,this._elementToUUID=n,this._attachedTypes=new Set,this._rootNode=null}attach(e,t){this._attachedTypes.has(t)||(this._attachedTypes.add(t),this._rootNode=e,e._literaljs_hasEvents=!0,e.addEventListener(t,e=>this._handle(e)))}_handle(e){if(!this._rootNode||!this._rootNode._literaljs_hasEvents)return;let t=e.target;for(;t&&t!==this._rootNode;){let n;if(this._elementToUUID&&(n=this._elementToUUID.get(t))){const t=this._getCache(n);if(t&&"function"==typeof t[e.type])return void t[e.type](e)}const s=this._resolveUUID(t);if("string"==typeof s){const t=this._getCache(s);if(t&&"function"==typeof t[e.type])return void t[e.type](e)}t=t.parentNode}}reset(){this._attachedTypes.clear()}}const c=["abort","blur","error","focus","load","mouseenter","mouseleave","resize","scroll","unload"],u="eid";class a{constructor(){this.cache={},this.rootNode=null,this._elementToUUID=new WeakMap,this.eventBus=new d(e=>this.cache[e],e=>this.getEventUUID(e),this._elementToUUID)}setRootNode(e){this.rootNode=e}getEventUUID(e){if(!e||!e.parentNode)return;if("#document"===e.parentNode.nodeName)return;const t=e.getAttribute("data-"+u);return"string"==typeof t?t:this.getEventUUID(e.parentNode)}bindEvents(e,t){const n=s();e.setAttribute("data-"+u,n),this.cache[n]=t,this._elementToUUID.set(e,n);const i=Object.keys(t);for(let t=i.length;t--;)c.includes(i[t])?e.addEventListener(i[t],this.cache[n][i[t]]):this.eventBus.attach(this.rootNode,i[t]);return n}unbindEvents(e,t){if(!this.cache[t])return;const n=Object.keys(this.cache[t]);for(let s=n.length;s--;)c.includes(n[s])&&e.removeEventListener(n[s],this.cache[t][n[s]]);this.deleteCachedEvent(t),this._elementToUUID.delete(e),e.removeAttribute("data-"+u)}addEvents(e,t,n){n.setAttribute("data-"+u,e),this.cache[e]=t,this._elementToUUID.set(n,e);const s=Object.keys(t);for(let t=s.length;t--;)c.includes(s[t])?n.addEventListener(s[t],this.cache[e][s[t]]):this.eventBus.attach(this.rootNode,s[t])}removeIndividualEvents(e,t){if(!this.cache[t])return;const n=Object.keys(this.cache[t]);for(let s=n.length;s--;)c.includes(n[s])&&e.removeEventListener(n[s],this.cache[t][n[s]])}deleteCachedEvent(e){"string"==typeof e&&delete this.cache[e]}destroy(){this.rootNode&&(this.rootNode._literaljs_hasEvents=!1),this.cache={},this.rootNode=null,this.eventBus.reset()}}class l{constructor(){this.queue=[]}mounted(e){"object"==typeof e&&"function"==typeof e.m&&this.queue.push(e.m)}updated(e){"object"==typeof e&&"function"==typeof e.up&&this.queue.push(e.up)}unmounted(e){"object"==typeof e&&"function"==typeof e.un&&this.queue.push(e.un)}deleteState(e){"object"==typeof e&&"function"==typeof e.d&&this.queue.push(e.d)}flush(){let e;for(;e=this.queue.shift();)e()}clear(){this.queue=[]}}function f(e,n){if(null==e)return e;if("function"==typeof e.e){const t={...e.a.props};delete(e={e:e.e,a:{...e.a},c:e.c}).a.props,e=e.e(t)}if(e&&"function"==typeof e.bind){const s=e.bind(n);let i;try{i=s.render()}catch(e){console.error("Component render error:",e),i={e:"div",a:{class:"error-boundary"},c:[`${e.name}: ${e.message}`]}}if("object"==typeof i&&null!==i&&i instanceof t)i.withIdentity(e.definitionId||s.definitionId,e.instanceId||s.instanceId),i.withLifecycle({mounted:s.mounted,updated:s.updated,unmounted:s.unmounted,deleteState:s.deleteState}),e=i;else if("object"==typeof i&&null!==i){const n=new t(i.e,i.a,i.c);n.withIdentity(e.definitionId||s.definitionId,e.instanceId||s.instanceId),n.withLifecycle({mounted:s.mounted,updated:s.updated,unmounted:s.unmounted,deleteState:s.deleteState}),e=n}else e=i}if(e&&Array.isArray(e.c))for(let t=0,s=e.c.length;t<s;t++)e.c[t]=f(e.c[t],n);return e}class p{areNodesEqual(e,t){const n=typeof e;return n===typeof t&&("object"===n&&e.e===t.e&&e.id===t.id||("string"===n||"number"===n)&&e===t)}reconcileChildren(e,t,n,s){return Array.isArray(t)?this._hasKeys(t)||this._hasKeys(n)?this._reconcileKeyed(e,t,n,s):this._reconcileNonKeyed(e,t,n,s):0}_reconcileNonKeyed(e,t,n,s){const i=t.length;if(0===i){if(n)for(let e=0;e<n.length;e++)s._unmountNodeAndChildren(n[e]);return e.innerHTML="",0}const o=e.childNodes;for(let r=0;r<i;r++)s.patch(e,o[r]||null,t[r],n?n[r]:void 0);return i}_hasKeys(e){if(!Array.isArray(e))return!1;for(let t=0,n=e.length;t<n;t++)if(e[t]&&e[t].a&&null!=e[t].a.key)return!0;return!1}_reconcileKeyed(e,t,n,s){const i=n?n.length:0,o=t.length;if(0===o){for(let e=0;e<i;e++)s._unmountNodeAndChildren(n[e]);return e.innerHTML="",0}const r=Object.create(null),h=Object.create(null);for(let t=0;t<i;t++){const s=n[t].a?n[t].a.key:null,i=e.childNodes[t];null!=s&&i&&(r[s]=i,h[s]=n[t])}const d=new Array(o),c=new Array(o);for(let e=0;e<o;e++){const n=t[e].a?t[e].a.key:null;null!=n&&r[n]?(d[e]=r[n],c[e]=h[n],delete r[n]):(d[e]=null,c[e]=null)}for(const t in r){const n=r[t];n&&(s.patch(e,n,void 0,h[t]),n.remove())}let u=e.firstChild;for(let n=0;n<o;n++){const i=d[n];if(i&&i===u)u=u.nextSibling;else if(i)e.insertBefore(i,u);else{const i=s.createElement(t[n]);i&&e.insertBefore(i,u)}}for(;u;){const e=u.nextSibling;u.remove(),u=e}for(let n=0;n<o;n++)c[n]&&s.patch(e,e.childNodes[n],t[n],c[n]);return o}removeExtraChildren(e,t,n,s){const i=t.c?t.c.length:0;if(!(i<=n))for(let o=i;o-- >n;){const n=e.lastChild;n&&(s._unmountNodeAndChildren(t.c[o]),n.remove())}}}class y{constructor(e,t,n){this.generateTree=e||f,this.renderer=t,this.lifecycleQueue=n}mount(e,t,n){const s=this.generateTree(t(),n);return this.renderer.mount(e,s),this.lifecycleQueue.flush(),s}update(e,t,n,s){const i=this.generateTree(t(),n);return this.renderer.patch(e,e.firstChild,i,s),this.lifecycleQueue.flush(),i}unmount(e,t){t&&(this.renderer.unmount(e,t),this.lifecycleQueue.flush())}}class m{constructor(e,t){void 0===t&&(t="microtask"),this._renderFn=e,this._scheduler=t,this._scheduled=!1}schedule(){this._scheduled||(this._scheduled=!0,"microtask"===this._scheduler?Promise.resolve().then(()=>this._execute()):"sync"===this._scheduler&&this._execute())}_execute(){this._scheduled=!1,this._renderFn()}}class _{constructor(e,t){void 0===t&&(t={}),this.rootComponent=e,this.savedTree=e,this.currentTree=null,this.rootNode=null,this.stateManager=new r(t),this.lifecycleQueue=new l,this.eventManager=new a,this.renderer=new h(this.eventManager,this.lifecycleQueue,new p),this.mountOrchestrator=new y(f,this.renderer,this.lifecycleQueue),this.updateLoop=new m(()=>this.update(),"microtask"),this._boundSchedule=()=>this.updateLoop.schedule(),this.stateManager.subscribe(this._boundSchedule)}mount(e){if(this.rootNode=document.getElementById(e),!this.rootNode)throw new Error(`Cannot mount app: element with id "${e}" not found`);return this.eventManager.setRootNode(this.rootNode),this.currentTree=this.mountOrchestrator.mount(this.rootNode,this.savedTree,this.stateManager),this}unmount(){this.mountOrchestrator.unmount(this.rootNode,this.currentTree),this.eventManager.destroy(),this.stateManager.unsubscribe(()=>this.updateLoop.schedule()),this.rootNode&&(this.rootNode.innerHTML=""),this.currentTree=null,this.rootNode=null}scheduleUpdate(){this.updateLoop.schedule()}update(){this.rootNode&&this.savedTree&&(this.currentTree=this.mountOrchestrator.update(this.rootNode,this.savedTree,this.stateManager,this.currentTree))}getStore(){return this.stateManager.getStore()}setStore(e,t){this.stateManager.setStore(e,t)}}e.App=_,e.EventManager=a,e.LifecycleQueue=l,e.Renderer=h,e.StateManager=r,e.component=function(e){let t=void 0===e?{}:e,n=t.name,o=void 0===n?"":n,r=t.state,h=void 0===r?{}:r,d=t.mounted,c=void 0===d?function(){}:d,u=t.updated,a=void 0===u?function(){}:u,l=t.unmounted,f=void 0===l?function(){}:l,p=t.methods,y=void 0===p?function(){}:p,m=t.render,_=void 0===m?function(){}:m;const g=s(),v=new Map;return function(e){void 0===e&&(e={});const t=e.key||"__default__";if(!v.has(t)){const n=s(),r=o+(e.key?"_"+e.key:"");v.set(t,{definitionId:g,instanceId:n,key:`${g}_${n}_${r}`,_props:null,_cachedRender:null,bind(e){const t=new i(g,n,r,this._props,{state:h,mounted:c,updated:a,unmounted:f,methods:y,render:_},e);return t.bindMethods(y),t}})}const n=v.get(t);return n._props=e,n}},e.createApp=function(e,t,n){const s=new _(e,n);return s.mount(t),s},e.flatten=n,e.generateTree=f,e.generateUUID=s,e.h=function(e,s){const i={};for(let e in s)i[e]=s[e];return new t(e,i,n([],[].slice.call(arguments,2)))},e.isVNode=function(e){return e instanceof t||null!==e&&"object"==typeof e&&"e"in e},e.render=function(e,t,n){void 0===n&&(n={});const s=new _(e,n);return s.mount(t),s}});
package/package.json CHANGED
@@ -1,29 +1,39 @@
1
1
  {
2
2
  "name": "literaljs",
3
- "version": "7.0.2",
3
+ "version": "8.0.1",
4
4
  "description": "A small JavaScript library for building reactive user interfaces.",
5
5
  "main": "build/index.js",
6
6
  "module": "build/index.m.js",
7
7
  "source": "src/index.js",
8
8
  "scripts": {
9
- "rebuild": "sudo rm -rf build/ && yarn build",
10
- "build": "microbundle",
9
+ "build": "microbundle --no-sourcemap",
10
+ "test": "jest --coverage",
11
+ "test:watch": "jest --watch",
12
+ "rebuild": "rm -rf build/ && npm run build",
11
13
  "prepare": "npm run build",
12
- "prepublishOnly": "npm run build",
13
- "test": "jest --coverage"
14
+ "benchmark": "node benchmark/suite.js"
14
15
  },
15
16
  "author": "Michael Farrell",
16
17
  "license": "MIT",
18
+ "files": [
19
+ "build/"
20
+ ],
17
21
  "jest": {
18
- "verbose": true
22
+ "verbose": true,
23
+ "testEnvironment": "jsdom"
19
24
  },
20
25
  "babel": {
21
- "presets": ["@babel/preset-env"]
26
+ "presets": [
27
+ ["@babel/preset-env", { "targets": { "chrome": "90", "firefox": "90", "safari": "14" } }]
28
+ ]
22
29
  },
23
- "dependencies": {},
24
30
  "devDependencies": {
25
- "babel-preset-env": "^1.7.0",
26
- "jest": "^26.6.3",
27
- "microbundle": "^0.13.0"
31
+ "@babel/core": "^7.26.0",
32
+ "@babel/preset-env": "^7.26.0",
33
+ "babel-jest": "^30.4.1",
34
+ "jest": "^30.4.2",
35
+ "jest-environment-jsdom": "^30.4.1",
36
+ "jsdom": "^29.1.1",
37
+ "microbundle": "^0.15.1"
28
38
  }
29
- }
39
+ }
package/.gitlab-ci.yml DELETED
@@ -1,15 +0,0 @@
1
- # This file is a template, and might need editing before it works on your project.
2
- # Official framework image. Look for the different tagged releases at:
3
- # https://hub.docker.com/r/library/node/tags/
4
- image: node:latest
5
-
6
- # This folder is cached between builds
7
- # http://docs.gitlab.com/ee/ci/yaml/README.html#cache
8
- cache:
9
- paths:
10
- - node_modules/
11
-
12
- test_async:
13
- script:
14
- - npm install
15
- - npm run test
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":["../src/index.js"],"sourcesContent":["let ROOT_NODE, SAVED_TREE, CURRENT_TREE;\nlet GLOBAL_STORE = {};\nlet COMPONENT_STATE = {};\nconst EVENTS_KEY = 'eid';\nconst DELEGATED_EVENTS_ADDED = [];\nconst EVENTS_CACHE = {};\nconst LIFECYCLE_QUEUE = [];\nconst NON_DELEGATED_EVENTS = [\n\t'abort',\n\t'blur',\n\t'error',\n\t'focus',\n\t'load',\n\t'mouseenter',\n\t'mouseleave',\n\t'resize',\n\t'scroll',\n\t'unload'\n];\nconst STRING_TYPE = 'string';\nconst NUMBER_TYPE = 'number';\nconst BOOLEAN_TYPE = 'boolean';\nconst UNDEFINED_TYPE = 'undefined';\nconst OBJECT_TYPE = 'object';\nconst FUNCTION_TYPE = 'function';\nconst EVENTS_TYPE = 'events';\nconst STYLE_TYPE = 'style';\nconst VALUE_TYPE = 'value';\n\nfunction isArray(val) {\n\treturn Array.isArray(val);\n}\n\nfunction generateUUID() {\n\treturn (\n\t\tMath.random()\n\t\t\t.toString(36)\n\t\t\t.substring(2) + new Date().getTime().toString(36)\n\t);\n}\n\nfunction flatten(out, a) {\n\tfor (let i = 0, len = a.length; i < len; i++) {\n\t\tif (isArray(a[i])) flatten(out, a[i]);\n\t\telse out.push(a[i]);\n\t}\n\treturn out;\n}\n\nfunction assign(out, a) {\n\tfor (let i in a) out[i] = a[i];\n\treturn out;\n}\n\nfunction merge(out, a, b) {\n\treturn assign(assign(out, a), b);\n}\n\nexport function h(el, attr, ...children) {\n\treturn {\n\t\te: el,\n\t\ta: assign({}, attr),\n\t\tc: flatten([], children)\n\t};\n}\n\nexport function render(components, documentNodeID, state = {}) {\n\t// Initialize application state\n\tGLOBAL_STORE = assign({}, state);\n\t// Cache initial tree for re-instanting with new states\n\t// Cache the initial tree for diffing later\n\tSAVED_TREE = components;\n\t// Grab root node to mount application on\n\tROOT_NODE = document.getElementById(documentNodeID);\n\t// Create first component tree\n\tCURRENT_TREE = generateTreeVN(components());\n\t// Append the new tree to our application for the first paint\n\tappendChild(ROOT_NODE, CURRENT_TREE);\n\t// Initial Lifecycle Trigger\n\tshiftLifcycleQueue();\n}\n\nexport function component({\n\tname = '',\n\tstate = {},\n\tmounted = function() {},\n\tupdated = function() {},\n\tunmounted = function() {},\n\tmethods = function() {},\n\trender = function() {}\n} = {}) {\n\tconst componentUUID = generateUUID();\n\treturn function(props = {}) {\n\t\treturn {\n\t\t\tid: componentUUID,\n\t\t\tinit: function() {\n\t\t\t\tthis.id = componentUUID;\n\t\t\t\tthis.name = name + (props.key ? '_' + props.key : '');\n\t\t\t\tthis.key = this.id + (this.name || '');\n\t\t\t\tthis.props = props;\n\t\t\t\tthis.store = GLOBAL_STORE;\n\t\t\t\tthis.getStore = getStore;\n\t\t\t\tthis.setStore = setStore.bind(this);\n\t\t\t\tthis.getState = getState.bind(this);\n\t\t\t\tthis.setState = setState.bind(this);\n\t\t\t\tthis.createState = function() {\n\t\t\t\t\tif (typeof COMPONENT_STATE[this.key] === UNDEFINED_TYPE) {\n\t\t\t\t\t\tCOMPONENT_STATE[this.key] = state;\n\t\t\t\t\t}\n\t\t\t\t}.bind(this)();\n\t\t\t\tthis.deleteState = function() {\n\t\t\t\t\tdelete COMPONENT_STATE[this.key];\n\t\t\t\t}.bind(this);\n\t\t\t\tthis.mounted = mounted.bind(this);\n\t\t\t\tthis.updated = updated.bind(this);\n\t\t\t\tthis.unmounted = unmounted.bind(this);\n\t\t\t\tbindMethods(this, methods);\n\t\t\t\tthis.render = render.bind(this);\n\t\t\t\treturn this;\n\t\t\t}\n\t\t};\n\t};\n}\n\nfunction getStore() {\n\treturn assign({}, GLOBAL_STORE);\n}\n\nfunction setStore(newStore, callback) {\n\tif (typeof newStore === FUNCTION_TYPE) {\n\t\tnewStore = newStore(GLOBAL_STORE);\n\t}\n\tGLOBAL_STORE = merge({}, GLOBAL_STORE, newStore);\n\tinitiateDiff();\n\tif (typeof callback === FUNCTION_TYPE) callback.bind(this)();\n}\n\nfunction getState() {\n\treturn assign({}, COMPONENT_STATE[this.key]);\n}\n\nfunction setState(newState, callback) {\n\tif (typeof newState === FUNCTION_TYPE) {\n\t\tnewState = newState(COMPONENT_STATE[this.key]);\n\t}\n\tCOMPONENT_STATE[this.key] = merge({}, COMPONENT_STATE[this.key], newState);\n\tinitiateDiff();\n\tif (typeof callback === FUNCTION_TYPE) callback.bind(this)();\n}\n\nfunction bindMethods(component, methods) {\n\tif (typeof methods === FUNCTION_TYPE) {\n\t\tmethods = methods.bind(component)();\n\t}\n\n\tfor (let func in methods) {\n\t\tcomponent[func] = methods[func].bind(component);\n\t}\n}\n\nfunction generateTreeVN(newC) {\n\tif (typeof newC === UNDEFINED_TYPE) {\n\t\treturn newC;\n\t} else if (typeof newC.e === FUNCTION_TYPE) {\n\t\t// For Components in the application to inject props.\n\t\tconst props = assign({}, newC.a.props);\n\t\tdelete newC.a.props;\n\t\tnewC = newC.e(props);\n\t}\n\n\tif (typeof newC.init === FUNCTION_TYPE) {\n\t\t// For the Root Component And Componets\n\t\t// Initialize The Component\n\t\tconst cObj = new newC.init();\n\t\t// Render Component Markup\n\t\tnewC = cObj.render();\n\n\t\tif (typeof newC === OBJECT_TYPE) {\n\t\t\t// Attach Id and LC Methods To Render Object\n\t\t\tnewC.id = cObj.id;\n\t\t\tnewC.m = cObj.mounted;\n\t\t\tnewC.up = cObj.updated;\n\t\t\tnewC.un = cObj.unmounted;\n\t\t\tnewC.d = cObj.deleteState;\n\t\t}\n\t}\n\n\tif (isArray(newC.c)) {\n\t\tfor (let i = 0, len = newC.c.length; i < len; i++) {\n\t\t\tnewC.c[i] = generateTreeVN(newC.c[i]);\n\t\t}\n\t}\n\n\treturn newC;\n}\n\nfunction createDomNode(data) {\n\tconst type = typeof data;\n\tif (type === STRING_TYPE || type === NUMBER_TYPE) {\n\t\treturn document.createTextNode(data);\n\t} else if (type === BOOLEAN_TYPE || type === UNDEFINED_TYPE) {\n\t\treturn document.createTextNode('');\n\t} else {\n\t\tconst newE = document.createElement(data.e);\n\n\t\tif (typeof data.a === OBJECT_TYPE) {\n\t\t\tconst keys = Object.keys(data.a);\n\t\t\tfor (let i = keys.length; i--; ) {\n\t\t\t\tif (keys[i] === EVENTS_TYPE) {\n\t\t\t\t\tdata.eid = generateUUID();\n\t\t\t\t\taddEvents(data.eid, data.a[keys[i]], newE);\n\t\t\t\t} else if (keys[i] === STYLE_TYPE) {\n\t\t\t\t\taddStyles(data.a[keys[i]], newE);\n\t\t\t\t} else {\n\t\t\t\t\tnewE.setAttribute(keys[i], data.a[keys[i]]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tpushLifecycle(data, 'm');\n\n\t\tif (isArray(data.c)) {\n\t\t\tfor (let i = 0, len = data.c.length; i < len; i++) {\n\t\t\t\tappendChild(newE, data.c[i]);\n\t\t\t}\n\t\t}\n\n\t\treturn newE;\n\t}\n}\n\nfunction getEventUUID(element) {\n\tif (element.parentNode.nodeName === '#document') return;\n\tconst eid = element.getAttribute('data-' + EVENTS_KEY);\n\tif (typeof eid === STRING_TYPE) return eid;\n\treturn getEventUUID(element.parentNode);\n}\n\nfunction addEvents(eid, eventObj, targetNode) {\n\t// Generate UUID here for event functions\n\t// Send event functions into a cache for lookup by UUID\n\t// UUID is pulled during Event Delegation and the appropriate\n\t// event is picked by type.\n\ttargetNode.setAttribute('data-' + EVENTS_KEY, eid);\n\tEVENTS_CACHE[eid] = eventObj;\n\n\t// Prevent certain events from being delegated due to them not bubbling.\n\tconst keys = Object.keys(eventObj);\n\tfor (let i = keys.length; i--; ) {\n\t\tif (NON_DELEGATED_EVENTS.includes(keys[i])) {\n\t\t\t// Attach event directly if non-bubbling / non-delegated\n\t\t\ttargetNode.addEventListener(keys[i], EVENTS_CACHE[eid][keys[i]]);\n\t\t} else if (!DELEGATED_EVENTS_ADDED.includes(keys[i])) {\n\t\t\t// Added listener type to keep track of what kinds of events\n\t\t\t// are added to the root node.\n\t\t\tDELEGATED_EVENTS_ADDED.push(keys[i]);\n\t\t\tROOT_NODE.addEventListener(keys[i], function(e) {\n\t\t\t\tconst uuid = getEventUUID(e.target);\n\t\t\t\tif (typeof uuid === STRING_TYPE && EVENTS_CACHE[uuid]) {\n\t\t\t\t\tconst event = EVENTS_CACHE[uuid][e.type];\n\t\t\t\t\tif (typeof event === FUNCTION_TYPE) event(e);\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t}\n}\n\nfunction addStyles(styles, e) {\n\tif (typeof styles === UNDEFINED_TYPE) return;\n\tconst keys = Object.keys(styles);\n\tfor (let i = keys.length; i--; ) {\n\t\te.style[keys[i]] = styles[keys[i]];\n\t}\n}\n\nfunction initiateDiff(uuid) {\n\t// Generate new and old trees\n\tconst oldTree = assign({}, CURRENT_TREE);\n\tconst newTree = generateTreeVN(SAVED_TREE());\n\t// Cache new tree for future diffs\n\tCURRENT_TREE = newTree;\n\t// Initiate diff of trees...\n\tdiffAndPatch(ROOT_NODE, ROOT_NODE.firstChild, newTree, oldTree);\n\t// Trigger Lifecycle Methods...\n\tshiftLifcycleQueue();\n}\n\nfunction diffAndPatch(parentNode, targetNode, newVN, oldVN) {\n\tconst nType = typeof newVN;\n\tconst oType = typeof oldVN;\n\n\tif (oType === UNDEFINED_TYPE) {\n\t\tappendChild(parentNode, newVN);\n\t} else if (nType === UNDEFINED_TYPE) {\n\t\tunmountNodeAndChildren(oldVN);\n\t\ttargetNode.remove();\n\t} else if (nodesNotEqual(newVN, oldVN, nType, oType)) {\n\t\tunmountNodeAndChildren(oldVN);\n\t\tparentNode.replaceChild(createDomNode(newVN), targetNode);\n\t} else if (nType === OBJECT_TYPE) {\n\t\tupdateNodes(targetNode, newVN, oldVN);\n\n\t\tlet lastChild;\n\t\tfor (let i = oldVN.c.length; i--; ) {\n\t\t\tif (typeof newVN.c[i] !== UNDEFINED_TYPE) break;\n\t\t\tlastChild = targetNode.lastChild;\n\t\t\tif (typeof lastChild === OBJECT_TYPE) {\n\t\t\t\tunmountNodeAndChildren(oldVN.c[i]);\n\t\t\t\tlastChild.remove();\n\t\t\t}\n\t\t}\n\n\t\t// Recurse through children and diff.\n\t\tfor (let i = 0, len = newVN.c.length; i < len; i++) {\n\t\t\tdiffAndPatch(\n\t\t\t\ttargetNode,\n\t\t\t\ttargetNode.childNodes[i],\n\t\t\t\tnewVN.c[i],\n\t\t\t\toldVN.c[i]\n\t\t\t);\n\t\t}\n\t}\n}\n\nfunction appendChild(parentNode, newNode) {\n\tparentNode.appendChild(createDomNode(newNode));\n}\n\nfunction nodesNotEqual(newVN, oldVN, nType, oType) {\n\treturn (\n\t\tnType !== oType ||\n\t\tnewVN.e !== oldVN.e ||\n\t\tnewVN.id !== oldVN.id ||\n\t\t((nType === STRING_TYPE || nType === NUMBER_TYPE) && newVN !== oldVN)\n\t);\n}\n\nfunction updateNodes(targetNode, newVN, oldVN) {\n\tpushLifecycle(newVN, 'up');\n\n\tconst keys = Object.keys(newVN.a);\n\tlet oldVal, newVal;\n\tfor (let i = keys.length; i--; ) {\n\t\tnewVal = newVN.a[keys[i]];\n\t\toldVal = oldVN.a[keys[i]];\n\t\tif (keys[i] === STYLE_TYPE) {\n\t\t\tif (stylesAreEqual(newVal, oldVal)) continue;\n\t\t\ttargetNode.removeAttribute(keys[i]);\n\t\t\taddStyles(newVal, targetNode);\n\t\t} else if (keys[i] === EVENTS_TYPE) {\n\t\t\tremoveIndividuallyBoundEvents(targetNode, oldVN.eid);\n\t\t\tdeleteCachedEvent(oldVN.eid);\n\t\t\tnewVN.eid = generateUUID();\n\t\t\taddEvents(newVN.eid, newVal, targetNode);\n\t\t} else if (keys[i] === VALUE_TYPE && newVal !== oldVal) {\n\t\t\ttargetNode.value = newVal;\n\t\t} else if (typeof oldVal === UNDEFINED_TYPE || newVal !== oldVal) {\n\t\t\ttargetNode.setAttribute(keys[i], newVal);\n\t\t}\n\t}\n}\n\nfunction unmountNodeAndChildren(node) {\n\t// Recursivly unmounts all children.\n\tif (typeof node === UNDEFINED_TYPE) return;\n\tpushLifecycle(node, 'un');\n\tpushLifecycle(node, 'd');\n\tdeleteCachedEvent(node.eid);\n\tif (isArray(node.c)) {\n\t\tfor (let i = node.c.length; i--; ) {\n\t\t\tunmountNodeAndChildren(node.c[i]);\n\t\t}\n\t}\n}\n\nfunction deleteCachedEvent(eid) {\n\tif (typeof eid === STRING_TYPE) delete EVENTS_CACHE[eid];\n}\n\nfunction removeIndividuallyBoundEvents(targetNode, eid) {\n\tconst keys = Object.keys(EVENTS_CACHE[eid]);\n\tfor (let i = keys.length; i--; ) {\n\t\tif (NON_DELEGATED_EVENTS.includes(keys[i])) {\n\t\t\ttargetNode.removeEventListener(keys[i], EVENTS_CACHE[eid][keys[i]]);\n\t\t}\n\t}\n}\n\nfunction stylesAreEqual(newStyle, oldStyle) {\n\tconst newType = typeof newStyle;\n\tconst oldType = typeof oldStyle;\n\n\treturn (\n\t\t(newType === OBJECT_TYPE &&\n\t\t\toldType === OBJECT_TYPE &&\n\t\t\tJSON.stringify(newStyle) === JSON.stringify(oldStyle)) ||\n\t\t(newType === UNDEFINED_TYPE && oldType === UNDEFINED_TYPE)\n\t);\n}\n\nfunction shiftLifcycleQueue() {\n\tlet lc;\n\twhile ((lc = LIFECYCLE_QUEUE.shift())) lc();\n}\n\nfunction pushLifecycle(node, lcName) {\n\tif (typeof node === OBJECT_TYPE && typeof node[lcName] === FUNCTION_TYPE) {\n\t\tLIFECYCLE_QUEUE.push(node[lcName]);\n\t}\n}\n\nmodule.exports = {\n\tcomponent,\n\trender,\n\th\n};\n"],"names":["ROOT_NODE","SAVED_TREE","CURRENT_TREE","GLOBAL_STORE","COMPONENT_STATE","DELEGATED_EVENTS_ADDED","EVENTS_CACHE","LIFECYCLE_QUEUE","NON_DELEGATED_EVENTS","isArray","val","Array","generateUUID","Math","random","toString","substring","Date","getTime","flatten","out","a","i","len","length","push","assign","merge","b","h","el","attr","e","c","render","components","documentNodeID","state","document","getElementById","generateTreeVN","appendChild","shiftLifcycleQueue","component","name","mounted","updated","unmounted","methods","componentUUID","props","id","init","this","key","store","getStore","setStore","bind","getState","setState","createState","deleteState","func","bindMethods","newStore","callback","initiateDiff","newState","newC","cObj","m","up","un","d","createDomNode","data","type","createTextNode","newE","createElement","keys","Object","eid","addEvents","addStyles","setAttribute","pushLifecycle","getEventUUID","element","parentNode","nodeName","getAttribute","eventObj","targetNode","includes","addEventListener","uuid","target","event","styles","style","oldTree","newTree","diffAndPatch","firstChild","newVN","oldVN","nType","oType","unmountNodeAndChildren","remove","nodesNotEqual","replaceChild","lastChild","oldVal","newVal","newType","oldType","oldStyle","newStyle","JSON","stringify","removeAttribute","removeIndividuallyBoundEvents","deleteCachedEvent","value","updateNodes","childNodes","newNode","node","removeEventListener","lc","shift","lcName","module","exports"],"mappings":"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"}