@lvce-editor/markdown-worker 1.6.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/markdownWorkerMain.js +147 -18
- package/package.json +1 -1
|
@@ -60,37 +60,45 @@ class AssertionError extends Error {
|
|
|
60
60
|
this.name = 'AssertionError';
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
+
const Object$1 = 1;
|
|
64
|
+
const Number = 2;
|
|
65
|
+
const Array$1 = 3;
|
|
66
|
+
const String = 4;
|
|
67
|
+
const Boolean = 5;
|
|
68
|
+
const Function = 6;
|
|
69
|
+
const Null = 7;
|
|
70
|
+
const Unknown = 8;
|
|
63
71
|
const getType = value => {
|
|
64
72
|
switch (typeof value) {
|
|
65
73
|
case 'number':
|
|
66
|
-
return
|
|
74
|
+
return Number;
|
|
67
75
|
case 'function':
|
|
68
|
-
return
|
|
76
|
+
return Function;
|
|
69
77
|
case 'string':
|
|
70
|
-
return
|
|
78
|
+
return String;
|
|
71
79
|
case 'object':
|
|
72
80
|
if (value === null) {
|
|
73
|
-
return
|
|
81
|
+
return Null;
|
|
74
82
|
}
|
|
75
83
|
if (Array.isArray(value)) {
|
|
76
|
-
return
|
|
84
|
+
return Array$1;
|
|
77
85
|
}
|
|
78
|
-
return
|
|
86
|
+
return Object$1;
|
|
79
87
|
case 'boolean':
|
|
80
|
-
return
|
|
88
|
+
return Boolean;
|
|
81
89
|
default:
|
|
82
|
-
return
|
|
90
|
+
return Unknown;
|
|
83
91
|
}
|
|
84
92
|
};
|
|
85
93
|
const array = value => {
|
|
86
94
|
const type = getType(value);
|
|
87
|
-
if (type !==
|
|
95
|
+
if (type !== Array$1) {
|
|
88
96
|
throw new AssertionError('expected value to be of type array');
|
|
89
97
|
}
|
|
90
98
|
};
|
|
91
99
|
const string = value => {
|
|
92
100
|
const type = getType(value);
|
|
93
|
-
if (type !==
|
|
101
|
+
if (type !== String) {
|
|
94
102
|
throw new AssertionError('expected value to be of type string');
|
|
95
103
|
}
|
|
96
104
|
};
|
|
@@ -409,6 +417,100 @@ const IpcChildWithModuleWorkerAndMessagePort$1 = {
|
|
|
409
417
|
listen: listen$6,
|
|
410
418
|
wrap: wrap$e
|
|
411
419
|
};
|
|
420
|
+
const addListener = (emitter, type, callback) => {
|
|
421
|
+
if ('addEventListener' in emitter) {
|
|
422
|
+
emitter.addEventListener(type, callback);
|
|
423
|
+
} else {
|
|
424
|
+
emitter.on(type, callback);
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
const removeListener = (emitter, type, callback) => {
|
|
428
|
+
if ('removeEventListener' in emitter) {
|
|
429
|
+
emitter.removeEventListener(type, callback);
|
|
430
|
+
} else {
|
|
431
|
+
emitter.off(type, callback);
|
|
432
|
+
}
|
|
433
|
+
};
|
|
434
|
+
const getFirstEvent = (eventEmitter, eventMap) => {
|
|
435
|
+
const {
|
|
436
|
+
resolve,
|
|
437
|
+
promise
|
|
438
|
+
} = Promise.withResolvers();
|
|
439
|
+
const listenerMap = Object.create(null);
|
|
440
|
+
const cleanup = value => {
|
|
441
|
+
for (const event of Object.keys(eventMap)) {
|
|
442
|
+
removeListener(eventEmitter, event, listenerMap[event]);
|
|
443
|
+
}
|
|
444
|
+
resolve(value);
|
|
445
|
+
};
|
|
446
|
+
for (const [event, type] of Object.entries(eventMap)) {
|
|
447
|
+
const listener = event => {
|
|
448
|
+
cleanup({
|
|
449
|
+
type,
|
|
450
|
+
event
|
|
451
|
+
});
|
|
452
|
+
};
|
|
453
|
+
addListener(eventEmitter, event, listener);
|
|
454
|
+
listenerMap[event] = listener;
|
|
455
|
+
}
|
|
456
|
+
return promise;
|
|
457
|
+
};
|
|
458
|
+
const Message$1 = 3;
|
|
459
|
+
const create$5$1 = async ({
|
|
460
|
+
messagePort,
|
|
461
|
+
isMessagePortOpen
|
|
462
|
+
}) => {
|
|
463
|
+
if (!isMessagePort(messagePort)) {
|
|
464
|
+
throw new IpcError('port must be of type MessagePort');
|
|
465
|
+
}
|
|
466
|
+
if (isMessagePortOpen) {
|
|
467
|
+
return messagePort;
|
|
468
|
+
}
|
|
469
|
+
const eventPromise = getFirstEvent(messagePort, {
|
|
470
|
+
message: Message$1
|
|
471
|
+
});
|
|
472
|
+
messagePort.start();
|
|
473
|
+
const {
|
|
474
|
+
type,
|
|
475
|
+
event
|
|
476
|
+
} = await eventPromise;
|
|
477
|
+
if (type !== Message$1) {
|
|
478
|
+
throw new IpcError('Failed to wait for ipc message');
|
|
479
|
+
}
|
|
480
|
+
if (event.data !== readyMessage) {
|
|
481
|
+
throw new IpcError('unexpected first message');
|
|
482
|
+
}
|
|
483
|
+
return messagePort;
|
|
484
|
+
};
|
|
485
|
+
const signal$1 = messagePort => {
|
|
486
|
+
messagePort.start();
|
|
487
|
+
};
|
|
488
|
+
class IpcParentWithMessagePort extends Ipc {
|
|
489
|
+
getData = getData$2;
|
|
490
|
+
send(message) {
|
|
491
|
+
this._rawIpc.postMessage(message);
|
|
492
|
+
}
|
|
493
|
+
sendAndTransfer(message) {
|
|
494
|
+
const transfer = getTransferrables(message);
|
|
495
|
+
this._rawIpc.postMessage(message, transfer);
|
|
496
|
+
}
|
|
497
|
+
dispose() {
|
|
498
|
+
this._rawIpc.close();
|
|
499
|
+
}
|
|
500
|
+
onMessage(callback) {
|
|
501
|
+
this._rawIpc.addEventListener('message', callback);
|
|
502
|
+
}
|
|
503
|
+
onClose(callback) {}
|
|
504
|
+
}
|
|
505
|
+
const wrap$5 = messagePort => {
|
|
506
|
+
return new IpcParentWithMessagePort(messagePort);
|
|
507
|
+
};
|
|
508
|
+
const IpcParentWithMessagePort$1 = {
|
|
509
|
+
__proto__: null,
|
|
510
|
+
create: create$5$1,
|
|
511
|
+
signal: signal$1,
|
|
512
|
+
wrap: wrap$5
|
|
513
|
+
};
|
|
412
514
|
|
|
413
515
|
const Two = '2.0';
|
|
414
516
|
const create$4 = (method, params) => {
|
|
@@ -665,7 +767,7 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
|
665
767
|
const errorProperty = getErrorProperty(error, prettyError);
|
|
666
768
|
return create$1$1(id, errorProperty);
|
|
667
769
|
};
|
|
668
|
-
const create$
|
|
770
|
+
const create$6 = (message, result) => {
|
|
669
771
|
return {
|
|
670
772
|
jsonrpc: Two,
|
|
671
773
|
id: message.id,
|
|
@@ -674,7 +776,7 @@ const create$5 = (message, result) => {
|
|
|
674
776
|
};
|
|
675
777
|
const getSuccessResponse = (message, result) => {
|
|
676
778
|
const resultProperty = result ?? null;
|
|
677
|
-
return create$
|
|
779
|
+
return create$6(message, resultProperty);
|
|
678
780
|
};
|
|
679
781
|
const getErrorResponseSimple = (id, error) => {
|
|
680
782
|
return {
|
|
@@ -856,6 +958,26 @@ const listen$1 = async (module, options) => {
|
|
|
856
958
|
const ipc = module.wrap(rawIpc);
|
|
857
959
|
return ipc;
|
|
858
960
|
};
|
|
961
|
+
const create$5 = async ({
|
|
962
|
+
commandMap,
|
|
963
|
+
messagePort
|
|
964
|
+
}) => {
|
|
965
|
+
// TODO create a commandMap per rpc instance
|
|
966
|
+
register(commandMap);
|
|
967
|
+
const rawIpc = await IpcParentWithMessagePort$1.create({
|
|
968
|
+
messagePort,
|
|
969
|
+
isMessagePortOpen: true
|
|
970
|
+
});
|
|
971
|
+
const ipc = IpcParentWithMessagePort$1.wrap(rawIpc);
|
|
972
|
+
handleIpc(ipc);
|
|
973
|
+
const rpc = createRpc(ipc);
|
|
974
|
+
messagePort.start();
|
|
975
|
+
return rpc;
|
|
976
|
+
};
|
|
977
|
+
const PlainMessagePortRpc = {
|
|
978
|
+
__proto__: null,
|
|
979
|
+
create: create$5
|
|
980
|
+
};
|
|
859
981
|
const create$1 = async ({
|
|
860
982
|
commandMap
|
|
861
983
|
}) => {
|
|
@@ -871,6 +993,10 @@ const WebWorkerRpcClient = {
|
|
|
871
993
|
create: create$1
|
|
872
994
|
};
|
|
873
995
|
|
|
996
|
+
const terminate = () => {
|
|
997
|
+
globalThis.close();
|
|
998
|
+
};
|
|
999
|
+
|
|
874
1000
|
const Div$1 = 4;
|
|
875
1001
|
const H1$1 = 5;
|
|
876
1002
|
const Span$1 = 8;
|
|
@@ -1419,6 +1545,13 @@ const getMarkdownVirtualDom = html => {
|
|
|
1419
1545
|
}, ...childDom];
|
|
1420
1546
|
};
|
|
1421
1547
|
|
|
1548
|
+
const handleMessagePort = async (port, rpcId) => {
|
|
1549
|
+
await PlainMessagePortRpc.create({
|
|
1550
|
+
commandMap: {},
|
|
1551
|
+
messagePort: port
|
|
1552
|
+
});
|
|
1553
|
+
};
|
|
1554
|
+
|
|
1422
1555
|
/**
|
|
1423
1556
|
* marked v16.0.0 - a markdown parser
|
|
1424
1557
|
* Copyright (c) 2011-2025, Christopher Jeffrey. (MIT Licensed)
|
|
@@ -3059,12 +3192,9 @@ const renderMarkdown = async (markdown, options = {}) => {
|
|
|
3059
3192
|
return html;
|
|
3060
3193
|
};
|
|
3061
3194
|
|
|
3062
|
-
const terminate = () => {
|
|
3063
|
-
globalThis.close();
|
|
3064
|
-
};
|
|
3065
|
-
|
|
3066
3195
|
const commandMap = {
|
|
3067
3196
|
'Markdown.getVirtualDom': getMarkdownVirtualDom,
|
|
3197
|
+
'Markdown.handleMessagePort': handleMessagePort,
|
|
3068
3198
|
'Markdown.render': renderMarkdown,
|
|
3069
3199
|
'Markdown.terminate': terminate,
|
|
3070
3200
|
// deprecated
|
|
@@ -3110,8 +3240,7 @@ const {
|
|
|
3110
3240
|
set: set$3} = create(RendererWorker$1);
|
|
3111
3241
|
const RendererWorker = {
|
|
3112
3242
|
__proto__: null,
|
|
3113
|
-
set: set$3
|
|
3114
|
-
};
|
|
3243
|
+
set: set$3};
|
|
3115
3244
|
|
|
3116
3245
|
const {
|
|
3117
3246
|
set
|