jmx-runtime 0.0.25 → 0.0.26

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/dist/base.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- export declare function rebind(o: Record<string, any>): Record<string, any>;
2
- export declare function mount(o: Record<string, any>): void;
3
- export declare const loggedmethodsex: <T extends Record<string, any>>(o: T, logger: (name: string, args: any[], result: any) => void) => T;
4
- export declare const loggedmethods: <T extends Record<string, any>>(o: T) => T;
5
- export declare const loggedmethodscolored: <T extends Record<string, any>>(bgcolor: string, o: T) => T;
1
+ export declare function rebind(o: Record<string, any>): Record<string, any>;
2
+ export declare function mount(o: Record<string, any>): void;
3
+ export declare const loggedmethodsex: <T extends Record<string, any>>(o: T, logger: (name: string, args: any[], result: any) => void) => T;
4
+ export declare const loggedmethods: <T extends Record<string, any>>(o: T) => T;
5
+ export declare const loggedmethodscolored: <T extends Record<string, any>>(bgcolor: string, o: T) => T;
6
6
  //# sourceMappingURL=base.d.ts.map
package/dist/base.js CHANGED
@@ -1,22 +1,22 @@
1
- export function rebind(o) {
2
- Object.entries(Object.getOwnPropertyDescriptors(Object.getPrototypeOf(o)))
3
- .filter(([name, p]) => name != 'constructor' && p.value instanceof Function)
4
- .forEach(([name]) => o[name] = o[name].bind(o));
5
- return o;
6
- }
7
- export function mount(o) { Object.assign(globalThis, o); }
8
- export const loggedmethodsex = (o, logger) => new Proxy(o, {
9
- get(target, name, receiver) {
10
- if (typeof target[name] === "function") {
11
- return function (...args) {
12
- logger(name, args, undefined);
13
- let r = target[name].apply(this, args);
14
- return r;
15
- };
16
- }
17
- return Reflect.get(target, name, receiver);
18
- },
19
- });
20
- export const loggedmethods = (o) => loggedmethodsex(o, (name, args, result) => console.log("%c" + name, "background:#585059;color:white;padding:2px;font-weight:bold", args));
21
- export const loggedmethodscolored = (bgcolor, o) => loggedmethodsex(o, (name, args, result) => console.log("%c" + name, `background:${bgcolor};color:white;padding:2px;font-weight:bold`, args));
1
+ export function rebind(o) {
2
+ Object.entries(Object.getOwnPropertyDescriptors(Object.getPrototypeOf(o)))
3
+ .filter(([name, p]) => name != 'constructor' && p.value instanceof Function)
4
+ .forEach(([name]) => o[name] = o[name].bind(o));
5
+ return o;
6
+ }
7
+ export function mount(o) { Object.assign(globalThis, o); }
8
+ export const loggedmethodsex = (o, logger) => new Proxy(o, {
9
+ get(target, name, receiver) {
10
+ if (typeof target[name] === "function") {
11
+ return function (...args) {
12
+ logger(name, args, undefined);
13
+ let r = target[name].apply(this, args);
14
+ return r;
15
+ };
16
+ }
17
+ return Reflect.get(target, name, receiver);
18
+ },
19
+ });
20
+ export const loggedmethods = (o) => loggedmethodsex(o, (name, args, result) => console.log("%c" + name, "background:#585059;color:white;padding:2px;font-weight:bold", args));
21
+ export const loggedmethodscolored = (bgcolor, o) => loggedmethodsex(o, (name, args, result) => console.log("%c" + name, `background:${bgcolor};color:white;padding:2px;font-weight:bold`, args));
22
22
  //# sourceMappingURL=base.js.map
package/dist/config.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- declare global {
2
- interface Window {
3
- jmx?: {
4
- getnamespace: (tag: string) => string;
5
- };
6
- }
7
- }
8
- export declare function createElement(tag: string): Element;
1
+ declare global {
2
+ interface Window {
3
+ jmx?: {
4
+ getnamespace: (tag: string) => string;
5
+ };
6
+ }
7
+ }
8
+ export declare function createElement(tag: string): Element;
9
9
  //# sourceMappingURL=config.d.ts.map
package/dist/config.js CHANGED
@@ -1,5 +1,5 @@
1
- export function createElement(tag) {
2
- let ns = window.jmx?.getnamespace?.(tag);
3
- return ns ? document.createElementNS(ns, tag) : document.createElement(tag);
4
- }
1
+ export function createElement(tag) {
2
+ let ns = window.jmx?.getnamespace?.(tag);
3
+ return ns ? document.createElementNS(ns, tag) : document.createElement(tag);
4
+ }
5
5
  //# sourceMappingURL=config.js.map
package/dist/h.d.ts CHANGED
@@ -1,58 +1,58 @@
1
- type Func<T> = () => T;
2
- export type Expr<T> = T | Func<T>;
3
- export type Props = Record<string, any>;
4
- export type FComponent = (props: Props | undefined, children?: ChildrenH) => HElement;
5
- export type FComponentT<P> = (pcn: P, cn?: Children) => H | void;
6
- export interface IClassComponent {
7
- element: Node;
8
- props?: Record<string, any>;
9
- view(): H;
10
- update(uc: IUpdateContext): boolean | void;
11
- mounted?(): void;
12
- }
13
- interface CComponent {
14
- new (props: any): IClassComponent;
15
- }
16
- export type ChildrenH = (H | undefined)[];
17
- export type Children = Expr<ChildrenH>;
18
- type HText = string | number | boolean;
19
- export type HFragment = {
20
- cn: Children;
21
- };
22
- export type HElement = {
23
- tag: string;
24
- p?: Expr<Props>;
25
- cn: Children;
26
- i?: any;
27
- };
28
- type HCompFun = {
29
- tag: FComponent;
30
- p?: Expr<Props>;
31
- cn?: Children;
32
- };
33
- export type HCompClass = {
34
- tag: CComponent;
35
- p?: Expr<Props>;
36
- cn: Children;
37
- i: IClassComponent;
38
- };
39
- export type HComp = HCompFun | HCompClass;
40
- export type H = HText | HElement | HComp | HFragment;
41
- declare global {
42
- interface Node {
43
- h?: HElement | HCompFun | HCompClass;
44
- }
45
- export interface IUpdateContext {
46
- patchElementOnly?: boolean;
47
- replace?: boolean;
48
- }
49
- export interface Window {
50
- jmx?: {
51
- getnamespace: (tag: string) => string | undefined;
52
- };
53
- }
54
- }
55
- export declare function jsx(): HElement;
56
- export declare function jsxf(): HElement;
57
- export {};
1
+ type Func<T> = () => T;
2
+ export type Expr<T> = T | Func<T>;
3
+ export type Props = Record<string, any>;
4
+ export type FComponent = (props: Props | undefined, children?: ChildrenH) => HElement;
5
+ export type FComponentT<P> = (pcn: P, cn?: Children) => H | void;
6
+ export interface IClassComponent {
7
+ element: Node;
8
+ props?: Record<string, any>;
9
+ view(): H;
10
+ update(uc: IUpdateContext): boolean | void;
11
+ mounted?(): void;
12
+ }
13
+ interface CComponent {
14
+ new (props: any): IClassComponent;
15
+ }
16
+ export type ChildrenH = (H | undefined)[];
17
+ export type Children = Expr<ChildrenH>;
18
+ type HText = string | number | boolean;
19
+ export type HFragment = {
20
+ cn: Children;
21
+ };
22
+ export type HElement = {
23
+ tag: string;
24
+ p?: Expr<Props>;
25
+ cn: Children;
26
+ i?: any;
27
+ };
28
+ type HCompFun = {
29
+ tag: FComponent;
30
+ p?: Expr<Props>;
31
+ cn?: Children;
32
+ };
33
+ export type HCompClass = {
34
+ tag: CComponent;
35
+ p?: Expr<Props>;
36
+ cn: Children;
37
+ i: IClassComponent;
38
+ };
39
+ export type HComp = HCompFun | HCompClass;
40
+ export type H = HText | HElement | HComp | HFragment;
41
+ declare global {
42
+ interface Node {
43
+ h?: HElement | HCompFun | HCompClass;
44
+ }
45
+ export interface IUpdateContext {
46
+ patchElementOnly?: boolean;
47
+ replace?: boolean;
48
+ }
49
+ export interface Window {
50
+ jmx?: {
51
+ getnamespace: (tag: string) => string | undefined;
52
+ };
53
+ }
54
+ }
55
+ export declare function jsx(): HElement;
56
+ export declare function jsxf(): HElement;
57
+ export {};
58
58
  //# sourceMappingURL=h.d.ts.map
package/dist/h.js CHANGED
@@ -1,7 +1,7 @@
1
- export function jsx() {
2
- throw 'jmx plugin not configured';
3
- }
4
- export function jsxf() {
5
- throw 'jmx plugin not configured';
6
- }
1
+ export function jsx() {
2
+ throw 'jmx plugin not configured';
3
+ }
4
+ export function jsxf() {
5
+ throw 'jmx plugin not configured';
6
+ }
7
7
  //# sourceMappingURL=h.js.map
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- export * from './jmx';
2
- export * from './lib';
3
- export * from './base';
4
- export * from './h';
5
- export * from './jsx';
1
+ export * from './jmx';
2
+ export * from './lib';
3
+ export * from './base';
4
+ export * from './h';
5
+ export * from './jsx';
6
6
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- export * from './jmx';
2
- export * from './lib';
3
- export * from './base';
4
- export * from './h';
5
- export * from './jsx';
1
+ export * from './jmx';
2
+ export * from './lib';
3
+ export * from './base';
4
+ export * from './h';
5
+ export * from './jsx';
6
6
  //# sourceMappingURL=index.js.map
package/dist/jmx.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { Expr, H } from './h';
2
- export declare function createElement(tag: string): Element;
3
- export declare function patch(e: Node | null, h: Expr<H>): void;
4
- type Selector = string | Node | undefined | null;
5
- type Selectors = Selector[];
6
- export declare function updateviewuc(uc: IUpdateContext, ...sels: Selectors): void;
7
- export declare function updateview(...sels: Selectors): void;
8
- export {};
1
+ import { Expr, H } from './h';
2
+ export declare function createElement(tag: string): Element;
3
+ export declare function patch(e: Node | null, h: Expr<H>): void;
4
+ type Selector = string | Node | undefined | null;
5
+ type Selectors = Selector[];
6
+ export declare function updateviewuc(uc: IUpdateContext, ...sels: Selectors): void;
7
+ export declare function updateview(...sels: Selectors): void;
8
+ export {};
9
9
  //# sourceMappingURL=jmx.d.ts.map
package/dist/jmx.js CHANGED
@@ -1,135 +1,135 @@
1
- import { rebind } from './base';
2
- export function createElement(tag) {
3
- let ns = window.jmx?.getnamespace?.(tag);
4
- return ns ? document.createElementNS(ns, tag) : document.createElement(tag);
5
- }
6
- let evaluate = (expr) => (expr instanceof Function ? expr() : expr);
7
- let removeexcesschildren = (n, i) => {
8
- let c;
9
- while ((c = n.childNodes[i])) {
10
- c.remove();
11
- }
12
- };
13
- let iswebcomponent = (h) => h.tag.includes('-');
14
- let isclasscomponent = (h) => h.tag?.prototype?.view;
15
- let iselement = (h) => typeof h.tag == 'string';
16
- let isfragment = (h) => {
17
- return h.tag == undefined && h.cn != undefined;
18
- };
19
- let isobject = (o) => typeof o === 'object';
20
- let isproperty = (name, value) => ['value', 'checked', 'disabled', 'className', 'style', 'href', 'src', 'selected', 'readOnly', 'tabIndex'].includes(name) ||
21
- value instanceof Object ||
22
- value instanceof Function;
23
- let setprops = (e, newprops = {}) => {
24
- let oldprops = evaluate(e.h?.p) ?? {};
25
- for (let p in oldprops)
26
- !(p in newprops) && isproperty(p, oldprops[p]) ? (e[p] = null) : e.removeAttribute(p);
27
- for (let p in newprops)
28
- isproperty(p, newprops[p]) ? (e[p] = newprops[p]) : e.setAttribute(p, newprops[p]);
29
- };
30
- function sync(p, i, h) {
31
- h = evaluate(h);
32
- if (h === null || h === undefined)
33
- return i;
34
- let c = p.childNodes[i];
35
- function synctextnode(text) {
36
- if (c && c.nodeType == 3) {
37
- if (c.textContent != text)
38
- c.textContent = text;
39
- }
40
- else {
41
- let tn = document.createTextNode(text);
42
- c ? c.replaceWith(tn) : p.appendChild(tn);
43
- }
44
- }
45
- if (isobject(h)) {
46
- function syncchildren(p, h, i) {
47
- evaluate(h.cn)
48
- ?.flat()
49
- .forEach(hc => (i = sync(p, i, hc)));
50
- return i;
51
- }
52
- if (isfragment(h))
53
- return syncchildren(p, h, i);
54
- const props = evaluate(h.p);
55
- if (iselement(h)) {
56
- let n;
57
- if (c?.tagName?.toLowerCase() != h.tag.toLowerCase()) {
58
- n = createElement(h.tag);
59
- c ? c.replaceWith(n) : p.appendChild(n);
60
- setprops(n, props);
61
- props?.mounted?.(n);
62
- }
63
- else {
64
- n = c;
65
- setprops(n, props);
66
- if (props?.update?.(c, globaluc))
67
- return i + 1;
68
- }
69
- n.h = h;
70
- if (!globaluc.patchElementOnly && !iswebcomponent(h)) {
71
- const j = syncchildren(n, h, 0);
72
- removeexcesschildren(n, j);
73
- }
74
- return i + 1;
75
- }
76
- switch (typeof h.tag) {
77
- case 'function':
78
- let isupdate = c?.h?.tag == h.tag;
79
- let ci;
80
- if (isclasscomponent(h)) {
81
- h.i = ci = c?.h?.i ?? rebind(new h.tag(props));
82
- ci.props = props;
83
- if (isupdate && ci.update(globaluc))
84
- return i + 1;
85
- }
86
- let hr = ci?.view ? ci?.view() : h.tag(props, evaluate(h.cn));
87
- if (hr === undefined || hr == null)
88
- return i;
89
- let j = sync(p, i, hr);
90
- let cn = p.childNodes[i];
91
- cn.h = h;
92
- if (ci)
93
- ci.element = cn;
94
- if (!isupdate)
95
- ci?.mounted?.();
96
- return j;
97
- case 'object':
98
- return sync(p, i, h.tag);
99
- }
100
- }
101
- synctextnode(h);
102
- return i + 1;
103
- }
104
- let globaluc = {};
105
- export function patch(e, h) {
106
- if (!e)
107
- return;
108
- if (globaluc.replace)
109
- e.replaceChildren();
110
- const p = e.parentElement;
111
- const i = [].indexOf.call(p.childNodes, e);
112
- sync(p, i, h);
113
- }
114
- export function updateviewuc(uc, ...sels) {
115
- {
116
- globaluc = uc;
117
- updateviewinternal(...sels);
118
- }
119
- }
120
- export function updateview(...sels) {
121
- {
122
- globaluc = {};
123
- updateviewinternal(...sels);
124
- }
125
- }
126
- function updateviewinternal(...sels) {
127
- if (!sels.length)
128
- sels.push('body');
129
- sels.flatMap(s => (typeof s == 'string' ? [...document.querySelectorAll(s)] : s ? [s] : [])).forEach(e => {
130
- if (!e?.h)
131
- throw 'jmx: no h exists on the node';
132
- patch(e, e.h);
133
- });
134
- }
1
+ import { rebind } from './base';
2
+ export function createElement(tag) {
3
+ let ns = window.jmx?.getnamespace?.(tag);
4
+ return ns ? document.createElementNS(ns, tag) : document.createElement(tag);
5
+ }
6
+ let evaluate = (expr) => (expr instanceof Function ? expr() : expr);
7
+ let removeexcesschildren = (n, i) => {
8
+ let c;
9
+ while ((c = n.childNodes[i])) {
10
+ c.remove();
11
+ }
12
+ };
13
+ let iswebcomponent = (h) => h.tag.includes('-');
14
+ let isclasscomponent = (h) => h.tag?.prototype?.view;
15
+ let iselement = (h) => typeof h.tag == 'string';
16
+ let isfragment = (h) => {
17
+ return h.tag == undefined && h.cn != undefined;
18
+ };
19
+ let isobject = (o) => typeof o === 'object';
20
+ let isproperty = (name, value) => ['value', 'checked', 'disabled', 'className', 'style', 'href', 'src', 'selected', 'readOnly', 'tabIndex'].includes(name) ||
21
+ value instanceof Object ||
22
+ value instanceof Function;
23
+ let setprops = (e, newprops = {}) => {
24
+ let oldprops = evaluate(e.h?.p) ?? {};
25
+ for (let p in oldprops)
26
+ !(p in newprops) && isproperty(p, oldprops[p]) ? (e[p] = null) : e.removeAttribute(p);
27
+ for (let p in newprops)
28
+ isproperty(p, newprops[p]) ? (e[p] = newprops[p]) : e.setAttribute(p, newprops[p]);
29
+ };
30
+ function sync(p, i, h) {
31
+ h = evaluate(h);
32
+ if (h === null || h === undefined)
33
+ return i;
34
+ let c = p.childNodes[i];
35
+ function synctextnode(text) {
36
+ if (c && c.nodeType == 3) {
37
+ if (c.textContent != text)
38
+ c.textContent = text;
39
+ }
40
+ else {
41
+ let tn = document.createTextNode(text);
42
+ c ? c.replaceWith(tn) : p.appendChild(tn);
43
+ }
44
+ }
45
+ if (isobject(h)) {
46
+ function syncchildren(p, h, i) {
47
+ evaluate(h.cn)
48
+ ?.flat()
49
+ .forEach(hc => (i = sync(p, i, hc)));
50
+ return i;
51
+ }
52
+ if (isfragment(h))
53
+ return syncchildren(p, h, i);
54
+ const props = evaluate(h.p);
55
+ if (iselement(h)) {
56
+ let n;
57
+ if (c?.tagName?.toLowerCase() != h.tag.toLowerCase()) {
58
+ n = createElement(h.tag);
59
+ c ? c.replaceWith(n) : p.appendChild(n);
60
+ setprops(n, props);
61
+ props?.mounted?.(n);
62
+ }
63
+ else {
64
+ n = c;
65
+ setprops(n, props);
66
+ if (props?.update?.(c, globaluc))
67
+ return i + 1;
68
+ }
69
+ n.h = h;
70
+ if (!globaluc.patchElementOnly && !iswebcomponent(h)) {
71
+ const j = syncchildren(n, h, 0);
72
+ removeexcesschildren(n, j);
73
+ }
74
+ return i + 1;
75
+ }
76
+ switch (typeof h.tag) {
77
+ case 'function':
78
+ let isupdate = c?.h?.tag == h.tag;
79
+ let ci;
80
+ if (isclasscomponent(h)) {
81
+ h.i = ci = c?.h?.i ?? rebind(new h.tag(props));
82
+ ci.props = props;
83
+ if (isupdate && ci.update(globaluc))
84
+ return i + 1;
85
+ }
86
+ let hr = ci?.view ? ci?.view() : h.tag(props, evaluate(h.cn));
87
+ if (hr === undefined || hr == null)
88
+ return i;
89
+ let j = sync(p, i, hr);
90
+ let cn = p.childNodes[i];
91
+ cn.h = h;
92
+ if (ci)
93
+ ci.element = cn;
94
+ if (!isupdate)
95
+ ci?.mounted?.();
96
+ return j;
97
+ case 'object':
98
+ return sync(p, i, h.tag);
99
+ }
100
+ }
101
+ synctextnode(h);
102
+ return i + 1;
103
+ }
104
+ let globaluc = {};
105
+ export function patch(e, h) {
106
+ if (!e)
107
+ return;
108
+ if (globaluc.replace)
109
+ e.replaceChildren();
110
+ const p = e.parentElement;
111
+ const i = [].indexOf.call(p.childNodes, e);
112
+ sync(p, i, h);
113
+ }
114
+ export function updateviewuc(uc, ...sels) {
115
+ {
116
+ globaluc = uc;
117
+ updateviewinternal(...sels);
118
+ }
119
+ }
120
+ export function updateview(...sels) {
121
+ {
122
+ globaluc = {};
123
+ updateviewinternal(...sels);
124
+ }
125
+ }
126
+ function updateviewinternal(...sels) {
127
+ if (!sels.length)
128
+ sels.push('body');
129
+ sels.flatMap(s => (typeof s == 'string' ? [...document.querySelectorAll(s)] : s ? [s] : [])).forEach(e => {
130
+ if (!e?.h)
131
+ throw 'jmx: no h exists on the node';
132
+ patch(e, e.h);
133
+ });
134
+ }
135
135
  //# sourceMappingURL=jmx.js.map