@o.z/zui 0.1.0 → 0.1.1

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 (2) hide show
  1. package/README.md +92 -79
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -1,36 +1,28 @@
1
1
  # ZUI Framework ⚡
2
2
 
3
- [![npm](https://img.shields.io/npm/v/@o.z/zui)](https://www.npmjs.com/package/@o.z/zui) [![license](https://img.shields.io/npm/l/@o.z/zui)](https://www.npmjs.com/package/@o.z/zui)
3
+ [![npm version](https://img.shields.io/npm/v/@o.z/zui?style=flat-square)](https://www.npmjs.com/package/@o.z/zui)
4
+ [![license](https://img.shields.io/npm/l/@o.z/zui?style=flat-square)](https://www.npmjs.com/package/@o.z/zui)
5
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-blue?style=flat-square&logo=typescript)](https://www.typescriptlang.org/)
6
+ [![Vite](https://img.shields.io/badge/Vite-Compatible-646CFF?style=flat-square&logo=vite)](https://vitejs.dev/)
4
7
 
5
- ### Next-Generation Web Components with TypeScript Stage 3 Decorators
6
-
7
- **ZUI** is a lightweight, type-safe abstraction layer for building native Web Components. It leverages the power of **TypeScript Stage 3 Decorators** (`accessor`) to remove boilerplate, manage reactivity, and streamline DOM interactions, all while staying close to the metal of the browser.
8
+ **ZUI** is a next-generation, lightweight abstraction layer for building native Web Components. It leverages **TypeScript Stage 3 Decorators** to eliminate boilerplate, manage reactive state, and streamline DOM interactions while staying close to the metal of the browser.
8
9
 
9
10
  ---
10
11
 
11
12
  ## 🚀 Why ZUI?
12
13
 
13
- Building raw Web Components requires repetitive boilerplate: `observedAttributes`, `attributeChangedCallback`, `shadowRoot` management, and manual event dispatching.
14
+ Standard Web Components require significant boilerplate: managing `observedAttributes`, manually handling `shadowRoot`, and verbose event dispatching. **ZUI** solves this with a declarative, type-safe API:
14
15
 
15
- **ZUI** solves this by offering a declarative API for:
16
- * **Reactive State:** Auto-updating views when properties change.
17
- * **Zero-Boilerplate Refs:** Type-safe access to DOM elements.
18
- * **Magic Event Emitters:** Auto-generated dispatch methods.
19
- * **Customized Built-ins:** Seamlessly extending native elements like `HTMLDivElement`.
16
+ * **⚡ Stage 3 Decorators:** Built for modern TypeScript, utilizing the standard `accessor` pattern.
17
+ * **🔄 Reactive State:** Properties automatically trigger view updates and lifecycle hooks.
18
+ * **🎯 Zero-Boilerplate Refs:** Type-safe DOM element caching without manual `querySelector` calls.
19
+ * **📡 Magic Event Emitters:** Auto-generated, strictly typed event dispatch methods.
20
+ * **🎨 Scoped Styling:** Seamless integration with standard Shadow DOM or scoped styles.
21
+ * **🛠 Customized Built-ins:** First-class support for extending native elements (e.g., `<div is="my-component">`).
20
22
 
21
23
  ---
22
24
 
23
- ## 📦 Features
24
-
25
- * **Stage 3 Decorators:** Built for the future of TypeScript.
26
- * **Reactivity System:** Simple `accessor` pattern with lifecycle hooks (e.g., `countUpdate`).
27
- * **Scoped Styling:** Automatic Shadow DOM or scoped style injection.
28
- * **Vite Compatible:** Designed to work with `.html?raw` and `.scss?inline` imports.
29
- * **Type Safety:** First-class TypeScript support for Props and Events.
30
-
31
- ---
32
-
33
- ## Installation
25
+ ## 📦 Installation
34
26
 
35
27
  ```bash
36
28
  npm install @o.z/zui
@@ -44,9 +36,9 @@ pnpm add @o.z/zui
44
36
 
45
37
  ## 🛠️ Usage Example
46
38
 
47
- Here is a complete example of a **Reactive Counter** component extending a native `div`.
39
+ ZUI works best with Vite's string imports for HTML and CSS. Below is a complete example of a **Reactive Counter** that extends a native `div`.
48
40
 
49
- ### 1. Define the Component
41
+ ### 1. The Component (`counter.ts`)
50
42
 
51
43
  ```typescript
52
44
  import { defineElement, event, property, ref } from "@o.z/zui";
@@ -57,75 +49,82 @@ import cssStr from "./counter.scss?inline";
57
49
  tagName: "my-counter",
58
50
  html: htmlStr,
59
51
  css: cssStr,
60
- options: { extends: 'div' } // Extends native DIV
52
+ options: { extends: 'div' } // Extends native HTMLDivElement
61
53
  })
62
54
  export class Counter extends HTMLDivElement {
63
55
 
64
- // 1. Reactive State
56
+ // 1. Reactive State: Auto-observes attributes and updates
65
57
  @property()
66
- accessor count: number = 0;
58
+ accessor count = 0;
67
59
 
68
- // 2. DOM References (No more querySelector in methods)
69
- @ref(selector: ".counter")
60
+ // 2. DOM References: Selects elements from the template
61
+ @ref(".counter")
70
62
  counterRef!: HTMLDivElement;
71
63
 
72
- @ref(selector: ".increase")
64
+ @ref(".increase")
73
65
  increaseRef!: HTMLButtonElement;
74
66
 
75
- @ref(selector: ".decrease")
67
+ @ref(".decrease")
76
68
  decreaseRef!: HTMLButtonElement;
77
69
 
78
- // 3. Event Definition
70
+ // 3. Event Emitter: Generates 'emitCounterClick' method
79
71
  @event({ name: "counter-click" })
80
72
  counterClick!: CustomEvent<any>;
81
73
 
82
74
  connected() {
83
- this.increaseRef.addEventListener("click", () => this.handleUpdate(1));
84
- this.decreaseRef.addEventListener("click", () => this.handleUpdate(-1));
75
+ // 'connected' is a ZUI shorthand for connectedCallback
76
+ this.increaseRef.addEventListener("click", this.incHandler);
77
+ this.decreaseRef.addEventListener("click", this.decHandler);
78
+ }
79
+
80
+ disconnected() {
81
+ this.increaseRef.removeEventListener("click", this.incHandler);
82
+ this.decreaseRef.removeEventListener("click", this.decHandler);
85
83
  }
86
84
 
87
- handleUpdate(delta: number) {
88
- // Magic method generated by @event decorator
89
- (this as any).emitCounterClick({ count: delta });
85
+ incHandler = (e: MouseEvent) => {
86
+ // Magic method generated by @event
87
+ (this as any).emitCounterClick({ e, count: 1 });
90
88
  }
91
89
 
92
- // 4. Reactive Hook: Called automatically when 'count' changes
90
+ decHandler = (e: MouseEvent) => {
91
+ (this as any).emitCounterClick({ e, count: -1 });
92
+ }
93
+
94
+ // 4. Lifecycle Hook: Called automatically when 'count' changes
93
95
  countUpdate(_oldVal: number, newVal: number) {
94
96
  this.counterRef.innerHTML = newVal.toString();
95
97
  }
96
98
  }
97
99
  ```
98
100
 
99
- ### 2. The Template & Styles
101
+ ### 2. The Template (`counter.html`)
100
102
 
101
- **Counter.html**
102
103
  ```html
103
104
  <div class="container">
104
- <div part="counter-text" class="counter">0</div>
105
- <button class="decrease"><slot name="decrease"></slot></button>
106
- <button class="increase"><slot name="increase"></slot></button>
105
+ <div class="counter">0</div>
106
+ <button class="increase">+</button>
107
+ <button class="decrease">-</button>
107
108
  </div>
108
109
  ```
109
110
 
110
- ### 3. Implementation in DOM
111
+ ### 3. Usage in HTML
111
112
 
112
- Because ZUI supports **Customized Built-in Elements**, you can use the `is` attribute to enhance standard HTML tags.
113
+ Because ZUI supports **Customized Built-in Elements**, you can enhance standard tags:
113
114
 
114
115
  ```html
115
- <div id="counter" is="my-counter">
116
- <span slot="increase">+1</span>
117
- <span slot="decrease">-1</span>
118
- </div>
119
- ```
120
-
121
- ```typescript
122
- // main.ts
123
- const counterEl = document.querySelector<Counter>("#counter")!;
116
+ <div id="counter" is="my-counter"></div>
124
117
 
125
- // Listen to custom events
126
- counterEl.addEventListener("counter-click", (e: any) => {
127
- counterEl.count += e.detail.value.count;
128
- });
118
+ <script type="module">
119
+ import "./counter";
120
+
121
+ const el = document.querySelector("#counter");
122
+
123
+ // Listen to the strongly typed custom event
124
+ el.addEventListener("counter-click", (e) => {
125
+ el.count += e.detail.value.count;
126
+ });
127
+ </script>
129
128
  ```
130
129
 
131
130
  ---
@@ -133,35 +132,49 @@ counterEl.addEventListener("counter-click", (e: any) => {
133
132
  ## 📚 API Reference
134
133
 
135
134
  ### `@defineElement(config)`
136
- Class decorator that registers the custom element.
137
- * `tagName`: The kebab-case tag name.
138
- * `html`: Raw HTML string (Shadow DOM content).
139
- * `css`: Raw CSS/SCSS string.
140
- * `options`: Standard `ElementDefinitionOptions` (e.g., `{ extends: 'div' }`).
141
-
142
- ### `@property()`
143
- Property decorator applied to an `accessor`.
144
- * Automatically observes attributes.
145
- * Triggers a lifecycle hook named `[propertyName]Update(oldVal, newVal)` when changed.
146
- * Handles type conversion (String to Number/Boolean).
135
+ Class decorator to register the custom element.
136
+
137
+ * **tagName** `string`: The kebab-case tag name (e.g., `my-counter`).
138
+ * **html** `string`: Raw HTML string for the Shadow DOM.
139
+ * **css** `string`: (Optional) Raw CSS string.
140
+ * **options** `ElementDefinitionOptions`: (Optional) Used for `extends` (e.g., `{ extends: 'div' }`).
141
+
142
+ ### `@property(options)`
143
+ Decorator for class accessors. It handles attribute observation and type conversion.
144
+
145
+ * **type**: `"string" | "number" | "boolean"` (Auto-inferred from initial value if omitted).
146
+ * **name**: Attribute name (defaults to kebab-case of property name).
147
+ * **Lifecycle Hook**: When `myProp` changes, ZUI looks for a method named `myPropUpdate(oldVal, newVal)` and calls it.
147
148
 
148
149
  ### `@ref(selector)`
149
- Cache DOM queries to elements within your component's template.
150
- * `selector`: The CSS selector to find the element.
151
- * Eliminates repetitive `this.shadowRoot.querySelector` calls.
150
+ Field decorator to cache DOM queries.
151
+
152
+ * **selector** `string`: The CSS selector to find the element within the component's Shadow Root.
153
+ * Populates the property automatically after the component connects.
152
154
 
153
- ### `@event({ name })`
154
- Generates event emitters.
155
- * Creates a generic method `emit[Name]` on the instance (e.g., `emitCounterClick`).
156
- * Payloads passed to the emitter are available in `event.detail.value`.
155
+ ### `@event(config)`
156
+ Field decorator to generate event emitters.
157
+
158
+ * **name** `string`: The name of the custom event to dispatch.
159
+ * **Generates**: A method on the instance named `emit[PropertyName capitalized]`.
160
+ * **Payload**: Arguments passed to the emit method are available in `event.detail.value`.
157
161
 
158
162
  ---
159
163
 
160
- ## 💻 Tech Stack
164
+ ## 💻 Development
165
+
166
+ This project uses **Vite** and **TypeScript**.
167
+
168
+ ```bash
169
+ # Install dependencies
170
+ yarn install
171
+
172
+ # Start development server
173
+ yarn dev
161
174
 
162
- * **TypeScript (5.0+)**: Leveraging Stage 3 Decorators.
163
- * **Vite**: For blazing fast development and asset handling.
164
- * **SCSS**: For structured, nested styling.
175
+ # Build the library
176
+ yarn build
177
+ ```
165
178
 
166
179
  ---
167
180
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@o.z/zui",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Next-generation Web Component framework leveraging TypeScript Stage 3 standard decorators.",
5
5
  "homepage": "https://github.com/z-npm/zui#readme",
6
6
  "docs": "https://github.com/z-npm/zui#readme",
@@ -56,10 +56,10 @@
56
56
  "build": "tsc && vite build"
57
57
  },
58
58
  "devDependencies": {
59
- "@types/node": "^25.0.9",
59
+ "@types/node": "^25.0.10",
60
60
  "@z-code/vite-plugin-swc": "^0.5.5",
61
61
  "glob": "^13.0.0",
62
- "sass": "^1.97.2",
62
+ "sass": "^1.97.3",
63
63
  "typescript": "^5.9.3",
64
64
  "vite": "^7.3.1",
65
65
  "vite-plugin-dts": "^4.5.4",