aberdeen 1.0.13 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/aberdeen.js CHANGED
@@ -194,7 +194,7 @@ class ContentScope extends Scope {
194
194
  getInsertAfterNode() {
195
195
  return this.getLastNode() || this.getPrecedingNode();
196
196
  }
197
- onChange(index, newData, oldData) {
197
+ onChange() {
198
198
  queue(this);
199
199
  }
200
200
  getChildPrevSibling() {
@@ -336,32 +336,6 @@ class SetArgScope extends ChainedScope {
336
336
  currentScope = savedScope;
337
337
  }
338
338
  }
339
- var immediateQueue = new ReverseSortedSet("prio");
340
-
341
- class ImmediateScope extends RegularScope {
342
- onChange(index, newData, oldData) {
343
- immediateQueue.add(this);
344
- }
345
- }
346
- var immediateQueueRunning = false;
347
- function runImmediateQueue() {
348
- for (let count = 0;!immediateQueue.isEmpty() && !immediateQueueRunning; count++) {
349
- if (count > 42) {
350
- immediateQueue.clear();
351
- throw new Error("Too many immediate-mode recursive updates");
352
- }
353
- immediateQueueRunning = true;
354
- const copy = immediateQueue;
355
- immediateQueue = new ReverseSortedSet("prio");
356
- try {
357
- for (const scope of copy) {
358
- scope.queueRun();
359
- }
360
- } finally {
361
- immediateQueueRunning = false;
362
- }
363
- }
364
- }
365
339
 
366
340
  class OnEachScope extends Scope {
367
341
  renderer;
@@ -383,22 +357,18 @@ class OnEachScope extends Scope {
383
357
  currentScope.cleaners.push(this);
384
358
  if (target instanceof Array) {
385
359
  for (let i = 0;i < target.length; i++) {
386
- if (target[i] !== undefined) {
387
- new OnEachItemScope(this, i, false);
388
- }
360
+ new OnEachItemScope(this, i, false);
389
361
  }
390
362
  } else {
391
- for (const [key, value] of getEntries(target)) {
392
- if (value !== undefined) {
393
- new OnEachItemScope(this, key, false);
394
- }
363
+ for (const key of target instanceof Map ? target.keys() : Object.keys(target)) {
364
+ new OnEachItemScope(this, key, false);
395
365
  }
396
366
  }
397
367
  }
398
368
  getPrecedingNode() {
399
369
  return findLastNodeInPrevSiblings(this.prevSibling);
400
370
  }
401
- onChange(index, newData, oldData) {
371
+ onChange(index) {
402
372
  if (!(this.target instanceof Array) || typeof index === "number")
403
373
  this.changedIndexes.add(index);
404
374
  queue(this);
@@ -410,16 +380,10 @@ class OnEachScope extends Scope {
410
380
  const oldScope = this.byIndex.get(index);
411
381
  if (oldScope)
412
382
  oldScope.remove();
413
- let hasValue;
414
- if (this.target instanceof Map) {
415
- hasValue = this.target.has(index);
383
+ if (this.target instanceof Map ? this.target.has(index) : (index in this.target)) {
384
+ new OnEachItemScope(this, index, true);
416
385
  } else {
417
- hasValue = this.target[index] !== undefined;
418
- }
419
- if (!hasValue) {
420
386
  this.byIndex.delete(index);
421
- } else {
422
- new OnEachItemScope(this, index, true);
423
387
  }
424
388
  }
425
389
  topRedrawScope = undefined;
@@ -553,6 +517,15 @@ function addNode(node) {
553
517
  }
554
518
  var ROOT_SCOPE = new RootScope;
555
519
  var currentScope = ROOT_SCOPE;
520
+ function leakScope(func) {
521
+ const savedScope = currentScope;
522
+ currentScope = new RootScope;
523
+ try {
524
+ return func();
525
+ } finally {
526
+ currentScope = savedScope;
527
+ }
528
+ }
556
529
  var ANY_SYMBOL = Symbol("any");
557
530
  var TARGET_SYMBOL = Symbol("target");
558
531
  var MAP_SIZE_SYMBOL = Symbol("mapSize");
@@ -587,10 +560,11 @@ function onEach(target, render, makeKey) {
587
560
  new OnEachScope(target, render, makeKey);
588
561
  }
589
562
  function isObjEmpty(obj) {
590
- for (const k in obj)
563
+ for (const k of Object.keys(obj))
591
564
  return false;
592
565
  return true;
593
566
  }
567
+ var EMPTY = Symbol("empty");
594
568
  function isEmpty(proxied) {
595
569
  const target = proxied[TARGET_SYMBOL] || proxied;
596
570
  const scope = currentScope;
@@ -610,7 +584,7 @@ function isEmpty(proxied) {
610
584
  }
611
585
  const result = isObjEmpty(target);
612
586
  subscribe(target, ANY_SYMBOL, (index, newData, oldData) => {
613
- if (result ? oldData === undefined : newData === undefined)
587
+ if (result ? oldData === EMPTY : newData === EMPTY)
614
588
  queue(scope);
615
589
  });
616
590
  return result;
@@ -622,14 +596,14 @@ function count(proxied) {
622
596
  return ref(proxied, "size");
623
597
  const target = proxied[TARGET_SYMBOL] || proxied;
624
598
  let cnt = 0;
625
- for (const k in target)
599
+ for (const k of Object.keys(target))
626
600
  if (target[k] !== undefined)
627
601
  cnt++;
628
602
  const result = proxy(cnt);
629
603
  subscribe(target, ANY_SYMBOL, (index, newData, oldData) => {
630
- if (oldData === newData) {} else if (oldData === undefined)
604
+ if (oldData === newData) {} else if (oldData === EMPTY)
631
605
  result.value = ++cnt;
632
- else if (newData === undefined)
606
+ else if (newData === EMPTY)
633
607
  result.value = --cnt;
634
608
  });
635
609
  return result;
@@ -647,7 +621,7 @@ function defaultEmitHandler(target, index, newData, oldData) {
647
621
  if (typeof observer === "function")
648
622
  observer(index, newData, oldData);
649
623
  else
650
- observer.onChange(index, newData, oldData);
624
+ observer.onChange(index);
651
625
  }
652
626
  }
653
627
  }
@@ -663,25 +637,22 @@ var objectHandler = {
663
637
  set(target, prop, newData) {
664
638
  if (typeof newData === "object" && newData)
665
639
  newData = newData[TARGET_SYMBOL] || newData;
666
- const oldData = target[prop];
640
+ const oldData = target.hasOwnProperty(prop) ? target[prop] : EMPTY;
667
641
  if (newData !== oldData) {
668
642
  target[prop] = newData;
669
643
  emit(target, prop, newData, oldData);
670
- runImmediateQueue();
671
644
  }
672
645
  return true;
673
646
  },
674
647
  deleteProperty(target, prop) {
675
- const old = target[prop];
648
+ const old = target.hasOwnProperty(prop) ? target[prop] : EMPTY;
676
649
  delete target[prop];
677
- emit(target, prop, undefined, old);
678
- runImmediateQueue();
650
+ emit(target, prop, EMPTY, old);
679
651
  return true;
680
652
  },
681
653
  has(target, prop) {
682
- const result = prop in target;
683
654
  subscribe(target, prop);
684
- return result;
655
+ return target.hasOwnProperty(prop);
685
656
  },
686
657
  ownKeys(target) {
687
658
  subscribe(target, ANY_SYMBOL);
@@ -689,27 +660,31 @@ var objectHandler = {
689
660
  }
690
661
  };
691
662
  function arraySet(target, prop, newData) {
692
- if (typeof newData === "object" && newData)
663
+ if (typeof newData === "object" && newData) {
693
664
  newData = newData[TARGET_SYMBOL] || newData;
694
- const oldData = target[prop];
665
+ }
666
+ let oldData = target[prop];
667
+ if (oldData === undefined && !target.hasOwnProperty(prop))
668
+ oldData = EMPTY;
695
669
  if (newData !== oldData) {
696
670
  const oldLength = target.length;
697
671
  if (prop === "length") {
698
672
  target.length = newData;
699
673
  for (let i = newData;i < oldLength; i++) {
700
- emit(target, i, undefined, target[i]);
674
+ emit(target, i, EMPTY, target[i]);
701
675
  }
702
676
  } else {
703
- const intProp = Number.parseInt(prop);
704
- if (intProp.toString() === prop)
705
- prop = intProp;
677
+ if (typeof prop === "string") {
678
+ const n = 0 | prop;
679
+ if (String(n) === prop && n >= 0)
680
+ prop = n;
681
+ }
706
682
  target[prop] = newData;
707
683
  emit(target, prop, newData, oldData);
708
684
  }
709
685
  if (target.length !== oldLength) {
710
686
  emit(target, "length", target.length, oldLength);
711
687
  }
712
- runImmediateQueue();
713
688
  }
714
689
  return true;
715
690
  }
@@ -717,18 +692,27 @@ var arrayHandler = {
717
692
  get(target, prop) {
718
693
  if (prop === TARGET_SYMBOL)
719
694
  return target;
720
- let subProp = prop;
721
- if (typeof prop !== "symbol") {
722
- const intProp = Number.parseInt(prop);
723
- if (intProp.toString() === prop)
724
- subProp = intProp;
695
+ if (typeof prop === "string") {
696
+ const n = 0 | prop;
697
+ if (String(n) === prop && n >= 0)
698
+ prop = n;
725
699
  }
726
- subscribe(target, subProp);
700
+ subscribe(target, prop);
727
701
  return optProxy(target[prop]);
728
702
  },
729
703
  set: arraySet,
730
704
  deleteProperty(target, prop) {
731
- return arraySet(target, prop, undefined);
705
+ if (typeof prop === "string") {
706
+ const n = 0 | prop;
707
+ if (String(n) === prop && n >= 0)
708
+ prop = n;
709
+ }
710
+ let oldData = target[prop];
711
+ if (oldData === undefined && !target.hasOwnProperty(prop))
712
+ oldData = EMPTY;
713
+ delete target[prop];
714
+ emit(target, prop, EMPTY, oldData);
715
+ return true;
732
716
  }
733
717
  };
734
718
  function wrapIteratorSingle(iterator) {
@@ -773,30 +757,35 @@ var mapMethodHandlers = {
773
757
  },
774
758
  set(key, newData) {
775
759
  const target = this[TARGET_SYMBOL];
776
- if (typeof key === "object" && key)
760
+ if (typeof key === "object" && key) {
777
761
  key = key[TARGET_SYMBOL] || key;
778
- if (typeof newData === "object" && newData)
762
+ }
763
+ if (typeof newData === "object" && newData) {
779
764
  newData = newData[TARGET_SYMBOL] || newData;
780
- const oldData = target.get(key);
765
+ }
766
+ let oldData = target.get(key);
767
+ if (oldData === undefined && !target.has(key))
768
+ oldData = EMPTY;
781
769
  if (newData !== oldData) {
782
770
  const oldSize = target.size;
783
771
  target.set(key, newData);
784
772
  emit(target, key, newData, oldData);
785
773
  emit(target, MAP_SIZE_SYMBOL, target.size, oldSize);
786
- runImmediateQueue();
787
774
  }
788
775
  return this;
789
776
  },
790
777
  delete(key) {
791
778
  const target = this[TARGET_SYMBOL];
792
- if (typeof key === "object" && key)
779
+ if (typeof key === "object" && key) {
793
780
  key = key[TARGET_SYMBOL] || key;
794
- const oldData = target.get(key);
781
+ }
782
+ let oldData = target.get(key);
783
+ if (oldData === undefined && !target.has(key))
784
+ oldData = EMPTY;
795
785
  const result = target.delete(key);
796
786
  if (result) {
797
- emit(target, key, undefined, oldData);
787
+ emit(target, key, EMPTY, oldData);
798
788
  emit(target, MAP_SIZE_SYMBOL, target.size, target.size + 1);
799
- runImmediateQueue();
800
789
  }
801
790
  return result;
802
791
  },
@@ -804,17 +793,16 @@ var mapMethodHandlers = {
804
793
  const target = this[TARGET_SYMBOL];
805
794
  const oldSize = target.size;
806
795
  for (const key of target.keys()) {
807
- const oldData = target.get(key);
808
- emit(target, key, undefined, oldData);
796
+ emit(target, key, undefined, target.get(key));
809
797
  }
810
798
  target.clear();
811
799
  emit(target, MAP_SIZE_SYMBOL, 0, oldSize);
812
- runImmediateQueue();
813
800
  },
814
801
  has(key) {
815
802
  const target = this[TARGET_SYMBOL];
816
- if (typeof key === "object" && key)
803
+ if (typeof key === "object" && key) {
817
804
  key = key[TARGET_SYMBOL] || key;
805
+ }
818
806
  subscribe(target, key);
819
807
  return target.has(key);
820
808
  },
@@ -843,15 +831,14 @@ var mapHandler = {
843
831
  get(target, prop) {
844
832
  if (prop === TARGET_SYMBOL)
845
833
  return target;
846
- if (prop in mapMethodHandlers) {
834
+ if (mapMethodHandlers.hasOwnProperty(prop)) {
847
835
  return mapMethodHandlers[prop];
848
836
  }
849
837
  if (prop === "size") {
850
838
  subscribe(target, MAP_SIZE_SYMBOL);
851
839
  return target.size;
852
840
  }
853
- subscribe(target, prop);
854
- return optProxy(target[prop]);
841
+ return target[prop];
855
842
  }
856
843
  };
857
844
  var proxyMap = new WeakMap;
@@ -875,6 +862,19 @@ function optProxy(value) {
875
862
  return proxied;
876
863
  }
877
864
  function proxy(target) {
865
+ if (target instanceof Promise) {
866
+ const result = optProxy({
867
+ busy: true
868
+ });
869
+ target.then((value) => {
870
+ result.value = value;
871
+ result.busy = false;
872
+ }).catch((err) => {
873
+ result.error = err;
874
+ result.busy = false;
875
+ });
876
+ return result;
877
+ }
878
878
  return optProxy(typeof target === "object" && target !== null ? target : { value: target });
879
879
  }
880
880
  function unproxy(target) {
@@ -886,31 +886,31 @@ function destroyWithClass(element, cls) {
886
886
  element.classList.add(...classes);
887
887
  setTimeout(() => element.remove(), 2000);
888
888
  }
889
- function copy(dst, src, flags = 0) {
890
- copyRecurse(dst, src, flags);
891
- runImmediateQueue();
889
+ function copy(a, b, c) {
890
+ if (arguments.length > 2)
891
+ return copySet(a, b, c, 0);
892
+ return copyImpl(a, b, 0);
892
893
  }
893
- var MERGE = 1;
894
- var SHALLOW = 2;
895
- var COPY_SUBSCRIBE = 32;
896
- var COPY_EMIT = 64;
897
- function clone(src, flags = 0) {
898
- let dst;
899
- if (src instanceof Map) {
900
- dst = new Map;
901
- } else {
902
- dst = Object.create(Object.getPrototypeOf(src));
903
- }
904
- copyRecurse(dst, src, flags);
905
- return dst;
906
- }
907
- function getEntries(subject) {
908
- return subject instanceof Map ? subject.entries() : Object.entries(subject);
894
+ function copySet(dst, dstKey, src, flags) {
895
+ let dstVal = peek(dst, dstKey);
896
+ if (src === dstVal)
897
+ return false;
898
+ if (typeof dstVal === "object" && dstVal && typeof src === "object" && src && dstVal.constructor === src.constructor) {
899
+ return copyImpl(dstVal, src, flags);
900
+ }
901
+ src = clone(src);
902
+ if (dst instanceof Map)
903
+ dst.set(dstKey, src);
904
+ else
905
+ dst[dstKey] = clone(src);
906
+ return true;
909
907
  }
910
- function getKeys(subject) {
911
- return subject instanceof Map ? subject.keys() : Object.keys(subject);
908
+ function merge(a, b, c) {
909
+ if (arguments.length > 2)
910
+ return copySet(a, b, c, MERGE);
911
+ return copyImpl(a, b, MERGE);
912
912
  }
913
- function copyRecurse(dst, src, flags) {
913
+ function copyImpl(dst, src, flags) {
914
914
  let unproxied = dst[TARGET_SYMBOL];
915
915
  if (unproxied) {
916
916
  dst = unproxied;
@@ -922,89 +922,127 @@ function copyRecurse(dst, src, flags) {
922
922
  if (currentScope !== ROOT_SCOPE && !peeking)
923
923
  flags |= COPY_SUBSCRIBE;
924
924
  }
925
+ return copyRecursive(dst, src, flags);
926
+ }
927
+ function copyRecursive(dst, src, flags) {
925
928
  if (flags & COPY_SUBSCRIBE)
926
929
  subscribe(src, ANY_SYMBOL);
927
- if (src instanceof Array) {
928
- if (!(dst instanceof Array))
929
- throw new Error("Cannot copy array into object");
930
+ let changed = false;
931
+ if (src instanceof Array && dst instanceof Array) {
930
932
  const dstLen = dst.length;
931
933
  const srcLen = src.length;
932
- for (let i = 0;i < srcLen; i++) {
933
- copyValue(dst, i, src[i], flags);
934
+ for (let index = 0;index < srcLen; index++) {
935
+ let dstValue = dst[index];
936
+ if (dstValue === undefined && !dst.hasOwnProperty(index))
937
+ dstValue = EMPTY;
938
+ let srcValue = src[index];
939
+ if (srcValue === undefined && !src.hasOwnProperty(index)) {
940
+ delete dst[index];
941
+ if (flags & COPY_EMIT)
942
+ emit(dst, index, EMPTY, dstValue);
943
+ changed = true;
944
+ } else if (dstValue !== srcValue) {
945
+ if (srcValue && typeof srcValue === "object") {
946
+ if (typeof dstValue === "object" && dstValue && srcValue.constructor === dstValue.constructor) {
947
+ changed = copyRecursive(dstValue, srcValue, flags) || changed;
948
+ continue;
949
+ }
950
+ srcValue = clone(srcValue);
951
+ }
952
+ dst[index] = srcValue;
953
+ if (flags & COPY_EMIT)
954
+ emit(dst, index, srcValue, dstValue);
955
+ changed = true;
956
+ }
934
957
  }
935
958
  if (srcLen !== dstLen) {
936
959
  if (flags & COPY_EMIT) {
937
960
  for (let i = srcLen;i < dstLen; i++) {
938
961
  const old = dst[i];
939
- dst[i] = undefined;
940
- emit(dst, i, undefined, old);
962
+ delete dst[i];
963
+ emit(dst, i, EMPTY, old);
941
964
  }
942
965
  dst.length = srcLen;
943
966
  emit(dst, "length", srcLen, dstLen);
944
967
  } else {
945
968
  dst.length = srcLen;
946
969
  }
970
+ changed = true;
947
971
  }
948
- } else {
949
- for (const [key, value] of getEntries(src)) {
950
- copyValue(dst, key, value, flags);
972
+ } else if (src instanceof Map && dst instanceof Map) {
973
+ for (const key of src.keys()) {
974
+ let srcValue = src.get(key);
975
+ let dstValue = dst.get(key);
976
+ if (dstValue === undefined && !dst.has(key))
977
+ dstValue = EMPTY;
978
+ if (dstValue !== srcValue) {
979
+ if (srcValue && typeof srcValue === "object") {
980
+ if (typeof dstValue === "object" && dstValue && srcValue.constructor === dstValue.constructor) {
981
+ changed = copyRecursive(dstValue, srcValue, flags) || changed;
982
+ continue;
983
+ }
984
+ srcValue = clone(srcValue);
985
+ }
986
+ dst.set(key, srcValue);
987
+ if (flags & COPY_EMIT)
988
+ emit(dst, key, srcValue, dstValue);
989
+ changed = true;
990
+ }
951
991
  }
952
992
  if (!(flags & MERGE)) {
953
- if (src instanceof Map) {
954
- for (const key of getKeys(dst)) {
955
- if (!src.has(key)) {
956
- deleteKey(dst, key, flags);
993
+ for (const k of dst.keys()) {
994
+ if (!src.has(k)) {
995
+ const old = dst.get(k);
996
+ dst.delete(k);
997
+ if (flags & COPY_EMIT) {
998
+ emit(dst, k, undefined, old);
957
999
  }
1000
+ changed = true;
958
1001
  }
959
- } else {
960
- for (const key of getKeys(dst)) {
961
- if (!(key in src)) {
962
- deleteKey(dst, key, flags);
1002
+ }
1003
+ }
1004
+ } else if (src.constructor === dst.constructor) {
1005
+ for (const key of Object.keys(src)) {
1006
+ let srcValue = src[key];
1007
+ const dstValue = dst.hasOwnProperty(key) ? dst[key] : EMPTY;
1008
+ if (dstValue !== srcValue) {
1009
+ if (srcValue && typeof srcValue === "object") {
1010
+ if (typeof dstValue === "object" && dstValue && srcValue.constructor === dstValue.constructor) {
1011
+ changed = copyRecursive(dstValue, srcValue, flags) || changed;
1012
+ continue;
963
1013
  }
1014
+ srcValue = clone(srcValue);
1015
+ }
1016
+ dst[key] = srcValue;
1017
+ if (flags & COPY_EMIT)
1018
+ emit(dst, key, srcValue, dstValue);
1019
+ changed = true;
1020
+ }
1021
+ }
1022
+ if (!(flags & MERGE)) {
1023
+ for (const k of Object.keys(dst)) {
1024
+ if (!src.hasOwnProperty(k)) {
1025
+ const old = dst[k];
1026
+ delete dst[k];
1027
+ if (flags & COPY_EMIT && old !== undefined) {
1028
+ emit(dst, k, undefined, old);
1029
+ }
1030
+ changed = true;
964
1031
  }
965
1032
  }
966
1033
  }
967
- }
968
- }
969
- function deleteKey(dst, key, flags) {
970
- let old;
971
- if (dst instanceof Map) {
972
- old = dst.get(key);
973
- dst.delete(key);
974
1034
  } else {
975
- old = dst[key];
976
- delete dst[key];
977
- }
978
- if (flags & COPY_EMIT && old !== undefined) {
979
- emit(dst, key, undefined, old);
1035
+ throw new Error(`Incompatible or non-object types: ${src?.constructor?.name || typeof src} vs ${dst?.constructor?.name || typeof dst}`);
980
1036
  }
1037
+ return changed;
981
1038
  }
982
- function copyValue(dst, index, srcValue, flags) {
983
- const dstValue = dst instanceof Map ? dst.get(index) : dst[index];
984
- if (srcValue !== dstValue) {
985
- if (srcValue && dstValue && typeof srcValue === "object" && typeof dstValue === "object" && (srcValue.constructor === dstValue.constructor || flags & MERGE && dstValue instanceof Array)) {
986
- copyRecurse(dstValue, srcValue, flags);
987
- return;
988
- }
989
- if (!(flags & SHALLOW) && srcValue && typeof srcValue === "object") {
990
- const copy2 = Object.create(Object.getPrototypeOf(srcValue));
991
- copyRecurse(copy2, srcValue, 0);
992
- srcValue = copy2;
993
- }
994
- if (dst instanceof Map) {
995
- if (flags & MERGE && srcValue == null)
996
- dst.delete(index);
997
- else
998
- dst.set(index, srcValue);
999
- } else {
1000
- if (flags & MERGE && srcValue == null)
1001
- delete dst[index];
1002
- else
1003
- dst[index] = srcValue;
1004
- }
1005
- if (flags & COPY_EMIT)
1006
- emit(dst, index, srcValue, dstValue);
1007
- }
1039
+ var MERGE = 1;
1040
+ var COPY_SUBSCRIBE = 32;
1041
+ var COPY_EMIT = 64;
1042
+ function clone(src) {
1043
+ const copied = Array.isArray(src) ? [] : src instanceof Map ? new Map : Object.create(Object.getPrototypeOf(src));
1044
+ copyImpl(copied, src, MERGE);
1045
+ return copied;
1008
1046
  }
1009
1047
  var refHandler = {
1010
1048
  get(target, prop) {
@@ -1062,7 +1100,7 @@ function applyBind(el, target) {
1062
1100
  throw new Error(`SELECT has no '${target.value}' OPTION (yet)`);
1063
1101
  };
1064
1102
  }
1065
- observe(onProxyChange);
1103
+ derive(onProxyChange);
1066
1104
  el.addEventListener("input", onInputChange);
1067
1105
  clean(() => {
1068
1106
  el.removeEventListener("input", onInputChange);
@@ -1096,34 +1134,86 @@ var SPECIAL_PROPS = {
1096
1134
  },
1097
1135
  text: (value) => {
1098
1136
  addNode(document.createTextNode(value));
1099
- },
1100
- element: (value) => {
1101
- console.log("Aberdeen: $({element: myElement}) is deprecated, use $(myElement) instead");
1102
- addNode(value);
1103
- SPECIAL_PROPS.element = addNode;
1104
1137
  }
1105
1138
  };
1106
1139
  function $(...args) {
1107
1140
  let savedCurrentScope;
1108
1141
  let err;
1109
1142
  let result;
1143
+ let nextArgIsProp;
1110
1144
  for (let arg of args) {
1111
- if (arg == null || arg === false)
1112
- continue;
1113
- if (typeof arg === "string") {
1114
- let text;
1115
- let classes;
1116
- const textPos = arg.indexOf(":");
1117
- if (textPos >= 0) {
1118
- text = arg.substring(textPos + 1);
1119
- arg = arg.substring(0, textPos);
1120
- }
1121
- const classPos = arg.indexOf(".");
1122
- if (classPos >= 0) {
1123
- classes = arg.substring(classPos + 1);
1124
- arg = arg.substring(0, classPos);
1125
- }
1126
- if (arg === "") {
1145
+ if (nextArgIsProp) {
1146
+ applyArg(nextArgIsProp, arg);
1147
+ nextArgIsProp = undefined;
1148
+ } else if (arg == null || arg === false) {} else if (typeof arg === "string") {
1149
+ let pos = 0;
1150
+ let argLen = arg.length;
1151
+ while (pos < argLen) {
1152
+ let nextSpace = arg.indexOf(" ", pos);
1153
+ if (nextSpace < 0)
1154
+ nextSpace = arg.length;
1155
+ let part = arg.substring(pos, nextSpace);
1156
+ const oldPos = pos;
1157
+ pos = nextSpace + 1;
1158
+ const firstIs = part.indexOf("=");
1159
+ const firstColon = part.indexOf(":");
1160
+ if (firstIs >= 0 && (firstColon < 0 || firstIs < firstColon)) {
1161
+ const prop = part.substring(0, firstIs);
1162
+ if (firstIs < part.length - 1) {
1163
+ let value = part.substring(firstIs + 1);
1164
+ if (value[0] === '"') {
1165
+ const closeIndex = arg.indexOf('"', firstIs + 2 + oldPos);
1166
+ if (closeIndex < 0)
1167
+ throw new Error(`Unterminated string for '${prop}'`);
1168
+ value = arg.substring(firstIs + 2 + oldPos, closeIndex);
1169
+ pos = closeIndex + 1;
1170
+ if (arg[pos] === " ")
1171
+ pos++;
1172
+ }
1173
+ applyArg(prop, value);
1174
+ continue;
1175
+ } else {
1176
+ if (pos < argLen)
1177
+ throw new Error(`No value given for '${part}'`);
1178
+ nextArgIsProp = prop;
1179
+ break;
1180
+ }
1181
+ }
1182
+ let text;
1183
+ if (firstColon >= 0) {
1184
+ text = arg.substring(firstColon + 1 + oldPos);
1185
+ part = part.substring(0, firstColon);
1186
+ if (!text) {
1187
+ if (pos < argLen)
1188
+ throw new Error(`No value given for '${part}'`);
1189
+ nextArgIsProp = "text";
1190
+ break;
1191
+ }
1192
+ pos = argLen;
1193
+ }
1194
+ let classes;
1195
+ const classPos = part.indexOf(".");
1196
+ if (classPos >= 0) {
1197
+ classes = part.substring(classPos + 1);
1198
+ part = part.substring(0, classPos);
1199
+ }
1200
+ if (part) {
1201
+ const svg = currentScope.inSvgNamespace || part === "svg";
1202
+ if (svg) {
1203
+ result = document.createElementNS("http://www.w3.org/2000/svg", part);
1204
+ } else {
1205
+ result = document.createElement(part);
1206
+ }
1207
+ addNode(result);
1208
+ if (!savedCurrentScope)
1209
+ savedCurrentScope = currentScope;
1210
+ const newScope = new ChainedScope(result, true);
1211
+ if (svg)
1212
+ newScope.inSvgNamespace = true;
1213
+ if (topRedrawScope === currentScope)
1214
+ topRedrawScope = newScope;
1215
+ currentScope = newScope;
1216
+ }
1127
1217
  if (text)
1128
1218
  addNode(document.createTextNode(text));
1129
1219
  if (classes) {
@@ -1133,32 +1223,6 @@ function $(...args) {
1133
1223
  clean(() => el.classList.remove(...classes.split(".")));
1134
1224
  }
1135
1225
  }
1136
- } else if (arg.indexOf(" ") >= 0) {
1137
- err = `Tag '${arg}' cannot contain space`;
1138
- break;
1139
- } else {
1140
- const useNamespace = currentScope.inSvgNamespace || arg === "svg";
1141
- if (useNamespace) {
1142
- result = document.createElementNS("http://www.w3.org/2000/svg", arg);
1143
- } else {
1144
- result = document.createElement(arg);
1145
- }
1146
- if (classes)
1147
- result.className = classes.replaceAll(".", " ");
1148
- if (text)
1149
- result.textContent = text;
1150
- addNode(result);
1151
- if (!savedCurrentScope) {
1152
- savedCurrentScope = currentScope;
1153
- }
1154
- const newScope = new ChainedScope(result, true);
1155
- if (arg === "svg") {
1156
- newScope.inSvgNamespace = true;
1157
- }
1158
- newScope.lastChild = result.lastChild || undefined;
1159
- if (topRedrawScope === currentScope)
1160
- topRedrawScope = newScope;
1161
- currentScope = newScope;
1162
1226
  }
1163
1227
  } else if (typeof arg === "object") {
1164
1228
  if (arg.constructor !== Object) {
@@ -1175,7 +1239,7 @@ function $(...args) {
1175
1239
  break;
1176
1240
  }
1177
1241
  } else {
1178
- for (const key in arg) {
1242
+ for (const key of Object.keys(arg)) {
1179
1243
  const val = arg[key];
1180
1244
  applyArg(key, val);
1181
1245
  }
@@ -1187,9 +1251,10 @@ function $(...args) {
1187
1251
  break;
1188
1252
  }
1189
1253
  }
1190
- if (savedCurrentScope) {
1254
+ if (nextArgIsProp !== undefined)
1255
+ throw new Error(`No value given for '${nextArgIsProp}='`);
1256
+ if (savedCurrentScope)
1191
1257
  currentScope = savedCurrentScope;
1192
- }
1193
1258
  if (err)
1194
1259
  throw new Error(err);
1195
1260
  return result;
@@ -1205,7 +1270,7 @@ function insertCss(style, global = false) {
1205
1270
  function styleToCss(style, prefix) {
1206
1271
  let props = "";
1207
1272
  let rules = "";
1208
- for (const kOr in style) {
1273
+ for (const kOr of Object.keys(style)) {
1209
1274
  const v = style[kOr];
1210
1275
  for (const k of kOr.split(/, ?/g)) {
1211
1276
  if (v && typeof v === "object") {
@@ -1271,12 +1336,9 @@ function getParentElement() {
1271
1336
  function clean(cleaner) {
1272
1337
  currentScope.cleaners.push(cleaner);
1273
1338
  }
1274
- function observe(func) {
1339
+ function derive(func) {
1275
1340
  return new ResultScope(currentScope.parentElement, func).result;
1276
1341
  }
1277
- function immediateObserve(func) {
1278
- new ImmediateScope(currentScope.parentElement, func);
1279
- }
1280
1342
  function mount(parentElement, func) {
1281
1343
  new MountScope(parentElement, func);
1282
1344
  }
@@ -1284,10 +1346,14 @@ function unmountAll() {
1284
1346
  ROOT_SCOPE.remove();
1285
1347
  cssCount = 0;
1286
1348
  }
1287
- function peek(func) {
1349
+ function peek(target, key) {
1288
1350
  peeking++;
1289
1351
  try {
1290
- return func();
1352
+ if (arguments.length === 1) {
1353
+ return target();
1354
+ } else {
1355
+ return target instanceof Map ? target.get(key) : target[key];
1356
+ }
1291
1357
  } finally {
1292
1358
  peeking--;
1293
1359
  }
@@ -1324,10 +1390,10 @@ function multiMap(source, func) {
1324
1390
  onEach(source, (item, key) => {
1325
1391
  const pairs = func(item, key);
1326
1392
  if (pairs) {
1327
- for (const key2 in pairs)
1393
+ for (const key2 of Object.keys(pairs))
1328
1394
  out[key2] = pairs[key2];
1329
1395
  clean(() => {
1330
- for (const key2 in pairs)
1396
+ for (const key2 of Object.keys(pairs))
1331
1397
  delete out[key2];
1332
1398
  });
1333
1399
  }
@@ -1418,25 +1484,24 @@ export {
1418
1484
  peek,
1419
1485
  partition,
1420
1486
  onEach,
1421
- observe,
1422
1487
  multiMap,
1423
1488
  mount,
1489
+ merge,
1424
1490
  map,
1491
+ leakScope,
1425
1492
  isEmpty,
1426
1493
  invertString,
1427
1494
  insertCss,
1428
- immediateObserve,
1429
1495
  getParentElement,
1430
1496
  dump,
1497
+ derive,
1431
1498
  defaultEmitHandler,
1432
1499
  count,
1433
1500
  copy,
1434
1501
  clone,
1435
1502
  clean,
1436
- SHALLOW,
1437
- MERGE,
1438
1503
  $
1439
1504
  };
1440
1505
 
1441
- //# debugId=8143A247906C19B564756E2164756E21
1506
+ //# debugId=1793ACD02DE96EE964756E2164756E21
1442
1507
  //# sourceMappingURL=aberdeen.js.map