@neuralfog/elemix 0.1.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/LICENSE +21 -0
- package/README.md +1 -0
- package/dist/app.d.ts +1 -0
- package/dist/app.js +1 -0
- package/dist/decorators.d.ts +2 -0
- package/dist/decorators.js +1 -0
- package/dist/directives.d.ts +1 -0
- package/dist/directives.js +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/reactive.d.ts +1 -0
- package/dist/reactive.js +1 -0
- package/dist/signal.d.ts +1 -0
- package/dist/signal.js +1 -0
- package/dist/src/App.d.ts +10 -0
- package/dist/src/Reactive.d.ts +15 -0
- package/dist/src/Signal.d.ts +2 -0
- package/dist/src/component/Component.d.ts +21 -0
- package/dist/src/component/LocalState.d.ts +6 -0
- package/dist/src/component/Props.d.ts +9 -0
- package/dist/src/component/Renderer.d.ts +10 -0
- package/dist/src/component/Styles.d.ts +9 -0
- package/dist/src/decorators/component.d.ts +9 -0
- package/dist/src/decorators/state.d.ts +3 -0
- package/dist/src/types.d.ts +10 -0
- package/dist/src/utilities.d.ts +3 -0
- package/dist/test/app-context.test.d.ts +1 -0
- package/dist/test/fixtures/FlagsApp.d.ts +14 -0
- package/dist/test/fixtures/LifeCycle.d.ts +9 -0
- package/dist/test/fixtures/LifeCycleNoTemplate.d.ts +5 -0
- package/dist/test/fixtures/ListApp.d.ts +9 -0
- package/dist/test/fixtures/MainApp.d.ts +13 -0
- package/dist/test/fixtures/Ref.d.ts +8 -0
- package/dist/test/fixtures/StateApp.d.ts +20 -0
- package/dist/test/fixtures/StateInProps.d.ts +20 -0
- package/dist/test/fixtures/StyledApp.d.ts +6 -0
- package/dist/test/fixtures/TestComp.d.ts +19 -0
- package/dist/test/fixtures/ViewModelBinding.d.ts +10 -0
- package/dist/test/fixtures/signal.d.ts +4 -0
- package/dist/test/fixtures/signalCustomFlag.d.ts +4 -0
- package/dist/test/lifecycle.test.d.ts +2 -0
- package/dist/test/multi-state-update.test.d.ts +1 -0
- package/dist/test/props.test.d.ts +1 -0
- package/dist/test/ref.test.d.ts +1 -0
- package/dist/test/signal.test.d.ts +2 -0
- package/dist/test/state.in-props.test.d.ts +1 -0
- package/dist/test/state.test.d.ts +1 -0
- package/dist/test/styles.test.d.ts +2 -0
- package/dist/test/user-defined-render-flags.test.d.ts +1 -0
- package/dist/test/view-model-binding.test.d.ts +1 -0
- package/dist/types-xKcmJSD7.js +1 -0
- package/dist/utilities.d.ts +1 -0
- package/dist/utilities.js +1 -0
- package/package.json +44 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 brownhounds
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
WIP
|
package/dist/app.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './src/App';
|
package/dist/app.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var g=Object.defineProperty;var s=(t,i,n)=>i in t?g(t,i,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[i]=n;var c=(t,i,n)=>s(t,typeof i!="symbol"?i+"":i,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=class o{static mergeConfigs(i){o.config={...o.config,...i}}};c(o,"config",{});let e=o;const f=t=>{var i,n;e.mergeConfigs(t),(n=(i=e.config).entryPoint)==null||n.call(i)};exports.App=e;exports.initApp=f;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./types-xKcmJSD7.js"),d=(t,e)=>{customElements.get(t)===void 0&&customElements.define(t,e)},f=({tag:t,signals:e,styles:s})=>r=>{const i=class extends r{constructor(){if(super(),e!=null&&e.length)for(const o of e)o.subscribe(this)}};r.$signals=e||[],r.$styles=s||[],d(t,i)},u=t=>(e,s)=>{e.stateProperties||(e.stateProperties=new Map),e.stateProperties.has(s)||e.stateProperties.set(s,t||c.RenderTrigger.LOCAL_STATE)};exports.component=f;exports.state=u;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@neuralfog/elemix-renderer/directives';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var n={},a;function v(){return a||(a=1,function(i){Object.defineProperty(i,Symbol.toStringTag,{value:"Module"});const s=(e,r,t)=>e.map((c,u)=>{const o=t(c,u);return o.key=r(c,u),o}),f=(e,r,t)=>(typeof e=="function"?e():e)?r:t;i.condition=f,i.repeat=s}(n)),n}v();
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var l=Object.defineProperty;var a=(i,e,t)=>e in i?l(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var s=(i,e,t)=>a(i,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./types-xKcmJSD7.js"),h=require("./reactive.js"),c=require("./app.js");class p{constructor(e){s(this,"locked",!1);s(this,"scheduledRenderTriggers",new Set);this.component=e}schedule(e,t=!1){this.component.template&&(e&&this.scheduledRenderTriggers.add(e),this.locked||(this.locked=!0,setTimeout(()=>{var o,n;this.render(Array.from(this.scheduledRenderTriggers)),this.scheduledRenderTriggers.clear(),this.locked=!1,t&&((n=(o=this.component).onMount)==null||n.call(o))},0)))}render(e){var t,o;this.component.template&&(r.distExports.render(this.component.template(),this.component.root),(o=(t=this.component).onRender)==null||o.call(t,e))}}class d{constructor(e){this.component=e}initialize(){const e=this.component.constructor.prototype.stateProperties;if(e)for(const[t,o]of e){const n=this.component;n[t]=new h.Reactive(n[t],o).subscribe(this.component).value}}}class u{constructor(e){s(this,"data",{});this.component=e}initialize(){this.data=new h.Reactive(this.data,r.RenderTrigger.PROPS).subscribe(this.component).value}setReactive(e,t){this.data[e]=t}set(e,t){if(typeof t=="object"&&t!==null){this.setReactive(e,t);return}const o=this.data[e];if(typeof t=="function"){this.data[e]||this.setReactive(e,t);return}o!==t&&this.setReactive(e,t)}}class f{constructor(e){s(this,"styles");s(this,"sheet");this.component=e,this.styles=this.component.constructor.$styles}initialize(){var e,t;this.component.shadowRoot&&!((e=this.component.shadowRoot.adoptedStyleSheets)!=null&&e.length)&&((t=c.App.config.cssReset)!=null&&t.length&&(this.styles=this.prependStyles(c.App.config.cssReset,this.styles)),this.styles.length&&(this.sheet=new CSSStyleSheet,this.sheet.replaceSync(this.styles.join(" ")),this.component.shadowRoot.adoptedStyleSheets=[this.sheet]))}prependStyles(e,t){const o=t.slice();return o.unshift(e),o}}class g extends HTMLElement{constructor(){super();s(this,"$props",new u(this));s(this,"$renderer",new p(this));s(this,"$localState",new d(this));s(this,"$styles",new f(this));s(this,"template");s(this,"onRender");s(this,"beforeMount");s(this,"onMount");s(this,"onDispose");this.attachShadow({mode:"open"})}get root(){return this.shadowRoot}get props(){return this.$props.data}get styles(){return this.$styles}connectedCallback(){var t;this.$styles.initialize(),this.$props.initialize(),this.$localState.initialize(),(t=this.beforeMount)==null||t.call(this),this.render(r.RenderTrigger.ON_MOUNT,!0)}disconnectedCallback(){var t;this.unsubscribeFromSignals(),(t=this.onDispose)==null||t.call(this)}render(t,o=!1){this.$renderer.schedule(t,o)}unsubscribeFromSignals(){for(const t of this.constructor.$signals)t.unsubscribe(this)}}exports.RenderTrigger=r.RenderTrigger;exports.html=r.html;exports.Component=g;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './src/Reactive';
|
package/dist/reactive.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var b=Object.defineProperty;var h=(r,e,t)=>e in r?b(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var n=(r,e,t)=>h(r,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class S{constructor(e,t){n(this,"subscribers",new Set);n(this,"proxy");n(this,"proxySet",new WeakSet);this.renderTrigger=t,this.proxy=this.create(e)}get value(){return this.proxy}subscribe(e){return this.subscribers.has(e)||this.subscribers.add(e),this}unsubscribe(e){return this.subscribers.delete(e),this}create(e){const t=this;return new Proxy(e,{get(i,o){const s=i[o];if(u(s),typeof s=="object"&&s!==null&&!t.proxySet.has(s)){const c=new Proxy(s,this);return t.proxySet.add(c),c}return s},set(i,o,s){return i[o]=s,u(i),Array.isArray(i)&&o==="length",t.notify(),!0}})}notify(){for(const e of this.subscribers)e.render(this.renderTrigger)}}const a="Reactive state does not support collections: Map, WeakMap, Set, WeakSet",u=r=>{if(r instanceof Map||r instanceof WeakMap||r instanceof Set||r instanceof WeakSet)throw new Error(a)};exports.Reactive=S;exports.UNSUPPORTED_COLLECTION_ERROR_MESSAGE=a;
|
package/dist/signal.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './src/Signal';
|
package/dist/signal.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./reactive.js"),i=require("./types-xKcmJSD7.js"),n=(e,r)=>new t.Reactive(e,r||i.RenderTrigger.SIGNAL);exports.signal=n;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type AppConfig = {
|
|
2
|
+
cssReset?: string;
|
|
3
|
+
entryPoint?: () => Promise<any>;
|
|
4
|
+
};
|
|
5
|
+
export declare class App {
|
|
6
|
+
static config: AppConfig;
|
|
7
|
+
static mergeConfigs(config: AppConfig): void;
|
|
8
|
+
}
|
|
9
|
+
export declare const initApp: (config: AppConfig) => void;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Component } from './component/Component';
|
|
2
|
+
import type { RenderTriggerType } from './types';
|
|
3
|
+
export declare class Reactive<State> {
|
|
4
|
+
private renderTrigger?;
|
|
5
|
+
subscribers: Set<Component<unknown>>;
|
|
6
|
+
private proxy;
|
|
7
|
+
private proxySet;
|
|
8
|
+
get value(): State;
|
|
9
|
+
constructor(state: any, renderTrigger?: RenderTriggerType | undefined);
|
|
10
|
+
subscribe(instance: Component): Reactive<State>;
|
|
11
|
+
unsubscribe(instance: Component): Reactive<State>;
|
|
12
|
+
private create;
|
|
13
|
+
private notify;
|
|
14
|
+
}
|
|
15
|
+
export declare const UNSUPPORTED_COLLECTION_ERROR_MESSAGE = "Reactive state does not support collections: Map, WeakMap, Set, WeakSet";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type RenderTriggerType, type Template } from '../types';
|
|
2
|
+
import { Styles } from './Styles';
|
|
3
|
+
export declare class Component<ComponentProps = unknown> extends HTMLElement {
|
|
4
|
+
private $props;
|
|
5
|
+
private $renderer;
|
|
6
|
+
private $localState;
|
|
7
|
+
private $styles;
|
|
8
|
+
get root(): HTMLElement | ShadowRoot | null;
|
|
9
|
+
get props(): ComponentProps;
|
|
10
|
+
get styles(): Styles;
|
|
11
|
+
constructor();
|
|
12
|
+
connectedCallback(): void;
|
|
13
|
+
disconnectedCallback(): void;
|
|
14
|
+
template?: () => Template;
|
|
15
|
+
onRender?: (renderTriggers?: RenderTriggerType[]) => void;
|
|
16
|
+
beforeMount?: () => void;
|
|
17
|
+
onMount?: () => void;
|
|
18
|
+
onDispose?: () => void;
|
|
19
|
+
render(renderTrigger?: RenderTriggerType, isConnectedCallback?: boolean): void;
|
|
20
|
+
private unsubscribeFromSignals;
|
|
21
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Component } from './Component';
|
|
2
|
+
export declare class Props<ComponentProps = unknown> {
|
|
3
|
+
private component;
|
|
4
|
+
data: ComponentProps;
|
|
5
|
+
constructor(component: Component);
|
|
6
|
+
initialize(): void;
|
|
7
|
+
setReactive(name: string, value: unknown): void;
|
|
8
|
+
set(name: string, value: unknown): void;
|
|
9
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Component } from './Component';
|
|
2
|
+
import type { RenderTriggerType } from '../types';
|
|
3
|
+
export declare class Renderer {
|
|
4
|
+
private component;
|
|
5
|
+
private locked;
|
|
6
|
+
private scheduledRenderTriggers;
|
|
7
|
+
constructor(component: Component);
|
|
8
|
+
schedule(renderTrigger?: RenderTriggerType, isConnectedCallback?: boolean): void;
|
|
9
|
+
private render;
|
|
10
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Reactive } from '../Reactive';
|
|
2
|
+
type ComponentDecoratorConfig = {
|
|
3
|
+
tag: string;
|
|
4
|
+
signals?: Reactive<unknown>[];
|
|
5
|
+
styles?: string[];
|
|
6
|
+
};
|
|
7
|
+
type Component = any;
|
|
8
|
+
export declare const component: ({ tag, signals, styles }: ComponentDecoratorConfig) => (component: Component) => void;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type HtmlTemplate } from '@neuralfog/elemix-renderer';
|
|
2
|
+
export type Template = HtmlTemplate;
|
|
3
|
+
export declare const html: (strings: TemplateStringsArray, ...values: unknown[]) => HtmlTemplate;
|
|
4
|
+
export declare const RenderTrigger: {
|
|
5
|
+
readonly PROPS: "PROPS";
|
|
6
|
+
readonly SIGNAL: "SIGNAL";
|
|
7
|
+
readonly LOCAL_STATE: "LOCAL_STATE";
|
|
8
|
+
readonly ON_MOUNT: "ON_MOUNT";
|
|
9
|
+
};
|
|
10
|
+
export type RenderTriggerType = (typeof RenderTrigger)[keyof typeof RenderTrigger] | string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Component } from '../../src/component/Component';
|
|
2
|
+
import { type Template } from '../../src/types';
|
|
3
|
+
export declare const CUSTOM_STATE_FLAG_1 = "user defined state flag 1";
|
|
4
|
+
export declare const CUSTOM_STATE_FLAG_2 = "user defined state flag 2";
|
|
5
|
+
export declare class FlagsApp extends Component {
|
|
6
|
+
state: {
|
|
7
|
+
value: string;
|
|
8
|
+
};
|
|
9
|
+
state2: {
|
|
10
|
+
value: string;
|
|
11
|
+
};
|
|
12
|
+
onRender: (_renderTrigger?: string[]) => void;
|
|
13
|
+
template: () => Template;
|
|
14
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Component } from '../../src/component/Component';
|
|
2
|
+
import type { Template } from '../../src/types';
|
|
3
|
+
export declare class LifeCycle extends Component {
|
|
4
|
+
beforeMount: () => void;
|
|
5
|
+
onRender: (_renderTrigger?: string[]) => void;
|
|
6
|
+
onMount: () => void;
|
|
7
|
+
onDispose: () => void;
|
|
8
|
+
template: () => Template;
|
|
9
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Component } from '../../src/component/Component';
|
|
2
|
+
import { type Template } from '../../src/types';
|
|
3
|
+
import './TestComp';
|
|
4
|
+
export declare class MainApp extends Component {
|
|
5
|
+
state: {
|
|
6
|
+
string: string;
|
|
7
|
+
color: string;
|
|
8
|
+
size: number;
|
|
9
|
+
};
|
|
10
|
+
propsHandler: () => void;
|
|
11
|
+
onRender: (_renderTrigger?: string[]) => void;
|
|
12
|
+
template: () => Template;
|
|
13
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Component } from '../../src/component/Component';
|
|
2
|
+
import { type Template } from '../../src/types';
|
|
3
|
+
export declare class StateApp extends Component {
|
|
4
|
+
state: {
|
|
5
|
+
string: string;
|
|
6
|
+
number: number;
|
|
7
|
+
null: null;
|
|
8
|
+
undefined: undefined;
|
|
9
|
+
list: string[];
|
|
10
|
+
any: any;
|
|
11
|
+
object: {
|
|
12
|
+
nested: {
|
|
13
|
+
value: string;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
onRender: (_renderTrigger?: string[]) => void;
|
|
18
|
+
onDispose: () => void;
|
|
19
|
+
template: () => Template;
|
|
20
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Component } from '../../src/component/Component';
|
|
2
|
+
import { type Template } from '../../src/types';
|
|
3
|
+
export type StateInPropsChildProps = {
|
|
4
|
+
state: {
|
|
5
|
+
nestedValue: string;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
export declare class StateInPropsChild extends Component<StateInPropsChildProps> {
|
|
9
|
+
onRender: (_renderTrigger?: string[]) => void;
|
|
10
|
+
template: () => Template;
|
|
11
|
+
}
|
|
12
|
+
export declare class StateInProps extends Component {
|
|
13
|
+
state: {
|
|
14
|
+
nested: {
|
|
15
|
+
nestedValue: string;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
onRender: (_renderTrigger?: string[]) => void;
|
|
19
|
+
template: () => Template;
|
|
20
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Component } from '../../src/component/Component';
|
|
2
|
+
import { type Template } from '../../src/types';
|
|
3
|
+
type TestCompProps = {
|
|
4
|
+
color: string;
|
|
5
|
+
size: number;
|
|
6
|
+
handler: () => void;
|
|
7
|
+
};
|
|
8
|
+
export declare class TestComp extends Component<TestCompProps> {
|
|
9
|
+
state: {
|
|
10
|
+
string: string;
|
|
11
|
+
};
|
|
12
|
+
state2: {
|
|
13
|
+
number: number;
|
|
14
|
+
};
|
|
15
|
+
onRender: (_renderTrigger?: string[]) => void;
|
|
16
|
+
onDispose: () => void;
|
|
17
|
+
template: () => Template;
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Component } from '../../src/component/Component';
|
|
2
|
+
import { type Template } from '../../src/types';
|
|
3
|
+
export declare class ViewModelBinding extends Component {
|
|
4
|
+
state: {
|
|
5
|
+
input: {
|
|
6
|
+
value?: string | undefined;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
template: () => Template;
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './fixtures/MainApp';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './fixtures/MainApp';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './fixtures/Ref';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './fixtures/StateInProps';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './fixtures/StateApp';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './fixtures/FlagsApp';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './fixtures/ViewModelBinding';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var T={},L;function st(){return L||(L=1,function(p){var M=Object.defineProperty,$=(r,t,s)=>t in r?M(r,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):r[t]=s,h=(r,t,s)=>$(r,typeof t!="symbol"?t+"":t,s);Object.defineProperty(p,Symbol.toStringTag,{value:"Module"});const R=r=>{const t=r;return t.$cache||(t.$cache={template:new Map}),t.$cache};class N{constructor(t,s){h(this,"key",""),this.strings=t,this.values=s}}const g="₥";var c=(r=>(r[r.EVENT=0]="EVENT",r[r.PROP=1]="PROP",r[r.DIRECT=2]="DIRECT",r[r.MODEL=3]="MODEL",r[r.STD=4]="STD",r[r.REF=5]="REF",r))(c||{});const V=/^(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)$/i,H=r=>{const t=new RegExp(`${g}(\\d+)`),s=r.match(t);if(!s)throw new Error("Unable to extract index from hole comment");return Number(s[1])},b=r=>`<!--${g}${r}-->`,P=r=>r.replace(/<([a-zA-Z][^\s/>]*)([^>]*)\/>/g,(t,s,e)=>V.test(s)?t:`<${s}${e}></${s}>`),D=r=>r.replace(/(\S+)=((<!--[\s\S]*?-->)|([^\s">]+))/g,'$1="$2"');class I{constructor(t,s){this.node=t,this.definition=s}setValue(t){const s=this.definition.name.slice(1);this.node[s]=t}}class C{constructor(t,s){this.node=t,this.definition=s}setValue(t){const s=this.definition.name.slice(1);this.node[`on${s}`]=t}}class x{constructor(t,s){this.node=t,this.definition=s}setValue(t){const s=e=>{t.value=e.target.value};this.node.oninput||(this.node.value=t.value,this.node.oninput=s)}}class F{constructor(t,s){this.node=t,this.definition=s}setValue(t){const s=this.definition.name.slice(1),e=this.node;e.$props&&e.$props.set(s,t)}}class _{constructor(t,s){this.node=t,this.definition=s}setValue(t){t.value=this.node}}let j=class{constructor(r,t){this.node=r,this.definition=t}setValue(r){this.node.setAttribute(this.definition.name,String(r))}};const K=(r,t)=>{const s=/(\S+)(?==(?:["']?)$)/,e=r.match(s);if(e){const n={index:t,name:e[1],value:b(t),virtual:!1,type:c.STD};switch(e[1][0]){case"@":return n.type=c.EVENT,n.virtual=!0,n;case":":return e[1].endsWith(":ref")?(n.type=c.REF,n.virtual=!0,n):(n.type=c.PROP,n.virtual=!0,n);case".":return n.type=c.DIRECT,n.virtual=!0,n;case"~":return e[1].startsWith("~model")&&(n.type=c.MODEL,n.virtual=!0),n;default:return n}}},W=(r,t)=>{const s=r.querySelector(q(t.name,t.value,t.virtual));if(s)switch(t.virtual&&s.removeAttribute(t.name),t.type){case c.EVENT:return new C(s,t);case c.PROP:return new F(s,t);case c.DIRECT:return new I(s,t);case c.MODEL:return new x(s,t);case c.REF:return new _(s,t);default:return new j(s,t)}},q=(r,t,s)=>s?`[\\${r}='${t}']`:`[${r}='${t}']`,U=(r,t)=>{const s=r.length,e=t.length,n=Object.create(null);let i,l,o;for(i=0;i<s;i++)l=r[i].key,n[l]=i;const a=new Array(e),d=[],u=[],E=Object.create(null);for(i=0;i<e;i++){const m=t[i].key;E[m]=!0;const v=n[m];v===void 0?a[i]=-1:(a[i]=v,d.push(v),u.push(i))}const w=G(d),y=new Array(e);for(i=0;i<e;i++)y[i]=!1;const et=w.length;for(i=0;i<et;i++)y[u[w[i]]]=!0;const S=[],A=[],k=[];for(i=0;i<s;i++)o=r[i].key,E[o]!==!0&&S.push({key:o});for(i=0;i<e;i++){o=t[i].key;const m=i+1<e?t[i+1].key:void 0;a[i]===-1?A.push({key:o,value:t[i],beforeKey:m}):y[i]||k.push({key:o,beforeKey:m})}return{deletes:S,inserts:A,moves:k}},G=r=>{const t=r.length,s=new Array(t),e=[];let n,i,l,o;for(n=0;n<t;n++){for(i=0,l=e.length;i<l;)o=i+l>>>1,r[e[o]]<r[n]?i=o+1:l=o;i===e.length?e.push(n):e[i]=n,s[n]=i>0?e[i-1]:-1}const a=e.length,d=new Array(a);let u=e[a-1];for(n=a-1;n>=0;n--)d[n]=u,u=s[u];return d};class z{constructor(t){h(this,"cache",{listTemplate:new Map,listNodes:new Map,listHtmlTemplate:[]}),this.commentNode=t}renderListElement(t,s){if(!this.commentNode)throw new Error("renderList method needs to accept instance of HTMLElement");if(!t.key)throw new Error("use repeat directive when rendering the lists");let e=this.cache.listTemplate.get(t.key);return e||(e=new f(t),this.cache.listTemplate.set(t.key,e),e.mountListElement(this.commentNode,t.key,t.values,this.cache,s)),e}renderAllItems(t){const s=t.length;for(let e=0;e<s;e++)this.renderListElement(t[e]).update(t[e].values)}emptyList(){for(const[,t]of this.cache.listNodes)t.remove();this.cache.listTemplate.clear(),this.cache.listNodes.clear()}deleteNodes(t){const s=t.length;for(let e=s-1;e>=0;e--){const n=this.cache.listNodes.get(t[e].key);n&&n.remove(),this.cache.listNodes.delete(t[e].key),this.cache.listTemplate.delete(t[e].key)}}moveNodes(t){const s=t.length;for(let e=s-1;e>=0;e--){const n=this.cache.listNodes.get(t[e].key),i=this.cache.listNodes.get(t[e].beforeKey);n&&i&&(i==null||i.before(n)),!i&&n&&this.commentNode.before(n)}}insertNodes(t){const s=t.length;for(let e=s-1;e>=0;e--){const n=this.cache.listNodes.get(t[e].beforeKey);this.renderListElement(t[e].value,n)}}updateAllItems(t){const s=t.length;for(let e=0;e<s;e++){const n=this.cache.listTemplate.get(t[e].key);n==null||n.update(t[e].values)}}render(t){if(!this.cache.listHtmlTemplate.length){this.renderAllItems(t),this.cache.listHtmlTemplate=t;return}if(!t.length){this.emptyList(),this.cache.listHtmlTemplate=t;return}const{deletes:s,inserts:e,moves:n}=U(this.cache.listHtmlTemplate,t);if(s.length===t.length||e.length===t.length){this.emptyList(),this.renderAllItems(t),this.cache.listHtmlTemplate=t;return}s.length&&this.deleteNodes(s),n.length&&this.moveNodes(n),e.length&&this.insertNodes(e),this.updateAllItems(t),this.cache.listHtmlTemplate=t}}class Z{constructor(t){h(this,"renderer"),this.commentNode=t,this.renderer=new z(t)}setValue(t){this.renderer.render(t)}}class B{constructor(t){h(this,"node",document.createTextNode("")),this.commentNode=t,t.before(this.node)}setValue(t){const s=t!=null?String(t):"";this.node.textContent!==s&&(this.node.textContent=s)}}class J{constructor(t){h(this,"cache",{nodes:[]}),this.commentNode=t}removeNodes(){if(!this.cache.nodes.length)return;const t=this.cache.nodes.length;for(let s=0;s<t;s++)this.cache.nodes[s].remove();this.cache.nodes=[]}render(t){this.cache.strings!==t.strings&&(this.cache.fragment=void 0,this.removeNodes()),this.cache.fragment||(this.cache.fragment=new f(t),this.cache.strings=t.strings,this.cache.nodes=this.cache.fragment.mountTemplate(this.commentNode,t.values)),this.cache.fragment.update(t.values)}}class Q{constructor(t){h(this,"renderer"),this.commentNode=t,this.renderer=new J(t)}setValue(t){this.renderer.render(t)}}const Y=(r,t)=>Array.isArray(r)?new Z(t):r instanceof N?new Q(t):new B(t);class f{constructor(t){h(this,"holes",new Map),h(this,"htmlString",""),h(this,"attributeMap",[]),this.parse(t.strings)}parse(t){const s=t.length;for(let e=0;e<s;e++)if(this.htmlString+=t[e],e<t.length-1){const n=K(this.htmlString,e);n&&this.attributeMap.push(n),this.htmlString+=b(e)}this.htmlString=P(this.htmlString),this.htmlString=D(this.htmlString)}initFragment(){const t=document.createElement("template");return t.innerHTML=this.htmlString,t.content}hydrateAttributes(t){const s=this.attributeMap.length;for(let e=0;e<s;e++){const n=W(t,this.attributeMap[e]);n&&this.holes.set(this.attributeMap[e].index,n)}return t}hydrateTemplateHoles(t,s){var e;const n=document.createTreeWalker(t,NodeFilter.SHOW_COMMENT,null);for(;n.nextNode();){const i=n.currentNode;if((e=i.nodeValue)!=null&&e.includes(g)){const l=H(i.nodeValue),o=Y(s[l],i);this.holes.set(l,o)}}return t}mount(t,s){const e=this.initFragment();this.hydrateTemplateHoles(e,s),this.hydrateAttributes(e),t.appendChild(e)}mountTemplate(t,s){const e=this.initFragment();this.hydrateTemplateHoles(e,s),this.hydrateAttributes(e);const n=Array.from(e.childNodes);return t.before(e),n}mountListElement(t,s,e,n,i){const l=this.initFragment();this.hydrateTemplateHoles(l,e),this.hydrateAttributes(l),i&&i.before(l),t.before(l);const o=i?i.previousSibling:t.previousSibling;o&&n&&n.listNodes.set(s,o)}update(t){for(const[s,e]of this.holes)e.setValue(t[s])}}const X=(r,...t)=>new N(r,t),tt=(r,t)=>{if(!t)throw new Error("render method needs to accept instance of HTMLElement");const s=R(t);let e=s.template.get(r.strings);e||(e=new f(r),s.template.set(r.strings,e),e.mount(t,r.values)),e.update(r.values)};p.html=X,p.render=tt}(T)),T}var O=st();const rt=O.html,nt={PROPS:"PROPS",SIGNAL:"SIGNAL",LOCAL_STATE:"LOCAL_STATE",ON_MOUNT:"ON_MOUNT"};exports.RenderTrigger=nt;exports.distExports=O;exports.html=rt;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './src/utilities';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=(e=void 0)=>({value:e});exports.ref=r;
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@neuralfog/elemix",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"author": "brownhounds",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": ["./dist/**/*"],
|
|
9
|
+
"exports": {
|
|
10
|
+
".": "./dist/index.js",
|
|
11
|
+
"./decorators": "./dist/decorators.js",
|
|
12
|
+
"./directives": "./dist/directives.js",
|
|
13
|
+
"./signal": "./dist/signal.js",
|
|
14
|
+
"./reactive": "./dist/reactive.js",
|
|
15
|
+
"./config": "./dist/config.js",
|
|
16
|
+
"./app": "./dist/app.js",
|
|
17
|
+
"./utilities": "./dist/utilities.js"
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"clean": "rm -rf ./dist",
|
|
21
|
+
"emit-declarations": "tsc --emitDeclarationOnly --declaration --outDir ./dist",
|
|
22
|
+
"build-lib": "vite build",
|
|
23
|
+
"build": "npm run clean && npm run build-lib && npm run emit-declarations",
|
|
24
|
+
"test": "vitest run --coverage --reporter verbose",
|
|
25
|
+
"test-nc": "vitest run",
|
|
26
|
+
"test-ui": "npx vitest --api.host 0.0.0.0 --ui",
|
|
27
|
+
"lint": "tsc --noEmit && biome format && biome lint",
|
|
28
|
+
"release": "npm run clean && npm run build && npm publish --access public"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@neuralfog/biome-config": "0.1.2",
|
|
32
|
+
"@neuralfog/elemix-testing": "0.1.0",
|
|
33
|
+
"@neuralfog/ts-config": "0.1.1",
|
|
34
|
+
"@vitest/coverage-v8": "3.0.7",
|
|
35
|
+
"@vitest/ui": "3.0.7",
|
|
36
|
+
"jsdom": "26.0.0",
|
|
37
|
+
"typescript": "5.8.2",
|
|
38
|
+
"vite": "6.2.0",
|
|
39
|
+
"vitest": "3.0.7"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"@neuralfog/elemix-renderer": "0.1.45"
|
|
43
|
+
}
|
|
44
|
+
}
|