vue-composition-api.common.js 72 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. /******************************************************************************
  4. Copyright (c) Microsoft Corporation.
  5. Permission to use, copy, modify, and/or distribute this software for any
  6. purpose with or without fee is hereby granted.
  7. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  8. REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  12. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. PERFORMANCE OF THIS SOFTWARE.
  14. ***************************************************************************** */
  15. /* global Reflect, Promise */
  16. var extendStatics = function(d, b) {
  17. extendStatics = Object.setPrototypeOf ||
  18. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  19. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  20. return extendStatics(d, b);
  21. };
  22. function __extends(d, b) {
  23. if (typeof b !== "function" && b !== null)
  24. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  25. extendStatics(d, b);
  26. function __() { this.constructor = d; }
  27. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  28. }
  29. var __assign = function() {
  30. __assign = Object.assign || function __assign(t) {
  31. for (var s, i = 1, n = arguments.length; i < n; i++) {
  32. s = arguments[i];
  33. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  34. }
  35. return t;
  36. };
  37. return __assign.apply(this, arguments);
  38. };
  39. function __values(o) {
  40. var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
  41. if (m) return m.call(o);
  42. if (o && typeof o.length === "number") return {
  43. next: function () {
  44. if (o && i >= o.length) o = void 0;
  45. return { value: o && o[i++], done: !o };
  46. }
  47. };
  48. throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
  49. }
  50. function __read(o, n) {
  51. var m = typeof Symbol === "function" && o[Symbol.iterator];
  52. if (!m) return o;
  53. var i = m.call(o), r, ar = [], e;
  54. try {
  55. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  56. }
  57. catch (error) { e = { error: error }; }
  58. finally {
  59. try {
  60. if (r && !r.done && (m = i["return"])) m.call(i);
  61. }
  62. finally { if (e) throw e.error; }
  63. }
  64. return ar;
  65. }
  66. function __spreadArray(to, from, pack) {
  67. if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
  68. if (ar || !(i in from)) {
  69. if (!ar) ar = Array.prototype.slice.call(from, 0, i);
  70. ar[i] = from[i];
  71. }
  72. }
  73. return to.concat(ar || Array.prototype.slice.call(from));
  74. }
  75. /**
  76. * Displays a warning message (using console.error) with a stack trace if the
  77. * function is called inside of active component.
  78. *
  79. * @param message warning message to be displayed
  80. */
  81. function warn$1(message) {
  82. var _a;
  83. warn(message, (_a = getCurrentInstance()) === null || _a === void 0 ? void 0 : _a.proxy);
  84. }
  85. var activeEffectScope;
  86. var effectScopeStack = [];
  87. var EffectScopeImpl = /** @class */ (function () {
  88. function EffectScopeImpl(vm) {
  89. this.active = true;
  90. this.effects = [];
  91. this.cleanups = [];
  92. this.vm = vm;
  93. }
  94. EffectScopeImpl.prototype.run = function (fn) {
  95. if (this.active) {
  96. try {
  97. this.on();
  98. return fn();
  99. }
  100. finally {
  101. this.off();
  102. }
  103. }
  104. else {
  105. warn$1("cannot run an inactive effect scope.");
  106. }
  107. return;
  108. };
  109. EffectScopeImpl.prototype.on = function () {
  110. if (this.active) {
  111. effectScopeStack.push(this);
  112. activeEffectScope = this;
  113. }
  114. };
  115. EffectScopeImpl.prototype.off = function () {
  116. if (this.active) {
  117. effectScopeStack.pop();
  118. activeEffectScope = effectScopeStack[effectScopeStack.length - 1];
  119. }
  120. };
  121. EffectScopeImpl.prototype.stop = function () {
  122. if (this.active) {
  123. this.vm.$destroy();
  124. this.effects.forEach(function (e) { return e.stop(); });
  125. this.cleanups.forEach(function (cleanup) { return cleanup(); });
  126. this.active = false;
  127. }
  128. };
  129. return EffectScopeImpl;
  130. }());
  131. var EffectScope = /** @class */ (function (_super) {
  132. __extends(EffectScope, _super);
  133. function EffectScope(detached) {
  134. if (detached === void 0) { detached = false; }
  135. var _this = this;
  136. var vm = undefined;
  137. withCurrentInstanceTrackingDisabled(function () {
  138. vm = defineComponentInstance(getVueConstructor());
  139. });
  140. _this = _super.call(this, vm) || this;
  141. if (!detached) {
  142. recordEffectScope(_this);
  143. }
  144. return _this;
  145. }
  146. return EffectScope;
  147. }(EffectScopeImpl));
  148. function recordEffectScope(effect, scope) {
  149. var _a;
  150. scope = scope || activeEffectScope;
  151. if (scope && scope.active) {
  152. scope.effects.push(effect);
  153. return;
  154. }
  155. // destroy on parent component unmounted
  156. var vm = (_a = getCurrentInstance()) === null || _a === void 0 ? void 0 : _a.proxy;
  157. vm && vm.$on('hook:destroyed', function () { return effect.stop(); });
  158. }
  159. function effectScope(detached) {
  160. return new EffectScope(detached);
  161. }
  162. function getCurrentScope() {
  163. return activeEffectScope;
  164. }
  165. function onScopeDispose(fn) {
  166. if (activeEffectScope) {
  167. activeEffectScope.cleanups.push(fn);
  168. }
  169. else {
  170. warn$1("onScopeDispose() is called when there is no active effect scope" +
  171. " to be associated with.");
  172. }
  173. }
  174. /**
  175. * @internal
  176. **/
  177. function getCurrentScopeVM() {
  178. var _a, _b;
  179. return ((_a = getCurrentScope()) === null || _a === void 0 ? void 0 : _a.vm) || ((_b = getCurrentInstance()) === null || _b === void 0 ? void 0 : _b.proxy);
  180. }
  181. /**
  182. * @internal
  183. **/
  184. function bindCurrentScopeToVM(vm) {
  185. if (!vm.scope) {
  186. var scope_1 = new EffectScopeImpl(vm.proxy);
  187. vm.scope = scope_1;
  188. vm.proxy.$on('hook:destroyed', function () { return scope_1.stop(); });
  189. }
  190. return vm.scope;
  191. }
  192. var vueDependency = undefined;
  193. try {
  194. var requiredVue = require('vue');
  195. if (requiredVue && isVue(requiredVue)) {
  196. vueDependency = requiredVue;
  197. }
  198. else if (requiredVue &&
  199. 'default' in requiredVue &&
  200. isVue(requiredVue.default)) {
  201. vueDependency = requiredVue.default;
  202. }
  203. }
  204. catch (_a) {
  205. // not available
  206. }
  207. var vueConstructor = null;
  208. var currentInstance = null;
  209. var currentInstanceTracking = true;
  210. var PluginInstalledFlag = '__composition_api_installed__';
  211. function isVue(obj) {
  212. return obj && isFunction(obj) && obj.name === 'Vue';
  213. }
  214. function isVueRegistered(Vue) {
  215. // resolve issue: https://github.com/vuejs/composition-api/issues/876#issue-1087619365
  216. return vueConstructor && hasOwn(Vue, PluginInstalledFlag);
  217. }
  218. function getVueConstructor() {
  219. {
  220. assert(vueConstructor, "must call Vue.use(VueCompositionAPI) before using any function.");
  221. }
  222. return vueConstructor;
  223. }
  224. // returns registered vue or `vue` dependency
  225. function getRegisteredVueOrDefault() {
  226. var constructor = vueConstructor || vueDependency;
  227. {
  228. assert(constructor, "No vue dependency found.");
  229. }
  230. return constructor;
  231. }
  232. function setVueConstructor(Vue) {
  233. // @ts-ignore
  234. if (vueConstructor && Vue.__proto__ !== vueConstructor.__proto__) {
  235. warn('[vue-composition-api] another instance of Vue installed');
  236. }
  237. vueConstructor = Vue;
  238. Object.defineProperty(Vue, PluginInstalledFlag, {
  239. configurable: true,
  240. writable: true,
  241. value: true,
  242. });
  243. }
  244. /**
  245. * For `effectScope` to create instance without populate the current instance
  246. * @internal
  247. **/
  248. function withCurrentInstanceTrackingDisabled(fn) {
  249. var prev = currentInstanceTracking;
  250. currentInstanceTracking = false;
  251. try {
  252. fn();
  253. }
  254. finally {
  255. currentInstanceTracking = prev;
  256. }
  257. }
  258. function setCurrentInstance(instance) {
  259. if (!currentInstanceTracking)
  260. return;
  261. var prev = currentInstance;
  262. prev === null || prev === void 0 ? void 0 : prev.scope.off();
  263. currentInstance = instance;
  264. currentInstance === null || currentInstance === void 0 ? void 0 : currentInstance.scope.on();
  265. }
  266. function getCurrentInstance() {
  267. return currentInstance;
  268. }
  269. var instanceMapCache = new WeakMap();
  270. function toVue3ComponentInstance(vm) {
  271. if (instanceMapCache.has(vm)) {
  272. return instanceMapCache.get(vm);
  273. }
  274. var instance = {
  275. proxy: vm,
  276. update: vm.$forceUpdate,
  277. type: vm.$options,
  278. uid: vm._uid,
  279. // $emit is defined on prototype and it expected to be bound
  280. emit: vm.$emit.bind(vm),
  281. parent: null,
  282. root: null, // to be immediately set
  283. };
  284. bindCurrentScopeToVM(instance);
  285. // map vm.$props =
  286. var instanceProps = [
  287. 'data',
  288. 'props',
  289. 'attrs',
  290. 'refs',
  291. 'vnode',
  292. 'slots',
  293. ];
  294. instanceProps.forEach(function (prop) {
  295. proxy(instance, prop, {
  296. get: function () {
  297. return vm["$".concat(prop)];
  298. },
  299. });
  300. });
  301. proxy(instance, 'isMounted', {
  302. get: function () {
  303. // @ts-expect-error private api
  304. return vm._isMounted;
  305. },
  306. });
  307. proxy(instance, 'isUnmounted', {
  308. get: function () {
  309. // @ts-expect-error private api
  310. return vm._isDestroyed;
  311. },
  312. });
  313. proxy(instance, 'isDeactivated', {
  314. get: function () {
  315. // @ts-expect-error private api
  316. return vm._inactive;
  317. },
  318. });
  319. proxy(instance, 'emitted', {
  320. get: function () {
  321. // @ts-expect-error private api
  322. return vm._events;
  323. },
  324. });
  325. instanceMapCache.set(vm, instance);
  326. if (vm.$parent) {
  327. instance.parent = toVue3ComponentInstance(vm.$parent);
  328. }
  329. if (vm.$root) {
  330. instance.root = toVue3ComponentInstance(vm.$root);
  331. }
  332. return instance;
  333. }
  334. var toString = function (x) { return Object.prototype.toString.call(x); };
  335. function isNative(Ctor) {
  336. return typeof Ctor === 'function' && /native code/.test(Ctor.toString());
  337. }
  338. var hasSymbol = typeof Symbol !== 'undefined' &&
  339. isNative(Symbol) &&
  340. typeof Reflect !== 'undefined' &&
  341. isNative(Reflect.ownKeys);
  342. var noopFn = function (_) { return _; };
  343. function proxy(target, key, _a) {
  344. var get = _a.get, set = _a.set;
  345. Object.defineProperty(target, key, {
  346. enumerable: true,
  347. configurable: true,
  348. get: get || noopFn,
  349. set: set || noopFn,
  350. });
  351. }
  352. function def(obj, key, val, enumerable) {
  353. Object.defineProperty(obj, key, {
  354. value: val,
  355. enumerable: !!enumerable,
  356. writable: true,
  357. configurable: true,
  358. });
  359. }
  360. function hasOwn(obj, key) {
  361. return Object.hasOwnProperty.call(obj, key);
  362. }
  363. function assert(condition, msg) {
  364. if (!condition) {
  365. throw new Error("[vue-composition-api] ".concat(msg));
  366. }
  367. }
  368. function isPrimitive(value) {
  369. return (typeof value === 'string' ||
  370. typeof value === 'number' ||
  371. // $flow-disable-line
  372. typeof value === 'symbol' ||
  373. typeof value === 'boolean');
  374. }
  375. function isArray(x) {
  376. return Array.isArray(x);
  377. }
  378. var objectToString = Object.prototype.toString;
  379. var toTypeString = function (value) {
  380. return objectToString.call(value);
  381. };
  382. var isMap = function (val) {
  383. return toTypeString(val) === '[object Map]';
  384. };
  385. var isSet = function (val) {
  386. return toTypeString(val) === '[object Set]';
  387. };
  388. var MAX_VALID_ARRAY_LENGTH = 4294967295; // Math.pow(2, 32) - 1
  389. function isValidArrayIndex(val) {
  390. var n = parseFloat(String(val));
  391. return (n >= 0 &&
  392. Math.floor(n) === n &&
  393. isFinite(val) &&
  394. n <= MAX_VALID_ARRAY_LENGTH);
  395. }
  396. function isObject(val) {
  397. return val !== null && typeof val === 'object';
  398. }
  399. function isPlainObject(x) {
  400. return toString(x) === '[object Object]';
  401. }
  402. function isFunction(x) {
  403. return typeof x === 'function';
  404. }
  405. function isUndef(v) {
  406. return v === undefined || v === null;
  407. }
  408. function warn(msg, vm) {
  409. var Vue = getRegisteredVueOrDefault();
  410. if (!Vue || !Vue.util)
  411. console.warn("[vue-composition-api] ".concat(msg));
  412. else
  413. Vue.util.warn(msg, vm);
  414. }
  415. function logError(err, vm, info) {
  416. {
  417. warn("Error in ".concat(info, ": \"").concat(err.toString(), "\""), vm);
  418. }
  419. if (typeof window !== 'undefined' && typeof console !== 'undefined') {
  420. console.error(err);
  421. }
  422. else {
  423. throw err;
  424. }
  425. }
  426. /**
  427. * Object.is polyfill
  428. * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
  429. * */
  430. function isSame(value1, value2) {
  431. if (value1 === value2) {
  432. return value1 !== 0 || 1 / value1 === 1 / value2;
  433. }
  434. else {
  435. return value1 !== value1 && value2 !== value2;
  436. }
  437. }
  438. function getCurrentInstanceForFn(hook, target) {
  439. target = target || getCurrentInstance();
  440. if (!target) {
  441. warn("".concat(hook, " is called when there is no active component instance to be ") +
  442. "associated with. " +
  443. "Lifecycle injection APIs can only be used during execution of setup().");
  444. }
  445. return target;
  446. }
  447. function defineComponentInstance(Ctor, options) {
  448. if (options === void 0) { options = {}; }
  449. var silent = Ctor.config.silent;
  450. Ctor.config.silent = true;
  451. var vm = new Ctor(options);
  452. Ctor.config.silent = silent;
  453. return vm;
  454. }
  455. function isComponentInstance(obj) {
  456. var Vue = getVueConstructor();
  457. return Vue && obj instanceof Vue;
  458. }
  459. function createSlotProxy(vm, slotName) {
  460. return (function () {
  461. var args = [];
  462. for (var _i = 0; _i < arguments.length; _i++) {
  463. args[_i] = arguments[_i];
  464. }
  465. if (!vm.$scopedSlots[slotName]) {
  466. return warn("slots.".concat(slotName, "() got called outside of the \"render()\" scope"), vm);
  467. }
  468. return vm.$scopedSlots[slotName].apply(vm, args);
  469. });
  470. }
  471. function resolveSlots(slots, normalSlots) {
  472. var res;
  473. if (!slots) {
  474. res = {};
  475. }
  476. else if (slots._normalized) {
  477. // fast path 1: child component re-render only, parent did not change
  478. return slots._normalized;
  479. }
  480. else {
  481. res = {};
  482. for (var key in slots) {
  483. if (slots[key] && key[0] !== '$') {
  484. res[key] = true;
  485. }
  486. }
  487. }
  488. // expose normal slots on scopedSlots
  489. for (var key in normalSlots) {
  490. if (!(key in res)) {
  491. res[key] = true;
  492. }
  493. }
  494. return res;
  495. }
  496. var vueInternalClasses;
  497. var getVueInternalClasses = function () {
  498. if (!vueInternalClasses) {
  499. var vm = defineComponentInstance(getVueConstructor(), {
  500. computed: {
  501. value: function () {
  502. return 0;
  503. },
  504. },
  505. });
  506. // to get Watcher class
  507. var Watcher = vm._computedWatchers.value.constructor;
  508. // to get Dep class
  509. var Dep = vm._data.__ob__.dep.constructor;
  510. vueInternalClasses = {
  511. Watcher: Watcher,
  512. Dep: Dep,
  513. };
  514. vm.$destroy();
  515. }
  516. return vueInternalClasses;
  517. };
  518. function createSymbol(name) {
  519. return hasSymbol ? Symbol.for(name) : name;
  520. }
  521. var WatcherPreFlushQueueKey = createSymbol('composition-api.preFlushQueue');
  522. var WatcherPostFlushQueueKey = createSymbol('composition-api.postFlushQueue');
  523. // must be a string, symbol key is ignored in reactive
  524. var RefKey = 'composition-api.refKey';
  525. var accessModifiedSet = new WeakMap();
  526. var rawSet = new WeakMap();
  527. var readonlySet = new WeakMap();
  528. /**
  529. * Set a property on an object. Adds the new property, triggers change
  530. * notification and intercept it's subsequent access if the property doesn't
  531. * already exist.
  532. */
  533. function set$1(target, key, val) {
  534. var Vue = getVueConstructor();
  535. // @ts-expect-error https://github.com/vuejs/vue/pull/12132
  536. var _a = Vue.util, warn = _a.warn, defineReactive = _a.defineReactive;
  537. if ((isUndef(target) || isPrimitive(target))) {
  538. warn("Cannot set reactive property on undefined, null, or primitive value: ".concat(target));
  539. }
  540. var ob = target.__ob__;
  541. function ssrMockReactivity() {
  542. // in SSR, there is no __ob__. Mock for reactivity check
  543. if (ob && isObject(val) && !hasOwn(val, '__ob__')) {
  544. mockReactivityDeep(val);
  545. }
  546. }
  547. if (isArray(target)) {
  548. if (isValidArrayIndex(key)) {
  549. target.length = Math.max(target.length, key);
  550. target.splice(key, 1, val);
  551. ssrMockReactivity();
  552. return val;
  553. }
  554. else if (key === 'length' && val !== target.length) {
  555. target.length = val;
  556. ob === null || ob === void 0 ? void 0 : ob.dep.notify();
  557. return val;
  558. }
  559. }
  560. if (key in target && !(key in Object.prototype)) {
  561. target[key] = val;
  562. ssrMockReactivity();
  563. return val;
  564. }
  565. if (target._isVue || (ob && ob.vmCount)) {
  566. warn('Avoid adding reactive properties to a Vue instance or its root $data ' +
  567. 'at runtime - declare it upfront in the data option.');
  568. return val;
  569. }
  570. if (!ob) {
  571. target[key] = val;
  572. return val;
  573. }
  574. defineReactive(ob.value, key, val);
  575. // IMPORTANT: define access control before trigger watcher
  576. defineAccessControl(target, key, val);
  577. ssrMockReactivity();
  578. ob.dep.notify();
  579. return val;
  580. }
  581. var _isForceTrigger = false;
  582. function isForceTrigger() {
  583. return _isForceTrigger;
  584. }
  585. function setForceTrigger(v) {
  586. _isForceTrigger = v;
  587. }
  588. var RefImpl = /** @class */ (function () {
  589. function RefImpl(_a) {
  590. var get = _a.get, set = _a.set;
  591. proxy(this, 'value', {
  592. get: get,
  593. set: set,
  594. });
  595. }
  596. return RefImpl;
  597. }());
  598. function createRef(options, isReadonly, isComputed) {
  599. if (isReadonly === void 0) { isReadonly = false; }
  600. if (isComputed === void 0) { isComputed = false; }
  601. var r = new RefImpl(options);
  602. // add effect to differentiate refs from computed
  603. if (isComputed)
  604. r.effect = true;
  605. // seal the ref, this could prevent ref from being observed
  606. // It's safe to seal the ref, since we really shouldn't extend it.
  607. // related issues: #79
  608. var sealed = Object.seal(r);
  609. if (isReadonly)
  610. readonlySet.set(sealed, true);
  611. return sealed;
  612. }
  613. function ref(raw) {
  614. var _a;
  615. if (isRef(raw)) {
  616. return raw;
  617. }
  618. var value = reactive((_a = {}, _a[RefKey] = raw, _a));
  619. return createRef({
  620. get: function () { return value[RefKey]; },
  621. set: function (v) { return (value[RefKey] = v); },
  622. });
  623. }
  624. function isRef(value) {
  625. return value instanceof RefImpl;
  626. }
  627. function unref(ref) {
  628. return isRef(ref) ? ref.value : ref;
  629. }
  630. function toRefs(obj) {
  631. if (!isReactive(obj)) {
  632. warn("toRefs() expects a reactive object but received a plain one.");
  633. }
  634. if (!isPlainObject(obj))
  635. return obj;
  636. var ret = {};
  637. for (var key in obj) {
  638. ret[key] = toRef(obj, key);
  639. }
  640. return ret;
  641. }
  642. function customRef(factory) {
  643. var version = ref(0);
  644. return createRef(factory(function () { return void version.value; }, function () {
  645. ++version.value;
  646. }));
  647. }
  648. function toRef(object, key) {
  649. if (!(key in object))
  650. set$1(object, key, undefined);
  651. var v = object[key];
  652. if (isRef(v))
  653. return v;
  654. return createRef({
  655. get: function () { return object[key]; },
  656. set: function (v) { return (object[key] = v); },
  657. });
  658. }
  659. function shallowRef(raw) {
  660. var _a;
  661. if (isRef(raw)) {
  662. return raw;
  663. }
  664. var value = shallowReactive((_a = {}, _a[RefKey] = raw, _a));
  665. return createRef({
  666. get: function () { return value[RefKey]; },
  667. set: function (v) { return (value[RefKey] = v); },
  668. });
  669. }
  670. function triggerRef(value) {
  671. if (!isRef(value))
  672. return;
  673. setForceTrigger(true);
  674. value.value = value.value;
  675. setForceTrigger(false);
  676. }
  677. function proxyRefs(objectWithRefs) {
  678. var _a, e_1, _b;
  679. if (isReactive(objectWithRefs)) {
  680. return objectWithRefs;
  681. }
  682. var value = reactive((_a = {}, _a[RefKey] = objectWithRefs, _a));
  683. def(value, RefKey, value[RefKey], false);
  684. var _loop_1 = function (key) {
  685. proxy(value, key, {
  686. get: function () {
  687. if (isRef(value[RefKey][key])) {
  688. return value[RefKey][key].value;
  689. }
  690. return value[RefKey][key];
  691. },
  692. set: function (v) {
  693. if (isRef(value[RefKey][key])) {
  694. return (value[RefKey][key].value = unref(v));
  695. }
  696. value[RefKey][key] = unref(v);
  697. },
  698. });
  699. };
  700. try {
  701. for (var _c = __values(Object.keys(objectWithRefs)), _d = _c.next(); !_d.done; _d = _c.next()) {
  702. var key = _d.value;
  703. _loop_1(key);
  704. }
  705. }
  706. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  707. finally {
  708. try {
  709. if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
  710. }
  711. finally { if (e_1) throw e_1.error; }
  712. }
  713. return value;
  714. }
  715. var SKIPFLAG = '__v_skip';
  716. function isRaw(obj) {
  717. var _a;
  718. return Boolean(obj &&
  719. hasOwn(obj, '__ob__') &&
  720. typeof obj.__ob__ === 'object' &&
  721. ((_a = obj.__ob__) === null || _a === void 0 ? void 0 : _a[SKIPFLAG]));
  722. }
  723. function isReactive(obj) {
  724. var _a;
  725. return Boolean(obj &&
  726. hasOwn(obj, '__ob__') &&
  727. typeof obj.__ob__ === 'object' &&
  728. !((_a = obj.__ob__) === null || _a === void 0 ? void 0 : _a[SKIPFLAG]));
  729. }
  730. /**
  731. * Proxing property access of target.
  732. * We can do unwrapping and other things here.
  733. */
  734. function setupAccessControl(target) {
  735. if (!isPlainObject(target) ||
  736. isRaw(target) ||
  737. isArray(target) ||
  738. isRef(target) ||
  739. isComponentInstance(target) ||
  740. accessModifiedSet.has(target))
  741. return;
  742. accessModifiedSet.set(target, true);
  743. var keys = Object.keys(target);
  744. for (var i = 0; i < keys.length; i++) {
  745. defineAccessControl(target, keys[i]);
  746. }
  747. }
  748. /**
  749. * Auto unwrapping when access property
  750. */
  751. function defineAccessControl(target, key, val) {
  752. if (key === '__ob__')
  753. return;
  754. if (isRaw(target[key]))
  755. return;
  756. var getter;
  757. var setter;
  758. var property = Object.getOwnPropertyDescriptor(target, key);
  759. if (property) {
  760. if (property.configurable === false) {
  761. return;
  762. }
  763. getter = property.get;
  764. setter = property.set;
  765. if ((!getter || setter) /* not only have getter */ &&
  766. arguments.length === 2) {
  767. val = target[key];
  768. }
  769. }
  770. setupAccessControl(val);
  771. proxy(target, key, {
  772. get: function getterHandler() {
  773. var value = getter ? getter.call(target) : val;
  774. // if the key is equal to RefKey, skip the unwrap logic
  775. if (key !== RefKey && isRef(value)) {
  776. return value.value;
  777. }
  778. else {
  779. return value;
  780. }
  781. },
  782. set: function setterHandler(newVal) {
  783. if (getter && !setter)
  784. return;
  785. // If the key is equal to RefKey, skip the unwrap logic
  786. // If and only if "value" is ref and "newVal" is not a ref,
  787. // the assignment should be proxied to "value" ref.
  788. if (key !== RefKey && isRef(val) && !isRef(newVal)) {
  789. val.value = newVal;
  790. }
  791. else if (setter) {
  792. setter.call(target, newVal);
  793. val = newVal;
  794. }
  795. else {
  796. val = newVal;
  797. }
  798. setupAccessControl(newVal);
  799. },
  800. });
  801. }
  802. function observe(obj) {
  803. var Vue = getRegisteredVueOrDefault();
  804. var observed;
  805. if (Vue.observable) {
  806. observed = Vue.observable(obj);
  807. }
  808. else {
  809. var vm = defineComponentInstance(Vue, {
  810. data: {
  811. $$state: obj,
  812. },
  813. });
  814. observed = vm._data.$$state;
  815. }
  816. // in SSR, there is no __ob__. Mock for reactivity check
  817. if (!hasOwn(observed, '__ob__')) {
  818. mockReactivityDeep(observed);
  819. }
  820. return observed;
  821. }
  822. /**
  823. * Mock __ob__ for object recursively
  824. */
  825. function mockReactivityDeep(obj, seen) {
  826. var e_1, _a;
  827. if (seen === void 0) { seen = new Set(); }
  828. if (seen.has(obj) || hasOwn(obj, '__ob__') || !Object.isExtensible(obj))
  829. return;
  830. def(obj, '__ob__', mockObserver(obj));
  831. seen.add(obj);
  832. try {
  833. for (var _b = __values(Object.keys(obj)), _c = _b.next(); !_c.done; _c = _b.next()) {
  834. var key = _c.value;
  835. var value = obj[key];
  836. if (!(isPlainObject(value) || isArray(value)) ||
  837. isRaw(value) ||
  838. !Object.isExtensible(value)) {
  839. continue;
  840. }
  841. mockReactivityDeep(value, seen);
  842. }
  843. }
  844. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  845. finally {
  846. try {
  847. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  848. }
  849. finally { if (e_1) throw e_1.error; }
  850. }
  851. }
  852. function mockObserver(value) {
  853. if (value === void 0) { value = {}; }
  854. return {
  855. value: value,
  856. dep: {
  857. notify: noopFn,
  858. depend: noopFn,
  859. addSub: noopFn,
  860. removeSub: noopFn,
  861. },
  862. };
  863. }
  864. function createObserver() {
  865. return observe({}).__ob__;
  866. }
  867. function shallowReactive(obj) {
  868. var e_2, _a;
  869. if (!isObject(obj)) {
  870. {
  871. warn('"shallowReactive()" must be called on an object.');
  872. }
  873. return obj;
  874. }
  875. if (!(isPlainObject(obj) || isArray(obj)) ||
  876. isRaw(obj) ||
  877. !Object.isExtensible(obj)) {
  878. return obj;
  879. }
  880. var observed = observe(isArray(obj) ? [] : {});
  881. var ob = observed.__ob__;
  882. var _loop_1 = function (key) {
  883. var val = obj[key];
  884. var getter;
  885. var setter;
  886. var property = Object.getOwnPropertyDescriptor(obj, key);
  887. if (property) {
  888. if (property.configurable === false) {
  889. return "continue";
  890. }
  891. getter = property.get;
  892. setter = property.set;
  893. }
  894. proxy(observed, key, {
  895. get: function getterHandler() {
  896. var _a;
  897. (_a = ob.dep) === null || _a === void 0 ? void 0 : _a.depend();
  898. return val;
  899. },
  900. set: function setterHandler(newVal) {
  901. var _a;
  902. if (getter && !setter)
  903. return;
  904. if (!isForceTrigger() && val === newVal)
  905. return;
  906. if (setter) {
  907. setter.call(obj, newVal);
  908. }
  909. else {
  910. val = newVal;
  911. }
  912. (_a = ob.dep) === null || _a === void 0 ? void 0 : _a.notify();
  913. },
  914. });
  915. };
  916. try {
  917. for (var _b = __values(Object.keys(obj)), _c = _b.next(); !_c.done; _c = _b.next()) {
  918. var key = _c.value;
  919. _loop_1(key);
  920. }
  921. }
  922. catch (e_2_1) { e_2 = { error: e_2_1 }; }
  923. finally {
  924. try {
  925. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  926. }
  927. finally { if (e_2) throw e_2.error; }
  928. }
  929. return observed;
  930. }
  931. /**
  932. * Make obj reactivity
  933. */
  934. function reactive(obj) {
  935. if (!isObject(obj)) {
  936. {
  937. warn('"reactive()" must be called on an object.');
  938. }
  939. return obj;
  940. }
  941. if (!(isPlainObject(obj) || isArray(obj)) ||
  942. isRaw(obj) ||
  943. !Object.isExtensible(obj)) {
  944. return obj;
  945. }
  946. var observed = observe(obj);
  947. setupAccessControl(observed);
  948. return observed;
  949. }
  950. /**
  951. * Make sure obj can't be a reactive
  952. */
  953. function markRaw(obj) {
  954. if (!(isPlainObject(obj) || isArray(obj)) || !Object.isExtensible(obj)) {
  955. return obj;
  956. }
  957. // set the vue observable flag at obj
  958. var ob = createObserver();
  959. ob[SKIPFLAG] = true;
  960. def(obj, '__ob__', ob);
  961. // mark as Raw
  962. rawSet.set(obj, true);
  963. return obj;
  964. }
  965. function toRaw(observed) {
  966. var _a;
  967. if (isRaw(observed) || !Object.isExtensible(observed)) {
  968. return observed;
  969. }
  970. return ((_a = observed === null || observed === void 0 ? void 0 : observed.__ob__) === null || _a === void 0 ? void 0 : _a.value) || observed;
  971. }
  972. function isReadonly(obj) {
  973. return readonlySet.has(obj);
  974. }
  975. /**
  976. * **In @vue/composition-api, `reactive` only provides type-level readonly check**
  977. *
  978. * Creates a readonly copy of the original object. Note the returned copy is not
  979. * made reactive, but `readonly` can be called on an already reactive object.
  980. */
  981. function readonly(target) {
  982. if (!isObject(target)) {
  983. warn("value cannot be made reactive: ".concat(String(target)));
  984. }
  985. else {
  986. readonlySet.set(target, true);
  987. }
  988. return target;
  989. }
  990. function shallowReadonly(obj) {
  991. var e_1, _a;
  992. if (!isObject(obj)) {
  993. {
  994. warn("value cannot be made reactive: ".concat(String(obj)));
  995. }
  996. return obj;
  997. }
  998. if (!(isPlainObject(obj) || isArray(obj)) ||
  999. (!Object.isExtensible(obj) && !isRef(obj))) {
  1000. return obj;
  1001. }
  1002. var readonlyObj = isRef(obj)
  1003. ? new RefImpl({})
  1004. : isReactive(obj)
  1005. ? observe({})
  1006. : {};
  1007. var source = reactive({});
  1008. var ob = source.__ob__;
  1009. var _loop_1 = function (key) {
  1010. var val = obj[key];
  1011. var getter;
  1012. var property = Object.getOwnPropertyDescriptor(obj, key);
  1013. if (property) {
  1014. if (property.configurable === false && !isRef(obj)) {
  1015. return "continue";
  1016. }
  1017. getter = property.get;
  1018. }
  1019. proxy(readonlyObj, key, {
  1020. get: function getterHandler() {
  1021. var value = getter ? getter.call(obj) : val;
  1022. ob.dep.depend();
  1023. return value;
  1024. },
  1025. set: function (v) {
  1026. {
  1027. warn("Set operation on key \"".concat(key, "\" failed: target is readonly."));
  1028. }
  1029. },
  1030. });
  1031. };
  1032. try {
  1033. for (var _b = __values(Object.keys(obj)), _c = _b.next(); !_c.done; _c = _b.next()) {
  1034. var key = _c.value;
  1035. _loop_1(key);
  1036. }
  1037. }
  1038. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  1039. finally {
  1040. try {
  1041. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  1042. }
  1043. finally { if (e_1) throw e_1.error; }
  1044. }
  1045. readonlySet.set(readonlyObj, true);
  1046. return readonlyObj;
  1047. }
  1048. /**
  1049. * Delete a property and trigger change if necessary.
  1050. */
  1051. function del(target, key) {
  1052. var Vue = getVueConstructor();
  1053. var warn = Vue.util.warn;
  1054. if ((isUndef(target) || isPrimitive(target))) {
  1055. warn("Cannot delete reactive property on undefined, null, or primitive value: ".concat(target));
  1056. }
  1057. if (isArray(target) && isValidArrayIndex(key)) {
  1058. target.splice(key, 1);
  1059. return;
  1060. }
  1061. var ob = target.__ob__;
  1062. if (target._isVue || (ob && ob.vmCount)) {
  1063. warn('Avoid deleting properties on a Vue instance or its root $data ' +
  1064. '- just set it to null.');
  1065. return;
  1066. }
  1067. if (!hasOwn(target, key)) {
  1068. return;
  1069. }
  1070. delete target[key];
  1071. if (!ob) {
  1072. return;
  1073. }
  1074. ob.dep.notify();
  1075. }
  1076. var genName = function (name) { return "on".concat(name[0].toUpperCase() + name.slice(1)); };
  1077. function createLifeCycle(lifeCyclehook) {
  1078. return function (callback, target) {
  1079. var instance = getCurrentInstanceForFn(genName(lifeCyclehook), target);
  1080. return (instance &&
  1081. injectHookOption(getVueConstructor(), instance, lifeCyclehook, callback));
  1082. };
  1083. }
  1084. function injectHookOption(Vue, instance, hook, val) {
  1085. var options = instance.proxy.$options;
  1086. var mergeFn = Vue.config.optionMergeStrategies[hook];
  1087. var wrappedHook = wrapHookCall(instance, val);
  1088. options[hook] = mergeFn(options[hook], wrappedHook);
  1089. return wrappedHook;
  1090. }
  1091. function wrapHookCall(instance, fn) {
  1092. return function () {
  1093. var args = [];
  1094. for (var _i = 0; _i < arguments.length; _i++) {
  1095. args[_i] = arguments[_i];
  1096. }
  1097. var prev = getCurrentInstance();
  1098. setCurrentInstance(instance);
  1099. try {
  1100. return fn.apply(void 0, __spreadArray([], __read(args), false));
  1101. }
  1102. finally {
  1103. setCurrentInstance(prev);
  1104. }
  1105. };
  1106. }
  1107. var onBeforeMount = createLifeCycle('beforeMount');
  1108. var onMounted = createLifeCycle('mounted');
  1109. var onBeforeUpdate = createLifeCycle('beforeUpdate');
  1110. var onUpdated = createLifeCycle('updated');
  1111. var onBeforeUnmount = createLifeCycle('beforeDestroy');
  1112. var onUnmounted = createLifeCycle('destroyed');
  1113. var onErrorCaptured = createLifeCycle('errorCaptured');
  1114. var onActivated = createLifeCycle('activated');
  1115. var onDeactivated = createLifeCycle('deactivated');
  1116. var onServerPrefetch = createLifeCycle('serverPrefetch');
  1117. var fallbackVM;
  1118. function flushPreQueue() {
  1119. flushQueue(this, WatcherPreFlushQueueKey);
  1120. }
  1121. function flushPostQueue() {
  1122. flushQueue(this, WatcherPostFlushQueueKey);
  1123. }
  1124. function hasWatchEnv(vm) {
  1125. return vm[WatcherPreFlushQueueKey] !== undefined;
  1126. }
  1127. function installWatchEnv(vm) {
  1128. vm[WatcherPreFlushQueueKey] = [];
  1129. vm[WatcherPostFlushQueueKey] = [];
  1130. vm.$on('hook:beforeUpdate', flushPreQueue);
  1131. vm.$on('hook:updated', flushPostQueue);
  1132. }
  1133. function getWatcherOption(options) {
  1134. return __assign({
  1135. immediate: false,
  1136. deep: false,
  1137. flush: 'pre',
  1138. }, options);
  1139. }
  1140. function getWatchEffectOption(options) {
  1141. return __assign({
  1142. flush: 'pre',
  1143. }, options);
  1144. }
  1145. function getWatcherVM() {
  1146. var vm = getCurrentScopeVM();
  1147. if (!vm) {
  1148. if (!fallbackVM) {
  1149. fallbackVM = defineComponentInstance(getVueConstructor());
  1150. }
  1151. vm = fallbackVM;
  1152. }
  1153. else if (!hasWatchEnv(vm)) {
  1154. installWatchEnv(vm);
  1155. }
  1156. return vm;
  1157. }
  1158. function flushQueue(vm, key) {
  1159. var queue = vm[key];
  1160. for (var index = 0; index < queue.length; index++) {
  1161. queue[index]();
  1162. }
  1163. queue.length = 0;
  1164. }
  1165. function queueFlushJob(vm, fn, mode) {
  1166. // flush all when beforeUpdate and updated are not fired
  1167. var fallbackFlush = function () {
  1168. vm.$nextTick(function () {
  1169. if (vm[WatcherPreFlushQueueKey].length) {
  1170. flushQueue(vm, WatcherPreFlushQueueKey);
  1171. }
  1172. if (vm[WatcherPostFlushQueueKey].length) {
  1173. flushQueue(vm, WatcherPostFlushQueueKey);
  1174. }
  1175. });
  1176. };
  1177. switch (mode) {
  1178. case 'pre':
  1179. fallbackFlush();
  1180. vm[WatcherPreFlushQueueKey].push(fn);
  1181. break;
  1182. case 'post':
  1183. fallbackFlush();
  1184. vm[WatcherPostFlushQueueKey].push(fn);
  1185. break;
  1186. default:
  1187. assert(false, "flush must be one of [\"post\", \"pre\", \"sync\"], but got ".concat(mode));
  1188. break;
  1189. }
  1190. }
  1191. function createVueWatcher(vm, getter, callback, options) {
  1192. var index = vm._watchers.length;
  1193. // @ts-ignore: use undocumented options
  1194. vm.$watch(getter, callback, {
  1195. immediate: options.immediateInvokeCallback,
  1196. deep: options.deep,
  1197. lazy: options.noRun,
  1198. sync: options.sync,
  1199. before: options.before,
  1200. });
  1201. return vm._watchers[index];
  1202. }
  1203. // We have to monkeypatch the teardown function so Vue will run
  1204. // runCleanup() when it tears down the watcher on unmounted.
  1205. function patchWatcherTeardown(watcher, runCleanup) {
  1206. var _teardown = watcher.teardown;
  1207. watcher.teardown = function () {
  1208. var args = [];
  1209. for (var _i = 0; _i < arguments.length; _i++) {
  1210. args[_i] = arguments[_i];
  1211. }
  1212. _teardown.apply(watcher, args);
  1213. runCleanup();
  1214. };
  1215. }
  1216. function createWatcher(vm, source, cb, options) {
  1217. var _a;
  1218. if (!cb) {
  1219. if (options.immediate !== undefined) {
  1220. warn("watch() \"immediate\" option is only respected when using the " +
  1221. "watch(source, callback, options?) signature.");
  1222. }
  1223. if (options.deep !== undefined) {
  1224. warn("watch() \"deep\" option is only respected when using the " +
  1225. "watch(source, callback, options?) signature.");
  1226. }
  1227. }
  1228. var flushMode = options.flush;
  1229. var isSync = flushMode === 'sync';
  1230. var cleanup;
  1231. var registerCleanup = function (fn) {
  1232. cleanup = function () {
  1233. try {
  1234. fn();
  1235. }
  1236. catch (
  1237. // FIXME: remove any
  1238. error) {
  1239. logError(error, vm, 'onCleanup()');
  1240. }
  1241. };
  1242. };
  1243. // cleanup before running getter again
  1244. var runCleanup = function () {
  1245. if (cleanup) {
  1246. cleanup();
  1247. cleanup = null;
  1248. }
  1249. };
  1250. var createScheduler = function (fn) {
  1251. if (isSync ||
  1252. /* without a current active instance, ignore pre|post mode */ vm ===
  1253. fallbackVM) {
  1254. return fn;
  1255. }
  1256. return (function () {
  1257. var args = [];
  1258. for (var _i = 0; _i < arguments.length; _i++) {
  1259. args[_i] = arguments[_i];
  1260. }
  1261. return queueFlushJob(vm, function () {
  1262. fn.apply(void 0, __spreadArray([], __read(args), false));
  1263. }, flushMode);
  1264. });
  1265. };
  1266. // effect watch
  1267. if (cb === null) {
  1268. var running_1 = false;
  1269. var getter_1 = function () {
  1270. // preventing the watch callback being call in the same execution
  1271. if (running_1) {
  1272. return;
  1273. }
  1274. try {
  1275. running_1 = true;
  1276. source(registerCleanup);
  1277. }
  1278. finally {
  1279. running_1 = false;
  1280. }
  1281. };
  1282. var watcher_1 = createVueWatcher(vm, getter_1, noopFn, {
  1283. deep: options.deep || false,
  1284. sync: isSync,
  1285. before: runCleanup,
  1286. });
  1287. patchWatcherTeardown(watcher_1, runCleanup);
  1288. // enable the watcher update
  1289. watcher_1.lazy = false;
  1290. var originGet = watcher_1.get.bind(watcher_1);
  1291. // always run watchEffect
  1292. watcher_1.get = createScheduler(originGet);
  1293. return function () {
  1294. watcher_1.teardown();
  1295. };
  1296. }
  1297. var deep = options.deep;
  1298. var isMultiSource = false;
  1299. var getter;
  1300. if (isRef(source)) {
  1301. getter = function () { return source.value; };
  1302. }
  1303. else if (isReactive(source)) {
  1304. getter = function () { return source; };
  1305. deep = true;
  1306. }
  1307. else if (isArray(source)) {
  1308. isMultiSource = true;
  1309. getter = function () {
  1310. return source.map(function (s) {
  1311. if (isRef(s)) {
  1312. return s.value;
  1313. }
  1314. else if (isReactive(s)) {
  1315. return traverse(s);
  1316. }
  1317. else if (isFunction(s)) {
  1318. return s();
  1319. }
  1320. else {
  1321. warn("Invalid watch source: ".concat(JSON.stringify(s), ".\n A watch source can only be a getter/effect function, a ref, a reactive object, or an array of these types."), vm);
  1322. return noopFn;
  1323. }
  1324. });
  1325. };
  1326. }
  1327. else if (isFunction(source)) {
  1328. getter = source;
  1329. }
  1330. else {
  1331. getter = noopFn;
  1332. warn("Invalid watch source: ".concat(JSON.stringify(source), ".\n A watch source can only be a getter/effect function, a ref, a reactive object, or an array of these types."), vm);
  1333. }
  1334. if (deep) {
  1335. var baseGetter_1 = getter;
  1336. getter = function () { return traverse(baseGetter_1()); };
  1337. }
  1338. var applyCb = function (n, o) {
  1339. if (!deep &&
  1340. isMultiSource &&
  1341. n.every(function (v, i) { return isSame(v, o[i]); }))
  1342. return;
  1343. // cleanup before running cb again
  1344. runCleanup();
  1345. return cb(n, o, registerCleanup);
  1346. };
  1347. var callback = createScheduler(applyCb);
  1348. if (options.immediate) {
  1349. var originalCallback_1 = callback;
  1350. // `shiftCallback` is used to handle the first sync effect run.
  1351. // The subsequent callbacks will redirect to `callback`.
  1352. var shiftCallback_1 = function (n, o) {
  1353. shiftCallback_1 = originalCallback_1;
  1354. // o is undefined on the first call
  1355. return applyCb(n, isArray(n) ? [] : o);
  1356. };
  1357. callback = function (n, o) {
  1358. return shiftCallback_1(n, o);
  1359. };
  1360. }
  1361. // @ts-ignore: use undocumented option "sync"
  1362. var stop = vm.$watch(getter, callback, {
  1363. immediate: options.immediate,
  1364. deep: deep,
  1365. sync: isSync,
  1366. });
  1367. // Once again, we have to hack the watcher for proper teardown
  1368. var watcher = vm._watchers[vm._watchers.length - 1];
  1369. // if the return value is reactive and deep:true
  1370. // watch for changes, this might happen when new key is added
  1371. if (isReactive(watcher.value) && ((_a = watcher.value.__ob__) === null || _a === void 0 ? void 0 : _a.dep) && deep) {
  1372. watcher.value.__ob__.dep.addSub({
  1373. update: function () {
  1374. // this will force the source to be reevaluated and the callback
  1375. // executed if needed
  1376. watcher.run();
  1377. },
  1378. });
  1379. }
  1380. patchWatcherTeardown(watcher, runCleanup);
  1381. return function () {
  1382. stop();
  1383. };
  1384. }
  1385. function watchEffect(effect, options) {
  1386. var opts = getWatchEffectOption(options);
  1387. var vm = getWatcherVM();
  1388. return createWatcher(vm, effect, null, opts);
  1389. }
  1390. function watchPostEffect(effect) {
  1391. return watchEffect(effect, { flush: 'post' });
  1392. }
  1393. function watchSyncEffect(effect) {
  1394. return watchEffect(effect, { flush: 'sync' });
  1395. }
  1396. // implementation
  1397. function watch(source, cb, options) {
  1398. var callback = null;
  1399. if (isFunction(cb)) {
  1400. // source watch
  1401. callback = cb;
  1402. }
  1403. else {
  1404. // effect watch
  1405. {
  1406. warn("`watch(fn, options?)` signature has been moved to a separate API. " +
  1407. "Use `watchEffect(fn, options?)` instead. `watch` now only " +
  1408. "supports `watch(source, cb, options?) signature.");
  1409. }
  1410. options = cb;
  1411. callback = null;
  1412. }
  1413. var opts = getWatcherOption(options);
  1414. var vm = getWatcherVM();
  1415. return createWatcher(vm, source, callback, opts);
  1416. }
  1417. function traverse(value, seen) {
  1418. if (seen === void 0) { seen = new Set(); }
  1419. if (!isObject(value) || seen.has(value) || rawSet.has(value)) {
  1420. return value;
  1421. }
  1422. seen.add(value);
  1423. if (isRef(value)) {
  1424. traverse(value.value, seen);
  1425. }
  1426. else if (isArray(value)) {
  1427. for (var i = 0; i < value.length; i++) {
  1428. traverse(value[i], seen);
  1429. }
  1430. }
  1431. else if (isSet(value) || isMap(value)) {
  1432. value.forEach(function (v) {
  1433. traverse(v, seen);
  1434. });
  1435. }
  1436. else if (isPlainObject(value)) {
  1437. for (var key in value) {
  1438. traverse(value[key], seen);
  1439. }
  1440. }
  1441. return value;
  1442. }
  1443. // implement
  1444. function computed(getterOrOptions) {
  1445. var vm = getCurrentScopeVM();
  1446. var getter;
  1447. var setter;
  1448. if (isFunction(getterOrOptions)) {
  1449. getter = getterOrOptions;
  1450. }
  1451. else {
  1452. getter = getterOrOptions.get;
  1453. setter = getterOrOptions.set;
  1454. }
  1455. var computedSetter;
  1456. var computedGetter;
  1457. if (vm && !vm.$isServer) {
  1458. var _a = getVueInternalClasses(), Watcher_1 = _a.Watcher, Dep_1 = _a.Dep;
  1459. var watcher_1;
  1460. computedGetter = function () {
  1461. if (!watcher_1) {
  1462. watcher_1 = new Watcher_1(vm, getter, noopFn, { lazy: true });
  1463. }
  1464. if (watcher_1.dirty) {
  1465. watcher_1.evaluate();
  1466. }
  1467. if (Dep_1.target) {
  1468. watcher_1.depend();
  1469. }
  1470. return watcher_1.value;
  1471. };
  1472. computedSetter = function (v) {
  1473. if (!setter) {
  1474. warn('Write operation failed: computed value is readonly.', vm);
  1475. return;
  1476. }
  1477. if (setter) {
  1478. setter(v);
  1479. }
  1480. };
  1481. }
  1482. else {
  1483. // fallback
  1484. var computedHost_1 = defineComponentInstance(getVueConstructor(), {
  1485. computed: {
  1486. $$state: {
  1487. get: getter,
  1488. set: setter,
  1489. },
  1490. },
  1491. });
  1492. vm && vm.$on('hook:destroyed', function () { return computedHost_1.$destroy(); });
  1493. computedGetter = function () { return computedHost_1.$$state; };
  1494. computedSetter = function (v) {
  1495. if (!setter) {
  1496. warn('Write operation failed: computed value is readonly.', vm);
  1497. return;
  1498. }
  1499. computedHost_1.$$state = v;
  1500. };
  1501. }
  1502. return createRef({
  1503. get: computedGetter,
  1504. set: computedSetter,
  1505. }, !setter, true);
  1506. }
  1507. var NOT_FOUND = {};
  1508. function resolveInject(provideKey, vm) {
  1509. var source = vm;
  1510. while (source) {
  1511. if (source._provided && hasOwn(source._provided, provideKey)) {
  1512. return source._provided[provideKey];
  1513. }
  1514. source = source.$parent;
  1515. }
  1516. return NOT_FOUND;
  1517. }
  1518. function provide(key, value) {
  1519. var _a;
  1520. var vm = (_a = getCurrentInstanceForFn('provide')) === null || _a === void 0 ? void 0 : _a.proxy;
  1521. if (!vm)
  1522. return;
  1523. if (!vm._provided) {
  1524. var provideCache_1 = {};
  1525. proxy(vm, '_provided', {
  1526. get: function () { return provideCache_1; },
  1527. set: function (v) { return Object.assign(provideCache_1, v); },
  1528. });
  1529. }
  1530. vm._provided[key] = value;
  1531. }
  1532. function inject(key, defaultValue, treatDefaultAsFactory) {
  1533. var _a;
  1534. if (treatDefaultAsFactory === void 0) { treatDefaultAsFactory = false; }
  1535. var vm = (_a = getCurrentInstance()) === null || _a === void 0 ? void 0 : _a.proxy;
  1536. if (!vm) {
  1537. warn("inject() can only be used inside setup() or functional components.");
  1538. return;
  1539. }
  1540. if (!key) {
  1541. warn("injection \"".concat(String(key), "\" not found."), vm);
  1542. return defaultValue;
  1543. }
  1544. var val = resolveInject(key, vm);
  1545. if (val !== NOT_FOUND) {
  1546. return val;
  1547. }
  1548. else if (arguments.length > 1) {
  1549. return treatDefaultAsFactory && isFunction(defaultValue)
  1550. ? defaultValue()
  1551. : defaultValue;
  1552. }
  1553. else {
  1554. warn("Injection \"".concat(String(key), "\" not found."), vm);
  1555. }
  1556. }
  1557. var EMPTY_OBJ = Object.freeze({})
  1558. ;
  1559. var useCssModule = function (name) {
  1560. var _a;
  1561. if (name === void 0) { name = '$style'; }
  1562. var instance = getCurrentInstance();
  1563. if (!instance) {
  1564. warn("useCssModule must be called inside setup()");
  1565. return EMPTY_OBJ;
  1566. }
  1567. var mod = (_a = instance.proxy) === null || _a === void 0 ? void 0 : _a[name];
  1568. if (!mod) {
  1569. warn("Current instance does not have CSS module named \"".concat(name, "\"."));
  1570. return EMPTY_OBJ;
  1571. }
  1572. return mod;
  1573. };
  1574. /**
  1575. * @deprecated use `useCssModule` instead.
  1576. */
  1577. var useCSSModule = useCssModule;
  1578. function createApp(rootComponent, rootProps) {
  1579. if (rootProps === void 0) { rootProps = undefined; }
  1580. var V = getVueConstructor();
  1581. var mountedVM = undefined;
  1582. var provide = {};
  1583. var app = {
  1584. config: V.config,
  1585. use: V.use.bind(V),
  1586. mixin: V.mixin.bind(V),
  1587. component: V.component.bind(V),
  1588. provide: function (key, value) {
  1589. provide[key] = value;
  1590. return this;
  1591. },
  1592. directive: function (name, dir) {
  1593. if (dir) {
  1594. V.directive(name, dir);
  1595. return app;
  1596. }
  1597. else {
  1598. return V.directive(name);
  1599. }
  1600. },
  1601. mount: function (el, hydrating) {
  1602. if (!mountedVM) {
  1603. mountedVM = new V(__assign(__assign({ propsData: rootProps }, rootComponent), { provide: __assign(__assign({}, provide), rootComponent.provide) }));
  1604. mountedVM.$mount(el, hydrating);
  1605. return mountedVM;
  1606. }
  1607. else {
  1608. {
  1609. warn("App has already been mounted.\n" +
  1610. "If you want to remount the same app, move your app creation logic " +
  1611. "into a factory function and create fresh app instances for each " +
  1612. "mount - e.g. `const createMyApp = () => createApp(App)`");
  1613. }
  1614. return mountedVM;
  1615. }
  1616. },
  1617. unmount: function () {
  1618. if (mountedVM) {
  1619. mountedVM.$destroy();
  1620. mountedVM = undefined;
  1621. }
  1622. else {
  1623. warn("Cannot unmount an app that is not mounted.");
  1624. }
  1625. },
  1626. };
  1627. return app;
  1628. }
  1629. var nextTick = function nextTick() {
  1630. var _a;
  1631. var args = [];
  1632. for (var _i = 0; _i < arguments.length; _i++) {
  1633. args[_i] = arguments[_i];
  1634. }
  1635. return (_a = getVueConstructor()) === null || _a === void 0 ? void 0 : _a.nextTick.apply(this, args);
  1636. };
  1637. var fallbackCreateElement;
  1638. var createElement = function createElement() {
  1639. var _a;
  1640. var args = [];
  1641. for (var _i = 0; _i < arguments.length; _i++) {
  1642. args[_i] = arguments[_i];
  1643. }
  1644. var instance = (this === null || this === void 0 ? void 0 : this.proxy) || ((_a = getCurrentInstance()) === null || _a === void 0 ? void 0 : _a.proxy);
  1645. if (!instance) {
  1646. warn('`createElement()` has been called outside of render function.');
  1647. if (!fallbackCreateElement) {
  1648. fallbackCreateElement = defineComponentInstance(getVueConstructor()).$createElement;
  1649. }
  1650. return fallbackCreateElement.apply(fallbackCreateElement, args);
  1651. }
  1652. return instance.$createElement.apply(instance, args);
  1653. };
  1654. function useSlots() {
  1655. return getContext().slots;
  1656. }
  1657. function useAttrs() {
  1658. return getContext().attrs;
  1659. }
  1660. function getContext() {
  1661. var i = getCurrentInstance();
  1662. if (!i) {
  1663. warn("useContext() called without active instance.");
  1664. }
  1665. return i.setupContext;
  1666. }
  1667. function set(vm, key, value) {
  1668. var state = (vm.__composition_api_state__ =
  1669. vm.__composition_api_state__ || {});
  1670. state[key] = value;
  1671. }
  1672. function get(vm, key) {
  1673. return (vm.__composition_api_state__ || {})[key];
  1674. }
  1675. var vmStateManager = {
  1676. set: set,
  1677. get: get,
  1678. };
  1679. function asVmProperty(vm, propName, propValue) {
  1680. var props = vm.$options.props;
  1681. if (!(propName in vm) && !(props && hasOwn(props, propName))) {
  1682. if (isRef(propValue)) {
  1683. proxy(vm, propName, {
  1684. get: function () { return propValue.value; },
  1685. set: function (val) {
  1686. propValue.value = val;
  1687. },
  1688. });
  1689. }
  1690. else {
  1691. proxy(vm, propName, {
  1692. get: function () {
  1693. if (isReactive(propValue)) {
  1694. propValue.__ob__.dep.depend();
  1695. }
  1696. return propValue;
  1697. },
  1698. set: function (val) {
  1699. propValue = val;
  1700. },
  1701. });
  1702. }
  1703. {
  1704. // expose binding to Vue Devtool as a data property
  1705. // delay this until state has been resolved to prevent repeated works
  1706. vm.$nextTick(function () {
  1707. if (Object.keys(vm._data).indexOf(propName) !== -1) {
  1708. return;
  1709. }
  1710. if (isRef(propValue)) {
  1711. proxy(vm._data, propName, {
  1712. get: function () { return propValue.value; },
  1713. set: function (val) {
  1714. propValue.value = val;
  1715. },
  1716. });
  1717. }
  1718. else {
  1719. proxy(vm._data, propName, {
  1720. get: function () { return propValue; },
  1721. set: function (val) {
  1722. propValue = val;
  1723. },
  1724. });
  1725. }
  1726. });
  1727. }
  1728. }
  1729. else {
  1730. if (props && hasOwn(props, propName)) {
  1731. warn("The setup binding property \"".concat(propName, "\" is already declared as a prop."), vm);
  1732. }
  1733. else {
  1734. warn("The setup binding property \"".concat(propName, "\" is already declared."), vm);
  1735. }
  1736. }
  1737. }
  1738. function updateTemplateRef(vm) {
  1739. var rawBindings = vmStateManager.get(vm, 'rawBindings') || {};
  1740. if (!rawBindings || !Object.keys(rawBindings).length)
  1741. return;
  1742. var refs = vm.$refs;
  1743. var oldRefKeys = vmStateManager.get(vm, 'refs') || [];
  1744. for (var index = 0; index < oldRefKeys.length; index++) {
  1745. var key = oldRefKeys[index];
  1746. var setupValue = rawBindings[key];
  1747. if (!refs[key] && setupValue && isRef(setupValue)) {
  1748. setupValue.value = null;
  1749. }
  1750. }
  1751. var newKeys = Object.keys(refs);
  1752. var validNewKeys = [];
  1753. for (var index = 0; index < newKeys.length; index++) {
  1754. var key = newKeys[index];
  1755. var setupValue = rawBindings[key];
  1756. if (refs[key] && setupValue && isRef(setupValue)) {
  1757. setupValue.value = refs[key];
  1758. validNewKeys.push(key);
  1759. }
  1760. }
  1761. vmStateManager.set(vm, 'refs', validNewKeys);
  1762. }
  1763. function afterRender(vm) {
  1764. var stack = [vm._vnode];
  1765. while (stack.length) {
  1766. var vnode = stack.pop();
  1767. if (vnode) {
  1768. if (vnode.context)
  1769. updateTemplateRef(vnode.context);
  1770. if (vnode.children) {
  1771. for (var i = 0; i < vnode.children.length; ++i) {
  1772. stack.push(vnode.children[i]);
  1773. }
  1774. }
  1775. }
  1776. }
  1777. }
  1778. function updateVmAttrs(vm, ctx) {
  1779. var e_1, _a;
  1780. if (!vm) {
  1781. return;
  1782. }
  1783. var attrBindings = vmStateManager.get(vm, 'attrBindings');
  1784. if (!attrBindings && !ctx) {
  1785. // fix 840
  1786. return;
  1787. }
  1788. if (!attrBindings) {
  1789. var observedData = reactive({});
  1790. attrBindings = { ctx: ctx, data: observedData };
  1791. vmStateManager.set(vm, 'attrBindings', attrBindings);
  1792. proxy(ctx, 'attrs', {
  1793. get: function () {
  1794. return attrBindings === null || attrBindings === void 0 ? void 0 : attrBindings.data;
  1795. },
  1796. set: function () {
  1797. warn("Cannot assign to '$attrs' because it is a read-only property", vm);
  1798. },
  1799. });
  1800. }
  1801. var source = vm.$attrs;
  1802. var _loop_1 = function (attr) {
  1803. if (!hasOwn(attrBindings.data, attr)) {
  1804. proxy(attrBindings.data, attr, {
  1805. get: function () {
  1806. // to ensure it always return the latest value
  1807. return vm.$attrs[attr];
  1808. },
  1809. });
  1810. }
  1811. };
  1812. try {
  1813. for (var _b = __values(Object.keys(source)), _c = _b.next(); !_c.done; _c = _b.next()) {
  1814. var attr = _c.value;
  1815. _loop_1(attr);
  1816. }
  1817. }
  1818. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  1819. finally {
  1820. try {
  1821. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  1822. }
  1823. finally { if (e_1) throw e_1.error; }
  1824. }
  1825. }
  1826. function resolveScopedSlots(vm, slotsProxy) {
  1827. var parentVNode = vm.$options._parentVnode;
  1828. if (!parentVNode)
  1829. return;
  1830. var prevSlots = vmStateManager.get(vm, 'slots') || [];
  1831. var curSlots = resolveSlots(parentVNode.data.scopedSlots, vm.$slots);
  1832. // remove staled slots
  1833. for (var index = 0; index < prevSlots.length; index++) {
  1834. var key = prevSlots[index];
  1835. if (!curSlots[key]) {
  1836. delete slotsProxy[key];
  1837. }
  1838. }
  1839. // proxy fresh slots
  1840. var slotNames = Object.keys(curSlots);
  1841. for (var index = 0; index < slotNames.length; index++) {
  1842. var key = slotNames[index];
  1843. if (!slotsProxy[key]) {
  1844. slotsProxy[key] = createSlotProxy(vm, key);
  1845. }
  1846. }
  1847. vmStateManager.set(vm, 'slots', slotNames);
  1848. }
  1849. function activateCurrentInstance(instance, fn, onError) {
  1850. var preVm = getCurrentInstance();
  1851. setCurrentInstance(instance);
  1852. try {
  1853. return fn(instance);
  1854. }
  1855. catch (
  1856. // FIXME: remove any
  1857. err) {
  1858. if (onError) {
  1859. onError(err);
  1860. }
  1861. else {
  1862. throw err;
  1863. }
  1864. }
  1865. finally {
  1866. setCurrentInstance(preVm);
  1867. }
  1868. }
  1869. function mixin(Vue) {
  1870. Vue.mixin({
  1871. beforeCreate: functionApiInit,
  1872. mounted: function () {
  1873. afterRender(this);
  1874. },
  1875. beforeUpdate: function () {
  1876. updateVmAttrs(this);
  1877. },
  1878. updated: function () {
  1879. afterRender(this);
  1880. },
  1881. });
  1882. /**
  1883. * Vuex init hook, injected into each instances init hooks list.
  1884. */
  1885. function functionApiInit() {
  1886. var vm = this;
  1887. var $options = vm.$options;
  1888. var setup = $options.setup, render = $options.render;
  1889. if (render) {
  1890. // keep currentInstance accessible for createElement
  1891. $options.render = function () {
  1892. var _this = this;
  1893. var args = [];
  1894. for (var _i = 0; _i < arguments.length; _i++) {
  1895. args[_i] = arguments[_i];
  1896. }
  1897. return activateCurrentInstance(toVue3ComponentInstance(vm), function () {
  1898. return render.apply(_this, args);
  1899. });
  1900. };
  1901. }
  1902. if (!setup) {
  1903. return;
  1904. }
  1905. if (!isFunction(setup)) {
  1906. {
  1907. warn('The "setup" option should be a function that returns a object in component definitions.', vm);
  1908. }
  1909. return;
  1910. }
  1911. var data = $options.data;
  1912. // wrapper the data option, so we can invoke setup before data get resolved
  1913. $options.data = function wrappedData() {
  1914. initSetup(vm, vm.$props);
  1915. return isFunction(data)
  1916. ? data.call(vm, vm)
  1917. : data || {};
  1918. };
  1919. }
  1920. function initSetup(vm, props) {
  1921. if (props === void 0) { props = {}; }
  1922. var setup = vm.$options.setup;
  1923. var ctx = createSetupContext(vm);
  1924. var instance = toVue3ComponentInstance(vm);
  1925. instance.setupContext = ctx;
  1926. // fake reactive for `toRefs(props)`
  1927. def(props, '__ob__', createObserver());
  1928. // resolve scopedSlots and slots to functions
  1929. resolveScopedSlots(vm, ctx.slots);
  1930. var binding;
  1931. activateCurrentInstance(instance, function () {
  1932. // make props to be fake reactive, this is for `toRefs(props)`
  1933. binding = setup(props, ctx);
  1934. });
  1935. if (!binding)
  1936. return;
  1937. if (isFunction(binding)) {
  1938. // keep typescript happy with the binding type.
  1939. var bindingFunc_1 = binding;
  1940. // keep currentInstance accessible for createElement
  1941. vm.$options.render = function () {
  1942. resolveScopedSlots(vm, ctx.slots);
  1943. return activateCurrentInstance(instance, function () { return bindingFunc_1(); });
  1944. };
  1945. return;
  1946. }
  1947. else if (isObject(binding)) {
  1948. if (isReactive(binding)) {
  1949. binding = toRefs(binding);
  1950. }
  1951. vmStateManager.set(vm, 'rawBindings', binding);
  1952. var bindingObj_1 = binding;
  1953. Object.keys(bindingObj_1).forEach(function (name) {
  1954. var bindingValue = bindingObj_1[name];
  1955. if (!isRef(bindingValue)) {
  1956. if (!isReactive(bindingValue)) {
  1957. if (isFunction(bindingValue)) {
  1958. var copy_1 = bindingValue;
  1959. bindingValue = bindingValue.bind(vm);
  1960. Object.keys(copy_1).forEach(function (ele) {
  1961. bindingValue[ele] = copy_1[ele];
  1962. });
  1963. }
  1964. else if (!isObject(bindingValue)) {
  1965. bindingValue = ref(bindingValue);
  1966. }
  1967. else if (hasReactiveArrayChild(bindingValue)) {
  1968. // creates a custom reactive properties without make the object explicitly reactive
  1969. // NOTE we should try to avoid this, better implementation needed
  1970. customReactive(bindingValue);
  1971. }
  1972. }
  1973. else if (isArray(bindingValue)) {
  1974. bindingValue = ref(bindingValue);
  1975. }
  1976. }
  1977. asVmProperty(vm, name, bindingValue);
  1978. });
  1979. return;
  1980. }
  1981. {
  1982. assert(false, "\"setup\" must return a \"Object\" or a \"Function\", got \"".concat(Object.prototype.toString
  1983. .call(binding)
  1984. .slice(8, -1), "\""));
  1985. }
  1986. }
  1987. function customReactive(target, seen) {
  1988. if (seen === void 0) { seen = new Set(); }
  1989. if (seen.has(target))
  1990. return;
  1991. if (!isPlainObject(target) ||
  1992. isRef(target) ||
  1993. isReactive(target) ||
  1994. isRaw(target))
  1995. return;
  1996. var Vue = getVueConstructor();
  1997. // @ts-expect-error https://github.com/vuejs/vue/pull/12132
  1998. var defineReactive = Vue.util.defineReactive;
  1999. Object.keys(target).forEach(function (k) {
  2000. var val = target[k];
  2001. defineReactive(target, k, val);
  2002. if (val) {
  2003. seen.add(val);
  2004. customReactive(val, seen);
  2005. }
  2006. return;
  2007. });
  2008. }
  2009. function hasReactiveArrayChild(target, visited) {
  2010. if (visited === void 0) { visited = new Map(); }
  2011. if (visited.has(target)) {
  2012. return visited.get(target);
  2013. }
  2014. visited.set(target, false);
  2015. if (isArray(target) && isReactive(target)) {
  2016. visited.set(target, true);
  2017. return true;
  2018. }
  2019. if (!isPlainObject(target) || isRaw(target) || isRef(target)) {
  2020. return false;
  2021. }
  2022. return Object.keys(target).some(function (x) {
  2023. return hasReactiveArrayChild(target[x], visited);
  2024. });
  2025. }
  2026. function createSetupContext(vm) {
  2027. var ctx = { slots: {} };
  2028. var propsPlain = [
  2029. 'root',
  2030. 'parent',
  2031. 'refs',
  2032. 'listeners',
  2033. 'isServer',
  2034. 'ssrContext',
  2035. ];
  2036. var methodReturnVoid = ['emit'];
  2037. propsPlain.forEach(function (key) {
  2038. var srcKey = "$".concat(key);
  2039. proxy(ctx, key, {
  2040. get: function () { return vm[srcKey]; },
  2041. set: function () {
  2042. warn("Cannot assign to '".concat(key, "' because it is a read-only property"), vm);
  2043. },
  2044. });
  2045. });
  2046. updateVmAttrs(vm, ctx);
  2047. methodReturnVoid.forEach(function (key) {
  2048. var srcKey = "$".concat(key);
  2049. proxy(ctx, key, {
  2050. get: function () {
  2051. return function () {
  2052. var args = [];
  2053. for (var _i = 0; _i < arguments.length; _i++) {
  2054. args[_i] = arguments[_i];
  2055. }
  2056. var fn = vm[srcKey];
  2057. fn.apply(vm, args);
  2058. };
  2059. },
  2060. });
  2061. });
  2062. return ctx;
  2063. }
  2064. }
  2065. /**
  2066. * Helper that recursively merges two data objects together.
  2067. */
  2068. function mergeData(from, to) {
  2069. if (!from)
  2070. return to;
  2071. if (!to)
  2072. return from;
  2073. var key;
  2074. var toVal;
  2075. var fromVal;
  2076. var keys = hasSymbol ? Reflect.ownKeys(from) : Object.keys(from);
  2077. for (var i = 0; i < keys.length; i++) {
  2078. key = keys[i];
  2079. // in case the object is already observed...
  2080. if (key === '__ob__')
  2081. continue;
  2082. toVal = to[key];
  2083. fromVal = from[key];
  2084. if (!hasOwn(to, key)) {
  2085. to[key] = fromVal;
  2086. }
  2087. else if (toVal !== fromVal &&
  2088. isPlainObject(toVal) &&
  2089. !isRef(toVal) &&
  2090. isPlainObject(fromVal) &&
  2091. !isRef(fromVal)) {
  2092. mergeData(fromVal, toVal);
  2093. }
  2094. }
  2095. return to;
  2096. }
  2097. function install(Vue) {
  2098. if (isVueRegistered(Vue)) {
  2099. {
  2100. warn('[vue-composition-api] already installed. Vue.use(VueCompositionAPI) should be called only once.');
  2101. }
  2102. return;
  2103. }
  2104. {
  2105. if (Vue.version) {
  2106. if (Vue.version[0] !== '2' || Vue.version[1] !== '.') {
  2107. warn("[vue-composition-api] only works with Vue 2, v".concat(Vue.version, " found."));
  2108. }
  2109. }
  2110. else {
  2111. warn('[vue-composition-api] no Vue version found');
  2112. }
  2113. }
  2114. Vue.config.optionMergeStrategies.setup = function (parent, child) {
  2115. return function mergedSetupFn(props, context) {
  2116. return mergeData(isFunction(parent) ? parent(props, context) || {} : undefined, isFunction(child) ? child(props, context) || {} : undefined);
  2117. };
  2118. };
  2119. setVueConstructor(Vue);
  2120. mixin(Vue);
  2121. }
  2122. var Plugin = {
  2123. install: function (Vue) { return install(Vue); },
  2124. };
  2125. // implementation, close to no-op
  2126. function defineComponent(options) {
  2127. return options;
  2128. }
  2129. function defineAsyncComponent(source) {
  2130. if (isFunction(source)) {
  2131. source = { loader: source };
  2132. }
  2133. var loader = source.loader, loadingComponent = source.loadingComponent, errorComponent = source.errorComponent, _a = source.delay, delay = _a === void 0 ? 200 : _a, timeout = source.timeout, // undefined = never times out
  2134. _b = source.suspensible, // undefined = never times out
  2135. suspensible = _b === void 0 ? false : _b, // in Vue 3 default is true
  2136. userOnError = source.onError;
  2137. if (suspensible) {
  2138. warn("The suspensiblbe option for async components is not supported in Vue2. It is ignored.");
  2139. }
  2140. var pendingRequest = null;
  2141. var retries = 0;
  2142. var retry = function () {
  2143. retries++;
  2144. pendingRequest = null;
  2145. return load();
  2146. };
  2147. var load = function () {
  2148. var thisRequest;
  2149. return (pendingRequest ||
  2150. (thisRequest = pendingRequest =
  2151. loader()
  2152. .catch(function (err) {
  2153. err = err instanceof Error ? err : new Error(String(err));
  2154. if (userOnError) {
  2155. return new Promise(function (resolve, reject) {
  2156. var userRetry = function () { return resolve(retry()); };
  2157. var userFail = function () { return reject(err); };
  2158. userOnError(err, userRetry, userFail, retries + 1);
  2159. });
  2160. }
  2161. else {
  2162. throw err;
  2163. }
  2164. })
  2165. .then(function (comp) {
  2166. if (thisRequest !== pendingRequest && pendingRequest) {
  2167. return pendingRequest;
  2168. }
  2169. if (!comp) {
  2170. warn("Async component loader resolved to undefined. " +
  2171. "If you are using retry(), make sure to return its return value.");
  2172. }
  2173. // interop module default
  2174. if (comp &&
  2175. (comp.__esModule || comp[Symbol.toStringTag] === 'Module')) {
  2176. comp = comp.default;
  2177. }
  2178. if (comp && !isObject(comp) && !isFunction(comp)) {
  2179. throw new Error("Invalid async component load result: ".concat(comp));
  2180. }
  2181. return comp;
  2182. })));
  2183. };
  2184. return function () {
  2185. var component = load();
  2186. return {
  2187. component: component,
  2188. delay: delay,
  2189. timeout: timeout,
  2190. error: errorComponent,
  2191. loading: loadingComponent,
  2192. };
  2193. };
  2194. }
  2195. var version = "1.7.2";
  2196. // auto install when using CDN
  2197. if (typeof window !== 'undefined' && window.Vue) {
  2198. window.Vue.use(Plugin);
  2199. }
  2200. exports.EffectScope = EffectScope;
  2201. exports.computed = computed;
  2202. exports.createApp = createApp;
  2203. exports.createRef = createRef;
  2204. exports.customRef = customRef;
  2205. exports["default"] = Plugin;
  2206. exports.defineAsyncComponent = defineAsyncComponent;
  2207. exports.defineComponent = defineComponent;
  2208. exports.del = del;
  2209. exports.effectScope = effectScope;
  2210. exports.getCurrentInstance = getCurrentInstance;
  2211. exports.getCurrentScope = getCurrentScope;
  2212. exports.h = createElement;
  2213. exports.inject = inject;
  2214. exports.isRaw = isRaw;
  2215. exports.isReactive = isReactive;
  2216. exports.isReadonly = isReadonly;
  2217. exports.isRef = isRef;
  2218. exports.markRaw = markRaw;
  2219. exports.nextTick = nextTick;
  2220. exports.onActivated = onActivated;
  2221. exports.onBeforeMount = onBeforeMount;
  2222. exports.onBeforeUnmount = onBeforeUnmount;
  2223. exports.onBeforeUpdate = onBeforeUpdate;
  2224. exports.onDeactivated = onDeactivated;
  2225. exports.onErrorCaptured = onErrorCaptured;
  2226. exports.onMounted = onMounted;
  2227. exports.onScopeDispose = onScopeDispose;
  2228. exports.onServerPrefetch = onServerPrefetch;
  2229. exports.onUnmounted = onUnmounted;
  2230. exports.onUpdated = onUpdated;
  2231. exports.provide = provide;
  2232. exports.proxyRefs = proxyRefs;
  2233. exports.reactive = reactive;
  2234. exports.readonly = readonly;
  2235. exports.ref = ref;
  2236. exports.set = set$1;
  2237. exports.shallowReactive = shallowReactive;
  2238. exports.shallowReadonly = shallowReadonly;
  2239. exports.shallowRef = shallowRef;
  2240. exports.toRaw = toRaw;
  2241. exports.toRef = toRef;
  2242. exports.toRefs = toRefs;
  2243. exports.triggerRef = triggerRef;
  2244. exports.unref = unref;
  2245. exports.useAttrs = useAttrs;
  2246. exports.useCSSModule = useCSSModule;
  2247. exports.useCssModule = useCssModule;
  2248. exports.useSlots = useSlots;
  2249. exports.version = version;
  2250. exports.warn = warn$1;
  2251. exports.watch = watch;
  2252. exports.watchEffect = watchEffect;
  2253. exports.watchPostEffect = watchPostEffect;
  2254. exports.watchSyncEffect = watchSyncEffect;