juxscript 1.1.4 → 1.1.6

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