2
0
mirror of https://github.com/tenrok/vue-meta.git synced 2026-06-20 16:00:33 +03:00
Files
vue-meta/dist/vue-meta.min.js
T
2020-02-26 18:53:05 +00:00

11 lines
14 KiB
JavaScript

/**
* vue-meta v2.3.3
* (c) 2020
* - Declan de Wet
* - Sébastien Chopin (@Atinux)
* - Pim (@pimlie)
* - All the amazing contributors
* @license MIT
*/
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(n=n||self).VueMeta=t()}(this,(function(){"use strict";function n(t){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n})(t)}function t(n){return Array.isArray(n)}function e(n){return void 0===n}function r(t){return"object"===n(t)}function i(t){return"object"===n(t)&&null!==t}function o(n){return"function"==typeof n}var u=(function(){try{return!e(window)}catch(n){return!1}}()?window:global).console||{};function a(n){u&&u.warn&&u.warn(n)}var f=function(n){return a("".concat(n," is not supported in browser builds"))},c={title:void 0,titleChunk:"",titleTemplate:"%s",htmlAttrs:{},bodyAttrs:{},headAttrs:{},base:[],link:[],meta:[],style:[],script:[],noscript:[],__dangerouslyDisableSanitizers:[],__dangerouslyDisableSanitizersByTagID:{}},s="metaInfo",d="data-vue-meta",l="data-vue-meta-server-rendered",v="vmid",m="content",h="template",y=!0,p=10,b="ssr",g=Object.keys(c),A=[g[12],g[13]],j=[g[1],g[2],"changed"].concat(A),I=[g[3],g[4],g[5]],O=["link","style","script"],N=["once","skip","template"],T=["body","pbody"],w=["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"],k=null;function M(n,t,e){var r=n.t;t._vueMeta.i||!t._vueMeta.o&&"watcher"!==e||(t._vueMeta.i=null),t._vueMeta.i&&!t._vueMeta.u&&function(n,t){if(!(t=void 0===t?10:t))return void n();clearTimeout(k),k=setTimeout((function(){n()}),t)}((function(){t.$meta().refresh()}),r)}function S(n,t,e){if(!Array.prototype.findIndex){for(var r=0;r<n.length;r++)if(t.call(e,n[r],r,n))return r;return-1}return n.findIndex(t,e)}function D(n){return Array.from?Array.from(n):Array.prototype.slice.call(n)}function K(n,t){if(!Array.prototype.includes){for(var e in n)if(n[e]===t)return!0;return!1}return n.includes(t)}function _(n){return(n=n||this)&&(!0===n._vueMeta||r(n._vueMeta))}function x(n,t){return n._vueMeta.u=!0,function(){return V(n,t)}}function V(n,t){if(n._vueMeta.u=!1,t||void 0===t)return n.$meta().refresh()}function z(n){var t=n.$router;!n._vueMeta.s&&t&&(n._vueMeta.s=!0,t.beforeEach((function(t,e,r){x(n),r()})),t.afterEach((function(){n.$nextTick((function(){var t=V(n).metaInfo;t&&o(t.afterNavigation)&&t.afterNavigation(t)}))})))}var B=1;function J(n,t){var r=["activated","deactivated","beforeMount"];return{beforeCreate:function(){var i=this,u=this.$root,f=this.$options,c=n.config.devtools;if(Object.defineProperty(this,"_hasMetaInfo",{configurable:!0,get:function(){return c&&!u._vueMeta.l&&(a("VueMeta DeprecationWarning: _hasMetaInfo has been deprecated and will be removed in a future version. Please use hasMetaInfo(vm) instead"),u._vueMeta.l=!0),_(this)}}),!e(f[t.v])&&null!==f[t.v]){if(u._vueMeta||(u._vueMeta={m:B},B++,c&&u.$options[t.v]&&this.$nextTick((function(){var n=function(n,t,e){if(Array.prototype.find)return n.find(t,e);for(var r=0;r<n.length;r++)if(t.call(e,n[r],r,n))return n[r]}(u.$children,(function(n){return n.$vnode&&n.$vnode.fnOptions}));n&&n.$vnode.fnOptions[t.v]&&a("VueMeta has detected a possible global mixin which adds a ".concat(t.v," 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._vueMeta){this._vueMeta=!0;for(var s=this.$parent;s&&s!==u;)e(s._vueMeta)&&(s._vueMeta=!1),s=s.$parent}o(f[t.v])&&(f.computed=f.computed||{},f.computed.$metaInfo=f[t.v],this.$isServer||this.$on("hook:created",(function(){this.$watch("$metaInfo",(function(){M(t,this.$root,"watcher")}))}))),e(u._vueMeta.i)&&(u._vueMeta.i=this.$isServer,u._vueMeta.i||(u._vueMeta.initializedSsr||(u._vueMeta.initializedSsr=!0,this.$on("hook:beforeMount",(function(){this.$el&&1===this.$el.nodeType&&this.$el.hasAttribute("data-server-rendered")&&(this._vueMeta.m=t.h)}))),this.$on("hook:mounted",(function(){var n=this.$root;n._vueMeta.i||(n._vueMeta.o=!0,this.$nextTick((function(){var e=n.$meta().refresh(),r=e.tags,i=e.metaInfo;!1===r&&null===n._vueMeta.i&&this.$nextTick((function(){return M(t,n,"init")})),n._vueMeta.i=!0,delete n._vueMeta.o,!t.p&&i.afterNavigation&&z(n)})))})),t.p&&z(u))),this.$on("hook:destroyed",(function(){var n=this;this.$parent&&_(this)&&(delete this._hasMetaInfo,this.$nextTick((function(){if(t.g&&n.$el&&n.$el.offsetParent)var e=setInterval((function(){n.$el&&null!==n.$el.offsetParent||(clearInterval(e),M(t,n.$root,"destroyed"))}),50);else M(t,n.$root,"destroyed")})))})),this.$isServer||r.forEach((function(n){i.$on("hook:".concat(n),(function(){M(t,this.$root,n)}))}))}}}}function R(n,e){return e&&r(n)?(t(n[e])||(n[e]=[]),n):t(n)?n:[]}var W=[[/&/g,"&"],[/</g,"<"],[/>/g,">"],[/"/g,'"'],[/'/g,"'"]];function C(n,e,r){r=r||[];var o={A:function(n){return r.reduce((function(n,t){return n.replace(t[0],t[1])}),n)}};return A.forEach((function(n,t){if(0===t)R(e,n);else if(1===t)for(var r in e[n])R(e[n],r);o[n]=e[n]})),function n(e,r,o,u){var a=r.j,f=o.A,c=void 0===f?function(n){return n}:f,s={};for(var d in e){var l=e[d];if(K(j,d))s[d]=l;else{var v=A[0];if(o[v]&&K(o[v],d))s[d]=l;else{var m=e[a];if(m&&(v=A[1],o[v]&&o[v][m]&&K(o[v][m],d)))s[d]=l;else if("string"==typeof l?s[d]=c(l):t(l)?s[d]=l.map((function(t){return i(t)?n(t,r,o,!0):c(t)})):i(l)?s[d]=n(l,r,o,!0):s[d]=l,u){var h=c(d);d!==h&&(s[h]=s[d],delete s[d])}}}}return s}(e,n,o)}var E=function(t){return function(t){return!!t&&"object"===n(t)}(t)&&!function(n){var t=Object.prototype.toString.call(n);return"[object RegExp]"===t||"[object Date]"===t||!1}(t)};function H(n,t){return n}function L(n){return Object.keys(n)}function P(n,t){try{return t in n}catch(n){return!1}}function $(n,t,e){var r={};return e.I(n)&&L(n).forEach((function(t){r[t]=H(n[t])})),L(t).forEach((function(i){(function(n,t){return P(n,t)&&!(Object.hasOwnProperty.call(n,t)&&Object.propertyIsEnumerable.call(n,t))})(n,i)||(P(n,i)&&e.I(t[i])?r[i]=q(n[i],t[i],e):r[i]=H(t[i]))})),r}function q(n,t,e){(e=e||{}).O=e.O,e.I=e.I||E,e.cloneUnlessOtherwiseSpecified=H;var r=Array.isArray(t);return r===Array.isArray(n)?r?e.O(n,t,e):$(n,t,e):H(t)}var U=q;function F(n,t,r,i){var u=n.component,a=n.N,f=n.T;return!0!==r&&!0!==t[a]&&(e(r)&&t[a]&&(r=t[a],t[a]=!0),r?(e(i)&&(i=t[f]),t[f]=o(r)?r.call(u,i):r.replace(/%s/g,i),!0):(delete t[a],!1))}var G=!1;function Q(n,t,e){return e=e||{},void 0===t.title&&delete t.title,I.forEach((function(n){if(t[n])for(var e in t[n])e in t[n]&&void 0===t[n][e]&&(K(w,e)&&!G&&(a("VueMeta: Please note that since v2 the value undefined is not used to indicate boolean attributes anymore, see migration guide for details"),G=!0),delete t[n][e])})),U(n,t,{O:function(n,t){return function(n,t,e){var r=n.component,i=n.j,o=n.N,u=n.T,a=[];return t.length||e.length?(t.forEach((function(n,t){if(n[i]){var f=S(e,(function(t){return t[i]===n[i]})),c=e[f];if(-1!==f){if(u in c&&void 0===c[u]||"innerHTML"in c&&void 0===c.innerHTML)return a.push(n),void e.splice(f,1);if(null!==c[u]&&null!==c.innerHTML){var s=n[o];if(s){if(!c[o])return F({component:r,N:o,T:u},c,s),void(c.template=!0);c[u]||F({component:r,N:o,T:u},c,void 0,n[u])}}else e.splice(f,1)}else a.push(n)}else a.push(n)})),a.concat(e)):a}(e,n,t)}})}function X(n,t){return function n(t,i,o){if(o=o||{},i._inactive)return o;var u=(t=t||{}).v,a=i.$metaInfo,f=i.$options,c=i.$children;if(f[u]){var s=a||f[u];r(s)&&(o=Q(o,s,t))}c.length&&c.forEach((function(r){(function(n){return(n=n||this)&&!e(n._vueMeta)})(r)&&(o=n(t,r,o))}));return o}(n||{},t,c)}var Y=function(n,t){return(t||document).querySelectorAll(n)};function Z(n,t){return n[t]||(n[t]=document.getElementsByTagName(t)[0]),n[t]}function nn(n,t,e){var r=t.m,i=t.k,o=t.type,u=t.j;e=e||{};var a=["".concat(o,"[").concat(i,'="').concat(r,'"]'),"".concat(o,"[data-").concat(u,"]")].map((function(n){for(var t in e){var r=e[t],i=r&&!0!==r?'="'.concat(r,'"'):"";n+="[data-".concat(t).concat(i,"]")}return n}));return D(Y(a.join(", "),n))}function tn(n,t){n.removeAttribute(t)}var en=[];function rn(n,t,e,r){var i=n.j,o=!1;return e.forEach((function(n){n[i]&&n.callback&&(o=!0,function(n,t){1===arguments.length&&(t=n,n=""),en.push([n,t])}("".concat(t,"[data-").concat(i,'="').concat(n[i],'"]'),n.callback))})),r&&o?on():o}function on(){var n;"complete"!==(n||document).readyState?document.onreadystatechange=function(){un()}:un()}function un(n){en.forEach((function(t){var e=t[0],r=t[1],i="".concat(e,'[onload="this.__vm_l=1"]'),o=[];n||(o=D(Y(i))),n&&n.matches(i)&&(o=[n]),o.forEach((function(n){if(!n.__vm_cb){var t=function(){n.__vm_cb=!0,tn(n,"onload"),r(n)};n.__vm_l?t():n.__vm_ev||(n.__vm_ev=!0,n.addEventListener("load",t))}}))}))}var an,fn={};function cn(n,t,e,r,i){var o=(t||{}).k,u=i.getAttribute(o);u&&(fn[e]=JSON.parse(decodeURI(u)),tn(i,o));var a=fn[e]||{},f=[];for(var c in a)a[c]&&n in a[c]&&(f.push(c),r[c]||delete a[c][n]);for(var s in r){var d=a[s];d&&d[n]===r[s]||(f.push(s),r[s]&&(a[s]=a[s]||{},a[s][n]=r[s]))}for(var l=0,v=f;l<v.length;l++){var m=v[l],h=a[m],y=[];for(var p in h)Array.prototype.push.apply(y,[].concat(h[p]));if(y.length){var b=K(w,m)&&y.some(Boolean)?"":y.filter(Boolean).join(" ");i.setAttribute(m,b)}else tn(i,m)}fn[e]=a}function sn(n,t,e,r,i,o){var u=t||{},a=u.k,f=u.j,c=T.slice();c.push(f);var s=[],d={m:n,k:a,type:e,j:f},l={head:nn(i,d),pbody:nn(o,d,{pbody:!0}),body:nn(o,d,{body:!0})};if(r.length>1){var v=[];r=r.filter((function(n){var t=JSON.stringify(n),e=!K(v,t);return v.push(t),e}))}r.forEach((function(t){if(!t.skip){var r=document.createElement(e);t.once||r.setAttribute(a,n),Object.keys(t).forEach((function(n){if(!K(N,n))if("innerHTML"!==n)if("json"!==n)if("cssText"!==n)if("callback"!==n){var e=K(c,n)?"data-".concat(n):n,i=K(w,n);if(!i||t[n]){var o=i?"":t[n];r.setAttribute(e,o)}}else r.onload=function(){return t[n](r)};else r.styleSheet?r.styleSheet.cssText=t.cssText:r.appendChild(document.createTextNode(t.cssText));else r.innerHTML=JSON.stringify(t.json);else r.innerHTML=t.innerHTML}));var i,o=l[function(n){var t=n.body,e=n.pbody;return t?"body":e?"pbody":"head"}(t)];o.some((function(n,t){return i=t,r.isEqualNode(n)}))&&(i||0===i)?o.splice(i,1):s.push(r)}}));var m=[];for(var h in l)Array.prototype.push.apply(m,l[h]);return m.forEach((function(n){n.parentNode.removeChild(n)})),s.forEach((function(n){n.hasAttribute("data-body")?o.appendChild(n):n.hasAttribute("data-pbody")?o.insertBefore(n,o.firstChild):i.appendChild(n)})),{oldTags:m,newTags:s}}function dn(n,e,r){var i=e=e||{},o=i.M,u=i.h,a={},f=Z(a,"html");if(n===u&&f.hasAttribute(o)){tn(f,o);var c=!1;return O.forEach((function(n){r[n]&&rn(e,n,r[n])&&(c=!0)})),c&&on(),!1}var s,d={},l={};for(var v in r)if(!K(j,v))if("title"!==v){if(K(I,v)){var m=v.substr(0,4);cn(n,e,v,r[v],Z(a,m))}else if(t(r[v])){var h=sn(n,e,v,r[v],Z(a,"head"),Z(a,"body")),y=h.oldTags,p=h.newTags;p.length&&(d[v]=p,l[v]=y)}}else((s=r.title)||""===s)&&(document.title=s);return{S:d,D:l}}function ln(n,t,e){return{set:function(r){return function(n,t,e,r){if(n&&n.$el)return dn(t,e,r);(an=an||{})[t]=r}(n,t,e,r)},remove:function(){return function(n,t,e){if(n&&n.$el){var r={},i=!0,o=!1,u=void 0;try{for(var a,f=I[Symbol.iterator]();!(i=(a=f.next()).done);i=!0){var c=a.value,s=c.substr(0,4);cn(t,e,c,{},Z(r,s))}}catch(n){o=!0,u=n}finally{try{i||null==f.return||f.return()}finally{if(o)throw u}}return function(n,t){var e=n.k;D(Y("[".concat(e,'="').concat(t,'"]'))).map((function(n){return n.remove()}))}(e,t)}an[t]&&(delete an[t],mn())}(n,t,e)}}}function vn(){return an}function mn(n){!n&&Object.keys(an).length||(an=void 0)}function hn(n,t){if(t=t||{},!n._vueMeta)return a("This vue app/component has no vue-meta configuration"),{};var e=function(n,t,e,r){e=e||[];var i=(n=n||{}).j;return t.title&&(t.titleChunk=t.title),t.titleTemplate&&"%s"!==t.titleTemplate&&F({component:r,T:"title"},t,t.titleTemplate,t.titleChunk||""),t.base&&(t.base=Object.keys(t.base).length?[t.base]:[]),t.meta&&(t.meta=t.meta.filter((function(n,t,e){return!n[i]||t===S(e,(function(t){return t[i]===n[i]}))})),t.meta.forEach((function(t){return F(n,t)}))),C(n,t,e)}(t,X(t,n),W,n),r=dn(n._vueMeta.m,t,e);r&&o(e.changed)&&(e.changed(e,r.S,r.D),r={addedTags:r.S,removedTags:r.D});var i=vn();if(i){for(var u in i)dn(u,t,i[u]),delete i[u];mn(!0)}return{vm:n,metaInfo:e,tags:r}}function yn(n){n=n||{};var t=this.$root;return{getOptions:function(){return function(n){var t={};for(var e in n)t[e]=n[e];return t}(n)},setOptions:function(e){e&&e.p&&(n.p=!!e.p,z(t));if(e&&"debounceWait"in e){var r=parseInt(e.t);isNaN(r)||(n.t=r)}e&&"waitOnDestroyed"in e&&(n.g=!!e.g)},refresh:function(){return hn(t,n)},inject:function(){return f("inject")},pause:function(){return x(t)},resume:function(){return V(t)},addApp:function(e){return ln(t,e,n)}}}return{version:"2.3.3",install:function(n,t){n.__vuemeta_installed||(n.__vuemeta_installed=!0,t=function(n){return{v:(n=r(n)?n:{}).keyName||s,k:n.attribute||d,M:n.ssrAttribute||l,j:n.tagIDKeyName||v,T:n.contentKeyName||m,N:n.metaTemplateKeyName||h,t:e(n.debounceWait)?p:n.debounceWait,g:e(n.waitOnDestroyed)?y:n.waitOnDestroyed,h:n.ssrAppId||b,p:!!n.refreshOnceOnNavigation}}(t),n.prototype.$meta=function(){return yn.call(this,t)},n.mixin(J(n,t)))},generate:function(n,t){return f("generate")},hasMetaInfo:_}}));