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