@eventuras/ratio-ui-shiki 0.0.0-stage → 0.2.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/LICENSE +394 -0
- package/README.md +145 -2
- package/dist/CodeBlock/CodeBlock.d.ts +40 -0
- package/dist/CodeBlock/CodeBlock.d.ts.map +1 -0
- package/dist/CodeBlock/CodeBlock.js +55 -0
- package/dist/CodeBlock/CodeBlock.js.map +1 -0
- package/dist/CodeBlock/index.d.ts +2 -0
- package/dist/CodeBlock/index.d.ts.map +1 -0
- package/dist/CodeBlock/index.js +3 -0
- package/dist/highlighter.d.ts +68 -0
- package/dist/highlighter.d.ts.map +1 -0
- package/dist/highlighter.js +120 -0
- package/dist/highlighter.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/tokens/index.d.ts +46 -0
- package/dist/tokens/index.d.ts.map +1 -0
- package/dist/tokens/index.js +60 -0
- package/dist/tokens/index.js.map +1 -0
- package/dist/useShikiHighlighter/index.d.ts +14 -0
- package/dist/useShikiHighlighter/index.d.ts.map +1 -0
- package/dist/useShikiHighlighter/index.js +49 -0
- package/dist/useShikiHighlighter/index.js.map +1 -0
- package/package.json +73 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
Ratio UI Shiki — Shiki syntax highlighting for the Ratio UI design system
|
|
2
|
+
Copyright (c) 2026 Losol AS.
|
|
3
|
+
|
|
4
|
+
@eventuras/ratio-ui-shiki is licensed under the Mozilla Public License, Version 2.0 (MPL-2.0).
|
|
5
|
+
The full license text is reproduced below and is also available at
|
|
6
|
+
https://mozilla.org/MPL/2.0/.
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
Mozilla Public License Version 2.0
|
|
11
|
+
==================================
|
|
12
|
+
|
|
13
|
+
1. Definitions
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
1.1. "Contributor"
|
|
18
|
+
means each individual or legal entity that creates, contributes to
|
|
19
|
+
the creation of, or owns Covered Software.
|
|
20
|
+
|
|
21
|
+
1.2. "Contributor Version"
|
|
22
|
+
means the combination of the Contributions of others (if any) used
|
|
23
|
+
by a Contributor and that particular Contributor's Contribution.
|
|
24
|
+
|
|
25
|
+
1.3. "Contribution"
|
|
26
|
+
means Covered Software of a particular Contributor.
|
|
27
|
+
|
|
28
|
+
1.4. "Covered Software"
|
|
29
|
+
means Source Code Form to which the initial Contributor has attached
|
|
30
|
+
the notice in Exhibit A, the Executable Form of such Source Code
|
|
31
|
+
Form, and Modifications of such Source Code Form, in each case
|
|
32
|
+
including portions thereof.
|
|
33
|
+
|
|
34
|
+
1.5. "Incompatible With Secondary Licenses"
|
|
35
|
+
means
|
|
36
|
+
|
|
37
|
+
(a) that the initial Contributor has attached the notice described
|
|
38
|
+
in Exhibit B to the Covered Software; or
|
|
39
|
+
|
|
40
|
+
(b) that the Covered Software was made available under the terms of
|
|
41
|
+
version 1.1 or earlier of the License, but not also under the
|
|
42
|
+
terms of a Secondary License.
|
|
43
|
+
|
|
44
|
+
1.6. "Executable Form"
|
|
45
|
+
means any form of the work other than Source Code Form.
|
|
46
|
+
|
|
47
|
+
1.7. "Larger Work"
|
|
48
|
+
means a work that combines Covered Software with other material, in
|
|
49
|
+
a separate file or files, that is not Covered Software.
|
|
50
|
+
|
|
51
|
+
1.8. "License"
|
|
52
|
+
means this document.
|
|
53
|
+
|
|
54
|
+
1.9. "Licensable"
|
|
55
|
+
means having the right to grant, to the maximum extent possible,
|
|
56
|
+
whether at the time of the initial grant or subsequently, any and
|
|
57
|
+
all of the rights conveyed by this License.
|
|
58
|
+
|
|
59
|
+
1.10. "Modifications"
|
|
60
|
+
means any of the following:
|
|
61
|
+
|
|
62
|
+
(a) any file in Source Code Form that results from an addition to,
|
|
63
|
+
deletion from, or modification of the contents of Covered
|
|
64
|
+
Software; or
|
|
65
|
+
|
|
66
|
+
(b) any new file in Source Code Form that contains any Covered
|
|
67
|
+
Software.
|
|
68
|
+
|
|
69
|
+
1.11. "Patent Claims" of a Contributor
|
|
70
|
+
means any patent claim(s), including without limitation, method,
|
|
71
|
+
process, and apparatus claims, in any patent Licensable by such
|
|
72
|
+
Contributor that would be infringed, but for the grant of the
|
|
73
|
+
License, by the making, using, selling, offering for sale, having
|
|
74
|
+
made, import, or transfer of either its Contributions or its
|
|
75
|
+
Contributor Version.
|
|
76
|
+
|
|
77
|
+
1.12. "Secondary License"
|
|
78
|
+
means either the GNU General Public License, Version 2.0, the GNU
|
|
79
|
+
Lesser General Public License, Version 2.1, the GNU Affero General
|
|
80
|
+
Public License, Version 3.0, or any later versions of those
|
|
81
|
+
licenses.
|
|
82
|
+
|
|
83
|
+
1.13. "Source Code Form"
|
|
84
|
+
means the form of the work preferred for making modifications.
|
|
85
|
+
|
|
86
|
+
1.14. "You" (or "Your")
|
|
87
|
+
means an individual or a legal entity exercising rights under this
|
|
88
|
+
License. For legal entities, "You" includes any entity that
|
|
89
|
+
controls, is controlled by, or is under common control with You. For
|
|
90
|
+
purposes of this definition, "control" means (a) the power, direct
|
|
91
|
+
or indirect, to cause the direction or management of such entity,
|
|
92
|
+
whether by contract or otherwise, or (b) ownership of more than
|
|
93
|
+
fifty percent (50%) of the outstanding shares or beneficial
|
|
94
|
+
ownership of such entity.
|
|
95
|
+
|
|
96
|
+
2. License Grants and Conditions
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
2.1. Grants
|
|
101
|
+
|
|
102
|
+
Each Contributor hereby grants You a world-wide, royalty-free,
|
|
103
|
+
non-exclusive license:
|
|
104
|
+
|
|
105
|
+
(a) under intellectual property rights (other than patent or trademark)
|
|
106
|
+
Licensable by such Contributor to use, reproduce, make available,
|
|
107
|
+
modify, display, perform, distribute, and otherwise exploit its
|
|
108
|
+
Contributions, either on an unmodified basis, with Modifications, or
|
|
109
|
+
as part of a Larger Work; and
|
|
110
|
+
|
|
111
|
+
(b) under Patent Claims of such Contributor to make, use, sell, offer
|
|
112
|
+
for sale, have made, import, and otherwise transfer either its
|
|
113
|
+
Contributions or its Contributor Version.
|
|
114
|
+
|
|
115
|
+
2.2. Effective Date
|
|
116
|
+
|
|
117
|
+
The licenses granted in Section 2.1 with respect to any Contribution
|
|
118
|
+
become effective for each Contribution on the date the Contributor first
|
|
119
|
+
distributes such Contribution.
|
|
120
|
+
|
|
121
|
+
2.3. Limitations on Grant Scope
|
|
122
|
+
|
|
123
|
+
The licenses granted in this Section 2 are the only rights granted under
|
|
124
|
+
this License. No additional rights or licenses will be implied from the
|
|
125
|
+
distribution or licensing of Covered Software under this License.
|
|
126
|
+
Notwithstanding Section 2.1(b) above, no patent license is granted by a
|
|
127
|
+
Contributor:
|
|
128
|
+
|
|
129
|
+
(a) for any code that a Contributor has removed from Covered Software;
|
|
130
|
+
or
|
|
131
|
+
|
|
132
|
+
(b) for infringements caused by: (i) Your and any other third party's
|
|
133
|
+
modifications of Covered Software, or (ii) the combination of its
|
|
134
|
+
Contributions with other software (except as part of its Contributor
|
|
135
|
+
Version); or
|
|
136
|
+
|
|
137
|
+
(c) under Patent Claims infringed by Covered Software in the absence of
|
|
138
|
+
its Contributions.
|
|
139
|
+
|
|
140
|
+
This License does not grant any rights in the trademarks, service marks,
|
|
141
|
+
or logos of any Contributor (except as may be necessary to comply with
|
|
142
|
+
the notice requirements in Section 3.4).
|
|
143
|
+
|
|
144
|
+
2.4. Subsequent Licenses
|
|
145
|
+
|
|
146
|
+
No Contributor makes additional grants as a result of Your choice to
|
|
147
|
+
distribute the Covered Software under a subsequent version of this
|
|
148
|
+
License (see Section 10.2) or under the terms of a Secondary License (if
|
|
149
|
+
permitted under the terms of Section 3.3).
|
|
150
|
+
|
|
151
|
+
2.5. Representation
|
|
152
|
+
|
|
153
|
+
Each Contributor represents that the Contributor believes its
|
|
154
|
+
Contributions are its original creation(s) or it has sufficient rights
|
|
155
|
+
to grant the rights to its Contributions conveyed by this License.
|
|
156
|
+
|
|
157
|
+
2.6. Fair Use
|
|
158
|
+
|
|
159
|
+
This License is not intended to limit any rights You have under
|
|
160
|
+
applicable copyright doctrines of fair use, fair dealing, or other
|
|
161
|
+
equivalents.
|
|
162
|
+
|
|
163
|
+
2.7. Conditions
|
|
164
|
+
|
|
165
|
+
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
|
|
166
|
+
in Section 2.1.
|
|
167
|
+
|
|
168
|
+
3. Responsibilities
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
3.1. Distribution of Source Form
|
|
173
|
+
|
|
174
|
+
All distribution of Covered Software in Source Code Form, including any
|
|
175
|
+
Modifications that You create or to which You contribute, must be under
|
|
176
|
+
the terms of this License. You must inform recipients that the Source
|
|
177
|
+
Code Form of the Covered Software is governed by the terms of this
|
|
178
|
+
License, and how they can obtain a copy of this License. You may not
|
|
179
|
+
attempt to alter or restrict the recipients' rights in the Source Code
|
|
180
|
+
Form.
|
|
181
|
+
|
|
182
|
+
3.2. Distribution of Executable Form
|
|
183
|
+
|
|
184
|
+
If You distribute Covered Software in Executable Form then:
|
|
185
|
+
|
|
186
|
+
(a) such Covered Software must also be made available in Source Code
|
|
187
|
+
Form, as described in Section 3.1, and You must inform recipients of
|
|
188
|
+
the Executable Form how they can obtain a copy of such Source Code
|
|
189
|
+
Form by reasonable means in a timely manner, at a charge no more
|
|
190
|
+
than the cost of distribution to the recipient; and
|
|
191
|
+
|
|
192
|
+
(b) You may distribute such Executable Form under the terms of this
|
|
193
|
+
License, or sublicense it under different terms, provided that the
|
|
194
|
+
license for the Executable Form does not attempt to limit or alter
|
|
195
|
+
the recipients' rights in the Source Code Form under this License.
|
|
196
|
+
|
|
197
|
+
3.3. Distribution of a Larger Work
|
|
198
|
+
|
|
199
|
+
You may create and distribute a Larger Work under terms of Your choice,
|
|
200
|
+
provided that You also comply with the requirements of this License for
|
|
201
|
+
the Covered Software. If the Larger Work is a combination of Covered
|
|
202
|
+
Software with a work governed by one or more Secondary Licenses, and the
|
|
203
|
+
Covered Software is not Incompatible With Secondary Licenses, this
|
|
204
|
+
License permits You to additionally distribute such Covered Software
|
|
205
|
+
under the terms of such Secondary License(s), so that the recipient of
|
|
206
|
+
the Larger Work may, at their option, further distribute the Covered
|
|
207
|
+
Software under the terms of either this License or such Secondary
|
|
208
|
+
License(s).
|
|
209
|
+
|
|
210
|
+
3.4. Notices
|
|
211
|
+
|
|
212
|
+
You may not remove or alter the substance of any license notices
|
|
213
|
+
(including copyright notices, patent notices, disclaimers of warranty,
|
|
214
|
+
or limitations of liability) contained within the Source Code Form of
|
|
215
|
+
the Covered Software, except that You may alter any license notices to
|
|
216
|
+
the extent required to remedy known factual inaccuracies.
|
|
217
|
+
|
|
218
|
+
3.5. Application of Additional Terms
|
|
219
|
+
|
|
220
|
+
You may choose to offer, and to charge a fee for, warranty, support,
|
|
221
|
+
indemnity or liability obligations to one or more recipients of Covered
|
|
222
|
+
Software. However, You may do so only on Your own behalf, and not on
|
|
223
|
+
behalf of any Contributor. You must make it absolutely clear that any
|
|
224
|
+
such warranty, support, indemnity, or liability obligation is offered by
|
|
225
|
+
You alone, and You hereby agree to indemnify every Contributor for any
|
|
226
|
+
liability incurred by such Contributor as a result of warranty, support,
|
|
227
|
+
indemnity or liability terms You offer. You may include additional
|
|
228
|
+
disclaimers of warranty and limitations of liability specific to any
|
|
229
|
+
jurisdiction.
|
|
230
|
+
|
|
231
|
+
4. Inability to Comply Due to Statute or Regulation
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
If it is impossible for You to comply with any of the terms of this
|
|
236
|
+
License with respect to some or all of the Covered Software due to
|
|
237
|
+
statute, judicial order, or regulation then You must: (a) comply with
|
|
238
|
+
the terms of this License to the maximum extent possible; and (b)
|
|
239
|
+
describe the limitations and the code they affect. Such description must
|
|
240
|
+
be placed in a text file included with all distributions of the Covered
|
|
241
|
+
Software under this License. Except to the extent prohibited by statute
|
|
242
|
+
or regulation, such description must be sufficiently detailed for a
|
|
243
|
+
recipient of ordinary skill to be able to understand it.
|
|
244
|
+
|
|
245
|
+
5. Termination
|
|
246
|
+
|
|
247
|
+
---
|
|
248
|
+
|
|
249
|
+
5.1. The rights granted under this License will terminate automatically
|
|
250
|
+
if You fail to comply with any of its terms. However, if You become
|
|
251
|
+
compliant, then the rights granted under this License from a particular
|
|
252
|
+
Contributor are reinstated (a) provisionally, unless and until such
|
|
253
|
+
Contributor explicitly and finally terminates Your grants, and (b) on an
|
|
254
|
+
ongoing basis, if such Contributor fails to notify You of the
|
|
255
|
+
non-compliance by some reasonable means prior to 60 days after You have
|
|
256
|
+
come back into compliance. Moreover, Your grants from a particular
|
|
257
|
+
Contributor are reinstated on an ongoing basis if such Contributor
|
|
258
|
+
notifies You of the non-compliance by some reasonable means, this is the
|
|
259
|
+
first time You have received notice of non-compliance with this License
|
|
260
|
+
from such Contributor, and You become compliant prior to 30 days after
|
|
261
|
+
Your receipt of the notice.
|
|
262
|
+
|
|
263
|
+
5.2. If You initiate litigation against any entity by asserting a patent
|
|
264
|
+
infringement claim (excluding declaratory judgment actions,
|
|
265
|
+
counter-claims, and cross-claims) alleging that a Contributor Version
|
|
266
|
+
directly or indirectly infringes any patent, then the rights granted to
|
|
267
|
+
You by any and all Contributors for the Covered Software under Section
|
|
268
|
+
2.1 of this License shall terminate.
|
|
269
|
+
|
|
270
|
+
5.3. In the event of termination under Sections 5.1 or 5.2 above, all
|
|
271
|
+
end user license agreements (excluding distributors and resellers) which
|
|
272
|
+
have been validly granted by You or Your distributors under this License
|
|
273
|
+
prior to termination shall survive termination.
|
|
274
|
+
|
|
275
|
+
---
|
|
276
|
+
|
|
277
|
+
- *
|
|
278
|
+
- 6. Disclaimer of Warranty *
|
|
279
|
+
- ------------------------- *
|
|
280
|
+
- *
|
|
281
|
+
- Covered Software is provided under this License on an "as is" *
|
|
282
|
+
- basis, without warranty of any kind, either expressed, implied, or *
|
|
283
|
+
- statutory, including, without limitation, warranties that the *
|
|
284
|
+
- Covered Software is free of defects, merchantable, fit for a *
|
|
285
|
+
- particular purpose or non-infringing. The entire risk as to the *
|
|
286
|
+
- quality and performance of the Covered Software is with You. *
|
|
287
|
+
- Should any Covered Software prove defective in any respect, You *
|
|
288
|
+
- (not any Contributor) assume the cost of any necessary servicing, *
|
|
289
|
+
- repair, or correction. This disclaimer of warranty constitutes an *
|
|
290
|
+
- essential part of this License. No use of any Covered Software is *
|
|
291
|
+
- authorized under this License except under this disclaimer. *
|
|
292
|
+
- *
|
|
293
|
+
|
|
294
|
+
---
|
|
295
|
+
|
|
296
|
+
---
|
|
297
|
+
|
|
298
|
+
- *
|
|
299
|
+
- 7. Limitation of Liability *
|
|
300
|
+
- -------------------------- *
|
|
301
|
+
- *
|
|
302
|
+
- Under no circumstances and under no legal theory, whether tort *
|
|
303
|
+
- (including negligence), contract, or otherwise, shall any *
|
|
304
|
+
- Contributor, or anyone who distributes Covered Software as *
|
|
305
|
+
- permitted above, be liable to You for any direct, indirect, *
|
|
306
|
+
- special, incidental, or consequential damages of any character *
|
|
307
|
+
- including, without limitation, damages for lost profits, loss of *
|
|
308
|
+
- goodwill, work stoppage, computer failure or malfunction, or any *
|
|
309
|
+
- and all other commercial damages or losses, even if such party *
|
|
310
|
+
- shall have been informed of the possibility of such damages. This *
|
|
311
|
+
- limitation of liability shall not apply to liability for death or *
|
|
312
|
+
- personal injury resulting from such party's negligence to the *
|
|
313
|
+
- extent applicable law prohibits such limitation. Some *
|
|
314
|
+
- jurisdictions do not allow the exclusion or limitation of *
|
|
315
|
+
- incidental or consequential damages, so this exclusion and *
|
|
316
|
+
- limitation may not apply to You. *
|
|
317
|
+
- *
|
|
318
|
+
|
|
319
|
+
---
|
|
320
|
+
|
|
321
|
+
8. Litigation
|
|
322
|
+
|
|
323
|
+
---
|
|
324
|
+
|
|
325
|
+
Any litigation relating to this License may be brought only in the
|
|
326
|
+
courts of a jurisdiction where the defendant maintains its principal
|
|
327
|
+
place of business and such litigation shall be governed by laws of that
|
|
328
|
+
jurisdiction, without reference to its conflict-of-law provisions.
|
|
329
|
+
Nothing in this Section shall prevent a party's ability to bring
|
|
330
|
+
cross-claims or counter-claims.
|
|
331
|
+
|
|
332
|
+
9. Miscellaneous
|
|
333
|
+
|
|
334
|
+
---
|
|
335
|
+
|
|
336
|
+
This License represents the complete agreement concerning the subject
|
|
337
|
+
matter hereof. If any provision of this License is held to be
|
|
338
|
+
unenforceable, such provision shall be reformed only to the extent
|
|
339
|
+
necessary to make it enforceable. Any law or regulation which provides
|
|
340
|
+
that the language of a contract shall be construed against the drafter
|
|
341
|
+
shall not be used to construe this License against a Contributor.
|
|
342
|
+
|
|
343
|
+
10. Versions of the License
|
|
344
|
+
|
|
345
|
+
---
|
|
346
|
+
|
|
347
|
+
10.1. New Versions
|
|
348
|
+
|
|
349
|
+
Mozilla Foundation is the license steward. Except as provided in Section
|
|
350
|
+
10.3, no one other than the license steward has the right to modify or
|
|
351
|
+
publish new versions of this License. Each version will be given a
|
|
352
|
+
distinguishing version number.
|
|
353
|
+
|
|
354
|
+
10.2. Effect of New Versions
|
|
355
|
+
|
|
356
|
+
You may distribute the Covered Software under the terms of the version
|
|
357
|
+
of the License under which You originally received the Covered Software,
|
|
358
|
+
or under the terms of any subsequent version published by the license
|
|
359
|
+
steward.
|
|
360
|
+
|
|
361
|
+
10.3. Modified Versions
|
|
362
|
+
|
|
363
|
+
If you create software not governed by this License, and you want to
|
|
364
|
+
create a new license for such software, you may create and use a
|
|
365
|
+
modified version of this License if you rename the license and remove
|
|
366
|
+
any references to the name of the license steward (except to note that
|
|
367
|
+
such modified license differs from this License).
|
|
368
|
+
|
|
369
|
+
10.4. Distributing Source Code Form that is Incompatible With Secondary
|
|
370
|
+
Licenses
|
|
371
|
+
|
|
372
|
+
If You choose to distribute Source Code Form that is Incompatible With
|
|
373
|
+
Secondary Licenses under the terms of this version of the License, the
|
|
374
|
+
notice described in Exhibit B of this License must be attached.
|
|
375
|
+
|
|
376
|
+
Exhibit A - Source Code Form License Notice
|
|
377
|
+
-------------------------------------------
|
|
378
|
+
|
|
379
|
+
This Source Code Form is subject to the terms of the Mozilla Public
|
|
380
|
+
License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
381
|
+
file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
382
|
+
|
|
383
|
+
If it is not possible or desirable to put the notice in a particular
|
|
384
|
+
file, then You may include the notice in a location (such as a LICENSE
|
|
385
|
+
file in a relevant directory) where a recipient would be likely to look
|
|
386
|
+
for such a notice.
|
|
387
|
+
|
|
388
|
+
You may add additional accurate notices of copyright ownership.
|
|
389
|
+
|
|
390
|
+
Exhibit B - "Incompatible With Secondary Licenses" Notice
|
|
391
|
+
---------------------------------------------------------
|
|
392
|
+
|
|
393
|
+
This Source Code Form is "Incompatible With Secondary Licenses", as
|
|
394
|
+
defined by the Mozilla Public License, v. 2.0.
|
package/README.md
CHANGED
|
@@ -1,3 +1,146 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @eventuras/ratio-ui-shiki
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> ⚠️ **Alpha.** Experimental and unstable — the API may change or be removed
|
|
4
|
+
> without notice, and it is published under the `alpha` npm dist-tag. Pin an
|
|
5
|
+
> exact version if you depend on it.
|
|
6
|
+
|
|
7
|
+
[Shiki](https://shiki.style) syntax highlighting for Ratio UI's
|
|
8
|
+
[`CodeBlock`](../ratio-ui/src/core/CodeBlock). The core `CodeBlock` stays
|
|
9
|
+
presentational and highlighter-agnostic; this companion package adds the Shiki
|
|
10
|
+
layer so you don't wire it yourself.
|
|
11
|
+
|
|
12
|
+
Built on `shiki/core` (fine-grained) with the WASM-free JavaScript regex engine,
|
|
13
|
+
so consumers bundle only the curated grammars — not Shiki's full registry.
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pnpm add @eventuras/ratio-ui @eventuras/ratio-ui-shiki shiki @shikijs/langs @shikijs/themes
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
`@eventuras/ratio-ui`, `shiki`, and Shiki's `@shikijs/langs` / `@shikijs/themes`
|
|
22
|
+
are peer dependencies — you control their versions. The `@shikijs/*` packages
|
|
23
|
+
ship with, and version-match, `shiki`.
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
A drop-in for the core `CodeBlock` that highlights `code` client-side:
|
|
28
|
+
|
|
29
|
+
```tsx
|
|
30
|
+
import { CodeBlock } from '@eventuras/ratio-ui-shiki/CodeBlock';
|
|
31
|
+
|
|
32
|
+
<CodeBlock code={source} language="tsx" />;
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
It loads a shared highlighter asynchronously and renders raw code until it is
|
|
36
|
+
ready — no flash of missing content. Token colors **follow the app's light/dark
|
|
37
|
+
mode** automatically (via `data-theme` / `data-color-scheme`, like the rest of
|
|
38
|
+
ratio-ui).
|
|
39
|
+
|
|
40
|
+
### Static / server-rendered highlighting
|
|
41
|
+
|
|
42
|
+
For docs or RSC, highlight ahead of time and pass the result to the **core**
|
|
43
|
+
`CodeBlock` — then no highlighter ships to the client:
|
|
44
|
+
|
|
45
|
+
```tsx
|
|
46
|
+
import { CodeBlock } from '@eventuras/ratio-ui/core/CodeBlock';
|
|
47
|
+
import { createRatioHighlighter, shikiToDualLines, DUAL_THEME_CSS } from '@eventuras/ratio-ui-shiki';
|
|
48
|
+
|
|
49
|
+
// Render DUAL_THEME_CSS once, high in your tree, so token colors follow the
|
|
50
|
+
// app's light/dark mode (the client `<CodeBlock>` injects this for you):
|
|
51
|
+
<style dangerouslySetInnerHTML={{ __html: DUAL_THEME_CSS }} />;
|
|
52
|
+
|
|
53
|
+
const hl = await createRatioHighlighter();
|
|
54
|
+
<CodeBlock
|
|
55
|
+
code={source}
|
|
56
|
+
language="tsx"
|
|
57
|
+
highlightedLines={shikiToDualLines(hl, source, 'tsx')}
|
|
58
|
+
/>;
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
`shikiToLines` is the single-theme equivalent if you don't need light/dark (no
|
|
62
|
+
`DUAL_THEME_CSS` needed — colors are inline). Because `highlightedLines` is an
|
|
63
|
+
array of React nodes (not an HTML string), this path never uses
|
|
64
|
+
`dangerouslySetInnerHTML` — it is injection-safe by construction.
|
|
65
|
+
|
|
66
|
+
### Precomputed tokens: highlight at build time, render without Shiki
|
|
67
|
+
|
|
68
|
+
When the page re-renders on the client (SPA, or React Router's `ssr: false` +
|
|
69
|
+
prerender), `shikiToDualLines` isn't enough — whatever produces the lines must
|
|
70
|
+
also run in the browser. Split it in two instead: tokenize in a **build
|
|
71
|
+
script** with `codeToDualTokens`, ship the result as JSON, and render it with
|
|
72
|
+
`tokensToLines` from the Shiki-free `tokens` entrypoint. The client then
|
|
73
|
+
bundles ~1 kB — no grammars, no engine — and code is highlighted from the very
|
|
74
|
+
first paint.
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
// build script (Node) — runs once per build
|
|
78
|
+
import { createRatioHighlighter, codeToDualTokens } from '@eventuras/ratio-ui-shiki';
|
|
79
|
+
|
|
80
|
+
const hl = await createRatioHighlighter();
|
|
81
|
+
const tokens = codeToDualTokens(hl, source, 'tsx');
|
|
82
|
+
await fs.writeFile('tokens.json', JSON.stringify(tokens));
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
```tsx
|
|
86
|
+
// client — imports only the tiny tokens module, never Shiki
|
|
87
|
+
import { CodeBlock } from '@eventuras/ratio-ui/core/CodeBlock';
|
|
88
|
+
import { tokensToLines, DualThemeStyles } from '@eventuras/ratio-ui-shiki/tokens';
|
|
89
|
+
import tokens from './tokens.json';
|
|
90
|
+
|
|
91
|
+
<DualThemeStyles />
|
|
92
|
+
<CodeBlock code={source} language="tsx" highlightedLines={tokensToLines(tokens)} />;
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
`shikiToDualLines(hl, code, lang)` is exactly
|
|
96
|
+
`tokensToLines(codeToDualTokens(hl, code, lang))` — the two paths render
|
|
97
|
+
byte-identical markup (unit-tested), so you can start client-side and move to
|
|
98
|
+
precomputed tokens later without visual change.
|
|
99
|
+
|
|
100
|
+
### Advanced: `useShikiHighlighter`
|
|
101
|
+
|
|
102
|
+
The hook the `<CodeBlock>` wrapper is built on. It loads (and shares) the
|
|
103
|
+
default highlighter for your own compositions — `null` while loading, then the
|
|
104
|
+
ready highlighter:
|
|
105
|
+
|
|
106
|
+
```tsx
|
|
107
|
+
import { useMemo } from 'react';
|
|
108
|
+
import { CodeBlock } from '@eventuras/ratio-ui/core/CodeBlock';
|
|
109
|
+
import { shikiToDualLines } from '@eventuras/ratio-ui-shiki';
|
|
110
|
+
import { useShikiHighlighter } from '@eventuras/ratio-ui-shiki/useShikiHighlighter';
|
|
111
|
+
|
|
112
|
+
function Code({ source }: { source: string }) {
|
|
113
|
+
const hl = useShikiHighlighter();
|
|
114
|
+
const lines = useMemo(
|
|
115
|
+
() => (hl ? shikiToDualLines(hl, source, 'tsx') : undefined),
|
|
116
|
+
[hl, source],
|
|
117
|
+
);
|
|
118
|
+
return <CodeBlock code={source} language="tsx" highlightedLines={lines} />;
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Need other languages or themes? Create a highlighter with your own imports and
|
|
123
|
+
pass it in (`langs` / `themes` **replace** the defaults, so include everything
|
|
124
|
+
you need):
|
|
125
|
+
|
|
126
|
+
```tsx
|
|
127
|
+
const hl = await createRatioHighlighter({
|
|
128
|
+
langs: [import('@shikijs/langs/rust'), import('@shikijs/langs/tsx')],
|
|
129
|
+
});
|
|
130
|
+
// useShikiHighlighter(hl) — or <CodeBlock highlighter={hl} … />
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Notes
|
|
134
|
+
|
|
135
|
+
- `createRatioHighlighter` preloads a curated language set (`DEFAULT_LANGS`: tsx,
|
|
136
|
+
ts, jsx, js, json, bash, css, html, markdown, yaml, xml, python, csharp) and
|
|
137
|
+
the `github-light` / `github-dark` pair. Pass `langs` / `themes` as Shiki
|
|
138
|
+
inputs (e.g. `import('@shikijs/langs/go')`) to change the set.
|
|
139
|
+
- The client `<CodeBlock>` injects `DUAL_THEME_CSS` itself (React style
|
|
140
|
+
hoisting); include it manually only when you render dual-theme lines by hand.
|
|
141
|
+
- Entrypoints are split for RSC: the root (`.`) is server-safe (highlighter
|
|
142
|
+
helpers + `DUAL_THEME_CSS` + types); the client component and hook live at
|
|
143
|
+
`@eventuras/ratio-ui-shiki/CodeBlock` and `.../useShikiHighlighter`; the
|
|
144
|
+
Shiki-free precomputed-token renderer lives at
|
|
145
|
+
`@eventuras/ratio-ui-shiki/tokens` (`tokensToLines`, `DualThemeStyles`,
|
|
146
|
+
`DUAL_THEME_CSS`, types — imports nothing from Shiki).
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { CodeBlockProps as CoreCodeBlockProps } from '@eventuras/ratio-ui/core/CodeBlock';
|
|
3
|
+
import { HighlighterCore } from 'shiki/core';
|
|
4
|
+
import { DualThemes } from '../highlighter';
|
|
5
|
+
export interface CodeBlockProps extends Omit<CoreCodeBlockProps, 'highlightedLines'> {
|
|
6
|
+
/**
|
|
7
|
+
* Light + dark Shiki theme pair to render with. The colors follow the app's
|
|
8
|
+
* mode (`data-theme` / `data-color-scheme`), like the rest of ratio-ui.
|
|
9
|
+
*
|
|
10
|
+
* The built-in highlighter only loads `github-light` / `github-dark`; to
|
|
11
|
+
* render a different pair, also pass a `highlighter` that has those themes
|
|
12
|
+
* loaded — otherwise the block falls back to un-highlighted code.
|
|
13
|
+
* @default { light: 'github-light', dark: 'github-dark' }
|
|
14
|
+
*/
|
|
15
|
+
themes?: DualThemes;
|
|
16
|
+
/**
|
|
17
|
+
* Reuse an existing highlighter — e.g. one shared singleton from
|
|
18
|
+
* `createRatioHighlighter` preloaded with your languages — instead of letting
|
|
19
|
+
* this component lazily create its own. Ensure it has `language` and both
|
|
20
|
+
* themes loaded; otherwise the block falls back to un-highlighted code.
|
|
21
|
+
*/
|
|
22
|
+
highlighter?: HighlighterCore;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* `CodeBlock`, wired to Shiki — a drop-in for `@eventuras/ratio-ui/core/CodeBlock`
|
|
26
|
+
* that highlights `code` for the given `language`. It loads a highlighter
|
|
27
|
+
* asynchronously (via `useShikiHighlighter`) and renders raw code until it is
|
|
28
|
+
* ready, so there is no flash of missing content (graceful degradation). Token
|
|
29
|
+
* colors follow the app's light/dark mode automatically.
|
|
30
|
+
*
|
|
31
|
+
* For static or server-rendered content, prefer the core `CodeBlock` with
|
|
32
|
+
* pre-computed `highlightedLines` (build them with `shikiToDualLines` +
|
|
33
|
+
* `DUAL_THEME_CSS`) so no highlighter ships to the client.
|
|
34
|
+
*/
|
|
35
|
+
export declare function CodeBlock({ code, language, themes, highlighter, ...rest }: Readonly<CodeBlockProps>): React.JSX.Element;
|
|
36
|
+
export declare namespace CodeBlock {
|
|
37
|
+
var displayName: string;
|
|
38
|
+
}
|
|
39
|
+
export default CodeBlock;
|
|
40
|
+
//# sourceMappingURL=CodeBlock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CodeBlock.d.ts","sourceRoot":"","sources":["../../src/CodeBlock/CodeBlock.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAkB,MAAM,OAAO,CAAC;AACvC,OAAO,EAEL,KAAK,cAAc,IAAI,kBAAkB,EAC1C,MAAM,oCAAoC,CAAC;AAC5C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAoC,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAInF,MAAM,WAAW,cAAe,SAAQ,IAAI,CAAC,kBAAkB,EAAE,kBAAkB,CAAC;IAClF;;;;;;;;OAQG;IACH,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,eAAe,CAAC;CAC/B;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,EACxB,IAAI,EACJ,QAAQ,EACR,MAAuB,EACvB,WAAW,EACX,GAAG,IAAI,EACR,EAAE,QAAQ,CAAC,cAAc,CAAC,qBA6B1B;yBAnCe,SAAS;;;AAsCzB,eAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/*! @eventuras/ratio-ui-shiki · Shiki syntax highlighting for ratio-ui · https://github.com/losol/ratio-ui · (c) 2026 Losol AS · MPL-2.0 */
|
|
2
|
+
"use client";
|
|
3
|
+
import { DualThemeStyles } from "../tokens/index.js";
|
|
4
|
+
import { DEFAULT_THEMES, shikiToDualLines } from "../highlighter.js";
|
|
5
|
+
import { useShikiHighlighter } from "../useShikiHighlighter/index.js";
|
|
6
|
+
import { useMemo } from "react";
|
|
7
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
import { CodeBlock } from "@eventuras/ratio-ui/core/CodeBlock";
|
|
9
|
+
//#region src/CodeBlock/CodeBlock.tsx
|
|
10
|
+
/**
|
|
11
|
+
* `CodeBlock`, wired to Shiki — a drop-in for `@eventuras/ratio-ui/core/CodeBlock`
|
|
12
|
+
* that highlights `code` for the given `language`. It loads a highlighter
|
|
13
|
+
* asynchronously (via `useShikiHighlighter`) and renders raw code until it is
|
|
14
|
+
* ready, so there is no flash of missing content (graceful degradation). Token
|
|
15
|
+
* colors follow the app's light/dark mode automatically.
|
|
16
|
+
*
|
|
17
|
+
* For static or server-rendered content, prefer the core `CodeBlock` with
|
|
18
|
+
* pre-computed `highlightedLines` (build them with `shikiToDualLines` +
|
|
19
|
+
* `DUAL_THEME_CSS`) so no highlighter ships to the client.
|
|
20
|
+
*/
|
|
21
|
+
function CodeBlock$1({ code, language, themes = DEFAULT_THEMES, highlighter, ...rest }) {
|
|
22
|
+
const { light, dark } = themes;
|
|
23
|
+
const activeHighlighter = useShikiHighlighter(highlighter);
|
|
24
|
+
const highlightedLines = useMemo(() => {
|
|
25
|
+
const hl = activeHighlighter;
|
|
26
|
+
if (!hl || !language) return void 0;
|
|
27
|
+
const loadedThemes = hl.getLoadedThemes();
|
|
28
|
+
if (!hl.getLoadedLanguages().includes(language) || !loadedThemes.includes(light) || !loadedThemes.includes(dark)) return;
|
|
29
|
+
try {
|
|
30
|
+
return shikiToDualLines(hl, code, language, {
|
|
31
|
+
light,
|
|
32
|
+
dark
|
|
33
|
+
});
|
|
34
|
+
} catch {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
}, [
|
|
38
|
+
activeHighlighter,
|
|
39
|
+
code,
|
|
40
|
+
language,
|
|
41
|
+
light,
|
|
42
|
+
dark
|
|
43
|
+
]);
|
|
44
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(DualThemeStyles, {}), /* @__PURE__ */ jsx(CodeBlock, {
|
|
45
|
+
code,
|
|
46
|
+
language,
|
|
47
|
+
highlightedLines,
|
|
48
|
+
...rest
|
|
49
|
+
})] });
|
|
50
|
+
}
|
|
51
|
+
CodeBlock$1.displayName = "ShikiCodeBlock";
|
|
52
|
+
//#endregion
|
|
53
|
+
export { CodeBlock$1 as CodeBlock, CodeBlock$1 as default };
|
|
54
|
+
|
|
55
|
+
//# sourceMappingURL=CodeBlock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CodeBlock.js","names":[],"sources":["../../src/CodeBlock/CodeBlock.tsx"],"sourcesContent":["// ratio-ui · design system for knowledge sharing\n// SPDX-FileCopyrightText: 2026 Losol AS\n// SPDX-License-Identifier: MPL-2.0\n\n'use client';\n\nimport React, { useMemo } from 'react';\nimport {\n CodeBlock as CoreCodeBlock,\n type CodeBlockProps as CoreCodeBlockProps,\n} from '@eventuras/ratio-ui/core/CodeBlock';\nimport type { HighlighterCore } from 'shiki/core';\nimport { shikiToDualLines, DEFAULT_THEMES, type DualThemes } from '../highlighter';\nimport { DualThemeStyles } from '../tokens';\nimport { useShikiHighlighter } from '../useShikiHighlighter';\n\nexport interface CodeBlockProps extends Omit<CoreCodeBlockProps, 'highlightedLines'> {\n /**\n * Light + dark Shiki theme pair to render with. The colors follow the app's\n * mode (`data-theme` / `data-color-scheme`), like the rest of ratio-ui.\n *\n * The built-in highlighter only loads `github-light` / `github-dark`; to\n * render a different pair, also pass a `highlighter` that has those themes\n * loaded — otherwise the block falls back to un-highlighted code.\n * @default { light: 'github-light', dark: 'github-dark' }\n */\n themes?: DualThemes;\n /**\n * Reuse an existing highlighter — e.g. one shared singleton from\n * `createRatioHighlighter` preloaded with your languages — instead of letting\n * this component lazily create its own. Ensure it has `language` and both\n * themes loaded; otherwise the block falls back to un-highlighted code.\n */\n highlighter?: HighlighterCore;\n}\n\n/**\n * `CodeBlock`, wired to Shiki — a drop-in for `@eventuras/ratio-ui/core/CodeBlock`\n * that highlights `code` for the given `language`. It loads a highlighter\n * asynchronously (via `useShikiHighlighter`) and renders raw code until it is\n * ready, so there is no flash of missing content (graceful degradation). Token\n * colors follow the app's light/dark mode automatically.\n *\n * For static or server-rendered content, prefer the core `CodeBlock` with\n * pre-computed `highlightedLines` (build them with `shikiToDualLines` +\n * `DUAL_THEME_CSS`) so no highlighter ships to the client.\n */\nexport function CodeBlock({\n code,\n language,\n themes = DEFAULT_THEMES,\n highlighter,\n ...rest\n}: Readonly<CodeBlockProps>) {\n const { light, dark } = themes;\n const activeHighlighter = useShikiHighlighter(highlighter);\n\n const highlightedLines = useMemo(() => {\n const hl = activeHighlighter;\n if (!hl || !language) return undefined;\n const loadedThemes = hl.getLoadedThemes();\n if (\n !hl.getLoadedLanguages().includes(language) ||\n !loadedThemes.includes(light) ||\n !loadedThemes.includes(dark)\n ) {\n return undefined;\n }\n try {\n return shikiToDualLines(hl, code, language, { light, dark });\n } catch {\n return undefined; // unknown grammar/theme → raw code fallback\n }\n }, [activeHighlighter, code, language, light, dark]);\n\n return (\n <>\n {/* Injection-safe theme switch; React hoists + dedupes by href. */}\n <DualThemeStyles />\n <CoreCodeBlock code={code} language={language} highlightedLines={highlightedLines} {...rest} />\n </>\n );\n}\n\nCodeBlock.displayName = 'ShikiCodeBlock';\nexport default CodeBlock;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA+CA,SAAgB,YAAU,EACxB,MACA,UACA,SAAS,gBACT,aACA,GAAG,QACwB;CAC3B,MAAM,EAAE,OAAO,SAAS;CACxB,MAAM,oBAAoB,oBAAoB,WAAW;CAEzD,MAAM,mBAAmB,cAAc;EACrC,MAAM,KAAK;EACX,IAAI,CAAC,MAAM,CAAC,UAAU,OAAO,KAAA;EAC7B,MAAM,eAAe,GAAG,gBAAgB;EACxC,IACE,CAAC,GAAG,mBAAmB,CAAC,CAAC,SAAS,QAAQ,KAC1C,CAAC,aAAa,SAAS,KAAK,KAC5B,CAAC,aAAa,SAAS,IAAI,GAE3B;EAEF,IAAI;GACF,OAAO,iBAAiB,IAAI,MAAM,UAAU;IAAE;IAAO;GAAK,CAAC;EAC7D,QAAQ;GACN;EACF;CACF,GAAG;EAAC;EAAmB;EAAM;EAAU;EAAO;CAAI,CAAC;CAEnD,OACE,qBAAA,YAAA,EAAA,UAAA,CAEE,oBAAC,iBAAD,CAAkB,CAAA,GAClB,oBAAC,WAAD;EAAqB;EAAgB;EAA4B;EAAkB,GAAI;CAAO,CAAA,CAC9F,EAAA,CAAA;AAEN;AAEA,YAAU,cAAc"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/CodeBlock/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { HighlighterCore } from 'shiki/core';
|
|
3
|
+
import { BundledLanguage, BundledTheme, LanguageInput, ThemeInput } from 'shiki';
|
|
4
|
+
import { DualTokenLine } from './tokens';
|
|
5
|
+
export { SHIKI_TOKEN_CLASS, DUAL_THEME_CSS } from './tokens';
|
|
6
|
+
/**
|
|
7
|
+
* Languages preloaded when you don't pass your own to {@link createRatioHighlighter}.
|
|
8
|
+
* Kept in sync with the fine-grained `@shikijs/langs/*` imports below.
|
|
9
|
+
*/
|
|
10
|
+
export declare const DEFAULT_LANGS: BundledLanguage[];
|
|
11
|
+
/** A light + dark Shiki theme pair. */
|
|
12
|
+
export interface DualThemes {
|
|
13
|
+
light: BundledTheme;
|
|
14
|
+
dark: BundledTheme;
|
|
15
|
+
}
|
|
16
|
+
/** Default light/dark theme pair — the code surface follows the app's mode. */
|
|
17
|
+
export declare const DEFAULT_THEMES: DualThemes;
|
|
18
|
+
export interface RatioHighlighterOptions {
|
|
19
|
+
/**
|
|
20
|
+
* Languages to preload, as Shiki language *inputs* (dynamic imports) — e.g.
|
|
21
|
+
* `import('@shikijs/langs/python')`, not the string names. Defaults to inputs
|
|
22
|
+
* for the {@link DEFAULT_LANGS} languages. Replaces the default set when set.
|
|
23
|
+
*/
|
|
24
|
+
langs?: LanguageInput[];
|
|
25
|
+
/**
|
|
26
|
+
* Themes to preload, as Shiki theme inputs — e.g.
|
|
27
|
+
* `import('@shikijs/themes/nord')`. Defaults to the `github-light` /
|
|
28
|
+
* `github-dark` pair.
|
|
29
|
+
*/
|
|
30
|
+
themes?: ThemeInput[];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Create a Shiki highlighter preconfigured for ratio-ui. Built on `shiki/core`
|
|
34
|
+
* (`createHighlighterCore`) with the WASM-free JavaScript regex engine and a
|
|
35
|
+
* curated, individually-imported language/theme set — so consumers bundle only
|
|
36
|
+
* these grammars, not Shiki's full bundled registry. The call is async and
|
|
37
|
+
* relatively heavy — create one and share it (the `<CodeBlock>` wrapper does).
|
|
38
|
+
*/
|
|
39
|
+
export declare function createRatioHighlighter(options?: RatioHighlighterOptions): Promise<HighlighterCore>;
|
|
40
|
+
/**
|
|
41
|
+
* Turn `code` into one React node per line for a **single** theme — each a run
|
|
42
|
+
* of `<span>`s carrying Shiki's token colors. Injection-safe (real elements, no
|
|
43
|
+
* HTML string). `lang`/`theme` must already be loaded in `highlighter`.
|
|
44
|
+
*/
|
|
45
|
+
export declare function shikiToLines(highlighter: HighlighterCore, code: string, lang: BundledLanguage | string, theme?: BundledTheme | string): React.ReactNode[];
|
|
46
|
+
/**
|
|
47
|
+
* Tokenize `code` for a **light + dark** theme pair into plain, serializable
|
|
48
|
+
* data ({@link DualTokenLine}) — each token carries both colors as
|
|
49
|
+
* `--shiki-light` / `--shiki-dark` custom properties. This is the build-time
|
|
50
|
+
* half of the precomputed pipeline: run it in a build script (Node), ship the
|
|
51
|
+
* result as JSON, and render it with `tokensToLines` from
|
|
52
|
+
* `@eventuras/ratio-ui-shiki/tokens` — the client then needs no highlighter,
|
|
53
|
+
* grammars, or engine at all. `lang` and both themes must already be loaded
|
|
54
|
+
* in `highlighter`.
|
|
55
|
+
*/
|
|
56
|
+
export declare function codeToDualTokens(highlighter: HighlighterCore, code: string, lang: BundledLanguage | string, themes?: DualThemes): DualTokenLine[];
|
|
57
|
+
/**
|
|
58
|
+
* Turn `code` into one React node per line for a **light + dark** theme pair.
|
|
59
|
+
* Each token span carries both colors as `--shiki-light` / `--shiki-dark` custom
|
|
60
|
+
* properties and the {@link SHIKI_TOKEN_CLASS} class; pair it with
|
|
61
|
+
* {@link DUAL_THEME_CSS} so the color follows the app's mode. Injection-safe.
|
|
62
|
+
* `lang` and both themes must already be loaded in `highlighter`.
|
|
63
|
+
*
|
|
64
|
+
* Shorthand for `tokensToLines(codeToDualTokens(...))` — split the two halves
|
|
65
|
+
* yourself to highlight at build time and render without Shiki on the client.
|
|
66
|
+
*/
|
|
67
|
+
export declare function shikiToDualLines(highlighter: HighlighterCore, code: string, lang: BundledLanguage | string, themes?: DualThemes): React.ReactNode[];
|
|
68
|
+
//# sourceMappingURL=highlighter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"highlighter.d.ts","sourceRoot":"","sources":["../src/highlighter.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAmB,MAAM,OAAO,CAAC;AACxC,OAAO,EAAyB,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC;AAEzE,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACtF,OAAO,EAAiB,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC;AAI7D,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE7D;;;GAGG;AACH,eAAO,MAAM,aAAa,EAAE,eAAe,EAc1C,CAAC;AAEF,uCAAuC;AACvC,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,YAAY,CAAC;IACpB,IAAI,EAAE,YAAY,CAAC;CACpB;AAED,+EAA+E;AAC/E,eAAO,MAAM,cAAc,EAAE,UAA2D,CAAC;AAEzF,MAAM,WAAW,uBAAuB;IACtC;;;;OAIG;IACH,KAAK,CAAC,EAAE,aAAa,EAAE,CAAC;IACxB;;;;OAIG;IACH,MAAM,CAAC,EAAE,UAAU,EAAE,CAAC;CACvB;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,GAAE,uBAA4B,GAAG,OAAO,CAAC,eAAe,CAAC,CAuBtG;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAC1B,WAAW,EAAE,eAAe,EAC5B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,eAAe,GAAG,MAAM,EAC9B,KAAK,GAAE,YAAY,GAAG,MAA4B,GACjD,KAAK,CAAC,SAAS,EAAE,CA0BnB;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAC9B,WAAW,EAAE,eAAe,EAC5B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,eAAe,GAAG,MAAM,EAC9B,MAAM,GAAE,UAA2B,GAClC,aAAa,EAAE,CAiBjB;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAC9B,WAAW,EAAE,eAAe,EAC5B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,eAAe,GAAG,MAAM,EAC9B,MAAM,GAAE,UAA2B,GAClC,KAAK,CAAC,SAAS,EAAE,CAEnB"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/*! @eventuras/ratio-ui-shiki · Shiki syntax highlighting for ratio-ui · https://github.com/losol/ratio-ui · (c) 2026 Losol AS · MPL-2.0 */
|
|
2
|
+
import { tokensToLines } from "./tokens/index.js";
|
|
3
|
+
import { Fragment } from "react";
|
|
4
|
+
import { createHighlighterCore } from "shiki/core";
|
|
5
|
+
import { createJavaScriptRegexEngine } from "shiki/engine/javascript";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
//#region src/highlighter.tsx
|
|
8
|
+
/**
|
|
9
|
+
* Languages preloaded when you don't pass your own to {@link createRatioHighlighter}.
|
|
10
|
+
* Kept in sync with the fine-grained `@shikijs/langs/*` imports below.
|
|
11
|
+
*/
|
|
12
|
+
var DEFAULT_LANGS = [
|
|
13
|
+
"tsx",
|
|
14
|
+
"ts",
|
|
15
|
+
"jsx",
|
|
16
|
+
"js",
|
|
17
|
+
"json",
|
|
18
|
+
"bash",
|
|
19
|
+
"css",
|
|
20
|
+
"html",
|
|
21
|
+
"markdown",
|
|
22
|
+
"yaml",
|
|
23
|
+
"xml",
|
|
24
|
+
"python",
|
|
25
|
+
"csharp"
|
|
26
|
+
];
|
|
27
|
+
/** Default light/dark theme pair — the code surface follows the app's mode. */
|
|
28
|
+
var DEFAULT_THEMES = {
|
|
29
|
+
light: "github-light",
|
|
30
|
+
dark: "github-dark"
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Create a Shiki highlighter preconfigured for ratio-ui. Built on `shiki/core`
|
|
34
|
+
* (`createHighlighterCore`) with the WASM-free JavaScript regex engine and a
|
|
35
|
+
* curated, individually-imported language/theme set — so consumers bundle only
|
|
36
|
+
* these grammars, not Shiki's full bundled registry. The call is async and
|
|
37
|
+
* relatively heavy — create one and share it (the `<CodeBlock>` wrapper does).
|
|
38
|
+
*/
|
|
39
|
+
function createRatioHighlighter(options = {}) {
|
|
40
|
+
return createHighlighterCore({
|
|
41
|
+
engine: createJavaScriptRegexEngine(),
|
|
42
|
+
langs: options.langs ?? [
|
|
43
|
+
import("@shikijs/langs/tsx"),
|
|
44
|
+
import("@shikijs/langs/ts"),
|
|
45
|
+
import("@shikijs/langs/jsx"),
|
|
46
|
+
import("@shikijs/langs/js"),
|
|
47
|
+
import("@shikijs/langs/json"),
|
|
48
|
+
import("@shikijs/langs/bash"),
|
|
49
|
+
import("@shikijs/langs/css"),
|
|
50
|
+
import("@shikijs/langs/html"),
|
|
51
|
+
import("@shikijs/langs/markdown"),
|
|
52
|
+
import("@shikijs/langs/yaml"),
|
|
53
|
+
import("@shikijs/langs/xml"),
|
|
54
|
+
import("@shikijs/langs/python"),
|
|
55
|
+
import("@shikijs/langs/csharp")
|
|
56
|
+
],
|
|
57
|
+
themes: options.themes ?? [import("@shikijs/themes/github-light"), import("@shikijs/themes/github-dark")]
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Turn `code` into one React node per line for a **single** theme — each a run
|
|
62
|
+
* of `<span>`s carrying Shiki's token colors. Injection-safe (real elements, no
|
|
63
|
+
* HTML string). `lang`/`theme` must already be loaded in `highlighter`.
|
|
64
|
+
*/
|
|
65
|
+
function shikiToLines(highlighter, code, lang, theme = DEFAULT_THEMES.dark) {
|
|
66
|
+
const { tokens } = highlighter.codeToTokens(code, {
|
|
67
|
+
lang,
|
|
68
|
+
theme
|
|
69
|
+
});
|
|
70
|
+
return tokens.map((line, i) => /* @__PURE__ */ jsx(Fragment, { children: line.map((token, j) => {
|
|
71
|
+
const fontStyle = token.fontStyle ?? 0;
|
|
72
|
+
return /* @__PURE__ */ jsx("span", {
|
|
73
|
+
style: {
|
|
74
|
+
color: token.color,
|
|
75
|
+
fontStyle: fontStyle & 1 ? "italic" : void 0,
|
|
76
|
+
fontWeight: fontStyle & 2 ? "bold" : void 0,
|
|
77
|
+
textDecoration: fontStyle & 4 ? "underline" : void 0
|
|
78
|
+
},
|
|
79
|
+
children: token.content
|
|
80
|
+
}, j);
|
|
81
|
+
}) }, i));
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Tokenize `code` for a **light + dark** theme pair into plain, serializable
|
|
85
|
+
* data ({@link DualTokenLine}) — each token carries both colors as
|
|
86
|
+
* `--shiki-light` / `--shiki-dark` custom properties. This is the build-time
|
|
87
|
+
* half of the precomputed pipeline: run it in a build script (Node), ship the
|
|
88
|
+
* result as JSON, and render it with `tokensToLines` from
|
|
89
|
+
* `@eventuras/ratio-ui-shiki/tokens` — the client then needs no highlighter,
|
|
90
|
+
* grammars, or engine at all. `lang` and both themes must already be loaded
|
|
91
|
+
* in `highlighter`.
|
|
92
|
+
*/
|
|
93
|
+
function codeToDualTokens(highlighter, code, lang, themes = DEFAULT_THEMES) {
|
|
94
|
+
const { tokens } = highlighter.codeToTokens(code, {
|
|
95
|
+
lang,
|
|
96
|
+
themes,
|
|
97
|
+
defaultColor: false
|
|
98
|
+
});
|
|
99
|
+
return tokens.map((line) => line.map((token) => ({
|
|
100
|
+
content: token.content,
|
|
101
|
+
...token.htmlStyle ? { htmlStyle: { ...token.htmlStyle } } : {}
|
|
102
|
+
})));
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Turn `code` into one React node per line for a **light + dark** theme pair.
|
|
106
|
+
* Each token span carries both colors as `--shiki-light` / `--shiki-dark` custom
|
|
107
|
+
* properties and the {@link SHIKI_TOKEN_CLASS} class; pair it with
|
|
108
|
+
* {@link DUAL_THEME_CSS} so the color follows the app's mode. Injection-safe.
|
|
109
|
+
* `lang` and both themes must already be loaded in `highlighter`.
|
|
110
|
+
*
|
|
111
|
+
* Shorthand for `tokensToLines(codeToDualTokens(...))` — split the two halves
|
|
112
|
+
* yourself to highlight at build time and render without Shiki on the client.
|
|
113
|
+
*/
|
|
114
|
+
function shikiToDualLines(highlighter, code, lang, themes = DEFAULT_THEMES) {
|
|
115
|
+
return tokensToLines(codeToDualTokens(highlighter, code, lang, themes));
|
|
116
|
+
}
|
|
117
|
+
//#endregion
|
|
118
|
+
export { DEFAULT_LANGS, DEFAULT_THEMES, codeToDualTokens, createRatioHighlighter, shikiToDualLines, shikiToLines };
|
|
119
|
+
|
|
120
|
+
//# sourceMappingURL=highlighter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"highlighter.js","names":[],"sources":["../src/highlighter.tsx"],"sourcesContent":["// ratio-ui · design system for knowledge sharing\n// SPDX-FileCopyrightText: 2026 Losol AS\n// SPDX-License-Identifier: MPL-2.0\n\nimport React, { Fragment } from 'react';\nimport { createHighlighterCore, type HighlighterCore } from 'shiki/core';\nimport { createJavaScriptRegexEngine } from 'shiki/engine/javascript';\nimport type { BundledLanguage, BundledTheme, LanguageInput, ThemeInput } from 'shiki';\nimport { tokensToLines, type DualTokenLine } from './tokens';\n\n// Re-exported so existing imports keep working; they live in `./tokens` (the\n// Shiki-free module) so precomputed-token consumers don't pull this file in.\nexport { SHIKI_TOKEN_CLASS, DUAL_THEME_CSS } from './tokens';\n\n/**\n * Languages preloaded when you don't pass your own to {@link createRatioHighlighter}.\n * Kept in sync with the fine-grained `@shikijs/langs/*` imports below.\n */\nexport const DEFAULT_LANGS: BundledLanguage[] = [\n 'tsx',\n 'ts',\n 'jsx',\n 'js',\n 'json',\n 'bash',\n 'css',\n 'html',\n 'markdown',\n 'yaml',\n 'xml',\n 'python',\n 'csharp',\n];\n\n/** A light + dark Shiki theme pair. */\nexport interface DualThemes {\n light: BundledTheme;\n dark: BundledTheme;\n}\n\n/** Default light/dark theme pair — the code surface follows the app's mode. */\nexport const DEFAULT_THEMES: DualThemes = { light: 'github-light', dark: 'github-dark' };\n\nexport interface RatioHighlighterOptions {\n /**\n * Languages to preload, as Shiki language *inputs* (dynamic imports) — e.g.\n * `import('@shikijs/langs/python')`, not the string names. Defaults to inputs\n * for the {@link DEFAULT_LANGS} languages. Replaces the default set when set.\n */\n langs?: LanguageInput[];\n /**\n * Themes to preload, as Shiki theme inputs — e.g.\n * `import('@shikijs/themes/nord')`. Defaults to the `github-light` /\n * `github-dark` pair.\n */\n themes?: ThemeInput[];\n}\n\n/**\n * Create a Shiki highlighter preconfigured for ratio-ui. Built on `shiki/core`\n * (`createHighlighterCore`) with the WASM-free JavaScript regex engine and a\n * curated, individually-imported language/theme set — so consumers bundle only\n * these grammars, not Shiki's full bundled registry. The call is async and\n * relatively heavy — create one and share it (the `<CodeBlock>` wrapper does).\n */\nexport function createRatioHighlighter(options: RatioHighlighterOptions = {}): Promise<HighlighterCore> {\n return createHighlighterCore({\n engine: createJavaScriptRegexEngine(),\n langs: options.langs ?? [\n import('@shikijs/langs/tsx'),\n import('@shikijs/langs/ts'),\n import('@shikijs/langs/jsx'),\n import('@shikijs/langs/js'),\n import('@shikijs/langs/json'),\n import('@shikijs/langs/bash'),\n import('@shikijs/langs/css'),\n import('@shikijs/langs/html'),\n import('@shikijs/langs/markdown'),\n import('@shikijs/langs/yaml'),\n import('@shikijs/langs/xml'),\n import('@shikijs/langs/python'),\n import('@shikijs/langs/csharp'),\n ],\n themes: options.themes ?? [\n import('@shikijs/themes/github-light'),\n import('@shikijs/themes/github-dark'),\n ],\n });\n}\n\n/**\n * Turn `code` into one React node per line for a **single** theme — each a run\n * of `<span>`s carrying Shiki's token colors. Injection-safe (real elements, no\n * HTML string). `lang`/`theme` must already be loaded in `highlighter`.\n */\nexport function shikiToLines(\n highlighter: HighlighterCore,\n code: string,\n lang: BundledLanguage | string,\n theme: BundledTheme | string = DEFAULT_THEMES.dark,\n): React.ReactNode[] {\n const { tokens } = highlighter.codeToTokens(code, {\n lang: lang as BundledLanguage,\n theme: theme as BundledTheme,\n });\n\n return tokens.map((line, i) => (\n <Fragment key={i}>\n {line.map((token, j) => {\n const fontStyle = token.fontStyle ?? 0;\n return (\n <span\n key={j}\n style={{\n color: token.color,\n fontStyle: fontStyle & 1 ? 'italic' : undefined,\n fontWeight: fontStyle & 2 ? 'bold' : undefined,\n textDecoration: fontStyle & 4 ? 'underline' : undefined,\n }}\n >\n {token.content}\n </span>\n );\n })}\n </Fragment>\n ));\n}\n\n/**\n * Tokenize `code` for a **light + dark** theme pair into plain, serializable\n * data ({@link DualTokenLine}) — each token carries both colors as\n * `--shiki-light` / `--shiki-dark` custom properties. This is the build-time\n * half of the precomputed pipeline: run it in a build script (Node), ship the\n * result as JSON, and render it with `tokensToLines` from\n * `@eventuras/ratio-ui-shiki/tokens` — the client then needs no highlighter,\n * grammars, or engine at all. `lang` and both themes must already be loaded\n * in `highlighter`.\n */\nexport function codeToDualTokens(\n highlighter: HighlighterCore,\n code: string,\n lang: BundledLanguage | string,\n themes: DualThemes = DEFAULT_THEMES,\n): DualTokenLine[] {\n const { tokens } = highlighter.codeToTokens(code, {\n lang: lang as BundledLanguage,\n themes: themes as unknown as Record<string, BundledTheme>,\n defaultColor: false,\n });\n\n return tokens.map((line) =>\n line.map((token) => ({\n content: token.content,\n // Copied into a fresh plain object so the result is JSON-clean no\n // matter what Shiki hands back.\n ...(token.htmlStyle\n ? { htmlStyle: { ...(token.htmlStyle as Record<string, string>) } }\n : {}),\n })),\n );\n}\n\n/**\n * Turn `code` into one React node per line for a **light + dark** theme pair.\n * Each token span carries both colors as `--shiki-light` / `--shiki-dark` custom\n * properties and the {@link SHIKI_TOKEN_CLASS} class; pair it with\n * {@link DUAL_THEME_CSS} so the color follows the app's mode. Injection-safe.\n * `lang` and both themes must already be loaded in `highlighter`.\n *\n * Shorthand for `tokensToLines(codeToDualTokens(...))` — split the two halves\n * yourself to highlight at build time and render without Shiki on the client.\n */\nexport function shikiToDualLines(\n highlighter: HighlighterCore,\n code: string,\n lang: BundledLanguage | string,\n themes: DualThemes = DEFAULT_THEMES,\n): React.ReactNode[] {\n return tokensToLines(codeToDualTokens(highlighter, code, lang, themes));\n}\n"],"mappings":";;;;;;;;;;;AAkBA,IAAa,gBAAmC;CAC9C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;AASA,IAAa,iBAA6B;CAAE,OAAO;CAAgB,MAAM;AAAc;;;;;;;;AAwBvF,SAAgB,uBAAuB,UAAmC,CAAC,GAA6B;CACtG,OAAO,sBAAsB;EAC3B,QAAQ,4BAA4B;EACpC,OAAO,QAAQ,SAAS;GACtB,OAAO;GACP,OAAO;GACP,OAAO;GACP,OAAO;GACP,OAAO;GACP,OAAO;GACP,OAAO;GACP,OAAO;GACP,OAAO;GACP,OAAO;GACP,OAAO;GACP,OAAO;GACP,OAAO;EACT;EACA,QAAQ,QAAQ,UAAU,CACxB,OAAO,iCACP,OAAO,8BACT;CACF,CAAC;AACH;;;;;;AAOA,SAAgB,aACd,aACA,MACA,MACA,QAA+B,eAAe,MAC3B;CACnB,MAAM,EAAE,WAAW,YAAY,aAAa,MAAM;EAC1C;EACC;CACT,CAAC;CAED,OAAO,OAAO,KAAK,MAAM,MACvB,oBAAC,UAAD,EAAA,UACG,KAAK,KAAK,OAAO,MAAM;EACtB,MAAM,YAAY,MAAM,aAAa;EACrC,OACE,oBAAC,QAAD;GAEE,OAAO;IACL,OAAO,MAAM;IACb,WAAW,YAAY,IAAI,WAAW,KAAA;IACtC,YAAY,YAAY,IAAI,SAAS,KAAA;IACrC,gBAAgB,YAAY,IAAI,cAAc,KAAA;GAChD;GAEC,UAAA,MAAM;EACH,GATC,CASD;CAEV,CAAC,EACO,GAjBK,CAiBL,CACX;AACH;;;;;;;;;;;AAYA,SAAgB,iBACd,aACA,MACA,MACA,SAAqB,gBACJ;CACjB,MAAM,EAAE,WAAW,YAAY,aAAa,MAAM;EAC1C;EACE;EACR,cAAc;CAChB,CAAC;CAED,OAAO,OAAO,KAAK,SACjB,KAAK,KAAK,WAAW;EACnB,SAAS,MAAM;EAGf,GAAI,MAAM,YACN,EAAE,WAAW,EAAE,GAAI,MAAM,UAAqC,EAAE,IAChE,CAAC;CACP,EAAE,CACJ;AACF;;;;;;;;;;;AAYA,SAAgB,iBACd,aACA,MACA,MACA,SAAqB,gBACF;CACnB,OAAO,cAAc,iBAAiB,aAAa,MAAM,MAAM,MAAM,CAAC;AACxE"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { createRatioHighlighter, shikiToLines, shikiToDualLines, codeToDualTokens, DEFAULT_LANGS, DEFAULT_THEMES, type RatioHighlighterOptions, type DualThemes, } from './highlighter';
|
|
2
|
+
export { tokensToLines, DualThemeStyles, SHIKI_TOKEN_CLASS, DUAL_THEME_CSS, type DualToken, type DualTokenLine, } from './tokens';
|
|
3
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,sBAAsB,EACtB,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACb,cAAc,EACd,KAAK,uBAAuB,EAC5B,KAAK,UAAU,GAChB,MAAM,eAAe,CAAC;AAIvB,OAAO,EACL,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,KAAK,SAAS,EACd,KAAK,aAAa,GACnB,MAAM,UAAU,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/*! @eventuras/ratio-ui-shiki · Shiki syntax highlighting for ratio-ui · https://github.com/losol/ratio-ui · (c) 2026 Losol AS · MPL-2.0 */
|
|
2
|
+
import { DUAL_THEME_CSS, DualThemeStyles, SHIKI_TOKEN_CLASS, tokensToLines } from "./tokens/index.js";
|
|
3
|
+
import { DEFAULT_LANGS, DEFAULT_THEMES, codeToDualTokens, createRatioHighlighter, shikiToDualLines, shikiToLines } from "./highlighter.js";
|
|
4
|
+
export { DEFAULT_LANGS, DEFAULT_THEMES, DUAL_THEME_CSS, DualThemeStyles, SHIKI_TOKEN_CLASS, codeToDualTokens, createRatioHighlighter, shikiToDualLines, shikiToLines, tokensToLines };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
/** Class set on every dual-theme token span; {@link DUAL_THEME_CSS} switches its color. */
|
|
3
|
+
export declare const SHIKI_TOKEN_CLASS = "ratio-shiki-token";
|
|
4
|
+
/**
|
|
5
|
+
* CSS that flips token colors with the mode of the nearest scope. Shiki writes
|
|
6
|
+
* each token's light/dark colors into `--shiki-light` / `--shiki-dark`; a
|
|
7
|
+
* switch set on the scope — `:root` and its `data-theme` / `data-color-scheme`
|
|
8
|
+
* arms, `.surface-light` and `.surface-dark` — is inherited down to the token,
|
|
9
|
+
* which reads the dark color while the switch is on and falls back to light.
|
|
10
|
+
* The same scopes and the same inheritance as ratio-ui's own code-surface
|
|
11
|
+
* tokens, so a band inside a band resolves to the inner one. Rendered for you
|
|
12
|
+
* by {@link DualThemeStyles} and by the `<CodeBlock>` wrapper; include it
|
|
13
|
+
* yourself only if you render dual-theme lines by hand.
|
|
14
|
+
*
|
|
15
|
+
* The switch: `initial` is a custom property's guaranteed-invalid value, so
|
|
16
|
+
* `var()` of it voids `--shiki-color` and `color` takes its fallback. A lone
|
|
17
|
+
* space is a valid, empty value that leaves `--shiki-color` whole.
|
|
18
|
+
*/
|
|
19
|
+
export declare const DUAL_THEME_CSS = ":root,.surface-light{--shiki-dark-on:initial}\n:root[data-theme=\"dark\"],:root[data-color-scheme=\"dark\"],.surface-dark{--shiki-dark-on: }\n.ratio-shiki-token{--shiki-color:var(--shiki-dark-on) var(--shiki-dark);color:var(--shiki-color,var(--shiki-light))}";
|
|
20
|
+
/**
|
|
21
|
+
* One Shiki token in serializable form: its text plus the inline style
|
|
22
|
+
* carrying the `--shiki-light` / `--shiki-dark` colors. Plain data — it
|
|
23
|
+
* survives `JSON.stringify`/`parse`, so tokens can be computed once at build
|
|
24
|
+
* time and shipped to the client instead of grammars.
|
|
25
|
+
*/
|
|
26
|
+
export interface DualToken {
|
|
27
|
+
content: string;
|
|
28
|
+
htmlStyle?: Record<string, string>;
|
|
29
|
+
}
|
|
30
|
+
/** One line of code as dual-theme tokens. */
|
|
31
|
+
export type DualTokenLine = DualToken[];
|
|
32
|
+
/**
|
|
33
|
+
* Renders {@link DUAL_THEME_CSS} as a hoisted `<style>` tag. React dedupes it
|
|
34
|
+
* by `href`, so rendering this next to Shiki `<CodeBlock>`s (which inject the
|
|
35
|
+
* same tag) adds nothing. Drop it once anywhere precomputed lines render.
|
|
36
|
+
*/
|
|
37
|
+
export declare function DualThemeStyles(): React.JSX.Element;
|
|
38
|
+
/**
|
|
39
|
+
* Turn dual-theme tokens back into one React node per line — the shape core
|
|
40
|
+
* CodeBlock's `highlightedLines` takes. This is the runtime half of the
|
|
41
|
+
* precomputed pipeline: `codeToDualTokens` at build time, this at render.
|
|
42
|
+
* Injection-safe (real elements, no HTML string). Pair with
|
|
43
|
+
* {@link DualThemeStyles} so the colors follow the app's mode.
|
|
44
|
+
*/
|
|
45
|
+
export declare function tokensToLines(lines: DualTokenLine[]): React.ReactNode[];
|
|
46
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tokens/index.tsx"],"names":[],"mappings":"AAIA;;;;;GAKG;AAEH,OAAO,KAAmB,MAAM,OAAO,CAAC;AAExC,2FAA2F;AAC3F,eAAO,MAAM,iBAAiB,sBAAsB,CAAC;AAErD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,cAAc,uQAE6F,CAAC;AAEzH;;;;;GAKG;AACH,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACpC;AAED,6CAA6C;AAC7C,MAAM,MAAM,aAAa,GAAG,SAAS,EAAE,CAAC;AAExC;;;;GAIG;AACH,wBAAgB,eAAe,sBAM9B;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,aAAa,EAAE,GAAG,KAAK,CAAC,SAAS,EAAE,CAcvE"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/*! @eventuras/ratio-ui-shiki · Shiki syntax highlighting for ratio-ui · https://github.com/losol/ratio-ui · (c) 2026 Losol AS · MPL-2.0 */
|
|
2
|
+
import { Fragment } from "react";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
//#region src/tokens/index.tsx
|
|
5
|
+
/**
|
|
6
|
+
* The Shiki-free half of the precomputed-highlighting pipeline. Everything in
|
|
7
|
+
* this module is plain data + tiny renderers with **no shiki import**, so a
|
|
8
|
+
* client that renders precomputed tokens (built with `codeToDualTokens` at
|
|
9
|
+
* build time) bundles about a kilobyte from here — no grammars, no engine.
|
|
10
|
+
*/
|
|
11
|
+
/** Class set on every dual-theme token span; {@link DUAL_THEME_CSS} switches its color. */
|
|
12
|
+
var SHIKI_TOKEN_CLASS = "ratio-shiki-token";
|
|
13
|
+
/**
|
|
14
|
+
* CSS that flips token colors with the mode of the nearest scope. Shiki writes
|
|
15
|
+
* each token's light/dark colors into `--shiki-light` / `--shiki-dark`; a
|
|
16
|
+
* switch set on the scope — `:root` and its `data-theme` / `data-color-scheme`
|
|
17
|
+
* arms, `.surface-light` and `.surface-dark` — is inherited down to the token,
|
|
18
|
+
* which reads the dark color while the switch is on and falls back to light.
|
|
19
|
+
* The same scopes and the same inheritance as ratio-ui's own code-surface
|
|
20
|
+
* tokens, so a band inside a band resolves to the inner one. Rendered for you
|
|
21
|
+
* by {@link DualThemeStyles} and by the `<CodeBlock>` wrapper; include it
|
|
22
|
+
* yourself only if you render dual-theme lines by hand.
|
|
23
|
+
*
|
|
24
|
+
* The switch: `initial` is a custom property's guaranteed-invalid value, so
|
|
25
|
+
* `var()` of it voids `--shiki-color` and `color` takes its fallback. A lone
|
|
26
|
+
* space is a valid, empty value that leaves `--shiki-color` whole.
|
|
27
|
+
*/
|
|
28
|
+
var DUAL_THEME_CSS = `:root,.surface-light{--shiki-dark-on:initial}
|
|
29
|
+
:root[data-theme="dark"],:root[data-color-scheme="dark"],.surface-dark{--shiki-dark-on: }
|
|
30
|
+
.${SHIKI_TOKEN_CLASS}{--shiki-color:var(--shiki-dark-on) var(--shiki-dark);color:var(--shiki-color,var(--shiki-light))}`;
|
|
31
|
+
/**
|
|
32
|
+
* Renders {@link DUAL_THEME_CSS} as a hoisted `<style>` tag. React dedupes it
|
|
33
|
+
* by `href`, so rendering this next to Shiki `<CodeBlock>`s (which inject the
|
|
34
|
+
* same tag) adds nothing. Drop it once anywhere precomputed lines render.
|
|
35
|
+
*/
|
|
36
|
+
function DualThemeStyles() {
|
|
37
|
+
return /* @__PURE__ */ jsx("style", {
|
|
38
|
+
href: "ratio-ui-shiki-dual",
|
|
39
|
+
precedence: "medium",
|
|
40
|
+
children: DUAL_THEME_CSS
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Turn dual-theme tokens back into one React node per line — the shape core
|
|
45
|
+
* CodeBlock's `highlightedLines` takes. This is the runtime half of the
|
|
46
|
+
* precomputed pipeline: `codeToDualTokens` at build time, this at render.
|
|
47
|
+
* Injection-safe (real elements, no HTML string). Pair with
|
|
48
|
+
* {@link DualThemeStyles} so the colors follow the app's mode.
|
|
49
|
+
*/
|
|
50
|
+
function tokensToLines(lines) {
|
|
51
|
+
return lines.map((line, i) => /* @__PURE__ */ jsx(Fragment, { children: line.map((token, j) => /* @__PURE__ */ jsx("span", {
|
|
52
|
+
className: SHIKI_TOKEN_CLASS,
|
|
53
|
+
style: token.htmlStyle,
|
|
54
|
+
children: token.content
|
|
55
|
+
}, j)) }, i));
|
|
56
|
+
}
|
|
57
|
+
//#endregion
|
|
58
|
+
export { DUAL_THEME_CSS, DualThemeStyles, SHIKI_TOKEN_CLASS, tokensToLines };
|
|
59
|
+
|
|
60
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/tokens/index.tsx"],"sourcesContent":["// ratio-ui · design system for knowledge sharing\n// SPDX-FileCopyrightText: 2026 Losol AS\n// SPDX-License-Identifier: MPL-2.0\n\n/**\n * The Shiki-free half of the precomputed-highlighting pipeline. Everything in\n * this module is plain data + tiny renderers with **no shiki import**, so a\n * client that renders precomputed tokens (built with `codeToDualTokens` at\n * build time) bundles about a kilobyte from here — no grammars, no engine.\n */\n\nimport React, { Fragment } from 'react';\n\n/** Class set on every dual-theme token span; {@link DUAL_THEME_CSS} switches its color. */\nexport const SHIKI_TOKEN_CLASS = 'ratio-shiki-token';\n\n/**\n * CSS that flips token colors with the mode of the nearest scope. Shiki writes\n * each token's light/dark colors into `--shiki-light` / `--shiki-dark`; a\n * switch set on the scope — `:root` and its `data-theme` / `data-color-scheme`\n * arms, `.surface-light` and `.surface-dark` — is inherited down to the token,\n * which reads the dark color while the switch is on and falls back to light.\n * The same scopes and the same inheritance as ratio-ui's own code-surface\n * tokens, so a band inside a band resolves to the inner one. Rendered for you\n * by {@link DualThemeStyles} and by the `<CodeBlock>` wrapper; include it\n * yourself only if you render dual-theme lines by hand.\n *\n * The switch: `initial` is a custom property's guaranteed-invalid value, so\n * `var()` of it voids `--shiki-color` and `color` takes its fallback. A lone\n * space is a valid, empty value that leaves `--shiki-color` whole.\n */\nexport const DUAL_THEME_CSS = `:root,.surface-light{--shiki-dark-on:initial}\n:root[data-theme=\"dark\"],:root[data-color-scheme=\"dark\"],.surface-dark{--shiki-dark-on: }\n.${SHIKI_TOKEN_CLASS}{--shiki-color:var(--shiki-dark-on) var(--shiki-dark);color:var(--shiki-color,var(--shiki-light))}`;\n\n/**\n * One Shiki token in serializable form: its text plus the inline style\n * carrying the `--shiki-light` / `--shiki-dark` colors. Plain data — it\n * survives `JSON.stringify`/`parse`, so tokens can be computed once at build\n * time and shipped to the client instead of grammars.\n */\nexport interface DualToken {\n content: string;\n htmlStyle?: Record<string, string>;\n}\n\n/** One line of code as dual-theme tokens. */\nexport type DualTokenLine = DualToken[];\n\n/**\n * Renders {@link DUAL_THEME_CSS} as a hoisted `<style>` tag. React dedupes it\n * by `href`, so rendering this next to Shiki `<CodeBlock>`s (which inject the\n * same tag) adds nothing. Drop it once anywhere precomputed lines render.\n */\nexport function DualThemeStyles() {\n return (\n <style href=\"ratio-ui-shiki-dual\" precedence=\"medium\">\n {DUAL_THEME_CSS}\n </style>\n );\n}\n\n/**\n * Turn dual-theme tokens back into one React node per line — the shape core\n * CodeBlock's `highlightedLines` takes. This is the runtime half of the\n * precomputed pipeline: `codeToDualTokens` at build time, this at render.\n * Injection-safe (real elements, no HTML string). Pair with\n * {@link DualThemeStyles} so the colors follow the app's mode.\n */\nexport function tokensToLines(lines: DualTokenLine[]): React.ReactNode[] {\n return lines.map((line, i) => (\n <Fragment key={i}>\n {line.map((token, j) => (\n <span\n key={j}\n className={SHIKI_TOKEN_CLASS}\n style={token.htmlStyle as React.CSSProperties}\n >\n {token.content}\n </span>\n ))}\n </Fragment>\n ));\n}\n"],"mappings":";;;;;;;;;;;AAcA,IAAa,oBAAoB;;;;;;;;;;;;;;;;AAiBjC,IAAa,iBAAiB;;GAE3B,kBAAkB;;;;;;AAqBrB,SAAgB,kBAAkB;CAChC,OACE,oBAAC,SAAD;EAAO,MAAK;EAAsB,YAAW;EAC1C,UAAA;CACI,CAAA;AAEX;;;;;;;;AASA,SAAgB,cAAc,OAA2C;CACvE,OAAO,MAAM,KAAK,MAAM,MACtB,oBAAC,UAAD,EAAA,UACG,KAAK,KAAK,OAAO,MAChB,oBAAC,QAAD;EAEE,WAAW;EACX,OAAO,MAAM;EAEZ,UAAA,MAAM;CACH,GALC,CAKD,CACP,EACO,GAVK,CAUL,CACX;AACH"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { HighlighterCore } from 'shiki/core';
|
|
2
|
+
/**
|
|
3
|
+
* Load (and share) the ratio-ui Shiki highlighter — the curated default set
|
|
4
|
+
* from `createRatioHighlighter` (see its `DEFAULT_LANGS` + github light/dark).
|
|
5
|
+
* Returns `null` while it loads, then the ready highlighter. Pass your own
|
|
6
|
+
* `highlighter` — e.g. from `createRatioHighlighter` with extra language/theme
|
|
7
|
+
* imports — to skip loading.
|
|
8
|
+
*
|
|
9
|
+
* Pair the result with `shikiToDualLines` + `DUAL_THEME_CSS` to render code
|
|
10
|
+
* whose colors follow the app's light/dark mode. This is the primitive the
|
|
11
|
+
* `<CodeBlock>` wrapper is built on.
|
|
12
|
+
*/
|
|
13
|
+
export declare function useShikiHighlighter(highlighter?: HighlighterCore): HighlighterCore | null;
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/useShikiHighlighter/index.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAmBlD;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,CAAC,EAAE,eAAe,GAAG,eAAe,GAAG,IAAI,CAyBzF"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/*! @eventuras/ratio-ui-shiki · Shiki syntax highlighting for ratio-ui · https://github.com/losol/ratio-ui · (c) 2026 Losol AS · MPL-2.0 */
|
|
2
|
+
"use client";
|
|
3
|
+
import { createRatioHighlighter } from "../highlighter.js";
|
|
4
|
+
import { useEffect, useState } from "react";
|
|
5
|
+
//#region src/useShikiHighlighter/index.ts
|
|
6
|
+
var defaultHighlighter;
|
|
7
|
+
function getDefaultHighlighter() {
|
|
8
|
+
if (!defaultHighlighter) {
|
|
9
|
+
const created = createRatioHighlighter();
|
|
10
|
+
created.catch(() => {
|
|
11
|
+
if (defaultHighlighter === created) defaultHighlighter = void 0;
|
|
12
|
+
});
|
|
13
|
+
defaultHighlighter = created;
|
|
14
|
+
}
|
|
15
|
+
return defaultHighlighter;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Load (and share) the ratio-ui Shiki highlighter — the curated default set
|
|
19
|
+
* from `createRatioHighlighter` (see its `DEFAULT_LANGS` + github light/dark).
|
|
20
|
+
* Returns `null` while it loads, then the ready highlighter. Pass your own
|
|
21
|
+
* `highlighter` — e.g. from `createRatioHighlighter` with extra language/theme
|
|
22
|
+
* imports — to skip loading.
|
|
23
|
+
*
|
|
24
|
+
* Pair the result with `shikiToDualLines` + `DUAL_THEME_CSS` to render code
|
|
25
|
+
* whose colors follow the app's light/dark mode. This is the primitive the
|
|
26
|
+
* `<CodeBlock>` wrapper is built on.
|
|
27
|
+
*/
|
|
28
|
+
function useShikiHighlighter(highlighter) {
|
|
29
|
+
const [active, setActive] = useState(highlighter ?? null);
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (highlighter) {
|
|
32
|
+
setActive(highlighter);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
let alive = true;
|
|
36
|
+
setActive(null);
|
|
37
|
+
getDefaultHighlighter().then((h) => {
|
|
38
|
+
if (alive) setActive(h);
|
|
39
|
+
}).catch(() => {});
|
|
40
|
+
return () => {
|
|
41
|
+
alive = false;
|
|
42
|
+
};
|
|
43
|
+
}, [highlighter]);
|
|
44
|
+
return active;
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
export { useShikiHighlighter };
|
|
48
|
+
|
|
49
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/useShikiHighlighter/index.ts"],"sourcesContent":["// ratio-ui · design system for knowledge sharing\n// SPDX-FileCopyrightText: 2026 Losol AS\n// SPDX-License-Identifier: MPL-2.0\n\n'use client';\n\nimport { useEffect, useState } from 'react';\nimport type { HighlighterCore } from 'shiki/core';\nimport { createRatioHighlighter } from '../highlighter';\n\n// The default highlighter (curated langs + github light/dark), created once and\n// shared across every component that doesn't pass its own.\nlet defaultHighlighter: Promise<HighlighterCore> | undefined;\n\nfunction getDefaultHighlighter(): Promise<HighlighterCore> {\n if (!defaultHighlighter) {\n const created = createRatioHighlighter();\n // Don't cache a rejection forever — evict so a later mount can retry.\n created.catch(() => {\n if (defaultHighlighter === created) defaultHighlighter = undefined;\n });\n defaultHighlighter = created;\n }\n return defaultHighlighter;\n}\n\n/**\n * Load (and share) the ratio-ui Shiki highlighter — the curated default set\n * from `createRatioHighlighter` (see its `DEFAULT_LANGS` + github light/dark).\n * Returns `null` while it loads, then the ready highlighter. Pass your own\n * `highlighter` — e.g. from `createRatioHighlighter` with extra language/theme\n * imports — to skip loading.\n *\n * Pair the result with `shikiToDualLines` + `DUAL_THEME_CSS` to render code\n * whose colors follow the app's light/dark mode. This is the primitive the\n * `<CodeBlock>` wrapper is built on.\n */\nexport function useShikiHighlighter(highlighter?: HighlighterCore): HighlighterCore | null {\n const [active, setActive] = useState<HighlighterCore | null>(highlighter ?? null);\n\n useEffect(() => {\n if (highlighter) {\n setActive(highlighter);\n return;\n }\n let alive = true;\n // Drop any previously-provided highlighter while the default loads, so we\n // never return a stale one (matches the \"null while loading\" contract).\n setActive(null);\n getDefaultHighlighter()\n .then((h) => {\n if (alive) setActive(h);\n })\n .catch(() => {\n // Highlighter failed to init — stay on null (raw-code fallback).\n });\n return () => {\n alive = false;\n };\n }, [highlighter]);\n\n return active;\n}\n"],"mappings":";;;;;AAYA,IAAI;AAEJ,SAAS,wBAAkD;CACzD,IAAI,CAAC,oBAAoB;EACvB,MAAM,UAAU,uBAAuB;EAEvC,QAAQ,YAAY;GAClB,IAAI,uBAAuB,SAAS,qBAAqB,KAAA;EAC3D,CAAC;EACD,qBAAqB;CACvB;CACA,OAAO;AACT;;;;;;;;;;;;AAaA,SAAgB,oBAAoB,aAAuD;CACzF,MAAM,CAAC,QAAQ,aAAa,SAAiC,eAAe,IAAI;CAEhF,gBAAgB;EACd,IAAI,aAAa;GACf,UAAU,WAAW;GACrB;EACF;EACA,IAAI,QAAQ;EAGZ,UAAU,IAAI;EACd,sBAAsB,CAAC,CACpB,MAAM,MAAM;GACX,IAAI,OAAO,UAAU,CAAC;EACxB,CAAC,CAAC,CACD,YAAY,CAEb,CAAC;EACH,aAAa;GACX,QAAQ;EACV;CACF,GAAG,CAAC,WAAW,CAAC;CAEhB,OAAO;AACT"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,76 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eventuras/ratio-ui-shiki",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Alpha — Shiki syntax highlighting for Ratio UI's CodeBlock",
|
|
5
|
+
"license": "MPL-2.0",
|
|
6
|
+
"homepage": "https://github.com/losol/ratio-ui/tree/main/packages/ratio-ui-shiki#readme",
|
|
7
|
+
"bugs": {
|
|
8
|
+
"url": "https://github.com/losol/ratio-ui/issues"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/losol/ratio-ui.git",
|
|
13
|
+
"directory": "packages/ratio-ui-shiki"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"ratio-ui",
|
|
17
|
+
"shiki",
|
|
18
|
+
"syntax-highlighting",
|
|
19
|
+
"codeblock",
|
|
20
|
+
"alpha"
|
|
21
|
+
],
|
|
22
|
+
"type": "module",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"import": "./dist/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./CodeBlock": {
|
|
29
|
+
"types": "./dist/CodeBlock/index.d.ts",
|
|
30
|
+
"import": "./dist/CodeBlock/index.js"
|
|
31
|
+
},
|
|
32
|
+
"./useShikiHighlighter": {
|
|
33
|
+
"types": "./dist/useShikiHighlighter/index.d.ts",
|
|
34
|
+
"import": "./dist/useShikiHighlighter/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./tokens": {
|
|
37
|
+
"types": "./dist/tokens/index.d.ts",
|
|
38
|
+
"import": "./dist/tokens/index.js"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"main": "./dist/index.js",
|
|
42
|
+
"module": "./dist/index.js",
|
|
43
|
+
"types": "./dist/index.d.ts",
|
|
44
|
+
"files": [
|
|
45
|
+
"dist"
|
|
46
|
+
],
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public",
|
|
49
|
+
"tag": "alpha"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@eventuras/eslint-config": "^1.0.4",
|
|
53
|
+
"@eventuras/typescript-config": "^1.0.0",
|
|
54
|
+
"@eventuras/vite-config": "^0.3.1",
|
|
55
|
+
"@shikijs/langs": "^4.4.3",
|
|
56
|
+
"@shikijs/themes": "^4.4.3",
|
|
57
|
+
"@types/react": "^19.3.0",
|
|
58
|
+
"@types/react-dom": "^19.3.0",
|
|
59
|
+
"shiki": "^4.4.3",
|
|
60
|
+
"typescript": "6.0.3",
|
|
61
|
+
"vite": "8.3.0",
|
|
62
|
+
"vitest": "4.1.11",
|
|
63
|
+
"@eventuras/ratio-ui": "2.31.1"
|
|
64
|
+
},
|
|
65
|
+
"peerDependencies": {
|
|
66
|
+
"@eventuras/ratio-ui": "^2.13.0",
|
|
67
|
+
"@shikijs/langs": "^4.4.3",
|
|
68
|
+
"@shikijs/themes": "^4.4.3",
|
|
69
|
+
"shiki": "^4.4.3"
|
|
70
|
+
},
|
|
71
|
+
"scripts": {
|
|
72
|
+
"build": "tsc && vite build",
|
|
73
|
+
"lint": "eslint .",
|
|
74
|
+
"test": "vitest run"
|
|
75
|
+
}
|
|
6
76
|
}
|