@siteping/widget 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +3713 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +19 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +3689 -0
- package/dist/index.js.map +1 -0
- package/package.json +43 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,3713 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
initSiteping: () => initSiteping
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
|
|
27
|
+
// ../../node_modules/.bun/@medv+finder@3.2.0/node_modules/@medv/finder/finder.js
|
|
28
|
+
var config;
|
|
29
|
+
var rootDocument;
|
|
30
|
+
var start;
|
|
31
|
+
function finder(input, options) {
|
|
32
|
+
start = /* @__PURE__ */ new Date();
|
|
33
|
+
if (input.nodeType !== Node.ELEMENT_NODE) {
|
|
34
|
+
throw new Error(`Can't generate CSS selector for non-element node type.`);
|
|
35
|
+
}
|
|
36
|
+
if ("html" === input.tagName.toLowerCase()) {
|
|
37
|
+
return "html";
|
|
38
|
+
}
|
|
39
|
+
const defaults = {
|
|
40
|
+
root: document.body,
|
|
41
|
+
idName: (name) => true,
|
|
42
|
+
className: (name) => true,
|
|
43
|
+
tagName: (name) => true,
|
|
44
|
+
attr: (name, value) => false,
|
|
45
|
+
seedMinLength: 1,
|
|
46
|
+
optimizedMinLength: 2,
|
|
47
|
+
threshold: 1e3,
|
|
48
|
+
maxNumberOfTries: 1e4,
|
|
49
|
+
timeoutMs: void 0
|
|
50
|
+
};
|
|
51
|
+
config = { ...defaults, ...options };
|
|
52
|
+
rootDocument = findRootDocument(config.root, defaults);
|
|
53
|
+
let path = bottomUpSearch(input, "all", () => bottomUpSearch(input, "two", () => bottomUpSearch(input, "one", () => bottomUpSearch(input, "none"))));
|
|
54
|
+
if (path) {
|
|
55
|
+
const optimized = sort(optimize(path, input));
|
|
56
|
+
if (optimized.length > 0) {
|
|
57
|
+
path = optimized[0];
|
|
58
|
+
}
|
|
59
|
+
return selector(path);
|
|
60
|
+
} else {
|
|
61
|
+
throw new Error(`Selector was not found.`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function findRootDocument(rootNode, defaults) {
|
|
65
|
+
if (rootNode.nodeType === Node.DOCUMENT_NODE) {
|
|
66
|
+
return rootNode;
|
|
67
|
+
}
|
|
68
|
+
if (rootNode === defaults.root) {
|
|
69
|
+
return rootNode.ownerDocument;
|
|
70
|
+
}
|
|
71
|
+
return rootNode;
|
|
72
|
+
}
|
|
73
|
+
function bottomUpSearch(input, limit, fallback) {
|
|
74
|
+
let path = null;
|
|
75
|
+
let stack = [];
|
|
76
|
+
let current = input;
|
|
77
|
+
let i = 0;
|
|
78
|
+
while (current) {
|
|
79
|
+
const elapsedTime = (/* @__PURE__ */ new Date()).getTime() - start.getTime();
|
|
80
|
+
if (config.timeoutMs !== void 0 && elapsedTime > config.timeoutMs) {
|
|
81
|
+
throw new Error(`Timeout: Can't find a unique selector after ${elapsedTime}ms`);
|
|
82
|
+
}
|
|
83
|
+
let level = maybe(id(current)) || maybe(...attr(current)) || maybe(...classNames(current)) || maybe(tagName(current)) || [any()];
|
|
84
|
+
const nth = index(current);
|
|
85
|
+
if (limit == "all") {
|
|
86
|
+
if (nth) {
|
|
87
|
+
level = level.concat(level.filter(dispensableNth).map((node) => nthChild(node, nth)));
|
|
88
|
+
}
|
|
89
|
+
} else if (limit == "two") {
|
|
90
|
+
level = level.slice(0, 1);
|
|
91
|
+
if (nth) {
|
|
92
|
+
level = level.concat(level.filter(dispensableNth).map((node) => nthChild(node, nth)));
|
|
93
|
+
}
|
|
94
|
+
} else if (limit == "one") {
|
|
95
|
+
const [node] = level = level.slice(0, 1);
|
|
96
|
+
if (nth && dispensableNth(node)) {
|
|
97
|
+
level = [nthChild(node, nth)];
|
|
98
|
+
}
|
|
99
|
+
} else if (limit == "none") {
|
|
100
|
+
level = [any()];
|
|
101
|
+
if (nth) {
|
|
102
|
+
level = [nthChild(level[0], nth)];
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
for (let node of level) {
|
|
106
|
+
node.level = i;
|
|
107
|
+
}
|
|
108
|
+
stack.push(level);
|
|
109
|
+
if (stack.length >= config.seedMinLength) {
|
|
110
|
+
path = findUniquePath(stack, fallback);
|
|
111
|
+
if (path) {
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
current = current.parentElement;
|
|
116
|
+
i++;
|
|
117
|
+
}
|
|
118
|
+
if (!path) {
|
|
119
|
+
path = findUniquePath(stack, fallback);
|
|
120
|
+
}
|
|
121
|
+
if (!path && fallback) {
|
|
122
|
+
return fallback();
|
|
123
|
+
}
|
|
124
|
+
return path;
|
|
125
|
+
}
|
|
126
|
+
function findUniquePath(stack, fallback) {
|
|
127
|
+
const paths = sort(combinations(stack));
|
|
128
|
+
if (paths.length > config.threshold) {
|
|
129
|
+
return fallback ? fallback() : null;
|
|
130
|
+
}
|
|
131
|
+
for (let candidate of paths) {
|
|
132
|
+
if (unique(candidate)) {
|
|
133
|
+
return candidate;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
function selector(path) {
|
|
139
|
+
let node = path[0];
|
|
140
|
+
let query = node.name;
|
|
141
|
+
for (let i = 1; i < path.length; i++) {
|
|
142
|
+
const level = path[i].level || 0;
|
|
143
|
+
if (node.level === level - 1) {
|
|
144
|
+
query = `${path[i].name} > ${query}`;
|
|
145
|
+
} else {
|
|
146
|
+
query = `${path[i].name} ${query}`;
|
|
147
|
+
}
|
|
148
|
+
node = path[i];
|
|
149
|
+
}
|
|
150
|
+
return query;
|
|
151
|
+
}
|
|
152
|
+
function penalty(path) {
|
|
153
|
+
return path.map((node) => node.penalty).reduce((acc, i) => acc + i, 0);
|
|
154
|
+
}
|
|
155
|
+
function unique(path) {
|
|
156
|
+
const css = selector(path);
|
|
157
|
+
switch (rootDocument.querySelectorAll(css).length) {
|
|
158
|
+
case 0:
|
|
159
|
+
throw new Error(`Can't select any node with this selector: ${css}`);
|
|
160
|
+
case 1:
|
|
161
|
+
return true;
|
|
162
|
+
default:
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
function id(input) {
|
|
167
|
+
const elementId = input.getAttribute("id");
|
|
168
|
+
if (elementId && config.idName(elementId)) {
|
|
169
|
+
return {
|
|
170
|
+
name: "#" + CSS.escape(elementId),
|
|
171
|
+
penalty: 0
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
function attr(input) {
|
|
177
|
+
const attrs = Array.from(input.attributes).filter((attr2) => config.attr(attr2.name, attr2.value));
|
|
178
|
+
return attrs.map((attr2) => ({
|
|
179
|
+
name: `[${CSS.escape(attr2.name)}="${CSS.escape(attr2.value)}"]`,
|
|
180
|
+
penalty: 0.5
|
|
181
|
+
}));
|
|
182
|
+
}
|
|
183
|
+
function classNames(input) {
|
|
184
|
+
const names = Array.from(input.classList).filter(config.className);
|
|
185
|
+
return names.map((name) => ({
|
|
186
|
+
name: "." + CSS.escape(name),
|
|
187
|
+
penalty: 1
|
|
188
|
+
}));
|
|
189
|
+
}
|
|
190
|
+
function tagName(input) {
|
|
191
|
+
const name = input.tagName.toLowerCase();
|
|
192
|
+
if (config.tagName(name)) {
|
|
193
|
+
return {
|
|
194
|
+
name,
|
|
195
|
+
penalty: 2
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
function any() {
|
|
201
|
+
return {
|
|
202
|
+
name: "*",
|
|
203
|
+
penalty: 3
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
function index(input) {
|
|
207
|
+
const parent = input.parentNode;
|
|
208
|
+
if (!parent) {
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
let child = parent.firstChild;
|
|
212
|
+
if (!child) {
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
let i = 0;
|
|
216
|
+
while (child) {
|
|
217
|
+
if (child.nodeType === Node.ELEMENT_NODE) {
|
|
218
|
+
i++;
|
|
219
|
+
}
|
|
220
|
+
if (child === input) {
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
child = child.nextSibling;
|
|
224
|
+
}
|
|
225
|
+
return i;
|
|
226
|
+
}
|
|
227
|
+
function nthChild(node, i) {
|
|
228
|
+
return {
|
|
229
|
+
name: node.name + `:nth-child(${i})`,
|
|
230
|
+
penalty: node.penalty + 1
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
function dispensableNth(node) {
|
|
234
|
+
return node.name !== "html" && !node.name.startsWith("#");
|
|
235
|
+
}
|
|
236
|
+
function maybe(...level) {
|
|
237
|
+
const list = level.filter(notEmpty);
|
|
238
|
+
if (list.length > 0) {
|
|
239
|
+
return list;
|
|
240
|
+
}
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
243
|
+
function notEmpty(value) {
|
|
244
|
+
return value !== null && value !== void 0;
|
|
245
|
+
}
|
|
246
|
+
function* combinations(stack, path = []) {
|
|
247
|
+
if (stack.length > 0) {
|
|
248
|
+
for (let node of stack[0]) {
|
|
249
|
+
yield* combinations(stack.slice(1, stack.length), path.concat(node));
|
|
250
|
+
}
|
|
251
|
+
} else {
|
|
252
|
+
yield path;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
function sort(paths) {
|
|
256
|
+
return [...paths].sort((a, b) => penalty(a) - penalty(b));
|
|
257
|
+
}
|
|
258
|
+
function* optimize(path, input, scope = {
|
|
259
|
+
counter: 0,
|
|
260
|
+
visited: /* @__PURE__ */ new Map()
|
|
261
|
+
}) {
|
|
262
|
+
if (path.length > 2 && path.length > config.optimizedMinLength) {
|
|
263
|
+
for (let i = 1; i < path.length - 1; i++) {
|
|
264
|
+
if (scope.counter > config.maxNumberOfTries) {
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
scope.counter += 1;
|
|
268
|
+
const newPath = [...path];
|
|
269
|
+
newPath.splice(i, 1);
|
|
270
|
+
const newPathKey = selector(newPath);
|
|
271
|
+
if (scope.visited.has(newPathKey)) {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
if (unique(newPath) && same(newPath, input)) {
|
|
275
|
+
yield newPath;
|
|
276
|
+
scope.visited.set(newPathKey, true);
|
|
277
|
+
yield* optimize(newPath, input, scope);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
function same(path, input) {
|
|
283
|
+
return rootDocument.querySelector(selector(path)) === input;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// src/dom/fingerprint.ts
|
|
287
|
+
var STABLE_ATTRS = ["role", "aria-label", "type", "name", "href", "src", "data-testid", "data-id"];
|
|
288
|
+
function djb2(str) {
|
|
289
|
+
let hash = 5381;
|
|
290
|
+
for (let i = 0; i < str.length; i++) {
|
|
291
|
+
hash = (hash << 5) + hash + str.charCodeAt(i) | 0;
|
|
292
|
+
}
|
|
293
|
+
return (hash >>> 0).toString(36);
|
|
294
|
+
}
|
|
295
|
+
function generateFingerprint(element) {
|
|
296
|
+
const childCount = element.children.length;
|
|
297
|
+
let siblingIdx = 0;
|
|
298
|
+
const parent = element.parentElement;
|
|
299
|
+
if (parent) {
|
|
300
|
+
for (const child of parent.children) {
|
|
301
|
+
if (child === element) break;
|
|
302
|
+
if (child.tagName === element.tagName) siblingIdx++;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
const attrs = [];
|
|
306
|
+
for (const attr2 of STABLE_ATTRS) {
|
|
307
|
+
const val = element.getAttribute(attr2);
|
|
308
|
+
if (val) attrs.push(`${attr2}=${val}`);
|
|
309
|
+
}
|
|
310
|
+
const attrHash = attrs.length > 0 ? djb2(attrs.join(",")) : "0";
|
|
311
|
+
return `${childCount}:${siblingIdx}:${attrHash}`;
|
|
312
|
+
}
|
|
313
|
+
function scoreFingerprint(candidate, storedFingerprint) {
|
|
314
|
+
const parts = storedFingerprint.split(":");
|
|
315
|
+
if (parts.length !== 3) return 0;
|
|
316
|
+
const [storedChildren, storedSibIdx, storedAttrHash] = parts;
|
|
317
|
+
const storedChildCount = Number(storedChildren);
|
|
318
|
+
const storedSibIndex = Number(storedSibIdx);
|
|
319
|
+
if (Number.isNaN(storedChildCount) || Number.isNaN(storedSibIndex)) return 0;
|
|
320
|
+
const candidateFp = generateFingerprint(candidate);
|
|
321
|
+
const [candChildren, candSibIdx, candAttrHash] = candidateFp.split(":");
|
|
322
|
+
let score = 0;
|
|
323
|
+
const childDiff = Math.abs(Number(candChildren) - storedChildCount);
|
|
324
|
+
if (childDiff === 0) score += 0.2;
|
|
325
|
+
else if (childDiff <= 2) score += 0.1;
|
|
326
|
+
else if (childDiff <= 5) score += 0.03;
|
|
327
|
+
const sibDiff = Math.abs(Number(candSibIdx) - storedSibIndex);
|
|
328
|
+
if (sibDiff === 0) score += 0.4;
|
|
329
|
+
else if (sibDiff === 1) score += 0.2;
|
|
330
|
+
else if (sibDiff <= 3) score += 0.08;
|
|
331
|
+
if (candAttrHash === storedAttrHash) score += 0.4;
|
|
332
|
+
return score;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// src/dom/text-context.ts
|
|
336
|
+
function adjacentText(element, direction) {
|
|
337
|
+
const prop = direction === "before" ? "previousElementSibling" : "nextElementSibling";
|
|
338
|
+
let sibling = element[prop];
|
|
339
|
+
let attempts = 3;
|
|
340
|
+
while (sibling && attempts > 0) {
|
|
341
|
+
const text = sibling.textContent?.trim();
|
|
342
|
+
if (text) {
|
|
343
|
+
return direction === "before" ? text.slice(-32) : text.slice(0, 32);
|
|
344
|
+
}
|
|
345
|
+
sibling = sibling[prop];
|
|
346
|
+
attempts--;
|
|
347
|
+
}
|
|
348
|
+
return "";
|
|
349
|
+
}
|
|
350
|
+
function neighborText(element) {
|
|
351
|
+
const prev = element.previousElementSibling?.textContent?.trim().slice(0, 40) ?? "";
|
|
352
|
+
const next = element.nextElementSibling?.textContent?.trim().slice(0, 40) ?? "";
|
|
353
|
+
return [prev, next].filter(Boolean).join(" | ");
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// src/dom/xpath.ts
|
|
357
|
+
function generateXPath(element) {
|
|
358
|
+
if (element.id) {
|
|
359
|
+
const safeId = element.id.includes("'") ? `concat('${element.id.replace(/'/g, `',"'",'`)}')` : `'${element.id}'`;
|
|
360
|
+
return `//${element.localName}[@id=${safeId}]`;
|
|
361
|
+
}
|
|
362
|
+
const segments = [];
|
|
363
|
+
let current = element;
|
|
364
|
+
while (current && current !== document.body && segments.length < 6) {
|
|
365
|
+
const tag = current.localName;
|
|
366
|
+
const parent = current.parentElement;
|
|
367
|
+
if (current.id) {
|
|
368
|
+
const safeId = current.id.includes("'") ? `concat('${current.id.replace(/'/g, `',"'",'`)}')` : `'${current.id}'`;
|
|
369
|
+
segments.unshift(`/${tag}[@id=${safeId}]`);
|
|
370
|
+
return "/" + segments.join("");
|
|
371
|
+
}
|
|
372
|
+
let position = 1;
|
|
373
|
+
if (parent) {
|
|
374
|
+
for (const sibling of parent.children) {
|
|
375
|
+
if (sibling === current) break;
|
|
376
|
+
if (sibling.localName === tag) position++;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
segments.unshift(`/${tag}[${position}]`);
|
|
380
|
+
current = parent;
|
|
381
|
+
}
|
|
382
|
+
return "/html/body" + segments.join("");
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// src/dom/anchor.ts
|
|
386
|
+
function generateAnchor(element) {
|
|
387
|
+
const cssSelector = finder(element, {
|
|
388
|
+
// Filter out CSS-in-JS hashed class names
|
|
389
|
+
className: (name) => !/^(css|sc|emotion|styled)-/.test(name) && !/^[a-z]{1,3}[A-Za-z0-9]{4,8}$/.test(name),
|
|
390
|
+
// Prefer stable attributes
|
|
391
|
+
attr: (name) => ["data-testid", "data-id", "role", "aria-label"].includes(name),
|
|
392
|
+
// Exclude framework-generated dynamic IDs
|
|
393
|
+
idName: (name) => !name.startsWith("radix-") && !/^:r[0-9]+:$/.test(name),
|
|
394
|
+
seedMinLength: 3,
|
|
395
|
+
optimizedMinLength: 2
|
|
396
|
+
});
|
|
397
|
+
const xpath = generateXPath(element);
|
|
398
|
+
const rawText = element.textContent?.trim() ?? "";
|
|
399
|
+
const textSnippet = rawText.slice(0, 120);
|
|
400
|
+
const textPrefix = adjacentText(element, "before");
|
|
401
|
+
const textSuffix = adjacentText(element, "after");
|
|
402
|
+
const fingerprint = generateFingerprint(element);
|
|
403
|
+
const neighbor = neighborText(element);
|
|
404
|
+
return {
|
|
405
|
+
cssSelector,
|
|
406
|
+
xpath,
|
|
407
|
+
textSnippet,
|
|
408
|
+
textPrefix,
|
|
409
|
+
textSuffix,
|
|
410
|
+
fingerprint,
|
|
411
|
+
neighborText: neighbor,
|
|
412
|
+
elementTag: element.tagName,
|
|
413
|
+
elementId: element.id || void 0
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
function findAnchorElement(rect, root = document.documentElement) {
|
|
417
|
+
const centerX = rect.x + rect.width / 2;
|
|
418
|
+
const centerY = rect.y + rect.height / 2;
|
|
419
|
+
const elementAtCenter = document.elementFromPoint(centerX, centerY);
|
|
420
|
+
if (!elementAtCenter || elementAtCenter === root) return document.body;
|
|
421
|
+
let candidate = elementAtCenter;
|
|
422
|
+
let current = elementAtCenter;
|
|
423
|
+
while (current && current !== document.body) {
|
|
424
|
+
const bounds = current.getBoundingClientRect();
|
|
425
|
+
if (bounds.left <= rect.x && bounds.top <= rect.y && bounds.right >= rect.x + rect.width && bounds.bottom >= rect.y + rect.height) {
|
|
426
|
+
candidate = current;
|
|
427
|
+
break;
|
|
428
|
+
}
|
|
429
|
+
current = current.parentElement;
|
|
430
|
+
}
|
|
431
|
+
return candidate;
|
|
432
|
+
}
|
|
433
|
+
function rectToPercentages(rect, anchorBounds) {
|
|
434
|
+
if (anchorBounds.width <= 0 || anchorBounds.height <= 0) {
|
|
435
|
+
return { xPct: 0, yPct: 0, wPct: 1, hPct: 1 };
|
|
436
|
+
}
|
|
437
|
+
return {
|
|
438
|
+
xPct: (rect.x - anchorBounds.x) / anchorBounds.width,
|
|
439
|
+
yPct: (rect.y - anchorBounds.y) / anchorBounds.height,
|
|
440
|
+
wPct: rect.width / anchorBounds.width,
|
|
441
|
+
hPct: rect.height / anchorBounds.height
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
// src/dom-utils.ts
|
|
446
|
+
function parseSvg(svgString) {
|
|
447
|
+
const range = document.createRange();
|
|
448
|
+
const fragment = range.createContextualFragment(svgString);
|
|
449
|
+
const svg = fragment.firstElementChild;
|
|
450
|
+
if (!svg || svg.nodeName.toLowerCase() !== "svg") {
|
|
451
|
+
throw new Error("[siteping] Invalid SVG string");
|
|
452
|
+
}
|
|
453
|
+
return svg;
|
|
454
|
+
}
|
|
455
|
+
function el(tag, attrs) {
|
|
456
|
+
const element = document.createElement(tag);
|
|
457
|
+
if (attrs) {
|
|
458
|
+
for (const [key, value] of Object.entries(attrs)) {
|
|
459
|
+
if (key === "class") {
|
|
460
|
+
element.className = value;
|
|
461
|
+
} else if (key === "style") {
|
|
462
|
+
element.style.cssText = value;
|
|
463
|
+
} else {
|
|
464
|
+
element.setAttribute(key, value);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
return element;
|
|
469
|
+
}
|
|
470
|
+
function setText(element, text) {
|
|
471
|
+
element.textContent = text;
|
|
472
|
+
}
|
|
473
|
+
function formatRelativeDate(isoString) {
|
|
474
|
+
const diff = Date.now() - new Date(isoString).getTime();
|
|
475
|
+
const minutes = Math.floor(diff / 6e4);
|
|
476
|
+
if (minutes < 1) return "maintenant";
|
|
477
|
+
if (minutes < 60) return `il y a ${minutes}min`;
|
|
478
|
+
const hours = Math.floor(minutes / 60);
|
|
479
|
+
if (hours < 24) return `il y a ${hours}h`;
|
|
480
|
+
const days = Math.floor(hours / 24);
|
|
481
|
+
if (days < 7) return `il y a ${days}j`;
|
|
482
|
+
return new Date(isoString).toLocaleDateString("fr-FR");
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
// src/icons.ts
|
|
486
|
+
var ICON_SITEPING = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/><circle cx="12" cy="10" r="1" fill="currentColor" stroke="none"/><circle cx="8" cy="10" r="1" fill="currentColor" stroke="none"/><circle cx="16" cy="10" r="1" fill="currentColor" stroke="none"/></svg>`;
|
|
487
|
+
var ICON_CHAT = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>`;
|
|
488
|
+
var ICON_ANNOTATE = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2"/><path d="M3 9h18"/><path d="M9 3v18"/></svg>`;
|
|
489
|
+
var ICON_EYE = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></svg>`;
|
|
490
|
+
var ICON_EYE_OFF = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94"/><path d="M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19"/><line x1="1" y1="1" x2="23" y2="23"/></svg>`;
|
|
491
|
+
var ICON_CLOSE = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>`;
|
|
492
|
+
var ICON_SEARCH = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>`;
|
|
493
|
+
var ICON_CHECK = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>`;
|
|
494
|
+
var ICON_QUESTION = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg>`;
|
|
495
|
+
var ICON_CHANGE = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/></svg>`;
|
|
496
|
+
var ICON_BUG = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="8" y="6" width="8" height="14" rx="4"/><path d="M19 9h2"/><path d="M3 9h2"/><path d="M19 13h2"/><path d="M3 13h2"/><path d="M19 17h2"/><path d="M3 17h2"/><path d="M10 2h4"/></svg>`;
|
|
497
|
+
var ICON_OTHER = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="1"/><circle cx="19" cy="12" r="1"/><circle cx="5" cy="12" r="1"/></svg>`;
|
|
498
|
+
var ICON_UNDO = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="1 4 1 10 7 10"/><path d="M3.51 15a9 9 0 1 0 2.13-9.36L1 10"/></svg>`;
|
|
499
|
+
var ICON_TRASH = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/><line x1="10" y1="11" x2="10" y2="17"/><line x1="14" y1="11" x2="14" y2="17"/></svg>`;
|
|
500
|
+
|
|
501
|
+
// src/styles/theme.ts
|
|
502
|
+
var DEFAULT_ACCENT = "#0066ff";
|
|
503
|
+
var HEX6_RE = /^#[0-9a-fA-F]{6}$/;
|
|
504
|
+
var HEX3_RE = /^#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])$/;
|
|
505
|
+
var HEX8_RE = /^#[0-9a-fA-F]{8}$/;
|
|
506
|
+
function normalizeHex(color) {
|
|
507
|
+
if (HEX6_RE.test(color)) return color;
|
|
508
|
+
const short = HEX3_RE.test(color) ? color.match(HEX3_RE) : null;
|
|
509
|
+
if (short) return `#${short[1]}${short[1]}${short[2]}${short[2]}${short[3]}${short[3]}`;
|
|
510
|
+
if (HEX8_RE.test(color)) return color.slice(0, 7);
|
|
511
|
+
return DEFAULT_ACCENT;
|
|
512
|
+
}
|
|
513
|
+
function darkenHex(hex, amount) {
|
|
514
|
+
const r = Math.max(0, Math.round(parseInt(hex.slice(1, 3), 16) * (1 - amount)));
|
|
515
|
+
const g = Math.max(0, Math.round(parseInt(hex.slice(3, 5), 16) * (1 - amount)));
|
|
516
|
+
const b = Math.max(0, Math.round(parseInt(hex.slice(5, 7), 16) * (1 - amount)));
|
|
517
|
+
return `#${r.toString(16).padStart(2, "0")}${g.toString(16).padStart(2, "0")}${b.toString(16).padStart(2, "0")}`;
|
|
518
|
+
}
|
|
519
|
+
function buildThemeColors(accent = DEFAULT_ACCENT) {
|
|
520
|
+
const hex = normalizeHex(accent);
|
|
521
|
+
const dark = darkenHex(hex, 0.15);
|
|
522
|
+
return {
|
|
523
|
+
accent: hex,
|
|
524
|
+
accentLight: hex + "14",
|
|
525
|
+
// 8% opacity
|
|
526
|
+
accentDark: dark,
|
|
527
|
+
accentGlow: hex + "33",
|
|
528
|
+
// 20% opacity
|
|
529
|
+
accentGradient: `linear-gradient(135deg, ${hex}, ${dark})`,
|
|
530
|
+
bg: "#ffffff",
|
|
531
|
+
bgHover: "#f8f9fb",
|
|
532
|
+
text: "#0f172a",
|
|
533
|
+
textSecondary: "#475569",
|
|
534
|
+
textTertiary: "#64748b",
|
|
535
|
+
border: "#e2e8f0",
|
|
536
|
+
shadow: "rgba(0, 0, 0, 0.06)",
|
|
537
|
+
// Glass tokens
|
|
538
|
+
glassBg: "rgba(255, 255, 255, 0.72)",
|
|
539
|
+
glassBgHeavy: "rgba(255, 255, 255, 0.85)",
|
|
540
|
+
glassBorder: "rgba(255, 255, 255, 0.35)",
|
|
541
|
+
glassBorderSubtle: "rgba(255, 255, 255, 0.18)",
|
|
542
|
+
// Vibrant type colors
|
|
543
|
+
typeQuestion: "#3b82f6",
|
|
544
|
+
typeChangement: "#f59e0b",
|
|
545
|
+
typeBug: "#ef4444",
|
|
546
|
+
typeAutre: "#64748b",
|
|
547
|
+
// Pastel backgrounds
|
|
548
|
+
typeQuestionBg: "#eff6ff",
|
|
549
|
+
typeChangementBg: "#fffbeb",
|
|
550
|
+
typeBugBg: "#fef2f2",
|
|
551
|
+
typeAutreBg: "#f8fafc"
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
function getTypeColor(type, colors) {
|
|
555
|
+
switch (type) {
|
|
556
|
+
case "question":
|
|
557
|
+
return colors.typeQuestion;
|
|
558
|
+
case "changement":
|
|
559
|
+
return colors.typeChangement;
|
|
560
|
+
case "bug":
|
|
561
|
+
return colors.typeBug;
|
|
562
|
+
default:
|
|
563
|
+
return colors.typeAutre;
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
function getTypeBgColor(type, colors) {
|
|
567
|
+
switch (type) {
|
|
568
|
+
case "question":
|
|
569
|
+
return colors.typeQuestionBg;
|
|
570
|
+
case "changement":
|
|
571
|
+
return colors.typeChangementBg;
|
|
572
|
+
case "bug":
|
|
573
|
+
return colors.typeBugBg;
|
|
574
|
+
default:
|
|
575
|
+
return colors.typeAutreBg;
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
function cssVariables(colors) {
|
|
579
|
+
return `
|
|
580
|
+
--sp-accent: ${colors.accent};
|
|
581
|
+
--sp-accent-light: ${colors.accentLight};
|
|
582
|
+
--sp-accent-dark: ${colors.accentDark};
|
|
583
|
+
--sp-accent-glow: ${colors.accentGlow};
|
|
584
|
+
--sp-accent-gradient: ${colors.accentGradient};
|
|
585
|
+
--sp-bg: ${colors.bg};
|
|
586
|
+
--sp-bg-hover: ${colors.bgHover};
|
|
587
|
+
--sp-text: ${colors.text};
|
|
588
|
+
--sp-text-secondary: ${colors.textSecondary};
|
|
589
|
+
--sp-text-tertiary: ${colors.textTertiary};
|
|
590
|
+
--sp-border: ${colors.border};
|
|
591
|
+
--sp-shadow: ${colors.shadow};
|
|
592
|
+
--sp-glass-bg: ${colors.glassBg};
|
|
593
|
+
--sp-glass-bg-heavy: ${colors.glassBgHeavy};
|
|
594
|
+
--sp-glass-border: ${colors.glassBorder};
|
|
595
|
+
--sp-glass-border-subtle: ${colors.glassBorderSubtle};
|
|
596
|
+
--sp-type-question: ${colors.typeQuestion};
|
|
597
|
+
--sp-type-changement: ${colors.typeChangement};
|
|
598
|
+
--sp-type-bug: ${colors.typeBug};
|
|
599
|
+
--sp-type-autre: ${colors.typeAutre};
|
|
600
|
+
--sp-type-question-bg: ${colors.typeQuestionBg};
|
|
601
|
+
--sp-type-changement-bg: ${colors.typeChangementBg};
|
|
602
|
+
--sp-type-bug-bg: ${colors.typeBugBg};
|
|
603
|
+
--sp-type-autre-bg: ${colors.typeAutreBg};
|
|
604
|
+
--sp-radius: 12px;
|
|
605
|
+
--sp-radius-lg: 16px;
|
|
606
|
+
--sp-radius-xl: 20px;
|
|
607
|
+
--sp-radius-full: 9999px;
|
|
608
|
+
--sp-blur: 20px;
|
|
609
|
+
--sp-blur-heavy: 32px;
|
|
610
|
+
--sp-shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
|
|
611
|
+
--sp-shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.05), 0 1px 2px rgba(0, 0, 0, 0.04);
|
|
612
|
+
--sp-shadow-md: 0 4px 16px rgba(0, 0, 0, 0.08), 0 2px 4px rgba(0, 0, 0, 0.04);
|
|
613
|
+
--sp-shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.1), 0 4px 8px rgba(0, 0, 0, 0.04);
|
|
614
|
+
--sp-shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.12), 0 8px 16px rgba(0, 0, 0, 0.06);
|
|
615
|
+
--sp-font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
|
|
616
|
+
`;
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
// src/popup.ts
|
|
620
|
+
var TYPE_OPTIONS = [
|
|
621
|
+
{ type: "question", label: "Question", icon: ICON_QUESTION },
|
|
622
|
+
{ type: "changement", label: "Changement", icon: ICON_CHANGE },
|
|
623
|
+
{ type: "bug", label: "Bug", icon: ICON_BUG },
|
|
624
|
+
{ type: "autre", label: "Autre", icon: ICON_OTHER }
|
|
625
|
+
];
|
|
626
|
+
var Popup = class {
|
|
627
|
+
constructor(colors) {
|
|
628
|
+
this.colors = colors;
|
|
629
|
+
this.root = el("div", {
|
|
630
|
+
style: `
|
|
631
|
+
position:fixed;
|
|
632
|
+
z-index:2147483647;
|
|
633
|
+
width:300px;
|
|
634
|
+
padding:16px;
|
|
635
|
+
border-radius:16px;
|
|
636
|
+
background:rgba(255, 255, 255, 0.82);
|
|
637
|
+
backdrop-filter:blur(24px);
|
|
638
|
+
-webkit-backdrop-filter:blur(24px);
|
|
639
|
+
border:1px solid rgba(255, 255, 255, 0.35);
|
|
640
|
+
box-shadow:0 8px 32px rgba(0,0,0,0.1), 0 2px 8px rgba(0,0,0,0.04);
|
|
641
|
+
font-family:"Inter",system-ui,-apple-system,sans-serif;
|
|
642
|
+
opacity:0;
|
|
643
|
+
transform:translateY(8px) scale(0.98);
|
|
644
|
+
transition:opacity 0.25s cubic-bezier(0.16, 1, 0.3, 1),transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
|
|
645
|
+
display:none;
|
|
646
|
+
-webkit-font-smoothing:antialiased;
|
|
647
|
+
`
|
|
648
|
+
});
|
|
649
|
+
const typeRow = el("div", { style: "display:grid;grid-template-columns:1fr 1fr;gap:6px;margin-bottom:12px;" });
|
|
650
|
+
for (const option of TYPE_OPTIONS) {
|
|
651
|
+
const btn = document.createElement("button");
|
|
652
|
+
btn.style.cssText = `
|
|
653
|
+
height:34px;
|
|
654
|
+
border-radius:9999px;border:1px solid #e2e8f0;
|
|
655
|
+
background:rgba(255,255,255,0.8);cursor:pointer;
|
|
656
|
+
display:flex;align-items:center;justify-content:center;gap:5px;
|
|
657
|
+
font-family:"Inter",system-ui,-apple-system,sans-serif;
|
|
658
|
+
font-size:12px;font-weight:500;color:#64748b;
|
|
659
|
+
transition:all 0.2s ease;
|
|
660
|
+
padding:0 10px;
|
|
661
|
+
`;
|
|
662
|
+
const icon = parseSvg(option.icon);
|
|
663
|
+
icon.setAttribute("style", "width:13px;height:13px;flex-shrink:0;");
|
|
664
|
+
btn.appendChild(icon);
|
|
665
|
+
const labelSpan = document.createElement("span");
|
|
666
|
+
setText(labelSpan, option.label);
|
|
667
|
+
btn.appendChild(labelSpan);
|
|
668
|
+
btn.dataset.type = option.type;
|
|
669
|
+
btn.addEventListener("click", () => {
|
|
670
|
+
this.selectType(option.type, typeRow);
|
|
671
|
+
});
|
|
672
|
+
btn.addEventListener("mouseenter", () => {
|
|
673
|
+
if (btn.dataset.type !== this.selectedType) {
|
|
674
|
+
const bgColor = getTypeBgColor(btn.dataset.type ?? "", this.colors);
|
|
675
|
+
btn.style.background = bgColor;
|
|
676
|
+
btn.style.borderColor = getTypeColor(btn.dataset.type ?? "", this.colors) + "40";
|
|
677
|
+
}
|
|
678
|
+
});
|
|
679
|
+
btn.addEventListener("mouseleave", () => {
|
|
680
|
+
if (btn.dataset.type !== this.selectedType) {
|
|
681
|
+
btn.style.background = "rgba(255,255,255,0.8)";
|
|
682
|
+
btn.style.borderColor = "#e2e8f0";
|
|
683
|
+
}
|
|
684
|
+
});
|
|
685
|
+
typeRow.appendChild(btn);
|
|
686
|
+
}
|
|
687
|
+
this.textarea = document.createElement("textarea");
|
|
688
|
+
this.textarea.style.cssText = `
|
|
689
|
+
width:100%;min-height:72px;max-height:152px;
|
|
690
|
+
padding:10px 12px;border-radius:12px;
|
|
691
|
+
border:1px solid #e2e8f0;
|
|
692
|
+
background:rgba(255,255,255,0.85);
|
|
693
|
+
color:#0f172a;font-family:"Inter",system-ui,-apple-system,sans-serif;
|
|
694
|
+
font-size:13px;line-height:1.5;resize:vertical;
|
|
695
|
+
outline:none;transition:all 0.2s ease;
|
|
696
|
+
box-sizing:border-box;
|
|
697
|
+
`;
|
|
698
|
+
this.textarea.placeholder = "D\xE9crivez votre retour...";
|
|
699
|
+
this.textarea.setAttribute("aria-label", "Message de feedback");
|
|
700
|
+
const hint = el("div", {
|
|
701
|
+
style: `
|
|
702
|
+
font-size:11px;color:#94a3b8;
|
|
703
|
+
text-align:right;margin-top:4px;
|
|
704
|
+
font-family:"Inter",system-ui,-apple-system,sans-serif;
|
|
705
|
+
letter-spacing:0.01em;
|
|
706
|
+
`
|
|
707
|
+
});
|
|
708
|
+
const isMac = navigator.platform.includes("Mac");
|
|
709
|
+
setText(hint, isMac ? "\u2318+Entr\xE9e pour envoyer" : "Ctrl+Entr\xE9e pour envoyer");
|
|
710
|
+
this.textarea.addEventListener("focus", () => {
|
|
711
|
+
this.textarea.style.borderColor = this.colors.accent;
|
|
712
|
+
this.textarea.style.boxShadow = `0 0 0 3px ${this.colors.accent}14`;
|
|
713
|
+
this.textarea.style.background = "#fff";
|
|
714
|
+
});
|
|
715
|
+
this.textarea.addEventListener("blur", () => {
|
|
716
|
+
this.textarea.style.borderColor = "#e2e8f0";
|
|
717
|
+
this.textarea.style.boxShadow = "none";
|
|
718
|
+
this.textarea.style.background = "rgba(255,255,255,0.85)";
|
|
719
|
+
});
|
|
720
|
+
this.textarea.addEventListener("input", () => {
|
|
721
|
+
this.updateSubmitState();
|
|
722
|
+
});
|
|
723
|
+
this.textarea.addEventListener("keydown", (e) => {
|
|
724
|
+
if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
|
|
725
|
+
e.preventDefault();
|
|
726
|
+
this.submit();
|
|
727
|
+
}
|
|
728
|
+
if (e.key === "Escape") {
|
|
729
|
+
this.cancel();
|
|
730
|
+
}
|
|
731
|
+
});
|
|
732
|
+
const btnRow = el("div", { style: "display:flex;justify-content:flex-end;gap:8px;margin-top:12px;" });
|
|
733
|
+
const cancelBtn = document.createElement("button");
|
|
734
|
+
cancelBtn.style.cssText = `
|
|
735
|
+
height:34px;padding:0 16px;border-radius:9999px;
|
|
736
|
+
border:1px solid #e2e8f0;
|
|
737
|
+
background:rgba(255,255,255,0.8);
|
|
738
|
+
color:#64748b;font-family:"Inter",system-ui,-apple-system,sans-serif;
|
|
739
|
+
font-size:13px;font-weight:500;cursor:pointer;
|
|
740
|
+
transition:all 0.2s ease;
|
|
741
|
+
`;
|
|
742
|
+
setText(cancelBtn, "Annuler");
|
|
743
|
+
cancelBtn.addEventListener("click", () => this.cancel());
|
|
744
|
+
cancelBtn.addEventListener("mouseenter", () => {
|
|
745
|
+
cancelBtn.style.borderColor = this.colors.accent;
|
|
746
|
+
cancelBtn.style.color = this.colors.accent;
|
|
747
|
+
});
|
|
748
|
+
cancelBtn.addEventListener("mouseleave", () => {
|
|
749
|
+
cancelBtn.style.borderColor = "#e2e8f0";
|
|
750
|
+
cancelBtn.style.color = "#64748b";
|
|
751
|
+
});
|
|
752
|
+
this.submitBtn = document.createElement("button");
|
|
753
|
+
this.submitBtn.style.cssText = `
|
|
754
|
+
height:34px;padding:0 18px;border-radius:9999px;
|
|
755
|
+
border:none;background:${this.colors.accentGradient};
|
|
756
|
+
color:#fff;font-family:"Inter",system-ui,-apple-system,sans-serif;
|
|
757
|
+
font-size:13px;font-weight:600;cursor:pointer;
|
|
758
|
+
opacity:0.35;pointer-events:none;
|
|
759
|
+
transition:all 0.2s ease;
|
|
760
|
+
box-shadow:0 2px 8px ${this.colors.accentGlow};
|
|
761
|
+
`;
|
|
762
|
+
setText(this.submitBtn, "Envoyer");
|
|
763
|
+
this.submitBtn.addEventListener("click", () => this.submit());
|
|
764
|
+
btnRow.appendChild(cancelBtn);
|
|
765
|
+
btnRow.appendChild(this.submitBtn);
|
|
766
|
+
this.root.appendChild(typeRow);
|
|
767
|
+
this.root.appendChild(this.textarea);
|
|
768
|
+
this.root.appendChild(hint);
|
|
769
|
+
this.root.appendChild(btnRow);
|
|
770
|
+
document.body.appendChild(this.root);
|
|
771
|
+
}
|
|
772
|
+
colors;
|
|
773
|
+
root;
|
|
774
|
+
selectedType = null;
|
|
775
|
+
textarea;
|
|
776
|
+
submitBtn;
|
|
777
|
+
resolve = null;
|
|
778
|
+
/**
|
|
779
|
+
* Show the popup near a drawn rectangle and return the user's input.
|
|
780
|
+
* Returns null if cancelled.
|
|
781
|
+
*/
|
|
782
|
+
show(rectBounds) {
|
|
783
|
+
return new Promise((resolve) => {
|
|
784
|
+
this.resolve = resolve;
|
|
785
|
+
this.selectedType = null;
|
|
786
|
+
this.textarea.value = "";
|
|
787
|
+
this.updateSubmitState();
|
|
788
|
+
this.resetTypeButtons();
|
|
789
|
+
let top = rectBounds.bottom + 8;
|
|
790
|
+
let left = rectBounds.left;
|
|
791
|
+
if (top + 220 > window.innerHeight) {
|
|
792
|
+
top = rectBounds.top - 220 - 8;
|
|
793
|
+
}
|
|
794
|
+
if (left + 300 > window.innerWidth) {
|
|
795
|
+
left = rectBounds.right - 300;
|
|
796
|
+
}
|
|
797
|
+
left = Math.max(8, left);
|
|
798
|
+
top = Math.max(8, top);
|
|
799
|
+
this.root.style.top = `${top}px`;
|
|
800
|
+
this.root.style.left = `${left}px`;
|
|
801
|
+
this.root.style.display = "block";
|
|
802
|
+
requestAnimationFrame(() => {
|
|
803
|
+
this.root.style.opacity = "1";
|
|
804
|
+
this.root.style.transform = "translateY(0) scale(1)";
|
|
805
|
+
this.textarea.focus();
|
|
806
|
+
});
|
|
807
|
+
});
|
|
808
|
+
}
|
|
809
|
+
selectType(type, container) {
|
|
810
|
+
this.selectedType = type;
|
|
811
|
+
const buttons = container.querySelectorAll("button");
|
|
812
|
+
for (const btn of buttons) {
|
|
813
|
+
const isActive = btn.dataset.type === type;
|
|
814
|
+
const color = getTypeColor(btn.dataset.type ?? "", this.colors);
|
|
815
|
+
const bgColor = getTypeBgColor(btn.dataset.type ?? "", this.colors);
|
|
816
|
+
btn.style.background = isActive ? bgColor : "rgba(255,255,255,0.8)";
|
|
817
|
+
btn.style.borderColor = isActive ? color + "60" : "#e2e8f0";
|
|
818
|
+
btn.style.color = isActive ? color : "#64748b";
|
|
819
|
+
btn.style.fontWeight = isActive ? "600" : "500";
|
|
820
|
+
}
|
|
821
|
+
this.updateSubmitState();
|
|
822
|
+
}
|
|
823
|
+
resetTypeButtons() {
|
|
824
|
+
const buttons = this.root.querySelectorAll("button[data-type]");
|
|
825
|
+
for (const btn of buttons) {
|
|
826
|
+
btn.style.background = "rgba(255,255,255,0.8)";
|
|
827
|
+
btn.style.borderColor = "#e2e8f0";
|
|
828
|
+
btn.style.color = "#64748b";
|
|
829
|
+
btn.style.fontWeight = "500";
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
updateSubmitState() {
|
|
833
|
+
const enabled = this.selectedType !== null && this.textarea.value.trim().length > 0;
|
|
834
|
+
this.submitBtn.style.opacity = enabled ? "1" : "0.35";
|
|
835
|
+
this.submitBtn.style.pointerEvents = enabled ? "auto" : "none";
|
|
836
|
+
}
|
|
837
|
+
submit() {
|
|
838
|
+
if (!this.selectedType || !this.textarea.value.trim()) return;
|
|
839
|
+
this.resolve?.({ type: this.selectedType, message: this.textarea.value.trim() });
|
|
840
|
+
this.resolve = null;
|
|
841
|
+
this.hideElement();
|
|
842
|
+
}
|
|
843
|
+
cancel() {
|
|
844
|
+
this.resolve?.(null);
|
|
845
|
+
this.resolve = null;
|
|
846
|
+
this.hideElement();
|
|
847
|
+
}
|
|
848
|
+
hideElement() {
|
|
849
|
+
this.root.style.opacity = "0";
|
|
850
|
+
this.root.style.transform = "translateY(8px) scale(0.98)";
|
|
851
|
+
setTimeout(() => {
|
|
852
|
+
this.root.style.display = "none";
|
|
853
|
+
}, 250);
|
|
854
|
+
}
|
|
855
|
+
destroy() {
|
|
856
|
+
this.root.remove();
|
|
857
|
+
}
|
|
858
|
+
};
|
|
859
|
+
|
|
860
|
+
// src/annotator.ts
|
|
861
|
+
var Annotator = class {
|
|
862
|
+
constructor(config2, colors, bus) {
|
|
863
|
+
this.config = config2;
|
|
864
|
+
this.colors = colors;
|
|
865
|
+
this.bus = bus;
|
|
866
|
+
this.popup = new Popup(colors);
|
|
867
|
+
this.bus.on("annotation:start", () => this.activate());
|
|
868
|
+
}
|
|
869
|
+
config;
|
|
870
|
+
colors;
|
|
871
|
+
bus;
|
|
872
|
+
overlay = null;
|
|
873
|
+
toolbar = null;
|
|
874
|
+
drawingRect = null;
|
|
875
|
+
startX = 0;
|
|
876
|
+
startY = 0;
|
|
877
|
+
isDrawing = false;
|
|
878
|
+
isActive = false;
|
|
879
|
+
popup;
|
|
880
|
+
savedOverflow = "";
|
|
881
|
+
activate() {
|
|
882
|
+
if (this.isActive) return;
|
|
883
|
+
this.isActive = true;
|
|
884
|
+
this.config.onAnnotationStart?.();
|
|
885
|
+
this.savedOverflow = document.body.style.overflow;
|
|
886
|
+
document.body.style.overflow = "hidden";
|
|
887
|
+
this.overlay = el("div", {
|
|
888
|
+
style: `
|
|
889
|
+
position:fixed;inset:0;
|
|
890
|
+
z-index:2147483646;
|
|
891
|
+
background:rgba(15, 23, 42, 0.04);
|
|
892
|
+
cursor:crosshair;
|
|
893
|
+
`
|
|
894
|
+
});
|
|
895
|
+
this.toolbar = el("div", {
|
|
896
|
+
style: `
|
|
897
|
+
position:fixed;top:0;left:0;right:0;
|
|
898
|
+
z-index:2147483647;
|
|
899
|
+
height:52px;
|
|
900
|
+
background:rgba(255, 255, 255, 0.82);
|
|
901
|
+
backdrop-filter:blur(24px);
|
|
902
|
+
-webkit-backdrop-filter:blur(24px);
|
|
903
|
+
border-bottom:1px solid rgba(255, 255, 255, 0.35);
|
|
904
|
+
display:flex;align-items:center;justify-content:center;gap:16px;
|
|
905
|
+
font-family:"Inter",system-ui,-apple-system,sans-serif;
|
|
906
|
+
font-size:14px;color:#0f172a;
|
|
907
|
+
box-shadow:0 4px 16px rgba(0,0,0,0.06);
|
|
908
|
+
-webkit-font-smoothing:antialiased;
|
|
909
|
+
`
|
|
910
|
+
});
|
|
911
|
+
const dot = el("span", {
|
|
912
|
+
style: `
|
|
913
|
+
width:8px;height:8px;border-radius:50%;
|
|
914
|
+
background:${this.colors.accent};
|
|
915
|
+
box-shadow:0 0 8px ${this.colors.accentGlow};
|
|
916
|
+
animation:pulse 1.5s ease-in-out infinite;
|
|
917
|
+
`
|
|
918
|
+
});
|
|
919
|
+
const style = document.createElement("style");
|
|
920
|
+
style.textContent = `@keyframes pulse{0%,100%{opacity:1}50%{opacity:0.4}}`;
|
|
921
|
+
this.toolbar.appendChild(style);
|
|
922
|
+
const instruction = el("span", { style: "font-weight:500;letter-spacing:-0.01em;" });
|
|
923
|
+
setText(instruction, "Tracez un rectangle sur la zone \xE0 commenter");
|
|
924
|
+
const cancelBtn = document.createElement("button");
|
|
925
|
+
cancelBtn.style.cssText = `
|
|
926
|
+
height:34px;padding:0 18px;border-radius:9999px;
|
|
927
|
+
border:1px solid #e2e8f0;
|
|
928
|
+
background:rgba(255,255,255,0.8);
|
|
929
|
+
color:#64748b;font-family:"Inter",system-ui,-apple-system,sans-serif;
|
|
930
|
+
font-size:13px;font-weight:500;cursor:pointer;
|
|
931
|
+
transition:all 0.2s ease;
|
|
932
|
+
`;
|
|
933
|
+
setText(cancelBtn, "Annuler");
|
|
934
|
+
cancelBtn.addEventListener("click", () => this.deactivate());
|
|
935
|
+
cancelBtn.addEventListener("mouseenter", () => {
|
|
936
|
+
cancelBtn.style.borderColor = "#ef4444";
|
|
937
|
+
cancelBtn.style.color = "#ef4444";
|
|
938
|
+
cancelBtn.style.background = "rgba(239,68,68,0.06)";
|
|
939
|
+
});
|
|
940
|
+
cancelBtn.addEventListener("mouseleave", () => {
|
|
941
|
+
cancelBtn.style.borderColor = "#e2e8f0";
|
|
942
|
+
cancelBtn.style.color = "#64748b";
|
|
943
|
+
cancelBtn.style.background = "rgba(255,255,255,0.8)";
|
|
944
|
+
});
|
|
945
|
+
this.toolbar.appendChild(dot);
|
|
946
|
+
this.toolbar.appendChild(instruction);
|
|
947
|
+
this.toolbar.appendChild(cancelBtn);
|
|
948
|
+
this.overlay.addEventListener("mousedown", this.onMouseDown);
|
|
949
|
+
this.overlay.addEventListener("mousemove", this.onMouseMove);
|
|
950
|
+
this.overlay.addEventListener("mouseup", this.onMouseUp);
|
|
951
|
+
document.addEventListener("keydown", this.onKeyDown);
|
|
952
|
+
document.body.appendChild(this.overlay);
|
|
953
|
+
document.body.appendChild(this.toolbar);
|
|
954
|
+
}
|
|
955
|
+
deactivate() {
|
|
956
|
+
if (!this.isActive) return;
|
|
957
|
+
this.isActive = false;
|
|
958
|
+
this.isDrawing = false;
|
|
959
|
+
document.body.style.overflow = this.savedOverflow;
|
|
960
|
+
document.removeEventListener("keydown", this.onKeyDown);
|
|
961
|
+
this.overlay?.remove();
|
|
962
|
+
this.toolbar?.remove();
|
|
963
|
+
this.drawingRect?.remove();
|
|
964
|
+
this.overlay = null;
|
|
965
|
+
this.toolbar = null;
|
|
966
|
+
this.drawingRect = null;
|
|
967
|
+
this.config.onAnnotationEnd?.();
|
|
968
|
+
this.bus.emit("annotation:end");
|
|
969
|
+
}
|
|
970
|
+
onKeyDown = (e) => {
|
|
971
|
+
if (e.key === "Escape") this.deactivate();
|
|
972
|
+
};
|
|
973
|
+
onMouseDown = (e) => {
|
|
974
|
+
this.isDrawing = true;
|
|
975
|
+
this.startX = e.clientX;
|
|
976
|
+
this.startY = e.clientY;
|
|
977
|
+
this.drawingRect?.remove();
|
|
978
|
+
this.drawingRect = el("div", {
|
|
979
|
+
style: `
|
|
980
|
+
position:fixed;
|
|
981
|
+
border:2px solid ${this.colors.accent};
|
|
982
|
+
background:${this.colors.accent}12;
|
|
983
|
+
pointer-events:none;
|
|
984
|
+
border-radius:8px;
|
|
985
|
+
box-shadow:0 0 16px ${this.colors.accentGlow};
|
|
986
|
+
transition:box-shadow 0.15s ease;
|
|
987
|
+
`
|
|
988
|
+
});
|
|
989
|
+
this.overlay?.appendChild(this.drawingRect);
|
|
990
|
+
};
|
|
991
|
+
onMouseMove = (e) => {
|
|
992
|
+
if (!this.isDrawing || !this.drawingRect) return;
|
|
993
|
+
const x = Math.min(e.clientX, this.startX);
|
|
994
|
+
const y = Math.min(e.clientY, this.startY);
|
|
995
|
+
const w = Math.abs(e.clientX - this.startX);
|
|
996
|
+
const h = Math.abs(e.clientY - this.startY);
|
|
997
|
+
this.drawingRect.style.left = `${x}px`;
|
|
998
|
+
this.drawingRect.style.top = `${y}px`;
|
|
999
|
+
this.drawingRect.style.width = `${w}px`;
|
|
1000
|
+
this.drawingRect.style.height = `${h}px`;
|
|
1001
|
+
};
|
|
1002
|
+
onMouseUp = async (e) => {
|
|
1003
|
+
if (!this.isDrawing || !this.drawingRect) return;
|
|
1004
|
+
this.isDrawing = false;
|
|
1005
|
+
const x = Math.min(e.clientX, this.startX);
|
|
1006
|
+
const y = Math.min(e.clientY, this.startY);
|
|
1007
|
+
const w = Math.abs(e.clientX - this.startX);
|
|
1008
|
+
const h = Math.abs(e.clientY - this.startY);
|
|
1009
|
+
if (w < 10 || h < 10) {
|
|
1010
|
+
this.drawingRect.remove();
|
|
1011
|
+
this.drawingRect = null;
|
|
1012
|
+
return;
|
|
1013
|
+
}
|
|
1014
|
+
const rectBounds = new DOMRect(x, y, w, h);
|
|
1015
|
+
const result = await this.popup.show(rectBounds);
|
|
1016
|
+
if (!result) {
|
|
1017
|
+
this.drawingRect?.remove();
|
|
1018
|
+
this.drawingRect = null;
|
|
1019
|
+
return;
|
|
1020
|
+
}
|
|
1021
|
+
const annotation = this.buildAnnotation(rectBounds);
|
|
1022
|
+
this.drawingRect?.remove();
|
|
1023
|
+
this.drawingRect = null;
|
|
1024
|
+
this.deactivate();
|
|
1025
|
+
this.bus.emit("annotation:complete", {
|
|
1026
|
+
annotation,
|
|
1027
|
+
type: result.type,
|
|
1028
|
+
message: result.message
|
|
1029
|
+
});
|
|
1030
|
+
};
|
|
1031
|
+
/**
|
|
1032
|
+
* Build an AnnotationPayload from a drawn rectangle.
|
|
1033
|
+
* Temporarily hides the overlay to access the real DOM underneath.
|
|
1034
|
+
*/
|
|
1035
|
+
buildAnnotation(rectBounds) {
|
|
1036
|
+
if (this.overlay) this.overlay.style.pointerEvents = "none";
|
|
1037
|
+
const anchorElement = findAnchorElement(rectBounds);
|
|
1038
|
+
if (this.overlay) this.overlay.style.pointerEvents = "auto";
|
|
1039
|
+
const anchor = generateAnchor(anchorElement);
|
|
1040
|
+
const anchorBounds = anchorElement.getBoundingClientRect();
|
|
1041
|
+
const rect = rectToPercentages(rectBounds, anchorBounds);
|
|
1042
|
+
return {
|
|
1043
|
+
anchor,
|
|
1044
|
+
rect,
|
|
1045
|
+
scrollX: window.scrollX,
|
|
1046
|
+
scrollY: window.scrollY,
|
|
1047
|
+
viewportW: window.innerWidth,
|
|
1048
|
+
viewportH: window.innerHeight,
|
|
1049
|
+
devicePixelRatio: window.devicePixelRatio
|
|
1050
|
+
};
|
|
1051
|
+
}
|
|
1052
|
+
destroy() {
|
|
1053
|
+
this.deactivate();
|
|
1054
|
+
this.popup.destroy();
|
|
1055
|
+
}
|
|
1056
|
+
};
|
|
1057
|
+
|
|
1058
|
+
// src/api-client.ts
|
|
1059
|
+
var MAX_RETRIES = 3;
|
|
1060
|
+
var TIMEOUT_MS = 1e4;
|
|
1061
|
+
var RETRY_QUEUE_KEY = "siteping_retry_queue";
|
|
1062
|
+
async function resilientFetch(url, init, retries = MAX_RETRIES) {
|
|
1063
|
+
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
1064
|
+
const controller = new AbortController();
|
|
1065
|
+
const timeout = setTimeout(() => controller.abort(), TIMEOUT_MS);
|
|
1066
|
+
try {
|
|
1067
|
+
const response = await fetch(url, {
|
|
1068
|
+
...init,
|
|
1069
|
+
signal: controller.signal
|
|
1070
|
+
});
|
|
1071
|
+
clearTimeout(timeout);
|
|
1072
|
+
if (response.ok || response.status >= 400 && response.status < 500) {
|
|
1073
|
+
return response;
|
|
1074
|
+
}
|
|
1075
|
+
if (attempt === retries) return response;
|
|
1076
|
+
} catch (error) {
|
|
1077
|
+
clearTimeout(timeout);
|
|
1078
|
+
if (attempt === retries) throw error;
|
|
1079
|
+
}
|
|
1080
|
+
const baseDelay = 1e3 * 2 ** attempt;
|
|
1081
|
+
const jitter = Math.random() * 1e3 - 500;
|
|
1082
|
+
await new Promise((r) => setTimeout(r, baseDelay + jitter));
|
|
1083
|
+
}
|
|
1084
|
+
throw new Error("Max retries exceeded");
|
|
1085
|
+
}
|
|
1086
|
+
function queueForRetry(endpoint, payload) {
|
|
1087
|
+
try {
|
|
1088
|
+
const raw = localStorage.getItem(RETRY_QUEUE_KEY);
|
|
1089
|
+
const queue = raw ? JSON.parse(raw) : [];
|
|
1090
|
+
queue.push({ endpoint, payload });
|
|
1091
|
+
localStorage.setItem(RETRY_QUEUE_KEY, JSON.stringify(queue));
|
|
1092
|
+
} catch {
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
async function flushRetryQueue(endpoint) {
|
|
1096
|
+
try {
|
|
1097
|
+
const raw = localStorage.getItem(RETRY_QUEUE_KEY);
|
|
1098
|
+
if (!raw) return;
|
|
1099
|
+
const queue = JSON.parse(raw);
|
|
1100
|
+
const toRetry = queue.filter((e) => e.endpoint === endpoint);
|
|
1101
|
+
if (toRetry.length === 0) return;
|
|
1102
|
+
const failed = [];
|
|
1103
|
+
for (const entry of toRetry) {
|
|
1104
|
+
try {
|
|
1105
|
+
const res = await fetch(endpoint, {
|
|
1106
|
+
method: "POST",
|
|
1107
|
+
headers: { "Content-Type": "application/json" },
|
|
1108
|
+
body: JSON.stringify(entry.payload)
|
|
1109
|
+
});
|
|
1110
|
+
if (!res.ok) failed.push(entry);
|
|
1111
|
+
} catch {
|
|
1112
|
+
failed.push(entry);
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
const remaining = queue.filter((e) => e.endpoint !== endpoint).concat(failed);
|
|
1116
|
+
if (remaining.length > 0) {
|
|
1117
|
+
localStorage.setItem(RETRY_QUEUE_KEY, JSON.stringify(remaining));
|
|
1118
|
+
} else {
|
|
1119
|
+
localStorage.removeItem(RETRY_QUEUE_KEY);
|
|
1120
|
+
}
|
|
1121
|
+
} catch {
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
var ApiClient = class {
|
|
1125
|
+
constructor(endpoint) {
|
|
1126
|
+
this.endpoint = endpoint;
|
|
1127
|
+
}
|
|
1128
|
+
endpoint;
|
|
1129
|
+
async sendFeedback(payload) {
|
|
1130
|
+
try {
|
|
1131
|
+
const response = await resilientFetch(this.endpoint, {
|
|
1132
|
+
method: "POST",
|
|
1133
|
+
headers: { "Content-Type": "application/json" },
|
|
1134
|
+
body: JSON.stringify(payload)
|
|
1135
|
+
});
|
|
1136
|
+
if (!response.ok) {
|
|
1137
|
+
const text = await response.text().catch(() => "Unknown error");
|
|
1138
|
+
throw new Error(`Failed to send feedback: ${response.status} ${text}`);
|
|
1139
|
+
}
|
|
1140
|
+
return await response.json();
|
|
1141
|
+
} catch (error) {
|
|
1142
|
+
queueForRetry(this.endpoint, payload);
|
|
1143
|
+
throw error;
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
async getFeedbacks(projectName, options) {
|
|
1147
|
+
const params = new URLSearchParams({ projectName });
|
|
1148
|
+
if (options?.page) params.set("page", String(options.page));
|
|
1149
|
+
if (options?.limit) params.set("limit", String(options.limit));
|
|
1150
|
+
if (options?.type) params.set("type", options.type);
|
|
1151
|
+
if (options?.status) params.set("status", options.status);
|
|
1152
|
+
if (options?.search) params.set("search", options.search);
|
|
1153
|
+
const response = await resilientFetch(`${this.endpoint}?${params.toString()}`, { method: "GET" });
|
|
1154
|
+
if (!response.ok) {
|
|
1155
|
+
throw new Error(`Failed to fetch feedbacks: ${response.status}`);
|
|
1156
|
+
}
|
|
1157
|
+
return await response.json();
|
|
1158
|
+
}
|
|
1159
|
+
async resolveFeedback(id2, resolved) {
|
|
1160
|
+
const response = await resilientFetch(this.endpoint, {
|
|
1161
|
+
method: "PATCH",
|
|
1162
|
+
headers: { "Content-Type": "application/json" },
|
|
1163
|
+
body: JSON.stringify({ id: id2, status: resolved ? "resolved" : "open" })
|
|
1164
|
+
});
|
|
1165
|
+
if (!response.ok) {
|
|
1166
|
+
throw new Error(`Failed to update feedback: ${response.status}`);
|
|
1167
|
+
}
|
|
1168
|
+
return await response.json();
|
|
1169
|
+
}
|
|
1170
|
+
async deleteFeedback(id2) {
|
|
1171
|
+
const response = await resilientFetch(this.endpoint, {
|
|
1172
|
+
method: "DELETE",
|
|
1173
|
+
headers: { "Content-Type": "application/json" },
|
|
1174
|
+
body: JSON.stringify({ id: id2 })
|
|
1175
|
+
});
|
|
1176
|
+
if (!response.ok) {
|
|
1177
|
+
throw new Error(`Failed to delete feedback: ${response.status}`);
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
async deleteAllFeedbacks(projectName) {
|
|
1181
|
+
const response = await resilientFetch(this.endpoint, {
|
|
1182
|
+
method: "DELETE",
|
|
1183
|
+
headers: { "Content-Type": "application/json" },
|
|
1184
|
+
body: JSON.stringify({ projectName, deleteAll: true })
|
|
1185
|
+
});
|
|
1186
|
+
if (!response.ok) {
|
|
1187
|
+
throw new Error(`Failed to delete all feedbacks: ${response.status}`);
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
};
|
|
1191
|
+
|
|
1192
|
+
// src/events.ts
|
|
1193
|
+
var EventBus = class {
|
|
1194
|
+
listeners = /* @__PURE__ */ new Map();
|
|
1195
|
+
on(event, listener) {
|
|
1196
|
+
if (!this.listeners.has(event)) {
|
|
1197
|
+
this.listeners.set(event, /* @__PURE__ */ new Set());
|
|
1198
|
+
}
|
|
1199
|
+
const set = this.listeners.get(event);
|
|
1200
|
+
set.add(listener);
|
|
1201
|
+
return () => {
|
|
1202
|
+
set.delete(listener);
|
|
1203
|
+
};
|
|
1204
|
+
}
|
|
1205
|
+
emit(event, ...args) {
|
|
1206
|
+
const set = this.listeners.get(event);
|
|
1207
|
+
if (!set) return;
|
|
1208
|
+
for (const fn of set) {
|
|
1209
|
+
try {
|
|
1210
|
+
fn(...args);
|
|
1211
|
+
} catch (err) {
|
|
1212
|
+
console.error(`[siteping] Error in event listener for "${String(event)}":`, err);
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
removeAll() {
|
|
1217
|
+
this.listeners.clear();
|
|
1218
|
+
}
|
|
1219
|
+
};
|
|
1220
|
+
|
|
1221
|
+
// src/fab.ts
|
|
1222
|
+
var ITEM_GAP = 54;
|
|
1223
|
+
var Fab = class {
|
|
1224
|
+
constructor(shadowRoot, config2, bus) {
|
|
1225
|
+
this.bus = bus;
|
|
1226
|
+
const position = config2.position ?? "bottom-right";
|
|
1227
|
+
const isRight = position === "bottom-right";
|
|
1228
|
+
this.items = [
|
|
1229
|
+
{ id: "chat", icon: ICON_CHAT, label: "Messages" },
|
|
1230
|
+
{ id: "annotate", icon: ICON_ANNOTATE, label: "Annoter" },
|
|
1231
|
+
{ id: "toggle-annotations", icon: ICON_EYE, iconAlt: ICON_EYE_OFF, label: "Annotations" }
|
|
1232
|
+
];
|
|
1233
|
+
this.fab = document.createElement("button");
|
|
1234
|
+
this.fab.className = `sp-fab sp-fab--${position} sp-anim-fab-in`;
|
|
1235
|
+
this.fab.style.position = "fixed";
|
|
1236
|
+
this.fab.appendChild(parseSvg(ICON_SITEPING));
|
|
1237
|
+
this.fab.setAttribute("aria-label", "Siteping \u2014 Menu feedback");
|
|
1238
|
+
this.fab.setAttribute("aria-expanded", "false");
|
|
1239
|
+
this.fab.addEventListener("click", () => this.toggle());
|
|
1240
|
+
this.radialContainer = document.createElement("div");
|
|
1241
|
+
this.radialContainer.className = `sp-radial sp-radial--${position}`;
|
|
1242
|
+
this.radialContainer.setAttribute("role", "menu");
|
|
1243
|
+
for (let i = 0; i < this.items.length; i++) {
|
|
1244
|
+
const item = this.items[i];
|
|
1245
|
+
const btn = document.createElement("button");
|
|
1246
|
+
btn.className = "sp-radial-item";
|
|
1247
|
+
btn.style.setProperty("--sp-i", String(i));
|
|
1248
|
+
btn.appendChild(parseSvg(item.icon));
|
|
1249
|
+
btn.setAttribute("role", "menuitem");
|
|
1250
|
+
btn.setAttribute("aria-label", item.label);
|
|
1251
|
+
btn.dataset.itemId = item.id;
|
|
1252
|
+
btn.addEventListener("click", (e) => {
|
|
1253
|
+
e.stopPropagation();
|
|
1254
|
+
this.handleItemClick(item.id);
|
|
1255
|
+
});
|
|
1256
|
+
const label = document.createElement("span");
|
|
1257
|
+
label.className = "sp-radial-label";
|
|
1258
|
+
label.textContent = item.label;
|
|
1259
|
+
label.style.cssText = isRight ? "position:absolute; right:54px; top:50%; transform:translateY(-50%); white-space:nowrap;" : "position:absolute; left:54px; top:50%; transform:translateY(-50%); white-space:nowrap;";
|
|
1260
|
+
btn.appendChild(label);
|
|
1261
|
+
this.radialContainer.appendChild(btn);
|
|
1262
|
+
}
|
|
1263
|
+
this.root = document.createElement("div");
|
|
1264
|
+
this.root.appendChild(this.radialContainer);
|
|
1265
|
+
this.root.appendChild(this.fab);
|
|
1266
|
+
shadowRoot.appendChild(this.root);
|
|
1267
|
+
const host = shadowRoot.host;
|
|
1268
|
+
this.onDocumentClick = (e) => {
|
|
1269
|
+
if (this.isOpen && !e.composedPath().includes(host)) {
|
|
1270
|
+
this.close();
|
|
1271
|
+
}
|
|
1272
|
+
};
|
|
1273
|
+
document.addEventListener("click", this.onDocumentClick);
|
|
1274
|
+
this.fab.addEventListener("keydown", (e) => {
|
|
1275
|
+
if (e.key === "Escape" && this.isOpen) this.close();
|
|
1276
|
+
});
|
|
1277
|
+
}
|
|
1278
|
+
bus;
|
|
1279
|
+
root;
|
|
1280
|
+
fab;
|
|
1281
|
+
radialContainer;
|
|
1282
|
+
badgeEl = null;
|
|
1283
|
+
isOpen = false;
|
|
1284
|
+
annotationsVisible = true;
|
|
1285
|
+
items;
|
|
1286
|
+
onDocumentClick;
|
|
1287
|
+
/** Update the badge count. Pass 0 to hide. */
|
|
1288
|
+
updateBadge(count) {
|
|
1289
|
+
if (count <= 0) {
|
|
1290
|
+
this.badgeEl?.remove();
|
|
1291
|
+
this.badgeEl = null;
|
|
1292
|
+
return;
|
|
1293
|
+
}
|
|
1294
|
+
if (!this.badgeEl) {
|
|
1295
|
+
this.badgeEl = document.createElement("span");
|
|
1296
|
+
this.badgeEl.className = "sp-fab-badge";
|
|
1297
|
+
this.fab.appendChild(this.badgeEl);
|
|
1298
|
+
}
|
|
1299
|
+
setText(this.badgeEl, count > 99 ? "99+" : String(count));
|
|
1300
|
+
}
|
|
1301
|
+
toggle() {
|
|
1302
|
+
this.isOpen ? this.close() : this.open();
|
|
1303
|
+
}
|
|
1304
|
+
open() {
|
|
1305
|
+
this.isOpen = true;
|
|
1306
|
+
this.setFabIcon(ICON_CLOSE);
|
|
1307
|
+
this.fab.setAttribute("aria-expanded", "true");
|
|
1308
|
+
const buttons = this.radialContainer.querySelectorAll(".sp-radial-item");
|
|
1309
|
+
buttons.forEach((btn, i) => {
|
|
1310
|
+
const y = -(16 + ITEM_GAP * (i + 1));
|
|
1311
|
+
btn.style.transform = `translate(0px, ${y}px) scale(1)`;
|
|
1312
|
+
btn.classList.add("sp-radial-item--open");
|
|
1313
|
+
});
|
|
1314
|
+
}
|
|
1315
|
+
close() {
|
|
1316
|
+
this.isOpen = false;
|
|
1317
|
+
this.setFabIcon(ICON_SITEPING);
|
|
1318
|
+
this.fab.setAttribute("aria-expanded", "false");
|
|
1319
|
+
const buttons = this.radialContainer.querySelectorAll(".sp-radial-item");
|
|
1320
|
+
buttons.forEach((btn) => {
|
|
1321
|
+
btn.style.transform = "translate(0, 0) scale(0.8)";
|
|
1322
|
+
btn.classList.remove("sp-radial-item--open");
|
|
1323
|
+
});
|
|
1324
|
+
}
|
|
1325
|
+
setFabIcon(svgStr) {
|
|
1326
|
+
const badge = this.badgeEl;
|
|
1327
|
+
this.fab.replaceChildren(parseSvg(svgStr));
|
|
1328
|
+
if (badge) this.fab.appendChild(badge);
|
|
1329
|
+
}
|
|
1330
|
+
handleItemClick(id2) {
|
|
1331
|
+
this.close();
|
|
1332
|
+
switch (id2) {
|
|
1333
|
+
case "chat":
|
|
1334
|
+
this.bus.emit("panel:toggle", true);
|
|
1335
|
+
break;
|
|
1336
|
+
case "annotate":
|
|
1337
|
+
this.bus.emit("annotation:start");
|
|
1338
|
+
break;
|
|
1339
|
+
case "toggle-annotations": {
|
|
1340
|
+
this.annotationsVisible = !this.annotationsVisible;
|
|
1341
|
+
this.bus.emit("annotations:toggle", this.annotationsVisible);
|
|
1342
|
+
const btn = this.radialContainer.querySelector('[data-item-id="toggle-annotations"]');
|
|
1343
|
+
if (btn) {
|
|
1344
|
+
btn.replaceChildren(parseSvg(this.annotationsVisible ? ICON_EYE : ICON_EYE_OFF));
|
|
1345
|
+
}
|
|
1346
|
+
break;
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
destroy() {
|
|
1351
|
+
document.removeEventListener("click", this.onDocumentClick);
|
|
1352
|
+
this.root.remove();
|
|
1353
|
+
}
|
|
1354
|
+
};
|
|
1355
|
+
|
|
1356
|
+
// src/identity.ts
|
|
1357
|
+
var STORAGE_KEY = "siteping_identity";
|
|
1358
|
+
function getIdentity() {
|
|
1359
|
+
try {
|
|
1360
|
+
const raw = localStorage.getItem(STORAGE_KEY);
|
|
1361
|
+
if (!raw) return null;
|
|
1362
|
+
const parsed = JSON.parse(raw);
|
|
1363
|
+
if (parsed.name && parsed.email) return parsed;
|
|
1364
|
+
return null;
|
|
1365
|
+
} catch {
|
|
1366
|
+
return null;
|
|
1367
|
+
}
|
|
1368
|
+
}
|
|
1369
|
+
function saveIdentity(identity) {
|
|
1370
|
+
try {
|
|
1371
|
+
localStorage.setItem(STORAGE_KEY, JSON.stringify(identity));
|
|
1372
|
+
} catch {
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1375
|
+
|
|
1376
|
+
// src/dom/fuzzy.ts
|
|
1377
|
+
function editDistance(a, b) {
|
|
1378
|
+
if (a === b) return 0;
|
|
1379
|
+
if (a.length === 0) return b.length;
|
|
1380
|
+
if (b.length === 0) return a.length;
|
|
1381
|
+
if (a.length > b.length) {
|
|
1382
|
+
const t = a;
|
|
1383
|
+
a = b;
|
|
1384
|
+
b = t;
|
|
1385
|
+
}
|
|
1386
|
+
const aLen = a.length;
|
|
1387
|
+
const bLen = b.length;
|
|
1388
|
+
let prev = new Array(aLen + 1);
|
|
1389
|
+
for (let k = 0; k <= aLen; k++) prev[k] = k;
|
|
1390
|
+
let curr = new Array(aLen + 1);
|
|
1391
|
+
for (let j = 1; j <= bLen; j++) {
|
|
1392
|
+
curr[0] = j;
|
|
1393
|
+
for (let i = 1; i <= aLen; i++) {
|
|
1394
|
+
curr[i] = a[i - 1] === b[j - 1] ? prev[i - 1] : 1 + Math.min(prev[i - 1], prev[i], curr[i - 1]);
|
|
1395
|
+
}
|
|
1396
|
+
const tmp = prev;
|
|
1397
|
+
prev = curr;
|
|
1398
|
+
curr = tmp;
|
|
1399
|
+
}
|
|
1400
|
+
return prev[aLen];
|
|
1401
|
+
}
|
|
1402
|
+
function similarity(a, b) {
|
|
1403
|
+
if (a === b) return 1;
|
|
1404
|
+
const maxLen = Math.max(a.length, b.length);
|
|
1405
|
+
if (maxLen === 0) return 1;
|
|
1406
|
+
return 1 - editDistance(a, b) / maxLen;
|
|
1407
|
+
}
|
|
1408
|
+
function fuzzyIncludes(haystack, needle, minScore = 0.6) {
|
|
1409
|
+
if (!needle || !haystack) return 0;
|
|
1410
|
+
if (haystack.includes(needle)) return 1;
|
|
1411
|
+
const nLen = needle.length;
|
|
1412
|
+
if (nLen > haystack.length) {
|
|
1413
|
+
const score = similarity(haystack, needle);
|
|
1414
|
+
return score >= minScore ? score : 0;
|
|
1415
|
+
}
|
|
1416
|
+
let best = 0;
|
|
1417
|
+
const capped = haystack.length > 500 ? haystack.slice(0, 500) : haystack;
|
|
1418
|
+
const limit = capped.length - nLen;
|
|
1419
|
+
for (let i = 0; i <= limit; i++) {
|
|
1420
|
+
const window2 = capped.slice(i, i + nLen);
|
|
1421
|
+
const score = similarity(window2, needle);
|
|
1422
|
+
if (score > best) best = score;
|
|
1423
|
+
if (best >= 0.95) break;
|
|
1424
|
+
}
|
|
1425
|
+
return best >= minScore ? best : 0;
|
|
1426
|
+
}
|
|
1427
|
+
|
|
1428
|
+
// src/dom/resolver.ts
|
|
1429
|
+
var MAX_SCAN_CANDIDATES = 300;
|
|
1430
|
+
var TEXT_MATCH_THRESHOLD = 0.3;
|
|
1431
|
+
function textMatches(el2, anchor) {
|
|
1432
|
+
if (!anchor.textSnippet) return true;
|
|
1433
|
+
const text = (el2.textContent?.trim() ?? "").slice(0, 500);
|
|
1434
|
+
return fuzzyIncludes(text, anchor.textSnippet, 0.5) > TEXT_MATCH_THRESHOLD;
|
|
1435
|
+
}
|
|
1436
|
+
function resolveAnchor(anchor) {
|
|
1437
|
+
if (anchor.elementId) {
|
|
1438
|
+
const el2 = document.getElementById(anchor.elementId);
|
|
1439
|
+
if (el2 && el2.tagName === anchor.elementTag && textMatches(el2, anchor)) {
|
|
1440
|
+
return { element: el2, confidence: 1, strategy: "id" };
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1443
|
+
try {
|
|
1444
|
+
const el2 = document.querySelector(anchor.cssSelector);
|
|
1445
|
+
if (el2 && el2.tagName === anchor.elementTag && textMatches(el2, anchor)) {
|
|
1446
|
+
return { element: el2, confidence: 0.95, strategy: "css" };
|
|
1447
|
+
}
|
|
1448
|
+
} catch {
|
|
1449
|
+
}
|
|
1450
|
+
try {
|
|
1451
|
+
const result = document.evaluate(anchor.xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
|
|
1452
|
+
const el2 = result.singleNodeValue;
|
|
1453
|
+
if (el2 instanceof Element && el2.tagName === anchor.elementTag && textMatches(el2, anchor)) {
|
|
1454
|
+
return { element: el2, confidence: 0.9, strategy: "xpath" };
|
|
1455
|
+
}
|
|
1456
|
+
} catch {
|
|
1457
|
+
}
|
|
1458
|
+
return smartScan(anchor);
|
|
1459
|
+
}
|
|
1460
|
+
function smartScan(anchor) {
|
|
1461
|
+
const tag = anchor.elementTag.toLowerCase();
|
|
1462
|
+
const candidates = document.querySelectorAll(tag);
|
|
1463
|
+
if (candidates.length === 0) return null;
|
|
1464
|
+
let bestElement = null;
|
|
1465
|
+
let bestScore = 0;
|
|
1466
|
+
const limit = Math.min(candidates.length, MAX_SCAN_CANDIDATES);
|
|
1467
|
+
for (let i = 0; i < limit; i++) {
|
|
1468
|
+
const el2 = candidates[i];
|
|
1469
|
+
const score = scoreCandidate(el2, anchor);
|
|
1470
|
+
if (score > bestScore) {
|
|
1471
|
+
bestScore = score;
|
|
1472
|
+
bestElement = el2;
|
|
1473
|
+
if (bestScore >= 0.85) break;
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1476
|
+
if (!bestElement || bestScore < 0.4) return null;
|
|
1477
|
+
return {
|
|
1478
|
+
element: bestElement,
|
|
1479
|
+
confidence: Math.min(bestScore, 0.85),
|
|
1480
|
+
strategy: "scan"
|
|
1481
|
+
};
|
|
1482
|
+
}
|
|
1483
|
+
function scoreCandidate(candidate, anchor) {
|
|
1484
|
+
let score = 0;
|
|
1485
|
+
let totalWeight = 0;
|
|
1486
|
+
const candidateText = (candidate.textContent?.trim() ?? "").slice(0, 500);
|
|
1487
|
+
if (anchor.textSnippet) {
|
|
1488
|
+
totalWeight += 40;
|
|
1489
|
+
score += fuzzyIncludes(candidateText, anchor.textSnippet, 0.5) * 40;
|
|
1490
|
+
}
|
|
1491
|
+
if (anchor.fingerprint) {
|
|
1492
|
+
totalWeight += 20;
|
|
1493
|
+
score += scoreFingerprint(candidate, anchor.fingerprint) * 20;
|
|
1494
|
+
}
|
|
1495
|
+
if (anchor.textPrefix || anchor.textSuffix) {
|
|
1496
|
+
totalWeight += 20;
|
|
1497
|
+
let contextScore = 0;
|
|
1498
|
+
let contextParts = 0;
|
|
1499
|
+
if (anchor.textPrefix) {
|
|
1500
|
+
const prevText = adjacentText(candidate, "before");
|
|
1501
|
+
contextScore += prevText ? similarity(prevText, anchor.textPrefix) : 0;
|
|
1502
|
+
contextParts++;
|
|
1503
|
+
}
|
|
1504
|
+
if (anchor.textSuffix) {
|
|
1505
|
+
const nextText = adjacentText(candidate, "after");
|
|
1506
|
+
contextScore += nextText ? similarity(nextText, anchor.textSuffix) : 0;
|
|
1507
|
+
contextParts++;
|
|
1508
|
+
}
|
|
1509
|
+
if (contextParts > 0) {
|
|
1510
|
+
score += contextScore / contextParts * 20;
|
|
1511
|
+
}
|
|
1512
|
+
}
|
|
1513
|
+
if (anchor.neighborText) {
|
|
1514
|
+
totalWeight += 20;
|
|
1515
|
+
const candidateNeighbor = neighborText(candidate);
|
|
1516
|
+
score += candidateNeighbor ? similarity(candidateNeighbor, anchor.neighborText) * 20 : 0;
|
|
1517
|
+
}
|
|
1518
|
+
return totalWeight > 0 ? score / totalWeight : 0;
|
|
1519
|
+
}
|
|
1520
|
+
function resolveAnnotation(anchor, rect) {
|
|
1521
|
+
const resolution = resolveAnchor(anchor);
|
|
1522
|
+
if (!resolution) return null;
|
|
1523
|
+
const bounds = resolution.element.getBoundingClientRect();
|
|
1524
|
+
const absoluteRect = new DOMRect(
|
|
1525
|
+
bounds.x + rect.xPct * bounds.width,
|
|
1526
|
+
bounds.y + rect.yPct * bounds.height,
|
|
1527
|
+
rect.wPct * bounds.width,
|
|
1528
|
+
rect.hPct * bounds.height
|
|
1529
|
+
);
|
|
1530
|
+
return {
|
|
1531
|
+
element: resolution.element,
|
|
1532
|
+
rect: absoluteRect,
|
|
1533
|
+
confidence: resolution.confidence,
|
|
1534
|
+
strategy: resolution.strategy
|
|
1535
|
+
};
|
|
1536
|
+
}
|
|
1537
|
+
|
|
1538
|
+
// src/markers.ts
|
|
1539
|
+
function toAnchorData(a) {
|
|
1540
|
+
return {
|
|
1541
|
+
cssSelector: a.cssSelector,
|
|
1542
|
+
xpath: a.xpath,
|
|
1543
|
+
textSnippet: a.textSnippet,
|
|
1544
|
+
elementTag: a.elementTag,
|
|
1545
|
+
elementId: a.elementId ?? void 0,
|
|
1546
|
+
textPrefix: a.textPrefix,
|
|
1547
|
+
textSuffix: a.textSuffix,
|
|
1548
|
+
fingerprint: a.fingerprint,
|
|
1549
|
+
neighborText: a.neighborText
|
|
1550
|
+
};
|
|
1551
|
+
}
|
|
1552
|
+
function toRectData(a) {
|
|
1553
|
+
return { xPct: a.xPct, yPct: a.yPct, wPct: a.wPct, hPct: a.hPct };
|
|
1554
|
+
}
|
|
1555
|
+
var MARKER_OFFSET = 13;
|
|
1556
|
+
function markerPosition(rect) {
|
|
1557
|
+
return {
|
|
1558
|
+
top: rect.top + window.scrollY - MARKER_OFFSET,
|
|
1559
|
+
left: rect.right + window.scrollX - MARKER_OFFSET
|
|
1560
|
+
};
|
|
1561
|
+
}
|
|
1562
|
+
function clusterMarker(cluster, i) {
|
|
1563
|
+
return cluster.entries[i].elements[cluster.elementIndices[i]];
|
|
1564
|
+
}
|
|
1565
|
+
var HIGHLIGHT_FADE = 300;
|
|
1566
|
+
var REPOSITION_DEBOUNCE = 200;
|
|
1567
|
+
var LOW_CONFIDENCE_THRESHOLD = 0.7;
|
|
1568
|
+
var CLUSTER_DISTANCE = 28;
|
|
1569
|
+
var FAN_SPACING = 32;
|
|
1570
|
+
var MarkerManager = class {
|
|
1571
|
+
constructor(colors, tooltip, bus) {
|
|
1572
|
+
this.colors = colors;
|
|
1573
|
+
this.tooltip = tooltip;
|
|
1574
|
+
this.bus = bus;
|
|
1575
|
+
this.container = el("div", {
|
|
1576
|
+
style: "position:absolute;top:0;left:0;pointer-events:none;z-index:2147483646;"
|
|
1577
|
+
});
|
|
1578
|
+
this.container.id = "siteping-markers";
|
|
1579
|
+
document.body.appendChild(this.container);
|
|
1580
|
+
this.bus.on("annotations:toggle", (visible) => {
|
|
1581
|
+
this.container.style.display = visible ? "block" : "none";
|
|
1582
|
+
});
|
|
1583
|
+
this.resizeHandler = () => this.scheduleReposition();
|
|
1584
|
+
window.addEventListener("resize", this.resizeHandler, { passive: true });
|
|
1585
|
+
this.mutationObserver = new MutationObserver((mutations) => {
|
|
1586
|
+
const isWidgetMutation = mutations.every(
|
|
1587
|
+
(m) => this.container.contains(m.target) || this.tooltip.contains(m.target)
|
|
1588
|
+
);
|
|
1589
|
+
if (!isWidgetMutation) this.scheduleReposition();
|
|
1590
|
+
});
|
|
1591
|
+
this.mutationObserver.observe(document.body, {
|
|
1592
|
+
childList: true,
|
|
1593
|
+
subtree: true,
|
|
1594
|
+
attributes: false,
|
|
1595
|
+
characterData: false
|
|
1596
|
+
});
|
|
1597
|
+
this.onDocumentClickForClusters = (e) => {
|
|
1598
|
+
if (this.container.contains(e.target)) return;
|
|
1599
|
+
this.collapseAllClusters();
|
|
1600
|
+
};
|
|
1601
|
+
document.addEventListener("click", this.onDocumentClickForClusters);
|
|
1602
|
+
}
|
|
1603
|
+
colors;
|
|
1604
|
+
tooltip;
|
|
1605
|
+
bus;
|
|
1606
|
+
container;
|
|
1607
|
+
entries = [];
|
|
1608
|
+
highlightElements = [];
|
|
1609
|
+
pinnedFeedback = null;
|
|
1610
|
+
onDocumentClick = null;
|
|
1611
|
+
repositionTimer = null;
|
|
1612
|
+
mutationObserver = null;
|
|
1613
|
+
resizeHandler = null;
|
|
1614
|
+
clusters = [];
|
|
1615
|
+
onDocumentClickForClusters = null;
|
|
1616
|
+
get count() {
|
|
1617
|
+
return this.entries.length;
|
|
1618
|
+
}
|
|
1619
|
+
scheduleReposition() {
|
|
1620
|
+
if (this.repositionTimer) return;
|
|
1621
|
+
this.repositionTimer = setTimeout(() => {
|
|
1622
|
+
this.repositionTimer = null;
|
|
1623
|
+
this.repositionAll();
|
|
1624
|
+
}, REPOSITION_DEBOUNCE);
|
|
1625
|
+
}
|
|
1626
|
+
repositionAll() {
|
|
1627
|
+
for (const entry of this.entries) {
|
|
1628
|
+
for (let i = 0; i < entry.feedback.annotations.length; i++) {
|
|
1629
|
+
const markerEl = entry.elements[i];
|
|
1630
|
+
if (!markerEl) continue;
|
|
1631
|
+
const annotation = entry.feedback.annotations[i];
|
|
1632
|
+
const resolved = resolveAnnotation(toAnchorData(annotation), toRectData(annotation));
|
|
1633
|
+
if (!resolved) {
|
|
1634
|
+
markerEl.style.display = "none";
|
|
1635
|
+
continue;
|
|
1636
|
+
}
|
|
1637
|
+
const pos = markerPosition(resolved.rect);
|
|
1638
|
+
entry.baseTop = pos.top;
|
|
1639
|
+
entry.baseLeft = pos.left;
|
|
1640
|
+
markerEl.style.display = "flex";
|
|
1641
|
+
this.applyConfidenceStyle(markerEl, resolved.confidence, entry.feedback);
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
this.applyClusterPositions();
|
|
1645
|
+
}
|
|
1646
|
+
applyClusterPositions() {
|
|
1647
|
+
for (const cluster of this.clusters) {
|
|
1648
|
+
if (cluster.expanded) {
|
|
1649
|
+
this.applyFanPositions(cluster);
|
|
1650
|
+
} else {
|
|
1651
|
+
this.applyStackPositions(cluster);
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
1655
|
+
render(feedbacks) {
|
|
1656
|
+
this.clear();
|
|
1657
|
+
feedbacks.forEach((feedback, i) => {
|
|
1658
|
+
const entry = this.buildEntry(feedback, i + 1);
|
|
1659
|
+
this.entries.push(entry);
|
|
1660
|
+
});
|
|
1661
|
+
this.buildClusters();
|
|
1662
|
+
}
|
|
1663
|
+
addFeedback(feedback, index2) {
|
|
1664
|
+
const entry = this.buildEntry(feedback, index2);
|
|
1665
|
+
for (const m of entry.elements) {
|
|
1666
|
+
m.style.animation = "sp-marker-in 0.35s cubic-bezier(0.34,1.56,0.64,1) both";
|
|
1667
|
+
}
|
|
1668
|
+
this.entries.push(entry);
|
|
1669
|
+
this.buildClusters();
|
|
1670
|
+
}
|
|
1671
|
+
buildEntry(feedback, index2) {
|
|
1672
|
+
const entry = { feedback, elements: [], baseTop: 0, baseLeft: 0 };
|
|
1673
|
+
for (const annotation of feedback.annotations) {
|
|
1674
|
+
const resolved = resolveAnnotation(toAnchorData(annotation), toRectData(annotation));
|
|
1675
|
+
if (!resolved) continue;
|
|
1676
|
+
const pos = markerPosition(resolved.rect);
|
|
1677
|
+
entry.baseTop = pos.top;
|
|
1678
|
+
entry.baseLeft = pos.left;
|
|
1679
|
+
const marker = this.createMarker(index2, feedback, pos);
|
|
1680
|
+
this.applyConfidenceStyle(marker, resolved.confidence, feedback);
|
|
1681
|
+
this.container.appendChild(marker);
|
|
1682
|
+
entry.elements.push(marker);
|
|
1683
|
+
}
|
|
1684
|
+
return entry;
|
|
1685
|
+
}
|
|
1686
|
+
buildClusters() {
|
|
1687
|
+
for (const badge of this.container.querySelectorAll(".sp-cluster-badge")) {
|
|
1688
|
+
badge.remove();
|
|
1689
|
+
}
|
|
1690
|
+
const allItems = [];
|
|
1691
|
+
for (const entry of this.entries) {
|
|
1692
|
+
for (let i = 0; i < entry.elements.length; i++) {
|
|
1693
|
+
allItems.push({ entry, elIdx: i });
|
|
1694
|
+
}
|
|
1695
|
+
}
|
|
1696
|
+
const used = /* @__PURE__ */ new Set();
|
|
1697
|
+
this.clusters = [];
|
|
1698
|
+
for (let i = 0; i < allItems.length; i++) {
|
|
1699
|
+
if (used.has(i)) continue;
|
|
1700
|
+
const cluster = {
|
|
1701
|
+
entries: [allItems[i].entry],
|
|
1702
|
+
elementIndices: [allItems[i].elIdx],
|
|
1703
|
+
expanded: false
|
|
1704
|
+
};
|
|
1705
|
+
used.add(i);
|
|
1706
|
+
for (let j = i + 1; j < allItems.length; j++) {
|
|
1707
|
+
if (used.has(j)) continue;
|
|
1708
|
+
const a = allItems[i].entry;
|
|
1709
|
+
const b = allItems[j].entry;
|
|
1710
|
+
const dist = Math.sqrt((a.baseLeft - b.baseLeft) ** 2 + (a.baseTop - b.baseTop) ** 2);
|
|
1711
|
+
if (dist < CLUSTER_DISTANCE) {
|
|
1712
|
+
cluster.entries.push(b);
|
|
1713
|
+
cluster.elementIndices.push(allItems[j].elIdx);
|
|
1714
|
+
used.add(j);
|
|
1715
|
+
}
|
|
1716
|
+
}
|
|
1717
|
+
this.clusters.push(cluster);
|
|
1718
|
+
}
|
|
1719
|
+
for (const cluster of this.clusters) {
|
|
1720
|
+
if (cluster.entries.length <= 1) continue;
|
|
1721
|
+
this.applyStackPositions(cluster);
|
|
1722
|
+
this.addClusterBadge(cluster);
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
applyStackPositions(cluster) {
|
|
1726
|
+
const { baseTop, baseLeft } = cluster.entries[0];
|
|
1727
|
+
const isSolo = cluster.entries.length <= 1;
|
|
1728
|
+
for (let i = 0; i < cluster.entries.length; i++) {
|
|
1729
|
+
const m = clusterMarker(cluster, i);
|
|
1730
|
+
if (!m) continue;
|
|
1731
|
+
m.style.top = `${baseTop + (isSolo ? 0 : i * 3)}px`;
|
|
1732
|
+
m.style.left = `${baseLeft + (isSolo ? 0 : i * 3)}px`;
|
|
1733
|
+
m.style.zIndex = String(i + 1);
|
|
1734
|
+
}
|
|
1735
|
+
}
|
|
1736
|
+
applyFanPositions(cluster) {
|
|
1737
|
+
const { baseTop, baseLeft } = cluster.entries[0];
|
|
1738
|
+
const count = cluster.entries.length;
|
|
1739
|
+
const totalWidth = (count - 1) * FAN_SPACING;
|
|
1740
|
+
const startLeft = baseLeft - totalWidth / 2;
|
|
1741
|
+
for (let i = 0; i < count; i++) {
|
|
1742
|
+
const m = clusterMarker(cluster, i);
|
|
1743
|
+
if (!m) continue;
|
|
1744
|
+
m.style.top = `${baseTop}px`;
|
|
1745
|
+
m.style.left = `${startLeft + i * FAN_SPACING}px`;
|
|
1746
|
+
m.style.zIndex = String(10 + i);
|
|
1747
|
+
}
|
|
1748
|
+
}
|
|
1749
|
+
addClusterBadge(cluster) {
|
|
1750
|
+
const topMarker = clusterMarker(cluster, cluster.entries.length - 1);
|
|
1751
|
+
if (!topMarker) return;
|
|
1752
|
+
const badge = el("div", {
|
|
1753
|
+
class: "sp-cluster-badge",
|
|
1754
|
+
style: `
|
|
1755
|
+
position:absolute;top:-6px;right:-6px;
|
|
1756
|
+
min-width:16px;height:16px;padding:0 4px;
|
|
1757
|
+
border-radius:9999px;
|
|
1758
|
+
background:${this.colors.accent};color:#fff;
|
|
1759
|
+
font-size:10px;font-weight:700;
|
|
1760
|
+
display:flex;align-items:center;justify-content:center;
|
|
1761
|
+
border:1.5px solid #fff;
|
|
1762
|
+
pointer-events:none;
|
|
1763
|
+
font-family:"Inter",system-ui,-apple-system,sans-serif;
|
|
1764
|
+
line-height:1;
|
|
1765
|
+
`
|
|
1766
|
+
});
|
|
1767
|
+
setText(badge, String(cluster.entries.length));
|
|
1768
|
+
topMarker.appendChild(badge);
|
|
1769
|
+
}
|
|
1770
|
+
setBadgesVisible(cluster, visible) {
|
|
1771
|
+
for (let i = 0; i < cluster.entries.length; i++) {
|
|
1772
|
+
const badge = clusterMarker(cluster, i)?.querySelector(".sp-cluster-badge");
|
|
1773
|
+
if (badge) badge.style.display = visible ? "flex" : "none";
|
|
1774
|
+
}
|
|
1775
|
+
}
|
|
1776
|
+
findCluster(marker) {
|
|
1777
|
+
for (const cluster of this.clusters) {
|
|
1778
|
+
if (cluster.entries.length <= 1) continue;
|
|
1779
|
+
for (let i = 0; i < cluster.entries.length; i++) {
|
|
1780
|
+
if (clusterMarker(cluster, i) === marker) return cluster;
|
|
1781
|
+
}
|
|
1782
|
+
}
|
|
1783
|
+
return null;
|
|
1784
|
+
}
|
|
1785
|
+
handleClusterClick(marker, e) {
|
|
1786
|
+
const cluster = this.findCluster(marker);
|
|
1787
|
+
if (!cluster) return false;
|
|
1788
|
+
if (!cluster.expanded) {
|
|
1789
|
+
e.stopPropagation();
|
|
1790
|
+
this.collapseAllClusters();
|
|
1791
|
+
cluster.expanded = true;
|
|
1792
|
+
this.applyFanPositions(cluster);
|
|
1793
|
+
this.setBadgesVisible(cluster, false);
|
|
1794
|
+
return true;
|
|
1795
|
+
}
|
|
1796
|
+
return false;
|
|
1797
|
+
}
|
|
1798
|
+
collapseCluster(cluster) {
|
|
1799
|
+
if (!cluster.expanded) return;
|
|
1800
|
+
cluster.expanded = false;
|
|
1801
|
+
this.applyStackPositions(cluster);
|
|
1802
|
+
this.setBadgesVisible(cluster, true);
|
|
1803
|
+
}
|
|
1804
|
+
collapseAllClusters() {
|
|
1805
|
+
for (const cluster of this.clusters) {
|
|
1806
|
+
this.collapseCluster(cluster);
|
|
1807
|
+
}
|
|
1808
|
+
}
|
|
1809
|
+
applyConfidenceStyle(marker, confidence, feedback) {
|
|
1810
|
+
const isResolved = feedback.status === "resolved";
|
|
1811
|
+
if (confidence < LOW_CONFIDENCE_THRESHOLD && !isResolved) {
|
|
1812
|
+
marker.style.borderStyle = "dashed";
|
|
1813
|
+
marker.style.opacity = "0.7";
|
|
1814
|
+
marker.title = `Position approximative (confiance : ${Math.round(confidence * 100)}%)`;
|
|
1815
|
+
} else {
|
|
1816
|
+
marker.style.borderStyle = "solid";
|
|
1817
|
+
marker.style.opacity = "1";
|
|
1818
|
+
marker.title = "";
|
|
1819
|
+
}
|
|
1820
|
+
}
|
|
1821
|
+
createMarker(number, feedback, pos) {
|
|
1822
|
+
const typeColor = getTypeColor(feedback.type, this.colors);
|
|
1823
|
+
const isResolved = feedback.status === "resolved";
|
|
1824
|
+
const marker = el("div", {
|
|
1825
|
+
style: `
|
|
1826
|
+
position:absolute;
|
|
1827
|
+
top:${pos.top}px;
|
|
1828
|
+
left:${pos.left}px;
|
|
1829
|
+
width:26px;height:26px;
|
|
1830
|
+
border-radius:50%;
|
|
1831
|
+
background:${isResolved ? "rgba(241,245,249,0.9)" : "rgba(255,255,255,0.92)"};
|
|
1832
|
+
backdrop-filter:blur(12px);
|
|
1833
|
+
-webkit-backdrop-filter:blur(12px);
|
|
1834
|
+
border:2px solid ${isResolved ? "#cbd5e1" : typeColor};
|
|
1835
|
+
display:flex;align-items:center;justify-content:center;
|
|
1836
|
+
font-family:"Inter",system-ui,-apple-system,sans-serif;
|
|
1837
|
+
font-size:11px;font-weight:700;
|
|
1838
|
+
color:${isResolved ? "#94a3b8" : typeColor};
|
|
1839
|
+
cursor:pointer;pointer-events:auto;
|
|
1840
|
+
box-shadow:${isResolved ? "0 2px 8px rgba(0,0,0,0.06)" : `0 2px 12px ${typeColor}25, 0 2px 6px rgba(0,0,0,0.06)`};
|
|
1841
|
+
transition:top 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), left 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), transform 0.15s ease, box-shadow 0.15s ease;
|
|
1842
|
+
user-select:none;
|
|
1843
|
+
-webkit-font-smoothing:antialiased;
|
|
1844
|
+
`
|
|
1845
|
+
});
|
|
1846
|
+
marker.dataset.feedbackId = feedback.id;
|
|
1847
|
+
setText(marker, isResolved ? "\u2713" : String(number));
|
|
1848
|
+
marker.addEventListener("mouseenter", () => {
|
|
1849
|
+
marker.style.transform = "scale(1.2)";
|
|
1850
|
+
marker.style.boxShadow = isResolved ? "0 4px 16px rgba(0,0,0,0.1)" : `0 4px 20px ${typeColor}35, 0 4px 12px rgba(0,0,0,0.08)`;
|
|
1851
|
+
this.tooltip.show(feedback, marker.getBoundingClientRect());
|
|
1852
|
+
if (!this.pinnedFeedback) this.showHighlight(feedback);
|
|
1853
|
+
});
|
|
1854
|
+
marker.addEventListener("mouseleave", () => {
|
|
1855
|
+
marker.style.transform = "scale(1)";
|
|
1856
|
+
marker.style.boxShadow = isResolved ? "0 2px 8px rgba(0,0,0,0.06)" : `0 2px 12px ${typeColor}25, 0 2px 6px rgba(0,0,0,0.06)`;
|
|
1857
|
+
this.tooltip.scheduleHide();
|
|
1858
|
+
if (!this.pinnedFeedback) this.clearHighlight();
|
|
1859
|
+
});
|
|
1860
|
+
marker.addEventListener("click", (e) => {
|
|
1861
|
+
if (this.handleClusterClick(marker, e)) return;
|
|
1862
|
+
this.pinHighlight(feedback);
|
|
1863
|
+
this.bus.emit("panel:toggle", true);
|
|
1864
|
+
marker.dispatchEvent(
|
|
1865
|
+
new CustomEvent("sp-marker-click", {
|
|
1866
|
+
detail: { feedbackId: feedback.id },
|
|
1867
|
+
bubbles: true
|
|
1868
|
+
})
|
|
1869
|
+
);
|
|
1870
|
+
});
|
|
1871
|
+
return marker;
|
|
1872
|
+
}
|
|
1873
|
+
highlight(feedbackId) {
|
|
1874
|
+
for (const entry of this.entries) {
|
|
1875
|
+
if (entry.feedback.id === feedbackId) {
|
|
1876
|
+
for (const markerEl of entry.elements) {
|
|
1877
|
+
markerEl.style.animation = "sp-pulse-ring 0.7s ease-out";
|
|
1878
|
+
markerEl.addEventListener(
|
|
1879
|
+
"animationend",
|
|
1880
|
+
() => {
|
|
1881
|
+
markerEl.style.animation = "";
|
|
1882
|
+
},
|
|
1883
|
+
{ once: true }
|
|
1884
|
+
);
|
|
1885
|
+
}
|
|
1886
|
+
}
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1889
|
+
showHighlight(feedback) {
|
|
1890
|
+
this.removeHighlightElements();
|
|
1891
|
+
for (const annotation of feedback.annotations) {
|
|
1892
|
+
const resolved = resolveAnnotation(toAnchorData(annotation), toRectData(annotation));
|
|
1893
|
+
if (!resolved) continue;
|
|
1894
|
+
const typeColor = getTypeColor(feedback.type, this.colors);
|
|
1895
|
+
const rect = resolved.rect;
|
|
1896
|
+
const highlight = el("div", {
|
|
1897
|
+
style: `
|
|
1898
|
+
position:absolute;
|
|
1899
|
+
top:${rect.top + window.scrollY}px;
|
|
1900
|
+
left:${rect.left + window.scrollX}px;
|
|
1901
|
+
width:${rect.width}px;height:${rect.height}px;
|
|
1902
|
+
border:2px solid ${typeColor};
|
|
1903
|
+
background:${typeColor}0c;
|
|
1904
|
+
border-radius:8px;
|
|
1905
|
+
pointer-events:none;z-index:-1;
|
|
1906
|
+
opacity:0;
|
|
1907
|
+
box-shadow:0 0 16px ${typeColor}20;
|
|
1908
|
+
transition:opacity ${HIGHLIGHT_FADE}ms ease;
|
|
1909
|
+
`
|
|
1910
|
+
});
|
|
1911
|
+
this.container.appendChild(highlight);
|
|
1912
|
+
this.highlightElements.push(highlight);
|
|
1913
|
+
highlight.offsetHeight;
|
|
1914
|
+
highlight.style.opacity = "1";
|
|
1915
|
+
}
|
|
1916
|
+
}
|
|
1917
|
+
pinHighlight(feedback) {
|
|
1918
|
+
this.unpinHighlight();
|
|
1919
|
+
this.showHighlight(feedback);
|
|
1920
|
+
this.pinnedFeedback = feedback;
|
|
1921
|
+
this.onDocumentClick = (e) => {
|
|
1922
|
+
if (this.container.contains(e.target)) return;
|
|
1923
|
+
this.unpinHighlight();
|
|
1924
|
+
};
|
|
1925
|
+
document.addEventListener("click", this.onDocumentClick, { capture: true });
|
|
1926
|
+
}
|
|
1927
|
+
unpinHighlight() {
|
|
1928
|
+
if (this.onDocumentClick) {
|
|
1929
|
+
document.removeEventListener("click", this.onDocumentClick, { capture: true });
|
|
1930
|
+
this.onDocumentClick = null;
|
|
1931
|
+
}
|
|
1932
|
+
this.pinnedFeedback = null;
|
|
1933
|
+
this.clearHighlight();
|
|
1934
|
+
}
|
|
1935
|
+
clearHighlight() {
|
|
1936
|
+
for (const h of this.highlightElements) {
|
|
1937
|
+
h.style.opacity = "0";
|
|
1938
|
+
setTimeout(() => h.remove(), HIGHLIGHT_FADE);
|
|
1939
|
+
}
|
|
1940
|
+
this.highlightElements = [];
|
|
1941
|
+
}
|
|
1942
|
+
removeHighlightElements() {
|
|
1943
|
+
for (const h of this.highlightElements) h.remove();
|
|
1944
|
+
this.highlightElements = [];
|
|
1945
|
+
}
|
|
1946
|
+
clear() {
|
|
1947
|
+
this.unpinHighlight();
|
|
1948
|
+
this.container.replaceChildren();
|
|
1949
|
+
this.entries = [];
|
|
1950
|
+
this.clusters = [];
|
|
1951
|
+
}
|
|
1952
|
+
destroy() {
|
|
1953
|
+
this.unpinHighlight();
|
|
1954
|
+
if (this.repositionTimer) clearTimeout(this.repositionTimer);
|
|
1955
|
+
if (this.resizeHandler) window.removeEventListener("resize", this.resizeHandler);
|
|
1956
|
+
if (this.onDocumentClickForClusters) document.removeEventListener("click", this.onDocumentClickForClusters);
|
|
1957
|
+
this.mutationObserver?.disconnect();
|
|
1958
|
+
this.container.remove();
|
|
1959
|
+
}
|
|
1960
|
+
};
|
|
1961
|
+
|
|
1962
|
+
// src/panel.ts
|
|
1963
|
+
var TYPE_LABELS = {
|
|
1964
|
+
question: "Question",
|
|
1965
|
+
changement: "Changement",
|
|
1966
|
+
bug: "Bug",
|
|
1967
|
+
autre: "Autre"
|
|
1968
|
+
};
|
|
1969
|
+
var Panel = class {
|
|
1970
|
+
constructor(shadowRoot, colors, bus, apiClient, projectName, markers) {
|
|
1971
|
+
this.colors = colors;
|
|
1972
|
+
this.bus = bus;
|
|
1973
|
+
this.apiClient = apiClient;
|
|
1974
|
+
this.projectName = projectName;
|
|
1975
|
+
this.markers = markers;
|
|
1976
|
+
this.root = el("div", { class: "sp-panel" });
|
|
1977
|
+
const header = el("div", { class: "sp-panel-header" });
|
|
1978
|
+
const title = el("span", { class: "sp-panel-title" });
|
|
1979
|
+
setText(title, "Feedbacks");
|
|
1980
|
+
const closeBtn = document.createElement("button");
|
|
1981
|
+
closeBtn.className = "sp-panel-close";
|
|
1982
|
+
closeBtn.setAttribute("aria-label", "Fermer le panneau");
|
|
1983
|
+
closeBtn.appendChild(parseSvg(ICON_CLOSE));
|
|
1984
|
+
closeBtn.addEventListener("click", () => this.close());
|
|
1985
|
+
this.deleteAllBtn = document.createElement("button");
|
|
1986
|
+
this.deleteAllBtn.className = "sp-btn-delete-all";
|
|
1987
|
+
this.deleteAllBtn.setAttribute("aria-label", "Tout supprimer");
|
|
1988
|
+
this.deleteAllBtn.appendChild(parseSvg(ICON_TRASH));
|
|
1989
|
+
const deleteAllLabel = document.createElement("span");
|
|
1990
|
+
setText(deleteAllLabel, " Tout supprimer");
|
|
1991
|
+
this.deleteAllBtn.appendChild(deleteAllLabel);
|
|
1992
|
+
this.deleteAllBtn.addEventListener("click", () => this.confirmDeleteAll());
|
|
1993
|
+
const headerRight = el("div", { class: "sp-panel-header-right" });
|
|
1994
|
+
headerRight.appendChild(this.deleteAllBtn);
|
|
1995
|
+
headerRight.appendChild(closeBtn);
|
|
1996
|
+
header.appendChild(title);
|
|
1997
|
+
header.appendChild(headerRight);
|
|
1998
|
+
const filters = el("div", { class: "sp-filters" });
|
|
1999
|
+
const searchWrap = el("div", { class: "sp-search-wrap" });
|
|
2000
|
+
const searchIcon = parseSvg(ICON_SEARCH);
|
|
2001
|
+
searchIcon.setAttribute("class", "sp-search-icon");
|
|
2002
|
+
this.searchInput = document.createElement("input");
|
|
2003
|
+
this.searchInput.type = "text";
|
|
2004
|
+
this.searchInput.className = "sp-search";
|
|
2005
|
+
this.searchInput.placeholder = "Rechercher...";
|
|
2006
|
+
this.searchInput.setAttribute("aria-label", "Rechercher dans les feedbacks");
|
|
2007
|
+
this.searchInput.addEventListener("input", () => {
|
|
2008
|
+
if (this.searchTimeout) clearTimeout(this.searchTimeout);
|
|
2009
|
+
this.searchTimeout = setTimeout(() => this.loadFeedbacks(), 200);
|
|
2010
|
+
});
|
|
2011
|
+
searchWrap.appendChild(searchIcon);
|
|
2012
|
+
searchWrap.appendChild(this.searchInput);
|
|
2013
|
+
const chips = el("div", { class: "sp-chips" });
|
|
2014
|
+
const chipOptions = [
|
|
2015
|
+
{ value: "all", label: "Tous" },
|
|
2016
|
+
{ value: "question", label: "Question" },
|
|
2017
|
+
{ value: "changement", label: "Changement" },
|
|
2018
|
+
{ value: "bug", label: "Bug" },
|
|
2019
|
+
{ value: "autre", label: "Autre" }
|
|
2020
|
+
];
|
|
2021
|
+
for (const option of chipOptions) {
|
|
2022
|
+
const chip = document.createElement("button");
|
|
2023
|
+
chip.className = `sp-chip ${option.value === "all" ? "sp-chip--active" : ""}`;
|
|
2024
|
+
if (option.value !== "all") {
|
|
2025
|
+
chip.style.borderColor = getTypeColor(option.value, this.colors);
|
|
2026
|
+
}
|
|
2027
|
+
setText(chip, option.label);
|
|
2028
|
+
chip.dataset.filter = option.value;
|
|
2029
|
+
chip.addEventListener("click", () => this.toggleFilter(option.value, chips));
|
|
2030
|
+
chips.appendChild(chip);
|
|
2031
|
+
}
|
|
2032
|
+
filters.appendChild(searchWrap);
|
|
2033
|
+
filters.appendChild(chips);
|
|
2034
|
+
this.listContainer = el("div", { class: "sp-list" });
|
|
2035
|
+
this.root.appendChild(header);
|
|
2036
|
+
this.root.appendChild(filters);
|
|
2037
|
+
this.root.appendChild(this.listContainer);
|
|
2038
|
+
shadowRoot.appendChild(this.root);
|
|
2039
|
+
this.bus.on("panel:toggle", (open) => {
|
|
2040
|
+
open ? this.open() : this.close();
|
|
2041
|
+
});
|
|
2042
|
+
shadowRoot.addEventListener("keydown", (e) => {
|
|
2043
|
+
if (e.key === "Escape" && this.isOpen) this.close();
|
|
2044
|
+
});
|
|
2045
|
+
this.onMarkerClick = ((e) => {
|
|
2046
|
+
this.scrollToFeedback(e.detail.feedbackId);
|
|
2047
|
+
});
|
|
2048
|
+
document.addEventListener("sp-marker-click", this.onMarkerClick);
|
|
2049
|
+
}
|
|
2050
|
+
colors;
|
|
2051
|
+
bus;
|
|
2052
|
+
apiClient;
|
|
2053
|
+
projectName;
|
|
2054
|
+
markers;
|
|
2055
|
+
root;
|
|
2056
|
+
listContainer;
|
|
2057
|
+
searchInput;
|
|
2058
|
+
deleteAllBtn;
|
|
2059
|
+
activeFilters = /* @__PURE__ */ new Set(["all"]);
|
|
2060
|
+
feedbacks = [];
|
|
2061
|
+
isOpen = false;
|
|
2062
|
+
searchTimeout = null;
|
|
2063
|
+
onMarkerClick;
|
|
2064
|
+
async open() {
|
|
2065
|
+
if (this.isOpen) return;
|
|
2066
|
+
this.isOpen = true;
|
|
2067
|
+
this.root.classList.add("sp-panel--open");
|
|
2068
|
+
this.bus.emit("open");
|
|
2069
|
+
await this.loadFeedbacks();
|
|
2070
|
+
}
|
|
2071
|
+
close() {
|
|
2072
|
+
if (!this.isOpen) return;
|
|
2073
|
+
this.isOpen = false;
|
|
2074
|
+
this.root.classList.remove("sp-panel--open");
|
|
2075
|
+
this.bus.emit("close");
|
|
2076
|
+
}
|
|
2077
|
+
showLoading() {
|
|
2078
|
+
this.listContainer.replaceChildren();
|
|
2079
|
+
const loading = el("div", { class: "sp-loading" });
|
|
2080
|
+
const spinner = el("div", { class: "sp-spinner" });
|
|
2081
|
+
loading.appendChild(spinner);
|
|
2082
|
+
this.listContainer.appendChild(loading);
|
|
2083
|
+
}
|
|
2084
|
+
showError() {
|
|
2085
|
+
this.listContainer.replaceChildren();
|
|
2086
|
+
const empty = el("div", { class: "sp-empty" });
|
|
2087
|
+
const text = el("div", { class: "sp-empty-text" });
|
|
2088
|
+
setText(text, "Erreur de chargement");
|
|
2089
|
+
const retryBtn = document.createElement("button");
|
|
2090
|
+
retryBtn.className = "sp-btn-ghost";
|
|
2091
|
+
retryBtn.style.marginTop = "8px";
|
|
2092
|
+
setText(retryBtn, "R\xE9essayer");
|
|
2093
|
+
retryBtn.addEventListener("click", () => this.loadFeedbacks());
|
|
2094
|
+
empty.appendChild(text);
|
|
2095
|
+
empty.appendChild(retryBtn);
|
|
2096
|
+
this.listContainer.appendChild(empty);
|
|
2097
|
+
}
|
|
2098
|
+
async loadFeedbacks() {
|
|
2099
|
+
const search = this.searchInput.value.trim() || void 0;
|
|
2100
|
+
const typeFilter = this.activeFilters.has("all") ? void 0 : Array.from(this.activeFilters)[0];
|
|
2101
|
+
const options = { limit: 50 };
|
|
2102
|
+
if (typeFilter) options.type = typeFilter;
|
|
2103
|
+
if (search) options.search = search;
|
|
2104
|
+
const hasContent = this.feedbacks.length > 0;
|
|
2105
|
+
if (!hasContent) this.showLoading();
|
|
2106
|
+
try {
|
|
2107
|
+
const { feedbacks } = await this.apiClient.getFeedbacks(this.projectName, options);
|
|
2108
|
+
this.feedbacks = feedbacks;
|
|
2109
|
+
this.renderList();
|
|
2110
|
+
this.markers.render(feedbacks);
|
|
2111
|
+
} catch (error) {
|
|
2112
|
+
if (!hasContent) this.showError();
|
|
2113
|
+
this.bus.emit("feedback:error", error instanceof Error ? error : new Error(String(error)));
|
|
2114
|
+
}
|
|
2115
|
+
}
|
|
2116
|
+
renderList() {
|
|
2117
|
+
this.listContainer.replaceChildren();
|
|
2118
|
+
if (this.feedbacks.length === 0) {
|
|
2119
|
+
const empty = el("div", { class: "sp-empty" });
|
|
2120
|
+
const emptyText = el("div", { class: "sp-empty-text" });
|
|
2121
|
+
setText(emptyText, "Aucun feedback pour le moment");
|
|
2122
|
+
empty.appendChild(emptyText);
|
|
2123
|
+
this.listContainer.appendChild(empty);
|
|
2124
|
+
return;
|
|
2125
|
+
}
|
|
2126
|
+
this.feedbacks.forEach((feedback, index2) => {
|
|
2127
|
+
const card = this.createCard(feedback, index2 + 1);
|
|
2128
|
+
card.style.setProperty("--sp-card-i", String(index2));
|
|
2129
|
+
this.listContainer.appendChild(card);
|
|
2130
|
+
});
|
|
2131
|
+
}
|
|
2132
|
+
createCard(feedback, number) {
|
|
2133
|
+
const isResolved = feedback.status === "resolved";
|
|
2134
|
+
const typeColor = getTypeColor(feedback.type, this.colors);
|
|
2135
|
+
const card = el("div", {
|
|
2136
|
+
class: `sp-card ${isResolved ? "sp-card--resolved" : ""}`
|
|
2137
|
+
});
|
|
2138
|
+
card.dataset.feedbackId = feedback.id;
|
|
2139
|
+
const bar = el("div", { class: "sp-card-bar" });
|
|
2140
|
+
bar.style.background = isResolved ? "#9ca3af" : typeColor;
|
|
2141
|
+
const body = el("div", { class: "sp-card-body" });
|
|
2142
|
+
const header = el("div", { class: "sp-card-header" });
|
|
2143
|
+
const num = el("span", { class: "sp-card-number" });
|
|
2144
|
+
setText(num, `#${number}`);
|
|
2145
|
+
const badge = el("span", { class: "sp-badge" });
|
|
2146
|
+
const typeBg = getTypeBgColor(feedback.type, this.colors);
|
|
2147
|
+
badge.style.background = typeBg;
|
|
2148
|
+
badge.style.color = typeColor;
|
|
2149
|
+
setText(badge, TYPE_LABELS[feedback.type] ?? feedback.type);
|
|
2150
|
+
const date = el("span", { class: "sp-card-date" });
|
|
2151
|
+
setText(date, formatRelativeDate(feedback.createdAt));
|
|
2152
|
+
header.appendChild(num);
|
|
2153
|
+
header.appendChild(badge);
|
|
2154
|
+
header.appendChild(date);
|
|
2155
|
+
const message = el("div", { class: "sp-card-message" });
|
|
2156
|
+
setText(message, feedback.message);
|
|
2157
|
+
const expandBtn = document.createElement("button");
|
|
2158
|
+
expandBtn.className = "sp-card-expand";
|
|
2159
|
+
setText(expandBtn, "Voir plus");
|
|
2160
|
+
expandBtn.style.display = "none";
|
|
2161
|
+
expandBtn.setAttribute("aria-expanded", "false");
|
|
2162
|
+
expandBtn.addEventListener("click", (e) => {
|
|
2163
|
+
e.stopPropagation();
|
|
2164
|
+
const isExpanded = message.classList.toggle("sp-card-message--expanded");
|
|
2165
|
+
setText(expandBtn, isExpanded ? "Voir moins" : "Voir plus");
|
|
2166
|
+
expandBtn.setAttribute("aria-expanded", String(isExpanded));
|
|
2167
|
+
});
|
|
2168
|
+
requestAnimationFrame(() => {
|
|
2169
|
+
if (message.scrollHeight > message.clientHeight) {
|
|
2170
|
+
expandBtn.style.display = "block";
|
|
2171
|
+
}
|
|
2172
|
+
});
|
|
2173
|
+
const footer = el("div", { class: "sp-card-footer" });
|
|
2174
|
+
const resolveBtn = document.createElement("button");
|
|
2175
|
+
resolveBtn.className = "sp-btn-resolve";
|
|
2176
|
+
if (isResolved) {
|
|
2177
|
+
resolveBtn.appendChild(parseSvg(ICON_UNDO));
|
|
2178
|
+
const span = document.createElement("span");
|
|
2179
|
+
setText(span, " Rouvrir");
|
|
2180
|
+
resolveBtn.appendChild(span);
|
|
2181
|
+
} else {
|
|
2182
|
+
resolveBtn.appendChild(parseSvg(ICON_CHECK));
|
|
2183
|
+
const span = document.createElement("span");
|
|
2184
|
+
setText(span, " R\xE9soudre");
|
|
2185
|
+
resolveBtn.appendChild(span);
|
|
2186
|
+
}
|
|
2187
|
+
resolveBtn.addEventListener("click", async (e) => {
|
|
2188
|
+
e.stopPropagation();
|
|
2189
|
+
await this.toggleResolve(feedback, resolveBtn);
|
|
2190
|
+
});
|
|
2191
|
+
const deleteBtn = document.createElement("button");
|
|
2192
|
+
deleteBtn.className = "sp-btn-delete";
|
|
2193
|
+
deleteBtn.appendChild(parseSvg(ICON_TRASH));
|
|
2194
|
+
const deleteLabel = document.createElement("span");
|
|
2195
|
+
setText(deleteLabel, " Supprimer");
|
|
2196
|
+
deleteBtn.appendChild(deleteLabel);
|
|
2197
|
+
deleteBtn.addEventListener("click", async (e) => {
|
|
2198
|
+
e.stopPropagation();
|
|
2199
|
+
await this.deleteFeedback(feedback, deleteBtn);
|
|
2200
|
+
});
|
|
2201
|
+
footer.appendChild(resolveBtn);
|
|
2202
|
+
footer.appendChild(deleteBtn);
|
|
2203
|
+
body.appendChild(header);
|
|
2204
|
+
body.appendChild(message);
|
|
2205
|
+
body.appendChild(expandBtn);
|
|
2206
|
+
body.appendChild(footer);
|
|
2207
|
+
card.appendChild(bar);
|
|
2208
|
+
card.appendChild(body);
|
|
2209
|
+
card.addEventListener("mouseenter", () => {
|
|
2210
|
+
this.markers.highlight(feedback.id);
|
|
2211
|
+
});
|
|
2212
|
+
card.addEventListener("click", () => {
|
|
2213
|
+
if (feedback.annotations.length > 0) {
|
|
2214
|
+
const ann = feedback.annotations[0];
|
|
2215
|
+
window.scrollTo({ left: ann.scrollX, top: ann.scrollY, behavior: "smooth" });
|
|
2216
|
+
this.markers.pinHighlight(feedback);
|
|
2217
|
+
}
|
|
2218
|
+
});
|
|
2219
|
+
return card;
|
|
2220
|
+
}
|
|
2221
|
+
async deleteFeedback(feedback, btn) {
|
|
2222
|
+
btn.disabled = true;
|
|
2223
|
+
try {
|
|
2224
|
+
await this.apiClient.deleteFeedback(feedback.id);
|
|
2225
|
+
this.bus.emit("feedback:deleted", feedback.id);
|
|
2226
|
+
await this.loadFeedbacks();
|
|
2227
|
+
} catch (error) {
|
|
2228
|
+
btn.disabled = false;
|
|
2229
|
+
this.bus.emit("feedback:error", error instanceof Error ? error : new Error(String(error)));
|
|
2230
|
+
}
|
|
2231
|
+
}
|
|
2232
|
+
async confirmDeleteAll() {
|
|
2233
|
+
const confirmed = await this.showConfirmDialog(
|
|
2234
|
+
"Tout supprimer",
|
|
2235
|
+
"Supprimer tous les feedbacks de ce projet ? Cette action est irr\xE9versible."
|
|
2236
|
+
);
|
|
2237
|
+
if (!confirmed) return;
|
|
2238
|
+
this.deleteAllBtn.disabled = true;
|
|
2239
|
+
try {
|
|
2240
|
+
await this.apiClient.deleteAllFeedbacks(this.projectName);
|
|
2241
|
+
this.bus.emit("feedback:all-deleted");
|
|
2242
|
+
await this.loadFeedbacks();
|
|
2243
|
+
} catch (error) {
|
|
2244
|
+
this.bus.emit("feedback:error", error instanceof Error ? error : new Error(String(error)));
|
|
2245
|
+
} finally {
|
|
2246
|
+
this.deleteAllBtn.disabled = false;
|
|
2247
|
+
}
|
|
2248
|
+
}
|
|
2249
|
+
showConfirmDialog(title, message) {
|
|
2250
|
+
return new Promise((resolve) => {
|
|
2251
|
+
const backdrop = el("div", { class: "sp-confirm-backdrop" });
|
|
2252
|
+
const titleId = `sp-confirm-title-${Date.now()}`;
|
|
2253
|
+
const messageId = `sp-confirm-msg-${Date.now()}`;
|
|
2254
|
+
const dialog = el("div", { class: "sp-confirm-dialog" });
|
|
2255
|
+
dialog.setAttribute("role", "alertdialog");
|
|
2256
|
+
dialog.setAttribute("aria-modal", "true");
|
|
2257
|
+
dialog.setAttribute("aria-labelledby", titleId);
|
|
2258
|
+
dialog.setAttribute("aria-describedby", messageId);
|
|
2259
|
+
const titleEl = el("div", { class: "sp-confirm-title" });
|
|
2260
|
+
titleEl.id = titleId;
|
|
2261
|
+
setText(titleEl, title);
|
|
2262
|
+
const messageEl = el("div", { class: "sp-confirm-message" });
|
|
2263
|
+
messageEl.id = messageId;
|
|
2264
|
+
setText(messageEl, message);
|
|
2265
|
+
const btnRow = el("div", { class: "sp-confirm-actions" });
|
|
2266
|
+
const cancelBtn = document.createElement("button");
|
|
2267
|
+
cancelBtn.type = "button";
|
|
2268
|
+
cancelBtn.className = "sp-btn-ghost";
|
|
2269
|
+
setText(cancelBtn, "Annuler");
|
|
2270
|
+
const confirmBtn = document.createElement("button");
|
|
2271
|
+
confirmBtn.type = "button";
|
|
2272
|
+
confirmBtn.className = "sp-btn-danger";
|
|
2273
|
+
setText(confirmBtn, "Supprimer");
|
|
2274
|
+
let closed = false;
|
|
2275
|
+
const close = (result) => {
|
|
2276
|
+
if (closed) return;
|
|
2277
|
+
closed = true;
|
|
2278
|
+
backdrop.removeEventListener("keydown", onKeydown);
|
|
2279
|
+
backdrop.style.opacity = "0";
|
|
2280
|
+
dialog.style.transform = "translateY(8px) scale(0.97)";
|
|
2281
|
+
setTimeout(() => {
|
|
2282
|
+
backdrop.remove();
|
|
2283
|
+
resolve(result);
|
|
2284
|
+
}, 200);
|
|
2285
|
+
};
|
|
2286
|
+
const onKeydown = (e) => {
|
|
2287
|
+
const ke = e;
|
|
2288
|
+
if (ke.key === "Escape") {
|
|
2289
|
+
close(false);
|
|
2290
|
+
return;
|
|
2291
|
+
}
|
|
2292
|
+
if (ke.key === "Tab") {
|
|
2293
|
+
ke.preventDefault();
|
|
2294
|
+
const active = backdrop.getRootNode().activeElement;
|
|
2295
|
+
if (active === cancelBtn) {
|
|
2296
|
+
confirmBtn.focus();
|
|
2297
|
+
} else {
|
|
2298
|
+
cancelBtn.focus();
|
|
2299
|
+
}
|
|
2300
|
+
}
|
|
2301
|
+
};
|
|
2302
|
+
backdrop.addEventListener("keydown", onKeydown);
|
|
2303
|
+
cancelBtn.addEventListener("click", () => close(false));
|
|
2304
|
+
confirmBtn.addEventListener("click", () => close(true));
|
|
2305
|
+
backdrop.addEventListener("click", (e) => {
|
|
2306
|
+
if (e.target === backdrop) close(false);
|
|
2307
|
+
});
|
|
2308
|
+
btnRow.appendChild(cancelBtn);
|
|
2309
|
+
btnRow.appendChild(confirmBtn);
|
|
2310
|
+
dialog.appendChild(titleEl);
|
|
2311
|
+
dialog.appendChild(messageEl);
|
|
2312
|
+
dialog.appendChild(btnRow);
|
|
2313
|
+
backdrop.appendChild(dialog);
|
|
2314
|
+
this.root.getRootNode() instanceof ShadowRoot ? this.root.getRootNode().appendChild(backdrop) : this.root.appendChild(backdrop);
|
|
2315
|
+
requestAnimationFrame(() => {
|
|
2316
|
+
backdrop.style.opacity = "1";
|
|
2317
|
+
dialog.style.transform = "translateY(0) scale(1)";
|
|
2318
|
+
cancelBtn.focus();
|
|
2319
|
+
});
|
|
2320
|
+
});
|
|
2321
|
+
}
|
|
2322
|
+
async toggleResolve(feedback, btn) {
|
|
2323
|
+
btn.disabled = true;
|
|
2324
|
+
try {
|
|
2325
|
+
const newResolved = feedback.status !== "resolved";
|
|
2326
|
+
await this.apiClient.resolveFeedback(feedback.id, newResolved);
|
|
2327
|
+
await this.loadFeedbacks();
|
|
2328
|
+
} catch (error) {
|
|
2329
|
+
btn.disabled = false;
|
|
2330
|
+
this.bus.emit("feedback:error", error instanceof Error ? error : new Error(String(error)));
|
|
2331
|
+
}
|
|
2332
|
+
}
|
|
2333
|
+
toggleFilter(value, container) {
|
|
2334
|
+
this.activeFilters.clear();
|
|
2335
|
+
this.activeFilters.add(value);
|
|
2336
|
+
const chips = container.querySelectorAll(".sp-chip");
|
|
2337
|
+
for (const chip of chips) {
|
|
2338
|
+
const isActive = this.activeFilters.has(chip.dataset.filter ?? "");
|
|
2339
|
+
chip.classList.toggle("sp-chip--active", isActive);
|
|
2340
|
+
}
|
|
2341
|
+
this.loadFeedbacks();
|
|
2342
|
+
}
|
|
2343
|
+
scrollToFeedback(feedbackId) {
|
|
2344
|
+
const escapedId = CSS.escape(feedbackId);
|
|
2345
|
+
const card = this.listContainer.querySelector(`[data-feedback-id="${escapedId}"]`);
|
|
2346
|
+
if (card) {
|
|
2347
|
+
card.scrollIntoView({ behavior: "smooth", block: "center" });
|
|
2348
|
+
card.classList.add("sp-anim-flash");
|
|
2349
|
+
card.addEventListener(
|
|
2350
|
+
"animationend",
|
|
2351
|
+
() => {
|
|
2352
|
+
card.classList.remove("sp-anim-flash");
|
|
2353
|
+
},
|
|
2354
|
+
{ once: true }
|
|
2355
|
+
);
|
|
2356
|
+
}
|
|
2357
|
+
}
|
|
2358
|
+
/** Refresh the panel after a new feedback is submitted */
|
|
2359
|
+
async refresh() {
|
|
2360
|
+
if (this.isOpen) {
|
|
2361
|
+
await this.loadFeedbacks();
|
|
2362
|
+
}
|
|
2363
|
+
}
|
|
2364
|
+
destroy() {
|
|
2365
|
+
if (this.searchTimeout) clearTimeout(this.searchTimeout);
|
|
2366
|
+
document.removeEventListener("sp-marker-click", this.onMarkerClick);
|
|
2367
|
+
this.root.remove();
|
|
2368
|
+
}
|
|
2369
|
+
};
|
|
2370
|
+
|
|
2371
|
+
// src/styles/animations.ts
|
|
2372
|
+
var SPRING_LINEAR = `linear(0, 0.006, 0.025, 0.06, 0.11, 0.17, 0.25, 0.34, 0.45, 0.56, 0.67, 0.78, 0.88, 0.95, 1.01, 1.04, 1.05, 1.04, 1.02, 1, 0.99, 1)`;
|
|
2373
|
+
var EASE_OUT_EXPO = `cubic-bezier(0.16, 1, 0.3, 1)`;
|
|
2374
|
+
var SPRING_OVERSHOOT = `cubic-bezier(0.34, 1.56, 0.64, 1)`;
|
|
2375
|
+
var EASE_OUT_QUART = `cubic-bezier(0.25, 1, 0.5, 1)`;
|
|
2376
|
+
var ANIMATION_CSS = `
|
|
2377
|
+
/* ---- Keyframes ---- */
|
|
2378
|
+
|
|
2379
|
+
@keyframes sp-fab-in {
|
|
2380
|
+
from {
|
|
2381
|
+
transform: scale(0) rotate(-180deg);
|
|
2382
|
+
opacity: 0;
|
|
2383
|
+
}
|
|
2384
|
+
to {
|
|
2385
|
+
transform: scale(1) rotate(0deg);
|
|
2386
|
+
opacity: 1;
|
|
2387
|
+
}
|
|
2388
|
+
}
|
|
2389
|
+
|
|
2390
|
+
@keyframes sp-fab-glow {
|
|
2391
|
+
0%, 100% { box-shadow: 0 4px 20px var(--sp-accent-glow), 0 2px 8px rgba(0, 0, 0, 0.08); }
|
|
2392
|
+
50% { box-shadow: 0 4px 28px var(--sp-accent-glow), 0 2px 12px rgba(0, 0, 0, 0.1); }
|
|
2393
|
+
}
|
|
2394
|
+
|
|
2395
|
+
@keyframes sp-marker-in {
|
|
2396
|
+
0% {
|
|
2397
|
+
transform: scale(0);
|
|
2398
|
+
opacity: 0;
|
|
2399
|
+
}
|
|
2400
|
+
60% {
|
|
2401
|
+
transform: scale(1.2);
|
|
2402
|
+
opacity: 1;
|
|
2403
|
+
}
|
|
2404
|
+
100% {
|
|
2405
|
+
transform: scale(1);
|
|
2406
|
+
}
|
|
2407
|
+
}
|
|
2408
|
+
|
|
2409
|
+
@keyframes sp-pulse-ring {
|
|
2410
|
+
0% {
|
|
2411
|
+
box-shadow: 0 0 0 0 var(--sp-accent-glow);
|
|
2412
|
+
}
|
|
2413
|
+
70% {
|
|
2414
|
+
box-shadow: 0 0 0 8px transparent;
|
|
2415
|
+
}
|
|
2416
|
+
100% {
|
|
2417
|
+
box-shadow: 0 0 0 0 transparent;
|
|
2418
|
+
}
|
|
2419
|
+
}
|
|
2420
|
+
|
|
2421
|
+
@keyframes sp-flash-bg {
|
|
2422
|
+
0% { background-color: var(--sp-accent-light); }
|
|
2423
|
+
100% { background-color: transparent; }
|
|
2424
|
+
}
|
|
2425
|
+
|
|
2426
|
+
@keyframes sp-slide-up {
|
|
2427
|
+
from {
|
|
2428
|
+
transform: translateY(8px);
|
|
2429
|
+
opacity: 0;
|
|
2430
|
+
}
|
|
2431
|
+
to {
|
|
2432
|
+
transform: translateY(0);
|
|
2433
|
+
opacity: 1;
|
|
2434
|
+
}
|
|
2435
|
+
}
|
|
2436
|
+
|
|
2437
|
+
@keyframes sp-fade-in {
|
|
2438
|
+
from { opacity: 0; }
|
|
2439
|
+
to { opacity: 1; }
|
|
2440
|
+
}
|
|
2441
|
+
|
|
2442
|
+
@keyframes sp-shimmer {
|
|
2443
|
+
0% { background-position: -200% 0; }
|
|
2444
|
+
100% { background-position: 200% 0; }
|
|
2445
|
+
}
|
|
2446
|
+
|
|
2447
|
+
/* ---- Animation classes ---- */
|
|
2448
|
+
|
|
2449
|
+
.sp-anim-fab-in {
|
|
2450
|
+
animation: sp-fab-in 0.5s ${SPRING_LINEAR} both;
|
|
2451
|
+
}
|
|
2452
|
+
|
|
2453
|
+
.sp-anim-marker-in {
|
|
2454
|
+
animation: sp-marker-in 0.35s ${SPRING_OVERSHOOT} both;
|
|
2455
|
+
}
|
|
2456
|
+
|
|
2457
|
+
.sp-anim-pulse {
|
|
2458
|
+
animation: sp-pulse-ring 0.7s ease-out;
|
|
2459
|
+
}
|
|
2460
|
+
|
|
2461
|
+
.sp-anim-flash {
|
|
2462
|
+
animation: sp-flash-bg 0.5s ${EASE_OUT_QUART};
|
|
2463
|
+
}
|
|
2464
|
+
|
|
2465
|
+
.sp-anim-slide-up {
|
|
2466
|
+
animation: sp-slide-up 0.3s ${EASE_OUT_EXPO} both;
|
|
2467
|
+
}
|
|
2468
|
+
|
|
2469
|
+
.sp-anim-fade-in {
|
|
2470
|
+
animation: sp-fade-in 0.2s ease-out both;
|
|
2471
|
+
}
|
|
2472
|
+
|
|
2473
|
+
/* ---- Transition utilities ---- */
|
|
2474
|
+
|
|
2475
|
+
.sp-panel {
|
|
2476
|
+
transform: translateX(110%);
|
|
2477
|
+
transition: transform 0.4s ${EASE_OUT_EXPO};
|
|
2478
|
+
}
|
|
2479
|
+
|
|
2480
|
+
.sp-panel.sp-panel--open {
|
|
2481
|
+
transform: translateX(0);
|
|
2482
|
+
}
|
|
2483
|
+
|
|
2484
|
+
.sp-radial-item {
|
|
2485
|
+
opacity: 0;
|
|
2486
|
+
pointer-events: none;
|
|
2487
|
+
transform: translate(0, 0) scale(0.8);
|
|
2488
|
+
transition:
|
|
2489
|
+
transform 0.35s ${SPRING_OVERSHOOT},
|
|
2490
|
+
opacity 0.2s ease,
|
|
2491
|
+
background 0.2s ease,
|
|
2492
|
+
border-color 0.2s ease,
|
|
2493
|
+
box-shadow 0.2s ease;
|
|
2494
|
+
}
|
|
2495
|
+
|
|
2496
|
+
.sp-radial-item.sp-radial-item--open {
|
|
2497
|
+
opacity: 1;
|
|
2498
|
+
pointer-events: auto;
|
|
2499
|
+
}
|
|
2500
|
+
|
|
2501
|
+
/* Stagger delay via CSS custom property --sp-i */
|
|
2502
|
+
.sp-radial-item {
|
|
2503
|
+
transition-delay: calc(var(--sp-i, 0) * 50ms);
|
|
2504
|
+
}
|
|
2505
|
+
|
|
2506
|
+
/* ---- Card stagger animation ---- */
|
|
2507
|
+
|
|
2508
|
+
@keyframes sp-card-in {
|
|
2509
|
+
from {
|
|
2510
|
+
transform: translateY(12px);
|
|
2511
|
+
opacity: 0;
|
|
2512
|
+
}
|
|
2513
|
+
to {
|
|
2514
|
+
transform: translateY(0);
|
|
2515
|
+
opacity: 1;
|
|
2516
|
+
}
|
|
2517
|
+
}
|
|
2518
|
+
|
|
2519
|
+
.sp-card {
|
|
2520
|
+
animation: sp-card-in 0.35s ${EASE_OUT_EXPO} both;
|
|
2521
|
+
animation-delay: calc(var(--sp-card-i, 0) * 40ms);
|
|
2522
|
+
}
|
|
2523
|
+
|
|
2524
|
+
/* ---- Loading spinner ---- */
|
|
2525
|
+
|
|
2526
|
+
@keyframes sp-spin {
|
|
2527
|
+
to { transform: rotate(360deg); }
|
|
2528
|
+
}
|
|
2529
|
+
|
|
2530
|
+
.sp-spinner {
|
|
2531
|
+
width: 20px;
|
|
2532
|
+
height: 20px;
|
|
2533
|
+
border: 2px solid var(--sp-border);
|
|
2534
|
+
border-top-color: var(--sp-accent);
|
|
2535
|
+
border-radius: 50%;
|
|
2536
|
+
animation: sp-spin 0.6s linear infinite;
|
|
2537
|
+
}
|
|
2538
|
+
|
|
2539
|
+
/* ---- Badge bounce ---- */
|
|
2540
|
+
|
|
2541
|
+
@keyframes sp-badge-in {
|
|
2542
|
+
0% { transform: scale(0); }
|
|
2543
|
+
60% { transform: scale(1.3); }
|
|
2544
|
+
100% { transform: scale(1); }
|
|
2545
|
+
}
|
|
2546
|
+
|
|
2547
|
+
.sp-fab-badge {
|
|
2548
|
+
animation: sp-badge-in 0.4s ${SPRING_OVERSHOOT} both;
|
|
2549
|
+
}
|
|
2550
|
+
|
|
2551
|
+
/* ---- Reduced motion ---- */
|
|
2552
|
+
|
|
2553
|
+
@media (prefers-reduced-motion: reduce) {
|
|
2554
|
+
*, *::before, *::after {
|
|
2555
|
+
animation-duration: 0.01ms !important;
|
|
2556
|
+
animation-iteration-count: 1 !important;
|
|
2557
|
+
transition-duration: 0.01ms !important;
|
|
2558
|
+
}
|
|
2559
|
+
}
|
|
2560
|
+
|
|
2561
|
+
`;
|
|
2562
|
+
|
|
2563
|
+
// src/styles/base.ts
|
|
2564
|
+
function buildStyles(colors) {
|
|
2565
|
+
return `
|
|
2566
|
+
:host {
|
|
2567
|
+
all: initial;
|
|
2568
|
+
position: fixed;
|
|
2569
|
+
z-index: 2147483647;
|
|
2570
|
+
font-family: var(--sp-font);
|
|
2571
|
+
font-size: 14px;
|
|
2572
|
+
line-height: 1.5;
|
|
2573
|
+
color: var(--sp-text);
|
|
2574
|
+
-webkit-font-smoothing: antialiased;
|
|
2575
|
+
-moz-osx-font-smoothing: grayscale;
|
|
2576
|
+
${cssVariables(colors)}
|
|
2577
|
+
}
|
|
2578
|
+
|
|
2579
|
+
*, *::before, *::after {
|
|
2580
|
+
box-sizing: border-box;
|
|
2581
|
+
margin: 0;
|
|
2582
|
+
padding: 0;
|
|
2583
|
+
}
|
|
2584
|
+
|
|
2585
|
+
/* ============================
|
|
2586
|
+
Focus visible (accessibility)
|
|
2587
|
+
============================ */
|
|
2588
|
+
|
|
2589
|
+
:focus-visible {
|
|
2590
|
+
outline: 2px solid var(--sp-accent);
|
|
2591
|
+
outline-offset: 2px;
|
|
2592
|
+
}
|
|
2593
|
+
|
|
2594
|
+
/* ============================
|
|
2595
|
+
FAB (Floating Action Button)
|
|
2596
|
+
============================ */
|
|
2597
|
+
|
|
2598
|
+
.sp-fab {
|
|
2599
|
+
position: fixed;
|
|
2600
|
+
width: 52px;
|
|
2601
|
+
height: 52px;
|
|
2602
|
+
border-radius: var(--sp-radius-full);
|
|
2603
|
+
background: var(--sp-accent-gradient);
|
|
2604
|
+
color: #fff;
|
|
2605
|
+
border: none;
|
|
2606
|
+
cursor: pointer;
|
|
2607
|
+
display: flex;
|
|
2608
|
+
align-items: center;
|
|
2609
|
+
justify-content: center;
|
|
2610
|
+
box-shadow:
|
|
2611
|
+
0 4px 20px var(--sp-accent-glow),
|
|
2612
|
+
0 2px 8px rgba(0, 0, 0, 0.08);
|
|
2613
|
+
transition:
|
|
2614
|
+
transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1),
|
|
2615
|
+
box-shadow 0.3s ease;
|
|
2616
|
+
outline: none;
|
|
2617
|
+
}
|
|
2618
|
+
|
|
2619
|
+
.sp-fab:focus-visible {
|
|
2620
|
+
outline: 2px solid #fff;
|
|
2621
|
+
outline-offset: 3px;
|
|
2622
|
+
}
|
|
2623
|
+
|
|
2624
|
+
.sp-fab:hover {
|
|
2625
|
+
transform: translateY(-2px) scale(1.05);
|
|
2626
|
+
box-shadow:
|
|
2627
|
+
0 8px 28px var(--sp-accent-glow),
|
|
2628
|
+
0 4px 12px rgba(0, 0, 0, 0.1);
|
|
2629
|
+
}
|
|
2630
|
+
|
|
2631
|
+
.sp-fab:active {
|
|
2632
|
+
transform: translateY(0) scale(0.95);
|
|
2633
|
+
transition-duration: 0.1s;
|
|
2634
|
+
}
|
|
2635
|
+
|
|
2636
|
+
.sp-fab--bottom-right {
|
|
2637
|
+
bottom: 24px;
|
|
2638
|
+
right: 24px;
|
|
2639
|
+
}
|
|
2640
|
+
|
|
2641
|
+
.sp-fab--bottom-left {
|
|
2642
|
+
bottom: 24px;
|
|
2643
|
+
left: 24px;
|
|
2644
|
+
}
|
|
2645
|
+
|
|
2646
|
+
.sp-fab svg {
|
|
2647
|
+
width: 22px;
|
|
2648
|
+
height: 22px;
|
|
2649
|
+
fill: currentColor;
|
|
2650
|
+
transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
|
|
2651
|
+
}
|
|
2652
|
+
|
|
2653
|
+
/* ---- FAB Badge ---- */
|
|
2654
|
+
|
|
2655
|
+
.sp-fab-badge {
|
|
2656
|
+
position: absolute;
|
|
2657
|
+
top: -4px;
|
|
2658
|
+
right: -4px;
|
|
2659
|
+
min-width: 20px;
|
|
2660
|
+
height: 20px;
|
|
2661
|
+
padding: 0 6px;
|
|
2662
|
+
border-radius: var(--sp-radius-full);
|
|
2663
|
+
background: #ef4444;
|
|
2664
|
+
color: #fff;
|
|
2665
|
+
font-size: 11px;
|
|
2666
|
+
font-weight: 700;
|
|
2667
|
+
display: flex;
|
|
2668
|
+
align-items: center;
|
|
2669
|
+
justify-content: center;
|
|
2670
|
+
border: 2px solid #fff;
|
|
2671
|
+
pointer-events: none;
|
|
2672
|
+
font-family: var(--sp-font);
|
|
2673
|
+
line-height: 1;
|
|
2674
|
+
}
|
|
2675
|
+
|
|
2676
|
+
/* ============================
|
|
2677
|
+
Radial Menu
|
|
2678
|
+
============================ */
|
|
2679
|
+
|
|
2680
|
+
.sp-radial {
|
|
2681
|
+
position: fixed;
|
|
2682
|
+
pointer-events: none;
|
|
2683
|
+
width: 52px;
|
|
2684
|
+
height: 52px;
|
|
2685
|
+
}
|
|
2686
|
+
|
|
2687
|
+
.sp-radial--bottom-right {
|
|
2688
|
+
bottom: 24px;
|
|
2689
|
+
right: 24px;
|
|
2690
|
+
}
|
|
2691
|
+
|
|
2692
|
+
.sp-radial--bottom-left {
|
|
2693
|
+
bottom: 24px;
|
|
2694
|
+
left: 24px;
|
|
2695
|
+
}
|
|
2696
|
+
|
|
2697
|
+
.sp-radial-item {
|
|
2698
|
+
position: absolute;
|
|
2699
|
+
left: 4px;
|
|
2700
|
+
bottom: 4px;
|
|
2701
|
+
width: 44px;
|
|
2702
|
+
height: 44px;
|
|
2703
|
+
border-radius: var(--sp-radius-full);
|
|
2704
|
+
background: var(--sp-glass-bg-heavy);
|
|
2705
|
+
backdrop-filter: blur(var(--sp-blur));
|
|
2706
|
+
-webkit-backdrop-filter: blur(var(--sp-blur));
|
|
2707
|
+
color: var(--sp-text);
|
|
2708
|
+
border: 1px solid var(--sp-glass-border);
|
|
2709
|
+
cursor: pointer;
|
|
2710
|
+
display: flex;
|
|
2711
|
+
align-items: center;
|
|
2712
|
+
justify-content: center;
|
|
2713
|
+
box-shadow: var(--sp-shadow-md);
|
|
2714
|
+
font-size: 12px;
|
|
2715
|
+
font-weight: 600;
|
|
2716
|
+
}
|
|
2717
|
+
|
|
2718
|
+
.sp-radial-item:hover,
|
|
2719
|
+
.sp-radial-item:focus-visible {
|
|
2720
|
+
background: rgba(255, 255, 255, 0.95);
|
|
2721
|
+
border-color: var(--sp-accent);
|
|
2722
|
+
color: var(--sp-accent);
|
|
2723
|
+
box-shadow:
|
|
2724
|
+
var(--sp-shadow-md),
|
|
2725
|
+
0 0 0 3px var(--sp-accent-light);
|
|
2726
|
+
outline: none;
|
|
2727
|
+
}
|
|
2728
|
+
|
|
2729
|
+
.sp-radial-item svg {
|
|
2730
|
+
width: 18px;
|
|
2731
|
+
height: 18px;
|
|
2732
|
+
flex-shrink: 0;
|
|
2733
|
+
stroke: currentColor;
|
|
2734
|
+
fill: none;
|
|
2735
|
+
}
|
|
2736
|
+
|
|
2737
|
+
.sp-radial-label {
|
|
2738
|
+
white-space: nowrap;
|
|
2739
|
+
font-size: 12px;
|
|
2740
|
+
font-weight: 500;
|
|
2741
|
+
color: var(--sp-text);
|
|
2742
|
+
pointer-events: none;
|
|
2743
|
+
opacity: 0;
|
|
2744
|
+
padding: 4px 12px;
|
|
2745
|
+
border-radius: var(--sp-radius);
|
|
2746
|
+
background: var(--sp-glass-bg-heavy);
|
|
2747
|
+
backdrop-filter: blur(12px);
|
|
2748
|
+
-webkit-backdrop-filter: blur(12px);
|
|
2749
|
+
border: 1px solid var(--sp-glass-border);
|
|
2750
|
+
box-shadow: var(--sp-shadow-sm);
|
|
2751
|
+
transform: translateX(4px);
|
|
2752
|
+
transition: opacity 0.2s ease, transform 0.2s ease;
|
|
2753
|
+
}
|
|
2754
|
+
|
|
2755
|
+
.sp-radial-item:hover .sp-radial-label,
|
|
2756
|
+
.sp-radial-item:focus-visible .sp-radial-label {
|
|
2757
|
+
opacity: 1;
|
|
2758
|
+
transform: translateX(0);
|
|
2759
|
+
}
|
|
2760
|
+
|
|
2761
|
+
/* ============================
|
|
2762
|
+
Panel (Side drawer)
|
|
2763
|
+
============================ */
|
|
2764
|
+
|
|
2765
|
+
.sp-panel {
|
|
2766
|
+
position: fixed;
|
|
2767
|
+
top: 0;
|
|
2768
|
+
right: 0;
|
|
2769
|
+
width: 400px;
|
|
2770
|
+
max-width: 100vw;
|
|
2771
|
+
height: 100vh;
|
|
2772
|
+
background: var(--sp-glass-bg);
|
|
2773
|
+
backdrop-filter: blur(var(--sp-blur-heavy));
|
|
2774
|
+
-webkit-backdrop-filter: blur(var(--sp-blur-heavy));
|
|
2775
|
+
border-left: 1px solid var(--sp-glass-border);
|
|
2776
|
+
box-shadow: var(--sp-shadow-xl);
|
|
2777
|
+
display: flex;
|
|
2778
|
+
flex-direction: column;
|
|
2779
|
+
overflow: hidden;
|
|
2780
|
+
}
|
|
2781
|
+
|
|
2782
|
+
@media (max-width: 480px) {
|
|
2783
|
+
.sp-panel {
|
|
2784
|
+
width: 100vw;
|
|
2785
|
+
border-left: none;
|
|
2786
|
+
}
|
|
2787
|
+
}
|
|
2788
|
+
|
|
2789
|
+
.sp-panel-header {
|
|
2790
|
+
display: flex;
|
|
2791
|
+
align-items: center;
|
|
2792
|
+
justify-content: space-between;
|
|
2793
|
+
padding: 20px 24px;
|
|
2794
|
+
border-bottom: 1px solid var(--sp-border);
|
|
2795
|
+
background: var(--sp-glass-bg-heavy);
|
|
2796
|
+
backdrop-filter: blur(var(--sp-blur));
|
|
2797
|
+
-webkit-backdrop-filter: blur(var(--sp-blur));
|
|
2798
|
+
}
|
|
2799
|
+
|
|
2800
|
+
.sp-panel-title {
|
|
2801
|
+
font-size: 17px;
|
|
2802
|
+
font-weight: 700;
|
|
2803
|
+
color: var(--sp-text);
|
|
2804
|
+
letter-spacing: -0.02em;
|
|
2805
|
+
}
|
|
2806
|
+
|
|
2807
|
+
.sp-panel-close {
|
|
2808
|
+
width: 32px;
|
|
2809
|
+
height: 32px;
|
|
2810
|
+
border-radius: var(--sp-radius);
|
|
2811
|
+
border: none;
|
|
2812
|
+
background: transparent;
|
|
2813
|
+
cursor: pointer;
|
|
2814
|
+
display: flex;
|
|
2815
|
+
align-items: center;
|
|
2816
|
+
justify-content: center;
|
|
2817
|
+
color: var(--sp-text-tertiary);
|
|
2818
|
+
transition: all 0.2s ease;
|
|
2819
|
+
}
|
|
2820
|
+
|
|
2821
|
+
.sp-panel-close:hover {
|
|
2822
|
+
background: var(--sp-bg-hover);
|
|
2823
|
+
color: var(--sp-text);
|
|
2824
|
+
}
|
|
2825
|
+
|
|
2826
|
+
.sp-panel-close svg {
|
|
2827
|
+
width: 16px;
|
|
2828
|
+
height: 16px;
|
|
2829
|
+
}
|
|
2830
|
+
|
|
2831
|
+
/* ============================
|
|
2832
|
+
Filters & Search
|
|
2833
|
+
============================ */
|
|
2834
|
+
|
|
2835
|
+
.sp-filters {
|
|
2836
|
+
padding: 16px 24px;
|
|
2837
|
+
border-bottom: 1px solid var(--sp-border);
|
|
2838
|
+
background: var(--sp-glass-bg-heavy);
|
|
2839
|
+
backdrop-filter: blur(var(--sp-blur));
|
|
2840
|
+
-webkit-backdrop-filter: blur(var(--sp-blur));
|
|
2841
|
+
position: sticky;
|
|
2842
|
+
top: 0;
|
|
2843
|
+
z-index: 1;
|
|
2844
|
+
}
|
|
2845
|
+
|
|
2846
|
+
.sp-search-wrap {
|
|
2847
|
+
position: relative;
|
|
2848
|
+
margin-bottom: 12px;
|
|
2849
|
+
}
|
|
2850
|
+
|
|
2851
|
+
.sp-search {
|
|
2852
|
+
width: 100%;
|
|
2853
|
+
height: 40px;
|
|
2854
|
+
padding: 0 12px 0 38px;
|
|
2855
|
+
border-radius: var(--sp-radius);
|
|
2856
|
+
border: 1px solid var(--sp-border);
|
|
2857
|
+
background: var(--sp-glass-bg-heavy);
|
|
2858
|
+
color: var(--sp-text);
|
|
2859
|
+
font-family: var(--sp-font);
|
|
2860
|
+
font-size: 13px;
|
|
2861
|
+
outline: none;
|
|
2862
|
+
transition: all 0.2s ease;
|
|
2863
|
+
}
|
|
2864
|
+
|
|
2865
|
+
.sp-search::placeholder {
|
|
2866
|
+
color: var(--sp-text-tertiary);
|
|
2867
|
+
}
|
|
2868
|
+
|
|
2869
|
+
.sp-search:focus {
|
|
2870
|
+
border-color: var(--sp-accent);
|
|
2871
|
+
box-shadow: 0 0 0 3px var(--sp-accent-light);
|
|
2872
|
+
background: #fff;
|
|
2873
|
+
}
|
|
2874
|
+
|
|
2875
|
+
.sp-search-icon {
|
|
2876
|
+
position: absolute;
|
|
2877
|
+
left: 12px;
|
|
2878
|
+
top: 50%;
|
|
2879
|
+
transform: translateY(-50%);
|
|
2880
|
+
color: var(--sp-text-tertiary);
|
|
2881
|
+
width: 16px;
|
|
2882
|
+
height: 16px;
|
|
2883
|
+
transition: color 0.2s ease;
|
|
2884
|
+
}
|
|
2885
|
+
|
|
2886
|
+
.sp-search:focus ~ .sp-search-icon,
|
|
2887
|
+
.sp-search-wrap:focus-within .sp-search-icon {
|
|
2888
|
+
color: var(--sp-accent);
|
|
2889
|
+
}
|
|
2890
|
+
|
|
2891
|
+
.sp-chips {
|
|
2892
|
+
display: flex;
|
|
2893
|
+
gap: 6px;
|
|
2894
|
+
flex-wrap: wrap;
|
|
2895
|
+
}
|
|
2896
|
+
|
|
2897
|
+
.sp-chip {
|
|
2898
|
+
padding: 5px 14px;
|
|
2899
|
+
border-radius: var(--sp-radius-full);
|
|
2900
|
+
border: 1px solid var(--sp-border);
|
|
2901
|
+
background: var(--sp-glass-bg-heavy);
|
|
2902
|
+
color: var(--sp-text-secondary);
|
|
2903
|
+
font-family: var(--sp-font);
|
|
2904
|
+
font-size: 12px;
|
|
2905
|
+
font-weight: 500;
|
|
2906
|
+
cursor: pointer;
|
|
2907
|
+
transition: all 0.2s ease;
|
|
2908
|
+
white-space: nowrap;
|
|
2909
|
+
letter-spacing: 0.01em;
|
|
2910
|
+
}
|
|
2911
|
+
|
|
2912
|
+
.sp-chip:hover {
|
|
2913
|
+
border-color: var(--sp-accent);
|
|
2914
|
+
color: var(--sp-accent);
|
|
2915
|
+
background: var(--sp-accent-light);
|
|
2916
|
+
}
|
|
2917
|
+
|
|
2918
|
+
.sp-chip--active {
|
|
2919
|
+
background: var(--sp-accent-gradient);
|
|
2920
|
+
border-color: transparent;
|
|
2921
|
+
color: #fff;
|
|
2922
|
+
box-shadow: 0 2px 8px var(--sp-accent-glow);
|
|
2923
|
+
}
|
|
2924
|
+
|
|
2925
|
+
.sp-chip--active:hover {
|
|
2926
|
+
background: var(--sp-accent-gradient);
|
|
2927
|
+
border-color: transparent;
|
|
2928
|
+
color: #fff;
|
|
2929
|
+
}
|
|
2930
|
+
|
|
2931
|
+
/* ============================
|
|
2932
|
+
Feedback Cards
|
|
2933
|
+
============================ */
|
|
2934
|
+
|
|
2935
|
+
.sp-list {
|
|
2936
|
+
flex: 1;
|
|
2937
|
+
overflow-y: auto;
|
|
2938
|
+
padding: 8px 12px;
|
|
2939
|
+
}
|
|
2940
|
+
|
|
2941
|
+
.sp-list::-webkit-scrollbar {
|
|
2942
|
+
width: 6px;
|
|
2943
|
+
}
|
|
2944
|
+
|
|
2945
|
+
.sp-list::-webkit-scrollbar-track {
|
|
2946
|
+
background: transparent;
|
|
2947
|
+
}
|
|
2948
|
+
|
|
2949
|
+
.sp-list::-webkit-scrollbar-thumb {
|
|
2950
|
+
background: var(--sp-border);
|
|
2951
|
+
border-radius: var(--sp-radius-full);
|
|
2952
|
+
}
|
|
2953
|
+
|
|
2954
|
+
.sp-list::-webkit-scrollbar-thumb:hover {
|
|
2955
|
+
background: var(--sp-text-tertiary);
|
|
2956
|
+
}
|
|
2957
|
+
|
|
2958
|
+
.sp-card {
|
|
2959
|
+
display: flex;
|
|
2960
|
+
padding: 14px 16px;
|
|
2961
|
+
margin-bottom: 6px;
|
|
2962
|
+
cursor: pointer;
|
|
2963
|
+
border-radius: var(--sp-radius);
|
|
2964
|
+
background: var(--sp-glass-bg-heavy);
|
|
2965
|
+
border: 1px solid var(--sp-glass-border);
|
|
2966
|
+
transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
|
|
2967
|
+
}
|
|
2968
|
+
|
|
2969
|
+
.sp-card:hover {
|
|
2970
|
+
background: #fff;
|
|
2971
|
+
border-color: var(--sp-border);
|
|
2972
|
+
box-shadow: var(--sp-shadow-md);
|
|
2973
|
+
transform: translateY(-2px);
|
|
2974
|
+
}
|
|
2975
|
+
|
|
2976
|
+
.sp-card:active {
|
|
2977
|
+
transform: translateY(0) scale(0.99);
|
|
2978
|
+
transition-duration: 0.1s;
|
|
2979
|
+
}
|
|
2980
|
+
|
|
2981
|
+
.sp-card-bar {
|
|
2982
|
+
width: 3px;
|
|
2983
|
+
border-radius: var(--sp-radius-full);
|
|
2984
|
+
margin-right: 14px;
|
|
2985
|
+
flex-shrink: 0;
|
|
2986
|
+
}
|
|
2987
|
+
|
|
2988
|
+
.sp-card-body {
|
|
2989
|
+
flex: 1;
|
|
2990
|
+
min-width: 0;
|
|
2991
|
+
}
|
|
2992
|
+
|
|
2993
|
+
.sp-card-header {
|
|
2994
|
+
display: flex;
|
|
2995
|
+
align-items: center;
|
|
2996
|
+
gap: 8px;
|
|
2997
|
+
margin-bottom: 6px;
|
|
2998
|
+
}
|
|
2999
|
+
|
|
3000
|
+
.sp-card-number {
|
|
3001
|
+
font-size: 12px;
|
|
3002
|
+
font-weight: 700;
|
|
3003
|
+
color: var(--sp-text-tertiary);
|
|
3004
|
+
font-variant-numeric: tabular-nums;
|
|
3005
|
+
}
|
|
3006
|
+
|
|
3007
|
+
.sp-badge {
|
|
3008
|
+
padding: 2px 10px;
|
|
3009
|
+
border-radius: var(--sp-radius-full);
|
|
3010
|
+
font-size: 11px;
|
|
3011
|
+
font-weight: 600;
|
|
3012
|
+
letter-spacing: 0.02em;
|
|
3013
|
+
}
|
|
3014
|
+
|
|
3015
|
+
.sp-card-date {
|
|
3016
|
+
font-size: 11px;
|
|
3017
|
+
color: var(--sp-text-tertiary);
|
|
3018
|
+
margin-left: auto;
|
|
3019
|
+
}
|
|
3020
|
+
|
|
3021
|
+
.sp-card-message {
|
|
3022
|
+
font-size: 13px;
|
|
3023
|
+
line-height: 1.5;
|
|
3024
|
+
color: var(--sp-text);
|
|
3025
|
+
display: -webkit-box;
|
|
3026
|
+
-webkit-line-clamp: 3;
|
|
3027
|
+
-webkit-box-orient: vertical;
|
|
3028
|
+
overflow: hidden;
|
|
3029
|
+
}
|
|
3030
|
+
|
|
3031
|
+
.sp-card-message--expanded {
|
|
3032
|
+
-webkit-line-clamp: unset;
|
|
3033
|
+
}
|
|
3034
|
+
|
|
3035
|
+
.sp-card-expand {
|
|
3036
|
+
font-size: 12px;
|
|
3037
|
+
font-weight: 500;
|
|
3038
|
+
color: var(--sp-accent);
|
|
3039
|
+
cursor: pointer;
|
|
3040
|
+
background: none;
|
|
3041
|
+
border: none;
|
|
3042
|
+
padding: 4px 0;
|
|
3043
|
+
font-family: var(--sp-font);
|
|
3044
|
+
transition: opacity 0.15s ease;
|
|
3045
|
+
}
|
|
3046
|
+
|
|
3047
|
+
.sp-card-expand:hover {
|
|
3048
|
+
opacity: 0.8;
|
|
3049
|
+
}
|
|
3050
|
+
|
|
3051
|
+
.sp-card-footer {
|
|
3052
|
+
display: flex;
|
|
3053
|
+
align-items: center;
|
|
3054
|
+
justify-content: flex-end;
|
|
3055
|
+
gap: 6px;
|
|
3056
|
+
margin-top: 10px;
|
|
3057
|
+
}
|
|
3058
|
+
|
|
3059
|
+
.sp-btn-resolve,
|
|
3060
|
+
.sp-btn-delete {
|
|
3061
|
+
padding: 5px 14px;
|
|
3062
|
+
border-radius: var(--sp-radius-full);
|
|
3063
|
+
border: 1px solid var(--sp-border);
|
|
3064
|
+
background: transparent;
|
|
3065
|
+
color: var(--sp-text-secondary);
|
|
3066
|
+
font-family: var(--sp-font);
|
|
3067
|
+
font-size: 12px;
|
|
3068
|
+
font-weight: 500;
|
|
3069
|
+
cursor: pointer;
|
|
3070
|
+
display: flex;
|
|
3071
|
+
align-items: center;
|
|
3072
|
+
gap: 4px;
|
|
3073
|
+
transition: all 0.2s ease;
|
|
3074
|
+
}
|
|
3075
|
+
|
|
3076
|
+
.sp-btn-resolve svg,
|
|
3077
|
+
.sp-btn-delete svg {
|
|
3078
|
+
width: 14px;
|
|
3079
|
+
height: 14px;
|
|
3080
|
+
}
|
|
3081
|
+
|
|
3082
|
+
.sp-btn-resolve:hover {
|
|
3083
|
+
border-color: #22c55e;
|
|
3084
|
+
color: #22c55e;
|
|
3085
|
+
background: rgba(34, 197, 94, 0.06);
|
|
3086
|
+
}
|
|
3087
|
+
|
|
3088
|
+
.sp-btn-delete:hover {
|
|
3089
|
+
border-color: #ef4444;
|
|
3090
|
+
color: #ef4444;
|
|
3091
|
+
background: rgba(239, 68, 68, 0.06);
|
|
3092
|
+
}
|
|
3093
|
+
|
|
3094
|
+
.sp-btn-resolve:disabled,
|
|
3095
|
+
.sp-btn-delete:disabled {
|
|
3096
|
+
opacity: 0.5;
|
|
3097
|
+
cursor: not-allowed;
|
|
3098
|
+
pointer-events: none;
|
|
3099
|
+
}
|
|
3100
|
+
|
|
3101
|
+
/* ---- Delete All (header) ---- */
|
|
3102
|
+
|
|
3103
|
+
.sp-panel-header-right {
|
|
3104
|
+
display: flex;
|
|
3105
|
+
align-items: center;
|
|
3106
|
+
gap: 8px;
|
|
3107
|
+
}
|
|
3108
|
+
|
|
3109
|
+
.sp-btn-delete-all {
|
|
3110
|
+
padding: 5px 12px;
|
|
3111
|
+
border-radius: var(--sp-radius-full);
|
|
3112
|
+
border: 1px solid var(--sp-border);
|
|
3113
|
+
background: transparent;
|
|
3114
|
+
color: var(--sp-text-tertiary);
|
|
3115
|
+
font-family: var(--sp-font);
|
|
3116
|
+
font-size: 11px;
|
|
3117
|
+
font-weight: 500;
|
|
3118
|
+
cursor: pointer;
|
|
3119
|
+
display: flex;
|
|
3120
|
+
align-items: center;
|
|
3121
|
+
gap: 4px;
|
|
3122
|
+
transition: all 0.2s ease;
|
|
3123
|
+
}
|
|
3124
|
+
|
|
3125
|
+
.sp-btn-delete-all svg {
|
|
3126
|
+
width: 13px;
|
|
3127
|
+
height: 13px;
|
|
3128
|
+
}
|
|
3129
|
+
|
|
3130
|
+
.sp-btn-delete-all:hover {
|
|
3131
|
+
border-color: #ef4444;
|
|
3132
|
+
color: #ef4444;
|
|
3133
|
+
background: rgba(239, 68, 68, 0.06);
|
|
3134
|
+
}
|
|
3135
|
+
|
|
3136
|
+
.sp-btn-delete-all:disabled {
|
|
3137
|
+
opacity: 0.5;
|
|
3138
|
+
cursor: not-allowed;
|
|
3139
|
+
pointer-events: none;
|
|
3140
|
+
}
|
|
3141
|
+
|
|
3142
|
+
/* ---- Confirm Dialog ---- */
|
|
3143
|
+
|
|
3144
|
+
.sp-confirm-backdrop {
|
|
3145
|
+
position: fixed;
|
|
3146
|
+
inset: 0;
|
|
3147
|
+
background: var(--sp-backdrop, rgba(15, 23, 42, 0.2));
|
|
3148
|
+
backdrop-filter: blur(var(--sp-blur));
|
|
3149
|
+
-webkit-backdrop-filter: blur(var(--sp-blur));
|
|
3150
|
+
display: flex;
|
|
3151
|
+
align-items: center;
|
|
3152
|
+
justify-content: center;
|
|
3153
|
+
z-index: 2147483647;
|
|
3154
|
+
opacity: 0;
|
|
3155
|
+
transition: opacity 0.2s ease;
|
|
3156
|
+
}
|
|
3157
|
+
|
|
3158
|
+
.sp-confirm-dialog {
|
|
3159
|
+
width: 340px;
|
|
3160
|
+
padding: 28px;
|
|
3161
|
+
border-radius: 20px;
|
|
3162
|
+
background: var(--sp-glass-bg-heavy);
|
|
3163
|
+
backdrop-filter: blur(var(--sp-blur-heavy));
|
|
3164
|
+
-webkit-backdrop-filter: blur(var(--sp-blur-heavy));
|
|
3165
|
+
border: 1px solid var(--sp-glass-border);
|
|
3166
|
+
box-shadow: var(--sp-shadow-xl);
|
|
3167
|
+
font-family: var(--sp-font);
|
|
3168
|
+
transform: translateY(8px) scale(0.97);
|
|
3169
|
+
transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
|
|
3170
|
+
}
|
|
3171
|
+
|
|
3172
|
+
.sp-confirm-title {
|
|
3173
|
+
font-size: 17px;
|
|
3174
|
+
font-weight: 700;
|
|
3175
|
+
color: var(--sp-text);
|
|
3176
|
+
letter-spacing: -0.02em;
|
|
3177
|
+
margin-bottom: 8px;
|
|
3178
|
+
}
|
|
3179
|
+
|
|
3180
|
+
.sp-confirm-message {
|
|
3181
|
+
font-size: 14px;
|
|
3182
|
+
color: var(--sp-text-secondary);
|
|
3183
|
+
line-height: 1.5;
|
|
3184
|
+
margin-bottom: 20px;
|
|
3185
|
+
}
|
|
3186
|
+
|
|
3187
|
+
.sp-confirm-actions {
|
|
3188
|
+
display: flex;
|
|
3189
|
+
gap: 8px;
|
|
3190
|
+
justify-content: flex-end;
|
|
3191
|
+
}
|
|
3192
|
+
|
|
3193
|
+
.sp-btn-danger {
|
|
3194
|
+
height: 40px;
|
|
3195
|
+
padding: 0 22px;
|
|
3196
|
+
border-radius: var(--sp-radius);
|
|
3197
|
+
border: none;
|
|
3198
|
+
background: #ef4444;
|
|
3199
|
+
color: #fff;
|
|
3200
|
+
font-family: var(--sp-font);
|
|
3201
|
+
font-size: 14px;
|
|
3202
|
+
font-weight: 600;
|
|
3203
|
+
cursor: pointer;
|
|
3204
|
+
transition: all 0.2s ease;
|
|
3205
|
+
box-shadow: 0 2px 8px rgba(239, 68, 68, 0.25);
|
|
3206
|
+
}
|
|
3207
|
+
|
|
3208
|
+
.sp-btn-danger:hover {
|
|
3209
|
+
background: #dc2626;
|
|
3210
|
+
box-shadow: 0 4px 16px rgba(239, 68, 68, 0.3);
|
|
3211
|
+
transform: translateY(-1px);
|
|
3212
|
+
}
|
|
3213
|
+
|
|
3214
|
+
.sp-btn-danger:active {
|
|
3215
|
+
transform: translateY(0) scale(0.98);
|
|
3216
|
+
transition-duration: 0.1s;
|
|
3217
|
+
}
|
|
3218
|
+
|
|
3219
|
+
.sp-card--resolved {
|
|
3220
|
+
opacity: 0.5;
|
|
3221
|
+
}
|
|
3222
|
+
|
|
3223
|
+
.sp-card--resolved .sp-card-message {
|
|
3224
|
+
text-decoration: line-through;
|
|
3225
|
+
text-decoration-color: var(--sp-text-tertiary);
|
|
3226
|
+
}
|
|
3227
|
+
|
|
3228
|
+
/* ============================
|
|
3229
|
+
Loading State
|
|
3230
|
+
============================ */
|
|
3231
|
+
|
|
3232
|
+
.sp-loading {
|
|
3233
|
+
display: flex;
|
|
3234
|
+
align-items: center;
|
|
3235
|
+
justify-content: center;
|
|
3236
|
+
padding: 48px 24px;
|
|
3237
|
+
}
|
|
3238
|
+
|
|
3239
|
+
/* ============================
|
|
3240
|
+
Identity Form
|
|
3241
|
+
============================ */
|
|
3242
|
+
|
|
3243
|
+
.sp-identity-title {
|
|
3244
|
+
font-size: 17px;
|
|
3245
|
+
font-weight: 700;
|
|
3246
|
+
color: var(--sp-text);
|
|
3247
|
+
letter-spacing: -0.02em;
|
|
3248
|
+
}
|
|
3249
|
+
|
|
3250
|
+
.sp-input {
|
|
3251
|
+
width: 100%;
|
|
3252
|
+
height: 42px;
|
|
3253
|
+
padding: 0 14px;
|
|
3254
|
+
border-radius: var(--sp-radius);
|
|
3255
|
+
border: 1px solid var(--sp-border);
|
|
3256
|
+
background: var(--sp-glass-bg-heavy);
|
|
3257
|
+
color: var(--sp-text);
|
|
3258
|
+
font-family: var(--sp-font);
|
|
3259
|
+
font-size: 14px;
|
|
3260
|
+
outline: none;
|
|
3261
|
+
transition: all 0.2s ease;
|
|
3262
|
+
}
|
|
3263
|
+
|
|
3264
|
+
.sp-input::placeholder {
|
|
3265
|
+
color: var(--sp-text-tertiary);
|
|
3266
|
+
}
|
|
3267
|
+
|
|
3268
|
+
.sp-input:focus {
|
|
3269
|
+
border-color: var(--sp-accent);
|
|
3270
|
+
box-shadow: 0 0 0 3px var(--sp-accent-light);
|
|
3271
|
+
background: #fff;
|
|
3272
|
+
}
|
|
3273
|
+
|
|
3274
|
+
.sp-input-label {
|
|
3275
|
+
font-size: 13px;
|
|
3276
|
+
font-weight: 500;
|
|
3277
|
+
color: var(--sp-text-secondary);
|
|
3278
|
+
margin-bottom: 6px;
|
|
3279
|
+
display: block;
|
|
3280
|
+
}
|
|
3281
|
+
|
|
3282
|
+
/* ============================
|
|
3283
|
+
Buttons
|
|
3284
|
+
============================ */
|
|
3285
|
+
|
|
3286
|
+
.sp-btn-primary {
|
|
3287
|
+
height: 40px;
|
|
3288
|
+
padding: 0 22px;
|
|
3289
|
+
border-radius: var(--sp-radius);
|
|
3290
|
+
border: none;
|
|
3291
|
+
background: var(--sp-accent-gradient);
|
|
3292
|
+
color: #fff;
|
|
3293
|
+
font-family: var(--sp-font);
|
|
3294
|
+
font-size: 14px;
|
|
3295
|
+
font-weight: 600;
|
|
3296
|
+
cursor: pointer;
|
|
3297
|
+
transition: all 0.2s ease;
|
|
3298
|
+
box-shadow: 0 2px 8px var(--sp-accent-glow);
|
|
3299
|
+
}
|
|
3300
|
+
|
|
3301
|
+
.sp-btn-primary:hover {
|
|
3302
|
+
box-shadow: 0 4px 16px var(--sp-accent-glow);
|
|
3303
|
+
transform: translateY(-1px);
|
|
3304
|
+
}
|
|
3305
|
+
|
|
3306
|
+
.sp-btn-primary:active {
|
|
3307
|
+
transform: translateY(0) scale(0.98);
|
|
3308
|
+
transition-duration: 0.1s;
|
|
3309
|
+
}
|
|
3310
|
+
|
|
3311
|
+
.sp-btn-primary:disabled {
|
|
3312
|
+
opacity: 0.4;
|
|
3313
|
+
cursor: not-allowed;
|
|
3314
|
+
transform: none;
|
|
3315
|
+
box-shadow: none;
|
|
3316
|
+
}
|
|
3317
|
+
|
|
3318
|
+
.sp-btn-ghost {
|
|
3319
|
+
height: 40px;
|
|
3320
|
+
padding: 0 22px;
|
|
3321
|
+
border-radius: var(--sp-radius);
|
|
3322
|
+
border: 1px solid var(--sp-border);
|
|
3323
|
+
background: var(--sp-glass-bg-heavy);
|
|
3324
|
+
color: var(--sp-text-secondary);
|
|
3325
|
+
font-family: var(--sp-font);
|
|
3326
|
+
font-size: 14px;
|
|
3327
|
+
font-weight: 500;
|
|
3328
|
+
cursor: pointer;
|
|
3329
|
+
transition: all 0.2s ease;
|
|
3330
|
+
}
|
|
3331
|
+
|
|
3332
|
+
.sp-btn-ghost:hover {
|
|
3333
|
+
border-color: var(--sp-accent);
|
|
3334
|
+
color: var(--sp-accent);
|
|
3335
|
+
background: var(--sp-accent-light);
|
|
3336
|
+
}
|
|
3337
|
+
|
|
3338
|
+
/* ============================
|
|
3339
|
+
Empty State
|
|
3340
|
+
============================ */
|
|
3341
|
+
|
|
3342
|
+
.sp-empty {
|
|
3343
|
+
display: flex;
|
|
3344
|
+
flex-direction: column;
|
|
3345
|
+
align-items: center;
|
|
3346
|
+
justify-content: center;
|
|
3347
|
+
padding: 56px 24px;
|
|
3348
|
+
color: var(--sp-text-tertiary);
|
|
3349
|
+
text-align: center;
|
|
3350
|
+
gap: 8px;
|
|
3351
|
+
animation: sp-fade-in 0.3s ease-out both;
|
|
3352
|
+
}
|
|
3353
|
+
|
|
3354
|
+
.sp-empty-text {
|
|
3355
|
+
font-size: 14px;
|
|
3356
|
+
font-weight: 500;
|
|
3357
|
+
}
|
|
3358
|
+
|
|
3359
|
+
${ANIMATION_CSS}
|
|
3360
|
+
`;
|
|
3361
|
+
}
|
|
3362
|
+
|
|
3363
|
+
// src/tooltip.ts
|
|
3364
|
+
var SHOW_DELAY = 120;
|
|
3365
|
+
var HIDE_DELAY = 80;
|
|
3366
|
+
var Tooltip = class {
|
|
3367
|
+
constructor(colors) {
|
|
3368
|
+
this.colors = colors;
|
|
3369
|
+
this.root = el("div", {
|
|
3370
|
+
style: `
|
|
3371
|
+
position: fixed;
|
|
3372
|
+
z-index: 2147483647;
|
|
3373
|
+
max-width: 280px;
|
|
3374
|
+
padding: 12px 14px;
|
|
3375
|
+
border-radius: 14px;
|
|
3376
|
+
background: rgba(255, 255, 255, 0.88);
|
|
3377
|
+
backdrop-filter: blur(24px);
|
|
3378
|
+
-webkit-backdrop-filter: blur(24px);
|
|
3379
|
+
border: 1px solid rgba(255, 255, 255, 0.35);
|
|
3380
|
+
box-shadow: 0 8px 32px rgba(0,0,0,0.1), 0 2px 8px rgba(0,0,0,0.04);
|
|
3381
|
+
font-family: "Inter", system-ui, -apple-system, sans-serif;
|
|
3382
|
+
pointer-events: auto;
|
|
3383
|
+
opacity: 0;
|
|
3384
|
+
transform: translateY(6px) scale(0.97);
|
|
3385
|
+
transition: opacity 0.2s cubic-bezier(0.16, 1, 0.3, 1), transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
|
|
3386
|
+
visibility: hidden;
|
|
3387
|
+
-webkit-font-smoothing: antialiased;
|
|
3388
|
+
`
|
|
3389
|
+
});
|
|
3390
|
+
this.arrow = el("div", {
|
|
3391
|
+
style: `
|
|
3392
|
+
position: absolute;
|
|
3393
|
+
width: 12px;
|
|
3394
|
+
height: 12px;
|
|
3395
|
+
background: rgba(255, 255, 255, 0.88);
|
|
3396
|
+
border: 1px solid rgba(255, 255, 255, 0.35);
|
|
3397
|
+
transform: rotate(45deg);
|
|
3398
|
+
pointer-events: none;
|
|
3399
|
+
`
|
|
3400
|
+
});
|
|
3401
|
+
this.root.appendChild(this.arrow);
|
|
3402
|
+
this.root.addEventListener("mouseenter", () => this.cancelHide());
|
|
3403
|
+
this.root.addEventListener("mouseleave", () => this.scheduleHide());
|
|
3404
|
+
document.body.appendChild(this.root);
|
|
3405
|
+
}
|
|
3406
|
+
colors;
|
|
3407
|
+
root;
|
|
3408
|
+
arrow;
|
|
3409
|
+
showTimer = null;
|
|
3410
|
+
hideTimer = null;
|
|
3411
|
+
currentFeedbackId = null;
|
|
3412
|
+
show(feedback, anchorRect) {
|
|
3413
|
+
if (this.currentFeedbackId === feedback.id) return;
|
|
3414
|
+
this.cancelHide();
|
|
3415
|
+
this.cancelShow();
|
|
3416
|
+
this.showTimer = setTimeout(() => {
|
|
3417
|
+
this.currentFeedbackId = feedback.id;
|
|
3418
|
+
this.render(feedback);
|
|
3419
|
+
this.position(anchorRect);
|
|
3420
|
+
this.root.style.visibility = "visible";
|
|
3421
|
+
this.root.style.opacity = "1";
|
|
3422
|
+
this.root.style.transform = "translateY(0) scale(1)";
|
|
3423
|
+
}, SHOW_DELAY);
|
|
3424
|
+
}
|
|
3425
|
+
scheduleHide() {
|
|
3426
|
+
this.cancelHide();
|
|
3427
|
+
this.hideTimer = setTimeout(() => this.hide(), HIDE_DELAY);
|
|
3428
|
+
}
|
|
3429
|
+
hide() {
|
|
3430
|
+
this.cancelShow();
|
|
3431
|
+
this.currentFeedbackId = null;
|
|
3432
|
+
this.root.style.opacity = "0";
|
|
3433
|
+
this.root.style.transform = "translateY(6px) scale(0.97)";
|
|
3434
|
+
setTimeout(() => {
|
|
3435
|
+
if (!this.currentFeedbackId) {
|
|
3436
|
+
this.root.style.visibility = "hidden";
|
|
3437
|
+
}
|
|
3438
|
+
}, 200);
|
|
3439
|
+
}
|
|
3440
|
+
cancelShow() {
|
|
3441
|
+
if (this.showTimer) {
|
|
3442
|
+
clearTimeout(this.showTimer);
|
|
3443
|
+
this.showTimer = null;
|
|
3444
|
+
}
|
|
3445
|
+
}
|
|
3446
|
+
cancelHide() {
|
|
3447
|
+
if (this.hideTimer) {
|
|
3448
|
+
clearTimeout(this.hideTimer);
|
|
3449
|
+
this.hideTimer = null;
|
|
3450
|
+
}
|
|
3451
|
+
}
|
|
3452
|
+
render(feedback) {
|
|
3453
|
+
const children = Array.from(this.root.children);
|
|
3454
|
+
for (const child of children) {
|
|
3455
|
+
if (child !== this.arrow) child.remove();
|
|
3456
|
+
}
|
|
3457
|
+
const typeColor = getTypeColor(feedback.type, this.colors);
|
|
3458
|
+
const typeBg = getTypeBgColor(feedback.type, this.colors);
|
|
3459
|
+
const typeLabel = feedback.type.charAt(0).toUpperCase() + feedback.type.slice(1);
|
|
3460
|
+
const header = el("div", { style: "display:flex;align-items:center;gap:8px;margin-bottom:8px;" });
|
|
3461
|
+
const badge = el("span", {
|
|
3462
|
+
style: `
|
|
3463
|
+
padding:3px 10px;border-radius:9999px;
|
|
3464
|
+
font-size:11px;font-weight:600;
|
|
3465
|
+
color:${typeColor};background:${typeBg};
|
|
3466
|
+
letter-spacing:0.02em;
|
|
3467
|
+
`
|
|
3468
|
+
});
|
|
3469
|
+
setText(badge, typeLabel);
|
|
3470
|
+
const date = el("span", { style: "font-size:11px;color:#64748b;margin-left:auto;" });
|
|
3471
|
+
setText(date, formatRelativeDate(feedback.createdAt));
|
|
3472
|
+
header.appendChild(badge);
|
|
3473
|
+
header.appendChild(date);
|
|
3474
|
+
const body = el("div", {
|
|
3475
|
+
style: "font-size:13px;line-height:1.55;color:#0f172a;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;"
|
|
3476
|
+
});
|
|
3477
|
+
setText(body, feedback.message);
|
|
3478
|
+
this.root.insertBefore(header, this.arrow);
|
|
3479
|
+
this.root.insertBefore(body, this.arrow);
|
|
3480
|
+
}
|
|
3481
|
+
position(anchorRect) {
|
|
3482
|
+
const tooltipRect = this.root.getBoundingClientRect();
|
|
3483
|
+
const gap = 10;
|
|
3484
|
+
let top = anchorRect.top - tooltipRect.height - gap;
|
|
3485
|
+
let left = anchorRect.left + anchorRect.width / 2 - tooltipRect.width / 2;
|
|
3486
|
+
let isAbove = true;
|
|
3487
|
+
if (top < 8) {
|
|
3488
|
+
top = anchorRect.bottom + gap;
|
|
3489
|
+
isAbove = false;
|
|
3490
|
+
}
|
|
3491
|
+
left = Math.max(8, Math.min(left, window.innerWidth - tooltipRect.width - 8));
|
|
3492
|
+
this.root.style.top = `${top}px`;
|
|
3493
|
+
this.root.style.left = `${left}px`;
|
|
3494
|
+
const arrowLeft = Math.max(16, Math.min(anchorRect.left + anchorRect.width / 2 - left - 6, tooltipRect.width - 22));
|
|
3495
|
+
if (isAbove) {
|
|
3496
|
+
this.arrow.style.cssText = `
|
|
3497
|
+
position:absolute;
|
|
3498
|
+
width:12px;height:12px;
|
|
3499
|
+
background:rgba(255, 255, 255, 0.88);
|
|
3500
|
+
border-right:1px solid rgba(255, 255, 255, 0.35);
|
|
3501
|
+
border-bottom:1px solid rgba(255, 255, 255, 0.35);
|
|
3502
|
+
transform:rotate(45deg);
|
|
3503
|
+
pointer-events:none;
|
|
3504
|
+
bottom:-6px;
|
|
3505
|
+
left:${arrowLeft}px;
|
|
3506
|
+
`;
|
|
3507
|
+
} else {
|
|
3508
|
+
this.arrow.style.cssText = `
|
|
3509
|
+
position:absolute;
|
|
3510
|
+
width:12px;height:12px;
|
|
3511
|
+
background:rgba(255, 255, 255, 0.88);
|
|
3512
|
+
border-left:1px solid rgba(255, 255, 255, 0.35);
|
|
3513
|
+
border-top:1px solid rgba(255, 255, 255, 0.35);
|
|
3514
|
+
transform:rotate(45deg);
|
|
3515
|
+
pointer-events:none;
|
|
3516
|
+
top:-6px;
|
|
3517
|
+
left:${arrowLeft}px;
|
|
3518
|
+
`;
|
|
3519
|
+
}
|
|
3520
|
+
}
|
|
3521
|
+
/** Check if a DOM node belongs to this tooltip (for MutationObserver filtering). */
|
|
3522
|
+
contains(node) {
|
|
3523
|
+
return this.root.contains(node);
|
|
3524
|
+
}
|
|
3525
|
+
destroy() {
|
|
3526
|
+
this.cancelShow();
|
|
3527
|
+
this.cancelHide();
|
|
3528
|
+
this.root.remove();
|
|
3529
|
+
}
|
|
3530
|
+
};
|
|
3531
|
+
|
|
3532
|
+
// src/launcher.ts
|
|
3533
|
+
var import_meta = {};
|
|
3534
|
+
function launch(config2) {
|
|
3535
|
+
if (!config2.forceShow) {
|
|
3536
|
+
try {
|
|
3537
|
+
const meta = import_meta;
|
|
3538
|
+
const proc = globalThis.process;
|
|
3539
|
+
const mode = meta.env?.MODE ?? proc?.env?.NODE_ENV;
|
|
3540
|
+
if (mode === "production") {
|
|
3541
|
+
return { destroy: () => {
|
|
3542
|
+
} };
|
|
3543
|
+
}
|
|
3544
|
+
} catch {
|
|
3545
|
+
}
|
|
3546
|
+
}
|
|
3547
|
+
if (window.innerWidth < 768) {
|
|
3548
|
+
return { destroy: () => {
|
|
3549
|
+
} };
|
|
3550
|
+
}
|
|
3551
|
+
const colors = buildThemeColors(config2.accentColor);
|
|
3552
|
+
const bus = new EventBus();
|
|
3553
|
+
const apiClient = new ApiClient(config2.endpoint);
|
|
3554
|
+
if (config2.onOpen) bus.on("open", config2.onOpen);
|
|
3555
|
+
if (config2.onClose) bus.on("close", config2.onClose);
|
|
3556
|
+
if (config2.onFeedbackSent) bus.on("feedback:sent", config2.onFeedbackSent);
|
|
3557
|
+
if (config2.onError) bus.on("feedback:error", config2.onError);
|
|
3558
|
+
if (config2.onAnnotationStart) bus.on("annotation:start", config2.onAnnotationStart);
|
|
3559
|
+
if (config2.onAnnotationEnd) bus.on("annotation:end", config2.onAnnotationEnd);
|
|
3560
|
+
const host = document.createElement("siteping-widget");
|
|
3561
|
+
host.style.cssText = "position:fixed;z-index:2147483647;";
|
|
3562
|
+
const shadowMode = config2.__testMode ? "open" : "closed";
|
|
3563
|
+
const shadow = host.attachShadow({ mode: shadowMode });
|
|
3564
|
+
const sheet = new CSSStyleSheet();
|
|
3565
|
+
sheet.replaceSync(buildStyles(colors));
|
|
3566
|
+
shadow.adoptedStyleSheets = [sheet];
|
|
3567
|
+
document.body.appendChild(host);
|
|
3568
|
+
const tooltip = new Tooltip(colors);
|
|
3569
|
+
const markers = new MarkerManager(colors, tooltip, bus);
|
|
3570
|
+
const fab = new Fab(shadow, config2, bus);
|
|
3571
|
+
const panel = new Panel(shadow, colors, bus, apiClient, config2.projectName, markers);
|
|
3572
|
+
const annotator = new Annotator(config2, colors, bus);
|
|
3573
|
+
const unsubAnnotation = bus.on("annotation:complete", async (data) => {
|
|
3574
|
+
const { annotation, type, message } = data;
|
|
3575
|
+
let identity = getIdentity();
|
|
3576
|
+
if (!identity) {
|
|
3577
|
+
identity = await promptIdentity(shadow);
|
|
3578
|
+
if (!identity) return;
|
|
3579
|
+
saveIdentity(identity);
|
|
3580
|
+
}
|
|
3581
|
+
const payload = {
|
|
3582
|
+
projectName: config2.projectName,
|
|
3583
|
+
type,
|
|
3584
|
+
message,
|
|
3585
|
+
url: window.location.href,
|
|
3586
|
+
viewport: `${window.innerWidth}x${window.innerHeight}`,
|
|
3587
|
+
userAgent: navigator.userAgent,
|
|
3588
|
+
authorName: identity.name,
|
|
3589
|
+
authorEmail: identity.email,
|
|
3590
|
+
annotations: [annotation],
|
|
3591
|
+
clientId: crypto.randomUUID()
|
|
3592
|
+
};
|
|
3593
|
+
try {
|
|
3594
|
+
const response = await apiClient.sendFeedback(payload);
|
|
3595
|
+
bus.emit("feedback:sent", response);
|
|
3596
|
+
markers.addFeedback(response, markers.count + 1);
|
|
3597
|
+
await panel.refresh();
|
|
3598
|
+
} catch (error) {
|
|
3599
|
+
bus.emit("feedback:error", error instanceof Error ? error : new Error(String(error)));
|
|
3600
|
+
}
|
|
3601
|
+
});
|
|
3602
|
+
apiClient.getFeedbacks(config2.projectName, { limit: 50 }).then(({ feedbacks }) => {
|
|
3603
|
+
markers.render(feedbacks);
|
|
3604
|
+
}).catch(() => {
|
|
3605
|
+
});
|
|
3606
|
+
flushRetryQueue(config2.endpoint);
|
|
3607
|
+
return {
|
|
3608
|
+
destroy: () => {
|
|
3609
|
+
unsubAnnotation();
|
|
3610
|
+
fab.destroy();
|
|
3611
|
+
panel.destroy();
|
|
3612
|
+
annotator.destroy();
|
|
3613
|
+
markers.destroy();
|
|
3614
|
+
tooltip.destroy();
|
|
3615
|
+
bus.removeAll();
|
|
3616
|
+
host.remove();
|
|
3617
|
+
}
|
|
3618
|
+
};
|
|
3619
|
+
}
|
|
3620
|
+
function promptIdentity(shadowRoot) {
|
|
3621
|
+
return new Promise((resolve) => {
|
|
3622
|
+
const backdrop = document.createElement("div");
|
|
3623
|
+
backdrop.style.cssText = `
|
|
3624
|
+
position:fixed;inset:0;
|
|
3625
|
+
background:rgba(15, 23, 42, 0.2);
|
|
3626
|
+
backdrop-filter:blur(8px);
|
|
3627
|
+
-webkit-backdrop-filter:blur(8px);
|
|
3628
|
+
display:flex;align-items:center;justify-content:center;
|
|
3629
|
+
z-index:2147483647;
|
|
3630
|
+
opacity:0;transition:opacity 0.25s ease;
|
|
3631
|
+
`;
|
|
3632
|
+
const modal = document.createElement("div");
|
|
3633
|
+
modal.style.cssText = `
|
|
3634
|
+
width:340px;padding:28px;border-radius:20px;
|
|
3635
|
+
background:rgba(255, 255, 255, 0.85);
|
|
3636
|
+
backdrop-filter:blur(32px);
|
|
3637
|
+
-webkit-backdrop-filter:blur(32px);
|
|
3638
|
+
border:1px solid rgba(255, 255, 255, 0.35);
|
|
3639
|
+
box-shadow:0 16px 48px rgba(0,0,0,0.12), 0 8px 16px rgba(0,0,0,0.06);
|
|
3640
|
+
font-family:"Inter",system-ui,-apple-system,sans-serif;
|
|
3641
|
+
transform:translateY(12px) scale(0.97);
|
|
3642
|
+
transition:transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
|
|
3643
|
+
-webkit-font-smoothing:antialiased;
|
|
3644
|
+
`;
|
|
3645
|
+
const title = document.createElement("div");
|
|
3646
|
+
title.className = "sp-identity-title";
|
|
3647
|
+
title.textContent = "Identifiez-vous";
|
|
3648
|
+
title.style.marginBottom = "20px";
|
|
3649
|
+
const nameLabel = document.createElement("label");
|
|
3650
|
+
nameLabel.className = "sp-input-label";
|
|
3651
|
+
nameLabel.textContent = "Nom";
|
|
3652
|
+
const nameInput = document.createElement("input");
|
|
3653
|
+
nameInput.className = "sp-input";
|
|
3654
|
+
nameInput.type = "text";
|
|
3655
|
+
nameInput.placeholder = "Votre nom";
|
|
3656
|
+
nameInput.style.marginBottom = "14px";
|
|
3657
|
+
const emailLabel = document.createElement("label");
|
|
3658
|
+
emailLabel.className = "sp-input-label";
|
|
3659
|
+
emailLabel.textContent = "Email";
|
|
3660
|
+
const emailInput = document.createElement("input");
|
|
3661
|
+
emailInput.className = "sp-input";
|
|
3662
|
+
emailInput.type = "email";
|
|
3663
|
+
emailInput.placeholder = "votre@email.com";
|
|
3664
|
+
const btnRow = document.createElement("div");
|
|
3665
|
+
btnRow.style.cssText = "display:flex;gap:8px;justify-content:flex-end;margin-top:20px;";
|
|
3666
|
+
const cancelBtn = document.createElement("button");
|
|
3667
|
+
cancelBtn.className = "sp-btn-ghost";
|
|
3668
|
+
cancelBtn.textContent = "Annuler";
|
|
3669
|
+
cancelBtn.addEventListener("click", () => {
|
|
3670
|
+
backdrop.style.opacity = "0";
|
|
3671
|
+
modal.style.transform = "translateY(12px) scale(0.97)";
|
|
3672
|
+
setTimeout(() => {
|
|
3673
|
+
backdrop.remove();
|
|
3674
|
+
resolve(null);
|
|
3675
|
+
}, 250);
|
|
3676
|
+
});
|
|
3677
|
+
const submitBtn = document.createElement("button");
|
|
3678
|
+
submitBtn.className = "sp-btn-primary";
|
|
3679
|
+
submitBtn.textContent = "Continuer";
|
|
3680
|
+
submitBtn.addEventListener("click", () => {
|
|
3681
|
+
const name = nameInput.value.trim();
|
|
3682
|
+
const email = emailInput.value.trim();
|
|
3683
|
+
if (!name || !email) return;
|
|
3684
|
+
backdrop.style.opacity = "0";
|
|
3685
|
+
modal.style.transform = "translateY(12px) scale(0.97)";
|
|
3686
|
+
setTimeout(() => {
|
|
3687
|
+
backdrop.remove();
|
|
3688
|
+
resolve({ name, email });
|
|
3689
|
+
}, 250);
|
|
3690
|
+
});
|
|
3691
|
+
btnRow.appendChild(cancelBtn);
|
|
3692
|
+
btnRow.appendChild(submitBtn);
|
|
3693
|
+
modal.appendChild(title);
|
|
3694
|
+
modal.appendChild(nameLabel);
|
|
3695
|
+
modal.appendChild(nameInput);
|
|
3696
|
+
modal.appendChild(emailLabel);
|
|
3697
|
+
modal.appendChild(emailInput);
|
|
3698
|
+
modal.appendChild(btnRow);
|
|
3699
|
+
backdrop.appendChild(modal);
|
|
3700
|
+
shadowRoot.appendChild(backdrop);
|
|
3701
|
+
requestAnimationFrame(() => {
|
|
3702
|
+
backdrop.style.opacity = "1";
|
|
3703
|
+
modal.style.transform = "translateY(0) scale(1)";
|
|
3704
|
+
nameInput.focus();
|
|
3705
|
+
});
|
|
3706
|
+
});
|
|
3707
|
+
}
|
|
3708
|
+
|
|
3709
|
+
// src/index.ts
|
|
3710
|
+
function initSiteping(config2) {
|
|
3711
|
+
return launch(config2);
|
|
3712
|
+
}
|
|
3713
|
+
//# sourceMappingURL=index.cjs.map
|