@opendesign-plus-test/plugins 0.0.1-rc.1

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,50 @@
1
+ import { App } from 'vue';
2
+ import { OpenAnalytics } from '@opensig/open-analytics';
3
+ type Awaitable<T> = T | Promise<T>;
4
+ /**
5
+ * 上报埋点数据
6
+ *
7
+ * @param event 事件名
8
+ * @param eventData 上报数据
9
+ * @param $service service字段取值
10
+ * @param options options
11
+ *
12
+ * @example
13
+ * // 最终上报数据格式:
14
+ * {
15
+ * event: string; // 事件名
16
+ * properties: {
17
+ * $service: string; // service字段
18
+ * ...eventData // 上报数据
19
+ * }
20
+ * }
21
+ */
22
+ export declare function oaReport<T extends Record<string, any>>(event: string, eventData?: T | ((...opts: any[]) => Awaitable<T>) | null, $service?: string, options?: {
23
+ immediate: boolean;
24
+ eventOptions?: any;
25
+ }): Promise<void> | undefined;
26
+ type ReportFn = ConstructorParameters<typeof OpenAnalytics>[0]['request'];
27
+ type ConfigOptions = {
28
+ /** appID */
29
+ appKey: string;
30
+ /** 埋点上报时携带的$service字段值 */
31
+ service?: string;
32
+ /** 字符串:上报数据的接口地址,默认会使用fetch调用;函数:自定义接口调用逻辑,要上报的数据将作为参数传入 */
33
+ request: string | ReportFn;
34
+ /** 判断cookie是否同意的逻辑,每当document.cookie被赋值的时候会自动调用,返回boolean控制分析埋点启用/禁用 */
35
+ isCookieAgreed?: () => boolean;
36
+ /** 开启埋点时的回调 */
37
+ onEnable?: () => void;
38
+ /** 关闭埋点时的回调 */
39
+ onDisable?: () => void;
40
+ /**
41
+ * 上报PV事件时的钩子,可以返回一个对象作为额外的数据被附加到最终调接口上报的数据中,返回undefined则不附加任何东西
42
+ *
43
+ * @param from 路由切换前的url路径
44
+ * @param to 路由切换后的url路径
45
+ * @returns 附加数据/覆盖原有的数据
46
+ */
47
+ onPageView?: (from: string, to: string) => Record<string, any> | void;
48
+ };
49
+ export declare const initOpenDesignAnalytics: (app: App, options: ConfigOptions) => void;
50
+ export {};
@@ -0,0 +1,26 @@
1
+ import { Plugin } from 'vite';
2
+ /**
3
+ * 检查主题插件
4
+ * @param options - 配置项
5
+ * @param options.cookieKey - cookie 键名
6
+ * @param options.lightValue - 浅色主题值
7
+ * @param options.darkValue - 深色主题值
8
+ * @param options.attribute - HTML 元素挂载主题的属性名
9
+ * @param options.attributeLightValue - 浅色主题下 attribute 属性设置的值,默认跟随 lightValue
10
+ * @param options.attributeDarkValue - 深色主题下 attribute 属性设置的值,默认跟随 darkValue
11
+ * @param options.classLightValue - 浅色主题下应用的 CSS 类名,默认跟随 lightValue
12
+ * @param options.classDarkValue - 深色主题下应用的 CSS 类名,默认跟随 darkValue
13
+ * @param options.filename - 要在入口插入检查主题的 js 文件名,默认为 check-theme.js
14
+ * @returns theme 插件实例
15
+ */
16
+ export declare function CheckThemePlugin(options: {
17
+ cookieKey: string;
18
+ lightValue?: string;
19
+ darkValue?: string;
20
+ attribute?: string;
21
+ attributeLightValue?: string;
22
+ attributeDarkValue?: string;
23
+ classLightValue?: string;
24
+ classDarkValue?: string;
25
+ filename?: string;
26
+ }): Plugin;
@@ -0,0 +1 @@
1
+ export * from './core/vite-check-theme-plugin';
package/dist/index.js ADDED
@@ -0,0 +1,72 @@
1
+ const r = {}, k = `
2
+ (function () {
3
+ function getCookie(key) {
4
+ const name = encodeURIComponent(key) + '=';
5
+ const decodedCookies = decodeURIComponent(document.cookie);
6
+ const cookies = decodedCookies.split('; ');
7
+ for (let cookie of cookies) {
8
+ if (cookie.startsWith(name)) {
9
+ return cookie.substring(name.length);
10
+ }
11
+ }
12
+
13
+ return null;
14
+ }
15
+
16
+ const e = getCookie('$COOKIE_KEY') || 'auto';
17
+ const a = window.matchMedia('(prefers-color-scheme: dark)').matches;
18
+ if (!e || e === 'auto' ? a : e === '$DARK_VALUE') {
19
+ document.documentElement.classList.add('$CLASS_DARK_VALUE');
20
+ document.documentElement.setAttribute('$ATTRIBUTE_NAME', '$ATTRIBUTE_DARK_VALUE');
21
+ } else {
22
+ document.documentElement.classList.add('$CLASS_LIGHT_VALUE');
23
+ document.documentElement.setAttribute('$ATTRIBUTE_NAME', '$ATTRIBUTE_LIGHT_VALUE');
24
+ }
25
+ })();
26
+ `.trim();
27
+ function U(T) {
28
+ const {
29
+ cookieKey: p,
30
+ lightValue: a = "light",
31
+ darkValue: n = "dark",
32
+ attribute: E = "data-o-theme",
33
+ attributeLightValue: $ = a,
34
+ attributeDarkValue: _ = n,
35
+ classLightValue: L = a,
36
+ classDarkValue: h = n,
37
+ filename: t = "check-theme.js"
38
+ } = T, u = k.replace(/\$COOKIE_KEY/g, p).replace(/\$LIGHT_VALUE/g, a).replace(/\$DARK_VALUE/g, n).replace(/\$CLASS_LIGHT_VALUE/g, L).replace(/\$CLASS_DARK_VALUE/g, h).replace(/\$ATTRIBUTE_NAME/g, E).replace(/\$ATTRIBUTE_LIGHT_VALUE/g, $).replace(/\$ATTRIBUTE_DARK_VALUE/g, _);
39
+ let s = "", d = !1, i = "", o = !1;
40
+ return {
41
+ name: "vite-check-theme-plugin",
42
+ enforce: "pre",
43
+ configResolved(e) {
44
+ if (s = e.base, d = e.command === "serve", i = e.build.outDir, o = !!e.vitepress, !o || !Array.isArray(e.vitepress.site.head))
45
+ return;
46
+ const l = e.vitepress.site.head.find((c) => {
47
+ var m, A;
48
+ return c[0] === "script" && ((A = (m = c[1]) == null ? void 0 : m.src) == null ? void 0 : A.startsWith(`${s}${t}`));
49
+ });
50
+ l ? l[1].src = `${s}${t}?t=${(/* @__PURE__ */ new Date()).getTime()}` : e.vitepress.site.head.push([
51
+ "script",
52
+ {
53
+ src: `${s}${t}?t=${(/* @__PURE__ */ new Date()).getTime()}`
54
+ }
55
+ ]);
56
+ },
57
+ generateBundle() {
58
+ d || r.existsSync(r.join(i, t)) || (r.existsSync(i) || r.mkdirSync(i, { recursive: !0 }), r.writeFileSync(r.join(i, t), u, "utf-8"));
59
+ },
60
+ configureServer(e) {
61
+ e.middlewares.use(`${s}${t}`, (l, c) => {
62
+ c.setHeader("Content-Type", "application/javascript"), c.end(u);
63
+ });
64
+ },
65
+ transformIndexHtml(e) {
66
+ return o ? e : e.replace("</head>", `<script src="${s}${t}?t=${(/* @__PURE__ */ new Date()).getTime()}"><\/script></head>`);
67
+ }
68
+ };
69
+ }
70
+ export {
71
+ U as CheckThemePlugin
72
+ };
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@opendesign-plus-test/plugins",
3
+ "version": "0.0.1-rc.1",
4
+ "type": "module",
5
+ "publishConfig": {
6
+ "access": "public",
7
+ "registry": "https://registry.npmjs.org/"
8
+ },
9
+ "files": [
10
+ "dist"
11
+ ],
12
+ "main": "./dist/index.js",
13
+ "module": "./dist/index.js",
14
+ "types": "./dist/index.d.ts",
15
+ "exports": {
16
+ ".": {
17
+ "types": "./dist/index.d.ts",
18
+ "import": "./dist/index.js"
19
+ },
20
+ "./analytics": {
21
+ "types": "./dist/analytics/analytics.d.ts",
22
+ "import": "./dist/analytics/index.js"
23
+ }
24
+ },
25
+ "devDependencies": {
26
+ "typescript": "~5.8.2",
27
+ "vite": "^6.2.3",
28
+ "vite-plugin-dts": "^4.5.3"
29
+ },
30
+ "dependencies": {
31
+ "@opensig/open-analytics": "^1.0.1"
32
+ },
33
+ "scripts": {
34
+ "build": "tsc && vite build"
35
+ }
36
+ }