cotomy 0.1.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/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+ Copyright (c) 2025 Yasuhiro Arakawa
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # Cotomy
2
+
3
+ A lightweight framework for managing form behavior and page controllers in web applications.
4
+ Ideal for SPA (Single Page Application) or traditional web apps with dynamic form operations.
5
+
6
+ ## Installation
7
+
8
+ To install Cotomy in your project, run the following command:
9
+
10
+ ```bash
11
+ npm i cotomy
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ Cotomy will continue to expand with more detailed usage instructions and code examples added to the README in the future.
17
+ For the latest updates, please check the official documentation or repository regularly.
18
+
19
+ The core of Cotomy is `CotomyElement`, which is constructed as a wrapper for `Element`.
20
+ By passing HTML and CSS strings to the constructor, it is possible to generate Element designs with a limited scope.
21
+
22
+ ```typescript
23
+ const element = new CotomyElement(/* html */\`
24
+ <div>
25
+ <p>Text</p>
26
+ </div>
27
+ \`, /* css */\`
28
+ [scope] {
29
+ display: block;
30
+ }
31
+ [scope] > p {
32
+ text-align: center;
33
+ }
34
+ \`);
35
+ ```
36
+
37
+ ## License
38
+
39
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
40
+
41
+ ## Warning
42
+
43
+ This project is in its early stages, and the API is still evolving.
44
+ Since the version is below `1.0.0`, breaking changes may occur without prior notice.
45
+
46
+ ## Contact
47
+
48
+ You can reach out to me at: [yshr1920@gmail.com](mailto:yshr1920@gmail.com)
49
+ GitHub repository: [https://github.com/yshr1920/cotomy](https://github.com/yshr1920/cotomy)
package/dist/api.d.ts ADDED
@@ -0,0 +1,80 @@
1
+ import { CotomyElementWrap } from "./view";
2
+ export declare class CotomyResponseJsonParseException extends Error {
3
+ constructor(message?: string);
4
+ }
5
+ export declare class CotomyInvalidFormDataBodyException extends Error {
6
+ constructor(message?: string);
7
+ }
8
+ export declare class CotomyRestApiResponse {
9
+ private readonly _response?;
10
+ private _json;
11
+ private _map;
12
+ constructor(_response?: (Response | null) | undefined);
13
+ get available(): boolean;
14
+ get empty(): boolean;
15
+ get ok(): boolean;
16
+ get status(): number;
17
+ get statusText(): string;
18
+ get headers(): Headers;
19
+ textAsync(): Promise<string>;
20
+ blobAsync(): Promise<Blob>;
21
+ objectAsync<T extends object>(defaultValue?: T): Promise<any>;
22
+ }
23
+ export declare class CotomyViewRenderer {
24
+ private readonly element;
25
+ private _locale;
26
+ private _currency;
27
+ private _renderers;
28
+ private _builded;
29
+ constructor(element: CotomyElementWrap);
30
+ protected get locale(): string;
31
+ protected get currency(): string;
32
+ renderer(type: string, callback: (element: CotomyElementWrap, value: any) => void): this;
33
+ get builded(): boolean;
34
+ build(): this;
35
+ applyAsync(respose: CotomyRestApiResponse): Promise<this>;
36
+ }
37
+ export interface ICotomyRestApiOptions {
38
+ baseUrl?: string | null;
39
+ headers?: Record<string, string> | null;
40
+ credentials?: RequestCredentials | null;
41
+ redirect?: RequestRedirect | null;
42
+ cache?: RequestCache | null;
43
+ referrerPolicy?: ReferrerPolicy | null;
44
+ mode?: RequestMode | null;
45
+ keepalive?: boolean | null;
46
+ integrity?: string | null;
47
+ unauthorizedHandler?: ((response: CotomyRestApiResponse) => void) | null;
48
+ }
49
+ export interface ICotomyRestSubmitForm {
50
+ method: string;
51
+ action: string;
52
+ body: globalThis.FormData | Record<string, string> | any;
53
+ }
54
+ export declare class CotomyRestApi {
55
+ private readonly _options;
56
+ private readonly _abortController;
57
+ constructor(_options?: ICotomyRestApiOptions);
58
+ get baseUrl(): string;
59
+ get headers(): Record<string, string>;
60
+ get credentials(): RequestCredentials;
61
+ get redirect(): RequestRedirect;
62
+ get cache(): RequestCache;
63
+ get referrerPolicy(): ReferrerPolicy;
64
+ get mode(): RequestMode;
65
+ get keepalive(): boolean;
66
+ get integrity(): string;
67
+ get abortController(): AbortController;
68
+ get unauthorizedHandler(): (response: CotomyRestApiResponse) => void;
69
+ private requestAsync;
70
+ getAsync(path: string, parameters?: globalThis.FormData | Record<string, string | number> | null): Promise<CotomyRestApiResponse>;
71
+ postAsync(path: string, body: globalThis.FormData | Record<string, string | number> | any): Promise<CotomyRestApiResponse>;
72
+ putAsync(path: string, body: globalThis.FormData | Record<string, string | number> | any): Promise<CotomyRestApiResponse>;
73
+ patchAsync(path: string, body: globalThis.FormData | Record<string, string | number> | any): Promise<CotomyRestApiResponse>;
74
+ deleteAsync(path: string): Promise<CotomyRestApiResponse>;
75
+ headAsync(path: string): Promise<CotomyRestApiResponse>;
76
+ optionsAsync(path: string): Promise<CotomyRestApiResponse>;
77
+ traceAsync(path: string): Promise<CotomyRestApiResponse>;
78
+ connectAsync(path: string): Promise<CotomyRestApiResponse>;
79
+ submitAsync(form: ICotomyRestSubmitForm): Promise<CotomyRestApiResponse>;
80
+ }
package/dist/form.d.ts ADDED
@@ -0,0 +1,54 @@
1
+ import { CotomyRestApi, CotomyRestApiResponse, CotomyViewRenderer } from "./api";
2
+ import { CotomyElementWrap } from "./view";
3
+ export declare class CotomyActionEvent extends Event {
4
+ action: string;
5
+ constructor(action: string);
6
+ }
7
+ export declare abstract class CotomyFormBase extends CotomyElementWrap {
8
+ constructor(element: HTMLFormElement | string, css?: string | null);
9
+ get formId(): string;
10
+ method(): string;
11
+ actionUri(): string;
12
+ get autoComplete(): boolean;
13
+ set autoComplete(value: boolean);
14
+ reload(): void;
15
+ get builded(): boolean;
16
+ build(): this;
17
+ submit(): void;
18
+ protected abstract submitAsync(e: Event): Promise<void>;
19
+ action(handle: ((event: CotomyActionEvent) => void | Promise<void>) | string): this;
20
+ }
21
+ export declare class CotomyQueryForm extends CotomyFormBase {
22
+ constructor(element: HTMLFormElement | string, css?: string | null);
23
+ method(): string;
24
+ protected submitAsync(e: Event): Promise<void>;
25
+ }
26
+ export declare class CotomyApiForm extends CotomyFormBase {
27
+ private _apiClient;
28
+ private _unauthorizedHandler;
29
+ constructor(element: HTMLFormElement | string, css?: string | null);
30
+ apiClient(): CotomyRestApi;
31
+ actionUri(): string;
32
+ get identifier(): string | undefined;
33
+ protected setIncrementedId(response: CotomyRestApiResponse): void;
34
+ get identifierInputs(): CotomyElementWrap[];
35
+ get identifierString(): string;
36
+ get autoIncrement(): boolean;
37
+ method(): string;
38
+ formData(): globalThis.FormData;
39
+ protected submitAsync(e: Event): Promise<void>;
40
+ protected submitToApiAsync(formData: globalThis.FormData): Promise<CotomyRestApiResponse>;
41
+ unauthorized(handle: (response: CotomyRestApiResponse) => void): this;
42
+ }
43
+ export declare class CotomyFillApiForm extends CotomyApiForm {
44
+ private _fillers;
45
+ constructor(element: HTMLFormElement | string, css?: string | null);
46
+ filler(type: string, callback: (input: CotomyElementWrap, value: any) => void): this;
47
+ build(): this;
48
+ protected submitToApiAsync(formData: globalThis.FormData): Promise<CotomyRestApiResponse>;
49
+ reload(): void;
50
+ loadActionUri(): string;
51
+ renderer(): CotomyViewRenderer;
52
+ loadAsync(): Promise<CotomyRestApiResponse>;
53
+ protected fillAsync(response: CotomyRestApiResponse): Promise<void>;
54
+ }
@@ -0,0 +1,4 @@
1
+ export type { CotomyInvalidFormDataBodyException, CotomyResponseJsonParseException, CotomyRestApi, CotomyRestApiResponse, CotomyViewRenderer } from "./api";
2
+ export type { CotomyActionEvent, CotomyApiForm, CotomyFillApiForm, CotomyFormBase, CotomyQueryForm } from "./form";
3
+ export type { CotomyPageController, CotomyUrl } from "./page";
4
+ export type { CotomyElementWrap, CotomyMetaElement, CotomyWindow } from "./view";
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Cotomy=t():e.Cotomy=t()}(this,()=>(()=>{"use strict";var e={};return e.default})());
package/dist/page.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ import { CotomyFormBase } from "./form";
2
+ import { CotomyElementWrap } from "./view";
3
+ export declare class CotomyUrl {
4
+ static location(): CotomyUrl;
5
+ private _url;
6
+ constructor(url?: string | null);
7
+ private current;
8
+ get url(): string;
9
+ get path(): string;
10
+ get segments(): string[];
11
+ get query(): string;
12
+ get parameters(): {
13
+ [key: string]: string;
14
+ };
15
+ redirect(): void;
16
+ }
17
+ export declare class CotomyPageController {
18
+ private static _instance;
19
+ static set<T extends CotomyPageController = CotomyPageController>(type: new () => T): T;
20
+ protected setForm<T extends CotomyFormBase = CotomyFormBase>(form: T): T;
21
+ protected initializeAsync(): Promise<void>;
22
+ get body(): CotomyElementWrap;
23
+ protected get uri(): CotomyUrl;
24
+ }
package/dist/view.d.ts ADDED
@@ -0,0 +1,194 @@
1
+ export declare class CotomyElementWrap {
2
+ protected static createHTMLElement(html: string): HTMLElement;
3
+ static create<T extends CotomyElementWrap = CotomyElementWrap>(html: string, type?: typeof CotomyElementWrap): T;
4
+ static first<T extends CotomyElementWrap = CotomyElementWrap>(selector: string, type?: typeof CotomyElementWrap): T;
5
+ static find<T extends CotomyElementWrap = CotomyElementWrap>(selector: string, type?: typeof CotomyElementWrap): T[];
6
+ static byId<T extends CotomyElementWrap = CotomyElementWrap>(id: string, type?: typeof CotomyElementWrap): T;
7
+ static contains(selector: string): boolean;
8
+ static empty<T extends CotomyElementWrap = CotomyElementWrap>(type?: typeof CotomyElementWrap): T;
9
+ private _element;
10
+ private _parentElement;
11
+ private _removed;
12
+ constructor(element: string | HTMLElement, css?: string | null);
13
+ private _scopeId;
14
+ get scopeId(): string;
15
+ get scopedSelector(): string;
16
+ get stylable(): boolean;
17
+ useScopedCss(css: string): this;
18
+ static readonly LISTEN_LAYOUT_EVENTS_ATTRIBUTE: string;
19
+ listenLayoutEvents(): this;
20
+ get id(): string | null | undefined;
21
+ setId(id: string): this;
22
+ get element(): HTMLElement;
23
+ get tagname(): string;
24
+ is(selector: string): boolean;
25
+ get empty(): boolean;
26
+ get attached(): boolean;
27
+ get readonly(): boolean;
28
+ set readonly(readonly: boolean);
29
+ get value(): string;
30
+ set value(val: string);
31
+ get text(): string;
32
+ set text(text: string);
33
+ get html(): string;
34
+ set html(html: string);
35
+ convertUtcToLocal(format?: string, recursive?: boolean): this;
36
+ setFocus(): void;
37
+ get visible(): boolean;
38
+ get enabled(): boolean;
39
+ set enabled(value: boolean);
40
+ remove(): void;
41
+ clone(): CotomyElementWrap;
42
+ clean(): void;
43
+ get width(): number;
44
+ set width(width: number);
45
+ get height(): number;
46
+ set height(height: number);
47
+ get innerWidth(): number;
48
+ get innerHeight(): number;
49
+ get outerWidth(): number;
50
+ get outerHeight(): number;
51
+ get scrollHeight(): number;
52
+ get scrollWidth(): number;
53
+ get scrollTop(): number;
54
+ get position(): {
55
+ top: number;
56
+ left: number;
57
+ };
58
+ get absolutePosition(): {
59
+ top: number;
60
+ left: number;
61
+ };
62
+ get screenPosition(): {
63
+ top: number;
64
+ left: number;
65
+ };
66
+ get rect(): {
67
+ top: number;
68
+ left: number;
69
+ width: number;
70
+ height: number;
71
+ };
72
+ get innerRect(): {
73
+ top: number;
74
+ left: number;
75
+ width: number;
76
+ height: number;
77
+ };
78
+ get outerRect(): {
79
+ top: number;
80
+ left: number;
81
+ width: number;
82
+ height: number;
83
+ };
84
+ get padding(): {
85
+ top: number;
86
+ right: number;
87
+ bottom: number;
88
+ left: number;
89
+ };
90
+ get margin(): {
91
+ top: number;
92
+ right: number;
93
+ bottom: number;
94
+ left: number;
95
+ };
96
+ get inViewport(): boolean;
97
+ get isAboveViewport(): boolean;
98
+ get isBelowViewport(): boolean;
99
+ get isLeftViewport(): boolean;
100
+ get isRightViewport(): boolean;
101
+ hasAttribute(name: string): boolean;
102
+ attribute(name: string): string | null | undefined;
103
+ setAttribute(name: string, value?: string | number | undefined): this;
104
+ removeAttribute(name: string): void;
105
+ hasClass(cls: string): boolean;
106
+ addClass(cls: string): this;
107
+ removeClass(cls: string): this;
108
+ setElementStyle(name: string, value: string): this;
109
+ removeElementStyle(name: string): this;
110
+ get computedStyle(): CSSStyleDeclaration;
111
+ style(name: string): string;
112
+ get parent(): CotomyElementWrap;
113
+ get parents(): CotomyElementWrap[];
114
+ hasChildren(selector?: string): boolean;
115
+ children<T extends CotomyElementWrap = CotomyElementWrap>(selector?: string, type?: typeof CotomyElementWrap): T[];
116
+ firstChild<T extends CotomyElementWrap = CotomyElementWrap>(selector?: string, type?: typeof CotomyElementWrap): T;
117
+ lastChild<T extends CotomyElementWrap = CotomyElementWrap>(selector?: string, type?: typeof CotomyElementWrap): T;
118
+ closest<T extends CotomyElementWrap = CotomyElementWrap>(selector: string, type?: typeof CotomyElementWrap): T;
119
+ find<T extends CotomyElementWrap = CotomyElementWrap>(selector: string, type?: typeof CotomyElementWrap): T[];
120
+ first<T extends CotomyElementWrap = CotomyElementWrap>(selector?: string, type?: typeof CotomyElementWrap): T;
121
+ prepend(prepend: CotomyElementWrap): this;
122
+ append(target: CotomyElementWrap): this;
123
+ appends(targets: CotomyElementWrap[]): this;
124
+ appendTo(target: CotomyElementWrap): this;
125
+ appendBefore(append: CotomyElementWrap): this;
126
+ appendAfter(append: CotomyElementWrap): this;
127
+ trigger(event: string, e?: Event | null): this;
128
+ on(event: string, handle: (e: Event) => void | Promise<void>): this;
129
+ once(event: string, handle: (e: Event) => void | Promise<void>): this;
130
+ off(event: string, handle: (e: Event) => void | Promise<void>): this;
131
+ click(handle?: ((e: MouseEvent) => void | Promise<void>) | null): this;
132
+ dblclick(handle?: ((e: MouseEvent) => void | Promise<void>) | null): this;
133
+ mouseover(handle?: ((e: MouseEvent) => void | Promise<void>) | null): this;
134
+ mouseout(handle?: ((e: MouseEvent) => void | Promise<void>) | null): this;
135
+ mousedown(handle?: ((e: MouseEvent) => void | Promise<void>) | null): this;
136
+ mouseup(handle?: ((e: MouseEvent) => void | Promise<void>) | null): this;
137
+ mousemove(handle?: ((e: MouseEvent) => void | Promise<void>) | null): this;
138
+ mouseenter(handle?: ((e: MouseEvent) => void | Promise<void>) | null): this;
139
+ mouseleave(handle?: ((e: MouseEvent) => void | Promise<void>) | null): this;
140
+ dragstart(handle?: ((e: DragEvent) => void | Promise<void>) | null): this;
141
+ dragend(handle?: ((e: DragEvent) => void | Promise<void>) | null): this;
142
+ dragover(handle?: ((e: DragEvent) => void | Promise<void>) | null): this;
143
+ dragenter(handle?: ((e: DragEvent) => void | Promise<void>) | null): this;
144
+ dragleave(handle?: ((e: DragEvent) => void | Promise<void>) | null): this;
145
+ drop(handle?: ((e: DragEvent) => void | Promise<void>) | null): this;
146
+ drag(handle?: ((e: DragEvent) => void | Promise<void>) | null): this;
147
+ removed(handle: ((e: Event) => void | Promise<void>)): this;
148
+ keydown(handle?: ((e: KeyboardEvent) => void | Promise<void>) | null): this;
149
+ keyup(handle?: ((e: KeyboardEvent) => void | Promise<void>) | null): this;
150
+ keypress(handle?: ((e: KeyboardEvent) => void | Promise<void>) | null): this;
151
+ change(handle?: ((e: Event) => void | Promise<void>) | null): this;
152
+ input(handle?: ((e: Event) => void | Promise<void>) | null): this;
153
+ private static _intersectionObserver;
154
+ static get intersectionObserver(): IntersectionObserver;
155
+ inview(handle?: ((e: Event) => void | Promise<void>) | null): this;
156
+ outview(handle?: ((e: Event) => void | Promise<void>) | null): this;
157
+ focus(handle?: ((e: FocusEvent) => void | Promise<void>) | null): this;
158
+ blur(handle?: ((e: FocusEvent) => void | Promise<void>) | null): this;
159
+ focusin(handle?: ((e: FocusEvent) => void | Promise<void>) | null): this;
160
+ focusout(handle?: ((e: FocusEvent) => void | Promise<void>) | null): this;
161
+ filedrop(handle: (files: File[]) => void | Promise<void>): this;
162
+ resize(handle?: ((e: Event) => void | Promise<void>) | null): this;
163
+ scroll(handle?: ((e: Event) => void | Promise<void>) | null): this;
164
+ changelayout(handle?: ((e: Event) => void | Promise<void>) | null): this;
165
+ }
166
+ export declare class CotomyMetaElement extends CotomyElementWrap {
167
+ static get(name: string): CotomyMetaElement;
168
+ get content(): string;
169
+ }
170
+ export declare class CotomyWindow {
171
+ private static _instance;
172
+ static get instance(): CotomyWindow;
173
+ private _body;
174
+ private _mutationObserver;
175
+ initialize(): void;
176
+ get initialized(): boolean;
177
+ get body(): CotomyElementWrap;
178
+ append(e: CotomyElementWrap): void;
179
+ moveNext(focused: CotomyElementWrap, shift?: boolean): void;
180
+ trigger(event: string): void;
181
+ load(handle: (e: Event) => void | Promise<void>): void;
182
+ ready(handle: ((e: Event) => void | Promise<void>)): void;
183
+ on(event: string, handle: (e: Event) => void | Promise<void>): void;
184
+ resize(handle?: ((event: Event) => void | Promise<void>) | null): void;
185
+ scroll(handle?: ((event: Event) => void | Promise<void>) | null): void;
186
+ changeLayout(handle?: ((event: Event) => void | Promise<void>) | null): void;
187
+ pageshow(handle?: ((event: PageTransitionEvent) => void | Promise<void>) | null): void;
188
+ get scrollTop(): number;
189
+ get scrollLeft(): number;
190
+ get width(): number;
191
+ get height(): number;
192
+ get documentWidth(): number;
193
+ get documentHeight(): number;
194
+ }
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "cotomy",
3
+ "version": "0.1.0",
4
+ "main": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
+ "files": ["dist"],
7
+ "scripts": {
8
+ "build": "webpack --mode=production",
9
+ "dev": "webpack --watch",
10
+ "clean": "rm -rf dist",
11
+ "test": "echo \"(optional) add test runner like vitest or jest\"",
12
+ "prepare": "npm run build",
13
+ "release": "npm run clean && npm run build && npm version patch && npm publish",
14
+ "check": "tsc --noEmit",
15
+ "lint": "eslint src --ext .ts",
16
+ "format": "prettier --write src"
17
+ },
18
+ "publishConfig": {
19
+ "access": "public"
20
+ },
21
+ "keywords": [],
22
+ "author": "",
23
+ "license": "MIT",
24
+ "description": "",
25
+ "devDependencies": {
26
+ "ts-loader": "^9.5.2",
27
+ "typescript": "^5.8.3",
28
+ "webpack": "^5.99.9",
29
+ "webpack-cli": "^6.0.1"
30
+ },
31
+ "dependencies": {
32
+ "cuid": "^3.0.0",
33
+ "dayjs": "^1.11.13",
34
+ "http-status-codes": "^2.3.0",
35
+ "locale-currency": "^0.0.4"
36
+ }
37
+ }