qrcode-alipay 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.
package/dist/index.cjs ADDED
@@ -0,0 +1,755 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ createAlipayQRCode: () => createAlipayQRCode,
34
+ toDataURL: () => toDataURL,
35
+ toSvg: () => toSvg
36
+ });
37
+ module.exports = __toCommonJS(index_exports);
38
+
39
+ // src/create.ts
40
+ var import_qrcode = __toESM(require("qrcode"), 1);
41
+
42
+ // src/logo.ts
43
+ function createDefaultAlipayLogo(x, y, size) {
44
+ return {
45
+ tag: "svg",
46
+ attrs: {
47
+ x,
48
+ y,
49
+ width: size,
50
+ height: size,
51
+ viewBox: "0 0 47 47",
52
+ "aria-hidden": "true",
53
+ focusable: "false"
54
+ },
55
+ children: [
56
+ {
57
+ tag: "defs",
58
+ children: [
59
+ {
60
+ tag: "rect",
61
+ attrs: {
62
+ id: "alipay-logo-path",
63
+ x: 0,
64
+ y: 0,
65
+ width: 47,
66
+ height: 47,
67
+ rx: 7.5
68
+ }
69
+ },
70
+ {
71
+ tag: "linearGradient",
72
+ attrs: {
73
+ id: "alipay-logo-bg",
74
+ x1: "0%",
75
+ y1: "50%",
76
+ x2: "100%",
77
+ y2: "50%"
78
+ },
79
+ children: [
80
+ {
81
+ tag: "stop",
82
+ attrs: {
83
+ "stop-color": "#179EFF",
84
+ offset: "0%"
85
+ }
86
+ },
87
+ {
88
+ tag: "stop",
89
+ attrs: {
90
+ "stop-color": "#1677FF",
91
+ offset: "100%"
92
+ }
93
+ }
94
+ ]
95
+ },
96
+ {
97
+ tag: "linearGradient",
98
+ attrs: {
99
+ id: "alipay-logo-highlight-a",
100
+ x1: "43.5923819%",
101
+ y1: "97.1205235%",
102
+ x2: "51.5611353%",
103
+ y2: "36.3892384%"
104
+ },
105
+ children: [
106
+ {
107
+ tag: "stop",
108
+ attrs: {
109
+ "stop-color": "#FFFFFF",
110
+ "stop-opacity": 0.699999988,
111
+ offset: "0%"
112
+ }
113
+ },
114
+ {
115
+ tag: "stop",
116
+ attrs: {
117
+ "stop-color": "#FFFFFF",
118
+ "stop-opacity": 0.779999971,
119
+ offset: "13.3333325%"
120
+ }
121
+ },
122
+ {
123
+ tag: "stop",
124
+ attrs: {
125
+ "stop-color": "#FFFFFF",
126
+ "stop-opacity": 0.879999995,
127
+ offset: "31.666665%"
128
+ }
129
+ },
130
+ {
131
+ tag: "stop",
132
+ attrs: {
133
+ "stop-color": "#FFFFFF",
134
+ "stop-opacity": 0.949999988,
135
+ offset: "53.33333%"
136
+ }
137
+ },
138
+ {
139
+ tag: "stop",
140
+ attrs: {
141
+ "stop-color": "#FFFFFF",
142
+ "stop-opacity": 0.99000001,
143
+ offset: "74.999995%"
144
+ }
145
+ },
146
+ {
147
+ tag: "stop",
148
+ attrs: {
149
+ "stop-color": "#FFFFFF",
150
+ offset: "100%"
151
+ }
152
+ }
153
+ ]
154
+ },
155
+ {
156
+ tag: "linearGradient",
157
+ attrs: {
158
+ id: "alipay-logo-highlight-b",
159
+ x1: "41.6085117%",
160
+ y1: "52.2245791%",
161
+ x2: "60.9955549%",
162
+ y2: "40.6569108%"
163
+ },
164
+ children: [
165
+ {
166
+ tag: "stop",
167
+ attrs: {
168
+ "stop-color": "#FFFFFF",
169
+ offset: "0%"
170
+ }
171
+ },
172
+ {
173
+ tag: "stop",
174
+ attrs: {
175
+ "stop-color": "#FFFFFF",
176
+ "stop-opacity": 0.980000019,
177
+ offset: "20.8333342%"
178
+ }
179
+ },
180
+ {
181
+ tag: "stop",
182
+ attrs: {
183
+ "stop-color": "#FFFFFF",
184
+ "stop-opacity": 0.910000026,
185
+ offset: "45.8333352%"
186
+ }
187
+ },
188
+ {
189
+ tag: "stop",
190
+ attrs: {
191
+ "stop-color": "#FFFFFF",
192
+ "stop-opacity": 0.810000002,
193
+ offset: "74.999999%"
194
+ }
195
+ },
196
+ {
197
+ tag: "stop",
198
+ attrs: {
199
+ "stop-color": "#FFFFFF",
200
+ "stop-opacity": 0.699999988,
201
+ offset: "100%"
202
+ }
203
+ }
204
+ ]
205
+ },
206
+ {
207
+ tag: "linearGradient",
208
+ attrs: {
209
+ id: "alipay-logo-highlight-c",
210
+ x1: "25.999999%",
211
+ y1: "49.9925554%",
212
+ x2: "100%",
213
+ y2: "49.9925554%"
214
+ },
215
+ children: [
216
+ {
217
+ tag: "stop",
218
+ attrs: {
219
+ "stop-color": "#FFFFFF",
220
+ offset: "0%"
221
+ }
222
+ },
223
+ {
224
+ tag: "stop",
225
+ attrs: {
226
+ "stop-color": "#FFFFFF",
227
+ "stop-opacity": 0.400000006,
228
+ offset: "100%"
229
+ }
230
+ }
231
+ ]
232
+ },
233
+ {
234
+ tag: "linearGradient",
235
+ attrs: {
236
+ id: "alipay-logo-highlight-d",
237
+ x1: "16.0001332%",
238
+ y1: "50%",
239
+ x2: "100.000834%",
240
+ y2: "50%"
241
+ },
242
+ children: [
243
+ {
244
+ tag: "stop",
245
+ attrs: {
246
+ "stop-color": "#FFFFFF",
247
+ offset: "0%"
248
+ }
249
+ },
250
+ {
251
+ tag: "stop",
252
+ attrs: {
253
+ "stop-color": "#FFFFFF",
254
+ "stop-opacity": 0.5,
255
+ offset: "100%"
256
+ }
257
+ }
258
+ ]
259
+ }
260
+ ]
261
+ },
262
+ {
263
+ tag: "g",
264
+ attrs: {
265
+ stroke: "none",
266
+ "stroke-width": 1,
267
+ fill: "none",
268
+ "fill-rule": "evenodd"
269
+ },
270
+ children: [
271
+ {
272
+ tag: "mask",
273
+ attrs: {
274
+ id: "alipay-logo-mask",
275
+ fill: "white"
276
+ },
277
+ children: [
278
+ {
279
+ tag: "use",
280
+ attrs: {
281
+ href: "#alipay-logo-path"
282
+ }
283
+ }
284
+ ]
285
+ },
286
+ {
287
+ tag: "use",
288
+ attrs: {
289
+ fill: "#FFFFFF",
290
+ href: "#alipay-logo-path"
291
+ }
292
+ },
293
+ {
294
+ tag: "rect",
295
+ attrs: {
296
+ stroke: "#FFFFFF",
297
+ "stroke-width": 2.05241823,
298
+ fill: "url(#alipay-logo-bg)",
299
+ "fill-rule": "nonzero",
300
+ mask: "url(#alipay-logo-mask)",
301
+ x: 0.973790884,
302
+ y: 0.973790884,
303
+ width: 45.0524182,
304
+ height: 45.0524182,
305
+ rx: 6
306
+ }
307
+ },
308
+ {
309
+ tag: "g",
310
+ attrs: {
311
+ mask: "url(#alipay-logo-mask)"
312
+ },
313
+ children: [
314
+ {
315
+ tag: "g",
316
+ attrs: {
317
+ transform: "translate(8.142857, 10.190476)"
318
+ },
319
+ children: [
320
+ {
321
+ tag: "rect",
322
+ attrs: {
323
+ "fill-rule": "nonzero",
324
+ x: 0,
325
+ y: 0,
326
+ width: 31.3968239,
327
+ height: 27.3015862
328
+ }
329
+ },
330
+ {
331
+ tag: "path",
332
+ attrs: {
333
+ d: "M17.742816,4.04394007 L17.742816,0.237326697 C17.742816,0.105373047 17.6342039,0 17.5017738,0 C13.9490309,0 13.6269121,0.87241292 13.6269121,2.01158094 L13.6269121,4.04394007 L5.01163846,4.04394007 C4.51621702,4.04394007 4.2985174,5.1065464 4.29882812,5.91393232 C4.29882812,6.04778433 4.40284172,6.15837812 4.53717715,6.15837812 L13.627389,6.15837812 L13.627389,9.55555534 C9.91700665,9.55555534 7.94851184,9.55555534 7.72190452,9.55555534 C7.0247643,9.55555534 6.78515196,10.5990095 6.78658104,11.3793402 C6.78658104,11.5098686 6.89328718,11.6157179 7.0247643,11.6157179 L23.6318626,11.6157179 C23.8865166,11.6157179 23.9538689,13.1127501 24.1113319,12.9789038 C24.2292786,12.8786497 24.5001163,11.3888502 24.5001163,10.1015615 C24.5001163,9.51883888 23.7903099,9.55555534 23.428791,9.55555534 L17.9496384,9.55555534 L17.9496384,6.14285707 L26.1661358,6.15837812 C26.6615562,6.15837812 26.8792534,5.14228821 26.8789673,4.28838682 C26.8789673,4.15453434 26.774929,4.04394007 26.6405945,4.04394007 L17.742816,4.04394007 Z",
334
+ fill: "#FFFFFF",
335
+ "fill-rule": "nonzero"
336
+ }
337
+ },
338
+ {
339
+ tag: "g",
340
+ attrs: {
341
+ transform: "translate(0.000000, 10.102539)",
342
+ "fill-rule": "nonzero"
343
+ },
344
+ children: [
345
+ {
346
+ tag: "rect",
347
+ attrs: {
348
+ x: 0,
349
+ y: 0,
350
+ width: 31.3968239,
351
+ height: 17.2000275
352
+ }
353
+ },
354
+ {
355
+ tag: "path",
356
+ attrs: {
357
+ d: "M24.3553729,0.47939992 C24.3567953,0.215492636 24.1433825,0 23.8785224,0 L18.8337988,0 C18.8337988,2.99506307 18.1730781,5.57622766 17.1083984,7.71074438 C18.5436915,8.38522625 19.9799376,9.10812378 21.4914489,9.77501202 C23.2559114,6.94797659 24.3348823,3.70846701 24.3548894,0.47939992 L24.3553729,0.47939992 Z",
358
+ fill: "url(#alipay-logo-highlight-a)"
359
+ }
360
+ },
361
+ {
362
+ tag: "g",
363
+ attrs: {
364
+ transform: "translate(0.000000, 4.421875)"
365
+ },
366
+ children: [
367
+ {
368
+ tag: "rect",
369
+ attrs: {
370
+ x: 0,
371
+ y: 0,
372
+ width: 31.3968239,
373
+ height: 12.777669
374
+ }
375
+ },
376
+ {
377
+ tag: "g",
378
+ attrs: {
379
+ transform: "translate(0.000000, 5.681641)"
380
+ },
381
+ children: [
382
+ {
383
+ tag: "rect",
384
+ attrs: {
385
+ x: 0,
386
+ y: 0,
387
+ width: 18.7755203,
388
+ height: 7.05382442
389
+ }
390
+ },
391
+ {
392
+ tag: "path",
393
+ attrs: {
394
+ d: "M1.94238281,0.725270391 C1.94238281,5.44759703 11.7159986,7.35807705 16.2667303,4.42709255 C17.1694469,3.82618117 18.0078526,3.13983226 18.7757549,2.3851335 C18.5089893,2.2071383 16.2614908,0.706758976 15.0586643,0 C9.61045885,6.26447582 1.94238281,4.60461283 1.94238281,0.725270391 Z",
395
+ fill: "url(#alipay-logo-highlight-b)"
396
+ }
397
+ },
398
+ {
399
+ tag: "path",
400
+ attrs: {
401
+ d: "M16.2612572,4.38385558 C11.7105255,7.31484032 1.94262373,5.40103769 1.94214737,0.678710938 L0,0.678710938 C0,4.21867609 3.12925315,7.05425596 7.41036177,7.05425596 C10.773035,7.05425596 13.7660475,6.04276896 16.2612572,4.38433003 L16.2612572,4.38385558 Z",
402
+ fill: "url(#alipay-logo-highlight-c)"
403
+ }
404
+ }
405
+ ]
406
+ },
407
+ {
408
+ tag: "g",
409
+ children: [
410
+ {
411
+ tag: "rect",
412
+ attrs: {
413
+ x: 0,
414
+ y: 0,
415
+ width: 31.3968239,
416
+ height: 12.777669
417
+ }
418
+ },
419
+ {
420
+ tag: "path",
421
+ attrs: {
422
+ d: "M17.1091881,2.6067965 C17.1091881,2.6067965 17.1091881,2.6067965 17.1087132,2.6067965 C14.1033154,1.1951772 11.1007757,0 7.41036224,0 C3.05827498,0 0,2.82276368 0,6.40687132 C0,6.40687132 1.94214749,6.40687132 1.94214749,6.40687132 C1.94214749,4.38294935 4.1748786,2.92481422 6.88397646,2.92481422 C9.5930748,2.92481422 12.4231701,4.12189007 15.0584316,5.68207598 C16.3136578,6.42490864 17.5512581,7.25033045 18.7759972,8.06768417 C22.2658615,10.3968077 25.6509228,12.6618547 29.0326481,12.777669 C23.6068325,12.5806885 21.6280041,6.47047472 17.1087132,2.60727119 L17.1091881,2.6067965 Z",
423
+ fill: "#FFFFFF"
424
+ }
425
+ },
426
+ {
427
+ tag: "path",
428
+ attrs: {
429
+ d: "M28.5255661,12.7351904 C30.7192345,12.7351904 31.2946863,10.0059333 31.3956776,7.85907602 C31.415206,7.43948221 31.0865145,7.0858655 30.6649303,7.07257509 C24.6598501,6.88556147 20.4930706,4.51466763 16.3310547,2.55957031 C20.9246593,6.48637795 22.8934832,12.7351904 28.5255661,12.7351904 L28.5255661,12.7351904 Z",
430
+ fill: "url(#alipay-logo-highlight-d)"
431
+ }
432
+ }
433
+ ]
434
+ }
435
+ ]
436
+ }
437
+ ]
438
+ }
439
+ ]
440
+ }
441
+ ]
442
+ }
443
+ ]
444
+ }
445
+ ]
446
+ };
447
+ }
448
+
449
+ // src/render.ts
450
+ var XML_ESCAPE = {
451
+ "&": "&",
452
+ "<": "&lt;",
453
+ ">": "&gt;",
454
+ '"': "&quot;",
455
+ "'": "&#39;"
456
+ };
457
+ function escapeXml(value) {
458
+ return value.replace(/[&<>"']/g, (char) => XML_ESCAPE[char] ?? char);
459
+ }
460
+ function renderAttribute(name, value) {
461
+ if (value === null || value === void 0 || value === false) return "";
462
+ return ` ${name}="${escapeXml(String(value))}"`;
463
+ }
464
+ function renderSvgNode(node) {
465
+ if (typeof node === "string") return escapeXml(node);
466
+ const attrs = Object.entries(node.attrs ?? {}).map(([name, value]) => renderAttribute(name, value)).join("");
467
+ const children = node.children ?? [];
468
+ if (children.length === 0) {
469
+ return `<${node.tag}${attrs}/>`;
470
+ }
471
+ return `<${node.tag}${attrs}>${children.map(renderSvgNode).join("")}</${node.tag}>`;
472
+ }
473
+ function renderSvgDescriptor(descriptor) {
474
+ return renderSvgNode(descriptor);
475
+ }
476
+ function cloneElementWithAttrs(element, attrs) {
477
+ return {
478
+ ...element,
479
+ attrs: {
480
+ ...element.attrs,
481
+ ...attrs
482
+ },
483
+ children: element.children ? [...element.children] : void 0
484
+ };
485
+ }
486
+
487
+ // src/create.ts
488
+ var DEFAULT_SIZE = 240;
489
+ var DEFAULT_MARGIN = 0;
490
+ var DEFAULT_DARK_COLOR = "#111319";
491
+ var DEFAULT_LIGHT_COLOR = "#ffffff";
492
+ var DEFAULT_FINDER_COLOR = "#1677ff";
493
+ var DEFAULT_LOGO_FRAME_RATIO = 0.22;
494
+ var DEFAULT_LOGO_ICON_RATIO = 1;
495
+ var DEFAULT_LOGO_RADIUS_RATIO = 0.18;
496
+ var DEFAULT_ARIA_LABEL = "Alipay QR code";
497
+ function assertContent(value) {
498
+ if (typeof value !== "string" || value.length === 0) {
499
+ throw new TypeError("qrcode-alipay: value must be a non-empty string.");
500
+ }
501
+ }
502
+ function normalizeSize(size) {
503
+ if (typeof size === "number") {
504
+ return Number.isFinite(size) && size > 0 ? size : DEFAULT_SIZE;
505
+ }
506
+ if (typeof size === "string" && size.trim()) {
507
+ return size;
508
+ }
509
+ return DEFAULT_SIZE;
510
+ }
511
+ function normalizeMargin(margin) {
512
+ if (!Number.isFinite(margin)) return DEFAULT_MARGIN;
513
+ return Math.max(0, Math.round(margin ?? DEFAULT_MARGIN));
514
+ }
515
+ function normalizeRatio(value, fallback, min, max) {
516
+ if (!Number.isFinite(value)) return fallback;
517
+ return Math.min(max, Math.max(min, value ?? fallback));
518
+ }
519
+ function formatNumber(value) {
520
+ if (Number.isInteger(value)) return String(value);
521
+ return Number(value.toFixed(4)).toString();
522
+ }
523
+ function modulePath(x, y) {
524
+ return `M${formatNumber(x)} ${formatNumber(y)}h1v1h-1z`;
525
+ }
526
+ function isFinderModule(row, column, moduleCount) {
527
+ const inTopLeft = row < 7 && column < 7;
528
+ const inTopRight = row < 7 && column >= moduleCount - 7;
529
+ const inBottomLeft = row >= moduleCount - 7 && column < 7;
530
+ return inTopLeft || inTopRight || inBottomLeft;
531
+ }
532
+ function intersectsRect(x, y, rectX, rectY, rectSize) {
533
+ return x < rectX + rectSize && x + 1 > rectX && y < rectY + rectSize && y + 1 > rectY;
534
+ }
535
+ function normalizeLogoOptions(options) {
536
+ if (options.logo === false || options.logo?.enabled === false) {
537
+ return null;
538
+ }
539
+ return {
540
+ frameRatio: normalizeRatio(
541
+ options.logo?.frameRatio,
542
+ DEFAULT_LOGO_FRAME_RATIO,
543
+ 0.12,
544
+ 0.3
545
+ ),
546
+ iconRatio: normalizeRatio(
547
+ options.logo?.iconRatio,
548
+ DEFAULT_LOGO_ICON_RATIO,
549
+ 0.4,
550
+ 0.9
551
+ ),
552
+ frameRadiusRatio: normalizeRatio(
553
+ options.logo?.frameRadiusRatio,
554
+ DEFAULT_LOGO_RADIUS_RATIO,
555
+ 0,
556
+ 0.5
557
+ ),
558
+ frameColor: options.logo?.frameColor ?? DEFAULT_LIGHT_COLOR,
559
+ element: options.logo?.element
560
+ };
561
+ }
562
+ function normalizeFinderOptions(options) {
563
+ if (options.finderPattern === false || options.finderPattern?.enabled === false) {
564
+ return null;
565
+ }
566
+ return {
567
+ color: options.finderPattern?.color ?? DEFAULT_FINDER_COLOR
568
+ };
569
+ }
570
+ function createLogoNodes(options, params) {
571
+ const logo = normalizeLogoOptions(options);
572
+ if (!logo) return [];
573
+ if (typeof logo.element === "function") {
574
+ const custom = logo.element(params);
575
+ return Array.isArray(custom) ? custom : [custom];
576
+ }
577
+ if (logo.element) {
578
+ return [
579
+ cloneElementWithAttrs(logo.element, {
580
+ x: params.x,
581
+ y: params.y,
582
+ width: params.size,
583
+ height: params.size
584
+ })
585
+ ];
586
+ }
587
+ return [createDefaultAlipayLogo(params.x, params.y, params.size)];
588
+ }
589
+ function buildModulePaths(value, margin, moduleCount, logoFrame, finderColorEnabled) {
590
+ const qrData = import_qrcode.default.create(value, {
591
+ errorCorrectionLevel: "H"
592
+ });
593
+ const paths = {
594
+ dark: [],
595
+ finder: []
596
+ };
597
+ for (let row = 0; row < moduleCount; row += 1) {
598
+ for (let column = 0; column < moduleCount; column += 1) {
599
+ if (!qrData.modules.get(row, column)) continue;
600
+ const x = column + margin;
601
+ const y = row + margin;
602
+ if (logoFrame && intersectsRect(x, y, logoFrame.x, logoFrame.y, logoFrame.size)) {
603
+ continue;
604
+ }
605
+ const path = modulePath(x, y);
606
+ if (finderColorEnabled && isFinderModule(row, column, moduleCount)) {
607
+ paths.finder.push(path);
608
+ } else {
609
+ paths.dark.push(path);
610
+ }
611
+ }
612
+ }
613
+ return paths;
614
+ }
615
+ function createAlipayQRCode(value, options = {}) {
616
+ return createAlipayQRCodeWithHiddenOptions(
617
+ value,
618
+ options
619
+ );
620
+ }
621
+ function createAlipayQRCodeWithHiddenOptions(value, options = {}) {
622
+ assertContent(value);
623
+ const qrData = import_qrcode.default.create(value, {
624
+ errorCorrectionLevel: "H"
625
+ });
626
+ const moduleCount = qrData.modules.size;
627
+ const margin = normalizeMargin(options.margin);
628
+ const viewBoxSize = moduleCount + margin * 2;
629
+ const size = normalizeSize(options.size);
630
+ const lightColor = options.colors?.light ?? DEFAULT_LIGHT_COLOR;
631
+ const darkColor = options.colors?.dark ?? DEFAULT_DARK_COLOR;
632
+ const finderPattern = normalizeFinderOptions(options);
633
+ const logo = normalizeLogoOptions(options);
634
+ const center = margin + moduleCount / 2;
635
+ const logoFrameSize = logo ? moduleCount * logo.frameRatio : 0;
636
+ const logoFrameX = center - logoFrameSize / 2;
637
+ const logoFrameY = center - logoFrameSize / 2;
638
+ const iconSize = logo ? logoFrameSize * logo.iconRatio : 0;
639
+ const iconX = center - iconSize / 2;
640
+ const iconY = center - iconSize / 2;
641
+ const logoFrame = logo ? {
642
+ x: logoFrameX,
643
+ y: logoFrameY,
644
+ size: logoFrameSize
645
+ } : null;
646
+ const modulePaths = buildModulePaths(
647
+ value,
648
+ margin,
649
+ moduleCount,
650
+ logoFrame,
651
+ Boolean(finderPattern)
652
+ );
653
+ const children = [];
654
+ if (options.title) {
655
+ children.push({
656
+ tag: "title",
657
+ children: [options.title]
658
+ });
659
+ }
660
+ children.push({
661
+ tag: "rect",
662
+ attrs: {
663
+ width: viewBoxSize,
664
+ height: viewBoxSize,
665
+ fill: lightColor,
666
+ "data-alipay-qrcode-part": "background"
667
+ }
668
+ });
669
+ children.push({
670
+ tag: "path",
671
+ attrs: {
672
+ d: modulePaths.dark.join(""),
673
+ fill: darkColor,
674
+ "shape-rendering": "crispEdges",
675
+ "data-alipay-qrcode-part": "modules"
676
+ }
677
+ });
678
+ if (finderPattern && modulePaths.finder.length > 0) {
679
+ children.push({
680
+ tag: "path",
681
+ attrs: {
682
+ d: modulePaths.finder.join(""),
683
+ fill: finderPattern.color,
684
+ "shape-rendering": "crispEdges",
685
+ "data-alipay-qrcode-part": "finder-patterns"
686
+ }
687
+ });
688
+ }
689
+ if (logo) {
690
+ const logoParams = {
691
+ x: iconX,
692
+ y: iconY,
693
+ size: iconSize,
694
+ frameX: logoFrameX,
695
+ frameY: logoFrameY,
696
+ frameSize: logoFrameSize,
697
+ viewBoxSize,
698
+ moduleCount,
699
+ margin
700
+ };
701
+ children.push({
702
+ tag: "rect",
703
+ attrs: {
704
+ x: logoFrameX,
705
+ y: logoFrameY,
706
+ width: logoFrameSize,
707
+ height: logoFrameSize,
708
+ rx: logoFrameSize * logo.frameRadiusRatio,
709
+ fill: logo.frameColor,
710
+ "data-alipay-qrcode-part": "logo-frame"
711
+ }
712
+ });
713
+ children.push(...createLogoNodes(options, logoParams));
714
+ }
715
+ return {
716
+ tag: "svg",
717
+ attrs: {
718
+ xmlns: "http://www.w3.org/2000/svg",
719
+ viewBox: `0 0 ${viewBoxSize} ${viewBoxSize}`,
720
+ width: size,
721
+ height: size,
722
+ role: "img",
723
+ "aria-label": options.ariaLabel ?? options.title ?? DEFAULT_ARIA_LABEL,
724
+ class: options.className
725
+ },
726
+ children,
727
+ metadata: {
728
+ moduleCount,
729
+ margin,
730
+ viewBoxSize,
731
+ logo: logo ? {
732
+ frameX: logoFrameX,
733
+ frameY: logoFrameY,
734
+ frameSize: logoFrameSize,
735
+ iconX,
736
+ iconY,
737
+ iconSize
738
+ } : void 0
739
+ }
740
+ };
741
+ }
742
+ function toSvg(value, options = {}) {
743
+ return renderSvgDescriptor(createAlipayQRCode(value, options));
744
+ }
745
+ function toDataURL(value, options = {}) {
746
+ return `data:image/svg+xml;charset=UTF-8,${encodeURIComponent(
747
+ toSvg(value, options)
748
+ )}`;
749
+ }
750
+ // Annotate the CommonJS export names for ESM import in node:
751
+ 0 && (module.exports = {
752
+ createAlipayQRCode,
753
+ toDataURL,
754
+ toSvg
755
+ });