mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-08 19:06:15 -08:00
- Emit 'resize' event after adding the document Picture-in-Picture class to the player. - Emit 'resize' event after removing the document Picture-in-Picture class from the player.
1 line
29 KiB
Plaintext
1 line
29 KiB
Plaintext
{"mappings":"C,A,S,C,C,C,C,C,C,C,C,C,C,C,C,C,C,C,E,I,E,A,a,O,W,W,A,a,O,K,K,A,a,O,O,O,A,a,O,O,O,C,E,E,A,Y,O,C,C,E,E,C,C,E,C,E,E,C,E,C,E,E,E,K,E,C,E,E,A,a,O,Q,A,Y,O,O,O,E,O,O,C,I,C,Q,S,E,C,C,C,E,G,C,C,C,E,C,C,G,C,C,C,E,C,C,G,C,C,E,C,O,C,C,E,C,I,E,A,Y,O,C,C,E,E,C,C,E,C,G,C,G,E,O,E,E,C,G,G,E,O,E,E,C,G,G,G,A,U,O,E,O,E,G,I,E,A,M,uB,E,I,O,E,I,C,mB,C,C,E,O,C,S,C,E,I,E,C,C,E,C,E,C,E,C,O,A,M,E,E,C,E,E,K,C,C,E,I,E,C,C,E,C,I,E,M,C,G,C,C,E,C,E,C,I,C,E,O,C,E,E,E,O,C,E,C,O,C,C,E,C,O,C,S,E,C,E,I,E,E,O,C,G,M,A,C,I,E,C,E,E,E,C,C,E,e,C,C,E,E,M,C,S,C,E,I,C,E,C,E,I,C,M,C,E,I,C,O,C,E,I,C,O,C,C,C,E,E,O,C,E,E,K,C,E,E,M,C,E,E,O,C,K,E,E,S,C,K,E,E,S,C,K,E,E,C,C,E,E,Q,C,S,C,C,C,E,C,C,E,C,C,S,C,C,C,E,E,O,C,C,E,C,E,A,E,O,c,C,E,O,C,I,W,O,C,C,E,A,C,G,C,C,E,C,E,I,I,E,E,E,E,M,C,I,E,C,C,E,E,G,E,C,I,E,E,E,A,C,U,O,S,A,a,O,O,O,O,C,E,A,Y,O,Q,O,G,E,O,W,O,C,E,C,E,C,M,C,S,C,C,C,C,C,C,C,E,I,E,E,kD,E,iB,C,GCEwB,E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AkBxC,OAjBA,OAAO,IAAI,CAAC,GAAQ,OAAO,CAAC,SAAU,CAAG,EAE7B,YAAR,GACA,AAAQ,eAAR,GACA,OAAO,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,EAAM,IAK7C,OAAO,cAAc,CAAC,EAAM,EAAK,CAC/B,WAAY,CAAA,EACZ,IAAK,WACH,OAAO,CAAM,CAAC,EAAI,AACpB,CACF,EACF,GAEO,CACT,EAEA,EAAQ,MAAM,CAAG,SAAU,CAAI,CAAE,CAAQ,CAAE,CAAG,EAC5C,OAAO,cAAc,CAAC,EAAM,EAAU,CACpC,WAAY,CAAA,EACZ,IAAK,CACP,EACF,C,E,C,E,E,C,Q,C,Q,oB,C,G,G,C,Q,C,C,C,kB,gB,K,O","sources":["<anon>","packages/artplayer-plugin-document-pip/src/index.js","node_modules/@parcel/runtime-js/lib/bundles/runtime-d505b78bb5af333a.js","node_modules/@parcel/transformer-js/src/esmodule-helpers.js"],"sourcesContent":["// modules are defined as an array\n// [ module function, map of requires ]\n//\n// map of requires is short require name -> numeric require\n//\n// anything defined in a previous bundle is accessed via the\n// orig method which is the require for previous bundles\n\n(function (\n modules,\n entry,\n mainEntry,\n parcelRequireName,\n externals,\n distDir,\n publicUrl,\n devServer\n) {\n /* eslint-disable no-undef */\n var globalObject =\n typeof globalThis !== 'undefined'\n ? globalThis\n : typeof self !== 'undefined'\n ? self\n : typeof window !== 'undefined'\n ? window\n : typeof global !== 'undefined'\n ? global\n : {};\n /* eslint-enable no-undef */\n\n // Save the require from previous bundle to this closure if any\n var previousRequire =\n typeof globalObject[parcelRequireName] === 'function' &&\n globalObject[parcelRequireName];\n\n var importMap = previousRequire.i || {};\n var cache = previousRequire.cache || {};\n // Do not use `require` to prevent Webpack from trying to bundle this call\n var nodeRequire =\n typeof module !== 'undefined' &&\n typeof module.require === 'function' &&\n module.require.bind(module);\n\n function newRequire(name, jumped) {\n if (!cache[name]) {\n if (!modules[name]) {\n if (externals[name]) {\n return externals[name];\n }\n // if we cannot find the module within our internal map or\n // cache jump to the current global require ie. the last bundle\n // that was added to the page.\n var currentRequire =\n typeof globalObject[parcelRequireName] === 'function' &&\n globalObject[parcelRequireName];\n if (!jumped && currentRequire) {\n return currentRequire(name, true);\n }\n\n // If there are other bundles on this page the require from the\n // previous one is saved to 'previousRequire'. Repeat this as\n // many times as there are bundles until the module is found or\n // we exhaust the require chain.\n if (previousRequire) {\n return previousRequire(name, true);\n }\n\n // Try the node require function if it exists.\n if (nodeRequire && typeof name === 'string') {\n return nodeRequire(name);\n }\n\n var err = new Error(\"Cannot find module '\" + name + \"'\");\n err.code = 'MODULE_NOT_FOUND';\n throw err;\n }\n\n localRequire.resolve = resolve;\n localRequire.cache = {};\n\n var module = (cache[name] = new newRequire.Module(name));\n\n modules[name][0].call(\n module.exports,\n localRequire,\n module,\n module.exports,\n globalObject\n );\n }\n\n return cache[name].exports;\n\n function localRequire(x) {\n var res = localRequire.resolve(x);\n return res === false ? {} : newRequire(res);\n }\n\n function resolve(x) {\n var id = modules[name][1][x];\n return id != null ? id : x;\n }\n }\n\n function Module(moduleName) {\n this.id = moduleName;\n this.bundle = newRequire;\n this.require = nodeRequire;\n this.exports = {};\n }\n\n newRequire.isParcelRequire = true;\n newRequire.Module = Module;\n newRequire.modules = modules;\n newRequire.cache = cache;\n newRequire.parent = previousRequire;\n newRequire.distDir = distDir;\n newRequire.publicUrl = publicUrl;\n newRequire.devServer = devServer;\n newRequire.i = importMap;\n newRequire.register = function (id, exports) {\n modules[id] = [\n function (require, module) {\n module.exports = exports;\n },\n {},\n ];\n };\n\n // Only insert newRequire.load when it is actually used.\n // The code in this file is linted against ES5, so dynamic import is not allowed.\n // INSERT_LOAD_HERE\n\n Object.defineProperty(newRequire, 'root', {\n get: function () {\n return globalObject[parcelRequireName];\n },\n });\n\n globalObject[parcelRequireName] = newRequire;\n\n for (var i = 0; i < entry.length; i++) {\n newRequire(entry[i]);\n }\n\n if (mainEntry) {\n // Expose entry point to Node, AMD or browser globals\n // Based on https://github.com/ForbesLindesay/umd/blob/master/template.js\n var mainExports = newRequire(mainEntry);\n\n // CommonJS\n if (typeof exports === 'object' && typeof module !== 'undefined') {\n module.exports = mainExports;\n\n // RequireJS\n } else if (typeof define === 'function' && define.amd) {\n define(function () {\n return mainExports;\n });\n }\n }\n})({\"bKI9O\":[function(require,module,exports,__globalThis) {\nvar parcelHelpers = require(\"@parcel/transformer-js/src/esmodule-helpers.js\");\nparcelHelpers.defineInteropFlag(exports);\nparcelHelpers.export(exports, \"default\", ()=>artplayerPluginDocumentPip);\nvar _styleLess = require(\"bundle-text:./style.less\");\nvar _styleLessDefault = parcelHelpers.interopDefault(_styleLess);\nfunction artplayerPluginDocumentPip(userOptions = {}) {\n const options = {\n width: 480,\n height: 270,\n fallbackToVideoPiP: true,\n placeholder: `Playing in Document Picture-in-Picture`,\n ...userOptions\n };\n return (art)=>{\n const isSupported = 'documentPictureInPicture' in window && typeof window.documentPictureInPicture?.requestWindow === 'function';\n const { proxy, icons, i18n, template: { $player }, constructor: { utils: { append, tooltip, addClass, removeClass } } } = art;\n const state = {\n win: null,\n originalParent: null,\n originalNext: null,\n currentDoc: null,\n placeholder: null\n };\n function copyStylesTo(targetDoc) {\n const base = targetDoc.createElement('style');\n base.textContent = `\n html, body { margin:0; padding:0; width:100%; height:100%; background:#000; overflow:hidden; }\n #__art_dpip_root { position:absolute; inset:0; display:flex; }\n #__art_dpip_root > * { width:100% !important; height:100% !important; }\n `;\n targetDoc.head.appendChild(base);\n if (!targetDoc.querySelector('meta[name=\"viewport\"]')) {\n const meta = targetDoc.createElement('meta');\n meta.name = 'viewport';\n meta.content = 'width=device-width,initial-scale=1';\n targetDoc.head.appendChild(meta);\n }\n try {\n document.querySelectorAll('link[rel=\"stylesheet\"]').forEach((link)=>{\n const clone = targetDoc.createElement('link');\n clone.rel = 'stylesheet';\n clone.href = link.href;\n if (link.media) clone.media = link.media;\n if (link.crossOrigin) clone.crossOrigin = link.crossOrigin;\n if (link.referrerPolicy) clone.referrerPolicy = link.referrerPolicy;\n targetDoc.head.appendChild(clone);\n });\n } catch {}\n try {\n document.querySelectorAll('style').forEach((style)=>{\n const clone = targetDoc.createElement('style');\n clone.textContent = style.textContent;\n targetDoc.head.appendChild(clone);\n });\n } catch {}\n }\n async function open() {\n if (!isSupported && options.fallbackToVideoPiP) {\n art.pip = true;\n console.warn('[artplayer-plugin-document-pip] Document Picture-in-Picture is not supported, falling back to Video Picture-in-Picture');\n return;\n }\n if (state.win) return;\n try {\n const pipWin = await window.documentPictureInPicture.requestWindow({\n width: options.width,\n height: options.height\n });\n state.win = pipWin;\n state.currentDoc = pipWin.document;\n state.placeholder = document.createElement('div');\n state.placeholder.className = 'artplayer-document-pip-placeholder';\n state.placeholder.style.cssText = `display:flex;justify-content:center;align-items:center;width:100%;height:100%;`;\n state.placeholder.textContent = options.placeholder;\n state.originalParent = $player.parentNode;\n state.originalNext = $player.nextSibling;\n state.originalParent.insertBefore(state.placeholder, state.originalNext);\n const root = pipWin.document.createElement('div');\n root.id = '__art_dpip_root';\n pipWin.document.body.appendChild(root);\n copyStylesTo(pipWin.document);\n const adopted = pipWin.document.adoptNode($player);\n root.appendChild(adopted);\n state.currentDoc = pipWin.document;\n const onResize = ()=>art.resize?.();\n const onClose = ()=>close();\n pipWin.addEventListener('resize', onResize);\n pipWin.addEventListener('pagehide', onClose);\n pipWin.addEventListener('unload', onClose);\n state.cleanup = ()=>{\n pipWin.removeEventListener('resize', onResize);\n pipWin.removeEventListener('pagehide', onClose);\n pipWin.removeEventListener('unload', onClose);\n };\n addClass($player, 'artplayer-document-pip');\n art.events.bindGlobalEvents?.();\n art.emit('resize');\n art.emit('document-pip', true);\n } catch (err) {\n art.notice.show = 'Document Picture-in-Picture open failed';\n console.warn('[artplayer-plugin-document-pip] open failed:', err);\n }\n }\n function restoreToOriginalDocument() {\n if (!state.placeholder) return;\n const backDoc = state.placeholder.ownerDocument || document;\n const adoptedBack = backDoc.adoptNode($player);\n state.originalParent.insertBefore(adoptedBack, state.placeholder);\n state.placeholder.remove();\n state.placeholder = null;\n state.currentDoc = backDoc;\n }\n function close() {\n if (!state.win) return;\n try {\n state.cleanup?.();\n restoreToOriginalDocument();\n state.win.close();\n state.win = null;\n removeClass($player, 'artplayer-document-pip');\n art.events.bindGlobalEvents?.();\n art.emit('resize');\n art.emit('document-pip', false);\n } catch (err) {\n art.notice.show = 'Document Picture-in-Picture close failed';\n console.warn('[artplayer-plugin-document-pip] close failed:', err);\n }\n }\n function toggle() {\n if (state.win) close();\n else open();\n }\n art.controls.add({\n name: 'document-pip',\n position: 'right',\n index: 40,\n tooltip: art.i18n.get('PIP Mode'),\n mounted: ($control)=>{\n append($control, icons.pip);\n proxy($control, 'click', toggle);\n art.on('document-pip', (value)=>{\n tooltip($control, i18n.get(value ? 'Exit PIP Mode' : 'PIP Mode'));\n });\n }\n });\n art.on('destroy', close);\n return {\n name: 'artplayerPluginDocumentPip',\n get isSupported () {\n return isSupported;\n },\n get isActive () {\n return !!state.win;\n },\n open,\n close,\n toggle\n };\n };\n}\nif (typeof window !== 'undefined') window.artplayerPluginDocumentPip = artplayerPluginDocumentPip;\nif (typeof document !== 'undefined') {\n const id = 'artplayer-plugin-document-pip';\n let $style = document.getElementById(id);\n if (!$style) {\n $style = document.createElement('style');\n $style.id = id;\n if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', ()=>{\n document.head.appendChild($style);\n });\n else (document.head || document.documentElement).appendChild($style);\n }\n $style.textContent = (0, _styleLessDefault.default);\n}\n\n},{\"bundle-text:./style.less\":\"forQu\",\"@parcel/transformer-js/src/esmodule-helpers.js\":\"5lQoW\"}],\"forQu\":[function(require,module,exports,__globalThis) {\nmodule.exports = \".artplayer-document-pip.art-video-player{width:100%!important;height:100%!important}\";\n\n},{}],\"5lQoW\":[function(require,module,exports,__globalThis) {\nexports.interopDefault = function(a) {\n return a && a.__esModule ? a : {\n default: a\n };\n};\nexports.defineInteropFlag = function(a) {\n Object.defineProperty(a, '__esModule', {\n value: true\n });\n};\nexports.exportAll = function(source, dest) {\n Object.keys(source).forEach(function(key) {\n if (key === 'default' || key === '__esModule' || Object.prototype.hasOwnProperty.call(dest, key)) return;\n Object.defineProperty(dest, key, {\n enumerable: true,\n get: function() {\n return source[key];\n }\n });\n });\n return dest;\n};\nexports.export = function(dest, destName, get) {\n Object.defineProperty(dest, destName, {\n enumerable: true,\n get: get\n });\n};\n\n},{}]},[\"bKI9O\"], \"bKI9O\", \"parcelRequire4dc0\", {})\nlet {default: _default, } = parcelRequire4dc0(\"bKI9O\");\nexport {_default as default, };\n\n//# sourceMappingURL=index.js.map\n","import style from 'bundle-text:./style.less'\n\nexport default function artplayerPluginDocumentPip(userOptions = {}) {\n const options = {\n width: 480,\n height: 270,\n fallbackToVideoPiP: true,\n placeholder: `Playing in Document Picture-in-Picture`,\n ...userOptions,\n }\n\n return (art) => {\n const isSupported = 'documentPictureInPicture' in window\n && typeof window.documentPictureInPicture?.requestWindow === 'function'\n\n const { proxy, icons, i18n, template: { $player }, constructor: { utils: { append, tooltip, addClass, removeClass } } } = art\n\n const state = {\n win: null,\n originalParent: null,\n originalNext: null,\n currentDoc: null,\n placeholder: null,\n }\n\n function copyStylesTo(targetDoc) {\n const base = targetDoc.createElement('style')\n base.textContent = `\n html, body { margin:0; padding:0; width:100%; height:100%; background:#000; overflow:hidden; }\n #__art_dpip_root { position:absolute; inset:0; display:flex; }\n #__art_dpip_root > * { width:100% !important; height:100% !important; }\n `\n targetDoc.head.appendChild(base)\n if (!targetDoc.querySelector('meta[name=\"viewport\"]')) {\n const meta = targetDoc.createElement('meta')\n meta.name = 'viewport'\n meta.content = 'width=device-width,initial-scale=1'\n targetDoc.head.appendChild(meta)\n }\n\n try {\n document.querySelectorAll('link[rel=\"stylesheet\"]').forEach((link) => {\n const clone = targetDoc.createElement('link')\n clone.rel = 'stylesheet'\n clone.href = link.href\n if (link.media)\n clone.media = link.media\n if (link.crossOrigin)\n clone.crossOrigin = link.crossOrigin\n if (link.referrerPolicy)\n clone.referrerPolicy = link.referrerPolicy\n targetDoc.head.appendChild(clone)\n })\n }\n catch { }\n\n try {\n document.querySelectorAll('style').forEach((style) => {\n const clone = targetDoc.createElement('style')\n clone.textContent = style.textContent\n targetDoc.head.appendChild(clone)\n })\n }\n catch { }\n }\n\n async function open() {\n if (!isSupported && options.fallbackToVideoPiP) {\n art.pip = true\n console.warn('[artplayer-plugin-document-pip] Document Picture-in-Picture is not supported, falling back to Video Picture-in-Picture')\n return\n }\n\n if (state.win)\n return\n\n try {\n const pipWin = await window.documentPictureInPicture.requestWindow({\n width: options.width,\n height: options.height,\n })\n\n state.win = pipWin\n state.currentDoc = pipWin.document\n\n state.placeholder = document.createElement('div')\n state.placeholder.className = 'artplayer-document-pip-placeholder'\n state.placeholder.style.cssText = `display:flex;justify-content:center;align-items:center;width:100%;height:100%;`\n state.placeholder.textContent = options.placeholder\n state.originalParent = $player.parentNode\n state.originalNext = $player.nextSibling\n state.originalParent.insertBefore(state.placeholder, state.originalNext)\n\n const root = pipWin.document.createElement('div')\n root.id = '__art_dpip_root'\n pipWin.document.body.appendChild(root)\n\n copyStylesTo(pipWin.document)\n\n const adopted = pipWin.document.adoptNode($player)\n root.appendChild(adopted)\n state.currentDoc = pipWin.document\n\n const onResize = () => art.resize?.()\n const onClose = () => close()\n\n pipWin.addEventListener('resize', onResize)\n pipWin.addEventListener('pagehide', onClose)\n pipWin.addEventListener('unload', onClose)\n\n state.cleanup = () => {\n pipWin.removeEventListener('resize', onResize)\n pipWin.removeEventListener('pagehide', onClose)\n pipWin.removeEventListener('unload', onClose)\n }\n\n addClass($player, 'artplayer-document-pip')\n art.events.bindGlobalEvents?.()\n art.emit('resize')\n art.emit('document-pip', true)\n }\n catch (err) {\n art.notice.show = 'Document Picture-in-Picture open failed'\n console.warn('[artplayer-plugin-document-pip] open failed:', err)\n }\n }\n\n function restoreToOriginalDocument() {\n if (!state.placeholder)\n return\n const backDoc = state.placeholder.ownerDocument || document\n const adoptedBack = backDoc.adoptNode($player)\n state.originalParent.insertBefore(adoptedBack, state.placeholder)\n state.placeholder.remove()\n state.placeholder = null\n state.currentDoc = backDoc\n }\n\n function close() {\n if (!state.win)\n return\n try {\n state.cleanup?.()\n restoreToOriginalDocument()\n state.win.close()\n state.win = null\n removeClass($player, 'artplayer-document-pip')\n art.events.bindGlobalEvents?.()\n art.emit('resize')\n art.emit('document-pip', false)\n }\n catch (err) {\n art.notice.show = 'Document Picture-in-Picture close failed'\n console.warn('[artplayer-plugin-document-pip] close failed:', err)\n }\n }\n\n function toggle() {\n if (state.win) {\n close()\n }\n else {\n open()\n }\n }\n\n art.controls.add({\n name: 'document-pip',\n position: 'right',\n index: 40,\n tooltip: art.i18n.get('PIP Mode'),\n mounted: ($control) => {\n append($control, icons.pip)\n proxy($control, 'click', toggle)\n art.on('document-pip', (value) => {\n tooltip($control, i18n.get(value ? 'Exit PIP Mode' : 'PIP Mode'))\n })\n },\n })\n\n art.on('destroy', close)\n\n return {\n name: 'artplayerPluginDocumentPip',\n get isSupported() { return isSupported },\n get isActive() { return !!state.win },\n open,\n close,\n toggle,\n }\n }\n}\n\nif (typeof window !== 'undefined') {\n window.artplayerPluginDocumentPip = artplayerPluginDocumentPip\n}\n\nif (typeof document !== 'undefined') {\n const id = 'artplayer-plugin-document-pip'\n let $style = document.getElementById(id)\n if (!$style) {\n $style = document.createElement('style')\n $style.id = id\n if (document.readyState === 'loading') {\n document.addEventListener('DOMContentLoaded', () => {\n document.head.appendChild($style)\n })\n }\n else {\n (document.head || document.documentElement).appendChild($style)\n }\n }\n $style.textContent = style\n}\n","module.exports = \"9a3b9db84948ae36\";","exports.interopDefault = function (a) {\n return a && a.__esModule ? a : {default: a};\n};\n\nexports.defineInteropFlag = function (a) {\n Object.defineProperty(a, '__esModule', {value: true});\n};\n\nexports.exportAll = function (source, dest) {\n Object.keys(source).forEach(function (key) {\n if (\n key === 'default' ||\n key === '__esModule' ||\n Object.prototype.hasOwnProperty.call(dest, key)\n ) {\n return;\n }\n\n Object.defineProperty(dest, key, {\n enumerable: true,\n get: function () {\n return source[key];\n },\n });\n });\n\n return dest;\n};\n\nexports.export = function (dest, destName, get) {\n Object.defineProperty(dest, destName, {\n enumerable: true,\n get: get,\n });\n};\n"],"names":["modules","entry","mainEntry","parcelRequireName","externals","distDir","publicUrl","devServer","globalObject","globalThis","self","window","global","previousRequire","importMap","i","cache","nodeRequire","module","require","bind","newRequire","name","jumped","currentRequire","err","Error","code","localRequire","resolve","x","id","Module","call","exports","res","isParcelRequire","moduleName","bundle","parent","register","Object","defineProperty","get","length","mainExports","define","amd","__globalThis","parcelHelpers","defineInteropFlag","export","artplayerPluginDocumentPip","_styleLess","_styleLessDefault","interopDefault","userOptions","options","width","height","fallbackToVideoPiP","placeholder","art","isSupported","documentPictureInPicture","requestWindow","proxy","icons","i18n","template","$player","utils","append","tooltip","addClass","removeClass","state","win","originalParent","originalNext","currentDoc","open","pip","console","warn","pipWin","document","createElement","className","style","cssText","textContent","parentNode","nextSibling","insertBefore","root","body","appendChild","targetDoc","base","head","querySelector","meta","content","querySelectorAll","forEach","link","clone","rel","href","media","crossOrigin","referrerPolicy","adopted","adoptNode","onResize","resize","onClose","close","addEventListener","cleanup","removeEventListener","events","bindGlobalEvents","emit","notice","show","restoreToOriginalDocument","backDoc","ownerDocument","adoptedBack","remove","toggle","controls","add","position","index","mounted","$control","on","value","isActive","$style","getElementById","readyState","documentElement","default","a","__esModule","exportAll","source","dest","keys","key","prototype","hasOwnProperty","enumerable","destName","_default","parcelRequire4dc0"],"version":3,"file":"index.js.map"} |