@riebeckite/plugin-responsive-image 0.0.31 → 0.0.33
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 +15 -15
- package/README_ja.md +13 -8
- package/dist/index.d.ts +0 -1
- package/dist/index.js +3 -4
- package/dist/src/hast.d.ts +0 -1
- package/dist/src/rehype.d.ts +0 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
<!-- Generated from docs/docs/plugins/responsive-image.md. Edit the canonical documentation in docs/docs/plugins and run `pnpm docs:sync`. -->
|
|
4
4
|
|
|
5
5
|
Upgrades existing `<img>` elements with lazy loading and responsive
|
|
6
|
-
`<picture>` / `srcset` markup, using only image variants
|
|
7
|
-
|
|
6
|
+
`<picture>` / `srcset` markup, using only image variants already present in the
|
|
7
|
+
content manifest, including variants from `imageOptimizer()`.
|
|
8
8
|
|
|
9
9
|
[日本語](./README_ja.md)
|
|
10
10
|
|
|
@@ -30,17 +30,24 @@ assets that the manifest already knows about.
|
|
|
30
30
|
import { defineConfig } from "@riebeckite/core";
|
|
31
31
|
import { attachment } from "@riebeckite/plugin-attachment";
|
|
32
32
|
import { obsidianMarkdown } from "@riebeckite/plugin-obsidian-markdown";
|
|
33
|
+
import { imageOptimizer } from "@riebeckite/plugin-image-optimizer";
|
|
33
34
|
import { responsiveImage } from "@riebeckite/plugin-responsive-image";
|
|
34
35
|
|
|
35
36
|
export default defineConfig({
|
|
36
37
|
// ...
|
|
37
|
-
plugins: [obsidianMarkdown(), attachment(), responsiveImage()],
|
|
38
|
+
plugins: [obsidianMarkdown(), attachment(), imageOptimizer(), responsiveImage()],
|
|
38
39
|
});
|
|
39
40
|
```
|
|
40
41
|
|
|
41
42
|
`responsiveImage()` uses `order: 100`, so it runs after the media and
|
|
42
43
|
attachment renderers.
|
|
43
44
|
|
|
45
|
+
## Live example
|
|
46
|
+
|
|
47
|
+
The logo below is emitted as a `<picture>` element when image variants exist in the manifest.
|
|
48
|
+
|
|
49
|
+

|
|
50
|
+
|
|
44
51
|
## Options
|
|
45
52
|
|
|
46
53
|
| Option | Type | Default | Description |
|
|
@@ -67,22 +74,15 @@ site asset URL (`/attachments/photo.png`) and the attachment URL
|
|
|
67
74
|
(`/assets/attachments/photo.png`). If the source cannot be matched to a manifest
|
|
68
75
|
asset, the `<img>` is left untouched.
|
|
69
76
|
|
|
70
|
-
##
|
|
71
|
-
|
|
72
|
-
This plugin is a deterministic discovery/HTML layer. It does **not** encode or
|
|
73
|
-
generate new image files by default. `PluginAsset` only supports `style` and
|
|
74
|
-
`script` module specifiers, so Core currently exposes no supported way for a
|
|
75
|
-
plugin to emit arbitrary binary files into the build output.
|
|
77
|
+
## Image encoding
|
|
76
78
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
commit them next to the original image. Sites copy referenced vault assets into
|
|
81
|
-
`public/` through `apps/web/scripts/build_images.ts`.
|
|
79
|
+
This plugin remains a deterministic markup layer. Add
|
|
80
|
+
`@riebeckite/plugin-image-optimizer` to encode WebP and AVIF variants during the
|
|
81
|
+
same build; generated assets are discovered before this plugin creates markup.
|
|
82
82
|
|
|
83
83
|
## Exports
|
|
84
84
|
|
|
85
|
-
- `responsiveImage(options?)` / `
|
|
85
|
+
- `responsiveImage(options?)` / `responsiveImage` — plugin factory
|
|
86
86
|
- `resolveResponsiveImageOptions(options?)` — resolve defaults
|
|
87
87
|
- `buildResponsiveSrcset(existingPaths, src, options?)` — pure srcset planner
|
|
88
88
|
- `applyResponsiveImages(html, existingPaths, options?)` — HTML transform
|
package/README_ja.md
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
<!-- Generated from docs/docs/plugins/responsive-image.ja.md. Edit the canonical documentation in docs/docs/plugins and run `pnpm docs:sync`. -->
|
|
4
4
|
|
|
5
|
-
既存の `<img>` に遅延読み込みと、レスポンシブな `<picture>` / `srcset`
|
|
5
|
+
既存の `<img>` に遅延読み込みと、レスポンシブな `<picture>` / `srcset` を付与するプラグインです。参照するのは、`imageOptimizer()` が生成したものを含め、すでにコンテンツマニフェストに存在する画像バリアントだけです。
|
|
6
6
|
|
|
7
7
|
[English](./README.md)
|
|
8
8
|
|
|
9
9
|
## できること
|
|
10
10
|
|
|
11
|
-
`responsiveImage()` はビルド時の HTML
|
|
11
|
+
`responsiveImage()` はビルド時の HTML 変換レイヤーとして動作します。
|
|
12
12
|
|
|
13
13
|
1. `<img>` に `loading="lazy"` と `decoding="async"` を付与します。すでに属性がある場合は変更しません。
|
|
14
14
|
2. `sizes` がなければ追加します。
|
|
@@ -22,16 +22,23 @@ URL を捏造することはありません。ファイルを書き出すこと
|
|
|
22
22
|
import { defineConfig } from "@riebeckite/core";
|
|
23
23
|
import { attachment } from "@riebeckite/plugin-attachment";
|
|
24
24
|
import { obsidianMarkdown } from "@riebeckite/plugin-obsidian-markdown";
|
|
25
|
+
import { imageOptimizer } from "@riebeckite/plugin-image-optimizer";
|
|
25
26
|
import { responsiveImage } from "@riebeckite/plugin-responsive-image";
|
|
26
27
|
|
|
27
28
|
export default defineConfig({
|
|
28
29
|
// ...
|
|
29
|
-
plugins: [obsidianMarkdown(), attachment(), responsiveImage()],
|
|
30
|
+
plugins: [obsidianMarkdown(), attachment(), imageOptimizer(), responsiveImage()],
|
|
30
31
|
});
|
|
31
32
|
```
|
|
32
33
|
|
|
33
34
|
`responsiveImage()` は `order: 100` で動作するため、メディアと添付ファイルのレンダラーより後に実行されます。
|
|
34
35
|
|
|
36
|
+
## 実行例
|
|
37
|
+
|
|
38
|
+
マニフェストに画像のバリアントがあれば、次のロゴは `<picture>` 要素として出力されます。
|
|
39
|
+
|
|
40
|
+

|
|
41
|
+
|
|
35
42
|
## オプション
|
|
36
43
|
|
|
37
44
|
| オプション | 型 | 既定値 | 内容 |
|
|
@@ -55,15 +62,13 @@ export default defineConfig({
|
|
|
55
62
|
|
|
56
63
|
元の `<img src>` は、サイトのアセット URL(`/attachments/photo.png`)と添付ファイル URL(`/assets/attachments/photo.png`)の両方を試して、マニフェスト上のアセットに対応付けます。対応するアセットが見つからない `<img>` はそのまま残します。
|
|
57
64
|
|
|
58
|
-
##
|
|
59
|
-
|
|
60
|
-
このプラグインは、決定的な探索と HTML 変換だけを担当します。既定では新しい画像ファイルを生成しません。`PluginAsset` は `style` と `script` のモジュール指定子しか扱えず、プラグインが任意のバイナリファイルをビルド成果物へ出力する手段を Core は提供していません。
|
|
65
|
+
## 画像のエンコード
|
|
61
66
|
|
|
62
|
-
|
|
67
|
+
このプラグインは引き続き決定的なマークアップ変換だけを担当します。同じビルドで WebP と AVIF を生成するには、`@riebeckite/plugin-image-optimizer` を追加してください。生成アセットは、このプラグインがマークアップを作る前に検出されます。
|
|
63
68
|
|
|
64
69
|
## 公開 API
|
|
65
70
|
|
|
66
|
-
- `responsiveImage(options?)` / `
|
|
71
|
+
- `responsiveImage(options?)` / `responsiveImage`:プラグインファクトリ
|
|
67
72
|
- `resolveResponsiveImageOptions(options?)`:既定値の解決
|
|
68
73
|
- `buildResponsiveSrcset(existingPaths, src, options?)`:純粋な srcset 計画
|
|
69
74
|
- `applyResponsiveImages(html, existingPaths, options?)`:HTML 変換
|
package/dist/index.d.ts
CHANGED
|
@@ -14,4 +14,3 @@ export type { ResponsiveImagePlan, ResponsiveImageSource, ResponsiveImageVariant
|
|
|
14
14
|
* content manifest. It never fabricates URLs and never writes files.
|
|
15
15
|
*/
|
|
16
16
|
export declare function responsiveImage(options?: ResponsiveImageOptions): import("@riebeckite/core").RiebeckitePlugin<ResponsiveImageOptions>;
|
|
17
|
-
export declare const responsiveImagePlugin: typeof responsiveImage;
|
package/dist/index.js
CHANGED
|
@@ -385,11 +385,12 @@ function responsiveImage(options = {}) {
|
|
|
385
385
|
return definePlugin({
|
|
386
386
|
name: PLUGIN_NAME,
|
|
387
387
|
order: 100,
|
|
388
|
+
optional: ["image-transforms"],
|
|
388
389
|
processedContentCache: {
|
|
389
390
|
version: "responsive-image-v1",
|
|
390
391
|
dependencyMode: "none"
|
|
391
392
|
},
|
|
392
|
-
|
|
393
|
+
resolveContentOutputDependencies: ({ entry }) => entry.html.includes(RESPONSIVE_IMAGE_MARKER) ? [{ type: "global" }] : [],
|
|
393
394
|
options,
|
|
394
395
|
validateOptions: validateResponsiveImageOptions,
|
|
395
396
|
extendHtmlPipeline: (pipeline) => {
|
|
@@ -417,7 +418,6 @@ function responsiveImage(options = {}) {
|
|
|
417
418
|
]
|
|
418
419
|
});
|
|
419
420
|
}
|
|
420
|
-
var responsiveImagePlugin = responsiveImage;
|
|
421
421
|
export {
|
|
422
422
|
DEFAULT_RESPONSIVE_IMAGE_CLASS,
|
|
423
423
|
DEFAULT_RESPONSIVE_IMAGE_FORMATS,
|
|
@@ -428,6 +428,5 @@ export {
|
|
|
428
428
|
collectKnownAssetPaths,
|
|
429
429
|
rehypeResponsiveImage,
|
|
430
430
|
resolveResponsiveImageOptions,
|
|
431
|
-
responsiveImage
|
|
432
|
-
responsiveImagePlugin
|
|
431
|
+
responsiveImage
|
|
433
432
|
};
|
package/dist/src/hast.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { ElementNode, HastNode } from "./types.js";
|
|
2
2
|
export declare function visitElements(node: HastNode, visitor: (node: ElementNode, parent?: ElementNode, index?: number) => void, parent?: ElementNode, index?: number): void;
|
|
3
|
-
export declare function isElementNode(node: HastNode): node is ElementNode;
|
|
4
3
|
export declare function getStringProperty(node: ElementNode, key: string): string | null;
|
|
5
4
|
export declare function hasProperty(node: ElementNode, key: string): boolean;
|
|
6
5
|
export declare function ensureProperty(node: ElementNode, key: string, value: string): void;
|
package/dist/src/rehype.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { ResponsiveImageOptions } from "./options.js";
|
|
2
2
|
import type { HastNode } from "./types.js";
|
|
3
3
|
export declare const RESPONSIVE_IMAGE_MARKER = "data-responsive-image";
|
|
4
|
-
export declare const RESPONSIVE_IMAGE_SOURCE = "@riebeckite/plugin-responsive-image";
|
|
5
4
|
/**
|
|
6
5
|
* HTML-pipeline pass: normalise the responsive attributes on every `<img>` and
|
|
7
6
|
* mark it so the manifest pass can wrap it once the asset set is known.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riebeckite/plugin-responsive-image",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.33",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -15,11 +15,11 @@
|
|
|
15
15
|
"./style.css": "./style.css"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@riebeckite/core": "0.0.
|
|
18
|
+
"@riebeckite/core": "0.0.33"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"
|
|
22
|
-
"
|
|
21
|
+
"@riebeckite/test": "0.0.33",
|
|
22
|
+
"tsx": "^4.22.4"
|
|
23
23
|
},
|
|
24
24
|
"publishConfig": {
|
|
25
25
|
"access": "public"
|