Skip to content

Commit b6f8475

Browse files
MADEVALCopilot
andcommitted
Version 2.0
Co-authored-by: Copilot <copilot@github.com>
1 parent 89836ee commit b6f8475

17 files changed

Lines changed: 3723 additions & 233 deletions

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false

.github/workflows/minify.yml

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build and Minify
1+
name: Build, Test and Minify
22

33
on:
44
push:
@@ -11,36 +11,48 @@ jobs:
1111
runs-on: ubuntu-latest
1212

1313
steps:
14-
- uses: actions/checkout@v3
14+
- uses: actions/checkout@v4
1515

1616
- name: Setup Node.js
17-
uses: actions/setup-node@v3
17+
uses: actions/setup-node@v4
1818
with:
19-
node-version: '16'
20-
# Удаляем опцию cache, которая вызывает ошибку
21-
# cache: 'npm'
19+
node-version: '20'
20+
cache: 'npm'
2221

2322
- name: Install dependencies
2423
run: npm install
2524

26-
- name: Minify GStime.js
25+
- name: Run tests
26+
run: npm test
27+
28+
- name: Build minified bundle
2729
run: npm run build
2830

31+
- name: Report bundle size
32+
run: npm run size
33+
2934
- name: Commit minified file
30-
uses: stefanzweifel/git-auto-commit-action@v4
35+
if: github.event_name == 'push'
36+
uses: stefanzweifel/git-auto-commit-action@v5
3137
with:
3238
commit_message: "Build: Minify GStime.js"
33-
file_pattern: 'GStime.min.js'
39+
file_pattern: 'GStime.min.js GStime.min.js.map'
3440

3541
- name: Send success message to Telegram
36-
if: success()
42+
if: success() && env.TELEGRAM_BOT_TOKEN != ''
43+
env:
44+
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
45+
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
3746
run: |
38-
curl -X POST "https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendMessage" \
39-
-d chat_id="${{ secrets.TELEGRAM_CHAT_ID }}" \
47+
curl -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \
48+
-d chat_id="${TELEGRAM_CHAT_ID}" \
4049
-d text="🟢 $GITHUB_REPOSITORY [${{ github.event.pusher.name }}] - OK"
4150
- name: Send error message to Telegram
42-
if: failure()
51+
if: failure() && env.TELEGRAM_BOT_TOKEN != ''
52+
env:
53+
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
54+
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
4355
run: |
44-
curl -X POST "https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendMessage" \
45-
-d chat_id="${{ secrets.TELEGRAM_CHAT_ID }}" \
56+
curl -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \
57+
-d chat_id="${TELEGRAM_CHAT_ID}" \
4658
-d text="🔴 $GITHUB_REPOSITORY [${{ github.event.pusher.name }}] - ERROR"

.gitignore

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Node
2+
node_modules/
3+
npm-debug.log*
4+
yarn-debug.log*
5+
yarn-error.log*
6+
pnpm-debug.log*
7+
.pnpm-store/
8+
9+
# Build / coverage
10+
coverage/
11+
.nyc_output/
12+
*.tsbuildinfo
13+
14+
# Editor / OS
15+
.vscode/
16+
.idea/
17+
.DS_Store
18+
Thumbs.db
19+
*.swp
20+
*.swo
21+
22+
# Env
23+
.env
24+
.env.local
25+
.env.*.local
26+
27+
# Vitest
28+
.vitest-cache/

.npmignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.git
2+
.github
3+
node_modules
4+
examples
5+
tests
6+
scripts
7+
coverage
8+
*.log
9+
.vscode
10+
.editorconfig
11+
.eslintrc*
12+
.prettierrc*
13+
README_*.md

CHANGELOG.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
## [2.0.0]
6+
7+
### Breaking
8+
- `createHTML(html)` now returns an `Element[]` instead of a single `Element`. Multi-root HTML strings are supported.
9+
- The library is now distributed as UMD (CommonJS / AMD / global). Importing in Node no longer silently no-ops.
10+
- `colorAnimate` now always emits `rgba(...)` to keep alpha consistent.
11+
12+
### Fixed
13+
- `.off(event, handler)` now actually removes handlers attached via `.on()` (previous versions wrapped the user callback in an internal closure, making removal impossible).
14+
- `.on(event, selector, handler)` delegation now uses `target.matches(selector)`, scoped to the bound element. Previously it queried `document.querySelectorAll(selector)` on every event, broke for dynamically inserted elements, and could fire across unrelated containers.
15+
- `.animate()` honours per-property units. `opacity` is now correctly treated as unitless (was emitted as `"0.5px"` and silently rejected by browsers, breaking `fadeIn`/`fadeOut`).
16+
- `.colorAnimate()` no longer collapses all elements to a single key (used `Element` as object key, coerced via `toString()`); now uses a `WeakMap`. Supports named colors and `#RGBA`.
17+
- `.slideUp()` / `.slideDown()` add a fallback timeout, so the callback always fires even when `transitionend` is suppressed (`prefers-reduced-motion`, hidden tabs, `transition: none`). `slideDown` no longer permanently overrides `display`.
18+
- `.remove()` no longer crashes when an element has no parent.
19+
- `GStime.ajax()`:
20+
- Uses `AbortController` so `timeout` actually aborts the request.
21+
- Strips non-fetch keys before passing to `fetch()`.
22+
- Adds `success` and `complete` callbacks; `error` is invoked before `reject`.
23+
- Default `credentials: "same-origin"`, `mode: "cors"`.
24+
- `text/javascript` and `text/*` are returned as text; only `xml` content types are parsed via `DOMParser`.
25+
26+
### Added
27+
- `GStime.noConflict()` to restore the previous `window.$`.
28+
- `$.fn` alias of `GStime.prototype` for plugin-style extension.
29+
- `$(function)` is a shorthand for `GStime.ready(function)`.
30+
- TypeScript declarations (`GStime.d.ts`).
31+
- Cross-platform build script (`scripts/build.js`) using `terser` + source map.
32+
- Vitest test suite (jsdom environment).
33+
34+
## [1.4.0]
35+
- Last release of the IIFE/browser-only build. See git history.

GStime.d.ts

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
// Type definitions for GStime 2.0.0
2+
3+
export interface AjaxSettings {
4+
url: string;
5+
method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD" | string;
6+
headers?: Record<string, string>;
7+
data?: unknown;
8+
timeout?: number;
9+
credentials?: RequestCredentials;
10+
mode?: RequestMode;
11+
cache?: RequestCache;
12+
redirect?: RequestRedirect;
13+
referrer?: string;
14+
integrity?: string;
15+
beforeSend?: () => boolean | void;
16+
success?: (data: unknown) => void;
17+
error?: (error: Error) => void;
18+
complete?: () => void;
19+
}
20+
21+
export interface Offset {
22+
top: number;
23+
left: number;
24+
}
25+
26+
export type GStimeSelector =
27+
| string
28+
| Element
29+
| Document
30+
| Window
31+
| NodeList
32+
| HTMLCollection
33+
| Element[]
34+
| (() => void)
35+
| null
36+
| undefined;
37+
38+
export class GStime {
39+
constructor(selector?: GStimeSelector);
40+
elements: Element[];
41+
42+
createHTML(html: string): Element[];
43+
each(callback: (this: Element, index: number, el: Element) => void): this;
44+
45+
on(event: string, callback: (this: Element, e: Event) => void): this;
46+
on(event: string, selector: string, callback: (this: Element, e: Event) => void): this;
47+
off(event: string, callback?: (this: Element, e: Event) => void): this;
48+
49+
val(): string | undefined;
50+
val(newVal: string): this;
51+
52+
append(html: string): this;
53+
prepend(html: string): this;
54+
before(html: string): this;
55+
after(html: string): this;
56+
remove(): this;
57+
58+
html(): string | undefined;
59+
html(html: string): this;
60+
61+
css(prop: string): string | undefined;
62+
css(prop: string, value: string | number): this;
63+
css(properties: Record<string, string | number>): this;
64+
65+
hide(): this;
66+
show(): this;
67+
toggle(): this;
68+
clone(): GStime;
69+
70+
animate(properties: Record<string, number | string>, duration: number, callback?: () => void): this;
71+
fadeIn(duration: number, callback?: () => void): this;
72+
fadeOut(duration: number, callback?: () => void): this;
73+
slideUp(duration: number, callback?: (this: Element) => void): this;
74+
slideDown(duration: number, callback?: (this: Element) => void): this;
75+
slideToggle(duration: number, callback?: (this: Element) => void): this;
76+
colorAnimate(properties: Record<string, string>, duration: number, callback?: () => void): this;
77+
78+
hasClass(className: string): boolean;
79+
addClass(className: string): this;
80+
removeClass(className: string): this;
81+
toggleClass(className: string): this;
82+
83+
attr(name: string): string | null | undefined;
84+
attr(name: string, value: string): this;
85+
removeAttr(name: string): this;
86+
87+
width(): number | undefined;
88+
width(value: number | string): this;
89+
height(): number | undefined;
90+
height(value: number | string): this;
91+
92+
offset(): Offset | undefined;
93+
position(): Offset | undefined;
94+
95+
parent(): GStime;
96+
children(): GStime;
97+
siblings(): GStime;
98+
find(selector: string): GStime;
99+
closest(selector: string): GStime;
100+
101+
static ajax(settings: AjaxSettings): Promise<unknown>;
102+
static get(url: string, data?: unknown, options?: Partial<AjaxSettings>): Promise<unknown>;
103+
static post(url: string, data?: unknown, options?: Partial<AjaxSettings>): Promise<unknown>;
104+
static put(url: string, data?: unknown, options?: Partial<AjaxSettings>): Promise<unknown>;
105+
static delete(url: string, data?: unknown, options?: Partial<AjaxSettings>): Promise<unknown>;
106+
107+
static each<T>(obj: T[] | Record<string, T>, callback: (this: T, key: string | number, value: T) => void): typeof obj;
108+
static map<T, U>(obj: T[], callback: (value: T, index: number) => U): U[];
109+
static map<T, U>(obj: Record<string, T>, callback: (this: T, key: string, value: T) => U): Record<string, U>;
110+
static ready(callback: () => void): void;
111+
static noConflict(): GStimeFactory;
112+
}
113+
114+
export interface GStimeFactory {
115+
(selector?: GStimeSelector): GStime;
116+
fn: GStime;
117+
ajax: typeof GStime.ajax;
118+
get: typeof GStime.get;
119+
post: typeof GStime.post;
120+
put: typeof GStime.put;
121+
delete: typeof GStime.delete;
122+
each: typeof GStime.each;
123+
map: typeof GStime.map;
124+
ready: typeof GStime.ready;
125+
noConflict: typeof GStime.noConflict;
126+
}
127+
128+
declare const _default: { GStime: typeof GStime; $: GStimeFactory };
129+
export default _default;
130+
export const $: GStimeFactory;
131+
132+
declare global {
133+
interface Window {
134+
GStime: typeof GStime;
135+
$: GStimeFactory;
136+
}
137+
}

0 commit comments

Comments
 (0)