@commentkit/comment-kit 0.7.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/dist/angular.es.js +2 -2
  3. package/dist/comment-kit.es.js +5 -5
  4. package/dist/demo.es.js +4 -3
  5. package/dist/headless.es.js +3 -3
  6. package/dist/preact.es.js +2 -2
  7. package/dist/qwik.qwik.mjs +2 -2
  8. package/dist/react.es.js +2 -2
  9. package/dist/shared/{annotation-toolbar-B9SxYqoF.js → annotation-toolbar-cGC1p-SP.js} +379 -379
  10. package/dist/shared/attachment-refresh-CzQFXHkL.js +94 -0
  11. package/dist/shared/{button-group-Cl9CrvvU.js → button-group-CWdKaOlC.js} +14 -16
  12. package/dist/shared/capture-colors-CxSLsU5-.js +74 -0
  13. package/dist/shared/{comment-drawing-canvas-Dzb5YoFw.js → comment-drawing-canvas-DdXlMgbF.js} +2 -2
  14. package/dist/shared/{comment-utils-BycYTSxA.js → comment-icon-Dg9ZWpz-.js} +29 -23
  15. package/dist/shared/comment-image-lightbox-B7iHjnAz.js +190 -0
  16. package/dist/shared/comment-images-content-D7YNUgo5.js +214 -0
  17. package/dist/shared/{comment-kit-core-BaSuMzp9.js → comment-kit-core-C862uNAm.js} +998 -778
  18. package/dist/shared/{comment-kit-ui-CzfdAZs2.js → comment-kit-ui-0vd-DY4S.js} +5206 -5410
  19. package/dist/shared/{comment-screenshot-annotator-C7X-_bm6.js → comment-screenshot-annotator-DcaSSuWB.js} +5 -5
  20. package/dist/shared/{comment-screenshot-overlay-wIrZrcRy.js → comment-screenshot-overlay-D_nFoJmM.js} +6 -5
  21. package/dist/shared/{dev-export-panel-FwFVdady.js → dev-export-panel-pWBlhlse.js} +7 -7
  22. package/dist/shared/dev-grab-eQ9EgEGY.js +210 -0
  23. package/dist/shared/{element-selector-BhJm-NSs.js → element-selector-DC-_XJ0k.js} +311 -272
  24. package/dist/shared/{mount-ui--ijs8pWT.js → mount-ui-B68j8r6I.js} +4 -4
  25. package/dist/shared/{pusher-ipHMJnO_.js → pusher-C1FHQGXV.js} +1 -1
  26. package/dist/shared/realtime-Diqz7G_y.js +317 -0
  27. package/dist/shared/realtime-recovery-DJ_adc-H.js +135 -0
  28. package/dist/shared/{shadow-root-C5v-T8lQ.js → shadow-root-CrO75sED.js} +1 -1
  29. package/dist/shared/{styles-D3yMtaec.js → styles-C9Jwvm0Q.js} +1 -1
  30. package/dist/shared/useRender-D1z_X_BY.js +5 -0
  31. package/dist/shared/{validation-C7QG8j7Z.js → validation-D-8u4M7I.js} +14 -1
  32. package/dist/shared/{websocket-manager-DhLWh3Jr.js → websocket-manager-CFak_YHy.js} +148 -89
  33. package/dist/solid.es.js +2 -2
  34. package/dist/svelte.es.js +2 -2
  35. package/dist/types/core/api-client.d.ts +8 -1
  36. package/dist/types/core/comment-kit-core.d.ts +9 -0
  37. package/dist/types/core/types.d.ts +35 -0
  38. package/dist/types/core/websocket-manager.d.ts +12 -0
  39. package/dist/types/core/write-access.d.ts +9 -0
  40. package/dist/vue.es.js +2 -2
  41. package/docs/api-reference.md +6 -0
  42. package/package.json +3 -2
  43. package/dist/shared/comment-image-lightbox-BPYJT1sB.js +0 -183
  44. package/dist/shared/dev-grab-DDqg0LQf.js +0 -203
  45. package/dist/shared/realtime-Dk41VwKg.js +0 -302
package/dist/vue.es.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as e } from "./shared/comment-kit-core-BaSuMzp9.js";
1
+ import { t as e } from "./shared/comment-kit-core-C862uNAm.js";
2
2
  import { n as t, r as n, t as r } from "./shared/bridge-CJoGYngu.js";
3
3
  import { n as i, t as a } from "./shared/errors-Bu5ajEmB.js";
4
4
  import { computed as o, h as s, onMounted as c, onUnmounted as l, shallowRef as u, watch as d } from "vue";
@@ -19,7 +19,7 @@ function f(s) {
19
19
  } catch {}
20
20
  }, V = async (e) => {
21
21
  try {
22
- let { mountCommentKitUI: t } = await import("./shared/mount-ui--ijs8pWT.js").then((e) => e.n);
22
+ let { mountCommentKitUI: t } = await import("./shared/mount-ui-B68j8r6I.js").then((e) => e.n);
23
23
  if (L || _.value !== e) return;
24
24
  let n = await t(e);
25
25
  if (L || _.value !== e) {
@@ -65,8 +65,14 @@ Qwik uses `useCommentKit` from `@commentkit/comment-kit/qwik` inside `component$
65
65
 
66
66
  Read `getState().projectContext`, `getState().activeBranch`, `getState().comments` and `getState().pagination` for the results. Context is null until an authenticated response is available. A missing context route on an older API is tolerated; it does not enable new server features. `loadMoreComments()` appends another page and becomes a no-op when there are no more pages.
67
67
 
68
+ Set `config.branch` to the branch actually deployed on the host, such as `main`. This controls the branch recorded on new pins, highlights, drawings and screenshots, including offline replay. `setBranch()` changes the viewing filter; selecting another branch or **All branches** does not relabel feedback created on a configured deployment. A caller can explicitly override the branch of `createComment` through `CommentCreateOptions.branch`. For older integrations without `config.branch`, creation retains the selected branch as its fallback.
69
+
68
70
  The API fetches across project pages. The built-in **Page** tab filters loaded records to the current path; **All** includes other pages. A `#comment-ID` link retrieves its authorized target even beyond the first loaded page. The engine resolves this internally after authentication; do not call a private loader. Cross-page links retain the comment’s original page URL, and markers only target the current page’s DOM.
69
71
 
72
+ Panel text search and its local filters apply to the comments already loaded. When more pages exist, the panel explains this scope and keeps **Load more comments** available even if the current search has no matches. They are not server-wide search endpoints.
73
+
74
+ `projectContext.permissions.canWriteComments` and `writeRestriction` describe the current backend write capability. An expired paid plan keeps authenticated viewing and export, while creation, replies, edits, deletion, reactions, status changes, pin moves and uploads are disabled. A project-level disabled-comments setting is shown separately from a missing paid plan. The backend enforces these rules; hiding UI controls is not authorization. Storage or individual tool limits do not disable ordinary text feedback. The public browser-local demo is a separate sandbox and does not grant access to production projects.
75
+
70
76
  ```ts
71
77
  // With an authenticated core from your integration:
72
78
  await core.setBranch("preview");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commentkit/comment-kit",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "description": "Figma-style collaborative commenting, drawing, and feedback tools for any website. Works with React, Vue, Svelte, Angular, and Vanilla JS.",
5
5
  "keywords": [
6
6
  "angular",
@@ -107,6 +107,7 @@
107
107
  "analyze": "ANALYZE=true BUILD_TARGET=all vp build",
108
108
  "preview": "vp preview",
109
109
  "test": "vp test run",
110
+ "test:coverage": "vp test run --coverage",
110
111
  "test:watch": "vp test watch",
111
112
  "test:ui": "vp test --ui",
112
113
  "test:e2e": "playwright test",
@@ -133,7 +134,7 @@
133
134
  "build:size": "node tools/check-size.mjs",
134
135
  "test:consumers": "node tools/smoke-consumers.mjs --next",
135
136
  "release:check": "npm run release:package && npm run test:e2e",
136
- "release:package": "npm run check && npm run typecheck:test && npm run lint:md && npm run build && npm test && npm run test:consumers && npm audit --audit-level=high"
137
+ "release:package": "npm run check && npm run typecheck:test && npm run lint:md && npm run build && npm run test:coverage && npm run test:consumers && npm audit --audit-level=high"
137
138
  },
138
139
  "devDependencies": {
139
140
  "@angular/common": "^22.2.3",
@@ -1,183 +0,0 @@
1
- import { n as e } from "./dist-De294MVF.js";
2
- import { s as t, t as n } from "./button-By0hGrJK.js";
3
- import { i as r, o as i, r as a } from "./separator-XDBsaWyw.js";
4
- import { r as o } from "./comment-utils-BycYTSxA.js";
5
- import { t as s } from "./button-group-Cl9CrvvU.js";
6
- import { d as c, f as l, u } from "./comment-kit-ui-CzfdAZs2.js";
7
- import * as d from "react";
8
- import { Fragment as f, jsx as p, jsxs as m } from "react/jsx-runtime";
9
- var h = ".ck-dialog-content.ck-image-lightbox{width:100vw;max-width:none;height:100dvh;max-height:none;box-shadow:none;background-color:#0000;border:0;border-radius:0;justify-content:center;align-items:center;gap:0;padding:0;display:flex;inset:0;translate:none}@media (width>=640px){.ck-dialog-content.ck-image-lightbox{max-width:none}}.ck-root[data-theme=dark] .ck-dialog-content.ck-image-lightbox{box-shadow:none}.ck-image-lightbox-prev,.ck-image-lightbox-next{position:absolute}.ck-image-lightbox-prev{inset-inline-start:1rem}.ck-image-lightbox-next{inset-inline-end:1rem}.ck-image-lightbox-photo{object-fit:contain;width:auto;max-width:90vw;height:auto;max-height:90vh}.ck-image-lightbox-meta{border-radius:var(--radius-xl);background-color:var(--muted);text-align:center;max-width:90vw;color:var(--muted-foreground);padding:.25rem .625rem;font-size:.75rem;line-height:1rem;position:absolute;bottom:3.5rem;left:50%;transform:translate(-50%)}.ck-image-lightbox-actions{top:1rem;position:absolute;inset-inline-end:1rem}.ck-image-lightbox-dots{gap:.5rem;display:flex;position:absolute;bottom:1.5rem}.ck-image-lightbox-dot{cursor:pointer;background-color:color-mix(in oklch, var(--foreground) 40%, transparent);border:0;border-radius:999px;width:.625rem;height:.625rem;padding:0;transition:background-color .15s cubic-bezier(.4,0,.2,1)}.ck-image-lightbox-dot:hover{background-color:color-mix(in oklch, var(--foreground) 60%, transparent)}.ck-image-lightbox-dot--active,.ck-image-lightbox-dot--active:hover{background-color:var(--foreground)}";
10
- function g({ className: e, children: t, ...n }) {
11
- return /* @__PURE__ */ p("svg", {
12
- viewBox: "0 0 24 24",
13
- fill: "none",
14
- stroke: "currentColor",
15
- strokeWidth: 1.5,
16
- strokeLinecap: "round",
17
- strokeLinejoin: "round",
18
- "aria-hidden": "true",
19
- ...n,
20
- className: e,
21
- children: t
22
- });
23
- }
24
- function _() {
25
- return /* @__PURE__ */ p(g, { children: /* @__PURE__ */ p("path", { d: "M15 6C15 6 9.00001 10.4189 9 12C8.99999 13.5812 15 18 15 18" }) });
26
- }
27
- function v() {
28
- return /* @__PURE__ */ p(g, { children: /* @__PURE__ */ p("path", { d: "M9.00005 6C9.00005 6 15 10.4189 15 12C15 13.5812 9 18 9 18" }) });
29
- }
30
- function y() {
31
- return /* @__PURE__ */ m(g, { children: [/* @__PURE__ */ p("path", { d: "M7.5 14.5C7.5 11.2002 7.5 9.55025 8.52513 8.52513C9.55025 7.5 11.2002 7.5 14.5 7.5C17.7998 7.5 19.4497 7.5 20.4749 8.52513C21.5 9.55025 21.5 11.2002 21.5 14.5C21.5 17.7998 21.5 19.4497 20.4749 20.4749C19.4497 21.5 17.7998 21.5 14.5 21.5C11.2002 21.5 9.55025 21.5 8.52513 20.4749C7.5 19.4497 7.5 17.7998 7.5 14.5Z" }), /* @__PURE__ */ p("path", { d: "M7.5 16.5C6.10355 16.5 5.40533 16.5 4.84402 16.3036C3.83866 15.9518 3.0482 15.1613 2.69641 14.156C2.5 13.5947 2.5 12.8964 2.5 11.5V9.5C2.5 6.20017 2.5 4.55025 3.52513 3.52513C4.55025 2.5 6.20017 2.5 9.5 2.5H11.5C12.8964 2.5 13.5947 2.5 14.156 2.69641C15.1613 3.0482 15.9518 3.83866 16.3036 4.84402C16.5 5.40533 16.5 6.10355 16.5 7.5" })] });
32
- }
33
- function b() {
34
- return /* @__PURE__ */ m(g, { children: [/* @__PURE__ */ p("path", { d: "M2.99969 17.0002C2.99969 17.9302 2.99969 18.3952 3.10192 18.7767C3.37932 19.8119 4.18796 20.6206 5.22324 20.898C5.60474 21.0002 6.06972 21.0002 6.99969 21.0002L16.9997 21.0002C17.9297 21.0002 18.3947 21.0002 18.7762 20.898C19.8114 20.6206 20.6201 19.8119 20.8975 18.7767C20.9997 18.3952 20.9997 17.9302 20.9997 17.0002" }), /* @__PURE__ */ p("path", { d: "M16.4998 11.5002C16.4998 11.5002 13.1856 16.0002 11.9997 16.0002C10.8139 16.0002 7.49976 11.5002 7.49976 11.5002M11.9997 15.0002V3.00016" })] });
35
- }
36
- function x() {
37
- return /* @__PURE__ */ p(g, { children: /* @__PURE__ */ p("path", { d: "M18 6L6.00081 17.9992M17.9992 18L6 6.00085" }) });
38
- }
39
- var S = d.memo(function({ images: h, initialIndex: g, open: S, onClose: C, returnFocusRef: w }) {
40
- let [T, E] = d.useState(g);
41
- d.useEffect(() => {
42
- S && E(Math.max(0, Math.min(g, h.length - 1)));
43
- }, [
44
- g,
45
- S,
46
- h.length
47
- ]);
48
- let D = h[T], O = !!(D && (D.type ?? D.filename ?? D.size != null)), k = async (t) => {
49
- if (t.stopPropagation(), D) try {
50
- let t = new URL(D.url, window.location.href);
51
- if (t.protocol !== "http:" && t.protocol !== "https:" && t.protocol !== "data:" && t.protocol !== "blob:") throw Error("Invalid image URL protocol");
52
- let n = await fetch(t.href);
53
- if (!n.ok) throw Error(`Failed to fetch image (${String(n.status)})`);
54
- let r = await n.blob();
55
- await navigator.clipboard.write([new ClipboardItem({ [r.type]: r })]), e.success("Image copied");
56
- } catch {
57
- e.error("Failed to copy image");
58
- }
59
- };
60
- return /* @__PURE__ */ p(u, {
61
- open: S && h.length > 0,
62
- onOpenChange: (e) => {
63
- e || C();
64
- },
65
- children: /* @__PURE__ */ m(c, {
66
- showCloseButton: !1,
67
- finalFocus: w,
68
- "aria-describedby": void 0,
69
- className: "ck-image-lightbox",
70
- onClick: C,
71
- onKeyDownCapture: (e) => {
72
- if (e.key !== "ArrowLeft" && e.key !== "ArrowRight") return;
73
- e.preventDefault(), e.stopPropagation();
74
- let t = e.key === "ArrowLeft" ? -1 : 1;
75
- E((e) => Math.max(0, Math.min(h.length - 1, e + t)));
76
- },
77
- children: [/* @__PURE__ */ p(l, {
78
- className: "ck-sr-only",
79
- children: "Image lightbox"
80
- }), D ? /* @__PURE__ */ m(f, { children: [
81
- h.length > 1 && T > 0 ? /* @__PURE__ */ p(n, {
82
- variant: "outline",
83
- size: "icon",
84
- "aria-label": "Previous image",
85
- className: "ck-image-lightbox-prev",
86
- onClick: (e) => {
87
- e.stopPropagation(), E((e) => e - 1);
88
- },
89
- children: /* @__PURE__ */ p(_, {})
90
- }) : null,
91
- h.length > 1 && T < h.length - 1 ? /* @__PURE__ */ p(n, {
92
- variant: "outline",
93
- size: "icon",
94
- "aria-label": "Next image",
95
- className: "ck-image-lightbox-next",
96
- onClick: (e) => {
97
- e.stopPropagation(), E((e) => e + 1);
98
- },
99
- children: /* @__PURE__ */ p(v, {})
100
- }) : null,
101
- /* @__PURE__ */ p("img", {
102
- src: D.url,
103
- alt: D.alt ?? D.filename ?? `Image ${String(T + 1)}`,
104
- className: "ck-image-lightbox-photo",
105
- onClick: (e) => {
106
- e.stopPropagation();
107
- }
108
- }),
109
- O ? /* @__PURE__ */ p("div", {
110
- className: "ck-image-lightbox-meta",
111
- onClick: (e) => {
112
- e.stopPropagation();
113
- },
114
- children: [
115
- D.type,
116
- D.filename,
117
- o(D.size)
118
- ].filter(Boolean).join(" • ")
119
- }) : null,
120
- /* @__PURE__ */ m(s, {
121
- className: "ck-image-lightbox-actions",
122
- onClick: (e) => {
123
- e.stopPropagation();
124
- },
125
- children: [
126
- /* @__PURE__ */ m(a, { children: [/* @__PURE__ */ p(i, {
127
- render: /* @__PURE__ */ p(n, {
128
- variant: "outline",
129
- size: "icon",
130
- "aria-label": "Copy image",
131
- onClick: (e) => {
132
- k(e);
133
- }
134
- }),
135
- children: /* @__PURE__ */ p(y, {})
136
- }), /* @__PURE__ */ p(r, { children: "Copy image" })] }),
137
- /* @__PURE__ */ m(a, { children: [/* @__PURE__ */ p(i, {
138
- render: /* @__PURE__ */ p(n, {
139
- variant: "outline",
140
- size: "icon",
141
- "aria-label": "Download",
142
- onClick: (e) => {
143
- if (e.stopPropagation(), !D) return;
144
- let t = document.createElement("a");
145
- t.href = D.url, t.download = D.alt ?? `image-${String(T + 1)}`, t.target = "_blank", t.click();
146
- }
147
- }),
148
- children: /* @__PURE__ */ p(b, {})
149
- }), /* @__PURE__ */ p(r, { children: "Download" })] }),
150
- /* @__PURE__ */ m(a, { children: [/* @__PURE__ */ p(i, {
151
- render: /* @__PURE__ */ p(n, {
152
- variant: "outline",
153
- size: "icon",
154
- "aria-label": "Close",
155
- onClick: C
156
- }),
157
- children: /* @__PURE__ */ p(x, {})
158
- }), /* @__PURE__ */ p(r, { children: "Close" })] })
159
- ]
160
- }),
161
- h.length > 1 ? /* @__PURE__ */ p("div", {
162
- className: "ck-image-lightbox-dots",
163
- children: h.map((e, n) => /* @__PURE__ */ p("button", {
164
- type: "button",
165
- "aria-label": `Go to image ${String(n + 1)}`,
166
- "aria-current": n === T ? "true" : void 0,
167
- className: t("ck-image-lightbox-dot", n === T && "ck-image-lightbox-dot--active"),
168
- onClick: (e) => {
169
- e.stopPropagation(), E(n);
170
- }
171
- }, e.id))
172
- }) : null
173
- ] }) : null]
174
- })
175
- });
176
- });
177
- function C(e) {
178
- return /* @__PURE__ */ m(f, { children: [/* @__PURE__ */ p("style", {
179
- "data-ck-tool-styles": "lightbox",
180
- children: h
181
- }), /* @__PURE__ */ p(S, { ...e })] });
182
- }
183
- export { C as CommentImageLightbox };
@@ -1,203 +0,0 @@
1
- import { d as e, o as t, r as n, s as r, u as i } from "./comment-kit-core-BaSuMzp9.js";
2
- import { a, i as o, o as s } from "./dom-Bhf4WFtY.js";
3
- var c = 4e3, l = 500, u = 2e3, d = 1e3, f = 5, p = 25, m = 3145728;
4
- function h(t) {
5
- let n = e(t?.comment, u);
6
- return n.length > 0 ? n : null;
7
- }
8
- function g(t) {
9
- return (t?.attachments ?? []).slice(0, f).flatMap((t) => {
10
- let n = e(t.name, d), r = e(t.path, d);
11
- return !n || !r ? [] : [{
12
- name: n,
13
- path: r,
14
- ...t.pathSource ? { pathSource: t.pathSource } : {},
15
- ...t.type ? { type: e(t.type, d) } : {},
16
- ...typeof t.size == "number" ? { size: t.size } : {},
17
- ...typeof t.lastModified == "number" ? { lastModified: t.lastModified } : {}
18
- }];
19
- });
20
- }
21
- function _(e) {
22
- return typeof HTMLElement < "u" && e instanceof HTMLElement;
23
- }
24
- function v(t, n, r, i) {
25
- let s = t.getBoundingClientRect(), u = o(t), d = a(t), f = t.getAttribute("class"), p = t.getAttribute("role"), m = t.getAttribute("aria-label"), h = e(t.textContent, l), g = e(t.outerHTML, c);
26
- return {
27
- found: !0,
28
- tagName: t.tagName.toLowerCase(),
29
- ...t.id ? { id: t.id } : {},
30
- ...f ? { className: f } : {},
31
- ...p ? { role: p } : {},
32
- ...m ? { ariaLabel: m } : {},
33
- ...h ? { text: h } : {},
34
- rect: {
35
- top: s.top,
36
- left: s.left,
37
- width: s.width,
38
- height: s.height
39
- },
40
- ...g ? { htmlPreview: g } : {},
41
- ...u ? { selector: u } : {},
42
- ...d ? { xpath: d } : {},
43
- ...n ? {
44
- source: y(n),
45
- stack: r.map(y)
46
- } : {},
47
- ...i ? { componentName: i } : {}
48
- };
49
- }
50
- function y(e) {
51
- return {
52
- filePath: e.filePath,
53
- lineNumber: e.lineNumber,
54
- columnNumber: e.columnNumber,
55
- componentName: e.componentName
56
- };
57
- }
58
- function b(e) {
59
- let t = `${e.filePath}${e.lineNumber === null ? "" : `:${e.lineNumber}`}${e.columnNumber === null ? "" : `:${e.columnNumber}`}`;
60
- return e.componentName ? `${e.componentName} (${t})` : t;
61
- }
62
- function x(e, t, n, r, i, a) {
63
- let o = ["# CommentKit Element Grab", ""], s = t.tagName ?? "element", c = t.id ? `#${t.id}` : "";
64
- if (o.push(`**Tag:** \`${s}${c}\``), i && o.push(`**Comment:** ${i}`), a.length > 0) {
65
- o.push("", "**Attachments:**");
66
- for (let e of a) {
67
- let t = [
68
- e.type ? `type: \`${e.type}\`` : null,
69
- typeof e.size == "number" ? `size: ${e.size} bytes` : null,
70
- e.pathSource ? `path source: ${e.pathSource}` : null
71
- ].filter(Boolean).join(", ");
72
- o.push(`- \`${e.name}\` - path: \`${e.path}\`${t ? ` (${t})` : ""}`);
73
- }
74
- }
75
- if (t.componentName && o.push(`**Component:** \`${t.componentName}\``), t.source && o.push(`**Source:** ${b(t.source)}`), t.stack && t.stack.length > 1) {
76
- o.push("", "**Stack:**");
77
- for (let e of t.stack) o.push(`- ${b(e)}`);
78
- }
79
- return t.source || (t.selector && o.push(`**Selector:** \`${t.selector}\``), t.xpath && o.push(`**XPath:** \`${t.xpath}\``)), o.push(`**Page:** ${e.title || "Untitled"} — ${e.url || e.path}`), o.push(""), o.push("**HTML:**", "```html", n, "```", ""), r && o.push("**Screenshot:** attached to clipboard as an image (paste below this text).", ""), o.join("\n");
80
- }
81
- function S(e) {
82
- let t = e.element;
83
- return {
84
- tagName: t.tagName,
85
- id: t.id,
86
- className: t.className,
87
- textContent: t.text,
88
- componentName: t.componentName,
89
- filePath: t.source?.filePath,
90
- lineNumber: t.source?.lineNumber ?? void 0,
91
- columnNumber: t.source?.columnNumber ?? void 0,
92
- comment: e.comment ?? void 0,
93
- attachments: e.attachments,
94
- selector: t.selector,
95
- xpath: t.xpath
96
- };
97
- }
98
- function C(e) {
99
- if (typeof window > "u" || typeof window.dispatchEvent != "function") return;
100
- let t = e[0];
101
- t && window.dispatchEvent(new CustomEvent("commentkit:element-selected", { detail: {
102
- generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
103
- page: t.page,
104
- elements: e.map(S)
105
- } }));
106
- }
107
- async function w(a, o, l, u) {
108
- if (!a || typeof Element > "u" || !(a instanceof Element) || typeof a.getBoundingClientRect != "function") return null;
109
- let d = (_(a), a), f = await i(a), p = f?.source ?? null, m = f?.stack ?? [], y = f?.componentName ?? null, b = await n(o, l, d, { reportErrors: !1 }), S = b?.dataUrl ?? null, w = b?.blob ?? null, T = v(a, p, m, y), E = T.htmlPreview ?? e(a.outerHTML, c), D = s(), O = h(u), k = g(u), A = x({
110
- url: D.url,
111
- path: D.path,
112
- title: D.title
113
- }, T, E, S, O, k);
114
- try {
115
- w ? await t(A, w) : await r(A);
116
- } catch {}
117
- let j = {
118
- generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
119
- page: {
120
- url: D.url,
121
- path: D.path,
122
- title: D.title
123
- },
124
- element: T,
125
- comment: O,
126
- attachments: k,
127
- html: E,
128
- screenshotDataUrl: S,
129
- markdown: A
130
- };
131
- return C([j]), j;
132
- }
133
- function T(e, t, n, r) {
134
- let i = [
135
- "# CommentKit Element Grab",
136
- "",
137
- `**Elements:** ${t.length}`,
138
- `**Page:** ${e.title || "Untitled"} — ${e.url || e.path}`
139
- ];
140
- if (n && i.push(`**Comment:** ${n}`), r.length > 0) {
141
- i.push("", "**Attachments:**");
142
- for (let e of r) i.push(`- \`${e.name}\` - path: \`${e.path}\`${e.pathSource ? ` (path source: ${e.pathSource})` : ""}`);
143
- }
144
- return i.push(""), t.forEach((e, t) => {
145
- let { element: n } = e, r = n.tagName ?? "element", a = n.id ? `#${n.id}` : "";
146
- i.push(`## [${t + 1}] \`${r}${a}\``), n.componentName && i.push(`- Component: \`${n.componentName}\``), n.source && i.push(`- Source: ${b(n.source)}`), n.stack && n.stack.length > 1 && i.push(`- Stack: ${n.stack.map((e) => e.componentName ?? e.filePath).join(" → ")}`), n.source || (n.selector && i.push(`- Selector: \`${n.selector}\``), n.xpath && i.push(`- XPath: \`${n.xpath}\``)), i.push("", "```html", e.html, "```", ""), e.screenshotDataUrl && i.push(`![screenshot](${e.screenshotDataUrl})`, "");
147
- }), i.join("\n");
148
- }
149
- async function E(t, a, o, l) {
150
- let u = t.filter((e) => !!e && typeof Element < "u" && e instanceof Element && typeof e.getBoundingClientRect == "function");
151
- if (u.length === 0) return null;
152
- let d = u.slice(0, p);
153
- u.length > p && typeof console < "u" && console.warn(`[CommentKit] grabElements was called with ${u.length} elements — capped to ${p} for clipboard size. Pass fewer elements to avoid truncation.`);
154
- let f = [], y = 0, b = 0, S = h(l), w = g(l);
155
- for (let t of d) {
156
- let r = (_(t), t), l = await i(t), u = l?.source ?? null, d = l?.stack ?? [], p = l?.componentName ?? null, h = null;
157
- if (y < m) {
158
- let e = (await n(a, o, r, { reportErrors: !1 }))?.dataUrl ?? null;
159
- e && y + e.length <= m ? (h = e, y += e.length) : e && b++;
160
- } else b++;
161
- let g = v(t, u, d, p), C = g.htmlPreview ?? e(t.outerHTML, c), T = s(), E = x({
162
- url: T.url,
163
- path: T.path,
164
- title: T.title
165
- }, g, C, h, S, w);
166
- f.push({
167
- generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
168
- page: {
169
- url: T.url,
170
- path: T.path,
171
- title: T.title
172
- },
173
- element: g,
174
- comment: S,
175
- attachments: w,
176
- html: C,
177
- screenshotDataUrl: h,
178
- markdown: E
179
- });
180
- }
181
- b > 0 && typeof console < "u" && console.warn(`[CommentKit] grabElements dropped ${b} screenshot${b === 1 ? "" : "s"} to stay under the ${Math.round(m / 1024 / 1024)}MB clipboard budget.`);
182
- let E = s(), D = T({
183
- url: E.url,
184
- path: E.path,
185
- title: E.title
186
- }, f, S, w);
187
- try {
188
- await r(D);
189
- } catch {}
190
- let O = {
191
- generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
192
- page: {
193
- url: E.url,
194
- path: E.path,
195
- title: E.title
196
- },
197
- results: f,
198
- attachments: w,
199
- markdown: D
200
- };
201
- return C(f), O;
202
- }
203
- export { w as grabElement, E as grabElements };