@tiptap/extension-youtube 2.11.7 → 3.0.0-beta.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/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/utils.ts","../src/youtube.ts"],"sourcesContent":["export const YOUTUBE_REGEX = /^((?:https?:)?\\/\\/)?((?:www|m|music)\\.)?((?:youtube\\.com|youtu.be|youtube-nocookie\\.com))(\\/(?:[\\w-]+\\?v=|embed\\/|v\\/)?)([\\w-]+)(\\S+)?$/\nexport const YOUTUBE_REGEX_GLOBAL = /^((?:https?:)?\\/\\/)?((?:www|m|music)\\.)?((?:youtube\\.com|youtu.be|youtube-nocookie\\.com))(\\/(?:[\\w-]+\\?v=|embed\\/|v\\/)?)([\\w-]+)(\\S+)?$/g\n\nexport const isValidYoutubeUrl = (url: string) => {\n return url.match(YOUTUBE_REGEX)\n}\n\nexport interface GetEmbedUrlOptions {\n url: string;\n allowFullscreen?: boolean;\n autoplay?: boolean;\n ccLanguage?:string;\n ccLoadPolicy?:boolean;\n controls?: boolean;\n disableKBcontrols?: boolean,\n enableIFrameApi?: boolean;\n endTime?: number;\n interfaceLanguage?: string;\n ivLoadPolicy?: number;\n loop?: boolean;\n modestBranding?: boolean;\n nocookie?: boolean;\n origin?: string;\n playlist?: string;\n progressBarColor?: string;\n startAt?: number;\n rel?: number;\n}\n\nexport const getYoutubeEmbedUrl = (nocookie?: boolean, isPlaylist?:boolean) => {\n if (isPlaylist) {\n return 'https://www.youtube-nocookie.com/embed/videoseries?list='\n }\n return nocookie ? 'https://www.youtube-nocookie.com/embed/' : 'https://www.youtube.com/embed/'\n}\n\nexport const getEmbedUrlFromYoutubeUrl = (options: GetEmbedUrlOptions) => {\n const {\n url,\n allowFullscreen,\n autoplay,\n ccLanguage,\n ccLoadPolicy,\n controls,\n disableKBcontrols,\n enableIFrameApi,\n endTime,\n interfaceLanguage,\n ivLoadPolicy,\n loop,\n modestBranding,\n nocookie,\n origin,\n playlist,\n progressBarColor,\n startAt,\n rel,\n } = options\n\n if (!isValidYoutubeUrl(url)) {\n return null\n }\n\n // if is already an embed url, return it\n if (url.includes('/embed/')) {\n return url\n }\n\n // if is a youtu.be url, get the id after the /\n if (url.includes('youtu.be')) {\n const id = url.split('/').pop()\n\n if (!id) {\n return null\n }\n return `${getYoutubeEmbedUrl(nocookie)}${id}`\n }\n\n const videoIdRegex = /(?:(v|list)=|shorts\\/)([-\\w]+)/gm\n const matches = videoIdRegex.exec(url)\n\n if (!matches || !matches[2]) {\n return null\n }\n\n let outputUrl = `${getYoutubeEmbedUrl(nocookie, matches[1] === 'list')}${matches[2]}`\n\n const params = []\n\n if (allowFullscreen === false) {\n params.push('fs=0')\n }\n\n if (autoplay) {\n params.push('autoplay=1')\n }\n\n if (ccLanguage) {\n params.push(`cc_lang_pref=${ccLanguage}`)\n }\n\n if (ccLoadPolicy) {\n params.push('cc_load_policy=1')\n }\n\n if (!controls) {\n params.push('controls=0')\n }\n\n if (disableKBcontrols) {\n params.push('disablekb=1')\n }\n\n if (enableIFrameApi) {\n params.push('enablejsapi=1')\n }\n\n if (endTime) {\n params.push(`end=${endTime}`)\n }\n\n if (interfaceLanguage) {\n params.push(`hl=${interfaceLanguage}`)\n }\n\n if (ivLoadPolicy) {\n params.push(`iv_load_policy=${ivLoadPolicy}`)\n }\n\n if (loop) {\n params.push('loop=1')\n }\n\n if (modestBranding) {\n params.push('modestbranding=1')\n }\n\n if (origin) {\n params.push(`origin=${origin}`)\n }\n\n if (playlist) {\n params.push(`playlist=${playlist}`)\n }\n\n if (startAt) {\n params.push(`start=${startAt}`)\n }\n\n if (progressBarColor) {\n params.push(`color=${progressBarColor}`)\n }\n\n if (rel !== undefined) {\n params.push(`rel=${rel}`)\n }\n\n if (params.length) {\n outputUrl += `${matches[1] === 'v' ? '?' : '&'}${params.join('&')}`\n }\n\n return outputUrl\n}\n","import { mergeAttributes, Node, nodePasteRule } from '@tiptap/core'\n\nimport { getEmbedUrlFromYoutubeUrl, isValidYoutubeUrl, YOUTUBE_REGEX_GLOBAL } from './utils.js'\n\nexport interface YoutubeOptions {\n /**\n * Controls if the paste handler for youtube videos should be added.\n * @default true\n * @example false\n */\n addPasteHandler: boolean;\n\n /**\n * Controls if the youtube video should be allowed to go fullscreen.\n * @default true\n * @example false\n */\n allowFullscreen: boolean;\n\n /**\n * Controls if the youtube video should autoplay.\n * @default false\n * @example true\n */\n autoplay: boolean;\n\n /**\n * The language of the captions shown in the youtube video.\n * @default undefined\n * @example 'en'\n */\n ccLanguage?: string;\n\n /**\n * Controls if the captions should be shown in the youtube video.\n * @default undefined\n * @example true\n */\n ccLoadPolicy?: boolean;\n\n /**\n * Controls if the controls should be shown in the youtube video.\n * @default true\n * @example false\n */\n controls: boolean;\n\n /**\n * Controls if the keyboard controls should be disabled in the youtube video.\n * @default false\n * @example true\n */\n disableKBcontrols: boolean;\n\n /**\n * Controls if the iframe api should be enabled in the youtube video.\n * @default false\n * @example true\n */\n enableIFrameApi: boolean;\n\n /**\n * The end time of the youtube video.\n * @default 0\n * @example 120\n */\n endTime: number;\n\n /**\n * The height of the youtube video.\n * @default 480\n * @example 720\n */\n height: number;\n\n /**\n * The language of the youtube video.\n * @default undefined\n * @example 'en'\n */\n interfaceLanguage?: string;\n\n /**\n * Controls if the video annotations should be shown in the youtube video.\n * @default 0\n * @example 1\n */\n ivLoadPolicy: number;\n\n /**\n * Controls if the youtube video should loop.\n * @default false\n * @example true\n */\n loop: boolean;\n\n /**\n * Controls if the youtube video should show a small youtube logo.\n * @default false\n * @example true\n */\n modestBranding: boolean;\n\n /**\n * The HTML attributes for a youtube video node.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>;\n\n /**\n * Controls if the youtube node should be inline or not.\n * @default false\n * @example true\n */\n inline: boolean;\n\n /**\n * Controls if the youtube video should be loaded from youtube-nocookie.com.\n * @default false\n * @example true\n */\n nocookie: boolean;\n\n /**\n * The origin of the youtube video.\n * @default ''\n * @example 'https://tiptap.dev'\n */\n origin: string;\n\n /**\n * The playlist of the youtube video.\n * @default ''\n * @example 'PLQg6GaokU5CwiVmsZ0dZm6VeIg0V5z1tK'\n */\n playlist: string;\n\n /**\n * The color of the youtube video progress bar.\n * @default undefined\n * @example 'red'\n */\n progressBarColor?: string;\n\n /**\n * The width of the youtube video.\n * @default 640\n * @example 1280\n */\n width: number;\n\n /**\n * Controls if the related youtube videos at the end are from the same channel.\n * @default 1\n * @example 0\n */\n rel: number;\n}\n\n/**\n * The options for setting a youtube video.\n */\ntype SetYoutubeVideoOptions = { src: string, width?: number, height?: number, start?: number }\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n youtube: {\n /**\n * Insert a youtube video\n * @param options The youtube video attributes\n * @example editor.commands.setYoutubeVideo({ src: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ' })\n */\n setYoutubeVideo: (options: SetYoutubeVideoOptions) => ReturnType,\n }\n }\n}\n\n/**\n * This extension adds support for youtube videos.\n * @see https://www.tiptap.dev/api/nodes/youtube\n */\nexport const Youtube = Node.create<YoutubeOptions>({\n name: 'youtube',\n\n addOptions() {\n return {\n addPasteHandler: true,\n allowFullscreen: true,\n autoplay: false,\n ccLanguage: undefined,\n ccLoadPolicy: undefined,\n controls: true,\n disableKBcontrols: false,\n enableIFrameApi: false,\n endTime: 0,\n height: 480,\n interfaceLanguage: undefined,\n ivLoadPolicy: 0,\n loop: false,\n modestBranding: false,\n HTMLAttributes: {},\n inline: false,\n nocookie: false,\n origin: '',\n playlist: '',\n progressBarColor: undefined,\n width: 640,\n rel: 1,\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 start: {\n default: 0,\n },\n width: {\n default: this.options.width,\n },\n height: {\n default: this.options.height,\n },\n }\n },\n\n parseHTML() {\n return [\n {\n tag: 'div[data-youtube-video] iframe',\n },\n ]\n },\n\n addCommands() {\n return {\n setYoutubeVideo: (options: SetYoutubeVideoOptions) => ({ commands }) => {\n if (!isValidYoutubeUrl(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: YOUTUBE_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 = getEmbedUrlFromYoutubeUrl({\n url: HTMLAttributes.src,\n allowFullscreen: this.options.allowFullscreen,\n autoplay: this.options.autoplay,\n ccLanguage: this.options.ccLanguage,\n ccLoadPolicy: this.options.ccLoadPolicy,\n controls: this.options.controls,\n disableKBcontrols: this.options.disableKBcontrols,\n enableIFrameApi: this.options.enableIFrameApi,\n endTime: this.options.endTime,\n interfaceLanguage: this.options.interfaceLanguage,\n ivLoadPolicy: this.options.ivLoadPolicy,\n loop: this.options.loop,\n modestBranding: this.options.modestBranding,\n nocookie: this.options.nocookie,\n origin: this.options.origin,\n playlist: this.options.playlist,\n progressBarColor: this.options.progressBarColor,\n startAt: HTMLAttributes.start || 0,\n rel: this.options.rel,\n })\n\n HTMLAttributes.src = embedUrl\n\n return [\n 'div',\n { 'data-youtube-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 autoplay: this.options.autoplay,\n ccLanguage: this.options.ccLanguage,\n ccLoadPolicy: this.options.ccLoadPolicy,\n disableKBcontrols: this.options.disableKBcontrols,\n enableIFrameApi: this.options.enableIFrameApi,\n endTime: this.options.endTime,\n interfaceLanguage: this.options.interfaceLanguage,\n ivLoadPolicy: this.options.ivLoadPolicy,\n loop: this.options.loop,\n modestBranding: this.options.modestBranding,\n origin: this.options.origin,\n playlist: this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,OAAO,CAAC,IAAI;AACvB,oBAAA,cAAc,EAAE,IAAI,CAAC,OAAO,CAAC,cAAc;AAC3C,oBAAA,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM;AAC3B,oBAAA,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ;AAC/B,oBAAA,gBAAgB,EAAE,IAAI,CAAC,OAAO,CAAC,gBAAgB;AAC/C,oBAAA,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG;AACtB,iBAAA,EACD,cAAc,CACf;AACF,aAAA;SACF;KACF;AACF,CAAA;;;;"}
1
+ {"version":3,"sources":["../src/youtube.ts","../src/utils.ts","../src/index.ts"],"sourcesContent":["import { mergeAttributes, Node, nodePasteRule } from '@tiptap/core'\n\nimport { getEmbedUrlFromYoutubeUrl, isValidYoutubeUrl, YOUTUBE_REGEX_GLOBAL } from './utils.js'\n\nexport interface YoutubeOptions {\n /**\n * Controls if the paste handler for youtube videos should be added.\n * @default true\n * @example false\n */\n addPasteHandler: boolean\n\n /**\n * Controls if the youtube video should be allowed to go fullscreen.\n * @default true\n * @example false\n */\n allowFullscreen: boolean\n\n /**\n * Controls if the youtube video should autoplay.\n * @default false\n * @example true\n */\n autoplay: boolean\n\n /**\n * The language of the captions shown in the youtube video.\n * @default undefined\n * @example 'en'\n */\n ccLanguage?: string\n\n /**\n * Controls if the captions should be shown in the youtube video.\n * @default undefined\n * @example true\n */\n ccLoadPolicy?: boolean\n\n /**\n * Controls if the controls should be shown in the youtube video.\n * @default true\n * @example false\n */\n controls: boolean\n\n /**\n * Controls if the keyboard controls should be disabled in the youtube video.\n * @default false\n * @example true\n */\n disableKBcontrols: boolean\n\n /**\n * Controls if the iframe api should be enabled in the youtube video.\n * @default false\n * @example true\n */\n enableIFrameApi: boolean\n\n /**\n * The end time of the youtube video.\n * @default 0\n * @example 120\n */\n endTime: number\n\n /**\n * The height of the youtube video.\n * @default 480\n * @example 720\n */\n height: number\n\n /**\n * The language of the youtube video.\n * @default undefined\n * @example 'en'\n */\n interfaceLanguage?: string\n\n /**\n * Controls if the video annotations should be shown in the youtube video.\n * @default 0\n * @example 1\n */\n ivLoadPolicy: number\n\n /**\n * Controls if the youtube video should loop.\n * @default false\n * @example true\n */\n loop: boolean\n\n /**\n * Controls if the youtube video should show a small youtube logo.\n * @default false\n * @example true\n */\n modestBranding: boolean\n\n /**\n * The HTML attributes for a youtube video node.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record<string, any>\n\n /**\n * Controls if the youtube node should be inline or not.\n * @default false\n * @example true\n */\n inline: boolean\n\n /**\n * Controls if the youtube video should be loaded from youtube-nocookie.com.\n * @default false\n * @example true\n */\n nocookie: boolean\n\n /**\n * The origin of the youtube video.\n * @default ''\n * @example 'https://tiptap.dev'\n */\n origin: string\n\n /**\n * The playlist of the youtube video.\n * @default ''\n * @example 'PLQg6GaokU5CwiVmsZ0dZm6VeIg0V5z1tK'\n */\n playlist: string\n\n /**\n * The color of the youtube video progress bar.\n * @default undefined\n * @example 'red'\n */\n progressBarColor?: string\n\n /**\n * The width of the youtube video.\n * @default 640\n * @example 1280\n */\n width: number\n\n /**\n * Controls if the related youtube videos at the end are from the same channel.\n * @default 1\n * @example 0\n */\n rel: number\n}\n\n/**\n * The options for setting a youtube video.\n */\ntype SetYoutubeVideoOptions = { src: string; width?: number; height?: number; start?: number }\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n youtube: {\n /**\n * Insert a youtube video\n * @param options The youtube video attributes\n * @example editor.commands.setYoutubeVideo({ src: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ' })\n */\n setYoutubeVideo: (options: SetYoutubeVideoOptions) => ReturnType\n }\n }\n}\n\n/**\n * This extension adds support for youtube videos.\n * @see https://www.tiptap.dev/api/nodes/youtube\n */\nexport const Youtube = Node.create<YoutubeOptions>({\n name: 'youtube',\n\n addOptions() {\n return {\n addPasteHandler: true,\n allowFullscreen: true,\n autoplay: false,\n ccLanguage: undefined,\n ccLoadPolicy: undefined,\n controls: true,\n disableKBcontrols: false,\n enableIFrameApi: false,\n endTime: 0,\n height: 480,\n interfaceLanguage: undefined,\n ivLoadPolicy: 0,\n loop: false,\n modestBranding: false,\n HTMLAttributes: {},\n inline: false,\n nocookie: false,\n origin: '',\n playlist: '',\n progressBarColor: undefined,\n width: 640,\n rel: 1,\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 start: {\n default: 0,\n },\n width: {\n default: this.options.width,\n },\n height: {\n default: this.options.height,\n },\n }\n },\n\n parseHTML() {\n return [\n {\n tag: 'div[data-youtube-video] iframe',\n },\n ]\n },\n\n addCommands() {\n return {\n setYoutubeVideo:\n (options: SetYoutubeVideoOptions) =>\n ({ commands }) => {\n if (!isValidYoutubeUrl(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: YOUTUBE_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 = getEmbedUrlFromYoutubeUrl({\n url: HTMLAttributes.src,\n allowFullscreen: this.options.allowFullscreen,\n autoplay: this.options.autoplay,\n ccLanguage: this.options.ccLanguage,\n ccLoadPolicy: this.options.ccLoadPolicy,\n controls: this.options.controls,\n disableKBcontrols: this.options.disableKBcontrols,\n enableIFrameApi: this.options.enableIFrameApi,\n endTime: this.options.endTime,\n interfaceLanguage: this.options.interfaceLanguage,\n ivLoadPolicy: this.options.ivLoadPolicy,\n loop: this.options.loop,\n modestBranding: this.options.modestBranding,\n nocookie: this.options.nocookie,\n origin: this.options.origin,\n playlist: this.options.playlist,\n progressBarColor: this.options.progressBarColor,\n startAt: HTMLAttributes.start || 0,\n rel: this.options.rel,\n })\n\n HTMLAttributes.src = embedUrl\n\n return [\n 'div',\n { 'data-youtube-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 autoplay: this.options.autoplay,\n ccLanguage: this.options.ccLanguage,\n ccLoadPolicy: this.options.ccLoadPolicy,\n disableKBcontrols: this.options.disableKBcontrols,\n enableIFrameApi: this.options.enableIFrameApi,\n endTime: this.options.endTime,\n interfaceLanguage: this.options.interfaceLanguage,\n ivLoadPolicy: this.options.ivLoadPolicy,\n loop: this.options.loop,\n modestBranding: this.options.modestBranding,\n origin: this.options.origin,\n playlist: this.options.playlist,\n progressBarColor: this.options.progressBarColor,\n rel: this.options.rel,\n },\n HTMLAttributes,\n ),\n ],\n ]\n },\n})\n","export const YOUTUBE_REGEX =\n /^((?:https?:)?\\/\\/)?((?:www|m|music)\\.)?((?:youtube\\.com|youtu.be|youtube-nocookie\\.com))(\\/(?:[\\w-]+\\?v=|embed\\/|v\\/)?)([\\w-]+)(\\S+)?$/\nexport const YOUTUBE_REGEX_GLOBAL =\n /^((?:https?:)?\\/\\/)?((?:www|m|music)\\.)?((?:youtube\\.com|youtu.be|youtube-nocookie\\.com))(\\/(?:[\\w-]+\\?v=|embed\\/|v\\/)?)([\\w-]+)(\\S+)?$/g\n\nexport const isValidYoutubeUrl = (url: string) => {\n return url.match(YOUTUBE_REGEX)\n}\n\nexport interface GetEmbedUrlOptions {\n url: string\n allowFullscreen?: boolean\n autoplay?: boolean\n ccLanguage?: string\n ccLoadPolicy?: boolean\n controls?: boolean\n disableKBcontrols?: boolean\n enableIFrameApi?: boolean\n endTime?: number\n interfaceLanguage?: string\n ivLoadPolicy?: number\n loop?: boolean\n modestBranding?: boolean\n nocookie?: boolean\n origin?: string\n playlist?: string\n progressBarColor?: string\n startAt?: number\n rel?: number\n}\n\nexport const getYoutubeEmbedUrl = (nocookie?: boolean, isPlaylist?: boolean) => {\n if (isPlaylist) {\n return 'https://www.youtube-nocookie.com/embed/videoseries?list='\n }\n return nocookie ? 'https://www.youtube-nocookie.com/embed/' : 'https://www.youtube.com/embed/'\n}\n\nexport const getEmbedUrlFromYoutubeUrl = (options: GetEmbedUrlOptions) => {\n const {\n url,\n allowFullscreen,\n autoplay,\n ccLanguage,\n ccLoadPolicy,\n controls,\n disableKBcontrols,\n enableIFrameApi,\n endTime,\n interfaceLanguage,\n ivLoadPolicy,\n loop,\n modestBranding,\n nocookie,\n origin,\n playlist,\n progressBarColor,\n startAt,\n rel,\n } = options\n\n if (!isValidYoutubeUrl(url)) {\n return null\n }\n\n // if is already an embed url, return it\n if (url.includes('/embed/')) {\n return url\n }\n\n // if is a youtu.be url, get the id after the /\n if (url.includes('youtu.be')) {\n const id = url.split('/').pop()\n\n if (!id) {\n return null\n }\n return `${getYoutubeEmbedUrl(nocookie)}${id}`\n }\n\n const videoIdRegex = /(?:(v|list)=|shorts\\/)([-\\w]+)/gm\n const matches = videoIdRegex.exec(url)\n\n if (!matches || !matches[2]) {\n return null\n }\n\n let outputUrl = `${getYoutubeEmbedUrl(nocookie, matches[1] === 'list')}${matches[2]}`\n\n const params = []\n\n if (allowFullscreen === false) {\n params.push('fs=0')\n }\n\n if (autoplay) {\n params.push('autoplay=1')\n }\n\n if (ccLanguage) {\n params.push(`cc_lang_pref=${ccLanguage}`)\n }\n\n if (ccLoadPolicy) {\n params.push('cc_load_policy=1')\n }\n\n if (!controls) {\n params.push('controls=0')\n }\n\n if (disableKBcontrols) {\n params.push('disablekb=1')\n }\n\n if (enableIFrameApi) {\n params.push('enablejsapi=1')\n }\n\n if (endTime) {\n params.push(`end=${endTime}`)\n }\n\n if (interfaceLanguage) {\n params.push(`hl=${interfaceLanguage}`)\n }\n\n if (ivLoadPolicy) {\n params.push(`iv_load_policy=${ivLoadPolicy}`)\n }\n\n if (loop) {\n params.push('loop=1')\n }\n\n if (modestBranding) {\n params.push('modestbranding=1')\n }\n\n if (origin) {\n params.push(`origin=${origin}`)\n }\n\n if (playlist) {\n params.push(`playlist=${playlist}`)\n }\n\n if (startAt) {\n params.push(`start=${startAt}`)\n }\n\n if (progressBarColor) {\n params.push(`color=${progressBarColor}`)\n }\n\n if (rel !== undefined) {\n params.push(`rel=${rel}`)\n }\n\n if (params.length) {\n outputUrl += `${matches[1] === 'v' ? '?' : '&'}${params.join('&')}`\n }\n\n return outputUrl\n}\n","import { Youtube } from './youtube.js'\n\nexport * from './youtube.js'\n\nexport default Youtube\n"],"mappings":";AAAA,SAAS,iBAAiB,MAAM,qBAAqB;;;ACA9C,IAAM,gBACX;AACK,IAAM,uBACX;AAEK,IAAM,oBAAoB,CAAC,QAAgB;AAChD,SAAO,IAAI,MAAM,aAAa;AAChC;AAwBO,IAAM,qBAAqB,CAAC,UAAoB,eAAyB;AAC9E,MAAI,YAAY;AACd,WAAO;AAAA,EACT;AACA,SAAO,WAAW,4CAA4C;AAChE;AAEO,IAAM,4BAA4B,CAAC,YAAgC;AACxE,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI;AAEJ,MAAI,CAAC,kBAAkB,GAAG,GAAG;AAC3B,WAAO;AAAA,EACT;AAGA,MAAI,IAAI,SAAS,SAAS,GAAG;AAC3B,WAAO;AAAA,EACT;AAGA,MAAI,IAAI,SAAS,UAAU,GAAG;AAC5B,UAAM,KAAK,IAAI,MAAM,GAAG,EAAE,IAAI;AAE9B,QAAI,CAAC,IAAI;AACP,aAAO;AAAA,IACT;AACA,WAAO,GAAG,mBAAmB,QAAQ,CAAC,GAAG,EAAE;AAAA,EAC7C;AAEA,QAAM,eAAe;AACrB,QAAM,UAAU,aAAa,KAAK,GAA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AAAA,MACA,EAAE,sBAAsB,GAAG;AAAA,MAC3B;AAAA,QACE;AAAA,QACA;AAAA,UACE,KAAK,QAAQ;AAAA,UACb;AAAA,YACE,OAAO,KAAK,QAAQ;AAAA,YACpB,QAAQ,KAAK,QAAQ;AAAA,YACrB,iBAAiB,KAAK,QAAQ;AAAA,YAC9B,UAAU,KAAK,QAAQ;AAAA,YACvB,YAAY,KAAK,QAAQ;AAAA,YACzB,cAAc,KAAK,QAAQ;AAAA,YAC3B,mBAAmB,KAAK,QAAQ;AAAA,YAChC,iBAAiB,KAAK,QAAQ;AAAA,YAC9B,SAAS,KAAK,QAAQ;AAAA,YACtB,mBAAmB,KAAK,QAAQ;AAAA,YAChC,cAAc,KAAK,QAAQ;AAAA,YAC3B,MAAM,KAAK,QAAQ;AAAA,YACnB,gBAAgB,KAAK,QAAQ;AAAA,YAC7B,QAAQ,KAAK,QAAQ;AAAA,YACrB,UAAU,KAAK,QAAQ;AAAA,YACvB,kBAAkB,KAAK,QAAQ;AAAA,YAC/B,KAAK,KAAK,QAAQ;AAAA,UACpB;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF,CAAC;;;AE5UD,IAAO,gBAAQ;","names":[]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tiptap/extension-youtube",
3
3
  "description": "a youtube embed extension for tiptap",
4
- "version": "2.11.7",
4
+ "version": "3.0.0-beta.0",
5
5
  "homepage": "https://tiptap.dev",
6
6
  "keywords": [
7
7
  "tiptap",
@@ -15,24 +15,26 @@
15
15
  "type": "module",
16
16
  "exports": {
17
17
  ".": {
18
- "types": "./dist/index.d.ts",
18
+ "types": {
19
+ "import": "./dist/index.d.ts",
20
+ "require": "./dist/index.d.cts"
21
+ },
19
22
  "import": "./dist/index.js",
20
23
  "require": "./dist/index.cjs"
21
24
  }
22
25
  },
23
26
  "main": "dist/index.cjs",
24
27
  "module": "dist/index.js",
25
- "umd": "dist/index.umd.js",
26
28
  "types": "dist/index.d.ts",
27
29
  "files": [
28
30
  "src",
29
31
  "dist"
30
32
  ],
31
33
  "devDependencies": {
32
- "@tiptap/core": "^2.11.7"
34
+ "@tiptap/core": "^3.0.0-beta.0"
33
35
  },
34
36
  "peerDependencies": {
35
- "@tiptap/core": "^2.7.0"
37
+ "@tiptap/core": "^3.0.0-beta.0"
36
38
  },
37
39
  "repository": {
38
40
  "type": "git",
@@ -40,7 +42,7 @@
40
42
  "directory": "packages/extension-youtube"
41
43
  },
42
44
  "scripts": {
43
- "clean": "rm -rf dist",
44
- "build": "npm run clean && rollup -c"
45
+ "build": "tsup",
46
+ "lint": "prettier ./src/ --check && eslint --cache --quiet --no-error-on-unmatched-pattern ./src/"
45
47
  }
46
- }
48
+ }
package/src/utils.ts CHANGED
@@ -1,33 +1,35 @@
1
- export const YOUTUBE_REGEX = /^((?:https?:)?\/\/)?((?:www|m|music)\.)?((?:youtube\.com|youtu.be|youtube-nocookie\.com))(\/(?:[\w-]+\?v=|embed\/|v\/)?)([\w-]+)(\S+)?$/
2
- export const YOUTUBE_REGEX_GLOBAL = /^((?:https?:)?\/\/)?((?:www|m|music)\.)?((?:youtube\.com|youtu.be|youtube-nocookie\.com))(\/(?:[\w-]+\?v=|embed\/|v\/)?)([\w-]+)(\S+)?$/g
1
+ export const YOUTUBE_REGEX =
2
+ /^((?:https?:)?\/\/)?((?:www|m|music)\.)?((?:youtube\.com|youtu.be|youtube-nocookie\.com))(\/(?:[\w-]+\?v=|embed\/|v\/)?)([\w-]+)(\S+)?$/
3
+ export const YOUTUBE_REGEX_GLOBAL =
4
+ /^((?:https?:)?\/\/)?((?:www|m|music)\.)?((?:youtube\.com|youtu.be|youtube-nocookie\.com))(\/(?:[\w-]+\?v=|embed\/|v\/)?)([\w-]+)(\S+)?$/g
3
5
 
4
6
  export const isValidYoutubeUrl = (url: string) => {
5
7
  return url.match(YOUTUBE_REGEX)
6
8
  }
7
9
 
8
10
  export interface GetEmbedUrlOptions {
9
- url: string;
10
- allowFullscreen?: boolean;
11
- autoplay?: boolean;
12
- ccLanguage?:string;
13
- ccLoadPolicy?:boolean;
14
- controls?: boolean;
15
- disableKBcontrols?: boolean,
16
- enableIFrameApi?: boolean;
17
- endTime?: number;
18
- interfaceLanguage?: string;
19
- ivLoadPolicy?: number;
20
- loop?: boolean;
21
- modestBranding?: boolean;
22
- nocookie?: boolean;
23
- origin?: string;
24
- playlist?: string;
25
- progressBarColor?: string;
26
- startAt?: number;
27
- rel?: number;
11
+ url: string
12
+ allowFullscreen?: boolean
13
+ autoplay?: boolean
14
+ ccLanguage?: string
15
+ ccLoadPolicy?: boolean
16
+ controls?: boolean
17
+ disableKBcontrols?: boolean
18
+ enableIFrameApi?: boolean
19
+ endTime?: number
20
+ interfaceLanguage?: string
21
+ ivLoadPolicy?: number
22
+ loop?: boolean
23
+ modestBranding?: boolean
24
+ nocookie?: boolean
25
+ origin?: string
26
+ playlist?: string
27
+ progressBarColor?: string
28
+ startAt?: number
29
+ rel?: number
28
30
  }
29
31
 
30
- export const getYoutubeEmbedUrl = (nocookie?: boolean, isPlaylist?:boolean) => {
32
+ export const getYoutubeEmbedUrl = (nocookie?: boolean, isPlaylist?: boolean) => {
31
33
  if (isPlaylist) {
32
34
  return 'https://www.youtube-nocookie.com/embed/videoseries?list='
33
35
  }
package/src/youtube.ts CHANGED
@@ -8,160 +8,160 @@ export interface YoutubeOptions {
8
8
  * @default true
9
9
  * @example false
10
10
  */
11
- addPasteHandler: boolean;
11
+ addPasteHandler: boolean
12
12
 
13
13
  /**
14
14
  * Controls if the youtube video should be allowed to go fullscreen.
15
15
  * @default true
16
16
  * @example false
17
17
  */
18
- allowFullscreen: boolean;
18
+ allowFullscreen: boolean
19
19
 
20
20
  /**
21
21
  * Controls if the youtube video should autoplay.
22
22
  * @default false
23
23
  * @example true
24
24
  */
25
- autoplay: boolean;
25
+ autoplay: boolean
26
26
 
27
27
  /**
28
28
  * The language of the captions shown in the youtube video.
29
29
  * @default undefined
30
30
  * @example 'en'
31
31
  */
32
- ccLanguage?: string;
32
+ ccLanguage?: string
33
33
 
34
34
  /**
35
35
  * Controls if the captions should be shown in the youtube video.
36
36
  * @default undefined
37
37
  * @example true
38
38
  */
39
- ccLoadPolicy?: boolean;
39
+ ccLoadPolicy?: boolean
40
40
 
41
41
  /**
42
42
  * Controls if the controls should be shown in the youtube video.
43
43
  * @default true
44
44
  * @example false
45
45
  */
46
- controls: boolean;
46
+ controls: boolean
47
47
 
48
48
  /**
49
49
  * Controls if the keyboard controls should be disabled in the youtube video.
50
50
  * @default false
51
51
  * @example true
52
52
  */
53
- disableKBcontrols: boolean;
53
+ disableKBcontrols: boolean
54
54
 
55
55
  /**
56
56
  * Controls if the iframe api should be enabled in the youtube video.
57
57
  * @default false
58
58
  * @example true
59
59
  */
60
- enableIFrameApi: boolean;
60
+ enableIFrameApi: boolean
61
61
 
62
62
  /**
63
63
  * The end time of the youtube video.
64
64
  * @default 0
65
65
  * @example 120
66
66
  */
67
- endTime: number;
67
+ endTime: number
68
68
 
69
69
  /**
70
70
  * The height of the youtube video.
71
71
  * @default 480
72
72
  * @example 720
73
73
  */
74
- height: number;
74
+ height: number
75
75
 
76
76
  /**
77
77
  * The language of the youtube video.
78
78
  * @default undefined
79
79
  * @example 'en'
80
80
  */
81
- interfaceLanguage?: string;
81
+ interfaceLanguage?: string
82
82
 
83
83
  /**
84
84
  * Controls if the video annotations should be shown in the youtube video.
85
85
  * @default 0
86
86
  * @example 1
87
87
  */
88
- ivLoadPolicy: number;
88
+ ivLoadPolicy: number
89
89
 
90
90
  /**
91
91
  * Controls if the youtube video should loop.
92
92
  * @default false
93
93
  * @example true
94
94
  */
95
- loop: boolean;
95
+ loop: boolean
96
96
 
97
97
  /**
98
98
  * Controls if the youtube video should show a small youtube logo.
99
99
  * @default false
100
100
  * @example true
101
101
  */
102
- modestBranding: boolean;
102
+ modestBranding: boolean
103
103
 
104
104
  /**
105
105
  * The HTML attributes for a youtube video node.
106
106
  * @default {}
107
107
  * @example { class: 'foo' }
108
108
  */
109
- HTMLAttributes: Record<string, any>;
109
+ HTMLAttributes: Record<string, any>
110
110
 
111
111
  /**
112
112
  * Controls if the youtube node should be inline or not.
113
113
  * @default false
114
114
  * @example true
115
115
  */
116
- inline: boolean;
116
+ inline: boolean
117
117
 
118
118
  /**
119
119
  * Controls if the youtube video should be loaded from youtube-nocookie.com.
120
120
  * @default false
121
121
  * @example true
122
122
  */
123
- nocookie: boolean;
123
+ nocookie: boolean
124
124
 
125
125
  /**
126
126
  * The origin of the youtube video.
127
127
  * @default ''
128
128
  * @example 'https://tiptap.dev'
129
129
  */
130
- origin: string;
130
+ origin: string
131
131
 
132
132
  /**
133
133
  * The playlist of the youtube video.
134
134
  * @default ''
135
135
  * @example 'PLQg6GaokU5CwiVmsZ0dZm6VeIg0V5z1tK'
136
136
  */
137
- playlist: string;
137
+ playlist: string
138
138
 
139
139
  /**
140
140
  * The color of the youtube video progress bar.
141
141
  * @default undefined
142
142
  * @example 'red'
143
143
  */
144
- progressBarColor?: string;
144
+ progressBarColor?: string
145
145
 
146
146
  /**
147
147
  * The width of the youtube video.
148
148
  * @default 640
149
149
  * @example 1280
150
150
  */
151
- width: number;
151
+ width: number
152
152
 
153
153
  /**
154
154
  * Controls if the related youtube videos at the end are from the same channel.
155
155
  * @default 1
156
156
  * @example 0
157
157
  */
158
- rel: number;
158
+ rel: number
159
159
  }
160
160
 
161
161
  /**
162
162
  * The options for setting a youtube video.
163
163
  */
164
- type SetYoutubeVideoOptions = { src: string, width?: number, height?: number, start?: number }
164
+ type SetYoutubeVideoOptions = { src: string; width?: number; height?: number; start?: number }
165
165
 
166
166
  declare module '@tiptap/core' {
167
167
  interface Commands<ReturnType> {
@@ -171,7 +171,7 @@ declare module '@tiptap/core' {
171
171
  * @param options The youtube video attributes
172
172
  * @example editor.commands.setYoutubeVideo({ src: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ' })
173
173
  */
174
- setYoutubeVideo: (options: SetYoutubeVideoOptions) => ReturnType,
174
+ setYoutubeVideo: (options: SetYoutubeVideoOptions) => ReturnType
175
175
  }
176
176
  }
177
177
  }
@@ -247,16 +247,18 @@ export const Youtube = Node.create<YoutubeOptions>({
247
247
 
248
248
  addCommands() {
249
249
  return {
250
- setYoutubeVideo: (options: SetYoutubeVideoOptions) => ({ commands }) => {
251
- if (!isValidYoutubeUrl(options.src)) {
252
- return false
253
- }
254
-
255
- return commands.insertContent({
256
- type: this.name,
257
- attrs: options,
258
- })
259
- },
250
+ setYoutubeVideo:
251
+ (options: SetYoutubeVideoOptions) =>
252
+ ({ commands }) => {
253
+ if (!isValidYoutubeUrl(options.src)) {
254
+ return false
255
+ }
256
+
257
+ return commands.insertContent({
258
+ type: this.name,
259
+ attrs: options,
260
+ })
261
+ },
260
262
  }
261
263
  },
262
264
 
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,cAAc,cAAc,CAAA;AAE5B,eAAe,OAAO,CAAA"}
package/dist/index.umd.js DELETED
@@ -1,246 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@tiptap/core')) :
3
- typeof define === 'function' && define.amd ? define(['exports', '@tiptap/core'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@tiptap/extension-youtube"] = {}, global.core));
5
- })(this, (function (exports, core) { 'use strict';
6
-
7
- const YOUTUBE_REGEX = /^((?:https?:)?\/\/)?((?:www|m|music)\.)?((?:youtube\.com|youtu.be|youtube-nocookie\.com))(\/(?:[\w-]+\?v=|embed\/|v\/)?)([\w-]+)(\S+)?$/;
8
- const YOUTUBE_REGEX_GLOBAL = /^((?:https?:)?\/\/)?((?:www|m|music)\.)?((?:youtube\.com|youtu.be|youtube-nocookie\.com))(\/(?:[\w-]+\?v=|embed\/|v\/)?)([\w-]+)(\S+)?$/g;
9
- const isValidYoutubeUrl = (url) => {
10
- return url.match(YOUTUBE_REGEX);
11
- };
12
- const getYoutubeEmbedUrl = (nocookie, isPlaylist) => {
13
- if (isPlaylist) {
14
- return 'https://www.youtube-nocookie.com/embed/videoseries?list=';
15
- }
16
- return nocookie ? 'https://www.youtube-nocookie.com/embed/' : 'https://www.youtube.com/embed/';
17
- };
18
- const getEmbedUrlFromYoutubeUrl = (options) => {
19
- const { url, allowFullscreen, autoplay, ccLanguage, ccLoadPolicy, controls, disableKBcontrols, enableIFrameApi, endTime, interfaceLanguage, ivLoadPolicy, loop, modestBranding, nocookie, origin, playlist, progressBarColor, startAt, rel, } = options;
20
- if (!isValidYoutubeUrl(url)) {
21
- return null;
22
- }
23
- // if is already an embed url, return it
24
- if (url.includes('/embed/')) {
25
- return url;
26
- }
27
- // if is a youtu.be url, get the id after the /
28
- if (url.includes('youtu.be')) {
29
- const id = url.split('/').pop();
30
- if (!id) {
31
- return null;
32
- }
33
- return `${getYoutubeEmbedUrl(nocookie)}${id}`;
34
- }
35
- const videoIdRegex = /(?:(v|list)=|shorts\/)([-\w]+)/gm;
36
- const matches = videoIdRegex.exec(url);
37
- if (!matches || !matches[2]) {
38
- return null;
39
- }
40
- let outputUrl = `${getYoutubeEmbedUrl(nocookie, matches[1] === 'list')}${matches[2]}`;
41
- const params = [];
42
- if (allowFullscreen === false) {
43
- params.push('fs=0');
44
- }
45
- if (autoplay) {
46
- params.push('autoplay=1');
47
- }
48
- if (ccLanguage) {
49
- params.push(`cc_lang_pref=${ccLanguage}`);
50
- }
51
- if (ccLoadPolicy) {
52
- params.push('cc_load_policy=1');
53
- }
54
- if (!controls) {
55
- params.push('controls=0');
56
- }
57
- if (disableKBcontrols) {
58
- params.push('disablekb=1');
59
- }
60
- if (enableIFrameApi) {
61
- params.push('enablejsapi=1');
62
- }
63
- if (endTime) {
64
- params.push(`end=${endTime}`);
65
- }
66
- if (interfaceLanguage) {
67
- params.push(`hl=${interfaceLanguage}`);
68
- }
69
- if (ivLoadPolicy) {
70
- params.push(`iv_load_policy=${ivLoadPolicy}`);
71
- }
72
- if (loop) {
73
- params.push('loop=1');
74
- }
75
- if (modestBranding) {
76
- params.push('modestbranding=1');
77
- }
78
- if (origin) {
79
- params.push(`origin=${origin}`);
80
- }
81
- if (playlist) {
82
- params.push(`playlist=${playlist}`);
83
- }
84
- if (startAt) {
85
- params.push(`start=${startAt}`);
86
- }
87
- if (progressBarColor) {
88
- params.push(`color=${progressBarColor}`);
89
- }
90
- if (rel !== undefined) {
91
- params.push(`rel=${rel}`);
92
- }
93
- if (params.length) {
94
- outputUrl += `${matches[1] === 'v' ? '?' : '&'}${params.join('&')}`;
95
- }
96
- return outputUrl;
97
- };
98
-
99
- /**
100
- * This extension adds support for youtube videos.
101
- * @see https://www.tiptap.dev/api/nodes/youtube
102
- */
103
- const Youtube = core.Node.create({
104
- name: 'youtube',
105
- addOptions() {
106
- return {
107
- addPasteHandler: true,
108
- allowFullscreen: true,
109
- autoplay: false,
110
- ccLanguage: undefined,
111
- ccLoadPolicy: undefined,
112
- controls: true,
113
- disableKBcontrols: false,
114
- enableIFrameApi: false,
115
- endTime: 0,
116
- height: 480,
117
- interfaceLanguage: undefined,
118
- ivLoadPolicy: 0,
119
- loop: false,
120
- modestBranding: false,
121
- HTMLAttributes: {},
122
- inline: false,
123
- nocookie: false,
124
- origin: '',
125
- playlist: '',
126
- progressBarColor: undefined,
127
- width: 640,
128
- rel: 1,
129
- };
130
- },
131
- inline() {
132
- return this.options.inline;
133
- },
134
- group() {
135
- return this.options.inline ? 'inline' : 'block';
136
- },
137
- draggable: true,
138
- addAttributes() {
139
- return {
140
- src: {
141
- default: null,
142
- },
143
- start: {
144
- default: 0,
145
- },
146
- width: {
147
- default: this.options.width,
148
- },
149
- height: {
150
- default: this.options.height,
151
- },
152
- };
153
- },
154
- parseHTML() {
155
- return [
156
- {
157
- tag: 'div[data-youtube-video] iframe',
158
- },
159
- ];
160
- },
161
- addCommands() {
162
- return {
163
- setYoutubeVideo: (options) => ({ commands }) => {
164
- if (!isValidYoutubeUrl(options.src)) {
165
- return false;
166
- }
167
- return commands.insertContent({
168
- type: this.name,
169
- attrs: options,
170
- });
171
- },
172
- };
173
- },
174
- addPasteRules() {
175
- if (!this.options.addPasteHandler) {
176
- return [];
177
- }
178
- return [
179
- core.nodePasteRule({
180
- find: YOUTUBE_REGEX_GLOBAL,
181
- type: this.type,
182
- getAttributes: match => {
183
- return { src: match.input };
184
- },
185
- }),
186
- ];
187
- },
188
- renderHTML({ HTMLAttributes }) {
189
- const embedUrl = getEmbedUrlFromYoutubeUrl({
190
- url: HTMLAttributes.src,
191
- allowFullscreen: this.options.allowFullscreen,
192
- autoplay: this.options.autoplay,
193
- ccLanguage: this.options.ccLanguage,
194
- ccLoadPolicy: this.options.ccLoadPolicy,
195
- controls: this.options.controls,
196
- disableKBcontrols: this.options.disableKBcontrols,
197
- enableIFrameApi: this.options.enableIFrameApi,
198
- endTime: this.options.endTime,
199
- interfaceLanguage: this.options.interfaceLanguage,
200
- ivLoadPolicy: this.options.ivLoadPolicy,
201
- loop: this.options.loop,
202
- modestBranding: this.options.modestBranding,
203
- nocookie: this.options.nocookie,
204
- origin: this.options.origin,
205
- playlist: this.options.playlist,
206
- progressBarColor: this.options.progressBarColor,
207
- startAt: HTMLAttributes.start || 0,
208
- rel: this.options.rel,
209
- });
210
- HTMLAttributes.src = embedUrl;
211
- return [
212
- 'div',
213
- { 'data-youtube-video': '' },
214
- [
215
- 'iframe',
216
- core.mergeAttributes(this.options.HTMLAttributes, {
217
- width: this.options.width,
218
- height: this.options.height,
219
- allowfullscreen: this.options.allowFullscreen,
220
- autoplay: this.options.autoplay,
221
- ccLanguage: this.options.ccLanguage,
222
- ccLoadPolicy: this.options.ccLoadPolicy,
223
- disableKBcontrols: this.options.disableKBcontrols,
224
- enableIFrameApi: this.options.enableIFrameApi,
225
- endTime: this.options.endTime,
226
- interfaceLanguage: this.options.interfaceLanguage,
227
- ivLoadPolicy: this.options.ivLoadPolicy,
228
- loop: this.options.loop,
229
- modestBranding: this.options.modestBranding,
230
- origin: this.options.origin,
231
- playlist: this.options.playlist,
232
- progressBarColor: this.options.progressBarColor,
233
- rel: this.options.rel,
234
- }, HTMLAttributes),
235
- ],
236
- ];
237
- },
238
- });
239
-
240
- exports.Youtube = Youtube;
241
- exports.default = Youtube;
242
-
243
- Object.defineProperty(exports, '__esModule', { value: true });
244
-
245
- }));
246
- //# sourceMappingURL=index.umd.js.map