@altano/astro-opengraph 0.0.1-alpha.2 → 0.1.0-alpha.4
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 +4 -2
- package/components/meta.astro +11 -5
- package/dist/chunk-DX3VCTOX.js +49 -0
- package/dist/config.js +8 -0
- package/dist/endpoint.js +4 -45
- package/dist/index.d.ts +1 -0
- package/dist/toolbar/components/CopyImageUrlButton.d.ts +2 -2
- package/dist/toolbar/components/Error.d.ts +7 -0
- package/dist/toolbar/components/ExternalLinkicon.d.ts +2 -2
- package/dist/toolbar/components/Image.d.ts +4 -3
- package/dist/toolbar/components/ImageSection.d.ts +4 -2
- package/dist/toolbar/components/ImageZoomToolbar.d.ts +3 -3
- package/dist/toolbar/components/LinkOrText.d.ts +2 -2
- package/dist/toolbar/components/MetaTags.d.ts +2 -2
- package/dist/toolbar/components/Summary.d.ts +3 -3
- package/dist/toolbar/components/ToolbarApp.d.ts +2 -2
- package/dist/toolbar/components/ToolbarAppWindow.d.ts +2 -2
- package/dist/toolbar/components/ToolbarSection.d.ts +5 -4
- package/dist/toolbar/components/ZoomButton.d.ts +3 -3
- package/dist/toolbar/components/getRelativeUrl.d.ts +2 -0
- package/dist/toolbar/hooks/useHoverState.d.ts +2 -2
- package/dist/toolbar/index.js +88 -50
- package/package.json +16 -12
package/README.md
CHANGED
|
@@ -86,7 +86,7 @@ In order serve the component from the prior step as an image, you need a js/ts [
|
|
|
86
86
|
|
|
87
87
|
```ts
|
|
88
88
|
import opengraphTemplate from "../components/opengraph.astro";
|
|
89
|
-
import { makeOpengraphEndpoint } from "@altano/astro-opengraph";
|
|
89
|
+
import { makeOpengraphEndpoint } from "@altano/astro-opengraph/endpoint";
|
|
90
90
|
|
|
91
91
|
export const GET = makeOpengraphEndpoint({
|
|
92
92
|
template: opengraphTemplate,
|
|
@@ -142,6 +142,8 @@ import OpenGraphMeta from "@altano/astro-opengraph/components/meta.astro";
|
|
|
142
142
|
</html>
|
|
143
143
|
```
|
|
144
144
|
|
|
145
|
+
You can also provide an `alt` prop which would set the `og:image:alt` meta tag, but my understanding is that it isn't well supported, so feel free to omit this.
|
|
146
|
+
|
|
145
147
|
If you want the `OpenGraphMeta` component to use a different set of defaults for your whole site, you can provide the `componentMetaTagFallbacks` integration config, e.g. to provide a default title:
|
|
146
148
|
|
|
147
149
|
```ts
|
|
@@ -274,7 +276,7 @@ It doesn't matter where you put your Open Graph component or endpoints, as long
|
|
|
274
276
|
```ts
|
|
275
277
|
// import your component, wherever it is
|
|
276
278
|
import opengraphTemplate from "../components/my-custom-component.astro";
|
|
277
|
-
import { makeOpengraphEndpoint } from "@altano/astro-opengraph";
|
|
279
|
+
import { makeOpengraphEndpoint } from "@altano/astro-opengraph/endpoint";
|
|
278
280
|
|
|
279
281
|
export const GET = makeOpengraphEndpoint({
|
|
280
282
|
template: opengraphTemplate,
|
package/components/meta.astro
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
---
|
|
2
|
-
import { getResolvedConfig } from "
|
|
2
|
+
import { getResolvedConfig } from "@altano/astro-opengraph/config";
|
|
3
3
|
|
|
4
4
|
export type Props = {
|
|
5
5
|
/**
|
|
@@ -21,6 +21,10 @@ export type Props = {
|
|
|
21
21
|
* something else, provide the path to the resulting image here.
|
|
22
22
|
*/
|
|
23
23
|
image?: string;
|
|
24
|
+
/**
|
|
25
|
+
* The specification says "A description of what is in the image (not a caption). If the page specifies an og:image it should specify og:image:alt." but people have found this to be poorly supported. Use if you want.
|
|
26
|
+
*/
|
|
27
|
+
alt?: string;
|
|
24
28
|
/**
|
|
25
29
|
* Override the width, which otherwise defaults to:
|
|
26
30
|
*
|
|
@@ -42,9 +46,9 @@ export type Props = {
|
|
|
42
46
|
*/
|
|
43
47
|
height?: number;
|
|
44
48
|
/**
|
|
45
|
-
* Override
|
|
49
|
+
* Override `og:image:type` MIME type, which defaults to "image/png"
|
|
46
50
|
*/
|
|
47
|
-
|
|
51
|
+
type?: string;
|
|
48
52
|
};
|
|
49
53
|
|
|
50
54
|
const { imageOptions, componentMetaTagFallbacks } = await getResolvedConfig();
|
|
@@ -56,12 +60,13 @@ const {
|
|
|
56
60
|
} = componentMetaTagFallbacks;
|
|
57
61
|
|
|
58
62
|
const {
|
|
63
|
+
alt,
|
|
59
64
|
title = titleFallback,
|
|
60
65
|
description = descriptionFallback,
|
|
61
66
|
image = imageUrlFallback,
|
|
62
67
|
width = imageOptions.width,
|
|
63
68
|
height = imageOptions.height,
|
|
64
|
-
|
|
69
|
+
type = "image/png",
|
|
65
70
|
} = Astro.props;
|
|
66
71
|
|
|
67
72
|
const urlStr = Astro.url.toString();
|
|
@@ -72,6 +77,7 @@ const opengraphImageUrl = new URL(image, urlWithTrailingSlash);
|
|
|
72
77
|
{title && <meta property="og:title" content={title} />}
|
|
73
78
|
{description && <meta property="og:description" content={description} />}
|
|
74
79
|
<meta property="og:image" content={opengraphImageUrl.toString()} />
|
|
75
|
-
<meta property="og:image:
|
|
80
|
+
{alt && <meta property="og:image:alt" content={alt} />}
|
|
81
|
+
<meta property="og:image:type" content={type} />
|
|
76
82
|
<meta property="og:image:width" content={width.toString()} />
|
|
77
83
|
<meta property="og:image:height" content={height.toString()} />
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// src/config.ts
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
async function deserializeVirtualConfig(configMaybeMocked) {
|
|
4
|
+
const config = typeof configMaybeMocked === "function" ? configMaybeMocked() : configMaybeMocked;
|
|
5
|
+
const fontsWithBuffers = await Promise.all(
|
|
6
|
+
config.imageOptions.fonts.map(async (font) => {
|
|
7
|
+
const data = await readFile(font.path);
|
|
8
|
+
return {
|
|
9
|
+
...font,
|
|
10
|
+
data
|
|
11
|
+
};
|
|
12
|
+
})
|
|
13
|
+
);
|
|
14
|
+
return {
|
|
15
|
+
...config,
|
|
16
|
+
imageOptions: {
|
|
17
|
+
...config.imageOptions,
|
|
18
|
+
fonts: fontsWithBuffers
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
var imageOptionDefaults = {
|
|
23
|
+
width: 1200,
|
|
24
|
+
height: 630
|
|
25
|
+
};
|
|
26
|
+
var metaTagDefaults = {
|
|
27
|
+
"og:image": `/opengraph.png`
|
|
28
|
+
};
|
|
29
|
+
async function getResolvedConfig() {
|
|
30
|
+
const module = await import("virtual:astro-opengraph/user-config");
|
|
31
|
+
const lazyConfig = module.default;
|
|
32
|
+
const deserialized = await deserializeVirtualConfig(lazyConfig);
|
|
33
|
+
return {
|
|
34
|
+
...deserialized,
|
|
35
|
+
imageOptions: {
|
|
36
|
+
...imageOptionDefaults,
|
|
37
|
+
...deserialized.imageOptions
|
|
38
|
+
},
|
|
39
|
+
componentMetaTagFallbacks: {
|
|
40
|
+
...deserialized.componentMetaTagFallbacks,
|
|
41
|
+
...metaTagDefaults
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export {
|
|
47
|
+
deserializeVirtualConfig,
|
|
48
|
+
getResolvedConfig
|
|
49
|
+
};
|
package/dist/config.js
ADDED
package/dist/endpoint.js
CHANGED
|
@@ -1,52 +1,11 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getResolvedConfig
|
|
3
|
+
} from "./chunk-DX3VCTOX.js";
|
|
4
|
+
|
|
1
5
|
// src/endpoint.ts
|
|
2
6
|
import { experimental_AstroContainer } from "astro/container";
|
|
3
7
|
import { isAstroComponentFactory } from "astro/runtime/server/render/astro/factory.js";
|
|
4
8
|
|
|
5
|
-
// src/config.ts
|
|
6
|
-
import { readFile } from "node:fs/promises";
|
|
7
|
-
async function deserializeVirtualConfig(configMaybeMocked) {
|
|
8
|
-
const config = typeof configMaybeMocked === "function" ? configMaybeMocked() : configMaybeMocked;
|
|
9
|
-
const fontsWithBuffers = await Promise.all(
|
|
10
|
-
config.imageOptions.fonts.map(async (font) => {
|
|
11
|
-
const data = await readFile(font.path);
|
|
12
|
-
return {
|
|
13
|
-
...font,
|
|
14
|
-
data
|
|
15
|
-
};
|
|
16
|
-
})
|
|
17
|
-
);
|
|
18
|
-
return {
|
|
19
|
-
...config,
|
|
20
|
-
imageOptions: {
|
|
21
|
-
...config.imageOptions,
|
|
22
|
-
fonts: fontsWithBuffers
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
var imageOptionDefaults = {
|
|
27
|
-
width: 1200,
|
|
28
|
-
height: 630
|
|
29
|
-
};
|
|
30
|
-
var metaTagDefaults = {
|
|
31
|
-
"og:image": `/opengraph.png`
|
|
32
|
-
};
|
|
33
|
-
async function getResolvedConfig() {
|
|
34
|
-
const module = await import("virtual:astro-opengraph/user-config");
|
|
35
|
-
const lazyConfig = module.default;
|
|
36
|
-
const deserialized = await deserializeVirtualConfig(lazyConfig);
|
|
37
|
-
return {
|
|
38
|
-
...deserialized,
|
|
39
|
-
imageOptions: {
|
|
40
|
-
...imageOptionDefaults,
|
|
41
|
-
...deserialized.imageOptions
|
|
42
|
-
},
|
|
43
|
-
componentMetaTagFallbacks: {
|
|
44
|
-
...deserialized.componentMetaTagFallbacks,
|
|
45
|
-
...metaTagDefaults
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
|
|
50
9
|
// src/image.ts
|
|
51
10
|
import { getConfiguredImageService, imageConfig } from "astro:assets";
|
|
52
11
|
import satori from "satori";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
export declare function CopyImageUrlButton():
|
|
1
|
+
import type Preact from "preact";
|
|
2
|
+
export declare function CopyImageUrlButton(): Preact.JSX.Element;
|
|
3
3
|
//# sourceMappingURL=CopyImageUrlButton.d.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Icon } from "astro/runtime/client/dev-toolbar/ui-library/icons.js";
|
|
2
|
+
import type Preact from "preact";
|
|
3
|
+
export declare function Error({ message, icon, }: {
|
|
4
|
+
message: string;
|
|
5
|
+
icon: Icon;
|
|
6
|
+
}): Preact.JSX.Element;
|
|
7
|
+
//# sourceMappingURL=Error.d.ts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type Preact from "preact";
|
|
2
2
|
export declare function ExternalLinkicon({ width, height, fill, }: {
|
|
3
3
|
width?: number;
|
|
4
4
|
height?: number;
|
|
5
5
|
fill?: string;
|
|
6
|
-
}):
|
|
6
|
+
}): Preact.JSX.Element;
|
|
7
7
|
//# sourceMappingURL=ExternalLinkicon.d.ts.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
export declare function Image({ imageSize }: {
|
|
1
|
+
import type Preact from "preact";
|
|
2
|
+
export declare function Image({ imageSize, handleLoadError, }: {
|
|
3
3
|
imageSize: number;
|
|
4
|
-
|
|
4
|
+
handleLoadError: () => void;
|
|
5
|
+
}): Preact.JSX.Element;
|
|
5
6
|
//# sourceMappingURL=Image.d.ts.map
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import type Preact from "preact";
|
|
2
|
+
export declare function ImageSection({ isHovered, handleLoadError, }: {
|
|
2
3
|
isHovered: boolean;
|
|
3
|
-
|
|
4
|
+
handleLoadError: () => void;
|
|
5
|
+
}): Preact.JSX.Element;
|
|
4
6
|
//# sourceMappingURL=ImageSection.d.ts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type Preact from "preact";
|
|
2
2
|
export declare function ImageZoomToolbar({ isHovered, imageSize, setImageSize, }: {
|
|
3
3
|
isHovered: boolean;
|
|
4
4
|
imageSize: number;
|
|
5
|
-
setImageSize:
|
|
6
|
-
}):
|
|
5
|
+
setImageSize: (size: number) => void;
|
|
6
|
+
}): Preact.JSX.Element;
|
|
7
7
|
//# sourceMappingURL=ImageZoomToolbar.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
type LinkOrTextType =
|
|
1
|
+
import type Preact from "preact";
|
|
2
|
+
type LinkOrTextType = Preact.JSX.Element | string | null;
|
|
3
3
|
export declare function LinkOrText({ maybeLinkText, }: {
|
|
4
4
|
maybeLinkText: string | null;
|
|
5
5
|
}): LinkOrTextType;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type
|
|
2
|
-
export declare function MetaTags():
|
|
1
|
+
import type Preact from "preact";
|
|
2
|
+
export declare function MetaTags(): Preact.JSX.Element;
|
|
3
3
|
//# sourceMappingURL=MetaTags.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
export declare function Summary({ children }: {
|
|
1
|
+
import type Preact from "preact";
|
|
2
|
+
export declare function Summary({ children, }: {
|
|
3
3
|
children: string;
|
|
4
|
-
}):
|
|
4
|
+
}): Preact.JSX.Element;
|
|
5
5
|
//# sourceMappingURL=Summary.d.ts.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
export declare function ToolbarApp():
|
|
1
|
+
import type Preact from "preact";
|
|
2
|
+
export declare function ToolbarApp(): Preact.JSX.Element;
|
|
3
3
|
//# sourceMappingURL=ToolbarApp.d.ts.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type
|
|
2
|
-
export declare function ToolbarAppWindow():
|
|
1
|
+
import type Preact from "preact";
|
|
2
|
+
export declare function ToolbarAppWindow(): Preact.JSX.Element;
|
|
3
3
|
//# sourceMappingURL=ToolbarAppWindow.d.ts.map
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type { ComponentChildren } from "preact";
|
|
2
|
+
import type Preact from "preact";
|
|
2
3
|
export declare function ToolbarSection({ icon, children, }: {
|
|
3
|
-
icon:
|
|
4
|
-
children:
|
|
5
|
-
}):
|
|
4
|
+
icon: Preact.JSX.Element;
|
|
5
|
+
children: ComponentChildren;
|
|
6
|
+
}): Preact.JSX.Element;
|
|
6
7
|
//# sourceMappingURL=ToolbarSection.d.ts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type Preact from "preact";
|
|
2
2
|
export declare function ZoomButton({ value, imageSize, setImageSize, }: {
|
|
3
3
|
value: number;
|
|
4
4
|
imageSize: number;
|
|
5
|
-
setImageSize:
|
|
6
|
-
}):
|
|
5
|
+
setImageSize: (size: number) => void;
|
|
6
|
+
}): Preact.JSX.Element;
|
|
7
7
|
//# sourceMappingURL=ZoomButton.d.ts.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
export declare function useHoverState<TElement extends HTMLElement>(setHoverState:
|
|
1
|
+
import type Preact from "preact";
|
|
2
|
+
export declare function useHoverState<TElement extends HTMLElement>(setHoverState: (isHover: boolean) => void): Preact.RefObject<TElement>;
|
|
3
3
|
//# sourceMappingURL=useHoverState.d.ts.map
|
package/dist/toolbar/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/toolbar/index.tsx
|
|
2
|
-
import {
|
|
2
|
+
import { render } from "preact";
|
|
3
3
|
import { defineToolbarApp } from "astro/toolbar";
|
|
4
4
|
|
|
5
5
|
// src/toolbar/styles.tsx
|
|
@@ -38,11 +38,13 @@ var styles = (
|
|
|
38
38
|
);
|
|
39
39
|
|
|
40
40
|
// src/toolbar/components/ToolbarApp.tsx
|
|
41
|
-
import { useState as useState4 } from "
|
|
41
|
+
import { useState as useState4 } from "preact/hooks";
|
|
42
42
|
|
|
43
43
|
// src/toolbar/components/Summary.tsx
|
|
44
|
-
import { jsx } from "
|
|
45
|
-
function Summary({
|
|
44
|
+
import { jsx } from "preact/jsx-runtime";
|
|
45
|
+
function Summary({
|
|
46
|
+
children
|
|
47
|
+
}) {
|
|
46
48
|
return /* @__PURE__ */ jsx(
|
|
47
49
|
"summary",
|
|
48
50
|
{
|
|
@@ -57,7 +59,7 @@ function Summary({ children }) {
|
|
|
57
59
|
}
|
|
58
60
|
|
|
59
61
|
// src/toolbar/components/ExternalLinkicon.tsx
|
|
60
|
-
import { jsx as jsx2, jsxs } from "
|
|
62
|
+
import { jsx as jsx2, jsxs } from "preact/jsx-runtime";
|
|
61
63
|
function ExternalLinkicon({
|
|
62
64
|
width = 27,
|
|
63
65
|
height = 27,
|
|
@@ -94,7 +96,7 @@ function ExternalLinkicon({
|
|
|
94
96
|
}
|
|
95
97
|
|
|
96
98
|
// src/toolbar/components/LinkOrText.tsx
|
|
97
|
-
import { jsx as jsx3, jsxs as jsxs2 } from "
|
|
99
|
+
import { jsx as jsx3, jsxs as jsxs2 } from "preact/jsx-runtime";
|
|
98
100
|
function LinkOrText({
|
|
99
101
|
maybeLinkText
|
|
100
102
|
}) {
|
|
@@ -125,7 +127,7 @@ function useMetaTagInfo() {
|
|
|
125
127
|
}
|
|
126
128
|
|
|
127
129
|
// src/toolbar/components/MetaTags.tsx
|
|
128
|
-
import { Fragment, jsx as jsx4, jsxs as jsxs3 } from "
|
|
130
|
+
import { Fragment, jsx as jsx4, jsxs as jsxs3 } from "preact/jsx-runtime";
|
|
129
131
|
function MetaTags() {
|
|
130
132
|
const tags = useMetaTagInfo();
|
|
131
133
|
return /* @__PURE__ */ jsx4(
|
|
@@ -162,7 +164,7 @@ function MetaTagContent({ tag }) {
|
|
|
162
164
|
}
|
|
163
165
|
|
|
164
166
|
// src/toolbar/hooks/useHoverState.tsx
|
|
165
|
-
import { useRef, useEffect } from "
|
|
167
|
+
import { useRef, useEffect } from "preact/hooks";
|
|
166
168
|
function useHoverState(setHoverState) {
|
|
167
169
|
const ref = useRef(null);
|
|
168
170
|
useEffect(() => {
|
|
@@ -180,7 +182,7 @@ function useHoverState(setHoverState) {
|
|
|
180
182
|
}
|
|
181
183
|
|
|
182
184
|
// src/toolbar/hooks/useImageURL.tsx
|
|
183
|
-
import { useState } from "
|
|
185
|
+
import { useState } from "preact/hooks";
|
|
184
186
|
function useImageURL() {
|
|
185
187
|
const imageUrl = useImageURLIfAvailable();
|
|
186
188
|
if (imageUrl == null) {
|
|
@@ -199,12 +201,16 @@ function useImageURLIfAvailable() {
|
|
|
199
201
|
}
|
|
200
202
|
|
|
201
203
|
// src/toolbar/components/Image.tsx
|
|
202
|
-
import { jsx as jsx5 } from "
|
|
203
|
-
function Image({
|
|
204
|
+
import { jsx as jsx5 } from "preact/jsx-runtime";
|
|
205
|
+
function Image({
|
|
206
|
+
imageSize,
|
|
207
|
+
handleLoadError
|
|
208
|
+
}) {
|
|
204
209
|
const imageUrl = useImageURL();
|
|
205
210
|
return /* @__PURE__ */ jsx5("div", { className: "image", children: /* @__PURE__ */ jsx5("a", { href: imageUrl, target: "_blank", title: "Open image in new tab", children: /* @__PURE__ */ jsx5(
|
|
206
211
|
"img",
|
|
207
212
|
{
|
|
213
|
+
onError: handleLoadError,
|
|
208
214
|
alt: "Open Graph",
|
|
209
215
|
src: imageUrl,
|
|
210
216
|
style: {
|
|
@@ -224,7 +230,7 @@ function ZoomLabel({ imageSize }) {
|
|
|
224
230
|
}
|
|
225
231
|
|
|
226
232
|
// src/toolbar/components/ZoomButton.tsx
|
|
227
|
-
import { jsx as jsx6 } from "
|
|
233
|
+
import { jsx as jsx6 } from "preact/jsx-runtime";
|
|
228
234
|
function ZoomButton({
|
|
229
235
|
value,
|
|
230
236
|
imageSize,
|
|
@@ -246,7 +252,7 @@ function ZoomButton({
|
|
|
246
252
|
}
|
|
247
253
|
|
|
248
254
|
// src/toolbar/components/ToolbarSection.tsx
|
|
249
|
-
import { jsx as jsx7, jsxs as jsxs4 } from "
|
|
255
|
+
import { jsx as jsx7, jsxs as jsxs4 } from "preact/jsx-runtime";
|
|
250
256
|
function ToolbarSection({
|
|
251
257
|
icon,
|
|
252
258
|
children
|
|
@@ -279,7 +285,7 @@ function ToolbarSection({
|
|
|
279
285
|
}
|
|
280
286
|
|
|
281
287
|
// src/toolbar/components/ImageZoomToolbar.tsx
|
|
282
|
-
import { Fragment as Fragment2, jsx as jsx8, jsxs as jsxs5 } from "
|
|
288
|
+
import { Fragment as Fragment2, jsx as jsx8, jsxs as jsxs5 } from "preact/jsx-runtime";
|
|
283
289
|
function ImageZoomToolbar({
|
|
284
290
|
isHovered,
|
|
285
291
|
imageSize,
|
|
@@ -329,12 +335,8 @@ function ImageZoomToolbar({
|
|
|
329
335
|
}
|
|
330
336
|
|
|
331
337
|
// src/toolbar/components/CopyImageUrlButton.tsx
|
|
332
|
-
import
|
|
333
|
-
|
|
334
|
-
useRef as useRef2,
|
|
335
|
-
useEffect as useEffect2
|
|
336
|
-
} from "react";
|
|
337
|
-
import { jsx as jsx9 } from "react/jsx-runtime";
|
|
338
|
+
import { useState as useState2, useRef as useRef2, useEffect as useEffect2, useCallback } from "preact/hooks";
|
|
339
|
+
import { jsx as jsx9 } from "preact/jsx-runtime";
|
|
338
340
|
function CopyImageUrlButton() {
|
|
339
341
|
const imageUrl = useImageURL();
|
|
340
342
|
const [wasRecentlyClicked, setWasRecentlyClicked] = useState2(false);
|
|
@@ -347,7 +349,7 @@ function CopyImageUrlButton() {
|
|
|
347
349
|
}, 3e3);
|
|
348
350
|
}
|
|
349
351
|
}, [wasRecentlyClicked]);
|
|
350
|
-
const handleClick =
|
|
352
|
+
const handleClick = useCallback(
|
|
351
353
|
(evt) => {
|
|
352
354
|
void navigator.clipboard.writeText(imageUrl);
|
|
353
355
|
setWasRecentlyClicked(true);
|
|
@@ -368,14 +370,15 @@ function CopyImageUrlButton() {
|
|
|
368
370
|
}
|
|
369
371
|
|
|
370
372
|
// src/toolbar/components/ImageSection.tsx
|
|
371
|
-
import { useState as useState3 } from "
|
|
372
|
-
import { Fragment as Fragment3, jsx as jsx10, jsxs as jsxs6 } from "
|
|
373
|
+
import { useState as useState3 } from "preact/hooks";
|
|
374
|
+
import { Fragment as Fragment3, jsx as jsx10, jsxs as jsxs6 } from "preact/jsx-runtime";
|
|
373
375
|
function ImageSection({
|
|
374
|
-
isHovered
|
|
376
|
+
isHovered,
|
|
377
|
+
handleLoadError
|
|
375
378
|
}) {
|
|
376
379
|
const [imageSize, setImageSize] = useState3(100);
|
|
377
380
|
return /* @__PURE__ */ jsxs6(Fragment3, { children: [
|
|
378
|
-
/* @__PURE__ */ jsx10(Image, { imageSize }),
|
|
381
|
+
/* @__PURE__ */ jsx10(Image, { imageSize, handleLoadError }),
|
|
379
382
|
/* @__PURE__ */ jsxs6(
|
|
380
383
|
"div",
|
|
381
384
|
{
|
|
@@ -402,58 +405,93 @@ function ImageSection({
|
|
|
402
405
|
] });
|
|
403
406
|
}
|
|
404
407
|
|
|
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
|
+
);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
// src/toolbar/components/getRelativeUrl.tsx
|
|
432
|
+
function getRelativeUrl(absoluteUrl) {
|
|
433
|
+
const url = new URL(absoluteUrl);
|
|
434
|
+
return url.pathname;
|
|
435
|
+
}
|
|
436
|
+
|
|
405
437
|
// src/toolbar/components/ToolbarApp.tsx
|
|
406
|
-
import { Fragment as Fragment4, jsx as
|
|
438
|
+
import { Fragment as Fragment4, jsx as jsx12, jsxs as jsxs8 } from "preact/jsx-runtime";
|
|
407
439
|
function ToolbarApp() {
|
|
408
440
|
const [isImageDetailsHovered, setIsImageDetailsHovered] = useState4(false);
|
|
409
441
|
const imageDetailsRef = useHoverState(
|
|
410
442
|
setIsImageDetailsHovered
|
|
411
443
|
);
|
|
412
444
|
const imageUrl = useImageURLIfAvailable();
|
|
445
|
+
const [imageLoadStatus, setImageLoadStatus] = useState4(
|
|
446
|
+
"pending"
|
|
447
|
+
);
|
|
413
448
|
if (imageUrl == null) {
|
|
414
|
-
return /* @__PURE__ */
|
|
415
|
-
|
|
416
|
-
|
|
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,
|
|
417
464
|
{
|
|
418
|
-
|
|
419
|
-
|
|
465
|
+
isHovered: isImageDetailsHovered,
|
|
466
|
+
handleLoadError: () => setImageLoadStatus("error")
|
|
420
467
|
}
|
|
421
|
-
)
|
|
422
|
-
" ",
|
|
423
|
-
"No Open Graph image found on this page"
|
|
424
|
-
] });
|
|
425
|
-
}
|
|
426
|
-
return /* @__PURE__ */ jsxs7(Fragment4, { children: [
|
|
427
|
-
/* @__PURE__ */ jsxs7("details", { open: true, className: "image", ref: imageDetailsRef, children: [
|
|
428
|
-
/* @__PURE__ */ jsx11(Summary, { children: "Image" }),
|
|
429
|
-
/* @__PURE__ */ jsx11(ImageSection, { isHovered: isImageDetailsHovered })
|
|
468
|
+
)
|
|
430
469
|
] }),
|
|
431
|
-
/* @__PURE__ */
|
|
432
|
-
/* @__PURE__ */
|
|
433
|
-
/* @__PURE__ */
|
|
470
|
+
/* @__PURE__ */ jsxs8("details", { children: [
|
|
471
|
+
/* @__PURE__ */ jsx12(Summary, { children: "Meta Tags" }),
|
|
472
|
+
/* @__PURE__ */ jsx12(MetaTags, {})
|
|
434
473
|
] })
|
|
435
474
|
] });
|
|
436
475
|
}
|
|
437
476
|
|
|
438
477
|
// src/toolbar/components/ToolbarAppWindow.tsx
|
|
439
|
-
import { jsx as
|
|
478
|
+
import { jsx as jsx13, jsxs as jsxs9 } from "preact/jsx-runtime";
|
|
440
479
|
function ToolbarAppWindow() {
|
|
441
|
-
return /* @__PURE__ */
|
|
442
|
-
/* @__PURE__ */
|
|
443
|
-
/* @__PURE__ */
|
|
480
|
+
return /* @__PURE__ */ jsxs9("astro-dev-toolbar-window", { children: [
|
|
481
|
+
/* @__PURE__ */ jsx13("style", { children: styles }),
|
|
482
|
+
/* @__PURE__ */ jsx13(ToolbarApp, {})
|
|
444
483
|
] });
|
|
445
484
|
}
|
|
446
485
|
|
|
447
486
|
// src/toolbar/index.tsx
|
|
448
|
-
import { jsx as
|
|
487
|
+
import { jsx as jsx14 } from "preact/jsx-runtime";
|
|
449
488
|
var SESSION_KEY_OPEN = "@altano/astro-opengraph/toolbar:is-open";
|
|
450
489
|
var toolbar_default = defineToolbarApp({
|
|
451
490
|
init(canvas, app) {
|
|
452
|
-
const root = createRoot(canvas);
|
|
453
491
|
app.onToggled((event) => {
|
|
454
492
|
if (event.state) {
|
|
455
493
|
sessionStorage.setItem(SESSION_KEY_OPEN, "true");
|
|
456
|
-
|
|
494
|
+
render(/* @__PURE__ */ jsx14(ToolbarAppWindow, {}), canvas);
|
|
457
495
|
} else {
|
|
458
496
|
sessionStorage.removeItem(SESSION_KEY_OPEN);
|
|
459
497
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@altano/astro-opengraph",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0-alpha.4",
|
|
4
4
|
"description": "Open Graph Tools for Astro",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"astro",
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"exports": {
|
|
26
26
|
".": "./dist/index.js",
|
|
27
27
|
"./components/meta.astro": "./components/meta.astro",
|
|
28
|
+
"./config": "./dist/config.js",
|
|
28
29
|
"./endpoint": "./dist/endpoint.js",
|
|
29
30
|
"./toolbar": "./dist/toolbar/index.js"
|
|
30
31
|
},
|
|
@@ -40,36 +41,38 @@
|
|
|
40
41
|
"satori-html": "^0.3.2"
|
|
41
42
|
},
|
|
42
43
|
"devDependencies": {
|
|
44
|
+
"@astrojs/check": "^0.9.4",
|
|
45
|
+
"@astrojs/preact": "^4.0.8",
|
|
46
|
+
"@astrojs/svelte": "^7.0.9",
|
|
47
|
+
"@astrojs/vue": "^5.0.9",
|
|
43
48
|
"@inox-tools/astro-tests": "0.5.1",
|
|
44
49
|
"@playwright/test": "1.47.0",
|
|
45
50
|
"@types/he": "^1.2.3",
|
|
46
51
|
"@types/jest-image-snapshot": "^6.4.0",
|
|
47
52
|
"@types/node": "^22.13.10",
|
|
48
|
-
"@types/react": "^19.0.12",
|
|
49
|
-
"@types/react-dom": "^19.0.4",
|
|
50
53
|
"@vitest/coverage-v8": "^3.1.1",
|
|
51
54
|
"astro": "^5.5.6",
|
|
52
55
|
"depcheck": "^1.4.7",
|
|
53
56
|
"jest-image-snapshot": "^6.4.0",
|
|
54
|
-
"
|
|
55
|
-
"react-dom": "^19.1.0",
|
|
57
|
+
"preact": "^10.26.5",
|
|
56
58
|
"sharp": "^0.33.1",
|
|
59
|
+
"svelte": "^5.25.12",
|
|
57
60
|
"tsup": "^8.4.0",
|
|
58
61
|
"typescript": "^5.8.2",
|
|
59
62
|
"vite": "^6.2.5",
|
|
60
63
|
"vitest": "^3.1.1",
|
|
64
|
+
"vue": "^3.5.13",
|
|
65
|
+
"zx": "^8.5.2",
|
|
61
66
|
"@altano/assets": "0.0.0",
|
|
62
67
|
"@altano/testing": "0.0.0",
|
|
63
|
-
"@altano/vitest-plugins": "1.1.0",
|
|
64
68
|
"@altano/build-config": "0.0.0",
|
|
65
|
-
"@altano/tsconfig": "0.0.0"
|
|
69
|
+
"@altano/tsconfig": "0.0.0",
|
|
70
|
+
"@altano/tiny-async-pool": "3.0.2",
|
|
71
|
+
"@altano/vitest-plugins": "1.1.0"
|
|
66
72
|
},
|
|
67
73
|
"peerDependencies": {
|
|
68
|
-
"@types/react": ">=18",
|
|
69
|
-
"@types/react-dom": ">=18",
|
|
70
74
|
"astro": "5.x.x",
|
|
71
|
-
"
|
|
72
|
-
"react-dom": ">=18"
|
|
75
|
+
"preact": ">=10"
|
|
73
76
|
},
|
|
74
77
|
"publishConfig": {
|
|
75
78
|
"access": "public"
|
|
@@ -77,6 +80,7 @@
|
|
|
77
80
|
"scripts": {
|
|
78
81
|
"build": "tsup --config ./tsup.config.ts",
|
|
79
82
|
"build:types": "tsc --project tsconfig.declarations.json",
|
|
83
|
+
"check:types:astro-fixtures": "node --experimental-strip-types ./scripts/check-fixtures.ts",
|
|
80
84
|
"check:types:src": "tsc --noEmit",
|
|
81
85
|
"check:types:test": "tsc --noEmit --project ./tests/tsconfig.json",
|
|
82
86
|
"check:unused-dependencies": "depcheck",
|
|
@@ -87,7 +91,7 @@
|
|
|
87
91
|
"lint:fix": "TIMING=1 eslint src/**/*.ts* --fix",
|
|
88
92
|
"lint:timing": "TIMING=1 eslint src/**/*.ts*",
|
|
89
93
|
"test:e2e": "playwright test",
|
|
90
|
-
"test:e2e:server": "astro --root tests/fixtures/
|
|
94
|
+
"test:e2e:server": "astro --root tests/fixtures/ui-frameworks --port 3913 dev",
|
|
91
95
|
"test:e2e:ui": "playwright test --ui",
|
|
92
96
|
"test:unit": "vitest --run",
|
|
93
97
|
"test:unit:watch": "vitest"
|