elegance-js 2.0.17 → 2.0.19

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.
Files changed (46) hide show
  1. package/package.json +1 -1
  2. package/scripts/prod.js +1 -0
  3. package/dist/docs/components/Header.d.ts +0 -1
  4. package/dist/docs/components/Header.mjs +0 -249
  5. package/dist/docs/components/RootLayout.d.ts +0 -1
  6. package/dist/docs/components/RootLayout.mjs +0 -10
  7. package/dist/docs/docs/basics/page.d.ts +0 -2
  8. package/dist/docs/docs/basics/page.mjs +0 -1057
  9. package/dist/docs/docs/compilations/page.d.ts +0 -2
  10. package/dist/docs/docs/compilations/page.mjs +0 -15
  11. package/dist/docs/docs/components/CodeBlock.d.ts +0 -2
  12. package/dist/docs/docs/components/CodeBlock.mjs +0 -324
  13. package/dist/docs/docs/components/DocsLayout.d.ts +0 -1
  14. package/dist/docs/docs/components/DocsLayout.mjs +0 -527
  15. package/dist/docs/docs/components/Header.d.ts +0 -1
  16. package/dist/docs/docs/components/Header.mjs +0 -160
  17. package/dist/docs/docs/components/Mono.d.ts +0 -1
  18. package/dist/docs/docs/components/Mono.mjs +0 -7
  19. package/dist/docs/docs/components/PageHeading.d.ts +0 -1
  20. package/dist/docs/docs/components/PageHeading.mjs +0 -9
  21. package/dist/docs/docs/components/Paragraph.d.ts +0 -1
  22. package/dist/docs/docs/components/Paragraph.mjs +0 -10
  23. package/dist/docs/docs/components/Separator.d.ts +0 -1
  24. package/dist/docs/docs/components/Separator.mjs +0 -7
  25. package/dist/docs/docs/components/SubHeading.d.ts +0 -1
  26. package/dist/docs/docs/components/SubHeading.mjs +0 -8
  27. package/dist/docs/docs/components/SubSeparator.d.ts +0 -1
  28. package/dist/docs/docs/components/SubSeparator.mjs +0 -7
  29. package/dist/docs/docs/components/Subtext.d.ts +0 -1
  30. package/dist/docs/docs/components/Subtext.mjs +0 -8
  31. package/dist/docs/docs/concepts/page.d.ts +0 -2
  32. package/dist/docs/docs/concepts/page.mjs +0 -954
  33. package/dist/docs/docs/page-files/page.d.ts +0 -2
  34. package/dist/docs/docs/page-files/page.mjs +0 -1206
  35. package/dist/docs/docs/route.d.ts +0 -2
  36. package/dist/docs/docs/route.mjs +0 -8
  37. package/dist/docs/docs/running/page.d.ts +0 -2
  38. package/dist/docs/docs/running/page.mjs +0 -7
  39. package/dist/docs/nullpage/page.d.ts +0 -2
  40. package/dist/docs/nullpage/page.mjs +0 -58
  41. package/dist/docs/page.d.ts +0 -2
  42. package/dist/docs/page.mjs +0 -437
  43. package/dist/docs/utils/MEGALEXER.d.ts +0 -1
  44. package/dist/docs/utils/MEGALEXER.mjs +0 -171
  45. package/dist/types/Metadata.d.ts +0 -19
  46. package/dist/types/Metadata.mjs +0 -15
@@ -1,2 +0,0 @@
1
- import http from "node:http";
2
- export declare function GET(_: http.IncomingMessage, res: http.ServerResponse): Promise<void>;
@@ -1,8 +0,0 @@
1
- // src/docs/docs/route.ts
2
- async function GET(_, res) {
3
- res.writeHead(302, { Location: "/new-path" });
4
- res.end();
5
- }
6
- export {
7
- GET
8
- };
@@ -1,2 +0,0 @@
1
- export declare const metadata: () => BuiltElement<"head">;
2
- export declare const page: BuiltElement<"body">;
@@ -1,7 +0,0 @@
1
- // src/docs/docs/running/page.ts
2
- var metadata = () => head({});
3
- var page = body({});
4
- export {
5
- metadata,
6
- page
7
- };
@@ -1,2 +0,0 @@
1
- export declare const metadata: () => BuiltElement<"head">;
2
- export declare const page: BuiltElement<"body">;
@@ -1,58 +0,0 @@
1
- // src/internal/deprecate.ts
2
- var ShowDeprecationWarning = (msg) => {
3
- console.warn("\x1B[31m", msg, "\x1B[0m");
4
- console.trace("Stack Trace:");
5
- };
6
-
7
- // src/server/createState.ts
8
- if (!globalThis.__SERVER_CURRENT_STATE_ID__) {
9
- globalThis.__SERVER_CURRENT_STATE_ID__ = 1;
10
- }
11
- var createEventListener = ({
12
- eventListener,
13
- dependencies = [],
14
- params
15
- }) => {
16
- ShowDeprecationWarning("WARNING: The createEventListener() and function is deprecated. Please use eventListener() instead, from elegance-js/state.");
17
- const deps = dependencies.map((dep) => ({ id: dep.id, bind: dep.bind }));
18
- let dependencyString = "[";
19
- for (const dep of deps) {
20
- dependencyString += `{id:${dep.id}`;
21
- if (dep.bind) dependencyString += `,bind:${dep.bind}`;
22
- dependencyString += `},`;
23
- }
24
- dependencyString += "]";
25
- const value = {
26
- id: __SERVER_CURRENT_STATE_ID__ += 1,
27
- type: 1 /* STATE */,
28
- value: new Function(
29
- "state",
30
- "event",
31
- `(${eventListener.toString()})({ event, ...${JSON.stringify(params || {})} }, ...state.getAll(${dependencyString}))`
32
- )
33
- };
34
- globalThis.__SERVER_CURRENT_STATE__.push(value);
35
- return value;
36
- };
37
-
38
- // src/docs/nullpage/page.ts
39
- createEventListener({
40
- dependencies: [],
41
- eventListener: (params) => {
42
- }
43
- });
44
- var metadata = () => head(
45
- {},
46
- link({
47
- rel: "stylesheet",
48
- href: "/index.css"
49
- }),
50
- title("Hi There!")
51
- );
52
- var page = body({
53
- class: "bg-green-400"
54
- });
55
- export {
56
- metadata,
57
- page
58
- };
@@ -1,2 +0,0 @@
1
- export declare const metadata: () => BuiltElement<"head">;
2
- export declare const page: BuiltElement<"body">;
@@ -1,437 +0,0 @@
1
- // src/internal/deprecate.ts
2
- var ShowDeprecationWarning = (msg) => {
3
- console.warn("\x1B[31m", msg, "\x1B[0m");
4
- console.trace("Stack Trace:");
5
- };
6
-
7
- // src/server/loadHook.ts
8
- var loadHook = (deps, fn, bind) => {
9
- const stringFn = fn.toString();
10
- const depsArray = (deps || []).map((dep) => ({
11
- id: dep.id,
12
- bind: dep.bind
13
- }));
14
- let dependencyString = "[";
15
- for (const dep of depsArray) {
16
- dependencyString += `{id:${dep.id}`;
17
- if (dep.bind) dependencyString += `,bind:${dep.bind}`;
18
- dependencyString += `},`;
19
- }
20
- dependencyString += "]";
21
- const isAsync = fn.constructor.name === "AsyncFunction";
22
- const wrapperFn = isAsync ? `async (state) => await (${stringFn})(state, ...state.getAll(${dependencyString}))` : `(state) => (${stringFn})(state, ...state.getAll(${dependencyString}))`;
23
- globalThis.__SERVER_CURRENT_LOADHOOKS__.push({
24
- fn: wrapperFn,
25
- bind: bind || ""
26
- });
27
- };
28
- var createLoadHook = (options) => {
29
- ShowDeprecationWarning("WARNING: createLoadHook() is a deprecated function. Use loadHook() from elegance-js/loadHook instead.");
30
- const stringFn = options.fn.toString();
31
- const deps = (options.deps || []).map((dep) => ({
32
- id: dep.id,
33
- bind: dep.bind
34
- }));
35
- let dependencyString = "[";
36
- for (const dep of deps) {
37
- dependencyString += `{id:${dep.id}`;
38
- if (dep.bind) dependencyString += `,bind:${dep.bind}`;
39
- dependencyString += `},`;
40
- }
41
- dependencyString += "]";
42
- const isAsync = options.fn.constructor.name === "AsyncFunction";
43
- const wrapperFn = isAsync ? `async (state) => await (${stringFn})(state, ...state.getAll(${dependencyString}))` : `(state) => (${stringFn})(state, ...state.getAll(${dependencyString}))`;
44
- globalThis.__SERVER_CURRENT_LOADHOOKS__.push({
45
- fn: wrapperFn,
46
- bind: options.bind || ""
47
- });
48
- };
49
-
50
- // src/server/state.ts
51
- if (!globalThis.__SERVER_CURRENT_STATE_ID__) {
52
- globalThis.__SERVER_CURRENT_STATE_ID__ = 1;
53
- }
54
- var eventListener = (dependencies, eventListener2) => {
55
- const deps = dependencies.map((dep) => ({ id: dep.id, bind: dep.bind }));
56
- let dependencyString = "[";
57
- for (const dep of deps) {
58
- dependencyString += `{id:${dep.id}`;
59
- if (dep.bind) dependencyString += `,bind:${dep.bind}`;
60
- dependencyString += `},`;
61
- }
62
- dependencyString += "]";
63
- const value = {
64
- id: __SERVER_CURRENT_STATE_ID__ += 1,
65
- type: 1 /* STATE */,
66
- value: new Function(
67
- "state",
68
- "event",
69
- `(${eventListener2.toString()})(event, ...state.getAll(${dependencyString}))`
70
- )
71
- };
72
- globalThis.__SERVER_CURRENT_STATE__.push(value);
73
- return value;
74
- };
75
-
76
- // src/server/observe.ts
77
- var observe = (refs, update) => {
78
- const returnValue = {
79
- type: 2 /* OBSERVER */,
80
- initialValues: refs.map((ref) => ref.value),
81
- update,
82
- refs: refs.map((ref) => ({
83
- id: ref.id,
84
- bind: ref.bind
85
- }))
86
- };
87
- return returnValue;
88
- };
89
-
90
- // src/components/Link.ts
91
- loadHook(
92
- [],
93
- () => {
94
- const anchors = Array.from(document.querySelectorAll("a[prefetch]"));
95
- const elsToClear = [];
96
- for (const anchor of anchors) {
97
- const prefetch = anchor.getAttribute("prefetch");
98
- const href = new URL(anchor.href);
99
- switch (prefetch) {
100
- case "load":
101
- client.fetchPage(href);
102
- break;
103
- case "hover":
104
- const fn = () => {
105
- client.fetchPage(href);
106
- };
107
- anchor.addEventListener("mouseenter", fn);
108
- elsToClear.push({
109
- el: anchor,
110
- fn
111
- });
112
- break;
113
- }
114
- }
115
- return () => {
116
- for (const listener of elsToClear) {
117
- listener.el.removeEventListener("mouseenter", listener.fn);
118
- }
119
- };
120
- }
121
- );
122
- var navigate = eventListener(
123
- [],
124
- (event) => {
125
- const target = new URL(event.currentTarget.href);
126
- const client2 = globalThis.client;
127
- const sanitizedTarget = client2.sanitizePathname(target.pathname);
128
- const sanitizedCurrent = client2.sanitizePathname(window.location.pathname);
129
- if (sanitizedTarget === sanitizedCurrent) {
130
- if (target.hash === window.location.hash) return event.preventDefault();
131
- return;
132
- }
133
- event.preventDefault();
134
- client2.navigateLocally(target.href);
135
- }
136
- );
137
- var Link = (options, ...children) => {
138
- if (!options.href) {
139
- throw `Link elements must have a HREF attribute set.`;
140
- }
141
- if (!options.href.startsWith("/")) {
142
- throw `Link elements may only navigate to local pages. "/"`;
143
- }
144
- return a(
145
- {
146
- ...options,
147
- onClick: navigate
148
- },
149
- ...children
150
- );
151
- };
152
-
153
- // src/server/createState.ts
154
- if (!globalThis.__SERVER_CURRENT_STATE_ID__) {
155
- globalThis.__SERVER_CURRENT_STATE_ID__ = 1;
156
- }
157
- var createState = (value, options) => {
158
- ShowDeprecationWarning("WARNING: The createState() and function is deprecated. Please use state() instead, from elegance-js/state.");
159
- const serverStateEntry = {
160
- id: __SERVER_CURRENT_STATE_ID__ += 1,
161
- value,
162
- type: 1 /* STATE */,
163
- bind: options?.bind
164
- };
165
- globalThis.__SERVER_CURRENT_STATE__.push(serverStateEntry);
166
- return serverStateEntry;
167
- };
168
-
169
- // src/docs/components/Header.ts
170
- var hasUserScrolled = createState(false);
171
- createLoadHook({
172
- deps: [hasUserScrolled],
173
- fn: (state2, hasUserScrolled2) => {
174
- const handleScroll = () => {
175
- const pos = {
176
- x: window.scrollX,
177
- y: window.scrollY
178
- };
179
- if (pos.y > 20) {
180
- if (hasUserScrolled2.value === true) return;
181
- hasUserScrolled2.value = true;
182
- hasUserScrolled2.signal();
183
- } else {
184
- if (hasUserScrolled2.value === false) return;
185
- hasUserScrolled2.value = false;
186
- hasUserScrolled2.signal();
187
- }
188
- };
189
- window.addEventListener("scroll", handleScroll);
190
- return () => {
191
- window.removeEventListener("scroll", handleScroll);
192
- };
193
- }
194
- });
195
- var Header = () => header(
196
- {
197
- class: "sticky z-10 lef-0 right-0 top-0 text-text-50 font-inter overflow-hidden duration-300 border-b-[1px] border-b-transparent"
198
- },
199
- div(
200
- {
201
- class: observe(
202
- [hasUserScrolled],
203
- (hasUserScrolled2) => {
204
- const defaultClass = "group duration-300 border-b-[1px] hover:border-b-transparent pointer-fine:hover:bg-accent-400 ";
205
- if (hasUserScrolled2) return defaultClass + "border-b-background-800 bg-background-950";
206
- return defaultClass + "bg-background-900 border-b-transparent";
207
- }
208
- )
209
- },
210
- div(
211
- {
212
- class: "max-w-[900px] w-full mx-auto flex pr-2 px-3 sm:px-5 sm:min-[calc(900px+1rem)]:px-0"
213
- },
214
- div(
215
- {
216
- class: "flex min-w-max w-full items-center z-10"
217
- },
218
- Link(
219
- {
220
- href: "/",
221
- class: "flex items-center gap-1 h-full"
222
- },
223
- p({
224
- class: "font-niconne pointer-fine:group-hover:text-background-950 font-bold text-xl sm:text-3xl relative top-0 z-20 duration-300 pointer-events-none",
225
- innerText: "Elegance"
226
- }),
227
- p({
228
- innerText: "JS",
229
- class: "font-bold pointer-fine:group-hover:text-background-950 relative top-0 text-xl sm:text-3xl z-10 text-accent-400 duration-300 pointer-events-none"
230
- })
231
- )
232
- ),
233
- div(
234
- {
235
- class: "flex py-2 sm:py-4 flex relative items-center justify-end w-full"
236
- },
237
- Link({
238
- prefetch: "hover",
239
- class: "z-10 text-xs uppercase font-bold px-4 py-2 rounded-full duration-300 bg-accent-400 text-primary-900 pointer-fine:group-hover:bg-background-950 pointer-fine:group-hover:text-accent-400 group-hover:hover:bg-text-50 group-hover:hover:text-background-950",
240
- href: "/docs/basics",
241
- innerText: "Docs"
242
- })
243
- )
244
- )
245
- )
246
- );
247
-
248
- // src/docs/components/RootLayout.ts
249
- var RootLayout = (...children) => body(
250
- {
251
- class: "bg-background-900 text-text-50 font-inter select-none text-text-50"
252
- },
253
- ...children
254
- );
255
-
256
- // src/docs/page.ts
257
- import fs from "fs";
258
- fs.existsSync("./page.mjs");
259
- var metadata = () => {
260
- return head(
261
- {},
262
- link({
263
- rel: "stylesheet",
264
- href: "/index.css"
265
- }),
266
- title("Hi There!")
267
- );
268
- };
269
- var pageTemplateString = `
270
- const variables = createState({
271
- counter: 0,
272
- });
273
-
274
- const functions = createState({
275
- increment: eventListener(
276
- [variables.counter],
277
- (event, counter) => {
278
- counter.value++;
279
- counter.signal();
280
- }
281
- ),
282
- });
283
-
284
- export const page = body ({
285
- class: "bg-black text-white",
286
- },
287
- p ({
288
- innerText: observe(
289
- [variables.counter],
290
- (value) => \`The Counter is at: \${value}\`,
291
- )
292
- }),
293
-
294
- button ({
295
- onClick: functions.increment,
296
- },
297
- "Increment Counter",
298
- ),
299
- );
300
- `;
301
- var convertToSpans = (inputString) => {
302
- const tokenMap = {
303
- "body": "text-orange-400",
304
- "observe": "text-orange-400",
305
- "createState": "text-orange-400",
306
- "p": "text-orange-400",
307
- "button": "text-orange-400",
308
- "eventListener": "text-orange-400",
309
- "signal": "text-orange-400",
310
- "const": "text-orange-300",
311
- "return": "text-orange-300",
312
- "export": "text-red-400",
313
- "import": "text-red-400",
314
- "from": "text-red-400",
315
- "onClick": "text-orange-200",
316
- "innerText": "text-orange-200",
317
- "class": "text-orange-200",
318
- "increment": "text-orange-200",
319
- "counter": "text-orange-200",
320
- "event": "text-orange-200"
321
- };
322
- const regex = /(?:\/\/[^\n]*|\/\*[\s\S]*?\*\/)|\b(?:const|incrementobserve|createState|export|import|from|return|body|p|button|onClick|ids|update|event|innerText|counter|class|signal|eventListener)\b|"(?:\\.|[^"\\])*"|\${[^}]*}|`(?:\\.|[^`\\])*`/g;
323
- const result = inputString.replace(regex, (match) => {
324
- if (match.startsWith("//")) {
325
- return `<span class="text-neutral-500">${match}</span>`;
326
- } else if (match.startsWith("${") && match.endsWith("}")) {
327
- return `<span class="text-purple-400">${match}</span>`;
328
- } else if (match.startsWith('"') && match.endsWith('"')) {
329
- return `<span class="text-green-400">${match}</span>`;
330
- } else if (match.startsWith("`") && match.endsWith("`")) {
331
- return `<span class="text-green-400">${match}</span>`;
332
- }
333
- const className = tokenMap[match];
334
- return className ? `<span class="${className}">${match}</span>` : match;
335
- });
336
- return result;
337
- };
338
- var page = RootLayout(
339
- Header(),
340
- div(
341
- {
342
- class: "max-w-[900px] w-full mx-auto pt-4 px-2"
343
- },
344
- div(
345
- {
346
- class: "text-center px-4 pt-8 mb-12 sm:mb-20"
347
- },
348
- div(
349
- {
350
- class: "text-3xl md:text-4xl lg:text-5xl font-bold font-inter mb-4"
351
- },
352
- span({
353
- innerText: "Your site doesn't"
354
- }),
355
- span({
356
- innerText: " need "
357
- }),
358
- span({
359
- innerText: "to be slow."
360
- })
361
- ),
362
- p({
363
- class: "text-xs sm:text-sm text-text-100",
364
- innerHTML: 'Nor should you depend on <b class="hover:text-red-400">1314</b> packages to display <b>"Hello World"</b>.'
365
- })
366
- ),
367
- p(
368
- {
369
- class: "text-base sm:text-xl text-center"
370
- },
371
- span({
372
- innerText: "Elegance gives you"
373
- }),
374
- span({
375
- class: "bg-gradient-to-r font-bold from-red-400 to-orange-400 bg-clip-text text-transparent",
376
- innerText: " performance, "
377
- }),
378
- span({
379
- class: "bg-gradient-to-r font-bold from-blue-400 to-green-400 bg-clip-text text-transparent",
380
- innerText: "state-of-the-art features"
381
- }),
382
- span({
383
- innerText: " and "
384
- }),
385
- span({
386
- class: "font-bold bg-gradient-to-r from-purple-400 to-pink-400 bg-clip-text text-transparent",
387
- innerText: "syntaxical sugar, "
388
- }),
389
- span({
390
- class: "",
391
- innerHTML: "whilst leaving <b>you</b> in full control of how your site works."
392
- })
393
- ),
394
- div(
395
- {
396
- class: "mt-6 bg-background-950 p-4 rounded-md mb-8 sm:mb-20"
397
- },
398
- div(
399
- {},
400
- h2({
401
- class: "text-sm sm:text-base text-text-200",
402
- innerText: "/pages/page.ts"
403
- })
404
- ),
405
- pre({
406
- class: "text-xs sm:text-sm font-mono select-text overflow-x-scroll w-full",
407
- innerHTML: convertToSpans(pageTemplateString)
408
- })
409
- )
410
- ),
411
- div(
412
- {
413
- class: "max-w-[900px] w-full mx-auto px-4 pb-64 flex flex-col gap-4 items-start sm:items-center sm:flex-row sm:justify-between"
414
- },
415
- div(
416
- {},
417
- h2({
418
- class: "text-xl sm:text-3xl font-bold",
419
- innerText: "Learn More"
420
- }),
421
- p(
422
- {},
423
- "Interested? ",
424
- "Read our Docs on how Elegance works."
425
- )
426
- ),
427
- Link({
428
- class: "text-base sm:text-lg uppercase font-bold text-background-950 font-semibold px-5 sm:px-6 py-2 sm:py-3 rounded-full bg-accent-400",
429
- href: "/docs/basics",
430
- innerText: "documentation"
431
- })
432
- )
433
- );
434
- export {
435
- metadata,
436
- page
437
- };
@@ -1 +0,0 @@
1
- export declare const highlightCode: (code: string) => string;
@@ -1,171 +0,0 @@
1
- // src/docs/utils/MEGALEXER.ts
2
- var tokenize = (input) => {
3
- const tokens = [];
4
- const length = input.length;
5
- let index = 0;
6
- const keywords = /* @__PURE__ */ new Set([
7
- "if",
8
- "else",
9
- "for",
10
- "while",
11
- "function",
12
- "return",
13
- "class",
14
- "const",
15
- "let",
16
- "var",
17
- "interface",
18
- "extends",
19
- "implements",
20
- "export",
21
- "import",
22
- "from"
23
- ]);
24
- const operatorChars = /* @__PURE__ */ new Set([
25
- "+",
26
- "-",
27
- "*",
28
- "/",
29
- "%",
30
- "=",
31
- ">",
32
- "<",
33
- "!",
34
- "&",
35
- "|",
36
- "^",
37
- "~",
38
- "?",
39
- ":"
40
- ]);
41
- const punctuationChars = /* @__PURE__ */ new Set([
42
- ";",
43
- ",",
44
- ".",
45
- "(",
46
- ")",
47
- "{",
48
- "}",
49
- "[",
50
- "]"
51
- ]);
52
- const peek = (offset = 1) => index + offset < length ? input[index + offset] : "";
53
- const readWhile = (predicate) => {
54
- const start = index;
55
- while (index < length && predicate(input[index])) {
56
- index++;
57
- }
58
- return input.slice(start, index);
59
- };
60
- const readString = (quoteType) => {
61
- let value = input[index++];
62
- while (index < length && input[index] !== quoteType) {
63
- if (input[index] === "\\") {
64
- value += input[index++];
65
- if (index < length) {
66
- value += input[index++];
67
- }
68
- } else {
69
- value += input[index++];
70
- }
71
- }
72
- if (index < length) {
73
- value += input[index++];
74
- }
75
- return value;
76
- };
77
- const readLineComment = () => {
78
- const start = index;
79
- index += 2;
80
- while (index < length && input[index] !== "\n") {
81
- index++;
82
- }
83
- return input.slice(start, index);
84
- };
85
- const readBlockComment = () => {
86
- const start = index;
87
- index += 2;
88
- while (index < length && !(input[index] === "*" && peek() === "/")) {
89
- index++;
90
- }
91
- if (index < length) {
92
- index += 2;
93
- }
94
- return input.slice(start, index);
95
- };
96
- while (index < length) {
97
- const char = input[index];
98
- const startPos = index;
99
- if (/\s/.test(char)) {
100
- const value = readWhile((c) => /\s/.test(c));
101
- tokens.push({ type: "" /* Whitespace */, value, position: startPos });
102
- continue;
103
- }
104
- if (char === "/") {
105
- if (peek() === "/") {
106
- const value = readLineComment();
107
- tokens.push({ type: "text-gray-400" /* Comment */, value, position: startPos });
108
- continue;
109
- } else if (peek() === "*") {
110
- const value = readBlockComment();
111
- tokens.push({ type: "text-gray-400" /* Comment */, value, position: startPos });
112
- continue;
113
- }
114
- }
115
- if (char === '"' || char === "'") {
116
- const value = readString(char);
117
- tokens.push({ type: "text-green-200" /* String */, value, position: startPos });
118
- continue;
119
- }
120
- if (/\d/.test(char)) {
121
- const value = readWhile((c) => /[\d\.]/.test(c));
122
- tokens.push({ type: "text-blue-400" /* Number */, value, position: startPos });
123
- continue;
124
- }
125
- if (/[a-zA-Z_$]/.test(char)) {
126
- const value = readWhile((c) => /[a-zA-Z0-9_$]/.test(c));
127
- let type = "text-orange-300" /* Identifier */;
128
- if (keywords.has(value)) {
129
- type = "text-amber-100 font-semibold" /* Keyword */;
130
- } else if (value === "true" || value === "false") {
131
- type = "text-blue-200" /* Boolean */;
132
- }
133
- let tempIndex = index;
134
- while (tempIndex < length && /\s/.test(input[tempIndex])) {
135
- tempIndex++;
136
- }
137
- if (tempIndex < length && input[tempIndex] === "(") {
138
- type = "text-red-300" /* FunctionCall */;
139
- }
140
- tokens.push({ type, value, position: startPos });
141
- continue;
142
- }
143
- if (operatorChars.has(char)) {
144
- let value = char;
145
- index++;
146
- if (index < length && operatorChars.has(input[index])) {
147
- value += input[index++];
148
- }
149
- tokens.push({ type: "" /* Operator */, value, position: startPos });
150
- continue;
151
- }
152
- if (punctuationChars.has(char)) {
153
- tokens.push({ type: "text-gray-400" /* Punctuation */, value: char, position: startPos });
154
- index++;
155
- continue;
156
- }
157
- tokens.push({ type: "" /* Unknown */, value: char, position: startPos });
158
- index++;
159
- }
160
- return tokens;
161
- };
162
- var escapeHtml = (text) => text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
163
- var highlightCode = (code) => {
164
- const tokens = tokenize(code);
165
- return tokens.map(
166
- (token) => token.type === "" /* Whitespace */ ? token.value : `<span class="${token.type}">${escapeHtml(token.value)}</span>`
167
- ).join("");
168
- };
169
- export {
170
- highlightCode
171
- };