@whnz/frontend-experience-css 1.0.0
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.mts +11 -0
- package/dist/index.mjs +53 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +16 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
interface Plugin {
|
|
2
|
+
name: string;
|
|
3
|
+
setup(): void;
|
|
4
|
+
}
|
|
5
|
+
interface CssPluginOptions {
|
|
6
|
+
keySelectors?: string[];
|
|
7
|
+
detectWhiteScreen?: boolean;
|
|
8
|
+
}
|
|
9
|
+
declare function cssPlugin(options?: CssPluginOptions): Plugin;
|
|
10
|
+
|
|
11
|
+
export { type CssPluginOptions, type Plugin, cssPlugin };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { report } from '@whnz/frontend-experience-core';
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
function detectWhiteScreen(delay = 3e3) {
|
|
5
|
+
setTimeout(() => {
|
|
6
|
+
const elements = document.elementsFromPoint(
|
|
7
|
+
window.innerWidth / 2,
|
|
8
|
+
window.innerHeight / 2
|
|
9
|
+
);
|
|
10
|
+
const isWhite = elements.every(
|
|
11
|
+
(el) => ["HTML", "BODY"].includes(el.tagName)
|
|
12
|
+
);
|
|
13
|
+
if (isWhite) {
|
|
14
|
+
report({
|
|
15
|
+
type: "white-screen",
|
|
16
|
+
timestamp: Date.now()
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}, delay);
|
|
20
|
+
}
|
|
21
|
+
function checkVisibility(selector) {
|
|
22
|
+
const el = document.querySelector(selector);
|
|
23
|
+
if (!el) return;
|
|
24
|
+
const rect = el.getBoundingClientRect();
|
|
25
|
+
const visible = rect.width > 0 && rect.height > 0 && rect.bottom > 0 && rect.top < window.innerHeight;
|
|
26
|
+
if (!visible) {
|
|
27
|
+
report({
|
|
28
|
+
type: "css-visibility-error",
|
|
29
|
+
timestamp: Date.now(),
|
|
30
|
+
extra: { selector }
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function cssPlugin(options = {}) {
|
|
35
|
+
return {
|
|
36
|
+
name: "css",
|
|
37
|
+
setup() {
|
|
38
|
+
var _a;
|
|
39
|
+
if (options.detectWhiteScreen !== false) {
|
|
40
|
+
detectWhiteScreen();
|
|
41
|
+
}
|
|
42
|
+
if ((_a = options.keySelectors) == null ? void 0 : _a.length) {
|
|
43
|
+
requestIdleCallback(() => {
|
|
44
|
+
options.keySelectors.forEach(checkVisibility);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export { cssPlugin };
|
|
52
|
+
//# sourceMappingURL=index.mjs.map
|
|
53
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;AAYA,SAAS,iBAAA,CAAkB,QAAQ,GAAA,EAAM;AACvC,EAAA,UAAA,CAAW,MAAM;AACf,IAAA,MAAM,WAAW,QAAA,CAAS,iBAAA;AAAA,MACxB,OAAO,UAAA,GAAa,CAAA;AAAA,MACpB,OAAO,WAAA,GAAc;AAAA,KACvB;AAEA,IAAA,MAAM,UAAU,QAAA,CAAS,KAAA;AAAA,MAAM,CAAC,OAC9B,CAAC,MAAA,EAAQ,MAAM,CAAA,CAAE,QAAA,CAAS,GAAG,OAAO;AAAA,KACtC;AAEA,IAAA,IAAI,OAAA,EAAS;AACX,MAAA,MAAA,CAAO;AAAA,QACL,IAAA,EAAM,cAAA;AAAA,QACN,SAAA,EAAW,KAAK,GAAA;AAAI,OACrB,CAAA;AAAA,IACH;AAAA,EACF,GAAG,KAAK,CAAA;AACV;AAEA,SAAS,gBAAgB,QAAA,EAAkB;AACzC,EAAA,MAAM,EAAA,GAAK,QAAA,CAAS,aAAA,CAAc,QAAQ,CAAA;AAC1C,EAAA,IAAI,CAAC,EAAA,EAAI;AAET,EAAA,MAAM,IAAA,GAAO,GAAG,qBAAA,EAAsB;AACtC,EAAA,MAAM,OAAA,GACJ,IAAA,CAAK,KAAA,GAAQ,CAAA,IACb,IAAA,CAAK,MAAA,GAAS,CAAA,IACd,IAAA,CAAK,MAAA,GAAS,CAAA,IACd,IAAA,CAAK,GAAA,GAAM,MAAA,CAAO,WAAA;AAEpB,EAAA,IAAI,CAAC,OAAA,EAAS;AACZ,IAAA,MAAA,CAAO;AAAA,MACL,IAAA,EAAM,sBAAA;AAAA,MACN,SAAA,EAAW,KAAK,GAAA,EAAI;AAAA,MACpB,KAAA,EAAO,EAAE,QAAA;AAAS,KACnB,CAAA;AAAA,EACH;AACF;AAEO,SAAS,SAAA,CAAU,OAAA,GAA4B,EAAC,EAAW;AAChE,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,KAAA;AAAA,IACN,KAAA,GAAQ;AAvDZ,MAAA,IAAA,EAAA;AAwDM,MAAA,IAAI,OAAA,CAAQ,sBAAsB,KAAA,EAAO;AACvC,QAAA,iBAAA,EAAkB;AAAA,MACpB;AAEA,MAAA,IAAA,CAAI,EAAA,GAAA,OAAA,CAAQ,YAAA,KAAR,IAAA,GAAA,MAAA,GAAA,EAAA,CAAsB,MAAA,EAAQ;AAChC,QAAA,mBAAA,CAAoB,MAAM;AACxB,UAAA,OAAA,CAAQ,YAAA,CAAc,QAAQ,eAAe,CAAA;AAAA,QAC/C,CAAC,CAAA;AAAA,MACH;AAAA,IACF;AAAA,GACF;AACF","file":"index.mjs","sourcesContent":["import { report } from '@whnz/frontend-experience-core';\n\nexport interface Plugin {\n name: string;\n setup(): void;\n}\n\nexport interface CssPluginOptions {\n keySelectors?: string[];\n detectWhiteScreen?: boolean;\n}\n\nfunction detectWhiteScreen(delay = 3000) {\n setTimeout(() => {\n const elements = document.elementsFromPoint(\n window.innerWidth / 2,\n window.innerHeight / 2,\n );\n\n const isWhite = elements.every((el) =>\n ['HTML', 'BODY'].includes(el.tagName),\n );\n\n if (isWhite) {\n report({\n type: 'white-screen',\n timestamp: Date.now(),\n });\n }\n }, delay);\n}\n\nfunction checkVisibility(selector: string) {\n const el = document.querySelector(selector);\n if (!el) return;\n\n const rect = el.getBoundingClientRect();\n const visible =\n rect.width > 0 &&\n rect.height > 0 &&\n rect.bottom > 0 &&\n rect.top < window.innerHeight;\n\n if (!visible) {\n report({\n type: 'css-visibility-error',\n timestamp: Date.now(),\n extra: { selector },\n });\n }\n}\n\nexport function cssPlugin(options: CssPluginOptions = {}): Plugin {\n return {\n name: 'css',\n setup() {\n if (options.detectWhiteScreen !== false) {\n detectWhiteScreen();\n }\n\n if (options.keySelectors?.length) {\n requestIdleCallback(() => {\n options.keySelectors!.forEach(checkVisibility);\n });\n }\n },\n };\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@whnz/frontend-experience-css",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"@whnz/frontend-experience-core": "1.0.0"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsup"
|
|
15
|
+
}
|
|
16
|
+
}
|