@zonetrix/shared 1.0.0 → 2.0.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 (2) hide show
  1. package/README.md +395 -0
  2. package/package.json +2 -1
package/README.md ADDED
@@ -0,0 +1,395 @@
1
+ # @zonetrix/shared
2
+
3
+ Shared types, utilities, and validation helpers for the Zonetrix seat map ecosystem.
4
+
5
+ ## Overview
6
+
7
+ `@zonetrix/shared` provides common type definitions, configuration utilities, and validation functions used across all Zonetrix packages. This package ensures type safety and consistency when working with seat map configurations.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install @zonetrix/shared
13
+ # or
14
+ yarn add @zonetrix/shared
15
+ # or
16
+ pnpm add @zonetrix/shared
17
+ ```
18
+
19
+ ## Features
20
+
21
+ - 📘 **TypeScript-first** - Comprehensive type definitions for all seat map entities
22
+ - ✅ **Validation** - Built-in configuration validation
23
+ - 🔧 **Utilities** - Helper functions for config manipulation
24
+ - 🎨 **Default Settings** - Pre-configured color schemes and settings
25
+ - 📦 **Zero dependencies** - Lightweight and fast
26
+
27
+ ## Type Definitions
28
+
29
+ ### Core Types
30
+
31
+ ```typescript
32
+ import {
33
+ SeatMapConfig,
34
+ SerializedSeat,
35
+ SerializedSection,
36
+ SerializedStage,
37
+ SeatState,
38
+ SeatShape,
39
+ ColorSettings,
40
+ } from '@zonetrix/shared';
41
+ ```
42
+
43
+ #### SeatState
44
+ ```typescript
45
+ type SeatState = 'available' | 'reserved' | 'selected' | 'unavailable';
46
+ ```
47
+
48
+ #### SeatShape
49
+ ```typescript
50
+ type SeatShape = 'circle' | 'square' | 'rounded-square';
51
+ ```
52
+
53
+ #### SerializedSeat
54
+ ```typescript
55
+ interface SerializedSeat {
56
+ id: string;
57
+ position: { x: number; y: number };
58
+ shape: SeatShape;
59
+ state: SeatState;
60
+ sectionName?: string;
61
+ rowLabel?: string;
62
+ columnLabel?: string;
63
+ seatNumber?: string;
64
+ price?: number;
65
+ }
66
+ ```
67
+
68
+ #### ColorSettings
69
+ ```typescript
70
+ interface ColorSettings {
71
+ canvasBackground: string;
72
+ stageColor: string;
73
+ seatAvailable: string;
74
+ seatReserved: string;
75
+ seatSelected: string;
76
+ seatUnavailable: string;
77
+ gridLines: string;
78
+ currency: string;
79
+ }
80
+ ```
81
+
82
+ #### SeatMapConfig
83
+ ```typescript
84
+ interface SeatMapConfig {
85
+ version: string;
86
+ metadata: {
87
+ name: string;
88
+ description?: string;
89
+ createdAt: string;
90
+ updatedAt: string;
91
+ venue?: string;
92
+ capacity?: number;
93
+ };
94
+ canvas: {
95
+ width: number;
96
+ height: number;
97
+ backgroundColor: string;
98
+ };
99
+ colors: ColorSettings;
100
+ seats: SerializedSeat[];
101
+ sections?: SerializedSection[];
102
+ stages?: SerializedStage[];
103
+ }
104
+ ```
105
+
106
+ ## Utilities
107
+
108
+ ### Configuration Management
109
+
110
+ #### createDefaultConfig
111
+ Creates a new seat map configuration with default values.
112
+
113
+ ```typescript
114
+ import { createDefaultConfig } from '@zonetrix/shared';
115
+
116
+ const config = createDefaultConfig('Grand Theater');
117
+ // Returns a complete SeatMapConfig with default settings
118
+ ```
119
+
120
+ #### updateConfigTimestamp
121
+ Updates the `updatedAt` timestamp in the configuration metadata.
122
+
123
+ ```typescript
124
+ import { updateConfigTimestamp } from '@zonetrix/shared';
125
+
126
+ const updatedConfig = updateConfigTimestamp(config);
127
+ ```
128
+
129
+ #### cloneConfig
130
+ Deep clones a seat map configuration.
131
+
132
+ ```typescript
133
+ import { cloneConfig } from '@zonetrix/shared';
134
+
135
+ const clonedConfig = cloneConfig(originalConfig);
136
+ ```
137
+
138
+ ### Seat State Management
139
+
140
+ #### applySeatStateOverrides
141
+ Applies seat state overrides (reserved/unavailable) to a configuration.
142
+
143
+ ```typescript
144
+ import { applySeatStateOverrides } from '@zonetrix/shared';
145
+
146
+ const updatedConfig = applySeatStateOverrides(
147
+ config,
148
+ ['A-1', 'A-2'], // reserved seats
149
+ ['B-5'] // unavailable seats
150
+ );
151
+ ```
152
+
153
+ #### getSelectedSeats
154
+ Extracts all selected seats from a configuration.
155
+
156
+ ```typescript
157
+ import { getSelectedSeats } from '@zonetrix/shared';
158
+
159
+ const selectedSeats = getSelectedSeats(config);
160
+ // Returns: SerializedSeat[]
161
+ ```
162
+
163
+ ### Statistics
164
+
165
+ #### calculateCapacity
166
+ Returns the total number of seats in the configuration.
167
+
168
+ ```typescript
169
+ import { calculateCapacity } from '@zonetrix/shared';
170
+
171
+ const totalSeats = calculateCapacity(config);
172
+ ```
173
+
174
+ #### calculateAvailableSeats
175
+ Returns the number of available seats.
176
+
177
+ ```typescript
178
+ import { calculateAvailableSeats } from '@zonetrix/shared';
179
+
180
+ const availableCount = calculateAvailableSeats(config);
181
+ ```
182
+
183
+ ### Import/Export
184
+
185
+ #### exportConfigAsJSON
186
+ Converts configuration to JSON string.
187
+
188
+ ```typescript
189
+ import { exportConfigAsJSON } from '@zonetrix/shared';
190
+
191
+ const jsonString = exportConfigAsJSON(config, true); // pretty print
192
+ ```
193
+
194
+ #### importConfigFromJSON
195
+ Parses JSON string into configuration object.
196
+
197
+ ```typescript
198
+ import { importConfigFromJSON } from '@zonetrix/shared';
199
+
200
+ const config = importConfigFromJSON(jsonString);
201
+ ```
202
+
203
+ #### downloadConfigAsFile
204
+ Downloads configuration as a JSON file (browser only).
205
+
206
+ ```typescript
207
+ import { downloadConfigAsFile } from '@zonetrix/shared';
208
+
209
+ downloadConfigAsFile(config, 'venue-config.json');
210
+ ```
211
+
212
+ ## Validation
213
+
214
+ ### validateSeatMapConfig
215
+ Validates a seat map configuration and returns detailed results.
216
+
217
+ ```typescript
218
+ import { validateSeatMapConfig } from '@zonetrix/shared';
219
+
220
+ const result = validateSeatMapConfig(config);
221
+
222
+ if (!result.valid) {
223
+ console.error('Validation errors:', result.errors);
224
+ }
225
+
226
+ if (result.warnings.length > 0) {
227
+ console.warn('Validation warnings:', result.warnings);
228
+ }
229
+ ```
230
+
231
+ **ValidationResult:**
232
+ ```typescript
233
+ interface ValidationResult {
234
+ valid: boolean;
235
+ errors: string[];
236
+ warnings: string[];
237
+ }
238
+ ```
239
+
240
+ ### Helper Functions
241
+
242
+ #### generateId
243
+ Generates a unique ID for seat map objects.
244
+
245
+ ```typescript
246
+ import { generateId } from '@zonetrix/shared';
247
+
248
+ const seatId = generateId('seat'); // e.g., "seat_1234567890_abc123def"
249
+ ```
250
+
251
+ #### formatDate
252
+ Formats a date for metadata fields.
253
+
254
+ ```typescript
255
+ import { formatDate } from '@zonetrix/shared';
256
+
257
+ const timestamp = formatDate(); // ISO 8601 format
258
+ const customDate = formatDate(new Date('2024-01-01'));
259
+ ```
260
+
261
+ ## Constants
262
+
263
+ ### DEFAULT_COLORS
264
+ Pre-configured default color scheme.
265
+
266
+ ```typescript
267
+ import { DEFAULT_COLORS } from '@zonetrix/shared';
268
+
269
+ console.log(DEFAULT_COLORS);
270
+ // {
271
+ // canvasBackground: '#1a1a1a',
272
+ // stageColor: '#808080',
273
+ // seatAvailable: '#2C2B30',
274
+ // seatReserved: '#FCEA00',
275
+ // seatSelected: '#3A7DE5',
276
+ // seatUnavailable: '#6b7280',
277
+ // gridLines: '#404040',
278
+ // currency: 'KD'
279
+ // }
280
+ ```
281
+
282
+ ## Usage Examples
283
+
284
+ ### Creating and Validating a Configuration
285
+
286
+ ```typescript
287
+ import {
288
+ createDefaultConfig,
289
+ validateSeatMapConfig,
290
+ SerializedSeat,
291
+ } from '@zonetrix/shared';
292
+
293
+ // Create a new configuration
294
+ const config = createDefaultConfig('Main Auditorium');
295
+
296
+ // Add seats
297
+ const seat: SerializedSeat = {
298
+ id: 'seat_001',
299
+ position: { x: 100, y: 100 },
300
+ shape: 'rounded-square',
301
+ state: 'available',
302
+ sectionName: 'Orchestra',
303
+ rowLabel: 'A',
304
+ columnLabel: '1',
305
+ seatNumber: 'A-1',
306
+ price: 50.00,
307
+ };
308
+
309
+ config.seats.push(seat);
310
+
311
+ // Validate
312
+ const validation = validateSeatMapConfig(config);
313
+ if (validation.valid) {
314
+ console.log('Configuration is valid!');
315
+ }
316
+ ```
317
+
318
+ ### Managing Seat States
319
+
320
+ ```typescript
321
+ import {
322
+ applySeatStateOverrides,
323
+ getSelectedSeats,
324
+ calculateAvailableSeats,
325
+ } from '@zonetrix/shared';
326
+
327
+ // Apply overrides from booking system
328
+ const updatedConfig = applySeatStateOverrides(
329
+ config,
330
+ bookedSeats,
331
+ maintenanceSeats
332
+ );
333
+
334
+ // Get statistics
335
+ const availableCount = calculateAvailableSeats(updatedConfig);
336
+ console.log(`${availableCount} seats available`);
337
+
338
+ // Get selected seats (for checkout)
339
+ const selectedSeats = getSelectedSeats(updatedConfig);
340
+ const totalPrice = selectedSeats.reduce((sum, seat) => sum + (seat.price || 0), 0);
341
+ ```
342
+
343
+ ### Export/Import Workflow
344
+
345
+ ```typescript
346
+ import {
347
+ exportConfigAsJSON,
348
+ importConfigFromJSON,
349
+ downloadConfigAsFile,
350
+ } from '@zonetrix/shared';
351
+
352
+ // Export to JSON string
353
+ const jsonString = exportConfigAsJSON(config);
354
+
355
+ // Save to file (browser)
356
+ downloadConfigAsFile(config, 'theater-layout.json');
357
+
358
+ // Import from JSON
359
+ const loadedConfig = importConfigFromJSON(jsonString);
360
+ ```
361
+
362
+ ## TypeScript Support
363
+
364
+ This package is written in TypeScript and includes full type definitions. All types are exported for use in your applications.
365
+
366
+ ```typescript
367
+ import type {
368
+ SeatMapConfig,
369
+ SerializedSeat,
370
+ SeatState,
371
+ ValidationResult,
372
+ } from '@zonetrix/shared';
373
+ ```
374
+
375
+ ## Related Packages
376
+
377
+ - **[@zonetrix/viewer](https://www.npmjs.com/package/@zonetrix/viewer)** - Lightweight React component for displaying seat maps
378
+
379
+ ## Contributing
380
+
381
+ Contributions are welcome! Please ensure all changes include appropriate type definitions and pass validation tests.
382
+
383
+ ## License
384
+
385
+ MIT
386
+
387
+ ## Author
388
+
389
+ Fahad Khan ([@fahadkhan1740](https://github.com/fahadkhan1740))
390
+
391
+ ## Links
392
+
393
+ - [npm Package](https://www.npmjs.com/package/@zonetrix/shared)
394
+ - [GitHub Repository](https://github.com/fahadkhan1740/seat-map-studio)
395
+ - [Documentation](https://github.com/fahadkhan1740/seat-map-studio#readme)
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@zonetrix/shared",
3
- "version": "1.0.0",
3
+ "version": "2.0.0",
4
4
  "description": "Shared types and utilities for seat-map-studio packages",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
7
7
  "types": "./dist/index.d.ts",
8
+ "sideEffects": false,
8
9
  "exports": {
9
10
  ".": {
10
11
  "import": "./dist/index.mjs",