dsh-workbench-danmaku 0.3.2 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/client.js CHANGED
@@ -1542,12 +1542,248 @@ var require_layer = __commonJS({
1542
1542
  }
1543
1543
  });
1544
1544
 
1545
+ // packages/addons/lib/config-client.cjs
1546
+ var require_config_client = __commonJS({
1547
+ "packages/addons/lib/config-client.cjs"(exports2, module2) {
1548
+ "use strict";
1549
+ var React = require("react");
1550
+ var BASE = "/workbench/api";
1551
+ var HOST_DOMAIN = "wb-shell";
1552
+ var DEFAULT_TTL = 3e4;
1553
+ var cache = /* @__PURE__ */ new Map();
1554
+ var inflight = /* @__PURE__ */ new Map();
1555
+ var listeners = /* @__PURE__ */ new Map();
1556
+ var events = null;
1557
+ var eventRefs = 0;
1558
+ function mergeValues(fallback, values) {
1559
+ var out = {};
1560
+ var base = fallback && typeof fallback === "object" ? fallback : {};
1561
+ var key;
1562
+ for (key in base) {
1563
+ if (Object.prototype.hasOwnProperty.call(base, key)) out[key] = base[key];
1564
+ }
1565
+ if (values && typeof values === "object") {
1566
+ for (key in values) {
1567
+ if (Object.prototype.hasOwnProperty.call(values, key)) out[key] = values[key];
1568
+ }
1569
+ }
1570
+ return out;
1571
+ }
1572
+ function unwrap(reply) {
1573
+ if (reply && typeof reply === "object" && Object.prototype.hasOwnProperty.call(reply, "result")) return reply.result;
1574
+ return reply;
1575
+ }
1576
+ function fetchHost(action, args) {
1577
+ return fetch(BASE + "/domains/" + HOST_DOMAIN + "/actions/" + encodeURIComponent(action), {
1578
+ method: "POST",
1579
+ headers: { "content-type": "application/json" },
1580
+ body: JSON.stringify(args || {})
1581
+ }).then(function(res) {
1582
+ return res.json().catch(function() {
1583
+ return { ok: false, error: "HTTP " + res.status };
1584
+ });
1585
+ });
1586
+ }
1587
+ function callHost(api, action, args) {
1588
+ if (api && typeof api.call === "function") {
1589
+ return Promise.resolve(api.call(action, args)).catch(function(error) {
1590
+ return { ok: false, error: String(error && error.message || error) };
1591
+ });
1592
+ }
1593
+ if (typeof fetch !== "function") return Promise.reject(new Error("\u5F53\u524D\u73AF\u5883\u6CA1\u6709 fetch\uFF0C\u8BFB\u4E0D\u5230\u5BBF\u4E3B\u914D\u7F6E\u4E2D\u5FC3"));
1594
+ return fetchHost(action, args);
1595
+ }
1596
+ function toSnapshot(body) {
1597
+ var reply = unwrap(body);
1598
+ if (!reply || typeof reply !== "object") throw new Error("\u5BBF\u4E3B\u914D\u7F6E\u4E2D\u5FC3\u6CA1\u6709\u8FD4\u56DE\u5FEB\u7167");
1599
+ if (reply.error) throw new Error(String(reply.error));
1600
+ var declared = reply.declared && typeof reply.declared === "object" ? reply.declared : {};
1601
+ return {
1602
+ values: reply.values && typeof reply.values === "object" ? reply.values : {},
1603
+ items: Array.isArray(declared.items) ? declared.items : [],
1604
+ groups: Array.isArray(declared.groups) ? declared.groups : [],
1605
+ overrides: reply.overrides && typeof reply.overrides === "object" ? reply.overrides : {},
1606
+ schemes: Array.isArray(reply.schemes) ? reply.schemes : [],
1607
+ activeSchemeId: reply.activeSchemeId || null
1608
+ };
1609
+ }
1610
+ function notify(domain, payload) {
1611
+ var set = listeners.get(domain);
1612
+ if (!set) return;
1613
+ set.forEach(function(fn) {
1614
+ try {
1615
+ fn(payload);
1616
+ } catch (error) {
1617
+ }
1618
+ });
1619
+ }
1620
+ function storeSnapshot(domain, snapshot) {
1621
+ cache.set(domain, { at: Date.now(), values: snapshot.values, snapshot });
1622
+ }
1623
+ function loadSnapshot(api, domain) {
1624
+ return callHost(api, "wb.configCenterGet", { domain }).then(toSnapshot);
1625
+ }
1626
+ function readConfig(api, domain, fallback, ttlMs) {
1627
+ var ttl = typeof ttlMs === "number" ? ttlMs : DEFAULT_TTL;
1628
+ var hit = cache.get(domain);
1629
+ if (hit && Date.now() - hit.at < ttl) return Promise.resolve(mergeValues(fallback, hit.values));
1630
+ if (inflight.has(domain)) {
1631
+ return inflight.get(domain).then(
1632
+ function(values) {
1633
+ return mergeValues(fallback, values);
1634
+ },
1635
+ function() {
1636
+ return mergeValues(fallback, hit ? hit.values : null);
1637
+ }
1638
+ );
1639
+ }
1640
+ var pending = loadSnapshot(api, domain).then(function(snapshot) {
1641
+ storeSnapshot(domain, snapshot);
1642
+ notify(domain, { reason: "read", values: snapshot.values });
1643
+ return snapshot.values;
1644
+ });
1645
+ inflight.set(domain, pending);
1646
+ var clear = function() {
1647
+ inflight.delete(domain);
1648
+ };
1649
+ pending.then(clear, clear);
1650
+ return pending.then(
1651
+ function(values) {
1652
+ return mergeValues(fallback, values);
1653
+ },
1654
+ function() {
1655
+ return mergeValues(fallback, hit ? hit.values : null);
1656
+ }
1657
+ );
1658
+ }
1659
+ function writeConfig(api, domain, values) {
1660
+ return callHost(api, "wb.configCenterSet", { domain, values: values || {} }).then(function(body) {
1661
+ var snapshot = toSnapshot(body);
1662
+ storeSnapshot(domain, snapshot);
1663
+ notify(domain, { reason: "set", values: snapshot.values });
1664
+ return snapshot.values;
1665
+ });
1666
+ }
1667
+ function invalidateConfig(domain) {
1668
+ cache.delete(domain);
1669
+ }
1670
+ function subscribeConfigChange(api, domain, cb) {
1671
+ if (typeof window === "undefined" || typeof window.EventSource !== "function") return function() {
1672
+ };
1673
+ var set = listeners.get(domain);
1674
+ if (!set) {
1675
+ set = /* @__PURE__ */ new Set();
1676
+ listeners.set(domain, set);
1677
+ }
1678
+ var handler = typeof cb === "function" ? cb : function() {
1679
+ };
1680
+ set.add(handler);
1681
+ if (!events) {
1682
+ events = new window.EventSource(BASE + "/events");
1683
+ events.addEventListener("domain-event", function(event) {
1684
+ var payload;
1685
+ try {
1686
+ payload = JSON.parse(event.data);
1687
+ } catch (error) {
1688
+ return;
1689
+ }
1690
+ if (!payload || payload.event !== "host.config-changed") return;
1691
+ var data = payload.data || {};
1692
+ var target = data.domain || payload.domainId;
1693
+ if (!target) return;
1694
+ invalidateConfig(target);
1695
+ notify(target, data);
1696
+ });
1697
+ }
1698
+ eventRefs += 1;
1699
+ var closed = false;
1700
+ return function() {
1701
+ if (closed) return;
1702
+ closed = true;
1703
+ set.delete(handler);
1704
+ if (!set.size) listeners.delete(domain);
1705
+ eventRefs -= 1;
1706
+ if (eventRefs <= 0 && events) {
1707
+ try {
1708
+ events.close();
1709
+ } catch (error) {
1710
+ }
1711
+ events = null;
1712
+ eventRefs = 0;
1713
+ }
1714
+ };
1715
+ }
1716
+ function useConfig(api, domain, fallback, ReactImpl) {
1717
+ var R = ReactImpl || React;
1718
+ var initial = {
1719
+ ready: false,
1720
+ values: mergeValues(fallback, null),
1721
+ items: [],
1722
+ groups: [],
1723
+ overrides: {},
1724
+ schemes: [],
1725
+ activeSchemeId: null,
1726
+ error: ""
1727
+ };
1728
+ var state = R.useState(initial);
1729
+ var current = state[0];
1730
+ var set = state[1];
1731
+ R.useEffect(function() {
1732
+ var alive = true;
1733
+ loadSnapshot(api, domain).then(
1734
+ function(snapshot) {
1735
+ if (!alive) return;
1736
+ storeSnapshot(domain, snapshot);
1737
+ set({
1738
+ ready: true,
1739
+ values: mergeValues(fallback, snapshot.values),
1740
+ items: snapshot.items,
1741
+ groups: snapshot.groups,
1742
+ overrides: snapshot.overrides,
1743
+ schemes: snapshot.schemes,
1744
+ activeSchemeId: snapshot.activeSchemeId,
1745
+ error: ""
1746
+ });
1747
+ },
1748
+ function(error) {
1749
+ if (!alive) return;
1750
+ set(function(prev) {
1751
+ return {
1752
+ ready: true,
1753
+ values: prev.values,
1754
+ items: prev.items,
1755
+ groups: prev.groups,
1756
+ overrides: prev.overrides,
1757
+ schemes: prev.schemes,
1758
+ activeSchemeId: prev.activeSchemeId,
1759
+ error: String(error && error.message || error)
1760
+ };
1761
+ });
1762
+ }
1763
+ );
1764
+ return function() {
1765
+ alive = false;
1766
+ };
1767
+ }, [api, domain]);
1768
+ return current;
1769
+ }
1770
+ module2.exports = {
1771
+ useConfig,
1772
+ readConfig,
1773
+ writeConfig,
1774
+ invalidateConfig,
1775
+ subscribeConfigChange
1776
+ };
1777
+ }
1778
+ });
1779
+
1545
1780
  // packages/addons/danmaku/client/overlay/mount.cjs
1546
1781
  var require_mount = __commonJS({
1547
1782
  "packages/addons/danmaku/client/overlay/mount.cjs"(exports2, module2) {
1548
1783
  "use strict";
1549
1784
  var overlayStyle = require_style();
1550
1785
  var layerModule = require_layer();
1786
+ var configClient = require_config_client();
1551
1787
  var DOMAIN = "wb-addon-danmaku";
1552
1788
  var ACTION_PREFIX = "danmaku.";
1553
1789
  var STYLE_ID2 = "wbdm-dm-styles";
@@ -1663,19 +1899,11 @@ var require_mount = __commonJS({
1663
1899
  if (visible) place(config.layer);
1664
1900
  }
1665
1901
  function refresh() {
1666
- return call("configGet", {}).then(function(res) {
1667
- var result = res && res.result ? res.result : res;
1668
- if (res && res.ok && result && result.values) {
1902
+ return configClient.readConfig(null, DOMAIN, DEFAULTS, 0).then(function(values) {
1903
+ if (values && typeof values === "object") {
1669
1904
  retries = 0;
1670
1905
  configLoaded = true;
1671
- apply(result.values);
1672
- return;
1673
- }
1674
- throw new Error(res && res.error || "\u914D\u7F6E\u8BFB\u53D6\u5931\u8D25");
1675
- }).catch(function() {
1676
- if (retries < 5) {
1677
- retries += 1;
1678
- window.setTimeout(refresh, 1500 * retries);
1906
+ apply(values);
1679
1907
  }
1680
1908
  });
1681
1909
  }
@@ -2946,1504 +3174,6 @@ var require_library = __commonJS({
2946
3174
  }
2947
3175
  });
2948
3176
 
2949
- // packages/addons/lib/config-scheme-bar.cjs
2950
- var require_config_scheme_bar = __commonJS({
2951
- "packages/addons/lib/config-scheme-bar.cjs"(exports2, module2) {
2952
- "use strict";
2953
- var React = require("react");
2954
- var h = React.createElement;
2955
- var COPY = {
2956
- zh: {
2957
- title: "\u914D\u7F6E\u65B9\u6848",
2958
- none: "\u4E0D\u4F7F\u7528\u65B9\u6848\uFF08\u63D2\u4EF6\u9ED8\u8BA4\u914D\u7F6E\uFF09",
2959
- create: "\u65B0\u5EFA\u65B9\u6848",
2960
- rename: "\u91CD\u547D\u540D",
2961
- remove: "\u5220\u9664",
2962
- namePlaceholder: "\u65B9\u6848\u540D\u79F0",
2963
- ok: "\u786E\u5B9A",
2964
- cancel: "\u53D6\u6D88",
2965
- current: "\u5F53\u524D\u65B9\u6848",
2966
- defaultHint: "\u672A\u9009\u62E9\u65B9\u6848\u65F6\u4F7F\u7528\u63D2\u4EF6\u9ED8\u8BA4\u914D\u7F6E\uFF1B\u4FEE\u6539\u4EFB\u610F\u8BBE\u7F6E\u4F1A\u81EA\u52A8\u65B0\u5EFA\u300C\u672C\u673A\u914D\u7F6E\u300D\u65B9\u6848\u3002",
2967
- syncedHint: "\u65B9\u6848\u4F1A\u968F\u4E91\u7AEF\u540C\u6B65\u4E0E\u5907\u4EFD\u4E00\u8D77\u8D70\uFF1B\u5F53\u524D\u9009\u4E2D\u54EA\u4E2A\u65B9\u6848\u53EA\u4FDD\u5B58\u5728\u672C\u673A\u3002",
2968
- confirmDelete: "\u5220\u9664\u5F53\u524D\u65B9\u6848\u540E\u4F1A\u56DE\u5230\u63D2\u4EF6\u9ED8\u8BA4\u914D\u7F6E\uFF0C\u786E\u5B9A\u5220\u9664\uFF1F",
2969
- createTitle: "\u65B0\u5EFA\u914D\u7F6E\u65B9\u6848",
2970
- renameTitle: "\u91CD\u547D\u540D\u914D\u7F6E\u65B9\u6848",
2971
- fromCurrent: "\u4ECE\u5F53\u524D\u65B9\u6848\u590D\u5236",
2972
- fromDefault: "\u4ECE\u63D2\u4EF6\u9ED8\u8BA4\u5F00\u59CB"
2973
- },
2974
- en: {
2975
- title: "Config scheme",
2976
- none: "No scheme (plugin defaults)",
2977
- create: "New scheme",
2978
- rename: "Rename",
2979
- remove: "Delete",
2980
- namePlaceholder: "Scheme name",
2981
- ok: "OK",
2982
- cancel: "Cancel",
2983
- current: "Active scheme",
2984
- defaultHint: 'With no scheme selected the plugin defaults apply. Editing any setting creates a local "My config" scheme automatically.',
2985
- syncedHint: "Schemes sync to the cloud and travel with backups; which scheme this device uses stays local.",
2986
- confirmDelete: "Deleting the active scheme returns to plugin defaults. Delete it?",
2987
- createTitle: "New config scheme",
2988
- renameTitle: "Rename config scheme",
2989
- fromCurrent: "Copy active scheme",
2990
- fromDefault: "Start from plugin defaults"
2991
- }
2992
- };
2993
- var styles2 = [
2994
- ".__P__-cfg-schemes{display:flex;flex-direction:column;gap:10px;padding:13px 16px;border:1px solid var(--cfg-line);border-radius:12px;background:var(--cfg-surface)}",
2995
- ".__P__-cfg-schemes-main{display:flex;align-items:center;gap:10px;flex-wrap:wrap}",
2996
- ".__P__-cfg-schemes-label{font-size:12.5px;font-weight:660;white-space:nowrap}",
2997
- ".__P__-cfg-schemes-select{border:1px solid var(--cfg-line);background:var(--dsw-alias-bg-base,transparent);color:inherit;border-radius:9px;padding:7px 11px;font:inherit;font-size:13px;line-height:1.4;outline:none;min-width:190px;max-width:100%}",
2998
- ".__P__-cfg-schemes-select:focus{border-color:var(--dsw-alias-brand-primary,currentColor);box-shadow:0 0 0 3px color-mix(in oklab,var(--dsw-alias-brand-primary,currentColor) 14%,transparent)}",
2999
- ".__P__-cfg-schemes-actions{display:flex;gap:7px;flex-wrap:wrap}",
3000
- ".__P__-cfg-sbtn{appearance:none;border:1px solid var(--cfg-line);background:transparent;color:inherit;border-radius:8px;padding:5px 11px;font:inherit;font-size:12px;line-height:1.5;cursor:pointer;transition:background .12s ease,border-color .12s ease}",
3001
- ".__P__-cfg-sbtn:hover:not(:disabled){background:var(--cfg-hover);border-color:color-mix(in oklab,currentColor 28%,var(--cfg-line))}",
3002
- ".__P__-cfg-sbtn:disabled{opacity:.5;cursor:default}",
3003
- ".__P__-cfg-sbtn.danger{color:var(--dsw-alias-state-error-primary,inherit)}",
3004
- ".__P__-cfg-schemes-form{display:flex;align-items:center;gap:7px;flex-wrap:wrap}",
3005
- ".__P__-cfg-schemes-input{flex:1 1 180px;min-width:120px;border:1px solid var(--cfg-line);background:var(--dsw-alias-bg-base,transparent);color:inherit;border-radius:8px;padding:6px 10px;font:inherit;font-size:13px;outline:none}",
3006
- ".__P__-cfg-schemes-input:focus{border-color:var(--dsw-alias-brand-primary,currentColor)}",
3007
- ".__P__-cfg-schemes-hint{font-size:11.5px;color:var(--cfg-muted);line-height:1.6}"
3008
- ];
3009
- function SchemeBar(props) {
3010
- var lang = props.lang === "en" ? "en" : "zh";
3011
- var c = props.copy ? Object.assign({}, COPY[lang], props.copy) : COPY[lang];
3012
- var prefix = props.prefix || "wb";
3013
- var cls = function(suffix) {
3014
- return "." + prefix + "-cfg-" + suffix;
3015
- };
3016
- var schemes = Array.isArray(props.schemes) ? props.schemes : [];
3017
- var activeId = props.activeId || "";
3018
- var busy = Boolean(props.busy);
3019
- var [editing, setEditing] = React.useState(null);
3020
- var [name, setName] = React.useState("");
3021
- var [from, setFrom] = React.useState("current");
3022
- function begin(mode) {
3023
- var current = schemes.filter(function(s) {
3024
- return s.id === activeId;
3025
- })[0];
3026
- setName(mode === "rename" && current ? current.name : "");
3027
- setFrom(current ? "current" : "default");
3028
- setEditing(mode);
3029
- }
3030
- function submit(event) {
3031
- if (event && event.preventDefault) event.preventDefault();
3032
- var value = String(name || "").trim();
3033
- if (!value || busy) return;
3034
- if (editing === "rename") props.onRename(activeId, value);
3035
- else props.onCreate(value, from);
3036
- setEditing(null);
3037
- setName("");
3038
- }
3039
- function remove() {
3040
- if (typeof window !== "undefined" && window.confirm && !window.confirm(c.confirmDelete)) return;
3041
- props.onDelete(activeId);
3042
- }
3043
- return h(
3044
- "div",
3045
- { className: prefix + "-cfg-schemes" },
3046
- h(
3047
- "div",
3048
- { className: prefix + "-cfg-schemes-main" },
3049
- h("span", { className: prefix + "-cfg-schemes-label" }, c.title),
3050
- h(
3051
- "select",
3052
- {
3053
- className: prefix + "-cfg-schemes-select",
3054
- value: activeId,
3055
- disabled: busy,
3056
- onChange: function(event) {
3057
- props.onActivate(event.target.value || null);
3058
- },
3059
- "aria-label": c.title
3060
- },
3061
- h("option", { value: "" }, c.none),
3062
- schemes.map(function(s) {
3063
- return h("option", { key: s.id, value: s.id }, s.name);
3064
- })
3065
- ),
3066
- h("span", { className: prefix + "-cfg-schemes-hint" }, activeId ? c.current : "")
3067
- ),
3068
- editing ? h(
3069
- "form",
3070
- { className: prefix + "-cfg-schemes-form", onSubmit: submit },
3071
- h("span", { className: prefix + "-cfg-schemes-label" }, editing === "rename" ? c.renameTitle : c.createTitle),
3072
- h("input", {
3073
- className: prefix + "-cfg-schemes-input",
3074
- value: name,
3075
- placeholder: c.namePlaceholder,
3076
- maxLength: 64,
3077
- autoFocus: true,
3078
- disabled: busy,
3079
- onChange: function(event) {
3080
- setName(event.target.value);
3081
- }
3082
- }),
3083
- editing === "create" && activeId ? h(
3084
- "select",
3085
- { className: prefix + "-cfg-schemes-select", value: from, disabled: busy, onChange: function(event) {
3086
- setFrom(event.target.value);
3087
- }, "aria-label": c.createTitle },
3088
- h("option", { value: "current" }, c.fromCurrent),
3089
- h("option", { value: "default" }, c.fromDefault)
3090
- ) : null,
3091
- h("button", { className: prefix + "-cfg-sbtn", type: "submit", disabled: busy || !String(name || "").trim() }, c.ok),
3092
- h("button", { className: prefix + "-cfg-sbtn", type: "button", disabled: busy, onClick: function() {
3093
- setEditing(null);
3094
- } }, c.cancel)
3095
- ) : h(
3096
- "div",
3097
- { className: prefix + "-cfg-schemes-actions" },
3098
- h("button", { className: prefix + "-cfg-sbtn", type: "button", disabled: busy, onClick: function() {
3099
- begin("create");
3100
- } }, c.create),
3101
- activeId ? h("button", { className: prefix + "-cfg-sbtn", type: "button", disabled: busy, onClick: function() {
3102
- begin("rename");
3103
- } }, c.rename) : null,
3104
- activeId ? h("button", { className: prefix + "-cfg-sbtn danger", type: "button", disabled: busy, onClick: remove }, c.remove) : null
3105
- ),
3106
- h("div", { className: prefix + "-cfg-schemes-hint" }, activeId ? c.syncedHint : c.defaultHint)
3107
- );
3108
- }
3109
- module2.exports = { SchemeBar, styles: styles2, COPY };
3110
- }
3111
- });
3112
-
3113
- // packages/addons/danmaku/client/views/config.cjs
3114
- var require_config = __commonJS({
3115
- "packages/addons/danmaku/client/views/config.cjs"(exports2, module2) {
3116
- "use strict";
3117
- var GLYPHS2 = require_icons2().ICONS;
3118
- var React = require("react");
3119
- var h = React.createElement;
3120
- var copy = require_copy();
3121
- var SW = require_switch();
3122
- var NF = require_number_field();
3123
- var SB = require_config_scheme_bar();
3124
- var DOMAIN = "danmaku";
3125
- var SCHEME_CSS = [
3126
- ".wbdm-wrap{--cfg-line:var(--wb-border,var(--dsw-alias-border-l2,color-mix(in oklab,currentColor 16%,transparent)));--cfg-surface:var(--wb-card,var(--wb-surface,var(--dsw-alias-bg-layer-1,transparent)));--cfg-muted:var(--wb-muted,var(--dsw-alias-label-secondary,color-mix(in oklab,currentColor 62%,transparent)));--cfg-hover:var(--dsw-alias-interactive-bg-hover,color-mix(in oklab,currentColor 5%,transparent))}"
3127
- ].concat(SB.styles).join("\n").split("__P__").join("wbdm");
3128
- var ICONS = {
3129
- check: GLYPHS2["check"],
3130
- power: GLYPHS2["power"],
3131
- refresh: GLYPHS2["refresh-cw"],
3132
- monitor: GLYPHS2["monitor"]
3133
- };
3134
- function glyph(Icon2, size) {
3135
- return h(Icon2, { size: size || 14, strokeWidth: 1.8, "aria-hidden": "true" });
3136
- }
3137
- function unwrap(r) {
3138
- return r && r.result !== void 0 ? r.result : r;
3139
- }
3140
- function useConfig(api, fallback) {
3141
- var stateS = React.useState({
3142
- ready: false,
3143
- values: Object.assign({}, fallback || {}),
3144
- items: [],
3145
- groups: [],
3146
- overrides: {},
3147
- warnings: [],
3148
- error: ""
3149
- });
3150
- var state = stateS[0];
3151
- var setState = stateS[1];
3152
- React.useEffect(function() {
3153
- var alive = true;
3154
- Promise.resolve(api.call(DOMAIN + ".configGet")).then(function(r) {
3155
- if (!alive) return;
3156
- if (r && r.ok === false) throw new Error(r && r.error || "load failed");
3157
- var body = unwrap(r);
3158
- if (!body || !body.values) throw new Error("empty config");
3159
- setState({
3160
- ready: true,
3161
- values: Object.assign({}, fallback || {}, body.values || {}),
3162
- items: body.items || [],
3163
- groups: body.groups || [],
3164
- overrides: body.overrides || {},
3165
- warnings: body.warnings || [],
3166
- error: "",
3167
- state: body
3168
- });
3169
- }).catch(function(e) {
3170
- if (!alive) return;
3171
- setState(function(prev) {
3172
- return Object.assign({}, prev, { ready: true, error: String(e && e.message || e) });
3173
- });
3174
- });
3175
- return function() {
3176
- alive = false;
3177
- };
3178
- }, [api]);
3179
- function setValues(next) {
3180
- if (!next || typeof next !== "object") return;
3181
- setState(function(prev) {
3182
- return Object.assign({}, prev, { values: Object.assign({}, prev.values, next) });
3183
- });
3184
- }
3185
- function setBody(body) {
3186
- if (!body) return;
3187
- setState({
3188
- ready: true,
3189
- values: Object.assign({}, fallback || {}, body.values || {}),
3190
- items: body.items || [],
3191
- groups: body.groups || [],
3192
- overrides: body.overrides || {},
3193
- warnings: body.warnings || [],
3194
- error: "",
3195
- state: body
3196
- });
3197
- }
3198
- return Object.assign({}, state, { setValues, setBody });
3199
- }
3200
- function labelOf(item, lang) {
3201
- return lang === "en" ? item.en || item.zh || item.id : item.zh || item.en || item.id;
3202
- }
3203
- function hintOf(item, lang) {
3204
- return lang === "en" ? item.hintEn || "" : item.hintZh || "";
3205
- }
3206
- function useDesktop(api, enabled) {
3207
- var stateS = React.useState({ data: null, error: "" });
3208
- var state = stateS[0];
3209
- var setState = stateS[1];
3210
- React.useEffect(function() {
3211
- if (!enabled) return void 0;
3212
- var alive = true;
3213
- function tick() {
3214
- Promise.resolve(api.call(DOMAIN + ".desktop", { op: "status" })).then(function(r) {
3215
- if (!alive) return;
3216
- if (r && r.ok === false) throw new Error(r && r.error || "status failed");
3217
- setState({ data: unwrap(r), error: "" });
3218
- }).catch(function(e) {
3219
- if (!alive) return;
3220
- setState({ data: null, error: String(e && e.message || e) });
3221
- });
3222
- }
3223
- tick();
3224
- var timer = window.setInterval(tick, 4e3);
3225
- return function() {
3226
- alive = false;
3227
- window.clearInterval(timer);
3228
- };
3229
- }, [api, enabled]);
3230
- return state;
3231
- }
3232
- function statusCell(key, value) {
3233
- return h(
3234
- "div",
3235
- { className: "wbdm-status-cell", key },
3236
- h("div", { className: "wbdm-status-k" }, key),
3237
- h("div", { className: "wbdm-status-v" }, value)
3238
- );
3239
- }
3240
- function DesktopCard(props) {
3241
- var api = props.api;
3242
- var lang = props.lang;
3243
- var C = copy.pick(lang);
3244
- var state = useDesktop(api, true);
3245
- var busyS = React.useState("");
3246
- var busy = busyS[0];
3247
- var setBusy = busyS[1];
3248
- var sayS = React.useState("");
3249
- var say = sayS[0];
3250
- var setSay = sayS[1];
3251
- var data = state.data || {};
3252
- function op(name) {
3253
- setBusy(name);
3254
- Promise.resolve(api.call(DOMAIN + ".desktop", { op: name })).then(function(r) {
3255
- if (r && r.ok === false) throw new Error(r && r.error || "failed");
3256
- setSay("");
3257
- return unwrap(r);
3258
- }).catch(function(e) {
3259
- setSay(String(e && e.message || e));
3260
- }).then(function() {
3261
- setBusy("");
3262
- });
3263
- }
3264
- var phase = data.phase || "stopped";
3265
- var phaseLabel = C.desktopPhase[phase] || phase;
3266
- return h(
3267
- "div",
3268
- { className: "wbdm-card" },
3269
- h(
3270
- "div",
3271
- { className: "wbdm-card-h" },
3272
- h(
3273
- "span",
3274
- { className: "wbdm-card-t" },
3275
- glyph(ICONS.monitor),
3276
- " ",
3277
- C.desktopTitle
3278
- ),
3279
- h("span", { className: "wbdm-card-s" }, C.desktopHint)
3280
- ),
3281
- h(
3282
- "div",
3283
- { className: "wbdm-status" },
3284
- statusCell(lang === "en" ? "State" : "\u72B6\u6001", phaseLabel + (data.suppressed ? " \xB7 " + C.desktopSuppressed : "")),
3285
- statusCell(lang === "en" ? "Protocol" : "\u534F\u8BAE", copy.fmt(C.desktopProtocol, { n: data.protocol || 1 })),
3286
- statusCell(lang === "en" ? "Displays" : "\u5C4F\u5E55", copy.fmt(C.desktopDisplays, { n: data.displays || 0 })),
3287
- statusCell(
3288
- lang === "en" ? "Theme" : "\u4E3B\u9898",
3289
- data.themeSynced ? C.desktopTheme : C.desktopThemeMissing
3290
- )
3291
- ),
3292
- state.error ? h("div", { className: "wbdm-notice error" }, state.error) : null,
3293
- say ? h("div", { className: "wbdm-notice error" }, say) : null,
3294
- h(
3295
- "div",
3296
- { className: "wbdm-status-actions" },
3297
- h(
3298
- "button",
3299
- {
3300
- type: "button",
3301
- className: "wbdm-btn",
3302
- disabled: Boolean(busy),
3303
- onClick: function() {
3304
- op("restart");
3305
- }
3306
- },
3307
- glyph(ICONS.refresh),
3308
- C.desktopRestart
3309
- ),
3310
- h(
3311
- "button",
3312
- {
3313
- type: "button",
3314
- className: "wbdm-btn",
3315
- disabled: Boolean(busy),
3316
- onClick: function() {
3317
- op("stop");
3318
- }
3319
- },
3320
- C.desktopStop
3321
- ),
3322
- h(
3323
- "button",
3324
- {
3325
- type: "button",
3326
- className: "wbdm-btn primary",
3327
- disabled: Boolean(busy),
3328
- onClick: function() {
3329
- op("resume");
3330
- }
3331
- },
3332
- glyph(ICONS.power),
3333
- C.desktopResume
3334
- )
3335
- )
3336
- );
3337
- }
3338
- function ConfigView(props) {
3339
- var api = props.api;
3340
- var lang = props.lang;
3341
- var t = props.t;
3342
- var C = copy.pick(lang);
3343
- var cfg = useConfig(api, {});
3344
- var localS = React.useState({});
3345
- var local = localS[0];
3346
- var setLocal = localS[1];
3347
- var toastS = React.useState("");
3348
- var toast = toastS[0];
3349
- var setToast = toastS[1];
3350
- var schemeBusyS = React.useState(false);
3351
- var schemeBusy = schemeBusyS[0];
3352
- var setSchemeBusy = schemeBusyS[1];
3353
- var schemeNote = lang === "en" ? "Schemes sync to the cloud and travel with backups; which scheme this device uses stays local" : "\u914D\u7F6E\u65B9\u6848\u4F1A\u968F\u4E91\u7AEF\u540C\u6B65\u4E0E\u5907\u4EFD\uFF1B\u5F53\u524D\u9009\u4E2D\u54EA\u4E2A\u65B9\u6848\u53EA\u4FDD\u5B58\u5728\u672C\u673A";
3354
- var seqRef = React.useRef(0);
3355
- var aliveRef = React.useRef(true);
3356
- React.useEffect(function() {
3357
- if (typeof document !== "undefined") {
3358
- var old = document.getElementById("wb-addon-danmaku-config-scheme-css");
3359
- if (old) {
3360
- old.textContent = SCHEME_CSS;
3361
- } else {
3362
- var el = document.createElement("style");
3363
- el.id = "wb-addon-danmaku-config-scheme-css";
3364
- el.textContent = SCHEME_CSS;
3365
- document.head.appendChild(el);
3366
- }
3367
- }
3368
- aliveRef.current = true;
3369
- return function() {
3370
- aliveRef.current = false;
3371
- };
3372
- }, []);
3373
- function values() {
3374
- return Object.assign({}, cfg.values, local);
3375
- }
3376
- function toastOnce(text) {
3377
- setToast(text);
3378
- window.setTimeout(function() {
3379
- if (aliveRef.current) setToast("");
3380
- }, 2200);
3381
- }
3382
- function save(id, value) {
3383
- var seq = ++seqRef.current;
3384
- var patch = {};
3385
- patch[id] = value;
3386
- setLocal(function(prev) {
3387
- return Object.assign({}, prev, patch);
3388
- });
3389
- Promise.resolve(api.call(DOMAIN + ".configSet", { values: patch })).then(function(r) {
3390
- if (r && r.ok === false) throw new Error(r && r.error || C.saveFail);
3391
- var body = unwrap(r) || {};
3392
- if (seq !== seqRef.current) return;
3393
- if (typeof cfg.setValues === "function") cfg.setValues(body.values);
3394
- setLocal({});
3395
- toastOnce(C.saved);
3396
- }).catch(function(e) {
3397
- setLocal(function(prev) {
3398
- var next = Object.assign({}, prev);
3399
- delete next[id];
3400
- return next;
3401
- });
3402
- toastOnce(String(e && e.message || e));
3403
- });
3404
- }
3405
- function schemeCall(action, args) {
3406
- setSchemeBusy(true);
3407
- return Promise.resolve(api.call(DOMAIN + "." + action, args || {})).then(function(r) {
3408
- if (r && r.ok === false) throw new Error(r && r.error || C.saveFail);
3409
- var body = unwrap(r) || {};
3410
- var next = body.state || body;
3411
- if (next && typeof cfg.setBody === "function") {
3412
- cfg.setBody(next);
3413
- seqRef.current += 1;
3414
- setLocal({});
3415
- }
3416
- toastOnce(C.saved);
3417
- }).catch(function(e) {
3418
- toastOnce(String(e && e.message || e));
3419
- }).then(function() {
3420
- setSchemeBusy(false);
3421
- });
3422
- }
3423
- function resetAll() {
3424
- Promise.resolve(api.call(DOMAIN + ".configReset", {})).then(function(r) {
3425
- if (r && r.ok === false) throw new Error(r && r.error || C.saveFail);
3426
- var body = unwrap(r) || {};
3427
- if (typeof cfg.setValues === "function") cfg.setValues(body.values);
3428
- seqRef.current += 1;
3429
- setLocal({});
3430
- toastOnce(C.resetDone);
3431
- }).catch(function(e) {
3432
- toastOnce(String(e && e.message || e));
3433
- });
3434
- }
3435
- function switchControl(item, value) {
3436
- return h(SW.Switch, {
3437
- h,
3438
- checked: value === true,
3439
- title: labelOf(item, lang),
3440
- ariaLabel: labelOf(item, lang),
3441
- onChange: function(next) {
3442
- save(item.id, next);
3443
- }
3444
- });
3445
- }
3446
- function control(item) {
3447
- var value = values()[item.id];
3448
- if (item.type === "bool") return switchControl(item, value);
3449
- if (item.type === "enum") {
3450
- return h(
3451
- "select",
3452
- {
3453
- className: "wbdm-select",
3454
- value: value === void 0 ? "" : String(value),
3455
- "aria-label": labelOf(item, lang),
3456
- onChange: function(e) {
3457
- var hit = (item.values || []).filter(function(option) {
3458
- return String(option.value) === e.target.value;
3459
- })[0];
3460
- save(item.id, hit ? hit.value : e.target.value);
3461
- }
3462
- },
3463
- (item.values || []).map(function(option) {
3464
- return h(
3465
- "option",
3466
- { key: String(option.value), value: String(option.value) },
3467
- lang === "en" ? option.en || option.zh || String(option.value) : option.zh || option.en || String(option.value)
3468
- );
3469
- })
3470
- );
3471
- }
3472
- if (item.type === "int" || item.type === "number") {
3473
- return h(NF.NumberField, {
3474
- h,
3475
- lang,
3476
- value: value === void 0 ? "" : value,
3477
- min: item.min,
3478
- max: item.max,
3479
- integer: item.type === "int",
3480
- ariaLabel: labelOf(item, lang),
3481
- onCommit: function(next) {
3482
- save(item.id, next);
3483
- }
3484
- });
3485
- }
3486
- return h("input", {
3487
- className: "wbdm-input",
3488
- type: "text",
3489
- value: value === void 0 ? "" : String(value),
3490
- "aria-label": labelOf(item, lang),
3491
- onChange: function(e) {
3492
- save(item.id, e.target.value);
3493
- }
3494
- });
3495
- }
3496
- var head = h(
3497
- "div",
3498
- { className: "wbdm-hero" },
3499
- h(
3500
- "div",
3501
- { className: "wbdm-hero-main" },
3502
- h("div", { className: "wbdm-title" }, C.configTitle),
3503
- h("div", { className: "wbdm-sub" }, schemeNote)
3504
- ),
3505
- h(
3506
- "button",
3507
- { type: "button", className: "wbdm-btn ghost", onClick: resetAll, disabled: !cfg.ready },
3508
- C.resetAll
3509
- )
3510
- );
3511
- if (!cfg.ready) return h("div", { className: "wbdm-wrap" }, h("div", { className: "wbdm-empty" }, C.loading));
3512
- if (cfg.error && !cfg.items.length) {
3513
- return h("div", { className: "wbdm-wrap" }, h("div", { className: "wbdm-notice error" }, cfg.error));
3514
- }
3515
- var groups = cfg.groups.length ? cfg.groups : [{ id: "all", zh: "\u5168\u90E8", en: "All" }];
3516
- var sections = groups.map(function(group) {
3517
- var items = cfg.items.filter(function(item) {
3518
- return (item.group || "all") === group.id;
3519
- });
3520
- if (!items.length) return null;
3521
- return h(
3522
- "div",
3523
- { className: "wbdm-card", key: group.id },
3524
- h(
3525
- "div",
3526
- { className: "wbdm-card-h" },
3527
- h("span", { className: "wbdm-card-t" }, lang === "en" ? group.en || group.zh : group.zh || group.en),
3528
- h("span", { className: "wbdm-card-s" }, String(items.length) + (lang === "en" ? " options" : " \u9879"))
3529
- ),
3530
- items.map(function(item) {
3531
- return h(
3532
- "div",
3533
- { className: "wbdm-crow", key: item.id },
3534
- h(
3535
- "div",
3536
- null,
3537
- h("div", { className: "wbdm-clabel" }, labelOf(item, lang)),
3538
- hintOf(item, lang) ? h("div", { className: "wbdm-chint" }, hintOf(item, lang)) : null
3539
- ),
3540
- h("div", { className: "wbdm-ctl" }, control(item))
3541
- );
3542
- })
3543
- );
3544
- });
3545
- return h(
3546
- "div",
3547
- { className: "wbdm-wrap" },
3548
- head,
3549
- h(SB.SchemeBar, {
3550
- key: "schemes",
3551
- lang,
3552
- prefix: "wbdm",
3553
- schemes: cfg.state && cfg.state.schemes || [],
3554
- activeId: cfg.state && cfg.state.scheme ? cfg.state.scheme.id : "",
3555
- busy: schemeBusy,
3556
- onActivate: function(id) {
3557
- schemeCall("configSchemeActivate", { id: id || "" });
3558
- },
3559
- onCreate: function(name, from) {
3560
- schemeCall("configSchemeCreate", { name, from: from || "current" });
3561
- },
3562
- onRename: function(id, name) {
3563
- schemeCall("configSchemeRename", { id, name });
3564
- },
3565
- onDelete: function(id) {
3566
- schemeCall("configSchemeDelete", { id });
3567
- }
3568
- }),
3569
- toast ? h("div", { className: "wbdm-notice ok" }, toast) : null,
3570
- cfg.warnings && cfg.warnings.length ? h("div", { className: "wbdm-notice warn" }, cfg.warnings.join("\uFF1B")) : null,
3571
- sections,
3572
- h(DesktopCard, { api, lang, t })
3573
- );
3574
- }
3575
- module2.exports = ConfigView;
3576
- module2.exports.useConfig = useConfig;
3577
- }
3578
- });
3579
-
3580
- // packages/addons/lib/highlight.cjs
3581
- var require_highlight = __commonJS({
3582
- "packages/addons/lib/highlight.cjs"(exports2, module2) {
3583
- "use strict";
3584
- module2.exports = function(React) {
3585
- var h = React.createElement;
3586
- function sourceOf(keyword) {
3587
- var pattern = keyword.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
3588
- return pattern.replace(/[a-zA-Z]/g, function(letter) {
3589
- return "[" + letter.toLowerCase() + letter.toUpperCase() + "]";
3590
- });
3591
- }
3592
- return function createHighlight(prefix) {
3593
- var className = String(prefix || "wb") + "-hit";
3594
- function hit(rawText, rawKeyword) {
3595
- var text = rawText == null ? "" : String(rawText);
3596
- var keyword = rawKeyword == null ? "" : String(rawKeyword);
3597
- if (!keyword) return text;
3598
- var matcher, match, end = 0, parts = [];
3599
- try {
3600
- matcher = new RegExp(sourceOf(keyword), "g");
3601
- } catch (error) {
3602
- return text;
3603
- }
3604
- while (match = matcher.exec(text)) {
3605
- if (match.index > end) parts.push(text.slice(end, match.index));
3606
- parts.push(h("mark", { className, key: match.index }, match[0]));
3607
- end = match.index + match[0].length;
3608
- if (!match[0]) matcher.lastIndex += 1;
3609
- }
3610
- if (!parts.length) return text;
3611
- if (end < text.length) parts.push(text.slice(end));
3612
- return parts;
3613
- }
3614
- function Highlight(props) {
3615
- return hit(props.text, props.keyword);
3616
- }
3617
- Highlight.hit = hit;
3618
- return Highlight;
3619
- };
3620
- };
3621
- }
3622
- });
3623
-
3624
- // node_modules/.pnpm/lucide-react@1.70.0_react@19.2.0/node_modules/lucide-react/dist/esm/icons/chevron-right.mjs
3625
- var chevron_right_exports = {};
3626
- __export(chevron_right_exports, {
3627
- __iconData: () => __iconData17,
3628
- default: () => ChevronRight
3629
- });
3630
- var __iconData17, ChevronRight;
3631
- var init_chevron_right = __esm({
3632
- "node_modules/.pnpm/lucide-react@1.70.0_react@19.2.0/node_modules/lucide-react/dist/esm/icons/chevron-right.mjs"() {
3633
- init_createLucideIcon();
3634
- __iconData17 = {
3635
- name: "chevron-right",
3636
- size: 24,
3637
- node: [["path", { d: "m9 18 6-6-6-6", key: "mthhwq" }]]
3638
- };
3639
- __iconData17.node;
3640
- ChevronRight = createLucideIcon(__iconData17);
3641
- }
3642
- });
3643
-
3644
- // packages/addons/lib/disclosure-styles.cjs
3645
- var require_disclosure_styles = __commonJS({
3646
- "packages/addons/lib/disclosure-styles.cjs"(exports2, module2) {
3647
- "use strict";
3648
- module2.exports = [
3649
- ".wb-disc{min-width:0;border:0;padding:0;margin:0}",
3650
- // 原生 details/summary 保留键盘与无障碍语义,这里只接管观感:去掉默认三角并铺满整行。
3651
- ".wb-disc>summary{display:flex;align-items:center;gap:6px;cursor:pointer;font-size:12.5px;font-weight:600;line-height:1.6;color:inherit;user-select:none;list-style:none;padding:2px 8px 2px 2px;margin:-2px -8px -2px -2px;border-radius:7px}",
3652
- ".wb-disc>summary::-webkit-details-marker{display:none}",
3653
- '.wb-disc>summary::marker{content:""}',
3654
- ".wb-disc>summary:hover{background:color-mix(in oklab,currentColor 6%,transparent)}",
3655
- ".wb-disc>summary:focus-visible{outline:2px solid var(--wb-accent,var(--dsw-alias-brand-primary,Highlight));outline-offset:2px}",
3656
- ".wb-disc-chev{flex:0 0 auto;width:14px;height:14px;transition:transform 160ms ease}",
3657
- ".wb-disc[open]>summary .wb-disc-chev{transform:rotate(90deg)}",
3658
- ".wb-disc-title{min-width:0;overflow-wrap:anywhere}",
3659
- ".wb-disc-meta{font-weight:400;font-size:12px;color:var(--wb-muted,var(--dsw-alias-label-tertiary,GrayText))}",
3660
- ".wb-disc-body{margin-top:8px;min-width:0;animation:wb-disc-in 160ms ease}",
3661
- "@keyframes wb-disc-in{from{opacity:0;transform:translateY(-2px)}to{opacity:1;transform:none}}",
3662
- "@media(prefers-reduced-motion:reduce){.wb-disc-chev{transition:none}.wb-disc-body{animation:none}}"
3663
- ].join("\n");
3664
- }
3665
- });
3666
-
3667
- // packages/addons/lib/disclosure.cjs
3668
- var require_disclosure = __commonJS({
3669
- "packages/addons/lib/disclosure.cjs"(exports2, module2) {
3670
- "use strict";
3671
- var ChevronRight2 = (init_chevron_right(), __toCommonJS(chevron_right_exports)).default;
3672
- function createDisclosure(React) {
3673
- var h = React.createElement;
3674
- function Disclosure(props) {
3675
- var attrs = Object.assign({ className: ("wb-disc " + (props.className || "")).trim() }, props.attrs || {});
3676
- if (props.open !== void 0) attrs.open = !!props.open;
3677
- else if (props.defaultOpen !== void 0) attrs.open = !!props.defaultOpen;
3678
- if (props.onToggle) attrs.onToggle = props.onToggle;
3679
- return h(
3680
- "details",
3681
- attrs,
3682
- h(
3683
- "summary",
3684
- null,
3685
- h(ChevronRight2, { className: "wb-disc-chev", "aria-hidden": true, focusable: false }),
3686
- h("span", { className: "wb-disc-title" }, props.title),
3687
- props.meta != null && props.meta !== "" ? h("span", { className: "wb-disc-meta" }, props.meta) : null
3688
- ),
3689
- h("div", { className: "wb-disc-body" }, props.children)
3690
- );
3691
- }
3692
- return { Disclosure, css: require_disclosure_styles() };
3693
- }
3694
- module2.exports = { createDisclosure, css: require_disclosure_styles() };
3695
- }
3696
- });
3697
-
3698
- // packages/addons/lib/action-schema-style.cjs
3699
- var require_action_schema_style = __commonJS({
3700
- "packages/addons/lib/action-schema-style.cjs"(exports2, module2) {
3701
- "use strict";
3702
- module2.exports = function(PREFIX, DOMAIN) {
3703
- var P = PREFIX + "-as";
3704
- var hairline = "1px solid color-mix(in oklab,currentColor 8%,transparent)";
3705
- var CSS = [
3706
- "." + P + "{display:flex;flex-direction:column;gap:12px;width:100%;min-width:0;font-size:13px;color:inherit}",
3707
- "." + P + "-head{display:flex;align-items:center;gap:8px;flex-wrap:wrap}",
3708
- "." + P + "-title{font-size:15px;font-weight:660;margin:0}",
3709
- "." + P + "-badge{display:inline-flex;align-items:center;gap:4px;max-width:100%;border:1px solid var(--wb-border,#e3e5e9);border-radius:999px;padding:1px 8px;font-size:11px;color:var(--dsw-alias-label-secondary,currentColor);font-variant-numeric:tabular-nums;overflow-wrap:anywhere}",
3710
- "." + P + "-mono{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:11.5px}",
3711
- "." + P + "-toolbar{display:flex;align-items:center;gap:8px;flex-wrap:wrap}",
3712
- "." + P + "-search{position:relative;flex:1 1 220px;min-width:0;display:flex;align-items:center}",
3713
- "." + P + "-search input{width:100%;border:1px solid var(--wb-border,#e3e5e9);border-radius:8px;background:var(--wb-surface,var(--dsw-alias-bg-layer-1,transparent));color:inherit;font:inherit;padding:6px 10px 6px 30px}",
3714
- "." + P + "-search input:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#4f6ef7);outline-offset:1px}",
3715
- "." + P + "-search .wbi-svg{position:absolute;left:10px;top:50%;transform:translateY(-50%);color:var(--dsw-alias-label-tertiary,inherit)}",
3716
- "." + P + " select{border:1px solid var(--wb-border,#e3e5e9);border-radius:8px;background:var(--wb-surface,var(--dsw-alias-bg-layer-1,transparent));color:inherit;font:inherit;padding:6px 8px;max-width:100%}",
3717
- "." + P + " select:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#4f6ef7);outline-offset:1px}",
3718
- "." + P + "-list{display:flex;flex-direction:column;gap:8px}",
3719
- "." + P + "-card{border:1px solid var(--wb-border,#e3e5e9);border-radius:10px;padding:10px 12px;background:var(--wb-surface,var(--dsw-alias-bg-layer-1,transparent));display:flex;flex-direction:column;gap:8px;min-width:0}",
3720
- "." + P + "-cardhead{display:grid;grid-template-columns:minmax(0,1fr) auto;align-items:start;gap:8px}",
3721
- "." + P + "-cardmeta{display:flex;align-items:center;flex-wrap:wrap;gap:8px;min-width:0;min-height:24px}",
3722
- "." + P + "-cardhead code{font-weight:640;overflow-wrap:anywhere;min-width:0}",
3723
- "." + P + "-hintline{margin:0;color:var(--dsw-alias-label-tertiary,inherit);font-size:11.5px;line-height:1.5}",
3724
- "." + P + "-origins{display:inline-flex;align-items:center;gap:10px;flex-wrap:wrap;justify-content:flex-end;min-width:0}",
3725
- "." + P + "-origins-label{font-size:11px;color:var(--wb-muted);white-space:nowrap}",
3726
- "." + P + "-origin{display:inline-flex;align-items:center;gap:4px;font-size:11.5px;color:var(--wb-muted);cursor:pointer;user-select:none}",
3727
- // 该 action 本身不支持的来源:整项置灰、不可点,示意「不是没开,是开不了」。
3728
- "." + P + "-origin-off{opacity:.55;cursor:not-allowed}",
3729
- "." + P + "-origin input[type=checkbox]{width:13px;height:13px;margin:0;accent-color:var(--wb-accent);cursor:inherit}",
3730
- "." + P + "-origin input[type=checkbox]:focus-visible{outline:2px solid var(--wb-accent);outline-offset:2px}",
3731
- "." + P + "-locked{border-color:var(--wb-warn,#b7791f);color:var(--wb-warn,#b7791f)}",
3732
- "." + P + "-desc{margin:0;color:var(--dsw-alias-label-secondary,inherit);line-height:1.55;font-size:12.5px;overflow-wrap:anywhere}",
3733
- // 搜索命中:用品牌色透明度叠加而不是写死浅色,深浅主题都可读;继承文字颜色、不覆盖 ::selection。
3734
- "." + P + " mark." + P + "-hit{background:color-mix(in oklab,var(--dsw-alias-brand-primary,#4f6ef7) 22%,transparent);color:inherit;border-radius:2px;padding:0;font:inherit;box-decoration-break:clone;-webkit-box-decoration-break:clone}",
3735
- "." + P + "-table{width:100%;border-collapse:collapse;font-size:12px;table-layout:auto}",
3736
- "." + P + "-table th{text-align:left;font-weight:620;font-size:11px;letter-spacing:.4px;text-transform:uppercase;color:var(--dsw-alias-label-tertiary,inherit);padding:4px 8px 4px 0;white-space:nowrap}",
3737
- "." + P + "-table td{padding:4px 8px 4px 0;vertical-align:top;border-top:" + hairline + ";line-height:1.5;overflow-wrap:anywhere}",
3738
- "." + P + "-req{color:var(--dsw-alias-state-error-primary,#d9534f);font-weight:620}",
3739
- "." + P + "-opt{color:var(--dsw-alias-label-tertiary,inherit)}",
3740
- "." + P + "-none{color:var(--dsw-alias-label-tertiary,inherit);font-size:12px}",
3741
- "." + P + "-example{position:relative;display:flex;flex-direction:column;gap:4px;min-width:0}",
3742
- "." + P + "-examplehead{display:flex;align-items:center;justify-content:space-between;gap:8px;flex-wrap:wrap}",
3743
- "." + P + "-pre{margin:0;padding:8px 10px;border-radius:8px;background:var(--dsw-alias-bg-skeleton,#f2f3f5);color:inherit;font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:11.5px;line-height:1.5;overflow:auto;max-height:280px;white-space:pre-wrap;word-break:break-word}",
3744
- "." + P + "-copy{border:1px solid var(--wb-border,#e3e5e9);border-radius:7px;background:transparent;color:inherit;font:inherit;font-size:11.5px;padding:2px 8px;cursor:pointer}",
3745
- "." + P + "-copy:hover{background:var(--dsw-alias-interactive-bg-hover,color-mix(in oklab,currentColor 5%,transparent))}",
3746
- "." + P + "-copy:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#4f6ef7);outline-offset:2px}",
3747
- // 折叠头观感已收口到共享控件 disclosure-styles.cjs(.wb-disc),这里不再重复定义 details>summary。
3748
- "." + P + "-params{min-width:0}",
3749
- "." + P + "-empty{padding:24px;text-align:center;border:1px dashed var(--wb-border,#e3e5e9);border-radius:10px;color:var(--dsw-alias-label-tertiary,inherit)}",
3750
- "." + P + "-error{padding:12px;border:1px solid var(--dsw-alias-state-error-primary,#d9534f);border-radius:10px;color:var(--dsw-alias-state-error-primary,#d9534f);display:flex;gap:10px;align-items:center;flex-wrap:wrap;overflow-wrap:anywhere}",
3751
- "." + P + "-toast{position:sticky;bottom:8px;align-self:flex-start;border-radius:999px;padding:3px 10px;background:var(--dsw-alias-bg-skeleton,#f2f3f5);font-size:11.5px;max-width:100%}",
3752
- // 窄屏:五列参数表压成一列会丢失列名、且 table 布局按最小内容宽度撑破容器,
3753
- // 这里整体改成块级网格:每行 = 名称 / 类型 / 必填 + 约束行 + 说明行,行间用细线分隔。
3754
- "@media(max-width:760px){." + P + "-toolbar{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px;align-items:end}." + P + "-search{grid-column:1/-1}." + P + "-toolbar>label{display:flex;flex-direction:column;align-items:stretch;gap:4px;min-width:0}." + P + "-toolbar select{width:100%;min-width:0}." + P + "-cardhead{grid-template-columns:minmax(0,1fr);row-gap:6px}." + P + "-origins{justify-content:flex-start}." + P + "-table{display:block}." + P + "-table thead{display:none}." + P + "-table tbody{display:block}." + P + '-table tr{display:grid;grid-template-columns:auto minmax(0,1fr) auto;grid-template-areas:"name type need" "extra extra extra" "desc desc desc";column-gap:8px;padding:9px 0;border-top:' + hairline + "}." + P + "-table tr:first-child{border-top:0;padding-top:2px}." + P + "-table tr:last-child{padding-bottom:2px}." + P + "-table td{display:block;border:0;padding:0;min-width:0}." + P + "-table td:empty{display:none}." + P + "-pname{grid-area:name;font-weight:640}." + P + "-ptype{grid-area:type;justify-self:start;align-self:center;color:var(--dsw-alias-label-tertiary,inherit)}." + P + "-pneed{grid-area:need;justify-self:end;align-self:center;font-size:11px;line-height:1.6;white-space:nowrap}." + P + "-pextra{grid-area:extra;margin-top:3px;color:var(--dsw-alias-label-secondary,inherit);line-height:1.55}." + P + "-pdesc{grid-area:desc;margin-top:3px;color:var(--dsw-alias-label-secondary,inherit);line-height:1.55}}",
3755
- // 中等宽度(521–760px)三个筛选项正好排成一行,避免第三项独占一行显得参差。
3756
- "@media(min-width:521px) and (max-width:760px){." + P + "-toolbar{grid-template-columns:repeat(3,minmax(0,1fr))}}",
3757
- "@media(max-width:420px){." + P + "-toolbar{grid-template-columns:minmax(0,1fr) minmax(0,1fr)}." + P + "-card{padding:10px}." + P + "-table tr{padding:8px 0}}"
3758
- ].join("\n") + "\n" + require_disclosure_styles();
3759
- return function injectCss() {
3760
- if (typeof document === "undefined") return;
3761
- var id = "wb-addon-" + DOMAIN + "-actions-css";
3762
- var old = document.getElementById(id);
3763
- if (old) {
3764
- old.textContent = CSS;
3765
- return;
3766
- }
3767
- var style = document.createElement("style");
3768
- style.id = id;
3769
- style.setAttribute("data-wb-addon", "wb-addon-" + DOMAIN);
3770
- style.textContent = CSS;
3771
- document.head.appendChild(style);
3772
- };
3773
- };
3774
- }
3775
- });
3776
-
3777
- // packages/addons/lib/action-schema-view.cjs
3778
- var require_action_schema_view = __commonJS({
3779
- "packages/addons/lib/action-schema-view.cjs"(exports2, module2) {
3780
- "use strict";
3781
- var React = require("react");
3782
- var createHighlight = require_highlight()(React);
3783
- var Disclosure = require_disclosure().createDisclosure(React).Disclosure;
3784
- var h = React.createElement;
3785
- var COPY = {
3786
- zh: {
3787
- title: "Action",
3788
- hint: "\u8FD0\u884C\u65F6\u6CE8\u518C \xB7 \u53EA\u8BFB",
3789
- switchHint: "\u5141\u8BB8\u6765\u6E90\u843D\u672C\u673A\u3001\u5373\u6539\u5373\u751F\u6548\uFF1A\u52FE\u4E0A\u7684\u6765\u6E90\u624D\u80FD\u8C03\u7528\u8BE5 action\uFF0C\u5176\u4F59\u4F1A\u88AB ACTION_ORIGIN_DENIED \u62E6\u4E0B\u3002",
3790
- hostHint: "\u5BBF\u4E3B action \u7684\u5141\u8BB8\u6765\u6E90\uFF1B\u6807\u300C\u6765\u6E90\u56FA\u5B9A\u300D\u7684\u4E0D\u53EF\u4FEE\u6539\u3002",
3791
- originsLabel: "\u5141\u8BB8\u6765\u6E90",
3792
- originUi: "\u754C\u9762",
3793
- originPlugin: "\u63D2\u4EF6",
3794
- originAgent: "agent",
3795
- originSync: "\u540C\u6B65",
3796
- originsSaving: "\u4FDD\u5B58\u4E2D\u2026",
3797
- originsToast: "\u5DF2\u66F4\u65B0\u5141\u8BB8\u6765\u6E90",
3798
- originsFail: "\u66F4\u65B0\u5141\u8BB8\u6765\u6E90\u5931\u8D25",
3799
- originsEmpty: "\u81F3\u5C11\u8981\u4FDD\u7559\u4E00\u4E2A\u6765\u6E90",
3800
- originsUnsupported: "\u8BE5 action \u672C\u8EAB\u4E0D\u652F\u6301\u8FD9\u4E2A\u6765\u6E90",
3801
- originsPinned: "\u6765\u6E90\u56FA\u5B9A",
3802
- originsPinnedHint: "\u8BE5 action \u7684\u5141\u8BB8\u6765\u6E90\u88AB\u56FA\u5B9A\uFF08\u5B89\u5168\u7EA6\u675F\uFF09\uFF0C\u4E0D\u80FD\u4FEE\u6539",
3803
- domain: "\u57DF",
3804
- versionLabel: "\u7248\u672C",
3805
- shell: "\u5BBF\u4E3B",
3806
- count: function(shown, total) {
3807
- return shown + " / " + total + " \u4E2A action";
3808
- },
3809
- search: "\u641C\u7D22\u540D\u79F0\u3001\u63CF\u8FF0\u3001\u53C2\u6570\uFF08\u547D\u4E2D\u5904\u9AD8\u4EAE\uFF09",
3810
- filterReq: "\u5FC5\u586B\u7B5B\u9009",
3811
- all: "\u5168\u90E8",
3812
- onlyRequired: "\u542B\u5FC5\u586B\u9879",
3813
- onlyOptional: "\u65E0\u5FC5\u586B\u9879",
3814
- filterType: "\u53C2\u6570\u7C7B\u578B",
3815
- allTypes: "\u5168\u90E8\u7C7B\u578B",
3816
- filterOrigin: "\u5141\u8BB8\u6765\u6E90",
3817
- allOrigins: "\u5168\u90E8\u6765\u6E90",
3818
- colName: "\u53C2\u6570",
3819
- colType: "\u7C7B\u578B",
3820
- colReq: "\u5FC5\u586B",
3821
- colExtra: "\u9ED8\u8BA4 / \u679A\u4E3E / \u7EA6\u675F",
3822
- colDesc: "\u8BF4\u660E",
3823
- required: "\u5FC5\u586B",
3824
- optional: "\u53EF\u9009",
3825
- noParams: "\u65E0\u53C2\u6570",
3826
- paramCount: function(n) {
3827
- return n + " \u4E2A\u53C2\u6570";
3828
- },
3829
- params: "\u53C2\u6570",
3830
- requiredCount: function(n) {
3831
- return "\u5FC5\u586B " + n;
3832
- },
3833
- examples: "\u793A\u4F8B",
3834
- noExamples: "\u65E0\u793A\u4F8B",
3835
- copy: "\u590D\u5236",
3836
- copied: "\u5DF2\u590D\u5236",
3837
- raw: "\u539F\u59CB JSON Schema",
3838
- loading: "\u8F7D\u5165\u4E2D\u2026",
3839
- loadFail: "\u8BFB\u53D6 action schema \u5931\u8D25",
3840
- retry: "\u91CD\u8BD5",
3841
- empty: "\u6CA1\u6709\u5339\u914D\u7684 action",
3842
- emptyRegistry: "\u8BE5\u57DF\u6CA1\u6709\u6CE8\u518C action",
3843
- envelope: "\u9ED8\u8BA4",
3844
- enumLabel: "\u679A\u4E3E",
3845
- range: "\u8303\u56F4",
3846
- length: "\u957F\u5EA6",
3847
- pattern: "\u6B63\u5219",
3848
- format: "\u683C\u5F0F",
3849
- items: "\u5143\u7D20\u6570"
3850
- },
3851
- en: {
3852
- title: "Actions",
3853
- hint: "runtime registry \xB7 read-only",
3854
- switchHint: "Allowed origins are stored locally and apply immediately: only checked origins may call the action; others get ACTION_ORIGIN_DENIED.",
3855
- hostHint: "Allowed origins for host actions; items marked pinned cannot be changed.",
3856
- originsLabel: "Origins",
3857
- originUi: "UI",
3858
- originPlugin: "Plugin",
3859
- originAgent: "Agent",
3860
- originSync: "Sync",
3861
- originsSaving: "Saving\u2026",
3862
- originsToast: "Allowed origins updated",
3863
- originsFail: "Failed to update allowed origins",
3864
- originsEmpty: "Keep at least one origin",
3865
- originsUnsupported: "This action does not support this origin",
3866
- originsPinned: "Pinned",
3867
- originsPinnedHint: "Allowed origins are pinned for this action (security constraint) and cannot be changed",
3868
- originsDefaultOn: "Allowed by default",
3869
- originsDefaultOff: "Off by default, can be enabled",
3870
- domain: "Domain",
3871
- versionLabel: "Version",
3872
- shell: "Host",
3873
- count: function(shown, total) {
3874
- return shown + " / " + total + " actions";
3875
- },
3876
- search: "Search name, description, params (matches highlighted)",
3877
- filterReq: "Required",
3878
- all: "All",
3879
- onlyRequired: "Has required",
3880
- onlyOptional: "No required",
3881
- filterType: "Param type",
3882
- allTypes: "All types",
3883
- filterOrigin: "Origins",
3884
- allOrigins: "All origins",
3885
- colName: "Param",
3886
- colType: "Type",
3887
- colReq: "Required",
3888
- colExtra: "Default / enum / constraints",
3889
- colDesc: "Description",
3890
- required: "required",
3891
- optional: "optional",
3892
- noParams: "No parameters",
3893
- paramCount: function(n) {
3894
- return n + " params";
3895
- },
3896
- params: "Parameters",
3897
- requiredCount: function(n) {
3898
- return n + " required";
3899
- },
3900
- examples: "Examples",
3901
- noExamples: "No examples",
3902
- copy: "Copy",
3903
- copied: "Copied",
3904
- raw: "Raw JSON Schema",
3905
- loading: "Loading\u2026",
3906
- loadFail: "Failed to read action schema",
3907
- retry: "Retry",
3908
- empty: "No matching action",
3909
- emptyRegistry: "This domain has no registered action",
3910
- envelope: "Default",
3911
- enumLabel: "Enum",
3912
- range: "Range",
3913
- length: "Length",
3914
- pattern: "Pattern",
3915
- format: "Format",
3916
- items: "Items"
3917
- }
3918
- };
3919
- function typeLabel(schema) {
3920
- if (!schema || typeof schema !== "object") return "";
3921
- if (Array.isArray(schema.type)) return schema.type.join(" | ");
3922
- if (typeof schema.type === "string") {
3923
- if (schema.type === "array" && schema.items) {
3924
- var inner = typeLabel(schema.items);
3925
- return inner ? inner + "[]" : "array";
3926
- }
3927
- return schema.type;
3928
- }
3929
- if (Array.isArray(schema.oneOf)) return schema.oneOf.map(typeLabel).filter(Boolean).join(" | ");
3930
- if (Array.isArray(schema.anyOf)) return schema.anyOf.map(typeLabel).filter(Boolean).join(" | ");
3931
- return "";
3932
- }
3933
- function typeNames(schema) {
3934
- var label = typeLabel(schema);
3935
- if (!label) return [];
3936
- return label.split("|").map(function(x) {
3937
- return x.trim().replace(/\[\]$/, "");
3938
- }).filter(Boolean);
3939
- }
3940
- function scalar(value) {
3941
- if (typeof value === "string") return JSON.stringify(value);
3942
- return String(value);
3943
- }
3944
- function extraText(schema, t) {
3945
- if (!schema || typeof schema !== "object") return "";
3946
- var parts = [];
3947
- if (Object.prototype.hasOwnProperty.call(schema, "default")) {
3948
- parts.push(t.envelope + " " + scalar(schema.default));
3949
- }
3950
- if (Array.isArray(schema.enum)) {
3951
- parts.push(t.enumLabel + " " + schema.enum.map(scalar).join(" / "));
3952
- }
3953
- if (typeof schema.minimum === "number" || typeof schema.maximum === "number") {
3954
- var lo = typeof schema.minimum === "number" ? schema.minimum : null;
3955
- var hi = typeof schema.maximum === "number" ? schema.maximum : null;
3956
- if (lo !== null && hi !== null) parts.push(t.range + " \u2265" + lo + " \u4E14 \u2264" + hi);
3957
- else if (lo !== null) parts.push(t.range + " \u2265" + lo);
3958
- else parts.push(t.range + " \u2264" + hi);
3959
- }
3960
- if (typeof schema.minLength === "number" || typeof schema.maxLength === "number") {
3961
- parts.push(t.length + " " + (schema.minLength ?? 0) + "\u2013" + (schema.maxLength ?? "\u221E"));
3962
- }
3963
- if (typeof schema.minItems === "number" || typeof schema.maxItems === "number") {
3964
- parts.push(t.items + " " + (schema.minItems ?? 0) + "\u2013" + (schema.maxItems ?? "\u221E"));
3965
- }
3966
- if (typeof schema.pattern === "string") parts.push(t.pattern + " " + schema.pattern);
3967
- if (typeof schema.format === "string") parts.push(t.format + " " + schema.format);
3968
- return parts.join(" \xB7 ");
3969
- }
3970
- function paramRows(action) {
3971
- var input = action && action.input && typeof action.input === "object" ? action.input : {};
3972
- var props = input.properties && typeof input.properties === "object" ? input.properties : {};
3973
- var required = Array.isArray(input.required) ? input.required : [];
3974
- return Object.keys(props).map(function(key) {
3975
- var schema = props[key] && typeof props[key] === "object" ? props[key] : {};
3976
- return {
3977
- name: key,
3978
- schema,
3979
- type: typeLabel(schema),
3980
- types: typeNames(schema),
3981
- required: required.indexOf(key) >= 0,
3982
- description: typeof schema.description === "string" ? schema.description : ""
3983
- };
3984
- });
3985
- }
3986
- module2.exports = function createActionSchemaView(options) {
3987
- var raw = String(options.domain || "");
3988
- var SOURCE = options.source === "actions.list" ? "actions.list" : "actionSchema";
3989
- var DOMAIN = SOURCE === "actions.list" ? raw : raw.indexOf("wb-addon-") === 0 ? raw : "wb-addon-" + raw;
3990
- var LIST_DOMAIN = options.listDomain ? String(options.listDomain) : DOMAIN;
3991
- var prefix = options.prefix;
3992
- var P = prefix + "-as";
3993
- var Icon2 = options.Icon || null;
3994
- var injectCss = require_action_schema_style()(prefix, DOMAIN);
3995
- var Highlight = createHighlight(P);
3996
- function icon(name, size) {
3997
- return Icon2 ? h(Icon2, { name, size: size || 14 }) : null;
3998
- }
3999
- function plainCopy(text) {
4000
- if (typeof document === "undefined") return;
4001
- var area = document.createElement("textarea");
4002
- area.value = text;
4003
- area.setAttribute("readonly", "readonly");
4004
- area.style.position = "fixed";
4005
- area.style.opacity = "0";
4006
- document.body.appendChild(area);
4007
- area.select();
4008
- try {
4009
- document.execCommand("copy");
4010
- } catch (e) {
4011
- }
4012
- document.body.removeChild(area);
4013
- }
4014
- function ActionSchemaView(props) {
4015
- var lang = props.lang === "en" ? "en" : "zh";
4016
- var t = COPY[lang];
4017
- var api = props.api;
4018
- var snapState = React.useState(null);
4019
- var snap = snapState[0], setSnap = snapState[1];
4020
- var errState = React.useState("");
4021
- var err = errState[0], setErr = errState[1];
4022
- var loadingState = React.useState(true);
4023
- var loading = loadingState[0], setLoading = loadingState[1];
4024
- var reloadState = React.useState(0);
4025
- var reload = reloadState[0], setReload = reloadState[1];
4026
- var queryState = React.useState("");
4027
- var query = queryState[0], setQuery = queryState[1];
4028
- var reqState = React.useState("all");
4029
- var reqMode = reqState[0], setReqMode = reqState[1];
4030
- var typeState = React.useState("");
4031
- var typePick = typeState[0], setTypePick = typeState[1];
4032
- var originFilterState = React.useState("");
4033
- var originPick = originFilterState[0], setOriginPick = originFilterState[1];
4034
- var toastState = React.useState("");
4035
- var toast = toastState[0], setToast = toastState[1];
4036
- var savingState = React.useState("");
4037
- var saving = savingState[0], setSaving = savingState[1];
4038
- var foldsState = React.useState({});
4039
- var folds = foldsState[0], setFolds = foldsState[1];
4040
- React.useEffect(function() {
4041
- injectCss();
4042
- }, []);
4043
- React.useEffect(function() {
4044
- var alive = true;
4045
- setLoading(true);
4046
- setErr("");
4047
- var pending;
4048
- var actionName = SOURCE === "actions.list" ? "actions.list" : DOMAIN.replace(/^wb-addon-/, "") + ".actionSchema";
4049
- var callArgs = SOURCE === "actions.list" ? { detail: true, domain: LIST_DOMAIN } : void 0;
4050
- if (api && typeof api.call === "function") {
4051
- pending = Promise.resolve(api.call(actionName, callArgs)).then(function(r) {
4052
- if (r && r.ok === false) return r;
4053
- return r && r.result || r;
4054
- });
4055
- } else {
4056
- pending = Promise.reject(new Error("no call api"));
4057
- }
4058
- Promise.resolve(pending).then(function(r) {
4059
- if (!alive) return;
4060
- if (!r || r.ok === false) {
4061
- setSnap(null);
4062
- setErr(String(r && (r.error || r.text) || t.loadFail));
4063
- } else {
4064
- setSnap(r);
4065
- }
4066
- setLoading(false);
4067
- }, function(e) {
4068
- if (!alive) return;
4069
- setSnap(null);
4070
- setErr(String(e && e.message || e || t.loadFail));
4071
- setLoading(false);
4072
- });
4073
- return function() {
4074
- alive = false;
4075
- };
4076
- }, [reload]);
4077
- function copy(text) {
4078
- var done = function() {
4079
- setToast(t.copied);
4080
- };
4081
- if (typeof navigator !== "undefined" && navigator.clipboard && typeof navigator.clipboard.writeText === "function") {
4082
- navigator.clipboard.writeText(text).then(done, function() {
4083
- plainCopy(text);
4084
- done();
4085
- });
4086
- return;
4087
- }
4088
- plainCopy(text);
4089
- done();
4090
- }
4091
- var ORIGINS = ["ui", "plugin", "agent", "sync"];
4092
- var originText = { ui: t.originUi, plugin: t.originPlugin, agent: t.originAgent, sync: t.originSync };
4093
- function setOrigins(action, origin) {
4094
- var name = action.name;
4095
- var current = Array.isArray(action.origins) ? action.origins.slice() : [];
4096
- var index = current.indexOf(origin);
4097
- var next = index >= 0 ? current.filter(function(o) {
4098
- return o !== origin;
4099
- }) : current.concat([origin]);
4100
- if (next.length === 0) {
4101
- setToast(t.originsEmpty);
4102
- return;
4103
- }
4104
- next = ORIGINS.filter(function(o) {
4105
- return next.indexOf(o) >= 0;
4106
- });
4107
- setSaving(name);
4108
- setToast("");
4109
- var fail = function(e) {
4110
- setSaving("");
4111
- setToast(t.originsFail + "\uFF1A" + String(e && e.message || e || ""));
4112
- };
4113
- var done = function(r) {
4114
- setSaving("");
4115
- var payload = r && typeof r === "object" && Object.prototype.hasOwnProperty.call(r, "result") ? r.result : r;
4116
- if (r && r.ok === false) {
4117
- setToast(t.originsFail + "\uFF1A" + String(r.error || r.text || ""));
4118
- return;
4119
- }
4120
- var value = payload && Array.isArray(payload.origins) ? payload.origins : next;
4121
- var source = payload && typeof payload.source === "string" ? payload.source : action.originsSource;
4122
- setSnap(function(prev) {
4123
- if (!prev || !Array.isArray(prev.actions)) return prev;
4124
- return Object.assign({}, prev, {
4125
- actions: prev.actions.map(function(a) {
4126
- if (!a || a.name !== name) return a;
4127
- return Object.assign({}, a, { origins: value, originsSource: source });
4128
- })
4129
- });
4130
- });
4131
- setToast(t.originsToast);
4132
- };
4133
- if (!api || typeof api.call !== "function") {
4134
- fail(new Error("no call api"));
4135
- return;
4136
- }
4137
- Promise.resolve(api.call("actions.setActionOrigins", { action: name, origins: next })).then(done, fail);
4138
- }
4139
- function paramsOpen(action) {
4140
- if (Object.prototype.hasOwnProperty.call(folds, action.name)) return folds[action.name] === true;
4141
- return Boolean(String(query || "").trim()) || reqMode !== "all" || Boolean(typePick);
4142
- }
4143
- function resetFolds() {
4144
- setFolds(function(prev) {
4145
- return Object.keys(prev).length ? {} : prev;
4146
- });
4147
- }
4148
- var all = snap && Array.isArray(snap.actions) ? snap.actions.filter(function(a) {
4149
- return a && a.domain === DOMAIN;
4150
- }) : [];
4151
- var info = snap && Array.isArray(snap.domains) ? snap.domains.filter(function(d) {
4152
- return d && d.id === DOMAIN;
4153
- })[0] || null : null;
4154
- var typeOptions = [];
4155
- all.forEach(function(a) {
4156
- paramRows(a).forEach(function(row) {
4157
- row.types.forEach(function(name) {
4158
- if (typeOptions.indexOf(name) < 0) typeOptions.push(name);
4159
- });
4160
- });
4161
- });
4162
- typeOptions.sort();
4163
- var kw = String(query || "").trim();
4164
- var q = kw.toLowerCase();
4165
- var visible = all.filter(function(a) {
4166
- var rows = paramRows(a);
4167
- if (q) {
4168
- var hay = [a.name || "", a.description || ""].concat(rows.map(function(row) {
4169
- return row.name + " " + row.type + " " + row.description;
4170
- })).join(" ").toLowerCase();
4171
- if (hay.indexOf(q) < 0) return false;
4172
- }
4173
- var hasRequired = rows.some(function(row) {
4174
- return row.required;
4175
- });
4176
- if (reqMode === "required" && !hasRequired) return false;
4177
- if (reqMode === "optional" && hasRequired) return false;
4178
- if (typePick && !rows.some(function(row) {
4179
- return row.types.indexOf(typePick) >= 0;
4180
- })) return false;
4181
- if (originPick && (!Array.isArray(a.origins) || a.origins.indexOf(originPick) < 0)) return false;
4182
- return true;
4183
- });
4184
- function paramRow(row) {
4185
- var extra = extraText(row.schema, t);
4186
- return h(
4187
- "tr",
4188
- { key: row.name },
4189
- h("td", { className: P + "-mono " + P + "-pname" }, Highlight.hit(row.name, kw)),
4190
- h("td", { className: P + "-mono " + P + "-ptype" }, Highlight.hit(row.type, kw)),
4191
- h(
4192
- "td",
4193
- { className: row.required ? P + "-req " + P + "-pneed" : P + "-opt " + P + "-pneed" },
4194
- row.required ? t.required : t.optional
4195
- ),
4196
- // extra(默认 / 枚举 / 约束)不在过滤 haystack 里,因此也不高亮,保持「显示即命中」口径。
4197
- h("td", { className: P + "-mono " + P + "-pextra" }, extra),
4198
- h("td", { className: P + "-pdesc" }, Highlight.hit(row.description, kw))
4199
- );
4200
- }
4201
- function originsChips(action) {
4202
- if (!Array.isArray(action.origins)) return null;
4203
- if (action.originsSource === "invalid") {
4204
- return h("span", { className: P + "-badge " + P + "-locked", title: t.originsPinnedHint, "data-origins-invalid": action.name }, t.originsPinned);
4205
- }
4206
- var busy = saving === action.name;
4207
- var pinned = action.name === "actions.setActionOrigins";
4208
- var supported = Array.isArray(action.originsDeclared) ? action.originsDeclared : action.origins;
4209
- return h(
4210
- "div",
4211
- { className: P + "-origins", "data-origins-row": action.name },
4212
- h("span", { className: P + "-origins-label" }, t.originsLabel),
4213
- ORIGINS.map(function(origin) {
4214
- var on = action.origins.indexOf(origin) >= 0;
4215
- var allowed = supported.indexOf(origin) >= 0;
4216
- var preset = Array.isArray(action.originsDefault) ? action.originsDefault : supported;
4217
- var byDefault = preset.indexOf(origin) >= 0;
4218
- return h(
4219
- "label",
4220
- {
4221
- key: origin,
4222
- className: P + "-origin" + (allowed ? "" : " " + P + "-origin-off"),
4223
- title: pinned ? t.originsPinnedHint : !allowed ? t.originsUnsupported : originText[origin] + " \xB7 " + action.name + " \xB7 " + (byDefault ? t.originsDefaultOn : t.originsDefaultOff)
4224
- },
4225
- h("input", {
4226
- type: "checkbox",
4227
- checked: on,
4228
- disabled: busy || pinned || !allowed,
4229
- "data-origin": origin,
4230
- "data-origin-row": action.name,
4231
- "data-origin-supported": allowed ? "1" : "0",
4232
- onChange: function() {
4233
- setOrigins(action, origin);
4234
- }
4235
- }),
4236
- h("span", null, originText[origin])
4237
- );
4238
- }),
4239
- busy ? h("span", { className: P + "-origins-label" }, t.originsSaving) : null
4240
- );
4241
- }
4242
- function card(action) {
4243
- var rows = paramRows(action);
4244
- var required = rows.filter(function(row) {
4245
- return row.required;
4246
- }).length;
4247
- var open = paramsOpen(action);
4248
- var examples = Array.isArray(action.examples) ? action.examples : [];
4249
- return h(
4250
- "div",
4251
- { className: P + "-card", key: action.name },
4252
- h(
4253
- "div",
4254
- { className: P + "-cardhead" },
4255
- h(
4256
- "div",
4257
- { className: P + "-cardmeta" },
4258
- h("code", { className: P + "-mono" }, Highlight.hit(action.name, kw)),
4259
- h("span", { className: P + "-badge" }, rows.length ? t.paramCount(rows.length) : t.noParams),
4260
- rows.some(function(row) {
4261
- return row.required;
4262
- }) ? h("span", { className: P + "-badge " + P + "-req" }, t.required) : null
4263
- ),
4264
- originsChips(action)
4265
- ),
4266
- action.description ? h("p", { className: P + "-desc" }, Highlight.hit(action.description, kw)) : null,
4267
- rows.length ? h(
4268
- Disclosure,
4269
- {
4270
- className: P + "-params",
4271
- title: t.params,
4272
- meta: required ? t.requiredCount(required) : "",
4273
- attrs: { "data-params-fold": action.name },
4274
- open,
4275
- // 原生 details 自带键盘与无障碍语义,这里只记下用户的开合;
4276
- // 筛选变化引起的程序性开合也会触发 toggle,记下的值与当次默认一致,随后由 resetFolds 清掉。
4277
- onToggle: function(e) {
4278
- var next = !!(e && e.currentTarget && e.currentTarget.open);
4279
- setFolds(function(prev) {
4280
- if (prev[action.name] === next) return prev;
4281
- var out = Object.assign({}, prev);
4282
- out[action.name] = next;
4283
- return out;
4284
- });
4285
- }
4286
- },
4287
- h(
4288
- "table",
4289
- { className: P + "-table" },
4290
- h("thead", null, h(
4291
- "tr",
4292
- null,
4293
- h("th", null, t.colName),
4294
- h("th", null, t.colType),
4295
- h("th", null, t.colReq),
4296
- h("th", null, t.colExtra),
4297
- h("th", null, t.colDesc)
4298
- )),
4299
- h("tbody", null, rows.map(paramRow))
4300
- )
4301
- ) : h("div", { className: P + "-none" }, t.noParams),
4302
- h(
4303
- "div",
4304
- { className: P + "-example" },
4305
- h(
4306
- "div",
4307
- { className: P + "-examplehead" },
4308
- h("span", { className: P + "-none" }, t.examples),
4309
- examples.length ? h("button", {
4310
- type: "button",
4311
- className: P + "-copy",
4312
- "data-copy-example": action.name,
4313
- onClick: function() {
4314
- copy(JSON.stringify(examples.length === 1 ? examples[0] : examples, null, 2));
4315
- }
4316
- }, t.copy) : null
4317
- ),
4318
- examples.length ? examples.map(function(example, index) {
4319
- return h("pre", { className: P + "-pre", key: index }, JSON.stringify(example, null, 2));
4320
- }) : h("div", { className: P + "-none" }, t.noExamples)
4321
- ),
4322
- h(
4323
- Disclosure,
4324
- { title: t.raw },
4325
- h("pre", { className: P + "-pre" }, JSON.stringify(action.input || {}, null, 2))
4326
- )
4327
- );
4328
- }
4329
- var body;
4330
- if (loading) {
4331
- body = h("div", { className: P + "-empty", role: "status" }, t.loading);
4332
- } else if (err) {
4333
- body = h(
4334
- "div",
4335
- { className: P + "-error", role: "alert" },
4336
- h("span", null, t.loadFail + "\uFF1A" + err),
4337
- h("button", { type: "button", className: P + "-copy", onClick: function() {
4338
- setReload(reload + 1);
4339
- } }, t.retry)
4340
- );
4341
- } else if (!all.length) {
4342
- body = h("div", { className: P + "-empty" }, t.emptyRegistry);
4343
- } else if (!visible.length) {
4344
- body = h("div", { className: P + "-empty" }, t.empty);
4345
- } else {
4346
- body = h("div", { className: P + "-list" }, visible.map(card));
4347
- }
4348
- return h(
4349
- "div",
4350
- { className: P },
4351
- h(
4352
- "div",
4353
- { className: P + "-head" },
4354
- h("h3", { className: P + "-title" }, t.title),
4355
- h("span", { className: P + "-badge" }, t.domain + " " + DOMAIN),
4356
- info && info.version ? h("span", { className: P + "-badge" }, t.versionLabel + " v" + info.version) : null,
4357
- snap && snap.shellVersion ? h("span", { className: P + "-badge" }, t.shell + " v" + snap.shellVersion) : null,
4358
- h("span", { className: P + "-badge" }, t.count(visible.length, all.length)),
4359
- h("span", { className: P + "-none" }, t.hint)
4360
- ),
4361
- h("p", { className: P + "-hintline" }, SOURCE === "actions.list" ? t.hostHint : t.switchHint),
4362
- snap ? h(
4363
- "div",
4364
- { className: P + "-toolbar" },
4365
- h(
4366
- "label",
4367
- { className: P + "-search" },
4368
- icon("search", 14),
4369
- h("input", {
4370
- type: "search",
4371
- value: query,
4372
- placeholder: t.search,
4373
- "aria-label": t.search,
4374
- onChange: function(e) {
4375
- setQuery(e.target.value);
4376
- resetFolds();
4377
- }
4378
- })
4379
- ),
4380
- h(
4381
- "label",
4382
- { className: P + "-none" },
4383
- t.filterReq + " ",
4384
- h(
4385
- "select",
4386
- { value: reqMode, "aria-label": t.filterReq, onChange: function(e) {
4387
- setReqMode(e.target.value);
4388
- resetFolds();
4389
- } },
4390
- h("option", { value: "all" }, t.all),
4391
- h("option", { value: "required" }, t.onlyRequired),
4392
- h("option", { value: "optional" }, t.onlyOptional)
4393
- )
4394
- ),
4395
- h(
4396
- "label",
4397
- { className: P + "-none" },
4398
- t.filterType + " ",
4399
- h(
4400
- "select",
4401
- { value: typePick, "aria-label": t.filterType, onChange: function(e) {
4402
- setTypePick(e.target.value);
4403
- resetFolds();
4404
- } },
4405
- h("option", { value: "" }, t.allTypes),
4406
- typeOptions.map(function(name) {
4407
- return h("option", { value: name, key: name }, name);
4408
- })
4409
- )
4410
- ),
4411
- h(
4412
- "label",
4413
- { className: P + "-none" },
4414
- t.filterOrigin + " ",
4415
- h(
4416
- "select",
4417
- { value: originPick, "aria-label": t.filterOrigin, "data-origin-filter": "", onChange: function(e) {
4418
- setOriginPick(e.target.value);
4419
- } },
4420
- h("option", { value: "" }, t.allOrigins),
4421
- ORIGINS.map(function(origin) {
4422
- return h("option", { value: origin, key: origin }, originText[origin]);
4423
- })
4424
- )
4425
- )
4426
- ) : null,
4427
- body,
4428
- toast ? h("div", { className: P + "-toast", role: "status" }, toast) : null
4429
- );
4430
- }
4431
- return { ActionSchemaView, DOMAIN, typeLabel, paramRows };
4432
- };
4433
- }
4434
- });
4435
-
4436
- // packages/addons/danmaku/client/views/actions.cjs
4437
- var require_actions = __commonJS({
4438
- "packages/addons/danmaku/client/views/actions.cjs"(exports2, module2) {
4439
- "use strict";
4440
- module2.exports = require_action_schema_view()({
4441
- domain: "danmaku",
4442
- prefix: "wbdm"
4443
- });
4444
- }
4445
- });
4446
-
4447
3177
  // packages/addons/danmaku/client/client.src.cjs
4448
3178
  var GLYPHS = require_icons2().ICONS;
4449
3179
  var styles = require_styles();
@@ -4491,7 +3221,7 @@ function definition(host) {
4491
3221
  var tab = makeTab(host.react);
4492
3222
  return {
4493
3223
  id: ADDON_ID,
4494
- version: "0.3.2",
3224
+ version: "0.4.0",
4495
3225
  icon: tab("megaphone"),
4496
3226
  views: [
4497
3227
  {
@@ -4499,18 +3229,6 @@ function definition(host) {
4499
3229
  icon: tab("list"),
4500
3230
  title: { zh: "\u5F39\u5E55\u5E93", en: "Library" },
4501
3231
  component: require_library()
4502
- },
4503
- {
4504
- id: "config",
4505
- icon: tab("settings"),
4506
- title: { zh: "\u914D\u7F6E", en: "Settings" },
4507
- component: require_config()
4508
- },
4509
- {
4510
- id: "actions",
4511
- icon: tab("play"),
4512
- title: { zh: "Action", en: "Actions" },
4513
- component: require_actions()
4514
3232
  }
4515
3233
  ]
4516
3234
  };