@jay-framework/compiler-jay-html 0.6.6 → 0.6.7

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.ts CHANGED
@@ -26,6 +26,8 @@ interface JayHtmlSourceFile extends CompilerSourceFile {
26
26
  namespaces: JayHtmlNamespace[];
27
27
  headlessImports: JayHeadlessImports[];
28
28
  headLinks: JayHtmlHeadLink[];
29
+ css?: string;
30
+ filename?: string;
29
31
  }
30
32
 
31
33
  declare function generateElementDefinitionFile(parsedFile: WithValidations<JayHtmlSourceFile>): WithValidations<string>;
package/dist/index.js CHANGED
@@ -14,8 +14,9 @@ const yaml = require("js-yaml");
14
14
  const changeCase = require("change-case");
15
15
  const pluralize = require("pluralize");
16
16
  const path = require("path");
17
+ const fs = require("fs/promises");
17
18
  const compilerAnalyzeExportedTypes = require("@jay-framework/compiler-analyze-exported-types");
18
- const fs = require("node:fs");
19
+ const fs$1 = require("node:fs");
19
20
  function peg$subclass(child, parent) {
20
21
  function ctor() {
21
22
  this.constructor = child;
@@ -5128,6 +5129,12 @@ function renderHeadLinksArray(headLinks) {
5128
5129
  }).join(", ");
5129
5130
  return `[${linksCode}]`;
5130
5131
  }
5132
+ function generateCssImport(jayFile) {
5133
+ if (!jayFile.css || !jayFile.filename) {
5134
+ return "";
5135
+ }
5136
+ return `import './${jayFile.filename}.css';`;
5137
+ }
5131
5138
  function renderFunctionImplementation$1(types, rootBodyElement, importStatements, baseElementName, namespaces, headlessImports, importerMode, headLinks = []) {
5132
5139
  const variables = new Variables(types);
5133
5140
  const { importedSymbols, importedSandboxedSymbols } = processImportedComponents(importStatements);
@@ -5363,6 +5370,7 @@ function generateElementDefinitionFile(parsedFile) {
5363
5370
  compilerShared.RuntimeMode.WorkerTrusted,
5364
5371
  jayFile.headLinks
5365
5372
  );
5373
+ const cssImport = generateCssImport(jayFile);
5366
5374
  return [
5367
5375
  renderImports$1(
5368
5376
  renderedImplementation.imports.plus(compilerShared.Import.jayElement),
@@ -5370,6 +5378,7 @@ function generateElementDefinitionFile(parsedFile) {
5370
5378
  jayFile.imports,
5371
5379
  compilerShared.RuntimeMode.MainTrusted
5372
5380
  ),
5381
+ cssImport,
5373
5382
  types,
5374
5383
  renderedRefs,
5375
5384
  renderedElement,
@@ -5389,6 +5398,7 @@ function generateElementFile(jayFile, importerMode) {
5389
5398
  importerMode,
5390
5399
  jayFile.headLinks
5391
5400
  );
5401
+ const cssImport = generateCssImport(jayFile);
5392
5402
  const renderedFile = [
5393
5403
  renderImports$1(
5394
5404
  renderedImplementation.imports.plus(compilerShared.Import.element).plus(compilerShared.Import.jayElement),
@@ -5396,6 +5406,7 @@ function generateElementFile(jayFile, importerMode) {
5396
5406
  jayFile.imports,
5397
5407
  importerMode
5398
5408
  ),
5409
+ cssImport,
5399
5410
  types,
5400
5411
  renderedRefs,
5401
5412
  renderedElement,
@@ -6399,9 +6410,16 @@ async function parseHeadlessImports(elements, validations, filePath, importResol
6399
6410
  function normalizeFilename(filename) {
6400
6411
  return filename.replace(".jay-html", "");
6401
6412
  }
6402
- function parseHeadLinks(root) {
6413
+ function parseHeadLinks(root, excludeCssLinks = false) {
6403
6414
  const allLinks = root.querySelectorAll("head link");
6404
- return allLinks.filter((link) => link.getAttribute("rel") !== "import").map((link) => {
6415
+ return allLinks.filter((link) => {
6416
+ const rel = link.getAttribute("rel");
6417
+ if (rel === "import")
6418
+ return false;
6419
+ if (excludeCssLinks && rel === "stylesheet")
6420
+ return false;
6421
+ return true;
6422
+ }).map((link) => {
6405
6423
  const attributes = { ...link.attributes };
6406
6424
  const rel = attributes.rel || "";
6407
6425
  const href = attributes.href || "";
@@ -6414,6 +6432,40 @@ function parseHeadLinks(root) {
6414
6432
  };
6415
6433
  });
6416
6434
  }
6435
+ async function extractCss(root, filePath) {
6436
+ const cssParts = [];
6437
+ const validations = [];
6438
+ const styleLinks = root.querySelectorAll('head link[rel="stylesheet"]');
6439
+ for (const link of styleLinks) {
6440
+ const href = link.getAttribute("href");
6441
+ if (href) {
6442
+ if (href.startsWith("http://") || href.startsWith("https://") || href.startsWith("//")) {
6443
+ continue;
6444
+ }
6445
+ if (filePath) {
6446
+ try {
6447
+ const cssFilePath = path.resolve(filePath, href);
6448
+ const cssContent = await fs.readFile(cssFilePath, "utf-8");
6449
+ cssParts.push(`/* External CSS: ${href} */
6450
+ ${cssContent}`);
6451
+ } catch (error) {
6452
+ validations.push(`CSS file not found or unreadable: ${href}`);
6453
+ }
6454
+ } else {
6455
+ cssParts.push(`/* External CSS: ${href} */`);
6456
+ }
6457
+ }
6458
+ }
6459
+ const styleTags = root.querySelectorAll("head style, style");
6460
+ for (const style of styleTags) {
6461
+ const cssContent = style.text.trim();
6462
+ if (cssContent) {
6463
+ cssParts.push(cssContent);
6464
+ }
6465
+ }
6466
+ const css = cssParts.length > 0 ? cssParts.join("\n\n") : void 0;
6467
+ return new compilerShared.WithValidations(css, validations);
6468
+ }
6417
6469
  async function parseJayFile(html, filename, filePath, options, linkedContractResolver) {
6418
6470
  const normalizedFileName = normalizeFilename(filename);
6419
6471
  const baseElementName = changeCase.capitalCase(normalizedFileName, { delimiter: "" });
@@ -6441,7 +6493,10 @@ async function parseJayFile(html, filename, filePath, options, linkedContractRes
6441
6493
  ...headfullImports,
6442
6494
  ...headlessImports.flatMap((_) => _.contractLinks)
6443
6495
  ];
6444
- const headLinks = parseHeadLinks(root);
6496
+ const cssResult = await extractCss(root, filePath);
6497
+ const excludeCssLinks = !!filePath;
6498
+ const headLinks = parseHeadLinks(root, excludeCssLinks);
6499
+ validations.push(...cssResult.validations);
6445
6500
  if (validations.length > 0)
6446
6501
  return new compilerShared.WithValidations(void 0, validations);
6447
6502
  let body = root.querySelector("body");
@@ -6458,7 +6513,9 @@ async function parseJayFile(html, filename, filePath, options, linkedContractRes
6458
6513
  baseElementName,
6459
6514
  namespaces,
6460
6515
  headlessImports,
6461
- headLinks
6516
+ headLinks,
6517
+ css: cssResult.val,
6518
+ filename: normalizedFileName
6462
6519
  },
6463
6520
  validations
6464
6521
  );
@@ -6474,7 +6531,7 @@ const JAY_IMPORT_RESOLVER = {
6474
6531
  return compilerAnalyzeExportedTypes.analyzeExportedTypes(fullPath, options);
6475
6532
  },
6476
6533
  loadContract(fullPath) {
6477
- const content = fs.readFileSync(fullPath).toString();
6534
+ const content = fs$1.readFileSync(fullPath).toString();
6478
6535
  return parseContract(content, fullPath);
6479
6536
  },
6480
6537
  resolveLink(importingModuleDir, link) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jay-framework/compiler-jay-html",
3
- "version": "0.6.6",
3
+ "version": "0.6.7",
4
4
  "description": "",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/index.js",
@@ -27,11 +27,11 @@
27
27
  },
28
28
  "author": "",
29
29
  "dependencies": {
30
- "@jay-framework/compiler-analyze-exported-types": "^0.6.6",
31
- "@jay-framework/compiler-shared": "^0.6.6",
32
- "@jay-framework/component": "^0.6.6",
33
- "@jay-framework/runtime": "^0.6.6",
34
- "@jay-framework/secure": "^0.6.6",
30
+ "@jay-framework/compiler-analyze-exported-types": "^0.6.7",
31
+ "@jay-framework/compiler-shared": "^0.6.7",
32
+ "@jay-framework/component": "^0.6.7",
33
+ "@jay-framework/runtime": "^0.6.7",
34
+ "@jay-framework/secure": "^0.6.7",
35
35
  "@types/js-yaml": "^4.0.9",
36
36
  "change-case": "^4.1.2",
37
37
  "js-yaml": "^4.1.0",
@@ -43,8 +43,8 @@
43
43
  },
44
44
  "devDependencies": {
45
45
  "@caiogondim/strip-margin": "^1.0.0",
46
- "@jay-framework/4-react": "^0.6.6",
47
- "@jay-framework/dev-environment": "^0.6.6",
46
+ "@jay-framework/4-react": "^0.6.7",
47
+ "@jay-framework/dev-environment": "^0.6.7",
48
48
  "@testing-library/jest-dom": "^6.2.0",
49
49
  "@types/js-beautify": "^1",
50
50
  "@types/node": "^20.11.5",