@dcloudio/uni-app-harmony 3.0.0-4010420240430001

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,1269 @@
1
+ import picker from '@ohos.file.picker';
2
+ import fs from '@ohos.file.fs';
3
+ import promptAction from '@ohos.promptAction';
4
+ import { getCurrentInstance, onMounted, nextTick, onBeforeUnmount } from 'vue';
5
+
6
+ /**
7
+ * @vue/shared v3.4.21
8
+ * (c) 2018-present Yuxi (Evan) You and Vue contributors
9
+ * @license MIT
10
+ **/
11
+ function makeMap(str, expectsLowerCase) {
12
+ const set = new Set(str.split(","));
13
+ return expectsLowerCase ? (val) => set.has(val.toLowerCase()) : (val) => set.has(val);
14
+ }
15
+ const extend = Object.assign;
16
+ const hasOwnProperty$1 = Object.prototype.hasOwnProperty;
17
+ const hasOwn$1 = (val, key) => hasOwnProperty$1.call(val, key);
18
+ const isArray = Array.isArray;
19
+ const isFunction = (val) => typeof val === "function";
20
+ const isString = (val) => typeof val === "string";
21
+ const isObject$1 = (val) => val !== null && typeof val === "object";
22
+ const isPromise = (val) => {
23
+ return (isObject$1(val) || isFunction(val)) && isFunction(val.then) && isFunction(val.catch);
24
+ };
25
+ const objectToString = Object.prototype.toString;
26
+ const toTypeString = (value) => objectToString.call(value);
27
+ const toRawType = (value) => {
28
+ return toTypeString(value).slice(8, -1);
29
+ };
30
+ const isPlainObject = (val) => toTypeString(val) === "[object Object]";
31
+ const cacheStringFunction = (fn) => {
32
+ const cache = /* @__PURE__ */ Object.create(null);
33
+ return (str) => {
34
+ const hit = cache[str];
35
+ return hit || (cache[str] = fn(str));
36
+ };
37
+ };
38
+ const capitalize = cacheStringFunction((str) => {
39
+ return str.charAt(0).toUpperCase() + str.slice(1);
40
+ });
41
+
42
+ const LINEFEED = '\n';
43
+ const ON_READY = 'onReady';
44
+ const ON_UNLOAD = 'onUnload';
45
+
46
+ let lastLogTime = 0;
47
+ function formatLog(module, ...args) {
48
+ const now = Date.now();
49
+ const diff = lastLogTime ? now - lastLogTime : 0;
50
+ lastLogTime = now;
51
+ return `[${now}][${diff}ms][${module}]:${args
52
+ .map((arg) => JSON.stringify(arg))
53
+ .join(' ')}`;
54
+ }
55
+
56
+ const invokeArrayFns = (fns, arg) => {
57
+ let ret;
58
+ for (let i = 0; i < fns.length; i++) {
59
+ ret = fns[i](arg);
60
+ }
61
+ return ret;
62
+ };
63
+ function once(fn, ctx = null) {
64
+ let res;
65
+ return ((...args) => {
66
+ if (fn) {
67
+ res = fn.apply(ctx, args);
68
+ fn = null;
69
+ }
70
+ return res;
71
+ });
72
+ }
73
+
74
+ class EventChannel {
75
+ id;
76
+ listener;
77
+ emitCache;
78
+ constructor(id, events) {
79
+ this.id = id;
80
+ this.listener = {};
81
+ this.emitCache = [];
82
+ if (events) {
83
+ Object.keys(events).forEach((name) => {
84
+ this.on(name, events[name]);
85
+ });
86
+ }
87
+ }
88
+ emit(eventName, ...args) {
89
+ const fns = this.listener[eventName];
90
+ if (!fns) {
91
+ return this.emitCache.push({
92
+ eventName,
93
+ args,
94
+ });
95
+ }
96
+ fns.forEach((opt) => {
97
+ opt.fn.apply(opt.fn, args);
98
+ });
99
+ this.listener[eventName] = fns.filter((opt) => opt.type !== 'once');
100
+ }
101
+ on(eventName, fn) {
102
+ this._addListener(eventName, 'on', fn);
103
+ this._clearCache(eventName);
104
+ }
105
+ once(eventName, fn) {
106
+ this._addListener(eventName, 'once', fn);
107
+ this._clearCache(eventName);
108
+ }
109
+ off(eventName, fn) {
110
+ const fns = this.listener[eventName];
111
+ if (!fns) {
112
+ return;
113
+ }
114
+ if (fn) {
115
+ for (let i = 0; i < fns.length;) {
116
+ if (fns[i].fn === fn) {
117
+ fns.splice(i, 1);
118
+ i--;
119
+ }
120
+ i++;
121
+ }
122
+ }
123
+ else {
124
+ delete this.listener[eventName];
125
+ }
126
+ }
127
+ _clearCache(eventName) {
128
+ for (let index = 0; index < this.emitCache.length; index++) {
129
+ const cache = this.emitCache[index];
130
+ const _name = eventName
131
+ ? cache.eventName === eventName
132
+ ? eventName
133
+ : null
134
+ : cache.eventName;
135
+ if (!_name)
136
+ continue;
137
+ const location = this.emit.apply(this, [_name, ...cache.args]);
138
+ if (typeof location === 'number') {
139
+ this.emitCache.pop();
140
+ continue;
141
+ }
142
+ this.emitCache.splice(index, 1);
143
+ index--;
144
+ }
145
+ }
146
+ _addListener(eventName, type, fn) {
147
+ (this.listener[eventName] || (this.listener[eventName] = [])).push({
148
+ fn,
149
+ type,
150
+ });
151
+ }
152
+ }
153
+
154
+ const CHOOSE_SIZE_TYPES = ['original', 'compressed'];
155
+ const CHOOSE_SOURCE_TYPES = ['album', 'camera'];
156
+ function elemsInArray(strArr, optionalVal) {
157
+ if (!isArray(strArr) ||
158
+ strArr.length === 0 ||
159
+ strArr.find((val) => optionalVal.indexOf(val) === -1)) {
160
+ return optionalVal;
161
+ }
162
+ return strArr;
163
+ }
164
+ function validateProtocolFail(name, msg) {
165
+ console.warn(`${name}: ${msg}`);
166
+ }
167
+ function validateProtocol(name, data, protocol, onFail) {
168
+ if (!onFail) {
169
+ onFail = validateProtocolFail;
170
+ }
171
+ for (const key in protocol) {
172
+ const errMsg = validateProp(key, data[key], protocol[key], !hasOwn$1(data, key));
173
+ if (isString(errMsg)) {
174
+ onFail(name, errMsg);
175
+ }
176
+ }
177
+ }
178
+ function validateProtocols(name, args, protocol, onFail) {
179
+ if (!protocol) {
180
+ return;
181
+ }
182
+ if (!isArray(protocol)) {
183
+ return validateProtocol(name, args[0] || Object.create(null), protocol, onFail);
184
+ }
185
+ const len = protocol.length;
186
+ const argsLen = args.length;
187
+ for (let i = 0; i < len; i++) {
188
+ const opts = protocol[i];
189
+ const data = Object.create(null);
190
+ if (argsLen > i) {
191
+ data[opts.name] = args[i];
192
+ }
193
+ validateProtocol(name, data, { [opts.name]: opts }, onFail);
194
+ }
195
+ }
196
+ function validateProp(name, value, prop, isAbsent) {
197
+ if (!isPlainObject(prop)) {
198
+ prop = { type: prop };
199
+ }
200
+ const { type, required, validator } = prop;
201
+ // required!
202
+ if (required && isAbsent) {
203
+ return 'Missing required args: "' + name + '"';
204
+ }
205
+ // missing but optional
206
+ if (value == null && !required) {
207
+ return;
208
+ }
209
+ // type check
210
+ if (type != null) {
211
+ let isValid = false;
212
+ const types = isArray(type) ? type : [type];
213
+ const expectedTypes = [];
214
+ // value is valid as long as one of the specified types match
215
+ for (let i = 0; i < types.length && !isValid; i++) {
216
+ const { valid, expectedType } = assertType(value, types[i]);
217
+ expectedTypes.push(expectedType || '');
218
+ isValid = valid;
219
+ }
220
+ if (!isValid) {
221
+ return getInvalidTypeMessage(name, value, expectedTypes);
222
+ }
223
+ }
224
+ // custom validator
225
+ if (validator) {
226
+ return validator(value);
227
+ }
228
+ }
229
+ const isSimpleType = /*#__PURE__*/ makeMap('String,Number,Boolean,Function,Symbol');
230
+ function assertType(value, type) {
231
+ let valid;
232
+ const expectedType = getType(type);
233
+ if (isSimpleType(expectedType)) {
234
+ const t = typeof value;
235
+ valid = t === expectedType.toLowerCase();
236
+ // for primitive wrapper objects
237
+ if (!valid && t === 'object') {
238
+ valid = value instanceof type;
239
+ }
240
+ }
241
+ else if (expectedType === 'Object') {
242
+ valid = isObject$1(value);
243
+ }
244
+ else if (expectedType === 'Array') {
245
+ valid = isArray(value);
246
+ }
247
+ else {
248
+ {
249
+ valid = value instanceof type;
250
+ }
251
+ }
252
+ return {
253
+ valid,
254
+ expectedType,
255
+ };
256
+ }
257
+ function getInvalidTypeMessage(name, value, expectedTypes) {
258
+ let message = `Invalid args: type check failed for args "${name}".` +
259
+ ` Expected ${expectedTypes.map(capitalize).join(', ')}`;
260
+ const expectedType = expectedTypes[0];
261
+ const receivedType = toRawType(value);
262
+ const expectedValue = styleValue(value, expectedType);
263
+ const receivedValue = styleValue(value, receivedType);
264
+ // check if we need to specify expected value
265
+ if (expectedTypes.length === 1 &&
266
+ isExplicable(expectedType) &&
267
+ !isBoolean(expectedType, receivedType)) {
268
+ message += ` with value ${expectedValue}`;
269
+ }
270
+ message += `, got ${receivedType} `;
271
+ // check if we need to specify received value
272
+ if (isExplicable(receivedType)) {
273
+ message += `with value ${receivedValue}.`;
274
+ }
275
+ return message;
276
+ }
277
+ function getType(ctor) {
278
+ const match = ctor && ctor.toString().match(/^\s*function (\w+)/);
279
+ return match ? match[1] : '';
280
+ }
281
+ function styleValue(value, type) {
282
+ if (type === 'String') {
283
+ return `"${value}"`;
284
+ }
285
+ else if (type === 'Number') {
286
+ return `${Number(value)}`;
287
+ }
288
+ else {
289
+ return `${value}`;
290
+ }
291
+ }
292
+ function isExplicable(type) {
293
+ const explicitTypes = ['string', 'number', 'boolean'];
294
+ return explicitTypes.some((elem) => type.toLowerCase() === elem);
295
+ }
296
+ function isBoolean(...args) {
297
+ return args.some((elem) => elem.toLowerCase() === 'boolean');
298
+ }
299
+
300
+ function tryCatch(fn) {
301
+ return function () {
302
+ try {
303
+ return fn.apply(fn, arguments);
304
+ }
305
+ catch (e) {
306
+ // TODO
307
+ console.error(e);
308
+ }
309
+ };
310
+ }
311
+
312
+ let invokeCallbackId = 1;
313
+ const invokeCallbacks = {};
314
+ function addInvokeCallback(id, name, callback, keepAlive = false) {
315
+ invokeCallbacks[id] = {
316
+ name,
317
+ keepAlive,
318
+ callback,
319
+ };
320
+ return id;
321
+ }
322
+ // onNativeEventReceive((event,data)=>{}) 需要两个参数,目前写死最多两个参数
323
+ function invokeCallback(id, res, extras) {
324
+ if (typeof id === 'number') {
325
+ const opts = invokeCallbacks[id];
326
+ if (opts) {
327
+ if (!opts.keepAlive) {
328
+ delete invokeCallbacks[id];
329
+ }
330
+ return opts.callback(res, extras);
331
+ }
332
+ }
333
+ return res;
334
+ }
335
+ const API_SUCCESS = 'success';
336
+ const API_FAIL = 'fail';
337
+ const API_COMPLETE = 'complete';
338
+ function getApiCallbacks(args) {
339
+ const apiCallbacks = {};
340
+ for (const name in args) {
341
+ const fn = args[name];
342
+ if (isFunction(fn)) {
343
+ apiCallbacks[name] = tryCatch(fn);
344
+ delete args[name];
345
+ }
346
+ }
347
+ return apiCallbacks;
348
+ }
349
+ function normalizeErrMsg$1(errMsg, name) {
350
+ if (!errMsg || errMsg.indexOf(':fail') === -1) {
351
+ return name + ':ok';
352
+ }
353
+ return name + errMsg.substring(errMsg.indexOf(':fail'));
354
+ }
355
+ function createAsyncApiCallback(name, args = {}, { beforeAll, beforeSuccess } = {}) {
356
+ if (!isPlainObject(args)) {
357
+ args = {};
358
+ }
359
+ const { success, fail, complete } = getApiCallbacks(args);
360
+ const hasSuccess = isFunction(success);
361
+ const hasFail = isFunction(fail);
362
+ const hasComplete = isFunction(complete);
363
+ const callbackId = invokeCallbackId++;
364
+ addInvokeCallback(callbackId, name, (res) => {
365
+ res = res || {};
366
+ res.errMsg = normalizeErrMsg$1(res.errMsg, name);
367
+ isFunction(beforeAll) && beforeAll(res);
368
+ if (res.errMsg === name + ':ok') {
369
+ isFunction(beforeSuccess) && beforeSuccess(res, args);
370
+ hasSuccess && success(res);
371
+ }
372
+ else {
373
+ hasFail && fail(res);
374
+ }
375
+ hasComplete && complete(res);
376
+ });
377
+ return callbackId;
378
+ }
379
+
380
+ const HOOK_SUCCESS = 'success';
381
+ const HOOK_FAIL = 'fail';
382
+ const HOOK_COMPLETE = 'complete';
383
+ const globalInterceptors = {};
384
+ const scopedInterceptors = {};
385
+ function wrapperHook(hook, params) {
386
+ return function (data) {
387
+ return hook(data, params) || data;
388
+ };
389
+ }
390
+ function queue(hooks, data, params) {
391
+ let promise = false;
392
+ for (let i = 0; i < hooks.length; i++) {
393
+ const hook = hooks[i];
394
+ if (promise) {
395
+ promise = Promise.resolve(wrapperHook(hook, params));
396
+ }
397
+ else {
398
+ const res = hook(data, params);
399
+ if (isPromise(res)) {
400
+ promise = Promise.resolve(res);
401
+ }
402
+ if (res === false) {
403
+ return {
404
+ then() { },
405
+ catch() { },
406
+ };
407
+ }
408
+ }
409
+ }
410
+ return (promise || {
411
+ then(callback) {
412
+ return callback(data);
413
+ },
414
+ catch() { },
415
+ });
416
+ }
417
+ function wrapperOptions(interceptors, options = {}) {
418
+ [HOOK_SUCCESS, HOOK_FAIL, HOOK_COMPLETE].forEach((name) => {
419
+ const hooks = interceptors[name];
420
+ if (!isArray(hooks)) {
421
+ return;
422
+ }
423
+ const oldCallback = options[name];
424
+ options[name] = function callbackInterceptor(res) {
425
+ queue(hooks, res, options).then((res) => {
426
+ return (isFunction(oldCallback) && oldCallback(res)) || res;
427
+ });
428
+ };
429
+ });
430
+ return options;
431
+ }
432
+ function wrapperReturnValue(method, returnValue) {
433
+ const returnValueHooks = [];
434
+ if (isArray(globalInterceptors.returnValue)) {
435
+ returnValueHooks.push(...globalInterceptors.returnValue);
436
+ }
437
+ const interceptor = scopedInterceptors[method];
438
+ if (interceptor && isArray(interceptor.returnValue)) {
439
+ returnValueHooks.push(...interceptor.returnValue);
440
+ }
441
+ returnValueHooks.forEach((hook) => {
442
+ returnValue = hook(returnValue) || returnValue;
443
+ });
444
+ return returnValue;
445
+ }
446
+ function getApiInterceptorHooks(method) {
447
+ const interceptor = Object.create(null);
448
+ Object.keys(globalInterceptors).forEach((hook) => {
449
+ if (hook !== 'returnValue') {
450
+ interceptor[hook] = globalInterceptors[hook].slice();
451
+ }
452
+ });
453
+ const scopedInterceptor = scopedInterceptors[method];
454
+ if (scopedInterceptor) {
455
+ Object.keys(scopedInterceptor).forEach((hook) => {
456
+ if (hook !== 'returnValue') {
457
+ interceptor[hook] = (interceptor[hook] || []).concat(scopedInterceptor[hook]);
458
+ }
459
+ });
460
+ }
461
+ return interceptor;
462
+ }
463
+ function invokeApi(method, api, options, params) {
464
+ const interceptor = getApiInterceptorHooks(method);
465
+ if (interceptor && Object.keys(interceptor).length) {
466
+ if (isArray(interceptor.invoke)) {
467
+ const res = queue(interceptor.invoke, options);
468
+ return res.then((options) => {
469
+ // 重新访问 getApiInterceptorHooks, 允许 invoke 中再次调用 addInterceptor,removeInterceptor
470
+ return api(wrapperOptions(getApiInterceptorHooks(method), options), ...params);
471
+ });
472
+ }
473
+ else {
474
+ return api(wrapperOptions(interceptor, options), ...params);
475
+ }
476
+ }
477
+ return api(options, ...params);
478
+ }
479
+
480
+ function hasCallback(args) {
481
+ if (isPlainObject(args) &&
482
+ [API_SUCCESS, API_FAIL, API_COMPLETE].find((cb) => isFunction(args[cb]))) {
483
+ return true;
484
+ }
485
+ return false;
486
+ }
487
+ function handlePromise(promise) {
488
+ // if (false) {
489
+ // return promise
490
+ // .then((data) => {
491
+ // return [null, data]
492
+ // })
493
+ // .catch((err) => [err])
494
+ // }
495
+ return promise;
496
+ }
497
+ function promisify(name, fn) {
498
+ return (args = {}, ...rest) => {
499
+ if (hasCallback(args)) {
500
+ return wrapperReturnValue(name, invokeApi(name, fn, args, rest));
501
+ }
502
+ return wrapperReturnValue(name, handlePromise(new Promise((resolve, reject) => {
503
+ invokeApi(name, fn, extend(args, { success: resolve, fail: reject }), rest);
504
+ })));
505
+ };
506
+ }
507
+
508
+ function formatApiArgs(args, options) {
509
+ const params = args[0];
510
+ if (!options ||
511
+ (!isPlainObject(options.formatArgs) && isPlainObject(params))) {
512
+ return;
513
+ }
514
+ const formatArgs = options.formatArgs;
515
+ const keys = Object.keys(formatArgs);
516
+ for (let i = 0; i < keys.length; i++) {
517
+ const name = keys[i];
518
+ const formatterOrDefaultValue = formatArgs[name];
519
+ if (isFunction(formatterOrDefaultValue)) {
520
+ const errMsg = formatterOrDefaultValue(args[0][name], params);
521
+ if (isString(errMsg)) {
522
+ return errMsg;
523
+ }
524
+ }
525
+ else {
526
+ // defaultValue
527
+ if (!hasOwn$1(params, name)) {
528
+ params[name] = formatterOrDefaultValue;
529
+ }
530
+ }
531
+ }
532
+ }
533
+ function invokeSuccess(id, name, res) {
534
+ const result = {
535
+ errMsg: name + ':ok',
536
+ };
537
+ return invokeCallback(id, extend((res || {}), result));
538
+ }
539
+ function invokeFail(id, name, errMsg, errRes = {}) {
540
+ const apiErrMsg = name + ':fail' + (errMsg ? ' ' + errMsg : '');
541
+ delete errRes.errCode;
542
+ let res = extend({ errMsg: apiErrMsg }, errRes);
543
+ return invokeCallback(id, res);
544
+ }
545
+ function beforeInvokeApi(name, args, protocol, options) {
546
+ if (('production' !== 'production')) {
547
+ validateProtocols(name, args, protocol);
548
+ }
549
+ if (options && options.beforeInvoke) {
550
+ const errMsg = options.beforeInvoke(args);
551
+ if (isString(errMsg)) {
552
+ return errMsg;
553
+ }
554
+ }
555
+ const errMsg = formatApiArgs(args, options);
556
+ if (errMsg) {
557
+ return errMsg;
558
+ }
559
+ }
560
+ function normalizeErrMsg(errMsg) {
561
+ if (!errMsg || isString(errMsg)) {
562
+ return errMsg;
563
+ }
564
+ if (errMsg.stack) {
565
+ console.error(errMsg.message + LINEFEED + errMsg.stack);
566
+ return errMsg.message;
567
+ }
568
+ return errMsg;
569
+ }
570
+ function wrapperTaskApi(name, fn, protocol, options) {
571
+ return (args) => {
572
+ const id = createAsyncApiCallback(name, args, options);
573
+ const errMsg = beforeInvokeApi(name, [args], protocol, options);
574
+ if (errMsg) {
575
+ return invokeFail(id, name, errMsg);
576
+ }
577
+ return fn(args, {
578
+ resolve: (res) => invokeSuccess(id, name, res),
579
+ reject: (errMsg, errRes) => invokeFail(id, name, normalizeErrMsg(errMsg), errRes),
580
+ });
581
+ };
582
+ }
583
+ function wrapperAsyncApi(name, fn, protocol, options) {
584
+ return wrapperTaskApi(name, fn, protocol, options);
585
+ }
586
+ function defineAsyncApi(name, fn, protocol, options) {
587
+ return promisify(name, wrapperAsyncApi(name, fn, ('production' !== 'production') ? protocol : undefined, options));
588
+ }
589
+
590
+ /**
591
+ * 简易版systemInfo,主要为upx2px,i18n服务
592
+ * @returns
593
+ */
594
+ function getBaseSystemInfo() {
595
+ return {
596
+ platform: 'harmonyos',
597
+ pixelRatio: vp2px(1),
598
+ windowWidth: lpx2px(720), // TODO designWidth可配置
599
+ };
600
+ }
601
+
602
+ const isObject = (val) => val !== null && typeof val === 'object';
603
+ const defaultDelimiters = ['{', '}'];
604
+ class BaseFormatter {
605
+ _caches;
606
+ constructor() {
607
+ this._caches = Object.create(null);
608
+ }
609
+ interpolate(message, values, delimiters = defaultDelimiters) {
610
+ if (!values) {
611
+ return [message];
612
+ }
613
+ let tokens = this._caches[message];
614
+ if (!tokens) {
615
+ tokens = parse(message, delimiters);
616
+ this._caches[message] = tokens;
617
+ }
618
+ return compile(tokens, values);
619
+ }
620
+ }
621
+ const RE_TOKEN_LIST_VALUE = /^(?:\d)+/;
622
+ const RE_TOKEN_NAMED_VALUE = /^(?:\w)+/;
623
+ function parse(format, [startDelimiter, endDelimiter]) {
624
+ const tokens = [];
625
+ let position = 0;
626
+ let text = '';
627
+ while (position < format.length) {
628
+ let char = format[position++];
629
+ if (char === startDelimiter) {
630
+ if (text) {
631
+ tokens.push({ type: 'text', value: text });
632
+ }
633
+ text = '';
634
+ let sub = '';
635
+ char = format[position++];
636
+ while (char !== undefined && char !== endDelimiter) {
637
+ sub += char;
638
+ char = format[position++];
639
+ }
640
+ const isClosed = char === endDelimiter;
641
+ const type = RE_TOKEN_LIST_VALUE.test(sub)
642
+ ? 'list'
643
+ : isClosed && RE_TOKEN_NAMED_VALUE.test(sub)
644
+ ? 'named'
645
+ : 'unknown';
646
+ tokens.push({ value: sub, type });
647
+ }
648
+ // else if (char === '%') {
649
+ // // when found rails i18n syntax, skip text capture
650
+ // if (format[position] !== '{') {
651
+ // text += char
652
+ // }
653
+ // }
654
+ else {
655
+ text += char;
656
+ }
657
+ }
658
+ text && tokens.push({ type: 'text', value: text });
659
+ return tokens;
660
+ }
661
+ function compile(tokens, values) {
662
+ const compiled = [];
663
+ let index = 0;
664
+ const mode = Array.isArray(values)
665
+ ? 'list'
666
+ : isObject(values)
667
+ ? 'named'
668
+ : 'unknown';
669
+ if (mode === 'unknown') {
670
+ return compiled;
671
+ }
672
+ while (index < tokens.length) {
673
+ const token = tokens[index];
674
+ switch (token.type) {
675
+ case 'text':
676
+ compiled.push(token.value);
677
+ break;
678
+ case 'list':
679
+ compiled.push(values[parseInt(token.value, 10)]);
680
+ break;
681
+ case 'named':
682
+ if (mode === 'named') {
683
+ compiled.push(values[token.value]);
684
+ }
685
+ break;
686
+ }
687
+ index++;
688
+ }
689
+ return compiled;
690
+ }
691
+
692
+ const LOCALE_ZH_HANS = 'zh-Hans';
693
+ const LOCALE_ZH_HANT = 'zh-Hant';
694
+ const LOCALE_EN = 'en';
695
+ const LOCALE_FR = 'fr';
696
+ const LOCALE_ES = 'es';
697
+ const hasOwnProperty = Object.prototype.hasOwnProperty;
698
+ const hasOwn = (val, key) => hasOwnProperty.call(val, key);
699
+ const defaultFormatter = new BaseFormatter();
700
+ function include(str, parts) {
701
+ return !!parts.find((part) => str.indexOf(part) !== -1);
702
+ }
703
+ function startsWith(str, parts) {
704
+ return parts.find((part) => str.indexOf(part) === 0);
705
+ }
706
+ function normalizeLocale(locale, messages) {
707
+ if (!locale) {
708
+ return;
709
+ }
710
+ locale = locale.trim().replace(/_/g, '-');
711
+ if (messages && messages[locale]) {
712
+ return locale;
713
+ }
714
+ locale = locale.toLowerCase();
715
+ if (locale === 'chinese') {
716
+ // 支付宝
717
+ return LOCALE_ZH_HANS;
718
+ }
719
+ if (locale.indexOf('zh') === 0) {
720
+ if (locale.indexOf('-hans') > -1) {
721
+ return LOCALE_ZH_HANS;
722
+ }
723
+ if (locale.indexOf('-hant') > -1) {
724
+ return LOCALE_ZH_HANT;
725
+ }
726
+ if (include(locale, ['-tw', '-hk', '-mo', '-cht'])) {
727
+ return LOCALE_ZH_HANT;
728
+ }
729
+ return LOCALE_ZH_HANS;
730
+ }
731
+ let locales = [LOCALE_EN, LOCALE_FR, LOCALE_ES];
732
+ if (messages && Object.keys(messages).length > 0) {
733
+ locales = Object.keys(messages);
734
+ }
735
+ const lang = startsWith(locale, locales);
736
+ if (lang) {
737
+ return lang;
738
+ }
739
+ }
740
+ class I18n {
741
+ locale = LOCALE_EN;
742
+ fallbackLocale = LOCALE_EN;
743
+ message = {};
744
+ messages = {};
745
+ watchers = [];
746
+ formater;
747
+ constructor({ locale, fallbackLocale, messages, watcher, formater, }) {
748
+ if (fallbackLocale) {
749
+ this.fallbackLocale = fallbackLocale;
750
+ }
751
+ this.formater = formater || defaultFormatter;
752
+ this.messages = messages || {};
753
+ this.setLocale(locale || LOCALE_EN);
754
+ if (watcher) {
755
+ this.watchLocale(watcher);
756
+ }
757
+ }
758
+ setLocale(locale) {
759
+ const oldLocale = this.locale;
760
+ this.locale = normalizeLocale(locale, this.messages) || this.fallbackLocale;
761
+ if (!this.messages[this.locale]) {
762
+ // 可能初始化时不存在
763
+ this.messages[this.locale] = {};
764
+ }
765
+ this.message = this.messages[this.locale];
766
+ // 仅发生变化时,通知
767
+ if (oldLocale !== this.locale) {
768
+ this.watchers.forEach((watcher) => {
769
+ watcher(this.locale, oldLocale);
770
+ });
771
+ }
772
+ }
773
+ getLocale() {
774
+ return this.locale;
775
+ }
776
+ watchLocale(fn) {
777
+ const index = this.watchers.push(fn) - 1;
778
+ return () => {
779
+ this.watchers.splice(index, 1);
780
+ };
781
+ }
782
+ add(locale, message, override = true) {
783
+ const curMessages = this.messages[locale];
784
+ if (curMessages) {
785
+ if (override) {
786
+ Object.assign(curMessages, message);
787
+ }
788
+ else {
789
+ Object.keys(message).forEach((key) => {
790
+ if (!hasOwn(curMessages, key)) {
791
+ curMessages[key] = message[key];
792
+ }
793
+ });
794
+ }
795
+ }
796
+ else {
797
+ this.messages[locale] = message;
798
+ }
799
+ }
800
+ f(message, values, delimiters) {
801
+ return this.formater.interpolate(message, values, delimiters).join('');
802
+ }
803
+ t(key, locale, values) {
804
+ let message = this.message;
805
+ if (typeof locale === 'string') {
806
+ locale = normalizeLocale(locale, this.messages);
807
+ locale && (message = this.messages[locale]);
808
+ }
809
+ else {
810
+ values = locale;
811
+ }
812
+ if (!hasOwn(message, key)) {
813
+ console.warn(`Cannot translate the value of keypath ${key}. Use the value of keypath as default.`);
814
+ return key;
815
+ }
816
+ return this.formater.interpolate(message[key], values).join('');
817
+ }
818
+ }
819
+
820
+ function watchAppLocale(appVm, i18n) {
821
+ // 需要保证 watch 的触发在组件渲染之前
822
+ if (appVm.$watchLocale) {
823
+ // vue2
824
+ appVm.$watchLocale((newLocale) => {
825
+ i18n.setLocale(newLocale);
826
+ });
827
+ }
828
+ else {
829
+ appVm.$watch(() => appVm.$locale, (newLocale) => {
830
+ i18n.setLocale(newLocale);
831
+ });
832
+ }
833
+ }
834
+ function getDefaultLocale() {
835
+ if (typeof uni !== 'undefined' && uni.getLocale) {
836
+ return uni.getLocale();
837
+ }
838
+ // 小程序平台,uni 和 uni-i18n 互相引用,导致访问不到 uni,故在 global 上挂了 getLocale
839
+ if (typeof global !== 'undefined' && global.getLocale) {
840
+ return global.getLocale();
841
+ }
842
+ return LOCALE_EN;
843
+ }
844
+ function initVueI18n(locale, messages = {}, fallbackLocale, watcher) {
845
+ // 兼容旧版本入参
846
+ if (typeof locale !== 'string') {
847
+ [locale, messages] = [
848
+ messages,
849
+ locale,
850
+ ];
851
+ }
852
+ if (typeof locale !== 'string') {
853
+ // 因为小程序平台,uni-i18n 和 uni 互相引用,导致此时访问 uni 时,为 undefined
854
+ locale = getDefaultLocale();
855
+ }
856
+ if (typeof fallbackLocale !== 'string') {
857
+ fallbackLocale =
858
+ (typeof __uniConfig !== 'undefined' && __uniConfig.fallbackLocale) ||
859
+ LOCALE_EN;
860
+ }
861
+ const i18n = new I18n({
862
+ locale,
863
+ fallbackLocale,
864
+ messages,
865
+ watcher,
866
+ });
867
+ let t = (key, values) => {
868
+ if (typeof getApp !== 'function') {
869
+ // app view
870
+ /* eslint-disable no-func-assign */
871
+ t = function (key, values) {
872
+ return i18n.t(key, values);
873
+ };
874
+ }
875
+ else {
876
+ let isWatchedAppLocale = false;
877
+ t = function (key, values) {
878
+ const appVm = getApp().$vm;
879
+ // 可能$vm还不存在,比如在支付宝小程序中,组件定义较早,在props的default里使用了t()函数(如uni-goods-nav),此时app还未初始化
880
+ // options: {
881
+ // type: Array,
882
+ // default () {
883
+ // return [{
884
+ // icon: 'shop',
885
+ // text: t("uni-goods-nav.options.shop"),
886
+ // }, {
887
+ // icon: 'cart',
888
+ // text: t("uni-goods-nav.options.cart")
889
+ // }]
890
+ // }
891
+ // },
892
+ if (appVm) {
893
+ // 触发响应式
894
+ appVm.$locale;
895
+ if (!isWatchedAppLocale) {
896
+ isWatchedAppLocale = true;
897
+ watchAppLocale(appVm, i18n);
898
+ }
899
+ }
900
+ return i18n.t(key, values);
901
+ };
902
+ }
903
+ return t(key, values);
904
+ };
905
+ return {
906
+ i18n,
907
+ f(message, values, delimiters) {
908
+ return i18n.f(message, values, delimiters);
909
+ },
910
+ t(key, values) {
911
+ return t(key, values);
912
+ },
913
+ add(locale, message, override = true) {
914
+ return i18n.add(locale, message, override);
915
+ },
916
+ watch(fn) {
917
+ return i18n.watchLocale(fn);
918
+ },
919
+ getLocale() {
920
+ return i18n.getLocale();
921
+ },
922
+ setLocale(newLocale) {
923
+ return i18n.setLocale(newLocale);
924
+ },
925
+ };
926
+ }
927
+
928
+ const isEnableLocale = /*#__PURE__*/ once(() => typeof __uniConfig !== 'undefined' &&
929
+ __uniConfig.locales &&
930
+ !!Object.keys(__uniConfig.locales).length);
931
+
932
+ let i18n;
933
+ function useI18n() {
934
+ if (!i18n) {
935
+ let locale;
936
+ {
937
+ locale = uni.getSystemInfoSync().language;
938
+ }
939
+ i18n = initVueI18n(locale);
940
+ // 自定义locales
941
+ if (isEnableLocale()) {
942
+ const localeKeys = Object.keys(__uniConfig.locales || {});
943
+ if (localeKeys.length) {
944
+ localeKeys.forEach((locale) => i18n.add(locale, __uniConfig.locales[locale]));
945
+ }
946
+ // initVueI18n 时 messages 还没有,导致用户自定义 locale 可能不生效,当设置完 messages 后,重新设置 locale
947
+ i18n.setLocale(locale);
948
+ }
949
+ }
950
+ return i18n;
951
+ }
952
+
953
+ // This file is created by scripts/i18n.js
954
+ // Do not modify this file!!!!!!!!!
955
+ function normalizeMessages(module, keys, values) {
956
+ return keys.reduce((res, name, index) => {
957
+ res[module + name] = values[index];
958
+ return res;
959
+ }, {});
960
+ }
961
+ const initI18nChooseImageMsgsOnce = /*#__PURE__*/ once(() => {
962
+ const name = 'uni.chooseImage.';
963
+ const keys = ['cancel', 'sourceType.album', 'sourceType.camera'];
964
+ {
965
+ useI18n().add(LOCALE_EN, normalizeMessages(name, keys, ['Cancel', 'Album', 'Camera']), false);
966
+ }
967
+ {
968
+ useI18n().add(LOCALE_ES, normalizeMessages(name, keys, ['Cancelar', 'Álbum', 'Cámara']), false);
969
+ }
970
+ {
971
+ useI18n().add(LOCALE_FR, normalizeMessages(name, keys, ['Annuler', 'Album', 'Caméra']), false);
972
+ }
973
+ {
974
+ useI18n().add(LOCALE_ZH_HANS, normalizeMessages(name, keys, ['取消', '从相册选择', '拍摄']), false);
975
+ }
976
+ {
977
+ useI18n().add(LOCALE_ZH_HANT, normalizeMessages(name, keys, ['取消', '從相冊選擇', '拍攝']), false);
978
+ }
979
+ });
980
+
981
+ function getCurrentPage() {
982
+ const pages = getCurrentPages();
983
+ const len = pages.length;
984
+ if (len) {
985
+ return pages[len - 1];
986
+ }
987
+ }
988
+ function getCurrentPageVm() {
989
+ const page = getCurrentPage();
990
+ if (page) {
991
+ return page.$vm;
992
+ }
993
+ }
994
+
995
+ function invokeHook(vm, name, args) {
996
+ if (isString(vm)) {
997
+ args = name;
998
+ name = vm;
999
+ vm = getCurrentPageVm();
1000
+ }
1001
+ else if (typeof vm === 'number') {
1002
+ const page = getCurrentPages().find((page) => page.$page.id === vm);
1003
+ if (page) {
1004
+ vm = page.$vm;
1005
+ }
1006
+ else {
1007
+ vm = getCurrentPageVm();
1008
+ }
1009
+ }
1010
+ if (!vm) {
1011
+ return;
1012
+ }
1013
+ const hooks = vm.$[name];
1014
+ return hooks && invokeArrayFns(hooks, args);
1015
+ }
1016
+
1017
+ function initPageVm(pageVm, page) {
1018
+ pageVm.route = page.route;
1019
+ pageVm.$vm = pageVm;
1020
+ pageVm.$page = page;
1021
+ pageVm.$mpType = 'page';
1022
+ pageVm.$fontFamilySet = new Set();
1023
+ if (page.meta.isTabBar) {
1024
+ pageVm.$.__isTabBar = true;
1025
+ // TODO preload? 初始化时,状态肯定是激活
1026
+ pageVm.$.__isActive = true;
1027
+ }
1028
+ }
1029
+
1030
+ const API_CHOOSE_IMAGE = 'chooseImage';
1031
+ const ChooseImageOptions = {
1032
+ formatArgs: {
1033
+ count(value, params) {
1034
+ if (!value || value <= 0) {
1035
+ params.count = 9;
1036
+ }
1037
+ },
1038
+ sizeType(sizeType, params) {
1039
+ params.sizeType = elemsInArray(sizeType, CHOOSE_SIZE_TYPES);
1040
+ },
1041
+ sourceType(sourceType, params) {
1042
+ params.sourceType = elemsInArray(sourceType, CHOOSE_SOURCE_TYPES);
1043
+ },
1044
+ extension(extension, params) {
1045
+ if (extension instanceof Array && extension.length === 0) {
1046
+ return 'param extension should not be empty.';
1047
+ }
1048
+ if (!extension)
1049
+ params.extension = ['*'];
1050
+ },
1051
+ },
1052
+ };
1053
+ const ChooseImageProtocol = {
1054
+ count: Number,
1055
+ sizeType: [Array, String],
1056
+ sourceType: Array,
1057
+ extension: Array,
1058
+ };
1059
+
1060
+ async function openAlbum(count = 9) {
1061
+ return new Promise((resolve, reject) => {
1062
+ try {
1063
+ const photoSelectOptions = new picker.PhotoSelectOptions();
1064
+ photoSelectOptions.MIMEType = picker.PhotoViewMIMETypes.IMAGE_TYPE;
1065
+ photoSelectOptions.maxSelectNumber = count;
1066
+ const photoPicker = new picker.PhotoViewPicker();
1067
+ photoPicker
1068
+ .select(photoSelectOptions)
1069
+ .then((photoSelectResult) => {
1070
+ resolve({
1071
+ tempFilePaths: photoSelectResult.photoUris,
1072
+ tempFiles: photoSelectResult.photoUris.map((uri) => {
1073
+ const file = fs.openSync(uri, fs.OpenMode.READ_ONLY);
1074
+ const stat = fs.statSync(file.fd);
1075
+ fs.closeSync(file);
1076
+ return {
1077
+ path: uri,
1078
+ size: stat.size,
1079
+ };
1080
+ }),
1081
+ });
1082
+ console.info('PhotoViewPicker.select successfully, PhotoSelectResult uri: ' +
1083
+ JSON.stringify(photoSelectResult));
1084
+ })
1085
+ .catch((error) => {
1086
+ console.error('PhotoViewPicker.select failed with err: ' + JSON.stringify(error));
1087
+ reject(error);
1088
+ });
1089
+ }
1090
+ catch (error) {
1091
+ reject(error);
1092
+ }
1093
+ });
1094
+ }
1095
+ async function openCamera() {
1096
+ return {
1097
+ tempFilePaths: [],
1098
+ tempFiles: [],
1099
+ };
1100
+ }
1101
+ async function chooseSourceType() {
1102
+ initI18nChooseImageMsgsOnce();
1103
+ const { t } = useI18n();
1104
+ return new Promise((resolve, reject) => {
1105
+ try {
1106
+ promptAction.showActionMenu({
1107
+ title: '',
1108
+ buttons: [
1109
+ {
1110
+ text: t('uni.chooseImage.sourceType.camera'),
1111
+ color: '#000000',
1112
+ },
1113
+ {
1114
+ text: t('uni.chooseImage.sourceType.album'),
1115
+ color: '#000000',
1116
+ },
1117
+ ],
1118
+ }, (err, data) => {
1119
+ if (err) {
1120
+ console.info(`showActionMenu fail callback, error code: ${err.code}, error message: ${err.message}`);
1121
+ reject(err);
1122
+ }
1123
+ console.info('showActionMenu success callback, click button: ' + data.index);
1124
+ switch (data.index) {
1125
+ case 0:
1126
+ resolve('camera');
1127
+ return;
1128
+ case 1:
1129
+ resolve('album');
1130
+ return;
1131
+ default:
1132
+ break;
1133
+ }
1134
+ });
1135
+ }
1136
+ catch (error) {
1137
+ reject(error);
1138
+ }
1139
+ });
1140
+ }
1141
+ const chooseImage = defineAsyncApi(API_CHOOSE_IMAGE, function ({ count, sourceType } = {}, { resolve, reject }) {
1142
+ return Promise.resolve()
1143
+ .then(async () => {
1144
+ let realSourceType = '';
1145
+ if (sourceType && sourceType.length === 1) {
1146
+ if (sourceType.includes('album')) {
1147
+ realSourceType = 'album';
1148
+ }
1149
+ else if (sourceType.includes('camera')) {
1150
+ realSourceType = 'camera';
1151
+ }
1152
+ }
1153
+ if (!realSourceType) {
1154
+ realSourceType = await chooseSourceType();
1155
+ }
1156
+ switch (realSourceType) {
1157
+ case 'album':
1158
+ return openAlbum(count);
1159
+ case 'camera':
1160
+ return openCamera();
1161
+ }
1162
+ })
1163
+ .then(resolve)
1164
+ .catch(reject);
1165
+ }, ChooseImageProtocol, ChooseImageOptions);
1166
+
1167
+ function getLocale() {
1168
+ return 'zh-CN';
1169
+ }
1170
+
1171
+ function getSystemInfoSync() {
1172
+ // TODO: implement
1173
+ return getBaseSystemInfo();
1174
+ }
1175
+
1176
+ var uni$1 = {
1177
+ __proto__: null,
1178
+ chooseImage: chooseImage,
1179
+ getLocale: getLocale,
1180
+ getSystemInfoSync: getSystemInfoSync
1181
+ };
1182
+
1183
+ const pages = [];
1184
+ function addCurrentPage(page) {
1185
+ const $page = page.$page;
1186
+ if (!$page.meta.isNVue) {
1187
+ return pages.push(page);
1188
+ }
1189
+ // 开发阶段热刷新需要移除旧的相同 id 的 page
1190
+ const index = pages.findIndex((p) => p.$page.id === page.$page.id);
1191
+ if (index > -1) {
1192
+ pages.splice(index, 1, page);
1193
+ }
1194
+ else {
1195
+ pages.push(page);
1196
+ }
1197
+ }
1198
+
1199
+ function setupPage(component) {
1200
+ const oldSetup = component.setup;
1201
+ component.inheritAttrs = false; // 禁止继承 __pageId 等属性,避免告警
1202
+ component.setup = (_, ctx) => {
1203
+ const { attrs: { __pageId, __pagePath, __pageQuery, __pageInstance }, } = ctx;
1204
+ if (('production' !== 'production')) {
1205
+ console.log(formatLog(__pagePath, 'setup'));
1206
+ }
1207
+ const instance = getCurrentInstance();
1208
+ const pageVm = instance.proxy;
1209
+ initPageVm(pageVm, __pageInstance);
1210
+ addCurrentPage(initScope(__pageId, pageVm, __pageInstance));
1211
+ {
1212
+ onMounted(() => {
1213
+ nextTick(() => {
1214
+ // onShow被延迟,故onReady也同时延迟
1215
+ invokeHook(pageVm, ON_READY);
1216
+ });
1217
+ // TODO preloadSubPackages
1218
+ });
1219
+ onBeforeUnmount(() => {
1220
+ invokeHook(pageVm, ON_UNLOAD);
1221
+ });
1222
+ }
1223
+ if (oldSetup) {
1224
+ return oldSetup(__pageQuery, ctx);
1225
+ }
1226
+ };
1227
+ return component;
1228
+ }
1229
+ function initScope(pageId, vm, pageInstance) {
1230
+ {
1231
+ const $getAppWebview = () => {
1232
+ return plus.webview.getWebviewById(pageId + '');
1233
+ };
1234
+ vm.$getAppWebview = $getAppWebview;
1235
+ vm.$.ctx.$scope = {
1236
+ $getAppWebview,
1237
+ };
1238
+ }
1239
+ vm.getOpenerEventChannel = () => {
1240
+ if (!pageInstance.eventChannel) {
1241
+ pageInstance.eventChannel = new EventChannel(pageId);
1242
+ }
1243
+ return pageInstance.eventChannel;
1244
+ };
1245
+ return vm;
1246
+ }
1247
+
1248
+ function isVuePageAsyncComponent(component) {
1249
+ return isFunction(component);
1250
+ }
1251
+ const pagesMap = new Map();
1252
+ function definePage(pagePath, asyncComponent) {
1253
+ pagesMap.set(pagePath, once(createFactory(asyncComponent)));
1254
+ }
1255
+ function createFactory(component) {
1256
+ return () => {
1257
+ if (isVuePageAsyncComponent(component)) {
1258
+ return component().then((component) => setupPage(component));
1259
+ }
1260
+ return setupPage(component);
1261
+ };
1262
+ }
1263
+
1264
+ var index = {
1265
+ uni: uni$1,
1266
+ __definePage: definePage,
1267
+ };
1268
+
1269
+ export { index as default };
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@dcloudio/uni-app-harmony",
3
+ "version": "3.0.0-4010420240430001",
4
+ "description": "@dcloudio/uni-app-harmony",
5
+ "files": [
6
+ "dist",
7
+ "lib",
8
+ "style"
9
+ ],
10
+ "sideEffects": [
11
+ "lib/automator.js"
12
+ ],
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/dcloudio/uni-app.git",
16
+ "directory": "packages/uni-app-harmony"
17
+ },
18
+ "license": "Apache-2.0",
19
+ "bugs": {
20
+ "url": "https://github.com/dcloudio/uni-app/issues"
21
+ },
22
+ "gitHead": "33e807d66e1fe47e2ee08ad9c59247e37b8884da",
23
+ "dependencies": {
24
+ "debug": "^4.3.3",
25
+ "fs-extra": "^10.0.0",
26
+ "licia": "^1.29.0",
27
+ "postcss-selector-parser": "^6.0.6"
28
+ },
29
+ "devDependencies": {
30
+ "@dcloudio/uni-cli-shared": "3.0.0-4010420240430001",
31
+ "@dcloudio/uni-app-plus": "3.0.0-4010420240430001",
32
+ "@dcloudio/uni-components": "3.0.0-4010420240430001",
33
+ "@dcloudio/uni-i18n": "3.0.0-4010420240430001",
34
+ "@dcloudio/uni-shared": "3.0.0-4010420240430001",
35
+ "@types/pako": "1.0.2",
36
+ "@vue/compiler-sfc": "3.4.21",
37
+ "autoprefixer": "^10.4.18",
38
+ "pako": "^1.0.11",
39
+ "postcss": "^8.4.21",
40
+ "vue": "3.4.21"
41
+ }
42
+ }