mirror of
https://github.com/tenrok/vue-meta.git
synced 2026-06-19 05:50:34 +03:00
2 lines
12 KiB
JavaScript
2 lines
12 KiB
JavaScript
import e from"deepmerge";function n(e){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function t(e){return Array.isArray(e)}function r(e){return void 0===e}function i(e){return"object"===n(e)}function o(e){return"object"===n(e)&&null!==e}function a(e){return"function"==typeof e}var u=(function(){try{return!r(window)}catch(e){return!1}}()?window:global).console||{};function f(e){u&&u.warn&&u.warn(e)}var c=function(e){return f("".concat(e," is not supported in browser builds"))},s=function(){return f("This vue app/component has no vue-meta configuration")},d={title:void 0,titleChunk:"",titleTemplate:"%s",htmlAttrs:{},bodyAttrs:{},headAttrs:{},base:[],link:[],meta:[],style:[],script:[],noscript:[],__dangerouslyDisableSanitizers:[],__dangerouslyDisableSanitizersByTagID:{}},l="_vueMeta",v={t:"metaInfo",i:"data-vue-meta",o:"data-vue-meta-server-rendered",u:"vmid",s:"content",l:"template",v:!0,m:10,p:"ssr"},m=Object.keys(d),p=[m[12],m[13]],y=[m[1],m[2],"changed"].concat(p),h=[m[3],m[4],m[5]],b=["link","style","script"],g=["once","template"],I=["body","pbody"],N=["allowfullscreen","amp","async","autofocus","autoplay","checked","compact","controls","declare","default","defaultchecked","defaultmuted","defaultselected","defer","disabled","enabled","formnovalidate","hidden","indeterminate","inert","ismap","itemscope","loop","multiple","muted","nohref","noresize","noshade","novalidate","nowrap","open","pauseonexit","readonly","required","reversed","scoped","seamless","selected","sortable","truespeed","typemustmatch","visible"],A=null;function T(e,n,t){var r=e.m;n[l].h||!n[l].g&&"watcher"!==t||(n[l].h=null),n[l].h&&!n[l].I&&function(e,n){if(!(n=void 0===n?10:n))return void e();clearTimeout(A),A=setTimeout((function(){e()}),n)}((function(){n.$meta().refresh()}),r)}function w(e,n,t){if(!Array.prototype.findIndex){for(var r=0;r<e.length;r++)if(n.call(t,e[r],r,e))return r;return-1}return e.findIndex(n,t)}function O(e){return Array.from?Array.from(e):Array.prototype.slice.call(e)}function M(e,n){if(!Array.prototype.includes){for(var t in e)if(e[t]===n)return!0;return!1}return e.includes(n)}function K(e,n){return n&&i(e)?(t(e[n])||(e[n]=[]),e):t(e)?e:[]}function S(e,n,t){K(e,n),e[n].push(t)}function j(e){return(e=e||this)&&(!0===e[l]||i(e[l]))}function D(e,n){return e[l].I=!0,function(){return _(e,n)}}function _(e,n){if(e[l].I=!1,n||void 0===n)return e.$meta().refresh()}function k(e){var n=e.$router;!e[l].N&&n&&(e[l].N=!0,n.beforeEach((function(n,t,r){D(e),r()})),n.afterEach((function(){var n=_(e).metaInfo;n&&a(n.afterNavigation)&&n.afterNavigation(n)})))}var x=1;function V(e,n){var t=["activated","deactivated","beforeMount"];return{beforeCreate:function(){var i=this.$root,o=this.$options,u=e.config.devtools;if(Object.defineProperty(this,"_hasMetaInfo",{configurable:!0,get:function(){return u&&!i[l].A&&(f("VueMeta DeprecationWarning: _hasMetaInfo has been deprecated and will be removed in a future version. Please use hasMetaInfo(vm) instead"),i[l].A=!0),j(this)}}),!r(o[n.t])&&null!==o[n.t]){if(i[l]||(i[l]={T:x},x++,u&&i.$options[n.t]&&this.$nextTick((function(){var e=function(e,n,t){if(Array.prototype.find)return e.find(n,t);for(var r=0;r<e.length;r++)if(n.call(t,e[r],r,e))return e[r]}(i.$children,(function(e){return e.$vnode&&e.$vnode.fnOptions}));e&&e.$vnode.fnOptions[n.t]&&f("VueMeta has detected a possible global mixin which adds a ".concat(n.t," property to all Vue components on the page. This could cause severe performance issues. If possible, use $meta().addApp to add meta information instead"))}))),!this[l]){this[l]=!0;for(var c=this.$parent;c&&c!==i;)r(c[l])&&(c[l]=!1),c=c.$parent}a(o[n.t])&&(o.computed=o.computed||{},o.computed.$metaInfo=o[n.t],this.$isServer||S(o,"created",(function(){this.$watch("$metaInfo",(function(){T(n,this.$root,"watcher")}))}))),r(i[l].h)&&(i[l].h=this.$isServer,i[l].h||(i[l].initializedSsr||(i[l].initializedSsr=!0,S(o,"beforeMount",(function(){this.$el&&1===this.$el.nodeType&&this.$el.hasAttribute("data-server-rendered")&&(this[l].T=n.p)}))),S(o,"mounted",(function(){var e=this.$root;e[l].h||(e[l].g=!0,this.$nextTick((function(){var t=e.$meta().refresh(),r=t.tags,i=t.metaInfo;!1===r&&null===e[l].h&&this.$nextTick((function(){return T(n,e,"init")})),e[l].h=!0,delete e[l].g,!n.O&&i.afterNavigation&&k(e)})))})),n.O&&k(i))),this.$isServer||t.forEach((function(e){S(o,e,(function(){T(n,this.$root,e)}))}))}},destroyed:function(){var e=this;this.$parent&&j(this)&&(delete this._hasMetaInfo,this.$nextTick((function(){if(n.v&&e.$el&&e.$el.offsetParent)var t=setInterval((function(){e.$el&&null!==e.$el.offsetParent||(clearInterval(t),T(n,e.$root,"destroyed"))}),50);else T(n,e.$root,"destroyed")})))}}}var W=[[/&/g,"&"],[/</g,"<"],[/>/g,">"],[/"/g,'"'],[/'/g,"'"]];function z(e,n,r){r=r||[];var i={M:function(e){return r.reduce((function(e,n){return e.replace(n[0],n[1])}),e)}};return p.forEach((function(e,t){if(0===t)K(n,e);else if(1===t)for(var r in n[e])K(n[e],r);i[e]=n[e]})),function e(n,r,i,a){var u=r.u,f=i.M,c=void 0===f?function(e){return e}:f,s={};for(var d in n){var l=n[d];if(M(y,d))s[d]=l;else{var v=p[0];if(i[v]&&M(i[v],d))s[d]=l;else{var m=n[u];if(m&&(v=p[1],i[v]&&i[v][m]&&M(i[v][m],d)))s[d]=l;else if("string"==typeof l?s[d]=c(l):t(l)?s[d]=l.map((function(n){return o(n)?e(n,r,i,!0):c(n)})):o(l)?s[d]=e(l,r,i,!0):s[d]=l,a){var h=c(d);d!==h&&(s[h]=s[d],delete s[d])}}}}return s}(n,e,i)}function B(e,n,t,i){var o=e.component,u=e.l,f=e.s;return!0!==t&&!0!==n[u]&&(r(t)&&n[u]&&(t=n[u],n[u]=!0),t?(r(i)&&(i=n[f]),n[f]=a(t)?t.call(o,i):t.replace(/%s/g,i),!0):(delete n[u],!1))}var J=!1;function C(n,t,r){return r=r||{},void 0===t.title&&delete t.title,h.forEach((function(e){if(t[e])for(var n in t[e])n in t[e]&&void 0===t[e][n]&&(M(N,n)&&!J&&(f("VueMeta: Please note that since v2 the value undefined is not used to indicate boolean attributes anymore, see migration guide for details"),J=!0),delete t[e][n])})),e(n,t,{K:function(e,n){return function(e,n,t){var r=e.component,i=e.u,o=e.l,a=e.s,u=[];return n.length||t.length?(n.forEach((function(e,n){if(e[i]){var f=w(t,(function(n){return n[i]===e[i]})),c=t[f];if(-1!==f){if(a in c&&void 0===c[a]||"innerHTML"in c&&void 0===c.innerHTML)return u.push(e),void t.splice(f,1);if(null!==c[a]&&null!==c.innerHTML){var s=e[o];if(s){if(!c[o])return B({component:r,l:o,s:a},c,s),void(c.template=!0);c[a]||B({component:r,l:o,s:a},c,void 0,e[a])}}else t.splice(f,1)}else u.push(e)}else u.push(e)})),u.concat(t)):u}(r,e,n)}})}function H(e,n){return function e(n,t,o){o=o||{};if(t._inactive)return o;n=n||{};var a=n,u=a.t;var f=t.$metaInfo,c=t.$options,s=t.$children;if(c[u]){var d=f||c[u];i(d)&&(o=C(o,d,n))}s.length&&s.forEach((function(t){(function(e){return(e=e||this)&&!r(e[l])})(t)&&(o=e(n,t,o))}));return o}(e||{},n,d)}var L=function(e,n){return(n||document).querySelectorAll(e)};function P(e,n){return e[n]||(e[n]=document.getElementsByTagName(n)[0]),e[n]}function R(e,n,t){var r=n.T,i=n.i,o=n.type,a=n.u;t=t||{};var u=["".concat(o,"[").concat(i,'="').concat(r,'"]'),"".concat(o,"[data-").concat(a,"]")].map((function(e){for(var n in t){var r=t[n],i=r&&!0!==r?'="'.concat(r,'"'):"";e+="[data-".concat(n).concat(i,"]")}return e}));return O(L(u.join(", "),e))}function $(e,n){e.removeAttribute(n)}var q=[];function E(e,n,t,r){var i=e.u,o=!1;return t.forEach((function(e){e[i]&&e.callback&&(o=!0,function(e,n){1===arguments.length&&(n=e,e=""),q.push([e,n])}("".concat(n,"[data-").concat(i,'="').concat(e[i],'"]'),e.callback))})),r&&o?U():o}function U(){var e;"complete"!==(e||document).readyState?document.onreadystatechange=function(){F()}:F()}function F(e){q.forEach((function(n){var t=n[0],r=n[1],i="".concat(t,'[onload="this.__vm_l=1"]'),o=[];e||(o=O(L(i))),e&&e.matches(i)&&(o=[e]),o.forEach((function(e){if(!e.__vm_cb){var n=function(){e.__vm_cb=!0,$(e,"onload"),r(e)};e.__vm_l?n():e.__vm_ev||(e.__vm_ev=!0,e.addEventListener("load",n))}}))}))}var G,Q={};function X(e,n,t,r,i){var o=(n||{}).i,a=i.getAttribute(o);a&&(Q[t]=JSON.parse(decodeURI(a)),$(i,o));var u=Q[t]||{},f=[];for(var c in u)u[c]&&e in u[c]&&(f.push(c),r[c]||delete u[c][e]);for(var s in r){var d=u[s];d&&d[e]===r[s]||(f.push(s),r[s]&&(u[s]=u[s]||{},u[s][e]=r[s]))}for(var l=0,v=f;l<v.length;l++){var m=v[l],p=u[m],y=[];for(var h in p)Array.prototype.push.apply(y,[].concat(p[h]));if(y.length){var b=M(N,m)&&y.some(Boolean)?"":y.filter(Boolean).join(" ");i.setAttribute(m,b)}else $(i,m)}Q[t]=u}function Y(e,n,t,r,i,o){var a=n||{},u=a.i,f=a.u,c=I.slice();c.push(f);var s=[],d={T:e,i:u,type:t,u:f},l={head:R(i,d),pbody:R(o,d,{pbody:!0}),body:R(o,d,{body:!0})};if(r.length>1){var v=[];r=r.filter((function(e){var n=JSON.stringify(e),t=!M(v,n);return v.push(n),t}))}r.forEach((function(n){if(!n.skip){var r=document.createElement(t);r.setAttribute(u,e),Object.keys(n).forEach((function(e){if(!M(g,e))if("innerHTML"!==e)if("json"!==e)if("cssText"!==e)if("callback"!==e){var t=M(c,e)?"data-".concat(e):e,i=M(N,e);if(!i||n[e]){var o=i?"":n[e];r.setAttribute(t,o)}}else r.onload=function(){return n[e](r)};else r.styleSheet?r.styleSheet.cssText=n.cssText:r.appendChild(document.createTextNode(n.cssText));else r.innerHTML=JSON.stringify(n.json);else r.innerHTML=n.innerHTML}));var i,o=l[function(e){var n=e.body,t=e.pbody;return n?"body":t?"pbody":"head"}(n)];o.some((function(e,n){return i=n,r.isEqualNode(e)}))&&(i||0===i)?o.splice(i,1):s.push(r)}}));var m=[];for(var p in l)Array.prototype.push.apply(m,l[p]);return m.forEach((function(e){e.parentNode.removeChild(e)})),s.forEach((function(e){e.hasAttribute("data-body")?o.appendChild(e):e.hasAttribute("data-pbody")?o.insertBefore(e,o.firstChild):i.appendChild(e)})),{oldTags:m,newTags:s}}function Z(e,n,r){var i=n=n||{},o=i.o,a=i.p,u={},f=P(u,"html");if(e===a&&f.hasAttribute(o)){$(f,o);var c=!1;return b.forEach((function(e){r[e]&&E(n,e,r[e])&&(c=!0)})),c&&U(),!1}var s,d={},l={};for(var v in r)if(!M(y,v))if("title"!==v){if(M(h,v)){var m=v.substr(0,4);X(e,n,v,r[v],P(u,m))}else if(t(r[v])){var p=Y(e,n,v,r[v],P(u,"head"),P(u,"body")),g=p.oldTags,I=p.newTags;I.length&&(d[v]=I,l[v]=g)}}else((s=r.title)||""===s)&&(document.title=s);return{S:d,j:l}}function ee(e,n,t){return{set:function(r){return function(e,n,t,r){if(e&&e.$el)return Z(n,t,r);(G=G||{})[n]=r}(e,n,t,r)},remove:function(){return function(e,n,t){if(e&&e.$el){var r={},i=!0,o=!1,a=void 0;try{for(var u,f=h[Symbol.iterator]();!(i=(u=f.next()).done);i=!0){var c=u.value,s=c.substr(0,4);X(n,t,c,{},P(r,s))}}catch(e){o=!0,a=e}finally{try{i||null==f.return||f.return()}finally{if(o)throw a}}return function(e,n){var t=e.i;O(L("[".concat(t,'="').concat(n,'"]'))).map((function(e){return e.remove()}))}(t,n)}G[n]&&(delete G[n],te())}(e,n,t)}}}function ne(){return G}function te(e){!e&&Object.keys(G).length||(G=void 0)}function re(e,n){if(n=n||{},!e[l])return s(),{};var t=function(e,n,t,r){t=t||[];var i=(e=e||{}).u;return n.title&&(n.titleChunk=n.title),n.titleTemplate&&"%s"!==n.titleTemplate&&B({component:r,s:"title"},n,n.titleTemplate,n.titleChunk||""),n.base&&(n.base=Object.keys(n.base).length?[n.base]:[]),n.meta&&(n.meta=n.meta.filter((function(e,n,t){return!e[i]||n===w(t,(function(n){return n[i]===e[i]}))})),n.meta.forEach((function(n){return B(e,n)}))),z(e,n,t)}(n,H(n,e),W,e),r=Z(e[l].T,n,t);r&&a(t.changed)&&(t.changed(t,r.S,r.j),r={addedTags:r.S,removedTags:r.j});var i=ne();if(i){for(var o in i)Z(o,n,i[o]),delete i[o];te(!0)}return{vm:e,metaInfo:t,tags:r}}function ie(e){e=e||{};var n=this.$root;return{getOptions:function(){return function(e){var n={};for(var t in e)n[t]=e[t];return n}(e)},setOptions:function(t){t&&t.O&&(e.O=!!t.O,k(n));if(t&&"debounceWait"in t){var r=parseInt(t.m);isNaN(r)||(e.m=r)}t&&"waitOnDestroyed"in t&&(e.v=!!t.v)},refresh:function(){return re(n,e)},inject:function(){return c("inject")},pause:function(){return D(n)},resume:function(){return _(n)},addApp:function(t){return ee(n,t,e)}}}var oe={version:"2.3.1",install:function(e,n){e.__vuemeta_installed||(e.__vuemeta_installed=!0,n=function(e){return{t:(e=i(e)?e:{}).keyName||v.t,i:e.attribute||v.i,o:e.ssrAttribute||v.o,u:e.tagIDKeyName||v.u,s:e.contentKeyName||v.s,l:e.metaTemplateKeyName||v.l,m:r(e.debounceWait)?v.m:e.debounceWait,v:r(e.waitOnDestroyed)?v.v:e.waitOnDestroyed,p:e.ssrAppId||v.p,O:!!e.refreshOnceOnNavigation}}(n),e.prototype.$meta=function(){return ie.call(this,n)},e.mixin(V(e,n)))},generate:function(e,n){return c("generate")},hasMetaInfo:j};export default oe;
|