@snupo/jmc 1.0.61 → 1.1.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/LICENSE +21 -0
- package/dist/base.d.ts +3 -2
- package/dist/base.d.ts.map +1 -1
- package/dist/base.js +11 -13
- package/dist/base.js.map +1 -1
- package/dist/events.d.ts +9 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +17 -0
- package/dist/events.js.map +1 -0
- package/dist/h.d.ts +14 -7
- package/dist/h.d.ts.map +1 -1
- package/dist/h.js +7 -4
- package/dist/h.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/jmc.d.ts +1 -9
- package/dist/jmc.d.ts.map +1 -1
- package/dist/jmc.js +80 -107
- package/dist/jmc.js.map +1 -1
- package/dist/jsx-dev-runtime.d.ts +5 -0
- package/dist/jsx-dev-runtime.d.ts.map +1 -0
- package/dist/jsx-dev-runtime.js +6 -0
- package/dist/jsx-dev-runtime.js.map +1 -0
- package/dist/jsx-runtime.d.ts +14 -0
- package/dist/jsx-runtime.d.ts.map +1 -0
- package/dist/jsx-runtime.js +10 -0
- package/dist/jsx-runtime.js.map +1 -0
- package/dist/jsx.d.ts +39 -46
- package/dist/jsx.d.ts.map +1 -1
- package/dist/jsx.js.map +1 -1
- package/dist/lib.d.ts +5 -3
- package/dist/lib.d.ts.map +1 -1
- package/dist/lib.js +4 -5
- package/dist/lib.js.map +1 -1
- package/dist/props.d.ts +11 -0
- package/dist/props.d.ts.map +1 -0
- package/dist/props.js +43 -0
- package/dist/props.js.map +1 -0
- package/dist/update.d.ts +10 -0
- package/dist/update.d.ts.map +1 -0
- package/dist/update.js +48 -0
- package/dist/update.js.map +1 -0
- package/package.json +29 -3
- package/readme.md +303 -34
- package/src/base.ts +11 -15
- package/src/events.ts +25 -0
- package/src/h.ts +29 -18
- package/src/index.ts +2 -1
- package/src/jmc.ts +90 -129
- package/src/jsx-dev-runtime.ts +8 -0
- package/src/jsx-runtime.ts +17 -0
- package/src/jsx.ts +18 -30
- package/src/lib.ts +10 -8
- package/src/props.ts +43 -0
- package/src/update.ts +54 -0
- package/dist/updateview.d.ts +0 -17
- package/dist/updateview.d.ts.map +0 -1
- package/dist/updateview.js +0 -43
- package/dist/updateview.js.map +0 -1
- package/src/updateview.ts +0 -48
package/src/update.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { updateview } from './jmc.js'
|
|
2
|
+
import type { Command, J, Selector } from './h.js'
|
|
3
|
+
|
|
4
|
+
// one queued update: a target with the depth and update context of the call that queued it
|
|
5
|
+
type Pending = [target: Selector, depth: number, uc: J | undefined]
|
|
6
|
+
|
|
7
|
+
let pendings: Pending[] = []
|
|
8
|
+
let isScheduled = false
|
|
9
|
+
|
|
10
|
+
/** resolves a call's commands into pendings, so depth and uc stay with their own call */
|
|
11
|
+
let enqueue = (cmds: Command[]) => {
|
|
12
|
+
if (!cmds.some(c => typeof c == 'string' || c instanceof Node)) cmds = [...cmds, 'body'] // like updateview()
|
|
13
|
+
let depth = 999
|
|
14
|
+
let uc: J | undefined
|
|
15
|
+
for (const c of cmds)
|
|
16
|
+
if (typeof c == 'number') depth = c
|
|
17
|
+
else if (typeof c == 'string' || c instanceof Node) pendings.push([c, depth, uc])
|
|
18
|
+
else uc = c
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** synchronously runs all queued updates. selectors are resolved now, and each node is updated once per depth and uc */
|
|
22
|
+
export const flush = (): void => {
|
|
23
|
+
isScheduled = false
|
|
24
|
+
const ps = pendings
|
|
25
|
+
pendings = []
|
|
26
|
+
const done: Pending[] = []
|
|
27
|
+
for (const [target, depth, uc] of ps)
|
|
28
|
+
for (const n of typeof target == 'string' ? document.querySelectorAll(target) : [target])
|
|
29
|
+
if (!done.some(([t, d, u]) => t == n && d == depth && u == uc)) {
|
|
30
|
+
done.push([n, depth, uc])
|
|
31
|
+
updateview(depth, uc ?? {}, n)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** queues the update and schedules a flush, so that all calls before it collapse into one batch */
|
|
36
|
+
let batch = (schedule: (f: () => void) => void) => (...cmds: Command[]): void => {
|
|
37
|
+
enqueue(cmds)
|
|
38
|
+
if (!isScheduled) {
|
|
39
|
+
isScheduled = true
|
|
40
|
+
schedule(flush)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** batches updates until the next microtask */
|
|
45
|
+
export const updateviewmicro = batch(f => queueMicrotask(f))
|
|
46
|
+
|
|
47
|
+
/** batches updates until the next animation frame */
|
|
48
|
+
export const updateviewaf = batch(f => requestAnimationFrame(f)) // looked up on call, so importing works without a DOM
|
|
49
|
+
|
|
50
|
+
/** updates immediately, together with all queued updates */
|
|
51
|
+
export const updateviewsync = (...cmds: Command[]): void => {
|
|
52
|
+
enqueue(cmds)
|
|
53
|
+
flush()
|
|
54
|
+
}
|
package/dist/updateview.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Command } from "./jmc";
|
|
2
|
-
/**
|
|
3
|
-
* Synchronously processes all pending commands queued in pendingCommands.
|
|
4
|
-
*/
|
|
5
|
-
export declare const flush: () => void;
|
|
6
|
-
/**
|
|
7
|
-
* Asynchronously batches view updates.
|
|
8
|
-
* Multiple synchronous calls collapse into a single execution during the microtask queue tick.
|
|
9
|
-
*/
|
|
10
|
-
export declare const updateviewmicro: (...args: Command[]) => void;
|
|
11
|
-
export declare const updateviewaf: (...args: Command[]) => void;
|
|
12
|
-
/**
|
|
13
|
-
* Synchronously updates the view immediately.
|
|
14
|
-
* Pushes new commands onto the queue and flushes all pending commands in a single batch.
|
|
15
|
-
*/
|
|
16
|
-
export declare const updateviewsync: (...args: Command[]) => void;
|
|
17
|
-
//# sourceMappingURL=updateview.d.ts.map
|
package/dist/updateview.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"updateview.d.ts","sourceRoot":"","sources":["../src/updateview.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAc,MAAM,OAAO,CAAA;AAK3C;;GAEG;AACH,eAAO,MAAM,KAAK,QAAO,IAUxB,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,eAAe,GAAI,GAAG,MAAM,OAAO,EAAE,KAAG,IAMpD,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,GAAG,MAAM,OAAO,EAAE,KAAG,IAMjD,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,cAAc,GAAI,GAAG,MAAM,OAAO,EAAE,KAAG,IAGnD,CAAA"}
|
package/dist/updateview.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { updateview } from "./jmc";
|
|
2
|
-
let pendings = [];
|
|
3
|
-
let isScheduled = false;
|
|
4
|
-
/**
|
|
5
|
-
* Synchronously processes all pending commands queued in pendingCommands.
|
|
6
|
-
*/
|
|
7
|
-
export const flush = () => {
|
|
8
|
-
if (pendings.length === 0)
|
|
9
|
-
return;
|
|
10
|
-
// Clear scheduling state and extract queued commands
|
|
11
|
-
isScheduled = false;
|
|
12
|
-
const cmds = [...new Set(pendings)]; // this is guaranteed stable, keeping order
|
|
13
|
-
pendings = [];
|
|
14
|
-
// Execute the single, unified update
|
|
15
|
-
updateview(...cmds);
|
|
16
|
-
};
|
|
17
|
-
/**
|
|
18
|
-
* Asynchronously batches view updates.
|
|
19
|
-
* Multiple synchronous calls collapse into a single execution during the microtask queue tick.
|
|
20
|
-
*/
|
|
21
|
-
export const updateviewmicro = (...args) => {
|
|
22
|
-
pendings.push(...args);
|
|
23
|
-
if (!isScheduled) {
|
|
24
|
-
isScheduled = true;
|
|
25
|
-
queueMicrotask(flush);
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
export const updateviewaf = (...args) => {
|
|
29
|
-
pendings.push(...args);
|
|
30
|
-
if (!isScheduled) {
|
|
31
|
-
isScheduled = true;
|
|
32
|
-
requestAnimationFrame(flush);
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
/**
|
|
36
|
-
* Synchronously updates the view immediately.
|
|
37
|
-
* Pushes new commands onto the queue and flushes all pending commands in a single batch.
|
|
38
|
-
*/
|
|
39
|
-
export const updateviewsync = (...args) => {
|
|
40
|
-
pendings.push(...args);
|
|
41
|
-
flush();
|
|
42
|
-
};
|
|
43
|
-
//# sourceMappingURL=updateview.js.map
|
package/dist/updateview.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"updateview.js","sourceRoot":"","sources":["../src/updateview.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,UAAU,EAAE,MAAM,OAAO,CAAA;AAE3C,IAAI,QAAQ,GAAc,EAAE,CAAA;AAC5B,IAAI,WAAW,GAAG,KAAK,CAAA;AAEvB;;GAEG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,GAAS,EAAE;IAC5B,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAM;IAEjC,qDAAqD;IACrD,WAAW,GAAG,KAAK,CAAA;IACnB,MAAM,IAAI,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAA,CAAC,2CAA2C;IAC/E,QAAQ,GAAG,EAAE,CAAA;IAEb,qCAAqC;IACrC,UAAU,CAAC,GAAG,IAAI,CAAC,CAAA;AACvB,CAAC,CAAA;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,GAAG,IAAe,EAAQ,EAAE;IACxD,QAAQ,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAA;IACtB,IAAI,CAAC,WAAW,EAAE,CAAC;QACf,WAAW,GAAG,IAAI,CAAA;QAClB,cAAc,CAAC,KAAK,CAAC,CAAA;IACzB,CAAC;AACL,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,GAAG,IAAe,EAAQ,EAAE;IACrD,QAAQ,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAA;IACtB,IAAI,CAAC,WAAW,EAAE,CAAC;QACf,WAAW,GAAG,IAAI,CAAA;QAClB,qBAAqB,CAAC,KAAK,CAAC,CAAA;IAChC,CAAC;AACL,CAAC,CAAA;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,GAAG,IAAe,EAAQ,EAAE;IACvD,QAAQ,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAA;IACtB,KAAK,EAAE,CAAA;AACX,CAAC,CAAA","sourcesContent":["import { Command, updateview } from \"./jmc\"\r\n\r\nlet pendings: Command[] = []\r\nlet isScheduled = false\r\n\r\n/**\r\n * Synchronously processes all pending commands queued in pendingCommands.\r\n */\r\nexport const flush = (): void => {\r\n if (pendings.length === 0) return\r\n\r\n // Clear scheduling state and extract queued commands\r\n isScheduled = false\r\n const cmds = [...new Set(pendings)] // this is guaranteed stable, keeping order\r\n pendings = []\r\n\r\n // Execute the single, unified update\r\n updateview(...cmds)\r\n}\r\n\r\n/**\r\n * Asynchronously batches view updates.\r\n * Multiple synchronous calls collapse into a single execution during the microtask queue tick.\r\n */\r\nexport const updateviewmicro = (...args: Command[]): void => {\r\n pendings.push(...args)\r\n if (!isScheduled) {\r\n isScheduled = true\r\n queueMicrotask(flush)\r\n }\r\n}\r\n\r\nexport const updateviewaf = (...args: Command[]): void => {\r\n pendings.push(...args)\r\n if (!isScheduled) {\r\n isScheduled = true\r\n requestAnimationFrame(flush)\r\n }\r\n}\r\n\r\n/**\r\n * Synchronously updates the view immediately.\r\n * Pushes new commands onto the queue and flushes all pending commands in a single batch.\r\n */\r\nexport const updateviewsync = (...args: Command[]): void => {\r\n pendings.push(...args)\r\n flush()\r\n}\r\n"]}
|
package/src/updateview.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { Command, updateview } from "./jmc"
|
|
2
|
-
|
|
3
|
-
let pendings: Command[] = []
|
|
4
|
-
let isScheduled = false
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Synchronously processes all pending commands queued in pendingCommands.
|
|
8
|
-
*/
|
|
9
|
-
export const flush = (): void => {
|
|
10
|
-
if (pendings.length === 0) return
|
|
11
|
-
|
|
12
|
-
// Clear scheduling state and extract queued commands
|
|
13
|
-
isScheduled = false
|
|
14
|
-
const cmds = [...new Set(pendings)] // this is guaranteed stable, keeping order
|
|
15
|
-
pendings = []
|
|
16
|
-
|
|
17
|
-
// Execute the single, unified update
|
|
18
|
-
updateview(...cmds)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Asynchronously batches view updates.
|
|
23
|
-
* Multiple synchronous calls collapse into a single execution during the microtask queue tick.
|
|
24
|
-
*/
|
|
25
|
-
export const updateviewmicro = (...args: Command[]): void => {
|
|
26
|
-
pendings.push(...args)
|
|
27
|
-
if (!isScheduled) {
|
|
28
|
-
isScheduled = true
|
|
29
|
-
queueMicrotask(flush)
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export const updateviewaf = (...args: Command[]): void => {
|
|
34
|
-
pendings.push(...args)
|
|
35
|
-
if (!isScheduled) {
|
|
36
|
-
isScheduled = true
|
|
37
|
-
requestAnimationFrame(flush)
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Synchronously updates the view immediately.
|
|
43
|
-
* Pushes new commands onto the queue and flushes all pending commands in a single batch.
|
|
44
|
-
*/
|
|
45
|
-
export const updateviewsync = (...args: Command[]): void => {
|
|
46
|
-
pendings.push(...args)
|
|
47
|
-
flush()
|
|
48
|
-
}
|