@whitesev/utils 2.3.2 → 2.3.4

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.
@@ -1758,6 +1758,8 @@ System.register('Utils', [], (function (exports) {
1758
1758
  data: details.data || this.context.#defaultDetails.data,
1759
1759
  redirect: details.redirect || this.context.#defaultDetails.redirect,
1760
1760
  cookie: details.cookie || this.context.#defaultDetails.cookie,
1761
+ cookiePartition: details.cookiePartition ||
1762
+ this.context.#defaultDetails.cookiePartition,
1761
1763
  binary: details.binary || this.context.#defaultDetails.binary,
1762
1764
  nocache: details.nocache || this.context.#defaultDetails.nocache,
1763
1765
  revalidate: details.revalidate || this.context.#defaultDetails.revalidate,
@@ -1859,6 +1861,15 @@ System.register('Utils', [], (function (exports) {
1859
1861
  else {
1860
1862
  result.fetchInit = details.fetchInit;
1861
1863
  }
1864
+ // 处理新的cookiePartition
1865
+ if (typeof result.cookiePartition === "object" &&
1866
+ result.cookiePartition != null) {
1867
+ if (Reflect.has(result.cookiePartition, "topLevelSite") &&
1868
+ typeof result.cookiePartition.topLevelSite !== "string") {
1869
+ // topLevelSite必须是字符串
1870
+ Reflect.deleteProperty(result.cookiePartition, "topLevelSite");
1871
+ }
1872
+ }
1862
1873
  return result;
1863
1874
  },
1864
1875
  /**
@@ -2348,6 +2359,7 @@ System.register('Utils', [], (function (exports) {
2348
2359
  data: void 0,
2349
2360
  redirect: void 0,
2350
2361
  cookie: void 0,
2362
+ cookiePartition: void 0,
2351
2363
  binary: void 0,
2352
2364
  nocache: void 0,
2353
2365
  revalidate: void 0,
@@ -3107,6 +3119,9 @@ System.register('Utils', [], (function (exports) {
3107
3119
  autoClearConsole: false,
3108
3120
  logMaxCount: 999,
3109
3121
  };
3122
+ /**
3123
+ * 颜色配置
3124
+ */
3110
3125
  #msgColorDetails = [
3111
3126
  "font-weight: bold; color: cornflowerblue",
3112
3127
  "font-weight: bold; color: cornflowerblue",
@@ -3114,16 +3129,16 @@ System.register('Utils', [], (function (exports) {
3114
3129
  "font-weight: bold; color: cornflowerblue",
3115
3130
  ];
3116
3131
  /**
3117
- * @param _GM_info_ 油猴管理器的API GM_info,或者是一个对象,如{"script":{name:"Utils.Log"}},或者直接是一个字符串
3132
+ * @param __GM_info 油猴管理器的API GM_info,或者是一个对象,如{"script":{name:"Utils.Log"}},或者直接是一个字符串,用作tag名
3118
3133
  * @param console 可指定console对象为unsafeWindow下的console或者是油猴window下的console
3119
3134
  */
3120
- constructor(_GM_info_, console = window.console) {
3121
- if (typeof _GM_info_ === "string") {
3122
- this.tag = _GM_info_;
3135
+ constructor(__GM_info, console = window.console) {
3136
+ if (typeof __GM_info === "string") {
3137
+ this.tag = __GM_info;
3123
3138
  }
3124
- else if (typeof _GM_info_ === "object" &&
3125
- typeof _GM_info_?.script?.name === "string") {
3126
- this.tag = _GM_info_.script.name;
3139
+ else if (typeof __GM_info === "object" &&
3140
+ typeof __GM_info?.script?.name === "string") {
3141
+ this.tag = __GM_info.script.name;
3127
3142
  }
3128
3143
  this.#console = console;
3129
3144
  }
@@ -3198,24 +3213,33 @@ System.register('Utils', [], (function (exports) {
3198
3213
  let { name: callerName, position: callerPosition } = this.parseErrorStack(stackSplit);
3199
3214
  let tagName = this.tag;
3200
3215
  let that = this;
3201
- function consoleMsg(_msg_) {
3202
- if (typeof _msg_ === "string") {
3203
- that.#console.log(`%c[${tagName}%c-%c${callerName}%c]%c %s`, ...that.#msgColorDetails, `color: ${color};${otherStyle}`, _msg_);
3216
+ /** tag的html输出格式 */
3217
+ let tagNameHTML = `%c[${tagName}%c`;
3218
+ /** 调用的函数名的html输出格式 */
3219
+ let callerNameHTML = `%c${callerName}%c]%c`;
3220
+ callerName.trim() !== "" && (callerNameHTML = "-" + callerNameHTML);
3221
+ /**
3222
+ * 输出消息到控制台
3223
+ * @param message
3224
+ */
3225
+ function consoleMsg(message) {
3226
+ if (typeof message === "string") {
3227
+ that.#console.log(`${tagNameHTML}${callerNameHTML} %s`, ...that.#msgColorDetails, `color: ${color};${otherStyle}`, message);
3204
3228
  }
3205
- else if (typeof _msg_ === "number") {
3206
- that.#console.log(`%c[${tagName}%c-%c${callerName}%c]%c %d`, ...that.#msgColorDetails, `color: ${color};${otherStyle}`, _msg_);
3229
+ else if (typeof message === "number") {
3230
+ that.#console.log(`${tagNameHTML}${callerNameHTML} %d`, ...that.#msgColorDetails, `color: ${color};${otherStyle}`, message);
3207
3231
  }
3208
- else if (typeof _msg_ === "object") {
3209
- that.#console.log(`%c[${tagName}%c-%c${callerName}%c]%c %o`, ...that.#msgColorDetails, `color: ${color};${otherStyle}`, _msg_);
3232
+ else if (typeof message === "object") {
3233
+ that.#console.log(`${tagNameHTML}${callerNameHTML} %o`, ...that.#msgColorDetails, `color: ${color};${otherStyle}`, message);
3210
3234
  }
3211
3235
  else {
3212
- that.#console.log(_msg_);
3236
+ that.#console.log(message);
3213
3237
  }
3214
3238
  }
3215
3239
  if (Array.isArray(msg)) {
3216
- msg.forEach((item) => {
3217
- consoleMsg(item);
3218
- });
3240
+ for (let index = 0; index < msg.length; index++) {
3241
+ consoleMsg(msg[index]);
3242
+ }
3219
3243
  }
3220
3244
  else {
3221
3245
  consoleMsg(msg);
@@ -3227,67 +3251,67 @@ System.register('Utils', [], (function (exports) {
3227
3251
  }
3228
3252
  /**
3229
3253
  * 控制台-普通输出
3230
- * @param msg 需要输出的内容,如果想输出多个,修改成数组,且数组内的长度最大值为4个
3231
- * @param color 输出的颜色
3232
- * @param otherStyle 其它CSS
3254
+ * @param args 需要输出的内容
3255
+ * @example
3256
+ * log.info("输出信息","输出信息2","输出信息3","输出")
3233
3257
  */
3234
- info(msg, color = this.#details.infoColor, otherStyle) {
3258
+ info(...args) {
3235
3259
  if (this.#disable)
3236
3260
  return;
3237
- this.printContent.call(this, msg, color, otherStyle);
3261
+ this.printContent(args, this.#details.infoColor);
3238
3262
  }
3239
3263
  /**
3240
3264
  * 控制台-警告输出
3241
- * @param msg 需要输出的内容,如果想输出多个,修改成数组,且数组内的长度最大值为4个
3242
- * @param color 输出的颜色
3243
- * @param otherStyle 其它CSS
3265
+ * @param args 需要输出的内容
3266
+ * @example
3267
+ * log.warn("输出警告","输出警告2","输出警告3","输出警告4")
3244
3268
  */
3245
- warn(msg, color = this.#details.warnColor, otherStyle = "background: #FEF6D5;padding: 4px 6px 4px 0px;") {
3269
+ warn(...args) {
3246
3270
  if (this.#disable)
3247
3271
  return;
3248
- this.printContent.call(this, msg, color, otherStyle);
3272
+ this.printContent(args, this.#details.warnColor, "background: #FEF6D5;padding: 4px 6px 4px 0px;");
3249
3273
  }
3250
3274
  /**
3251
3275
  * 控制台-错误输出
3252
- * @param msg 需要输出的内容,如果想输出多个,修改成数组,且数组内的长度最大值为4个
3253
- * @param color 输出的颜色
3254
- * @param otherStyle 其它CSS
3276
+ * @param args 需要输出的内容
3277
+ * @example
3278
+ * log.error("输出错误","输出错误2","输出错误3","输出错误4")
3255
3279
  */
3256
- error(msg, color = this.#details.errorColor, otherStyle) {
3280
+ error(...args) {
3257
3281
  if (this.#disable)
3258
3282
  return;
3259
- this.printContent.call(this, msg, color, otherStyle);
3283
+ this.printContent(args, this.#details.errorColor);
3260
3284
  }
3261
3285
  /**
3262
3286
  * 控制台-成功输出
3263
- * @param msg 需要输出的内容,如果想输出多个,修改成数组,且数组内的长度最大值为4个
3264
- * @param color 输出的颜色
3265
- * @param otherStyle 其它CSS
3287
+ * @param args 需要输出的内容
3288
+ * @example
3289
+ * log.success("输出成功")
3266
3290
  */
3267
- success(msg, color = this.#details.successColor, otherStyle) {
3291
+ success(...args) {
3268
3292
  if (this.#disable)
3269
3293
  return;
3270
- this.printContent.call(this, msg, color, otherStyle);
3294
+ this.printContent(args, this.#details.successColor);
3271
3295
  }
3272
3296
  /**
3273
3297
  * 控制台-输出表格
3274
- * @param msg
3275
- * @param color 输出的颜色
3276
- * @param otherStyle 其它CSS
3298
+ * @param msg 需要输出的内容
3277
3299
  * @example
3278
3300
  * log.table([{"名字":"example","值":"123"},{"名字":"example2","值":"345"}])
3279
3301
  */
3280
- table(msg, color = this.#details.infoColor, otherStyle = "") {
3302
+ table(msg) {
3281
3303
  if (this.#disable)
3282
3304
  return;
3283
3305
  this.checkClearConsole();
3284
3306
  let stack = new Error().stack.split("\n");
3285
3307
  stack.splice(0, 1);
3286
3308
  let errorStackParse = this.parseErrorStack(stack);
3309
+ /** 堆栈函数名 */
3287
3310
  let stackFunctionName = errorStackParse.name;
3311
+ /** 堆栈位置 */
3288
3312
  let stackFunctionNamePosition = errorStackParse.position;
3289
3313
  let callerName = stackFunctionName;
3290
- this.#console.log(`%c[${this.tag}%c-%c${callerName}%c]%c`, ...this.#msgColorDetails, `color: ${color};${otherStyle}`);
3314
+ this.#console.log(`%c[${this.tag}%c-%c${callerName}%c]%c`, ...this.#msgColorDetails, `color: ${this.#details.infoColor};`);
3291
3315
  this.#console.table(msg);
3292
3316
  if (this.#details.debug) {
3293
3317
  this.#console.log(stackFunctionNamePosition);
@@ -3931,7 +3955,7 @@ System.register('Utils', [], (function (exports) {
3931
3955
  this.windowApi = new WindowApi(option);
3932
3956
  }
3933
3957
  /** 版本号 */
3934
- version = "2024.9.10";
3958
+ version = "2024.9.28";
3935
3959
  addStyle(cssText) {
3936
3960
  if (typeof cssText !== "string") {
3937
3961
  throw new Error("Utils.addStyle 参数cssText 必须为String类型");