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