lego-dom 1.3.4 → 1.4.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 (91) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/main.js +24 -3
  3. package/package.json +1 -1
  4. package/vite-plugin.js +0 -14
  5. package/.github/workflows/deploy-docs.yml +0 -56
  6. package/.legodom +0 -87
  7. package/docs/.vitepress/config.js +0 -161
  8. package/docs/api/config.md +0 -95
  9. package/docs/api/define.md +0 -58
  10. package/docs/api/directives.md +0 -50
  11. package/docs/api/globals.md +0 -29
  12. package/docs/api/index.md +0 -30
  13. package/docs/api/lifecycle.md +0 -40
  14. package/docs/api/route.md +0 -37
  15. package/docs/api/vite-plugin.md +0 -58
  16. package/docs/contributing/01-welcome.md +0 -38
  17. package/docs/contributing/02-registry.md +0 -133
  18. package/docs/contributing/03-batcher.md +0 -110
  19. package/docs/contributing/04-reactivity.md +0 -87
  20. package/docs/contributing/05-caching.md +0 -59
  21. package/docs/contributing/06-init.md +0 -136
  22. package/docs/contributing/07-observer.md +0 -72
  23. package/docs/contributing/08-snap.md +0 -140
  24. package/docs/contributing/09-diffing.md +0 -69
  25. package/docs/contributing/10-studs.md +0 -78
  26. package/docs/contributing/11-scanner.md +0 -117
  27. package/docs/contributing/12-render.md +0 -138
  28. package/docs/contributing/13-directives.md +0 -243
  29. package/docs/contributing/14-events.md +0 -57
  30. package/docs/contributing/15-router.md +0 -57
  31. package/docs/contributing/16-state.md +0 -47
  32. package/docs/contributing/17-legodom.md +0 -48
  33. package/docs/contributing/index.md +0 -24
  34. package/docs/examples/form.md +0 -42
  35. package/docs/examples/index.md +0 -104
  36. package/docs/examples/routing.md +0 -409
  37. package/docs/examples/sfc-showcase.md +0 -34
  38. package/docs/examples/todo-app.md +0 -383
  39. package/docs/guide/cdn-usage.md +0 -354
  40. package/docs/guide/components.md +0 -418
  41. package/docs/guide/directives.md +0 -539
  42. package/docs/guide/directory-structure.md +0 -248
  43. package/docs/guide/faq.md +0 -210
  44. package/docs/guide/getting-started.md +0 -262
  45. package/docs/guide/index.md +0 -88
  46. package/docs/guide/lifecycle.md +0 -525
  47. package/docs/guide/quick-start.md +0 -49
  48. package/docs/guide/reactivity.md +0 -415
  49. package/docs/guide/routing.md +0 -334
  50. package/docs/guide/server-side.md +0 -134
  51. package/docs/guide/sfc.md +0 -464
  52. package/docs/guide/templating.md +0 -388
  53. package/docs/index.md +0 -160
  54. package/docs/public/logo.svg +0 -17
  55. package/docs/router/basic-routing.md +0 -103
  56. package/docs/router/cold-entry.md +0 -91
  57. package/docs/router/history.md +0 -69
  58. package/docs/router/index.md +0 -73
  59. package/docs/router/resolver.md +0 -74
  60. package/docs/router/surgical-swaps.md +0 -134
  61. package/docs/tutorial/01-project-setup.md +0 -152
  62. package/docs/tutorial/02-your-first-component.md +0 -226
  63. package/docs/tutorial/03-adding-routes.md +0 -279
  64. package/docs/tutorial/04-multi-page-app.md +0 -329
  65. package/docs/tutorial/05-state-and-globals.md +0 -285
  66. package/docs/tutorial/index.md +0 -40
  67. package/examples/vite-app/README.md +0 -71
  68. package/examples/vite-app/index.html +0 -42
  69. package/examples/vite-app/package.json +0 -18
  70. package/examples/vite-app/src/app.css +0 -3
  71. package/examples/vite-app/src/app.js +0 -29
  72. package/examples/vite-app/src/components/app-navbar.lego +0 -34
  73. package/examples/vite-app/src/components/customers/customer-details.lego +0 -24
  74. package/examples/vite-app/src/components/customers/customer-orders.lego +0 -21
  75. package/examples/vite-app/src/components/customers/order-list.lego +0 -55
  76. package/examples/vite-app/src/components/greeting-card.lego +0 -41
  77. package/examples/vite-app/src/components/sample-component.lego +0 -75
  78. package/examples/vite-app/src/components/shells/customers-shell.lego +0 -21
  79. package/examples/vite-app/src/components/side-menu.lego +0 -46
  80. package/examples/vite-app/src/components/todo-list.lego +0 -239
  81. package/examples/vite-app/src/components/widgets/user-card.lego +0 -27
  82. package/examples/vite-app/vite.config.js +0 -22
  83. package/tests/error.test.js +0 -74
  84. package/tests/main.test.js +0 -103
  85. package/tests/memory.test.js +0 -68
  86. package/tests/monitoring.test.js +0 -74
  87. package/tests/naming.test.js +0 -74
  88. package/tests/parse-lego.test.js +0 -65
  89. package/tests/security.test.js +0 -67
  90. package/tests/server.test.js +0 -114
  91. package/tests/syntax.test.js +0 -67
@@ -1,354 +0,0 @@
1
- # CDN Usage
2
-
3
- Lego works perfectly without any build tools. Just include it via CDN and start building!
4
-
5
- ## Quick Start
6
-
7
- ```html
8
- <!DOCTYPE html>
9
- <html>
10
- <head>
11
- <title>My App</title>
12
- </head>
13
- <body>
14
- <!-- Define your component -->
15
- <template b-id="hello-world">
16
- <h1>[[ message ]]</h1>
17
- </template>
18
-
19
- <!-- Use it -->
20
- <hello-world b-data="{ message: 'Hello from CDN!' }"></hello-world>
21
-
22
- <!-- Include Lego -->
23
- <script src="https://unpkg.com/lego-dom/main.js"></script>
24
- <script>
25
- Lego.init();
26
- </script>
27
- </body>
28
- </html>
29
- ```
30
-
31
- That's it! Open this file in any browser and it works.
32
-
33
- ## CDN Providers
34
-
35
- ### unpkg (Recommended)
36
-
37
- ```html
38
- <!-- Latest version -->
39
- <script src="https://unpkg.com/lego-dom/main.js"></script>
40
-
41
- <!-- Specific version -->
42
- <script src="https://unpkg.com/lego-dom@1.3.4/main.js"></script>
43
- ```
44
-
45
- ### jsdelivr
46
-
47
- ```html
48
- <!-- Latest version -->
49
- <script src="https://cdn.jsdelivr.net/npm/lego-dom/main.js"></script>
50
-
51
- <!-- Specific version -->
52
- <script src="https://cdn.jsdelivr.net/npm/lego-dom@1.3.4/main.js"></script>
53
- ```
54
-
55
-
56
-
57
- ## Complete Example
58
-
59
- Here's a full working application using only CDN:
60
-
61
- ```html
62
- <!DOCTYPE html>
63
- <html lang="en">
64
- <head>
65
- <meta charset="UTF-8">
66
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
67
- <title>Todo App - Lego</title>
68
- <style>
69
- body {
70
- font-family: system-ui, sans-serif;
71
- max-width: 600px;
72
- margin: 2rem auto;
73
- padding: 0 1rem;
74
- }
75
- </style>
76
- </head>
77
- <body>
78
- <h1>My Todo App</h1>
79
- <todo-app></todo-app>
80
-
81
- <template b-id="todo-app">
82
- <style>
83
- self {
84
- display: block;
85
- }
86
- .input-group {
87
- display: flex;
88
- gap: 0.5rem;
89
- margin-bottom: 1rem;
90
- }
91
- input {
92
- flex: 1;
93
- padding: 0.5rem;
94
- font-size: 1rem;
95
- }
96
- button {
97
- padding: 0.5rem 1rem;
98
- font-size: 1rem;
99
- background: #4CAF50;
100
- color: white;
101
- border: none;
102
- cursor: pointer;
103
- }
104
- ul {
105
- list-style: none;
106
- padding: 0;
107
- }
108
- li {
109
- padding: 0.75rem;
110
- border-bottom: 1px solid #eee;
111
- display: flex;
112
- align-items: center;
113
- gap: 0.5rem;
114
- }
115
- .done {
116
- text-decoration: line-through;
117
- opacity: 0.6;
118
- }
119
- </style>
120
-
121
- <div class="input-group">
122
- <input
123
- b-sync="newTodo"
124
- placeholder="What needs to be done?"
125
- @keyup="event.key === 'Enter' && addTodo()">
126
- <button @click="addTodo()">Add</button>
127
- </div>
128
-
129
- <ul>
130
- <li b-for="todo in todos">
131
- <input type="checkbox" b-sync="todo.done">
132
- <span class="[[ todo.done ? 'done' : '' ]]">
133
- [[ todo.text ]]
134
- </span>
135
- </li>
136
- </ul>
137
-
138
- <p>[[ remaining() ]] remaining</p>
139
- </template>
140
-
141
- <script src="https://unpkg.com/lego-dom/main.js"></script>
142
-
143
- <script>
144
- // Initialize with data
145
- Lego.define('todo-app', Lego.registry['todo-app'].innerHTML, {
146
- newTodo: '',
147
- todos: [
148
- { text: 'Learn Lego', done: true },
149
- { text: 'Build something awesome', done: false }
150
- ],
151
- addTodo() {
152
- if (this.newTodo.trim()) {
153
- this.todos.push({
154
- text: this.newTodo,
155
- done: false
156
- });
157
- this.newTodo = '';
158
- }
159
- },
160
- remaining() {
161
- return this.todos.filter(t => !t.done).length;
162
- }
163
- });
164
-
165
- // Don't forget to init!
166
- Lego.init();
167
- </script>
168
- </body>
169
- </html>
170
- ```
171
-
172
- ## Progressive Enhancement
173
-
174
- Lego is perfect for progressively enhancing existing sites:
175
-
176
- ```html
177
- <!-- Your existing page -->
178
- <div id="legacy-content">
179
- <h1>My Existing Site</h1>
180
- <p>This works without JavaScript</p>
181
- </div>
182
-
183
- <!-- Add interactive components -->
184
- <user-widget></user-widget>
185
-
186
- <template b-id="user-widget">
187
- <style>
188
- self {
189
- position: fixed;
190
- bottom: 1rem;
191
- right: 1rem;
192
- background: white;
193
- padding: 1rem;
194
- box-shadow: 0 2px 10px rgba(0,0,0,0.1);
195
- }
196
- </style>
197
- <p>Welcome, [[ username ]]!</p>
198
- <button @click="logout()">Logout</button>
199
- </template>
200
-
201
- <script src="https://unpkg.com/lego-dom/main.js"></script>
202
- <script>
203
- Lego.define('user-widget', Lego.registry['user-widget'].innerHTML, {
204
- username: 'Guest',
205
- async mounted() {
206
- const user = await fetch('/api/user').then(r => r.json());
207
- this.username = user.name;
208
- },
209
- logout() {
210
- window.location.href = '/logout';
211
- }
212
- });
213
-
214
- Lego.init();
215
- </script>
216
- ```
217
-
218
- ## Embedding in Existing Apps
219
-
220
- Lego components work alongside other frameworks:
221
-
222
- ```html
223
- <!-- Works fine with jQuery, Bootstrap, etc. -->
224
- <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
225
- <script src="https://unpkg.com/lego-dom/main.js"></script>
226
-
227
- <!-- Your Lego component -->
228
- <my-component></my-component>
229
-
230
- <!-- Your jQuery code -->
231
- <script>
232
- $(document).ready(function() {
233
- // jQuery code here
234
- });
235
- </script>
236
- ```
237
-
238
- ## Loading Strategy
239
-
240
- ### For Production
241
-
242
- Always pin to a specific version:
243
-
244
- ```html
245
- <script src="https://unpkg.com/lego-dom@1.3.4/main.js"></script>
246
- ```
247
-
248
- ### For Development/Prototyping
249
-
250
- Use latest:
251
-
252
- ```html
253
- <script src="https://unpkg.com/lego-dom/main.js"></script>
254
- ```
255
-
256
- ### With defer
257
-
258
- Load asynchronously without blocking page render:
259
-
260
- ```html
261
- <script defer src="https://unpkg.com/lego-dom/main.js"></script>
262
- ```
263
-
264
- ### With integrity (SRI)
265
-
266
- For maximum security:
267
-
268
- ```html
269
- <script
270
- src="https://unpkg.com/lego-dom@1.3.4/main.js"
271
- integrity="sha384-..."
272
- crossorigin="anonymous">
273
- </script>
274
- ```
275
-
276
- ## Browser Compatibility
277
-
278
- Lego works in all modern browsers:
279
-
280
- - ✅ Chrome 63+
281
- - ✅ Firefox 63+
282
- - ✅ Safari 11.1+
283
- - ✅ Edge 79+
284
-
285
- No polyfills needed for these browsers!
286
-
287
- ## Using .lego Files without Build Tools
288
-
289
- You can use full Single File Components (`.lego` files) directly in the browser without any build step!
290
- Lego provides a `loader` configuration that lets you fetch component files on demand.
291
-
292
- ### How it Works
293
-
294
- 1. **Serve your files**: Make sure your `.lego` files are accessible via HTTP (e.g., in a `/components` folder).
295
- 2. **Configure the loader**: Tell Lego how to fetch a component when it encounters an unknown tag.
296
-
297
- ### Example
298
-
299
- ```html
300
- <script>
301
- Lego.init(document.body, {
302
- // The loader function receives the tag name (e.g., 'user-card')
303
- // and must return a Promise that resolves to the component's source code.
304
- loader: (tagName) => {
305
- // Fetch the raw text content of the .lego file
306
- return fetch(`/components/${tagName}.lego`).then(res => res.text());
307
- }
308
- });
309
- </script>
310
-
311
- <!-- Now just use the tag! Lego will fetch, compile, and render it automatically. -->
312
- <user-card></user-card>
313
- ```
314
-
315
- This is perfect for:
316
- - **Micro-frontends**: Load components from different services.
317
- - **CMS Integration**: Store component code in a database.
318
- - **Dynamic Apps**: Load features only when they are needed.
319
-
320
- ## Pros and Cons
321
-
322
- ### Advantages
323
-
324
- - **No build step** - Instant development
325
- - **No npm** - No dependency management
326
- - **Fast prototyping** - Perfect for demos and learning
327
- - **Progressive enhancement** - Add to existing sites easily
328
- - **Low barrier** - Great for beginners
329
-
330
- ### Limitations
331
-
332
- - No hot module replacement
333
- - Slower for large apps compared to bundled versions
334
-
335
- ## When to Use CDN
336
-
337
- **Perfect for:**
338
- - Prototypes and demos
339
- - Small websites (1-5 components)
340
- - Progressive enhancement
341
- - Learning and experimentation
342
- - CodePen/JSFiddle examples
343
-
344
- **Consider bundling for:**
345
- - Large applications (10+ components)
346
- - Production apps requiring optimization
347
- - Projects needing TypeScript
348
- - Teams wanting SFC workflow
349
-
350
- ## Next Steps
351
-
352
- - See [complete CDN examples](/examples/)
353
- - Learn about [routing](/guide/routing) for multi-page apps
354
- - Explore [directives](/guide/directives) for common patterns