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

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