@base-web-kits/base-tools-web 1.3.3 → 1.3.6
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/dist/base-tools-web.umd.global.js +276 -13
- package/dist/base-tools-web.umd.global.js.map +1 -1
- package/dist/clipboard/index.d.ts.map +1 -1
- package/dist/index.cjs +282 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +57 -24
- package/dist/index.mjs +282 -19
- package/dist/index.mjs.map +1 -1
- package/dist/network/request.d.ts +29 -23
- package/dist/network/request.d.ts.map +1 -1
- package/package.json +30 -30
- package/src/web/clipboard/index.ts +0 -1
- package/src/web/network/request.ts +59 -34
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/web/clipboard/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAsB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/web/clipboard/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAsB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAgD1D;AAED;;;;;;GAMG;AACH,wBAAsB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAW1D;AAED;;;;;;;GAOG;AACH,wBAAsB,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAWxD;AAED;;;;;;;GAOG;AACH,wBAAsB,SAAS,CAAC,KAAK,EAAE,IAAI,GAAG,iBAAiB,GAAG,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAS5F;AAED;;;;;;GAMG;AACH,wBAAsB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAUxD;AAED;;;;;;;GAOG;AACH,wBAAsB,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAOxD;AAED;;;;;;GAMG;AACH,wBAAsB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBxD;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAsClF"}
|
package/dist/index.cjs
CHANGED
|
@@ -43,6 +43,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
43
43
|
mod
|
|
44
44
|
));
|
|
45
45
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
46
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
46
47
|
var __async = (__this, __arguments, generator) => {
|
|
47
48
|
return new Promise((resolve, reject) => {
|
|
48
49
|
var fulfilled = (value) => {
|
|
@@ -857,12 +858,12 @@ function isUnsafeProperty(key) {
|
|
|
857
858
|
|
|
858
859
|
// src/ts/day/index.ts
|
|
859
860
|
var import_dayjs = __toESM(require("dayjs"), 1);
|
|
860
|
-
var import_customParseFormat = __toESM(require("dayjs/plugin/customParseFormat"), 1);
|
|
861
|
-
var import_utc = __toESM(require("dayjs/plugin/utc"), 1);
|
|
862
|
-
var import_timezone = __toESM(require("dayjs/plugin/timezone"), 1);
|
|
863
|
-
var import_relativeTime = __toESM(require("dayjs/plugin/relativeTime"), 1);
|
|
864
|
-
var import_advancedFormat = __toESM(require("dayjs/plugin/advancedFormat"), 1);
|
|
865
|
-
var import_zh_cn = require("dayjs/locale/zh-cn");
|
|
861
|
+
var import_customParseFormat = __toESM(require("dayjs/plugin/customParseFormat.js"), 1);
|
|
862
|
+
var import_utc = __toESM(require("dayjs/plugin/utc.js"), 1);
|
|
863
|
+
var import_timezone = __toESM(require("dayjs/plugin/timezone.js"), 1);
|
|
864
|
+
var import_relativeTime = __toESM(require("dayjs/plugin/relativeTime.js"), 1);
|
|
865
|
+
var import_advancedFormat = __toESM(require("dayjs/plugin/advancedFormat.js"), 1);
|
|
866
|
+
var import_zh_cn = require("dayjs/locale/zh-cn.js");
|
|
866
867
|
import_dayjs.default.extend(import_customParseFormat.default);
|
|
867
868
|
import_dayjs.default.extend(import_utc.default);
|
|
868
869
|
import_dayjs.default.extend(import_timezone.default);
|
|
@@ -1093,6 +1094,262 @@ function appendUrlParam(url, param) {
|
|
|
1093
1094
|
return base + (qs ? `?${qs}` : "") + hash;
|
|
1094
1095
|
}
|
|
1095
1096
|
|
|
1097
|
+
// src/ts/buffer/PolyfillTextDecoder.ts
|
|
1098
|
+
var PolyfillTextDecoder = class {
|
|
1099
|
+
constructor() {
|
|
1100
|
+
__publicField(this, "leftOver", new Uint8Array(0));
|
|
1101
|
+
}
|
|
1102
|
+
decode(input, options) {
|
|
1103
|
+
var _a;
|
|
1104
|
+
const stream = (_a = options == null ? void 0 : options.stream) != null ? _a : false;
|
|
1105
|
+
let bytes;
|
|
1106
|
+
if (!input) {
|
|
1107
|
+
bytes = new Uint8Array(0);
|
|
1108
|
+
} else if (input instanceof ArrayBuffer) {
|
|
1109
|
+
bytes = new Uint8Array(input);
|
|
1110
|
+
} else {
|
|
1111
|
+
bytes = input;
|
|
1112
|
+
}
|
|
1113
|
+
if (this.leftOver.length > 0) {
|
|
1114
|
+
const merged = new Uint8Array(this.leftOver.length + bytes.length);
|
|
1115
|
+
merged.set(this.leftOver);
|
|
1116
|
+
merged.set(bytes, this.leftOver.length);
|
|
1117
|
+
bytes = merged;
|
|
1118
|
+
this.leftOver = new Uint8Array(0);
|
|
1119
|
+
}
|
|
1120
|
+
const len = bytes.length;
|
|
1121
|
+
if (len === 0) return "";
|
|
1122
|
+
const parts = [];
|
|
1123
|
+
let i = 0;
|
|
1124
|
+
const replacement = "\uFFFD";
|
|
1125
|
+
const isContinuationByte = (b) => (b & 192) === 128;
|
|
1126
|
+
while (i < len) {
|
|
1127
|
+
const byte1 = bytes[i];
|
|
1128
|
+
if (byte1 < 128) {
|
|
1129
|
+
parts.push(String.fromCharCode(byte1));
|
|
1130
|
+
i += 1;
|
|
1131
|
+
} else if (byte1 >= 194 && byte1 < 224) {
|
|
1132
|
+
if (i + 1 >= len) {
|
|
1133
|
+
if (stream) {
|
|
1134
|
+
this.leftOver = bytes.slice(i);
|
|
1135
|
+
break;
|
|
1136
|
+
}
|
|
1137
|
+
parts.push(replacement);
|
|
1138
|
+
break;
|
|
1139
|
+
}
|
|
1140
|
+
const byte2 = bytes[i + 1];
|
|
1141
|
+
if (!isContinuationByte(byte2)) {
|
|
1142
|
+
parts.push(replacement);
|
|
1143
|
+
i += 1;
|
|
1144
|
+
continue;
|
|
1145
|
+
}
|
|
1146
|
+
parts.push(String.fromCharCode((byte1 & 31) << 6 | byte2 & 63));
|
|
1147
|
+
i += 2;
|
|
1148
|
+
} else if (byte1 >= 224 && byte1 < 240) {
|
|
1149
|
+
if (i + 2 >= len) {
|
|
1150
|
+
if (stream) {
|
|
1151
|
+
this.leftOver = bytes.slice(i);
|
|
1152
|
+
break;
|
|
1153
|
+
}
|
|
1154
|
+
parts.push(replacement);
|
|
1155
|
+
break;
|
|
1156
|
+
}
|
|
1157
|
+
const byte2 = bytes[i + 1];
|
|
1158
|
+
const byte3 = bytes[i + 2];
|
|
1159
|
+
if (!isContinuationByte(byte2) || !isContinuationByte(byte3)) {
|
|
1160
|
+
parts.push(replacement);
|
|
1161
|
+
i += 1;
|
|
1162
|
+
continue;
|
|
1163
|
+
}
|
|
1164
|
+
if (byte1 === 224 && byte2 < 160) {
|
|
1165
|
+
parts.push(replacement);
|
|
1166
|
+
i += 3;
|
|
1167
|
+
continue;
|
|
1168
|
+
}
|
|
1169
|
+
if (byte1 === 237 && byte2 >= 160) {
|
|
1170
|
+
parts.push(replacement);
|
|
1171
|
+
i += 3;
|
|
1172
|
+
continue;
|
|
1173
|
+
}
|
|
1174
|
+
const codeUnit = (byte1 & 15) << 12 | (byte2 & 63) << 6 | byte3 & 63;
|
|
1175
|
+
parts.push(String.fromCharCode(codeUnit));
|
|
1176
|
+
i += 3;
|
|
1177
|
+
} else if (byte1 >= 240 && byte1 <= 244) {
|
|
1178
|
+
if (i + 3 >= len) {
|
|
1179
|
+
if (stream) {
|
|
1180
|
+
this.leftOver = bytes.slice(i);
|
|
1181
|
+
break;
|
|
1182
|
+
}
|
|
1183
|
+
parts.push(replacement);
|
|
1184
|
+
break;
|
|
1185
|
+
}
|
|
1186
|
+
const byte2 = bytes[i + 1];
|
|
1187
|
+
const byte3 = bytes[i + 2];
|
|
1188
|
+
const byte4 = bytes[i + 3];
|
|
1189
|
+
if (!isContinuationByte(byte2) || !isContinuationByte(byte3) || !isContinuationByte(byte4)) {
|
|
1190
|
+
parts.push(replacement);
|
|
1191
|
+
i += 1;
|
|
1192
|
+
continue;
|
|
1193
|
+
}
|
|
1194
|
+
if (byte1 === 240 && byte2 < 144) {
|
|
1195
|
+
parts.push(replacement);
|
|
1196
|
+
i += 4;
|
|
1197
|
+
continue;
|
|
1198
|
+
}
|
|
1199
|
+
if (byte1 === 244 && byte2 >= 144) {
|
|
1200
|
+
parts.push(replacement);
|
|
1201
|
+
i += 4;
|
|
1202
|
+
continue;
|
|
1203
|
+
}
|
|
1204
|
+
const codepoint = (byte1 & 7) << 18 | (byte2 & 63) << 12 | (byte3 & 63) << 6 | byte4 & 63;
|
|
1205
|
+
const offset = codepoint - 65536;
|
|
1206
|
+
parts.push(String.fromCharCode(55296 + (offset >> 10), 56320 + (offset & 1023)));
|
|
1207
|
+
i += 4;
|
|
1208
|
+
} else {
|
|
1209
|
+
parts.push(replacement);
|
|
1210
|
+
i += 1;
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
return parts.join("");
|
|
1214
|
+
}
|
|
1215
|
+
};
|
|
1216
|
+
var PolyfillTextDecoder_default = PolyfillTextDecoder;
|
|
1217
|
+
|
|
1218
|
+
// src/ts/buffer/SSEParser.ts
|
|
1219
|
+
var SSEParser = class {
|
|
1220
|
+
constructor(onMessage) {
|
|
1221
|
+
__publicField(this, "buffer", "");
|
|
1222
|
+
__publicField(this, "onMessage");
|
|
1223
|
+
__publicField(this, "decoder");
|
|
1224
|
+
__publicField(this, "eventDataLines", []);
|
|
1225
|
+
__publicField(this, "eventType");
|
|
1226
|
+
__publicField(this, "eventId");
|
|
1227
|
+
__publicField(this, "eventRetry");
|
|
1228
|
+
this.onMessage = onMessage;
|
|
1229
|
+
this.decoder = typeof TextDecoder !== "undefined" ? new TextDecoder("utf-8") : new PolyfillTextDecoder_default();
|
|
1230
|
+
}
|
|
1231
|
+
/**
|
|
1232
|
+
* 接收流式数据
|
|
1233
|
+
* @param buffer ArrayBuffer
|
|
1234
|
+
*/
|
|
1235
|
+
receive(buffer) {
|
|
1236
|
+
const text = this.decoder.decode(new Uint8Array(buffer), { stream: true });
|
|
1237
|
+
this.appendText(text);
|
|
1238
|
+
}
|
|
1239
|
+
/**
|
|
1240
|
+
* 刷新解码器残留数据并处理尾部未换行的内容
|
|
1241
|
+
*/
|
|
1242
|
+
flush() {
|
|
1243
|
+
const tail = this.decoder.decode(void 0, { stream: false });
|
|
1244
|
+
if (tail) this.appendText(tail);
|
|
1245
|
+
this.flushRemainder();
|
|
1246
|
+
}
|
|
1247
|
+
/**
|
|
1248
|
+
* 追加文本并按行拆分处理,保留不完整尾行
|
|
1249
|
+
* @param text 新到达的文本片段
|
|
1250
|
+
*/
|
|
1251
|
+
appendText(text) {
|
|
1252
|
+
this.buffer += text;
|
|
1253
|
+
const lines = this.buffer.split(/\r?\n/);
|
|
1254
|
+
this.buffer = lines.pop() || "";
|
|
1255
|
+
this.processLines(lines);
|
|
1256
|
+
}
|
|
1257
|
+
/**
|
|
1258
|
+
* 处理缓冲区中剩余的尾行内容
|
|
1259
|
+
*/
|
|
1260
|
+
flushRemainder() {
|
|
1261
|
+
if (!this.buffer.trim()) {
|
|
1262
|
+
this.buffer = "";
|
|
1263
|
+
return;
|
|
1264
|
+
}
|
|
1265
|
+
const rest = this.buffer;
|
|
1266
|
+
this.buffer = "";
|
|
1267
|
+
this.processLines([rest, ""]);
|
|
1268
|
+
}
|
|
1269
|
+
/**
|
|
1270
|
+
* 解析每行 SSE 数据并触发回调
|
|
1271
|
+
* @param lines 以换行切分后的行内容
|
|
1272
|
+
*/
|
|
1273
|
+
processLines(lines) {
|
|
1274
|
+
for (const line of lines) {
|
|
1275
|
+
if (!line.trim()) {
|
|
1276
|
+
this.dispatchEvent();
|
|
1277
|
+
continue;
|
|
1278
|
+
}
|
|
1279
|
+
if (line.startsWith(":")) continue;
|
|
1280
|
+
const colonIndex = line.indexOf(":");
|
|
1281
|
+
const field = colonIndex === -1 ? line : line.slice(0, colonIndex);
|
|
1282
|
+
let value = colonIndex === -1 ? "" : line.slice(colonIndex + 1);
|
|
1283
|
+
if (value.startsWith(" ")) value = value.slice(1);
|
|
1284
|
+
if (field === "data") {
|
|
1285
|
+
this.eventDataLines.push(value);
|
|
1286
|
+
continue;
|
|
1287
|
+
}
|
|
1288
|
+
if (field === "event") {
|
|
1289
|
+
this.eventType = value || void 0;
|
|
1290
|
+
continue;
|
|
1291
|
+
}
|
|
1292
|
+
if (field === "id") {
|
|
1293
|
+
this.eventId = value || void 0;
|
|
1294
|
+
continue;
|
|
1295
|
+
}
|
|
1296
|
+
if (field === "retry") {
|
|
1297
|
+
const retry = Number(value);
|
|
1298
|
+
this.eventRetry = Number.isFinite(retry) ? retry : void 0;
|
|
1299
|
+
continue;
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
/**
|
|
1304
|
+
* 将当前缓存的一次 SSE 事件分发给回调
|
|
1305
|
+
* @description 以空行作为事件边界,将多行 data 合并后再解析;处理 "[DONE]" 结束标记;分发完成后会重置事件缓存
|
|
1306
|
+
*/
|
|
1307
|
+
dispatchEvent() {
|
|
1308
|
+
if (!this.eventDataLines.length) {
|
|
1309
|
+
this.resetEvent();
|
|
1310
|
+
return;
|
|
1311
|
+
}
|
|
1312
|
+
const data = this.eventDataLines.join("\n");
|
|
1313
|
+
if (!data) {
|
|
1314
|
+
this.resetEvent();
|
|
1315
|
+
return;
|
|
1316
|
+
}
|
|
1317
|
+
if (data.trim() === "[DONE]") {
|
|
1318
|
+
this.safeOnMessage({ type: "DONE" });
|
|
1319
|
+
this.resetEvent();
|
|
1320
|
+
return;
|
|
1321
|
+
}
|
|
1322
|
+
let msg;
|
|
1323
|
+
try {
|
|
1324
|
+
const json = JSON.parse(data);
|
|
1325
|
+
msg = isPlainObject(json) ? json : { data: json };
|
|
1326
|
+
} catch (e) {
|
|
1327
|
+
msg = { raw: data };
|
|
1328
|
+
}
|
|
1329
|
+
if (this.eventType && msg.event === void 0) msg.event = this.eventType;
|
|
1330
|
+
if (this.eventType && msg.type === void 0) msg.type = this.eventType;
|
|
1331
|
+
if (this.eventId && msg.id === void 0) msg.id = this.eventId;
|
|
1332
|
+
if (this.eventRetry !== void 0 && msg.retry === void 0) msg.retry = this.eventRetry;
|
|
1333
|
+
this.safeOnMessage(msg);
|
|
1334
|
+
this.resetEvent();
|
|
1335
|
+
}
|
|
1336
|
+
/** 安全调用 onMessage 回调,捕获并打印错误 */
|
|
1337
|
+
safeOnMessage(msg) {
|
|
1338
|
+
try {
|
|
1339
|
+
this.onMessage(msg);
|
|
1340
|
+
} catch (onMessageError) {
|
|
1341
|
+
console.error("SSEParser onMessage error:", onMessageError);
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
/** 重置当前 SSE 事件的临时缓存 */
|
|
1345
|
+
resetEvent() {
|
|
1346
|
+
this.eventDataLines = [];
|
|
1347
|
+
this.eventType = void 0;
|
|
1348
|
+
this.eventId = void 0;
|
|
1349
|
+
this.eventRetry = void 0;
|
|
1350
|
+
}
|
|
1351
|
+
};
|
|
1352
|
+
|
|
1096
1353
|
// src/web/network/request.ts
|
|
1097
1354
|
var requestCache = /* @__PURE__ */ new Map();
|
|
1098
1355
|
function request(config) {
|
|
@@ -1114,18 +1371,16 @@ function request(config) {
|
|
|
1114
1371
|
resMap,
|
|
1115
1372
|
responseType = "json",
|
|
1116
1373
|
timeout = 6e4,
|
|
1117
|
-
onTaskReady
|
|
1374
|
+
onTaskReady,
|
|
1375
|
+
onMessage
|
|
1118
1376
|
} = config;
|
|
1119
1377
|
const controller = new AbortController();
|
|
1120
1378
|
const signal = controller.signal;
|
|
1121
|
-
|
|
1379
|
+
const sseTask = { parser: onMessage ? new SSEParser(onMessage) : void 0 };
|
|
1122
1380
|
const task = {
|
|
1123
|
-
abort: () =>
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
},
|
|
1127
|
-
offChunkReceived: () => {
|
|
1128
|
-
chunkCallback = null;
|
|
1381
|
+
abort: () => {
|
|
1382
|
+
sseTask.parser = null;
|
|
1383
|
+
controller.abort();
|
|
1129
1384
|
}
|
|
1130
1385
|
};
|
|
1131
1386
|
onTaskReady == null ? void 0 : onTaskReady(task);
|
|
@@ -1197,7 +1452,7 @@ function request(config) {
|
|
|
1197
1452
|
}
|
|
1198
1453
|
if (enableChunked) {
|
|
1199
1454
|
if (showLoading) (_c = appConfig2.hideLoading) == null ? void 0 : _c.call(appConfig2);
|
|
1200
|
-
const res2 = yield handleStreamResponse(response,
|
|
1455
|
+
const res2 = yield handleStreamResponse(response, sseTask);
|
|
1201
1456
|
logRequestInfo({ status: "success", config: logConfig, startTime, res: res2 });
|
|
1202
1457
|
resolve(res2);
|
|
1203
1458
|
return;
|
|
@@ -1298,17 +1553,25 @@ function checkCache(cacheKey) {
|
|
|
1298
1553
|
}
|
|
1299
1554
|
return cached.res;
|
|
1300
1555
|
}
|
|
1301
|
-
function handleStreamResponse(response,
|
|
1556
|
+
function handleStreamResponse(response, sseTask) {
|
|
1302
1557
|
return __async(this, null, function* () {
|
|
1303
1558
|
if (!response.body) throw new Error("Response body is null");
|
|
1559
|
+
if (sseTask.parser === void 0) {
|
|
1560
|
+
throw new Error(
|
|
1561
|
+
"Stream parser missing: Please set config.onMessage when enableChunked is true"
|
|
1562
|
+
);
|
|
1563
|
+
}
|
|
1304
1564
|
const reader = response.body.getReader();
|
|
1305
1565
|
while (true) {
|
|
1306
1566
|
const { done, value } = yield reader.read();
|
|
1307
|
-
if (
|
|
1308
|
-
|
|
1309
|
-
|
|
1567
|
+
if (sseTask.parser === null) {
|
|
1568
|
+
yield reader.cancel();
|
|
1569
|
+
throw new DOMException("BodyStreamBuffer was aborted", "AbortError");
|
|
1310
1570
|
}
|
|
1571
|
+
if (done) break;
|
|
1572
|
+
if (sseTask.parser && value) sseTask.parser.receive(value.buffer);
|
|
1311
1573
|
}
|
|
1574
|
+
if (sseTask.parser) sseTask.parser.flush();
|
|
1312
1575
|
return "Stream Finished";
|
|
1313
1576
|
});
|
|
1314
1577
|
}
|