lego-dom 0.0.7 → 0.0.9

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 (147) hide show
  1. package/.github/workflows/deploy-docs.yml +56 -0
  2. package/LICENSE +21 -0
  3. package/README.md +52 -314
  4. package/docs/.vitepress/config.js +107 -0
  5. package/docs/.vitepress/dist/404.html +22 -0
  6. package/docs/.vitepress/dist/api/define.html +35 -0
  7. package/docs/.vitepress/dist/api/directives.html +32 -0
  8. package/docs/.vitepress/dist/api/globals.html +27 -0
  9. package/docs/.vitepress/dist/api/index.html +25 -0
  10. package/docs/.vitepress/dist/api/lifecycle.html +38 -0
  11. package/docs/.vitepress/dist/api/route.html +34 -0
  12. package/docs/.vitepress/dist/api/vite-plugin.html +37 -0
  13. package/docs/.vitepress/dist/assets/api_define.md.UA-ygUnQ.js +11 -0
  14. package/docs/.vitepress/dist/assets/api_define.md.UA-ygUnQ.lean.js +1 -0
  15. package/docs/.vitepress/dist/assets/api_directives.md.BV-D251p.js +8 -0
  16. package/docs/.vitepress/dist/assets/api_directives.md.BV-D251p.lean.js +1 -0
  17. package/docs/.vitepress/dist/assets/api_globals.md.CEznyRAY.js +3 -0
  18. package/docs/.vitepress/dist/assets/api_globals.md.CEznyRAY.lean.js +1 -0
  19. package/docs/.vitepress/dist/assets/api_index.md.IEYUxUIr.js +1 -0
  20. package/docs/.vitepress/dist/assets/api_index.md.IEYUxUIr.lean.js +1 -0
  21. package/docs/.vitepress/dist/assets/api_lifecycle.md.Ccm5xw6-.js +14 -0
  22. package/docs/.vitepress/dist/assets/api_lifecycle.md.Ccm5xw6-.lean.js +1 -0
  23. package/docs/.vitepress/dist/assets/api_route.md.CAHf_KNp.js +10 -0
  24. package/docs/.vitepress/dist/assets/api_route.md.CAHf_KNp.lean.js +1 -0
  25. package/docs/.vitepress/dist/assets/api_vite-plugin.md.DC8Li09k.js +13 -0
  26. package/docs/.vitepress/dist/assets/api_vite-plugin.md.DC8Li09k.lean.js +1 -0
  27. package/docs/.vitepress/dist/assets/app.BfblNDJy.js +1 -0
  28. package/docs/.vitepress/dist/assets/chunks/@localSearchIndexroot.Crdp7-Zp.js +1 -0
  29. package/docs/.vitepress/dist/assets/chunks/VPLocalSearchBox.C18E44rY.js +9 -0
  30. package/docs/.vitepress/dist/assets/chunks/framework.B7OFBR9X.js +19 -0
  31. package/docs/.vitepress/dist/assets/chunks/theme.VX3itTW6.js +2 -0
  32. package/docs/.vitepress/dist/assets/examples_form.md.DQoAgbLR.js +34 -0
  33. package/docs/.vitepress/dist/assets/examples_form.md.DQoAgbLR.lean.js +1 -0
  34. package/docs/.vitepress/dist/assets/examples_index.md.CVJJjXXE.js +28 -0
  35. package/docs/.vitepress/dist/assets/examples_index.md.CVJJjXXE.lean.js +1 -0
  36. package/docs/.vitepress/dist/assets/examples_routing.md.sRnA5RXw.js +338 -0
  37. package/docs/.vitepress/dist/assets/examples_routing.md.sRnA5RXw.lean.js +1 -0
  38. package/docs/.vitepress/dist/assets/examples_sfc-showcase.md.DPf9Wm99.js +13 -0
  39. package/docs/.vitepress/dist/assets/examples_sfc-showcase.md.DPf9Wm99.lean.js +1 -0
  40. package/docs/.vitepress/dist/assets/examples_todo-app.md.CqF4JaWn.js +297 -0
  41. package/docs/.vitepress/dist/assets/examples_todo-app.md.CqF4JaWn.lean.js +1 -0
  42. package/docs/.vitepress/dist/assets/guide_cdn-usage.md.CjIjusre.js +182 -0
  43. package/docs/.vitepress/dist/assets/guide_cdn-usage.md.CjIjusre.lean.js +1 -0
  44. package/docs/.vitepress/dist/assets/guide_components.md.CMU3iM6R.js +174 -0
  45. package/docs/.vitepress/dist/assets/guide_components.md.CMU3iM6R.lean.js +1 -0
  46. package/docs/.vitepress/dist/assets/guide_contributing.md.Crrv3T_0.js +1 -0
  47. package/docs/.vitepress/dist/assets/guide_contributing.md.Crrv3T_0.lean.js +1 -0
  48. package/docs/.vitepress/dist/assets/guide_directives.md.DFwqvqOv.js +140 -0
  49. package/docs/.vitepress/dist/assets/guide_directives.md.DFwqvqOv.lean.js +1 -0
  50. package/docs/.vitepress/dist/assets/guide_getting-started.md.DtaJPe0i.js +107 -0
  51. package/docs/.vitepress/dist/assets/guide_getting-started.md.DtaJPe0i.lean.js +1 -0
  52. package/docs/.vitepress/dist/assets/guide_index.md.DtJVpLI9.js +2 -0
  53. package/docs/.vitepress/dist/assets/guide_index.md.DtJVpLI9.lean.js +1 -0
  54. package/docs/.vitepress/dist/assets/guide_lifecycle.md.CfY3jlU1.js +304 -0
  55. package/docs/.vitepress/dist/assets/guide_lifecycle.md.CfY3jlU1.lean.js +1 -0
  56. package/docs/.vitepress/dist/assets/guide_quick-start.md.CwdNNA21.js +33 -0
  57. package/docs/.vitepress/dist/assets/guide_quick-start.md.CwdNNA21.lean.js +1 -0
  58. package/docs/.vitepress/dist/assets/guide_reactivity.md.DgTH0MTn.js +135 -0
  59. package/docs/.vitepress/dist/assets/guide_reactivity.md.DgTH0MTn.lean.js +1 -0
  60. package/docs/.vitepress/dist/assets/guide_routing.md.nMB0QOBR.js +193 -0
  61. package/docs/.vitepress/dist/assets/guide_routing.md.nMB0QOBR.lean.js +1 -0
  62. package/docs/.vitepress/dist/assets/guide_sfc.md.BUkWma1z.js +187 -0
  63. package/docs/.vitepress/dist/assets/guide_sfc.md.BUkWma1z.lean.js +1 -0
  64. package/docs/.vitepress/dist/assets/guide_templating.md.XI3uUlYI.js +119 -0
  65. package/docs/.vitepress/dist/assets/guide_templating.md.XI3uUlYI.lean.js +1 -0
  66. package/docs/.vitepress/dist/assets/index.md.M4_o26kF.js +23 -0
  67. package/docs/.vitepress/dist/assets/index.md.M4_o26kF.lean.js +1 -0
  68. package/docs/.vitepress/dist/assets/inter-italic-cyrillic-ext.r48I6akx.woff2 +0 -0
  69. package/docs/.vitepress/dist/assets/inter-italic-cyrillic.By2_1cv3.woff2 +0 -0
  70. package/docs/.vitepress/dist/assets/inter-italic-greek-ext.1u6EdAuj.woff2 +0 -0
  71. package/docs/.vitepress/dist/assets/inter-italic-greek.DJ8dCoTZ.woff2 +0 -0
  72. package/docs/.vitepress/dist/assets/inter-italic-latin-ext.CN1xVJS-.woff2 +0 -0
  73. package/docs/.vitepress/dist/assets/inter-italic-latin.C2AdPX0b.woff2 +0 -0
  74. package/docs/.vitepress/dist/assets/inter-italic-vietnamese.BSbpV94h.woff2 +0 -0
  75. package/docs/.vitepress/dist/assets/inter-roman-cyrillic-ext.BBPuwvHQ.woff2 +0 -0
  76. package/docs/.vitepress/dist/assets/inter-roman-cyrillic.C5lxZ8CY.woff2 +0 -0
  77. package/docs/.vitepress/dist/assets/inter-roman-greek-ext.CqjqNYQ-.woff2 +0 -0
  78. package/docs/.vitepress/dist/assets/inter-roman-greek.BBVDIX6e.woff2 +0 -0
  79. package/docs/.vitepress/dist/assets/inter-roman-latin-ext.4ZJIpNVo.woff2 +0 -0
  80. package/docs/.vitepress/dist/assets/inter-roman-latin.Di8DUHzh.woff2 +0 -0
  81. package/docs/.vitepress/dist/assets/inter-roman-vietnamese.BjW4sHH5.woff2 +0 -0
  82. package/docs/.vitepress/dist/assets/style.eycE2Jhw.css +1 -0
  83. package/docs/.vitepress/dist/examples/form.html +58 -0
  84. package/docs/.vitepress/dist/examples/index.html +52 -0
  85. package/docs/.vitepress/dist/examples/routing.html +362 -0
  86. package/docs/.vitepress/dist/examples/sfc-showcase.html +37 -0
  87. package/docs/.vitepress/dist/examples/todo-app.html +321 -0
  88. package/docs/.vitepress/dist/guide/cdn-usage.html +206 -0
  89. package/docs/.vitepress/dist/guide/components.html +198 -0
  90. package/docs/.vitepress/dist/guide/contributing.html +25 -0
  91. package/docs/.vitepress/dist/guide/directives.html +164 -0
  92. package/docs/.vitepress/dist/guide/getting-started.html +131 -0
  93. package/docs/.vitepress/dist/guide/index.html +26 -0
  94. package/docs/.vitepress/dist/guide/lifecycle.html +328 -0
  95. package/docs/.vitepress/dist/guide/quick-start.html +57 -0
  96. package/docs/.vitepress/dist/guide/reactivity.html +159 -0
  97. package/docs/.vitepress/dist/guide/routing.html +217 -0
  98. package/docs/.vitepress/dist/guide/sfc.html +211 -0
  99. package/docs/.vitepress/dist/guide/templating.html +143 -0
  100. package/docs/.vitepress/dist/hashmap.json +1 -0
  101. package/docs/.vitepress/dist/index.html +47 -0
  102. package/docs/.vitepress/dist/logo.svg +38 -0
  103. package/docs/.vitepress/dist/vp-icons.css +1 -0
  104. package/docs/api/define.md +31 -0
  105. package/docs/api/directives.md +42 -0
  106. package/docs/api/globals.md +29 -0
  107. package/docs/api/index.md +29 -0
  108. package/docs/api/lifecycle.md +40 -0
  109. package/docs/api/route.md +37 -0
  110. package/docs/api/vite-plugin.md +58 -0
  111. package/docs/examples/form.md +42 -0
  112. package/docs/examples/index.md +104 -0
  113. package/docs/examples/routing.md +409 -0
  114. package/docs/examples/sfc-showcase.md +34 -0
  115. package/docs/examples/todo-app.md +383 -0
  116. package/docs/guide/cdn-usage.md +320 -0
  117. package/docs/guide/components.md +394 -0
  118. package/docs/guide/contributing.md +32 -0
  119. package/docs/guide/directives.md +430 -0
  120. package/docs/guide/getting-started.md +233 -0
  121. package/docs/guide/index.md +88 -0
  122. package/docs/guide/lifecycle.md +493 -0
  123. package/docs/guide/quick-start.md +46 -0
  124. package/docs/guide/reactivity.md +394 -0
  125. package/docs/guide/routing.md +373 -0
  126. package/docs/guide/sfc.md +381 -0
  127. package/docs/guide/templating.md +383 -0
  128. package/docs/index.md +126 -0
  129. package/docs/public/logo.svg +17 -0
  130. package/examples/vite-app/README.md +71 -0
  131. package/examples/vite-app/index.html +49 -0
  132. package/examples/vite-app/package.json +16 -0
  133. package/examples/vite-app/src/components/greeting-card.lego +41 -0
  134. package/examples/vite-app/src/components/sample-component.lego +75 -0
  135. package/examples/vite-app/src/components/todo-list.lego +242 -0
  136. package/examples/vite-app/src/main.js +11 -0
  137. package/examples/vite-app/vite.config.js +17 -0
  138. package/examples.js +99 -0
  139. package/go.html +117 -0
  140. package/lego.js +2 -0
  141. package/main.js +41 -35
  142. package/package.json +39 -6
  143. package/parse-lego.js +119 -0
  144. package/parse-lego.test.js +107 -0
  145. package/vite-plugin.js +133 -0
  146. package/.ignore/auto.html +0 -135
  147. package/.ignore/test.html +0 -73
@@ -0,0 +1,42 @@
1
+ # Directives
2
+
3
+ Special attributes that control DOM behavior.
4
+
5
+ ## b-if
6
+
7
+ Conditionally render an element.
8
+
9
+ ```html
10
+ <div b-if="loading">Loading...</div>
11
+ <div b-if="!loading">Content loaded!</div>
12
+ ```
13
+
14
+ ## b-for
15
+
16
+ Render a list of items.
17
+
18
+ ```html
19
+ <ul>
20
+ <li b-for="user in users">
21
+ {{ user.name }}
22
+ </li>
23
+ </ul>
24
+ ```
25
+
26
+ ## b-sync
27
+
28
+ Two-way data binding for form inputs.
29
+
30
+ ```html
31
+ <input b-sync="username" placeholder="Enter username">
32
+ <p>You typed: {{ username }}</p>
33
+ ```
34
+
35
+ ## @event
36
+
37
+ Event listeners.
38
+
39
+ ```html
40
+ <button @click="save()">Save</button>
41
+ <input @input="validate($event)">
42
+ ```
@@ -0,0 +1,29 @@
1
+ # Global Helpers
2
+
3
+ Lego exposes a global `Lego` object when loaded via CDN, or as exports when using modules.
4
+
5
+ ## Lego.page
6
+
7
+ Access to the router's current state.
8
+
9
+ ```js
10
+ console.log(Lego.page.params); // URL parameters
11
+ console.log(Lego.page.query); // Query string parameters
12
+ ```
13
+
14
+ ## Lego.create()
15
+
16
+ Manually create a reactive object (stud) detached from a component.
17
+
18
+ ```js
19
+ const store = Lego.create({ count: 0 });
20
+ ```
21
+
22
+ ## Event Bus
23
+
24
+ Simple global event bus.
25
+
26
+ ```js
27
+ Lego.on('user-login', (user) => { ... });
28
+ Lego.emit('user-login', { name: 'Alice' });
29
+ ```
@@ -0,0 +1,29 @@
1
+ # API Reference
2
+
3
+ Welcome to the Lego API documentation.
4
+
5
+ ## Core
6
+
7
+ - [Lego.define()](/api/define) - Defining components
8
+ - [Lego.route()](/api/route) - Client-side routing
9
+ - [Lego.globals](/api/globals) - Global state
10
+ - [Lifecycle Hooks](/api/lifecycle) - Component lifecycle methods
11
+
12
+ ## Templates & Binding
13
+
14
+ - [Directives](/api/directives) - `b-if`, `b-for`, `b-sync`
15
+
16
+ ## Browser Support
17
+
18
+ Lego requires:
19
+ - Web Components (Custom Elements v1)
20
+ - Shadow DOM v1
21
+ - ES6 Proxy
22
+ - Template Literals
23
+ - MutationObserver
24
+
25
+ Supported browsers:
26
+ - Chrome 63+
27
+ - Firefox 63+
28
+ - Safari 11.1+
29
+ - Edge 79+
@@ -0,0 +1,40 @@
1
+ # Lifecycle Hooks
2
+
3
+ Methods that are automatically called during a component's lifecycle.
4
+
5
+ ## init()
6
+
7
+ Called when the component is initialized and state is reactive, but before rendering.
8
+
9
+ ```js
10
+ {
11
+ init() {
12
+ this.fetchData();
13
+ }
14
+ }
15
+ ```
16
+
17
+ ## render()
18
+
19
+ Called after the DOM has been updated.
20
+
21
+ ```js
22
+ {
23
+ render() {
24
+ console.log('Component rendered');
25
+ }
26
+ }
27
+ ```
28
+
29
+ ## destroy()
30
+
31
+ Called when the component is removed from the DOM.
32
+
33
+ ```js
34
+ {
35
+ destroy() {
36
+ // Cleanup timers or listeners
37
+ clearInterval(this.timer);
38
+ }
39
+ }
40
+ ```
@@ -0,0 +1,37 @@
1
+ # Lego.route()
2
+
3
+ Client-side routing.
4
+
5
+ ## Type Signature
6
+
7
+ ```ts
8
+ Lego.route(path: string, componentOrHtml: string | HTMLElement)
9
+ ```
10
+
11
+ ## Arguments
12
+
13
+ - **path**: The URL path pattern (e.g., `/users/:id`).
14
+ - **componentOrHtml**: The tag name of the component to render, or raw HTML.
15
+
16
+ ## Example
17
+
18
+ ```js
19
+ // Route to a component
20
+ Lego.route('/', 'home-page');
21
+ Lego.route('/about', 'about-page');
22
+
23
+ // Route with params
24
+ Lego.route('/user/:id', 'user-profile');
25
+ ```
26
+
27
+ ## Router Outlet
28
+
29
+ You must have a `<router-outlet>` in your DOM where the routed content will appear.
30
+
31
+ ```html
32
+ <nav>
33
+ <a href="/">Home</a>
34
+ <a href="/about">About</a>
35
+ </nav>
36
+ <router-outlet></router-outlet>
37
+ ```
@@ -0,0 +1,58 @@
1
+ # Vite Plugin API
2
+
3
+ Lego includes a Vite plugin for processing `.lego` Single File Components.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install vite lego-dom
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```js
14
+ // vite.config.js
15
+ import { defineConfig } from 'vite';
16
+ import legoPlugin from 'lego-dom/vite-plugin';
17
+
18
+ export default defineConfig({
19
+ plugins: [
20
+ legoPlugin({
21
+ // Options
22
+ })
23
+ ]
24
+ });
25
+ ```
26
+
27
+ ## Options
28
+
29
+ ### `componentsDir`
30
+
31
+ - **Type**: `string`
32
+ - **Default**: `'src/components'`
33
+
34
+ Directory to search for `.lego` files.
35
+
36
+ ### `include`
37
+
38
+ - **Type**: `string | string[]`
39
+ - **Default**: `'**/*.lego'`
40
+
41
+ Glob pattern(s) to match files.
42
+
43
+ ### `exclude`
44
+
45
+ - **Type**: `string | string[]`
46
+ - **Default**: `null`
47
+
48
+ Glob pattern(s) to exclude files.
49
+
50
+ ## Virtual Module
51
+
52
+ The plugin exposes a virtual module to register all components:
53
+
54
+ ```js
55
+ import registerComponents from 'virtual:lego-components';
56
+
57
+ registerComponents();
58
+ ```
@@ -0,0 +1,42 @@
1
+ # Form Example
2
+
3
+ Handling forms in Lego.
4
+
5
+ ## Live Demo
6
+
7
+ ```html
8
+ <template b-id="login-form">
9
+ <form @submit.prevent="login()">
10
+ <div>
11
+ <label>Email:</label>
12
+ <input type="email" b-sync="email">
13
+ </div>
14
+
15
+ <div>
16
+ <label>Password:</label>
17
+ <input type="password" b-sync="password">
18
+ </div>
19
+
20
+ <p b-if="error" style="color: red">{{ error }}</p>
21
+
22
+ <button type="submit">Login</button>
23
+ </form>
24
+ </template>
25
+
26
+ <script>
27
+ Lego.define('login-form', {
28
+ email: '',
29
+ password: '',
30
+ error: '',
31
+
32
+ login() {
33
+ if (!this.email || !this.password) {
34
+ this.error = 'Please fill in all fields';
35
+ return;
36
+ }
37
+ alert(`Logging in as ${this.email}`);
38
+ this.error = '';
39
+ }
40
+ });
41
+ </script>
42
+ ```
@@ -0,0 +1,104 @@
1
+ # Examples
2
+
3
+ Explore these hands-on examples to learn Lego patterns and best practices.
4
+
5
+ ## Quick Examples
6
+
7
+ ### Counter
8
+
9
+ A simple reactive counter demonstrating basic state and events.
10
+
11
+ ```html
12
+ <template b-id="click-counter">
13
+ <style>
14
+ button { font-size: 1.2rem; padding: 0.5rem 1rem; }
15
+ </style>
16
+ <p>Count: {{ count }}</p>
17
+ <button @click="count++">Increment</button>
18
+ </template>
19
+
20
+ <click-counter b-data="{ count: 0 }"></click-counter>
21
+ ```
22
+
23
+ ### Input Binding
24
+
25
+ Two-way data binding with `b-sync`.
26
+
27
+ ```html
28
+ <template b-id="name-input">
29
+ <input b-sync="name" placeholder="Enter your name">
30
+ <p b-if="name">Hello, {{ name }}!</p>
31
+ </template>
32
+
33
+ <name-input b-data="{ name: '' }"></name-input>
34
+ ```
35
+
36
+ ### Todo List
37
+
38
+ Lists with `b-for`.
39
+
40
+ ```html
41
+ <template b-id="todo-list">
42
+ <ul>
43
+ <li b-for="todo in todos">
44
+ <input type="checkbox" b-sync="todo.done">
45
+ <span class="{{ todo.done ? 'done' : '' }}">{{ todo.text }}</span>
46
+ </li>
47
+ </ul>
48
+ </template>
49
+
50
+ <todo-list b-data="{
51
+ todos: [
52
+ { text: 'Learn Lego', done: true },
53
+ { text: 'Build an app', done: false }
54
+ ]
55
+ }"></todo-list>
56
+ ```
57
+
58
+ ## Full Applications
59
+
60
+ ### [Todo App](/examples/todo-app)
61
+
62
+ A complete todo application with:
63
+ - Add/remove todos
64
+ - Mark as complete
65
+ - Filter by status
66
+ - Local storage persistence
67
+
68
+ ### [Routing Demo](/examples/routing)
69
+
70
+ Single-page application with:
71
+ - Multiple pages
72
+ - Dynamic routes
73
+ - Navigation
74
+ - Route parameters
75
+
76
+ ### [SFC Showcase](/examples/sfc-showcase)
77
+
78
+ Using Single File Components:
79
+ - User cards
80
+ - Product grid
81
+ - Modal dialogs
82
+ - Form validation
83
+
84
+ ### [Form Validation](/examples/form)
85
+
86
+ Advanced form handling:
87
+ - Input validation
88
+ - Error messages
89
+ - Submit handling
90
+ - Reset functionality
91
+
92
+ ## CodePen Examples
93
+
94
+ Try these examples directly in your browser:
95
+
96
+ - [Simple Counter](https://codepen.io/ortserga/pen/XJKdMJm)
97
+ - [Todo App](https://codepen.io/ortserga/pen/todo)
98
+ - [Dynamic Form](https://codepen.io/ortserga/pen/form)
99
+
100
+ ## Next Steps
101
+
102
+ - Check the [API Reference](/api/)
103
+ - Read the [Guide](/guide/)
104
+ - View the [source code](https://github.com/rayattack/Lego)