@altano/astro-opengraph 0.1.0-alpha.4 → 0.1.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 (40) hide show
  1. package/README.md +9 -0
  2. package/dist/config-CzK0JuaO.js +45 -0
  3. package/dist/config-CzK0JuaO.js.map +1 -0
  4. package/dist/config.d.ts +7 -3
  5. package/dist/config.js +3 -8
  6. package/dist/endpoint.d.ts +24 -11
  7. package/dist/endpoint.js +62 -85
  8. package/dist/endpoint.js.map +1 -0
  9. package/dist/index.d.ts +7 -2
  10. package/dist/index.js +41 -58
  11. package/dist/index.js.map +1 -0
  12. package/dist/toolbar/index.d.ts +6 -2
  13. package/dist/toolbar/index.js +359 -429
  14. package/dist/toolbar/index.js.map +1 -0
  15. package/dist/types-B1hoqgLx.d.ts +70 -0
  16. package/package.json +20 -17
  17. package/dist/chunk-DX3VCTOX.js +0 -49
  18. package/dist/image.d.ts +0 -7
  19. package/dist/integration.d.ts +0 -5
  20. package/dist/toolbar/components/CopyImageUrlButton.d.ts +0 -3
  21. package/dist/toolbar/components/Error.d.ts +0 -7
  22. package/dist/toolbar/components/ExternalLinkicon.d.ts +0 -7
  23. package/dist/toolbar/components/Image.d.ts +0 -6
  24. package/dist/toolbar/components/ImageSection.d.ts +0 -6
  25. package/dist/toolbar/components/ImageZoomToolbar.d.ts +0 -7
  26. package/dist/toolbar/components/LinkOrText.d.ts +0 -7
  27. package/dist/toolbar/components/MetaTags.d.ts +0 -3
  28. package/dist/toolbar/components/Summary.d.ts +0 -5
  29. package/dist/toolbar/components/ToolbarApp.d.ts +0 -3
  30. package/dist/toolbar/components/ToolbarAppWindow.d.ts +0 -3
  31. package/dist/toolbar/components/ToolbarSection.d.ts +0 -7
  32. package/dist/toolbar/components/ZoomButton.d.ts +0 -7
  33. package/dist/toolbar/components/ZoomLabel.d.ts +0 -4
  34. package/dist/toolbar/components/getRelativeUrl.d.ts +0 -2
  35. package/dist/toolbar/hooks/useHoverState.d.ts +0 -3
  36. package/dist/toolbar/hooks/useImageURL.d.ts +0 -3
  37. package/dist/toolbar/hooks/useMetaTagInfo.d.ts +0 -3
  38. package/dist/toolbar/styles.d.ts +0 -2
  39. package/dist/types.d.ts +0 -67
  40. package/dist/virtual-user-config.d.ts +0 -8
@@ -1,11 +1,10 @@
1
- // src/toolbar/index.tsx
2
1
  import { render } from "preact";
3
2
  import { defineToolbarApp } from "astro/toolbar";
3
+ import { useCallback, useEffect, useRef, useState } from "preact/hooks";
4
+ import { Fragment, jsx, jsxs } from "preact/jsx-runtime";
4
5
 
5
- // src/toolbar/styles.tsx
6
- var styles = (
7
- /* css */
8
- `
6
+ //#region src/toolbar/styles.tsx
7
+ const styles = `
9
8
  :host astro-dev-toolbar-window {
10
9
  max-height: calc(100vh - 80px);
11
10
  overflow-y: auto;
@@ -34,477 +33,408 @@ var styles = (
34
33
  .image img {
35
34
  transition: max-width 0.1s;
36
35
  }
37
- `
38
- );
36
+ `;
39
37
 
40
- // src/toolbar/components/ToolbarApp.tsx
41
- import { useState as useState4 } from "preact/hooks";
42
-
43
- // src/toolbar/components/Summary.tsx
44
- import { jsx } from "preact/jsx-runtime";
45
- function Summary({
46
- children
47
- }) {
48
- return /* @__PURE__ */ jsx(
49
- "summary",
50
- {
51
- style: {
52
- cursor: "pointer",
53
- fontWeight: 700,
54
- color: "white"
55
- },
56
- children
57
- }
58
- );
38
+ //#endregion
39
+ //#region src/toolbar/components/Summary.tsx
40
+ function Summary({ children }) {
41
+ return /* @__PURE__ */ jsx("summary", {
42
+ style: {
43
+ cursor: "pointer",
44
+ fontWeight: 700,
45
+ color: "white"
46
+ },
47
+ children
48
+ });
59
49
  }
60
50
 
61
- // src/toolbar/components/ExternalLinkicon.tsx
62
- import { jsx as jsx2, jsxs } from "preact/jsx-runtime";
63
- function ExternalLinkicon({
64
- width = 27,
65
- height = 27,
66
- fill = "#020202"
67
- }) {
68
- return /* @__PURE__ */ jsx2(
69
- "span",
70
- {
71
- style: {
72
- display: "inline-block",
73
- width,
74
- height
75
- },
76
- children: /* @__PURE__ */ jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 120 120", children: [
77
- /* @__PURE__ */ jsx2("path", { d: "M120.09 16.696H60.256V.096L120.09.09z", fill }),
78
- /* @__PURE__ */ jsx2(
79
- "path",
80
- {
81
- d: "M57.99 48.64l42.573-42.574 13.475 13.475-42.574 42.58z",
82
- fill
83
- }
84
- ),
85
- /* @__PURE__ */ jsx2(
86
- "path",
87
- {
88
- d: "M119.98.107l.02 59.83-16.59.013-.02-59.846zM3 23.5h17v87H3zm83.49 52.56h17V113h-17z",
89
- fill
90
- }
91
- ),
92
- /* @__PURE__ */ jsx2("path", { d: "M3 16.692h40.655v17H3zM3 96h100.49v17H3z", fill })
93
- ] })
94
- }
95
- );
51
+ //#endregion
52
+ //#region src/toolbar/components/ExternalLinkicon.tsx
53
+ function ExternalLinkicon({ width = 27, height = 27, fill = "#020202" }) {
54
+ return /* @__PURE__ */ jsx("span", {
55
+ style: {
56
+ display: "inline-block",
57
+ width,
58
+ height
59
+ },
60
+ children: /* @__PURE__ */ jsxs("svg", {
61
+ xmlns: "http://www.w3.org/2000/svg",
62
+ viewBox: "0 0 120 120",
63
+ children: [
64
+ /* @__PURE__ */ jsx("path", {
65
+ d: "M120.09 16.696H60.256V.096L120.09.09z",
66
+ fill
67
+ }),
68
+ /* @__PURE__ */ jsx("path", {
69
+ d: "M57.99 48.64l42.573-42.574 13.475 13.475-42.574 42.58z",
70
+ fill
71
+ }),
72
+ /* @__PURE__ */ jsx("path", {
73
+ d: "M119.98.107l.02 59.83-16.59.013-.02-59.846zM3 23.5h17v87H3zm83.49 52.56h17V113h-17z",
74
+ fill
75
+ }),
76
+ /* @__PURE__ */ jsx("path", {
77
+ d: "M3 16.692h40.655v17H3zM3 96h100.49v17H3z",
78
+ fill
79
+ })
80
+ ]
81
+ })
82
+ });
96
83
  }
97
84
 
98
- // src/toolbar/components/LinkOrText.tsx
99
- import { jsx as jsx3, jsxs as jsxs2 } from "preact/jsx-runtime";
100
- function LinkOrText({
101
- maybeLinkText
102
- }) {
103
- let parsedMaybeLink = null;
104
- try {
105
- if (maybeLinkText != null) {
106
- const url = new URL(maybeLinkText);
107
- parsedMaybeLink = /* @__PURE__ */ jsxs2("a", { href: url.toString(), target: "_blank", children: [
108
- maybeLinkText,
109
- " ",
110
- /* @__PURE__ */ jsx3(ExternalLinkicon, { width: 10, height: 10, fill: "white" })
111
- ] });
112
- }
113
- } catch (_) {
114
- parsedMaybeLink = maybeLinkText;
115
- }
116
- return parsedMaybeLink;
85
+ //#endregion
86
+ //#region src/toolbar/components/LinkOrText.tsx
87
+ function LinkOrText({ maybeLinkText }) {
88
+ let parsedMaybeLink = null;
89
+ try {
90
+ if (maybeLinkText != null) {
91
+ const url = new URL(maybeLinkText);
92
+ parsedMaybeLink = /* @__PURE__ */ jsxs("a", {
93
+ href: url.toString(),
94
+ target: "_blank",
95
+ children: [
96
+ maybeLinkText,
97
+ " ",
98
+ /* @__PURE__ */ jsx(ExternalLinkicon, {
99
+ width: 10,
100
+ height: 10,
101
+ fill: "white"
102
+ })
103
+ ]
104
+ });
105
+ }
106
+ } catch (_) {
107
+ parsedMaybeLink = maybeLinkText;
108
+ }
109
+ return parsedMaybeLink;
117
110
  }
118
111
 
119
- // src/toolbar/hooks/useMetaTagInfo.tsx
112
+ //#endregion
113
+ //#region src/toolbar/hooks/useMetaTagInfo.tsx
114
+ const useHeadObserver = () => {
115
+ const [_generation, setGeneration] = useState(0);
116
+ const forceRerender = () => setGeneration((old) => ++old);
117
+ const headRef = useRef(document.querySelector("head"));
118
+ useEffect(() => {
119
+ if (headRef.current == null) return;
120
+ const observer = new MutationObserver(forceRerender);
121
+ observer.observe(headRef.current, {
122
+ attributes: true,
123
+ characterData: true,
124
+ childList: true,
125
+ subtree: true
126
+ });
127
+ return () => observer.disconnect();
128
+ }, []);
129
+ return headRef;
130
+ };
120
131
  function useMetaTagInfo() {
121
- return Array.from(document.querySelectorAll("meta[property^='og:']")).map(
122
- (tag) => [
123
- tag.getAttribute("content"),
124
- tag.getAttribute("property")
125
- ]
126
- );
132
+ const headRef = useHeadObserver();
133
+ const opengraphMetaTags = headRef?.current?.querySelectorAll("meta[property^='og:']") ?? [];
134
+ return Array.from(opengraphMetaTags).map((tag) => [tag.getAttribute("content"), tag.getAttribute("property")]);
127
135
  }
128
136
 
129
- // src/toolbar/components/MetaTags.tsx
130
- import { Fragment, jsx as jsx4, jsxs as jsxs3 } from "preact/jsx-runtime";
137
+ //#endregion
138
+ //#region src/toolbar/components/MetaTags.tsx
131
139
  function MetaTags() {
132
- const tags = useMetaTagInfo();
133
- return /* @__PURE__ */ jsx4(
134
- "dl",
135
- {
136
- "data-testid": "astro-opengraph-toolbar",
137
- style: {
138
- margin: 0,
139
- display: "grid",
140
- gridTemplateColumns: "max-content 1fr",
141
- gap: 7,
142
- columnGap: 13
143
- },
144
- children: tags.map((tag) => /* @__PURE__ */ jsx4(MetaTagContent, { tag }, tag[1]))
145
- }
146
- );
140
+ const tags = useMetaTagInfo();
141
+ return /* @__PURE__ */ jsx("dl", {
142
+ "data-testid": "astro-opengraph-toolbar",
143
+ style: {
144
+ margin: 0,
145
+ display: "grid",
146
+ gridTemplateColumns: "max-content 1fr",
147
+ gap: 7,
148
+ columnGap: 13
149
+ },
150
+ children: tags.map((tag) => /* @__PURE__ */ jsx(MetaTagContent, { tag }, tag[1]))
151
+ });
147
152
  }
148
153
  function MetaTagContent({ tag }) {
149
- const [content, property] = tag;
150
- return /* @__PURE__ */ jsxs3(Fragment, { children: [
151
- /* @__PURE__ */ jsx4(
152
- "dt",
153
- {
154
- style: {
155
- color: "white",
156
- textAlign: "right",
157
- fontWeight: 500
158
- },
159
- children: property
160
- }
161
- ),
162
- /* @__PURE__ */ jsx4("dd", { style: { margin: 0 }, children: /* @__PURE__ */ jsx4(LinkOrText, { maybeLinkText: content }) })
163
- ] });
154
+ const [content, property] = tag;
155
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("dt", {
156
+ style: {
157
+ color: "white",
158
+ textAlign: "right",
159
+ fontWeight: 500
160
+ },
161
+ children: property
162
+ }), /* @__PURE__ */ jsx("dd", {
163
+ style: { margin: 0 },
164
+ children: /* @__PURE__ */ jsx(LinkOrText, { maybeLinkText: content })
165
+ })] });
164
166
  }
165
167
 
166
- // src/toolbar/hooks/useHoverState.tsx
167
- import { useRef, useEffect } from "preact/hooks";
168
+ //#endregion
169
+ //#region src/toolbar/hooks/useHoverState.tsx
168
170
  function useHoverState(setHoverState) {
169
- const ref = useRef(null);
170
- useEffect(() => {
171
- const controller = new AbortController();
172
- const { signal } = controller;
173
- ref.current?.addEventListener("mouseenter", () => setHoverState(true), {
174
- signal
175
- });
176
- ref.current?.addEventListener("mouseleave", () => setHoverState(false), {
177
- signal
178
- });
179
- return () => controller.abort();
180
- }, [setHoverState]);
181
- return ref;
171
+ const ref = useRef(null);
172
+ useEffect(() => {
173
+ const controller = new AbortController();
174
+ const { signal } = controller;
175
+ ref.current?.addEventListener("mouseenter", () => setHoverState(true), { signal });
176
+ ref.current?.addEventListener("mouseleave", () => setHoverState(false), { signal });
177
+ return () => controller.abort();
178
+ }, [setHoverState]);
179
+ return ref;
182
180
  }
183
181
 
184
- // src/toolbar/hooks/useImageURL.tsx
185
- import { useState } from "preact/hooks";
182
+ //#endregion
183
+ //#region src/toolbar/hooks/useImageURL.tsx
186
184
  function useImageURL() {
187
- const imageUrl = useImageURLIfAvailable();
188
- if (imageUrl == null) {
189
- throw new Error(
190
- `Shouldn't be rendering this component without an image URL`
191
- );
192
- }
193
- return imageUrl;
185
+ const imageUrl = useImageURLIfAvailable();
186
+ if (imageUrl == null) throw new Error(`Shouldn't be rendering this component without an image URL`);
187
+ return imageUrl;
194
188
  }
195
189
  function useImageURLIfAvailable() {
196
- const [imageUrlRef] = useState(() => {
197
- const meta = document.querySelector('meta[property="og:image"]');
198
- return meta?.getAttribute("content") ?? null;
199
- });
200
- return imageUrlRef;
190
+ const [imageUrlRef] = useState(() => {
191
+ const meta = document.querySelector("meta[property=\"og:image\"]");
192
+ return meta?.getAttribute("content") ?? null;
193
+ });
194
+ return imageUrlRef;
201
195
  }
202
196
 
203
- // src/toolbar/components/Image.tsx
204
- import { jsx as jsx5 } from "preact/jsx-runtime";
205
- function Image({
206
- imageSize,
207
- handleLoadError
208
- }) {
209
- const imageUrl = useImageURL();
210
- return /* @__PURE__ */ jsx5("div", { className: "image", children: /* @__PURE__ */ jsx5("a", { href: imageUrl, target: "_blank", title: "Open image in new tab", children: /* @__PURE__ */ jsx5(
211
- "img",
212
- {
213
- onError: handleLoadError,
214
- alt: "Open Graph",
215
- src: imageUrl,
216
- style: {
217
- maxHeight: "100%",
218
- maxWidth: `${imageSize}%`
219
- }
220
- }
221
- ) }) });
197
+ //#endregion
198
+ //#region src/toolbar/components/Image.tsx
199
+ function Image({ imageSize, handleLoadError }) {
200
+ const imageUrl = useImageURL();
201
+ return /* @__PURE__ */ jsx("div", {
202
+ className: "image",
203
+ children: /* @__PURE__ */ jsx("a", {
204
+ href: imageUrl,
205
+ target: "_blank",
206
+ title: "Open image in new tab",
207
+ children: /* @__PURE__ */ jsx("img", {
208
+ onError: handleLoadError,
209
+ alt: "Open Graph",
210
+ src: imageUrl,
211
+ style: {
212
+ maxHeight: "100%",
213
+ maxWidth: `${imageSize}%`
214
+ }
215
+ })
216
+ })
217
+ });
222
218
  }
223
219
 
224
- // src/toolbar/components/ZoomLabel.tsx
220
+ //#endregion
221
+ //#region src/toolbar/components/ZoomLabel.tsx
225
222
  function ZoomLabel({ imageSize }) {
226
- const formattedNumber = (imageSize / 100).toLocaleString(void 0, {
227
- minimumFractionDigits: 2
228
- });
229
- return `${formattedNumber}x`;
223
+ const formattedNumber = (imageSize / 100).toLocaleString(void 0, { minimumFractionDigits: 2 });
224
+ return `${formattedNumber}x`;
230
225
  }
231
226
 
232
- // src/toolbar/components/ZoomButton.tsx
233
- import { jsx as jsx6 } from "preact/jsx-runtime";
234
- function ZoomButton({
235
- value,
236
- imageSize,
237
- setImageSize
238
- }) {
239
- const isSelected = value === imageSize;
240
- return /* @__PURE__ */ jsx6(
241
- "astro-dev-toolbar-button",
242
- {
243
- size: "small",
244
- style: { padding: 0, margin: 0 },
245
- buttonStyle: isSelected ? "gray" : "ghost",
246
- className: "zoom-button",
247
- role: "radio",
248
- onClick: () => setImageSize(value),
249
- children: /* @__PURE__ */ jsx6(ZoomLabel, { imageSize: value })
250
- }
251
- );
227
+ //#endregion
228
+ //#region src/toolbar/components/ZoomButton.tsx
229
+ function ZoomButton({ value, imageSize, setImageSize }) {
230
+ const isSelected = value === imageSize;
231
+ return /* @__PURE__ */ jsx("astro-dev-toolbar-button", {
232
+ size: "small",
233
+ style: {
234
+ padding: 0,
235
+ margin: 0
236
+ },
237
+ buttonStyle: isSelected ? "gray" : "ghost",
238
+ className: "zoom-button",
239
+ role: "radio",
240
+ onClick: () => setImageSize(value),
241
+ children: /* @__PURE__ */ jsx(ZoomLabel, { imageSize: value })
242
+ });
252
243
  }
253
244
 
254
- // src/toolbar/components/ToolbarSection.tsx
255
- import { jsx as jsx7, jsxs as jsxs4 } from "preact/jsx-runtime";
256
- function ToolbarSection({
257
- icon,
258
- children
259
- }) {
260
- return /* @__PURE__ */ jsxs4(
261
- "div",
262
- {
263
- style: {
264
- fontSize: 12,
265
- display: "flex",
266
- alignItems: "center",
267
- columnGap: 5
268
- },
269
- children: [
270
- /* @__PURE__ */ jsx7(
271
- "div",
272
- {
273
- style: {
274
- display: "inline-block",
275
- width: 12,
276
- height: 12
277
- },
278
- children: icon
279
- }
280
- ),
281
- children
282
- ]
283
- }
284
- );
245
+ //#endregion
246
+ //#region src/toolbar/components/ToolbarSection.tsx
247
+ function ToolbarSection({ icon, children }) {
248
+ return /* @__PURE__ */ jsxs("div", {
249
+ style: {
250
+ fontSize: 12,
251
+ display: "flex",
252
+ alignItems: "center",
253
+ columnGap: 5
254
+ },
255
+ children: [/* @__PURE__ */ jsx("div", {
256
+ style: {
257
+ display: "inline-block",
258
+ width: 12,
259
+ height: 12
260
+ },
261
+ children: icon
262
+ }), children]
263
+ });
285
264
  }
286
265
 
287
- // src/toolbar/components/ImageZoomToolbar.tsx
288
- import { Fragment as Fragment2, jsx as jsx8, jsxs as jsxs5 } from "preact/jsx-runtime";
289
- function ImageZoomToolbar({
290
- isHovered,
291
- imageSize,
292
- setImageSize
293
- }) {
294
- return /* @__PURE__ */ jsx8(ToolbarSection, { icon: /* @__PURE__ */ jsx8("astro-dev-toolbar-icon", { icon: "gear" }), children: !isHovered ? /* @__PURE__ */ jsx8(
295
- ZoomButton,
296
- {
297
- value: imageSize,
298
- imageSize,
299
- setImageSize
300
- }
301
- ) : /* @__PURE__ */ jsxs5(Fragment2, { children: [
302
- /* @__PURE__ */ jsx8(
303
- ZoomButton,
304
- {
305
- value: 25,
306
- imageSize,
307
- setImageSize
308
- }
309
- ),
310
- /* @__PURE__ */ jsx8(
311
- ZoomButton,
312
- {
313
- value: 50,
314
- imageSize,
315
- setImageSize
316
- }
317
- ),
318
- /* @__PURE__ */ jsx8(
319
- ZoomButton,
320
- {
321
- value: 75,
322
- imageSize,
323
- setImageSize
324
- }
325
- ),
326
- /* @__PURE__ */ jsx8(
327
- ZoomButton,
328
- {
329
- value: 100,
330
- imageSize,
331
- setImageSize
332
- }
333
- )
334
- ] }) });
266
+ //#endregion
267
+ //#region src/toolbar/components/ImageZoomToolbar.tsx
268
+ function ImageZoomToolbar({ isHovered, imageSize, setImageSize }) {
269
+ return /* @__PURE__ */ jsx(ToolbarSection, {
270
+ icon: /* @__PURE__ */ jsx("astro-dev-toolbar-icon", { icon: "gear" }),
271
+ children: !isHovered ? /* @__PURE__ */ jsx(ZoomButton, {
272
+ value: imageSize,
273
+ imageSize,
274
+ setImageSize
275
+ }) : /* @__PURE__ */ jsxs(Fragment, { children: [
276
+ /* @__PURE__ */ jsx(ZoomButton, {
277
+ value: 25,
278
+ imageSize,
279
+ setImageSize
280
+ }),
281
+ /* @__PURE__ */ jsx(ZoomButton, {
282
+ value: 50,
283
+ imageSize,
284
+ setImageSize
285
+ }),
286
+ /* @__PURE__ */ jsx(ZoomButton, {
287
+ value: 75,
288
+ imageSize,
289
+ setImageSize
290
+ }),
291
+ /* @__PURE__ */ jsx(ZoomButton, {
292
+ value: 100,
293
+ imageSize,
294
+ setImageSize
295
+ })
296
+ ] })
297
+ });
335
298
  }
336
299
 
337
- // src/toolbar/components/CopyImageUrlButton.tsx
338
- import { useState as useState2, useRef as useRef2, useEffect as useEffect2, useCallback } from "preact/hooks";
339
- import { jsx as jsx9 } from "preact/jsx-runtime";
300
+ //#endregion
301
+ //#region src/toolbar/components/CopyImageUrlButton.tsx
340
302
  function CopyImageUrlButton() {
341
- const imageUrl = useImageURL();
342
- const [wasRecentlyClicked, setWasRecentlyClicked] = useState2(false);
343
- const checkTimer = useRef2(null);
344
- useEffect2(() => {
345
- if (wasRecentlyClicked && checkTimer.current == null) {
346
- checkTimer.current = setTimeout(() => {
347
- setWasRecentlyClicked(false);
348
- checkTimer.current = null;
349
- }, 3e3);
350
- }
351
- }, [wasRecentlyClicked]);
352
- const handleClick = useCallback(
353
- (evt) => {
354
- void navigator.clipboard.writeText(imageUrl);
355
- setWasRecentlyClicked(true);
356
- evt.stopPropagation();
357
- evt.preventDefault();
358
- },
359
- [imageUrl]
360
- );
361
- return /* @__PURE__ */ jsx9(ToolbarSection, { icon: /* @__PURE__ */ jsx9("astro-dev-toolbar-icon", { icon: "copy" }), children: /* @__PURE__ */ jsx9("div", { style: { display: "flex", alignItems: "center" }, children: /* @__PURE__ */ jsx9(
362
- "astro-dev-toolbar-button",
363
- {
364
- size: "small",
365
- buttonStyle: "gray",
366
- onClick: handleClick,
367
- children: wasRecentlyClicked ? "Copied to clipboard" : "Copy image URL"
368
- }
369
- ) }) });
303
+ const imageUrl = useImageURL();
304
+ const [wasRecentlyClicked, setWasRecentlyClicked] = useState(false);
305
+ const checkTimer = useRef(null);
306
+ useEffect(() => {
307
+ if (wasRecentlyClicked && checkTimer.current == null) checkTimer.current = setTimeout(() => {
308
+ setWasRecentlyClicked(false);
309
+ checkTimer.current = null;
310
+ }, 3e3);
311
+ }, [wasRecentlyClicked]);
312
+ const handleClick = useCallback((evt) => {
313
+ navigator.clipboard.writeText(imageUrl);
314
+ setWasRecentlyClicked(true);
315
+ evt.stopPropagation();
316
+ evt.preventDefault();
317
+ }, [imageUrl]);
318
+ return /* @__PURE__ */ jsx(ToolbarSection, {
319
+ icon: /* @__PURE__ */ jsx("astro-dev-toolbar-icon", { icon: "copy" }),
320
+ children: /* @__PURE__ */ jsx("div", {
321
+ style: {
322
+ display: "flex",
323
+ alignItems: "center"
324
+ },
325
+ children: /* @__PURE__ */ jsx("astro-dev-toolbar-button", {
326
+ size: "small",
327
+ buttonStyle: "gray",
328
+ onClick: handleClick,
329
+ children: wasRecentlyClicked ? "Copied to clipboard" : "Copy image URL"
330
+ })
331
+ })
332
+ });
370
333
  }
371
334
 
372
- // src/toolbar/components/ImageSection.tsx
373
- import { useState as useState3 } from "preact/hooks";
374
- import { Fragment as Fragment3, jsx as jsx10, jsxs as jsxs6 } from "preact/jsx-runtime";
375
- function ImageSection({
376
- isHovered,
377
- handleLoadError
378
- }) {
379
- const [imageSize, setImageSize] = useState3(100);
380
- return /* @__PURE__ */ jsxs6(Fragment3, { children: [
381
- /* @__PURE__ */ jsx10(Image, { imageSize, handleLoadError }),
382
- /* @__PURE__ */ jsxs6(
383
- "div",
384
- {
385
- "data-testid": "image-section-toolbar",
386
- style: {
387
- display: "flex",
388
- flexDirection: "row",
389
- alignItems: "center",
390
- columnGap: 15
391
- },
392
- children: [
393
- /* @__PURE__ */ jsx10(CopyImageUrlButton, {}),
394
- /* @__PURE__ */ jsx10(
395
- ImageZoomToolbar,
396
- {
397
- isHovered,
398
- imageSize,
399
- setImageSize
400
- }
401
- )
402
- ]
403
- }
404
- )
405
- ] });
335
+ //#endregion
336
+ //#region src/toolbar/components/ImageSection.tsx
337
+ function ImageSection({ isHovered, handleLoadError }) {
338
+ const [imageSize, setImageSize] = useState(100);
339
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Image, {
340
+ imageSize,
341
+ handleLoadError
342
+ }), /* @__PURE__ */ jsxs("div", {
343
+ "data-testid": "image-section-toolbar",
344
+ style: {
345
+ display: "flex",
346
+ flexDirection: "row",
347
+ alignItems: "center",
348
+ columnGap: 15
349
+ },
350
+ children: [/* @__PURE__ */ jsx(CopyImageUrlButton, {}), /* @__PURE__ */ jsx(ImageZoomToolbar, {
351
+ isHovered,
352
+ imageSize,
353
+ setImageSize
354
+ })]
355
+ })] });
406
356
  }
407
357
 
408
- // src/toolbar/components/Error.tsx
409
- import { jsx as jsx11, jsxs as jsxs7 } from "preact/jsx-runtime";
410
- function Error2({
411
- message,
412
- icon
413
- }) {
414
- return /* @__PURE__ */ jsxs7(
415
- "div",
416
- {
417
- style: {
418
- display: "flex",
419
- gap: 10,
420
- alignItems: "center"
421
- },
422
- children: [
423
- /* @__PURE__ */ jsx11("astro-dev-toolbar-icon", { style: { width: 24, height: 24 }, icon }),
424
- " ",
425
- message
426
- ]
427
- }
428
- );
358
+ //#endregion
359
+ //#region src/toolbar/components/Error.tsx
360
+ function Error$1({ message, icon }) {
361
+ return /* @__PURE__ */ jsxs("div", {
362
+ style: {
363
+ display: "flex",
364
+ gap: 10,
365
+ alignItems: "center"
366
+ },
367
+ children: [
368
+ /* @__PURE__ */ jsx("astro-dev-toolbar-icon", {
369
+ style: {
370
+ width: 24,
371
+ height: 24
372
+ },
373
+ icon
374
+ }),
375
+ " ",
376
+ message
377
+ ]
378
+ });
429
379
  }
430
380
 
431
- // src/toolbar/components/getRelativeUrl.tsx
381
+ //#endregion
382
+ //#region src/toolbar/components/getRelativeUrl.tsx
432
383
  function getRelativeUrl(absoluteUrl) {
433
- const url = new URL(absoluteUrl);
434
- return url.pathname;
384
+ const url = new URL(absoluteUrl);
385
+ return url.pathname;
435
386
  }
436
387
 
437
- // src/toolbar/components/ToolbarApp.tsx
438
- import { Fragment as Fragment4, jsx as jsx12, jsxs as jsxs8 } from "preact/jsx-runtime";
388
+ //#endregion
389
+ //#region src/toolbar/components/ToolbarApp.tsx
439
390
  function ToolbarApp() {
440
- const [isImageDetailsHovered, setIsImageDetailsHovered] = useState4(false);
441
- const imageDetailsRef = useHoverState(
442
- setIsImageDetailsHovered
443
- );
444
- const imageUrl = useImageURLIfAvailable();
445
- const [imageLoadStatus, setImageLoadStatus] = useState4(
446
- "pending"
447
- );
448
- if (imageUrl == null) {
449
- return /* @__PURE__ */ jsx12(Error2, { icon: "warning", message: "No Open Graph image found on this page" });
450
- } else if (imageLoadStatus === "error") {
451
- return /* @__PURE__ */ jsx12(
452
- Error2,
453
- {
454
- icon: "bug",
455
- message: `Error loading image at ${getRelativeUrl(imageUrl)}`
456
- }
457
- );
458
- }
459
- return /* @__PURE__ */ jsxs8(Fragment4, { children: [
460
- /* @__PURE__ */ jsxs8("details", { open: true, className: "image", ref: imageDetailsRef, children: [
461
- /* @__PURE__ */ jsx12(Summary, { children: "Image" }),
462
- /* @__PURE__ */ jsx12(
463
- ImageSection,
464
- {
465
- isHovered: isImageDetailsHovered,
466
- handleLoadError: () => setImageLoadStatus("error")
467
- }
468
- )
469
- ] }),
470
- /* @__PURE__ */ jsxs8("details", { children: [
471
- /* @__PURE__ */ jsx12(Summary, { children: "Meta Tags" }),
472
- /* @__PURE__ */ jsx12(MetaTags, {})
473
- ] })
474
- ] });
391
+ const [isImageDetailsHovered, setIsImageDetailsHovered] = useState(false);
392
+ const imageDetailsRef = useHoverState(setIsImageDetailsHovered);
393
+ const imageUrl = useImageURLIfAvailable();
394
+ const [imageLoadStatus, setImageLoadStatus] = useState("pending");
395
+ if (imageUrl == null) return /* @__PURE__ */ jsx(Error$1, {
396
+ icon: "warning",
397
+ message: "No Open Graph image found on this page"
398
+ });
399
+ else if (imageLoadStatus === "error") return /* @__PURE__ */ jsx(Error$1, {
400
+ icon: "bug",
401
+ message: `Error loading image at ${getRelativeUrl(imageUrl)}`
402
+ });
403
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("details", {
404
+ open: true,
405
+ className: "image",
406
+ ref: imageDetailsRef,
407
+ children: [/* @__PURE__ */ jsx(Summary, { children: "Image" }), /* @__PURE__ */ jsx(ImageSection, {
408
+ isHovered: isImageDetailsHovered,
409
+ handleLoadError: () => setImageLoadStatus("error")
410
+ })]
411
+ }), /* @__PURE__ */ jsxs("details", { children: [/* @__PURE__ */ jsx(Summary, { children: "Meta Tags" }), /* @__PURE__ */ jsx(MetaTags, {})] })] });
475
412
  }
476
413
 
477
- // src/toolbar/components/ToolbarAppWindow.tsx
478
- import { jsx as jsx13, jsxs as jsxs9 } from "preact/jsx-runtime";
414
+ //#endregion
415
+ //#region src/toolbar/components/ToolbarAppWindow.tsx
479
416
  function ToolbarAppWindow() {
480
- return /* @__PURE__ */ jsxs9("astro-dev-toolbar-window", { children: [
481
- /* @__PURE__ */ jsx13("style", { children: styles }),
482
- /* @__PURE__ */ jsx13(ToolbarApp, {})
483
- ] });
417
+ return /* @__PURE__ */ jsxs("astro-dev-toolbar-window", { children: [/* @__PURE__ */ jsx("style", { children: styles }), /* @__PURE__ */ jsx(ToolbarApp, {})] });
484
418
  }
485
419
 
486
- // src/toolbar/index.tsx
487
- import { jsx as jsx14 } from "preact/jsx-runtime";
488
- var SESSION_KEY_OPEN = "@altano/astro-opengraph/toolbar:is-open";
489
- var toolbar_default = defineToolbarApp({
490
- init(canvas, app) {
491
- app.onToggled((event) => {
492
- if (event.state) {
493
- sessionStorage.setItem(SESSION_KEY_OPEN, "true");
494
- render(/* @__PURE__ */ jsx14(ToolbarAppWindow, {}), canvas);
495
- } else {
496
- sessionStorage.removeItem(SESSION_KEY_OPEN);
497
- }
498
- });
499
- app.toggleNotification({
500
- state: document.querySelector('meta[property="og:image"]') != null,
501
- level: "info"
502
- });
503
- if (sessionStorage.getItem(SESSION_KEY_OPEN) != null) {
504
- app.toggleState({ state: true });
505
- }
506
- }
507
- });
508
- export {
509
- toolbar_default as default
510
- };
420
+ //#endregion
421
+ //#region src/toolbar/index.tsx
422
+ const SESSION_KEY_OPEN = "@altano/astro-opengraph/toolbar:is-open";
423
+ const app = defineToolbarApp({ init(canvas, app$1) {
424
+ app$1.onToggled((event) => {
425
+ if (event.state) {
426
+ sessionStorage.setItem(SESSION_KEY_OPEN, "true");
427
+ render(/* @__PURE__ */ jsx(ToolbarAppWindow, {}), canvas);
428
+ } else sessionStorage.removeItem(SESSION_KEY_OPEN);
429
+ });
430
+ app$1.toggleNotification({
431
+ state: document.querySelector("meta[property=\"og:image\"]") != null,
432
+ level: "info"
433
+ });
434
+ if (sessionStorage.getItem(SESSION_KEY_OPEN) != null) app$1.toggleState({ state: true });
435
+ } });
436
+ var toolbar_default = app;
437
+
438
+ //#endregion
439
+ export { toolbar_default as default };
440
+ //# sourceMappingURL=index.js.map