sprae 2.10.1 → 2.10.2
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/r&d.md +22 -18
- package/sprae.js +57 -57
- package/sprae.min.js +1 -1
- package/src/directives.js +4 -4
- package/test/test.js +32 -3
package/package.json
CHANGED
package/r&d.md
CHANGED
|
@@ -424,9 +424,26 @@
|
|
|
424
424
|
+ allow multiple setters for same props or multiple listeners for same events
|
|
425
425
|
+ oldschool jquery-compatible events
|
|
426
426
|
|
|
427
|
+
* [x] Event modifiers
|
|
428
|
+
* [x] onevt.x, onevt.y
|
|
429
|
+
+ jquery-like
|
|
430
|
+
+ multiple same events
|
|
431
|
+
* [x] onevt.once, onevt.passive, onevt.capture
|
|
432
|
+
+ standard props passing
|
|
433
|
+
* [x] onevt.prevent, onevt.stop
|
|
434
|
+
+ conventional mods
|
|
435
|
+
* [x] onevt.outside onevt.window, onevt.document, onevt.self
|
|
436
|
+
+ useful handlers, conventional mods
|
|
437
|
+
* [x] onevt.throttle-xxx, onevt.debounce-xxx
|
|
438
|
+
+ conventional
|
|
439
|
+
* [x] onevt.shift, onevt.cmd.shift, onevt.meta
|
|
440
|
+
+ conventional
|
|
441
|
+
* [x] onkey.enter, .space, .up|.down|.left|.right, .escape, .tab, .period, .slash, .caps-lock
|
|
442
|
+
+ conventional
|
|
443
|
+
|
|
427
444
|
## [x] Mods design -> use event modifiers, not props modifiers
|
|
428
445
|
|
|
429
|
-
* [ ]
|
|
446
|
+
* [ ] Prop modifiers
|
|
430
447
|
- overall seems code complication without much benefit
|
|
431
448
|
* [ ] value.bind? value.watch?
|
|
432
449
|
- let's wait for use-case: value can be too big to set it every time
|
|
@@ -443,23 +460,10 @@
|
|
|
443
460
|
- let's wait until that's really a problem
|
|
444
461
|
* [ ] prop.class
|
|
445
462
|
? what's the use-case
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
* [
|
|
449
|
-
|
|
450
|
-
+ multiple same events
|
|
451
|
-
* [x] onevt.once, onevt.passive, onevt.capture
|
|
452
|
-
+ standard props passing
|
|
453
|
-
* [x] onevt.prevent, onevt.stop
|
|
454
|
-
+ conventional mods
|
|
455
|
-
* [x] onevt.outside onevt.window, onevt.document, onevt.self
|
|
456
|
-
+ useful handlers, conventional mods
|
|
457
|
-
* [x] onevt.throttle-xxx, onevt.debounce-xxx
|
|
458
|
-
+ conventional
|
|
459
|
-
* [x] onevt.shift, onevt.cmd.shift, onevt.meta
|
|
460
|
-
+ conventional
|
|
461
|
-
* [x] onkey.enter, .space, .up|.down|.left|.right, .escape, .tab, .period, .slash, .caps-lock
|
|
462
|
-
+ conventional
|
|
463
|
+
* [ ] prop.next="" - run update after other DOM updates happen
|
|
464
|
+
* [ ] prop.fx="" - run effect without changing property
|
|
465
|
+
* [ ] x.prop="xyz" - set element property, rather than attribute (following topic)
|
|
466
|
+
* [ ] x.raf="abc" - run regularly?
|
|
463
467
|
|
|
464
468
|
## [x] Writing props on elements (like ones in :each) -> nah, just use `:x="this.x=abc"`
|
|
465
469
|
|
package/sprae.js
CHANGED
|
@@ -71,16 +71,16 @@ function v(i2) {
|
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
|
-
function
|
|
74
|
+
function e(i2) {
|
|
75
75
|
this.v = i2;
|
|
76
76
|
this.i = 0;
|
|
77
77
|
this.n = void 0;
|
|
78
78
|
this.t = void 0;
|
|
79
79
|
}
|
|
80
|
-
|
|
80
|
+
e.prototype.h = function() {
|
|
81
81
|
return true;
|
|
82
82
|
};
|
|
83
|
-
|
|
83
|
+
e.prototype.S = function(i2) {
|
|
84
84
|
if (this.t !== i2 && void 0 === i2.e) {
|
|
85
85
|
i2.x = this.t;
|
|
86
86
|
if (void 0 !== this.t)
|
|
@@ -88,7 +88,7 @@ e2.prototype.S = function(i2) {
|
|
|
88
88
|
this.t = i2;
|
|
89
89
|
}
|
|
90
90
|
};
|
|
91
|
-
|
|
91
|
+
e.prototype.U = function(i2) {
|
|
92
92
|
var t2 = i2.e, h2 = i2.x;
|
|
93
93
|
if (void 0 !== t2) {
|
|
94
94
|
t2.x = h2;
|
|
@@ -101,7 +101,7 @@ e2.prototype.U = function(i2) {
|
|
|
101
101
|
if (i2 === this.t)
|
|
102
102
|
this.t = h2;
|
|
103
103
|
};
|
|
104
|
-
|
|
104
|
+
e.prototype.subscribe = function(i2) {
|
|
105
105
|
var t2 = this;
|
|
106
106
|
return b(function() {
|
|
107
107
|
var h2 = t2.value, o2 = 32 & this.f;
|
|
@@ -113,16 +113,16 @@ e2.prototype.subscribe = function(i2) {
|
|
|
113
113
|
}
|
|
114
114
|
});
|
|
115
115
|
};
|
|
116
|
-
|
|
116
|
+
e.prototype.valueOf = function() {
|
|
117
117
|
return this.value;
|
|
118
118
|
};
|
|
119
|
-
|
|
119
|
+
e.prototype.toString = function() {
|
|
120
120
|
return this.value + "";
|
|
121
121
|
};
|
|
122
|
-
|
|
122
|
+
e.prototype.peek = function() {
|
|
123
123
|
return this.v;
|
|
124
124
|
};
|
|
125
|
-
Object.defineProperty(
|
|
125
|
+
Object.defineProperty(e.prototype, "value", { get: function() {
|
|
126
126
|
var i2 = v(this);
|
|
127
127
|
if (void 0 !== i2)
|
|
128
128
|
i2.i = this.i;
|
|
@@ -144,7 +144,7 @@ Object.defineProperty(e2.prototype, "value", { get: function() {
|
|
|
144
144
|
}
|
|
145
145
|
} });
|
|
146
146
|
function u(i2) {
|
|
147
|
-
return new
|
|
147
|
+
return new e(i2);
|
|
148
148
|
}
|
|
149
149
|
function d(i2) {
|
|
150
150
|
for (var t2 = i2.s; void 0 !== t2; t2 = t2.n)
|
|
@@ -183,13 +183,13 @@ function a(i2) {
|
|
|
183
183
|
i2.s = h2;
|
|
184
184
|
}
|
|
185
185
|
function l(i2) {
|
|
186
|
-
|
|
186
|
+
e.call(this, void 0);
|
|
187
187
|
this.x = i2;
|
|
188
188
|
this.s = void 0;
|
|
189
189
|
this.g = f - 1;
|
|
190
190
|
this.f = 4;
|
|
191
191
|
}
|
|
192
|
-
(l.prototype = new
|
|
192
|
+
(l.prototype = new e()).h = function() {
|
|
193
193
|
this.f &= -3;
|
|
194
194
|
if (1 & this.f)
|
|
195
195
|
return false;
|
|
@@ -230,10 +230,10 @@ l.prototype.S = function(i2) {
|
|
|
230
230
|
for (var t2 = this.s; void 0 !== t2; t2 = t2.n)
|
|
231
231
|
t2.S.S(t2);
|
|
232
232
|
}
|
|
233
|
-
|
|
233
|
+
e.prototype.S.call(this, i2);
|
|
234
234
|
};
|
|
235
235
|
l.prototype.U = function(i2) {
|
|
236
|
-
|
|
236
|
+
e.prototype.U.call(this, i2);
|
|
237
237
|
if (void 0 === this.t) {
|
|
238
238
|
this.f &= -33;
|
|
239
239
|
for (var t2 = this.s; void 0 !== t2; t2 = t2.n)
|
|
@@ -408,7 +408,7 @@ function signalStruct(values, proto) {
|
|
|
408
408
|
try {
|
|
409
409
|
Object.assign(s2.value, v2);
|
|
410
410
|
return;
|
|
411
|
-
} catch (
|
|
411
|
+
} catch (e2) {
|
|
412
412
|
}
|
|
413
413
|
s2.value = Object.seal(signalStruct(v2));
|
|
414
414
|
} else if (Array.isArray(v2))
|
|
@@ -708,25 +708,25 @@ var directives_default = (el, expr, state, name) => {
|
|
|
708
708
|
};
|
|
709
709
|
var _stop = Symbol("stop");
|
|
710
710
|
var addListener = (el, evt, startFn) => {
|
|
711
|
-
let evts = evt.split("..").map((
|
|
711
|
+
let evts = evt.split("..").map((e2) => e2.startsWith("on") ? e2.slice(2) : e2), opts = { target: el, hooks: [], fn: startFn };
|
|
712
712
|
evts[0] = evts[0].replace(/\.(\w+)?-?([\w]+)?/g, (match, mod, param) => (mods[mod]?.(opts, param), ""));
|
|
713
713
|
let { target, hooks, fn, ...listenerOpts } = opts;
|
|
714
714
|
if (hooks.length) {
|
|
715
715
|
let _fn = fn;
|
|
716
|
-
fn = (
|
|
716
|
+
fn = (e2) => {
|
|
717
717
|
for (let hook of hooks)
|
|
718
|
-
if (hook(
|
|
718
|
+
if (hook(e2) === false)
|
|
719
719
|
return false;
|
|
720
|
-
return _fn(
|
|
720
|
+
return _fn(e2);
|
|
721
721
|
};
|
|
722
722
|
}
|
|
723
723
|
if (evts.length == 1)
|
|
724
724
|
target.addEventListener(evts[0], fn, listenerOpts);
|
|
725
725
|
else {
|
|
726
726
|
const nextEvt = (handler, cur = 0) => {
|
|
727
|
-
let curListener = (
|
|
727
|
+
let curListener = (e2) => {
|
|
728
728
|
target.removeEventListener(evts[cur], curListener);
|
|
729
|
-
if (typeof (handler = handler.call(target,
|
|
729
|
+
if (typeof (handler = handler.call(target, e2)) !== "function")
|
|
730
730
|
handler = () => {
|
|
731
731
|
};
|
|
732
732
|
if (++cur < evts.length)
|
|
@@ -746,42 +746,42 @@ var removeListener = (el, evt, fn) => {
|
|
|
746
746
|
};
|
|
747
747
|
var mods = {
|
|
748
748
|
prevent({ hooks }) {
|
|
749
|
-
hooks.push((
|
|
750
|
-
|
|
749
|
+
hooks.push((e2) => {
|
|
750
|
+
e2.preventDefault();
|
|
751
751
|
});
|
|
752
752
|
},
|
|
753
753
|
stop({ hooks }) {
|
|
754
|
-
hooks.push((
|
|
755
|
-
|
|
754
|
+
hooks.push((e2) => {
|
|
755
|
+
e2.stopPropagation();
|
|
756
756
|
});
|
|
757
757
|
},
|
|
758
758
|
throttle(opts, limit) {
|
|
759
759
|
let { fn } = opts;
|
|
760
760
|
limit = Number(limit) || 108;
|
|
761
|
-
let pause, planned, block = () => {
|
|
761
|
+
let pause, planned, block = (e2) => {
|
|
762
762
|
pause = true;
|
|
763
763
|
setTimeout(() => {
|
|
764
764
|
pause = false;
|
|
765
765
|
if (planned)
|
|
766
|
-
return planned = false, block(), fn(
|
|
767
|
-
});
|
|
766
|
+
return planned = false, block(), fn(e2);
|
|
767
|
+
}, limit);
|
|
768
768
|
};
|
|
769
|
-
opts.fn = (
|
|
769
|
+
opts.fn = (e2) => {
|
|
770
770
|
if (pause)
|
|
771
771
|
return planned = true;
|
|
772
|
-
block();
|
|
773
|
-
return fn(
|
|
772
|
+
block(e2);
|
|
773
|
+
return fn(e2);
|
|
774
774
|
};
|
|
775
775
|
},
|
|
776
776
|
debounce(opts, wait) {
|
|
777
777
|
let { fn } = opts;
|
|
778
778
|
wait = Number(wait) || 108;
|
|
779
779
|
let timeout;
|
|
780
|
-
opts.fn = (
|
|
780
|
+
opts.fn = (e2) => {
|
|
781
781
|
clearTimeout(timeout);
|
|
782
782
|
timeout = setTimeout(() => {
|
|
783
783
|
timeout = null;
|
|
784
|
-
fn(
|
|
784
|
+
fn(e2);
|
|
785
785
|
}, wait);
|
|
786
786
|
};
|
|
787
787
|
},
|
|
@@ -792,18 +792,18 @@ var mods = {
|
|
|
792
792
|
opts.target = document;
|
|
793
793
|
},
|
|
794
794
|
outside({ target, hooks }) {
|
|
795
|
-
hooks.push((
|
|
796
|
-
if (target.contains(
|
|
795
|
+
hooks.push((e2) => {
|
|
796
|
+
if (target.contains(e2.target))
|
|
797
797
|
return false;
|
|
798
|
-
if (
|
|
798
|
+
if (e2.target.isConnected === false)
|
|
799
799
|
return false;
|
|
800
800
|
if (target.offsetWidth < 1 && target.offsetHeight < 1)
|
|
801
801
|
return false;
|
|
802
802
|
});
|
|
803
803
|
},
|
|
804
804
|
self({ target, hooks }) {
|
|
805
|
-
hooks.push((
|
|
806
|
-
return
|
|
805
|
+
hooks.push((e2) => {
|
|
806
|
+
return e2.target === target;
|
|
807
807
|
});
|
|
808
808
|
},
|
|
809
809
|
once(opts) {
|
|
@@ -816,46 +816,46 @@ var mods = {
|
|
|
816
816
|
opts.capture = true;
|
|
817
817
|
},
|
|
818
818
|
ctrl({ hooks }) {
|
|
819
|
-
hooks.push((
|
|
819
|
+
hooks.push((e2) => e2.key === "Control" || e2.key === "Ctrl");
|
|
820
820
|
},
|
|
821
821
|
shift({ hooks }) {
|
|
822
|
-
hooks.push((
|
|
822
|
+
hooks.push((e2) => e2.key === "Shift");
|
|
823
823
|
},
|
|
824
824
|
alt({ hooks }) {
|
|
825
|
-
hooks.push((
|
|
825
|
+
hooks.push((e2) => e2.key === "Alt");
|
|
826
826
|
},
|
|
827
827
|
meta({ hooks }) {
|
|
828
|
-
hooks.push((
|
|
828
|
+
hooks.push((e2) => e2.key === "Meta");
|
|
829
829
|
},
|
|
830
830
|
arrow({ hooks }) {
|
|
831
|
-
hooks.push((
|
|
831
|
+
hooks.push((e2) => e2.key.startsWith("Arrow"));
|
|
832
832
|
},
|
|
833
833
|
enter({ hooks }) {
|
|
834
|
-
hooks.push((
|
|
834
|
+
hooks.push((e2) => e2.key === "Enter");
|
|
835
835
|
},
|
|
836
836
|
escape({ hooks }) {
|
|
837
|
-
hooks.push((
|
|
837
|
+
hooks.push((e2) => e2.key.startsWith("Esc"));
|
|
838
838
|
},
|
|
839
839
|
tab({ hooks }) {
|
|
840
|
-
hooks.push((
|
|
840
|
+
hooks.push((e2) => e2.key === "Tab");
|
|
841
841
|
},
|
|
842
842
|
space({ hooks }) {
|
|
843
|
-
hooks.push((
|
|
843
|
+
hooks.push((e2) => e2.key === "Space" || e2.key === " ");
|
|
844
844
|
},
|
|
845
845
|
backspace({ hooks }) {
|
|
846
|
-
hooks.push((
|
|
846
|
+
hooks.push((e2) => e2.key === "Backspace");
|
|
847
847
|
},
|
|
848
848
|
delete({ hooks }) {
|
|
849
|
-
hooks.push((
|
|
849
|
+
hooks.push((e2) => e2.key === "Delete");
|
|
850
850
|
},
|
|
851
851
|
digit({ hooks }) {
|
|
852
|
-
hooks.push((
|
|
852
|
+
hooks.push((e2) => /\d/.test(e2.key));
|
|
853
853
|
},
|
|
854
854
|
letter({ hooks }) {
|
|
855
|
-
hooks.push((
|
|
855
|
+
hooks.push((e2) => /[a-zA-Z]/.test(e2.key));
|
|
856
856
|
},
|
|
857
857
|
character({ hooks }) {
|
|
858
|
-
hooks.push((
|
|
858
|
+
hooks.push((e2) => /^\S$/.test(e2.key));
|
|
859
859
|
}
|
|
860
860
|
};
|
|
861
861
|
var attr = (el, name, v2) => {
|
|
@@ -868,19 +868,19 @@ var evaluatorMemo = {};
|
|
|
868
868
|
function parseExpr(el, expression, dir) {
|
|
869
869
|
let evaluate = evaluatorMemo[expression];
|
|
870
870
|
if (!evaluate) {
|
|
871
|
-
let rightSideSafeExpression = /^[\n\s]*if.*\(.*\)/.test(expression) ||
|
|
871
|
+
let rightSideSafeExpression = /^[\n\s]*if.*\(.*\)/.test(expression) || /\b(let|const)\s/.test(expression) ? `(() => { ${expression} })()` : expression;
|
|
872
872
|
try {
|
|
873
873
|
evaluate = evaluatorMemo[expression] = new Function(`__scope`, `with (__scope) { return ${rightSideSafeExpression} };`);
|
|
874
|
-
} catch (
|
|
875
|
-
return exprError(
|
|
874
|
+
} catch (e2) {
|
|
875
|
+
return exprError(e2, el, expression, dir);
|
|
876
876
|
}
|
|
877
877
|
}
|
|
878
878
|
return (state) => {
|
|
879
879
|
let result;
|
|
880
880
|
try {
|
|
881
881
|
result = evaluate.call(el, state);
|
|
882
|
-
} catch (
|
|
883
|
-
return exprError(
|
|
882
|
+
} catch (e2) {
|
|
883
|
+
return exprError(e2, el, expression, dir);
|
|
884
884
|
}
|
|
885
885
|
return result;
|
|
886
886
|
};
|
package/sprae.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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};
|
|
1
|
+
function t(){throw new Error("Cycle detected")}function e(){if(o>1)o--;else{for(var t,e=!1;void 0!==r;){var i=r;for(r=void 0,n++;void 0!==i;){var s=i.o;if(i.o=void 0,i.f&=-3,!(8&i.f)&&a(i))try{i.c()}catch(i){e||(t=i,e=!0)}i=s}}if(n=0,o--,e)throw t}}var i=void 0,r=void 0,o=0,n=0,s=0;function l(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 a(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 f(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 h(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 c(t){u.call(this,void 0),this.x=t,this.s=void 0,this.g=s-1,this.f=4}function v(t){var r=t.u;if(t.u=void 0,"function"==typeof r){o++;var n=i;i=void 0;try{r()}catch(e){throw t.f&=-2,t.f|=8,p(t),e}finally{i=n,e()}}}function p(t){for(var e=t.s;void 0!==e;e=e.n)e.S.U(e);t.x=void 0,t.s=void 0,v(t)}function d(t){if(i!==this)throw new Error("Out-of-order effect");h(this),i=t,this.f&=-2,8&this.f&&p(this),e()}function y(t){this.x=t,this.u=void 0,this.s=void 0,this.o=void 0,this.f=32}function b(t){var e=new y(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,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)},u.prototype.subscribe=function(t){var e=this;return b((function(){var i=e.value,r=32&this.f;this.f&=-33;try{t(i)}finally{this.f|=r}}))},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=l(this);return void 0!==t&&(t.i=this.i),this.v},set:function(i){if(i!==this.v){n>100&&t(),this.v=i,this.i++,s++,o++;try{for(var r=this.t;void 0!==r;r=r.x)r.t.N()}finally{e()}}}}),(c.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===s)return!0;if(this.g=s,this.f|=1,this.i>0&&!a(this))return this.f&=-2,!0;var t=i;try{f(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},c.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)},c.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)}},c.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var t=this.t;void 0!==t;t=t.x)t.t.N()}},c.prototype.peek=function(){if(this.h()||t(),16&this.f)throw this.v;return this.v},Object.defineProperty(c.prototype,"value",{get:function(){1&this.f&&t();var e=l(this);if(this.h(),void 0!==e&&(e.i=this.i),16&this.f)throw this.v;return this.v}}),y.prototype.c=function(){var t=this.S();try{8&this.f||void 0===this.x||(this.u=this.x())}finally{t()}},y.prototype.S=function(){1&this.f&&t(),this.f|=1,this.f&=-9,v(this),f(this),o++;var e=i;return i=this,d.bind(this,e)},y.prototype.N=function(){2&this.f||(this.f|=2,this.o=r,r=this)},y.prototype.d=function(){this.f|=8,1&this.f||p(this)},Symbol.observable||=Symbol("observable");var g=new FinalizationRegistry((t=>t.call?.())),m=(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),g.register(t,n),n);var s},k=t=>t&&t[w],w=Symbol("signal-struct");function S(t,e){if(k(t)&&!e)return t;if(A(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 c(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),a=n[t]=(i=s)&&i.peek?s:new u(l?void 0:A(s)?Object.seal(S(s)):Array.isArray(s)?S(s):s);l&&m(s,(t=>a.value=t)),Object.defineProperty(o,t,{get:()=>a.value,set(t){if(A(t)){if(A(a.value))try{return void Object.assign(a.value,t)}catch(t){}a.value=Object.seal(S(t))}else Array.isArray(t)?a.value=S(t):a.value=t},enumerable:!0,configurable:!1})}}return Object.defineProperty(o,w,{configurable:!1,enumerable:!1,value:!0}),o}var i,r;if(Array.isArray(t)&&!k(t[0]))for(let e=0;e<t.length;e++)t[e]=S(t[e]);return t}function A(t){return t&&t.constructor===Object}S.isStruct=k;var x={},O={},j={},N=t=>null===t?O:void 0===t?j:"number"==typeof t||t instanceof Number?x[t]||(x[t]=new Number(t)):"string"==typeof t||t instanceof String?x[t]||(x[t]=new String(t)):"boolean"==typeof t||t instanceof Boolean?x[t]||(x[t]=new Boolean(t)):t,E={},W={};E.if=(t,e)=>{let i=document.createTextNode(""),r=[L(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(L(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[C]||n).replaceWith(n=o[e]||i),F(n,t))}},E.with=(t,e,i)=>{F(t,S(L(t,e,"with")(i),i))};var C=Symbol(":each");E.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 _(new Error,t,e);const r=t[C]=document.createTextNode("");t.replaceWith(r);const o=L(t,i[2],":each"),n=t.getAttribute(":key"),s=n?L(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):_(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=N(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=S({[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++)F(h[t],c[t])}},W.ref=(t,e,i)=>{i[e]=t},W.id=(t,e)=>{let i=L(t,e,":id");return e=>{return r=i(e),t.id=r||0===r?r:"";var r}},W.class=(t,e)=>{let i=L(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(" ")}},W.style=(t,e)=>{let i=L(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]}},W.text=(t,e)=>{let i=L(t,e,":text");return e=>{let r=i(e);t.textContent=null==r?"":r}},W.data=(t,e)=>{let i=L(t,e,":data");return e=>{let r=i(e);for(let e in r)t.dataset[e]=r[e]}},W.aria=(t,e)=>{let i=L(t,e,":aria");return e=>(e=>{for(let i in e)M(t,"aria-"+R(i),null==e[i]?null:e[i]+"")})(i(e))},W[""]=(t,e)=>{let i=L(t,e,":");if(i)return e=>{let r=i(e);for(let e in r)M(t,R(e),r[e])}},W.value=(t,e)=>{let i,r,o=L(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":"",M(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))},W.on=(t,e)=>{let i=L(t,e,":on");return e=>{let r=i(e);for(let e in r)B(t,e,r[e]);return()=>{for(let e in r)P(t,e,r[e])}}};var T=(t,e,i,r)=>{let o=r.startsWith("on")&&r.slice(2),n=L(t,e,":"+r);if(n)return o?e=>{let i=n(e)||(()=>{});return B(t,o,i),()=>P(t,o,i)}:e=>M(t,r,n(e))},$=Symbol("stop"),B=(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)=>(D[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[$]||t(l)};n.addEventListener(r[i],o,u)};t(l)}},P=(t,e,i)=>{e.indexOf("..")>=0&&(i[$]=!0),t.removeEventListener(e,i)},D={prevent({hooks:t}){t.push((t=>{t.preventDefault()}))},stop({hooks:t}){t.push((t=>{t.stopPropagation()}))},throttle(t,e){let{fn:i}=t;e=Number(e)||108;let r,o,n=t=>{r=!0,setTimeout((()=>{if(r=!1,o)return o=!1,n(),i(t)}),e)};t.fn=t=>r?o=!0:(n(t),i(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)))}},M=(t,e,i)=>{null==i||!1===i?t.removeAttribute(e):t.setAttribute(e,!0===i?"":"number"==typeof i||"string"==typeof i?i:"")},U={};function L(t,e,i){let r=U[e];if(!r){let o=/^[\n\s]*if.*\(.*\)/.test(e)||/\b(let|const)\s/.test(e)?`(() => { ${e} })()`:e;try{r=U[e]=new Function("__scope",`with (__scope) { return ${o} };`)}catch(r){return _(r,t,e,i)}}return o=>{let n;try{n=r.call(t,o)}catch(r){return _(r,t,e,i)}return n}}function _(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 R(t){return t.replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,(t=>"-"+t.toLowerCase()))}var z=new WeakMap;function F(t,i){if(!t.children)return;if(z.has(t)){let r=z.get(t);return function(t){if(o>0)return t();o++;try{t()}finally{e()}}((()=>Object.assign(r,i))),r}const r=S(i||{}),n=[],s=(t,e=t.parentNode)=>{for(let i in E){let o=":"+i;if(t.hasAttribute?.(o)){let s=t.getAttribute(o);if(t.removeAttribute(o),n.push(E[i](t,s,r,i)),z.has(t)||t.parentNode!==e)return!1}}if(t.attributes)for(let i=0;i<t.attributes.length;){let o=t.attributes[i];if(":"!==o.name[0]){i++;continue}t.removeAttribute(o.name);let s=o.value,l=o.name.slice(1).split(":");for(let i of l){let o=W[i]||T;if(n.push(o(t,s,r,i)),z.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 n)if(t){let e;b((()=>{"function"==typeof e&&e(),e=t(r)}))}return Object.seal(r),z.set(t,r),r}var I=F;export{I as default};
|
package/src/directives.js
CHANGED
|
@@ -303,17 +303,17 @@ const mods = {
|
|
|
303
303
|
throttle(opts, limit) {
|
|
304
304
|
let {fn} = opts
|
|
305
305
|
limit = Number(limit) || 108
|
|
306
|
-
let pause, planned, block = () => {
|
|
306
|
+
let pause, planned, block = (e) => {
|
|
307
307
|
pause = true
|
|
308
308
|
setTimeout(() => {
|
|
309
309
|
pause = false
|
|
310
310
|
// if event happened during blocked time, it schedules call by the end
|
|
311
311
|
if (planned) return (planned = false, block(), fn(e))
|
|
312
|
-
})
|
|
312
|
+
}, limit)
|
|
313
313
|
}
|
|
314
314
|
opts.fn = e => {
|
|
315
315
|
if (pause) return (planned = true)
|
|
316
|
-
block();
|
|
316
|
+
block(e);
|
|
317
317
|
return fn(e);
|
|
318
318
|
}
|
|
319
319
|
},
|
|
@@ -383,7 +383,7 @@ function parseExpr(el, expression, dir) {
|
|
|
383
383
|
// Support expressions starting with "if" statements like: "if (...) doSomething()"
|
|
384
384
|
|| /^[\n\s]*if.*\(.*\)/.test(expression)
|
|
385
385
|
// Support expressions starting with "let/const" like: "let foo = 'bar'"
|
|
386
|
-
||
|
|
386
|
+
|| /\b(let|const)\s/.test(expression)
|
|
387
387
|
? `(() => { ${expression} })()`
|
|
388
388
|
: expression;
|
|
389
389
|
|
package/test/test.js
CHANGED
|
@@ -96,11 +96,22 @@ test('props: multiprop', async () => {
|
|
|
96
96
|
|
|
97
97
|
// FIXME: this must work without return
|
|
98
98
|
test.todo('props: calculation', async () => {
|
|
99
|
-
let el = h`<x :x="let a = 5; return Array.from({length:
|
|
100
|
-
sprae(el);
|
|
101
|
-
is(el.outerHTML, `<x x="
|
|
99
|
+
let el = h`<x :x="let a = 5; return Array.from({length: x}, (_,i)=>i).join('')"></x>`
|
|
100
|
+
let state = sprae(el, {x:3});
|
|
101
|
+
is(el.outerHTML, `<x x="012"></x>`)
|
|
102
|
+
state.x = 4
|
|
103
|
+
is(el.outerHTML, `<x x="0123"></x>`)
|
|
102
104
|
})
|
|
103
105
|
|
|
106
|
+
test.todo('props: semicols in expression', async () => {
|
|
107
|
+
let el = h`<x :x="0; return Array.from({length: x}, (_,i)=>i).join('')"></x>`
|
|
108
|
+
let state = sprae(el, {x:3});
|
|
109
|
+
is(el.outerHTML, `<x x="012"></x>`)
|
|
110
|
+
state.x = 4
|
|
111
|
+
is(el.outerHTML, `<x x="0123"></x>`)
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
|
|
104
115
|
test('data: base', async () => {
|
|
105
116
|
let el = h`<input :data="{a:1, fooBar:2}"/>`
|
|
106
117
|
let params = sprae(el)
|
|
@@ -654,6 +665,24 @@ test('on: debounce', async e => {
|
|
|
654
665
|
is(state.log, ['x'])
|
|
655
666
|
})
|
|
656
667
|
|
|
668
|
+
test('on: throttle', async e => {
|
|
669
|
+
let el = h`<x :onkeydown.throttle-10="e=>log.push(e.key)"></x>`
|
|
670
|
+
let state = sprae(el, {log:[]})
|
|
671
|
+
el.dispatchEvent(new window.KeyboardEvent('keydown', { key: 'x', bubbles: true }));
|
|
672
|
+
el.dispatchEvent(new window.KeyboardEvent('keydown', { key: 'x', bubbles: true }));
|
|
673
|
+
is(state.log, ['x'])
|
|
674
|
+
await time(5)
|
|
675
|
+
el.dispatchEvent(new window.KeyboardEvent('keydown', { key: 'x', bubbles: true }));
|
|
676
|
+
is(state.log, ['x'])
|
|
677
|
+
await time(10)
|
|
678
|
+
is(state.log, ['x', 'x'])
|
|
679
|
+
await time(10)
|
|
680
|
+
is(state.log, ['x', 'x'])
|
|
681
|
+
el.dispatchEvent(new window.KeyboardEvent('keydown', { key: 'x', bubbles: true }));
|
|
682
|
+
is(state.log, ['x', 'x', 'x'])
|
|
683
|
+
})
|
|
684
|
+
|
|
685
|
+
|
|
657
686
|
test('with: inline', () => {
|
|
658
687
|
let el = h`<x :with="{foo:'bar'}"><y :text="foo + baz"></y></x>`
|
|
659
688
|
let state = sprae(el, {baz: 'qux'})
|