@lemoncat7/dsh-knowledge 2.3.2 → 2.3.4

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.
Files changed (86) hide show
  1. package/README.md +1 -1
  2. package/docs/ui-maintenance.md +97 -0
  3. package/lib/activity-control.d.ts +6 -0
  4. package/lib/activity-control.d.ts.map +1 -0
  5. package/lib/activity-control.js +118 -0
  6. package/lib/activity-control.js.map +1 -0
  7. package/lib/client.d.ts +17 -0
  8. package/lib/client.d.ts.map +1 -1
  9. package/lib/client.js +4030 -196
  10. package/lib/client.js.map +4 -4
  11. package/lib/design-tokens.d.ts +12 -0
  12. package/lib/design-tokens.d.ts.map +1 -0
  13. package/lib/design-tokens.js +58 -0
  14. package/lib/design-tokens.js.map +1 -0
  15. package/lib/index.d.ts.map +1 -1
  16. package/lib/index.js +3 -0
  17. package/lib/index.js.map +1 -1
  18. package/lib/knowledge-activity-api.d.ts +35 -0
  19. package/lib/knowledge-activity-api.d.ts.map +1 -0
  20. package/lib/knowledge-activity-api.js +115 -0
  21. package/lib/knowledge-activity-api.js.map +1 -0
  22. package/lib/knowledge-activity-controller.d.ts +20 -0
  23. package/lib/knowledge-activity-controller.d.ts.map +1 -0
  24. package/lib/knowledge-activity-controller.js +138 -0
  25. package/lib/knowledge-activity-controller.js.map +1 -0
  26. package/lib/knowledge-activity-notes.d.ts +9 -0
  27. package/lib/knowledge-activity-notes.d.ts.map +1 -0
  28. package/lib/knowledge-activity-notes.js +150 -0
  29. package/lib/knowledge-activity-notes.js.map +1 -0
  30. package/lib/knowledge-activity-panel.d.ts +8 -0
  31. package/lib/knowledge-activity-panel.d.ts.map +1 -0
  32. package/lib/knowledge-activity-panel.js +245 -0
  33. package/lib/knowledge-activity-panel.js.map +1 -0
  34. package/lib/knowledge-activity-presentation.d.ts +14 -0
  35. package/lib/knowledge-activity-presentation.d.ts.map +1 -0
  36. package/lib/knowledge-activity-presentation.js +77 -0
  37. package/lib/knowledge-activity-presentation.js.map +1 -0
  38. package/lib/knowledge-activity-state.d.ts +17 -0
  39. package/lib/knowledge-activity-state.d.ts.map +1 -0
  40. package/lib/knowledge-activity-state.js +14 -0
  41. package/lib/knowledge-activity-state.js.map +1 -0
  42. package/lib/latest-request.d.ts +7 -0
  43. package/lib/latest-request.d.ts.map +1 -0
  44. package/lib/latest-request.js +14 -0
  45. package/lib/latest-request.js.map +1 -0
  46. package/lib/local-provider.d.ts +0 -2
  47. package/lib/local-provider.d.ts.map +1 -1
  48. package/lib/local-provider.js +2 -323
  49. package/lib/local-provider.js.map +1 -1
  50. package/lib/notes/share-page-styles.d.ts +2 -0
  51. package/lib/notes/share-page-styles.d.ts.map +1 -0
  52. package/lib/notes/share-page-styles.js +11 -0
  53. package/lib/notes/share-page-styles.js.map +1 -0
  54. package/lib/notes/share-page.d.ts.map +1 -1
  55. package/lib/notes/share-page.js +1 -8
  56. package/lib/notes/share-page.js.map +1 -1
  57. package/lib/storage/migrations.d.ts +5 -0
  58. package/lib/storage/migrations.d.ts.map +1 -0
  59. package/lib/storage/migrations.js +325 -0
  60. package/lib/storage/migrations.js.map +1 -0
  61. package/lib/theme-bridge.d.ts +9 -7
  62. package/lib/theme-bridge.d.ts.map +1 -1
  63. package/lib/theme-bridge.js +3 -23
  64. package/lib/theme-bridge.js.map +1 -1
  65. package/lib/web-note-editor-outline.js +2 -2
  66. package/lib/web-note-editor-outline.js.map +1 -1
  67. package/lib/web-note-editor-selection.d.ts.map +1 -1
  68. package/lib/web-note-editor-selection.js +51 -16
  69. package/lib/web-note-editor-selection.js.map +1 -1
  70. package/lib/web-note-editor.d.ts.map +1 -1
  71. package/lib/web-note-editor.js +15 -1
  72. package/lib/web-note-editor.js.map +1 -1
  73. package/lib/web.d.ts.map +1 -1
  74. package/lib/web.js +4 -0
  75. package/lib/web.js.map +1 -1
  76. package/package.json +4 -1
  77. package/web/app.js +111 -191
  78. package/web/design-tokens.css +1 -0
  79. package/web/dialogs.js +94 -0
  80. package/web/document-actions.js +68 -0
  81. package/web/index.html +1 -0
  82. package/web/model-catalog.js +22 -0
  83. package/web/note-editor.js +57 -57
  84. package/web/select-control.js +193 -0
  85. package/web/styles.css +162 -203
  86. package/web/ui-primitives.js +5 -0
package/lib/client.js CHANGED
@@ -21,33 +21,3860 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  // src/client.tsx
22
22
  var client_exports = {};
23
23
  __export(client_exports, {
24
- apply: () => apply,
24
+ apply: () => apply2,
25
25
  inject: () => inject
26
26
  });
27
27
  module.exports = __toCommonJS(client_exports);
28
+ var import_react4 = require("react");
29
+
30
+ // src/workspace-ownership.ts
31
+ var WORKSPACE_ACTIVATE_EVENT = "@lemoncat7/dsh-plugin-ui/workspace-activate";
32
+ function activatePluginWorkspace(pluginId) {
33
+ window.dispatchEvent(new CustomEvent(WORKSPACE_ACTIVATE_EVENT, {
34
+ detail: { pluginId }
35
+ }));
36
+ }
37
+ function observePluginWorkspace(pluginId, close) {
38
+ const onActivate = (event) => {
39
+ const detail = event.detail;
40
+ if (detail?.pluginId !== pluginId) close();
41
+ };
42
+ window.addEventListener(WORKSPACE_ACTIVATE_EVENT, onActivate);
43
+ return () => window.removeEventListener(WORKSPACE_ACTIVATE_EVENT, onActivate);
44
+ }
45
+
46
+ // src/client.tsx
47
+ var import_dsh_client_ui_primitives3 = require("@deepseek-ai/dsh-client-ui-primitives");
48
+
49
+ // src/design-tokens.ts
50
+ var KNOWLEDGE_PALETTE = {
51
+ light: {
52
+ "--bg": "#ebebeb",
53
+ "--surface": "#f4f4f4",
54
+ "--surface-raised": "#fafafa",
55
+ "--surface-soft": "#eeeeef",
56
+ "--surface-hover": "rgb(118 118 128 / 9%)",
57
+ "--dialog-surface": "#f4f4f4",
58
+ "--menu-surface": "rgb(232 234 236 / 98%)",
59
+ "--menu-surface-solid": "#e8eaec",
60
+ "--document-surface": "rgb(218 222 226 / 32%)",
61
+ "--selection-background": "#b8c8d6",
62
+ "--selection-text": "#17212b",
63
+ "--activity-surface": "rgba(255, 255, 255, 0.14)",
64
+ "--text": "#1d1d1f",
65
+ "--text-secondary": "#515154",
66
+ "--text-tertiary": "#6e6e73",
67
+ "--border": "rgb(60 60 67 / 14%)",
68
+ "--border-strong": "rgb(60 60 67 / 24%)",
69
+ "--accent": "#3a3a3c",
70
+ "--accent-hover": "#1d1d1f",
71
+ "--accent-soft": "#e2e2e5",
72
+ "--on-accent": "#ffffff",
73
+ "--success": "#248a3d",
74
+ "--success-soft": "#e8f5eb",
75
+ "--warning": "#c93400",
76
+ "--warning-soft": "#fff1e8",
77
+ "--danger": "#d70015",
78
+ "--danger-soft": "#ffebed",
79
+ "--shadow": "0 24px 64px rgb(0 0 0 / 20%)"
80
+ },
81
+ dark: {
82
+ "--bg": "#101719",
83
+ "--surface": "#182022",
84
+ "--surface-raised": "#20292b",
85
+ "--surface-soft": "rgb(184 204 205 / 6%)",
86
+ "--surface-hover": "rgb(105 182 186 / 9%)",
87
+ "--dialog-surface": "#20292b",
88
+ "--menu-surface": "rgb(29 38 40 / 98%)",
89
+ "--menu-surface-solid": "#1d2628",
90
+ "--document-surface": "rgb(130 138 146 / 6%)",
91
+ "--selection-background": "#455b68",
92
+ "--selection-text": "#ffffff",
93
+ "--activity-surface": "rgb(29 36 38 / 24%)",
94
+ "--text": "#e3eaeb",
95
+ "--text-secondary": "#bbc9cc",
96
+ "--text-tertiary": "#95a7ab",
97
+ "--border": "rgb(184 204 205 / 10%)",
98
+ "--border-strong": "rgb(184 204 205 / 18%)",
99
+ "--accent": "#69b6ba",
100
+ "--accent-hover": "#8aced0",
101
+ "--accent-soft": "rgb(105 182 186 / 13%)",
102
+ "--on-accent": "#101819",
103
+ "--success": "#30d158",
104
+ "--success-soft": "rgb(48 209 88 / 13%)",
105
+ "--warning": "#ff9f0a",
106
+ "--warning-soft": "rgb(255 159 10 / 13%)",
107
+ "--danger": "#ff453a",
108
+ "--danger-soft": "rgb(255 69 58 / 14%)",
109
+ "--shadow": "0 28px 72px rgb(0 0 0 / 42%)"
110
+ }
111
+ };
112
+ var KNOWLEDGE_FONTS = {
113
+ "--font-ui": 'ui-sans-serif, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", "PingFang SC", "Noto Sans CJK SC", "Microsoft YaHei UI", Arial, sans-serif',
114
+ "--font-reading": "var(--font-ui)",
115
+ "--font-mono": '"SFMono-Regular", "Cascadia Code", Menlo, Consolas, monospace'
116
+ };
117
+ var KNOWLEDGE_EMBEDDED_MATERIAL = {
118
+ light: {
119
+ "--knowledge-embedded-surface": "rgba(255, 255, 255, 0.08)",
120
+ "--knowledge-embedded-filter": "saturate(.65) contrast(1.015) blur(24px)",
121
+ "--knowledge-embedded-control": "rgba(255, 255, 255, 0.27)"
122
+ },
123
+ dark: {
124
+ "--knowledge-embedded-surface": "rgb(16 23 25 / 18%)",
125
+ "--knowledge-embedded-filter": "saturate(.55) contrast(1.02) blur(24px)",
126
+ "--knowledge-embedded-control": "rgb(39 50 53 / 72%)"
127
+ }
128
+ };
129
+ function declarations(tokens) {
130
+ return Object.entries(tokens).map(([name, value]) => name + ":" + value + ";").join("");
131
+ }
132
+ function knowledgeDesignCss(scope = ":root", dark = ':root[data-color-scheme="dark"]', systemMode = true) {
133
+ const themeTokens = (scheme) => declarations(KNOWLEDGE_PALETTE[scheme]) + declarations(KNOWLEDGE_EMBEDDED_MATERIAL[scheme]);
134
+ const base = scope + "{" + declarations(KNOWLEDGE_FONTS) + themeTokens("light") + "}";
135
+ const darkRule = dark + "{" + themeTokens("dark") + "}";
136
+ const automatic = systemMode ? "@media(prefers-color-scheme:dark){" + scope + ":not([data-color-scheme]){" + themeTokens("dark") + "}}" : "";
137
+ return base + automatic + darkRule;
138
+ }
139
+
140
+ // src/knowledge-activity-state.ts
141
+ function availableActivitySession(state) {
142
+ const current = state.current;
143
+ return current !== void 0 && state.byId[current]?.blank === false ? String(current) : void 0;
144
+ }
145
+ function mergeActivitySelection(previous, next) {
146
+ const merged = { ...previous, ...next };
147
+ if ("knowledgeBaseId" in next && next.knowledgeBaseId !== previous.knowledgeBaseId && !("documentId" in next)) {
148
+ merged.documentId = void 0;
149
+ }
150
+ return merged;
151
+ }
152
+
153
+ // src/client.css
154
+ var client_default = '.dsh-knowledge-trigger,\n.dsh-knowledge-activity-panel,\n.dsh-knowledge-workspace,\n.dsh-knowledge-settings-card,\n.dsh-knowledge-writeback-notice {\n color-scheme: light;\n --knowledge-canvas: transparent;\n --knowledge-accent: var(--accent);\n --knowledge-on-accent: var(--on-accent);\n --knowledge-danger: var(--danger);\n --knowledge-success: var(--success);\n --knowledge-pane: rgba(255, 255, 255, 0.16);\n --knowledge-raised: rgba(255, 255, 255, 0.38);\n --knowledge-control: rgba(255, 255, 255, 0.27);\n --knowledge-border: var(--border);\n --knowledge-text: var(--text);\n --knowledge-text-secondary: var(--text-secondary);\n --knowledge-text-tertiary: var(--text-tertiary);\n --knowledge-hover: var(--surface-hover);\n --knowledge-glare-light: rgb(255 255 255 / 70%);\n --knowledge-glare-rim: rgb(60 60 67 / 11%);\n --knowledge-glass-filter: saturate(1.22) contrast(1.03) blur(32px);\n --knowledge-host-glass-filter: saturate(.18) contrast(1.015) blur(24px);\n --knowledge-glass-shadow: inset 0 1px 0 rgb(255 255 255 / 70%), inset 0 -1px 0 rgb(60 60 67 / 11%), 0 10px 28px rgb(31 31 35 / 8.5%);\n --knowledge-font-family: var(--font-ui);\n color: var(--knowledge-text);\n font-family: var(--knowledge-font-family);\n font-size: 13px;\n line-height: 1.5;\n}\n\nbody[data-ds-dark-theme] :is(\n .dsh-knowledge-trigger,\n .dsh-knowledge-activity-panel,\n .dsh-knowledge-workspace,\n .dsh-knowledge-settings-card,\n .dsh-knowledge-writeback-notice\n) {\n color-scheme: dark;\n --knowledge-canvas: transparent;\n --knowledge-accent: var(--accent);\n --knowledge-on-accent: var(--on-accent);\n --knowledge-danger: var(--danger);\n --knowledge-success: var(--success);\n --knowledge-pane: rgb(25 33 35 / 90%);\n --knowledge-raised: rgb(32 41 43 / 94%);\n --knowledge-control: rgb(39 50 53 / 92%);\n --knowledge-border: var(--border);\n --knowledge-text: var(--text);\n --knowledge-text-secondary: var(--text-secondary);\n --knowledge-text-tertiary: var(--text-tertiary);\n --knowledge-hover: var(--surface-hover);\n --knowledge-glare-light: rgb(255 255 255 / 16%);\n --knowledge-glare-rim: rgb(0 0 0 / 30%);\n --knowledge-host-glass-filter: saturate(.45) contrast(1.02) blur(24px);\n --knowledge-glass-shadow: inset 0 1px 0 rgb(255 255 255 / 16%), inset 0 -1px 0 rgb(0 0 0 / 30%), 0 12px 32px rgb(0 0 0 / 30%);\n}\n\n:is(\n .dsh-knowledge-trigger,\n .dsh-knowledge-activity-panel,\n .dsh-knowledge-workspace,\n .dsh-knowledge-settings-card,\n .dsh-knowledge-writeback-notice\n),\n:is(\n .dsh-knowledge-trigger,\n .dsh-knowledge-activity-panel,\n .dsh-knowledge-workspace,\n .dsh-knowledge-settings-card,\n .dsh-knowledge-writeback-notice\n) * {\n box-sizing: border-box;\n}\n\n:is(\n .dsh-knowledge-trigger,\n .dsh-knowledge-activity-panel,\n .dsh-knowledge-workspace,\n .dsh-knowledge-settings-card,\n .dsh-knowledge-writeback-notice\n) :where(button, input, textarea, select) {\n margin: 0;\n color: inherit;\n font-family: var(--knowledge-font-family);\n font-size: inherit;\n font-weight: inherit;\n line-height: inherit;\n letter-spacing: inherit;\n}\n\n.dsh-knowledge-trigger,\n.dsh-knowledge-activity-panel button,\n.dsh-knowledge-activity-panel input,\n.dsh-knowledge-panel-state button,\n.dsh-knowledge-settings-card button,\n.dsh-knowledge-writeback-notice button {\n -webkit-appearance: none;\n appearance: none;\n margin: 0;\n}\n\n.dsh-knowledge-trigger {\n position: relative;\n flex: none;\n min-width: 0;\n display: flex;\n align-items: center;\n gap: 8px;\n width: calc(100% + 8px);\n height: 34px;\n margin: 4px -4px;\n padding: 6px 2px 6px 10px;\n box-sizing: border-box;\n border: 0;\n border-radius: 12px;\n overflow: hidden;\n background: transparent;\n color: var(--knowledge-text);\n cursor: pointer;\n font: inherit;\n font-size: 14px;\n line-height: 22px;\n white-space: nowrap;\n isolation: isolate;\n transition:\n color 120ms ease,\n background-color 120ms ease,\n box-shadow 160ms ease;\n}\n\n.dsh-knowledge-trigger:hover {\n background: var(--knowledge-hover);\n}\n\n.dsh-knowledge-trigger:focus-visible,\n.dsh-knowledge-writeback-notice button:focus-visible {\n outline: 2px solid var(--knowledge-accent);\n outline-offset: 2px;\n}\n\n.dsh-knowledge-trigger.is-active {\n background: var(--knowledge-control);\n color: var(--knowledge-text);\n box-shadow: 0 1px 2px rgb(0 0 0 / 7%), inset 0 1px 0 rgb(255 255 255 / 28%);\n}\n\n.dsh-knowledge-trigger--rail {\n width: 36px;\n height: 36px;\n margin: 8px 0 10px;\n padding: 0;\n justify-content: center;\n gap: 0;\n border-radius: 50%;\n}\n\n.dsh-knowledge-trigger--rail { margin-inline: auto; }\n\n@media (prefers-reduced-motion: reduce) {\n .dsh-knowledge-trigger { transition: none; }\n}\n\n.dsh-knowledge-workspace {\n width: 100%;\n height: 100%;\n min-width: 0;\n min-height: 0;\n display: flex;\n flex-direction: column;\n overflow: hidden;\n background: var(--knowledge-canvas);\n}\n\n.dsh-knowledge-workspace-header {\n position: relative;\n z-index: 2;\n flex: none;\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: 16px;\n min-height: 52px;\n margin: 8px 10px 0;\n padding: 7px 14px;\n box-sizing: border-box;\n border: 1px solid var(--knowledge-border);\n border-radius: 14px 14px 11px 11px;\n background: transparent;\n box-shadow: var(--knowledge-glass-shadow);\n -webkit-backdrop-filter: var(--knowledge-host-glass-filter);\n backdrop-filter: var(--knowledge-host-glass-filter);\n}\n\n.dsh-knowledge-workspace-header > div {\n display: flex;\n align-items: center;\n gap: 10px;\n min-width: 0;\n}\n\n.dsh-knowledge-workspace-header [data-knowledge-workspace-close] {\n -webkit-appearance: none;\n appearance: none;\n display: grid;\n place-items: center;\n box-sizing: border-box;\n flex: none;\n width: 30px;\n height: 30px;\n margin: 0;\n padding: 0;\n border: 1px solid transparent;\n border-radius: 9px;\n color: var(--knowledge-text-secondary);\n background: transparent;\n font: inherit;\n line-height: 1;\n -webkit-tap-highlight-color: transparent;\n cursor: pointer;\n transition: color 120ms ease, background-color 120ms ease, border-color 120ms ease;\n}\n\n.dsh-knowledge-workspace-header [data-knowledge-workspace-close]:hover {\n border-color: var(--knowledge-border);\n color: var(--knowledge-text);\n background: var(--knowledge-control);\n}\n\n.dsh-knowledge-workspace-header [data-knowledge-workspace-close]:active { border-color: var(--knowledge-text-secondary); }\n.dsh-knowledge-workspace-header [data-knowledge-workspace-close]:focus-visible {\n outline: 2px solid var(--knowledge-accent);\n outline-offset: 2px;\n}\n.dsh-knowledge-workspace-header [data-knowledge-workspace-close] > svg {\n display: block;\n pointer-events: none;\n}\n\n.dsh-knowledge-workspace-header > div > span {\n display: grid;\n min-width: 0;\n gap: 2px;\n}\n\n.dsh-knowledge-workspace-header h2,\n.dsh-knowledge-workspace-header p {\n margin: 0;\n}\n\n.dsh-knowledge-workspace-header h2 {\n color: var(--knowledge-text);\n font-size: 15px;\n line-height: 22px;\n font-weight: 600;\n}\n\n.dsh-knowledge-workspace-header p {\n color: var(--knowledge-text-secondary);\n font-size: 11px;\n line-height: 16px;\n}\n\n.dsh-knowledge-frame {\n flex: 1;\n display: block;\n width: 100%;\n min-height: 0;\n margin: 0;\n border: 0;\n border-radius: 0;\n background: transparent;\n box-shadow: none;\n -webkit-backdrop-filter: none;\n backdrop-filter: none;\n}\n\n.dsh-knowledge-panel-state {\n flex: 1;\n display: flex;\n align-items: center;\n justify-content: center;\n gap: 16px;\n min-height: 0;\n margin: 8px 10px 10px;\n padding: 32px;\n box-sizing: border-box;\n border: 1px solid var(--knowledge-border);\n border-radius: 15px;\n background: var(--knowledge-pane);\n box-shadow: var(--knowledge-glass-shadow);\n -webkit-backdrop-filter: var(--knowledge-host-glass-filter);\n backdrop-filter: var(--knowledge-host-glass-filter);\n color: var(--knowledge-text);\n}\n\n.dsh-knowledge-panel-state-icon {\n flex: none;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n width: 40px;\n height: 40px;\n border-radius: 12px;\n background: var(--knowledge-hover);\n color: var(--knowledge-text-secondary);\n font-size: 18px;\n font-weight: 600;\n}\n\n.dsh-knowledge-panel-state > div { max-width: 560px; }\n.dsh-knowledge-panel-state h3 { margin: 0 0 6px; font-size: 17px; line-height: 24px; font-weight: 600; }\n.dsh-knowledge-panel-state p { margin: 0; color: var(--knowledge-text-secondary); font-size: 13px; line-height: 20px; }\n.dsh-knowledge-panel-state button {\n min-width: 72px;\n min-height: 32px;\n margin-top: 16px;\n padding: 6px 14px;\n border: 0;\n border-radius: 10px;\n background: var(--knowledge-accent);\n color: var(--knowledge-on-accent);\n cursor: pointer;\n font: inherit;\n}\n.dsh-knowledge-panel-state button:focus-visible {\n outline: 2px solid var(--knowledge-accent);\n outline-offset: 2px;\n}\n\n.dsh-knowledge-settings-card {\n list-style: none;\n overflow: hidden;\n border: 1px solid var(--knowledge-border);\n border-radius: 14px;\n background:\n linear-gradient(145deg, color-mix(in srgb, var(--knowledge-glare-light) 16%, transparent), transparent 58%),\n var(--knowledge-pane);\n color: var(--knowledge-text);\n box-shadow: var(--knowledge-glass-shadow), 0 8px 24px rgb(0 0 0 / 5%);\n -webkit-backdrop-filter: var(--knowledge-glass-filter);\n backdrop-filter: var(--knowledge-glass-filter);\n transition: border-color 120ms ease, background-color 120ms ease;\n}\n.dsh-knowledge-settings-card:hover {\n border-color: color-mix(in srgb, var(--knowledge-border) 68%, var(--knowledge-text-secondary));\n}\n.dsh-knowledge-settings-card--open {\n border-color: color-mix(in srgb, var(--knowledge-border) 68%, var(--knowledge-text-secondary));\n background: var(--knowledge-pane);\n}\n.dsh-knowledge-settings-header { display: flex; width: 100%; align-items: center; gap: 12px; padding: 14px 16px; border: 0; border-radius: 12px; background: transparent; color: inherit; text-align: left; cursor: pointer; font: inherit; }\n.dsh-knowledge-settings-header:focus-visible {\n outline: 2px solid var(--knowledge-accent);\n outline-offset: -2px;\n}\n.dsh-knowledge-settings-actions button:focus-visible,\n.dsh-knowledge-settings-load-error button:focus-visible {\n outline: 2px solid var(--knowledge-accent);\n outline-offset: 2px;\n}\n.dsh-knowledge-settings-header > span:first-child { display: flex; min-width: 0; flex: 1; flex-direction: column; gap: 4px; }\n.dsh-knowledge-settings-header strong { font-size: 15px; font-weight: 600; line-height: 1.4; }\n.dsh-knowledge-settings-header small { color: var(--knowledge-text-tertiary); font-size: 13px; line-height: 1.5; }\n.dsh-knowledge-source-picker small,\n.dsh-knowledge-remote-fields small { color: var(--knowledge-text-secondary); font-size: 12px; }\n.dsh-knowledge-settings-summary { display: flex; flex: none; align-items: center; gap: 10px; color: var(--knowledge-text-tertiary); font-size: 12px; }\n.dsh-knowledge-settings-summary i { width: 8px; height: 8px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(45deg); transition: transform 160ms ease; }\n.dsh-knowledge-settings-card--open .dsh-knowledge-settings-summary i { transform: rotate(225deg); }\n\n.dsh-knowledge-settings-body {\n display: grid;\n gap: 18px;\n margin: 0 16px;\n padding-bottom: 8px;\n border-top: 1px solid var(--knowledge-border);\n}\n\n.dsh-knowledge-source-picker {\n min-width: 0;\n display: grid;\n grid-template-columns: repeat(2, minmax(0, 1fr));\n gap: 10px;\n margin: 18px 0 0;\n padding: 0;\n border: 0;\n}\n\n.dsh-knowledge-source-picker legend { margin-bottom: 8px; padding: 0; color: inherit; font-size: 13px; font-weight: 600; }\n.dsh-knowledge-source-picker label {\n display: flex;\n gap: 10px;\n padding: 13px;\n border: 1px solid var(--knowledge-border);\n border-radius: 14px;\n cursor: pointer;\n}\n.dsh-knowledge-source-picker label.is-selected {\n border-color: var(--knowledge-accent);\n background: color-mix(in srgb, var(--knowledge-accent) 7%, transparent);\n}\n.dsh-knowledge-source-picker label.is-disabled {\n cursor: default;\n opacity: .55;\n}\n.dsh-knowledge-source-picker label:focus-within {\n outline: 2px solid var(--knowledge-accent);\n outline-offset: 2px;\n}\n.dsh-knowledge-source-picker input {\n -webkit-appearance: none;\n appearance: none;\n width: 16px;\n height: 16px;\n display: inline-grid;\n place-content: center;\n flex: none;\n margin: 2px 0 0;\n border: 1px solid var(--knowledge-border);\n border-radius: 50%;\n background: var(--knowledge-control);\n color: var(--knowledge-on-accent);\n cursor: pointer;\n transition: border-color .15s ease, background-color .15s ease;\n}\n.dsh-knowledge-source-picker input::before {\n content: "";\n width: 6px;\n height: 6px;\n border-radius: 50%;\n background: currentColor;\n opacity: 0;\n transform: scale(.55);\n transition: opacity .12s ease, transform .15s cubic-bezier(.2, .8, .2, 1);\n}\n.dsh-knowledge-source-picker input:checked { border-color: var(--knowledge-accent); background: var(--knowledge-accent); }\n.dsh-knowledge-source-picker input:checked::before { opacity: 1; transform: scale(1); }\n.dsh-knowledge-source-picker input:disabled { cursor: default; }\n.dsh-knowledge-source-picker span { display: grid; gap: 3px; }\n\n.dsh-knowledge-remote-fields { display: grid; grid-template-columns: 1.25fr 1fr; gap: 12px; }\n.dsh-knowledge-remote-fields label,\n.dsh-knowledge-timeout-field { display: grid; gap: 6px; color: var(--knowledge-text-secondary); font-size: 12px; }\n.dsh-knowledge-remote-fields input,\n.dsh-knowledge-timeout-field input {\n -webkit-appearance: none;\n appearance: none;\n min-height: 38px;\n box-sizing: border-box;\n padding: 8px 11px;\n border: 1px solid var(--knowledge-border);\n border-radius: 10px;\n outline: none;\n background: var(--knowledge-control);\n color: var(--knowledge-text);\n font: inherit;\n}\n.dsh-knowledge-remote-fields input:focus,\n.dsh-knowledge-timeout-field input:focus { border-color: var(--knowledge-accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--knowledge-accent) 16%, transparent); }\n.dsh-knowledge-remote-fields input:-webkit-autofill,\n.dsh-knowledge-remote-fields input:-webkit-autofill:hover,\n.dsh-knowledge-remote-fields input:-webkit-autofill:focus {\n -webkit-text-fill-color: var(--knowledge-text);\n box-shadow: 0 0 0 1000px var(--knowledge-control) inset;\n caret-color: var(--knowledge-text);\n}\n.dsh-knowledge-timeout-field input::-webkit-inner-spin-button,\n.dsh-knowledge-timeout-field input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }\n.dsh-knowledge-timeout-field { max-width: 240px; }\n.dsh-knowledge-field-error { color: var(--knowledge-danger) !important; }\n\n.dsh-knowledge-settings-message,\n.dsh-knowledge-settings-note { margin: 0; color: var(--knowledge-text-secondary); font-size: 12px; }\n.dsh-knowledge-settings-message.is-success { color: var(--knowledge-success); }\n.dsh-knowledge-settings-message.is-error { color: var(--knowledge-danger); }\n.dsh-knowledge-settings-load-error {\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: 12px;\n margin-top: 18px;\n padding: 12px 14px;\n border-radius: 12px;\n background: color-mix(in srgb, var(--knowledge-danger) 8%, transparent);\n color: var(--knowledge-danger);\n font-size: 13px;\n}\n.dsh-knowledge-settings-load-error p { margin: 0; }\n.dsh-knowledge-settings-load-error button {\n flex: none;\n min-height: 30px;\n padding: 5px 10px;\n border: 0;\n border-radius: 9px;\n background: var(--knowledge-control);\n color: var(--knowledge-text);\n cursor: pointer;\n font: inherit;\n}\n.dsh-knowledge-settings-actions { display: flex; justify-content: flex-end; gap: 8px; }\n.dsh-knowledge-settings-actions button {\n min-height: 34px;\n padding: 7px 13px;\n border: 0;\n border-radius: 10px;\n background: var(--knowledge-hover);\n color: var(--knowledge-text);\n cursor: pointer;\n font: inherit;\n font-size: 13px;\n}\n.dsh-knowledge-settings-actions button.is-primary { background: var(--knowledge-accent); color: var(--knowledge-on-accent); }\n.dsh-knowledge-settings-actions button:disabled { cursor: default; opacity: .45; }\n\n@media (max-width: 720px) {\n .dsh-knowledge-source-picker,\n .dsh-knowledge-remote-fields { grid-template-columns: 1fr; }\n .dsh-knowledge-settings-summary { font-size: 0; }\n}\n\n@media (prefers-reduced-motion: reduce) {\n .dsh-knowledge-settings-card,\n .dsh-knowledge-settings-header,\n .dsh-knowledge-settings-summary i { transition: none; }\n}\n\n.dsh-knowledge-writeback-notice {\n display: grid;\n gap: 5px;\n min-width: 0;\n color: var(--knowledge-text-tertiary);\n font-size: 12px;\n line-height: 1.5;\n}\n.dsh-knowledge-writeback-summary {\n display: flex;\n align-items: center;\n flex-wrap: wrap;\n gap: 8px;\n min-width: 0;\n}\n.dsh-knowledge-writeback-notice strong {\n color: var(--knowledge-text-secondary);\n font-weight: 600;\n}\n.dsh-knowledge-writeback-notice button {\n min-height: 24px;\n padding: 0 9px;\n border: 1px solid var(--knowledge-border);\n border-radius: 7px;\n color: var(--knowledge-text-secondary);\n background: var(--knowledge-control);\n cursor: pointer;\n font: inherit;\n}\n.dsh-knowledge-writeback-notice button:disabled { cursor: default; opacity: .5; }\n.dsh-knowledge-writeback-destinations {\n display: flex;\n flex-wrap: wrap;\n gap: 2px 12px;\n min-width: 0;\n margin: 0;\n padding: 0;\n list-style: none;\n}\n.dsh-knowledge-writeback-destinations li {\n display: inline-flex;\n align-items: center;\n gap: 5px;\n min-width: 0;\n max-width: 100%;\n padding: 0;\n border: 0;\n background: transparent;\n}\n.dsh-knowledge-writeback-base,\n.dsh-knowledge-writeback-separator {\n flex: none;\n}\n.dsh-knowledge-writeback-separator {\n color: var(--knowledge-text-tertiary);\n}\n.dsh-knowledge-writeback-destinations strong {\n min-width: 0;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n.dsh-knowledge-writeback-notice .dsh-knowledge-writeback-document {\n display: inline-flex;\n align-items: center;\n min-width: 0;\n min-height: 24px;\n padding: 0 3px;\n border: 0;\n border-radius: 4px;\n background: transparent;\n color: var(--knowledge-text-secondary);\n text-decoration: underline;\n text-decoration-color: transparent;\n text-underline-offset: 3px;\n transition: color 120ms ease, background-color 120ms ease, text-decoration-color 120ms ease;\n}\n.dsh-knowledge-writeback-notice .dsh-knowledge-writeback-document:hover {\n background: var(--knowledge-hover);\n color: var(--knowledge-text);\n text-decoration-color: currentColor;\n}\n.dsh-knowledge-writeback-document strong { color: inherit; }\n.dsh-knowledge-writeback-destinations small {\n flex: none;\n color: var(--knowledge-text-secondary);\n font: inherit;\n white-space: nowrap;\n}\n.dsh-knowledge-writeback-destinations small[data-disposition="written"] { color: var(--knowledge-success); }\n.dsh-knowledge-writeback-error {\n max-width: min(720px, 100%);\n margin: 0;\n color: var(--knowledge-danger);\n overflow-wrap: anywhere;\n}\n';
155
+
156
+ // src/knowledge-activity.css
157
+ var knowledge_activity_default = '.dsh-knowledge-activity-viewport {\n width: 100%;\n height: 100%;\n min-width: 0;\n overflow: hidden;\n contain: layout paint;\n}\n\n.dsh-knowledge-activity-panel {\n display: flex;\n width: 100%;\n height: 100%;\n min-width: 0;\n min-height: 0;\n flex-direction: column;\n overflow: hidden;\n color: var(--knowledge-text);\n background: var(--activity-surface);\n -webkit-backdrop-filter: var(--knowledge-embedded-filter);\n backdrop-filter: var(--knowledge-embedded-filter);\n box-shadow: inset 1px 0 0 var(--knowledge-border);\n font-family: var(--knowledge-font-family);\n font-size: 13px;\n line-height: 1.5;\n}\n\n.dsh-knowledge-activity-panel *,\n.dsh-knowledge-activity-panel *::before,\n.dsh-knowledge-activity-panel *::after { box-sizing: border-box; }\n\n.dsh-knowledge-activity-panel ::selection { background: var(--selection-background); color: var(--selection-text); }\n\n.dsh-knowledge-activity-panel :where(button, input) {\n -webkit-appearance: none;\n appearance: none;\n margin: 0;\n color: inherit;\n font: inherit;\n letter-spacing: inherit;\n}\n\n.dsh-knowledge-activity-header {\n display: flex;\n min-height: 58px;\n padding: 0 12px 0 15px;\n align-items: center;\n justify-content: space-between;\n gap: 10px;\n border-bottom: 1px solid var(--knowledge-border);\n background: transparent;\n}\n\n.dsh-knowledge-activity-tabs {\n display: grid;\n min-height: 43px;\n flex: none;\n grid-template-columns: 1fr 1fr;\n gap: 4px;\n padding: 5px 10px;\n border-bottom: 1px solid var(--knowledge-border);\n background: transparent;\n}\n.dsh-knowledge-activity-tabs button {\n display: inline-flex;\n min-width: 0;\n min-height: 32px;\n align-items: center;\n justify-content: center;\n gap: 6px;\n padding: 0 10px;\n border: 1px solid transparent;\n border-radius: 9px;\n color: var(--knowledge-text-tertiary);\n background: transparent;\n cursor: pointer;\n font-size: 12px;\n font-weight: 580;\n}\n.dsh-knowledge-activity-tabs button:hover { color: var(--knowledge-text); background: var(--knowledge-hover); }\n.dsh-knowledge-activity-tabs button.is-active {\n border-color: var(--knowledge-border);\n color: var(--knowledge-text);\n background: var(--knowledge-embedded-control);\n box-shadow: inset 0 1px 0 var(--knowledge-glare-light);\n}\n\n.dsh-knowledge-activity-title,\n.dsh-knowledge-activity-header-actions { display: flex; min-width: 0; align-items: center; gap: 9px; }\n.dsh-knowledge-activity-title > span:last-child { display: grid; min-width: 0; gap: 1px; }\n.dsh-knowledge-activity-title strong { overflow: hidden; font-size: 14px; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }\n.dsh-knowledge-activity-title small { overflow: hidden; color: var(--knowledge-text-tertiary); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }\n\n.dsh-knowledge-activity-mark,\n.dsh-knowledge-activity-document-icon,\n.dsh-knowledge-activity-row-icon {\n display: grid;\n flex: none;\n place-items: center;\n border: 1px solid color-mix(in srgb, var(--knowledge-accent) 18%, transparent);\n color: var(--knowledge-accent);\n background: color-mix(in srgb, var(--knowledge-accent) 6%, transparent);\n}\n\n.dsh-knowledge-activity-mark { width: 27px; height: 27px; border: 0; border-radius: 8px; background: transparent; }\n.dsh-knowledge-activity-icon-button {\n display: grid;\n width: 32px;\n height: 32px;\n flex: none;\n place-items: center;\n padding: 0;\n border: 1px solid transparent;\n border-radius: 9px;\n color: var(--knowledge-text-secondary);\n background: transparent;\n cursor: pointer;\n}\n.dsh-knowledge-activity-icon-button:hover { border-color: var(--knowledge-border); color: var(--knowledge-text); background: var(--knowledge-hover); }\n.dsh-knowledge-activity-icon-button:focus-visible,\n.dsh-knowledge-activity-panel button:focus-visible,\n.dsh-knowledge-activity-panel input:focus-visible { outline: 2px solid var(--knowledge-accent); outline-offset: 2px; }\n\n.dsh-knowledge-activity-browser,\n.dsh-knowledge-activity-reader {\n display: flex;\n min-height: 0;\n flex: 1;\n flex-direction: column;\n overflow: hidden;\n padding: 14px 14px 16px;\n}\n\n.dsh-knowledge-activity-search {\n display: flex;\n min-height: 40px;\n flex: none;\n align-items: center;\n gap: 8px;\n padding: 0 10px;\n border: 1px solid var(--knowledge-border);\n border-radius: 10px;\n color: var(--knowledge-text-tertiary);\n background: var(--knowledge-embedded-control);\n}\n.dsh-knowledge-activity-search:focus-within { border-color: color-mix(in srgb, var(--knowledge-accent) 50%, var(--knowledge-border)); box-shadow: 0 0 0 3px color-mix(in srgb, var(--knowledge-accent) 10%, transparent); }\n.dsh-knowledge-activity-search input { min-width: 0; height: 38px; flex: 1; padding: 0; border: 0; outline: 0 !important; color: var(--knowledge-text); background: transparent; box-shadow: none; }\n.dsh-knowledge-activity-search input::placeholder { color: var(--knowledge-text-tertiary); opacity: 1; }\n.dsh-knowledge-activity-search > button { display: grid; width: 28px; height: 28px; place-items: center; padding: 0; border: 0; border-radius: 8px; color: var(--knowledge-text-tertiary); background: transparent; cursor: pointer; }\n.dsh-knowledge-activity-search > button:hover { color: var(--knowledge-text); background: var(--knowledge-hover); }\n\n.dsh-knowledge-activity-scope { position: relative; z-index: 3; flex: none; margin-top: 10px; }\n.dsh-knowledge-activity-breadcrumbs {\n display: flex;\n min-height: 37px;\n flex: none;\n align-items: center;\n gap: 1px;\n overflow-x: auto;\n padding: 5px 1px 2px;\n color: var(--knowledge-text-tertiary);\n scrollbar-width: none;\n}\n.dsh-knowledge-activity-breadcrumbs::-webkit-scrollbar { display: none; }\n.dsh-knowledge-activity-breadcrumbs span { display: inline-flex; flex: none; align-items: center; gap: 1px; }\n.dsh-knowledge-activity-breadcrumbs button {\n max-width: 130px;\n min-height: 28px;\n overflow: hidden;\n padding: 0 7px;\n border: 0;\n border-radius: 7px;\n color: inherit;\n text-overflow: ellipsis;\n white-space: nowrap;\n background: transparent;\n cursor: pointer;\n font-size: 11px;\n}\n.dsh-knowledge-activity-breadcrumbs button:hover { color: var(--knowledge-text); background: var(--knowledge-hover); }\n.dsh-knowledge-activity-breadcrumbs button[aria-current="location"] { color: var(--knowledge-text-secondary); font-weight: 620; }\n.dsh-knowledge-activity-scope-trigger {\n display: grid;\n width: 100%;\n min-height: 48px;\n grid-template-columns: 30px minmax(0, 1fr) 20px;\n align-items: center;\n gap: 8px;\n padding: 5px 9px;\n border: 1px solid var(--knowledge-border);\n border-radius: 10px;\n text-align: left;\n background: color-mix(in srgb, var(--knowledge-embedded-control) 72%, transparent);\n cursor: pointer;\n}\n.dsh-knowledge-activity-scope-trigger:hover { background: var(--knowledge-embedded-control); }\n.dsh-knowledge-activity-scope-trigger > span:nth-child(2) { display: grid; min-width: 0; gap: 1px; }\n.dsh-knowledge-activity-scope-trigger small { color: var(--knowledge-text-tertiary); font-size: 10px; }\n.dsh-knowledge-activity-scope-trigger strong { overflow: hidden; font-size: 12px; font-weight: 620; text-overflow: ellipsis; white-space: nowrap; }\n.dsh-knowledge-activity-scope-trigger > svg { color: var(--knowledge-text-tertiary); transition: transform 140ms ease; }\n.dsh-knowledge-activity-scope-trigger > svg.is-open { transform: rotate(180deg); }\n.dsh-knowledge-activity-scope-icon { display: grid; width: 28px; height: 28px; place-items: center; border-radius: 8px; color: var(--knowledge-accent); background: color-mix(in srgb, var(--knowledge-accent) 8%, transparent); }\n.dsh-knowledge-activity-scope-menu {\n position: absolute;\n z-index: 6;\n top: calc(100% + 6px);\n right: 0;\n left: 0;\n max-height: min(320px, 44vh);\n overflow-y: auto;\n padding: 5px;\n border: 1px solid var(--knowledge-border);\n border-radius: 12px;\n background: var(--dialog-surface);\n box-shadow: 0 16px 38px rgb(24 30 32 / 18%), inset 0 1px 0 var(--knowledge-glare-light);\n -webkit-backdrop-filter: none;\n backdrop-filter: none;\n}\n.dsh-knowledge-activity-scope-menu button { display: flex; width: 100%; min-height: 46px; align-items: center; gap: 9px; padding: 6px 9px; border: 0; border-radius: 8px; text-align: left; background: transparent; cursor: pointer; }\n.dsh-knowledge-activity-scope-menu button:hover { background: var(--knowledge-hover); }\n.dsh-knowledge-activity-scope-menu button.is-active { background: var(--knowledge-embedded-control); }\n.dsh-knowledge-activity-scope-menu button > svg { flex: none; color: var(--knowledge-text-secondary); }\n.dsh-knowledge-activity-scope-menu button > span { display: grid; min-width: 0; gap: 1px; }\n.dsh-knowledge-activity-scope-menu button strong { overflow: hidden; font-size: 12px; font-weight: 620; text-overflow: ellipsis; white-space: nowrap; }\n.dsh-knowledge-activity-scope-menu button small { color: var(--knowledge-text-tertiary); font-size: 10px; }\n\n.dsh-knowledge-activity-list-heading {\n display: flex;\n min-height: 46px;\n flex: none;\n align-items: center;\n justify-content: space-between;\n gap: 12px;\n padding: 8px 2px 6px;\n border-bottom: 1px solid var(--knowledge-border);\n}\n.dsh-knowledge-activity-list-heading > span { display: grid; min-width: 0; }\n.dsh-knowledge-activity-list-heading strong { overflow: hidden; font-size: 13px; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }\n.dsh-knowledge-activity-list-heading small { color: var(--knowledge-text-tertiary); font-size: 11px; }\n\n.dsh-knowledge-activity-list {\n min-height: 0;\n flex: 1;\n overflow-y: auto;\n overscroll-behavior: contain;\n padding: 0 0 20px;\n scrollbar-color: color-mix(in srgb, var(--knowledge-text-tertiary) 35%, transparent) transparent;\n scrollbar-width: thin;\n}\n.dsh-knowledge-activity-row {\n display: flex;\n width: 100%;\n min-height: 61px;\n align-items: center;\n gap: 9px;\n padding: 8px 6px;\n border: 0;\n border-bottom: 1px solid color-mix(in srgb, var(--knowledge-border) 72%, transparent);\n border-radius: 0;\n text-align: left;\n background: transparent;\n cursor: pointer;\n}\n.dsh-knowledge-activity-row:hover { border-radius: 8px; background: var(--knowledge-hover); }\n.dsh-knowledge-activity-row:disabled { cursor: default; opacity: .58; }\n.dsh-knowledge-activity-row:disabled:hover { border-radius: 0; background: transparent; }\n.dsh-knowledge-activity-row-icon { width: 27px; height: 27px; border: 0; border-radius: 0; background: transparent; }\n.dsh-knowledge-activity-row-copy { display: grid; min-width: 0; flex: 1; gap: 2px; }\n.dsh-knowledge-activity-row-copy strong,\n.dsh-knowledge-activity-row-copy small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.dsh-knowledge-activity-row-copy strong { color: var(--knowledge-text); font-size: 13px; font-weight: 600; }\n.dsh-knowledge-activity-row-copy small { color: var(--knowledge-text-tertiary); font-size: 10px; }\n.dsh-knowledge-activity-row-meta { display: grid; flex: none; justify-items: end; align-items: center; gap: 3px; color: var(--knowledge-text-tertiary); font-size: 10px; }\n.dsh-knowledge-activity-row-meta em { padding: 1px 5px; border-radius: 999px; color: var(--knowledge-text-secondary); background: var(--knowledge-embedded-control); font-style: normal; }\n.dsh-knowledge-activity-load-more { display: block; min-height: 36px; margin: 8px auto 0; padding: 0 14px; border: 1px solid var(--knowledge-border); border-radius: 10px; color: var(--knowledge-text-secondary); background: var(--knowledge-embedded-control); cursor: pointer; }\n.dsh-knowledge-activity-load-more:hover:not(:disabled) { color: var(--knowledge-text); background: var(--knowledge-hover); }\n\n.dsh-knowledge-activity-reader-bar {\n display: flex;\n min-height: 38px;\n flex: none;\n align-items: center;\n justify-content: space-between;\n gap: 8px;\n border-bottom: 1px solid var(--knowledge-border);\n color: var(--knowledge-text-tertiary);\n font-size: 11px;\n}\n.dsh-knowledge-activity-back { display: inline-flex; min-height: 32px; align-items: center; gap: 4px; padding: 0 7px 0 4px; border: 0; border-radius: 8px; color: var(--knowledge-text-secondary); background: transparent; cursor: pointer; font-size: 12px !important; }\n.dsh-knowledge-activity-back:hover { color: var(--knowledge-text); background: var(--knowledge-hover); }\n.dsh-knowledge-activity-document-heading { display: flex; flex: none; align-items: center; gap: 10px; padding: 16px 4px 13px; }\n.dsh-knowledge-activity-document-icon { width: 36px; height: 36px; border-radius: 11px; }\n.dsh-knowledge-activity-document-heading > div { min-width: 0; }\n.dsh-knowledge-activity-document-heading h2 { overflow: hidden; margin: 0; font-size: 16px; line-height: 22px; font-weight: 680; text-overflow: ellipsis; white-space: nowrap; }\n.dsh-knowledge-activity-document-heading p { overflow: hidden; margin: 1px 0 0; color: var(--knowledge-text-tertiary); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }\n\n.dsh-knowledge-activity-markdown {\n min-height: 0;\n flex: 1;\n overflow-y: auto;\n padding: 0 5px 44px;\n color: var(--knowledge-text);\n font-size: 13px;\n line-height: 1.75;\n overflow-wrap: anywhere;\n scrollbar-color: color-mix(in srgb, var(--knowledge-text-tertiary) 35%, transparent) transparent;\n scrollbar-width: thin;\n}\n.dsh-knowledge-activity-markdown :where(h1, h2, h3, h4, h5, h6) { margin: 1.35em 0 .55em; color: var(--knowledge-text); line-height: 1.35; font-weight: 650; }\n.dsh-knowledge-activity-markdown h1 { font-size: 18px; }\n.dsh-knowledge-activity-markdown h2 { padding-bottom: .35em; border-bottom: 1px solid var(--knowledge-border); font-size: 16px; }\n.dsh-knowledge-activity-markdown h3 { font-size: 14px; }\n.dsh-knowledge-activity-markdown :where(h4, h5, h6) { font-size: 13px; }\n.dsh-knowledge-activity-markdown hr { height: 1px; margin: 18px 0; border: 0; background: var(--knowledge-border); }\n.dsh-knowledge-activity-markdown summary { cursor: pointer; color: var(--knowledge-text); }\n.dsh-knowledge-activity-markdown :where(p, ul, ol, blockquote, pre, table) { margin: .7em 0; }\n.dsh-knowledge-activity-markdown :where(ul, ol) { padding-left: 1.5em; }\n.dsh-knowledge-activity-markdown a { color: var(--knowledge-accent); text-decoration-thickness: 1px; text-underline-offset: 3px; }\n.dsh-knowledge-activity-markdown blockquote { margin-left: 0; padding: .15em 0 .15em 12px; border-left: 3px solid color-mix(in srgb, var(--knowledge-accent) 40%, transparent); color: var(--knowledge-text-secondary); }\n.dsh-knowledge-activity-markdown :where(code, pre) { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; }\n.dsh-knowledge-activity-markdown code { padding: .14em .32em; border-radius: 5px; background: var(--knowledge-embedded-control); font-size: .92em; }\n.dsh-knowledge-activity-markdown pre { overflow-x: auto; padding: 11px 12px; border: 1px solid var(--knowledge-border); border-radius: 10px; background: var(--knowledge-embedded-control); }\n.dsh-knowledge-activity-markdown pre code { padding: 0; background: transparent; }\n.dsh-knowledge-activity-markdown table { width: 100%; border-collapse: collapse; font-size: 12px; }\n.dsh-knowledge-activity-markdown :where(th, td) { padding: 6px 7px; border: 1px solid var(--knowledge-border); text-align: left; }\n.dsh-knowledge-activity-markdown img { display: block; max-width: 100%; height: auto; border-radius: 10px; }\n\n.dsh-knowledge-activity-state,\n.dsh-knowledge-activity-error,\n.dsh-knowledge-activity-empty { margin: auto; text-align: center; }\n.dsh-knowledge-activity-state { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 28px 10px; color: var(--knowledge-text-tertiary); }\n.dsh-knowledge-activity-state > span { width: 8px; height: 8px; border: 2px solid var(--knowledge-border); border-top-color: var(--knowledge-accent); border-radius: 50%; animation: dsh-knowledge-activity-spin .8s linear infinite; }\n.dsh-knowledge-activity-error,\n.dsh-knowledge-activity-empty { display: grid; max-width: 260px; justify-items: center; gap: 6px; padding: 32px 12px; }\n.dsh-knowledge-activity-error strong,\n.dsh-knowledge-activity-empty strong { font-size: 13px; font-weight: 650; }\n.dsh-knowledge-activity-error p,\n.dsh-knowledge-activity-empty p { margin: 0; color: var(--knowledge-text-tertiary); font-size: 11px; line-height: 1.65; }\n.dsh-knowledge-activity-empty > span { display: grid; width: 40px; height: 40px; margin-bottom: 3px; place-items: center; border-radius: 13px; color: var(--knowledge-text-secondary); background: var(--knowledge-embedded-control); }\n.dsh-knowledge-activity-error > button { min-height: 34px; margin-top: 6px; padding: 0 13px; border: 1px solid var(--knowledge-border); border-radius: 9px; background: var(--knowledge-embedded-control); cursor: pointer; }\n.dsh-knowledge-activity-error > button:hover { background: var(--knowledge-hover); }\n\n@keyframes dsh-knowledge-activity-spin { to { transform: rotate(360deg); } }\n\n@media (max-width: 460px) {\n .dsh-knowledge-activity-header { padding-inline: 10px; }\n .dsh-knowledge-activity-browser,\n .dsh-knowledge-activity-reader { padding: 10px 10px max(14px, env(safe-area-inset-bottom)); }\n .dsh-knowledge-activity-search input { font-size: 16px; }\n}\n\n@media (prefers-reduced-motion: reduce) {\n .dsh-knowledge-activity-panel,\n .dsh-knowledge-activity-state > span,\n .dsh-knowledge-activity-scope-trigger > svg { animation: none; transition: none; }\n}\n';
158
+
159
+ // src/knowledge-activity-panel.tsx
160
+ var import_react2 = require("react");
161
+ var import_dsh_client_ui_primitives2 = require("@deepseek-ai/dsh-client-ui-primitives");
162
+
163
+ // src/knowledge-activity-api.ts
164
+ var API_PREFIX = "/knowledge-control/v1/activity";
165
+ var CLIENT_HEADER = "conversation-web";
166
+ async function loadMountedKnowledge(sessionId, projectId, signal) {
167
+ const params = new URLSearchParams({ sessionId });
168
+ if (projectId !== void 0) params.set("projectId", projectId);
169
+ const value = await request(`mounts?${params}`, signal);
170
+ if (!Array.isArray(value)) throw new Error("\u77E5\u8BC6\u5E93\u6302\u8F7D\u63A5\u53E3\u8FD4\u56DE\u4E86\u65E0\u6548\u6570\u636E\u3002");
171
+ return value.filter(isResolvedMount);
172
+ }
173
+ async function loadKnowledgeDocumentIndex(input) {
174
+ const params = new URLSearchParams({ sessionId: input.sessionId, limit: "60" });
175
+ if (input.projectId !== void 0) params.set("projectId", input.projectId);
176
+ for (const id of input.knowledgeBaseIds) params.append("knowledgeBaseId", id);
177
+ if (input.query?.trim()) params.set("q", input.query.trim());
178
+ if (input.cursor !== void 0) params.set("cursor", input.cursor);
179
+ const value = await request(`documents?${params}`, input.signal);
180
+ if (!isDocumentIndex(value)) throw new Error("\u77E5\u8BC6\u6587\u6863\u76EE\u5F55\u8FD4\u56DE\u4E86\u65E0\u6548\u6570\u636E\u3002");
181
+ return value;
182
+ }
183
+ async function loadNoteIndex(input) {
184
+ const params = new URLSearchParams({ sessionId: input.sessionId, limit: "200" });
185
+ if (input.projectId !== void 0) params.set("projectId", input.projectId);
186
+ if (input.query?.trim()) params.set("q", input.query.trim());
187
+ else if (input.parentId !== void 0 && input.parentId !== null) params.set("parentId", input.parentId);
188
+ const value = await request(`notes?${params}`, input.signal);
189
+ if (!Array.isArray(value) || !value.every(isNoteNode)) throw new Error("\u7B14\u8BB0\u76EE\u5F55\u8FD4\u56DE\u4E86\u65E0\u6548\u6570\u636E\u3002");
190
+ return value;
191
+ }
192
+ async function loadNoteContent(input) {
193
+ const params = new URLSearchParams({ sessionId: input.sessionId });
194
+ if (input.projectId !== void 0) params.set("projectId", input.projectId);
195
+ const value = await request(`notes/${encodeURIComponent(input.id)}/content?${params}`, input.signal);
196
+ if (!isRecord(value) || !isNoteNode(value.node) || typeof value.content !== "string") {
197
+ throw new Error("\u7B14\u8BB0\u6B63\u6587\u63A5\u53E3\u8FD4\u56DE\u4E86\u65E0\u6548\u6570\u636E\u3002");
198
+ }
199
+ return value;
200
+ }
201
+ async function loadKnowledgeDocument(input) {
202
+ const params = new URLSearchParams({ sessionId: input.sessionId });
203
+ if (input.projectId !== void 0) params.set("projectId", input.projectId);
204
+ const value = await request(`documents/${encodeURIComponent(input.id)}?${params}`, input.signal);
205
+ if (!isDocument(value)) throw new Error("\u77E5\u8BC6\u6587\u6863\u63A5\u53E3\u8FD4\u56DE\u4E86\u65E0\u6548\u6570\u636E\u3002");
206
+ return value;
207
+ }
208
+ async function request(path, signal) {
209
+ const response = await fetch(`${API_PREFIX}/${path}`, {
210
+ headers: { accept: "application/json", "x-dsh-knowledge-client": CLIENT_HEADER },
211
+ ...signal === void 0 ? {} : { signal }
212
+ });
213
+ const body = await response.json().catch(() => void 0);
214
+ if (!response.ok) {
215
+ const message3 = isRecord(body) && typeof body.error === "string" ? body.error : `\u77E5\u8BC6\u5E93\u63A5\u53E3\u8FD4\u56DE HTTP ${response.status}`;
216
+ throw new Error(message3);
217
+ }
218
+ return body;
219
+ }
220
+ function isResolvedMount(value) {
221
+ return isRecord(value) && typeof value.knowledgeBaseId === "string" && typeof value.enabled === "boolean" && isRecord(value.base) && typeof value.base.id === "string" && typeof value.base.name === "string";
222
+ }
223
+ function isDocumentIndex(value) {
224
+ return isRecord(value) && Array.isArray(value.items) && value.items.every(isDocumentSummary) && Number.isInteger(value.total) && (value.nextCursor === void 0 || typeof value.nextCursor === "string");
225
+ }
226
+ function isDocumentSummary(value) {
227
+ return isRecord(value) && typeof value.id === "string" && typeof value.knowledgeBaseId === "string" && typeof value.relPath === "string" && typeof value.title === "string" && typeof value.updatedAt === "string" && (value.documentState === "open" || value.documentState === "resolved" || value.documentState === "complete");
228
+ }
229
+ function isDocument(value) {
230
+ return isDocumentSummary(value) && isRecord(value) && typeof value.content === "string";
231
+ }
232
+ function isNoteNode(value) {
233
+ return isRecord(value) && typeof value.id === "string" && (value.parentId === null || typeof value.parentId === "string") && (value.kind === "folder" || value.kind === "document" || value.kind === "file") && typeof value.name === "string" && (value.mediaType === null || typeof value.mediaType === "string") && typeof value.editable === "boolean" && typeof value.size === "number" && typeof value.version === "number" && typeof value.updatedAt === "string";
234
+ }
235
+ function isRecord(value) {
236
+ return value !== null && typeof value === "object" && !Array.isArray(value);
237
+ }
238
+
239
+ // src/knowledge-activity-notes.tsx
28
240
  var import_react = require("react");
241
+ var import_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
242
+
243
+ // src/latest-request.ts
244
+ var LatestRequest = class {
245
+ current;
246
+ start() {
247
+ this.cancel();
248
+ this.current = new AbortController();
249
+ return this.current.signal;
250
+ }
251
+ cancel() {
252
+ this.current?.abort();
253
+ this.current = void 0;
254
+ }
255
+ };
256
+
257
+ // node_modules/dompurify/dist/purify.es.mjs
258
+ function _arrayLikeToArray(r, a) {
259
+ (null == a || a > r.length) && (a = r.length);
260
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
261
+ return n;
262
+ }
263
+ function _arrayWithHoles(r) {
264
+ if (Array.isArray(r)) return r;
265
+ }
266
+ function _iterableToArrayLimit(r, l3) {
267
+ var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
268
+ if (null != t) {
269
+ var e, n, i, u, a = [], f2 = true, o = false;
270
+ try {
271
+ if (i = (t = t.call(r)).next, 0 === l3) ;
272
+ else for (; !(f2 = (e = i.call(t)).done) && (a.push(e.value), a.length !== l3); f2 = true) ;
273
+ } catch (r2) {
274
+ o = true, n = r2;
275
+ } finally {
276
+ try {
277
+ if (!f2 && null != t.return && (u = t.return(), Object(u) !== u)) return;
278
+ } finally {
279
+ if (o) throw n;
280
+ }
281
+ }
282
+ return a;
283
+ }
284
+ }
285
+ function _nonIterableRest() {
286
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
287
+ }
288
+ function _slicedToArray(r, e) {
289
+ return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
290
+ }
291
+ function _unsupportedIterableToArray(r, a) {
292
+ if (r) {
293
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
294
+ var t = {}.toString.call(r).slice(8, -1);
295
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
296
+ }
297
+ }
298
+ var entries = Object.entries;
299
+ var setPrototypeOf = Object.setPrototypeOf;
300
+ var isFrozen = Object.isFrozen;
301
+ var getPrototypeOf = Object.getPrototypeOf;
302
+ var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
303
+ var freeze = Object.freeze;
304
+ var seal = Object.seal;
305
+ var create = Object.create;
306
+ var _ref = typeof Reflect !== "undefined" && Reflect;
307
+ var apply = _ref.apply;
308
+ var construct = _ref.construct;
309
+ if (!freeze) {
310
+ freeze = function freeze2(x2) {
311
+ return x2;
312
+ };
313
+ }
314
+ if (!seal) {
315
+ seal = function seal2(x2) {
316
+ return x2;
317
+ };
318
+ }
319
+ if (!apply) {
320
+ apply = function apply3(func, thisArg) {
321
+ for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
322
+ args[_key - 2] = arguments[_key];
323
+ }
324
+ return func.apply(thisArg, args);
325
+ };
326
+ }
327
+ if (!construct) {
328
+ construct = function construct2(Func) {
329
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
330
+ args[_key2 - 1] = arguments[_key2];
331
+ }
332
+ return new Func(...args);
333
+ };
334
+ }
335
+ var arrayForEach = unapply(Array.prototype.forEach);
336
+ var arrayLastIndexOf = unapply(Array.prototype.lastIndexOf);
337
+ var arrayPop = unapply(Array.prototype.pop);
338
+ var arrayPush = unapply(Array.prototype.push);
339
+ var arraySplice = unapply(Array.prototype.splice);
340
+ var arrayIsArray = Array.isArray;
341
+ var stringToLowerCase = unapply(String.prototype.toLowerCase);
342
+ var stringToString = unapply(String.prototype.toString);
343
+ var stringMatch = unapply(String.prototype.match);
344
+ var stringReplace = unapply(String.prototype.replace);
345
+ var stringIndexOf = unapply(String.prototype.indexOf);
346
+ var stringTrim = unapply(String.prototype.trim);
347
+ var numberToString = unapply(Number.prototype.toString);
348
+ var booleanToString = unapply(Boolean.prototype.toString);
349
+ var bigintToString = typeof BigInt === "undefined" ? null : unapply(BigInt.prototype.toString);
350
+ var symbolToString = typeof Symbol === "undefined" ? null : unapply(Symbol.prototype.toString);
351
+ var objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);
352
+ var objectToString = unapply(Object.prototype.toString);
353
+ var regExpTest = unapply(RegExp.prototype.test);
354
+ var typeErrorCreate = unconstruct(TypeError);
355
+ function unapply(func) {
356
+ return function(thisArg) {
357
+ if (thisArg instanceof RegExp) {
358
+ thisArg.lastIndex = 0;
359
+ }
360
+ for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
361
+ args[_key3 - 1] = arguments[_key3];
362
+ }
363
+ return apply(func, thisArg, args);
364
+ };
365
+ }
366
+ function unconstruct(Func) {
367
+ return function() {
368
+ for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
369
+ args[_key4] = arguments[_key4];
370
+ }
371
+ return construct(Func, args);
372
+ };
373
+ }
374
+ function addToSet(set, array) {
375
+ let transformCaseFunc = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : stringToLowerCase;
376
+ if (setPrototypeOf) {
377
+ setPrototypeOf(set, null);
378
+ }
379
+ if (!arrayIsArray(array)) {
380
+ return set;
381
+ }
382
+ let l3 = array.length;
383
+ while (l3--) {
384
+ let element = array[l3];
385
+ if (typeof element === "string") {
386
+ const lcElement = transformCaseFunc(element);
387
+ if (lcElement !== element) {
388
+ if (!isFrozen(array)) {
389
+ array[l3] = lcElement;
390
+ }
391
+ element = lcElement;
392
+ }
393
+ }
394
+ set[element] = true;
395
+ }
396
+ return set;
397
+ }
398
+ function cleanArray(array) {
399
+ for (let index = 0; index < array.length; index++) {
400
+ const isPropertyExist = objectHasOwnProperty(array, index);
401
+ if (!isPropertyExist) {
402
+ array[index] = null;
403
+ }
404
+ }
405
+ return array;
406
+ }
407
+ function clone(object) {
408
+ const newObject = create(null);
409
+ for (const _ref2 of entries(object)) {
410
+ var _ref3 = _slicedToArray(_ref2, 2);
411
+ const property = _ref3[0];
412
+ const value = _ref3[1];
413
+ const isPropertyExist = objectHasOwnProperty(object, property);
414
+ if (isPropertyExist) {
415
+ if (arrayIsArray(value)) {
416
+ newObject[property] = cleanArray(value);
417
+ } else if (value && typeof value === "object" && value.constructor === Object) {
418
+ newObject[property] = clone(value);
419
+ } else {
420
+ newObject[property] = value;
421
+ }
422
+ }
423
+ }
424
+ return newObject;
425
+ }
426
+ function stringifyValue(value) {
427
+ switch (typeof value) {
428
+ case "string": {
429
+ return value;
430
+ }
431
+ case "number": {
432
+ return numberToString(value);
433
+ }
434
+ case "boolean": {
435
+ return booleanToString(value);
436
+ }
437
+ case "bigint": {
438
+ return bigintToString ? bigintToString(value) : "0";
439
+ }
440
+ case "symbol": {
441
+ return symbolToString ? symbolToString(value) : "Symbol()";
442
+ }
443
+ case "undefined": {
444
+ return objectToString(value);
445
+ }
446
+ case "function":
447
+ case "object": {
448
+ if (value === null) {
449
+ return objectToString(value);
450
+ }
451
+ const valueAsRecord = value;
452
+ const valueToString = lookupGetter(valueAsRecord, "toString");
453
+ if (typeof valueToString === "function") {
454
+ const stringified = valueToString(valueAsRecord);
455
+ return typeof stringified === "string" ? stringified : objectToString(stringified);
456
+ }
457
+ return objectToString(value);
458
+ }
459
+ default: {
460
+ return objectToString(value);
461
+ }
462
+ }
463
+ }
464
+ function lookupGetter(object, prop) {
465
+ while (object !== null) {
466
+ const desc = getOwnPropertyDescriptor(object, prop);
467
+ if (desc) {
468
+ if (desc.get) {
469
+ return unapply(desc.get);
470
+ }
471
+ if (typeof desc.value === "function") {
472
+ return unapply(desc.value);
473
+ }
474
+ }
475
+ object = getPrototypeOf(object);
476
+ }
477
+ function fallbackValue() {
478
+ return null;
479
+ }
480
+ return fallbackValue;
481
+ }
482
+ function isRegex(value) {
483
+ try {
484
+ regExpTest(value, "");
485
+ return true;
486
+ } catch (_unused) {
487
+ return false;
488
+ }
489
+ }
490
+ var html$1 = freeze(["a", "abbr", "acronym", "address", "area", "article", "aside", "audio", "b", "bdi", "bdo", "big", "blink", "blockquote", "body", "br", "button", "canvas", "caption", "center", "cite", "code", "col", "colgroup", "content", "data", "datalist", "dd", "decorator", "del", "details", "dfn", "dialog", "dir", "div", "dl", "dt", "element", "em", "fieldset", "figcaption", "figure", "font", "footer", "form", "h1", "h2", "h3", "h4", "h5", "h6", "head", "header", "hgroup", "hr", "html", "i", "img", "input", "ins", "kbd", "label", "legend", "li", "main", "map", "mark", "marquee", "menu", "menuitem", "meter", "nav", "nobr", "ol", "optgroup", "option", "output", "p", "picture", "pre", "progress", "q", "rp", "rt", "ruby", "s", "samp", "search", "section", "select", "shadow", "slot", "small", "source", "spacer", "span", "strike", "strong", "style", "sub", "summary", "sup", "table", "tbody", "td", "template", "textarea", "tfoot", "th", "thead", "time", "tr", "track", "tt", "u", "ul", "var", "video", "wbr"]);
491
+ var svg$1 = freeze(["svg", "a", "altglyph", "altglyphdef", "altglyphitem", "animatecolor", "animatemotion", "animatetransform", "circle", "clippath", "defs", "desc", "ellipse", "enterkeyhint", "exportparts", "filter", "font", "g", "glyph", "glyphref", "hkern", "image", "inputmode", "line", "lineargradient", "marker", "mask", "metadata", "mpath", "part", "path", "pattern", "polygon", "polyline", "radialgradient", "rect", "stop", "style", "switch", "symbol", "text", "textpath", "title", "tref", "tspan", "view", "vkern"]);
492
+ var svgFilters = freeze(["feBlend", "feColorMatrix", "feComponentTransfer", "feComposite", "feConvolveMatrix", "feDiffuseLighting", "feDisplacementMap", "feDistantLight", "feDropShadow", "feFlood", "feFuncA", "feFuncB", "feFuncG", "feFuncR", "feGaussianBlur", "feImage", "feMerge", "feMergeNode", "feMorphology", "feOffset", "fePointLight", "feSpecularLighting", "feSpotLight", "feTile", "feTurbulence"]);
493
+ var svgDisallowed = freeze(["animate", "color-profile", "cursor", "discard", "font-face", "font-face-format", "font-face-name", "font-face-src", "font-face-uri", "foreignobject", "hatch", "hatchpath", "mesh", "meshgradient", "meshpatch", "meshrow", "missing-glyph", "script", "set", "solidcolor", "unknown", "use"]);
494
+ var mathMl$1 = freeze(["math", "menclose", "merror", "mfenced", "mfrac", "mglyph", "mi", "mlabeledtr", "mmultiscripts", "mn", "mo", "mover", "mpadded", "mphantom", "mroot", "mrow", "ms", "mspace", "msqrt", "mstyle", "msub", "msup", "msubsup", "mtable", "mtd", "mtext", "mtr", "munder", "munderover", "mprescripts"]);
495
+ var mathMlDisallowed = freeze(["maction", "maligngroup", "malignmark", "mlongdiv", "mscarries", "mscarry", "msgroup", "mstack", "msline", "msrow", "semantics", "annotation", "annotation-xml", "mprescripts", "none"]);
496
+ var text = freeze(["#text"]);
497
+ var html = freeze(["accept", "action", "align", "alt", "autocapitalize", "autocomplete", "autopictureinpicture", "autoplay", "background", "bgcolor", "border", "capture", "cellpadding", "cellspacing", "checked", "cite", "class", "clear", "color", "cols", "colspan", "command", "commandfor", "controls", "controlslist", "coords", "crossorigin", "datetime", "decoding", "default", "dir", "disabled", "disablepictureinpicture", "disableremoteplayback", "download", "draggable", "enctype", "enterkeyhint", "exportparts", "face", "for", "headers", "height", "hidden", "high", "href", "hreflang", "id", "inert", "inputmode", "integrity", "ismap", "kind", "label", "lang", "list", "loading", "loop", "low", "max", "maxlength", "media", "method", "min", "minlength", "multiple", "muted", "name", "nonce", "noshade", "novalidate", "nowrap", "open", "optimum", "part", "pattern", "placeholder", "playsinline", "popover", "popovertarget", "popovertargetaction", "poster", "preload", "pubdate", "radiogroup", "readonly", "rel", "required", "rev", "reversed", "role", "rows", "rowspan", "spellcheck", "scope", "selected", "shape", "size", "sizes", "slot", "span", "srclang", "start", "src", "srcset", "step", "style", "summary", "tabindex", "title", "translate", "type", "usemap", "valign", "value", "width", "wrap", "xmlns"]);
498
+ var svg = freeze(["accent-height", "accumulate", "additive", "alignment-baseline", "amplitude", "ascent", "attributename", "attributetype", "azimuth", "basefrequency", "baseline-shift", "begin", "bias", "by", "class", "clip", "clippathunits", "clip-path", "clip-rule", "color", "color-interpolation", "color-interpolation-filters", "color-profile", "color-rendering", "cx", "cy", "d", "dx", "dy", "diffuseconstant", "direction", "display", "divisor", "dominant-baseline", "dur", "edgemode", "elevation", "end", "exponent", "fill", "fill-opacity", "fill-rule", "filter", "filterunits", "flood-color", "flood-opacity", "font-family", "font-size", "font-size-adjust", "font-stretch", "font-style", "font-variant", "font-weight", "fx", "fy", "g1", "g2", "glyph-name", "glyphref", "gradientunits", "gradienttransform", "height", "href", "id", "image-rendering", "in", "in2", "intercept", "k", "k1", "k2", "k3", "k4", "kerning", "keypoints", "keysplines", "keytimes", "lang", "lengthadjust", "letter-spacing", "kernelmatrix", "kernelunitlength", "lighting-color", "local", "marker-end", "marker-mid", "marker-start", "markerheight", "markerunits", "markerwidth", "maskcontentunits", "maskunits", "max", "mask", "mask-type", "media", "method", "mode", "min", "name", "numoctaves", "offset", "operator", "opacity", "order", "orient", "orientation", "origin", "overflow", "paint-order", "path", "pathlength", "patterncontentunits", "patterntransform", "patternunits", "pointer-events", "points", "preservealpha", "preserveaspectratio", "primitiveunits", "r", "rx", "ry", "radius", "refx", "refy", "repeatcount", "repeatdur", "restart", "result", "rotate", "scale", "seed", "shape-rendering", "slope", "specularconstant", "specularexponent", "spreadmethod", "startoffset", "stddeviation", "stitchtiles", "stop-color", "stop-opacity", "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin", "stroke-miterlimit", "stroke-opacity", "stroke", "stroke-width", "style", "surfacescale", "systemlanguage", "tabindex", "tablevalues", "targetx", "targety", "transform", "transform-origin", "text-anchor", "text-decoration", "text-orientation", "text-rendering", "textlength", "type", "u1", "u2", "unicode", "values", "vector-effect", "viewbox", "visibility", "version", "vert-adv-y", "vert-origin-x", "vert-origin-y", "width", "word-spacing", "wrap", "writing-mode", "xchannelselector", "ychannelselector", "x", "x1", "x2", "xmlns", "y", "y1", "y2", "z", "zoomandpan"]);
499
+ var mathMl = freeze(["accent", "accentunder", "align", "bevelled", "close", "columnalign", "columnlines", "columnspacing", "columnspan", "denomalign", "depth", "dir", "display", "displaystyle", "encoding", "fence", "frame", "height", "href", "id", "largeop", "length", "linethickness", "lquote", "lspace", "mathbackground", "mathcolor", "mathsize", "mathvariant", "maxsize", "minsize", "movablelimits", "notation", "numalign", "open", "rowalign", "rowlines", "rowspacing", "rowspan", "rspace", "rquote", "scriptlevel", "scriptminsize", "scriptsizemultiplier", "selection", "separator", "separators", "stretchy", "subscriptshift", "supscriptshift", "symmetric", "voffset", "width", "xmlns"]);
500
+ var xml = freeze(["xlink:href", "xml:id", "xlink:title", "xml:space", "xmlns:xlink"]);
501
+ var MUSTACHE_EXPR = seal(/{{[\w\W]*|^[\w\W]*}}/g);
502
+ var ERB_EXPR = seal(/<%[\w\W]*|^[\w\W]*%>/g);
503
+ var TMPLIT_EXPR = seal(/\${[\w\W]*/g);
504
+ var DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]+$/);
505
+ var ARIA_ATTR = seal(/^aria-[\-\w]+$/);
506
+ var IS_ALLOWED_URI = seal(
507
+ /^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i
508
+ // eslint-disable-line no-useless-escape
509
+ );
510
+ var IS_SCRIPT_OR_DATA = seal(/^(?:\w+script|data):/i);
511
+ var ATTR_WHITESPACE = seal(
512
+ /[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g
513
+ // eslint-disable-line no-control-regex
514
+ );
515
+ var DOCTYPE_NAME = seal(/^html$/i);
516
+ var CUSTOM_ELEMENT = seal(/^[a-z][.\w]*(-[.\w]+)+$/i);
517
+ var ELEMENT_MARKUP_PROBE = seal(/<[/\w!]/g);
518
+ var COMMENT_MARKUP_PROBE = seal(/<[/\w]/g);
519
+ var FALLBACK_TAG_CLOSE = seal(/<\/no(script|embed|frames)/i);
520
+ var SELF_CLOSING_TAG = seal(/\/>/i);
521
+ var NODE_TYPE = {
522
+ element: 1,
523
+ attribute: 2,
524
+ text: 3,
525
+ cdataSection: 4,
526
+ entityReference: 5,
527
+ // Deprecated
528
+ entityNode: 6,
529
+ // Deprecated
530
+ processingInstruction: 7,
531
+ comment: 8,
532
+ document: 9,
533
+ documentType: 10,
534
+ documentFragment: 11,
535
+ notation: 12
536
+ // Deprecated
537
+ };
538
+ var LITERAL_TEXT_ELEMENT_NAMES = ["style", "script", "xmp", "iframe", "noembed", "noframes", "plaintext", "noscript"];
539
+ var LITERAL_TEXT_ELEMENTS = freeze(addToSet({}, LITERAL_TEXT_ELEMENT_NAMES));
540
+ var LITERAL_TEXT_CLOSE = (function() {
541
+ const map = {};
542
+ arrayForEach(LITERAL_TEXT_ELEMENT_NAMES, (name) => {
543
+ map[name] = seal(new RegExp("</" + name + "(?=[\\t\\n\\f\\r />])", "i"));
544
+ });
545
+ return freeze(map);
546
+ })();
547
+ var getGlobal = function getGlobal2() {
548
+ return typeof window === "undefined" ? null : window;
549
+ };
550
+ var _createTrustedTypesPolicy = function _createTrustedTypesPolicy2(trustedTypes, purifyHostElement) {
551
+ if (typeof trustedTypes !== "object" || typeof trustedTypes.createPolicy !== "function") {
552
+ return null;
553
+ }
554
+ let suffix = null;
555
+ const ATTR_NAME = "data-tt-policy-suffix";
556
+ if (purifyHostElement && purifyHostElement.hasAttribute(ATTR_NAME)) {
557
+ suffix = purifyHostElement.getAttribute(ATTR_NAME);
558
+ }
559
+ const policyName = "dompurify" + (suffix ? "#" + suffix : "");
560
+ try {
561
+ return trustedTypes.createPolicy(policyName, {
562
+ createHTML(html2) {
563
+ return html2;
564
+ },
565
+ createScriptURL(scriptUrl) {
566
+ return scriptUrl;
567
+ }
568
+ });
569
+ } catch (_2) {
570
+ console.warn("TrustedTypes policy " + policyName + " could not be created.");
571
+ return null;
572
+ }
573
+ };
574
+ var _createHooksMap = function _createHooksMap2() {
575
+ return {
576
+ afterSanitizeAttributes: [],
577
+ afterSanitizeElements: [],
578
+ afterSanitizeShadowDOM: [],
579
+ beforeSanitizeAttributes: [],
580
+ beforeSanitizeElements: [],
581
+ beforeSanitizeShadowDOM: [],
582
+ uponSanitizeAttribute: [],
583
+ uponSanitizeElement: [],
584
+ uponSanitizeShadowNode: []
585
+ };
586
+ };
587
+ var _resolveSetOption = function _resolveSetOption2(cfg, key, fallback, options) {
588
+ return objectHasOwnProperty(cfg, key) && arrayIsArray(cfg[key]) ? addToSet(options.base ? clone(options.base) : {}, cfg[key], options.transform) : fallback;
589
+ };
590
+ var _resolveObjectOption = function _resolveObjectOption2(cfg, key, makeFallback) {
591
+ const value = objectHasOwnProperty(cfg, key) ? cfg[key] : void 0;
592
+ return value && typeof value === "object" ? clone(value) : makeFallback();
593
+ };
594
+ function createDOMPurify() {
595
+ let window2 = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : getGlobal();
596
+ const DOMPurify = (root) => createDOMPurify(root);
597
+ DOMPurify.version = "3.4.14";
598
+ DOMPurify.removed = [];
599
+ if (!window2 || !window2.document || window2.document.nodeType !== NODE_TYPE.document || !window2.Element) {
600
+ DOMPurify.isSupported = false;
601
+ return DOMPurify;
602
+ }
603
+ let document2 = window2.document;
604
+ const originalDocument = document2;
605
+ const currentScript = originalDocument.currentScript;
606
+ window2.DocumentFragment;
607
+ const HTMLTemplateElement = window2.HTMLTemplateElement, Node = window2.Node, Element = window2.Element, NodeFilter = window2.NodeFilter, _window$NamedNodeMap = window2.NamedNodeMap;
608
+ _window$NamedNodeMap === void 0 ? window2.NamedNodeMap || window2.MozNamedAttrMap : _window$NamedNodeMap;
609
+ window2.HTMLFormElement;
610
+ const DOMParser = window2.DOMParser, trustedTypes = window2.trustedTypes;
611
+ const ElementPrototype = Element.prototype;
612
+ const cloneNode = lookupGetter(ElementPrototype, "cloneNode");
613
+ const remove = lookupGetter(ElementPrototype, "remove");
614
+ const getNextSibling = lookupGetter(ElementPrototype, "nextSibling");
615
+ const getChildNodes = lookupGetter(ElementPrototype, "childNodes");
616
+ const getParentNode = lookupGetter(ElementPrototype, "parentNode");
617
+ const getShadowRoot = lookupGetter(ElementPrototype, "shadowRoot");
618
+ const getAttributes = lookupGetter(ElementPrototype, "attributes");
619
+ const getNodeType = Node && Node.prototype ? lookupGetter(Node.prototype, "nodeType") : null;
620
+ const getNodeName = Node && Node.prototype ? lookupGetter(Node.prototype, "nodeName") : null;
621
+ const getOwnerDocument = Node && Node.prototype ? lookupGetter(Node.prototype, "ownerDocument") : null;
622
+ const _readNodeType = function _readNodeType2(node) {
623
+ return getNodeType ? getNodeType(node) : node.nodeType;
624
+ };
625
+ const _readNodeName = function _readNodeName2(node) {
626
+ return getNodeName ? getNodeName(node) : node.nodeName;
627
+ };
628
+ if (typeof HTMLTemplateElement === "function") {
629
+ const template = document2.createElement("template");
630
+ if (template.content && template.content.ownerDocument) {
631
+ document2 = template.content.ownerDocument;
632
+ }
633
+ }
634
+ let trustedTypesPolicy;
635
+ let emptyHTML = "";
636
+ let defaultTrustedTypesPolicy;
637
+ let defaultTrustedTypesPolicyResolved = false;
638
+ let IN_TRUSTED_TYPES_POLICY = 0;
639
+ const _assertNotInTrustedTypesPolicy = function _assertNotInTrustedTypesPolicy2() {
640
+ if (IN_TRUSTED_TYPES_POLICY > 0) {
641
+ throw typeErrorCreate('A configured TRUSTED_TYPES_POLICY callback (createHTML or createScriptURL) must not call DOMPurify.sanitize, as that causes infinite recursion. Do not pass a policy whose callbacks wrap DOMPurify as TRUSTED_TYPES_POLICY; see the "DOMPurify and Trusted Types" section of the README.');
642
+ }
643
+ };
644
+ const _createTrustedHTML = function _createTrustedHTML2(html2) {
645
+ _assertNotInTrustedTypesPolicy();
646
+ IN_TRUSTED_TYPES_POLICY++;
647
+ try {
648
+ return trustedTypesPolicy.createHTML(html2);
649
+ } finally {
650
+ IN_TRUSTED_TYPES_POLICY--;
651
+ }
652
+ };
653
+ const _createTrustedScriptURL = function _createTrustedScriptURL2(scriptUrl) {
654
+ _assertNotInTrustedTypesPolicy();
655
+ IN_TRUSTED_TYPES_POLICY++;
656
+ try {
657
+ return trustedTypesPolicy.createScriptURL(scriptUrl);
658
+ } finally {
659
+ IN_TRUSTED_TYPES_POLICY--;
660
+ }
661
+ };
662
+ const _getDefaultTrustedTypesPolicy = function _getDefaultTrustedTypesPolicy2() {
663
+ if (!defaultTrustedTypesPolicyResolved) {
664
+ defaultTrustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
665
+ defaultTrustedTypesPolicyResolved = true;
666
+ }
667
+ return defaultTrustedTypesPolicy;
668
+ };
669
+ const _document = document2, implementation = _document.implementation, createNodeIterator = _document.createNodeIterator, createDocumentFragment = _document.createDocumentFragment, getElementsByTagName = _document.getElementsByTagName;
670
+ const importNode = originalDocument.importNode;
671
+ let hooks = _createHooksMap();
672
+ DOMPurify.isSupported = typeof entries === "function" && typeof getParentNode === "function" && implementation && implementation.createHTMLDocument !== void 0;
673
+ const MUSTACHE_EXPR$1 = MUSTACHE_EXPR, ERB_EXPR$1 = ERB_EXPR, TMPLIT_EXPR$1 = TMPLIT_EXPR, DATA_ATTR$1 = DATA_ATTR, ARIA_ATTR$1 = ARIA_ATTR, IS_SCRIPT_OR_DATA$1 = IS_SCRIPT_OR_DATA, ATTR_WHITESPACE$1 = ATTR_WHITESPACE, CUSTOM_ELEMENT$1 = CUSTOM_ELEMENT;
674
+ let IS_ALLOWED_URI$1 = IS_ALLOWED_URI;
675
+ let ALLOWED_TAGS = null;
676
+ const DEFAULT_ALLOWED_TAGS = addToSet({}, [...html$1, ...svg$1, ...svgFilters, ...mathMl$1, ...text]);
677
+ let ALLOWED_ATTR = null;
678
+ const DEFAULT_ALLOWED_ATTR = addToSet({}, [...html, ...svg, ...mathMl, ...xml]);
679
+ let CUSTOM_ELEMENT_HANDLING = Object.seal(create(null, {
680
+ tagNameCheck: {
681
+ writable: true,
682
+ configurable: false,
683
+ enumerable: true,
684
+ value: null
685
+ },
686
+ attributeNameCheck: {
687
+ writable: true,
688
+ configurable: false,
689
+ enumerable: true,
690
+ value: null
691
+ },
692
+ allowCustomizedBuiltInElements: {
693
+ writable: true,
694
+ configurable: false,
695
+ enumerable: true,
696
+ value: false
697
+ }
698
+ }));
699
+ let FORBID_TAGS = null;
700
+ let FORBID_ATTR = null;
701
+ const EXTRA_ELEMENT_HANDLING = Object.seal(create(null, {
702
+ tagCheck: {
703
+ writable: true,
704
+ configurable: false,
705
+ enumerable: true,
706
+ value: null
707
+ },
708
+ attributeCheck: {
709
+ writable: true,
710
+ configurable: false,
711
+ enumerable: true,
712
+ value: null
713
+ }
714
+ }));
715
+ let ALLOW_ARIA_ATTR = true;
716
+ let ALLOW_DATA_ATTR = true;
717
+ let ALLOW_UNKNOWN_PROTOCOLS = false;
718
+ let ALLOW_SELF_CLOSE_IN_ATTR = true;
719
+ let SAFE_FOR_TEMPLATES = false;
720
+ let SAFE_FOR_XML = true;
721
+ let WHOLE_DOCUMENT = false;
722
+ let SET_CONFIG = false;
723
+ let SET_CONFIG_ALLOWED_TAGS = null;
724
+ let SET_CONFIG_ALLOWED_ATTR = null;
725
+ let FORCE_BODY = false;
726
+ let RETURN_DOM = false;
727
+ let RETURN_DOM_FRAGMENT = false;
728
+ let RETURN_TRUSTED_TYPE = false;
729
+ let SANITIZE_DOM = true;
730
+ let SANITIZE_NAMED_PROPS = false;
731
+ const SANITIZE_NAMED_PROPS_PREFIX = "user-content-";
732
+ let KEEP_CONTENT = true;
733
+ let IN_PLACE = false;
734
+ let USE_PROFILES = {};
735
+ let FORBID_CONTENTS = null;
736
+ const DEFAULT_FORBID_CONTENTS = addToSet({}, [
737
+ "annotation-xml",
738
+ "audio",
739
+ "colgroup",
740
+ "desc",
741
+ "foreignobject",
742
+ "head",
743
+ "iframe",
744
+ "math",
745
+ "mi",
746
+ "mn",
747
+ "mo",
748
+ "ms",
749
+ "mtext",
750
+ "noembed",
751
+ "noframes",
752
+ "noscript",
753
+ "plaintext",
754
+ "script",
755
+ // <selectedcontent> mirrors the selected <option>'s subtree, cloned by
756
+ // the UA (customizable <select>) — including any on* handlers — and the
757
+ // engine re-mirrors synchronously whenever a removal changes which
758
+ // option/selectedcontent is current, even inside DOMPurify's inert
759
+ // DOMParser document. Hoisting its children on removal re-inserts a fresh
760
+ // mirror target ahead of the walk, which the engine refills, looping
761
+ // forever (DoS) and amplifying output. Dropping its content on removal
762
+ // (rather than hoisting) breaks that cascade; the content is a duplicate
763
+ // of the option, which is sanitized on its own. See campaign-3 F1/F6.
764
+ "selectedcontent",
765
+ "style",
766
+ "svg",
767
+ "template",
768
+ "thead",
769
+ "title",
770
+ "video",
771
+ "xmp"
772
+ ]);
773
+ let DATA_URI_TAGS = null;
774
+ const DEFAULT_DATA_URI_TAGS = addToSet({}, ["audio", "video", "img", "source", "image", "track"]);
775
+ let URI_SAFE_ATTRIBUTES = null;
776
+ const DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, ["alt", "class", "for", "id", "label", "name", "pattern", "placeholder", "role", "summary", "title", "value", "style", "xmlns"]);
777
+ const MATHML_NAMESPACE = "http://www.w3.org/1998/Math/MathML";
778
+ const SVG_NAMESPACE = "http://www.w3.org/2000/svg";
779
+ const HTML_NAMESPACE = "http://www.w3.org/1999/xhtml";
780
+ let NAMESPACE = HTML_NAMESPACE;
781
+ let IS_EMPTY_INPUT = false;
782
+ let ALLOWED_NAMESPACES = null;
783
+ const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [MATHML_NAMESPACE, SVG_NAMESPACE, HTML_NAMESPACE], stringToString);
784
+ const DEFAULT_MATHML_TEXT_INTEGRATION_POINTS = freeze(["mi", "mo", "mn", "ms", "mtext"]);
785
+ let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, DEFAULT_MATHML_TEXT_INTEGRATION_POINTS);
786
+ const DEFAULT_HTML_INTEGRATION_POINTS = freeze(["annotation-xml"]);
787
+ let HTML_INTEGRATION_POINTS = addToSet({}, DEFAULT_HTML_INTEGRATION_POINTS);
788
+ const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, ["title", "style", "font", "a", "script"]);
789
+ let PARSER_MEDIA_TYPE = null;
790
+ const SUPPORTED_PARSER_MEDIA_TYPES = ["application/xhtml+xml", "text/html"];
791
+ const DEFAULT_PARSER_MEDIA_TYPE = "text/html";
792
+ let transformCaseFunc = null;
793
+ let CONFIG = null;
794
+ const formElement = document2.createElement("form");
795
+ const isRegexOrFunction = function isRegexOrFunction2(testValue) {
796
+ return testValue instanceof RegExp || testValue instanceof Function;
797
+ };
798
+ const _parseConfig = function _parseConfig2() {
799
+ let cfg = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
800
+ if (CONFIG && CONFIG === cfg) {
801
+ return;
802
+ }
803
+ if (!cfg || typeof cfg !== "object") {
804
+ cfg = {};
805
+ }
806
+ cfg = clone(cfg);
807
+ PARSER_MEDIA_TYPE = // eslint-disable-next-line unicorn/prefer-includes
808
+ SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? DEFAULT_PARSER_MEDIA_TYPE : cfg.PARSER_MEDIA_TYPE;
809
+ transformCaseFunc = PARSER_MEDIA_TYPE === "application/xhtml+xml" ? stringToString : stringToLowerCase;
810
+ ALLOWED_TAGS = _resolveSetOption(cfg, "ALLOWED_TAGS", DEFAULT_ALLOWED_TAGS, {
811
+ transform: transformCaseFunc
812
+ });
813
+ ALLOWED_ATTR = _resolveSetOption(cfg, "ALLOWED_ATTR", DEFAULT_ALLOWED_ATTR, {
814
+ transform: transformCaseFunc
815
+ });
816
+ ALLOWED_NAMESPACES = _resolveSetOption(cfg, "ALLOWED_NAMESPACES", DEFAULT_ALLOWED_NAMESPACES, {
817
+ transform: stringToString
818
+ });
819
+ URI_SAFE_ATTRIBUTES = _resolveSetOption(cfg, "ADD_URI_SAFE_ATTR", DEFAULT_URI_SAFE_ATTRIBUTES, {
820
+ transform: transformCaseFunc,
821
+ base: DEFAULT_URI_SAFE_ATTRIBUTES
822
+ });
823
+ DATA_URI_TAGS = _resolveSetOption(cfg, "ADD_DATA_URI_TAGS", DEFAULT_DATA_URI_TAGS, {
824
+ transform: transformCaseFunc,
825
+ base: DEFAULT_DATA_URI_TAGS
826
+ });
827
+ FORBID_CONTENTS = _resolveSetOption(cfg, "FORBID_CONTENTS", DEFAULT_FORBID_CONTENTS, {
828
+ transform: transformCaseFunc
829
+ });
830
+ FORBID_TAGS = _resolveSetOption(cfg, "FORBID_TAGS", clone({}), {
831
+ transform: transformCaseFunc
832
+ });
833
+ FORBID_ATTR = _resolveSetOption(cfg, "FORBID_ATTR", clone({}), {
834
+ transform: transformCaseFunc
835
+ });
836
+ USE_PROFILES = objectHasOwnProperty(cfg, "USE_PROFILES") ? cfg.USE_PROFILES && typeof cfg.USE_PROFILES === "object" ? clone(cfg.USE_PROFILES) : cfg.USE_PROFILES : false;
837
+ ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false;
838
+ ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false;
839
+ ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false;
840
+ ALLOW_SELF_CLOSE_IN_ATTR = cfg.ALLOW_SELF_CLOSE_IN_ATTR !== false;
841
+ SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false;
842
+ SAFE_FOR_XML = cfg.SAFE_FOR_XML !== false;
843
+ WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false;
844
+ RETURN_DOM = cfg.RETURN_DOM || false;
845
+ RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false;
846
+ RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false;
847
+ FORCE_BODY = cfg.FORCE_BODY || false;
848
+ SANITIZE_DOM = cfg.SANITIZE_DOM !== false;
849
+ SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false;
850
+ KEEP_CONTENT = cfg.KEEP_CONTENT !== false;
851
+ IN_PLACE = cfg.IN_PLACE || false;
852
+ IS_ALLOWED_URI$1 = isRegex(cfg.ALLOWED_URI_REGEXP) ? cfg.ALLOWED_URI_REGEXP : IS_ALLOWED_URI;
853
+ NAMESPACE = typeof cfg.NAMESPACE === "string" ? cfg.NAMESPACE : HTML_NAMESPACE;
854
+ MATHML_TEXT_INTEGRATION_POINTS = _resolveObjectOption(
855
+ cfg,
856
+ "MATHML_TEXT_INTEGRATION_POINTS",
857
+ () => addToSet({}, DEFAULT_MATHML_TEXT_INTEGRATION_POINTS)
858
+ // Default built-in map
859
+ );
860
+ HTML_INTEGRATION_POINTS = _resolveObjectOption(
861
+ cfg,
862
+ "HTML_INTEGRATION_POINTS",
863
+ () => addToSet({}, DEFAULT_HTML_INTEGRATION_POINTS)
864
+ // Default built-in map
865
+ );
866
+ const customElementHandling = _resolveObjectOption(cfg, "CUSTOM_ELEMENT_HANDLING", () => create(null));
867
+ CUSTOM_ELEMENT_HANDLING = create(null);
868
+ if (objectHasOwnProperty(customElementHandling, "tagNameCheck") && isRegexOrFunction(customElementHandling.tagNameCheck)) {
869
+ CUSTOM_ELEMENT_HANDLING.tagNameCheck = customElementHandling.tagNameCheck;
870
+ }
871
+ if (objectHasOwnProperty(customElementHandling, "attributeNameCheck") && isRegexOrFunction(customElementHandling.attributeNameCheck)) {
872
+ CUSTOM_ELEMENT_HANDLING.attributeNameCheck = customElementHandling.attributeNameCheck;
873
+ }
874
+ if (objectHasOwnProperty(customElementHandling, "allowCustomizedBuiltInElements") && typeof customElementHandling.allowCustomizedBuiltInElements === "boolean") {
875
+ CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = customElementHandling.allowCustomizedBuiltInElements;
876
+ }
877
+ seal(CUSTOM_ELEMENT_HANDLING);
878
+ if (SAFE_FOR_TEMPLATES) {
879
+ ALLOW_DATA_ATTR = false;
880
+ }
881
+ if (RETURN_DOM_FRAGMENT) {
882
+ RETURN_DOM = true;
883
+ }
884
+ if (USE_PROFILES) {
885
+ ALLOWED_TAGS = addToSet({}, text);
886
+ ALLOWED_ATTR = create(null);
887
+ if (USE_PROFILES.html === true) {
888
+ addToSet(ALLOWED_TAGS, html$1);
889
+ addToSet(ALLOWED_ATTR, html);
890
+ }
891
+ if (USE_PROFILES.svg === true) {
892
+ addToSet(ALLOWED_TAGS, svg$1);
893
+ addToSet(ALLOWED_ATTR, svg);
894
+ addToSet(ALLOWED_ATTR, xml);
895
+ }
896
+ if (USE_PROFILES.svgFilters === true) {
897
+ addToSet(ALLOWED_TAGS, svgFilters);
898
+ addToSet(ALLOWED_ATTR, svg);
899
+ addToSet(ALLOWED_ATTR, xml);
900
+ }
901
+ if (USE_PROFILES.mathMl === true) {
902
+ addToSet(ALLOWED_TAGS, mathMl$1);
903
+ addToSet(ALLOWED_ATTR, mathMl);
904
+ addToSet(ALLOWED_ATTR, xml);
905
+ }
906
+ }
907
+ EXTRA_ELEMENT_HANDLING.tagCheck = null;
908
+ EXTRA_ELEMENT_HANDLING.attributeCheck = null;
909
+ if (objectHasOwnProperty(cfg, "ADD_TAGS")) {
910
+ if (typeof cfg.ADD_TAGS === "function") {
911
+ EXTRA_ELEMENT_HANDLING.tagCheck = cfg.ADD_TAGS;
912
+ } else if (arrayIsArray(cfg.ADD_TAGS)) {
913
+ if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {
914
+ ALLOWED_TAGS = clone(ALLOWED_TAGS);
915
+ }
916
+ addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
917
+ }
918
+ }
919
+ if (objectHasOwnProperty(cfg, "ADD_ATTR")) {
920
+ if (typeof cfg.ADD_ATTR === "function") {
921
+ EXTRA_ELEMENT_HANDLING.attributeCheck = cfg.ADD_ATTR;
922
+ } else if (arrayIsArray(cfg.ADD_ATTR)) {
923
+ if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {
924
+ ALLOWED_ATTR = clone(ALLOWED_ATTR);
925
+ }
926
+ addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
927
+ }
928
+ }
929
+ if (objectHasOwnProperty(cfg, "ADD_FORBID_CONTENTS") && arrayIsArray(cfg.ADD_FORBID_CONTENTS)) {
930
+ if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
931
+ FORBID_CONTENTS = clone(FORBID_CONTENTS);
932
+ }
933
+ addToSet(FORBID_CONTENTS, cfg.ADD_FORBID_CONTENTS, transformCaseFunc);
934
+ }
935
+ if (KEEP_CONTENT) {
936
+ ALLOWED_TAGS["#text"] = true;
937
+ }
938
+ if (WHOLE_DOCUMENT) {
939
+ addToSet(ALLOWED_TAGS, ["html", "head", "body"]);
940
+ }
941
+ if (ALLOWED_TAGS.table) {
942
+ addToSet(ALLOWED_TAGS, ["tbody"]);
943
+ delete FORBID_TAGS.tbody;
944
+ }
945
+ if (cfg.TRUSTED_TYPES_POLICY) {
946
+ if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== "function") {
947
+ throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');
948
+ }
949
+ if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== "function") {
950
+ throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');
951
+ }
952
+ const previousTrustedTypesPolicy = trustedTypesPolicy;
953
+ trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY;
954
+ try {
955
+ emptyHTML = _createTrustedHTML("");
956
+ } catch (error) {
957
+ trustedTypesPolicy = previousTrustedTypesPolicy;
958
+ throw error;
959
+ }
960
+ } else if (cfg.TRUSTED_TYPES_POLICY === null) {
961
+ trustedTypesPolicy = void 0;
962
+ emptyHTML = "";
963
+ } else {
964
+ if (trustedTypesPolicy === void 0) {
965
+ trustedTypesPolicy = _getDefaultTrustedTypesPolicy();
966
+ }
967
+ if (trustedTypesPolicy && typeof emptyHTML === "string") {
968
+ emptyHTML = _createTrustedHTML("");
969
+ }
970
+ }
971
+ if (freeze) {
972
+ freeze(cfg);
973
+ }
974
+ CONFIG = cfg;
975
+ };
976
+ const ALL_SVG_TAGS = addToSet({}, [...svg$1, ...svgFilters, ...svgDisallowed]);
977
+ const ALL_MATHML_TAGS = addToSet({}, [...mathMl$1, ...mathMlDisallowed]);
978
+ const _checkSvgNamespace = function _checkSvgNamespace2(tagName, parent, parentTagName) {
979
+ if (parent.namespaceURI === HTML_NAMESPACE) {
980
+ return tagName === "svg";
981
+ }
982
+ if (parent.namespaceURI === MATHML_NAMESPACE) {
983
+ return tagName === "svg" && (parentTagName === "annotation-xml" || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
984
+ }
985
+ return Boolean(ALL_SVG_TAGS[tagName]);
986
+ };
987
+ const _checkMathMlNamespace = function _checkMathMlNamespace2(tagName, parent, parentTagName) {
988
+ if (parent.namespaceURI === HTML_NAMESPACE) {
989
+ return tagName === "math";
990
+ }
991
+ if (parent.namespaceURI === SVG_NAMESPACE) {
992
+ return tagName === "math" && HTML_INTEGRATION_POINTS[parentTagName];
993
+ }
994
+ return Boolean(ALL_MATHML_TAGS[tagName]);
995
+ };
996
+ const _checkHtmlNamespace = function _checkHtmlNamespace2(tagName, parent, parentTagName) {
997
+ if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
998
+ return false;
999
+ }
1000
+ if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
1001
+ return false;
1002
+ }
1003
+ return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
1004
+ };
1005
+ const _checkValidNamespace = function _checkValidNamespace2(element) {
1006
+ let parent = getParentNode(element);
1007
+ if (!parent || !parent.tagName) {
1008
+ parent = {
1009
+ namespaceURI: NAMESPACE,
1010
+ tagName: "template"
1011
+ };
1012
+ }
1013
+ const tagName = stringToLowerCase(element.tagName);
1014
+ const parentTagName = stringToLowerCase(parent.tagName);
1015
+ if (!ALLOWED_NAMESPACES[element.namespaceURI]) {
1016
+ return false;
1017
+ }
1018
+ if (element.namespaceURI === SVG_NAMESPACE) {
1019
+ return _checkSvgNamespace(tagName, parent, parentTagName);
1020
+ }
1021
+ if (element.namespaceURI === MATHML_NAMESPACE) {
1022
+ return _checkMathMlNamespace(tagName, parent, parentTagName);
1023
+ }
1024
+ if (element.namespaceURI === HTML_NAMESPACE) {
1025
+ return _checkHtmlNamespace(tagName, parent, parentTagName);
1026
+ }
1027
+ if (PARSER_MEDIA_TYPE === "application/xhtml+xml" && ALLOWED_NAMESPACES[element.namespaceURI]) {
1028
+ return true;
1029
+ }
1030
+ return false;
1031
+ };
1032
+ const _forceRemove = function _forceRemove2(node) {
1033
+ arrayPush(DOMPurify.removed, {
1034
+ element: node
1035
+ });
1036
+ try {
1037
+ getParentNode(node).removeChild(node);
1038
+ } catch (_2) {
1039
+ remove(node);
1040
+ if (!getParentNode(node)) {
1041
+ throw typeErrorCreate("a node selected for removal could not be detached from its tree and cannot be safely returned; refusing to sanitize in place");
1042
+ }
1043
+ }
1044
+ };
1045
+ const _stripAttributeNode = function _stripAttributeNode2(element, attribute, name) {
1046
+ try {
1047
+ element.removeAttributeNode(attribute);
1048
+ } catch (_2) {
1049
+ try {
1050
+ element.removeAttribute(name);
1051
+ } catch (_3) {
1052
+ }
1053
+ }
1054
+ };
1055
+ const _neutralizeRoot = function _neutralizeRoot2(root) {
1056
+ _neutralizeSubtree(root);
1057
+ const childNodes = getChildNodes(root);
1058
+ if (childNodes) {
1059
+ const snapshot = [];
1060
+ arrayForEach(childNodes, (child) => {
1061
+ arrayPush(snapshot, child);
1062
+ });
1063
+ arrayForEach(snapshot, (child) => {
1064
+ try {
1065
+ remove(child);
1066
+ } catch (_2) {
1067
+ }
1068
+ });
1069
+ }
1070
+ const attributes = getAttributes(root);
1071
+ if (attributes) {
1072
+ for (let i = attributes.length - 1; i >= 0; --i) {
1073
+ const attribute = attributes[i];
1074
+ const name = attribute && attribute.name;
1075
+ if (typeof name === "string") {
1076
+ _stripAttributeNode(root, attribute, name);
1077
+ }
1078
+ }
1079
+ }
1080
+ };
1081
+ const _removeAttribute = function _removeAttribute2(name, element, attr) {
1082
+ if (!attr) {
1083
+ try {
1084
+ attr = element.getAttributeNode(name);
1085
+ } catch (_2) {
1086
+ attr = null;
1087
+ }
1088
+ }
1089
+ arrayPush(DOMPurify.removed, {
1090
+ attribute: attr || null,
1091
+ from: element
1092
+ });
1093
+ try {
1094
+ if (attr) {
1095
+ element.removeAttributeNode(attr);
1096
+ } else {
1097
+ element.removeAttribute(name);
1098
+ }
1099
+ } catch (_2) {
1100
+ try {
1101
+ element.removeAttribute(name);
1102
+ } catch (_3) {
1103
+ }
1104
+ }
1105
+ if (name === "is") {
1106
+ if (RETURN_DOM || RETURN_DOM_FRAGMENT) {
1107
+ try {
1108
+ _forceRemove(element);
1109
+ } catch (_2) {
1110
+ }
1111
+ } else {
1112
+ try {
1113
+ element.setAttribute(name, "");
1114
+ } catch (_2) {
1115
+ }
1116
+ }
1117
+ }
1118
+ };
1119
+ const _stripDisallowedAttributes = function _stripDisallowedAttributes2(element) {
1120
+ const attributes = getAttributes(element);
1121
+ if (!attributes) {
1122
+ return;
1123
+ }
1124
+ for (let i = attributes.length - 1; i >= 0; --i) {
1125
+ const attribute = attributes[i];
1126
+ const name = attribute && attribute.name;
1127
+ if (typeof name !== "string" || ALLOWED_ATTR[transformCaseFunc(name)]) {
1128
+ continue;
1129
+ }
1130
+ _stripAttributeNode(element, attribute, name);
1131
+ }
1132
+ };
1133
+ const _neutralizeSubtree = function _neutralizeSubtree2(root) {
1134
+ const stack = [root];
1135
+ while (stack.length > 0) {
1136
+ const node = stack.pop();
1137
+ const nodeType = _readNodeType(node);
1138
+ if (nodeType === NODE_TYPE.element) {
1139
+ _stripDisallowedAttributes(node);
1140
+ }
1141
+ const childNodes = getChildNodes(node);
1142
+ if (childNodes) {
1143
+ for (let i = childNodes.length - 1; i >= 0; --i) {
1144
+ stack.push(childNodes[i]);
1145
+ }
1146
+ }
1147
+ }
1148
+ };
1149
+ const _isPatchLinkageAttribute = function _isPatchLinkageAttribute2(lcName, lcTag) {
1150
+ if (!SAFE_FOR_XML) {
1151
+ return false;
1152
+ }
1153
+ if (lcName === "patchsrc") {
1154
+ return true;
1155
+ }
1156
+ return lcName === "for" && lcTag !== "label" && lcTag !== "output";
1157
+ };
1158
+ const _neutralizePatchLinkage = function _neutralizePatchLinkage2(root) {
1159
+ if (!SAFE_FOR_XML) {
1160
+ return;
1161
+ }
1162
+ const stack = [root];
1163
+ while (stack.length > 0) {
1164
+ const node = stack.pop();
1165
+ const nodeType = _readNodeType(node);
1166
+ if (nodeType === NODE_TYPE.processingInstruction || nodeType === NODE_TYPE.comment && regExpTest(COMMENT_MARKUP_PROBE, node.data)) {
1167
+ try {
1168
+ remove(node);
1169
+ } catch (_2) {
1170
+ }
1171
+ continue;
1172
+ }
1173
+ if (nodeType === NODE_TYPE.element) {
1174
+ const element = node;
1175
+ const lcTag = transformCaseFunc(_readNodeName(node));
1176
+ try {
1177
+ if (element.hasAttribute && element.hasAttribute("patchsrc")) {
1178
+ element.removeAttribute("patchsrc");
1179
+ }
1180
+ if (element.hasAttribute && element.hasAttribute("for") && _isPatchLinkageAttribute("for", lcTag)) {
1181
+ element.removeAttribute("for");
1182
+ }
1183
+ } catch (_2) {
1184
+ }
1185
+ }
1186
+ const childNodes = getChildNodes(node);
1187
+ if (childNodes) {
1188
+ for (let i = childNodes.length - 1; i >= 0; --i) {
1189
+ stack.push(childNodes[i]);
1190
+ }
1191
+ }
1192
+ }
1193
+ };
1194
+ const _initDocument = function _initDocument2(dirty) {
1195
+ let doc = null;
1196
+ let leadingWhitespace = null;
1197
+ if (FORCE_BODY) {
1198
+ dirty = "<remove></remove>" + dirty;
1199
+ } else {
1200
+ const matches = stringMatch(dirty, /^[\r\n\t ]+/);
1201
+ leadingWhitespace = matches && matches[0];
1202
+ }
1203
+ if (PARSER_MEDIA_TYPE === "application/xhtml+xml" && NAMESPACE === HTML_NAMESPACE) {
1204
+ dirty = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + dirty + "</body></html>";
1205
+ }
1206
+ const dirtyPayload = trustedTypesPolicy ? _createTrustedHTML(dirty) : dirty;
1207
+ if (NAMESPACE === HTML_NAMESPACE) {
1208
+ try {
1209
+ doc = new DOMParser().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);
1210
+ } catch (_2) {
1211
+ }
1212
+ }
1213
+ if (!doc || !doc.documentElement) {
1214
+ doc = implementation.createDocument(NAMESPACE, "template", null);
1215
+ try {
1216
+ doc.documentElement.innerHTML = IS_EMPTY_INPUT ? emptyHTML : dirtyPayload;
1217
+ } catch (_2) {
1218
+ }
1219
+ }
1220
+ const body = doc.body || doc.documentElement;
1221
+ if (dirty && leadingWhitespace) {
1222
+ body.insertBefore(document2.createTextNode(leadingWhitespace), body.childNodes[0] || null);
1223
+ }
1224
+ if (NAMESPACE === HTML_NAMESPACE) {
1225
+ return getElementsByTagName.call(doc, WHOLE_DOCUMENT ? "html" : "body")[0];
1226
+ }
1227
+ return WHOLE_DOCUMENT ? doc.documentElement : body;
1228
+ };
1229
+ const _createNodeIterator = function _createNodeIterator2(root) {
1230
+ const doc = getOwnerDocument ? getOwnerDocument(root) : root.ownerDocument;
1231
+ return createNodeIterator.call(
1232
+ doc || root,
1233
+ root,
1234
+ // eslint-disable-next-line no-bitwise
1235
+ NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION,
1236
+ null
1237
+ );
1238
+ };
1239
+ const _stripTemplateExpressions = function _stripTemplateExpressions2(value) {
1240
+ value = stringReplace(value, MUSTACHE_EXPR$1, " ");
1241
+ value = stringReplace(value, ERB_EXPR$1, " ");
1242
+ value = stringReplace(value, TMPLIT_EXPR$1, " ");
1243
+ return value;
1244
+ };
1245
+ const _scrubTemplateExpressions2 = function _scrubTemplateExpressions(node) {
1246
+ var _node$querySelectorAl;
1247
+ node.normalize();
1248
+ const doc = getOwnerDocument ? getOwnerDocument(node) : node.ownerDocument;
1249
+ const walker = createNodeIterator.call(
1250
+ doc || node,
1251
+ node,
1252
+ // eslint-disable-next-line no-bitwise
1253
+ NodeFilter.SHOW_TEXT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_CDATA_SECTION | NodeFilter.SHOW_PROCESSING_INSTRUCTION,
1254
+ null
1255
+ );
1256
+ let currentNode = walker.nextNode();
1257
+ while (currentNode) {
1258
+ currentNode.data = _stripTemplateExpressions(currentNode.data);
1259
+ currentNode = walker.nextNode();
1260
+ }
1261
+ const templates = (_node$querySelectorAl = node.querySelectorAll) === null || _node$querySelectorAl === void 0 ? void 0 : _node$querySelectorAl.call(node, "template");
1262
+ if (templates) {
1263
+ arrayForEach(templates, (tmpl) => {
1264
+ if (_isDocumentFragment(tmpl.content)) {
1265
+ _scrubTemplateExpressions2(tmpl.content);
1266
+ }
1267
+ });
1268
+ }
1269
+ };
1270
+ const _isClobbered = function _isClobbered2(element) {
1271
+ const realTagName = getNodeName ? getNodeName(element) : null;
1272
+ if (typeof realTagName !== "string") {
1273
+ return false;
1274
+ }
1275
+ if (transformCaseFunc(realTagName) !== "form") {
1276
+ return false;
1277
+ }
1278
+ return typeof element.nodeName !== "string" || typeof element.textContent !== "string" || typeof element.removeChild !== "function" || // Realm-safe NamedNodeMap detection: equality against the cached
1279
+ // prototype getter. Clobbered .attributes (e.g. <input name="attributes">)
1280
+ // makes the direct read diverge from the cached read; a clean form
1281
+ // (same-realm OR foreign-realm) has both reads pointing at the same
1282
+ // canonical NamedNodeMap.
1283
+ element.attributes !== getAttributes(element) || typeof element.removeAttribute !== "function" || typeof element.setAttribute !== "function" || typeof element.namespaceURI !== "string" || typeof element.insertBefore !== "function" || typeof element.hasChildNodes !== "function" || // NodeType clobbering probe. Cached Node.prototype.nodeType getter
1284
+ // returns the integer 1 for any Element regardless of realm; direct
1285
+ // read on a clobbered form (e.g. <input name="nodeType">) returns
1286
+ // the named child element. Cheap addition — nodeType is read from
1287
+ // an internal slot, no serialization cost — and removes a residual
1288
+ // clobbering surface used by several mXSS / PI / comment branches
1289
+ // in _sanitizeElements that compare currentNode.nodeType directly.
1290
+ element.nodeType !== getNodeType(element) || // HTMLFormElement has [LegacyOverrideBuiltIns]: a descendant named
1291
+ // "childNodes" shadows the prototype getter. Direct reads of
1292
+ // form.childNodes from a clobbered form return the named child
1293
+ // instead of the real NodeList, so any walk that reads it directly
1294
+ // skips the form's real children. Compare the direct read to the
1295
+ // cached Node.prototype getter — when the form's named-property
1296
+ // getter intercepts the read, the two values differ and we flag
1297
+ // the form. This catches every clobbering child type (input,
1298
+ // select, etc.) regardless of whether the named child happens to
1299
+ // carry a numeric .length, which a typeof-based probe would miss
1300
+ // (e.g. HTMLSelectElement.length is a defined unsigned-long).
1301
+ element.childNodes !== getChildNodes(element);
1302
+ };
1303
+ const _isDocumentFragment = function _isDocumentFragment2(value) {
1304
+ if (!getNodeType || typeof value !== "object" || value === null) {
1305
+ return false;
1306
+ }
1307
+ try {
1308
+ return getNodeType(value) === NODE_TYPE.documentFragment;
1309
+ } catch (_2) {
1310
+ return false;
1311
+ }
1312
+ };
1313
+ const _isNode = function _isNode2(value) {
1314
+ if (!getNodeType || typeof value !== "object" || value === null) {
1315
+ return false;
1316
+ }
1317
+ try {
1318
+ return typeof getNodeType(value) === "number";
1319
+ } catch (_2) {
1320
+ return false;
1321
+ }
1322
+ };
1323
+ function _executeHooks(hooks2, currentNode, data) {
1324
+ if (hooks2.length === 0) {
1325
+ return;
1326
+ }
1327
+ arrayForEach(hooks2, (hook) => {
1328
+ hook.call(DOMPurify, currentNode, data, CONFIG);
1329
+ });
1330
+ }
1331
+ const _isUnsafeNode = function _isUnsafeNode2(currentNode, tagName) {
1332
+ if (SAFE_FOR_XML && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.textContent) && regExpTest(ELEMENT_MARKUP_PROBE, currentNode.innerHTML)) {
1333
+ return true;
1334
+ }
1335
+ if (SAFE_FOR_XML && currentNode.namespaceURI === HTML_NAMESPACE && LITERAL_TEXT_ELEMENTS[tagName] && (_isNode(currentNode.firstElementChild) || typeof currentNode.textContent === "string" && regExpTest(LITERAL_TEXT_CLOSE[tagName], currentNode.textContent))) {
1336
+ return true;
1337
+ }
1338
+ if (currentNode.nodeType === NODE_TYPE.processingInstruction) {
1339
+ return true;
1340
+ }
1341
+ if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(COMMENT_MARKUP_PROBE, currentNode.data)) {
1342
+ return true;
1343
+ }
1344
+ return false;
1345
+ };
1346
+ const _matchesNameCheck = function _matchesNameCheck2(check, name) {
1347
+ if (check instanceof RegExp) {
1348
+ return regExpTest(check, name);
1349
+ }
1350
+ if (check instanceof Function) {
1351
+ for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
1352
+ args[_key - 2] = arguments[_key];
1353
+ }
1354
+ return Boolean(check(name, ...args));
1355
+ }
1356
+ return false;
1357
+ };
1358
+ const _sanitizeDisallowedNode = function _sanitizeDisallowedNode2(currentNode, tagName, root) {
1359
+ if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName) && _matchesNameCheck(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
1360
+ return false;
1361
+ }
1362
+ if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
1363
+ const parentNode = getParentNode(currentNode);
1364
+ const childNodes = getChildNodes(currentNode);
1365
+ if (childNodes && parentNode) {
1366
+ const childCount = childNodes.length;
1367
+ for (let i = childCount - 1; i >= 0; --i) {
1368
+ const hoisted = currentNode === root ? cloneNode(childNodes[i], true) : childNodes[i];
1369
+ parentNode.insertBefore(hoisted, getNextSibling(currentNode));
1370
+ }
1371
+ }
1372
+ }
1373
+ _forceRemove(currentNode);
1374
+ return true;
1375
+ };
1376
+ const _forkSharedAllowlist = function _forkSharedAllowlist2(hookList, set, defaultSet, setConfigSet) {
1377
+ if (hookList.length === 0) {
1378
+ return set;
1379
+ }
1380
+ return set === defaultSet || set === setConfigSet ? clone(set) : set;
1381
+ };
1382
+ const _handleHookDetachedNode = function _handleHookDetachedNode2(currentNode, root) {
1383
+ if (currentNode === root || getParentNode(currentNode) !== null) {
1384
+ return false;
1385
+ }
1386
+ if (IN_PLACE) {
1387
+ _neutralizeSubtree(currentNode);
1388
+ }
1389
+ return true;
1390
+ };
1391
+ const _sanitizeElements = function _sanitizeElements2(currentNode, root) {
1392
+ _executeHooks(hooks.beforeSanitizeElements, currentNode, null);
1393
+ if (_handleHookDetachedNode(currentNode, root)) {
1394
+ return true;
1395
+ }
1396
+ if (_isClobbered(currentNode)) {
1397
+ _forceRemove(currentNode);
1398
+ return true;
1399
+ }
1400
+ const tagName = transformCaseFunc(_readNodeName(currentNode));
1401
+ ALLOWED_TAGS = _forkSharedAllowlist(hooks.uponSanitizeElement, ALLOWED_TAGS, DEFAULT_ALLOWED_TAGS, SET_CONFIG_ALLOWED_TAGS);
1402
+ _executeHooks(hooks.uponSanitizeElement, currentNode, {
1403
+ tagName,
1404
+ allowedTags: ALLOWED_TAGS
1405
+ });
1406
+ if (_handleHookDetachedNode(currentNode, root)) {
1407
+ return true;
1408
+ }
1409
+ if (_isUnsafeNode(currentNode, tagName)) {
1410
+ _forceRemove(currentNode);
1411
+ return true;
1412
+ }
1413
+ if (FORBID_TAGS[tagName] || !(EXTRA_ELEMENT_HANDLING.tagCheck instanceof Function && EXTRA_ELEMENT_HANDLING.tagCheck(tagName)) && !ALLOWED_TAGS[tagName]) {
1414
+ const removed = _sanitizeDisallowedNode(currentNode, tagName, root);
1415
+ if (removed === false) {
1416
+ _executeHooks(hooks.afterSanitizeElements, currentNode, null);
1417
+ }
1418
+ return removed;
1419
+ }
1420
+ const nt2 = _readNodeType(currentNode);
1421
+ if (nt2 === NODE_TYPE.element && !_checkValidNamespace(currentNode)) {
1422
+ _forceRemove(currentNode);
1423
+ return true;
1424
+ }
1425
+ if ((tagName === "noscript" || tagName === "noembed" || tagName === "noframes") && regExpTest(FALLBACK_TAG_CLOSE, currentNode.innerHTML)) {
1426
+ _forceRemove(currentNode);
1427
+ return true;
1428
+ }
1429
+ if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {
1430
+ const content = _stripTemplateExpressions(currentNode.textContent);
1431
+ if (currentNode.textContent !== content) {
1432
+ arrayPush(DOMPurify.removed, {
1433
+ element: currentNode.cloneNode()
1434
+ });
1435
+ currentNode.textContent = content;
1436
+ }
1437
+ }
1438
+ _executeHooks(hooks.afterSanitizeElements, currentNode, null);
1439
+ return false;
1440
+ };
1441
+ const _isValidAttribute = function _isValidAttribute2(lcTag, lcName, value) {
1442
+ if (FORBID_ATTR[lcName]) {
1443
+ return false;
1444
+ }
1445
+ if (_isPatchLinkageAttribute(lcName, lcTag)) {
1446
+ return false;
1447
+ }
1448
+ if (SANITIZE_DOM && (lcName === "id" || lcName === "name") && (value in document2 || value in formElement)) {
1449
+ return false;
1450
+ }
1451
+ const nameIsPermitted = ALLOWED_ATTR[lcName] || EXTRA_ELEMENT_HANDLING.attributeCheck instanceof Function && EXTRA_ELEMENT_HANDLING.attributeCheck(lcName, lcTag);
1452
+ if (ALLOW_DATA_ATTR && regExpTest(DATA_ATTR$1, lcName)) {
1453
+ return true;
1454
+ }
1455
+ if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR$1, lcName)) {
1456
+ return true;
1457
+ }
1458
+ if (!nameIsPermitted) {
1459
+ return (
1460
+ // Condition a) covers a basically valid custom element tag name whose
1461
+ // tag passes the configured tagNameCheck and whose attribute name
1462
+ // passes the configured attributeNameCheck ...
1463
+ _isBasicCustomElement(lcTag) && _matchesNameCheck(CUSTOM_ELEMENT_HANDLING.tagNameCheck, lcTag) && _matchesNameCheck(CUSTOM_ELEMENT_HANDLING.attributeNameCheck, lcName, lcTag) || // Condition b) covers an `is` attribute whose value passes the
1464
+ // configured tagNameCheck while customized built-in elements are
1465
+ // allowed.
1466
+ lcName === "is" && CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements && _matchesNameCheck(CUSTOM_ELEMENT_HANDLING.tagNameCheck, value)
1467
+ );
1468
+ }
1469
+ if (URI_SAFE_ATTRIBUTES[lcName]) {
1470
+ return true;
1471
+ }
1472
+ if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value, ATTR_WHITESPACE$1, ""))) {
1473
+ return true;
1474
+ }
1475
+ if ((lcName === "src" || lcName === "xlink:href" || lcName === "href") && lcTag !== "script" && stringIndexOf(value, "data:") === 0 && DATA_URI_TAGS[lcTag]) {
1476
+ return true;
1477
+ }
1478
+ if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA$1, stringReplace(value, ATTR_WHITESPACE$1, ""))) {
1479
+ return true;
1480
+ }
1481
+ return !value;
1482
+ };
1483
+ const RESERVED_CUSTOM_ELEMENT_NAMES = addToSet({}, ["annotation-xml", "color-profile", "font-face", "font-face-format", "font-face-name", "font-face-src", "font-face-uri", "missing-glyph"]);
1484
+ const _isBasicCustomElement = function _isBasicCustomElement2(tagName) {
1485
+ return !RESERVED_CUSTOM_ELEMENT_NAMES[stringToLowerCase(tagName)] && regExpTest(CUSTOM_ELEMENT$1, tagName);
1486
+ };
1487
+ const _applyTrustedTypesToAttribute = function _applyTrustedTypesToAttribute2(lcTag, lcName, namespaceURI, value) {
1488
+ if (trustedTypesPolicy && typeof trustedTypes === "object" && typeof trustedTypes.getAttributeType === "function" && !namespaceURI) {
1489
+ switch (trustedTypes.getAttributeType(lcTag, lcName)) {
1490
+ case "TrustedHTML": {
1491
+ return _createTrustedHTML(value);
1492
+ }
1493
+ case "TrustedScriptURL": {
1494
+ return _createTrustedScriptURL(value);
1495
+ }
1496
+ }
1497
+ }
1498
+ return value;
1499
+ };
1500
+ const _setAttributeValue = function _setAttributeValue2(currentNode, name, namespaceURI, value) {
1501
+ try {
1502
+ if (namespaceURI) {
1503
+ currentNode.setAttributeNS(namespaceURI, name, value);
1504
+ } else {
1505
+ currentNode.setAttribute(name, value);
1506
+ }
1507
+ if (_isClobbered(currentNode)) {
1508
+ _forceRemove(currentNode);
1509
+ } else {
1510
+ arrayPop(DOMPurify.removed);
1511
+ }
1512
+ } catch (_2) {
1513
+ _removeAttribute(name, currentNode);
1514
+ }
1515
+ };
1516
+ const _sanitizeAttributes = function _sanitizeAttributes2(currentNode) {
1517
+ _executeHooks(hooks.beforeSanitizeAttributes, currentNode, null);
1518
+ const attributes = currentNode.attributes;
1519
+ if (!attributes || _isClobbered(currentNode)) {
1520
+ return;
1521
+ }
1522
+ ALLOWED_ATTR = _forkSharedAllowlist(hooks.uponSanitizeAttribute, ALLOWED_ATTR, DEFAULT_ALLOWED_ATTR, SET_CONFIG_ALLOWED_ATTR);
1523
+ const hookEvent = {
1524
+ attrName: "",
1525
+ attrValue: "",
1526
+ keepAttr: true,
1527
+ allowedAttributes: ALLOWED_ATTR,
1528
+ forceKeepAttr: void 0
1529
+ };
1530
+ let l3 = attributes.length;
1531
+ const lcTag = transformCaseFunc(currentNode.nodeName);
1532
+ while (l3--) {
1533
+ const attr = attributes[l3];
1534
+ const name = attr.name, namespaceURI = attr.namespaceURI, attrValue = attr.value;
1535
+ const lcName = transformCaseFunc(name);
1536
+ const initValue = attrValue;
1537
+ let value = name === "value" ? initValue : stringTrim(initValue);
1538
+ hookEvent.attrName = lcName;
1539
+ hookEvent.attrValue = value;
1540
+ hookEvent.keepAttr = true;
1541
+ hookEvent.forceKeepAttr = void 0;
1542
+ _executeHooks(hooks.uponSanitizeAttribute, currentNode, hookEvent);
1543
+ value = hookEvent.attrValue;
1544
+ if (SANITIZE_NAMED_PROPS && (lcName === "id" || lcName === "name") && stringIndexOf(value, SANITIZE_NAMED_PROPS_PREFIX) !== 0) {
1545
+ _removeAttribute(name, currentNode, attr);
1546
+ value = SANITIZE_NAMED_PROPS_PREFIX + value;
1547
+ }
1548
+ if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i, value)) {
1549
+ _removeAttribute(name, currentNode, attr);
1550
+ continue;
1551
+ }
1552
+ if (lcName === "attributename" && stringMatch(value, "href")) {
1553
+ _removeAttribute(name, currentNode, attr);
1554
+ continue;
1555
+ }
1556
+ if (hookEvent.forceKeepAttr) {
1557
+ continue;
1558
+ }
1559
+ if (!hookEvent.keepAttr) {
1560
+ _removeAttribute(name, currentNode, attr);
1561
+ continue;
1562
+ }
1563
+ if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(SELF_CLOSING_TAG, value)) {
1564
+ _removeAttribute(name, currentNode, attr);
1565
+ continue;
1566
+ }
1567
+ if (SAFE_FOR_TEMPLATES) {
1568
+ value = _stripTemplateExpressions(value);
1569
+ }
1570
+ if (!_isValidAttribute(lcTag, lcName, value)) {
1571
+ _removeAttribute(name, currentNode, attr);
1572
+ continue;
1573
+ }
1574
+ value = _applyTrustedTypesToAttribute(lcTag, lcName, namespaceURI, value);
1575
+ if (value !== initValue) {
1576
+ _setAttributeValue(currentNode, name, namespaceURI, value);
1577
+ }
1578
+ }
1579
+ _executeHooks(hooks.afterSanitizeAttributes, currentNode, null);
1580
+ };
1581
+ const _sanitizeShadowDOM2 = function _sanitizeShadowDOM(fragment) {
1582
+ let shadowNode = null;
1583
+ const shadowIterator = _createNodeIterator(fragment);
1584
+ _executeHooks(hooks.beforeSanitizeShadowDOM, fragment, null);
1585
+ while (shadowNode = shadowIterator.nextNode()) {
1586
+ _executeHooks(hooks.uponSanitizeShadowNode, shadowNode, null);
1587
+ _sanitizeElements(shadowNode, fragment);
1588
+ _sanitizeAttributes(shadowNode);
1589
+ if (_isDocumentFragment(shadowNode.content)) {
1590
+ _sanitizeShadowDOM2(shadowNode.content);
1591
+ }
1592
+ if (_readNodeType(shadowNode) === NODE_TYPE.element) {
1593
+ const innerSr = getShadowRoot(shadowNode);
1594
+ if (_isDocumentFragment(innerSr)) {
1595
+ _sanitizeAttachedShadowRoots(innerSr);
1596
+ _sanitizeShadowDOM2(innerSr);
1597
+ }
1598
+ }
1599
+ }
1600
+ _executeHooks(hooks.afterSanitizeShadowDOM, fragment, null);
1601
+ };
1602
+ const _sanitizeAttachedShadowRoots = function _sanitizeAttachedShadowRoots2(root) {
1603
+ const stack = [{
1604
+ node: root,
1605
+ shadow: null
1606
+ }];
1607
+ while (stack.length > 0) {
1608
+ const item = stack.pop();
1609
+ if (item.shadow) {
1610
+ _sanitizeShadowDOM2(item.shadow);
1611
+ continue;
1612
+ }
1613
+ const node = item.node;
1614
+ const nodeType = _readNodeType(node);
1615
+ const isElement = nodeType === NODE_TYPE.element;
1616
+ const childNodes = getChildNodes(node);
1617
+ if (childNodes) {
1618
+ for (let i = childNodes.length - 1; i >= 0; --i) {
1619
+ stack.push({
1620
+ node: childNodes[i],
1621
+ shadow: null
1622
+ });
1623
+ }
1624
+ }
1625
+ if (isElement) {
1626
+ const rootName = getNodeName ? getNodeName(node) : null;
1627
+ if (typeof rootName === "string" && transformCaseFunc(rootName) === "template") {
1628
+ const content = node.content;
1629
+ if (_isDocumentFragment(content)) {
1630
+ stack.push({
1631
+ node: content,
1632
+ shadow: null
1633
+ });
1634
+ }
1635
+ }
1636
+ }
1637
+ if (isElement) {
1638
+ const sr = getShadowRoot(node);
1639
+ if (_isDocumentFragment(sr)) {
1640
+ stack.push({
1641
+ node: null,
1642
+ shadow: sr
1643
+ }, {
1644
+ node: sr,
1645
+ shadow: null
1646
+ });
1647
+ }
1648
+ }
1649
+ }
1650
+ };
1651
+ DOMPurify.sanitize = function(dirty) {
1652
+ let cfg = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1653
+ let body = null;
1654
+ let importedNode = null;
1655
+ let currentNode = null;
1656
+ let returnNode = null;
1657
+ IS_EMPTY_INPUT = !dirty;
1658
+ if (IS_EMPTY_INPUT) {
1659
+ dirty = "<!-->";
1660
+ }
1661
+ if (typeof dirty !== "string" && !_isNode(dirty)) {
1662
+ dirty = stringifyValue(dirty);
1663
+ if (typeof dirty !== "string") {
1664
+ throw typeErrorCreate("dirty is not a string, aborting");
1665
+ }
1666
+ }
1667
+ if (!DOMPurify.isSupported) {
1668
+ return dirty;
1669
+ }
1670
+ if (SET_CONFIG) {
1671
+ ALLOWED_TAGS = SET_CONFIG_ALLOWED_TAGS;
1672
+ ALLOWED_ATTR = SET_CONFIG_ALLOWED_ATTR;
1673
+ } else {
1674
+ _parseConfig(cfg);
1675
+ }
1676
+ if (hooks.uponSanitizeElement.length > 0 || hooks.uponSanitizeAttribute.length > 0) {
1677
+ ALLOWED_TAGS = clone(ALLOWED_TAGS);
1678
+ }
1679
+ if (hooks.uponSanitizeAttribute.length > 0) {
1680
+ ALLOWED_ATTR = clone(ALLOWED_ATTR);
1681
+ }
1682
+ DOMPurify.removed = [];
1683
+ const inPlace = IN_PLACE && typeof dirty !== "string" && _isNode(dirty);
1684
+ if (inPlace) {
1685
+ _neutralizePatchLinkage(dirty);
1686
+ const nn2 = _readNodeName(dirty);
1687
+ if (typeof nn2 === "string") {
1688
+ const tagName = transformCaseFunc(nn2);
1689
+ if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
1690
+ _neutralizeRoot(dirty);
1691
+ throw typeErrorCreate("root node is forbidden and cannot be sanitized in-place");
1692
+ }
1693
+ }
1694
+ if (_isClobbered(dirty)) {
1695
+ _neutralizeRoot(dirty);
1696
+ throw typeErrorCreate("root node is clobbered and cannot be sanitized in-place");
1697
+ }
1698
+ try {
1699
+ _sanitizeAttachedShadowRoots(dirty);
1700
+ } catch (error) {
1701
+ _neutralizeRoot(dirty);
1702
+ throw error;
1703
+ }
1704
+ } else if (_isNode(dirty)) {
1705
+ body = _initDocument("<!---->");
1706
+ importedNode = body.ownerDocument.importNode(dirty, true);
1707
+ if (importedNode.nodeType === NODE_TYPE.element && importedNode.nodeName === "BODY") {
1708
+ body = importedNode;
1709
+ } else if (importedNode.nodeName === "HTML") {
1710
+ body = importedNode;
1711
+ } else {
1712
+ body.appendChild(importedNode);
1713
+ }
1714
+ _sanitizeAttachedShadowRoots(importedNode);
1715
+ } else {
1716
+ if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT && // eslint-disable-next-line unicorn/prefer-includes
1717
+ dirty.indexOf("<") === -1) {
1718
+ return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? _createTrustedHTML(dirty) : dirty;
1719
+ }
1720
+ body = _initDocument(dirty);
1721
+ if (!body) {
1722
+ return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : "";
1723
+ }
1724
+ }
1725
+ if (body && FORCE_BODY) {
1726
+ _forceRemove(body.firstChild);
1727
+ }
1728
+ const walkRoot = inPlace ? dirty : body;
1729
+ try {
1730
+ const nodeIterator = _createNodeIterator(walkRoot);
1731
+ while (currentNode = nodeIterator.nextNode()) {
1732
+ _sanitizeElements(currentNode, walkRoot);
1733
+ _sanitizeAttributes(currentNode);
1734
+ if (_isDocumentFragment(currentNode.content)) {
1735
+ _sanitizeShadowDOM2(currentNode.content);
1736
+ }
1737
+ }
1738
+ } catch (error) {
1739
+ if (inPlace) {
1740
+ _neutralizeRoot(dirty);
1741
+ arrayForEach(DOMPurify.removed, (entry) => {
1742
+ if (entry.element) {
1743
+ _neutralizeSubtree(entry.element);
1744
+ }
1745
+ });
1746
+ }
1747
+ throw error;
1748
+ }
1749
+ if (inPlace) {
1750
+ arrayForEach(DOMPurify.removed, (entry) => {
1751
+ if (entry.element) {
1752
+ _neutralizeSubtree(entry.element);
1753
+ }
1754
+ });
1755
+ if (SAFE_FOR_TEMPLATES) {
1756
+ _scrubTemplateExpressions2(dirty);
1757
+ }
1758
+ return dirty;
1759
+ }
1760
+ if (RETURN_DOM) {
1761
+ if (SAFE_FOR_TEMPLATES) {
1762
+ _scrubTemplateExpressions2(body);
1763
+ }
1764
+ if (RETURN_DOM_FRAGMENT) {
1765
+ returnNode = createDocumentFragment.call(body.ownerDocument);
1766
+ while (body.firstChild) {
1767
+ returnNode.appendChild(body.firstChild);
1768
+ }
1769
+ } else {
1770
+ returnNode = body;
1771
+ }
1772
+ if (ALLOWED_ATTR.shadowroot || ALLOWED_ATTR.shadowrootmode) {
1773
+ returnNode = importNode.call(originalDocument, returnNode, true);
1774
+ }
1775
+ return returnNode;
1776
+ }
1777
+ let serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
1778
+ if (WHOLE_DOCUMENT && ALLOWED_TAGS["!doctype"] && body.ownerDocument && body.ownerDocument.doctype && body.ownerDocument.doctype.name && regExpTest(DOCTYPE_NAME, body.ownerDocument.doctype.name)) {
1779
+ serializedHTML = "<!DOCTYPE " + body.ownerDocument.doctype.name + ">\n" + serializedHTML;
1780
+ }
1781
+ if (SAFE_FOR_TEMPLATES) {
1782
+ serializedHTML = _stripTemplateExpressions(serializedHTML);
1783
+ }
1784
+ return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? _createTrustedHTML(serializedHTML) : serializedHTML;
1785
+ };
1786
+ DOMPurify.setConfig = function() {
1787
+ let cfg = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
1788
+ _parseConfig(cfg);
1789
+ SET_CONFIG = true;
1790
+ SET_CONFIG_ALLOWED_TAGS = ALLOWED_TAGS;
1791
+ SET_CONFIG_ALLOWED_ATTR = ALLOWED_ATTR;
1792
+ };
1793
+ DOMPurify.clearConfig = function() {
1794
+ CONFIG = null;
1795
+ SET_CONFIG = false;
1796
+ SET_CONFIG_ALLOWED_TAGS = null;
1797
+ SET_CONFIG_ALLOWED_ATTR = null;
1798
+ trustedTypesPolicy = defaultTrustedTypesPolicy;
1799
+ emptyHTML = "";
1800
+ };
1801
+ DOMPurify.isValidAttribute = function(tag, attr, value) {
1802
+ if (!CONFIG) {
1803
+ _parseConfig({});
1804
+ }
1805
+ const lcTag = transformCaseFunc(tag);
1806
+ const lcName = transformCaseFunc(attr);
1807
+ return _isValidAttribute(lcTag, lcName, value);
1808
+ };
1809
+ DOMPurify.addHook = function(entryPoint, hookFunction) {
1810
+ if (typeof hookFunction !== "function") {
1811
+ return;
1812
+ }
1813
+ if (!objectHasOwnProperty(hooks, entryPoint)) {
1814
+ return;
1815
+ }
1816
+ arrayPush(hooks[entryPoint], hookFunction);
1817
+ };
1818
+ DOMPurify.removeHook = function(entryPoint, hookFunction) {
1819
+ if (!objectHasOwnProperty(hooks, entryPoint)) {
1820
+ return void 0;
1821
+ }
1822
+ if (hookFunction !== void 0) {
1823
+ const index = arrayLastIndexOf(hooks[entryPoint], hookFunction);
1824
+ return index === -1 ? void 0 : arraySplice(hooks[entryPoint], index, 1)[0];
1825
+ }
1826
+ return arrayPop(hooks[entryPoint]);
1827
+ };
1828
+ DOMPurify.removeHooks = function(entryPoint) {
1829
+ if (!objectHasOwnProperty(hooks, entryPoint)) {
1830
+ return;
1831
+ }
1832
+ hooks[entryPoint] = [];
1833
+ };
1834
+ DOMPurify.removeAllHooks = function() {
1835
+ hooks = _createHooksMap();
1836
+ };
1837
+ return DOMPurify;
1838
+ }
1839
+ var purify = createDOMPurify();
1840
+
1841
+ // node_modules/marked/lib/marked.esm.js
1842
+ function C() {
1843
+ return { async: false, breaks: false, extensions: null, gfm: true, hooks: null, pedantic: false, renderer: null, silent: false, tokenizer: null, walkTokens: null };
1844
+ }
1845
+ var R = C();
1846
+ function j(l3) {
1847
+ R = l3;
1848
+ }
1849
+ var z = { exec: () => null };
1850
+ function A(l3) {
1851
+ let e = [];
1852
+ return (t) => {
1853
+ let n = Math.max(0, Math.min(3, t - 1)), s = e[n];
1854
+ return s || (s = l3(n), e[n] = s), s;
1855
+ };
1856
+ }
1857
+ function d(l3, e = "") {
1858
+ let t = typeof l3 == "string" ? l3 : l3.source, n = { replace: (s, r) => {
1859
+ let i = typeof r == "string" ? r : r.source;
1860
+ return i = i.replace(m.caret, "$1"), t = t.replace(s, i), n;
1861
+ }, getRegex: () => new RegExp(t, e) };
1862
+ return n;
1863
+ }
1864
+ var Te = ((l3 = "") => {
1865
+ try {
1866
+ return !!new RegExp("(?<=1)(?<!1)" + l3);
1867
+ } catch {
1868
+ return false;
1869
+ }
1870
+ })();
1871
+ var m = { codeRemoveIndent: /^(?: {1,4}| {0,3}\t)/gm, outputLinkReplace: /\\([\[\]])/g, indentCodeCompensation: /^(\s+)(?:```)/, beginningSpace: /^\s+/, endingHash: /#$/, startingSpaceChar: /^ /, endingSpaceChar: / $/, nonSpaceChar: /[^ ]/, newLineCharGlobal: /\n/g, tabCharGlobal: /\t/g, multipleSpaceGlobal: /\s+/g, blankLine: /^[ \t]*$/, doubleBlankLine: /\n[ \t]*\n[ \t]*$/, blockquoteStart: /^ {0,3}>/, blockquoteSetextReplace: /\n {0,3}((?:=+|-+) *)(?=\n|$)/g, blockquoteSetextReplace2: /^ {0,3}>[ \t]?/gm, listReplaceNesting: /^ {1,4}(?=( {4})*[^ ])/g, listIsTask: /^\[[ xX]\] +\S/, listReplaceTask: /^\[[ xX]\] +/, listTaskCheckbox: /\[[ xX]\]/, anyLine: /\n.*\n/, hrefBrackets: /^<(.*)>$/, tableDelimiter: /[:|]/, tableAlignChars: /^\||\| *$/g, tableRowBlankLine: /\n[ \t]*$/, tableAlignRight: /^ *-+: *$/, tableAlignCenter: /^ *:-+: *$/, tableAlignLeft: /^ *:-+ *$/, startATag: /^<a /i, endATag: /^<\/a>/i, startPreScriptTag: /^<(pre|code|kbd|script)(\s|>)/i, endPreScriptTag: /^<\/(pre|code|kbd|script)(\s|>)/i, startAngleBracket: /^</, endAngleBracket: />$/, pedanticHrefTitle: /^([^'"]*[^\s])\s+(['"])(.*)\2/, unicodeAlphaNumeric: /[\p{L}\p{N}]/u, escapeTest: /[&<>"']/, escapeReplace: /[&<>"']/g, escapeTestNoEncode: /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/, escapeReplaceNoEncode: /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g, caret: /(^|[^\[])\^/g, percentDecode: /%25/g, findPipe: /\|/g, splitPipe: / \|/, slashPipe: /\\\|/g, carriageReturn: /\r\n|\r/g, spaceLine: /^ +$/gm, notSpaceStart: /^\S*/, endingNewline: /\n$/, listItemRegex: (l3) => new RegExp(`^( {0,3}${l3})((?:[ ][^\\n]*)?(?:\\n|$))`), nextBulletRegex: A((l3) => new RegExp(`^ {0,${l3}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`)), hrRegex: A((l3) => new RegExp(`^ {0,${l3}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`)), fencesBeginRegex: A((l3) => new RegExp(`^ {0,${l3}}(?:\`\`\`|~~~)`)), headingBeginRegex: A((l3) => new RegExp(`^ {0,${l3}}#`)), htmlBeginRegex: A((l3) => new RegExp(`^ {0,${l3}}<(?:[a-z].*>|!--)`, "i")), blockquoteBeginRegex: A((l3) => new RegExp(`^ {0,${l3}}>`)) };
1872
+ var Oe = /^(?:[ \t]*(?:\n|$))+/;
1873
+ var we = /^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/;
1874
+ var ye = /^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/;
1875
+ var q = /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/;
1876
+ var Pe = /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/;
1877
+ var U = / {0,3}(?:[*+-]|\d{1,9}[.)])/;
1878
+ var oe = /^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/;
1879
+ var ae = d(oe).replace(/bull/g, U).replace(/blockCode/g, /(?: {4}| {0,3}\t)/).replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g, / {0,3}>/).replace(/heading/g, / {0,3}#{1,6}(?:\s|$)/).replace(/html/g, / {0,3}<[^\n>]+>\n/).replace(/\|table/g, "").getRegex();
1880
+ var Se = d(oe).replace(/bull/g, U).replace(/blockCode/g, /(?: {4}| {0,3}\t)/).replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g, / {0,3}>/).replace(/heading/g, / {0,3}#{1,6}(?:\s|$)/).replace(/html/g, / {0,3}<[^\n>]+>\n/).replace(/table/g, / {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex();
1881
+ var K = /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table|[ \t]+\n)[^\n]+)*)/;
1882
+ var _e = /^[^\n]+/;
1883
+ var W = /(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/;
1884
+ var $e = d(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label", W).replace("title", /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex();
1885
+ var Le = d(/^(bull)([ \t][^\n]*?)?(?:\n|$)/).replace(/bull/g, U).getRegex();
1886
+ var Q = "address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul";
1887
+ var X = /<!--(?:-?>|[\s\S]*?(?:-->|$))/;
1888
+ var Me = d("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n*|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>[^\\n]*\\n*|$)|<![A-Z][\\s\\S]*?(?:>[^\\n]*\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>[^\\n]*\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))", "i").replace("comment", X).replace("tag", Q).replace("attribute", / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex();
1889
+ var le = (l3) => d(K).replace("hr", q).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("|lheading", "").replace("|table", "").replace("blockquote", " {0,3}>").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace("list", l3).replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", Q).getRegex();
1890
+ var ze = le(/ {0,3}(?:[*+-]|1[.)])[ \t]+[^ \t\n]/);
1891
+ var Ee = le(/ {0,3}(?:[*+-]|\d{1,9}[.)])(?:[ \t]|\n|$)/);
1892
+ var Ce = d(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph", Ee).getRegex();
1893
+ var J = { blockquote: Ce, code: we, def: $e, fences: ye, heading: Pe, hr: q, html: Me, lheading: ae, list: Le, newline: Oe, paragraph: ze, table: z, text: _e };
1894
+ var se = d("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr", q).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("blockquote", " {0,3}>").replace("code", "(?: {4}| {0,3} )[^\\n]").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace("list", " {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", Q).getRegex();
1895
+ var Ae = { ...J, lheading: Se, table: se, paragraph: d(K).replace("hr", q).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("|lheading", "").replace("table", se).replace("blockquote", " {0,3}>").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace("list", " {0,3}(?:[*+-]|1[.)])[ \\t]+[^ \\t\\n]").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", Q).getRegex() };
1896
+ var Ie = { ...J, html: d(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment", X).replace(/tag/g, "(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(), def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/, heading: /^(#{1,6})(.*)(?:\n+|$)/, fences: z, lheading: /^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/, paragraph: d(K).replace("hr", q).replace("heading", ` *#{1,6} *[^
1897
+ ]`).replace("lheading", ae).replace("|table", "").replace("blockquote", " {0,3}>").replace("|fences", "").replace("|list", "").replace("|html", "").replace("|tag", "").getRegex() };
1898
+ var Be = /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/;
1899
+ var De = /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/;
1900
+ var pe = /^( {2,}|\\)\n(?!\s*$)/;
1901
+ var qe = /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/;
1902
+ var _ = /[\p{P}\p{S}]/u;
1903
+ var I = /[\s\p{P}\p{S}]/u;
1904
+ var v = /[^\s\p{P}\p{S}]/u;
1905
+ var ve = d(/^((?![*_])punctSpace)/, "u").replace(/punctSpace/g, I).getRegex();
1906
+ var He = /[\p{Pi}\p{Ps}"']/u;
1907
+ var ue = /(?!~)[\p{P}\p{S}]/u;
1908
+ var Ze = /(?!~)[\s\p{P}\p{S}]/u;
1909
+ var Ge = /(?:[^\s\p{P}\p{S}]|~)/u;
1910
+ var Qe = d(/link|precode-code|html/, "g").replace("link", /\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-", Te ? "(?<!`)()" : "(^^|[^`])").replace("code", /(?<b>`+)[^`]+\k<b>(?!`)/).replace("html", /<(?! )[^<>]*?>/).getRegex();
1911
+ var ce = /^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/;
1912
+ var Ne = d(ce, "u").replace(/punct/g, _).getRegex();
1913
+ var je = d(ce, "u").replace(/punct/g, ue).getRegex();
1914
+ var Fe = /^(?:\*+(?:((?!\*)(?!openQuote)punct)|([^\s*]))?)|^_+(?:((?!_)(?!openQuote)punct)|([^\s_]))?/;
1915
+ var Ue = d(Fe, "u").replace(/openQuote/g, He).replace(/punct/g, _).getRegex();
1916
+ var he = "^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)";
1917
+ var Ke = d(he, "gu").replace(/notPunctSpace/g, v).replace(/punctSpace/g, I).replace(/punct/g, _).getRegex();
1918
+ var We = d(he, "gu").replace(/notPunctSpace/g, Ge).replace(/punctSpace/g, Ze).replace(/punct/g, ue).getRegex();
1919
+ var Xe = "^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)[\\s](\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|(?:(?!\\*)punct|notPunctSpace)(\\*+)(?!\\*)(?=notPunctSpace)";
1920
+ var Je = d(Xe, "gu").replace(/notPunctSpace/g, v).replace(/punctSpace/g, I).replace(/punct/g, _).getRegex();
1921
+ var Ve = d("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)", "gu").replace(/notPunctSpace/g, v).replace(/punctSpace/g, I).replace(/punct/g, _).getRegex();
1922
+ var Ye = "^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)[\\s](_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)|(?:(?!_)punct|notPunctSpace)(_+)(?!_)(?=notPunctSpace)";
1923
+ var et = d(Ye, "gu").replace(/notPunctSpace/g, v).replace(/punctSpace/g, I).replace(/punct/g, _).getRegex();
1924
+ var tt = d(/^~~?(?:((?!~)punct)|[^\s~])/, "u").replace(/punct/g, _).getRegex();
1925
+ var nt = "^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)";
1926
+ var rt = d(nt, "gu").replace(/notPunctSpace/g, v).replace(/punctSpace/g, I).replace(/punct/g, _).getRegex();
1927
+ var st = d(/\\(punct)/, "gu").replace(/punct/g, _).getRegex();
1928
+ var it = d(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme", /[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email", /[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex();
1929
+ var ot = d(X).replace("(?:-->|$)", "-->").getRegex();
1930
+ var at = d("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment", ot).replace("attribute", /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex();
1931
+ var G = /(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/;
1932
+ var lt = d(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label", G).replace("href", /<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]+|(?=\))/).replace("title", /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex();
1933
+ var de = d(/^!?\[(label)\]\[(ref)\]/).replace("label", G).replace("ref", W).getRegex();
1934
+ var ke = d(/^!?\[(ref)\](?:\[\])?/).replace("ref", W).getRegex();
1935
+ var pt = d("reflink|nolink(?!\\()", "g").replace("reflink", de).replace("nolink", ke).getRegex();
1936
+ var ie = /[hH][tT][tT][pP][sS]?|[fF][tT][pP]/;
1937
+ var V = { _backpedal: z, anyPunctuation: st, autolink: it, blockSkip: Qe, br: pe, code: De, del: z, delLDelim: z, delRDelim: z, emStrongLDelim: Ne, emStrongRDelimAst: Ke, emStrongRDelimUnd: Ve, escape: Be, link: lt, nolink: ke, punctuation: ve, reflink: de, reflinkSearch: pt, tag: at, text: qe, url: z };
1938
+ var ut = { ...V, emStrongLDelim: Ue, emStrongRDelimAst: Je, emStrongRDelimUnd: et, link: d(/^!?\[(label)\]\((.*?)\)/).replace("label", G).getRegex(), reflink: d(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label", G).getRegex() };
1939
+ var F = { ...V, emStrongRDelimAst: We, emStrongLDelim: je, delLDelim: tt, delRDelim: rt, url: d(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol", ie).replace("email", /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(), _backpedal: /(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/, del: /^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/, text: d(/^(`+|~+|[^`~])(?:(?=[`~])|(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol", ie).getRegex() };
1940
+ var ct = { ...F, br: d(pe).replace("{2,}", "*").getRegex(), text: d(F.text).replace("\\b_", "\\b_| {2,}\\n").replace(/\{2,\}/g, "*").getRegex() };
1941
+ var H = { normal: J, gfm: Ae, pedantic: Ie };
1942
+ var B = { normal: V, gfm: F, breaks: ct, pedantic: ut };
1943
+ var ht = { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" };
1944
+ var ge = (l3) => ht[l3];
1945
+ function O(l3, e) {
1946
+ if (e) {
1947
+ if (m.escapeTest.test(l3)) return l3.replace(m.escapeReplace, ge);
1948
+ } else if (m.escapeTestNoEncode.test(l3)) return l3.replace(m.escapeReplaceNoEncode, ge);
1949
+ return l3;
1950
+ }
1951
+ function Y(l3) {
1952
+ try {
1953
+ l3 = encodeURI(l3).replace(m.percentDecode, "%");
1954
+ } catch {
1955
+ return null;
1956
+ }
1957
+ return l3;
1958
+ }
1959
+ function ee(l3, e) {
1960
+ let t = l3.replace(m.findPipe, (r, i, o) => {
1961
+ let p = false, a = i;
1962
+ for (; --a >= 0 && o[a] === "\\"; ) p = !p;
1963
+ return p ? "|" : " |";
1964
+ }), n = t.split(m.splitPipe), s = 0;
1965
+ if (n[0].trim() || n.shift(), n.length > 0 && !n.at(-1)?.trim() && n.pop(), e) if (n.length > e) n.splice(e);
1966
+ else for (; n.length < e; ) n.push("");
1967
+ for (; s < n.length; s++) n[s] = n[s].trim().replace(m.slashPipe, "|");
1968
+ return n;
1969
+ }
1970
+ function $(l3, e, t) {
1971
+ let n = l3.length;
1972
+ if (n === 0) return "";
1973
+ let s = 0;
1974
+ for (; s < n; ) {
1975
+ let r = l3.charAt(n - s - 1);
1976
+ if (r === e && !t) s++;
1977
+ else if (r !== e && t) s++;
1978
+ else break;
1979
+ }
1980
+ return l3.slice(0, n - s);
1981
+ }
1982
+ function te(l3) {
1983
+ let e = l3.split(`
1984
+ `), t = e.length - 1;
1985
+ for (; t >= 0 && m.blankLine.test(e[t]); ) t--;
1986
+ return e.length - t <= 2 ? l3 : e.slice(0, t + 1).join(`
1987
+ `);
1988
+ }
1989
+ function fe(l3, e) {
1990
+ if (l3.indexOf(e[1]) === -1) return -1;
1991
+ let t = 0;
1992
+ for (let n = 0; n < l3.length; n++) if (l3[n] === "\\") n++;
1993
+ else if (l3[n] === e[0]) t++;
1994
+ else if (l3[n] === e[1] && (t--, t < 0)) return n;
1995
+ return t > 0 ? -2 : -1;
1996
+ }
1997
+ function me(l3, e = 0) {
1998
+ let t = e, n = "";
1999
+ for (let s of l3) if (s === " ") {
2000
+ let r = 4 - t % 4;
2001
+ n += " ".repeat(r), t += r;
2002
+ } else n += s, t++;
2003
+ return n;
2004
+ }
2005
+ function xe(l3, e, t, n, s) {
2006
+ let r = e.href, i = e.title || null, o = l3[1].replace(s.other.outputLinkReplace, "$1");
2007
+ n.state.inLink = true;
2008
+ let p = { type: l3[0].charAt(0) === "!" ? "image" : "link", raw: t, href: r, title: i, text: o, tokens: n.inlineTokens(o) };
2009
+ return n.state.inLink = false, p;
2010
+ }
2011
+ function dt(l3, e, t) {
2012
+ let n = l3.match(t.other.indentCodeCompensation);
2013
+ if (n === null) return e;
2014
+ let s = n[1];
2015
+ return e.split(`
2016
+ `).map((r) => {
2017
+ let i = r.match(t.other.beginningSpace);
2018
+ if (i === null) return r;
2019
+ let [o] = i;
2020
+ return o.length >= s.length ? r.slice(s.length) : r;
2021
+ }).join(`
2022
+ `);
2023
+ }
2024
+ var y = class {
2025
+ options;
2026
+ rules;
2027
+ lexer;
2028
+ constructor(e) {
2029
+ this.options = e || R;
2030
+ }
2031
+ space(e) {
2032
+ let t = this.rules.block.newline.exec(e);
2033
+ if (t && t[0].length > 0) return { type: "space", raw: t[0] };
2034
+ }
2035
+ code(e) {
2036
+ let t = this.rules.block.code.exec(e);
2037
+ if (t) {
2038
+ let n = this.options.pedantic ? t[0] : te(t[0]), s = n.replace(this.rules.other.codeRemoveIndent, "");
2039
+ return { type: "code", raw: n, codeBlockStyle: "indented", text: s };
2040
+ }
2041
+ }
2042
+ fences(e) {
2043
+ let t = this.rules.block.fences.exec(e);
2044
+ if (t) {
2045
+ let n = t[0], s = dt(n, t[3] || "", this.rules);
2046
+ return { type: "code", raw: n, lang: t[2] ? t[2].trim().replace(this.rules.inline.anyPunctuation, "$1") : t[2], text: s };
2047
+ }
2048
+ }
2049
+ heading(e) {
2050
+ let t = this.rules.block.heading.exec(e);
2051
+ if (t) {
2052
+ let n = t[2].trim();
2053
+ if (this.rules.other.endingHash.test(n)) {
2054
+ let s = $(n, "#");
2055
+ (this.options.pedantic || !s || this.rules.other.endingSpaceChar.test(s)) && (n = s.trim());
2056
+ }
2057
+ return { type: "heading", raw: $(t[0], `
2058
+ `), depth: t[1].length, text: n, tokens: this.lexer.inline(n) };
2059
+ }
2060
+ }
2061
+ hr(e) {
2062
+ let t = this.rules.block.hr.exec(e);
2063
+ if (t) return { type: "hr", raw: $(t[0], `
2064
+ `) };
2065
+ }
2066
+ blockquote(e) {
2067
+ let t = this.rules.block.blockquote.exec(e);
2068
+ if (t) {
2069
+ let n = $(t[0], `
2070
+ `).split(`
2071
+ `), s = "", r = "", i = [];
2072
+ for (; n.length > 0; ) {
2073
+ let o = false, p = [], a;
2074
+ for (a = 0; a < n.length; a++) if (this.rules.other.blockquoteStart.test(n[a])) p.push(n[a]), o = true;
2075
+ else if (!o) p.push(n[a]);
2076
+ else break;
2077
+ n = n.slice(a);
2078
+ let u = p.join(`
2079
+ `), c = u.replace(this.rules.other.blockquoteSetextReplace, `
2080
+ $1`).replace(this.rules.other.blockquoteSetextReplace2, "");
2081
+ s = s ? `${s}
2082
+ ${u}` : u, r = r ? `${r}
2083
+ ${c}` : c;
2084
+ let h = this.lexer.state.top;
2085
+ if (this.lexer.state.top = true, this.lexer.blockTokens(c, i, true), this.lexer.state.top = h, n.length === 0) break;
2086
+ let k = i.at(-1);
2087
+ if (k?.type === "code") break;
2088
+ if (k?.type === "blockquote") {
2089
+ let T = k, g = n.join(`
2090
+ `), w = T.raw + `
2091
+ ` + g.replace(this.rules.other.blockquoteSetextReplace2, ""), M = this.blockquote(w);
2092
+ i[i.length - 1] = M, s = `${s}
2093
+ ${g}`, r = r.substring(0, r.length - T.text.length) + M.text;
2094
+ break;
2095
+ } else if (k?.type === "list") {
2096
+ let T = k, g = T.raw + `
2097
+ ` + n.join(`
2098
+ `), w = this.list(g);
2099
+ i[i.length - 1] = w, s = s.substring(0, s.length - k.raw.length) + w.raw, r = r.substring(0, r.length - T.raw.length) + w.raw, n = g.substring(i.at(-1).raw.length).split(`
2100
+ `);
2101
+ continue;
2102
+ }
2103
+ }
2104
+ return { type: "blockquote", raw: s, tokens: i, text: r };
2105
+ }
2106
+ }
2107
+ list(e) {
2108
+ let t = this.rules.block.list.exec(e);
2109
+ if (t) {
2110
+ let n = t[1].trim(), s = n.length > 1, r = { type: "list", raw: "", ordered: s, start: s ? +n.slice(0, -1) : "", loose: false, items: [] };
2111
+ n = s ? `\\d{1,9}\\${n.slice(-1)}` : `\\${n}`, this.options.pedantic && (n = s ? n : "[*+-]");
2112
+ let i = this.rules.other.listItemRegex(n), o = false;
2113
+ for (; e; ) {
2114
+ let a = false, u = "", c = "";
2115
+ if (!(t = i.exec(e)) || this.rules.block.hr.test(e)) break;
2116
+ u = t[0], e = e.substring(u.length);
2117
+ let h = me(t[2].split(`
2118
+ `, 1)[0], t[1].length), k = e.split(`
2119
+ `, 1)[0], T = !h.trim(), g = 0;
2120
+ if (this.options.pedantic ? (g = 2, c = h.trimStart()) : T ? g = t[1].length + 1 : (g = h.search(this.rules.other.nonSpaceChar), g = g > 4 ? 1 : g, c = h.slice(g), g += t[1].length), T && this.rules.other.blankLine.test(k) && (u += k + `
2121
+ `, e = e.substring(k.length + 1), a = true), !a) {
2122
+ let w = this.rules.other.nextBulletRegex(g), M = this.rules.other.hrRegex(g), ne = this.rules.other.fencesBeginRegex(g), re = this.rules.other.headingBeginRegex(g), be = this.rules.other.htmlBeginRegex(g), Re = this.rules.other.blockquoteBeginRegex(g);
2123
+ for (; e; ) {
2124
+ let N = e.split(`
2125
+ `, 1)[0], D;
2126
+ if (k = N, this.options.pedantic ? (k = k.replace(this.rules.other.listReplaceNesting, " "), D = k) : D = k.replace(this.rules.other.tabCharGlobal, " "), ne.test(k) || re.test(k) || be.test(k) || Re.test(k) || w.test(k) || M.test(k)) break;
2127
+ if (D.search(this.rules.other.nonSpaceChar) >= g || !k.trim()) c += `
2128
+ ` + D.slice(g);
2129
+ else {
2130
+ if (T || h.replace(this.rules.other.tabCharGlobal, " ").search(this.rules.other.nonSpaceChar) >= 4 || ne.test(h) || re.test(h) || M.test(h)) break;
2131
+ c += `
2132
+ ` + k;
2133
+ }
2134
+ T = !k.trim(), u += N + `
2135
+ `, e = e.substring(N.length + 1), h = D.slice(g);
2136
+ }
2137
+ }
2138
+ r.loose || (o ? r.loose = true : this.rules.other.doubleBlankLine.test(u) && (o = true)), r.items.push({ type: "list_item", raw: u, task: !!this.options.gfm && this.rules.other.listIsTask.test(c), loose: false, text: c, tokens: [] }), r.raw += u;
2139
+ }
2140
+ let p = r.items.at(-1);
2141
+ if (p) p.raw = p.raw.trimEnd(), p.text = p.text.trimEnd();
2142
+ else return;
2143
+ r.raw = r.raw.trimEnd();
2144
+ for (let a of r.items) if (this.lexer.state.top = false, a.tokens = this.lexer.blockTokens(a.text, []), !r.loose) {
2145
+ let u = a.tokens.filter((h) => h.type === "space"), c = u.length > 0 && u.some((h) => this.rules.other.anyLine.test(h.raw));
2146
+ r.loose = c;
2147
+ }
2148
+ for (let a of r.items) {
2149
+ let u = a.tokens[0];
2150
+ if (a.task && (u?.type === "text" || u?.type === "paragraph")) {
2151
+ a.text = a.text.replace(this.rules.other.listReplaceTask, ""), u.raw = u.raw.replace(this.rules.other.listReplaceTask, ""), u.text = u.text.replace(this.rules.other.listReplaceTask, "");
2152
+ for (let h = this.lexer.inlineQueue.length - 1; h >= 0; h--) if (this.rules.other.listIsTask.test(this.lexer.inlineQueue[h].src)) {
2153
+ this.lexer.inlineQueue[h].src = this.lexer.inlineQueue[h].src.replace(this.rules.other.listReplaceTask, "");
2154
+ break;
2155
+ }
2156
+ let c = this.rules.other.listTaskCheckbox.exec(a.raw);
2157
+ if (c) {
2158
+ let h = { type: "checkbox", raw: c[0] + " ", checked: c[0] !== "[ ]" };
2159
+ a.checked = h.checked, r.loose ? a.tokens[0] && ["paragraph", "text"].includes(a.tokens[0].type) && "tokens" in a.tokens[0] && a.tokens[0].tokens ? (a.tokens[0].raw = h.raw + a.tokens[0].raw, a.tokens[0].text = h.raw + a.tokens[0].text, a.tokens[0].tokens.unshift(h)) : a.tokens.unshift({ type: "paragraph", raw: h.raw, text: h.raw, tokens: [h] }) : a.tokens.unshift(h);
2160
+ }
2161
+ } else a.task && (a.task = false);
2162
+ }
2163
+ if (r.loose) for (let a of r.items) {
2164
+ a.loose = true;
2165
+ for (let u of a.tokens) u.type === "text" && (u.type = "paragraph");
2166
+ }
2167
+ return r;
2168
+ }
2169
+ }
2170
+ html(e) {
2171
+ let t = this.rules.block.html.exec(e);
2172
+ if (t) {
2173
+ let n = te(t[0]);
2174
+ return { type: "html", block: true, raw: n, pre: t[1] === "pre" || t[1] === "script" || t[1] === "style", text: n };
2175
+ }
2176
+ }
2177
+ def(e) {
2178
+ let t = this.rules.block.def.exec(e);
2179
+ if (t) {
2180
+ let n = t[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal, " "), s = t[2] ? t[2].replace(this.rules.other.hrefBrackets, "$1").replace(this.rules.inline.anyPunctuation, "$1") : "", r = t[3] ? t[3].substring(1, t[3].length - 1).replace(this.rules.inline.anyPunctuation, "$1") : t[3];
2181
+ return { type: "def", tag: n, raw: $(t[0], `
2182
+ `), href: s, title: r };
2183
+ }
2184
+ }
2185
+ table(e) {
2186
+ let t = this.rules.block.table.exec(e);
2187
+ if (!t || !this.rules.other.tableDelimiter.test(t[2])) return;
2188
+ let n = ee(t[1]), s = t[2].replace(this.rules.other.tableAlignChars, "").split("|"), r = t[3]?.trim() ? t[3].replace(this.rules.other.tableRowBlankLine, "").split(`
2189
+ `) : [], i = { type: "table", raw: $(t[0], `
2190
+ `), header: [], align: [], rows: [] };
2191
+ if (n.length === s.length) {
2192
+ for (let o of s) this.rules.other.tableAlignRight.test(o) ? i.align.push("right") : this.rules.other.tableAlignCenter.test(o) ? i.align.push("center") : this.rules.other.tableAlignLeft.test(o) ? i.align.push("left") : i.align.push(null);
2193
+ for (let o = 0; o < n.length; o++) i.header.push({ text: n[o], tokens: this.lexer.inline(n[o]), header: true, align: i.align[o] });
2194
+ for (let o of r) i.rows.push(ee(o, i.header.length).map((p, a) => ({ text: p, tokens: this.lexer.inline(p), header: false, align: i.align[a] })));
2195
+ return i;
2196
+ }
2197
+ }
2198
+ lheading(e) {
2199
+ let t = this.rules.block.lheading.exec(e);
2200
+ if (t) {
2201
+ let n = t[1].trim();
2202
+ return { type: "heading", raw: $(t[0], `
2203
+ `), depth: t[2].charAt(0) === "=" ? 1 : 2, text: n, tokens: this.lexer.inline(n) };
2204
+ }
2205
+ }
2206
+ paragraph(e) {
2207
+ let t = this.rules.block.paragraph.exec(e);
2208
+ if (t) {
2209
+ let n = t[1].charAt(t[1].length - 1) === `
2210
+ ` ? t[1].slice(0, -1) : t[1];
2211
+ return { type: "paragraph", raw: t[0], text: n, tokens: this.lexer.inline(n) };
2212
+ }
2213
+ }
2214
+ text(e) {
2215
+ let t = this.rules.block.text.exec(e);
2216
+ if (t) return { type: "text", raw: t[0], text: t[0], tokens: this.lexer.inline(t[0]) };
2217
+ }
2218
+ escape(e) {
2219
+ let t = this.rules.inline.escape.exec(e);
2220
+ if (t) return { type: "escape", raw: t[0], text: t[1] };
2221
+ }
2222
+ tag(e) {
2223
+ let t = this.rules.inline.tag.exec(e);
2224
+ if (t) return !this.lexer.state.inLink && this.rules.other.startATag.test(t[0]) ? this.lexer.state.inLink = true : this.lexer.state.inLink && this.rules.other.endATag.test(t[0]) && (this.lexer.state.inLink = false), !this.lexer.state.inRawBlock && this.rules.other.startPreScriptTag.test(t[0]) ? this.lexer.state.inRawBlock = true : this.lexer.state.inRawBlock && this.rules.other.endPreScriptTag.test(t[0]) && (this.lexer.state.inRawBlock = false), { type: "html", raw: t[0], inLink: this.lexer.state.inLink, inRawBlock: this.lexer.state.inRawBlock, block: false, text: t[0] };
2225
+ }
2226
+ link(e) {
2227
+ let t = this.rules.inline.link.exec(e);
2228
+ if (t) {
2229
+ let n = t[2].trim();
2230
+ if (!this.options.pedantic && this.rules.other.startAngleBracket.test(n)) {
2231
+ if (!this.rules.other.endAngleBracket.test(n)) return;
2232
+ let i = $(n.slice(0, -1), "\\");
2233
+ if ((n.length - i.length) % 2 === 0) return;
2234
+ } else {
2235
+ let i = fe(t[2], "()");
2236
+ if (i === -2) return;
2237
+ if (i > -1) {
2238
+ let p = (t[0].indexOf("!") === 0 ? 5 : 4) + t[1].length + i;
2239
+ t[2] = t[2].substring(0, i), t[0] = t[0].substring(0, p).trim(), t[3] = "";
2240
+ }
2241
+ }
2242
+ let s = t[2], r = "";
2243
+ if (this.options.pedantic) {
2244
+ let i = this.rules.other.pedanticHrefTitle.exec(s);
2245
+ i && (s = i[1], r = i[3]);
2246
+ } else r = t[3] ? t[3].slice(1, -1) : "";
2247
+ return s = s.trim(), this.rules.other.startAngleBracket.test(s) && (this.options.pedantic && !this.rules.other.endAngleBracket.test(n) ? s = s.slice(1) : s = s.slice(1, -1)), xe(t, { href: s && s.replace(this.rules.inline.anyPunctuation, "$1"), title: r && r.replace(this.rules.inline.anyPunctuation, "$1") }, t[0], this.lexer, this.rules);
2248
+ }
2249
+ }
2250
+ reflink(e, t) {
2251
+ let n;
2252
+ if ((n = this.rules.inline.reflink.exec(e)) || (n = this.rules.inline.nolink.exec(e))) {
2253
+ let s = (n[2] || n[1]).replace(this.rules.other.multipleSpaceGlobal, " "), r = t[s.toLowerCase()];
2254
+ if (!r) {
2255
+ let i = n[0].charAt(0);
2256
+ return { type: "text", raw: i, text: i };
2257
+ }
2258
+ return xe(n, r, n[0], this.lexer, this.rules);
2259
+ }
2260
+ }
2261
+ emStrong(e, t, n = "") {
2262
+ let s = this.rules.inline.emStrongLDelim.exec(e);
2263
+ if (!s || !s[1] && !s[2] && !s[3] && !s[4] || s[4] && n.match(this.rules.other.unicodeAlphaNumeric)) return;
2264
+ if (!(s[1] || s[3] || "") || !n || this.rules.inline.punctuation.exec(n)) {
2265
+ let i = [...s[0]].length - 1, o, p, a = i, u = 0, c = s[0][0], h = n === c, k = c === "*" ? this.rules.inline.emStrongRDelimAst : this.rules.inline.emStrongRDelimUnd;
2266
+ for (k.lastIndex = 0, t = t.slice(-1 * e.length + i); (s = k.exec(t)) !== null; ) {
2267
+ if (o = s[1] || s[2] || s[3] || s[4] || s[5] || s[6], !o) continue;
2268
+ if (p = [...o].length, s[3] || s[4]) {
2269
+ a += p;
2270
+ continue;
2271
+ } else if (s[5] || s[6]) {
2272
+ if (i % 3 && !((i + p) % 3)) {
2273
+ u += p;
2274
+ continue;
2275
+ }
2276
+ if (h) break;
2277
+ }
2278
+ if (a -= p, a > 0) continue;
2279
+ p = Math.min(p, p + a + u);
2280
+ let T = [...s[0]][0].length, g = e.slice(0, i + s.index + T + p);
2281
+ if (Math.min(i, p) % 2) {
2282
+ let M = g.slice(1, -1);
2283
+ return { type: "em", raw: g, text: M, tokens: this.lexer.inlineTokens(M) };
2284
+ }
2285
+ let w = g.slice(2, -2);
2286
+ return { type: "strong", raw: g, text: w, tokens: this.lexer.inlineTokens(w) };
2287
+ }
2288
+ }
2289
+ }
2290
+ codespan(e) {
2291
+ let t = this.rules.inline.code.exec(e);
2292
+ if (t) {
2293
+ let n = t[2].replace(this.rules.other.newLineCharGlobal, " "), s = this.rules.other.nonSpaceChar.test(n), r = this.rules.other.startingSpaceChar.test(n) && this.rules.other.endingSpaceChar.test(n);
2294
+ return s && r && (n = n.substring(1, n.length - 1)), { type: "codespan", raw: t[0], text: n };
2295
+ }
2296
+ }
2297
+ br(e) {
2298
+ let t = this.rules.inline.br.exec(e);
2299
+ if (t) return { type: "br", raw: t[0] };
2300
+ }
2301
+ del(e, t, n = "") {
2302
+ let s = this.rules.inline.delLDelim.exec(e);
2303
+ if (!s) return;
2304
+ if (!(s[1] || "") || !n || this.rules.inline.punctuation.exec(n)) {
2305
+ let i = [...s[0]].length - 1, o, p, a = i, u = this.rules.inline.delRDelim;
2306
+ for (u.lastIndex = 0, t = t.slice(-1 * e.length + i); (s = u.exec(t)) !== null; ) {
2307
+ if (o = s[1] || s[2] || s[3] || s[4] || s[5] || s[6], !o || (p = [...o].length, p !== i)) continue;
2308
+ if (s[3] || s[4]) {
2309
+ a += p;
2310
+ continue;
2311
+ }
2312
+ if (a -= p, a > 0) continue;
2313
+ p = Math.min(p, p + a);
2314
+ let c = [...s[0]][0].length, h = e.slice(0, i + s.index + c + p), k = h.slice(i, -i);
2315
+ return { type: "del", raw: h, text: k, tokens: this.lexer.inlineTokens(k) };
2316
+ }
2317
+ }
2318
+ }
2319
+ autolink(e) {
2320
+ let t = this.rules.inline.autolink.exec(e);
2321
+ if (t) {
2322
+ let n, s;
2323
+ return t[2] === "@" ? (n = t[1], s = "mailto:" + n) : (n = t[1], s = n), { type: "link", raw: t[0], text: n, href: s, tokens: [{ type: "text", raw: n, text: n }] };
2324
+ }
2325
+ }
2326
+ url(e) {
2327
+ let t;
2328
+ if (t = this.rules.inline.url.exec(e)) {
2329
+ let n, s;
2330
+ if (t[2] === "@") n = t[0], s = "mailto:" + n;
2331
+ else {
2332
+ let r;
2333
+ do
2334
+ r = t[0], t[0] = this.rules.inline._backpedal.exec(t[0])?.[0] ?? "";
2335
+ while (r !== t[0]);
2336
+ n = t[0], t[1] === "www." ? s = "http://" + t[0] : s = t[0];
2337
+ }
2338
+ return { type: "link", raw: t[0], text: n, href: s, tokens: [{ type: "text", raw: n, text: n }] };
2339
+ }
2340
+ }
2341
+ inlineText(e) {
2342
+ let t = this.rules.inline.text.exec(e);
2343
+ if (t) {
2344
+ let n = this.lexer.state.inRawBlock;
2345
+ return { type: "text", raw: t[0], text: t[0], escaped: n };
2346
+ }
2347
+ }
2348
+ };
2349
+ var x = class l {
2350
+ tokens;
2351
+ options;
2352
+ state;
2353
+ inlineQueue;
2354
+ tokenizer;
2355
+ constructor(e) {
2356
+ this.tokens = [], this.tokens.links = /* @__PURE__ */ Object.create(null), this.options = e || R, this.options.tokenizer = this.options.tokenizer || new y(), this.tokenizer = this.options.tokenizer, this.tokenizer.options = this.options, this.tokenizer.lexer = this, this.inlineQueue = [], this.state = { inLink: false, inRawBlock: false, top: true };
2357
+ let t = { other: m, block: H.normal, inline: B.normal };
2358
+ this.options.pedantic ? (t.block = H.pedantic, t.inline = B.pedantic) : this.options.gfm && (t.block = H.gfm, this.options.breaks ? t.inline = B.breaks : t.inline = B.gfm), this.tokenizer.rules = t;
2359
+ }
2360
+ static get rules() {
2361
+ return { block: H, inline: B };
2362
+ }
2363
+ static lex(e, t) {
2364
+ return new l(t).lex(e);
2365
+ }
2366
+ static lexInline(e, t) {
2367
+ return new l(t).inlineTokens(e);
2368
+ }
2369
+ lex(e) {
2370
+ e = e.replace(m.carriageReturn, `
2371
+ `), this.blockTokens(e, this.tokens);
2372
+ for (let t = 0; t < this.inlineQueue.length; t++) {
2373
+ let n = this.inlineQueue[t];
2374
+ this.inlineTokens(n.src, n.tokens);
2375
+ }
2376
+ return this.inlineQueue = [], this.tokens;
2377
+ }
2378
+ blockTokens(e, t = [], n = false) {
2379
+ this.tokenizer.lexer = this, this.options.pedantic && (e = e.replace(m.tabCharGlobal, " ").replace(m.spaceLine, ""));
2380
+ let s = 1 / 0;
2381
+ for (; e; ) {
2382
+ if (e.length < s) s = e.length;
2383
+ else {
2384
+ this.infiniteLoopError(e.charCodeAt(0));
2385
+ break;
2386
+ }
2387
+ let r;
2388
+ if (this.options.extensions?.block?.some((o) => (r = o.call({ lexer: this }, e, t)) ? (e = e.substring(r.raw.length), t.push(r), true) : false)) continue;
2389
+ if (r = this.tokenizer.space(e)) {
2390
+ e = e.substring(r.raw.length);
2391
+ let o = t.at(-1);
2392
+ r.raw.length === 1 && o !== void 0 ? o.raw += `
2393
+ ` : t.push(r);
2394
+ continue;
2395
+ }
2396
+ if (r = this.tokenizer.code(e)) {
2397
+ e = e.substring(r.raw.length);
2398
+ let o = t.at(-1);
2399
+ o?.type === "paragraph" || o?.type === "text" ? (o.raw += (o.raw.endsWith(`
2400
+ `) ? "" : `
2401
+ `) + r.raw, o.text += `
2402
+ ` + r.text, this.inlineQueue.at(-1).src = o.text) : t.push(r);
2403
+ continue;
2404
+ }
2405
+ if (r = this.tokenizer.fences(e)) {
2406
+ e = e.substring(r.raw.length), t.push(r);
2407
+ continue;
2408
+ }
2409
+ if (r = this.tokenizer.heading(e)) {
2410
+ e = e.substring(r.raw.length), t.push(r);
2411
+ continue;
2412
+ }
2413
+ if (r = this.tokenizer.hr(e)) {
2414
+ e = e.substring(r.raw.length), t.push(r);
2415
+ continue;
2416
+ }
2417
+ if (r = this.tokenizer.blockquote(e)) {
2418
+ e = e.substring(r.raw.length), t.push(r);
2419
+ continue;
2420
+ }
2421
+ if (r = this.tokenizer.list(e)) {
2422
+ e = e.substring(r.raw.length), t.push(r);
2423
+ continue;
2424
+ }
2425
+ if (r = this.tokenizer.html(e)) {
2426
+ e = e.substring(r.raw.length), t.push(r);
2427
+ continue;
2428
+ }
2429
+ if (r = this.tokenizer.def(e)) {
2430
+ e = e.substring(r.raw.length);
2431
+ let o = t.at(-1);
2432
+ o?.type === "paragraph" || o?.type === "text" ? (o.raw += (o.raw.endsWith(`
2433
+ `) ? "" : `
2434
+ `) + r.raw, o.text += `
2435
+ ` + r.raw, this.inlineQueue.at(-1).src = o.text) : this.tokens.links[r.tag] || (this.tokens.links[r.tag] = { href: r.href, title: r.title }, t.push(r));
2436
+ continue;
2437
+ }
2438
+ if (r = this.tokenizer.table(e)) {
2439
+ e = e.substring(r.raw.length), t.push(r);
2440
+ continue;
2441
+ }
2442
+ if (r = this.tokenizer.lheading(e)) {
2443
+ e = e.substring(r.raw.length), t.push(r);
2444
+ continue;
2445
+ }
2446
+ let i = e;
2447
+ if (this.options.extensions?.startBlock) {
2448
+ let o = 1 / 0, p = e.slice(1), a;
2449
+ this.options.extensions.startBlock.forEach((u) => {
2450
+ a = u.call({ lexer: this }, p), typeof a == "number" && a >= 0 && (o = Math.min(o, a));
2451
+ }), o < 1 / 0 && o >= 0 && (i = e.substring(0, o + 1));
2452
+ }
2453
+ if (this.state.top && (r = this.tokenizer.paragraph(i))) {
2454
+ let o = t.at(-1);
2455
+ n && o?.type === "paragraph" ? (o.raw += (o.raw.endsWith(`
2456
+ `) ? "" : `
2457
+ `) + r.raw, o.text += `
2458
+ ` + r.text, this.inlineQueue.pop(), this.inlineQueue.at(-1).src = o.text) : t.push(r), n = i.length !== e.length, e = e.substring(r.raw.length);
2459
+ continue;
2460
+ }
2461
+ if (r = this.tokenizer.text(e)) {
2462
+ e = e.substring(r.raw.length);
2463
+ let o = t.at(-1);
2464
+ o?.type === "text" ? (o.raw += (o.raw.endsWith(`
2465
+ `) ? "" : `
2466
+ `) + r.raw, o.text += `
2467
+ ` + r.text, this.inlineQueue.pop(), this.inlineQueue.at(-1).src = o.text) : t.push(r);
2468
+ continue;
2469
+ }
2470
+ if (e) {
2471
+ this.infiniteLoopError(e.charCodeAt(0));
2472
+ break;
2473
+ }
2474
+ }
2475
+ return this.state.top = true, t;
2476
+ }
2477
+ inline(e, t = []) {
2478
+ return this.inlineQueue.push({ src: e, tokens: t }), t;
2479
+ }
2480
+ inlineTokens(e, t = []) {
2481
+ this.tokenizer.lexer = this;
2482
+ let n = e;
2483
+ if (this.tokens.links) {
2484
+ let o = Object.keys(this.tokens.links);
2485
+ o.length > 0 && (n = n.replace(this.tokenizer.rules.inline.reflinkSearch, (p) => o.includes(p.slice(p.lastIndexOf("[") + 1, -1)) ? "[" + "a".repeat(p.length - 2) + "]" : p));
2486
+ }
2487
+ n = n.replace(this.tokenizer.rules.inline.anyPunctuation, (o) => "+".repeat(o.length)), n = n.replace(this.tokenizer.rules.inline.blockSkip, (o, p, a) => {
2488
+ let u = a ? a.length : 0;
2489
+ return o.slice(0, u) + "[" + "a".repeat(o.length - u - 2) + "]";
2490
+ }), n = this.options.hooks?.emStrongMask?.call({ lexer: this }, n) ?? n;
2491
+ let s = false, r = "", i = 1 / 0;
2492
+ for (; e; ) {
2493
+ if (e.length < i) i = e.length;
2494
+ else {
2495
+ this.infiniteLoopError(e.charCodeAt(0));
2496
+ break;
2497
+ }
2498
+ s || (r = ""), s = false;
2499
+ let o;
2500
+ if (this.options.extensions?.inline?.some((a) => (o = a.call({ lexer: this }, e, t)) ? (e = e.substring(o.raw.length), t.push(o), true) : false)) continue;
2501
+ if (o = this.tokenizer.escape(e)) {
2502
+ e = e.substring(o.raw.length), t.push(o);
2503
+ continue;
2504
+ }
2505
+ if (o = this.tokenizer.tag(e)) {
2506
+ e = e.substring(o.raw.length), t.push(o);
2507
+ continue;
2508
+ }
2509
+ if (o = this.tokenizer.link(e)) {
2510
+ e = e.substring(o.raw.length), t.push(o);
2511
+ continue;
2512
+ }
2513
+ if (o = this.tokenizer.reflink(e, this.tokens.links)) {
2514
+ e = e.substring(o.raw.length);
2515
+ let a = t.at(-1);
2516
+ o.type === "text" && a?.type === "text" ? (a.raw += o.raw, a.text += o.text) : t.push(o);
2517
+ continue;
2518
+ }
2519
+ if (o = this.tokenizer.emStrong(e, n, r)) {
2520
+ e = e.substring(o.raw.length), t.push(o);
2521
+ continue;
2522
+ }
2523
+ if (o = this.tokenizer.codespan(e)) {
2524
+ e = e.substring(o.raw.length), t.push(o);
2525
+ continue;
2526
+ }
2527
+ if (o = this.tokenizer.br(e)) {
2528
+ e = e.substring(o.raw.length), t.push(o);
2529
+ continue;
2530
+ }
2531
+ if (o = this.tokenizer.del(e, n, r)) {
2532
+ e = e.substring(o.raw.length), t.push(o);
2533
+ continue;
2534
+ }
2535
+ if (o = this.tokenizer.autolink(e)) {
2536
+ e = e.substring(o.raw.length), t.push(o);
2537
+ continue;
2538
+ }
2539
+ if (!this.state.inLink && (o = this.tokenizer.url(e))) {
2540
+ e = e.substring(o.raw.length), t.push(o);
2541
+ continue;
2542
+ }
2543
+ let p = e;
2544
+ if (this.options.extensions?.startInline) {
2545
+ let a = 1 / 0, u = e.slice(1), c;
2546
+ this.options.extensions.startInline.forEach((h) => {
2547
+ c = h.call({ lexer: this }, u), typeof c == "number" && c >= 0 && (a = Math.min(a, c));
2548
+ }), a < 1 / 0 && a >= 0 && (p = e.substring(0, a + 1));
2549
+ }
2550
+ if (o = this.tokenizer.inlineText(p)) {
2551
+ e = e.substring(o.raw.length), o.raw.slice(-1) !== "_" && (r = o.raw.slice(-1)), s = true;
2552
+ let a = t.at(-1);
2553
+ a?.type === "text" ? (a.raw += o.raw, a.text += o.text) : t.push(o);
2554
+ continue;
2555
+ }
2556
+ if (e) {
2557
+ this.infiniteLoopError(e.charCodeAt(0));
2558
+ break;
2559
+ }
2560
+ }
2561
+ return t;
2562
+ }
2563
+ infiniteLoopError(e) {
2564
+ let t = "Infinite loop on byte: " + e;
2565
+ if (this.options.silent) console.error(t);
2566
+ else throw new Error(t);
2567
+ }
2568
+ };
2569
+ var P = class {
2570
+ options;
2571
+ parser;
2572
+ constructor(e) {
2573
+ this.options = e || R;
2574
+ }
2575
+ space(e) {
2576
+ return "";
2577
+ }
2578
+ code({ text: e, lang: t, escaped: n }) {
2579
+ let s = (t || "").match(m.notSpaceStart)?.[0], r = e.replace(m.endingNewline, "") + `
2580
+ `;
2581
+ return s ? '<pre><code class="language-' + O(s) + '">' + (n ? r : O(r, true)) + `</code></pre>
2582
+ ` : "<pre><code>" + (n ? r : O(r, true)) + `</code></pre>
2583
+ `;
2584
+ }
2585
+ blockquote({ tokens: e }) {
2586
+ return `<blockquote>
2587
+ ${this.parser.parse(e)}</blockquote>
2588
+ `;
2589
+ }
2590
+ html({ text: e }) {
2591
+ return e;
2592
+ }
2593
+ def(e) {
2594
+ return "";
2595
+ }
2596
+ heading({ tokens: e, depth: t }) {
2597
+ return `<h${t}>${this.parser.parseInline(e)}</h${t}>
2598
+ `;
2599
+ }
2600
+ hr(e) {
2601
+ return `<hr>
2602
+ `;
2603
+ }
2604
+ list(e) {
2605
+ let t = e.ordered, n = e.start, s = "";
2606
+ for (let o = 0; o < e.items.length; o++) {
2607
+ let p = e.items[o];
2608
+ s += this.listitem(p);
2609
+ }
2610
+ let r = t ? "ol" : "ul", i = t && n !== 1 ? ' start="' + n + '"' : "";
2611
+ return "<" + r + i + `>
2612
+ ` + s + "</" + r + `>
2613
+ `;
2614
+ }
2615
+ listitem(e) {
2616
+ return `<li>${this.parser.parse(e.tokens)}</li>
2617
+ `;
2618
+ }
2619
+ checkbox({ checked: e }) {
2620
+ return "<input " + (e ? 'checked="" ' : "") + 'disabled="" type="checkbox"> ';
2621
+ }
2622
+ paragraph({ tokens: e }) {
2623
+ return `<p>${this.parser.parseInline(e)}</p>
2624
+ `;
2625
+ }
2626
+ table(e) {
2627
+ let t = "", n = "";
2628
+ for (let r = 0; r < e.header.length; r++) n += this.tablecell(e.header[r]);
2629
+ t += this.tablerow({ text: n });
2630
+ let s = "";
2631
+ for (let r = 0; r < e.rows.length; r++) {
2632
+ let i = e.rows[r];
2633
+ n = "";
2634
+ for (let o = 0; o < i.length; o++) n += this.tablecell(i[o]);
2635
+ s += this.tablerow({ text: n });
2636
+ }
2637
+ return s && (s = `<tbody>${s}</tbody>`), `<table>
2638
+ <thead>
2639
+ ` + t + `</thead>
2640
+ ` + s + `</table>
2641
+ `;
2642
+ }
2643
+ tablerow({ text: e }) {
2644
+ return `<tr>
2645
+ ${e}</tr>
2646
+ `;
2647
+ }
2648
+ tablecell(e) {
2649
+ let t = this.parser.parseInline(e.tokens), n = e.header ? "th" : "td";
2650
+ return (e.align ? `<${n} align="${e.align}">` : `<${n}>`) + t + `</${n}>
2651
+ `;
2652
+ }
2653
+ strong({ tokens: e }) {
2654
+ return `<strong>${this.parser.parseInline(e)}</strong>`;
2655
+ }
2656
+ em({ tokens: e }) {
2657
+ return `<em>${this.parser.parseInline(e)}</em>`;
2658
+ }
2659
+ codespan({ text: e }) {
2660
+ return `<code>${O(e, true)}</code>`;
2661
+ }
2662
+ br(e) {
2663
+ return "<br>";
2664
+ }
2665
+ del({ tokens: e }) {
2666
+ return `<del>${this.parser.parseInline(e)}</del>`;
2667
+ }
2668
+ link({ href: e, title: t, tokens: n }) {
2669
+ let s = this.parser.parseInline(n), r = Y(e);
2670
+ if (r === null) return s;
2671
+ e = r;
2672
+ let i = '<a href="' + e + '"';
2673
+ return t && (i += ' title="' + O(t) + '"'), i += ">" + s + "</a>", i;
2674
+ }
2675
+ image({ href: e, title: t, text: n, tokens: s }) {
2676
+ s && (n = this.parser.parseInline(s, this.parser.textRenderer));
2677
+ let r = Y(e);
2678
+ if (r === null) return O(n);
2679
+ e = r;
2680
+ let i = `<img src="${e}" alt="${O(n)}"`;
2681
+ return t && (i += ` title="${O(t)}"`), i += ">", i;
2682
+ }
2683
+ text(e) {
2684
+ return "tokens" in e && e.tokens ? this.parser.parseInline(e.tokens) : "escaped" in e && e.escaped ? e.text : O(e.text);
2685
+ }
2686
+ };
2687
+ var L = class {
2688
+ strong({ text: e }) {
2689
+ return e;
2690
+ }
2691
+ em({ text: e }) {
2692
+ return e;
2693
+ }
2694
+ codespan({ text: e }) {
2695
+ return e;
2696
+ }
2697
+ del({ text: e }) {
2698
+ return e;
2699
+ }
2700
+ html({ text: e }) {
2701
+ return e;
2702
+ }
2703
+ text({ text: e }) {
2704
+ return e;
2705
+ }
2706
+ link({ text: e }) {
2707
+ return "" + e;
2708
+ }
2709
+ image({ text: e }) {
2710
+ return "" + e;
2711
+ }
2712
+ br() {
2713
+ return "";
2714
+ }
2715
+ checkbox({ raw: e }) {
2716
+ return e;
2717
+ }
2718
+ };
2719
+ var b = class l2 {
2720
+ options;
2721
+ renderer;
2722
+ textRenderer;
2723
+ constructor(e) {
2724
+ this.options = e || R, this.options.renderer = this.options.renderer || new P(), this.renderer = this.options.renderer, this.renderer.options = this.options, this.renderer.parser = this, this.textRenderer = new L();
2725
+ }
2726
+ static parse(e, t) {
2727
+ return new l2(t).parse(e);
2728
+ }
2729
+ static parseInline(e, t) {
2730
+ return new l2(t).parseInline(e);
2731
+ }
2732
+ parse(e) {
2733
+ this.renderer.parser = this;
2734
+ let t = "";
2735
+ for (let n = 0; n < e.length; n++) {
2736
+ let s = e[n];
2737
+ if (this.options.extensions?.renderers?.[s.type]) {
2738
+ let i = s, o = this.options.extensions.renderers[i.type].call({ parser: this }, i);
2739
+ if (o !== false || !["space", "hr", "heading", "code", "table", "blockquote", "list", "checkbox", "html", "def", "paragraph", "text"].includes(i.type)) {
2740
+ t += o || "";
2741
+ continue;
2742
+ }
2743
+ }
2744
+ let r = s;
2745
+ switch (r.type) {
2746
+ case "space": {
2747
+ t += this.renderer.space(r);
2748
+ break;
2749
+ }
2750
+ case "hr": {
2751
+ t += this.renderer.hr(r);
2752
+ break;
2753
+ }
2754
+ case "heading": {
2755
+ t += this.renderer.heading(r);
2756
+ break;
2757
+ }
2758
+ case "code": {
2759
+ t += this.renderer.code(r);
2760
+ break;
2761
+ }
2762
+ case "table": {
2763
+ t += this.renderer.table(r);
2764
+ break;
2765
+ }
2766
+ case "blockquote": {
2767
+ t += this.renderer.blockquote(r);
2768
+ break;
2769
+ }
2770
+ case "list": {
2771
+ t += this.renderer.list(r);
2772
+ break;
2773
+ }
2774
+ case "checkbox": {
2775
+ t += this.renderer.checkbox(r);
2776
+ break;
2777
+ }
2778
+ case "html": {
2779
+ t += this.renderer.html(r);
2780
+ break;
2781
+ }
2782
+ case "def": {
2783
+ t += this.renderer.def(r);
2784
+ break;
2785
+ }
2786
+ case "paragraph": {
2787
+ t += this.renderer.paragraph(r);
2788
+ break;
2789
+ }
2790
+ case "text": {
2791
+ t += this.renderer.text(r);
2792
+ break;
2793
+ }
2794
+ default: {
2795
+ let i = 'Token with "' + r.type + '" type was not found.';
2796
+ if (this.options.silent) return console.error(i), "";
2797
+ throw new Error(i);
2798
+ }
2799
+ }
2800
+ }
2801
+ return t;
2802
+ }
2803
+ parseInline(e, t = this.renderer) {
2804
+ this.renderer.parser = this;
2805
+ let n = "";
2806
+ for (let s = 0; s < e.length; s++) {
2807
+ let r = e[s];
2808
+ if (this.options.extensions?.renderers?.[r.type]) {
2809
+ let o = this.options.extensions.renderers[r.type].call({ parser: this }, r);
2810
+ if (o !== false || !["escape", "html", "link", "image", "checkbox", "strong", "em", "codespan", "br", "del", "text"].includes(r.type)) {
2811
+ n += o || "";
2812
+ continue;
2813
+ }
2814
+ }
2815
+ let i = r;
2816
+ switch (i.type) {
2817
+ case "escape": {
2818
+ n += t.text(i);
2819
+ break;
2820
+ }
2821
+ case "html": {
2822
+ n += t.html(i);
2823
+ break;
2824
+ }
2825
+ case "link": {
2826
+ n += t.link(i);
2827
+ break;
2828
+ }
2829
+ case "image": {
2830
+ n += t.image(i);
2831
+ break;
2832
+ }
2833
+ case "checkbox": {
2834
+ n += t.checkbox(i);
2835
+ break;
2836
+ }
2837
+ case "strong": {
2838
+ n += t.strong(i);
2839
+ break;
2840
+ }
2841
+ case "em": {
2842
+ n += t.em(i);
2843
+ break;
2844
+ }
2845
+ case "codespan": {
2846
+ n += t.codespan(i);
2847
+ break;
2848
+ }
2849
+ case "br": {
2850
+ n += t.br(i);
2851
+ break;
2852
+ }
2853
+ case "del": {
2854
+ n += t.del(i);
2855
+ break;
2856
+ }
2857
+ case "text": {
2858
+ n += t.text(i);
2859
+ break;
2860
+ }
2861
+ default: {
2862
+ let o = 'Token with "' + i.type + '" type was not found.';
2863
+ if (this.options.silent) return console.error(o), "";
2864
+ throw new Error(o);
2865
+ }
2866
+ }
2867
+ }
2868
+ return n;
2869
+ }
2870
+ };
2871
+ var S = class {
2872
+ options;
2873
+ block;
2874
+ constructor(e) {
2875
+ this.options = e || R;
2876
+ }
2877
+ static passThroughHooks = /* @__PURE__ */ new Set(["preprocess", "postprocess", "processAllTokens", "emStrongMask"]);
2878
+ static passThroughHooksRespectAsync = /* @__PURE__ */ new Set(["preprocess", "postprocess", "processAllTokens"]);
2879
+ preprocess(e) {
2880
+ return e;
2881
+ }
2882
+ postprocess(e) {
2883
+ return e;
2884
+ }
2885
+ processAllTokens(e) {
2886
+ return e;
2887
+ }
2888
+ emStrongMask(e) {
2889
+ return e;
2890
+ }
2891
+ provideLexer(e = this.block) {
2892
+ return e ? x.lex : x.lexInline;
2893
+ }
2894
+ provideParser(e = this.block) {
2895
+ return e ? b.parse : b.parseInline;
2896
+ }
2897
+ };
2898
+ var Z = class {
2899
+ defaults = C();
2900
+ options = this.setOptions;
2901
+ parse = this.parseMarkdown(true);
2902
+ parseInline = this.parseMarkdown(false);
2903
+ Parser = b;
2904
+ Renderer = P;
2905
+ TextRenderer = L;
2906
+ Lexer = x;
2907
+ Tokenizer = y;
2908
+ Hooks = S;
2909
+ constructor(...e) {
2910
+ this.use(...e);
2911
+ }
2912
+ walkTokens(e, t) {
2913
+ let n = [];
2914
+ for (let s of e) switch (n = n.concat(t.call(this, s)), s.type) {
2915
+ case "table": {
2916
+ let r = s;
2917
+ for (let i of r.header) n = n.concat(this.walkTokens(i.tokens, t));
2918
+ for (let i of r.rows) for (let o of i) n = n.concat(this.walkTokens(o.tokens, t));
2919
+ break;
2920
+ }
2921
+ case "list": {
2922
+ let r = s;
2923
+ n = n.concat(this.walkTokens(r.items, t));
2924
+ break;
2925
+ }
2926
+ default: {
2927
+ let r = s;
2928
+ this.defaults.extensions?.childTokens?.[r.type] ? this.defaults.extensions.childTokens[r.type].forEach((i) => {
2929
+ let o = r[i].flat(1 / 0);
2930
+ n = n.concat(this.walkTokens(o, t));
2931
+ }) : r.tokens && (n = n.concat(this.walkTokens(r.tokens, t)));
2932
+ }
2933
+ }
2934
+ return n;
2935
+ }
2936
+ use(...e) {
2937
+ let t = this.defaults.extensions || { renderers: {}, childTokens: {} };
2938
+ return e.forEach((n) => {
2939
+ let s = { ...n };
2940
+ if (s.async = this.defaults.async || s.async || false, n.extensions && (n.extensions.forEach((r) => {
2941
+ if (!r.name) throw new Error("extension name required");
2942
+ if ("renderer" in r) {
2943
+ let i = t.renderers[r.name];
2944
+ i ? t.renderers[r.name] = function(...o) {
2945
+ let p = r.renderer.apply(this, o);
2946
+ return p === false && (p = i.apply(this, o)), p;
2947
+ } : t.renderers[r.name] = r.renderer;
2948
+ }
2949
+ if ("tokenizer" in r) {
2950
+ if (!r.level || r.level !== "block" && r.level !== "inline") throw new Error("extension level must be 'block' or 'inline'");
2951
+ let i = t[r.level];
2952
+ i ? i.unshift(r.tokenizer) : t[r.level] = [r.tokenizer], r.start && (r.level === "block" ? t.startBlock ? t.startBlock.push(r.start) : t.startBlock = [r.start] : r.level === "inline" && (t.startInline ? t.startInline.push(r.start) : t.startInline = [r.start]));
2953
+ }
2954
+ "childTokens" in r && r.childTokens && (t.childTokens[r.name] = r.childTokens);
2955
+ }), s.extensions = t), n.renderer) {
2956
+ let r = this.defaults.renderer || new P(this.defaults);
2957
+ for (let i in n.renderer) {
2958
+ if (!(i in r)) throw new Error(`renderer '${i}' does not exist`);
2959
+ if (["options", "parser"].includes(i)) continue;
2960
+ let o = i, p = n.renderer[o], a = r[o];
2961
+ r[o] = (...u) => {
2962
+ let c = p.apply(r, u);
2963
+ return c === false && (c = a.apply(r, u)), c || "";
2964
+ };
2965
+ }
2966
+ s.renderer = r;
2967
+ }
2968
+ if (n.tokenizer) {
2969
+ let r = this.defaults.tokenizer || new y(this.defaults);
2970
+ for (let i in n.tokenizer) {
2971
+ if (!(i in r)) throw new Error(`tokenizer '${i}' does not exist`);
2972
+ if (["options", "rules", "lexer"].includes(i)) continue;
2973
+ let o = i, p = n.tokenizer[o], a = r[o];
2974
+ r[o] = (...u) => {
2975
+ let c = p.apply(r, u);
2976
+ return c === false && (c = a.apply(r, u)), c;
2977
+ };
2978
+ }
2979
+ s.tokenizer = r;
2980
+ }
2981
+ if (n.hooks) {
2982
+ let r = this.defaults.hooks || new S();
2983
+ for (let i in n.hooks) {
2984
+ if (!(i in r)) throw new Error(`hook '${i}' does not exist`);
2985
+ if (["options", "block"].includes(i)) continue;
2986
+ let o = i, p = n.hooks[o], a = r[o];
2987
+ S.passThroughHooks.has(i) ? r[o] = (u) => {
2988
+ if (this.defaults.async && S.passThroughHooksRespectAsync.has(i)) return (async () => {
2989
+ let h = await p.call(r, u);
2990
+ return a.call(r, h);
2991
+ })();
2992
+ let c = p.call(r, u);
2993
+ return a.call(r, c);
2994
+ } : r[o] = (...u) => {
2995
+ if (this.defaults.async) return (async () => {
2996
+ let h = await p.apply(r, u);
2997
+ return h === false && (h = await a.apply(r, u)), h;
2998
+ })();
2999
+ let c = p.apply(r, u);
3000
+ return c === false && (c = a.apply(r, u)), c;
3001
+ };
3002
+ }
3003
+ s.hooks = r;
3004
+ }
3005
+ if (n.walkTokens) {
3006
+ let r = this.defaults.walkTokens, i = n.walkTokens;
3007
+ s.walkTokens = function(o) {
3008
+ let p = [];
3009
+ return p.push(i.call(this, o)), r && (p = p.concat(r.call(this, o))), p;
3010
+ };
3011
+ }
3012
+ this.defaults = { ...this.defaults, ...s };
3013
+ }), this;
3014
+ }
3015
+ setOptions(e) {
3016
+ return this.defaults = { ...this.defaults, ...e }, this;
3017
+ }
3018
+ lexer(e, t) {
3019
+ return x.lex(e, t ?? this.defaults);
3020
+ }
3021
+ parser(e, t) {
3022
+ return b.parse(e, t ?? this.defaults);
3023
+ }
3024
+ parseMarkdown(e) {
3025
+ return (n, s) => {
3026
+ let r = { ...s }, i = { ...this.defaults, ...r }, o = this.onError(!!i.silent, !!i.async);
3027
+ if (this.defaults.async === true && r.async === false) return o(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));
3028
+ if (typeof n > "u" || n === null) return o(new Error("marked(): input parameter is undefined or null"));
3029
+ if (typeof n != "string") return o(new Error("marked(): input parameter is of type " + Object.prototype.toString.call(n) + ", string expected"));
3030
+ if (i.hooks && (i.hooks.options = i, i.hooks.block = e), i.async) return (async () => {
3031
+ let p = i.hooks ? await i.hooks.preprocess(n) : n, u = await (i.hooks ? await i.hooks.provideLexer(e) : e ? x.lex : x.lexInline)(p, i), c = i.hooks ? await i.hooks.processAllTokens(u) : u;
3032
+ i.walkTokens && await Promise.all(this.walkTokens(c, i.walkTokens));
3033
+ let k = await (i.hooks ? await i.hooks.provideParser(e) : e ? b.parse : b.parseInline)(c, i);
3034
+ return i.hooks ? await i.hooks.postprocess(k) : k;
3035
+ })().catch(o);
3036
+ try {
3037
+ i.hooks && (n = i.hooks.preprocess(n));
3038
+ let a = (i.hooks ? i.hooks.provideLexer(e) : e ? x.lex : x.lexInline)(n, i);
3039
+ i.hooks && (a = i.hooks.processAllTokens(a)), i.walkTokens && this.walkTokens(a, i.walkTokens);
3040
+ let c = (i.hooks ? i.hooks.provideParser(e) : e ? b.parse : b.parseInline)(a, i);
3041
+ return i.hooks && (c = i.hooks.postprocess(c)), c;
3042
+ } catch (p) {
3043
+ return o(p);
3044
+ }
3045
+ };
3046
+ }
3047
+ onError(e, t) {
3048
+ return (n) => {
3049
+ if (n.message += `
3050
+ Please report this to https://github.com/markedjs/marked.`, e) {
3051
+ let s = "<p>An error occurred:</p><pre>" + O(n.message + "", true) + "</pre>";
3052
+ return t ? Promise.resolve(s) : s;
3053
+ }
3054
+ if (t) return Promise.reject(n);
3055
+ throw n;
3056
+ };
3057
+ }
3058
+ };
3059
+ var E = new Z();
3060
+ function f(l3, e) {
3061
+ return E.parse(l3, e);
3062
+ }
3063
+ f.options = f.setOptions = function(l3) {
3064
+ return E.setOptions(l3), f.defaults = E.defaults, j(f.defaults), f;
3065
+ };
3066
+ f.getDefaults = C;
3067
+ f.defaults = R;
3068
+ function kt(...l3) {
3069
+ return E.use(...l3), f.defaults = E.defaults, j(f.defaults), f;
3070
+ }
3071
+ f.use = kt;
3072
+ f.walkTokens = function(l3, e) {
3073
+ return E.walkTokens(l3, e);
3074
+ };
3075
+ f.parseInline = E.parseInline;
3076
+ f.Parser = b;
3077
+ f.parser = b.parse;
3078
+ f.Renderer = P;
3079
+ f.TextRenderer = L;
3080
+ f.Lexer = x;
3081
+ f.lexer = x.lex;
3082
+ f.Tokenizer = y;
3083
+ f.Hooks = S;
3084
+ f.parse = f;
3085
+ var nn = f.options;
3086
+ var rn = f.setOptions;
3087
+ var sn = f.walkTokens;
3088
+ var on = f.parseInline;
3089
+ var ln = b.parse;
3090
+ var pn = x.lex;
3091
+
3092
+ // src/web-markdown-preview.ts
3093
+ f.use({
3094
+ gfm: true,
3095
+ breaks: false
3096
+ });
3097
+ var SAFE_LINK_PATTERN = /^(?:(?:https?|mailto|tel):|note:\/\/note_[a-f0-9]{32}$|[^a-z]|[a-z+.-]+(?:[^a-z+.-:]|$))/i;
3098
+ var NOTE_LINK_PATTERN = /^note:\/\/(note_[a-f0-9]{32})$/;
3099
+ function renderMarkdown(markdown) {
3100
+ const rendered = f.parse(markdown, { async: false });
3101
+ const sanitized = purify.sanitize(rendered, {
3102
+ FORBID_TAGS: ["style", "form", "input", "button", "textarea", "select", "option", "iframe", "object", "embed", "svg", "math", "video", "audio"],
3103
+ FORBID_ATTR: ["style"],
3104
+ RETURN_TRUSTED_TYPE: false,
3105
+ USE_PROFILES: { html: true },
3106
+ ALLOWED_URI_REGEXP: SAFE_LINK_PATTERN
3107
+ });
3108
+ const template = document.createElement("template");
3109
+ template.innerHTML = sanitized;
3110
+ for (const link of template.content.querySelectorAll("a")) {
3111
+ const note = NOTE_LINK_PATTERN.exec(link.getAttribute("href") ?? "");
3112
+ if (note?.[1]) {
3113
+ link.removeAttribute("href");
3114
+ link.dataset.noteId = note[1];
3115
+ link.classList.add("note-reference");
3116
+ continue;
3117
+ }
3118
+ link.target = "_blank";
3119
+ link.rel = "noopener noreferrer";
3120
+ }
3121
+ return template.innerHTML;
3122
+ }
29
3123
 
30
- // src/workspace-ownership.ts
31
- var WORKSPACE_ACTIVATE_EVENT = "@lemoncat7/dsh-plugin-ui/workspace-activate";
32
- function activatePluginWorkspace(pluginId) {
33
- window.dispatchEvent(new CustomEvent(WORKSPACE_ACTIVATE_EVENT, {
34
- detail: { pluginId }
35
- }));
3124
+ // src/knowledge-activity-notes.tsx
3125
+ var import_jsx_runtime = require("react/jsx-runtime");
3126
+ function KnowledgeActivityNotes({ sessionId, projectId, controller }) {
3127
+ const initial = controller.selection(sessionId);
3128
+ const [folderId, setFolderId] = (0, import_react.useState)(initial.noteFolderId ?? null);
3129
+ const [crumbs, setCrumbs] = (0, import_react.useState)(initial.noteCrumbs ?? [{ id: null, name: "\u5168\u90E8\u7B14\u8BB0" }]);
3130
+ const [selectedId, setSelectedId] = (0, import_react.useState)(initial.noteDocumentId);
3131
+ const [nodes, setNodes] = (0, import_react.useState)([]);
3132
+ const [content, setContent] = (0, import_react.useState)();
3133
+ const [queryInput, setQueryInput] = (0, import_react.useState)("");
3134
+ const [query, setQuery] = (0, import_react.useState)("");
3135
+ const [listState, setListState] = (0, import_react.useState)("loading");
3136
+ const [contentState, setContentState] = (0, import_react.useState)("idle");
3137
+ const [error, setError] = (0, import_react.useState)("");
3138
+ const listRequest = (0, import_react.useRef)(new LatestRequest());
3139
+ const [refresh, setRefresh] = (0, import_react.useState)(0);
3140
+ const loadNodes = (0, import_react.useCallback)(async () => {
3141
+ const signal = listRequest.current.start();
3142
+ setListState("loading");
3143
+ setError("");
3144
+ try {
3145
+ const value = await loadNoteIndex({
3146
+ sessionId,
3147
+ ...projectId === void 0 ? {} : { projectId },
3148
+ parentId: folderId,
3149
+ query,
3150
+ ...signal === void 0 ? {} : { signal }
3151
+ });
3152
+ if (signal.aborted) return;
3153
+ setNodes(value);
3154
+ setListState("ready");
3155
+ } catch (reason) {
3156
+ if (signal?.aborted) return;
3157
+ setListState("error");
3158
+ setError(message(reason));
3159
+ }
3160
+ }, [folderId, projectId, query, sessionId]);
3161
+ (0, import_react.useEffect)(() => {
3162
+ void loadNodes();
3163
+ return () => {
3164
+ listRequest.current.cancel();
3165
+ };
3166
+ }, [loadNodes, refresh]);
3167
+ (0, import_react.useEffect)(() => {
3168
+ if (selectedId === void 0) {
3169
+ setContent(void 0);
3170
+ setContentState("idle");
3171
+ return;
3172
+ }
3173
+ const abort = new AbortController();
3174
+ setContentState("loading");
3175
+ setError("");
3176
+ void loadNoteContent({
3177
+ id: selectedId,
3178
+ sessionId,
3179
+ ...projectId === void 0 ? {} : { projectId },
3180
+ signal: abort.signal
3181
+ }).then((value) => {
3182
+ if (abort.signal.aborted) return;
3183
+ setContent(value);
3184
+ setContentState("ready");
3185
+ }).catch((reason) => {
3186
+ if (abort.signal.aborted) return;
3187
+ setContentState("error");
3188
+ setError(message(reason));
3189
+ });
3190
+ return () => {
3191
+ abort.abort();
3192
+ };
3193
+ }, [projectId, refresh, selectedId, sessionId]);
3194
+ const openFolder = (node) => {
3195
+ setFolderId(node.id);
3196
+ const nextCrumbs = [...crumbs, { id: node.id, name: node.name }];
3197
+ setCrumbs(nextCrumbs);
3198
+ setQuery("");
3199
+ setQueryInput("");
3200
+ controller.select(sessionId, { mode: "notes", noteFolderId: node.id, noteDocumentId: void 0, noteCrumbs: nextCrumbs });
3201
+ };
3202
+ const openCrumb = (crumb, index) => {
3203
+ setFolderId(crumb.id);
3204
+ const nextCrumbs = crumbs.slice(0, index + 1);
3205
+ setCrumbs(nextCrumbs);
3206
+ setSelectedId(void 0);
3207
+ controller.select(sessionId, { mode: "notes", noteFolderId: crumb.id, noteDocumentId: void 0, noteCrumbs: nextCrumbs });
3208
+ };
3209
+ const openNode = (node) => {
3210
+ if (node.kind === "folder") return openFolder(node);
3211
+ if (!node.editable) return;
3212
+ setSelectedId(node.id);
3213
+ controller.select(sessionId, { ...controller.selection(sessionId), mode: "notes", noteFolderId: folderId, noteDocumentId: node.id });
3214
+ };
3215
+ const closeDocument = () => {
3216
+ setSelectedId(void 0);
3217
+ setContent(void 0);
3218
+ controller.select(sessionId, { ...controller.selection(sessionId), mode: "notes", noteFolderId: folderId, noteDocumentId: void 0 });
3219
+ };
3220
+ const submitSearch = (event) => {
3221
+ event.preventDefault();
3222
+ setSelectedId(void 0);
3223
+ setContent(void 0);
3224
+ controller.select(sessionId, { noteDocumentId: void 0 });
3225
+ setQuery(queryInput.trim());
3226
+ };
3227
+ if (selectedId !== void 0) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
3228
+ NoteReader,
3229
+ {
3230
+ value: content,
3231
+ state: contentState,
3232
+ error,
3233
+ onBack: closeDocument,
3234
+ onRetry: () => setRefresh((value) => value + 1)
3235
+ }
3236
+ );
3237
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsh-knowledge-activity-browser", children: [
3238
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("form", { className: "dsh-knowledge-activity-search", role: "search", onSubmit: submitSearch, children: [
3239
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dsh_client_ui_primitives.IconSearchOutline16, { size: 16, "aria-hidden": "true" }),
3240
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", { "aria-label": "\u641C\u7D22\u7B14\u8BB0\u6587\u6863", value: queryInput, placeholder: "\u641C\u7D22\u7B14\u8BB0\u548C\u76EE\u5F55\u2026", onChange: (event) => setQueryInput(event.target.value) }),
3241
+ queryInput && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", onClick: () => {
3242
+ setQueryInput("");
3243
+ setQuery("");
3244
+ }, "aria-label": "\u6E05\u9664\u641C\u7D22", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dsh_client_ui_primitives.IconCloseOutline16, { size: 14 }) })
3245
+ ] }),
3246
+ !query && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("nav", { className: "dsh-knowledge-activity-breadcrumbs", "aria-label": "\u7B14\u8BB0\u76EE\u5F55\u8DEF\u5F84", children: crumbs.map((crumb, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { children: [
3247
+ index > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dsh_client_ui_primitives.IconChevronRightOutline14, { size: 12 }),
3248
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", "aria-current": index === crumbs.length - 1 ? "location" : void 0, onClick: () => openCrumb(crumb, index), children: crumb.name })
3249
+ ] }, `${crumb.id ?? "root"}-${index}`)) }),
3250
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsh-knowledge-activity-list-heading", children: [
3251
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { children: [
3252
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { children: query ? `\u201C${query}\u201D \u7684\u7ED3\u679C` : crumbs.at(-1)?.name ?? "\u7B14\u8BB0\u6587\u6863" }),
3253
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("small", { children: query ? "\u641C\u7D22\u5168\u90E8\u7B14\u8BB0" : `\u5F53\u524D\u663E\u793A ${nodes.length} \u9879` })
3254
+ ] }),
3255
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "dsh-knowledge-activity-icon-button", "aria-label": "\u5237\u65B0\u7B14\u8BB0", title: "\u5237\u65B0", onClick: () => setRefresh((value) => value + 1), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dsh_client_ui_primitives.IconRefreshOutline14, { size: 14 }) })
3256
+ ] }),
3257
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dsh-knowledge-activity-list", "aria-busy": listState === "loading", children: listState === "loading" && nodes.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ActivityState, { label: "\u6B63\u5728\u8BFB\u53D6\u7B14\u8BB0\u2026" }) : listState === "error" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ActivityError, { error, onRetry: () => setRefresh((value) => value + 1) }) : nodes.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ActivityEmpty, { query }) : nodes.map((node) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", { type: "button", className: "dsh-knowledge-activity-row", disabled: node.kind !== "folder" && !node.editable, onClick: () => openNode(node), children: [
3258
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dsh-knowledge-activity-row-icon", children: node.kind === "folder" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dsh_client_ui_primitives.IconFolderOpenOutline16, { size: 16 }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dsh_client_ui_primitives.IconDataOutline16, { size: 16 }) }),
3259
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "dsh-knowledge-activity-row-copy", children: [
3260
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { children: node.name }),
3261
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("small", { children: node.kind === "folder" ? "\u76EE\u5F55" : node.editable ? formatSize(node.size) : "\u6682\u4E0D\u652F\u6301\u4FA7\u680F\u9884\u89C8" })
3262
+ ] }),
3263
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "dsh-knowledge-activity-row-meta", children: [
3264
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("time", { dateTime: node.updatedAt, children: formatDate(node.updatedAt) }),
3265
+ node.kind === "folder" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dsh_client_ui_primitives.IconChevronRightOutline14, { size: 13 })
3266
+ ] })
3267
+ ] }, node.id)) })
3268
+ ] });
36
3269
  }
37
- function observePluginWorkspace(pluginId, close) {
38
- const onActivate = (event) => {
39
- const detail = event.detail;
40
- if (detail?.pluginId !== pluginId) close();
3270
+ function NoteReader({ value, state, error, onBack, onRetry }) {
3271
+ const html2 = (0, import_react.useMemo)(() => value === void 0 ? "" : renderMarkdown(value.content), [value]);
3272
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsh-knowledge-activity-reader", children: [
3273
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsh-knowledge-activity-reader-bar", children: [
3274
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", { type: "button", className: "dsh-knowledge-activity-back", onClick: onBack, children: [
3275
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dsh_client_ui_primitives.IconChevronLeftOutline14, { size: 14 }),
3276
+ "\u7B14\u8BB0\u76EE\u5F55"
3277
+ ] }),
3278
+ value && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { children: [
3279
+ formatDate(value.node.updatedAt),
3280
+ " \u66F4\u65B0"
3281
+ ] })
3282
+ ] }),
3283
+ state === "loading" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ActivityState, { label: "\u6B63\u5728\u6253\u5F00\u7B14\u8BB0\u2026" }) : state === "error" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ActivityError, { error, onRetry }) : value === void 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ActivityState, { label: "\u6B63\u5728\u51C6\u5907\u7B14\u8BB0\u2026" }) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
3284
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsh-knowledge-activity-document-heading", children: [
3285
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dsh-knowledge-activity-document-icon", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dsh_client_ui_primitives.IconDataOutline16, { size: 18 }) }),
3286
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
3287
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { children: value.node.name }),
3288
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { children: [
3289
+ "\u7B14\u8BB0\u6587\u6863 \xB7 ",
3290
+ formatSize(value.node.size)
3291
+ ] })
3292
+ ] })
3293
+ ] }),
3294
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("article", { className: "dsh-knowledge-activity-markdown", dangerouslySetInnerHTML: { __html: html2 } })
3295
+ ] })
3296
+ ] });
3297
+ }
3298
+ function ActivityState({ label }) {
3299
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { className: "dsh-knowledge-activity-state", role: "status", children: [
3300
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { "aria-hidden": "true" }),
3301
+ label
3302
+ ] });
3303
+ }
3304
+ function ActivityError({ error, onRetry }) {
3305
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsh-knowledge-activity-error", role: "alert", children: [
3306
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { children: "\u6682\u65F6\u65E0\u6CD5\u8BFB\u53D6" }),
3307
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: error }),
3308
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", onClick: onRetry, children: "\u91CD\u8BD5" })
3309
+ ] });
3310
+ }
3311
+ function ActivityEmpty({ query }) {
3312
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsh-knowledge-activity-empty", children: [
3313
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dsh_client_ui_primitives.IconDataOutline16, { size: 20 }) }),
3314
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { children: query ? "\u6CA1\u6709\u627E\u5230\u76F8\u5173\u7B14\u8BB0" : "\u8FD9\u4E2A\u76EE\u5F55\u8FD8\u662F\u7A7A\u7684" }),
3315
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: query ? "\u6362\u4E2A\u5173\u952E\u8BCD\uFF0C\u6216\u6E05\u9664\u641C\u7D22\u540E\u6D4F\u89C8\u76EE\u5F55\u3002" : "\u53EF\u4EE5\u5728\u5B8C\u6574\u5DE5\u4F5C\u533A\u4E2D\u65B0\u5EFA\u6216\u5BFC\u5165\u7B14\u8BB0\u3002" })
3316
+ ] });
3317
+ }
3318
+ function formatDate(value) {
3319
+ const date = new Date(value);
3320
+ if (Number.isNaN(date.getTime())) return "\u672A\u77E5\u65F6\u95F4";
3321
+ return new Intl.DateTimeFormat("zh-CN", { month: "2-digit", day: "2-digit" }).format(date);
3322
+ }
3323
+ function formatSize(value) {
3324
+ if (value < 1024) return `${value} B`;
3325
+ if (value < 1024 * 1024) return `${(value / 1024).toFixed(value < 10 * 1024 ? 1 : 0)} KB`;
3326
+ return `${(value / 1024 / 1024).toFixed(1)} MB`;
3327
+ }
3328
+ function message(reason) {
3329
+ return reason instanceof Error ? reason.message : String(reason);
3330
+ }
3331
+
3332
+ // src/knowledge-activity-panel.tsx
3333
+ var import_jsx_runtime2 = require("react/jsx-runtime");
3334
+ function KnowledgeActivityPanel(props) {
3335
+ const sessionId = String(props.sessionId);
3336
+ const projectId = props.useSessions((state) => state.byId[sessionId]?.cwd);
3337
+ const initial = props.controller.selection(sessionId);
3338
+ const [mode, setMode] = (0, import_react2.useState)(initial.mode ?? "knowledge");
3339
+ const [mounts, setMounts] = (0, import_react2.useState)([]);
3340
+ const [selectedBaseId, setSelectedBaseId] = (0, import_react2.useState)(initial.knowledgeBaseId);
3341
+ const [selectedDocumentId, setSelectedDocumentId] = (0, import_react2.useState)(initial.documentId);
3342
+ const [documents, setDocuments] = (0, import_react2.useState)([]);
3343
+ const [documentValue, setDocumentValue] = (0, import_react2.useState)();
3344
+ const [queryInput, setQueryInput] = (0, import_react2.useState)("");
3345
+ const [query, setQuery] = (0, import_react2.useState)("");
3346
+ const [mountState, setMountState] = (0, import_react2.useState)("loading");
3347
+ const [listState, setListState] = (0, import_react2.useState)("idle");
3348
+ const [documentState, setDocumentState] = (0, import_react2.useState)("idle");
3349
+ const [documentRefresh, setDocumentRefresh] = (0, import_react2.useState)(0);
3350
+ const [error, setError] = (0, import_react2.useState)("");
3351
+ const [nextCursor, setNextCursor] = (0, import_react2.useState)();
3352
+ const [baseMenuOpen, setBaseMenuOpen] = (0, import_react2.useState)(false);
3353
+ const indexRequest = (0, import_react2.useRef)(new LatestRequest());
3354
+ const mountRequest = (0, import_react2.useRef)(new LatestRequest());
3355
+ const scopeRef = (0, import_react2.useRef)(null);
3356
+ (0, import_react2.useEffect)(() => {
3357
+ if (!baseMenuOpen) return;
3358
+ const closeOutside = (event) => {
3359
+ if (!scopeRef.current?.contains(event.target)) setBaseMenuOpen(false);
3360
+ };
3361
+ const closeOnEscape = (event) => {
3362
+ if (event.key === "Escape") setBaseMenuOpen(false);
3363
+ };
3364
+ document.addEventListener("pointerdown", closeOutside);
3365
+ document.addEventListener("keydown", closeOnEscape);
3366
+ return () => {
3367
+ document.removeEventListener("pointerdown", closeOutside);
3368
+ document.removeEventListener("keydown", closeOnEscape);
3369
+ };
3370
+ }, [baseMenuOpen]);
3371
+ const refreshMounts = (0, import_react2.useCallback)(async () => {
3372
+ const signal = mountRequest.current.start();
3373
+ setMountState("loading");
3374
+ setError("");
3375
+ try {
3376
+ const next = await loadMountedKnowledge(sessionId, projectId, signal);
3377
+ if (signal.aborted) return;
3378
+ setMounts(next);
3379
+ const current = props.controller.selection(sessionId);
3380
+ const selected = next.some((item) => item.knowledgeBaseId === current.knowledgeBaseId) ? current.knowledgeBaseId : next[0]?.knowledgeBaseId;
3381
+ props.controller.select(sessionId, {
3382
+ knowledgeBaseId: selected,
3383
+ documentId: selected === current.knowledgeBaseId ? current.documentId : void 0
3384
+ });
3385
+ setSelectedBaseId(selected);
3386
+ if (selected !== current.knowledgeBaseId) {
3387
+ setSelectedDocumentId(void 0);
3388
+ setDocumentValue(void 0);
3389
+ }
3390
+ setMountState("ready");
3391
+ } catch (reason) {
3392
+ if (signal?.aborted) return;
3393
+ setMountState("error");
3394
+ setError(message2(reason));
3395
+ }
3396
+ }, [projectId, props.controller, sessionId]);
3397
+ (0, import_react2.useEffect)(() => {
3398
+ void refreshMounts();
3399
+ return () => {
3400
+ mountRequest.current.cancel();
3401
+ };
3402
+ }, [refreshMounts]);
3403
+ const loadIndex = (0, import_react2.useCallback)(async (cursor, append = false) => {
3404
+ const signal = indexRequest.current.start();
3405
+ if (mounts.length === 0 || query.length === 0 && selectedBaseId === void 0) {
3406
+ setDocuments([]);
3407
+ setNextCursor(void 0);
3408
+ setListState("ready");
3409
+ return;
3410
+ }
3411
+ setListState("loading");
3412
+ setError("");
3413
+ try {
3414
+ const result = await loadKnowledgeDocumentIndex({
3415
+ sessionId,
3416
+ ...projectId === void 0 ? {} : { projectId },
3417
+ knowledgeBaseIds: query ? mounts.map((item) => item.knowledgeBaseId) : [selectedBaseId],
3418
+ ...query ? { query } : {},
3419
+ ...cursor === void 0 ? {} : { cursor },
3420
+ ...signal === void 0 ? {} : { signal }
3421
+ });
3422
+ if (signal.aborted) return;
3423
+ setDocuments((current) => append ? [...current, ...result.items] : result.items);
3424
+ setNextCursor(result.nextCursor);
3425
+ setListState("ready");
3426
+ } catch (reason) {
3427
+ if (signal?.aborted) return;
3428
+ setListState("error");
3429
+ setError(message2(reason));
3430
+ }
3431
+ }, [mounts, projectId, query, selectedBaseId, sessionId]);
3432
+ (0, import_react2.useEffect)(() => {
3433
+ void loadIndex();
3434
+ return () => {
3435
+ indexRequest.current.cancel();
3436
+ };
3437
+ }, [loadIndex]);
3438
+ (0, import_react2.useEffect)(() => {
3439
+ if (selectedDocumentId === void 0) {
3440
+ setDocumentValue(void 0);
3441
+ setDocumentState("idle");
3442
+ return;
3443
+ }
3444
+ const controller = new AbortController();
3445
+ setDocumentState("loading");
3446
+ setError("");
3447
+ void loadKnowledgeDocument({
3448
+ id: selectedDocumentId,
3449
+ sessionId,
3450
+ ...projectId === void 0 ? {} : { projectId },
3451
+ signal: controller.signal
3452
+ }).then((value) => {
3453
+ if (controller.signal.aborted) return;
3454
+ setDocumentValue(value);
3455
+ setDocumentState("ready");
3456
+ }).catch((reason) => {
3457
+ if (controller.signal.aborted) return;
3458
+ setDocumentState("error");
3459
+ setError(message2(reason));
3460
+ });
3461
+ return () => {
3462
+ controller.abort();
3463
+ };
3464
+ }, [documentRefresh, projectId, selectedDocumentId, sessionId]);
3465
+ const selectBase = (knowledgeBaseId) => {
3466
+ setBaseMenuOpen(false);
3467
+ setSelectedBaseId(knowledgeBaseId);
3468
+ setSelectedDocumentId(void 0);
3469
+ setDocumentValue(void 0);
3470
+ setQueryInput("");
3471
+ setQuery("");
3472
+ props.controller.select(sessionId, { mode: "knowledge", knowledgeBaseId, documentId: void 0 });
41
3473
  };
42
- window.addEventListener(WORKSPACE_ACTIVATE_EVENT, onActivate);
43
- return () => window.removeEventListener(WORKSPACE_ACTIVATE_EVENT, onActivate);
3474
+ const selectDocument = (document2) => {
3475
+ setSelectedBaseId(document2.knowledgeBaseId);
3476
+ setSelectedDocumentId(document2.id);
3477
+ props.controller.select(sessionId, {
3478
+ mode: "knowledge",
3479
+ knowledgeBaseId: document2.knowledgeBaseId,
3480
+ documentId: document2.id
3481
+ });
3482
+ };
3483
+ const closeDocument = () => {
3484
+ setSelectedDocumentId(void 0);
3485
+ setDocumentValue(void 0);
3486
+ props.controller.select(sessionId, {
3487
+ mode: "knowledge",
3488
+ documentId: void 0,
3489
+ ...selectedBaseId === void 0 ? {} : { knowledgeBaseId: selectedBaseId }
3490
+ });
3491
+ };
3492
+ const submitSearch = (event) => {
3493
+ event.preventDefault();
3494
+ setSelectedDocumentId(void 0);
3495
+ setDocumentValue(void 0);
3496
+ props.controller.select(sessionId, { documentId: void 0 });
3497
+ setQuery(queryInput.trim());
3498
+ };
3499
+ const clearSearch = () => {
3500
+ setQueryInput("");
3501
+ setQuery("");
3502
+ };
3503
+ const openWorkspace = () => {
3504
+ const noteId = props.controller.selection(sessionId).noteDocumentId;
3505
+ props.controller.openWorkspace(mode === "notes" ? { view: "notes", ...noteId === void 0 ? {} : { noteId } } : documentValue === void 0 ? void 0 : {
3506
+ knowledgeBaseId: documentValue.knowledgeBaseId,
3507
+ documentId: documentValue.id
3508
+ });
3509
+ };
3510
+ const selectMode = (nextMode) => {
3511
+ setMode(nextMode);
3512
+ setBaseMenuOpen(false);
3513
+ props.controller.select(sessionId, { ...props.controller.selection(sessionId), mode: nextMode });
3514
+ };
3515
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("section", { className: "dsh-knowledge-activity-panel", "data-knowledge-surface": "activity", "aria-label": "\u4F1A\u8BDD\u77E5\u8BC6\u5E93", children: [
3516
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("header", { className: "dsh-knowledge-activity-header", children: [
3517
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dsh-knowledge-activity-title", children: [
3518
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "dsh-knowledge-activity-mark", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_dsh_client_ui_primitives2.IconDatabaseOutline16, { size: 17 }) }),
3519
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { children: [
3520
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("strong", { children: "\u77E5\u8BC6\u5E93" }),
3521
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("small", { children: [
3522
+ "\u5F53\u524D\u4F1A\u8BDD \xB7 ",
3523
+ shortId(sessionId)
3524
+ ] })
3525
+ ] })
3526
+ ] }),
3527
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dsh-knowledge-activity-header-actions", children: [
3528
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: "dsh-knowledge-activity-icon-button", "aria-label": "\u5728\u5B8C\u6574\u5DE5\u4F5C\u533A\u4E2D\u6253\u5F00", title: "\u5B8C\u6574\u5DE5\u4F5C\u533A", onClick: openWorkspace, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_dsh_client_ui_primitives2.IconFullscreenOutline16, { size: 16 }) }),
3529
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: "dsh-knowledge-activity-icon-button", "aria-label": "\u5173\u95ED\u4F1A\u8BDD\u77E5\u8BC6\u5E93", title: "\u5173\u95ED", onClick: () => props.controller.close(sessionId), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_dsh_client_ui_primitives2.IconCloseOutline16, { size: 16 }) })
3530
+ ] })
3531
+ ] }),
3532
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("nav", { className: "dsh-knowledge-activity-tabs", "aria-label": "\u77E5\u8BC6\u5E93\u5185\u5BB9\u7C7B\u578B", children: [
3533
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("button", { type: "button", className: mode === "knowledge" ? "is-active" : "", "aria-pressed": mode === "knowledge", onClick: () => selectMode("knowledge"), children: [
3534
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_dsh_client_ui_primitives2.IconDatabaseOutline16, { size: 15 }),
3535
+ "\u77E5\u8BC6\u6587\u6863"
3536
+ ] }),
3537
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("button", { type: "button", className: mode === "notes" ? "is-active" : "", "aria-pressed": mode === "notes", onClick: () => selectMode("notes"), children: [
3538
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_dsh_client_ui_primitives2.IconDataOutline16, { size: 15 }),
3539
+ "\u7B14\u8BB0\u6587\u6863"
3540
+ ] })
3541
+ ] }),
3542
+ mode === "notes" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(KnowledgeActivityNotes, { sessionId, projectId, controller: props.controller }) : selectedDocumentId === void 0 ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dsh-knowledge-activity-browser", children: [
3543
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("form", { className: "dsh-knowledge-activity-search", role: "search", onSubmit: submitSearch, children: [
3544
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_dsh_client_ui_primitives2.IconSearchOutline16, { size: 16, "aria-hidden": "true" }),
3545
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("input", { "aria-label": "\u641C\u7D22\u5F53\u524D\u4F1A\u8BDD\u77E5\u8BC6\u6587\u6863", value: queryInput, placeholder: "\u641C\u7D22\u5DF2\u6302\u8F7D\u77E5\u8BC6\u2026", onChange: (event) => setQueryInput(event.target.value) }),
3546
+ queryInput && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", onClick: clearSearch, "aria-label": "\u6E05\u9664\u641C\u7D22", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_dsh_client_ui_primitives2.IconCloseOutline16, { size: 14 }) })
3547
+ ] }),
3548
+ mountState === "loading" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ActivityState2, { label: "\u6B63\u5728\u8BFB\u53D6\u4F1A\u8BDD\u6302\u8F7D\u2026" }) : mountState === "error" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ActivityError2, { message: error, onRetry: () => {
3549
+ void refreshMounts();
3550
+ } }) : mounts.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ActivityEmpty2, { title: "\u5F53\u524D\u4F1A\u8BDD\u6CA1\u6709\u6302\u8F7D\u77E5\u8BC6\u5E93", description: "\u5728\u5B8C\u6574\u5DE5\u4F5C\u533A\u4E2D\u6302\u8F7D\u540E\uFF0C\u5C31\u80FD\u5728\u8FD9\u91CC\u968F\u624B\u67E5\u9605\u6587\u6863\u3002" }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
3551
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { ref: scopeRef, className: "dsh-knowledge-activity-scope", children: [
3552
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("button", { type: "button", className: "dsh-knowledge-activity-scope-trigger", "aria-haspopup": "listbox", "aria-expanded": baseMenuOpen, onClick: () => setBaseMenuOpen((value) => !value), children: [
3553
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "dsh-knowledge-activity-scope-icon", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_dsh_client_ui_primitives2.IconDatabaseOutline16, { size: 15 }) }),
3554
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { children: [
3555
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("small", { children: "\u5F53\u524D\u77E5\u8BC6\u5E93" }),
3556
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("strong", { children: mounts.find((item) => item.knowledgeBaseId === selectedBaseId)?.base.name })
3557
+ ] }),
3558
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_dsh_client_ui_primitives2.IconChevronDownOutline14, { size: 14, className: baseMenuOpen ? "is-open" : "" })
3559
+ ] }),
3560
+ baseMenuOpen && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dsh-knowledge-activity-scope-menu", role: "listbox", "aria-label": "\u5207\u6362\u77E5\u8BC6\u5E93", children: mounts.map((mount) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
3561
+ "button",
3562
+ {
3563
+ type: "button",
3564
+ role: "option",
3565
+ "aria-selected": selectedBaseId === mount.knowledgeBaseId,
3566
+ className: selectedBaseId === mount.knowledgeBaseId ? "is-active" : "",
3567
+ onClick: () => selectBase(mount.knowledgeBaseId),
3568
+ children: [
3569
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_dsh_client_ui_primitives2.IconDataOutline16, { size: 15 }),
3570
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { children: [
3571
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("strong", { children: mount.base.name }),
3572
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("small", { children: mount.inheritedFrom === "project" ? "\u9879\u76EE\u6302\u8F7D" : "\u4F1A\u8BDD\u6302\u8F7D" })
3573
+ ] })
3574
+ ]
3575
+ },
3576
+ mount.knowledgeBaseId
3577
+ )) })
3578
+ ] }),
3579
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dsh-knowledge-activity-list-heading", children: [
3580
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { children: [
3581
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("strong", { children: query ? `\u201C${query}\u201D \u7684\u7ED3\u679C` : "\u77E5\u8BC6\u6587\u6863" }),
3582
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("small", { children: query ? "\u641C\u7D22\u5168\u90E8\u5DF2\u6302\u8F7D\u77E5\u8BC6\u5E93" : `\u5F53\u524D\u663E\u793A ${documents.length} \u9879` })
3583
+ ] }),
3584
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: "dsh-knowledge-activity-icon-button", "aria-label": "\u5237\u65B0\u6587\u6863", title: "\u5237\u65B0", onClick: () => {
3585
+ void loadIndex();
3586
+ }, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_dsh_client_ui_primitives2.IconRefreshOutline14, { size: 14 }) })
3587
+ ] }),
3588
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dsh-knowledge-activity-list", "aria-busy": listState === "loading", children: listState === "loading" && documents.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ActivityState2, { label: "\u6B63\u5728\u8BFB\u53D6\u6587\u6863\u2026" }) : listState === "error" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ActivityError2, { message: error, onRetry: () => {
3589
+ void loadIndex();
3590
+ } }) : documents.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ActivityEmpty2, { title: query ? "\u6CA1\u6709\u627E\u5230\u76F8\u5173\u6587\u6863" : "\u8FD9\u91CC\u8FD8\u6CA1\u6709\u77E5\u8BC6\u6587\u6863", description: query ? "\u6362\u4E2A\u5173\u952E\u8BCD\uFF0C\u6216\u6E05\u9664\u641C\u7D22\u540E\u6D4F\u89C8\u76EE\u5F55\u3002" : "\u5BA1\u6838\u901A\u8FC7\u6216\u76F4\u63A5\u56DE\u5199\u7684\u77E5\u8BC6\u4F1A\u51FA\u73B0\u5728\u8FD9\u91CC\u3002" }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
3591
+ documents.map((document2) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
3592
+ DocumentRow,
3593
+ {
3594
+ document: document2,
3595
+ baseName: query ? mounts.find((item) => item.knowledgeBaseId === document2.knowledgeBaseId)?.base.name : void 0,
3596
+ onClick: () => selectDocument(document2)
3597
+ },
3598
+ document2.id
3599
+ )),
3600
+ nextCursor && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: "dsh-knowledge-activity-load-more", disabled: listState === "loading", onClick: () => {
3601
+ void loadIndex(nextCursor, true);
3602
+ }, children: listState === "loading" ? "\u6B63\u5728\u52A0\u8F7D\u2026" : "\u52A0\u8F7D\u66F4\u591A" })
3603
+ ] }) })
3604
+ ] })
3605
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
3606
+ DocumentReader,
3607
+ {
3608
+ value: documentValue,
3609
+ state: documentState,
3610
+ error,
3611
+ onBack: closeDocument,
3612
+ onRetry: () => setDocumentRefresh((value) => value + 1)
3613
+ }
3614
+ )
3615
+ ] });
3616
+ }
3617
+ function DocumentRow({ document: document2, baseName, onClick }) {
3618
+ const stateLabel = document2.documentState === "resolved" ? "\u5DF2\u89E3\u51B3" : document2.documentState === "complete" ? "\u5DF2\u5B8C\u6210" : void 0;
3619
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("button", { type: "button", className: "dsh-knowledge-activity-row", onClick, children: [
3620
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "dsh-knowledge-activity-row-icon", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_dsh_client_ui_primitives2.IconDataOutline16, { size: 16 }) }),
3621
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "dsh-knowledge-activity-row-copy", children: [
3622
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("strong", { children: document2.title }),
3623
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("small", { children: baseName ? `${baseName} \xB7 ${document2.relPath}` : document2.relPath })
3624
+ ] }),
3625
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "dsh-knowledge-activity-row-meta", children: [
3626
+ stateLabel && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("em", { children: stateLabel }),
3627
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("time", { dateTime: document2.updatedAt, children: formatDate2(document2.updatedAt) })
3628
+ ] })
3629
+ ] });
3630
+ }
3631
+ function DocumentReader({ value, state, error, onBack, onRetry }) {
3632
+ const html2 = (0, import_react2.useMemo)(() => value === void 0 ? "" : renderMarkdown(readableMarkdown(value.content)), [value]);
3633
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dsh-knowledge-activity-reader", children: [
3634
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dsh-knowledge-activity-reader-bar", children: [
3635
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("button", { type: "button", className: "dsh-knowledge-activity-back", onClick: onBack, children: [
3636
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_dsh_client_ui_primitives2.IconChevronLeftOutline14, { size: 14 }),
3637
+ "\u6587\u6863\u76EE\u5F55"
3638
+ ] }),
3639
+ value && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { children: [
3640
+ formatDate2(value.updatedAt),
3641
+ " \u66F4\u65B0"
3642
+ ] })
3643
+ ] }),
3644
+ state === "loading" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ActivityState2, { label: "\u6B63\u5728\u6253\u5F00\u6587\u6863\u2026" }) : state === "error" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ActivityError2, { message: error, onRetry }) : value === void 0 ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ActivityState2, { label: "\u6B63\u5728\u51C6\u5907\u6587\u6863\u2026" }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
3645
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dsh-knowledge-activity-document-heading", children: [
3646
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "dsh-knowledge-activity-document-icon", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_dsh_client_ui_primitives2.IconDataOutline16, { size: 18 }) }),
3647
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
3648
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("h2", { children: value.title }),
3649
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { children: value.relPath })
3650
+ ] })
3651
+ ] }),
3652
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("article", { className: "dsh-knowledge-activity-markdown", dangerouslySetInnerHTML: { __html: html2 } })
3653
+ ] })
3654
+ ] });
3655
+ }
3656
+ function ActivityState2({ label }) {
3657
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("p", { className: "dsh-knowledge-activity-state", role: "status", children: [
3658
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { "aria-hidden": "true" }),
3659
+ label
3660
+ ] });
3661
+ }
3662
+ function ActivityError2({ message: message3, onRetry }) {
3663
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dsh-knowledge-activity-error", role: "alert", children: [
3664
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("strong", { children: "\u6682\u65F6\u65E0\u6CD5\u8BFB\u53D6" }),
3665
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { children: message3 }),
3666
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", onClick: onRetry, children: "\u91CD\u8BD5" })
3667
+ ] });
3668
+ }
3669
+ function ActivityEmpty2({ title, description }) {
3670
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dsh-knowledge-activity-empty", children: [
3671
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_dsh_client_ui_primitives2.IconDatabaseOutline16, { size: 20 }) }),
3672
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("strong", { children: title }),
3673
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { children: description })
3674
+ ] });
3675
+ }
3676
+ function readableMarkdown(value) {
3677
+ return value.replace(/^---\s*\n[\s\S]*?\n---\s*\n*/u, "").replace(/^#\s+[^\n]+\n*/u, "");
3678
+ }
3679
+ function shortId(value) {
3680
+ return value.length <= 12 ? value : `${value.slice(0, 7)}\u2026${value.slice(-5)}`;
3681
+ }
3682
+ function formatDate2(value) {
3683
+ const date = new Date(value);
3684
+ if (Number.isNaN(date.getTime())) return "\u672A\u77E5\u65F6\u95F4";
3685
+ return new Intl.DateTimeFormat("zh-CN", { month: "2-digit", day: "2-digit" }).format(date);
3686
+ }
3687
+ function message2(reason) {
3688
+ return reason instanceof Error ? reason.message : String(reason);
44
3689
  }
45
3690
 
46
- // src/client.tsx
47
- var import_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
3691
+ // src/knowledge-activity-presentation.tsx
3692
+ var import_react3 = require("react");
3693
+ var import_jsx_runtime3 = require("react/jsx-runtime");
3694
+ function KnowledgeActivityPresentation({ controller, sessionId, onClosed, children }) {
3695
+ const root = (0, import_react3.useRef)(null);
3696
+ const open = (0, import_react3.useSyncExternalStore)(controller.subscribe, () => controller.isOpen(sessionId));
3697
+ (0, import_react3.useLayoutEffect)(() => {
3698
+ const viewport = root.current;
3699
+ const panel = viewport?.firstElementChild;
3700
+ if (!viewport || !panel) return;
3701
+ let cancelled = false;
3702
+ let timeout;
3703
+ let reveal;
3704
+ const width = panel.getBoundingClientRect().width;
3705
+ panel.style.width = `${width > 1 ? width : 360}px`;
3706
+ viewport.toggleAttribute("inert", !open);
3707
+ const settle = () => {
3708
+ if (cancelled) return;
3709
+ cancelled = true;
3710
+ if (timeout !== void 0) clearTimeout(timeout);
3711
+ reveal?.cancel();
3712
+ panel.style.removeProperty("width");
3713
+ if (!open) onClosed();
3714
+ };
3715
+ const reducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
3716
+ if (!open && reducedMotion) {
3717
+ settle();
3718
+ return;
3719
+ }
3720
+ const frame = requestAnimationFrame(() => {
3721
+ const transitions = [];
3722
+ for (let parent = viewport.parentElement; parent; parent = parent.parentElement) {
3723
+ for (const animation of parent.getAnimations()) {
3724
+ if ("transitionProperty" in animation && animation.transitionProperty === "grid-template-columns") transitions.push(animation);
3725
+ }
3726
+ if (transitions.length > 0) break;
3727
+ }
3728
+ if (open && transitions.length > 0) {
3729
+ for (const transition of transitions) transition.finish();
3730
+ panel.style.removeProperty("width");
3731
+ if (!reducedMotion) {
3732
+ reveal = panel.animate([
3733
+ { transform: "translateX(100%)" },
3734
+ { transform: "translateX(0)" }
3735
+ ], { duration: 180, easing: "cubic-bezier(.22, 1, .36, 1)" });
3736
+ }
3737
+ }
3738
+ timeout = setTimeout(settle, 1e3);
3739
+ void Promise.allSettled((reveal ? [reveal] : transitions).map((animation) => animation.finished)).then(settle);
3740
+ });
3741
+ return () => {
3742
+ cancelled = true;
3743
+ cancelAnimationFrame(frame);
3744
+ if (timeout !== void 0) clearTimeout(timeout);
3745
+ reveal?.cancel();
3746
+ panel.style.removeProperty("width");
3747
+ };
3748
+ }, [open, onClosed]);
3749
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { ref: root, className: "dsh-knowledge-activity-viewport", "aria-hidden": !open || void 0, children });
3750
+ }
48
3751
 
49
- // src/client.css
50
- var client_default = '.dsh-knowledge-trigger,\n.dsh-knowledge-workspace,\n.dsh-knowledge-settings-card,\n.dsh-knowledge-writeback-status {\n color-scheme: light;\n --knowledge-canvas: transparent;\n --knowledge-accent: #3a3a3c;\n --knowledge-on-accent: #fff;\n --knowledge-danger: #d70015;\n --knowledge-success: #248a3d;\n --knowledge-pane: rgba(255, 255, 255, 0.16);\n --knowledge-raised: rgba(255, 255, 255, 0.38);\n --knowledge-control: rgba(255, 255, 255, 0.27);\n --knowledge-border: rgb(60 60 67 / 14%);\n --knowledge-text: #1d1d1f;\n --knowledge-text-secondary: #515154;\n --knowledge-text-tertiary: #747478;\n --knowledge-hover: rgba(118, 118, 128, .1);\n --knowledge-glare-light: rgb(255 255 255 / 70%);\n --knowledge-glare-rim: rgb(60 60 67 / 11%);\n --knowledge-glass-filter: saturate(1.22) contrast(1.03) blur(32px);\n --knowledge-host-glass-filter: saturate(.18) contrast(1.015) blur(24px);\n --knowledge-glass-shadow: inset 0 1px 0 rgb(255 255 255 / 70%), inset 0 -1px 0 rgb(60 60 67 / 11%), 0 10px 28px rgb(31 31 35 / 8.5%);\n --knowledge-font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Microsoft YaHei", sans-serif;\n color: var(--knowledge-text);\n font-family: var(--knowledge-font-family);\n font-size: 13px;\n line-height: 1.5;\n}\n\nbody[data-ds-dark-theme] :is(\n .dsh-knowledge-trigger,\n .dsh-knowledge-workspace,\n .dsh-knowledge-settings-card,\n .dsh-knowledge-writeback-status\n) {\n color-scheme: dark;\n --knowledge-canvas: transparent;\n --knowledge-accent: #69b6ba;\n --knowledge-on-accent: #101819;\n --knowledge-danger: #ff453a;\n --knowledge-success: #30d158;\n --knowledge-pane: rgb(25 33 35 / 90%);\n --knowledge-raised: rgb(32 41 43 / 94%);\n --knowledge-control: rgb(39 50 53 / 92%);\n --knowledge-border: rgb(184 204 205 / 11%);\n --knowledge-text: #e3eaeb;\n --knowledge-text-secondary: #bbc9cc;\n --knowledge-text-tertiary: #95a7ab;\n --knowledge-hover: rgb(105 182 186 / 9%);\n --knowledge-glare-light: rgb(255 255 255 / 16%);\n --knowledge-glare-rim: rgb(0 0 0 / 30%);\n --knowledge-host-glass-filter: saturate(.45) contrast(1.02) blur(24px);\n --knowledge-glass-shadow: inset 0 1px 0 rgb(255 255 255 / 16%), inset 0 -1px 0 rgb(0 0 0 / 30%), 0 12px 32px rgb(0 0 0 / 30%);\n}\n\n:is(\n .dsh-knowledge-trigger,\n .dsh-knowledge-workspace,\n .dsh-knowledge-settings-card,\n .dsh-knowledge-writeback-status\n),\n:is(\n .dsh-knowledge-trigger,\n .dsh-knowledge-workspace,\n .dsh-knowledge-settings-card,\n .dsh-knowledge-writeback-status\n) * {\n box-sizing: border-box;\n}\n\n:is(\n .dsh-knowledge-trigger,\n .dsh-knowledge-workspace,\n .dsh-knowledge-settings-card,\n .dsh-knowledge-writeback-status\n) :where(button, input, textarea, select) {\n margin: 0;\n color: inherit;\n font-family: var(--knowledge-font-family);\n font-size: inherit;\n font-weight: inherit;\n line-height: inherit;\n letter-spacing: inherit;\n}\n\n.dsh-knowledge-trigger,\n.dsh-knowledge-panel-state button,\n.dsh-knowledge-settings-card button,\n.dsh-knowledge-writeback-status button {\n -webkit-appearance: none;\n appearance: none;\n margin: 0;\n}\n\n.dsh-knowledge-trigger {\n position: relative;\n flex: none;\n min-width: 0;\n display: flex;\n align-items: center;\n gap: 8px;\n width: calc(100% + 4px);\n height: 42px;\n margin: 4px -2px;\n padding: 0 10px 0 8px;\n box-sizing: border-box;\n border: 0;\n border-radius: 8px;\n overflow: hidden;\n background: transparent;\n color: var(--knowledge-text);\n cursor: pointer;\n font: inherit;\n font-size: 14px;\n line-height: 22px;\n white-space: nowrap;\n isolation: isolate;\n transition:\n color 120ms ease,\n background-color 120ms ease,\n box-shadow 160ms ease;\n}\n\n.dsh-knowledge-trigger:hover {\n background: var(--knowledge-hover);\n}\n\n.dsh-knowledge-trigger:focus-visible,\n.dsh-knowledge-writeback-status button:focus-visible {\n outline: 2px solid var(--knowledge-accent);\n outline-offset: 2px;\n}\n\n.dsh-knowledge-trigger.is-active {\n background: var(--knowledge-control);\n color: var(--knowledge-text);\n box-shadow: 0 1px 2px rgb(0 0 0 / 7%), inset 0 1px 0 rgb(255 255 255 / 28%);\n}\n\n.dsh-knowledge-trigger--rail {\n width: 36px;\n height: 36px;\n margin: 8px 0 4px;\n padding: 0;\n justify-content: center;\n gap: 0;\n border-radius: 50%;\n}\n\n/* Rail (collapsed) mode: the host footer seat is a horizontal row sized for a\n single 36px circle per entry; with several entries it overflows the 56px\n rail and the circles drift off the settings axis. Stack the entries\n vertically, centered on the same axis as the settings circle. The --rail\n class on the knowledge trigger is the collapsed-mode signal, so wide mode\n is untouched. */\ndiv:has(> div[data-slot="sidebar.footer.action"] .dsh-knowledge-trigger--rail) {\n flex-direction: column;\n align-items: center;\n}\n\n@media (prefers-reduced-motion: reduce) {\n .dsh-knowledge-trigger { transition: none; }\n}\n\n.dsh-knowledge-workspace {\n width: 100%;\n height: 100%;\n min-width: 0;\n min-height: 0;\n display: flex;\n flex-direction: column;\n overflow: hidden;\n background: var(--knowledge-canvas);\n}\n\n.dsh-knowledge-workspace-header {\n position: relative;\n z-index: 2;\n flex: none;\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: 16px;\n min-height: 52px;\n margin: 8px 10px 0;\n padding: 7px 14px;\n box-sizing: border-box;\n border: 1px solid var(--knowledge-border);\n border-radius: 14px 14px 11px 11px;\n background: transparent;\n box-shadow: var(--knowledge-glass-shadow);\n -webkit-backdrop-filter: var(--knowledge-host-glass-filter);\n backdrop-filter: var(--knowledge-host-glass-filter);\n}\n\n.dsh-knowledge-workspace-header > div {\n display: flex;\n align-items: center;\n gap: 10px;\n min-width: 0;\n}\n\n.dsh-knowledge-workspace-header [data-xiaohei-workspace-close] {\n -webkit-appearance: none;\n appearance: none;\n display: grid;\n place-items: center;\n box-sizing: border-box;\n flex: none;\n width: 30px;\n height: 30px;\n margin: 0;\n padding: 0;\n border: 1px solid transparent;\n border-radius: 9px;\n color: var(--knowledge-text-secondary);\n background: transparent;\n font: inherit;\n line-height: 1;\n -webkit-tap-highlight-color: transparent;\n cursor: pointer;\n transition: color 140ms ease, background 140ms ease, border-color 140ms ease, transform 140ms ease;\n}\n\n.dsh-knowledge-workspace-header [data-xiaohei-workspace-close]:hover {\n border-color: var(--knowledge-border);\n color: var(--knowledge-text);\n background: var(--knowledge-control);\n}\n\n.dsh-knowledge-workspace-header [data-xiaohei-workspace-close]:active { transform: scale(.96); }\n.dsh-knowledge-workspace-header [data-xiaohei-workspace-close]:focus-visible {\n outline: 2px solid var(--knowledge-accent);\n outline-offset: 2px;\n}\n.dsh-knowledge-workspace-header [data-xiaohei-workspace-close] > svg {\n display: block;\n pointer-events: none;\n}\n\n.dsh-knowledge-workspace-header > div > span {\n display: grid;\n min-width: 0;\n gap: 2px;\n}\n\n.dsh-knowledge-workspace-header h2,\n.dsh-knowledge-workspace-header p {\n margin: 0;\n}\n\n.dsh-knowledge-workspace-header h2 {\n color: var(--knowledge-text);\n font-size: 15px;\n line-height: 22px;\n font-weight: 600;\n}\n\n.dsh-knowledge-workspace-header p {\n color: var(--knowledge-text-secondary);\n font-size: 11px;\n line-height: 16px;\n}\n\n.dsh-knowledge-frame {\n flex: 1;\n display: block;\n width: 100%;\n min-height: 0;\n margin: 0;\n border: 0;\n border-radius: 0;\n background: transparent;\n box-shadow: none;\n -webkit-backdrop-filter: none;\n backdrop-filter: none;\n}\n\n.dsh-knowledge-panel-state {\n flex: 1;\n display: flex;\n align-items: center;\n justify-content: center;\n gap: 16px;\n min-height: 0;\n margin: 8px 10px 10px;\n padding: 32px;\n box-sizing: border-box;\n border: 1px solid var(--knowledge-border);\n border-radius: 15px;\n background: var(--knowledge-pane);\n box-shadow: var(--knowledge-glass-shadow);\n -webkit-backdrop-filter: var(--knowledge-host-glass-filter);\n backdrop-filter: var(--knowledge-host-glass-filter);\n color: var(--knowledge-text);\n}\n\n.dsh-knowledge-panel-state-icon {\n flex: none;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n width: 40px;\n height: 40px;\n border-radius: 12px;\n background: var(--knowledge-hover);\n color: var(--knowledge-text-secondary);\n font-size: 18px;\n font-weight: 600;\n}\n\n.dsh-knowledge-panel-state > div { max-width: 560px; }\n.dsh-knowledge-panel-state h3 { margin: 0 0 6px; font-size: 17px; line-height: 24px; font-weight: 600; }\n.dsh-knowledge-panel-state p { margin: 0; color: var(--knowledge-text-secondary); font-size: 13px; line-height: 20px; }\n.dsh-knowledge-panel-state button {\n min-width: 72px;\n min-height: 32px;\n margin-top: 16px;\n padding: 6px 14px;\n border: 0;\n border-radius: 10px;\n background: var(--knowledge-accent);\n color: var(--knowledge-on-accent);\n cursor: pointer;\n font: inherit;\n}\n.dsh-knowledge-panel-state button:focus-visible {\n outline: 2px solid var(--knowledge-accent);\n outline-offset: 2px;\n}\n\n.dsh-knowledge-settings-card {\n list-style: none;\n overflow: hidden;\n border: 1px solid var(--knowledge-border);\n border-radius: 14px;\n background:\n linear-gradient(145deg, color-mix(in srgb, var(--knowledge-glare-light) 16%, transparent), transparent 58%),\n var(--knowledge-pane);\n color: var(--knowledge-text);\n box-shadow: var(--knowledge-glass-shadow), 0 8px 24px rgb(0 0 0 / 5%);\n -webkit-backdrop-filter: var(--knowledge-glass-filter);\n backdrop-filter: var(--knowledge-glass-filter);\n transition: border-color .16s, background .16s, box-shadow .2s, transform .2s cubic-bezier(.22, 1, .36, 1);\n}\n.dsh-knowledge-settings-card:hover {\n border-color: color-mix(in srgb, var(--knowledge-border) 68%, var(--knowledge-text-secondary));\n box-shadow: var(--knowledge-glass-shadow), 0 12px 30px rgb(0 0 0 / 8%);\n transform: translateY(-1px);\n}\n.dsh-knowledge-settings-card--open {\n border-color: color-mix(in srgb, var(--knowledge-border) 68%, var(--knowledge-text-secondary));\n background: var(--knowledge-pane);\n}\n.dsh-knowledge-settings-header { display: flex; width: 100%; align-items: center; gap: 12px; padding: 14px 16px; border: 0; border-radius: 12px; background: transparent; color: inherit; text-align: left; cursor: pointer; font: inherit; }\n.dsh-knowledge-settings-header:focus-visible {\n outline: 2px solid var(--knowledge-accent);\n outline-offset: -2px;\n}\n.dsh-knowledge-settings-actions button:focus-visible,\n.dsh-knowledge-settings-load-error button:focus-visible {\n outline: 2px solid var(--knowledge-accent);\n outline-offset: 2px;\n}\n.dsh-knowledge-settings-header > span:first-child { display: flex; min-width: 0; flex: 1; flex-direction: column; gap: 4px; }\n.dsh-knowledge-settings-header strong { font-size: 15px; font-weight: 600; line-height: 1.4; }\n.dsh-knowledge-settings-header small { color: var(--knowledge-text-tertiary); font-size: 13px; line-height: 1.5; }\n.dsh-knowledge-source-picker small,\n.dsh-knowledge-remote-fields small { color: var(--knowledge-text-secondary); font-size: 12px; }\n.dsh-knowledge-settings-summary { display: flex; flex: none; align-items: center; gap: 10px; color: var(--knowledge-text-tertiary); font-size: 12px; }\n.dsh-knowledge-settings-summary i { width: 8px; height: 8px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(45deg); transition: transform 160ms ease; }\n.dsh-knowledge-settings-card--open .dsh-knowledge-settings-summary i { transform: rotate(225deg); }\n\n.dsh-knowledge-settings-body {\n display: grid;\n gap: 18px;\n margin: 0 16px;\n padding-bottom: 8px;\n border-top: 1px solid var(--knowledge-border);\n}\n\n.dsh-knowledge-source-picker {\n min-width: 0;\n display: grid;\n grid-template-columns: repeat(2, minmax(0, 1fr));\n gap: 10px;\n margin: 18px 0 0;\n padding: 0;\n border: 0;\n}\n\n.dsh-knowledge-source-picker legend { margin-bottom: 8px; padding: 0; color: inherit; font-size: 13px; font-weight: 600; }\n.dsh-knowledge-source-picker label {\n display: flex;\n gap: 10px;\n padding: 13px;\n border: 1px solid var(--knowledge-border);\n border-radius: 14px;\n cursor: pointer;\n}\n.dsh-knowledge-source-picker label.is-selected {\n border-color: var(--knowledge-accent);\n background: color-mix(in srgb, var(--knowledge-accent) 7%, transparent);\n}\n.dsh-knowledge-source-picker label.is-disabled {\n cursor: default;\n opacity: .55;\n}\n.dsh-knowledge-source-picker label:focus-within {\n outline: 2px solid var(--knowledge-accent);\n outline-offset: 2px;\n}\n.dsh-knowledge-source-picker input {\n -webkit-appearance: none;\n appearance: none;\n width: 16px;\n height: 16px;\n display: inline-grid;\n place-content: center;\n flex: none;\n margin: 2px 0 0;\n border: 1px solid var(--knowledge-border);\n border-radius: 50%;\n background: var(--knowledge-control);\n color: var(--knowledge-on-accent);\n cursor: pointer;\n transition: border-color .15s ease, background-color .15s ease;\n}\n.dsh-knowledge-source-picker input::before {\n content: "";\n width: 6px;\n height: 6px;\n border-radius: 50%;\n background: currentColor;\n opacity: 0;\n transform: scale(.55);\n transition: opacity .12s ease, transform .15s cubic-bezier(.2, .8, .2, 1);\n}\n.dsh-knowledge-source-picker input:checked { border-color: var(--knowledge-accent); background: var(--knowledge-accent); }\n.dsh-knowledge-source-picker input:checked::before { opacity: 1; transform: scale(1); }\n.dsh-knowledge-source-picker input:disabled { cursor: default; }\n.dsh-knowledge-source-picker span { display: grid; gap: 3px; }\n\n.dsh-knowledge-remote-fields { display: grid; grid-template-columns: 1.25fr 1fr; gap: 12px; }\n.dsh-knowledge-remote-fields label,\n.dsh-knowledge-timeout-field { display: grid; gap: 6px; color: var(--knowledge-text-secondary); font-size: 12px; }\n.dsh-knowledge-remote-fields input,\n.dsh-knowledge-timeout-field input {\n -webkit-appearance: none;\n appearance: none;\n min-height: 38px;\n box-sizing: border-box;\n padding: 8px 11px;\n border: 1px solid var(--knowledge-border);\n border-radius: 10px;\n outline: none;\n background: var(--knowledge-control);\n color: var(--knowledge-text);\n font: inherit;\n}\n.dsh-knowledge-remote-fields input:focus,\n.dsh-knowledge-timeout-field input:focus { border-color: var(--knowledge-accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--knowledge-accent) 16%, transparent); }\n.dsh-knowledge-remote-fields input:-webkit-autofill,\n.dsh-knowledge-remote-fields input:-webkit-autofill:hover,\n.dsh-knowledge-remote-fields input:-webkit-autofill:focus {\n -webkit-text-fill-color: var(--knowledge-text);\n box-shadow: 0 0 0 1000px var(--knowledge-control) inset;\n caret-color: var(--knowledge-text);\n}\n.dsh-knowledge-timeout-field input::-webkit-inner-spin-button,\n.dsh-knowledge-timeout-field input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }\n.dsh-knowledge-timeout-field { max-width: 240px; }\n.dsh-knowledge-field-error { color: var(--knowledge-danger) !important; }\n\n.dsh-knowledge-settings-message,\n.dsh-knowledge-settings-note { margin: 0; color: var(--knowledge-text-secondary); font-size: 12px; }\n.dsh-knowledge-settings-message.is-success { color: var(--knowledge-success); }\n.dsh-knowledge-settings-message.is-error { color: var(--knowledge-danger); }\n.dsh-knowledge-settings-load-error {\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: 12px;\n margin-top: 18px;\n padding: 12px 14px;\n border-radius: 12px;\n background: color-mix(in srgb, var(--knowledge-danger) 8%, transparent);\n color: var(--knowledge-danger);\n font-size: 13px;\n}\n.dsh-knowledge-settings-load-error p { margin: 0; }\n.dsh-knowledge-settings-load-error button {\n flex: none;\n min-height: 30px;\n padding: 5px 10px;\n border: 0;\n border-radius: 9px;\n background: var(--knowledge-control);\n color: var(--knowledge-text);\n cursor: pointer;\n font: inherit;\n}\n.dsh-knowledge-settings-actions { display: flex; justify-content: flex-end; gap: 8px; }\n.dsh-knowledge-settings-actions button {\n min-height: 34px;\n padding: 7px 13px;\n border: 0;\n border-radius: 10px;\n background: var(--knowledge-hover);\n color: var(--knowledge-text);\n cursor: pointer;\n font: inherit;\n font-size: 13px;\n}\n.dsh-knowledge-settings-actions button.is-primary { background: var(--knowledge-accent); color: var(--knowledge-on-accent); }\n.dsh-knowledge-settings-actions button:disabled { cursor: default; opacity: .45; }\n\n@media (max-width: 720px) {\n .dsh-knowledge-source-picker,\n .dsh-knowledge-remote-fields { grid-template-columns: 1fr; }\n .dsh-knowledge-settings-summary { font-size: 0; }\n}\n\n@media (prefers-reduced-motion: reduce) {\n .dsh-knowledge-settings-card,\n .dsh-knowledge-settings-header,\n .dsh-knowledge-settings-summary i { transition: none; }\n}\n\n.dsh-knowledge-writeback-status {\n display: grid;\n gap: 5px;\n min-width: 0;\n color: var(--knowledge-text-tertiary);\n font-size: 12px;\n line-height: 1.5;\n}\n.dsh-knowledge-writeback-summary {\n display: flex;\n align-items: center;\n flex-wrap: wrap;\n gap: 8px;\n min-width: 0;\n}\n.dsh-knowledge-writeback-status strong {\n color: var(--knowledge-text-secondary);\n font-weight: 600;\n}\n.dsh-knowledge-writeback-status button {\n min-height: 24px;\n padding: 0 9px;\n border: 1px solid var(--knowledge-border);\n border-radius: 7px;\n color: var(--knowledge-text-secondary);\n background: var(--knowledge-control);\n cursor: pointer;\n font: inherit;\n}\n.dsh-knowledge-writeback-status button:disabled { cursor: default; opacity: .5; }\n.dsh-knowledge-writeback-destinations {\n display: flex;\n flex-wrap: wrap;\n gap: 2px 12px;\n min-width: 0;\n margin: 0;\n padding: 0;\n list-style: none;\n}\n.dsh-knowledge-writeback-destinations li {\n display: inline-flex;\n align-items: center;\n gap: 5px;\n min-width: 0;\n max-width: 100%;\n padding: 0;\n border: 0;\n background: transparent;\n}\n.dsh-knowledge-writeback-base,\n.dsh-knowledge-writeback-separator {\n flex: none;\n}\n.dsh-knowledge-writeback-separator {\n color: var(--knowledge-text-tertiary);\n}\n.dsh-knowledge-writeback-destinations strong {\n min-width: 0;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n.dsh-knowledge-writeback-status .dsh-knowledge-writeback-document {\n display: inline-flex;\n align-items: center;\n min-width: 0;\n min-height: 24px;\n padding: 0 3px;\n border: 0;\n border-radius: 4px;\n background: transparent;\n color: var(--knowledge-text-secondary);\n text-decoration: underline;\n text-decoration-color: transparent;\n text-underline-offset: 3px;\n transition: color 120ms ease, background-color 120ms ease, text-decoration-color 120ms ease;\n}\n.dsh-knowledge-writeback-status .dsh-knowledge-writeback-document:hover {\n background: var(--knowledge-hover);\n color: var(--knowledge-text);\n text-decoration-color: currentColor;\n}\n.dsh-knowledge-writeback-document strong { color: inherit; }\n.dsh-knowledge-writeback-destinations small {\n flex: none;\n color: var(--knowledge-text-secondary);\n font: inherit;\n white-space: nowrap;\n}\n.dsh-knowledge-writeback-destinations small[data-disposition="written"] { color: var(--knowledge-success); }\n.dsh-knowledge-writeback-error {\n max-width: min(720px, 100%);\n margin: 0;\n color: var(--knowledge-danger);\n overflow-wrap: anywhere;\n}\n';
3752
+ // src/knowledge-activity-controller.tsx
3753
+ var import_jsx_runtime4 = require("react/jsx-runtime");
3754
+ function createKnowledgeActivityController(ctx, options) {
3755
+ const runtime = ctx;
3756
+ const listeners = /* @__PURE__ */ new Set();
3757
+ const states = /* @__PURE__ */ new Map();
3758
+ let currentSessionId = normalizeSessionId(runtime.sessions.list.getSnapshot().current);
3759
+ let mountedSessionId;
3760
+ let restoreFrame;
3761
+ let disposePanel;
3762
+ const notify = () => {
3763
+ for (const listener of listeners) listener();
3764
+ };
3765
+ const cancelRestore = () => {
3766
+ if (restoreFrame === void 0) return;
3767
+ window.cancelAnimationFrame(restoreFrame);
3768
+ restoreFrame = void 0;
3769
+ };
3770
+ const unmount = () => {
3771
+ if (disposePanel === void 0) return false;
3772
+ const dispose = disposePanel;
3773
+ disposePanel = void 0;
3774
+ mountedSessionId = void 0;
3775
+ dispose();
3776
+ return true;
3777
+ };
3778
+ const mount = (sessionId, openDetails = true) => {
3779
+ if (mountedSessionId === sessionId && disposePanel !== void 0) {
3780
+ if (openDetails) ctx.layout.openDetails();
3781
+ return;
3782
+ }
3783
+ unmount();
3784
+ mountedSessionId = sessionId;
3785
+ const onClosed = () => {
3786
+ if (mountedSessionId === sessionId && states.get(sessionId)?.open !== true) unmount();
3787
+ };
3788
+ disposePanel = ctx.slots.register({ name: "details", priority: -3 }, (props) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(KnowledgeActivityPresentation, { sessionId, controller, onClosed, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(KnowledgeActivityPanel, { ...props, controller }) }, sessionId));
3789
+ if (openDetails) ctx.layout.openDetails();
3790
+ };
3791
+ const syncCurrentSession = () => {
3792
+ const nextSessionId = normalizeSessionId(runtime.sessions.list.getSnapshot().current);
3793
+ if (nextSessionId === currentSessionId) return;
3794
+ cancelRestore();
3795
+ const wasMounted = unmount();
3796
+ currentSessionId = nextSessionId;
3797
+ if (nextSessionId !== void 0 && states.get(nextSessionId)?.open === true) {
3798
+ mount(nextSessionId, false);
3799
+ restoreFrame = window.requestAnimationFrame(() => {
3800
+ restoreFrame = void 0;
3801
+ if (currentSessionId === nextSessionId && mountedSessionId === nextSessionId && states.get(nextSessionId)?.open === true) {
3802
+ ctx.layout.openDetails();
3803
+ }
3804
+ });
3805
+ } else if (wasMounted) {
3806
+ ctx.layout.closeDetails();
3807
+ }
3808
+ notify();
3809
+ };
3810
+ const controller = {
3811
+ open(sessionId, selection) {
3812
+ const previous = states.get(sessionId);
3813
+ states.set(sessionId, { ...mergeActivitySelection(previous ?? {}, selection ?? {}), open: true });
3814
+ options.beforeOpen();
3815
+ if (sessionId === currentSessionId) {
3816
+ cancelRestore();
3817
+ mount(sessionId);
3818
+ }
3819
+ notify();
3820
+ },
3821
+ toggle(sessionId) {
3822
+ if (states.get(sessionId)?.open === true) controller.close(sessionId);
3823
+ else controller.open(sessionId);
3824
+ },
3825
+ close(sessionId, immediate = false) {
3826
+ const target = sessionId ?? currentSessionId;
3827
+ if (target === void 0) return;
3828
+ const previous = states.get(target) ?? { open: false };
3829
+ states.set(target, { ...previous, open: false });
3830
+ if (target === currentSessionId) {
3831
+ cancelRestore();
3832
+ if (mountedSessionId === target) ctx.layout.closeDetails();
3833
+ if (immediate) unmount();
3834
+ }
3835
+ notify();
3836
+ },
3837
+ isOpen: (sessionId) => states.get(sessionId)?.open === true,
3838
+ selection(sessionId) {
3839
+ const state = states.get(sessionId);
3840
+ return {
3841
+ ...state?.mode === void 0 ? {} : { mode: state.mode },
3842
+ ...state?.knowledgeBaseId === void 0 ? {} : { knowledgeBaseId: state.knowledgeBaseId },
3843
+ ...state?.documentId === void 0 ? {} : { documentId: state.documentId },
3844
+ ...state?.noteFolderId === void 0 ? {} : { noteFolderId: state.noteFolderId },
3845
+ ...state?.noteDocumentId === void 0 ? {} : { noteDocumentId: state.noteDocumentId },
3846
+ ...state?.noteCrumbs === void 0 ? {} : { noteCrumbs: state.noteCrumbs }
3847
+ };
3848
+ },
3849
+ select(sessionId, selection) {
3850
+ const previous = states.get(sessionId) ?? { open: true };
3851
+ states.set(sessionId, { ...mergeActivitySelection(previous, selection), open: previous.open });
3852
+ notify();
3853
+ },
3854
+ openWorkspace(target) {
3855
+ controller.close(void 0, true);
3856
+ options.openWorkspace(target);
3857
+ },
3858
+ subscribe(listener) {
3859
+ listeners.add(listener);
3860
+ return () => {
3861
+ listeners.delete(listener);
3862
+ };
3863
+ },
3864
+ dispose() {
3865
+ disposeSelection();
3866
+ cancelRestore();
3867
+ unmount();
3868
+ states.clear();
3869
+ listeners.clear();
3870
+ }
3871
+ };
3872
+ const disposeSelection = runtime.sessions.list.subscribe(syncCurrentSession);
3873
+ return controller;
3874
+ }
3875
+ function normalizeSessionId(value) {
3876
+ return typeof value === "string" && value.length > 0 ? value : void 0;
3877
+ }
51
3878
 
52
3879
  // src/constants.ts
53
3880
  var KNOWLEDGE_SETTINGS_NAMESPACE = "dsh-knowledge-connection";
@@ -56,84 +3883,50 @@ var KNOWLEDGE_SETTINGS_NAMESPACE = "dsh-knowledge-connection";
56
3883
  var KNOWLEDGE_THEME_MESSAGE = "@lemoncat7/dsh-knowledge/host-theme";
57
3884
  var KNOWLEDGE_THEME_READY_MESSAGE = "@lemoncat7/dsh-knowledge/host-theme-ready";
58
3885
  var KNOWLEDGE_THEME_PROTOCOL_VERSION = 1;
59
- var WORKSPACE_TOKENS = {
60
- light: {
61
- "--bg": "#ebebeb",
62
- "--surface": "#f4f4f4",
63
- "--surface-raised": "#fafafa",
64
- "--surface-soft": "#eeeeef",
65
- "--surface-hover": "rgb(118 118 128 / 9%)",
66
- "--dialog-surface": "#f4f4f4",
67
- "--text": "#1d1d1f",
68
- "--text-secondary": "#515154",
69
- "--text-tertiary": "#6e6e73",
70
- "--border": "rgb(60 60 67 / 14%)",
71
- "--border-strong": "rgb(60 60 67 / 24%)",
72
- "--accent": "#3a3a3c",
73
- "--accent-hover": "#1d1d1f",
74
- "--accent-soft": "#e2e2e5",
75
- "--on-accent": "#ffffff",
76
- "--success": "#248a3d",
77
- "--success-soft": "#e8f5eb",
78
- "--warning": "#c93400",
79
- "--warning-soft": "#fff1e8",
80
- "--danger": "#d70015",
81
- "--danger-soft": "#ffebed",
82
- "--shadow": "0 24px 64px rgb(0 0 0 / 20%)"
83
- },
84
- dark: {
85
- "--bg": "#101719",
86
- "--surface": "#182022",
87
- "--surface-raised": "#20292b",
88
- "--surface-soft": "rgb(184 204 205 / 6%)",
89
- "--surface-hover": "rgb(105 182 186 / 9%)",
90
- "--dialog-surface": "#20292b",
91
- "--text": "#e3eaeb",
92
- "--text-secondary": "#bbc9cc",
93
- "--text-tertiary": "#95a7ab",
94
- "--border": "rgb(184 204 205 / 10%)",
95
- "--border-strong": "rgb(184 204 205 / 18%)",
96
- "--accent": "#69b6ba",
97
- "--accent-hover": "#8aced0",
98
- "--accent-soft": "rgb(105 182 186 / 13%)",
99
- "--on-accent": "#101819",
100
- "--success": "#30d158",
101
- "--success-soft": "rgb(48 209 88 / 13%)",
102
- "--warning": "#ff9f0a",
103
- "--warning-soft": "rgb(255 159 10 / 13%)",
104
- "--danger": "#ff453a",
105
- "--danger-soft": "rgb(255 69 58 / 14%)",
106
- "--shadow": "0 28px 72px rgb(0 0 0 / 42%)"
107
- }
108
- };
109
- function createKnowledgeHostTheme(_computed, snapshot) {
3886
+ function createKnowledgeHostTheme(snapshot) {
110
3887
  return {
111
3888
  type: KNOWLEDGE_THEME_MESSAGE,
112
3889
  version: KNOWLEDGE_THEME_PROTOCOL_VERSION,
113
3890
  colorScheme: snapshot.active.colorScheme,
114
- tokens: { ...WORKSPACE_TOKENS[snapshot.active.colorScheme] }
3891
+ tokens: { ...KNOWLEDGE_PALETTE[snapshot.active.colorScheme] }
115
3892
  };
116
3893
  }
117
3894
 
118
3895
  // src/client.tsx
119
- var import_jsx_runtime = require("react/jsx-runtime");
3896
+ var import_jsx_runtime5 = require("react/jsx-runtime");
120
3897
  var PLUGIN_ID = "@lemoncat7/dsh-knowledge";
121
3898
  var STYLE_ID = `${PLUGIN_ID}/client`;
3899
+ var COMPACT_KNOWLEDGE_VIEWPORT = "(max-width: 1120px), (hover: none) and (pointer: coarse) and (max-width: 1400px)";
122
3900
  var CONNECTION_CONTROL_PATH = "/knowledge-control/v1/connection";
123
3901
  var cachedConnectionView;
124
- var inject = ["slots", "theme"];
125
- function apply(ctx) {
3902
+ var inject = ["slots", "theme", "layout", "sessions"];
3903
+ function apply2(ctx) {
126
3904
  ctx.effect(installStyles, "dsh-knowledge: client styles");
127
- const workspace = createKnowledgeWorkspaceController(ctx);
128
- ctx.effect(() => observePluginWorkspace(PLUGIN_ID, workspace.close), "dsh-knowledge: exclusive workspace");
3905
+ let activity;
3906
+ const workspace = createKnowledgeWorkspaceController(ctx, () => activity?.close(void 0, true));
3907
+ activity = createKnowledgeActivityController(ctx, {
3908
+ beforeOpen: () => {
3909
+ workspace.close();
3910
+ activatePluginWorkspace(PLUGIN_ID);
3911
+ },
3912
+ openWorkspace: (target) => {
3913
+ if (target === void 0) workspace.open();
3914
+ else workspace.openDocument(target);
3915
+ }
3916
+ });
3917
+ ctx.effect(() => observePluginWorkspace(PLUGIN_ID, () => {
3918
+ workspace.close();
3919
+ activity?.close(void 0, true);
3920
+ }), "dsh-knowledge: exclusive workspace");
129
3921
  ctx.effect(() => () => {
130
3922
  workspace.close();
3923
+ activity?.dispose();
131
3924
  }, "dsh-knowledge: workspace lifecycle");
132
3925
  ctx.slots.inject("sidebar.footer.action", () => ctx.slots.register({
133
3926
  name: "sidebar.footer.action",
134
3927
  id: "knowledge",
135
3928
  order: -10
136
- }, (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(KnowledgeLauncher, { ...props, workspace })));
3929
+ }, (props) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(KnowledgeLauncher, { ...props, workspace, activity })));
137
3930
  ctx.slots.inject("settings.plugin.item", () => ctx.slots.register({
138
3931
  name: "settings.plugin.item",
139
3932
  key: KNOWLEDGE_SETTINGS_NAMESPACE
@@ -141,16 +3934,16 @@ function apply(ctx) {
141
3934
  ctx.slots.inject("conversation.chat.turnTail", () => ctx.slots.register({
142
3935
  name: "conversation.chat.turnTail",
143
3936
  select: (owner) => ({ turn: owner.turn.turn })
144
- }, (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(KnowledgeWritebackStatus, { sessionId: String(props.sessionId), turn: props.matched.turn, workspace })));
3937
+ }, (props) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(KnowledgeWritebackStatus, { sessionId: String(props.sessionId), turn: props.matched.turn, workspace })));
145
3938
  }
146
3939
  function KnowledgeWritebackStatus({
147
3940
  sessionId,
148
3941
  turn,
149
3942
  workspace
150
3943
  }) {
151
- const [state, setState] = (0, import_react.useState)();
152
- const [retrying, setRetrying] = (0, import_react.useState)(false);
153
- (0, import_react.useEffect)(() => {
3944
+ const [state, setState] = (0, import_react4.useState)();
3945
+ const [retrying, setRetrying] = (0, import_react4.useState)(false);
3946
+ (0, import_react4.useEffect)(() => {
154
3947
  const controller = new AbortController();
155
3948
  let timer;
156
3949
  let missingAttempts = 0;
@@ -211,19 +4004,19 @@ function KnowledgeWritebackStatus({
211
4004
  };
212
4005
  const destinations = state.destinations ?? [];
213
4006
  const summary = state.summary.replace(/^知识库回写\s*·\s*/u, "");
214
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsh-knowledge-writeback-status", "data-status": state.status, children: [
215
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsh-knowledge-writeback-summary", role: state.status === "running" ? "status" : void 0, "aria-atomic": "true", children: [
216
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "\u77E5\u8BC6\u5E93\u56DE\u5199" }),
217
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { children: "@lemoncat7/dsh-knowledge" }),
218
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { title: state.error, children: summary }),
219
- state.status === "failed" && state.retryable && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", disabled: retrying, onClick: () => {
4007
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "dsh-knowledge-writeback-notice", "data-status": state.status, children: [
4008
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "dsh-knowledge-writeback-summary", role: state.status === "running" ? "status" : void 0, "aria-atomic": "true", children: [
4009
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: "\u77E5\u8BC6\u5E93\u56DE\u5199" }),
4010
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("strong", { children: "@lemoncat7/dsh-knowledge" }),
4011
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { title: state.error, children: summary }),
4012
+ state.status === "failed" && state.retryable && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { type: "button", disabled: retrying, onClick: () => {
220
4013
  void retry();
221
4014
  }, children: retrying ? "\u91CD\u8BD5\u4E2D\u2026" : "\u91CD\u8BD5" })
222
4015
  ] }),
223
- destinations.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("ul", { className: "dsh-knowledge-writeback-destinations", "aria-label": "\u56DE\u5199\u76EE\u6807", children: destinations.map((destination, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("li", { children: [
224
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dsh-knowledge-writeback-base", children: destination.knowledgeBaseName }),
225
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dsh-knowledge-writeback-separator", "aria-hidden": "true", children: "/" }),
226
- destination.documentId ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
4016
+ destinations.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("ul", { className: "dsh-knowledge-writeback-destinations", "aria-label": "\u56DE\u5199\u76EE\u6807", children: destinations.map((destination, index) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("li", { children: [
4017
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "dsh-knowledge-writeback-base", children: destination.knowledgeBaseName }),
4018
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "dsh-knowledge-writeback-separator", "aria-hidden": "true", children: "/" }),
4019
+ destination.documentId ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
227
4020
  "button",
228
4021
  {
229
4022
  type: "button",
@@ -233,15 +4026,15 @@ function KnowledgeWritebackStatus({
233
4026
  onClick: () => {
234
4027
  workspace.openDocument({ knowledgeBaseId: destination.knowledgeBaseId, documentId: destination.documentId });
235
4028
  },
236
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { children: destination.documentPath ?? destination.documentTitle })
4029
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("strong", { children: destination.documentPath ?? destination.documentTitle })
237
4030
  }
238
- ) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { title: destination.documentTitle, children: `\u62DF\u65B0\u5EFA\uFF1A${destination.documentTitle}` }),
239
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("small", { "data-disposition": destination.disposition, children: destination.disposition === "written" ? "\u5DF2\u5199\u5165" : "\u5F85\u5BA1\u6838" })
4031
+ ) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("strong", { title: destination.documentTitle, children: `\u62DF\u65B0\u5EFA\uFF1A${destination.documentTitle}` }),
4032
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("small", { "data-disposition": destination.disposition, children: destination.disposition === "written" ? "\u5DF2\u5199\u5165" : "\u5F85\u5BA1\u6838" })
240
4033
  ] }, `${destination.knowledgeBaseId}:${destination.documentId ?? destination.documentTitle}:${index}`)) }),
241
- state.status === "failed" && state.error && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dsh-knowledge-writeback-error", role: "alert", children: state.error })
4034
+ state.status === "failed" && state.error && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "dsh-knowledge-writeback-error", role: "alert", children: state.error })
242
4035
  ] });
243
4036
  }
244
- function createKnowledgeWorkspaceController(client) {
4037
+ function createKnowledgeWorkspaceController(client, beforeOpen) {
245
4038
  const listeners = /* @__PURE__ */ new Set();
246
4039
  let disposeWorkspace;
247
4040
  let target;
@@ -258,11 +4051,17 @@ function createKnowledgeWorkspaceController(client) {
258
4051
  let controller;
259
4052
  const open = () => {
260
4053
  if (disposeWorkspace !== void 0) return;
4054
+ beforeOpen();
261
4055
  activatePluginWorkspace(PLUGIN_ID);
262
- disposeWorkspace = client.slots.register({ name: "conversation", priority: -1 }, (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(KnowledgeWorkspace, { ...props, client, workspace: controller }));
4056
+ disposeWorkspace = client.slots.register({ name: "conversation", priority: -1 }, (props) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(KnowledgeWorkspace, { ...props, client, workspace: controller }));
263
4057
  };
264
4058
  controller = {
265
4059
  isOpen: () => disposeWorkspace !== void 0,
4060
+ open: () => {
4061
+ target = void 0;
4062
+ open();
4063
+ notify();
4064
+ },
266
4065
  toggle: () => {
267
4066
  if (disposeWorkspace !== void 0) return close();
268
4067
  target = void 0;
@@ -286,18 +4085,18 @@ function createKnowledgeWorkspaceController(client) {
286
4085
  return controller;
287
4086
  }
288
4087
  function KnowledgeConnectionCard() {
289
- const [current, setCurrent] = (0, import_react.useState)();
290
- const [loadState, setLoadState] = (0, import_react.useState)("loading");
291
- const [loadError, setLoadError] = (0, import_react.useState)("");
292
- const [open, setOpen] = (0, import_react.useState)(false);
293
- const [backend, setBackend] = (0, import_react.useState)("local");
294
- const [remoteUrl, setRemoteUrl] = (0, import_react.useState)("");
295
- const [remoteToken, setRemoteToken] = (0, import_react.useState)("");
296
- const [timeout, setTimeoutValue] = (0, import_react.useState)("10000");
297
- const [dirty, setDirty] = (0, import_react.useState)(false);
298
- const [saving, setSaving] = (0, import_react.useState)(false);
299
- const [message, setMessage] = (0, import_react.useState)();
300
- const load = (0, import_react.useCallback)(async (signal) => {
4088
+ const [current, setCurrent] = (0, import_react4.useState)();
4089
+ const [loadState, setLoadState] = (0, import_react4.useState)("loading");
4090
+ const [loadError, setLoadError] = (0, import_react4.useState)("");
4091
+ const [open, setOpen] = (0, import_react4.useState)(false);
4092
+ const [backend, setBackend] = (0, import_react4.useState)("local");
4093
+ const [remoteUrl, setRemoteUrl] = (0, import_react4.useState)("");
4094
+ const [remoteToken, setRemoteToken] = (0, import_react4.useState)("");
4095
+ const [timeout, setTimeoutValue] = (0, import_react4.useState)("10000");
4096
+ const [dirty, setDirty] = (0, import_react4.useState)(false);
4097
+ const [saving, setSaving] = (0, import_react4.useState)(false);
4098
+ const [message3, setMessage] = (0, import_react4.useState)();
4099
+ const load = (0, import_react4.useCallback)(async (signal) => {
301
4100
  setLoadState("loading");
302
4101
  setLoadError("");
303
4102
  try {
@@ -310,14 +4109,14 @@ function KnowledgeConnectionCard() {
310
4109
  setLoadState("error");
311
4110
  }
312
4111
  }, []);
313
- (0, import_react.useEffect)(() => {
4112
+ (0, import_react4.useEffect)(() => {
314
4113
  const controller = new AbortController();
315
4114
  void load(controller.signal);
316
4115
  return () => {
317
4116
  controller.abort();
318
4117
  };
319
4118
  }, [load]);
320
- (0, import_react.useEffect)(() => {
4119
+ (0, import_react4.useEffect)(() => {
321
4120
  if (dirty || current === void 0) return;
322
4121
  setBackend(current.backend);
323
4122
  setRemoteUrl(current.remoteUrl ?? "");
@@ -365,75 +4164,75 @@ function KnowledgeConnectionCard() {
365
4164
  setSaving(false);
366
4165
  }
367
4166
  };
368
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("li", { className: `dsh-knowledge-settings-card${open ? " dsh-knowledge-settings-card--open" : ""}`, children: [
369
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", { type: "button", className: "dsh-knowledge-settings-header", "aria-expanded": open, onClick: () => {
4167
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("li", { className: `dsh-knowledge-settings-card${open ? " dsh-knowledge-settings-card--open" : ""}`, children: [
4168
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("button", { type: "button", className: "dsh-knowledge-settings-header", "aria-expanded": open, onClick: () => {
370
4169
  setOpen((value) => !value);
371
4170
  }, children: [
372
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { children: [
373
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { children: "\u77E5\u8BC6\u5E93\u8FDE\u63A5" }),
374
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("small", { children: "\u9009\u62E9\u672C\u673A\u77E5\u8BC6\u5E93\uFF0C\u6216\u8FDE\u63A5\u4E00\u53F0\u4E2D\u592E DSH \u77E5\u8BC6\u5E93" })
4171
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { children: [
4172
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("strong", { children: "\u77E5\u8BC6\u5E93\u8FDE\u63A5" }),
4173
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("small", { children: "\u9009\u62E9\u672C\u673A\u77E5\u8BC6\u5E93\uFF0C\u6216\u8FDE\u63A5\u4E00\u53F0\u4E2D\u592E DSH \u77E5\u8BC6\u5E93" })
375
4174
  ] }),
376
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "dsh-knowledge-settings-summary", children: [
4175
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: "dsh-knowledge-settings-summary", children: [
377
4176
  loadState === "loading" ? "\u8BFB\u53D6\u4E2D" : loadState === "error" ? "\u8FDE\u63A5\u5165\u53E3" : current?.backend === "remote" ? "\u8FDC\u7A0B" : "\u672C\u5730",
378
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("i", { "aria-hidden": "true" })
4177
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("i", { "aria-hidden": "true" })
379
4178
  ] })
380
4179
  ] }),
381
- open && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dsh-knowledge-settings-body", children: loadState === "loading" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dsh-knowledge-settings-note", role: "status", children: "\u6B63\u5728\u8BFB\u53D6\u8FDE\u63A5\u914D\u7F6E\u2026" }) : loadState === "error" ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsh-knowledge-settings-load-error", role: "alert", children: [
382
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: loadError }),
383
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", onClick: () => {
4180
+ open && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "dsh-knowledge-settings-body", children: loadState === "loading" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "dsh-knowledge-settings-note", role: "status", children: "\u6B63\u5728\u8BFB\u53D6\u8FDE\u63A5\u914D\u7F6E\u2026" }) : loadState === "error" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "dsh-knowledge-settings-load-error", role: "alert", children: [
4181
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { children: loadError }),
4182
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { type: "button", onClick: () => {
384
4183
  void load();
385
4184
  }, children: "\u91CD\u65B0\u8BFB\u53D6" })
386
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
387
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("fieldset", { className: "dsh-knowledge-source-picker", children: [
388
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("legend", { children: "\u77E5\u8BC6\u5E93\u6765\u6E90" }),
389
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", { className: backend === "local" ? "is-selected" : "", children: [
390
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", { type: "radio", name: "dsh-knowledge-backend", checked: backend === "local", onChange: () => edit(() => {
4185
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
4186
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("fieldset", { className: "dsh-knowledge-source-picker", children: [
4187
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("legend", { children: "\u77E5\u8BC6\u5E93\u6765\u6E90" }),
4188
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { className: backend === "local" ? "is-selected" : "", children: [
4189
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("input", { type: "radio", name: "dsh-knowledge-backend", checked: backend === "local", onChange: () => edit(() => {
391
4190
  setBackend("local");
392
4191
  }) }),
393
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { children: [
394
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { children: "\u672C\u5730" }),
395
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("small", { children: "\u6570\u636E\u4FDD\u5B58\u5728\u5F53\u524D DSH \u7684 SQLite \u4E2D" })
4192
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { children: [
4193
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("strong", { children: "\u672C\u5730" }),
4194
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("small", { children: "\u6570\u636E\u4FDD\u5B58\u5728\u5F53\u524D DSH \u7684 SQLite \u4E2D" })
396
4195
  ] })
397
4196
  ] }),
398
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", { className: `${backend === "remote" ? "is-selected" : ""}${!current?.canSwitchRemote ? " is-disabled" : ""}`, children: [
399
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", { type: "radio", name: "dsh-knowledge-backend", checked: backend === "remote", disabled: !current?.canSwitchRemote, onChange: () => edit(() => {
4197
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { className: `${backend === "remote" ? "is-selected" : ""}${!current?.canSwitchRemote ? " is-disabled" : ""}`, children: [
4198
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("input", { type: "radio", name: "dsh-knowledge-backend", checked: backend === "remote", disabled: !current?.canSwitchRemote, onChange: () => edit(() => {
400
4199
  setBackend("remote");
401
4200
  }) }),
402
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { children: [
403
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { children: "\u8FDC\u7A0B" }),
404
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("small", { children: "\u53EC\u56DE\u548C\u56DE\u5199\u7EDF\u4E00\u4F7F\u7528\u4E2D\u592E\u77E5\u8BC6\u5E93" })
4201
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { children: [
4202
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("strong", { children: "\u8FDC\u7A0B" }),
4203
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("small", { children: "\u53EC\u56DE\u548C\u56DE\u5199\u7EDF\u4E00\u4F7F\u7528\u4E2D\u592E\u77E5\u8BC6\u5E93" })
405
4204
  ] })
406
4205
  ] })
407
4206
  ] }),
408
- !current?.canSwitchRemote && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dsh-knowledge-settings-note", children: "\u5F53\u524D\u5B9E\u4F8B\u662F\u4E2D\u592E\u77E5\u8BC6\u5E93\u670D\u52A1\uFF0C\u4E0D\u80FD\u518D\u5207\u6362\u5230\u53E6\u4E00\u53F0\u8FDC\u7A0B\u670D\u52A1\u3002" }),
409
- backend === "remote" && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsh-knowledge-remote-fields", children: [
410
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", { htmlFor: "dsh-knowledge-remote-url", children: [
4207
+ !current?.canSwitchRemote && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "dsh-knowledge-settings-note", children: "\u5F53\u524D\u5B9E\u4F8B\u662F\u4E2D\u592E\u77E5\u8BC6\u5E93\u670D\u52A1\uFF0C\u4E0D\u80FD\u518D\u5207\u6362\u5230\u53E6\u4E00\u53F0\u8FDC\u7A0B\u670D\u52A1\u3002" }),
4208
+ backend === "remote" && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "dsh-knowledge-remote-fields", children: [
4209
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { htmlFor: "dsh-knowledge-remote-url", children: [
411
4210
  "\u670D\u52A1\u5668\u5730\u5740",
412
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", { id: "dsh-knowledge-remote-url", type: "url", value: remoteUrl, placeholder: "https://example.com/knowledge-api/v1", autoComplete: "url", onChange: (event) => edit(() => {
4211
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("input", { id: "dsh-knowledge-remote-url", type: "url", value: remoteUrl, placeholder: "https://example.com/knowledge-api/v1", autoComplete: "url", onChange: (event) => edit(() => {
413
4212
  setRemoteUrl(event.target.value);
414
4213
  }), "aria-invalid": urlError !== void 0, "aria-describedby": urlError ? "dsh-knowledge-url-error" : void 0 }),
415
- urlError && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("small", { id: "dsh-knowledge-url-error", className: "dsh-knowledge-field-error", children: urlError })
4214
+ urlError && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("small", { id: "dsh-knowledge-url-error", className: "dsh-knowledge-field-error", children: urlError })
416
4215
  ] }),
417
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", { htmlFor: "dsh-knowledge-remote-token", children: [
4216
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { htmlFor: "dsh-knowledge-remote-token", children: [
418
4217
  "\u5BA2\u6237\u7AEF\u4EE4\u724C",
419
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", { id: "dsh-knowledge-remote-token", type: "password", value: remoteToken, placeholder: current?.tokenConfigured ? "\u5DF2\u4FDD\u5B58\uFF1B\u7559\u7A7A\u5219\u4FDD\u6301\u4E0D\u53D8" : "\u7C98\u8D34\u5BA2\u6237\u7AEF\u4EE4\u724C", autoComplete: "new-password", onChange: (event) => edit(() => {
4218
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("input", { id: "dsh-knowledge-remote-token", type: "password", value: remoteToken, placeholder: current?.tokenConfigured ? "\u5DF2\u4FDD\u5B58\uFF1B\u7559\u7A7A\u5219\u4FDD\u6301\u4E0D\u53D8" : "\u7C98\u8D34\u5BA2\u6237\u7AEF\u4EE4\u724C", autoComplete: "new-password", onChange: (event) => edit(() => {
420
4219
  setRemoteToken(event.target.value);
421
4220
  }), "aria-invalid": tokenError !== void 0, "aria-describedby": "dsh-knowledge-token-help" }),
422
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("small", { id: "dsh-knowledge-token-help", className: tokenError ? "dsh-knowledge-field-error" : void 0, children: tokenError ?? (current?.tokenConfigured ? "\u4EE4\u724C\u5DF2\u5B89\u5168\u4FDD\u5B58\uFF0C\u9875\u9762\u65E0\u6CD5\u8BFB\u53D6\uFF1B\u8F93\u5165\u65B0\u4EE4\u724C\u53EF\u8986\u76D6\u3002" : "\u4EE4\u724C\u4FDD\u5B58\u540E\u4E0D\u53EF\u8BFB\u53D6\uFF0C\u53EA\u80FD\u8986\u76D6\u3002") })
4221
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("small", { id: "dsh-knowledge-token-help", className: tokenError ? "dsh-knowledge-field-error" : void 0, children: tokenError ?? (current?.tokenConfigured ? "\u4EE4\u724C\u5DF2\u5B89\u5168\u4FDD\u5B58\uFF0C\u9875\u9762\u65E0\u6CD5\u8BFB\u53D6\uFF1B\u8F93\u5165\u65B0\u4EE4\u724C\u53EF\u8986\u76D6\u3002" : "\u4EE4\u724C\u4FDD\u5B58\u540E\u4E0D\u53EF\u8BFB\u53D6\uFF0C\u53EA\u80FD\u8986\u76D6\u3002") })
423
4222
  ] })
424
4223
  ] }),
425
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", { className: "dsh-knowledge-timeout-field", htmlFor: "dsh-knowledge-timeout", children: [
4224
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { className: "dsh-knowledge-timeout-field", htmlFor: "dsh-knowledge-timeout", children: [
426
4225
  "\u8BF7\u6C42\u8D85\u65F6\uFF08\u6BEB\u79D2\uFF09",
427
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", { id: "dsh-knowledge-timeout", type: "number", min: "100", max: "120000", step: "100", value: timeout, onChange: (event) => edit(() => {
4226
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("input", { id: "dsh-knowledge-timeout", type: "number", min: "100", max: "120000", step: "100", value: timeout, onChange: (event) => edit(() => {
428
4227
  setTimeoutValue(event.target.value);
429
4228
  }), "aria-invalid": timeoutError !== void 0 }),
430
- timeoutError && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("small", { className: "dsh-knowledge-field-error", children: timeoutError })
4229
+ timeoutError && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("small", { className: "dsh-knowledge-field-error", children: timeoutError })
431
4230
  ] }),
432
- !current?.writable && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dsh-knowledge-settings-note", children: "\u5F53\u524D\u63D2\u4EF6\u6CA1\u6709\u914D\u7F6E\u6301\u4E45\u5316\u8DEF\u5F84\uFF0C\u65E0\u6CD5\u4FDD\u5B58\u8FDE\u63A5\u3002" }),
433
- message && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: `dsh-knowledge-settings-message is-${message.kind}`, role: message.kind === "error" ? "alert" : "status", "aria-live": "polite", children: message.text }),
434
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsh-knowledge-settings-actions", children: [
435
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", onClick: reset, disabled: !dirty || saving, children: "\u653E\u5F03\u66F4\u6539" }),
436
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "is-primary", onClick: () => {
4231
+ !current?.writable && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "dsh-knowledge-settings-note", children: "\u5F53\u524D\u63D2\u4EF6\u6CA1\u6709\u914D\u7F6E\u6301\u4E45\u5316\u8DEF\u5F84\uFF0C\u65E0\u6CD5\u4FDD\u5B58\u8FDE\u63A5\u3002" }),
4232
+ message3 && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: `dsh-knowledge-settings-message is-${message3.kind}`, role: message3.kind === "error" ? "alert" : "status", "aria-live": "polite", children: message3.text }),
4233
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "dsh-knowledge-settings-actions", children: [
4234
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { type: "button", onClick: reset, disabled: !dirty || saving, children: "\u653E\u5F03\u66F4\u6539" }),
4235
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { type: "button", className: "is-primary", onClick: () => {
437
4236
  void save();
438
4237
  }, disabled: !dirty || invalid || saving || !current?.writable, children: saving ? "\u6B63\u5728\u9A8C\u8BC1\u2026" : "\u9A8C\u8BC1\u5E76\u8FDE\u63A5" })
439
4238
  ] })
@@ -451,9 +4250,9 @@ function validateRemoteUrl(value) {
451
4250
  }
452
4251
  }
453
4252
  function connectionErrorMessage(error) {
454
- const message = error instanceof Error ? error.message : String(error);
455
- if (message.includes("Failed to fetch")) return "\u65E0\u6CD5\u8BBF\u95EE\u63D2\u4EF6\u8FDE\u63A5\u63A5\u53E3\uFF0C\u8BF7\u786E\u8BA4\u63D2\u4EF6\u670D\u52A1\u5DF2\u52A0\u8F7D\u3002";
456
- return message || "\u8FDE\u63A5\u914D\u7F6E\u64CD\u4F5C\u5931\u8D25\uFF0C\u8BF7\u68C0\u67E5\u5730\u5740\u3001\u4EE4\u724C\u548C DSH \u65E5\u5FD7\u3002";
4253
+ const message3 = error instanceof Error ? error.message : String(error);
4254
+ if (message3.includes("Failed to fetch")) return "\u65E0\u6CD5\u8BBF\u95EE\u63D2\u4EF6\u8FDE\u63A5\u63A5\u53E3\uFF0C\u8BF7\u786E\u8BA4\u63D2\u4EF6\u670D\u52A1\u5DF2\u52A0\u8F7D\u3002";
4255
+ return message3 || "\u8FDE\u63A5\u914D\u7F6E\u64CD\u4F5C\u5931\u8D25\uFF0C\u8BF7\u68C0\u67E5\u5730\u5740\u3001\u4EE4\u724C\u548C DSH \u65E5\u5FD7\u3002";
457
4256
  }
458
4257
  async function requestConnection(method, body, signal) {
459
4258
  const response = await fetch(CONNECTION_CONTROL_PATH, {
@@ -464,8 +4263,8 @@ async function requestConnection(method, body, signal) {
464
4263
  });
465
4264
  const payload = await response.json().catch(() => void 0);
466
4265
  if (!response.ok) {
467
- const message = payload !== null && typeof payload === "object" && typeof payload.error === "string" ? payload.error : `\u8FDE\u63A5\u63A5\u53E3\u8FD4\u56DE HTTP ${response.status}`;
468
- throw new Error(message);
4266
+ const message3 = payload !== null && typeof payload === "object" && typeof payload.error === "string" ? payload.error : `\u8FDE\u63A5\u63A5\u53E3\u8FD4\u56DE HTTP ${response.status}`;
4267
+ throw new Error(message3);
469
4268
  }
470
4269
  if (!isConnectionView(payload)) throw new Error("\u63D2\u4EF6\u8FDE\u63A5\u63A5\u53E3\u8FD4\u56DE\u4E86\u65E0\u6548\u6570\u636E\u3002");
471
4270
  cachedConnectionView = payload;
@@ -479,25 +4278,50 @@ function isConnectionView(value) {
479
4278
  function isManagementPath(value) {
480
4279
  return typeof value === "string" && value.startsWith("/") && !value.startsWith("//");
481
4280
  }
482
- function KnowledgeLauncher({ wide, workspace }) {
483
- const [open, setOpen] = (0, import_react.useState)(workspace.isOpen());
484
- (0, import_react.useEffect)(() => workspace.subscribe(() => {
4281
+ function KnowledgeLauncher({ wide, useSessions, workspace, activity }) {
4282
+ const [open, setOpen] = (0, import_react4.useState)(workspace.isOpen());
4283
+ const currentSessionId = useSessions(availableActivitySession);
4284
+ const [activityOpen, setActivityOpen] = (0, import_react4.useState)(currentSessionId === void 0 ? false : activity.isOpen(currentSessionId));
4285
+ const [compactViewport, setCompactViewport] = (0, import_react4.useState)(() => window.matchMedia(COMPACT_KNOWLEDGE_VIEWPORT).matches);
4286
+ (0, import_react4.useEffect)(() => workspace.subscribe(() => {
485
4287
  setOpen(workspace.isOpen());
486
4288
  }), [workspace]);
487
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
4289
+ (0, import_react4.useEffect)(() => {
4290
+ const sync = () => {
4291
+ setActivityOpen(currentSessionId === void 0 ? false : activity.isOpen(currentSessionId));
4292
+ };
4293
+ sync();
4294
+ return activity.subscribe(sync);
4295
+ }, [activity, currentSessionId]);
4296
+ (0, import_react4.useEffect)(() => {
4297
+ const query = window.matchMedia(COMPACT_KNOWLEDGE_VIEWPORT);
4298
+ const sync = () => {
4299
+ setCompactViewport(query.matches);
4300
+ };
4301
+ sync();
4302
+ query.addEventListener("change", sync);
4303
+ return () => {
4304
+ query.removeEventListener("change", sync);
4305
+ };
4306
+ }, []);
4307
+ const active = open || activityOpen;
4308
+ const activate = () => {
4309
+ if (open) return workspace.close();
4310
+ if (compactViewport || currentSessionId === void 0) return workspace.open();
4311
+ if (currentSessionId !== void 0) activity.toggle(currentSessionId);
4312
+ };
4313
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
488
4314
  "button",
489
4315
  {
490
4316
  type: "button",
491
- className: `dsh-knowledge-trigger${wide ? "" : " dsh-knowledge-trigger--rail"}${open ? " is-active" : ""}`,
492
- "aria-label": open ? "\u8FD4\u56DE\u5BF9\u8BDD" : "\u77E5\u8BC6\u5E93",
493
- "aria-pressed": open,
494
- title: wide ? void 0 : open ? "\u8FD4\u56DE\u5BF9\u8BDD" : "\u77E5\u8BC6\u5E93",
495
- onClick: () => {
496
- workspace.toggle();
497
- },
4317
+ className: `dsh-knowledge-trigger${wide ? "" : " dsh-knowledge-trigger--rail"}${active ? " is-active" : ""}`,
4318
+ "aria-label": active ? "\u8FD4\u56DE\u5BF9\u8BDD" : compactViewport || currentSessionId === void 0 ? "\u6253\u5F00\u77E5\u8BC6\u5E93\u5DE5\u4F5C\u533A" : "\u5C55\u5F00\u4F1A\u8BDD\u77E5\u8BC6\u5E93",
4319
+ "aria-pressed": active,
4320
+ title: wide ? void 0 : active ? "\u8FD4\u56DE\u5BF9\u8BDD" : "\u77E5\u8BC6\u5E93",
4321
+ onClick: activate,
498
4322
  children: [
499
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dsh_client_ui_primitives.IconDataOutline16, { size: wide ? 16 : 18 }),
500
- wide && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: open ? "\u8FD4\u56DE\u5BF9\u8BDD" : "\u77E5\u8BC6\u5E93" })
4323
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_dsh_client_ui_primitives3.IconDataOutline16, { size: wide ? 16 : 18 }),
4324
+ wide && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: "\u77E5\u8BC6\u5E93" })
501
4325
  ]
502
4326
  }
503
4327
  );
@@ -509,15 +4333,15 @@ function KnowledgeWorkspace({
509
4333
  workspace
510
4334
  }) {
511
4335
  const cachedManagementPath = cachedConnectionView?.managementAvailable ? cachedConnectionView.managementPath : void 0;
512
- const [panelState, setPanelState] = (0, import_react.useState)(cachedConnectionView === void 0 ? "loading" : cachedManagementPath === void 0 ? "unavailable" : "ready");
513
- const [managementPath, setManagementPath] = (0, import_react.useState)(cachedManagementPath);
514
- const [panelError, setPanelError] = (0, import_react.useState)("");
515
- const [target, setTarget] = (0, import_react.useState)(workspace.currentTarget());
4336
+ const [panelState, setPanelState] = (0, import_react4.useState)(cachedConnectionView === void 0 ? "loading" : cachedManagementPath === void 0 ? "unavailable" : "ready");
4337
+ const [managementPath, setManagementPath] = (0, import_react4.useState)(cachedManagementPath);
4338
+ const [panelError, setPanelError] = (0, import_react4.useState)("");
4339
+ const [target, setTarget] = (0, import_react4.useState)(workspace.currentTarget());
516
4340
  const projectId = useSessions((state) => sessionId === void 0 ? void 0 : state.byId[sessionId]?.cwd);
517
4341
  const knowledgeUrl = managementPath === void 0 ? void 0 : knowledgePanelUrl(managementPath, sessionId, projectId, target);
518
- const frame = (0, import_react.useRef)(null);
519
- const themeFrame = (0, import_react.useRef)(0);
520
- const loadManagement = (0, import_react.useCallback)(async (background = false) => {
4342
+ const frame = (0, import_react4.useRef)(null);
4343
+ const themeFrame = (0, import_react4.useRef)(0);
4344
+ const loadManagement = (0, import_react4.useCallback)(async (background = false) => {
521
4345
  if (!background) setPanelState("loading");
522
4346
  setPanelError("");
523
4347
  try {
@@ -535,31 +4359,30 @@ function KnowledgeWorkspace({
535
4359
  setPanelState("error");
536
4360
  }
537
4361
  }, []);
538
- (0, import_react.useEffect)(() => {
4362
+ (0, import_react4.useEffect)(() => {
539
4363
  void loadManagement(cachedConnectionView !== void 0);
540
4364
  }, [loadManagement]);
541
- (0, import_react.useEffect)(() => workspace.subscribe(() => {
4365
+ (0, import_react4.useEffect)(() => workspace.subscribe(() => {
542
4366
  setTarget(workspace.currentTarget());
543
4367
  }), [workspace]);
544
- const sendTheme = (0, import_react.useCallback)(() => {
4368
+ const sendTheme = (0, import_react4.useCallback)(() => {
545
4369
  const currentFrame = frame.current;
546
4370
  if (currentFrame === null) return;
547
4371
  const target2 = currentFrame.contentWindow;
548
4372
  if (target2 === null) return;
549
- const computed = getComputedStyle(document.body);
550
4373
  target2.postMessage(
551
- createKnowledgeHostTheme(computed, client.theme.getTheme()),
4374
+ createKnowledgeHostTheme(client.theme.getTheme()),
552
4375
  frameOrigin(currentFrame) ?? "*"
553
4376
  );
554
4377
  }, [client]);
555
- const scheduleTheme = (0, import_react.useCallback)(() => {
4378
+ const scheduleTheme = (0, import_react4.useCallback)(() => {
556
4379
  if (themeFrame.current !== 0) window.cancelAnimationFrame(themeFrame.current);
557
4380
  themeFrame.current = window.requestAnimationFrame(() => {
558
4381
  themeFrame.current = 0;
559
4382
  sendTheme();
560
4383
  });
561
4384
  }, [sendTheme]);
562
- (0, import_react.useEffect)(() => {
4385
+ (0, import_react4.useEffect)(() => {
563
4386
  const off = client.on("theme/change", scheduleTheme);
564
4387
  const onMessage = (event) => {
565
4388
  const currentFrame = frame.current;
@@ -577,21 +4400,21 @@ function KnowledgeWorkspace({
577
4400
  if (themeFrame.current !== 0) window.cancelAnimationFrame(themeFrame.current);
578
4401
  };
579
4402
  }, [client, scheduleTheme, sendTheme]);
580
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", { className: "dsh-knowledge-workspace", "data-xiaohei-surface": "plugin-workspace", "aria-labelledby": "dsh-knowledge-workspace-title", children: [
581
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("header", { className: "dsh-knowledge-workspace-header", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
582
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", "data-xiaohei-workspace-close": true, onClick: workspace.close, "aria-label": "\u8FD4\u56DE\u4F1A\u8BDD", title: "\u8FD4\u56DE\u4F1A\u8BDD", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dsh_client_ui_primitives.IconChevronLeftOutline14, { size: 15 }) }),
583
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dsh_client_ui_primitives.IconDataOutline16, { size: 18 }),
584
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { children: [
585
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { id: "dsh-knowledge-workspace-title", children: "\u77E5\u8BC6\u5E93" }),
586
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: "\u6587\u6863\u3001\u5BA1\u6838\u3001\u6302\u8F7D\u4E0E\u8BBF\u95EE\u7BA1\u7406" })
4403
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("section", { className: "dsh-knowledge-workspace", "data-knowledge-surface": "workspace", "aria-labelledby": "dsh-knowledge-workspace-title", children: [
4404
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("header", { className: "dsh-knowledge-workspace-header", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
4405
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { type: "button", "data-knowledge-workspace-close": true, onClick: workspace.close, "aria-label": "\u8FD4\u56DE\u4F1A\u8BDD", title: "\u8FD4\u56DE\u4F1A\u8BDD", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_dsh_client_ui_primitives3.IconChevronLeftOutline14, { size: 15 }) }),
4406
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_dsh_client_ui_primitives3.IconDataOutline16, { size: 18 }),
4407
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { children: [
4408
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("h2", { id: "dsh-knowledge-workspace-title", children: "\u77E5\u8BC6\u5E93" }),
4409
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { children: "\u6587\u6863\u3001\u5BA1\u6838\u3001\u6302\u8F7D\u4E0E\u8BBF\u95EE\u7BA1\u7406" })
587
4410
  ] })
588
4411
  ] }) }),
589
- panelState === "ready" && knowledgeUrl !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("iframe", { ref: frame, className: "dsh-knowledge-frame", src: knowledgeUrl, title: "\u77E5\u8BC6\u5E93\u7BA1\u7406\u53F0", onLoad: sendTheme }) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsh-knowledge-panel-state", role: panelState === "error" ? "alert" : "status", "aria-live": "polite", children: [
590
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dsh-knowledge-panel-state-icon", "aria-hidden": "true", children: panelState === "loading" ? "\xB7\xB7\xB7" : panelState === "error" ? "!" : "\u2014" }),
591
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
592
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", { children: panelState === "loading" ? "\u6B63\u5728\u6253\u5F00\u77E5\u8BC6\u5E93\u2026" : panelState === "error" ? "\u6682\u65F6\u65E0\u6CD5\u6253\u5F00\u77E5\u8BC6\u5E93" : "\u8FD9\u53F0 DSH \u672A\u542F\u7528\u77E5\u8BC6\u5E93\u7BA1\u7406\u53F0" }),
593
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: panelState === "loading" ? "\u6B63\u5728\u786E\u8BA4\u5F53\u524D\u5B9E\u4F8B\u662F\u5426\u63D0\u4F9B\u7BA1\u7406\u9875\u9762\u3002" : panelState === "error" ? panelError : "\u672C\u5730\u53EC\u56DE\u548C\u56DE\u5199\u4ECD\u53EF\u4F7F\u7528\u3002\u5F53\u524D profile \u5DF2\u663E\u5F0F\u5173\u95ED exposeWeb\uFF1B\u91CD\u65B0\u542F\u7528\u540E\u5373\u53EF\u5728\u8FD9\u91CC\u7BA1\u7406\u3002\u4F7F\u7528\u8FDC\u7A0B\u77E5\u8BC6\u5E93\u65F6\uFF0C\u8BF7\u524D\u5F80\u4E2D\u592E DSH \u7684\u77E5\u8BC6\u5E93\u7BA1\u7406\u53F0\u3002" }),
594
- panelState === "error" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", onClick: () => {
4412
+ panelState === "ready" && knowledgeUrl !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("iframe", { ref: frame, className: "dsh-knowledge-frame", src: knowledgeUrl, title: "\u77E5\u8BC6\u5E93\u7BA1\u7406\u53F0", onLoad: sendTheme }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "dsh-knowledge-panel-state", role: panelState === "error" ? "alert" : "status", "aria-live": "polite", children: [
4413
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "dsh-knowledge-panel-state-icon", "aria-hidden": "true", children: panelState === "loading" ? "\xB7\xB7\xB7" : panelState === "error" ? "!" : "\u2014" }),
4414
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
4415
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("h3", { children: panelState === "loading" ? "\u6B63\u5728\u6253\u5F00\u77E5\u8BC6\u5E93\u2026" : panelState === "error" ? "\u6682\u65F6\u65E0\u6CD5\u6253\u5F00\u77E5\u8BC6\u5E93" : "\u8FD9\u53F0 DSH \u672A\u542F\u7528\u77E5\u8BC6\u5E93\u7BA1\u7406\u53F0" }),
4416
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { children: panelState === "loading" ? "\u6B63\u5728\u786E\u8BA4\u5F53\u524D\u5B9E\u4F8B\u662F\u5426\u63D0\u4F9B\u7BA1\u7406\u9875\u9762\u3002" : panelState === "error" ? panelError : "\u672C\u5730\u53EC\u56DE\u548C\u56DE\u5199\u4ECD\u53EF\u4F7F\u7528\u3002\u5F53\u524D profile \u5DF2\u663E\u5F0F\u5173\u95ED exposeWeb\uFF1B\u91CD\u65B0\u542F\u7528\u540E\u5373\u53EF\u5728\u8FD9\u91CC\u7BA1\u7406\u3002\u4F7F\u7528\u8FDC\u7A0B\u77E5\u8BC6\u5E93\u65F6\uFF0C\u8BF7\u524D\u5F80\u4E2D\u592E DSH \u7684\u77E5\u8BC6\u5E93\u7BA1\u7406\u53F0\u3002" }),
4417
+ panelState === "error" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { type: "button", onClick: () => {
595
4418
  void loadManagement();
596
4419
  }, children: "\u91CD\u8BD5" })
597
4420
  ] })
@@ -603,8 +4426,13 @@ function knowledgePanelUrl(managementPath, sessionId, projectId, target) {
603
4426
  if (sessionId !== void 0) params.set("sessionId", sessionId);
604
4427
  if (projectId !== void 0) params.set("projectId", projectId);
605
4428
  if (target !== void 0) {
606
- params.set("knowledgeBaseId", target.knowledgeBaseId);
607
- params.set("documentId", target.documentId);
4429
+ if (target.view === "notes") {
4430
+ params.set("view", "notes");
4431
+ if (target.noteId !== void 0) params.set("noteId", target.noteId);
4432
+ } else {
4433
+ params.set("knowledgeBaseId", target.knowledgeBaseId);
4434
+ params.set("documentId", target.documentId);
4435
+ }
608
4436
  }
609
4437
  const query = params.toString();
610
4438
  return query.length === 0 ? managementPath : `${managementPath}${managementPath.includes("?") ? "&" : "?"}${query}`;
@@ -623,11 +4451,17 @@ function installStyles() {
623
4451
  const style = document.createElement("style");
624
4452
  style.dataset.plugin = PLUGIN_ID;
625
4453
  style.dataset.pluginCss = STYLE_ID;
626
- style.textContent = client_default;
4454
+ const scope = ":is(.dsh-knowledge-trigger, .dsh-knowledge-activity-panel, .dsh-knowledge-workspace, .dsh-knowledge-settings-card, .dsh-knowledge-writeback-notice)";
4455
+ style.textContent = knowledgeDesignCss(scope, "body[data-ds-dark-theme] " + scope, false) + client_default + knowledge_activity_default;
627
4456
  document.head.appendChild(style);
628
4457
  return () => {
629
4458
  style.remove();
630
4459
  };
631
4460
  }
4461
+ /*! Bundled license information:
4462
+
4463
+ dompurify/dist/purify.es.mjs:
4464
+ (*! @license DOMPurify 3.4.14 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.4.14/LICENSE *)
4465
+ */
632
4466
  return module.exports; } });
633
4467
  //# sourceMappingURL=client.js.map