@xpadev-net/niconicomments 0.2.49 → 0.2.51
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/LICENSE +21 -21
- package/README.en.md +53 -43
- package/README.md +53 -43
- package/dist/bundle.d.ts +1101 -754
- package/dist/bundle.js +1070 -1133
- package/package.json +24 -20
package/dist/bundle.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
niconicomments.js v0.2.
|
|
2
|
+
niconicomments.js v0.2.51
|
|
3
3
|
(c) 2021 xpadev-net https://xpadev.net
|
|
4
4
|
Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -9,66 +9,12 @@
|
|
|
9
9
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.NiconiComments = factory());
|
|
10
10
|
})(this, (function () { 'use strict';
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
16
|
-
purpose with or without fee is hereby granted.
|
|
17
|
-
|
|
18
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
19
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
20
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
21
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
22
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
23
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
24
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
25
|
-
***************************************************************************** */
|
|
26
|
-
/* global Reflect, Promise */
|
|
27
|
-
|
|
28
|
-
var _extendStatics = function extendStatics(d, b) {
|
|
29
|
-
_extendStatics = Object.setPrototypeOf || {
|
|
30
|
-
__proto__: []
|
|
31
|
-
} instanceof Array && function (d, b) {
|
|
32
|
-
d.__proto__ = b;
|
|
33
|
-
} || function (d, b) {
|
|
34
|
-
for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
|
|
35
|
-
};
|
|
36
|
-
return _extendStatics(d, b);
|
|
37
|
-
};
|
|
38
|
-
function __extends(d, b) {
|
|
39
|
-
if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
40
|
-
_extendStatics(d, b);
|
|
41
|
-
function __() {
|
|
42
|
-
this.constructor = d;
|
|
43
|
-
}
|
|
44
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
45
|
-
}
|
|
46
|
-
var _assign = function __assign() {
|
|
47
|
-
_assign = Object.assign || function __assign(t) {
|
|
48
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
49
|
-
s = arguments[i];
|
|
50
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
51
|
-
}
|
|
52
|
-
return t;
|
|
53
|
-
};
|
|
54
|
-
return _assign.apply(this, arguments);
|
|
55
|
-
};
|
|
56
|
-
function __spreadArray(to, from, pack) {
|
|
57
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
58
|
-
if (ar || !(i in from)) {
|
|
59
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
60
|
-
ar[i] = from[i];
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
var imageCache = {};
|
|
67
|
-
var resetImageCache = function () {
|
|
12
|
+
let imageCache = {};
|
|
13
|
+
const resetImageCache = () => {
|
|
68
14
|
imageCache = {};
|
|
69
15
|
};
|
|
70
16
|
|
|
71
|
-
|
|
17
|
+
let nicoScripts = {
|
|
72
18
|
reverse: [],
|
|
73
19
|
default: [],
|
|
74
20
|
replace: [],
|
|
@@ -76,7 +22,7 @@
|
|
|
76
22
|
seekDisable: [],
|
|
77
23
|
jump: [],
|
|
78
24
|
};
|
|
79
|
-
|
|
25
|
+
const resetNicoScripts = () => {
|
|
80
26
|
nicoScripts = {
|
|
81
27
|
reverse: [],
|
|
82
28
|
default: [],
|
|
@@ -87,8 +33,8 @@
|
|
|
87
33
|
};
|
|
88
34
|
};
|
|
89
35
|
|
|
90
|
-
|
|
91
|
-
|
|
36
|
+
let plugins = [];
|
|
37
|
+
const setPlugins = (input) => {
|
|
92
38
|
plugins = input;
|
|
93
39
|
};
|
|
94
40
|
|
|
@@ -102,11 +48,11 @@
|
|
|
102
48
|
setPlugins: setPlugins
|
|
103
49
|
});
|
|
104
50
|
|
|
105
|
-
|
|
106
|
-
|
|
51
|
+
let defaultConfig;
|
|
52
|
+
const updateConfig = (config) => {
|
|
107
53
|
defaultConfig = config;
|
|
108
54
|
};
|
|
109
|
-
|
|
55
|
+
const defaultOptions = {
|
|
110
56
|
config: {},
|
|
111
57
|
debug: false,
|
|
112
58
|
enableLegacyPiP: false,
|
|
@@ -121,10 +67,14 @@
|
|
|
121
67
|
useLegacy: false,
|
|
122
68
|
video: undefined,
|
|
123
69
|
};
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
70
|
+
let config;
|
|
71
|
+
let options;
|
|
72
|
+
const setConfig = (value) => {
|
|
73
|
+
config = value;
|
|
74
|
+
};
|
|
75
|
+
const setOptions = (value) => {
|
|
76
|
+
options = value;
|
|
77
|
+
};
|
|
128
78
|
|
|
129
79
|
var config$1 = /*#__PURE__*/Object.freeze({
|
|
130
80
|
__proto__: null,
|
|
@@ -137,47 +87,36 @@
|
|
|
137
87
|
updateConfig: updateConfig
|
|
138
88
|
});
|
|
139
89
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
return CanvasRenderingContext2DError;
|
|
147
|
-
}(Error));
|
|
90
|
+
class CanvasRenderingContext2DError extends Error {
|
|
91
|
+
constructor(options = {}) {
|
|
92
|
+
super("CanvasRenderingContext2DError", options);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
148
95
|
CanvasRenderingContext2DError.prototype.name = "CanvasRenderingContext2DError";
|
|
149
96
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
return InvalidFormatError;
|
|
157
|
-
}(Error));
|
|
97
|
+
class InvalidFormatError extends Error {
|
|
98
|
+
constructor(options = {}) {
|
|
99
|
+
super("InvalidFormatError", options);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
158
102
|
InvalidFormatError.prototype.name = "InvalidFormatError";
|
|
159
103
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
166
|
-
return InvalidOptionError;
|
|
167
|
-
}(Error));
|
|
104
|
+
class InvalidOptionError extends Error {
|
|
105
|
+
constructor(options = {}) {
|
|
106
|
+
super("Invalid option\nPlease check document: https://xpadev-net.github.io/niconicomments/#p_options", options);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
168
109
|
InvalidOptionError.prototype.name = "InvalidOptionError";
|
|
169
110
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
return NotImplementedError;
|
|
180
|
-
}(Error));
|
|
111
|
+
class NotImplementedError extends Error {
|
|
112
|
+
pluginName;
|
|
113
|
+
methodName;
|
|
114
|
+
constructor(pluginName, methodName, options = {}) {
|
|
115
|
+
super("NotImplementedError", options);
|
|
116
|
+
this.pluginName = pluginName;
|
|
117
|
+
this.methodName = methodName;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
181
120
|
NotImplementedError.prototype.name = "NotImplementedError";
|
|
182
121
|
|
|
183
122
|
var index$2 = /*#__PURE__*/Object.freeze({
|
|
@@ -188,27 +127,26 @@
|
|
|
188
127
|
NotImplementedError: NotImplementedError
|
|
189
128
|
});
|
|
190
129
|
|
|
191
|
-
|
|
192
|
-
var _a;
|
|
130
|
+
const ArrayPush = (array, key, push) => {
|
|
193
131
|
if (!array) {
|
|
194
132
|
array = {};
|
|
195
133
|
}
|
|
196
134
|
if (!array[Number(key)]) {
|
|
197
135
|
array[Number(key)] = [];
|
|
198
136
|
}
|
|
199
|
-
|
|
137
|
+
array[Number(key)]?.push(push);
|
|
200
138
|
};
|
|
201
|
-
|
|
139
|
+
const ArrayEqual = (a, b) => {
|
|
202
140
|
if (a.length !== b.length)
|
|
203
141
|
return false;
|
|
204
|
-
for (
|
|
142
|
+
for (let i = 0, n = a.length; i < n; ++i) {
|
|
205
143
|
if (a[i] !== b[i])
|
|
206
144
|
return false;
|
|
207
145
|
}
|
|
208
146
|
return true;
|
|
209
147
|
};
|
|
210
148
|
|
|
211
|
-
|
|
149
|
+
const hex2rgb = (hex) => {
|
|
212
150
|
if (hex.slice(0, 1) === "#")
|
|
213
151
|
hex = hex.slice(1);
|
|
214
152
|
if (hex.length === 3)
|
|
@@ -223,7 +161,7 @@
|
|
|
223
161
|
return parseInt(str, 16);
|
|
224
162
|
});
|
|
225
163
|
};
|
|
226
|
-
|
|
164
|
+
const hex2rgba = (hex) => {
|
|
227
165
|
if (hex.slice(0, 1) === "#")
|
|
228
166
|
hex = hex.slice(1);
|
|
229
167
|
if (hex.length === 4)
|
|
@@ -241,28 +179,28 @@
|
|
|
241
179
|
hex.slice(2, 4),
|
|
242
180
|
hex.slice(4, 6),
|
|
243
181
|
hex.slice(4, 6),
|
|
244
|
-
].map(
|
|
182
|
+
].map((str, index) => {
|
|
245
183
|
if (index === 3)
|
|
246
184
|
return parseInt(str, 16) / 256;
|
|
247
185
|
return parseInt(str, 16);
|
|
248
186
|
});
|
|
249
187
|
};
|
|
250
|
-
|
|
188
|
+
const getStrokeColor = (comment) => {
|
|
251
189
|
if (comment.strokeColor) {
|
|
252
|
-
|
|
253
|
-
if (
|
|
254
|
-
return
|
|
190
|
+
const length = comment.strokeColor.length;
|
|
191
|
+
if (length === 3 || length === 6) {
|
|
192
|
+
return `rgba(${hex2rgb(comment.strokeColor).join(",")},${config.contextStrokeOpacity})`;
|
|
255
193
|
}
|
|
256
|
-
else if (
|
|
257
|
-
return
|
|
194
|
+
else if (length === 4 || length === 8) {
|
|
195
|
+
return `rgba(${hex2rgba(comment.strokeColor).join(",")})`;
|
|
258
196
|
}
|
|
259
197
|
}
|
|
260
|
-
return
|
|
261
|
-
|
|
262
|
-
|
|
198
|
+
return `rgba(${hex2rgb(comment.color === "#000000"
|
|
199
|
+
? config.contextStrokeInversionColor
|
|
200
|
+
: config.contextStrokeColor).join(",")},${config.contextStrokeOpacity})`;
|
|
263
201
|
};
|
|
264
202
|
|
|
265
|
-
|
|
203
|
+
const colors = {
|
|
266
204
|
white: "#FFFFFF",
|
|
267
205
|
red: "#FF0000",
|
|
268
206
|
pink: "#FF8080",
|
|
@@ -297,51 +235,47 @@
|
|
|
297
235
|
colors: colors
|
|
298
236
|
});
|
|
299
237
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
238
|
+
const isNode = typeof process === "object" && typeof require === "function";
|
|
239
|
+
|
|
240
|
+
const isBoolean = (i) => typeof i === "boolean";
|
|
241
|
+
const isNumber = (i) => typeof i === "number";
|
|
242
|
+
const isObject = (i) => typeof i === "object";
|
|
243
|
+
const typeGuard = {
|
|
304
244
|
formatted: {
|
|
305
|
-
comment:
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
},
|
|
319
|
-
comments: function (i) {
|
|
245
|
+
comment: (i) => objectVerify(i, [
|
|
246
|
+
"id",
|
|
247
|
+
"vpos",
|
|
248
|
+
"content",
|
|
249
|
+
"date",
|
|
250
|
+
"date_usec",
|
|
251
|
+
"owner",
|
|
252
|
+
"premium",
|
|
253
|
+
"mail",
|
|
254
|
+
"user_id",
|
|
255
|
+
"layer",
|
|
256
|
+
]),
|
|
257
|
+
comments: (i) => {
|
|
320
258
|
if (typeof i !== "object")
|
|
321
259
|
return false;
|
|
322
|
-
for (
|
|
323
|
-
var item = _a[_i];
|
|
260
|
+
for (const item of i) {
|
|
324
261
|
if (!typeGuard.formatted.comment(item))
|
|
325
262
|
return false;
|
|
326
263
|
}
|
|
327
264
|
return true;
|
|
328
265
|
},
|
|
329
|
-
legacyComment:
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
},
|
|
340
|
-
legacyComments: function (i) {
|
|
266
|
+
legacyComment: (i) => objectVerify(i, [
|
|
267
|
+
"id",
|
|
268
|
+
"vpos",
|
|
269
|
+
"content",
|
|
270
|
+
"date",
|
|
271
|
+
"owner",
|
|
272
|
+
"premium",
|
|
273
|
+
"mail",
|
|
274
|
+
]),
|
|
275
|
+
legacyComments: (i) => {
|
|
341
276
|
if (typeof i !== "object")
|
|
342
277
|
return false;
|
|
343
|
-
for (
|
|
344
|
-
var item = _a[_i];
|
|
278
|
+
for (const item of i) {
|
|
345
279
|
if (!typeGuard.formatted.legacyComment(item))
|
|
346
280
|
return false;
|
|
347
281
|
}
|
|
@@ -349,14 +283,12 @@
|
|
|
349
283
|
},
|
|
350
284
|
},
|
|
351
285
|
legacy: {
|
|
352
|
-
rawApiResponses:
|
|
286
|
+
rawApiResponses: (i) => {
|
|
353
287
|
if (typeof i !== "object")
|
|
354
288
|
return false;
|
|
355
|
-
for (
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
var key = _c[_b];
|
|
359
|
-
var item = itemWrapper[key];
|
|
289
|
+
for (const itemWrapper of i) {
|
|
290
|
+
for (const key of Object.keys(itemWrapper)) {
|
|
291
|
+
const item = itemWrapper[key];
|
|
360
292
|
if (!item)
|
|
361
293
|
continue;
|
|
362
294
|
if (!(typeGuard.legacy.apiChat(item) ||
|
|
@@ -370,33 +302,26 @@
|
|
|
370
302
|
}
|
|
371
303
|
return true;
|
|
372
304
|
},
|
|
373
|
-
apiChat:
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
"revision",
|
|
386
|
-
"server_time",
|
|
387
|
-
"thread",
|
|
388
|
-
"ticket",
|
|
389
|
-
]);
|
|
390
|
-
},
|
|
305
|
+
apiChat: (i) => typeof i === "object" &&
|
|
306
|
+
objectVerify(i, ["content", "date", "no", "thread", "vpos"]),
|
|
307
|
+
apiGlobalNumRes: (i) => objectVerify(i, ["num_res", "thread"]),
|
|
308
|
+
apiLeaf: (i) => objectVerify(i, ["count", "thread"]),
|
|
309
|
+
apiPing: (i) => objectVerify(i, ["content"]),
|
|
310
|
+
apiThread: (i) => objectVerify(i, [
|
|
311
|
+
"resultcode",
|
|
312
|
+
"revision",
|
|
313
|
+
"server_time",
|
|
314
|
+
"thread",
|
|
315
|
+
"ticket",
|
|
316
|
+
]),
|
|
391
317
|
},
|
|
392
|
-
xmlDocument:
|
|
318
|
+
xmlDocument: (i) => {
|
|
393
319
|
if (!i.documentElement ||
|
|
394
320
|
i.documentElement.nodeName !== "packet")
|
|
395
321
|
return false;
|
|
396
322
|
if (!i.documentElement.children)
|
|
397
323
|
return false;
|
|
398
|
-
for (
|
|
399
|
-
var element = _a[_i];
|
|
324
|
+
for (const element of Array.from(i.documentElement.children)) {
|
|
400
325
|
if (!element || element.nodeName !== "chat")
|
|
401
326
|
continue;
|
|
402
327
|
if (!typeAttributeVerify(element, ["vpos", "date"]))
|
|
@@ -405,12 +330,11 @@
|
|
|
405
330
|
return true;
|
|
406
331
|
},
|
|
407
332
|
legacyOwner: {
|
|
408
|
-
comments:
|
|
333
|
+
comments: (i) => {
|
|
409
334
|
if (typeof i !== "string")
|
|
410
335
|
return false;
|
|
411
|
-
|
|
412
|
-
for (
|
|
413
|
-
var list = lists_1[_i];
|
|
336
|
+
const lists = i.split("\n");
|
|
337
|
+
for (const list of lists) {
|
|
414
338
|
if (list.split(":").length < 3) {
|
|
415
339
|
return false;
|
|
416
340
|
}
|
|
@@ -419,14 +343,11 @@
|
|
|
419
343
|
},
|
|
420
344
|
},
|
|
421
345
|
owner: {
|
|
422
|
-
comment:
|
|
423
|
-
|
|
424
|
-
},
|
|
425
|
-
comments: function (i) {
|
|
346
|
+
comment: (i) => objectVerify(i, ["time", "command", "comment"]),
|
|
347
|
+
comments: (i) => {
|
|
426
348
|
if (typeof i !== "object")
|
|
427
349
|
return false;
|
|
428
|
-
for (
|
|
429
|
-
var item = _a[_i];
|
|
350
|
+
for (const item of i) {
|
|
430
351
|
if (!typeGuard.owner.comment(item))
|
|
431
352
|
return false;
|
|
432
353
|
}
|
|
@@ -434,38 +355,34 @@
|
|
|
434
355
|
},
|
|
435
356
|
},
|
|
436
357
|
v1: {
|
|
437
|
-
comment:
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
},
|
|
454
|
-
thread: function (i) {
|
|
358
|
+
comment: (i) => objectVerify(i, [
|
|
359
|
+
"id",
|
|
360
|
+
"no",
|
|
361
|
+
"vposMs",
|
|
362
|
+
"body",
|
|
363
|
+
"commands",
|
|
364
|
+
"userId",
|
|
365
|
+
"isPremium",
|
|
366
|
+
"score",
|
|
367
|
+
"postedAt",
|
|
368
|
+
"nicoruCount",
|
|
369
|
+
"nicoruId",
|
|
370
|
+
"source",
|
|
371
|
+
"isMyPost",
|
|
372
|
+
]),
|
|
373
|
+
thread: (i) => {
|
|
455
374
|
if (!objectVerify(i, ["id", "fork", "commentCount", "comments"]))
|
|
456
375
|
return false;
|
|
457
|
-
for (
|
|
458
|
-
var value = _a[_i];
|
|
376
|
+
for (const value of i.comments) {
|
|
459
377
|
if (!typeGuard.v1.comment(value))
|
|
460
378
|
return false;
|
|
461
379
|
}
|
|
462
380
|
return true;
|
|
463
381
|
},
|
|
464
|
-
threads:
|
|
382
|
+
threads: (i) => {
|
|
465
383
|
if (typeof i !== "object")
|
|
466
384
|
return false;
|
|
467
|
-
for (
|
|
468
|
-
var item = _a[_i];
|
|
385
|
+
for (const item of i) {
|
|
469
386
|
if (!typeGuard.v1.thread(item))
|
|
470
387
|
return false;
|
|
471
388
|
}
|
|
@@ -474,55 +391,33 @@
|
|
|
474
391
|
},
|
|
475
392
|
nicoScript: {
|
|
476
393
|
range: {
|
|
477
|
-
target:
|
|
478
|
-
return typeof i === "string" && !!i.match(/^(?:\u6295?\u30b3\u30e1|\u5168)$/);
|
|
479
|
-
},
|
|
394
|
+
target: (i) => typeof i === "string" && !!i.match(/^(?:\u6295?\u30b3\u30e1|\u5168)$/),
|
|
480
395
|
},
|
|
481
396
|
replace: {
|
|
482
|
-
range:
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
!!i.match(/^(?:\u30b3\u30e1|\u6295\u30b3\u30e1|\u5168|\u542b\u3080|\u542b\u307e\u306a\u3044)$/);
|
|
488
|
-
},
|
|
489
|
-
condition: function (i) {
|
|
490
|
-
return typeof i === "string" &&
|
|
491
|
-
!!i.match(/^(?:\u90e8\u5206\u4e00\u81f4|\u5b8c\u5168\u4e00\u81f4)$/);
|
|
492
|
-
},
|
|
397
|
+
range: (i) => typeof i === "string" && !!i.match(/^[\u5358\u5168]$/),
|
|
398
|
+
target: (i) => typeof i === "string" &&
|
|
399
|
+
!!i.match(/^(?:\u30b3\u30e1|\u6295\u30b3\u30e1|\u5168|\u542b\u3080|\u542b\u307e\u306a\u3044)$/),
|
|
400
|
+
condition: (i) => typeof i === "string" &&
|
|
401
|
+
!!i.match(/^(?:\u90e8\u5206\u4e00\u81f4|\u5b8c\u5168\u4e00\u81f4)$/),
|
|
493
402
|
},
|
|
494
403
|
},
|
|
495
404
|
comment: {
|
|
496
|
-
font:
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
loc: function (i) {
|
|
500
|
-
return typeof i === "string" && !!i.match(/^(?:ue|naka|shita)$/);
|
|
501
|
-
},
|
|
502
|
-
size: function (i) {
|
|
503
|
-
return typeof i === "string" && !!i.match(/^(?:big|medium|small)$/);
|
|
504
|
-
},
|
|
405
|
+
font: (i) => typeof i === "string" && !!i.match(/^(?:gothic|mincho|defont)$/),
|
|
406
|
+
loc: (i) => typeof i === "string" && !!i.match(/^(?:ue|naka|shita)$/),
|
|
407
|
+
size: (i) => typeof i === "string" && !!i.match(/^(?:big|medium|small)$/),
|
|
505
408
|
command: {
|
|
506
|
-
key:
|
|
507
|
-
return typeof i === "string" && !!i.match(/^(?:full|ender|_live|invisible)$/);
|
|
508
|
-
},
|
|
509
|
-
},
|
|
510
|
-
color: function (i) {
|
|
511
|
-
return typeof i === "string" && Object.keys(colors).includes(i);
|
|
512
|
-
},
|
|
513
|
-
colorCode: function (i) {
|
|
514
|
-
return typeof i === "string" && !!i.match(/^#(?:[0-9a-z]{3}|[0-9a-z]{6})$/);
|
|
515
|
-
},
|
|
516
|
-
colorCodeAllowAlpha: function (i) {
|
|
517
|
-
return typeof i === "string" &&
|
|
518
|
-
!!i.match(/^#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/);
|
|
409
|
+
key: (i) => typeof i === "string" && !!i.match(/^(?:full|ender|_live|invisible)$/),
|
|
519
410
|
},
|
|
411
|
+
color: (i) => typeof i === "string" && Object.keys(colors).includes(i),
|
|
412
|
+
colorCode: (i) => typeof i === "string" && !!i.match(/^#(?:[0-9a-z]{3}|[0-9a-z]{6})$/),
|
|
413
|
+
colorCodeAllowAlpha: (i) => typeof i === "string" &&
|
|
414
|
+
!!i.match(/^#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/),
|
|
520
415
|
},
|
|
521
416
|
config: {
|
|
522
|
-
initOptions:
|
|
417
|
+
initOptions: (item) => {
|
|
523
418
|
if (typeof item !== "object" || !item)
|
|
524
419
|
return false;
|
|
525
|
-
|
|
420
|
+
const keys = {
|
|
526
421
|
useLegacy: isBoolean,
|
|
527
422
|
formatted: isBoolean,
|
|
528
423
|
showCollision: isBoolean,
|
|
@@ -534,41 +429,38 @@
|
|
|
534
429
|
keepCA: isBoolean,
|
|
535
430
|
scale: isNumber,
|
|
536
431
|
config: isObject,
|
|
537
|
-
format:
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
},
|
|
541
|
-
video: function (i) {
|
|
542
|
-
return typeof i === "object" && i.nodeName === "VIDEO";
|
|
543
|
-
},
|
|
432
|
+
format: (i) => typeof i === "string" &&
|
|
433
|
+
!!i.match(/^(XMLDocument|niconicome|formatted|legacy|legacyOwner|owner|v1|default|empty)$/),
|
|
434
|
+
video: (i) => typeof i === "object" && i.nodeName === "VIDEO",
|
|
544
435
|
};
|
|
545
|
-
for (
|
|
546
|
-
var key = _a[_i];
|
|
436
|
+
for (const key of Object.keys(keys)) {
|
|
547
437
|
if (item[key] !== undefined &&
|
|
548
438
|
!keys[key](item[key])) {
|
|
549
|
-
console.warn(
|
|
439
|
+
console.warn(`[Incorrect input] var: initOptions, key: ${key}, value: ${item[key]}`);
|
|
550
440
|
return false;
|
|
551
441
|
}
|
|
552
442
|
}
|
|
553
443
|
return true;
|
|
554
444
|
},
|
|
555
445
|
},
|
|
446
|
+
canvas: {
|
|
447
|
+
nodeCanvas: (_) => isNode,
|
|
448
|
+
nodeContext: (_) => isNode,
|
|
449
|
+
},
|
|
556
450
|
};
|
|
557
|
-
|
|
451
|
+
const objectVerify = (item, keys) => {
|
|
558
452
|
if (typeof item !== "object" || !item)
|
|
559
453
|
return false;
|
|
560
|
-
for (
|
|
561
|
-
var key = keys_1[_i];
|
|
454
|
+
for (const key of keys) {
|
|
562
455
|
if (!Object.prototype.hasOwnProperty.call(item, key))
|
|
563
456
|
return false;
|
|
564
457
|
}
|
|
565
458
|
return true;
|
|
566
459
|
};
|
|
567
|
-
|
|
460
|
+
const typeAttributeVerify = (item, keys) => {
|
|
568
461
|
if (typeof item !== "object" || !item)
|
|
569
462
|
return false;
|
|
570
|
-
for (
|
|
571
|
-
var key = keys_2[_i];
|
|
463
|
+
for (const key of keys) {
|
|
572
464
|
if (item.getAttribute(key) === null)
|
|
573
465
|
return false;
|
|
574
466
|
}
|
|
@@ -580,8 +472,7 @@
|
|
|
580
472
|
default: typeGuard
|
|
581
473
|
});
|
|
582
474
|
|
|
583
|
-
|
|
584
|
-
if (isFlash === void 0) { isFlash = false; }
|
|
475
|
+
const getConfig = (input, isFlash = false) => {
|
|
585
476
|
if (Object.prototype.hasOwnProperty.call(input, "html5") &&
|
|
586
477
|
Object.prototype.hasOwnProperty.call(input, "flash")) {
|
|
587
478
|
return input[isFlash ? "flash" : "html5"];
|
|
@@ -591,16 +482,15 @@
|
|
|
591
482
|
}
|
|
592
483
|
};
|
|
593
484
|
|
|
594
|
-
|
|
485
|
+
const isLineBreakResize = (comment) => {
|
|
595
486
|
return (!comment.resized &&
|
|
596
487
|
!comment.ender &&
|
|
597
488
|
comment.lineCount >= config.lineBreakCount[comment.size]);
|
|
598
489
|
};
|
|
599
|
-
|
|
600
|
-
nicoScripts.default = nicoScripts.default.filter(
|
|
601
|
-
|
|
602
|
-
for (
|
|
603
|
-
var item = _a[_i];
|
|
490
|
+
const getDefaultCommand = (vpos) => {
|
|
491
|
+
nicoScripts.default = nicoScripts.default.filter((item) => !item.long || item.start + item.long >= vpos);
|
|
492
|
+
let color = undefined, size = undefined, font = undefined, loc = undefined;
|
|
493
|
+
for (const item of nicoScripts.default) {
|
|
604
494
|
if (item.loc) {
|
|
605
495
|
loc = item.loc;
|
|
606
496
|
}
|
|
@@ -616,23 +506,20 @@
|
|
|
616
506
|
if (loc && color && size && font)
|
|
617
507
|
break;
|
|
618
508
|
}
|
|
619
|
-
return { color
|
|
620
|
-
};
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
(item.
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
nicoScripts.replace = nicoScripts.replace.filter(function (item) { return !item.long || item.start + item.long >= comment.vpos; });
|
|
634
|
-
for (var _i = 0, _a = nicoScripts.replace; _i < _a.length; _i++) {
|
|
635
|
-
var item = _a[_i];
|
|
509
|
+
return { color, size, font, loc };
|
|
510
|
+
};
|
|
511
|
+
const nicoscriptReplaceIgnoreable = (comment, item) => ((item.target === "\u30b3\u30e1" ||
|
|
512
|
+
item.target === "\u542b\u307e\u306a\u3044") &&
|
|
513
|
+
comment.owner) ||
|
|
514
|
+
(item.target === "\u6295\u30b3\u30e1" && !comment.owner) ||
|
|
515
|
+
(item.target === "\u542b\u307e\u306a\u3044" && comment.owner) ||
|
|
516
|
+
(item.condition === "\u5b8c\u5168\u4e00\u81f4" &&
|
|
517
|
+
comment.content !== item.keyword) ||
|
|
518
|
+
(item.condition === "\u90e8\u5206\u4e00\u81f4" &&
|
|
519
|
+
comment.content.indexOf(item.keyword) === -1);
|
|
520
|
+
const applyNicoScriptReplace = (comment, commands) => {
|
|
521
|
+
nicoScripts.replace = nicoScripts.replace.filter((item) => !item.long || item.start + item.long >= comment.vpos);
|
|
522
|
+
for (const item of nicoScripts.replace) {
|
|
636
523
|
if (nicoscriptReplaceIgnoreable(comment, item))
|
|
637
524
|
continue;
|
|
638
525
|
if (item.range === "\u5358") {
|
|
@@ -647,30 +534,33 @@
|
|
|
647
534
|
item.font && (commands.font = item.font);
|
|
648
535
|
}
|
|
649
536
|
};
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
537
|
+
const parseCommandAndNicoScript = (comment) => {
|
|
538
|
+
const isFlash = isFlashComment(comment);
|
|
539
|
+
const commands = parseCommands(comment);
|
|
653
540
|
processNicoscript(comment, commands);
|
|
654
|
-
|
|
541
|
+
const defaultCommand = getDefaultCommand(comment.vpos);
|
|
655
542
|
applyNicoScriptReplace(comment, commands);
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
543
|
+
const size = commands.size || defaultCommand.size || "medium";
|
|
544
|
+
return {
|
|
545
|
+
size: size,
|
|
546
|
+
loc: commands.loc || defaultCommand.loc || "naka",
|
|
547
|
+
color: commands.color || defaultCommand.color || "#FFFFFF",
|
|
548
|
+
font: commands.font || defaultCommand.font || "defont",
|
|
549
|
+
fontSize: getConfig(config.fontSize, isFlash)[size].default,
|
|
550
|
+
long: commands.long ? Math.floor(Number(commands.long) * 100) : 300,
|
|
551
|
+
flash: isFlash,
|
|
552
|
+
full: commands.full,
|
|
553
|
+
ender: commands.ender,
|
|
554
|
+
_live: commands._live,
|
|
555
|
+
invisible: commands.invisible,
|
|
556
|
+
strokeColor: commands.strokeColor,
|
|
557
|
+
wakuColor: commands.wakuColor,
|
|
558
|
+
};
|
|
668
559
|
};
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
for (
|
|
673
|
-
var i = _a[_i];
|
|
560
|
+
const parseBrackets = (input) => {
|
|
561
|
+
const content = input.split(""), result = [];
|
|
562
|
+
let quote = "", last_i = "", string = "";
|
|
563
|
+
for (const i of content.slice(4)) {
|
|
674
564
|
if (i.match(/["'\u300c]/) && quote === "") {
|
|
675
565
|
quote = i;
|
|
676
566
|
}
|
|
@@ -698,8 +588,8 @@
|
|
|
698
588
|
result.push(string);
|
|
699
589
|
return result;
|
|
700
590
|
};
|
|
701
|
-
|
|
702
|
-
|
|
591
|
+
const addNicoscriptReplace = (comment, commands) => {
|
|
592
|
+
const result = parseBrackets(comment.content);
|
|
703
593
|
if (result[0] === undefined ||
|
|
704
594
|
(result[2] !== undefined &&
|
|
705
595
|
!typeGuard.nicoScript.replace.range(result[2])) ||
|
|
@@ -724,8 +614,8 @@
|
|
|
724
614
|
});
|
|
725
615
|
sortNicoscriptReplace();
|
|
726
616
|
};
|
|
727
|
-
|
|
728
|
-
nicoScripts.replace.sort(
|
|
617
|
+
const sortNicoscriptReplace = () => {
|
|
618
|
+
nicoScripts.replace.sort((a, b) => {
|
|
729
619
|
if (a.start < b.start)
|
|
730
620
|
return -1;
|
|
731
621
|
if (a.start > b.start)
|
|
@@ -737,8 +627,8 @@
|
|
|
737
627
|
return 0;
|
|
738
628
|
});
|
|
739
629
|
};
|
|
740
|
-
|
|
741
|
-
|
|
630
|
+
const processNicoscript = (comment, commands) => {
|
|
631
|
+
const nicoscript = comment.content.match(/^[@\uff20](\u30c7\u30d5\u30a9\u30eb\u30c8|\u7f6e\u63db|\u9006|\u30b3\u30e1\u30f3\u30c8\u7981\u6b62|\u30b7\u30fc\u30af\u7981\u6b62|\u30b8\u30e3\u30f3\u30d7)(.*)/);
|
|
742
632
|
if (!nicoscript || !comment.owner)
|
|
743
633
|
return;
|
|
744
634
|
commands.invisible = true;
|
|
@@ -766,7 +656,7 @@
|
|
|
766
656
|
addNicoscriptReplace(comment, commands);
|
|
767
657
|
}
|
|
768
658
|
};
|
|
769
|
-
|
|
659
|
+
const processDefaultScript = (comment, commands) => {
|
|
770
660
|
nicoScripts.default.unshift({
|
|
771
661
|
start: comment.vpos,
|
|
772
662
|
long: commands.long === undefined ? undefined : Math.floor(commands.long * 100),
|
|
@@ -776,8 +666,8 @@
|
|
|
776
666
|
loc: commands.loc,
|
|
777
667
|
});
|
|
778
668
|
};
|
|
779
|
-
|
|
780
|
-
|
|
669
|
+
const processReverseScript = (comment, commands) => {
|
|
670
|
+
const reverse = comment.content.match(/^[@\uff20]\u9006(?:\s+)?(\u5168|\u30b3\u30e1|\u6295\u30b3\u30e1)?/);
|
|
781
671
|
if (!reverse || !reverse[1] || !typeGuard.nicoScript.range.target(reverse[1]))
|
|
782
672
|
return;
|
|
783
673
|
if (commands.long === undefined) {
|
|
@@ -789,7 +679,7 @@
|
|
|
789
679
|
target: reverse[1],
|
|
790
680
|
});
|
|
791
681
|
};
|
|
792
|
-
|
|
682
|
+
const processBanScript = (comment, commands) => {
|
|
793
683
|
if (commands.long === undefined) {
|
|
794
684
|
commands.long = 30;
|
|
795
685
|
}
|
|
@@ -798,7 +688,7 @@
|
|
|
798
688
|
end: comment.vpos + commands.long * 100,
|
|
799
689
|
});
|
|
800
690
|
};
|
|
801
|
-
|
|
691
|
+
const processSeekDisableScript$1 = (comment, commands) => {
|
|
802
692
|
if (commands.long === undefined) {
|
|
803
693
|
commands.long = 30;
|
|
804
694
|
}
|
|
@@ -807,8 +697,8 @@
|
|
|
807
697
|
end: comment.vpos + commands.long * 100,
|
|
808
698
|
});
|
|
809
699
|
};
|
|
810
|
-
|
|
811
|
-
|
|
700
|
+
const processJumpScript$1 = (comment, commands, input) => {
|
|
701
|
+
const options = input.match(/\s*((?:sm|so|nm|\uff53\uff4d|\uff53\uff4f|\uff4e\uff4d)?[1-9\uff11-\uff19][0-9\uff11-\uff19]*|#[0-9]+:[0-9]+(?:\.[0-9]+)?)\s+(.*)/);
|
|
812
702
|
if (!options || !options[1])
|
|
813
703
|
return;
|
|
814
704
|
nicoScripts.jump.unshift({
|
|
@@ -818,9 +708,9 @@
|
|
|
818
708
|
message: options[2],
|
|
819
709
|
});
|
|
820
710
|
};
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
711
|
+
const parseCommands = (comment) => {
|
|
712
|
+
const commands = comment.mail, isFlash = isFlashComment(comment);
|
|
713
|
+
const result = {
|
|
824
714
|
loc: undefined,
|
|
825
715
|
size: undefined,
|
|
826
716
|
fontSize: undefined,
|
|
@@ -834,8 +724,7 @@
|
|
|
834
724
|
invisible: false,
|
|
835
725
|
long: undefined,
|
|
836
726
|
};
|
|
837
|
-
for (
|
|
838
|
-
var command = commands_1[_i];
|
|
727
|
+
for (const command of commands) {
|
|
839
728
|
parseCommand(comment, command, result, isFlash);
|
|
840
729
|
}
|
|
841
730
|
if (comment.content.startsWith("/")) {
|
|
@@ -843,35 +732,25 @@
|
|
|
843
732
|
}
|
|
844
733
|
return result;
|
|
845
734
|
};
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
if (
|
|
850
|
-
result.long = Number(
|
|
735
|
+
const parseCommand = (comment, _command, result, isFlash) => {
|
|
736
|
+
const command = _command.toLowerCase();
|
|
737
|
+
const long = command.match(/^[@\uff20]([0-9.]+)/);
|
|
738
|
+
if (long) {
|
|
739
|
+
result.long = Number(long[1]);
|
|
851
740
|
return;
|
|
852
741
|
}
|
|
853
|
-
|
|
854
|
-
if (
|
|
855
|
-
|
|
856
|
-
result.strokeColor = colors[match[1]];
|
|
857
|
-
}
|
|
858
|
-
else if (typeGuard.comment.colorCodeAllowAlpha(match[1])) {
|
|
859
|
-
result.strokeColor = match[1].slice(1);
|
|
860
|
-
}
|
|
742
|
+
const strokeColor = getColor(command.match(/^nico:stroke:(.+)$/));
|
|
743
|
+
if (strokeColor) {
|
|
744
|
+
result.strokeColor ??= strokeColor;
|
|
861
745
|
return;
|
|
862
746
|
}
|
|
863
|
-
|
|
864
|
-
if (
|
|
865
|
-
|
|
866
|
-
result.wakuColor = colors[match[1]];
|
|
867
|
-
}
|
|
868
|
-
else if (typeGuard.comment.colorCodeAllowAlpha(match[1])) {
|
|
869
|
-
result.wakuColor = match[1].slice(1);
|
|
870
|
-
}
|
|
747
|
+
const rectColor = getColor(command.match(/^nico:waku:(.+)$/));
|
|
748
|
+
if (rectColor) {
|
|
749
|
+
result.wakuColor ??= rectColor;
|
|
871
750
|
return;
|
|
872
751
|
}
|
|
873
|
-
if (
|
|
874
|
-
result.loc
|
|
752
|
+
if (typeGuard.comment.loc(command)) {
|
|
753
|
+
result.loc ??= command;
|
|
875
754
|
return;
|
|
876
755
|
}
|
|
877
756
|
if (result.size === undefined && typeGuard.comment.size(command)) {
|
|
@@ -879,34 +758,44 @@
|
|
|
879
758
|
result.fontSize = getConfig(config.fontSize, isFlash)[command].default;
|
|
880
759
|
return;
|
|
881
760
|
}
|
|
882
|
-
if (
|
|
883
|
-
result.color
|
|
761
|
+
if (config.colors[command]) {
|
|
762
|
+
result.color ??= config.colors[command];
|
|
884
763
|
return;
|
|
885
764
|
}
|
|
886
|
-
|
|
887
|
-
if (
|
|
888
|
-
result.color
|
|
765
|
+
const colorCode = command.match(/^#(?:[0-9a-z]{3}|[0-9a-z]{6})$/);
|
|
766
|
+
if (colorCode && comment.premium) {
|
|
767
|
+
result.color ??= colorCode[0].toUpperCase();
|
|
889
768
|
return;
|
|
890
769
|
}
|
|
891
|
-
if (
|
|
892
|
-
result.font
|
|
770
|
+
if (typeGuard.comment.font(command)) {
|
|
771
|
+
result.font ??= command;
|
|
772
|
+
return;
|
|
893
773
|
}
|
|
894
|
-
|
|
774
|
+
if (typeGuard.comment.command.key(command)) {
|
|
895
775
|
result[command] = true;
|
|
896
776
|
}
|
|
897
777
|
};
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
778
|
+
const getColor = (match) => {
|
|
779
|
+
if (!match)
|
|
780
|
+
return;
|
|
781
|
+
const value = match[1];
|
|
782
|
+
if (typeGuard.comment.color(value)) {
|
|
783
|
+
return colors[value];
|
|
784
|
+
}
|
|
785
|
+
else if (typeGuard.comment.colorCodeAllowAlpha(value)) {
|
|
786
|
+
return value.slice(1);
|
|
787
|
+
}
|
|
788
|
+
return;
|
|
789
|
+
};
|
|
790
|
+
const isFlashComment = (comment) => options.mode === "flash" ||
|
|
791
|
+
(options.mode === "default" &&
|
|
792
|
+
!(comment.mail.includes("gothic") ||
|
|
793
|
+
comment.mail.includes("defont") ||
|
|
794
|
+
comment.mail.includes("mincho")) &&
|
|
795
|
+
(comment.date < config.flashThreshold ||
|
|
796
|
+
comment.mail.includes("nico:flash")));
|
|
797
|
+
const isReverseActive = (vpos, isOwner) => {
|
|
798
|
+
for (const range of nicoScripts.reverse) {
|
|
910
799
|
if ((range.target === "コメ" && isOwner) ||
|
|
911
800
|
(range.target === "投コメ" && !isOwner))
|
|
912
801
|
continue;
|
|
@@ -916,29 +805,28 @@
|
|
|
916
805
|
}
|
|
917
806
|
return false;
|
|
918
807
|
};
|
|
919
|
-
|
|
920
|
-
for (
|
|
921
|
-
var range = _a[_i];
|
|
808
|
+
const isBanActive = (vpos) => {
|
|
809
|
+
for (const range of nicoScripts.ban) {
|
|
922
810
|
if (range.start < vpos && vpos < range.end)
|
|
923
811
|
return true;
|
|
924
812
|
}
|
|
925
813
|
return false;
|
|
926
814
|
};
|
|
927
|
-
|
|
928
|
-
|
|
815
|
+
const processFixedComment = (comment, collision, timeline) => {
|
|
816
|
+
let posY = 0, isChanged = true, count = 0;
|
|
929
817
|
while (isChanged && count < 10) {
|
|
930
818
|
isChanged = false;
|
|
931
819
|
count++;
|
|
932
|
-
for (
|
|
933
|
-
|
|
820
|
+
for (let j = 0; j < comment.long; j++) {
|
|
821
|
+
const result = getPosY(posY, comment, collision[comment.vpos + j]);
|
|
934
822
|
posY = result.currentPos;
|
|
935
823
|
isChanged = result.isChanged;
|
|
936
824
|
if (result.isBreak)
|
|
937
825
|
break;
|
|
938
826
|
}
|
|
939
827
|
}
|
|
940
|
-
for (
|
|
941
|
-
|
|
828
|
+
for (let j = 0; j < comment.long; j++) {
|
|
829
|
+
const vpos = comment.vpos + j;
|
|
942
830
|
ArrayPush(timeline, vpos, comment);
|
|
943
831
|
if (j > comment.long - 20)
|
|
944
832
|
continue;
|
|
@@ -946,31 +834,31 @@
|
|
|
946
834
|
}
|
|
947
835
|
comment.posY = posY;
|
|
948
836
|
};
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
837
|
+
const processMovableComment = (comment, collision, timeline) => {
|
|
838
|
+
const beforeVpos = Math.round(-288 / ((1632 + comment.width) / (comment.long + 125))) - 100;
|
|
839
|
+
const posY = (() => {
|
|
952
840
|
if (config.canvasHeight < comment.height) {
|
|
953
841
|
return (comment.height - config.canvasHeight) / -2;
|
|
954
842
|
}
|
|
955
|
-
|
|
956
|
-
|
|
843
|
+
let posY = 0;
|
|
844
|
+
let isChanged = true, count = 0;
|
|
957
845
|
while (isChanged && count < 10) {
|
|
958
846
|
isChanged = false;
|
|
959
847
|
count++;
|
|
960
|
-
for (
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
848
|
+
for (let j = beforeVpos, n = comment.long + 125; j < n; j++) {
|
|
849
|
+
const vpos = comment.vpos + j;
|
|
850
|
+
const left_pos = getPosX(comment.comment, vpos);
|
|
851
|
+
let isBreak = false;
|
|
964
852
|
if (left_pos + comment.width >= config.collisionRange.right &&
|
|
965
853
|
left_pos <= config.collisionRange.right) {
|
|
966
|
-
|
|
854
|
+
const result = getPosY(posY, comment, collision.right[vpos]);
|
|
967
855
|
posY = result.currentPos;
|
|
968
856
|
isChanged = result.isChanged;
|
|
969
857
|
isBreak = result.isBreak;
|
|
970
858
|
}
|
|
971
859
|
if (left_pos + comment.width >= config.collisionRange.left &&
|
|
972
860
|
left_pos <= config.collisionRange.left) {
|
|
973
|
-
|
|
861
|
+
const result = getPosY(posY, comment, collision.left[vpos]);
|
|
974
862
|
posY = result.currentPos;
|
|
975
863
|
isChanged = result.isChanged;
|
|
976
864
|
isBreak = result.isBreak;
|
|
@@ -981,9 +869,9 @@
|
|
|
981
869
|
}
|
|
982
870
|
return posY;
|
|
983
871
|
})();
|
|
984
|
-
for (
|
|
985
|
-
|
|
986
|
-
|
|
872
|
+
for (let j = beforeVpos, n = comment.long + 125; j < n; j++) {
|
|
873
|
+
const vpos = comment.vpos + j;
|
|
874
|
+
const left_pos = getPosX(comment.comment, vpos);
|
|
987
875
|
ArrayPush(timeline, vpos, comment);
|
|
988
876
|
if (left_pos + comment.width >= config.collisionRange.right &&
|
|
989
877
|
left_pos <= config.collisionRange.right) {
|
|
@@ -996,12 +884,11 @@
|
|
|
996
884
|
}
|
|
997
885
|
comment.posY = posY;
|
|
998
886
|
};
|
|
999
|
-
|
|
1000
|
-
|
|
887
|
+
const getPosY = (currentPos, targetComment, collision) => {
|
|
888
|
+
let isChanged = false, isBreak = false;
|
|
1001
889
|
if (!collision)
|
|
1002
|
-
return { currentPos
|
|
1003
|
-
for (
|
|
1004
|
-
var collisionItem = collision_1[_i];
|
|
890
|
+
return { currentPos, isChanged, isBreak };
|
|
891
|
+
for (const collisionItem of collision) {
|
|
1005
892
|
if (currentPos < collisionItem.posY + collisionItem.height &&
|
|
1006
893
|
currentPos + targetComment.height > collisionItem.posY &&
|
|
1007
894
|
collisionItem.owner === targetComment.owner &&
|
|
@@ -1027,17 +914,16 @@
|
|
|
1027
914
|
}
|
|
1028
915
|
}
|
|
1029
916
|
}
|
|
1030
|
-
return { currentPos
|
|
917
|
+
return { currentPos, isChanged, isBreak };
|
|
1031
918
|
};
|
|
1032
|
-
|
|
1033
|
-
if (isReverse === void 0) { isReverse = false; }
|
|
919
|
+
const getPosX = (comment, vpos, isReverse = false) => {
|
|
1034
920
|
if (comment.loc !== "naka") {
|
|
1035
921
|
return (config.canvasWidth - comment.width) / 2;
|
|
1036
922
|
}
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
923
|
+
const speed = (config.commentDrawRange + comment.width * config.nakaCommentSpeedOffset) /
|
|
924
|
+
(comment.long + 100);
|
|
925
|
+
const vposLapsed = vpos - comment.vpos;
|
|
926
|
+
const posX = config.commentDrawPadding +
|
|
1041
927
|
config.commentDrawRange -
|
|
1042
928
|
(vposLapsed + 100) * speed;
|
|
1043
929
|
if (isReverse) {
|
|
@@ -1045,58 +931,55 @@
|
|
|
1045
931
|
}
|
|
1046
932
|
return posX;
|
|
1047
933
|
};
|
|
1048
|
-
|
|
934
|
+
const parseFont = (font, size) => {
|
|
1049
935
|
switch (font) {
|
|
1050
936
|
case "gulim":
|
|
1051
937
|
case "simsun":
|
|
1052
|
-
return config.font[font].replace("[size]",
|
|
938
|
+
return config.font[font].replace("[size]", `${size}`);
|
|
1053
939
|
case "gothic":
|
|
1054
940
|
case "mincho":
|
|
1055
|
-
return
|
|
941
|
+
return `${config.fonts[font].weight} ${size}px ${config.fonts[font].font}`;
|
|
1056
942
|
default:
|
|
1057
|
-
return
|
|
943
|
+
return `${config.fonts.defont.weight} ${size}px ${config.fonts.defont.font}`;
|
|
1058
944
|
}
|
|
1059
945
|
};
|
|
1060
946
|
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
var commentArtsGroupedByUser = groupCommentsByUser(commentArts);
|
|
1069
|
-
var commentArtsGroupedByTimes = groupCommentsByTime(commentArtsGroupedByUser);
|
|
947
|
+
const changeCALayer = (rawData) => {
|
|
948
|
+
const userScoreList = getUsersScore(rawData);
|
|
949
|
+
const filteredComments = removeDuplicateCommentArt(rawData);
|
|
950
|
+
const commentArts = filteredComments.filter((comment) => (userScoreList[comment.user_id] || 0) >= config.sameCAMinScore &&
|
|
951
|
+
!comment.owner);
|
|
952
|
+
const commentArtsGroupedByUser = groupCommentsByUser(commentArts);
|
|
953
|
+
const commentArtsGroupedByTimes = groupCommentsByTime(commentArtsGroupedByUser);
|
|
1070
954
|
updateLayerId(commentArtsGroupedByTimes);
|
|
1071
955
|
return filteredComments;
|
|
1072
956
|
};
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
for (var _i = 0, comments_1 = comments; _i < comments_1.length; _i++) {
|
|
1077
|
-
var comment = comments_1[_i];
|
|
957
|
+
const getUsersScore = (comments) => {
|
|
958
|
+
const userScoreList = {};
|
|
959
|
+
for (const comment of comments) {
|
|
1078
960
|
if (comment.user_id === undefined || comment.user_id === -1)
|
|
1079
961
|
continue;
|
|
1080
|
-
userScoreList[
|
|
962
|
+
userScoreList[comment.user_id] ||= 0;
|
|
1081
963
|
if (comment.mail.includes("ca") ||
|
|
1082
964
|
comment.mail.includes("patissier") ||
|
|
1083
965
|
comment.mail.includes("ender") ||
|
|
1084
966
|
comment.mail.includes("full")) {
|
|
1085
967
|
userScoreList[comment.user_id] += 5;
|
|
1086
968
|
}
|
|
1087
|
-
|
|
969
|
+
const lineCount = (comment.content.match(/\r\n|\n|\r/g) || []).length;
|
|
1088
970
|
if (lineCount > 2) {
|
|
1089
971
|
userScoreList[comment.user_id] += lineCount / 2;
|
|
1090
972
|
}
|
|
1091
973
|
}
|
|
1092
974
|
return userScoreList;
|
|
1093
975
|
};
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
return comments.filter(
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
976
|
+
const removeDuplicateCommentArt = (comments) => {
|
|
977
|
+
const index = {};
|
|
978
|
+
return comments.filter((comment) => {
|
|
979
|
+
const key = `${comment.content}@@${[...comment.mail]
|
|
980
|
+
.sort()
|
|
981
|
+
.filter((e) => !e.match(/@[\d.]+|184|device:.+|patissier|ca/))
|
|
982
|
+
.join("")}`, lastComment = index[key];
|
|
1100
983
|
if (lastComment === undefined) {
|
|
1101
984
|
index[key] = comment;
|
|
1102
985
|
return true;
|
|
@@ -1109,44 +992,41 @@
|
|
|
1109
992
|
return false;
|
|
1110
993
|
});
|
|
1111
994
|
};
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
for (
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
var time = _b[_a];
|
|
1118
|
-
for (var _c = 0, _d = time.comments; _c < _d.length; _c++) {
|
|
1119
|
-
var comment = _d[_c];
|
|
995
|
+
const updateLayerId = (filteredComments) => {
|
|
996
|
+
let layerId = 0;
|
|
997
|
+
for (const user of filteredComments) {
|
|
998
|
+
for (const time of user.comments) {
|
|
999
|
+
for (const comment of time.comments) {
|
|
1120
1000
|
comment.layer = layerId;
|
|
1121
1001
|
}
|
|
1122
1002
|
layerId++;
|
|
1123
1003
|
}
|
|
1124
1004
|
}
|
|
1125
1005
|
};
|
|
1126
|
-
|
|
1127
|
-
return comments.reduce(
|
|
1128
|
-
|
|
1006
|
+
const groupCommentsByUser = (comments) => {
|
|
1007
|
+
return comments.reduce((users, comment) => {
|
|
1008
|
+
const user = getUser(comment.user_id, users);
|
|
1129
1009
|
user.comments.push(comment);
|
|
1130
1010
|
return users;
|
|
1131
1011
|
}, []);
|
|
1132
1012
|
};
|
|
1133
|
-
|
|
1134
|
-
|
|
1013
|
+
const getUser = (userId, users) => {
|
|
1014
|
+
const user = users.find((user) => user.userId === userId);
|
|
1135
1015
|
if (user)
|
|
1136
1016
|
return user;
|
|
1137
|
-
|
|
1138
|
-
userId
|
|
1017
|
+
const obj = {
|
|
1018
|
+
userId,
|
|
1139
1019
|
comments: [],
|
|
1140
1020
|
};
|
|
1141
1021
|
users.push(obj);
|
|
1142
1022
|
return obj;
|
|
1143
1023
|
};
|
|
1144
|
-
|
|
1145
|
-
return comments.reduce(
|
|
1024
|
+
const groupCommentsByTime = (comments) => {
|
|
1025
|
+
return comments.reduce((result, user) => {
|
|
1146
1026
|
result.push({
|
|
1147
1027
|
userId: user.userId,
|
|
1148
|
-
comments: user.comments.reduce(
|
|
1149
|
-
|
|
1028
|
+
comments: user.comments.reduce((result, comment) => {
|
|
1029
|
+
const time = getTime(comment.date, result);
|
|
1150
1030
|
time.comments.push(comment);
|
|
1151
1031
|
time.range.start = Math.min(time.range.start, comment.date);
|
|
1152
1032
|
time.range.end = Math.max(time.range.end, comment.date);
|
|
@@ -1156,14 +1036,12 @@
|
|
|
1156
1036
|
return result;
|
|
1157
1037
|
}, []);
|
|
1158
1038
|
};
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
timeObj.range.end + config.sameCATimestampRange >= time;
|
|
1163
|
-
});
|
|
1039
|
+
const getTime = (time, times) => {
|
|
1040
|
+
const timeObj = times.find((timeObj) => timeObj.range.start - config.sameCATimestampRange <= time &&
|
|
1041
|
+
timeObj.range.end + config.sameCATimestampRange >= time);
|
|
1164
1042
|
if (timeObj)
|
|
1165
1043
|
return timeObj;
|
|
1166
|
-
|
|
1044
|
+
const obj = {
|
|
1167
1045
|
range: {
|
|
1168
1046
|
start: time,
|
|
1169
1047
|
end: time,
|
|
@@ -1174,15 +1052,29 @@
|
|
|
1174
1052
|
return obj;
|
|
1175
1053
|
};
|
|
1176
1054
|
|
|
1177
|
-
|
|
1178
|
-
|
|
1055
|
+
const nativeSort = (getter) => {
|
|
1056
|
+
return (a, b) => {
|
|
1057
|
+
if (getter(a) > getter(b)) {
|
|
1058
|
+
return 1;
|
|
1059
|
+
}
|
|
1060
|
+
else if (getter(a) < getter(b)) {
|
|
1061
|
+
return -1;
|
|
1062
|
+
}
|
|
1063
|
+
else {
|
|
1064
|
+
return 0;
|
|
1065
|
+
}
|
|
1066
|
+
};
|
|
1067
|
+
};
|
|
1068
|
+
|
|
1069
|
+
const getFlashFontIndex = (part) => {
|
|
1070
|
+
const regex = {
|
|
1179
1071
|
simsunStrong: new RegExp(config.flashChar.simsunStrong),
|
|
1180
1072
|
simsunWeak: new RegExp(config.flashChar.simsunWeak),
|
|
1181
1073
|
gulim: new RegExp(config.flashChar.gulim),
|
|
1182
1074
|
gothic: new RegExp(config.flashChar.gothic),
|
|
1183
1075
|
};
|
|
1184
|
-
|
|
1185
|
-
|
|
1076
|
+
const index = [];
|
|
1077
|
+
let match;
|
|
1186
1078
|
if ((match = regex.simsunStrong.exec(part)) !== null) {
|
|
1187
1079
|
index.push({ font: "simsunStrong", index: match.index });
|
|
1188
1080
|
}
|
|
@@ -1197,46 +1089,150 @@
|
|
|
1197
1089
|
}
|
|
1198
1090
|
return index;
|
|
1199
1091
|
};
|
|
1200
|
-
|
|
1092
|
+
const getFlashFontName = (font) => {
|
|
1201
1093
|
if (font.match("^simsun.+"))
|
|
1202
1094
|
return "simsun";
|
|
1203
1095
|
if (font === "gothic")
|
|
1204
1096
|
return "defont";
|
|
1205
1097
|
return font;
|
|
1206
1098
|
};
|
|
1099
|
+
const parseContent = (content) => {
|
|
1100
|
+
const results = [];
|
|
1101
|
+
const lines = (content.match(/\n|[^\n]+/g) || []).map((val) => Array.from(val.match(/[ -~。-゚]+|[^ -~。-゚]+/g) || []));
|
|
1102
|
+
for (const line of lines) {
|
|
1103
|
+
const lineContent = parseLine(line);
|
|
1104
|
+
const firstContent = lineContent[0];
|
|
1105
|
+
if (firstContent && firstContent.font) {
|
|
1106
|
+
results.push(...lineContent.map((val) => {
|
|
1107
|
+
if (!val.font) {
|
|
1108
|
+
val.font = firstContent.font;
|
|
1109
|
+
}
|
|
1110
|
+
return val;
|
|
1111
|
+
}));
|
|
1112
|
+
}
|
|
1113
|
+
else {
|
|
1114
|
+
results.push(...lineContent);
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
return results;
|
|
1118
|
+
};
|
|
1119
|
+
const parseLine = (line) => {
|
|
1120
|
+
const lineContent = [];
|
|
1121
|
+
for (const part of line) {
|
|
1122
|
+
if (part.match(/[ -~。-゚]+/g) !== null) {
|
|
1123
|
+
lineContent.push({ content: part, slicedContent: part.split("\n") });
|
|
1124
|
+
continue;
|
|
1125
|
+
}
|
|
1126
|
+
parseFullWidthPart(part, lineContent);
|
|
1127
|
+
}
|
|
1128
|
+
return lineContent;
|
|
1129
|
+
};
|
|
1130
|
+
const parseFullWidthPart = (part, lineContent) => {
|
|
1131
|
+
const index = getFlashFontIndex(part);
|
|
1132
|
+
if (index.length === 0) {
|
|
1133
|
+
lineContent.push({ content: part, slicedContent: part.split("\n") });
|
|
1134
|
+
}
|
|
1135
|
+
else if (index.length === 1 && index[0]) {
|
|
1136
|
+
lineContent.push({
|
|
1137
|
+
content: part,
|
|
1138
|
+
slicedContent: part.split("\n"),
|
|
1139
|
+
font: getFlashFontName(index[0].font),
|
|
1140
|
+
});
|
|
1141
|
+
}
|
|
1142
|
+
else {
|
|
1143
|
+
parseMultiFontFullWidthPart(part, index, lineContent);
|
|
1144
|
+
}
|
|
1145
|
+
};
|
|
1146
|
+
const parseMultiFontFullWidthPart = (part, index, lineContent) => {
|
|
1147
|
+
index.sort(nativeSort((val) => val.index));
|
|
1148
|
+
if (config.FlashMode === "xp") {
|
|
1149
|
+
let offset = 0;
|
|
1150
|
+
for (let i = 1, n = index.length; i < n; i++) {
|
|
1151
|
+
const currentVal = index[i], lastVal = index[i - 1];
|
|
1152
|
+
if (currentVal === undefined || lastVal === undefined)
|
|
1153
|
+
continue;
|
|
1154
|
+
const content = part.slice(offset, currentVal.index);
|
|
1155
|
+
lineContent.push({
|
|
1156
|
+
content: content,
|
|
1157
|
+
slicedContent: content.split("\n"),
|
|
1158
|
+
font: getFlashFontName(lastVal.font),
|
|
1159
|
+
});
|
|
1160
|
+
offset = currentVal.index;
|
|
1161
|
+
}
|
|
1162
|
+
const val = index[index.length - 1];
|
|
1163
|
+
if (val) {
|
|
1164
|
+
const content = part.slice(offset);
|
|
1165
|
+
lineContent.push({
|
|
1166
|
+
content: content,
|
|
1167
|
+
slicedContent: content.split("\n"),
|
|
1168
|
+
font: getFlashFontName(val.font),
|
|
1169
|
+
});
|
|
1170
|
+
}
|
|
1171
|
+
return;
|
|
1172
|
+
}
|
|
1173
|
+
const firstVal = index[0], secondVal = index[1];
|
|
1174
|
+
if (!firstVal || !secondVal) {
|
|
1175
|
+
lineContent.push({
|
|
1176
|
+
content: part,
|
|
1177
|
+
slicedContent: part.split("\n"),
|
|
1178
|
+
});
|
|
1179
|
+
return;
|
|
1180
|
+
}
|
|
1181
|
+
if (firstVal.font !== "gothic") {
|
|
1182
|
+
lineContent.push({
|
|
1183
|
+
content: part,
|
|
1184
|
+
slicedContent: part.split("\n"),
|
|
1185
|
+
font: getFlashFontName(firstVal.font),
|
|
1186
|
+
});
|
|
1187
|
+
return;
|
|
1188
|
+
}
|
|
1189
|
+
const firstContent = part.slice(0, secondVal.index);
|
|
1190
|
+
const secondContent = part.slice(secondVal.index);
|
|
1191
|
+
lineContent.push({
|
|
1192
|
+
content: firstContent,
|
|
1193
|
+
slicedContent: firstContent.split("\n"),
|
|
1194
|
+
font: getFlashFontName(firstVal.font),
|
|
1195
|
+
});
|
|
1196
|
+
lineContent.push({
|
|
1197
|
+
content: secondContent,
|
|
1198
|
+
slicedContent: secondContent.split("\n"),
|
|
1199
|
+
font: getFlashFontName(secondVal.font),
|
|
1200
|
+
});
|
|
1201
|
+
};
|
|
1207
1202
|
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
var lineCounts = getConfig(config.lineCounts, isFlash), commentStageSize = getConfig(config.commentStageSize, isFlash), lineHeight = commentStageSize.height / lineCounts.doubleResized[fontSize], defaultLineCount = lineCounts.default[fontSize];
|
|
1203
|
+
const getLineHeight = (fontSize, isFlash, resized = false) => {
|
|
1204
|
+
const lineCounts = getConfig(config.lineCounts, isFlash), CommentStageSize = getConfig(config.CommentStageSize, isFlash), lineHeight = CommentStageSize.height / lineCounts.doubleResized[fontSize], defaultLineCount = lineCounts.default[fontSize];
|
|
1211
1205
|
if (resized) {
|
|
1212
|
-
|
|
1213
|
-
return ((
|
|
1206
|
+
const resizedLineCount = lineCounts.resized[fontSize];
|
|
1207
|
+
return ((CommentStageSize.height -
|
|
1214
1208
|
lineHeight * (defaultLineCount / resizedLineCount)) /
|
|
1215
1209
|
(resizedLineCount - 1));
|
|
1216
1210
|
}
|
|
1217
|
-
return (
|
|
1211
|
+
return (CommentStageSize.height - lineHeight) / (defaultLineCount - 1);
|
|
1218
1212
|
};
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
return
|
|
1213
|
+
const getCharSize = (fontSize, isFlash) => {
|
|
1214
|
+
const lineCounts = getConfig(config.lineCounts, isFlash), CommentStageSize = getConfig(config.CommentStageSize, isFlash);
|
|
1215
|
+
return CommentStageSize.height / lineCounts.doubleResized[fontSize];
|
|
1222
1216
|
};
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
return
|
|
1217
|
+
const measure = (comment, context) => {
|
|
1218
|
+
const width = measureWidth(comment, context);
|
|
1219
|
+
return {
|
|
1220
|
+
...width,
|
|
1221
|
+
height: comment.lineHeight * (comment.lineCount - 1) + comment.charSize,
|
|
1222
|
+
};
|
|
1226
1223
|
};
|
|
1227
|
-
|
|
1228
|
-
|
|
1224
|
+
const measureWidth = (comment, context) => {
|
|
1225
|
+
const { fontSize, scale } = getFontSizeAndScale(comment.charSize), lineWidth = [], itemWidth = [];
|
|
1229
1226
|
context.font = parseFont(comment.font, fontSize);
|
|
1230
|
-
|
|
1231
|
-
for (
|
|
1232
|
-
|
|
1233
|
-
var lines = item.content.split("\n");
|
|
1227
|
+
let currentWidth = 0;
|
|
1228
|
+
for (const item of comment.content) {
|
|
1229
|
+
const lines = item.content.split("\n");
|
|
1234
1230
|
context.font = parseFont(item.font || comment.font, fontSize);
|
|
1235
|
-
|
|
1236
|
-
for (
|
|
1237
|
-
|
|
1238
|
-
currentWidth +=
|
|
1239
|
-
width.push(
|
|
1231
|
+
const width = [];
|
|
1232
|
+
for (let j = 0, n = lines.length; j < n; j++) {
|
|
1233
|
+
const measure = context.measureText(lines[j]);
|
|
1234
|
+
currentWidth += measure.width;
|
|
1235
|
+
width.push(measure.width);
|
|
1240
1236
|
if (j < lines.length - 1) {
|
|
1241
1237
|
lineWidth.push(Math.ceil(currentWidth * scale));
|
|
1242
1238
|
currentWidth = 0;
|
|
@@ -1246,12 +1242,12 @@
|
|
|
1246
1242
|
lineWidth.push(Math.ceil(currentWidth * scale));
|
|
1247
1243
|
}
|
|
1248
1244
|
return {
|
|
1249
|
-
width: Math.max
|
|
1250
|
-
lineWidth
|
|
1251
|
-
itemWidth
|
|
1245
|
+
width: Math.max(...lineWidth),
|
|
1246
|
+
lineWidth,
|
|
1247
|
+
itemWidth,
|
|
1252
1248
|
};
|
|
1253
1249
|
};
|
|
1254
|
-
|
|
1250
|
+
const getFontSizeAndScale = (charSize) => {
|
|
1255
1251
|
charSize *= 0.8;
|
|
1256
1252
|
if (charSize < config.minFontSize) {
|
|
1257
1253
|
if (charSize >= 1)
|
|
@@ -1267,20 +1263,6 @@
|
|
|
1267
1263
|
};
|
|
1268
1264
|
};
|
|
1269
1265
|
|
|
1270
|
-
var nativeSort = function (getter) {
|
|
1271
|
-
return function (a, b) {
|
|
1272
|
-
if (getter(a) > getter(b)) {
|
|
1273
|
-
return 1;
|
|
1274
|
-
}
|
|
1275
|
-
else if (getter(a) < getter(b)) {
|
|
1276
|
-
return -1;
|
|
1277
|
-
}
|
|
1278
|
-
else {
|
|
1279
|
-
return 0;
|
|
1280
|
-
}
|
|
1281
|
-
};
|
|
1282
|
-
};
|
|
1283
|
-
|
|
1284
1266
|
var index$1 = /*#__PURE__*/Object.freeze({
|
|
1285
1267
|
__proto__: null,
|
|
1286
1268
|
ArrayEqual: ArrayEqual,
|
|
@@ -1305,123 +1287,127 @@
|
|
|
1305
1287
|
measure: measure,
|
|
1306
1288
|
nativeSort: nativeSort,
|
|
1307
1289
|
parseCommandAndNicoScript: parseCommandAndNicoScript,
|
|
1290
|
+
parseContent: parseContent,
|
|
1308
1291
|
parseFont: parseFont,
|
|
1309
1292
|
processFixedComment: processFixedComment,
|
|
1310
1293
|
processMovableComment: processMovableComment
|
|
1311
1294
|
});
|
|
1312
1295
|
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1296
|
+
const generateCanvas = () => {
|
|
1297
|
+
if (isNode) {
|
|
1298
|
+
const { createCanvas } = require("@napi-rs/canvas");
|
|
1299
|
+
return createCanvas(1920, 1080);
|
|
1300
|
+
}
|
|
1301
|
+
return document.createElement("canvas");
|
|
1302
|
+
};
|
|
1303
|
+
const getContext = (canvas) => {
|
|
1304
|
+
if (typeGuard.canvas.nodeCanvas(canvas)) {
|
|
1305
|
+
return canvas.getContext("2d");
|
|
1306
|
+
}
|
|
1307
|
+
const context = canvas.getContext("2d");
|
|
1308
|
+
if (!context)
|
|
1309
|
+
throw new CanvasRenderingContext2DError();
|
|
1310
|
+
return context;
|
|
1311
|
+
};
|
|
1312
|
+
const drawImage = (targetContext, sourceImage, x, y) => {
|
|
1313
|
+
if (typeGuard.canvas.nodeContext(targetContext)) {
|
|
1314
|
+
if (!typeGuard.canvas.nodeCanvas(sourceImage))
|
|
1315
|
+
return;
|
|
1316
|
+
targetContext.drawImage(sourceImage, x, y);
|
|
1317
|
+
return;
|
|
1318
|
+
}
|
|
1319
|
+
if (typeGuard.canvas.nodeCanvas(sourceImage))
|
|
1320
|
+
return;
|
|
1321
|
+
targetContext.drawImage(sourceImage, x, y);
|
|
1322
|
+
};
|
|
1323
|
+
|
|
1324
|
+
class BaseComment {
|
|
1325
|
+
context;
|
|
1326
|
+
cacheKey;
|
|
1327
|
+
comment;
|
|
1328
|
+
posY;
|
|
1329
|
+
pluginName = "BaseComment";
|
|
1330
|
+
image;
|
|
1331
|
+
constructor(comment, context) {
|
|
1316
1332
|
this.context = context;
|
|
1317
1333
|
this.posY = 0;
|
|
1318
1334
|
comment.content = comment.content.replace(/\t/g, "\u2003\u2003");
|
|
1319
1335
|
this.comment = this.convertComment(comment);
|
|
1320
1336
|
this.cacheKey =
|
|
1321
1337
|
JSON.stringify(this.comment.content) +
|
|
1322
|
-
|
|
1323
|
-
|
|
1338
|
+
`@@${this.pluginName}@@` +
|
|
1339
|
+
[...this.comment.mail].sort().join(",");
|
|
1324
1340
|
}
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
}
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
return this.comment.height;
|
|
1363
|
-
},
|
|
1364
|
-
enumerable: false,
|
|
1365
|
-
configurable: true
|
|
1366
|
-
});
|
|
1367
|
-
Object.defineProperty(BaseComment.prototype, "flash", {
|
|
1368
|
-
get: function () {
|
|
1369
|
-
return false;
|
|
1370
|
-
},
|
|
1371
|
-
enumerable: false,
|
|
1372
|
-
configurable: true
|
|
1373
|
-
});
|
|
1374
|
-
Object.defineProperty(BaseComment.prototype, "layer", {
|
|
1375
|
-
get: function () {
|
|
1376
|
-
return this.comment.layer;
|
|
1377
|
-
},
|
|
1378
|
-
enumerable: false,
|
|
1379
|
-
configurable: true
|
|
1380
|
-
});
|
|
1381
|
-
Object.defineProperty(BaseComment.prototype, "owner", {
|
|
1382
|
-
get: function () {
|
|
1383
|
-
return this.comment.owner;
|
|
1384
|
-
},
|
|
1385
|
-
enumerable: false,
|
|
1386
|
-
configurable: true
|
|
1387
|
-
});
|
|
1388
|
-
Object.defineProperty(BaseComment.prototype, "mail", {
|
|
1389
|
-
get: function () {
|
|
1390
|
-
return this.comment.mail;
|
|
1391
|
-
},
|
|
1392
|
-
enumerable: false,
|
|
1393
|
-
configurable: true
|
|
1394
|
-
});
|
|
1395
|
-
BaseComment.prototype.getCommentSize = function (parsedData) {
|
|
1341
|
+
get invisible() {
|
|
1342
|
+
return this.comment.invisible;
|
|
1343
|
+
}
|
|
1344
|
+
get loc() {
|
|
1345
|
+
return this.comment.loc;
|
|
1346
|
+
}
|
|
1347
|
+
get long() {
|
|
1348
|
+
return this.comment.long;
|
|
1349
|
+
}
|
|
1350
|
+
get vpos() {
|
|
1351
|
+
return this.comment.vpos;
|
|
1352
|
+
}
|
|
1353
|
+
get width() {
|
|
1354
|
+
return this.comment.width;
|
|
1355
|
+
}
|
|
1356
|
+
get height() {
|
|
1357
|
+
return this.comment.height;
|
|
1358
|
+
}
|
|
1359
|
+
get flash() {
|
|
1360
|
+
return false;
|
|
1361
|
+
}
|
|
1362
|
+
get layer() {
|
|
1363
|
+
return this.comment.layer;
|
|
1364
|
+
}
|
|
1365
|
+
get owner() {
|
|
1366
|
+
return this.comment.owner;
|
|
1367
|
+
}
|
|
1368
|
+
get mail() {
|
|
1369
|
+
return this.comment.mail;
|
|
1370
|
+
}
|
|
1371
|
+
get content() {
|
|
1372
|
+
throw new NotImplementedError(this.pluginName, "set: content");
|
|
1373
|
+
}
|
|
1374
|
+
set content(_) {
|
|
1375
|
+
throw new NotImplementedError(this.pluginName, "set: content");
|
|
1376
|
+
}
|
|
1377
|
+
getCommentSize(parsedData) {
|
|
1396
1378
|
console.error("getCommentSize method is not implemented", parsedData);
|
|
1397
1379
|
throw new NotImplementedError(this.pluginName, "getCommentSize");
|
|
1398
|
-
}
|
|
1399
|
-
|
|
1380
|
+
}
|
|
1381
|
+
parseCommandAndNicoscript(comment) {
|
|
1400
1382
|
console.error("parseCommandAndNicoscript method is not implemented", comment);
|
|
1401
1383
|
throw new NotImplementedError(this.pluginName, "parseCommandAndNicoscript");
|
|
1402
|
-
}
|
|
1403
|
-
|
|
1384
|
+
}
|
|
1385
|
+
parseContent(comment) {
|
|
1386
|
+
console.error("parseContent method is not implemented", comment);
|
|
1387
|
+
throw new NotImplementedError(this.pluginName, "parseContent");
|
|
1388
|
+
}
|
|
1389
|
+
measureText(comment) {
|
|
1404
1390
|
console.error("measureText method is not implemented", comment);
|
|
1405
1391
|
throw new NotImplementedError(this.pluginName, "measureText");
|
|
1406
|
-
}
|
|
1407
|
-
|
|
1392
|
+
}
|
|
1393
|
+
convertComment(comment) {
|
|
1408
1394
|
console.error("convertComment method is not implemented", comment);
|
|
1409
1395
|
throw new NotImplementedError(this.pluginName, "convertComment");
|
|
1410
|
-
}
|
|
1411
|
-
|
|
1396
|
+
}
|
|
1397
|
+
draw(vpos, showCollision, debug) {
|
|
1412
1398
|
if (isBanActive(vpos))
|
|
1413
1399
|
return;
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1400
|
+
const reverse = isReverseActive(vpos, this.comment.owner);
|
|
1401
|
+
const posX = getPosX(this.comment, vpos, reverse);
|
|
1402
|
+
const posY = this.comment.loc === "shita"
|
|
1417
1403
|
? config.canvasHeight - this.posY - this.comment.height
|
|
1418
1404
|
: this.posY;
|
|
1419
1405
|
this._draw(posX, posY);
|
|
1420
1406
|
this._drawRectColor(posX, posY);
|
|
1421
1407
|
this._drawCollision(posX, posY, showCollision);
|
|
1422
1408
|
this._drawDebugInfo(posX, posY, debug);
|
|
1423
|
-
}
|
|
1424
|
-
|
|
1409
|
+
}
|
|
1410
|
+
_draw(posX, posY) {
|
|
1425
1411
|
if (this.image === undefined) {
|
|
1426
1412
|
this.image = this.getTextImage();
|
|
1427
1413
|
}
|
|
@@ -1432,121 +1418,137 @@
|
|
|
1432
1418
|
else {
|
|
1433
1419
|
this.context.globalAlpha = 1;
|
|
1434
1420
|
}
|
|
1435
|
-
this.context
|
|
1421
|
+
drawImage(this.context, this.image, posX, posY);
|
|
1436
1422
|
}
|
|
1437
|
-
}
|
|
1438
|
-
|
|
1423
|
+
}
|
|
1424
|
+
_drawRectColor(posX, posY) {
|
|
1439
1425
|
if (this.comment.wakuColor) {
|
|
1440
1426
|
this.context.strokeStyle = this.comment.wakuColor;
|
|
1441
1427
|
this.context.strokeRect(posX, posY, this.comment.width, this.comment.height);
|
|
1442
1428
|
}
|
|
1443
|
-
}
|
|
1444
|
-
|
|
1429
|
+
}
|
|
1430
|
+
_drawDebugInfo(posX, posY, debug) {
|
|
1445
1431
|
if (debug) {
|
|
1446
|
-
|
|
1447
|
-
|
|
1432
|
+
const font = this.context.font;
|
|
1433
|
+
const fillStyle = this.context.fillStyle;
|
|
1448
1434
|
this.context.font = parseFont("defont", 30);
|
|
1449
1435
|
this.context.fillStyle = "#ff00ff";
|
|
1450
1436
|
this.context.fillText(this.comment.mail.join(","), posX, posY + 30);
|
|
1451
1437
|
this.context.font = font;
|
|
1452
1438
|
this.context.fillStyle = fillStyle;
|
|
1453
1439
|
}
|
|
1454
|
-
}
|
|
1455
|
-
|
|
1440
|
+
}
|
|
1441
|
+
_drawCollision(posX, posY, showCollision) {
|
|
1456
1442
|
console.error("_drawCollision method is not implemented", posX, posY, showCollision);
|
|
1457
1443
|
throw new NotImplementedError(this.pluginName, "_drawCollision");
|
|
1458
|
-
}
|
|
1459
|
-
|
|
1460
|
-
var _this = this;
|
|
1444
|
+
}
|
|
1445
|
+
getTextImage() {
|
|
1461
1446
|
if (this.comment.invisible ||
|
|
1462
1447
|
(this.comment.lineCount === 1 && this.comment.width === 0) ||
|
|
1463
1448
|
this.comment.height - (this.comment.charSize - this.comment.lineHeight) <=
|
|
1464
1449
|
0)
|
|
1465
1450
|
return null;
|
|
1466
|
-
|
|
1451
|
+
const cache = imageCache[this.cacheKey];
|
|
1467
1452
|
if (cache) {
|
|
1468
1453
|
this.image = cache.image;
|
|
1469
|
-
|
|
1470
|
-
delete
|
|
1454
|
+
setTimeout(() => {
|
|
1455
|
+
delete this.image;
|
|
1471
1456
|
}, this.comment.long * 10 + config.cacheAge);
|
|
1472
1457
|
clearTimeout(cache.timeout);
|
|
1473
|
-
cache.timeout =
|
|
1474
|
-
delete imageCache[
|
|
1458
|
+
cache.timeout = setTimeout(() => {
|
|
1459
|
+
delete imageCache[this.cacheKey];
|
|
1475
1460
|
}, this.comment.long * 10 + config.cacheAge);
|
|
1476
1461
|
return cache.image;
|
|
1477
1462
|
}
|
|
1478
1463
|
if (this.image)
|
|
1479
1464
|
return this.image;
|
|
1480
|
-
|
|
1465
|
+
const image = this._generateTextImage();
|
|
1481
1466
|
this._cacheImage(image);
|
|
1482
1467
|
return image;
|
|
1483
|
-
}
|
|
1484
|
-
|
|
1468
|
+
}
|
|
1469
|
+
_generateTextImage() {
|
|
1485
1470
|
console.error("_generateTextImage method is not implemented");
|
|
1486
1471
|
throw new NotImplementedError(this.pluginName, "_generateTextImage");
|
|
1487
|
-
}
|
|
1488
|
-
|
|
1489
|
-
var _this = this;
|
|
1472
|
+
}
|
|
1473
|
+
_cacheImage(image) {
|
|
1490
1474
|
this.image = image;
|
|
1491
|
-
|
|
1492
|
-
delete
|
|
1475
|
+
setTimeout(() => {
|
|
1476
|
+
delete this.image;
|
|
1493
1477
|
}, this.comment.long * 10 + config.cacheAge);
|
|
1494
1478
|
imageCache[this.cacheKey] = {
|
|
1495
|
-
timeout:
|
|
1496
|
-
delete imageCache[
|
|
1479
|
+
timeout: setTimeout(() => {
|
|
1480
|
+
delete imageCache[this.cacheKey];
|
|
1497
1481
|
}, this.comment.long * 10 + config.cacheAge),
|
|
1498
|
-
image
|
|
1482
|
+
image,
|
|
1499
1483
|
};
|
|
1500
|
-
}
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
if (!context)
|
|
1505
|
-
throw new CanvasRenderingContext2DError();
|
|
1484
|
+
}
|
|
1485
|
+
createCanvas() {
|
|
1486
|
+
const image = generateCanvas();
|
|
1487
|
+
const context = getContext(image);
|
|
1506
1488
|
return {
|
|
1507
|
-
image
|
|
1508
|
-
context
|
|
1489
|
+
image,
|
|
1490
|
+
context,
|
|
1509
1491
|
};
|
|
1510
|
-
}
|
|
1511
|
-
|
|
1512
|
-
}());
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1513
1494
|
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1495
|
+
class FlashComment extends BaseComment {
|
|
1496
|
+
_globalScale;
|
|
1497
|
+
scale;
|
|
1498
|
+
scaleX;
|
|
1499
|
+
pluginName = "FlashComment";
|
|
1500
|
+
constructor(comment, context) {
|
|
1501
|
+
super(comment, context);
|
|
1502
|
+
this.scale ??= 1;
|
|
1503
|
+
this.scaleX ??= 1;
|
|
1504
|
+
this._globalScale ??= getConfig(config.commentScale, true);
|
|
1505
|
+
this.posY ??= 0;
|
|
1506
|
+
}
|
|
1507
|
+
get content() {
|
|
1508
|
+
return this.comment.rawContent;
|
|
1509
|
+
}
|
|
1510
|
+
set content(input) {
|
|
1511
|
+
const { content, lineCount, lineOffset } = this.parseContent(input);
|
|
1512
|
+
const comment = {
|
|
1513
|
+
...this.comment,
|
|
1514
|
+
rawContent: input,
|
|
1515
|
+
content,
|
|
1516
|
+
lineCount,
|
|
1517
|
+
lineOffset,
|
|
1518
|
+
};
|
|
1519
|
+
const val = content[0];
|
|
1520
|
+
if (val && val.font) {
|
|
1521
|
+
comment.font = val.font;
|
|
1522
|
+
}
|
|
1523
|
+
this.comment = this.getCommentSize(comment);
|
|
1524
|
+
this.cacheKey =
|
|
1525
|
+
JSON.stringify(this.comment.content) +
|
|
1526
|
+
`@@${this.pluginName}@@` +
|
|
1527
|
+
[...this.comment.mail].sort().join(",");
|
|
1528
|
+
delete this.image;
|
|
1529
|
+
}
|
|
1530
|
+
convertComment(comment) {
|
|
1528
1531
|
this.scale = 1;
|
|
1529
1532
|
this.scaleX = 1;
|
|
1530
1533
|
this._globalScale = getConfig(config.commentScale, true);
|
|
1531
1534
|
this.posY = 0;
|
|
1532
1535
|
return this.getCommentSize(this.parseCommandAndNicoscript(comment));
|
|
1533
|
-
}
|
|
1534
|
-
|
|
1536
|
+
}
|
|
1537
|
+
getCommentSize(parsedData) {
|
|
1535
1538
|
this.context.font = parseFont(parsedData.font, parsedData.fontSize);
|
|
1536
|
-
|
|
1539
|
+
const size = parsedData;
|
|
1537
1540
|
if (parsedData.invisible) {
|
|
1538
1541
|
size.height = 0;
|
|
1539
1542
|
size.width = 0;
|
|
1540
1543
|
size.lineHeight = 0;
|
|
1541
1544
|
size.fontSize = 0;
|
|
1542
|
-
size.content = [];
|
|
1543
1545
|
size.resized = false;
|
|
1544
1546
|
size.resizedX = false;
|
|
1545
1547
|
size.resizedY = false;
|
|
1546
1548
|
size.charSize = 0;
|
|
1547
1549
|
return size;
|
|
1548
1550
|
}
|
|
1549
|
-
|
|
1551
|
+
const measure = this.measureText(parsedData);
|
|
1550
1552
|
if (options.scale !== 1 && size.layer === -1) {
|
|
1551
1553
|
measure.height *= options.scale;
|
|
1552
1554
|
measure.width *= options.scale;
|
|
@@ -1561,129 +1563,44 @@
|
|
|
1561
1563
|
size.resizedY = measure.resizedY;
|
|
1562
1564
|
size.charSize = measure.charSize;
|
|
1563
1565
|
return size;
|
|
1564
|
-
}
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
var parts = (comment.content.match(/\n|[^\n]+/g) || []).map(function (val) {
|
|
1570
|
-
return Array.from(val.match(/[ -~。-゚]+|[^ -~。-゚]+/g) || []);
|
|
1571
|
-
});
|
|
1572
|
-
var _loop_1 = function (line) {
|
|
1573
|
-
var lineContent = [];
|
|
1574
|
-
for (var _c = 0, line_1 = line; _c < line_1.length; _c++) {
|
|
1575
|
-
var part = line_1[_c];
|
|
1576
|
-
if (part.match(/[ -~。-゚]+/g) !== null) {
|
|
1577
|
-
lineContent.push({ content: part, slicedContent: part.split("\n") });
|
|
1578
|
-
continue;
|
|
1579
|
-
}
|
|
1580
|
-
var index = getFlashFontIndex(part);
|
|
1581
|
-
if (index.length === 0) {
|
|
1582
|
-
lineContent.push({ content: part, slicedContent: part.split("\n") });
|
|
1583
|
-
}
|
|
1584
|
-
else if (index.length === 1 && index[0]) {
|
|
1585
|
-
lineContent.push({
|
|
1586
|
-
content: part,
|
|
1587
|
-
slicedContent: part.split("\n"),
|
|
1588
|
-
font: getFlashFontName(index[0].font),
|
|
1589
|
-
});
|
|
1590
|
-
}
|
|
1591
|
-
else {
|
|
1592
|
-
index.sort(nativeSort(function (val) { return val.index; }));
|
|
1593
|
-
if (config.flashMode === "xp") {
|
|
1594
|
-
var offset = 0;
|
|
1595
|
-
for (var i = 1, n = index.length; i < n; i++) {
|
|
1596
|
-
var currentVal = index[i], lastVal = index[i - 1];
|
|
1597
|
-
if (currentVal === undefined || lastVal === undefined)
|
|
1598
|
-
continue;
|
|
1599
|
-
var content_1 = part.slice(offset, currentVal.index);
|
|
1600
|
-
lineContent.push({
|
|
1601
|
-
content: content_1,
|
|
1602
|
-
slicedContent: content_1.split("\n"),
|
|
1603
|
-
font: getFlashFontName(lastVal.font),
|
|
1604
|
-
});
|
|
1605
|
-
offset = currentVal.index;
|
|
1606
|
-
}
|
|
1607
|
-
var val_1 = index[index.length - 1];
|
|
1608
|
-
if (val_1) {
|
|
1609
|
-
var content_2 = part.slice(offset);
|
|
1610
|
-
lineContent.push({
|
|
1611
|
-
content: content_2,
|
|
1612
|
-
slicedContent: content_2.split("\n"),
|
|
1613
|
-
font: getFlashFontName(val_1.font),
|
|
1614
|
-
});
|
|
1615
|
-
}
|
|
1616
|
-
}
|
|
1617
|
-
else {
|
|
1618
|
-
var firstVal = index[0], secondVal = index[1];
|
|
1619
|
-
if (!firstVal || !secondVal) {
|
|
1620
|
-
lineContent.push({
|
|
1621
|
-
content: part,
|
|
1622
|
-
slicedContent: part.split("\n"),
|
|
1623
|
-
});
|
|
1624
|
-
continue;
|
|
1625
|
-
}
|
|
1626
|
-
if (firstVal.font !== "gothic") {
|
|
1627
|
-
lineContent.push({
|
|
1628
|
-
content: part,
|
|
1629
|
-
slicedContent: part.split("\n"),
|
|
1630
|
-
font: getFlashFontName(firstVal.font),
|
|
1631
|
-
});
|
|
1632
|
-
}
|
|
1633
|
-
else {
|
|
1634
|
-
var firstContent_1 = part.slice(0, secondVal.index);
|
|
1635
|
-
var secondContent = part.slice(secondVal.index);
|
|
1636
|
-
lineContent.push({
|
|
1637
|
-
content: firstContent_1,
|
|
1638
|
-
slicedContent: firstContent_1.split("\n"),
|
|
1639
|
-
font: getFlashFontName(firstVal.font),
|
|
1640
|
-
});
|
|
1641
|
-
lineContent.push({
|
|
1642
|
-
content: secondContent,
|
|
1643
|
-
slicedContent: secondContent.split("\n"),
|
|
1644
|
-
font: getFlashFontName(secondVal.font),
|
|
1645
|
-
});
|
|
1646
|
-
}
|
|
1647
|
-
}
|
|
1648
|
-
}
|
|
1649
|
-
}
|
|
1650
|
-
var firstContent = lineContent[0];
|
|
1651
|
-
if (firstContent && firstContent.font) {
|
|
1652
|
-
content.push.apply(content, lineContent.map(function (val) {
|
|
1653
|
-
if (!val.font) {
|
|
1654
|
-
val.font = firstContent.font;
|
|
1655
|
-
}
|
|
1656
|
-
return val;
|
|
1657
|
-
}));
|
|
1658
|
-
}
|
|
1659
|
-
else {
|
|
1660
|
-
content.push.apply(content, lineContent);
|
|
1661
|
-
}
|
|
1662
|
-
};
|
|
1663
|
-
for (var _i = 0, parts_1 = parts; _i < parts_1.length; _i++) {
|
|
1664
|
-
var line = parts_1[_i];
|
|
1665
|
-
_loop_1(line);
|
|
1666
|
-
}
|
|
1667
|
-
var val = content[0];
|
|
1566
|
+
}
|
|
1567
|
+
parseCommandAndNicoscript(comment) {
|
|
1568
|
+
const data = parseCommandAndNicoScript(comment);
|
|
1569
|
+
const { content, lineCount, lineOffset } = this.parseContent(comment.content);
|
|
1570
|
+
const val = content[0];
|
|
1668
1571
|
if (val && val.font) {
|
|
1669
1572
|
data.font = val.font;
|
|
1670
1573
|
}
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1574
|
+
return {
|
|
1575
|
+
...comment,
|
|
1576
|
+
rawContent: comment.content,
|
|
1577
|
+
...data,
|
|
1578
|
+
content,
|
|
1579
|
+
lineCount,
|
|
1580
|
+
lineOffset,
|
|
1581
|
+
};
|
|
1582
|
+
}
|
|
1583
|
+
parseContent(input) {
|
|
1584
|
+
const content = parseContent(input);
|
|
1585
|
+
const lineCount = content.reduce((pv, val) => {
|
|
1586
|
+
return pv + (val.content.match(/\n/g)?.length || 0);
|
|
1674
1587
|
}, 1);
|
|
1675
|
-
|
|
1588
|
+
const lineOffset = (input.match(new RegExp(config.FlashScriptChar.super, "g"))?.length ||
|
|
1589
|
+
0) *
|
|
1676
1590
|
-1 *
|
|
1677
1591
|
config.scriptCharOffset +
|
|
1678
|
-
(
|
|
1592
|
+
(input.match(new RegExp(config.FlashScriptChar.sub, "g"))?.length || 0) *
|
|
1679
1593
|
config.scriptCharOffset;
|
|
1680
|
-
return
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1594
|
+
return {
|
|
1595
|
+
content,
|
|
1596
|
+
lineCount,
|
|
1597
|
+
lineOffset,
|
|
1598
|
+
};
|
|
1599
|
+
}
|
|
1600
|
+
measureText(comment) {
|
|
1601
|
+
const configLineHeight = getConfig(config.lineHeight, true), configFontSize = getConfig(config.fontSize, true);
|
|
1602
|
+
const lineCount = comment.lineCount;
|
|
1603
|
+
comment.lineHeight ??= configLineHeight[comment.size].default;
|
|
1687
1604
|
if (isLineBreakResize(comment)) {
|
|
1688
1605
|
comment.fontSize = configFontSize[comment.size].resized;
|
|
1689
1606
|
comment.lineHeight = configLineHeight[comment.size].resized;
|
|
@@ -1691,52 +1608,26 @@
|
|
|
1691
1608
|
comment.resizedY = true;
|
|
1692
1609
|
this.context.font = parseFont(comment.font, comment.fontSize);
|
|
1693
1610
|
}
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
var widths = [];
|
|
1700
|
-
this.context.font = parseFont(item.font || comment.font, comment.fontSize);
|
|
1701
|
-
for (var i = 0, n = lines.length; i < n; i++) {
|
|
1702
|
-
var value = lines[i];
|
|
1703
|
-
if (value === undefined)
|
|
1704
|
-
continue;
|
|
1705
|
-
var measure = this.context.measureText(value);
|
|
1706
|
-
currentWidth += measure.width;
|
|
1707
|
-
spacedWidth +=
|
|
1708
|
-
measure.width + Math.max(value.length - 1, 0) * config.letterSpacing;
|
|
1709
|
-
widths.push(measure.width);
|
|
1710
|
-
if (i < lines.length - 1) {
|
|
1711
|
-
width_arr.push(currentWidth);
|
|
1712
|
-
spacedWidth_arr.push(spacedWidth);
|
|
1713
|
-
spacedWidth = 0;
|
|
1714
|
-
currentWidth = 0;
|
|
1715
|
-
}
|
|
1716
|
-
}
|
|
1717
|
-
width_arr.push(currentWidth);
|
|
1718
|
-
spacedWidth_arr.push(spacedWidth);
|
|
1719
|
-
item.width = widths;
|
|
1720
|
-
}
|
|
1721
|
-
var leadLine = (function () {
|
|
1722
|
-
var max = 0, index = -1;
|
|
1723
|
-
for (var i = 0, l = spacedWidth_arr.length; i < l; i++) {
|
|
1724
|
-
var val = spacedWidth_arr[i];
|
|
1611
|
+
const { width_arr, spacedWidth_arr } = this._measureContent(comment);
|
|
1612
|
+
const leadLine = (function () {
|
|
1613
|
+
let max = 0, index = -1;
|
|
1614
|
+
for (let i = 0, l = spacedWidth_arr.length; i < l; i++) {
|
|
1615
|
+
const val = spacedWidth_arr[i];
|
|
1725
1616
|
if (val && max < val) {
|
|
1726
1617
|
max = val;
|
|
1727
1618
|
index = i;
|
|
1728
1619
|
}
|
|
1729
1620
|
}
|
|
1730
|
-
return { max
|
|
1621
|
+
return { max, index };
|
|
1731
1622
|
})();
|
|
1732
|
-
|
|
1623
|
+
const width = leadLine.max;
|
|
1733
1624
|
this.scaleX = leadLine.max / (width_arr[leadLine.index] || 1);
|
|
1734
|
-
|
|
1735
|
-
|
|
1625
|
+
const width_max = width * this.scale;
|
|
1626
|
+
const height = (comment.fontSize * comment.lineHeight * lineCount +
|
|
1736
1627
|
config.commentYPaddingTop[comment.resizedY ? "resized" : "default"]) *
|
|
1737
1628
|
this.scale;
|
|
1738
1629
|
if (comment.loc !== "naka") {
|
|
1739
|
-
|
|
1630
|
+
const widthLimit = getConfig(config.CommentStageSize, true)[comment.full ? "fullWidth" : "width"];
|
|
1740
1631
|
if (width_max > widthLimit && !comment.resizedX) {
|
|
1741
1632
|
comment.fontSize = configFontSize[comment.size].default;
|
|
1742
1633
|
comment.lineHeight = configLineHeight[comment.size].default;
|
|
@@ -1757,16 +1648,45 @@
|
|
|
1757
1648
|
resizedX: !!comment.resizedX,
|
|
1758
1649
|
resizedY: !!comment.resizedY,
|
|
1759
1650
|
};
|
|
1760
|
-
}
|
|
1761
|
-
|
|
1651
|
+
}
|
|
1652
|
+
_measureContent(comment) {
|
|
1653
|
+
const width_arr = [], spacedWidth_arr = [];
|
|
1654
|
+
let currentWidth = 0, spacedWidth = 0;
|
|
1655
|
+
for (const item of comment.content) {
|
|
1656
|
+
const lines = item.content.split("\n");
|
|
1657
|
+
const widths = [];
|
|
1658
|
+
this.context.font = parseFont(item.font || comment.font, comment.fontSize);
|
|
1659
|
+
for (let i = 0, n = lines.length; i < n; i++) {
|
|
1660
|
+
const value = lines[i];
|
|
1661
|
+
if (value === undefined)
|
|
1662
|
+
continue;
|
|
1663
|
+
const measure = this.context.measureText(value);
|
|
1664
|
+
currentWidth += measure.width;
|
|
1665
|
+
spacedWidth +=
|
|
1666
|
+
measure.width + Math.max(value.length - 1, 0) * config.letterSpacing;
|
|
1667
|
+
widths.push(measure.width);
|
|
1668
|
+
if (i < lines.length - 1) {
|
|
1669
|
+
width_arr.push(currentWidth);
|
|
1670
|
+
spacedWidth_arr.push(spacedWidth);
|
|
1671
|
+
spacedWidth = 0;
|
|
1672
|
+
currentWidth = 0;
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
width_arr.push(currentWidth);
|
|
1676
|
+
spacedWidth_arr.push(spacedWidth);
|
|
1677
|
+
item.width = widths;
|
|
1678
|
+
}
|
|
1679
|
+
return { width_arr, spacedWidth_arr };
|
|
1680
|
+
}
|
|
1681
|
+
_drawCollision(posX, posY, showCollision) {
|
|
1762
1682
|
if (showCollision) {
|
|
1763
1683
|
this.context.strokeStyle = "rgba(255,0,255,1)";
|
|
1764
1684
|
this.context.strokeRect(posX, posY, this.comment.width, this.comment.height);
|
|
1765
|
-
for (
|
|
1766
|
-
|
|
1685
|
+
for (let i = 0, n = this.comment.lineCount; i < n; i++) {
|
|
1686
|
+
const linePosY = ((i + 1) * (this.comment.fontSize * this.comment.lineHeight) +
|
|
1767
1687
|
config.commentYPaddingTop[this.comment.resizedY ? "resized" : "default"]) *
|
|
1768
1688
|
this.scale;
|
|
1769
|
-
this.context.strokeStyle =
|
|
1689
|
+
this.context.strokeStyle = `rgba(255,255,0,0.25)`;
|
|
1770
1690
|
this.context.strokeRect(posX, posY + linePosY * this._globalScale, this.comment.width, this.comment.fontSize *
|
|
1771
1691
|
this.comment.lineHeight *
|
|
1772
1692
|
-1 *
|
|
@@ -1775,9 +1695,9 @@
|
|
|
1775
1695
|
(this.comment.layer === -1 ? options.scale : 1));
|
|
1776
1696
|
}
|
|
1777
1697
|
}
|
|
1778
|
-
}
|
|
1779
|
-
|
|
1780
|
-
|
|
1698
|
+
}
|
|
1699
|
+
_generateTextImage() {
|
|
1700
|
+
const { image, context } = this.createCanvas();
|
|
1781
1701
|
image.width = this.comment.width;
|
|
1782
1702
|
image.height = this.comment.height;
|
|
1783
1703
|
context.strokeStyle = getStrokeColor(this.comment);
|
|
@@ -1786,29 +1706,29 @@
|
|
|
1786
1706
|
context.textBaseline = "alphabetic";
|
|
1787
1707
|
context.lineWidth = 4;
|
|
1788
1708
|
context.font = parseFont(this.comment.font, this.comment.fontSize);
|
|
1789
|
-
|
|
1709
|
+
const scale = this._globalScale *
|
|
1790
1710
|
this.scale *
|
|
1791
1711
|
(this.comment.layer === -1 ? options.scale : 1);
|
|
1792
1712
|
context.scale(scale * this.scaleX, scale);
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1713
|
+
const lineOffset = this.comment.lineOffset;
|
|
1714
|
+
const offsetKey = this.comment.resizedY ? "resized" : "default";
|
|
1715
|
+
const offsetY = config.commentYPaddingTop[offsetKey] +
|
|
1796
1716
|
this.comment.fontSize *
|
|
1797
1717
|
this.comment.lineHeight *
|
|
1798
1718
|
config.commentYOffset[this.comment.size][offsetKey];
|
|
1799
|
-
|
|
1800
|
-
for (
|
|
1801
|
-
|
|
1802
|
-
if (lastFont !==
|
|
1803
|
-
lastFont =
|
|
1804
|
-
context.font = parseFont(
|
|
1719
|
+
let lastFont = this.comment.font, leftOffset = 0, lineCount = 0;
|
|
1720
|
+
for (const item of this.comment.content) {
|
|
1721
|
+
const font = item.font || this.comment.font;
|
|
1722
|
+
if (lastFont !== font) {
|
|
1723
|
+
lastFont = font;
|
|
1724
|
+
context.font = parseFont(font, this.comment.fontSize);
|
|
1805
1725
|
}
|
|
1806
|
-
|
|
1807
|
-
for (
|
|
1808
|
-
|
|
1726
|
+
const lines = item.slicedContent;
|
|
1727
|
+
for (let j = 0, n = lines.length; j < n; j++) {
|
|
1728
|
+
const line = lines[j];
|
|
1809
1729
|
if (line === undefined)
|
|
1810
1730
|
continue;
|
|
1811
|
-
|
|
1731
|
+
const posY = (lineOffset + lineCount + 1) *
|
|
1812
1732
|
(this.comment.fontSize * this.comment.lineHeight) +
|
|
1813
1733
|
offsetY;
|
|
1814
1734
|
context.strokeText(line, leftOffset, posY);
|
|
@@ -1816,44 +1736,58 @@
|
|
|
1816
1736
|
if (j < n - 1) {
|
|
1817
1737
|
leftOffset = 0;
|
|
1818
1738
|
lineCount += 1;
|
|
1739
|
+
continue;
|
|
1819
1740
|
}
|
|
1820
|
-
|
|
1821
|
-
leftOffset += item.width[j] || 0;
|
|
1822
|
-
}
|
|
1741
|
+
leftOffset += item.width[j] || 0;
|
|
1823
1742
|
}
|
|
1824
1743
|
}
|
|
1825
1744
|
return image;
|
|
1826
|
-
}
|
|
1827
|
-
|
|
1828
|
-
}(BaseComment));
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1829
1747
|
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1748
|
+
class HTML5Comment extends BaseComment {
|
|
1749
|
+
pluginName = "HTML5Comment";
|
|
1750
|
+
constructor(comment, context) {
|
|
1751
|
+
super(comment, context);
|
|
1752
|
+
this.posY = 0;
|
|
1753
|
+
}
|
|
1754
|
+
get content() {
|
|
1755
|
+
return this.comment.rawContent;
|
|
1756
|
+
}
|
|
1757
|
+
set content(input) {
|
|
1758
|
+
const { content, lineCount, lineOffset } = this.parseContent(input);
|
|
1759
|
+
const comment = {
|
|
1760
|
+
...this.comment,
|
|
1761
|
+
rawContent: input,
|
|
1762
|
+
content,
|
|
1763
|
+
lineCount,
|
|
1764
|
+
lineOffset,
|
|
1765
|
+
};
|
|
1766
|
+
this.comment = this.getCommentSize(comment);
|
|
1767
|
+
this.cacheKey =
|
|
1768
|
+
JSON.stringify(this.comment.content) +
|
|
1769
|
+
`@@${this.pluginName}@@` +
|
|
1770
|
+
[...this.comment.mail].sort().join(",");
|
|
1771
|
+
delete this.image;
|
|
1772
|
+
}
|
|
1773
|
+
convertComment(comment) {
|
|
1839
1774
|
return this.getCommentSize(this.parseCommandAndNicoscript(comment));
|
|
1840
|
-
}
|
|
1841
|
-
|
|
1775
|
+
}
|
|
1776
|
+
getCommentSize(parsedData) {
|
|
1842
1777
|
this.context.font = parseFont(parsedData.font, parsedData.fontSize);
|
|
1843
|
-
|
|
1778
|
+
const size = parsedData;
|
|
1844
1779
|
if (parsedData.invisible) {
|
|
1845
1780
|
size.height = 0;
|
|
1846
1781
|
size.width = 0;
|
|
1847
1782
|
size.lineHeight = 0;
|
|
1848
1783
|
size.fontSize = 0;
|
|
1849
|
-
size.content = [];
|
|
1850
1784
|
size.resized = false;
|
|
1851
1785
|
size.resizedX = false;
|
|
1852
1786
|
size.resizedY = false;
|
|
1853
1787
|
size.charSize = 0;
|
|
1854
1788
|
return size;
|
|
1855
1789
|
}
|
|
1856
|
-
|
|
1790
|
+
const measure = this.measureText(parsedData);
|
|
1857
1791
|
if (options.scale !== 1 && size.layer === -1) {
|
|
1858
1792
|
measure.height *= options.scale;
|
|
1859
1793
|
measure.width *= options.scale;
|
|
@@ -1869,24 +1803,38 @@
|
|
|
1869
1803
|
size.resizedY = measure.resizedY;
|
|
1870
1804
|
size.charSize = measure.charSize;
|
|
1871
1805
|
return size;
|
|
1872
|
-
}
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1806
|
+
}
|
|
1807
|
+
parseCommandAndNicoscript(comment) {
|
|
1808
|
+
const data = parseCommandAndNicoScript(comment);
|
|
1809
|
+
const { content, lineCount, lineOffset } = this.parseContent(comment.content);
|
|
1810
|
+
return {
|
|
1811
|
+
...comment,
|
|
1812
|
+
rawContent: comment.content,
|
|
1813
|
+
...data,
|
|
1814
|
+
content,
|
|
1815
|
+
lineCount,
|
|
1816
|
+
lineOffset,
|
|
1817
|
+
};
|
|
1818
|
+
}
|
|
1819
|
+
parseContent(input) {
|
|
1820
|
+
const content = [];
|
|
1876
1821
|
content.push({
|
|
1877
|
-
content:
|
|
1878
|
-
slicedContent:
|
|
1822
|
+
content: input,
|
|
1823
|
+
slicedContent: input.split("\n"),
|
|
1879
1824
|
});
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
return pv + (((_a = val.content.match(/\n/g)) === null || _a === void 0 ? void 0 : _a.length) || 0);
|
|
1825
|
+
const lineCount = content.reduce((pv, val) => {
|
|
1826
|
+
return pv + (val.content.match(/\n/g)?.length || 0);
|
|
1883
1827
|
}, 1);
|
|
1884
|
-
|
|
1885
|
-
return
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1828
|
+
const lineOffset = 0;
|
|
1829
|
+
return {
|
|
1830
|
+
content,
|
|
1831
|
+
lineCount,
|
|
1832
|
+
lineOffset,
|
|
1833
|
+
};
|
|
1834
|
+
}
|
|
1835
|
+
measureText(comment) {
|
|
1836
|
+
const scale = getConfig(config.commentScale, false);
|
|
1837
|
+
const configFontSize = getConfig(config.fontSize, false), lineHeight = getLineHeight(comment.size, false), charSize = getCharSize(comment.size, false);
|
|
1890
1838
|
if (!comment.lineHeight)
|
|
1891
1839
|
comment.lineHeight = lineHeight;
|
|
1892
1840
|
if (!comment.charSize)
|
|
@@ -1895,15 +1843,15 @@
|
|
|
1895
1843
|
this.context.font = parseFont(comment.font, comment.fontSize);
|
|
1896
1844
|
if (isLineBreakResize(comment)) {
|
|
1897
1845
|
comment.fontSize = configFontSize[comment.size].resized;
|
|
1898
|
-
|
|
1899
|
-
comment.charSize = comment.charSize * (
|
|
1900
|
-
comment.lineHeight =
|
|
1846
|
+
const lineHeight = getLineHeight(comment.size, false, true);
|
|
1847
|
+
comment.charSize = comment.charSize * (lineHeight / comment.lineHeight);
|
|
1848
|
+
comment.lineHeight = lineHeight;
|
|
1901
1849
|
comment.resized = true;
|
|
1902
1850
|
comment.resizedY = true;
|
|
1903
1851
|
}
|
|
1904
|
-
|
|
1905
|
-
for (
|
|
1906
|
-
|
|
1852
|
+
const { width, height, itemWidth } = this._measureComment(comment);
|
|
1853
|
+
for (let i = 0, n = comment.content.length; i < n; i++) {
|
|
1854
|
+
const item = comment.content[i];
|
|
1907
1855
|
if (!item || !itemWidth)
|
|
1908
1856
|
continue;
|
|
1909
1857
|
item.width = itemWidth[i];
|
|
@@ -1920,29 +1868,29 @@
|
|
|
1920
1868
|
resizedY: !!comment.resizedY,
|
|
1921
1869
|
charSize: comment.charSize || 0,
|
|
1922
1870
|
};
|
|
1923
|
-
}
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1871
|
+
}
|
|
1872
|
+
_measureComment(comment) {
|
|
1873
|
+
const widthLimit = getConfig(config.CommentStageSize, false)[comment.full ? "fullWidth" : "width"];
|
|
1874
|
+
const measureResult = measure(comment, this.context);
|
|
1927
1875
|
if (comment.loc !== "naka" && measureResult.width > widthLimit) {
|
|
1928
1876
|
return this._processResizeX(comment, measureResult.width);
|
|
1929
1877
|
}
|
|
1930
1878
|
return measureResult;
|
|
1931
|
-
}
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1879
|
+
}
|
|
1880
|
+
_processResizeX(comment, width) {
|
|
1881
|
+
const widthLimit = getConfig(config.CommentStageSize, false)[comment.full ? "fullWidth" : "width"];
|
|
1882
|
+
const lineHeight = getLineHeight(comment.size, false);
|
|
1883
|
+
const charSize = getCharSize(comment.size, false);
|
|
1884
|
+
const scale = widthLimit / width;
|
|
1937
1885
|
comment.resizedX = true;
|
|
1938
|
-
|
|
1886
|
+
let _comment = { ...comment };
|
|
1939
1887
|
_comment.charSize = (_comment.charSize || 0) * scale;
|
|
1940
1888
|
_comment.lineHeight = (_comment.lineHeight || 0) * scale;
|
|
1941
1889
|
_comment.fontSize = _comment.charSize * 0.8;
|
|
1942
|
-
|
|
1890
|
+
let result = measure(_comment, this.context);
|
|
1943
1891
|
if (result.width > widthLimit) {
|
|
1944
1892
|
while (result.width >= widthLimit) {
|
|
1945
|
-
|
|
1893
|
+
const originalCharSize = _comment.charSize;
|
|
1946
1894
|
_comment.charSize -= 1;
|
|
1947
1895
|
_comment.lineHeight *= _comment.charSize / originalCharSize;
|
|
1948
1896
|
_comment.fontSize = _comment.charSize * 0.8;
|
|
@@ -1950,10 +1898,10 @@
|
|
|
1950
1898
|
}
|
|
1951
1899
|
}
|
|
1952
1900
|
else {
|
|
1953
|
-
|
|
1901
|
+
let lastComment = { ..._comment };
|
|
1954
1902
|
while (result.width < widthLimit) {
|
|
1955
|
-
lastComment =
|
|
1956
|
-
|
|
1903
|
+
lastComment = { ..._comment };
|
|
1904
|
+
const originalCharSize = _comment.charSize;
|
|
1957
1905
|
_comment.charSize += 1;
|
|
1958
1906
|
_comment.lineHeight *= _comment.charSize / originalCharSize;
|
|
1959
1907
|
_comment.fontSize = _comment.charSize * 0.8;
|
|
@@ -1962,9 +1910,9 @@
|
|
|
1962
1910
|
_comment = lastComment;
|
|
1963
1911
|
}
|
|
1964
1912
|
if (comment.resizedY) {
|
|
1965
|
-
|
|
1966
|
-
comment.charSize =
|
|
1967
|
-
comment.lineHeight =
|
|
1913
|
+
const scale = (_comment.charSize || 0) / (comment.charSize || 0);
|
|
1914
|
+
comment.charSize = scale * charSize;
|
|
1915
|
+
comment.lineHeight = scale * lineHeight;
|
|
1968
1916
|
}
|
|
1969
1917
|
else {
|
|
1970
1918
|
comment.charSize = _comment.charSize;
|
|
@@ -1972,31 +1920,29 @@
|
|
|
1972
1920
|
}
|
|
1973
1921
|
comment.fontSize = (comment.charSize || 0) * 0.8;
|
|
1974
1922
|
return measure(comment, this.context);
|
|
1975
|
-
}
|
|
1976
|
-
|
|
1977
|
-
var _a;
|
|
1923
|
+
}
|
|
1924
|
+
_drawCollision(posX, posY, showCollision) {
|
|
1978
1925
|
if (showCollision) {
|
|
1979
|
-
|
|
1926
|
+
const scale = getConfig(config.commentScale, false);
|
|
1980
1927
|
this.context.strokeStyle = "rgba(0,255,255,1)";
|
|
1981
1928
|
this.context.strokeRect(posX, posY, this.comment.width, this.comment.height);
|
|
1982
|
-
for (
|
|
1983
|
-
|
|
1929
|
+
for (let i = 0, n = this.comment.lineCount; i < n; i++) {
|
|
1930
|
+
const linePosY = (this.comment.lineHeight * (i + 1) +
|
|
1984
1931
|
(this.comment.charSize - this.comment.lineHeight) / 2 +
|
|
1985
1932
|
this.comment.lineHeight * -0.16 +
|
|
1986
|
-
(
|
|
1933
|
+
(config.fonts[this.comment.font]?.offset ||
|
|
1987
1934
|
0)) *
|
|
1988
1935
|
scale;
|
|
1989
1936
|
this.context.strokeStyle = "rgba(255,255,0,0.5)";
|
|
1990
1937
|
this.context.strokeRect(posX, posY + linePosY, this.comment.width, this.comment.fontSize * -1 * scale);
|
|
1991
1938
|
}
|
|
1992
1939
|
}
|
|
1993
|
-
}
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
var paddingTop = (10 - scale * 10) *
|
|
1940
|
+
}
|
|
1941
|
+
_generateTextImage() {
|
|
1942
|
+
const { fontSize, scale } = getFontSizeAndScale(this.comment.charSize);
|
|
1943
|
+
const paddingTop = (10 - scale * 10) *
|
|
1998
1944
|
((this.comment.lineCount + 1) / config.hiResCommentCorrection);
|
|
1999
|
-
|
|
1945
|
+
const { image, context } = this.createCanvas();
|
|
2000
1946
|
image.width = this.comment.width + 2 * 2 * this.comment.charSize;
|
|
2001
1947
|
image.height =
|
|
2002
1948
|
this.comment.height +
|
|
@@ -2007,22 +1953,21 @@
|
|
|
2007
1953
|
context.textBaseline = "alphabetic";
|
|
2008
1954
|
context.lineWidth = config.contextLineWidth;
|
|
2009
1955
|
context.font = parseFont(this.comment.font, fontSize);
|
|
2010
|
-
|
|
1956
|
+
const drawScale = getConfig(config.commentScale, false) *
|
|
2011
1957
|
scale *
|
|
2012
1958
|
(this.comment.layer === -1 ? options.scale : 1);
|
|
2013
1959
|
context.scale(drawScale, drawScale);
|
|
2014
|
-
|
|
2015
|
-
|
|
1960
|
+
let lineCount = 0;
|
|
1961
|
+
const offsetY = (this.comment.charSize - this.comment.lineHeight) / 2 +
|
|
2016
1962
|
this.comment.lineHeight * -0.16 +
|
|
2017
|
-
(
|
|
2018
|
-
for (
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
var line = lines[j];
|
|
1963
|
+
(config.fonts[this.comment.font]?.offset || 0);
|
|
1964
|
+
for (const item of this.comment.content) {
|
|
1965
|
+
const lines = item.slicedContent;
|
|
1966
|
+
for (let j = 0, n = lines.length; j < n; j++) {
|
|
1967
|
+
const line = lines[j];
|
|
2023
1968
|
if (line === undefined)
|
|
2024
1969
|
continue;
|
|
2025
|
-
|
|
1970
|
+
const posY = (this.comment.lineHeight * (lineCount + 1 + paddingTop) + offsetY) /
|
|
2026
1971
|
scale;
|
|
2027
1972
|
context.strokeText(line, 0, posY);
|
|
2028
1973
|
context.fillText(line, 0, posY);
|
|
@@ -2030,9 +1975,8 @@
|
|
|
2030
1975
|
}
|
|
2031
1976
|
}
|
|
2032
1977
|
return image;
|
|
2033
|
-
}
|
|
2034
|
-
|
|
2035
|
-
}(BaseComment));
|
|
1978
|
+
}
|
|
1979
|
+
}
|
|
2036
1980
|
|
|
2037
1981
|
var index = /*#__PURE__*/Object.freeze({
|
|
2038
1982
|
__proto__: null,
|
|
@@ -2041,16 +1985,16 @@
|
|
|
2041
1985
|
HTML5Comment: HTML5Comment
|
|
2042
1986
|
});
|
|
2043
1987
|
|
|
2044
|
-
|
|
2045
|
-
return fonts.reduce(
|
|
1988
|
+
const build = (fonts) => {
|
|
1989
|
+
return fonts.reduce((pv, val, index) => {
|
|
2046
1990
|
if (index === 0) {
|
|
2047
|
-
return
|
|
1991
|
+
return { ...val };
|
|
2048
1992
|
}
|
|
2049
|
-
pv.font +=
|
|
1993
|
+
pv.font += `, ${val.font}`;
|
|
2050
1994
|
return pv;
|
|
2051
1995
|
}, { font: "", offset: 0, weight: 600 });
|
|
2052
1996
|
};
|
|
2053
|
-
|
|
1997
|
+
const fontTemplates = {
|
|
2054
1998
|
arial: {
|
|
2055
1999
|
font: 'Arial, "MS Pゴシック", "MS PGothic", MSPGothic, MS-PGothic',
|
|
2056
2000
|
offset: 0.01,
|
|
@@ -2117,7 +2061,7 @@
|
|
|
2117
2061
|
weight: 400,
|
|
2118
2062
|
},
|
|
2119
2063
|
};
|
|
2120
|
-
|
|
2064
|
+
const fonts = {
|
|
2121
2065
|
win7: {
|
|
2122
2066
|
defont: build([fontTemplates.arial]),
|
|
2123
2067
|
gothic: build([
|
|
@@ -2185,23 +2129,23 @@
|
|
|
2185
2129
|
fonts: fonts
|
|
2186
2130
|
});
|
|
2187
2131
|
|
|
2188
|
-
|
|
2189
|
-
|
|
2132
|
+
const initConfig = () => {
|
|
2133
|
+
const platform = (function (ua) {
|
|
2190
2134
|
if (ua.match(/windows nt 6\.[12]/i))
|
|
2191
2135
|
return "win7";
|
|
2192
|
-
else if (ua.match(/windows nt (6\.3|10\.\d+)/i))
|
|
2136
|
+
else if (ua.match(/windows nt (6\.3|10\.\d+)|win32/i))
|
|
2193
2137
|
return "win8_1";
|
|
2194
2138
|
else if (ua.match(/windows nt/i))
|
|
2195
2139
|
return "win";
|
|
2196
2140
|
else if (ua.match(/mac os x 10(.|_)(9|10)/i))
|
|
2197
2141
|
return "mac10_9";
|
|
2198
|
-
else if (ua.match(/mac os x 10(.|_)\d{2}/i))
|
|
2142
|
+
else if (ua.match(/mac os x 10(.|_)\d{2}|darwin/i))
|
|
2199
2143
|
return "mac10_11";
|
|
2200
2144
|
else if (ua.match(/mac os x/i))
|
|
2201
2145
|
return "mac";
|
|
2202
2146
|
return "other";
|
|
2203
|
-
})(navigator.userAgent);
|
|
2204
|
-
|
|
2147
|
+
})(typeof navigator !== "undefined" ? navigator.userAgent : process.platform);
|
|
2148
|
+
const defaultConfig = {
|
|
2205
2149
|
colors: colors,
|
|
2206
2150
|
contextStrokeColor: "#000000",
|
|
2207
2151
|
contextStrokeInversionColor: "#FFFFFF",
|
|
@@ -2212,7 +2156,7 @@
|
|
|
2212
2156
|
html5: 1920 / 683,
|
|
2213
2157
|
flash: 1920 / 683,
|
|
2214
2158
|
},
|
|
2215
|
-
|
|
2159
|
+
CommentStageSize: {
|
|
2216
2160
|
html5: {
|
|
2217
2161
|
width: 512,
|
|
2218
2162
|
fullWidth: 683,
|
|
@@ -2296,8 +2240,8 @@
|
|
|
2296
2240
|
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]",
|
|
2297
2241
|
gothic: "[\u03fb\uff9f]",
|
|
2298
2242
|
},
|
|
2299
|
-
|
|
2300
|
-
|
|
2243
|
+
FlashMode: "vista",
|
|
2244
|
+
FlashScriptChar: {
|
|
2301
2245
|
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]",
|
|
2302
2246
|
sub: "[\u0320\u1d62-\u1d6a\u2080-\u208e\u2090-\u209c\u2c7c]",
|
|
2303
2247
|
},
|
|
@@ -2352,7 +2296,7 @@
|
|
|
2352
2296
|
condition: isFlashComment,
|
|
2353
2297
|
},
|
|
2354
2298
|
],
|
|
2355
|
-
nakaCommentSpeedOffset: 0.
|
|
2299
|
+
nakaCommentSpeedOffset: 0.95,
|
|
2356
2300
|
};
|
|
2357
2301
|
updateConfig(defaultConfig);
|
|
2358
2302
|
};
|
|
@@ -2362,43 +2306,38 @@
|
|
|
2362
2306
|
initConfig: initConfig
|
|
2363
2307
|
});
|
|
2364
2308
|
|
|
2365
|
-
|
|
2366
|
-
|
|
2309
|
+
let handlerList = [];
|
|
2310
|
+
const handlerCounts = {
|
|
2367
2311
|
seekDisable: 0,
|
|
2368
2312
|
seekEnable: 0,
|
|
2369
2313
|
commentDisable: 0,
|
|
2370
2314
|
commentEnable: 0,
|
|
2371
2315
|
jump: 0,
|
|
2372
2316
|
};
|
|
2373
|
-
|
|
2374
|
-
handlerList.push({ eventName
|
|
2317
|
+
const registerHandler = (eventName, handler) => {
|
|
2318
|
+
handlerList.push({ eventName, handler });
|
|
2375
2319
|
updateEventHandlerCounts();
|
|
2376
2320
|
};
|
|
2377
|
-
|
|
2378
|
-
handlerList = handlerList.filter(
|
|
2321
|
+
const removeHandler = (eventName, handler) => {
|
|
2322
|
+
handlerList = handlerList.filter((item) => item.eventName !== eventName || item.handler !== handler);
|
|
2379
2323
|
updateEventHandlerCounts();
|
|
2380
2324
|
};
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
handlerCounts[key] = handlerList.filter(
|
|
2385
|
-
};
|
|
2386
|
-
for (var _i = 0, _a = Object.keys(handlerCounts); _i < _a.length; _i++) {
|
|
2387
|
-
var key_ = _a[_i];
|
|
2388
|
-
_loop_1(key_);
|
|
2325
|
+
const updateEventHandlerCounts = () => {
|
|
2326
|
+
for (const key_ of Object.keys(handlerCounts)) {
|
|
2327
|
+
const key = key_;
|
|
2328
|
+
handlerCounts[key] = handlerList.filter((item) => item.eventName === key).length;
|
|
2389
2329
|
}
|
|
2390
2330
|
};
|
|
2391
|
-
|
|
2331
|
+
const triggerHandler = (vpos, lastVpos) => {
|
|
2392
2332
|
processCommentDisableScript(vpos, lastVpos);
|
|
2393
2333
|
processSeekDisableScript(vpos, lastVpos);
|
|
2394
2334
|
processJumpScript(vpos, lastVpos);
|
|
2395
2335
|
};
|
|
2396
|
-
|
|
2336
|
+
const processCommentDisableScript = (vpos, lastVpos) => {
|
|
2397
2337
|
if (handlerCounts.commentDisable < 1 && handlerCounts.commentEnable < 1)
|
|
2398
2338
|
return;
|
|
2399
|
-
for (
|
|
2400
|
-
|
|
2401
|
-
var vposInRange = range.start < vpos && vpos < range.end, lastVposInRange = range.start < lastVpos && lastVpos < range.end;
|
|
2339
|
+
for (const range of nicoScripts.ban) {
|
|
2340
|
+
const vposInRange = range.start < vpos && vpos < range.end, lastVposInRange = range.start < lastVpos && lastVpos < range.end;
|
|
2402
2341
|
if (vposInRange && !lastVposInRange) {
|
|
2403
2342
|
executeEvents("commentDisable", {
|
|
2404
2343
|
type: "commentDisable",
|
|
@@ -2415,12 +2354,11 @@
|
|
|
2415
2354
|
}
|
|
2416
2355
|
}
|
|
2417
2356
|
};
|
|
2418
|
-
|
|
2357
|
+
const processSeekDisableScript = (vpos, lastVpos) => {
|
|
2419
2358
|
if (handlerCounts.seekDisable < 1 && handlerCounts.seekEnable < 1)
|
|
2420
2359
|
return;
|
|
2421
|
-
for (
|
|
2422
|
-
|
|
2423
|
-
var vposInRange = range.start < vpos && vpos < range.end, lastVposInRange = range.start < lastVpos && lastVpos < range.end;
|
|
2360
|
+
for (const range of nicoScripts.seekDisable) {
|
|
2361
|
+
const vposInRange = range.start < vpos && vpos < range.end, lastVposInRange = range.start < lastVpos && lastVpos < range.end;
|
|
2424
2362
|
if (vposInRange && !lastVposInRange) {
|
|
2425
2363
|
executeEvents("seekDisable", {
|
|
2426
2364
|
type: "seekDisable",
|
|
@@ -2437,12 +2375,11 @@
|
|
|
2437
2375
|
}
|
|
2438
2376
|
}
|
|
2439
2377
|
};
|
|
2440
|
-
|
|
2378
|
+
const processJumpScript = (vpos, lastVpos) => {
|
|
2441
2379
|
if (handlerCounts.jump < 1)
|
|
2442
2380
|
return;
|
|
2443
|
-
for (
|
|
2444
|
-
|
|
2445
|
-
var vposInRange = range.start < vpos && (!range.end || vpos < range.end), lastVposInRange = range.start < lastVpos && (!range.end || lastVpos < range.end);
|
|
2381
|
+
for (const range of nicoScripts.jump) {
|
|
2382
|
+
const vposInRange = range.start < vpos && (!range.end || vpos < range.end), lastVposInRange = range.start < lastVpos && (!range.end || lastVpos < range.end);
|
|
2446
2383
|
if (vposInRange && !lastVposInRange) {
|
|
2447
2384
|
executeEvents("jump", {
|
|
2448
2385
|
type: "jump",
|
|
@@ -2454,9 +2391,8 @@
|
|
|
2454
2391
|
}
|
|
2455
2392
|
}
|
|
2456
2393
|
};
|
|
2457
|
-
|
|
2458
|
-
for (
|
|
2459
|
-
var item = handlerList_1[_i];
|
|
2394
|
+
const executeEvents = (eventName, event) => {
|
|
2395
|
+
for (const item of handlerList) {
|
|
2460
2396
|
if (eventName !== item.eventName)
|
|
2461
2397
|
continue;
|
|
2462
2398
|
item.handler(event);
|
|
@@ -2470,8 +2406,8 @@
|
|
|
2470
2406
|
triggerHandler: triggerHandler
|
|
2471
2407
|
});
|
|
2472
2408
|
|
|
2473
|
-
|
|
2474
|
-
|
|
2409
|
+
const convert2formattedComment = (data, type) => {
|
|
2410
|
+
let result = [];
|
|
2475
2411
|
if (type === "empty" && data === undefined) {
|
|
2476
2412
|
return [];
|
|
2477
2413
|
}
|
|
@@ -2499,15 +2435,13 @@
|
|
|
2499
2435
|
}
|
|
2500
2436
|
return sort(result);
|
|
2501
2437
|
};
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
for (var _i = 0, _b = Array.from(data.documentElement.children); _i < _b.length; _i++) {
|
|
2507
|
-
var item = _b[_i];
|
|
2438
|
+
const fromXMLDocument = (data) => {
|
|
2439
|
+
const data_ = [], userList = [];
|
|
2440
|
+
let index = Array.from(data.documentElement.children).length;
|
|
2441
|
+
for (const item of Array.from(data.documentElement.children)) {
|
|
2508
2442
|
if (item.nodeName !== "chat")
|
|
2509
2443
|
continue;
|
|
2510
|
-
|
|
2444
|
+
const tmpParam = {
|
|
2511
2445
|
id: Number(item.getAttribute("no")) || index++,
|
|
2512
2446
|
vpos: Number(item.getAttribute("vpos")),
|
|
2513
2447
|
content: item.innerHTML,
|
|
@@ -2520,13 +2454,13 @@
|
|
|
2520
2454
|
layer: -1,
|
|
2521
2455
|
};
|
|
2522
2456
|
if (item.getAttribute("mail")) {
|
|
2523
|
-
tmpParam.mail =
|
|
2457
|
+
tmpParam.mail = item.getAttribute("mail")?.split(/\s+/g) || [];
|
|
2524
2458
|
}
|
|
2525
2459
|
if (tmpParam.content.startsWith("/") && tmpParam.owner) {
|
|
2526
2460
|
tmpParam.mail.push("invisible");
|
|
2527
2461
|
}
|
|
2528
|
-
|
|
2529
|
-
|
|
2462
|
+
const userId = item.getAttribute("user_id") || "";
|
|
2463
|
+
const isUserExist = userList.indexOf(userId);
|
|
2530
2464
|
if (isUserExist === -1) {
|
|
2531
2465
|
tmpParam.user_id = userList.length;
|
|
2532
2466
|
userList.push(userId);
|
|
@@ -2538,11 +2472,10 @@
|
|
|
2538
2472
|
}
|
|
2539
2473
|
return data_;
|
|
2540
2474
|
};
|
|
2541
|
-
|
|
2542
|
-
|
|
2475
|
+
const fromFormatted = (data) => {
|
|
2476
|
+
const tmpData = data;
|
|
2543
2477
|
if (!typeGuard.formatted.comments(data)) {
|
|
2544
|
-
for (
|
|
2545
|
-
var item = tmpData_1[_i];
|
|
2478
|
+
for (const item of tmpData) {
|
|
2546
2479
|
item.layer = -1;
|
|
2547
2480
|
item.user_id = 0;
|
|
2548
2481
|
if (!item.date_usec)
|
|
@@ -2551,15 +2484,14 @@
|
|
|
2551
2484
|
}
|
|
2552
2485
|
return tmpData;
|
|
2553
2486
|
};
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
for (
|
|
2557
|
-
var val = data_1[_i];
|
|
2487
|
+
const fromLegacy = (data) => {
|
|
2488
|
+
const data_ = [], userList = [];
|
|
2489
|
+
for (const val of data) {
|
|
2558
2490
|
if (!typeGuard.legacy.apiChat(val.chat))
|
|
2559
2491
|
continue;
|
|
2560
|
-
|
|
2492
|
+
const value = val.chat;
|
|
2561
2493
|
if (value.deleted !== 1) {
|
|
2562
|
-
|
|
2494
|
+
const tmpParam = {
|
|
2563
2495
|
id: value.no,
|
|
2564
2496
|
vpos: value.vpos,
|
|
2565
2497
|
content: value.content || "",
|
|
@@ -2577,7 +2509,7 @@
|
|
|
2577
2509
|
if (value.content.startsWith("/") && !value.user_id) {
|
|
2578
2510
|
tmpParam.mail.push("invisible");
|
|
2579
2511
|
}
|
|
2580
|
-
|
|
2512
|
+
const isUserExist = userList.indexOf(value.user_id);
|
|
2581
2513
|
if (isUserExist === -1) {
|
|
2582
2514
|
tmpParam.user_id = userList.length;
|
|
2583
2515
|
userList.push(value.user_id);
|
|
@@ -2590,22 +2522,22 @@
|
|
|
2590
2522
|
}
|
|
2591
2523
|
return data_;
|
|
2592
2524
|
};
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
for (
|
|
2596
|
-
|
|
2525
|
+
const fromLegacyOwner = (data) => {
|
|
2526
|
+
const data_ = [], comments = data.split("\n");
|
|
2527
|
+
for (let i = 0, n = comments.length; i < n; i++) {
|
|
2528
|
+
const value = comments[i];
|
|
2597
2529
|
if (!value)
|
|
2598
2530
|
continue;
|
|
2599
|
-
|
|
2531
|
+
const commentData = value.split(":");
|
|
2600
2532
|
if (commentData.length < 3) {
|
|
2601
2533
|
continue;
|
|
2602
2534
|
}
|
|
2603
2535
|
else if (commentData.length > 3) {
|
|
2604
|
-
for (
|
|
2605
|
-
commentData[2] +=
|
|
2536
|
+
for (let j = 3, n = commentData.length; j < n; j++) {
|
|
2537
|
+
commentData[2] += `:${commentData[j]}`;
|
|
2606
2538
|
}
|
|
2607
2539
|
}
|
|
2608
|
-
|
|
2540
|
+
const tmpParam = {
|
|
2609
2541
|
id: i,
|
|
2610
2542
|
vpos: Number(commentData[0]),
|
|
2611
2543
|
content: commentData[2] || "",
|
|
@@ -2627,13 +2559,13 @@
|
|
|
2627
2559
|
}
|
|
2628
2560
|
return data_;
|
|
2629
2561
|
};
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
for (
|
|
2633
|
-
|
|
2562
|
+
const fromOwner = (data) => {
|
|
2563
|
+
const data_ = [];
|
|
2564
|
+
for (let i = 0, n = data.length; i < n; i++) {
|
|
2565
|
+
const value = data[i];
|
|
2634
2566
|
if (!value)
|
|
2635
2567
|
continue;
|
|
2636
|
-
|
|
2568
|
+
const tmpParam = {
|
|
2637
2569
|
id: i,
|
|
2638
2570
|
vpos: time2vpos(value.time),
|
|
2639
2571
|
content: value.comment,
|
|
@@ -2655,14 +2587,12 @@
|
|
|
2655
2587
|
}
|
|
2656
2588
|
return data_;
|
|
2657
2589
|
};
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
for (
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
var value = val_1[_a];
|
|
2665
|
-
var tmpParam = {
|
|
2590
|
+
const fromV1 = (data) => {
|
|
2591
|
+
const data_ = [], userList = [];
|
|
2592
|
+
for (const item of data) {
|
|
2593
|
+
const val = item.comments, forkName = item.fork;
|
|
2594
|
+
for (const value of val) {
|
|
2595
|
+
const tmpParam = {
|
|
2666
2596
|
id: value.no,
|
|
2667
2597
|
vpos: Math.floor(value.vposMs / 10),
|
|
2668
2598
|
content: value.body,
|
|
@@ -2677,7 +2607,7 @@
|
|
|
2677
2607
|
if (tmpParam.content.startsWith("/") && tmpParam.owner) {
|
|
2678
2608
|
tmpParam.mail.push("invisible");
|
|
2679
2609
|
}
|
|
2680
|
-
|
|
2610
|
+
const isUserExist = userList.indexOf(value.userId);
|
|
2681
2611
|
if (isUserExist === -1) {
|
|
2682
2612
|
tmpParam.user_id = userList.length;
|
|
2683
2613
|
userList.push(value.userId);
|
|
@@ -2690,8 +2620,8 @@
|
|
|
2690
2620
|
}
|
|
2691
2621
|
return data_;
|
|
2692
2622
|
};
|
|
2693
|
-
|
|
2694
|
-
data.sort(
|
|
2623
|
+
const sort = (data) => {
|
|
2624
|
+
data.sort((a, b) => {
|
|
2695
2625
|
if (a.vpos < b.vpos)
|
|
2696
2626
|
return -1;
|
|
2697
2627
|
if (a.vpos > b.vpos)
|
|
@@ -2708,8 +2638,8 @@
|
|
|
2708
2638
|
});
|
|
2709
2639
|
return data;
|
|
2710
2640
|
};
|
|
2711
|
-
|
|
2712
|
-
|
|
2641
|
+
const time2vpos = (time_str) => {
|
|
2642
|
+
const time = time_str.match(/^(?:(\d+):(\d+)\.(\d+)|(\d+):(\d+)|(\d+)\.(\d+)|(\d+))$/);
|
|
2713
2643
|
if (time) {
|
|
2714
2644
|
if (time[1] !== undefined &&
|
|
2715
2645
|
time[2] !== undefined &&
|
|
@@ -2730,18 +2660,15 @@
|
|
|
2730
2660
|
}
|
|
2731
2661
|
return 0;
|
|
2732
2662
|
};
|
|
2733
|
-
|
|
2734
|
-
return Math.floor(new Date(date).getTime() / 1000);
|
|
2735
|
-
};
|
|
2663
|
+
const date2time = (date) => Math.floor(new Date(date).getTime() / 1000);
|
|
2736
2664
|
|
|
2737
2665
|
var inputParser = /*#__PURE__*/Object.freeze({
|
|
2738
2666
|
__proto__: null,
|
|
2739
2667
|
default: convert2formattedComment
|
|
2740
2668
|
});
|
|
2741
2669
|
|
|
2742
|
-
|
|
2743
|
-
for (
|
|
2744
|
-
var plugin = _a[_i];
|
|
2670
|
+
const createCommentInstance = (comment, context) => {
|
|
2671
|
+
for (const plugin of config.commentPlugins) {
|
|
2745
2672
|
if (plugin.condition(comment)) {
|
|
2746
2673
|
return new plugin.class(comment, context);
|
|
2747
2674
|
}
|
|
@@ -2749,7 +2676,7 @@
|
|
|
2749
2676
|
return new HTML5Comment(comment, context);
|
|
2750
2677
|
};
|
|
2751
2678
|
|
|
2752
|
-
|
|
2679
|
+
const definition = {
|
|
2753
2680
|
colors: colors$1,
|
|
2754
2681
|
config: config$1,
|
|
2755
2682
|
fonts: fonts$1,
|
|
@@ -2768,11 +2695,27 @@
|
|
|
2768
2695
|
utils: index$1
|
|
2769
2696
|
});
|
|
2770
2697
|
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2698
|
+
let isDebug = false;
|
|
2699
|
+
class NiconiComments {
|
|
2700
|
+
enableLegacyPiP;
|
|
2701
|
+
showCollision;
|
|
2702
|
+
showFPS;
|
|
2703
|
+
showCommentCount;
|
|
2704
|
+
video;
|
|
2705
|
+
lastVpos;
|
|
2706
|
+
canvas;
|
|
2707
|
+
collision;
|
|
2708
|
+
context;
|
|
2709
|
+
timeline;
|
|
2710
|
+
static typeGuard = typeGuard;
|
|
2711
|
+
static default = NiconiComments;
|
|
2712
|
+
static FlashComment = {
|
|
2713
|
+
condition: isFlashComment,
|
|
2714
|
+
class: FlashComment,
|
|
2715
|
+
};
|
|
2716
|
+
static internal = internal;
|
|
2717
|
+
constructor(canvas, data, initOptions = {}) {
|
|
2718
|
+
const constructorStart = performance.now();
|
|
2776
2719
|
initConfig();
|
|
2777
2720
|
if (!typeGuard.config.initOptions(initOptions))
|
|
2778
2721
|
throw new InvalidOptionError();
|
|
@@ -2782,15 +2725,12 @@
|
|
|
2782
2725
|
resetImageCache();
|
|
2783
2726
|
resetNicoScripts();
|
|
2784
2727
|
this.canvas = canvas;
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
throw new CanvasRenderingContext2DError();
|
|
2788
|
-
this.context = context;
|
|
2789
|
-
this.context.strokeStyle = "rgba(".concat(hex2rgb(config.contextStrokeColor).join(","), ",").concat(config.contextStrokeOpacity, ")");
|
|
2728
|
+
this.context = getContext(canvas);
|
|
2729
|
+
this.context.strokeStyle = `rgba(${hex2rgb(config.contextStrokeColor).join(",")},${config.contextStrokeOpacity})`;
|
|
2790
2730
|
this.context.textAlign = "start";
|
|
2791
2731
|
this.context.textBaseline = "alphabetic";
|
|
2792
2732
|
this.context.lineWidth = config.contextLineWidth;
|
|
2793
|
-
|
|
2733
|
+
let formatType = options.format;
|
|
2794
2734
|
if (options.formatted) {
|
|
2795
2735
|
console.warn("Deprecated: options.formatted is no longer recommended. Please use options.format. https://xpadev-net.github.io/niconicomments/#p_format");
|
|
2796
2736
|
}
|
|
@@ -2803,39 +2743,47 @@
|
|
|
2803
2743
|
if (options.mode === "default" && options.useLegacy) {
|
|
2804
2744
|
options.mode = "html5";
|
|
2805
2745
|
}
|
|
2806
|
-
|
|
2807
|
-
setPlugins(config.plugins.map(function (val) { return new val(canvas, parsedData); }));
|
|
2746
|
+
const parsedData = convert2formattedComment(data, formatType);
|
|
2808
2747
|
this.video = options.video || undefined;
|
|
2809
2748
|
this.showCollision = options.showCollision;
|
|
2810
2749
|
this.showFPS = options.showFPS;
|
|
2811
2750
|
this.showCommentCount = options.showCommentCount;
|
|
2812
2751
|
this.enableLegacyPiP = options.enableLegacyPiP;
|
|
2813
2752
|
this.timeline = {};
|
|
2814
|
-
this.collision = ["ue", "shita", "right", "left"].reduce(
|
|
2753
|
+
this.collision = ["ue", "shita", "right", "left"].reduce((pv, value) => {
|
|
2815
2754
|
pv[value] = [];
|
|
2816
2755
|
return pv;
|
|
2817
2756
|
}, {});
|
|
2818
2757
|
this.lastVpos = -1;
|
|
2819
2758
|
this.preRendering(parsedData);
|
|
2820
|
-
logger(
|
|
2759
|
+
logger(`constructor complete: ${performance.now() - constructorStart}ms`);
|
|
2821
2760
|
}
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
var preRenderingStart = performance.now();
|
|
2761
|
+
preRendering(rawData) {
|
|
2762
|
+
const preRenderingStart = performance.now();
|
|
2825
2763
|
if (options.keepCA) {
|
|
2826
2764
|
rawData = changeCALayer(rawData);
|
|
2827
2765
|
}
|
|
2828
|
-
|
|
2829
|
-
pv.push(createCommentInstance(val,
|
|
2766
|
+
const instances = rawData.reduce((pv, val) => {
|
|
2767
|
+
pv.push(createCommentInstance(val, this.context));
|
|
2830
2768
|
return pv;
|
|
2831
|
-
}, [])
|
|
2769
|
+
}, []);
|
|
2770
|
+
this.getCommentPos(instances);
|
|
2832
2771
|
this.sortComment();
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2772
|
+
const plugins = [];
|
|
2773
|
+
for (const plugin of config.plugins) {
|
|
2774
|
+
try {
|
|
2775
|
+
plugins.push(new plugin(this.canvas, instances));
|
|
2776
|
+
}
|
|
2777
|
+
catch (e) {
|
|
2778
|
+
console.error("Failed to init plugin");
|
|
2779
|
+
}
|
|
2780
|
+
}
|
|
2781
|
+
setPlugins(plugins);
|
|
2782
|
+
logger(`preRendering complete: ${performance.now() - preRenderingStart}ms`);
|
|
2783
|
+
}
|
|
2784
|
+
getCommentPos(data) {
|
|
2785
|
+
const getCommentPosStart = performance.now();
|
|
2786
|
+
for (const comment of data) {
|
|
2839
2787
|
if (comment.invisible)
|
|
2840
2788
|
continue;
|
|
2841
2789
|
if (comment.loc === "naka") {
|
|
@@ -2845,19 +2793,17 @@
|
|
|
2845
2793
|
processFixedComment(comment, this.collision[comment.loc], this.timeline);
|
|
2846
2794
|
}
|
|
2847
2795
|
}
|
|
2848
|
-
logger(
|
|
2849
|
-
}
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
for (
|
|
2853
|
-
|
|
2854
|
-
var item = this.timeline[Number(vpos)];
|
|
2796
|
+
logger(`getCommentPos complete: ${performance.now() - getCommentPosStart}ms`);
|
|
2797
|
+
}
|
|
2798
|
+
sortComment() {
|
|
2799
|
+
const sortCommentStart = performance.now();
|
|
2800
|
+
for (const vpos of Object.keys(this.timeline)) {
|
|
2801
|
+
const item = this.timeline[Number(vpos)];
|
|
2855
2802
|
if (!item)
|
|
2856
2803
|
continue;
|
|
2857
|
-
|
|
2858
|
-
for (
|
|
2859
|
-
|
|
2860
|
-
if (comment === null || comment === void 0 ? void 0 : comment.owner) {
|
|
2804
|
+
const owner = [], user = [];
|
|
2805
|
+
for (const comment of item) {
|
|
2806
|
+
if (comment?.owner) {
|
|
2861
2807
|
owner.push(comment);
|
|
2862
2808
|
}
|
|
2863
2809
|
else {
|
|
@@ -2866,24 +2812,22 @@
|
|
|
2866
2812
|
}
|
|
2867
2813
|
this.timeline[Number(vpos)] = user.concat(owner);
|
|
2868
2814
|
}
|
|
2869
|
-
logger(
|
|
2870
|
-
}
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2875
|
-
rawComments[_i] = arguments[_i];
|
|
2876
|
-
}
|
|
2877
|
-
for (var _a = 0, plugins_1 = plugins; _a < plugins_1.length; _a++) {
|
|
2878
|
-
var plugin = plugins_1[_a];
|
|
2879
|
-
plugin.addComments(rawComments);
|
|
2880
|
-
}
|
|
2881
|
-
var comments = rawComments.reduce(function (pv, val) {
|
|
2882
|
-
pv.push(createCommentInstance(val, _this.context));
|
|
2815
|
+
logger(`parseData complete: ${performance.now() - sortCommentStart}ms`);
|
|
2816
|
+
}
|
|
2817
|
+
addComments(...rawComments) {
|
|
2818
|
+
const comments = rawComments.reduce((pv, val) => {
|
|
2819
|
+
pv.push(createCommentInstance(val, this.context));
|
|
2883
2820
|
return pv;
|
|
2884
2821
|
}, []);
|
|
2885
|
-
for (
|
|
2886
|
-
|
|
2822
|
+
for (const plugin of plugins) {
|
|
2823
|
+
try {
|
|
2824
|
+
plugin.addComments(comments);
|
|
2825
|
+
}
|
|
2826
|
+
catch (e) {
|
|
2827
|
+
console.error("Failed to add comments");
|
|
2828
|
+
}
|
|
2829
|
+
}
|
|
2830
|
+
for (const comment of comments) {
|
|
2887
2831
|
if (comment.invisible)
|
|
2888
2832
|
continue;
|
|
2889
2833
|
if (comment.loc === "naka") {
|
|
@@ -2893,19 +2837,19 @@
|
|
|
2893
2837
|
processFixedComment(comment, this.collision[comment.loc], this.timeline);
|
|
2894
2838
|
}
|
|
2895
2839
|
}
|
|
2896
|
-
}
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
if (forceRendering === void 0) { forceRendering = false; }
|
|
2900
|
-
var drawCanvasStart = performance.now();
|
|
2840
|
+
}
|
|
2841
|
+
drawCanvas(vpos, forceRendering = false) {
|
|
2842
|
+
const drawCanvasStart = performance.now();
|
|
2901
2843
|
if (this.lastVpos === vpos && !forceRendering)
|
|
2902
2844
|
return false;
|
|
2903
2845
|
triggerHandler(vpos, this.lastVpos);
|
|
2904
|
-
|
|
2846
|
+
const timelineRange = this.timeline[vpos];
|
|
2905
2847
|
if (!forceRendering &&
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2848
|
+
plugins.length === 0 &&
|
|
2849
|
+
timelineRange?.filter((item) => item.loc === "naka").length === 0 &&
|
|
2850
|
+
this.timeline[this.lastVpos]?.filter((item) => item.loc === "naka")
|
|
2851
|
+
?.length === 0) {
|
|
2852
|
+
const current = timelineRange.filter((item) => item.loc !== "naka"), last = this.timeline[this.lastVpos]?.filter((item) => item.loc !== "naka") ||
|
|
2909
2853
|
[];
|
|
2910
2854
|
if (ArrayEqual(current, last))
|
|
2911
2855
|
return false;
|
|
@@ -2915,32 +2859,36 @@
|
|
|
2915
2859
|
this._drawVideo();
|
|
2916
2860
|
this._drawCollision(vpos);
|
|
2917
2861
|
this._drawComments(timelineRange, vpos);
|
|
2918
|
-
for (
|
|
2919
|
-
|
|
2920
|
-
|
|
2862
|
+
for (const plugin of plugins) {
|
|
2863
|
+
try {
|
|
2864
|
+
plugin.draw(vpos);
|
|
2865
|
+
}
|
|
2866
|
+
catch (e) {
|
|
2867
|
+
console.error(`Failed to draw comments`);
|
|
2868
|
+
}
|
|
2921
2869
|
}
|
|
2922
2870
|
this._drawFPS(drawCanvasStart);
|
|
2923
|
-
this._drawCommentCount(timelineRange
|
|
2924
|
-
logger(
|
|
2871
|
+
this._drawCommentCount(timelineRange?.length);
|
|
2872
|
+
logger(`drawCanvas complete: ${performance.now() - drawCanvasStart}ms`);
|
|
2925
2873
|
return true;
|
|
2926
|
-
}
|
|
2927
|
-
|
|
2928
|
-
if (this.video) {
|
|
2929
|
-
|
|
2930
|
-
|
|
2874
|
+
}
|
|
2875
|
+
_drawVideo() {
|
|
2876
|
+
if (this.video && !typeGuard.canvas.nodeContext(this.context)) {
|
|
2877
|
+
let scale;
|
|
2878
|
+
const height = this.canvas.height / this.video.videoHeight, width = this.canvas.width / this.video.videoWidth;
|
|
2931
2879
|
if (this.enableLegacyPiP ? height > width : height < width) {
|
|
2932
2880
|
scale = width;
|
|
2933
2881
|
}
|
|
2934
2882
|
else {
|
|
2935
2883
|
scale = height;
|
|
2936
2884
|
}
|
|
2937
|
-
|
|
2885
|
+
const offsetX = (this.canvas.width - this.video.videoWidth * scale) * 0.5, offsetY = (this.canvas.height - this.video.videoHeight * scale) * 0.5;
|
|
2938
2886
|
this.context.drawImage(this.video, offsetX, offsetY, this.video.videoWidth * scale, this.video.videoHeight * scale);
|
|
2939
2887
|
}
|
|
2940
|
-
}
|
|
2941
|
-
|
|
2888
|
+
}
|
|
2889
|
+
_drawComments(timelineRange, vpos) {
|
|
2942
2890
|
if (timelineRange) {
|
|
2943
|
-
|
|
2891
|
+
const targetComment = (() => {
|
|
2944
2892
|
if (config.commentLimit === undefined) {
|
|
2945
2893
|
return timelineRange;
|
|
2946
2894
|
}
|
|
@@ -2949,72 +2897,61 @@
|
|
|
2949
2897
|
}
|
|
2950
2898
|
return timelineRange.slice(0, config.commentLimit);
|
|
2951
2899
|
})();
|
|
2952
|
-
for (
|
|
2953
|
-
var comment = targetComment_1[_i];
|
|
2900
|
+
for (const comment of targetComment) {
|
|
2954
2901
|
if (comment.invisible) {
|
|
2955
2902
|
continue;
|
|
2956
2903
|
}
|
|
2957
2904
|
comment.draw(vpos, this.showCollision, isDebug);
|
|
2958
2905
|
}
|
|
2959
2906
|
}
|
|
2960
|
-
}
|
|
2961
|
-
|
|
2907
|
+
}
|
|
2908
|
+
_drawCollision(vpos) {
|
|
2962
2909
|
if (this.showCollision) {
|
|
2963
|
-
|
|
2910
|
+
const leftCollision = this.collision.left[vpos], rightCollision = this.collision.right[vpos];
|
|
2964
2911
|
this.context.fillStyle = "red";
|
|
2965
2912
|
if (leftCollision) {
|
|
2966
|
-
for (
|
|
2967
|
-
var comment = leftCollision_1[_i];
|
|
2913
|
+
for (const comment of leftCollision) {
|
|
2968
2914
|
this.context.fillRect(config.collisionRange.left, comment.posY, config.contextLineWidth, comment.height);
|
|
2969
2915
|
}
|
|
2970
2916
|
}
|
|
2971
2917
|
if (rightCollision) {
|
|
2972
|
-
for (
|
|
2973
|
-
var comment = rightCollision_1[_a];
|
|
2918
|
+
for (const comment of rightCollision) {
|
|
2974
2919
|
this.context.fillRect(config.collisionRange.right, comment.posY, config.contextLineWidth * -1, comment.height);
|
|
2975
2920
|
}
|
|
2976
2921
|
}
|
|
2977
2922
|
}
|
|
2978
|
-
}
|
|
2979
|
-
|
|
2923
|
+
}
|
|
2924
|
+
_drawFPS(drawCanvasStart) {
|
|
2980
2925
|
if (this.showFPS) {
|
|
2981
2926
|
this.context.font = parseFont("defont", 60);
|
|
2982
2927
|
this.context.fillStyle = "#00FF00";
|
|
2983
|
-
this.context.strokeStyle =
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
this.context.strokeText(
|
|
2987
|
-
this.context.fillText(
|
|
2928
|
+
this.context.strokeStyle = `rgba(${hex2rgb(config.contextStrokeColor).join(",")},${config.contextStrokeOpacity})`;
|
|
2929
|
+
const drawTime = Math.floor(performance.now() - drawCanvasStart);
|
|
2930
|
+
const fps = Math.floor(1000 / (drawTime === 0 ? 1 : drawTime));
|
|
2931
|
+
this.context.strokeText(`FPS:${fps}(${drawTime}ms)`, 100, 100);
|
|
2932
|
+
this.context.fillText(`FPS:${fps}(${drawTime}ms)`, 100, 100);
|
|
2988
2933
|
}
|
|
2989
|
-
}
|
|
2990
|
-
|
|
2934
|
+
}
|
|
2935
|
+
_drawCommentCount(count) {
|
|
2991
2936
|
if (this.showCommentCount) {
|
|
2992
2937
|
this.context.font = parseFont("defont", 60);
|
|
2993
2938
|
this.context.fillStyle = "#00FF00";
|
|
2994
|
-
this.context.strokeStyle =
|
|
2995
|
-
this.context.strokeText(
|
|
2996
|
-
this.context.fillText(
|
|
2939
|
+
this.context.strokeStyle = `rgba(${hex2rgb(config.contextStrokeColor).join(",")},${config.contextStrokeOpacity})`;
|
|
2940
|
+
this.context.strokeText(`Count:${count || 0}`, 100, 200);
|
|
2941
|
+
this.context.fillText(`Count:${count || 0}`, 100, 200);
|
|
2997
2942
|
}
|
|
2998
|
-
}
|
|
2999
|
-
|
|
2943
|
+
}
|
|
2944
|
+
addEventListener(eventName, handler) {
|
|
3000
2945
|
registerHandler(eventName, handler);
|
|
3001
|
-
}
|
|
3002
|
-
|
|
2946
|
+
}
|
|
2947
|
+
removeEventListener(eventName, handler) {
|
|
3003
2948
|
removeHandler(eventName, handler);
|
|
3004
|
-
}
|
|
3005
|
-
|
|
2949
|
+
}
|
|
2950
|
+
clear() {
|
|
3006
2951
|
this.context.clearRect(0, 0, config.canvasWidth, config.canvasHeight);
|
|
3007
|
-
}
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
NiconiComments.FlashComment = {
|
|
3011
|
-
condition: isFlashComment,
|
|
3012
|
-
class: FlashComment,
|
|
3013
|
-
};
|
|
3014
|
-
NiconiComments.internal = internal;
|
|
3015
|
-
return NiconiComments;
|
|
3016
|
-
}());
|
|
3017
|
-
var logger = function (msg) {
|
|
2952
|
+
}
|
|
2953
|
+
}
|
|
2954
|
+
const logger = (msg) => {
|
|
3018
2955
|
if (isDebug)
|
|
3019
2956
|
console.debug(msg);
|
|
3020
2957
|
};
|