@wenyan-md/core 1.0.8 → 1.0.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.
@@ -3,19 +3,19 @@ const n = `/*
3
3
  * https://github.com/sumruler/typora-theme-phycat
4
4
  */
5
5
 
6
- :root {
6
+ :root {
7
7
  /* 标题后小图标,借鉴自思源笔记主题——Savor */
8
8
  --h1-r-graphic: url("https://cdn.phycat.cn/img/mdicon/green/h1_icon.svg")
9
9
  no-repeat center;
10
10
  --h2-r-graphic: url("https://cdn.phycat.cn/img/mdicon/green/h2_icon.svg")
11
11
  no-repeat center;
12
- --h3-r-graphic: url("https://cdn.phycat.cn/img/mdicon/green/h3_icon.svg")
12
+ --h3-r-graphic: url("data:image/svg+xml;utf8,<svg fill='rgba(74, 200, 141, 0.5)' height='28' viewBox='0 0 32 32' width='24' xmlns='http://www.w3.org/2000/svg'><path d='M4.571 25.143c-1.257 0-2.286 1.029-2.286 2.286s1.029 2.286 2.286 2.286 2.286-1.029 2.286-2.286-1.029-2.286-2.286-2.286zM4.571 18.286c-1.257 0-2.286 1.029-2.286 2.286s1.029 2.286 2.286 2.286 2.286-1.029 2.286-2.286-1.029-2.286-2.286-2.286zM11.429 25.143c-1.257 0-2.286 1.029-2.286 2.286s1.029 2.286 2.286 2.286 2.286-1.029 2.286-2.286-1.029-2.286-2.286-2.286z'/></svg>")
13
13
  no-repeat center;
14
- --h4-r-graphic: url("https://cdn.phycat.cn/img/mdicon/green/h4_icon.svg")
14
+ --h4-r-graphic: url("data:image/svg+xml;utf8,<svg fill='rgba(74, 200, 141, 0.5)' height='24' viewBox='0 0 32 32' width='24' xmlns='http://www.w3.org/2000/svg'><path d='M4.571 25.143c-1.257 0-2.286 1.029-2.286 2.286s1.029 2.286 2.286 2.286 2.286-1.029 2.286-2.286-1.029-2.286-2.286-2.286zM4.571 18.286c-1.257 0-2.286 1.029-2.286 2.286s1.029 2.286 2.286 2.286 2.286-1.029 2.286-2.286-1.029-2.286-2.286-2.286zM11.429 25.143c-1.257 0-2.286 1.029-2.286 2.286s1.029 2.286 2.286 2.286 2.286-1.029 2.286-2.286-1.029-2.286-2.286-2.286zM11.429 22.857c1.257 0 2.286-1.029 2.286-2.286s-1.029-2.286-2.286-2.286-2.286 1.029-2.286 2.286 1.029 2.286 2.286 2.286z'/></svg>")
15
15
  no-repeat center;
16
- --h5-r-graphic: url("https://cdn.phycat.cn/img/mdicon/green/h5_icon.svg")
16
+ --h5-r-graphic: url("data:image/svg+xml;utf8,<svg fill='rgba(74, 200, 141, 0.5)' height='24' viewBox='0 0 32 32' width='24' xmlns='http://www.w3.org/2000/svg'><path d='M4.571 18.286c-1.257 0-2.286 1.029-2.286 2.286s1.029 2.286 2.286 2.286 2.286-1.029 2.286-2.286-1.029-2.286-2.286-2.286zM11.429 22.857c1.257 0 2.286-1.029 2.286-2.286s-1.029-2.286-2.286-2.286-2.286 1.029-2.286 2.286 1.029 2.286 2.286 2.286zM4.571 25.143c-1.257 0-2.286 1.029-2.286 2.286s1.029 2.286 2.286 2.286 2.286-1.029 2.286-2.286-1.029-2.286-2.286-2.286zM11.429 25.143c-1.257 0-2.286 1.029-2.286 2.286s1.029 2.286 2.286 2.286 2.286-1.029 2.286-2.286-1.029-2.286-2.286-2.286zM4.571 11.429c-1.257 0-2.286 1.029-2.286 2.286s1.029 2.286 2.286 2.286 2.286-1.029 2.286-2.286-1.029-2.286-2.286-2.286z'/></svg>")
17
17
  no-repeat center;
18
- --h6-r-graphic: url("https://cdn.phycat.cn/img/mdicon/green/h6_icon.svg")
18
+ --h6-r-graphic: url("data:image/svg+xml;utf8,<svg fill='rgba(74, 200, 141, 0.5)' height='24' viewBox='0 0 32 32' width='24' xmlns='http://www.w3.org/2000/svg'><path d='M4.571 25.143c-1.257 0-2.286 1.029-2.286 2.286s1.029 2.286 2.286 2.286 2.286-1.029 2.286-2.286-1.029-2.286-2.286-2.286zM4.571 18.286c-1.257 0-2.286 1.029-2.286 2.286s1.029 2.286 2.286 2.286 2.286-1.029 2.286-2.286-1.029-2.286-2.286-2.286zM4.571 11.429c-1.257 0-2.286 1.029-2.286 2.286s1.029 2.286 2.286 2.286 2.286-1.029 2.286-2.286-1.029-2.286-2.286-2.286zM11.429 18.286c-1.257 0-2.286 1.029-2.286 2.286s1.029 2.286 2.286 2.286 2.286-1.029 2.286-2.286-1.029-2.286-2.286-2.286zM11.429 25.143c-1.257 0-2.286 1.029-2.286 2.286s1.029 2.286 2.286 2.286 2.286-1.029 2.286-2.286-1.029-2.286-2.286-2.286zM11.429 16c1.257 0 2.286-1.029 2.286-2.286s-1.029-2.286-2.286-2.286-2.286 1.029-2.286 2.286 1.029 2.286 2.286 2.286z'/></svg>")
19
19
  no-repeat center;
20
20
 
21
21
  /* 是否开启网格背景?1 是;0 否 */
@@ -47,7 +47,7 @@ const n = `/*
47
47
  }
48
48
  #wenyan {
49
49
  font-size: 14px;
50
- font-family:var(--sans-serif-font);
50
+ font-family: var(--sans-serif-font);
51
51
  margin: 0 auto;
52
52
  padding: 15px;
53
53
  line-height: 1.75;
@@ -56,17 +56,21 @@ const n = `/*
56
56
  word-break: break-word;
57
57
  word-wrap: break-word;
58
58
  text-align: left;
59
- background-image: linear-gradient(90deg,
60
- rgba(50, 0, 0, 0.05) calc(3% * var(--bg-grid)),
61
- rgba(0, 0, 0, 0) calc(3% * var(--bg-grid))),
62
- linear-gradient(360deg,
63
- rgba(50, 0, 0, 0.05) calc(3% * var(--bg-grid)),
64
- rgba(0, 0, 0, 0) calc(3% * var(--bg-grid)));
65
- background-size: 20px 20px;
66
- background-position: center center;
59
+ background-image: linear-gradient(
60
+ 90deg,
61
+ rgba(50, 0, 0, 0.05) calc(3% * var(--bg-grid)),
62
+ rgba(0, 0, 0, 0) calc(3% * var(--bg-grid))
63
+ ),
64
+ linear-gradient(
65
+ 360deg,
66
+ rgba(50, 0, 0, 0.05) calc(3% * var(--bg-grid)),
67
+ rgba(0, 0, 0, 0) calc(3% * var(--bg-grid))
68
+ );
69
+ background-size: 20px 20px;
70
+ background-position: center center;
67
71
  }
68
72
  #wenyan p {
69
- text-align:justify;
73
+ text-align: justify;
70
74
  color: #333;
71
75
  margin: 10px 10px;
72
76
  word-spacing: 2px;
@@ -75,7 +79,7 @@ const n = `/*
75
79
  #wenyan h4::after,
76
80
  #wenyan h5::after,
77
81
  #wenyan h6::after {
78
- content: '';
82
+ content: "";
79
83
  margin-left: 0.2em;
80
84
  height: 2em;
81
85
  width: 1.2em;
@@ -113,9 +117,12 @@ const n = `/*
113
117
  background: var(--head-title-h2-background);
114
118
  background-size: 200% 100%;
115
119
  background-position: 0% 0%;
116
- transition: all ease-in-out 0.1s;
120
+ display: inline-block;
117
121
  }
118
- #wenyan h3,h4,h5,h6{
122
+ #wenyan h3,
123
+ h4,
124
+ h5,
125
+ h6 {
119
126
  font-weight: bold;
120
127
  display: flex;
121
128
  align-items: top;
@@ -135,7 +142,7 @@ const n = `/*
135
142
  font-size: 1.15em;
136
143
  }
137
144
  #wenyan h4::before {
138
- content: '';
145
+ content: "";
139
146
  margin-right: 7px;
140
147
  margin-top: 8px;
141
148
  background-color: var(--head-title-color);
@@ -149,7 +156,7 @@ const n = `/*
149
156
  font-size: 1.1em;
150
157
  }
151
158
  #wenyan h5::before {
152
- content: '';
159
+ content: "";
153
160
  margin-right: 7px;
154
161
  margin-top: 8px;
155
162
  display: inline-block;
@@ -164,60 +171,60 @@ const n = `/*
164
171
  font-size: 1.1em;
165
172
  }
166
173
  #wenyan h6::before {
167
- content: '';
174
+ content: "";
168
175
  color: var(--head-title-color);
169
176
  margin-right: 7px;
170
177
  }
171
178
 
172
179
  #wenyan ol {
173
- margin-left: 2px;
174
- padding-left: 12px;
175
- margin-bottom: 0px;
176
- margin-top: 0px;
180
+ margin-left: 2px;
181
+ padding-left: 12px;
182
+ margin-bottom: 0px;
183
+ margin-top: 0px;
177
184
  }
178
185
 
179
186
  #wenyan ul {
180
- list-style-type: disc;
181
- margin-bottom: 0px;
182
- margin-top: 0px;
187
+ list-style-type: disc;
188
+ margin-bottom: 0px;
189
+ margin-top: 0px;
183
190
  }
184
191
 
185
192
  #wenyan ul ul {
186
- list-style-type: circle;
193
+ list-style-type: circle;
187
194
  }
188
195
 
189
196
  #wenyan ul ul ul {
190
- list-style-type: square;
197
+ list-style-type: square;
191
198
  }
192
199
 
193
200
  #wenyan ol {
194
- padding-left: 27px;
195
- list-style-type: decimal;
201
+ padding-left: 27px;
202
+ list-style-type: decimal;
196
203
  }
197
204
  #wenyan ol ol {
198
- list-style-type: lower-alpha;
205
+ list-style-type: lower-alpha;
199
206
  }
200
207
  #wenyan ol ol ol {
201
- list-style-type: lower-roman;
208
+ list-style-type: lower-roman;
202
209
  }
203
210
 
204
211
  #wenyan li {
205
- color: #333;
206
- margin: 0px 6px;
207
- word-spacing: 2px;
208
- line-height: 2.5;
212
+ color: #333;
213
+ margin: 0px 6px;
214
+ word-spacing: 2px;
215
+ line-height: 2.5;
209
216
  }
210
217
 
211
218
  #wenyan li {
212
- position: relative;
219
+ position: relative;
213
220
  }
214
- #wenyan li > p{
215
- margin:0;
221
+ #wenyan li > p {
222
+ margin: 0;
216
223
  }
217
224
  #wenyan blockquote {
218
- font-size:12px;
225
+ font-size: 12px;
219
226
  margin-left: 12px;
220
- text-align:justify;
227
+ text-align: justify;
221
228
  padding: 12px;
222
229
  background: var(--element-color-soo-shallow);
223
230
  border: 0px solid var(--element-color);
@@ -255,7 +262,7 @@ const n = `/*
255
262
  }
256
263
  #wenyan img {
257
264
  max-width: 90%;
258
- display:block;
265
+ display: block;
259
266
  border-radius: 6px;
260
267
  margin: 10px auto;
261
268
  object-fit: contain;
@@ -275,14 +282,14 @@ const n = `/*
275
282
  border-radius: 5px;
276
283
  line-height: 2;
277
284
  margin: 1em 0.5em;
278
- padding: .5em;
285
+ padding: 0.5em;
279
286
  box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px;
280
287
  }
281
288
  #wenyan pre code {
282
289
  font-family: var(--monospace-font);
283
290
  display: block;
284
291
  overflow-x: auto;
285
- margin: .5em;
292
+ margin: 0.5em;
286
293
  padding: 0;
287
294
  }
288
295
  #wenyan table {
package/dist/publish.js CHANGED
@@ -1,24 +1,24 @@
1
- import { JSDOM as W } from "jsdom";
2
- import { FormData as L } from "formdata-node";
3
- import { createReadStream as N } from "fs";
4
- import { stat as x } from "fs/promises";
5
- import b, { basename as j } from "path";
6
- var I = (t, e, r) => {
1
+ import { JSDOM as P } from "jsdom";
2
+ import { createReadStream as W } from "fs";
3
+ import { stat as B } from "fs/promises";
4
+ import b, { basename as L } from "path";
5
+ import { FormData as N, Blob as j } from "formdata-node";
6
+ var F = (t, e, r) => {
7
7
  if (!e.has(t))
8
8
  throw TypeError("Cannot " + r);
9
- }, c = (t, e, r) => (I(t, e, "read from private field"), r ? r.call(t) : e.get(t)), p = (t, e, r) => {
9
+ }, c = (t, e, r) => (F(t, e, "read from private field"), r ? r.call(t) : e.get(t)), p = (t, e, r) => {
10
10
  if (e.has(t))
11
11
  throw TypeError("Cannot add the same private member more than once");
12
12
  e instanceof WeakSet ? e.add(t) : e.set(t, r);
13
- }, w = (t, e, r, a) => (I(t, e, "write to private field"), e.set(t, r), r), z = (t) => typeof t == "object" && t != null && !Array.isArray(t), h = (t) => typeof t == "function", R = (t) => z(t) && h(t[Symbol.asyncIterator]), v = 65536;
14
- async function* q(t) {
15
- if (t.byteLength <= v) {
13
+ }, y = (t, e, r, a) => (F(t, e, "write to private field"), e.set(t, r), r), I = (t) => typeof t == "object" && t != null && !Array.isArray(t), h = (t) => typeof t == "function", R = (t) => I(t) && h(t[Symbol.asyncIterator]), T = 65536;
14
+ async function* z(t) {
15
+ if (t.byteLength <= T) {
16
16
  yield t;
17
17
  return;
18
18
  }
19
19
  let e = 0;
20
20
  for (; e < t.byteLength; ) {
21
- const r = Math.min(t.byteLength - e, v), a = t.buffer.slice(e, e + r);
21
+ const r = Math.min(t.byteLength - e, T), a = t.buffer.slice(e, e + r);
22
22
  e += a.byteLength, yield new Uint8Array(a);
23
23
  }
24
24
  }
@@ -31,51 +31,51 @@ async function* C(t) {
31
31
  yield a;
32
32
  }
33
33
  }
34
- async function* $(t) {
34
+ async function* x(t) {
35
35
  for await (const e of t)
36
- yield* q(e);
36
+ yield* z(e);
37
37
  }
38
- var U = (t) => {
38
+ var D = (t) => {
39
39
  if (R(t))
40
- return $(t);
40
+ return x(t);
41
41
  if (h(t.getReader))
42
- return $(C(t));
42
+ return x(C(t));
43
43
  throw new TypeError(
44
44
  "Unsupported data source: Expected either ReadableStream or async iterable."
45
45
  );
46
46
  };
47
- async function* D(t) {
47
+ async function* U(t) {
48
48
  let e = 0;
49
49
  for (; e !== t.size; ) {
50
50
  const a = await t.slice(
51
51
  e,
52
- Math.min(t.size, e + v)
52
+ Math.min(t.size, e + T)
53
53
  ).arrayBuffer();
54
54
  e += a.byteLength, yield new Uint8Array(a);
55
55
  }
56
56
  }
57
57
  async function* S(t, e = !1) {
58
58
  for (const r of t)
59
- ArrayBuffer.isView(r) ? e ? yield* q(r) : yield r : h(r.stream) ? yield* U(r.stream()) : yield* D(r);
59
+ ArrayBuffer.isView(r) ? e ? yield* z(r) : yield r : h(r.stream) ? yield* D(r.stream()) : yield* U(r);
60
60
  }
61
61
  function* H(t, e, r = 0, a) {
62
62
  a ??= e;
63
63
  let n = r < 0 ? Math.max(e + r, 0) : Math.min(r, e), i = a < 0 ? Math.max(e + a, 0) : Math.min(a, e);
64
64
  const s = Math.max(i - n, 0);
65
65
  let o = 0;
66
- for (const d of t) {
66
+ for (const l of t) {
67
67
  if (o >= s)
68
68
  break;
69
- const l = ArrayBuffer.isView(d) ? d.byteLength : d.size;
70
- if (n && l <= n)
71
- n -= l, i -= l;
69
+ const f = ArrayBuffer.isView(l) ? l.byteLength : l.size;
70
+ if (n && f <= n)
71
+ n -= f, i -= f;
72
72
  else {
73
- let f;
74
- ArrayBuffer.isView(d) ? (f = d.subarray(n, Math.min(l, i)), o += f.byteLength) : (f = d.slice(n, Math.min(l, i)), o += f.size), i -= l, n = 0, yield f;
73
+ let d;
74
+ ArrayBuffer.isView(l) ? (d = l.subarray(n, Math.min(f, i)), o += d.byteLength) : (d = l.slice(n, Math.min(f, i)), o += d.size), i -= f, n = 0, yield d;
75
75
  }
76
76
  }
77
77
  }
78
- var u, _, g, O = class A {
78
+ var u, _, g, O = class v {
79
79
  /**
80
80
  * Returns a new [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) object.
81
81
  * The content of the blob consists of the concatenation of the values given in the parameter array.
@@ -102,10 +102,10 @@ var u, _, g, O = class A {
102
102
  ArrayBuffer.isView(i) ? s = new Uint8Array(i.buffer.slice(
103
103
  i.byteOffset,
104
104
  i.byteOffset + i.byteLength
105
- )) : i instanceof ArrayBuffer ? s = new Uint8Array(i.slice(0)) : i instanceof A ? s = i : s = a.encode(String(i)), w(this, g, c(this, g) + (ArrayBuffer.isView(s) ? s.byteLength : s.size)), c(this, u).push(s);
105
+ )) : i instanceof ArrayBuffer ? s = new Uint8Array(i.slice(0)) : i instanceof v ? s = i : s = a.encode(String(i)), y(this, g, c(this, g) + (ArrayBuffer.isView(s) ? s.byteLength : s.size)), c(this, u).push(s);
106
106
  }
107
107
  const n = r.type === void 0 ? "" : String(r.type);
108
- w(this, _, /^[\x20-\x7E]*$/.test(n) ? n : "");
108
+ y(this, _, /^[\x20-\x7E]*$/.test(n) ? n : "");
109
109
  }
110
110
  static [Symbol.hasInstance](e) {
111
111
  return !!(e && typeof e == "object" && h(e.constructor) && (h(e.stream) || h(e.arrayBuffer)) && /^(Blob|File)$/.test(e[Symbol.toStringTag]));
@@ -130,7 +130,7 @@ var u, _, g, O = class A {
130
130
  * @param contentType The content type to assign to the new Blob; this will be the value of its type property. The default value is an empty string.
131
131
  */
132
132
  slice(e, r, a) {
133
- return new A(H(c(this, u), this.size, e, r), {
133
+ return new v(H(c(this, u), this.size, e, r), {
134
134
  type: a
135
135
  });
136
136
  }
@@ -178,8 +178,8 @@ var u, _, g, O = class A {
178
178
  u = /* @__PURE__ */ new WeakMap();
179
179
  _ = /* @__PURE__ */ new WeakMap();
180
180
  g = /* @__PURE__ */ new WeakMap();
181
- var T = O;
182
- Object.defineProperties(T.prototype, {
181
+ var A = O;
182
+ Object.defineProperties(A.prototype, {
183
183
  type: { enumerable: !0 },
184
184
  size: { enumerable: !0 },
185
185
  slice: { enumerable: !0 },
@@ -187,7 +187,7 @@ Object.defineProperties(T.prototype, {
187
187
  text: { enumerable: !0 },
188
188
  arrayBuffer: { enumerable: !0 }
189
189
  });
190
- var M, k, V = class extends T {
190
+ var k, M, V = class extends A {
191
191
  /**
192
192
  * Creates a new File instance.
193
193
  *
@@ -196,22 +196,22 @@ var M, k, V = class extends T {
196
196
  * @param options An options object containing optional attributes for the file.
197
197
  */
198
198
  constructor(t, e, r = {}) {
199
- if (super(t, r), p(this, M, void 0), p(this, k, 0), arguments.length < 2)
199
+ if (super(t, r), p(this, k, void 0), p(this, M, 0), arguments.length < 2)
200
200
  throw new TypeError(
201
201
  `Failed to construct 'File': 2 arguments required, but only ${arguments.length} present.`
202
202
  );
203
- w(this, M, String(e));
203
+ y(this, k, String(e));
204
204
  const a = r.lastModified === void 0 ? Date.now() : Number(r.lastModified);
205
- Number.isNaN(a) || w(this, k, a);
205
+ Number.isNaN(a) || y(this, M, a);
206
206
  }
207
207
  static [Symbol.hasInstance](t) {
208
- return t instanceof T && t[Symbol.toStringTag] === "File" && typeof t.name == "string";
208
+ return t instanceof A && t[Symbol.toStringTag] === "File" && typeof t.name == "string";
209
209
  }
210
210
  /**
211
211
  * Name of the file referenced by the File object.
212
212
  */
213
213
  get name() {
214
- return c(this, M);
214
+ return c(this, k);
215
215
  }
216
216
  /* c8 ignore next 3 */
217
217
  get webkitRelativePath() {
@@ -221,36 +221,36 @@ var M, k, V = class extends T {
221
221
  * The last modified date of the file as the number of milliseconds since the Unix epoch (January 1, 1970 at midnight). Files without a known last modified date return the current date.
222
222
  */
223
223
  get lastModified() {
224
- return c(this, k);
224
+ return c(this, M);
225
225
  }
226
226
  get [Symbol.toStringTag]() {
227
227
  return "File";
228
228
  }
229
229
  };
230
- M = /* @__PURE__ */ new WeakMap();
231
230
  k = /* @__PURE__ */ new WeakMap();
232
- var m, y, J = class P {
231
+ M = /* @__PURE__ */ new WeakMap();
232
+ var m, w, J = class q {
233
233
  constructor(e) {
234
- p(this, m, void 0), p(this, y, void 0), w(this, m, e.path), w(this, y, e.start || 0), this.name = j(c(this, m)), this.size = e.size, this.lastModified = e.lastModified;
234
+ p(this, m, void 0), p(this, w, void 0), y(this, m, e.path), y(this, w, e.start || 0), this.name = L(c(this, m)), this.size = e.size, this.lastModified = e.lastModified;
235
235
  }
236
236
  slice(e, r) {
237
- return new P({
237
+ return new q({
238
238
  path: c(this, m),
239
239
  lastModified: this.lastModified,
240
- start: c(this, y) + e,
240
+ start: c(this, w) + e,
241
241
  size: r - e
242
242
  });
243
243
  }
244
244
  async *stream() {
245
- const { mtimeMs: e } = await x(c(this, m));
245
+ const { mtimeMs: e } = await B(c(this, m));
246
246
  if (e > this.lastModified)
247
247
  throw new DOMException(
248
248
  "The requested file could not be read, typically due to permission problems that have occurred after a reference to a file was acquired.",
249
249
  "NotReadableError"
250
250
  );
251
- this.size && (yield* N(c(this, m), {
252
- start: c(this, y),
253
- end: c(this, y) + this.size - 1
251
+ this.size && (yield* W(c(this, m), {
252
+ start: c(this, w),
253
+ end: c(this, w) + this.size - 1
254
254
  }));
255
255
  }
256
256
  get [Symbol.toStringTag]() {
@@ -258,11 +258,11 @@ var m, y, J = class P {
258
258
  }
259
259
  };
260
260
  m = /* @__PURE__ */ new WeakMap();
261
- y = /* @__PURE__ */ new WeakMap();
261
+ w = /* @__PURE__ */ new WeakMap();
262
262
  var G = J;
263
263
  function K(t, { mtimeMs: e, size: r }, a, n = {}) {
264
264
  let i;
265
- z(a) ? [n, i] = [a, void 0] : i = a;
265
+ I(a) ? [n, i] = [a, void 0] : i = a;
266
266
  const s = new G({ path: t, size: r, lastModified: e });
267
267
  return i || (i = s.name), new V([s], i, {
268
268
  ...n,
@@ -270,90 +270,101 @@ function K(t, { mtimeMs: e, size: r }, a, n = {}) {
270
270
  });
271
271
  }
272
272
  async function X(t, e, r) {
273
- const a = await x(t);
273
+ const a = await B(t);
274
274
  return K(t, a, e, r);
275
275
  }
276
276
  /*! Based on fetch-blob. MIT License. Jimmy Wärting <https://jimmy.warting.se/opensource> & David Frank */
277
277
  const Z = "https://api.weixin.qq.com/cgi-bin/token", Q = "https://api.weixin.qq.com/cgi-bin/draft/add", Y = "https://api.weixin.qq.com/cgi-bin/material/add_material", ee = process.env.WECHAT_APP_ID || "", te = process.env.WECHAT_APP_SECRET || "";
278
278
  async function re() {
279
- try {
280
- const e = await (await fetch(`${Z}?grant_type=client_credential&appid=${ee}&secret=${te}`)).json();
281
- if (e.access_token)
282
- return e;
283
- throw e.errcode ? new Error(`获取 Access Token 失败,错误码:${e.errcode},${e.errmsg}`) : new Error(`获取 Access Token 失败: ${e}`);
284
- } catch (t) {
285
- throw t;
279
+ const t = await fetch(`${Z}?grant_type=client_credential&appid=${ee}&secret=${te}`);
280
+ if (!t.ok) {
281
+ const e = await t.text();
282
+ throw new Error(`获取AccessToken失败: ${t.status} ${e}`);
286
283
  }
284
+ return await t.json();
287
285
  }
288
- async function F(t, e, r, a) {
289
- const n = new L();
286
+ async function ae(t, e, r, a) {
287
+ const n = new N();
290
288
  n.append("media", e, r);
291
289
  const i = await fetch(`${Y}?access_token=${a}&type=${t}`, {
292
290
  method: "POST",
293
291
  body: n
294
292
  });
295
293
  if (!i.ok) {
296
- const d = await i.text();
297
- throw new Error(`上传失败: ${i.status} ${d}`);
294
+ const o = await i.text();
295
+ throw new Error(`上传素材失败: ${i.status} ${o}`);
298
296
  }
299
297
  const s = await i.json();
300
- if (s.errcode)
301
- throw new Error(`上传失败,错误码:${s.errcode},错误信息:${s.errmsg}`);
302
- const o = s.url.replace("http://", "https://");
303
- return s.url = o, s;
298
+ return s.url && s.url.startsWith("http://") && (s.url = s.url.replace("http://", "https://")), s;
304
299
  }
305
- async function E(t, e, r) {
300
+ async function ie(t, e, r, a) {
301
+ const n = await fetch(`${Q}?access_token=${a}`, {
302
+ method: "POST",
303
+ body: JSON.stringify({
304
+ articles: [
305
+ {
306
+ title: t,
307
+ content: e,
308
+ thumb_media_id: r
309
+ }
310
+ ]
311
+ })
312
+ });
313
+ if (!n.ok) {
314
+ const i = await n.text();
315
+ throw new Error(`发布失败: ${n.status} ${i}`);
316
+ }
317
+ return await n.json();
318
+ }
319
+ async function $(t, e, r) {
320
+ let a, n;
306
321
  if (t.startsWith("http")) {
307
- const a = await fetch(t);
308
- if (!a.ok || !a.body)
322
+ const s = await fetch(t);
323
+ if (!s.ok || !s.body)
309
324
  throw new Error(`Failed to download image from URL: ${t}`);
310
- const n = b.basename(t.split("?")[0]), i = b.extname(n), s = r ?? (i === "" ? `${n}.jpg` : n), o = await a.arrayBuffer();
311
- return await F("image", new Blob([o]), s, e);
325
+ const o = b.basename(t.split("?")[0]), l = b.extname(o);
326
+ n = r ?? (l === "" ? `${o}.jpg` : o);
327
+ const f = await s.arrayBuffer();
328
+ a = new j([f]);
312
329
  } else {
313
- const a = t, n = b.basename(a), i = b.extname(n), s = r ?? (i === "" ? `${n}.jpg` : n), o = await X(a);
314
- return await F("image", o, s, e);
330
+ const s = b.basename(t), o = b.extname(s);
331
+ n = r ?? (o === "" ? `${s}.jpg` : s), a = await X(t);
315
332
  }
333
+ const i = await ae("image", a, n, e);
334
+ if (i.errcode)
335
+ throw new Error(`上传失败,错误码:${i.errcode},错误信息:${i.errmsg}`);
336
+ return i;
316
337
  }
317
- async function ae(t, e) {
338
+ async function se(t, e) {
318
339
  if (!t.includes("<img"))
319
340
  return { html: t, firstImageId: "" };
320
- const r = new W(t), a = r.window.document, i = Array.from(a.querySelectorAll("img")).map(async (l) => {
321
- const f = l.getAttribute("src");
322
- if (f) {
323
- if (f.startsWith("https://mmbiz.qpic.cn"))
324
- return f;
341
+ const r = new P(t), a = r.window.document, i = Array.from(a.querySelectorAll("img")).map(async (f) => {
342
+ const d = f.getAttribute("src");
343
+ if (d) {
344
+ if (d.startsWith("https://mmbiz.qpic.cn"))
345
+ return d;
325
346
  {
326
- const B = await E(f, e);
327
- return l.setAttribute("src", B.url), B.media_id;
347
+ const E = await $(d, e);
348
+ return f.setAttribute("src", E.url), E.media_id;
328
349
  }
329
350
  }
330
351
  return null;
331
352
  }), o = (await Promise.all(i)).filter(Boolean)[0] || "";
332
353
  return { html: r.serialize(), firstImageId: o };
333
354
  }
334
- async function le(t, e, r) {
335
- try {
336
- const a = await re(), n = e.replace(/\n<li/g, "<li").replace(/<\/li>\n/g, "</li>"), { html: i, firstImageId: s } = await ae(n, a.access_token);
337
- let o = "";
338
- if (r ? o = (await E(r, a.access_token, "cover.jpg")).media_id : s.startsWith("https://mmbiz.qpic.cn") ? o = (await E(s, a.access_token, "cover.jpg")).media_id : o = s, !o)
339
- throw new Error("你必须指定一张封面图或者在正文中至少出现一张图片。");
340
- const l = await (await fetch(`${Q}?access_token=${a.access_token}`, {
341
- method: "POST",
342
- body: JSON.stringify({
343
- articles: [{
344
- title: t,
345
- content: i,
346
- thumb_media_id: o
347
- }]
348
- })
349
- })).json();
350
- if (l.media_id)
351
- return l;
352
- throw l.errcode ? new Error(`上传到公众号草稿失败,错误码:${l.errcode},${l.errmsg}`) : new Error(`上传到公众号草稿失败: ${l}`);
353
- } catch (a) {
354
- throw a;
355
- }
355
+ async function de(t, e, r) {
356
+ const a = await re();
357
+ if (!a.access_token)
358
+ throw a.errcode ? new Error(`获取 Access Token 失败,错误码:${a.errcode},${a.errmsg}`) : new Error(`获取 Access Token 失败: ${a}`);
359
+ const n = e.replace(/\n<li/g, "<li").replace(/<\/li>\n/g, "</li>"), { html: i, firstImageId: s } = await se(n, a.access_token);
360
+ let o = "";
361
+ if (r ? o = (await $(r, a.access_token, "cover.jpg")).media_id : s.startsWith("https://mmbiz.qpic.cn") ? o = (await $(s, a.access_token, "cover.jpg")).media_id : o = s, !o)
362
+ throw new Error("你必须指定一张封面图或者在正文中至少出现一张图片。");
363
+ const l = await ie(t, i, o, a.access_token);
364
+ if (l.media_id)
365
+ return l;
366
+ throw l.errcode ? new Error(`上传到公众号草稿失败,错误码:${l.errcode},${l.errmsg}`) : new Error(`上传到公众号草稿失败: ${l}`);
356
367
  }
357
368
  export {
358
- le as publishToDraft
369
+ de as publishToDraft
359
370
  };