2
0
mirror of https://github.com/tenrok/vue-meta.git synced 2026-06-21 00:50:33 +03:00
Files
vue-meta/dist/vue-meta.esm.browser.min.js
T
2019-07-26 17:45:31 +02:00

2 lines
15 KiB
JavaScript

import t from"deepmerge";var e=null;function n(t,n){t.$root._vueMeta.initialized||!t.$root._vueMeta.initializing&&"watcher"!==n||(t.$root._vueMeta.initialized=null),t.$root._vueMeta.initialized&&!t.$root._vueMeta.paused&&function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:10;clearTimeout(e),e=setTimeout(function(){t()},n)}(function(){return t.$meta().refresh()})}function r(t){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function o(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function i(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,r)}return n}function a(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?i(n,!0).forEach(function(e){o(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):i(n).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function u(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=[],r=!0,o=!1,i=void 0;try{for(var a,u=t[Symbol.iterator]();!(r=(a=u.next()).done)&&(n.push(a.value),!e||n.length!==e);r=!0);}catch(t){o=!0,i=t}finally{try{r||null==u.return||u.return()}finally{if(o)throw i}}return n}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function c(t){return function(t){if(Array.isArray(t)){for(var e=0,n=new Array(t.length);e<t.length;e++)n[e]=t[e];return n}}(t)||function(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}function l(t){return Array.isArray(t)}function s(t){return void 0===t}function f(t){return"object"===r(t)}function d(t){return"object"===r(t)&&null!==t}function v(t){return"function"==typeof t}function h(t,e){return e&&f(t)?(l(t[e])||(t[e]=[]),t):l(t)?t:[]}function p(t,e,n){h(t,e),t[e].push(n)}function m(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this;return t&&(!0===t._vueMeta||f(t._vueMeta))}function y(t){if(!t.$root._vueMeta.navGuards&&t.$root.$router){t.$root._vueMeta.navGuards=!0;var e=t.$root.$router,n=t.$root.$meta();e.beforeEach(function(t,e,r){n.pause(),r()}),e.afterEach(function(){var t=n.resume().metaInfo;t&&t.afterNavigation&&v(t.afterNavigation)&&t.afterNavigation(t)})}}var g=function(){try{return!s(window)}catch(t){return!1}}()?window:global,b=g.console=g.console||{};function $(){b&&b.warn&&b.warn.apply(b,arguments)}var _=function(){return $("This vue app/component has no vue-meta configuration")},M=1;var w={title:void 0,titleChunk:"",titleTemplate:"%s",htmlAttrs:{},bodyAttrs:{},headAttrs:{},base:[],link:[],meta:[],style:[],script:[],noscript:[],__dangerouslyDisableSanitizers:[],__dangerouslyDisableSanitizersByTagID:{}},T={keyName:"metaInfo",attribute:"data-vue-meta",ssrAttribute:"data-vue-meta-server-rendered",tagIDKeyName:"vmid",contentKeyName:"content",metaTemplateKeyName:"template",ssrAppId:"ssr"},N=["titleChunk","titleTemplate","changed","__dangerouslyDisableSanitizers","__dangerouslyDisableSanitizersByTagID"],A=["__dangerouslyDisableSanitizers","__dangerouslyDisableSanitizersByTagID"],O=["htmlAttrs","headAttrs","bodyAttrs"],I=["link","style","script"],S=["body","pbody"],j=["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"];function D(){var t=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];return this.$root._vueMeta.paused=!0,function(){return K(t)}}function K(){var t=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];if(this.$root._vueMeta.paused=!1,t)return this.$root.$meta().refresh()}function k(t,e,n,r){var o=t.component,i=t.metaTemplateKeyName,a=t.contentKeyName;return s(n)&&(n=e[i],delete e[i]),!!n&&(s(r)&&(r=e[a]),e[a]=v(n)?n.call(o,r):n.replace(/%s/g,r),!0)}function z(t,e){return t.findIndex(e,arguments[2])}function P(t){return Array.from(t)}function E(t,e){return t.includes(e)}var x=[[/&/g,"&"],[/</g,"<"],[/>/g,">"],[/"/g,'"'],[/'/g,"'"]];function C(e,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return n.hasOwnProperty("title")&&void 0===n.title&&delete n.title,O.forEach(function(t){if(n[t])for(var e in n[t])n[t].hasOwnProperty(e)&&void 0===n[t][e]&&(E(j,e)&&$("VueMeta: Please note that since v2 the value undefined is not used to indicate boolean attributes anymore, see migration guide for details"),delete n[t][e])}),t(e,n,{arrayMerge:function(t,e){return function(t,e,n){var r=t.component,o=t.tagIDKeyName,i=t.metaTemplateKeyName,a=t.contentKeyName,u=[];return e.forEach(function(t,e){if(t[o]){var c=z(n,function(e){return e[o]===t[o]}),l=n[c];if(-1!==c){if(l.hasOwnProperty(a)&&void 0===l[a]||l.hasOwnProperty("innerHTML")&&void 0===l.innerHTML)return u.push(t),void n.splice(c,1);if(null!==l[a]&&null!==l.innerHTML){var s=t[i];s&&(l[i]?l[a]||k({component:r,metaTemplateKeyName:i,contentKeyName:a},l,void 0,t[a]):k({component:r,metaTemplateKeyName:i,contentKeyName:a},l,s))}else n.splice(c,1)}else u.push(t)}else u.push(t)}),u.concat(n)}(r,t,e)}})}function L(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=arguments.length>1?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=t.keyName,o=t.metaTemplateKeyName,i=t.tagIDKeyName,a=e.$options,u=e.$children;if(e._inactive)return n;if(a[r]){var c=a[r];if(v(c)&&(c=c.call(e)),!f(c))return n;n=C(n,c,t)}return u.length&&u.forEach(function(e){(function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this;return t&&!s(t._vueMeta)})(e)&&(n=L(t,e,n))}),o&&n.meta&&(n.meta.forEach(function(e){return k(t,e)}),n.meta=n.meta.filter(function(t,e,n){return!t.hasOwnProperty(i)||e===z(n,function(e){return e[i]===t[i]})})),n}function H(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=arguments.length>1?arguments[1]:void 0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],r=L(t,e,w);r.title&&(r.titleChunk=r.title),r.titleTemplate&&"%s"!==r.titleTemplate&&k({component:e,contentKeyName:"title"},r,r.titleTemplate,r.titleChunk||""),r.base&&(r.base=Object.keys(r.base).length?[r.base]:[]);var o={doEscape:function(t){return n.reduce(function(t,e){var n=u(e,2),r=n[0],o=n[1];return t.replace(r,o)},t)}};return A.forEach(function(t,e){if(0===e)h(r,t);else if(1===e)for(var n in r[t])h(r[t],n);o[t]=r[t]}),r=function t(e,n,r){var o=n.tagIDKeyName,i=r.doEscape,c=void 0===i?function(t){return t}:i,s=r.escapeKeys,f={};for(var v in e){var h=e[v];if(E(N,v))f[v]=h;else{var p=u(A,1)[0];if(r[p]&&E(r[p],v))f[v]=h;else{var m=e[o];if(m&&(p=A[1],r[p]&&r[p][m]&&E(r[p][m],v)))f[v]=h;else if("string"==typeof h?f[v]=c(h):l(h)?f[v]=h.map(function(e){return d(e)?t(e,n,a({},r,{escapeKeys:!0})):c(e)}):d(h)?f[v]=t(h,n,a({},r,{escapeKeys:!0})):f[v]=h,s){var y=c(v);v!==y&&(f[y]=f[v],delete f[v])}}}}return f}(r,t,o)}function B(t,e){return t[e]||(t[e]=document.getElementsByTagName(e)[0]),t[e]}function q(t,e){var n=e.appId,r=e.attribute,o=e.type,i=e.tagIDKeyName,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},u=["".concat(o,"[").concat(r,'="').concat(n,'"]'),"".concat(o,"[data-").concat(i,"]")].map(function(t){for(var e in a){var n=a[e],r=n&&!0!==n?'="'.concat(n,'"'):"";t+="[data-".concat(e).concat(r,"]")}return t});return P(t.querySelectorAll(u.join(", ")))}var V=[];function W(t,e){1===arguments.length&&(e=t,t=""),V.push([t,e])}function G(t,e,n,r){var o=t.tagIDKeyName,i=!1,a=!0,u=!1,c=void 0;try{for(var l,s=n[Symbol.iterator]();!(a=(l=s.next()).done);a=!0){var f=l.value;f[o]&&f.callback&&(i=!0,W("".concat(e,"[data-").concat(o,'="').concat(f[o],'"]'),f.callback))}}catch(t){u=!0,c=t}finally{try{a||null==s.return||s.return()}finally{if(u)throw c}}return r&&i?J():i}function J(){!function(){return"complete"===(arguments.length>0&&void 0!==arguments[0]?arguments[0]:document).readyState}()?document.onreadystatechange=function(){F()}:F()}function F(t){for(var e=function(){var e=u(r[n],2),o=e[0],i=e[1],a="".concat(o,'[onload="this.__vm_l=1"]'),c=[];t||(c=P(document.querySelectorAll(a))),t&&t.matches(a)&&(c=[t]);var l=!0,s=!1,f=void 0;try{for(var d,v=function(){var t=d.value;if(t.__vm_cb)return"continue";var e=function(){t.__vm_cb=!0,t.removeAttribute("onload"),i(t)};if(t.__vm_l)return e(),"continue";t.__vm_ev||(t.__vm_ev=!0,t.addEventListener("load",e))},h=c[Symbol.iterator]();!(l=(d=h.next()).done);l=!0)v()}catch(t){s=!0,f=t}finally{try{l||null==h.return||h.return()}finally{if(s)throw f}}},n=0,r=V;n<r.length;n++)e()}function Q(){var t=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).attribute,e=arguments.length>1?arguments[1]:void 0,n=arguments.length>2?arguments[2]:void 0,r=n.getAttribute(t),o=r?r.split(","):[],i=P(o),a=[];for(var u in e)if(e.hasOwnProperty(u)){var c=E(j,u)?"":l(e[u])?e[u].join(" "):e[u];n.setAttribute(u,c||""),E(o,u)||o.push(u),a.push(i.indexOf(u))}var s=i.filter(function(t,e){return!E(a,e)}).reduce(function(t,e){return n.removeAttribute(e),t+1},0);o.length===s?n.removeAttribute(t):n.setAttribute(t,o.sort().join(","))}function R(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0,r=arguments.length>3?arguments[3]:void 0,o=arguments.length>4?arguments[4]:void 0,i=arguments.length>5?arguments[5]:void 0,a=e.attribute,u=e.tagIDKeyName,l=[u].concat(c(S)),s=[],f={appId:t,attribute:a,type:n,tagIDKeyName:u},d={head:q(o,f),pbody:q(i,f,{pbody:!0}),body:q(i,f,{body:!0})};if(r.length>1){var v=[];r=r.filter(function(t){var e=JSON.stringify(t),n=!E(v,e);return v.push(e),n})}if(r.length){var h=!0,p=!1,m=void 0;try{for(var y,g=function(){var e=y.value;if(e.skip)return"continue";var r=document.createElement(n);r.setAttribute(a,t);var o=function(t){if(!e.hasOwnProperty(t))return"continue";if("innerHTML"===t)return r.innerHTML=e.innerHTML,"continue";if("json"===t)return r.innerHTML=JSON.stringify(e.json),"continue";if("cssText"===t)return r.styleSheet?r.styleSheet.cssText=e.cssText:r.appendChild(document.createTextNode(e.cssText)),"continue";if("callback"===t)return r.onload=function(){return e[t](r)},"continue";var n=E(l,t)?"data-".concat(t):t,o=E(j,t);if(o&&!e[t])return"continue";var i=o?"":e[t];r.setAttribute(n,i)};for(var i in e)o(i);var u=d[function(t){var e=t.body,n=t.pbody;return e?"body":n?"pbody":"head"}(e)],c=void 0;u.some(function(t,e){return c=e,r.isEqualNode(t)})&&(c||0===c)?u.splice(c,1):s.push(r)},b=r[Symbol.iterator]();!(h=(y=b.next()).done);h=!0)g()}catch(t){p=!0,m=t}finally{try{h||null==b.return||b.return()}finally{if(p)throw m}}}for(var $=[],_=0,M=Object.values(d);_<M.length;_++){var w=M[_];$=[].concat(c($),c(w))}for(var T=0,N=$;T<N.length;T++){var A=N[T];A.parentNode.removeChild(A)}for(var O=0,I=s;O<I.length;O++){var D=I[O];D.hasAttribute("data-body")?i.appendChild(D):D.hasAttribute("data-pbody")?i.insertBefore(D,i.firstChild):o.appendChild(D)}return{oldTags:$,newTags:s}}function U(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(){var e=H(t,this.$root,x),n=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0,r=e.ssrAttribute,o=e.ssrAppId,i={},a=B(i,"html");if(t===o&&a.hasAttribute(r)){a.removeAttribute(r);var u=!1,c=!0,s=!1,f=void 0;try{for(var d,v=I[Symbol.iterator]();!(c=(d=v.next()).done);c=!0){var h=d.value;n[h]&&G(e,h,n[h])&&(u=!0)}}catch(t){s=!0,f=t}finally{try{c||null==v.return||v.return()}finally{if(s)throw f}}return u&&J(),!1}var p,m={},y={};for(var g in n)if(!E(N,g))if("title"!==g){if(E(O,g)){var b=g.substr(0,4);Q(e,n[g],B(i,b))}else if(l(n[g])){var $=R(t,e,g,n[g],B(i,"head"),B(i,"body")),_=$.oldTags,M=$.newTags;M.length&&(m[g]=M,y[g]=_)}}else((p=n.title)||""===p)&&(document.title=p);return{addedTags:m,removedTags:y}}(this.$root._vueMeta.appId,t,e);return n&&v(e.changed)&&e.changed(e,n.addedTags,n.removedTags),{vm:this,metaInfo:e,tags:n}}}function X(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};t.__vuemeta_installed||(t.__vuemeta_installed=!0,e=function(t){for(var e in t=f(t)?t:{},T)t[e]||(t[e]=T[e]);return t}(e),t.prototype.$meta=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=U(t),n=function(){};return function(){return this.$root._vueMeta?{getOptions:function(){return function(t){var e={};for(var n in t)e[n]=t[n];return e}(t)},refresh:e.bind(this),inject:n,pause:D.bind(this),resume:K.bind(this)}:{getOptions:_,refresh:_,inject:_,pause:_,resume:_}}}(e),t.mixin(function(t,e){var r=["activated","deactivated","beforeMount"];return{beforeCreate:function(){var o=this;if(Object.defineProperty(this,"_hasMetaInfo",{configurable:!0,get:function(){return t.config.devtools&&!this.$root._vueMeta.hasMetaInfoDeprecationWarningShown&&($("VueMeta DeprecationWarning: _hasMetaInfo has been deprecated and will be removed in a future version. Please use hasMetaInfo(vm) instead"),this.$root._vueMeta.hasMetaInfoDeprecationWarningShown=!0),m(this)}}),!s(this.$options[e.keyName])&&null!==this.$options[e.keyName]){if(this.$root._vueMeta||(this.$root._vueMeta={appId:M},M++),!this._vueMeta){this._vueMeta=!0;for(var i=this.$parent;i&&i!==this.$root;)s(i._vueMeta)&&(i._vueMeta=!1),i=i.$parent}v(this.$options[e.keyName])&&(this.$options.computed||(this.$options.computed={}),this.$options.computed.$metaInfo=this.$options[e.keyName],this.$isServer||p(this.$options,"created",function(){o.$watch("$metaInfo",function(){n(this,"watcher")})})),s(this.$root._vueMeta.initialized)&&(this.$root._vueMeta.initialized=this.$isServer,this.$root._vueMeta.initialized||(p(this.$options,"beforeMount",function(){o.$root.$el&&o.$root.$el.hasAttribute&&o.$root.$el.hasAttribute("data-server-rendered")&&(o.$root._vueMeta.appId=e.ssrAppId)}),p(this.$options,"mounted",function(){o.$root._vueMeta.initialized||(o.$root._vueMeta.initializing=!0,o.$nextTick(function(){var t=this,r=this.$root.$meta().refresh(),o=r.tags,i=r.metaInfo;!1===o&&null===this.$root._vueMeta.initialized&&this.$nextTick(function(){return n(t,"initializing")}),this.$root._vueMeta.initialized=!0,delete this.$root._vueMeta.initializing,!e.refreshOnceOnNavigation&&i.afterNavigation&&y(this)}))}),e.refreshOnceOnNavigation&&y(this))),this.$isServer||(r.forEach(function(t){p(o.$options,t,function(){return n(o,t)})}),p(this.$options,"destroyed",function(){var t=setInterval(function(){o.$el&&null!==o.$el.offsetParent||(clearInterval(t),o.$parent&&n(o,"destroyed"))},50)}))}}}}(t,e)))}s(window)||s(window.Vue)||X(window.Vue);var Y={version:"2.1.1",install:X,hasMetaInfo:m};export default Y;