j20 0.0.25 → 0.0.27
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/index.d.ts +314 -258
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +84 -51
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -315,12 +315,11 @@ function batch(fn) {
|
|
|
315
315
|
}
|
|
316
316
|
}
|
|
317
317
|
|
|
318
|
-
const
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
const
|
|
322
|
-
|
|
323
|
-
};
|
|
318
|
+
const exist = (val) => val !== undefined;
|
|
319
|
+
const isEvent = (eventName) => eventName.startsWith("on");
|
|
320
|
+
const isNativeEvent = (eventName) => eventName.startsWith("onNative");
|
|
321
|
+
const getNativeEventName = (eventName) => eventName.slice(8).toLowerCase();
|
|
322
|
+
const getEventName = (eventName) => eventName.slice(2).toLowerCase();
|
|
324
323
|
const getChildren = (propChildren) => {
|
|
325
324
|
const arr = [];
|
|
326
325
|
for (let i = 0; i < propChildren.length; i++) {
|
|
@@ -363,7 +362,12 @@ const styleObjectToString = (style) => {
|
|
|
363
362
|
return styleString.trim();
|
|
364
363
|
};
|
|
365
364
|
const update = (node, key, oldValue, newValue) => {
|
|
366
|
-
if (
|
|
365
|
+
if (isNativeEvent(key)) {
|
|
366
|
+
node.removeEventListener(getNativeEventName(key), oldValue.handleEvent);
|
|
367
|
+
const { handleEvent, ...restValues } = newValue;
|
|
368
|
+
node.addEventListener(getNativeEventName(key), handleEvent, restValues);
|
|
369
|
+
}
|
|
370
|
+
else if (isEvent(key)) {
|
|
367
371
|
node.removeEventListener(getEventName(key), oldValue);
|
|
368
372
|
node.addEventListener(getEventName(key), newValue);
|
|
369
373
|
}
|
|
@@ -382,7 +386,10 @@ const update = (node, key, oldValue, newValue) => {
|
|
|
382
386
|
}
|
|
383
387
|
};
|
|
384
388
|
const unset = (node, key, oldValue) => {
|
|
385
|
-
if (
|
|
389
|
+
if (isNativeEvent(key)) {
|
|
390
|
+
node.removeEventListener(getNativeEventName(key), oldValue.handleEvent);
|
|
391
|
+
}
|
|
392
|
+
else if (isEvent(key)) {
|
|
386
393
|
node.removeEventListener(getEventName(key), oldValue);
|
|
387
394
|
}
|
|
388
395
|
else if (key === "ref") {
|
|
@@ -393,7 +400,11 @@ const unset = (node, key, oldValue) => {
|
|
|
393
400
|
}
|
|
394
401
|
};
|
|
395
402
|
const add = (node, key, newValue) => {
|
|
396
|
-
if (
|
|
403
|
+
if (isNativeEvent(key)) {
|
|
404
|
+
const { handleEvent, ...restValues } = newValue;
|
|
405
|
+
node.addEventListener(getNativeEventName(key), handleEvent, restValues);
|
|
406
|
+
}
|
|
407
|
+
else if (isEvent(key)) {
|
|
397
408
|
node.addEventListener(getEventName(key), newValue);
|
|
398
409
|
}
|
|
399
410
|
else if (key === "ref") {
|
|
@@ -422,17 +433,22 @@ const nodeAttributesEffect = (node, propsFn) => {
|
|
|
422
433
|
let oldProps = {};
|
|
423
434
|
effect(() => {
|
|
424
435
|
const newProps = { ...propsFn() };
|
|
425
|
-
const
|
|
426
|
-
|
|
427
|
-
|
|
436
|
+
const allKeys = new Set([
|
|
437
|
+
...Object.keys(newProps),
|
|
438
|
+
...Object.keys(oldProps),
|
|
439
|
+
]);
|
|
428
440
|
for (const key of allKeys) {
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
441
|
+
const oldValue = oldProps[key];
|
|
442
|
+
const newValue = newProps[key];
|
|
443
|
+
exist(oldValue)
|
|
444
|
+
? exist(newValue)
|
|
445
|
+
? Object.is(oldValue, newValue)
|
|
432
446
|
? null
|
|
433
|
-
: update(node, key,
|
|
434
|
-
: unset(node, key,
|
|
435
|
-
:
|
|
447
|
+
: update(node, key, oldValue, newValue)
|
|
448
|
+
: unset(node, key, oldValue)
|
|
449
|
+
: exist(newValue)
|
|
450
|
+
? add(node, key, newValue)
|
|
451
|
+
: null;
|
|
436
452
|
}
|
|
437
453
|
oldProps = newProps;
|
|
438
454
|
});
|
|
@@ -880,51 +896,68 @@ const onMount = (callback) => {
|
|
|
880
896
|
|
|
881
897
|
const onDestroy = (callback) => effect(() => callback);
|
|
882
898
|
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
let
|
|
899
|
+
function replaceTopLevelSelectors(css, id) {
|
|
900
|
+
let depth = 0;
|
|
901
|
+
let result = "";
|
|
902
|
+
let lastSlice = 0;
|
|
903
|
+
for (let i = 0; i < css.length; i++) {
|
|
904
|
+
if (css[i] === "{") {
|
|
905
|
+
if (depth === 0) {
|
|
906
|
+
result +=
|
|
907
|
+
css
|
|
908
|
+
.slice(lastSlice, i)
|
|
909
|
+
.replace(/\.(\w[\w-]*)/g, (_, name) => `.${name}_${id}`) + "{";
|
|
910
|
+
lastSlice = i + 1;
|
|
911
|
+
}
|
|
912
|
+
depth++;
|
|
913
|
+
}
|
|
914
|
+
else if (css[i] === "}") {
|
|
915
|
+
depth--;
|
|
916
|
+
if (depth === 0) {
|
|
917
|
+
result += css.slice(lastSlice, i + 1);
|
|
918
|
+
lastSlice = i + 1;
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
result += css.slice(lastSlice);
|
|
923
|
+
return result;
|
|
924
|
+
}
|
|
925
|
+
const createCssModule = (css) => {
|
|
926
|
+
let hash = undefined;
|
|
927
|
+
let replacedCss = undefined;
|
|
886
928
|
return () => {
|
|
887
|
-
if (!
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
});
|
|
893
|
-
styleSheet(replacedCss, id);
|
|
929
|
+
if (!hash)
|
|
930
|
+
hash = cssHash(css);
|
|
931
|
+
if (!replacedCss)
|
|
932
|
+
replacedCss = replaceTopLevelSelectors(css, hash);
|
|
933
|
+
styleSheet(replacedCss, hash);
|
|
894
934
|
return new Proxy({}, {
|
|
895
935
|
get: (_, prop) => {
|
|
896
|
-
return `${prop}_${
|
|
936
|
+
return `${prop}_${hash}`;
|
|
897
937
|
},
|
|
898
938
|
});
|
|
899
939
|
};
|
|
900
940
|
};
|
|
901
941
|
const addReference = (host, id, css) => {
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
const newState = {
|
|
909
|
-
id,
|
|
910
|
-
refCount: 1,
|
|
911
|
-
styleSheet: createStyleSheet(css),
|
|
912
|
-
};
|
|
913
|
-
refWeakMap.set(host, [...states, newState]);
|
|
914
|
-
addStyleSheet(host, newState.styleSheet);
|
|
942
|
+
const currentSheet = host[id];
|
|
943
|
+
if (!currentSheet) {
|
|
944
|
+
const sheet = createStyleSheet(css);
|
|
945
|
+
sheet.refCount = 1;
|
|
946
|
+
host[id] = sheet;
|
|
947
|
+
addStyleSheet(host, sheet);
|
|
915
948
|
}
|
|
916
949
|
else {
|
|
917
|
-
|
|
950
|
+
currentSheet.refCount++;
|
|
918
951
|
}
|
|
919
952
|
};
|
|
920
953
|
const removeReference = (host, id) => {
|
|
921
|
-
const
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
954
|
+
const currentSheet = host[id];
|
|
955
|
+
if (currentSheet) {
|
|
956
|
+
currentSheet.refCount--;
|
|
957
|
+
if (currentSheet.refCount === 0) {
|
|
958
|
+
removeStyleSheet(host, currentSheet);
|
|
959
|
+
delete currentSheet.refCount;
|
|
960
|
+
delete host[id];
|
|
928
961
|
}
|
|
929
962
|
}
|
|
930
963
|
};
|
|
@@ -1382,5 +1415,5 @@ const template = (template) => {
|
|
|
1382
1415
|
};
|
|
1383
1416
|
};
|
|
1384
1417
|
|
|
1385
|
-
export { $, $useContext, Case, Computed, Default, Effect, For, Fragment, If, Replace, Signal, Some, Switch, batch, computed, createComponent, createContext,
|
|
1418
|
+
export { $, $useContext, Case, Computed, Default, Effect, For, Fragment, If, Replace, Signal, Some, Switch, batch, computed, createComponent, createContext, createCssModule, createDom, createElement, createLogicComponent, createRoot, cssHash, effect, getCurrentInstance, h2, id, instanceCreate, instanceCreateElement, instanceDestroy, instanceGetElements, instanceInit, jsx, jsxs, mounts, onDestroy, onMount, ref, registerWebComponent, securityGetCurrentInstance, signal, styleSheet, template, untrack, wc };
|
|
1386
1419
|
//# sourceMappingURL=index.js.map
|