juxscript 1.0.131 → 1.1.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.
Files changed (129) hide show
  1. package/README.md +1 -32
  2. package/bin/cli.js +4 -2
  3. package/index.d.ts +200 -0
  4. package/index.js +96 -22
  5. package/juxconfig.example.js +58 -63
  6. package/lib/components/alert.ts +200 -0
  7. package/lib/components/app.ts +247 -0
  8. package/lib/components/badge.ts +101 -0
  9. package/lib/components/base/BaseComponent.ts +421 -0
  10. package/lib/components/base/FormInput.ts +227 -0
  11. package/lib/components/button.ts +178 -0
  12. package/lib/components/card.ts +173 -0
  13. package/lib/components/chart.ts +231 -0
  14. package/lib/components/checkbox.ts +242 -0
  15. package/lib/components/code.ts +123 -0
  16. package/lib/components/container.ts +140 -0
  17. package/lib/components/data.ts +135 -0
  18. package/lib/components/datepicker.ts +234 -0
  19. package/lib/components/dialog.ts +172 -0
  20. package/lib/components/divider.ts +100 -0
  21. package/lib/components/dropdown.ts +186 -0
  22. package/lib/components/element.ts +267 -0
  23. package/lib/components/fileupload.ts +309 -0
  24. package/lib/components/grid.ts +291 -0
  25. package/lib/components/guard.ts +92 -0
  26. package/lib/components/heading.ts +96 -0
  27. package/lib/components/helpers.ts +41 -0
  28. package/lib/components/hero.ts +224 -0
  29. package/lib/components/icon.ts +178 -0
  30. package/lib/components/icons.ts +464 -0
  31. package/lib/components/include.ts +410 -0
  32. package/lib/components/input.ts +457 -0
  33. package/lib/components/list.ts +419 -0
  34. package/lib/components/loading.ts +100 -0
  35. package/lib/components/menu.ts +275 -0
  36. package/lib/components/modal.ts +284 -0
  37. package/lib/components/nav.ts +257 -0
  38. package/lib/components/paragraph.ts +97 -0
  39. package/lib/components/progress.ts +159 -0
  40. package/lib/components/radio.ts +278 -0
  41. package/lib/components/req.ts +303 -0
  42. package/lib/components/script.ts +41 -0
  43. package/lib/components/select.ts +252 -0
  44. package/lib/components/sidebar.ts +275 -0
  45. package/lib/components/style.ts +41 -0
  46. package/lib/components/switch.ts +246 -0
  47. package/lib/components/table.ts +1249 -0
  48. package/lib/components/tabs.ts +250 -0
  49. package/lib/components/theme-toggle.ts +293 -0
  50. package/lib/components/tooltip.ts +144 -0
  51. package/lib/components/view.ts +190 -0
  52. package/lib/components/write.ts +272 -0
  53. package/lib/globals.d.ts +19 -5
  54. package/lib/layouts/default.css +260 -0
  55. package/lib/layouts/figma.css +334 -0
  56. package/lib/reactivity/state.ts +78 -0
  57. package/lib/utils/{fetch.js → fetch.ts} +206 -81
  58. package/package.json +9 -31
  59. package/create/index.jux +0 -77
  60. package/create/layout.jux +0 -18
  61. package/create/style.css +0 -57
  62. package/create/themes/assets/jux.svg +0 -34
  63. package/create/themes/base.css +0 -197
  64. package/create/themes/base2.css +0 -54
  65. package/create/themes/layouts/base.jux +0 -16
  66. package/create/themes/layouts/base_blog.jux +0 -0
  67. package/create/themes/layouts/base_docs.jux +0 -0
  68. package/create/themes/layouts/base_login.jux +0 -0
  69. package/create/themes/layouts/base_marketing.jux +0 -0
  70. package/create/themes/layouts/base_saas.jux +0 -0
  71. package/lib/componentsv2/base/BaseEngine.d.ts +0 -112
  72. package/lib/componentsv2/base/BaseEngine.js +0 -279
  73. package/lib/componentsv2/base/BaseSkin.d.ts +0 -74
  74. package/lib/componentsv2/base/BaseSkin.js +0 -130
  75. package/lib/componentsv2/base/Neighborhood.d.ts +0 -22
  76. package/lib/componentsv2/base/Neighborhood.js +0 -56
  77. package/lib/componentsv2/base/OptionsContract.d.ts +0 -20
  78. package/lib/componentsv2/base/OptionsContract.js +0 -107
  79. package/lib/componentsv2/base/State.d.ts +0 -18
  80. package/lib/componentsv2/base/State.js +0 -68
  81. package/lib/componentsv2/element/Element.d.ts +0 -29
  82. package/lib/componentsv2/element/Element.js +0 -49
  83. package/lib/componentsv2/element/ElementEngine.d.ts +0 -58
  84. package/lib/componentsv2/element/ElementEngine.js +0 -112
  85. package/lib/componentsv2/element/ElementSkin.d.ts +0 -10
  86. package/lib/componentsv2/element/ElementSkin.js +0 -56
  87. package/lib/componentsv2/element/structure.css +0 -261
  88. package/lib/componentsv2/grid/Grid.d.ts +0 -13
  89. package/lib/componentsv2/grid/Grid.js +0 -27
  90. package/lib/componentsv2/grid/GridEngine.d.ts +0 -77
  91. package/lib/componentsv2/grid/GridEngine.js +0 -153
  92. package/lib/componentsv2/grid/GridSkin.d.ts +0 -11
  93. package/lib/componentsv2/grid/GridSkin.js +0 -84
  94. package/lib/componentsv2/grid/structure.css +0 -27
  95. package/lib/componentsv2/input/Input.d.ts +0 -6
  96. package/lib/componentsv2/input/Input.js +0 -21
  97. package/lib/componentsv2/input/InputEngine.d.ts +0 -70
  98. package/lib/componentsv2/input/InputEngine.js +0 -143
  99. package/lib/componentsv2/input/InputSkin.d.ts +0 -11
  100. package/lib/componentsv2/input/InputSkin.js +0 -89
  101. package/lib/componentsv2/input/structure.css +0 -47
  102. package/lib/componentsv2/list/List.d.ts +0 -49
  103. package/lib/componentsv2/list/List.js +0 -105
  104. package/lib/componentsv2/list/ListEngine.d.ts +0 -121
  105. package/lib/componentsv2/list/ListEngine.js +0 -322
  106. package/lib/componentsv2/list/ListSkin.d.ts +0 -20
  107. package/lib/componentsv2/list/ListSkin.js +0 -345
  108. package/lib/componentsv2/list/structure.css +0 -359
  109. package/lib/componentsv2/plugins/ClientSQLitePlugin.d.ts +0 -21
  110. package/lib/componentsv2/plugins/ClientSQLitePlugin.js +0 -130
  111. package/lib/componentsv2/plugins/IndexedDBPlugin.d.ts +0 -18
  112. package/lib/componentsv2/plugins/IndexedDBPlugin.js +0 -75
  113. package/lib/componentsv2/plugins/LocalStoragePlugin.d.ts +0 -20
  114. package/lib/componentsv2/plugins/LocalStoragePlugin.js +0 -65
  115. package/lib/componentsv2/plugins/ServerSQLitePlugin.d.ts +0 -25
  116. package/lib/componentsv2/plugins/ServerSQLitePlugin.js +0 -70
  117. package/lib/componentsv2/stubs/ComponentComposition.ts.stub +0 -32
  118. package/lib/componentsv2/stubs/ComponentEngine.ts.stub +0 -36
  119. package/lib/componentsv2/stubs/ComponentSkin.ts.stub +0 -35
  120. package/lib/componentsv2/stubs/ComponentStructure.css.d.ts.stub +0 -2
  121. package/lib/componentsv2/stubs/ComponentStructure.css.stub +0 -13
  122. package/lib/utils/fetch.d.ts +0 -176
  123. package/machinery/build3.js +0 -159
  124. package/machinery/compiler3.js +0 -688
  125. package/machinery/config.js +0 -155
  126. package/machinery/serve.js +0 -255
  127. package/machinery/validators/file-validator.js +0 -123
  128. package/machinery/watcher.js +0 -59
  129. package/types/css.d.ts +0 -10
@@ -0,0 +1,410 @@
1
+
2
+ /**
3
+ * Include - Include external resources (CSS, JS, images, fonts, etc.)
4
+ * Auto-detects resource type from URL and provides simple, fluent API
5
+ */
6
+
7
+ type IncludeType = 'stylesheet' | 'script' | 'image' | 'font' | 'preload' | 'prefetch' | 'module' | 'json';
8
+ type IncludeLocation = 'head' | 'body-start' | 'body-end';
9
+
10
+ interface IncludeOptions {
11
+ as?: string;
12
+ crossOrigin?: 'anonymous' | 'use-credentials';
13
+ integrity?: string;
14
+ async?: boolean;
15
+ defer?: boolean;
16
+ location?: IncludeLocation;
17
+ }
18
+
19
+ export class Include {
20
+ private url: string;
21
+ private type: IncludeType;
22
+ private options: IncludeOptions = {};
23
+ private element: HTMLElement | null = null;
24
+ private explicitType: boolean = false; // NEW: Track if type was explicitly set
25
+
26
+ constructor(urlOrFile: string) {
27
+ this.url = urlOrFile;
28
+ this.type = this.detectType(urlOrFile);
29
+ }
30
+
31
+ /* -------------------------
32
+ * Type Detection
33
+ * ------------------------- */
34
+
35
+ private detectType(url: string): IncludeType {
36
+ // Check for common script patterns in URLs (CDN, etc.)
37
+ if (url.includes('tailwindcss') ||
38
+ url.includes('jsdelivr.net/npm') ||
39
+ url.includes('unpkg.com') ||
40
+ url.includes('cdn.') ||
41
+ url.match(/\.(js|mjs)($|\?)/)) {
42
+ return 'script';
43
+ }
44
+
45
+ if (url.endsWith('.css')) return 'stylesheet';
46
+ if (url.endsWith('.json')) return 'json';
47
+ if (url.match(/\.(png|jpg|jpeg|gif|svg|webp)$/i)) return 'image';
48
+ if (url.match(/\.(woff|woff2|ttf|otf|eot)$/i)) return 'font';
49
+
50
+ // Default to script for extensionless URLs from CDN domains
51
+ if (!url.includes('.') || url.match(/^https?:\/\/cdn/)) {
52
+ return 'script';
53
+ }
54
+
55
+ return 'preload';
56
+ }
57
+
58
+ /* -------------------------
59
+ * Fluent Type Setters
60
+ * ------------------------- */
61
+
62
+ /**
63
+ * Force treat as CSS stylesheet
64
+ * Use when URL doesn't have .css extension
65
+ */
66
+ withCss(): this {
67
+ this.type = 'stylesheet';
68
+ this.explicitType = true; // Mark as explicit
69
+ return this;
70
+ }
71
+
72
+ /**
73
+ * Force treat as JavaScript
74
+ * Use when URL doesn't have .js extension (CDN scripts, etc.)
75
+ *
76
+ * @example
77
+ * jux.include('https://cdn.tailwindcss.com').withJs().render();
78
+ * jux.include('https://unpkg.com/alpine').withJs({ defer: true }).render();
79
+ */
80
+ withJs(options?: { async?: boolean; defer?: boolean }): this {
81
+ this.type = 'script';
82
+ this.explicitType = true; // Mark as explicit
83
+ if (options?.async) this.options.async = true;
84
+ if (options?.defer) this.options.defer = true;
85
+ return this;
86
+ }
87
+
88
+ /**
89
+ * Force treat as ES module
90
+ * Use for module scripts
91
+ */
92
+ withModule(): this {
93
+ this.type = 'module';
94
+ this.explicitType = true; // Mark as explicit
95
+ return this;
96
+ }
97
+
98
+ withImage(): this {
99
+ this.type = 'image';
100
+ this.explicitType = true;
101
+ return this;
102
+ }
103
+
104
+ withFont(): this {
105
+ this.type = 'font';
106
+ this.explicitType = true;
107
+ return this;
108
+ }
109
+
110
+ withPreload(as?: string): this {
111
+ this.type = 'preload';
112
+ this.explicitType = true;
113
+ if (as) this.options.as = as;
114
+ return this;
115
+ }
116
+
117
+ withPrefetch(): this {
118
+ this.type = 'prefetch';
119
+ this.explicitType = true;
120
+ return this;
121
+ }
122
+
123
+ withJson(): this {
124
+ this.type = 'json';
125
+ this.explicitType = true;
126
+ return this;
127
+ }
128
+
129
+ /* -------------------------
130
+ * Convenience aliases for common patterns
131
+ * ------------------------- */
132
+
133
+ /**
134
+ * Shorthand for .withJs()
135
+ * @example jux.include(url).asScript()
136
+ */
137
+ asScript(options?: { async?: boolean; defer?: boolean }): this {
138
+ return this.withJs(options);
139
+ }
140
+
141
+ /**
142
+ * Shorthand for .withCss()
143
+ * @example jux.include(url).asStylesheet()
144
+ */
145
+ asStylesheet(): this {
146
+ return this.withCss();
147
+ }
148
+
149
+ /* -------------------------
150
+ * JSON Fetching
151
+ * ------------------------- */
152
+
153
+ /**
154
+ * Fetch and parse JSON file
155
+ * Returns a Promise that resolves to the parsed JSON data
156
+ *
157
+ * Usage:
158
+ * const config = await jux.include('config.json').asJson();
159
+ * const data = await jux.include('/api/data').asJson();
160
+ */
161
+ async asJson<T = any>(): Promise<T> {
162
+ try {
163
+ const response = await fetch(this.url);
164
+
165
+ if (!response.ok) {
166
+ throw new Error(`HTTP error! status: ${response.status}`);
167
+ }
168
+
169
+ const data = await response.json();
170
+ console.log(`✓ JSON loaded: ${this.url}`);
171
+ return data;
172
+ } catch (error: any) {
173
+ throw error;
174
+ }
175
+ }
176
+
177
+ /**
178
+ * Fetch JSON and execute callback with data
179
+ *
180
+ * Usage:
181
+ * jux.include('config.json').onJson(data => {
182
+ * console.log('Config:', data);
183
+ * });
184
+ */
185
+ onJson<T = any>(callback: (data: T) => void): this {
186
+ this.asJson<T>().then(callback).catch(error => {
187
+ console.error('Failed to load JSON:', error);
188
+ });
189
+ return this;
190
+ }
191
+
192
+ /* -------------------------
193
+ * Options
194
+ * ------------------------- */
195
+
196
+ with(options: IncludeOptions): this {
197
+ this.options = { ...this.options, ...options };
198
+ return this;
199
+ }
200
+
201
+ inHead(): this {
202
+ this.options.location = 'head';
203
+ return this;
204
+ }
205
+
206
+ inBody(): this {
207
+ this.options.location = 'body-end';
208
+ return this;
209
+ }
210
+
211
+ async(): this {
212
+ this.options.async = true;
213
+ return this;
214
+ }
215
+
216
+ defer(): this {
217
+ this.options.defer = true;
218
+ return this;
219
+ }
220
+
221
+ crossOrigin(value: 'anonymous' | 'use-credentials' = 'anonymous'): this {
222
+ this.options.crossOrigin = value;
223
+ return this;
224
+ }
225
+
226
+ integrity(hash: string): this {
227
+ this.options.integrity = hash;
228
+ return this;
229
+ }
230
+
231
+ /* -------------------------
232
+ * Render
233
+ * ------------------------- */
234
+
235
+ render(): this {
236
+ if (typeof document === 'undefined') return this;
237
+
238
+ // Don't render JSON type (it's fetched via asJson() instead)
239
+ if (this.type === 'json') {
240
+ console.warn('Include: JSON files should be loaded with .asJson() instead of .render()');
241
+ return this;
242
+ }
243
+
244
+ try {
245
+ this.remove();
246
+
247
+ let element: HTMLElement;
248
+
249
+ switch (this.type) {
250
+ case 'stylesheet':
251
+ element = this.createStylesheet();
252
+ break;
253
+ case 'script':
254
+ case 'module':
255
+ element = this.createScript();
256
+ break;
257
+ case 'image':
258
+ case 'font':
259
+ case 'preload':
260
+ case 'prefetch':
261
+ element = this.createLink();
262
+ break;
263
+ default:
264
+ throw new Error(`Unknown include type: ${this.type}`);
265
+ }
266
+
267
+ const container = this.getContainer();
268
+ const location = this.options.location || 'head';
269
+
270
+ if (location === 'body-end') {
271
+ container.appendChild(element);
272
+ } else {
273
+ container.insertBefore(element, container.firstChild);
274
+ }
275
+
276
+ this.element = element;
277
+
278
+ // Log with type indicator
279
+ const typeIndicator = this.explicitType ? '(explicit)' : '(auto-detected)';
280
+ console.log(`✓ Include loaded as ${this.type} ${typeIndicator}: ${this.url}`);
281
+ } catch (error: any) {
282
+ throw error;
283
+ }
284
+
285
+ return this;
286
+ }
287
+
288
+ /* -------------------------
289
+ * Element Creation
290
+ * ------------------------- */
291
+
292
+ private createStylesheet(): HTMLLinkElement {
293
+ const link = document.createElement('link');
294
+ link.rel = 'stylesheet';
295
+ link.href = this.url;
296
+
297
+ if (this.options.crossOrigin) link.crossOrigin = this.options.crossOrigin;
298
+ if (this.options.integrity) link.integrity = this.options.integrity;
299
+
300
+ link.onload = () => console.log(`✓ Stylesheet loaded: ${this.url}`);
301
+ link.onerror = () => this.handleError('stylesheet');
302
+
303
+ return link;
304
+ }
305
+
306
+ private createScript(): HTMLScriptElement {
307
+ const script = document.createElement('script');
308
+ script.src = this.url;
309
+
310
+ if (this.type === 'module') script.type = 'module';
311
+ if (this.options.async) script.async = true;
312
+ if (this.options.defer) script.defer = true;
313
+ if (this.options.crossOrigin) script.crossOrigin = this.options.crossOrigin;
314
+ if (this.options.integrity) script.integrity = this.options.integrity;
315
+
316
+ script.onload = () => console.log(`✓ Script loaded: ${this.url}`);
317
+ script.onerror = () => this.handleError('script');
318
+
319
+ return script;
320
+ }
321
+
322
+ private createLink(): HTMLLinkElement {
323
+ const link = document.createElement('link');
324
+
325
+ // Set rel based on type
326
+ if (this.type === 'prefetch') {
327
+ link.rel = 'prefetch';
328
+ } else {
329
+ link.rel = 'preload';
330
+ }
331
+
332
+ link.href = this.url;
333
+
334
+ // Set 'as' attribute
335
+ if (this.type === 'image') {
336
+ link.as = 'image';
337
+ } else if (this.type === 'font') {
338
+ link.as = 'font';
339
+ link.crossOrigin = this.options.crossOrigin || 'anonymous';
340
+ } else if (this.options.as) {
341
+ link.as = this.options.as;
342
+ }
343
+
344
+ if (this.options.crossOrigin && this.type !== 'font') {
345
+ link.crossOrigin = this.options.crossOrigin;
346
+ }
347
+ if (this.options.integrity) {
348
+ link.integrity = this.options.integrity;
349
+ }
350
+
351
+ return link;
352
+ }
353
+
354
+ /* -------------------------
355
+ * Helpers
356
+ * ------------------------- */
357
+
358
+ private getContainer(): HTMLElement {
359
+ const location = this.options.location || 'head';
360
+ return location === 'head' ? document.head : document.body;
361
+ }
362
+
363
+ private handleError(type: string): void {
364
+ const error = new Error(`Failed to load ${type}: ${this.url}`);
365
+ throw error;
366
+ }
367
+
368
+
369
+ remove(): this {
370
+ if (this.element?.parentNode) {
371
+ this.element.parentNode.removeChild(this.element);
372
+ this.element = null;
373
+ }
374
+ return this;
375
+ }
376
+ }
377
+
378
+ /**
379
+ * Factory function - auto-detects type and renders immediately
380
+ *
381
+ * Usage:
382
+ * // Auto-detect (works for most cases)
383
+ * jux.include('styles.css');
384
+ * jux.include('script.js').async();
385
+ *
386
+ * // Explicit type (for extensionless URLs)
387
+ * jux.include('https://cdn.tailwindcss.com').withJs();
388
+ * jux.include('https://cdn.tailwindcss.com').asScript();
389
+ * jux.include('https://unpkg.com/htmx.org').withJs({ defer: true });
390
+ *
391
+ * // CDN with parameters
392
+ * jux.include('https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4').withJs();
393
+ *
394
+ * // Module
395
+ * jux.include('app.mjs').withModule();
396
+ *
397
+ * // For JSON:
398
+ * const data = await jux.include('config.json').asJson();
399
+ * jux.include('data.json').onJson(data => console.log(data));
400
+ */
401
+ export function include(urlOrFile: string): Include {
402
+ const imp = new Include(urlOrFile);
403
+
404
+ // Don't auto-render JSON files
405
+ if (imp['type'] !== 'json') {
406
+ imp.render();
407
+ }
408
+
409
+ return imp;
410
+ }