regor 1.7.0 → 1.7.1

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.
@@ -1230,6 +1230,132 @@ var Regor = (() => {
1230
1230
  return scopeSymbol2 in value;
1231
1231
  };
1232
1232
 
1233
+ // src/reactivity/unref.ts
1234
+ var unref = (value) => {
1235
+ const anyValue = value;
1236
+ return anyValue != null && anyValue[srefSymbol] > 0 ? anyValue() : anyValue;
1237
+ };
1238
+
1239
+ // src/directives/attr.ts
1240
+ var xlinkNS = "http://www.w3.org/1999/xlink";
1241
+ var booleanAttributes = {
1242
+ itemscope: 2,
1243
+ allowfullscreen: 2,
1244
+ formnovalidate: 2,
1245
+ ismap: 2,
1246
+ nomodule: 2,
1247
+ novalidate: 2,
1248
+ readonly: 2,
1249
+ async: 1,
1250
+ autofocus: 1,
1251
+ autoplay: 1,
1252
+ controls: 1,
1253
+ default: 1,
1254
+ defer: 1,
1255
+ disabled: 1,
1256
+ hidden: 1,
1257
+ inert: 1,
1258
+ loop: 1,
1259
+ open: 1,
1260
+ required: 1,
1261
+ reversed: 1,
1262
+ scoped: 1,
1263
+ seamless: 1,
1264
+ checked: 1,
1265
+ muted: 1,
1266
+ multiple: 1,
1267
+ selected: 1
1268
+ };
1269
+ var updateAttr = (el, values, previousValues, option, previousOption, flags) => {
1270
+ var _a;
1271
+ if (option) {
1272
+ option = unref(option);
1273
+ if (flags && flags.includes("camel")) option = camelize(option);
1274
+ patchAttr(
1275
+ el,
1276
+ option,
1277
+ unref(values[0]),
1278
+ unref(previousOption)
1279
+ );
1280
+ return;
1281
+ }
1282
+ const len = values.length;
1283
+ for (let i = 0; i < len; ++i) {
1284
+ const next = values[i];
1285
+ if (isArray(next)) {
1286
+ const previousKey = unref((_a = previousValues == null ? void 0 : previousValues[i]) == null ? void 0 : _a[0]);
1287
+ const key = unref(next[0]);
1288
+ const value = unref(next[1]);
1289
+ patchAttr(el, key, value, previousKey);
1290
+ } else if (isObject(next)) {
1291
+ for (const item of Object.entries(next)) {
1292
+ const key = item[0];
1293
+ const value = unref(item[1]);
1294
+ const p = unref(previousValues == null ? void 0 : previousValues[i]);
1295
+ const previousKey = p && key in p ? key : void 0;
1296
+ patchAttr(el, key, value, previousKey);
1297
+ }
1298
+ } else {
1299
+ const previousKey = unref(previousValues == null ? void 0 : previousValues[i]);
1300
+ const key = unref(values[i++]);
1301
+ const value = unref(values[i]);
1302
+ patchAttr(el, key, value, previousKey);
1303
+ }
1304
+ }
1305
+ };
1306
+ var attrDirective = {
1307
+ mount: () => ({
1308
+ update: ({ el, values, previousValues, option, previousOption, flags }) => {
1309
+ updateAttr(
1310
+ el,
1311
+ values,
1312
+ previousValues,
1313
+ option,
1314
+ previousOption,
1315
+ flags
1316
+ );
1317
+ }
1318
+ })
1319
+ };
1320
+ var patchAttr = (el, key, value, previousKey) => {
1321
+ if (previousKey && previousKey !== key) {
1322
+ el.removeAttribute(previousKey);
1323
+ }
1324
+ if (isNullOrUndefined(key)) {
1325
+ warning(3 /* KeyIsEmpty */, "r-bind", el);
1326
+ return;
1327
+ }
1328
+ if (!isString(key)) {
1329
+ warning(
1330
+ 6 /* ErrorLog */,
1331
+ `Attribute key is not string at ${el.outerHTML}`,
1332
+ key
1333
+ );
1334
+ return;
1335
+ }
1336
+ if (key.startsWith("xlink:")) {
1337
+ if (isNullOrUndefined(value)) {
1338
+ el.removeAttributeNS(xlinkNS, key.slice(6, key.length));
1339
+ } else {
1340
+ el.setAttributeNS(xlinkNS, key, value);
1341
+ }
1342
+ return;
1343
+ }
1344
+ if (isNullOrUndefined(value)) {
1345
+ el.removeAttribute(key);
1346
+ return;
1347
+ }
1348
+ if (key in booleanAttributes) {
1349
+ if (toBoolean(value)) {
1350
+ el.setAttribute(key, "");
1351
+ } else {
1352
+ el.removeAttribute(key);
1353
+ }
1354
+ return;
1355
+ }
1356
+ el.setAttribute(key, value);
1357
+ };
1358
+
1233
1359
  // src/directives/context.ts
1234
1360
  var contextDirective = {
1235
1361
  collectRefObj: true,
@@ -1968,10 +2094,11 @@ var Regor = (() => {
1968
2094
  } else if (attrName === ":style" || attrName === bindStyleName) {
1969
2095
  mergeBinding(":style", bindStyleName, value);
1970
2096
  } else {
1971
- inheritor.setAttribute(
1972
- normalizeAttributeName(attrName, binder.__config),
1973
- value
2097
+ const normalizedName = normalizeAttributeName(
2098
+ attrName,
2099
+ binder.__config
1974
2100
  );
2101
+ patchAttr(inheritor, normalizedName, value);
1975
2102
  }
1976
2103
  };
1977
2104
  for (const { name, value } of inheritedPropAttrs) {
@@ -2313,12 +2440,6 @@ var Regor = (() => {
2313
2440
  }
2314
2441
  };
2315
2442
 
2316
- // src/reactivity/unref.ts
2317
- var unref = (value) => {
2318
- const anyValue = value;
2319
- return anyValue != null && anyValue[srefSymbol] > 0 ? anyValue() : anyValue;
2320
- };
2321
-
2322
2443
  // src/directives/html.ts
2323
2444
  var updateHtml = (el, values) => {
2324
2445
  const [value, replacer] = values;
@@ -3268,116 +3389,6 @@ var Regor = (() => {
3268
3389
  }
3269
3390
  };
3270
3391
 
3271
- // src/directives/attr.ts
3272
- var xlinkNS = "http://www.w3.org/1999/xlink";
3273
- var booleanAttributes = {
3274
- itemscope: 2,
3275
- allowfullscreen: 2,
3276
- formnovalidate: 2,
3277
- ismap: 2,
3278
- nomodule: 2,
3279
- novalidate: 2,
3280
- readonly: 2,
3281
- async: 1,
3282
- autofocus: 1,
3283
- autoplay: 1,
3284
- controls: 1,
3285
- default: 1,
3286
- defer: 1,
3287
- disabled: 1,
3288
- hidden: 1,
3289
- inert: 1,
3290
- loop: 1,
3291
- open: 1,
3292
- required: 1,
3293
- reversed: 1,
3294
- scoped: 1,
3295
- seamless: 1,
3296
- checked: 1,
3297
- muted: 1,
3298
- multiple: 1,
3299
- selected: 1
3300
- };
3301
- function includeBooleanAttr(value) {
3302
- return !!value || value === "";
3303
- }
3304
- var updateAttr = (el, values, previousValues, option, previousOption, flags) => {
3305
- var _a;
3306
- if (option) {
3307
- if (flags && flags.includes("camel")) option = camelize(option);
3308
- patchAttribute(el, option, values[0], previousOption);
3309
- return;
3310
- }
3311
- const len = values.length;
3312
- for (let i = 0; i < len; ++i) {
3313
- const next = values[i];
3314
- if (isArray(next)) {
3315
- const previousKey = (_a = previousValues == null ? void 0 : previousValues[i]) == null ? void 0 : _a[0];
3316
- const key = next[0];
3317
- const value = next[1];
3318
- patchAttribute(el, key, value, previousKey);
3319
- } else if (isObject(next)) {
3320
- for (const item of Object.entries(next)) {
3321
- const key = item[0];
3322
- const value = item[1];
3323
- const p = previousValues == null ? void 0 : previousValues[i];
3324
- const previousKey = p && key in p ? key : void 0;
3325
- patchAttribute(el, key, value, previousKey);
3326
- }
3327
- } else {
3328
- const previousKey = previousValues == null ? void 0 : previousValues[i];
3329
- const key = values[i++];
3330
- const value = values[i];
3331
- patchAttribute(el, key, value, previousKey);
3332
- }
3333
- }
3334
- };
3335
- var attrDirective = {
3336
- mount: () => ({
3337
- update: ({ el, values, previousValues, option, previousOption, flags }) => {
3338
- updateAttr(
3339
- el,
3340
- values,
3341
- previousValues,
3342
- option,
3343
- previousOption,
3344
- flags
3345
- );
3346
- }
3347
- })
3348
- };
3349
- var patchAttribute = (el, key, value, previousKey) => {
3350
- if (previousKey && previousKey !== key) {
3351
- el.removeAttribute(previousKey);
3352
- }
3353
- if (isNullOrUndefined(key)) {
3354
- warning(3 /* KeyIsEmpty */, "r-bind", el);
3355
- return;
3356
- }
3357
- if (!isString(key)) {
3358
- warning(
3359
- 6 /* ErrorLog */,
3360
- `Attribute key is not string at ${el.outerHTML}`,
3361
- key
3362
- );
3363
- return;
3364
- }
3365
- if (key.startsWith("xlink:")) {
3366
- if (isNullOrUndefined(value)) {
3367
- el.removeAttributeNS(xlinkNS, key.slice(6, key.length));
3368
- } else {
3369
- el.setAttributeNS(xlinkNS, key, value);
3370
- }
3371
- return;
3372
- }
3373
- const isBoolean2 = key in booleanAttributes;
3374
- if (isNullOrUndefined(value) || isBoolean2 && !includeBooleanAttr(value)) {
3375
- el.removeAttribute(key);
3376
- } else {
3377
- el.setAttribute(key, isBoolean2 ? "" : value);
3378
- }
3379
- };
3380
-
3381
3392
  // src/directives/class.ts
3382
3393
  var updateClass = (el, values, previousValues) => {
3383
3394
  const len = values.length;
@@ -4024,7 +4035,7 @@ var Regor = (() => {
4024
4035
  }
4025
4036
  })
4026
4037
  };
4027
- function includeBooleanAttr2(value) {
4038
+ function includeBooleanAttr(value) {
4028
4039
  return !!value || value === "";
4029
4040
  }
4030
4041
  var patchProp = (el, key, value) => {
@@ -4056,7 +4067,7 @@ var Regor = (() => {
4056
4067
  if (value === "" || value == null) {
4057
4068
  const type = typeof el[key];
4058
4069
  if (type === "boolean") {
4059
- value = includeBooleanAttr2(value);
4070
+ value = includeBooleanAttr(value);
4060
4071
  } else if (value == null && type === "string") {
4061
4072
  value = "";
4062
4073
  needRemove = true;