openchemlib 8.20.2 → 9.0.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/README.md +5 -55
- package/{types.d.ts → dist/openchemlib.d.ts} +66 -240
- package/dist/openchemlib.debug.js +69894 -0
- package/dist/openchemlib.js +24 -0
- package/dist/resources.json +37 -0
- package/package.json +26 -44
- package/core.d.ts +0 -15
- package/core.js +0 -24
- package/dist/openchemlib-core.js +0 -283
- package/dist/openchemlib-full.js +0 -310
- package/dist/openchemlib-full.pretty.js +0 -101963
- package/dist/openchemlib-minimal.js +0 -228
- package/full.d.ts +0 -16
- package/full.js +0 -32
- package/full.pretty.d.ts +0 -1
- package/full.pretty.js +0 -32
- package/lib/canvas_editor/clipboard_handler.js +0 -15
- package/lib/canvas_editor/create_editor.js +0 -152
- package/lib/canvas_editor/cursor_manager_16.js +0 -41
- package/lib/canvas_editor/cursor_manager_24.js +0 -43
- package/lib/canvas_editor/cursors_24px.js +0 -21
- package/lib/canvas_editor/draw_context.js +0 -156
- package/lib/canvas_editor/editor_area.js +0 -31
- package/lib/canvas_editor/editor_dialog.js +0 -250
- package/lib/canvas_editor/editor_image.js +0 -46
- package/lib/canvas_editor/editor_stylesheet.js +0 -21
- package/lib/canvas_editor/events.js +0 -144
- package/lib/canvas_editor/init/canvas_editor.js +0 -137
- package/lib/canvas_editor/init/canvas_editor_element.js +0 -359
- package/lib/canvas_editor/init/index.js +0 -70
- package/lib/canvas_editor/toolbar.js +0 -28
- package/lib/canvas_editor/ui_helper.js +0 -57
- package/lib/canvas_editor/utils.js +0 -55
- package/minimal.d.ts +0 -18
- package/minimal.js +0 -14
|
@@ -1,359 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
function initCanvasEditorElement(CanvasEditor, Molecule, ReactionEncoder) {
|
|
4
|
-
class CanvasEditorElement extends HTMLElement {
|
|
5
|
-
/** @type {{MOLECULE: 'molecule', REACTION: 'reaction'}} */
|
|
6
|
-
static MODE = Object.freeze(
|
|
7
|
-
Object.create({
|
|
8
|
-
MOLECULE: 'molecule',
|
|
9
|
-
REACTION: 'reaction',
|
|
10
|
-
}),
|
|
11
|
-
);
|
|
12
|
-
static observedAttributes = Object.freeze([
|
|
13
|
-
'idcode',
|
|
14
|
-
'fragment',
|
|
15
|
-
'mode',
|
|
16
|
-
'readonly',
|
|
17
|
-
]);
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* @type {{mode: 'molecule' | 'reaction', fragment: boolean, idcode: string, readonly: boolean}}
|
|
21
|
-
*/
|
|
22
|
-
#state;
|
|
23
|
-
|
|
24
|
-
get idcode() {
|
|
25
|
-
return this.#state.idcode;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
set idcode(value) {
|
|
29
|
-
this.#state.idcode = String(value);
|
|
30
|
-
this.setAttribute('idcode', this.#state.idcode);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
get fragment() {
|
|
34
|
-
return this.#state.fragment;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
set fragment(value) {
|
|
38
|
-
this.#state.fragment = Boolean(value);
|
|
39
|
-
if (this.#state.fragment) {
|
|
40
|
-
this.setAttribute('fragment', '');
|
|
41
|
-
} else {
|
|
42
|
-
this.removeAttribute('fragment');
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
get mode() {
|
|
47
|
-
return this.#state.mode;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
set mode(value) {
|
|
51
|
-
this.#state.mode = String(value);
|
|
52
|
-
this.setAttribute('mode', this.#state.mode);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
get readonly() {
|
|
56
|
-
return this.#state.readonly;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
set readonly(value) {
|
|
60
|
-
this.#state.readonly = Boolean(value);
|
|
61
|
-
if (this.#state.readonly) {
|
|
62
|
-
this.setAttribute('readonly', '');
|
|
63
|
-
} else {
|
|
64
|
-
this.removeAttribute('readonly');
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/* --- custom element api --- */
|
|
69
|
-
/**
|
|
70
|
-
* @param {Molecule} molecule
|
|
71
|
-
* @this {CanvasEditorElement}
|
|
72
|
-
*/
|
|
73
|
-
setMolecule(molecule) {
|
|
74
|
-
this.fragment = molecule.isFragment();
|
|
75
|
-
this.idcode = `${molecule.getIDCode()} ${molecule.getIDCoordinates()}`;
|
|
76
|
-
|
|
77
|
-
this.#editor.setMolecule(molecule);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* @return {Molecule}
|
|
82
|
-
* @this {CanvasEditorElement}
|
|
83
|
-
*/
|
|
84
|
-
getMolecule() {
|
|
85
|
-
return this.#editor.getMolecule();
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* @param {Reaction} reaction
|
|
90
|
-
* @this {CanvasEditorElement}
|
|
91
|
-
*/
|
|
92
|
-
setReaction(reaction) {
|
|
93
|
-
this.fragment = reaction.isFragment();
|
|
94
|
-
this.idcode = ReactionEncoder.encode(reaction, {
|
|
95
|
-
keepAbsoluteCoordinates: true,
|
|
96
|
-
mode:
|
|
97
|
-
ReactionEncoder.INCLUDE_MAPPING |
|
|
98
|
-
ReactionEncoder.INCLUDE_COORDS |
|
|
99
|
-
ReactionEncoder.RETAIN_REACTANT_AND_PRODUCT_ORDER,
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
this.#editor.setReaction(reaction);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* @return {Reaction}
|
|
107
|
-
* @this {CanvasEditorElement}
|
|
108
|
-
*/
|
|
109
|
-
getReaction() {
|
|
110
|
-
return this.#editor.getReaction();
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* @this {CanvasEditorElement}
|
|
115
|
-
*/
|
|
116
|
-
clearAll() {
|
|
117
|
-
this.#editor.clearAll();
|
|
118
|
-
this.idcode = '';
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* @this {CanvasEditorElement}
|
|
123
|
-
*/
|
|
124
|
-
moleculeChanged() {
|
|
125
|
-
this.#editor.moleculeChanged();
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/* --- internals --- */
|
|
129
|
-
/** @type {CanvasEditor} */ #editor;
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* @this {CanvasEditorElement}
|
|
133
|
-
*/
|
|
134
|
-
#initEditor() {
|
|
135
|
-
if (this.#editor) return;
|
|
136
|
-
|
|
137
|
-
this.#editor = new CanvasEditor(this, {
|
|
138
|
-
readOnly: this.readonly,
|
|
139
|
-
initialMode: this.mode,
|
|
140
|
-
});
|
|
141
|
-
this.#editor.setOnChangeListener(this.#handleChange);
|
|
142
|
-
|
|
143
|
-
requestIdleCallback(() => this.#initIdCode());
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* @this {CanvasEditorElement}
|
|
148
|
-
*/
|
|
149
|
-
#initIdCode() {
|
|
150
|
-
switch (this.mode) {
|
|
151
|
-
case CanvasEditorElement.MODE.MOLECULE: {
|
|
152
|
-
return this.#initMolecule();
|
|
153
|
-
}
|
|
154
|
-
case CanvasEditorElement.MODE.REACTION: {
|
|
155
|
-
return this.#initReaction();
|
|
156
|
-
}
|
|
157
|
-
default:
|
|
158
|
-
throw new Error(`Mode ${this.mode} is not supported`);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* @param {string} idcodeAndCoordinates
|
|
164
|
-
*/
|
|
165
|
-
#moleculeFromIdCode(idcodeAndCoordinates) {
|
|
166
|
-
const index = idcodeAndCoordinates.indexOf(' ');
|
|
167
|
-
|
|
168
|
-
if (index === -1) {
|
|
169
|
-
return Molecule.fromIDCode(idcodeAndCoordinates);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
const idcode = idcodeAndCoordinates.slice(0, index);
|
|
173
|
-
const coordinates = idcodeAndCoordinates.slice(index + 1);
|
|
174
|
-
|
|
175
|
-
return Molecule.fromIDCode(idcode, coordinates);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* @this {CanvasEditorElement}
|
|
180
|
-
*/
|
|
181
|
-
#initMolecule() {
|
|
182
|
-
const molecule = this.#moleculeFromIdCode(this.idcode);
|
|
183
|
-
molecule.setFragment(this.fragment);
|
|
184
|
-
|
|
185
|
-
this.#editor.setMolecule(molecule);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* @this {CanvasEditorElement}
|
|
190
|
-
*/
|
|
191
|
-
#initReaction() {
|
|
192
|
-
const reaction = ReactionEncoder.decode(this.idcode, {
|
|
193
|
-
ensureCoordinates: true,
|
|
194
|
-
});
|
|
195
|
-
reaction.setFragment(this.fragment);
|
|
196
|
-
|
|
197
|
-
this.#editor.setReaction(reaction);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
#ignoreAttributeChange = false;
|
|
201
|
-
/**
|
|
202
|
-
* @param {() => void} fn
|
|
203
|
-
* @this {CanvasEditorElement}
|
|
204
|
-
*/
|
|
205
|
-
#wrapIgnoreAttributeChange(fn) {
|
|
206
|
-
this.#ignoreAttributeChange = true;
|
|
207
|
-
|
|
208
|
-
try {
|
|
209
|
-
fn();
|
|
210
|
-
} finally {
|
|
211
|
-
this.#ignoreAttributeChange = false;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* @param {{
|
|
217
|
-
* type: 'molecule' | 'selection' | 'highlight-atom' | 'highlight-bond';
|
|
218
|
-
* isUserEvent: boolean;
|
|
219
|
-
* }} editorEventOnChange
|
|
220
|
-
*/
|
|
221
|
-
#handleChange = (editorEventOnChange) => {
|
|
222
|
-
const idcode = this.idcode;
|
|
223
|
-
const fragment = this.fragment;
|
|
224
|
-
|
|
225
|
-
// update internal state from editor change
|
|
226
|
-
this.#wrapIgnoreAttributeChange(() => {
|
|
227
|
-
if (editorEventOnChange.type !== 'molecule') return;
|
|
228
|
-
|
|
229
|
-
switch (this.mode) {
|
|
230
|
-
case CanvasEditorElement.MODE.MOLECULE: {
|
|
231
|
-
const molecule = this.getMolecule();
|
|
232
|
-
this.idcode = `${molecule.getIDCode()} ${molecule.getIDCoordinates()}`;
|
|
233
|
-
this.fragment = molecule.isFragment();
|
|
234
|
-
break;
|
|
235
|
-
}
|
|
236
|
-
case CanvasEditorElement.MODE.REACTION: {
|
|
237
|
-
const reaction = this.getReaction();
|
|
238
|
-
this.idcode = ReactionEncoder.encode(reaction, {
|
|
239
|
-
keepAbsoluteCoordinates: true,
|
|
240
|
-
mode:
|
|
241
|
-
ReactionEncoder.INCLUDE_MAPPING |
|
|
242
|
-
ReactionEncoder.INCLUDE_COORDS |
|
|
243
|
-
ReactionEncoder.RETAIN_REACTANT_AND_PRODUCT_ORDER,
|
|
244
|
-
});
|
|
245
|
-
this.fragment = reaction.isFragment();
|
|
246
|
-
break;
|
|
247
|
-
}
|
|
248
|
-
default:
|
|
249
|
-
throw new Error(`Unsupported mode ${this.mode}`);
|
|
250
|
-
}
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
// propagate editor changes to parent
|
|
254
|
-
const domEvent = new CustomEvent('change', {
|
|
255
|
-
detail: editorEventOnChange,
|
|
256
|
-
bubbles: true,
|
|
257
|
-
});
|
|
258
|
-
this.dispatchEvent(domEvent);
|
|
259
|
-
|
|
260
|
-
if (editorEventOnChange.mode !== 'molecule') return;
|
|
261
|
-
|
|
262
|
-
// propagate vaadin events
|
|
263
|
-
if (this.idcode !== idcode) {
|
|
264
|
-
const idcodeChangeEvent = new CustomEvent('idcode-changed', {
|
|
265
|
-
detail: this.idcode,
|
|
266
|
-
bubbles: true,
|
|
267
|
-
});
|
|
268
|
-
this.dispatchEvent(idcodeChangeEvent);
|
|
269
|
-
}
|
|
270
|
-
if (this.fragment !== fragment) {
|
|
271
|
-
const fragmentChangeEvent = new CustomEvent('fragment-changed', {
|
|
272
|
-
detail: this.fragment,
|
|
273
|
-
bubbles: true,
|
|
274
|
-
});
|
|
275
|
-
this.dispatchEvent(fragmentChangeEvent);
|
|
276
|
-
}
|
|
277
|
-
};
|
|
278
|
-
|
|
279
|
-
#destroyEditor() {
|
|
280
|
-
if (!this.#editor) return;
|
|
281
|
-
|
|
282
|
-
this.#editor.destroy();
|
|
283
|
-
this.#editor = undefined;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
#resetEditor() {
|
|
287
|
-
this.#destroyEditor();
|
|
288
|
-
this.#initEditor();
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
/* --- lifecycle hooks --- */
|
|
292
|
-
/**
|
|
293
|
-
* Custom element added to page.
|
|
294
|
-
*/
|
|
295
|
-
connectedCallback() {
|
|
296
|
-
this.#state = {
|
|
297
|
-
idcode: this.getAttribute('idcode') || '',
|
|
298
|
-
fragment: this.hasAttribute('fragment'),
|
|
299
|
-
mode: this.getAttribute('mode') || CanvasEditorElement.MODE.MOLECULE,
|
|
300
|
-
readonly: this.hasAttribute('readonly'),
|
|
301
|
-
};
|
|
302
|
-
|
|
303
|
-
this.#initEditor();
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
/**
|
|
307
|
-
* Custom element removed from page.
|
|
308
|
-
*/
|
|
309
|
-
disconnectedCallback() {
|
|
310
|
-
this.#destroyEditor();
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
* Custom element moved to new page.
|
|
315
|
-
*/
|
|
316
|
-
adoptedCallback() {
|
|
317
|
-
this.connectedCallback();
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
/**
|
|
321
|
-
* Attribute ${name} has changed from ${oldValue} to ${newValue}
|
|
322
|
-
*
|
|
323
|
-
* Sync attribute changes to internal state.
|
|
324
|
-
* propagate changes to editor.
|
|
325
|
-
*/
|
|
326
|
-
attributeChangedCallback(name, oldValue, newValue) {
|
|
327
|
-
if (!this.#editor) return;
|
|
328
|
-
if (this.#ignoreAttributeChange) return;
|
|
329
|
-
|
|
330
|
-
const mutatorHandler = (() => {
|
|
331
|
-
switch (name) {
|
|
332
|
-
case 'idcode': {
|
|
333
|
-
this.#state.idcode = String(newValue);
|
|
334
|
-
return () => this.#initIdCode();
|
|
335
|
-
}
|
|
336
|
-
case 'fragment': {
|
|
337
|
-
this.#state.fragment = newValue !== null;
|
|
338
|
-
return () => this.#initIdCode();
|
|
339
|
-
}
|
|
340
|
-
case 'mode': {
|
|
341
|
-
this.#state.mode = String(newValue);
|
|
342
|
-
return () => this.#resetEditor();
|
|
343
|
-
}
|
|
344
|
-
case 'readonly': {
|
|
345
|
-
this.#state.readonly = newValue !== null;
|
|
346
|
-
return () => this.#resetEditor();
|
|
347
|
-
}
|
|
348
|
-
default:
|
|
349
|
-
throw new Error('unsupported attribute change');
|
|
350
|
-
}
|
|
351
|
-
})();
|
|
352
|
-
mutatorHandler();
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
return CanvasEditorElement;
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
module.exports = initCanvasEditorElement;
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const initCanvasEditor = require('./canvas_editor');
|
|
4
|
-
const initCanvasEditorElement = require('./canvas_editor_element');
|
|
5
|
-
|
|
6
|
-
function init(OCL) {
|
|
7
|
-
const {
|
|
8
|
-
GenericEditorArea: JavaEditorArea,
|
|
9
|
-
GenericEditorToolbar: JavaEditorToolbar,
|
|
10
|
-
GenericUIHelper: JavaUIHelper,
|
|
11
|
-
Molecule,
|
|
12
|
-
Reaction,
|
|
13
|
-
ReactionEncoder,
|
|
14
|
-
} = OCL;
|
|
15
|
-
|
|
16
|
-
const CanvasEditor = initCanvasEditor(
|
|
17
|
-
JavaEditorArea,
|
|
18
|
-
JavaEditorToolbar,
|
|
19
|
-
JavaUIHelper,
|
|
20
|
-
Molecule,
|
|
21
|
-
Reaction,
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
function registerCustomElement() {
|
|
25
|
-
const constructor = customElements.get('openchemlib-editor');
|
|
26
|
-
if (constructor) return constructor;
|
|
27
|
-
|
|
28
|
-
const CanvasEditorElement = initCanvasEditorElement(
|
|
29
|
-
CanvasEditor,
|
|
30
|
-
Molecule,
|
|
31
|
-
ReactionEncoder,
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
customElements.define('openchemlib-editor', CanvasEditorElement);
|
|
35
|
-
|
|
36
|
-
// mutate the first stylesheet available or construct a new one, added to adoptedStyleSheets
|
|
37
|
-
// It's default styling for openchemlib-editor element,
|
|
38
|
-
// should be considered as a user-agent stylesheet (low-priority)
|
|
39
|
-
const css =
|
|
40
|
-
document.styleSheets[0] ??
|
|
41
|
-
(() => {
|
|
42
|
-
const css = new CSSStyleSheet();
|
|
43
|
-
document.adoptedStyleSheets.unshift(css);
|
|
44
|
-
return css;
|
|
45
|
-
})();
|
|
46
|
-
css.insertRule(
|
|
47
|
-
`
|
|
48
|
-
/* dynamicaly added from openchemlib registerCustomElement with low priority */
|
|
49
|
-
openchemlib-editor:defined {
|
|
50
|
-
display: block;
|
|
51
|
-
height: 400px;
|
|
52
|
-
width: 600px;
|
|
53
|
-
}
|
|
54
|
-
`,
|
|
55
|
-
0,
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
return CanvasEditorElement;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
OCL.CanvasEditor = CanvasEditor;
|
|
62
|
-
OCL.registerCustomElement = registerCustomElement;
|
|
63
|
-
|
|
64
|
-
// Do not expose internal classes to end users.
|
|
65
|
-
delete OCL.GenericEditorArea;
|
|
66
|
-
delete OCL.GenericEditorToolbar;
|
|
67
|
-
delete OCL.GenericUIHelper;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
module.exports = init;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const DrawContext = require('./draw_context');
|
|
4
|
-
|
|
5
|
-
class Toolbar {
|
|
6
|
-
constructor(canvasElement) {
|
|
7
|
-
this.canvasElement = canvasElement;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
setDimensions(width, height) {
|
|
11
|
-
this.canvasElement.width = width;
|
|
12
|
-
this.canvasElement.height = height;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
getDrawContext() {
|
|
16
|
-
return new DrawContext(this.canvasElement.getContext('2d'));
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
getBackgroundRGB() {
|
|
20
|
-
return 0xffffff;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
getForegroundRGB() {
|
|
24
|
-
return 0x000000;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
module.exports = Toolbar;
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const CursorManager = require('./cursor_manager_24');
|
|
4
|
-
const EditorDialog = require('./editor_dialog');
|
|
5
|
-
const EditorImage = require('./editor_image');
|
|
6
|
-
const { decodeBase64 } = require('./utils');
|
|
7
|
-
|
|
8
|
-
class UIHelper {
|
|
9
|
-
/**
|
|
10
|
-
*
|
|
11
|
-
* @param {HTMLCanvasElement} canvasElement
|
|
12
|
-
* @param {HTMLElement} dialogRoot
|
|
13
|
-
* @param JavaEditorArea
|
|
14
|
-
*/
|
|
15
|
-
constructor(canvasElement, dialogRoot, JavaEditorArea) {
|
|
16
|
-
this.canvasElement = canvasElement;
|
|
17
|
-
this.dialogRoot = dialogRoot;
|
|
18
|
-
this.JavaEditorArea = JavaEditorArea;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
register(javaUiHelper) {
|
|
22
|
-
this.javaUiHelper = javaUiHelper;
|
|
23
|
-
this.cursorManager = new CursorManager(this.JavaEditorArea, javaUiHelper);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
grabFocus() {
|
|
27
|
-
this.canvasElement.focus({ preventScroll: true });
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
setCursor(cursor) {
|
|
31
|
-
this.canvasElement.style.cursor = this.cursorManager.getCursor(cursor);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
showHelpDialog(/* url, title */) {
|
|
35
|
-
// TODO: implement help dialog?
|
|
36
|
-
// console.log({ url, title });
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
createImage(width, height) {
|
|
40
|
-
const imageData = new ImageData(width, height);
|
|
41
|
-
return new EditorImage(imageData);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
createImageFromBase64(width, height, base64) {
|
|
45
|
-
base64 = base64.replaceAll('%', 'A'.repeat(20));
|
|
46
|
-
const decoded = decodeBase64(base64);
|
|
47
|
-
const typedArray = new Uint8ClampedArray(decoded);
|
|
48
|
-
const imageData = new ImageData(typedArray, width, height);
|
|
49
|
-
return new EditorImage(imageData);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
createDialog(title) {
|
|
53
|
-
return new EditorDialog(title, this.dialogRoot);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
module.exports = UIHelper;
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/* eslint-disable unicorn/prefer-code-point */
|
|
4
|
-
|
|
5
|
-
// https://github.com/niklasvh/base64-arraybuffer/blob/master/LICENSE
|
|
6
|
-
const chars =
|
|
7
|
-
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
8
|
-
// Use a lookup table to find the index.
|
|
9
|
-
const lookup = new Uint8Array(256);
|
|
10
|
-
for (let i = 0; i < chars.length; i++) {
|
|
11
|
-
lookup[chars.charCodeAt(i)] = i;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function decodeBase64(base64) {
|
|
15
|
-
let bufferLength = base64.length * 0.75;
|
|
16
|
-
let len = base64.length;
|
|
17
|
-
let i;
|
|
18
|
-
let p = 0;
|
|
19
|
-
let encoded1;
|
|
20
|
-
let encoded2;
|
|
21
|
-
let encoded3;
|
|
22
|
-
let encoded4;
|
|
23
|
-
|
|
24
|
-
if (base64.at(-1) === '=') {
|
|
25
|
-
bufferLength--;
|
|
26
|
-
if (base64.at(-2) === '=') {
|
|
27
|
-
bufferLength--;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const arraybuffer = new ArrayBuffer(bufferLength);
|
|
32
|
-
const bytes = new Uint8Array(arraybuffer);
|
|
33
|
-
|
|
34
|
-
for (i = 0; i < len; i += 4) {
|
|
35
|
-
encoded1 = lookup[base64.charCodeAt(i)];
|
|
36
|
-
encoded2 = lookup[base64.charCodeAt(i + 1)];
|
|
37
|
-
encoded3 = lookup[base64.charCodeAt(i + 2)];
|
|
38
|
-
encoded4 = lookup[base64.charCodeAt(i + 3)];
|
|
39
|
-
|
|
40
|
-
bytes[p++] = (encoded1 << 2) | (encoded2 >> 4);
|
|
41
|
-
bytes[p++] = ((encoded2 & 15) << 4) | (encoded3 >> 2);
|
|
42
|
-
bytes[p++] = ((encoded3 & 3) << 6) | (encoded4 & 63);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return arraybuffer;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function toHex(v) {
|
|
49
|
-
return v.toString(16).padStart(2, '0');
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
module.exports = {
|
|
53
|
-
decodeBase64,
|
|
54
|
-
toHex,
|
|
55
|
-
};
|
package/minimal.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export {
|
|
2
|
-
IMoleculeFromSmilesOptions,
|
|
3
|
-
IMoleculeToSVGOptions,
|
|
4
|
-
IHoseCodesOptions,
|
|
5
|
-
Molecule,
|
|
6
|
-
MolecularFormula,
|
|
7
|
-
RingCollection,
|
|
8
|
-
IDepictorOptions,
|
|
9
|
-
Reaction,
|
|
10
|
-
SDFileParser,
|
|
11
|
-
ISmilesParserOptions,
|
|
12
|
-
ISmilesParserParseMoleculeOptions,
|
|
13
|
-
SmilesParser,
|
|
14
|
-
SSSearcher,
|
|
15
|
-
SSSearcherWithIndex,
|
|
16
|
-
Util,
|
|
17
|
-
version,
|
|
18
|
-
} from './types';
|
package/minimal.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const OCL = require('./dist/openchemlib-minimal.js');
|
|
4
|
-
|
|
5
|
-
exports.default = OCL;
|
|
6
|
-
exports.Molecule = OCL.Molecule;
|
|
7
|
-
exports.Reaction = OCL.Reaction;
|
|
8
|
-
exports.RingCollection = OCL.RingCollection;
|
|
9
|
-
exports.SDFileParser = OCL.SDFileParser;
|
|
10
|
-
exports.SSSearcher = OCL.SSSearcher;
|
|
11
|
-
exports.SSSearcherWithIndex = OCL.SSSearcherWithIndex;
|
|
12
|
-
exports.SmilesParser = OCL.SmilesParser;
|
|
13
|
-
exports.Util = OCL.Util;
|
|
14
|
-
exports.version = OCL.version;
|