@devaccel-labs/app-comments-toolbar 1.0.0 → 1.1.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.
@@ -1,160 +0,0 @@
1
- // src/runtime/screenshot.ts
2
- var MAX_WIDTH = 1200;
3
- var BROWSERS = [
4
- ["Edge", /Edg\/(\d+)/],
5
- ["Firefox", /Firefox\/(\d+)/],
6
- ["Chrome", /Chrome\/(\d+)/],
7
- ["Safari", /Version\/(\d+)[\d.]* .*Safari/]
8
- ];
9
- var SYSTEMS = [
10
- ["iOS", /iPhone|iPad/],
11
- ["Android", /Android/],
12
- ["macOS", /Mac OS X/],
13
- ["Windows", /Windows/],
14
- ["Linux", /Linux/]
15
- ];
16
- function browserLabel(agent) {
17
- let browser;
18
- for (const [name, pattern] of BROWSERS) {
19
- const version = agent.match(pattern)?.[1];
20
- if (version) {
21
- browser = `${name} ${version}`;
22
- break;
23
- }
24
- }
25
- const system = SYSTEMS.find(([, pattern]) => pattern.test(agent))?.[0];
26
- return [browser, system].filter(Boolean).join(" \xB7 ") || void 0;
27
- }
28
- function describeCapture(url) {
29
- return {
30
- url,
31
- viewport: { width: document.documentElement.clientWidth, height: window.innerHeight },
32
- browser: browserLabel(navigator.userAgent)
33
- };
34
- }
35
- function roundedRect(ctx, x, y, w, h, r) {
36
- ctx.moveTo(x + r, y);
37
- ctx.arcTo(x + w, y, x + w, y + h, r);
38
- ctx.arcTo(x + w, y + h, x, y + h, r);
39
- ctx.arcTo(x, y + h, x, y, r);
40
- ctx.arcTo(x, y, x + w, y, r);
41
- ctx.closePath();
42
- }
43
- async function renderViewport(scale, timeout = 6e3) {
44
- const { domToCanvas } = await import("./render-page-76MLIT6M.js");
45
- return domToCanvas(document.documentElement, {
46
- width: document.documentElement.clientWidth,
47
- height: window.innerHeight,
48
- scale,
49
- timeout,
50
- backgroundColor: getComputedStyle(document.body).backgroundColor || "#ffffff",
51
- filter: (node) => !(node instanceof Element && node.id === "cs-root"),
52
- style: {
53
- transform: `translate(${-window.scrollX}px, ${-window.scrollY}px)`,
54
- transformOrigin: "0 0"
55
- }
56
- });
57
- }
58
- function outline(ctx, width, height, ring, scale) {
59
- const radius = Math.min(12 * scale, ring.w / 2, ring.h / 2);
60
- ctx.beginPath();
61
- ctx.rect(0, 0, width, height);
62
- roundedRect(ctx, ring.x, ring.y, ring.w, ring.h, radius);
63
- ctx.fillStyle = "rgba(15, 15, 20, 0.22)";
64
- ctx.fill("evenodd");
65
- ctx.beginPath();
66
- roundedRect(ctx, ring.x, ring.y, ring.w, ring.h, radius);
67
- ctx.lineWidth = 3 * scale;
68
- ctx.strokeStyle = "#007aff";
69
- ctx.stroke();
70
- }
71
- async function capturePage(highlight) {
72
- const scale = Math.min(window.devicePixelRatio || 1, 2);
73
- let page;
74
- try {
75
- page = await renderViewport(scale);
76
- } catch {
77
- return null;
78
- }
79
- const width = document.documentElement.clientWidth;
80
- const outScale = Math.min(scale, 1600 / width);
81
- const out = document.createElement("canvas");
82
- out.width = Math.round(width * outScale);
83
- out.height = Math.round(window.innerHeight * outScale);
84
- const ctx = out.getContext("2d");
85
- if (!ctx) return null;
86
- ctx.drawImage(page, 0, 0, out.width, out.height);
87
- const rect = highlight?.getBoundingClientRect();
88
- if (rect && rect.width > 0 && rect.bottom > 0 && rect.top < window.innerHeight) {
89
- const pad = 6;
90
- outline(
91
- ctx,
92
- out.width,
93
- out.height,
94
- {
95
- x: (rect.left - pad) * outScale,
96
- y: (rect.top - pad) * outScale,
97
- w: (rect.width + pad * 2) * outScale,
98
- h: (rect.height + pad * 2) * outScale
99
- },
100
- outScale
101
- );
102
- }
103
- return new Promise((resolve) => out.toBlob((blob) => resolve(blob), "image/jpeg", 0.85));
104
- }
105
- async function captureAround(element) {
106
- const rect = element.getBoundingClientRect();
107
- const viewportWidth = document.documentElement.clientWidth;
108
- const viewportHeight = window.innerHeight;
109
- if (rect.width < 1 || rect.bottom <= 0 || rect.top >= viewportHeight || rect.right <= 0 || rect.left >= viewportWidth)
110
- return null;
111
- const scale = Math.min(window.devicePixelRatio || 1, 2);
112
- let page;
113
- try {
114
- page = await renderViewport(scale);
115
- } catch {
116
- return null;
117
- }
118
- const width = Math.min(viewportWidth, Math.max(rect.width + 200, 760));
119
- const height = Math.min(viewportHeight, Math.max(rect.height + 200, 420));
120
- const x = Math.max(0, Math.min(rect.left + rect.width / 2 - width / 2, viewportWidth - width));
121
- const y = Math.max(0, Math.min(rect.top + rect.height / 2 - height / 2, viewportHeight - height));
122
- const out = document.createElement("canvas");
123
- const outScale = Math.min(scale, MAX_WIDTH / width);
124
- out.width = Math.round(width * outScale);
125
- out.height = Math.round(height * outScale);
126
- const ctx = out.getContext("2d");
127
- if (!ctx) return null;
128
- ctx.drawImage(
129
- page,
130
- x * scale,
131
- y * scale,
132
- width * scale,
133
- height * scale,
134
- 0,
135
- 0,
136
- out.width,
137
- out.height
138
- );
139
- const pad = 6;
140
- outline(
141
- ctx,
142
- out.width,
143
- out.height,
144
- {
145
- x: (rect.left - x - pad) * outScale,
146
- y: (rect.top - y - pad) * outScale,
147
- w: (rect.width + pad * 2) * outScale,
148
- h: (rect.height + pad * 2) * outScale
149
- },
150
- outScale
151
- );
152
- return out.toDataURL("image/jpeg", 0.82);
153
- }
154
-
155
- export {
156
- describeCapture,
157
- renderViewport,
158
- capturePage,
159
- captureAround
160
- };