@xingwangzhe/satteri-photoswipe 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 王兴家
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,96 @@
1
+ # @xingwangzhe/satteri-photoswipe
2
+
3
+ [中文文档](README_CN.md) | [English](#)
4
+
5
+ > Satteri HAST plugin that wraps `<img>` with PhotoSwipe v5 `<a>` containers using [official attributes](https://photoswipe.com/getting-started/).
6
+
7
+ ## Features
8
+
9
+ - **PhotoSwipe v5 native** — uses `data-pswp-width`, `data-pswp-height`, `data-pswp-srcset`, `data-cropped`
10
+ - **Auto attribute mapping** — `width`/`height` → `data-pswp-*`, `alt` → `aria-label`, `srcset` → `data-pswp-srcset`
11
+ - **Exposes selector** — `defaultSelector` ready for `PhotoSwipeLightbox` config
12
+ - **Zero-config** — `photoswipe()` just works
13
+
14
+ ## Install
15
+
16
+ ```bash
17
+ bun add @xingwangzhe/satteri-photoswipe
18
+ ```
19
+
20
+ Requires `satteri >= 0.8.0`. [PhotoSwipe v5](https://photoswipe.com/) must be loaded client-side.
21
+
22
+ ## Usage
23
+
24
+ ```js
25
+ // astro.config.mjs
26
+ import { photoswipe, defaultSelector } from "@xingwangzhe/satteri-photoswipe";
27
+
28
+ export default defineConfig({
29
+ markdown: {
30
+ processor: satteri({
31
+ hastPlugins: [photoswipe()],
32
+ }),
33
+ },
34
+ });
35
+ ```
36
+
37
+ Markdown:
38
+
39
+ ```markdown
40
+ ![A photo](photo.jpg)
41
+ ```
42
+
43
+ Output:
44
+
45
+ ```html
46
+ <a href="photo.jpg" data-pswp-width="800" data-pswp-height="600" aria-label="A photo">
47
+ <img src="photo.jpg" alt="A photo" />
48
+ </a>
49
+ ```
50
+
51
+ ### Client-side setup
52
+
53
+ ```js
54
+ import PhotoSwipeLightbox from "photoswipe/lightbox";
55
+ import PhotoSwipe from "photoswipe";
56
+ import { defaultSelector } from "@xingwangzhe/satteri-photoswipe";
57
+
58
+ const lightbox = new PhotoSwipeLightbox({
59
+ gallery: defaultSelector, // "a[data-pswp-width]"
60
+ children: "img",
61
+ pswpModule: PhotoSwipe,
62
+ });
63
+ lightbox.init();
64
+ ```
65
+
66
+ ## API
67
+
68
+ ### `photoswipe(options?)`
69
+
70
+ | Option | Type | Default | Description |
71
+ |--------|------|---------|-------------|
72
+ | `selector` | `string` | `"a[data-pswp-width]"` | CSS selector for `PhotoSwipeLightbox` gallery |
73
+ | `cropped` | `boolean` | `false` | Add `data-cropped="true"` for cropped thumbnails |
74
+
75
+ ### `defaultSelector`
76
+
77
+ `"a[data-pswp-width]"` — pass directly to `PhotoSwipeLightbox({ gallery: defaultSelector })`.
78
+
79
+ ### `createPhotoswipePlugin(options?)`
80
+
81
+ Returns `{ plugin, selector }`. For advanced use cases.
82
+
83
+ ## How it maps attributes
84
+
85
+ | `<img>` attribute | `<a>` attribute | PhotoSwipe v5 usage |
86
+ |-------------------|-----------------|---------------------|
87
+ | `src` | `href` | Full-size image URL |
88
+ | `width` | `data-pswp-width` | Image width in px (required) |
89
+ | `height` | `data-pswp-height` | Image height in px (required) |
90
+ | `srcset` | `data-pswp-srcset` | Responsive images |
91
+ | `data-pswp-src` | `data-pswp-src` | Passthrough (overrides href) |
92
+ | `alt` | `aria-label` | Accessibility |
93
+
94
+ ## License
95
+
96
+ MIT
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("satteri");var t={WIDTH:`data-pswp-width`,HEIGHT:`data-pswp-height`,SRC:`data-pswp-src`,SRCSET:`data-pswp-srcset`,CROPPED:`data-cropped`};function n(n){let r=n?.selector??`a[${t.WIDTH}]`,i=n?.cropped??!1;return{plugin:(0,e.defineHastPlugin)({name:`satteri-photoswipe`,element:{filter:[`img`],visit(e,n){let r=e.properties??{},a=String(r.src??``);if(!a)return;let o={href:a},s=r.width??r[t.WIDTH],c=r.height??r[t.HEIGHT];s!=null&&(o[t.WIDTH]=String(s)),c!=null&&(o[t.HEIGHT]=String(c));let l=r.srcset??r[t.SRCSET];l!=null&&(o[t.SRCSET]=String(l)),r[t.SRC]!=null&&(o[t.SRC]=String(r[t.SRC])),r.alt!=null&&(o[`aria-label`]=String(r.alt)),i&&(o[t.CROPPED]=`true`),n.wrapNode(e,{type:`element`,tagName:`a`,properties:o,children:[]})}}}),selector:r}}function r(e){return n(e).plugin}var i=n(),a=i.plugin,o=i.selector;exports.createPhotoswipePlugin=n,exports.defaultSelector=o,exports.photoswipe=r,exports.photoswipePlugin=a;
@@ -0,0 +1,2 @@
1
+ export { createPhotoswipePlugin, defaultSelector, photoswipe, photoswipePlugin, } from "./plugin";
2
+ export type { PhotoswipeOptions } from "./plugin";
package/dist/index.mjs ADDED
@@ -0,0 +1,40 @@
1
+ import { defineHastPlugin as e } from "satteri";
2
+ //#region src/plugin.ts
3
+ var t = {
4
+ WIDTH: "data-pswp-width",
5
+ HEIGHT: "data-pswp-height",
6
+ SRC: "data-pswp-src",
7
+ SRCSET: "data-pswp-srcset",
8
+ CROPPED: "data-cropped"
9
+ };
10
+ function n(n) {
11
+ let r = n?.selector ?? `a[${t.WIDTH}]`, i = n?.cropped ?? !1;
12
+ return {
13
+ plugin: e({
14
+ name: "satteri-photoswipe",
15
+ element: {
16
+ filter: ["img"],
17
+ visit(e, n) {
18
+ let r = e.properties ?? {}, a = String(r.src ?? "");
19
+ if (!a) return;
20
+ let o = { href: a }, s = r.width ?? r[t.WIDTH], c = r.height ?? r[t.HEIGHT];
21
+ s != null && (o[t.WIDTH] = String(s)), c != null && (o[t.HEIGHT] = String(c));
22
+ let l = r.srcset ?? r[t.SRCSET];
23
+ l != null && (o[t.SRCSET] = String(l)), r[t.SRC] != null && (o[t.SRC] = String(r[t.SRC])), r.alt != null && (o["aria-label"] = String(r.alt)), i && (o[t.CROPPED] = "true"), n.wrapNode(e, {
24
+ type: "element",
25
+ tagName: "a",
26
+ properties: o,
27
+ children: []
28
+ });
29
+ }
30
+ }
31
+ }),
32
+ selector: r
33
+ };
34
+ }
35
+ function r(e) {
36
+ return n(e).plugin;
37
+ }
38
+ var i = n(), a = i.plugin, o = i.selector;
39
+ //#endregion
40
+ export { n as createPhotoswipePlugin, o as defaultSelector, r as photoswipe, a as photoswipePlugin };
@@ -0,0 +1,36 @@
1
+ export interface PhotoswipeOptions {
2
+ /**
3
+ * CSS selector for PhotoSwipe to find gallery links.
4
+ * Default: "a[data-pswp-width]" — PhotoSwipe v5 requires width/height.
5
+ * @see https://photoswipe.com/getting-started/
6
+ */
7
+ selector?: string;
8
+ /** Whether to mark thumbnail as cropped (affects opening animation). Default: false */
9
+ cropped?: boolean;
10
+ }
11
+ export declare function createPhotoswipePlugin(options?: PhotoswipeOptions): {
12
+ plugin: {
13
+ name: string;
14
+ element: {
15
+ filter: string[];
16
+ visit(node: Readonly<import("hast").Element>, ctx: import("satteri").HastVisitorContext): void;
17
+ };
18
+ };
19
+ selector: string;
20
+ };
21
+ /** Factory function. Usage: `photoswipe()` — aligns with `katex()` style */
22
+ export declare function photoswipe(options?: PhotoswipeOptions): {
23
+ name: string;
24
+ element: {
25
+ filter: string[];
26
+ visit(node: Readonly<import("hast").Element>, ctx: import("satteri").HastVisitorContext): void;
27
+ };
28
+ };
29
+ export declare const photoswipePlugin: {
30
+ name: string;
31
+ element: {
32
+ filter: string[];
33
+ visit(node: Readonly<import("hast").Element>, ctx: import("satteri").HastVisitorContext): void;
34
+ };
35
+ };
36
+ export declare const defaultSelector: string;
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@xingwangzhe/satteri-photoswipe",
3
+ "version": "0.1.0",
4
+ "description": "Satteri HAST plugin that wraps images with PhotoSwipe lightbox containers",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "author": "xingwangzhe",
8
+ "homepage": "https://github.com/xingwangzhe/satteri-photoswipe#readme",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/xingwangzhe/satteri-photoswipe"
12
+ },
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "import": "./dist/index.mjs",
17
+ "require": "./dist/index.cjs"
18
+ }
19
+ },
20
+ "main": "./dist/index.cjs",
21
+ "module": "./dist/index.mjs",
22
+ "types": "./dist/index.d.ts",
23
+ "files": [
24
+ "dist"
25
+ ],
26
+ "scripts": {
27
+ "dev": "vite",
28
+ "build": "vite build && tsc --emitDeclarationOnly --declarationDir dist",
29
+ "test": "vitest run",
30
+ "test:watch": "vitest",
31
+ "fmt": "oxfmt",
32
+ "fmt:check": "oxfmt --check",
33
+ "lint": "oxlint src test",
34
+ "lint:fix": "oxlint --fix src test",
35
+ "prepublishOnly": "bun run build"
36
+ },
37
+ "peerDependencies": {
38
+ "satteri": ">=0.8.0"
39
+ },
40
+ "devDependencies": {
41
+ "@types/node": "^24.0.0",
42
+ "oxfmt": "^0.55.0",
43
+ "oxlint": "^1.70.0",
44
+ "satteri": "^0.9.0",
45
+ "typescript": "^5.9.0",
46
+ "vite": "^8.0.0",
47
+ "vitest": "^4.1.0"
48
+ },
49
+ "keywords": [
50
+ "astro",
51
+ "astro-component",
52
+ "satteri",
53
+ "photoswipe",
54
+ "hast",
55
+ "lightbox",
56
+ "image",
57
+ "gallery",
58
+ "markdown",
59
+ "plugin"
60
+ ]
61
+ }