@snupo/jmc 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/coverage/base.css +224 -0
- package/coverage/base.ts.html +172 -0
- package/coverage/block-navigation.js +87 -0
- package/coverage/coverage-final.json +7 -0
- package/coverage/favicon.png +0 -0
- package/coverage/h.ts.html +490 -0
- package/coverage/index.html +191 -0
- package/coverage/index.ts.html +97 -0
- package/coverage/jmc.ts.html +562 -0
- package/coverage/jsx.ts.html +2446 -0
- package/coverage/lib.ts.html +157 -0
- package/coverage/prettify.css +1 -0
- package/coverage/prettify.js +2 -0
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +210 -0
- package/dist/app.js +65602 -0
- package/dist/magic-string.es-hwNd2_8t.js +1012 -0
- package/dist/rolldown-runtime-C_rDcCAf.js +43 -0
- package/dist/src/base.d.ts +7 -0
- package/dist/src/base.d.ts.map +1 -0
- package/dist/src/base.js +23 -0
- package/dist/src/base.js.map +1 -0
- package/dist/src/h.d.ts +65 -0
- package/dist/src/h.d.ts.map +1 -0
- package/dist/src/h.js +21 -0
- package/dist/src/h.js.map +1 -0
- package/dist/src/index.d.ts +6 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +6 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/jmc.d.ts +5 -0
- package/dist/src/jmc.d.ts.map +1 -0
- package/dist/src/jmc.js +123 -0
- package/dist/src/jmc.js.map +1 -0
- package/dist/src/jsx.d.ts +697 -0
- package/dist/src/jsx.d.ts.map +1 -0
- package/dist/src/jsx.js +21 -0
- package/dist/src/jsx.js.map +1 -0
- package/dist/src/lib.d.ts +21 -0
- package/dist/src/lib.d.ts.map +1 -0
- package/dist/src/lib.js +19 -0
- package/dist/src/lib.js.map +1 -0
- package/package.json +29 -0
- package/src/base.ts +27 -0
- package/src/h.ts +118 -0
- package/src/index.ts +5 -0
- package/src/jmc.ts +139 -0
- package/src/jsx.ts +787 -0
- package/src/lib.ts +25 -0
- package/tests/classcomponent.test.tsx +170 -0
- package/tests/functioncomponent.test.tsx +41 -0
- package/tests/h.test.tsx +312 -0
- package/tests/jmc.test.tsx +329 -0
- package/tsconfig.build.json +12 -0
- package/tsconfig.json +42 -0
- package/tsdown.config.ts +5 -0
- package/vite.config.mts +31 -0
- package/vitest.config.mts +34 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
+
get: ((k) => from[k]).bind(null, key),
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
20
|
+
value: mod,
|
|
21
|
+
enumerable: true
|
|
22
|
+
}) : target, mod));
|
|
23
|
+
(() => {
|
|
24
|
+
var table = /* @__PURE__ */ new Uint8Array(128);
|
|
25
|
+
for (var i = 0; i < 64; i++) table[i < 26 ? i + 65 : i < 52 ? i + 71 : i < 62 ? i - 4 : i * 4 - 205] = i;
|
|
26
|
+
return (base64) => {
|
|
27
|
+
var n = base64.length, bytes = new Uint8Array((n - (base64[n - 1] == "=") - (base64[n - 2] == "=")) * 3 / 4 | 0);
|
|
28
|
+
for (var i = 0, j = 0; i < n;) {
|
|
29
|
+
var c0 = table[base64.charCodeAt(i++)], c1 = table[base64.charCodeAt(i++)];
|
|
30
|
+
var c2 = table[base64.charCodeAt(i++)], c3 = table[base64.charCodeAt(i++)];
|
|
31
|
+
bytes[j++] = c0 << 2 | c1 >> 4;
|
|
32
|
+
bytes[j++] = c1 << 4 | c2 >> 2;
|
|
33
|
+
bytes[j++] = c2 << 6 | c3;
|
|
34
|
+
}
|
|
35
|
+
return bytes;
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
38
|
+
((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { get: (a, b) => (typeof require !== "undefined" ? require : a)[b] }) : x)(function(x) {
|
|
39
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
40
|
+
throw Error("Calling `require` for \"" + x + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
|
|
41
|
+
});
|
|
42
|
+
//#endregion
|
|
43
|
+
export { __toESM as n, __commonJSMin as t };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare function rebind<T extends object>(o: T, proto?: any): T;
|
|
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
|
+
export declare function closestby(e: Node | null, pred: (e: Node) => boolean): Node | null;
|
|
7
|
+
//# sourceMappingURL=base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/base.ts"],"names":[],"mappings":"AAAA,wBAAgB,MAAM,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,MAA2B,GAAG,CAAC,CAKlF;AAED,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,QAAkC;AAE9E,eAAO,MAAM,eAAe,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,MAAM,EAAE,GAAG,KAAK,IAAI,MAY3H,CAAA;AAEF,eAAO,MAAM,aAAa,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,CAAC,KAAG,CAA8I,CAAA;AAClN,eAAO,MAAM,oBAAoB,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,WAAW,MAAM,KAAK,CAAC,KAAG,CAAiJ,CAAA;AAE7O,wBAAgB,SAAS,CAAC,CAAC,EAAE,IAAI,GAAG,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,IAAI,KAAK,OAAO,GAAG,IAAI,GAAG,IAAI,CAAsE"}
|
package/dist/src/base.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export function rebind(o, proto = Object.getPrototypeOf(o)) {
|
|
2
|
+
Object.entries(Object.getOwnPropertyDescriptors(proto))
|
|
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
|
+
export function closestby(e, pred) { return (e == null || pred(e)) ? e : closestby(e.parentNode, pred); }
|
|
23
|
+
//# sourceMappingURL=base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/base.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,MAAM,CAAmB,CAAI,EAAE,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC;IAC3E,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,yBAAyB,CAAC,KAAK,CAAC,CAAC;SAClD,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,IAAI,aAAa,IAAI,CAAC,CAAC,KAAK,YAAY,QAAQ,CAAC;SAC3E,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,CAAE,CAAS,CAAC,IAAI,CAAC,GAAI,CAAS,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;IACrE,OAAO,CAAC,CAAA;AACZ,CAAC;AAED,MAAM,UAAU,KAAK,CAAC,CAAsB,IAAI,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC,CAAA,CAAC,CAAC;AAE9E,MAAM,CAAC,M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C,CAAC,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA,CAAC,CAAC","sourcesContent":["export function rebind<T extends object>(o: T, proto = Object.getPrototypeOf(o)): T {\r\n Object.entries(Object.getOwnPropertyDescriptors(proto))\r\n .filter(([name, p]) => name != 'constructor' && p.value instanceof Function)\r\n .forEach(([name]) => (o as any)[name] = (o as any)[name].bind(o))\r\n return o\r\n}\r\n\r\nexport function mount(o: Record<string, any>) { Object.assign(globalThis, o) }\r\n\r\nexport const loggedmethodsex = <T extends Record<string, any>>(o: T, logger: (name: string, args: any[], result: any) => void) => new Proxy(o, {\r\n get(target, name: string, receiver) {\r\n if (typeof target[name] === \"function\") {\r\n return function (this: T, ...args: any[]) {\r\n\r\n logger(name, args, undefined)\r\n let r = target[name].apply(this, args)\r\n return r\r\n }\r\n }\r\n return Reflect.get(target, name, receiver)\r\n },\r\n})\r\n\r\nexport const loggedmethods = <T extends Record<string, any>>(o: T): T => loggedmethodsex(o, (name, args, result) => console.log(\"%c\" + name, \"background:#585059;color:white;padding:2px;font-weight:bold\", args))\r\nexport const loggedmethodscolored = <T extends Record<string, any>>(bgcolor: string, o: T): T => loggedmethodsex(o, (name, args, result) => console.log(\"%c\" + name, `background:${bgcolor};color:white;padding:2px;font-weight:bold`, args))\r\n\r\nexport function closestby(e: Node | null, pred: (e: Node) => boolean): Node | null { return (e == null || pred(e)) ? e : closestby(e.parentNode, pred) }\r\n"]}
|
package/dist/src/h.d.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
export type Func<T> = () => T;
|
|
2
|
+
export type Expr<T> = T | Func<T>;
|
|
3
|
+
export type J = Record<string, any>;
|
|
4
|
+
export type Selector = string | Node | undefined | null;
|
|
5
|
+
export type Selectors = Selector[];
|
|
6
|
+
export type FComponent = (props: J | undefined, children?: Children) => HElement;
|
|
7
|
+
export interface IClassComponent {
|
|
8
|
+
element: Node;
|
|
9
|
+
props?: Record<string, any>;
|
|
10
|
+
view(): H;
|
|
11
|
+
update(uc: IUpdateContext): boolean | void;
|
|
12
|
+
mounted?(): void;
|
|
13
|
+
}
|
|
14
|
+
export interface CComponent {
|
|
15
|
+
new (props: any): IClassComponent;
|
|
16
|
+
}
|
|
17
|
+
export type Children = (H | undefined)[];
|
|
18
|
+
export type HText = string | number | boolean;
|
|
19
|
+
export type HFragment = {
|
|
20
|
+
kind: HKind.Fragment;
|
|
21
|
+
cn?: Children;
|
|
22
|
+
};
|
|
23
|
+
export type HElement = {
|
|
24
|
+
kind: HKind.Element;
|
|
25
|
+
tag: string;
|
|
26
|
+
p?: J;
|
|
27
|
+
cn?: Children;
|
|
28
|
+
};
|
|
29
|
+
export type HFunctionComponent = {
|
|
30
|
+
kind: HKind.FunctionComponent;
|
|
31
|
+
tag: FComponent;
|
|
32
|
+
p?: J;
|
|
33
|
+
cn?: Children;
|
|
34
|
+
};
|
|
35
|
+
export type HClassComponent = {
|
|
36
|
+
kind: HKind.ClassComponent;
|
|
37
|
+
tag: CComponent;
|
|
38
|
+
p?: J;
|
|
39
|
+
cn?: Children;
|
|
40
|
+
i?: IClassComponent;
|
|
41
|
+
};
|
|
42
|
+
export declare const enum HKind {
|
|
43
|
+
Element = 1,
|
|
44
|
+
FunctionComponent = 2,
|
|
45
|
+
ClassComponent = 3,
|
|
46
|
+
Fragment = 4
|
|
47
|
+
}
|
|
48
|
+
export type HComp = HFunctionComponent | HClassComponent;
|
|
49
|
+
export type H = (HText & {
|
|
50
|
+
kind?: undefined;
|
|
51
|
+
}) | HElement | HFunctionComponent | HClassComponent | HFragment;
|
|
52
|
+
export interface IUpdateContext {
|
|
53
|
+
patchElementOnly?: boolean;
|
|
54
|
+
replace?: boolean;
|
|
55
|
+
}
|
|
56
|
+
declare global {
|
|
57
|
+
interface Node {
|
|
58
|
+
h?: H & {
|
|
59
|
+
p?: J;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export declare function jsx(tag: any, p: any, ...cn: any[]): HElement | HFunctionComponent | HClassComponent | HFragment;
|
|
64
|
+
export declare function jsxf(props: any, ...cn: any[]): HFragment;
|
|
65
|
+
//# sourceMappingURL=h.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"h.d.ts","sourceRoot":"","sources":["../../src/h.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,IAAI,CAAC,CAAC,IAAI,MAAM,CAAC,CAAA;AAC7B,MAAM,MAAM,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA;AAEjC,MAAM,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;AAGnC,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI,CAAA;AACvD,MAAM,MAAM,SAAS,GAAG,QAAQ,EAAE,CAAA;AAElC,MAAM,MAAM,UAAU,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,SAAS,EAAE,QAAQ,CAAC,EAAE,QAAQ,KAAK,QAAQ,CAAA;AAGhF,MAAM,WAAW,eAAe;IAC5B,OAAO,EAAE,IAAI,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC3B,IAAI,IAAI,CAAC,CAAA;IACT,MAAM,CAAC,EAAE,EAAE,cAAc,GAAG,OAAO,GAAG,IAAI,CAAA;IAC1C,OAAO,CAAC,IAAI,IAAI,CAAA;CAEnB;AAED,MAAM,WAAW,UAAU;IACvB,KAAI,KAAK,EAAE,GAAG,GAAG,eAAe,CAAA;CACnC;AAYD,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,GAAG,SAAS,CAAC,EAAE,CAAA;AAExC,MAAM,MAAM,KAAK,GACX,MAAM,GACN,MAAM,GACN,OAAO,CAAA;AAEb,MAAM,MAAM,SAAS,GAAG;IACpB,IAAI,EAAE,KAAK,CAAC,QAAQ,CAAA;IACpB,EAAE,CAAC,EAAE,QA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AG,EAAE,GAAG,EAAE,EAAE,GAAG,EAAE,GAAG,QAAQ,GAAG,kBAAkB,GAAG,eAAe,GAAG,SAAS,CAY/G;AAGD,wBAAgB,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,GAAG,EAAE,GAAG,SAAS,CAAY"}
|
package/dist/src/h.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// jmx internal types
|
|
2
|
+
// the following types describe the js expression we get from tsx after conversion be our jmx plugin
|
|
3
|
+
// they can be useful for users as well, components might return them.
|
|
4
|
+
let isclass = (X) => /^class\s|^class\{/.test(X.toString());
|
|
5
|
+
export function jsx(tag, p, ...cn) {
|
|
6
|
+
if (tag?.kind)
|
|
7
|
+
return tag; // already an H node, flatten tree
|
|
8
|
+
let kind = tag == jsxf ? 4 /* HKind.Fragment */ : tag instanceof Function ? (isclass(tag) ? 3 /* HKind.ClassComponent */ : 2 /* HKind.FunctionComponent */)
|
|
9
|
+
: 1 /* HKind.Element */;
|
|
10
|
+
let h = { kind };
|
|
11
|
+
if (kind != 4 /* HKind.Fragment */)
|
|
12
|
+
h.tag = tag;
|
|
13
|
+
if (p)
|
|
14
|
+
h.p = p;
|
|
15
|
+
if (cn?.length)
|
|
16
|
+
h.cn = cn;
|
|
17
|
+
return h;
|
|
18
|
+
}
|
|
19
|
+
// declare fragment function with similar signature as a function component
|
|
20
|
+
export function jsxf(props, ...cn) { throw 2; }
|
|
21
|
+
//# sourceMappingURL=h.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"h.js","sourceRoot":"","sources":["../../src/h.ts"],"names":[],"mappings":"AAAA,qBAAqB;AACrB,oGAAoG;AACpG,sEAAsE;AAkGtE,IAAI,OAAO,GAAG,CAAC,CAAW,EAAE,EAAE,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAA;AAErE,MAAM,UAAU,GAAG,CAAC,GAAQ,EAAE,CAAM,EAAE,GAAG,EAAS;IAC9C,IAAI,GAAG,EAAE,IAAI;QAAE,OAAO,GAAG,CAAA,CAAC,kCAAkC;IAE5D,IAAI,IAAI,GAAG,GAAG,IAAI,IAAI,CAAC,CAAC,wBACpB,CAAC,CAAC,GAAG,YAAY,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,8BAAsB,CAAC,gCAAwB,CAAC;QAC3F,CAAC,sBAAc,CAAA;IAEnB,IAAI,CAAC,GAAQ,EAAE,IAAI,EAAE,CAAA;IACrB,IAAI,IAAI,0BAAkB;QAAE,CAAC,CAAC,GAAG,GAAG,GAAG,CAAA;IACvC,IAAI,CAAC;QAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;IACd,IAAI,EAAE,EAAE,MAAM;QAAE,CAAC,CAAC,EAAE,GAAG,EAAE,CAAA;IACzB,OAAO,CAAC,CAAA;AACZ,CAAC;AAED,2EAA2E;AAC3E,MAAM,UAAU,IAAI,CAAC,KAAU,EAAE,GAAG,EAAS,IAAe,MAAM,CAAC,CAAA,CAAC,CAAC","sourcesContent":["// jmx internal types\r\n// the following types describe the js expression we get from tsx after conversion be our jmx plugin\r\n// they can be useful for users as well, components might return them.\r\n\r\nexport type Func<T> = () => T\r\nexport type Expr<T> = T | Func<T>\r\n\r\nexport type J = Record<string, any> // a json record\r\n\r\n// Overload signatures\r\nexport type Selector = string | Node | undefined | null\r\nexport type Selectors = Selector[]\r\n\r\nexport type FComponent = (props: J | undefined, children?: Children) => HElement // show an example for usage of children\r\n//export type FComponentT<P> = (pcn: P, cn?: Children) => H | void\r\n\r\nexport interface IClassComponent {\r\n element: Node\r\n props?: Record<string, any>\r\n view(): H\r\n update(uc: IUpdateContext): boolean | void\r\n mounted?(): void\r\n //new(props: any): IClassComponent\r\n}\r\n\r\nexport interface CComponent {\r\n new(props: any): IClassComponent\r\n}\r\n\r\n// export interface FComponentState<P, S> {\r\n// (this: S & {\r\n// element: HTMLElement;\r\n// update: (...ss: Selectors) => void //Action | Selectors | Selector\r\n// uc?: Selector | Selectors\r\n// }, p: P): H;\r\n// state?: S;\r\n// }\r\n\r\n\r\nexport type Children = (H | undefined)[]\r\n\r\nexport type HText =\r\n | string // text node\r\n | number // text node\r\n | boolean // do not allow boolean, that\r\n\r\nexport type HFragment = {\r\n kind: HKind.Fragment\r\n cn?: Children\r\n}\r\n\r\nexport type HElement = {\r\n kind: HKind.Element\r\n tag: string\r\n p?: J\r\n cn?: Children\r\n}\r\n\r\nexport type HFunctionComponent = {\r\n kind: HKind.FunctionComponent\r\n tag: FComponent\r\n p?: J\r\n cn?: Children\r\n}\r\n\r\nexport type HClassComponent = {\r\n kind: HKind.ClassComponent\r\n tag: CComponent\r\n p?: J\r\n cn?: Children\r\n i?: IClassComponent\r\n}\r\n\r\nexport const enum HKind {\r\n Element = 1,\r\n FunctionComponent = 2,\r\n ClassComponent = 3,\r\n Fragment = 4\r\n}\r\n\r\nexport type HComp = HFunctionComponent | HClassComponent\r\n\r\nexport type H =\r\n | HText & { kind?: undefined } // text nodes never have a kind. but this type addition makes H a full DU\r\n | HElement\r\n | HFunctionComponent\r\n | HClassComponent\r\n | HFragment\r\n\r\nexport interface IUpdateContext {\r\n patchElementOnly?: boolean\r\n replace?: boolean\r\n}\r\n\r\ndeclare global {\r\n interface Node {\r\n h?: H & { p?: J }\r\n }\r\n}\r\n\r\nlet isclass = (X: Function) => /^class\\s|^class\\{/.test(X.toString())\r\n\r\nexport function jsx(tag: any, p: any, ...cn: any[]): HElement | HFunctionComponent | HClassComponent | HFragment {\r\n if (tag?.kind) return tag // already an H node, flatten tree\r\n\r\n let kind = tag == jsxf ? HKind.Fragment\r\n : tag instanceof Function ? (isclass(tag) ? HKind.ClassComponent : HKind.FunctionComponent)\r\n : HKind.Element\r\n\r\n let h: any = { kind }\r\n if (kind != HKind.Fragment) h.tag = tag\r\n if (p) h.p = p\r\n if (cn?.length) h.cn = cn\r\n return h\r\n}\r\n\r\n// declare fragment function with similar signature as a function component\r\nexport function jsxf(props: any, ...cn: any[]): HFragment { throw 2 }"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAA;AACrB,cAAc,OAAO,CAAA;AACrB,cAAc,QAAQ,CAAA;AACtB,cAAc,OAAO,CAAA;AACrB,cAAc,KAAK,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAA;AACrB,cAAc,OAAO,CAAA;AACrB,cAAc,QAAQ,CAAA;AACtB,cAAc,OAAO,CAAA;AACrB,cAAc,KAAK,CAAA","sourcesContent":["export * from './jmc'\r\nexport * from './lib'\r\nexport * from './base'\r\nexport * from './jsx'\r\nexport * from './h'"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { H, IUpdateContext, Selectors } from './h';
|
|
2
|
+
export declare function patch(e: Node | null, h: H, uc?: IUpdateContext): void;
|
|
3
|
+
export declare function updateviewuc(u: IUpdateContext, ...sels: Selectors): void;
|
|
4
|
+
export declare function updateview(...sels: Selectors): void;
|
|
5
|
+
//# sourceMappingURL=jmc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jmc.d.ts","sourceRoot":"","sources":["../../src/jmc.ts"],"names":[],"mappings":"AACA,OAAO,EAAQ,CAAC,EAAmB,cAAc,EAAe,SAAS,EAAY,MAAM,KAAK,CAAA;AAwHhG,wBAAgB,KAAK,CAAC,CAAC,EAAE,IAAI,GAAG,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,GAAS,cAAc,QAQpE;AAED,wBAAgB,YAAY,CAAC,CAAC,EAAE,cAAc,EAAE,GAAG,IAAI,EAAE,SAAS,GAAG,IAAI,CAAmC;AAC5G,wBAAgB,UAAU,CAAC,GAAG,IAAI,EAAE,SAAS,GAAG,IAAI,CAAoC"}
|
package/dist/src/jmc.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { rebind } from './base';
|
|
2
|
+
let removeexcesschildren = (n, i) => {
|
|
3
|
+
let c;
|
|
4
|
+
while ((c = n.childNodes[i])) {
|
|
5
|
+
try {
|
|
6
|
+
c.remove();
|
|
7
|
+
}
|
|
8
|
+
catch (_) { } // due to blur-event-handlers, this can fail
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
let iswebcomponent = (h) => h.tag.includes('-');
|
|
12
|
+
let isproperty = (e, name, value) => name in e ||
|
|
13
|
+
value instanceof Object ||
|
|
14
|
+
value instanceof Function;
|
|
15
|
+
let setprops = (e, old, now) => {
|
|
16
|
+
old ??= {};
|
|
17
|
+
now ??= {};
|
|
18
|
+
for (let p in old)
|
|
19
|
+
if (!(p in now))
|
|
20
|
+
isproperty(e, p, old[p])
|
|
21
|
+
? e[p] = typeof old[p] === 'boolean' ? false : '' // not sure about this. safest handling of initial values would be to track them. tbd: unit test
|
|
22
|
+
: e.removeAttribute(p);
|
|
23
|
+
for (let p in now)
|
|
24
|
+
isproperty(e, p, now[p])
|
|
25
|
+
? e[p] = now[p]
|
|
26
|
+
: e.setAttribute(p, now[p]);
|
|
27
|
+
};
|
|
28
|
+
/** synchronizes children starting at the i-th element. returns the index of the last child synchronized */
|
|
29
|
+
let syncchildren = (uc, p, cn, i, ns) => {
|
|
30
|
+
cn.flat().forEach(hc => (i = sync(uc, p, i, hc, ns)));
|
|
31
|
+
return i;
|
|
32
|
+
};
|
|
33
|
+
function sync(uc, parent, i, h, ns) {
|
|
34
|
+
// console.log('%csync2', "background:orange", parent.tagName, i, h, ns)
|
|
35
|
+
if (h === null || h === undefined)
|
|
36
|
+
return i; // skip. keep 0 and false renderable, per comment below
|
|
37
|
+
let c = parent.childNodes[i];
|
|
38
|
+
switch (h.kind) {
|
|
39
|
+
case 1 /* HKind.Element */:
|
|
40
|
+
let n;
|
|
41
|
+
let { tag, cn, p } = h;
|
|
42
|
+
cn ??= [];
|
|
43
|
+
if (c?.tagName?.toLowerCase() != tag.toLowerCase()) {
|
|
44
|
+
n = document.createElementNS(ns = p?.xmlns ?? ns, tag); // replace namespace with propertyvalue if set. otherwise pass forward to children
|
|
45
|
+
c ? c.replaceWith(n) : parent.appendChild(n);
|
|
46
|
+
setprops(n, {}, p);
|
|
47
|
+
p?.mounted?.(n);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
n = c;
|
|
51
|
+
setprops(n, n.h?.p, p); // tbd: this is wrong - try to break this with property updates, just patch sequences - create an own patch test file
|
|
52
|
+
if (p?.update?.(c, uc))
|
|
53
|
+
return i + 1;
|
|
54
|
+
}
|
|
55
|
+
n.h = h;
|
|
56
|
+
if (!uc.patchElementOnly && !iswebcomponent(h)) {
|
|
57
|
+
// tbd: make "island" attribute
|
|
58
|
+
const j = syncchildren(uc, n, cn, 0, ns);
|
|
59
|
+
removeexcesschildren(n, j);
|
|
60
|
+
}
|
|
61
|
+
return i + 1;
|
|
62
|
+
case 4 /* HKind.Fragment */:
|
|
63
|
+
return syncchildren(uc, parent, h.cn ?? [], i, ns);
|
|
64
|
+
case 2 /* HKind.FunctionComponent */:
|
|
65
|
+
{
|
|
66
|
+
let hr = h.tag(h.p, h.cn);
|
|
67
|
+
let j = sync(uc, parent, i, hr, ns);
|
|
68
|
+
let n = parent.childNodes[i]; // now the dom element exists, unless the function returned undefined or null
|
|
69
|
+
if (n)
|
|
70
|
+
n.h = h;
|
|
71
|
+
return j;
|
|
72
|
+
}
|
|
73
|
+
case 3 /* HKind.ClassComponent */:
|
|
74
|
+
{
|
|
75
|
+
let isupdate = c?.h?.tag == h.tag;
|
|
76
|
+
let ci = h.i = isupdate ? h.i : rebind(new h.tag(h.p));
|
|
77
|
+
ci.props = h.p; // for the update case we set props
|
|
78
|
+
// if component instance returns truthy for update(), then this update substitutes syncing
|
|
79
|
+
if (isupdate && ci.update?.(uc))
|
|
80
|
+
return i + 1;
|
|
81
|
+
let hr = ci.view();
|
|
82
|
+
let j = sync(uc, parent, i, hr, ns);
|
|
83
|
+
let n = parent.childNodes[i];
|
|
84
|
+
if (n)
|
|
85
|
+
n.h = h; // tbd: this could disallow component updates ?? i guess it is right
|
|
86
|
+
ci.element = n;
|
|
87
|
+
if (!isupdate)
|
|
88
|
+
ci?.mounted?.();
|
|
89
|
+
return j;
|
|
90
|
+
}
|
|
91
|
+
case undefined:
|
|
92
|
+
// textnode
|
|
93
|
+
let s = h; // coerce type as the js runtime does
|
|
94
|
+
if (c?.nodeType == 3 /* NodeType.TextNode */) {
|
|
95
|
+
if (c.textContent != s)
|
|
96
|
+
c.textContent = s; // firefox updates equal text, loosing existing text selection
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
c ? c.replaceWith(s) : parent.append(s);
|
|
100
|
+
}
|
|
101
|
+
return i + 1;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
export function patch(e, h, uc = {}) {
|
|
105
|
+
if (!e)
|
|
106
|
+
return;
|
|
107
|
+
delete uc.patchElementOnly;
|
|
108
|
+
if (uc.replace)
|
|
109
|
+
e.replaceChildren();
|
|
110
|
+
const p = e.parentElement;
|
|
111
|
+
const i = [].indexOf.call(p.childNodes, e);
|
|
112
|
+
// always called deferred, because removing elements can trigger events and their handlers (like blur)
|
|
113
|
+
sync(uc, p, i, h, p.namespaceURI); // is this safe? use default html namespace?
|
|
114
|
+
}
|
|
115
|
+
export function updateviewuc(u, ...sels) { updateviewinternal(u, ...sels); }
|
|
116
|
+
export function updateview(...sels) { updateviewinternal({}, ...sels); }
|
|
117
|
+
function updateviewinternal(uc, ...sels) {
|
|
118
|
+
if (!sels.length)
|
|
119
|
+
sels.push('body');
|
|
120
|
+
sels.flatMap(s => (typeof s == 'string' ? [...document.querySelectorAll(s)] : s ? [s] : []))
|
|
121
|
+
.forEach(e => { patch(e, e.h, uc); });
|
|
122
|
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,MAAM;QAAE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IACnC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;SACvF,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAE,EAAE,EAAE,CAAC,CAAA,CAAC,CAAC,CAAC,CAAA;AAC7C,CAAC","sourcesContent":["import { rebind } from './base'\r\nimport { Expr, H, HElement, HKind, IUpdateContext, J, Selector, Selectors, Children } from './h'\r\n\r\nconst enum NodeType { // vaporizes (but for that must be in this file, otherwise not)\r\n TextNode = 3\r\n}\r\n\r\nlet removeexcesschildren = (n: Element, i: number) => {\r\n let c: ChildNode\r\n while ((c = n.childNodes[i])) {\r\n try { c.remove() } catch (_) { } // due to blur-event-handlers, this can fail\r\n }\r\n}\r\n\r\nlet iswebcomponent = (h: HElement) => h.tag.includes('-')\r\n\r\nlet isproperty = (e: Element, name: string, value: any) =>\r\n name in e ||\r\n value instanceof Object ||\r\n value instanceof Function\r\n\r\nlet setprops = (e: Element & J, old: J | undefined, now: J | undefined) => {\r\n old ??= {}\r\n now ??= {}\r\n for (let p in old)\r\n if (!(p in now))\r\n isproperty(e, p, old[p])\r\n ? e[p] = typeof old[p] === 'boolean' ? false : '' // not sure about this. safest handling of initial values would be to track them. tbd: unit test\r\n : e.removeAttribute(p)\r\n for (let p in now)\r\n isproperty(e, p, now[p])\r\n ? e[p] = now[p]\r\n : e.setAttribute(p, now[p])\r\n}\r\n\r\n/** synchronizes children starting at the i-th element. returns the index of the last child synchronized */\r\nlet syncchildren = (uc: IUpdateContext, p: Element, cn: Children, i: number, ns: string): number => {\r\n cn.flat().forEach(hc => (i = sync(uc, p, i, hc, ns)))\r\n return i\r\n}\r\n\r\nfunction sync(uc: IUpdateContext, parent: Element, i: number, h: H | undefined, ns: string): number {\r\n\r\n // console.log('%csync2', \"background:orange\", parent.tagName, i, h, ns)\r\n\r\n if (h === null || h === undefined) return i // skip. keep 0 and false renderable, per comment below\r\n let c = parent.childNodes[i]\r\n\r\n switch (h.kind) {\r\n case HKind.Element:\r\n\r\n let n: Element\r\n let { tag, cn, p } = h\r\n cn ??= []\r\n\r\n if ((<Element>c)?.tagName?.toLowerCase() != tag.toLowerCase()) {\r\n n = document.createElementNS(ns = p?.xmlns ?? ns, tag) // replace namespace with propertyvalue if set. otherwise pass forward to children\r\n c ? c.replaceWith(n) : parent.appendChild(n) \r\n setprops(n, {}, p)\r\n p?.mounted?.(n)\r\n } else {\r\n n = c as Element\r\n setprops(n, n.h?.p, p) // tbd: this is wrong - try to break this with property updates, just patch sequences - create an own patch test file\r\n if (p?.update?.(c, uc)) return i + 1\r\n }\r\n\r\n n.h = h\r\n\r\n if (!uc.patchElementOnly && !iswebcomponent(h as HElement)) {\r\n // tbd: make \"island\" attribute\r\n const j = syncchildren(uc, n, cn, 0, ns)\r\n removeexcesschildren(n, j)\r\n }\r\n\r\n return i + 1\r\n\r\n case HKind.Fragment:\r\n return syncchildren(uc, parent, h.cn ?? [], i, ns)\r\n\r\n case HKind.FunctionComponent:\r\n {\r\n let hr = h.tag(h.p, h.cn)\r\n let j = sync(uc, parent, i, hr, ns)\r\n let n = parent.childNodes[i]! // now the dom element exists, unless the function returned undefined or null\r\n if (n) n.h = h\r\n return j\r\n }\r\n\r\n case HKind.ClassComponent:\r\n {\r\n let isupdate = (c?.h as any)?.tag == h.tag\r\n\r\n let ci = h.i = isupdate ? h.i! : rebind(new h.tag(h.p))\r\n ci.props = h.p // for the update case we set props\r\n\r\n // if component instance returns truthy for update(), then this update substitutes syncing\r\n if (isupdate && ci.update?.(uc)) return i + 1\r\n\r\n let hr = ci.view()\r\n let j = sync(uc, parent, i, hr, ns)\r\n let n = parent.childNodes[i]!\r\n if (n) n.h = h // tbd: this could disallow component updates ?? i guess it is right\r\n\r\n ci.element = n\r\n if (!isupdate) ci?.mounted?.()\r\n\r\n return j\r\n }\r\n\r\n case undefined:\r\n // textnode\r\n let s = h as string // coerce type as the js runtime does\r\n if (c?.nodeType == NodeType.TextNode) {\r\n if (c.textContent != s) c.textContent = s // firefox updates equal text, loosing existing text selection\r\n } else {\r\n c ? c.replaceWith(s) : parent.append(s)\r\n }\r\n return i + 1\r\n }\r\n}\r\n\r\nexport function patch(e: Node | null, h: H, uc = {} as IUpdateContext) {\r\n if (!e) return\r\n delete uc.patchElementOnly\r\n if (uc.replace) (e as HTMLElement).replaceChildren()\r\n const p = e.parentElement as HTMLElement\r\n const i = [].indexOf.call<any, any, any>(p.childNodes, e)\r\n // always called deferred, because removing elements can trigger events and their handlers (like blur)\r\n sync(uc, p, i, h, p.namespaceURI!) // is this safe? use default html namespace?\r\n}\r\n\r\nexport function updateviewuc(u: IUpdateContext, ...sels: Selectors): void { updateviewinternal(u, ...sels) }\r\nexport function updateview(...sels: Selectors): void { updateviewinternal({}, ...sels) }\r\n\r\nfunction updateviewinternal(uc: IUpdateContext, ...sels: Selector[]): void {\r\n if (!sels.length) sels.push('body')\r\n sels.flatMap(s => (typeof s == 'string' ? [...document.querySelectorAll(s)] : s ? [s] : []))\r\n .forEach(e => { patch(e, e.h!, uc) })\r\n}\r\n"]}
|