@altano/astro-opengraph 0.1.0-alpha.3 → 0.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.
- package/README.md +9 -0
- package/components/meta.astro +1 -1
- package/dist/config-CzK0JuaO.js +45 -0
- package/dist/config.d.ts +8 -3
- package/dist/config.js +3 -0
- package/dist/endpoint.d.ts +25 -11
- package/dist/endpoint.js +62 -126
- package/dist/index.d.ts +8 -2
- package/dist/index.js +41 -58
- package/dist/toolbar/index.d.ts +7 -2
- package/dist/toolbar/index.js +364 -396
- package/dist/types-Lk5HqHkQ.d.ts +71 -0
- package/package.json +28 -26
- package/dist/image.d.ts +0 -7
- package/dist/integration.d.ts +0 -5
- package/dist/toolbar/components/CopyImageUrlButton.d.ts +0 -3
- package/dist/toolbar/components/ExternalLinkicon.d.ts +0 -7
- package/dist/toolbar/components/Image.d.ts +0 -5
- package/dist/toolbar/components/ImageSection.d.ts +0 -4
- package/dist/toolbar/components/ImageZoomToolbar.d.ts +0 -7
- package/dist/toolbar/components/LinkOrText.d.ts +0 -7
- package/dist/toolbar/components/MetaTags.d.ts +0 -3
- package/dist/toolbar/components/Summary.d.ts +0 -5
- package/dist/toolbar/components/ToolbarApp.d.ts +0 -3
- package/dist/toolbar/components/ToolbarAppWindow.d.ts +0 -3
- package/dist/toolbar/components/ToolbarSection.d.ts +0 -6
- package/dist/toolbar/components/ZoomButton.d.ts +0 -7
- package/dist/toolbar/components/ZoomLabel.d.ts +0 -4
- package/dist/toolbar/hooks/useHoverState.d.ts +0 -3
- package/dist/toolbar/hooks/useImageURL.d.ts +0 -3
- package/dist/toolbar/hooks/useMetaTagInfo.d.ts +0 -3
- package/dist/toolbar/styles.d.ts +0 -2
- package/dist/types.d.ts +0 -67
- package/dist/virtual-user-config.d.ts +0 -8
package/dist/toolbar/index.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
import { createRoot } from "react-dom/client";
|
|
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
|
-
|
|
6
|
-
|
|
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,439 +33,408 @@ var styles = (
|
|
|
34
33
|
.image img {
|
|
35
34
|
transition: max-width 0.1s;
|
|
36
35
|
}
|
|
37
|
-
|
|
38
|
-
);
|
|
36
|
+
`;
|
|
39
37
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
// src/toolbar/components/Summary.tsx
|
|
44
|
-
import { jsx } from "react/jsx-runtime";
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/toolbar/components/Summary.tsx
|
|
45
40
|
function Summary({ children }) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
children
|
|
55
|
-
}
|
|
56
|
-
);
|
|
41
|
+
return /* @__PURE__ */ jsx("summary", {
|
|
42
|
+
style: {
|
|
43
|
+
cursor: "pointer",
|
|
44
|
+
fontWeight: 700,
|
|
45
|
+
color: "white"
|
|
46
|
+
},
|
|
47
|
+
children
|
|
48
|
+
});
|
|
57
49
|
}
|
|
58
50
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
function ExternalLinkicon({
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
] })
|
|
92
|
-
}
|
|
93
|
-
);
|
|
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
|
+
});
|
|
94
83
|
}
|
|
95
84
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
function LinkOrText({
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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;
|
|
115
110
|
}
|
|
116
111
|
|
|
117
|
-
|
|
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
|
+
};
|
|
118
131
|
function useMetaTagInfo() {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
tag.getAttribute("property")
|
|
123
|
-
]
|
|
124
|
-
);
|
|
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")]);
|
|
125
135
|
}
|
|
126
136
|
|
|
127
|
-
|
|
128
|
-
|
|
137
|
+
//#endregion
|
|
138
|
+
//#region src/toolbar/components/MetaTags.tsx
|
|
129
139
|
function MetaTags() {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
children: tags.map((tag) => /* @__PURE__ */ jsx4(MetaTagContent, { tag }, tag[1]))
|
|
143
|
-
}
|
|
144
|
-
);
|
|
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
|
+
});
|
|
145
152
|
}
|
|
146
153
|
function MetaTagContent({ tag }) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
),
|
|
160
|
-
/* @__PURE__ */ jsx4("dd", { style: { margin: 0 }, children: /* @__PURE__ */ jsx4(LinkOrText, { maybeLinkText: content }) })
|
|
161
|
-
] });
|
|
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
|
+
})] });
|
|
162
166
|
}
|
|
163
167
|
|
|
164
|
-
|
|
165
|
-
|
|
168
|
+
//#endregion
|
|
169
|
+
//#region src/toolbar/hooks/useHoverState.tsx
|
|
166
170
|
function useHoverState(setHoverState) {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
});
|
|
177
|
-
return () => controller.abort();
|
|
178
|
-
}, [setHoverState]);
|
|
179
|
-
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;
|
|
180
180
|
}
|
|
181
181
|
|
|
182
|
-
|
|
183
|
-
|
|
182
|
+
//#endregion
|
|
183
|
+
//#region src/toolbar/hooks/useImageURL.tsx
|
|
184
184
|
function useImageURL() {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
`Shouldn't be rendering this component without an image URL`
|
|
189
|
-
);
|
|
190
|
-
}
|
|
191
|
-
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;
|
|
192
188
|
}
|
|
193
189
|
function useImageURLIfAvailable() {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
190
|
+
const [imageUrlRef] = useState(() => {
|
|
191
|
+
const meta = document.querySelector("meta[property=\"og:image\"]");
|
|
192
|
+
return meta?.getAttribute("content") ?? null;
|
|
193
|
+
});
|
|
194
|
+
return imageUrlRef;
|
|
199
195
|
}
|
|
200
196
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
function Image({ imageSize }) {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
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
|
+
});
|
|
216
218
|
}
|
|
217
219
|
|
|
218
|
-
|
|
220
|
+
//#endregion
|
|
221
|
+
//#region src/toolbar/components/ZoomLabel.tsx
|
|
219
222
|
function ZoomLabel({ imageSize }) {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
});
|
|
223
|
-
return `${formattedNumber}x`;
|
|
223
|
+
const formattedNumber = (imageSize / 100).toLocaleString(void 0, { minimumFractionDigits: 2 });
|
|
224
|
+
return `${formattedNumber}x`;
|
|
224
225
|
}
|
|
225
226
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
function ZoomButton({
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
onClick: () => setImageSize(value),
|
|
243
|
-
children: /* @__PURE__ */ jsx6(ZoomLabel, { imageSize: value })
|
|
244
|
-
}
|
|
245
|
-
);
|
|
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
|
+
});
|
|
246
243
|
}
|
|
247
244
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
function ToolbarSection({
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
style: {
|
|
268
|
-
display: "inline-block",
|
|
269
|
-
width: 12,
|
|
270
|
-
height: 12
|
|
271
|
-
},
|
|
272
|
-
children: icon
|
|
273
|
-
}
|
|
274
|
-
),
|
|
275
|
-
children
|
|
276
|
-
]
|
|
277
|
-
}
|
|
278
|
-
);
|
|
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
|
+
});
|
|
279
264
|
}
|
|
280
265
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
function ImageZoomToolbar({
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
ZoomButton,
|
|
314
|
-
{
|
|
315
|
-
value: 75,
|
|
316
|
-
imageSize,
|
|
317
|
-
setImageSize
|
|
318
|
-
}
|
|
319
|
-
),
|
|
320
|
-
/* @__PURE__ */ jsx8(
|
|
321
|
-
ZoomButton,
|
|
322
|
-
{
|
|
323
|
-
value: 100,
|
|
324
|
-
imageSize,
|
|
325
|
-
setImageSize
|
|
326
|
-
}
|
|
327
|
-
)
|
|
328
|
-
] }) });
|
|
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
|
+
});
|
|
329
298
|
}
|
|
330
299
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
useState as useState2,
|
|
334
|
-
useRef as useRef2,
|
|
335
|
-
useEffect as useEffect2
|
|
336
|
-
} from "react";
|
|
337
|
-
import { jsx as jsx9 } from "react/jsx-runtime";
|
|
300
|
+
//#endregion
|
|
301
|
+
//#region src/toolbar/components/CopyImageUrlButton.tsx
|
|
338
302
|
function CopyImageUrlButton() {
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
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
|
+
});
|
|
333
|
+
}
|
|
334
|
+
|
|
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
|
+
})] });
|
|
368
356
|
}
|
|
369
357
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
/* @__PURE__ */ jsx10(
|
|
392
|
-
ImageZoomToolbar,
|
|
393
|
-
{
|
|
394
|
-
isHovered,
|
|
395
|
-
imageSize,
|
|
396
|
-
setImageSize
|
|
397
|
-
}
|
|
398
|
-
)
|
|
399
|
-
]
|
|
400
|
-
}
|
|
401
|
-
)
|
|
402
|
-
] });
|
|
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
|
+
});
|
|
403
379
|
}
|
|
404
380
|
|
|
405
|
-
|
|
406
|
-
|
|
381
|
+
//#endregion
|
|
382
|
+
//#region src/toolbar/components/getRelativeUrl.tsx
|
|
383
|
+
function getRelativeUrl(absoluteUrl) {
|
|
384
|
+
const url = new URL(absoluteUrl);
|
|
385
|
+
return url.pathname;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
//#endregion
|
|
389
|
+
//#region src/toolbar/components/ToolbarApp.tsx
|
|
407
390
|
function ToolbarApp() {
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
/* @__PURE__ */ jsx11(ImageSection, { isHovered: isImageDetailsHovered })
|
|
430
|
-
] }),
|
|
431
|
-
/* @__PURE__ */ jsxs7("details", { children: [
|
|
432
|
-
/* @__PURE__ */ jsx11(Summary, { children: "Meta Tags" }),
|
|
433
|
-
/* @__PURE__ */ jsx11(MetaTags, {})
|
|
434
|
-
] })
|
|
435
|
-
] });
|
|
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, {})] })] });
|
|
436
412
|
}
|
|
437
413
|
|
|
438
|
-
|
|
439
|
-
|
|
414
|
+
//#endregion
|
|
415
|
+
//#region src/toolbar/components/ToolbarAppWindow.tsx
|
|
440
416
|
function ToolbarAppWindow() {
|
|
441
|
-
|
|
442
|
-
/* @__PURE__ */ jsx12("style", { children: styles }),
|
|
443
|
-
/* @__PURE__ */ jsx12(ToolbarApp, {})
|
|
444
|
-
] });
|
|
417
|
+
return /* @__PURE__ */ jsxs("astro-dev-toolbar-window", { children: [/* @__PURE__ */ jsx("style", { children: styles }), /* @__PURE__ */ jsx(ToolbarApp, {})] });
|
|
445
418
|
}
|
|
446
419
|
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
}
|
|
469
|
-
});
|
|
470
|
-
export {
|
|
471
|
-
toolbar_default as default
|
|
472
|
-
};
|
|
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
|