2
0
mirror of https://github.com/tenrok/vue-meta.git synced 2026-06-16 10:30:34 +03:00
Files
vue-meta/dist/vue-meta.esm.browser.min.js
T
2019-08-30 16:19:52 +00:00

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