2
0
mirror of https://github.com/tenrok/vue-meta.git synced 2026-06-20 18:30:33 +03:00
Files
vue-meta/dist/vue-meta.min.js
T
2019-09-17 12:00:16 +00:00

2 lines
12 KiB
JavaScript

!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=function(){return a("This vue app/component has no vue-meta configuration")},s={title:void 0,titleChunk:"",titleTemplate:"%s",htmlAttrs:{},bodyAttrs:{},headAttrs:{},base:[],link:[],meta:[],style:[],script:[],noscript:[],__dangerouslyDisableSanitizers:[],__dangerouslyDisableSanitizersByTagID:{}},d="_vueMeta",v={t:"metaInfo",i:"data-vue-meta",o:"data-vue-meta-server-rendered",u:"vmid",s:"content",v:"template",l:!0,m:10,p:"ssr"},l=Object.keys(s),m=[l[12],l[13]],y=[l[1],l[2],"changed"].concat(m),p=[l[3],l[4],l[5]],b=["link","style","script"],h=["once","template"],g=["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 I(n,t,e){var r=n.m;t[d].h||!t[d].g&&"watcher"!==e||(t[d].h=null),t[d].h&&!t[d].N&&function(n,t){if(!(t=void 0===t?10:t))return void n();clearTimeout(A),A=setTimeout((function(){n()}),t)}((function(){t.$meta().refresh()}),r)}function O(n,e){return e&&r(n)?(t(n[e])||(n[e]=[]),n):t(n)?n:[]}function j(n,t,e){O(n,t),n[t].push(e)}function T(n){return(n=n||this)&&(!0===n[d]||r(n[d]))}function w(n,t){return n[d].N=!0,function(){return K(n,t)}}function K(n,t){if(n[d].N=!1,t||void 0===t)return n.$meta().refresh()}function M(n){var t=n.$router;!n[d].A&&t&&(n[d].A=!0,t.beforeEach((function(t,e,r){w(n),r()})),t.afterEach((function(){var t=K(n).metaInfo;t&&o(t.afterNavigation)&&t.afterNavigation(t)})))}var D=1;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 _(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)}var x=[[/&/g,"&"],[/</g,"<"],[/>/g,">"],[/"/g,'"'],[/'/g,"'"]];function W(n,e,r){r=r||[];var o={I:function(n){return r.reduce((function(n,t){return n.replace(t[0],t[1])}),n)}};return m.forEach((function(n,t){if(0===t)O(e,n);else if(1===t)for(var r in e[n])O(e[n],r);o[n]=e[n]})),function n(e,r,o,u){var a=r.u,f=o.I,c=void 0===f?function(n){return n}:f,s={};for(var d in e){var v=e[d];if(k(y,d))s[d]=v;else{var l=m[0];if(o[l]&&k(o[l],d))s[d]=v;else{var p=e[a];if(p&&(l=m[1],o[l]&&o[l][p]&&k(o[l][p],d)))s[d]=v;else if("string"==typeof v?s[d]=c(v):t(v)?s[d]=v.map((function(t){return i(t)?n(t,r,o,!0):c(t)})):i(v)?s[d]=n(v,r,o,!0):s[d]=v,u){var b=c(d);d!==b&&(s[b]=s[d],delete s[d])}}}}return s}(e,n,o)}var z=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 B(n,t){return n}function J(n){return Object.keys(n)}function R(n,t,e){var r={};return e.O(n)&&J(n).forEach((function(t){r[t]=B(n[t])})),J(t).forEach((function(i){e.O(t[i])&&n[i]?r[i]=C(n[i],t[i],e):r[i]=B(t[i])})),r}function C(n,t,e){(e=e||{}).j=e.j,e.O=e.O||z;var r=Array.isArray(t);return r===Array.isArray(n)?r?e.j(n,t,e):R(n,t,e):B(t)}var E=C;function H(n,t,r,i){var u=n.component,a=n.v,f=n.s;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 L=!1;function P(n,t,e){return e=e||{},void 0===t.title&&delete t.title,p.forEach((function(n){if(t[n])for(var e in t[n])e in t[n]&&void 0===t[n][e]&&(k(N,e)&&!L&&(a("VueMeta: Please note that since v2 the value undefined is not used to indicate boolean attributes anymore, see migration guide for details"),L=!0),delete t[n][e])})),E(n,t,{j:function(n,t){return function(n,t,e){var r=n.component,i=n.u,o=n.v,u=n.s,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 H({component:r,v:o,s:u},c,s),void(c.template=!0);c[u]||H({component:r,v:o,s: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 V(n,t){return function n(t,i,o){o=o||{};if(i._inactive)return o;t=t||{};var u=t,a=u.t;var f=i.$metaInfo,c=i.$options,s=i.$children;if(c[a]){var v=f||c[a];if(!r(v))return o;o=P(o,v,t)}s.length&&s.forEach((function(r){(function(n){return(n=n||this)&&!e(n[d])})(r)&&(o=n(t,r,o))}));return o}(n||{},t,s)}var q=function(n,t){return(t||document).querySelectorAll(n)};function U(n,t){return n[t]||(n[t]=document.getElementsByTagName(t)[0]),n[t]}function $(n,t,e){var r=t.T,i=t.i,o=t.type,u=t.u;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 _(q(a.join(", "),n))}function F(n,t){n.removeAttribute(t)}var G=[];function Q(n,t,e,r){var i=n.u,o=!1;return e.forEach((function(n){n[i]&&n.callback&&(o=!0,function(n,t){1===arguments.length&&(t=n,n=""),G.push([n,t])}("".concat(t,"[data-").concat(i,'="').concat(n[i],'"]'),n.callback))})),r&&o?X():o}function X(){var n;"complete"!==(n||document).readyState?document.onreadystatechange=function(){Y()}:Y()}function Y(n){G.forEach((function(t){var e=t[0],r=t[1],i="".concat(e,'[onload="this.__vm_l=1"]'),o=[];n||(o=_(q(i))),n&&n.matches(i)&&(o=[n]),o.forEach((function(n){if(!n.__vm_cb){var t=function(){n.__vm_cb=!0,F(n,"onload"),r(n)};n.__vm_l?t():n.__vm_ev||(n.__vm_ev=!0,n.addEventListener("load",t))}}))}))}var Z,nn={};function tn(n,t,e,r,i){var o=(t||{}).i,u=i.getAttribute(o);u&&(nn[e]=JSON.parse(decodeURI(u)),F(i,o));var a=nn[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 v=0,l=f;v<l.length;v++){var m=l[v],y=a[m],p=[];for(var b in y)Array.prototype.push.apply(p,[].concat(y[b]));if(p.length){var h=k(N,m)&&p.some(Boolean)?"":p.filter(Boolean).join(" ");i.setAttribute(m,h)}else F(i,m)}nn[e]=a}function en(n,t,e,r,i,o){var u=t||{},a=u.i,f=u.u,c=g.slice();c.push(f);var s=[],d={T:n,i:a,type:e,u:f},v={head:$(i,d),pbody:$(o,d,{pbody:!0}),body:$(o,d,{body:!0})};if(r.length>1){var l=[];r=r.filter((function(n){var t=JSON.stringify(n),e=!k(l,t);return l.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(!k(h,n))if("innerHTML"!==n)if("json"!==n)if("cssText"!==n)if("callback"!==n){var e=k(c,n)?"data-".concat(n):n,i=k(N,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=v[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 v)Array.prototype.push.apply(m,v[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 rn(n,e,r){var i=e=e||{},o=i.o,u=i.p,a={},f=U(a,"html");if(n===u&&f.hasAttribute(o)){F(f,o);var c=!1;return b.forEach((function(n){r[n]&&Q(e,n,r[n])&&(c=!0)})),c&&X(),!1}var s,d={},v={};for(var l in r)if(!k(y,l))if("title"!==l){if(k(p,l)){var m=l.substr(0,4);tn(n,e,l,r[l],U(a,m))}else if(t(r[l])){var h=en(n,e,l,r[l],U(a,"head"),U(a,"body")),g=h.oldTags,N=h.newTags;N.length&&(d[l]=N,v[l]=g)}}else((s=r.title)||""===s)&&(document.title=s);return{K:d,M:v}}function on(n,t,e){return{set:function(r){return function(n,t,e,r){if(n&&n.$el)return rn(t,e,r);(Z=Z||{})[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=p[Symbol.iterator]();!(i=(a=f.next()).done);i=!0){var c=a.value,s=c.substr(0,4);tn(t,e,c,{},U(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.i;_(q("[".concat(e,'="').concat(t,'"]'))).map((function(n){return n.remove()}))}(e,t)}Z[t]&&(delete Z[t],an())}(n,t,e)}}}function un(){return Z}function an(n){!n&&Object.keys(Z).length||(Z=void 0)}function fn(n,t){if(t=t||{},!n[d])return c(),{};var e=function(n,t,e,r){e=e||[];var i=(n=n||{}).u;return t.title&&(t.titleChunk=t.title),t.titleTemplate&&"%s"!==t.titleTemplate&&H({component:r,s:"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 H(n,t)}))),W(n,t,e)}(t,V(t,n),x,n),r=rn(n[d].T,t,e);r&&o(e.changed)&&(e.changed(e,r.K,r.M),r={addedTags:r.K,removedTags:r.M});var i=un();if(i){for(var u in i)rn(u,t,i[u]),delete i[u];an(!0)}return{vm:n,metaInfo:e,tags:r}}function cn(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.D&&(n.D=!!e.D,M(t));if(e&&"debounceWait"in e){var r=parseInt(e.m);isNaN(r)||(n.m=r)}e&&"waitOnDestroyed"in e&&(n.l=!!e.l)},refresh:function(){return fn(t,n)},inject:function(){return f("inject")},pause:function(){return w(t)},resume:function(){return K(t)},addApp:function(e){return on(t,e,n)}}}return{version:"2.3.0-beta.0",install:function(n,t){n.__vuemeta_installed||(n.__vuemeta_installed=!0,t=function(n){return{t:(n=r(n)?n:{}).keyName||v.t,i:n.attribute||v.i,o:n.ssrAttribute||v.o,u:n.tagIDKeyName||v.u,s:n.contentKeyName||v.s,v:n.metaTemplateKeyName||v.v,m:e(n.debounceWait)?v.m:n.debounceWait,l:e(n.waitOnDestroyed)?v.l:n.waitOnDestroyed,p:n.ssrAppId||v.p,D:!!n.refreshOnceOnNavigation}}(t),n.prototype.$meta=function(){return cn.call(this,t)},n.mixin(function(n,t){var r=["activated","deactivated","beforeMount"];return{beforeCreate:function(){var i=this.$root,u=this.$options;if(Object.defineProperty(this,"_hasMetaInfo",{configurable:!0,get:function(){return n.config.devtools&&!i[d].S&&(a("VueMeta DeprecationWarning: _hasMetaInfo has been deprecated and will be removed in a future version. Please use hasMetaInfo(vm) instead"),i[d].S=!0),T(this)}}),!e(u[t.t])&&null!==u[t.t]){if(i[d]||(i[d]={T:D},D++),!this[d]){this[d]=!0;for(var f=this.$parent;f&&f!==i;)e(f[d])&&(f[d]=!1),f=f.$parent}o(u[t.t])&&(u.computed=u.computed||{},u.computed.$metaInfo=u[t.t],this.$isServer||j(u,"created",(function(){this.$watch("$metaInfo",(function(){I(t,this.$root,"watcher")}))}))),e(i[d].h)&&(i[d].h=this.$isServer,i[d].h||(j(u,"beforeMount",(function(){var n=this.$root;n.$el&&1===n.$el.nodeType&&n.$el.hasAttribute("data-server-rendered")&&(n[d].T=t.p)})),j(u,"mounted",(function(){var n=this.$root;n[d].h||(n[d].g=!0,this.$nextTick((function(){var e=n.$meta().refresh(),r=e.tags,i=e.metaInfo;!1===r&&null===n[d].h&&this.$nextTick((function(){return I(t,n,"init")})),n[d].h=!0,delete n[d].g,!t.D&&i.afterNavigation&&M(n)})))})),t.D&&M(i))),this.$isServer||r.forEach((function(n){j(u,n,(function(){I(t,this.$root,n)}))}))}},destroyed:function(){var n=this;this.$parent&&T(this)&&this.$nextTick((function(){if(t.l&&n.$el&&n.$el.offsetParent)var e=setInterval((function(){n.$el&&null!==n.$el.offsetParent||(clearInterval(e),I(t,n.$root,"destroyed"))}),50);else I(t,n.$root,"destroyed")}))}}}(n,t)))},generate:function(n){return f("generate")},hasMetaInfo:T}}));