@tiptap/extension-twitch 3.30.2 → 3.30.3

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.js CHANGED
@@ -1,313 +1,353 @@
1
- // src/twitch.ts
2
- import { createAtomBlockMarkdownSpec, mergeAttributes, Node, nodePasteRule } from "@tiptap/core";
3
-
4
- // src/utils.ts
5
- var TWITCH_REGEX = /^(https?:\/\/)?(www\.)?(twitch\.tv|clips\.twitch\.tv)\/(?:videos\/(\d+)|(\w+)\/clip\/([\w-]+)|([\w-]+)(?:\/)?)?(\?.*)?$/;
6
- var TWITCH_REGEX_GLOBAL = /^(https?:\/\/)?(www\.)?(twitch\.tv|clips\.twitch\.tv)\/(?:videos\/(\d+)|(\w+)\/clip\/([\w-]+)|([\w-]+)(?:\/)?)?(\?.*)?$/g;
7
- var isValidTwitchUrl = (url) => {
8
- return url.match(TWITCH_REGEX);
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
- var getTwitchIdentifier = (url) => {
11
- if (!isValidTwitchUrl(url)) {
12
- return null;
13
- }
14
- const cleanUrl = url.split("?")[0];
15
- if (cleanUrl.includes("clips.twitch.tv/")) {
16
- const clipRegex = /clips\.twitch\.tv\/([\w-]+)/;
17
- const match = cleanUrl.match(clipRegex);
18
- return match ? { type: "clip", id: match[1] } : null;
19
- }
20
- if (cleanUrl.includes("twitch.tv/")) {
21
- const videoRegex = /twitch\.tv\/videos\/(\d+)/;
22
- const videoMatch = cleanUrl.match(videoRegex);
23
- if (videoMatch) {
24
- return { type: "video", id: videoMatch[1] };
25
- }
26
- const channelClipRegex = /twitch\.tv\/([\w-]+)\/clip\/([\w-]+)/;
27
- const clipMatch = cleanUrl.match(channelClipRegex);
28
- if (clipMatch) {
29
- return { type: "clip", id: clipMatch[2] };
30
- }
31
- const channelRegex = /twitch\.tv\/([\w-]+)(?:\/)?$/;
32
- const channelMatch = cleanUrl.match(channelRegex);
33
- if (channelMatch) {
34
- return { type: "channel", id: channelMatch[1] };
35
- }
36
- }
37
- return null;
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
- var getEmbedUrlFromTwitchUrl = (options) => {
40
- const { url, allowFullscreen = true, autoplay = false, muted = false, time, parent } = options;
41
- const identifier = getTwitchIdentifier(url);
42
- if (!identifier) {
43
- return null;
44
- }
45
- const parentDomain = parent || "localhost";
46
- if (identifier.type === "clip") {
47
- const clipUrl = new URL("https://clips.twitch.tv/embed");
48
- clipUrl.searchParams.set("clip", identifier.id);
49
- clipUrl.searchParams.set("parent", parentDomain);
50
- if (autoplay) {
51
- clipUrl.searchParams.set("autoplay", "true");
52
- }
53
- if (muted) {
54
- clipUrl.searchParams.set("muted", "true");
55
- }
56
- return clipUrl.toString();
57
- }
58
- if (identifier.type === "video") {
59
- const videoUrl = new URL("https://player.twitch.tv/");
60
- videoUrl.searchParams.set("video", identifier.id);
61
- videoUrl.searchParams.set("parent", parentDomain);
62
- if (allowFullscreen) {
63
- videoUrl.searchParams.set("allowfullscreen", "true");
64
- }
65
- if (autoplay) {
66
- videoUrl.searchParams.set("autoplay", "true");
67
- }
68
- if (muted) {
69
- videoUrl.searchParams.set("muted", "true");
70
- }
71
- if (time) {
72
- videoUrl.searchParams.set("time", time);
73
- }
74
- return videoUrl.toString();
75
- }
76
- if (identifier.type === "channel") {
77
- const channelUrl = new URL("https://player.twitch.tv/");
78
- channelUrl.searchParams.set("channel", identifier.id);
79
- channelUrl.searchParams.set("parent", parentDomain);
80
- if (allowFullscreen) {
81
- channelUrl.searchParams.set("allowfullscreen", "true");
82
- }
83
- if (autoplay) {
84
- channelUrl.searchParams.set("autoplay", "true");
85
- }
86
- if (muted) {
87
- channelUrl.searchParams.set("muted", "true");
88
- }
89
- return channelUrl.toString();
90
- }
91
- return null;
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
- var getAttributesFromTwitchEmbedUrl = (url) => {
94
- let parsedUrl;
95
- try {
96
- parsedUrl = new URL(url);
97
- } catch {
98
- return null;
99
- }
100
- const hostname = parsedUrl.hostname.replace(/^www\./, "");
101
- const result = {
102
- src: ""
103
- };
104
- if (hostname === "player.twitch.tv") {
105
- const videoId = parsedUrl.searchParams.get("video");
106
- const channelName = parsedUrl.searchParams.get("channel");
107
- if (videoId) {
108
- result.src = `https://www.twitch.tv/videos/${videoId}`;
109
- } else if (channelName) {
110
- result.src = `https://www.twitch.tv/${channelName}`;
111
- } else {
112
- return null;
113
- }
114
- } else if (hostname === "clips.twitch.tv" && parsedUrl.pathname === "/embed") {
115
- const clipId = parsedUrl.searchParams.get("clip");
116
- if (!clipId) {
117
- return null;
118
- }
119
- result.src = `https://clips.twitch.tv/${clipId}`;
120
- } else {
121
- return null;
122
- }
123
- if (parsedUrl.searchParams.get("autoplay") === "true") {
124
- result.autoplay = true;
125
- }
126
- if (parsedUrl.searchParams.get("muted") === "true") {
127
- result.muted = true;
128
- }
129
- const time = parsedUrl.searchParams.get("time");
130
- if (time) {
131
- result.time = time;
132
- }
133
- if (!isValidTwitchUrl(result.src)) {
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
- // src/twitch.ts
140
- var getParsedDimension = (value) => {
141
- if (!value) {
142
- return null;
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
- var getParsedTwitchAttributes = (element) => {
148
- const src = element.getAttribute("src");
149
- if (!src) {
150
- return null;
151
- }
152
- const embedAttributes = getAttributesFromTwitchEmbedUrl(src);
153
- if (embedAttributes) {
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
- var Twitch = Node.create({
166
- name: "twitch",
167
- addOptions() {
168
- return {
169
- addPasteHandler: true,
170
- allowFullscreen: true,
171
- autoplay: false,
172
- muted: false,
173
- time: void 0,
174
- parent: "localhost",
175
- height: 480,
176
- width: 640,
177
- HTMLAttributes: {},
178
- inline: false
179
- };
180
- },
181
- inline() {
182
- return this.options.inline;
183
- },
184
- group() {
185
- return this.options.inline ? "inline" : "block";
186
- },
187
- draggable: true,
188
- addAttributes() {
189
- return {
190
- src: {
191
- default: null,
192
- parseHTML: (element) => {
193
- var _a;
194
- return (_a = getParsedTwitchAttributes(element)) == null ? void 0 : _a.src;
195
- }
196
- },
197
- width: {
198
- default: this.options.width,
199
- parseHTML: (element) => getParsedDimension(element.getAttribute("width"))
200
- },
201
- height: {
202
- default: this.options.height,
203
- parseHTML: (element) => getParsedDimension(element.getAttribute("height"))
204
- },
205
- autoplay: {
206
- default: this.options.autoplay,
207
- parseHTML: (element) => {
208
- var _a;
209
- return (_a = getParsedTwitchAttributes(element)) == null ? void 0 : _a.autoplay;
210
- }
211
- },
212
- muted: {
213
- default: this.options.muted,
214
- parseHTML: (element) => {
215
- var _a;
216
- return (_a = getParsedTwitchAttributes(element)) == null ? void 0 : _a.muted;
217
- }
218
- },
219
- time: {
220
- default: this.options.time,
221
- parseHTML: (element) => {
222
- var _a;
223
- return (_a = getParsedTwitchAttributes(element)) == null ? void 0 : _a.time;
224
- }
225
- }
226
- };
227
- },
228
- parseHTML() {
229
- return [
230
- {
231
- tag: "div[data-twitch-video] iframe"
232
- }
233
- ];
234
- },
235
- addCommands() {
236
- return {
237
- setTwitchVideo: (options) => ({ commands }) => {
238
- if (!isValidTwitchUrl(options.src)) {
239
- return false;
240
- }
241
- return commands.insertContent({
242
- type: this.name,
243
- attrs: options
244
- });
245
- }
246
- };
247
- },
248
- addPasteRules() {
249
- if (!this.options.addPasteHandler) {
250
- return [];
251
- }
252
- return [
253
- nodePasteRule({
254
- find: TWITCH_REGEX_GLOBAL,
255
- type: this.type,
256
- getAttributes: (match) => {
257
- return { src: match.input };
258
- }
259
- })
260
- ];
261
- },
262
- renderHTML({ HTMLAttributes }) {
263
- var _a, _b, _c;
264
- const embedUrl = getEmbedUrlFromTwitchUrl({
265
- url: HTMLAttributes.src,
266
- allowFullscreen: this.options.allowFullscreen,
267
- autoplay: (_a = HTMLAttributes.autoplay) != null ? _a : this.options.autoplay,
268
- muted: (_b = HTMLAttributes.muted) != null ? _b : this.options.muted,
269
- time: (_c = HTMLAttributes.time) != null ? _c : this.options.time,
270
- parent: this.options.parent
271
- });
272
- if (!embedUrl) {
273
- return ["div", "Invalid Twitch URL"];
274
- }
275
- HTMLAttributes.src = embedUrl;
276
- return [
277
- "div",
278
- { "data-twitch-video": "" },
279
- [
280
- "iframe",
281
- mergeAttributes(
282
- this.options.HTMLAttributes,
283
- {
284
- width: this.options.width,
285
- height: this.options.height,
286
- allowfullscreen: this.options.allowFullscreen,
287
- scrolling: "no",
288
- frameborder: "0"
289
- },
290
- HTMLAttributes
291
- )
292
- ]
293
- ];
294
- },
295
- ...createAtomBlockMarkdownSpec({
296
- nodeName: "twitch",
297
- allowedAttributes: ["src", "width", "height", "autoplay", "muted", "time"]
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