/** * @see https://www.w3.org/TR/wai-aria-1.1/#state_prop_def */ interface AriaAttrs { "aria-activedescendant": string; "aria-atomic": string; "aria-autocomplete": string; "aria-busy": string; "aria-checked": string; "aria-colcount": string; "aria-colindex": string; "aria-colspan": string; "aria-controls": string; "aria-current": string; "aria-describedby": string; "aria-details": string; "aria-disabled": string; "aria-dropeffect": string; "aria-errormessage": string; "aria-expanded": string; "aria-flowto": string; "aria-grabbed": string; "aria-haspopup": string; "aria-hidden": string; "aria-invalid": string; "aria-keyshortcuts": string; "aria-label": string; "aria-labelledby": string; "aria-level": string; "aria-live": string; "aria-modal": string; "aria-multiline": string; "aria-multiselectable": string; "aria-orientation": string; "aria-owns": string; "aria-placeholder": string; "aria-posinset": string; "aria-pressed": string; "aria-readonly": string; "aria-relevant": string; "aria-required": string; "aria-roledescription": string; "aria-rowcount": string; "aria-rowindex": string; "aria-rowspan": string; "aria-selected": string; "aria-setsize": string; "aria-sort": string; "aria-valuemax": string; "aria-valuemin": string; "aria-valuenow": string; "aria-valuetext": string; } interface HTMLProps { style: string | Partial | object; class: string; id: string; slot: string; is: string; tabindex: string | number; role: string; shadowDom: boolean; width: string | number; height: string | number; children: any; [indes: string]: any; } type Tag = Partial & Partial & Partial & Partial< Omit< T, "style" | "children" | "width" | "height" | "viewBox" | "transform" > >; type SVGMapElements = Omit; /**@todo associate to specific constructor */ interface SVGProps { d: string | number; //path x: string | number; y: string | number; r: string | number; cx: string | number; cy: string | number; x1: string | number; x2: string | number; y1: string | number; y2: string | number; systemLanguage: string; // switch fill: string; gradientTransform: string; // linearGradient offset: string; // linearGradient points: string | number[]; } type SVGElementsTagMap = { [K in keyof SVGMapElements]: Omit & SVGProps; }; type TagMaps = HTMLElementTagNameMap & SVGElementsTagMap & HTMLElementDeprecatedTagNameMap & { host: Tag<{ shadowDom: boolean }>; }; /** * The behavior of the Vdom is not strict, so you opt for a dynamic statement */ interface Vdom { type: T; props: P; children: any[]; readonly key?: any; readonly shadow?: boolean; readonly raw?: boolean; } declare module "atomico/html" { export function html( strings: TemplateStringsArray, ...values: any[] ): Vdom; export default html; } declare module "atomico" { type TypeAny = null; /** * Types supported by Atomico. */ type Types = | TypeAny | typeof Number | typeof String | typeof Boolean | typeof Promise | typeof Object | typeof Array | typeof Symbol | typeof Function; type SetState = (value: T | ((value: T) => T)) => T; type TypesForReflect = | typeof String | typeof Number | typeof Boolean | typeof Array | typeof Object; interface ObjectFill { [index: string]: any | null | undefined; } /** * Current will take its value immediately after rendering * The whole object is persistent between renders and mutable */ interface Ref extends ObjectFill { current: T | null; } type Callback = (...args: any[]) => T; /** * Used to force the correct definition of the Shema.value */ type FnProp = (value: T) => T; /** * Type Builders Dictionary */ type TypeConstructor = T extends number ? NumberConstructor : T extends string ? StringConstructor : T extends boolean ? BooleanConstructor : T extends () => {} ? FunctionConstructor : T extends symbol ? SymbolConstructor : T extends Promise ? PromiseConstructor : T extends any[] ? ArrayConstructor : T extends object ? ObjectConstructor : any; type ContructorType = T extends typeof Number ? number : T extends typeof String ? string : T extends typeof Boolean ? boolean : T extends typeof Function ? (...args: any[]) => any : T extends typeof Symbol ? symbol : T extends typeof Promise ? Promise : T extends typeof Array ? any[] : T extends typeof Object ? object : any; type Reducer = (state: T, action: A) => T; interface FunctionalComponent { (props?: ObjectFill | any): any; props?: SchemaProps; } export const Any: TypeAny; export type JSXIntrinsicElements = { [K in keyof TagMaps]: Tag; }; export namespace h.JSX { interface IntrinsicElements extends JSXIntrinsicElements { [tagName: string]: any; } } export type JSXTag = Tag; export type EventInit = CustomEventInit & { type: string }; export interface SchemaValue { type: T; /** * customize the attribute name, escaping the Camelcase */ attr?: string; /** * reflects the value of the property as an attribute of the customElement */ reflect?: T extends TypesForReflect ? boolean : never; /** * Event to be dispatched at each change in property value */ event?: EventInit; /** * default value when declaring the customElement */ value?: T extends FunctionConstructor ? (...args: any[]) => any : T extends ArrayConstructor | ObjectConstructor ? FnProp> : FnProp> | ContructorType; } /** * Type to autofill the props object * ```ts * Component.props:Props = { * myProp : Number * myProp2 : { type : String, reflect: true } * } * ``` */ export type SchemaProps = { [x: string]: | Types | SchemaValue | SchemaValue | SchemaValue | SchemaValue | SchemaValue | SchemaValue | SchemaValue | SchemaValue; }; export type Props

= { [K in keyof P]: P[K] extends SchemaValue ? ContructorType : ContructorType; }; export type Component

= P extends SchemaProps ? { (props: ObjectFill): any; props?: P; } : { (props: P): any; props: { [C in keyof P]: | TypeConstructor | SchemaValue>; }; }; /** * Create the customElement to be declared in the document. * ```js * import {c,h} from "atomico"; * let myComponent = * customElements.define("my-component",c(myComponent)); * ``` * @todo Add a type setting that doesn't crash between JS and template-string. */ export function c( component: FunctionalComponent, BaseElement?: T ): T; /** * Declares Atomico virtual-dom format and is used to build JSX * ```jsx * import {h} from "atomico"; * // JS * const Component = ()=>h("host",{onclick(){ console.log("event") }}, "text..."); * // JSX * const Component = ()=>{ console.log("event") }}>text...; * ``` */ export function h( type: T, props?: P, ...children: any[] ): Vdom; /** * */ export function render( vdom: Vdom<"host", any>, node: T, id?: string | symbol ): T; /** * dispatch an event from the custom Element * ```js * let dispatchChangeValue = useEvent("changeValue") * let dispatchChangeValueToParent = useEvent("changeValue", {bubbles:true}) * ``` */ export function useEvent( type: String, eventInit?: Omit ): (detail?: any) => boolean; export function useEvent( type: string, eventInit?: Omit ): (detail: T) => boolean; /** * Similar to useState, but with the difference that useProp reflects the effect as component property * ```js * let component = ()=>{ * let [ myProp, setMyProp ] = useProp("myProp"); * return { myProp }; * } * component.props = { myProp : String } * ``` */ export function useProp(prop: string): [T, SetState]; /** * create a private state in the customElement * ```js * let component = ()=>{ * let [ count, setCount ] = useState(0); * return { count }; * } * ``` */ export function useState(initialState: T | (() => T)): [T, SetState]; export function useState(): [T, SetState]; /** * Create or recover a persistent reference between renders. * ```js * let ref = useRef(); * ``` */ export function useRef(current?: T): Ref; /** * Memorize the return of a callback based on a group of arguments, * the callback will be executed only if the arguments change between renders * ```js * let value = useMemo(expensiveProcessesCallback) * ``` */ export function useMemo( callback: () => T, args?: Args ): T; /** * Memorize the creation of a callback to a group of arguments, * The callback will preserve the scope of the observed arguments * ```js * let callback = useCallback((user)=>addUser(users, user),[users]); * ``` */ export function useCallback( callback: Callback, args?: Args ): Callback; /** * Evaluate the execution of a callback after each render cycle, * if the arguments between render do not change the callback * will not be executed, If the callback returns a function * it will be executed as an effect collector */ export function useEffect( callback: () => void | (() => any), args?: Args ): void; /** * Lets you use the redux pattern as Hook */ export function useReducer( reducer: Reducer, initialStaet?: T ): [T, (action: A) => void]; /** * returns the host associated with the instance of the customElement */ export function useHost(): Ref; }