cally 0.2.0 → 0.4.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.
package/README.md CHANGED
@@ -19,19 +19,30 @@ npm install cally
19
19
 
20
20
  ## Usage
21
21
 
22
+ ### Via module
23
+
22
24
  ```js
23
25
  import "cally";
24
26
  ```
25
27
 
26
- ## Usage with CDN
28
+ ### Via CDN
29
+
30
+ ```html
31
+ <script type="module" src="https://unpkg.com/cally"></script>
32
+ ```
33
+
34
+ ### Using the components
27
35
 
28
36
  ```html
29
- <script src="https://unpkg.com/cally"></script>
37
+ <calendar-range months="2">
38
+ <calendar-month></calendar-month>
39
+ <calendar-month offset="1"></calendar-month>
40
+ </calendar-range>
30
41
  ```
31
42
 
32
43
  ## Docs
33
44
 
34
- Coming soon.
45
+ For full documentation, visit: https://wicky.nillia.ms/cally/
35
46
 
36
47
  ## License
37
48
 
@@ -0,0 +1,575 @@
1
+ declare interface Atomico<Props, PropsForInstance, Base>
2
+ extends AtomicoStatic<Props> {
3
+ new (
4
+ props?: JSXProxy<
5
+ DOMTag<DOMThis<Base>, Props>,
6
+ AtomicoThis<PropsForInstance, Base>
7
+ >
8
+ ): AtomicoThis<PropsForInstance, Base>;
9
+ }
10
+
11
+ declare interface AtomicoStatic<Props> extends HTMLElement {
12
+ styles: Sheets[];
13
+ props: SchemaInfer<Props>;
14
+ /**
15
+ * Meta property, allows associating the component's
16
+ * props in typescript to external environments.
17
+ */
18
+ readonly "##props": Props;
19
+ /**
20
+ * Allows to identify a constructor created with Atomico
21
+ */
22
+ readonly "##atomico": true;
23
+ }
24
+
25
+ declare type AtomicoThis<Props = {}, Base = HTMLElement> = Props &
26
+ DOMThis<Base> & {
27
+ update(): Promise<void>;
28
+ updated: Promise<void>;
29
+ mounted: Promise<void>;
30
+ unmounted: Promise<void>;
31
+ readonly symbolId: unique symbol;
32
+ };
33
+
34
+ export declare const CalendarDate: Atomico<{
35
+ months: number;
36
+ value: string;
37
+ firstDayOfWeek: DaysOfWeek;
38
+ isDateDisallowed: (date: Date) => boolean;
39
+ min: string;
40
+ max: string;
41
+ locale: string | undefined;
42
+ onFocusDay: (event: CustomEvent<Date>) => any;
43
+ showOutsideDays: boolean;
44
+ onChange: (event: Event) => any;
45
+ } & {}, {
46
+ months: number;
47
+ value: string;
48
+ firstDayOfWeek: DaysOfWeek;
49
+ isDateDisallowed: (date: Date) => boolean;
50
+ min: string;
51
+ max: string;
52
+ locale: string | undefined;
53
+ onFocusDay: (event: CustomEvent<Date>) => any;
54
+ showOutsideDays: boolean;
55
+ onChange: (event: Event) => any;
56
+ } & {}, {
57
+ new (): HTMLElement;
58
+ prototype: HTMLElement;
59
+ }>;
60
+
61
+ export declare type CalendarDateProps = ComponentProps<typeof CalendarDate>;
62
+
63
+ export declare const CalendarMonth: Atomico<{
64
+ offset: number;
65
+ onSelectDay: (event: CustomEvent<string>) => any;
66
+ onFocusDay: (event: CustomEvent<string>) => any;
67
+ onHoverDay: (event: CustomEvent<string>) => any;
68
+ } & {}, {
69
+ offset: number;
70
+ onSelectDay: (event: CustomEvent<string>) => any;
71
+ onFocusDay: (event: CustomEvent<string>) => any;
72
+ onHoverDay: (event: CustomEvent<string>) => any;
73
+ } & {}, {
74
+ new (): HTMLElement;
75
+ prototype: HTMLElement;
76
+ }>;
77
+
78
+ export declare type CalendarMonthProps = ComponentProps<typeof CalendarMonth>;
79
+
80
+ export declare const CalendarRange: Atomico<{
81
+ months: number;
82
+ value: string;
83
+ firstDayOfWeek: DaysOfWeek;
84
+ isDateDisallowed: (date: Date) => boolean;
85
+ min: string;
86
+ max: string;
87
+ locale: string | undefined;
88
+ onFocusDay: (event: CustomEvent<Date>) => any;
89
+ showOutsideDays: boolean;
90
+ onChange: (event: Event) => any;
91
+ onRangeStart: (event: CustomEvent<Date>) => any;
92
+ onRangeEnd: (event: CustomEvent<Date>) => any;
93
+ } & {}, {
94
+ months: number;
95
+ value: string;
96
+ firstDayOfWeek: DaysOfWeek;
97
+ isDateDisallowed: (date: Date) => boolean;
98
+ min: string;
99
+ max: string;
100
+ locale: string | undefined;
101
+ onFocusDay: (event: CustomEvent<Date>) => any;
102
+ showOutsideDays: boolean;
103
+ onChange: (event: Event) => any;
104
+ onRangeStart: (event: CustomEvent<Date>) => any;
105
+ onRangeEnd: (event: CustomEvent<Date>) => any;
106
+ } & {}, {
107
+ new (): HTMLElement;
108
+ prototype: HTMLElement;
109
+ }>;
110
+
111
+ export declare type CalendarRangeProps = ComponentProps<typeof CalendarRange>;
112
+
113
+ declare type CheckEvent<CurrentEvent, True> = CurrentEvent extends Event ? True : never;
114
+
115
+ declare type ComponentProps<T extends abstract new (...args: any) => any> = Simplify<Partial<Omit<InstanceType<T>, keyof HTMLElement | keyof AtomicoThis>>>;
116
+
117
+ declare type DaysOfWeek = 0 | 1 | 2 | 3 | 4 | 5 | 6;
118
+
119
+ declare interface DOM$Attrs {
120
+ [prop: `\$${string}`]: Nullable<string>;
121
+ }
122
+
123
+ declare type DOMCleanKeys =
124
+ | keyof DOMGenericProperties
125
+ | `add${string}`
126
+ | `get${string}`
127
+ | `set${string}`
128
+ | `has${string}`
129
+ | `matches${string}`
130
+ | `remove${string}`
131
+ | `replace${string}`
132
+ | `querySelector${string}`
133
+ | `offset${string}`
134
+ | `append${string}`
135
+ | `request${string}`
136
+ | `scroll${string}`
137
+ | `is${string}`
138
+ | `toggle${string}`
139
+ | `webkit${string}`
140
+ | `insert${string}`
141
+ | `client${string}`
142
+ | `child${string}`
143
+ | `${string}_${string}`
144
+ | `${string}HTML`
145
+ | `${string}Child`
146
+ | `${string}Validity`
147
+ | `${string}Capture`
148
+ | `${string}ElementSibling`
149
+ | "classList"
150
+ | "attributes"
151
+ | "normalize"
152
+ | "closest"
153
+ | "localName"
154
+ | "contains"
155
+ | "animate"
156
+ | "attachShadow"
157
+ | "outerText"
158
+ | "attachInternals"
159
+ | "click"
160
+ | "tagName"
161
+ | "focus"
162
+ | "submit"
163
+ | "accessKeyLabel"
164
+ | "elements"
165
+ | "isContentEditable"
166
+ | "innerText"
167
+ | "prepend"
168
+ | "namespaceURI"
169
+ | "blur"
170
+ | "dataset"
171
+ | "shadowRoot"
172
+ | keyof Omit<ChildNode, "textContent">;
173
+
174
+ declare type DOMCustomTarget<Target> = { customTarget: Target };
175
+
176
+ declare type DOMEvent<
177
+ Target = HTMLElement,
178
+ CurrentEvent = Event
179
+ > = Target extends string
180
+ ? CurrentEvent extends AtomicoStatic<any>
181
+ ? DOMGetEvent<Target, CurrentEvent>
182
+ : DOMEventType<Target, CurrentEvent>
183
+ : DOMTarget<DOMThis<Target>, CurrentEvent>;
184
+
185
+ declare type DOMEventHandler<Target, Handler> = Handler extends (
186
+ ev: infer CurrentEvent
187
+ ) => any
188
+ ? CurrentEvent extends Event
189
+ ? (ev: DOMEvent<Target, CurrentEvent>) => any
190
+ : Handler
191
+ : Handler;
192
+
193
+ /**
194
+ * @todo Rename Handler to Listener
195
+ */
196
+
197
+ declare type DOMEventHandlerKeys<P> = {
198
+ [I in keyof P]-?: NonNullable<P[I]> extends DOMEventHandlerValue<infer E>
199
+ ? CheckEvent<E, I>
200
+ : P[I] extends { value: DOMEventHandlerValue<infer E> }
201
+ ? CheckEvent<E, I>
202
+ : never;
203
+ }[keyof P];
204
+
205
+ declare interface DOMEventHandlerType extends FunctionConstructor {}
206
+
207
+ declare interface DOMEventHandlerValue<CurrentEvent> {
208
+ (event: CurrentEvent): any;
209
+ }
210
+
211
+ declare type DOMEvents<Target> = {
212
+ [Prop in keyof Target]?: Prop extends `on${string}`
213
+ ? DOMEventHandler<Target, Target[Prop]>
214
+ : Target[Prop];
215
+ };
216
+
217
+ declare type DOMEventTarget<CurrentEvent, CurrentTarget, Target> = {
218
+ [I in keyof CurrentEvent]: I extends "currentTarget"
219
+ ? CurrentTarget
220
+ : I extends "target"
221
+ ? Target
222
+ : CurrentEvent[I];
223
+ };
224
+
225
+ declare type DOMEventType<Type extends string, CurrentEvent> = {
226
+ [I in keyof "0" as `on${Type}`]: {
227
+ type: DOMEventHandlerType;
228
+ value: DOMEventHandlerValue<CurrentEvent>;
229
+ };
230
+ };
231
+
232
+ declare interface DOMGenericProperties {
233
+ style?: string | Partial<CSSStyleDeclaration> | object;
234
+ class?: string;
235
+ id?: string;
236
+ slot?: string;
237
+ part?: string;
238
+ is?: string;
239
+ tabindex?: string | number;
240
+ role?: string;
241
+ shadowDom?: boolean | Partial<ShadowRootInit>;
242
+ staticNode?: boolean;
243
+ cloneNode?: boolean;
244
+ width?: string | number;
245
+ height?: string | number;
246
+ key?: any;
247
+ children?: any;
248
+ }
249
+
250
+ declare type DOMGetEvent<
251
+ Type extends string,
252
+ Element extends AtomicoStatic<any>
253
+ > = Element extends {
254
+ "##props": infer Props;
255
+ }
256
+ ? `on${Type}` extends keyof Props
257
+ ? DOMGetEventBefore<NonNullable<Props[`on${Type}`]>, DOMThis<Element>>
258
+ : Event
259
+ : Event;
260
+
261
+ declare type DOMGetEventBefore<Value, Target> = Value extends DOMEventHandlerValue<
262
+ infer Event
263
+ >
264
+ ? DOMEvent<HTMLElement, Event & DOMCustomTarget<Target>>
265
+ : null;
266
+
267
+ declare type DOMRef<Target> = {
268
+ ref?: DOMRefValue<Target>;
269
+ };
270
+
271
+ declare type DOMRefValue<Target> = FillObject | ((target: Target) => any);
272
+
273
+ declare type DOMTag<Element, Props = null> = Props extends null
274
+ ? PropsNullable<
275
+ Omit<DOMEvents<Element>, DOMCleanKeys> &
276
+ DOMGenericProperties &
277
+ DOMRef<Element>
278
+ > &
279
+ DOM$Attrs &
280
+ DOMUnknown
281
+ : PropsNullable<
282
+ Props &
283
+ Omit<DOMEvents<Element & Props>, keyof Props | DOMCleanKeys> &
284
+ DOMGenericProperties &
285
+ DOMRef<Element & Props>
286
+ > &
287
+ DOM$Attrs &
288
+ DOMUnknown;
289
+
290
+ declare type DOMTarget<
291
+ Target,
292
+ CurrentEvent,
293
+ Targets = Element | Node
294
+ > = CurrentEvent extends {
295
+ customTarget: infer EventTarget;
296
+ }
297
+ ? DOMTarget<Target, Omit<CurrentEvent, "customTarget">, EventTarget>
298
+ : DOMEventTarget<CurrentEvent, Target, Targets>;
299
+
300
+ declare type DOMThis<Element> = Element extends new (
301
+ ...args: any[]
302
+ ) => infer This
303
+ ? This
304
+ : Element;
305
+
306
+ declare interface DOMUnknown {
307
+ [prop: string]: any;
308
+ }
309
+
310
+ declare type EventInit_2 = CustomEventInit<any> & {
311
+ type: string;
312
+ base?: typeof CustomEvent | typeof Event;
313
+ };
314
+
315
+ declare type FillArray = any[];
316
+
317
+ declare type FillConstructor = abstract new (...args: any) => any;
318
+
319
+ declare type FillFunction = (...args: any[]) => any;
320
+
321
+ /**
322
+ * Interface to fill in unknown properties like any | null | undefined
323
+ */
324
+ declare interface FillObject {
325
+ [index: string]: any;
326
+ }
327
+
328
+ declare type FillPromise = Promise<any>;
329
+
330
+ declare type GetTypeSelf<value extends TypesSelfValues> = {
331
+ [I in keyof SelfConstructors]-?: value extends InstanceType<
332
+ SelfConstructors[I]
333
+ >
334
+ ? keyof value extends keyof InstanceType<SelfConstructors[I]>
335
+ ? SelfConstructors[I]
336
+ : never
337
+ : never;
338
+ }[keyof SelfConstructors];
339
+
340
+ declare type JSXProxy<Props, This> = {
341
+ [I in keyof Props]?: I extends `on${string}`
342
+ ? NonNullable<Props[I]> extends DOMEventHandlerValue<infer CurrentEvent>
343
+ ? Nullable<
344
+ (
345
+ ev: DOMEventTarget<CurrentEvent, This, Element | Node>
346
+ ) => any
347
+ >
348
+ : Props[I]
349
+ : I extends "ref"
350
+ ? DOMRefValue<This>
351
+ : Props[I];
352
+ };
353
+
354
+ declare type Nullable<T> = NonNullable<T> | undefined | null;
355
+
356
+ declare type PropsNullable<Data> = {
357
+ [I in keyof Data]?: Nullable<Data[I]>;
358
+ };
359
+
360
+ declare type SafeGlobal =
361
+ | "Event"
362
+ | "URL"
363
+ | "Range"
364
+ | "Image"
365
+ | "Crypto"
366
+ | "File"
367
+ | "Date"
368
+ | "Set"
369
+ | "Map"
370
+ | "RegExp"
371
+ | "Animation"
372
+ | `${string}Event`
373
+ | `Event${string}`
374
+ | `Clipboard${string}`
375
+ | `Animation${string}`
376
+ | `Form${string}`
377
+ | `Font${string}`
378
+ | `DOM${string}`
379
+ | `Touch${string}`
380
+ | `Mutation${string}`
381
+ | `Intersection${string}`
382
+ | `Message${string}`
383
+ | `HTML${string}`
384
+ | `SVG${string}`
385
+ | `Audio${string}`
386
+ | `Document${string}`
387
+ | `Weak${string}`
388
+ | `CSS${string}`
389
+ | `File${string}`;
390
+
391
+ declare type SchemaAny<Type> =
392
+ | SchemaReflect<{
393
+ value: Type;
394
+ }>
395
+ | SchemaReflect<{
396
+ value: () => Type;
397
+ }>
398
+ | SchemaReflect<{}>;
399
+
400
+ declare type SchemaBase = SchemaEvent & {
401
+ attr?: string;
402
+ };
403
+
404
+ declare type SchemaEvent = {
405
+ event?: EventInit_2;
406
+ };
407
+
408
+ declare type SchemaInfer<Props> = Required<
409
+ Omit<
410
+ {
411
+ [I in keyof Props]: Type<Props[I]>;
412
+ },
413
+ DOMEventHandlerKeys<Props>
414
+ >
415
+ >;
416
+
417
+ declare type SchemaOnlyPropWrapper<Constructor, Type> =
418
+ | SchemaProp<{
419
+ type: Constructor;
420
+ }>
421
+ | SchemaProp<{
422
+ type: Constructor;
423
+ value: Type;
424
+ }>
425
+ | SchemaProp<{
426
+ type: Constructor;
427
+ value: () => Type;
428
+ }>;
429
+
430
+ declare type SchemaProp<type> = SchemaEvent & type;
431
+
432
+ declare type SchemaReflect<type> = SchemaBase & {
433
+ reflect?: boolean;
434
+ } & type;
435
+
436
+ declare type SchemaReflectWrapper<Constructor, Type> =
437
+ | SchemaReflect<{
438
+ type: Constructor;
439
+ }>
440
+ | SchemaReflect<{
441
+ type: Constructor;
442
+ value: Type;
443
+ }>
444
+ | SchemaReflect<{
445
+ type: Constructor;
446
+ value: () => Type;
447
+ }>;
448
+
449
+ declare type SchemaTypeCustom =
450
+ | TypeCustom<FillFunction>
451
+ | SchemaReflectWrapper<TypeCustom<FillFunction>, any>;
452
+
453
+ declare type Self = typeof window;
454
+
455
+ declare type SelfConstructors = Pick<
456
+ Self,
457
+ {
458
+ [I in keyof Self]-?: I extends string
459
+ ? I extends Capitalize<I>
460
+ ? Self[I] extends FillConstructor
461
+ ? Self[I] extends SelfIgnore
462
+ ? never
463
+ : I extends SafeGlobal
464
+ ? I
465
+ : never
466
+ : never
467
+ : never
468
+ : never;
469
+ }[keyof Self]
470
+ >;
471
+
472
+ declare type SelfIgnore =
473
+ | StringConstructor
474
+ | NumberConstructor
475
+ | BooleanConstructor
476
+ | FunctionConstructor
477
+ | ObjectConstructor
478
+ | PromiseConstructor
479
+ | SymbolConstructor
480
+ | ArrayConstructor;
481
+
482
+ declare type Sheet = CSSStyleSheet | HTMLStyleElement;
483
+
484
+ declare type Sheets = Sheet | Sheet[] | Sheets[];
485
+
486
+ declare type Simplify<T> = {
487
+ [K in keyof T]: T[K];
488
+ } & {};
489
+
490
+ declare type Type<type> = type extends string
491
+ ? TypeString<type>
492
+ : type extends number
493
+ ? TypeNumber<type>
494
+ : type extends boolean
495
+ ? TypeBoolean
496
+ : type extends TypeCustom<FillFunction>
497
+ ? SchemaTypeCustom
498
+ : type extends FillPromise
499
+ ? TypePromise<type>
500
+ : type extends symbol
501
+ ? TypeSymbol<type>
502
+ : type extends FillArray
503
+ ? TypeArray<type>
504
+ : type extends DOMStringMap
505
+ ? TypeObject<type>
506
+ : type extends TypesSelfValues
507
+ ? GetTypeSelf<type> extends never
508
+ ? TypesDiscard<type>
509
+ : TypeConstructor<GetTypeSelf<type>>
510
+ : TypesDiscard<type>;
511
+
512
+ declare type TypeAny<type = any> = null | SchemaAny<type>;
513
+
514
+ declare type TypeArray<type extends FillArray> =
515
+ | ArrayConstructor
516
+ | SchemaReflectWrapper<ArrayConstructor, type>;
517
+
518
+ declare type TypeBoolean =
519
+ | BooleanConstructor
520
+ | SchemaReflectWrapper<BooleanConstructor, true | false>;
521
+
522
+ declare type TypeConstructor<type extends FillConstructor> =
523
+ | type
524
+ | SchemaOnlyPropWrapper<type, InstanceType<type>>;
525
+
526
+ declare type TypeCustom<Map extends FillFunction> = {
527
+ name: "Custom";
528
+ map: Map;
529
+ serialize?: (value: ReturnType<Map>) => string;
530
+ };
531
+
532
+ declare type TypeFunction<type extends FillFunction> =
533
+ | FunctionConstructor
534
+ | SchemaOnlyPropWrapper<FunctionConstructor, type>;
535
+
536
+ declare type TypeNumber<type extends number> =
537
+ | NumberConstructor
538
+ | SchemaReflectWrapper<NumberConstructor, type>;
539
+
540
+ declare type TypeObject<type extends FillObject> =
541
+ | ObjectConstructor
542
+ | SchemaReflectWrapper<ObjectConstructor, type>;
543
+
544
+ declare type TypePromise<type extends FillPromise> =
545
+ | PromiseConstructor
546
+ | SchemaOnlyPropWrapper<PromiseConstructor, type>;
547
+
548
+ declare type TypesDiscard<type> = type extends FillFunction
549
+ ? TypeFunction<type>
550
+ : type extends FillObject
551
+ ? TypeObject<type>
552
+ : TypeAny<type>;
553
+
554
+ declare type TypesSelfValues = {
555
+ [I in keyof SelfConstructors]-?: InstanceType<SelfConstructors[I]>;
556
+ }[keyof SelfConstructors];
557
+
558
+ declare type TypeString<type extends string> =
559
+ | StringConstructor
560
+ | SchemaReflectWrapper<StringConstructor, type>;
561
+
562
+ declare type TypeSymbol<type extends symbol> =
563
+ | SymbolConstructor
564
+ | SchemaOnlyPropWrapper<SymbolConstructor, type>;
565
+
566
+ export { }
567
+ // this is just a hacky workaround to ensure the global declarations make it into the dts rollup
568
+ // they get appended to the end of the file on vite build
569
+ declare global {
570
+ interface HTMLElementTagNameMap {
571
+ "calendar-month": InstanceType<typeof CalendarMonth>;
572
+ "calendar-date": InstanceType<typeof CalendarDate>;
573
+ "calendar-range": InstanceType<typeof CalendarRange>;
574
+ }
575
+ }