@codesuma/baseline 1.0.7 → 1.0.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 +29 -44
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ npm install @codesuma/baseline
|
|
|
20
20
|
## Quick Start
|
|
21
21
|
|
|
22
22
|
```typescript
|
|
23
|
-
import { Div, Button, router } from '@
|
|
23
|
+
import { Div, Button, router } from '@codesuma/baseline'
|
|
24
24
|
|
|
25
25
|
const App = () => {
|
|
26
26
|
const app = Div()
|
|
@@ -51,7 +51,7 @@ document.body.appendChild(App().el)
|
|
|
51
51
|
Every component is created with the `Base()` factory:
|
|
52
52
|
|
|
53
53
|
```typescript
|
|
54
|
-
import { Base } from '
|
|
54
|
+
import { Base } from '@codesuma/baseline'
|
|
55
55
|
|
|
56
56
|
const card = Base('div') // Creates a <div>
|
|
57
57
|
card.el // The actual DOM element
|
|
@@ -61,7 +61,7 @@ card.id // Unique identifier
|
|
|
61
61
|
Or use pre-made native components:
|
|
62
62
|
|
|
63
63
|
```typescript
|
|
64
|
-
import { Div, Button, Input, Span, A, Img } from '
|
|
64
|
+
import { Div, Button, Input, Span, A, Img } from '@codesuma/baseline'
|
|
65
65
|
|
|
66
66
|
const container = Div('Hello')
|
|
67
67
|
const btn = Button('Click')
|
|
@@ -137,7 +137,7 @@ Use `.module.css` files for scoped, maintainable styles:
|
|
|
137
137
|
|
|
138
138
|
**card/index.ts**
|
|
139
139
|
```typescript
|
|
140
|
-
import { Div } from '
|
|
140
|
+
import { Div } from '@codesuma/baseline'
|
|
141
141
|
import styles from './index.module.css'
|
|
142
142
|
|
|
143
143
|
export const Card = () => {
|
|
@@ -244,8 +244,7 @@ Base includes a full-featured SPA router with page lifecycle management. Pages s
|
|
|
244
244
|
### Basic Setup
|
|
245
245
|
|
|
246
246
|
```typescript
|
|
247
|
-
import { Div } from '
|
|
248
|
-
import router from 'base/lib/router'
|
|
247
|
+
import { Div, router } from '@codesuma/baseline'
|
|
249
248
|
import { HomePage } from './pages/home'
|
|
250
249
|
import { AboutPage } from './pages/about'
|
|
251
250
|
import { UserPage } from './pages/user'
|
|
@@ -281,8 +280,9 @@ router.routes({
|
|
|
281
280
|
### How It Works
|
|
282
281
|
|
|
283
282
|
- All pages are created once and stay in DOM
|
|
284
|
-
- Navigation toggles visibility via CSS classes
|
|
283
|
+
- Navigation toggles visibility via CSS classes
|
|
285
284
|
- Smooth transitions because both pages exist during animation
|
|
285
|
+
- **Smart Directional Animations**: Automatically slides UP for forward navigation and DOWN for back navigation
|
|
286
286
|
- State preserved (scroll position, form inputs)
|
|
287
287
|
|
|
288
288
|
### Page Component
|
|
@@ -290,29 +290,29 @@ router.routes({
|
|
|
290
290
|
Base includes a `Page` component with built-in CSS transitions for smooth page navigation:
|
|
291
291
|
|
|
292
292
|
```typescript
|
|
293
|
-
import { Page } from '
|
|
294
|
-
import { IRouteEvent } from 'base/lib/router'
|
|
293
|
+
import { Page, IRouteEvent } from '@codesuma/baseline'
|
|
295
294
|
|
|
296
295
|
export const AboutPage = () => {
|
|
297
|
-
const page = Page() //
|
|
296
|
+
const page = Page() // Includes directional enter/exit animations
|
|
298
297
|
|
|
299
298
|
// Add your content
|
|
300
299
|
page.append(header, body)
|
|
301
300
|
|
|
302
|
-
//
|
|
301
|
+
// Default animations:
|
|
302
|
+
// Forward: Enter Up / Exit Up
|
|
303
|
+
// Back: Enter Down / Exit Down
|
|
303
304
|
return page
|
|
304
305
|
}
|
|
305
306
|
```
|
|
306
307
|
|
|
307
308
|
**Default animations:**
|
|
308
|
-
-
|
|
309
|
-
-
|
|
309
|
+
- Forward: Slides up from bottom
|
|
310
|
+
- Back: Slides down to bottom
|
|
310
311
|
|
|
311
312
|
### Customizing Page Transitions
|
|
312
313
|
|
|
313
314
|
```typescript
|
|
314
|
-
import { Page } from '
|
|
315
|
-
import { IRouteEvent } from 'base/lib/router'
|
|
315
|
+
import { Page, IRouteEvent } from '@codesuma/baseline'
|
|
316
316
|
|
|
317
317
|
export const HomePage = () => {
|
|
318
318
|
const page = Page()
|
|
@@ -320,24 +320,12 @@ export const HomePage = () => {
|
|
|
320
320
|
// Override default enter - show instantly
|
|
321
321
|
page.off('enter')
|
|
322
322
|
page.on('enter', async ({ from }: IRouteEvent) => {
|
|
323
|
-
page.showInstant()
|
|
323
|
+
page.showInstant() // Assuming you implemented this helper or use style overrides
|
|
324
324
|
// Load data...
|
|
325
325
|
})
|
|
326
326
|
|
|
327
327
|
return page
|
|
328
328
|
}
|
|
329
|
-
|
|
330
|
-
export const AboutPage = () => {
|
|
331
|
-
const page = Page()
|
|
332
|
-
|
|
333
|
-
// Custom exit - slide DOWN instead of up (for back navigation)
|
|
334
|
-
page.off('exit')
|
|
335
|
-
page.on('exit', async () => {
|
|
336
|
-
await page.exitDown()
|
|
337
|
-
})
|
|
338
|
-
|
|
339
|
-
return page
|
|
340
|
-
}
|
|
341
329
|
```
|
|
342
330
|
|
|
343
331
|
**Page methods:**
|
|
@@ -365,7 +353,7 @@ page.on('exit', async () => {
|
|
|
365
353
|
### Navigation
|
|
366
354
|
|
|
367
355
|
```typescript
|
|
368
|
-
import router from '
|
|
356
|
+
import { router } from '@codesuma/baseline'
|
|
369
357
|
|
|
370
358
|
// Navigate to path
|
|
371
359
|
router.goto('/about')
|
|
@@ -432,9 +420,8 @@ router.on('change', ({ path, params, query, from, data }) => {
|
|
|
432
420
|
|
|
433
421
|
```typescript
|
|
434
422
|
// app.ts
|
|
435
|
-
import { Div } from '
|
|
436
|
-
import
|
|
437
|
-
import { FIXED, EASE } from './base/helpers/style'
|
|
423
|
+
import { Div, router } from '@codesuma/baseline'
|
|
424
|
+
import { FIXED, EASE } from '@codesuma/baseline/helpers/style' // specialized helpers might still need specific paths if not all exported, but index.ts didn't show helpers/style exported. Let's check index.ts again.
|
|
438
425
|
import { HomePage } from './pages/home'
|
|
439
426
|
import { AboutPage } from './pages/about'
|
|
440
427
|
import { UserPage } from './pages/user'
|
|
@@ -468,8 +455,7 @@ export default app
|
|
|
468
455
|
|
|
469
456
|
```typescript
|
|
470
457
|
// pages/user/index.ts
|
|
471
|
-
import { Div } from '
|
|
472
|
-
import http from '../../base/lib/http'
|
|
458
|
+
import { Div, http } from '@codesuma/baseline'
|
|
473
459
|
|
|
474
460
|
export const UserPage = () => {
|
|
475
461
|
const page = Div()
|
|
@@ -493,7 +479,7 @@ export const UserPage = () => {
|
|
|
493
479
|
Built-in fetch wrapper with request deduplication:
|
|
494
480
|
|
|
495
481
|
```typescript
|
|
496
|
-
import http from '
|
|
482
|
+
import { http } from '@codesuma/baseline'
|
|
497
483
|
|
|
498
484
|
// GET (automatically deduplicated - same URL = same request)
|
|
499
485
|
const { status, data } = await http.get('/api/users')
|
|
@@ -520,7 +506,7 @@ await http.upload('/api/upload', file, {
|
|
|
520
506
|
### localStorage
|
|
521
507
|
|
|
522
508
|
```typescript
|
|
523
|
-
import ldb from '
|
|
509
|
+
import { ldb } from '@codesuma/baseline'
|
|
524
510
|
|
|
525
511
|
ldb.set('user', { name: 'John' }) // Auto JSON stringify
|
|
526
512
|
ldb.get('user') // Auto JSON parse
|
|
@@ -531,9 +517,9 @@ ldb.clear()
|
|
|
531
517
|
### IndexedDB
|
|
532
518
|
|
|
533
519
|
```typescript
|
|
534
|
-
import
|
|
520
|
+
import { idb } from '@codesuma/baseline'
|
|
535
521
|
|
|
536
|
-
const db =
|
|
522
|
+
const db = idb('my-app')
|
|
537
523
|
|
|
538
524
|
// Create store (run once on app init)
|
|
539
525
|
await db.createStore('users', 1, { keyPath: 'id', indices: ['email'] })
|
|
@@ -557,7 +543,7 @@ const results = await db.find('users', {
|
|
|
557
543
|
### Global State
|
|
558
544
|
|
|
559
545
|
```typescript
|
|
560
|
-
import state from '
|
|
546
|
+
import { state } from '@codesuma/baseline'
|
|
561
547
|
|
|
562
548
|
// Simple get/set
|
|
563
549
|
state.set('user', { name: 'John', id: 123 })
|
|
@@ -579,7 +565,7 @@ state.on('change', ({ key, value }) => {
|
|
|
579
565
|
### Style Helpers
|
|
580
566
|
|
|
581
567
|
```typescript
|
|
582
|
-
import { ABSOLUTE, FIXED,
|
|
568
|
+
import { ABSOLUTE, FIXED, EASE, WH, Y, CENTER } from '@codesuma/baseline/helpers/style'
|
|
583
569
|
|
|
584
570
|
card.style({ ...ABSOLUTE }) // position: absolute; inset: 0;
|
|
585
571
|
card.style({ ...CENTER }) // display: flex; align-items: center; justify-content: center;
|
|
@@ -591,8 +577,7 @@ card.style({ ...Y(-10) }) // transform: translateY(-10px);
|
|
|
591
577
|
### Ripple Effect
|
|
592
578
|
|
|
593
579
|
```typescript
|
|
594
|
-
import { withRipple } from '
|
|
595
|
-
import { Button } from 'base/components/native/button'
|
|
580
|
+
import { withRipple, Button } from '@codesuma/baseline'
|
|
596
581
|
|
|
597
582
|
const btn = withRipple(Button('Click me'))
|
|
598
583
|
// Now has Material Design ripple effect on click/touch
|
|
@@ -601,7 +586,7 @@ const btn = withRipple(Button('Click me'))
|
|
|
601
586
|
### Device Detection
|
|
602
587
|
|
|
603
588
|
```typescript
|
|
604
|
-
import { isMobile, isTouch
|
|
589
|
+
import { isMobile, isTouch } from '@codesuma/baseline/helpers/device'
|
|
605
590
|
|
|
606
591
|
if (isMobile()) { /* mobile layout */ }
|
|
607
592
|
if (isTouch()) { /* touch interactions */ }
|
|
@@ -610,7 +595,7 @@ if (isTouch()) { /* touch interactions */ }
|
|
|
610
595
|
### Validation
|
|
611
596
|
|
|
612
597
|
```typescript
|
|
613
|
-
import { isEmail
|
|
598
|
+
import { isEmail } from '@codesuma/baseline/helpers/regex'
|
|
614
599
|
|
|
615
600
|
if (isEmail(input.value())) { /* valid */ }
|
|
616
601
|
```
|
package/package.json
CHANGED