@galacean/effects-plugin-dom-content 2.9.3 → 2.9.4
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 +8 -4
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +2 -2
- package/dist/index.min.js.map +1 -1
- package/dist/index.mjs +8 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.min.js
CHANGED
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
* Description: Galacean Effects plugin for rendering HTML/CSS DOM content as texture
|
|
4
4
|
* Author: Ant Group CO., Ltd.
|
|
5
5
|
* Contributors: 陈茉
|
|
6
|
-
* Version: v2.9.
|
|
7
|
-
*/function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@galacean/effects")):"function"==typeof define&&define.amd?define(["exports","@galacean/effects"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).ge=e.ge||{},e.ge.domContentPlugin={}),e.ge)}(this,function(e,t){"use strict";var n=function(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}}),t.default=e,Object.freeze(t)}(t);function r(e,t){return(r=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function i(e,t){if("function"!=typeof t&&null!==t)throw TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&r(e,t)}function o(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(o=function(){return!!e})()}function a(e,t,n){return(a=o()?Reflect.construct:function(e,t,n){var i=[null];i.push.apply(i,t);var o=new(Function.bind.apply(e,i));return n&&r(o,n.prototype),o}).apply(null,arguments)}function s(e){return(s=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function c(e){var t="function"==typeof Map?new Map:void 0;return(c=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return a(e,arguments,s(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),r(n,e)})(e)}var u=function(e){function t(){var t;return t=e.apply(this,arguments)||this,t.name="dom-content",t}return i(t,e),t}(c(t.Plugin));function l(e,t,n,r,i,o,a){try{var s=e[o](a),c=s.value}catch(e){n(e);return}s.done?t(c):Promise.resolve(c).then(r,i)}function f(e){return function(){var t=this,n=arguments;return new Promise(function(r,i){var o=e.apply(t,n);function a(e){l(o,r,i,a,s,"next",e)}function s(e){l(o,r,i,a,s,"throw",e)}a(void 0)})}}function h(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function d(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return h(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return h(e,void 0)}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function p(e,t){var n,r,i,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return a.next=s(0),a.throw=s(1),a.return=s(2),"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(s){return function(c){return function(s){if(n)throw TypeError("Generator is already executing.");for(;a&&(a=0,s[0]&&(o=0)),o;)try{if(n=1,r&&(i=2&s[0]?r.return:s[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,s[1])).done)return i;switch(r=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return o.label++,{value:s[1],done:!1};case 5:o.label++,r=s[1],s=[0];continue;case 7:s=o.ops.pop(),o.trys.pop();continue;default:if(!(i=(i=o.trys).length>0&&i[i.length-1])&&(6===s[0]||2===s[0])){o=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){o.label=s[1];break}if(6===s[0]&&o.label<i[1]){o.label=i[1],i=s;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(s);break}i[2]&&o.ops.pop(),o.trys.pop();continue}s=t.call(e,o)}catch(e){s=[6,e],r=0}finally{n=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,c])}}}function g(){return(g=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}"function"==typeof SuppressedError&&SuppressedError;var v={inlineFonts:!0,inlineImages:!0,extractDefs:!0},m=new Set(["filter","clippath","mask","lineargradient","radialgradient","pattern","marker"]),y=new Set(["img"]),w=new Set(["video","source","input","audio"]),b=/url\(\s*(?:"([^"]+)"|'([^']+)'|([^\s)"']+))\s*\)/gi;function x(e,t,n,r){for(var i=0,o=e.length;i<o;){var a=e.indexOf("<",i);if(-1===a)break;var s=e.charCodeAt(a+1);if(!(s>=65&&s<=90||s>=97&&s<=122)){i=a+1;continue}for(var c=a+1;c<o;){var u=e.charCodeAt(c);if(32===u||9===u||10===u||13===u||47===u||62===u)break;c++}var l=e.slice(a+1,c).toLowerCase();if(null!==t&&!t.has(l)){i=c;continue}for(var f=Math.min(o,c+16e3),h=-1,p=!1,g=!1,v=c;v<f;v++){var m=e.charCodeAt(v);if(34!==m||g){if(39!==m||p){if(62===m&&!p&&!g){h=v;break}}else g=!g}else p=!p}if(-1===h){i=c;continue}for(var y,w=e.slice(c,h),b=d(n);!(y=b()).done;)!function(e,t,n){for(var r=e.toLowerCase(),i=t.toLowerCase(),o=0;o<r.length;){var a=r.indexOf(i,o);if(-1===a)return;var s=0===a?32:r.charCodeAt(a-1);if(!(32===s||9===s||10===s||13===s)){o=a+i.length;continue}for(var c=a+i.length;c<e.length&&/\s/.test(e[c]);)c++;if("="!==e[c]){o=a+i.length;continue}for(c++;c<e.length&&/\s/.test(e[c]);)c++;var u="",l=e[c];if('"'===l||"'"===l){var f=e.indexOf(l,c+1);if(-1===f)return;u=e.slice(c+1,f)}else{for(var h=c;h<e.length&&!/[\s>]/.test(e[h]);)h++;u=e.slice(c,h)}u&&n.add(u);return}}(w,y.value,r);i=h+1}}var C=/url\(\s*(?:"([^"]+)"|'([^']+)'|([^\s)"']+))\s*\)/gi,A=/url\(\s*(?:"|')?#([a-zA-Z][\w.-]*)(?:"|')?\s*\)/g,T=function(e){return e.startsWith("data:")||e.startsWith("blob:")};function O(e,t,n){return S.apply(this,arguments)}function S(){return(S=f(function(e,n,r,i,o){var a,s,c,u,l,f,h;return p(this,function(d){switch(d.label){case 0:if(void 0===i&&(i=1),!Number.isFinite(n)||!Number.isFinite(r)||!Number.isFinite(i)||n<=0||r<=0||i<0)throw Error("renderDOMToImage: width and height must be positive, scale must be non-negative.");if(0===i)return t.logger.warn("renderDOMToImage: scale is 0, skipping render."),[2,t.loadImage("data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7")];if(a=g({},v,o),s=j(e),!a.inlineFonts)return[3,2];return[4,R(s)];case 1:s=d.sent(),d.label=2;case 2:if(!a.inlineImages)return[3,4];return[4,E(s)];case 3:s=d.sent(),d.label=4;case 4:return c=a.extractDefs?z(s):"",u=n*i,l=r*i,f=function(e){if("undefined"==typeof document)return'<div xmlns="http://www.w3.org/1999/xhtml">'+e+"</div>";var t=document.implementation.createHTMLDocument("").createElement("div");return t.innerHTML=e,t.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),new XMLSerializer().serializeToString(t)}(function(e){for(var t="",n=0,r=e.length,i=e.toLowerCase();n<r;){var o=i.indexOf("<svg",n);if(-1===o){t+=e.slice(n);break}var a=i.charCodeAt(o+4);if(!(32===a||9===a||10===a||13===a||62===a||47===a)){t+=e.slice(n,o+4),n=o+4;continue}var s=i.indexOf(">",o+4);if(-1===s){t+=e.slice(n);break}var c=i.slice(o,s),u=/[\s][\s]*xmlns\s*=/i.test(" "+c);t+=e.slice(n,o+4),u||(t+=' xmlns="http://www.w3.org/2000/svg"'),t+=e.slice(o+4,s+1),n=s+1}return t}(s)),h='<svg xmlns="http://www.w3.org/2000/svg" width="'+u+'" height="'+l+'">'+(c?"<defs>"+c+"</defs>":"")+('<foreignObject width="'+n+'" height="'+r)+'" transform="scale('+i+')">'+f+"</foreignObject></svg>",[2,t.loadImage("data:image/svg+xml;charset=utf-8,"+encodeURIComponent(h))]}})})).apply(this,arguments)}var D=new Set(["foreignobject","script","iframe","object","embed","link","base","meta","template","noscript"]),I=new Set(["href","src","action","formaction"]),M=["javascript","vbscript"],k=["data:image/","data:font/","data:application/font","data:application/x-font"];function L(e){return e.replace(/&#x([0-9a-fA-F]+);?/g,function(e,t){return String.fromCharCode(parseInt(t,16))}).replace(/&#(\d+);?/g,function(e,t){return String.fromCharCode(parseInt(t,10))}).replace(/&([a-zA-Z]+);/gi,function(e,t){var n;return null!=(n=({amp:"&",lt:"<",gt:">",quot:'"',apos:"'",colon:":",semi:";",tab:" ",newline:"\n",nbsp:"\xa0"})[t.toLowerCase()])?n:e})}function j(e){for(var t="",n=0,r=e.length;n<r;){if(60!==e.charCodeAt(n)){t+=e[n++];continue}var i=e.charCodeAt(n+1),o=i>=65&&i<=90||i>=97&&i<=122,a=e.charCodeAt(n+2),s=47===i&&(a>=65&&a<=90||a>=97&&a<=122);if(!o&&!s){t+=e[n++];continue}for(var c=s?n+2:n+1,u=c;u<r;){var l=e.charCodeAt(u);if(32===l||9===l||10===l||13===l||47===l||62===l)break;u++}for(var f=e.slice(c,u).toLowerCase(),h=Math.min(r,u+16e3),d=-1,p=!1,g=!1,v=u;v<h;v++){var m=e.charCodeAt(v);if(34!==m||g){if(39!==m||p){if(62===m&&!p&&!g){d=v;break}}else g=!g}else p=!p}if(-1===d){t+=e[n++];continue}if(D.has(f)){t+="<"+e.slice(n+1,d)+">",n=d+1;continue}t+=e.slice(n,u)+function(e){for(var t="",n=0,r=e.length;n<r;){var i=e.charCodeAt(n);if(32===i||9===i||10===i||13===i||47===i){t+=e[n++];continue}for(var o=n;n<r;){var a=e.charCodeAt(n);if(61===a||32===a||9===a||10===a||13===a||47===a||62===a)break;n++}if(n===o){t+=e[n++];continue}for(var s=e.slice(o,n).toLowerCase(),c=n;c<r&&/\s/.test(e[c]);)c++;var u=c,l=null,f=!1;if("="===e[c]){for(f=!0,c++;c<r&&/\s/.test(e[c]);)c++;var h=e[c];if('"'===h||"'"===h){var d=e.indexOf(h,c+1);if(-1===d)return t+e.slice(o);l=e.slice(c+1,d),u=d+1}else{for(var p=c;p<r&&!/[\s>]/.test(e[p]);)p++;l=e.slice(c,p),u=p}}var g=s.length>2&&111===s.charCodeAt(0)&&110===s.charCodeAt(1),v=f&&null!==l&&I.has(s)&&function(e){var t=function(e){var t=L(e);try{t=decodeURIComponent(t)}catch(e){}return(t=(t=t.replace(/[\u0000-\u001f\u007f\s]+/g,"")).toLowerCase()).replace(/^[^a-z]+/,"")}(e);return!!M.some(function(e){return t.startsWith(""+e+":")})||!!t.startsWith("data:")&&!k.some(function(e){return t.startsWith(e)})}(l);if(g||v){n=u;continue}t+=e.slice(o,u),n=u}return t}(e.slice(u,d))+">",n=d+1}return t}function E(e){return P.apply(this,arguments)}function P(){return(P=f(function(e){var n,r,i,o,a,s,c;return p(this,function(u){switch(u.label){case 0:for(x(e,y,["src"],n=new Set),x(e,w,["src","poster"],n),r=new Set,i=d(n);!(o=i()).done;)(a=o.value)&&!T(a)&&r.add(a);if(!function(e,t){var n=[];if("undefined"!=typeof DOMParser)try{var r=new DOMParser().parseFromString(e,"text/html");r.querySelectorAll("style").forEach(function(e){e.textContent&&n.push(e.textContent)}),r.querySelectorAll("[style]").forEach(function(e){var t=e.getAttribute("style");t&&n.push(t)})}catch(e){}if(0===n.length){!function(e,t){for(var n=e.toLowerCase(),r=0,i=e.length;r<i;){var o=n.indexOf("<style",r);if(-1===o)break;var a=n.charCodeAt(o+6);if(!(32===a||9===a||10===a||13===a||62===a||47===a)){r=o+6;continue}var s=n.indexOf(">",o+6);if(-1===s)break;var c=s+1,u=n.indexOf("</style",c);if(-1===u)break;t.push(e.slice(c,u));var l=n.indexOf(">",u);if(-1===l)break;r=l+1}}(e,n);var i=new Set;x(e,null,["style"],i);for(var o,a=d(i);!(o=a()).done;){var s=o.value;n.push(s)}}for(var c,u=d(n);!(c=u()).done;){var l=c.value;b.lastIndex=0;for(var f=void 0;null!==(f=b.exec(l));){var h,p,g=null!=(p=null!=(h=f[1])?h:f[2])?p:f[3];!g||T(g)||g.startsWith("#")||t.add(g)}}}(e,r),0===r.size)return[2,e];return s=new Map,c=[].concat(r).slice(0,U),r.size>U&&t.logger.warn("inlineImageSources: URL count ("+r.size+") exceeds limit ("+U+"), only processing first "+U+"."),[4,B(c.map(function(e){return f(function(){var n,r,i,o;return p(this,function(a){switch(a.label){case 0:n=L(e),a.label=1;case 1:return a.trys.push([1,3,,4]),r=s.set,i=[e],[4,N(n)];case 2:return r.apply(s,i.concat([a.sent()])),[3,4];case 3:return o=a.sent(),t.logger.warn('inlineImageSources: Failed to fetch "'+n+'". '+W,o),[3,4];case 4:return[2]}})})}),G)];case 1:return u.sent(),[2,_(e,s)]}})})).apply(this,arguments)}function R(e){return F.apply(this,arguments)}function F(){return(F=f(function(e){var n,r,i,o,a,s,c,u,l,h;return p(this,function(g){switch(g.label){case 0:for(n=new Set,r=d(function(e){for(var t,n=[],r=/@font-face\s*\{/gi;null!==(t=r.exec(e));){for(var i=t.index+t[0].length,o=1,a=i;a<e.length&&a<i+8e3;a++)if("{"===e[a])o++;else if("}"===e[a]&&0==--o)break;n.push(e.slice(t.index,a+1)),r.lastIndex=a+1}return n}(e));!(i=r()).done;)for(o=i.value,C.lastIndex=0,a=void 0;null!==(a=C.exec(o));)(u=null!=(c=null!=(s=a[1])?s:a[2])?c:a[3])&&!T(u)&&n.add(u);if(0===n.size)return[2,e];return l=new Map,h=[].concat(n).slice(0,U),n.size>U&&t.logger.warn("inlineFontSources: URL count ("+n.size+") exceeds limit ("+U+"), only processing first "+U+"."),[4,B(h.map(function(e){return f(function(){var n,r,i,o;return p(this,function(a){switch(a.label){case 0:n=L(e),a.label=1;case 1:return a.trys.push([1,3,,4]),r=l.set,i=[e],[4,N(n)];case 2:return r.apply(l,i.concat([a.sent()])),[3,4];case 3:return o=a.sent(),t.logger.warn('inlineFontSources: Failed to fetch font "'+n+'". '+W,o),[3,4];case 4:return[2]}})})}),G)];case 1:return g.sent(),[2,_(e,l)]}})})).apply(this,arguments)}function _(e,t){return(function(e,t,n,r){if(0===r.size)return e;for(var i=n.map(function(e){return e.toLowerCase()}),o="",a=0,s=e.length;a<s;){var c=e.indexOf("<",a);if(-1===c){o+=e.slice(a);break}var u=e.charCodeAt(c+1);if(!(u>=65&&u<=90||u>=97&&u<=122)){o+=e.slice(a,c+1),a=c+1;continue}for(var l=c+1;l<s;){var f=e.charCodeAt(l);if(32===f||9===f||10===f||13===f||47===f||62===f)break;l++}var h=e.slice(c+1,l).toLowerCase();if(!t.has(h)){o+=e.slice(a,l),a=l;continue}for(var d=Math.min(s,l+16e3),p=-1,g=!1,v=!1,m=l;m<d;m++){var y=e.charCodeAt(m);if(34!==y||v){if(39!==y||g){if(62===y&&!g&&!v){p=m;break}}else v=!v}else g=!g}if(-1===p){o+=e.slice(a,c+1),a=c+1;continue}o+=e.slice(a,l)+function(e,t,n){for(var r="",i=0,o=e.length;i<o;){var a=e.charCodeAt(i);if(32===a||9===a||10===a||13===a||47===a){r+=e[i++];continue}for(var s=i;i<o;){var c=e.charCodeAt(i);if(61===c||32===c||9===c||10===c||13===c||47===c||62===c)break;i++}if(i===s){r+=e[i++];continue}for(var u=e.slice(s,i).toLowerCase(),l=i;l<o&&/\s/.test(e[l]);)l++;if("="!==e[l]){r+=e.slice(s,l),i=l;continue}for(l++;l<o&&/\s/.test(e[l]);)l++;var f=l,h=l,d=l,p=null;if('"'===e[l]||"'"===e[l]){p=e[l];var g=e.indexOf(p,l+1);if(-1===g)return r+e.slice(s);f=l+1,h=g,d=g+1}else{for(var v=l;v<o&&!/[\s>]/.test(e[v]);)v++;f=l,h=v,d=v}var m=e.slice(f,h);if(t.includes(u)){var y=n.get(m);if(y){null===p?r+=e.slice(s,f)+'"'+y+'"':r+=e.slice(s,f)+y+p,i=d;continue}}r+=e.slice(s,d),i=d}return r}(e.slice(l,p),i,r)+">",a=p+1}return o})(e,new Set(["img","video","source","input","audio"]),["src","poster"],t).replace(/url\(\s*(["'])([^"'\n\r)]*)\1\s*\)/g,function(e,n,r){var i=t.get(r);return i?"url("+n+i+n+")":e}).replace(/url\(\s*([^\s)"'\n\r]+)\s*\)/g,function(e,n){var r=t.get(n);return r?"url("+r+")":e})}function z(e){if("undefined"==typeof document)return"";var n=function(e){for(var t="",n=0,r=e.length,i=e.toLowerCase();n<r;){var o=i.indexOf("<svg",n);if(-1===o){t+=e.slice(n);break}var a=i.charCodeAt(o+4);if(!(32===a||9===a||10===a||13===a||62===a||47===a)){t+=e.slice(n,o+4),n=o+4;continue}t+=e.slice(n,o);var s=i.indexOf("</svg",o+4);if(-1===s)break;var c=i.indexOf(">",s);if(-1===c)break;n=c+1}return t}(e),r=new Set;for(A.lastIndex=0;null!==(i=A.exec(n));)r.add(i[1]);if(0===r.size)return"";for(var i,o,a=new XMLSerializer,s=[],c=d(r);!(o=c()).done;){var u=o.value,l=document.getElementById(u);if(!l){t.logger.warn("extractSVGDefs: #"+u+" not found.");continue}if(!m.has(l.tagName.toLowerCase())){t.logger.warn("extractSVGDefs: #"+u+" is not a supported SVG def element.");continue}s.push(a.serializeToString(l))}return s.join("")}var G=6,U=100,W="可能原因: (1) 资源服务器未开启 CORS(需 Access-Control-Allow-Origin 响应头); (2) URL 不可访问 (404 / 403); (3) 网络异常。";function B(e,t){return V.apply(this,arguments)}function V(){return(V=f(function(e,t){var n,r;function i(){return(i=f(function(){var t;return p(this,function(i){switch(i.label){case 0:if(!(r<e.length))return[3,2];return[4,e[t=r++]()];case 1:return n[t]=i.sent(),[3,0];case 2:return[2]}})})).apply(this,arguments)}return p(this,function(o){switch(o.label){case 0:return n=Array(e.length),r=0,[4,Promise.all(Array.from({length:Math.min(t,e.length)},function(){return function(){return i.apply(this,arguments)}()}))];case 1:return o.sent(),[2,n]}})})).apply(this,arguments)}function N(e){return q.apply(this,arguments)}function q(){return(q=f(function(e){var n;return p(this,function(r){switch(r.label){case 0:return[4,t.loadBlob(e)];case 1:if((n=r.sent()).size>10485760)throw Error('fetchAsBase64: Resource "'+e+'" exceeds max size (10485760 bytes), actual: '+n.size+".");return[2,new Promise(function(e,t){var r=new FileReader;r.onloadend=function(){e(r.result)},r.onerror=function(){t(Error("FileReader failed."))},r.readAsDataURL(n)})]}})})).apply(this,arguments)}var H=1/255;e.DomContentComponent=function(e){function n(t){var n;return(n=e.call(this,t)||this).htmlContent="",n.contentWidth=300,n.contentHeight=200,n.contentScale=1,n.rendering=!1,n.asyncCancelled=!1,n.targetComponent=null,n.renderVersion=0,n.ownedTextures=new Set,n.originalTargetTexture=null,n.isDirty=!1,n.canvas=document.createElement("canvas"),n.context=n.canvas.getContext("2d",{willReadFrequently:!0}),n}i(n,e);var r=n.prototype;return r.setContent=function(e,n,r,i){if("string"!=typeof e){t.logger.warn("DomContentComponent.setContent: html must be a string, ignored.");return}e.length>1048576?(t.logger.warn("DomContentComponent.setContent: html length ("+e.length+") exceeds limit (1048576), truncated."),this.htmlContent=e.slice(0,1048576)):this.htmlContent=e,void 0!==n&&(this.contentWidth=Math.max(0,n)),void 0!==r&&(this.contentHeight=Math.max(0,r)),void 0!==i&&(this.contentScale=Math.max(0,i)),this.isDirty=!0,this.renderVersion++},r.onAwake=function(){if(this.material.setColor("_Color",new t.math.Color(1,1,1,1)),this.item)for(var e,n=d(this.item.getComponents(t.MaskableGraphic));!(e=n()).done;){var r=e.value;if(r!==this){this.targetComponent=r,t.logger.info("DomContentComponent: Bound to "+r.constructor.name+", overriding texture.");break}}},r.onUpdate=function(n){e.prototype.onUpdate.call(this,n),this.isDirty&&!this.rendering&&(this.isDirty=!1,this.updateTexture().catch(function(e){t.logger.error("DomContentComponent: Unhandled error in updateTexture.",e)}))},r.render=function(t){this.targetComponent||e.prototype.render.call(this,t)},r.onDestroy=function(){e.prototype.onDestroy.call(this),this.asyncCancelled=!0,this.disposeOwnTexture(),(null==(t=this.targetComponent)?void 0:t.renderer)&&this.originalTargetTexture&&this.targetComponent.setTexture(this.originalTargetTexture);for(var t,n,r=d(this.ownedTextures);!(n=r()).done;)n.value.dispose();this.ownedTextures.clear(),this.originalTargetTexture=null,this.canvas&&(this.canvas.width=1,this.canvas.height=1),this.targetComponent=null},r.disposeOwnTexture=function(){var e=this.renderer.texture;e&&e!==this.engine.whiteTexture&&e.dispose()},r.renderImageToTexture=function(e,n,r,i){if(this.context&&this.canvas){var o=this.context;o.save(),this.canvas.width=e,this.canvas.height=n,o.setTransform(1,0,0,1,0,0),r||(o.translate(0,n),o.scale(1,-1)),o.clearRect(0,0,e,n),o.fillStyle="rgba(255, 255, 255, "+H+")",i(o),o.restore();var a=o.getImageData(0,0,e,n),s=t.Texture.createWithData(this.engine,{data:new Uint8Array(a.data),width:a.width,height:a.height},{flipY:r,magFilter:t.glContext.LINEAR,minFilter:t.glContext.LINEAR,wrapS:t.glContext.CLAMP_TO_EDGE,wrapT:t.glContext.CLAMP_TO_EDGE});this.disposeOwnTexture(),this.renderer.texture=s,this.material.setTexture("_MainTex",s),this.ownedTextures.add(s)}},r.updateTexture=function(){var e=this;return f(function(){var n,r,i,o,a,s,c,u,l,f,h;return p(this,function(d){switch(d.label){case 0:if(n=e.renderVersion,r=e.htmlContent,i=e.contentWidth,o=e.contentHeight,a=e.contentScale,!r||i<=0||o<=0)return[2];if(a<=0)return t.logger.warn("DomContentComponent: contentScale must be positive, skipping render."),[2];u=Math.min((s=Math.min(Math.round(i*a),2048))/i,(c=Math.min(Math.round(o*a),2048))/o),e.rendering=!0,d.label=1;case 1:return d.trys.push([1,3,4,5]),[4,O(r,i,o,u)];case 2:if(l=d.sent(),e.asyncCancelled||n!==e.renderVersion)return[2];return e.targetComponent?e.updateTargetTexture(l,s,c):e.renderImageToTexture(s,c,!0,function(e){e.drawImage(l,0,0,s,c)}),[3,5];case 3:return f=d.sent(),t.logger.error("DomContentComponent: Failed to render texture.",f),[3,5];case 4:return e.rendering=!1,e.isDirty&&!e.asyncCancelled&&(h=e.isDirty,e.isDirty=!1,h&&e.updateTexture().catch(function(e){t.logger.error("DomContentComponent: Unhandled error in updateTexture.",e)})),[7];case 5:return[2]}})})()},r.updateTargetTexture=function(e,n,r){if(this.canvas&&this.context&&this.targetComponent){var i=this.context,o=this.targetComponent;if(!o.renderer){t.logger.warn("DomContentComponent: targetComponent.renderer is null, skipping texture update.");return}var a=o.renderer.texture;null===this.originalTargetTexture&&(this.originalTargetTexture=null!=a?a:null),a&&this.ownedTextures.has(a)&&(a.dispose(),this.ownedTextures.delete(a)),i.save(),this.canvas.width=n,this.canvas.height=r,i.setTransform(1,0,0,1,0,0),i.clearRect(0,0,n,r),i.drawImage(e,0,0,n,r),i.restore();var s=i.getImageData(0,0,n,r),c=t.Texture.createWithData(this.engine,{data:new Uint8Array(s.data),width:s.width,height:s.height},{flipY:!0,magFilter:t.glContext.LINEAR,minFilter:t.glContext.LINEAR,wrapS:t.glContext.CLAMP_TO_EDGE,wrapT:t.glContext.CLAMP_TO_EDGE});this.ownedTextures.add(c),o.setTexture(c)}},n}(t.MaskableGraphic),e.DomContentComponent=function(e,t,n,r){var i,o=arguments.length,a=o<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(a=(o<3?i(a):o>3?i(t,n,a):i(t,n))||a);return o>3&&a&&Object.defineProperty(t,n,a),a}([t.effectsClass("DomContentComponent")],e.DomContentComponent);var X="2.9.3";t.registerPlugin("dom-content",u),t.logger.info("Plugin dom-content version: "+X+"."),X!==n.version&&console.error("注意:请统一 DomContent 插件与 Player 版本,不统一的版本混用会有不可预知的后果!","\nAttention: Please ensure the DomContent plugin is synchronized with the Player version. Mixing and matching incompatible versions may result in unpredictable consequences!"),e.DomContentLoader=u,e.extractSVGDefs=z,e.inlineFontSources=R,e.inlineImageSources=E,e.renderDOMToImage=O,e.sanitizeSVGContent=function(e){return j(e)},e.version=X,Object.defineProperty(e,"__esModule",{value:!0})});
|
|
6
|
+
* Version: v2.9.4
|
|
7
|
+
*/function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@galacean/effects")):"function"==typeof define&&define.amd?define(["exports","@galacean/effects"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).ge=e.ge||{},e.ge.domContentPlugin={}),e.ge)}(this,function(e,t){"use strict";var n=function(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}}),t.default=e,Object.freeze(t)}(t);function r(e,t){return(r=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function i(e,t){if("function"!=typeof t&&null!==t)throw TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&r(e,t)}function o(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(o=function(){return!!e})()}function a(e,t,n){return(a=o()?Reflect.construct:function(e,t,n){var i=[null];i.push.apply(i,t);var o=new(Function.bind.apply(e,i));return n&&r(o,n.prototype),o}).apply(null,arguments)}function s(e){return(s=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function u(e){var t="function"==typeof Map?new Map:void 0;return(u=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return a(e,arguments,s(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),r(n,e)})(e)}var c=function(e){function t(){var t;return t=e.apply(this,arguments)||this,t.name="dom-content",t}return i(t,e),t}(u(t.Plugin));function l(e,t,n,r,i,o,a){try{var s=e[o](a),u=s.value}catch(e){n(e);return}s.done?t(u):Promise.resolve(u).then(r,i)}function f(e){return function(){var t=this,n=arguments;return new Promise(function(r,i){var o=e.apply(t,n);function a(e){l(o,r,i,a,s,"next",e)}function s(e){l(o,r,i,a,s,"throw",e)}a(void 0)})}}function h(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function d(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return h(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return h(e,void 0)}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function p(e,t){var n,r,i,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return a.next=s(0),a.throw=s(1),a.return=s(2),"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(s){return function(u){return function(s){if(n)throw TypeError("Generator is already executing.");for(;a&&(a=0,s[0]&&(o=0)),o;)try{if(n=1,r&&(i=2&s[0]?r.return:s[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,s[1])).done)return i;switch(r=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return o.label++,{value:s[1],done:!1};case 5:o.label++,r=s[1],s=[0];continue;case 7:s=o.ops.pop(),o.trys.pop();continue;default:if(!(i=(i=o.trys).length>0&&i[i.length-1])&&(6===s[0]||2===s[0])){o=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){o.label=s[1];break}if(6===s[0]&&o.label<i[1]){o.label=i[1],i=s;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(s);break}i[2]&&o.ops.pop(),o.trys.pop();continue}s=t.call(e,o)}catch(e){s=[6,e],r=0}finally{n=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,u])}}}function g(){return(g=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}"function"==typeof SuppressedError&&SuppressedError;var v={inlineFonts:!0,inlineImages:!0,extractDefs:!0},m=new Set(["filter","clippath","mask","lineargradient","radialgradient","pattern","marker"]),y=new Set(["img"]),w=new Set(["video","source","input","audio"]),b=/url\(\s*(?:"([^"]+)"|'([^']+)'|([^\s)"']+))\s*\)/gi;function x(e,t,n,r){for(var i=0,o=e.length;i<o;){var a=e.indexOf("<",i);if(-1===a)break;var s=e.charCodeAt(a+1);if(!(s>=65&&s<=90||s>=97&&s<=122)){i=a+1;continue}for(var u=a+1;u<o;){var c=e.charCodeAt(u);if(32===c||9===c||10===c||13===c||47===c||62===c)break;u++}var l=e.slice(a+1,u).toLowerCase();if(null!==t&&!t.has(l)){i=u;continue}for(var f=Math.min(o,u+16e3),h=-1,p=!1,g=!1,v=u;v<f;v++){var m=e.charCodeAt(v);if(34!==m||g){if(39!==m||p){if(62===m&&!p&&!g){h=v;break}}else g=!g}else p=!p}if(-1===h){i=u;continue}for(var y,w=e.slice(u,h),b=d(n);!(y=b()).done;)!function(e,t,n){for(var r=e.toLowerCase(),i=t.toLowerCase(),o=0;o<r.length;){var a=r.indexOf(i,o);if(-1===a)return;var s=0===a?32:r.charCodeAt(a-1);if(!(32===s||9===s||10===s||13===s)){o=a+i.length;continue}for(var u=a+i.length;u<e.length&&/\s/.test(e[u]);)u++;if("="!==e[u]){o=a+i.length;continue}for(u++;u<e.length&&/\s/.test(e[u]);)u++;var c="",l=e[u];if('"'===l||"'"===l){var f=e.indexOf(l,u+1);if(-1===f)return;c=e.slice(u+1,f)}else{for(var h=u;h<e.length&&!/[\s>]/.test(e[h]);)h++;c=e.slice(u,h)}c&&n.add(c);return}}(w,y.value,r);i=h+1}}var C=/url\(\s*(?:"([^"]+)"|'([^']+)'|([^\s)"']+))\s*\)/gi,A=/url\(\s*(?:"|')?#([a-zA-Z][\w.-]*)(?:"|')?\s*\)/g,T=function(e){return e.startsWith("data:")||e.startsWith("blob:")};function O(e,t,n){return S.apply(this,arguments)}function S(){return(S=f(function(e,n,r,i,o){var a,s,u,c,l,f,h;return p(this,function(d){switch(d.label){case 0:if(void 0===i&&(i=1),!Number.isFinite(n)||!Number.isFinite(r)||!Number.isFinite(i)||n<=0||r<=0||i<0)throw Error("renderDOMToImage: width and height must be positive, scale must be non-negative.");if(0===i)return t.logger.warn("renderDOMToImage: scale is 0, skipping render."),[2,t.loadImage("data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7")];if(a=g({},v,o),s=j(e),!a.inlineFonts)return[3,2];return[4,R(s)];case 1:s=d.sent(),d.label=2;case 2:if(!a.inlineImages)return[3,4];return[4,E(s)];case 3:s=d.sent(),d.label=4;case 4:return u=a.extractDefs?z(s):"",c=n*i,l=r*i,f=function(e){if("undefined"==typeof document)return'<div xmlns="http://www.w3.org/1999/xhtml">'+e+"</div>";var t=document.implementation.createHTMLDocument("").createElement("div");return t.innerHTML=e,t.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),new XMLSerializer().serializeToString(t)}(function(e){for(var t="",n=0,r=e.length,i=e.toLowerCase();n<r;){var o=i.indexOf("<svg",n);if(-1===o){t+=e.slice(n);break}var a=i.charCodeAt(o+4);if(!(32===a||9===a||10===a||13===a||62===a||47===a)){t+=e.slice(n,o+4),n=o+4;continue}var s=i.indexOf(">",o+4);if(-1===s){t+=e.slice(n);break}var u=i.slice(o,s),c=/[\s][\s]*xmlns\s*=/i.test(" "+u);t+=e.slice(n,o+4),c||(t+=' xmlns="http://www.w3.org/2000/svg"'),t+=e.slice(o+4,s+1),n=s+1}return t}(s)),h='<svg xmlns="http://www.w3.org/2000/svg" width="'+c+'" height="'+l+'">'+(u?"<defs>"+u+"</defs>":"")+('<foreignObject width="'+n+'" height="'+r)+'" transform="scale('+i+')">'+f+"</foreignObject></svg>",[2,t.loadImage("data:image/svg+xml;charset=utf-8,"+encodeURIComponent(h))]}})})).apply(this,arguments)}var D=new Set(["foreignobject","script","iframe","object","embed","link","base","meta","template","noscript"]),I=new Set(["href","src","action","formaction"]),M=["javascript","vbscript"],k=["data:image/","data:font/","data:application/font","data:application/x-font"];function L(e){return e.replace(/&#x([0-9a-fA-F]+);?/g,function(e,t){return String.fromCharCode(parseInt(t,16))}).replace(/&#(\d+);?/g,function(e,t){return String.fromCharCode(parseInt(t,10))}).replace(/&([a-zA-Z]+);/gi,function(e,t){var n;return null!=(n=({amp:"&",lt:"<",gt:">",quot:'"',apos:"'",colon:":",semi:";",tab:" ",newline:"\n",nbsp:"\xa0"})[t.toLowerCase()])?n:e})}function j(e){for(var t="",n=0,r=e.length;n<r;){if(60!==e.charCodeAt(n)){t+=e[n++];continue}var i=e.charCodeAt(n+1),o=i>=65&&i<=90||i>=97&&i<=122,a=e.charCodeAt(n+2),s=47===i&&(a>=65&&a<=90||a>=97&&a<=122);if(!o&&!s){t+=e[n++];continue}for(var u=s?n+2:n+1,c=u;c<r;){var l=e.charCodeAt(c);if(32===l||9===l||10===l||13===l||47===l||62===l)break;c++}for(var f=e.slice(u,c).toLowerCase(),h=Math.min(r,c+16e3),d=-1,p=!1,g=!1,v=c;v<h;v++){var m=e.charCodeAt(v);if(34!==m||g){if(39!==m||p){if(62===m&&!p&&!g){d=v;break}}else g=!g}else p=!p}if(-1===d){t+=e[n++];continue}if(D.has(f)){t+="<"+e.slice(n+1,d)+">",n=d+1;continue}t+=e.slice(n,c)+function(e){for(var t="",n=0,r=e.length;n<r;){var i=e.charCodeAt(n);if(32===i||9===i||10===i||13===i||47===i){t+=e[n++];continue}for(var o=n;n<r;){var a=e.charCodeAt(n);if(61===a||32===a||9===a||10===a||13===a||47===a||62===a)break;n++}if(n===o){t+=e[n++];continue}for(var s=e.slice(o,n).toLowerCase(),u=n;u<r&&/\s/.test(e[u]);)u++;var c=u,l=null,f=!1;if("="===e[u]){for(f=!0,u++;u<r&&/\s/.test(e[u]);)u++;var h=e[u];if('"'===h||"'"===h){var d=e.indexOf(h,u+1);if(-1===d)return t+e.slice(o);l=e.slice(u+1,d),c=d+1}else{for(var p=u;p<r&&!/[\s>]/.test(e[p]);)p++;l=e.slice(u,p),c=p}}var g=s.length>2&&111===s.charCodeAt(0)&&110===s.charCodeAt(1),v=f&&null!==l&&I.has(s)&&function(e){var t=function(e){var t=L(e);try{t=decodeURIComponent(t)}catch(e){}return(t=(t=t.replace(/[\u0000-\u001f\u007f\s]+/g,"")).toLowerCase()).replace(/^[^a-z]+/,"")}(e);return!!M.some(function(e){return t.startsWith(""+e+":")})||!!t.startsWith("data:")&&!k.some(function(e){return t.startsWith(e)})}(l);if(g||v){n=c;continue}t+=e.slice(o,c),n=c}return t}(e.slice(c,d))+">",n=d+1}return t}function E(e){return P.apply(this,arguments)}function P(){return(P=f(function(e){var n,r,i,o,a,s,u;return p(this,function(c){switch(c.label){case 0:for(x(e,y,["src"],n=new Set),x(e,w,["src","poster"],n),r=new Set,i=d(n);!(o=i()).done;)(a=o.value)&&!T(a)&&r.add(a);if(!function(e,t){var n=[];if("undefined"!=typeof DOMParser)try{var r=new DOMParser().parseFromString(e,"text/html");r.querySelectorAll("style").forEach(function(e){e.textContent&&n.push(e.textContent)}),r.querySelectorAll("[style]").forEach(function(e){var t=e.getAttribute("style");t&&n.push(t)})}catch(e){}if(0===n.length){!function(e,t){for(var n=e.toLowerCase(),r=0,i=e.length;r<i;){var o=n.indexOf("<style",r);if(-1===o)break;var a=n.charCodeAt(o+6);if(!(32===a||9===a||10===a||13===a||62===a||47===a)){r=o+6;continue}var s=n.indexOf(">",o+6);if(-1===s)break;var u=s+1,c=n.indexOf("</style",u);if(-1===c)break;t.push(e.slice(u,c));var l=n.indexOf(">",c);if(-1===l)break;r=l+1}}(e,n);var i=new Set;x(e,null,["style"],i);for(var o,a=d(i);!(o=a()).done;){var s=o.value;n.push(s)}}for(var u,c=d(n);!(u=c()).done;){var l=u.value;b.lastIndex=0;for(var f=void 0;null!==(f=b.exec(l));){var h,p,g=null!=(p=null!=(h=f[1])?h:f[2])?p:f[3];!g||T(g)||g.startsWith("#")||t.add(g)}}}(e,r),0===r.size)return[2,e];return s=new Map,u=Array.from(r).slice(0,U),r.size>U&&t.logger.warn("inlineImageSources: URL count ("+r.size+") exceeds limit ("+U+"), only processing first "+U+"."),[4,B(u.map(function(e){return f(function(){var n,r,i,o;return p(this,function(a){switch(a.label){case 0:n=L(e),a.label=1;case 1:return a.trys.push([1,3,,4]),r=s.set,i=[e],[4,N(n)];case 2:return r.apply(s,i.concat([a.sent()])),[3,4];case 3:return o=a.sent(),t.logger.warn('inlineImageSources: Failed to fetch "'+n+'". '+W,o),[3,4];case 4:return[2]}})})}),G)];case 1:return c.sent(),[2,_(e,s)]}})})).apply(this,arguments)}function R(e){return F.apply(this,arguments)}function F(){return(F=f(function(e){var n,r,i,o,a,s,u,c,l,h;return p(this,function(g){switch(g.label){case 0:for(n=new Set,r=d(function(e){for(var t,n=[],r=/@font-face\s*\{/gi;null!==(t=r.exec(e));){for(var i=t.index+t[0].length,o=1,a=i;a<e.length&&a<i+8e3;a++)if("{"===e[a])o++;else if("}"===e[a]&&0==--o)break;n.push(e.slice(t.index,a+1)),r.lastIndex=a+1}return n}(e));!(i=r()).done;)for(o=i.value,C.lastIndex=0,a=void 0;null!==(a=C.exec(o));)(c=null!=(u=null!=(s=a[1])?s:a[2])?u:a[3])&&!T(c)&&n.add(c);if(0===n.size)return[2,e];return l=new Map,h=Array.from(n).slice(0,U),n.size>U&&t.logger.warn("inlineFontSources: URL count ("+n.size+") exceeds limit ("+U+"), only processing first "+U+"."),[4,B(h.map(function(e){return f(function(){var n,r,i,o;return p(this,function(a){switch(a.label){case 0:n=L(e),a.label=1;case 1:return a.trys.push([1,3,,4]),r=l.set,i=[e],[4,N(n)];case 2:return r.apply(l,i.concat([a.sent()])),[3,4];case 3:return o=a.sent(),t.logger.warn('inlineFontSources: Failed to fetch font "'+n+'". '+W,o),[3,4];case 4:return[2]}})})}),G)];case 1:return g.sent(),[2,_(e,l)]}})})).apply(this,arguments)}function _(e,t){return(function(e,t,n,r){if(0===r.size)return e;for(var i=n.map(function(e){return e.toLowerCase()}),o="",a=0,s=e.length;a<s;){var u=e.indexOf("<",a);if(-1===u){o+=e.slice(a);break}var c=e.charCodeAt(u+1);if(!(c>=65&&c<=90||c>=97&&c<=122)){o+=e.slice(a,u+1),a=u+1;continue}for(var l=u+1;l<s;){var f=e.charCodeAt(l);if(32===f||9===f||10===f||13===f||47===f||62===f)break;l++}var h=e.slice(u+1,l).toLowerCase();if(!t.has(h)){o+=e.slice(a,l),a=l;continue}for(var d=Math.min(s,l+16e3),p=-1,g=!1,v=!1,m=l;m<d;m++){var y=e.charCodeAt(m);if(34!==y||v){if(39!==y||g){if(62===y&&!g&&!v){p=m;break}}else v=!v}else g=!g}if(-1===p){o+=e.slice(a,u+1),a=u+1;continue}o+=e.slice(a,l)+function(e,t,n){for(var r="",i=0,o=e.length;i<o;){var a=e.charCodeAt(i);if(32===a||9===a||10===a||13===a||47===a){r+=e[i++];continue}for(var s=i;i<o;){var u=e.charCodeAt(i);if(61===u||32===u||9===u||10===u||13===u||47===u||62===u)break;i++}if(i===s){r+=e[i++];continue}for(var c=e.slice(s,i).toLowerCase(),l=i;l<o&&/\s/.test(e[l]);)l++;if("="!==e[l]){r+=e.slice(s,l),i=l;continue}for(l++;l<o&&/\s/.test(e[l]);)l++;var f=l,h=l,d=l,p=null;if('"'===e[l]||"'"===e[l]){p=e[l];var g=e.indexOf(p,l+1);if(-1===g)return r+e.slice(s);f=l+1,h=g,d=g+1}else{for(var v=l;v<o&&!/[\s>]/.test(e[v]);)v++;f=l,h=v,d=v}var m=e.slice(f,h);if(t.includes(c)){var y=n.get(m);if(y){null===p?r+=e.slice(s,f)+'"'+y+'"':r+=e.slice(s,f)+y+p,i=d;continue}}r+=e.slice(s,d),i=d}return r}(e.slice(l,p),i,r)+">",a=p+1}return o})(e,new Set(["img","video","source","input","audio"]),["src","poster"],t).replace(/url\(\s*(["'])([^"'\n\r)]*)\1\s*\)/g,function(e,n,r){var i=t.get(r);return i?"url("+n+i+n+")":e}).replace(/url\(\s*([^\s)"'\n\r]+)\s*\)/g,function(e,n){var r=t.get(n);return r?"url("+r+")":e})}function z(e){if("undefined"==typeof document)return"";var n=function(e){for(var t="",n=0,r=e.length,i=e.toLowerCase();n<r;){var o=i.indexOf("<svg",n);if(-1===o){t+=e.slice(n);break}var a=i.charCodeAt(o+4);if(!(32===a||9===a||10===a||13===a||62===a||47===a)){t+=e.slice(n,o+4),n=o+4;continue}t+=e.slice(n,o);var s=i.indexOf("</svg",o+4);if(-1===s)break;var u=i.indexOf(">",s);if(-1===u)break;n=u+1}return t}(e),r=new Set;for(A.lastIndex=0;null!==(i=A.exec(n));)r.add(i[1]);if(0===r.size)return"";for(var i,o,a=new XMLSerializer,s=[],u=d(r);!(o=u()).done;){var c=o.value,l=document.getElementById(c);if(!l){t.logger.warn("extractSVGDefs: #"+c+" not found.");continue}if(!m.has(l.tagName.toLowerCase())){t.logger.warn("extractSVGDefs: #"+c+" is not a supported SVG def element.");continue}s.push(a.serializeToString(l))}return s.join("")}var G=6,U=100,W="可能原因: (1) 资源服务器未开启 CORS(需 Access-Control-Allow-Origin 响应头); (2) URL 不可访问 (404 / 403); (3) 网络异常。";function B(e,t){return V.apply(this,arguments)}function V(){return(V=f(function(e,t){var n,r;function i(){return(i=f(function(){var t;return p(this,function(i){switch(i.label){case 0:if(!(r<e.length))return[3,2];return[4,e[t=r++]()];case 1:return n[t]=i.sent(),[3,0];case 2:return[2]}})})).apply(this,arguments)}return p(this,function(o){switch(o.label){case 0:return n=Array(e.length),r=0,[4,Promise.all(Array.from({length:Math.min(t,e.length)},function(){return function(){return i.apply(this,arguments)}()}))];case 1:return o.sent(),[2,n]}})})).apply(this,arguments)}function N(e){return q.apply(this,arguments)}function q(){return(q=f(function(e){var n;return p(this,function(r){switch(r.label){case 0:return[4,t.loadBlob(e)];case 1:if((n=r.sent()).size>10485760)throw Error('fetchAsBase64: Resource "'+e+'" exceeds max size (10485760 bytes), actual: '+n.size+".");return[2,new Promise(function(e,t){var r=new FileReader;r.onloadend=function(){e(r.result)},r.onerror=function(){t(Error("FileReader failed."))},r.readAsDataURL(n)})]}})})).apply(this,arguments)}var H=1/255;e.DomContentComponent=function(e){function n(t){var n;return(n=e.call(this,t)||this).htmlContent="",n.contentWidth=300,n.contentHeight=200,n.contentScale=1,n.rendering=!1,n.asyncCancelled=!1,n.targetComponent=null,n.renderVersion=0,n.ownedTextures=new Set,n.originalTargetTexture=null,n.isDirty=!1,n.canvas=document.createElement("canvas"),n.context=n.canvas.getContext("2d",{willReadFrequently:!0}),n}i(n,e);var r=n.prototype;return r.setContent=function(e,n,r,i){if("string"!=typeof e){t.logger.warn("DomContentComponent.setContent: html must be a string, ignored.");return}e.length>1048576?(t.logger.warn("DomContentComponent.setContent: html length ("+e.length+") exceeds limit (1048576), truncated."),this.htmlContent=e.slice(0,1048576)):this.htmlContent=e,void 0!==n&&(this.contentWidth=Math.max(0,n)),void 0!==r&&(this.contentHeight=Math.max(0,r)),void 0!==i&&(this.contentScale=Math.max(0,i)),this.isDirty=!0,this.renderVersion++},r.onAwake=function(){if(this.material.setColor("_Color",new t.math.Color(1,1,1,1)),this.item)for(var e,n=d(this.item.getComponents(t.MaskableGraphic));!(e=n()).done;){var r=e.value;if(r!==this){this.targetComponent=r,t.logger.info("DomContentComponent: Bound to "+r.constructor.name+", overriding texture.");break}}},r.onUpdate=function(n){e.prototype.onUpdate.call(this,n),this.isDirty&&!this.rendering&&(this.isDirty=!1,this.updateTexture().catch(function(e){t.logger.error("DomContentComponent: Unhandled error in updateTexture.",e)}))},r.render=function(t){this.targetComponent||e.prototype.render.call(this,t)},r.onDestroy=function(){e.prototype.onDestroy.call(this),this.asyncCancelled=!0,this.disposeOwnTexture(),(null==(t=this.targetComponent)?void 0:t.renderer)&&this.originalTargetTexture&&this.targetComponent.setTexture(this.originalTargetTexture);for(var t,n,r=d(this.ownedTextures);!(n=r()).done;)n.value.dispose();this.ownedTextures.clear(),this.originalTargetTexture=null,this.canvas&&(this.canvas.width=1,this.canvas.height=1),this.targetComponent=null},r.disposeOwnTexture=function(){var e=this.renderer.texture;e&&e!==this.engine.whiteTexture&&e.dispose()},r.renderImageToTexture=function(e,n,r,i){if(this.context&&this.canvas){var o=this.context;o.save(),this.canvas.width=e,this.canvas.height=n,o.setTransform(1,0,0,1,0,0),r||(o.translate(0,n),o.scale(1,-1)),o.clearRect(0,0,e,n),o.fillStyle="rgba(255, 255, 255, "+H+")",i(o),o.restore();var a=o.getImageData(0,0,e,n),s=t.Texture.createWithData(this.engine,{data:new Uint8Array(a.data),width:a.width,height:a.height},{flipY:r,magFilter:t.glContext.LINEAR,minFilter:t.glContext.LINEAR,wrapS:t.glContext.CLAMP_TO_EDGE,wrapT:t.glContext.CLAMP_TO_EDGE});this.disposeOwnTexture(),this.renderer.texture=s,this.material.setTexture("_MainTex",s),this.ownedTextures.add(s)}},r.updateTexture=function(){var e=this;return f(function(){var n,r,i,o,a,s,u,c,l,f,h;return p(this,function(d){switch(d.label){case 0:if(n=e.renderVersion,r=e.htmlContent,i=e.contentWidth,o=e.contentHeight,a=e.contentScale,!r||i<=0||o<=0)return[2];if(a<=0)return t.logger.warn("DomContentComponent: contentScale must be positive, skipping render."),[2];c=Math.min((s=Math.min(Math.round(i*a),2048))/i,(u=Math.min(Math.round(o*a),2048))/o),e.rendering=!0,d.label=1;case 1:return d.trys.push([1,3,4,5]),[4,O(r,i,o,c)];case 2:if(l=d.sent(),e.asyncCancelled||n!==e.renderVersion)return[2];return e.targetComponent?e.updateTargetTexture(l,s,u):e.renderImageToTexture(s,u,!0,function(e){e.drawImage(l,0,0,s,u)}),[3,5];case 3:return f=d.sent(),t.logger.error("DomContentComponent: Failed to render texture.",f),[3,5];case 4:return e.rendering=!1,e.isDirty&&!e.asyncCancelled&&(h=e.isDirty,e.isDirty=!1,h&&e.updateTexture().catch(function(e){t.logger.error("DomContentComponent: Unhandled error in updateTexture.",e)})),[7];case 5:return[2]}})})()},r.updateTargetTexture=function(e,n,r){if(this.canvas&&this.context&&this.targetComponent){var i=this.context,o=this.targetComponent;if(!o.renderer){t.logger.warn("DomContentComponent: targetComponent.renderer is null, skipping texture update.");return}var a=o.renderer.texture;null===this.originalTargetTexture&&(this.originalTargetTexture=null!=a?a:null),a&&this.ownedTextures.has(a)&&(a.dispose(),this.ownedTextures.delete(a)),i.save(),this.canvas.width=n,this.canvas.height=r,i.setTransform(1,0,0,1,0,0),i.clearRect(0,0,n,r),i.drawImage(e,0,0,n,r),i.restore();var s=i.getImageData(0,0,n,r),u=t.Texture.createWithData(this.engine,{data:new Uint8Array(s.data),width:s.width,height:s.height},{flipY:!0,magFilter:t.glContext.LINEAR,minFilter:t.glContext.LINEAR,wrapS:t.glContext.CLAMP_TO_EDGE,wrapT:t.glContext.CLAMP_TO_EDGE});this.ownedTextures.add(u),o.setTexture(u)}},n}(t.MaskableGraphic),e.DomContentComponent=function(e,t,n,r){var i,o=arguments.length,a=o<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(i=e[s])&&(a=(o<3?i(a):o>3?i(t,n,a):i(t,n))||a);return o>3&&a&&Object.defineProperty(t,n,a),a}([t.effectsClass("DomContentComponent")],e.DomContentComponent);var X="2.9.4";t.registerPlugin("dom-content",c),t.logger.info("Plugin dom-content version: "+X+"."),X!==n.version&&console.error("注意:请统一 DomContent 插件与 Player 版本,不统一的版本混用会有不可预知的后果!","\nAttention: Please ensure the DomContent plugin is synchronized with the Player version. Mixing and matching incompatible versions may result in unpredictable consequences!"),e.DomContentLoader=c,e.extractSVGDefs=z,e.inlineFontSources=R,e.inlineImageSources=E,e.renderDOMToImage=O,e.sanitizeSVGContent=function(e){return j(e)},e.version=X,Object.defineProperty(e,"__esModule",{value:!0})});
|
|
8
8
|
//# sourceMappingURL=index.min.js.map
|