domql 3.7.6 → 3.8.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.
Files changed (2) hide show
  1. package/dist/iife/index.js +131 -4
  2. package/package.json +4 -4
@@ -1335,7 +1335,7 @@ var Domql = (() => {
1335
1335
  const isElement = RE_UPPER.test(key) || RE_DIGITS.test(key) || looksLikeElement(value);
1336
1336
  const isBuiltin = DOMQ_PROPERTIES.has(key);
1337
1337
  if (!isElement && !isBuiltin) {
1338
- obj.props[key] = value;
1338
+ if (!(key in obj.props)) obj.props[key] = value;
1339
1339
  delete obj[key];
1340
1340
  cachedKeys.push(key);
1341
1341
  }
@@ -2605,6 +2605,7 @@ var Domql = (() => {
2605
2605
  const session = await adapter.getSession();
2606
2606
  updateAuth(session?.user || null, session);
2607
2607
  } catch (e) {
2608
+ console.warn("[fetch] Failed to restore auth session:", e.message);
2608
2609
  }
2609
2610
  if (adapter.onAuthStateChange) {
2610
2611
  adapter.onAuthStateChange((event, session) => {
@@ -4399,6 +4400,7 @@ ${element}` : "";
4399
4400
  init_esm();
4400
4401
  function text(param, element, node) {
4401
4402
  let prop = exec(element.props.text || param, element);
4403
+ if (isFunction(prop)) prop = exec(prop, element);
4402
4404
  if (isString(prop) && prop.includes("{{")) {
4403
4405
  prop = element.call("replaceLiteralsWithObjectFields", prop, element.state);
4404
4406
  }
@@ -6434,7 +6436,18 @@ ${element}` : "";
6434
6436
  "onfullscreenchange",
6435
6437
  "onfullscreenerror"
6436
6438
  ];
6439
+ var camelToAttr = (key) => {
6440
+ if (key.startsWith("aria") && key.length > 4 && key.charCodeAt(4) >= 65 && key.charCodeAt(4) <= 90) {
6441
+ return "aria-" + key.charAt(4).toLowerCase() + key.slice(5).replace(/([A-Z])/g, (m) => "-" + m.toLowerCase());
6442
+ }
6443
+ if (key.startsWith("data") && key.length > 4 && key.charCodeAt(4) >= 65 && key.charCodeAt(4) <= 90) {
6444
+ return "data-" + key.charAt(4).toLowerCase() + key.slice(5).replace(/([A-Z])/g, (m) => "-" + m.toLowerCase());
6445
+ }
6446
+ return null;
6447
+ };
6437
6448
  var checkAttributeByTagName = (tag, attribute) => {
6449
+ if (attribute.startsWith("aria-") || attribute.startsWith("data-")) return true;
6450
+ if (camelToAttr(attribute)) return true;
6438
6451
  if (Object.prototype.hasOwnProperty.call(HTML_ATTRIBUTES, tag)) {
6439
6452
  const attributes = HTML_ATTRIBUTES[tag];
6440
6453
  return attributes.includes(attribute) || attributes.includes("default");
@@ -6453,25 +6466,139 @@ ${element}` : "";
6453
6466
  for (const key in props) {
6454
6467
  if (Object.prototype.hasOwnProperty.call(props, key)) {
6455
6468
  if (cssProps && key in cssProps) continue;
6469
+ if (key === "aria" && props[key] && typeof props[key] === "object") {
6470
+ for (const ariaKey in props[key]) {
6471
+ if (isDefined(props[key][ariaKey])) {
6472
+ filteredObject["aria-" + ariaKey] = props[key][ariaKey];
6473
+ }
6474
+ }
6475
+ continue;
6476
+ }
6477
+ if (key === "data" && props[key] && typeof props[key] === "object") {
6478
+ for (const dataKey in props[key]) {
6479
+ if (isDefined(props[key][dataKey])) {
6480
+ const kebab = dataKey.replace(/([A-Z])/g, (m) => "-" + m.toLowerCase());
6481
+ filteredObject["data-" + kebab] = props[key][dataKey];
6482
+ }
6483
+ }
6484
+ continue;
6485
+ }
6456
6486
  const isAttribute = checkAttributeByTagName(tag, key);
6457
6487
  const isEvent = checkEventFunctions(key);
6458
6488
  if (isDefined(props[key]) && (isAttribute || isEvent)) {
6459
- filteredObject[key] = props[key];
6489
+ const attrName = camelToAttr(key) || key;
6490
+ filteredObject[attrName] = props[key];
6460
6491
  }
6461
6492
  }
6462
6493
  }
6463
6494
  return filteredObject;
6464
6495
  };
6496
+ var resolvePropValue = (el, value) => {
6497
+ let resolved = el.call("exec", value, el);
6498
+ if (!resolved) return;
6499
+ if (isString(resolved) && resolved.includes("{{")) {
6500
+ resolved = el.call("replaceLiteralsWithObjectFields", resolved);
6501
+ }
6502
+ return resolved;
6503
+ };
6504
+ var resolveFileSource = (el, value) => {
6505
+ let src = (el.props.preSrc || "") + (resolvePropValue(el, value) || "");
6506
+ if (!src) return;
6507
+ try {
6508
+ new URL(src);
6509
+ return src;
6510
+ } catch (e) {
6511
+ }
6512
+ const { context } = el;
6513
+ if (!context.files) return src;
6514
+ const fileSrc = src.startsWith("/files/") ? src.slice(7) : src;
6515
+ const file = context.files[src] || context.files[fileSrc];
6516
+ if (file && file.content) return file.content.src;
6517
+ return src;
6518
+ };
6519
+ var ATTR_TRANSFORMS = {
6520
+ src: (el) => resolveFileSource(el, el.props.src),
6521
+ href: (el) => resolvePropValue(el, el.props.href),
6522
+ action: (el) => resolvePropValue(el, el.props.action),
6523
+ poster: (el) => resolveFileSource(el, el.props.poster),
6524
+ data: (el) => resolvePropValue(el, el.props.data)
6525
+ };
6526
+ var resolveCase = (caseKey, element) => {
6527
+ const caseFn = element.context?.cases?.[caseKey];
6528
+ if (caseFn === void 0) return void 0;
6529
+ if (isFunction(caseFn)) return caseFn.call(element, element);
6530
+ return !!caseFn;
6531
+ };
6532
+ var evaluateCondition = (prefix, caseKey, element) => {
6533
+ if (prefix === "$") {
6534
+ let result = resolveCase(caseKey, element);
6535
+ if (result === void 0) result = !!element.props?.[caseKey];
6536
+ return result;
6537
+ }
6538
+ let isTruthy = element.props[caseKey] === true || element.state[caseKey] || element[caseKey];
6539
+ if (!isTruthy) {
6540
+ const caseResult = resolveCase(caseKey, element);
6541
+ if (caseResult !== void 0) isTruthy = caseResult;
6542
+ }
6543
+ return prefix === "." ? !!isTruthy : !isTruthy;
6544
+ };
6545
+ var CONDITIONAL_PREFIXES = /* @__PURE__ */ new Set(["$", ".", "!"]);
6546
+ var extractConditionalAttrs = (props, tag, cssProps) => {
6547
+ const result = {};
6548
+ const addConditionalAttr = (attrName, attrVal, prefix, caseKey) => {
6549
+ const capturedVal = attrVal;
6550
+ result[attrName] = (el) => {
6551
+ if (!evaluateCondition(prefix, caseKey, el)) return void 0;
6552
+ return isFunction(capturedVal) ? capturedVal(el) : capturedVal;
6553
+ };
6554
+ };
6555
+ for (const key in props) {
6556
+ const prefix = key.charAt(0);
6557
+ if (!CONDITIONAL_PREFIXES.has(prefix)) continue;
6558
+ const block = props[key];
6559
+ if (!block || typeof block !== "object") continue;
6560
+ const caseKey = key.slice(1);
6561
+ for (const attrKey in block) {
6562
+ if (cssProps && attrKey in cssProps) continue;
6563
+ if (attrKey === "aria" && block[attrKey] && typeof block[attrKey] === "object") {
6564
+ for (const ariaKey in block[attrKey]) {
6565
+ addConditionalAttr("aria-" + ariaKey, block[attrKey][ariaKey], prefix, caseKey);
6566
+ }
6567
+ continue;
6568
+ }
6569
+ if (attrKey === "data" && block[attrKey] && typeof block[attrKey] === "object") {
6570
+ for (const dataKey in block[attrKey]) {
6571
+ const kebab = dataKey.replace(/([A-Z])/g, (m) => "-" + m.toLowerCase());
6572
+ addConditionalAttr("data-" + kebab, block[attrKey][dataKey], prefix, caseKey);
6573
+ }
6574
+ continue;
6575
+ }
6576
+ const isAttribute = checkAttributeByTagName(tag, attrKey);
6577
+ const isEvent = checkEventFunctions(attrKey);
6578
+ if (!isAttribute && !isEvent) continue;
6579
+ const attrName = camelToAttr(attrKey) || attrKey;
6580
+ addConditionalAttr(attrName, block[attrKey], prefix, caseKey);
6581
+ }
6582
+ }
6583
+ return result;
6584
+ };
6465
6585
 
6466
6586
  // ../element/dist/esm/create.js
6467
6587
  var EXCLUDED_ATTRS = /* @__PURE__ */ new Set(["class", "style"]);
6468
6588
  var applyPropsAsAttrs = (element) => {
6469
6589
  const { tag, props, context } = element;
6470
6590
  if (!tag || !props) return;
6471
- const autoAttrs = filterAttributesByTagName(tag, props, context?.cssPropsRegistry);
6591
+ const cssProps = context?.cssPropsRegistry;
6592
+ const autoAttrs = filterAttributesByTagName(tag, props, cssProps);
6593
+ const conditionalAttrs = extractConditionalAttrs(props, tag, cssProps);
6472
6594
  const filtered = {};
6473
6595
  for (const key in autoAttrs) {
6474
- if (!EXCLUDED_ATTRS.has(key)) filtered[key] = autoAttrs[key];
6596
+ if (!EXCLUDED_ATTRS.has(key)) {
6597
+ filtered[key] = ATTR_TRANSFORMS[key] ? ATTR_TRANSFORMS[key] : autoAttrs[key];
6598
+ }
6599
+ }
6600
+ for (const key in conditionalAttrs) {
6601
+ if (!EXCLUDED_ATTRS.has(key)) filtered[key] = conditionalAttrs[key];
6475
6602
  }
6476
6603
  let hasFiltered = false;
6477
6604
  for (const _k in filtered) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "domql",
3
- "version": "3.7.6",
3
+ "version": "3.8.1",
4
4
  "license": "CC-BY-NC-4.0",
5
5
  "type": "module",
6
6
  "module": "./dist/esm/index.js",
@@ -25,9 +25,9 @@
25
25
  "build:iife": "cross-env NODE_ENV=$NODE_ENV esbuild index.js --bundle --target=es2020 --format=iife --global-name=Domql --outfile=dist/iife/index.js --define:process.env.NODE_ENV=process.env.NODE_ENV"
26
26
  },
27
27
  "dependencies": {
28
- "@domql/element": "^3.7.6",
29
- "@domql/state": "^3.7.6",
30
- "@domql/utils": "^3.7.6"
28
+ "@domql/element": "^3.8.1",
29
+ "@domql/state": "^3.8.1",
30
+ "@domql/utils": "^3.8.1"
31
31
  },
32
32
  "gitHead": "9fc1b79b41cdc725ca6b24aec64920a599634681",
33
33
  "browser": "./dist/esm/index.js",