regor 1.7.0 → 1.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1163,6 +1163,132 @@ var isScope = (value) => {
1163
1163
  return scopeSymbol2 in value;
1164
1164
  };
1165
1165
 
1166
+ // src/reactivity/unref.ts
1167
+ var unref = (value) => {
1168
+ const anyValue = value;
1169
+ return anyValue != null && anyValue[srefSymbol] > 0 ? anyValue() : anyValue;
1170
+ };
1171
+
1172
+ // src/directives/attr.ts
1173
+ var xlinkNS = "http://www.w3.org/1999/xlink";
1174
+ var booleanAttributes = {
1175
+ itemscope: 2,
1176
+ allowfullscreen: 2,
1177
+ formnovalidate: 2,
1178
+ ismap: 2,
1179
+ nomodule: 2,
1180
+ novalidate: 2,
1181
+ readonly: 2,
1182
+ async: 1,
1183
+ autofocus: 1,
1184
+ autoplay: 1,
1185
+ controls: 1,
1186
+ default: 1,
1187
+ defer: 1,
1188
+ disabled: 1,
1189
+ hidden: 1,
1190
+ inert: 1,
1191
+ loop: 1,
1192
+ open: 1,
1193
+ required: 1,
1194
+ reversed: 1,
1195
+ scoped: 1,
1196
+ seamless: 1,
1197
+ checked: 1,
1198
+ muted: 1,
1199
+ multiple: 1,
1200
+ selected: 1
1201
+ };
1202
+ var updateAttr = (el, values, previousValues, option, previousOption, flags) => {
1203
+ var _a;
1204
+ if (option) {
1205
+ option = unref(option);
1206
+ if (flags && flags.includes("camel")) option = camelize(option);
1207
+ patchAttr(
1208
+ el,
1209
+ option,
1210
+ unref(values[0]),
1211
+ unref(previousOption)
1212
+ );
1213
+ return;
1214
+ }
1215
+ const len = values.length;
1216
+ for (let i = 0; i < len; ++i) {
1217
+ const next = values[i];
1218
+ if (isArray(next)) {
1219
+ const previousKey = unref((_a = previousValues == null ? void 0 : previousValues[i]) == null ? void 0 : _a[0]);
1220
+ const key = unref(next[0]);
1221
+ const value = unref(next[1]);
1222
+ patchAttr(el, key, value, previousKey);
1223
+ } else if (isObject(next)) {
1224
+ for (const item of Object.entries(next)) {
1225
+ const key = item[0];
1226
+ const value = unref(item[1]);
1227
+ const p = unref(previousValues == null ? void 0 : previousValues[i]);
1228
+ const previousKey = p && key in p ? key : void 0;
1229
+ patchAttr(el, key, value, previousKey);
1230
+ }
1231
+ } else {
1232
+ const previousKey = unref(previousValues == null ? void 0 : previousValues[i]);
1233
+ const key = unref(values[i++]);
1234
+ const value = unref(values[i]);
1235
+ patchAttr(el, key, value, previousKey);
1236
+ }
1237
+ }
1238
+ };
1239
+ var attrDirective = {
1240
+ mount: () => ({
1241
+ update: ({ el, values, previousValues, option, previousOption, flags }) => {
1242
+ updateAttr(
1243
+ el,
1244
+ values,
1245
+ previousValues,
1246
+ option,
1247
+ previousOption,
1248
+ flags
1249
+ );
1250
+ }
1251
+ })
1252
+ };
1253
+ var patchAttr = (el, key, value, previousKey) => {
1254
+ if (previousKey && previousKey !== key) {
1255
+ el.removeAttribute(previousKey);
1256
+ }
1257
+ if (isNullOrUndefined(key)) {
1258
+ warning(3 /* KeyIsEmpty */, "r-bind", el);
1259
+ return;
1260
+ }
1261
+ if (!isString(key)) {
1262
+ warning(
1263
+ 6 /* ErrorLog */,
1264
+ `Attribute key is not string at ${el.outerHTML}`,
1265
+ key
1266
+ );
1267
+ return;
1268
+ }
1269
+ if (key.startsWith("xlink:")) {
1270
+ if (isNullOrUndefined(value)) {
1271
+ el.removeAttributeNS(xlinkNS, key.slice(6, key.length));
1272
+ } else {
1273
+ el.setAttributeNS(xlinkNS, key, value);
1274
+ }
1275
+ return;
1276
+ }
1277
+ if (isNullOrUndefined(value)) {
1278
+ el.removeAttribute(key);
1279
+ return;
1280
+ }
1281
+ if (key in booleanAttributes) {
1282
+ if (toBoolean(value)) {
1283
+ el.setAttribute(key, "");
1284
+ } else {
1285
+ el.removeAttribute(key);
1286
+ }
1287
+ return;
1288
+ }
1289
+ el.setAttribute(key, value);
1290
+ };
1291
+
1166
1292
  // src/directives/context.ts
1167
1293
  var contextDirective = {
1168
1294
  collectRefObj: true,
@@ -1901,10 +2027,11 @@ var ComponentBinder = class {
1901
2027
  } else if (attrName === ":style" || attrName === bindStyleName) {
1902
2028
  mergeBinding(":style", bindStyleName, value);
1903
2029
  } else {
1904
- inheritor.setAttribute(
1905
- normalizeAttributeName(attrName, binder.__config),
1906
- value
2030
+ const normalizedName = normalizeAttributeName(
2031
+ attrName,
2032
+ binder.__config
1907
2033
  );
2034
+ patchAttr(inheritor, normalizedName, value);
1908
2035
  }
1909
2036
  };
1910
2037
  for (const { name, value } of inheritedPropAttrs) {
@@ -2246,12 +2373,6 @@ var DynamicBinder = class {
2246
2373
  }
2247
2374
  };
2248
2375
 
2249
- // src/reactivity/unref.ts
2250
- var unref = (value) => {
2251
- const anyValue = value;
2252
- return anyValue != null && anyValue[srefSymbol] > 0 ? anyValue() : anyValue;
2253
- };
2254
-
2255
2376
  // src/directives/html.ts
2256
2377
  var updateHtml = (el, values) => {
2257
2378
  const [value, replacer] = values;
@@ -3201,116 +3322,6 @@ var Binder = class {
3201
3322
  }
3202
3323
  };
3203
3324
 
3204
- // src/directives/attr.ts
3205
- var xlinkNS = "http://www.w3.org/1999/xlink";
3206
- var booleanAttributes = {
3207
- itemscope: 2,
3208
- allowfullscreen: 2,
3209
- formnovalidate: 2,
3210
- ismap: 2,
3211
- nomodule: 2,
3212
- novalidate: 2,
3213
- readonly: 2,
3214
- async: 1,
3215
- autofocus: 1,
3216
- autoplay: 1,
3217
- controls: 1,
3218
- default: 1,
3219
- defer: 1,
3220
- disabled: 1,
3221
- hidden: 1,
3222
- inert: 1,
3223
- loop: 1,
3224
- open: 1,
3225
- required: 1,
3226
- reversed: 1,
3227
- scoped: 1,
3228
- seamless: 1,
3229
- checked: 1,
3230
- muted: 1,
3231
- multiple: 1,
3232
- selected: 1
3233
- };
3234
- function includeBooleanAttr(value) {
3235
- return !!value || value === "";
3236
- }
3237
- var updateAttr = (el, values, previousValues, option, previousOption, flags) => {
3238
- var _a;
3239
- if (option) {
3240
- if (flags && flags.includes("camel")) option = camelize(option);
3241
- patchAttribute(el, option, values[0], previousOption);
3242
- return;
3243
- }
3244
- const len = values.length;
3245
- for (let i = 0; i < len; ++i) {
3246
- const next = values[i];
3247
- if (isArray(next)) {
3248
- const previousKey = (_a = previousValues == null ? void 0 : previousValues[i]) == null ? void 0 : _a[0];
3249
- const key = next[0];
3250
- const value = next[1];
3251
- patchAttribute(el, key, value, previousKey);
3252
- } else if (isObject(next)) {
3253
- for (const item of Object.entries(next)) {
3254
- const key = item[0];
3255
- const value = item[1];
3256
- const p = previousValues == null ? void 0 : previousValues[i];
3257
- const previousKey = p && key in p ? key : void 0;
3258
- patchAttribute(el, key, value, previousKey);
3259
- }
3260
- } else {
3261
- const previousKey = previousValues == null ? void 0 : previousValues[i];
3262
- const key = values[i++];
3263
- const value = values[i];
3264
- patchAttribute(el, key, value, previousKey);
3265
- }
3266
- }
3267
- };
3268
- var attrDirective = {
3269
- mount: () => ({
3270
- update: ({ el, values, previousValues, option, previousOption, flags }) => {
3271
- updateAttr(
3272
- el,
3273
- values,
3274
- previousValues,
3275
- option,
3276
- previousOption,
3277
- flags
3278
- );
3279
- }
3280
- })
3281
- };
3282
- var patchAttribute = (el, key, value, previousKey) => {
3283
- if (previousKey && previousKey !== key) {
3284
- el.removeAttribute(previousKey);
3285
- }
3286
- if (isNullOrUndefined(key)) {
3287
- warning(3 /* KeyIsEmpty */, "r-bind", el);
3288
- return;
3289
- }
3290
- if (!isString(key)) {
3291
- warning(
3292
- 6 /* ErrorLog */,
3293
- `Attribute key is not string at ${el.outerHTML}`,
3294
- key
3295
- );
3296
- return;
3297
- }
3298
- if (key.startsWith("xlink:")) {
3299
- if (isNullOrUndefined(value)) {
3300
- el.removeAttributeNS(xlinkNS, key.slice(6, key.length));
3301
- } else {
3302
- el.setAttributeNS(xlinkNS, key, value);
3303
- }
3304
- return;
3305
- }
3306
- const isBoolean2 = key in booleanAttributes;
3307
- if (isNullOrUndefined(value) || isBoolean2 && !includeBooleanAttr(value)) {
3308
- el.removeAttribute(key);
3309
- } else {
3310
- el.setAttribute(key, isBoolean2 ? "" : value);
3311
- }
3312
- };
3313
-
3314
3325
  // src/directives/class.ts
3315
3326
  var updateClass = (el, values, previousValues) => {
3316
3327
  const len = values.length;
@@ -3957,7 +3968,7 @@ var propDirective = {
3957
3968
  }
3958
3969
  })
3959
3970
  };
3960
- function includeBooleanAttr2(value) {
3971
+ function includeBooleanAttr(value) {
3961
3972
  return !!value || value === "";
3962
3973
  }
3963
3974
  var patchProp = (el, key, value) => {
@@ -3989,7 +4000,7 @@ var patchProp = (el, key, value) => {
3989
4000
  if (value === "" || value == null) {
3990
4001
  const type = typeof el[key];
3991
4002
  if (type === "boolean") {
3992
- value = includeBooleanAttr2(value);
4003
+ value = includeBooleanAttr(value);
3993
4004
  } else if (value == null && type === "string") {
3994
4005
  value = "";
3995
4006
  needRemove = true;
@@ -4155,6 +4166,8 @@ var flatten = (reference) => {
4155
4166
  var flattenContent = (value, weakMap = /* @__PURE__ */ new WeakMap()) => {
4156
4167
  if (!value) return value;
4157
4168
  if (!isObject(value)) return value;
4169
+ if (value instanceof Node || value instanceof Date || value instanceof RegExp || value instanceof Promise || value instanceof Error)
4170
+ return value;
4158
4171
  if (isArray(value)) {
4159
4172
  return value.map(flatten);
4160
4173
  }
@@ -4243,6 +4256,11 @@ function ref(value) {
4243
4256
  return result;
4244
4257
  }
4245
4258
 
4259
+ // src/reactivity/cref.ts
4260
+ function cref(value) {
4261
+ return ref(flatten(value));
4262
+ }
4263
+
4246
4264
  // src/app/RegorConfig.ts
4247
4265
  var _RegorConfig = class _RegorConfig {
4248
4266
  constructor(globalContext) {
@@ -4303,6 +4321,7 @@ var _RegorConfig = class _RegorConfig {
4303
4321
  obj[key] = global[key];
4304
4322
  }
4305
4323
  obj.ref = ref;
4324
+ obj.cref = cref;
4306
4325
  obj.sref = sref;
4307
4326
  obj.flatten = flatten;
4308
4327
  return obj;
@@ -6999,6 +7018,7 @@ export {
6999
7018
  computeRef,
7000
7019
  computed,
7001
7020
  createApp,
7021
+ cref,
7002
7022
  defineComponent,
7003
7023
  drainUnbind,
7004
7024
  endBatch,