vue-meta.min.js 15 KB

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