Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
102 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// tslint:disable-next-line:export-just-namespace | ||
export = hybrids; | ||
export as namespace hybrids; | ||
|
||
declare namespace hybrids { | ||
interface Descriptor<E extends HTMLElement> { | ||
get?(host: E, lastValue: any): any; | ||
set?(host: E, value: any, lastValue: any): any; | ||
connect?(host: E, key: string, invalidate: Function): Function; | ||
observe?(host: E, value: any, lastValue: any): void; | ||
} | ||
|
||
type Property<E extends HTMLElement> = | ||
| string | ||
| number | ||
| boolean | ||
| null | ||
| undefined | ||
| any[] | ||
| Descriptor<E>; | ||
|
||
interface UpdateFunction<E extends HTMLElement> { | ||
(host: E, target?: HTMLElement): void; | ||
} | ||
|
||
interface RenderFunction<E extends HTMLElement> { | ||
(host: E) : UpdateFunction<E>; | ||
} | ||
|
||
type Hybrids<E extends HTMLElement> = | ||
{ render?: RenderFunction<E> | Property<E> } | ||
& { [property in keyof E]?: Property<E> | Descriptor<E>['get'] } | ||
|
||
interface MapOfHybridsOrConstructors { | ||
[tagName: string]: Hybrids<any> | typeof HTMLElement, | ||
} | ||
|
||
type MapOfConstructors<T> = { | ||
[tagName in keyof T]: typeof HTMLElement; | ||
} | ||
|
||
interface HybridElement<E extends HTMLElement> { | ||
new(): E; | ||
prototype: E; | ||
} | ||
|
||
/* Define */ | ||
|
||
function define<E extends HTMLElement>(tagName: string, hybridsOrConstructor: Hybrids<E> | typeof HTMLElement): HybridElement<E>; | ||
function define(mapOfHybridsOrConstructors: MapOfHybridsOrConstructors): MapOfConstructors<typeof mapOfHybridsOrConstructors>; | ||
|
||
/* Factories */ | ||
|
||
function property<E extends HTMLElement>(value: any, connect?: Descriptor<E>['connect']): Descriptor<E>; | ||
function parent<E extends HTMLElement>(hybridsOrFn: Hybrids<E> | ((hybrids: Hybrids<E>) => boolean)): Descriptor<E>; | ||
function children<E extends HTMLElement>(hybridsOrFn: (Hybrids<E> | ((hybrids: Hybrids<E>) => boolean)), options? : { deep?: boolean, nested?: boolean }): Descriptor<E>; | ||
function render<E extends HTMLElement>(fn: RenderFunction<E>, customOptions?: { shadowRoot?: boolean | object }): Descriptor<E>; | ||
|
||
/* Template Engine */ | ||
|
||
interface UpdateFunctionWithMethods<E extends HTMLElement> extends UpdateFunction<E> { | ||
define: (elements: MapOfHybridsOrConstructors) => this; | ||
key: (id: any) => this; | ||
style: (...styles: string[]) => this; | ||
} | ||
|
||
interface EventHandler<E extends HTMLElement> { | ||
(host: E, event?: Event) : any; | ||
} | ||
|
||
type TemplateItem<E extends HTMLElement> = | ||
| string | ||
| number | ||
| boolean | ||
| null | ||
| undefined | ||
| UpdateFunction<E>; | ||
|
||
type TemplateExpression<E extends HTMLElement> = TemplateItem<E> | EventHandler<E> | TemplateItem<E>[]; | ||
|
||
namespace html { | ||
function set<E extends HTMLElement>(propertyName: keyof E, value?: any): EventHandler<E>; | ||
function resolve<E extends HTMLElement>(promise: Promise<UpdateFunction<E>>, placeholder?: UpdateFunction<E>, delay?: number): UpdateFunction<E>; | ||
} | ||
|
||
function html<E extends HTMLElement>(parts: TemplateStringsArray, ...args: TemplateExpression<E>[]): UpdateFunctionWithMethods<E>; | ||
|
||
namespace svg { | ||
function set<E extends HTMLElement>(propertyName: keyof E, value?: any): EventHandler<E>; | ||
function resolve<E extends HTMLElement>(promise: Promise<UpdateFunction<E>>, placeholder?: UpdateFunction<E>, delay?: number) : UpdateFunction<E>; | ||
} | ||
|
||
function svg<E extends HTMLElement>(parts: TemplateStringsArray, ...args: TemplateExpression<E>[]): UpdateFunctionWithMethods<E>; | ||
} |