vue-meta.esm.js 60 KB

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