@heybox/hb-sdk 0.8.3-alpha.6 → 0.8.3
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.
- package/CHANGELOG.md +60 -1
- package/README.md +24 -4
- package/dist/cli-chunks/{build-BRLdyZ76.cjs → build-BMLuhvh9.cjs} +5 -5
- package/dist/cli-chunks/{context-CbiL9O6w.cjs → context-BoNshqZO.cjs} +2 -2
- package/dist/cli-chunks/{create-B7kL5QkJ.cjs → create-rUrkd162.cjs} +1 -1
- package/dist/cli-chunks/{dev-DvH2_I1Y.cjs → dev-BRx7xYck.cjs} +74 -19
- package/dist/cli-chunks/{doctor-DMqILTR4.cjs → doctor-DOCFSRjQ.cjs} +1 -1
- package/dist/cli-chunks/{index-BVylxPGU.cjs → index-BrJ7364Q.cjs} +15 -15
- package/dist/cli-chunks/{index-D8AT5s4x.cjs → index-CbmIweP8.cjs} +2 -2
- package/dist/cli-chunks/{index.esm-Cwh5ei9-.cjs → index.esm-CGFTxGm6.cjs} +7 -7
- package/dist/cli-chunks/{login-BHAg3-HY.cjs → login-DxtSW2QP.cjs} +2 -2
- package/dist/cli-chunks/{project-vite-AGDPqVSX.cjs → project-vite-D9tmGT59.cjs} +1 -1
- package/dist/cli-chunks/{remote-jgmCl_OP.cjs → remote-DuiJdetu.cjs} +7 -7
- package/dist/cli-chunks/{runtime-gate-DjTZ46xz.cjs → runtime-gate-CDh8XjRx.cjs} +1 -1
- package/dist/cli-chunks/{runtime-permission-env-Bjlpv6zh.cjs → runtime-permission-env-D2pJlHds.cjs} +1 -1
- package/dist/cli-chunks/{session-DnS1mH8i.cjs → session-BAw6iix6.cjs} +1 -1
- package/dist/cli-chunks/{skill-CUnigEtN.cjs → skill-Cu4QVawo.cjs} +2 -2
- package/dist/cli-chunks/{version-CNl684Yw.cjs → version-BuPFCnrl.cjs} +1 -1
- package/dist/cli.cjs +1 -1
- package/dist/devtools/browser-dev-host/assets/browser-dev-host-CE4o5TF5.js +102 -0
- package/dist/devtools/browser-dev-host/assets/{desktop-app-launch-38leCDIj.js → desktop-app-launch-DldUhS5Y.js} +1 -1
- package/dist/devtools/browser-dev-host/assets/index-0Ac39Njs.css +1 -0
- package/dist/devtools/browser-dev-host/assets/{index-Dui3LdcO.js → index-DUhquRwB.js} +4 -4
- package/dist/devtools/browser-dev-host/index.html +3 -3
- package/dist/index.cjs.js +549 -8
- package/dist/index.esm.js +549 -8
- package/dist/vite.cjs.js +69 -7
- package/dist/vite.esm.js +69 -7
- package/docs/device-logs.md +2 -2
- package/docs/runtime-host-migration.md +7 -5
- package/package.json +6 -6
- package/skill/skill.json +4 -4
- package/types/index.d.ts +1 -1
- package/types/modules/navigation/app-pages/index.d.ts +1 -1
- package/types/modules/navigation/app-pages/types.d.ts +23 -5
- package/types/modules/navigation/index.d.ts +21 -12
- package/types/modules/share/extra.d.ts +2 -0
- package/types/modules/share/types.d.ts +1 -0
- package/types/protocol.d.ts +1 -1
- package/types/vite/html-policy.d.ts +1 -0
- package/dist/devtools/browser-dev-host/assets/browser-dev-host-D2fH-vdb.js +0 -101
- package/dist/devtools/browser-dev-host/assets/index-BrXEMo2-.css +0 -1
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
6
|
<meta name="theme-color" content="#f4f5f7" />
|
|
7
7
|
<title>小程序工坊调试台</title>
|
|
8
|
-
<script type="module" crossorigin src="/assets/index-
|
|
9
|
-
<link rel="modulepreload" crossorigin href="/assets/desktop-app-launch-
|
|
10
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
8
|
+
<script type="module" crossorigin src="/assets/index-DUhquRwB.js"></script>
|
|
9
|
+
<link rel="modulepreload" crossorigin href="/assets/desktop-app-launch-DldUhS5Y.js">
|
|
10
|
+
<link rel="stylesheet" crossorigin href="/assets/index-0Ac39Njs.css">
|
|
11
11
|
</head>
|
|
12
12
|
<body>
|
|
13
13
|
<div id="app"></div>
|
package/dist/index.cjs.js
CHANGED
|
@@ -1342,7 +1342,7 @@ function createMessageId() {
|
|
|
1342
1342
|
/** 构建时替换为当前发布包的实际版本。 */
|
|
1343
1343
|
const HB_SDK_VERSION = typeof undefined === 'string'
|
|
1344
1344
|
? undefined
|
|
1345
|
-
: '0.8.3
|
|
1345
|
+
: '0.8.3';
|
|
1346
1346
|
|
|
1347
1347
|
const RUNTIME_MODES = new Set(['production', 'preview', 'development', 'unknown']);
|
|
1348
1348
|
const OPERATING_SYSTEM_NAMES = new Set(['android', 'ios', 'ohos', 'windows', 'macos', 'linux', 'unknown']);
|
|
@@ -2594,6 +2594,14 @@ function copyLink(requester, options) {
|
|
|
2594
2594
|
|
|
2595
2595
|
// Integer Utility
|
|
2596
2596
|
var UINT32_MAX = 4294967295;
|
|
2597
|
+
// DataView extension to handle int64 / uint64,
|
|
2598
|
+
// where the actual range is 53-bits integer (a.k.a. safe integer)
|
|
2599
|
+
function setUint64(view, offset, value) {
|
|
2600
|
+
var high = value / 4294967296;
|
|
2601
|
+
var low = value; // high bits are truncated by DataView
|
|
2602
|
+
view.setUint32(offset, high);
|
|
2603
|
+
view.setUint32(offset + 4, low);
|
|
2604
|
+
}
|
|
2597
2605
|
function setInt64(view, offset, value) {
|
|
2598
2606
|
var high = Math.floor(value / 4294967296);
|
|
2599
2607
|
var low = value; // high bits are truncated by DataView
|
|
@@ -2615,8 +2623,89 @@ var _a, _b, _c;
|
|
|
2615
2623
|
var TEXT_ENCODING_AVAILABLE = (typeof process === "undefined" || ((_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a["TEXT_ENCODING"]) !== "never") &&
|
|
2616
2624
|
typeof TextEncoder !== "undefined" &&
|
|
2617
2625
|
typeof TextDecoder !== "undefined";
|
|
2626
|
+
function utf8Count(str) {
|
|
2627
|
+
var strLength = str.length;
|
|
2628
|
+
var byteLength = 0;
|
|
2629
|
+
var pos = 0;
|
|
2630
|
+
while (pos < strLength) {
|
|
2631
|
+
var value = str.charCodeAt(pos++);
|
|
2632
|
+
if ((value & 0xffffff80) === 0) {
|
|
2633
|
+
// 1-byte
|
|
2634
|
+
byteLength++;
|
|
2635
|
+
continue;
|
|
2636
|
+
}
|
|
2637
|
+
else if ((value & 0xfffff800) === 0) {
|
|
2638
|
+
// 2-bytes
|
|
2639
|
+
byteLength += 2;
|
|
2640
|
+
}
|
|
2641
|
+
else {
|
|
2642
|
+
// handle surrogate pair
|
|
2643
|
+
if (value >= 0xd800 && value <= 0xdbff) {
|
|
2644
|
+
// high surrogate
|
|
2645
|
+
if (pos < strLength) {
|
|
2646
|
+
var extra = str.charCodeAt(pos);
|
|
2647
|
+
if ((extra & 0xfc00) === 0xdc00) {
|
|
2648
|
+
++pos;
|
|
2649
|
+
value = ((value & 0x3ff) << 10) + (extra & 0x3ff) + 0x10000;
|
|
2650
|
+
}
|
|
2651
|
+
}
|
|
2652
|
+
}
|
|
2653
|
+
if ((value & 0xffff0000) === 0) {
|
|
2654
|
+
// 3-byte
|
|
2655
|
+
byteLength += 3;
|
|
2656
|
+
}
|
|
2657
|
+
else {
|
|
2658
|
+
// 4-byte
|
|
2659
|
+
byteLength += 4;
|
|
2660
|
+
}
|
|
2661
|
+
}
|
|
2662
|
+
}
|
|
2663
|
+
return byteLength;
|
|
2664
|
+
}
|
|
2665
|
+
function utf8EncodeJs(str, output, outputOffset) {
|
|
2666
|
+
var strLength = str.length;
|
|
2667
|
+
var offset = outputOffset;
|
|
2668
|
+
var pos = 0;
|
|
2669
|
+
while (pos < strLength) {
|
|
2670
|
+
var value = str.charCodeAt(pos++);
|
|
2671
|
+
if ((value & 0xffffff80) === 0) {
|
|
2672
|
+
// 1-byte
|
|
2673
|
+
output[offset++] = value;
|
|
2674
|
+
continue;
|
|
2675
|
+
}
|
|
2676
|
+
else if ((value & 0xfffff800) === 0) {
|
|
2677
|
+
// 2-bytes
|
|
2678
|
+
output[offset++] = ((value >> 6) & 0x1f) | 0xc0;
|
|
2679
|
+
}
|
|
2680
|
+
else {
|
|
2681
|
+
// handle surrogate pair
|
|
2682
|
+
if (value >= 0xd800 && value <= 0xdbff) {
|
|
2683
|
+
// high surrogate
|
|
2684
|
+
if (pos < strLength) {
|
|
2685
|
+
var extra = str.charCodeAt(pos);
|
|
2686
|
+
if ((extra & 0xfc00) === 0xdc00) {
|
|
2687
|
+
++pos;
|
|
2688
|
+
value = ((value & 0x3ff) << 10) + (extra & 0x3ff) + 0x10000;
|
|
2689
|
+
}
|
|
2690
|
+
}
|
|
2691
|
+
}
|
|
2692
|
+
if ((value & 0xffff0000) === 0) {
|
|
2693
|
+
// 3-byte
|
|
2694
|
+
output[offset++] = ((value >> 12) & 0x0f) | 0xe0;
|
|
2695
|
+
output[offset++] = ((value >> 6) & 0x3f) | 0x80;
|
|
2696
|
+
}
|
|
2697
|
+
else {
|
|
2698
|
+
// 4-byte
|
|
2699
|
+
output[offset++] = ((value >> 18) & 0x07) | 0xf0;
|
|
2700
|
+
output[offset++] = ((value >> 12) & 0x3f) | 0x80;
|
|
2701
|
+
output[offset++] = ((value >> 6) & 0x3f) | 0x80;
|
|
2702
|
+
}
|
|
2703
|
+
}
|
|
2704
|
+
output[offset++] = (value & 0x3f) | 0x80;
|
|
2705
|
+
}
|
|
2706
|
+
}
|
|
2618
2707
|
var sharedTextEncoder = TEXT_ENCODING_AVAILABLE ? new TextEncoder() : undefined;
|
|
2619
|
-
!TEXT_ENCODING_AVAILABLE
|
|
2708
|
+
var TEXT_ENCODER_THRESHOLD = !TEXT_ENCODING_AVAILABLE
|
|
2620
2709
|
? UINT32_MAX
|
|
2621
2710
|
: typeof process !== "undefined" && ((_b = process === null || process === void 0 ? void 0 : process.env) === null || _b === void 0 ? void 0 : _b["TEXT_ENCODING"]) !== "force"
|
|
2622
2711
|
? 200
|
|
@@ -2627,7 +2716,7 @@ function utf8EncodeTEencode(str, output, outputOffset) {
|
|
|
2627
2716
|
function utf8EncodeTEencodeInto(str, output, outputOffset) {
|
|
2628
2717
|
sharedTextEncoder.encodeInto(str, output.subarray(outputOffset));
|
|
2629
2718
|
}
|
|
2630
|
-
(sharedTextEncoder === null || sharedTextEncoder === void 0 ? void 0 : sharedTextEncoder.encodeInto) ? utf8EncodeTEencodeInto : utf8EncodeTEencode;
|
|
2719
|
+
var utf8EncodeTE = (sharedTextEncoder === null || sharedTextEncoder === void 0 ? void 0 : sharedTextEncoder.encodeInto) ? utf8EncodeTEencodeInto : utf8EncodeTEencode;
|
|
2631
2720
|
var CHUNK_SIZE = 4096;
|
|
2632
2721
|
function utf8DecodeJs(bytes, inputOffset, byteLength) {
|
|
2633
2722
|
var offset = inputOffset;
|
|
@@ -2917,6 +3006,431 @@ function createDataView(buffer) {
|
|
|
2917
3006
|
return new DataView(bufferView.buffer, bufferView.byteOffset, bufferView.byteLength);
|
|
2918
3007
|
}
|
|
2919
3008
|
|
|
3009
|
+
var DEFAULT_MAX_DEPTH = 100;
|
|
3010
|
+
var DEFAULT_INITIAL_BUFFER_SIZE = 2048;
|
|
3011
|
+
var Encoder = /** @class */ (function () {
|
|
3012
|
+
function Encoder(extensionCodec, context, maxDepth, initialBufferSize, sortKeys, forceFloat32, ignoreUndefined, forceIntegerToFloat) {
|
|
3013
|
+
if (extensionCodec === void 0) { extensionCodec = ExtensionCodec.defaultCodec; }
|
|
3014
|
+
if (context === void 0) { context = undefined; }
|
|
3015
|
+
if (maxDepth === void 0) { maxDepth = DEFAULT_MAX_DEPTH; }
|
|
3016
|
+
if (initialBufferSize === void 0) { initialBufferSize = DEFAULT_INITIAL_BUFFER_SIZE; }
|
|
3017
|
+
if (sortKeys === void 0) { sortKeys = false; }
|
|
3018
|
+
if (forceFloat32 === void 0) { forceFloat32 = false; }
|
|
3019
|
+
if (ignoreUndefined === void 0) { ignoreUndefined = false; }
|
|
3020
|
+
if (forceIntegerToFloat === void 0) { forceIntegerToFloat = false; }
|
|
3021
|
+
this.extensionCodec = extensionCodec;
|
|
3022
|
+
this.context = context;
|
|
3023
|
+
this.maxDepth = maxDepth;
|
|
3024
|
+
this.initialBufferSize = initialBufferSize;
|
|
3025
|
+
this.sortKeys = sortKeys;
|
|
3026
|
+
this.forceFloat32 = forceFloat32;
|
|
3027
|
+
this.ignoreUndefined = ignoreUndefined;
|
|
3028
|
+
this.forceIntegerToFloat = forceIntegerToFloat;
|
|
3029
|
+
this.pos = 0;
|
|
3030
|
+
this.view = new DataView(new ArrayBuffer(this.initialBufferSize));
|
|
3031
|
+
this.bytes = new Uint8Array(this.view.buffer);
|
|
3032
|
+
}
|
|
3033
|
+
Encoder.prototype.reinitializeState = function () {
|
|
3034
|
+
this.pos = 0;
|
|
3035
|
+
};
|
|
3036
|
+
/**
|
|
3037
|
+
* This is almost equivalent to {@link Encoder#encode}, but it returns an reference of the encoder's internal buffer and thus much faster than {@link Encoder#encode}.
|
|
3038
|
+
*
|
|
3039
|
+
* @returns Encodes the object and returns a shared reference the encoder's internal buffer.
|
|
3040
|
+
*/
|
|
3041
|
+
Encoder.prototype.encodeSharedRef = function (object) {
|
|
3042
|
+
this.reinitializeState();
|
|
3043
|
+
this.doEncode(object, 1);
|
|
3044
|
+
return this.bytes.subarray(0, this.pos);
|
|
3045
|
+
};
|
|
3046
|
+
/**
|
|
3047
|
+
* @returns Encodes the object and returns a copy of the encoder's internal buffer.
|
|
3048
|
+
*/
|
|
3049
|
+
Encoder.prototype.encode = function (object) {
|
|
3050
|
+
this.reinitializeState();
|
|
3051
|
+
this.doEncode(object, 1);
|
|
3052
|
+
return this.bytes.slice(0, this.pos);
|
|
3053
|
+
};
|
|
3054
|
+
Encoder.prototype.doEncode = function (object, depth) {
|
|
3055
|
+
if (depth > this.maxDepth) {
|
|
3056
|
+
throw new Error("Too deep objects in depth ".concat(depth));
|
|
3057
|
+
}
|
|
3058
|
+
if (object == null) {
|
|
3059
|
+
this.encodeNil();
|
|
3060
|
+
}
|
|
3061
|
+
else if (typeof object === "boolean") {
|
|
3062
|
+
this.encodeBoolean(object);
|
|
3063
|
+
}
|
|
3064
|
+
else if (typeof object === "number") {
|
|
3065
|
+
this.encodeNumber(object);
|
|
3066
|
+
}
|
|
3067
|
+
else if (typeof object === "string") {
|
|
3068
|
+
this.encodeString(object);
|
|
3069
|
+
}
|
|
3070
|
+
else {
|
|
3071
|
+
this.encodeObject(object, depth);
|
|
3072
|
+
}
|
|
3073
|
+
};
|
|
3074
|
+
Encoder.prototype.ensureBufferSizeToWrite = function (sizeToWrite) {
|
|
3075
|
+
var requiredSize = this.pos + sizeToWrite;
|
|
3076
|
+
if (this.view.byteLength < requiredSize) {
|
|
3077
|
+
this.resizeBuffer(requiredSize * 2);
|
|
3078
|
+
}
|
|
3079
|
+
};
|
|
3080
|
+
Encoder.prototype.resizeBuffer = function (newSize) {
|
|
3081
|
+
var newBuffer = new ArrayBuffer(newSize);
|
|
3082
|
+
var newBytes = new Uint8Array(newBuffer);
|
|
3083
|
+
var newView = new DataView(newBuffer);
|
|
3084
|
+
newBytes.set(this.bytes);
|
|
3085
|
+
this.view = newView;
|
|
3086
|
+
this.bytes = newBytes;
|
|
3087
|
+
};
|
|
3088
|
+
Encoder.prototype.encodeNil = function () {
|
|
3089
|
+
this.writeU8(0xc0);
|
|
3090
|
+
};
|
|
3091
|
+
Encoder.prototype.encodeBoolean = function (object) {
|
|
3092
|
+
if (object === false) {
|
|
3093
|
+
this.writeU8(0xc2);
|
|
3094
|
+
}
|
|
3095
|
+
else {
|
|
3096
|
+
this.writeU8(0xc3);
|
|
3097
|
+
}
|
|
3098
|
+
};
|
|
3099
|
+
Encoder.prototype.encodeNumber = function (object) {
|
|
3100
|
+
if (Number.isSafeInteger(object) && !this.forceIntegerToFloat) {
|
|
3101
|
+
if (object >= 0) {
|
|
3102
|
+
if (object < 0x80) {
|
|
3103
|
+
// positive fixint
|
|
3104
|
+
this.writeU8(object);
|
|
3105
|
+
}
|
|
3106
|
+
else if (object < 0x100) {
|
|
3107
|
+
// uint 8
|
|
3108
|
+
this.writeU8(0xcc);
|
|
3109
|
+
this.writeU8(object);
|
|
3110
|
+
}
|
|
3111
|
+
else if (object < 0x10000) {
|
|
3112
|
+
// uint 16
|
|
3113
|
+
this.writeU8(0xcd);
|
|
3114
|
+
this.writeU16(object);
|
|
3115
|
+
}
|
|
3116
|
+
else if (object < 0x100000000) {
|
|
3117
|
+
// uint 32
|
|
3118
|
+
this.writeU8(0xce);
|
|
3119
|
+
this.writeU32(object);
|
|
3120
|
+
}
|
|
3121
|
+
else {
|
|
3122
|
+
// uint 64
|
|
3123
|
+
this.writeU8(0xcf);
|
|
3124
|
+
this.writeU64(object);
|
|
3125
|
+
}
|
|
3126
|
+
}
|
|
3127
|
+
else {
|
|
3128
|
+
if (object >= -32) {
|
|
3129
|
+
// negative fixint
|
|
3130
|
+
this.writeU8(0xe0 | (object + 0x20));
|
|
3131
|
+
}
|
|
3132
|
+
else if (object >= -128) {
|
|
3133
|
+
// int 8
|
|
3134
|
+
this.writeU8(0xd0);
|
|
3135
|
+
this.writeI8(object);
|
|
3136
|
+
}
|
|
3137
|
+
else if (object >= -32768) {
|
|
3138
|
+
// int 16
|
|
3139
|
+
this.writeU8(0xd1);
|
|
3140
|
+
this.writeI16(object);
|
|
3141
|
+
}
|
|
3142
|
+
else if (object >= -2147483648) {
|
|
3143
|
+
// int 32
|
|
3144
|
+
this.writeU8(0xd2);
|
|
3145
|
+
this.writeI32(object);
|
|
3146
|
+
}
|
|
3147
|
+
else {
|
|
3148
|
+
// int 64
|
|
3149
|
+
this.writeU8(0xd3);
|
|
3150
|
+
this.writeI64(object);
|
|
3151
|
+
}
|
|
3152
|
+
}
|
|
3153
|
+
}
|
|
3154
|
+
else {
|
|
3155
|
+
// non-integer numbers
|
|
3156
|
+
if (this.forceFloat32) {
|
|
3157
|
+
// float 32
|
|
3158
|
+
this.writeU8(0xca);
|
|
3159
|
+
this.writeF32(object);
|
|
3160
|
+
}
|
|
3161
|
+
else {
|
|
3162
|
+
// float 64
|
|
3163
|
+
this.writeU8(0xcb);
|
|
3164
|
+
this.writeF64(object);
|
|
3165
|
+
}
|
|
3166
|
+
}
|
|
3167
|
+
};
|
|
3168
|
+
Encoder.prototype.writeStringHeader = function (byteLength) {
|
|
3169
|
+
if (byteLength < 32) {
|
|
3170
|
+
// fixstr
|
|
3171
|
+
this.writeU8(0xa0 + byteLength);
|
|
3172
|
+
}
|
|
3173
|
+
else if (byteLength < 0x100) {
|
|
3174
|
+
// str 8
|
|
3175
|
+
this.writeU8(0xd9);
|
|
3176
|
+
this.writeU8(byteLength);
|
|
3177
|
+
}
|
|
3178
|
+
else if (byteLength < 0x10000) {
|
|
3179
|
+
// str 16
|
|
3180
|
+
this.writeU8(0xda);
|
|
3181
|
+
this.writeU16(byteLength);
|
|
3182
|
+
}
|
|
3183
|
+
else if (byteLength < 0x100000000) {
|
|
3184
|
+
// str 32
|
|
3185
|
+
this.writeU8(0xdb);
|
|
3186
|
+
this.writeU32(byteLength);
|
|
3187
|
+
}
|
|
3188
|
+
else {
|
|
3189
|
+
throw new Error("Too long string: ".concat(byteLength, " bytes in UTF-8"));
|
|
3190
|
+
}
|
|
3191
|
+
};
|
|
3192
|
+
Encoder.prototype.encodeString = function (object) {
|
|
3193
|
+
var maxHeaderSize = 1 + 4;
|
|
3194
|
+
var strLength = object.length;
|
|
3195
|
+
if (strLength > TEXT_ENCODER_THRESHOLD) {
|
|
3196
|
+
var byteLength = utf8Count(object);
|
|
3197
|
+
this.ensureBufferSizeToWrite(maxHeaderSize + byteLength);
|
|
3198
|
+
this.writeStringHeader(byteLength);
|
|
3199
|
+
utf8EncodeTE(object, this.bytes, this.pos);
|
|
3200
|
+
this.pos += byteLength;
|
|
3201
|
+
}
|
|
3202
|
+
else {
|
|
3203
|
+
var byteLength = utf8Count(object);
|
|
3204
|
+
this.ensureBufferSizeToWrite(maxHeaderSize + byteLength);
|
|
3205
|
+
this.writeStringHeader(byteLength);
|
|
3206
|
+
utf8EncodeJs(object, this.bytes, this.pos);
|
|
3207
|
+
this.pos += byteLength;
|
|
3208
|
+
}
|
|
3209
|
+
};
|
|
3210
|
+
Encoder.prototype.encodeObject = function (object, depth) {
|
|
3211
|
+
// try to encode objects with custom codec first of non-primitives
|
|
3212
|
+
var ext = this.extensionCodec.tryToEncode(object, this.context);
|
|
3213
|
+
if (ext != null) {
|
|
3214
|
+
this.encodeExtension(ext);
|
|
3215
|
+
}
|
|
3216
|
+
else if (Array.isArray(object)) {
|
|
3217
|
+
this.encodeArray(object, depth);
|
|
3218
|
+
}
|
|
3219
|
+
else if (ArrayBuffer.isView(object)) {
|
|
3220
|
+
this.encodeBinary(object);
|
|
3221
|
+
}
|
|
3222
|
+
else if (typeof object === "object") {
|
|
3223
|
+
this.encodeMap(object, depth);
|
|
3224
|
+
}
|
|
3225
|
+
else {
|
|
3226
|
+
// symbol, function and other special object come here unless extensionCodec handles them.
|
|
3227
|
+
throw new Error("Unrecognized object: ".concat(Object.prototype.toString.apply(object)));
|
|
3228
|
+
}
|
|
3229
|
+
};
|
|
3230
|
+
Encoder.prototype.encodeBinary = function (object) {
|
|
3231
|
+
var size = object.byteLength;
|
|
3232
|
+
if (size < 0x100) {
|
|
3233
|
+
// bin 8
|
|
3234
|
+
this.writeU8(0xc4);
|
|
3235
|
+
this.writeU8(size);
|
|
3236
|
+
}
|
|
3237
|
+
else if (size < 0x10000) {
|
|
3238
|
+
// bin 16
|
|
3239
|
+
this.writeU8(0xc5);
|
|
3240
|
+
this.writeU16(size);
|
|
3241
|
+
}
|
|
3242
|
+
else if (size < 0x100000000) {
|
|
3243
|
+
// bin 32
|
|
3244
|
+
this.writeU8(0xc6);
|
|
3245
|
+
this.writeU32(size);
|
|
3246
|
+
}
|
|
3247
|
+
else {
|
|
3248
|
+
throw new Error("Too large binary: ".concat(size));
|
|
3249
|
+
}
|
|
3250
|
+
var bytes = ensureUint8Array(object);
|
|
3251
|
+
this.writeU8a(bytes);
|
|
3252
|
+
};
|
|
3253
|
+
Encoder.prototype.encodeArray = function (object, depth) {
|
|
3254
|
+
var size = object.length;
|
|
3255
|
+
if (size < 16) {
|
|
3256
|
+
// fixarray
|
|
3257
|
+
this.writeU8(0x90 + size);
|
|
3258
|
+
}
|
|
3259
|
+
else if (size < 0x10000) {
|
|
3260
|
+
// array 16
|
|
3261
|
+
this.writeU8(0xdc);
|
|
3262
|
+
this.writeU16(size);
|
|
3263
|
+
}
|
|
3264
|
+
else if (size < 0x100000000) {
|
|
3265
|
+
// array 32
|
|
3266
|
+
this.writeU8(0xdd);
|
|
3267
|
+
this.writeU32(size);
|
|
3268
|
+
}
|
|
3269
|
+
else {
|
|
3270
|
+
throw new Error("Too large array: ".concat(size));
|
|
3271
|
+
}
|
|
3272
|
+
for (var _i = 0, object_1 = object; _i < object_1.length; _i++) {
|
|
3273
|
+
var item = object_1[_i];
|
|
3274
|
+
this.doEncode(item, depth + 1);
|
|
3275
|
+
}
|
|
3276
|
+
};
|
|
3277
|
+
Encoder.prototype.countWithoutUndefined = function (object, keys) {
|
|
3278
|
+
var count = 0;
|
|
3279
|
+
for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
|
|
3280
|
+
var key = keys_1[_i];
|
|
3281
|
+
if (object[key] !== undefined) {
|
|
3282
|
+
count++;
|
|
3283
|
+
}
|
|
3284
|
+
}
|
|
3285
|
+
return count;
|
|
3286
|
+
};
|
|
3287
|
+
Encoder.prototype.encodeMap = function (object, depth) {
|
|
3288
|
+
var keys = Object.keys(object);
|
|
3289
|
+
if (this.sortKeys) {
|
|
3290
|
+
keys.sort();
|
|
3291
|
+
}
|
|
3292
|
+
var size = this.ignoreUndefined ? this.countWithoutUndefined(object, keys) : keys.length;
|
|
3293
|
+
if (size < 16) {
|
|
3294
|
+
// fixmap
|
|
3295
|
+
this.writeU8(0x80 + size);
|
|
3296
|
+
}
|
|
3297
|
+
else if (size < 0x10000) {
|
|
3298
|
+
// map 16
|
|
3299
|
+
this.writeU8(0xde);
|
|
3300
|
+
this.writeU16(size);
|
|
3301
|
+
}
|
|
3302
|
+
else if (size < 0x100000000) {
|
|
3303
|
+
// map 32
|
|
3304
|
+
this.writeU8(0xdf);
|
|
3305
|
+
this.writeU32(size);
|
|
3306
|
+
}
|
|
3307
|
+
else {
|
|
3308
|
+
throw new Error("Too large map object: ".concat(size));
|
|
3309
|
+
}
|
|
3310
|
+
for (var _i = 0, keys_2 = keys; _i < keys_2.length; _i++) {
|
|
3311
|
+
var key = keys_2[_i];
|
|
3312
|
+
var value = object[key];
|
|
3313
|
+
if (!(this.ignoreUndefined && value === undefined)) {
|
|
3314
|
+
this.encodeString(key);
|
|
3315
|
+
this.doEncode(value, depth + 1);
|
|
3316
|
+
}
|
|
3317
|
+
}
|
|
3318
|
+
};
|
|
3319
|
+
Encoder.prototype.encodeExtension = function (ext) {
|
|
3320
|
+
var size = ext.data.length;
|
|
3321
|
+
if (size === 1) {
|
|
3322
|
+
// fixext 1
|
|
3323
|
+
this.writeU8(0xd4);
|
|
3324
|
+
}
|
|
3325
|
+
else if (size === 2) {
|
|
3326
|
+
// fixext 2
|
|
3327
|
+
this.writeU8(0xd5);
|
|
3328
|
+
}
|
|
3329
|
+
else if (size === 4) {
|
|
3330
|
+
// fixext 4
|
|
3331
|
+
this.writeU8(0xd6);
|
|
3332
|
+
}
|
|
3333
|
+
else if (size === 8) {
|
|
3334
|
+
// fixext 8
|
|
3335
|
+
this.writeU8(0xd7);
|
|
3336
|
+
}
|
|
3337
|
+
else if (size === 16) {
|
|
3338
|
+
// fixext 16
|
|
3339
|
+
this.writeU8(0xd8);
|
|
3340
|
+
}
|
|
3341
|
+
else if (size < 0x100) {
|
|
3342
|
+
// ext 8
|
|
3343
|
+
this.writeU8(0xc7);
|
|
3344
|
+
this.writeU8(size);
|
|
3345
|
+
}
|
|
3346
|
+
else if (size < 0x10000) {
|
|
3347
|
+
// ext 16
|
|
3348
|
+
this.writeU8(0xc8);
|
|
3349
|
+
this.writeU16(size);
|
|
3350
|
+
}
|
|
3351
|
+
else if (size < 0x100000000) {
|
|
3352
|
+
// ext 32
|
|
3353
|
+
this.writeU8(0xc9);
|
|
3354
|
+
this.writeU32(size);
|
|
3355
|
+
}
|
|
3356
|
+
else {
|
|
3357
|
+
throw new Error("Too large extension object: ".concat(size));
|
|
3358
|
+
}
|
|
3359
|
+
this.writeI8(ext.type);
|
|
3360
|
+
this.writeU8a(ext.data);
|
|
3361
|
+
};
|
|
3362
|
+
Encoder.prototype.writeU8 = function (value) {
|
|
3363
|
+
this.ensureBufferSizeToWrite(1);
|
|
3364
|
+
this.view.setUint8(this.pos, value);
|
|
3365
|
+
this.pos++;
|
|
3366
|
+
};
|
|
3367
|
+
Encoder.prototype.writeU8a = function (values) {
|
|
3368
|
+
var size = values.length;
|
|
3369
|
+
this.ensureBufferSizeToWrite(size);
|
|
3370
|
+
this.bytes.set(values, this.pos);
|
|
3371
|
+
this.pos += size;
|
|
3372
|
+
};
|
|
3373
|
+
Encoder.prototype.writeI8 = function (value) {
|
|
3374
|
+
this.ensureBufferSizeToWrite(1);
|
|
3375
|
+
this.view.setInt8(this.pos, value);
|
|
3376
|
+
this.pos++;
|
|
3377
|
+
};
|
|
3378
|
+
Encoder.prototype.writeU16 = function (value) {
|
|
3379
|
+
this.ensureBufferSizeToWrite(2);
|
|
3380
|
+
this.view.setUint16(this.pos, value);
|
|
3381
|
+
this.pos += 2;
|
|
3382
|
+
};
|
|
3383
|
+
Encoder.prototype.writeI16 = function (value) {
|
|
3384
|
+
this.ensureBufferSizeToWrite(2);
|
|
3385
|
+
this.view.setInt16(this.pos, value);
|
|
3386
|
+
this.pos += 2;
|
|
3387
|
+
};
|
|
3388
|
+
Encoder.prototype.writeU32 = function (value) {
|
|
3389
|
+
this.ensureBufferSizeToWrite(4);
|
|
3390
|
+
this.view.setUint32(this.pos, value);
|
|
3391
|
+
this.pos += 4;
|
|
3392
|
+
};
|
|
3393
|
+
Encoder.prototype.writeI32 = function (value) {
|
|
3394
|
+
this.ensureBufferSizeToWrite(4);
|
|
3395
|
+
this.view.setInt32(this.pos, value);
|
|
3396
|
+
this.pos += 4;
|
|
3397
|
+
};
|
|
3398
|
+
Encoder.prototype.writeF32 = function (value) {
|
|
3399
|
+
this.ensureBufferSizeToWrite(4);
|
|
3400
|
+
this.view.setFloat32(this.pos, value);
|
|
3401
|
+
this.pos += 4;
|
|
3402
|
+
};
|
|
3403
|
+
Encoder.prototype.writeF64 = function (value) {
|
|
3404
|
+
this.ensureBufferSizeToWrite(8);
|
|
3405
|
+
this.view.setFloat64(this.pos, value);
|
|
3406
|
+
this.pos += 8;
|
|
3407
|
+
};
|
|
3408
|
+
Encoder.prototype.writeU64 = function (value) {
|
|
3409
|
+
this.ensureBufferSizeToWrite(8);
|
|
3410
|
+
setUint64(this.view, this.pos, value);
|
|
3411
|
+
this.pos += 8;
|
|
3412
|
+
};
|
|
3413
|
+
Encoder.prototype.writeI64 = function (value) {
|
|
3414
|
+
this.ensureBufferSizeToWrite(8);
|
|
3415
|
+
setInt64(this.view, this.pos, value);
|
|
3416
|
+
this.pos += 8;
|
|
3417
|
+
};
|
|
3418
|
+
return Encoder;
|
|
3419
|
+
}());
|
|
3420
|
+
|
|
3421
|
+
var defaultEncodeOptions = {};
|
|
3422
|
+
/**
|
|
3423
|
+
* It encodes `value` in the MessagePack format and
|
|
3424
|
+
* returns a byte buffer.
|
|
3425
|
+
*
|
|
3426
|
+
* The returned buffer is a slice of a larger `ArrayBuffer`, so you have to use its `#byteOffset` and `#byteLength` in order to convert it to another typed arrays including NodeJS `Buffer`.
|
|
3427
|
+
*/
|
|
3428
|
+
function encode(value, options) {
|
|
3429
|
+
if (options === void 0) { options = defaultEncodeOptions; }
|
|
3430
|
+
var encoder = new Encoder(options.extensionCodec, options.context, options.maxDepth, options.initialBufferSize, options.sortKeys, options.forceFloat32, options.ignoreUndefined, options.forceIntegerToFloat);
|
|
3431
|
+
return encoder.encodeSharedRef(value);
|
|
3432
|
+
}
|
|
3433
|
+
|
|
2920
3434
|
function prettyByte(byte) {
|
|
2921
3435
|
return "".concat(byte < 0 ? "-" : "", "0x").concat(Math.abs(byte).toString(16).padStart(2, "0"));
|
|
2922
3436
|
}
|
|
@@ -3724,6 +4238,13 @@ function decode(buffer, options) {
|
|
|
3724
4238
|
return decoder.decode(buffer);
|
|
3725
4239
|
}
|
|
3726
4240
|
|
|
4241
|
+
/** 校验公开启动扩展数据,并保持调用方传入的值语义不变。 */
|
|
4242
|
+
function normalizeMiniProgramShareExtra(value) {
|
|
4243
|
+
assertExtraValue(value);
|
|
4244
|
+
if (encode(value).byteLength > 128)
|
|
4245
|
+
throw new Error('extra is too large');
|
|
4246
|
+
return value;
|
|
4247
|
+
}
|
|
3727
4248
|
/** 读取小程序启动时携带的分享数据。 */
|
|
3728
4249
|
function readMiniProgramShareExtra(launchHref) {
|
|
3729
4250
|
if (!launchHref)
|
|
@@ -3770,11 +4291,14 @@ function assertExtraValue(value, depth = 0, seen = new WeakSet()) {
|
|
|
3770
4291
|
const prototype = Object.getPrototypeOf(value);
|
|
3771
4292
|
if (prototype !== Object.prototype && prototype !== null)
|
|
3772
4293
|
throw new Error('extra object must be a plain object');
|
|
3773
|
-
const
|
|
3774
|
-
if (
|
|
4294
|
+
const entries = Object.entries(value);
|
|
4295
|
+
if (entries.length > 64)
|
|
3775
4296
|
throw new Error('extra object has too many fields');
|
|
3776
|
-
for (const item of
|
|
4297
|
+
for (const [key, item] of entries) {
|
|
4298
|
+
if (key === '__proto__')
|
|
4299
|
+
throw new Error('extra object key is not supported');
|
|
3777
4300
|
assertExtraValue(item, depth + 1, seen);
|
|
4301
|
+
}
|
|
3778
4302
|
seen.delete(value);
|
|
3779
4303
|
}
|
|
3780
4304
|
function decodeBase64Url(value) {
|
|
@@ -4568,10 +5092,27 @@ function normalizeOpenAppPageOptions(options) {
|
|
|
4568
5092
|
return normalizeUserDetailOptions(options);
|
|
4569
5093
|
case 'post_detail':
|
|
4570
5094
|
return normalizePostDetailOptions(options);
|
|
5095
|
+
case 'mini_program':
|
|
5096
|
+
return normalizeMiniProgramOptions(options);
|
|
4571
5097
|
default:
|
|
4572
5098
|
throw createSDKError('INVALID_PARAMS', 'navigation.openAppPage target 不支持');
|
|
4573
5099
|
}
|
|
4574
5100
|
}
|
|
5101
|
+
function normalizeMiniProgramOptions(options) {
|
|
5102
|
+
const payload = {
|
|
5103
|
+
target: 'mini_program',
|
|
5104
|
+
miniProgramId: readRequiredString(options.miniProgramId, 'navigation.openAppPage miniProgramId 必须是非空字符串'),
|
|
5105
|
+
};
|
|
5106
|
+
if (options.extra !== undefined) {
|
|
5107
|
+
try {
|
|
5108
|
+
payload.extra = normalizeMiniProgramShareExtra(options.extra);
|
|
5109
|
+
}
|
|
5110
|
+
catch {
|
|
5111
|
+
throw createSDKError('INVALID_PARAMS', 'navigation.openAppPage extra 必须是符合限制的 JSON-compatible 数据');
|
|
5112
|
+
}
|
|
5113
|
+
}
|
|
5114
|
+
return payload;
|
|
5115
|
+
}
|
|
4575
5116
|
function normalizeGameDetailOptions(options) {
|
|
4576
5117
|
const appId = readRequiredStringLike(options.appId, 'navigation.openAppPage appId 必须是非空字符串或数字');
|
|
4577
5118
|
if (!GAME_DETAIL_GAME_TYPES.has(options.gameType)) {
|
|
@@ -4664,14 +5205,14 @@ function reload(requester) {
|
|
|
4664
5205
|
return requester.request(NAVIGATION_RELOAD_METHOD);
|
|
4665
5206
|
}
|
|
4666
5207
|
/**
|
|
4667
|
-
* 请求宿主打开受 SDK 白名单约束的黑盒 App
|
|
5208
|
+
* 请求宿主打开受 SDK 白名单约束的黑盒 App 页面或公开小程序。
|
|
4668
5209
|
*
|
|
4669
5210
|
* @param requester - 底层 bridge 请求能力。
|
|
4670
5211
|
* @param options - 由 `target` 判别的目标页参数;发送前会校验并规范化。
|
|
4671
5212
|
* @returns Host 发起受控页面路由后 resolve `undefined`。
|
|
4672
5213
|
* @throws {@link HbMiniProgramSDKError} 参数非法、目标不受 Host 支持、路由失败或 SDK /
|
|
4673
5214
|
* Runtime 已终止时抛出。
|
|
4674
|
-
* @remarks 该能力不接受任意 URL
|
|
5215
|
+
* @remarks 该能力不接受任意 URL、版本或内部路由,也无需 Manifest 权限或可信用户手势。
|
|
4675
5216
|
* @see [navigation.openAppPage](/reference/sdk/navigation/openAppPage)
|
|
4676
5217
|
*/
|
|
4677
5218
|
function openAppPage(requester, options) {
|