elegance-js 2.0.17 → 2.0.18

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 (45) hide show
  1. package/package.json +1 -1
  2. package/dist/docs/components/Header.d.ts +0 -1
  3. package/dist/docs/components/Header.mjs +0 -249
  4. package/dist/docs/components/RootLayout.d.ts +0 -1
  5. package/dist/docs/components/RootLayout.mjs +0 -10
  6. package/dist/docs/docs/basics/page.d.ts +0 -2
  7. package/dist/docs/docs/basics/page.mjs +0 -1057
  8. package/dist/docs/docs/compilations/page.d.ts +0 -2
  9. package/dist/docs/docs/compilations/page.mjs +0 -15
  10. package/dist/docs/docs/components/CodeBlock.d.ts +0 -2
  11. package/dist/docs/docs/components/CodeBlock.mjs +0 -324
  12. package/dist/docs/docs/components/DocsLayout.d.ts +0 -1
  13. package/dist/docs/docs/components/DocsLayout.mjs +0 -527
  14. package/dist/docs/docs/components/Header.d.ts +0 -1
  15. package/dist/docs/docs/components/Header.mjs +0 -160
  16. package/dist/docs/docs/components/Mono.d.ts +0 -1
  17. package/dist/docs/docs/components/Mono.mjs +0 -7
  18. package/dist/docs/docs/components/PageHeading.d.ts +0 -1
  19. package/dist/docs/docs/components/PageHeading.mjs +0 -9
  20. package/dist/docs/docs/components/Paragraph.d.ts +0 -1
  21. package/dist/docs/docs/components/Paragraph.mjs +0 -10
  22. package/dist/docs/docs/components/Separator.d.ts +0 -1
  23. package/dist/docs/docs/components/Separator.mjs +0 -7
  24. package/dist/docs/docs/components/SubHeading.d.ts +0 -1
  25. package/dist/docs/docs/components/SubHeading.mjs +0 -8
  26. package/dist/docs/docs/components/SubSeparator.d.ts +0 -1
  27. package/dist/docs/docs/components/SubSeparator.mjs +0 -7
  28. package/dist/docs/docs/components/Subtext.d.ts +0 -1
  29. package/dist/docs/docs/components/Subtext.mjs +0 -8
  30. package/dist/docs/docs/concepts/page.d.ts +0 -2
  31. package/dist/docs/docs/concepts/page.mjs +0 -954
  32. package/dist/docs/docs/page-files/page.d.ts +0 -2
  33. package/dist/docs/docs/page-files/page.mjs +0 -1206
  34. package/dist/docs/docs/route.d.ts +0 -2
  35. package/dist/docs/docs/route.mjs +0 -8
  36. package/dist/docs/docs/running/page.d.ts +0 -2
  37. package/dist/docs/docs/running/page.mjs +0 -7
  38. package/dist/docs/nullpage/page.d.ts +0 -2
  39. package/dist/docs/nullpage/page.mjs +0 -58
  40. package/dist/docs/page.d.ts +0 -2
  41. package/dist/docs/page.mjs +0 -437
  42. package/dist/docs/utils/MEGALEXER.d.ts +0 -1
  43. package/dist/docs/utils/MEGALEXER.mjs +0 -171
  44. package/dist/types/Metadata.d.ts +0 -19
  45. package/dist/types/Metadata.mjs +0 -15
@@ -1,1057 +0,0 @@
1
- // src/docs/components/RootLayout.ts
2
- var RootLayout = (...children) => body(
3
- {
4
- class: "bg-background-900 text-text-50 font-inter select-none text-text-50"
5
- },
6
- ...children
7
- );
8
-
9
- // src/docs/docs/components/PageHeading.ts
10
- var PageHeading = (title2, id) => h2({
11
- class: "text-3xl font-semibold mb-4",
12
- id,
13
- innerText: title2
14
- });
15
-
16
- // src/components/Breakpoint.ts
17
- var Breakpoint = (options, ...children) => {
18
- process.emitWarning(
19
- "Function Breakpoint() is deprecated. Prefer layout.ts files instead.",
20
- { type: "DeprecationWarning" }
21
- );
22
- if (options.id === void 0) throw `Breakpoints must set a name attribute.`;
23
- const id = options.id;
24
- delete options.id;
25
- return div(
26
- {
27
- bp: id,
28
- ...options
29
- },
30
- ...children
31
- );
32
- };
33
-
34
- // src/internal/deprecate.ts
35
- var ShowDeprecationWarning = (msg) => {
36
- console.warn("\x1B[31m", msg, "\x1B[0m");
37
- console.trace("Stack Trace:");
38
- };
39
-
40
- // src/server/loadHook.ts
41
- var loadHook = (deps, fn, bind) => {
42
- const stringFn = fn.toString();
43
- const depsArray = (deps || []).map((dep) => ({
44
- id: dep.id,
45
- bind: dep.bind
46
- }));
47
- let dependencyString = "[";
48
- for (const dep of depsArray) {
49
- dependencyString += `{id:${dep.id}`;
50
- if (dep.bind) dependencyString += `,bind:${dep.bind}`;
51
- dependencyString += `},`;
52
- }
53
- dependencyString += "]";
54
- const isAsync = fn.constructor.name === "AsyncFunction";
55
- const wrapperFn = isAsync ? `async (state) => await (${stringFn})(state, ...state.getAll(${dependencyString}))` : `(state) => (${stringFn})(state, ...state.getAll(${dependencyString}))`;
56
- globalThis.__SERVER_CURRENT_LOADHOOKS__.push({
57
- fn: wrapperFn,
58
- bind: bind || ""
59
- });
60
- };
61
- var createLoadHook = (options) => {
62
- ShowDeprecationWarning("WARNING: createLoadHook() is a deprecated function. Use loadHook() from elegance-js/loadHook instead.");
63
- const stringFn = options.fn.toString();
64
- const deps = (options.deps || []).map((dep) => ({
65
- id: dep.id,
66
- bind: dep.bind
67
- }));
68
- let dependencyString = "[";
69
- for (const dep of deps) {
70
- dependencyString += `{id:${dep.id}`;
71
- if (dep.bind) dependencyString += `,bind:${dep.bind}`;
72
- dependencyString += `},`;
73
- }
74
- dependencyString += "]";
75
- const isAsync = options.fn.constructor.name === "AsyncFunction";
76
- const wrapperFn = isAsync ? `async (state) => await (${stringFn})(state, ...state.getAll(${dependencyString}))` : `(state) => (${stringFn})(state, ...state.getAll(${dependencyString}))`;
77
- globalThis.__SERVER_CURRENT_LOADHOOKS__.push({
78
- fn: wrapperFn,
79
- bind: options.bind || ""
80
- });
81
- };
82
-
83
- // src/server/state.ts
84
- if (!globalThis.__SERVER_CURRENT_STATE_ID__) {
85
- globalThis.__SERVER_CURRENT_STATE_ID__ = 1;
86
- }
87
- var eventListener = (dependencies, eventListener2) => {
88
- const deps = dependencies.map((dep) => ({ id: dep.id, bind: dep.bind }));
89
- let dependencyString = "[";
90
- for (const dep of deps) {
91
- dependencyString += `{id:${dep.id}`;
92
- if (dep.bind) dependencyString += `,bind:${dep.bind}`;
93
- dependencyString += `},`;
94
- }
95
- dependencyString += "]";
96
- const value = {
97
- id: __SERVER_CURRENT_STATE_ID__ += 1,
98
- type: 1 /* STATE */,
99
- value: new Function(
100
- "state",
101
- "event",
102
- `(${eventListener2.toString()})(event, ...state.getAll(${dependencyString}))`
103
- )
104
- };
105
- globalThis.__SERVER_CURRENT_STATE__.push(value);
106
- return value;
107
- };
108
-
109
- // src/server/observe.ts
110
- var observe = (refs, update) => {
111
- const returnValue = {
112
- type: 2 /* OBSERVER */,
113
- initialValues: refs.map((ref) => ref.value),
114
- update,
115
- refs: refs.map((ref) => ({
116
- id: ref.id,
117
- bind: ref.bind
118
- }))
119
- };
120
- return returnValue;
121
- };
122
-
123
- // src/components/Link.ts
124
- loadHook(
125
- [],
126
- () => {
127
- const anchors = Array.from(document.querySelectorAll("a[prefetch]"));
128
- const elsToClear = [];
129
- for (const anchor of anchors) {
130
- const prefetch = anchor.getAttribute("prefetch");
131
- const href = new URL(anchor.href);
132
- switch (prefetch) {
133
- case "load":
134
- client.fetchPage(href);
135
- break;
136
- case "hover":
137
- const fn = () => {
138
- client.fetchPage(href);
139
- };
140
- anchor.addEventListener("mouseenter", fn);
141
- elsToClear.push({
142
- el: anchor,
143
- fn
144
- });
145
- break;
146
- }
147
- }
148
- return () => {
149
- for (const listener of elsToClear) {
150
- listener.el.removeEventListener("mouseenter", listener.fn);
151
- }
152
- };
153
- }
154
- );
155
- var navigate = eventListener(
156
- [],
157
- (event) => {
158
- const target = new URL(event.currentTarget.href);
159
- const client2 = globalThis.client;
160
- const sanitizedTarget = client2.sanitizePathname(target.pathname);
161
- const sanitizedCurrent = client2.sanitizePathname(window.location.pathname);
162
- if (sanitizedTarget === sanitizedCurrent) {
163
- if (target.hash === window.location.hash) return event.preventDefault();
164
- return;
165
- }
166
- event.preventDefault();
167
- client2.navigateLocally(target.href);
168
- }
169
- );
170
- var Link = (options, ...children) => {
171
- if (!options.href) {
172
- throw `Link elements must have a HREF attribute set.`;
173
- }
174
- if (!options.href.startsWith("/")) {
175
- throw `Link elements may only navigate to local pages. "/"`;
176
- }
177
- return a(
178
- {
179
- ...options,
180
- onClick: navigate
181
- },
182
- ...children
183
- );
184
- };
185
-
186
- // src/server/createState.ts
187
- if (!globalThis.__SERVER_CURRENT_STATE_ID__) {
188
- globalThis.__SERVER_CURRENT_STATE_ID__ = 1;
189
- }
190
- var createState = (value, options) => {
191
- ShowDeprecationWarning("WARNING: The createState() and function is deprecated. Please use state() instead, from elegance-js/state.");
192
- const serverStateEntry = {
193
- id: __SERVER_CURRENT_STATE_ID__ += 1,
194
- value,
195
- type: 1 /* STATE */,
196
- bind: options?.bind
197
- };
198
- globalThis.__SERVER_CURRENT_STATE__.push(serverStateEntry);
199
- return serverStateEntry;
200
- };
201
- var createEventListener = ({
202
- eventListener: eventListener2,
203
- dependencies = [],
204
- params
205
- }) => {
206
- ShowDeprecationWarning("WARNING: The createEventListener() and function is deprecated. Please use eventListener() instead, from elegance-js/state.");
207
- const deps = dependencies.map((dep) => ({ id: dep.id, bind: dep.bind }));
208
- let dependencyString = "[";
209
- for (const dep of deps) {
210
- dependencyString += `{id:${dep.id}`;
211
- if (dep.bind) dependencyString += `,bind:${dep.bind}`;
212
- dependencyString += `},`;
213
- }
214
- dependencyString += "]";
215
- const value = {
216
- id: __SERVER_CURRENT_STATE_ID__ += 1,
217
- type: 1 /* STATE */,
218
- value: new Function(
219
- "state",
220
- "event",
221
- `(${eventListener2.toString()})({ event, ...${JSON.stringify(params || {})} }, ...state.getAll(${dependencyString}))`
222
- )
223
- };
224
- globalThis.__SERVER_CURRENT_STATE__.push(value);
225
- return value;
226
- };
227
-
228
- // src/docs/docs/components/Header.ts
229
- var Header = () => header(
230
- {
231
- 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"
232
- },
233
- div(
234
- {
235
- class: "group duration-300 border-b-[1px] hover:border-b-transparent pointer-fine:hover:bg-accent-400 border-b-background-800 bg-background-950"
236
- },
237
- div(
238
- {
239
- class: "max-w-[1200px] w-full mx-auto flex pr-2 px-3 sm:px-5 sm:min-[calc(1200px+1rem)]:px-0"
240
- },
241
- div(
242
- {
243
- class: "flex min-w-max w-full items-center z-10"
244
- },
245
- Link(
246
- {
247
- href: "/",
248
- class: "flex items-center gap-1 h-full"
249
- },
250
- p({
251
- 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",
252
- innerText: "Elegance"
253
- }),
254
- p({
255
- innerText: "JS",
256
- 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"
257
- })
258
- )
259
- ),
260
- div(
261
- {
262
- class: "flex py-2 sm:py-4 flex relative items-center justify-end w-full"
263
- },
264
- Link({
265
- prefetch: "hover",
266
- 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",
267
- href: "/docs",
268
- innerText: "Docs"
269
- })
270
- )
271
- )
272
- )
273
- );
274
-
275
- // src/docs/utils/MEGALEXER.ts
276
- var tokenize = (input) => {
277
- const tokens = [];
278
- const length = input.length;
279
- let index = 0;
280
- const keywords = /* @__PURE__ */ new Set([
281
- "if",
282
- "else",
283
- "for",
284
- "while",
285
- "function",
286
- "return",
287
- "class",
288
- "const",
289
- "let",
290
- "var",
291
- "interface",
292
- "extends",
293
- "implements",
294
- "export",
295
- "import",
296
- "from"
297
- ]);
298
- const operatorChars = /* @__PURE__ */ new Set([
299
- "+",
300
- "-",
301
- "*",
302
- "/",
303
- "%",
304
- "=",
305
- ">",
306
- "<",
307
- "!",
308
- "&",
309
- "|",
310
- "^",
311
- "~",
312
- "?",
313
- ":"
314
- ]);
315
- const punctuationChars = /* @__PURE__ */ new Set([
316
- ";",
317
- ",",
318
- ".",
319
- "(",
320
- ")",
321
- "{",
322
- "}",
323
- "[",
324
- "]"
325
- ]);
326
- const peek = (offset = 1) => index + offset < length ? input[index + offset] : "";
327
- const readWhile = (predicate) => {
328
- const start = index;
329
- while (index < length && predicate(input[index])) {
330
- index++;
331
- }
332
- return input.slice(start, index);
333
- };
334
- const readString = (quoteType) => {
335
- let value = input[index++];
336
- while (index < length && input[index] !== quoteType) {
337
- if (input[index] === "\\") {
338
- value += input[index++];
339
- if (index < length) {
340
- value += input[index++];
341
- }
342
- } else {
343
- value += input[index++];
344
- }
345
- }
346
- if (index < length) {
347
- value += input[index++];
348
- }
349
- return value;
350
- };
351
- const readLineComment = () => {
352
- const start = index;
353
- index += 2;
354
- while (index < length && input[index] !== "\n") {
355
- index++;
356
- }
357
- return input.slice(start, index);
358
- };
359
- const readBlockComment = () => {
360
- const start = index;
361
- index += 2;
362
- while (index < length && !(input[index] === "*" && peek() === "/")) {
363
- index++;
364
- }
365
- if (index < length) {
366
- index += 2;
367
- }
368
- return input.slice(start, index);
369
- };
370
- while (index < length) {
371
- const char = input[index];
372
- const startPos = index;
373
- if (/\s/.test(char)) {
374
- const value = readWhile((c) => /\s/.test(c));
375
- tokens.push({ type: "" /* Whitespace */, value, position: startPos });
376
- continue;
377
- }
378
- if (char === "/") {
379
- if (peek() === "/") {
380
- const value = readLineComment();
381
- tokens.push({ type: "text-gray-400" /* Comment */, value, position: startPos });
382
- continue;
383
- } else if (peek() === "*") {
384
- const value = readBlockComment();
385
- tokens.push({ type: "text-gray-400" /* Comment */, value, position: startPos });
386
- continue;
387
- }
388
- }
389
- if (char === '"' || char === "'") {
390
- const value = readString(char);
391
- tokens.push({ type: "text-green-200" /* String */, value, position: startPos });
392
- continue;
393
- }
394
- if (/\d/.test(char)) {
395
- const value = readWhile((c) => /[\d\.]/.test(c));
396
- tokens.push({ type: "text-blue-400" /* Number */, value, position: startPos });
397
- continue;
398
- }
399
- if (/[a-zA-Z_$]/.test(char)) {
400
- const value = readWhile((c) => /[a-zA-Z0-9_$]/.test(c));
401
- let type = "text-orange-300" /* Identifier */;
402
- if (keywords.has(value)) {
403
- type = "text-amber-100 font-semibold" /* Keyword */;
404
- } else if (value === "true" || value === "false") {
405
- type = "text-blue-200" /* Boolean */;
406
- }
407
- let tempIndex = index;
408
- while (tempIndex < length && /\s/.test(input[tempIndex])) {
409
- tempIndex++;
410
- }
411
- if (tempIndex < length && input[tempIndex] === "(") {
412
- type = "text-red-300" /* FunctionCall */;
413
- }
414
- tokens.push({ type, value, position: startPos });
415
- continue;
416
- }
417
- if (operatorChars.has(char)) {
418
- let value = char;
419
- index++;
420
- if (index < length && operatorChars.has(input[index])) {
421
- value += input[index++];
422
- }
423
- tokens.push({ type: "" /* Operator */, value, position: startPos });
424
- continue;
425
- }
426
- if (punctuationChars.has(char)) {
427
- tokens.push({ type: "text-gray-400" /* Punctuation */, value: char, position: startPos });
428
- index++;
429
- continue;
430
- }
431
- tokens.push({ type: "" /* Unknown */, value: char, position: startPos });
432
- index++;
433
- }
434
- return tokens;
435
- };
436
- var escapeHtml = (text) => text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
437
- var highlightCode = (code) => {
438
- const tokens = tokenize(code);
439
- return tokens.map(
440
- (token) => token.type === "" /* Whitespace */ ? token.value : `<span class="${token.type}">${escapeHtml(token.value)}</span>`
441
- ).join("");
442
- };
443
-
444
- // src/docs/docs/components/CodeBlock.ts
445
- var isToastShowing = createState(false);
446
- var toastTimeoutId = createState(0);
447
- var copyCode = createEventListener({
448
- dependencies: [
449
- isToastShowing,
450
- toastTimeoutId
451
- ],
452
- eventListener: async (params, isToastShowing2, toastTimeoutId2) => {
453
- const children = params.event.currentTarget.children;
454
- const pre2 = children.item(0);
455
- const content = pre2.innerText;
456
- await navigator.clipboard.writeText(content);
457
- if (toastTimeoutId2.value !== 0) clearTimeout(toastTimeoutId2.value);
458
- isToastShowing2.value = true;
459
- isToastShowing2.signal();
460
- const timeoutId = window.setTimeout(() => {
461
- isToastShowing2.value = false;
462
- isToastShowing2.signal();
463
- }, 3e3);
464
- toastTimeoutId2.value = timeoutId;
465
- }
466
- });
467
- var Toast = (bind) => {
468
- createLoadHook({
469
- bind,
470
- deps: [
471
- toastTimeoutId,
472
- isToastShowing
473
- ],
474
- fn: (state2, toastTimeoutId2, isToastShowing2) => {
475
- return () => {
476
- clearTimeout(toastTimeoutId2.value);
477
- isToastShowing2.value = false;
478
- isToastShowing2.signal();
479
- };
480
- }
481
- });
482
- return div(
483
- {
484
- class: observe(
485
- [isToastShowing],
486
- (isShowing) => {
487
- const modularClass = isShowing ? "right-8" : "right-0 translate-x-full";
488
- return `fixed z-50 shadow-lg rounded-sm duration-200 bottom-4 px-4 py-2 w-max bg-background-950 ` + modularClass;
489
- }
490
- )
491
- },
492
- h1({
493
- class: "font-mono uppercase"
494
- }, "copied to clipboard")
495
- );
496
- };
497
- var escapeHtml2 = (str) => {
498
- const replaced = str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
499
- return replaced;
500
- };
501
- var CodeBlock = (value, parse = true) => div(
502
- {
503
- class: `bg-background-950 hover:cursor-pointer p-2 rounded-sm
504
- border-[1px] border-background-800 w-max my-3 max-w-full
505
- overflow-scroll`,
506
- onClick: copyCode
507
- },
508
- pre({}, parse ? highlightCode(value) : escapeHtml2(value))
509
- );
510
-
511
- // src/server/layout.ts
512
- if (!globalThis.__SERVER_CURRENT_LAYOUT_ID__) globalThis.__SERVER_CURRENT_LAYOUT_ID__ = 1;
513
- var createLayout = (name) => {
514
- process.emitWarning(
515
- "Function createLayout() is deprecated. Prefer layout.ts files instead.",
516
- { type: "DeprecationWarning" }
517
- );
518
- const layouts = globalThis.__SERVER_CURRENT_LAYOUTS__;
519
- if (layouts.has(name)) return layouts.get(name);
520
- const id = globalThis.__SERVER_CURRENT_LAYOUT_ID__ += 1;
521
- layouts.set(name, id);
522
- return id;
523
- };
524
-
525
- // src/docs/docs/components/DocsLayout.ts
526
- var docsLayoutId = createLayout("docs-layout");
527
- var secondsSpentOnPage = createState(0, {
528
- bind: docsLayoutId
529
- });
530
- createLoadHook({
531
- deps: [secondsSpentOnPage],
532
- bind: docsLayoutId,
533
- fn: (state2, time) => {
534
- const storedTime = localStorage.getItem("time-on-page");
535
- if (storedTime) {
536
- time.value = parseInt(storedTime);
537
- time.signal();
538
- }
539
- let intervalId;
540
- intervalId = setInterval(() => {
541
- time.value++;
542
- time.signal();
543
- }, 1e3);
544
- const handlePageLeave = () => {
545
- localStorage.setItem("time-on-page", `${time.value}`);
546
- };
547
- window.addEventListener("beforeunload", handlePageLeave);
548
- return () => {
549
- window.removeEventListener("beforeunload", handlePageLeave);
550
- handlePageLeave();
551
- clearInterval(intervalId);
552
- };
553
- }
554
- });
555
- var NavSubLink = (href, innerText) => Link({
556
- class: "text-sm font-normal flex flex-col gap-2 opacity-80 hover:opacity-60 duration-200",
557
- innerText,
558
- href,
559
- prefetch: "hover"
560
- });
561
- var Sidebar = () => nav(
562
- {
563
- class: "w-1/5"
564
- },
565
- ul(
566
- {
567
- class: "flex flex-col gap-4"
568
- },
569
- li(
570
- {},
571
- h2(
572
- {
573
- class: "text-lg font-semibold"
574
- },
575
- "Quick Nav"
576
- ),
577
- span(
578
- {
579
- class: "text-xs opacity-75"
580
- },
581
- "Elapsed: ",
582
- span({
583
- class: "font-mono",
584
- innerText: observe(
585
- [secondsSpentOnPage],
586
- (secondsSpentOnPage2) => {
587
- const hours = Math.floor(secondsSpentOnPage2 / 60 / 60);
588
- const minutes = Math.floor(secondsSpentOnPage2 / 60 % 60);
589
- const seconds = secondsSpentOnPage2 % 60;
590
- return `${hours}h:${minutes}m:${seconds}s`;
591
- }
592
- )
593
- })
594
- )
595
- ),
596
- li(
597
- {
598
- class: "flex flex-col gap-1"
599
- },
600
- h4({
601
- class: "text-base font-medium",
602
- innerText: "The Basics"
603
- }),
604
- ol(
605
- {
606
- class: "pl-2 ml-2 border-l-[1px] border-background-600 flex flex-col gap-2"
607
- },
608
- NavSubLink(
609
- "/docs/basics#preamble",
610
- "Preamble"
611
- ),
612
- NavSubLink(
613
- "/docs/basics#how-elegance-works",
614
- "How Elegance Works"
615
- ),
616
- NavSubLink(
617
- "/docs/basics#installation",
618
- "Installation"
619
- ),
620
- NavSubLink(
621
- "/docs/basics#your-first-page",
622
- "Your First Page"
623
- )
624
- )
625
- ),
626
- li(
627
- {
628
- class: "flex flex-col gap-1"
629
- },
630
- h4({
631
- class: "text-base font-medium",
632
- innerText: "Concepts"
633
- }),
634
- ol(
635
- {
636
- class: "pl-2 ml-2 border-l-[1px] border-background-600 flex flex-col gap-2"
637
- },
638
- NavSubLink(
639
- "/docs/concepts#elements",
640
- "Elements"
641
- ),
642
- NavSubLink(
643
- "/docs/concepts#object-attributes",
644
- "Object Attributes"
645
- )
646
- )
647
- ),
648
- li(
649
- {
650
- class: "flex flex-col gap-1"
651
- },
652
- h4({
653
- class: "text-base font-medium",
654
- innerText: "Page Files"
655
- }),
656
- ol(
657
- {
658
- class: "pl-2 ml-2 border-l-[1px] border-background-600 flex flex-col gap-2"
659
- },
660
- NavSubLink(
661
- "/docs/page-files#state",
662
- "State"
663
- ),
664
- NavSubLink(
665
- "/docs/page-files#load-hooks",
666
- "Load Hooks"
667
- ),
668
- NavSubLink(
669
- "/docs/page-files#event-listeners",
670
- "Event Listeners"
671
- ),
672
- NavSubLink(
673
- "/docs/page-files#layouts",
674
- "Layouts"
675
- )
676
- )
677
- ),
678
- li(
679
- {
680
- class: "flex flex-col gap-1"
681
- },
682
- h4({
683
- class: "text-base font-medium",
684
- innerText: "Compilation"
685
- }),
686
- ol(
687
- {
688
- class: "pl-2 ml-2 border-l-[1px] border-background-600 flex flex-col gap-2"
689
- },
690
- NavSubLink(
691
- "/docs/compilation#options",
692
- "Compilation Options"
693
- )
694
- )
695
- )
696
- )
697
- );
698
- var DocsLayout = (...children) => div(
699
- {
700
- class: "h-screen overflow-clip"
701
- },
702
- Header(),
703
- Toast(docsLayoutId),
704
- div(
705
- {
706
- class: "max-w-[1200px] h-full w-full mx-auto flex pt-8 px-3 sm:px-5 sm:min-[calc(1200px+1rem)]:px-0"
707
- },
708
- Sidebar(),
709
- article(
710
- {
711
- class: "h-full w-full overflow-y-scroll pb-[250px] pl-6 ml-6"
712
- },
713
- Breakpoint(
714
- {
715
- id: docsLayoutId
716
- },
717
- ...children
718
- )
719
- )
720
- )
721
- );
722
-
723
- // src/docs/docs/components/Separator.ts
724
- var Separator = () => div({
725
- class: "my-20"
726
- }, []);
727
-
728
- // src/docs/docs/components/Mono.ts
729
- var Mono = (text) => span({
730
- class: "font-mono select-text"
731
- }, text);
732
-
733
- // src/docs/docs/basics/page.ts
734
- var bodyCallResult = `
735
- {
736
- tag: "body",
737
- options: {
738
- style: "background-color: #000; color: #fff;",
739
- },
740
- children: [
741
- {
742
- tag: "h1",
743
- options: {
744
- innerText: "Greetings Traveler!",
745
- },
746
- children: [],
747
- },
748
- ],
749
- }
750
- `;
751
- var demoPageTS = `export const page = body ({
752
- style: "background-color: #000; color: #fff;",
753
- },
754
- h1 ("Greetings Traveler!"),
755
- );`;
756
- var demoInfoTS = `export const metadata = () => head (
757
- title ("The BEST Page Ever!"),
758
- );
759
- `;
760
- var metadata = () => head(
761
- {},
762
- link({
763
- rel: "stylesheet",
764
- href: "/index.css"
765
- }),
766
- title("Hi There!")
767
- );
768
- var page = RootLayout(
769
- DocsLayout(
770
- PageHeading(
771
- "Preamble",
772
- "preamble"
773
- ),
774
- h3({
775
- class: "text-lg font-medium mb-1",
776
- innerText: "A Quick Forewarning"
777
- }),
778
- p(
779
- {
780
- class: "opacity-80"
781
- },
782
- "Elegance is still only in Beta.",
783
- br(),
784
- "There are absolutely no guarantees of backwards compatibility, security or really anything.",
785
- br(),
786
- "As such, elegance isn't really meant for production, yet."
787
- ),
788
- Separator(),
789
- h3({
790
- class: "text-lg font-medium mb-1",
791
- innerText: "What is Elegance?"
792
- }),
793
- p(
794
- {
795
- class: "opacity-80"
796
- },
797
- "Elegance is an opinionated, strict, compiled, fully-typescript, ",
798
- br(),
799
- "web-framework designed for building feature-rich, yet fast and efficient web pages.",
800
- br(),
801
- br(),
802
- "Elegance is written fully by hand, and dependencies are used ",
803
- b("very "),
804
- "sparsely.",
805
- br(),
806
- "As of writing, ",
807
- b("esbuild "),
808
- "is the only dependency.",
809
- br(),
810
- br(),
811
- "A simple, fully-working (non gzipped) elegance page transfers only ",
812
- b("4kB "),
813
- "of data!",
814
- img({
815
- class: "border-[1px] rounded-sm border-background-600 my-4",
816
- src: "/nullpage_size.png"
817
- }),
818
- 'For context, an "empty" (gzipped) react app on average transfers roughly ',
819
- b("200-300kB "),
820
- "of data.",
821
- br(),
822
- br(),
823
- "This lack of JS sent to the browser is achieved through not ",
824
- "creating unnecessary, wildly complex rude goldberg machines; ",
825
- "and compilation instead of interpretation."
826
- ),
827
- Separator(),
828
- PageHeading(
829
- "How Elegance Works",
830
- "how-elegance-works"
831
- ),
832
- h3({
833
- class: "text-lg font-medium mb-1",
834
- innerText: "File Structure"
835
- }),
836
- p(
837
- {
838
- class: "opacity-80"
839
- },
840
- "An Elegance.JS projects file structure is akin to that of something like a Next.JS project. ",
841
- br(),
842
- "We use filesystem routing, where each directory contains a ",
843
- Mono("page.ts"),
844
- " file."
845
- ),
846
- div({
847
- class: "my-10"
848
- }, []),
849
- h3({
850
- class: "text-lg font-medium mb-1",
851
- innerText: "Page Files"
852
- }),
853
- p(
854
- {
855
- class: "opacity-80"
856
- },
857
- "The page.ts file has two requirements, it must export a ",
858
- Mono("page"),
859
- " object, which is of type ",
860
- Mono('EleganceElement<"body">')
861
- ),
862
- CodeBlock(demoPageTS),
863
- p(
864
- {
865
- class: "opacity-80"
866
- },
867
- "and it must also export a ",
868
- Mono("metadata"),
869
- " function, which then resolves into an ",
870
- Mono('EleganceElement<"head">')
871
- ),
872
- CodeBlock(demoInfoTS),
873
- p(
874
- {
875
- class: "opacity-80"
876
- },
877
- "Elements are created using simple, ambient global functions.",
878
- br(),
879
- "The above ",
880
- Mono("body()"),
881
- " call, for example, gets turned into this."
882
- ),
883
- CodeBlock(bodyCallResult),
884
- p(
885
- {
886
- class: "opacity-80"
887
- },
888
- "The estute among you may have noticed that the result can easily be serialized into HTML or JSON.",
889
- br(),
890
- "This is ",
891
- b("precisely "),
892
- "what the Elegance compiler does.",
893
- br(),
894
- br(),
895
- "It recursively goes through the page, notes down any points of interest (more on this later), ",
896
- br(),
897
- "and then serializes each element.",
898
- br(),
899
- br(),
900
- "The resulting data can then either be used to serve static HTML pages, ",
901
- br(),
902
- "(which still have all the normal features of Elegance, but won't get re-rendered),",
903
- br(),
904
- "or dynamically server-rendered content."
905
- ),
906
- p(
907
- {
908
- class: "opacity-80"
909
- },
910
- "Metadata is of course a function, so that you may dynamically generate page information. ",
911
- br(),
912
- br(),
913
- "This is useful for something like a social media page, ",
914
- br(),
915
- "where you may want need to fetch information about a post, and then display it in a nice rich embed."
916
- ),
917
- div({
918
- class: "my-10"
919
- }, []),
920
- h3({
921
- class: "text-lg font-medium mb-1",
922
- innerText: "Compilation"
923
- }),
924
- p(
925
- {
926
- class: "opacity-80"
927
- },
928
- "Elegance exposes a function called ",
929
- Mono("compile()"),
930
- " which your project should call to build itself.",
931
- br(),
932
- "This is typically done via the use of the built in build scripts.",
933
- br(),
934
- "However, if you wish to customize your build options, you need just create a file which calls compile.",
935
- br(),
936
- br(),
937
- "Compilation handles generating page_data files, ",
938
- "HTML, JSON, transpilation of ts into js, etc.",
939
- br(),
940
- br(),
941
- "We will explore compilation, state, reactivity, optimization, ",
942
- "static generation, hot-reloading, and many of the other features of ",
943
- "Elegance in greater-depth later on. However, this is all that you need to know for now."
944
- ),
945
- Separator(),
946
- PageHeading(
947
- "Installation",
948
- "installation"
949
- ),
950
- h3({
951
- class: "text-lg font-medium mb-1",
952
- innerText: "NPM"
953
- }),
954
- p(
955
- {
956
- class: "opacity-80"
957
- },
958
- "To make an elegance project, first create a directory with a name of your choosing.",
959
- br(),
960
- "For this example, we'll use ",
961
- Mono("my-first-webpage"),
962
- br(),
963
- "Then, in that directory, issue the following command to initialize an empty NPM project."
964
- ),
965
- CodeBlock("npm init -y", false),
966
- p(
967
- {
968
- class: "opacity-80"
969
- },
970
- "After this, install elegance-js by running"
971
- ),
972
- CodeBlock("npm install elegance-js", false),
973
- p(
974
- {
975
- class: "opacity-80"
976
- },
977
- "And that's it! Elegance.js has been installed into your project."
978
- ),
979
- Separator(),
980
- PageHeading(
981
- "Your First Page",
982
- "your-first-page"
983
- ),
984
- h3({
985
- class: "text-lg font-medium mb-1",
986
- innerText: "Making a Project"
987
- }),
988
- p(
989
- {
990
- class: "opacity-80"
991
- },
992
- "To bootstrap an Elegance.js project, run the following command in the directory we just made."
993
- ),
994
- CodeBlock("npx bootstrap", false),
995
- p(
996
- {
997
- class: "opacity-80"
998
- },
999
- "This will create a few files and directories for you.",
1000
- br(),
1001
- "Firstly, it creates the aforementioned pages directory, and an example ",
1002
- Mono("page.ts"),
1003
- " file.",
1004
- br(),
1005
- br(),
1006
- "Then it makes a public directory where you can store files",
1007
- br(),
1008
- "that you want to be publicly accessible on your website.",
1009
- br(),
1010
- br(),
1011
- "Thirdly, it creates an ",
1012
- Mono("env.d.ts + tsconfig.json"),
1013
- br(),
1014
- "which gives you ambient global typings for the elements that are in Elegance.",
1015
- br(),
1016
- br(),
1017
- "Lastly, it creates a file in the pages directory called ",
1018
- Mono("index.css"),
1019
- br(),
1020
- "which tailwind will automatically compile and put in your dist folder."
1021
- ),
1022
- div({
1023
- class: "my-10"
1024
- }, []),
1025
- h3({
1026
- class: "text-lg font-medium mb-1",
1027
- innerText: "Running your project."
1028
- }),
1029
- p(
1030
- {
1031
- class: "opacity-80"
1032
- },
1033
- "There's a few way to run elegance.",
1034
- br(),
1035
- br(),
1036
- "The intended way is using our provided scripts."
1037
- ),
1038
- CodeBlock("npx dev", false),
1039
- CodeBlock("npx prod", false),
1040
- CodeBlock("npx static", false),
1041
- p(
1042
- {
1043
- class: "opacity-80"
1044
- },
1045
- "However, you may also serve the files in any way you like.",
1046
- br(),
1047
- br(),
1048
- "API Routes will not be available without the built-in Elegance server,",
1049
- br(),
1050
- "but all static content like event listeners, load hooks, pages, etc, will work."
1051
- )
1052
- )
1053
- );
1054
- export {
1055
- metadata,
1056
- page
1057
- };