@widget-js/core 24.1.1-beta.86 → 24.1.1-beta.88

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 CHANGED
@@ -1,10 +1,12 @@
1
1
  'use strict';
2
2
 
3
3
  var cssTree = require('css-tree');
4
+ var merge = require('lodash/merge');
4
5
  var localforage = require('localforage');
5
6
 
6
7
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
7
8
 
9
+ var merge__default = /*#__PURE__*/_interopDefault(merge);
8
10
  var localforage__default = /*#__PURE__*/_interopDefault(localforage);
9
11
 
10
12
  var __create = Object.create;
@@ -33,238 +35,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
33
35
  mod
34
36
  ));
35
37
 
36
- // ../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_arrayReduce.js
37
- var require_arrayReduce = __commonJS({
38
- "../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_arrayReduce.js"(exports$1, module) {
39
- function arrayReduce(array, iteratee, accumulator, initAccum) {
40
- var index = -1, length = array == null ? 0 : array.length;
41
- if (initAccum && length) {
42
- accumulator = array[++index];
43
- }
44
- while (++index < length) {
45
- accumulator = iteratee(accumulator, array[index], index, array);
46
- }
47
- return accumulator;
48
- }
49
- module.exports = arrayReduce;
50
- }
51
- });
52
-
53
- // ../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_basePropertyOf.js
54
- var require_basePropertyOf = __commonJS({
55
- "../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_basePropertyOf.js"(exports$1, module) {
56
- function basePropertyOf(object) {
57
- return function(key) {
58
- return object == null ? void 0 : object[key];
59
- };
60
- }
61
- module.exports = basePropertyOf;
62
- }
63
- });
64
-
65
- // ../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_deburrLetter.js
66
- var require_deburrLetter = __commonJS({
67
- "../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_deburrLetter.js"(exports$1, module) {
68
- var basePropertyOf = require_basePropertyOf();
69
- var deburredLetters = {
70
- // Latin-1 Supplement block.
71
- "\xC0": "A",
72
- "\xC1": "A",
73
- "\xC2": "A",
74
- "\xC3": "A",
75
- "\xC4": "A",
76
- "\xC5": "A",
77
- "\xE0": "a",
78
- "\xE1": "a",
79
- "\xE2": "a",
80
- "\xE3": "a",
81
- "\xE4": "a",
82
- "\xE5": "a",
83
- "\xC7": "C",
84
- "\xE7": "c",
85
- "\xD0": "D",
86
- "\xF0": "d",
87
- "\xC8": "E",
88
- "\xC9": "E",
89
- "\xCA": "E",
90
- "\xCB": "E",
91
- "\xE8": "e",
92
- "\xE9": "e",
93
- "\xEA": "e",
94
- "\xEB": "e",
95
- "\xCC": "I",
96
- "\xCD": "I",
97
- "\xCE": "I",
98
- "\xCF": "I",
99
- "\xEC": "i",
100
- "\xED": "i",
101
- "\xEE": "i",
102
- "\xEF": "i",
103
- "\xD1": "N",
104
- "\xF1": "n",
105
- "\xD2": "O",
106
- "\xD3": "O",
107
- "\xD4": "O",
108
- "\xD5": "O",
109
- "\xD6": "O",
110
- "\xD8": "O",
111
- "\xF2": "o",
112
- "\xF3": "o",
113
- "\xF4": "o",
114
- "\xF5": "o",
115
- "\xF6": "o",
116
- "\xF8": "o",
117
- "\xD9": "U",
118
- "\xDA": "U",
119
- "\xDB": "U",
120
- "\xDC": "U",
121
- "\xF9": "u",
122
- "\xFA": "u",
123
- "\xFB": "u",
124
- "\xFC": "u",
125
- "\xDD": "Y",
126
- "\xFD": "y",
127
- "\xFF": "y",
128
- "\xC6": "Ae",
129
- "\xE6": "ae",
130
- "\xDE": "Th",
131
- "\xFE": "th",
132
- "\xDF": "ss",
133
- // Latin Extended-A block.
134
- "\u0100": "A",
135
- "\u0102": "A",
136
- "\u0104": "A",
137
- "\u0101": "a",
138
- "\u0103": "a",
139
- "\u0105": "a",
140
- "\u0106": "C",
141
- "\u0108": "C",
142
- "\u010A": "C",
143
- "\u010C": "C",
144
- "\u0107": "c",
145
- "\u0109": "c",
146
- "\u010B": "c",
147
- "\u010D": "c",
148
- "\u010E": "D",
149
- "\u0110": "D",
150
- "\u010F": "d",
151
- "\u0111": "d",
152
- "\u0112": "E",
153
- "\u0114": "E",
154
- "\u0116": "E",
155
- "\u0118": "E",
156
- "\u011A": "E",
157
- "\u0113": "e",
158
- "\u0115": "e",
159
- "\u0117": "e",
160
- "\u0119": "e",
161
- "\u011B": "e",
162
- "\u011C": "G",
163
- "\u011E": "G",
164
- "\u0120": "G",
165
- "\u0122": "G",
166
- "\u011D": "g",
167
- "\u011F": "g",
168
- "\u0121": "g",
169
- "\u0123": "g",
170
- "\u0124": "H",
171
- "\u0126": "H",
172
- "\u0125": "h",
173
- "\u0127": "h",
174
- "\u0128": "I",
175
- "\u012A": "I",
176
- "\u012C": "I",
177
- "\u012E": "I",
178
- "\u0130": "I",
179
- "\u0129": "i",
180
- "\u012B": "i",
181
- "\u012D": "i",
182
- "\u012F": "i",
183
- "\u0131": "i",
184
- "\u0134": "J",
185
- "\u0135": "j",
186
- "\u0136": "K",
187
- "\u0137": "k",
188
- "\u0138": "k",
189
- "\u0139": "L",
190
- "\u013B": "L",
191
- "\u013D": "L",
192
- "\u013F": "L",
193
- "\u0141": "L",
194
- "\u013A": "l",
195
- "\u013C": "l",
196
- "\u013E": "l",
197
- "\u0140": "l",
198
- "\u0142": "l",
199
- "\u0143": "N",
200
- "\u0145": "N",
201
- "\u0147": "N",
202
- "\u014A": "N",
203
- "\u0144": "n",
204
- "\u0146": "n",
205
- "\u0148": "n",
206
- "\u014B": "n",
207
- "\u014C": "O",
208
- "\u014E": "O",
209
- "\u0150": "O",
210
- "\u014D": "o",
211
- "\u014F": "o",
212
- "\u0151": "o",
213
- "\u0154": "R",
214
- "\u0156": "R",
215
- "\u0158": "R",
216
- "\u0155": "r",
217
- "\u0157": "r",
218
- "\u0159": "r",
219
- "\u015A": "S",
220
- "\u015C": "S",
221
- "\u015E": "S",
222
- "\u0160": "S",
223
- "\u015B": "s",
224
- "\u015D": "s",
225
- "\u015F": "s",
226
- "\u0161": "s",
227
- "\u0162": "T",
228
- "\u0164": "T",
229
- "\u0166": "T",
230
- "\u0163": "t",
231
- "\u0165": "t",
232
- "\u0167": "t",
233
- "\u0168": "U",
234
- "\u016A": "U",
235
- "\u016C": "U",
236
- "\u016E": "U",
237
- "\u0170": "U",
238
- "\u0172": "U",
239
- "\u0169": "u",
240
- "\u016B": "u",
241
- "\u016D": "u",
242
- "\u016F": "u",
243
- "\u0171": "u",
244
- "\u0173": "u",
245
- "\u0174": "W",
246
- "\u0175": "w",
247
- "\u0176": "Y",
248
- "\u0177": "y",
249
- "\u0178": "Y",
250
- "\u0179": "Z",
251
- "\u017B": "Z",
252
- "\u017D": "Z",
253
- "\u017A": "z",
254
- "\u017C": "z",
255
- "\u017E": "z",
256
- "\u0132": "IJ",
257
- "\u0133": "ij",
258
- "\u0152": "Oe",
259
- "\u0153": "oe",
260
- "\u0149": "'n",
261
- "\u017F": "s"
262
- };
263
- var deburrLetter = basePropertyOf(deburredLetters);
264
- module.exports = deburrLetter;
265
- }
266
- });
267
-
268
38
  // ../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_freeGlobal.js
269
39
  var require_freeGlobal = __commonJS({
270
40
  "../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_freeGlobal.js"(exports$1, module) {
@@ -434,154 +204,6 @@ var require_toString = __commonJS({
434
204
  }
435
205
  });
436
206
 
437
- // ../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/deburr.js
438
- var require_deburr = __commonJS({
439
- "../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/deburr.js"(exports$1, module) {
440
- var deburrLetter = require_deburrLetter();
441
- var toString = require_toString();
442
- var reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g;
443
- var rsComboMarksRange = "\\u0300-\\u036f";
444
- var reComboHalfMarksRange = "\\ufe20-\\ufe2f";
445
- var rsComboSymbolsRange = "\\u20d0-\\u20ff";
446
- var rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange;
447
- var rsCombo = "[" + rsComboRange + "]";
448
- var reComboMark = RegExp(rsCombo, "g");
449
- function deburr(string) {
450
- string = toString(string);
451
- return string && string.replace(reLatin, deburrLetter).replace(reComboMark, "");
452
- }
453
- module.exports = deburr;
454
- }
455
- });
456
-
457
- // ../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_asciiWords.js
458
- var require_asciiWords = __commonJS({
459
- "../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_asciiWords.js"(exports$1, module) {
460
- var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
461
- function asciiWords(string) {
462
- return string.match(reAsciiWord) || [];
463
- }
464
- module.exports = asciiWords;
465
- }
466
- });
467
-
468
- // ../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_hasUnicodeWord.js
469
- var require_hasUnicodeWord = __commonJS({
470
- "../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_hasUnicodeWord.js"(exports$1, module) {
471
- var reHasUnicodeWord = /[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/;
472
- function hasUnicodeWord(string) {
473
- return reHasUnicodeWord.test(string);
474
- }
475
- module.exports = hasUnicodeWord;
476
- }
477
- });
478
-
479
- // ../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_unicodeWords.js
480
- var require_unicodeWords = __commonJS({
481
- "../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_unicodeWords.js"(exports$1, module) {
482
- var rsAstralRange = "\\ud800-\\udfff";
483
- var rsComboMarksRange = "\\u0300-\\u036f";
484
- var reComboHalfMarksRange = "\\ufe20-\\ufe2f";
485
- var rsComboSymbolsRange = "\\u20d0-\\u20ff";
486
- var rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange;
487
- var rsDingbatRange = "\\u2700-\\u27bf";
488
- var rsLowerRange = "a-z\\xdf-\\xf6\\xf8-\\xff";
489
- var rsMathOpRange = "\\xac\\xb1\\xd7\\xf7";
490
- var rsNonCharRange = "\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf";
491
- var rsPunctuationRange = "\\u2000-\\u206f";
492
- var rsSpaceRange = " \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000";
493
- var rsUpperRange = "A-Z\\xc0-\\xd6\\xd8-\\xde";
494
- var rsVarRange = "\\ufe0e\\ufe0f";
495
- var rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange;
496
- var rsApos = "['\u2019]";
497
- var rsBreak = "[" + rsBreakRange + "]";
498
- var rsCombo = "[" + rsComboRange + "]";
499
- var rsDigits = "\\d+";
500
- var rsDingbat = "[" + rsDingbatRange + "]";
501
- var rsLower = "[" + rsLowerRange + "]";
502
- var rsMisc = "[^" + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + "]";
503
- var rsFitz = "\\ud83c[\\udffb-\\udfff]";
504
- var rsModifier = "(?:" + rsCombo + "|" + rsFitz + ")";
505
- var rsNonAstral = "[^" + rsAstralRange + "]";
506
- var rsRegional = "(?:\\ud83c[\\udde6-\\uddff]){2}";
507
- var rsSurrPair = "[\\ud800-\\udbff][\\udc00-\\udfff]";
508
- var rsUpper = "[" + rsUpperRange + "]";
509
- var rsZWJ = "\\u200d";
510
- var rsMiscLower = "(?:" + rsLower + "|" + rsMisc + ")";
511
- var rsMiscUpper = "(?:" + rsUpper + "|" + rsMisc + ")";
512
- var rsOptContrLower = "(?:" + rsApos + "(?:d|ll|m|re|s|t|ve))?";
513
- var rsOptContrUpper = "(?:" + rsApos + "(?:D|LL|M|RE|S|T|VE))?";
514
- var reOptMod = rsModifier + "?";
515
- var rsOptVar = "[" + rsVarRange + "]?";
516
- var rsOptJoin = "(?:" + rsZWJ + "(?:" + [rsNonAstral, rsRegional, rsSurrPair].join("|") + ")" + rsOptVar + reOptMod + ")*";
517
- var rsOrdLower = "\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])";
518
- var rsOrdUpper = "\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])";
519
- var rsSeq = rsOptVar + reOptMod + rsOptJoin;
520
- var rsEmoji = "(?:" + [rsDingbat, rsRegional, rsSurrPair].join("|") + ")" + rsSeq;
521
- var reUnicodeWord = RegExp([
522
- rsUpper + "?" + rsLower + "+" + rsOptContrLower + "(?=" + [rsBreak, rsUpper, "$"].join("|") + ")",
523
- rsMiscUpper + "+" + rsOptContrUpper + "(?=" + [rsBreak, rsUpper + rsMiscLower, "$"].join("|") + ")",
524
- rsUpper + "?" + rsMiscLower + "+" + rsOptContrLower,
525
- rsUpper + "+" + rsOptContrUpper,
526
- rsOrdUpper,
527
- rsOrdLower,
528
- rsDigits,
529
- rsEmoji
530
- ].join("|"), "g");
531
- function unicodeWords(string) {
532
- return string.match(reUnicodeWord) || [];
533
- }
534
- module.exports = unicodeWords;
535
- }
536
- });
537
-
538
- // ../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/words.js
539
- var require_words = __commonJS({
540
- "../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/words.js"(exports$1, module) {
541
- var asciiWords = require_asciiWords();
542
- var hasUnicodeWord = require_hasUnicodeWord();
543
- var toString = require_toString();
544
- var unicodeWords = require_unicodeWords();
545
- function words(string, pattern, guard) {
546
- string = toString(string);
547
- pattern = guard ? void 0 : pattern;
548
- if (pattern === void 0) {
549
- return hasUnicodeWord(string) ? unicodeWords(string) : asciiWords(string);
550
- }
551
- return string.match(pattern) || [];
552
- }
553
- module.exports = words;
554
- }
555
- });
556
-
557
- // ../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_createCompounder.js
558
- var require_createCompounder = __commonJS({
559
- "../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_createCompounder.js"(exports$1, module) {
560
- var arrayReduce = require_arrayReduce();
561
- var deburr = require_deburr();
562
- var words = require_words();
563
- var rsApos = "['\u2019]";
564
- var reApos = RegExp(rsApos, "g");
565
- function createCompounder(callback) {
566
- return function(string) {
567
- return arrayReduce(words(deburr(string).replace(reApos, "")), callback, "");
568
- };
569
- }
570
- module.exports = createCompounder;
571
- }
572
- });
573
-
574
- // ../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/kebabCase.js
575
- var require_kebabCase = __commonJS({
576
- "../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/kebabCase.js"(exports$1, module) {
577
- var createCompounder = require_createCompounder();
578
- var kebabCase3 = createCompounder(function(result, word, index) {
579
- return result + (index ? "-" : "") + word.toLowerCase();
580
- });
581
- module.exports = kebabCase3;
582
- }
583
- });
584
-
585
207
  // ../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseSlice.js
586
208
  var require_baseSlice = __commonJS({
587
209
  "../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_baseSlice.js"(exports$1, module) {
@@ -731,135 +353,916 @@ var require_capitalize = __commonJS({
731
353
  }
732
354
  });
733
355
 
734
- // ../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/camelCase.js
735
- var require_camelCase = __commonJS({
736
- "../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/camelCase.js"(exports$1, module) {
737
- var capitalize = require_capitalize();
738
- var createCompounder = require_createCompounder();
739
- var camelCase2 = createCompounder(function(result, word, index) {
740
- word = word.toLowerCase();
741
- return result + (index ? capitalize(word) : word);
742
- });
743
- module.exports = camelCase2;
744
- }
745
- });
746
-
747
- // ../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/snakeCase.js
748
- var require_snakeCase = __commonJS({
749
- "../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/snakeCase.js"(exports$1, module) {
750
- var createCompounder = require_createCompounder();
751
- var snakeCase2 = createCompounder(function(result, word, index) {
752
- return result + (index ? "_" : "") + word.toLowerCase();
753
- });
754
- module.exports = snakeCase2;
755
- }
756
- });
757
-
758
- // src/model/DeployMode.ts
759
- var HostedMode = /* @__PURE__ */ ((HostedMode2) => {
760
- HostedMode2[HostedMode2["NORMAL"] = 1] = "NORMAL";
761
- HostedMode2[HostedMode2["OVERLAP"] = 16] = "OVERLAP";
762
- HostedMode2[HostedMode2["WALLPAPER"] = 256] = "WALLPAPER";
763
- HostedMode2[HostedMode2["SCREEN"] = 4096] = "SCREEN";
764
- HostedMode2[HostedMode2["BACKGROUND"] = 65536] = "BACKGROUND";
765
- HostedMode2[HostedMode2["PAGE"] = 1048576] = "PAGE";
766
- HostedMode2[HostedMode2["ALL"] = 1118481] = "ALL";
767
- return HostedMode2;
768
- })(HostedMode || {});
769
- var DeployMode = /* @__PURE__ */ ((DeployMode2) => {
770
- DeployMode2[DeployMode2["NORMAL"] = 1] = "NORMAL";
771
- DeployMode2[DeployMode2["OVERLAP"] = 16] = "OVERLAP";
772
- DeployMode2[DeployMode2["BACKGROUND"] = 65536] = "BACKGROUND";
773
- DeployMode2[DeployMode2["TRAY"] = 256] = "TRAY";
774
- DeployMode2[DeployMode2["ALL"] = 1118481] = "ALL";
775
- return DeployMode2;
776
- })(DeployMode || {});
777
-
778
- // src/utils/ElectronUtils.ts
779
- var ElectronUtils = class {
780
- static hasElectronApi() {
781
- return this.getAPI() != null;
782
- }
783
- /**
784
- * 获取ElectronAPI
785
- * windows api
786
- */
787
- static getAPI() {
788
- if (Reflect.has(window, "electronAPI")) {
789
- return window.electronAPI;
790
- } else if (Reflect.has(window.parent, "electronAPI")) {
791
- return window.parent.electronAPI;
792
- }
793
- return null;
794
- }
795
- static async invokeMethod(channel, method, ...args) {
796
- return this.getAPI()?.invoke(channel, method, ...args);
797
- }
798
- static async invoke(channel, ...args) {
799
- return this.getAPI()?.invoke(channel, ...args);
800
- }
801
- };
802
-
803
- // src/utils/LanguageUtils.ts
804
- var LanguageUtils = class {
805
- static findText(langMap, localeCode) {
806
- const locales = Object.keys(langMap).map((key) => new Intl.Locale(key));
807
- const targetLocale = new Intl.Locale(localeCode);
808
- let find2 = locales.find((locale) => locale.baseName == targetLocale.baseName);
809
- if (!find2) {
810
- find2 = locales.find((locale) => locale.language == targetLocale.language);
811
- }
812
- return find2;
813
- }
814
- /**
815
- * Get text from `LanguageTextMap` by Unicode locale identifier.
816
- * `localeCode` > `localeCode` without region > browser default language > English > first language
817
- * @param langMap 对象
818
- * @param {LanguageCode} localeCode `zh-CN`、`en-US`、 `zh`、`en`
819
- * @param fallbackToBrowser
820
- */
821
- static getTextByLocate(langMap, localeCode, fallbackToBrowser = true) {
822
- let result;
823
- if (localeCode) {
824
- if (localeCode in langMap) {
825
- return langMap[localeCode];
826
- }
827
- }
828
- if (localeCode) {
829
- const find2 = this.findText(langMap, localeCode);
830
- if (find2) {
831
- return langMap[find2.baseName];
832
- }
833
- }
834
- if (result == void 0 && fallbackToBrowser) {
835
- if (typeof navigator != "undefined" && navigator.languages) {
836
- const langCode = navigator.language;
837
- result = this.getTextByLocate(langMap, langCode, false);
838
- if (result != void 0) {
839
- return result;
840
- }
356
+ // ../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_arrayReduce.js
357
+ var require_arrayReduce = __commonJS({
358
+ "../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_arrayReduce.js"(exports$1, module) {
359
+ function arrayReduce(array, iteratee, accumulator, initAccum) {
360
+ var index = -1, length = array == null ? 0 : array.length;
361
+ if (initAccum && length) {
362
+ accumulator = array[++index];
841
363
  }
842
- }
843
- if (result == void 0) {
844
- const find2 = this.findText(langMap, "en");
845
- if (find2) {
846
- return langMap[find2.baseName];
364
+ while (++index < length) {
365
+ accumulator = iteratee(accumulator, array[index], index, array);
847
366
  }
367
+ return accumulator;
848
368
  }
849
- if (result == void 0) {
850
- const langCode = Object.keys(langMap);
851
- if (langCode.length > 0) {
852
- return langMap[langCode[0]];
853
- }
369
+ module.exports = arrayReduce;
370
+ }
371
+ });
372
+
373
+ // ../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_basePropertyOf.js
374
+ var require_basePropertyOf = __commonJS({
375
+ "../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_basePropertyOf.js"(exports$1, module) {
376
+ function basePropertyOf(object) {
377
+ return function(key) {
378
+ return object == null ? void 0 : object[key];
379
+ };
854
380
  }
855
- return void 0;
381
+ module.exports = basePropertyOf;
856
382
  }
857
- };
383
+ });
858
384
 
859
- // src/utils/WidgetUtils.ts
860
- var WidgetUtils = class {
861
- /**
862
- * 是否支持悬浮窗
385
+ // ../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_deburrLetter.js
386
+ var require_deburrLetter = __commonJS({
387
+ "../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_deburrLetter.js"(exports$1, module) {
388
+ var basePropertyOf = require_basePropertyOf();
389
+ var deburredLetters = {
390
+ // Latin-1 Supplement block.
391
+ "\xC0": "A",
392
+ "\xC1": "A",
393
+ "\xC2": "A",
394
+ "\xC3": "A",
395
+ "\xC4": "A",
396
+ "\xC5": "A",
397
+ "\xE0": "a",
398
+ "\xE1": "a",
399
+ "\xE2": "a",
400
+ "\xE3": "a",
401
+ "\xE4": "a",
402
+ "\xE5": "a",
403
+ "\xC7": "C",
404
+ "\xE7": "c",
405
+ "\xD0": "D",
406
+ "\xF0": "d",
407
+ "\xC8": "E",
408
+ "\xC9": "E",
409
+ "\xCA": "E",
410
+ "\xCB": "E",
411
+ "\xE8": "e",
412
+ "\xE9": "e",
413
+ "\xEA": "e",
414
+ "\xEB": "e",
415
+ "\xCC": "I",
416
+ "\xCD": "I",
417
+ "\xCE": "I",
418
+ "\xCF": "I",
419
+ "\xEC": "i",
420
+ "\xED": "i",
421
+ "\xEE": "i",
422
+ "\xEF": "i",
423
+ "\xD1": "N",
424
+ "\xF1": "n",
425
+ "\xD2": "O",
426
+ "\xD3": "O",
427
+ "\xD4": "O",
428
+ "\xD5": "O",
429
+ "\xD6": "O",
430
+ "\xD8": "O",
431
+ "\xF2": "o",
432
+ "\xF3": "o",
433
+ "\xF4": "o",
434
+ "\xF5": "o",
435
+ "\xF6": "o",
436
+ "\xF8": "o",
437
+ "\xD9": "U",
438
+ "\xDA": "U",
439
+ "\xDB": "U",
440
+ "\xDC": "U",
441
+ "\xF9": "u",
442
+ "\xFA": "u",
443
+ "\xFB": "u",
444
+ "\xFC": "u",
445
+ "\xDD": "Y",
446
+ "\xFD": "y",
447
+ "\xFF": "y",
448
+ "\xC6": "Ae",
449
+ "\xE6": "ae",
450
+ "\xDE": "Th",
451
+ "\xFE": "th",
452
+ "\xDF": "ss",
453
+ // Latin Extended-A block.
454
+ "\u0100": "A",
455
+ "\u0102": "A",
456
+ "\u0104": "A",
457
+ "\u0101": "a",
458
+ "\u0103": "a",
459
+ "\u0105": "a",
460
+ "\u0106": "C",
461
+ "\u0108": "C",
462
+ "\u010A": "C",
463
+ "\u010C": "C",
464
+ "\u0107": "c",
465
+ "\u0109": "c",
466
+ "\u010B": "c",
467
+ "\u010D": "c",
468
+ "\u010E": "D",
469
+ "\u0110": "D",
470
+ "\u010F": "d",
471
+ "\u0111": "d",
472
+ "\u0112": "E",
473
+ "\u0114": "E",
474
+ "\u0116": "E",
475
+ "\u0118": "E",
476
+ "\u011A": "E",
477
+ "\u0113": "e",
478
+ "\u0115": "e",
479
+ "\u0117": "e",
480
+ "\u0119": "e",
481
+ "\u011B": "e",
482
+ "\u011C": "G",
483
+ "\u011E": "G",
484
+ "\u0120": "G",
485
+ "\u0122": "G",
486
+ "\u011D": "g",
487
+ "\u011F": "g",
488
+ "\u0121": "g",
489
+ "\u0123": "g",
490
+ "\u0124": "H",
491
+ "\u0126": "H",
492
+ "\u0125": "h",
493
+ "\u0127": "h",
494
+ "\u0128": "I",
495
+ "\u012A": "I",
496
+ "\u012C": "I",
497
+ "\u012E": "I",
498
+ "\u0130": "I",
499
+ "\u0129": "i",
500
+ "\u012B": "i",
501
+ "\u012D": "i",
502
+ "\u012F": "i",
503
+ "\u0131": "i",
504
+ "\u0134": "J",
505
+ "\u0135": "j",
506
+ "\u0136": "K",
507
+ "\u0137": "k",
508
+ "\u0138": "k",
509
+ "\u0139": "L",
510
+ "\u013B": "L",
511
+ "\u013D": "L",
512
+ "\u013F": "L",
513
+ "\u0141": "L",
514
+ "\u013A": "l",
515
+ "\u013C": "l",
516
+ "\u013E": "l",
517
+ "\u0140": "l",
518
+ "\u0142": "l",
519
+ "\u0143": "N",
520
+ "\u0145": "N",
521
+ "\u0147": "N",
522
+ "\u014A": "N",
523
+ "\u0144": "n",
524
+ "\u0146": "n",
525
+ "\u0148": "n",
526
+ "\u014B": "n",
527
+ "\u014C": "O",
528
+ "\u014E": "O",
529
+ "\u0150": "O",
530
+ "\u014D": "o",
531
+ "\u014F": "o",
532
+ "\u0151": "o",
533
+ "\u0154": "R",
534
+ "\u0156": "R",
535
+ "\u0158": "R",
536
+ "\u0155": "r",
537
+ "\u0157": "r",
538
+ "\u0159": "r",
539
+ "\u015A": "S",
540
+ "\u015C": "S",
541
+ "\u015E": "S",
542
+ "\u0160": "S",
543
+ "\u015B": "s",
544
+ "\u015D": "s",
545
+ "\u015F": "s",
546
+ "\u0161": "s",
547
+ "\u0162": "T",
548
+ "\u0164": "T",
549
+ "\u0166": "T",
550
+ "\u0163": "t",
551
+ "\u0165": "t",
552
+ "\u0167": "t",
553
+ "\u0168": "U",
554
+ "\u016A": "U",
555
+ "\u016C": "U",
556
+ "\u016E": "U",
557
+ "\u0170": "U",
558
+ "\u0172": "U",
559
+ "\u0169": "u",
560
+ "\u016B": "u",
561
+ "\u016D": "u",
562
+ "\u016F": "u",
563
+ "\u0171": "u",
564
+ "\u0173": "u",
565
+ "\u0174": "W",
566
+ "\u0175": "w",
567
+ "\u0176": "Y",
568
+ "\u0177": "y",
569
+ "\u0178": "Y",
570
+ "\u0179": "Z",
571
+ "\u017B": "Z",
572
+ "\u017D": "Z",
573
+ "\u017A": "z",
574
+ "\u017C": "z",
575
+ "\u017E": "z",
576
+ "\u0132": "IJ",
577
+ "\u0133": "ij",
578
+ "\u0152": "Oe",
579
+ "\u0153": "oe",
580
+ "\u0149": "'n",
581
+ "\u017F": "s"
582
+ };
583
+ var deburrLetter = basePropertyOf(deburredLetters);
584
+ module.exports = deburrLetter;
585
+ }
586
+ });
587
+
588
+ // ../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/deburr.js
589
+ var require_deburr = __commonJS({
590
+ "../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/deburr.js"(exports$1, module) {
591
+ var deburrLetter = require_deburrLetter();
592
+ var toString = require_toString();
593
+ var reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g;
594
+ var rsComboMarksRange = "\\u0300-\\u036f";
595
+ var reComboHalfMarksRange = "\\ufe20-\\ufe2f";
596
+ var rsComboSymbolsRange = "\\u20d0-\\u20ff";
597
+ var rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange;
598
+ var rsCombo = "[" + rsComboRange + "]";
599
+ var reComboMark = RegExp(rsCombo, "g");
600
+ function deburr(string) {
601
+ string = toString(string);
602
+ return string && string.replace(reLatin, deburrLetter).replace(reComboMark, "");
603
+ }
604
+ module.exports = deburr;
605
+ }
606
+ });
607
+
608
+ // ../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_asciiWords.js
609
+ var require_asciiWords = __commonJS({
610
+ "../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_asciiWords.js"(exports$1, module) {
611
+ var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
612
+ function asciiWords(string) {
613
+ return string.match(reAsciiWord) || [];
614
+ }
615
+ module.exports = asciiWords;
616
+ }
617
+ });
618
+
619
+ // ../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_hasUnicodeWord.js
620
+ var require_hasUnicodeWord = __commonJS({
621
+ "../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_hasUnicodeWord.js"(exports$1, module) {
622
+ var reHasUnicodeWord = /[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/;
623
+ function hasUnicodeWord(string) {
624
+ return reHasUnicodeWord.test(string);
625
+ }
626
+ module.exports = hasUnicodeWord;
627
+ }
628
+ });
629
+
630
+ // ../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_unicodeWords.js
631
+ var require_unicodeWords = __commonJS({
632
+ "../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_unicodeWords.js"(exports$1, module) {
633
+ var rsAstralRange = "\\ud800-\\udfff";
634
+ var rsComboMarksRange = "\\u0300-\\u036f";
635
+ var reComboHalfMarksRange = "\\ufe20-\\ufe2f";
636
+ var rsComboSymbolsRange = "\\u20d0-\\u20ff";
637
+ var rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange;
638
+ var rsDingbatRange = "\\u2700-\\u27bf";
639
+ var rsLowerRange = "a-z\\xdf-\\xf6\\xf8-\\xff";
640
+ var rsMathOpRange = "\\xac\\xb1\\xd7\\xf7";
641
+ var rsNonCharRange = "\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf";
642
+ var rsPunctuationRange = "\\u2000-\\u206f";
643
+ var rsSpaceRange = " \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000";
644
+ var rsUpperRange = "A-Z\\xc0-\\xd6\\xd8-\\xde";
645
+ var rsVarRange = "\\ufe0e\\ufe0f";
646
+ var rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange;
647
+ var rsApos = "['\u2019]";
648
+ var rsBreak = "[" + rsBreakRange + "]";
649
+ var rsCombo = "[" + rsComboRange + "]";
650
+ var rsDigits = "\\d+";
651
+ var rsDingbat = "[" + rsDingbatRange + "]";
652
+ var rsLower = "[" + rsLowerRange + "]";
653
+ var rsMisc = "[^" + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + "]";
654
+ var rsFitz = "\\ud83c[\\udffb-\\udfff]";
655
+ var rsModifier = "(?:" + rsCombo + "|" + rsFitz + ")";
656
+ var rsNonAstral = "[^" + rsAstralRange + "]";
657
+ var rsRegional = "(?:\\ud83c[\\udde6-\\uddff]){2}";
658
+ var rsSurrPair = "[\\ud800-\\udbff][\\udc00-\\udfff]";
659
+ var rsUpper = "[" + rsUpperRange + "]";
660
+ var rsZWJ = "\\u200d";
661
+ var rsMiscLower = "(?:" + rsLower + "|" + rsMisc + ")";
662
+ var rsMiscUpper = "(?:" + rsUpper + "|" + rsMisc + ")";
663
+ var rsOptContrLower = "(?:" + rsApos + "(?:d|ll|m|re|s|t|ve))?";
664
+ var rsOptContrUpper = "(?:" + rsApos + "(?:D|LL|M|RE|S|T|VE))?";
665
+ var reOptMod = rsModifier + "?";
666
+ var rsOptVar = "[" + rsVarRange + "]?";
667
+ var rsOptJoin = "(?:" + rsZWJ + "(?:" + [rsNonAstral, rsRegional, rsSurrPair].join("|") + ")" + rsOptVar + reOptMod + ")*";
668
+ var rsOrdLower = "\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])";
669
+ var rsOrdUpper = "\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])";
670
+ var rsSeq = rsOptVar + reOptMod + rsOptJoin;
671
+ var rsEmoji = "(?:" + [rsDingbat, rsRegional, rsSurrPair].join("|") + ")" + rsSeq;
672
+ var reUnicodeWord = RegExp([
673
+ rsUpper + "?" + rsLower + "+" + rsOptContrLower + "(?=" + [rsBreak, rsUpper, "$"].join("|") + ")",
674
+ rsMiscUpper + "+" + rsOptContrUpper + "(?=" + [rsBreak, rsUpper + rsMiscLower, "$"].join("|") + ")",
675
+ rsUpper + "?" + rsMiscLower + "+" + rsOptContrLower,
676
+ rsUpper + "+" + rsOptContrUpper,
677
+ rsOrdUpper,
678
+ rsOrdLower,
679
+ rsDigits,
680
+ rsEmoji
681
+ ].join("|"), "g");
682
+ function unicodeWords(string) {
683
+ return string.match(reUnicodeWord) || [];
684
+ }
685
+ module.exports = unicodeWords;
686
+ }
687
+ });
688
+
689
+ // ../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/words.js
690
+ var require_words = __commonJS({
691
+ "../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/words.js"(exports$1, module) {
692
+ var asciiWords = require_asciiWords();
693
+ var hasUnicodeWord = require_hasUnicodeWord();
694
+ var toString = require_toString();
695
+ var unicodeWords = require_unicodeWords();
696
+ function words(string, pattern, guard) {
697
+ string = toString(string);
698
+ pattern = guard ? void 0 : pattern;
699
+ if (pattern === void 0) {
700
+ return hasUnicodeWord(string) ? unicodeWords(string) : asciiWords(string);
701
+ }
702
+ return string.match(pattern) || [];
703
+ }
704
+ module.exports = words;
705
+ }
706
+ });
707
+
708
+ // ../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_createCompounder.js
709
+ var require_createCompounder = __commonJS({
710
+ "../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/_createCompounder.js"(exports$1, module) {
711
+ var arrayReduce = require_arrayReduce();
712
+ var deburr = require_deburr();
713
+ var words = require_words();
714
+ var rsApos = "['\u2019]";
715
+ var reApos = RegExp(rsApos, "g");
716
+ function createCompounder(callback) {
717
+ return function(string) {
718
+ return arrayReduce(words(deburr(string).replace(reApos, "")), callback, "");
719
+ };
720
+ }
721
+ module.exports = createCompounder;
722
+ }
723
+ });
724
+
725
+ // ../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/camelCase.js
726
+ var require_camelCase = __commonJS({
727
+ "../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/camelCase.js"(exports$1, module) {
728
+ var capitalize = require_capitalize();
729
+ var createCompounder = require_createCompounder();
730
+ var camelCase3 = createCompounder(function(result, word, index) {
731
+ word = word.toLowerCase();
732
+ return result + (index ? capitalize(word) : word);
733
+ });
734
+ module.exports = camelCase3;
735
+ }
736
+ });
737
+
738
+ // ../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/kebabCase.js
739
+ var require_kebabCase = __commonJS({
740
+ "../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/kebabCase.js"(exports$1, module) {
741
+ var createCompounder = require_createCompounder();
742
+ var kebabCase4 = createCompounder(function(result, word, index) {
743
+ return result + (index ? "-" : "") + word.toLowerCase();
744
+ });
745
+ module.exports = kebabCase4;
746
+ }
747
+ });
748
+
749
+ // ../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/snakeCase.js
750
+ var require_snakeCase = __commonJS({
751
+ "../../../node_modules/.pnpm/lodash@4.17.21/node_modules/lodash/snakeCase.js"(exports$1, module) {
752
+ var createCompounder = require_createCompounder();
753
+ var snakeCase2 = createCompounder(function(result, word, index) {
754
+ return result + (index ? "_" : "") + word.toLowerCase();
755
+ });
756
+ module.exports = snakeCase2;
757
+ }
758
+ });
759
+
760
+ // src/model/AppNotification.ts
761
+ var NotificationSize = /* @__PURE__ */ ((NotificationSize2) => {
762
+ NotificationSize2["SMALL"] = "small";
763
+ NotificationSize2["NORMAL"] = "normal";
764
+ NotificationSize2["LARGE"] = "large";
765
+ return NotificationSize2;
766
+ })(NotificationSize || {});
767
+ var AppNotification = class {
768
+ type = "info";
769
+ message;
770
+ title;
771
+ targetTime;
772
+ /**
773
+ * 持续时间,单位毫秒
774
+ */
775
+ duration;
776
+ /**
777
+ * IconPark图标
778
+ * @example close-one
779
+ * @see [IconPark](https://iconpark.oceanengine.com/official)
780
+ */
781
+ icon;
782
+ color;
783
+ backgroundColor;
784
+ confirmButtonText;
785
+ cancelButtonText;
786
+ cancelBroadcast;
787
+ confirmBroadcast;
788
+ size;
789
+ url;
790
+ avatar;
791
+ audio;
792
+ lyric;
793
+ createdAt;
794
+ constructor(option) {
795
+ this.createdAt = (/* @__PURE__ */ new Date()).toISOString();
796
+ this.type = option.type ?? "info";
797
+ this.title = option.title;
798
+ this.message = option.message;
799
+ this.targetTime = option.targetTime;
800
+ this.duration = option.duration ?? 5e3;
801
+ this.icon = option.icon;
802
+ this.color = option.color ?? "#5D8AC8";
803
+ this.confirmButtonText = option.confirmButtonText;
804
+ this.cancelButtonText = option.cancelButtonText;
805
+ this.cancelBroadcast = option.cancelBroadcast;
806
+ this.confirmBroadcast = option.confirmBroadcast;
807
+ this.size = option.size ?? "normal" /* NORMAL */;
808
+ this.audio = option.audio;
809
+ this.avatar = option.avatar;
810
+ this.lyric = option.lyric;
811
+ this.backgroundColor = option.backgroundColor ?? "#000000";
812
+ }
813
+ };
814
+ var AppReminderNotification = class extends AppNotification {
815
+ constructor(option) {
816
+ super(option);
817
+ this.type = "reminder";
818
+ this.size = "large" /* LARGE */;
819
+ }
820
+ };
821
+
822
+ // src/model/AppTheme.ts
823
+ var import_camelCase = __toESM(require_camelCase());
824
+ var import_kebabCase = __toESM(require_kebabCase());
825
+ var DefaultThemeDark = {
826
+ useGlobalTheme: true,
827
+ mode: "dark",
828
+ colors: {
829
+ background: "hsl(0 0% 10%)",
830
+ foreground: "hsl(0 0% 98%)",
831
+ card: "hsl(0 0% 12%)",
832
+ cardForeground: "hsl(0 0% 98%)",
833
+ popover: "hsl(0 0% 12%)",
834
+ popoverForeground: "hsl(0 0% 98%)",
835
+ primary: "hsl(210 100% 56%)",
836
+ primaryForeground: "#fff",
837
+ secondary: "hsl(0 0% 20%)",
838
+ secondaryForeground: "#fff",
839
+ muted: "hsl(0 0% 30%)",
840
+ mutedForeground: "hsl(0 0% 70%)",
841
+ accent: "hsl(210 100% 60%)",
842
+ accentForeground: "#fff",
843
+ destructive: "hsl(0 84% 60%)",
844
+ destructiveForeground: "#fff",
845
+ border: "hsl(0 0% 30%)",
846
+ input: "hsl(0 0% 25%)",
847
+ ring: "hsl(210 100% 60%)",
848
+ shadow: "0 0% 0%",
849
+ innerShadow: "0 0% 0%"
850
+ },
851
+ radius: {
852
+ sm: "6px",
853
+ md: "10px",
854
+ lg: "16px",
855
+ full: "9999px"
856
+ },
857
+ typography: {
858
+ fontFamily: "system-ui, sans-serif",
859
+ fontSize: "14px"
860
+ },
861
+ shadow: {
862
+ sm: { offsetX: "0", offsetY: "1px", blur: "2px" },
863
+ md: { offsetX: "0", offsetY: "4px", blur: "6px" },
864
+ lg: { offsetX: "0", offsetY: "10px", blur: "20px" }
865
+ },
866
+ spacing: "0.5rem"
867
+ };
868
+ var DefaultThemeLight = {
869
+ ...DefaultThemeDark,
870
+ mode: "light",
871
+ colors: {
872
+ background: "#ffffff",
873
+ foreground: "hsl(0 0% 10%)",
874
+ card: "#ffffff",
875
+ cardForeground: "hsl(0 0% 10%)",
876
+ popover: "#ffffff",
877
+ popoverForeground: "hsl(0 0% 10%)",
878
+ primary: "hsl(210 100% 56%)",
879
+ primaryForeground: "#fff",
880
+ secondary: "hsl(0 0% 90%)",
881
+ secondaryForeground: "hsl(0 0% 10%)",
882
+ muted: "hsl(0 0% 95%)",
883
+ mutedForeground: "hsl(0 0% 40%)",
884
+ accent: "hsl(210 100% 90%)",
885
+ accentForeground: "hsl(210 100% 40%)",
886
+ destructive: "hsl(0 84% 60%)",
887
+ destructiveForeground: "#fff",
888
+ border: "hsl(0 0% 90%)",
889
+ input: "hsl(0 0% 85%)",
890
+ ring: "hsl(210 100% 56%)",
891
+ shadow: "0 0% 0%",
892
+ innerShadow: "0 0% 0%"
893
+ },
894
+ shadow: {
895
+ sm: { offsetX: "0", offsetY: "1px", blur: "2px" },
896
+ md: { offsetX: "0", offsetY: "4px", blur: "6px" },
897
+ lg: { offsetX: "0", offsetY: "10px", blur: "20px" }
898
+ }
899
+ };
900
+ var DefaultTheme = DefaultThemeDark;
901
+ var AppTheme = class _AppTheme {
902
+ useGlobalTheme;
903
+ mode;
904
+ colors;
905
+ radius;
906
+ typography;
907
+ shadow;
908
+ spacing;
909
+ constructor(options) {
910
+ let parsedOptions = {};
911
+ if (typeof options === "string") {
912
+ try {
913
+ parsedOptions = JSON.parse(options);
914
+ } catch (e) {
915
+ console.error("Failed to parse AppTheme options", e);
916
+ }
917
+ } else if (options) {
918
+ parsedOptions = options;
919
+ }
920
+ const baseTheme = parsedOptions.mode === "light" ? DefaultThemeLight : DefaultThemeDark;
921
+ merge__default.default(this, structuredClone(baseTheme), parsedOptions);
922
+ if (this.useGlobalTheme === void 0) {
923
+ this.useGlobalTheme = true;
924
+ }
925
+ }
926
+ static fromJSON(json) {
927
+ return new _AppTheme(json);
928
+ }
929
+ /**
930
+ * 兼容 V1 版本的 CSS 变量
931
+ */
932
+ toLegacyCSSVariables(prefix = "--widget") {
933
+ const result = {};
934
+ if (this.colors) {
935
+ if (this.colors.background) {
936
+ result[`${prefix}-background-color`] = this.colors.background;
937
+ }
938
+ if (this.colors.foreground) {
939
+ result[`${prefix}-color`] = this.colors.foreground;
940
+ }
941
+ if (this.colors.primary) {
942
+ result[`${prefix}-primary-color`] = this.colors.primary;
943
+ }
944
+ if (this.colors.border) {
945
+ result[`${prefix}-border-color`] = this.colors.border;
946
+ result[`${prefix}-divider-color`] = this.colors.border;
947
+ result[`${prefix}-background-border-color`] = this.colors.border;
948
+ }
949
+ if (this.colors.shadow) {
950
+ result[`${prefix}-shadow-color`] = this.colors.shadow;
951
+ }
952
+ if (this.colors.innerShadow) {
953
+ result[`${prefix}-background-box-shadow-color`] = this.colors.innerShadow;
954
+ }
955
+ }
956
+ if (this.typography) {
957
+ if (this.typography.fontSize) {
958
+ result[`${prefix}-font-size`] = this.typography.fontSize;
959
+ }
960
+ if (this.typography.fontFamily) {
961
+ result[`${prefix}-font-family`] = this.typography.fontFamily;
962
+ }
963
+ }
964
+ if (this.radius) {
965
+ if (this.radius.lg) {
966
+ result[`${prefix}-border-radius`] = this.radius.lg;
967
+ }
968
+ }
969
+ if (this.spacing) {
970
+ result[`${prefix}-padding`] = this.spacing;
971
+ }
972
+ return result;
973
+ }
974
+ /**
975
+ * flatten tokens → CSS variables
976
+ */
977
+ toCSSVariables(prefix = "--widget") {
978
+ const result = {};
979
+ const tokensToWalk = {
980
+ colors: this.colors,
981
+ radius: this.radius,
982
+ typography: this.typography,
983
+ shadow: this.shadow,
984
+ spacing: this.spacing
985
+ };
986
+ const walk = (obj, path = []) => {
987
+ Object.entries(obj).forEach(([key, value]) => {
988
+ if (value === void 0 || value === null) {
989
+ return;
990
+ }
991
+ const newPath = [...path, key];
992
+ if (typeof value === "object") {
993
+ if ("offsetX" in value && "offsetY" in value && "blur" in value) {
994
+ const varName = `${prefix}-${newPath.map(import_kebabCase.default).join("-")}`;
995
+ result[varName] = `${value.offsetX} ${value.offsetY} ${value.blur} var(${prefix}-colors-shadow)`;
996
+ }
997
+ walk(value, newPath);
998
+ } else {
999
+ const varName = `${prefix}-${newPath.map(import_kebabCase.default).join("-")}`;
1000
+ result[varName] = String(value);
1001
+ }
1002
+ });
1003
+ };
1004
+ walk(tokensToWalk);
1005
+ Object.assign(result, this.toLegacyCSSVariables(prefix));
1006
+ return result;
1007
+ }
1008
+ toCSS(selector = ":root") {
1009
+ const vars = this.toCSSVariables();
1010
+ const body = Object.entries(vars).map(([k, v]) => ` ${k}: ${v};`).join("\n");
1011
+ return `${selector} {
1012
+ ${body}
1013
+ }`;
1014
+ }
1015
+ injectCSS(el = document.documentElement) {
1016
+ const vars = this.toCSSVariables();
1017
+ Object.entries(vars).forEach(([k, v]) => {
1018
+ el.style.setProperty(k, v);
1019
+ });
1020
+ }
1021
+ removeCSS(el = document.documentElement) {
1022
+ const vars = this.toCSSVariables();
1023
+ Object.keys(vars).forEach((k) => el.style.removeProperty(k));
1024
+ }
1025
+ /**
1026
+ * 支持主题切换(light/dark)
1027
+ */
1028
+ setMode(mode) {
1029
+ if (this.mode === mode) {
1030
+ return;
1031
+ }
1032
+ this.mode = mode;
1033
+ const baseTheme = mode === "light" ? DefaultThemeLight : DefaultThemeDark;
1034
+ this.colors = structuredClone(baseTheme.colors);
1035
+ this.shadow = structuredClone(baseTheme.shadow);
1036
+ }
1037
+ copy(partial) {
1038
+ return new _AppTheme(merge__default.default({}, structuredClone(this), partial));
1039
+ }
1040
+ static fromCSS(css) {
1041
+ const ast = cssTree.parse(css);
1042
+ const rootRule = cssTree.find(ast, (node, _item, _list) => {
1043
+ if (node.type == "Rule") {
1044
+ const prelude = node.prelude;
1045
+ if (prelude.type == "SelectorList") {
1046
+ const isRoot = prelude.children.some((it) => {
1047
+ return it.type == "Selector" && it.children.some((child) => child.type == "PseudoClassSelector" && child.name == "root");
1048
+ });
1049
+ if (isRoot) {
1050
+ return true;
1051
+ }
1052
+ }
1053
+ }
1054
+ return false;
1055
+ });
1056
+ if (rootRule == null) {
1057
+ return new _AppTheme();
1058
+ }
1059
+ const widgetVariables = rootRule.block.children.filter((it) => it.type == "Declaration" && it.property.startsWith("--widget-"));
1060
+ const themeOptions = {};
1061
+ for (const cssNode of widgetVariables) {
1062
+ const propStr = cssNode.property.replace("--widget-", "");
1063
+ const firstDashIndex = propStr.indexOf("-");
1064
+ const value = cssNode.value.value?.trim() || "";
1065
+ if (firstDashIndex !== -1) {
1066
+ const category = propStr.substring(0, firstDashIndex);
1067
+ const restStr = propStr.substring(firstDashIndex + 1);
1068
+ if (!themeOptions[category]) {
1069
+ themeOptions[category] = {};
1070
+ }
1071
+ if (category === "shadow") {
1072
+ const dashIndex = restStr.indexOf("-");
1073
+ if (dashIndex === -1) {
1074
+ const shadowSize = restStr;
1075
+ if (!themeOptions.shadow[shadowSize]) {
1076
+ themeOptions.shadow[shadowSize] = {};
1077
+ }
1078
+ const match = value.match(/^(\S+)\s+(\S+)\s+(\S+)\s+(.+)$/);
1079
+ if (match) {
1080
+ const obj = themeOptions.shadow[shadowSize];
1081
+ if (!obj.offsetX) {
1082
+ obj.offsetX = match[1];
1083
+ }
1084
+ if (!obj.offsetY) {
1085
+ obj.offsetY = match[2];
1086
+ }
1087
+ if (!obj.blur) {
1088
+ obj.blur = match[3];
1089
+ }
1090
+ }
1091
+ } else {
1092
+ const shadowSize = restStr.substring(0, dashIndex);
1093
+ const shadowProp = (0, import_camelCase.default)(restStr.substring(dashIndex + 1));
1094
+ if (!themeOptions.shadow[shadowSize]) {
1095
+ themeOptions.shadow[shadowSize] = {};
1096
+ }
1097
+ themeOptions.shadow[shadowSize][shadowProp] = value;
1098
+ }
1099
+ } else {
1100
+ const propName = (0, import_camelCase.default)(restStr);
1101
+ themeOptions[category][propName] = value;
1102
+ }
1103
+ } else {
1104
+ const category = (0, import_camelCase.default)(propStr);
1105
+ themeOptions[category] = value;
1106
+ }
1107
+ }
1108
+ return new _AppTheme(themeOptions);
1109
+ }
1110
+ };
1111
+
1112
+ // src/model/DeployedPage.ts
1113
+ var DeployedPage = class {
1114
+ name;
1115
+ packageName;
1116
+ x = 0;
1117
+ y = 0;
1118
+ height = 600;
1119
+ width = 800;
1120
+ proxy;
1121
+ id;
1122
+ isIgnoreMouseEvents;
1123
+ };
1124
+
1125
+ // src/model/DeployMode.ts
1126
+ var HostedMode = /* @__PURE__ */ ((HostedMode2) => {
1127
+ HostedMode2[HostedMode2["NORMAL"] = 1] = "NORMAL";
1128
+ HostedMode2[HostedMode2["OVERLAP"] = 16] = "OVERLAP";
1129
+ HostedMode2[HostedMode2["WALLPAPER"] = 256] = "WALLPAPER";
1130
+ HostedMode2[HostedMode2["SCREEN"] = 4096] = "SCREEN";
1131
+ HostedMode2[HostedMode2["BACKGROUND"] = 65536] = "BACKGROUND";
1132
+ HostedMode2[HostedMode2["PAGE"] = 1048576] = "PAGE";
1133
+ HostedMode2[HostedMode2["ALL"] = 1118481] = "ALL";
1134
+ return HostedMode2;
1135
+ })(HostedMode || {});
1136
+ var DeployMode = /* @__PURE__ */ ((DeployMode2) => {
1137
+ DeployMode2[DeployMode2["NORMAL"] = 1] = "NORMAL";
1138
+ DeployMode2[DeployMode2["OVERLAP"] = 16] = "OVERLAP";
1139
+ DeployMode2[DeployMode2["BACKGROUND"] = 65536] = "BACKGROUND";
1140
+ DeployMode2[DeployMode2["TRAY"] = 256] = "TRAY";
1141
+ DeployMode2[DeployMode2["ALL"] = 1118481] = "ALL";
1142
+ return DeployMode2;
1143
+ })(DeployMode || {});
1144
+
1145
+ // src/model/DeployedWidget.ts
1146
+ var DeployedWidget = class extends DeployedPage {
1147
+ shortcut;
1148
+ deployMode;
1149
+ isOverlap() {
1150
+ return (this.deployMode & 16 /* OVERLAP */) > 0;
1151
+ }
1152
+ };
1153
+
1154
+ // src/model/event/BroadcastEvent.ts
1155
+ var BroadcastEvent = class {
1156
+ event;
1157
+ sender;
1158
+ payload;
1159
+ constructor(options) {
1160
+ this.event = options.event;
1161
+ this.sender = options.sender;
1162
+ this.payload = options.payload;
1163
+ }
1164
+ };
1165
+
1166
+ // src/model/event/WebSocketEvent.ts
1167
+ var WebSocketEventType = /* @__PURE__ */ ((WebSocketEventType2) => {
1168
+ WebSocketEventType2["RESISTER_PACKAGE"] = "ws::cn.widgetjs.core.resister_package";
1169
+ return WebSocketEventType2;
1170
+ })(WebSocketEventType || {});
1171
+ var WebSocketEvent = class {
1172
+ // 类型
1173
+ type;
1174
+ payload;
1175
+ constructor(type, payload) {
1176
+ this.type = type;
1177
+ this.payload = payload;
1178
+ }
1179
+ };
1180
+
1181
+ // src/utils/ElectronUtils.ts
1182
+ var ElectronUtils = class {
1183
+ static hasElectronApi() {
1184
+ return this.getAPI() != null;
1185
+ }
1186
+ /**
1187
+ * 获取ElectronAPI
1188
+ * windows api
1189
+ */
1190
+ static getAPI() {
1191
+ if (Reflect.has(window, "electronAPI")) {
1192
+ return window.electronAPI;
1193
+ } else if (Reflect.has(window.parent, "electronAPI")) {
1194
+ return window.parent.electronAPI;
1195
+ }
1196
+ return null;
1197
+ }
1198
+ static async invokeMethod(channel, method, ...args) {
1199
+ return this.getAPI()?.invoke(channel, method, ...args);
1200
+ }
1201
+ static async invoke(channel, ...args) {
1202
+ return this.getAPI()?.invoke(channel, ...args);
1203
+ }
1204
+ };
1205
+
1206
+ // src/utils/LanguageUtils.ts
1207
+ var LanguageUtils = class {
1208
+ static findText(langMap, localeCode) {
1209
+ const locales = Object.keys(langMap).map((key) => new Intl.Locale(key));
1210
+ const targetLocale = new Intl.Locale(localeCode);
1211
+ let find3 = locales.find((locale) => locale.baseName == targetLocale.baseName);
1212
+ if (!find3) {
1213
+ find3 = locales.find((locale) => locale.language == targetLocale.language);
1214
+ }
1215
+ return find3;
1216
+ }
1217
+ /**
1218
+ * Get text from `LanguageTextMap` by Unicode locale identifier.
1219
+ * `localeCode` > `localeCode` without region > browser default language > English > first language
1220
+ * @param langMap 对象
1221
+ * @param {LanguageCode} localeCode `zh-CN`、`en-US`、 `zh`、`en`
1222
+ * @param fallbackToBrowser
1223
+ */
1224
+ static getTextByLocate(langMap, localeCode, fallbackToBrowser = true) {
1225
+ let result;
1226
+ if (localeCode) {
1227
+ if (localeCode in langMap) {
1228
+ return langMap[localeCode];
1229
+ }
1230
+ }
1231
+ if (localeCode) {
1232
+ const find3 = this.findText(langMap, localeCode);
1233
+ if (find3) {
1234
+ return langMap[find3.baseName];
1235
+ }
1236
+ }
1237
+ if (result == void 0 && fallbackToBrowser) {
1238
+ if (typeof navigator != "undefined" && navigator.languages) {
1239
+ const langCode = navigator.language;
1240
+ result = this.getTextByLocate(langMap, langCode, false);
1241
+ if (result != void 0) {
1242
+ return result;
1243
+ }
1244
+ }
1245
+ }
1246
+ if (result == void 0) {
1247
+ const find3 = this.findText(langMap, "en");
1248
+ if (find3) {
1249
+ return langMap[find3.baseName];
1250
+ }
1251
+ }
1252
+ if (result == void 0) {
1253
+ const langCode = Object.keys(langMap);
1254
+ if (langCode.length > 0) {
1255
+ return langMap[langCode[0]];
1256
+ }
1257
+ }
1258
+ return void 0;
1259
+ }
1260
+ };
1261
+
1262
+ // src/utils/WidgetUtils.ts
1263
+ var WidgetUtils = class {
1264
+ /**
1265
+ * 是否支持悬浮窗
863
1266
  */
864
1267
  static isSupportOverlap(supportDeployMode) {
865
1268
  return (supportDeployMode & 16 /* OVERLAP */) > 0;
@@ -1047,6 +1450,16 @@ var Page = class _Page {
1047
1450
  }
1048
1451
  };
1049
1452
 
1453
+ // src/model/SocialInfo.ts
1454
+ var SocialInfo = class {
1455
+ content;
1456
+ name;
1457
+ constructor(name, content) {
1458
+ this.name = name;
1459
+ this.content = content;
1460
+ }
1461
+ };
1462
+
1050
1463
  // src/model/Widget.ts
1051
1464
  var Widget = class _Widget extends Page {
1052
1465
  categories;
@@ -1148,39 +1561,12 @@ var WidgetKeyword = /* @__PURE__ */ ((WidgetKeyword2) => {
1148
1561
  return WidgetKeyword2;
1149
1562
  })(WidgetKeyword || {});
1150
1563
 
1151
- // src/model/event/BroadcastEvent.ts
1152
- var BroadcastEvent = class {
1153
- event;
1154
- sender;
1155
- payload;
1156
- constructor(options) {
1157
- this.event = options.event;
1158
- this.sender = options.sender;
1159
- this.payload = options.payload;
1160
- }
1161
- };
1162
-
1163
- // src/model/event/WebSocketEvent.ts
1164
- var WebSocketEventType = /* @__PURE__ */ ((WebSocketEventType2) => {
1165
- WebSocketEventType2["RESISTER_PACKAGE"] = "ws::cn.widgetjs.core.resister_package";
1166
- return WebSocketEventType2;
1167
- })(WebSocketEventType || {});
1168
- var WebSocketEvent = class {
1169
- // 类型
1170
- type;
1171
- payload;
1172
- constructor(type, payload) {
1173
- this.type = type;
1174
- this.payload = payload;
1175
- }
1176
- };
1177
-
1178
1564
  // src/model/WidgetData.ts
1179
- var import_kebabCase2 = __toESM(require_kebabCase());
1565
+ var import_kebabCase3 = __toESM(require_kebabCase());
1180
1566
 
1181
1567
  // src/model/WidgetTheme.ts
1182
- var import_kebabCase = __toESM(require_kebabCase());
1183
- var import_camelCase = __toESM(require_camelCase());
1568
+ var import_camelCase2 = __toESM(require_camelCase());
1569
+ var import_kebabCase2 = __toESM(require_kebabCase());
1184
1570
  var WidgetTheme = class _WidgetTheme {
1185
1571
  borderRadius;
1186
1572
  backgroundColor;
@@ -1254,7 +1640,7 @@ ${cssVariables}
1254
1640
  const prefix = "--widget-";
1255
1641
  const keys = Object.keys(this);
1256
1642
  keys.filter((key) => this[key] != void 0).forEach((key) => {
1257
- variables[`${prefix}${(0, import_kebabCase.default)(key)}`] = `${this[key]}`;
1643
+ variables[`${prefix}${(0, import_kebabCase2.default)(key)}`] = `${this[key]}`;
1258
1644
  });
1259
1645
  return variables;
1260
1646
  }
@@ -1262,7 +1648,7 @@ ${cssVariables}
1262
1648
  const properties = {};
1263
1649
  const keys = Object.keys(this);
1264
1650
  keys.filter((key) => this[key] != void 0).forEach((key) => {
1265
- properties[`${(0, import_kebabCase.default)(key)}`] = `${this[key]}`;
1651
+ properties[`${(0, import_kebabCase2.default)(key)}`] = `${this[key]}`;
1266
1652
  });
1267
1653
  return properties;
1268
1654
  }
@@ -1288,7 +1674,7 @@ ${cssVariables}
1288
1674
  const widgetVariables = rootRule.block.children.filter((it) => it.type == "Declaration" && it.property.startsWith("--widget-"));
1289
1675
  const themeOptions = {};
1290
1676
  for (const cssNode of widgetVariables) {
1291
- const prop = (0, import_camelCase.default)(cssNode.property.replace("--widget-", ""));
1677
+ const prop = (0, import_camelCase2.default)(cssNode.property.replace("--widget-", ""));
1292
1678
  themeOptions[prop] = cssNode.value.value.trim();
1293
1679
  }
1294
1680
  return new _WidgetTheme(themeOptions);
@@ -1367,7 +1753,7 @@ var WidgetData = class {
1367
1753
  const prefix = "--widget-";
1368
1754
  const keys = Object.keys(this.theme);
1369
1755
  keys.filter((key) => this.theme[key] != void 0).forEach((key) => {
1370
- properties[`${prefix}${(0, import_kebabCase2.default)(key)}`] = `${this.theme[key]}`;
1756
+ properties[`${prefix}${(0, import_kebabCase3.default)(key)}`] = `${this.theme[key]}`;
1371
1757
  });
1372
1758
  }
1373
1759
  return properties;
@@ -1384,6 +1770,159 @@ var WidgetData = class {
1384
1770
  }
1385
1771
  };
1386
1772
 
1773
+ // src/model/WidgetPackage.ts
1774
+ var WidgetPackage = class _WidgetPackage {
1775
+ /**
1776
+ * 组件包名,一般为域名倒写,e.g. com.example
1777
+ */
1778
+ name;
1779
+ /**
1780
+ * 组件包版本,可以为空,默认采用package.json里的版本
1781
+ * e.g. 1.0.2
1782
+ */
1783
+ version;
1784
+ /**
1785
+ * 组件包所需的App版本
1786
+ */
1787
+ requiredAppVersion;
1788
+ /**
1789
+ * 组件作者署名
1790
+ */
1791
+ author;
1792
+ development;
1793
+ /**
1794
+ * 组件首页
1795
+ */
1796
+ homepage;
1797
+ /**
1798
+ * 组件描述
1799
+ */
1800
+ title;
1801
+ /**
1802
+ * 组件描述
1803
+ */
1804
+ description;
1805
+ /**
1806
+ * 本地组件入口文件,通常为 index.html
1807
+ */
1808
+ entry;
1809
+ /**
1810
+ * 远程组件包入口文件
1811
+ * @deprecated
1812
+ */
1813
+ remoteEntry;
1814
+ /**
1815
+ * 组件包json文件路径
1816
+ * @deprecated
1817
+ * @example https://rtugeek.gitee.io/hotspot/widget.json
1818
+ */
1819
+ remotePackage;
1820
+ local;
1821
+ remote;
1822
+ /**
1823
+ * zip package url, used for downloading the package
1824
+ */
1825
+ zipUrl;
1826
+ /**
1827
+ * 组件包图标
1828
+ */
1829
+ icon;
1830
+ /**
1831
+ * Hash路由模式,默认为true
1832
+ */
1833
+ hash = true;
1834
+ /**
1835
+ * 可能是网络地址,或者本地路径(解压后的文件夹路径),
1836
+ * 网络地址:https://www.bilibili.com
1837
+ * 本地地址:file:///C:/Users/neo/Desktop
1838
+ * 在测试时。地址通常为: http://127.0.0.1:8080
1839
+ */
1840
+ url;
1841
+ widgets = [];
1842
+ pages = [];
1843
+ devOptions;
1844
+ constructor(options) {
1845
+ this.name = options.name;
1846
+ this.development = options.development;
1847
+ this.version = options.version;
1848
+ this.author = options.author;
1849
+ this.homepage = options.homepage;
1850
+ this.title = options.title;
1851
+ this.description = options.description;
1852
+ this.entry = options.entry ?? "index.html";
1853
+ this.remoteEntry = options.remoteEntry;
1854
+ this.requiredAppVersion = options.requiredAppVersion;
1855
+ this.remotePackage = options.remotePackage;
1856
+ this.hash = options.hash ?? false;
1857
+ this.url = "";
1858
+ this.icon = options.icon;
1859
+ this.devOptions = options.devOptions;
1860
+ this.zipUrl = options.zipUrl;
1861
+ this.remote = options.remote;
1862
+ if (options.widgets) {
1863
+ for (const widget of options.widgets) {
1864
+ this.widgets.push(widget);
1865
+ }
1866
+ }
1867
+ }
1868
+ static parseJSON(json) {
1869
+ const object = JSON.parse(json);
1870
+ return this.parseObject(object);
1871
+ }
1872
+ static parseObject(obj) {
1873
+ const widgetPackage = new _WidgetPackage({
1874
+ author: "",
1875
+ description: {
1876
+ "zh-CN": ""
1877
+ },
1878
+ entry: "",
1879
+ hash: false,
1880
+ homepage: "",
1881
+ name: "",
1882
+ title: {
1883
+ "zh-CN": ""
1884
+ },
1885
+ version: ""
1886
+ });
1887
+ Object.assign(widgetPackage, obj);
1888
+ const widgets = [];
1889
+ if (widgetPackage.widgets) {
1890
+ for (const jsonWidget of widgetPackage.widgets) {
1891
+ const widget = new Widget({
1892
+ previewImage: "",
1893
+ path: "",
1894
+ description: { "zh-CN": "" },
1895
+ height: 0,
1896
+ keywords: [],
1897
+ lang: "zh-CN",
1898
+ name: "",
1899
+ title: { "zh-CN": "" },
1900
+ width: 0
1901
+ });
1902
+ Object.assign(widget, jsonWidget);
1903
+ widgets.push(widget);
1904
+ }
1905
+ }
1906
+ widgetPackage.widgets.splice(0, widgetPackage.widgets.length);
1907
+ widgetPackage.widgets.push(...widgets);
1908
+ return widgetPackage;
1909
+ }
1910
+ /**
1911
+ * 获取组件包标题
1912
+ * @param lang 语言环境,不传则获取默认语言
1913
+ */
1914
+ getTitle(lang) {
1915
+ return LanguageUtils.getTextByLocate(this.title, lang);
1916
+ }
1917
+ /**
1918
+ * 获取组件包描述
1919
+ * @param lang 语言环境,不传则获取默认标题
1920
+ */
1921
+ getDescription(lang) {
1922
+ return LanguageUtils.getTextByLocate(this.description, lang);
1923
+ }
1924
+ };
1925
+
1387
1926
  // src/model/WidgetParams.ts
1388
1927
  var import_snakeCase = __toESM(require_snakeCase());
1389
1928
 
@@ -1596,1101 +2135,1171 @@ var ThemeMode = /* @__PURE__ */ ((ThemeMode2) => {
1596
2135
  return ThemeMode2;
1597
2136
  })(ThemeMode || {});
1598
2137
 
1599
- // src/model/AppNotification.ts
1600
- var NotificationSize = /* @__PURE__ */ ((NotificationSize2) => {
1601
- NotificationSize2["SMALL"] = "small";
1602
- NotificationSize2["NORMAL"] = "normal";
1603
- NotificationSize2["LARGE"] = "large";
1604
- return NotificationSize2;
1605
- })(NotificationSize || {});
1606
- var AppNotification = class {
1607
- type = "info";
1608
- message;
1609
- title;
1610
- targetTime;
1611
- /**
1612
- * 持续时间,单位毫秒
1613
- */
1614
- duration;
1615
- /**
1616
- * IconPark图标
1617
- * @example close-one
1618
- * @see [IconPark](https://iconpark.oceanengine.com/official)
1619
- */
1620
- icon;
1621
- color;
1622
- backgroundColor;
1623
- confirmButtonText;
1624
- cancelButtonText;
1625
- cancelBroadcast;
1626
- confirmBroadcast;
1627
- size;
1628
- url;
1629
- avatar;
1630
- audio;
1631
- lyric;
1632
- createdAt;
1633
- constructor(option) {
1634
- this.createdAt = (/* @__PURE__ */ new Date()).toISOString();
1635
- this.type = option.type ?? "info";
1636
- this.title = option.title;
1637
- this.message = option.message;
1638
- this.targetTime = option.targetTime;
1639
- this.duration = option.duration ?? 5e3;
1640
- this.icon = option.icon;
1641
- this.color = option.color ?? "#5D8AC8";
1642
- this.confirmButtonText = option.confirmButtonText;
1643
- this.cancelButtonText = option.cancelButtonText;
1644
- this.cancelBroadcast = option.cancelBroadcast;
1645
- this.confirmBroadcast = option.confirmBroadcast;
1646
- this.size = option.size ?? "normal" /* NORMAL */;
1647
- this.audio = option.audio;
1648
- this.avatar = option.avatar;
1649
- this.lyric = option.lyric;
1650
- this.backgroundColor = option.backgroundColor ?? "#000000";
2138
+ // src/lang/LanguageCode.ts
2139
+ var LanguageMap = class {
2140
+ "ar-SA" = { baseName: "ar-SA", language: "ar", nativeName: "\u0627\u0644\u0639\u0631\u0628\u064A\u0629" };
2141
+ "bn-BD" = { baseName: "bn-BD", language: "bn", nativeName: "\u09AC\u09BE\u0982\u09B2\u09BE" };
2142
+ "en-US" = { baseName: "en-US", language: "en", nativeName: "English" };
2143
+ "de-DE" = { baseName: "de-DE", language: "de", nativeName: "Deutsch" };
2144
+ "el-GR" = { baseName: "el-GR", language: "el", nativeName: "\u0395\u03BB\u03BB\u03B7\u03BD\u03B9\u03BA\u03AC" };
2145
+ "es-ES" = { baseName: "es-ES", language: "es", nativeName: "Espa\xF1ol", region: "ES" };
2146
+ "fi-FI" = { baseName: "fi-FI", language: "fi", nativeName: "Suomalainen" };
2147
+ "fil-PH" = { baseName: "fil-PH", language: "fil", nativeName: "Filipino" };
2148
+ "fr-FR" = { baseName: "fr-FR", language: "fr", nativeName: "Fran\xE7ais" };
2149
+ "hi-IN" = { baseName: "hi-IN", language: "hi", nativeName: "\u0939\u093F\u0902\u0926\u0940" };
2150
+ "hu-HU" = { baseName: "hu-HU", language: "hu", nativeName: "Magyar" };
2151
+ "id-ID" = { baseName: "id-ID", language: "id", nativeName: "Bahasa Indonesia" };
2152
+ "it-IT" = { baseName: "it-IT", language: "it", nativeName: "Italiano" };
2153
+ "ja-JP" = { baseName: "ja-JP", language: "ja", nativeName: "\u65E5\u672C\u8A9E" };
2154
+ "ko-KR" = { baseName: "ko-KR", language: "ko", nativeName: "\uD55C\uAD6D\uC5B4" };
2155
+ "nl-NL" = { baseName: "nl-NL", language: "nl", nativeName: "Nederlands" };
2156
+ "pl-PL" = { baseName: "pl-PL", language: "pl", nativeName: "Polski" };
2157
+ "pt-BR" = { baseName: "pt-BR", language: "pt", nativeName: "Portugu\xEAs (Brazil)", region: "BR" };
2158
+ "pt-PT" = { baseName: "pt-PT", language: "pt", nativeName: "Portugu\xEAs" };
2159
+ "ro-RO" = { baseName: "ro-RO", language: "ro", nativeName: "Rom\xE2n\u0103" };
2160
+ "ru-RU" = { baseName: "ru-RU", language: "ru", nativeName: "\u0420\u0443\u0441\u0441\u043A\u0438\u0439" };
2161
+ "sv-SE" = { baseName: "sv-SE", language: "sv", nativeName: "Svenska" };
2162
+ "ta-IN" = { baseName: "ta-IN", language: "ta", nativeName: "\u0BA4\u0BAE\u0BBF\u0BB4\u0BCD" };
2163
+ "tr-TR" = { baseName: "tr-TR", language: "tr", nativeName: "T\xFCrk\xE7e" };
2164
+ "uk-UA" = { baseName: "uk-UA", language: "uk", nativeName: "\u0423\u043A\u0440\u0430\u0457\u043D\u0441\u044C\u043A\u0430" };
2165
+ "vi-VN" = { baseName: "vi-VN", language: "vi", nativeName: "Ti\u1EBFng Vi\u1EC7t" };
2166
+ "zh-CN" = { baseName: "zh-CN", language: "zh", nativeName: "\u7B80\u4F53\u4E2D\u6587", region: "CN" };
2167
+ "zh-TW" = { baseName: "zh-TW", language: "zh", nativeName: "\u7E41\u9AD4\u4E2D\u6587", region: "TW" };
2168
+ };
2169
+
2170
+ // src/utils/normalizeUrl.ts
2171
+ var DATA_URL_DEFAULT_MIME_TYPE = "text/plain";
2172
+ var DATA_URL_DEFAULT_CHARSET = "us-ascii";
2173
+ var testParameter = (name, filters) => filters.some((filter) => filter instanceof RegExp ? filter.test(name) : filter === name);
2174
+ var supportedProtocols = /* @__PURE__ */ new Set([
2175
+ "https:",
2176
+ "http:",
2177
+ "file:"
2178
+ ]);
2179
+ function hasCustomProtocol(urlString) {
2180
+ try {
2181
+ const { protocol } = new URL(urlString);
2182
+ return protocol.endsWith(":") && !supportedProtocols.has(protocol);
2183
+ } catch {
2184
+ return false;
2185
+ }
2186
+ }
2187
+ function normalizeDataURL(urlString, option) {
2188
+ const match = /^data:(?<type>[^,]*?),(?<data>[^#]*?)(?:#(?<hash>.*))?$/.exec(urlString);
2189
+ if (!match) {
2190
+ throw new Error(`Invalid URL: ${urlString}`);
2191
+ }
2192
+ let { type, data, hash } = match.groups;
2193
+ const mediaType = type.split(";");
2194
+ hash = option.stripHash ? "" : hash;
2195
+ let isBase64 = false;
2196
+ if (mediaType[mediaType.length - 1] === "base64") {
2197
+ mediaType.pop();
2198
+ isBase64 = true;
2199
+ }
2200
+ const mimeType = mediaType.shift()?.toLowerCase() ?? "";
2201
+ const attributes = mediaType.map((attribute) => {
2202
+ let [key, value = ""] = attribute.split("=").map((item) => item.trim());
2203
+ if (key === "charset") {
2204
+ value = value.toLowerCase();
2205
+ if (value === DATA_URL_DEFAULT_CHARSET) {
2206
+ return "";
2207
+ }
2208
+ }
2209
+ return `${key}${value ? `=${value}` : ""}`;
2210
+ }).filter(Boolean);
2211
+ const normalizedMediaType = [
2212
+ ...attributes
2213
+ ];
2214
+ if (isBase64) {
2215
+ normalizedMediaType.push("base64");
2216
+ }
2217
+ if (normalizedMediaType.length > 0 || mimeType && mimeType !== DATA_URL_DEFAULT_MIME_TYPE) {
2218
+ normalizedMediaType.unshift(mimeType);
2219
+ }
2220
+ return `data:${normalizedMediaType.join(";")},${isBase64 ? data.trim() : data}${hash ? `#${hash}` : ""}`;
2221
+ }
2222
+ function normalizeUrl(urlString, options) {
2223
+ options = {
2224
+ defaultProtocol: "http",
2225
+ normalizeProtocol: true,
2226
+ forceHttp: false,
2227
+ forceHttps: false,
2228
+ stripAuthentication: true,
2229
+ stripHash: false,
2230
+ stripTextFragment: true,
2231
+ stripWWW: true,
2232
+ removeQueryParameters: [/^utm_\w+/i],
2233
+ removeTrailingSlash: true,
2234
+ removeSingleSlash: true,
2235
+ removeDirectoryIndex: false,
2236
+ removeExplicitPort: false,
2237
+ sortQueryParameters: true,
2238
+ ...options
2239
+ };
2240
+ urlString = urlString.replace("\\\\", "//");
2241
+ if (typeof options.defaultProtocol === "string" && !options.defaultProtocol.endsWith(":")) {
2242
+ options.defaultProtocol = `${options.defaultProtocol}:`;
2243
+ }
2244
+ urlString = urlString.trim();
2245
+ if (/^data:/i.test(urlString)) {
2246
+ return normalizeDataURL(urlString, { stripHash: options.stripHash ?? false });
2247
+ }
2248
+ if (hasCustomProtocol(urlString)) {
2249
+ return urlString;
2250
+ }
2251
+ const hasRelativeProtocol = urlString.startsWith("//");
2252
+ const isRelativeUrl = !hasRelativeProtocol && /^\.*\//.test(urlString);
2253
+ if (!isRelativeUrl) {
2254
+ urlString = urlString.replace(/^(?!(?:\w+:)?\/\/)|^\/\//, options.defaultProtocol);
2255
+ }
2256
+ const urlObject = new URL(urlString);
2257
+ if (options.forceHttp && options.forceHttps) {
2258
+ throw new Error("The `forceHttp` and `forceHttps` options cannot be used together");
2259
+ }
2260
+ if (options.forceHttp && urlObject.protocol === "https:") {
2261
+ urlObject.protocol = "http:";
2262
+ }
2263
+ if (options.forceHttps && urlObject.protocol === "http:") {
2264
+ urlObject.protocol = "https:";
2265
+ }
2266
+ if (options.stripAuthentication) {
2267
+ urlObject.username = "";
2268
+ urlObject.password = "";
2269
+ }
2270
+ if (options.stripHash) {
2271
+ urlObject.hash = "";
2272
+ } else if (options.stripTextFragment) {
2273
+ urlObject.hash = urlObject.hash.replace(/#?:~:text.*?$/i, "");
2274
+ }
2275
+ if (urlObject.pathname) {
2276
+ const protocolRegex = /\b[a-z][a-z\d+\-.]{1,50}:\/\//g;
2277
+ let lastIndex = 0;
2278
+ let result = "";
2279
+ for (; ; ) {
2280
+ const match = protocolRegex.exec(urlObject.pathname);
2281
+ if (!match) {
2282
+ break;
2283
+ }
2284
+ const protocol = match[0];
2285
+ const protocolAtIndex = match.index;
2286
+ const intermediate = urlObject.pathname.slice(lastIndex, protocolAtIndex);
2287
+ result += intermediate.replace(/\/{2,}/g, "/");
2288
+ result += protocol;
2289
+ lastIndex = protocolAtIndex + protocol.length;
2290
+ }
2291
+ const remnant = urlObject.pathname.slice(lastIndex, urlObject.pathname.length);
2292
+ result += remnant.replace(/\/{2,}/g, "/");
2293
+ urlObject.pathname = result;
2294
+ }
2295
+ if (urlObject.pathname) {
2296
+ try {
2297
+ urlObject.pathname = decodeURI(urlObject.pathname);
2298
+ } catch {
2299
+ }
2300
+ }
2301
+ if (options.removeDirectoryIndex === true) {
2302
+ options.removeDirectoryIndex = [/^index\.[a-z]+$/];
2303
+ }
2304
+ if (Array.isArray(options.removeDirectoryIndex) && options.removeDirectoryIndex.length > 0) {
2305
+ let pathComponents = urlObject.pathname.split("/");
2306
+ const lastComponent = pathComponents[pathComponents.length - 1];
2307
+ if (testParameter(lastComponent, options.removeDirectoryIndex)) {
2308
+ pathComponents = pathComponents.slice(0, -1);
2309
+ urlObject.pathname = `${pathComponents.slice(1).join("/")}/`;
2310
+ }
2311
+ }
2312
+ if (urlObject.hostname) {
2313
+ urlObject.hostname = urlObject.hostname.replace(/\.$/, "");
2314
+ if (options.stripWWW && /^www\.(?!www\.)[a-z\-\d]{1,63}\.[a-z.\-\d]{2,63}$/.test(urlObject.hostname)) {
2315
+ urlObject.hostname = urlObject.hostname.replace(/^www\./, "");
2316
+ }
2317
+ }
2318
+ if (Array.isArray(options.removeQueryParameters)) {
2319
+ for (const key of [...urlObject.searchParams.keys()]) {
2320
+ if (testParameter(key, options.removeQueryParameters)) {
2321
+ urlObject.searchParams.delete(key);
2322
+ }
2323
+ }
2324
+ }
2325
+ if (!Array.isArray(options.keepQueryParameters) && options.removeQueryParameters === true) {
2326
+ urlObject.search = "";
2327
+ }
2328
+ if (Array.isArray(options.keepQueryParameters) && options.keepQueryParameters.length > 0) {
2329
+ for (const key of [...urlObject.searchParams.keys()]) {
2330
+ if (!testParameter(key, options.keepQueryParameters)) {
2331
+ urlObject.searchParams.delete(key);
2332
+ }
2333
+ }
2334
+ }
2335
+ if (options.sortQueryParameters) {
2336
+ urlObject.searchParams.sort();
2337
+ try {
2338
+ urlObject.search = decodeURIComponent(urlObject.search);
2339
+ } catch {
2340
+ }
2341
+ }
2342
+ if (options.removeTrailingSlash) {
2343
+ urlObject.pathname = urlObject.pathname.replace(/\/$/, "");
1651
2344
  }
1652
- };
1653
- var AppReminderNotification = class extends AppNotification {
1654
- constructor(option) {
1655
- super(option);
1656
- this.type = "reminder";
1657
- this.size = "large" /* LARGE */;
2345
+ if (options.removeExplicitPort && urlObject.port) {
2346
+ urlObject.port = "";
1658
2347
  }
1659
- };
1660
-
1661
- // src/model/DeployedPage.ts
1662
- var DeployedPage = class {
1663
- name;
1664
- packageName;
1665
- x = 0;
1666
- y = 0;
1667
- height = 600;
1668
- width = 800;
1669
- proxy;
1670
- id;
1671
- isIgnoreMouseEvents;
1672
- };
1673
-
1674
- // src/model/SocialInfo.ts
1675
- var SocialInfo = class {
1676
- content;
1677
- name;
1678
- constructor(name, content) {
1679
- this.name = name;
1680
- this.content = content;
2348
+ const oldUrlString = urlString;
2349
+ urlString = urlObject.toString();
2350
+ if (!options.removeSingleSlash && urlObject.pathname === "/" && !oldUrlString.endsWith("/") && urlObject.hash === "") {
2351
+ urlString = urlString.replace(/\/$/, "");
1681
2352
  }
1682
- };
2353
+ if ((options.removeTrailingSlash || urlObject.pathname === "/") && urlObject.hash === "" && options.removeSingleSlash) {
2354
+ urlString = urlString.replace(/\/$/, "");
2355
+ }
2356
+ if (hasRelativeProtocol && !options.normalizeProtocol) {
2357
+ urlString = urlString.replace(/^http:\/\//, "//");
2358
+ }
2359
+ if (options.stripProtocol) {
2360
+ urlString = urlString.replace(/^(?:https?:)?\/\//, "");
2361
+ }
2362
+ return urlString;
2363
+ }
1683
2364
 
1684
- // src/model/DeployedWidget.ts
1685
- var DeployedWidget = class extends DeployedPage {
1686
- shortcut;
1687
- deployMode;
1688
- isOverlap() {
1689
- return (this.deployMode & 16 /* OVERLAP */) > 0;
2365
+ // src/grid/GridSystem.ts
2366
+ var GridRect = class {
2367
+ top;
2368
+ left;
2369
+ width;
2370
+ height;
2371
+ constructor(left, top, width, height) {
2372
+ this.top = top;
2373
+ this.left = left;
2374
+ this.width = width;
2375
+ this.height = height;
2376
+ }
2377
+ get right() {
2378
+ return this.left + this.width;
2379
+ }
2380
+ get bottom() {
2381
+ return this.top + this.height;
1690
2382
  }
1691
2383
  };
1692
-
1693
- // src/model/WidgetPackage.ts
1694
- var WidgetPackage = class _WidgetPackage {
1695
- /**
1696
- * 组件包名,一般为域名倒写,e.g. com.example
1697
- */
1698
- name;
1699
- /**
1700
- * 组件包版本,可以为空,默认采用package.json里的版本
1701
- * e.g. 1.0.2
1702
- */
1703
- version;
1704
- /**
1705
- * 组件包所需的App版本
1706
- */
1707
- requiredAppVersion;
1708
- /**
1709
- * 组件作者署名
1710
- */
1711
- author;
1712
- development;
1713
- /**
1714
- * 组件首页
1715
- */
1716
- homepage;
1717
- /**
1718
- * 组件描述
1719
- */
1720
- title;
1721
- /**
1722
- * 组件描述
1723
- */
1724
- description;
1725
- /**
1726
- * 本地组件入口文件,通常为 index.html
1727
- */
1728
- entry;
1729
- /**
1730
- * 远程组件包入口文件
1731
- * @deprecated
1732
- */
1733
- remoteEntry;
1734
- /**
1735
- * 组件包json文件路径
1736
- * @deprecated
1737
- * @example https://rtugeek.gitee.io/hotspot/widget.json
1738
- */
1739
- remotePackage;
1740
- local;
1741
- remote;
2384
+ var GridSystem = class extends GridRect {
2385
+ cellSize;
2386
+ horizontalCellCount;
2387
+ verticalCellCount;
2388
+ screenWidth;
2389
+ screenHeight;
1742
2390
  /**
1743
- * zip package url, used for downloading the package
2391
+ * 屏幕x坐标,用于解决多块屏幕坐标计算问题
1744
2392
  */
1745
- zipUrl;
2393
+ screenLeft;
1746
2394
  /**
1747
- * 组件包图标
2395
+ * 屏幕y坐标,用于解决多块屏幕坐标计算问题
1748
2396
  */
1749
- icon;
2397
+ screenTop;
2398
+ canvasScreenTop;
2399
+ canvasScreenLeft;
1750
2400
  /**
1751
- * Hash路由模式,默认为true
2401
+ *
2402
+ * @param cellSize
2403
+ * @param padding 至少保留的边距
2404
+ * @param screenWidth
2405
+ * @param screenHeight
2406
+ * @param screenX
2407
+ * @param screenY
1752
2408
  */
1753
- hash = true;
2409
+ constructor(cellSize, padding, screenWidth, screenHeight, screenX, screenY) {
2410
+ const gridMaxWidth = screenWidth - padding * 2;
2411
+ const gridMaxHeight = screenHeight - padding * 2;
2412
+ const horizontalPadding = gridMaxWidth % cellSize / 2 + padding;
2413
+ const verticalPadding = gridMaxHeight % cellSize / 2 + padding;
2414
+ const horizontalCellCount = Math.floor(gridMaxWidth / cellSize);
2415
+ const verticalCellCount = Math.floor(gridMaxHeight / cellSize);
2416
+ super(horizontalPadding, verticalPadding, horizontalCellCount * cellSize, verticalCellCount * cellSize);
2417
+ this.canvasScreenLeft = horizontalPadding + (screenX ?? 0);
2418
+ this.canvasScreenTop = verticalPadding + (screenY ?? 0);
2419
+ this.cellSize = cellSize;
2420
+ this.screenWidth = screenWidth;
2421
+ this.screenHeight = screenHeight;
2422
+ this.horizontalCellCount = horizontalCellCount;
2423
+ this.verticalCellCount = verticalCellCount;
2424
+ this.screenLeft = screenX;
2425
+ this.screenTop = screenY;
2426
+ }
1754
2427
  /**
1755
- * 可能是网络地址,或者本地路径(解压后的文件夹路径),
1756
- * 网络地址:https://www.bilibili.com
1757
- * 本地地址:file:///C:/Users/neo/Desktop
1758
- * 在测试时。地址通常为: http://127.0.0.1:8080
2428
+ * 将坐标对齐到网格上
2429
+ * @param x
2430
+ * @param y
2431
+ * @param gridSystem
1759
2432
  */
1760
- url;
1761
- widgets = [];
1762
- pages = [];
1763
- devOptions;
1764
- constructor(options) {
1765
- this.name = options.name;
1766
- this.development = options.development;
1767
- this.version = options.version;
1768
- this.author = options.author;
1769
- this.homepage = options.homepage;
1770
- this.title = options.title;
1771
- this.description = options.description;
1772
- this.entry = options.entry ?? "index.html";
1773
- this.remoteEntry = options.remoteEntry;
1774
- this.requiredAppVersion = options.requiredAppVersion;
1775
- this.remotePackage = options.remotePackage;
1776
- this.hash = options.hash ?? false;
1777
- this.url = "";
1778
- this.icon = options.icon;
1779
- this.devOptions = options.devOptions;
1780
- this.zipUrl = options.zipUrl;
1781
- this.remote = options.remote;
1782
- if (options.widgets) {
1783
- for (const widget of options.widgets) {
1784
- this.widgets.push(widget);
1785
- }
1786
- }
2433
+ snapCanvasPosition(x, y) {
2434
+ const newX = this.getRangeValue(x - this.left, 0, this.right);
2435
+ const newY = this.getRangeValue(y - this.top, 0, this.bottom);
2436
+ return this.snapPosition(newX, newY);
1787
2437
  }
1788
- static parseJSON(json) {
1789
- const object = JSON.parse(json);
1790
- return this.parseObject(object);
2438
+ snapPosition(newX, newY) {
2439
+ const diffX = newX % this.cellSize;
2440
+ if (diffX >= this.cellSize / 2) {
2441
+ newX = newX + this.cellSize - diffX;
2442
+ } else {
2443
+ newX = newX - diffX;
2444
+ }
2445
+ const diffY = newY % this.cellSize;
2446
+ if (diffY >= this.cellSize / 2) {
2447
+ newY = newY + this.cellSize - diffY;
2448
+ } else {
2449
+ newY = newY - diffY;
2450
+ }
2451
+ return [newX + this.left, newY + this.top];
1791
2452
  }
1792
- static parseObject(obj) {
1793
- const widgetPackage = new _WidgetPackage({
1794
- author: "",
1795
- description: {
1796
- "zh-CN": ""
1797
- },
1798
- entry: "",
1799
- hash: false,
1800
- homepage: "",
1801
- name: "",
1802
- title: {
1803
- "zh-CN": ""
1804
- },
1805
- version: ""
1806
- });
1807
- Object.assign(widgetPackage, obj);
1808
- const widgets = [];
1809
- if (widgetPackage.widgets) {
1810
- for (const jsonWidget of widgetPackage.widgets) {
1811
- const widget = new Widget({
1812
- previewImage: "",
1813
- path: "",
1814
- description: { "zh-CN": "" },
1815
- height: 0,
1816
- keywords: [],
1817
- lang: "zh-CN",
1818
- name: "",
1819
- title: { "zh-CN": "" },
1820
- width: 0
1821
- });
1822
- Object.assign(widget, jsonWidget);
1823
- widgets.push(widget);
1824
- }
2453
+ snapSize(width, height) {
2454
+ let newWidth = Math.floor(width);
2455
+ let newHeight = Math.floor(height);
2456
+ const diffWidth = newWidth % this.cellSize;
2457
+ const diffHeight = newHeight % this.cellSize;
2458
+ if (diffWidth > this.cellSize / 2) {
2459
+ newWidth = width + this.cellSize - diffWidth;
2460
+ } else {
2461
+ newWidth = width - diffWidth;
1825
2462
  }
1826
- widgetPackage.widgets.splice(0, widgetPackage.widgets.length);
1827
- widgetPackage.widgets.push(...widgets);
1828
- return widgetPackage;
2463
+ if (diffHeight > this.cellSize / 2) {
2464
+ newHeight = height + this.cellSize - diffHeight;
2465
+ } else {
2466
+ newHeight = height - diffHeight;
2467
+ }
2468
+ return [newWidth, newHeight];
1829
2469
  }
1830
2470
  /**
1831
- * 获取组件包标题
1832
- * @param lang 语言环境,不传则获取默认语言
2471
+ * 将矩形对齐到网格上
2472
+ * @param rect
2473
+ * @param minWidth
2474
+ * @param maxWidth
2475
+ * @param minHeight
2476
+ * @param maxHeight
1833
2477
  */
1834
- getTitle(lang) {
1835
- return LanguageUtils.getTextByLocate(this.title, lang);
2478
+ snapCanvasRect(rect, minWidth, maxWidth, minHeight, maxHeight) {
2479
+ const [newX, newY] = this.snapCanvasPosition(rect.left, rect.top);
2480
+ return this.snapRect(rect, minWidth, maxWidth, minHeight, maxHeight, newX, newY);
2481
+ }
2482
+ snapRect(rect, minWidth, maxWidth, minHeight, maxHeight, newX, newY) {
2483
+ let [newWidth, newHeight] = this.snapSize(rect.width, rect.height);
2484
+ newWidth = this.getRangeValue(newWidth, minWidth, maxWidth);
2485
+ newHeight = this.getRangeValue(newHeight, minHeight, maxHeight);
2486
+ if (newX + newWidth > this.right) {
2487
+ newX = this.right - newWidth;
2488
+ }
2489
+ if (newY + newHeight > this.bottom) {
2490
+ newY = this.bottom - newHeight;
2491
+ }
2492
+ return new GridRect(newX, newY, newWidth, newHeight);
1836
2493
  }
1837
2494
  /**
1838
- * 获取组件包描述
1839
- * @param lang 语言环境,不传则获取默认标题
2495
+ * 将矩形对齐到网格上,与snapRect的区别是,这个会加上屏幕x和y坐标,用于适配多个显示器
2496
+ * @param rect
2497
+ * @param minWidth
2498
+ * @param maxWidth
2499
+ * @param minHeight
2500
+ * @param maxHeight
1840
2501
  */
1841
- getDescription(lang) {
1842
- return LanguageUtils.getTextByLocate(this.description, lang);
2502
+ snapWindow(rect, minWidth, maxWidth, minHeight, maxHeight) {
2503
+ rect.left = rect.left - (this.screenLeft ?? 0);
2504
+ rect.top = rect.top - (this.screenTop ?? 0);
2505
+ const result = this.snapCanvasRect(rect, minWidth, maxWidth, minHeight, maxHeight);
2506
+ return new GridRect(
2507
+ result.left + (this.screenLeft ?? 0),
2508
+ result.top + (this.screenTop ?? 0),
2509
+ result.width,
2510
+ result.height
2511
+ );
2512
+ }
2513
+ /**
2514
+ * 限制值不超出屏幕
2515
+ * @param value
2516
+ * @param min
2517
+ * @param max
2518
+ * @private
2519
+ */
2520
+ getRangeValue(value, min, max) {
2521
+ if (value < min) {
2522
+ return min;
2523
+ }
2524
+ if (value > max) {
2525
+ return max;
2526
+ }
2527
+ return value;
2528
+ }
2529
+ getWidth() {
2530
+ return this.width;
2531
+ }
2532
+ getHeight() {
2533
+ return this.height;
1843
2534
  }
1844
2535
  };
1845
2536
 
1846
- // src/lang/LanguageCode.ts
1847
- var LanguageMap = class {
1848
- "ar-SA" = { baseName: "ar-SA", language: "ar", nativeName: "\u0627\u0644\u0639\u0631\u0628\u064A\u0629" };
1849
- "bn-BD" = { baseName: "bn-BD", language: "bn", nativeName: "\u09AC\u09BE\u0982\u09B2\u09BE" };
1850
- "en-US" = { baseName: "en-US", language: "en", nativeName: "English" };
1851
- "de-DE" = { baseName: "de-DE", language: "de", nativeName: "Deutsch" };
1852
- "el-GR" = { baseName: "el-GR", language: "el", nativeName: "\u0395\u03BB\u03BB\u03B7\u03BD\u03B9\u03BA\u03AC" };
1853
- "es-ES" = { baseName: "es-ES", language: "es", nativeName: "Espa\xF1ol", region: "ES" };
1854
- "fi-FI" = { baseName: "fi-FI", language: "fi", nativeName: "Suomalainen" };
1855
- "fil-PH" = { baseName: "fil-PH", language: "fil", nativeName: "Filipino" };
1856
- "fr-FR" = { baseName: "fr-FR", language: "fr", nativeName: "Fran\xE7ais" };
1857
- "hi-IN" = { baseName: "hi-IN", language: "hi", nativeName: "\u0939\u093F\u0902\u0926\u0940" };
1858
- "hu-HU" = { baseName: "hu-HU", language: "hu", nativeName: "Magyar" };
1859
- "id-ID" = { baseName: "id-ID", language: "id", nativeName: "Bahasa Indonesia" };
1860
- "it-IT" = { baseName: "it-IT", language: "it", nativeName: "Italiano" };
1861
- "ja-JP" = { baseName: "ja-JP", language: "ja", nativeName: "\u65E5\u672C\u8A9E" };
1862
- "ko-KR" = { baseName: "ko-KR", language: "ko", nativeName: "\uD55C\uAD6D\uC5B4" };
1863
- "nl-NL" = { baseName: "nl-NL", language: "nl", nativeName: "Nederlands" };
1864
- "pl-PL" = { baseName: "pl-PL", language: "pl", nativeName: "Polski" };
1865
- "pt-BR" = { baseName: "pt-BR", language: "pt", nativeName: "Portugu\xEAs (Brazil)", region: "BR" };
1866
- "pt-PT" = { baseName: "pt-PT", language: "pt", nativeName: "Portugu\xEAs" };
1867
- "ro-RO" = { baseName: "ro-RO", language: "ro", nativeName: "Rom\xE2n\u0103" };
1868
- "ru-RU" = { baseName: "ru-RU", language: "ru", nativeName: "\u0420\u0443\u0441\u0441\u043A\u0438\u0439" };
1869
- "sv-SE" = { baseName: "sv-SE", language: "sv", nativeName: "Svenska" };
1870
- "ta-IN" = { baseName: "ta-IN", language: "ta", nativeName: "\u0BA4\u0BAE\u0BBF\u0BB4\u0BCD" };
1871
- "tr-TR" = { baseName: "tr-TR", language: "tr", nativeName: "T\xFCrk\xE7e" };
1872
- "uk-UA" = { baseName: "uk-UA", language: "uk", nativeName: "\u0423\u043A\u0440\u0430\u0457\u043D\u0441\u044C\u043A\u0430" };
1873
- "vi-VN" = { baseName: "vi-VN", language: "vi", nativeName: "Ti\u1EBFng Vi\u1EC7t" };
1874
- "zh-CN" = { baseName: "zh-CN", language: "zh", nativeName: "\u7B80\u4F53\u4E2D\u6587", region: "CN" };
1875
- "zh-TW" = { baseName: "zh-TW", language: "zh", nativeName: "\u7E41\u9AD4\u4E2D\u6587", region: "TW" };
2537
+ // src/api/ApiConstants.ts
2538
+ var ApiConstants = class {
2539
+ static CONFIG_LAUNCH_AT_STARTUP = "CONFIG_LAUNCH_AT_STARTUP";
2540
+ static CONFIG_WIDGET_TITLE_COLOR = "CONFIG_WIDGET_TITLE_COLOR";
2541
+ static CONFIG_DEBUG_MODE = "cn.widgetjs.config.debug";
2542
+ static CONFIG_GRID_CELL_SIZE = "cn.widgetjs.config.grid.size";
2543
+ static SHORTCUT_PIN_DESKTOP_WIDGETS = "cn.widgetjs.config.shortcut.pin_desktop_widgets";
2544
+ };
2545
+ var AppEvent = class {
2546
+ static LANGUAGE_CHANGED = "event::cn.widgetjs.core.app.language.changed";
2547
+ };
2548
+ var AppConfig = class {
2549
+ static LANGUAGE = "cn.widgetjs.config.app.language";
2550
+ static LAUNCH_AT_STARTUP = "CONFIG_LAUNCH_AT_STARTUP";
1876
2551
  };
1877
2552
 
1878
- // src/utils/normalizeUrl.ts
1879
- var DATA_URL_DEFAULT_MIME_TYPE = "text/plain";
1880
- var DATA_URL_DEFAULT_CHARSET = "us-ascii";
1881
- var testParameter = (name, filters) => filters.some((filter) => filter instanceof RegExp ? filter.test(name) : filter === name);
1882
- var supportedProtocols = /* @__PURE__ */ new Set([
1883
- "https:",
1884
- "http:",
1885
- "file:"
1886
- ]);
1887
- function hasCustomProtocol(urlString) {
1888
- try {
1889
- const { protocol } = new URL(urlString);
1890
- return protocol.endsWith(":") && !supportedProtocols.has(protocol);
1891
- } catch {
1892
- return false;
2553
+ // src/api/BaseApi.ts
2554
+ var BaseApi = class {
2555
+ async invokeMethod(method, ...args) {
2556
+ return await ElectronUtils.invokeMethod(this.getChannel(), method, ...args);
1893
2557
  }
1894
- }
1895
- function normalizeDataURL(urlString, option) {
1896
- const match = /^data:(?<type>[^,]*?),(?<data>[^#]*?)(?:#(?<hash>.*))?$/.exec(urlString);
1897
- if (!match) {
1898
- throw new Error(`Invalid URL: ${urlString}`);
2558
+ async invoke(...args) {
2559
+ return await ElectronUtils.invoke(this.getChannel(), ...args);
1899
2560
  }
1900
- let { type, data, hash } = match.groups;
1901
- const mediaType = type.split(";");
1902
- hash = option.stripHash ? "" : hash;
1903
- let isBase64 = false;
1904
- if (mediaType[mediaType.length - 1] === "base64") {
1905
- mediaType.pop();
1906
- isBase64 = true;
2561
+ };
2562
+
2563
+ // src/api/Channel.ts
2564
+ var Channel = /* @__PURE__ */ ((Channel2) => {
2565
+ Channel2["NOTIFICATION"] = "channel::cn.widgetjs.core.notification";
2566
+ Channel2["BROWSER_WINDOW"] = "channel::cn.widgetjs.core.browser_window";
2567
+ Channel2["BROADCAST"] = "channel::cn.widgetjs.core.broadcast";
2568
+ Channel2["WIDGET"] = "channel::cn.widgetjs.core.widget";
2569
+ Channel2["WIDGET_PACKAGE"] = "channel::cn.widgetjs.core.widget.package";
2570
+ Channel2["DEPLOYED_WIDGET"] = "channel::cn.widgetjs.core.deployed_widget";
2571
+ Channel2["APP"] = "channel::cn.widgetjs.core.app";
2572
+ Channel2["SYSTEM"] = "channel::cn.widgetjs.core.system";
2573
+ Channel2["DIALOG"] = "channel::cn.widgetjs.core.dialog";
2574
+ Channel2["HTTP"] = "channel::cn.widgetjs.core.http";
2575
+ Channel2["CLIPBOARD"] = "channel::cn.widgetjs.core.clipboard";
2576
+ Channel2["FILE"] = "channel::cn.widgetjs.core.file";
2577
+ Channel2["SCREEN"] = "channel::cn.widgetjs.core.screen";
2578
+ Channel2["MENU"] = "channel::cn.widgetjs.core.menu";
2579
+ Channel2["SHORTCUT"] = "channel::cn.widgetjs.core.shortcut";
2580
+ Channel2["LOG"] = "channel::cn.widgetjs.core.log";
2581
+ Channel2["DEVICE"] = "channel::cn.widgetjs.core.device";
2582
+ Channel2["MOUSE"] = "channel::cn.widgetjs.core.mouse";
2583
+ Channel2["KEYBOARD"] = "channel::cn.widgetjs.core.keyboard";
2584
+ Channel2["STORE"] = "channel::cn.widgetjs.core.store";
2585
+ Channel2["STORAGE"] = "channel::cn.widgetjs.core.storage";
2586
+ Channel2["PROCESS"] = "channel::cn.widgetjs.core.process";
2587
+ Channel2["USER"] = "channel::cn.widgetjs.core.user";
2588
+ Channel2["TRAY"] = "channel::cn.widgetjs.core.tray";
2589
+ Channel2["AI"] = "channel::cn.widgetjs.core.ai";
2590
+ return Channel2;
2591
+ })(Channel || {});
2592
+
2593
+ // src/api/AppApi.ts
2594
+ var AppApiImpl = class extends BaseApi {
2595
+ showAppWindow(route, options) {
2596
+ return this.invokeMethod("showAppWindow", route, options);
1907
2597
  }
1908
- const mimeType = mediaType.shift()?.toLowerCase() ?? "";
1909
- const attributes = mediaType.map((attribute) => {
1910
- let [key, value = ""] = attribute.split("=").map((item) => item.trim());
1911
- if (key === "charset") {
1912
- value = value.toLowerCase();
1913
- if (value === DATA_URL_DEFAULT_CHARSET) {
1914
- return "";
1915
- }
1916
- }
1917
- return `${key}${value ? `=${value}` : ""}`;
1918
- }).filter(Boolean);
1919
- const normalizedMediaType = [
1920
- ...attributes
1921
- ];
1922
- if (isBase64) {
1923
- normalizedMediaType.push("base64");
2598
+ openWidgetPackageManagerWindow() {
2599
+ return this.invokeMethod("openWidgetPackageManagerWindow");
1924
2600
  }
1925
- if (normalizedMediaType.length > 0 || mimeType && mimeType !== DATA_URL_DEFAULT_MIME_TYPE) {
1926
- normalizedMediaType.unshift(mimeType);
2601
+ getRuntimeInfo() {
2602
+ return this.invokeMethod("getRuntimeInfo");
1927
2603
  }
1928
- return `data:${normalizedMediaType.join(";")},${isBase64 ? data.trim() : data}${hash ? `#${hash}` : ""}`;
1929
- }
1930
- function normalizeUrl(urlString, options) {
1931
- options = {
1932
- defaultProtocol: "http",
1933
- normalizeProtocol: true,
1934
- forceHttp: false,
1935
- forceHttps: false,
1936
- stripAuthentication: true,
1937
- stripHash: false,
1938
- stripTextFragment: true,
1939
- stripWWW: true,
1940
- removeQueryParameters: [/^utm_\w+/i],
1941
- removeTrailingSlash: true,
1942
- removeSingleSlash: true,
1943
- removeDirectoryIndex: false,
1944
- removeExplicitPort: false,
1945
- sortQueryParameters: true,
1946
- ...options
1947
- };
1948
- urlString = urlString.replace("\\\\", "//");
1949
- if (typeof options.defaultProtocol === "string" && !options.defaultProtocol.endsWith(":")) {
1950
- options.defaultProtocol = `${options.defaultProtocol}:`;
2604
+ setProxy(config) {
2605
+ return this.invokeMethod("setProxy", config);
1951
2606
  }
1952
- urlString = urlString.trim();
1953
- if (/^data:/i.test(urlString)) {
1954
- return normalizeDataURL(urlString, { stripHash: options.stripHash ?? false });
2607
+ getProxy() {
2608
+ return this.invokeMethod("getProxy");
2609
+ }
2610
+ isWindowsStore() {
2611
+ return this.invokeMethod("isWindowsStore");
2612
+ }
2613
+ getAppPath() {
2614
+ return this.invokeMethod("getAppPath");
2615
+ }
2616
+ async getIconFile() {
2617
+ return this.invokeMethod("getIconFile");
1955
2618
  }
1956
- if (hasCustomProtocol(urlString)) {
1957
- return urlString;
2619
+ getChannel() {
2620
+ return "channel::cn.widgetjs.core.app" /* APP */;
1958
2621
  }
1959
- const hasRelativeProtocol = urlString.startsWith("//");
1960
- const isRelativeUrl = !hasRelativeProtocol && /^\.*\//.test(urlString);
1961
- if (!isRelativeUrl) {
1962
- urlString = urlString.replace(/^(?!(?:\w+:)?\/\/)|^\/\//, options.defaultProtocol);
2622
+ async setConfig(key, value) {
2623
+ return await this.invokeMethod("setConfig", key, value);
1963
2624
  }
1964
- const urlObject = new URL(urlString);
1965
- if (options.forceHttp && options.forceHttps) {
1966
- throw new Error("The `forceHttp` and `forceHttps` options cannot be used together");
2625
+ async getConfig(key, defaultValue) {
2626
+ const value = await this.invokeMethod("getConfig", key);
2627
+ if (value === null || value === void 0) {
2628
+ return defaultValue;
2629
+ }
2630
+ if (typeof defaultValue == "boolean") {
2631
+ return value === "true";
2632
+ }
2633
+ if (typeof defaultValue == "number") {
2634
+ return Number(value);
2635
+ }
2636
+ return value;
1967
2637
  }
1968
- if (options.forceHttp && urlObject.protocol === "https:") {
1969
- urlObject.protocol = "http:";
2638
+ async openAddWidgetWindow() {
2639
+ return this.invokeMethod("openAddWidgetWindow");
1970
2640
  }
1971
- if (options.forceHttps && urlObject.protocol === "http:") {
1972
- urlObject.protocol = "https:";
2641
+ async getVersion(type) {
2642
+ return this.invokeMethod("getVersion", type);
1973
2643
  }
1974
- if (options.stripAuthentication) {
1975
- urlObject.username = "";
1976
- urlObject.password = "";
2644
+ async getPreloadPath() {
2645
+ return this.invokeMethod("getPreloadPath");
1977
2646
  }
1978
- if (options.stripHash) {
1979
- urlObject.hash = "";
1980
- } else if (options.stripTextFragment) {
1981
- urlObject.hash = urlObject.hash.replace(/#?:~:text.*?$/i, "");
2647
+ async openSettingWindow() {
2648
+ return this.invokeMethod("openSettingWindow");
1982
2649
  }
1983
- if (urlObject.pathname) {
1984
- const protocolRegex = /\b[a-z][a-z\d+\-.]{1,50}:\/\//g;
1985
- let lastIndex = 0;
1986
- let result = "";
1987
- for (; ; ) {
1988
- const match = protocolRegex.exec(urlObject.pathname);
1989
- if (!match) {
1990
- break;
1991
- }
1992
- const protocol = match[0];
1993
- const protocolAtIndex = match.index;
1994
- const intermediate = urlObject.pathname.slice(lastIndex, protocolAtIndex);
1995
- result += intermediate.replace(/\/{2,}/g, "/");
1996
- result += protocol;
1997
- lastIndex = protocolAtIndex + protocol.length;
1998
- }
1999
- const remnant = urlObject.pathname.slice(lastIndex, urlObject.pathname.length);
2000
- result += remnant.replace(/\/{2,}/g, "/");
2001
- urlObject.pathname = result;
2650
+ getThemeCSS() {
2651
+ return this.invokeMethod("getThemeCSS");
2002
2652
  }
2003
- if (urlObject.pathname) {
2004
- try {
2005
- urlObject.pathname = decodeURI(urlObject.pathname);
2006
- } catch {
2007
- }
2653
+ setThemeCSS(css) {
2654
+ return this.invokeMethod("setThemeCSS", css);
2008
2655
  }
2009
- if (options.removeDirectoryIndex === true) {
2010
- options.removeDirectoryIndex = [/^index\.[a-z]+$/];
2656
+ getDevMode() {
2657
+ return this.invokeMethod("getDevMode");
2011
2658
  }
2012
- if (Array.isArray(options.removeDirectoryIndex) && options.removeDirectoryIndex.length > 0) {
2013
- let pathComponents = urlObject.pathname.split("/");
2014
- const lastComponent = pathComponents[pathComponents.length - 1];
2015
- if (testParameter(lastComponent, options.removeDirectoryIndex)) {
2016
- pathComponents = pathComponents.slice(0, -1);
2017
- urlObject.pathname = `${pathComponents.slice(1).join("/")}/`;
2018
- }
2659
+ setDevMode(enable) {
2660
+ return this.invokeMethod("setDevMode", enable);
2019
2661
  }
2020
- if (urlObject.hostname) {
2021
- urlObject.hostname = urlObject.hostname.replace(/\.$/, "");
2022
- if (options.stripWWW && /^www\.(?!www\.)[a-z\-\d]{1,63}\.[a-z.\-\d]{2,63}$/.test(urlObject.hostname)) {
2023
- urlObject.hostname = urlObject.hostname.replace(/^www\./, "");
2662
+ getLanguageCode() {
2663
+ if (ElectronUtils.hasElectronApi()) {
2664
+ return this.invokeMethod("getLanguageCode");
2024
2665
  }
2666
+ return Promise.resolve(navigator.language);
2025
2667
  }
2026
- if (Array.isArray(options.removeQueryParameters)) {
2027
- for (const key of [...urlObject.searchParams.keys()]) {
2028
- if (testParameter(key, options.removeQueryParameters)) {
2029
- urlObject.searchParams.delete(key);
2030
- }
2031
- }
2668
+ async setLanguageCode(code) {
2669
+ await this.invokeMethod("setLanguageCode", code);
2032
2670
  }
2033
- if (!Array.isArray(options.keepQueryParameters) && options.removeQueryParameters === true) {
2034
- urlObject.search = "";
2671
+ getGridCellSize() {
2672
+ return this.invokeMethod("getGridCellSize");
2035
2673
  }
2036
- if (Array.isArray(options.keepQueryParameters) && options.keepQueryParameters.length > 0) {
2037
- for (const key of [...urlObject.searchParams.keys()]) {
2038
- if (!testParameter(key, options.keepQueryParameters)) {
2039
- urlObject.searchParams.delete(key);
2040
- }
2041
- }
2674
+ setGridCellSize(size) {
2675
+ return this.invokeMethod("setGridCellSize", size);
2042
2676
  }
2043
- if (options.sortQueryParameters) {
2044
- urlObject.searchParams.sort();
2045
- try {
2046
- urlObject.search = decodeURIComponent(urlObject.search);
2047
- } catch {
2048
- }
2677
+ exit() {
2678
+ return this.invokeMethod("exit");
2049
2679
  }
2050
- if (options.removeTrailingSlash) {
2051
- urlObject.pathname = urlObject.pathname.replace(/\/$/, "");
2680
+ openCheckUpdateWindow() {
2681
+ return this.invokeMethod(`openCheckUpdateWindow`);
2052
2682
  }
2053
- if (options.removeExplicitPort && urlObject.port) {
2054
- urlObject.port = "";
2683
+ openWidgetManagerWindow() {
2684
+ return this.invokeMethod(`openWidgetManagerWindow`);
2055
2685
  }
2056
- const oldUrlString = urlString;
2057
- urlString = urlObject.toString();
2058
- if (!options.removeSingleSlash && urlObject.pathname === "/" && !oldUrlString.endsWith("/") && urlObject.hash === "") {
2059
- urlString = urlString.replace(/\/$/, "");
2686
+ openRuntimeInfoWindow() {
2687
+ return this.invokeMethod(`openRuntimeInfoWindow`);
2060
2688
  }
2061
- if ((options.removeTrailingSlash || urlObject.pathname === "/") && urlObject.hash === "" && options.removeSingleSlash) {
2062
- urlString = urlString.replace(/\/$/, "");
2689
+ };
2690
+ var AppApi = new AppApiImpl();
2691
+
2692
+ // src/api/BroadcastApi.ts
2693
+ var BroadcastApiImpl = class extends BaseApi {
2694
+ async send(event) {
2695
+ await this.invokeMethod("send", event);
2063
2696
  }
2064
- if (hasRelativeProtocol && !options.normalizeProtocol) {
2065
- urlString = urlString.replace(/^http:\/\//, "//");
2697
+ async register(...event) {
2698
+ await this.invokeMethod("register", event);
2066
2699
  }
2067
- if (options.stripProtocol) {
2068
- urlString = urlString.replace(/^(?:https?:)?\/\//, "");
2700
+ async unregister(...event) {
2701
+ await this.invokeMethod("unregister", event);
2069
2702
  }
2070
- return urlString;
2071
- }
2703
+ getChannel() {
2704
+ return "channel::cn.widgetjs.core.broadcast" /* BROADCAST */;
2705
+ }
2706
+ };
2707
+ var BroadcastApi = new BroadcastApiImpl();
2072
2708
 
2073
- // src/grid/GridSystem.ts
2074
- var GridRect = class {
2075
- top;
2076
- left;
2077
- width;
2078
- height;
2079
- constructor(left, top, width, height) {
2080
- this.top = top;
2081
- this.left = left;
2082
- this.width = width;
2083
- this.height = height;
2709
+ // src/api/BrowserWindowApi.ts
2710
+ var BrowserWindowApiEvent = /* @__PURE__ */ ((BrowserWindowApiEvent2) => {
2711
+ BrowserWindowApiEvent2["BLUR"] = "event::cn.widgetjs.core.browser-window.blur";
2712
+ BrowserWindowApiEvent2["MOVED"] = "event::cn.widgetjs.core.browser-window.moved";
2713
+ BrowserWindowApiEvent2["FOCUS"] = "event::cn.widgetjs.core.browser-window.focus";
2714
+ BrowserWindowApiEvent2["CLOSE"] = "event::cn.widgetjs.core.browser-window.close";
2715
+ BrowserWindowApiEvent2["SNAP_TO_EDGE"] = "event::cn.widgetjs.core.browser-window.snap_to_edge";
2716
+ BrowserWindowApiEvent2["RESIZED"] = "event::cn.widgetjs.core.browser-window.resized";
2717
+ BrowserWindowApiEvent2["CANCEL_SNAP_TO_EDGE"] = "event::cn.widgetjs.core.browser-window.cancel_snap_to_edge";
2718
+ return BrowserWindowApiEvent2;
2719
+ })(BrowserWindowApiEvent || {});
2720
+ var BrowserWindowApiImpl = class extends BaseApi {
2721
+ getProxy() {
2722
+ return this.invokeMethod("getProxy");
2084
2723
  }
2085
- get right() {
2086
- return this.left + this.width;
2724
+ setBackgroundThrottling(enabled) {
2725
+ return this.invokeMethod("setBackgroundThrottling", enabled);
2087
2726
  }
2088
- get bottom() {
2089
- return this.top + this.height;
2727
+ getBackgroundThrottling() {
2728
+ return this.invokeMethod("getBackgroundThrottling");
2090
2729
  }
2091
- };
2092
- var GridSystem = class extends GridRect {
2093
- cellSize;
2094
- horizontalCellCount;
2095
- verticalCellCount;
2096
- screenWidth;
2097
- screenHeight;
2098
- /**
2099
- * 屏幕x坐标,用于解决多块屏幕坐标计算问题
2100
- */
2101
- screenLeft;
2102
- /**
2103
- * 屏幕y坐标,用于解决多块屏幕坐标计算问题
2104
- */
2105
- screenTop;
2106
- canvasScreenTop;
2107
- canvasScreenLeft;
2108
- /**
2109
- *
2110
- * @param cellSize
2111
- * @param padding 至少保留的边距
2112
- * @param screenWidth
2113
- * @param screenHeight
2114
- * @param screenX
2115
- * @param screenY
2116
- */
2117
- constructor(cellSize, padding, screenWidth, screenHeight, screenX, screenY) {
2118
- const gridMaxWidth = screenWidth - padding * 2;
2119
- const gridMaxHeight = screenHeight - padding * 2;
2120
- const horizontalPadding = gridMaxWidth % cellSize / 2 + padding;
2121
- const verticalPadding = gridMaxHeight % cellSize / 2 + padding;
2122
- const horizontalCellCount = Math.floor(gridMaxWidth / cellSize);
2123
- const verticalCellCount = Math.floor(gridMaxHeight / cellSize);
2124
- super(horizontalPadding, verticalPadding, horizontalCellCount * cellSize, verticalCellCount * cellSize);
2125
- this.canvasScreenLeft = horizontalPadding + (screenX ?? 0);
2126
- this.canvasScreenTop = verticalPadding + (screenY ?? 0);
2127
- this.cellSize = cellSize;
2128
- this.screenWidth = screenWidth;
2129
- this.screenHeight = screenHeight;
2130
- this.horizontalCellCount = horizontalCellCount;
2131
- this.verticalCellCount = verticalCellCount;
2132
- this.screenLeft = screenX;
2133
- this.screenTop = screenY;
2730
+ isResizable() {
2731
+ return this.invokeMethod("isResizable");
2732
+ }
2733
+ setHasShadow(hasShadow) {
2734
+ return this.invokeMethod("setHasShadow", hasShadow);
2735
+ }
2736
+ isDraggingWindow() {
2737
+ return this.invokeMethod("isDraggingWindow");
2738
+ }
2739
+ setNoActivate() {
2740
+ return this.invokeMethod("setNoActivate");
2741
+ }
2742
+ async isVisible() {
2743
+ return await this.invokeMethod("isVisible");
2744
+ }
2745
+ getChannel() {
2746
+ return "channel::cn.widgetjs.core.browser_window" /* BROWSER_WINDOW */;
2747
+ }
2748
+ async setIgnoreMouseEvent(ignore) {
2749
+ await this.invokeMethod("setIgnoreMouseEvent", ignore);
2750
+ }
2751
+ async show() {
2752
+ await this.invokeMethod("show", true);
2134
2753
  }
2135
- /**
2136
- * 将坐标对齐到网格上
2137
- * @param x
2138
- * @param y
2139
- * @param gridSystem
2140
- */
2141
- snapCanvasPosition(x, y) {
2142
- const newX = this.getRangeValue(x - this.left, 0, this.right);
2143
- const newY = this.getRangeValue(y - this.top, 0, this.bottom);
2144
- return this.snapPosition(newX, newY);
2754
+ async showInactive() {
2755
+ await this.invokeMethod("showInactive", true);
2145
2756
  }
2146
- snapPosition(newX, newY) {
2147
- const diffX = newX % this.cellSize;
2148
- if (diffX >= this.cellSize / 2) {
2149
- newX = newX + this.cellSize - diffX;
2150
- } else {
2151
- newX = newX - diffX;
2152
- }
2153
- const diffY = newY % this.cellSize;
2154
- if (diffY >= this.cellSize / 2) {
2155
- newY = newY + this.cellSize - diffY;
2156
- } else {
2157
- newY = newY - diffY;
2158
- }
2159
- return [newX + this.left, newY + this.top];
2757
+ async hide() {
2758
+ await this.invokeMethod("hide", false);
2160
2759
  }
2161
- snapSize(width, height) {
2162
- let newWidth = Math.floor(width);
2163
- let newHeight = Math.floor(height);
2164
- const diffWidth = newWidth % this.cellSize;
2165
- const diffHeight = newHeight % this.cellSize;
2166
- if (diffWidth > this.cellSize / 2) {
2167
- newWidth = width + this.cellSize - diffWidth;
2168
- } else {
2169
- newWidth = width - diffWidth;
2170
- }
2171
- if (diffHeight > this.cellSize / 2) {
2172
- newHeight = height + this.cellSize - diffHeight;
2760
+ async center() {
2761
+ await this.invokeMethod("center", false);
2762
+ }
2763
+ async setAlwaysOnTop(alwaysOnTop) {
2764
+ await this.invokeMethod("setAlwaysOnTop", alwaysOnTop);
2765
+ }
2766
+ async isAlwaysOnTop() {
2767
+ return await this.invokeMethod("isAlwaysOnTop");
2768
+ }
2769
+ async openUrl(url, option) {
2770
+ if (ElectronUtils.hasElectronApi()) {
2771
+ await this.invokeMethod("openUrl", url, option);
2173
2772
  } else {
2174
- newHeight = height - diffHeight;
2773
+ window.open(url, "_blank");
2175
2774
  }
2176
- return [newWidth, newHeight];
2177
2775
  }
2178
- /**
2179
- * 将矩形对齐到网格上
2180
- * @param rect
2181
- * @param minWidth
2182
- * @param maxWidth
2183
- * @param minHeight
2184
- * @param maxHeight
2185
- */
2186
- snapCanvasRect(rect, minWidth, maxWidth, minHeight, maxHeight) {
2187
- const [newX, newY] = this.snapCanvasPosition(rect.left, rect.top);
2188
- return this.snapRect(rect, minWidth, maxWidth, minHeight, maxHeight, newX, newY);
2776
+ async moveTop() {
2777
+ await this.invokeMethod("moveTop");
2189
2778
  }
2190
- snapRect(rect, minWidth, maxWidth, minHeight, maxHeight, newX, newY) {
2191
- let [newWidth, newHeight] = this.snapSize(rect.width, rect.height);
2192
- newWidth = this.getRangeValue(newWidth, minWidth, maxWidth);
2193
- newHeight = this.getRangeValue(newHeight, minHeight, maxHeight);
2194
- if (newX + newWidth > this.right) {
2195
- newX = this.right - newWidth;
2196
- }
2197
- if (newY + newHeight > this.bottom) {
2198
- newY = this.bottom - newHeight;
2199
- }
2200
- return new GridRect(newX, newY, newWidth, newHeight);
2779
+ async openDevTools() {
2780
+ await this.invokeMethod("openDevTools");
2781
+ }
2782
+ async setPosition(options) {
2783
+ await this.invokeMethod("setPosition", options);
2784
+ }
2785
+ async getPosition() {
2786
+ return await this.invokeMethod("getPosition");
2787
+ }
2788
+ async blur() {
2789
+ return await this.invokeMethod("blur");
2790
+ }
2791
+ async focus() {
2792
+ return await this.invokeMethod("focus");
2201
2793
  }
2202
2794
  /**
2203
- * 将矩形对齐到网格上,与snapRect的区别是,这个会加上屏幕x和y坐标,用于适配多个显示器
2204
- * @param rect
2205
- * @param minWidth
2206
- * @param maxWidth
2207
- * @param minHeight
2208
- * @param maxHeight
2795
+ * 设置窗口是否可以拉伸
2796
+ * @param resizable
2209
2797
  */
2210
- snapWindow(rect, minWidth, maxWidth, minHeight, maxHeight) {
2211
- rect.left = rect.left - (this.screenLeft ?? 0);
2212
- rect.top = rect.top - (this.screenTop ?? 0);
2213
- const result = this.snapCanvasRect(rect, minWidth, maxWidth, minHeight, maxHeight);
2214
- return new GridRect(
2215
- result.left + (this.screenLeft ?? 0),
2216
- result.top + (this.screenTop ?? 0),
2217
- result.width,
2218
- result.height
2219
- );
2798
+ async setResizable(resizable) {
2799
+ return await this.invokeMethod("setResizable", resizable);
2800
+ }
2801
+ async getBounds() {
2802
+ return await this.invokeMethod("getBounds");
2803
+ }
2804
+ async setBounds(bounds, animate) {
2805
+ return await this.invokeMethod("setBounds", bounds, animate);
2806
+ }
2807
+ async alignToScreen(align) {
2808
+ return await this.invokeMethod("alignToScreen", align);
2809
+ }
2810
+ async startDraggingWindow() {
2811
+ return await this.invokeMethod("startDraggingWindow");
2812
+ }
2813
+ async stopDraggingWindow() {
2814
+ return await this.invokeMethod("stopDraggingWindow");
2220
2815
  }
2221
2816
  /**
2222
- * 限制值不超出屏幕
2223
- * @param value
2224
- * @param min
2225
- * @param max
2226
- * @private
2817
+ * 通过url检测窗口是否存在
2818
+ * @param url
2227
2819
  */
2228
- getRangeValue(value, min, max) {
2229
- if (value < min) {
2230
- return min;
2231
- }
2232
- if (value > max) {
2233
- return max;
2234
- }
2235
- return value;
2820
+ async existsByUrl(url) {
2821
+ return await this.invokeMethod("existsByUrl", url);
2236
2822
  }
2237
- getWidth() {
2238
- return this.width;
2823
+ async getMaximumSize() {
2824
+ return await this.invokeMethod("getMaximumSize");
2239
2825
  }
2240
- getHeight() {
2241
- return this.height;
2826
+ async minimize() {
2827
+ return await this.invokeMethod("minimize");
2242
2828
  }
2243
- };
2244
-
2245
- // src/api/ElectronApi.ts
2246
- var ElectronApi = class {
2247
- static async addIpcListener(key, f) {
2248
- await ElectronUtils.getAPI()?.addIpcListener(key, f);
2829
+ async maximize() {
2830
+ return await this.invokeMethod("maximize");
2249
2831
  }
2250
- static async removeIpcListener(key) {
2251
- await ElectronUtils.getAPI()?.removeIpcListener(key);
2832
+ async isMaximized() {
2833
+ return await this.invokeMethod("isMaximized");
2252
2834
  }
2253
- };
2254
-
2255
- // src/api/Channel.ts
2256
- var Channel = /* @__PURE__ */ ((Channel2) => {
2257
- Channel2["NOTIFICATION"] = "channel::cn.widgetjs.core.notification";
2258
- Channel2["BROWSER_WINDOW"] = "channel::cn.widgetjs.core.browser_window";
2259
- Channel2["BROADCAST"] = "channel::cn.widgetjs.core.broadcast";
2260
- Channel2["WIDGET"] = "channel::cn.widgetjs.core.widget";
2261
- Channel2["WIDGET_PACKAGE"] = "channel::cn.widgetjs.core.widget.package";
2262
- Channel2["DEPLOYED_WIDGET"] = "channel::cn.widgetjs.core.deployed_widget";
2263
- Channel2["APP"] = "channel::cn.widgetjs.core.app";
2264
- Channel2["SYSTEM"] = "channel::cn.widgetjs.core.system";
2265
- Channel2["DIALOG"] = "channel::cn.widgetjs.core.dialog";
2266
- Channel2["HTTP"] = "channel::cn.widgetjs.core.http";
2267
- Channel2["CLIPBOARD"] = "channel::cn.widgetjs.core.clipboard";
2268
- Channel2["FILE"] = "channel::cn.widgetjs.core.file";
2269
- Channel2["SCREEN"] = "channel::cn.widgetjs.core.screen";
2270
- Channel2["MENU"] = "channel::cn.widgetjs.core.menu";
2271
- Channel2["SHORTCUT"] = "channel::cn.widgetjs.core.shortcut";
2272
- Channel2["LOG"] = "channel::cn.widgetjs.core.log";
2273
- Channel2["DEVICE"] = "channel::cn.widgetjs.core.device";
2274
- Channel2["MOUSE"] = "channel::cn.widgetjs.core.mouse";
2275
- Channel2["KEYBOARD"] = "channel::cn.widgetjs.core.keyboard";
2276
- Channel2["STORE"] = "channel::cn.widgetjs.core.store";
2277
- Channel2["STORAGE"] = "channel::cn.widgetjs.core.storage";
2278
- Channel2["PROCESS"] = "channel::cn.widgetjs.core.process";
2279
- Channel2["USER"] = "channel::cn.widgetjs.core.user";
2280
- Channel2["TRAY"] = "channel::cn.widgetjs.core.tray";
2281
- Channel2["AI"] = "channel::cn.widgetjs.core.ai";
2282
- return Channel2;
2283
- })(Channel || {});
2284
-
2285
- // src/api/BaseApi.ts
2286
- var BaseApi = class {
2287
- async invokeMethod(method, ...args) {
2288
- return await ElectronUtils.invokeMethod(this.getChannel(), method, ...args);
2835
+ async isMinimized() {
2836
+ return await this.invokeMethod("isMinimized");
2289
2837
  }
2290
- async invoke(...args) {
2291
- return await ElectronUtils.invoke(this.getChannel(), ...args);
2838
+ async restore() {
2839
+ return await this.invokeMethod("restore");
2292
2840
  }
2293
- };
2294
-
2295
- // src/api/BroadcastApi.ts
2296
- var BroadcastApiImpl = class extends BaseApi {
2297
- async send(event) {
2298
- await this.invokeMethod("send", event);
2841
+ async unmaximize() {
2842
+ return await this.invokeMethod("unmaximize");
2843
+ }
2844
+ async setZoomLevel(level) {
2845
+ return await this.invokeMethod("setZoomLevel", level);
2846
+ }
2847
+ async reload() {
2848
+ return await this.invokeMethod("reload");
2849
+ }
2850
+ async setMovable(movable) {
2851
+ return await this.invokeMethod("setMovable", movable);
2852
+ }
2853
+ async setSize(width, height, animate) {
2854
+ return this.invokeMethod("setSize", width, height, animate);
2855
+ }
2856
+ async isFocused() {
2857
+ return this.invokeMethod("isFocused");
2858
+ }
2859
+ async setMaximumSize(width, height) {
2860
+ return this.invokeMethod("setMaximumSize", width, height);
2861
+ }
2862
+ async setMinimumSize(width, height) {
2863
+ return this.invokeMethod("setMinimumSize", width, height);
2864
+ }
2865
+ getMinimumSize() {
2866
+ return this.invokeMethod("getMinimumSize");
2867
+ }
2868
+ close() {
2869
+ return this.invokeMethod("close");
2870
+ }
2871
+ setZoomFactor(factor) {
2872
+ return this.invokeMethod("setZoomFactor", factor);
2873
+ }
2874
+ async setup(options) {
2875
+ if (options.alwaysOnTop) {
2876
+ await this.setAlwaysOnTop(true);
2877
+ }
2878
+ await this.setResizable(!!options.resizable);
2879
+ await this.setMovable(!!options.movable);
2880
+ if (options.width && options.height) {
2881
+ await this.setSize(options.width, options.height);
2882
+ }
2883
+ if (options.minWidth && options.minHeight) {
2884
+ await this.setMinimumSize(options.minWidth, options.minHeight);
2885
+ }
2886
+ if (options.maxWidth && options.maxHeight) {
2887
+ await this.setMaximumSize(options.maxWidth, options.maxHeight);
2888
+ }
2889
+ if (options.center) {
2890
+ await this.center();
2891
+ }
2892
+ if (options.x != void 0 || options.y != void 0) {
2893
+ await this.setPosition({ x: options.x, y: options.y });
2894
+ }
2895
+ if (options.skipTaskbar) {
2896
+ await this.setSkipTaskbar(true);
2897
+ } else if (options.skipTaskbar === false) {
2898
+ await this.setSkipTaskbar(false);
2899
+ }
2299
2900
  }
2300
- async register(...event) {
2301
- await this.invokeMethod("register", event);
2901
+ async setProxy(config) {
2902
+ return await this.invokeMethod("setProxy", config);
2302
2903
  }
2303
- async unregister(...event) {
2304
- await this.invokeMethod("unregister", event);
2904
+ getSize() {
2905
+ return this.invokeMethod("getSize");
2305
2906
  }
2306
- getChannel() {
2307
- return "channel::cn.widgetjs.core.broadcast" /* BROADCAST */;
2907
+ setSkipTaskbar(skip) {
2908
+ return this.invokeMethod("setSkipTaskbar", skip);
2308
2909
  }
2309
2910
  };
2310
- var BroadcastApi = new BroadcastApiImpl();
2911
+ var BrowserWindowApi = new BrowserWindowApiImpl();
2311
2912
 
2312
- // src/api/WidgetApi.ts
2313
- var WidgetApiEvent = /* @__PURE__ */ ((WidgetApiEvent2) => {
2314
- WidgetApiEvent2["DATA_CHANGED"] = "event::cn.widgetjs.core.widget.data-changed";
2315
- WidgetApiEvent2["EDIT_DESKTOP_WIDGETS"] = "event::cn.widgetjs.core.widget.desktop.edit";
2316
- WidgetApiEvent2["PACKAGE_UPGRADE"] = "event::cn.widgetjs.core.widget.package.upgraded";
2317
- WidgetApiEvent2["PACKAGE_INSTALLED"] = "event::cn.widgetjs.core.widget.package.installed";
2318
- return WidgetApiEvent2;
2319
- })(WidgetApiEvent || {});
2320
- var WidgetApiImpl = class extends BaseApi {
2321
- getSyncInfo(widgetName) {
2322
- return this.invokeMethod("getSyncInfo", widgetName);
2913
+ // src/api/ClipboardApi.ts
2914
+ var ClipboardApiEvent = /* @__PURE__ */ ((ClipboardApiEvent2) => {
2915
+ ClipboardApiEvent2["CHANGED"] = "clipboard-changed";
2916
+ return ClipboardApiEvent2;
2917
+ })(ClipboardApiEvent || {});
2918
+ var ClipboardApiImpl = class extends BaseApi {
2919
+ writeText(text) {
2920
+ return this.invokeMethod("writeText", text);
2323
2921
  }
2324
- updateSyncInfo() {
2325
- return this.invokeMethod("updateSyncInfo");
2922
+ async getSelectedText() {
2923
+ return this.invokeMethod("getSelectedText");
2326
2924
  }
2327
- reload(id) {
2328
- return this.invokeMethod("reload", id);
2925
+ async getText() {
2926
+ return this.invokeMethod("getText");
2329
2927
  }
2330
2928
  getChannel() {
2331
- return "channel::cn.widgetjs.core.widget" /* WIDGET */;
2332
- }
2333
- async registerWidgets(widgets) {
2334
- return this.invokeMethod("registerWidgets", JSON.stringify(widgets));
2929
+ return "channel::cn.widgetjs.core.clipboard" /* CLIPBOARD */;
2335
2930
  }
2336
- async registerWidgetPackage(widgetPackage) {
2337
- return this.invokeMethod("registerWidgetPackage", JSON.stringify(widgetPackage));
2931
+ };
2932
+ var ClipboardApi = new ClipboardApiImpl();
2933
+
2934
+ // src/utils/AppProtocolUtils.ts
2935
+ var AppProtocolUtils = class {
2936
+ static getBaseURL() {
2937
+ return new URL("widget://widgetjs.cn");
2338
2938
  }
2339
- async getWidgets() {
2340
- const data = await this.invokeMethod("getWidgets");
2341
- const widgets = [];
2342
- if (data) {
2343
- for (const item of data) {
2344
- widgets.push(Widget.parseObject(item));
2345
- }
2939
+ static getAddWidgetUrl(options) {
2940
+ const url = this.getBaseURL();
2941
+ url.pathname = "/widget/add";
2942
+ if (options.packageJsonUrl) {
2943
+ url.searchParams.set("packageJsonUrl", options.packageJsonUrl);
2346
2944
  }
2347
- return widgets;
2348
- }
2349
- async openConfigPage(widgetId) {
2350
- return this.invokeMethod("openConfigPage", widgetId);
2351
- }
2352
- async openConfigPageByName(widgetName) {
2353
- return this.invokeMethod("openConfigPageByName", widgetName);
2354
- }
2355
- /**
2356
- * @deprecated
2357
- */
2358
- async getWidgetPackages() {
2359
- return await this.invokeMethod("getWidgetPackages");
2945
+ if (options.hostname) {
2946
+ url.searchParams.set("hostname", options.hostname);
2947
+ }
2948
+ if (options.widgetTitle) {
2949
+ url.searchParams.set("widgetTitle", options.widgetTitle);
2950
+ }
2951
+ url.searchParams.set("widgetName", options.widgetName);
2952
+ url.searchParams.set("deployMode", options.deployMode.toString());
2953
+ return url.toString();
2360
2954
  }
2361
- /**
2362
- *
2363
- * @param name package name
2364
- */
2365
- async getWidget(name) {
2366
- return Widget.parseObject(await this.invokeMethod("getWidget", name));
2955
+ };
2956
+
2957
+ // src/api/DeployedWidgetApi.ts
2958
+ var DeployedWidgetApiImpl = class extends BaseApi {
2959
+ getChannel() {
2960
+ return "channel::cn.widgetjs.core.deployed_widget" /* DEPLOYED_WIDGET */;
2367
2961
  }
2368
2962
  /**
2369
- * @param name package name
2370
- * @deprecated
2963
+ * 移除组件
2964
+ * @param id
2371
2965
  */
2372
- async getWidgetPackage(name) {
2373
- const result = await this.invokeMethod("getWidgetPackage", name);
2374
- if (result) {
2375
- return WidgetPackage.parseObject(result);
2376
- }
2377
- return void 0;
2966
+ async removeDeployedWidget(id) {
2967
+ return this.invokeMethod("removeDeployedWidget", id);
2378
2968
  }
2379
- async getWidgetPackageUrl(packageName) {
2380
- const widgetPackage = await this.getWidgetPackage(packageName);
2381
- if (!widgetPackage) {
2382
- return null;
2969
+ addWidget(options) {
2970
+ if (ElectronUtils.hasElectronApi()) {
2971
+ return this.invokeMethod("addWidget", options);
2972
+ } else {
2973
+ window.location.href = AppProtocolUtils.getAddWidgetUrl(options);
2974
+ return Promise.resolve([]);
2383
2975
  }
2384
- return widgetPackage.url;
2385
2976
  }
2386
- async upgradePackage(packageName) {
2387
- return await this.invokeMethod("upgradePackage", packageName);
2977
+ createDesktopShortcut(widgetName) {
2978
+ return this.invokeMethod("createDesktopShortcut", widgetName);
2388
2979
  }
2389
2980
  /**
2390
- * 阻止拖动窗口,只能用于悬浮窗口 DeployMode.OVERLAP
2391
- * @param draggable
2981
+ * 通过组件名移除已添加的组件
2982
+ * @param name 组件名
2392
2983
  */
2393
- setMouseDraggable(draggable) {
2394
- return this.invokeMethod("setMouseDraggable", draggable);
2395
- }
2396
- isIgnoreMouseEvents(widgetId) {
2397
- return this.invokeMethod("isIgnoreMouseEvents", widgetId);
2398
- }
2399
- setIgnoreMouseEvents(widgetId, ignore) {
2400
- return this.invokeMethod("setIgnoreMouseEvents", widgetId, ignore);
2401
- }
2402
- restartWidgets(mode) {
2403
- return this.invokeMethod("restartWidgets", mode);
2984
+ async removeDeployedWidgetByName(name) {
2985
+ return this.invokeMethod("removeDeployedWidgetByName", name);
2404
2986
  }
2405
- };
2406
- var WidgetApi = new WidgetApiImpl();
2407
-
2408
- // src/api/WidgetDataApi.ts
2409
- var WidgetDataApiImpl = class {
2410
- stores = /* @__PURE__ */ new Map();
2411
2987
  /**
2412
- * 保存组件数据
2413
- * @param data
2414
- * @param options
2988
+ * 获取已添加的组件
2989
+ * @param name 组件名,可以不传
2415
2990
  */
2416
- async save(data, options = { sendBroadcast: true }) {
2417
- const store = this.getStore(data.name, options.storeName);
2418
- const json = JSON.stringify(data);
2419
- const result = await store.setItem(this.getKey(data.name, data.id), json);
2420
- if (options.sendBroadcast) {
2421
- const broadcastEvent = new BroadcastEvent({
2422
- event: "event::cn.widgetjs.core.widget.data-changed" /* DATA_CHANGED */,
2423
- payload: { name: data.name, json }
2424
- });
2425
- await BroadcastApi.send(broadcastEvent);
2426
- }
2427
- return result;
2991
+ async getDeployedWidgets(name) {
2992
+ return this.invokeMethod("getDeployedWidgets", name);
2428
2993
  }
2429
- getStore(widgetName, storeName) {
2430
- if (this.stores.has(widgetName)) {
2431
- return this.stores.get(widgetName);
2432
- }
2433
- const store = localforage__default.default.createInstance({ name: widgetName, storeName });
2434
- this.stores.set(widgetName, store);
2435
- return store;
2994
+ async getDeployedWidget(id) {
2995
+ return this.invokeMethod("getDeployedWidget", id);
2436
2996
  }
2437
2997
  /**
2438
- * 通过组件名保存组件信息,通常用于存储可以在同类组件中共用的数据
2439
- * @param data
2440
- * @param options
2998
+ * Opens the dev tools for a widget with the specified ID.
2999
+ *
3000
+ * @param {string} widgetId - The ID of the widget to open the dev tools for.
3001
+ * @return {Promise} A Promise that resolves when the dev tools are opened.
2441
3002
  */
2442
- async saveByName(data, options = { sendBroadcast: true }) {
2443
- const store = this.getStore(data.name);
2444
- const json = JSON.stringify(data);
2445
- const result = await store.setItem(data.name, json);
2446
- if (options?.sendBroadcast) {
2447
- const broadcastEvent = new BroadcastEvent({
2448
- event: "event::cn.widgetjs.core.widget.data-changed" /* DATA_CHANGED */,
2449
- payload: { name: data.name, json }
2450
- });
2451
- await BroadcastApi.send(broadcastEvent);
2452
- }
2453
- return result;
2454
- }
2455
- async findByName(...args) {
2456
- let name = "";
2457
- let dbStr = "";
2458
- let data;
2459
- if (args.length === 2) {
2460
- name = args[0];
2461
- const Type = args[1];
2462
- data = new Type(name);
2463
- } else {
2464
- data = args[0];
2465
- name = data.name;
2466
- }
2467
- const store = this.getStore(name);
2468
- dbStr = await store.getItem(name);
2469
- if (dbStr) {
2470
- data.parseJSON(JSON.parse(dbStr));
2471
- return data;
2472
- }
2473
- return void 0;
3003
+ async openDevTools(widgetId) {
3004
+ return this.invokeMethod("openDevTools", widgetId);
2474
3005
  }
2475
- async find(name, id, Type) {
2476
- const store = this.getStore(name);
2477
- const result = await store.getItem(this.getKey(name, id));
2478
- if (result) {
2479
- const widgetData = new Type(name, id);
2480
- widgetData.parseJSON(JSON.parse(result));
2481
- return widgetData;
2482
- }
2483
- return void 0;
3006
+ async openConfigPage(widgetId, params) {
3007
+ return this.invokeMethod("openConfigPage", widgetId, params);
2484
3008
  }
2485
- getKey(name, id) {
2486
- return `${name}@${id}`;
3009
+ /**
3010
+ * 注册激活、呼出、置顶组件快捷键
3011
+ * @param widgetId 组件id
3012
+ * @param shortcut 如果传空或者不传,则会取消快捷键。更多快捷键配置,请查看Accelerator用法
3013
+ * https://www.electronjs.org/docs/latest/api/accelerator
3014
+ */
3015
+ async registerActiveShortcut(widgetId, shortcut) {
3016
+ return this.invokeMethod("registerActiveShortcut", widgetId, shortcut);
3017
+ }
3018
+ async setProxy(widgetId, proxy) {
3019
+ return this.invokeMethod("setProxy", widgetId, proxy);
2487
3020
  }
2488
3021
  };
2489
- var WidgetDataApi = new WidgetDataApiImpl();
3022
+ var DeployedWidgetApi = new DeployedWidgetApiImpl();
2490
3023
 
2491
- // src/api/BrowserWindowApi.ts
2492
- var BrowserWindowApiEvent = /* @__PURE__ */ ((BrowserWindowApiEvent2) => {
2493
- BrowserWindowApiEvent2["BLUR"] = "event::cn.widgetjs.core.browser-window.blur";
2494
- BrowserWindowApiEvent2["MOVED"] = "event::cn.widgetjs.core.browser-window.moved";
2495
- BrowserWindowApiEvent2["FOCUS"] = "event::cn.widgetjs.core.browser-window.focus";
2496
- BrowserWindowApiEvent2["CLOSE"] = "event::cn.widgetjs.core.browser-window.close";
2497
- BrowserWindowApiEvent2["SNAP_TO_EDGE"] = "event::cn.widgetjs.core.browser-window.snap_to_edge";
2498
- BrowserWindowApiEvent2["RESIZED"] = "event::cn.widgetjs.core.browser-window.resized";
2499
- BrowserWindowApiEvent2["CANCEL_SNAP_TO_EDGE"] = "event::cn.widgetjs.core.browser-window.cancel_snap_to_edge";
2500
- return BrowserWindowApiEvent2;
2501
- })(BrowserWindowApiEvent || {});
2502
- var BrowserWindowApiImpl = class extends BaseApi {
2503
- getProxy() {
2504
- return this.invokeMethod("getProxy");
2505
- }
2506
- setBackgroundThrottling(enabled) {
2507
- return this.invokeMethod("setBackgroundThrottling", enabled);
2508
- }
2509
- getBackgroundThrottling() {
2510
- return this.invokeMethod("getBackgroundThrottling");
3024
+ // src/api/DeviceApi.ts
3025
+ var DeviceApiImpl = class extends BaseApi {
3026
+ getDisplayNearestPoint(point) {
3027
+ return this.invokeMethod("getDisplayNearestPoint", point);
2511
3028
  }
2512
- isResizable() {
2513
- return this.invokeMethod("isResizable");
3029
+ getAllDisplays() {
3030
+ return this.invokeMethod("getAllDisplays");
2514
3031
  }
2515
- setHasShadow(hasShadow) {
2516
- return this.invokeMethod("setHasShadow", hasShadow);
3032
+ getPrimaryDisplay() {
3033
+ return this.invokeMethod("getPrimaryDisplay");
2517
3034
  }
2518
- isDraggingWindow() {
2519
- return this.invokeMethod("isDraggingWindow");
3035
+ /**
3036
+ * 获取当前鼠标位置
3037
+ */
3038
+ async getCursorScreenPoint() {
3039
+ return this.invokeMethod("getCursorScreenPoint");
2520
3040
  }
2521
- setNoActivate() {
2522
- return this.invokeMethod("setNoActivate");
3041
+ async sendCtrlV() {
3042
+ return this.invokeMethod("sendCtrlV");
2523
3043
  }
2524
- async isVisible() {
2525
- return await this.invokeMethod("isVisible");
3044
+ /**
3045
+ * 判断是否所有按键都已经释放
3046
+ */
3047
+ async isAllKeyReleased() {
3048
+ return this.invokeMethod("isAllKeyReleased");
2526
3049
  }
2527
3050
  getChannel() {
2528
- return "channel::cn.widgetjs.core.browser_window" /* BROWSER_WINDOW */;
2529
- }
2530
- async setIgnoreMouseEvent(ignore) {
2531
- await this.invokeMethod("setIgnoreMouseEvent", ignore);
3051
+ return "channel::cn.widgetjs.core.device" /* DEVICE */;
2532
3052
  }
2533
- async show() {
2534
- await this.invokeMethod("show", true);
3053
+ isCapsLockOn() {
3054
+ return this.invokeMethod("isCapsLockOn");
2535
3055
  }
2536
- async showInactive() {
2537
- await this.invokeMethod("showInactive", true);
3056
+ };
3057
+ var DeviceApi = new DeviceApiImpl();
3058
+
3059
+ // src/api/DialogApi.ts
3060
+ var DialogApiImpl = class extends BaseApi {
3061
+ getChannel() {
3062
+ return "channel::cn.widgetjs.core.dialog" /* DIALOG */;
2538
3063
  }
2539
- async hide() {
2540
- await this.invokeMethod("hide", false);
3064
+ pickFile(extensions) {
3065
+ return this.invokeMethod("pickFile", extensions);
2541
3066
  }
2542
- async center() {
2543
- await this.invokeMethod("center", false);
3067
+ pickFolder() {
3068
+ return this.invokeMethod("pickFolder");
2544
3069
  }
2545
- async setAlwaysOnTop(alwaysOnTop) {
2546
- await this.invokeMethod("setAlwaysOnTop", alwaysOnTop);
3070
+ };
3071
+ var DialogApi = new DialogApiImpl();
3072
+
3073
+ // src/api/ElectronApi.ts
3074
+ var ElectronApi = class {
3075
+ static async addIpcListener(key, f) {
3076
+ await ElectronUtils.getAPI()?.addIpcListener(key, f);
2547
3077
  }
2548
- async isAlwaysOnTop() {
2549
- return await this.invokeMethod("isAlwaysOnTop");
3078
+ static async removeIpcListener(key) {
3079
+ await ElectronUtils.getAPI()?.removeIpcListener(key);
2550
3080
  }
2551
- async openUrl(url, option) {
2552
- if (ElectronUtils.hasElectronApi()) {
2553
- await this.invokeMethod("openUrl", url, option);
2554
- } else {
2555
- window.open(url, "_blank");
2556
- }
3081
+ };
3082
+
3083
+ // src/api/FileApi.ts
3084
+ var FileApiImpl = class extends BaseApi {
3085
+ async readShortcutLink(shortcutPath) {
3086
+ return this.invokeMethod("readShortcutLink", shortcutPath);
2557
3087
  }
2558
- async moveTop() {
2559
- await this.invokeMethod("moveTop");
3088
+ async extractIcon(path, size) {
3089
+ return this.invokeMethod("extractIcon", path, size);
2560
3090
  }
2561
- async openDevTools() {
2562
- await this.invokeMethod("openDevTools");
3091
+ async delete(filePath) {
3092
+ return this.invokeMethod("delete", filePath);
2563
3093
  }
2564
- async setPosition(options) {
2565
- await this.invokeMethod("setPosition", options);
3094
+ async getPictureMetadata(filePath) {
3095
+ return this.invokeMethod("getPictureMetadata", filePath);
2566
3096
  }
2567
- async getPosition() {
2568
- return await this.invokeMethod("getPosition");
3097
+ async move(form, to) {
3098
+ return this.invokeMethod("move", form, to);
2569
3099
  }
2570
- async blur() {
2571
- return await this.invokeMethod("blur");
3100
+ async isDirectory(filePath) {
3101
+ return this.invokeMethod("isDirectory", filePath);
2572
3102
  }
2573
- async focus() {
2574
- return await this.invokeMethod("focus");
3103
+ getChannel() {
3104
+ return "channel::cn.widgetjs.core.file" /* FILE */;
2575
3105
  }
2576
- /**
2577
- * 设置窗口是否可以拉伸
2578
- * @param resizable
2579
- */
2580
- async setResizable(resizable) {
2581
- return await this.invokeMethod("setResizable", resizable);
3106
+ async readDirectory(path, options) {
3107
+ return this.invokeMethod("readDirectory", path, options);
2582
3108
  }
2583
- async getBounds() {
2584
- return await this.invokeMethod("getBounds");
3109
+ async downloadUrl(options) {
3110
+ return this.invokeMethod("downloadUrl", options);
2585
3111
  }
2586
- async setBounds(bounds, animate) {
2587
- return await this.invokeMethod("setBounds", bounds, animate);
3112
+ async exists(filePath) {
3113
+ return this.invokeMethod("exists", filePath);
2588
3114
  }
2589
- async alignToScreen(align) {
2590
- return await this.invokeMethod("alignToScreen", align);
3115
+ async readFile(filePath) {
3116
+ return this.invokeMethod("readFile", filePath);
2591
3117
  }
2592
- async startDraggingWindow() {
2593
- return await this.invokeMethod("startDraggingWindow");
3118
+ async getDocumentFolder(filePath) {
3119
+ return this.invokeMethod("getDocumentFolder", filePath);
2594
3120
  }
2595
- async stopDraggingWindow() {
2596
- return await this.invokeMethod("stopDraggingWindow");
3121
+ async getMimeType(absoluteFilePath) {
3122
+ return this.invokeMethod("getMimeType", absoluteFilePath);
2597
3123
  }
2598
- /**
2599
- * 通过url检测窗口是否存在
2600
- * @param url
2601
- */
2602
- async existsByUrl(url) {
2603
- return await this.invokeMethod("existsByUrl", url);
3124
+ async getFileInfo(absoluteFilePath) {
3125
+ return this.invokeMethod("getFileInfo", absoluteFilePath);
2604
3126
  }
2605
- async getMaximumSize() {
2606
- return await this.invokeMethod("getMaximumSize");
3127
+ async showItemInFolder(fullPath) {
3128
+ return this.invokeMethod("showItemInFolder", fullPath);
2607
3129
  }
2608
- async minimize() {
2609
- return await this.invokeMethod("minimize");
3130
+ async openPath(path) {
3131
+ return this.invokeMethod("openPath", path);
2610
3132
  }
2611
- async maximize() {
2612
- return await this.invokeMethod("maximize");
3133
+ async trashItem(path) {
3134
+ return this.invokeMethod("trashItem", path);
2613
3135
  }
2614
- async isMaximized() {
2615
- return await this.invokeMethod("isMaximized");
3136
+ };
3137
+ var FileApi = new FileApiImpl();
3138
+
3139
+ // src/api/HttpApi.ts
3140
+ var HttpApiImpl = class extends BaseApi {
3141
+ getChannel() {
3142
+ return "channel::cn.widgetjs.core.http" /* HTTP */;
2616
3143
  }
2617
- async isMinimized() {
2618
- return await this.invokeMethod("isMinimized");
3144
+ get(url, params) {
3145
+ return this.invokeMethod("get", url, params);
2619
3146
  }
2620
- async restore() {
2621
- return await this.invokeMethod("restore");
3147
+ post(url, data) {
3148
+ return this.invokeMethod("post", url, data);
2622
3149
  }
2623
- async unmaximize() {
2624
- return await this.invokeMethod("unmaximize");
3150
+ };
3151
+ var HttpApi = new HttpApiImpl();
3152
+
3153
+ // src/api/interface/IAiApi.ts
3154
+ var AiApiEvent = /* @__PURE__ */ ((AiApiEvent2) => {
3155
+ AiApiEvent2["CONFIG_UPDATED"] = `channel::cn.widgetjs.core.ai.config.updated`;
3156
+ return AiApiEvent2;
3157
+ })(AiApiEvent || {});
3158
+
3159
+ // src/api/interface/IAppApi.ts
3160
+ var AppApiEvent = /* @__PURE__ */ ((AppApiEvent2) => {
3161
+ AppApiEvent2["CONFIG_CHANGED"] = "event::cn.widgetjs.core.app.config.changed";
3162
+ AppApiEvent2["MOVING_GRID_WINDOW"] = "event::cn.widgetjs.core.app.moving.grid.window";
3163
+ AppApiEvent2["STOP_MOVING_GRID_WINDOW"] = "event::cn.widgetjs.core.app.moving.grid.window.stop";
3164
+ AppApiEvent2["PROXY_CHANGED"] = "event::cn.widgetjs.core.app.proxy.changed";
3165
+ AppApiEvent2["LANGUAGE_CHANGED"] = "event::cn.widgetjs.core.app.language.changed";
3166
+ return AppApiEvent2;
3167
+ })(AppApiEvent || {});
3168
+ var AppApiConstants = /* @__PURE__ */ ((AppApiConstants2) => {
3169
+ AppApiConstants2["CONFIG_GRID_CELL_SIZE"] = "cn.widgetjs.config.grid.size";
3170
+ AppApiConstants2["CONFIG_WIDGET_THEME_CSS"] = "cn.widgetjs.config.widget.theme.css";
3171
+ AppApiConstants2["CONFIG_PROXY"] = "cn.widgetjs.config.app.proxy";
3172
+ AppApiConstants2["CONFIG_DEV_MODE"] = "cn.widgetjs.config.app.dev.mode";
3173
+ AppApiConstants2["CONFIG_LANGUAGE"] = "cn.widgetjs.config.app.language";
3174
+ return AppApiConstants2;
3175
+ })(AppApiConstants || {});
3176
+
3177
+ // src/api/interface/IDeployedWidgetApi.ts
3178
+ var DeployedWidgetApiEvent = /* @__PURE__ */ ((DeployedWidgetApiEvent2) => {
3179
+ DeployedWidgetApiEvent2["SECOND_INSTANCE"] = `channel::cn.widgetjs.core.deployed_widget.second_instance`;
3180
+ return DeployedWidgetApiEvent2;
3181
+ })(DeployedWidgetApiEvent || {});
3182
+
3183
+ // src/api/interface/IMouseApi.ts
3184
+ var MouseApiEvent = /* @__PURE__ */ ((MouseApiEvent2) => {
3185
+ MouseApiEvent2["HOTSPOT_ACTIVE"] = "event::cn.widgetjs.core.mouse.hotspot.active";
3186
+ return MouseApiEvent2;
3187
+ })(MouseApiEvent || {});
3188
+
3189
+ // src/api/interface/ITrayApi.ts
3190
+ var TrayApiEvent = /* @__PURE__ */ ((TrayApiEvent2) => {
3191
+ TrayApiEvent2["CLICK"] = "channel::cn.widgetjs.core.tray.click";
3192
+ TrayApiEvent2["RIGHT_CLICK"] = "channel::cn.widgetjs.core.tray.right-click";
3193
+ TrayApiEvent2["MIDDLE_CLICK"] = "channel::cn.widgetjs.core.tray.middle-click";
3194
+ TrayApiEvent2["MOUSE_ENTER"] = "channel::cn.widgetjs.core.tray.mouse-enter";
3195
+ TrayApiEvent2["MOUSE_LEAVE"] = "channel::cn.widgetjs.core.tray.mouse-leave";
3196
+ return TrayApiEvent2;
3197
+ })(TrayApiEvent || {});
3198
+
3199
+ // src/api/interface/IUserApi.ts
3200
+ var UserApiEvent = /* @__PURE__ */ ((UserApiEvent2) => {
3201
+ UserApiEvent2["USER_UPDATED"] = `channel::cn.widgetjs.core.user.updated`;
3202
+ UserApiEvent2["SIGNED_OUT"] = `channel::cn.widgetjs.core.user.signed.out`;
3203
+ UserApiEvent2["SIGNED_IN"] = `channel::cn.widgetjs.core.user.signed.in`;
3204
+ UserApiEvent2["TOKEN_REFRESHED"] = `channel::cn.widgetjs.core.user.token.refreshed`;
3205
+ return UserApiEvent2;
3206
+ })(UserApiEvent || {});
3207
+
3208
+ // src/api/interface/IWidgetPackageApi.ts
3209
+ var WidgetPackageApiEvent = /* @__PURE__ */ ((WidgetPackageApiEvent2) => {
3210
+ WidgetPackageApiEvent2["PACKAGE_UPGRADE"] = "event::cn.widgetjs.core.widget.package.upgraded";
3211
+ WidgetPackageApiEvent2["PACKAGE_INSTALLED"] = "event::cn.widgetjs.core.widget.package.installed";
3212
+ return WidgetPackageApiEvent2;
3213
+ })(WidgetPackageApiEvent || {});
3214
+
3215
+ // src/api/LogApi.ts
3216
+ var LogApiImpl = class extends BaseApi {
3217
+ getChannel() {
3218
+ return "channel::cn.widgetjs.core.log" /* LOG */;
2625
3219
  }
2626
- async setZoomLevel(level) {
2627
- return await this.invokeMethod("setZoomLevel", level);
3220
+ info(...data) {
3221
+ console.log(...data);
3222
+ this.invokeMethod("info", ...data);
2628
3223
  }
2629
- async reload() {
2630
- return await this.invokeMethod("reload");
3224
+ error(...data) {
3225
+ console.error(...data);
3226
+ this.invokeMethod("error", ...data);
2631
3227
  }
2632
- async setMovable(movable) {
2633
- return await this.invokeMethod("setMovable", movable);
3228
+ warn(...data) {
3229
+ console.warn(...data);
3230
+ this.invokeMethod("warn", ...data);
2634
3231
  }
2635
- async setSize(width, height, animate) {
2636
- return this.invokeMethod("setSize", width, height, animate);
3232
+ log(...data) {
3233
+ console.log(...data);
3234
+ this.invokeMethod("log", ...data);
2637
3235
  }
2638
- async isFocused() {
2639
- return this.invokeMethod("isFocused");
3236
+ json(data) {
3237
+ const json = JSON.stringify(data, null, 2);
3238
+ this.log(json);
2640
3239
  }
2641
- async setMaximumSize(width, height) {
2642
- return this.invokeMethod("setMaximumSize", width, height);
3240
+ };
3241
+ var LogApi = new LogApiImpl();
3242
+
3243
+ // src/api/MenuApi.ts
3244
+ var MenuApiEvent = /* @__PURE__ */ ((MenuApiEvent2) => {
3245
+ MenuApiEvent2["ITEM_CLICK"] = "event::cn.widgetjs.core.menu.item.click";
3246
+ return MenuApiEvent2;
3247
+ })(MenuApiEvent || {});
3248
+ var MenuApiImpl = class extends BaseApi {
3249
+ getChannel() {
3250
+ return "channel::cn.widgetjs.core.menu" /* MENU */;
2643
3251
  }
2644
- async setMinimumSize(width, height) {
2645
- return this.invokeMethod("setMinimumSize", width, height);
3252
+ /**
3253
+ * Add items to the context menu
3254
+ * @param menuItems The menu items to add
3255
+ */
3256
+ addContextMenuItem(menuItems) {
3257
+ return this.invokeMethod("addContextMenuItem", menuItems);
2646
3258
  }
2647
- getMinimumSize() {
2648
- return this.invokeMethod("getMinimumSize");
3259
+ /**
3260
+ * Add items to the application menu
3261
+ * @param menuItems The menu items to add
3262
+ */
3263
+ addMenuItem(menuItems) {
3264
+ return this.invokeMethod("addMenuItem", menuItems);
2649
3265
  }
2650
- close() {
2651
- return this.invokeMethod("close");
3266
+ /**
3267
+ * Show a menu programmatically
3268
+ * @param options The options for showing the menu
3269
+ */
3270
+ showMenu(options) {
3271
+ return this.invokeMethod("showMenu", options);
2652
3272
  }
2653
- setZoomFactor(factor) {
2654
- return this.invokeMethod("setZoomFactor", factor);
3273
+ /**
3274
+ * Remove items from the application menu
3275
+ * @param menuItemIds The IDs of the menu items to remove
3276
+ */
3277
+ removeMenuItem(menuItemIds) {
3278
+ return this.invokeMethod("removeMenuItem", menuItemIds);
2655
3279
  }
2656
- async setup(options) {
2657
- if (options.alwaysOnTop) {
2658
- await this.setAlwaysOnTop(true);
2659
- }
2660
- await this.setResizable(!!options.resizable);
2661
- await this.setMovable(!!options.movable);
2662
- if (options.width && options.height) {
2663
- await this.setSize(options.width, options.height);
2664
- }
2665
- if (options.minWidth && options.minHeight) {
2666
- await this.setMinimumSize(options.minWidth, options.minHeight);
2667
- }
2668
- if (options.maxWidth && options.maxHeight) {
2669
- await this.setMaximumSize(options.maxWidth, options.maxHeight);
2670
- }
2671
- if (options.center) {
2672
- await this.center();
2673
- }
2674
- if (options.x != void 0 || options.y != void 0) {
2675
- await this.setPosition({ x: options.x, y: options.y });
2676
- }
2677
- if (options.skipTaskbar) {
2678
- await this.setSkipTaskbar(true);
2679
- } else if (options.skipTaskbar === false) {
2680
- await this.setSkipTaskbar(false);
2681
- }
3280
+ /**
3281
+ * Remove items from the context menu
3282
+ * @param menuItemIds The IDs of the menu items to remove
3283
+ */
3284
+ removeContextMenuItem(menuItemIds) {
3285
+ return this.invokeMethod("removeContextMenuItem", menuItemIds);
2682
3286
  }
2683
- async setProxy(config) {
2684
- return await this.invokeMethod("setProxy", config);
3287
+ };
3288
+ var MenuApi = new MenuApiImpl();
3289
+
3290
+ // src/api/MouseApi.ts
3291
+ var MouseApiImpl = class extends BaseApi {
3292
+ getChannel() {
3293
+ return "channel::cn.widgetjs.core.mouse" /* MOUSE */;
2685
3294
  }
2686
- getSize() {
2687
- return this.invokeMethod("getSize");
3295
+ removeHotspot() {
3296
+ return this.invokeMethod("removeHotspot");
2688
3297
  }
2689
- setSkipTaskbar(skip) {
2690
- return this.invokeMethod("setSkipTaskbar", skip);
3298
+ createHotspot(rect) {
3299
+ return this.invokeMethod("createHotspot", rect);
2691
3300
  }
2692
3301
  };
2693
- var BrowserWindowApi = new BrowserWindowApiImpl();
3302
+ var MouseApi = new MouseApiImpl();
2694
3303
 
2695
3304
  // src/api/NotificationApi.ts
2696
3305
  var NotificationApiEvent = /* @__PURE__ */ ((NotificationApiEvent2) => {
@@ -2766,191 +3375,52 @@ var NotificationApiImpl = class extends BaseApi {
2766
3375
  }));
2767
3376
  }
2768
3377
  async warning(message, duration = 5e3) {
2769
- await this.send(new AppNotification({
2770
- message,
2771
- type: "warning",
2772
- icon: "attention",
2773
- duration
2774
- }));
2775
- }
2776
- async info(message, duration = 5e3) {
2777
- await this.send(new AppNotification({
2778
- message,
2779
- type: "info",
2780
- icon: "info",
2781
- duration
2782
- }));
2783
- }
2784
- /**
2785
- * 隐藏通知
2786
- */
2787
- async hide() {
2788
- await this.invokeMethod("hide");
2789
- }
2790
- getChannel() {
2791
- return "channel::cn.widgetjs.core.notification" /* NOTIFICATION */;
2792
- }
2793
- };
2794
- var NotificationApi = new NotificationApiImpl();
2795
-
2796
- // src/utils/AppProtocolUtils.ts
2797
- var AppProtocolUtils = class {
2798
- static getBaseURL() {
2799
- return new URL("widget://widgetjs.cn");
2800
- }
2801
- static getAddWidgetUrl(options) {
2802
- const url = this.getBaseURL();
2803
- url.pathname = "/widget/add";
2804
- if (options.packageJsonUrl) {
2805
- url.searchParams.set("packageJsonUrl", options.packageJsonUrl);
2806
- }
2807
- if (options.hostname) {
2808
- url.searchParams.set("hostname", options.hostname);
2809
- }
2810
- if (options.widgetTitle) {
2811
- url.searchParams.set("widgetTitle", options.widgetTitle);
2812
- }
2813
- url.searchParams.set("widgetName", options.widgetName);
2814
- url.searchParams.set("deployMode", options.deployMode.toString());
2815
- return url.toString();
2816
- }
2817
- };
2818
-
2819
- // src/api/DeployedWidgetApi.ts
2820
- var DeployedWidgetApiImpl = class extends BaseApi {
2821
- getChannel() {
2822
- return "channel::cn.widgetjs.core.deployed_widget" /* DEPLOYED_WIDGET */;
2823
- }
2824
- /**
2825
- * 移除组件
2826
- * @param id
2827
- */
2828
- async removeDeployedWidget(id) {
2829
- return this.invokeMethod("removeDeployedWidget", id);
2830
- }
2831
- addWidget(options) {
2832
- if (ElectronUtils.hasElectronApi()) {
2833
- return this.invokeMethod("addWidget", options);
2834
- } else {
2835
- window.location.href = AppProtocolUtils.getAddWidgetUrl(options);
2836
- return Promise.resolve([]);
2837
- }
2838
- }
2839
- /**
2840
- * 通过组件名移除已添加的组件
2841
- * @param name 组件名
2842
- */
2843
- async removeDeployedWidgetByName(name) {
2844
- return this.invokeMethod("removeDeployedWidgetByName", name);
2845
- }
2846
- /**
2847
- * 获取已添加的组件
2848
- * @param name 组件名,可以不传
2849
- */
2850
- async getDeployedWidgets(name) {
2851
- return this.invokeMethod("getDeployedWidgets", name);
2852
- }
2853
- async getDeployedWidget(id) {
2854
- return this.invokeMethod("getDeployedWidget", id);
2855
- }
2856
- /**
2857
- * Opens the dev tools for a widget with the specified ID.
2858
- *
2859
- * @param {string} widgetId - The ID of the widget to open the dev tools for.
2860
- * @return {Promise} A Promise that resolves when the dev tools are opened.
2861
- */
2862
- async openDevTools(widgetId) {
2863
- return this.invokeMethod("openDevTools", widgetId);
2864
- }
2865
- async openConfigPage(widgetId, params) {
2866
- return this.invokeMethod("openConfigPage", widgetId, params);
2867
- }
2868
- /**
2869
- * 注册激活、呼出、置顶组件快捷键
2870
- * @param widgetId 组件id
2871
- * @param shortcut 如果传空或者不传,则会取消快捷键。更多快捷键配置,请查看Accelerator用法
2872
- * https://www.electronjs.org/docs/latest/api/accelerator
2873
- */
2874
- async registerActiveShortcut(widgetId, shortcut) {
2875
- return this.invokeMethod("registerActiveShortcut", widgetId, shortcut);
2876
- }
2877
- async setProxy(widgetId, proxy) {
2878
- return this.invokeMethod("setProxy", widgetId, proxy);
2879
- }
2880
- };
2881
- var DeployedWidgetApi = new DeployedWidgetApiImpl();
2882
-
2883
- // src/api/DeviceApi.ts
2884
- var DeviceApiImpl = class extends BaseApi {
2885
- getDisplayNearestPoint(point) {
2886
- return this.invokeMethod("getDisplayNearestPoint", point);
2887
- }
2888
- getAllDisplays() {
2889
- return this.invokeMethod("getAllDisplays");
2890
- }
2891
- getPrimaryDisplay() {
2892
- return this.invokeMethod("getPrimaryDisplay");
2893
- }
2894
- /**
2895
- * 获取当前鼠标位置
2896
- */
2897
- async getCursorScreenPoint() {
2898
- return this.invokeMethod("getCursorScreenPoint");
3378
+ await this.send(new AppNotification({
3379
+ message,
3380
+ type: "warning",
3381
+ icon: "attention",
3382
+ duration
3383
+ }));
2899
3384
  }
2900
- async sendCtrlV() {
2901
- return this.invokeMethod("sendCtrlV");
3385
+ async info(message, duration = 5e3) {
3386
+ await this.send(new AppNotification({
3387
+ message,
3388
+ type: "info",
3389
+ icon: "info",
3390
+ duration
3391
+ }));
2902
3392
  }
2903
3393
  /**
2904
- * 判断是否所有按键都已经释放
3394
+ * 隐藏通知
2905
3395
  */
2906
- async isAllKeyReleased() {
2907
- return this.invokeMethod("isAllKeyReleased");
3396
+ async hide() {
3397
+ await this.invokeMethod("hide");
2908
3398
  }
2909
3399
  getChannel() {
2910
- return "channel::cn.widgetjs.core.device" /* DEVICE */;
2911
- }
2912
- isCapsLockOn() {
2913
- return this.invokeMethod("isCapsLockOn");
3400
+ return "channel::cn.widgetjs.core.notification" /* NOTIFICATION */;
2914
3401
  }
2915
3402
  };
2916
- var DeviceApi = new DeviceApiImpl();
3403
+ var NotificationApi = new NotificationApiImpl();
2917
3404
 
2918
- // src/api/ClipboardApi.ts
2919
- var ClipboardApiEvent = /* @__PURE__ */ ((ClipboardApiEvent2) => {
2920
- ClipboardApiEvent2["CHANGED"] = "clipboard-changed";
2921
- return ClipboardApiEvent2;
2922
- })(ClipboardApiEvent || {});
2923
- var ClipboardApiImpl = class extends BaseApi {
2924
- writeText(text) {
2925
- return this.invokeMethod("writeText", text);
3405
+ // src/api/ProcessApi.ts
3406
+ var ProcessApiImpl = class extends BaseApi {
3407
+ getChannel() {
3408
+ return "channel::cn.widgetjs.core.process" /* PROCESS */;
2926
3409
  }
2927
- async getSelectedText() {
2928
- return this.invokeMethod("getSelectedText");
3410
+ getBlinkMemoryInfo() {
3411
+ return this.invokeMethod("getBlinkMemoryInfo");
2929
3412
  }
2930
- async getText() {
2931
- return this.invokeMethod("getText");
3413
+ getHeapStatistics() {
3414
+ return this.invokeMethod("getHeapStatistics");
2932
3415
  }
2933
- getChannel() {
2934
- return "channel::cn.widgetjs.core.clipboard" /* CLIPBOARD */;
3416
+ getProcessMemoryInfo() {
3417
+ return this.invokeMethod("getProcessMemoryInfo");
3418
+ }
3419
+ getSystemVersion() {
3420
+ return this.invokeMethod("getSystemVersion");
2935
3421
  }
2936
3422
  };
2937
- var ClipboardApi = new ClipboardApiImpl();
2938
-
2939
- // src/api/ApiConstants.ts
2940
- var ApiConstants = class {
2941
- static CONFIG_LAUNCH_AT_STARTUP = "CONFIG_LAUNCH_AT_STARTUP";
2942
- static CONFIG_WIDGET_TITLE_COLOR = "CONFIG_WIDGET_TITLE_COLOR";
2943
- static CONFIG_DEBUG_MODE = "cn.widgetjs.config.debug";
2944
- static CONFIG_GRID_CELL_SIZE = "cn.widgetjs.config.grid.size";
2945
- static SHORTCUT_PIN_DESKTOP_WIDGETS = "cn.widgetjs.config.shortcut.pin_desktop_widgets";
2946
- };
2947
- var AppEvent = class {
2948
- static LANGUAGE_CHANGED = "event::cn.widgetjs.core.app.language.changed";
2949
- };
2950
- var AppConfig = class {
2951
- static LANGUAGE = "cn.widgetjs.config.app.language";
2952
- static LAUNCH_AT_STARTUP = "CONFIG_LAUNCH_AT_STARTUP";
2953
- };
3423
+ var ProcessApi = new ProcessApiImpl();
2954
3424
 
2955
3425
  // src/api/interface/IShortcutApi.ts
2956
3426
  var ShortcutApiEvent = /* @__PURE__ */ ((ShortcutApiEvent2) => {
@@ -2972,363 +3442,331 @@ var ShortcutApiImpl = class extends BaseApi {
2972
3442
  };
2973
3443
  var ShortcutApi = new ShortcutApiImpl();
2974
3444
 
2975
- // src/api/ProcessApi.ts
2976
- var ProcessApiImpl = class extends BaseApi {
2977
- getChannel() {
2978
- return "channel::cn.widgetjs.core.process" /* PROCESS */;
2979
- }
2980
- getBlinkMemoryInfo() {
2981
- return this.invokeMethod("getBlinkMemoryInfo");
2982
- }
2983
- getHeapStatistics() {
2984
- return this.invokeMethod("getHeapStatistics");
2985
- }
2986
- getProcessMemoryInfo() {
2987
- return this.invokeMethod("getProcessMemoryInfo");
2988
- }
2989
- getSystemVersion() {
2990
- return this.invokeMethod("getSystemVersion");
2991
- }
2992
- };
2993
- var ProcessApi = new ProcessApiImpl();
2994
-
2995
- // src/api/AppApi.ts
2996
- var AppApiImpl = class extends BaseApi {
2997
- showAppWindow(route, options) {
2998
- return this.invokeMethod("showAppWindow", route, options);
2999
- }
3000
- openWidgetPackageManagerWindow() {
3001
- return this.invokeMethod("openWidgetPackageManagerWindow");
3002
- }
3003
- getRuntimeInfo() {
3004
- return this.invokeMethod("getRuntimeInfo");
3005
- }
3006
- setProxy(config) {
3007
- return this.invokeMethod("setProxy", config);
3008
- }
3009
- getProxy() {
3010
- return this.invokeMethod("getProxy");
3011
- }
3012
- isWindowsStore() {
3013
- return this.invokeMethod("isWindowsStore");
3014
- }
3015
- getAppPath() {
3016
- return this.invokeMethod("getAppPath");
3017
- }
3018
- async getIconFile() {
3019
- return this.invokeMethod("getIconFile");
3020
- }
3445
+ // src/api/StorageApi.ts
3446
+ var StorageApiImpl = class extends BaseApi {
3021
3447
  getChannel() {
3022
- return "channel::cn.widgetjs.core.app" /* APP */;
3448
+ return "channel::cn.widgetjs.core.store" /* STORE */;
3023
3449
  }
3024
- async setConfig(key, value) {
3025
- return await this.invokeMethod("setConfig", key, value);
3450
+ async delete(key) {
3451
+ return this.invokeMethod("delete", key);
3026
3452
  }
3027
- async getConfig(key, defaultValue) {
3028
- const value = await this.invokeMethod("getConfig", key);
3029
- if (value === null || value === void 0) {
3453
+ async get(key, defaultValue) {
3454
+ const result = await this.invokeMethod("get", key);
3455
+ if (result == null && defaultValue != void 0) {
3030
3456
  return defaultValue;
3031
3457
  }
3032
- if (typeof defaultValue == "boolean") {
3033
- return value === "true";
3458
+ return result;
3459
+ }
3460
+ async getObject(key, defaultValue) {
3461
+ const result = await this.invokeMethod("get", key);
3462
+ if (result) {
3463
+ return JSON.parse(result);
3034
3464
  }
3035
- if (typeof defaultValue == "number") {
3036
- return Number(value);
3465
+ if (defaultValue != void 0) {
3466
+ return defaultValue;
3037
3467
  }
3038
- return value;
3039
- }
3040
- async openAddWidgetWindow() {
3041
- return this.invokeMethod("openAddWidgetWindow");
3042
- }
3043
- async getVersion(type) {
3044
- return this.invokeMethod("getVersion", type);
3045
- }
3046
- async getPreloadPath() {
3047
- return this.invokeMethod("getPreloadPath");
3048
- }
3049
- async openSettingWindow() {
3050
- return this.invokeMethod("openSettingWindow");
3051
- }
3052
- getThemeCSS() {
3053
- return this.invokeMethod("getThemeCSS");
3468
+ return void 0;
3054
3469
  }
3055
- setThemeCSS(css) {
3056
- return this.invokeMethod("setThemeCSS", css);
3470
+ async set(key, value) {
3471
+ if (typeof value == "object") {
3472
+ return this.invokeMethod("set", key, JSON.stringify(value));
3473
+ }
3474
+ return this.invokeMethod("set", key, value);
3057
3475
  }
3058
- getDevMode() {
3059
- return this.invokeMethod("getDevMode");
3476
+ decryptString(value) {
3477
+ return this.invokeMethod("decryptString", value);
3060
3478
  }
3061
- setDevMode(enable) {
3062
- return this.invokeMethod("setDevMode", enable);
3479
+ decryptGet(key, defaultValue) {
3480
+ return this.invokeMethod("decryptGet", key, defaultValue);
3063
3481
  }
3064
- getLanguageCode() {
3065
- if (ElectronUtils.hasElectronApi()) {
3066
- return this.invokeMethod("getLanguageCode");
3067
- }
3068
- return Promise.resolve(navigator.language);
3482
+ encryptSet(key, value) {
3483
+ return this.invokeMethod("encryptSet", key, value);
3069
3484
  }
3070
- async setLanguageCode(code) {
3071
- await this.invokeMethod("setLanguageCode", code);
3485
+ encryptString(value) {
3486
+ return this.invokeMethod("encryptString", value);
3072
3487
  }
3073
- getGridCellSize() {
3074
- return this.invokeMethod("getGridCellSize");
3488
+ };
3489
+ var StorageApi = new StorageApiImpl();
3490
+ var StoreApi = new StorageApiImpl();
3491
+
3492
+ // src/api/structures/Gravity.ts
3493
+ var Gravity = /* @__PURE__ */ ((Gravity2) => {
3494
+ Gravity2["TOP"] = "TOP";
3495
+ Gravity2["LEFT"] = "LEFT";
3496
+ Gravity2["RIGHT"] = "RIGHT";
3497
+ Gravity2["BOTTOM"] = "BOTTOM";
3498
+ return Gravity2;
3499
+ })(Gravity || {});
3500
+
3501
+ // src/api/interface/ISystemApi.ts
3502
+ var SystemApiEvent = /* @__PURE__ */ ((SystemApiEvent2) => {
3503
+ SystemApiEvent2["DATE_CHANGED"] = "event::cn.widgetjs.core.sys.date.changed";
3504
+ return SystemApiEvent2;
3505
+ })(SystemApiEvent || {});
3506
+
3507
+ // src/api/SystemApi.ts
3508
+ var SystemApiImpl = class extends BaseApi {
3509
+ launchWindowsSettings(uri) {
3510
+ return this.invokeMethod("launchWindowsSettings", uri);
3075
3511
  }
3076
- setGridCellSize(size) {
3077
- return this.invokeMethod("setGridCellSize", size);
3512
+ launchStoreDetailsPage(storeId) {
3513
+ return this.invokeMethod("launchStoreDetailsPage", storeId ?? "9NPR50GQ7T53");
3078
3514
  }
3079
- exit() {
3080
- return this.invokeMethod("exit");
3515
+ getChannel() {
3516
+ return "channel::cn.widgetjs.core.system" /* SYSTEM */;
3081
3517
  }
3082
- openCheckUpdateWindow() {
3083
- return this.invokeMethod(`openCheckUpdateWindow`);
3518
+ getWallpaper() {
3519
+ return this.invokeMethod("getWallpaper");
3084
3520
  }
3085
- openWidgetManagerWindow() {
3086
- return this.invokeMethod(`openWidgetManagerWindow`);
3521
+ getInfo(valuesObject) {
3522
+ return this.invokeMethod("getInfo", valuesObject);
3087
3523
  }
3088
- openRuntimeInfoWindow() {
3089
- return this.invokeMethod(`openRuntimeInfoWindow`);
3524
+ getUptime() {
3525
+ return this.invokeMethod("getUptime");
3090
3526
  }
3091
3527
  };
3092
- var AppApi = new AppApiImpl();
3528
+ var SystemApi = new SystemApiImpl();
3093
3529
 
3094
- // src/api/DialogApi.ts
3095
- var DialogApiImpl = class extends BaseApi {
3530
+ // src/api/TrayApi.ts
3531
+ var TrayApiImpl = class extends BaseApi {
3096
3532
  getChannel() {
3097
- return "channel::cn.widgetjs.core.dialog" /* DIALOG */;
3098
- }
3099
- pickFile(extensions) {
3100
- return this.invokeMethod("pickFile", extensions);
3533
+ return "channel::cn.widgetjs.core.tray" /* TRAY */;
3101
3534
  }
3102
- pickFolder() {
3103
- return this.invokeMethod("pickFolder");
3535
+ setTray(options) {
3536
+ return this.invokeMethod("setTray", options);
3104
3537
  }
3105
- };
3106
- var DialogApi = new DialogApiImpl();
3107
-
3108
- // src/api/StorageApi.ts
3109
- var StorageApiImpl = class extends BaseApi {
3110
- getChannel() {
3111
- return "channel::cn.widgetjs.core.store" /* STORE */;
3538
+ removeTray() {
3539
+ return this.invokeMethod("removeTray");
3112
3540
  }
3113
- async delete(key) {
3114
- return this.invokeMethod("delete", key);
3541
+ displayBalloon(options) {
3542
+ return this.invokeMethod("displayBalloon", options);
3115
3543
  }
3116
- async get(key, defaultValue) {
3117
- const result = await this.invokeMethod("get", key);
3118
- if (result == null && defaultValue != void 0) {
3119
- return defaultValue;
3120
- }
3121
- return result;
3544
+ removeBalloon() {
3545
+ return this.invokeMethod("removeBalloon");
3122
3546
  }
3123
- async getObject(key, defaultValue) {
3124
- const result = await this.invokeMethod("get", key);
3125
- if (result) {
3126
- return JSON.parse(result);
3127
- }
3128
- if (defaultValue != void 0) {
3129
- return defaultValue;
3130
- }
3131
- return void 0;
3547
+ setContextMenu(menus) {
3548
+ return this.invokeMethod("setContextMenu", menus);
3132
3549
  }
3133
- async set(key, value) {
3134
- if (typeof value == "object") {
3135
- return this.invokeMethod("set", key, JSON.stringify(value));
3136
- }
3137
- return this.invokeMethod("set", key, value);
3550
+ closeContextMenu() {
3551
+ return this.invokeMethod("closeContextMenu");
3138
3552
  }
3139
- decryptString(value) {
3140
- return this.invokeMethod("decryptString", value);
3553
+ popUpContextMenu(menus, position) {
3554
+ return this.invokeMethod("popUpContextMenu", menus, position);
3141
3555
  }
3142
- decryptGet(key, defaultValue) {
3143
- return this.invokeMethod("decryptGet", key, defaultValue);
3556
+ isDestroyed() {
3557
+ return this.invokeMethod("isDestroyed");
3144
3558
  }
3145
- encryptSet(key, value) {
3146
- return this.invokeMethod("encryptSet", key, value);
3559
+ getBounds() {
3560
+ return this.invokeMethod("getBounds");
3147
3561
  }
3148
- encryptString(value) {
3149
- return this.invokeMethod("encryptString", value);
3562
+ focus() {
3563
+ return this.invokeMethod("focus");
3150
3564
  }
3151
3565
  };
3152
- var StorageApi = new StorageApiImpl();
3153
- var StoreApi = new StorageApiImpl();
3566
+ var TrayApi = new TrayApiImpl();
3154
3567
 
3155
- // src/api/LogApi.ts
3156
- var LogApiImpl = class extends BaseApi {
3157
- getChannel() {
3158
- return "channel::cn.widgetjs.core.log" /* LOG */;
3568
+ // src/api/UserApi.ts
3569
+ var UserApiImpl = class extends BaseApi {
3570
+ async getSession() {
3571
+ return await this.invokeMethod("getSession");
3159
3572
  }
3160
- info(...data) {
3161
- console.log(...data);
3162
- this.invokeMethod("info", ...data);
3573
+ async updateSession(session) {
3574
+ await this.invokeMethod("updateSession", session);
3163
3575
  }
3164
- error(...data) {
3165
- console.error(...data);
3166
- this.invokeMethod("error", ...data);
3576
+ async updateUser(user) {
3577
+ await this.invokeMethod("updateUser", user);
3167
3578
  }
3168
- warn(...data) {
3169
- console.warn(...data);
3170
- this.invokeMethod("warn", ...data);
3579
+ async login(session) {
3580
+ await this.invokeMethod("login", session);
3171
3581
  }
3172
- log(...data) {
3173
- console.log(...data);
3174
- this.invokeMethod("log", ...data);
3582
+ async logout() {
3583
+ await this.invokeMethod("logout");
3175
3584
  }
3176
- json(data) {
3177
- const json = JSON.stringify(data, null, 2);
3178
- this.log(json);
3585
+ async getUser() {
3586
+ return await this.invokeMethod("getUser");
3587
+ }
3588
+ getChannel() {
3589
+ return "channel::cn.widgetjs.core.user" /* USER */;
3179
3590
  }
3180
3591
  };
3181
- var LogApi = new LogApiImpl();
3592
+ var UserApi = new UserApiImpl();
3182
3593
 
3183
- // src/api/FileApi.ts
3184
- var FileApiImpl = class extends BaseApi {
3185
- async readShortcutLink(shortcutPath) {
3186
- return this.invokeMethod("readShortcutLink", shortcutPath);
3594
+ // src/api/WidgetApi.ts
3595
+ var WidgetApiEvent = /* @__PURE__ */ ((WidgetApiEvent2) => {
3596
+ WidgetApiEvent2["DATA_CHANGED"] = "event::cn.widgetjs.core.widget.data-changed";
3597
+ WidgetApiEvent2["EDIT_DESKTOP_WIDGETS"] = "event::cn.widgetjs.core.widget.desktop.edit";
3598
+ WidgetApiEvent2["PACKAGE_UPGRADE"] = "event::cn.widgetjs.core.widget.package.upgraded";
3599
+ WidgetApiEvent2["PACKAGE_INSTALLED"] = "event::cn.widgetjs.core.widget.package.installed";
3600
+ return WidgetApiEvent2;
3601
+ })(WidgetApiEvent || {});
3602
+ var WidgetApiImpl = class extends BaseApi {
3603
+ getSyncInfo(widgetName) {
3604
+ return this.invokeMethod("getSyncInfo", widgetName);
3187
3605
  }
3188
- async extractIcon(path, size) {
3189
- return this.invokeMethod("extractIcon", path, size);
3606
+ updateSyncInfo() {
3607
+ return this.invokeMethod("updateSyncInfo");
3190
3608
  }
3191
- async delete(filePath) {
3192
- return this.invokeMethod("delete", filePath);
3609
+ reload(id) {
3610
+ return this.invokeMethod("reload", id);
3193
3611
  }
3194
- async getPictureMetadata(filePath) {
3195
- return this.invokeMethod("getPictureMetadata", filePath);
3612
+ getChannel() {
3613
+ return "channel::cn.widgetjs.core.widget" /* WIDGET */;
3196
3614
  }
3197
- async move(form, to) {
3198
- return this.invokeMethod("move", form, to);
3615
+ async registerWidgets(widgets) {
3616
+ return this.invokeMethod("registerWidgets", JSON.stringify(widgets));
3199
3617
  }
3200
- async isDirectory(filePath) {
3201
- return this.invokeMethod("isDirectory", filePath);
3618
+ async registerWidgetPackage(widgetPackage) {
3619
+ return this.invokeMethod("registerWidgetPackage", JSON.stringify(widgetPackage));
3202
3620
  }
3203
- getChannel() {
3204
- return "channel::cn.widgetjs.core.file" /* FILE */;
3621
+ async getWidgets() {
3622
+ const data = await this.invokeMethod("getWidgets");
3623
+ const widgets = [];
3624
+ if (data) {
3625
+ for (const item of data) {
3626
+ widgets.push(Widget.parseObject(item));
3627
+ }
3628
+ }
3629
+ return widgets;
3205
3630
  }
3206
- async readDirectory(path, options) {
3207
- return this.invokeMethod("readDirectory", path, options);
3631
+ async openConfigPage(widgetId) {
3632
+ return this.invokeMethod("openConfigPage", widgetId);
3208
3633
  }
3209
- async downloadUrl(options) {
3210
- return this.invokeMethod("downloadUrl", options);
3634
+ async openConfigPageByName(widgetName) {
3635
+ return this.invokeMethod("openConfigPageByName", widgetName);
3211
3636
  }
3212
- async exists(filePath) {
3213
- return this.invokeMethod("exists", filePath);
3637
+ /**
3638
+ * @deprecated
3639
+ */
3640
+ async getWidgetPackages() {
3641
+ return await this.invokeMethod("getWidgetPackages");
3214
3642
  }
3215
- async readFile(filePath) {
3216
- return this.invokeMethod("readFile", filePath);
3643
+ /**
3644
+ *
3645
+ * @param name package name
3646
+ */
3647
+ async getWidget(name) {
3648
+ return Widget.parseObject(await this.invokeMethod("getWidget", name));
3217
3649
  }
3218
- async getDocumentFolder(filePath) {
3219
- return this.invokeMethod("getDocumentFolder", filePath);
3650
+ /**
3651
+ * @param name package name
3652
+ * @deprecated
3653
+ */
3654
+ async getWidgetPackage(name) {
3655
+ const result = await this.invokeMethod("getWidgetPackage", name);
3656
+ if (result) {
3657
+ return WidgetPackage.parseObject(result);
3658
+ }
3659
+ return void 0;
3220
3660
  }
3221
- async getMimeType(absoluteFilePath) {
3222
- return this.invokeMethod("getMimeType", absoluteFilePath);
3661
+ async getWidgetPackageUrl(packageName) {
3662
+ const widgetPackage = await this.getWidgetPackage(packageName);
3663
+ if (!widgetPackage) {
3664
+ return null;
3665
+ }
3666
+ return widgetPackage.url;
3223
3667
  }
3224
- async getFileInfo(absoluteFilePath) {
3225
- return this.invokeMethod("getFileInfo", absoluteFilePath);
3668
+ async upgradePackage(packageName) {
3669
+ return await this.invokeMethod("upgradePackage", packageName);
3226
3670
  }
3227
- async showItemInFolder(fullPath) {
3228
- return this.invokeMethod("showItemInFolder", fullPath);
3671
+ /**
3672
+ * 阻止拖动窗口,只能用于悬浮窗口 DeployMode.OVERLAP
3673
+ * @param draggable
3674
+ */
3675
+ setMouseDraggable(draggable) {
3676
+ return this.invokeMethod("setMouseDraggable", draggable);
3229
3677
  }
3230
- async openPath(path) {
3231
- return this.invokeMethod("openPath", path);
3678
+ isIgnoreMouseEvents(widgetId) {
3679
+ return this.invokeMethod("isIgnoreMouseEvents", widgetId);
3232
3680
  }
3233
- async trashItem(path) {
3234
- return this.invokeMethod("trashItem", path);
3681
+ setIgnoreMouseEvents(widgetId, ignore) {
3682
+ return this.invokeMethod("setIgnoreMouseEvents", widgetId, ignore);
3683
+ }
3684
+ restartWidgets(mode) {
3685
+ return this.invokeMethod("restartWidgets", mode);
3235
3686
  }
3236
3687
  };
3237
- var FileApi = new FileApiImpl();
3238
-
3239
- // src/api/structures/Gravity.ts
3240
- var Gravity = /* @__PURE__ */ ((Gravity2) => {
3241
- Gravity2["TOP"] = "TOP";
3242
- Gravity2["LEFT"] = "LEFT";
3243
- Gravity2["RIGHT"] = "RIGHT";
3244
- Gravity2["BOTTOM"] = "BOTTOM";
3245
- return Gravity2;
3246
- })(Gravity || {});
3247
-
3248
- // src/api/interface/ISystemApi.ts
3249
- var SystemApiEvent = /* @__PURE__ */ ((SystemApiEvent2) => {
3250
- SystemApiEvent2["DATE_CHANGED"] = "event::cn.widgetjs.core.sys.date.changed";
3251
- return SystemApiEvent2;
3252
- })(SystemApiEvent || {});
3253
-
3254
- // src/api/SystemApi.ts
3255
- var SystemApiImpl = class extends BaseApi {
3256
- launchWindowsSettings(uri) {
3257
- return this.invokeMethod("launchWindowsSettings", uri);
3688
+ var WidgetApi = new WidgetApiImpl();
3689
+ var WidgetDataApiImpl = class {
3690
+ stores = /* @__PURE__ */ new Map();
3691
+ /**
3692
+ * 保存组件数据
3693
+ * @param data
3694
+ * @param options
3695
+ */
3696
+ async save(data, options = { sendBroadcast: true }) {
3697
+ const store = this.getStore(data.name, options.storeName);
3698
+ const json = JSON.stringify(data);
3699
+ const result = await store.setItem(this.getKey(data.name, data.id), json);
3700
+ if (options.sendBroadcast) {
3701
+ const broadcastEvent = new BroadcastEvent({
3702
+ event: "event::cn.widgetjs.core.widget.data-changed" /* DATA_CHANGED */,
3703
+ payload: { name: data.name, json }
3704
+ });
3705
+ await BroadcastApi.send(broadcastEvent);
3706
+ }
3707
+ return result;
3258
3708
  }
3259
- launchStoreDetailsPage(storeId) {
3260
- return this.invokeMethod("launchStoreDetailsPage", storeId ?? "9NPR50GQ7T53");
3709
+ getStore(widgetName, storeName) {
3710
+ if (this.stores.has(widgetName)) {
3711
+ return this.stores.get(widgetName);
3712
+ }
3713
+ const store = localforage__default.default.createInstance({ name: widgetName, storeName });
3714
+ this.stores.set(widgetName, store);
3715
+ return store;
3261
3716
  }
3262
- getChannel() {
3263
- return "channel::cn.widgetjs.core.system" /* SYSTEM */;
3717
+ /**
3718
+ * 通过组件名保存组件信息,通常用于存储可以在同类组件中共用的数据
3719
+ * @param data
3720
+ * @param options
3721
+ */
3722
+ async saveByName(data, options = { sendBroadcast: true }) {
3723
+ const store = this.getStore(data.name);
3724
+ const json = JSON.stringify(data);
3725
+ const result = await store.setItem(data.name, json);
3726
+ if (options?.sendBroadcast) {
3727
+ const broadcastEvent = new BroadcastEvent({
3728
+ event: "event::cn.widgetjs.core.widget.data-changed" /* DATA_CHANGED */,
3729
+ payload: { name: data.name, json }
3730
+ });
3731
+ await BroadcastApi.send(broadcastEvent);
3732
+ }
3733
+ return result;
3264
3734
  }
3265
- getWallpaper() {
3266
- return this.invokeMethod("getWallpaper");
3735
+ async findByName(...args) {
3736
+ let name = "";
3737
+ let dbStr = "";
3738
+ let data;
3739
+ if (args.length === 2) {
3740
+ name = args[0];
3741
+ const Type = args[1];
3742
+ data = new Type(name);
3743
+ } else {
3744
+ data = args[0];
3745
+ name = data.name;
3746
+ }
3747
+ const store = this.getStore(name);
3748
+ dbStr = await store.getItem(name);
3749
+ if (dbStr) {
3750
+ data.parseJSON(JSON.parse(dbStr));
3751
+ return data;
3752
+ }
3753
+ return void 0;
3267
3754
  }
3268
- getInfo(valuesObject) {
3269
- return this.invokeMethod("getInfo", valuesObject);
3755
+ async find(name, id, Type) {
3756
+ const store = this.getStore(name);
3757
+ const result = await store.getItem(this.getKey(name, id));
3758
+ if (result) {
3759
+ const widgetData = new Type(name, id);
3760
+ widgetData.parseJSON(JSON.parse(result));
3761
+ return widgetData;
3762
+ }
3763
+ return void 0;
3270
3764
  }
3271
- getUptime() {
3272
- return this.invokeMethod("getUptime");
3765
+ getKey(name, id) {
3766
+ return `${name}@${id}`;
3273
3767
  }
3274
3768
  };
3275
- var SystemApi = new SystemApiImpl();
3276
-
3277
- // src/api/interface/IAppApi.ts
3278
- var AppApiEvent = /* @__PURE__ */ ((AppApiEvent2) => {
3279
- AppApiEvent2["CONFIG_CHANGED"] = "event::cn.widgetjs.core.app.config.changed";
3280
- AppApiEvent2["MOVING_GRID_WINDOW"] = "event::cn.widgetjs.core.app.moving.grid.window";
3281
- AppApiEvent2["STOP_MOVING_GRID_WINDOW"] = "event::cn.widgetjs.core.app.moving.grid.window.stop";
3282
- AppApiEvent2["PROXY_CHANGED"] = "event::cn.widgetjs.core.app.proxy.changed";
3283
- AppApiEvent2["LANGUAGE_CHANGED"] = "event::cn.widgetjs.core.app.language.changed";
3284
- return AppApiEvent2;
3285
- })(AppApiEvent || {});
3286
- var AppApiConstants = /* @__PURE__ */ ((AppApiConstants2) => {
3287
- AppApiConstants2["CONFIG_GRID_CELL_SIZE"] = "cn.widgetjs.config.grid.size";
3288
- AppApiConstants2["CONFIG_WIDGET_THEME_CSS"] = "cn.widgetjs.config.widget.theme.css";
3289
- AppApiConstants2["CONFIG_PROXY"] = "cn.widgetjs.config.app.proxy";
3290
- AppApiConstants2["CONFIG_DEV_MODE"] = "cn.widgetjs.config.app.dev.mode";
3291
- AppApiConstants2["CONFIG_LANGUAGE"] = "cn.widgetjs.config.app.language";
3292
- return AppApiConstants2;
3293
- })(AppApiConstants || {});
3294
-
3295
- // src/api/interface/IWidgetPackageApi.ts
3296
- var WidgetPackageApiEvent = /* @__PURE__ */ ((WidgetPackageApiEvent2) => {
3297
- WidgetPackageApiEvent2["PACKAGE_UPGRADE"] = "event::cn.widgetjs.core.widget.package.upgraded";
3298
- WidgetPackageApiEvent2["PACKAGE_INSTALLED"] = "event::cn.widgetjs.core.widget.package.installed";
3299
- return WidgetPackageApiEvent2;
3300
- })(WidgetPackageApiEvent || {});
3301
-
3302
- // src/api/interface/IMouseApi.ts
3303
- var MouseApiEvent = /* @__PURE__ */ ((MouseApiEvent2) => {
3304
- MouseApiEvent2["HOTSPOT_ACTIVE"] = "event::cn.widgetjs.core.mouse.hotspot.active";
3305
- return MouseApiEvent2;
3306
- })(MouseApiEvent || {});
3307
-
3308
- // src/api/interface/ITrayApi.ts
3309
- var TrayApiEvent = /* @__PURE__ */ ((TrayApiEvent2) => {
3310
- TrayApiEvent2["CLICK"] = "channel::cn.widgetjs.core.tray.click";
3311
- TrayApiEvent2["RIGHT_CLICK"] = "channel::cn.widgetjs.core.tray.right-click";
3312
- TrayApiEvent2["MIDDLE_CLICK"] = "channel::cn.widgetjs.core.tray.middle-click";
3313
- TrayApiEvent2["MOUSE_ENTER"] = "channel::cn.widgetjs.core.tray.mouse-enter";
3314
- TrayApiEvent2["MOUSE_LEAVE"] = "channel::cn.widgetjs.core.tray.mouse-leave";
3315
- return TrayApiEvent2;
3316
- })(TrayApiEvent || {});
3317
-
3318
- // src/api/interface/IUserApi.ts
3319
- var UserApiEvent = /* @__PURE__ */ ((UserApiEvent2) => {
3320
- UserApiEvent2["USER_UPDATED"] = `channel::cn.widgetjs.core.user.updated`;
3321
- UserApiEvent2["SIGNED_OUT"] = `channel::cn.widgetjs.core.user.signed.out`;
3322
- UserApiEvent2["SIGNED_IN"] = `channel::cn.widgetjs.core.user.signed.in`;
3323
- UserApiEvent2["TOKEN_REFRESHED"] = `channel::cn.widgetjs.core.user.token.refreshed`;
3324
- return UserApiEvent2;
3325
- })(UserApiEvent || {});
3326
-
3327
- // src/api/interface/IAiApi.ts
3328
- var AiApiEvent = /* @__PURE__ */ ((AiApiEvent2) => {
3329
- AiApiEvent2["CONFIG_UPDATED"] = `channel::cn.widgetjs.core.ai.config.updated`;
3330
- return AiApiEvent2;
3331
- })(AiApiEvent || {});
3769
+ var WidgetDataApi = new WidgetDataApiImpl();
3332
3770
 
3333
3771
  // src/api/WidgetPackageApi.ts
3334
3772
  var WidgetPackageApiImpl = class extends BaseApi {
@@ -3389,172 +3827,6 @@ var WidgetPackageApiImpl = class extends BaseApi {
3389
3827
  };
3390
3828
  var WidgetPackageApi = new WidgetPackageApiImpl();
3391
3829
 
3392
- // src/api/MenuApi.ts
3393
- var MenuApiEvent = /* @__PURE__ */ ((MenuApiEvent2) => {
3394
- MenuApiEvent2["ITEM_CLICK"] = "event::cn.widgetjs.core.menu.item.click";
3395
- return MenuApiEvent2;
3396
- })(MenuApiEvent || {});
3397
- var MenuApiImpl = class extends BaseApi {
3398
- getChannel() {
3399
- return "channel::cn.widgetjs.core.menu" /* MENU */;
3400
- }
3401
- /**
3402
- * Add items to the context menu
3403
- * @param menuItems The menu items to add
3404
- */
3405
- addContextMenuItem(menuItems) {
3406
- return this.invokeMethod("addContextMenuItem", menuItems);
3407
- }
3408
- /**
3409
- * Add items to the application menu
3410
- * @param menuItems The menu items to add
3411
- */
3412
- addMenuItem(menuItems) {
3413
- return this.invokeMethod("addMenuItem", menuItems);
3414
- }
3415
- /**
3416
- * Show a menu programmatically
3417
- * @param options The options for showing the menu
3418
- */
3419
- showMenu(options) {
3420
- return this.invokeMethod("showMenu", options);
3421
- }
3422
- /**
3423
- * Remove items from the application menu
3424
- * @param menuItemIds The IDs of the menu items to remove
3425
- */
3426
- removeMenuItem(menuItemIds) {
3427
- return this.invokeMethod("removeMenuItem", menuItemIds);
3428
- }
3429
- /**
3430
- * Remove items from the context menu
3431
- * @param menuItemIds The IDs of the menu items to remove
3432
- */
3433
- removeContextMenuItem(menuItemIds) {
3434
- return this.invokeMethod("removeContextMenuItem", menuItemIds);
3435
- }
3436
- };
3437
- var MenuApi = new MenuApiImpl();
3438
-
3439
- // src/api/MouseApi.ts
3440
- var MouseApiImpl = class extends BaseApi {
3441
- getChannel() {
3442
- return "channel::cn.widgetjs.core.mouse" /* MOUSE */;
3443
- }
3444
- removeHotspot() {
3445
- return this.invokeMethod("removeHotspot");
3446
- }
3447
- createHotspot(rect) {
3448
- return this.invokeMethod("createHotspot", rect);
3449
- }
3450
- };
3451
- var MouseApi = new MouseApiImpl();
3452
-
3453
- // src/api/HttpApi.ts
3454
- var HttpApiImpl = class extends BaseApi {
3455
- getChannel() {
3456
- return "channel::cn.widgetjs.core.http" /* HTTP */;
3457
- }
3458
- get(url, params) {
3459
- return this.invokeMethod("get", url, params);
3460
- }
3461
- post(url, data) {
3462
- return this.invokeMethod("post", url, data);
3463
- }
3464
- };
3465
- var HttpApi = new HttpApiImpl();
3466
-
3467
- // src/api/UserApi.ts
3468
- var UserApiImpl = class extends BaseApi {
3469
- async getSession() {
3470
- return await this.invokeMethod("getSession");
3471
- }
3472
- async updateSession(session) {
3473
- await this.invokeMethod("updateSession", session);
3474
- }
3475
- async updateUser(user) {
3476
- await this.invokeMethod("updateUser", user);
3477
- }
3478
- async login(session) {
3479
- await this.invokeMethod("login", session);
3480
- }
3481
- async logout() {
3482
- await this.invokeMethod("logout");
3483
- }
3484
- async getUser() {
3485
- return await this.invokeMethod("getUser");
3486
- }
3487
- getChannel() {
3488
- return "channel::cn.widgetjs.core.user" /* USER */;
3489
- }
3490
- };
3491
- var UserApi = new UserApiImpl();
3492
-
3493
- // src/api/TrayApi.ts
3494
- var TrayApiImpl = class extends BaseApi {
3495
- getChannel() {
3496
- return "channel::cn.widgetjs.core.tray" /* TRAY */;
3497
- }
3498
- setTray(options) {
3499
- return this.invokeMethod("setTray", options);
3500
- }
3501
- removeTray() {
3502
- return this.invokeMethod("removeTray");
3503
- }
3504
- displayBalloon(options) {
3505
- return this.invokeMethod("displayBalloon", options);
3506
- }
3507
- removeBalloon() {
3508
- return this.invokeMethod("removeBalloon");
3509
- }
3510
- setContextMenu(menus) {
3511
- return this.invokeMethod("setContextMenu", menus);
3512
- }
3513
- closeContextMenu() {
3514
- return this.invokeMethod("closeContextMenu");
3515
- }
3516
- popUpContextMenu(menus, position) {
3517
- return this.invokeMethod("popUpContextMenu", menus, position);
3518
- }
3519
- isDestroyed() {
3520
- return this.invokeMethod("isDestroyed");
3521
- }
3522
- getBounds() {
3523
- return this.invokeMethod("getBounds");
3524
- }
3525
- focus() {
3526
- return this.invokeMethod("focus");
3527
- }
3528
- };
3529
- var TrayApi = new TrayApiImpl();
3530
-
3531
- // src/api/AiApi.ts
3532
- var AiApiImpl = class extends BaseApi {
3533
- addConfig(config) {
3534
- return this.invokeMethod("addConfig", config);
3535
- }
3536
- deleteConfig(id) {
3537
- return this.invokeMethod("deleteConfig", id);
3538
- }
3539
- updateConfig(config) {
3540
- return this.invokeMethod("updateConfig", config);
3541
- }
3542
- getConfigList() {
3543
- return this.invokeMethod("getConfigList");
3544
- }
3545
- setConfigList(configs) {
3546
- return this.invokeMethod("setConfigList", configs);
3547
- }
3548
- getConfig(id) {
3549
- return this.invokeMethod("getConfig", id);
3550
- }
3551
- getChannel() {
3552
- return "channel::cn.widgetjs.core.ai" /* AI */;
3553
- }
3554
- };
3555
- var AiApi = new AiApiImpl();
3556
-
3557
- exports.AiApi = AiApi;
3558
3830
  exports.AiApiEvent = AiApiEvent;
3559
3831
  exports.ApiConstants = ApiConstants;
3560
3832
  exports.AppApi = AppApi;
@@ -3564,6 +3836,7 @@ exports.AppConfig = AppConfig;
3564
3836
  exports.AppEvent = AppEvent;
3565
3837
  exports.AppNotification = AppNotification;
3566
3838
  exports.AppReminderNotification = AppReminderNotification;
3839
+ exports.AppTheme = AppTheme;
3567
3840
  exports.BackgroundWidget = BackgroundWidget;
3568
3841
  exports.BaseApi = BaseApi;
3569
3842
  exports.BroadcastApi = BroadcastApi;
@@ -3573,11 +3846,15 @@ exports.BrowserWindowApiEvent = BrowserWindowApiEvent;
3573
3846
  exports.Channel = Channel;
3574
3847
  exports.ClipboardApi = ClipboardApi;
3575
3848
  exports.ClipboardApiEvent = ClipboardApiEvent;
3849
+ exports.DefaultTheme = DefaultTheme;
3850
+ exports.DefaultThemeDark = DefaultThemeDark;
3851
+ exports.DefaultThemeLight = DefaultThemeLight;
3576
3852
  exports.DefaultWidgetTheme = DefaultWidgetTheme;
3577
3853
  exports.DeployMode = DeployMode;
3578
3854
  exports.DeployedPage = DeployedPage;
3579
3855
  exports.DeployedWidget = DeployedWidget;
3580
3856
  exports.DeployedWidgetApi = DeployedWidgetApi;
3857
+ exports.DeployedWidgetApiEvent = DeployedWidgetApiEvent;
3581
3858
  exports.DeviceApi = DeviceApi;
3582
3859
  exports.DialogApi = DialogApi;
3583
3860
  exports.ElectronApi = ElectronApi;