@webiny/website-builder-nextjs 6.0.0-alpha.0 → 6.0.0-alpha.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.
@@ -0,0 +1,6 @@
1
+ export declare class CSSInliner {
2
+ private seen;
3
+ load(entryPath: string): Promise<string>;
4
+ private inlineFile;
5
+ private createImportInlinerPlugin;
6
+ }
package/CssInliner.js ADDED
@@ -0,0 +1,70 @@
1
+ import postcss from "postcss";
2
+ import path from "path";
3
+ import { readFile } from "fs";
4
+ import { promisify } from "util";
5
+ const readFileAsync = promisify(readFile);
6
+ export class CSSInliner {
7
+ seen = new Set();
8
+ async load(entryPath) {
9
+ const result = await this.inlineFile(entryPath);
10
+ return result.css;
11
+ }
12
+ async inlineFile(filePath) {
13
+ const absolutePath = path.resolve(filePath);
14
+ if (this.seen.has(absolutePath)) {
15
+ return postcss().process("", {
16
+ from: undefined
17
+ });
18
+ }
19
+ this.seen.add(absolutePath);
20
+ const css = await readFileAsync(absolutePath, "utf8");
21
+ return postcss([this.createImportInlinerPlugin(path.dirname(absolutePath))]).process(css, {
22
+ from: absolutePath
23
+ });
24
+ }
25
+ createImportInlinerPlugin(currentDir) {
26
+ return {
27
+ postcssPlugin: "css-inliner",
28
+ AtRule: async atRule => {
29
+ if (atRule.name !== "import") {
30
+ return;
31
+ }
32
+ const importPath = atRule.params.replace(/^url\(|\)$|['"]/g, "").trim();
33
+ let importedCSS;
34
+ let from;
35
+ try {
36
+ if (importPath.startsWith("http://") || importPath.startsWith("https://")) {
37
+ // Leave remote @import untouched
38
+ return;
39
+ } else {
40
+ const resolvedPath = path.resolve(currentDir, importPath);
41
+ if (this.seen.has(resolvedPath)) {
42
+ atRule.remove();
43
+ return;
44
+ }
45
+ this.seen.add(resolvedPath);
46
+ importedCSS = await readFileAsync(resolvedPath, "utf8");
47
+ from = resolvedPath;
48
+ }
49
+ } catch (err) {
50
+ console.warn(`⚠️ Failed to inline import: ${importPath}`, err);
51
+ return;
52
+ }
53
+ const result = await postcss([this.createImportInlinerPlugin(from ? path.dirname(from) : currentDir)]).process(importedCSS, {
54
+ from
55
+ });
56
+ const root = postcss.parse(result.css);
57
+ if (atRule.parent?.type === "atrule" && atRule.parent.name === "media") {
58
+ atRule.replaceWith(root);
59
+ } else {
60
+ atRule.replaceWith(root.nodes);
61
+ }
62
+ }
63
+ };
64
+ }
65
+ }
66
+
67
+ // @ts-expect-error `postcss` requires this to treat the function as a valid plugin.
68
+ CSSInliner.prototype.createImportInlinerPlugin.postcss = true;
69
+
70
+ //# sourceMappingURL=CssInliner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["postcss","path","readFile","promisify","readFileAsync","CSSInliner","seen","Set","load","entryPath","result","inlineFile","css","filePath","absolutePath","resolve","has","process","from","undefined","add","createImportInlinerPlugin","dirname","currentDir","postcssPlugin","AtRule","atRule","name","importPath","params","replace","trim","importedCSS","startsWith","resolvedPath","remove","err","console","warn","root","parse","parent","type","replaceWith","nodes","prototype"],"sources":["CssInliner.ts"],"sourcesContent":["import postcss, { type AtRule } from \"postcss\";\nimport path from \"path\";\nimport { readFile } from \"fs\";\nimport { promisify } from \"util\";\n\nconst readFileAsync = promisify(readFile);\n\nexport class CSSInliner {\n private seen = new Set<string>();\n\n async load(entryPath: string): Promise<string> {\n const result = await this.inlineFile(entryPath);\n return result.css;\n }\n\n private async inlineFile(filePath: string): Promise<postcss.Result> {\n const absolutePath = path.resolve(filePath);\n\n if (this.seen.has(absolutePath)) {\n return postcss().process(\"\", { from: undefined });\n }\n\n this.seen.add(absolutePath);\n const css = await readFileAsync(absolutePath, \"utf8\");\n\n return postcss([this.createImportInlinerPlugin(path.dirname(absolutePath))]).process(css, {\n from: absolutePath\n });\n }\n\n private createImportInlinerPlugin(currentDir: string) {\n return {\n postcssPlugin: \"css-inliner\",\n AtRule: async (atRule: AtRule) => {\n if (atRule.name !== \"import\") {\n return;\n }\n\n const importPath = atRule.params.replace(/^url\\(|\\)$|['\"]/g, \"\").trim();\n\n let importedCSS: string;\n let from: string | undefined;\n\n try {\n if (importPath.startsWith(\"http://\") || importPath.startsWith(\"https://\")) {\n // Leave remote @import untouched\n return;\n } else {\n const resolvedPath = path.resolve(currentDir, importPath);\n\n if (this.seen.has(resolvedPath)) {\n atRule.remove();\n return;\n }\n\n this.seen.add(resolvedPath);\n importedCSS = await readFileAsync(resolvedPath, \"utf8\");\n from = resolvedPath;\n }\n } catch (err) {\n console.warn(`⚠️ Failed to inline import: ${importPath}`, err);\n return;\n }\n\n const result = await postcss([\n this.createImportInlinerPlugin(from ? path.dirname(from) : currentDir)\n ]).process(importedCSS, { from });\n\n const root = postcss.parse(result.css);\n\n if (atRule.parent?.type === \"atrule\" && atRule.parent.name === \"media\") {\n atRule.replaceWith(root);\n } else {\n atRule.replaceWith(root.nodes);\n }\n }\n };\n }\n}\n\n// @ts-expect-error `postcss` requires this to treat the function as a valid plugin.\nCSSInliner.prototype.createImportInlinerPlugin.postcss = true;\n"],"mappings":"AAAA,OAAOA,OAAO,MAAuB,SAAS;AAC9C,OAAOC,IAAI,MAAM,MAAM;AACvB,SAASC,QAAQ,QAAQ,IAAI;AAC7B,SAASC,SAAS,QAAQ,MAAM;AAEhC,MAAMC,aAAa,GAAGD,SAAS,CAACD,QAAQ,CAAC;AAEzC,OAAO,MAAMG,UAAU,CAAC;EACZC,IAAI,GAAG,IAAIC,GAAG,CAAS,CAAC;EAEhC,MAAMC,IAAIA,CAACC,SAAiB,EAAmB;IAC3C,MAAMC,MAAM,GAAG,MAAM,IAAI,CAACC,UAAU,CAACF,SAAS,CAAC;IAC/C,OAAOC,MAAM,CAACE,GAAG;EACrB;EAEA,MAAcD,UAAUA,CAACE,QAAgB,EAA2B;IAChE,MAAMC,YAAY,GAAGb,IAAI,CAACc,OAAO,CAACF,QAAQ,CAAC;IAE3C,IAAI,IAAI,CAACP,IAAI,CAACU,GAAG,CAACF,YAAY,CAAC,EAAE;MAC7B,OAAOd,OAAO,CAAC,CA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AC,OAAOE,GAAG,EAAE;UACVC,OAAO,CAACC,IAAI,CAAC,+BAA+BV,UAAU,EAAE,EAAEQ,GAAG,CAAC;UAC9D;QACJ;QAEA,MAAM1B,MAAM,GAAG,MAAMV,OAAO,CAAC,CACzB,IAAI,CAACqB,yBAAyB,CAACH,IAAI,GAAGjB,IAAI,CAACqB,OAAO,CAACJ,IAAI,CAAC,GAAGK,UAAU,CAAC,CACzE,CAAC,CAACN,OAAO,CAACe,WAAW,EAAE;UAAEd;QAAK,CAAC,CAAC;QAEjC,MAAMqB,IAAI,GAAGvC,OAAO,CAACwC,KAAK,CAAC9B,MAAM,CAACE,GAAG,CAAC;QAEtC,IAAIc,MAAM,CAACe,MAAM,EAAEC,IAAI,KAAK,QAAQ,IAAIhB,MAAM,CAACe,MAAM,CAACd,IAAI,KAAK,OAAO,EAAE;UACpED,MAAM,CAACiB,WAAW,CAACJ,IAAI,CAAC;QAC5B,CAAC,MAAM;UACHb,MAAM,CAACiB,WAAW,CAACJ,IAAI,CAACK,KAAK,CAAC;QAClC;MACJ;IACJ,CAAC;EACL;AACJ;;AAEA;AACAvC,UAAU,CAACwC,SAAS,CAACxB,yBAAyB,CAACrB,OAAO,GAAG,IAAI","ignoreList":[]}
package/index.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export * from "@webiny/website-builder-react";
2
+ export * from "./useCss";
package/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  export * from "@webiny/website-builder-react";
2
+ export * from "./useCss";
2
3
  import { setHeadersProvider } from "@webiny/website-builder-react";
3
4
  setHeadersProvider(async () => {
4
- // @ts-expect-error This is a peer dependency.
5
+ // Settings @ts-expect-error breaks the build if the dependency is installed in the repo.
6
+ // @ts-ignore This is a peer dependency.
5
7
  const {
6
8
  headers
7
9
  } = await import("next/headers");
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["setHeadersProvider","headers"],"sources":["index.ts"],"sourcesContent":["export * from \"@webiny/website-builder-react\";\n\nimport { setHeadersProvider } from \"@webiny/website-builder-react\";\n\nsetHeadersProvider(async () => {\n // @ts-expect-error This is a peer dependency.\n const { headers } = await import(\"next/headers\");\n return await headers();\n});\n"],"mappings":"AAAA,cAAc,+BAA+B;AAE7C,SAASA,kBAAkB,QAAQ,+BAA+B;AAElEA,kBAAkB,CAAC,YAAY;EAC3B;EACA,MAAM;IAAEC;EAAQ,CAAC,GAAG,MAAM,MAAM,CAAC,cAAc,CAAC;EAChD,OAAO,MAAMA,OAAO,CAAC,CAAC;AAC1B,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["setHeadersProvider","headers"],"sources":["index.ts"],"sourcesContent":["export * from \"@webiny/website-builder-react\";\nexport * from \"./useCss\";\n\nimport { setHeadersProvider } from \"@webiny/website-builder-react\";\n\nsetHeadersProvider(async () => {\n // Settings @ts-expect-error breaks the build if the dependency is installed in the repo.\n // @ts-ignore This is a peer dependency.\n const { headers } = await import(\"next/headers\");\n return await headers();\n});\n"],"mappings":"AAAA,cAAc,+BAA+B;AAC7C;AAEA,SAASA,kBAAkB,QAAQ,+BAA+B;AAElEA,kBAAkB,CAAC,YAAY;EAC3B;EACA;EACA,MAAM;IAAEC;EAAQ,CAAC,GAAG,MAAM,MAAM,CAAC,cAAc,CAAC;EAChD,OAAO,MAAMA,OAAO,CAAC,CAAC;AAC1B,CAAC,CAAC","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/website-builder-nextjs",
3
- "version": "6.0.0-alpha.0",
3
+ "version": "6.0.0-alpha.2",
4
4
  "main": "index.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -17,13 +17,14 @@
17
17
  ],
18
18
  "license": "MIT",
19
19
  "dependencies": {
20
- "@webiny/website-builder-react": "6.0.0-alpha.0"
20
+ "@webiny/website-builder-react": "6.0.0-alpha.2",
21
+ "postcss": "8.5.6"
21
22
  },
22
23
  "peerDependencies": {
23
24
  "next": "^15"
24
25
  },
25
26
  "devDependencies": {
26
- "@webiny/project-utils": "6.0.0-alpha.0",
27
+ "@webiny/project-utils": "6.0.0-alpha.2",
27
28
  "typescript": "5.3.3"
28
29
  },
29
30
  "publishConfig": {
@@ -37,10 +38,11 @@
37
38
  "adio": {
38
39
  "ignore": {
39
40
  "dependencies": [
41
+ "postcss",
40
42
  "next",
41
43
  "@webiny/website-builder-react"
42
44
  ]
43
45
  }
44
46
  },
45
- "gitHead": "a5b28fed7a242d8f56712197a8ea83aa6d2ed101"
47
+ "gitHead": "7c9e8fbfd62a57ece5f880dbad6c864636b0355e"
46
48
  }
package/useCss.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function useCss(cssFile?: string): Promise<string>;
package/useCss.js ADDED
@@ -0,0 +1,13 @@
1
+ "use server";
2
+
3
+ import path from "path";
4
+ export async function useCss(cssFile) {
5
+ const {
6
+ CSSInliner
7
+ } = await import("./CssInliner");
8
+ const entryCss = cssFile ?? path.resolve(process.cwd(), "src/theme/theme.css");
9
+ const inliner = new CSSInliner();
10
+ return await inliner.load(entryCss);
11
+ }
12
+
13
+ //# sourceMappingURL=useCss.js.map
package/useCss.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"names":["path","useCss","cssFile","CSSInliner","entryCss","resolve","process","cwd","inliner","load"],"sources":["useCss.ts"],"sourcesContent":["\"use server\";\nimport path from \"path\";\n\nexport async function useCss(cssFile?: string) {\n const { CSSInliner } = await import(\"~/CssInliner\");\n const entryCss = cssFile ?? path.resolve(process.cwd(), \"src/theme/theme.css\");\n\n const inliner = new CSSInliner();\n return await inliner.load(entryCss);\n}\n"],"mappings":"AAAA,YAAY;;AACZ,OAAOA,IAAI,MAAM,MAAM;AAEvB,OAAO,eAAeC,MAAMA,CAACC,OAAgB,EAAE;EAC3C,MAAM;IAAEC;EAAW,CAAC,GAAG,MAAM,MAAM,eAAe,CAAC;EACnD,MAAMC,QAAQ,GAAGF,OAAO,IAAIF,IAAI,CAACK,OAAO,CAACC,OAAO,CAACC,GAAG,CAAC,CAAC,EAAE,qBAAqB,CAAC;EAE9E,MAAMC,OAAO,GAAG,IAAIL,UAAU,CAAC,CAAC;EAChC,OAAO,MAAMK,OAAO,CAACC,IAAI,CAACL,QAAQ,CAAC;AACvC","ignoreList":[]}