@xpadev-net/niconicomments 0.2.61 → 0.2.62
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/bundle.d.ts +1236 -618
- package/dist/bundle.js +2096 -568
- package/package.json +17 -17
package/dist/bundle.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
niconicomments.js v0.2.
|
|
2
|
+
niconicomments.js v0.2.62
|
|
3
3
|
(c) 2021 xpadev-net https://xpadev.net
|
|
4
4
|
Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
plugins = input;
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
-
var index$
|
|
41
|
+
var index$4 = /*#__PURE__*/Object.freeze({
|
|
42
42
|
__proto__: null,
|
|
43
43
|
get imageCache () { return imageCache; },
|
|
44
44
|
get nicoScripts () { return nicoScripts; },
|
|
@@ -124,7 +124,7 @@
|
|
|
124
124
|
}
|
|
125
125
|
NotImplementedError.prototype.name = "NotImplementedError";
|
|
126
126
|
|
|
127
|
-
var index$
|
|
127
|
+
var index$3 = /*#__PURE__*/Object.freeze({
|
|
128
128
|
__proto__: null,
|
|
129
129
|
CanvasRenderingContext2DError: CanvasRenderingContext2DError,
|
|
130
130
|
InvalidFormatError: InvalidFormatError,
|
|
@@ -132,7 +132,7 @@
|
|
|
132
132
|
NotImplementedError: NotImplementedError
|
|
133
133
|
});
|
|
134
134
|
|
|
135
|
-
const
|
|
135
|
+
const arrayPush = (array, key, push) => {
|
|
136
136
|
if (!array) {
|
|
137
137
|
array = {};
|
|
138
138
|
}
|
|
@@ -141,7 +141,7 @@
|
|
|
141
141
|
}
|
|
142
142
|
array[Number(key)]?.push(push);
|
|
143
143
|
};
|
|
144
|
-
const
|
|
144
|
+
const arrayEqual = (a, b) => {
|
|
145
145
|
if (a.length !== b.length)
|
|
146
146
|
return false;
|
|
147
147
|
for (let i = 0, n = a.length; i < n; ++i) {
|
|
@@ -206,6 +206,1449 @@
|
|
|
206
206
|
: config.contextStrokeColor).join(",")},${config.contextStrokeOpacity})`;
|
|
207
207
|
};
|
|
208
208
|
|
|
209
|
+
function _iterableToArrayLimit(r, l) {
|
|
210
|
+
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
211
|
+
if (null != t) {
|
|
212
|
+
var e,
|
|
213
|
+
n,
|
|
214
|
+
i,
|
|
215
|
+
u,
|
|
216
|
+
a = [],
|
|
217
|
+
f = !0,
|
|
218
|
+
o = !1;
|
|
219
|
+
try {
|
|
220
|
+
if (i = (t = t.call(r)).next, 0 === l) {
|
|
221
|
+
if (Object(t) !== t) return;
|
|
222
|
+
f = !1;
|
|
223
|
+
} else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
|
|
224
|
+
} catch (r) {
|
|
225
|
+
o = !0, n = r;
|
|
226
|
+
} finally {
|
|
227
|
+
try {
|
|
228
|
+
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
|
|
229
|
+
} finally {
|
|
230
|
+
if (o) throw n;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return a;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
function ownKeys(e, r) {
|
|
237
|
+
var t = Object.keys(e);
|
|
238
|
+
if (Object.getOwnPropertySymbols) {
|
|
239
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
240
|
+
r && (o = o.filter(function (r) {
|
|
241
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
242
|
+
})), t.push.apply(t, o);
|
|
243
|
+
}
|
|
244
|
+
return t;
|
|
245
|
+
}
|
|
246
|
+
function _objectSpread2(e) {
|
|
247
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
248
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
249
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
|
|
250
|
+
_defineProperty(e, r, t[r]);
|
|
251
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
|
|
252
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
return e;
|
|
256
|
+
}
|
|
257
|
+
function _typeof(o) {
|
|
258
|
+
"@babel/helpers - typeof";
|
|
259
|
+
|
|
260
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
|
|
261
|
+
return typeof o;
|
|
262
|
+
} : function (o) {
|
|
263
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
264
|
+
}, _typeof(o);
|
|
265
|
+
}
|
|
266
|
+
function _classCallCheck(instance, Constructor) {
|
|
267
|
+
if (!(instance instanceof Constructor)) {
|
|
268
|
+
throw new TypeError("Cannot call a class as a function");
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
function _defineProperties(target, props) {
|
|
272
|
+
for (var i = 0; i < props.length; i++) {
|
|
273
|
+
var descriptor = props[i];
|
|
274
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
275
|
+
descriptor.configurable = true;
|
|
276
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
277
|
+
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
281
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
282
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
283
|
+
Object.defineProperty(Constructor, "prototype", {
|
|
284
|
+
writable: false
|
|
285
|
+
});
|
|
286
|
+
return Constructor;
|
|
287
|
+
}
|
|
288
|
+
function _defineProperty(obj, key, value) {
|
|
289
|
+
key = _toPropertyKey(key);
|
|
290
|
+
if (key in obj) {
|
|
291
|
+
Object.defineProperty(obj, key, {
|
|
292
|
+
value: value,
|
|
293
|
+
enumerable: true,
|
|
294
|
+
configurable: true,
|
|
295
|
+
writable: true
|
|
296
|
+
});
|
|
297
|
+
} else {
|
|
298
|
+
obj[key] = value;
|
|
299
|
+
}
|
|
300
|
+
return obj;
|
|
301
|
+
}
|
|
302
|
+
function _inherits(subClass, superClass) {
|
|
303
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
304
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
305
|
+
}
|
|
306
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
307
|
+
constructor: {
|
|
308
|
+
value: subClass,
|
|
309
|
+
writable: true,
|
|
310
|
+
configurable: true
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
Object.defineProperty(subClass, "prototype", {
|
|
314
|
+
writable: false
|
|
315
|
+
});
|
|
316
|
+
if (superClass) _setPrototypeOf(subClass, superClass);
|
|
317
|
+
}
|
|
318
|
+
function _getPrototypeOf(o) {
|
|
319
|
+
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
|
|
320
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
321
|
+
};
|
|
322
|
+
return _getPrototypeOf(o);
|
|
323
|
+
}
|
|
324
|
+
function _setPrototypeOf(o, p) {
|
|
325
|
+
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
326
|
+
o.__proto__ = p;
|
|
327
|
+
return o;
|
|
328
|
+
};
|
|
329
|
+
return _setPrototypeOf(o, p);
|
|
330
|
+
}
|
|
331
|
+
function _isNativeReflectConstruct() {
|
|
332
|
+
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
|
333
|
+
if (Reflect.construct.sham) return false;
|
|
334
|
+
if (typeof Proxy === "function") return true;
|
|
335
|
+
try {
|
|
336
|
+
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
|
|
337
|
+
return true;
|
|
338
|
+
} catch (e) {
|
|
339
|
+
return false;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
function _construct(Parent, args, Class) {
|
|
343
|
+
if (_isNativeReflectConstruct()) {
|
|
344
|
+
_construct = Reflect.construct.bind();
|
|
345
|
+
} else {
|
|
346
|
+
_construct = function _construct(Parent, args, Class) {
|
|
347
|
+
var a = [null];
|
|
348
|
+
a.push.apply(a, args);
|
|
349
|
+
var Constructor = Function.bind.apply(Parent, a);
|
|
350
|
+
var instance = new Constructor();
|
|
351
|
+
if (Class) _setPrototypeOf(instance, Class.prototype);
|
|
352
|
+
return instance;
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
return _construct.apply(null, arguments);
|
|
356
|
+
}
|
|
357
|
+
function _isNativeFunction(fn) {
|
|
358
|
+
try {
|
|
359
|
+
return Function.toString.call(fn).indexOf("[native code]") !== -1;
|
|
360
|
+
} catch (e) {
|
|
361
|
+
return typeof fn === "function";
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
function _wrapNativeSuper(Class) {
|
|
365
|
+
var _cache = typeof Map === "function" ? new Map() : undefined;
|
|
366
|
+
_wrapNativeSuper = function _wrapNativeSuper(Class) {
|
|
367
|
+
if (Class === null || !_isNativeFunction(Class)) return Class;
|
|
368
|
+
if (typeof Class !== "function") {
|
|
369
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
370
|
+
}
|
|
371
|
+
if (typeof _cache !== "undefined") {
|
|
372
|
+
if (_cache.has(Class)) return _cache.get(Class);
|
|
373
|
+
_cache.set(Class, Wrapper);
|
|
374
|
+
}
|
|
375
|
+
function Wrapper() {
|
|
376
|
+
return _construct(Class, arguments, _getPrototypeOf(this).constructor);
|
|
377
|
+
}
|
|
378
|
+
Wrapper.prototype = Object.create(Class.prototype, {
|
|
379
|
+
constructor: {
|
|
380
|
+
value: Wrapper,
|
|
381
|
+
enumerable: false,
|
|
382
|
+
writable: true,
|
|
383
|
+
configurable: true
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
return _setPrototypeOf(Wrapper, Class);
|
|
387
|
+
};
|
|
388
|
+
return _wrapNativeSuper(Class);
|
|
389
|
+
}
|
|
390
|
+
function _assertThisInitialized(self) {
|
|
391
|
+
if (self === void 0) {
|
|
392
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
393
|
+
}
|
|
394
|
+
return self;
|
|
395
|
+
}
|
|
396
|
+
function _possibleConstructorReturn(self, call) {
|
|
397
|
+
if (call && (typeof call === "object" || typeof call === "function")) {
|
|
398
|
+
return call;
|
|
399
|
+
} else if (call !== void 0) {
|
|
400
|
+
throw new TypeError("Derived constructors may only return object or undefined");
|
|
401
|
+
}
|
|
402
|
+
return _assertThisInitialized(self);
|
|
403
|
+
}
|
|
404
|
+
function _createSuper(Derived) {
|
|
405
|
+
var hasNativeReflectConstruct = _isNativeReflectConstruct();
|
|
406
|
+
return function _createSuperInternal() {
|
|
407
|
+
var Super = _getPrototypeOf(Derived),
|
|
408
|
+
result;
|
|
409
|
+
if (hasNativeReflectConstruct) {
|
|
410
|
+
var NewTarget = _getPrototypeOf(this).constructor;
|
|
411
|
+
result = Reflect.construct(Super, arguments, NewTarget);
|
|
412
|
+
} else {
|
|
413
|
+
result = Super.apply(this, arguments);
|
|
414
|
+
}
|
|
415
|
+
return _possibleConstructorReturn(this, result);
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
function _slicedToArray(arr, i) {
|
|
419
|
+
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
420
|
+
}
|
|
421
|
+
function _arrayWithHoles(arr) {
|
|
422
|
+
if (Array.isArray(arr)) return arr;
|
|
423
|
+
}
|
|
424
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
425
|
+
if (!o) return;
|
|
426
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
427
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
428
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
429
|
+
if (n === "Map" || n === "Set") return Array.from(o);
|
|
430
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
431
|
+
}
|
|
432
|
+
function _arrayLikeToArray(arr, len) {
|
|
433
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
434
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
435
|
+
return arr2;
|
|
436
|
+
}
|
|
437
|
+
function _nonIterableRest() {
|
|
438
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
439
|
+
}
|
|
440
|
+
function _createForOfIteratorHelper(o, allowArrayLike) {
|
|
441
|
+
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
442
|
+
if (!it) {
|
|
443
|
+
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
444
|
+
if (it) o = it;
|
|
445
|
+
var i = 0;
|
|
446
|
+
var F = function () {};
|
|
447
|
+
return {
|
|
448
|
+
s: F,
|
|
449
|
+
n: function () {
|
|
450
|
+
if (i >= o.length) return {
|
|
451
|
+
done: true
|
|
452
|
+
};
|
|
453
|
+
return {
|
|
454
|
+
done: false,
|
|
455
|
+
value: o[i++]
|
|
456
|
+
};
|
|
457
|
+
},
|
|
458
|
+
e: function (e) {
|
|
459
|
+
throw e;
|
|
460
|
+
},
|
|
461
|
+
f: F
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
465
|
+
}
|
|
466
|
+
var normalCompletion = true,
|
|
467
|
+
didErr = false,
|
|
468
|
+
err;
|
|
469
|
+
return {
|
|
470
|
+
s: function () {
|
|
471
|
+
it = it.call(o);
|
|
472
|
+
},
|
|
473
|
+
n: function () {
|
|
474
|
+
var step = it.next();
|
|
475
|
+
normalCompletion = step.done;
|
|
476
|
+
return step;
|
|
477
|
+
},
|
|
478
|
+
e: function (e) {
|
|
479
|
+
didErr = true;
|
|
480
|
+
err = e;
|
|
481
|
+
},
|
|
482
|
+
f: function () {
|
|
483
|
+
try {
|
|
484
|
+
if (!normalCompletion && it.return != null) it.return();
|
|
485
|
+
} finally {
|
|
486
|
+
if (didErr) throw err;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
function _toPrimitive(input, hint) {
|
|
492
|
+
if (typeof input !== "object" || input === null) return input;
|
|
493
|
+
var prim = input[Symbol.toPrimitive];
|
|
494
|
+
if (prim !== undefined) {
|
|
495
|
+
var res = prim.call(input, hint || "default");
|
|
496
|
+
if (typeof res !== "object") return res;
|
|
497
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
498
|
+
}
|
|
499
|
+
return (hint === "string" ? String : Number)(input);
|
|
500
|
+
}
|
|
501
|
+
function _toPropertyKey(arg) {
|
|
502
|
+
var key = _toPrimitive(arg, "string");
|
|
503
|
+
return typeof key === "symbol" ? key : String(key);
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
// src/error/ValiError/ValiError.ts
|
|
507
|
+
var ValiError = /*#__PURE__*/function (_Error) {
|
|
508
|
+
_inherits(ValiError, _Error);
|
|
509
|
+
var _super = _createSuper(ValiError);
|
|
510
|
+
/**
|
|
511
|
+
* Creates a Valibot error with useful information.
|
|
512
|
+
*
|
|
513
|
+
* @param issues The error issues.
|
|
514
|
+
*/
|
|
515
|
+
function ValiError(issues) {
|
|
516
|
+
var _this;
|
|
517
|
+
_classCallCheck(this, ValiError);
|
|
518
|
+
_this = _super.call(this, issues[0].message);
|
|
519
|
+
_defineProperty(_assertThisInitialized(_this), "issues", void 0);
|
|
520
|
+
_this.name = "ValiError";
|
|
521
|
+
_this.issues = issues;
|
|
522
|
+
return _this;
|
|
523
|
+
}
|
|
524
|
+
return _createClass(ValiError);
|
|
525
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
526
|
+
|
|
527
|
+
// src/utils/getIssues/getIssues.ts
|
|
528
|
+
function getIssues(issues) {
|
|
529
|
+
return {
|
|
530
|
+
issues: issues
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
// src/utils/getOutput/getOutput.ts
|
|
535
|
+
function getOutput(output) {
|
|
536
|
+
return {
|
|
537
|
+
output: output
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
// src/utils/executePipe/utils/getIssue/getIssue.ts
|
|
542
|
+
function getIssue(info, issue) {
|
|
543
|
+
return {
|
|
544
|
+
reason: info === null || info === void 0 ? void 0 : info.reason,
|
|
545
|
+
validation: issue.validation,
|
|
546
|
+
origin: (info === null || info === void 0 ? void 0 : info.origin) || "value",
|
|
547
|
+
message: issue.message,
|
|
548
|
+
input: issue.input,
|
|
549
|
+
path: issue.path,
|
|
550
|
+
abortEarly: info === null || info === void 0 ? void 0 : info.abortEarly,
|
|
551
|
+
abortPipeEarly: info === null || info === void 0 ? void 0 : info.abortPipeEarly,
|
|
552
|
+
skipPipe: info === null || info === void 0 ? void 0 : info.skipPipe
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
// src/utils/executePipe/utils/getPipeInfo/getPipeInfo.ts
|
|
557
|
+
function getPipeInfo(info, reason) {
|
|
558
|
+
return {
|
|
559
|
+
reason: reason,
|
|
560
|
+
origin: info === null || info === void 0 ? void 0 : info.origin,
|
|
561
|
+
abortEarly: info === null || info === void 0 ? void 0 : info.abortEarly,
|
|
562
|
+
abortPipeEarly: info === null || info === void 0 ? void 0 : info.abortPipeEarly,
|
|
563
|
+
skipPipe: info === null || info === void 0 ? void 0 : info.skipPipe
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
// src/utils/executePipe/executePipe.ts
|
|
568
|
+
function executePipe(input, pipe, parseInfo, reason) {
|
|
569
|
+
if (!pipe || !pipe.length || parseInfo !== null && parseInfo !== void 0 && parseInfo.skipPipe) {
|
|
570
|
+
return getOutput(input);
|
|
571
|
+
}
|
|
572
|
+
var pipeInfo;
|
|
573
|
+
var issues;
|
|
574
|
+
var output = input;
|
|
575
|
+
var _iterator = _createForOfIteratorHelper(pipe),
|
|
576
|
+
_step;
|
|
577
|
+
try {
|
|
578
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
579
|
+
var action = _step.value;
|
|
580
|
+
var result = action(output);
|
|
581
|
+
if (result.issues) {
|
|
582
|
+
pipeInfo = pipeInfo || getPipeInfo(parseInfo, reason);
|
|
583
|
+
var _iterator2 = _createForOfIteratorHelper(result.issues),
|
|
584
|
+
_step2;
|
|
585
|
+
try {
|
|
586
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
587
|
+
var issueInfo = _step2.value;
|
|
588
|
+
var issue = getIssue(pipeInfo, issueInfo);
|
|
589
|
+
issues ? issues.push(issue) : issues = [issue];
|
|
590
|
+
}
|
|
591
|
+
} catch (err) {
|
|
592
|
+
_iterator2.e(err);
|
|
593
|
+
} finally {
|
|
594
|
+
_iterator2.f();
|
|
595
|
+
}
|
|
596
|
+
if (pipeInfo.abortEarly || pipeInfo.abortPipeEarly) {
|
|
597
|
+
break;
|
|
598
|
+
}
|
|
599
|
+
} else {
|
|
600
|
+
output = result.output;
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
} catch (err) {
|
|
604
|
+
_iterator.e(err);
|
|
605
|
+
} finally {
|
|
606
|
+
_iterator.f();
|
|
607
|
+
}
|
|
608
|
+
return issues ? getIssues(issues) : getOutput(output);
|
|
609
|
+
}
|
|
610
|
+
function getDefaultArgs(arg1, arg2) {
|
|
611
|
+
return Array.isArray(arg1) ? [void 0, arg1] : [arg1, arg2];
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
// src/utils/getErrorMessage/getErrorMessage.ts
|
|
615
|
+
function getErrorMessage(error) {
|
|
616
|
+
return typeof error === "function" ? error() : error;
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
// src/utils/getPipeIssues/getPipeIssues.ts
|
|
620
|
+
function getPipeIssues(validation, error, input) {
|
|
621
|
+
return getIssues([{
|
|
622
|
+
validation: validation,
|
|
623
|
+
message: getErrorMessage(error),
|
|
624
|
+
input: input
|
|
625
|
+
}]);
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
// src/utils/getRestAndDefaultArgs/getRestAndDefaultArgs.ts
|
|
629
|
+
function getRestAndDefaultArgs(arg1, arg2, arg3) {
|
|
630
|
+
if (!arg1 || _typeof(arg1) === "object" && !Array.isArray(arg1)) {
|
|
631
|
+
var _getDefaultArgs = getDefaultArgs(arg2, arg3),
|
|
632
|
+
_getDefaultArgs2 = _slicedToArray(_getDefaultArgs, 2),
|
|
633
|
+
error2 = _getDefaultArgs2[0],
|
|
634
|
+
pipe2 = _getDefaultArgs2[1];
|
|
635
|
+
return [arg1, error2, pipe2];
|
|
636
|
+
}
|
|
637
|
+
var _getDefaultArgs3 = getDefaultArgs(arg1, arg2),
|
|
638
|
+
_getDefaultArgs4 = _slicedToArray(_getDefaultArgs3, 2),
|
|
639
|
+
error = _getDefaultArgs4[0],
|
|
640
|
+
pipe = _getDefaultArgs4[1];
|
|
641
|
+
return [void 0, error, pipe];
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
// src/utils/getSchemaIssues/getSchemaIssues.ts
|
|
645
|
+
function getSchemaIssues(info, reason, validation, error, input, issues) {
|
|
646
|
+
return {
|
|
647
|
+
issues: [{
|
|
648
|
+
reason: reason,
|
|
649
|
+
validation: validation,
|
|
650
|
+
origin: (info === null || info === void 0 ? void 0 : info.origin) || "value",
|
|
651
|
+
message: getErrorMessage(error),
|
|
652
|
+
input: input,
|
|
653
|
+
issues: issues,
|
|
654
|
+
abortEarly: info === null || info === void 0 ? void 0 : info.abortEarly,
|
|
655
|
+
abortPipeEarly: info === null || info === void 0 ? void 0 : info.abortPipeEarly,
|
|
656
|
+
skipPipe: info === null || info === void 0 ? void 0 : info.skipPipe
|
|
657
|
+
}]
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
function is(schema, input) {
|
|
661
|
+
return !schema._parse(input, {
|
|
662
|
+
abortEarly: true
|
|
663
|
+
}).issues;
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
// src/schemas/array/array.ts
|
|
667
|
+
function array(item, arg2, arg3) {
|
|
668
|
+
var _getDefaultArgs5 = getDefaultArgs(arg2, arg3),
|
|
669
|
+
_getDefaultArgs6 = _slicedToArray(_getDefaultArgs5, 2),
|
|
670
|
+
error = _getDefaultArgs6[0],
|
|
671
|
+
pipe = _getDefaultArgs6[1];
|
|
672
|
+
return {
|
|
673
|
+
/**
|
|
674
|
+
* The schema type.
|
|
675
|
+
*/
|
|
676
|
+
type: "array",
|
|
677
|
+
/**
|
|
678
|
+
* The item schema.
|
|
679
|
+
*/
|
|
680
|
+
item: item,
|
|
681
|
+
/**
|
|
682
|
+
* Whether it's async.
|
|
683
|
+
*/
|
|
684
|
+
async: false,
|
|
685
|
+
/**
|
|
686
|
+
* Parses unknown input based on its schema.
|
|
687
|
+
*
|
|
688
|
+
* @param input The input to be parsed.
|
|
689
|
+
* @param info The parse info.
|
|
690
|
+
*
|
|
691
|
+
* @returns The parsed output.
|
|
692
|
+
*/
|
|
693
|
+
_parse: function _parse(input, info) {
|
|
694
|
+
if (!Array.isArray(input)) {
|
|
695
|
+
return getSchemaIssues(info, "type", "array", error || "Invalid type", input);
|
|
696
|
+
}
|
|
697
|
+
var issues;
|
|
698
|
+
var output = [];
|
|
699
|
+
for (var key = 0; key < input.length; key++) {
|
|
700
|
+
var value2 = input[key];
|
|
701
|
+
var result = item._parse(value2, info);
|
|
702
|
+
if (result.issues) {
|
|
703
|
+
var pathItem = {
|
|
704
|
+
type: "array",
|
|
705
|
+
input: input,
|
|
706
|
+
key: key,
|
|
707
|
+
value: value2
|
|
708
|
+
};
|
|
709
|
+
var _iterator3 = _createForOfIteratorHelper(result.issues),
|
|
710
|
+
_step3;
|
|
711
|
+
try {
|
|
712
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
713
|
+
var _issues;
|
|
714
|
+
var issue = _step3.value;
|
|
715
|
+
if (issue.path) {
|
|
716
|
+
issue.path.unshift(pathItem);
|
|
717
|
+
} else {
|
|
718
|
+
issue.path = [pathItem];
|
|
719
|
+
}
|
|
720
|
+
(_issues = issues) === null || _issues === void 0 || _issues.push(issue);
|
|
721
|
+
}
|
|
722
|
+
} catch (err) {
|
|
723
|
+
_iterator3.e(err);
|
|
724
|
+
} finally {
|
|
725
|
+
_iterator3.f();
|
|
726
|
+
}
|
|
727
|
+
if (!issues) {
|
|
728
|
+
issues = result.issues;
|
|
729
|
+
}
|
|
730
|
+
if (info !== null && info !== void 0 && info.abortEarly) {
|
|
731
|
+
break;
|
|
732
|
+
}
|
|
733
|
+
} else {
|
|
734
|
+
output.push(result.output);
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
return issues ? getIssues(issues) : executePipe(output, pipe, info, "array");
|
|
738
|
+
}
|
|
739
|
+
};
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
// src/schemas/boolean/boolean.ts
|
|
743
|
+
function _boolean(arg1, arg2) {
|
|
744
|
+
var _getDefaultArgs17 = getDefaultArgs(arg1, arg2),
|
|
745
|
+
_getDefaultArgs18 = _slicedToArray(_getDefaultArgs17, 2),
|
|
746
|
+
error = _getDefaultArgs18[0],
|
|
747
|
+
pipe = _getDefaultArgs18[1];
|
|
748
|
+
return {
|
|
749
|
+
/**
|
|
750
|
+
* The schema type.
|
|
751
|
+
*/
|
|
752
|
+
type: "boolean",
|
|
753
|
+
/**
|
|
754
|
+
* Whether it's async.
|
|
755
|
+
*/
|
|
756
|
+
async: false,
|
|
757
|
+
/**
|
|
758
|
+
* Parses unknown input based on its schema.
|
|
759
|
+
*
|
|
760
|
+
* @param input The input to be parsed.
|
|
761
|
+
* @param info The parse info.
|
|
762
|
+
*
|
|
763
|
+
* @returns The parsed output.
|
|
764
|
+
*/
|
|
765
|
+
_parse: function _parse(input, info) {
|
|
766
|
+
if (typeof input !== "boolean") {
|
|
767
|
+
return getSchemaIssues(info, "type", "boolean", error || "Invalid type", input);
|
|
768
|
+
}
|
|
769
|
+
return executePipe(input, pipe, info, "boolean");
|
|
770
|
+
}
|
|
771
|
+
};
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
// src/schemas/intersect/utils/mergeOutputs/mergeOutputs.ts
|
|
775
|
+
function mergeOutputs(output1, output2) {
|
|
776
|
+
if (_typeof(output1) === _typeof(output2)) {
|
|
777
|
+
if (output1 === output2 || output1 instanceof Date && output2 instanceof Date && +output1 === +output2) {
|
|
778
|
+
return getOutput(output1);
|
|
779
|
+
}
|
|
780
|
+
if (Array.isArray(output1) && Array.isArray(output2)) {
|
|
781
|
+
if (output1.length === output2.length) {
|
|
782
|
+
var array2 = [];
|
|
783
|
+
for (var index = 0; index < output1.length; index++) {
|
|
784
|
+
var result = mergeOutputs(output1[index], output2[index]);
|
|
785
|
+
if (result.invalid) {
|
|
786
|
+
return result;
|
|
787
|
+
}
|
|
788
|
+
array2.push(result.output);
|
|
789
|
+
}
|
|
790
|
+
return getOutput(array2);
|
|
791
|
+
}
|
|
792
|
+
return {
|
|
793
|
+
invalid: true
|
|
794
|
+
};
|
|
795
|
+
}
|
|
796
|
+
if (output1 && output2 && output1.constructor === Object && output2.constructor === Object) {
|
|
797
|
+
var object2 = _objectSpread2(_objectSpread2({}, output1), output2);
|
|
798
|
+
for (var key in output1) {
|
|
799
|
+
if (key in output2) {
|
|
800
|
+
var _result = mergeOutputs(output1[key], output2[key]);
|
|
801
|
+
if (_result.invalid) {
|
|
802
|
+
return _result;
|
|
803
|
+
}
|
|
804
|
+
object2[key] = _result.output;
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
return getOutput(object2);
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
return {
|
|
811
|
+
invalid: true
|
|
812
|
+
};
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
// src/schemas/intersect/intersect.ts
|
|
816
|
+
function intersect(options, error) {
|
|
817
|
+
return {
|
|
818
|
+
/**
|
|
819
|
+
* The schema type.
|
|
820
|
+
*/
|
|
821
|
+
type: "intersect",
|
|
822
|
+
/**
|
|
823
|
+
* The intersect options.
|
|
824
|
+
*/
|
|
825
|
+
options: options,
|
|
826
|
+
/**
|
|
827
|
+
* Whether it's async.
|
|
828
|
+
*/
|
|
829
|
+
async: false,
|
|
830
|
+
/**
|
|
831
|
+
* Parses unknown input based on its schema.
|
|
832
|
+
*
|
|
833
|
+
* @param input The input to be parsed.
|
|
834
|
+
* @param info The parse info.
|
|
835
|
+
*
|
|
836
|
+
* @returns The parsed output.
|
|
837
|
+
*/
|
|
838
|
+
_parse: function _parse(input, info) {
|
|
839
|
+
var issues;
|
|
840
|
+
var outputs;
|
|
841
|
+
var _iterator5 = _createForOfIteratorHelper(options),
|
|
842
|
+
_step5;
|
|
843
|
+
try {
|
|
844
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
845
|
+
var schema = _step5.value;
|
|
846
|
+
var _result2 = schema._parse(input, info);
|
|
847
|
+
if (_result2.issues) {
|
|
848
|
+
if (issues) {
|
|
849
|
+
var _iterator6 = _createForOfIteratorHelper(_result2.issues),
|
|
850
|
+
_step6;
|
|
851
|
+
try {
|
|
852
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
853
|
+
var issue = _step6.value;
|
|
854
|
+
issues.push(issue);
|
|
855
|
+
}
|
|
856
|
+
} catch (err) {
|
|
857
|
+
_iterator6.e(err);
|
|
858
|
+
} finally {
|
|
859
|
+
_iterator6.f();
|
|
860
|
+
}
|
|
861
|
+
} else {
|
|
862
|
+
issues = _result2.issues;
|
|
863
|
+
}
|
|
864
|
+
if (info !== null && info !== void 0 && info.abortEarly) {
|
|
865
|
+
break;
|
|
866
|
+
}
|
|
867
|
+
} else {
|
|
868
|
+
if (outputs) {
|
|
869
|
+
outputs.push(_result2.output);
|
|
870
|
+
} else {
|
|
871
|
+
outputs = [_result2.output];
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
} catch (err) {
|
|
876
|
+
_iterator5.e(err);
|
|
877
|
+
} finally {
|
|
878
|
+
_iterator5.f();
|
|
879
|
+
}
|
|
880
|
+
if (issues) {
|
|
881
|
+
return getIssues(issues);
|
|
882
|
+
}
|
|
883
|
+
var output = outputs[0];
|
|
884
|
+
for (var index = 1; index < outputs.length; index++) {
|
|
885
|
+
var result = mergeOutputs(output, outputs[index]);
|
|
886
|
+
if (result.invalid) {
|
|
887
|
+
return getSchemaIssues(info, "type", "intersect", error || "Invalid type", input);
|
|
888
|
+
}
|
|
889
|
+
output = result.output;
|
|
890
|
+
}
|
|
891
|
+
return getOutput(output);
|
|
892
|
+
}
|
|
893
|
+
};
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
// src/schemas/literal/literal.ts
|
|
897
|
+
function literal(literal2, error) {
|
|
898
|
+
return {
|
|
899
|
+
/**
|
|
900
|
+
* The schema type.
|
|
901
|
+
*/
|
|
902
|
+
type: "literal",
|
|
903
|
+
/**
|
|
904
|
+
* The literal value.
|
|
905
|
+
*/
|
|
906
|
+
literal: literal2,
|
|
907
|
+
/**
|
|
908
|
+
* Whether it's async.
|
|
909
|
+
*/
|
|
910
|
+
async: false,
|
|
911
|
+
/**
|
|
912
|
+
* Parses unknown input based on its schema.
|
|
913
|
+
*
|
|
914
|
+
* @param input The input to be parsed.
|
|
915
|
+
* @param info The parse info.
|
|
916
|
+
*
|
|
917
|
+
* @returns The parsed output.
|
|
918
|
+
*/
|
|
919
|
+
_parse: function _parse(input, info) {
|
|
920
|
+
if (input !== literal2) {
|
|
921
|
+
return getSchemaIssues(info, "type", "literal", error || "Invalid type", input);
|
|
922
|
+
}
|
|
923
|
+
return getOutput(input);
|
|
924
|
+
}
|
|
925
|
+
};
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
// src/schemas/nullable/nullable.ts
|
|
929
|
+
function nullable(wrapped, default_) {
|
|
930
|
+
return {
|
|
931
|
+
/**
|
|
932
|
+
* The schema type.
|
|
933
|
+
*/
|
|
934
|
+
type: "nullable",
|
|
935
|
+
/**
|
|
936
|
+
* The wrapped schema.
|
|
937
|
+
*/
|
|
938
|
+
wrapped: wrapped,
|
|
939
|
+
/**
|
|
940
|
+
* Returns the default value.
|
|
941
|
+
*/
|
|
942
|
+
getDefault: function getDefault() {
|
|
943
|
+
return typeof default_ === "function" ? default_() : default_;
|
|
944
|
+
},
|
|
945
|
+
/**
|
|
946
|
+
* Whether it's async.
|
|
947
|
+
*/
|
|
948
|
+
async: false,
|
|
949
|
+
/**
|
|
950
|
+
* Parses unknown input based on its schema.
|
|
951
|
+
*
|
|
952
|
+
* @param input The input to be parsed.
|
|
953
|
+
* @param info The parse info.
|
|
954
|
+
*
|
|
955
|
+
* @returns The parsed output.
|
|
956
|
+
*/
|
|
957
|
+
_parse: function _parse(input, info) {
|
|
958
|
+
if (input === null) {
|
|
959
|
+
var override = this.getDefault();
|
|
960
|
+
if (override === void 0) {
|
|
961
|
+
return getOutput(input);
|
|
962
|
+
}
|
|
963
|
+
input = override;
|
|
964
|
+
}
|
|
965
|
+
return wrapped._parse(input, info);
|
|
966
|
+
}
|
|
967
|
+
};
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
// src/schemas/number/number.ts
|
|
971
|
+
function number(arg1, arg2) {
|
|
972
|
+
var _getDefaultArgs33 = getDefaultArgs(arg1, arg2),
|
|
973
|
+
_getDefaultArgs34 = _slicedToArray(_getDefaultArgs33, 2),
|
|
974
|
+
error = _getDefaultArgs34[0],
|
|
975
|
+
pipe = _getDefaultArgs34[1];
|
|
976
|
+
return {
|
|
977
|
+
/**
|
|
978
|
+
* The schema type.
|
|
979
|
+
*/
|
|
980
|
+
type: "number",
|
|
981
|
+
/**
|
|
982
|
+
* Whether it's async.
|
|
983
|
+
*/
|
|
984
|
+
async: false,
|
|
985
|
+
/**
|
|
986
|
+
* Parses unknown input based on its schema.
|
|
987
|
+
*
|
|
988
|
+
* @param input The input to be parsed.
|
|
989
|
+
* @param info The parse info.
|
|
990
|
+
*
|
|
991
|
+
* @returns The parsed output.
|
|
992
|
+
*/
|
|
993
|
+
_parse: function _parse(input, info) {
|
|
994
|
+
if (typeof input !== "number" || isNaN(input)) {
|
|
995
|
+
return getSchemaIssues(info, "type", "number", error || "Invalid type", input);
|
|
996
|
+
}
|
|
997
|
+
return executePipe(input, pipe, info, "number");
|
|
998
|
+
}
|
|
999
|
+
};
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
// src/schemas/object/object.ts
|
|
1003
|
+
function object(entries, arg2, arg3, arg4) {
|
|
1004
|
+
var _getRestAndDefaultArg = getRestAndDefaultArgs(arg2, arg3, arg4),
|
|
1005
|
+
_getRestAndDefaultArg2 = _slicedToArray(_getRestAndDefaultArg, 3),
|
|
1006
|
+
rest = _getRestAndDefaultArg2[0],
|
|
1007
|
+
error = _getRestAndDefaultArg2[1],
|
|
1008
|
+
pipe = _getRestAndDefaultArg2[2];
|
|
1009
|
+
var cachedEntries;
|
|
1010
|
+
return {
|
|
1011
|
+
/**
|
|
1012
|
+
* The schema type.
|
|
1013
|
+
*/
|
|
1014
|
+
type: "object",
|
|
1015
|
+
/**
|
|
1016
|
+
* The entries schema.
|
|
1017
|
+
*/
|
|
1018
|
+
entries: entries,
|
|
1019
|
+
/**
|
|
1020
|
+
* The rest schema.
|
|
1021
|
+
*/
|
|
1022
|
+
rest: rest,
|
|
1023
|
+
/**
|
|
1024
|
+
* Whether it's async.
|
|
1025
|
+
*/
|
|
1026
|
+
async: false,
|
|
1027
|
+
/**
|
|
1028
|
+
* Parses unknown input based on its schema.
|
|
1029
|
+
*
|
|
1030
|
+
* @param input The input to be parsed.
|
|
1031
|
+
* @param info The parse info.
|
|
1032
|
+
*
|
|
1033
|
+
* @returns The parsed output.
|
|
1034
|
+
*/
|
|
1035
|
+
_parse: function _parse(input, info) {
|
|
1036
|
+
if (!input || _typeof(input) !== "object") {
|
|
1037
|
+
return getSchemaIssues(info, "type", "object", error || "Invalid type", input);
|
|
1038
|
+
}
|
|
1039
|
+
cachedEntries = cachedEntries || Object.entries(entries);
|
|
1040
|
+
var issues;
|
|
1041
|
+
var output = {};
|
|
1042
|
+
var _iterator11 = _createForOfIteratorHelper(cachedEntries),
|
|
1043
|
+
_step11;
|
|
1044
|
+
try {
|
|
1045
|
+
for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
|
|
1046
|
+
var _step11$value = _slicedToArray(_step11.value, 2),
|
|
1047
|
+
_key3 = _step11$value[0],
|
|
1048
|
+
schema = _step11$value[1];
|
|
1049
|
+
var _value = input[_key3];
|
|
1050
|
+
var _result3 = schema._parse(_value, info);
|
|
1051
|
+
if (_result3.issues) {
|
|
1052
|
+
var _pathItem = {
|
|
1053
|
+
type: "object",
|
|
1054
|
+
input: input,
|
|
1055
|
+
key: _key3,
|
|
1056
|
+
value: _value
|
|
1057
|
+
};
|
|
1058
|
+
var _iterator13 = _createForOfIteratorHelper(_result3.issues),
|
|
1059
|
+
_step13;
|
|
1060
|
+
try {
|
|
1061
|
+
for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
|
|
1062
|
+
var _issues7;
|
|
1063
|
+
var _issue2 = _step13.value;
|
|
1064
|
+
if (_issue2.path) {
|
|
1065
|
+
_issue2.path.unshift(_pathItem);
|
|
1066
|
+
} else {
|
|
1067
|
+
_issue2.path = [_pathItem];
|
|
1068
|
+
}
|
|
1069
|
+
(_issues7 = issues) === null || _issues7 === void 0 || _issues7.push(_issue2);
|
|
1070
|
+
}
|
|
1071
|
+
} catch (err) {
|
|
1072
|
+
_iterator13.e(err);
|
|
1073
|
+
} finally {
|
|
1074
|
+
_iterator13.f();
|
|
1075
|
+
}
|
|
1076
|
+
if (!issues) {
|
|
1077
|
+
issues = _result3.issues;
|
|
1078
|
+
}
|
|
1079
|
+
if (info !== null && info !== void 0 && info.abortEarly) {
|
|
1080
|
+
break;
|
|
1081
|
+
}
|
|
1082
|
+
} else if (_result3.output !== void 0 || _key3 in input) {
|
|
1083
|
+
output[_key3] = _result3.output;
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
} catch (err) {
|
|
1087
|
+
_iterator11.e(err);
|
|
1088
|
+
} finally {
|
|
1089
|
+
_iterator11.f();
|
|
1090
|
+
}
|
|
1091
|
+
if (rest && !(info !== null && info !== void 0 && info.abortEarly && issues)) {
|
|
1092
|
+
for (var key in input) {
|
|
1093
|
+
if (!(key in entries)) {
|
|
1094
|
+
var value2 = input[key];
|
|
1095
|
+
var result = rest._parse(value2, info);
|
|
1096
|
+
if (result.issues) {
|
|
1097
|
+
var pathItem = {
|
|
1098
|
+
type: "object",
|
|
1099
|
+
input: input,
|
|
1100
|
+
key: key,
|
|
1101
|
+
value: value2
|
|
1102
|
+
};
|
|
1103
|
+
var _iterator12 = _createForOfIteratorHelper(result.issues),
|
|
1104
|
+
_step12;
|
|
1105
|
+
try {
|
|
1106
|
+
for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
|
|
1107
|
+
var _issues6;
|
|
1108
|
+
var issue = _step12.value;
|
|
1109
|
+
if (issue.path) {
|
|
1110
|
+
issue.path.unshift(pathItem);
|
|
1111
|
+
} else {
|
|
1112
|
+
issue.path = [pathItem];
|
|
1113
|
+
}
|
|
1114
|
+
(_issues6 = issues) === null || _issues6 === void 0 || _issues6.push(issue);
|
|
1115
|
+
}
|
|
1116
|
+
} catch (err) {
|
|
1117
|
+
_iterator12.e(err);
|
|
1118
|
+
} finally {
|
|
1119
|
+
_iterator12.f();
|
|
1120
|
+
}
|
|
1121
|
+
if (!issues) {
|
|
1122
|
+
issues = result.issues;
|
|
1123
|
+
}
|
|
1124
|
+
if (info !== null && info !== void 0 && info.abortEarly) {
|
|
1125
|
+
break;
|
|
1126
|
+
}
|
|
1127
|
+
} else {
|
|
1128
|
+
output[key] = result.output;
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
return issues ? getIssues(issues) : executePipe(output, pipe, info, "object");
|
|
1134
|
+
}
|
|
1135
|
+
};
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
// src/schemas/optional/optional.ts
|
|
1139
|
+
function optional(wrapped, default_) {
|
|
1140
|
+
return {
|
|
1141
|
+
/**
|
|
1142
|
+
* The schema type.
|
|
1143
|
+
*/
|
|
1144
|
+
type: "optional",
|
|
1145
|
+
/**
|
|
1146
|
+
* The wrapped schema.
|
|
1147
|
+
*/
|
|
1148
|
+
wrapped: wrapped,
|
|
1149
|
+
/**
|
|
1150
|
+
* Returns the default value.
|
|
1151
|
+
*/
|
|
1152
|
+
getDefault: function getDefault() {
|
|
1153
|
+
return typeof default_ === "function" ? default_() : default_;
|
|
1154
|
+
},
|
|
1155
|
+
/**
|
|
1156
|
+
* Whether it's async.
|
|
1157
|
+
*/
|
|
1158
|
+
async: false,
|
|
1159
|
+
/**
|
|
1160
|
+
* Parses unknown input based on its schema.
|
|
1161
|
+
*
|
|
1162
|
+
* @param input The input to be parsed.
|
|
1163
|
+
* @param info The parse info.
|
|
1164
|
+
*
|
|
1165
|
+
* @returns The parsed output.
|
|
1166
|
+
*/
|
|
1167
|
+
_parse: function _parse(input, info) {
|
|
1168
|
+
if (input === void 0) {
|
|
1169
|
+
var override = this.getDefault();
|
|
1170
|
+
if (override === void 0) {
|
|
1171
|
+
return getOutput(input);
|
|
1172
|
+
}
|
|
1173
|
+
input = override;
|
|
1174
|
+
}
|
|
1175
|
+
return wrapped._parse(input, info);
|
|
1176
|
+
}
|
|
1177
|
+
};
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
// src/schemas/string/string.ts
|
|
1181
|
+
function string(arg1, arg2) {
|
|
1182
|
+
var _getDefaultArgs37 = getDefaultArgs(arg1, arg2),
|
|
1183
|
+
_getDefaultArgs38 = _slicedToArray(_getDefaultArgs37, 2),
|
|
1184
|
+
error = _getDefaultArgs38[0],
|
|
1185
|
+
pipe = _getDefaultArgs38[1];
|
|
1186
|
+
return {
|
|
1187
|
+
/**
|
|
1188
|
+
* The schema type.
|
|
1189
|
+
*/
|
|
1190
|
+
type: "string",
|
|
1191
|
+
/**
|
|
1192
|
+
* Whether it's async.
|
|
1193
|
+
*/
|
|
1194
|
+
async: false,
|
|
1195
|
+
/**
|
|
1196
|
+
* Parses unknown input based on its schema.
|
|
1197
|
+
*
|
|
1198
|
+
* @param input The input to be parsed.
|
|
1199
|
+
* @param info The parse info.
|
|
1200
|
+
*
|
|
1201
|
+
* @returns The parsed output.
|
|
1202
|
+
*/
|
|
1203
|
+
_parse: function _parse(input, info) {
|
|
1204
|
+
if (typeof input !== "string") {
|
|
1205
|
+
return getSchemaIssues(info, "type", "string", error || "Invalid type", input);
|
|
1206
|
+
}
|
|
1207
|
+
return executePipe(input, pipe, info, "string");
|
|
1208
|
+
}
|
|
1209
|
+
};
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
// src/schemas/record/utils/getRecordArgs/getRecordArgs.ts
|
|
1213
|
+
function getRecordArgs(arg1, arg2, arg3, arg4) {
|
|
1214
|
+
if (_typeof(arg2) === "object" && !Array.isArray(arg2)) {
|
|
1215
|
+
var _getDefaultArgs41 = getDefaultArgs(arg3, arg4),
|
|
1216
|
+
_getDefaultArgs42 = _slicedToArray(_getDefaultArgs41, 2),
|
|
1217
|
+
error2 = _getDefaultArgs42[0],
|
|
1218
|
+
pipe2 = _getDefaultArgs42[1];
|
|
1219
|
+
return [arg1, arg2, error2, pipe2];
|
|
1220
|
+
}
|
|
1221
|
+
var _getDefaultArgs43 = getDefaultArgs(arg2, arg3),
|
|
1222
|
+
_getDefaultArgs44 = _slicedToArray(_getDefaultArgs43, 2),
|
|
1223
|
+
error = _getDefaultArgs44[0],
|
|
1224
|
+
pipe = _getDefaultArgs44[1];
|
|
1225
|
+
return [string(), arg1, error, pipe];
|
|
1226
|
+
}
|
|
1227
|
+
|
|
1228
|
+
// src/schemas/record/values.ts
|
|
1229
|
+
var BLOCKED_KEYS = ["__proto__", "prototype", "constructor"];
|
|
1230
|
+
|
|
1231
|
+
// src/schemas/record/record.ts
|
|
1232
|
+
function record(arg1, arg2, arg3, arg4) {
|
|
1233
|
+
var _getRecordArgs = getRecordArgs(arg1, arg2, arg3, arg4),
|
|
1234
|
+
_getRecordArgs2 = _slicedToArray(_getRecordArgs, 4),
|
|
1235
|
+
key = _getRecordArgs2[0],
|
|
1236
|
+
value2 = _getRecordArgs2[1],
|
|
1237
|
+
error = _getRecordArgs2[2],
|
|
1238
|
+
pipe = _getRecordArgs2[3];
|
|
1239
|
+
return {
|
|
1240
|
+
/**
|
|
1241
|
+
* The schema type.
|
|
1242
|
+
*/
|
|
1243
|
+
type: "record",
|
|
1244
|
+
/**
|
|
1245
|
+
* The key schema.
|
|
1246
|
+
*/
|
|
1247
|
+
key: key,
|
|
1248
|
+
/**
|
|
1249
|
+
* The value schema.
|
|
1250
|
+
*/
|
|
1251
|
+
value: value2,
|
|
1252
|
+
/**
|
|
1253
|
+
* Whether it's async.
|
|
1254
|
+
*/
|
|
1255
|
+
async: false,
|
|
1256
|
+
/**
|
|
1257
|
+
* Parses unknown input based on its schema.
|
|
1258
|
+
*
|
|
1259
|
+
* @param input The input to be parsed.
|
|
1260
|
+
* @param info The parse info.
|
|
1261
|
+
*
|
|
1262
|
+
* @returns The parsed output.
|
|
1263
|
+
*/
|
|
1264
|
+
_parse: function _parse(input, info) {
|
|
1265
|
+
if (!input || _typeof(input) !== "object") {
|
|
1266
|
+
return getSchemaIssues(info, "type", "record", error || "Invalid type", input);
|
|
1267
|
+
}
|
|
1268
|
+
var issues;
|
|
1269
|
+
var output = {};
|
|
1270
|
+
for (var _i = 0, _Object$entries = Object.entries(input); _i < _Object$entries.length; _i++) {
|
|
1271
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
1272
|
+
inputKey = _Object$entries$_i[0],
|
|
1273
|
+
inputValue = _Object$entries$_i[1];
|
|
1274
|
+
if (!BLOCKED_KEYS.includes(inputKey)) {
|
|
1275
|
+
var pathItem = void 0;
|
|
1276
|
+
var keyResult = key._parse(inputKey, {
|
|
1277
|
+
origin: "key",
|
|
1278
|
+
abortEarly: info === null || info === void 0 ? void 0 : info.abortEarly,
|
|
1279
|
+
abortPipeEarly: info === null || info === void 0 ? void 0 : info.abortPipeEarly,
|
|
1280
|
+
skipPipe: info === null || info === void 0 ? void 0 : info.skipPipe
|
|
1281
|
+
});
|
|
1282
|
+
if (keyResult.issues) {
|
|
1283
|
+
pathItem = {
|
|
1284
|
+
type: "record",
|
|
1285
|
+
input: input,
|
|
1286
|
+
key: inputKey,
|
|
1287
|
+
value: inputValue
|
|
1288
|
+
};
|
|
1289
|
+
var _iterator16 = _createForOfIteratorHelper(keyResult.issues),
|
|
1290
|
+
_step16;
|
|
1291
|
+
try {
|
|
1292
|
+
for (_iterator16.s(); !(_step16 = _iterator16.n()).done;) {
|
|
1293
|
+
var _issues10;
|
|
1294
|
+
var issue = _step16.value;
|
|
1295
|
+
issue.path = [pathItem];
|
|
1296
|
+
(_issues10 = issues) === null || _issues10 === void 0 || _issues10.push(issue);
|
|
1297
|
+
}
|
|
1298
|
+
} catch (err) {
|
|
1299
|
+
_iterator16.e(err);
|
|
1300
|
+
} finally {
|
|
1301
|
+
_iterator16.f();
|
|
1302
|
+
}
|
|
1303
|
+
if (!issues) {
|
|
1304
|
+
issues = keyResult.issues;
|
|
1305
|
+
}
|
|
1306
|
+
if (info !== null && info !== void 0 && info.abortEarly) {
|
|
1307
|
+
break;
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
var valueResult = value2._parse(inputValue, info);
|
|
1311
|
+
if (valueResult.issues) {
|
|
1312
|
+
pathItem = pathItem || {
|
|
1313
|
+
type: "record",
|
|
1314
|
+
input: input,
|
|
1315
|
+
key: inputKey,
|
|
1316
|
+
value: inputValue
|
|
1317
|
+
};
|
|
1318
|
+
var _iterator17 = _createForOfIteratorHelper(valueResult.issues),
|
|
1319
|
+
_step17;
|
|
1320
|
+
try {
|
|
1321
|
+
for (_iterator17.s(); !(_step17 = _iterator17.n()).done;) {
|
|
1322
|
+
var _issues11;
|
|
1323
|
+
var _issue3 = _step17.value;
|
|
1324
|
+
if (_issue3.path) {
|
|
1325
|
+
_issue3.path.unshift(pathItem);
|
|
1326
|
+
} else {
|
|
1327
|
+
_issue3.path = [pathItem];
|
|
1328
|
+
}
|
|
1329
|
+
(_issues11 = issues) === null || _issues11 === void 0 || _issues11.push(_issue3);
|
|
1330
|
+
}
|
|
1331
|
+
} catch (err) {
|
|
1332
|
+
_iterator17.e(err);
|
|
1333
|
+
} finally {
|
|
1334
|
+
_iterator17.f();
|
|
1335
|
+
}
|
|
1336
|
+
if (!issues) {
|
|
1337
|
+
issues = valueResult.issues;
|
|
1338
|
+
}
|
|
1339
|
+
if (info !== null && info !== void 0 && info.abortEarly) {
|
|
1340
|
+
break;
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
if (!keyResult.issues && !valueResult.issues) {
|
|
1344
|
+
output[keyResult.output] = valueResult.output;
|
|
1345
|
+
}
|
|
1346
|
+
}
|
|
1347
|
+
}
|
|
1348
|
+
return issues ? getIssues(issues) : executePipe(output, pipe, info, "record");
|
|
1349
|
+
}
|
|
1350
|
+
};
|
|
1351
|
+
}
|
|
1352
|
+
|
|
1353
|
+
// src/schemas/union/union.ts
|
|
1354
|
+
function union(options, error) {
|
|
1355
|
+
return {
|
|
1356
|
+
/**
|
|
1357
|
+
* The schema type.
|
|
1358
|
+
*/
|
|
1359
|
+
type: "union",
|
|
1360
|
+
/**
|
|
1361
|
+
* The union options.
|
|
1362
|
+
*/
|
|
1363
|
+
options: options,
|
|
1364
|
+
/**
|
|
1365
|
+
* Whether it's async.
|
|
1366
|
+
*/
|
|
1367
|
+
async: false,
|
|
1368
|
+
/**
|
|
1369
|
+
* Parses unknown input based on its schema.
|
|
1370
|
+
*
|
|
1371
|
+
* @param input The input to be parsed.
|
|
1372
|
+
* @param info The parse info.
|
|
1373
|
+
*
|
|
1374
|
+
* @returns The parsed output.
|
|
1375
|
+
*/
|
|
1376
|
+
_parse: function _parse(input, info) {
|
|
1377
|
+
var issues;
|
|
1378
|
+
var output;
|
|
1379
|
+
var _iterator26 = _createForOfIteratorHelper(options),
|
|
1380
|
+
_step26;
|
|
1381
|
+
try {
|
|
1382
|
+
for (_iterator26.s(); !(_step26 = _iterator26.n()).done;) {
|
|
1383
|
+
var schema = _step26.value;
|
|
1384
|
+
var result = schema._parse(input, info);
|
|
1385
|
+
if (result.issues) {
|
|
1386
|
+
if (issues) {
|
|
1387
|
+
var _iterator27 = _createForOfIteratorHelper(result.issues),
|
|
1388
|
+
_step27;
|
|
1389
|
+
try {
|
|
1390
|
+
for (_iterator27.s(); !(_step27 = _iterator27.n()).done;) {
|
|
1391
|
+
var issue = _step27.value;
|
|
1392
|
+
issues.push(issue);
|
|
1393
|
+
}
|
|
1394
|
+
} catch (err) {
|
|
1395
|
+
_iterator27.e(err);
|
|
1396
|
+
} finally {
|
|
1397
|
+
_iterator27.f();
|
|
1398
|
+
}
|
|
1399
|
+
} else {
|
|
1400
|
+
issues = result.issues;
|
|
1401
|
+
}
|
|
1402
|
+
} else {
|
|
1403
|
+
output = [result.output];
|
|
1404
|
+
break;
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
} catch (err) {
|
|
1408
|
+
_iterator26.e(err);
|
|
1409
|
+
} finally {
|
|
1410
|
+
_iterator26.f();
|
|
1411
|
+
}
|
|
1412
|
+
return output ? getOutput(output[0]) : getSchemaIssues(info, "type", "union", error || "Invalid type", input, issues);
|
|
1413
|
+
}
|
|
1414
|
+
};
|
|
1415
|
+
}
|
|
1416
|
+
|
|
1417
|
+
// src/schemas/unknown/unknown.ts
|
|
1418
|
+
function unknown() {
|
|
1419
|
+
var pipe = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
1420
|
+
return {
|
|
1421
|
+
/**
|
|
1422
|
+
* The schema type.
|
|
1423
|
+
*/
|
|
1424
|
+
type: "unknown",
|
|
1425
|
+
/**
|
|
1426
|
+
* Whether it's async.
|
|
1427
|
+
*/
|
|
1428
|
+
async: false,
|
|
1429
|
+
/**
|
|
1430
|
+
* Parses unknown input based on its schema.
|
|
1431
|
+
*
|
|
1432
|
+
* @param input The input to be parsed.
|
|
1433
|
+
* @param info The parse info.
|
|
1434
|
+
*
|
|
1435
|
+
* @returns The parsed output.
|
|
1436
|
+
*/
|
|
1437
|
+
_parse: function _parse(input, info) {
|
|
1438
|
+
return executePipe(input, pipe, info, "unknown");
|
|
1439
|
+
}
|
|
1440
|
+
};
|
|
1441
|
+
}
|
|
1442
|
+
|
|
1443
|
+
// src/methods/omit/omit.ts
|
|
1444
|
+
function omit(schema, keys, arg3, arg4, arg5) {
|
|
1445
|
+
var _getRestAndDefaultArg13 = getRestAndDefaultArgs(arg3, arg4, arg5),
|
|
1446
|
+
_getRestAndDefaultArg14 = _slicedToArray(_getRestAndDefaultArg13, 3),
|
|
1447
|
+
rest = _getRestAndDefaultArg14[0],
|
|
1448
|
+
error = _getRestAndDefaultArg14[1],
|
|
1449
|
+
pipe = _getRestAndDefaultArg14[2];
|
|
1450
|
+
return object(Object.entries(schema.entries).reduce(function (entries, _ref24) {
|
|
1451
|
+
var _ref25 = _slicedToArray(_ref24, 2),
|
|
1452
|
+
key = _ref25[0],
|
|
1453
|
+
schema2 = _ref25[1];
|
|
1454
|
+
return keys.includes(key) ? entries : _objectSpread2(_objectSpread2({}, entries), {}, _defineProperty({}, key, schema2));
|
|
1455
|
+
}, {}), rest, error, pipe);
|
|
1456
|
+
}
|
|
1457
|
+
|
|
1458
|
+
// src/methods/parse/parse.ts
|
|
1459
|
+
function parse(schema, input, info) {
|
|
1460
|
+
var result = schema._parse(input, info);
|
|
1461
|
+
if (result.issues) {
|
|
1462
|
+
throw new ValiError(result.issues);
|
|
1463
|
+
}
|
|
1464
|
+
return result.output;
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1467
|
+
// src/methods/safeParse/safeParse.ts
|
|
1468
|
+
function safeParse(schema, input, info) {
|
|
1469
|
+
var result = schema._parse(input, info);
|
|
1470
|
+
return result.issues ? {
|
|
1471
|
+
success: false,
|
|
1472
|
+
error: new ValiError(result.issues),
|
|
1473
|
+
issues: result.issues
|
|
1474
|
+
} : {
|
|
1475
|
+
success: true,
|
|
1476
|
+
data: result.output,
|
|
1477
|
+
output: result.output
|
|
1478
|
+
};
|
|
1479
|
+
}
|
|
1480
|
+
|
|
1481
|
+
// src/validations/custom/custom.ts
|
|
1482
|
+
function custom(requirement, error) {
|
|
1483
|
+
return function (input) {
|
|
1484
|
+
return !requirement(input) ? getPipeIssues("custom", error || "Invalid input", input) : getOutput(input);
|
|
1485
|
+
};
|
|
1486
|
+
}
|
|
1487
|
+
|
|
1488
|
+
// src/validations/notValue/notValue.ts
|
|
1489
|
+
function notValue(requirement, error) {
|
|
1490
|
+
return function (input) {
|
|
1491
|
+
return input === requirement ? getPipeIssues("not_value", error || "Invalid value", input) : getOutput(input);
|
|
1492
|
+
};
|
|
1493
|
+
}
|
|
1494
|
+
|
|
1495
|
+
// src/validations/regex/regex.ts
|
|
1496
|
+
function regex(requirement, error) {
|
|
1497
|
+
return function (input) {
|
|
1498
|
+
return !requirement.test(input) ? getPipeIssues("regex", error || "Invalid regex", input) : getOutput(input);
|
|
1499
|
+
};
|
|
1500
|
+
}
|
|
1501
|
+
|
|
1502
|
+
const ZHTML5Fonts = union([
|
|
1503
|
+
literal("gothic"),
|
|
1504
|
+
literal("mincho"),
|
|
1505
|
+
literal("defont"),
|
|
1506
|
+
]);
|
|
1507
|
+
|
|
1508
|
+
const ZFormattedComment = object({
|
|
1509
|
+
id: optional(number(), 0),
|
|
1510
|
+
vpos: optional(number(), 0),
|
|
1511
|
+
content: optional(string(), ""),
|
|
1512
|
+
date: optional(number(), 0),
|
|
1513
|
+
date_usec: optional(number(), 0),
|
|
1514
|
+
owner: optional(_boolean(), false),
|
|
1515
|
+
premium: optional(_boolean(), false),
|
|
1516
|
+
mail: optional(array(string()), []),
|
|
1517
|
+
user_id: optional(number(), 0),
|
|
1518
|
+
layer: optional(number(), -1),
|
|
1519
|
+
is_my_post: optional(_boolean(), false),
|
|
1520
|
+
});
|
|
1521
|
+
omit(ZFormattedComment, [
|
|
1522
|
+
"layer",
|
|
1523
|
+
"user_id",
|
|
1524
|
+
"is_my_post",
|
|
1525
|
+
]);
|
|
1526
|
+
|
|
1527
|
+
const ZApiChat = object({
|
|
1528
|
+
thread: optional(string(), ""),
|
|
1529
|
+
no: optional(number(), 0),
|
|
1530
|
+
vpos: number(),
|
|
1531
|
+
date: optional(number(), 0),
|
|
1532
|
+
date_usec: optional(number(), 0),
|
|
1533
|
+
nicoru: optional(number(), 0),
|
|
1534
|
+
premium: optional(number(), 0),
|
|
1535
|
+
anonymity: optional(number(), 0),
|
|
1536
|
+
user_id: optional(string(), ""),
|
|
1537
|
+
mail: optional(string(), ""),
|
|
1538
|
+
content: string(),
|
|
1539
|
+
deleted: optional(number(), 0),
|
|
1540
|
+
});
|
|
1541
|
+
const ZRawApiResponse = union([
|
|
1542
|
+
object({ chat: ZApiChat }),
|
|
1543
|
+
record(string([notValue("chat")]), unknown()),
|
|
1544
|
+
]);
|
|
1545
|
+
object({
|
|
1546
|
+
content: string(),
|
|
1547
|
+
});
|
|
1548
|
+
object({
|
|
1549
|
+
resultcode: number(),
|
|
1550
|
+
thread: string(),
|
|
1551
|
+
server_time: number(),
|
|
1552
|
+
ticket: string(),
|
|
1553
|
+
revision: number(),
|
|
1554
|
+
});
|
|
1555
|
+
object({
|
|
1556
|
+
thread: string(),
|
|
1557
|
+
count: number(),
|
|
1558
|
+
});
|
|
1559
|
+
object({
|
|
1560
|
+
thread: string(),
|
|
1561
|
+
num_res: number(),
|
|
1562
|
+
});
|
|
1563
|
+
|
|
1564
|
+
const ZOwnerComment = object({
|
|
1565
|
+
time: string(),
|
|
1566
|
+
command: string(),
|
|
1567
|
+
comment: string(),
|
|
1568
|
+
});
|
|
1569
|
+
|
|
1570
|
+
const ZV1Comment = object({
|
|
1571
|
+
id: string(),
|
|
1572
|
+
no: number(),
|
|
1573
|
+
vposMs: number(),
|
|
1574
|
+
body: string(),
|
|
1575
|
+
commands: array(string()),
|
|
1576
|
+
userId: string(),
|
|
1577
|
+
isPremium: _boolean(),
|
|
1578
|
+
score: number(),
|
|
1579
|
+
postedAt: string(),
|
|
1580
|
+
nicoruCount: number(),
|
|
1581
|
+
nicoruId: nullable(string()),
|
|
1582
|
+
source: string(),
|
|
1583
|
+
isMyPost: _boolean(),
|
|
1584
|
+
});
|
|
1585
|
+
const ZV1Thread = object({
|
|
1586
|
+
id: unknown(),
|
|
1587
|
+
fork: string(),
|
|
1588
|
+
commentCount: optional(number(), 0),
|
|
1589
|
+
comments: array(ZV1Comment),
|
|
1590
|
+
});
|
|
1591
|
+
|
|
1592
|
+
const ZCommentFont = union([
|
|
1593
|
+
literal("defont"),
|
|
1594
|
+
literal("mincho"),
|
|
1595
|
+
literal("gothic"),
|
|
1596
|
+
literal("gulim"),
|
|
1597
|
+
literal("simsun"),
|
|
1598
|
+
]);
|
|
1599
|
+
const ZCommentFlashFont = union([
|
|
1600
|
+
literal("defont"),
|
|
1601
|
+
literal("gulim"),
|
|
1602
|
+
literal("simsun"),
|
|
1603
|
+
]);
|
|
1604
|
+
const ZCommentContentItemSpacer = object({
|
|
1605
|
+
type: literal("spacer"),
|
|
1606
|
+
char: string(),
|
|
1607
|
+
charWidth: number(),
|
|
1608
|
+
isButton: optional(_boolean()),
|
|
1609
|
+
font: optional(ZCommentFlashFont),
|
|
1610
|
+
count: number(),
|
|
1611
|
+
});
|
|
1612
|
+
const ZCommentContentItemText = object({
|
|
1613
|
+
type: literal("text"),
|
|
1614
|
+
content: string(),
|
|
1615
|
+
slicedContent: array(string()),
|
|
1616
|
+
isButton: optional(_boolean()),
|
|
1617
|
+
font: optional(ZCommentFlashFont),
|
|
1618
|
+
width: optional(array(number())),
|
|
1619
|
+
});
|
|
1620
|
+
const ZCommentContentItem = union([
|
|
1621
|
+
ZCommentContentItemSpacer,
|
|
1622
|
+
ZCommentContentItemText,
|
|
1623
|
+
]);
|
|
1624
|
+
const ZCommentMeasuredContentItemText = intersect([
|
|
1625
|
+
ZCommentContentItem,
|
|
1626
|
+
object({
|
|
1627
|
+
width: array(number()),
|
|
1628
|
+
}),
|
|
1629
|
+
]);
|
|
1630
|
+
const ZCommentMeasuredContentItem = union([
|
|
1631
|
+
ZCommentMeasuredContentItemText,
|
|
1632
|
+
ZCommentContentItemSpacer,
|
|
1633
|
+
]);
|
|
1634
|
+
const ZCommentSize = union([
|
|
1635
|
+
literal("big"),
|
|
1636
|
+
literal("medium"),
|
|
1637
|
+
literal("small"),
|
|
1638
|
+
]);
|
|
1639
|
+
const ZCommentLoc = union([
|
|
1640
|
+
literal("ue"),
|
|
1641
|
+
literal("naka"),
|
|
1642
|
+
literal("shita"),
|
|
1643
|
+
]);
|
|
1644
|
+
const ZMeasureInput = object({
|
|
1645
|
+
font: ZCommentFont,
|
|
1646
|
+
content: array(ZCommentContentItem),
|
|
1647
|
+
lineHeight: number(),
|
|
1648
|
+
charSize: number(),
|
|
1649
|
+
lineCount: number(),
|
|
1650
|
+
});
|
|
1651
|
+
|
|
209
1652
|
const colors = {
|
|
210
1653
|
white: "#FFFFFF",
|
|
211
1654
|
red: "#FF0000",
|
|
@@ -245,81 +1688,6 @@
|
|
|
245
1688
|
const isNumber = (i) => typeof i === "number";
|
|
246
1689
|
const isObject = (i) => typeof i === "object";
|
|
247
1690
|
const typeGuard = {
|
|
248
|
-
formatted: {
|
|
249
|
-
comment: (i) => objectVerify(i, [
|
|
250
|
-
"id",
|
|
251
|
-
"vpos",
|
|
252
|
-
"content",
|
|
253
|
-
"date",
|
|
254
|
-
"date_usec",
|
|
255
|
-
"owner",
|
|
256
|
-
"premium",
|
|
257
|
-
"mail",
|
|
258
|
-
"user_id",
|
|
259
|
-
"layer",
|
|
260
|
-
"is_my_post",
|
|
261
|
-
]),
|
|
262
|
-
comments: (i) => {
|
|
263
|
-
if (typeof i !== "object")
|
|
264
|
-
return false;
|
|
265
|
-
for (const item of i) {
|
|
266
|
-
if (!typeGuard.formatted.comment(item))
|
|
267
|
-
return false;
|
|
268
|
-
}
|
|
269
|
-
return true;
|
|
270
|
-
},
|
|
271
|
-
legacyComment: (i) => objectVerify(i, [
|
|
272
|
-
"id",
|
|
273
|
-
"vpos",
|
|
274
|
-
"content",
|
|
275
|
-
"date",
|
|
276
|
-
"owner",
|
|
277
|
-
"premium",
|
|
278
|
-
"mail",
|
|
279
|
-
]),
|
|
280
|
-
legacyComments: (i) => {
|
|
281
|
-
if (typeof i !== "object")
|
|
282
|
-
return false;
|
|
283
|
-
for (const item of i) {
|
|
284
|
-
if (!typeGuard.formatted.legacyComment(item))
|
|
285
|
-
return false;
|
|
286
|
-
}
|
|
287
|
-
return true;
|
|
288
|
-
},
|
|
289
|
-
},
|
|
290
|
-
legacy: {
|
|
291
|
-
rawApiResponses: (i) => {
|
|
292
|
-
if (typeof i !== "object")
|
|
293
|
-
return false;
|
|
294
|
-
for (const itemWrapper of i) {
|
|
295
|
-
for (const key of Object.keys(itemWrapper)) {
|
|
296
|
-
const item = itemWrapper[key];
|
|
297
|
-
if (!item)
|
|
298
|
-
continue;
|
|
299
|
-
if (!(typeGuard.legacy.apiChat(item) ||
|
|
300
|
-
typeGuard.legacy.apiGlobalNumRes(item) ||
|
|
301
|
-
typeGuard.legacy.apiLeaf(item) ||
|
|
302
|
-
typeGuard.legacy.apiPing(item) ||
|
|
303
|
-
typeGuard.legacy.apiThread(item))) {
|
|
304
|
-
return false;
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
return true;
|
|
309
|
-
},
|
|
310
|
-
apiChat: (i) => typeof i === "object" &&
|
|
311
|
-
objectVerify(i, ["content", "date", "no", "thread", "vpos"]),
|
|
312
|
-
apiGlobalNumRes: (i) => objectVerify(i, ["num_res", "thread"]),
|
|
313
|
-
apiLeaf: (i) => objectVerify(i, ["count", "thread"]),
|
|
314
|
-
apiPing: (i) => objectVerify(i, ["content"]),
|
|
315
|
-
apiThread: (i) => objectVerify(i, [
|
|
316
|
-
"resultcode",
|
|
317
|
-
"revision",
|
|
318
|
-
"server_time",
|
|
319
|
-
"thread",
|
|
320
|
-
"ticket",
|
|
321
|
-
]),
|
|
322
|
-
},
|
|
323
1691
|
xmlDocument: (i) => {
|
|
324
1692
|
if (!i.documentElement ||
|
|
325
1693
|
i.documentElement.nodeName !== "packet")
|
|
@@ -335,91 +1703,45 @@
|
|
|
335
1703
|
return true;
|
|
336
1704
|
},
|
|
337
1705
|
legacyOwner: {
|
|
338
|
-
comments: (i) =>
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
1706
|
+
comments: (i) => is(string([
|
|
1707
|
+
custom((i) => {
|
|
1708
|
+
const lists = i.split(/\r\n|\r|\n/);
|
|
1709
|
+
for (const list of lists) {
|
|
1710
|
+
if (list.split(":").length < 3) {
|
|
1711
|
+
return false;
|
|
1712
|
+
}
|
|
345
1713
|
}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
},
|
|
350
|
-
owner: {
|
|
351
|
-
comment: (i) => objectVerify(i, ["time", "command", "comment"]),
|
|
352
|
-
comments: (i) => {
|
|
353
|
-
if (typeof i !== "object")
|
|
354
|
-
return false;
|
|
355
|
-
for (const item of i) {
|
|
356
|
-
if (!typeGuard.owner.comment(item))
|
|
357
|
-
return false;
|
|
358
|
-
}
|
|
359
|
-
return true;
|
|
360
|
-
},
|
|
361
|
-
},
|
|
362
|
-
v1: {
|
|
363
|
-
comment: (i) => objectVerify(i, [
|
|
364
|
-
"id",
|
|
365
|
-
"no",
|
|
366
|
-
"vposMs",
|
|
367
|
-
"body",
|
|
368
|
-
"commands",
|
|
369
|
-
"userId",
|
|
370
|
-
"isPremium",
|
|
371
|
-
"score",
|
|
372
|
-
"postedAt",
|
|
373
|
-
"nicoruCount",
|
|
374
|
-
"nicoruId",
|
|
375
|
-
"source",
|
|
376
|
-
"isMyPost",
|
|
377
|
-
]),
|
|
378
|
-
thread: (i) => {
|
|
379
|
-
if (!objectVerify(i, ["id", "fork", "commentCount", "comments"]))
|
|
380
|
-
return false;
|
|
381
|
-
for (const value of i.comments) {
|
|
382
|
-
if (!typeGuard.v1.comment(value))
|
|
383
|
-
return false;
|
|
384
|
-
}
|
|
385
|
-
return true;
|
|
386
|
-
},
|
|
387
|
-
threads: (i) => {
|
|
388
|
-
if (typeof i !== "object")
|
|
389
|
-
return false;
|
|
390
|
-
for (const item of i) {
|
|
391
|
-
if (!typeGuard.v1.thread(item))
|
|
392
|
-
return false;
|
|
393
|
-
}
|
|
394
|
-
return true;
|
|
395
|
-
},
|
|
1714
|
+
return true;
|
|
1715
|
+
}),
|
|
1716
|
+
]), i),
|
|
396
1717
|
},
|
|
397
1718
|
nicoScript: {
|
|
398
1719
|
range: {
|
|
399
|
-
target: (i) =>
|
|
400
|
-
!!RegExp(/^(?:\u6295?\u30b3\u30e1|\u5168)$/).exec(i),
|
|
1720
|
+
target: (i) => is(string([regex(/^(?:\u6295?\u30b3\u30e1|\u5168)$/)]), i),
|
|
401
1721
|
},
|
|
402
1722
|
replace: {
|
|
403
|
-
range: (i) =>
|
|
404
|
-
target: (i) =>
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
1723
|
+
range: (i) => is(string([regex(/^[\u5358\u5168]$/)]), i),
|
|
1724
|
+
target: (i) => is(string([
|
|
1725
|
+
regex(/^(?:\u30b3\u30e1|\u6295\u30b3\u30e1|\u5168|\u542b\u3080|\u542b\u307e\u306a\u3044)$/),
|
|
1726
|
+
]), i),
|
|
1727
|
+
condition: (i) => is(string([
|
|
1728
|
+
regex(/^(?:\u90e8\u5206\u4e00\u81f4|\u5b8c\u5168\u4e00\u81f4)$/),
|
|
1729
|
+
]), i),
|
|
408
1730
|
},
|
|
409
1731
|
},
|
|
410
1732
|
comment: {
|
|
411
|
-
font: (i) => typeof i === "string" && !!RegExp(/^(?:gothic|mincho|defont)$/).exec(i),
|
|
412
|
-
loc: (i) => typeof i === "string" && !!RegExp(/^(?:ue|naka|shita)$/).exec(i),
|
|
413
|
-
size: (i) => typeof i === "string" && !!RegExp(/^(?:big|medium|small)$/).exec(i),
|
|
414
1733
|
command: {
|
|
415
|
-
key: (i) =>
|
|
416
|
-
|
|
1734
|
+
key: (i) => is(union([
|
|
1735
|
+
literal("full"),
|
|
1736
|
+
literal("ender"),
|
|
1737
|
+
literal("_live"),
|
|
1738
|
+
literal("invisible"),
|
|
1739
|
+
]), i),
|
|
417
1740
|
},
|
|
418
|
-
color: (i) =>
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
!!RegExp(/^#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/).exec(i),
|
|
1741
|
+
color: (i) => is(string([custom((i) => Object.keys(colors).includes(i))]), i),
|
|
1742
|
+
colorCodeAllowAlpha: (i) => is(string([
|
|
1743
|
+
regex(/^#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/),
|
|
1744
|
+
]), i),
|
|
423
1745
|
},
|
|
424
1746
|
config: {
|
|
425
1747
|
initOptions: (item) => {
|
|
@@ -452,25 +1774,17 @@
|
|
|
452
1774
|
},
|
|
453
1775
|
},
|
|
454
1776
|
internal: {
|
|
455
|
-
|
|
456
|
-
CommentMeasuredContentItemArray: (i) => Array.isArray(i) &&
|
|
457
|
-
i.every(typeGuard.internal.CommentMeasuredContentItem),
|
|
1777
|
+
CommentMeasuredContentItemArray: (i) => is(array(ZCommentMeasuredContentItem), i),
|
|
458
1778
|
MultiConfigItem: (i) => typeof i === "object" && objectVerify(i, ["html5", "flash"]),
|
|
459
|
-
HTML5Fonts: (i) =>
|
|
460
|
-
MeasureInput: (i) =>
|
|
461
|
-
"font",
|
|
462
|
-
"content",
|
|
463
|
-
"lineHeight",
|
|
464
|
-
"charSize",
|
|
465
|
-
"lineCount",
|
|
466
|
-
]),
|
|
1779
|
+
HTML5Fonts: (i) => is(ZHTML5Fonts, i),
|
|
1780
|
+
MeasureInput: (i) => is(ZMeasureInput, i),
|
|
467
1781
|
},
|
|
468
1782
|
};
|
|
469
1783
|
const objectVerify = (item, keys) => {
|
|
470
1784
|
if (typeof item !== "object" || !item)
|
|
471
1785
|
return false;
|
|
472
1786
|
for (const key of keys) {
|
|
473
|
-
if (!Object.
|
|
1787
|
+
if (!Object.hasOwn(item, key))
|
|
474
1788
|
return false;
|
|
475
1789
|
}
|
|
476
1790
|
return true;
|
|
@@ -576,12 +1890,12 @@
|
|
|
576
1890
|
};
|
|
577
1891
|
const parseBrackets = (input) => {
|
|
578
1892
|
const content = input.split(""), result = [];
|
|
579
|
-
let quote = "",
|
|
1893
|
+
let quote = "", lastChar = "", string = "";
|
|
580
1894
|
for (const i of content) {
|
|
581
1895
|
if (RegExp(/^["'\u300c]$/).exec(i) && quote === "") {
|
|
582
1896
|
quote = i;
|
|
583
1897
|
}
|
|
584
|
-
else if (RegExp(/^["']$/).exec(i) && quote === i &&
|
|
1898
|
+
else if (RegExp(/^["']$/).exec(i) && quote === i && lastChar !== "\\") {
|
|
585
1899
|
result.push(string.replaceAll("\\n", "\n"));
|
|
586
1900
|
quote = "";
|
|
587
1901
|
string = "";
|
|
@@ -600,7 +1914,7 @@
|
|
|
600
1914
|
else {
|
|
601
1915
|
string += i;
|
|
602
1916
|
}
|
|
603
|
-
|
|
1917
|
+
lastChar = i;
|
|
604
1918
|
}
|
|
605
1919
|
result.push(string);
|
|
606
1920
|
return result;
|
|
@@ -798,11 +2112,11 @@
|
|
|
798
2112
|
result.fillColor ??= fillColor;
|
|
799
2113
|
return;
|
|
800
2114
|
}
|
|
801
|
-
if (
|
|
2115
|
+
if (is(ZCommentLoc, command)) {
|
|
802
2116
|
result.loc ??= command;
|
|
803
2117
|
return;
|
|
804
2118
|
}
|
|
805
|
-
if (result.size === undefined &&
|
|
2119
|
+
if (result.size === undefined && is(ZCommentSize, command)) {
|
|
806
2120
|
result.size = command;
|
|
807
2121
|
result.fontSize = getConfig(config.fontSize, isFlash)[command].default;
|
|
808
2122
|
return;
|
|
@@ -816,7 +2130,7 @@
|
|
|
816
2130
|
result.color ??= colorCode[0].toUpperCase();
|
|
817
2131
|
return;
|
|
818
2132
|
}
|
|
819
|
-
if (
|
|
2133
|
+
if (is(ZCommentFont, command)) {
|
|
820
2134
|
result.font ??= command;
|
|
821
2135
|
return;
|
|
822
2136
|
}
|
|
@@ -876,10 +2190,10 @@
|
|
|
876
2190
|
}
|
|
877
2191
|
for (let j = 0; j < comment.long; j++) {
|
|
878
2192
|
const vpos = comment.vpos + j;
|
|
879
|
-
|
|
2193
|
+
arrayPush(timeline, vpos, comment);
|
|
880
2194
|
if (j > comment.long - 20)
|
|
881
2195
|
continue;
|
|
882
|
-
|
|
2196
|
+
arrayPush(collision, vpos, comment);
|
|
883
2197
|
}
|
|
884
2198
|
comment.posY = posY;
|
|
885
2199
|
};
|
|
@@ -890,26 +2204,25 @@
|
|
|
890
2204
|
return (comment.height - config.canvasHeight) / -2;
|
|
891
2205
|
}
|
|
892
2206
|
let posY = 0;
|
|
893
|
-
let isChanged = true
|
|
894
|
-
while (isChanged
|
|
2207
|
+
let isChanged = true;
|
|
2208
|
+
while (isChanged) {
|
|
895
2209
|
isChanged = false;
|
|
896
|
-
count++;
|
|
897
2210
|
for (let j = beforeVpos, n = comment.long + 125; j < n; j++) {
|
|
898
2211
|
const vpos = comment.vpos + j;
|
|
899
|
-
const
|
|
2212
|
+
const leftPos = getPosX(comment.comment, vpos);
|
|
900
2213
|
let isBreak = false;
|
|
901
|
-
if (
|
|
902
|
-
|
|
2214
|
+
if (leftPos + comment.width >= config.collisionRange.right &&
|
|
2215
|
+
leftPos <= config.collisionRange.right) {
|
|
903
2216
|
const result = getPosY(posY, comment, collision.right[vpos]);
|
|
904
2217
|
posY = result.currentPos;
|
|
905
|
-
isChanged
|
|
2218
|
+
isChanged ||= result.isChanged;
|
|
906
2219
|
isBreak = result.isBreak;
|
|
907
2220
|
}
|
|
908
|
-
if (
|
|
909
|
-
|
|
2221
|
+
if (leftPos + comment.width >= config.collisionRange.left &&
|
|
2222
|
+
leftPos <= config.collisionRange.left) {
|
|
910
2223
|
const result = getPosY(posY, comment, collision.left[vpos]);
|
|
911
2224
|
posY = result.currentPos;
|
|
912
|
-
isChanged
|
|
2225
|
+
isChanged ||= result.isChanged;
|
|
913
2226
|
isBreak = result.isBreak;
|
|
914
2227
|
}
|
|
915
2228
|
if (isBreak)
|
|
@@ -920,21 +2233,23 @@
|
|
|
920
2233
|
})();
|
|
921
2234
|
for (let j = beforeVpos, n = comment.long + 125; j < n; j++) {
|
|
922
2235
|
const vpos = comment.vpos + j;
|
|
923
|
-
const
|
|
924
|
-
|
|
925
|
-
if (
|
|
926
|
-
|
|
927
|
-
|
|
2236
|
+
const leftPos = getPosX(comment.comment, vpos);
|
|
2237
|
+
arrayPush(timeline, vpos, comment);
|
|
2238
|
+
if (leftPos + comment.width + config.collisionPadding >=
|
|
2239
|
+
config.collisionRange.right &&
|
|
2240
|
+
leftPos <= config.collisionRange.right) {
|
|
2241
|
+
arrayPush(collision.right, vpos, comment);
|
|
928
2242
|
}
|
|
929
|
-
if (
|
|
930
|
-
|
|
931
|
-
|
|
2243
|
+
if (leftPos + comment.width + config.collisionPadding >=
|
|
2244
|
+
config.collisionRange.left &&
|
|
2245
|
+
leftPos <= config.collisionRange.left) {
|
|
2246
|
+
arrayPush(collision.left, vpos, comment);
|
|
932
2247
|
}
|
|
933
2248
|
}
|
|
934
2249
|
comment.posY = posY;
|
|
935
2250
|
};
|
|
936
|
-
const getPosY = (currentPos, targetComment, collision) => {
|
|
937
|
-
let
|
|
2251
|
+
const getPosY = (currentPos, targetComment, collision, isChanged = false) => {
|
|
2252
|
+
let isBreak = false;
|
|
938
2253
|
if (!collision)
|
|
939
2254
|
return { currentPos, isChanged, isBreak };
|
|
940
2255
|
for (const collisionItem of collision) {
|
|
@@ -961,6 +2276,7 @@
|
|
|
961
2276
|
isBreak = true;
|
|
962
2277
|
break;
|
|
963
2278
|
}
|
|
2279
|
+
return getPosY(currentPos, targetComment, collision, true);
|
|
964
2280
|
}
|
|
965
2281
|
}
|
|
966
2282
|
return { currentPos, isChanged, isBreak };
|
|
@@ -984,12 +2300,12 @@
|
|
|
984
2300
|
switch (font) {
|
|
985
2301
|
case "gulim":
|
|
986
2302
|
case "simsun":
|
|
987
|
-
return config.
|
|
2303
|
+
return config.fonts.flash[font].replace("[size]", `${size}`);
|
|
988
2304
|
case "gothic":
|
|
989
2305
|
case "mincho":
|
|
990
|
-
return `${config.fonts[font].weight} ${size}px ${config.fonts[font].font}`;
|
|
2306
|
+
return `${config.fonts.html5[font].weight} ${size}px ${config.fonts.html5[font].font}`;
|
|
991
2307
|
default:
|
|
992
|
-
return `${config.fonts.defont.weight} ${size}px ${config.fonts.defont.font}`;
|
|
2308
|
+
return `${config.fonts.html5.defont.weight} ${size}px ${config.fonts.html5.defont.font}`;
|
|
993
2309
|
}
|
|
994
2310
|
};
|
|
995
2311
|
|
|
@@ -1026,7 +2342,7 @@
|
|
|
1026
2342
|
const index = {};
|
|
1027
2343
|
return comments.filter((comment) => {
|
|
1028
2344
|
const key = `${comment.content}@@${[...comment.mail]
|
|
1029
|
-
.sort()
|
|
2345
|
+
.sort((a, b) => a.localeCompare(b))
|
|
1030
2346
|
.filter((e) => !RegExp(/@[\d.]+|184|device:.+|patissier|ca/).exec(e))
|
|
1031
2347
|
.join("")}`, lastComment = index[key];
|
|
1032
2348
|
if (lastComment === undefined) {
|
|
@@ -1151,10 +2467,18 @@
|
|
|
1151
2467
|
for (const line of lines) {
|
|
1152
2468
|
const lineContent = parseLine(line);
|
|
1153
2469
|
const firstContent = lineContent[0];
|
|
1154
|
-
|
|
2470
|
+
const defaultFont = firstContent?.font;
|
|
2471
|
+
if (defaultFont) {
|
|
1155
2472
|
results.push(...lineContent.map((val) => {
|
|
1156
|
-
|
|
1157
|
-
|
|
2473
|
+
val.font ??= defaultFont;
|
|
2474
|
+
if (val.type === "spacer") {
|
|
2475
|
+
const spacer = config.compatSpacer.flash[val.char];
|
|
2476
|
+
if (!spacer)
|
|
2477
|
+
return val;
|
|
2478
|
+
const width = spacer[val.font];
|
|
2479
|
+
if (!width)
|
|
2480
|
+
return val;
|
|
2481
|
+
val.charWidth = width;
|
|
1158
2482
|
}
|
|
1159
2483
|
return val;
|
|
1160
2484
|
}));
|
|
@@ -1170,24 +2494,51 @@
|
|
|
1170
2494
|
const lineContent = [];
|
|
1171
2495
|
for (const part of parts) {
|
|
1172
2496
|
if (part.match(/[ -~。-゚]+/g) !== null) {
|
|
1173
|
-
lineContent
|
|
2497
|
+
addPartToResult(lineContent, part, "defont");
|
|
1174
2498
|
continue;
|
|
1175
2499
|
}
|
|
1176
2500
|
parseFullWidthPart(part, lineContent);
|
|
1177
2501
|
}
|
|
1178
2502
|
return lineContent;
|
|
1179
2503
|
};
|
|
2504
|
+
const addPartToResult = (lineContent, part, font) => {
|
|
2505
|
+
if (part === "")
|
|
2506
|
+
return;
|
|
2507
|
+
for (const key of Object.keys(config.compatSpacer.flash)) {
|
|
2508
|
+
const spacerWidth = config.compatSpacer.flash[key]?.[font ?? "defont"];
|
|
2509
|
+
if (!spacerWidth)
|
|
2510
|
+
continue;
|
|
2511
|
+
const compatIndex = part.indexOf(key);
|
|
2512
|
+
if (compatIndex >= 0) {
|
|
2513
|
+
addPartToResult(lineContent, part.slice(0, compatIndex), font);
|
|
2514
|
+
let i = compatIndex;
|
|
2515
|
+
for (; i < part.length && part[i] === key; i++) {
|
|
2516
|
+
}
|
|
2517
|
+
lineContent.push({
|
|
2518
|
+
type: "spacer",
|
|
2519
|
+
char: key,
|
|
2520
|
+
charWidth: spacerWidth,
|
|
2521
|
+
font,
|
|
2522
|
+
count: i - compatIndex,
|
|
2523
|
+
});
|
|
2524
|
+
addPartToResult(lineContent, part.slice(i), font);
|
|
2525
|
+
return;
|
|
2526
|
+
}
|
|
2527
|
+
}
|
|
2528
|
+
lineContent.push({
|
|
2529
|
+
type: "text",
|
|
2530
|
+
content: part,
|
|
2531
|
+
slicedContent: part.split("\n"),
|
|
2532
|
+
font,
|
|
2533
|
+
});
|
|
2534
|
+
};
|
|
1180
2535
|
const parseFullWidthPart = (part, lineContent) => {
|
|
1181
2536
|
const index = getFlashFontIndex(part);
|
|
1182
2537
|
if (index.length === 0) {
|
|
1183
|
-
lineContent
|
|
2538
|
+
addPartToResult(lineContent, part);
|
|
1184
2539
|
}
|
|
1185
2540
|
else if (index.length === 1 && index[0]) {
|
|
1186
|
-
lineContent.
|
|
1187
|
-
content: part,
|
|
1188
|
-
slicedContent: part.split("\n"),
|
|
1189
|
-
font: getFlashFontName(index[0].font),
|
|
1190
|
-
});
|
|
2541
|
+
addPartToResult(lineContent, part, getFlashFontName(index[0].font));
|
|
1191
2542
|
}
|
|
1192
2543
|
else {
|
|
1193
2544
|
parseMultiFontFullWidthPart(part, index, lineContent);
|
|
@@ -1195,59 +2546,36 @@
|
|
|
1195
2546
|
};
|
|
1196
2547
|
const parseMultiFontFullWidthPart = (part, index, lineContent) => {
|
|
1197
2548
|
index.sort(nativeSort((val) => val.index));
|
|
1198
|
-
if (config.
|
|
2549
|
+
if (config.flashMode === "xp") {
|
|
1199
2550
|
let offset = 0;
|
|
1200
2551
|
for (let i = 1, n = index.length; i < n; i++) {
|
|
1201
2552
|
const currentVal = index[i], lastVal = index[i - 1];
|
|
1202
2553
|
if (currentVal === undefined || lastVal === undefined)
|
|
1203
2554
|
continue;
|
|
1204
2555
|
const content = part.slice(offset, currentVal.index);
|
|
1205
|
-
lineContent.
|
|
1206
|
-
content: content,
|
|
1207
|
-
slicedContent: content.split("\n"),
|
|
1208
|
-
font: getFlashFontName(lastVal.font),
|
|
1209
|
-
});
|
|
2556
|
+
addPartToResult(lineContent, content, getFlashFontName(lastVal.font));
|
|
1210
2557
|
offset = currentVal.index;
|
|
1211
2558
|
}
|
|
1212
2559
|
const val = index[index.length - 1];
|
|
1213
2560
|
if (val) {
|
|
1214
2561
|
const content = part.slice(offset);
|
|
1215
|
-
lineContent.
|
|
1216
|
-
content: content,
|
|
1217
|
-
slicedContent: content.split("\n"),
|
|
1218
|
-
font: getFlashFontName(val.font),
|
|
1219
|
-
});
|
|
2562
|
+
addPartToResult(lineContent, content, getFlashFontName(val.font));
|
|
1220
2563
|
}
|
|
1221
2564
|
return;
|
|
1222
2565
|
}
|
|
1223
2566
|
const firstVal = index[0], secondVal = index[1];
|
|
1224
2567
|
if (!firstVal || !secondVal) {
|
|
1225
|
-
lineContent
|
|
1226
|
-
content: part,
|
|
1227
|
-
slicedContent: part.split("\n"),
|
|
1228
|
-
});
|
|
2568
|
+
addPartToResult(lineContent, part);
|
|
1229
2569
|
return;
|
|
1230
2570
|
}
|
|
1231
2571
|
if (firstVal.font !== "gothic") {
|
|
1232
|
-
lineContent.
|
|
1233
|
-
content: part,
|
|
1234
|
-
slicedContent: part.split("\n"),
|
|
1235
|
-
font: getFlashFontName(firstVal.font),
|
|
1236
|
-
});
|
|
2572
|
+
addPartToResult(lineContent, part, getFlashFontName(firstVal.font));
|
|
1237
2573
|
return;
|
|
1238
2574
|
}
|
|
1239
2575
|
const firstContent = part.slice(0, secondVal.index);
|
|
1240
2576
|
const secondContent = part.slice(secondVal.index);
|
|
1241
|
-
lineContent.
|
|
1242
|
-
|
|
1243
|
-
slicedContent: firstContent.split("\n"),
|
|
1244
|
-
font: getFlashFontName(firstVal.font),
|
|
1245
|
-
});
|
|
1246
|
-
lineContent.push({
|
|
1247
|
-
content: secondContent,
|
|
1248
|
-
slicedContent: secondContent.split("\n"),
|
|
1249
|
-
font: getFlashFontName(secondVal.font),
|
|
1250
|
-
});
|
|
2577
|
+
addPartToResult(lineContent, firstContent, getFlashFontName(firstVal.font));
|
|
2578
|
+
addPartToResult(lineContent, secondContent, getFlashFontName(secondVal.font));
|
|
1251
2579
|
};
|
|
1252
2580
|
const getButtonParts = (comment) => {
|
|
1253
2581
|
let leftParts = undefined;
|
|
@@ -1256,12 +2584,16 @@
|
|
|
1256
2584
|
const lineOffset = comment.lineOffset;
|
|
1257
2585
|
const lineHeight = comment.fontSize * comment.lineHeight;
|
|
1258
2586
|
const offsetKey = comment.resizedY ? "resized" : "default";
|
|
1259
|
-
const offsetY = config.
|
|
2587
|
+
const offsetY = config.flashCommentYPaddingTop[offsetKey] +
|
|
1260
2588
|
comment.fontSize *
|
|
1261
2589
|
comment.lineHeight *
|
|
1262
|
-
config.
|
|
2590
|
+
config.flashCommentYOffset[comment.size][offsetKey];
|
|
1263
2591
|
let leftOffset = 0, lineCount = 0, isLastButton = false;
|
|
1264
2592
|
for (const item of comment.content) {
|
|
2593
|
+
if (item.type === "spacer") {
|
|
2594
|
+
leftOffset += item.count * comment.fontSize * item.charWidth;
|
|
2595
|
+
continue;
|
|
2596
|
+
}
|
|
1265
2597
|
const lines = item.slicedContent;
|
|
1266
2598
|
for (let j = 0, n = lines.length; j < n; j++) {
|
|
1267
2599
|
const line = lines[j];
|
|
@@ -1360,39 +2692,75 @@
|
|
|
1360
2692
|
TypeGuardError.prototype.name = "TypeGuardError";
|
|
1361
2693
|
|
|
1362
2694
|
const getLineHeight = (fontSize, isFlash, resized = false) => {
|
|
1363
|
-
const lineCounts = getConfig(config.
|
|
2695
|
+
const lineCounts = getConfig(config.html5LineCounts, isFlash), commentStageSize = getConfig(config.commentStageSize, isFlash), lineHeight = commentStageSize.height / lineCounts.doubleResized[fontSize], defaultLineCount = lineCounts.default[fontSize];
|
|
1364
2696
|
if (resized) {
|
|
1365
2697
|
const resizedLineCount = lineCounts.resized[fontSize];
|
|
1366
|
-
return ((
|
|
2698
|
+
return ((commentStageSize.height -
|
|
1367
2699
|
lineHeight * (defaultLineCount / resizedLineCount)) /
|
|
1368
2700
|
(resizedLineCount - 1));
|
|
1369
2701
|
}
|
|
1370
|
-
return (
|
|
2702
|
+
return (commentStageSize.height - lineHeight) / (defaultLineCount - 1);
|
|
1371
2703
|
};
|
|
1372
2704
|
const getCharSize = (fontSize, isFlash) => {
|
|
1373
|
-
const lineCounts = getConfig(config.
|
|
1374
|
-
return
|
|
2705
|
+
const lineCounts = getConfig(config.html5LineCounts, isFlash), commentStageSize = getConfig(config.commentStageSize, isFlash);
|
|
2706
|
+
return commentStageSize.height / lineCounts.doubleResized[fontSize];
|
|
1375
2707
|
};
|
|
1376
|
-
const measure = (comment,
|
|
1377
|
-
const width = measureWidth(comment,
|
|
2708
|
+
const measure = (comment, renderer) => {
|
|
2709
|
+
const width = measureWidth(comment, renderer);
|
|
1378
2710
|
return {
|
|
1379
2711
|
...width,
|
|
1380
2712
|
height: comment.lineHeight * (comment.lineCount - 1) + comment.charSize,
|
|
1381
2713
|
};
|
|
1382
2714
|
};
|
|
1383
|
-
const
|
|
2715
|
+
const addHTML5PartToResult = (lineContent, part, font) => {
|
|
2716
|
+
if (part === "")
|
|
2717
|
+
return;
|
|
2718
|
+
font ??= "defont";
|
|
2719
|
+
for (const key of Object.keys(config.compatSpacer.html5)) {
|
|
2720
|
+
const spacerWidth = config.compatSpacer.html5[key]?.[font];
|
|
2721
|
+
if (!spacerWidth)
|
|
2722
|
+
continue;
|
|
2723
|
+
const compatIndex = part.indexOf(key);
|
|
2724
|
+
if (compatIndex >= 0) {
|
|
2725
|
+
addHTML5PartToResult(lineContent, part.slice(0, compatIndex), font);
|
|
2726
|
+
let i = compatIndex;
|
|
2727
|
+
for (; i < part.length && part[i] === key; i++) {
|
|
2728
|
+
}
|
|
2729
|
+
lineContent.push({
|
|
2730
|
+
type: "spacer",
|
|
2731
|
+
char: key,
|
|
2732
|
+
charWidth: spacerWidth,
|
|
2733
|
+
count: i - compatIndex,
|
|
2734
|
+
});
|
|
2735
|
+
addHTML5PartToResult(lineContent, part.slice(i), font);
|
|
2736
|
+
return;
|
|
2737
|
+
}
|
|
2738
|
+
}
|
|
2739
|
+
lineContent.push({
|
|
2740
|
+
type: "text",
|
|
2741
|
+
content: part,
|
|
2742
|
+
slicedContent: part.split("\n"),
|
|
2743
|
+
});
|
|
2744
|
+
};
|
|
2745
|
+
const measureWidth = (comment, renderer) => {
|
|
1384
2746
|
const { fontSize, scale } = getFontSizeAndScale(comment.charSize), lineWidth = [], itemWidth = [];
|
|
1385
|
-
|
|
2747
|
+
renderer.setFont(parseFont(comment.font, fontSize));
|
|
1386
2748
|
let currentWidth = 0;
|
|
1387
2749
|
for (const item of comment.content) {
|
|
2750
|
+
if (item.type === "spacer") {
|
|
2751
|
+
currentWidth += item.count * fontSize * item.charWidth;
|
|
2752
|
+
itemWidth.push([item.count * fontSize * item.charWidth]);
|
|
2753
|
+
lineWidth.push(Math.ceil(currentWidth * scale));
|
|
2754
|
+
continue;
|
|
2755
|
+
}
|
|
1388
2756
|
const lines = item.content.split("\n");
|
|
1389
|
-
|
|
2757
|
+
renderer.setFont(parseFont(item.font ?? comment.font, fontSize));
|
|
1390
2758
|
const width = [];
|
|
1391
2759
|
for (let j = 0, n = lines.length; j < n; j++) {
|
|
1392
2760
|
const line = lines[j];
|
|
1393
2761
|
if (line === undefined)
|
|
1394
2762
|
throw new TypeGuardError();
|
|
1395
|
-
const measure =
|
|
2763
|
+
const measure = renderer.measureText(line);
|
|
1396
2764
|
currentWidth += measure.width;
|
|
1397
2765
|
width.push(measure.width);
|
|
1398
2766
|
if (j < lines.length - 1) {
|
|
@@ -1411,12 +2779,12 @@
|
|
|
1411
2779
|
};
|
|
1412
2780
|
const getFontSizeAndScale = (charSize) => {
|
|
1413
2781
|
charSize *= 0.8;
|
|
1414
|
-
if (charSize < config.
|
|
2782
|
+
if (charSize < config.html5MinFontSize) {
|
|
1415
2783
|
if (charSize >= 1)
|
|
1416
2784
|
charSize = Math.floor(charSize);
|
|
1417
2785
|
return {
|
|
1418
|
-
scale: charSize / config.
|
|
1419
|
-
fontSize: config.
|
|
2786
|
+
scale: charSize / config.html5MinFontSize,
|
|
2787
|
+
fontSize: config.html5MinFontSize,
|
|
1420
2788
|
};
|
|
1421
2789
|
}
|
|
1422
2790
|
return {
|
|
@@ -1425,10 +2793,11 @@
|
|
|
1425
2793
|
};
|
|
1426
2794
|
};
|
|
1427
2795
|
|
|
1428
|
-
var index$
|
|
2796
|
+
var index$2 = /*#__PURE__*/Object.freeze({
|
|
1429
2797
|
__proto__: null,
|
|
1430
|
-
|
|
1431
|
-
|
|
2798
|
+
addHTML5PartToResult: addHTML5PartToResult,
|
|
2799
|
+
arrayEqual: arrayEqual,
|
|
2800
|
+
arrayPush: arrayPush,
|
|
1432
2801
|
buildAtButtonComment: buildAtButtonComment,
|
|
1433
2802
|
changeCALayer: changeCALayer,
|
|
1434
2803
|
getButtonParts: getButtonParts,
|
|
@@ -1457,21 +2826,8 @@
|
|
|
1457
2826
|
processMovableComment: processMovableComment
|
|
1458
2827
|
});
|
|
1459
2828
|
|
|
1460
|
-
const generateCanvas = () => {
|
|
1461
|
-
return document.createElement("canvas");
|
|
1462
|
-
};
|
|
1463
|
-
const getContext = (canvas) => {
|
|
1464
|
-
const context = canvas.getContext("2d");
|
|
1465
|
-
if (!context)
|
|
1466
|
-
throw new CanvasRenderingContext2DError();
|
|
1467
|
-
return context;
|
|
1468
|
-
};
|
|
1469
|
-
const drawImage = (targetContext, sourceImage, x, y) => {
|
|
1470
|
-
targetContext.drawImage(sourceImage, x, y);
|
|
1471
|
-
};
|
|
1472
|
-
|
|
1473
2829
|
class BaseComment {
|
|
1474
|
-
|
|
2830
|
+
renderer;
|
|
1475
2831
|
cacheKey;
|
|
1476
2832
|
comment;
|
|
1477
2833
|
pos;
|
|
@@ -1479,16 +2835,13 @@
|
|
|
1479
2835
|
pluginName = "BaseComment";
|
|
1480
2836
|
image;
|
|
1481
2837
|
buttonImage;
|
|
1482
|
-
constructor(comment,
|
|
1483
|
-
this.
|
|
2838
|
+
constructor(comment, renderer) {
|
|
2839
|
+
this.renderer = renderer;
|
|
1484
2840
|
this.posY = 0;
|
|
1485
2841
|
this.pos = { x: 0, y: 0 };
|
|
1486
2842
|
comment.content = comment.content.replace(/\t/g, "\u2003\u2003");
|
|
1487
2843
|
this.comment = this.convertComment(comment);
|
|
1488
|
-
this.cacheKey =
|
|
1489
|
-
JSON.stringify(this.comment.content) +
|
|
1490
|
-
`@@${this.pluginName}@@` +
|
|
1491
|
-
[...this.comment.mail].sort().join(",");
|
|
2844
|
+
this.cacheKey = this.getCacheKey();
|
|
1492
2845
|
}
|
|
1493
2846
|
get invisible() {
|
|
1494
2847
|
return this.comment.invisible;
|
|
@@ -1569,48 +2922,44 @@
|
|
|
1569
2922
|
this.image = this.getTextImage();
|
|
1570
2923
|
}
|
|
1571
2924
|
if (this.image) {
|
|
1572
|
-
this.
|
|
2925
|
+
this.renderer.save();
|
|
1573
2926
|
if (this.comment._live) {
|
|
1574
|
-
this.
|
|
2927
|
+
this.renderer.setGlobalAlpha(config.contextFillLiveOpacity);
|
|
1575
2928
|
}
|
|
1576
2929
|
else {
|
|
1577
|
-
this.
|
|
2930
|
+
this.renderer.setGlobalAlpha(1);
|
|
1578
2931
|
}
|
|
1579
2932
|
if (this.comment.button && !this.comment.button.hidden) {
|
|
1580
2933
|
const button = this.getButtonImage(posX, posY, cursor);
|
|
1581
|
-
button && drawImage(
|
|
2934
|
+
button && this.renderer.drawImage(button, posX, posY);
|
|
1582
2935
|
}
|
|
1583
|
-
drawImage(this.
|
|
1584
|
-
this.
|
|
2936
|
+
this.renderer.drawImage(this.image, posX, posY);
|
|
2937
|
+
this.renderer.restore();
|
|
1585
2938
|
}
|
|
1586
2939
|
}
|
|
1587
2940
|
_drawRectColor(posX, posY) {
|
|
1588
2941
|
if (this.comment.wakuColor) {
|
|
1589
|
-
this.
|
|
1590
|
-
this.
|
|
1591
|
-
this.
|
|
1592
|
-
this.
|
|
2942
|
+
this.renderer.save();
|
|
2943
|
+
this.renderer.setStrokeStyle(this.comment.wakuColor);
|
|
2944
|
+
this.renderer.strokeRect(posX, posY, this.comment.width, this.comment.height);
|
|
2945
|
+
this.renderer.restore();
|
|
1593
2946
|
}
|
|
1594
2947
|
}
|
|
1595
2948
|
_drawBackgroundColor(posX, posY) {
|
|
1596
2949
|
if (this.comment.fillColor) {
|
|
1597
|
-
this.
|
|
1598
|
-
this.
|
|
1599
|
-
this.
|
|
1600
|
-
this.
|
|
2950
|
+
this.renderer.save();
|
|
2951
|
+
this.renderer.setFillStyle(this.comment.fillColor);
|
|
2952
|
+
this.renderer.fillRect(posX, posY, this.comment.width, this.comment.height);
|
|
2953
|
+
this.renderer.restore();
|
|
1601
2954
|
}
|
|
1602
2955
|
}
|
|
1603
2956
|
_drawDebugInfo(posX, posY) {
|
|
1604
2957
|
if (isDebug) {
|
|
1605
|
-
this.
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
this.
|
|
1609
|
-
this.
|
|
1610
|
-
this.context.fillText(this.comment.mail.join(","), posX, posY + 30);
|
|
1611
|
-
this.context.font = font;
|
|
1612
|
-
this.context.fillStyle = fillStyle;
|
|
1613
|
-
this.context.restore();
|
|
2958
|
+
this.renderer.save();
|
|
2959
|
+
this.renderer.setFont(parseFont("defont", 30));
|
|
2960
|
+
this.renderer.setFillStyle("#ff00ff");
|
|
2961
|
+
this.renderer.fillText(this.comment.mail.join(","), posX, posY + 30);
|
|
2962
|
+
this.renderer.restore();
|
|
1614
2963
|
}
|
|
1615
2964
|
}
|
|
1616
2965
|
_drawCollision(posX, posY, showCollision) {
|
|
@@ -1657,14 +3006,6 @@
|
|
|
1657
3006
|
image,
|
|
1658
3007
|
};
|
|
1659
3008
|
}
|
|
1660
|
-
createCanvas() {
|
|
1661
|
-
const image = generateCanvas();
|
|
1662
|
-
const context = getContext(image);
|
|
1663
|
-
return {
|
|
1664
|
-
image,
|
|
1665
|
-
context,
|
|
1666
|
-
};
|
|
1667
|
-
}
|
|
1668
3009
|
getButtonImage(posX, posY, cursor) {
|
|
1669
3010
|
console.error("getButtonImage method is not implemented", posX, posY, cursor);
|
|
1670
3011
|
throw new NotImplementedError(this.pluginName, "getButtonImage");
|
|
@@ -1673,6 +3014,11 @@
|
|
|
1673
3014
|
console.error("isHovered method is not implemented", posX, posY, cursor);
|
|
1674
3015
|
throw new NotImplementedError(this.pluginName, "getButtonImage");
|
|
1675
3016
|
}
|
|
3017
|
+
getCacheKey() {
|
|
3018
|
+
return (JSON.stringify(this.comment.content) +
|
|
3019
|
+
`@@${this.pluginName}@@` +
|
|
3020
|
+
[...this.comment.mail].sort((a, b) => a.localeCompare(b)).join(","));
|
|
3021
|
+
}
|
|
1676
3022
|
}
|
|
1677
3023
|
|
|
1678
3024
|
const drawLeftBorder = (context, left, top, width, height, radius) => {
|
|
@@ -1712,13 +3058,10 @@
|
|
|
1712
3058
|
_globalScale;
|
|
1713
3059
|
pluginName = "FlashComment";
|
|
1714
3060
|
buttonImage;
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
super(comment, context);
|
|
3061
|
+
constructor(comment, renderer) {
|
|
3062
|
+
super(comment, renderer);
|
|
1718
3063
|
this._globalScale ??= getConfig(config.commentScale, true);
|
|
1719
|
-
|
|
1720
|
-
this.buttonImage = button.image;
|
|
1721
|
-
this.buttonContext = button.context;
|
|
3064
|
+
this.buttonImage = renderer.getCanvas();
|
|
1722
3065
|
}
|
|
1723
3066
|
get content() {
|
|
1724
3067
|
return this.comment.rawContent;
|
|
@@ -1737,10 +3080,7 @@
|
|
|
1737
3080
|
comment.font = val.font;
|
|
1738
3081
|
}
|
|
1739
3082
|
this.comment = this.getCommentSize(comment);
|
|
1740
|
-
this.cacheKey =
|
|
1741
|
-
JSON.stringify(this.comment.content) +
|
|
1742
|
-
`@@${this.pluginName}@@` +
|
|
1743
|
-
[...this.comment.mail].sort((a, b) => a.localeCompare(b)).join(",");
|
|
3083
|
+
this.cacheKey = this.getCacheKey();
|
|
1744
3084
|
delete this.image;
|
|
1745
3085
|
}
|
|
1746
3086
|
convertComment(comment) {
|
|
@@ -1764,14 +3104,14 @@
|
|
|
1764
3104
|
content: [],
|
|
1765
3105
|
};
|
|
1766
3106
|
}
|
|
1767
|
-
this.
|
|
1768
|
-
this.
|
|
3107
|
+
this.renderer.save();
|
|
3108
|
+
this.renderer.setFont(parseFont(parsedData.font, parsedData.fontSize));
|
|
1769
3109
|
const measure = this.measureText({ ...parsedData, scale: 1 });
|
|
1770
3110
|
if (options.scale !== 1 && parsedData.layer === -1) {
|
|
1771
3111
|
measure.height *= options.scale;
|
|
1772
3112
|
measure.width *= options.scale;
|
|
1773
3113
|
}
|
|
1774
|
-
this.
|
|
3114
|
+
this.renderer.restore();
|
|
1775
3115
|
if (parsedData.button && !parsedData.button.hidden) {
|
|
1776
3116
|
measure.width += getConfig(config.atButtonPadding, true) * 4;
|
|
1777
3117
|
}
|
|
@@ -1818,12 +3158,12 @@
|
|
|
1818
3158
|
]
|
|
1819
3159
|
: parseContent(input);
|
|
1820
3160
|
const lineCount = (input.match(/\n/g)?.length ?? 0) + 1;
|
|
1821
|
-
const lineOffset = (input.match(new RegExp(config.
|
|
3161
|
+
const lineOffset = (input.match(new RegExp(config.flashScriptChar.super, "g"))?.length ??
|
|
1822
3162
|
0) *
|
|
1823
3163
|
-1 *
|
|
1824
|
-
config.
|
|
1825
|
-
(input.match(new RegExp(config.
|
|
1826
|
-
config.
|
|
3164
|
+
config.flashScriptCharOffset +
|
|
3165
|
+
(input.match(new RegExp(config.flashScriptChar.sub, "g"))?.length ?? 0) *
|
|
3166
|
+
config.flashScriptCharOffset;
|
|
1827
3167
|
return {
|
|
1828
3168
|
content,
|
|
1829
3169
|
lineCount,
|
|
@@ -1831,51 +3171,41 @@
|
|
|
1831
3171
|
};
|
|
1832
3172
|
}
|
|
1833
3173
|
measureText(comment) {
|
|
1834
|
-
const configLineHeight = getConfig(config.lineHeight, true), configFontSize = getConfig(config.fontSize, true);
|
|
1835
|
-
const
|
|
3174
|
+
const configLineHeight = getConfig(config.lineHeight, true), configFontSize = getConfig(config.fontSize, true)[comment.size], configStageSize = getConfig(config.commentStageSize, true);
|
|
3175
|
+
const defaultFontSize = configFontSize.default;
|
|
1836
3176
|
comment.lineHeight ??= configLineHeight[comment.size].default;
|
|
3177
|
+
const widthLimit = configStageSize[comment.full ? "fullWidth" : "width"];
|
|
3178
|
+
const { scaleX, width, height } = this._measureContent(comment);
|
|
3179
|
+
let scale = 1;
|
|
1837
3180
|
if (isLineBreakResize(comment)) {
|
|
1838
|
-
comment.fontSize = configFontSize[comment.size].resized;
|
|
1839
|
-
comment.lineHeight = configLineHeight[comment.size].resized;
|
|
1840
3181
|
comment.resized = true;
|
|
1841
3182
|
comment.resizedY = true;
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
index = i;
|
|
3183
|
+
const lineBreakScale = config.flashLineBreakScale[comment.size];
|
|
3184
|
+
const scaledWidth = width * lineBreakScale;
|
|
3185
|
+
if (comment.loc !== "naka" &&
|
|
3186
|
+
this._isDoubleResize(scaledWidth, widthLimit, comment.size, comment.lineCount, comment.full)) {
|
|
3187
|
+
if (scaledWidth > widthLimit) {
|
|
3188
|
+
const resizedFontSize = Math.round((widthLimit / scaledWidth) * defaultFontSize);
|
|
3189
|
+
const resizeRate = (resizedFontSize + 1) / (defaultFontSize + 1);
|
|
3190
|
+
scale *= resizeRate;
|
|
1851
3191
|
}
|
|
1852
|
-
}
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
const width = leadLine.max;
|
|
1856
|
-
const scaleX = leadLine.max / (width_arr[leadLine.index] ?? 1);
|
|
1857
|
-
const width_max = width * comment.scale;
|
|
1858
|
-
const height = (comment.fontSize * comment.lineHeight * lineCount +
|
|
1859
|
-
config.commentYPaddingTop[comment.resizedY ? "resized" : "default"]) *
|
|
1860
|
-
comment.scale;
|
|
1861
|
-
if (comment.loc !== "naka") {
|
|
1862
|
-
const widthLimit = getConfig(config.CommentStageSize, true)[comment.full ? "fullWidth" : "width"];
|
|
1863
|
-
if (width_max > widthLimit && !comment.resizedX) {
|
|
1864
|
-
comment.fontSize = configFontSize[comment.size].default;
|
|
1865
|
-
comment.lineHeight = configLineHeight[comment.size].default;
|
|
1866
|
-
comment.scale = widthLimit / width_max;
|
|
1867
|
-
comment.resizedX = true;
|
|
1868
|
-
comment.resized = true;
|
|
1869
|
-
return this.measureText(comment);
|
|
3192
|
+
}
|
|
3193
|
+
else {
|
|
3194
|
+
scale *= lineBreakScale;
|
|
1870
3195
|
}
|
|
1871
3196
|
}
|
|
3197
|
+
else if (comment.loc !== "naka" && width > widthLimit) {
|
|
3198
|
+
const resizeRate = (Math.round((widthLimit / width) * defaultFontSize) + 1) /
|
|
3199
|
+
(defaultFontSize + 1);
|
|
3200
|
+
scale *= resizeRate;
|
|
3201
|
+
}
|
|
3202
|
+
comment.scale = scale;
|
|
1872
3203
|
if (!typeGuard.internal.CommentMeasuredContentItemArray(comment.content)) {
|
|
1873
3204
|
throw new TypeGuardError();
|
|
1874
3205
|
}
|
|
1875
3206
|
return {
|
|
1876
|
-
width: width_max,
|
|
1877
3207
|
charSize: 0,
|
|
1878
|
-
height: height,
|
|
3208
|
+
height: height * scale,
|
|
1879
3209
|
resized: !!comment.resized,
|
|
1880
3210
|
fontSize: comment.fontSize,
|
|
1881
3211
|
lineHeight: comment.lineHeight,
|
|
@@ -1883,75 +3213,134 @@
|
|
|
1883
3213
|
resizedX: !!comment.resizedX,
|
|
1884
3214
|
resizedY: !!comment.resizedY,
|
|
1885
3215
|
scale: comment.scale,
|
|
1886
|
-
scaleX,
|
|
3216
|
+
scaleX: scaleX,
|
|
3217
|
+
width: width * scale,
|
|
1887
3218
|
};
|
|
1888
3219
|
}
|
|
3220
|
+
_isDoubleResize(width, widthLimit, size, lineCount, isFull) {
|
|
3221
|
+
if (width < widthLimit * 0.9 || widthLimit * 1.1 < width)
|
|
3222
|
+
return width > widthLimit;
|
|
3223
|
+
if (size === "big") {
|
|
3224
|
+
if (8 <= lineCount &&
|
|
3225
|
+
lineCount <= 14 &&
|
|
3226
|
+
!isFull &&
|
|
3227
|
+
widthLimit * 0.99 < width)
|
|
3228
|
+
return true;
|
|
3229
|
+
if (width <= widthLimit)
|
|
3230
|
+
return false;
|
|
3231
|
+
if (16 <= lineCount && width * 0.95 < widthLimit)
|
|
3232
|
+
return true;
|
|
3233
|
+
if (isFull) {
|
|
3234
|
+
if (width * 0.95 < widthLimit)
|
|
3235
|
+
return false;
|
|
3236
|
+
return width > widthLimit;
|
|
3237
|
+
}
|
|
3238
|
+
return true;
|
|
3239
|
+
}
|
|
3240
|
+
if (width <= widthLimit)
|
|
3241
|
+
return false;
|
|
3242
|
+
if (((size === "medium" && 25 <= lineCount) ||
|
|
3243
|
+
(size === "small" && 38 <= lineCount)) &&
|
|
3244
|
+
width * 0.95 < widthLimit)
|
|
3245
|
+
return false;
|
|
3246
|
+
return widthLimit < width;
|
|
3247
|
+
}
|
|
1889
3248
|
_measureContent(comment) {
|
|
1890
|
-
const
|
|
3249
|
+
const widthArr = [], spacedWidthArr = [];
|
|
1891
3250
|
let currentWidth = 0, spacedWidth = 0;
|
|
1892
3251
|
for (const item of comment.content) {
|
|
3252
|
+
if (item.type === "spacer") {
|
|
3253
|
+
spacedWidth +=
|
|
3254
|
+
item.count * item.charWidth * comment.fontSize +
|
|
3255
|
+
Math.max(item.count - 1, 0) * config.flashLetterSpacing;
|
|
3256
|
+
currentWidth += item.count * item.charWidth * comment.fontSize;
|
|
3257
|
+
widthArr.push(currentWidth);
|
|
3258
|
+
spacedWidthArr.push(spacedWidth);
|
|
3259
|
+
continue;
|
|
3260
|
+
}
|
|
1893
3261
|
const lines = item.content.split("\n");
|
|
1894
3262
|
const widths = [];
|
|
1895
|
-
this.
|
|
3263
|
+
this.renderer.setFont(parseFont(item.font ?? comment.font, comment.fontSize));
|
|
1896
3264
|
for (let i = 0, n = lines.length; i < n; i++) {
|
|
1897
3265
|
const value = lines[i];
|
|
1898
3266
|
if (value === undefined)
|
|
1899
3267
|
continue;
|
|
1900
|
-
const measure = this.
|
|
3268
|
+
const measure = this.renderer.measureText(value);
|
|
1901
3269
|
currentWidth += measure.width;
|
|
1902
3270
|
spacedWidth +=
|
|
1903
|
-
measure.width +
|
|
3271
|
+
measure.width +
|
|
3272
|
+
Math.max(value.length - 1, 0) * config.flashLetterSpacing;
|
|
1904
3273
|
widths.push(measure.width);
|
|
1905
3274
|
if (i < lines.length - 1) {
|
|
1906
|
-
|
|
1907
|
-
|
|
3275
|
+
widthArr.push(currentWidth);
|
|
3276
|
+
spacedWidthArr.push(spacedWidth);
|
|
1908
3277
|
spacedWidth = 0;
|
|
1909
3278
|
currentWidth = 0;
|
|
1910
3279
|
}
|
|
1911
3280
|
}
|
|
1912
|
-
|
|
1913
|
-
|
|
3281
|
+
widthArr.push(currentWidth);
|
|
3282
|
+
spacedWidthArr.push(spacedWidth);
|
|
1914
3283
|
item.width = widths;
|
|
1915
3284
|
}
|
|
1916
|
-
|
|
3285
|
+
const leadLine = (function () {
|
|
3286
|
+
let max = 0, index = -1;
|
|
3287
|
+
spacedWidthArr.forEach((val, i) => {
|
|
3288
|
+
if (max < val) {
|
|
3289
|
+
max = val;
|
|
3290
|
+
index = i;
|
|
3291
|
+
}
|
|
3292
|
+
});
|
|
3293
|
+
return { max, index };
|
|
3294
|
+
})();
|
|
3295
|
+
const scaleX = leadLine.max / (widthArr[leadLine.index] ?? 1);
|
|
3296
|
+
const width = leadLine.max * comment.scale;
|
|
3297
|
+
const height = (comment.fontSize * (comment.lineHeight ?? 0) * comment.lineCount +
|
|
3298
|
+
config.flashCommentYPaddingTop[comment.resizedY ? "resized" : "default"]) *
|
|
3299
|
+
comment.scale;
|
|
3300
|
+
return { scaleX, width, height };
|
|
1917
3301
|
}
|
|
1918
3302
|
_drawCollision(posX, posY, showCollision) {
|
|
1919
3303
|
if (showCollision) {
|
|
1920
|
-
this.
|
|
1921
|
-
this.
|
|
1922
|
-
this.
|
|
3304
|
+
this.renderer.save();
|
|
3305
|
+
this.renderer.setStrokeStyle("rgba(255,0,255,1)");
|
|
3306
|
+
this.renderer.strokeRect(posX, posY, this.comment.width, this.comment.height);
|
|
1923
3307
|
for (let i = 0, n = this.comment.lineCount; i < n; i++) {
|
|
1924
3308
|
const linePosY = ((i + 1) * (this.comment.fontSize * this.comment.lineHeight) +
|
|
1925
|
-
config.
|
|
3309
|
+
config.flashCommentYPaddingTop[this.comment.resizedY ? "resized" : "default"]) *
|
|
1926
3310
|
this.comment.scale;
|
|
1927
|
-
this.
|
|
1928
|
-
this.
|
|
3311
|
+
this.renderer.setStrokeStyle(`rgba(255,255,0,0.25)`);
|
|
3312
|
+
this.renderer.strokeRect(posX, posY + linePosY * this._globalScale, this.comment.width, this.comment.fontSize *
|
|
1929
3313
|
this.comment.lineHeight *
|
|
1930
3314
|
-1 *
|
|
1931
3315
|
this._globalScale *
|
|
1932
3316
|
this.comment.scale *
|
|
1933
3317
|
(this.comment.layer === -1 ? options.scale : 1));
|
|
1934
3318
|
}
|
|
1935
|
-
this.
|
|
3319
|
+
this.renderer.restore();
|
|
1936
3320
|
}
|
|
1937
3321
|
}
|
|
1938
3322
|
_generateTextImage() {
|
|
1939
|
-
const
|
|
1940
|
-
this._setupCanvas(
|
|
3323
|
+
const renderer = this.renderer.getCanvas();
|
|
3324
|
+
this._setupCanvas(renderer);
|
|
1941
3325
|
const atButtonPadding = getConfig(config.atButtonPadding, true);
|
|
1942
3326
|
const lineOffset = this.comment.lineOffset;
|
|
1943
3327
|
const lineHeight = this.comment.fontSize * this.comment.lineHeight;
|
|
1944
3328
|
const offsetKey = this.comment.resizedY ? "resized" : "default";
|
|
1945
|
-
const offsetY = config.
|
|
3329
|
+
const offsetY = config.flashCommentYPaddingTop[offsetKey] +
|
|
1946
3330
|
this.comment.fontSize *
|
|
1947
3331
|
this.comment.lineHeight *
|
|
1948
|
-
config.
|
|
3332
|
+
config.flashCommentYOffset[this.comment.size][offsetKey];
|
|
1949
3333
|
let lastFont = this.comment.font, leftOffset = 0, lineCount = 0, isLastButton = false;
|
|
1950
3334
|
for (const item of this.comment.content) {
|
|
3335
|
+
if (item.type === "spacer") {
|
|
3336
|
+
leftOffset += item.count * item.charWidth * this.comment.fontSize;
|
|
3337
|
+
isLastButton = !!item.isButton;
|
|
3338
|
+
continue;
|
|
3339
|
+
}
|
|
1951
3340
|
const font = item.font ?? this.comment.font;
|
|
1952
3341
|
if (lastFont !== font) {
|
|
1953
3342
|
lastFont = font;
|
|
1954
|
-
|
|
3343
|
+
renderer.setFont(parseFont(font, this.comment.fontSize));
|
|
1955
3344
|
}
|
|
1956
3345
|
const lines = item.slicedContent;
|
|
1957
3346
|
for (let lineIndex = 0, lineLength = lines.length; lineIndex < lineLength; lineIndex++) {
|
|
@@ -1965,42 +3354,45 @@
|
|
|
1965
3354
|
((!isLastButton && item.isButton) || (isLastButton && !item.isButton))) {
|
|
1966
3355
|
leftOffset += atButtonPadding * 2;
|
|
1967
3356
|
}
|
|
1968
|
-
|
|
1969
|
-
|
|
3357
|
+
renderer.strokeText(line, leftOffset, posY);
|
|
3358
|
+
renderer.fillText(line, leftOffset, posY);
|
|
3359
|
+
leftOffset += partWidth;
|
|
1970
3360
|
if (lineIndex < lineLength - 1) {
|
|
1971
3361
|
leftOffset = 0;
|
|
1972
3362
|
lineCount += 1;
|
|
1973
|
-
continue;
|
|
1974
3363
|
}
|
|
1975
|
-
leftOffset += partWidth;
|
|
1976
3364
|
}
|
|
1977
3365
|
isLastButton = !!item.isButton;
|
|
1978
3366
|
}
|
|
1979
|
-
return
|
|
3367
|
+
return renderer;
|
|
1980
3368
|
}
|
|
1981
3369
|
getButtonImage(posX, posY, cursor) {
|
|
1982
3370
|
if (!this.comment.button || this.comment.button.hidden)
|
|
1983
3371
|
return undefined;
|
|
1984
|
-
const {
|
|
3372
|
+
const { renderer } = this._setupCanvas(this.buttonImage);
|
|
1985
3373
|
const parts = this.comment.buttonObjects;
|
|
1986
3374
|
if (!parts)
|
|
1987
3375
|
return undefined;
|
|
1988
3376
|
const atButtonRadius = getConfig(config.atButtonRadius, true);
|
|
1989
3377
|
const isHover = this.isHovered(cursor, posX, posY);
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
3378
|
+
renderer.save();
|
|
3379
|
+
const getStrokeStyle = () => {
|
|
3380
|
+
if (isHover) {
|
|
3381
|
+
return this.comment.color;
|
|
3382
|
+
}
|
|
3383
|
+
if (this.comment.button && this.comment.button.limit < 1) {
|
|
3384
|
+
return "#777777";
|
|
3385
|
+
}
|
|
3386
|
+
return "white";
|
|
3387
|
+
};
|
|
3388
|
+
renderer.setStrokeStyle(getStrokeStyle());
|
|
3389
|
+
drawLeftBorder(renderer, parts.left.left, parts.left.top, parts.left.width, parts.left.height, atButtonRadius);
|
|
1998
3390
|
for (const part of parts.middle) {
|
|
1999
|
-
drawMiddleBorder(
|
|
3391
|
+
drawMiddleBorder(renderer, part.left, part.top, part.width, part.height);
|
|
2000
3392
|
}
|
|
2001
|
-
drawRightBorder(
|
|
2002
|
-
|
|
2003
|
-
return
|
|
3393
|
+
drawRightBorder(renderer, parts.right.right, parts.right.top, parts.right.height, atButtonRadius);
|
|
3394
|
+
renderer.restore();
|
|
3395
|
+
return renderer;
|
|
2004
3396
|
}
|
|
2005
3397
|
isHovered(_cursor, _posX, _posY) {
|
|
2006
3398
|
if (!_cursor || !this.comment.buttonObjects)
|
|
@@ -2034,22 +3426,18 @@
|
|
|
2034
3426
|
}
|
|
2035
3427
|
return (between(cursor.x, posX + right.right - atButtonPadding, posX + right.right + getConfig(config.contextLineWidth, true) / 2) && between(cursor.y, posY + right.top, posY + right.top + right.height));
|
|
2036
3428
|
}
|
|
2037
|
-
_setupCanvas(
|
|
3429
|
+
_setupCanvas(renderer) {
|
|
2038
3430
|
const atButtonPadding = getConfig(config.atButtonPadding, true);
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
context.textAlign = "start";
|
|
2045
|
-
context.textBaseline = "alphabetic";
|
|
2046
|
-
context.lineWidth = getConfig(config.contextLineWidth, true);
|
|
2047
|
-
context.font = parseFont(this.comment.font, this.comment.fontSize);
|
|
3431
|
+
renderer.setSize(this.comment.width, this.comment.height + (this.comment.button ? atButtonPadding * 2 : 0));
|
|
3432
|
+
renderer.setStrokeStyle(getStrokeColor(this.comment));
|
|
3433
|
+
renderer.setFillStyle(this.comment.color);
|
|
3434
|
+
renderer.setLineWidth(getConfig(config.contextLineWidth, true));
|
|
3435
|
+
renderer.setFont(parseFont(this.comment.font, this.comment.fontSize));
|
|
2048
3436
|
const scale = this._globalScale *
|
|
2049
3437
|
this.comment.scale *
|
|
2050
3438
|
(this.comment.layer === -1 ? options.scale : 1);
|
|
2051
|
-
|
|
2052
|
-
return {
|
|
3439
|
+
renderer.setScale(scale * this.comment.scaleX, scale);
|
|
3440
|
+
return { renderer };
|
|
2053
3441
|
}
|
|
2054
3442
|
}
|
|
2055
3443
|
|
|
@@ -2072,10 +3460,7 @@
|
|
|
2072
3460
|
lineOffset,
|
|
2073
3461
|
};
|
|
2074
3462
|
this.comment = this.getCommentSize(comment);
|
|
2075
|
-
this.cacheKey =
|
|
2076
|
-
JSON.stringify(this.comment.content) +
|
|
2077
|
-
`@@${this.pluginName}@@` +
|
|
2078
|
-
[...this.comment.mail].sort().join(",");
|
|
3463
|
+
this.cacheKey = this.getCacheKey();
|
|
2079
3464
|
delete this.image;
|
|
2080
3465
|
}
|
|
2081
3466
|
convertComment(comment) {
|
|
@@ -2083,7 +3468,6 @@
|
|
|
2083
3468
|
}
|
|
2084
3469
|
getCommentSize(parsedData) {
|
|
2085
3470
|
if (parsedData.invisible) {
|
|
2086
|
-
this.context.restore();
|
|
2087
3471
|
return {
|
|
2088
3472
|
...parsedData,
|
|
2089
3473
|
height: 0,
|
|
@@ -2099,15 +3483,15 @@
|
|
|
2099
3483
|
scale: 1,
|
|
2100
3484
|
};
|
|
2101
3485
|
}
|
|
2102
|
-
this.
|
|
2103
|
-
this.
|
|
3486
|
+
this.renderer.save();
|
|
3487
|
+
this.renderer.setFont(parseFont(parsedData.font, parsedData.fontSize));
|
|
2104
3488
|
const measure = this.measureText({ ...parsedData, scale: 1 });
|
|
2105
3489
|
if (options.scale !== 1 && parsedData.layer === -1) {
|
|
2106
3490
|
measure.height *= options.scale;
|
|
2107
3491
|
measure.width *= options.scale;
|
|
2108
3492
|
measure.fontSize *= options.scale;
|
|
2109
3493
|
}
|
|
2110
|
-
this.
|
|
3494
|
+
this.renderer.restore();
|
|
2111
3495
|
return {
|
|
2112
3496
|
...parsedData,
|
|
2113
3497
|
height: measure.height,
|
|
@@ -2125,7 +3509,7 @@
|
|
|
2125
3509
|
}
|
|
2126
3510
|
parseCommandAndNicoscript(comment) {
|
|
2127
3511
|
const data = parseCommandAndNicoScript(comment);
|
|
2128
|
-
const { content, lineCount, lineOffset } = this.parseContent(comment.content);
|
|
3512
|
+
const { content, lineCount, lineOffset } = this.parseContent(comment.content, data.font);
|
|
2129
3513
|
return {
|
|
2130
3514
|
...comment,
|
|
2131
3515
|
rawContent: comment.content,
|
|
@@ -2135,15 +3519,10 @@
|
|
|
2135
3519
|
lineOffset,
|
|
2136
3520
|
};
|
|
2137
3521
|
}
|
|
2138
|
-
parseContent(input) {
|
|
3522
|
+
parseContent(input, font) {
|
|
2139
3523
|
const content = [];
|
|
2140
|
-
content
|
|
2141
|
-
|
|
2142
|
-
slicedContent: input.split("\n"),
|
|
2143
|
-
});
|
|
2144
|
-
const lineCount = content.reduce((pv, val) => {
|
|
2145
|
-
return pv + (val.content.match(/\n/g)?.length ?? 0);
|
|
2146
|
-
}, 1);
|
|
3524
|
+
addHTML5PartToResult(content, input, font ?? "defont");
|
|
3525
|
+
const lineCount = input.split("\n").length;
|
|
2147
3526
|
const lineOffset = 0;
|
|
2148
3527
|
return {
|
|
2149
3528
|
content,
|
|
@@ -2159,7 +3538,7 @@
|
|
|
2159
3538
|
if (!comment.charSize)
|
|
2160
3539
|
comment.charSize = charSize;
|
|
2161
3540
|
comment.fontSize = comment.charSize * 0.8;
|
|
2162
|
-
this.
|
|
3541
|
+
this.renderer.setFont(parseFont(comment.font, comment.fontSize));
|
|
2163
3542
|
if (isLineBreakResize(comment)) {
|
|
2164
3543
|
comment.fontSize = configFontSize[comment.size].resized;
|
|
2165
3544
|
const lineHeight = getLineHeight(comment.size, false, true);
|
|
@@ -2171,7 +3550,7 @@
|
|
|
2171
3550
|
const { width, height, itemWidth } = this._measureComment(comment);
|
|
2172
3551
|
for (let i = 0, n = comment.content.length; i < n; i++) {
|
|
2173
3552
|
const item = comment.content[i];
|
|
2174
|
-
if (
|
|
3553
|
+
if (item?.type !== "text" || !itemWidth)
|
|
2175
3554
|
continue;
|
|
2176
3555
|
item.width = itemWidth[i];
|
|
2177
3556
|
}
|
|
@@ -2194,17 +3573,17 @@
|
|
|
2194
3573
|
};
|
|
2195
3574
|
}
|
|
2196
3575
|
_measureComment(comment) {
|
|
2197
|
-
const widthLimit = getConfig(config.
|
|
3576
|
+
const widthLimit = getConfig(config.commentStageSize, false)[comment.full ? "fullWidth" : "width"];
|
|
2198
3577
|
if (!typeGuard.internal.MeasureInput(comment))
|
|
2199
3578
|
throw new TypeGuardError();
|
|
2200
|
-
const measureResult = measure(comment, this.
|
|
3579
|
+
const measureResult = measure(comment, this.renderer);
|
|
2201
3580
|
if (comment.loc !== "naka" && measureResult.width > widthLimit) {
|
|
2202
3581
|
return this._processResizeX(comment, measureResult.width);
|
|
2203
3582
|
}
|
|
2204
3583
|
return measureResult;
|
|
2205
3584
|
}
|
|
2206
3585
|
_processResizeX(comment, width) {
|
|
2207
|
-
const widthLimit = getConfig(config.
|
|
3586
|
+
const widthLimit = getConfig(config.commentStageSize, false)[comment.full ? "fullWidth" : "width"];
|
|
2208
3587
|
const lineHeight = getLineHeight(comment.size, false);
|
|
2209
3588
|
const charSize = getCharSize(comment.size, false);
|
|
2210
3589
|
const scale = widthLimit / width;
|
|
@@ -2215,14 +3594,14 @@
|
|
|
2215
3594
|
_comment.fontSize = _comment.charSize * 0.8;
|
|
2216
3595
|
if (!typeGuard.internal.MeasureInput(_comment))
|
|
2217
3596
|
throw new TypeGuardError();
|
|
2218
|
-
let result = measure(_comment, this.
|
|
3597
|
+
let result = measure(_comment, this.renderer);
|
|
2219
3598
|
if (result.width > widthLimit) {
|
|
2220
3599
|
while (result.width >= widthLimit) {
|
|
2221
3600
|
const originalCharSize = _comment.charSize;
|
|
2222
3601
|
_comment.charSize -= 1;
|
|
2223
3602
|
_comment.lineHeight *= _comment.charSize / originalCharSize;
|
|
2224
3603
|
_comment.fontSize = _comment.charSize * 0.8;
|
|
2225
|
-
result = measure(_comment, this.
|
|
3604
|
+
result = measure(_comment, this.renderer);
|
|
2226
3605
|
}
|
|
2227
3606
|
}
|
|
2228
3607
|
else {
|
|
@@ -2233,7 +3612,7 @@
|
|
|
2233
3612
|
_comment.charSize += 1;
|
|
2234
3613
|
_comment.lineHeight *= _comment.charSize / originalCharSize;
|
|
2235
3614
|
_comment.fontSize = _comment.charSize * 0.8;
|
|
2236
|
-
result = measure(_comment, this.
|
|
3615
|
+
result = measure(_comment, this.renderer);
|
|
2237
3616
|
}
|
|
2238
3617
|
_comment = lastComment;
|
|
2239
3618
|
}
|
|
@@ -2249,54 +3628,54 @@
|
|
|
2249
3628
|
comment.fontSize = (comment.charSize ?? 0) * 0.8;
|
|
2250
3629
|
if (!typeGuard.internal.MeasureInput(comment))
|
|
2251
3630
|
throw new TypeGuardError();
|
|
2252
|
-
return measure(comment, this.
|
|
3631
|
+
return measure(comment, this.renderer);
|
|
2253
3632
|
}
|
|
2254
3633
|
_drawCollision(posX, posY, showCollision) {
|
|
2255
3634
|
if (showCollision) {
|
|
2256
|
-
this.
|
|
3635
|
+
this.renderer.save();
|
|
2257
3636
|
const scale = getConfig(config.commentScale, false);
|
|
2258
|
-
this.
|
|
2259
|
-
this.
|
|
3637
|
+
this.renderer.setStrokeStyle("rgba(0,255,255,1)");
|
|
3638
|
+
this.renderer.strokeRect(posX, posY, this.comment.width, this.comment.height);
|
|
2260
3639
|
for (let i = 0, n = this.comment.lineCount; i < n; i++) {
|
|
2261
3640
|
if (!typeGuard.internal.HTML5Fonts(this.comment.font))
|
|
2262
3641
|
throw new TypeGuardError();
|
|
2263
3642
|
const linePosY = (this.comment.lineHeight * (i + 1) +
|
|
2264
3643
|
(this.comment.charSize - this.comment.lineHeight) / 2 +
|
|
2265
3644
|
this.comment.lineHeight * -0.16 +
|
|
2266
|
-
(config.fonts[this.comment.font]?.offset || 0)) *
|
|
3645
|
+
(config.fonts.html5[this.comment.font]?.offset || 0)) *
|
|
2267
3646
|
scale;
|
|
2268
|
-
this.
|
|
2269
|
-
this.
|
|
3647
|
+
this.renderer.setStrokeStyle("rgba(255,255,0,0.5)");
|
|
3648
|
+
this.renderer.strokeRect(posX, posY + linePosY, this.comment.width, this.comment.fontSize * -1 * scale);
|
|
2270
3649
|
}
|
|
2271
|
-
this.
|
|
3650
|
+
this.renderer.restore();
|
|
2272
3651
|
}
|
|
2273
3652
|
}
|
|
2274
3653
|
_generateTextImage() {
|
|
2275
3654
|
const { fontSize, scale } = getFontSizeAndScale(this.comment.charSize);
|
|
2276
3655
|
const paddingTop = (10 - scale * 10) *
|
|
2277
|
-
((this.comment.lineCount + 1) / config.
|
|
3656
|
+
((this.comment.lineCount + 1) / config.html5HiResCommentCorrection);
|
|
2278
3657
|
const drawScale = getConfig(config.commentScale, false) *
|
|
2279
3658
|
scale *
|
|
2280
3659
|
(this.comment.layer === -1 ? options.scale : 1);
|
|
2281
|
-
const
|
|
2282
|
-
image.
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
context.textBaseline = "alphabetic";
|
|
2290
|
-
context.lineWidth = getConfig(config.contextLineWidth, false);
|
|
2291
|
-
context.font = parseFont(this.comment.font, fontSize);
|
|
2292
|
-
context.scale(drawScale, drawScale);
|
|
3660
|
+
const image = this.renderer.getCanvas();
|
|
3661
|
+
image.setSize(this.comment.width + 2 * 2 * this.comment.charSize, this.comment.height +
|
|
3662
|
+
(((paddingTop + 1) * this.comment.lineHeight) / scale) * drawScale);
|
|
3663
|
+
image.setStrokeStyle(getStrokeColor(this.comment));
|
|
3664
|
+
image.setFillStyle(this.comment.color);
|
|
3665
|
+
image.setLineWidth(getConfig(config.contextLineWidth, false));
|
|
3666
|
+
image.setFont(parseFont(this.comment.font, fontSize));
|
|
3667
|
+
image.setScale(drawScale);
|
|
2293
3668
|
let lineCount = 0;
|
|
2294
3669
|
if (!typeGuard.internal.HTML5Fonts(this.comment.font))
|
|
2295
3670
|
throw new TypeGuardError();
|
|
2296
3671
|
const offsetY = (this.comment.charSize - this.comment.lineHeight) / 2 +
|
|
2297
3672
|
this.comment.lineHeight * -0.16 +
|
|
2298
|
-
(config.fonts[this.comment.font]?.offset || 0);
|
|
3673
|
+
(config.fonts.html5[this.comment.font]?.offset || 0);
|
|
2299
3674
|
for (const item of this.comment.content) {
|
|
3675
|
+
if (item?.type === "spacer") {
|
|
3676
|
+
lineCount += item.count * item.charWidth * this.comment.fontSize;
|
|
3677
|
+
continue;
|
|
3678
|
+
}
|
|
2300
3679
|
const lines = item.slicedContent;
|
|
2301
3680
|
for (let j = 0, n = lines.length; j < n; j++) {
|
|
2302
3681
|
const line = lines[j];
|
|
@@ -2304,8 +3683,8 @@
|
|
|
2304
3683
|
continue;
|
|
2305
3684
|
const posY = (this.comment.lineHeight * (lineCount + 1 + paddingTop) + offsetY) /
|
|
2306
3685
|
scale;
|
|
2307
|
-
|
|
2308
|
-
|
|
3686
|
+
image.strokeText(line, 0, posY);
|
|
3687
|
+
image.fillText(line, 0, posY);
|
|
2309
3688
|
lineCount += 1;
|
|
2310
3689
|
}
|
|
2311
3690
|
}
|
|
@@ -2319,7 +3698,7 @@
|
|
|
2319
3698
|
}
|
|
2320
3699
|
}
|
|
2321
3700
|
|
|
2322
|
-
var index = /*#__PURE__*/Object.freeze({
|
|
3701
|
+
var index$1 = /*#__PURE__*/Object.freeze({
|
|
2323
3702
|
__proto__: null,
|
|
2324
3703
|
BaseComment: BaseComment,
|
|
2325
3704
|
FlashComment: FlashComment,
|
|
@@ -2500,7 +3879,7 @@
|
|
|
2500
3879
|
html5: 1920 / 683,
|
|
2501
3880
|
flash: 1920 / 683,
|
|
2502
3881
|
},
|
|
2503
|
-
|
|
3882
|
+
commentStageSize: {
|
|
2504
3883
|
html5: {
|
|
2505
3884
|
width: 512,
|
|
2506
3885
|
fullWidth: 683,
|
|
@@ -2542,7 +3921,7 @@
|
|
|
2542
3921
|
},
|
|
2543
3922
|
},
|
|
2544
3923
|
},
|
|
2545
|
-
|
|
3924
|
+
html5LineCounts: {
|
|
2546
3925
|
default: {
|
|
2547
3926
|
big: 8.4,
|
|
2548
3927
|
medium: 13.1,
|
|
@@ -2559,9 +3938,15 @@
|
|
|
2559
3938
|
small: 16.6,
|
|
2560
3939
|
},
|
|
2561
3940
|
},
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
fonts:
|
|
3941
|
+
html5HiResCommentCorrection: 20,
|
|
3942
|
+
html5MinFontSize: 10,
|
|
3943
|
+
fonts: {
|
|
3944
|
+
html5: fonts[platform],
|
|
3945
|
+
flash: {
|
|
3946
|
+
gulim: `normal 600 [size]px gulim, ${fonts[platform].gothic.font}, Arial`,
|
|
3947
|
+
simsun: `normal 400 [size]px simsun, batang, "PMingLiU", MingLiU-ExtB, ${fonts[platform].mincho.font}, Arial`,
|
|
3948
|
+
},
|
|
3949
|
+
},
|
|
2565
3950
|
fpsInterval: 500,
|
|
2566
3951
|
cacheAge: 2000,
|
|
2567
3952
|
canvasWidth: 1920,
|
|
@@ -2572,6 +3957,7 @@
|
|
|
2572
3957
|
left: 235,
|
|
2573
3958
|
right: 1685,
|
|
2574
3959
|
},
|
|
3960
|
+
collisionPadding: 5,
|
|
2575
3961
|
sameCARange: 3600,
|
|
2576
3962
|
sameCAGap: 100,
|
|
2577
3963
|
sameCAMinScore: 10,
|
|
@@ -2579,20 +3965,16 @@
|
|
|
2579
3965
|
plugins: [],
|
|
2580
3966
|
flashThreshold: 1499871600,
|
|
2581
3967
|
flashChar: {
|
|
2582
|
-
gulim: "[\u0126\u0127\u0132\u0133\u0138\u013f\u0140\u0149-\u014b\u0166\u0167\u02d0\u02da\u2074\u207f\u2081-\u2084\u2113\u2153\u2154\u215c-\u215e\u2194\u2195\u223c\u249c-\u24b5\u24d0-\u24e9\u25a3-\u25a9\u25b6\u25b7\u25c0\u25c1\u25c8\u25d0\u25d1\u260e\u260f\u261c\u261e\u2660\u2661\u2663-\u2665\u2667-\u2669\u266c\u3131-\u316e\u3200-\u321c\u3260-\u327b\u3380-\u3384\u3388-\u338d\u3390-\u339b\u339f\u33a0\u33a2-\u33ca\u33cf\u33d0\u33d3\u33d6\u33d8\u33db-\u33dd\uf900-\uf928\uf92a-\uf994\uf996\ufa0b\uffe6]",
|
|
3968
|
+
gulim: "[\u0126\u0127\u0132\u0133\u0138\u013f\u0140\u0149-\u014b\u0166\u0167\u02d0\u02da\u2074\u207f\u2081-\u2084\u2113\u2153\u2154\u215c-\u215e\u2194\u2195\u223c\u249c-\u24b5\u24d0-\u24e9\u25a3-\u25a9\u25b6\u25b7\u25c0\u25c1\u25c8\u25d0\u25d1\u260e\u260f\u261c\u261e\u2660\u2661\u2663-\u2665\u2667-\u2669\u266c\u3131-\u316e\u3200-\u321c\u3260-\u327b\u3380-\u3384\u3388-\u338d\u3390-\u339b\u339f\u33a0\u33a2-\u33ca\u33cf\u33d0\u33d3\u33d6\u33d8\u33db-\u33dd\uac00-\ud7a3\uf900-\uf928\uf92a-\uf994\uf996\ufa0b\uffe6]",
|
|
2583
3969
|
simsunStrong: "[\u01ce\u01d0\u01d2\u01d4\u01d6\u01d8\u01da\u01dc\u0251\u0261\u02ca\u02cb\u2016\u2035\u216a\u216b\u2223\u2236\u2237\u224c\u226e\u226f\u2295\u2483-\u249b\u2504-\u250b\u256d-\u2573\u2581-\u2583\u2585-\u2587\u2589-\u258b\u258d-\u258f\u2594\u2595\u25e2-\u25e5\u2609\u3016\u3017\u301e\u3021-\u3029\u3105-\u3129\u3220-\u3229\u32a3\u33ce\u33d1\u33d2\u33d5\ue758-\ue864\ufa0c\ufa0d\ufe30\ufe31\ufe33-\ufe44\ufe49-\ufe52\ufe54-\ufe57\ufe59-\ufe66\ufe68-\ufe6b]",
|
|
2584
3970
|
simsunWeak: "[\u02c9\u2105\u2109\u2196-\u2199\u220f\u2215\u2248\u2264\u2265\u2299\u2474-\u2482\u250d\u250e\u2511\u2512\u2515\u2516\u2519\u251a\u251e\u251f\u2521\u2522\u2526\u2527\u2529\u252a\u252d\u252e\u2531\u2532\u2535\u2536\u2539\u253a\u253d\u253e\u2540\u2541\u2543-\u254a\u2550-\u256c\u2584\u2588\u258c\u2593]",
|
|
2585
|
-
gothic: "[\u03fb\uff9f]",
|
|
3971
|
+
gothic: "[\u03fb\uff9f\u30fb]",
|
|
2586
3972
|
},
|
|
2587
|
-
|
|
2588
|
-
|
|
3973
|
+
flashMode: "vista",
|
|
3974
|
+
flashScriptChar: {
|
|
2589
3975
|
super: "[\u00aa\u00b2\u00b3\u00b9\u00ba\u02b0\u02b2\u02b3\u02b7\u02b8\u02e1-\u02e3\u0304\u1d2c-\u1d43\u1d45-\u1d61\u1d9b-\u1da1\u1da3-\u1dbf\u2070\u2071\u2074-\u207f\u2c7d]",
|
|
2590
3976
|
sub: "[\u0320\u1d62-\u1d6a\u2080-\u208e\u2090-\u209c\u2c7c]",
|
|
2591
3977
|
},
|
|
2592
|
-
font: {
|
|
2593
|
-
gulim: 'normal 600 [size]px gulim, "Microsoft JhengHei UI", Arial, "MS Pゴシック", "MS PGothic", MSPGothic, MS-PGothic',
|
|
2594
|
-
simsun: 'normal 400 [size]px simsun, "游明朝体", "游明朝", "Yu Mincho", YuMincho, yumincho, YuMin-Medium',
|
|
2595
|
-
},
|
|
2596
3978
|
lineHeight: {
|
|
2597
3979
|
small: {
|
|
2598
3980
|
default: 18 / 15,
|
|
@@ -2607,26 +3989,17 @@
|
|
|
2607
3989
|
resized: 24 / 19.5,
|
|
2608
3990
|
},
|
|
2609
3991
|
},
|
|
2610
|
-
|
|
2611
|
-
full: 1200,
|
|
2612
|
-
normal: 960,
|
|
2613
|
-
},
|
|
2614
|
-
commentYPaddingTop: {
|
|
3992
|
+
flashCommentYPaddingTop: {
|
|
2615
3993
|
default: 5,
|
|
2616
3994
|
resized: 3,
|
|
2617
3995
|
},
|
|
2618
|
-
|
|
2619
|
-
small: 0.24,
|
|
2620
|
-
medium: 0.28,
|
|
2621
|
-
big: 0.24,
|
|
2622
|
-
},
|
|
2623
|
-
commentYOffset: {
|
|
3996
|
+
flashCommentYOffset: {
|
|
2624
3997
|
small: { default: -0.2, resized: -0.2 },
|
|
2625
3998
|
medium: { default: -0.2, resized: -0.2 },
|
|
2626
3999
|
big: { default: -0.2, resized: -0.2 },
|
|
2627
4000
|
},
|
|
2628
|
-
|
|
2629
|
-
|
|
4001
|
+
flashLetterSpacing: 1,
|
|
4002
|
+
flashScriptCharOffset: 0.12,
|
|
2630
4003
|
commentLimit: undefined,
|
|
2631
4004
|
hideCommentOrder: "asc",
|
|
2632
4005
|
lineBreakCount: {
|
|
@@ -2643,6 +4016,50 @@
|
|
|
2643
4016
|
nakaCommentSpeedOffset: 0.95,
|
|
2644
4017
|
atButtonPadding: 5,
|
|
2645
4018
|
atButtonRadius: 7,
|
|
4019
|
+
flashDoubleResizeHeights: {
|
|
4020
|
+
big: {
|
|
4021
|
+
9: 392,
|
|
4022
|
+
10: 384,
|
|
4023
|
+
11: 389,
|
|
4024
|
+
12: 388,
|
|
4025
|
+
13: 381,
|
|
4026
|
+
14: 381,
|
|
4027
|
+
15: 384,
|
|
4028
|
+
},
|
|
4029
|
+
},
|
|
4030
|
+
flashLineBreakScale: {
|
|
4031
|
+
small: 0.557,
|
|
4032
|
+
medium: 0.519,
|
|
4033
|
+
big: 0.535,
|
|
4034
|
+
},
|
|
4035
|
+
compatSpacer: {
|
|
4036
|
+
flash: {
|
|
4037
|
+
"\u3000": {
|
|
4038
|
+
simsun: 0.98,
|
|
4039
|
+
defont: 0.645,
|
|
4040
|
+
gulim: 0.95,
|
|
4041
|
+
},
|
|
4042
|
+
"\u00a0": {
|
|
4043
|
+
simsun: 0.25,
|
|
4044
|
+
},
|
|
4045
|
+
"\u0020": {
|
|
4046
|
+
defont: 0.3,
|
|
4047
|
+
},
|
|
4048
|
+
"\u2001": {
|
|
4049
|
+
defont: 0.95,
|
|
4050
|
+
},
|
|
4051
|
+
"\u2004": {
|
|
4052
|
+
defont: 1.6,
|
|
4053
|
+
},
|
|
4054
|
+
"\u2007": {
|
|
4055
|
+
defont: 1.6,
|
|
4056
|
+
},
|
|
4057
|
+
"\u202a": {
|
|
4058
|
+
defont: 0.59,
|
|
4059
|
+
},
|
|
4060
|
+
},
|
|
4061
|
+
html5: {},
|
|
4062
|
+
},
|
|
2646
4063
|
};
|
|
2647
4064
|
updateConfig(defaultConfig);
|
|
2648
4065
|
};
|
|
@@ -2754,32 +4171,44 @@
|
|
|
2754
4171
|
|
|
2755
4172
|
const convert2formattedComment = (data, type) => {
|
|
2756
4173
|
let result = [];
|
|
4174
|
+
try {
|
|
4175
|
+
result = parseComments(data, type);
|
|
4176
|
+
}
|
|
4177
|
+
catch (e) {
|
|
4178
|
+
if (e instanceof ValiError) {
|
|
4179
|
+
console.error("", e.issues);
|
|
4180
|
+
}
|
|
4181
|
+
}
|
|
4182
|
+
return sort(result);
|
|
4183
|
+
};
|
|
4184
|
+
const parseComments = (data, type) => {
|
|
2757
4185
|
if (type === "empty" && data === undefined) {
|
|
2758
4186
|
return [];
|
|
2759
4187
|
}
|
|
2760
4188
|
else if ((type === "XMLDocument" || type === "niconicome") &&
|
|
2761
4189
|
typeGuard.xmlDocument(data)) {
|
|
2762
|
-
|
|
4190
|
+
return fromXMLDocument(data);
|
|
2763
4191
|
}
|
|
2764
|
-
else if (type === "formatted"
|
|
2765
|
-
|
|
4192
|
+
else if (type === "formatted") {
|
|
4193
|
+
return fromFormatted(parse(array(ZFormattedComment), data));
|
|
2766
4194
|
}
|
|
2767
|
-
else if (type === "legacy"
|
|
2768
|
-
|
|
4195
|
+
else if (type === "legacy") {
|
|
4196
|
+
return fromLegacy(parse(array(ZRawApiResponse), data));
|
|
2769
4197
|
}
|
|
2770
|
-
else if (type === "legacyOwner"
|
|
2771
|
-
|
|
4198
|
+
else if (type === "legacyOwner") {
|
|
4199
|
+
if (!typeGuard.legacyOwner.comments(data))
|
|
4200
|
+
throw new InvalidFormatError();
|
|
4201
|
+
return fromLegacyOwner(data);
|
|
2772
4202
|
}
|
|
2773
|
-
else if (type === "owner"
|
|
2774
|
-
|
|
4203
|
+
else if (type === "owner") {
|
|
4204
|
+
return fromOwner(parse(array(ZOwnerComment), data));
|
|
2775
4205
|
}
|
|
2776
|
-
else if (type === "v1"
|
|
2777
|
-
|
|
4206
|
+
else if (type === "v1") {
|
|
4207
|
+
return fromV1(parse(array(ZV1Thread), data));
|
|
2778
4208
|
}
|
|
2779
4209
|
else {
|
|
2780
4210
|
throw new InvalidFormatError();
|
|
2781
4211
|
}
|
|
2782
|
-
return sort(result);
|
|
2783
4212
|
};
|
|
2784
4213
|
const fromXMLDocument = (data) => {
|
|
2785
4214
|
const data_ = [], userList = [];
|
|
@@ -2820,24 +4249,15 @@
|
|
|
2820
4249
|
return data_;
|
|
2821
4250
|
};
|
|
2822
4251
|
const fromFormatted = (data) => {
|
|
2823
|
-
return data
|
|
2824
|
-
if (!typeGuard.formatted.comment(comment)) {
|
|
2825
|
-
return {
|
|
2826
|
-
...comment,
|
|
2827
|
-
layer: -1,
|
|
2828
|
-
user_id: 0,
|
|
2829
|
-
is_my_post: false,
|
|
2830
|
-
};
|
|
2831
|
-
}
|
|
2832
|
-
return comment;
|
|
2833
|
-
});
|
|
4252
|
+
return data;
|
|
2834
4253
|
};
|
|
2835
4254
|
const fromLegacy = (data) => {
|
|
2836
4255
|
const data_ = [], userList = [];
|
|
2837
|
-
for (const
|
|
2838
|
-
|
|
4256
|
+
for (const _val of data) {
|
|
4257
|
+
const val = safeParse(ZApiChat, _val.chat);
|
|
4258
|
+
if (!val.success)
|
|
2839
4259
|
continue;
|
|
2840
|
-
const value = val.
|
|
4260
|
+
const value = val.output;
|
|
2841
4261
|
if (value.deleted !== 1) {
|
|
2842
4262
|
const tmpParam = {
|
|
2843
4263
|
id: value.no,
|
|
@@ -2990,8 +4410,8 @@
|
|
|
2990
4410
|
});
|
|
2991
4411
|
return data;
|
|
2992
4412
|
};
|
|
2993
|
-
const time2vpos = (
|
|
2994
|
-
const time = RegExp(/^(?:(\d+):(\d+)\.(\d+)|(\d+):(\d+)|(\d+)\.(\d+)|(\d+))$/).exec(
|
|
4413
|
+
const time2vpos = (input) => {
|
|
4414
|
+
const time = RegExp(/^(?:(\d+):(\d+)\.(\d+)|(\d+):(\d+)|(\d+)\.(\d+)|(\d+))$/).exec(input);
|
|
2995
4415
|
if (time) {
|
|
2996
4416
|
if (time[1] !== undefined &&
|
|
2997
4417
|
time[2] !== undefined &&
|
|
@@ -3019,6 +4439,123 @@
|
|
|
3019
4439
|
default: convert2formattedComment
|
|
3020
4440
|
});
|
|
3021
4441
|
|
|
4442
|
+
class CanvasRenderer {
|
|
4443
|
+
canvas;
|
|
4444
|
+
video;
|
|
4445
|
+
context;
|
|
4446
|
+
constructor(canvas, video) {
|
|
4447
|
+
this.canvas = canvas ?? document.createElement("canvas");
|
|
4448
|
+
const context = this.canvas.getContext("2d");
|
|
4449
|
+
if (!context)
|
|
4450
|
+
throw new CanvasRenderingContext2DError();
|
|
4451
|
+
this.context = context;
|
|
4452
|
+
this.context.textAlign = "start";
|
|
4453
|
+
this.context.textBaseline = "alphabetic";
|
|
4454
|
+
this.video = video;
|
|
4455
|
+
}
|
|
4456
|
+
drawVideo(enableLegacyPip) {
|
|
4457
|
+
if (this.video) {
|
|
4458
|
+
let scale;
|
|
4459
|
+
const height = this.canvas.height / this.video.videoHeight, width = this.canvas.width / this.video.videoWidth;
|
|
4460
|
+
if (enableLegacyPip ? height > width : height < width) {
|
|
4461
|
+
scale = width;
|
|
4462
|
+
}
|
|
4463
|
+
else {
|
|
4464
|
+
scale = height;
|
|
4465
|
+
}
|
|
4466
|
+
const offsetX = (this.canvas.width - this.video.videoWidth * scale) * 0.5, offsetY = (this.canvas.height - this.video.videoHeight * scale) * 0.5;
|
|
4467
|
+
this.context.drawImage(this.video, offsetX, offsetY, this.video.videoWidth * scale, this.video.videoHeight * scale);
|
|
4468
|
+
}
|
|
4469
|
+
}
|
|
4470
|
+
getFont() {
|
|
4471
|
+
return this.context.font;
|
|
4472
|
+
}
|
|
4473
|
+
getFillStyle() {
|
|
4474
|
+
return this.context.fillStyle;
|
|
4475
|
+
}
|
|
4476
|
+
setScale(scale, arg1) {
|
|
4477
|
+
this.context.scale(scale, arg1 ?? scale);
|
|
4478
|
+
}
|
|
4479
|
+
drawImage(image, x, y, width, height) {
|
|
4480
|
+
if (width === undefined || height === undefined)
|
|
4481
|
+
this.context.drawImage(image.canvas, x, y);
|
|
4482
|
+
else
|
|
4483
|
+
this.context.drawImage(image.canvas, x, y, width, height);
|
|
4484
|
+
}
|
|
4485
|
+
fillRect(x, y, width, height) {
|
|
4486
|
+
this.context.fillRect(x, y, width, height);
|
|
4487
|
+
}
|
|
4488
|
+
strokeRect(x, y, width, height) {
|
|
4489
|
+
this.context.strokeRect(x, y, width, height);
|
|
4490
|
+
}
|
|
4491
|
+
fillText(text, x, y) {
|
|
4492
|
+
this.context.fillText(text, x, y);
|
|
4493
|
+
}
|
|
4494
|
+
strokeText(text, x, y) {
|
|
4495
|
+
this.context.strokeText(text, x, y);
|
|
4496
|
+
}
|
|
4497
|
+
quadraticCurveTo(cpx, cpy, x, y) {
|
|
4498
|
+
this.context.quadraticCurveTo(cpx, cpy, x, y);
|
|
4499
|
+
}
|
|
4500
|
+
clearRect(x, y, width, height) {
|
|
4501
|
+
this.context.clearRect(x, y, width, height);
|
|
4502
|
+
}
|
|
4503
|
+
setFont(font) {
|
|
4504
|
+
this.context.font = font;
|
|
4505
|
+
}
|
|
4506
|
+
setFillStyle(color) {
|
|
4507
|
+
this.context.fillStyle = color;
|
|
4508
|
+
}
|
|
4509
|
+
setStrokeStyle(color) {
|
|
4510
|
+
this.context.strokeStyle = color;
|
|
4511
|
+
}
|
|
4512
|
+
setLineWidth(width) {
|
|
4513
|
+
this.context.lineWidth = width;
|
|
4514
|
+
}
|
|
4515
|
+
setGlobalAlpha(alpha) {
|
|
4516
|
+
this.context.globalAlpha = alpha;
|
|
4517
|
+
}
|
|
4518
|
+
setSize(width, height) {
|
|
4519
|
+
this.canvas.width = width;
|
|
4520
|
+
this.canvas.height = height;
|
|
4521
|
+
}
|
|
4522
|
+
getSize() {
|
|
4523
|
+
return { width: this.canvas.width, height: this.canvas.height };
|
|
4524
|
+
}
|
|
4525
|
+
measureText(text) {
|
|
4526
|
+
return this.context.measureText(text);
|
|
4527
|
+
}
|
|
4528
|
+
beginPath() {
|
|
4529
|
+
this.context.beginPath();
|
|
4530
|
+
}
|
|
4531
|
+
closePath() {
|
|
4532
|
+
this.context.closePath();
|
|
4533
|
+
}
|
|
4534
|
+
moveTo(x, y) {
|
|
4535
|
+
this.context.moveTo(x, y);
|
|
4536
|
+
}
|
|
4537
|
+
lineTo(x, y) {
|
|
4538
|
+
this.context.lineTo(x, y);
|
|
4539
|
+
}
|
|
4540
|
+
stroke() {
|
|
4541
|
+
this.context.stroke();
|
|
4542
|
+
}
|
|
4543
|
+
save() {
|
|
4544
|
+
this.context.save();
|
|
4545
|
+
}
|
|
4546
|
+
restore() {
|
|
4547
|
+
this.context.restore();
|
|
4548
|
+
}
|
|
4549
|
+
getCanvas() {
|
|
4550
|
+
return new CanvasRenderer();
|
|
4551
|
+
}
|
|
4552
|
+
}
|
|
4553
|
+
|
|
4554
|
+
var index = /*#__PURE__*/Object.freeze({
|
|
4555
|
+
__proto__: null,
|
|
4556
|
+
CanvasRenderer: CanvasRenderer
|
|
4557
|
+
});
|
|
4558
|
+
|
|
3022
4559
|
const createCommentInstance = (comment, context) => {
|
|
3023
4560
|
for (const plugin of config.commentPlugins) {
|
|
3024
4561
|
if (plugin.condition(comment)) {
|
|
@@ -3037,14 +4574,15 @@
|
|
|
3037
4574
|
|
|
3038
4575
|
var internal = /*#__PURE__*/Object.freeze({
|
|
3039
4576
|
__proto__: null,
|
|
3040
|
-
comments: index,
|
|
3041
|
-
contexts: index$
|
|
4577
|
+
comments: index$1,
|
|
4578
|
+
contexts: index$4,
|
|
3042
4579
|
definition: definition,
|
|
3043
|
-
errors: index$
|
|
4580
|
+
errors: index$3,
|
|
3044
4581
|
eventHandler: eventHandler,
|
|
3045
4582
|
inputParser: inputParser,
|
|
4583
|
+
renderer: index,
|
|
3046
4584
|
typeGuard: typeGuard$1,
|
|
3047
|
-
utils: index$
|
|
4585
|
+
utils: index$2
|
|
3048
4586
|
});
|
|
3049
4587
|
|
|
3050
4588
|
class NiconiComments {
|
|
@@ -3052,11 +4590,9 @@
|
|
|
3052
4590
|
showCollision;
|
|
3053
4591
|
showFPS;
|
|
3054
4592
|
showCommentCount;
|
|
3055
|
-
video;
|
|
3056
4593
|
lastVpos;
|
|
3057
|
-
|
|
4594
|
+
renderer;
|
|
3058
4595
|
collision;
|
|
3059
|
-
context;
|
|
3060
4596
|
timeline;
|
|
3061
4597
|
static typeGuard = typeGuard;
|
|
3062
4598
|
static default = NiconiComments;
|
|
@@ -3065,7 +4601,7 @@
|
|
|
3065
4601
|
class: FlashComment,
|
|
3066
4602
|
};
|
|
3067
4603
|
static internal = internal;
|
|
3068
|
-
constructor(
|
|
4604
|
+
constructor(renderer, data, initOptions = {}) {
|
|
3069
4605
|
const constructorStart = performance.now();
|
|
3070
4606
|
initConfig();
|
|
3071
4607
|
if (!typeGuard.config.initOptions(initOptions))
|
|
@@ -3075,11 +4611,14 @@
|
|
|
3075
4611
|
setIsDebug(options.debug);
|
|
3076
4612
|
resetImageCache();
|
|
3077
4613
|
resetNicoScripts();
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
4614
|
+
if (renderer instanceof HTMLCanvasElement) {
|
|
4615
|
+
renderer = new CanvasRenderer(renderer, options.video);
|
|
4616
|
+
}
|
|
4617
|
+
else if (options.video) {
|
|
4618
|
+
console.warn("options.video is ignored because renderer is not HTMLCanvasElement");
|
|
4619
|
+
}
|
|
4620
|
+
this.renderer = renderer;
|
|
4621
|
+
this.renderer.setLineWidth(getConfig(config.contextLineWidth, false));
|
|
3083
4622
|
let formatType = options.format;
|
|
3084
4623
|
if (options.formatted) {
|
|
3085
4624
|
console.warn("Deprecated: options.formatted is no longer recommended. Please use options.format. https://xpadev-net.github.io/niconicomments/#p_format");
|
|
@@ -3094,7 +4633,6 @@
|
|
|
3094
4633
|
options.mode = "html5";
|
|
3095
4634
|
}
|
|
3096
4635
|
const parsedData = convert2formattedComment(data, formatType);
|
|
3097
|
-
this.video = options.video ?? undefined;
|
|
3098
4636
|
this.showCollision = options.showCollision;
|
|
3099
4637
|
this.showFPS = options.showFPS;
|
|
3100
4638
|
this.showCommentCount = options.showCommentCount;
|
|
@@ -3116,7 +4654,7 @@
|
|
|
3116
4654
|
rawData = changeCALayer(rawData);
|
|
3117
4655
|
}
|
|
3118
4656
|
let instances = rawData.reduce((pv, val) => {
|
|
3119
|
-
pv.push(createCommentInstance(val, this.
|
|
4657
|
+
pv.push(createCommentInstance(val, this.renderer));
|
|
3120
4658
|
return pv;
|
|
3121
4659
|
}, []);
|
|
3122
4660
|
this.getCommentPos(instances);
|
|
@@ -3124,7 +4662,7 @@
|
|
|
3124
4662
|
const plugins = [];
|
|
3125
4663
|
for (const plugin of config.plugins) {
|
|
3126
4664
|
try {
|
|
3127
|
-
const canvas =
|
|
4665
|
+
const canvas = this.renderer.getCanvas();
|
|
3128
4666
|
const pluginInstance = new plugin(canvas, instances);
|
|
3129
4667
|
plugins.push({
|
|
3130
4668
|
canvas,
|
|
@@ -3176,7 +4714,7 @@
|
|
|
3176
4714
|
}
|
|
3177
4715
|
addComments(...rawComments) {
|
|
3178
4716
|
const comments = rawComments.reduce((pv, val) => {
|
|
3179
|
-
pv.push(createCommentInstance(val, this.
|
|
4717
|
+
pv.push(createCommentInstance(val, this.renderer));
|
|
3180
4718
|
return pv;
|
|
3181
4719
|
}, []);
|
|
3182
4720
|
for (const plugin of plugins) {
|
|
@@ -3211,19 +4749,20 @@
|
|
|
3211
4749
|
?.length === 0) {
|
|
3212
4750
|
const current = timelineRange.filter((item) => item.loc !== "naka"), last = this.timeline[this.lastVpos]?.filter((item) => item.loc !== "naka") ??
|
|
3213
4751
|
[];
|
|
3214
|
-
if (
|
|
4752
|
+
if (arrayEqual(current, last))
|
|
3215
4753
|
return false;
|
|
3216
4754
|
}
|
|
3217
|
-
|
|
4755
|
+
const size = this.renderer.getSize();
|
|
4756
|
+
this.renderer.clearRect(0, 0, size.width, size.height);
|
|
3218
4757
|
this.lastVpos = vpos;
|
|
3219
4758
|
this._drawVideo();
|
|
3220
4759
|
for (const plugin of plugins) {
|
|
3221
4760
|
try {
|
|
3222
4761
|
plugin.instance.draw?.(vpos);
|
|
3223
|
-
this.
|
|
4762
|
+
this.renderer.drawImage(plugin.canvas, 0, 0);
|
|
3224
4763
|
}
|
|
3225
4764
|
catch (e) {
|
|
3226
|
-
console.error(`Failed to draw comments
|
|
4765
|
+
console.error(`Failed to draw comments`, e);
|
|
3227
4766
|
}
|
|
3228
4767
|
}
|
|
3229
4768
|
this._drawCollision(vpos);
|
|
@@ -3234,18 +4773,7 @@
|
|
|
3234
4773
|
return true;
|
|
3235
4774
|
}
|
|
3236
4775
|
_drawVideo() {
|
|
3237
|
-
|
|
3238
|
-
let scale;
|
|
3239
|
-
const height = this.canvas.height / this.video.videoHeight, width = this.canvas.width / this.video.videoWidth;
|
|
3240
|
-
if (this.enableLegacyPiP ? height > width : height < width) {
|
|
3241
|
-
scale = width;
|
|
3242
|
-
}
|
|
3243
|
-
else {
|
|
3244
|
-
scale = height;
|
|
3245
|
-
}
|
|
3246
|
-
const offsetX = (this.canvas.width - this.video.videoWidth * scale) * 0.5, offsetY = (this.canvas.height - this.video.videoHeight * scale) * 0.5;
|
|
3247
|
-
this.context.drawImage(this.video, offsetX, offsetY, this.video.videoWidth * scale, this.video.videoHeight * scale);
|
|
3248
|
-
}
|
|
4776
|
+
this.renderer.drawVideo(this.enableLegacyPiP);
|
|
3249
4777
|
}
|
|
3250
4778
|
_drawComments(timelineRange, vpos, cursor) {
|
|
3251
4779
|
if (timelineRange) {
|
|
@@ -3268,44 +4796,44 @@
|
|
|
3268
4796
|
}
|
|
3269
4797
|
_drawCollision(vpos) {
|
|
3270
4798
|
if (this.showCollision) {
|
|
3271
|
-
this.
|
|
4799
|
+
this.renderer.save();
|
|
3272
4800
|
const leftCollision = this.collision.left[vpos], rightCollision = this.collision.right[vpos];
|
|
3273
|
-
this.
|
|
4801
|
+
this.renderer.setFillStyle("red");
|
|
3274
4802
|
if (leftCollision) {
|
|
3275
4803
|
for (const comment of leftCollision) {
|
|
3276
|
-
this.
|
|
4804
|
+
this.renderer.fillRect(config.collisionRange.left, comment.posY, getConfig(config.contextLineWidth, comment.flash), comment.height);
|
|
3277
4805
|
}
|
|
3278
4806
|
}
|
|
3279
4807
|
if (rightCollision) {
|
|
3280
4808
|
for (const comment of rightCollision) {
|
|
3281
|
-
this.
|
|
4809
|
+
this.renderer.fillRect(config.collisionRange.right, comment.posY, getConfig(config.contextLineWidth, comment.flash) * -1, comment.height);
|
|
3282
4810
|
}
|
|
3283
4811
|
}
|
|
3284
|
-
this.
|
|
4812
|
+
this.renderer.restore();
|
|
3285
4813
|
}
|
|
3286
4814
|
}
|
|
3287
4815
|
_drawFPS(drawCanvasStart) {
|
|
3288
4816
|
if (this.showFPS) {
|
|
3289
|
-
this.
|
|
3290
|
-
this.
|
|
3291
|
-
this.
|
|
3292
|
-
this.
|
|
4817
|
+
this.renderer.save();
|
|
4818
|
+
this.renderer.setFont(parseFont("defont", 60));
|
|
4819
|
+
this.renderer.setFillStyle("#00FF00");
|
|
4820
|
+
this.renderer.setStrokeStyle(`rgba(${hex2rgb(config.contextStrokeColor).join(",")},${config.contextStrokeOpacity})`);
|
|
3293
4821
|
const drawTime = Math.floor(performance.now() - drawCanvasStart);
|
|
3294
4822
|
const fps = Math.floor(1000 / (drawTime === 0 ? 1 : drawTime));
|
|
3295
|
-
this.
|
|
3296
|
-
this.
|
|
3297
|
-
this.
|
|
4823
|
+
this.renderer.strokeText(`FPS:${fps}(${drawTime}ms)`, 100, 100);
|
|
4824
|
+
this.renderer.fillText(`FPS:${fps}(${drawTime}ms)`, 100, 100);
|
|
4825
|
+
this.renderer.restore();
|
|
3298
4826
|
}
|
|
3299
4827
|
}
|
|
3300
4828
|
_drawCommentCount(count) {
|
|
3301
4829
|
if (this.showCommentCount) {
|
|
3302
|
-
this.
|
|
3303
|
-
this.
|
|
3304
|
-
this.
|
|
3305
|
-
this.
|
|
3306
|
-
this.
|
|
3307
|
-
this.
|
|
3308
|
-
this.
|
|
4830
|
+
this.renderer.save();
|
|
4831
|
+
this.renderer.setFont(parseFont("defont", 60));
|
|
4832
|
+
this.renderer.setFillStyle("#00FF00");
|
|
4833
|
+
this.renderer.setStrokeStyle(`rgba(${hex2rgb(config.contextStrokeColor).join(",")},${config.contextStrokeOpacity})`);
|
|
4834
|
+
this.renderer.strokeText(`Count:${count ?? 0}`, 100, 200);
|
|
4835
|
+
this.renderer.fillText(`Count:${count ?? 0}`, 100, 200);
|
|
4836
|
+
this.renderer.restore();
|
|
3309
4837
|
}
|
|
3310
4838
|
}
|
|
3311
4839
|
addEventListener(eventName, handler) {
|
|
@@ -3315,7 +4843,8 @@
|
|
|
3315
4843
|
removeHandler(eventName, handler);
|
|
3316
4844
|
}
|
|
3317
4845
|
clear() {
|
|
3318
|
-
this.
|
|
4846
|
+
const size = this.renderer.getSize();
|
|
4847
|
+
this.renderer.clearRect(0, 0, size.width, size.height);
|
|
3319
4848
|
}
|
|
3320
4849
|
click(vpos, pos) {
|
|
3321
4850
|
const _comments = this.timeline[vpos];
|
|
@@ -3325,7 +4854,6 @@
|
|
|
3325
4854
|
for (const comment of comments) {
|
|
3326
4855
|
if (comment.isHovered(pos)) {
|
|
3327
4856
|
const newComment = buildAtButtonComment(comment.comment, vpos);
|
|
3328
|
-
console.log(newComment);
|
|
3329
4857
|
if (!newComment)
|
|
3330
4858
|
continue;
|
|
3331
4859
|
this.addComments(newComment);
|