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

2 lines
15 KiB
JavaScript

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