@xpadev-net/niconicomments 0.2.66 → 0.2.68

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.
Files changed (3) hide show
  1. package/dist/bundle.d.ts +428 -367
  2. package/dist/bundle.js +306 -155
  3. package/package.json +16 -16
package/dist/bundle.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- niconicomments.js v0.2.66
2
+ niconicomments.js v0.2.68
3
3
  (c) 2021 xpadev-net https://xpadev.net
4
4
  Released under the MIT License.
5
5
  */
@@ -254,6 +254,20 @@
254
254
  }
255
255
  return e;
256
256
  }
257
+ function _toPrimitive(t, r) {
258
+ if ("object" != typeof t || !t) return t;
259
+ var e = t[Symbol.toPrimitive];
260
+ if (void 0 !== e) {
261
+ var i = e.call(t, r || "default");
262
+ if ("object" != typeof i) return i;
263
+ throw new TypeError("@@toPrimitive must return a primitive value.");
264
+ }
265
+ return ("string" === r ? String : Number)(t);
266
+ }
267
+ function _toPropertyKey(t) {
268
+ var i = _toPrimitive(t, "string");
269
+ return "symbol" == typeof i ? i : String(i);
270
+ }
257
271
  function _typeof(o) {
258
272
  "@babel/helpers - typeof";
259
273
 
@@ -488,20 +502,6 @@
488
502
  }
489
503
  };
490
504
  }
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
505
 
506
506
  // src/error/ValiError/ValiError.ts
507
507
  var ValiError = /*#__PURE__*/function (_Error) {
@@ -647,7 +647,7 @@
647
647
  }
648
648
  return parseResult(true, output, issues);
649
649
  }
650
- function schemaIssue(info, reason, validation, message, input, issues) {
650
+ function schemaIssue(info, reason, validation, message, input, path, issues) {
651
651
  return {
652
652
  typed: false,
653
653
  output: input,
@@ -657,6 +657,7 @@
657
657
  origin: (info === null || info === void 0 ? void 0 : info.origin) || "value",
658
658
  message: errorMessage(message),
659
659
  input: input,
660
+ path: path,
660
661
  issues: issues,
661
662
  abortEarly: info === null || info === void 0 ? void 0 : info.abortEarly,
662
663
  abortPipeEarly: info === null || info === void 0 ? void 0 : info.abortPipeEarly,
@@ -766,6 +767,28 @@
766
767
  };
767
768
  }
768
769
 
770
+ // src/schemas/instance/instance.ts
771
+ function instance(class_, arg2, arg3) {
772
+ var _defaultArgs25 = defaultArgs(arg2, arg3),
773
+ _defaultArgs26 = _slicedToArray(_defaultArgs25, 2),
774
+ _defaultArgs26$ = _defaultArgs26[0],
775
+ message = _defaultArgs26$ === void 0 ? "Invalid type" : _defaultArgs26$,
776
+ pipe = _defaultArgs26[1];
777
+ return {
778
+ type: "instance",
779
+ async: false,
780
+ "class": class_,
781
+ message: message,
782
+ pipe: pipe,
783
+ _parse: function _parse(input, info) {
784
+ if (!(input instanceof this["class"])) {
785
+ return schemaIssue(info, "type", "instance", this.message, input);
786
+ }
787
+ return pipeResult(input, this.pipe, info, "instance");
788
+ }
789
+ };
790
+ }
791
+
769
792
  // src/schemas/intersect/utils/mergeOutputs/mergeOutputs.ts
770
793
  function mergeOutputs(output1, output2) {
771
794
  if (_typeof(output1) === _typeof(output2)) {
@@ -814,13 +837,18 @@
814
837
  }
815
838
 
816
839
  // src/schemas/intersect/intersect.ts
817
- function intersect(options) {
818
- var message = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "Invalid type";
840
+ function intersect(options, arg2, arg3) {
841
+ var _defaultArgs29 = defaultArgs(arg2, arg3),
842
+ _defaultArgs30 = _slicedToArray(_defaultArgs29, 2),
843
+ _defaultArgs30$ = _defaultArgs30[0],
844
+ message = _defaultArgs30$ === void 0 ? "Invalid type" : _defaultArgs30$,
845
+ pipe = _defaultArgs30[1];
819
846
  return {
820
847
  type: "intersect",
821
848
  async: false,
822
849
  options: options,
823
850
  message: message,
851
+ pipe: pipe,
824
852
  _parse: function _parse(input, info) {
825
853
  var typed = true;
826
854
  var issues;
@@ -873,7 +901,7 @@
873
901
  }
874
902
  output = result.output;
875
903
  }
876
- return parseResult(true, output, issues);
904
+ return pipeResult(output, this.pipe, info, "intersect", issues);
877
905
  }
878
906
  return parseResult(false, output, issues);
879
907
  }
@@ -919,11 +947,11 @@
919
947
 
920
948
  // src/schemas/number/number.ts
921
949
  function number(arg1, arg2) {
922
- var _defaultArgs33 = defaultArgs(arg1, arg2),
923
- _defaultArgs34 = _slicedToArray(_defaultArgs33, 2),
924
- _defaultArgs34$ = _defaultArgs34[0],
925
- message = _defaultArgs34$ === void 0 ? "Invalid type" : _defaultArgs34$,
926
- pipe = _defaultArgs34[1];
950
+ var _defaultArgs35 = defaultArgs(arg1, arg2),
951
+ _defaultArgs36 = _slicedToArray(_defaultArgs35, 2),
952
+ _defaultArgs36$ = _defaultArgs36[0],
953
+ message = _defaultArgs36$ === void 0 ? "Invalid type" : _defaultArgs36$,
954
+ pipe = _defaultArgs36[1];
927
955
  return {
928
956
  type: "number",
929
957
  async: false,
@@ -1091,11 +1119,11 @@
1091
1119
 
1092
1120
  // src/schemas/string/string.ts
1093
1121
  function string(arg1, arg2) {
1094
- var _defaultArgs37 = defaultArgs(arg1, arg2),
1095
- _defaultArgs38 = _slicedToArray(_defaultArgs37, 2),
1096
- _defaultArgs38$ = _defaultArgs38[0],
1097
- message = _defaultArgs38$ === void 0 ? "Invalid type" : _defaultArgs38$,
1098
- pipe = _defaultArgs38[1];
1122
+ var _defaultArgs39 = defaultArgs(arg1, arg2),
1123
+ _defaultArgs40 = _slicedToArray(_defaultArgs39, 2),
1124
+ _defaultArgs40$ = _defaultArgs40[0],
1125
+ message = _defaultArgs40$ === void 0 ? "Invalid type" : _defaultArgs40$,
1126
+ pipe = _defaultArgs40[1];
1099
1127
  return {
1100
1128
  type: "string",
1101
1129
  async: false,
@@ -1113,16 +1141,16 @@
1113
1141
  // src/schemas/record/utils/recordArgs/recordArgs.ts
1114
1142
  function recordArgs(arg1, arg2, arg3, arg4) {
1115
1143
  if (_typeof(arg2) === "object" && !Array.isArray(arg2)) {
1116
- var _defaultArgs41 = defaultArgs(arg3, arg4),
1117
- _defaultArgs42 = _slicedToArray(_defaultArgs41, 2),
1118
- message2 = _defaultArgs42[0],
1119
- pipe2 = _defaultArgs42[1];
1144
+ var _defaultArgs43 = defaultArgs(arg3, arg4),
1145
+ _defaultArgs44 = _slicedToArray(_defaultArgs43, 2),
1146
+ message2 = _defaultArgs44[0],
1147
+ pipe2 = _defaultArgs44[1];
1120
1148
  return [arg1, arg2, message2, pipe2];
1121
1149
  }
1122
- var _defaultArgs43 = defaultArgs(arg2, arg3),
1123
- _defaultArgs44 = _slicedToArray(_defaultArgs43, 2),
1124
- message = _defaultArgs44[0],
1125
- pipe = _defaultArgs44[1];
1150
+ var _defaultArgs45 = defaultArgs(arg2, arg3),
1151
+ _defaultArgs46 = _slicedToArray(_defaultArgs45, 2),
1152
+ message = _defaultArgs46[0],
1153
+ pipe = _defaultArgs46[1];
1126
1154
  return [string(), arg1, message, pipe];
1127
1155
  }
1128
1156
 
@@ -1244,13 +1272,18 @@
1244
1272
  }
1245
1273
 
1246
1274
  // src/schemas/union/union.ts
1247
- function union(options) {
1248
- var message = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "Invalid type";
1275
+ function union(options, arg2, arg3) {
1276
+ var _defaultArgs55 = defaultArgs(arg2, arg3),
1277
+ _defaultArgs56 = _slicedToArray(_defaultArgs55, 2),
1278
+ _defaultArgs56$ = _defaultArgs56[0],
1279
+ message = _defaultArgs56$ === void 0 ? "Invalid type" : _defaultArgs56$,
1280
+ pipe = _defaultArgs56[1];
1249
1281
  return {
1250
1282
  type: "union",
1251
1283
  async: false,
1252
1284
  options: options,
1253
1285
  message: message,
1286
+ pipe: pipe,
1254
1287
  _parse: function _parse(input, info) {
1255
1288
  var issues;
1256
1289
  var output;
@@ -1288,9 +1321,9 @@
1288
1321
  _iterator28.f();
1289
1322
  }
1290
1323
  if (output) {
1291
- return parseResult(true, output[0]);
1324
+ return pipeResult(output[0], this.pipe, info, "union");
1292
1325
  }
1293
- return schemaIssue(info, "type", "union", this.message, input, issues);
1326
+ return schemaIssue(info, "type", "union", this.message, input, void 0, issues);
1294
1327
  }
1295
1328
  };
1296
1329
  }
@@ -1476,6 +1509,19 @@
1476
1509
  comments: array(ZV1Comment),
1477
1510
  });
1478
1511
 
1512
+ const ZInputFormatType = union([
1513
+ literal("XMLDocument"),
1514
+ literal("niconicome"),
1515
+ literal("xml2js"),
1516
+ literal("formatted"),
1517
+ literal("legacy"),
1518
+ literal("legacyOwner"),
1519
+ literal("owner"),
1520
+ literal("v1"),
1521
+ literal("empty"),
1522
+ literal("default"),
1523
+ ]);
1524
+
1479
1525
  const ZCommentFont = union([
1480
1526
  literal("defont"),
1481
1527
  literal("mincho"),
@@ -1483,6 +1529,11 @@
1483
1529
  literal("gulim"),
1484
1530
  literal("simsun"),
1485
1531
  ]);
1532
+ union([
1533
+ literal("defont"),
1534
+ literal("mincho"),
1535
+ literal("gothic"),
1536
+ ]);
1486
1537
  const ZCommentFlashFont = union([
1487
1538
  literal("defont"),
1488
1539
  literal("gulim"),
@@ -1528,6 +1579,26 @@
1528
1579
  literal("naka"),
1529
1580
  literal("shita"),
1530
1581
  ]);
1582
+ const ZNicoScriptReverseTarget = union([
1583
+ literal("\u30b3\u30e1"),
1584
+ literal("\u6295\u30b3\u30e1"),
1585
+ literal("\u5168"),
1586
+ ]);
1587
+ const ZNicoScriptReplaceRange = union([
1588
+ literal("\u5358"),
1589
+ literal("\u5168"),
1590
+ ]);
1591
+ const ZNicoScriptReplaceTarget = union([
1592
+ literal("\u30b3\u30e1"),
1593
+ literal("\u6295\u30b3\u30e1"),
1594
+ literal("\u5168"),
1595
+ literal("\u542b\u307e\u306a\u3044"),
1596
+ literal("\u542b\u3080"),
1597
+ ]);
1598
+ const ZNicoScriptReplaceCondition = union([
1599
+ literal("\u90e8\u5206\u4e00\u81f4"),
1600
+ literal("\u5b8c\u5168\u4e00\u81f4"),
1601
+ ]);
1531
1602
  const ZMeasureInput = object({
1532
1603
  font: ZCommentFont,
1533
1604
  content: array(ZCommentContentItem),
@@ -1628,16 +1699,12 @@
1628
1699
  },
1629
1700
  nicoScript: {
1630
1701
  range: {
1631
- target: (i) => is(string([regex(/^(?:\u6295?\u30b3\u30e1|\u5168)$/)]), i),
1702
+ target: (i) => is(ZNicoScriptReverseTarget, i),
1632
1703
  },
1633
1704
  replace: {
1634
- range: (i) => is(string([regex(/^[\u5358\u5168]$/)]), i),
1635
- target: (i) => is(string([
1636
- regex(/^(?:\u30b3\u30e1|\u6295\u30b3\u30e1|\u5168|\u542b\u3080|\u542b\u307e\u306a\u3044)$/),
1637
- ]), i),
1638
- condition: (i) => is(string([
1639
- regex(/^(?:\u90e8\u5206\u4e00\u81f4|\u5b8c\u5168\u4e00\u81f4)$/),
1640
- ]), i),
1705
+ range: (i) => is(ZNicoScriptReplaceRange, i),
1706
+ target: (i) => is(ZNicoScriptReplaceTarget, i),
1707
+ condition: (i) => is(ZNicoScriptReplaceCondition, i),
1641
1708
  },
1642
1709
  },
1643
1710
  comment: {
@@ -1674,9 +1741,8 @@
1674
1741
  keepCA: isBoolean,
1675
1742
  scale: isNumber,
1676
1743
  config: isObject,
1677
- format: (i) => typeof i === "string" &&
1678
- !!RegExp(/^(XMLDocument|niconicome|formatted|legacy|legacyOwner|owner|v1|default|empty)$/).exec(i),
1679
- video: (i) => typeof i === "object" && i.nodeName === "VIDEO",
1744
+ format: (i) => is(ZInputFormatType, i),
1745
+ video: (i) => is(optional(instance(HTMLVideoElement)), i),
1680
1746
  };
1681
1747
  for (const key of Object.keys(keys)) {
1682
1748
  if (item[key] !== undefined &&
@@ -4086,87 +4152,25 @@
4086
4152
  triggerHandler: triggerHandler
4087
4153
  });
4088
4154
 
4089
- const convert2formattedComment = (data, type) => {
4090
- let result = [];
4091
- try {
4092
- result = parseComments(data, type);
4093
- }
4094
- catch (e) {
4095
- if (e instanceof ValiError) {
4096
- console.error("", e.issues);
4097
- }
4098
- }
4099
- return sort(result);
4100
- };
4101
- const parseComments = (data, type) => {
4102
- if (type === "empty" && data === undefined) {
4155
+ const EmptyParser = {
4156
+ key: ["empty"],
4157
+ parse: () => {
4103
4158
  return [];
4104
- }
4105
- else if ((type === "XMLDocument" || type === "niconicome") &&
4106
- typeGuard.xmlDocument(data)) {
4107
- return fromXMLDocument(data);
4108
- }
4109
- else if (type === "formatted") {
4110
- return fromFormatted(parse(array(ZFormattedComment), data));
4111
- }
4112
- else if (type === "legacy") {
4113
- return fromLegacy(parse(array(ZRawApiResponse), data));
4114
- }
4115
- else if (type === "legacyOwner") {
4116
- if (!typeGuard.legacyOwner.comments(data))
4117
- throw new InvalidFormatError();
4118
- return fromLegacyOwner(data);
4119
- }
4120
- else if (type === "owner") {
4121
- return fromOwner(parse(array(ZOwnerComment), data));
4122
- }
4123
- else if (type === "v1") {
4124
- return fromV1(parse(array(ZV1Thread), data));
4125
- }
4126
- else {
4127
- throw new InvalidFormatError();
4128
- }
4159
+ },
4129
4160
  };
4130
- const fromXMLDocument = (data) => {
4131
- const data_ = [], userList = [];
4132
- let index = Array.from(data.documentElement.children).length;
4133
- for (const item of Array.from(data.documentElement.children)) {
4134
- if (item.nodeName !== "chat")
4135
- continue;
4136
- const tmpParam = {
4137
- id: Number(item.getAttribute("no")) || index++,
4138
- vpos: Number(item.getAttribute("vpos")),
4139
- content: item.innerHTML,
4140
- date: Number(item.getAttribute("date")) || 0,
4141
- date_usec: Number(item.getAttribute("date_usec")) || 0,
4142
- owner: !item.getAttribute("user_id"),
4143
- premium: item.getAttribute("premium") === "1",
4144
- mail: [],
4145
- user_id: -1,
4146
- layer: -1,
4147
- is_my_post: false,
4148
- };
4149
- if (item.getAttribute("mail")) {
4150
- tmpParam.mail = item.getAttribute("mail")?.split(/\s+/g) ?? [];
4151
- }
4152
- if (tmpParam.content.startsWith("/") && tmpParam.owner) {
4153
- tmpParam.mail.push("invisible");
4154
- }
4155
- const userId = item.getAttribute("user_id") ?? "";
4156
- const isUserExist = userList.indexOf(userId);
4157
- if (isUserExist === -1) {
4158
- tmpParam.user_id = userList.length;
4159
- userList.push(userId);
4160
- }
4161
- else {
4162
- tmpParam.user_id = isUserExist;
4163
- }
4164
- data_.push(tmpParam);
4165
- }
4166
- return data_;
4161
+
4162
+ const FormattedParser = {
4163
+ key: ["formatted", "niconicome"],
4164
+ parse: (input) => {
4165
+ return parse(array(ZFormattedComment), input);
4166
+ },
4167
4167
  };
4168
- const fromFormatted = (data) => {
4169
- return data;
4168
+
4169
+ const LegacyParser = {
4170
+ key: ["legacy"],
4171
+ parse: (input) => {
4172
+ return fromLegacy(parse(array(ZRawApiResponse), input));
4173
+ },
4170
4174
  };
4171
4175
  const fromLegacy = (data) => {
4172
4176
  const data_ = [], userList = [];
@@ -4208,6 +4212,15 @@
4208
4212
  }
4209
4213
  return data_;
4210
4214
  };
4215
+
4216
+ const LegacyOwnerParser = {
4217
+ key: ["legacyOwner"],
4218
+ parse: (input) => {
4219
+ if (!typeGuard.legacyOwner.comments(input))
4220
+ throw new InvalidFormatError();
4221
+ return fromLegacyOwner(input);
4222
+ },
4223
+ };
4211
4224
  const fromLegacyOwner = (data) => {
4212
4225
  const data_ = [], comments = data.split("\n");
4213
4226
  for (let i = 0, n = comments.length; i < n; i++) {
@@ -4246,6 +4259,13 @@
4246
4259
  }
4247
4260
  return data_;
4248
4261
  };
4262
+
4263
+ const OwnerParser = {
4264
+ key: ["owner"],
4265
+ parse: (input) => {
4266
+ return fromOwner(parse(array(ZOwnerComment), input));
4267
+ },
4268
+ };
4249
4269
  const fromOwner = (data) => {
4250
4270
  const data_ = [];
4251
4271
  for (let i = 0, n = data.length; i < n; i++) {
@@ -4275,6 +4295,35 @@
4275
4295
  }
4276
4296
  return data_;
4277
4297
  };
4298
+ const time2vpos = (input) => {
4299
+ const time = RegExp(/^(?:(\d+):(\d+)\.(\d+)|(\d+):(\d+)|(\d+)\.(\d+)|(\d+))$/).exec(input);
4300
+ if (time) {
4301
+ if (time[1] !== undefined &&
4302
+ time[2] !== undefined &&
4303
+ time[3] !== undefined) {
4304
+ return ((Number(time[1]) * 60 + Number(time[2])) * 100 +
4305
+ Number(time[3]) / Math.pow(10, time[3].length - 2));
4306
+ }
4307
+ else if (time[4] !== undefined && time[5] !== undefined) {
4308
+ return (Number(time[4]) * 60 + Number(time[5])) * 100;
4309
+ }
4310
+ else if (time[6] !== undefined && time[7] !== undefined) {
4311
+ return (Number(time[6]) * 100 +
4312
+ Number(time[7]) / Math.pow(10, time[7].length - 2));
4313
+ }
4314
+ else if (time[8] !== undefined) {
4315
+ return Number(time[8]) * 100;
4316
+ }
4317
+ }
4318
+ return 0;
4319
+ };
4320
+
4321
+ const V1Parser = {
4322
+ key: ["v1"],
4323
+ parse: (input) => {
4324
+ return fromV1(parse(array(ZV1Thread), input));
4325
+ },
4326
+ };
4278
4327
  const fromV1 = (data) => {
4279
4328
  const data_ = [], userList = [];
4280
4329
  for (const item of data) {
@@ -4309,6 +4358,132 @@
4309
4358
  }
4310
4359
  return data_;
4311
4360
  };
4361
+ const date2time = (date) => Math.floor(Date.parse(date) / 1000);
4362
+
4363
+ const ZXml2jsChatItem = object({
4364
+ _: string(),
4365
+ $: object({
4366
+ no: optional(string()),
4367
+ vpos: string(),
4368
+ date: optional(string(), "0"),
4369
+ date_usec: optional(string(), "0"),
4370
+ user_id: optional(string()),
4371
+ owner: optional(string(), ""),
4372
+ premium: optional(string(), ""),
4373
+ mail: optional(string(), ""),
4374
+ }),
4375
+ });
4376
+ const ZXml2jsChat = object({
4377
+ chat: array(ZXml2jsChatItem),
4378
+ });
4379
+ const ZXml2jsPacket = object({
4380
+ packet: ZXml2jsChat,
4381
+ });
4382
+
4383
+ const Xml2jsParser = {
4384
+ key: ["xml2js"],
4385
+ parse: (input) => {
4386
+ return fromXml2js(parse(ZXml2jsPacket, input));
4387
+ },
4388
+ };
4389
+ const fromXml2js = (data) => {
4390
+ const data_ = [], userList = [];
4391
+ let index = data.packet.chat.length;
4392
+ for (const item of data.packet.chat) {
4393
+ const tmpParam = {
4394
+ id: Number(item.$.no) || index++,
4395
+ vpos: Number(item.$.vpos),
4396
+ content: item._,
4397
+ date: Number(item.$.date),
4398
+ date_usec: Number(item.$.date_usec),
4399
+ owner: !(item.$.owner === "0" || item.$.user_id),
4400
+ premium: item.$.premium === "1",
4401
+ mail: item.$.mail.split(/\s+/g),
4402
+ user_id: -1,
4403
+ layer: -1,
4404
+ is_my_post: false,
4405
+ };
4406
+ if (tmpParam.content.startsWith("/") && tmpParam.owner) {
4407
+ tmpParam.mail.push("invisible");
4408
+ }
4409
+ const userId = item.$.user_id ?? "";
4410
+ const isUserExist = userList.indexOf(userId);
4411
+ if (isUserExist === -1) {
4412
+ tmpParam.user_id = userList.length;
4413
+ userList.push(userId);
4414
+ }
4415
+ else {
4416
+ tmpParam.user_id = isUserExist;
4417
+ }
4418
+ data_.push(tmpParam);
4419
+ }
4420
+ return data_;
4421
+ };
4422
+
4423
+ const XmlDocumentParser = {
4424
+ key: ["formatted", "niconicome"],
4425
+ parse: (input) => {
4426
+ if (!typeGuard.xmlDocument(input))
4427
+ throw new InvalidFormatError();
4428
+ return parseXMLDocument(input);
4429
+ },
4430
+ };
4431
+ const parseXMLDocument = (data) => {
4432
+ const data_ = [], userList = [];
4433
+ let index = Array.from(data.documentElement.children).length;
4434
+ for (const item of Array.from(data.documentElement.children)) {
4435
+ if (item.nodeName !== "chat")
4436
+ continue;
4437
+ const tmpParam = {
4438
+ id: Number(item.getAttribute("no")) || index++,
4439
+ vpos: Number(item.getAttribute("vpos")),
4440
+ content: item.textContent ?? "",
4441
+ date: Number(item.getAttribute("date")) || 0,
4442
+ date_usec: Number(item.getAttribute("date_usec")) || 0,
4443
+ owner: !item.getAttribute("user_id"),
4444
+ premium: item.getAttribute("premium") === "1",
4445
+ mail: [],
4446
+ user_id: -1,
4447
+ layer: -1,
4448
+ is_my_post: false,
4449
+ };
4450
+ if (item.getAttribute("mail")) {
4451
+ tmpParam.mail = item.getAttribute("mail")?.split(/\s+/g) ?? [];
4452
+ }
4453
+ if (tmpParam.content.startsWith("/") && tmpParam.owner) {
4454
+ tmpParam.mail.push("invisible");
4455
+ }
4456
+ const userId = item.getAttribute("user_id") ?? "";
4457
+ const isUserExist = userList.indexOf(userId);
4458
+ if (isUserExist === -1) {
4459
+ tmpParam.user_id = userList.length;
4460
+ userList.push(userId);
4461
+ }
4462
+ else {
4463
+ tmpParam.user_id = isUserExist;
4464
+ }
4465
+ data_.push(tmpParam);
4466
+ }
4467
+ return data_;
4468
+ };
4469
+
4470
+ const parsers = [
4471
+ EmptyParser,
4472
+ FormattedParser,
4473
+ LegacyParser,
4474
+ LegacyOwnerParser,
4475
+ OwnerParser,
4476
+ V1Parser,
4477
+ Xml2jsParser,
4478
+ XmlDocumentParser,
4479
+ ];
4480
+
4481
+ const convert2formattedComment = (data, type) => {
4482
+ const parser = parsers.find((parser) => parser.key.includes(type));
4483
+ if (!parser)
4484
+ throw new InvalidFormatError();
4485
+ return sort(parser.parse(data));
4486
+ };
4312
4487
  const sort = (data) => {
4313
4488
  data.sort((a, b) => {
4314
4489
  if (a.vpos < b.vpos)
@@ -4327,29 +4502,6 @@
4327
4502
  });
4328
4503
  return data;
4329
4504
  };
4330
- const time2vpos = (input) => {
4331
- const time = RegExp(/^(?:(\d+):(\d+)\.(\d+)|(\d+):(\d+)|(\d+)\.(\d+)|(\d+))$/).exec(input);
4332
- if (time) {
4333
- if (time[1] !== undefined &&
4334
- time[2] !== undefined &&
4335
- time[3] !== undefined) {
4336
- return ((Number(time[1]) * 60 + Number(time[2])) * 100 +
4337
- Number(time[3]) / Math.pow(10, time[3].length - 2));
4338
- }
4339
- else if (time[4] !== undefined && time[5] !== undefined) {
4340
- return (Number(time[4]) * 60 + Number(time[5])) * 100;
4341
- }
4342
- else if (time[6] !== undefined && time[7] !== undefined) {
4343
- return (Number(time[6]) * 100 +
4344
- Number(time[7]) / Math.pow(10, time[7].length - 2));
4345
- }
4346
- else if (time[8] !== undefined) {
4347
- return Number(time[8]) * 100;
4348
- }
4349
- }
4350
- return 0;
4351
- };
4352
- const date2time = (date) => Math.floor(new Date(date).getTime() / 1000);
4353
4505
 
4354
4506
  var inputParser = /*#__PURE__*/Object.freeze({
4355
4507
  __proto__: null,
@@ -4673,8 +4825,7 @@
4673
4825
  if (arrayEqual(current, last))
4674
4826
  return false;
4675
4827
  }
4676
- const size = this.renderer.getSize();
4677
- this.renderer.clearRect(0, 0, size.width, size.height);
4828
+ this.renderer.clearRect(0, 0, config.canvasWidth, config.canvasHeight);
4678
4829
  this.lastVpos = vpos;
4679
4830
  this._drawVideo();
4680
4831
  for (const plugin of plugins) {