@webiny/website-builder-nextjs 0.0.0-unstable.39223eb3c1
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/CssInliner.d.ts +6 -0
- package/CssInliner.js +70 -0
- package/CssInliner.js.map +1 -0
- package/LICENSE +21 -0
- package/README.md +3 -0
- package/index.d.ts +2 -0
- package/index.js +13 -0
- package/index.js.map +1 -0
- package/package.json +48 -0
- package/useCss.d.ts +1 -0
- package/useCss.js +11 -0
- package/useCss.js.map +1 -0
package/CssInliner.d.ts
ADDED
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.createImportInlin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AM,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/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Webiny
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
package/index.d.ts
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from "@webiny/website-builder-react";
|
|
2
|
+
export * from "./useCss";
|
|
3
|
+
import { setHeadersProvider } from "@webiny/website-builder-react";
|
|
4
|
+
setHeadersProvider(async () => {
|
|
5
|
+
// Settings @ts-expect-error breaks the build if the dependency is installed in the repo.
|
|
6
|
+
// @ts-ignore This is a peer dependency.
|
|
7
|
+
const {
|
|
8
|
+
headers
|
|
9
|
+
} = await import("next/headers");
|
|
10
|
+
return await headers();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@webiny/website-builder-nextjs",
|
|
3
|
+
"version": "0.0.0-unstable.39223eb3c1",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/webiny/webiny-js.git"
|
|
8
|
+
},
|
|
9
|
+
"exports": {
|
|
10
|
+
".": "./index.js"
|
|
11
|
+
},
|
|
12
|
+
"description": "A Next.js integration SDK for Webiny Website Builder.",
|
|
13
|
+
"contributors": [
|
|
14
|
+
"Pavel Denisjuk <pavel@webiny.com>",
|
|
15
|
+
"Sven Al Hamad <sven@webiny.com>",
|
|
16
|
+
"Adrian Smijulj <adrian@webiny.com>"
|
|
17
|
+
],
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@webiny/website-builder-react": "0.0.0-unstable.39223eb3c1",
|
|
21
|
+
"postcss": "8.5.6"
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"next": "^15"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@webiny/project-utils": "0.0.0-unstable.39223eb3c1",
|
|
28
|
+
"typescript": "5.3.3"
|
|
29
|
+
},
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public",
|
|
32
|
+
"directory": "dist"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "node ../cli/bin.js run build",
|
|
36
|
+
"watch": "node ../cli/bin.js run watch"
|
|
37
|
+
},
|
|
38
|
+
"adio": {
|
|
39
|
+
"ignore": {
|
|
40
|
+
"dependencies": [
|
|
41
|
+
"postcss",
|
|
42
|
+
"next",
|
|
43
|
+
"@webiny/website-builder-react"
|
|
44
|
+
]
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"gitHead": "39223eb3c19f7398d2cf6da389b33061a67b1075"
|
|
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,11 @@
|
|
|
1
|
+
"use server";
|
|
2
|
+
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { CSSInliner } from "./CssInliner";
|
|
5
|
+
export async function useCss(cssFile) {
|
|
6
|
+
const entryCss = cssFile ?? path.resolve(process.cwd(), "src/theme/theme.css");
|
|
7
|
+
const inliner = new CSSInliner();
|
|
8
|
+
return await inliner.load(entryCss);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=useCss.js.map
|
package/useCss.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["path","CSSInliner","useCss","cssFile","entryCss","resolve","process","cwd","inliner","load"],"sources":["useCss.ts"],"sourcesContent":["\"use server\";\nimport path from \"path\";\nimport { CSSInliner } from \"~/CssInliner\";\n\nexport async function useCss(cssFile?: string) {\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;AACvB,SAASC,UAAU;AAEnB,OAAO,eAAeC,MAAMA,CAACC,OAAgB,EAAE;EAC3C,MAAMC,QAAQ,GAAGD,OAAO,IAAIH,IAAI,CAACK,OAAO,CAACC,OAAO,CAACC,GAAG,CAAC,CAAC,EAAE,qBAAqB,CAAC;EAE9E,MAAMC,OAAO,GAAG,IAAIP,UAAU,CAAC,CAAC;EAChC,OAAO,MAAMO,OAAO,CAACC,IAAI,CAACL,QAAQ,CAAC;AACvC","ignoreList":[]}
|