vue-meta.common.js 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017
  1. /**
  2. * vue-meta v2.4.0
  3. * (c) 2020
  4. * - Declan de Wet
  5. * - Sébastien Chopin (@Atinux)
  6. * - Pim (@pimlie)
  7. * - All the amazing contributors
  8. * @license MIT
  9. */
  10. 'use strict';
  11. function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
  12. var deepmerge = _interopDefault(require('deepmerge'));
  13. var version = "2.4.0";
  14. function _typeof(obj) {
  15. "@babel/helpers - typeof";
  16. if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
  17. _typeof = function (obj) {
  18. return typeof obj;
  19. };
  20. } else {
  21. _typeof = function (obj) {
  22. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  23. };
  24. }
  25. return _typeof(obj);
  26. }
  27. function _defineProperty(obj, key, value) {
  28. if (key in obj) {
  29. Object.defineProperty(obj, key, {
  30. value: value,
  31. enumerable: true,
  32. configurable: true,
  33. writable: true
  34. });
  35. } else {
  36. obj[key] = value;
  37. }
  38. return obj;
  39. }
  40. function ownKeys(object, enumerableOnly) {
  41. var keys = Object.keys(object);
  42. if (Object.getOwnPropertySymbols) {
  43. var symbols = Object.getOwnPropertySymbols(object);
  44. if (enumerableOnly) symbols = symbols.filter(function (sym) {
  45. return Object.getOwnPropertyDescriptor(object, sym).enumerable;
  46. });
  47. keys.push.apply(keys, symbols);
  48. }
  49. return keys;
  50. }
  51. function _objectSpread2(target) {
  52. for (var i = 1; i < arguments.length; i++) {
  53. var source = arguments[i] != null ? arguments[i] : {};
  54. if (i % 2) {
  55. ownKeys(Object(source), true).forEach(function (key) {
  56. _defineProperty(target, key, source[key]);
  57. });
  58. } else if (Object.getOwnPropertyDescriptors) {
  59. Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
  60. } else {
  61. ownKeys(Object(source)).forEach(function (key) {
  62. Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
  63. });
  64. }
  65. }
  66. return target;
  67. }
  68. function _toConsumableArray(arr) {
  69. return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
  70. }
  71. function _arrayWithoutHoles(arr) {
  72. if (Array.isArray(arr)) return _arrayLikeToArray(arr);
  73. }
  74. function _iterableToArray(iter) {
  75. if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
  76. }
  77. function _unsupportedIterableToArray(o, minLen) {
  78. if (!o) return;
  79. if (typeof o === "string") return _arrayLikeToArray(o, minLen);
  80. var n = Object.prototype.toString.call(o).slice(8, -1);
  81. if (n === "Object" && o.constructor) n = o.constructor.name;
  82. if (n === "Map" || n === "Set") return Array.from(o);
  83. if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
  84. }
  85. function _arrayLikeToArray(arr, len) {
  86. if (len == null || len > arr.length) len = arr.length;
  87. for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
  88. return arr2;
  89. }
  90. function _nonIterableSpread() {
  91. throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  92. }
  93. function _createForOfIteratorHelper(o, allowArrayLike) {
  94. var it;
  95. if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
  96. if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
  97. if (it) o = it;
  98. var i = 0;
  99. var F = function () {};
  100. return {
  101. s: F,
  102. n: function () {
  103. if (i >= o.length) return {
  104. done: true
  105. };
  106. return {
  107. done: false,
  108. value: o[i++]
  109. };
  110. },
  111. e: function (e) {
  112. throw e;
  113. },
  114. f: F
  115. };
  116. }
  117. throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  118. }
  119. var normalCompletion = true,
  120. didErr = false,
  121. err;
  122. return {
  123. s: function () {
  124. it = o[Symbol.iterator]();
  125. },
  126. n: function () {
  127. var step = it.next();
  128. normalCompletion = step.done;
  129. return step;
  130. },
  131. e: function (e) {
  132. didErr = true;
  133. err = e;
  134. },
  135. f: function () {
  136. try {
  137. if (!normalCompletion && it.return != null) it.return();
  138. } finally {
  139. if (didErr) throw err;
  140. }
  141. }
  142. };
  143. }
  144. /**
  145. * checks if passed argument is an array
  146. * @param {any} arg - the object to check
  147. * @return {Boolean} - true if `arg` is an array
  148. */
  149. function isArray(arg) {
  150. return Array.isArray(arg);
  151. }
  152. function isUndefined(arg) {
  153. return typeof arg === 'undefined';
  154. }
  155. function isObject(arg) {
  156. return _typeof(arg) === 'object';
  157. }
  158. function isPureObject(arg) {
  159. return _typeof(arg) === 'object' && arg !== null;
  160. }
  161. function isFunction(arg) {
  162. return typeof arg === 'function';
  163. }
  164. function isString(arg) {
  165. return typeof arg === 'string';
  166. }
  167. function hasGlobalWindowFn() {
  168. try {
  169. return !isUndefined(window);
  170. } catch (e) {
  171. return false;
  172. }
  173. }
  174. var hasGlobalWindow = hasGlobalWindowFn();
  175. var _global = hasGlobalWindow ? window : global;
  176. var console = _global.console || {};
  177. function warn(str) {
  178. /* istanbul ignore next */
  179. if (!console || !console.warn) {
  180. return;
  181. }
  182. console.warn(str);
  183. }
  184. var showWarningNotSupported = function showWarningNotSupported() {
  185. return warn('This vue app/component has no vue-meta configuration');
  186. };
  187. /**
  188. * These are constant variables used throughout the application.
  189. */
  190. // set some sane defaults
  191. var defaultInfo = {
  192. title: undefined,
  193. titleChunk: '',
  194. titleTemplate: '%s',
  195. htmlAttrs: {},
  196. bodyAttrs: {},
  197. headAttrs: {},
  198. base: [],
  199. link: [],
  200. meta: [],
  201. style: [],
  202. script: [],
  203. noscript: [],
  204. __dangerouslyDisableSanitizers: [],
  205. __dangerouslyDisableSanitizersByTagID: {}
  206. };
  207. var rootConfigKey = '_vueMeta'; // This is the name of the component option that contains all the information that
  208. // gets converted to the various meta tags & attributes for the page.
  209. var keyName = 'metaInfo'; // This is the attribute vue-meta arguments on elements to know which it should
  210. // manage and which it should ignore.
  211. var attribute = 'data-vue-meta'; // This is the attribute that goes on the `html` tag to inform `vue-meta`
  212. // that the server has already generated the meta tags for the initial render.
  213. var ssrAttribute = 'data-vue-meta-server-rendered'; // This is the property that tells vue-meta to overwrite (instead of append)
  214. // an item in a tag list. For example, if you have two `meta` tag list items
  215. // that both have `vmid` of "description", then vue-meta will overwrite the
  216. // shallowest one with the deepest one.
  217. var tagIDKeyName = 'vmid'; // This is the key name for possible meta templates
  218. var metaTemplateKeyName = 'template'; // This is the key name for the content-holding property
  219. var contentKeyName = 'content'; // The id used for the ssr app
  220. var ssrAppId = 'ssr'; // How long meta update
  221. var debounceWait = 10; // How long meta update
  222. var waitOnDestroyed = true;
  223. var defaultOptions = {
  224. keyName: keyName,
  225. attribute: attribute,
  226. ssrAttribute: ssrAttribute,
  227. tagIDKeyName: tagIDKeyName,
  228. contentKeyName: contentKeyName,
  229. metaTemplateKeyName: metaTemplateKeyName,
  230. waitOnDestroyed: waitOnDestroyed,
  231. debounceWait: debounceWait,
  232. ssrAppId: ssrAppId
  233. }; // might be a bit ugly, but minimizes the browser bundles a bit
  234. var defaultInfoKeys = Object.keys(defaultInfo); // The metaInfo property keys which are used to disable escaping
  235. var disableOptionKeys = [defaultInfoKeys[12], defaultInfoKeys[13]]; // List of metaInfo property keys which are configuration options (and dont generate html)
  236. var metaInfoOptionKeys = [defaultInfoKeys[1], defaultInfoKeys[2], 'changed'].concat(disableOptionKeys); // List of metaInfo property keys which only generates attributes and no tags
  237. var metaInfoAttributeKeys = [defaultInfoKeys[3], defaultInfoKeys[4], defaultInfoKeys[5]]; // HTML elements which support the onload event
  238. var tagsSupportingOnload = ['link', 'style', 'script']; // HTML elements which dont have a head tag (shortened to our needs)
  239. // see: https://www.w3.org/TR/html52/document-metadata.html
  240. var tagsWithoutEndTag = ['base', 'meta', 'link']; // HTML elements which can have inner content (shortened to our needs)
  241. var tagsWithInnerContent = ['noscript', 'script', 'style']; // Attributes which are inserted as childNodes instead of HTMLAttribute
  242. var tagAttributeAsInnerContent = ['innerHTML', 'cssText', 'json'];
  243. var tagProperties = ['once', 'skip', 'template']; // Attributes which should be added with data- prefix
  244. var commonDataAttributes = ['body', 'pbody']; // from: https://github.com/kangax/html-minifier/blob/gh-pages/src/htmlminifier.js#L202
  245. var booleanHtmlAttributes = ['allowfullscreen', 'amp', 'amp-boilerplate', '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'];
  246. var batchId = null;
  247. function triggerUpdate(_ref, rootVm, hookName) {
  248. var debounceWait = _ref.debounceWait;
  249. // if an update was triggered during initialization or when an update was triggered by the
  250. // metaInfo watcher, set initialized to null
  251. // then we keep falsy value but know we need to run a triggerUpdate after initialization
  252. if (!rootVm[rootConfigKey].initialized && (rootVm[rootConfigKey].initializing || hookName === 'watcher')) {
  253. rootVm[rootConfigKey].initialized = null;
  254. }
  255. if (rootVm[rootConfigKey].initialized && !rootVm[rootConfigKey].pausing) {
  256. // batch potential DOM updates to prevent extraneous re-rendering
  257. // eslint-disable-next-line no-void
  258. batchUpdate(function () {
  259. return void rootVm.$meta().refresh();
  260. }, debounceWait);
  261. }
  262. }
  263. /**
  264. * Performs a batched update.
  265. *
  266. * @param {(null|Number)} id - the ID of this update
  267. * @param {Function} callback - the update to perform
  268. * @return {Number} id - a new ID
  269. */
  270. function batchUpdate(callback, timeout) {
  271. timeout = timeout === undefined ? 10 : timeout;
  272. if (!timeout) {
  273. callback();
  274. return;
  275. }
  276. clearTimeout(batchId);
  277. batchId = setTimeout(function () {
  278. callback();
  279. }, timeout);
  280. return batchId;
  281. }
  282. /*
  283. * To reduce build size, this file provides simple polyfills without
  284. * overly excessive type checking and without modifying
  285. * the global Array.prototype
  286. * The polyfills are automatically removed in the commonjs build
  287. * Also, only files in client/ & shared/ should use these functions
  288. * files in server/ still use normal js function
  289. */
  290. function find(array, predicate, thisArg) {
  291. if ( !Array.prototype.find) {
  292. // idx needs to be a Number, for..in returns string
  293. for (var idx = 0; idx < array.length; idx++) {
  294. if (predicate.call(thisArg, array[idx], idx, array)) {
  295. return array[idx];
  296. }
  297. }
  298. return;
  299. }
  300. return array.find(predicate, thisArg);
  301. }
  302. function findIndex(array, predicate, thisArg) {
  303. if ( !Array.prototype.findIndex) {
  304. // idx needs to be a Number, for..in returns string
  305. for (var idx = 0; idx < array.length; idx++) {
  306. if (predicate.call(thisArg, array[idx], idx, array)) {
  307. return idx;
  308. }
  309. }
  310. return -1;
  311. }
  312. return array.findIndex(predicate, thisArg);
  313. }
  314. function toArray(arg) {
  315. if ( !Array.from) {
  316. return Array.prototype.slice.call(arg);
  317. }
  318. return Array.from(arg);
  319. }
  320. function includes(array, value) {
  321. if ( !Array.prototype.includes) {
  322. for (var idx in array) {
  323. if (array[idx] === value) {
  324. return true;
  325. }
  326. }
  327. return false;
  328. }
  329. return array.includes(value);
  330. }
  331. var querySelector = function querySelector(arg, el) {
  332. return (el || document).querySelectorAll(arg);
  333. };
  334. function getTag(tags, tag) {
  335. if (!tags[tag]) {
  336. tags[tag] = document.getElementsByTagName(tag)[0];
  337. }
  338. return tags[tag];
  339. }
  340. function getElementsKey(_ref) {
  341. var body = _ref.body,
  342. pbody = _ref.pbody;
  343. return body ? 'body' : pbody ? 'pbody' : 'head';
  344. }
  345. function queryElements(parentNode, _ref2, attributes) {
  346. var appId = _ref2.appId,
  347. attribute = _ref2.attribute,
  348. type = _ref2.type,
  349. tagIDKeyName = _ref2.tagIDKeyName;
  350. attributes = attributes || {};
  351. var queries = ["".concat(type, "[").concat(attribute, "=\"").concat(appId, "\"]"), "".concat(type, "[data-").concat(tagIDKeyName, "]")].map(function (query) {
  352. for (var key in attributes) {
  353. var val = attributes[key];
  354. var attributeValue = val && val !== true ? "=\"".concat(val, "\"") : '';
  355. query += "[data-".concat(key).concat(attributeValue, "]");
  356. }
  357. return query;
  358. });
  359. return toArray(querySelector(queries.join(', '), parentNode));
  360. }
  361. function removeElementsByAppId(_ref3, appId) {
  362. var attribute = _ref3.attribute;
  363. toArray(querySelector("[".concat(attribute, "=\"").concat(appId, "\"]"))).map(function (el) {
  364. return el.remove();
  365. });
  366. }
  367. function removeAttribute(el, attributeName) {
  368. el.removeAttribute(attributeName);
  369. }
  370. function hasMetaInfo(vm) {
  371. vm = vm || this;
  372. return vm && (vm[rootConfigKey] === true || isObject(vm[rootConfigKey]));
  373. } // a component is in a metaInfo branch when itself has meta info or one of its (grand-)children has
  374. function inMetaInfoBranch(vm) {
  375. vm = vm || this;
  376. return vm && !isUndefined(vm[rootConfigKey]);
  377. }
  378. function pause(rootVm, refresh) {
  379. rootVm[rootConfigKey].pausing = true;
  380. return function () {
  381. return resume(rootVm, refresh);
  382. };
  383. }
  384. function resume(rootVm, refresh) {
  385. rootVm[rootConfigKey].pausing = false;
  386. if (refresh || refresh === undefined) {
  387. return rootVm.$meta().refresh();
  388. }
  389. }
  390. function addNavGuards(rootVm) {
  391. var router = rootVm.$router; // return when nav guards already added or no router exists
  392. if (rootVm[rootConfigKey].navGuards || !router) {
  393. /* istanbul ignore next */
  394. return;
  395. }
  396. rootVm[rootConfigKey].navGuards = true;
  397. router.beforeEach(function (to, from, next) {
  398. pause(rootVm);
  399. next();
  400. });
  401. router.afterEach(function () {
  402. rootVm.$nextTick(function () {
  403. var _resume = resume(rootVm),
  404. metaInfo = _resume.metaInfo;
  405. if (metaInfo && isFunction(metaInfo.afterNavigation)) {
  406. metaInfo.afterNavigation(metaInfo);
  407. }
  408. });
  409. });
  410. }
  411. var appId = 1;
  412. function createMixin(Vue, options) {
  413. // for which Vue lifecycle hooks should the metaInfo be refreshed
  414. var updateOnLifecycleHook = ['activated', 'deactivated', 'beforeMount'];
  415. var wasServerRendered = false; // watch for client side component updates
  416. return {
  417. beforeCreate: function beforeCreate() {
  418. var _this2 = this;
  419. var rootKey = '$root';
  420. var $root = this[rootKey];
  421. var $options = this.$options;
  422. var devtoolsEnabled = Vue.config.devtools;
  423. Object.defineProperty(this, '_hasMetaInfo', {
  424. configurable: true,
  425. get: function get() {
  426. // Show deprecation warning once when devtools enabled
  427. if (devtoolsEnabled && !$root[rootConfigKey].deprecationWarningShown) {
  428. warn('VueMeta DeprecationWarning: _hasMetaInfo has been deprecated and will be removed in a future version. Please use hasMetaInfo(vm) instead');
  429. $root[rootConfigKey].deprecationWarningShown = true;
  430. }
  431. return hasMetaInfo(this);
  432. }
  433. });
  434. if (this === $root) {
  435. $root.$once('hook:beforeMount', function () {
  436. wasServerRendered = this.$el && this.$el.nodeType === 1 && this.$el.hasAttribute('data-server-rendered'); // In most cases when you have a SSR app it will be the first app thats gonna be
  437. // initiated, if we cant detect the data-server-rendered attribute from Vue but we
  438. // do see our own ssrAttribute then _assume_ the Vue app with appId 1 is the ssr app
  439. // attempted fix for #404 & #562, but we rly need to refactor how we pass appIds from
  440. // ssr to the client
  441. if (!wasServerRendered && $root[rootConfigKey] && $root[rootConfigKey].appId === 1) {
  442. var htmlTag = getTag({}, 'html');
  443. wasServerRendered = htmlTag && htmlTag.hasAttribute(options.ssrAttribute);
  444. }
  445. });
  446. } // Add a marker to know if it uses metaInfo
  447. // _vnode is used to know that it's attached to a real component
  448. // useful if we use some mixin to add some meta tags (like nuxt-i18n)
  449. if (isUndefined($options[options.keyName]) || $options[options.keyName] === null) {
  450. return;
  451. }
  452. if (!$root[rootConfigKey]) {
  453. $root[rootConfigKey] = {
  454. appId: appId
  455. };
  456. appId++;
  457. if (devtoolsEnabled && $root.$options[options.keyName]) {
  458. // use nextTick so the children should be added to $root
  459. this.$nextTick(function () {
  460. // find the first child that lists fnOptions
  461. var child = find($root.$children, function (c) {
  462. return c.$vnode && c.$vnode.fnOptions;
  463. });
  464. if (child && child.$vnode.fnOptions[options.keyName]) {
  465. warn("VueMeta has detected a possible global mixin which adds a ".concat(options.keyName, " property to all Vue components on the page. This could cause severe performance issues. If possible, use $meta().addApp to add meta information instead"));
  466. }
  467. });
  468. }
  469. } // to speed up updates we keep track of branches which have a component with vue-meta info defined
  470. // if _vueMeta = true it has info, if _vueMeta = false a child has info
  471. if (!this[rootConfigKey]) {
  472. this[rootConfigKey] = true;
  473. var parent = this.$parent;
  474. while (parent && parent !== $root) {
  475. if (isUndefined(parent[rootConfigKey])) {
  476. parent[rootConfigKey] = false;
  477. }
  478. parent = parent.$parent;
  479. }
  480. } // coerce function-style metaInfo to a computed prop so we can observe
  481. // it on creation
  482. if (isFunction($options[options.keyName])) {
  483. $options.computed = $options.computed || {};
  484. $options.computed.$metaInfo = $options[options.keyName];
  485. if (!this.$isServer) {
  486. // if computed $metaInfo exists, watch it for updates & trigger a refresh
  487. // when it changes (i.e. automatically handle async actions that affect metaInfo)
  488. // credit for this suggestion goes to [Sébastien Chopin](https://github.com/Atinux)
  489. this.$on('hook:created', function () {
  490. this.$watch('$metaInfo', function () {
  491. triggerUpdate(options, this[rootKey], 'watcher');
  492. });
  493. });
  494. }
  495. } // force an initial refresh on page load and prevent other lifecycleHooks
  496. // to triggerUpdate until this initial refresh is finished
  497. // this is to make sure that when a page is opened in an inactive tab which
  498. // has throttled rAF/timers we still immediately set the page title
  499. if (isUndefined($root[rootConfigKey].initialized)) {
  500. $root[rootConfigKey].initialized = this.$isServer;
  501. if (!$root[rootConfigKey].initialized) {
  502. if (!$root[rootConfigKey].initializedSsr) {
  503. $root[rootConfigKey].initializedSsr = true;
  504. this.$on('hook:beforeMount', function () {
  505. var $root = this[rootKey]; // if this Vue-app was server rendered, set the appId to 'ssr'
  506. // only one SSR app per page is supported
  507. if (wasServerRendered) {
  508. $root[rootConfigKey].appId = options.ssrAppId;
  509. }
  510. });
  511. } // we use the mounted hook here as on page load
  512. this.$on('hook:mounted', function () {
  513. var $root = this[rootKey];
  514. if ($root[rootConfigKey].initialized) {
  515. return;
  516. } // used in triggerUpdate to check if a change was triggered
  517. // during initialization
  518. $root[rootConfigKey].initializing = true; // refresh meta in nextTick so all child components have loaded
  519. this.$nextTick(function () {
  520. var _$root$$meta$refresh = $root.$meta().refresh(),
  521. tags = _$root$$meta$refresh.tags,
  522. metaInfo = _$root$$meta$refresh.metaInfo; // After ssr hydration (identifier by tags === false) check
  523. // if initialized was set to null in triggerUpdate. That'd mean
  524. // that during initilazation changes where triggered which need
  525. // to be applied OR a metaInfo watcher was triggered before the
  526. // current hook was called
  527. // (during initialization all changes are blocked)
  528. if (tags === false && $root[rootConfigKey].initialized === null) {
  529. this.$nextTick(function () {
  530. return triggerUpdate(options, $root, 'init');
  531. });
  532. }
  533. $root[rootConfigKey].initialized = true;
  534. delete $root[rootConfigKey].initializing; // add the navigation guards if they havent been added yet
  535. // they are needed for the afterNavigation callback
  536. if (!options.refreshOnceOnNavigation && metaInfo.afterNavigation) {
  537. addNavGuards($root);
  538. }
  539. });
  540. }); // add the navigation guards if requested
  541. if (options.refreshOnceOnNavigation) {
  542. addNavGuards($root);
  543. }
  544. }
  545. }
  546. this.$on('hook:destroyed', function () {
  547. var _this = this;
  548. // do not trigger refresh:
  549. // - when user configured to not wait for transitions on destroyed
  550. // - when the component doesnt have a parent
  551. // - doesnt have metaInfo defined
  552. if (!this.$parent || !hasMetaInfo(this)) {
  553. return;
  554. }
  555. delete this._hasMetaInfo;
  556. this.$nextTick(function () {
  557. if (!options.waitOnDestroyed || !_this.$el || !_this.$el.offsetParent) {
  558. triggerUpdate(options, _this.$root, 'destroyed');
  559. return;
  560. } // Wait that element is hidden before refreshing meta tags (to support animations)
  561. var interval = setInterval(function () {
  562. if (_this.$el && _this.$el.offsetParent !== null) {
  563. /* istanbul ignore next line */
  564. return;
  565. }
  566. clearInterval(interval);
  567. triggerUpdate(options, _this.$root, 'destroyed');
  568. }, 50);
  569. });
  570. }); // do not trigger refresh on the server side
  571. if (this.$isServer) {
  572. /* istanbul ignore next */
  573. return;
  574. } // no need to add this hooks on server side
  575. updateOnLifecycleHook.forEach(function (lifecycleHook) {
  576. _this2.$on("hook:".concat(lifecycleHook), function () {
  577. triggerUpdate(options, this[rootKey], lifecycleHook);
  578. });
  579. });
  580. }
  581. };
  582. }
  583. function setOptions(options) {
  584. // combine options
  585. options = isObject(options) ? options : {}; // The options are set like this so they can
  586. // be minified by terser while keeping the
  587. // user api intact
  588. // terser --mangle-properties keep_quoted=strict
  589. /* eslint-disable dot-notation */
  590. return {
  591. keyName: options['keyName'] || defaultOptions.keyName,
  592. attribute: options['attribute'] || defaultOptions.attribute,
  593. ssrAttribute: options['ssrAttribute'] || defaultOptions.ssrAttribute,
  594. tagIDKeyName: options['tagIDKeyName'] || defaultOptions.tagIDKeyName,
  595. contentKeyName: options['contentKeyName'] || defaultOptions.contentKeyName,
  596. metaTemplateKeyName: options['metaTemplateKeyName'] || defaultOptions.metaTemplateKeyName,
  597. debounceWait: isUndefined(options['debounceWait']) ? defaultOptions.debounceWait : options['debounceWait'],
  598. waitOnDestroyed: isUndefined(options['waitOnDestroyed']) ? defaultOptions.waitOnDestroyed : options['waitOnDestroyed'],
  599. ssrAppId: options['ssrAppId'] || defaultOptions.ssrAppId,
  600. refreshOnceOnNavigation: !!options['refreshOnceOnNavigation']
  601. };
  602. /* eslint-enable dot-notation */
  603. }
  604. function getOptions(options) {
  605. var optionsCopy = {};
  606. for (var key in options) {
  607. optionsCopy[key] = options[key];
  608. }
  609. return optionsCopy;
  610. }
  611. function ensureIsArray(arg, key) {
  612. if (!key || !isObject(arg)) {
  613. return isArray(arg) ? arg : [];
  614. }
  615. if (!isArray(arg[key])) {
  616. arg[key] = [];
  617. }
  618. return arg;
  619. }
  620. var serverSequences = [[/&/g, '&amp;'], [/</g, '&lt;'], [/>/g, '&gt;'], [/"/g, '&quot;'], [/'/g, '&#x27;']];
  621. var clientSequences = [[/&/g, "&"], [/</g, "<"], [/>/g, ">"], [/"/g, "\""], [/'/g, "'"]]; // sanitizes potentially dangerous characters
  622. function escape(info, options, escapeOptions, escapeKeys) {
  623. var tagIDKeyName = options.tagIDKeyName;
  624. var _escapeOptions$doEsca = escapeOptions.doEscape,
  625. doEscape = _escapeOptions$doEsca === void 0 ? function (v) {
  626. return v;
  627. } : _escapeOptions$doEsca;
  628. var escaped = {};
  629. for (var key in info) {
  630. var value = info[key]; // no need to escape configuration options
  631. if (includes(metaInfoOptionKeys, key)) {
  632. escaped[key] = value;
  633. continue;
  634. } // do not use destructuring for disableOptionKeys, it increases transpiled size
  635. // due to var checks while we are guaranteed the structure of the cb
  636. var disableKey = disableOptionKeys[0];
  637. if (escapeOptions[disableKey] && includes(escapeOptions[disableKey], key)) {
  638. // this info[key] doesnt need to escaped if the option is listed in __dangerouslyDisableSanitizers
  639. escaped[key] = value;
  640. continue;
  641. }
  642. var tagId = info[tagIDKeyName];
  643. if (tagId) {
  644. disableKey = disableOptionKeys[1]; // keys which are listed in __dangerouslyDisableSanitizersByTagID for the current vmid do not need to be escaped
  645. if (escapeOptions[disableKey] && escapeOptions[disableKey][tagId] && includes(escapeOptions[disableKey][tagId], key)) {
  646. escaped[key] = value;
  647. continue;
  648. }
  649. }
  650. if (isString(value)) {
  651. escaped[key] = doEscape(value);
  652. } else if (isArray(value)) {
  653. escaped[key] = value.map(function (v) {
  654. if (isPureObject(v)) {
  655. return escape(v, options, escapeOptions, true);
  656. }
  657. return doEscape(v);
  658. });
  659. } else if (isPureObject(value)) {
  660. escaped[key] = escape(value, options, escapeOptions, true);
  661. } else {
  662. escaped[key] = value;
  663. }
  664. if (escapeKeys) {
  665. var escapedKey = doEscape(key);
  666. if (key !== escapedKey) {
  667. escaped[escapedKey] = escaped[key];
  668. delete escaped[key];
  669. }
  670. }
  671. }
  672. return escaped;
  673. }
  674. function escapeMetaInfo(options, info, escapeSequences) {
  675. escapeSequences = escapeSequences || []; // do not use destructuring for seq, it increases transpiled size
  676. // due to var checks while we are guaranteed the structure of the cb
  677. var escapeOptions = {
  678. doEscape: function doEscape(value) {
  679. return escapeSequences.reduce(function (val, seq) {
  680. return val.replace(seq[0], seq[1]);
  681. }, value);
  682. }
  683. };
  684. disableOptionKeys.forEach(function (disableKey, index) {
  685. if (index === 0) {
  686. ensureIsArray(info, disableKey);
  687. } else if (index === 1) {
  688. for (var key in info[disableKey]) {
  689. ensureIsArray(info[disableKey], key);
  690. }
  691. }
  692. escapeOptions[disableKey] = info[disableKey];
  693. }); // begin sanitization
  694. return escape(info, options, escapeOptions);
  695. }
  696. function applyTemplate(_ref, headObject, template, chunk) {
  697. var component = _ref.component,
  698. metaTemplateKeyName = _ref.metaTemplateKeyName,
  699. contentKeyName = _ref.contentKeyName;
  700. if (template === true || headObject[metaTemplateKeyName] === true) {
  701. // abort, template was already applied
  702. return false;
  703. }
  704. if (isUndefined(template) && headObject[metaTemplateKeyName]) {
  705. template = headObject[metaTemplateKeyName];
  706. headObject[metaTemplateKeyName] = true;
  707. } // return early if no template defined
  708. if (!template) {
  709. // cleanup faulty template properties
  710. delete headObject[metaTemplateKeyName];
  711. return false;
  712. }
  713. if (isUndefined(chunk)) {
  714. chunk = headObject[contentKeyName];
  715. }
  716. headObject[contentKeyName] = isFunction(template) ? template.call(component, chunk) : template.replace(/%s/g, chunk);
  717. return true;
  718. }
  719. function _arrayMerge(_ref, target, source) {
  720. var component = _ref.component,
  721. tagIDKeyName = _ref.tagIDKeyName,
  722. metaTemplateKeyName = _ref.metaTemplateKeyName,
  723. contentKeyName = _ref.contentKeyName;
  724. // we concat the arrays without merging objects contained in,
  725. // but we check for a `vmid` property on each object in the array
  726. // using an O(1) lookup associative array exploit
  727. var destination = [];
  728. if (!target.length && !source.length) {
  729. return destination;
  730. }
  731. target.forEach(function (targetItem, targetIndex) {
  732. // no tagID so no need to check for duplicity
  733. if (!targetItem[tagIDKeyName]) {
  734. destination.push(targetItem);
  735. return;
  736. }
  737. var sourceIndex = findIndex(source, function (item) {
  738. return item[tagIDKeyName] === targetItem[tagIDKeyName];
  739. });
  740. var sourceItem = source[sourceIndex]; // source doesnt contain any duplicate vmid's, we can keep targetItem
  741. if (sourceIndex === -1) {
  742. destination.push(targetItem);
  743. return;
  744. } // when sourceItem explictly defines contentKeyName or innerHTML as undefined, its
  745. // an indication that we need to skip the default behaviour or child has preference over parent
  746. // which means we keep the targetItem and ignore/remove the sourceItem
  747. if (contentKeyName in sourceItem && sourceItem[contentKeyName] === undefined || 'innerHTML' in sourceItem && sourceItem.innerHTML === undefined) {
  748. destination.push(targetItem); // remove current index from source array so its not concatenated to destination below
  749. source.splice(sourceIndex, 1);
  750. return;
  751. } // we now know that targetItem is a duplicate and we should ignore it in favor of sourceItem
  752. // if source specifies null as content then ignore both the target as the source
  753. if (sourceItem[contentKeyName] === null || sourceItem.innerHTML === null) {
  754. // remove current index from source array so its not concatenated to destination below
  755. source.splice(sourceIndex, 1);
  756. return;
  757. } // now we only need to check if the target has a template to combine it with the source
  758. var targetTemplate = targetItem[metaTemplateKeyName];
  759. if (!targetTemplate) {
  760. return;
  761. }
  762. var sourceTemplate = sourceItem[metaTemplateKeyName];
  763. if (!sourceTemplate) {
  764. // use parent template and child content
  765. applyTemplate({
  766. component: component,
  767. metaTemplateKeyName: metaTemplateKeyName,
  768. contentKeyName: contentKeyName
  769. }, sourceItem, targetTemplate); // set template to true to indicate template was already applied
  770. sourceItem.template = true;
  771. return;
  772. }
  773. if (!sourceItem[contentKeyName]) {
  774. // use parent content and child template
  775. applyTemplate({
  776. component: component,
  777. metaTemplateKeyName: metaTemplateKeyName,
  778. contentKeyName: contentKeyName
  779. }, sourceItem, undefined, targetItem[contentKeyName]);
  780. }
  781. });
  782. return destination.concat(source);
  783. }
  784. var warningShown = false;
  785. function merge(target, source, options) {
  786. options = options || {}; // remove properties explicitly set to false so child components can
  787. // optionally _not_ overwrite the parents content
  788. // (for array properties this is checked in arrayMerge)
  789. if (source.title === undefined) {
  790. delete source.title;
  791. }
  792. metaInfoAttributeKeys.forEach(function (attrKey) {
  793. if (!source[attrKey]) {
  794. return;
  795. }
  796. for (var key in source[attrKey]) {
  797. if (key in source[attrKey] && source[attrKey][key] === undefined) {
  798. if (includes(booleanHtmlAttributes, key) && !warningShown) {
  799. warn('VueMeta: Please note that since v2 the value undefined is not used to indicate boolean attributes anymore, see migration guide for details');
  800. warningShown = true;
  801. }
  802. delete source[attrKey][key];
  803. }
  804. }
  805. });
  806. return deepmerge(target, source, {
  807. arrayMerge: function arrayMerge(t, s) {
  808. return _arrayMerge(options, t, s);
  809. }
  810. });
  811. }
  812. function getComponentMetaInfo(options, component) {
  813. return getComponentOption(options || {}, component, defaultInfo);
  814. }
  815. /**
  816. * Returns the `opts.option` $option value of the given `opts.component`.
  817. * If methods are encountered, they will be bound to the component context.
  818. * If `opts.deep` is true, will recursively merge all child component
  819. * `opts.option` $option values into the returned result.
  820. *
  821. * @param {Object} opts - options
  822. * @param {Object} opts.component - Vue component to fetch option data from
  823. * @param {Boolean} opts.deep - look for data in child components as well?
  824. * @param {Function} opts.arrayMerge - how should arrays be merged?
  825. * @param {String} opts.keyName - the name of the option to look for
  826. * @param {Object} [result={}] - result so far
  827. * @return {Object} result - final aggregated result
  828. */
  829. function getComponentOption(options, component, result) {
  830. result = result || {};
  831. if (component._inactive) {
  832. return result;
  833. }
  834. options = options || {};
  835. var _options = options,
  836. keyName = _options.keyName;
  837. var $metaInfo = component.$metaInfo,
  838. $options = component.$options,
  839. $children = component.$children; // only collect option data if it exists
  840. if ($options[keyName]) {
  841. // if $metaInfo exists then [keyName] was defined as a function
  842. // and set to the computed prop $metaInfo in the mixin
  843. // using the computed prop should be a small performance increase
  844. // because Vue caches those internally
  845. var data = $metaInfo || $options[keyName]; // only merge data with result when its an object
  846. // eg it could be a function when metaInfo() returns undefined
  847. // dueo to the or statement above
  848. if (isObject(data)) {
  849. result = merge(result, data, options);
  850. }
  851. } // collect & aggregate child options if deep = true
  852. if ($children.length) {
  853. $children.forEach(function (childComponent) {
  854. // check if the childComponent is in a branch
  855. // return otherwise so we dont walk all component branches unnecessarily
  856. if (!inMetaInfoBranch(childComponent)) {
  857. return;
  858. }
  859. result = getComponentOption(options, childComponent, result);
  860. });
  861. }
  862. return result;
  863. }
  864. var callbacks = [];
  865. function isDOMComplete(d) {
  866. return (d || document).readyState === 'complete';
  867. }
  868. function addCallback(query, callback) {
  869. if (arguments.length === 1) {
  870. callback = query;
  871. query = '';
  872. }
  873. callbacks.push([query, callback]);
  874. }
  875. function addCallbacks(_ref, type, tags, autoAddListeners) {
  876. var tagIDKeyName = _ref.tagIDKeyName;
  877. var hasAsyncCallback = false;
  878. tags.forEach(function (tag) {
  879. if (!tag[tagIDKeyName] || !tag.callback) {
  880. return;
  881. }
  882. hasAsyncCallback = true;
  883. addCallback("".concat(type, "[data-").concat(tagIDKeyName, "=\"").concat(tag[tagIDKeyName], "\"]"), tag.callback);
  884. });
  885. if (!autoAddListeners || !hasAsyncCallback) {
  886. return hasAsyncCallback;
  887. }
  888. return addListeners();
  889. }
  890. function addListeners() {
  891. if (isDOMComplete()) {
  892. applyCallbacks();
  893. return;
  894. } // Instead of using a MutationObserver, we just apply
  895. /* istanbul ignore next */
  896. document.onreadystatechange = function () {
  897. applyCallbacks();
  898. };
  899. }
  900. function applyCallbacks(matchElement) {
  901. callbacks.forEach(function (args) {
  902. // do not use destructuring for args, it increases transpiled size
  903. // due to var checks while we are guaranteed the structure of the cb
  904. var query = args[0];
  905. var callback = args[1];
  906. var selector = "".concat(query, "[onload=\"this.__vm_l=1\"]");
  907. var elements = [];
  908. if (!matchElement) {
  909. elements = toArray(querySelector(selector));
  910. }
  911. if (matchElement && matchElement.matches(selector)) {
  912. elements = [matchElement];
  913. }
  914. elements.forEach(function (element) {
  915. /* __vm_cb: whether the load callback has been called
  916. * __vm_l: set by onload attribute, whether the element was loaded
  917. * __vm_ev: whether the event listener was added or not
  918. */
  919. if (element.__vm_cb) {
  920. return;
  921. }
  922. var onload = function onload() {
  923. /* Mark that the callback for this element has already been called,
  924. * this prevents the callback to run twice in some (rare) conditions
  925. */
  926. element.__vm_cb = true;
  927. /* onload needs to be removed because we only need the
  928. * attribute after ssr and if we dont remove it the node
  929. * will fail isEqualNode on the client
  930. */
  931. removeAttribute(element, 'onload');
  932. callback(element);
  933. };
  934. /* IE9 doesnt seem to load scripts synchronously,
  935. * causing a script sometimes/often already to be loaded
  936. * when we add the event listener below (thus adding an onload event
  937. * listener has no use because it will never be triggered).
  938. * Therefore we add the onload attribute during ssr, and
  939. * check here if it was already loaded or not
  940. */
  941. if (element.__vm_l) {
  942. onload();
  943. return;
  944. }
  945. if (!element.__vm_ev) {
  946. element.__vm_ev = true;
  947. element.addEventListener('load', onload);
  948. }
  949. });
  950. });
  951. }
  952. // instead of adding it to the html
  953. var attributeMap = {};
  954. /**
  955. * Updates the document's html tag attributes
  956. *
  957. * @param {Object} attrs - the new document html attributes
  958. * @param {HTMLElement} tag - the HTMLElement tag to update with new attrs
  959. */
  960. function updateAttribute(appId, options, type, attrs, tag) {
  961. var _ref = options || {},
  962. attribute = _ref.attribute;
  963. var vueMetaAttrString = tag.getAttribute(attribute);
  964. if (vueMetaAttrString) {
  965. attributeMap[type] = JSON.parse(decodeURI(vueMetaAttrString));
  966. removeAttribute(tag, attribute);
  967. }
  968. var data = attributeMap[type] || {};
  969. var toUpdate = []; // remove attributes from the map
  970. // which have been removed for this appId
  971. for (var attr in data) {
  972. if (data[attr] !== undefined && appId in data[attr]) {
  973. toUpdate.push(attr);
  974. if (!attrs[attr]) {
  975. delete data[attr][appId];
  976. }
  977. }
  978. }
  979. for (var _attr in attrs) {
  980. var attrData = data[_attr];
  981. if (!attrData || attrData[appId] !== attrs[_attr]) {
  982. toUpdate.push(_attr);
  983. if (attrs[_attr] !== undefined) {
  984. data[_attr] = data[_attr] || {};
  985. data[_attr][appId] = attrs[_attr];
  986. }
  987. }
  988. }
  989. for (var _i = 0, _toUpdate = toUpdate; _i < _toUpdate.length; _i++) {
  990. var _attr2 = _toUpdate[_i];
  991. var _attrData = data[_attr2];
  992. var attrValues = [];
  993. for (var _appId in _attrData) {
  994. Array.prototype.push.apply(attrValues, [].concat(_attrData[_appId]));
  995. }
  996. if (attrValues.length) {
  997. var attrValue = includes(booleanHtmlAttributes, _attr2) && attrValues.some(Boolean) ? '' : attrValues.filter(function (v) {
  998. return v !== undefined;
  999. }).join(' ');
  1000. tag.setAttribute(_attr2, attrValue);
  1001. } else {
  1002. removeAttribute(tag, _attr2);
  1003. }
  1004. }
  1005. attributeMap[type] = data;
  1006. }
  1007. /**
  1008. * Updates the document title
  1009. *
  1010. * @param {String} title - the new title of the document
  1011. */
  1012. function updateTitle(title) {
  1013. if (!title && title !== '') {
  1014. return;
  1015. }
  1016. document.title = title;
  1017. }
  1018. /**
  1019. * Updates meta tags inside <head> and <body> on the client. Borrowed from `react-helmet`:
  1020. * https://github.com/nfl/react-helmet/blob/004d448f8de5f823d10f838b02317521180f34da/src/Helmet.js#L195-L245
  1021. *
  1022. * @param {('meta'|'base'|'link'|'style'|'script'|'noscript')} type - the name of the tag
  1023. * @param {(Array<Object>|Object)} tags - an array of tag objects or a single object in case of base
  1024. * @return {Object} - a representation of what tags changed
  1025. */
  1026. function updateTag(appId, options, type, tags, head, body) {
  1027. var _ref = options || {},
  1028. attribute = _ref.attribute,
  1029. tagIDKeyName = _ref.tagIDKeyName;
  1030. var dataAttributes = commonDataAttributes.slice();
  1031. dataAttributes.push(tagIDKeyName);
  1032. var newElements = [];
  1033. var queryOptions = {
  1034. appId: appId,
  1035. attribute: attribute,
  1036. type: type,
  1037. tagIDKeyName: tagIDKeyName
  1038. };
  1039. var currentElements = {
  1040. head: queryElements(head, queryOptions),
  1041. pbody: queryElements(body, queryOptions, {
  1042. pbody: true
  1043. }),
  1044. body: queryElements(body, queryOptions, {
  1045. body: true
  1046. })
  1047. };
  1048. if (tags.length > 1) {
  1049. // remove duplicates that could have been found by merging tags
  1050. // which include a mixin with metaInfo and that mixin is used
  1051. // by multiple components on the same page
  1052. var found = [];
  1053. tags = tags.filter(function (x) {
  1054. var k = JSON.stringify(x);
  1055. var res = !includes(found, k);
  1056. found.push(k);
  1057. return res;
  1058. });
  1059. }
  1060. tags.forEach(function (tag) {
  1061. if (tag.skip) {
  1062. return;
  1063. }
  1064. var newElement = document.createElement(type);
  1065. if (!tag.once) {
  1066. newElement.setAttribute(attribute, appId);
  1067. }
  1068. Object.keys(tag).forEach(function (attr) {
  1069. /* istanbul ignore next */
  1070. if (includes(tagProperties, attr)) {
  1071. return;
  1072. }
  1073. if (attr === 'innerHTML') {
  1074. newElement.innerHTML = tag.innerHTML;
  1075. return;
  1076. }
  1077. if (attr === 'json') {
  1078. newElement.innerHTML = JSON.stringify(tag.json);
  1079. return;
  1080. }
  1081. if (attr === 'cssText') {
  1082. if (newElement.styleSheet) {
  1083. /* istanbul ignore next */
  1084. newElement.styleSheet.cssText = tag.cssText;
  1085. } else {
  1086. newElement.appendChild(document.createTextNode(tag.cssText));
  1087. }
  1088. return;
  1089. }
  1090. if (attr === 'callback') {
  1091. newElement.onload = function () {
  1092. return tag[attr](newElement);
  1093. };
  1094. return;
  1095. }
  1096. var _attr = includes(dataAttributes, attr) ? "data-".concat(attr) : attr;
  1097. var isBooleanAttribute = includes(booleanHtmlAttributes, attr);
  1098. if (isBooleanAttribute && !tag[attr]) {
  1099. return;
  1100. }
  1101. var value = isBooleanAttribute ? '' : tag[attr];
  1102. newElement.setAttribute(_attr, value);
  1103. });
  1104. var oldElements = currentElements[getElementsKey(tag)]; // Remove a duplicate tag from domTagstoRemove, so it isn't cleared.
  1105. var indexToDelete;
  1106. var hasEqualElement = oldElements.some(function (existingTag, index) {
  1107. indexToDelete = index;
  1108. return newElement.isEqualNode(existingTag);
  1109. });
  1110. if (hasEqualElement && (indexToDelete || indexToDelete === 0)) {
  1111. oldElements.splice(indexToDelete, 1);
  1112. } else {
  1113. newElements.push(newElement);
  1114. }
  1115. });
  1116. var oldElements = [];
  1117. for (var _type in currentElements) {
  1118. Array.prototype.push.apply(oldElements, currentElements[_type]);
  1119. } // remove old elements
  1120. oldElements.forEach(function (element) {
  1121. element.parentNode.removeChild(element);
  1122. }); // insert new elements
  1123. newElements.forEach(function (element) {
  1124. if (element.hasAttribute('data-body')) {
  1125. body.appendChild(element);
  1126. return;
  1127. }
  1128. if (element.hasAttribute('data-pbody')) {
  1129. body.insertBefore(element, body.firstChild);
  1130. return;
  1131. }
  1132. head.appendChild(element);
  1133. });
  1134. return {
  1135. oldTags: oldElements,
  1136. newTags: newElements
  1137. };
  1138. }
  1139. /**
  1140. * Performs client-side updates when new meta info is received
  1141. *
  1142. * @param {Object} newInfo - the meta info to update to
  1143. */
  1144. function updateClientMetaInfo(appId, options, newInfo) {
  1145. options = options || {};
  1146. var _options = options,
  1147. ssrAttribute = _options.ssrAttribute,
  1148. ssrAppId = _options.ssrAppId; // only cache tags for current update
  1149. var tags = {};
  1150. var htmlTag = getTag(tags, 'html'); // if this is a server render, then dont update
  1151. if (appId === ssrAppId && htmlTag.hasAttribute(ssrAttribute)) {
  1152. // remove the server render attribute so we can update on (next) changes
  1153. removeAttribute(htmlTag, ssrAttribute); // add load callbacks if the
  1154. var addLoadListeners = false;
  1155. tagsSupportingOnload.forEach(function (type) {
  1156. if (newInfo[type] && addCallbacks(options, type, newInfo[type])) {
  1157. addLoadListeners = true;
  1158. }
  1159. });
  1160. if (addLoadListeners) {
  1161. addListeners();
  1162. }
  1163. return false;
  1164. } // initialize tracked changes
  1165. var tagsAdded = {};
  1166. var tagsRemoved = {};
  1167. for (var type in newInfo) {
  1168. // ignore these
  1169. if (includes(metaInfoOptionKeys, type)) {
  1170. continue;
  1171. }
  1172. if (type === 'title') {
  1173. // update the title
  1174. updateTitle(newInfo.title);
  1175. continue;
  1176. }
  1177. if (includes(metaInfoAttributeKeys, type)) {
  1178. var tagName = type.substr(0, 4);
  1179. updateAttribute(appId, options, type, newInfo[type], getTag(tags, tagName));
  1180. continue;
  1181. } // tags should always be an array, ignore if it isnt
  1182. if (!isArray(newInfo[type])) {
  1183. continue;
  1184. }
  1185. var _updateTag = updateTag(appId, options, type, newInfo[type], getTag(tags, 'head'), getTag(tags, 'body')),
  1186. oldTags = _updateTag.oldTags,
  1187. newTags = _updateTag.newTags;
  1188. if (newTags.length) {
  1189. tagsAdded[type] = newTags;
  1190. tagsRemoved[type] = oldTags;
  1191. }
  1192. }
  1193. return {
  1194. tagsAdded: tagsAdded,
  1195. tagsRemoved: tagsRemoved
  1196. };
  1197. }
  1198. var appsMetaInfo;
  1199. function addApp(rootVm, appId, options) {
  1200. return {
  1201. set: function set(metaInfo) {
  1202. return setMetaInfo(rootVm, appId, options, metaInfo);
  1203. },
  1204. remove: function remove() {
  1205. return removeMetaInfo(rootVm, appId, options);
  1206. }
  1207. };
  1208. }
  1209. function setMetaInfo(rootVm, appId, options, metaInfo) {
  1210. // if a vm exists _and_ its mounted then immediately update
  1211. if (rootVm && rootVm.$el) {
  1212. return updateClientMetaInfo(appId, options, metaInfo);
  1213. } // store for later, the info
  1214. // will be set on the first refresh
  1215. appsMetaInfo = appsMetaInfo || {};
  1216. appsMetaInfo[appId] = metaInfo;
  1217. }
  1218. function removeMetaInfo(rootVm, appId, options) {
  1219. if (rootVm && rootVm.$el) {
  1220. var tags = {};
  1221. var _iterator = _createForOfIteratorHelper(metaInfoAttributeKeys),
  1222. _step;
  1223. try {
  1224. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  1225. var type = _step.value;
  1226. var tagName = type.substr(0, 4);
  1227. updateAttribute(appId, options, type, {}, getTag(tags, tagName));
  1228. }
  1229. } catch (err) {
  1230. _iterator.e(err);
  1231. } finally {
  1232. _iterator.f();
  1233. }
  1234. return removeElementsByAppId(options, appId);
  1235. }
  1236. if (appsMetaInfo[appId]) {
  1237. delete appsMetaInfo[appId];
  1238. clearAppsMetaInfo();
  1239. }
  1240. }
  1241. function getAppsMetaInfo() {
  1242. return appsMetaInfo;
  1243. }
  1244. function clearAppsMetaInfo(force) {
  1245. if (force || !Object.keys(appsMetaInfo).length) {
  1246. appsMetaInfo = undefined;
  1247. }
  1248. }
  1249. /**
  1250. * Returns the correct meta info for the given component
  1251. * (child components will overwrite parent meta info)
  1252. *
  1253. * @param {Object} component - the Vue instance to get meta info from
  1254. * @return {Object} - returned meta info
  1255. */
  1256. function getMetaInfo(options, info, escapeSequences, component) {
  1257. options = options || {};
  1258. escapeSequences = escapeSequences || [];
  1259. var _options = options,
  1260. tagIDKeyName = _options.tagIDKeyName; // Remove all "template" tags from meta
  1261. // backup the title chunk in case user wants access to it
  1262. if (info.title) {
  1263. info.titleChunk = info.title;
  1264. } // replace title with populated template
  1265. if (info.titleTemplate && info.titleTemplate !== '%s') {
  1266. applyTemplate({
  1267. component: component,
  1268. contentKeyName: 'title'
  1269. }, info, info.titleTemplate, info.titleChunk || '');
  1270. } // convert base tag to an array so it can be handled the same way
  1271. // as the other tags
  1272. if (info.base) {
  1273. info.base = Object.keys(info.base).length ? [info.base] : [];
  1274. }
  1275. if (info.meta) {
  1276. // remove meta items with duplicate vmid's
  1277. info.meta = info.meta.filter(function (metaItem, index, arr) {
  1278. var hasVmid = !!metaItem[tagIDKeyName];
  1279. if (!hasVmid) {
  1280. return true;
  1281. }
  1282. var isFirstItemForVmid = index === findIndex(arr, function (item) {
  1283. return item[tagIDKeyName] === metaItem[tagIDKeyName];
  1284. });
  1285. return isFirstItemForVmid;
  1286. }); // apply templates if needed
  1287. info.meta.forEach(function (metaObject) {
  1288. return applyTemplate(options, metaObject);
  1289. });
  1290. }
  1291. return escapeMetaInfo(options, info, escapeSequences);
  1292. }
  1293. /**
  1294. * When called, will update the current meta info with new meta info.
  1295. * Useful when updating meta info as the result of an asynchronous
  1296. * action that resolves after the initial render takes place.
  1297. *
  1298. * Credit to [Sébastien Chopin](https://github.com/Atinux) for the suggestion
  1299. * to implement this method.
  1300. *
  1301. * @return {Object} - new meta info
  1302. */
  1303. function refresh(rootVm, options) {
  1304. options = options || {}; // make sure vue-meta was initiated
  1305. if (!rootVm[rootConfigKey]) {
  1306. showWarningNotSupported();
  1307. return {};
  1308. } // collect & aggregate all metaInfo $options
  1309. var rawInfo = getComponentMetaInfo(options, rootVm);
  1310. var metaInfo = getMetaInfo(options, rawInfo, clientSequences, rootVm);
  1311. var appId = rootVm[rootConfigKey].appId;
  1312. var tags = updateClientMetaInfo(appId, options, metaInfo); // emit "event" with new info
  1313. if (tags && isFunction(metaInfo.changed)) {
  1314. metaInfo.changed(metaInfo, tags.tagsAdded, tags.tagsRemoved);
  1315. tags = {
  1316. addedTags: tags.tagsAdded,
  1317. removedTags: tags.tagsRemoved
  1318. };
  1319. }
  1320. var appsMetaInfo = getAppsMetaInfo();
  1321. if (appsMetaInfo) {
  1322. for (var additionalAppId in appsMetaInfo) {
  1323. updateClientMetaInfo(additionalAppId, options, appsMetaInfo[additionalAppId]);
  1324. delete appsMetaInfo[additionalAppId];
  1325. }
  1326. clearAppsMetaInfo(true);
  1327. }
  1328. return {
  1329. vm: rootVm,
  1330. metaInfo: metaInfo,
  1331. // eslint-disable-line object-shorthand
  1332. tags: tags
  1333. };
  1334. }
  1335. /**
  1336. * Generates tag attributes for use on the server.
  1337. *
  1338. * @param {('bodyAttrs'|'htmlAttrs'|'headAttrs')} type - the type of attributes to generate
  1339. * @param {Object} data - the attributes to generate
  1340. * @return {Object} - the attribute generator
  1341. */
  1342. function attributeGenerator(options, type, data, _ref) {
  1343. var addSsrAttribute = _ref.addSsrAttribute;
  1344. var _ref2 = options || {},
  1345. attribute = _ref2.attribute,
  1346. ssrAttribute = _ref2.ssrAttribute;
  1347. var attributeStr = '';
  1348. for (var attr in data) {
  1349. var attrData = data[attr];
  1350. var attrValues = [];
  1351. for (var appId in attrData) {
  1352. attrValues.push.apply(attrValues, _toConsumableArray([].concat(attrData[appId])));
  1353. }
  1354. if (attrValues.length) {
  1355. attributeStr += booleanHtmlAttributes.includes(attr) && attrValues.some(Boolean) ? "".concat(attr) : "".concat(attr, "=\"").concat(attrValues.join(' '), "\"");
  1356. attributeStr += ' ';
  1357. }
  1358. }
  1359. if (attributeStr) {
  1360. attributeStr += "".concat(attribute, "=\"").concat(encodeURI(JSON.stringify(data)), "\"");
  1361. }
  1362. if (type === 'htmlAttrs' && addSsrAttribute) {
  1363. return "".concat(ssrAttribute).concat(attributeStr ? ' ' : '').concat(attributeStr);
  1364. }
  1365. return attributeStr;
  1366. }
  1367. /**
  1368. * Generates title output for the server
  1369. *
  1370. * @param {'title'} type - the string "title"
  1371. * @param {String} data - the title text
  1372. * @return {Object} - the title generator
  1373. */
  1374. function titleGenerator(options, type, data, generatorOptions) {
  1375. var _ref = generatorOptions || {},
  1376. ln = _ref.ln;
  1377. if (!data) {
  1378. return '';
  1379. }
  1380. return "<".concat(type, ">").concat(data, "</").concat(type, ">").concat(ln ? '\n' : '');
  1381. }
  1382. /**
  1383. * Generates meta, base, link, style, script, noscript tags for use on the server
  1384. *
  1385. * @param {('meta'|'base'|'link'|'style'|'script'|'noscript')} the name of the tag
  1386. * @param {(Array<Object>|Object)} tags - an array of tag objects or a single object in case of base
  1387. * @return {Object} - the tag generator
  1388. */
  1389. function tagGenerator(options, type, tags, generatorOptions) {
  1390. var _ref = options || {},
  1391. ssrAppId = _ref.ssrAppId,
  1392. attribute = _ref.attribute,
  1393. tagIDKeyName = _ref.tagIDKeyName;
  1394. var _ref2 = generatorOptions || {},
  1395. appId = _ref2.appId,
  1396. _ref2$isSSR = _ref2.isSSR,
  1397. isSSR = _ref2$isSSR === void 0 ? true : _ref2$isSSR,
  1398. _ref2$body = _ref2.body,
  1399. body = _ref2$body === void 0 ? false : _ref2$body,
  1400. _ref2$pbody = _ref2.pbody,
  1401. pbody = _ref2$pbody === void 0 ? false : _ref2$pbody,
  1402. _ref2$ln = _ref2.ln,
  1403. ln = _ref2$ln === void 0 ? false : _ref2$ln;
  1404. var dataAttributes = [tagIDKeyName].concat(_toConsumableArray(commonDataAttributes));
  1405. if (!tags || !tags.length) {
  1406. return '';
  1407. } // build a string containing all tags of this type
  1408. return tags.reduce(function (tagsStr, tag) {
  1409. if (tag.skip) {
  1410. return tagsStr;
  1411. }
  1412. var tagKeys = Object.keys(tag);
  1413. if (tagKeys.length === 0) {
  1414. return tagsStr; // Bail on empty tag object
  1415. }
  1416. if (Boolean(tag.body) !== body || Boolean(tag.pbody) !== pbody) {
  1417. return tagsStr;
  1418. }
  1419. var attrs = tag.once ? '' : " ".concat(attribute, "=\"").concat(appId || (isSSR === false ? '1' : ssrAppId), "\""); // build a string containing all attributes of this tag
  1420. for (var attr in tag) {
  1421. // these attributes are treated as children on the tag
  1422. if (tagAttributeAsInnerContent.includes(attr) || tagProperties.includes(attr)) {
  1423. continue;
  1424. }
  1425. if (attr === 'callback') {
  1426. attrs += ' onload="this.__vm_l=1"';
  1427. continue;
  1428. } // these form the attribute list for this tag
  1429. var prefix = '';
  1430. if (dataAttributes.includes(attr)) {
  1431. prefix = 'data-';
  1432. }
  1433. var isBooleanAttr = !prefix && booleanHtmlAttributes.includes(attr);
  1434. if (isBooleanAttr && !tag[attr]) {
  1435. continue;
  1436. }
  1437. attrs += " ".concat(prefix).concat(attr) + (isBooleanAttr ? '' : "=\"".concat(tag[attr], "\""));
  1438. }
  1439. var json = '';
  1440. if (tag.json) {
  1441. json = JSON.stringify(tag.json);
  1442. } // grab child content from one of these attributes, if possible
  1443. var content = tag.innerHTML || tag.cssText || json; // generate tag exactly without any other redundant attribute
  1444. // these tags have no end tag
  1445. var hasEndTag = !tagsWithoutEndTag.includes(type); // these tag types will have content inserted
  1446. var hasContent = hasEndTag && tagsWithInnerContent.includes(type); // the final string for this specific tag
  1447. return "".concat(tagsStr, "<").concat(type).concat(attrs).concat(!hasContent && hasEndTag ? '/' : '', ">") + (hasContent ? "".concat(content, "</").concat(type, ">") : '') + (ln ? '\n' : '');
  1448. }, '');
  1449. }
  1450. /**
  1451. * Converts a meta info property to one that can be stringified on the server
  1452. *
  1453. * @param {String} type - the type of data to convert
  1454. * @param {(String|Object|Array<Object>)} data - the data value
  1455. * @return {Object} - the new injector
  1456. */
  1457. function generateServerInjector(options, metaInfo, globalInjectOptions) {
  1458. var serverInjector = {
  1459. data: metaInfo,
  1460. extraData: undefined,
  1461. addInfo: function addInfo(appId, metaInfo) {
  1462. this.extraData = this.extraData || {};
  1463. this.extraData[appId] = metaInfo;
  1464. },
  1465. callInjectors: function callInjectors(opts) {
  1466. var m = this.injectors; // only call title for the head
  1467. return (opts.body || opts.pbody ? '' : m.title.text(opts)) + m.meta.text(opts) + m.base.text(opts) + m.link.text(opts) + m.style.text(opts) + m.script.text(opts) + m.noscript.text(opts);
  1468. },
  1469. injectors: {
  1470. head: function head(ln) {
  1471. return serverInjector.callInjectors(_objectSpread2(_objectSpread2({}, globalInjectOptions), {}, {
  1472. ln: ln
  1473. }));
  1474. },
  1475. bodyPrepend: function bodyPrepend(ln) {
  1476. return serverInjector.callInjectors(_objectSpread2(_objectSpread2({}, globalInjectOptions), {}, {
  1477. ln: ln,
  1478. pbody: true
  1479. }));
  1480. },
  1481. bodyAppend: function bodyAppend(ln) {
  1482. return serverInjector.callInjectors(_objectSpread2(_objectSpread2({}, globalInjectOptions), {}, {
  1483. ln: ln,
  1484. body: true
  1485. }));
  1486. }
  1487. }
  1488. };
  1489. var _loop = function _loop(type) {
  1490. if (metaInfoOptionKeys.includes(type)) {
  1491. return "continue";
  1492. }
  1493. serverInjector.injectors[type] = {
  1494. text: function text(injectOptions) {
  1495. var addSsrAttribute = injectOptions === true;
  1496. injectOptions = _objectSpread2(_objectSpread2({
  1497. addSsrAttribute: addSsrAttribute
  1498. }, globalInjectOptions), injectOptions);
  1499. if (type === 'title') {
  1500. return titleGenerator(options, type, serverInjector.data[type], injectOptions);
  1501. }
  1502. if (metaInfoAttributeKeys.includes(type)) {
  1503. var attributeData = {};
  1504. var data = serverInjector.data[type];
  1505. if (data) {
  1506. var appId = injectOptions.isSSR === false ? '1' : options.ssrAppId;
  1507. for (var attr in data) {
  1508. attributeData[attr] = _defineProperty({}, appId, data[attr]);
  1509. }
  1510. }
  1511. if (serverInjector.extraData) {
  1512. for (var _appId in serverInjector.extraData) {
  1513. var _data = serverInjector.extraData[_appId][type];
  1514. if (_data) {
  1515. for (var _attr in _data) {
  1516. attributeData[_attr] = _objectSpread2(_objectSpread2({}, attributeData[_attr]), {}, _defineProperty({}, _appId, _data[_attr]));
  1517. }
  1518. }
  1519. }
  1520. }
  1521. return attributeGenerator(options, type, attributeData, injectOptions);
  1522. }
  1523. var str = tagGenerator(options, type, serverInjector.data[type], injectOptions);
  1524. if (serverInjector.extraData) {
  1525. for (var _appId2 in serverInjector.extraData) {
  1526. var _data2 = serverInjector.extraData[_appId2][type];
  1527. var extraStr = tagGenerator(options, type, _data2, _objectSpread2({
  1528. appId: _appId2
  1529. }, injectOptions));
  1530. str = "".concat(str).concat(extraStr);
  1531. }
  1532. }
  1533. return str;
  1534. }
  1535. };
  1536. };
  1537. for (var type in defaultInfo) {
  1538. var _ret = _loop(type);
  1539. if (_ret === "continue") continue;
  1540. }
  1541. return serverInjector;
  1542. }
  1543. /**
  1544. * Converts the state of the meta info object such that each item
  1545. * can be compiled to a tag string on the server
  1546. *
  1547. * @vm {Object} - Vue instance - ideally the root component
  1548. * @return {Object} - server meta info with `toString` methods
  1549. */
  1550. function inject(rootVm, options, injectOptions) {
  1551. // make sure vue-meta was initiated
  1552. if (!rootVm[rootConfigKey]) {
  1553. showWarningNotSupported();
  1554. return {};
  1555. } // collect & aggregate all metaInfo $options
  1556. var rawInfo = getComponentMetaInfo(options, rootVm);
  1557. var metaInfo = getMetaInfo(options, rawInfo, serverSequences, rootVm); // generate server injector
  1558. var serverInjector = generateServerInjector(options, metaInfo, injectOptions); // add meta info from additional apps
  1559. var appsMetaInfo = getAppsMetaInfo();
  1560. if (appsMetaInfo) {
  1561. for (var additionalAppId in appsMetaInfo) {
  1562. serverInjector.addInfo(additionalAppId, appsMetaInfo[additionalAppId]);
  1563. delete appsMetaInfo[additionalAppId];
  1564. }
  1565. clearAppsMetaInfo(true);
  1566. }
  1567. return serverInjector.injectors;
  1568. }
  1569. function $meta(options) {
  1570. options = options || {};
  1571. /**
  1572. * Returns an injector for server-side rendering.
  1573. * @this {Object} - the Vue instance (a root component)
  1574. * @return {Object} - injector
  1575. */
  1576. var $root = this.$root;
  1577. return {
  1578. getOptions: function getOptions$1() {
  1579. return getOptions(options);
  1580. },
  1581. setOptions: function setOptions(newOptions) {
  1582. var refreshNavKey = 'refreshOnceOnNavigation';
  1583. if (newOptions && newOptions[refreshNavKey]) {
  1584. options.refreshOnceOnNavigation = !!newOptions[refreshNavKey];
  1585. addNavGuards($root);
  1586. }
  1587. var debounceWaitKey = 'debounceWait';
  1588. if (newOptions && debounceWaitKey in newOptions) {
  1589. var debounceWait = parseInt(newOptions[debounceWaitKey]);
  1590. if (!isNaN(debounceWait)) {
  1591. options.debounceWait = debounceWait;
  1592. }
  1593. }
  1594. var waitOnDestroyedKey = 'waitOnDestroyed';
  1595. if (newOptions && waitOnDestroyedKey in newOptions) {
  1596. options.waitOnDestroyed = !!newOptions[waitOnDestroyedKey];
  1597. }
  1598. },
  1599. refresh: function refresh$1() {
  1600. return refresh($root, options);
  1601. },
  1602. inject: function inject$1(injectOptions) {
  1603. return inject($root, options, injectOptions) ;
  1604. },
  1605. pause: function pause$1() {
  1606. return pause($root);
  1607. },
  1608. resume: function resume$1() {
  1609. return resume($root);
  1610. },
  1611. addApp: function addApp$1(appId) {
  1612. return addApp($root, appId, options);
  1613. }
  1614. };
  1615. }
  1616. function generate(rawInfo, options) {
  1617. options = setOptions(options);
  1618. var metaInfo = getMetaInfo(options, rawInfo, serverSequences);
  1619. var serverInjector = generateServerInjector(options, metaInfo);
  1620. return serverInjector.injectors;
  1621. }
  1622. /**
  1623. * Plugin install function.
  1624. * @param {Function} Vue - the Vue constructor.
  1625. */
  1626. function install(Vue, options) {
  1627. if (Vue.__vuemeta_installed) {
  1628. return;
  1629. }
  1630. Vue.__vuemeta_installed = true;
  1631. options = setOptions(options);
  1632. Vue.prototype.$meta = function () {
  1633. return $meta.call(this, options);
  1634. };
  1635. Vue.mixin(createMixin(Vue, options));
  1636. }
  1637. var index = {
  1638. version: version,
  1639. install: install,
  1640. generate: function generate$1(metaInfo, options) {
  1641. return generate(metaInfo, options) ;
  1642. },
  1643. hasMetaInfo: hasMetaInfo
  1644. };
  1645. module.exports = index;