paintcannon-react 0.0.1

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 (58) hide show
  1. package/README.md +213 -0
  2. package/dist/src/hooks/app-context.d.ts +8 -0
  3. package/dist/src/hooks/app-context.js +2 -0
  4. package/dist/src/hooks/index.d.ts +2 -0
  5. package/dist/src/hooks/index.js +2 -0
  6. package/dist/src/hooks/use-animation.d.ts +35 -0
  7. package/dist/src/hooks/use-animation.js +120 -0
  8. package/dist/src/hooks/use-app.d.ts +9 -0
  9. package/dist/src/hooks/use-app.js +9 -0
  10. package/dist/src/host-components/button/button.d.ts +8 -0
  11. package/dist/src/host-components/button/button.js +3 -0
  12. package/dist/src/host-components/button/reconcile-button.d.ts +6 -0
  13. package/dist/src/host-components/button/reconcile-button.js +14 -0
  14. package/dist/src/host-components/button.d.ts +8 -0
  15. package/dist/src/host-components/button.js +3 -0
  16. package/dist/src/host-components/div/div.d.ts +6 -0
  17. package/dist/src/host-components/div/div.js +3 -0
  18. package/dist/src/host-components/div/reconcile-div.d.ts +6 -0
  19. package/dist/src/host-components/div/reconcile-div.js +10 -0
  20. package/dist/src/host-components/div.d.ts +6 -0
  21. package/dist/src/host-components/div.js +3 -0
  22. package/dist/src/host-components/form/form.d.ts +6 -0
  23. package/dist/src/host-components/form/form.js +3 -0
  24. package/dist/src/host-components/form/reconcile-form.d.ts +6 -0
  25. package/dist/src/host-components/form/reconcile-form.js +10 -0
  26. package/dist/src/host-components/form.d.ts +6 -0
  27. package/dist/src/host-components/form.js +3 -0
  28. package/dist/src/host-components/index.d.ts +14 -0
  29. package/dist/src/host-components/index.js +14 -0
  30. package/dist/src/host-components/input/input.d.ts +8 -0
  31. package/dist/src/host-components/input/input.js +3 -0
  32. package/dist/src/host-components/input/reconcile-input.d.ts +6 -0
  33. package/dist/src/host-components/input/reconcile-input.js +14 -0
  34. package/dist/src/host-components/input.d.ts +8 -0
  35. package/dist/src/host-components/input.js +3 -0
  36. package/dist/src/host-components/mounted.d.ts +38 -0
  37. package/dist/src/host-components/mounted.js +17 -0
  38. package/dist/src/host-components/reconcile-shared.d.ts +8 -0
  39. package/dist/src/host-components/reconcile-shared.js +26 -0
  40. package/dist/src/host-components/shared.d.ts +40 -0
  41. package/dist/src/host-components/shared.js +18 -0
  42. package/dist/src/host-components/span/reconcile-span.d.ts +6 -0
  43. package/dist/src/host-components/span/reconcile-span.js +10 -0
  44. package/dist/src/host-components/span/span.d.ts +6 -0
  45. package/dist/src/host-components/span/span.js +3 -0
  46. package/dist/src/host-components/span.d.ts +6 -0
  47. package/dist/src/host-components/span.js +3 -0
  48. package/dist/src/host-components/textarea/reconcile-textarea.d.ts +6 -0
  49. package/dist/src/host-components/textarea/reconcile-textarea.js +12 -0
  50. package/dist/src/host-components/textarea/textarea.d.ts +8 -0
  51. package/dist/src/host-components/textarea/textarea.js +3 -0
  52. package/dist/src/host-components/textarea.d.ts +8 -0
  53. package/dist/src/host-components/textarea.js +3 -0
  54. package/dist/src/index.d.ts +21 -0
  55. package/dist/src/index.js +9 -0
  56. package/dist/src/reconciler.d.ts +17 -0
  57. package/dist/src/reconciler.js +403 -0
  58. package/package.json +39 -0
@@ -0,0 +1,38 @@
1
+ import type { PaintElement, TextNode } from "paintcannon";
2
+ import * as button from "./button/button.ts";
3
+ import * as div from "./div/div.ts";
4
+ import * as form from "./form/form.ts";
5
+ import * as input from "./input/input.ts";
6
+ import * as span from "./span/span.ts";
7
+ import * as textarea from "./textarea/textarea.ts";
8
+ import type { HostComponent, HostType } from "./shared.ts";
9
+ export type HostProps = div.Props | span.Props | form.Props | button.Props | input.Props | textarea.Props;
10
+ export type MountedHostElement<Type extends HostType, Props, Element extends PaintElement> = {
11
+ kind: "element";
12
+ type: Type;
13
+ props: Props;
14
+ children: HostNode[];
15
+ node: Element;
16
+ };
17
+ export type MountedComponent<Module> = Module extends {
18
+ type: infer Type extends HostType;
19
+ Component: HostComponent<infer Props, infer Element extends PaintElement>;
20
+ } ? MountedHostElement<Type, Props, Element> : never;
21
+ export type HostElement = MountedComponent<typeof div> | MountedComponent<typeof span> | MountedComponent<typeof form> | MountedComponent<typeof button> | MountedComponent<typeof input> | MountedComponent<typeof textarea>;
22
+ export type HostText = {
23
+ kind: "text";
24
+ text: string;
25
+ node: TextNode;
26
+ };
27
+ export type HostNode = HostElement | HostText;
28
+ declare const hostPropsForType: {
29
+ "paintcannon.div": div.Props;
30
+ "paintcannon.span": span.Props;
31
+ "paintcannon.form": form.Props;
32
+ "paintcannon.button": button.Props;
33
+ "paintcannon.input": input.Props;
34
+ "paintcannon.textarea": textarea.Props;
35
+ };
36
+ export type HostPropsForType = typeof hostPropsForType;
37
+ export declare function castHostProps<Type extends HostType>(_type: Type, props: HostProps): HostPropsForType[Type];
38
+ export {};
@@ -0,0 +1,17 @@
1
+ import * as button from "./button/button.js";
2
+ import * as div from "./div/div.js";
3
+ import * as form from "./form/form.js";
4
+ import * as input from "./input/input.js";
5
+ import * as span from "./span/span.js";
6
+ import * as textarea from "./textarea/textarea.js";
7
+ const hostPropsForType = {
8
+ [div.type]: undefined,
9
+ [span.type]: undefined,
10
+ [form.type]: undefined,
11
+ [button.type]: undefined,
12
+ [input.type]: undefined,
13
+ [textarea.type]: undefined,
14
+ };
15
+ export function castHostProps(_type, props) {
16
+ return props;
17
+ }
@@ -0,0 +1,8 @@
1
+ import type { InputElement, PaintElement, TextAreaElement } from "paintcannon";
2
+ import type * as input from "./input/input.ts";
3
+ import type * as textarea from "./textarea/textarea.ts";
4
+ import type { CommonProps, Scrollable } from "./shared.ts";
5
+ export type ApplyCommonProps = (node: PaintElement, oldProps: Partial<CommonProps>, newProps: CommonProps) => void;
6
+ export declare function applyScrollableElementProps<Props extends CommonProps & Partial<Scrollable>>(node: PaintElement & Scrollable, oldProps: Partial<Props>, newProps: Props, applyCommonProps: ApplyCommonProps): void;
7
+ export declare function applyScrollableProps(node: Scrollable, props: Partial<Scrollable>): void;
8
+ export declare function applyTextControlProps<T extends InputElement | TextAreaElement>(node: T, oldProps: Partial<input.Props | textarea.Props>, newProps: input.Props | textarea.Props): void;
@@ -0,0 +1,26 @@
1
+ export function applyScrollableElementProps(node, oldProps, newProps, applyCommonProps) {
2
+ applyCommonProps(node, oldProps, newProps);
3
+ applyScrollableProps(node, newProps);
4
+ }
5
+ export function applyScrollableProps(node, props) {
6
+ if (props.scrollLeft !== undefined) {
7
+ node.scrollLeft = props.scrollLeft;
8
+ }
9
+ if (props.scrollTop !== undefined) {
10
+ node.scrollTop = props.scrollTop;
11
+ }
12
+ }
13
+ export function applyTextControlProps(node, oldProps, newProps) {
14
+ if (newProps.value !== undefined) {
15
+ node.value = newProps.value;
16
+ }
17
+ if (newProps.placeholder !== undefined) {
18
+ node.placeholder = newProps.placeholder;
19
+ }
20
+ if (newProps.cursorPosition !== undefined) {
21
+ node.cursorPosition = newProps.cursorPosition;
22
+ }
23
+ if (newProps.autoFocus === true && oldProps.autoFocus !== true) {
24
+ node.focus();
25
+ }
26
+ }
@@ -0,0 +1,40 @@
1
+ import type React from "react";
2
+ import type { CSSStyleProperties, ElementEventListenerFor, ElementEventType, PaintElement, PaintElementTagName } from "paintcannon";
3
+ export type HostTagName = Exclude<PaintElementTagName, "img">;
4
+ export type HostType = `paintcannon.${HostTagName}`;
5
+ export declare function typeString<Type extends HostType>(type: Type): Type;
6
+ export type Scrollable = {
7
+ scrollLeft: number;
8
+ scrollTop: number;
9
+ };
10
+ export type HostComponent<Props, Element extends PaintElement> = React.ForwardRefExoticComponent<React.PropsWithoutRef<Props> & React.RefAttributes<Element>>;
11
+ export declare const EVENT_PROP_NAMES: {
12
+ readonly keydown: "onKeyDown";
13
+ readonly keyup: "onKeyUp";
14
+ readonly click: "onClick";
15
+ readonly mouseenter: "onMouseEnter";
16
+ readonly mouseleave: "onMouseLeave";
17
+ readonly mousemove: "onMouseMove";
18
+ readonly focus: "onFocus";
19
+ readonly blur: "onBlur";
20
+ readonly submit: "onSubmit";
21
+ readonly change: "onChange";
22
+ readonly transitionstart: "onTransitionStart";
23
+ readonly transitionend: "onTransitionEnd";
24
+ readonly scroll: "onScroll";
25
+ };
26
+ export type EventPropName<T extends ElementEventType = ElementEventType> = (typeof EVENT_PROP_NAMES)[T];
27
+ type ElementEventProps = {
28
+ [T in ElementEventType as EventPropName<T>]?: ElementEventListenerFor<T>;
29
+ };
30
+ export type CommonProps = ElementEventProps & {
31
+ children?: React.ReactNode;
32
+ style?: CSSStyleProperties;
33
+ };
34
+ export type TextControlProps = CommonProps & {
35
+ value?: string;
36
+ placeholder?: string;
37
+ cursorPosition?: number;
38
+ autoFocus?: boolean;
39
+ };
40
+ export {};
@@ -0,0 +1,18 @@
1
+ export function typeString(type) {
2
+ return type;
3
+ }
4
+ export const EVENT_PROP_NAMES = {
5
+ keydown: "onKeyDown",
6
+ keyup: "onKeyUp",
7
+ click: "onClick",
8
+ mouseenter: "onMouseEnter",
9
+ mouseleave: "onMouseLeave",
10
+ mousemove: "onMouseMove",
11
+ focus: "onFocus",
12
+ blur: "onBlur",
13
+ submit: "onSubmit",
14
+ change: "onChange",
15
+ transitionstart: "onTransitionStart",
16
+ transitionend: "onTransitionEnd",
17
+ scroll: "onScroll",
18
+ };
@@ -0,0 +1,6 @@
1
+ import type { PaintCannon } from "paintcannon";
2
+ import * as span from "./span.ts";
3
+ import type { MountedComponent } from "../mounted.ts";
4
+ import { type ApplyCommonProps } from "../reconcile-shared.ts";
5
+ export declare function create(paintCannon: PaintCannon, props: span.Props, applyCommonProps: ApplyCommonProps): MountedComponent<typeof span>;
6
+ export declare function applyProps(node: span.Element, oldProps: Partial<span.Props>, newProps: span.Props, applyCommonProps: ApplyCommonProps): void;
@@ -0,0 +1,10 @@
1
+ import * as span from "./span.js";
2
+ import { applyScrollableElementProps } from "../reconcile-shared.js";
3
+ export function create(paintCannon, props, applyCommonProps) {
4
+ const node = paintCannon.createElement("span");
5
+ applyProps(node, {}, props, applyCommonProps);
6
+ return { kind: "element", type: span.type, props, children: [], node };
7
+ }
8
+ export function applyProps(node, oldProps, newProps, applyCommonProps) {
9
+ applyScrollableElementProps(node, oldProps, newProps, applyCommonProps);
10
+ }
@@ -0,0 +1,6 @@
1
+ import type { SpanElement as PaintSpanElement } from "paintcannon";
2
+ import type { CommonProps, HostComponent, Scrollable } from "../shared.ts";
3
+ export type Props = CommonProps & Partial<Scrollable>;
4
+ export type Element = PaintSpanElement;
5
+ export declare const type: "paintcannon.span";
6
+ export declare const Component: HostComponent<Props, Element>;
@@ -0,0 +1,3 @@
1
+ import { typeString } from "../shared.js";
2
+ export const type = typeString("paintcannon.span");
3
+ export const Component = type;
@@ -0,0 +1,6 @@
1
+ import type { SpanElement as PaintSpanElement } from 'paintcannon';
2
+ import type { CommonProps, HostComponent, Scrollable } from './shared.ts';
3
+ export type Props = CommonProps & Partial<Scrollable>;
4
+ export type Element = PaintSpanElement;
5
+ export declare const type: "paintcannon.span";
6
+ export declare const Component: HostComponent<Props, Element>;
@@ -0,0 +1,3 @@
1
+ import { typeString } from "./shared.js";
2
+ export const type = typeString('paintcannon.span');
3
+ export const Component = type;
@@ -0,0 +1,6 @@
1
+ import type { PaintCannon } from "paintcannon";
2
+ import * as textarea from "./textarea.ts";
3
+ import type { MountedComponent } from "../mounted.ts";
4
+ import { type ApplyCommonProps } from "../reconcile-shared.ts";
5
+ export declare function create(paintCannon: PaintCannon, props: textarea.Props, applyCommonProps: ApplyCommonProps): MountedComponent<typeof textarea>;
6
+ export declare function applyProps(node: textarea.Element, oldProps: Partial<textarea.Props>, newProps: textarea.Props, applyCommonProps: ApplyCommonProps): void;
@@ -0,0 +1,12 @@
1
+ import * as textarea from "./textarea.js";
2
+ import { applyScrollableProps, applyTextControlProps, } from "../reconcile-shared.js";
3
+ export function create(paintCannon, props, applyCommonProps) {
4
+ const node = paintCannon.createElement("textarea");
5
+ applyProps(node, {}, props, applyCommonProps);
6
+ return { kind: "element", type: textarea.type, props, children: [], node };
7
+ }
8
+ export function applyProps(node, oldProps, newProps, applyCommonProps) {
9
+ applyCommonProps(node, oldProps, newProps);
10
+ applyTextControlProps(node, oldProps, newProps);
11
+ applyScrollableProps(node, newProps);
12
+ }
@@ -0,0 +1,8 @@
1
+ import type { TextAreaElement as PaintTextAreaElement } from "paintcannon";
2
+ import type { HostComponent, Scrollable, TextControlProps } from "../shared.ts";
3
+ export type Props = TextControlProps & Partial<Scrollable> & {
4
+ type?: never;
5
+ };
6
+ export type Element = PaintTextAreaElement;
7
+ export declare const type: "paintcannon.textarea";
8
+ export declare const Component: HostComponent<Props, Element>;
@@ -0,0 +1,3 @@
1
+ import { typeString } from "../shared.js";
2
+ export const type = typeString("paintcannon.textarea");
3
+ export const Component = type;
@@ -0,0 +1,8 @@
1
+ import type { TextAreaElement as PaintTextAreaElement } from 'paintcannon';
2
+ import type { HostComponent, Scrollable, TextControlProps } from './shared.ts';
3
+ export type Props = TextControlProps & Partial<Scrollable> & {
4
+ type?: never;
5
+ };
6
+ export type Element = PaintTextAreaElement;
7
+ export declare const type: "paintcannon.textarea";
8
+ export declare const Component: HostComponent<Props, Element>;
@@ -0,0 +1,3 @@
1
+ import { typeString } from "./shared.js";
2
+ export const type = typeString('paintcannon.textarea');
3
+ export const Component = type;
@@ -0,0 +1,21 @@
1
+ import * as hostComponents from "./host-components/index.ts";
2
+ export { useAnimation, useApp, type AnimationOptions, type AnimationResult, type PaintCannonReactApp, } from "./hooks/index.ts";
3
+ export { createRoot, render, type CreateRootOptions, type PaintCannonReactRoot, } from "./reconciler.ts";
4
+ export type DivProps = hostComponents.div.Props;
5
+ export type DivElement = hostComponents.div.Element;
6
+ export declare const Div: hostComponents.HostComponent<hostComponents.div.Props, import("paintcannon").DivElement>;
7
+ export type SpanProps = hostComponents.span.Props;
8
+ export type SpanElement = hostComponents.span.Element;
9
+ export declare const Span: hostComponents.HostComponent<hostComponents.span.Props, import("paintcannon").SpanElement>;
10
+ export type FormProps = hostComponents.form.Props;
11
+ export type FormElement = hostComponents.form.Element;
12
+ export declare const Form: hostComponents.HostComponent<hostComponents.form.Props, import("paintcannon").FormElement>;
13
+ export type ButtonProps = hostComponents.button.Props;
14
+ export type ButtonElement = hostComponents.button.Element;
15
+ export declare const Button: hostComponents.HostComponent<hostComponents.button.Props, import("paintcannon").ButtonElement>;
16
+ export type InputProps = hostComponents.input.Props;
17
+ export type InputElement = hostComponents.input.Element;
18
+ export declare const Input: hostComponents.HostComponent<hostComponents.input.Props, import("paintcannon").InputElement>;
19
+ export type TextareaProps = hostComponents.textarea.Props;
20
+ export type TextareaElement = hostComponents.textarea.Element;
21
+ export declare const Textarea: hostComponents.HostComponent<hostComponents.textarea.Props, import("paintcannon").TextAreaElement>;
@@ -0,0 +1,9 @@
1
+ import * as hostComponents from "./host-components/index.js";
2
+ export { useAnimation, useApp, } from "./hooks/index.js";
3
+ export { createRoot, render, } from "./reconciler.js";
4
+ export const Div = hostComponents.div.Component;
5
+ export const Span = hostComponents.span.Component;
6
+ export const Form = hostComponents.form.Component;
7
+ export const Button = hostComponents.button.Component;
8
+ export const Input = hostComponents.input.Component;
9
+ export const Textarea = hostComponents.textarea.Component;
@@ -0,0 +1,17 @@
1
+ import React from "react";
2
+ import type { DivElement as PaintDivElement, FormElement as PaintFormElement, PaintCannonOptions, SpanElement as PaintSpanElement } from "paintcannon";
3
+ import { PaintCannon } from "paintcannon";
4
+ export type CreateRootOptions = PaintCannonOptions & {
5
+ paintCannon?: PaintCannon;
6
+ container?: PaintDivElement | PaintSpanElement | PaintFormElement;
7
+ };
8
+ export type PaintCannonReactRoot = {
9
+ readonly paintCannon: PaintCannon;
10
+ readonly container: PaintDivElement | PaintSpanElement | PaintFormElement;
11
+ render(element: React.ReactNode): void;
12
+ unmount(): void;
13
+ exit(errorOrResult?: unknown): void;
14
+ waitUntilExit(): Promise<unknown>;
15
+ };
16
+ export declare function createRoot(options?: CreateRootOptions): PaintCannonReactRoot;
17
+ export declare function render(element: React.ReactNode, options?: CreateRootOptions): PaintCannonReactRoot;