@opendesign-plus-test/plugins 0.0.1-rc.2 → 0.0.1-rc.20

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.ts CHANGED
@@ -1 +1,5 @@
1
1
  export * from './core/vite-check-theme-plugin';
2
+ export * from './analytics/plugin';
3
+ export * from './analytics/directive';
4
+ export * from './external-link-guard';
5
+ export * from './sitemap/generate-lastmod-changefreq';
package/dist/index.js CHANGED
@@ -1,4 +1,6 @@
1
- const r = {}, k = `
1
+ import { i as B, o as K, v as O } from "./plugin-lvjNLBe-.js";
2
+ import { g as j } from "./generate-lastmod-changefreq-Wk3kOITw.js";
3
+ const f = {}, $ = `
2
4
  (function () {
3
5
  function getCookie(key) {
4
6
  const name = encodeURIComponent(key) + '=';
@@ -24,49 +26,290 @@ const r = {}, k = `
24
26
  }
25
27
  })();
26
28
  `.trim();
27
- function U(T) {
29
+ function R(e) {
28
30
  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;
31
+ cookieKey: n,
32
+ lightValue: t = "light",
33
+ darkValue: r = "dark",
34
+ attribute: a = "data-o-theme",
35
+ attributeLightValue: s = t,
36
+ attributeDarkValue: c = r,
37
+ classLightValue: w = t,
38
+ classDarkValue: p = r,
39
+ filename: l = "check-theme.js"
40
+ } = e, g = $.replace(/\$COOKIE_KEY/g, n).replace(/\$LIGHT_VALUE/g, t).replace(/\$DARK_VALUE/g, r).replace(/\$CLASS_LIGHT_VALUE/g, w).replace(/\$CLASS_DARK_VALUE/g, p).replace(/\$ATTRIBUTE_NAME/g, a).replace(/\$ATTRIBUTE_LIGHT_VALUE/g, s).replace(/\$ATTRIBUTE_DARK_VALUE/g, c);
41
+ let d = "", h = !1, u = "", m = !1;
40
42
  return {
41
43
  name: "vite-check-theme-plugin",
42
44
  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
+ configResolved(o) {
46
+ if (d = o.base, h = o.command === "serve", u = o.build.outDir, m = !!o.vitepress, !m || !Array.isArray(o.vitepress.site.head))
45
47
  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}`));
48
+ const k = o.vitepress.site.head.find((x) => {
49
+ var y, E;
50
+ return x[0] === "script" && ((E = (y = x[1]) == null ? void 0 : y.src) == null ? void 0 : E.startsWith(`${d}${l}`));
49
51
  });
50
- l ? l[1].src = `${s}${t}?t=${(/* @__PURE__ */ new Date()).getTime()}` : e.vitepress.site.head.push([
52
+ k ? k[1].src = `${d}${l}?t=${(/* @__PURE__ */ new Date()).getTime()}` : o.vitepress.site.head.push([
51
53
  "script",
52
54
  {
53
- src: `${s}${t}?t=${(/* @__PURE__ */ new Date()).getTime()}`
55
+ src: `${d}${l}?t=${(/* @__PURE__ */ new Date()).getTime()}`
54
56
  }
55
57
  ]);
56
58
  },
57
59
  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"));
60
+ h || f.existsSync(f.join(u, l)) || (f.existsSync(u) || f.mkdirSync(u, { recursive: !0 }), f.writeFileSync(f.join(u, l), g, "utf-8"));
59
61
  },
60
- configureServer(e) {
61
- e.middlewares.use(`${s}${t}`, (l, c) => {
62
- c.setHeader("Content-Type", "application/javascript"), c.end(u);
62
+ configureServer(o) {
63
+ o.middlewares.use(`${d}${l}`, (k, x) => {
64
+ x.setHeader("Content-Type", "application/javascript"), x.end(g);
63
65
  });
64
66
  },
65
- transformIndexHtml(e) {
66
- return o ? e : e.replace("</head>", `<script src="${s}${t}?t=${(/* @__PURE__ */ new Date()).getTime()}"><\/script></head>`);
67
+ transformIndexHtml(o) {
68
+ return m ? o : o.replace("</head>", `<script src="${d}${l}?t=${(/* @__PURE__ */ new Date()).getTime()}"><\/script></head>`);
69
+ }
70
+ };
71
+ }
72
+ function b(e) {
73
+ if (typeof window > "u")
74
+ return !1;
75
+ let n;
76
+ try {
77
+ n = new URL(e, window.location.href);
78
+ } catch {
79
+ return !1;
80
+ }
81
+ return /^https?:$/.test(n.protocol) ? n.hostname !== window.location.hostname : !1;
82
+ }
83
+ function A(e, n = []) {
84
+ return n.some((t) => {
85
+ if (t === "*") return !0;
86
+ if (t.startsWith("*.")) {
87
+ const r = t.slice(2);
88
+ return e === r || e.endsWith(`.${r}`);
89
+ }
90
+ return e === t || e.endsWith(`.${t}`);
91
+ });
92
+ }
93
+ const T = {
94
+ zh: {
95
+ title: "即将跳转到外部网站",
96
+ message: (e) => `您将要访问的链接不属于${e},请关注您的账号安全。`,
97
+ cancel: "取消",
98
+ confirm: "继续前往"
99
+ },
100
+ en: {
101
+ title: "You will be redirected to an external website",
102
+ message: (e) => `The link you are about to visit does not belong to ${e}. Please ensure the security of your account.`,
103
+ cancel: "Cancel",
104
+ confirm: "Continue"
105
+ }
106
+ };
107
+ let i = null, v = !1;
108
+ function C(e, n, t) {
109
+ const r = T[e];
110
+ return new Promise((a) => {
111
+ if (v) {
112
+ a(!1);
113
+ return;
114
+ }
115
+ v = !0, _(), i || (i = document.createElement("div"), i.className = "elg-mask", i.innerHTML = `
116
+ <div class="elg-modal">
117
+ <div class="elg-title"></div>
118
+ <div class="elg-content">
119
+ <div class="elg-message"></div>
120
+ <div class="elg-url"></div>
121
+ </div>
122
+
123
+ <div class="elg-actions">
124
+ <button class="elg-btn elg-confirm">${r.confirm}</button>
125
+ <button class="elg-btn elg-cancel">${r.cancel}</button>
126
+ </div>
127
+ </div>
128
+ `, document.body.appendChild(i));
129
+ const s = i.querySelector(".elg-title"), c = i.querySelector(".elg-message"), w = i.querySelector(".elg-url"), p = i.querySelector(".elg-cancel"), l = i.querySelector(".elg-confirm");
130
+ s.textContent = r.title, c.textContent = r.message(t), w.textContent = n, i.style.display = "flex";
131
+ const g = (m) => {
132
+ i && (i.style.display = "none", i.removeEventListener("click", u), p.removeEventListener("click", d), l.removeEventListener("click", h), v = !1, a(m));
133
+ }, d = () => g(!1), h = () => g(!0), u = (m) => {
134
+ m.target === i && g(!1);
135
+ };
136
+ i.addEventListener("click", u), p.addEventListener("click", d), l.addEventListener("click", h);
137
+ });
138
+ }
139
+ function _() {
140
+ if (document.getElementById("elg-confirm-style"))
141
+ return;
142
+ const e = document.createElement("style");
143
+ e.id = "elg-confirm-style", e.textContent = `
144
+ :root {
145
+ --elg-primary: var(--o-color-primary1);
146
+ --elg-text: var(--o-color-info1);
147
+ --elg-mask: rgba(0,0,0,.45);
148
+ }
149
+
150
+ .elg-mask {
151
+ position: fixed;
152
+ inset: 0;
153
+ display: none;
154
+ align-items: center;
155
+ justify-content: center;
156
+ background: var(--elg-mask);
157
+ z-index: 9999;
158
+ }
159
+
160
+ .elg-modal {
161
+ min-width: 272px;
162
+ background: var(--o-color-fill2);
163
+ border-radius: 8px;
164
+ padding: 32px;
165
+ color: var(--elg-text);
166
+ margin: 24px;
167
+ box-shadow: 0p 3px 8px rgba(111, 111, 117, .08)
168
+ word-break: break-word;
169
+
170
+ @media (max-width: 840px) {
171
+ padding: 24px;
172
+ }
173
+
174
+ @media (max-width: 600px) {
175
+ padding: 16px;
176
+ }
177
+ }
178
+
179
+ .elg-title {
180
+ font-size: 24px;
181
+ line-height: 32px;
182
+ font-weight: 500;
183
+ text-align: center;
184
+ margin-bottom: 24px;
185
+
186
+ @media (max-width: 1440px) {
187
+ font-size: 20px;
188
+ line-height: 28px;
189
+ }
190
+
191
+ @media (max-width: 1200px) {
192
+ font-size: 18px;
193
+ line-height: 26px;
194
+ }
195
+ }
196
+
197
+ .elg-content{
198
+ max-width: 600px;
199
+ }
200
+
201
+ .elg-url,.elg-message {
202
+ font-size: 18px;
203
+ line-height: 26px;
204
+ word-break: break-all;
205
+
206
+ @media (max-width: 1440px) {
207
+ font-size: 16px;
208
+ line-height: 24px;
209
+ }
210
+
211
+ @media (max-width: 1200px) {
212
+ font-size: 14px;
213
+ line-height: 22px;
214
+ }
215
+ }
216
+
217
+ .elg-url{
218
+ color: var(--o-color-info2);
219
+ margin-top: 24px;
220
+ }
221
+
222
+ .elg-actions {
223
+ display: flex;
224
+ justify-content: center;
225
+ gap: 12px;
226
+ margin-top: 24px;
227
+ }
228
+
229
+ .elg-btn {
230
+ min-width: 80px;
231
+ height: 40px;
232
+ border-radius: 20px;
233
+ padding: 0 23px;
234
+ border: none;
235
+ cursor: pointer;
236
+ }
237
+
238
+ .elg-cancel {
239
+ background-color: transparent;
240
+ border: 1px solid var(--elg-primary);
241
+ color: var(--elg-primary);
242
+ &:hover{
243
+ background: var(--elg-primary);
244
+ color: #fff;
245
+ }
246
+ }
247
+
248
+ .elg-confirm {
249
+ background: var(--elg-primary);
250
+ color: #fff;
251
+ &:hover{
252
+ background: rgba(81, 119, 202)
253
+ }
254
+ }
255
+ `, document.head.appendChild(e);
256
+ }
257
+ async function L(e, n) {
258
+ if (n.showCustomConfirm)
259
+ return C(n.lang || "zh", e, n.community || "");
260
+ const t = n.message ?? `即将离开本站,前往第三方网站:
261
+
262
+ ${e}`;
263
+ return Promise.resolve(window.confirm(t));
264
+ }
265
+ function U(e) {
266
+ const n = window.open;
267
+ document.addEventListener(
268
+ "click",
269
+ async (t) => {
270
+ const r = t.target;
271
+ if (!r)
272
+ return;
273
+ const a = r.closest("a[href]");
274
+ if (!a)
275
+ return;
276
+ const s = a.getAttribute("href");
277
+ if (!s || s.startsWith("#") || !b(s))
278
+ return;
279
+ const c = new URL(s, window.location.href);
280
+ if (A(c.hostname, e.whitelist))
281
+ return;
282
+ t.preventDefault(), await L(c.href, e) && ((a.getAttribute("target") || "_self") === "_blank" ? n.call(window, c.href, "_blank", "noopener,noreferrer") : window.location.href = c.href);
283
+ },
284
+ !0
285
+ );
286
+ }
287
+ function S(e) {
288
+ const n = window.open;
289
+ window.open = async function(t, ...r) {
290
+ if (t) {
291
+ const a = t.toString();
292
+ if (b(a)) {
293
+ const s = new URL(a, window.location.href);
294
+ if (!A(s.hostname, e.whitelist) && !await L(s.href, e))
295
+ return null;
296
+ }
297
+ }
298
+ return n.call(window, t, ...r);
299
+ };
300
+ }
301
+ function I(e = {}) {
302
+ return {
303
+ install() {
304
+ typeof window > "u" || (U(e), S(e));
67
305
  }
68
306
  };
69
307
  }
70
308
  export {
71
- U as CheckThemePlugin
309
+ R as CheckThemePlugin,
310
+ I as createExternalLinkGuard,
311
+ j as generateLastmodAndChangefreq,
312
+ B as initOpenDesignAnalytics,
313
+ K as oaReport,
314
+ O as vAnalytics
72
315
  };
@@ -0,0 +1,102 @@
1
+ import { defineNuxtModule as W, addVitePlugin as O } from "nuxt/kit";
2
+ import { g as v, m as A } from "../../generate-lastmod-changefreq-Wk3kOITw.js";
3
+ import { existsSync as b, readFileSync as D, createWriteStream as q, writeFileSync as C, readdirSync as T } from "node:fs";
4
+ import m, { join as z } from "node:path";
5
+ import { pipeline as J } from "node:stream/promises";
6
+ const I = W({
7
+ meta: {
8
+ name: "sitemap",
9
+ configKey: "sitemap"
10
+ },
11
+ setup(t, f) {
12
+ O(
13
+ v({
14
+ rootDir: f.options.dir.app,
15
+ // @ts-ignore
16
+ pageEntryPattern: "**/pages/**/*.vue",
17
+ ...t.lastmodAndChangefreqOptions
18
+ })
19
+ );
20
+ const w = Array.isArray(t.ignore) ? t.ignore : typeof t.ignore == "string" ? [t.ignore] : [], c = t.hostname.endsWith("/") ? t.hostname.slice(0, -1) : t.hostname;
21
+ f.hook("close", async () => {
22
+ var h, u, x, g, P, y;
23
+ const r = m.join(f.options.rootDir, ".output", "public");
24
+ if (!b(r))
25
+ return;
26
+ const s = {};
27
+ if ((h = t.index) != null && h.items)
28
+ for (const e of t.index.items)
29
+ e.pathPrefix && (s[e.pathPrefix.startsWith("/") ? e.pathPrefix : `/${e.pathPrefix}`] = []);
30
+ else
31
+ s["/"] = [];
32
+ const d = (e) => {
33
+ const n = T(e, {
34
+ withFileTypes: !0,
35
+ encoding: "utf-8"
36
+ });
37
+ for (const o of n) {
38
+ if (o.isDirectory()) {
39
+ d(m.join(e, o.name));
40
+ continue;
41
+ }
42
+ if (o.name === "index.html") {
43
+ const l = `/${m.relative(r, e).replace(/\\/g, "/")}`;
44
+ for (const i of w)
45
+ A(l, i);
46
+ for (const i in s)
47
+ l.startsWith(i) && s[i].push(l);
48
+ }
49
+ }
50
+ };
51
+ d(r), console.log("[module:generate-sitemap] collect html done");
52
+ const j = ((u = t.lastmodAndChangefreqOptions) == null ? void 0 : u.outputFile) || m.join(f.options.dir.app, "last-modified.json"), p = JSON.parse(D(j, "utf-8"));
53
+ await Promise.all(
54
+ (((x = t.index) == null ? void 0 : x.items) ?? [{ pathPrefix: "/", filename: "sitemap.xml" }]).filter((e) => e.pathPrefix && e.filename).map(async (e) => {
55
+ const n = e.pathPrefix.startsWith("/") ? e.pathPrefix : `/${e.pathPrefix}`, o = e.filename.endsWith(".xml") ? e.filename : `${e.filename}.xml`, l = q(m.join(r, n, o), "utf-8");
56
+ try {
57
+ await J(function* () {
58
+ yield `<?xml version="1.0" encoding="UTF-8"?>
59
+ <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
60
+ `;
61
+ for (const i of s[n]) {
62
+ if (!i.startsWith("/"))
63
+ continue;
64
+ const a = p[`pages${i.endsWith("/") ? i.slice(0, -1) : i}/index.vue`] || p[`pages${i}.md`];
65
+ a != null && a.lastmod && (a.lastmod = new Date(a.lastmod).toISOString());
66
+ const F = {
67
+ loc: c + i,
68
+ ...a
69
+ };
70
+ yield ` <url>
71
+ ${Object.entries(F).map(([$, S]) => ` <${$}>${S}</${$}>`).join(`
72
+ `)}
73
+ </url>
74
+ `;
75
+ }
76
+ yield "</urlset>";
77
+ }, l);
78
+ } catch (i) {
79
+ console.log("[module:generate-sitemap] error", i);
80
+ return;
81
+ }
82
+ })
83
+ ), (g = t.index) != null && g.indexFilename && ((y = (P = t.index) == null ? void 0 : P.items) != null && y.length) && C(
84
+ z(r, t.index.indexFilename),
85
+ `<?xml version="1.0" encoding="UTF-8"?>
86
+ <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
87
+ ${t.index.items.filter((e) => e.loc || e.filename).map((e) => {
88
+ const n = e.pathPrefix ? e.pathPrefix.startsWith("/") ? e.pathPrefix : `/${e.pathPrefix}` : "";
89
+ return `<sitemap>
90
+ <loc>${e.filename ? `${c}${n}/${e.filename}` : e.loc}</loc>
91
+ </sitemap>`;
92
+ })}
93
+ </sitemapindex>
94
+ `,
95
+ "utf-8"
96
+ ), console.log("[module:generate-sitemap] generate done");
97
+ });
98
+ }
99
+ });
100
+ export {
101
+ I as default
102
+ };
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;