@tiptap/extension-twitch 3.0.0
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/LICENSE.md +21 -0
- package/README.md +18 -0
- package/dist/index.cjs +256 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +206 -0
- package/dist/index.d.ts +206 -0
- package/dist/index.js +224 -0
- package/dist/index.js.map +1 -0
- package/package.json +48 -0
- package/src/index.ts +6 -0
- package/src/twitch.ts +257 -0
- package/src/utils.ts +213 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025, Tiptap GmbH
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# @tiptap/extension-twitch
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@tiptap/extension-twitch)
|
|
4
|
+
[](https://npmcharts.com/compare/@tiptap/extension-twitch?minimal=true)
|
|
5
|
+
[](https://www.npmjs.com/package/@tiptap/extension-twitch)
|
|
6
|
+
[](https://github.com/sponsors/ueberdosis)
|
|
7
|
+
|
|
8
|
+
## Introduction
|
|
9
|
+
|
|
10
|
+
Tiptap is a headless wrapper around [ProseMirror](https://ProseMirror.net) – a toolkit for building rich text WYSIWYG editors, which is already in use at many well-known companies such as _New York Times_, _The Guardian_ or _Atlassian_.
|
|
11
|
+
|
|
12
|
+
## Official Documentation
|
|
13
|
+
|
|
14
|
+
Documentation can be found on the [Tiptap website](https://tiptap.dev).
|
|
15
|
+
|
|
16
|
+
## License
|
|
17
|
+
|
|
18
|
+
Tiptap is open sourced software licensed under the [MIT license](https://github.com/ueberdosis/tiptap/blob/main/LICENSE.md).
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
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
|
+
getEmbedUrlFromTwitchUrl: () => getEmbedUrlFromTwitchUrl,
|
|
28
|
+
getTwitchIdentifier: () => getTwitchIdentifier,
|
|
29
|
+
isValidTwitchUrl: () => isValidTwitchUrl
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(index_exports);
|
|
32
|
+
|
|
33
|
+
// src/twitch.ts
|
|
34
|
+
var import_core = require("@tiptap/core");
|
|
35
|
+
|
|
36
|
+
// src/utils.ts
|
|
37
|
+
var TWITCH_REGEX = /^(https?:\/\/)?(www\.)?(twitch\.tv|clips\.twitch\.tv)\/(?:videos\/(\d+)|(\w+)\/clip\/([\w-]+)|([\w-]+)(?:\/)?)?(\?.*)?$/;
|
|
38
|
+
var TWITCH_REGEX_GLOBAL = /^(https?:\/\/)?(www\.)?(twitch\.tv|clips\.twitch\.tv)\/(?:videos\/(\d+)|(\w+)\/clip\/([\w-]+)|([\w-]+)(?:\/)?)?(\?.*)?$/g;
|
|
39
|
+
var isValidTwitchUrl = (url) => {
|
|
40
|
+
return url.match(TWITCH_REGEX);
|
|
41
|
+
};
|
|
42
|
+
var getTwitchIdentifier = (url) => {
|
|
43
|
+
if (!isValidTwitchUrl(url)) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
const cleanUrl = url.split("?")[0];
|
|
47
|
+
if (cleanUrl.includes("clips.twitch.tv/")) {
|
|
48
|
+
const clipRegex = /clips\.twitch\.tv\/([\w-]+)/;
|
|
49
|
+
const match = cleanUrl.match(clipRegex);
|
|
50
|
+
return match ? { type: "clip", id: match[1] } : null;
|
|
51
|
+
}
|
|
52
|
+
if (cleanUrl.includes("twitch.tv/")) {
|
|
53
|
+
const videoRegex = /twitch\.tv\/videos\/(\d+)/;
|
|
54
|
+
const videoMatch = cleanUrl.match(videoRegex);
|
|
55
|
+
if (videoMatch) {
|
|
56
|
+
return { type: "video", id: videoMatch[1] };
|
|
57
|
+
}
|
|
58
|
+
const channelClipRegex = /twitch\.tv\/([\w-]+)\/clip\/([\w-]+)/;
|
|
59
|
+
const clipMatch = cleanUrl.match(channelClipRegex);
|
|
60
|
+
if (clipMatch) {
|
|
61
|
+
return { type: "clip", id: clipMatch[2] };
|
|
62
|
+
}
|
|
63
|
+
const channelRegex = /twitch\.tv\/([\w-]+)(?:\/)?$/;
|
|
64
|
+
const channelMatch = cleanUrl.match(channelRegex);
|
|
65
|
+
if (channelMatch) {
|
|
66
|
+
return { type: "channel", id: channelMatch[1] };
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return null;
|
|
70
|
+
};
|
|
71
|
+
var getEmbedUrlFromTwitchUrl = (options) => {
|
|
72
|
+
const { url, allowFullscreen = true, autoplay = false, muted = false, time, parent } = options;
|
|
73
|
+
const identifier = getTwitchIdentifier(url);
|
|
74
|
+
if (!identifier) {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
const parentDomain = parent || "localhost";
|
|
78
|
+
if (identifier.type === "clip") {
|
|
79
|
+
const clipUrl = new URL("https://clips.twitch.tv/embed");
|
|
80
|
+
clipUrl.searchParams.set("clip", identifier.id);
|
|
81
|
+
clipUrl.searchParams.set("parent", parentDomain);
|
|
82
|
+
if (autoplay) {
|
|
83
|
+
clipUrl.searchParams.set("autoplay", "true");
|
|
84
|
+
}
|
|
85
|
+
if (muted) {
|
|
86
|
+
clipUrl.searchParams.set("muted", "true");
|
|
87
|
+
}
|
|
88
|
+
return clipUrl.toString();
|
|
89
|
+
}
|
|
90
|
+
if (identifier.type === "video") {
|
|
91
|
+
const videoUrl = new URL("https://player.twitch.tv/");
|
|
92
|
+
videoUrl.searchParams.set("video", identifier.id);
|
|
93
|
+
videoUrl.searchParams.set("parent", parentDomain);
|
|
94
|
+
if (allowFullscreen) {
|
|
95
|
+
videoUrl.searchParams.set("allowfullscreen", "true");
|
|
96
|
+
}
|
|
97
|
+
if (autoplay) {
|
|
98
|
+
videoUrl.searchParams.set("autoplay", "true");
|
|
99
|
+
}
|
|
100
|
+
if (muted) {
|
|
101
|
+
videoUrl.searchParams.set("muted", "true");
|
|
102
|
+
}
|
|
103
|
+
if (time) {
|
|
104
|
+
videoUrl.searchParams.set("time", time);
|
|
105
|
+
}
|
|
106
|
+
return videoUrl.toString();
|
|
107
|
+
}
|
|
108
|
+
if (identifier.type === "channel") {
|
|
109
|
+
const channelUrl = new URL("https://player.twitch.tv/");
|
|
110
|
+
channelUrl.searchParams.set("channel", identifier.id);
|
|
111
|
+
channelUrl.searchParams.set("parent", parentDomain);
|
|
112
|
+
if (allowFullscreen) {
|
|
113
|
+
channelUrl.searchParams.set("allowfullscreen", "true");
|
|
114
|
+
}
|
|
115
|
+
if (autoplay) {
|
|
116
|
+
channelUrl.searchParams.set("autoplay", "true");
|
|
117
|
+
}
|
|
118
|
+
if (muted) {
|
|
119
|
+
channelUrl.searchParams.set("muted", "true");
|
|
120
|
+
}
|
|
121
|
+
return channelUrl.toString();
|
|
122
|
+
}
|
|
123
|
+
return null;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
// src/twitch.ts
|
|
127
|
+
var Twitch = import_core.Node.create({
|
|
128
|
+
name: "twitch",
|
|
129
|
+
addOptions() {
|
|
130
|
+
return {
|
|
131
|
+
addPasteHandler: true,
|
|
132
|
+
allowFullscreen: true,
|
|
133
|
+
autoplay: false,
|
|
134
|
+
muted: false,
|
|
135
|
+
time: void 0,
|
|
136
|
+
parent: "localhost",
|
|
137
|
+
height: 480,
|
|
138
|
+
width: 640,
|
|
139
|
+
HTMLAttributes: {},
|
|
140
|
+
inline: false
|
|
141
|
+
};
|
|
142
|
+
},
|
|
143
|
+
inline() {
|
|
144
|
+
return this.options.inline;
|
|
145
|
+
},
|
|
146
|
+
group() {
|
|
147
|
+
return this.options.inline ? "inline" : "block";
|
|
148
|
+
},
|
|
149
|
+
draggable: true,
|
|
150
|
+
addAttributes() {
|
|
151
|
+
return {
|
|
152
|
+
src: {
|
|
153
|
+
default: null
|
|
154
|
+
},
|
|
155
|
+
width: {
|
|
156
|
+
default: this.options.width
|
|
157
|
+
},
|
|
158
|
+
height: {
|
|
159
|
+
default: this.options.height
|
|
160
|
+
},
|
|
161
|
+
autoplay: {
|
|
162
|
+
default: this.options.autoplay
|
|
163
|
+
},
|
|
164
|
+
muted: {
|
|
165
|
+
default: this.options.muted
|
|
166
|
+
},
|
|
167
|
+
time: {
|
|
168
|
+
default: this.options.time
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
},
|
|
172
|
+
parseHTML() {
|
|
173
|
+
return [
|
|
174
|
+
{
|
|
175
|
+
tag: "div[data-twitch-video] iframe"
|
|
176
|
+
}
|
|
177
|
+
];
|
|
178
|
+
},
|
|
179
|
+
addCommands() {
|
|
180
|
+
return {
|
|
181
|
+
setTwitchVideo: (options) => ({ commands }) => {
|
|
182
|
+
if (!isValidTwitchUrl(options.src)) {
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
return commands.insertContent({
|
|
186
|
+
type: this.name,
|
|
187
|
+
attrs: options
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
},
|
|
192
|
+
addPasteRules() {
|
|
193
|
+
if (!this.options.addPasteHandler) {
|
|
194
|
+
return [];
|
|
195
|
+
}
|
|
196
|
+
return [
|
|
197
|
+
(0, import_core.nodePasteRule)({
|
|
198
|
+
find: TWITCH_REGEX_GLOBAL,
|
|
199
|
+
type: this.type,
|
|
200
|
+
getAttributes: (match) => {
|
|
201
|
+
return { src: match.input };
|
|
202
|
+
}
|
|
203
|
+
})
|
|
204
|
+
];
|
|
205
|
+
},
|
|
206
|
+
renderHTML({ HTMLAttributes }) {
|
|
207
|
+
var _a, _b, _c;
|
|
208
|
+
const embedUrl = getEmbedUrlFromTwitchUrl({
|
|
209
|
+
url: HTMLAttributes.src,
|
|
210
|
+
allowFullscreen: this.options.allowFullscreen,
|
|
211
|
+
autoplay: (_a = HTMLAttributes.autoplay) != null ? _a : this.options.autoplay,
|
|
212
|
+
muted: (_b = HTMLAttributes.muted) != null ? _b : this.options.muted,
|
|
213
|
+
time: (_c = HTMLAttributes.time) != null ? _c : this.options.time,
|
|
214
|
+
parent: this.options.parent
|
|
215
|
+
});
|
|
216
|
+
if (!embedUrl) {
|
|
217
|
+
return ["div", "Invalid Twitch URL"];
|
|
218
|
+
}
|
|
219
|
+
HTMLAttributes.src = embedUrl;
|
|
220
|
+
return [
|
|
221
|
+
"div",
|
|
222
|
+
{ "data-twitch-video": "" },
|
|
223
|
+
[
|
|
224
|
+
"iframe",
|
|
225
|
+
(0, import_core.mergeAttributes)(
|
|
226
|
+
this.options.HTMLAttributes,
|
|
227
|
+
{
|
|
228
|
+
width: this.options.width,
|
|
229
|
+
height: this.options.height,
|
|
230
|
+
allowfullscreen: this.options.allowFullscreen,
|
|
231
|
+
scrolling: "no",
|
|
232
|
+
frameborder: "0"
|
|
233
|
+
},
|
|
234
|
+
HTMLAttributes
|
|
235
|
+
)
|
|
236
|
+
]
|
|
237
|
+
];
|
|
238
|
+
},
|
|
239
|
+
...(0, import_core.createAtomBlockMarkdownSpec)({
|
|
240
|
+
nodeName: "twitch",
|
|
241
|
+
allowedAttributes: ["src", "width", "height", "autoplay", "muted", "time"]
|
|
242
|
+
})
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
// src/index.ts
|
|
246
|
+
var index_default = Twitch;
|
|
247
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
248
|
+
0 && (module.exports = {
|
|
249
|
+
TWITCH_REGEX,
|
|
250
|
+
TWITCH_REGEX_GLOBAL,
|
|
251
|
+
Twitch,
|
|
252
|
+
getEmbedUrlFromTwitchUrl,
|
|
253
|
+
getTwitchIdentifier,
|
|
254
|
+
isValidTwitchUrl
|
|
255
|
+
});
|
|
256
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/twitch.ts","../src/utils.ts"],"sourcesContent":["import { Twitch } from './twitch.js'\n\nexport * from './twitch.js'\nexport * from './utils.js'\n\nexport default Twitch\n","import { createAtomBlockMarkdownSpec, mergeAttributes, Node, nodePasteRule } from '@tiptap/core'\n\nimport { getEmbedUrlFromTwitchUrl, isValidTwitchUrl, TWITCH_REGEX_GLOBAL } from './utils.js'\n\nexport interface TwitchOptions {\n /**\n * Controls if the paste handler for Twitch videos should be added.\n * @default true\n * @example false\n */\n addPasteHandler: boolean\n\n /**\n * Controls if the Twitch video should be allowed to go fullscreen.\n * @default true\n * @example false\n */\n allowFullscreen: boolean\n\n /**\n * Controls if the Twitch video should autoplay.\n * @default false\n * @example true\n */\n autoplay: boolean\n\n /**\n * Controls if the Twitch video should start muted.\n * @default false\n * @example true\n */\n muted: boolean\n\n /**\n * The time in the video where playback starts (format: 1h2m3s).\n * Only works for video embeds, not for clips or channels.\n * @default undefined\n * @example '1h2m3s'\n */\n time?: string\n\n /**\n * The parent domain for the Twitch embed. Required for embed functionality.\n * @default 'localhost'\n * @example 'example.com'\n */\n parent: string\n\n /**\n * The height of the Twitch video.\n * @default 480\n * @example 720\n */\n height: number\n\n /**\n * The width of the Twitch video.\n * @default 640\n * @example 1280\n */\n width: number\n\n /**\n * The HTML attributes for a Twitch video node.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>\n\n /**\n * Controls if the Twitch node should be inline or not.\n * @default false\n * @example true\n */\n inline: boolean\n}\n\n/**\n * The options for setting a Twitch video.\n */\ntype SetTwitchVideoOptions = {\n src: string\n width?: number\n height?: number\n autoplay?: boolean\n muted?: boolean\n time?: string\n}\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n twitch: {\n /**\n * Insert a Twitch video\n * @param options The Twitch video attributes\n * @example editor.commands.setTwitchVideo({ src: 'https://www.twitch.tv/videos/1234567890' })\n */\n setTwitchVideo: (options: SetTwitchVideoOptions) => ReturnType\n }\n }\n}\n\n/**\n * This extension adds support for Twitch videos.\n * @see https://www.tiptap.dev/api/nodes/twitch\n *\n * @example\n * ```ts\n * import { useEditor, EditorContent } from '@tiptap/react'\n * import { StarterKit } from '@tiptap/starter-kit'\n * import { Twitch } from '@tiptap/extension-twitch'\n *\n * const editor = useEditor({\n * extensions: [\n * StarterKit,\n * Twitch.configure({\n * parent: 'example.com',\n * allowFullscreen: true,\n * }),\n * ],\n * content: '<p>Hello World!</p>',\n * })\n * ```\n */\nexport const Twitch = Node.create<TwitchOptions>({\n name: 'twitch',\n\n addOptions() {\n return {\n addPasteHandler: true,\n allowFullscreen: true,\n autoplay: false,\n muted: false,\n time: undefined,\n parent: 'localhost',\n height: 480,\n width: 640,\n HTMLAttributes: {},\n inline: false,\n }\n },\n\n inline() {\n return this.options.inline\n },\n\n group() {\n return this.options.inline ? 'inline' : 'block'\n },\n\n draggable: true,\n\n addAttributes() {\n return {\n src: {\n default: null,\n },\n width: {\n default: this.options.width,\n },\n height: {\n default: this.options.height,\n },\n autoplay: {\n default: this.options.autoplay,\n },\n muted: {\n default: this.options.muted,\n },\n time: {\n default: this.options.time,\n },\n }\n },\n\n parseHTML() {\n return [\n {\n tag: 'div[data-twitch-video] iframe',\n },\n ]\n },\n\n addCommands() {\n return {\n setTwitchVideo:\n (options: SetTwitchVideoOptions) =>\n ({ commands }) => {\n if (!isValidTwitchUrl(options.src)) {\n return false\n }\n\n return commands.insertContent({\n type: this.name,\n attrs: options,\n })\n },\n }\n },\n\n addPasteRules() {\n if (!this.options.addPasteHandler) {\n return []\n }\n\n return [\n nodePasteRule({\n find: TWITCH_REGEX_GLOBAL,\n type: this.type,\n getAttributes: match => {\n return { src: match.input }\n },\n }),\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n const embedUrl = getEmbedUrlFromTwitchUrl({\n url: HTMLAttributes.src,\n allowFullscreen: this.options.allowFullscreen,\n autoplay: HTMLAttributes.autoplay ?? this.options.autoplay,\n muted: HTMLAttributes.muted ?? this.options.muted,\n time: HTMLAttributes.time ?? this.options.time,\n parent: this.options.parent,\n })\n\n if (!embedUrl) {\n return ['div', 'Invalid Twitch URL']\n }\n\n HTMLAttributes.src = embedUrl\n\n return [\n 'div',\n { 'data-twitch-video': '' },\n [\n 'iframe',\n mergeAttributes(\n this.options.HTMLAttributes,\n {\n width: this.options.width,\n height: this.options.height,\n allowfullscreen: this.options.allowFullscreen,\n scrolling: 'no',\n frameborder: '0',\n },\n HTMLAttributes,\n ),\n ],\n ]\n },\n\n ...createAtomBlockMarkdownSpec({\n nodeName: 'twitch',\n allowedAttributes: ['src', 'width', 'height', 'autoplay', 'muted', 'time'],\n }),\n})\n","/**\n * Regex patterns for matching Twitch URLs\n * Matches:\n * - https://twitch.tv/videos/1234567890\n * - https://www.twitch.tv/videos/1234567890\n * - https://twitch.tv/examplechannel/clip/ClipName-123\n * - https://www.twitch.tv/examplechannel/clip/ClipName-123\n * - https://clips.twitch.tv/ClipName\n * - https://www.clips.twitch.tv/ClipName\n * - https://twitch.tv/examplechannel (channel)\n * - https://www.twitch.tv/examplechannel\n */\nexport const TWITCH_REGEX =\n /^(https?:\\/\\/)?(www\\.)?(twitch\\.tv|clips\\.twitch\\.tv)\\/(?:videos\\/(\\d+)|(\\w+)\\/clip\\/([\\w-]+)|([\\w-]+)(?:\\/)?)?(\\?.*)?$/\n\nexport const TWITCH_REGEX_GLOBAL =\n /^(https?:\\/\\/)?(www\\.)?(twitch\\.tv|clips\\.twitch\\.tv)\\/(?:videos\\/(\\d+)|(\\w+)\\/clip\\/([\\w-]+)|([\\w-]+)(?:\\/)?)?(\\?.*)?$/g\n\n/**\n * Validates if a URL is a valid Twitch video, clip or channel URL\n *\n * @param url - The URL to validate\n * @returns true if the URL is a valid Twitch URL\n *\n * @example\n * ```ts\n * isValidTwitchUrl('https://www.twitch.tv/videos/1234567890') // true\n * isValidTwitchUrl('https://www.twitch.tv/examplechannel/clip/ExampleClipName') // true\n * isValidTwitchUrl('https://www.twitch.tv/examplechannel') // true\n * isValidTwitchUrl('https://clips.twitch.tv/ExampleClipName') // true\n * isValidTwitchUrl('invalid') // false\n * ```\n */\nexport const isValidTwitchUrl = (url: string) => {\n return url.match(TWITCH_REGEX)\n}\n\nexport interface GetEmbedUrlOptions {\n url: string\n allowFullscreen?: boolean\n autoplay?: boolean\n muted?: boolean\n time?: string\n parent?: string\n}\n\n/**\n * Extracts the video, clip or channel identifier from a Twitch URL\n *\n * @param url - The Twitch URL\n * @returns Object containing type ('video', 'clip' or 'channel') and ID, or null if invalid\n *\n * @example\n * ```ts\n * getTwitchIdentifier('https://www.twitch.tv/videos/1234567890')\n * // { type: 'video', id: '1234567890' }\n *\n * getTwitchIdentifier('https://www.twitch.tv/examplechannel/clip/ExampleClipName-ABC123')\n * // { type: 'clip', id: 'ExampleClipName-ABC123' }\n *\n * getTwitchIdentifier('https://www.twitch.tv/examplechannel')\n * // { type: 'channel', id: 'examplechannel' }\n * ```\n */\nexport const getTwitchIdentifier = (url: string): { type: 'video' | 'clip' | 'channel'; id: string } | null => {\n if (!isValidTwitchUrl(url)) {\n return null\n }\n\n // Remove query parameters\n const cleanUrl = url.split('?')[0]\n\n // Handle clip URLs from clips.twitch.tv\n if (cleanUrl.includes('clips.twitch.tv/')) {\n const clipRegex = /clips\\.twitch\\.tv\\/([\\w-]+)/\n const match = cleanUrl.match(clipRegex)\n return match ? { type: 'clip', id: match[1] } : null\n }\n\n // Handle twitch.tv URLs\n if (cleanUrl.includes('twitch.tv/')) {\n // Check if it's a video URL (videos/ID)\n const videoRegex = /twitch\\.tv\\/videos\\/(\\d+)/\n const videoMatch = cleanUrl.match(videoRegex)\n if (videoMatch) {\n return { type: 'video', id: videoMatch[1] }\n }\n\n // Check if it's a clip URL (channel/clip/clipname)\n const channelClipRegex = /twitch\\.tv\\/([\\w-]+)\\/clip\\/([\\w-]+)/\n const clipMatch = cleanUrl.match(channelClipRegex)\n if (clipMatch) {\n return { type: 'clip', id: clipMatch[2] }\n }\n\n // Otherwise it's a channel URL\n const channelRegex = /twitch\\.tv\\/([\\w-]+)(?:\\/)?$/\n const channelMatch = cleanUrl.match(channelRegex)\n if (channelMatch) {\n return { type: 'channel', id: channelMatch[1] }\n }\n }\n\n return null\n}\n\n/**\n * Generates an embed URL from a Twitch video, clip or channel URL with optional parameters\n *\n * @param options - The embed URL options\n * @returns The embed URL or null if invalid\n *\n * @example\n * ```ts\n * getEmbedUrlFromTwitchUrl({\n * url: 'https://www.twitch.tv/videos/1234567890',\n * parent: 'example.com',\n * muted: true,\n * time: '1h2m3s'\n * })\n * // Returns: https://player.twitch.tv/?video=1234567890&parent=example.com&muted=true&time=1h2m3s\n *\n * getEmbedUrlFromTwitchUrl({\n * url: 'https://www.twitch.tv/examplechannel/clip/ExampleClipName-ABC123',\n * parent: 'example.com',\n * autoplay: true,\n * muted: true\n * })\n * // Returns: https://clips.twitch.tv/embed?clip=ExampleClipName-ABC123&parent=example.com&autoplay=true&muted=true\n *\n * getEmbedUrlFromTwitchUrl({\n * url: 'https://www.twitch.tv/examplechannel',\n * parent: 'example.com'\n * })\n * // Returns: https://player.twitch.tv/?channel=examplechannel&parent=example.com\n * ```\n */\nexport const getEmbedUrlFromTwitchUrl = (options: GetEmbedUrlOptions): string | null => {\n const { url, allowFullscreen = true, autoplay = false, muted = false, time, parent } = options\n\n const identifier = getTwitchIdentifier(url)\n\n if (!identifier) {\n return null\n }\n\n const parentDomain = parent || 'localhost'\n\n // Handle clip URLs\n if (identifier.type === 'clip') {\n const clipUrl = new URL('https://clips.twitch.tv/embed')\n clipUrl.searchParams.set('clip', identifier.id)\n clipUrl.searchParams.set('parent', parentDomain)\n\n if (autoplay) {\n clipUrl.searchParams.set('autoplay', 'true')\n }\n\n if (muted) {\n clipUrl.searchParams.set('muted', 'true')\n }\n\n return clipUrl.toString()\n }\n\n // Handle video URLs\n if (identifier.type === 'video') {\n const videoUrl = new URL('https://player.twitch.tv/')\n videoUrl.searchParams.set('video', identifier.id)\n videoUrl.searchParams.set('parent', parentDomain)\n\n if (allowFullscreen) {\n videoUrl.searchParams.set('allowfullscreen', 'true')\n }\n\n if (autoplay) {\n videoUrl.searchParams.set('autoplay', 'true')\n }\n\n if (muted) {\n videoUrl.searchParams.set('muted', 'true')\n }\n\n if (time) {\n videoUrl.searchParams.set('time', time)\n }\n\n return videoUrl.toString()\n }\n\n // Handle channel URLs\n if (identifier.type === 'channel') {\n const channelUrl = new URL('https://player.twitch.tv/')\n channelUrl.searchParams.set('channel', identifier.id)\n channelUrl.searchParams.set('parent', parentDomain)\n\n if (allowFullscreen) {\n channelUrl.searchParams.set('allowfullscreen', 'true')\n }\n\n if (autoplay) {\n channelUrl.searchParams.set('autoplay', 'true')\n }\n\n if (muted) {\n channelUrl.searchParams.set('muted', 'true')\n }\n\n return channelUrl.toString()\n }\n\n return null\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAAkF;;;ACY3E,IAAM,eACX;AAEK,IAAM,sBACX;AAiBK,IAAM,mBAAmB,CAAC,QAAgB;AAC/C,SAAO,IAAI,MAAM,YAAY;AAC/B;AA6BO,IAAM,sBAAsB,CAAC,QAA2E;AAC7G,MAAI,CAAC,iBAAiB,GAAG,GAAG;AAC1B,WAAO;AAAA,EACT;AAGA,QAAM,WAAW,IAAI,MAAM,GAAG,EAAE,CAAC;AAGjC,MAAI,SAAS,SAAS,kBAAkB,GAAG;AACzC,UAAM,YAAY;AAClB,UAAM,QAAQ,SAAS,MAAM,SAAS;AACtC,W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,SAAf,YAAuB,KAAK,QAAQ;AAAA,MAC1C,QAAQ,KAAK,QAAQ;AAAA,IACvB,CAAC;AAED,QAAI,CAAC,UAAU;AACb,aAAO,CAAC,OAAO,oBAAoB;AAAA,IACrC;AAEA,mBAAe,MAAM;AAErB,WAAO;AAAA,MACL;AAAA,MACA,EAAE,qBAAqB,GAAG;AAAA,MAC1B;AAAA,QACE;AAAA,YACA;AAAA,UACE,KAAK,QAAQ;AAAA,UACb;AAAA,YACE,OAAO,KAAK,QAAQ;AAAA,YACpB,QAAQ,KAAK,QAAQ;AAAA,YACrB,iBAAiB,KAAK,QAAQ;AAAA,YAC9B,WAAW;AAAA,YACX,aAAa;AAAA,UACf;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EAEA,OAAG,yCAA4B;AAAA,IAC7B,UAAU;AAAA,IACV,mBAAmB,CAAC,OAAO,SAAS,UAAU,YAAY,SAAS,MAAM;AAAA,EAC3E,CAAC;AACH,CAAC;;;AD3PD,IAAO,gBAAQ;","names":[]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { Node } from '@tiptap/core';
|
|
2
|
+
|
|
3
|
+
interface TwitchOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Controls if the paste handler for Twitch videos should be added.
|
|
6
|
+
* @default true
|
|
7
|
+
* @example false
|
|
8
|
+
*/
|
|
9
|
+
addPasteHandler: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Controls if the Twitch video should be allowed to go fullscreen.
|
|
12
|
+
* @default true
|
|
13
|
+
* @example false
|
|
14
|
+
*/
|
|
15
|
+
allowFullscreen: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Controls if the Twitch video should autoplay.
|
|
18
|
+
* @default false
|
|
19
|
+
* @example true
|
|
20
|
+
*/
|
|
21
|
+
autoplay: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Controls if the Twitch video should start muted.
|
|
24
|
+
* @default false
|
|
25
|
+
* @example true
|
|
26
|
+
*/
|
|
27
|
+
muted: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* The time in the video where playback starts (format: 1h2m3s).
|
|
30
|
+
* Only works for video embeds, not for clips or channels.
|
|
31
|
+
* @default undefined
|
|
32
|
+
* @example '1h2m3s'
|
|
33
|
+
*/
|
|
34
|
+
time?: string;
|
|
35
|
+
/**
|
|
36
|
+
* The parent domain for the Twitch embed. Required for embed functionality.
|
|
37
|
+
* @default 'localhost'
|
|
38
|
+
* @example 'example.com'
|
|
39
|
+
*/
|
|
40
|
+
parent: string;
|
|
41
|
+
/**
|
|
42
|
+
* The height of the Twitch video.
|
|
43
|
+
* @default 480
|
|
44
|
+
* @example 720
|
|
45
|
+
*/
|
|
46
|
+
height: number;
|
|
47
|
+
/**
|
|
48
|
+
* The width of the Twitch video.
|
|
49
|
+
* @default 640
|
|
50
|
+
* @example 1280
|
|
51
|
+
*/
|
|
52
|
+
width: number;
|
|
53
|
+
/**
|
|
54
|
+
* The HTML attributes for a Twitch video node.
|
|
55
|
+
* @default {}
|
|
56
|
+
* @example { class: 'foo' }
|
|
57
|
+
*/
|
|
58
|
+
HTMLAttributes: Record<string, any>;
|
|
59
|
+
/**
|
|
60
|
+
* Controls if the Twitch node should be inline or not.
|
|
61
|
+
* @default false
|
|
62
|
+
* @example true
|
|
63
|
+
*/
|
|
64
|
+
inline: boolean;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The options for setting a Twitch video.
|
|
68
|
+
*/
|
|
69
|
+
type SetTwitchVideoOptions = {
|
|
70
|
+
src: string;
|
|
71
|
+
width?: number;
|
|
72
|
+
height?: number;
|
|
73
|
+
autoplay?: boolean;
|
|
74
|
+
muted?: boolean;
|
|
75
|
+
time?: string;
|
|
76
|
+
};
|
|
77
|
+
declare module '@tiptap/core' {
|
|
78
|
+
interface Commands<ReturnType> {
|
|
79
|
+
twitch: {
|
|
80
|
+
/**
|
|
81
|
+
* Insert a Twitch video
|
|
82
|
+
* @param options The Twitch video attributes
|
|
83
|
+
* @example editor.commands.setTwitchVideo({ src: 'https://www.twitch.tv/videos/1234567890' })
|
|
84
|
+
*/
|
|
85
|
+
setTwitchVideo: (options: SetTwitchVideoOptions) => ReturnType;
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* This extension adds support for Twitch videos.
|
|
91
|
+
* @see https://www.tiptap.dev/api/nodes/twitch
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* import { useEditor, EditorContent } from '@tiptap/react'
|
|
96
|
+
* import { StarterKit } from '@tiptap/starter-kit'
|
|
97
|
+
* import { Twitch } from '@tiptap/extension-twitch'
|
|
98
|
+
*
|
|
99
|
+
* const editor = useEditor({
|
|
100
|
+
* extensions: [
|
|
101
|
+
* StarterKit,
|
|
102
|
+
* Twitch.configure({
|
|
103
|
+
* parent: 'example.com',
|
|
104
|
+
* allowFullscreen: true,
|
|
105
|
+
* }),
|
|
106
|
+
* ],
|
|
107
|
+
* content: '<p>Hello World!</p>',
|
|
108
|
+
* })
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
declare const Twitch: Node<TwitchOptions, any>;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Regex patterns for matching Twitch URLs
|
|
115
|
+
* Matches:
|
|
116
|
+
* - https://twitch.tv/videos/1234567890
|
|
117
|
+
* - https://www.twitch.tv/videos/1234567890
|
|
118
|
+
* - https://twitch.tv/examplechannel/clip/ClipName-123
|
|
119
|
+
* - https://www.twitch.tv/examplechannel/clip/ClipName-123
|
|
120
|
+
* - https://clips.twitch.tv/ClipName
|
|
121
|
+
* - https://www.clips.twitch.tv/ClipName
|
|
122
|
+
* - https://twitch.tv/examplechannel (channel)
|
|
123
|
+
* - https://www.twitch.tv/examplechannel
|
|
124
|
+
*/
|
|
125
|
+
declare const TWITCH_REGEX: RegExp;
|
|
126
|
+
declare const TWITCH_REGEX_GLOBAL: RegExp;
|
|
127
|
+
/**
|
|
128
|
+
* Validates if a URL is a valid Twitch video, clip or channel URL
|
|
129
|
+
*
|
|
130
|
+
* @param url - The URL to validate
|
|
131
|
+
* @returns true if the URL is a valid Twitch URL
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```ts
|
|
135
|
+
* isValidTwitchUrl('https://www.twitch.tv/videos/1234567890') // true
|
|
136
|
+
* isValidTwitchUrl('https://www.twitch.tv/examplechannel/clip/ExampleClipName') // true
|
|
137
|
+
* isValidTwitchUrl('https://www.twitch.tv/examplechannel') // true
|
|
138
|
+
* isValidTwitchUrl('https://clips.twitch.tv/ExampleClipName') // true
|
|
139
|
+
* isValidTwitchUrl('invalid') // false
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
declare const isValidTwitchUrl: (url: string) => RegExpMatchArray | null;
|
|
143
|
+
interface GetEmbedUrlOptions {
|
|
144
|
+
url: string;
|
|
145
|
+
allowFullscreen?: boolean;
|
|
146
|
+
autoplay?: boolean;
|
|
147
|
+
muted?: boolean;
|
|
148
|
+
time?: string;
|
|
149
|
+
parent?: string;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Extracts the video, clip or channel identifier from a Twitch URL
|
|
153
|
+
*
|
|
154
|
+
* @param url - The Twitch URL
|
|
155
|
+
* @returns Object containing type ('video', 'clip' or 'channel') and ID, or null if invalid
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```ts
|
|
159
|
+
* getTwitchIdentifier('https://www.twitch.tv/videos/1234567890')
|
|
160
|
+
* // { type: 'video', id: '1234567890' }
|
|
161
|
+
*
|
|
162
|
+
* getTwitchIdentifier('https://www.twitch.tv/examplechannel/clip/ExampleClipName-ABC123')
|
|
163
|
+
* // { type: 'clip', id: 'ExampleClipName-ABC123' }
|
|
164
|
+
*
|
|
165
|
+
* getTwitchIdentifier('https://www.twitch.tv/examplechannel')
|
|
166
|
+
* // { type: 'channel', id: 'examplechannel' }
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
declare const getTwitchIdentifier: (url: string) => {
|
|
170
|
+
type: "video" | "clip" | "channel";
|
|
171
|
+
id: string;
|
|
172
|
+
} | null;
|
|
173
|
+
/**
|
|
174
|
+
* Generates an embed URL from a Twitch video, clip or channel URL with optional parameters
|
|
175
|
+
*
|
|
176
|
+
* @param options - The embed URL options
|
|
177
|
+
* @returns The embed URL or null if invalid
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```ts
|
|
181
|
+
* getEmbedUrlFromTwitchUrl({
|
|
182
|
+
* url: 'https://www.twitch.tv/videos/1234567890',
|
|
183
|
+
* parent: 'example.com',
|
|
184
|
+
* muted: true,
|
|
185
|
+
* time: '1h2m3s'
|
|
186
|
+
* })
|
|
187
|
+
* // Returns: https://player.twitch.tv/?video=1234567890&parent=example.com&muted=true&time=1h2m3s
|
|
188
|
+
*
|
|
189
|
+
* getEmbedUrlFromTwitchUrl({
|
|
190
|
+
* url: 'https://www.twitch.tv/examplechannel/clip/ExampleClipName-ABC123',
|
|
191
|
+
* parent: 'example.com',
|
|
192
|
+
* autoplay: true,
|
|
193
|
+
* muted: true
|
|
194
|
+
* })
|
|
195
|
+
* // Returns: https://clips.twitch.tv/embed?clip=ExampleClipName-ABC123&parent=example.com&autoplay=true&muted=true
|
|
196
|
+
*
|
|
197
|
+
* getEmbedUrlFromTwitchUrl({
|
|
198
|
+
* url: 'https://www.twitch.tv/examplechannel',
|
|
199
|
+
* parent: 'example.com'
|
|
200
|
+
* })
|
|
201
|
+
* // Returns: https://player.twitch.tv/?channel=examplechannel&parent=example.com
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
204
|
+
declare const getEmbedUrlFromTwitchUrl: (options: GetEmbedUrlOptions) => string | null;
|
|
205
|
+
|
|
206
|
+
export { type GetEmbedUrlOptions, TWITCH_REGEX, TWITCH_REGEX_GLOBAL, Twitch, type TwitchOptions, Twitch as default, getEmbedUrlFromTwitchUrl, getTwitchIdentifier, isValidTwitchUrl };
|