mirror of
https://github.com/tenrok/vue-meta.git
synced 2026-06-22 14:50:33 +03:00
11 lines
14 KiB
JavaScript
11 lines
14 KiB
JavaScript
/**
|
|
* vue-meta v2.3.2
|
|
* (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",y="template",p=!0,h=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","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"],M=null;function S(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 D(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 K(n){return Array.from?Array.from(n):Array.prototype.slice.call(n)}function _(n,t){if(!Array.prototype.includes){for(var e in n)if(n[e]===t)return!0;return!1}return n.includes(t)}function k(n,e){return e&&r(n)?(t(n[e])||(n[e]=[]),n):t(n)?n:[]}function x(n,t,e){k(n,t),n[t].push(e)}function V(n){return(n=n||this)&&(!0===n._vueMeta||r(n._vueMeta))}function z(n,t){return n._vueMeta.u=!0,function(){return B(n,t)}}function B(n,t){if(n._vueMeta.u=!1,t||void 0===t)return n.$meta().refresh()}function J(n){var t=n.$router;!n._vueMeta.s&&t&&(n._vueMeta.s=!0,t.beforeEach((function(t,e,r){z(n),r()})),t.afterEach((function(){n.$nextTick((function(){var t=B(n).metaInfo;t&&o(t.afterNavigation)&&t.afterNavigation(t)}))})))}var R=1;function W(n,t){var r=["activated","deactivated","beforeMount"];return{beforeCreate:function(){var i=this.$root,u=this.$options,f=n.config.devtools;if(Object.defineProperty(this,"_hasMetaInfo",{configurable:!0,get:function(){return f&&!i._vueMeta.l&&(a("VueMeta DeprecationWarning: _hasMetaInfo has been deprecated and will be removed in a future version. Please use hasMetaInfo(vm) instead"),i._vueMeta.l=!0),V(this)}}),!e(u[t.v])&&null!==u[t.v]){if(i._vueMeta||(i._vueMeta={m:R},R++,f&&i.$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]}(i.$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 c=this.$parent;c&&c!==i;)e(c._vueMeta)&&(c._vueMeta=!1),c=c.$parent}o(u[t.v])&&(u.computed=u.computed||{},u.computed.$metaInfo=u[t.v],this.$isServer||x(u,"created",(function(){this.$watch("$metaInfo",(function(){S(t,this.$root,"watcher")}))}))),e(i._vueMeta.i)&&(i._vueMeta.i=this.$isServer,i._vueMeta.i||(i._vueMeta.initializedSsr||(i._vueMeta.initializedSsr=!0,x(u,"beforeMount",(function(){this.$el&&1===this.$el.nodeType&&this.$el.hasAttribute("data-server-rendered")&&(this._vueMeta.m=t.p)}))),x(u,"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 S(t,n,"init")})),n._vueMeta.i=!0,delete n._vueMeta.o,!t.h&&i.afterNavigation&&J(n)})))})),t.h&&J(i))),this.$isServer||r.forEach((function(n){x(u,n,(function(){S(t,this.$root,n)}))}))}},destroyed:function(){var n=this;this.$parent&&V(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),S(t,n.$root,"destroyed"))}),50);else S(t,n.$root,"destroyed")})))}}}var C=[[/&/g,"&"],[/</g,"<"],[/>/g,">"],[/"/g,'"'],[/'/g,"'"]];function E(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)k(e,n);else if(1===t)for(var r in e[n])k(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(_(j,d))s[d]=l;else{var v=A[0];if(o[v]&&_(o[v],d))s[d]=l;else{var m=e[a];if(m&&(v=A[1],o[v]&&o[v][m]&&_(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 y=c(d);d!==y&&(s[y]=s[d],delete s[d])}}}}return s}(e,n,o)}var H=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 L(n,t){return n}function P(n){return Object.keys(n)}function $(n,t){try{return t in n}catch(n){return!1}}function q(n,t,e){var r={};return e.I(n)&&P(n).forEach((function(t){r[t]=L(n[t])})),P(t).forEach((function(i){(function(n,t){return $(n,t)&&!(Object.hasOwnProperty.call(n,t)&&Object.propertyIsEnumerable.call(n,t))})(n,i)||($(n,i)&&e.I(t[i])?r[i]=U(n[i],t[i],e):r[i]=L(t[i]))})),r}function U(n,t,e){(e=e||{}).O=e.O,e.I=e.I||H,e.cloneUnlessOtherwiseSpecified=L;var r=Array.isArray(t);return r===Array.isArray(n)?r?e.O(n,t,e):q(n,t,e):L(t)}var F=U;function G(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 Q=!1;function X(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]&&(_(w,e)&&!Q&&(a("VueMeta: Please note that since v2 the value undefined is not used to indicate boolean attributes anymore, see migration guide for details"),Q=!0),delete t[n][e])})),F(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=D(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 G({component:r,N:o,T:u},c,s),void(c.template=!0);c[u]||G({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 Y(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=X(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 Z=function(n,t){return(t||document).querySelectorAll(n)};function nn(n,t){return n[t]||(n[t]=document.getElementsByTagName(t)[0]),n[t]}function tn(n,t,e){var r=t.m,i=t.M,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 K(Z(a.join(", "),n))}function en(n,t){n.removeAttribute(t)}var rn=[];function on(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=""),rn.push([n,t])}("".concat(t,"[data-").concat(i,'="').concat(n[i],'"]'),n.callback))})),r&&o?un():o}function un(){var n;"complete"!==(n||document).readyState?document.onreadystatechange=function(){an()}:an()}function an(n){rn.forEach((function(t){var e=t[0],r=t[1],i="".concat(e,'[onload="this.__vm_l=1"]'),o=[];n||(o=K(Z(i))),n&&n.matches(i)&&(o=[n]),o.forEach((function(n){if(!n.__vm_cb){var t=function(){n.__vm_cb=!0,en(n,"onload"),r(n)};n.__vm_l?t():n.__vm_ev||(n.__vm_ev=!0,n.addEventListener("load",t))}}))}))}var fn,cn={};function sn(n,t,e,r,i){var o=(t||{}).M,u=i.getAttribute(o);u&&(cn[e]=JSON.parse(decodeURI(u)),en(i,o));var a=cn[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],y=a[m],p=[];for(var h in y)Array.prototype.push.apply(p,[].concat(y[h]));if(p.length){var b=_(w,m)&&p.some(Boolean)?"":p.filter(Boolean).join(" ");i.setAttribute(m,b)}else en(i,m)}cn[e]=a}function dn(n,t,e,r,i,o){var u=t||{},a=u.M,f=u.j,c=T.slice();c.push(f);var s=[],d={m:n,M:a,type:e,j:f},l={head:tn(i,d),pbody:tn(o,d,{pbody:!0}),body:tn(o,d,{body:!0})};if(r.length>1){var v=[];r=r.filter((function(n){var t=JSON.stringify(n),e=!_(v,t);return v.push(t),e}))}r.forEach((function(t){if(!t.skip){var r=document.createElement(e);r.setAttribute(a,n),Object.keys(t).forEach((function(n){if(!_(N,n))if("innerHTML"!==n)if("json"!==n)if("cssText"!==n)if("callback"!==n){var e=_(c,n)?"data-".concat(n):n,i=_(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 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 ln(n,e,r){var i=e=e||{},o=i.S,u=i.p,a={},f=nn(a,"html");if(n===u&&f.hasAttribute(o)){en(f,o);var c=!1;return O.forEach((function(n){r[n]&&on(e,n,r[n])&&(c=!0)})),c&&un(),!1}var s,d={},l={};for(var v in r)if(!_(j,v))if("title"!==v){if(_(I,v)){var m=v.substr(0,4);sn(n,e,v,r[v],nn(a,m))}else if(t(r[v])){var y=dn(n,e,v,r[v],nn(a,"head"),nn(a,"body")),p=y.oldTags,h=y.newTags;h.length&&(d[v]=h,l[v]=p)}}else((s=r.title)||""===s)&&(document.title=s);return{D:d,K:l}}function vn(n,t,e){return{set:function(r){return function(n,t,e,r){if(n&&n.$el)return ln(t,e,r);(fn=fn||{})[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);sn(t,e,c,{},nn(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.M;K(Z("[".concat(e,'="').concat(t,'"]'))).map((function(n){return n.remove()}))}(e,t)}fn[t]&&(delete fn[t],yn())}(n,t,e)}}}function mn(){return fn}function yn(n){!n&&Object.keys(fn).length||(fn=void 0)}function pn(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&&G({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===D(e,(function(t){return t[i]===n[i]}))})),t.meta.forEach((function(t){return G(n,t)}))),E(n,t,e)}(t,Y(t,n),C,n),r=ln(n._vueMeta.m,t,e);r&&o(e.changed)&&(e.changed(e,r.D,r.K),r={addedTags:r.D,removedTags:r.K});var i=mn();if(i){for(var u in i)ln(u,t,i[u]),delete i[u];yn(!0)}return{vm:n,metaInfo:e,tags:r}}function hn(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.h&&(n.h=!!e.h,J(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 pn(t,n)},inject:function(){return f("inject")},pause:function(){return z(t)},resume:function(){return B(t)},addApp:function(e){return vn(t,e,n)}}}return{version:"2.3.2",install:function(n,t){n.__vuemeta_installed||(n.__vuemeta_installed=!0,t=function(n){return{v:(n=r(n)?n:{}).keyName||s,M:n.attribute||d,S:n.ssrAttribute||l,j:n.tagIDKeyName||v,T:n.contentKeyName||m,N:n.metaTemplateKeyName||y,t:e(n.debounceWait)?h:n.debounceWait,g:e(n.waitOnDestroyed)?p:n.waitOnDestroyed,p:n.ssrAppId||b,h:!!n.refreshOnceOnNavigation}}(t),n.prototype.$meta=function(){return hn.call(this,t)},n.mixin(W(n,t)))},generate:function(n,t){return f("generate")},hasMetaInfo:V}}));
|