@aardarch/aardink-web 0.5.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/JETBRAINS_MONO_OFL.txt +93 -0
- package/LICENSE +178 -0
- package/README.md +86 -0
- package/index.d.ts +75 -0
- package/index.js +92 -0
- package/kotlin/aardink-web.import-object.mjs +582 -0
- package/kotlin/aardink-web.js-builtins.mjs +52 -0
- package/kotlin/aardink-web.mjs +98 -0
- package/kotlin/aardink-web.wasm +0 -0
- package/kotlin/composeResources/com.aardarch.aardink.web.res/font/jetbrains_mono_regular.ttf +0 -0
- package/kotlin/js-reexport-symbols.mjs +999 -0
- package/kotlin/skiko.mjs +1118 -0
- package/kotlin/skiko.wasm +0 -0
- package/kotlin/skikod8.mjs +1118 -0
- package/package.json +27 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
Copyright 2020 The JetBrains Mono Project Authors (https://github.com/JetBrains/JetBrainsMono)
|
|
2
|
+
|
|
3
|
+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
|
4
|
+
This license is copied below, and is also available with a FAQ at:
|
|
5
|
+
https://scripts.sil.org/OFL
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
-----------------------------------------------------------
|
|
9
|
+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
|
10
|
+
-----------------------------------------------------------
|
|
11
|
+
|
|
12
|
+
PREAMBLE
|
|
13
|
+
The goals of the Open Font License (OFL) are to stimulate worldwide
|
|
14
|
+
development of collaborative font projects, to support the font creation
|
|
15
|
+
efforts of academic and linguistic communities, and to provide a free and
|
|
16
|
+
open framework in which fonts may be shared and improved in partnership
|
|
17
|
+
with others.
|
|
18
|
+
|
|
19
|
+
The OFL allows the licensed fonts to be used, studied, modified and
|
|
20
|
+
redistributed freely as long as they are not sold by themselves. The
|
|
21
|
+
fonts, including any derivative works, can be bundled, embedded,
|
|
22
|
+
redistributed and/or sold with any software provided that any reserved
|
|
23
|
+
names are not used by derivative works. The fonts and derivatives,
|
|
24
|
+
however, cannot be released under any other type of license. The
|
|
25
|
+
requirement for fonts to remain under this license does not apply
|
|
26
|
+
to any document created using the fonts or their derivatives.
|
|
27
|
+
|
|
28
|
+
DEFINITIONS
|
|
29
|
+
"Font Software" refers to the set of files released by the Copyright
|
|
30
|
+
Holder(s) under this license and clearly marked as such. This may
|
|
31
|
+
include source files, build scripts and documentation.
|
|
32
|
+
|
|
33
|
+
"Reserved Font Name" refers to any names specified as such after the
|
|
34
|
+
copyright statement(s).
|
|
35
|
+
|
|
36
|
+
"Original Version" refers to the collection of Font Software components as
|
|
37
|
+
distributed by the Copyright Holder(s).
|
|
38
|
+
|
|
39
|
+
"Modified Version" refers to any derivative made by adding to, deleting,
|
|
40
|
+
or substituting -- in part or in whole -- any of the components of the
|
|
41
|
+
Original Version, by changing formats or by porting the Font Software to a
|
|
42
|
+
new environment.
|
|
43
|
+
|
|
44
|
+
"Author" refers to any designer, engineer, programmer, technical
|
|
45
|
+
writer or other person who contributed to the Font Software.
|
|
46
|
+
|
|
47
|
+
PERMISSION & CONDITIONS
|
|
48
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
49
|
+
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
|
50
|
+
redistribute, and sell modified and unmodified copies of the Font
|
|
51
|
+
Software, subject to the following conditions:
|
|
52
|
+
|
|
53
|
+
1) Neither the Font Software nor any of its individual components,
|
|
54
|
+
in Original or Modified Versions, may be sold by itself.
|
|
55
|
+
|
|
56
|
+
2) Original or Modified Versions of the Font Software may be bundled,
|
|
57
|
+
redistributed and/or sold with any software, provided that each copy
|
|
58
|
+
contains the above copyright notice and this license. These can be
|
|
59
|
+
included either as stand-alone text files, human-readable headers or
|
|
60
|
+
in the appropriate machine-readable metadata fields within text or
|
|
61
|
+
binary files as long as those fields can be easily viewed by the user.
|
|
62
|
+
|
|
63
|
+
3) No Modified Version of the Font Software may use the Reserved Font
|
|
64
|
+
Name(s) unless explicit written permission is granted by the corresponding
|
|
65
|
+
Copyright Holder. This restriction only applies to the primary font name as
|
|
66
|
+
presented to the users.
|
|
67
|
+
|
|
68
|
+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
|
69
|
+
Software shall not be used to promote, endorse or advertise any
|
|
70
|
+
Modified Version, except to acknowledge the contribution(s) of the
|
|
71
|
+
Copyright Holder(s) and the Author(s) or with their explicit written
|
|
72
|
+
permission.
|
|
73
|
+
|
|
74
|
+
5) The Font Software, modified or unmodified, in part or in whole,
|
|
75
|
+
must be distributed entirely under this license, and must not be
|
|
76
|
+
distributed under any other license. The requirement for fonts to
|
|
77
|
+
remain under this license does not apply to any document created
|
|
78
|
+
using the Font Software.
|
|
79
|
+
|
|
80
|
+
TERMINATION
|
|
81
|
+
This license becomes null and void if any of the above conditions are
|
|
82
|
+
not met.
|
|
83
|
+
|
|
84
|
+
DISCLAIMER
|
|
85
|
+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
86
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
|
87
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
|
88
|
+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
|
89
|
+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
90
|
+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
|
91
|
+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
92
|
+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
|
93
|
+
OTHER DEALINGS IN THE FONT SOFTWARE.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship made available under
|
|
36
|
+
the License, as indicated by a copyright notice that is included in
|
|
37
|
+
or attached to the work (an example is provided in the Appendix below).
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
|
+
form, that is based on (or derived from) the Work and for which the
|
|
41
|
+
editorial revisions, annotations, elaborations, or other transformations
|
|
42
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
43
|
+
of this License, Derivative Works shall not include works that remain
|
|
44
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
45
|
+
the Work and Derivative Works thereof.
|
|
46
|
+
|
|
47
|
+
"Contribution" shall mean, as submitted to the Licensor for inclusion
|
|
48
|
+
in the Work by the copyright owner or by an individual or Legal Entity
|
|
49
|
+
authorized to submit on behalf of the copyright owner. For the purposes
|
|
50
|
+
of this definition, "submitted" means any form of electronic, verbal,
|
|
51
|
+
or written communication sent to the Licensor or its representatives,
|
|
52
|
+
including but not limited to communication on electronic mailing lists,
|
|
53
|
+
source code control systems, and issue tracking systems that are managed
|
|
54
|
+
by, or on behalf of, the Licensor for the purpose of discussing and
|
|
55
|
+
improving the Work, but excluding communication that is conspicuously
|
|
56
|
+
marked or designated in writing by the copyright owner as
|
|
57
|
+
"Not a Contribution."
|
|
58
|
+
|
|
59
|
+
"Contributor" shall mean Licensor and any Legal Entity on behalf of
|
|
60
|
+
whom a Contribution has been received by the Licensor and included
|
|
61
|
+
within the Work.
|
|
62
|
+
|
|
63
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
64
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
65
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
66
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
67
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
68
|
+
Work and such Derivative Works in Source or Object form.
|
|
69
|
+
|
|
70
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
71
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
72
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
73
|
+
(except as stated in this section) patent license to make, have made,
|
|
74
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
75
|
+
where such license applies only to those patent claims licensable
|
|
76
|
+
by such Contributor that are necessarily infringed by their
|
|
77
|
+
Contribution(s) alone or by the combined contribution of their
|
|
78
|
+
Contribution(s) with the Work to which such Contribution(s) was
|
|
79
|
+
submitted. If You institute patent litigation against any entity
|
|
80
|
+
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
|
81
|
+
the Work or any Work embodying the Work constitutes direct or
|
|
82
|
+
contributory patent infringement, then any patent rights granted to
|
|
83
|
+
You under this License for that Work shall terminate as of the date
|
|
84
|
+
such litigation is filed.
|
|
85
|
+
|
|
86
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
87
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
88
|
+
modifications, and in Source or Object form, provided that You
|
|
89
|
+
meet the following conditions:
|
|
90
|
+
|
|
91
|
+
(a) You must give any other recipients of the Work or Derivative
|
|
92
|
+
Works a copy of this License; and
|
|
93
|
+
|
|
94
|
+
(b) You must cause any modified files to carry prominent notices
|
|
95
|
+
stating that You changed the files; and
|
|
96
|
+
|
|
97
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
98
|
+
that You distribute, all copyright, patent, trademark, and
|
|
99
|
+
attribution notices from the Source form of the Work,
|
|
100
|
+
excluding those notices that do not pertain to any part of
|
|
101
|
+
the Derivative Works; and
|
|
102
|
+
|
|
103
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
104
|
+
distribution, You must include a readable copy of the
|
|
105
|
+
attribution notices contained within such NOTICE file, in
|
|
106
|
+
at least one of the following places: within a NOTICE text
|
|
107
|
+
file distributed as part of the Derivative Works; within
|
|
108
|
+
the Source form or documentation, if provided along with the
|
|
109
|
+
Derivative Works; or, within a display generated by the
|
|
110
|
+
Derivative Works, if and wherever such third-party notices
|
|
111
|
+
normally appear. The contents of the NOTICE file are for
|
|
112
|
+
informational purposes only and do not modify the License.
|
|
113
|
+
You may add Your own attribution notices within Derivative
|
|
114
|
+
Works that You distribute, alongside or as an addendum to
|
|
115
|
+
the NOTICE text from the Work, provided that such additional
|
|
116
|
+
attribution notices cannot be construed as modifying the License.
|
|
117
|
+
|
|
118
|
+
You may add Your own license statement for Your modifications and
|
|
119
|
+
may provide additional grant of rights to use, copy, modify, merge,
|
|
120
|
+
publish, distribute, sublicense, and/or sell copies of the Work.
|
|
121
|
+
|
|
122
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
123
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
124
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
125
|
+
this License, without any additional terms or conditions.
|
|
126
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
127
|
+
the terms of any separate license agreement you may have executed
|
|
128
|
+
with Licensor regarding such Contributions.
|
|
129
|
+
|
|
130
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
131
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
132
|
+
except as required for reasonable and customary use in describing the
|
|
133
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
134
|
+
|
|
135
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
136
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
137
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
138
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
139
|
+
implied, including, without limitation, any conditions of
|
|
140
|
+
TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
141
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
142
|
+
appropriateness of using or reproducing the Work and assume any
|
|
143
|
+
risks associated with Your exercise of permissions under this License.
|
|
144
|
+
|
|
145
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
146
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
147
|
+
unless required by applicable law (such as deliberate and grossly
|
|
148
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
149
|
+
liable to You for damages, including any direct, indirect, special,
|
|
150
|
+
incidental, or exemplary damages of any character arising as a
|
|
151
|
+
result of this License or out of the use or inability to use the
|
|
152
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
153
|
+
work stoppage, computer failure or malfunction, or all other
|
|
154
|
+
commercial damages or losses), even if such Contributor has been
|
|
155
|
+
advised of the possibility of such damages.
|
|
156
|
+
|
|
157
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
158
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
159
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
160
|
+
or other liability obligations and/or rights consistent with this
|
|
161
|
+
License. However, in accepting such obligations, You may offer only
|
|
162
|
+
conditions consistent with this License.
|
|
163
|
+
|
|
164
|
+
END OF TERMS AND CONDITIONS
|
|
165
|
+
|
|
166
|
+
Copyright 2026 Aardarch
|
|
167
|
+
|
|
168
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
169
|
+
you may not use this file except in compliance with the License.
|
|
170
|
+
You may obtain a copy of the License at
|
|
171
|
+
|
|
172
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
173
|
+
|
|
174
|
+
Unless required by applicable law or agreed to in writing, software
|
|
175
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
176
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
177
|
+
See the License for the specific language governing permissions and
|
|
178
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# @aardarch/aardink-web
|
|
2
|
+
|
|
3
|
+
The [Aardink](https://github.com/aardarch/aardink) code editor for the browser: Compose
|
|
4
|
+
Multiplatform compiled to WebAssembly, behind a small Monaco-shaped API. It covers syntax
|
|
5
|
+
highlighting for Kotlin, TypeScript, JSON, TOML, XML, HTML, CSS and Markdown, plus folding,
|
|
6
|
+
find and replace, diagnostics, undo/redo and six themes.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
pnpm add @aardarch/aardink-web # or: npm install @aardarch/aardink-web
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
The package is plain ES modules plus two `.wasm` files and a font. It needs a bundler that
|
|
15
|
+
understands `new URL('./file', import.meta.url)`, which Vite, webpack 5 and Rollup all do.
|
|
16
|
+
|
|
17
|
+
## Use
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { createEditor, preloadAardink } from '@aardarch/aardink-web';
|
|
21
|
+
|
|
22
|
+
preloadAardink(); // optional: start loading the WebAssembly module early
|
|
23
|
+
|
|
24
|
+
const editor = await createEditor(document.getElementById('editor')!, (text) => save(text), {
|
|
25
|
+
value: source,
|
|
26
|
+
language: 'xml',
|
|
27
|
+
theme: 'vscode-dark',
|
|
28
|
+
wordWrap: 'on',
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
editor.updateOptions({ readOnly: true });
|
|
32
|
+
editor.setDiagnostics([
|
|
33
|
+
{ line: 3, startColumn: 5, endColumn: 9, message: 'Unknown tag', severity: 'error' },
|
|
34
|
+
]);
|
|
35
|
+
const stop = editor.onDidChangeCursor((line, column) => showPosition(line, column));
|
|
36
|
+
editor.dispose();
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
The editor fills its container, so give the container a size. `createEditor` is async because
|
|
40
|
+
the first call loads the WebAssembly module (about 13 MB, 4.7 MB gzipped); every editor on the
|
|
41
|
+
page shares that one module. See [`index.d.ts`](./index.d.ts) for the full API.
|
|
42
|
+
|
|
43
|
+
## Vite
|
|
44
|
+
|
|
45
|
+
```js
|
|
46
|
+
// vite.config.js
|
|
47
|
+
import { defineConfig } from 'vite';
|
|
48
|
+
|
|
49
|
+
export default defineConfig({
|
|
50
|
+
// The dev-server pre-bundler would move the package into .vite/deps and break the
|
|
51
|
+
// new URL(..., import.meta.url) references the loader relies on.
|
|
52
|
+
optimizeDeps: { exclude: ['@aardarch/aardink-web'] },
|
|
53
|
+
build: { target: 'es2022', chunkSizeWarningLimit: 3500 },
|
|
54
|
+
});
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
`vite build` prints two harmless warnings about `node:fs` and `node:url` being externalised:
|
|
58
|
+
the Kotlin loader has Node and Deno branches that never run in a browser. Serve `.wasm` with
|
|
59
|
+
`Content-Type: application/wasm`.
|
|
60
|
+
|
|
61
|
+
## Browser support
|
|
62
|
+
|
|
63
|
+
Chrome and Edge 119+, Firefox 120+, Safari 18.2+: the module needs WebAssembly garbage
|
|
64
|
+
collection and exception handling.
|
|
65
|
+
|
|
66
|
+
## Known limitations
|
|
67
|
+
|
|
68
|
+
Read these before adopting the package; the
|
|
69
|
+
[integration guide](https://github.com/aardarch/aardink/blob/main/docs/WEB_INTEGRATION.md) has
|
|
70
|
+
the measurements and the device checklist.
|
|
71
|
+
|
|
72
|
+
- **Typing latency grows with document size, and fast typing can lose keys in large files.**
|
|
73
|
+
Up to a few hundred lines of highlighted code it is comfortable. At 1,000 lines each keystroke
|
|
74
|
+
keeps the editor busy for about half a second, and typing at 10 keys a second can drop around
|
|
75
|
+
half the keys. At 5,000 lines each keystroke keeps it busy for several seconds. 0.5.x is for
|
|
76
|
+
small files such as configuration or markup documents; a virtualised renderer that fixes this
|
|
77
|
+
is planned for 0.6.0.
|
|
78
|
+
- **A disposed editor is not fully released** (about 275 KB each), because Compose
|
|
79
|
+
Multiplatform cannot yet tear down its viewport. Reuse one editor with `setValue` and
|
|
80
|
+
`updateOptions` rather than mounting one per view.
|
|
81
|
+
- There is no minimap, bracket-pair colouring or multi-cursor yet.
|
|
82
|
+
|
|
83
|
+
## Licence
|
|
84
|
+
|
|
85
|
+
Apache-2.0. The bundled JetBrains Mono font is under the SIL Open Font License 1.1; see
|
|
86
|
+
`JETBRAINS_MONO_OFL.txt`.
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026 Aardarch
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** Editor options. Every field is optional; `updateOptions` changes only the ones you pass. */
|
|
18
|
+
export interface AardinkOptions {
|
|
19
|
+
/** Initial text. Only read by `createEditor`. */
|
|
20
|
+
value?: string;
|
|
21
|
+
/** A language id: kotlin, typescript, json, toml, xml, html, css, markdown, plaintext. */
|
|
22
|
+
language?: string;
|
|
23
|
+
/** vscode-dark, vscode-light, material-dark, material-light, midnight-ocean, solarized-dark. */
|
|
24
|
+
theme?: string;
|
|
25
|
+
/** In CSS pixels. */
|
|
26
|
+
fontSize?: number;
|
|
27
|
+
wordWrap?: 'on' | 'off';
|
|
28
|
+
readOnly?: boolean;
|
|
29
|
+
showGutter?: boolean;
|
|
30
|
+
showLineNumbers?: boolean;
|
|
31
|
+
showFoldMarkers?: boolean;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Monaco-marker shape: 1-based line and columns, `endColumn` exclusive. */
|
|
35
|
+
export interface AardinkDiagnostic {
|
|
36
|
+
line: number;
|
|
37
|
+
startColumn: number;
|
|
38
|
+
endColumn: number;
|
|
39
|
+
message: string;
|
|
40
|
+
severity: 'error' | 'warning' | 'info';
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface AardinkEditor {
|
|
44
|
+
getValue(): string;
|
|
45
|
+
/** Replaces the whole text and clears undo history. Fires the change listeners. */
|
|
46
|
+
setValue(text: string): void;
|
|
47
|
+
updateOptions(options: Partial<AardinkOptions>): void;
|
|
48
|
+
/** Full text after every change, at most once per frame. Returns an unsubscribe function. */
|
|
49
|
+
onDidChangeContent(listener: (text: string) => void): () => void;
|
|
50
|
+
/** 1-based caret position. Returns an unsubscribe function. */
|
|
51
|
+
onDidChangeCursor(listener: (line: number, column: number) => void): () => void;
|
|
52
|
+
setDiagnostics(diagnostics: AardinkDiagnostic[]): void;
|
|
53
|
+
revealPosition(line: number, column: number): void;
|
|
54
|
+
showFind(): void;
|
|
55
|
+
undo(): boolean;
|
|
56
|
+
redo(): boolean;
|
|
57
|
+
/** Stops the editor. Safe to call twice. Remove or reuse the container yourself. */
|
|
58
|
+
dispose(): void;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Mounts an editor that fills `container`. Loads the WebAssembly module on first use (see
|
|
63
|
+
* `preloadAardink`). `onChange` is registered as the first content listener.
|
|
64
|
+
*/
|
|
65
|
+
export function createEditor(
|
|
66
|
+
container: HTMLElement,
|
|
67
|
+
onChange?: (text: string) => void,
|
|
68
|
+
options?: AardinkOptions,
|
|
69
|
+
): Promise<AardinkEditor>;
|
|
70
|
+
|
|
71
|
+
/** Starts loading the WebAssembly module without mounting anything. */
|
|
72
|
+
export function preloadAardink(): Promise<void>;
|
|
73
|
+
|
|
74
|
+
/** The Aardink version this package was built from. */
|
|
75
|
+
export const version: string;
|
package/index.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026 Aardarch
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
// Adapts the Kotlin module's integer-handle exports (aardinkCreate, aardinkGetValue, ...) into
|
|
18
|
+
// the Monaco-shaped object described in index.d.ts.
|
|
19
|
+
|
|
20
|
+
export const version = '0.5.0';
|
|
21
|
+
|
|
22
|
+
let kotlinModule;
|
|
23
|
+
|
|
24
|
+
function load() {
|
|
25
|
+
// Memoised: every editor on the page shares one WebAssembly instance.
|
|
26
|
+
kotlinModule ??= import('./kotlin/aardink-web.mjs').then((k) => {
|
|
27
|
+
// Compose looks for resources relative to the page, not this package. A literal
|
|
28
|
+
// new URL(..., import.meta.url) is also what makes a bundler (Vite) emit the font file.
|
|
29
|
+
k.aardinkSetBundledFontUrl(
|
|
30
|
+
new URL('./kotlin/composeResources/com.aardarch.aardink.web.res/font/jetbrains_mono_regular.ttf', import.meta.url).href,
|
|
31
|
+
);
|
|
32
|
+
return k;
|
|
33
|
+
});
|
|
34
|
+
return kotlinModule;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function preloadAardink() {
|
|
38
|
+
return load().then(() => undefined);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
let generatedIds = 0;
|
|
42
|
+
|
|
43
|
+
/** Keeps only the fields the Kotlin side knows, translating Monaco's wordWrap 'on'/'off'. */
|
|
44
|
+
function toKotlinOptions(options) {
|
|
45
|
+
const out = {};
|
|
46
|
+
for (const key of ['language', 'theme', 'fontSize', 'readOnly', 'showGutter', 'showLineNumbers', 'showFoldMarkers']) {
|
|
47
|
+
if (options[key] !== undefined) out[key] = options[key];
|
|
48
|
+
}
|
|
49
|
+
if (options.wordWrap !== undefined) out.wordWrap = options.wordWrap === 'on';
|
|
50
|
+
return out;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export async function createEditor(container, onChange, options = {}) {
|
|
54
|
+
const k = await load();
|
|
55
|
+
if (!container.id) container.id = `aardink-editor-${++generatedIds}`;
|
|
56
|
+
const id = k.aardinkCreate(container.id, options.value ?? '', JSON.stringify(toKotlinOptions(options)));
|
|
57
|
+
|
|
58
|
+
// The Kotlin side holds one listener of each kind; fan out to any number here.
|
|
59
|
+
const contentListeners = new Set();
|
|
60
|
+
const cursorListeners = new Set();
|
|
61
|
+
k.aardinkOnChange(id, (text) => contentListeners.forEach((listener) => listener(text)));
|
|
62
|
+
k.aardinkOnCursorChange(id, (line, column) => cursorListeners.forEach((listener) => listener(line, column)));
|
|
63
|
+
if (onChange) contentListeners.add(onChange);
|
|
64
|
+
|
|
65
|
+
let disposed = false;
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
getValue: () => k.aardinkGetValue(id),
|
|
69
|
+
setValue: (text) => k.aardinkSetValue(id, text),
|
|
70
|
+
updateOptions: (patch) => k.aardinkUpdateOptions(id, JSON.stringify(toKotlinOptions(patch))),
|
|
71
|
+
onDidChangeContent(listener) {
|
|
72
|
+
contentListeners.add(listener);
|
|
73
|
+
return () => contentListeners.delete(listener);
|
|
74
|
+
},
|
|
75
|
+
onDidChangeCursor(listener) {
|
|
76
|
+
cursorListeners.add(listener);
|
|
77
|
+
return () => cursorListeners.delete(listener);
|
|
78
|
+
},
|
|
79
|
+
setDiagnostics: (diagnostics) => k.aardinkSetDiagnostics(id, JSON.stringify(diagnostics)),
|
|
80
|
+
revealPosition: (line, column) => k.aardinkRevealPosition(id, line, column),
|
|
81
|
+
showFind: () => k.aardinkShowFind(id),
|
|
82
|
+
undo: () => k.aardinkUndo(id),
|
|
83
|
+
redo: () => k.aardinkRedo(id),
|
|
84
|
+
dispose() {
|
|
85
|
+
if (disposed) return;
|
|
86
|
+
disposed = true;
|
|
87
|
+
contentListeners.clear();
|
|
88
|
+
cursorListeners.clear();
|
|
89
|
+
k.aardinkDispose(id);
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
}
|