regor 1.2.6 → 1.2.8

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.
@@ -755,15 +755,344 @@ var entangle = (r1, r2) => {
755
755
  };
756
756
  };
757
757
 
758
+ // src/misc/isRaw.ts
759
+ var isRaw = (value) => {
760
+ return !!value && value[rawSymbol] === 1;
761
+ };
762
+
763
+ // src/reactivity/isDeepRef.ts
764
+ var isDeepRef = (value) => {
765
+ return (value == null ? void 0 : value[refSymbol]) === 1;
766
+ };
767
+
768
+ // src/computed/watchEffect.ts
769
+ var collectedRefs = [];
770
+ var collectRef = (ref2) => {
771
+ var _a;
772
+ if (collectedRefs.length === 0) return;
773
+ (_a = collectedRefs[collectedRefs.length - 1]) == null ? void 0 : _a.add(ref2);
774
+ };
775
+ var watchEffect = (effect) => {
776
+ if (!effect) return () => {
777
+ };
778
+ const terminator = { stop: () => {
779
+ } };
780
+ watchEffectInternal(effect, terminator);
781
+ onUnmounted(() => terminator.stop(), true);
782
+ return terminator.stop;
783
+ };
784
+ var watchEffectInternal = (effect, terminator) => {
785
+ if (!effect) return;
786
+ let stopObservingList = [];
787
+ let isStopped = false;
788
+ const stopWatch = () => {
789
+ for (const stop of stopObservingList) stop();
790
+ stopObservingList = [];
791
+ isStopped = true;
792
+ };
793
+ terminator.stop = stopWatch;
794
+ try {
795
+ const set = /* @__PURE__ */ new Set();
796
+ collectedRefs.push(set);
797
+ effect((onCleanup) => stopObservingList.push(onCleanup));
798
+ if (isStopped) return;
799
+ for (const r of [...set]) {
800
+ const stopObserving = observe(r, () => {
801
+ stopWatch();
802
+ watchEffect(effect);
803
+ });
804
+ stopObservingList.push(stopObserving);
805
+ }
806
+ } finally {
807
+ collectedRefs.pop();
808
+ }
809
+ };
810
+ var silence = (action) => {
811
+ const len = collectedRefs.length;
812
+ const hasPush = len > 0 && collectedRefs[len - 1];
813
+ try {
814
+ if (hasPush) collectedRefs.push(null);
815
+ return action();
816
+ } finally {
817
+ if (hasPush) collectedRefs.pop();
818
+ }
819
+ };
820
+ var collectRefs = (action) => {
821
+ try {
822
+ const set = /* @__PURE__ */ new Set();
823
+ collectedRefs.push(set);
824
+ const result = action();
825
+ return { value: result, refs: [...set] };
826
+ } finally {
827
+ collectedRefs.pop();
828
+ }
829
+ };
830
+
831
+ // src/reactivity/trigger.ts
832
+ var trigger = (source, eventSource, isRecursive) => {
833
+ if (!isRef(source)) return;
834
+ const srefImpl = source;
835
+ srefImpl(void 0, eventSource, 1 /* trigger */);
836
+ if (!isRecursive) return;
837
+ const obj = srefImpl();
838
+ if (!obj) return;
839
+ if (isArray(obj) || isSet(obj)) {
840
+ for (const el of obj) {
841
+ trigger(el, eventSource, true);
842
+ }
843
+ } else if (isMap(obj)) {
844
+ for (const el of obj) {
845
+ trigger(el[0], eventSource, true);
846
+ trigger(el[1], eventSource, true);
847
+ }
848
+ }
849
+ if (isObject(obj)) {
850
+ for (const k in obj) {
851
+ trigger(obj[k], eventSource, true);
852
+ }
853
+ }
854
+ };
855
+
856
+ // src/proxies/proxy.ts
857
+ function define(obj, key, val) {
858
+ Object.defineProperty(obj, key, {
859
+ value: val,
860
+ enumerable: false,
861
+ writable: true,
862
+ configurable: true
863
+ });
864
+ }
865
+ var createProxy = (originalProto, proxyProto, methodsToPatch4) => {
866
+ methodsToPatch4.forEach(function(method) {
867
+ const original = originalProto[method];
868
+ define(proxyProto, method, function mutator(...args) {
869
+ const result = original.apply(this, args);
870
+ const subscribers = this[srefSymbol];
871
+ for (const subscriber of subscribers) trigger(subscriber);
872
+ return result;
873
+ });
874
+ });
875
+ };
876
+ var setToStringTag = (proxyProto, tag) => {
877
+ Object.defineProperty(proxyProto, Symbol.toStringTag, {
878
+ value: tag,
879
+ writable: false,
880
+ enumerable: false,
881
+ configurable: true
882
+ });
883
+ };
884
+
885
+ // src/proxies/array-ref.ts
886
+ var arrayProto = Array.prototype;
887
+ var proxyArrayProto = Object.create(arrayProto);
888
+ var methodsToPatch = [
889
+ "push",
890
+ "pop",
891
+ "shift",
892
+ "unshift",
893
+ "splice",
894
+ "sort",
895
+ "reverse"
896
+ ];
897
+ createProxy(arrayProto, proxyArrayProto, methodsToPatch);
898
+
899
+ // src/proxies/map-ref.ts
900
+ var mapProto = Map.prototype;
901
+ var proxyMapProto = Object.create(mapProto);
902
+ var methodsToPatch2 = ["set", "clear", "delete"];
903
+ setToStringTag(proxyMapProto, "Map");
904
+ createProxy(mapProto, proxyMapProto, methodsToPatch2);
905
+
906
+ // src/proxies/set-ref.ts
907
+ var setProto = Set.prototype;
908
+ var proxySetProto = Object.create(setProto);
909
+ var methodsToPatch3 = ["add", "clear", "delete"];
910
+ setToStringTag(proxySetProto, "Set");
911
+ createProxy(setProto, proxySetProto, methodsToPatch3);
912
+
913
+ // src/reactivity/sref.ts
914
+ var batchCollector = {};
915
+ var sref = (value) => {
916
+ if (isRef(value) || isRaw(value)) return value;
917
+ const refObj = {
918
+ auto: true,
919
+ _value: value
920
+ };
921
+ const createProxy2 = (value2) => {
922
+ if (!isObject(value2)) return false;
923
+ if (srefSymbol in value2) return true;
924
+ const isAnArray = isArray(value2);
925
+ if (isAnArray) {
926
+ Object.setPrototypeOf(value2, proxyArrayProto);
927
+ return true;
928
+ }
929
+ const isASet = isSet(value2);
930
+ if (isASet) {
931
+ Object.setPrototypeOf(value2, proxySetProto);
932
+ return true;
933
+ }
934
+ const isAMap = isMap(value2);
935
+ if (isAMap) {
936
+ Object.setPrototypeOf(value2, proxyMapProto);
937
+ return true;
938
+ }
939
+ return false;
940
+ };
941
+ const isProxy = createProxy2(value);
942
+ const observers = /* @__PURE__ */ new Set();
943
+ const trigger2 = (newValue, eventSource) => {
944
+ if (batchCollector.stack && batchCollector.stack.length) {
945
+ const current = batchCollector.stack[batchCollector.stack.length - 1];
946
+ current.add(srefFunction);
947
+ return;
948
+ }
949
+ if (observers.size === 0) return;
950
+ silence(() => {
951
+ for (const callback of [...observers.keys()]) {
952
+ if (!observers.has(callback)) continue;
953
+ callback(newValue, eventSource);
954
+ }
955
+ });
956
+ };
957
+ const attachProxyHandle = (value2) => {
958
+ let proxyHandle = value2[srefSymbol];
959
+ if (!proxyHandle) value2[srefSymbol] = proxyHandle = /* @__PURE__ */ new Set();
960
+ proxyHandle.add(srefFunction);
961
+ };
962
+ const srefFunction = (...args) => {
963
+ if (!(2 in args)) {
964
+ let newValue = args[0];
965
+ const eventSource = args[1];
966
+ if (0 in args) {
967
+ if (refObj._value === newValue) return newValue;
968
+ if (isRef(newValue)) {
969
+ newValue = newValue();
970
+ if (refObj._value === newValue) return newValue;
971
+ }
972
+ if (createProxy2(newValue)) attachProxyHandle(newValue);
973
+ refObj._value = newValue;
974
+ if (refObj.auto) {
975
+ trigger2(newValue, eventSource);
976
+ }
977
+ return refObj._value;
978
+ } else {
979
+ collectRef(srefFunction);
980
+ }
981
+ return refObj._value;
982
+ }
983
+ const operation = args[2];
984
+ switch (operation) {
985
+ case 0 /* observe */: {
986
+ const observer = args[3];
987
+ if (!observer) return () => {
988
+ };
989
+ const removeObserver = (observer2) => {
990
+ observers.delete(observer2);
991
+ };
992
+ observers.add(observer);
993
+ return () => {
994
+ removeObserver(observer);
995
+ };
996
+ }
997
+ case 1 /* trigger */: {
998
+ const eventSource = args[1];
999
+ const value2 = refObj._value;
1000
+ trigger2(value2, eventSource);
1001
+ break;
1002
+ }
1003
+ case 2 /* observerCount */: {
1004
+ return observers.size;
1005
+ }
1006
+ case 3 /* pause */: {
1007
+ refObj.auto = false;
1008
+ break;
1009
+ }
1010
+ case 4 /* resume */: {
1011
+ refObj.auto = true;
1012
+ }
1013
+ }
1014
+ return refObj._value;
1015
+ };
1016
+ srefFunction[srefSymbol] = 1;
1017
+ defineRefValue(srefFunction, false);
1018
+ if (isProxy) attachProxyHandle(value);
1019
+ return srefFunction;
1020
+ };
1021
+
1022
+ // src/reactivity/ref.ts
1023
+ var ref = (value) => {
1024
+ if (isRaw(value)) return value;
1025
+ let result;
1026
+ if (isRef(value)) {
1027
+ result = value;
1028
+ value = result();
1029
+ } else {
1030
+ result = sref(value);
1031
+ }
1032
+ if (value instanceof Node || value instanceof Date || value instanceof RegExp || value instanceof Promise || value instanceof Error)
1033
+ return result;
1034
+ result[refSymbol] = 1;
1035
+ if (isArray(value)) {
1036
+ const len = value.length;
1037
+ for (let i = 0; i < len; ++i) {
1038
+ const item = value[i];
1039
+ if (isDeepRef(item)) continue;
1040
+ value[i] = ref(item);
1041
+ }
1042
+ return result;
1043
+ }
1044
+ if (!isObject(value)) return result;
1045
+ for (const item of Object.entries(value)) {
1046
+ const val = item[1];
1047
+ if (isDeepRef(val)) continue;
1048
+ const key = item[0];
1049
+ if (isSymbol(key)) continue;
1050
+ value[key] = null;
1051
+ value[key] = ref(val);
1052
+ }
1053
+ return result;
1054
+ };
1055
+
758
1056
  // src/directives/single-prop.ts
1057
+ var modelBridgeSymbol = Symbol("modelBridge");
1058
+ var isModelBridge = (value) => !!(value == null ? void 0 : value[modelBridgeSymbol]);
1059
+ var markModelBridge = (value) => {
1060
+ ;
1061
+ value[modelBridgeSymbol] = 1;
1062
+ };
1063
+ var createModelBridge = (source) => {
1064
+ const bridge = ref(source());
1065
+ markModelBridge(bridge);
1066
+ return bridge;
1067
+ };
759
1068
  var singlePropDirective = {
760
1069
  collectRefObj: true,
761
1070
  onBind: (_, parseResult, _expr, option, _dynamicOption, _flags) => {
762
1071
  if (!option) return () => {
763
1072
  };
764
1073
  const key = camelize(option);
1074
+ let currentSource;
1075
+ let bridge;
765
1076
  let stopEntangle = () => {
766
1077
  };
1078
+ const resetSync = () => {
1079
+ stopEntangle();
1080
+ stopEntangle = () => {
1081
+ };
1082
+ currentSource = void 0;
1083
+ bridge = void 0;
1084
+ };
1085
+ const clearEntangle = () => {
1086
+ stopEntangle();
1087
+ stopEntangle = () => {
1088
+ };
1089
+ };
1090
+ const syncRefs = (source, target) => {
1091
+ if (currentSource === source) return;
1092
+ clearEntangle();
1093
+ stopEntangle = entangle(source, target);
1094
+ currentSource = source;
1095
+ };
767
1096
  const stopObserving = observe(
768
1097
  parseResult.value,
769
1098
  () => {
@@ -771,24 +1100,31 @@ var singlePropDirective = {
771
1100
  const value = (_a = parseResult.refs[0]) != null ? _a : parseResult.value()[0];
772
1101
  const ctx = parseResult.context;
773
1102
  const ctxKey = ctx[key];
774
- if (ctxKey === value) return;
775
- if (isRef(value)) {
1103
+ if (!isRef(value)) {
1104
+ if (bridge && ctxKey === bridge) {
1105
+ bridge(value);
1106
+ return;
1107
+ }
1108
+ resetSync();
776
1109
  if (isRef(ctxKey)) {
777
- stopEntangle();
778
- stopEntangle = entangle(value, ctxKey);
1110
+ ctxKey(value);
779
1111
  return;
780
1112
  }
781
1113
  ctx[key] = value;
782
1114
  return;
783
1115
  }
784
- stopEntangle();
785
- stopEntangle = () => {
786
- };
787
- if (isRef(ctxKey)) {
788
- ctxKey(value);
1116
+ if (isModelBridge(value)) {
1117
+ if (ctxKey === value) return;
1118
+ if (isRef(ctxKey)) {
1119
+ syncRefs(value, ctxKey);
1120
+ } else {
1121
+ ctx[key] = value;
1122
+ }
789
1123
  return;
790
1124
  }
791
- ctx[key] = value;
1125
+ if (!bridge) bridge = createModelBridge(value);
1126
+ ctx[key] = bridge;
1127
+ syncRefs(value, bridge);
792
1128
  },
793
1129
  true
794
1130
  );
@@ -1039,486 +1375,227 @@ var ComponentBinder = class {
1039
1375
  } else {
1040
1376
  inheritor.setAttribute(
1041
1377
  normalizeAttributeName(attrName, binder.__config),
1042
- value
1043
- );
1044
- }
1045
- }
1046
- };
1047
- const clearUnusedAttributes = () => {
1048
- for (const attrName of component.getAttributeNames()) {
1049
- if (!attrName.startsWith("@") && !attrName.startsWith(binder.__config.__builtInNames.on))
1050
- component.removeAttribute(attrName);
1051
- }
1052
- };
1053
- const bindComponent = () => {
1054
- transferAttributesToTheComponentChild();
1055
- clearUnusedAttributes();
1056
- parser.__push(componentCtx);
1057
- binder.__bindAttributes(component, false);
1058
- componentCtx.$emit = head.emit;
1059
- bindChildNodes(binder, childNodes);
1060
- addUnbinder(component, () => {
1061
- callUnmounted(componentCtx);
1062
- });
1063
- addUnbinder(startOfComponent, () => {
1064
- unbind(component);
1065
- });
1066
- callMounted(componentCtx);
1067
- };
1068
- parser.__scoped(capturedContext, bindComponent);
1069
- }
1070
- }
1071
- };
1072
-
1073
- // src/bind/DirectiveCollector.ts
1074
- var DirectiveElement = class {
1075
- constructor(name2) {
1076
- __publicField(this, "__name");
1077
- // r-on @click @submit r-on:click.prevent @submit.prevent @[event-name].self.camel :src :className.prop .class-name.camel r-if r-for key
1078
- /** Contains: `['@', 'submit'], ['r-on', 'click'], ['\\@', '[dynamicKey]']` */
1079
- __publicField(this, "__terms", []);
1080
- /** Contains directive flags. ['camel', 'prevent',...] */
1081
- __publicField(this, "__flags", []);
1082
- __publicField(this, "__elements", []);
1083
- this.__name = name2;
1084
- this.__parse();
1085
- }
1086
- __parse() {
1087
- let name2 = this.__name;
1088
- const isPropShortcut = name2.startsWith(".");
1089
- if (isPropShortcut) name2 = ":" + name2.slice(1);
1090
- const firstFlagIndex = name2.indexOf(".");
1091
- const terms = this.__terms = (firstFlagIndex < 0 ? name2 : name2.substring(0, firstFlagIndex)).split(/[:@]/);
1092
- if (isNullOrWhitespace(terms[0])) terms[0] = isPropShortcut ? "." : name2[0];
1093
- if (firstFlagIndex >= 0) {
1094
- const flags = this.__flags = name2.slice(firstFlagIndex + 1).split(".");
1095
- if (flags.includes("camel")) {
1096
- const index = terms.length - 1;
1097
- terms[index] = camelize(terms[index]);
1098
- }
1099
- if (flags.includes("prop")) {
1100
- terms[0] = ".";
1101
- }
1102
- }
1103
- }
1104
- };
1105
- var DirectiveCollector = class {
1106
- constructor(binder) {
1107
- __publicField(this, "__binder");
1108
- __publicField(this, "__prefixes");
1109
- this.__binder = binder;
1110
- this.__prefixes = binder.__config.__getPrefixes();
1111
- }
1112
- __collect(element, isRecursive) {
1113
- const map = /* @__PURE__ */ new Map();
1114
- if (!isHTMLElement(element)) return map;
1115
- const prefixes2 = this.__prefixes;
1116
- const processNode = (node) => {
1117
- const names = node.getAttributeNames().filter((name2) => prefixes2.some((p) => name2.startsWith(p)));
1118
- for (const name2 of names) {
1119
- if (!map.has(name2)) map.set(name2, new DirectiveElement(name2));
1120
- const item = map.get(name2);
1121
- item.__elements.push(node);
1122
- }
1123
- };
1124
- processNode(element);
1125
- if (!isRecursive) return map;
1126
- const nodes = element.querySelectorAll("*");
1127
- for (const node of nodes) {
1128
- processNode(node);
1129
- }
1130
- return map;
1131
- }
1132
- };
1133
-
1134
- // src/bind/DynamicBinder.ts
1135
- var mount2 = (nodes, parent) => {
1136
- for (const x of nodes) {
1137
- const node = x.cloneNode(true);
1138
- parent.appendChild(node);
1139
- }
1140
- };
1141
- var DynamicBinder = class {
1142
- constructor(binder) {
1143
- __publicField(this, "__binder");
1144
- __publicField(this, "__is");
1145
- __publicField(this, "__isSelector");
1146
- this.__binder = binder;
1147
- this.__is = binder.__config.__builtInNames.is;
1148
- this.__isSelector = toSelector(this.__is) + ", [is]";
1149
- }
1150
- __bindAll(element) {
1151
- const isComponentElement = element.hasAttribute(this.__is);
1152
- const elements = findElements(element, this.__isSelector);
1153
- for (const el of elements) {
1154
- this.__bind(el);
1155
- }
1156
- return isComponentElement;
1157
- }
1158
- __bind(el) {
1159
- let expression = el.getAttribute(this.__is);
1160
- if (!expression) {
1161
- expression = el.getAttribute("is");
1162
- if (!expression) return;
1163
- if (!expression.startsWith("regor:")) {
1164
- if (!expression.startsWith("r-")) return;
1165
- const staticName = expression.slice(2).trim().toLowerCase();
1166
- if (!staticName) return;
1167
- const parent = el.parentNode;
1168
- if (!parent) return;
1169
- const nativeElement = document.createElement(staticName);
1170
- for (const attr of el.getAttributeNames()) {
1171
- if (attr === "is") continue;
1172
- nativeElement.setAttribute(attr, el.getAttribute(attr));
1173
- }
1174
- while (el.firstChild) nativeElement.appendChild(el.firstChild);
1175
- parent.insertBefore(nativeElement, el);
1176
- el.remove();
1177
- this.__binder.__bindDefault(nativeElement);
1178
- return;
1179
- }
1180
- expression = `'${expression.slice(6)}'`;
1181
- el.removeAttribute("is");
1182
- }
1183
- el.removeAttribute(this.__is);
1184
- this.__bindToExpression(el, expression);
1185
- }
1186
- __createRegion(el, expression) {
1187
- const nodes = getNodes(el);
1188
- const parent = el.parentNode;
1189
- const commentBegin = document.createComment(
1190
- `__begin__ dynamic ${expression != null ? expression : ""}`
1191
- );
1192
- parent.insertBefore(commentBegin, el);
1193
- setSwitchOwner(commentBegin, nodes);
1194
- nodes.forEach((x) => {
1195
- removeNode(x);
1196
- });
1197
- el.remove();
1198
- const commentEnd = document.createComment(
1199
- `__end__ dynamic ${expression != null ? expression : ""}`
1200
- );
1201
- parent.insertBefore(commentEnd, commentBegin.nextSibling);
1202
- return {
1203
- nodes,
1204
- parent,
1205
- commentBegin,
1206
- commentEnd
1207
- };
1208
- }
1209
- __bindToExpression(el, expression) {
1210
- const { nodes, parent, commentBegin, commentEnd } = this.__createRegion(
1211
- el,
1212
- ` => ${expression} `
1213
- );
1214
- const parseResult = this.__binder.__parser.__parse(expression);
1215
- const value = parseResult.value;
1216
- const parser = this.__binder.__parser;
1217
- const capturedContext = parser.__capture();
1218
- const mounted = { name: "" };
1219
- const componentChildNodes = isTemplate(el) ? nodes : [...nodes[0].childNodes];
1220
- const refresh = () => {
1221
- parser.__scoped(capturedContext, () => {
1222
- var _a;
1223
- let name2 = value()[0];
1224
- if (isObject(name2)) {
1225
- if (!name2.name) {
1226
- name2 = (_a = Object.entries(parser.__getComponents()).filter(
1227
- (x) => x[1] === name2
1228
- )[0]) == null ? void 0 : _a[0];
1229
- } else {
1230
- name2 = name2.name;
1231
- }
1232
- }
1233
- if (!isString(name2) || isNullOrWhitespace(name2)) {
1234
- unmount(commentBegin, commentEnd);
1235
- return;
1378
+ value
1379
+ );
1380
+ }
1236
1381
  }
1237
- if (mounted.name === name2) return;
1238
- unmount(commentBegin, commentEnd);
1239
- const componentElement = document.createElement(name2);
1240
- for (const attr of el.getAttributeNames()) {
1241
- if (attr === this.__is) continue;
1242
- componentElement.setAttribute(attr, el.getAttribute(attr));
1382
+ };
1383
+ const clearUnusedAttributes = () => {
1384
+ for (const attrName of component.getAttributeNames()) {
1385
+ if (!attrName.startsWith("@") && !attrName.startsWith(binder.__config.__builtInNames.on))
1386
+ component.removeAttribute(attrName);
1243
1387
  }
1244
- mount2(componentChildNodes, componentElement);
1245
- parent.insertBefore(componentElement, commentEnd);
1246
- this.__binder.__bindDefault(componentElement);
1247
- mounted.name = name2;
1248
- });
1249
- };
1250
- const stopObserverList = [];
1251
- const unbinder = () => {
1252
- parseResult.stop();
1253
- for (const stopObserver of stopObserverList) {
1254
- stopObserver();
1255
- }
1256
- stopObserverList.length = 0;
1257
- };
1258
- addUnbinder(commentBegin, unbinder);
1259
- refresh();
1260
- const stopObserving = observe(value, refresh);
1261
- stopObserverList.push(stopObserving);
1262
- }
1263
- };
1264
-
1265
- // src/computed/watchEffect.ts
1266
- var collectedRefs = [];
1267
- var collectRef = (ref2) => {
1268
- var _a;
1269
- if (collectedRefs.length === 0) return;
1270
- (_a = collectedRefs[collectedRefs.length - 1]) == null ? void 0 : _a.add(ref2);
1271
- };
1272
- var watchEffect = (effect) => {
1273
- if (!effect) return () => {
1274
- };
1275
- const terminator = { stop: () => {
1276
- } };
1277
- watchEffectInternal(effect, terminator);
1278
- onUnmounted(() => terminator.stop(), true);
1279
- return terminator.stop;
1280
- };
1281
- var watchEffectInternal = (effect, terminator) => {
1282
- if (!effect) return;
1283
- let stopObservingList = [];
1284
- let isStopped = false;
1285
- const stopWatch = () => {
1286
- for (const stop of stopObservingList) stop();
1287
- stopObservingList = [];
1288
- isStopped = true;
1289
- };
1290
- terminator.stop = stopWatch;
1291
- try {
1292
- const set = /* @__PURE__ */ new Set();
1293
- collectedRefs.push(set);
1294
- effect((onCleanup) => stopObservingList.push(onCleanup));
1295
- if (isStopped) return;
1296
- for (const r of [...set]) {
1297
- const stopObserving = observe(r, () => {
1298
- stopWatch();
1299
- watchEffect(effect);
1300
- });
1301
- stopObservingList.push(stopObserving);
1388
+ };
1389
+ const bindComponent = () => {
1390
+ transferAttributesToTheComponentChild();
1391
+ clearUnusedAttributes();
1392
+ parser.__push(componentCtx);
1393
+ binder.__bindAttributes(component, false);
1394
+ componentCtx.$emit = head.emit;
1395
+ bindChildNodes(binder, childNodes);
1396
+ addUnbinder(component, () => {
1397
+ callUnmounted(componentCtx);
1398
+ });
1399
+ addUnbinder(startOfComponent, () => {
1400
+ unbind(component);
1401
+ });
1402
+ callMounted(componentCtx);
1403
+ };
1404
+ parser.__scoped(capturedContext, bindComponent);
1302
1405
  }
1303
- } finally {
1304
- collectedRefs.pop();
1305
- }
1306
- };
1307
- var silence = (action) => {
1308
- const len = collectedRefs.length;
1309
- const hasPush = len > 0 && collectedRefs[len - 1];
1310
- try {
1311
- if (hasPush) collectedRefs.push(null);
1312
- return action();
1313
- } finally {
1314
- if (hasPush) collectedRefs.pop();
1315
- }
1316
- };
1317
- var collectRefs = (action) => {
1318
- try {
1319
- const set = /* @__PURE__ */ new Set();
1320
- collectedRefs.push(set);
1321
- const result = action();
1322
- return { value: result, refs: [...set] };
1323
- } finally {
1324
- collectedRefs.pop();
1325
1406
  }
1326
1407
  };
1327
1408
 
1328
- // src/misc/isRaw.ts
1329
- var isRaw = (value) => {
1330
- return !!value && value[rawSymbol] === 1;
1331
- };
1332
-
1333
- // src/reactivity/trigger.ts
1334
- var trigger = (source, eventSource, isRecursive) => {
1335
- if (!isRef(source)) return;
1336
- const srefImpl = source;
1337
- srefImpl(void 0, eventSource, 1 /* trigger */);
1338
- if (!isRecursive) return;
1339
- const obj = srefImpl();
1340
- if (!obj) return;
1341
- if (isArray(obj) || isSet(obj)) {
1342
- for (const el of obj) {
1343
- trigger(el, eventSource, true);
1344
- }
1345
- } else if (isMap(obj)) {
1346
- for (const el of obj) {
1347
- trigger(el[0], eventSource, true);
1348
- trigger(el[1], eventSource, true);
1349
- }
1409
+ // src/bind/DirectiveCollector.ts
1410
+ var DirectiveElement = class {
1411
+ constructor(name2) {
1412
+ __publicField(this, "__name");
1413
+ // r-on @click @submit r-on:click.prevent @submit.prevent @[event-name].self.camel :src :className.prop .class-name.camel r-if r-for key
1414
+ /** Contains: `['@', 'submit'], ['r-on', 'click'], ['\\@', '[dynamicKey]']` */
1415
+ __publicField(this, "__terms", []);
1416
+ /** Contains directive flags. ['camel', 'prevent',...] */
1417
+ __publicField(this, "__flags", []);
1418
+ __publicField(this, "__elements", []);
1419
+ this.__name = name2;
1420
+ this.__parse();
1350
1421
  }
1351
- if (isObject(obj)) {
1352
- for (const k in obj) {
1353
- trigger(obj[k], eventSource, true);
1422
+ __parse() {
1423
+ let name2 = this.__name;
1424
+ const isPropShortcut = name2.startsWith(".");
1425
+ if (isPropShortcut) name2 = ":" + name2.slice(1);
1426
+ const firstFlagIndex = name2.indexOf(".");
1427
+ const terms = this.__terms = (firstFlagIndex < 0 ? name2 : name2.substring(0, firstFlagIndex)).split(/[:@]/);
1428
+ if (isNullOrWhitespace(terms[0])) terms[0] = isPropShortcut ? "." : name2[0];
1429
+ if (firstFlagIndex >= 0) {
1430
+ const flags = this.__flags = name2.slice(firstFlagIndex + 1).split(".");
1431
+ if (flags.includes("camel")) {
1432
+ const index = terms.length - 1;
1433
+ terms[index] = camelize(terms[index]);
1434
+ }
1435
+ if (flags.includes("prop")) {
1436
+ terms[0] = ".";
1437
+ }
1354
1438
  }
1355
1439
  }
1356
1440
  };
1357
-
1358
- // src/proxies/proxy.ts
1359
- function define(obj, key, val) {
1360
- Object.defineProperty(obj, key, {
1361
- value: val,
1362
- enumerable: false,
1363
- writable: true,
1364
- configurable: true
1365
- });
1366
- }
1367
- var createProxy = (originalProto, proxyProto, methodsToPatch4) => {
1368
- methodsToPatch4.forEach(function(method) {
1369
- const original = originalProto[method];
1370
- define(proxyProto, method, function mutator(...args) {
1371
- const result = original.apply(this, args);
1372
- const subscribers = this[srefSymbol];
1373
- for (const subscriber of subscribers) trigger(subscriber);
1374
- return result;
1375
- });
1376
- });
1377
- };
1378
- var setToStringTag = (proxyProto, tag) => {
1379
- Object.defineProperty(proxyProto, Symbol.toStringTag, {
1380
- value: tag,
1381
- writable: false,
1382
- enumerable: false,
1383
- configurable: true
1384
- });
1385
- };
1386
-
1387
- // src/proxies/array-ref.ts
1388
- var arrayProto = Array.prototype;
1389
- var proxyArrayProto = Object.create(arrayProto);
1390
- var methodsToPatch = [
1391
- "push",
1392
- "pop",
1393
- "shift",
1394
- "unshift",
1395
- "splice",
1396
- "sort",
1397
- "reverse"
1398
- ];
1399
- createProxy(arrayProto, proxyArrayProto, methodsToPatch);
1400
-
1401
- // src/proxies/map-ref.ts
1402
- var mapProto = Map.prototype;
1403
- var proxyMapProto = Object.create(mapProto);
1404
- var methodsToPatch2 = ["set", "clear", "delete"];
1405
- setToStringTag(proxyMapProto, "Map");
1406
- createProxy(mapProto, proxyMapProto, methodsToPatch2);
1407
-
1408
- // src/proxies/set-ref.ts
1409
- var setProto = Set.prototype;
1410
- var proxySetProto = Object.create(setProto);
1411
- var methodsToPatch3 = ["add", "clear", "delete"];
1412
- setToStringTag(proxySetProto, "Set");
1413
- createProxy(setProto, proxySetProto, methodsToPatch3);
1414
-
1415
- // src/reactivity/sref.ts
1416
- var batchCollector = {};
1417
- var sref = (value) => {
1418
- if (isRef(value) || isRaw(value)) return value;
1419
- const refObj = {
1420
- auto: true,
1421
- _value: value
1422
- };
1423
- const createProxy2 = (value2) => {
1424
- if (!isObject(value2)) return false;
1425
- if (srefSymbol in value2) return true;
1426
- const isAnArray = isArray(value2);
1427
- if (isAnArray) {
1428
- Object.setPrototypeOf(value2, proxyArrayProto);
1429
- return true;
1430
- }
1431
- const isASet = isSet(value2);
1432
- if (isASet) {
1433
- Object.setPrototypeOf(value2, proxySetProto);
1434
- return true;
1435
- }
1436
- const isAMap = isMap(value2);
1437
- if (isAMap) {
1438
- Object.setPrototypeOf(value2, proxyMapProto);
1439
- return true;
1441
+ var DirectiveCollector = class {
1442
+ constructor(binder) {
1443
+ __publicField(this, "__binder");
1444
+ __publicField(this, "__prefixes");
1445
+ this.__binder = binder;
1446
+ this.__prefixes = binder.__config.__getPrefixes();
1447
+ }
1448
+ __collect(element, isRecursive) {
1449
+ const map = /* @__PURE__ */ new Map();
1450
+ if (!isHTMLElement(element)) return map;
1451
+ const prefixes2 = this.__prefixes;
1452
+ const processNode = (node) => {
1453
+ const names = node.getAttributeNames().filter((name2) => prefixes2.some((p) => name2.startsWith(p)));
1454
+ for (const name2 of names) {
1455
+ if (!map.has(name2)) map.set(name2, new DirectiveElement(name2));
1456
+ const item = map.get(name2);
1457
+ item.__elements.push(node);
1458
+ }
1459
+ };
1460
+ processNode(element);
1461
+ if (!isRecursive) return map;
1462
+ const nodes = element.querySelectorAll("*");
1463
+ for (const node of nodes) {
1464
+ processNode(node);
1440
1465
  }
1441
- return false;
1442
- };
1443
- const isProxy = createProxy2(value);
1444
- const observers = /* @__PURE__ */ new Set();
1445
- const trigger2 = (newValue, eventSource) => {
1446
- if (batchCollector.stack && batchCollector.stack.length) {
1447
- const current = batchCollector.stack[batchCollector.stack.length - 1];
1448
- current.add(srefFunction);
1449
- return;
1466
+ return map;
1467
+ }
1468
+ };
1469
+
1470
+ // src/bind/DynamicBinder.ts
1471
+ var mount2 = (nodes, parent) => {
1472
+ for (const x of nodes) {
1473
+ const node = x.cloneNode(true);
1474
+ parent.appendChild(node);
1475
+ }
1476
+ };
1477
+ var DynamicBinder = class {
1478
+ constructor(binder) {
1479
+ __publicField(this, "__binder");
1480
+ __publicField(this, "__is");
1481
+ __publicField(this, "__isSelector");
1482
+ this.__binder = binder;
1483
+ this.__is = binder.__config.__builtInNames.is;
1484
+ this.__isSelector = toSelector(this.__is) + ", [is]";
1485
+ }
1486
+ __bindAll(element) {
1487
+ const isComponentElement = element.hasAttribute(this.__is);
1488
+ const elements = findElements(element, this.__isSelector);
1489
+ for (const el of elements) {
1490
+ this.__bind(el);
1450
1491
  }
1451
- if (observers.size === 0) return;
1452
- silence(() => {
1453
- for (const callback of [...observers.keys()]) {
1454
- if (!observers.has(callback)) continue;
1455
- callback(newValue, eventSource);
1492
+ return isComponentElement;
1493
+ }
1494
+ __bind(el) {
1495
+ let expression = el.getAttribute(this.__is);
1496
+ if (!expression) {
1497
+ expression = el.getAttribute("is");
1498
+ if (!expression) return;
1499
+ if (!expression.startsWith("regor:")) {
1500
+ if (!expression.startsWith("r-")) return;
1501
+ const staticName = expression.slice(2).trim().toLowerCase();
1502
+ if (!staticName) return;
1503
+ const parent = el.parentNode;
1504
+ if (!parent) return;
1505
+ const nativeElement = document.createElement(staticName);
1506
+ for (const attr of el.getAttributeNames()) {
1507
+ if (attr === "is") continue;
1508
+ nativeElement.setAttribute(attr, el.getAttribute(attr));
1509
+ }
1510
+ while (el.firstChild) nativeElement.appendChild(el.firstChild);
1511
+ parent.insertBefore(nativeElement, el);
1512
+ el.remove();
1513
+ this.__binder.__bindDefault(nativeElement);
1514
+ return;
1456
1515
  }
1516
+ expression = `'${expression.slice(6)}'`;
1517
+ el.removeAttribute("is");
1518
+ }
1519
+ el.removeAttribute(this.__is);
1520
+ this.__bindToExpression(el, expression);
1521
+ }
1522
+ __createRegion(el, expression) {
1523
+ const nodes = getNodes(el);
1524
+ const parent = el.parentNode;
1525
+ const commentBegin = document.createComment(
1526
+ `__begin__ dynamic ${expression != null ? expression : ""}`
1527
+ );
1528
+ parent.insertBefore(commentBegin, el);
1529
+ setSwitchOwner(commentBegin, nodes);
1530
+ nodes.forEach((x) => {
1531
+ removeNode(x);
1457
1532
  });
1458
- };
1459
- const attachProxyHandle = (value2) => {
1460
- let proxyHandle = value2[srefSymbol];
1461
- if (!proxyHandle) value2[srefSymbol] = proxyHandle = /* @__PURE__ */ new Set();
1462
- proxyHandle.add(srefFunction);
1463
- };
1464
- const srefFunction = (...args) => {
1465
- if (!(2 in args)) {
1466
- let newValue = args[0];
1467
- const eventSource = args[1];
1468
- if (0 in args) {
1469
- if (refObj._value === newValue) return newValue;
1470
- if (isRef(newValue)) {
1471
- newValue = newValue();
1472
- if (refObj._value === newValue) return newValue;
1533
+ el.remove();
1534
+ const commentEnd = document.createComment(
1535
+ `__end__ dynamic ${expression != null ? expression : ""}`
1536
+ );
1537
+ parent.insertBefore(commentEnd, commentBegin.nextSibling);
1538
+ return {
1539
+ nodes,
1540
+ parent,
1541
+ commentBegin,
1542
+ commentEnd
1543
+ };
1544
+ }
1545
+ __bindToExpression(el, expression) {
1546
+ const { nodes, parent, commentBegin, commentEnd } = this.__createRegion(
1547
+ el,
1548
+ ` => ${expression} `
1549
+ );
1550
+ const parseResult = this.__binder.__parser.__parse(expression);
1551
+ const value = parseResult.value;
1552
+ const parser = this.__binder.__parser;
1553
+ const capturedContext = parser.__capture();
1554
+ const mounted = { name: "" };
1555
+ const componentChildNodes = isTemplate(el) ? nodes : [...nodes[0].childNodes];
1556
+ const refresh = () => {
1557
+ parser.__scoped(capturedContext, () => {
1558
+ var _a;
1559
+ let name2 = value()[0];
1560
+ if (isObject(name2)) {
1561
+ if (!name2.name) {
1562
+ name2 = (_a = Object.entries(parser.__getComponents()).filter(
1563
+ (x) => x[1] === name2
1564
+ )[0]) == null ? void 0 : _a[0];
1565
+ } else {
1566
+ name2 = name2.name;
1567
+ }
1473
1568
  }
1474
- if (createProxy2(newValue)) attachProxyHandle(newValue);
1475
- refObj._value = newValue;
1476
- if (refObj.auto) {
1477
- trigger2(newValue, eventSource);
1569
+ if (!isString(name2) || isNullOrWhitespace(name2)) {
1570
+ unmount(commentBegin, commentEnd);
1571
+ return;
1478
1572
  }
1479
- return refObj._value;
1480
- } else {
1481
- collectRef(srefFunction);
1482
- }
1483
- return refObj._value;
1484
- }
1485
- const operation = args[2];
1486
- switch (operation) {
1487
- case 0 /* observe */: {
1488
- const observer = args[3];
1489
- if (!observer) return () => {
1490
- };
1491
- const removeObserver = (observer2) => {
1492
- observers.delete(observer2);
1493
- };
1494
- observers.add(observer);
1495
- return () => {
1496
- removeObserver(observer);
1497
- };
1498
- }
1499
- case 1 /* trigger */: {
1500
- const eventSource = args[1];
1501
- const value2 = refObj._value;
1502
- trigger2(value2, eventSource);
1503
- break;
1504
- }
1505
- case 2 /* observerCount */: {
1506
- return observers.size;
1507
- }
1508
- case 3 /* pause */: {
1509
- refObj.auto = false;
1510
- break;
1511
- }
1512
- case 4 /* resume */: {
1513
- refObj.auto = true;
1573
+ if (mounted.name === name2) return;
1574
+ unmount(commentBegin, commentEnd);
1575
+ const componentElement = document.createElement(name2);
1576
+ for (const attr of el.getAttributeNames()) {
1577
+ if (attr === this.__is) continue;
1578
+ componentElement.setAttribute(attr, el.getAttribute(attr));
1579
+ }
1580
+ mount2(componentChildNodes, componentElement);
1581
+ parent.insertBefore(componentElement, commentEnd);
1582
+ this.__binder.__bindDefault(componentElement);
1583
+ mounted.name = name2;
1584
+ });
1585
+ };
1586
+ const stopObserverList = [];
1587
+ const unbinder = () => {
1588
+ parseResult.stop();
1589
+ for (const stopObserver of stopObserverList) {
1590
+ stopObserver();
1514
1591
  }
1515
- }
1516
- return refObj._value;
1517
- };
1518
- srefFunction[srefSymbol] = 1;
1519
- defineRefValue(srefFunction, false);
1520
- if (isProxy) attachProxyHandle(value);
1521
- return srefFunction;
1592
+ stopObserverList.length = 0;
1593
+ };
1594
+ addUnbinder(commentBegin, unbinder);
1595
+ refresh();
1596
+ const stopObserving = observe(value, refresh);
1597
+ stopObserverList.push(stopObserving);
1598
+ }
1522
1599
  };
1523
1600
 
1524
1601
  // src/reactivity/unref.ts
@@ -2976,45 +3053,6 @@ var valueDirective = {
2976
3053
  }
2977
3054
  };
2978
3055
 
2979
- // src/reactivity/isDeepRef.ts
2980
- var isDeepRef = (value) => {
2981
- return (value == null ? void 0 : value[refSymbol]) === 1;
2982
- };
2983
-
2984
- // src/reactivity/ref.ts
2985
- var ref = (value) => {
2986
- if (isRaw(value)) return value;
2987
- let result;
2988
- if (isRef(value)) {
2989
- result = value;
2990
- value = result();
2991
- } else {
2992
- result = sref(value);
2993
- }
2994
- if (value instanceof Node || value instanceof Date || value instanceof RegExp || value instanceof Promise || value instanceof Error)
2995
- return result;
2996
- result[refSymbol] = 1;
2997
- if (isArray(value)) {
2998
- const len = value.length;
2999
- for (let i = 0; i < len; ++i) {
3000
- const item = value[i];
3001
- if (isDeepRef(item)) continue;
3002
- value[i] = ref(item);
3003
- }
3004
- return result;
3005
- }
3006
- if (!isObject(value)) return result;
3007
- for (const item of Object.entries(value)) {
3008
- const val = item[1];
3009
- if (isDeepRef(val)) continue;
3010
- const key = item[0];
3011
- if (isSymbol(key)) continue;
3012
- value[key] = null;
3013
- value[key] = ref(val);
3014
- }
3015
- return result;
3016
- };
3017
-
3018
3056
  // src/app/RegorConfig.ts
3019
3057
  var _RegorConfig = class _RegorConfig {
3020
3058
  constructor(globalContext) {