codesign-mcp-next 0.0.0-stage → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +137 -0
- package/LICENSE +21 -0
- package/README.md +457 -2
- package/dist/browser/manager.js +204 -0
- package/dist/browser/session.js +62 -0
- package/dist/codesign/cache.js +85 -0
- package/dist/codesign/errors.js +47 -0
- package/dist/codesign/integrity.js +197 -0
- package/dist/codesign/meta.js +57 -0
- package/dist/codesign/parser.js +56 -0
- package/dist/codesign/platform.js +232 -0
- package/dist/codesign/selection.js +205 -0
- package/dist/codesign/sharing.js +153 -0
- package/dist/codesign/slices.js +34 -0
- package/dist/codesign/types.js +1 -0
- package/dist/config.js +94 -0
- package/dist/index.js +16 -0
- package/dist/logger.js +68 -0
- package/dist/mcp/result.js +151 -0
- package/dist/mcp/schema.js +122 -0
- package/dist/mcp/server.js +313 -0
- package/dist/prompts/design-to-code.js +128 -0
- package/dist/resources/workflow.js +33 -0
- package/dist/server.js +61 -0
- package/dist/tools/artboards.js +96 -0
- package/dist/tools/diagnostics.js +192 -0
- package/dist/tools/image.js +134 -0
- package/dist/tools/login.js +136 -0
- package/dist/tools/slices.js +228 -0
- package/dist/tools/spec.js +236 -0
- package/dist/tools/status.js +62 -0
- package/dist/utils/download.js +290 -0
- package/dist/utils/filename.js +16 -0
- package/dist/utils/http.js +54 -0
- package/dist/utils/rate-limit.js +120 -0
- package/dist/utils/redact.js +110 -0
- package/dist/utils/retry.js +97 -0
- package/dist/utils/url.js +98 -0
- package/package.json +56 -4
- package/userscripts/codesign-ai-selection.user.js +445 -0
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
// ==UserScript==
|
|
2
|
+
// @name CoDesign AI 选区复制
|
|
3
|
+
// @name:en CoDesign Copy AI Selection
|
|
4
|
+
// @namespace https://github.com/ccpopy/codesign-mcp
|
|
5
|
+
// @version 0.1.4
|
|
6
|
+
// @description 将当前 CoDesign 画板和图层选区复制为 codesign-mcp 可使用的 Agent 提示词。
|
|
7
|
+
// @description:en Copy the current CoDesign screen and layer selection as a codesign-mcp Agent prompt.
|
|
8
|
+
// @author codesign-mcp contributors
|
|
9
|
+
// @homepageURL https://github.com/ccpopy/codesign-mcp
|
|
10
|
+
// @supportURL https://github.com/ccpopy/codesign-mcp/issues
|
|
11
|
+
// @match https://codesign.qq.com/app/s/*
|
|
12
|
+
// @match https://codesign.qq.com/s/*
|
|
13
|
+
// @grant GM_setClipboard
|
|
14
|
+
// @grant GM.setClipboard
|
|
15
|
+
// @run-at document-idle
|
|
16
|
+
// @updateURL https://raw.githubusercontent.com/ccpopy/codesign-mcp/main/userscripts/codesign-ai-selection.user.js
|
|
17
|
+
// @downloadURL https://raw.githubusercontent.com/ccpopy/codesign-mcp/main/userscripts/codesign-ai-selection.user.js
|
|
18
|
+
// ==/UserScript==
|
|
19
|
+
|
|
20
|
+
(function () {
|
|
21
|
+
'use strict';
|
|
22
|
+
|
|
23
|
+
const BUTTON_ID = 'codesign-ai-selection-copy';
|
|
24
|
+
const STYLE_ID = 'codesign-ai-selection-style';
|
|
25
|
+
const TOAST_ID = 'codesign-ai-selection-toast';
|
|
26
|
+
const USERSCRIPT_VERSION = '0.1.4';
|
|
27
|
+
const SELECTION_SCOPE = 'region';
|
|
28
|
+
const SELECTORS = Object.freeze({
|
|
29
|
+
inspectorHeaders: 'aside.screen-inspector .node-box__header',
|
|
30
|
+
inspectorAction: ':scope > .node-box__btn',
|
|
31
|
+
inspectorTitle: '.node-box__header--title, .node-box__header--left',
|
|
32
|
+
activeScreen: '.board-screen-list__item.active[data-id]',
|
|
33
|
+
selectedCanvasLayer:
|
|
34
|
+
'.selected.layer[data-object-id][data-layer-name]:not(.orange-dash-rect)',
|
|
35
|
+
activeLayerWrapper: '.custom-tree__node-wrapper.active',
|
|
36
|
+
activeLayerNode: ':scope > .custom-tree__node[id^="id-"]',
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
let refreshScheduled = false;
|
|
40
|
+
let lastPointerActivationAt = 0;
|
|
41
|
+
const handledActivationEvents = new WeakSet();
|
|
42
|
+
const boundButtons = new WeakSet();
|
|
43
|
+
|
|
44
|
+
document.getElementById(BUTTON_ID)?.remove();
|
|
45
|
+
installStyles();
|
|
46
|
+
window.addEventListener('pointerdown', handleButtonPointerDown, true);
|
|
47
|
+
document.addEventListener('pointerdown', handleButtonPointerDown, true);
|
|
48
|
+
document.addEventListener('click', handleButtonClick, true);
|
|
49
|
+
refreshButton();
|
|
50
|
+
|
|
51
|
+
const observer = new MutationObserver(scheduleRefresh);
|
|
52
|
+
observer.observe(document.documentElement, {
|
|
53
|
+
childList: true,
|
|
54
|
+
subtree: true,
|
|
55
|
+
attributes: true,
|
|
56
|
+
attributeFilter: ['class', 'data-id', 'data-layer-name', 'data-object-id', 'id', 'title'],
|
|
57
|
+
});
|
|
58
|
+
window.addEventListener('popstate', scheduleRefresh);
|
|
59
|
+
window.addEventListener('hashchange', scheduleRefresh);
|
|
60
|
+
|
|
61
|
+
function scheduleRefresh() {
|
|
62
|
+
if (refreshScheduled) return;
|
|
63
|
+
refreshScheduled = true;
|
|
64
|
+
requestAnimationFrame(() => {
|
|
65
|
+
refreshScheduled = false;
|
|
66
|
+
refreshButton();
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function refreshButton() {
|
|
71
|
+
const header = findInspectorHeader();
|
|
72
|
+
if (!header) return;
|
|
73
|
+
|
|
74
|
+
let button = document.getElementById(BUTTON_ID);
|
|
75
|
+
if (!button) {
|
|
76
|
+
button = document.createElement('button');
|
|
77
|
+
button.id = BUTTON_ID;
|
|
78
|
+
button.type = 'button';
|
|
79
|
+
button.textContent = '复制给 AI';
|
|
80
|
+
}
|
|
81
|
+
button.dataset.userscriptVersion = USERSCRIPT_VERSION;
|
|
82
|
+
bindButtonEvents(button);
|
|
83
|
+
const nativeAction = header.querySelector(SELECTORS.inspectorAction);
|
|
84
|
+
if (nativeAction) header.insertBefore(button, nativeAction);
|
|
85
|
+
else if (button.parentElement !== header) header.append(button);
|
|
86
|
+
|
|
87
|
+
const selection = readSelection(false, header);
|
|
88
|
+
const disabled = selection == null;
|
|
89
|
+
if (button.disabled !== disabled) button.disabled = disabled;
|
|
90
|
+
const title = selection
|
|
91
|
+
? `复制 ${selection.screenName} / ${selection.layerName} 的 AI 选区提示词`
|
|
92
|
+
: '请先在 CoDesign 画布或图层面板中选中一个图层或分组';
|
|
93
|
+
if (button.title !== title) button.title = title;
|
|
94
|
+
if (button.getAttribute('aria-label') !== title) button.setAttribute('aria-label', title);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function bindButtonEvents(button) {
|
|
98
|
+
if (boundButtons.has(button)) return;
|
|
99
|
+
boundButtons.add(button);
|
|
100
|
+
button.addEventListener('pointerdown', handleButtonPointerDown, true);
|
|
101
|
+
button.addEventListener('mousedown', stopButtonEvent, true);
|
|
102
|
+
button.addEventListener('click', handleButtonClick, true);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function handleButtonPointerDown(event) {
|
|
106
|
+
if (event.button !== 0 || event.isPrimary === false) return;
|
|
107
|
+
const button = findEventButton(event);
|
|
108
|
+
if (!button || handledActivationEvents.has(event)) return;
|
|
109
|
+
|
|
110
|
+
handledActivationEvents.add(event);
|
|
111
|
+
stopButtonEvent(event);
|
|
112
|
+
lastPointerActivationAt = Date.now();
|
|
113
|
+
if (button.disabled) return;
|
|
114
|
+
void copySelectionPrompt(button);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function handleButtonClick(event) {
|
|
118
|
+
const button = findEventButton(event);
|
|
119
|
+
if (!button || handledActivationEvents.has(event)) return;
|
|
120
|
+
|
|
121
|
+
handledActivationEvents.add(event);
|
|
122
|
+
stopButtonEvent(event);
|
|
123
|
+
|
|
124
|
+
if (button.disabled || Date.now() - lastPointerActivationAt < 1000) return;
|
|
125
|
+
void copySelectionPrompt(button);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function stopButtonEvent(event) {
|
|
129
|
+
if (!findEventButton(event)) return;
|
|
130
|
+
event.preventDefault();
|
|
131
|
+
event.stopPropagation();
|
|
132
|
+
event.stopImmediatePropagation?.();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function findEventButton(event) {
|
|
136
|
+
const path = typeof event.composedPath === 'function' ? event.composedPath() : [event.target];
|
|
137
|
+
for (const target of path) {
|
|
138
|
+
if (target?.id === BUTTON_ID) return target;
|
|
139
|
+
if (typeof target?.closest === 'function') {
|
|
140
|
+
const button = target.closest(`#${BUTTON_ID}`);
|
|
141
|
+
if (button) return button;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
async function copySelectionPrompt(button) {
|
|
148
|
+
setButtonBusy(button, true);
|
|
149
|
+
try {
|
|
150
|
+
const selection = readSelection(true);
|
|
151
|
+
const prompt = buildPrompt(selection);
|
|
152
|
+
await writeClipboard(prompt);
|
|
153
|
+
showToast(`已复制:${selection.screenName} / ${selection.layerName}`, 'success');
|
|
154
|
+
} catch (error) {
|
|
155
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
156
|
+
console.error('[codesign-ai-selection]', error);
|
|
157
|
+
showToast(message, 'error');
|
|
158
|
+
} finally {
|
|
159
|
+
setButtonBusy(button, false);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
async function writeClipboard(text) {
|
|
164
|
+
const errors = [];
|
|
165
|
+
|
|
166
|
+
try {
|
|
167
|
+
copyWithTextArea(text);
|
|
168
|
+
return;
|
|
169
|
+
} catch (error) {
|
|
170
|
+
errors.push(error);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (navigator.clipboard && typeof navigator.clipboard.writeText === 'function') {
|
|
174
|
+
try {
|
|
175
|
+
await navigator.clipboard.writeText(text);
|
|
176
|
+
return;
|
|
177
|
+
} catch (error) {
|
|
178
|
+
errors.push(error);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (typeof GM_setClipboard === 'function') {
|
|
183
|
+
try {
|
|
184
|
+
GM_setClipboard(text);
|
|
185
|
+
return;
|
|
186
|
+
} catch (error) {
|
|
187
|
+
errors.push(error);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (typeof GM !== 'undefined' && typeof GM.setClipboard === 'function') {
|
|
192
|
+
try {
|
|
193
|
+
await GM.setClipboard(text);
|
|
194
|
+
return;
|
|
195
|
+
} catch (error) {
|
|
196
|
+
errors.push(error);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const lastError = errors.at(-1);
|
|
201
|
+
const detail = lastError instanceof Error ? `:${lastError.message}` : '';
|
|
202
|
+
throw new Error(`无法写入剪贴板${detail}`);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function copyWithTextArea(text) {
|
|
206
|
+
const textArea = document.createElement('textarea');
|
|
207
|
+
textArea.value = text;
|
|
208
|
+
textArea.setAttribute('readonly', '');
|
|
209
|
+
textArea.setAttribute('aria-hidden', 'true');
|
|
210
|
+
textArea.style.position = 'fixed';
|
|
211
|
+
textArea.style.left = '-9999px';
|
|
212
|
+
textArea.style.top = '0';
|
|
213
|
+
textArea.style.opacity = '0';
|
|
214
|
+
document.body.append(textArea);
|
|
215
|
+
|
|
216
|
+
const activeElement = document.activeElement;
|
|
217
|
+
const selection = document.getSelection();
|
|
218
|
+
const selectedRanges = [];
|
|
219
|
+
if (selection) {
|
|
220
|
+
for (let index = 0; index < selection.rangeCount; index += 1) {
|
|
221
|
+
selectedRanges.push(selection.getRangeAt(index).cloneRange());
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
textArea.focus({ preventScroll: true });
|
|
226
|
+
textArea.select();
|
|
227
|
+
|
|
228
|
+
try {
|
|
229
|
+
if (!document.execCommand('copy')) {
|
|
230
|
+
throw new Error('浏览器拒绝写入剪贴板,请检查用户脚本管理器的剪贴板权限。');
|
|
231
|
+
}
|
|
232
|
+
} finally {
|
|
233
|
+
textArea.remove();
|
|
234
|
+
|
|
235
|
+
if (selection) {
|
|
236
|
+
selection.removeAllRanges();
|
|
237
|
+
for (const range of selectedRanges) selection.addRange(range);
|
|
238
|
+
}
|
|
239
|
+
if (activeElement instanceof HTMLElement) activeElement.focus({ preventScroll: true });
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function setButtonBusy(button, busy) {
|
|
244
|
+
if (!button) return;
|
|
245
|
+
button.dataset.copying = busy ? 'true' : 'false';
|
|
246
|
+
button.textContent = busy ? '复制中...' : '复制给 AI';
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function readSelection(required, inspectorHeader = findInspectorHeader()) {
|
|
250
|
+
const screenElements = document.querySelectorAll(SELECTORS.activeScreen);
|
|
251
|
+
|
|
252
|
+
if (screenElements.length !== 1 || !inspectorHeader) {
|
|
253
|
+
if (!required) return null;
|
|
254
|
+
throw new Error(
|
|
255
|
+
`无法确定唯一选区:找到 ${screenElements.length} 个当前画板,右侧标注面板${inspectorHeader ? '已找到' : '未找到'}。`,
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const screenElement = screenElements[0];
|
|
260
|
+
const screenId = screenElement.getAttribute('data-id');
|
|
261
|
+
const screenName = readRequiredLabel(screenElement, '当前画板');
|
|
262
|
+
const layerName = readRequiredLabel(
|
|
263
|
+
inspectorHeader.querySelector(SELECTORS.inspectorTitle),
|
|
264
|
+
'当前图层',
|
|
265
|
+
);
|
|
266
|
+
const layerReference = readLayerReference(layerName, required);
|
|
267
|
+
if (!layerReference) return null;
|
|
268
|
+
const sharingUrl = readSharingUrl();
|
|
269
|
+
|
|
270
|
+
if (!screenId) throw new Error('当前画板缺少 data-id,无法生成 AI 选区引用。');
|
|
271
|
+
|
|
272
|
+
return {
|
|
273
|
+
type: 'codesign-selection',
|
|
274
|
+
sharingUrl,
|
|
275
|
+
screenId,
|
|
276
|
+
screenName,
|
|
277
|
+
layerObjectId: layerReference.objectId,
|
|
278
|
+
layerName,
|
|
279
|
+
selectionScope: SELECTION_SCOPE,
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function findInspectorHeader() {
|
|
284
|
+
return Array.from(document.querySelectorAll(SELECTORS.inspectorHeaders)).find((item) =>
|
|
285
|
+
item.querySelector(SELECTORS.inspectorAction),
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
function readLayerReference(layerName, required) {
|
|
290
|
+
const canvasReferences = uniqueLayerReferences(
|
|
291
|
+
Array.from(document.querySelectorAll(SELECTORS.selectedCanvasLayer))
|
|
292
|
+
.filter(
|
|
293
|
+
(element) =>
|
|
294
|
+
readLabel(element) === layerName && getComputedStyle(element).display !== 'none',
|
|
295
|
+
)
|
|
296
|
+
.map((element) => ({
|
|
297
|
+
objectId: (element.getAttribute('data-object-id') || '').trim(),
|
|
298
|
+
name: readLabel(element),
|
|
299
|
+
})),
|
|
300
|
+
);
|
|
301
|
+
if (canvasReferences.length === 1) return canvasReferences[0];
|
|
302
|
+
|
|
303
|
+
const treeReferences = uniqueLayerReferences(
|
|
304
|
+
Array.from(document.querySelectorAll(SELECTORS.activeLayerWrapper))
|
|
305
|
+
.filter((wrapper) => readLabel(wrapper) === layerName)
|
|
306
|
+
.flatMap((wrapper) =>
|
|
307
|
+
Array.from(wrapper.querySelectorAll(SELECTORS.activeLayerNode)).map((node) => ({
|
|
308
|
+
objectId: node.id.startsWith('id-') ? node.id.slice(3) : '',
|
|
309
|
+
name: readLabel(wrapper),
|
|
310
|
+
})),
|
|
311
|
+
),
|
|
312
|
+
);
|
|
313
|
+
if (treeReferences.length === 1) return treeReferences[0];
|
|
314
|
+
|
|
315
|
+
if (!required) return null;
|
|
316
|
+
throw new Error(
|
|
317
|
+
`无法读取当前图层 ID:画布候选 ${canvasReferences.length} 个、与右侧标注一致的图层树候选 ${treeReferences.length} 个。请重新选择图层。`,
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
function uniqueLayerReferences(references) {
|
|
322
|
+
const unique = new Map();
|
|
323
|
+
for (const reference of references) {
|
|
324
|
+
if (reference.objectId) unique.set(reference.objectId, reference);
|
|
325
|
+
}
|
|
326
|
+
return Array.from(unique.values());
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
function readLabel(element) {
|
|
330
|
+
return (
|
|
331
|
+
element?.getAttribute('data-layer-name') ||
|
|
332
|
+
element?.getAttribute('title') ||
|
|
333
|
+
element?.textContent ||
|
|
334
|
+
''
|
|
335
|
+
).trim();
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
function readRequiredLabel(element, label) {
|
|
339
|
+
const value = readLabel(element);
|
|
340
|
+
if (!value) throw new Error(`${label}缺少可读名称,无法生成 AI 选区引用。`);
|
|
341
|
+
return value;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
function readSharingUrl() {
|
|
345
|
+
const match = location.pathname.match(/\/s\/(\d+)/);
|
|
346
|
+
if (!match) throw new Error('当前地址不是受支持的 CoDesign 分享页。');
|
|
347
|
+
return `${location.origin}/s/${match[1]}`;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
function buildPrompt(selection) {
|
|
351
|
+
const reference = JSON.stringify(selection, null, 2);
|
|
352
|
+
return `请仅实现下面这个 CoDesign 选区,不要实现整张画板。
|
|
353
|
+
|
|
354
|
+
CoDesign selection reference:
|
|
355
|
+
\`\`\`json
|
|
356
|
+
${reference}
|
|
357
|
+
\`\`\`
|
|
358
|
+
|
|
359
|
+
要求:
|
|
360
|
+
1. 调用 codesign-mcp 的 get_artboard_spec,传入 sharingUrl、screenId、layerObjectId、selectionScope,并设置 includeSlices=true。
|
|
361
|
+
2. 使用返回的 selection.layers、selection.groups、selection.hierarchy、selection.bounds 和 relativeRect 还原选区结构。
|
|
362
|
+
3. selectionScope=region 表示实现选中边界内的完整视觉区域,而不只是当前图层的严格子节点。
|
|
363
|
+
4. 默认优先使用语义化结构、正常文档流、Flexbox/Grid;如果用户明确要求 absolute/canvas 式布局,则以用户要求为准,并尽量把定位限制在选区容器内。
|
|
364
|
+
5. 设计师导出的资源使用 download_slice;预览图只用于视觉对比,不作为生产切图来源。
|
|
365
|
+
6. 如果分享链接需要访问码但当前上下文未提供,请明确向用户索取,不要猜测或伪造数据。`;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
function installStyles() {
|
|
369
|
+
if (document.getElementById(STYLE_ID)) return;
|
|
370
|
+
const style = document.createElement('style');
|
|
371
|
+
style.id = STYLE_ID;
|
|
372
|
+
style.textContent = `
|
|
373
|
+
#${BUTTON_ID} {
|
|
374
|
+
position: relative;
|
|
375
|
+
z-index: 2147483647;
|
|
376
|
+
display: inline-flex;
|
|
377
|
+
align-items: center;
|
|
378
|
+
justify-content: center;
|
|
379
|
+
min-width: 84px;
|
|
380
|
+
height: 28px;
|
|
381
|
+
flex: 0 0 auto;
|
|
382
|
+
margin-left: auto;
|
|
383
|
+
padding: 0 10px;
|
|
384
|
+
border: 1px solid #0052d9;
|
|
385
|
+
border-radius: 4px;
|
|
386
|
+
background: #0052d9;
|
|
387
|
+
color: #ffffff;
|
|
388
|
+
font: 500 12px/1 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
|
389
|
+
letter-spacing: 0;
|
|
390
|
+
cursor: pointer;
|
|
391
|
+
pointer-events: auto;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
#${BUTTON_ID}:hover:not(:disabled) {
|
|
395
|
+
background: #266fe8;
|
|
396
|
+
border-color: #266fe8;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
#${BUTTON_ID}:focus-visible {
|
|
400
|
+
outline: 2px solid #85adff;
|
|
401
|
+
outline-offset: 2px;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
#${BUTTON_ID}:disabled {
|
|
405
|
+
border-color: #dcdcdc;
|
|
406
|
+
background: #eeeeee;
|
|
407
|
+
color: #999999;
|
|
408
|
+
cursor: not-allowed;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
#${TOAST_ID} {
|
|
412
|
+
position: fixed;
|
|
413
|
+
right: 24px;
|
|
414
|
+
bottom: 72px;
|
|
415
|
+
z-index: 2147483647;
|
|
416
|
+
max-width: 420px;
|
|
417
|
+
padding: 10px 14px;
|
|
418
|
+
border-radius: 4px;
|
|
419
|
+
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
|
|
420
|
+
color: #ffffff;
|
|
421
|
+
font: 500 13px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
|
422
|
+
letter-spacing: 0;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
#${TOAST_ID}[data-kind="success"] {
|
|
426
|
+
background: #137333;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
#${TOAST_ID}[data-kind="error"] {
|
|
430
|
+
background: #c5221f;
|
|
431
|
+
}
|
|
432
|
+
`;
|
|
433
|
+
document.head.append(style);
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
function showToast(message, kind) {
|
|
437
|
+
document.getElementById(TOAST_ID)?.remove();
|
|
438
|
+
const toast = document.createElement('div');
|
|
439
|
+
toast.id = TOAST_ID;
|
|
440
|
+
toast.dataset.kind = kind;
|
|
441
|
+
toast.textContent = message;
|
|
442
|
+
document.body.append(toast);
|
|
443
|
+
window.setTimeout(() => toast.remove(), kind === 'error' ? 6000 : 3000);
|
|
444
|
+
}
|
|
445
|
+
})();
|