@whnz/frontend-experience-vitals 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.
@@ -0,0 +1,7 @@
1
+ interface Plugin {
2
+ name: string;
3
+ setup(): void;
4
+ }
5
+ declare function vitalsPlugin(): Plugin;
6
+
7
+ export { type Plugin, vitalsPlugin };
package/dist/index.mjs ADDED
@@ -0,0 +1,51 @@
1
+ import { onFCP, onLCP, onCLS, onINP } from 'web-vitals';
2
+ import { report } from '@whnz/frontend-experience-core';
3
+
4
+ // src/index.ts
5
+ function vitalsPlugin() {
6
+ return {
7
+ name: "vitals",
8
+ setup() {
9
+ onFCP(
10
+ (m) => report({
11
+ type: "fcp",
12
+ value: m.value,
13
+ timestamp: Date.now()
14
+ })
15
+ );
16
+ onLCP(
17
+ (m) => {
18
+ var _a, _b, _c;
19
+ return report({
20
+ type: "lcp",
21
+ value: m.value,
22
+ timestamp: Date.now(),
23
+ extra: {
24
+ element: (_c = (_b = (_a = m.entries) == null ? void 0 : _a[0]) == null ? void 0 : _b.element) == null ? void 0 : _c.tagName
25
+ }
26
+ });
27
+ }
28
+ );
29
+ onCLS(
30
+ (m) => report({
31
+ type: "cls",
32
+ value: m.value,
33
+ timestamp: Date.now()
34
+ })
35
+ );
36
+ onINP((m) => {
37
+ if (m.value > 200) {
38
+ report({
39
+ type: "inp",
40
+ value: m.value,
41
+ timestamp: Date.now()
42
+ });
43
+ }
44
+ });
45
+ }
46
+ };
47
+ }
48
+
49
+ export { vitalsPlugin };
50
+ //# sourceMappingURL=index.mjs.map
51
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;AAQO,SAAS,YAAA,GAAuB;AACrC,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,QAAA;AAAA,IACN,KAAA,GAAQ;AACN,MAAA,KAAA;AAAA,QAAM,CAAC,MACL,MAAA,CAAO;AAAA,UACL,IAAA,EAAM,KAAA;AAAA,UACN,OAAO,CAAA,CAAE,KAAA;AAAA,UACT,SAAA,EAAW,KAAK,GAAA;AAAI,SACrB;AAAA,OACH;AAEA,MAAA,KAAA;AAAA,QAAM,CAAC,CAAA,KAAG;AApBhB,UAAA,IAAA,EAAA,EAAA,EAAA,EAAA,EAAA;AAqBQ,UAAA,OAAA,MAAA,CAAO;AAAA,YACL,IAAA,EAAM,KAAA;AAAA,YACN,OAAO,CAAA,CAAE,KAAA;AAAA,YACT,SAAA,EAAW,KAAK,GAAA,EAAI;AAAA,YACpB,KAAA,EAAO;AAAA,cACL,UAAS,EAAA,GAAA,CAAA,EAAA,GAAA,CAAA,EAAA,GAAA,CAAA,CAAE,OAAA,KAAF,mBAAY,CAAA,CAAA,KAAZ,IAAA,GAAA,MAAA,GAAA,EAAA,CAAgB,YAAhB,IAAA,GAAA,MAAA,GAAA,EAAA,CAAyB;AAAA;AACpC,WACD,CAAA;AAAA,QAAA;AAAA,OACH;AAEA,MAAA,KAAA;AAAA,QAAM,CAAC,MACL,MAAA,CAAO;AAAA,UACL,IAAA,EAAM,KAAA;AAAA,UACN,OAAO,CAAA,CAAE,KAAA;AAAA,UACT,SAAA,EAAW,KAAK,GAAA;AAAI,SACrB;AAAA,OACH;AAEA,MAAA,KAAA,CAAM,CAAC,CAAA,KAAM;AACX,QAAA,IAAI,CAAA,CAAE,QAAQ,GAAA,EAAK;AACjB,UAAA,MAAA,CAAO;AAAA,YACL,IAAA,EAAM,KAAA;AAAA,YACN,OAAO,CAAA,CAAE,KAAA;AAAA,YACT,SAAA,EAAW,KAAK,GAAA;AAAI,WACrB,CAAA;AAAA,QACH;AAAA,MACF,CAAC,CAAA;AAAA,IACH;AAAA,GACF;AACF","file":"index.mjs","sourcesContent":["import { onFCP, onLCP, onCLS, onINP } from 'web-vitals';\nimport { report } from '@whnz/frontend-experience-core';\n\nexport interface Plugin {\n name: string;\n setup(): void;\n}\n\nexport function vitalsPlugin(): Plugin {\n return {\n name: 'vitals',\n setup() {\n onFCP((m) =>\n report({\n type: 'fcp',\n value: m.value,\n timestamp: Date.now(),\n }),\n );\n\n onLCP((m) =>\n report({\n type: 'lcp',\n value: m.value,\n timestamp: Date.now(),\n extra: {\n element: m.entries?.[0]?.element?.tagName,\n },\n }),\n );\n\n onCLS((m) =>\n report({\n type: 'cls',\n value: m.value,\n timestamp: Date.now(),\n }),\n );\n\n onINP((m) => {\n if (m.value > 200) {\n report({\n type: 'inp',\n value: m.value,\n timestamp: Date.now(),\n });\n }\n });\n },\n };\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "@whnz/frontend-experience-vitals",
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
+ "web-vitals": "^4.0.0",
12
+ "@whnz/frontend-experience-core": "1.0.0"
13
+ },
14
+ "scripts": {
15
+ "build": "tsup"
16
+ }
17
+ }