rezor 0.0.0 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1240 @@
1
+ /*!
2
+ * rezor v0.0.2
3
+ * https://github.com/rezorjs/rezor
4
+ * (c) 2026-present Yang Mingshan
5
+ * @license MIT
6
+ */
7
+ 'use strict';
8
+
9
+ let currentApp = null;
10
+ function setCurrentApp(app) {
11
+ currentApp = app;
12
+ }
13
+ function unsetCurrentApp() {
14
+ currentApp = null;
15
+ }
16
+ let currentPage = null;
17
+ function setCurrentPage(page) {
18
+ currentPage = page;
19
+ }
20
+ function unsetCurrentPage() {
21
+ currentPage = null;
22
+ }
23
+ let currentComponent = null;
24
+ function setCurrentComponent(component) {
25
+ currentComponent = component;
26
+ }
27
+ function unsetCurrentComponent() {
28
+ currentComponent = null;
29
+ }
30
+ function getCurrentInstance() {
31
+ return currentPage || currentComponent;
32
+ }
33
+ function getCurrentInstanceAll() {
34
+ return currentApp || currentPage || currentComponent;
35
+ }
36
+
37
+ function getHooksStore(instance) {
38
+ if (instance.__hooks__ === undefined) {
39
+ instance.__hooks__ = { cursor: 0, slots: [] };
40
+ }
41
+ return instance.__hooks__;
42
+ }
43
+ function resetHooksCursor(instance) {
44
+ const store = instance.__hooks__;
45
+ if (store === undefined) {
46
+ return;
47
+ }
48
+ store.cursor = 0;
49
+ }
50
+ function trimHooksStore(instance) {
51
+ const store = instance.__hooks__;
52
+ if (store === undefined) {
53
+ return;
54
+ }
55
+ store.slots.length = store.cursor;
56
+ }
57
+ function isHookKind(slot, kind) {
58
+ return slot !== undefined && slot.kind === kind;
59
+ }
60
+ function resetLifecycleCursors(instance, lifecycles) {
61
+ const store = instance.__lifecycle__;
62
+ if (store === undefined) {
63
+ return;
64
+ }
65
+ lifecycles.forEach((lifecycle) => {
66
+ if (store[lifecycle] !== undefined) {
67
+ store[lifecycle].cursor = 0;
68
+ }
69
+ });
70
+ }
71
+ function trimLifecycleBuckets(instance, lifecycles) {
72
+ const store = instance.__lifecycle__;
73
+ if (store === undefined) {
74
+ return;
75
+ }
76
+ lifecycles.forEach((lifecycle) => {
77
+ if (store[lifecycle] !== undefined) {
78
+ store[lifecycle].handlers.length = store[lifecycle].cursor;
79
+ }
80
+ });
81
+ }
82
+ function registerLifecycleHook(instance, lifecycle, hook) {
83
+ if (instance.__lifecycle__ === undefined) {
84
+ instance.__lifecycle__ = {};
85
+ }
86
+ const store = instance.__lifecycle__;
87
+ if (store[lifecycle] === undefined) {
88
+ store[lifecycle] = { cursor: 0, handlers: [] };
89
+ }
90
+ const bucket = store[lifecycle];
91
+ bucket.handlers[bucket.cursor] = hook;
92
+ bucket.cursor += 1;
93
+ }
94
+ function getLifecycleCursor(instance, lifecycle) {
95
+ const store = instance.__lifecycle__;
96
+ if (store === undefined || store[lifecycle] === undefined) {
97
+ return 0;
98
+ }
99
+ return store[lifecycle].cursor;
100
+ }
101
+ function getLifecycleHooks(instance, lifecycle) {
102
+ const store = instance.__lifecycle__;
103
+ if (store === undefined || store[lifecycle] === undefined) {
104
+ return [];
105
+ }
106
+ return store[lifecycle].handlers;
107
+ }
108
+
109
+ function useRef(initialValue) {
110
+ const currentInstance = getCurrentInstanceAll();
111
+ if (currentInstance) {
112
+ const store = getHooksStore(currentInstance);
113
+ const index = store.cursor;
114
+ let refSlot = store.slots[index];
115
+ if (!isHookKind(refSlot, 'ref')) {
116
+ refSlot = { kind: 'ref', ref: { current: initialValue } };
117
+ store.slots[index] = refSlot;
118
+ }
119
+ store.cursor += 1;
120
+ return refSlot.ref;
121
+ }
122
+ /* istanbul ignore else -- @preserve */
123
+ {
124
+ console.warn('useRef() hook can only be called during execution of render().');
125
+ }
126
+ return { current: initialValue };
127
+ }
128
+
129
+ const extend = Object.assign;
130
+ function exclude(obj, keys) {
131
+ const ret = {};
132
+ Object.keys(obj).forEach((key) => {
133
+ if (!keys.includes(key)) {
134
+ ret[key] = obj[key];
135
+ }
136
+ });
137
+ return ret;
138
+ }
139
+ function isFunction(x) {
140
+ return typeof x === 'function';
141
+ }
142
+ function areHookDepsEqual(prevDeps, nextDeps) {
143
+ if (prevDeps === undefined || nextDeps === undefined) {
144
+ return false;
145
+ }
146
+ if (nextDeps.length !== prevDeps.length) {
147
+ return false;
148
+ }
149
+ for (let i = 0; i < nextDeps.length; i++) {
150
+ if (!Object.is(nextDeps[i], prevDeps[i])) {
151
+ return false;
152
+ }
153
+ }
154
+ return true;
155
+ }
156
+
157
+ var SchedulerJobFlags;
158
+ (function (SchedulerJobFlags) {
159
+ SchedulerJobFlags[SchedulerJobFlags["QUEUED"] = 1] = "QUEUED";
160
+ SchedulerJobFlags[SchedulerJobFlags["DISPOSED"] = 2] = "DISPOSED";
161
+ })(SchedulerJobFlags || (SchedulerJobFlags = {}));
162
+ const jobs = [];
163
+ let postJobs = [];
164
+ let activePostJobs = null;
165
+ let currentFlushPromise = null;
166
+ let jobsLength = 0;
167
+ let flushIndex = 0;
168
+ let postFlushIndex = 0;
169
+ const resolvedPromise = /*@__PURE__*/ Promise.resolve();
170
+ const RECURSION_LIMIT = 100;
171
+ function nextTick(fn) {
172
+ const p = currentFlushPromise || resolvedPromise;
173
+ return fn ? p.then(fn) : p;
174
+ }
175
+ function queueJob(job) {
176
+ if (queueJobWorker(job, jobs, jobsLength)) {
177
+ jobsLength++;
178
+ queueFlush();
179
+ }
180
+ }
181
+ function queueJobWorker(job, queue, length) {
182
+ const flags = job.flags;
183
+ if (!(flags & SchedulerJobFlags.QUEUED)) {
184
+ job.flags = flags | SchedulerJobFlags.QUEUED;
185
+ queue[length] = job;
186
+ return true;
187
+ }
188
+ return false;
189
+ }
190
+ function queueFlush() {
191
+ if (!currentFlushPromise) {
192
+ // We don't flush post jobs on flushJobs's finally block, so we don't need `doFlushJobs` here.
193
+ currentFlushPromise = resolvedPromise.then(flushJobs);
194
+ }
195
+ }
196
+ function queuePostFlushCb(job) {
197
+ queueJobWorker(job, postJobs, postJobs.length);
198
+ }
199
+ function flushPostFlushCbs() {
200
+ if (postJobs.length) {
201
+ activePostJobs = postJobs;
202
+ postJobs = [];
203
+ try {
204
+ while (postFlushIndex < activePostJobs.length) {
205
+ const cb = activePostJobs[postFlushIndex++];
206
+ if (!(cb.flags & SchedulerJobFlags.DISPOSED)) {
207
+ cb.flags &= ~SchedulerJobFlags.QUEUED;
208
+ cb();
209
+ }
210
+ }
211
+ }
212
+ finally {
213
+ // If there was an error we still need to clear the QUEUED flags
214
+ while (postFlushIndex < activePostJobs.length) {
215
+ activePostJobs[postFlushIndex++].flags &= ~SchedulerJobFlags.QUEUED;
216
+ }
217
+ activePostJobs = null;
218
+ postFlushIndex = 0;
219
+ }
220
+ }
221
+ }
222
+ function flushJobs() {
223
+ let seen;
224
+ /* istanbul ignore else -- @preserve */
225
+ {
226
+ seen = new Map();
227
+ }
228
+ try {
229
+ while (flushIndex < jobsLength) {
230
+ const job = jobs[flushIndex];
231
+ jobs[flushIndex++] = undefined;
232
+ if (!(job.flags & SchedulerJobFlags.DISPOSED)) {
233
+ // Conditional usage of checkRecursiveUpdate must be determined out of
234
+ // try ... catch block since Rollup by default de-optimizes treeshaking
235
+ // inside try-catch. This can leave all warning code unshaked. Although
236
+ // they would get eventually shaken by a minifier like terser, some minifiers
237
+ // would fail to do that (e.g. https://github.com/evanw/esbuild/issues/1610)
238
+ /* istanbul ignore if -- @preserve */
239
+ if (true && checkRecursiveUpdates(seen, job)) {
240
+ continue;
241
+ }
242
+ job.flags &= ~SchedulerJobFlags.QUEUED;
243
+ job();
244
+ }
245
+ }
246
+ }
247
+ finally {
248
+ // If there was an error we still need to clear the QUEUED flags
249
+ while (flushIndex < jobsLength) {
250
+ jobs[flushIndex].flags &= ~SchedulerJobFlags.QUEUED;
251
+ jobs[flushIndex++] = undefined;
252
+ }
253
+ flushIndex = 0;
254
+ jobsLength = 0;
255
+ currentFlushPromise = null;
256
+ }
257
+ }
258
+ function checkRecursiveUpdates(seen, fn) {
259
+ const count = seen.get(fn) || 0;
260
+ /* istanbul ignore if -- @preserve */
261
+ if (count > RECURSION_LIMIT) {
262
+ console.warn(`Maximum recursive updates exceeded. ` +
263
+ `This usually means a state update is being triggered inside render(), ` +
264
+ `causing an infinite loop.`);
265
+ return true;
266
+ }
267
+ seen.set(fn, count + 1);
268
+ return false;
269
+ }
270
+
271
+ function useState(initialState) {
272
+ const getState = () => isFunction(initialState) ? initialState() : initialState;
273
+ const currentInstance = getCurrentInstanceAll();
274
+ if (currentInstance) {
275
+ const store = getHooksStore(currentInstance);
276
+ const index = store.cursor;
277
+ let stateSlot = store.slots[index];
278
+ if (!isHookKind(stateSlot, 'state')) {
279
+ const setState = (newState) => {
280
+ const prevState = stateSlot.value;
281
+ const nextState = isFunction(newState) ? newState(prevState) : newState;
282
+ if (Object.is(prevState, nextState)) {
283
+ return;
284
+ }
285
+ stateSlot.value = nextState;
286
+ queueJob(currentInstance.__render__);
287
+ };
288
+ stateSlot = { kind: 'state', value: getState(), setState };
289
+ store.slots[index] = stateSlot;
290
+ }
291
+ store.cursor += 1;
292
+ return [stateSlot.value, stateSlot.setState];
293
+ }
294
+ /* istanbul ignore else -- @preserve */
295
+ {
296
+ console.warn('useState() hook can only be called during execution of render().');
297
+ }
298
+ return [getState(), () => { }];
299
+ }
300
+
301
+ function useReducer(reducer, initialArg, init) {
302
+ const getState = () => init === undefined ? initialArg : init(initialArg);
303
+ const currentInstance = getCurrentInstanceAll();
304
+ if (currentInstance) {
305
+ const store = getHooksStore(currentInstance);
306
+ const index = store.cursor;
307
+ let stateSlot = store.slots[index];
308
+ if (!isHookKind(stateSlot, 'state')) {
309
+ const dispatch = (action) => {
310
+ const prevState = stateSlot.value;
311
+ const nextState = reducer(prevState, action);
312
+ if (Object.is(prevState, nextState)) {
313
+ return;
314
+ }
315
+ stateSlot.value = nextState;
316
+ queueJob(currentInstance.__render__);
317
+ };
318
+ stateSlot = {
319
+ kind: 'state',
320
+ value: getState(),
321
+ setState: dispatch,
322
+ };
323
+ store.slots[index] = stateSlot;
324
+ }
325
+ store.cursor += 1;
326
+ return [stateSlot.value, stateSlot.setState];
327
+ }
328
+ /* istanbul ignore else -- @preserve */
329
+ {
330
+ console.warn('useReducer() hook can only be called during execution of render().');
331
+ }
332
+ return [getState(), () => { }];
333
+ }
334
+
335
+ function memoImpl(currentInstance, factory, deps) {
336
+ const store = getHooksStore(currentInstance);
337
+ const index = store.cursor;
338
+ let memoSlot = store.slots[index];
339
+ if (!isHookKind(memoSlot, 'memo')) {
340
+ memoSlot = { kind: 'memo', value: factory(), deps };
341
+ store.slots[index] = memoSlot;
342
+ }
343
+ else if (!areHookDepsEqual(memoSlot.deps, deps)) {
344
+ memoSlot.value = factory();
345
+ memoSlot.deps = deps;
346
+ }
347
+ store.cursor += 1;
348
+ return memoSlot.value;
349
+ }
350
+ function useMemo(factory, deps) {
351
+ const currentInstance = getCurrentInstanceAll();
352
+ if (currentInstance) {
353
+ return memoImpl(currentInstance, factory, deps);
354
+ }
355
+ /* istanbul ignore else -- @preserve */
356
+ {
357
+ console.warn('useMemo() hook can only be called during execution of render().');
358
+ }
359
+ return factory();
360
+ }
361
+ function useCallback(callback, deps) {
362
+ const currentInstance = getCurrentInstanceAll();
363
+ if (currentInstance) {
364
+ return memoImpl(currentInstance, () => callback, deps);
365
+ }
366
+ /* istanbul ignore else -- @preserve */
367
+ {
368
+ console.warn('useCallback() hook can only be called during execution of render().');
369
+ }
370
+ return callback;
371
+ }
372
+
373
+ function useEffectEvent(callback) {
374
+ const currentInstance = getCurrentInstanceAll();
375
+ if (currentInstance) {
376
+ const store = getHooksStore(currentInstance);
377
+ const index = store.cursor;
378
+ let effectEventSlot = store.slots[index];
379
+ if (!isHookKind(effectEventSlot, 'effectEvent')) {
380
+ effectEventSlot = { kind: 'effectEvent', fn: callback };
381
+ store.slots[index] = effectEventSlot;
382
+ }
383
+ else {
384
+ effectEventSlot.fn = callback;
385
+ }
386
+ store.cursor += 1;
387
+ return ((...args) => effectEventSlot.fn(...args));
388
+ }
389
+ /* istanbul ignore else -- @preserve */
390
+ {
391
+ console.warn('useEffectEvent() hook can only be called during execution of render().');
392
+ }
393
+ return callback;
394
+ }
395
+
396
+ function effectImpl(currentInstance, queue, callback, deps) {
397
+ const store = getHooksStore(currentInstance);
398
+ const index = store.cursor;
399
+ let effectSlot = store.slots[index];
400
+ if (!isHookKind(effectSlot, 'effect')) {
401
+ effectSlot = { kind: 'effect', deps, cleanup: undefined };
402
+ store.slots[index] = effectSlot;
403
+ const job = () => {
404
+ effectSlot.job = undefined;
405
+ effectSlot.cleanup = callback();
406
+ };
407
+ effectSlot.job = job;
408
+ queue(job);
409
+ }
410
+ else if (!areHookDepsEqual(effectSlot.deps, deps)) {
411
+ effectSlot.deps = deps;
412
+ const job = () => {
413
+ effectSlot.job = undefined;
414
+ if (effectSlot.cleanup) {
415
+ effectSlot.cleanup();
416
+ }
417
+ effectSlot.cleanup = callback();
418
+ };
419
+ effectSlot.job = job;
420
+ queue(job);
421
+ }
422
+ store.cursor += 1;
423
+ }
424
+ function useEffect(callback, deps) {
425
+ const currentInstance = getCurrentInstanceAll();
426
+ if (currentInstance) {
427
+ effectImpl(currentInstance, queuePostFlushCb, callback, deps);
428
+ return;
429
+ }
430
+ /* istanbul ignore else -- @preserve */
431
+ {
432
+ console.warn('useEffect() hook can only be called during execution of render().');
433
+ }
434
+ }
435
+ function useRenderEffect(callback, deps) {
436
+ const currentInstance = getCurrentInstanceAll();
437
+ if (currentInstance) {
438
+ effectImpl(currentInstance, queueJob, callback, deps);
439
+ return;
440
+ }
441
+ /* istanbul ignore else -- @preserve */
442
+ {
443
+ console.warn('useRenderEffect() hook can only be called during execution of render().');
444
+ }
445
+ }
446
+
447
+ function createContext(defaultValue) {
448
+ return {
449
+ defaultValue,
450
+ currentValue: defaultValue,
451
+ subscribers: new Set(),
452
+ provider: null,
453
+ };
454
+ }
455
+ function notifyContextSubscribers(context) {
456
+ context.subscribers.forEach((job) => {
457
+ queueJob(job);
458
+ });
459
+ }
460
+ function useContext(context, value) {
461
+ const currentInstance = getCurrentInstanceAll();
462
+ if (currentInstance) {
463
+ const store = getHooksStore(currentInstance);
464
+ const index = store.cursor;
465
+ if (arguments.length >= 2) {
466
+ // Provider
467
+ if (!isHookKind(store.slots[index], 'context')) {
468
+ // It maybe invalid now, but become valid in a later render.
469
+ // So we need to reserve a slot for it and add cleanup logic.
470
+ store.slots[index] = {
471
+ kind: 'context',
472
+ cleanup: () => {
473
+ if (context.provider === currentInstance) {
474
+ context.provider = null;
475
+ if (!Object.is(context.currentValue, context.defaultValue)) {
476
+ context.currentValue = context.defaultValue;
477
+ notifyContextSubscribers(context);
478
+ }
479
+ }
480
+ },
481
+ };
482
+ }
483
+ if (context.provider !== null && context.provider !== currentInstance) {
484
+ /* istanbul ignore else -- @preserve */
485
+ {
486
+ console.warn('useContext() does not support multiple providers for the same context at the same time.');
487
+ }
488
+ store.cursor += 1;
489
+ return;
490
+ }
491
+ context.provider = currentInstance;
492
+ if (!Object.is(context.currentValue, value)) {
493
+ context.currentValue = value;
494
+ notifyContextSubscribers(context);
495
+ }
496
+ store.cursor += 1;
497
+ return;
498
+ }
499
+ // Consumer
500
+ const render = currentInstance.__render__;
501
+ if (!isHookKind(store.slots[index], 'context')) {
502
+ store.slots[index] = {
503
+ kind: 'context',
504
+ cleanup() {
505
+ context.subscribers.delete(render);
506
+ },
507
+ };
508
+ }
509
+ context.subscribers.add(render);
510
+ store.cursor += 1;
511
+ return context.currentValue;
512
+ }
513
+ /* istanbul ignore else -- @preserve */
514
+ {
515
+ console.warn('useContext() hook can only be called during execution of render().');
516
+ }
517
+ return context.currentValue;
518
+ }
519
+
520
+ var AppLifecycle;
521
+ (function (AppLifecycle) {
522
+ AppLifecycle["ON_LAUNCH"] = "onLaunch";
523
+ AppLifecycle["ON_SHOW"] = "onShow";
524
+ AppLifecycle["ON_HIDE"] = "onHide";
525
+ AppLifecycle["ON_ERROR"] = "onError";
526
+ AppLifecycle["ON_PAGE_NOT_FOUND"] = "onPageNotFound";
527
+ AppLifecycle["ON_UNHANDLED_REJECTION"] = "onUnhandledRejection";
528
+ AppLifecycle["ON_THEME_CHANGE"] = "onThemeChange";
529
+ })(AppLifecycle || (AppLifecycle = {}));
530
+ const appLifeHooks = [
531
+ AppLifecycle.ON_SHOW,
532
+ AppLifecycle.ON_HIDE,
533
+ AppLifecycle.ON_ERROR,
534
+ AppLifecycle.ON_PAGE_NOT_FOUND,
535
+ AppLifecycle.ON_UNHANDLED_REJECTION,
536
+ AppLifecycle.ON_THEME_CHANGE,
537
+ ];
538
+ function createApp(optionsOrRender) {
539
+ let render;
540
+ let options;
541
+ if (isFunction(optionsOrRender)) {
542
+ render = optionsOrRender;
543
+ options = {};
544
+ }
545
+ else {
546
+ if (optionsOrRender.render === undefined) {
547
+ App(optionsOrRender);
548
+ return;
549
+ }
550
+ render = optionsOrRender.render;
551
+ options = exclude(optionsOrRender, ['render']);
552
+ }
553
+ const originOnLaunch = options[AppLifecycle.ON_LAUNCH];
554
+ options[AppLifecycle.ON_LAUNCH] = function (options) {
555
+ this.__render__ = () => {
556
+ setCurrentApp(this);
557
+ resetHooksCursor(this);
558
+ resetLifecycleCursors(this, appLifeHooks);
559
+ try {
560
+ const bindings = render(options);
561
+ if (bindings !== undefined) {
562
+ Object.keys(bindings).forEach((key) => {
563
+ this[key] = bindings[key];
564
+ });
565
+ }
566
+ }
567
+ finally {
568
+ unsetCurrentApp();
569
+ }
570
+ trimHooksStore(this);
571
+ trimLifecycleBuckets(this, appLifeHooks);
572
+ };
573
+ this.__render__();
574
+ if (originOnLaunch !== undefined) {
575
+ originOnLaunch.call(this, options);
576
+ }
577
+ };
578
+ options[AppLifecycle.ON_SHOW] = createLifecycle$2(options, AppLifecycle.ON_SHOW);
579
+ options[AppLifecycle.ON_HIDE] = createLifecycle$2(options, AppLifecycle.ON_HIDE);
580
+ options[AppLifecycle.ON_ERROR] = createLifecycle$2(options, AppLifecycle.ON_ERROR);
581
+ options[AppLifecycle.ON_PAGE_NOT_FOUND] = createLifecycle$2(options, AppLifecycle.ON_PAGE_NOT_FOUND);
582
+ options[AppLifecycle.ON_UNHANDLED_REJECTION] = createLifecycle$2(options, AppLifecycle.ON_UNHANDLED_REJECTION);
583
+ options[AppLifecycle.ON_THEME_CHANGE] = createLifecycle$2(options, AppLifecycle.ON_THEME_CHANGE);
584
+ App(options);
585
+ }
586
+ function createLifecycle$2(options, lifecycle) {
587
+ const originLifecycle = options[lifecycle];
588
+ return function (...args) {
589
+ getLifecycleHooks(this, lifecycle).forEach((hook) => hook(...args));
590
+ if (originLifecycle !== undefined) {
591
+ originLifecycle.call(this, ...args);
592
+ }
593
+ };
594
+ }
595
+
596
+ var PageLifecycle;
597
+ (function (PageLifecycle) {
598
+ PageLifecycle["ON_LOAD"] = "onLoad";
599
+ PageLifecycle["ON_SHOW"] = "onShow";
600
+ PageLifecycle["ON_READY"] = "onReady";
601
+ PageLifecycle["ON_HIDE"] = "onHide";
602
+ PageLifecycle["ON_UNLOAD"] = "onUnload";
603
+ PageLifecycle["ON_ROUTE_DONE"] = "onRouteDone";
604
+ PageLifecycle["ON_PULL_DOWN_REFRESH"] = "onPullDownRefresh";
605
+ PageLifecycle["ON_REACH_BOTTOM"] = "onReachBottom";
606
+ PageLifecycle["ON_PAGE_SCROLL"] = "onPageScroll";
607
+ PageLifecycle["ON_SHARE_APP_MESSAGE"] = "onShareAppMessage";
608
+ PageLifecycle["ON_SHARE_TIMELINE"] = "onShareTimeline";
609
+ PageLifecycle["ON_ADD_TO_FAVORITES"] = "onAddToFavorites";
610
+ PageLifecycle["ON_RESIZE"] = "onResize";
611
+ PageLifecycle["ON_TAB_ITEM_TAP"] = "onTabItemTap";
612
+ PageLifecycle["ON_SAVE_EXIT_STATE"] = "onSaveExitState";
613
+ })(PageLifecycle || (PageLifecycle = {}));
614
+ const pageLifeHooks = [
615
+ PageLifecycle.ON_SHOW,
616
+ PageLifecycle.ON_HIDE,
617
+ PageLifecycle.ON_ROUTE_DONE,
618
+ PageLifecycle.ON_PULL_DOWN_REFRESH,
619
+ PageLifecycle.ON_REACH_BOTTOM,
620
+ PageLifecycle.ON_PAGE_SCROLL,
621
+ PageLifecycle.ON_SHARE_APP_MESSAGE,
622
+ PageLifecycle.ON_SHARE_TIMELINE,
623
+ PageLifecycle.ON_ADD_TO_FAVORITES,
624
+ PageLifecycle.ON_RESIZE,
625
+ PageLifecycle.ON_TAB_ITEM_TAP,
626
+ PageLifecycle.ON_SAVE_EXIT_STATE,
627
+ ];
628
+ function definePage(optionsOrRender, config) {
629
+ config = extend({
630
+ listenPageScroll: false,
631
+ canShareToOthers: false,
632
+ canShareToTimeline: false,
633
+ }, config);
634
+ let render;
635
+ let options;
636
+ if (isFunction(optionsOrRender)) {
637
+ render = optionsOrRender;
638
+ options = {};
639
+ }
640
+ else {
641
+ if (optionsOrRender.render === undefined) {
642
+ Page(optionsOrRender);
643
+ return;
644
+ }
645
+ render = optionsOrRender.render;
646
+ options = exclude(optionsOrRender, ['render']);
647
+ }
648
+ const originOnLoad = options[PageLifecycle.ON_LOAD];
649
+ options[PageLifecycle.ON_LOAD] = function (query) {
650
+ const context = {
651
+ is: this.is,
652
+ route: this.route,
653
+ options: this.options,
654
+ exitState: this.exitState,
655
+ router: this.router,
656
+ pageRouter: this.pageRouter,
657
+ renderer: this.renderer,
658
+ createSelectorQuery: this.createSelectorQuery.bind(this),
659
+ createIntersectionObserver: this.createIntersectionObserver.bind(this),
660
+ createMediaQueryObserver: this.createMediaQueryObserver.bind(this),
661
+ selectComponent: this.selectComponent.bind(this),
662
+ selectAllComponents: this.selectAllComponents.bind(this),
663
+ getTabBar: this.getTabBar.bind(this),
664
+ getPageId: this.getPageId.bind(this),
665
+ animate: this.animate.bind(this),
666
+ clearAnimation: this.clearAnimation.bind(this),
667
+ getOpenerEventChannel: this.getOpenerEventChannel.bind(this),
668
+ applyAnimatedStyle: this.applyAnimatedStyle.bind(this),
669
+ clearAnimatedStyle: this.clearAnimatedStyle.bind(this),
670
+ setUpdatePerformanceListener: this.setUpdatePerformanceListener.bind(this),
671
+ getPassiveEvent: this.getPassiveEvent.bind(this),
672
+ setPassiveEvent: this.setPassiveEvent.bind(this),
673
+ setInitialRenderingCache: this.setInitialRenderingCache.bind(this),
674
+ getAppBar: this.getAppBar && this.getAppBar.bind(this),
675
+ };
676
+ this.__render__ = () => {
677
+ setCurrentPage(this);
678
+ resetHooksCursor(this);
679
+ resetLifecycleCursors(this, pageLifeHooks);
680
+ try {
681
+ const bindings = render(query, context);
682
+ if (bindings !== undefined) {
683
+ let data;
684
+ Object.keys(bindings).forEach((key) => {
685
+ const value = bindings[key];
686
+ if (isFunction(value)) {
687
+ this[key] = value;
688
+ return;
689
+ }
690
+ if (!Object.prototype.hasOwnProperty.call(this.data, key) ||
691
+ !Object.is(this.data[key], value)) {
692
+ data = data || {};
693
+ data[key] = value;
694
+ }
695
+ });
696
+ if (data !== undefined) {
697
+ this.setData(data, flushPostFlushCbs);
698
+ }
699
+ }
700
+ }
701
+ finally {
702
+ unsetCurrentPage();
703
+ }
704
+ trimHooksStore(this);
705
+ trimLifecycleBuckets(this, pageLifeHooks);
706
+ };
707
+ this.__render__();
708
+ if (originOnLoad !== undefined) {
709
+ originOnLoad.call(this, query);
710
+ }
711
+ };
712
+ const originOnReady = options[PageLifecycle.ON_READY];
713
+ options[PageLifecycle.ON_READY] = function () {
714
+ flushPostFlushCbs();
715
+ if (originOnReady !== undefined) {
716
+ originOnReady.call(this);
717
+ }
718
+ };
719
+ const originOnUnload = options[PageLifecycle.ON_UNLOAD];
720
+ options[PageLifecycle.ON_UNLOAD] = function () {
721
+ const renderJob = this.__render__;
722
+ renderJob.flags |= SchedulerJobFlags.DISPOSED;
723
+ const store = getHooksStore(this);
724
+ store.slots.forEach((slot) => {
725
+ if (slot.kind === 'effect') {
726
+ if (slot.job) {
727
+ slot.job.flags |= SchedulerJobFlags.DISPOSED;
728
+ slot.job = undefined;
729
+ }
730
+ if (slot.cleanup) {
731
+ slot.cleanup();
732
+ }
733
+ }
734
+ else if (slot.kind === 'context') {
735
+ slot.cleanup();
736
+ }
737
+ });
738
+ if (originOnUnload !== undefined) {
739
+ originOnUnload.call(this);
740
+ }
741
+ };
742
+ if (options[PageLifecycle.ON_PAGE_SCROLL] || config.listenPageScroll) {
743
+ options[PageLifecycle.ON_PAGE_SCROLL] = createLifecycle$1(options, PageLifecycle.ON_PAGE_SCROLL);
744
+ /* istanbul ignore next -- @preserve */
745
+ options.__listenPageScroll__ = () => true;
746
+ }
747
+ if (options[PageLifecycle.ON_SHARE_APP_MESSAGE] === undefined &&
748
+ config.canShareToOthers) {
749
+ options[PageLifecycle.ON_SHARE_APP_MESSAGE] = createReturnLifecycle$1(PageLifecycle.ON_SHARE_APP_MESSAGE, () => ({}));
750
+ /* istanbul ignore next -- @preserve */
751
+ options.__isInjectedShareToOthersHook__ = () => true;
752
+ }
753
+ if (options[PageLifecycle.ON_SHARE_TIMELINE] === undefined &&
754
+ config.canShareToTimeline) {
755
+ options[PageLifecycle.ON_SHARE_TIMELINE] = createReturnLifecycle$1(PageLifecycle.ON_SHARE_TIMELINE, () => ({}));
756
+ /* istanbul ignore next -- @preserve */
757
+ options.__isInjectedShareToTimelineHook__ = () => true;
758
+ }
759
+ if (options[PageLifecycle.ON_ADD_TO_FAVORITES] === undefined) {
760
+ options[PageLifecycle.ON_ADD_TO_FAVORITES] = createReturnLifecycle$1(PageLifecycle.ON_ADD_TO_FAVORITES, () => ({}));
761
+ /* istanbul ignore next -- @preserve */
762
+ options.__isInjectedFavoritesHook__ = () => true;
763
+ }
764
+ if (options[PageLifecycle.ON_SAVE_EXIT_STATE] === undefined) {
765
+ options[PageLifecycle.ON_SAVE_EXIT_STATE] = createReturnLifecycle$1(PageLifecycle.ON_SAVE_EXIT_STATE, () => ({ data: undefined }));
766
+ /* istanbul ignore next -- @preserve */
767
+ options.__isInjectedExitStateHook__ = () => true;
768
+ }
769
+ options[PageLifecycle.ON_SHOW] = createLifecycle$1(options, PageLifecycle.ON_SHOW);
770
+ options[PageLifecycle.ON_HIDE] = createLifecycle$1(options, PageLifecycle.ON_HIDE);
771
+ options[PageLifecycle.ON_ROUTE_DONE] = createLifecycle$1(options, PageLifecycle.ON_ROUTE_DONE);
772
+ options[PageLifecycle.ON_PULL_DOWN_REFRESH] = createLifecycle$1(options, PageLifecycle.ON_PULL_DOWN_REFRESH);
773
+ options[PageLifecycle.ON_REACH_BOTTOM] = createLifecycle$1(options, PageLifecycle.ON_REACH_BOTTOM);
774
+ options[PageLifecycle.ON_RESIZE] = createLifecycle$1(options, PageLifecycle.ON_RESIZE);
775
+ options[PageLifecycle.ON_TAB_ITEM_TAP] = createLifecycle$1(options, PageLifecycle.ON_TAB_ITEM_TAP);
776
+ Page(options);
777
+ }
778
+ function createLifecycle$1(options, lifecycle) {
779
+ const originLifecycle = options[lifecycle];
780
+ return function (...args) {
781
+ getLifecycleHooks(this, lifecycle).forEach((hook) => hook(...args));
782
+ if (originLifecycle !== undefined) {
783
+ originLifecycle.call(this, ...args);
784
+ }
785
+ };
786
+ }
787
+ function createReturnLifecycle$1(lifecycle, getDefaultValue) {
788
+ return function (...args) {
789
+ const [hook] = getLifecycleHooks(this, lifecycle);
790
+ if (hook) {
791
+ return hook(...args);
792
+ }
793
+ return getDefaultValue();
794
+ };
795
+ }
796
+
797
+ var ComponentLifecycle;
798
+ (function (ComponentLifecycle) {
799
+ ComponentLifecycle["ATTACHED"] = "attached";
800
+ ComponentLifecycle["READY"] = "ready";
801
+ ComponentLifecycle["MOVED"] = "moved";
802
+ ComponentLifecycle["DETACHED"] = "detached";
803
+ ComponentLifecycle["ERROR"] = "error";
804
+ })(ComponentLifecycle || (ComponentLifecycle = {}));
805
+ const specialLifecycleMap = {
806
+ [PageLifecycle.ON_SHOW]: 'show',
807
+ [PageLifecycle.ON_HIDE]: 'hide',
808
+ [PageLifecycle.ON_RESIZE]: 'resize',
809
+ [PageLifecycle.ON_ROUTE_DONE]: 'routeDone',
810
+ };
811
+ const componentLifeHooks = [
812
+ ...pageLifeHooks,
813
+ ComponentLifecycle.MOVED,
814
+ ComponentLifecycle.ERROR,
815
+ ];
816
+ function defineComponent(optionsOrRender, config) {
817
+ config = extend({
818
+ listenPageScroll: false,
819
+ canShareToOthers: false,
820
+ canShareToTimeline: false,
821
+ }, config);
822
+ let render;
823
+ let options;
824
+ let properties = null;
825
+ if (isFunction(optionsOrRender)) {
826
+ render = optionsOrRender;
827
+ options = {};
828
+ }
829
+ else {
830
+ if (optionsOrRender.render === undefined) {
831
+ return Component(optionsOrRender);
832
+ }
833
+ render = optionsOrRender.render;
834
+ options = exclude(optionsOrRender, ['render']);
835
+ if (options.properties) {
836
+ properties = Object.keys(options.properties);
837
+ }
838
+ }
839
+ if (options.lifetimes === undefined) {
840
+ options.lifetimes = {};
841
+ }
842
+ const originAttached = options.lifetimes[ComponentLifecycle.ATTACHED] ||
843
+ options[ComponentLifecycle.ATTACHED];
844
+ options.lifetimes[ComponentLifecycle.ATTACHED] = function () {
845
+ this.__props__ = {};
846
+ if (properties) {
847
+ properties.forEach((property) => {
848
+ this.__props__[property] = this.data[property];
849
+ });
850
+ }
851
+ const context = {
852
+ is: this.is,
853
+ id: this.id,
854
+ dataset: this.dataset,
855
+ exitState: this.exitState,
856
+ router: this.router,
857
+ pageRouter: this.pageRouter,
858
+ renderer: this.renderer,
859
+ triggerEvent: this.triggerEvent.bind(this),
860
+ createSelectorQuery: this.createSelectorQuery.bind(this),
861
+ createIntersectionObserver: this.createIntersectionObserver.bind(this),
862
+ createMediaQueryObserver: this.createMediaQueryObserver.bind(this),
863
+ selectComponent: this.selectComponent.bind(this),
864
+ selectAllComponents: this.selectAllComponents.bind(this),
865
+ selectOwnerComponent: this.selectOwnerComponent.bind(this),
866
+ getRelationNodes: this.getRelationNodes.bind(this),
867
+ getTabBar: this.getTabBar.bind(this),
868
+ getPageId: this.getPageId.bind(this),
869
+ animate: this.animate.bind(this),
870
+ clearAnimation: this.clearAnimation.bind(this),
871
+ getOpenerEventChannel: this.getOpenerEventChannel.bind(this),
872
+ applyAnimatedStyle: this.applyAnimatedStyle.bind(this),
873
+ clearAnimatedStyle: this.clearAnimatedStyle.bind(this),
874
+ setUpdatePerformanceListener: this.setUpdatePerformanceListener.bind(this),
875
+ getPassiveEvent: this.getPassiveEvent.bind(this),
876
+ setPassiveEvent: this.setPassiveEvent.bind(this),
877
+ setInitialRenderingCache: this.setInitialRenderingCache.bind(this),
878
+ getAppBar: this.getAppBar && this.getAppBar.bind(this),
879
+ };
880
+ this.__render__ = () => {
881
+ setCurrentComponent(this);
882
+ resetHooksCursor(this);
883
+ resetLifecycleCursors(this, componentLifeHooks);
884
+ try {
885
+ const bindings = render(this.__props__, context);
886
+ if (bindings !== undefined) {
887
+ let data;
888
+ Object.keys(bindings).forEach((key) => {
889
+ const value = bindings[key];
890
+ if (isFunction(value)) {
891
+ this[key] = value;
892
+ return;
893
+ }
894
+ if (!Object.prototype.hasOwnProperty.call(this.data, key) ||
895
+ !Object.is(this.data[key], value)) {
896
+ data = data || {};
897
+ data[key] = value;
898
+ }
899
+ });
900
+ if (data !== undefined) {
901
+ this.setData(data, flushPostFlushCbs);
902
+ }
903
+ }
904
+ }
905
+ finally {
906
+ unsetCurrentComponent();
907
+ }
908
+ trimHooksStore(this);
909
+ trimLifecycleBuckets(this, componentLifeHooks);
910
+ };
911
+ this.__render__();
912
+ if (originAttached !== undefined) {
913
+ originAttached.call(this);
914
+ }
915
+ };
916
+ const originReady = options.lifetimes[ComponentLifecycle.READY] ||
917
+ options[ComponentLifecycle.READY];
918
+ options.lifetimes[ComponentLifecycle.READY] = function () {
919
+ flushPostFlushCbs();
920
+ if (originReady !== undefined) {
921
+ originReady.call(this);
922
+ }
923
+ };
924
+ const originDetached = options.lifetimes[ComponentLifecycle.DETACHED] ||
925
+ options[ComponentLifecycle.DETACHED];
926
+ options.lifetimes[ComponentLifecycle.DETACHED] = function () {
927
+ const renderJob = this.__render__;
928
+ renderJob.flags |= SchedulerJobFlags.DISPOSED;
929
+ const store = getHooksStore(this);
930
+ store.slots.forEach((slot) => {
931
+ if (slot.kind === 'effect') {
932
+ if (slot.job) {
933
+ slot.job.flags |= SchedulerJobFlags.DISPOSED;
934
+ slot.job = undefined;
935
+ }
936
+ if (slot.cleanup) {
937
+ slot.cleanup();
938
+ }
939
+ }
940
+ else if (slot.kind === 'context') {
941
+ slot.cleanup();
942
+ }
943
+ });
944
+ if (originDetached !== undefined) {
945
+ originDetached.call(this);
946
+ }
947
+ };
948
+ options.lifetimes[ComponentLifecycle.MOVED] = createComponentLifecycle(options, ComponentLifecycle.MOVED);
949
+ options.lifetimes[ComponentLifecycle.ERROR] = createComponentLifecycle(options, ComponentLifecycle.ERROR);
950
+ if (options.methods === undefined) {
951
+ options.methods = {};
952
+ }
953
+ if (options.methods[PageLifecycle.ON_PAGE_SCROLL] ||
954
+ config.listenPageScroll) {
955
+ options.methods[PageLifecycle.ON_PAGE_SCROLL] = createPageLifecycle(options, PageLifecycle.ON_PAGE_SCROLL);
956
+ /* istanbul ignore next -- @preserve */
957
+ options.methods.__listenPageScroll__ = () => true;
958
+ }
959
+ if (options.methods[PageLifecycle.ON_SHARE_APP_MESSAGE] === undefined &&
960
+ config.canShareToOthers) {
961
+ options.methods[PageLifecycle.ON_SHARE_APP_MESSAGE] = createReturnLifecycle(PageLifecycle.ON_SHARE_APP_MESSAGE, () => ({}));
962
+ /* istanbul ignore next -- @preserve */
963
+ options.methods.__isInjectedShareToOthersHook__ = () => true;
964
+ }
965
+ if (options.methods[PageLifecycle.ON_SHARE_TIMELINE] === undefined &&
966
+ config.canShareToTimeline) {
967
+ options.methods[PageLifecycle.ON_SHARE_TIMELINE] = createReturnLifecycle(PageLifecycle.ON_SHARE_TIMELINE, () => ({}));
968
+ /* istanbul ignore next -- @preserve */
969
+ options.methods.__isInjectedShareToTimelineHook__ = () => true;
970
+ }
971
+ if (options.methods[PageLifecycle.ON_ADD_TO_FAVORITES] === undefined) {
972
+ options.methods[PageLifecycle.ON_ADD_TO_FAVORITES] = createReturnLifecycle(PageLifecycle.ON_ADD_TO_FAVORITES, () => ({}));
973
+ /* istanbul ignore next -- @preserve */
974
+ options.methods.__isInjectedFavoritesHook__ = () => true;
975
+ }
976
+ if (options.methods[PageLifecycle.ON_SAVE_EXIT_STATE] === undefined) {
977
+ options.methods[PageLifecycle.ON_SAVE_EXIT_STATE] = createReturnLifecycle(PageLifecycle.ON_SAVE_EXIT_STATE, () => ({ data: undefined }));
978
+ /* istanbul ignore next -- @preserve */
979
+ options.methods.__isInjectedExitStateHook__ = () => true;
980
+ }
981
+ options.methods[PageLifecycle.ON_PULL_DOWN_REFRESH] = createPageLifecycle(options, PageLifecycle.ON_PULL_DOWN_REFRESH);
982
+ options.methods[PageLifecycle.ON_REACH_BOTTOM] = createPageLifecycle(options, PageLifecycle.ON_REACH_BOTTOM);
983
+ options.methods[PageLifecycle.ON_TAB_ITEM_TAP] = createPageLifecycle(options, PageLifecycle.ON_TAB_ITEM_TAP);
984
+ if (options.pageLifetimes === undefined) {
985
+ options.pageLifetimes = {};
986
+ }
987
+ options.pageLifetimes[specialLifecycleMap[PageLifecycle.ON_SHOW]] =
988
+ createSpecialPageLifecycle(options, PageLifecycle.ON_SHOW);
989
+ options.pageLifetimes[specialLifecycleMap[PageLifecycle.ON_HIDE]] =
990
+ createSpecialPageLifecycle(options, PageLifecycle.ON_HIDE);
991
+ options.pageLifetimes[specialLifecycleMap[PageLifecycle.ON_RESIZE]] =
992
+ createSpecialPageLifecycle(options, PageLifecycle.ON_RESIZE);
993
+ options.pageLifetimes[specialLifecycleMap[PageLifecycle.ON_ROUTE_DONE]] =
994
+ createSpecialPageLifecycle(options, PageLifecycle.ON_ROUTE_DONE);
995
+ if (properties) {
996
+ if (options.observers === undefined) {
997
+ options.observers = {};
998
+ }
999
+ properties.forEach((property) => {
1000
+ const originObserver = options.observers[property];
1001
+ options.observers[property] = function (value) {
1002
+ // Observer executes before attached
1003
+ if (this.__props__) {
1004
+ this.__props__ = extend({}, this.__props__, { [property]: value });
1005
+ }
1006
+ // Observer executes before attached
1007
+ if (this.__render__) {
1008
+ queueJob(this.__render__);
1009
+ }
1010
+ if (originObserver !== undefined) {
1011
+ originObserver.call(this, value);
1012
+ }
1013
+ };
1014
+ });
1015
+ }
1016
+ return Component(options);
1017
+ }
1018
+ function createComponentLifecycle(options, lifecycle) {
1019
+ const originLifecycle = options.lifetimes[lifecycle] || options[lifecycle];
1020
+ return createLifecycle(lifecycle, originLifecycle);
1021
+ }
1022
+ function createPageLifecycle(options, lifecycle) {
1023
+ const originLifecycle = options.methods[lifecycle];
1024
+ return createLifecycle(lifecycle, originLifecycle);
1025
+ }
1026
+ function createSpecialPageLifecycle(options, lifecycle) {
1027
+ const originLifecycle = options.pageLifetimes[specialLifecycleMap[lifecycle]];
1028
+ return createLifecycle(lifecycle, originLifecycle);
1029
+ }
1030
+ function createLifecycle(lifecycle, originLifecycle) {
1031
+ return function (...args) {
1032
+ getLifecycleHooks(this, lifecycle).forEach((hook) => hook(...args));
1033
+ if (originLifecycle !== undefined) {
1034
+ originLifecycle.call(this, ...args);
1035
+ }
1036
+ };
1037
+ }
1038
+ function createReturnLifecycle(lifecycle, getDefaultValue) {
1039
+ return function (...args) {
1040
+ const [hook] = getLifecycleHooks(this, lifecycle);
1041
+ if (hook) {
1042
+ return hook(...args);
1043
+ }
1044
+ return getDefaultValue();
1045
+ };
1046
+ }
1047
+
1048
+ const pageHookWarn = 'Page specific lifecycle hooks can only be used during execution of render() in definePage() or defineComponent().';
1049
+ const useAppShow = createAppHook(AppLifecycle.ON_SHOW);
1050
+ const useAppHide = createAppHook(AppLifecycle.ON_HIDE);
1051
+ const useAppError = createAppHook(AppLifecycle.ON_ERROR);
1052
+ const usePageNotFound = createAppHook(AppLifecycle.ON_PAGE_NOT_FOUND);
1053
+ const useUnhandledRejection = createAppHook(AppLifecycle.ON_UNHANDLED_REJECTION);
1054
+ const useThemeChange = createAppHook(AppLifecycle.ON_THEME_CHANGE);
1055
+ const useShow = createPageHook(PageLifecycle.ON_SHOW);
1056
+ const useHide = createPageHook(PageLifecycle.ON_HIDE);
1057
+ const useRouteDone = createPageHook(PageLifecycle.ON_ROUTE_DONE);
1058
+ const usePullDownRefresh = createPageHook(PageLifecycle.ON_PULL_DOWN_REFRESH);
1059
+ const useReachBottom = createPageHook(PageLifecycle.ON_REACH_BOTTOM);
1060
+ const useResize = createPageHook(PageLifecycle.ON_RESIZE);
1061
+ const useTabItemTap = createPageHook(PageLifecycle.ON_TAB_ITEM_TAP);
1062
+ const usePageScroll = (hook) => {
1063
+ const currentInstance = getCurrentInstance();
1064
+ /* istanbul ignore else -- @preserve */
1065
+ if (currentInstance) {
1066
+ /* istanbul ignore else -- @preserve */
1067
+ if (currentInstance.__listenPageScroll__) {
1068
+ registerLifecycleHook(currentInstance, PageLifecycle.ON_PAGE_SCROLL, hook);
1069
+ }
1070
+ else {
1071
+ console.warn('usePageScroll() hook only works when `listenPageScroll` is configured to true.');
1072
+ }
1073
+ }
1074
+ else {
1075
+ console.warn(pageHookWarn);
1076
+ }
1077
+ };
1078
+ const useShareAppMessage = (hook) => {
1079
+ const currentInstance = getCurrentInstance();
1080
+ /* istanbul ignore else -- @preserve */
1081
+ if (currentInstance) {
1082
+ /* istanbul ignore else -- @preserve */
1083
+ if (currentInstance.__isInjectedShareToOthersHook__) {
1084
+ const cursor = getLifecycleCursor(currentInstance, PageLifecycle.ON_SHARE_APP_MESSAGE);
1085
+ /* istanbul ignore else -- @preserve */
1086
+ if (cursor === 0) {
1087
+ registerLifecycleHook(currentInstance, PageLifecycle.ON_SHARE_APP_MESSAGE, hook);
1088
+ }
1089
+ else {
1090
+ console.warn('useShareAppMessage() hook can only be called once.');
1091
+ }
1092
+ }
1093
+ else {
1094
+ console.warn('useShareAppMessage() hook only works when `onShareAppMessage` option does not exist and `canShareToOthers` is configured to true.');
1095
+ }
1096
+ }
1097
+ else {
1098
+ console.warn(pageHookWarn);
1099
+ }
1100
+ };
1101
+ const useShareTimeline = (hook) => {
1102
+ const currentInstance = getCurrentInstance();
1103
+ /* istanbul ignore else -- @preserve */
1104
+ if (currentInstance) {
1105
+ /* istanbul ignore else -- @preserve */
1106
+ if (currentInstance.__isInjectedShareToTimelineHook__) {
1107
+ const cursor = getLifecycleCursor(currentInstance, PageLifecycle.ON_SHARE_TIMELINE);
1108
+ /* istanbul ignore else -- @preserve */
1109
+ if (cursor === 0) {
1110
+ registerLifecycleHook(currentInstance, PageLifecycle.ON_SHARE_TIMELINE, hook);
1111
+ }
1112
+ else {
1113
+ console.warn('useShareTimeline() hook can only be called once.');
1114
+ }
1115
+ }
1116
+ else {
1117
+ console.warn('useShareTimeline() hook only works when `onShareTimeline` option does not exist and `canShareToTimeline` is configured to true.');
1118
+ }
1119
+ }
1120
+ else {
1121
+ console.warn(pageHookWarn);
1122
+ }
1123
+ };
1124
+ const useAddToFavorites = (hook) => {
1125
+ const currentInstance = getCurrentInstance();
1126
+ /* istanbul ignore else -- @preserve */
1127
+ if (currentInstance) {
1128
+ /* istanbul ignore else -- @preserve */
1129
+ if (currentInstance.__isInjectedFavoritesHook__) {
1130
+ const cursor = getLifecycleCursor(currentInstance, PageLifecycle.ON_ADD_TO_FAVORITES);
1131
+ /* istanbul ignore else -- @preserve */
1132
+ if (cursor === 0) {
1133
+ registerLifecycleHook(currentInstance, PageLifecycle.ON_ADD_TO_FAVORITES, hook);
1134
+ }
1135
+ else {
1136
+ console.warn('useAddToFavorites() hook can only be called once.');
1137
+ }
1138
+ }
1139
+ else {
1140
+ console.warn('useAddToFavorites() hook only works when `onAddToFavorites` option does not exist.');
1141
+ }
1142
+ }
1143
+ else {
1144
+ console.warn(pageHookWarn);
1145
+ }
1146
+ };
1147
+ const useSaveExitState = (hook) => {
1148
+ const currentInstance = getCurrentInstance();
1149
+ /* istanbul ignore else -- @preserve */
1150
+ if (currentInstance) {
1151
+ /* istanbul ignore else -- @preserve */
1152
+ if (currentInstance.__isInjectedExitStateHook__) {
1153
+ const cursor = getLifecycleCursor(currentInstance, PageLifecycle.ON_SAVE_EXIT_STATE);
1154
+ /* istanbul ignore else -- @preserve */
1155
+ if (cursor === 0) {
1156
+ registerLifecycleHook(currentInstance, PageLifecycle.ON_SAVE_EXIT_STATE, hook);
1157
+ }
1158
+ else {
1159
+ console.warn('useSaveExitState() hook can only be called once.');
1160
+ }
1161
+ }
1162
+ else {
1163
+ console.warn('useSaveExitState() hook only works when `onSaveExitState` option does not exist.');
1164
+ }
1165
+ }
1166
+ else {
1167
+ console.warn(pageHookWarn);
1168
+ }
1169
+ };
1170
+ const useMove = createComponentHook(ComponentLifecycle.MOVED);
1171
+ const useError = createComponentHook(ComponentLifecycle.ERROR);
1172
+ function createAppHook(lifecycle) {
1173
+ return (hook) => {
1174
+ /* istanbul ignore else -- @preserve */
1175
+ if (currentApp) {
1176
+ registerLifecycleHook(currentApp, lifecycle, hook);
1177
+ }
1178
+ else {
1179
+ console.warn('App specific lifecycle hooks can only be used during execution of render() in createApp().');
1180
+ }
1181
+ };
1182
+ }
1183
+ function createPageHook(lifecycle) {
1184
+ return (hook) => {
1185
+ const currentInstance = getCurrentInstance();
1186
+ /* istanbul ignore else -- @preserve */
1187
+ if (currentInstance) {
1188
+ registerLifecycleHook(currentInstance, lifecycle, hook);
1189
+ }
1190
+ else {
1191
+ console.warn(pageHookWarn);
1192
+ }
1193
+ };
1194
+ }
1195
+ function createComponentHook(lifecycle) {
1196
+ return (hook) => {
1197
+ /* istanbul ignore else -- @preserve */
1198
+ if (currentComponent) {
1199
+ registerLifecycleHook(currentComponent, lifecycle, hook);
1200
+ }
1201
+ else {
1202
+ console.warn('Component specific lifecycle hooks can only be used during execution of render() in defineComponent().');
1203
+ }
1204
+ };
1205
+ }
1206
+
1207
+ exports.createApp = createApp;
1208
+ exports.createContext = createContext;
1209
+ exports.defineComponent = defineComponent;
1210
+ exports.definePage = definePage;
1211
+ exports.nextTick = nextTick;
1212
+ exports.useAddToFavorites = useAddToFavorites;
1213
+ exports.useAppError = useAppError;
1214
+ exports.useAppHide = useAppHide;
1215
+ exports.useAppShow = useAppShow;
1216
+ exports.useCallback = useCallback;
1217
+ exports.useContext = useContext;
1218
+ exports.useEffect = useEffect;
1219
+ exports.useEffectEvent = useEffectEvent;
1220
+ exports.useError = useError;
1221
+ exports.useHide = useHide;
1222
+ exports.useMemo = useMemo;
1223
+ exports.useMove = useMove;
1224
+ exports.usePageNotFound = usePageNotFound;
1225
+ exports.usePageScroll = usePageScroll;
1226
+ exports.usePullDownRefresh = usePullDownRefresh;
1227
+ exports.useReachBottom = useReachBottom;
1228
+ exports.useReducer = useReducer;
1229
+ exports.useRef = useRef;
1230
+ exports.useRenderEffect = useRenderEffect;
1231
+ exports.useResize = useResize;
1232
+ exports.useRouteDone = useRouteDone;
1233
+ exports.useSaveExitState = useSaveExitState;
1234
+ exports.useShareAppMessage = useShareAppMessage;
1235
+ exports.useShareTimeline = useShareTimeline;
1236
+ exports.useShow = useShow;
1237
+ exports.useState = useState;
1238
+ exports.useTabItemTap = useTabItemTap;
1239
+ exports.useThemeChange = useThemeChange;
1240
+ exports.useUnhandledRejection = useUnhandledRejection;