2
0
mirror of https://github.com/tenrok/vue-meta.git synced 2026-06-20 16:40:35 +03:00
Files
vue-meta/dist/vue-meta.min.js
T
2019-07-26 17:45:31 +02:00

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