@cpfr/tootframes 1.0.9

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/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2024 Carsten Pfeffer
2
+
3
+ This software is provided ‘as-is’, without any express or implied
4
+ warranty. In no event will the authors be held liable for any damages
5
+ arising from the use of this software.
6
+
7
+ Permission is granted to anyone to use this software for any purpose,
8
+ including commercial applications, and to alter it and redistribute it
9
+ freely, subject to the following restrictions:
10
+
11
+ 1. The origin of this software must not be misrepresented; you must not
12
+ claim that you wrote the original software. If you use this software
13
+ in a product, an acknowledgment in the product documentation would be
14
+ appreciated but is not required.
15
+
16
+ 2. Altered source versions must be plainly marked as such, and must not be
17
+ misrepresented as being the original software.
18
+
19
+ 3. This notice may not be removed or altered from any source
20
+ distribution.
package/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # Tootframes
2
+
3
+ Tootframes is a simple UI libary that does not use reactive bindings or external frameworks such as React, Angular, Vue or similar.
4
+
5
+ The name *"Tootframes"* is derived from the sound an elephant does plus *"frames"* for the frames where the UI elements are rendered.
6
+
7
+ ## Available UI Elements
8
+
9
+ - Button
10
+ - ColorPicker
11
+ - Dialogs & MessageDialogs
12
+ - Docking System (dockable containers)
13
+ - Dropdown
14
+ - Image
15
+ - Text Label
16
+ - ListBox (only one column)
17
+ - ListView (table with headers)
18
+ - Menu and MenuBar
19
+ - Node Editor
20
+ - Panels
21
+ - TreeView
22
+ - UndoHistory
23
+
24
+
25
+ ## License
26
+ Zlib: https://opensource.org/license/zlib
27
+
28
+ ## Usage
29
+ ```
30
+ import { ROOT, NodeEditor, Node } from "@cpfr/tootframes";
31
+
32
+ // create a new node editor
33
+ let nodeEditor = new NodeEditor(null, null, null, null, true, true, new tootframes.UndoHistory());
34
+
35
+
36
+ // create two nodes
37
+ var n1 = new Node("Node 1");
38
+ var n2 = new Node("Node 2");
39
+
40
+ // set the node position
41
+ n1.setPos(100, 100);
42
+ n2.setPos(200, 10);
43
+
44
+ // add some HTML content to the second node
45
+ let n2content = document.createElement("div");
46
+ n2content.textContent = "Lorem Ipsum dolor si amet bla bla";
47
+ n2._contentsElement.appendChild(n2content);
48
+
49
+ // add inputs and outputs to the nodes
50
+ let n1Out = n1.addOutput(null, null, true);
51
+ let n2In = n2.addInput("Input");
52
+ let n2Out = n2.addOutput("Output");
53
+
54
+ // add the nodes to the editor
55
+ nodeEditor.addNode(n1);
56
+ nodeEditor.addNode(n2);
57
+
58
+ // connect the output of node1 with the input of node2
59
+ nodeEditor.connect(n1Out, n2In);
60
+
61
+ // append the node editor to the root element of tootframes
62
+ ROOT.appendChild(nodeEditor);
63
+ ```
@@ -0,0 +1,5 @@
1
+ import { Widget } from './Widget';
2
+ declare class Button extends Widget {
3
+ constructor(label: string, callback: () => void);
4
+ }
5
+ export { Button };
@@ -0,0 +1,79 @@
1
+ declare enum ColorModificationMode {
2
+ Percentage = 0,
3
+ FixedAmount = 1
4
+ }
5
+ declare class Color {
6
+ private _r;
7
+ private _g;
8
+ private _b;
9
+ private _hueInfo?;
10
+ constructor(r?: number, g?: number, b?: number);
11
+ static fromRgb(r: number, g: number, b: number): Color;
12
+ static fromHsl(h: number, s: number, l: number): Color;
13
+ static fromHsv(h: number, s: number, v: number): Color;
14
+ static fromHex(hex: string): Color;
15
+ private static _hexToRgb;
16
+ private static _hslToRgb;
17
+ private static _hsvToRgb;
18
+ static fromRgbObject(rgbObject: {
19
+ r: number;
20
+ g: number;
21
+ b: number;
22
+ }): Color;
23
+ static fromHslObject(hslObject: {
24
+ h: number;
25
+ s: number;
26
+ l: number;
27
+ }): Color;
28
+ static fromHsvObject(hsvObject: {
29
+ h: number;
30
+ s: number;
31
+ v: number;
32
+ }): Color;
33
+ setRgb(r: number, g: number, b: number): void;
34
+ setHsl(h: number, s: number, l: number): void;
35
+ setHsv(h: number, s: number, v: number): void;
36
+ setHex(hex: string): void;
37
+ setRgbObject(rgbObject: {
38
+ r: number;
39
+ g: number;
40
+ b: number;
41
+ }): void;
42
+ setHslObject(hslObject: {
43
+ h: number;
44
+ s: number;
45
+ l: number;
46
+ }): void;
47
+ setHsvObject(hsvObject: {
48
+ h: number;
49
+ s: number;
50
+ v: number;
51
+ }): void;
52
+ getHsl(): {
53
+ h: number;
54
+ s: number;
55
+ l: number;
56
+ };
57
+ getHsv(): {
58
+ h: number;
59
+ s: number;
60
+ v: number;
61
+ };
62
+ getRgb(): {
63
+ r: number;
64
+ g: number;
65
+ b: number;
66
+ };
67
+ getHex(): string;
68
+ lighten(amount: number, mode: ColorModificationMode): void;
69
+ darken(amount: number, mode: ColorModificationMode): void;
70
+ saturate(amount: number, mode: ColorModificationMode): void;
71
+ desaturate(amount: number, mode: ColorModificationMode): void;
72
+ setSaturation(saturation: number): void;
73
+ rotateHue(degrees: number): void;
74
+ invert(): void;
75
+ getInverted(): Color;
76
+ getComplement(): Color;
77
+ getBlended(other: Color, alpha: number): Color;
78
+ }
79
+ export { Color, ColorModificationMode };
@@ -0,0 +1,71 @@
1
+ import { Widget } from './Widget';
2
+ import { Color } from './Color';
3
+ import { Dialog } from './Dialog';
4
+ import { MessageDialogButton } from './MessageDialog';
5
+ declare abstract class AbstractColorPicker extends Widget {
6
+ private _color;
7
+ protected _onColorChanged: (oldColor: Color, newColor: Color) => void;
8
+ abstract setColor(color: Color): void;
9
+ constructor(onColorChanged?: (oldColor: Color, newColor: Color) => void);
10
+ protected setColorProperty(color: Color): void;
11
+ getColor(): Color;
12
+ }
13
+ declare class PaintStyleColorPicker extends AbstractColorPicker {
14
+ private _hueDiv;
15
+ private _saturationDiv;
16
+ private _lightnessDiv;
17
+ private _colorHandle;
18
+ private _lightnessHandle;
19
+ constructor(color?: Color, onColorChanged?: (oldColor: Color, newColor: Color) => void);
20
+ private _onLightnessMove;
21
+ private _onHueMove;
22
+ private _getColorFromCurrentPositions;
23
+ private _setColorInternal;
24
+ setColor(color: Color): void;
25
+ onAttached(): void;
26
+ }
27
+ declare class GimpStyleColorPicker extends AbstractColorPicker {
28
+ private _saturationDiv;
29
+ private _valueDiv;
30
+ private _hueDiv;
31
+ private _svHandle;
32
+ private _hueHandle;
33
+ constructor(color?: Color, onColorChanged?: (oldColor: Color, newColor: Color) => void);
34
+ private _onHueMove;
35
+ private _onSatValMove;
36
+ private _getColorFromCurrentPositions;
37
+ private _setColorInternal;
38
+ setColor(color: Color): void;
39
+ onAttached(): void;
40
+ }
41
+ declare class WheelColorPicker extends AbstractColorPicker {
42
+ private _hueWheelDiv;
43
+ private _wheelHandle;
44
+ private _slHandle;
45
+ private _innerCircleDiv;
46
+ private _saturationDiv;
47
+ private _lightnessDiv;
48
+ private readonly _zeroHueVector;
49
+ constructor(color?: Color, onColorChanged?: (oldColor: Color, newColor: Color) => void);
50
+ private _onHueMove;
51
+ private _onSatLitMove;
52
+ private _getColorFromCurrentPositions;
53
+ private _setColorInternal;
54
+ setColor(color: Color): void;
55
+ onAttached(): void;
56
+ }
57
+ declare class ColorPickerDialog extends Dialog {
58
+ private colorPicker;
59
+ private _textInput;
60
+ private _divOutput;
61
+ private _cancelOption;
62
+ private _continueOption;
63
+ private _boundKeyEvent;
64
+ constructor(title: string, text: string, color: Color, buttons: MessageDialogButton[], hasCloseButton: boolean);
65
+ onAttached(): void;
66
+ getColor(): Color;
67
+ showModal(): void;
68
+ _clickButton(button: HTMLButtonElement): void;
69
+ hide(): void;
70
+ }
71
+ export { AbstractColorPicker, PaintStyleColorPicker, GimpStyleColorPicker, WheelColorPicker, ColorPickerDialog };
@@ -0,0 +1,18 @@
1
+ import { Widget } from './Widget';
2
+ import { DragInfo } from './dragAndDrop';
3
+ declare class Dialog extends Widget {
4
+ title: string;
5
+ titleElement: HTMLDivElement;
6
+ modalElement: HTMLDivElement;
7
+ contentElement: HTMLElement;
8
+ attachedElement?: HTMLElement;
9
+ contentWidget: Widget;
10
+ constructor(title: string, contentWidget: Widget, hasCloseButton: boolean);
11
+ onAttached(): void;
12
+ show(): void;
13
+ hide(): void;
14
+ showModal(): void;
15
+ isShown(): boolean;
16
+ onDragging(dragInfo: DragInfo): void;
17
+ }
18
+ export { Dialog };
@@ -0,0 +1,82 @@
1
+ import { Widget } from './Widget';
2
+ import { DragInfo } from './dragAndDrop';
3
+ declare enum DockDirection {
4
+ Left = 1,
5
+ Right = 2,
6
+ Top = 3,
7
+ Bottom = 4,
8
+ Inside = 5,
9
+ Float = 6
10
+ }
11
+ declare enum Orientation {
12
+ Horizontal = 1,
13
+ Vertical = 2
14
+ }
15
+ declare class DockingStructure {
16
+ orientation: Orientation;
17
+ dockPercentage: number;
18
+ children?: DockingStructure[];
19
+ identifier?: string;
20
+ static fromDockPanel(dockPanel: DockPanel): DockingStructure;
21
+ static fromDockContainer(dockContainer: DockContainer): DockingStructure;
22
+ }
23
+ declare abstract class Dockable extends Widget {
24
+ _dockPercentage: number;
25
+ identifier: string | null;
26
+ }
27
+ declare class DockContainer extends Dockable {
28
+ children: Dockable[];
29
+ orientation: Orientation;
30
+ constructor();
31
+ onAttached(): void;
32
+ getFloatingPanels(): {
33
+ identifier: string;
34
+ width: number;
35
+ height: number;
36
+ x: number;
37
+ y: number;
38
+ }[];
39
+ getDockPanelAtPoint(x: number, y: number): DockPanel;
40
+ getDockingStructure(): DockingStructure;
41
+ setChildPercentages(percentages: number[]): void;
42
+ _dockRelative(child: Dockable, relativeTo: Dockable, insertBefore: boolean, percentage: number): void;
43
+ _dock(child: Dockable, insertBefore: boolean, percentage?: number): void;
44
+ _setOrientation(orientation: Orientation): void;
45
+ _wrapChildren(): void;
46
+ _subdivide(relativeTo: Dockable, dockDirection: DockDirection): DockContainer;
47
+ dockRelativeTo(child: Dockable, relativeTo: Dockable, dockDirection: DockDirection, percentage?: number): Dockable;
48
+ dock(child: Dockable, dockDirection: DockDirection, percentage?: number): Dockable;
49
+ undock(child: Dockable): Dockable;
50
+ _layoutChildren(width?: number, height?: number): void;
51
+ }
52
+ declare class DockPanel extends Dockable {
53
+ titleElement: HTMLDivElement;
54
+ contentWidget: Widget;
55
+ private _dragged;
56
+ private _dockOverlay;
57
+ private _dockTargetDirection;
58
+ resizeEW: HTMLDivElement;
59
+ resizeNS: HTMLDivElement;
60
+ resizeDiag: HTMLDivElement;
61
+ private _resizingHorizontally;
62
+ private _resizingVertically;
63
+ private _dockTarget;
64
+ identifier: string;
65
+ constructor(title: string, contentWidget: Widget, hasCloseButton?: boolean);
66
+ onResize(): void;
67
+ onAttached(): void;
68
+ getTitle(): string;
69
+ setTitle(title: string): void;
70
+ setContent(contentWidget: Widget): void;
71
+ isFloating(): boolean;
72
+ close(): void;
73
+ createDragOverlay(): void;
74
+ onResizeStart(mouseEvt: MouseEvent, resizingHorizontally: boolean, resizingVertically: boolean): boolean;
75
+ onResizing(dragInfo: DragInfo): void;
76
+ onDragStart(mouseEvt: MouseEvent): boolean;
77
+ onDragging(dragInfo: DragInfo): void;
78
+ onDragEnd(mouseEvt: MouseEvent): void;
79
+ float(x?: number, y?: number, width?: number, height?: number): void;
80
+ dockRelativeTo(relativeWidget: Dockable, dockDirection: DockDirection, percentage?: number): void;
81
+ }
82
+ export { DockContainer, DockPanel, DockDirection, Orientation };
@@ -0,0 +1,9 @@
1
+ import { Widget } from './Widget';
2
+ declare class Dropdown extends Widget {
3
+ constructor();
4
+ addOption(label: string, value: string): void;
5
+ removeOption(value: string): void;
6
+ getSelectedValue(): string;
7
+ setSelectedValue(value: string): void;
8
+ }
9
+ export { Dropdown };
@@ -0,0 +1,16 @@
1
+ declare class FakeClipboard {
2
+ _data: ClipboardData;
3
+ constructor();
4
+ set(data: ClipboardData): void;
5
+ clear(): void;
6
+ get(): ClipboardData;
7
+ containsData(): boolean;
8
+ }
9
+ declare class ClipboardData {
10
+ type: string;
11
+ timestamp: Date;
12
+ data: any;
13
+ constructor(type: string, timestamp: Date, data: any);
14
+ }
15
+ declare let fakeClipboard: FakeClipboard;
16
+ export { fakeClipboard, FakeClipboard, ClipboardData };
@@ -0,0 +1,7 @@
1
+ import { Widget } from './Widget';
2
+ declare class Image extends Widget {
3
+ constructor(src: string, width?: number, height?: number);
4
+ setSource(src: string): void;
5
+ getSource(): string;
6
+ }
7
+ export { Image };
@@ -0,0 +1,7 @@
1
+ import { Widget } from './Widget';
2
+ declare class Label extends Widget {
3
+ constructor(text: string);
4
+ setText(text: string): void;
5
+ getText(): string;
6
+ }
7
+ export { Label };
@@ -0,0 +1,23 @@
1
+ import { Widget } from './Widget';
2
+ declare class ListBox extends Widget {
3
+ private _toElementFunction;
4
+ private _selectedIndex;
5
+ private _onItemClick;
6
+ private _items;
7
+ constructor(items: any[], toElementFunction: (item: any) => HTMLElement, onItemClick: (item: any, element: HTMLElement) => void);
8
+ clear(): void;
9
+ setItems(items: any[]): void;
10
+ getItemCount(): number;
11
+ addItem(item: any): void;
12
+ removeItem(item: any): void;
13
+ removeItemAtIndex(index: number): void;
14
+ selectItem(item: any): void;
15
+ selectItemAtIndex(index: number): void;
16
+ getSelectedItem(): any;
17
+ getItemAtIndex(index: number): any;
18
+ getSelectedIndex(): number;
19
+ }
20
+ declare class StringListBox extends ListBox {
21
+ constructor(items: any[], toStringFunction?: (item: any) => string, onItemClick?: (item: any, element: HTMLElement) => void);
22
+ }
23
+ export { ListBox, StringListBox };
@@ -0,0 +1,59 @@
1
+ import { Widget } from './Widget';
2
+ declare class ListViewColumn {
3
+ name: string;
4
+ isReadOnly: boolean;
5
+ fromString: (value: string) => any;
6
+ toString: (value: any) => string;
7
+ constructor(name: string, isReadOnly: boolean, fromString: (value: string) => any, toString: (value: any) => string);
8
+ compare(a: any, b: any): number;
9
+ }
10
+ declare class StringListViewColumn extends ListViewColumn {
11
+ constructor(name: string, isReadOnly: boolean);
12
+ compare(a: string, b: string): 1 | -1 | 0;
13
+ }
14
+ declare class IntListViewColumn extends ListViewColumn {
15
+ constructor(name: string, isReadOnly: boolean);
16
+ compare(a: number, b: number): 1 | -1 | 0;
17
+ }
18
+ declare class FloatListViewColumn extends ListViewColumn {
19
+ constructor(name: string, isReadOnly: boolean);
20
+ compare(a: number, b: number): 1 | -1 | 0;
21
+ }
22
+ declare class ListView extends Widget {
23
+ private _columns;
24
+ private _rows;
25
+ private _htmlRows;
26
+ private _cellValueChangedCallback;
27
+ private _editValidationCallback;
28
+ private _cellDoubleClickCallback;
29
+ private _headerRow;
30
+ constructor(columns: ListViewColumn[], editValidationCallback?: (oldContent: any, inputContent: string, row: any[], column: ListViewColumn, rowIndex: number, columnIndex: number) => void, cellValueChangedCallback?: (oldContent: any, inputContent: string, row: any[], column: ListViewColumn, rowIndex: number, columnIndex: number) => void, cellDoubleClickCallback?: (row: any[], column: ListViewColumn, rowIndex: number, columnIndex: number) => void);
31
+ static fromStringColumns(columns: string[], areReadonly: boolean, editValidationCallback?: (oldContent: any, inputContent: string, row: any[], column: ListViewColumn, rowIndex: number, columnIndex: number) => void, cellValueChangedCallback?: (oldContent: any, inputContent: string, row: any[], column: ListViewColumn, rowIndex: number, columnIndex: number) => void, cellDoubleClickCallback?: (row: any[], column: ListViewColumn, rowIndex: number, columnIndex: number) => void): ListView;
32
+ addStringColumn(columnName: string, isReadonly?: boolean, columnValues?: string[], columnIndex?: number): void;
33
+ addColumn(column: ListViewColumn, columnValues?: any[], columnIndex?: number): void;
34
+ removeColumn(columnIndex: number): void;
35
+ setColumnAtIndexReadonly(columnIndex: number, readOnly: boolean): void;
36
+ setColumnReadonly(column: ListViewColumn, readOnly?: boolean): void;
37
+ removeRow(index: number): void;
38
+ clear(): void;
39
+ sortByColumn(index: number): void;
40
+ _makeEditable(editable: boolean, htmlCell: HTMLElement, columnIndex: number, row: any[], column: ListViewColumn): void;
41
+ _addCellToRow(row: any[], htmlRow: HTMLElement, colNo: number, value: any): HTMLSpanElement;
42
+ addRow(row: any[]): void;
43
+ deselectRows(): void;
44
+ selectRow(index: number): void;
45
+ getSelectedRowIndex(): number;
46
+ getSelectedRow(): any[];
47
+ getColumnCount(): number;
48
+ getRowCount(): number;
49
+ getColumns(): ListViewColumn[];
50
+ changeCellValue(rowIndex: number, columnIndex: number, newValue: string): void;
51
+ getRow(index: number): any[];
52
+ getRows(): any[][];
53
+ getColumn(index: number): ListViewColumn;
54
+ renameColumn(index: number, newName: string): void;
55
+ getColumnValues(index: number): any[];
56
+ setCellContent(rowIndex: number, columnIndex: number, newValue: any): void;
57
+ getCellContent(rowIndex: number, columnIndex: number): any;
58
+ }
59
+ export { ListView, ListViewColumn, StringListViewColumn, IntListViewColumn, FloatListViewColumn };
package/dist/Math.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ declare const RAD_TO_DEGREES: number;
2
+ declare const DEGREES_TO_RAD: number;
3
+ declare class Vector2 {
4
+ x: number;
5
+ y: number;
6
+ constructor(x: number, y: number);
7
+ getAngleToOtherInRadians(other: Vector2): number;
8
+ getAngleToOtherInDegrees(other: Vector2): number;
9
+ getRotatedInRadians(radians: number): Vector2;
10
+ getRotatedInDegrees(degrees: number): Vector2;
11
+ rotateInRadians(radians: number): void;
12
+ rotateInDegrees(degrees: number): void;
13
+ getScalarProduct(other: Vector2): number;
14
+ scale(factor: number): void;
15
+ getScaled(factor: number): Vector2;
16
+ getLength(): number;
17
+ normalize(): void;
18
+ getNormalized(): Vector2;
19
+ setLength(length: number): void;
20
+ getWithLength(length: number): Vector2;
21
+ }
22
+ declare function rectContains(rect: DOMRect, x: number, y: number): boolean;
23
+ export { Vector2, rectContains, RAD_TO_DEGREES, DEGREES_TO_RAD };
package/dist/Menu.d.ts ADDED
@@ -0,0 +1,28 @@
1
+ import { MenuBar } from './MenuBar';
2
+ import { Widget } from './Widget';
3
+ import { Vector2 } from './Math';
4
+ declare class MenuEntry {
5
+ name: string;
6
+ element: HTMLElement;
7
+ constructor(name: string, element: HTMLElement);
8
+ }
9
+ declare class Menu extends Widget {
10
+ name: string;
11
+ private _submenus;
12
+ menuEntryPanel: HTMLDivElement;
13
+ _menuEntries: MenuEntry[];
14
+ private _x;
15
+ private _y;
16
+ constructor(name: string);
17
+ getParentMenuBar(): MenuBar;
18
+ getParentMenu(): Menu;
19
+ isShown(): boolean;
20
+ getPos(): Vector2;
21
+ show(x?: number, y?: number): void;
22
+ hide(): void;
23
+ addEntry(title: string, callback: () => void, canExecuteCallback?: () => boolean): void;
24
+ addSubMenu(menu: Menu): void;
25
+ addSeparator(): void;
26
+ clearEntries(): void;
27
+ }
28
+ export { Menu };
@@ -0,0 +1,10 @@
1
+ import { Widget } from './Widget';
2
+ import { Menu } from './Menu';
3
+ declare class MenuBar extends Widget {
4
+ menus: Menu[];
5
+ activeMenu?: Menu;
6
+ constructor();
7
+ addMenu(menu: Menu): void;
8
+ hideMenus(): void;
9
+ }
10
+ export { MenuBar };
@@ -0,0 +1,32 @@
1
+ import { Dialog } from './Dialog';
2
+ declare class MessageDialogButton {
3
+ label: string;
4
+ callback: (dlg: Dialog) => void;
5
+ isContinue: boolean;
6
+ isCancel: boolean;
7
+ constructor(label: string, callback: (dlg: Dialog) => void, isContinue: boolean, isCancel: boolean);
8
+ }
9
+ declare class MessageDialog extends Dialog {
10
+ private _cancelOption;
11
+ private _continueOption;
12
+ private _boundKeyEvent;
13
+ constructor(title: string, text: string, buttons: MessageDialogButton[], hasCloseButton: boolean);
14
+ showModal(): void;
15
+ _clickButton(button: HTMLButtonElement): void;
16
+ hide(): void;
17
+ }
18
+ declare class OkMessageDialog extends MessageDialog {
19
+ constructor(title: string, text: string, hasCloseButton: boolean, callback: (dlg: Dialog) => void);
20
+ }
21
+ declare class InputDialog extends Dialog {
22
+ inputElement: HTMLInputElement;
23
+ private _cancelOption;
24
+ private _continueOption;
25
+ private _boundKeyEvent;
26
+ constructor(title: string, text: string, value: string, buttons: MessageDialogButton[], hasCloseButton: boolean);
27
+ getValue(): string;
28
+ showModal(): void;
29
+ _clickButton(button: HTMLButtonElement): void;
30
+ hide(): void;
31
+ }
32
+ export { MessageDialog, OkMessageDialog, InputDialog, MessageDialogButton };