@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.
- package/README.md +9 -0
- package/dist/config-CzK0JuaO.js +45 -0
- package/dist/config-CzK0JuaO.js.map +1 -0
- package/dist/config.d.ts +7 -3
- package/dist/config.js +3 -8
- package/dist/endpoint.d.ts +24 -11
- package/dist/endpoint.js +62 -85
- package/dist/endpoint.js.map +1 -0
- package/dist/index.d.ts +7 -2
- package/dist/index.js +41 -58
- package/dist/index.js.map +1 -0
- package/dist/toolbar/index.d.ts +6 -2
- package/dist/toolbar/index.js +359 -429
- package/dist/toolbar/index.js.map +1 -0
- package/dist/types-B1hoqgLx.d.ts +70 -0
- package/package.json +20 -17
- package/dist/chunk-DX3VCTOX.js +0 -49
- 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/Error.d.ts +0 -7
- package/dist/toolbar/components/ExternalLinkicon.d.ts +0 -7
- package/dist/toolbar/components/Image.d.ts +0 -6
- package/dist/toolbar/components/ImageSection.d.ts +0 -6
- 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 -7
- package/dist/toolbar/components/ZoomButton.d.ts +0 -7
- package/dist/toolbar/components/ZoomLabel.d.ts +0 -4
- package/dist/toolbar/components/getRelativeUrl.d.ts +0 -2
- 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
|
-
// 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
|
-
|
|
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,477 +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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
function ExternalLinkicon({
|
|
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
|
-
] })
|
|
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
|
-
|
|
99
|
-
|
|
100
|
-
function LinkOrText({
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
-
|
|
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
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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
|
-
|
|
130
|
-
|
|
137
|
+
//#endregion
|
|
138
|
+
//#region src/toolbar/components/MetaTags.tsx
|
|
131
139
|
function MetaTags() {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
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
|
-
|
|
167
|
-
|
|
168
|
+
//#endregion
|
|
169
|
+
//#region src/toolbar/hooks/useHoverState.tsx
|
|
168
170
|
function useHoverState(setHoverState) {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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
|
-
|
|
185
|
-
|
|
182
|
+
//#endregion
|
|
183
|
+
//#region src/toolbar/hooks/useImageURL.tsx
|
|
186
184
|
function useImageURL() {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
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
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
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
|
-
|
|
204
|
-
|
|
205
|
-
function Image({
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
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
|
-
|
|
220
|
+
//#endregion
|
|
221
|
+
//#region src/toolbar/components/ZoomLabel.tsx
|
|
225
222
|
function ZoomLabel({ imageSize }) {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
});
|
|
229
|
-
return `${formattedNumber}x`;
|
|
223
|
+
const formattedNumber = (imageSize / 100).toLocaleString(void 0, { minimumFractionDigits: 2 });
|
|
224
|
+
return `${formattedNumber}x`;
|
|
230
225
|
}
|
|
231
226
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
function ZoomButton({
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
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
|
-
|
|
255
|
-
|
|
256
|
-
function ToolbarSection({
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
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
|
-
|
|
288
|
-
|
|
289
|
-
function ImageZoomToolbar({
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
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
|
-
|
|
338
|
-
|
|
339
|
-
import { jsx as jsx9 } from "preact/jsx-runtime";
|
|
300
|
+
//#endregion
|
|
301
|
+
//#region src/toolbar/components/CopyImageUrlButton.tsx
|
|
340
302
|
function CopyImageUrlButton() {
|
|
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
|
-
|
|
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
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
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
|
-
|
|
409
|
-
|
|
410
|
-
function
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
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
|
-
|
|
381
|
+
//#endregion
|
|
382
|
+
//#region src/toolbar/components/getRelativeUrl.tsx
|
|
432
383
|
function getRelativeUrl(absoluteUrl) {
|
|
433
|
-
|
|
434
|
-
|
|
384
|
+
const url = new URL(absoluteUrl);
|
|
385
|
+
return url.pathname;
|
|
435
386
|
}
|
|
436
387
|
|
|
437
|
-
|
|
438
|
-
|
|
388
|
+
//#endregion
|
|
389
|
+
//#region src/toolbar/components/ToolbarApp.tsx
|
|
439
390
|
function ToolbarApp() {
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
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
|
-
|
|
478
|
-
|
|
414
|
+
//#endregion
|
|
415
|
+
//#region src/toolbar/components/ToolbarAppWindow.tsx
|
|
479
416
|
function ToolbarAppWindow() {
|
|
480
|
-
|
|
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
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
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
|