@tiptap/extension-twitch 3.30.2 → 3.30.4
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.cjs +354 -336
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +96 -94
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +96 -94
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +344 -304
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,313 +1,353 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { Node, createAtomBlockMarkdownSpec, mergeAttributes, nodePasteRule } from "@tiptap/core";
|
|
2
|
+
//#region src/utils.ts
|
|
3
|
+
/**
|
|
4
|
+
* Regex patterns for matching Twitch URLs
|
|
5
|
+
* Matches:
|
|
6
|
+
* - https://twitch.tv/videos/1234567890
|
|
7
|
+
* - https://www.twitch.tv/videos/1234567890
|
|
8
|
+
* - https://twitch.tv/examplechannel/clip/ClipName-123
|
|
9
|
+
* - https://www.twitch.tv/examplechannel/clip/ClipName-123
|
|
10
|
+
* - https://clips.twitch.tv/ClipName
|
|
11
|
+
* - https://www.clips.twitch.tv/ClipName
|
|
12
|
+
* - https://twitch.tv/examplechannel (channel)
|
|
13
|
+
* - https://www.twitch.tv/examplechannel
|
|
14
|
+
*/
|
|
15
|
+
const TWITCH_REGEX = /^(https?:\/\/)?(www\.)?(twitch\.tv|clips\.twitch\.tv)\/(?:videos\/(\d+)|(\w+)\/clip\/([\w-]+)|([\w-]+)(?:\/)?)?(\?.*)?$/;
|
|
16
|
+
const TWITCH_REGEX_GLOBAL = /^(https?:\/\/)?(www\.)?(twitch\.tv|clips\.twitch\.tv)\/(?:videos\/(\d+)|(\w+)\/clip\/([\w-]+)|([\w-]+)(?:\/)?)?(\?.*)?$/g;
|
|
17
|
+
/**
|
|
18
|
+
* Validates if a URL is a valid Twitch video, clip or channel URL
|
|
19
|
+
*
|
|
20
|
+
* @param url - The URL to validate
|
|
21
|
+
* @returns true if the URL is a valid Twitch URL
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* isValidTwitchUrl('https://www.twitch.tv/videos/1234567890') // true
|
|
26
|
+
* isValidTwitchUrl('https://www.twitch.tv/examplechannel/clip/ExampleClipName') // true
|
|
27
|
+
* isValidTwitchUrl('https://www.twitch.tv/examplechannel') // true
|
|
28
|
+
* isValidTwitchUrl('https://clips.twitch.tv/ExampleClipName') // true
|
|
29
|
+
* isValidTwitchUrl('invalid') // false
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
const isValidTwitchUrl = (url) => {
|
|
33
|
+
return url.match(TWITCH_REGEX);
|
|
9
34
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Extracts the video, clip or channel identifier from a Twitch URL
|
|
37
|
+
*
|
|
38
|
+
* @param url - The Twitch URL
|
|
39
|
+
* @returns Object containing type ('video', 'clip' or 'channel') and ID, or null if invalid
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* getTwitchIdentifier('https://www.twitch.tv/videos/1234567890')
|
|
44
|
+
* // { type: 'video', id: '1234567890' }
|
|
45
|
+
*
|
|
46
|
+
* getTwitchIdentifier('https://www.twitch.tv/examplechannel/clip/ExampleClipName-ABC123')
|
|
47
|
+
* // { type: 'clip', id: 'ExampleClipName-ABC123' }
|
|
48
|
+
*
|
|
49
|
+
* getTwitchIdentifier('https://www.twitch.tv/examplechannel')
|
|
50
|
+
* // { type: 'channel', id: 'examplechannel' }
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
const getTwitchIdentifier = (url) => {
|
|
54
|
+
if (!isValidTwitchUrl(url)) return null;
|
|
55
|
+
const cleanUrl = url.split("?")[0];
|
|
56
|
+
if (cleanUrl.includes("clips.twitch.tv/")) {
|
|
57
|
+
const match = cleanUrl.match(/clips\.twitch\.tv\/([\w-]+)/);
|
|
58
|
+
return match ? {
|
|
59
|
+
type: "clip",
|
|
60
|
+
id: match[1]
|
|
61
|
+
} : null;
|
|
62
|
+
}
|
|
63
|
+
if (cleanUrl.includes("twitch.tv/")) {
|
|
64
|
+
const videoMatch = cleanUrl.match(/twitch\.tv\/videos\/(\d+)/);
|
|
65
|
+
if (videoMatch) return {
|
|
66
|
+
type: "video",
|
|
67
|
+
id: videoMatch[1]
|
|
68
|
+
};
|
|
69
|
+
const clipMatch = cleanUrl.match(/twitch\.tv\/([\w-]+)\/clip\/([\w-]+)/);
|
|
70
|
+
if (clipMatch) return {
|
|
71
|
+
type: "clip",
|
|
72
|
+
id: clipMatch[2]
|
|
73
|
+
};
|
|
74
|
+
const channelMatch = cleanUrl.match(/twitch\.tv\/([\w-]+)(?:\/)?$/);
|
|
75
|
+
if (channelMatch) return {
|
|
76
|
+
type: "channel",
|
|
77
|
+
id: channelMatch[1]
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
return null;
|
|
38
81
|
};
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
82
|
+
/**
|
|
83
|
+
* Generates an embed URL from a Twitch video, clip or channel URL with optional parameters
|
|
84
|
+
*
|
|
85
|
+
* @param options - The embed URL options
|
|
86
|
+
* @returns The embed URL or null if invalid
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* getEmbedUrlFromTwitchUrl({
|
|
91
|
+
* url: 'https://www.twitch.tv/videos/1234567890',
|
|
92
|
+
* parent: 'example.com',
|
|
93
|
+
* muted: true,
|
|
94
|
+
* time: '1h2m3s'
|
|
95
|
+
* })
|
|
96
|
+
* // Returns: https://player.twitch.tv/?video=1234567890&parent=example.com&muted=true&time=1h2m3s
|
|
97
|
+
*
|
|
98
|
+
* getEmbedUrlFromTwitchUrl({
|
|
99
|
+
* url: 'https://www.twitch.tv/examplechannel/clip/ExampleClipName-ABC123',
|
|
100
|
+
* parent: 'example.com',
|
|
101
|
+
* autoplay: true,
|
|
102
|
+
* muted: true
|
|
103
|
+
* })
|
|
104
|
+
* // Returns: https://clips.twitch.tv/embed?clip=ExampleClipName-ABC123&parent=example.com&autoplay=true&muted=true
|
|
105
|
+
*
|
|
106
|
+
* getEmbedUrlFromTwitchUrl({
|
|
107
|
+
* url: 'https://www.twitch.tv/examplechannel',
|
|
108
|
+
* parent: 'example.com'
|
|
109
|
+
* })
|
|
110
|
+
* // Returns: https://player.twitch.tv/?channel=examplechannel&parent=example.com
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
const getEmbedUrlFromTwitchUrl = (options) => {
|
|
114
|
+
const { url, allowFullscreen = true, autoplay = false, muted = false, time, parent } = options;
|
|
115
|
+
const identifier = getTwitchIdentifier(url);
|
|
116
|
+
if (!identifier) return null;
|
|
117
|
+
const parentDomain = parent || "localhost";
|
|
118
|
+
if (identifier.type === "clip") {
|
|
119
|
+
const clipUrl = new URL("https://clips.twitch.tv/embed");
|
|
120
|
+
clipUrl.searchParams.set("clip", identifier.id);
|
|
121
|
+
clipUrl.searchParams.set("parent", parentDomain);
|
|
122
|
+
if (autoplay) clipUrl.searchParams.set("autoplay", "true");
|
|
123
|
+
if (muted) clipUrl.searchParams.set("muted", "true");
|
|
124
|
+
return clipUrl.toString();
|
|
125
|
+
}
|
|
126
|
+
if (identifier.type === "video") {
|
|
127
|
+
const videoUrl = new URL("https://player.twitch.tv/");
|
|
128
|
+
videoUrl.searchParams.set("video", identifier.id);
|
|
129
|
+
videoUrl.searchParams.set("parent", parentDomain);
|
|
130
|
+
if (allowFullscreen) videoUrl.searchParams.set("allowfullscreen", "true");
|
|
131
|
+
if (autoplay) videoUrl.searchParams.set("autoplay", "true");
|
|
132
|
+
if (muted) videoUrl.searchParams.set("muted", "true");
|
|
133
|
+
if (time) videoUrl.searchParams.set("time", time);
|
|
134
|
+
return videoUrl.toString();
|
|
135
|
+
}
|
|
136
|
+
if (identifier.type === "channel") {
|
|
137
|
+
const channelUrl = new URL("https://player.twitch.tv/");
|
|
138
|
+
channelUrl.searchParams.set("channel", identifier.id);
|
|
139
|
+
channelUrl.searchParams.set("parent", parentDomain);
|
|
140
|
+
if (allowFullscreen) channelUrl.searchParams.set("allowfullscreen", "true");
|
|
141
|
+
if (autoplay) channelUrl.searchParams.set("autoplay", "true");
|
|
142
|
+
if (muted) channelUrl.searchParams.set("muted", "true");
|
|
143
|
+
return channelUrl.toString();
|
|
144
|
+
}
|
|
145
|
+
return null;
|
|
92
146
|
};
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
return null;
|
|
135
|
-
}
|
|
136
|
-
return result;
|
|
147
|
+
/**
|
|
148
|
+
* Parses a Twitch embed URL into canonical Twitch node attributes.
|
|
149
|
+
*
|
|
150
|
+
* @param url - The Twitch embed URL
|
|
151
|
+
* @returns Canonical node attributes or null if the URL is not a supported Twitch embed URL
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```ts
|
|
155
|
+
* getAttributesFromTwitchEmbedUrl('https://player.twitch.tv/?video=1234567890&parent=example.com&muted=true')
|
|
156
|
+
* // Returns: { src: 'https://www.twitch.tv/videos/1234567890', muted: true }
|
|
157
|
+
*
|
|
158
|
+
* getAttributesFromTwitchEmbedUrl('https://clips.twitch.tv/embed?clip=ExampleClipName-ABC123&parent=example.com')
|
|
159
|
+
* // Returns: { src: 'https://clips.twitch.tv/ExampleClipName-ABC123' }
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
const getAttributesFromTwitchEmbedUrl = (url) => {
|
|
163
|
+
let parsedUrl;
|
|
164
|
+
try {
|
|
165
|
+
parsedUrl = new URL(url);
|
|
166
|
+
} catch {
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
const hostname = parsedUrl.hostname.replace(/^www\./, "");
|
|
170
|
+
const result = { src: "" };
|
|
171
|
+
if (hostname === "player.twitch.tv") {
|
|
172
|
+
const videoId = parsedUrl.searchParams.get("video");
|
|
173
|
+
const channelName = parsedUrl.searchParams.get("channel");
|
|
174
|
+
if (videoId) result.src = `https://www.twitch.tv/videos/${videoId}`;
|
|
175
|
+
else if (channelName) result.src = `https://www.twitch.tv/${channelName}`;
|
|
176
|
+
else return null;
|
|
177
|
+
} else if (hostname === "clips.twitch.tv" && parsedUrl.pathname === "/embed") {
|
|
178
|
+
const clipId = parsedUrl.searchParams.get("clip");
|
|
179
|
+
if (!clipId) return null;
|
|
180
|
+
result.src = `https://clips.twitch.tv/${clipId}`;
|
|
181
|
+
} else return null;
|
|
182
|
+
if (parsedUrl.searchParams.get("autoplay") === "true") result.autoplay = true;
|
|
183
|
+
if (parsedUrl.searchParams.get("muted") === "true") result.muted = true;
|
|
184
|
+
const time = parsedUrl.searchParams.get("time");
|
|
185
|
+
if (time) result.time = time;
|
|
186
|
+
if (!isValidTwitchUrl(result.src)) return null;
|
|
187
|
+
return result;
|
|
137
188
|
};
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const parsedValue = Number.parseInt(value, 10);
|
|
145
|
-
return Number.isNaN(parsedValue) ? null : parsedValue;
|
|
189
|
+
//#endregion
|
|
190
|
+
//#region src/twitch.ts
|
|
191
|
+
const getParsedDimension = (value) => {
|
|
192
|
+
if (!value) return null;
|
|
193
|
+
const parsedValue = Number.parseInt(value, 10);
|
|
194
|
+
return Number.isNaN(parsedValue) ? null : parsedValue;
|
|
146
195
|
};
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
return embedAttributes;
|
|
155
|
-
}
|
|
156
|
-
if (isValidTwitchUrl(src)) {
|
|
157
|
-
return {
|
|
158
|
-
src
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
return {
|
|
162
|
-
src
|
|
163
|
-
};
|
|
196
|
+
const getParsedTwitchAttributes = (element) => {
|
|
197
|
+
const src = element.getAttribute("src");
|
|
198
|
+
if (!src) return null;
|
|
199
|
+
const embedAttributes = getAttributesFromTwitchEmbedUrl(src);
|
|
200
|
+
if (embedAttributes) return embedAttributes;
|
|
201
|
+
if (isValidTwitchUrl(src)) return { src };
|
|
202
|
+
return { src };
|
|
164
203
|
};
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
204
|
+
/**
|
|
205
|
+
* This extension adds support for Twitch videos.
|
|
206
|
+
* @see https://www.tiptap.dev/api/nodes/twitch
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* ```ts
|
|
210
|
+
* import { useEditor, EditorContent } from '@tiptap/react'
|
|
211
|
+
* import { StarterKit } from '@tiptap/starter-kit'
|
|
212
|
+
* import { Twitch } from '@tiptap/extension-twitch'
|
|
213
|
+
*
|
|
214
|
+
* const editor = useEditor({
|
|
215
|
+
* extensions: [
|
|
216
|
+
* StarterKit,
|
|
217
|
+
* Twitch.configure({
|
|
218
|
+
* parent: 'example.com',
|
|
219
|
+
* allowFullscreen: true,
|
|
220
|
+
* }),
|
|
221
|
+
* ],
|
|
222
|
+
* content: '<p>Hello World!</p>',
|
|
223
|
+
* })
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
226
|
+
const Twitch = Node.create({
|
|
227
|
+
name: "twitch",
|
|
228
|
+
addOptions() {
|
|
229
|
+
return {
|
|
230
|
+
addPasteHandler: true,
|
|
231
|
+
allowFullscreen: true,
|
|
232
|
+
autoplay: false,
|
|
233
|
+
muted: false,
|
|
234
|
+
time: void 0,
|
|
235
|
+
parent: "localhost",
|
|
236
|
+
height: 480,
|
|
237
|
+
width: 640,
|
|
238
|
+
HTMLAttributes: {},
|
|
239
|
+
inline: false
|
|
240
|
+
};
|
|
241
|
+
},
|
|
242
|
+
inline() {
|
|
243
|
+
return this.options.inline;
|
|
244
|
+
},
|
|
245
|
+
group() {
|
|
246
|
+
return this.options.inline ? "inline" : "block";
|
|
247
|
+
},
|
|
248
|
+
draggable: true,
|
|
249
|
+
addAttributes() {
|
|
250
|
+
return {
|
|
251
|
+
src: {
|
|
252
|
+
default: null,
|
|
253
|
+
parseHTML: (element) => {
|
|
254
|
+
var _getParsedTwitchAttri;
|
|
255
|
+
return (_getParsedTwitchAttri = getParsedTwitchAttributes(element)) === null || _getParsedTwitchAttri === void 0 ? void 0 : _getParsedTwitchAttri.src;
|
|
256
|
+
}
|
|
257
|
+
},
|
|
258
|
+
width: {
|
|
259
|
+
default: this.options.width,
|
|
260
|
+
parseHTML: (element) => getParsedDimension(element.getAttribute("width"))
|
|
261
|
+
},
|
|
262
|
+
height: {
|
|
263
|
+
default: this.options.height,
|
|
264
|
+
parseHTML: (element) => getParsedDimension(element.getAttribute("height"))
|
|
265
|
+
},
|
|
266
|
+
autoplay: {
|
|
267
|
+
default: this.options.autoplay,
|
|
268
|
+
parseHTML: (element) => {
|
|
269
|
+
var _getParsedTwitchAttri2;
|
|
270
|
+
return (_getParsedTwitchAttri2 = getParsedTwitchAttributes(element)) === null || _getParsedTwitchAttri2 === void 0 ? void 0 : _getParsedTwitchAttri2.autoplay;
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
muted: {
|
|
274
|
+
default: this.options.muted,
|
|
275
|
+
parseHTML: (element) => {
|
|
276
|
+
var _getParsedTwitchAttri3;
|
|
277
|
+
return (_getParsedTwitchAttri3 = getParsedTwitchAttributes(element)) === null || _getParsedTwitchAttri3 === void 0 ? void 0 : _getParsedTwitchAttri3.muted;
|
|
278
|
+
}
|
|
279
|
+
},
|
|
280
|
+
time: {
|
|
281
|
+
default: this.options.time,
|
|
282
|
+
parseHTML: (element) => {
|
|
283
|
+
var _getParsedTwitchAttri4;
|
|
284
|
+
return (_getParsedTwitchAttri4 = getParsedTwitchAttributes(element)) === null || _getParsedTwitchAttri4 === void 0 ? void 0 : _getParsedTwitchAttri4.time;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
},
|
|
289
|
+
parseHTML() {
|
|
290
|
+
return [{ tag: "div[data-twitch-video] iframe" }];
|
|
291
|
+
},
|
|
292
|
+
addCommands() {
|
|
293
|
+
return { setTwitchVideo: (options) => ({ commands }) => {
|
|
294
|
+
if (!isValidTwitchUrl(options.src)) return false;
|
|
295
|
+
return commands.insertContent({
|
|
296
|
+
type: this.name,
|
|
297
|
+
attrs: options
|
|
298
|
+
});
|
|
299
|
+
} };
|
|
300
|
+
},
|
|
301
|
+
addPasteRules() {
|
|
302
|
+
if (!this.options.addPasteHandler) return [];
|
|
303
|
+
return [nodePasteRule({
|
|
304
|
+
find: TWITCH_REGEX_GLOBAL,
|
|
305
|
+
type: this.type,
|
|
306
|
+
getAttributes: (match) => {
|
|
307
|
+
return { src: match.input };
|
|
308
|
+
}
|
|
309
|
+
})];
|
|
310
|
+
},
|
|
311
|
+
renderHTML({ HTMLAttributes }) {
|
|
312
|
+
var _HTMLAttributes$autop, _HTMLAttributes$muted, _HTMLAttributes$time;
|
|
313
|
+
const embedUrl = getEmbedUrlFromTwitchUrl({
|
|
314
|
+
url: HTMLAttributes.src,
|
|
315
|
+
allowFullscreen: this.options.allowFullscreen,
|
|
316
|
+
autoplay: (_HTMLAttributes$autop = HTMLAttributes.autoplay) !== null && _HTMLAttributes$autop !== void 0 ? _HTMLAttributes$autop : this.options.autoplay,
|
|
317
|
+
muted: (_HTMLAttributes$muted = HTMLAttributes.muted) !== null && _HTMLAttributes$muted !== void 0 ? _HTMLAttributes$muted : this.options.muted,
|
|
318
|
+
time: (_HTMLAttributes$time = HTMLAttributes.time) !== null && _HTMLAttributes$time !== void 0 ? _HTMLAttributes$time : this.options.time,
|
|
319
|
+
parent: this.options.parent
|
|
320
|
+
});
|
|
321
|
+
if (!embedUrl) return ["div", "Invalid Twitch URL"];
|
|
322
|
+
HTMLAttributes.src = embedUrl;
|
|
323
|
+
return [
|
|
324
|
+
"div",
|
|
325
|
+
{ "data-twitch-video": "" },
|
|
326
|
+
["iframe", mergeAttributes(this.options.HTMLAttributes, {
|
|
327
|
+
width: this.options.width,
|
|
328
|
+
height: this.options.height,
|
|
329
|
+
allowfullscreen: this.options.allowFullscreen,
|
|
330
|
+
scrolling: "no",
|
|
331
|
+
frameborder: "0"
|
|
332
|
+
}, HTMLAttributes)]
|
|
333
|
+
];
|
|
334
|
+
},
|
|
335
|
+
...createAtomBlockMarkdownSpec({
|
|
336
|
+
nodeName: "twitch",
|
|
337
|
+
allowedAttributes: [
|
|
338
|
+
"src",
|
|
339
|
+
"width",
|
|
340
|
+
"height",
|
|
341
|
+
"autoplay",
|
|
342
|
+
"muted",
|
|
343
|
+
"time"
|
|
344
|
+
]
|
|
345
|
+
})
|
|
299
346
|
});
|
|
347
|
+
//#endregion
|
|
348
|
+
//#region src/index.ts
|
|
349
|
+
var src_default = Twitch;
|
|
350
|
+
//#endregion
|
|
351
|
+
export { TWITCH_REGEX, TWITCH_REGEX_GLOBAL, Twitch, src_default as default, getAttributesFromTwitchEmbedUrl, getEmbedUrlFromTwitchUrl, getTwitchIdentifier, isValidTwitchUrl };
|
|
300
352
|
|
|
301
|
-
// src/index.ts
|
|
302
|
-
var index_default = Twitch;
|
|
303
|
-
export {
|
|
304
|
-
TWITCH_REGEX,
|
|
305
|
-
TWITCH_REGEX_GLOBAL,
|
|
306
|
-
Twitch,
|
|
307
|
-
index_default as default,
|
|
308
|
-
getAttributesFromTwitchEmbedUrl,
|
|
309
|
-
getEmbedUrlFromTwitchUrl,
|
|
310
|
-
getTwitchIdentifier,
|
|
311
|
-
isValidTwitchUrl
|
|
312
|
-
};
|
|
313
353
|
//# sourceMappingURL=index.js.map
|