@riebeckite/plugin-rich-embed 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 CHANGED
@@ -75,6 +75,15 @@ listed in `allowHosts`.
75
75
  | `providers` | `RichEmbedProvider[]` | all | Allowlist of providers to enable |
76
76
  | `disable` | `RichEmbedProvider[]` | `[]` | Providers to disable (wins over `providers`) |
77
77
 
78
+ ## Live example
79
+
80
+ ~~~embed
81
+ https://www.youtube.com/watch?v=dQw4w9WgXcQ
82
+ title: Demo video
83
+ caption: A short caption
84
+ aspect: 16/9
85
+ ~~~
86
+
78
87
  ## Output HTML
79
88
 
80
89
  ```html
@@ -136,7 +145,7 @@ warning through the vfile message channel:
136
145
  ## Exports
137
146
 
138
147
  - `richEmbed(options?)` — plugin factory
139
- - `richEmbedPlugin` — alias of `richEmbed`
148
+ - `richEmbed` — alias of `richEmbed`
140
149
  - Types: `RichEmbedOptions`, `RichEmbedProvider`
141
150
 
142
151
  ## See also
package/README_ja.md CHANGED
@@ -9,7 +9,7 @@
9
9
  ## 概要
10
10
 
11
11
  `richEmbed()` は ` ```embed ` フェンスをレスポンシブな
12
- `<figure class="rb-rich-embed">` に置き換えます。プロバイダの判定は URL の文字列解析だけで行うため、ビルド時にネットワークへアクセスしません。クライアント側 JavaScript も不要です。
12
+ `<figure class="rb-rich-embed">` に置き換えます。プロバイダーの判定は URL の文字列解析だけで行うため、ビルド時にネットワークへアクセスしません。クライアント側 JavaScript も不要です。
13
13
 
14
14
  ## 使い方
15
15
 
@@ -50,9 +50,9 @@ start: 30
50
50
 
51
51
  未知のキーは無視します。`aspect` が不正な場合は `16/9` に戻します。
52
52
 
53
- ## 対応プロバイダ
53
+ ## 対応プロバイダー
54
54
 
55
- | プロバイダ | 認識する URL | 出力する `src` |
55
+ | プロバイダー | 認識する URL | 出力する `src` |
56
56
  | ---------- | ------------ | -------------- |
57
57
  | YouTube | `youtube.com/watch?v=`, `youtu.be/`, `/shorts/`, `/embed/`, `/live/` | `https://www.youtube-nocookie.com/embed/<id>` |
58
58
  | Vimeo | `vimeo.com/<数値ID>` | `https://player.vimeo.com/video/<id>` |
@@ -66,9 +66,18 @@ start: 30
66
66
 
67
67
  | オプション | 型 | 既定値 | 説明 |
68
68
  | ---------- | -- | ------ | ---- |
69
- | `allowHosts` | `string[]` | `[]` | 汎用 iframe へのフォールバックを許可するホスト名 |
70
- | `providers` | `RichEmbedProvider[]` | すべて | 有効にするプロバイダの許可リスト |
71
- | `disable` | `RichEmbedProvider[]` | `[]` | 無効にするプロバイダ(`providers` より優先) |
69
+ | `allowHosts` | `string[]` | `[]` | 汎用 `<iframe>` へのフォールバックを許可するホスト名 |
70
+ | `providers` | `RichEmbedProvider[]` | すべて | 有効にするプロバイダーの許可リスト |
71
+ | `disable` | `RichEmbedProvider[]` | `[]` | 無効にするプロバイダー(`providers` より優先) |
72
+
73
+ ## 実行例
74
+
75
+ ~~~embed
76
+ https://www.youtube.com/watch?v=dQw4w9WgXcQ
77
+ title: Demo video
78
+ caption: A short caption
79
+ aspect: 16/9
80
+ ~~~
72
81
 
73
82
  ## 出力 HTML
74
83
 
@@ -113,8 +122,8 @@ Gist の場合は iframe の代わりに
113
122
  ## セキュリティ
114
123
 
115
124
  - `https:` の URL だけを受理します。
116
- - プロバイダの出力は検証済みのパスセグメントから組み立て、動的な部分は `encodeURIComponent` を通します。
117
- - 汎用 iframe には `allowHosts` への明示的な登録が必要です。
125
+ - プロバイダーの出力は検証済みのパスセグメントから組み立て、動的な部分は `encodeURIComponent` を通します。
126
+ - 汎用 `<iframe>` には `allowHosts` への明示的な登録が必要です。
118
127
  - 生のユーザー HTML は出力しません。タイトル・キャプション・ラベルはすべてエスケープされるテキストノードとして書き込みます。
119
128
 
120
129
  ## 制限事項
@@ -126,7 +135,7 @@ Gist の場合は iframe の代わりに
126
135
  ## エクスポート
127
136
 
128
137
  - `richEmbed(options?)`:プラグインファクトリ
129
- - `richEmbedPlugin`:`richEmbed` の別名
138
+ - `richEmbed`:`richEmbed` の別名
130
139
  - 型: `RichEmbedOptions`, `RichEmbedProvider`
131
140
 
132
141
  ## 関連
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
1
  import type { RichEmbedOptions } from "./src/types.js";
2
2
  export type { RichEmbedOptions, RichEmbedProvider } from "./src/types.js";
3
3
  export declare function richEmbed(options?: RichEmbedOptions): import("@riebeckite/core").RiebeckitePlugin<RichEmbedOptions>;
4
- export declare const richEmbedPlugin: typeof richEmbed;
package/dist/index.js CHANGED
@@ -216,44 +216,18 @@ function parseStart(value) {
216
216
  }
217
217
 
218
218
  // src/hast.ts
219
- function visitElements(node, visitor, parent, index) {
220
- if (isElementNode(node)) visitor(node, parent, index);
221
- for (const [childIndex, child] of [...getChildren(node)].entries()) {
222
- visitElements(
223
- child,
224
- visitor,
225
- hasChildren(node) ? node : parent,
226
- childIndex
227
- );
228
- }
229
- }
230
- function element(tagName, properties = {}, children = []) {
231
- return { type: "element", tagName, properties, children };
232
- }
233
- function text(value) {
234
- return { type: "text", value };
235
- }
236
- function getTextContent(node) {
237
- if (node.type === "text" && "value" in node && typeof node.value === "string") {
238
- return node.value;
239
- }
240
- return getChildren(node).map(getTextContent).join("");
241
- }
242
- function hasClass(node, className) {
243
- const value = node.properties?.className;
244
- const classes = Array.isArray(value) ? value.map(String) : typeof value === "string" ? value.split(/\s+/) : [];
245
- return classes.includes(className);
246
- }
247
- function isElementNode(node) {
248
- return node.type === "element";
249
- }
250
- function hasChildren(node) {
251
- return Array.isArray(node.children);
252
- }
253
- function getChildren(node) {
254
- const children = node.children;
255
- return Array.isArray(children) ? children : [];
256
- }
219
+ import {
220
+ element as sharedElement,
221
+ getTextContent as sharedGetTextContent,
222
+ hasClass as sharedHasClass,
223
+ text as sharedText,
224
+ visitElements as sharedVisitElements
225
+ } from "@riebeckite/diagram";
226
+ var element = sharedElement;
227
+ var text = sharedText;
228
+ var getTextContent = sharedGetTextContent;
229
+ var hasClass = sharedHasClass;
230
+ var visitElements = sharedVisitElements;
257
231
 
258
232
  // src/rehype.ts
259
233
  var DIAGNOSTIC_SOURCE = "@riebeckite/plugin-rich-embed";
@@ -377,7 +351,6 @@ function richEmbed(options = {}) {
377
351
  ]
378
352
  });
379
353
  }
380
- var richEmbedPlugin = richEmbed;
381
354
  function validateRichEmbedOptions(options) {
382
355
  if (!options) return [];
383
356
  const issues = [];
@@ -428,6 +401,5 @@ function isRichEmbedProvider(value) {
428
401
  return typeof value === "string" && RICH_EMBED_PROVIDERS.includes(value);
429
402
  }
430
403
  export {
431
- richEmbed,
432
- richEmbedPlugin
404
+ richEmbed
433
405
  };
@@ -1,8 +1,6 @@
1
1
  import type { ElementNode, HastNode, ParentNode, TextNode } from "./types.js";
2
- export declare function visitElements(node: HastNode, visitor: (node: ElementNode, parent?: ParentNode, index?: number) => void, parent?: ParentNode, index?: number): void;
3
- export declare function element(tagName: string, properties?: Record<string, unknown>, children?: HastNode[]): ElementNode;
4
- export declare function text(value: string): TextNode;
5
- export declare function getTextContent(node: HastNode): string;
6
- export declare function getStringProperty(node: ElementNode, key: string): string | null;
7
- export declare function hasClass(node: ElementNode, className: string): boolean;
8
- export declare function mergeClassName(current: unknown, next: string): string;
2
+ export declare const element: (tagName: string, properties?: Record<string, unknown>, children?: HastNode[]) => ElementNode;
3
+ export declare const text: (value: string) => TextNode;
4
+ export declare const getTextContent: (node: HastNode) => string;
5
+ export declare const hasClass: (node: ElementNode, className: string) => boolean;
6
+ export declare const visitElements: (node: HastNode, visitor: (node: ElementNode, parent?: ParentNode, index?: number) => void, parent?: ParentNode, index?: number) => void;
@@ -1,11 +1,10 @@
1
1
  import type { RichEmbedBlockOptions, RichEmbedOptions, RichEmbedProvider } from "./types.js";
2
2
  export declare const RICH_EMBED_PROVIDERS: readonly RichEmbedProvider[];
3
- export declare const DEFAULT_ASPECT = "16/9";
4
- export type ParsedEmbedBlock = {
3
+ type ParsedEmbedBlock = {
5
4
  url: string;
6
5
  options: RichEmbedBlockOptions;
7
6
  };
8
- export type EmbedResolution = {
7
+ type EmbedResolution = {
9
8
  kind: "iframe";
10
9
  provider: RichEmbedProvider;
11
10
  src: string;
@@ -30,9 +29,9 @@ export type SupportedEmbedResolution = Exclude<EmbedResolution, {
30
29
  * every following `key: value` line is an option.
31
30
  */
32
31
  export declare function parseEmbedBlock(source: string): ParsedEmbedBlock | null;
33
- export declare function normalizeAspect(value: string): string | null;
34
32
  /**
35
33
  * Resolves a URL to an embeddable target using only string inspection. No
36
34
  * network request is performed.
37
35
  */
38
36
  export declare function resolveEmbed(urlText: string, block: RichEmbedBlockOptions, config: RichEmbedOptions): EmbedResolution;
37
+ export {};
@@ -39,7 +39,7 @@ export type TextNode = {
39
39
  type: "text";
40
40
  value: string;
41
41
  };
42
- export type RawNode = {
42
+ type RawNode = {
43
43
  type: "raw";
44
44
  value: string;
45
45
  };
@@ -47,3 +47,4 @@ export type HastNode = ElementNode | TextNode | RawNode | {
47
47
  type: string;
48
48
  [key: string]: unknown;
49
49
  };
50
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riebeckite/plugin-rich-embed",
3
- "version": "0.0.31",
3
+ "version": "0.0.33",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -15,7 +15,8 @@
15
15
  "./style.css": "./style.css"
16
16
  },
17
17
  "dependencies": {
18
- "@riebeckite/core": "0.0.31"
18
+ "@riebeckite/core": "0.0.33",
19
+ "@riebeckite/diagram": "0.0.33"
19
20
  },
20
21
  "publishConfig": {
21
22
  "access": "public"