@widget-js/core 24.1.1-beta.1 → 24.1.1-beta.2

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.js CHANGED
@@ -687,7 +687,7 @@ var Page = class {
687
687
  this.maxHeight = options.maxHeight ?? options.height;
688
688
  this.minWidth = options.minWidth ?? options.width;
689
689
  this.minHeight = options.minHeight ?? options.height;
690
- this.backgroundThrottling = options.backgroundThrottling ?? true;
690
+ this.backgroundThrottling = options.backgroundThrottling == void 0 ? true : options.backgroundThrottling;
691
691
  this.packageName = options.packageName;
692
692
  this.singleton = options.singleton ?? false;
693
693
  this.previewImage = options.previewImage;
@@ -795,6 +795,15 @@ var Widget = class extends Page {
795
795
  return this.configPagePath != null && this.configPagePath != "";
796
796
  }
797
797
  };
798
+ var BackgroundWidget = class extends Widget {
799
+ constructor(options) {
800
+ options.supportDeployMode = 65536 /* BACKGROUND */;
801
+ options.backgroundThrottling = false;
802
+ options.width = 1;
803
+ options.height = 1;
804
+ super(options);
805
+ }
806
+ };
798
807
  var WidgetKeyword = /* @__PURE__ */ ((WidgetKeyword2) => {
799
808
  WidgetKeyword2["RECOMMEND"] = "recommend";
800
809
  WidgetKeyword2["TOOLS"] = "tools";
@@ -1243,6 +1252,177 @@ var Gravity = /* @__PURE__ */ ((Gravity2) => {
1243
1252
  return Gravity2;
1244
1253
  })(Gravity || {});
1245
1254
 
1255
+ // src/model/WidgetPackage.ts
1256
+ var WidgetPackage = class {
1257
+ /**
1258
+ * 组件包名,一般为域名倒写,e.g. com.example
1259
+ */
1260
+ name;
1261
+ /**
1262
+ * 组件包版本,可以为空,默认采用package.json里的版本
1263
+ * e.g. 1.0.2
1264
+ */
1265
+ version;
1266
+ /**
1267
+ * 组件包所需的App版本
1268
+ */
1269
+ requiredAppVersion;
1270
+ /**
1271
+ * 组件作者署名
1272
+ */
1273
+ author;
1274
+ development;
1275
+ /**
1276
+ * 组件首页
1277
+ */
1278
+ homepage;
1279
+ /**
1280
+ * 组件描述
1281
+ */
1282
+ title;
1283
+ /**
1284
+ * 组件描述
1285
+ */
1286
+ description;
1287
+ /**
1288
+ * 本地组件入口文件,通常为 index.html
1289
+ */
1290
+ entry;
1291
+ /**
1292
+ * 远程组件包入口文件
1293
+ */
1294
+ remoteEntry;
1295
+ /**
1296
+ * 组件包json文件路径
1297
+ * @example https://rtugeek.gitee.io/hotspot/widget.json
1298
+ */
1299
+ remotePackage;
1300
+ local;
1301
+ remote;
1302
+ /**
1303
+ * 组件包图标
1304
+ */
1305
+ icon;
1306
+ /**
1307
+ * Hash路由模式,默认为true
1308
+ */
1309
+ hash = true;
1310
+ /**
1311
+ * 可能是网络地址,或者本地路径(解压后的文件夹路径),
1312
+ * 网络地址:https://www.bilibili.com
1313
+ * 本地地址:file:///C:/Users/neo/Desktop
1314
+ * 在测试时。地址通常为: http://127.0.0.1:8080
1315
+ */
1316
+ url;
1317
+ widgets = [];
1318
+ pages = [];
1319
+ devOptions;
1320
+ constructor(options) {
1321
+ this.name = options.name;
1322
+ this.development = options.development;
1323
+ this.version = options.version;
1324
+ this.author = options.author;
1325
+ this.homepage = options.homepage;
1326
+ this.title = options.title;
1327
+ this.description = options.description;
1328
+ this.entry = options.entry ?? "index.html";
1329
+ this.remoteEntry = options.remoteEntry;
1330
+ this.requiredAppVersion = options.requiredAppVersion;
1331
+ this.remotePackage = options.remotePackage;
1332
+ this.hash = options.hash;
1333
+ this.url = "";
1334
+ this.icon = options.icon;
1335
+ this.devOptions = options.devOptions;
1336
+ this.remote = options.remote;
1337
+ if (options.widgets) {
1338
+ for (const widget of options.widgets) {
1339
+ this.widgets.push(widget);
1340
+ }
1341
+ }
1342
+ }
1343
+ static parseJSON(json) {
1344
+ const object = JSON.parse(json);
1345
+ return this.parseObject(object);
1346
+ }
1347
+ static parseObject(obj) {
1348
+ const widgetPackage = new WidgetPackage({
1349
+ author: "",
1350
+ description: {
1351
+ "zh-CN": ""
1352
+ },
1353
+ entry: "",
1354
+ hash: false,
1355
+ homepage: "",
1356
+ name: "",
1357
+ title: {
1358
+ "zh-CN": ""
1359
+ },
1360
+ version: ""
1361
+ });
1362
+ Object.assign(widgetPackage, obj);
1363
+ const widgets = [];
1364
+ if (widgetPackage.widgets) {
1365
+ for (const jsonWidget of widgetPackage.widgets) {
1366
+ const widget = new Widget({
1367
+ previewImage: "",
1368
+ path: "",
1369
+ description: { "zh-CN": "" },
1370
+ height: 0,
1371
+ keywords: [],
1372
+ lang: "zh-CN",
1373
+ name: "",
1374
+ title: { "zh-CN": "" },
1375
+ width: 0
1376
+ });
1377
+ Object.assign(widget, jsonWidget);
1378
+ widgets.push(widget);
1379
+ }
1380
+ }
1381
+ widgetPackage.widgets.splice(0, widgetPackage.widgets.length);
1382
+ widgetPackage.widgets.push(...widgets);
1383
+ return widgetPackage;
1384
+ }
1385
+ /**
1386
+ * 获取组件包标题
1387
+ * @param lang 语言环境,不传则获取默认语言
1388
+ */
1389
+ getTitle(lang) {
1390
+ return getTextByLanguageCode(this.title, lang);
1391
+ }
1392
+ /**
1393
+ * 获取组件包描述
1394
+ * @param lang 语言环境,不传则获取默认标题
1395
+ */
1396
+ getDescription(lang) {
1397
+ return getTextByLanguageCode(this.description, lang);
1398
+ }
1399
+ };
1400
+
1401
+ // src/utils/ElectronUtils.ts
1402
+ var ElectronUtils = class {
1403
+ static hasElectronApi() {
1404
+ return this.getAPI() != null;
1405
+ }
1406
+ /**
1407
+ * 获取ElectronAPI
1408
+ * windows api
1409
+ */
1410
+ static getAPI() {
1411
+ if (Reflect.has(window, "electronAPI")) {
1412
+ return window.electronAPI;
1413
+ } else if (Reflect.has(window.parent, "electronAPI")) {
1414
+ return window.parent.electronAPI;
1415
+ }
1416
+ return null;
1417
+ }
1418
+ static async invokeMethod(channel, method, ...args) {
1419
+ return this.getAPI()?.invoke(channel, method, ...args);
1420
+ }
1421
+ static async invoke(channel, ...args) {
1422
+ return this.getAPI()?.invoke(channel, ...args);
1423
+ }
1424
+ };
1425
+
1246
1426
  // src/utils/normalizeUrl.ts
1247
1427
  var DATA_URL_DEFAULT_MIME_TYPE = "text/plain";
1248
1428
  var DATA_URL_DEFAULT_CHARSET = "us-ascii";
@@ -1438,221 +1618,6 @@ function normalizeUrl(urlString, options) {
1438
1618
  return urlString;
1439
1619
  }
1440
1620
 
1441
- // src/utils/WidgetUrlUtils.ts
1442
- var WidgetUrlUtils = class {
1443
- static getWidgetUrl(widgetUrl, widgetPackage, widgetParams) {
1444
- let url = "";
1445
- const arr = [];
1446
- if (widgetUrl.startsWith("http")) {
1447
- url = widgetUrl;
1448
- } else {
1449
- url = widgetPackage.getIndexUrl() + widgetUrl;
1450
- }
1451
- arr.push(url);
1452
- if (url.includes("?")) {
1453
- arr.push("&");
1454
- } else {
1455
- arr.push("?");
1456
- }
1457
- arr.push(widgetParams.toUrlParams().toString());
1458
- return normalizeUrl(arr.join("")).replaceAll("//", "/");
1459
- }
1460
- static getWidgetPackageUrl(url, entry, hash, path = "") {
1461
- const arr = [url];
1462
- if (url.startsWith("http")) {
1463
- if (hash) {
1464
- arr.push("#");
1465
- }
1466
- } else {
1467
- arr.push(`/${entry}`);
1468
- if (hash) {
1469
- arr.push("#");
1470
- }
1471
- }
1472
- arr.push(path);
1473
- return arr.join("");
1474
- }
1475
- };
1476
-
1477
- // src/model/WidgetPackage.ts
1478
- var WidgetPackage = class {
1479
- /**
1480
- * 组件包名,一般为域名倒写,e.g. com.example
1481
- */
1482
- name;
1483
- /**
1484
- * 组件包版本,可以为空,默认采用package.json里的版本
1485
- * e.g. 1.0.2
1486
- */
1487
- version;
1488
- /**
1489
- * 组件作者署名
1490
- */
1491
- author;
1492
- /**
1493
- * 组件首页
1494
- */
1495
- homepage;
1496
- /**
1497
- * 组件描述
1498
- */
1499
- title;
1500
- /**
1501
- * 组件描述
1502
- */
1503
- description;
1504
- /**
1505
- * 本地组件入口文件,通常为 index.html
1506
- */
1507
- entry;
1508
- /**
1509
- * 远程组件包入口文件
1510
- * @deprecated 使用 remote.entry 替代
1511
- */
1512
- remoteEntry;
1513
- /**
1514
- * 组件包json文件路径
1515
- * @example https://rtugeek.gitee.io/hotspot/widget.json
1516
- */
1517
- remotePackage;
1518
- local;
1519
- remote;
1520
- /**
1521
- * 组件包图标
1522
- */
1523
- icon;
1524
- /**
1525
- * Hash路由模式,默认为true
1526
- */
1527
- hash = true;
1528
- /**
1529
- * 可能是网络地址,或者本地路径(解压后的文件夹路径),
1530
- * 网络地址:https://www.bilibili.com
1531
- * 本地地址:file:///C:/Users/neo/Desktop
1532
- * 在测试时。地址通常为: http://127.0.0.1:8080
1533
- */
1534
- url;
1535
- widgets = [];
1536
- pages = [];
1537
- devOptions;
1538
- constructor(options) {
1539
- this.name = options.name;
1540
- this.version = options.version;
1541
- this.author = options.author;
1542
- this.homepage = options.homepage;
1543
- this.title = options.title;
1544
- this.description = options.description;
1545
- this.entry = options.entry ?? "index.html";
1546
- this.remoteEntry = options.remoteEntry;
1547
- this.remotePackage = options.remotePackage;
1548
- this.hash = options.hash;
1549
- this.url = "";
1550
- this.icon = options.icon;
1551
- this.devOptions = options.devOptions;
1552
- this.remote = options.remote;
1553
- if (options.widgets) {
1554
- for (const widget of options.widgets) {
1555
- this.widgets.push(widget);
1556
- }
1557
- }
1558
- }
1559
- static parseJSON(json) {
1560
- const object = JSON.parse(json);
1561
- return this.parseObject(object);
1562
- }
1563
- static parseObject(obj) {
1564
- const widgetPackage = new WidgetPackage({
1565
- author: "",
1566
- description: {
1567
- "zh-CN": ""
1568
- },
1569
- entry: "",
1570
- hash: false,
1571
- homepage: "",
1572
- name: "",
1573
- title: {
1574
- "zh-CN": ""
1575
- },
1576
- version: ""
1577
- });
1578
- Object.assign(widgetPackage, obj);
1579
- const widgets = [];
1580
- if (widgetPackage.widgets) {
1581
- for (const jsonWidget of widgetPackage.widgets) {
1582
- const widget = new Widget({
1583
- previewImage: "",
1584
- path: "",
1585
- description: { "zh-CN": "" },
1586
- height: 0,
1587
- keywords: [],
1588
- lang: "zh-CN",
1589
- name: "",
1590
- title: { "zh-CN": "" },
1591
- width: 0
1592
- });
1593
- Object.assign(widget, jsonWidget);
1594
- widgets.push(widget);
1595
- }
1596
- }
1597
- widgetPackage.widgets.splice(0, widgetPackage.widgets.length);
1598
- widgetPackage.widgets.push(...widgets);
1599
- return widgetPackage;
1600
- }
1601
- /**
1602
- * 获取组件包标题
1603
- * @param lang 语言环境,不传则获取默认语言
1604
- */
1605
- getTitle(lang) {
1606
- return getTextByLanguageCode(this.title, lang);
1607
- }
1608
- /**
1609
- * 获取组件包描述
1610
- * @param lang 语言环境,不传则获取默认标题
1611
- */
1612
- getDescription(lang) {
1613
- return getTextByLanguageCode(this.description, lang);
1614
- }
1615
- /**
1616
- * 获取组件完整路径
1617
- * 如果url是http链接,直接返回链接
1618
- * 如果是本地组件:file://链接,则返回 url+entry,
1619
- * 如果是远程组件:http://链接,则返回 entry,
1620
- * @example file://C:/users/neo/desktop/index.html#
1621
- * @example file://C:/users/neo/desktop/index.html#
1622
- */
1623
- getIndexUrl(hash) {
1624
- return WidgetUrlUtils.getWidgetPackageUrl(this.url, this.entry, hash == null ? this.hash : hash);
1625
- }
1626
- getUrl(path, hash) {
1627
- return WidgetUrlUtils.getWidgetPackageUrl(this.url, this.entry, hash == null ? this.hash : hash, path);
1628
- }
1629
- };
1630
-
1631
- // src/utils/ElectronUtils.ts
1632
- var ElectronUtils = class {
1633
- static hasElectronApi() {
1634
- return this.getAPI() != null;
1635
- }
1636
- /**
1637
- * 获取ElectronAPI
1638
- * windows api
1639
- */
1640
- static getAPI() {
1641
- if (Reflect.has(window, "electronAPI")) {
1642
- return window.electronAPI;
1643
- } else if (Reflect.has(window.parent, "electronAPI")) {
1644
- return window.parent.electronAPI;
1645
- }
1646
- return null;
1647
- }
1648
- static async invokeMethod(channel, method, ...args) {
1649
- return this.getAPI()?.invoke(channel, method, ...args);
1650
- }
1651
- static async invoke(channel, ...args) {
1652
- return this.getAPI()?.invoke(channel, ...args);
1653
- }
1654
- };
1655
-
1656
1621
  // src/grid/GridSystem.ts
1657
1622
  var GridRect = class {
1658
1623
  top;
@@ -1939,43 +1904,6 @@ var WidgetApiImpl = class extends BaseApi {
1939
1904
  async getWidgetPackage(name) {
1940
1905
  return WidgetPackage.parseObject(await this.invokeMethod("getWidgetPackage", name));
1941
1906
  }
1942
- /**
1943
- * 获取组件配置地址
1944
- * @param widgetName
1945
- */
1946
- async getWidgetConfigUrl(widgetName, widgetParams) {
1947
- const widget = await this.getWidget(widgetName);
1948
- if (!widget) {
1949
- return null;
1950
- }
1951
- const configPagePath = widget.configPagePath;
1952
- if (!configPagePath) {
1953
- return null;
1954
- }
1955
- const widgetPackage = await this.getWidgetPackage(widget.packageName);
1956
- if (!widgetPackage) {
1957
- return null;
1958
- }
1959
- return WidgetUrlUtils.getWidgetUrl(configPagePath, widgetPackage, widgetParams);
1960
- }
1961
- async getWidgetUrl(widgetName, widgetParams) {
1962
- const widget = await this.getWidget(widgetName);
1963
- if (!widget) {
1964
- return null;
1965
- }
1966
- const widgetPackage = await this.getWidgetPackage(widget.packageName);
1967
- if (!widgetPackage) {
1968
- return null;
1969
- }
1970
- return WidgetUrlUtils.getWidgetUrl(widget.path, widgetPackage, widgetParams);
1971
- }
1972
- async getWidgetPackageIndexUrl(packageName, hash) {
1973
- const widgetPackage = await this.getWidgetPackage(packageName);
1974
- if (!widgetPackage) {
1975
- return null;
1976
- }
1977
- return widgetPackage.getIndexUrl(hash);
1978
- }
1979
1907
  async getWidgetPackageUrl(packageName) {
1980
1908
  const widgetPackage = await this.getWidgetPackage(packageName);
1981
1909
  if (!widgetPackage) {
@@ -2032,7 +1960,7 @@ var WidgetDataApiImpl = class {
2032
1960
  * @param options
2033
1961
  */
2034
1962
  async save(data, options = { sendBroadcast: true }) {
2035
- const store = this.getStore(data.name);
1963
+ const store = this.getStore(data.name, options.storeName);
2036
1964
  const json = JSON.stringify(data);
2037
1965
  const result = await store.setItem(this.getKey(data.name, data.id), json);
2038
1966
  if (options.sendBroadcast) {
@@ -2117,6 +2045,12 @@ var BrowserWindowApiEvent = /* @__PURE__ */ ((BrowserWindowApiEvent2) => {
2117
2045
  return BrowserWindowApiEvent2;
2118
2046
  })(BrowserWindowApiEvent || {});
2119
2047
  var BrowserWindowApiImpl = class extends BaseApi {
2048
+ setNoActivate() {
2049
+ return this.invokeMethod("setNoActivate");
2050
+ }
2051
+ async isVisible() {
2052
+ return await this.invokeMethod("isVisible");
2053
+ }
2120
2054
  getChannel() {
2121
2055
  return "channel::cn.widgetjs.core.browser_window" /* BROWSER_WINDOW */;
2122
2056
  }
@@ -2449,6 +2383,9 @@ var DeviceApiImpl = class extends BaseApi {
2449
2383
  async getCursorScreenPoint() {
2450
2384
  return this.invokeMethod("getCursorScreenPoint");
2451
2385
  }
2386
+ async sendCtrlV() {
2387
+ return this.invokeMethod("sendCtrlV");
2388
+ }
2452
2389
  /**
2453
2390
  * 判断是否所有按键都已经释放
2454
2391
  */
@@ -2467,6 +2404,9 @@ var ClipboardApiEvent = /* @__PURE__ */ ((ClipboardApiEvent2) => {
2467
2404
  return ClipboardApiEvent2;
2468
2405
  })(ClipboardApiEvent || {});
2469
2406
  var ClipboardApiImpl = class extends BaseApi {
2407
+ writeText(text) {
2408
+ return this.invokeMethod("writeText", text);
2409
+ }
2470
2410
  async getSelectedText() {
2471
2411
  return this.invokeMethod("getSelectedText");
2472
2412
  }
@@ -2731,6 +2671,7 @@ export {
2731
2671
  AppApiConstants,
2732
2672
  AppApiEvent,
2733
2673
  AppNotification,
2674
+ BackgroundWidget,
2734
2675
  BaseApi,
2735
2676
  BroadcastApi,
2736
2677
  BroadcastEvent,
@@ -2774,7 +2715,6 @@ export {
2774
2715
  WidgetKeyword,
2775
2716
  WidgetPackage,
2776
2717
  WidgetParams,
2777
- WidgetUrlUtils,
2778
2718
  getTextByLanguageCode,
2779
2719
  normalizeUrl,
2780
2720
  parseQuery,