@mintjamsinc/ichigojs 0.1.6 → 0.1.8

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.
package/README.md CHANGED
@@ -16,7 +16,9 @@ A simple and intuitive reactive framework. Lightweight, fast, and user-friendly
16
16
  - 📦 **Lightweight** - Minimal bundle size
17
17
  - 🚀 **High Performance** - Efficient batched updates via microtask queue
18
18
  - 💪 **TypeScript** - Written in TypeScript with full type support
19
- - 🎨 **Directives** - `v-if`, `v-for`, `v-show`, `v-bind`, `v-on`, `v-model`
19
+ - 🎨 **Directives** - `v-if`, `v-for`, `v-show`, `v-bind`, `v-on`, `v-model`, `v-resize`, `v-intersection`
20
+ - 📐 **Resize Observer** - Monitor element size changes with `v-resize` directive
21
+ - 👁️ **Intersection Observer** - Detect element visibility with `v-intersection` directive
20
22
 
21
23
  ## Installation
22
24
 
@@ -160,6 +162,97 @@ Event handling with modifiers:
160
162
 
161
163
  Supported modifiers: `.stop`, `.prevent`, `.capture`, `.self`, `.once`
162
164
 
165
+ **Event Handlers with Context:**
166
+
167
+ All event handlers receive the event as the first parameter and `$ctx` as the second parameter:
168
+
169
+ ```javascript
170
+ methods: {
171
+ handleClick(event, $ctx) {
172
+ // event - the DOM event object
173
+ // $ctx.element - the DOM element
174
+ // $ctx.vnode - the VNode instance
175
+ // $ctx.userData - Proxy-free storage
176
+ }
177
+ }
178
+ ```
179
+
180
+ #### v-resize
181
+
182
+ Monitor element size changes using ResizeObserver:
183
+
184
+ ```html
185
+ <div v-resize="onResize" class="resizable-box">
186
+ {{ width }}px × {{ height }}px
187
+ </div>
188
+ ```
189
+
190
+ ```javascript
191
+ methods: {
192
+ onResize(entries, $ctx) {
193
+ const entry = entries[0];
194
+ this.width = Math.round(entry.contentRect.width);
195
+ this.height = Math.round(entry.contentRect.height);
196
+
197
+ // Access element through $ctx
198
+ console.log('Element:', $ctx.element);
199
+ }
200
+ }
201
+ ```
202
+
203
+ **Features:**
204
+ - Native ResizeObserver API for efficient resize detection
205
+ - Automatic cleanup in destroy phase
206
+ - Access to element, VNode, and userData via `$ctx`
207
+
208
+ #### v-intersection
209
+
210
+ Detect element visibility using IntersectionObserver:
211
+
212
+ ```html
213
+ <div v-intersection="onIntersection" class="observable-box">
214
+ I'm {{ isVisible ? 'VISIBLE' : 'NOT VISIBLE' }}
215
+ </div>
216
+ ```
217
+
218
+ ```javascript
219
+ methods: {
220
+ onIntersection(entries, $ctx) {
221
+ const entry = entries[0];
222
+ this.isVisible = entry.isIntersecting;
223
+ this.intersectionRatio = entry.intersectionRatio;
224
+
225
+ // Access element through $ctx
226
+ console.log('Element:', $ctx.element);
227
+ }
228
+ }
229
+ ```
230
+
231
+ **With custom options:**
232
+
233
+ ```html
234
+ <div v-intersection="onIntersection"
235
+ :options.intersection="{threshold: 0.5, rootMargin: '0px'}">
236
+ Triggers at 50% visibility
237
+ </div>
238
+ ```
239
+
240
+ You can also use `:options` for generic options:
241
+
242
+ ```html
243
+ <div v-intersection="onIntersection"
244
+ :options="{threshold: 0.5}">
245
+ Observable content
246
+ </div>
247
+ ```
248
+
249
+ **Features:**
250
+ - Native IntersectionObserver API for efficient visibility detection
251
+ - Custom threshold and rootMargin options via `:options.intersection` or `:options`
252
+ - Automatic cleanup in destroy phase
253
+ - Perfect for lazy loading, infinite scroll, and animation triggers
254
+ - Access to element, VNode, and userData via `$ctx`
255
+
163
256
  #### Lifecycle Hooks
164
257
 
165
258
  Lifecycle hooks allow you to run code at specific stages of an element's lifecycle. Each hook receives a **lifecycle context** (`$ctx`) with access to the element, VNode, and userData storage.
@@ -182,8 +275,8 @@ Lifecycle hooks allow you to run code at specific stages of an element's lifecyc
182
275
  - `@mounted` - Called after the element is inserted into the DOM
183
276
  - `@update` - Called before the element is updated
184
277
  - `@updated` - Called after the element is updated
185
- - `@unmount` - Called before the element is removed from the DOM
186
- - `@unmounted` - Called after the element is removed from the DOM
278
+ - `@unmount` - Called before VNode cleanup begins
279
+ - `@unmounted` - Called after VNode cleanup is complete (element reference still available)
187
280
 
188
281
  **Lifecycle Context (`$ctx`):**
189
282
 
@@ -195,7 +288,7 @@ Every lifecycle hook receives a context object with:
195
288
 
196
289
  **userData Storage:**
197
290
 
198
- `$ctx.userData` is a safe space to store data associated with the element's lifecycle. It's not affected by Vue's reactive proxy system, making it perfect for storing third-party library instances.
291
+ `$ctx.userData` is a safe space to store data associated with the element's lifecycle. It's not affected by the reactive proxy system, making it perfect for storing third-party library instances.
199
292
 
200
293
  ```javascript
201
294
  methods: {
@@ -248,19 +341,19 @@ methods: {
248
341
  };
249
342
 
250
343
  $ctx.userData.set('myResource', resource);
251
- // resource.close() will be called automatically on unmount
344
+ // resource.close() will be called automatically during destroy phase
252
345
  }
253
346
  }
254
347
  ```
255
348
 
256
349
  **Cleanup Order:**
257
350
 
258
- 1. `@unmount` hook fires
351
+ 1. `@unmount` hook fires (element still in DOM)
259
352
  2. `userData` auto-cleanup (close() methods called)
260
- 3. Child nodes destroyed
353
+ 3. Child nodes destroyed recursively
261
354
  4. Dependencies unregistered
262
355
  5. Directive manager cleanup
263
- 6. `@unmounted` hook fires
356
+ 6. `@unmounted` hook fires (element removed from DOM, but reference still available in `$ctx.element`)
264
357
 
265
358
  **Works with v-if and v-for:**
266
359