@sealpixel/astro 1.0.0-rc.11 → 1.0.0-rc.12
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/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -1
- package/dist/index.js.map +1 -1
- package/dist/render-route.d.ts +5 -0
- package/dist/render-route.d.ts.map +1 -1
- package/dist/render-route.js +5 -2
- package/dist/render-route.js.map +1 -1
- package/package.json +12 -9
- package/src/components/SealpixelEditor.astro +3 -8
- package/src/components/hydrate.ts +43 -0
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,11 @@ export interface SealpixelAstroOptions {
|
|
|
3
3
|
/**
|
|
4
4
|
* Inject `POST /api/sealpixel/render` backed by `@sealpixel/server` with the
|
|
5
5
|
* first-party plugins and inline sources. Requires an SSR adapter.
|
|
6
|
+
*
|
|
7
|
+
* The object form sets the route `path`, the handler's `cors` and
|
|
8
|
+
* `limits.maxMegapixels`. Without `cors` the handler's own default applies:
|
|
9
|
+
* no CORS headers, so only the same origin can call the route. Without
|
|
10
|
+
* `maxMegapixels` the route reads `SEALPIXEL_MAX_MEGAPIXELS`, then uses 40.
|
|
6
11
|
*/
|
|
7
12
|
renderRoute?: boolean | {
|
|
8
13
|
path?: string;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAK9C,MAAM,WAAW,qBAAqB;IACpC;;;;;;;;OAQG;IACH,WAAW,CAAC,EAAE,OAAO,GAAG;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;QAAC,aAAa,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAC1F;AAED;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,OAAO,GAAE,qBAA0B,GAAG,gBAAgB,CA8CvF"}
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/** Carries the object form of `renderRoute` into the injected route. */
|
|
2
|
+
const ROUTE_CONFIG_ID = 'virtual:sealpixel/render-route-config';
|
|
1
3
|
/**
|
|
2
4
|
* `astro add @sealpixel/astro`. Keeps the Sealpixel packages out of Vite's
|
|
3
5
|
* dependency pre-bundling so `new URL(..., import.meta.url)` for the wasm and
|
|
@@ -8,6 +10,12 @@ export default function sealpixel(options = {}) {
|
|
|
8
10
|
name: '@sealpixel/astro',
|
|
9
11
|
hooks: {
|
|
10
12
|
'astro:config:setup': ({ updateConfig, injectRoute }) => {
|
|
13
|
+
const route = typeof options.renderRoute === 'object' ? options.renderRoute : {};
|
|
14
|
+
const routeConfig = {
|
|
15
|
+
...(route.cors === undefined ? {} : { cors: route.cors }),
|
|
16
|
+
...(route.maxMegapixels === undefined ? {} : { maxMegapixels: route.maxMegapixels }),
|
|
17
|
+
};
|
|
18
|
+
const resolvedId = `\0${ROUTE_CONFIG_ID}`;
|
|
11
19
|
updateConfig({
|
|
12
20
|
vite: {
|
|
13
21
|
optimizeDeps: {
|
|
@@ -23,10 +31,16 @@ export default function sealpixel(options = {}) {
|
|
|
23
31
|
],
|
|
24
32
|
},
|
|
25
33
|
worker: { format: 'es' },
|
|
34
|
+
plugins: [
|
|
35
|
+
{
|
|
36
|
+
name: '@sealpixel/astro:render-route-config',
|
|
37
|
+
resolveId: (id) => (id === ROUTE_CONFIG_ID ? resolvedId : undefined),
|
|
38
|
+
load: (id) => id === resolvedId ? `export default ${JSON.stringify(routeConfig)};` : undefined,
|
|
39
|
+
},
|
|
40
|
+
],
|
|
26
41
|
},
|
|
27
42
|
});
|
|
28
43
|
if (options.renderRoute) {
|
|
29
|
-
const route = typeof options.renderRoute === 'object' ? options.renderRoute : {};
|
|
30
44
|
injectRoute({
|
|
31
45
|
pattern: route.path ?? '/api/sealpixel/render',
|
|
32
46
|
entrypoint: '@sealpixel/astro/render-route',
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,wEAAwE;AACxE,MAAM,eAAe,GAAG,uCAAuC,CAAC;AAehE;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,UAAiC,EAAE;IACnE,OAAO;QACL,IAAI,EAAE,kBAAkB;QACxB,KAAK,EAAE;YACL,oBAAoB,EAAE,CAAC,EAAE,YAAY,EAAE,WAAW,EAAE,EAAE,EAAE;gBACtD,MAAM,KAAK,GAAG,OAAO,OAAO,CAAC,WAAW,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC;gBACjF,MAAM,WAAW,GAAG;oBAClB,GAAG,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC;oBACzD,GAAG,CAAC,KAAK,CAAC,aAAa,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,KAAK,CAAC,aAAa,EAAE,CAAC;iBACrF,CAAC;gBACF,MAAM,UAAU,GAAG,KAAK,eAAe,EAAE,CAAC;gBAC1C,YAAY,CAAC;oBACX,IAAI,EAAE;wBACJ,YAAY,EAAE;4BACZ,OAAO,EAAE;gCACP,iBAAiB;gCACjB,iBAAiB;gCACjB,eAAe;gCACf,oBAAoB;gCACpB,oBAAoB;gCACpB,kBAAkB;gCAClB,gBAAgB;gCAChB,mBAAmB;6BACpB;yBACF;wBACD,MAAM,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE;wBACxB,OAAO,EAAE;4BACP;gCACE,IAAI,EAAE,sCAAsC;gCAC5C,SAAS,EAAE,CAAC,EAAU,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,eAAe,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC;gCAC5E,IAAI,EAAE,CAAC,EAAU,EAAE,EAAE,CACnB,EAAE,KAAK,UAAU,CAAC,CAAC,CAAC,kBAAkB,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS;6BACnF;yBACF;qBACF;iBACF,CAAC,CAAC;gBACH,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;oBACxB,WAAW,CAAC;wBACV,OAAO,EAAE,KAAK,CAAC,IAAI,IAAI,uBAAuB;wBAC9C,UAAU,EAAE,+BAA+B;wBAC3C,SAAS,EAAE,KAAK;qBACjB,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;SACF;KACF,CAAC;AACJ,CAAC"}
|
package/dist/render-route.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Astro API route running `@sealpixel/server` in the SSR runtime (Node, Deno,
|
|
3
|
+
* Bun, Cloudflare via the fetch handler). Inline sources only; hosts wanting
|
|
4
|
+
* S3 sources write their own route with `createSealpixelHandler`.
|
|
5
|
+
*/
|
|
1
6
|
export declare const prerender = false;
|
|
2
7
|
export declare function POST({ request }: {
|
|
3
8
|
request: Request;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-route.d.ts","sourceRoot":"","sources":["../src/render-route.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"render-route.d.ts","sourceRoot":"","sources":["../src/render-route.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAeH,eAAO,MAAM,SAAS,QAAQ,CAAC;AAE/B,wBAAgB,IAAI,CAAC,EAAE,OAAO,EAAE,EAAE;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,GAAG,OAAO,CAAC,QAAQ,CAAC,CAEzE;AAED,wBAAgB,GAAG,CAAC,EAAE,OAAO,EAAE,EAAE;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,GAAG,OAAO,CAAC,QAAQ,CAAC,CAExE;AAED,wBAAgB,OAAO,CAAC,EAAE,OAAO,EAAE,EAAE;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,GAAG,OAAO,CAAC,QAAQ,CAAC,CAE5E"}
|
package/dist/render-route.js
CHANGED
|
@@ -3,13 +3,16 @@
|
|
|
3
3
|
* Bun, Cloudflare via the fetch handler). Inline sources only; hosts wanting
|
|
4
4
|
* S3 sources write their own route with `createSealpixelHandler`.
|
|
5
5
|
*/
|
|
6
|
+
import config from 'virtual:sealpixel/render-route-config';
|
|
6
7
|
import { defaultPlugins } from '@sealpixel/plugins';
|
|
7
8
|
import { createSealpixelHandler, inlineSource } from '@sealpixel/server';
|
|
8
9
|
const handler = createSealpixelHandler({
|
|
9
10
|
plugins: defaultPlugins,
|
|
10
11
|
sources: [inlineSource()],
|
|
11
|
-
cors:
|
|
12
|
-
limits: {
|
|
12
|
+
...(config.cors === undefined ? {} : { cors: config.cors }),
|
|
13
|
+
limits: {
|
|
14
|
+
maxMegapixels: config.maxMegapixels ?? Number(process.env['SEALPIXEL_MAX_MEGAPIXELS'] ?? 40),
|
|
15
|
+
},
|
|
13
16
|
});
|
|
14
17
|
export const prerender = false;
|
|
15
18
|
export function POST({ request }) {
|
package/dist/render-route.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-route.js","sourceRoot":"","sources":["../src/render-route.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"render-route.js","sourceRoot":"","sources":["../src/render-route.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,MAAM,MAAM,uCAAuC,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEzE,MAAM,OAAO,GAAG,sBAAsB,CAAC;IACrC,OAAO,EAAE,cAAc;IACvB,OAAO,EAAE,CAAC,YAAY,EAAE,CAAC;IACzB,GAAG,CAAC,MAAM,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;IAC3D,MAAM,EAAE;QACN,aAAa,EAAE,MAAM,CAAC,aAAa,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,IAAI,EAAE,CAAC;KAC7F;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,CAAC;AAE/B,MAAM,UAAU,IAAI,CAAC,EAAE,OAAO,EAAwB;IACpD,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC;AAC1B,CAAC;AAED,MAAM,UAAU,GAAG,CAAC,EAAE,OAAO,EAAwB;IACnD,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC;AAC1B,CAAC;AAED,MAAM,UAAU,OAAO,CAAC,EAAE,OAAO,EAAwB;IACvD,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC;AAC1B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sealpixel/astro",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.12",
|
|
4
4
|
"description": "Astro integration for the Sealpixel image editor: Vite config for the wasm and worker, a <SealpixelEditor /> component, and an optional /api/sealpixel/render endpoint.",
|
|
5
5
|
"license": "BUSL-1.1",
|
|
6
6
|
"repository": {
|
|
@@ -30,12 +30,12 @@
|
|
|
30
30
|
"./package.json": "./package.json"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@sealpixel/core": "1.0.0-rc.
|
|
34
|
-
"@sealpixel/element": "1.0.0-rc.
|
|
35
|
-
"@sealpixel/plugins": "1.0.0-rc.
|
|
36
|
-
"@sealpixel/server": "1.0.0-rc.
|
|
37
|
-
"@sealpixel/ui": "1.0.0-rc.
|
|
38
|
-
"@sealpixel/wasm": "1.0.0-rc.
|
|
33
|
+
"@sealpixel/core": "1.0.0-rc.12",
|
|
34
|
+
"@sealpixel/element": "1.0.0-rc.12",
|
|
35
|
+
"@sealpixel/plugins": "1.0.0-rc.12",
|
|
36
|
+
"@sealpixel/server": "1.0.0-rc.12",
|
|
37
|
+
"@sealpixel/ui": "1.0.0-rc.12",
|
|
38
|
+
"@sealpixel/wasm": "1.0.0-rc.12"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"astro": ">=5.0.0"
|
|
@@ -44,10 +44,13 @@
|
|
|
44
44
|
"@sealpixel/config": "0.0.0",
|
|
45
45
|
"@types/node": "^24.0.0",
|
|
46
46
|
"astro": "^7.0.0",
|
|
47
|
-
"
|
|
47
|
+
"happy-dom": "^20.0.0",
|
|
48
|
+
"typescript": "^6.0.0",
|
|
49
|
+
"vitest": "^5.0.0"
|
|
48
50
|
},
|
|
49
51
|
"scripts": {
|
|
50
52
|
"build": "tsc -p tsconfig.build.json",
|
|
51
|
-
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
53
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
54
|
+
"test": "vitest run && node --test test/*.node.test.mjs"
|
|
52
55
|
}
|
|
53
56
|
}
|
|
@@ -54,12 +54,7 @@ const id = `sealpixel-${Math.random().toString(36).slice(2, 10)}`;
|
|
|
54
54
|
|
|
55
55
|
<script>
|
|
56
56
|
import '@sealpixel/element';
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
el.locale = el.dataset.locale ?? 'en';
|
|
61
|
-
if (el.dataset.serverEndpoint) el.serverEndpoint = el.dataset.serverEndpoint;
|
|
62
|
-
if (el.dataset.editLog) el.defaultEditLog = JSON.parse(el.dataset.editLog);
|
|
63
|
-
if (el.dataset.src) el.src = el.dataset.src;
|
|
64
|
-
}
|
|
57
|
+
import { startHydration } from './hydrate';
|
|
58
|
+
|
|
59
|
+
startHydration();
|
|
65
60
|
</script>
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The client script of `SealpixelEditor.astro`. The component renders plain
|
|
3
|
+
* data as `data-*` attributes; this script copies it into the properties that
|
|
4
|
+
* the element reads.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
type EditorElement = HTMLElement & {
|
|
8
|
+
src: unknown;
|
|
9
|
+
locale: string;
|
|
10
|
+
serverEndpoint: string | null;
|
|
11
|
+
defaultEditLog: unknown;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
function hydrateEditors(): void {
|
|
15
|
+
for (const el of document.querySelectorAll<EditorElement>(
|
|
16
|
+
'sealpixel-editor[data-src], sealpixel-editor[data-locale]',
|
|
17
|
+
)) {
|
|
18
|
+
// A second pass must not reset an editor, for example one that the router kept.
|
|
19
|
+
if (el.hasAttribute('data-hydrated')) continue;
|
|
20
|
+
el.setAttribute('data-hydrated', '1');
|
|
21
|
+
el.locale = el.getAttribute('data-locale') ?? 'en';
|
|
22
|
+
const serverEndpoint = el.getAttribute('data-server-endpoint');
|
|
23
|
+
if (serverEndpoint) el.serverEndpoint = serverEndpoint;
|
|
24
|
+
const editLog = el.getAttribute('data-edit-log');
|
|
25
|
+
if (editLog) el.defaultEditLog = JSON.parse(editLog);
|
|
26
|
+
const src = el.getAttribute('data-src');
|
|
27
|
+
if (src) el.src = src;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let started = false;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Hydrates the editors on the page now and after every client-side navigation.
|
|
35
|
+
* A module script runs once per full page load, but the ClientRouter swaps
|
|
36
|
+
* pages without one and fires `astro:page-load` instead.
|
|
37
|
+
*/
|
|
38
|
+
export function startHydration(): void {
|
|
39
|
+
hydrateEditors();
|
|
40
|
+
if (started) return;
|
|
41
|
+
started = true;
|
|
42
|
+
document.addEventListener('astro:page-load', hydrateEditors);
|
|
43
|
+
}
|