@snupo/jmc 1.0.12 → 1.0.21

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/lib.d.ts CHANGED
@@ -4,7 +4,7 @@ export type DeepReadonly<T> = {
4
4
  };
5
5
  export declare const When: ({ cond }: {
6
6
  cond: boolean;
7
- }, cn: Children) => HFragment | undefined;
7
+ }, cn: Children) => HFragment | null;
8
8
  export declare abstract class JMXComp<P extends J = {}> implements IClassComponent {
9
9
  props: P;
10
10
  element: HTMLElement;
@@ -16,4 +16,5 @@ export declare abstract class JMXComp<P extends J = {}> implements IClassCompone
16
16
  get ismounted(): boolean;
17
17
  }
18
18
  export declare function cc(...namesOrObjects: (string | any)[]): string;
19
+ export declare const focuselement: (e: Node) => void;
19
20
  //# sourceMappingURL=lib.d.ts.map
package/dist/lib.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../src/lib.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,cAAc,EAAE,CAAC,EAAE,CAAC,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAItF,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI;IAAE,QAAQ,EAAE,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAG,CAAA;AAE5H,eAAO,MAAM,IAAI,aAAc;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,MAAM,QAAQ,KAAG,SAAS,GAAG,SAA4D,CAAA;AAEzI,8BAAsB,OAAO,CAAC,CAAC,SAAS,CAAC,GAAG,EAAE,CAAE,YAAW,eAAe;IAGnD,KAAK,EAAE,CAAC;IAD3B,OAAO,EAAG,WAAW,CAAA;IACrB,YAAmB,KAAK,EAAE,CAAC,EAAK;IAGhC,OAAO,SAAM;IACb,MAAM,CAAC,EAAE,CAAC,EAAE,cAAc,GAAG,OAAO,GAAG,IAAI,CAAI;IAC/C,QAAQ,CAAC,IAAI,IAAI,CAAC,CAAA;IAGlB,UAAU,SAA+B;IACzC,IAAI,SAAS,IAAI,OAAO,CAA+B;CAC1D;AAED,wBAAgB,EAAE,CAAC,GAAG,cAAc,EAAE,CAAC,MAAM,GAAG,GAAG,CAAC,EAAE,GAAG,MAAM,CAE9D"}
1
+ {"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../src/lib.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,cAAc,EAAE,CAAC,EAAE,CAAC,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAItF,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI;IAAE,QAAQ,EAAE,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAG,CAAA;AAE5H,eAAO,MAAM,IAAI,GAAI,UAAU;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,EAAE,IAAI,QAAQ,KAAG,SAAS,GAAG,IAAkD,CAAA;AAE/H,8BAAsB,OAAO,CAAC,CAAC,SAAS,CAAC,GAAG,EAAE,CAAE,YAAW,eAAe;IAGnD,KAAK,EAAE,CAAC;IAD3B,OAAO,EAAG,WAAW,CAAA;gBACF,KAAK,EAAE,CAAC;IAG3B,OAAO;IACP,MAAM,CAAC,EAAE,CAAC,EAAE,cAAc,GAAG,OAAO,GAAG,IAAI;IAC3C,QAAQ,CAAC,IAAI,IAAI,CAAC;IAGlB,UAAU;IACV,IAAI,SAAS,IAAI,OAAO,CAA+B;CAC1D;AAED,wBAAgB,EAAE,CAAC,GAAG,cAAc,EAAE,CAAC,MAAM,GAAG,GAAG,CAAC,EAAE,GAAG,MAAM,CAE9D;AAED,eAAO,MAAM,YAAY,GAAI,GAAG,IAAI,SAA+B,CAAA"}
package/dist/lib.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { updateview } from './jmc.js';
2
- export const When = ({ cond }, cn) => cond ? { kind: 4 /* HKind.Fragment */, cn } : undefined;
2
+ export const When = ({ cond }, cn) => cond ? { kind: 4 /* HKind.Fragment */, cn } : null;
3
3
  export class JMXComp {
4
4
  props;
5
5
  element; // assigned by jmx framework
@@ -16,4 +16,5 @@ export class JMXComp {
16
16
  export function cc(...namesOrObjects) {
17
17
  return namesOrObjects.flatMap(n => (n.trim ? n : Object.keys(n).filter(k => n[k]))).join(' '); // n.trim distinguishes strings from objects
18
18
  }
19
+ export const focuselement = (e) => e.focus();
19
20
  //# sourceMappingURL=lib.js.map
package/dist/lib.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"lib.js","sourceRoot":"","sources":["../src/lib.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAIrC,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,EAAE,IAAI,EAAqB,EAAE,EAAY,EAAyB,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,wBAAgB,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAA;AAEzI,MAAM,OAAgB,OAAO;IAGN,KAAK;IADxB,OAAO,CAAc,CAAC,4BAA4B;IAClD,YAAmB,KAAQ;qBAAR,KAAK;IAAO,CAAC;IAEhC,YAAY;IACZ,OAAO,KAAK,CAAC;IACb,MAAM,CAAC,EAAmB,IAAoB,CAAC;IAG/C,wCAAwC;IACxC,UAAU,KAAK,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA,CAAC,CAAC;IACzC,IAAI,SAAS,KAAc,OAAO,IAAI,CAAC,OAAc,CAAA,CAAC,CAAC;CAC1D;AAED,MAAM,UAAU,EAAE,CAAC,GAAG,cAAgC;IAClD,OAAO,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA,CAAC,4CAA4C;AAC9I,CAAC","sourcesContent":["import type { Children, IClassComponent, IUpdateContext, H, J, HFragment } from './h';\r\nimport { HKind } from './h.js'\r\nimport { updateview } from './jmc.js'\r\n\r\nexport type DeepReadonly<T> = { readonly [K in keyof T]: T[K] extends Record<string, unknown> ? DeepReadonly<T[K]> : T[K]; }\r\n\r\nexport const When = ({ cond }: { cond: boolean }, cn: Children): HFragment | undefined => cond ? { kind: HKind.Fragment, cn } : undefined\r\n\r\nexport abstract class JMXComp<P extends J = {}> implements IClassComponent {\r\n\r\n element!: HTMLElement // assigned by jmx framework\r\n constructor(public props: P) { }\r\n\r\n // overrides\r\n mounted() { }\r\n update(uc?: IUpdateContext): boolean | void { }\r\n abstract view(): H\r\n\r\n // utility: updates the component's view\r\n updateview() { updateview(this.element) }\r\n get ismounted(): boolean { return this.element as any }\r\n}\r\n\r\nexport function cc(...namesOrObjects: (string | any)[]): string {\r\n return namesOrObjects.flatMap(n => (n.trim ? n : Object.keys(n).filter(k => n[k]))).join(' ') // n.trim distinguishes strings from objects\r\n}"]}
1
+ {"version":3,"file":"lib.js","sourceRoot":"","sources":["../src/lib.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAIrC,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,EAAE,IAAI,EAAqB,EAAE,EAAY,EAAoB,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,wBAAgB,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAA;AAE/H,MAAM,OAAgB,OAAO;IAGN;IADnB,OAAO,CAAc,CAAC,4BAA4B;IAClD,YAAmB,KAAQ;QAAR,UAAK,GAAL,KAAK,CAAG;IAAI,CAAC;IAEhC,YAAY;IACZ,OAAO,KAAK,CAAC;IACb,MAAM,CAAC,EAAmB,IAAoB,CAAC;IAG/C,wCAAwC;IACxC,UAAU,KAAK,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA,CAAC,CAAC;IACzC,IAAI,SAAS,KAAc,OAAO,IAAI,CAAC,OAAc,CAAA,CAAC,CAAC;CAC1D;AAED,MAAM,UAAU,EAAE,CAAC,GAAG,cAAgC;IAClD,OAAO,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA,CAAC,4CAA4C;AAC9I,CAAC;AAED,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAO,EAAE,EAAE,CAAE,CAAiB,CAAC,KAAK,EAAE,CAAA","sourcesContent":["import type { Children, IClassComponent, IUpdateContext, H, J, HFragment } from './h';\r\nimport { HKind } from './h.js'\r\nimport { updateview } from './jmc.js'\r\n\r\nexport type DeepReadonly<T> = { readonly [K in keyof T]: T[K] extends Record<string, unknown> ? DeepReadonly<T[K]> : T[K]; }\r\n\r\nexport const When = ({ cond }: { cond: boolean }, cn: Children): HFragment | null => cond ? { kind: HKind.Fragment, cn } : null\r\n\r\nexport abstract class JMXComp<P extends J = {}> implements IClassComponent {\r\n\r\n element!: HTMLElement // assigned by jmx framework\r\n constructor(public props: P) { }\r\n\r\n // overrides\r\n mounted() { }\r\n update(uc?: IUpdateContext): boolean | void { }\r\n abstract view(): H\r\n\r\n // utility: updates the component's view\r\n updateview() { updateview(this.element) }\r\n get ismounted(): boolean { return this.element as any }\r\n}\r\n\r\nexport function cc(...namesOrObjects: (string | any)[]): string {\r\n return namesOrObjects.flatMap(n => (n.trim ? n : Object.keys(n).filter(k => n[k]))).join(' ') // n.trim distinguishes strings from objects\r\n}\r\n\r\nexport const focuselement = (e: Node) => (e as HTMLElement).focus()"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@snupo/jmc",
3
3
  "author": "snupo",
4
- "version": "1.0.12",
4
+ "version": "1.0.21",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -15,20 +15,22 @@
15
15
  }
16
16
  },
17
17
  "files": [
18
- "dist"
18
+ "dist",
19
+ "src"
19
20
  ],
20
21
  "devDependencies": {
21
- "@vitest/coverage-v8": "^4.1.10",
22
+ "typescript": "^6.0.3",
23
+ "vite": "^8.1.5",
24
+ "vitest": "4.1.10",
22
25
  "happy-dom": "^16.8.1",
23
- "rimraf": "^6.1.3",
24
- "tsdown": "^0.22.14",
25
- "vitest": "4.1.10"
26
+ "@vitest/coverage-v8": "^4.1.10",
27
+ "rimraf": "^6.1.3"
26
28
  },
27
29
  "dependencies": {
28
30
  "@types/react": "^19.2.17"
29
31
  },
30
32
  "scripts": {
31
33
  "prebuild": "rimraf dist",
32
- "build": "tsc -p tsconfig.build.json"
34
+ "build": "tsc -p tsconfig.json"
33
35
  }
34
36
  }
package/src/base.ts ADDED
@@ -0,0 +1,27 @@
1
+ export function rebind<T extends object>(o: T, proto = Object.getPrototypeOf(o)): T {
2
+ Object.entries(Object.getOwnPropertyDescriptors(proto))
3
+ .filter(([name, p]) => name != 'constructor' && p.value instanceof Function)
4
+ .forEach(([name]) => (o as any)[name] = (o as any)[name].bind(o))
5
+ return o
6
+ }
7
+
8
+ export function mount(o: Record<string, any>) { Object.assign(globalThis, o) }
9
+
10
+ export const loggedmethodsex = <T extends Record<string, any>>(o: T, logger: (name: string, args: any[], result: any) => void) => new Proxy(o, {
11
+ get(target, name: string, receiver) {
12
+ if (typeof target[name] === "function") {
13
+ return function (this: T, ...args: any[]) {
14
+
15
+ logger(name, args, undefined)
16
+ let r = target[name].apply(this, args)
17
+ return r
18
+ }
19
+ }
20
+ return Reflect.get(target, name, receiver)
21
+ },
22
+ })
23
+
24
+ export 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))
25
+ export 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))
26
+
27
+ export function closestby(e: Node | null, pred: (e: Node) => boolean): Node | null { return (e == null || pred(e)) ? e : closestby(e.parentNode, pred) }
package/src/h.ts ADDED
@@ -0,0 +1,99 @@
1
+ export type J = Record<string, any> // a json record
2
+
3
+ // Overload signatures
4
+ export type Selector = string | Node | undefined | null
5
+
6
+ export type FComponent = (props: J | undefined, children?: Children) => HElement // show an example for usage of children
7
+ export type FComponentT<P> = (pcn: P, cn?: Children) => H | void
8
+
9
+ export interface IClassComponent {
10
+ element: Node
11
+ props?: Record<string, any>
12
+ view(): H
13
+ update(uc: IUpdateContext): boolean | void
14
+ mounted?(): void
15
+ }
16
+
17
+ export interface CComponent {
18
+ new(props: any): IClassComponent
19
+ }
20
+
21
+ export type Children = (H | undefined)[]
22
+
23
+ export type HText =
24
+ | string // text node
25
+ | number // text node
26
+ | boolean // do not allow boolean, that
27
+
28
+ export type HFragment = {
29
+ kind: HKind.Fragment
30
+ cn?: Children
31
+ }
32
+
33
+ export type HElement = {
34
+ kind: HKind.Element
35
+ tag: string
36
+ p?: J
37
+ cn?: Children
38
+ }
39
+
40
+ export type HFunctionComponent = {
41
+ kind: HKind.FunctionComponent
42
+ tag: FComponent
43
+ p?: J
44
+ cn?: Children
45
+ }
46
+
47
+ export type HClassComponent = {
48
+ kind: HKind.ClassComponent
49
+ tag: CComponent
50
+ p?: J
51
+ cn?: Children
52
+ i?: IClassComponent
53
+ }
54
+
55
+ export const enum HKind {
56
+ Element = 1,
57
+ FunctionComponent = 2,
58
+ ClassComponent = 3,
59
+ Fragment = 4
60
+ }
61
+
62
+ export type HComp = HFunctionComponent | HClassComponent
63
+
64
+ export type H =
65
+ | HText & { kind?: undefined } // text nodes never have a kind. but this type addition makes H a full DU
66
+ | HElement
67
+ | HFunctionComponent
68
+ | HClassComponent
69
+ | HFragment
70
+
71
+ export interface IUpdateContext {
72
+ patchElementOnly?: boolean
73
+ replace?: boolean
74
+ }
75
+
76
+ declare global {
77
+ interface Node {
78
+ h?: H & { p?: J }
79
+ }
80
+ }
81
+
82
+ let isclass = (f: Function) => /^class\s|^class\{/.test(f.toString())
83
+
84
+ export function jsx(tag: any, p: any, ...cn: any[]): HElement | HFunctionComponent | HClassComponent | HFragment {
85
+ if (tag?.kind) return tag // already an H node, flatten tree
86
+
87
+ let kind = tag == jsxf ? HKind.Fragment
88
+ : tag instanceof Function ? (isclass(tag) ? HKind.ClassComponent : HKind.FunctionComponent)
89
+ : HKind.Element
90
+
91
+ let h: any = { kind }
92
+ if (kind != HKind.Fragment) h.tag = tag
93
+ if (p) h.p = p
94
+ if (cn?.length) h.cn = cn
95
+ return h
96
+ }
97
+
98
+ // fragment is only used above as a sentinel
99
+ export let jsxf = Symbol()
package/src/index.ts ADDED
@@ -0,0 +1,5 @@
1
+ export * from './jmc.js'
2
+ export * from './lib.js'
3
+ export * from './base.js'
4
+ export * from './jsx.js'
5
+ export * from './h.js'
package/src/jmc.ts ADDED
@@ -0,0 +1,163 @@
1
+ import { rebind } from './base.js'
2
+ import type { H, HElement, IUpdateContext, J, Selector, Children, HClassComponent } from './h'
3
+ import { HKind } from './h'
4
+
5
+ const enum NodeType { // vaporizes (but for that must be in this file, otherwise not)
6
+ TextNode = 3
7
+ }
8
+
9
+ let removeexcesschildren = (n: Element, i: number) => {
10
+ let c: ChildNode
11
+ while ((c = n.childNodes[i])) {
12
+ try { c.remove() } catch (_) { } // due to blur-event-handlers, this can fail
13
+ }
14
+ }
15
+
16
+ let iswebcomponent = (h: HElement) => h.tag.includes('-')
17
+
18
+ const isproperty = (e: Element, name: string, value: any) =>
19
+ name !== "viewBox" &&
20
+ (value instanceof Object ||
21
+ value instanceof Function ||
22
+ (e.namespaceURI !== "http://www.w3.org/2000/svg" && name in e && name != 'style'))
23
+
24
+ let setprops = (e: Element & J, old: J | undefined, now: J | undefined) => {
25
+
26
+ old ??= {}
27
+ now ??= {}
28
+
29
+ // removals
30
+ for (let p in old)
31
+ if (!(p in now))
32
+ isproperty(e, p, old[p])
33
+ ? e[p] = typeof old[p] === 'boolean' ? false : ''
34
+ : e.removeAttribute(p)
35
+ // updates
36
+ for (let p in now) {
37
+ let v = now[p]
38
+ if (v != old[p]) {
39
+ isproperty(e, p, v)
40
+ ? e[p] = v
41
+ : e.setAttribute(p, v)
42
+ }
43
+ }
44
+ }
45
+
46
+ /** synchronizes children starting at the i-th element. returns the index of the last child synchronized */
47
+ let syncchildren = (uc: IUpdateContext, p: Element, cn: Children, i: number, ns: string): number => {
48
+ cn.flat().forEach(hc => (i = sync(uc, p, i, hc, ns)))
49
+ return i
50
+ }
51
+
52
+ function sync(uc: IUpdateContext, parent: Element, i: number, h: H | undefined, ns: string): number {
53
+
54
+ // console.log('%csync2', "background:orange", parent.tagName, i, h)
55
+
56
+ if (h === null || h === undefined) return i // skip. keep 0 and false renderable, per comment below
57
+ let c = parent.childNodes[i]
58
+
59
+ switch (h.kind) {
60
+ case HKind.Element:
61
+ {
62
+ let n: Element
63
+ let { tag, cn, p } = h
64
+ cn ??= []
65
+
66
+ if ((<Element>c)?.tagName?.toLowerCase() != tag.toLowerCase()) {
67
+ n = document.createElementNS(ns = p?.xmlns ?? ns, tag) // replace namespace with propertyvalue if set. otherwise pass forward to children
68
+ c ? c.replaceWith(n) : parent.appendChild(n)
69
+ setprops(n, {}, p)
70
+ p?.mounted?.(n)
71
+ } else {
72
+ n = c as Element
73
+ 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
74
+ if (p?.update?.(c, uc)) return i + 1
75
+ }
76
+
77
+ n.h = h // sets the new property values
78
+
79
+ if (!uc.patchElementOnly && !iswebcomponent(h as HElement)) {
80
+
81
+ // island attribute
82
+ if (n.h?.p?.const) return i + 1
83
+
84
+ const j = syncchildren(uc, n, cn, 0, ns)
85
+ removeexcesschildren(n, j)
86
+ }
87
+
88
+ return i + 1
89
+ }
90
+
91
+ case HKind.Fragment:
92
+ {
93
+ return syncchildren(uc, parent, h.cn ?? [], i, ns)
94
+ }
95
+
96
+ case HKind.FunctionComponent:
97
+ {
98
+ let hr = h.tag(h.p, h.cn)
99
+ let j = sync(uc, parent, i, hr, ns)
100
+ let n = parent.childNodes[i]! // now the dom element exists, unless the function returned undefined or null
101
+ if (n) n.h = h
102
+ return j
103
+ }
104
+
105
+ case HKind.ClassComponent: {
106
+ let isupdate = (c?.h as any)?.tag == h.tag
107
+
108
+ if (isupdate) {
109
+ let ci = (c!.h as HClassComponent).i!
110
+ ci.props = h.p
111
+
112
+ // update() substitutes view/sync when returning truthy
113
+ return (ci.update?.(uc)) ? i + 1 : sync(uc, parent, i, ci.view(), ns)
114
+ }
115
+
116
+ let ci = h.i = rebind(new h.tag(h.p))
117
+ let j = sync(uc, parent, i, ci.view(), ns)
118
+ let n = parent.childNodes[i]!
119
+ ci.element = n
120
+ n.h = h
121
+ ci.mounted?.()
122
+ return j
123
+ }
124
+
125
+ case undefined:
126
+ // textnode
127
+ let s = h as string // coerce type as the js runtime does
128
+ if (c?.nodeType == NodeType.TextNode) {
129
+ if (c.textContent != s) c.textContent = s // firefox updates equal text, loosing existing text selection
130
+ } else {
131
+ c ? c.replaceWith(s) : parent.append(s)
132
+ }
133
+ return i + 1
134
+ }
135
+ }
136
+
137
+ export function patch(e: Node | null, h?: H, uc = {} as IUpdateContext) {
138
+ if (!e) return
139
+ if (uc.replace) (e as HTMLElement).replaceChildren()
140
+
141
+ // walk up
142
+ while (!h && e) h = (e = e.parentNode)?.h
143
+ if (!h || !e) {
144
+ console.warn("patch not possible, h is undefined in whole parent chain", e, h)
145
+ return
146
+ }
147
+
148
+ let p = e.parentElement as HTMLElement
149
+ let i = [].indexOf.call<any, any, any>(p.childNodes, e)
150
+ // always called deferred, because removing elements can trigger events and their handlers (like blur)
151
+ sync(uc, p, i, h, p.namespaceURI!) // is this safe? use default html namespace?
152
+ }
153
+
154
+ export function updateviewuc(u: IUpdateContext, ...sels: Selector[]): void { updateviewinternal(u, ...sels) }
155
+ export function updateview(...sels: Selector[]): void { updateviewinternal({}, ...sels) }
156
+
157
+ function updateviewinternal(uc: IUpdateContext, ...sels: Selector[]): void {
158
+ if (!sels.length) sels.push('body')
159
+ sels.flatMap(s => (typeof s == 'string' ? [...document.querySelectorAll(s)] : s ? [s] : []))
160
+ .forEach(e => { patch(e, e.h, uc) })
161
+ }
162
+
163
+ // console.log("jmc version 1.0.16");