@jay-framework/compiler-jay-html 0.24.0 → 0.24.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.
package/dist/index.d.cts CHANGED
@@ -223,6 +223,8 @@ interface JayHtmlSourceFile extends CompilerSourceFile {
223
223
  */
224
224
  clientTrackByMap?: Record<string, string>;
225
225
  headMeta?: JayHtmlHeadMeta;
226
+ /** Per-page validation overrides from <script type="application/jay-validations">. */
227
+ validationOverrides?: Record<string, Record<string, boolean>>;
226
228
  scripts?: JayHtmlScript[];
227
229
  }
228
230
 
package/dist/index.js CHANGED
@@ -19162,7 +19162,7 @@ function injectHeadfullFSTemplatesRecursive(fsElements, body, sourceDir, importR
19162
19162
  }
19163
19163
  }
19164
19164
  }
19165
- async function parseHeadfullFSImports(elements, validations, filePath, importResolver, body, projectRoot, visited = /* @__PURE__ */ new Set(), sourceDir) {
19165
+ async function parseHeadfullFSImports(elements, validations, filePath, importResolver, body, projectRoot, visited = /* @__PURE__ */ new Set(), sourceDir, pageLinkedCssPaths) {
19166
19166
  const headlessImports = [];
19167
19167
  const cssParts = [];
19168
19168
  const linkedCssFiles = [];
@@ -19272,10 +19272,11 @@ async function parseHeadfullFSImports(elements, validations, filePath, importRes
19272
19272
  continue;
19273
19273
  }
19274
19274
  const componentDir = jayHtmlResult.componentDir;
19275
- const componentCssResult = await extractCss(jayHtmlRoot, componentDir);
19275
+ const componentCssResult = await extractCss(jayHtmlRoot, componentDir, pageLinkedCssPaths);
19276
19276
  validations.push(...componentCssResult.validations);
19277
19277
  if (componentCssResult.val?.css) {
19278
- cssParts.push(componentCssResult.val.css);
19278
+ cssParts.push(`/* Component: ${contractName} */
19279
+ ${componentCssResult.val.css}`);
19279
19280
  }
19280
19281
  if (componentCssResult.val?.linkedCssFiles) {
19281
19282
  linkedCssFiles.push(...componentCssResult.val.linkedCssFiles);
@@ -19319,7 +19320,9 @@ async function parseHeadfullFSImports(elements, validations, filePath, importRes
19319
19320
  importResolver,
19320
19321
  jayHtmlBody,
19321
19322
  projectRoot,
19322
- visited
19323
+ visited,
19324
+ void 0,
19325
+ pageLinkedCssPaths
19323
19326
  );
19324
19327
  headlessImports.push(...nestedResult.headlessImports);
19325
19328
  if (nestedResult.css) {
@@ -19557,6 +19560,25 @@ function parseHeadMeta(root) {
19557
19560
  }
19558
19561
  return { title, meta, links };
19559
19562
  }
19563
+ function parseValidationOverrides(root) {
19564
+ const el = root.querySelector('script[type="application/jay-validations"]');
19565
+ if (!el) return void 0;
19566
+ const text2 = el.textContent?.trim();
19567
+ if (!text2) return void 0;
19568
+ try {
19569
+ const parsed = yaml.load(text2);
19570
+ if (!parsed || typeof parsed !== "object") return void 0;
19571
+ const result = {};
19572
+ for (const [key, value] of Object.entries(parsed)) {
19573
+ if (value && typeof value === "object") {
19574
+ result[key] = value;
19575
+ }
19576
+ }
19577
+ return Object.keys(result).length > 0 ? result : void 0;
19578
+ } catch {
19579
+ return void 0;
19580
+ }
19581
+ }
19560
19582
  function resolveNestedCssImports(css, cssDir, visited) {
19561
19583
  if (!css.includes("@import")) return css;
19562
19584
  const seen = visited ?? /* @__PURE__ */ new Set();
@@ -19574,7 +19596,7 @@ ${resolveNestedCssImports(imported, path.dirname(resolved), seen)}`;
19574
19596
  }
19575
19597
  });
19576
19598
  }
19577
- async function extractCss(root, filePath) {
19599
+ async function extractCss(root, filePath, skipPaths) {
19578
19600
  const cssParts = [];
19579
19601
  const validations = [];
19580
19602
  const linkedCssFiles = [];
@@ -19588,6 +19610,7 @@ async function extractCss(root, filePath) {
19588
19610
  if (filePath) {
19589
19611
  const cssFilePath = path.resolve(filePath, href);
19590
19612
  linkedCssFiles.push(cssFilePath);
19613
+ if (skipPaths?.has(cssFilePath)) continue;
19591
19614
  try {
19592
19615
  const cssContent = await fs$1.readFile(cssFilePath, "utf-8");
19593
19616
  const resolvedCss = resolveNestedCssImports(
@@ -19700,6 +19723,13 @@ async function parseJayFile(html2, filename, filePath, options, linkedContractRe
19700
19723
  validations.push(`jay file must have exactly a body tag`);
19701
19724
  return new WithValidations(void 0, validations);
19702
19725
  }
19726
+ const pageLinkedCssPaths = /* @__PURE__ */ new Set();
19727
+ for (const link of root.querySelectorAll('head link[rel="stylesheet"]')) {
19728
+ const href = link.getAttribute("href");
19729
+ if (href && !href.startsWith("http://") && !href.startsWith("https://") && !href.startsWith("//")) {
19730
+ pageLinkedCssPaths.add(path.resolve(filePath, href));
19731
+ }
19732
+ }
19703
19733
  const headfullFSResult = await parseHeadfullFSImports(
19704
19734
  fsHeadfullElements,
19705
19735
  validations,
@@ -19709,7 +19739,8 @@ async function parseJayFile(html2, filename, filePath, options, linkedContractRe
19709
19739
  projectRoot,
19710
19740
  void 0,
19711
19741
  // visited
19712
- sourceDir
19742
+ sourceDir,
19743
+ pageLinkedCssPaths
19713
19744
  );
19714
19745
  const headlessImports = await parseHeadlessImports(
19715
19746
  root.querySelectorAll('script[type="application/jay-headless"]'),
@@ -19744,6 +19775,7 @@ async function parseJayFile(html2, filename, filePath, options, linkedContractRe
19744
19775
  const excludeCssLinks = !!filePath;
19745
19776
  const headLinks = parseHeadLinks(root, excludeCssLinks);
19746
19777
  const headMeta = parseHeadMeta(root);
19778
+ const validationOverrides = parseValidationOverrides(root);
19747
19779
  const scripts = validateAndCollectScripts(root, validations);
19748
19780
  validations.push(...cssResult.validations);
19749
19781
  if (validations.length > 0) return new WithValidations(void 0, validations);
@@ -19783,6 +19815,7 @@ async function parseJayFile(html2, filename, filePath, options, linkedContractRe
19783
19815
  serverTrackByMap: Object.keys(serverTrackByMap).length > 0 ? serverTrackByMap : void 0,
19784
19816
  clientTrackByMap: Object.keys(clientTrackByMap).length > 0 ? clientTrackByMap : void 0,
19785
19817
  headMeta,
19818
+ validationOverrides,
19786
19819
  scripts: scripts.length > 0 ? scripts : void 0
19787
19820
  },
19788
19821
  validations
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jay-framework/compiler-jay-html",
3
- "version": "0.24.0",
3
+ "version": "0.24.2",
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.24.0",
38
- "@jay-framework/compiler-shared": "^0.24.0",
39
- "@jay-framework/component": "^0.24.0",
40
- "@jay-framework/logger": "^0.24.0",
41
- "@jay-framework/runtime": "^0.24.0",
42
- "@jay-framework/secure": "^0.24.0",
37
+ "@jay-framework/compiler-analyze-exported-types": "^0.24.2",
38
+ "@jay-framework/compiler-shared": "^0.24.2",
39
+ "@jay-framework/component": "^0.24.2",
40
+ "@jay-framework/logger": "^0.24.2",
41
+ "@jay-framework/runtime": "^0.24.2",
42
+ "@jay-framework/secure": "^0.24.2",
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.24.0",
56
- "@jay-framework/dev-environment": "^0.24.0",
55
+ "@jay-framework/4-react": "^0.24.2",
56
+ "@jay-framework/dev-environment": "^0.24.2",
57
57
  "@testing-library/jest-dom": "^6.2.0",
58
58
  "@types/js-beautify": "^1",
59
59
  "@types/node": "^20.11.5",