@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 +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.cjs
CHANGED
|
@@ -1,346 +1,364 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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
|
-
|
|
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
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
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
|
-
|
|
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
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
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
|