@jay-framework/compiler-jay-html 0.23.1 → 0.24.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/index.js +75 -21
  2. package/package.json +9 -9
package/dist/index.js CHANGED
@@ -14377,6 +14377,49 @@ function updateImportRefsWithTemplateConstNames(importTree, templateRefsByOrigin
14377
14377
  importTree?.imported?.repeatedRefsTypeName
14378
14378
  );
14379
14379
  }
14380
+ function graftTemplateOnlyRefs(importTree, templateTree, allImportRefNames) {
14381
+ const knownNames = allImportRefNames ?? collectAllRefNames(importTree);
14382
+ const importRefNames = new Set(importTree.refs.map((r) => r.ref));
14383
+ const extraRefs = templateTree.refs.filter(
14384
+ (r) => !importRefNames.has(r.ref) && !knownNames.has(r.ref)
14385
+ );
14386
+ let childrenChanged = false;
14387
+ const children = { ...importTree.children };
14388
+ for (const [key, templateChild] of Object.entries(templateTree.children)) {
14389
+ if (!(key in children)) {
14390
+ if (hasRefsNotIn(templateChild, knownNames)) {
14391
+ children[key] = templateChild;
14392
+ childrenChanged = true;
14393
+ }
14394
+ } else {
14395
+ const grafted = graftTemplateOnlyRefs(children[key], templateChild, knownNames);
14396
+ if (grafted !== children[key]) {
14397
+ children[key] = grafted;
14398
+ childrenChanged = true;
14399
+ }
14400
+ }
14401
+ }
14402
+ if (extraRefs.length === 0 && !childrenChanged) return importTree;
14403
+ return mkRefsTree(
14404
+ [...importTree.refs, ...extraRefs],
14405
+ children,
14406
+ importTree.repeated,
14407
+ importTree?.imported?.refsTypeName,
14408
+ importTree?.imported?.repeatedRefsTypeName
14409
+ );
14410
+ }
14411
+ function hasRefsNotIn(tree, knownNames) {
14412
+ if (tree.refs.some((r) => !knownNames.has(r.ref))) return true;
14413
+ return Object.values(tree.children).some((c) => hasRefsNotIn(c, knownNames));
14414
+ }
14415
+ function collectAllRefNames(tree) {
14416
+ const names = /* @__PURE__ */ new Set();
14417
+ for (const ref of tree.refs) names.add(ref.ref);
14418
+ for (const child of Object.values(tree.children)) {
14419
+ for (const name of collectAllRefNames(child)) names.add(name);
14420
+ }
14421
+ return names;
14422
+ }
14380
14423
  function optimizeRefs({ rendered, imports, validations, refs, recursiveRegions }, headlessImports = []) {
14381
14424
  const deDuplicateRefsTree = (refs2) => {
14382
14425
  const mergedRefs = [];
@@ -14443,7 +14486,8 @@ function optimizeRefs({ rendered, imports, validations, refs, recursiveRegions }
14443
14486
  }
14444
14487
  }
14445
14488
  for (const [key, child] of Object.entries(importedRefsUpdated)) {
14446
- mergedChildren[key] = child;
14489
+ const templateChild = markedAutoOnImported.children[key];
14490
+ mergedChildren[key] = templateChild ? graftTemplateOnlyRefs(child, templateChild) : child;
14447
14491
  }
14448
14492
  const combined = mkRefsTree(
14449
14493
  markedAutoOnImported.refs,
@@ -19581,15 +19625,25 @@ function detectCssNameCollisions(css, validations) {
19581
19625
  }
19582
19626
  keyframeNames.add(name);
19583
19627
  }
19584
- const fontFaceNames = /* @__PURE__ */ new Set();
19585
- for (const match of css.matchAll(/@font-face\s*\{[^}]*font-family\s*:\s*['"]?([^;'"}\n]+)/g)) {
19586
- const name = match[1].trim();
19587
- if (fontFaceNames.has(name)) {
19628
+ const fontFaceKeys = /* @__PURE__ */ new Set();
19629
+ for (const match of css.matchAll(/@font-face\s*\{([^}]*)\}/g)) {
19630
+ const block = match[1];
19631
+ const familyMatch = block.match(/font-family\s*:\s*['"]?([^;'"\n}]+)/);
19632
+ if (!familyMatch) {
19633
+ continue;
19634
+ }
19635
+ const family = familyMatch[1].trim();
19636
+ const weightMatch = block.match(/font-weight\s*:\s*([^;\n}]+)/);
19637
+ const styleMatch = block.match(/font-style\s*:\s*([^;\n}]+)/);
19638
+ const weight = weightMatch ? weightMatch[1].trim() : "normal";
19639
+ const style = styleMatch ? styleMatch[1].trim() : "normal";
19640
+ const key = `${family}|${weight}|${style}`;
19641
+ if (fontFaceKeys.has(key)) {
19588
19642
  validations.push(
19589
- `@font-face "${name}" is defined multiple times. Font family names are global — rename to avoid collisions.`
19643
+ `@font-face "${family}" (${weight}, ${style}) is defined multiple times. Font faces are global — rename to avoid collisions.`
19590
19644
  );
19591
19645
  }
19592
- fontFaceNames.add(name);
19646
+ fontFaceKeys.add(key);
19593
19647
  }
19594
19648
  }
19595
19649
  function extractTrackByMaps(pageContract, headlessImports) {
@@ -21425,8 +21479,8 @@ function renderAttributes$1(element, { variables }) {
21425
21479
  let attributes2 = element.attributes;
21426
21480
  let renderedAttributes = [];
21427
21481
  Object.keys(attributes2).forEach((attrName) => {
21428
- let attrCanonical = attrName.toLowerCase();
21429
- let attrKey = attrCanonical.match(attributesRequiresQuotes$1) ? `"${attrCanonical}"` : attrCanonical;
21482
+ const attrCanonical = attrName.toLowerCase();
21483
+ const attrKey = attrName.match(attributesRequiresQuotes$1) ? `"${attrName}"` : attrName;
21430
21484
  if (isDirectiveAttribute(attrCanonical)) return;
21431
21485
  if (attrCanonical === "style") {
21432
21486
  renderedAttributes.push(renderStyleAttribute(attributes2[attrName], variables));
@@ -21462,7 +21516,7 @@ function renderDynamicAttributes(element, { variables }) {
21462
21516
  const renderedAttributes = [];
21463
21517
  Object.keys(attributes2).forEach((attrName) => {
21464
21518
  const attrCanonical = attrName.toLowerCase();
21465
- const attrKey = attrCanonical.match(attributesRequiresQuotes$1) ? `"${attrCanonical}"` : attrCanonical;
21519
+ const attrKey = attrName.match(attributesRequiresQuotes$1) ? `"${attrName}"` : attrName;
21466
21520
  if (isDirectiveAttribute(attrCanonical)) return;
21467
21521
  if (attrCanonical === "style") {
21468
21522
  const styleFragment = renderStyleAttribute(attributes2[attrName], variables);
@@ -23309,12 +23363,12 @@ function renderServerAttributes(element, context) {
23309
23363
  const attrValue = attributes2[attrName];
23310
23364
  if (propertyMapping[attrCanonical]?.type === BOOLEAN_ATTRIBUTE) {
23311
23365
  if (attrValue === "") {
23312
- parts.push(w(indent, `' ${attrCanonical}'`));
23366
+ parts.push(w(indent, `' ${attrName}'`));
23313
23367
  } else {
23314
23368
  const condExpr = parseServerCondition(attrValue, variables);
23315
23369
  parts.push(
23316
23370
  new RenderFragment(
23317
- `${indent.firstLine}if (${condExpr.rendered}) { w(' ${attrCanonical}'); }`
23371
+ `${indent.firstLine}if (${condExpr.rendered}) { w(' ${attrName}'); }`
23318
23372
  )
23319
23373
  );
23320
23374
  }
@@ -23324,13 +23378,13 @@ function renderServerAttributes(element, context) {
23324
23378
  parts.push(
23325
23379
  w(
23326
23380
  indent,
23327
- `' ${attrCanonical}="' + escapeAttr(String(${fragment.rendered})) + '"'`,
23381
+ `' ${attrName}="' + escapeAttr(String(${fragment.rendered})) + '"'`,
23328
23382
  Imports.for(Import.escapeAttr)
23329
23383
  )
23330
23384
  );
23331
23385
  } else {
23332
23386
  const escaped = escapeForJsString(attrValue);
23333
- parts.push(w(indent, `' ${attrCanonical}="${escaped}"'`));
23387
+ parts.push(w(indent, `' ${attrName}="${escaped}"'`));
23334
23388
  }
23335
23389
  } else if (attrCanonical === "class") {
23336
23390
  const classExpr = parseClassExpression(attrValue, variables);
@@ -23373,13 +23427,13 @@ function renderServerAttributes(element, context) {
23373
23427
  parts.push(
23374
23428
  w(
23375
23429
  indent,
23376
- `' ${attrCanonical}="' + escapeAttr(String(${fragment.rendered})) + '"'`,
23430
+ `' ${attrName}="' + escapeAttr(String(${fragment.rendered})) + '"'`,
23377
23431
  Imports.for(Import.escapeAttr)
23378
23432
  )
23379
23433
  );
23380
23434
  } else {
23381
23435
  const escaped = escapeForJsString(attrValue);
23382
- parts.push(w(indent, `' ${attrCanonical}="${escaped}"'`));
23436
+ parts.push(w(indent, `' ${attrName}="${escaped}"'`));
23383
23437
  }
23384
23438
  }
23385
23439
  });
@@ -23512,20 +23566,20 @@ function renderServerAttributesAsString(element, context) {
23512
23566
  const attrValue = attributes2[attrName];
23513
23567
  if (propertyMapping[attrCanonical]?.type === BOOLEAN_ATTRIBUTE) {
23514
23568
  if (attrValue === "") {
23515
- parts.push(new RenderFragment(`' ${attrCanonical}'`));
23569
+ parts.push(new RenderFragment(`' ${attrName}'`));
23516
23570
  }
23517
23571
  } else if (propertyMapping[attrCanonical]?.type === PROPERTY) {
23518
23572
  const [fragment, isDynamic] = parseServerTemplateExpression(attrValue, variables);
23519
23573
  if (isDynamic) {
23520
23574
  parts.push(
23521
23575
  new RenderFragment(
23522
- `' ${attrCanonical}="' + escapeAttr(String(${fragment.rendered})) + '"'`,
23576
+ `' ${attrName}="' + escapeAttr(String(${fragment.rendered})) + '"'`,
23523
23577
  Imports.for(Import.escapeAttr)
23524
23578
  )
23525
23579
  );
23526
23580
  } else {
23527
23581
  const escaped = escapeForJsString(attrValue);
23528
- parts.push(new RenderFragment(`' ${attrCanonical}="${escaped}"'`));
23582
+ parts.push(new RenderFragment(`' ${attrName}="${escaped}"'`));
23529
23583
  }
23530
23584
  } else if (attrCanonical === "class") {
23531
23585
  const classExpr = parseClassExpression(attrValue, variables);
@@ -23565,13 +23619,13 @@ function renderServerAttributesAsString(element, context) {
23565
23619
  if (isDynamic) {
23566
23620
  parts.push(
23567
23621
  new RenderFragment(
23568
- `' ${attrCanonical}="' + escapeAttr(String(${fragment.rendered})) + '"'`,
23622
+ `' ${attrName}="' + escapeAttr(String(${fragment.rendered})) + '"'`,
23569
23623
  Imports.for(Import.escapeAttr)
23570
23624
  )
23571
23625
  );
23572
23626
  } else {
23573
23627
  const escaped = escapeForJsString(attrValue);
23574
- parts.push(new RenderFragment(`' ${attrCanonical}="${escaped}"'`));
23628
+ parts.push(new RenderFragment(`' ${attrName}="${escaped}"'`));
23575
23629
  }
23576
23630
  }
23577
23631
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jay-framework/compiler-jay-html",
3
- "version": "0.23.1",
3
+ "version": "0.24.1",
4
4
  "description": "",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/index.js",
@@ -34,12 +34,12 @@
34
34
  },
35
35
  "author": "",
36
36
  "dependencies": {
37
- "@jay-framework/compiler-analyze-exported-types": "^0.23.1",
38
- "@jay-framework/compiler-shared": "^0.23.1",
39
- "@jay-framework/component": "^0.23.1",
40
- "@jay-framework/logger": "^0.23.1",
41
- "@jay-framework/runtime": "^0.23.1",
42
- "@jay-framework/secure": "^0.23.1",
37
+ "@jay-framework/compiler-analyze-exported-types": "^0.24.1",
38
+ "@jay-framework/compiler-shared": "^0.24.1",
39
+ "@jay-framework/component": "^0.24.1",
40
+ "@jay-framework/logger": "^0.24.1",
41
+ "@jay-framework/runtime": "^0.24.1",
42
+ "@jay-framework/secure": "^0.24.1",
43
43
  "@types/js-yaml": "^4.0.9",
44
44
  "change-case": "^4.1.2",
45
45
  "he": "^1.2.0",
@@ -52,8 +52,8 @@
52
52
  },
53
53
  "devDependencies": {
54
54
  "@caiogondim/strip-margin": "^1.0.0",
55
- "@jay-framework/4-react": "^0.23.1",
56
- "@jay-framework/dev-environment": "^0.23.1",
55
+ "@jay-framework/4-react": "^0.24.1",
56
+ "@jay-framework/dev-environment": "^0.24.1",
57
57
  "@testing-library/jest-dom": "^6.2.0",
58
58
  "@types/js-beautify": "^1",
59
59
  "@types/node": "^20.11.5",