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