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,388 +0,0 @@
1
- # Templating
2
-
3
- Learn about Lego templating features and syntax.
4
-
5
- ## Interpolation
6
-
7
- Use `[[ ]]` to insert dynamic content:
8
-
9
- ### Simple Values
10
-
11
- ```html
12
- <p>[[ message ]]</p>
13
- <h1>[[ title ]]</h1>
14
- <span>[[ count ]]</span>
15
- ```
16
-
17
- ### Expressions
18
-
19
- ```html
20
- <p>[[ count * 2 ]]</p>
21
- <span>[[ price.toFixed(2) ]]</span>
22
- <div>[[ firstName + ' ' + lastName ]]</div>
23
- ```
24
-
25
- ### Method Calls
26
-
27
- ```html
28
- <p>[[ formatDate(timestamp) ]]</p>
29
- <span>[[ calculateTotal() ]]</span>
30
- <div>[[ getUsername() ]]</div>
31
- ```
32
-
33
- ### Conditional (Ternary)
34
-
35
- ```html
36
- <p>[[ age >= 18 ? 'Adult' : 'Minor' ]]</p>
37
- <span>[[ isOnline ? '🟢 Online' : '🔴 Offline' ]]</span>
38
- <div>[[ items.length > 0 ? items.length + ' items' : 'Empty' ]]</div>
39
- ```
40
-
41
- ## Attribute Binding
42
-
43
- Interpolate in any attribute:
44
-
45
- ### Simple Attributes
46
-
47
- ```html
48
- <img src="/avatars/[[ userId ]].png" alt="[[ username ]]">
49
- <a href="/user/[[ userId ]]">[[ username ]]</a>
50
- <input placeholder="[[ defaultText ]]">
51
- ```
52
-
53
- ### Class Names
54
-
55
- ```html
56
- <div class="card [[ isActive ? 'active' : '' ]]">...</div>
57
- <button class="[[ isDisabled ? 'disabled' : 'enabled' ]]">...</button>
58
- <li class="item status-[[ status ]]">...</li>
59
- ```
60
-
61
- ### Data Attributes
62
-
63
- ```html
64
- <div data-id="[[ itemId ]]" data-type="[[ itemType ]]">...</div>
65
- ```
66
-
67
- ### Style (Inline)
68
-
69
- ```html
70
- <div style="color: [[ textColor ]]; background: [[ bgColor ]]">...</div>
71
- ```
72
-
73
- ## Escaping
74
-
75
- Lego automatically escapes HTML to prevent XSS:
76
-
77
- ```js
78
- {
79
- userInput: '<script>alert("XSS")</script>'
80
- }
81
- ```
82
-
83
- ```html
84
- <p>[[ userInput ]]</p>
85
- <!-- Renders as: &lt;script&gt;alert("XSS")&lt;/script&gt; -->
86
- ```
87
-
88
- **By default,## Raw HTML
89
-
90
- To render raw HTML content, use the `b-html` directive.
91
-
92
- > [!WARNING]
93
- > Never use `b-html` on untrusted user input (e.g., comments, messages). It can lead to XSS attacks.
94
-
95
- ## Whitespace
96
-
97
- Templates preserve whitespace:
98
-
99
- ```html
100
- <p>
101
- [[ message ]]
102
- </p>
103
- <!-- Renders with newlines and indentation -->
104
- ```
105
-
106
- Trim manually if needed:
107
-
108
- ```html
109
- <p>[[ message.trim() ]]</p>
110
- ```
111
-
112
- ## Context
113
-
114
- Inside `[[ ]]`, you have access to:
115
-
116
- ### Component State (`this`)
117
-
118
- ```html
119
- <p>[[ count ]]</p> <!-- this.count -->
120
- <span>[[ user.name ]]</span> <!-- this.user.name -->
121
- ```
122
-
123
- ### Methods
124
-
125
- ```html
126
- <p>[[ formatDate(timestamp) ]]</p>
127
- <div>[[ calculateTotal() ]]</div>
128
- ```
129
-
130
- ### Special Keywords
131
-
132
- - `global` - Access `Lego.globals`
133
- - `event` - In event handlers
134
- - `self` - Reference to component element (rare)
135
-
136
- ```html
137
- <p>[[ global.user.name ]]</p>
138
- <button @click="console.log(event)">Click</button>
139
- ```
140
-
141
- ## Complex Examples
142
-
143
- ### Formatting Currency
144
-
145
- ```js
146
- {
147
- price: 29.99,
148
- formatCurrency(value) {
149
- return '$' + value.toFixed(2);
150
- }
151
- }
152
- ```
153
-
154
- ```html
155
- <p>Price: [[ formatCurrency(price) ]]</p>
156
- ```
157
-
158
- ### Date Formatting
159
-
160
- ```js
161
- {
162
- timestamp: Date.now(),
163
- formatDate(ts) {
164
- return new Date(ts).toLocaleDateString();
165
- }
166
- }
167
- ```
168
-
169
- ```html
170
- <time>[[ formatDate(timestamp) ]]</time>
171
- ```
172
-
173
- ### Pluralization
174
-
175
- ```js
176
- {
177
- items: ['apple', 'banana'],
178
- plural(count, singular, plural) {
179
- return count === 1 ? singular : plural;
180
- }
181
- }
182
- ```
183
-
184
- ```html
185
- <p>[[ items.length ]] [[ plural(items.length, 'item', 'items') ]]</p>
186
- ```
187
-
188
- ### Truncation
189
-
190
- ```js
191
- {
192
- description: 'Very long text...',
193
- truncate(text, length) {
194
- return text.length > length
195
- ? text.slice(0, length) + '...'
196
- : text;
197
- }
198
- }
199
- ```
200
-
201
- ```html
202
- <p>[[ truncate(description, 100) ]]</p>
203
- ```
204
-
205
- ## Limitations
206
-
207
- ### No Statements
208
-
209
- Can't use statements—only expressions:
210
-
211
- ```html
212
- <!-- ❌ Doesn't work -->
213
- <p>[[ if (condition) { return 'yes'; } ]]</p>
214
- <p>[[ for (let i = 0; i < 10; i++) { } ]]</p>
215
-
216
- <!-- ✅ Use ternary or methods -->
217
- <p>[[ condition ? 'yes' : 'no' ]]</p>
218
- <p>[[ renderList() ]]</p>
219
- ```
220
-
221
- ### No Declarations
222
-
223
- Can't declare variables:
224
-
225
- ```html
226
- <!-- ❌ Doesn't work -->
227
- <p>[[ const total = price * qty; total ]]</p>
228
-
229
- <!-- ✅ Use methods -->
230
- <p>[[ getTotal() ]]</p>
231
- ```
232
-
233
- ```js
234
- {
235
- getTotal() {
236
- const total = this.price * this.qty;
237
- return total;
238
- }
239
- }
240
- ```
241
-
242
- ## Best Practices
243
-
244
- ### 1. Keep Templates Simple
245
-
246
- If logic is complex, use methods:
247
-
248
- ```html
249
- <!-- ❌ Too complex -->
250
- <p>[[ items.filter(x => x.active).map(x => x.name).join(', ') ]]</p>
251
-
252
- <!-- ✅ Better -->
253
- <p>[[ getActiveNames() ]]</p>
254
- ```
255
-
256
- ```js
257
- {
258
- getActiveNames() {
259
- return this.items
260
- .filter(x => x.active)
261
- .map(x => x.name)
262
- .join(', ');
263
- }
264
- }
265
- ```
266
-
267
- ### 2. Format in Methods
268
-
269
- Don't put formatting logic in templates:
270
-
271
- ```html
272
- <!-- ❌ Messy -->
273
- <p>$[[ (price * 1.2).toFixed(2) ]]</p>
274
-
275
- <!-- ✅ Clean -->
276
- <p>[[ formatPrice(price) ]]</p>
277
- ```
278
-
279
- ### 3. Avoid Side Effects
280
-
281
- Don't mutate state in templates:
282
-
283
- ```html
284
- <!-- ❌ Bad -->
285
- <p>[[ count++ ]]</p>
286
-
287
- <!-- ✅ Good -->
288
- <p>[[ count ]]</p>
289
- <button @click="count++">Increment</button>
290
- ```
291
-
292
- ### 4. Use Descriptive Method Names
293
-
294
- ```js
295
- {
296
- // ✅ Clear purpose
297
- formatCurrency(value) { ... },
298
- calculateTax(amount) { ... },
299
- isValidEmail(email) { ... }
300
- }
301
- ```
302
-
303
- ## Performance Tips
304
-
305
- ### Cache Computed Values
306
-
307
- If a calculation is expensive, cache it:
308
-
309
- ```js
310
- {
311
- items: [],
312
- _cachedTotal: null,
313
-
314
- total() {
315
- if (this._cachedTotal === null) {
316
- this._cachedTotal = this.items.reduce((sum, x) => sum + x.price, 0);
317
- }
318
- return this._cachedTotal;
319
- },
320
-
321
- updated() {
322
- this._cachedTotal = null; // Invalidate cache
323
- }
324
- }
325
- ```
326
-
327
- ### Avoid Heavy Calculations
328
-
329
- ```html
330
- <!-- ❌ Runs on every render -->
331
- <p>[[ expensiveCalculation() ]]</p>
332
-
333
- <!-- ✅ Calculate once, store result -->
334
- <p>[[ cachedResult ]]</p>
335
- ```
336
-
337
- ```js
338
- {
339
- cachedResult: null,
340
- mounted() {
341
- this.cachedResult = this.expensiveCalculation();
342
- }
343
- }
344
- ```
345
-
346
- ## Common Patterns
347
-
348
- ### Show/Hide Based on Condition
349
-
350
- ```html
351
- <p b-show="user">Welcome, [[ user.name ]]!</p>
352
- <p b-show="!user">Please log in</p>
353
- ```
354
-
355
- ### List with Index
356
-
357
- ```html
358
- <ul>
359
- <li b-for="item in items">
360
- #[[ $index + 1 ]]: [[ item.name ]]
361
- </li>
362
- </ul>
363
- ```
364
-
365
- ### Conditional Classes
366
-
367
- ```html
368
- <div class="item [[ item.active ? 'active' : '' ]] [[ item.featured ? 'featured' : '' ]]">
369
- [[ item.name ]]
370
- </div>
371
- ```
372
-
373
- ### Dynamic Attributes
374
-
375
- ```html
376
- <a
377
- href="/product/[[ product.id ]]"
378
- class="product-link [[ product.inStock ? '' : 'out-of-stock' ]]"
379
- title="[[ product.name ]] - $[[ product.price ]]">
380
- [[ product.name ]]
381
- </a>
382
- ```
383
-
384
- ## Next Steps
385
-
386
- - Learn about [Directives](/guide/directives)
387
- - See [templating examples](/examples/)
388
- - Explore [component patterns](/guide/components)
package/docs/index.md DELETED
@@ -1,160 +0,0 @@
1
- ---
2
- layout: home
3
-
4
- hero:
5
- name: LegoDOM
6
- text: Build Reactive Web Components
7
- tagline: A tiny, zero-dependency Web library for creating reactive Web Components directly in the browser
8
- image:
9
- src: /logo.svg
10
- alt: LegoDOM
11
- actions:
12
- - theme: brand
13
- text: Get Started
14
- link: /guide/getting-started
15
- - theme: alt
16
- text: View on GitHub
17
- link: https://github.com/rayattack/LegoDOM
18
- - theme: alt
19
- text: Try Examples
20
- link: /examples/
21
-
22
- features:
23
- - icon: 🎯
24
- title: Mental Model Simplicity
25
- details: No virtual DOM, no compilation step, no JSX. Just HTML with a few directives and reactive objects.
26
-
27
- - icon: ⚡
28
- title: Zero Dependencies
29
- details: Under 500 lines of code with no external dependencies. The entire library is smaller than most framework router plugins.
30
-
31
- - icon: 🔄
32
- title: True Reactivity
33
- details: Direct object mutation triggers updates. No setters, no actions, no reducers. Just change the data and the DOM updates.
34
-
35
- - icon: 🧩
36
- title: Web Components Native
37
- details: Built on standard Web Components with Shadow DOM. Works anywhere, plays well with existing code.
38
-
39
- - icon: 📦
40
- title: Single File Components
41
- details: Use .lego files with Vite for a modern development experience, or load directly in the browser.
42
-
43
- - icon: 🎨
44
- title: Scoped Styles
45
- details: Shadow DOM encapsulation means your styles never leak. Use the 'self' keyword to target component root.
46
-
47
- - icon: 🛣️
48
- title: Built-in Router
49
- details: Client-side routing included. Define routes, handle parameters, and add middleware without extra packages.
50
-
51
- - icon: 💪
52
- title: TypeScript Ready
53
- details: Full JSDoc annotations for excellent IDE support and optional TypeScript integration.
54
-
55
- - icon: 🚀
56
- title: Production Ready
57
- details: Battle-tested patterns from Vue and React, adapted for pure Web Components. No framework lock-in.
58
- ---
59
-
60
- ## Components & Naming
61
-
62
- How you name your components depends on how you use LegoDOM:
63
-
64
- ### 1. Vite / Build Tools (Recommended)
65
- **Convention over Configuration.** The filename *is* the tag name.
66
- - `user-card.lego` → `<user-card></user-card>`
67
- - `app-nav.lego` → `<app-nav></app-nav>`
68
-
69
- You do not need `b-id` inside `.lego` files; the build system handles registration automatically.
70
-
71
- ### 2. CDN / Script Tags
72
- Since there are no files, you must explicitly name your components using the `b-id` attribute on the `<template>` tag.
73
-
74
- ```html
75
- <!-- Only needed for CDN usage -->
76
- <template b-id="user-profile">
77
- <h1>User Profile</h1>
78
- </template>
79
- ```
80
-
81
- ## Quick Start (CDN)
82
-
83
- ```html
84
- <!-- Define a component -->
85
- <template b-id="counter-button" b-data="{
86
- title: 'My counter',
87
- count: 0
88
- }">
89
- <style>
90
- self {
91
- display: block;
92
- padding: 1rem;
93
- }
94
- button {
95
- font-size: 1.2rem;
96
- padding: 0.5rem 1rem;
97
- }
98
- </style>
99
-
100
- <h2>{{ title }}</h2>
101
- <button @click="count++">
102
- Clicked {{ count }} times
103
- </button>
104
- </template>
105
-
106
- <!-- Use it -->
107
- <counter-button b-data="{ title: 'Override b-data title' }"></counter-button>
108
-
109
- <script src="https://unpkg.com/lego-dom/main.js"></script>
110
- <script>
111
- // Complete the initialization
112
- LegoDOM.init();
113
- </script>
114
- ```
115
-
116
- That's it. No build step, no npm, no configuration.
117
-
118
- > [!IMPORTANT]
119
- > **Why call `LegoDOM.init()`?**
120
- > While `LegoDOM.define()` will "snap" your components into the page immediately, you must call `LegoDOM.init()` to start the background engine. Without it:
121
- > - **Reactivity** to data changes won't work.
122
- > - **Mustaches** (<code v-pre>{{...}}</code>) outside of components won't hydrate.
123
- > - **Single Page Routing** won't be activated.
124
- > - **New components** added to the DOM dynamically won't be auto-initialized.
125
-
126
- ## Why LegoDOM?
127
-
128
- **For small projects**, you get reactive components without the overhead of a full framework.
129
-
130
- **For large projects**, you get a clear mental model and Web Standards compliance.
131
-
132
- **For learning**, you can read the entire source code in an afternoon and understand exactly how it works.
133
-
134
- ## Comparison
135
-
136
- | Feature | LegoDOM | Vue | React |
137
- |---------|--------|-----|-------|
138
- | Size | < 17KB | ~33KB | ~40KB |
139
- | Dependencies | 0 | Many | Many |
140
- | Build Required | No* | Yes | Yes |
141
- | Virtual DOM | No | Yes | Yes |
142
- | Learning Curve | Minimal | Moderate | Moderate |
143
- | Web Components | Native | Optional | No |
144
-
145
- \* *Optional with Vite for .lego files*
146
-
147
- ## Browser Support
148
-
149
- LegoDOM works in all modern browsers that support:
150
- - Web Components
151
- - Shadow DOM
152
- - ES6 Proxy
153
- - Template literals
154
-
155
- This includes Chrome 63+, Firefox 63+, Safari 11.1+, and Edge 79+.
156
-
157
- ## Community
158
- - 💬 [Discussions](https://github.com/rayattack/LegoDOM/discussions)
159
- - 🐛 [Issue Tracker](https://github.com/rayattack/LegoDOM/issues)
160
- - 📦 [npm Package](https://www.npmjs.com/package/lego-dom)
@@ -1,17 +0,0 @@
1
- <svg width="270" height="270" viewBox="0 0 270 270" fill="none" xmlns="http://www.w3.org/2000/svg">
2
- <path d="M19.8 199H250.2C257.88 199 263 202.657 263 208.143V253.857C263 259.343 257.88 263 250.2 263H19.8C12.12 263 7.00001 259.343 7.00001 253.857V208.143C7.00001 202.657 12.12 199 19.8 199Z" fill="#FFCA28"/>
3
- <path d="M205.194 199H238.226V183C238.226 178.2 234.923 175 229.968 175H213.452C208.497 175 205.194 178.2 205.194 183V199Z" fill="#FFCA28"/>
4
- <path d="M147.387 199H180.419V183C180.419 178.2 177.116 175 172.161 175H155.645C150.69 175 147.387 178.2 147.387 183V199Z" fill="#FFCA28"/>
5
- <path d="M15.2581 143H106.097C111.052 143 114.355 146.2 114.355 151V191C114.355 195.8 111.052 199 106.097 199H15.2581C10.3032 199 7 195.8 7 191V151C7 146.2 10.3032 143 15.2581 143Z" fill="#FFCA28"/>
6
- <path d="M15.2581 87H106.097C111.052 87 114.355 90.2 114.355 95V135C114.355 139.8 111.052 143 106.097 143H15.2581C10.3032 143 7 139.8 7 135V95C7 90.2 10.3032 87 15.2581 87Z" fill="#FFCA28"/>
7
- <path d="M15.2581 31H106.097C111.052 31 114.355 34.2 114.355 39V79C114.355 83.8 111.052 87 106.097 87H15.2581C10.3032 87 7 83.8 7 79V39C7 34.2 10.3032 31 15.2581 31Z" fill="#FFCA28"/>
8
- <path d="M73.0645 31H106.097V15C106.097 10.2 102.794 7 97.8387 7H81.3226C76.3677 7 73.0645 10.2 73.0645 15V31Z" fill="#FFCA28"/>
9
- <path d="M15.2581 31H48.2903V15C48.2903 10.2 44.9871 7 40.0323 7H23.5161C18.5613 7 15.2581 10.2 15.2581 15V31Z" fill="#FFCA28"/>
10
- <path d="M256 208.143C256 207.853 255.974 207.612 255.411 207.21C254.671 206.682 253.019 206 250.2 206H19.7998C16.9807 206 15.3288 206.682 14.5889 207.21C14.0263 207.612 14 207.853 14 208.143V253.857C14 254.147 14.0263 254.388 14.5889 254.79C15.3288 255.318 16.9807 256 19.7998 256H250.2C253.019 256 254.671 255.318 255.411 254.79C255.974 254.388 256 254.147 256 253.857V208.143ZM173.419 183C173.419 182.606 173.352 182.39 173.319 182.308C173.302 182.265 173.29 182.243 173.285 182.236C173.281 182.23 173.278 182.228 173.277 182.228C173.275 182.226 173.266 182.217 173.244 182.203C173.22 182.188 173.174 182.163 173.098 182.135C172.946 182.078 172.647 182 172.161 182H155.646C155.16 182 154.861 182.078 154.709 182.135C154.632 182.163 154.585 182.188 154.562 182.203C154.538 182.218 154.529 182.227 154.528 182.228C154.527 182.228 154.526 182.23 154.521 182.236C154.517 182.243 154.504 182.264 154.486 182.308C154.453 182.39 154.387 182.606 154.387 183V192H173.419V183ZM231.226 183C231.226 182.606 231.159 182.39 231.126 182.308C231.109 182.264 231.095 182.243 231.091 182.236C231.087 182.23 231.085 182.228 231.084 182.228C231.082 182.226 231.073 182.217 231.051 182.203C231.027 182.188 230.981 182.163 230.904 182.135C230.752 182.078 230.453 182 229.968 182H213.451C212.966 182 212.666 182.078 212.515 182.135C212.438 182.163 212.392 182.188 212.368 182.203C212.345 182.218 212.336 182.227 212.335 182.228C212.334 182.228 212.332 182.23 212.328 182.236C212.324 182.243 212.31 182.264 212.293 182.308C212.26 182.39 212.193 182.606 212.193 183V192H231.226V183ZM107.354 151C107.354 150.606 107.288 150.39 107.255 150.308C107.238 150.264 107.224 150.243 107.22 150.236C107.216 150.23 107.214 150.228 107.213 150.228C107.211 150.226 107.202 150.217 107.18 150.203C107.156 150.188 107.109 150.163 107.033 150.135C106.881 150.078 106.582 150 106.097 150H15.2578C14.7724 150 14.4731 150.078 14.3213 150.135C14.2449 150.163 14.1986 150.188 14.1748 150.203C14.1521 150.217 14.143 150.226 14.1416 150.228C14.1408 150.228 14.139 150.23 14.1348 150.236C14.1304 150.243 14.1168 150.264 14.0996 150.308C14.0667 150.39 14 150.606 14 151V191C14 191.394 14.0667 191.61 14.0996 191.692C14.1168 191.736 14.1304 191.757 14.1348 191.764C14.139 191.77 14.1408 191.772 14.1416 191.772C14.143 191.774 14.1521 191.783 14.1748 191.797C14.1986 191.812 14.2449 191.837 14.3213 191.865C14.4731 191.922 14.7724 192 15.2578 192H106.097C106.582 192 106.881 191.922 107.033 191.865C107.109 191.837 107.156 191.812 107.18 191.797C107.202 191.783 107.211 191.774 107.213 191.772C107.214 191.772 107.216 191.77 107.22 191.764C107.224 191.757 107.238 191.736 107.255 191.692C107.288 191.61 107.354 191.394 107.354 191V151ZM107.354 95C107.354 94.6058 107.288 94.3904 107.255 94.3076C107.238 94.2644 107.224 94.2429 107.22 94.2363C107.216 94.2302 107.214 94.2283 107.213 94.2275C107.211 94.2257 107.202 94.2168 107.18 94.2031C107.156 94.1883 107.109 94.1632 107.033 94.1348C106.881 94.0782 106.582 94 106.097 94H15.2578C14.7724 94 14.4731 94.0782 14.3213 94.1348C14.2449 94.1632 14.1986 94.1883 14.1748 94.2031C14.1521 94.2173 14.143 94.2262 14.1416 94.2275C14.1408 94.2284 14.139 94.2301 14.1348 94.2363C14.1304 94.2429 14.1168 94.2643 14.0996 94.3076C14.0667 94.3904 14 94.6058 14 95V135C14 135.394 14.0667 135.61 14.0996 135.692C14.1168 135.736 14.1304 135.757 14.1348 135.764C14.139 135.77 14.1408 135.772 14.1416 135.772C14.143 135.774 14.1521 135.783 14.1748 135.797C14.1986 135.812 14.2449 135.837 14.3213 135.865C14.4731 135.922 14.7724 136 15.2578 136H106.097C106.582 136 106.881 135.922 107.033 135.865C107.109 135.837 107.156 135.812 107.18 135.797C107.202 135.783 107.211 135.774 107.213 135.772C107.214 135.772 107.216 135.77 107.22 135.764C107.224 135.757 107.238 135.736 107.255 135.692C107.288 135.61 107.354 135.394 107.354 135V95ZM107.354 39C107.354 38.6058 107.288 38.3904 107.255 38.3076C107.238 38.2644 107.224 38.2429 107.22 38.2363C107.216 38.2302 107.214 38.2283 107.213 38.2275C107.211 38.2257 107.202 38.2168 107.18 38.2031C107.156 38.1883 107.109 38.1632 107.033 38.1348C106.881 38.0782 106.582 38 106.097 38H15.2578C14.7724 38 14.4731 38.0782 14.3213 38.1348C14.2449 38.1632 14.1986 38.1883 14.1748 38.2031C14.1521 38.2173 14.143 38.2262 14.1416 38.2275C14.1408 38.2284 14.139 38.2301 14.1348 38.2363C14.1304 38.2429 14.1168 38.2643 14.0996 38.3076C14.0667 38.3904 14 38.6058 14 39V79C14 79.3942 14.0667 79.6096 14.0996 79.6924C14.1168 79.7357 14.1304 79.7571 14.1348 79.7637C14.139 79.7699 14.1408 79.7716 14.1416 79.7725C14.143 79.7738 14.1521 79.7827 14.1748 79.7969C14.1986 79.8117 14.2449 79.8368 14.3213 79.8652C14.4731 79.9218 14.7724 80 15.2578 80H106.097C106.582 80 106.881 79.9218 107.033 79.8652C107.109 79.8368 107.156 79.8117 107.18 79.7969C107.202 79.7832 107.211 79.7743 107.213 79.7725C107.214 79.7717 107.216 79.7698 107.22 79.7637C107.224 79.7571 107.238 79.7356 107.255 79.6924C107.288 79.6096 107.354 79.3942 107.354 79V39ZM41.29 15C41.29 14.6058 41.2233 14.3904 41.1904 14.3076C41.1732 14.2644 41.1596 14.2429 41.1553 14.2363C41.1511 14.2302 41.1493 14.2283 41.1484 14.2275C41.1466 14.2258 41.1372 14.2169 41.1152 14.2031C41.0914 14.1883 41.045 14.1632 40.9688 14.1348C40.8169 14.0782 40.5178 14 40.0322 14H23.5166C23.031 14 22.7309 14.0782 22.5791 14.1348C22.5027 14.1633 22.4563 14.1883 22.4326 14.2031C22.4092 14.2177 22.4004 14.2266 22.3994 14.2275C22.3986 14.2284 22.3968 14.23 22.3926 14.2363C22.3882 14.2429 22.3747 14.2643 22.3574 14.3076C22.3245 14.3904 22.2578 14.6058 22.2578 15V24H41.29V15ZM99.0967 15C99.0967 14.6058 99.03 14.3904 98.9971 14.3076C98.9799 14.2644 98.9663 14.2429 98.9619 14.2363C98.9577 14.2301 98.9559 14.2283 98.9551 14.2275C98.9535 14.2261 98.9443 14.2171 98.9219 14.2031C98.8981 14.1883 98.8517 14.1632 98.7754 14.1348C98.6236 14.0782 98.3244 14 97.8389 14H81.3223C80.8369 14 80.5375 14.0782 80.3857 14.1348C80.3094 14.1632 80.263 14.1883 80.2393 14.2031C80.2164 14.2174 80.2073 14.2263 80.2061 14.2275C80.2052 14.2284 80.2034 14.23 80.1992 14.2363C80.1948 14.2429 80.1813 14.2643 80.1641 14.3076C80.1312 14.3904 80.0645 14.6058 80.0645 15V24H99.0967V15ZM113.097 25.5107C114.495 26.1706 115.799 27.0527 116.954 28.1719C119.921 31.0462 121.354 34.9412 121.354 39V79C121.354 81.8462 120.648 84.6105 119.204 87C120.648 89.3895 121.354 92.1538 121.354 95V135C121.354 137.846 120.648 140.611 119.204 143C120.648 145.389 121.354 148.154 121.354 151V191C121.354 191.335 121.345 191.668 121.325 192H140.387V183C140.387 178.941 141.82 175.046 144.787 172.172C147.734 169.317 151.643 168 155.646 168H172.161C176.164 168 180.071 169.317 183.019 172.172C185.986 175.046 187.419 178.941 187.419 183V192H198.193V183C198.193 178.941 199.627 175.046 202.594 172.172C205.541 169.317 209.449 168 213.451 168H229.968C233.97 168 237.878 169.317 240.825 172.172C243.792 175.046 245.226 178.941 245.226 183V192H250.2C255.06 192 259.809 193.147 263.549 195.818C267.466 198.616 270 202.947 270 208.143V253.857C270 259.053 267.466 263.384 263.549 266.182C259.809 268.853 255.06 270 250.2 270H19.7998C14.9396 270 10.1913 268.853 6.45117 266.182C2.53412 263.384 8.92991e-05 259.053 0 253.857V208.143C5.4865e-05 204.95 0.95743 202.085 2.60352 199.701C0.853644 197.16 0 194.129 0 191V151C0 148.154 0.706222 145.389 2.15039 143C0.706222 140.611 0 137.846 0 135V95C0 92.1539 0.706222 89.3894 2.15039 87C0.706222 84.6106 0 81.8461 0 79V39C0 34.9412 1.43333 31.0462 4.40039 28.1719C5.55577 27.0526 6.85931 26.1706 8.25781 25.5107V15C8.25781 10.9412 9.69114 7.04622 12.6582 4.17188C15.6053 1.31691 19.5139 0 23.5166 0H40.0322C44.0348 0 47.9426 1.3171 50.8896 4.17188C53.8567 7.04622 55.29 10.9412 55.29 15V24H66.0645V15C66.0645 10.9412 67.4978 7.04622 70.4648 4.17188C73.4119 1.31705 77.3197 6.86267e-05 81.3223 0H97.8389C101.841 3.51509e-05 105.749 1.31707 108.696 4.17188C111.663 7.04622 113.097 10.9412 113.097 15V25.5107Z" fill="#3E3E3E"/>
11
- <path d="M151.988 148.804L143 48H241.76L232.76 148.788L192.32 160L151.988 148.804Z" fill="#E44F26"/>
12
- <path d="M192.381 151.432L225.061 142.372L232.749 56.2441H192.381V151.432Z" fill="#F1662A"/>
13
- <path d="M192.381 93.628H176.021L174.893 80.968H192.381V68.604H192.337H161.381L164.713 105.992H192.381V93.628Z" fill="#EBEBEB"/>
14
- <path d="M192.382 125.736L192.326 125.752L178.558 122.036L177.678 112.176H165.266L166.998 131.584L192.326 138.616L192.382 138.6V125.736Z" fill="#EBEBEB"/>
15
- <path d="M192.336 93.6279V105.992H207.56L206.128 122.028L192.336 125.748V138.612L217.684 131.584L217.868 129.496L220.772 96.9479L221.076 93.6279H192.336Z" fill="white"/>
16
- <path d="M192.337 68.604L192.336 80.968H222.2L223.308 68.604H192.337Z" fill="white"/>
17
- </svg>
@@ -1,103 +0,0 @@
1
- # Basic Routing: The Global Outlet
2
-
3
- Before we dive into surgical swaps, we must understand how LegoDOM handles the initial entry into your application. Every application needs a primary gateway—a place where the main content lives. In LegoDOM, this is the `<lego-router>`.
4
-
5
- ## The Entry Point
6
-
7
- In your `index.html`, you define a single custom element that acts as the "Master Outlet":
8
-
9
- ```html
10
- <body>
11
- <my-application-nav></my-application-nav>
12
- <lego-router></lego-router>
13
- </body>
14
-
15
- ```
16
-
17
-
18
- When the page loads, the LegoDOM router looks at the current browser URL and searches its internal "Route Map" for a match.
19
-
20
- ## Defining Your First Routes
21
-
22
- Routes are defined using the `Lego.route(path, componentName)` method. This creates a contract between a URL pattern and a Web Component.
23
-
24
- ```js
25
- // Static Route
26
- Lego.route('/', 'home-page');
27
-
28
- // Dynamic Route (with parameters)
29
- Lego.route('/user/:id', 'profile-page');
30
-
31
- ```
32
-
33
- ### How the Matching Works
34
-
35
- 1. **The Match**: LegoDOM uses Regex to compare the window location with your defined paths.
36
-
37
- 2. **The Injection**: If a match is found, LegoDOM creates an instance of the associated component (e.g., `<home-page>`) and injects it into the `<lego-router>` tag.
38
-
39
- 3. **The Hydration**: The framework then "snaps" the component to life, initializing its state and running its `mounted()` lifecycle hook.
40
-
41
-
42
- ## The Global Fallback
43
-
44
- If no route matches the current URL, LegoDOM looks for a special fallback route. This is essential for handling **404 Not Found** states gracefully.
45
-
46
- ```js
47
- Lego.route('*', 'not-found-page');
48
-
49
- ```
50
-
51
- ## Handling Parameters (`$params`)
52
-
53
- When you use a dynamic path like `/user/:id`, LegoDOM automatically parses the URL and makes the data available to the component via the global `$route` object.
54
-
55
- In your component template:
56
-
57
- ```html
58
- <template b-id="profile-page">
59
- <h1>User Profile</h1>
60
- <p>Viewing ID: [[ $route.params.id ]]</p>
61
- </template>
62
-
63
- ```
64
-
65
- In your component logic:
66
-
67
- ```js
68
- mounted() {
69
- const userId = this.$route.params.id;
70
- this.fetchUserData(userId);
71
- }
72
-
73
- ```
74
-
75
- **or**
76
-
77
-
78
- ```html
79
- <!-- profile-page.lego -->
80
- <style>
81
- /* nothing here for now */
82
- </style>
83
-
84
- <template>
85
- <h1>User Profile</h1>
86
- <p>Viewing ID: [[ $params.id ]]</p>
87
- </template>
88
-
89
- <script>
90
- export default {
91
- mounted() {
92
- const userId = this.$route.params.id;
93
- this.fetchUserData(userId);
94
- }
95
- }
96
- </script>
97
- ```
98
-
99
- ## Summary
100
-
101
- The `<lego-router>` is the foundation. It handles the "Big Swaps" of your application. However, in a modern "Enterprise" application, we rarely want to swap the _entire_ page content every time the URL changes.
102
-
103
- In the next section, we will learn about **Surgical Swaps**, where we move beyond the global router and start updating specific pieces of the DOM using `b-target`.