@riebeckite/plugin-lightbox 0.0.14 → 0.0.15
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 -2
- package/README_ja.md +5 -1
- package/dist/client.d.ts +2 -0
- package/dist/client.js +18 -8
- package/dist/index.d.ts +2 -1
- package/dist/index.js +29 -9
- package/dist/src/dialog.d.ts +4 -1
- package/dist/src/types.d.ts +4 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -36,6 +36,8 @@ the app calls on page initialization.
|
|
|
36
36
|
- Adds `rr-lightbox-image` to the image
|
|
37
37
|
- Skips images that have `data-lightbox-ignore="true"`, and images already
|
|
38
38
|
inside an `<a>`, `<button>`, existing trigger, or the dialog
|
|
39
|
+
- Uses `expandLabel` (default `"Expand image"`) for the trigger and dialog
|
|
40
|
+
accessible labels
|
|
39
41
|
|
|
40
42
|
### Client (`initLightbox`)
|
|
41
43
|
|
|
@@ -54,9 +56,11 @@ the app calls on page initialization.
|
|
|
54
56
|
| Option | Type | Default | Description |
|
|
55
57
|
| ------ | ---- | ------- | ----------- |
|
|
56
58
|
| `selectorClass` | `string` | `"rr-lightbox-trigger"` | Trigger class (build and client) |
|
|
59
|
+
| `expandLabel` | `string` | `"Expand image"` | Accessible label for triggers and the dialog |
|
|
60
|
+
| `closeLabel` | `string` | `"Close"` | Accessible label for the dialog close button |
|
|
57
61
|
| `autoWrapImages` | `boolean` | `true` | Client-only: wrap unhandled images on init |
|
|
58
62
|
|
|
59
|
-
`LightboxOptions` = `{ selectorClass? }` (build),
|
|
63
|
+
`LightboxOptions` = `{ selectorClass?, expandLabel?, closeLabel? }` (build),
|
|
60
64
|
`LightboxInitOptions` = `LightboxOptions & { autoWrapImages? }` (client).
|
|
61
65
|
|
|
62
66
|
## Exports
|
|
@@ -65,8 +69,11 @@ the app calls on page initialization.
|
|
|
65
69
|
- `rehypeLightbox(options?)` — rehype transform
|
|
66
70
|
- `initLightbox(root?, options?)` — client initializer, returns a cleanup
|
|
67
71
|
function
|
|
72
|
+
- `initLightboxFromOptions(options?)` — option-first browser entry the plugin's
|
|
73
|
+
client script calls; wraps `initLightbox`
|
|
68
74
|
- Types: `LightboxOptions`, `LightboxInitOptions`
|
|
69
75
|
|
|
70
76
|
## See also
|
|
71
77
|
|
|
72
|
-
- [Plugin guide](../../../docs/en/reference/plugin-api.md)
|
|
78
|
+
- [Plugin guide](../../../docs/en/docs/reference/plugin-api.md)
|
|
79
|
+
|
package/README_ja.md
CHANGED
|
@@ -30,6 +30,8 @@ export default defineConfig({
|
|
|
30
30
|
| オプション | 型 | 既定値 | 内容 |
|
|
31
31
|
| --- | --- | --- | --- |
|
|
32
32
|
| `selectorClass` | `string` | `"rr-lightbox-trigger"` | トリガーに使う CSS クラス |
|
|
33
|
+
| `expandLabel` | `string` | `"Expand image"` | トリガーとダイアログのアクセシブルラベル |
|
|
34
|
+
| `closeLabel` | `string` | `"Close"` | 閉じるボタンのアクセシブルラベル |
|
|
33
35
|
| `autoWrapImages` | `boolean` | `true` | 初期化時に未処理の画像も囲むか。クライアント側だけの設定 |
|
|
34
36
|
|
|
35
37
|
`initLightbox()` はイベントリスナー、ダイアログ、追加したトリガーを解除する cleanup 関数を返します。
|
|
@@ -39,8 +41,10 @@ export default defineConfig({
|
|
|
39
41
|
- `lightboxPlugin(options?)` — プラグインファクトリ
|
|
40
42
|
- `rehypeLightbox(options?)` — Rehype 変換
|
|
41
43
|
- `initLightbox(root?, options?)` — ブラウザ初期化関数
|
|
44
|
+
- `initLightboxFromOptions(options?)` — プラグインのクライアントスクリプトが呼ぶ、オプションを先に取る初期化関数
|
|
42
45
|
- `LightboxOptions`、`LightboxInitOptions` — 型
|
|
43
46
|
|
|
44
47
|
## 関連資料
|
|
45
48
|
|
|
46
|
-
- [プラグインシステム](../../../docs/ja/reference/plugin-api.md)
|
|
49
|
+
- [プラグインシステム](../../../docs/ja/docs/reference/plugin-api.md)
|
|
50
|
+
|
package/dist/client.d.ts
CHANGED
package/dist/client.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// src/dialog.ts
|
|
2
|
-
function createDialog() {
|
|
2
|
+
function createDialog(options) {
|
|
3
3
|
const element = document.createElement("div");
|
|
4
4
|
element.className = "rr-lightbox";
|
|
5
5
|
element.setAttribute("role", "dialog");
|
|
6
6
|
element.setAttribute("aria-modal", "true");
|
|
7
|
-
element.setAttribute("aria-label",
|
|
7
|
+
element.setAttribute("aria-label", options.expandLabel);
|
|
8
8
|
element.tabIndex = -1;
|
|
9
9
|
element.setAttribute("hidden", "");
|
|
10
10
|
const frame = document.createElement("figure");
|
|
@@ -17,7 +17,7 @@ function createDialog() {
|
|
|
17
17
|
const closeButton = document.createElement("button");
|
|
18
18
|
closeButton.className = "rr-lightbox__close";
|
|
19
19
|
closeButton.type = "button";
|
|
20
|
-
closeButton.setAttribute("aria-label",
|
|
20
|
+
closeButton.setAttribute("aria-label", options.closeLabel);
|
|
21
21
|
closeButton.textContent = "×";
|
|
22
22
|
frame.appendChild(image);
|
|
23
23
|
frame.appendChild(caption);
|
|
@@ -28,11 +28,15 @@ function createDialog() {
|
|
|
28
28
|
|
|
29
29
|
// src/types.ts
|
|
30
30
|
var DEFAULT_TRIGGER_CLASS = "rr-lightbox-trigger";
|
|
31
|
+
var DEFAULT_EXPAND_LABEL = "Expand image";
|
|
32
|
+
var DEFAULT_CLOSE_LABEL = "Close";
|
|
31
33
|
|
|
32
34
|
// src/init.ts
|
|
33
35
|
function initLightbox(root = document, options = {}) {
|
|
34
36
|
const triggerClass = options.selectorClass ?? DEFAULT_TRIGGER_CLASS;
|
|
35
|
-
const
|
|
37
|
+
const expandLabel = options.expandLabel ?? DEFAULT_EXPAND_LABEL;
|
|
38
|
+
const closeLabel = options.closeLabel ?? DEFAULT_CLOSE_LABEL;
|
|
39
|
+
const wrappedTriggers = options.autoWrapImages === false ? [] : wrapImages(root, triggerClass, expandLabel);
|
|
36
40
|
const triggers = Array.from(
|
|
37
41
|
root.querySelectorAll(`.${triggerClass}`)
|
|
38
42
|
);
|
|
@@ -42,7 +46,7 @@ function initLightbox(root = document, options = {}) {
|
|
|
42
46
|
};
|
|
43
47
|
}
|
|
44
48
|
let previouslyFocused = null;
|
|
45
|
-
const dialog = createDialog();
|
|
49
|
+
const dialog = createDialog({ expandLabel, closeLabel });
|
|
46
50
|
document.body.appendChild(dialog.element);
|
|
47
51
|
const open = (trigger) => {
|
|
48
52
|
const src = trigger.dataset.lightboxSrc ?? trigger.href;
|
|
@@ -126,7 +130,7 @@ function getFocusableElements(container) {
|
|
|
126
130
|
)
|
|
127
131
|
).filter((element) => !element.hasAttribute("disabled"));
|
|
128
132
|
}
|
|
129
|
-
function wrapImages(root, triggerClass) {
|
|
133
|
+
function wrapImages(root, triggerClass, expandLabel) {
|
|
130
134
|
const images = Array.from(
|
|
131
135
|
root.querySelectorAll("img[src]")
|
|
132
136
|
);
|
|
@@ -145,7 +149,7 @@ function wrapImages(root, triggerClass) {
|
|
|
145
149
|
trigger.dataset.lightboxAlt = image.alt;
|
|
146
150
|
trigger.setAttribute(
|
|
147
151
|
"aria-label",
|
|
148
|
-
image.alt ?
|
|
152
|
+
image.alt ? `${expandLabel}: ${image.alt}` : expandLabel
|
|
149
153
|
);
|
|
150
154
|
image.parentNode?.insertBefore(trigger, image);
|
|
151
155
|
trigger.appendChild(image);
|
|
@@ -160,6 +164,12 @@ function unwrapImage(trigger) {
|
|
|
160
164
|
trigger.parentNode.insertBefore(image, trigger);
|
|
161
165
|
trigger.remove();
|
|
162
166
|
}
|
|
167
|
+
|
|
168
|
+
// client.ts
|
|
169
|
+
function initLightboxFromOptions(options = {}) {
|
|
170
|
+
return initLightbox(document, options);
|
|
171
|
+
}
|
|
163
172
|
export {
|
|
164
|
-
initLightbox
|
|
173
|
+
initLightbox,
|
|
174
|
+
initLightboxFromOptions
|
|
165
175
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type LightboxOptions } from "./src/types.js";
|
|
2
|
+
export { initLightboxFromOptions } from "./client.js";
|
|
2
3
|
export { initLightbox } from "./src/init.js";
|
|
3
4
|
export { rehypeLightbox } from "./src/rehype.js";
|
|
4
5
|
export type { LightboxInitOptions, LightboxOptions } from "./src/types.js";
|
package/dist/index.js
CHANGED
|
@@ -38,10 +38,13 @@ function getChildren(node) {
|
|
|
38
38
|
|
|
39
39
|
// src/types.ts
|
|
40
40
|
var DEFAULT_TRIGGER_CLASS = "rr-lightbox-trigger";
|
|
41
|
+
var DEFAULT_EXPAND_LABEL = "Expand image";
|
|
42
|
+
var DEFAULT_CLOSE_LABEL = "Close";
|
|
41
43
|
|
|
42
44
|
// src/rehype.ts
|
|
43
45
|
function rehypeLightbox(options = {}) {
|
|
44
46
|
const triggerClass = options.selectorClass ?? DEFAULT_TRIGGER_CLASS;
|
|
47
|
+
const expandLabel = options.expandLabel ?? DEFAULT_EXPAND_LABEL;
|
|
45
48
|
return (tree) => {
|
|
46
49
|
visitElements(tree, (node, parent, index) => {
|
|
47
50
|
if (!parent || index === void 0 || node.tagName !== "img") return;
|
|
@@ -63,7 +66,7 @@ function rehypeLightbox(options = {}) {
|
|
|
63
66
|
href: src,
|
|
64
67
|
dataLightboxSrc: src,
|
|
65
68
|
dataLightboxAlt: alt,
|
|
66
|
-
ariaLabel: alt ?
|
|
69
|
+
ariaLabel: alt ? `${expandLabel}: ${alt}` : expandLabel
|
|
67
70
|
},
|
|
68
71
|
children: [
|
|
69
72
|
{
|
|
@@ -80,12 +83,12 @@ function rehypeLightbox(options = {}) {
|
|
|
80
83
|
}
|
|
81
84
|
|
|
82
85
|
// src/dialog.ts
|
|
83
|
-
function createDialog() {
|
|
86
|
+
function createDialog(options) {
|
|
84
87
|
const element = document.createElement("div");
|
|
85
88
|
element.className = "rr-lightbox";
|
|
86
89
|
element.setAttribute("role", "dialog");
|
|
87
90
|
element.setAttribute("aria-modal", "true");
|
|
88
|
-
element.setAttribute("aria-label",
|
|
91
|
+
element.setAttribute("aria-label", options.expandLabel);
|
|
89
92
|
element.tabIndex = -1;
|
|
90
93
|
element.setAttribute("hidden", "");
|
|
91
94
|
const frame = document.createElement("figure");
|
|
@@ -98,7 +101,7 @@ function createDialog() {
|
|
|
98
101
|
const closeButton = document.createElement("button");
|
|
99
102
|
closeButton.className = "rr-lightbox__close";
|
|
100
103
|
closeButton.type = "button";
|
|
101
|
-
closeButton.setAttribute("aria-label",
|
|
104
|
+
closeButton.setAttribute("aria-label", options.closeLabel);
|
|
102
105
|
closeButton.textContent = "×";
|
|
103
106
|
frame.appendChild(image);
|
|
104
107
|
frame.appendChild(caption);
|
|
@@ -110,7 +113,9 @@ function createDialog() {
|
|
|
110
113
|
// src/init.ts
|
|
111
114
|
function initLightbox(root = document, options = {}) {
|
|
112
115
|
const triggerClass = options.selectorClass ?? DEFAULT_TRIGGER_CLASS;
|
|
113
|
-
const
|
|
116
|
+
const expandLabel = options.expandLabel ?? DEFAULT_EXPAND_LABEL;
|
|
117
|
+
const closeLabel = options.closeLabel ?? DEFAULT_CLOSE_LABEL;
|
|
118
|
+
const wrappedTriggers = options.autoWrapImages === false ? [] : wrapImages(root, triggerClass, expandLabel);
|
|
114
119
|
const triggers = Array.from(
|
|
115
120
|
root.querySelectorAll(`.${triggerClass}`)
|
|
116
121
|
);
|
|
@@ -120,7 +125,7 @@ function initLightbox(root = document, options = {}) {
|
|
|
120
125
|
};
|
|
121
126
|
}
|
|
122
127
|
let previouslyFocused = null;
|
|
123
|
-
const dialog = createDialog();
|
|
128
|
+
const dialog = createDialog({ expandLabel, closeLabel });
|
|
124
129
|
document.body.appendChild(dialog.element);
|
|
125
130
|
const open = (trigger) => {
|
|
126
131
|
const src = trigger.dataset.lightboxSrc ?? trigger.href;
|
|
@@ -204,7 +209,7 @@ function getFocusableElements(container) {
|
|
|
204
209
|
)
|
|
205
210
|
).filter((element) => !element.hasAttribute("disabled"));
|
|
206
211
|
}
|
|
207
|
-
function wrapImages(root, triggerClass) {
|
|
212
|
+
function wrapImages(root, triggerClass, expandLabel) {
|
|
208
213
|
const images = Array.from(
|
|
209
214
|
root.querySelectorAll("img[src]")
|
|
210
215
|
);
|
|
@@ -223,7 +228,7 @@ function wrapImages(root, triggerClass) {
|
|
|
223
228
|
trigger.dataset.lightboxAlt = image.alt;
|
|
224
229
|
trigger.setAttribute(
|
|
225
230
|
"aria-label",
|
|
226
|
-
image.alt ?
|
|
231
|
+
image.alt ? `${expandLabel}: ${image.alt}` : expandLabel
|
|
227
232
|
);
|
|
228
233
|
image.parentNode?.insertBefore(trigger, image);
|
|
229
234
|
trigger.appendChild(image);
|
|
@@ -239,20 +244,35 @@ function unwrapImage(trigger) {
|
|
|
239
244
|
trigger.remove();
|
|
240
245
|
}
|
|
241
246
|
|
|
247
|
+
// client.ts
|
|
248
|
+
function initLightboxFromOptions(options = {}) {
|
|
249
|
+
return initLightbox(document, options);
|
|
250
|
+
}
|
|
251
|
+
|
|
242
252
|
// index.ts
|
|
243
253
|
function lightboxPlugin(options = {}) {
|
|
244
254
|
return definePlugin({
|
|
245
255
|
name: "lightbox",
|
|
256
|
+
processedContentCache: {
|
|
257
|
+
version: "lightbox-v2",
|
|
258
|
+
dependencyMode: "none"
|
|
259
|
+
},
|
|
246
260
|
options,
|
|
247
261
|
extendHtmlPipeline: (pipeline) => {
|
|
248
262
|
pipeline.use(rehypeLightbox, options);
|
|
249
263
|
},
|
|
250
264
|
assets: [createStyleAsset("lightbox")],
|
|
251
|
-
clientEntries: [
|
|
265
|
+
clientEntries: [
|
|
266
|
+
createClientEntry("lightbox", "initLightboxFromOptions", {
|
|
267
|
+
expandLabel: options.expandLabel ?? DEFAULT_EXPAND_LABEL,
|
|
268
|
+
closeLabel: options.closeLabel ?? DEFAULT_CLOSE_LABEL
|
|
269
|
+
})
|
|
270
|
+
]
|
|
252
271
|
});
|
|
253
272
|
}
|
|
254
273
|
export {
|
|
255
274
|
initLightbox,
|
|
275
|
+
initLightboxFromOptions,
|
|
256
276
|
lightboxPlugin,
|
|
257
277
|
rehypeLightbox
|
|
258
278
|
};
|
package/dist/src/dialog.d.ts
CHANGED
package/dist/src/types.d.ts
CHANGED
|
@@ -10,8 +10,12 @@ export type HastNode = ElementNode | {
|
|
|
10
10
|
};
|
|
11
11
|
export type LightboxOptions = {
|
|
12
12
|
selectorClass?: string;
|
|
13
|
+
expandLabel?: string;
|
|
14
|
+
closeLabel?: string;
|
|
13
15
|
};
|
|
14
16
|
export type LightboxInitOptions = LightboxOptions & {
|
|
15
17
|
autoWrapImages?: boolean;
|
|
16
18
|
};
|
|
17
19
|
export declare const DEFAULT_TRIGGER_CLASS = "rr-lightbox-trigger";
|
|
20
|
+
export declare const DEFAULT_EXPAND_LABEL = "Expand image";
|
|
21
|
+
export declare const DEFAULT_CLOSE_LABEL = "Close";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riebeckite/plugin-lightbox",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.15",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"./style.css": "./style.css"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@riebeckite/core": "0.0.
|
|
24
|
+
"@riebeckite/core": "0.0.15"
|
|
25
25
|
},
|
|
26
26
|
"publishConfig": {
|
|
27
27
|
"access": "public"
|