sprae 2.8.4 → 2.10.1
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/package.json +1 -1
- package/readme.md +1 -1
- package/sprae.js +151 -135
- package/sprae.min.js +1 -1
- package/src/directives.js +61 -68
- package/src/domdiff.js +68 -0
- package/test/index.html +2 -0
- package/test/test.js +22 -0
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -176,7 +176,7 @@ Add event listeners.
|
|
|
176
176
|
* `.prevent`, `.stop` – prevent default or stop propagation.
|
|
177
177
|
* `.window`, `.document`, `.outside`, `.self` – specify event target.
|
|
178
178
|
* `.throttle-108`, `.debounce-108` – define throttling or postponing callback with (optional) timeout in ms.
|
|
179
|
-
* `.ctrl`, `.shift`, `.alt`, `.meta`, `.
|
|
179
|
+
* `.ctrl`, `.shift`, `.alt`, `.meta`, `.arrow`, `.enter`, `.escape`, `.tab`, `.space`, `.backspace`, `.delete`, `.digit`, `.letter`, `.character` – filter by [`event.key`](https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_key_values).
|
|
180
180
|
* `.*` – any other modifier has no effect, but allows binding multiple handlers to same event (like jQuery event classes).
|
|
181
181
|
|
|
182
182
|
#### `:data="values"`
|
package/sprae.js
CHANGED
|
@@ -434,37 +434,57 @@ function isObject(v2) {
|
|
|
434
434
|
return v2 && v2.constructor === Object;
|
|
435
435
|
}
|
|
436
436
|
|
|
437
|
-
//
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
437
|
+
// src/domdiff.js
|
|
438
|
+
function domdiff_default(parent, a2, b2, before) {
|
|
439
|
+
const aIdx = /* @__PURE__ */ new Map();
|
|
440
|
+
const bIdx = /* @__PURE__ */ new Map();
|
|
441
|
+
let i2;
|
|
442
|
+
let j;
|
|
443
|
+
for (i2 = 0; i2 < a2.length; i2++) {
|
|
444
|
+
aIdx.set(a2[i2], i2);
|
|
445
|
+
}
|
|
446
|
+
for (i2 = 0; i2 < b2.length; i2++) {
|
|
447
|
+
bIdx.set(b2[i2], i2);
|
|
448
|
+
}
|
|
449
|
+
for (i2 = j = 0; i2 !== a2.length || j !== b2.length; ) {
|
|
450
|
+
var aElm = a2[i2], bElm = b2[j];
|
|
451
|
+
if (aElm === null) {
|
|
452
|
+
i2++;
|
|
453
|
+
} else if (b2.length <= j) {
|
|
454
|
+
parent.removeChild(a2[i2]);
|
|
455
|
+
i2++;
|
|
456
|
+
} else if (a2.length <= i2) {
|
|
457
|
+
parent.insertBefore(bElm, a2[i2] || before);
|
|
458
|
+
j++;
|
|
459
|
+
} else if (aElm === bElm) {
|
|
460
|
+
i2++;
|
|
461
|
+
j++;
|
|
462
|
+
} else {
|
|
463
|
+
var curElmInNew = bIdx.get(aElm);
|
|
464
|
+
var wantedElmInOld = aIdx.get(bElm);
|
|
465
|
+
if (curElmInNew === void 0) {
|
|
466
|
+
parent.removeChild(a2[i2]);
|
|
467
|
+
i2++;
|
|
468
|
+
} else if (wantedElmInOld === void 0) {
|
|
469
|
+
parent.insertBefore(
|
|
470
|
+
bElm,
|
|
471
|
+
a2[i2] || before
|
|
472
|
+
);
|
|
473
|
+
j++;
|
|
474
|
+
} else {
|
|
475
|
+
parent.insertBefore(
|
|
476
|
+
a2[wantedElmInOld],
|
|
477
|
+
a2[i2] || before
|
|
478
|
+
);
|
|
479
|
+
a2[wantedElmInOld] = null;
|
|
480
|
+
if (wantedElmInOld > i2 + 1)
|
|
481
|
+
i2++;
|
|
482
|
+
j++;
|
|
483
|
+
}
|
|
457
484
|
}
|
|
458
|
-
while (!same(cur, end))
|
|
459
|
-
next = cur.nextSibling, remove(cur, parent), cur = next;
|
|
460
485
|
}
|
|
461
486
|
return b2;
|
|
462
|
-
}
|
|
463
|
-
swap.same = (a2, b2) => a2 == b2;
|
|
464
|
-
swap.replace = (a2, b2, parent) => parent.replaceChild(b2, a2);
|
|
465
|
-
swap.insert = (a2, b2, parent) => parent.insertBefore(b2, a2);
|
|
466
|
-
swap.remove = (a2, parent) => parent.removeChild(a2);
|
|
467
|
-
var swap_inflate_default = swap;
|
|
487
|
+
}
|
|
468
488
|
|
|
469
489
|
// node_modules/primitive-pool/index.js
|
|
470
490
|
var cache = {};
|
|
@@ -562,7 +582,7 @@ primary["each"] = (tpl, expr) => {
|
|
|
562
582
|
scope[each[0]] = item;
|
|
563
583
|
elScopes.push(scope);
|
|
564
584
|
}
|
|
565
|
-
|
|
585
|
+
domdiff_default(holder.parentNode, curEls, newEls, holder);
|
|
566
586
|
curEls = newEls;
|
|
567
587
|
for (let i2 = 0; i2 < newEls.length; i2++) {
|
|
568
588
|
sprae(newEls[i2], elScopes[i2]);
|
|
@@ -688,40 +708,35 @@ var directives_default = (el, expr, state, name) => {
|
|
|
688
708
|
};
|
|
689
709
|
var _stop = Symbol("stop");
|
|
690
710
|
var addListener = (el, evt, startFn) => {
|
|
691
|
-
let evts = evt.split("..").map((e3) => e3.startsWith("on") ? e3.slice(2) : e3), opts = {
|
|
692
|
-
evts[0] = evts[0].replace(
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
if (conditions.length) {
|
|
700
|
-
let _cb = startFn;
|
|
701
|
-
startFn = (e3) => {
|
|
702
|
-
for (let cond2 of conditions)
|
|
703
|
-
if (cond2(e3) === false)
|
|
711
|
+
let evts = evt.split("..").map((e3) => e3.startsWith("on") ? e3.slice(2) : e3), opts = { target: el, hooks: [], fn: startFn };
|
|
712
|
+
evts[0] = evts[0].replace(/\.(\w+)?-?([\w]+)?/g, (match, mod, param) => (mods[mod]?.(opts, param), ""));
|
|
713
|
+
let { target, hooks, fn, ...listenerOpts } = opts;
|
|
714
|
+
if (hooks.length) {
|
|
715
|
+
let _fn = fn;
|
|
716
|
+
fn = (e3) => {
|
|
717
|
+
for (let hook of hooks)
|
|
718
|
+
if (hook(e3) === false)
|
|
704
719
|
return false;
|
|
705
|
-
|
|
720
|
+
return _fn(e3);
|
|
706
721
|
};
|
|
707
722
|
}
|
|
708
723
|
if (evts.length == 1)
|
|
709
|
-
|
|
724
|
+
target.addEventListener(evts[0], fn, listenerOpts);
|
|
710
725
|
else {
|
|
711
|
-
const nextEvt = (
|
|
726
|
+
const nextEvt = (handler, cur = 0) => {
|
|
712
727
|
let curListener = (e3) => {
|
|
713
|
-
|
|
714
|
-
if (typeof (
|
|
715
|
-
|
|
728
|
+
target.removeEventListener(evts[cur], curListener);
|
|
729
|
+
if (typeof (handler = handler.call(target, e3)) !== "function")
|
|
730
|
+
handler = () => {
|
|
716
731
|
};
|
|
717
732
|
if (++cur < evts.length)
|
|
718
|
-
nextEvt(
|
|
719
|
-
else if (!
|
|
720
|
-
nextEvt(
|
|
733
|
+
nextEvt(handler, cur);
|
|
734
|
+
else if (!fn[_stop])
|
|
735
|
+
nextEvt(fn);
|
|
721
736
|
};
|
|
722
|
-
|
|
737
|
+
target.addEventListener(evts[cur], curListener, listenerOpts);
|
|
723
738
|
};
|
|
724
|
-
nextEvt(
|
|
739
|
+
nextEvt(fn);
|
|
725
740
|
}
|
|
726
741
|
};
|
|
727
742
|
var removeListener = (el, evt, fn) => {
|
|
@@ -730,118 +745,119 @@ var removeListener = (el, evt, fn) => {
|
|
|
730
745
|
el.removeEventListener(evt, fn);
|
|
731
746
|
};
|
|
732
747
|
var mods = {
|
|
733
|
-
|
|
748
|
+
prevent({ hooks }) {
|
|
749
|
+
hooks.push((e3) => {
|
|
750
|
+
e3.preventDefault();
|
|
751
|
+
});
|
|
752
|
+
},
|
|
753
|
+
stop({ hooks }) {
|
|
754
|
+
hooks.push((e3) => {
|
|
755
|
+
e3.stopPropagation();
|
|
756
|
+
});
|
|
757
|
+
},
|
|
758
|
+
throttle(opts, limit) {
|
|
759
|
+
let { fn } = opts;
|
|
734
760
|
limit = Number(limit) || 108;
|
|
735
761
|
let pause, planned, block = () => {
|
|
736
762
|
pause = true;
|
|
737
763
|
setTimeout(() => {
|
|
738
764
|
pause = false;
|
|
739
765
|
if (planned)
|
|
740
|
-
|
|
766
|
+
return planned = false, block(), fn(e);
|
|
741
767
|
});
|
|
742
768
|
};
|
|
743
|
-
|
|
769
|
+
opts.fn = (e3) => {
|
|
744
770
|
if (pause)
|
|
745
771
|
return planned = true;
|
|
746
|
-
cb(e3);
|
|
747
772
|
block();
|
|
748
|
-
|
|
773
|
+
return fn(e3);
|
|
774
|
+
};
|
|
749
775
|
},
|
|
750
|
-
debounce(
|
|
776
|
+
debounce(opts, wait) {
|
|
777
|
+
let { fn } = opts;
|
|
751
778
|
wait = Number(wait) || 108;
|
|
752
|
-
let timeout
|
|
753
|
-
|
|
754
|
-
cb(e);
|
|
755
|
-
};
|
|
756
|
-
return [el, (e3) => {
|
|
779
|
+
let timeout;
|
|
780
|
+
opts.fn = (e3) => {
|
|
757
781
|
clearTimeout(timeout);
|
|
758
|
-
timeout = setTimeout(
|
|
759
|
-
|
|
782
|
+
timeout = setTimeout(() => {
|
|
783
|
+
timeout = null;
|
|
784
|
+
fn(e3);
|
|
785
|
+
}, wait);
|
|
786
|
+
};
|
|
760
787
|
},
|
|
761
|
-
window(
|
|
762
|
-
|
|
788
|
+
window(opts) {
|
|
789
|
+
opts.target = window;
|
|
763
790
|
},
|
|
764
|
-
document(
|
|
765
|
-
|
|
791
|
+
document(opts) {
|
|
792
|
+
opts.target = document;
|
|
766
793
|
},
|
|
767
|
-
outside(
|
|
768
|
-
|
|
769
|
-
if (
|
|
794
|
+
outside({ target, hooks }) {
|
|
795
|
+
hooks.push((e3) => {
|
|
796
|
+
if (target.contains(e3.target))
|
|
770
797
|
return false;
|
|
771
798
|
if (e3.target.isConnected === false)
|
|
772
799
|
return false;
|
|
773
|
-
if (
|
|
800
|
+
if (target.offsetWidth < 1 && target.offsetHeight < 1)
|
|
774
801
|
return false;
|
|
775
|
-
}
|
|
802
|
+
});
|
|
776
803
|
},
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
e3.
|
|
780
|
-
}
|
|
781
|
-
},
|
|
782
|
-
stop(el, cb) {
|
|
783
|
-
return [el, cb, (e3) => {
|
|
784
|
-
e3.stopPropagation();
|
|
785
|
-
}];
|
|
804
|
+
self({ target, hooks }) {
|
|
805
|
+
hooks.push((e3) => {
|
|
806
|
+
return e3.target === target;
|
|
807
|
+
});
|
|
786
808
|
},
|
|
787
|
-
|
|
788
|
-
return [el, cb, (e3) => {
|
|
789
|
-
return e3.target === el;
|
|
790
|
-
}];
|
|
791
|
-
},
|
|
792
|
-
once(el, cb, opts) {
|
|
809
|
+
once(opts) {
|
|
793
810
|
opts.once = true;
|
|
794
|
-
return [el, cb];
|
|
795
811
|
},
|
|
796
|
-
passive(
|
|
812
|
+
passive(opts) {
|
|
797
813
|
opts.passive = true;
|
|
798
|
-
return [el, cb];
|
|
799
814
|
},
|
|
800
|
-
capture(
|
|
815
|
+
capture(opts) {
|
|
801
816
|
opts.capture = true;
|
|
802
|
-
|
|
817
|
+
},
|
|
818
|
+
ctrl({ hooks }) {
|
|
819
|
+
hooks.push((e3) => e3.key === "Control" || e3.key === "Ctrl");
|
|
820
|
+
},
|
|
821
|
+
shift({ hooks }) {
|
|
822
|
+
hooks.push((e3) => e3.key === "Shift");
|
|
823
|
+
},
|
|
824
|
+
alt({ hooks }) {
|
|
825
|
+
hooks.push((e3) => e3.key === "Alt");
|
|
826
|
+
},
|
|
827
|
+
meta({ hooks }) {
|
|
828
|
+
hooks.push((e3) => e3.key === "Meta");
|
|
829
|
+
},
|
|
830
|
+
arrow({ hooks }) {
|
|
831
|
+
hooks.push((e3) => e3.key.startsWith("Arrow"));
|
|
832
|
+
},
|
|
833
|
+
enter({ hooks }) {
|
|
834
|
+
hooks.push((e3) => e3.key === "Enter");
|
|
835
|
+
},
|
|
836
|
+
escape({ hooks }) {
|
|
837
|
+
hooks.push((e3) => e3.key.startsWith("Esc"));
|
|
838
|
+
},
|
|
839
|
+
tab({ hooks }) {
|
|
840
|
+
hooks.push((e3) => e3.key === "Tab");
|
|
841
|
+
},
|
|
842
|
+
space({ hooks }) {
|
|
843
|
+
hooks.push((e3) => e3.key === "Space" || e3.key === " ");
|
|
844
|
+
},
|
|
845
|
+
backspace({ hooks }) {
|
|
846
|
+
hooks.push((e3) => e3.key === "Backspace");
|
|
847
|
+
},
|
|
848
|
+
delete({ hooks }) {
|
|
849
|
+
hooks.push((e3) => e3.key === "Delete");
|
|
850
|
+
},
|
|
851
|
+
digit({ hooks }) {
|
|
852
|
+
hooks.push((e3) => /\d/.test(e3.key));
|
|
853
|
+
},
|
|
854
|
+
letter({ hooks }) {
|
|
855
|
+
hooks.push((e3) => /[a-zA-Z]/.test(e3.key));
|
|
856
|
+
},
|
|
857
|
+
character({ hooks }) {
|
|
858
|
+
hooks.push((e3) => /^\S$/.test(e3.key));
|
|
803
859
|
}
|
|
804
860
|
};
|
|
805
|
-
var keys = {
|
|
806
|
-
ctrl: "Control Ctrl",
|
|
807
|
-
shift: "Shift",
|
|
808
|
-
alt: "Alt",
|
|
809
|
-
meta: "Meta",
|
|
810
|
-
cmd: "Meta",
|
|
811
|
-
down: "ArrowDown",
|
|
812
|
-
up: "ArrowUp",
|
|
813
|
-
left: "ArrowLeft",
|
|
814
|
-
right: "ArrowRight",
|
|
815
|
-
end: "End",
|
|
816
|
-
home: "Home",
|
|
817
|
-
pagedown: "PageDown",
|
|
818
|
-
pageup: "PageUp",
|
|
819
|
-
enter: "Enter",
|
|
820
|
-
esc: "Escape",
|
|
821
|
-
escape: "Escape",
|
|
822
|
-
tab: "Tab",
|
|
823
|
-
backspace: "Backspace",
|
|
824
|
-
delete: "Delete",
|
|
825
|
-
space: / /,
|
|
826
|
-
plus: /\+/,
|
|
827
|
-
minus: /\-/,
|
|
828
|
-
star: /\*/,
|
|
829
|
-
slash: /\//,
|
|
830
|
-
period: /\./,
|
|
831
|
-
equal: /\=/,
|
|
832
|
-
underscore: /\_/,
|
|
833
|
-
alnum: /\w/,
|
|
834
|
-
letter: /[a-zA-Z]/,
|
|
835
|
-
digit: /\d/
|
|
836
|
-
};
|
|
837
|
-
keys.arrow = keys.down + keys.up + keys.left + keys.right;
|
|
838
|
-
for (let keyAttr in keys) {
|
|
839
|
-
let keyName = keys[keyAttr];
|
|
840
|
-
mods[keyAttr] = (el, cb, opts, extraKey) => [el, cb, (e3) => {
|
|
841
|
-
if (!e3.key || (e3.key.length > 2 ? !keyName.includes?.(e3.key) : !keyName.test?.(e3.key)))
|
|
842
|
-
return false;
|
|
843
|
-
}];
|
|
844
|
-
}
|
|
845
861
|
var attr = (el, name, v2) => {
|
|
846
862
|
if (v2 == null || v2 === false)
|
|
847
863
|
el.removeAttribute(name);
|
package/sprae.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function t(){throw new Error("Cycle detected")}function r(){if(o>1)o--;else{for(var t,e=!1;void 0!==n;){var r=n;for(n=void 0,s++;void 0!==r;){var i=r.o;if(r.o=void 0,r.f&=-3,!(8&r.f)&&f(r))try{r.c()}catch(r){e||(t=r,e=!0)}r=i}}if(s=0,o--,e)throw t}}var i=void 0,n=void 0,o=0,s=0,l=0;function a(t){if(void 0!==i){var e=t.n;if(void 0===e||e.t!==i)return i.s=e={i:0,S:t,p:void 0,n:i.s,t:i,e:void 0,x:void 0,r:e},t.n=e,32&i.f&&t.S(e),e;if(-1===e.i)return e.i=0,void 0!==e.p&&(e.p.n=e.n,void 0!==e.n&&(e.n.p=e.p),e.p=void 0,e.n=i.s,i.s.p=e,i.s=e),e}}function u(t){this.v=t,this.i=0,this.n=void 0,this.t=void 0}function f(t){for(var e=t.s;void 0!==e;e=e.n)if(e.S.i!==e.i||!e.S.h()||e.S.i!==e.i)return!0;return!1}function c(t){for(var e=t.s;void 0!==e;e=e.n){var r=e.S.n;void 0!==r&&(e.r=r),e.S.n=e,e.i=-1}}function h(t){for(var e=t.s,r=void 0;void 0!==e;){var i=e.n;-1===e.i?(e.S.U(e),e.n=void 0):(void 0!==r&&(r.p=e),e.p=void 0,e.n=r,r=e),e.S.n=e.r,void 0!==e.r&&(e.r=void 0),e=i}t.s=r}function v(t){u.call(this,void 0),this.x=t,this.s=void 0,this.g=l-1,this.f=4}function p(t){var e=t.u;if(t.u=void 0,"function"==typeof e){o++;var n=i;i=void 0;try{e()}catch(e){throw t.f&=-2,t.f|=8,d(t),e}finally{i=n,r()}}}function d(t){for(var e=t.s;void 0!==e;e=e.n)e.S.U(e);t.x=void 0,t.s=void 0,p(t)}function y(t){if(i!==this)throw new Error("Out-of-order effect");h(this),i=t,this.f&=-2,8&this.f&&d(this),r()}function b(t){this.x=t,this.u=void 0,this.s=void 0,this.o=void 0,this.f=32}function m(t){var e=new b(t);return e.c(),e.d.bind(e)}u.prototype.h=function(){return!0},u.prototype.S=function(t){this.t!==t&&void 0===t.e&&(t.x=this.t,void 0!==this.t&&(this.t.e=t),this.t=t)},u.prototype.U=function(t){var e=t.e,r=t.x;void 0!==e&&(e.x=r,t.e=void 0),void 0!==r&&(r.e=e,t.x=void 0),t===this.t&&(this.t=r)},u.prototype.subscribe=function(t){var e=this;return m((function(){var r=e.value,i=32&this.f;this.f&=-33;try{t(r)}finally{this.f|=i}}))},u.prototype.valueOf=function(){return this.value},u.prototype.toString=function(){return this.value+""},u.prototype.peek=function(){return this.v},Object.defineProperty(u.prototype,"value",{get:function(){var t=a(this);return void 0!==t&&(t.i=this.i),this.v},set:function(e){if(e!==this.v){s>100&&t(),this.v=e,this.i++,l++,o++;try{for(var i=this.t;void 0!==i;i=i.x)i.t.N()}finally{r()}}}}),(v.prototype=new u).h=function(){if(this.f&=-3,1&this.f)return!1;if(32==(36&this.f))return!0;if(this.f&=-5,this.g===l)return!0;if(this.g=l,this.f|=1,this.i>0&&!f(this))return this.f&=-2,!0;var t=i;try{c(this),i=this;var e=this.x();(16&this.f||this.v!==e||0===this.i)&&(this.v=e,this.f&=-17,this.i++)}catch(t){this.v=t,this.f|=16,this.i++}return i=t,h(this),this.f&=-2,!0},v.prototype.S=function(t){if(void 0===this.t){this.f|=36;for(var e=this.s;void 0!==e;e=e.n)e.S.S(e)}u.prototype.S.call(this,t)},v.prototype.U=function(t){if(u.prototype.U.call(this,t),void 0===this.t){this.f&=-33;for(var e=this.s;void 0!==e;e=e.n)e.S.U(e)}},v.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var t=this.t;void 0!==t;t=t.x)t.t.N()}},v.prototype.peek=function(){if(this.h()||t(),16&this.f)throw this.v;return this.v},Object.defineProperty(v.prototype,"value",{get:function(){1&this.f&&t();var e=a(this);if(this.h(),void 0!==e&&(e.i=this.i),16&this.f)throw this.v;return this.v}}),b.prototype.c=function(){var t=this.S();try{8&this.f||void 0===this.x||(this.u=this.x())}finally{t()}},b.prototype.S=function(){1&this.f&&t(),this.f|=1,this.f&=-9,p(this),c(this),o++;var e=i;return i=this,y.bind(this,e)},b.prototype.N=function(){2&this.f||(this.f|=2,this.o=n,n=this)},b.prototype.d=function(){this.f|=8,1&this.f||d(this)},Symbol.observable||=Symbol("observable");var g=new FinalizationRegistry((t=>t.call?.())),w=(t,e,r,i,n,o)=>{return t&&(s=(t[Symbol.observable]?.()||t).subscribe?.(e,r,i),o=s&&(()=>s.unsubscribe?.())||t.set&&t.call?.(n,e)||(t.then?.((t=>(!n&&e(t),i?.())),r)||(async o=>{try{for await(o of t){if(n)return;e(o)}i?.()}catch(t){r?.(t)}})())&&(t=>n=1),g.register(t,o),o);var s},A=t=>t&&t[S],S=Symbol("signal-struct");function x(t,e){if(A(t)&&!e)return t;if(O(t)){const n=Object.create(e||Object.getPrototypeOf(t)),o={},s=Object.getOwnPropertyDescriptors(t);for(let t in s){let e=s[t];if(e.get){let r=o[t]=new v(e.get.bind(n));Object.defineProperty(n,t,{get:()=>r.value,set:e.set?.bind(n),configurable:!1,enumerable:!0})}else{let s=e.value,l=(i=s)&&!!(i[Symbol.observable]||i[Symbol.asyncIterator]||i.call&&i.set||i.subscribe||i.then),a=o[t]=(r=s)&&r.peek?s:new u(l?void 0:O(s)?Object.seal(x(s)):Array.isArray(s)?x(s):s);l&&w(s,(t=>a.value=t)),Object.defineProperty(n,t,{get:()=>a.value,set(t){if(O(t)){if(O(a.value))try{return void Object.assign(a.value,t)}catch(t){}a.value=Object.seal(x(t))}else Array.isArray(t)?a.value=x(t):a.value=t},enumerable:!0,configurable:!1})}}return Object.defineProperty(n,S,{configurable:!1,enumerable:!1,value:!0}),n}var r,i;if(Array.isArray(t)&&!A(t[0]))for(let e=0;e<t.length;e++)t[e]=x(t[e]);return t}function O(t){return t&&t.constructor===Object}x.isStruct=A;var j=(t,e,r,i=null)=>{let n,o,s,l=0,a=r.length,u=e.length,{remove:f,same:c,insert:h,replace:v}=j;for(;l<a&&l<u&&c(e[l],r[l]);)l++;for(;l<a&&l<u&&c(r[a-1],e[u-1]);)i=r[(--u,--a)];if(l==u)for(;l<a;)h(i,r[l++],t);else{for(n=e[l];l<a;)s=r[l++],o=n?n.nextSibling:i,c(n,s)?n=o:l<a&&c(r[l],o)?(v(n,s,t),n=o):h(n,s,t);for(;!c(n,i);)o=n.nextSibling,f(n,t),n=o}return r};j.same=(t,e)=>t==e,j.replace=(t,e,r)=>r.replaceChild(e,t),j.insert=(t,e,r)=>r.insertBefore(e,t),j.remove=(t,e)=>e.removeChild(t);var N=j,E={},k={},P={},W=t=>null===t?k:void 0===t?P:"number"==typeof t||t instanceof Number?E[t]||(E[t]=new Number(t)):"string"==typeof t||t instanceof String?E[t]||(E[t]=new String(t)):"boolean"==typeof t||t instanceof Boolean?E[t]||(E[t]=new Boolean(t)):t,C={},T={};C.if=(t,e)=>{let r=document.createTextNode(""),i=[F(t,e,":if")],n=[t],o=t;for(;(o=t.nextElementSibling)&&o.hasAttribute(":else");)o.removeAttribute(":else"),(e=o.getAttribute(":if"))?(o.removeAttribute(":if"),o.remove(),n.push(o),i.push(F(t,e,":else :if"))):(o.remove(),n.push(o),i.push((()=>1)));return t.replaceWith(o=r),t=>{let e=i.findIndex((e=>e(t)));n[e]!=o&&((o[D]||o).replaceWith(o=n[e]||r),q(o,t))}},C.with=(t,e,r)=>{q(t,x(F(t,e,"with")(r),r))};var D=Symbol(":each");C.each=(t,e)=>{let r=function(t){let e=/,([^,\}\]]*)(?:,([^,\}\]]*))?$/,r=t.match(/([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/);if(!r)return;let i=r[2].trim(),n=r[1].replace(/^\s*\(|\)\s*$/g,"").trim(),o=n.match(e);return o?[n.replace(e,"").trim(),o[1].trim(),i]:[n,"",i]}(e);if(!r)return H(new Error,t,e);const i=t[D]=document.createTextNode("");t.replaceWith(i);const n=F(t,r[2],":each"),o=t.getAttribute(":key"),s=o?F(null,o):null;t.removeAttribute(":key");const l=new WeakMap,a=new WeakMap;let u=[];return o=>{let f=n(o);f?"number"==typeof f?f=Array.from({length:f},((t,e)=>[e,e+1])):Array.isArray(f)?f=f.map(((t,e)=>[e+1,t])):"object"==typeof f?f=Object.entries(f):H(Error("Bad list value"),t,e,":each"):f=[];let c=[],h=[];for(let[e,i]of f){let n,u,f=s?.({[r[0]]:i,[r[1]]:e});("string"==typeof(v=f)||"boolean"==typeof v||"number"==typeof v)&&(f=W(f)),null==f?n=t.cloneNode(!0):(n=a.get(f))||a.set(f,n=t.cloneNode(!0)),c.push(n),null!=f&&(u=l.get(f))?u[r[0]]=i:(u=x({[r[0]]:i,[r[1]]:e},o),null!=f&&l.set(f,u)),h.push(u)}var v;N(i.parentNode,u,c,i),u=c;for(let t=0;t<c.length;t++)q(c[t],h[t])}},T.ref=(t,e,r)=>{r[e]=t},T.id=(t,e)=>{let r=F(t,e,":id");return e=>{return i=r(e),t.id=i||0===i?i:"";var i}},T.class=(t,e)=>{let r=F(t,e,":class"),i=t.className;return e=>{let n=r(e);t.className=i+typeof n=="string"?n:(Array.isArray(n)?n:Object.entries(n).map((([t,e])=>e?t:""))).filter(Boolean).join(" ")}},T.style=(t,e)=>{let r=F(t,e,":style"),i=t.getAttribute("style")||"";return i.endsWith(";")||(i+="; "),e=>{let n=r(e);if("string"==typeof n)t.setAttribute("style",i+n);else for(let e in n)t.style[e]=n[e]}},T.text=(t,e)=>{let r=F(t,e,":text");return e=>{let i=r(e);t.textContent=null==i?"":i}},T.data=(t,e)=>{let r=F(t,e,":data");return e=>{let i=r(e);for(let e in i)t.dataset[e]=i[e]}},T.aria=(t,e)=>{let r=F(t,e,":aria");return e=>(e=>{for(let r in e)R(t,"aria-"+I(r),null==e[r]?null:e[r]+"")})(r(e))},T[""]=(t,e)=>{let r=F(t,e,":");if(r)return e=>{let i=r(e);for(let e in i)R(t,I(e),i[e])}},T.value=(t,e)=>{let r,i,n=F(t,e,":value"),o="text"===t.type||""===t.type?e=>t.setAttribute("value",t.value=null==e?"":e):"TEXTAREA"===t.tagName||"text"===t.type||""===t.type?e=>(r=t.selectionStart,i=t.selectionEnd,t.setAttribute("value",t.value=null==e?"":e),r&&t.setSelectionRange(r,i)):"checkbox"===t.type?e=>(t.value=e?"on":"",R(t,"checked",e)):"select-one"===t.type?e=>{for(let e in t.options)e.removeAttribute("selected");t.value=e,t.selectedOptions[0]?.setAttribute("selected","")}:e=>t.value=e;return t=>o(n(t))},T.on=(t,e)=>{let r=F(t,e,":on");return e=>{let i=r(e);for(let e in i)B(t,e,i[e]);return()=>{for(let e in i)L(t,e,i[e])}}};var U=(t,e,r,i)=>{let n=i.startsWith("on")&&i.slice(2),o=F(t,e,":"+i);if(o)return n?e=>{let r=o(e)||(()=>{});return B(t,n,r),()=>L(t,n,r)}:e=>R(t,i,o(e))},$=Symbol("stop"),B=(t,e,r)=>{let i,n=e.split("..").map((t=>t.startsWith("on")?t.slice(2):t)),o={},s=[];if(n[0]=n[0].replace(/\.(\w+)?-?([\w]+)?/g,((e,n,l)=>((n=M[n])&&([t,r,i]=n(t,r,o,l),i&&s.push(i)),""))),s.length){let t=r;r=e=>{for(let t of s)if(!1===t(e))return!1;t(e)}}if(1==n.length)t.addEventListener(n[0],r,o);else{const e=(i,s=0)=>{let l=o=>{t.removeEventListener(n[s],l),"function"!=typeof(i=i.call(t,o))&&(i=()=>{}),++s<n.length?e(i,s):r[$]||e(r)};t.addEventListener(n[s],l,o)};e(r)}},L=(t,e,r)=>{e.indexOf("..")>=0&&(r[$]=!0),t.removeEventListener(e,r)},M={throttle(t,r,i,n){n=Number(n)||108;let o,s,l=()=>{o=!0,setTimeout((()=>{o=!1,s&&(r(e),s=!1,l())}))};return[t,t=>{if(o)return s=!0;r(t),l()}]},debounce(t,r,i,n){n=Number(n)||108;let o,s=()=>{o=null,r(e)};return[t,t=>{clearTimeout(o),o=setTimeout(s,n)}]},window:(t,e)=>[window,e],document:(t,e)=>[document,e],outside:(t,e)=>[t,e,e=>!t.contains(e.target)&&!1!==e.target.isConnected&&!(t.offsetWidth<1&&t.offsetHeight<1)&&void 0],prevent:(t,e)=>[t,e,t=>{t.preventDefault()}],stop:(t,e)=>[t,e,t=>{t.stopPropagation()}],self:(t,e)=>[t,e,e=>e.target===t],once:(t,e,r)=>(r.once=!0,[t,e]),passive:(t,e,r)=>(r.passive=!0,[t,e]),capture:(t,e,r)=>(r.capture=!0,[t,e])},_={ctrl:"Control Ctrl",shift:"Shift",alt:"Alt",meta:"Meta",cmd:"Meta",down:"ArrowDown",up:"ArrowUp",left:"ArrowLeft",right:"ArrowRight",end:"End",home:"Home",pagedown:"PageDown",pageup:"PageUp",enter:"Enter",esc:"Escape",escape:"Escape",tab:"Tab",backspace:"Backspace",delete:"Delete",space:/ /,plus:/\+/,minus:/\-/,star:/\*/,slash:/\//,period:/\./,equal:/\=/,underscore:/\_/,alnum:/\w/,letter:/[a-zA-Z]/,digit:/\d/};_.arrow=_.down+_.up+_.left+_.right;for(let t in _){let e=_[t];M[t]=(t,r,i,n)=>[t,r,t=>{if(!t.key||(t.key.length>2?!e.includes?.(t.key):!e.test?.(t.key)))return!1}]}var R=(t,e,r)=>{null==r||!1===r?t.removeAttribute(e):t.setAttribute(e,!0===r?"":"number"==typeof r||"string"==typeof r?r:"")},z={};function F(t,e,r){let i=z[e];if(!i){let n=/^[\n\s]*if.*\(.*\)/.test(e)||/^(let|const)\s/.test(e)?`(() => { ${e} })()`:e;try{i=z[e]=new Function("__scope",`with (__scope) { return ${n} };`)}catch(i){return H(i,t,e,r)}}return n=>{let o;try{o=i.call(t,n)}catch(i){return H(i,t,e,r)}return o}}function H(t,e,r,i){Object.assign(t,{element:e,expression:r}),console.warn(`∴ ${t.message}\n\n${i}=${r?`"${r}"\n\n`:""}`,e),setTimeout((()=>{throw t}),0)}function I(t){return t.replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,(t=>"-"+t.toLowerCase()))}var Z=new WeakMap;function q(t,e){if(!t.children)return;if(Z.has(t)){let i=Z.get(t);return function(t){if(o>0)return t();o++;try{t()}finally{r()}}((()=>Object.assign(i,e))),i}const i=x(e||{}),n=[],s=(t,e=t.parentNode)=>{for(let r in C){let o=":"+r;if(t.hasAttribute?.(o)){let s=t.getAttribute(o);if(t.removeAttribute(o),n.push(C[r](t,s,i,r)),Z.has(t)||t.parentNode!==e)return!1}}if(t.attributes)for(let r=0;r<t.attributes.length;){let o=t.attributes[r];if(":"!==o.name[0]){r++;continue}t.removeAttribute(o.name);let s=o.value,l=o.name.slice(1).split(":");for(let r of l){let o=T[r]||U;if(n.push(o(t,s,i,r)),Z.has(t)||t.parentNode!==e)return!1}}for(let e,r=0;e=t.children[r];r++)!1===s(e,t)&&r--};s(t);for(let t of n)if(t){let e;m((()=>{"function"==typeof e&&e(),e=t(i)}))}return Object.seal(i),Z.set(t,i),i}var X=q;export{X as default};
|
|
1
|
+
function t(){throw new Error("Cycle detected")}function i(){if(n>1)n--;else{for(var t,e=!1;void 0!==o;){var i=o;for(o=void 0,s++;void 0!==i;){var r=i.o;if(i.o=void 0,i.f&=-3,!(8&i.f)&&f(i))try{i.c()}catch(i){e||(t=i,e=!0)}i=r}}if(s=0,n--,e)throw t}}var r=void 0,o=void 0,n=0,s=0,l=0;function u(t){if(void 0!==r){var e=t.n;if(void 0===e||e.t!==r)return r.s=e={i:0,S:t,p:void 0,n:r.s,t:r,e:void 0,x:void 0,r:e},t.n=e,32&r.f&&t.S(e),e;if(-1===e.i)return e.i=0,void 0!==e.p&&(e.p.n=e.n,void 0!==e.n&&(e.n.p=e.p),e.p=void 0,e.n=r.s,r.s.p=e,r.s=e),e}}function a(t){this.v=t,this.i=0,this.n=void 0,this.t=void 0}function f(t){for(var e=t.s;void 0!==e;e=e.n)if(e.S.i!==e.i||!e.S.h()||e.S.i!==e.i)return!0;return!1}function h(t){for(var e=t.s;void 0!==e;e=e.n){var i=e.S.n;void 0!==i&&(e.r=i),e.S.n=e,e.i=-1}}function c(t){for(var e=t.s,i=void 0;void 0!==e;){var r=e.n;-1===e.i?(e.S.U(e),e.n=void 0):(void 0!==i&&(i.p=e),e.p=void 0,e.n=i,i=e),e.S.n=e.r,void 0!==e.r&&(e.r=void 0),e=r}t.s=i}function v(t){a.call(this,void 0),this.x=t,this.s=void 0,this.g=l-1,this.f=4}function p(t){var e=t.u;if(t.u=void 0,"function"==typeof e){n++;var o=r;r=void 0;try{e()}catch(e){throw t.f&=-2,t.f|=8,d(t),e}finally{r=o,i()}}}function d(t){for(var e=t.s;void 0!==e;e=e.n)e.S.U(e);t.x=void 0,t.s=void 0,p(t)}function y(t){if(r!==this)throw new Error("Out-of-order effect");c(this),r=t,this.f&=-2,8&this.f&&d(this),i()}function b(t){this.x=t,this.u=void 0,this.s=void 0,this.o=void 0,this.f=32}function g(t){var e=new b(t);return e.c(),e.d.bind(e)}a.prototype.h=function(){return!0},a.prototype.S=function(t){this.t!==t&&void 0===t.e&&(t.x=this.t,void 0!==this.t&&(this.t.e=t),this.t=t)},a.prototype.U=function(t){var e=t.e,i=t.x;void 0!==e&&(e.x=i,t.e=void 0),void 0!==i&&(i.e=e,t.x=void 0),t===this.t&&(this.t=i)},a.prototype.subscribe=function(t){var e=this;return g((function(){var i=e.value,r=32&this.f;this.f&=-33;try{t(i)}finally{this.f|=r}}))},a.prototype.valueOf=function(){return this.value},a.prototype.toString=function(){return this.value+""},a.prototype.peek=function(){return this.v},Object.defineProperty(a.prototype,"value",{get:function(){var t=u(this);return void 0!==t&&(t.i=this.i),this.v},set:function(e){if(e!==this.v){s>100&&t(),this.v=e,this.i++,l++,n++;try{for(var r=this.t;void 0!==r;r=r.x)r.t.N()}finally{i()}}}}),(v.prototype=new a).h=function(){if(this.f&=-3,1&this.f)return!1;if(32==(36&this.f))return!0;if(this.f&=-5,this.g===l)return!0;if(this.g=l,this.f|=1,this.i>0&&!f(this))return this.f&=-2,!0;var t=r;try{h(this),r=this;var e=this.x();(16&this.f||this.v!==e||0===this.i)&&(this.v=e,this.f&=-17,this.i++)}catch(t){this.v=t,this.f|=16,this.i++}return r=t,c(this),this.f&=-2,!0},v.prototype.S=function(t){if(void 0===this.t){this.f|=36;for(var e=this.s;void 0!==e;e=e.n)e.S.S(e)}a.prototype.S.call(this,t)},v.prototype.U=function(t){if(a.prototype.U.call(this,t),void 0===this.t){this.f&=-33;for(var e=this.s;void 0!==e;e=e.n)e.S.U(e)}},v.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var t=this.t;void 0!==t;t=t.x)t.t.N()}},v.prototype.peek=function(){if(this.h()||t(),16&this.f)throw this.v;return this.v},Object.defineProperty(v.prototype,"value",{get:function(){1&this.f&&t();var e=u(this);if(this.h(),void 0!==e&&(e.i=this.i),16&this.f)throw this.v;return this.v}}),b.prototype.c=function(){var t=this.S();try{8&this.f||void 0===this.x||(this.u=this.x())}finally{t()}},b.prototype.S=function(){1&this.f&&t(),this.f|=1,this.f&=-9,p(this),h(this),n++;var e=r;return r=this,y.bind(this,e)},b.prototype.N=function(){2&this.f||(this.f|=2,this.o=o,o=this)},b.prototype.d=function(){this.f|=8,1&this.f||d(this)},Symbol.observable||=Symbol("observable");var m=new FinalizationRegistry((t=>t.call?.())),k=(t,e,i,r,o,n)=>{return t&&(s=(t[Symbol.observable]?.()||t).subscribe?.(e,i,r),n=s&&(()=>s.unsubscribe?.())||t.set&&t.call?.(o,e)||(t.then?.((t=>(!o&&e(t),r?.())),i)||(async n=>{try{for await(n of t){if(o)return;e(n)}r?.()}catch(t){i?.(t)}})())&&(t=>o=1),m.register(t,n),n);var s},w=t=>t&&t[S],S=Symbol("signal-struct");function A(t,e){if(w(t)&&!e)return t;if(x(t)){const o=Object.create(e||Object.getPrototypeOf(t)),n={},s=Object.getOwnPropertyDescriptors(t);for(let t in s){let e=s[t];if(e.get){let i=n[t]=new v(e.get.bind(o));Object.defineProperty(o,t,{get:()=>i.value,set:e.set?.bind(o),configurable:!1,enumerable:!0})}else{let s=e.value,l=(r=s)&&!!(r[Symbol.observable]||r[Symbol.asyncIterator]||r.call&&r.set||r.subscribe||r.then),u=n[t]=(i=s)&&i.peek?s:new a(l?void 0:x(s)?Object.seal(A(s)):Array.isArray(s)?A(s):s);l&&k(s,(t=>u.value=t)),Object.defineProperty(o,t,{get:()=>u.value,set(t){if(x(t)){if(x(u.value))try{return void Object.assign(u.value,t)}catch(t){}u.value=Object.seal(A(t))}else Array.isArray(t)?u.value=A(t):u.value=t},enumerable:!0,configurable:!1})}}return Object.defineProperty(o,S,{configurable:!1,enumerable:!1,value:!0}),o}var i,r;if(Array.isArray(t)&&!w(t[0]))for(let e=0;e<t.length;e++)t[e]=A(t[e]);return t}function x(t){return t&&t.constructor===Object}A.isStruct=w;var O={},j={},N={},E=t=>null===t?j:void 0===t?N:"number"==typeof t||t instanceof Number?O[t]||(O[t]=new Number(t)):"string"==typeof t||t instanceof String?O[t]||(O[t]=new String(t)):"boolean"==typeof t||t instanceof Boolean?O[t]||(O[t]=new Boolean(t)):t,W={},C={};W.if=(t,e)=>{let i=document.createTextNode(""),r=[_(t,e,":if")],o=[t],n=t;for(;(n=t.nextElementSibling)&&n.hasAttribute(":else");)n.removeAttribute(":else"),(e=n.getAttribute(":if"))?(n.removeAttribute(":if"),n.remove(),o.push(n),r.push(_(t,e,":else :if"))):(n.remove(),o.push(n),r.push((()=>1)));return t.replaceWith(n=i),t=>{let e=r.findIndex((e=>e(t)));o[e]!=n&&((n[T]||n).replaceWith(n=o[e]||i),I(n,t))}},W.with=(t,e,i)=>{I(t,A(_(t,e,"with")(i),i))};var T=Symbol(":each");W.each=(t,e)=>{let i=function(t){let e=/,([^,\}\]]*)(?:,([^,\}\]]*))?$/,i=t.match(/([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/);if(!i)return;let r=i[2].trim(),o=i[1].replace(/^\s*\(|\)\s*$/g,"").trim(),n=o.match(e);return n?[o.replace(e,"").trim(),n[1].trim(),r]:[o,"",r]}(e);if(!i)return R(new Error,t,e);const r=t[T]=document.createTextNode("");t.replaceWith(r);const o=_(t,i[2],":each"),n=t.getAttribute(":key"),s=n?_(null,n):null;t.removeAttribute(":key");const l=new WeakMap,u=new WeakMap;let a=[];return n=>{let f=o(n);f?"number"==typeof f?f=Array.from({length:f},((t,e)=>[e,e+1])):Array.isArray(f)?f=f.map(((t,e)=>[e+1,t])):"object"==typeof f?f=Object.entries(f):R(Error("Bad list value"),t,e,":each"):f=[];let h=[],c=[];for(let[e,r]of f){let o,a,f=s?.({[i[0]]:r,[i[1]]:e});("string"==typeof(v=f)||"boolean"==typeof v||"number"==typeof v)&&(f=E(f)),null==f?o=t.cloneNode(!0):(o=u.get(f))||u.set(f,o=t.cloneNode(!0)),h.push(o),null!=f&&(a=l.get(f))?a[i[0]]=r:(a=A({[i[0]]:r,[i[1]]:e},n),null!=f&&l.set(f,a)),c.push(a)}var v;!function(t,e,i,r){const o=new Map,n=new Map;let s,l;for(s=0;s<e.length;s++)o.set(e[s],s);for(s=0;s<i.length;s++)n.set(i[s],s);for(s=l=0;s!==e.length||l!==i.length;){var u=e[s],a=i[l];if(null===u)s++;else if(i.length<=l)t.removeChild(e[s]),s++;else if(e.length<=s)t.insertBefore(a,e[s]||r),l++;else if(u===a)s++,l++;else{var f=n.get(u),h=o.get(a);void 0===f?(t.removeChild(e[s]),s++):void 0===h?(t.insertBefore(a,e[s]||r),l++):(t.insertBefore(e[h],e[s]||r),e[h]=null,h>s+1&&s++,l++)}}}(r.parentNode,a,h,r),a=h;for(let t=0;t<h.length;t++)I(h[t],c[t])}},C.ref=(t,e,i)=>{i[e]=t},C.id=(t,e)=>{let i=_(t,e,":id");return e=>{return r=i(e),t.id=r||0===r?r:"";var r}},C.class=(t,e)=>{let i=_(t,e,":class"),r=t.className;return e=>{let o=i(e);t.className=r+typeof o=="string"?o:(Array.isArray(o)?o:Object.entries(o).map((([t,e])=>e?t:""))).filter(Boolean).join(" ")}},C.style=(t,e)=>{let i=_(t,e,":style"),r=t.getAttribute("style")||"";return r.endsWith(";")||(r+="; "),e=>{let o=i(e);if("string"==typeof o)t.setAttribute("style",r+o);else for(let e in o)t.style[e]=o[e]}},C.text=(t,e)=>{let i=_(t,e,":text");return e=>{let r=i(e);t.textContent=null==r?"":r}},C.data=(t,e)=>{let i=_(t,e,":data");return e=>{let r=i(e);for(let e in r)t.dataset[e]=r[e]}},C.aria=(t,e)=>{let i=_(t,e,":aria");return e=>(e=>{for(let i in e)U(t,"aria-"+z(i),null==e[i]?null:e[i]+"")})(i(e))},C[""]=(t,e)=>{let i=_(t,e,":");if(i)return e=>{let r=i(e);for(let e in r)U(t,z(e),r[e])}},C.value=(t,e)=>{let i,r,o=_(t,e,":value"),n="text"===t.type||""===t.type?e=>t.setAttribute("value",t.value=null==e?"":e):"TEXTAREA"===t.tagName||"text"===t.type||""===t.type?e=>(i=t.selectionStart,r=t.selectionEnd,t.setAttribute("value",t.value=null==e?"":e),i&&t.setSelectionRange(i,r)):"checkbox"===t.type?e=>(t.value=e?"on":"",U(t,"checked",e)):"select-one"===t.type?e=>{for(let e in t.options)e.removeAttribute("selected");t.value=e,t.selectedOptions[0]?.setAttribute("selected","")}:e=>t.value=e;return t=>n(o(t))},C.on=(t,e)=>{let i=_(t,e,":on");return e=>{let r=i(e);for(let e in r)P(t,e,r[e]);return()=>{for(let e in r)D(t,e,r[e])}}};var $=(t,e,i,r)=>{let o=r.startsWith("on")&&r.slice(2),n=_(t,e,":"+r);if(n)return o?e=>{let i=n(e)||(()=>{});return P(t,o,i),()=>D(t,o,i)}:e=>U(t,r,n(e))},B=Symbol("stop"),P=(t,e,i)=>{let r=e.split("..").map((t=>t.startsWith("on")?t.slice(2):t)),o={target:t,hooks:[],fn:i};r[0]=r[0].replace(/\.(\w+)?-?([\w]+)?/g,((t,e,i)=>(M[e]?.(o,i),"")));let{target:n,hooks:s,fn:l,...u}=o;if(s.length){let t=l;l=e=>{for(let t of s)if(!1===t(e))return!1;return t(e)}}if(1==r.length)n.addEventListener(r[0],l,u);else{const t=(e,i=0)=>{let o=s=>{n.removeEventListener(r[i],o),"function"!=typeof(e=e.call(n,s))&&(e=()=>{}),++i<r.length?t(e,i):l[B]||t(l)};n.addEventListener(r[i],o,u)};t(l)}},D=(t,e,i)=>{e.indexOf("..")>=0&&(i[B]=!0),t.removeEventListener(e,i)},M={prevent({hooks:t}){t.push((t=>{t.preventDefault()}))},stop({hooks:t}){t.push((t=>{t.stopPropagation()}))},throttle(t,i){let{fn:r}=t;i=Number(i)||108;let o,n,s=()=>{o=!0,setTimeout((()=>{if(o=!1,n)return n=!1,s(),r(e)}))};t.fn=t=>o?n=!0:(s(),r(t))},debounce(t,e){let i,{fn:r}=t;e=Number(e)||108,t.fn=t=>{clearTimeout(i),i=setTimeout((()=>{i=null,r(t)}),e)}},window(t){t.target=window},document(t){t.target=document},outside({target:t,hooks:e}){e.push((e=>!t.contains(e.target)&&!1!==e.target.isConnected&&!(t.offsetWidth<1&&t.offsetHeight<1)&&void 0))},self({target:t,hooks:e}){e.push((e=>e.target===t))},once(t){t.once=!0},passive(t){t.passive=!0},capture(t){t.capture=!0},ctrl({hooks:t}){t.push((t=>"Control"===t.key||"Ctrl"===t.key))},shift({hooks:t}){t.push((t=>"Shift"===t.key))},alt({hooks:t}){t.push((t=>"Alt"===t.key))},meta({hooks:t}){t.push((t=>"Meta"===t.key))},arrow({hooks:t}){t.push((t=>t.key.startsWith("Arrow")))},enter({hooks:t}){t.push((t=>"Enter"===t.key))},escape({hooks:t}){t.push((t=>t.key.startsWith("Esc")))},tab({hooks:t}){t.push((t=>"Tab"===t.key))},space({hooks:t}){t.push((t=>"Space"===t.key||" "===t.key))},backspace({hooks:t}){t.push((t=>"Backspace"===t.key))},delete({hooks:t}){t.push((t=>"Delete"===t.key))},digit({hooks:t}){t.push((t=>/\d/.test(t.key)))},letter({hooks:t}){t.push((t=>/[a-zA-Z]/.test(t.key)))},character({hooks:t}){t.push((t=>/^\S$/.test(t.key)))}},U=(t,e,i)=>{null==i||!1===i?t.removeAttribute(e):t.setAttribute(e,!0===i?"":"number"==typeof i||"string"==typeof i?i:"")},L={};function _(t,e,i){let r=L[e];if(!r){let o=/^[\n\s]*if.*\(.*\)/.test(e)||/^(let|const)\s/.test(e)?`(() => { ${e} })()`:e;try{r=L[e]=new Function("__scope",`with (__scope) { return ${o} };`)}catch(r){return R(r,t,e,i)}}return o=>{let n;try{n=r.call(t,o)}catch(r){return R(r,t,e,i)}return n}}function R(t,e,i,r){Object.assign(t,{element:e,expression:i}),console.warn(`∴ ${t.message}\n\n${r}=${i?`"${i}"\n\n`:""}`,e),setTimeout((()=>{throw t}),0)}function z(t){return t.replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,(t=>"-"+t.toLowerCase()))}var F=new WeakMap;function I(t,e){if(!t.children)return;if(F.has(t)){let r=F.get(t);return function(t){if(n>0)return t();n++;try{t()}finally{i()}}((()=>Object.assign(r,e))),r}const r=A(e||{}),o=[],s=(t,e=t.parentNode)=>{for(let i in W){let n=":"+i;if(t.hasAttribute?.(n)){let s=t.getAttribute(n);if(t.removeAttribute(n),o.push(W[i](t,s,r,i)),F.has(t)||t.parentNode!==e)return!1}}if(t.attributes)for(let i=0;i<t.attributes.length;){let n=t.attributes[i];if(":"!==n.name[0]){i++;continue}t.removeAttribute(n.name);let s=n.value,l=n.name.slice(1).split(":");for(let i of l){let n=C[i]||$;if(o.push(n(t,s,r,i)),F.has(t)||t.parentNode!==e)return!1}}for(let e,i=0;e=t.children[i];i++)!1===s(e,t)&&i--};s(t);for(let t of o)if(t){let e;g((()=>{"function"==typeof e&&e(),e=t(r)}))}return Object.seal(r),F.set(t,r),r}var Z=I;export{Z as default};
|
package/src/directives.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// directives & parsing
|
|
2
2
|
import sprae from './core.js'
|
|
3
|
-
import swap from '
|
|
3
|
+
import swap from './domdiff.js'
|
|
4
4
|
import signalStruct from 'signal-struct'
|
|
5
5
|
import p from 'primitive-pool'
|
|
6
6
|
|
|
@@ -266,34 +266,29 @@ const _stop = Symbol('stop')
|
|
|
266
266
|
const addListener = (el, evt, startFn) => {
|
|
267
267
|
// ona..onb
|
|
268
268
|
let evts = evt.split('..').map(e => e.startsWith('on') ? e.slice(2) : e),
|
|
269
|
-
opts = {
|
|
269
|
+
opts = {target: el, hooks: [], fn: startFn}
|
|
270
270
|
|
|
271
271
|
// onevt.debounce-108
|
|
272
|
-
evts[0] = evts[0].replace(
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
}
|
|
278
|
-
);
|
|
279
|
-
// we collect conditions into a sigle callback to check before throttles
|
|
280
|
-
if (conditions.length) {
|
|
281
|
-
let _cb = startFn
|
|
282
|
-
startFn = (e) => { for (let cond of conditions) if (cond(e) === false) return false; _cb(e) }
|
|
272
|
+
evts[0] = evts[0].replace(/\.(\w+)?-?([\w]+)?/g, (match, mod, param) => (mods[mod]?.(opts, param), ''));
|
|
273
|
+
// we collect condition hooks into a sigle callback to check before throttles
|
|
274
|
+
let {target, hooks, fn, ...listenerOpts} = opts
|
|
275
|
+
if (hooks.length) {
|
|
276
|
+
let _fn = fn
|
|
277
|
+
fn = (e) => { for (let hook of hooks) if (hook(e) === false) return false; return _fn(e) }
|
|
283
278
|
}
|
|
284
279
|
|
|
285
|
-
if (evts.length == 1)
|
|
280
|
+
if (evts.length == 1) target.addEventListener(evts[0], fn, listenerOpts);
|
|
286
281
|
else {
|
|
287
|
-
const nextEvt = (
|
|
282
|
+
const nextEvt = (handler, cur=0) => {
|
|
288
283
|
let curListener = e => {
|
|
289
|
-
|
|
290
|
-
if (typeof (
|
|
291
|
-
if (++cur < evts.length) nextEvt(
|
|
292
|
-
else if (!
|
|
284
|
+
target.removeEventListener(evts[cur], curListener)
|
|
285
|
+
if (typeof (handler = handler.call(target,e)) !== 'function') handler = ()=>{}
|
|
286
|
+
if (++cur < evts.length) nextEvt(handler, cur);
|
|
287
|
+
else if (!fn[_stop]) nextEvt(fn); // update only if chain isn't stopped
|
|
293
288
|
}
|
|
294
|
-
|
|
289
|
+
target.addEventListener(evts[cur], curListener, listenerOpts)
|
|
295
290
|
}
|
|
296
|
-
nextEvt(
|
|
291
|
+
nextEvt(fn)
|
|
297
292
|
}
|
|
298
293
|
}
|
|
299
294
|
const removeListener = (el, evt, fn) => {
|
|
@@ -303,70 +298,68 @@ const removeListener = (el, evt, fn) => {
|
|
|
303
298
|
|
|
304
299
|
// event modifiers
|
|
305
300
|
const mods = {
|
|
306
|
-
|
|
301
|
+
prevent({hooks}) { hooks.push(e => { e.preventDefault(); })},
|
|
302
|
+
stop({hooks}) { hooks.push(e => { e.stopPropagation(); })},
|
|
303
|
+
throttle(opts, limit) {
|
|
304
|
+
let {fn} = opts
|
|
307
305
|
limit = Number(limit) || 108
|
|
308
306
|
let pause, planned, block = () => {
|
|
309
307
|
pause = true
|
|
310
308
|
setTimeout(() => {
|
|
311
309
|
pause = false
|
|
312
310
|
// if event happened during blocked time, it schedules call by the end
|
|
313
|
-
if (planned)
|
|
311
|
+
if (planned) return (planned = false, block(), fn(e))
|
|
314
312
|
})
|
|
315
313
|
}
|
|
316
|
-
|
|
314
|
+
opts.fn = e => {
|
|
317
315
|
if (pause) return (planned = true)
|
|
318
|
-
|
|
319
|
-
|
|
316
|
+
block();
|
|
317
|
+
return fn(e);
|
|
318
|
+
}
|
|
320
319
|
},
|
|
321
|
-
|
|
322
|
-
|
|
320
|
+
debounce(opts, wait) {
|
|
321
|
+
let {fn} = opts
|
|
323
322
|
wait = Number(wait) || 108;
|
|
324
|
-
let timeout
|
|
325
|
-
|
|
323
|
+
let timeout
|
|
324
|
+
opts.fn = (e) => {
|
|
326
325
|
clearTimeout(timeout)
|
|
327
|
-
timeout = setTimeout(
|
|
328
|
-
}
|
|
326
|
+
timeout = setTimeout(() => {timeout = null; fn(e)}, wait)
|
|
327
|
+
}
|
|
329
328
|
},
|
|
330
329
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
330
|
+
// target
|
|
331
|
+
window(opts) { opts.target = window },
|
|
332
|
+
document(opts) { opts.target = document },
|
|
333
|
+
outside({target, hooks}) {
|
|
334
|
+
hooks.push((e) => {
|
|
335
|
+
if (target.contains(e.target)) return false
|
|
336
336
|
if (e.target.isConnected === false) return false
|
|
337
|
-
if (
|
|
338
|
-
}
|
|
337
|
+
if (target.offsetWidth < 1 && target.offsetHeight < 1) return false
|
|
338
|
+
})
|
|
339
339
|
},
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
once(
|
|
344
|
-
passive(
|
|
345
|
-
capture(
|
|
340
|
+
self({target, hooks}) { hooks.push(e => { return e.target === target })},
|
|
341
|
+
|
|
342
|
+
// options
|
|
343
|
+
once(opts) { opts.once = true; },
|
|
344
|
+
passive(opts) { opts.passive = true; },
|
|
345
|
+
capture(opts) { opts.capture = true; },
|
|
346
|
+
|
|
347
|
+
// keyboard
|
|
348
|
+
ctrl({hooks}) { hooks.push(e => e.key === 'Control' || e.key === 'Ctrl')},
|
|
349
|
+
shift({hooks}) { hooks.push(e => e.key === 'Shift')},
|
|
350
|
+
alt({hooks}) { hooks.push(e => e.key === 'Alt')},
|
|
351
|
+
meta({hooks}) { hooks.push(e => e.key === 'Meta')},
|
|
352
|
+
arrow({hooks}) { hooks.push(e => e.key.startsWith('Arrow'))},
|
|
353
|
+
enter({hooks}) { hooks.push(e => e.key === 'Enter')},
|
|
354
|
+
escape({hooks}) { hooks.push(e => e.key.startsWith('Esc'))},
|
|
355
|
+
tab({hooks}) { hooks.push(e => e.key === 'Tab')},
|
|
356
|
+
space({hooks}) { hooks.push(e => e.key === 'Space' || e.key === ' ')},
|
|
357
|
+
backspace({hooks}) { hooks.push(e => e.key === 'Backspace') },
|
|
358
|
+
delete({hooks}) { hooks.push(e => e.key === 'Delete') },
|
|
359
|
+
digit({hooks}) { hooks.push(e => /\d/.test(e.key)) },
|
|
360
|
+
letter({hooks}) { hooks.push(e => /[a-zA-Z]/.test(e.key)) },
|
|
361
|
+
character({hooks}) { hooks.push(e => /^\S$/.test(e.key) ) },
|
|
346
362
|
};
|
|
347
|
-
let keys = {
|
|
348
|
-
ctrl:'Control Ctrl',
|
|
349
|
-
shift:'Shift',
|
|
350
|
-
alt:'Alt',
|
|
351
|
-
meta:'Meta',cmd:'Meta',
|
|
352
|
-
down:'ArrowDown',up:'ArrowUp',left:'ArrowLeft',right:'ArrowRight',
|
|
353
|
-
end:'End',home:'Home',pagedown:'PageDown',pageup:'PageUp',
|
|
354
|
-
enter:'Enter',
|
|
355
|
-
esc:'Escape',escape:'Escape',tab:'Tab',
|
|
356
|
-
backspace:'Backspace', delete:'Delete',
|
|
357
|
-
space:/ /,
|
|
358
|
-
plus:/\+/,minus:/\-/,star:/\*/,slash:/\//,period:/\./,equal:/\=/,underscore:/\_/,
|
|
359
|
-
alnum: /\w/,
|
|
360
|
-
letter: /[a-zA-Z]/,
|
|
361
|
-
digit: /\d/
|
|
362
|
-
}
|
|
363
|
-
keys.arrow = keys.down + keys.up + keys.left + keys.right
|
|
364
|
-
for (let keyAttr in keys) {
|
|
365
|
-
let keyName = keys[keyAttr]
|
|
366
|
-
mods[keyAttr] = (el, cb, opts, extraKey) => [el, cb, e => {
|
|
367
|
-
if (!e.key || (e.key.length > 2 ? !keyName.includes?.(e.key) : !keyName.test?.(e.key))) return false
|
|
368
|
-
}]
|
|
369
|
-
}
|
|
370
363
|
|
|
371
364
|
// set attr
|
|
372
365
|
const attr = (el, name, v) => {
|
package/src/domdiff.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// https://github.com/luwes/js-diff-benchmark/blob/master/libs/list-difference.js
|
|
2
|
+
// this implementation is more persistent in terms of preserving in-between nodes
|
|
3
|
+
|
|
4
|
+
// a is old list, b is the new
|
|
5
|
+
export default function(parent, a, b, before) {
|
|
6
|
+
const aIdx = new Map();
|
|
7
|
+
const bIdx = new Map();
|
|
8
|
+
let i;
|
|
9
|
+
let j;
|
|
10
|
+
|
|
11
|
+
// Create a mapping from keys to their position in the old list
|
|
12
|
+
for (i = 0; i < a.length; i++) {
|
|
13
|
+
aIdx.set(a[i], i);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Create a mapping from keys to their position in the new list
|
|
17
|
+
for (i = 0; i < b.length; i++) {
|
|
18
|
+
bIdx.set(b[i], i);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
for (i = j = 0; i !== a.length || j !== b.length;) {
|
|
22
|
+
var aElm = a[i], bElm = b[j];
|
|
23
|
+
if (aElm === null) {
|
|
24
|
+
// This is a element that has been moved to earlier in the list
|
|
25
|
+
i++;
|
|
26
|
+
} else if (b.length <= j) {
|
|
27
|
+
// No more elements in new, this is a delete
|
|
28
|
+
parent.removeChild(a[i]);
|
|
29
|
+
i++;
|
|
30
|
+
} else if (a.length <= i) {
|
|
31
|
+
// No more elements in old, this is an addition
|
|
32
|
+
parent.insertBefore(bElm, a[i] || before);
|
|
33
|
+
j++;
|
|
34
|
+
} else if (aElm === bElm) {
|
|
35
|
+
// No difference, we move on
|
|
36
|
+
i++; j++;
|
|
37
|
+
} else {
|
|
38
|
+
// Look for the current element at this location in the new list
|
|
39
|
+
// This gives us the idx of where this element should be
|
|
40
|
+
var curElmInNew = bIdx.get(aElm);
|
|
41
|
+
// Look for the the wanted elment at this location in the old list
|
|
42
|
+
// This gives us the idx of where the wanted element is now
|
|
43
|
+
var wantedElmInOld = aIdx.get(bElm);
|
|
44
|
+
if (curElmInNew === undefined) {
|
|
45
|
+
// Current element is not in new list, it has been removed
|
|
46
|
+
parent.removeChild(a[i]);
|
|
47
|
+
i++;
|
|
48
|
+
} else if (wantedElmInOld === undefined) {
|
|
49
|
+
// New element is not in old list, it has been added
|
|
50
|
+
parent.insertBefore(
|
|
51
|
+
bElm,
|
|
52
|
+
a[i] || before
|
|
53
|
+
);
|
|
54
|
+
j++;
|
|
55
|
+
} else {
|
|
56
|
+
// Element is in both lists, it has been moved
|
|
57
|
+
parent.insertBefore(
|
|
58
|
+
a[wantedElmInOld],
|
|
59
|
+
a[i] || before
|
|
60
|
+
);
|
|
61
|
+
a[wantedElmInOld] = null;
|
|
62
|
+
if (wantedElmInOld > i + 1) i++;
|
|
63
|
+
j++;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return b;
|
|
68
|
+
};
|
package/test/index.html
CHANGED
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
"signal-struct" : "../node_modules/signal-struct/signal-struct.js",
|
|
16
16
|
"element-props" : "../node_modules/element-props/element-props.js",
|
|
17
17
|
"swapdom" : "../node_modules/swapdom/swap-inflate.js",
|
|
18
|
+
"swapdom/swap-deflate" : "../node_modules/swapdom/swap-deflate.js",
|
|
19
|
+
"swapdom/swap-inflate" : "../node_modules/swapdom/swap-inflate.js",
|
|
18
20
|
"primitive-pool" : "../node_modules/primitive-pool/index.js",
|
|
19
21
|
"preact": "../node_modules/preact/dist/preact.mjs",
|
|
20
22
|
"preact/hooks": "../node_modules/preact/hooks/dist/hooks.mjs",
|
package/test/test.js
CHANGED
|
@@ -443,6 +443,19 @@ test('each: :id and others must receive value from context', () => {
|
|
|
443
443
|
is(el.innerHTML,`<x id="1"></x><x id="2"></x><x id="3"></x>`)
|
|
444
444
|
})
|
|
445
445
|
|
|
446
|
+
test('each: key-based caching is in-sync with direct elements', () => {
|
|
447
|
+
let el = h`<ul><li :each="i in x" :key="i" :id="i"></li></ul>`
|
|
448
|
+
let el2 = h`<ul><li :each="i in x" :id="i"></li></ul>`
|
|
449
|
+
let state = sprae(el, {x:2})
|
|
450
|
+
let state2 = sprae(el2, {x:2})
|
|
451
|
+
is(el.outerHTML, el2.outerHTML)
|
|
452
|
+
el.firstChild.after(el.firstChild.cloneNode(true))
|
|
453
|
+
el2.firstChild.after(el2.firstChild.cloneNode(true))
|
|
454
|
+
state.x = 3
|
|
455
|
+
state2.x = 3
|
|
456
|
+
is(el.outerHTML, el2.outerHTML)
|
|
457
|
+
})
|
|
458
|
+
|
|
446
459
|
test('on: base', () => {
|
|
447
460
|
let el = h`<div :on="{click(e){log.push('click')},x}"></div>`
|
|
448
461
|
let log = signal([])
|
|
@@ -632,6 +645,15 @@ test('on: keys with prevent', e => {
|
|
|
632
645
|
is(state.log,['x'])
|
|
633
646
|
})
|
|
634
647
|
|
|
648
|
+
test('on: debounce', async e => {
|
|
649
|
+
let el = h`<x :onkeydown.debounce-1="e=>log.push(e.key)"></x>`
|
|
650
|
+
let state = sprae(el, {log:[]})
|
|
651
|
+
el.dispatchEvent(new window.KeyboardEvent('keydown', { key: 'x', bubbles: true }));
|
|
652
|
+
is(state.log, [])
|
|
653
|
+
await time(2)
|
|
654
|
+
is(state.log, ['x'])
|
|
655
|
+
})
|
|
656
|
+
|
|
635
657
|
test('with: inline', () => {
|
|
636
658
|
let el = h`<x :with="{foo:'bar'}"><y :text="foo + baz"></y></x>`
|
|
637
659
|
let state = sprae(el, {baz: 'qux'})
|