@elementalfx/gravity 0.0.0-stage → 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 +21 -0
- package/README.md +125 -2
- package/dist/body.d.ts +52 -0
- package/dist/body.d.ts.map +1 -0
- package/dist/chunks/chunk-HATLEHJ2.js +1430 -0
- package/dist/chunks/chunk-HATLEHJ2.js.map +7 -0
- package/dist/collide.d.ts +18 -0
- package/dist/collide.d.ts.map +1 -0
- package/dist/element.d.ts +73 -0
- package/dist/element.d.ts.map +1 -0
- package/dist/element.js +38 -0
- package/dist/element.js.map +7 -0
- package/dist/global.d.ts +3 -0
- package/dist/global.d.ts.map +1 -0
- package/dist/grab.d.ts +37 -0
- package/dist/grab.d.ts.map +1 -0
- package/dist/gravity.d.ts +35 -0
- package/dist/gravity.d.ts.map +1 -0
- package/dist/gravity.global.js +2 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +7 -0
- package/dist/options.d.ts +62 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/pick.d.ts +18 -0
- package/dist/pick.d.ts.map +1 -0
- package/dist/world.d.ts +61 -0
- package/dist/world.d.ts.map +1 -0
- package/package.json +71 -3
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export type GravityWalls = 'viewport' | 'root';
|
|
2
|
+
export type GravitySplit = false | 'words' | 'letters';
|
|
3
|
+
/**
|
|
4
|
+
* When the page falls by itself:
|
|
5
|
+
* - 'manual': only when you call `drop()` (default)
|
|
6
|
+
* - 'load': as soon as the effect is created
|
|
7
|
+
* - 'konami': ↑ ↑ ↓ ↓ ← → ← → B A toggles it
|
|
8
|
+
* - `{ idle: seconds }`: after the visitor does nothing for that long
|
|
9
|
+
* - `{ click: element or selector }`: when that element is clicked
|
|
10
|
+
*/
|
|
11
|
+
export type GravityTrigger = 'manual' | 'load' | 'konami' | {
|
|
12
|
+
idle: number;
|
|
13
|
+
} | {
|
|
14
|
+
click: Element | string;
|
|
15
|
+
};
|
|
16
|
+
export interface GravityOptions {
|
|
17
|
+
/**
|
|
18
|
+
* Which elements fall. By default the smallest elements that hold text or
|
|
19
|
+
* media (paragraphs, headings, list items, images, buttons…). Give a CSS
|
|
20
|
+
* selector to choose them yourself. Elements marked `data-gravity="ignore"`
|
|
21
|
+
* never fall, and `data-gravity="body"` falls as one piece.
|
|
22
|
+
*/
|
|
23
|
+
selector?: string | null;
|
|
24
|
+
/** Split text into words or letters that fall one by one. Default false. */
|
|
25
|
+
splitText?: GravitySplit;
|
|
26
|
+
/** Downward acceleration in px/s². Default 2000. */
|
|
27
|
+
gravity?: number;
|
|
28
|
+
/** How bouncy elements are, 0 to 1. Default 0.25. */
|
|
29
|
+
bounce?: number;
|
|
30
|
+
/** Surface friction, 0 to 1. Default 0.5. */
|
|
31
|
+
friction?: number;
|
|
32
|
+
/** Random spin added as elements start to fall, in rad/s. Default 0.6. */
|
|
33
|
+
spin?: number;
|
|
34
|
+
/**
|
|
35
|
+
* Where elements land: the bottom of the visible 'viewport', or the edges of
|
|
36
|
+
* the 'root' element. Defaults to 'viewport' for the page, 'root' otherwise.
|
|
37
|
+
*/
|
|
38
|
+
walls?: GravityWalls | null;
|
|
39
|
+
/** Only elements on screen when it drops fall. Default true. */
|
|
40
|
+
onlyVisible?: boolean;
|
|
41
|
+
/** Most elements that fall at once. Default 400. */
|
|
42
|
+
maxBodies?: number;
|
|
43
|
+
/** Drag and throw fallen elements with the mouse or a finger. Default true. */
|
|
44
|
+
interactive?: boolean;
|
|
45
|
+
/** When the page falls by itself. Default 'manual'. */
|
|
46
|
+
trigger?: GravityTrigger;
|
|
47
|
+
/** Escape puts everything back. Default true. */
|
|
48
|
+
restoreOnEscape?: boolean;
|
|
49
|
+
/** Seconds the trip back into place takes. Default 0.9. */
|
|
50
|
+
restoreDuration?: number;
|
|
51
|
+
/** Do nothing when the user prefers reduced motion. Default true. */
|
|
52
|
+
respectReducedMotion?: boolean;
|
|
53
|
+
}
|
|
54
|
+
export type ResolvedGravityOptions = Required<Omit<GravityOptions, 'selector' | 'walls'>> & {
|
|
55
|
+
selector: string | null;
|
|
56
|
+
walls: GravityWalls | null;
|
|
57
|
+
};
|
|
58
|
+
export declare const defaults: ResolvedGravityOptions;
|
|
59
|
+
export declare function resolveOptions(options: GravityOptions, base?: ResolvedGravityOptions): ResolvedGravityOptions;
|
|
60
|
+
/** Reads a trigger from an attribute: `load`, `konami`, `idle 30` or `click #button`. */
|
|
61
|
+
export declare function parseTrigger(value: string): GravityTrigger;
|
|
62
|
+
//# sourceMappingURL=options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG,UAAU,GAAG,MAAM,CAAC;AAC/C,MAAM,MAAM,YAAY,GAAG,KAAK,GAAG,OAAO,GAAG,SAAS,CAAC;AAEvD;;;;;;;GAOG;AACH,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,OAAO,GAAG,MAAM,CAAA;CAAE,CAAC;AAE3G,MAAM,WAAW,cAAc;IAC7B;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,4EAA4E;IAC5E,SAAS,CAAC,EAAE,YAAY,CAAC;IACzB,oDAAoD;IACpD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,qDAAqD;IACrD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,6CAA6C;IAC7C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,0EAA0E;IAC1E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,KAAK,CAAC,EAAE,YAAY,GAAG,IAAI,CAAC;IAC5B,gEAAgE;IAChE,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,oDAAoD;IACpD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+EAA+E;IAC/E,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,uDAAuD;IACvD,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,iDAAiD;IACjD,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,2DAA2D;IAC3D,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,qEAAqE;IACrE,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC;AAED,MAAM,MAAM,sBAAsB,GAAG,QAAQ,CAAC,IAAI,CAAC,cAAc,EAAE,UAAU,GAAG,OAAO,CAAC,CAAC,GAAG;IAC1F,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,KAAK,EAAE,YAAY,GAAG,IAAI,CAAC;CAC5B,CAAC;AAEF,eAAO,MAAM,QAAQ,EAAE,sBAetB,CAAC;AAEF,wBAAgB,cAAc,CAAC,OAAO,EAAE,cAAc,EAAE,IAAI,GAAE,sBAAiC,GAAG,sBAAsB,CAOvH;AAED,yFAAyF;AACzF,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,cAAc,CAU1D"}
|
package/dist/pick.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { GravitySplit } from './options';
|
|
2
|
+
/**
|
|
3
|
+
* Finds the elements that fall: the smallest ones that show text or media, so
|
|
4
|
+
* a paragraph falls as one piece while the section around it stays put.
|
|
5
|
+
*/
|
|
6
|
+
export declare function pickElements(root: Element, selector: string | null, onlyVisible: boolean, max: number): Element[];
|
|
7
|
+
export interface SplitResult {
|
|
8
|
+
/** Elements that fall: word or letter spans, plus media inside the split elements. */
|
|
9
|
+
bodies: Element[];
|
|
10
|
+
/** Puts the original text nodes back. */
|
|
11
|
+
undo(): void;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Wraps every word (or letter) of text inside `elements` in an inline-block
|
|
15
|
+
* span so each can fall on its own. Media and form controls inside fall whole.
|
|
16
|
+
*/
|
|
17
|
+
export declare function splitText(elements: Element[], mode: Exclude<GravitySplit, false>, max: number): SplitResult;
|
|
18
|
+
//# sourceMappingURL=pick.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pick.d.ts","sourceRoot":"","sources":["../src/pick.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAiC9C;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,EAAE,CAwDjH;AAoBD,MAAM,WAAW,WAAW;IAC1B,sFAAsF;IACtF,MAAM,EAAE,OAAO,EAAE,CAAC;IAClB,yCAAyC;IACzC,IAAI,IAAI,IAAI,CAAC;CACd;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,YAAY,EAAE,KAAK,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,WAAW,CAwE3G"}
|
package/dist/world.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A compact 2D rigid-body engine for boxes and circles, in CSS px and seconds.
|
|
3
|
+
* Box-box contacts use separating axes and edge clipping, and the solver uses
|
|
4
|
+
* sequential impulses with warm starting (after Erin Catto's Box2D Lite).
|
|
5
|
+
* Bodies that come to rest fall asleep and cost nothing until disturbed.
|
|
6
|
+
*/
|
|
7
|
+
import type { Body } from './body';
|
|
8
|
+
import { Grab } from './grab';
|
|
9
|
+
export interface WorldOptions {
|
|
10
|
+
/** Downward acceleration in px/s². Default 2000. */
|
|
11
|
+
gravity?: number;
|
|
12
|
+
/** Solver iterations per substep. Default 6. */
|
|
13
|
+
iterations?: number;
|
|
14
|
+
/**
|
|
15
|
+
* Fixed simulation rate in steps per second. `step(dt)` runs as many fixed
|
|
16
|
+
* substeps as fit in `dt`. Stacks of boxes only stand reliably at around
|
|
17
|
+
* 240 Hz with a sequential-impulse solver, so that is the default.
|
|
18
|
+
*/
|
|
19
|
+
rate?: number;
|
|
20
|
+
}
|
|
21
|
+
export declare class World {
|
|
22
|
+
bodies: Body[];
|
|
23
|
+
gravity: number;
|
|
24
|
+
iterations: number;
|
|
25
|
+
rate: number;
|
|
26
|
+
private arbiters;
|
|
27
|
+
private grabs;
|
|
28
|
+
private pending;
|
|
29
|
+
constructor(options?: WorldOptions);
|
|
30
|
+
add(body: Body): Body;
|
|
31
|
+
remove(body: Body): void;
|
|
32
|
+
clear(): void;
|
|
33
|
+
/** Start dragging `body` by the world point (x, y). Move it with `grab.moveTo`. */
|
|
34
|
+
grab(body: Body, x: number, y: number): Grab;
|
|
35
|
+
release(grab: Grab): void;
|
|
36
|
+
/**
|
|
37
|
+
* Wake every body touching `body`, e.g. before pulling it out of a pile.
|
|
38
|
+
* Goes by bounds rather than contacts, since two sleeping bodies keep none.
|
|
39
|
+
*/
|
|
40
|
+
wakeTouching(body: Body): void;
|
|
41
|
+
/** Put every body to sleep at once, as one island, e.g. to stop a pile that keeps fidgeting. */
|
|
42
|
+
sleepAll(): void;
|
|
43
|
+
/** True when every dynamic body is asleep. */
|
|
44
|
+
get settled(): boolean;
|
|
45
|
+
/** Advance by `dt` seconds in fixed substeps. Returns the number of substeps run. */
|
|
46
|
+
step(dt: number): number;
|
|
47
|
+
private substep;
|
|
48
|
+
/**
|
|
49
|
+
* Groups awake bodies that touch into islands and puts an island to sleep
|
|
50
|
+
* once all of it has been still for SLEEP_TIME. A body resting on another
|
|
51
|
+
* can't sleep alone, so nothing is ever pinned under a sleeping neighbour.
|
|
52
|
+
*/
|
|
53
|
+
private sleepIslands;
|
|
54
|
+
/** Sort-and-sweep on x to find overlapping pairs, then narrow-phase contacts. */
|
|
55
|
+
private broadphase;
|
|
56
|
+
private preStep;
|
|
57
|
+
/** Re-apply last step's impulses so the solver starts close to the answer. */
|
|
58
|
+
private warmStart;
|
|
59
|
+
private applyImpulses;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=world.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"world.d.ts","sourceRoot":"","sources":["../src/world.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEnC,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AA4B9B,MAAM,WAAW,YAAY;IAC3B,oDAAoD;IACpD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gDAAgD;IAChD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAeD,qBAAa,KAAK;IAChB,MAAM,EAAE,IAAI,EAAE,CAAM;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,QAAQ,CAA8B;IAC9C,OAAO,CAAC,KAAK,CAAc;IAC3B,OAAO,CAAC,OAAO,CAAK;gBAER,OAAO,GAAE,YAAiB;IAMtC,GAAG,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IAKrB,MAAM,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IAUxB,KAAK,IAAI,IAAI;IAMb,mFAAmF;IACnF,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI;IAQ5C,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IAIzB;;;OAGG;IACH,YAAY,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IAU9B,gGAAgG;IAChG,QAAQ,IAAI,IAAI;IAShB,8CAA8C;IAC9C,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,qFAAqF;IACrF,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM;IAcxB,OAAO,CAAC,OAAO;IA0Cf;;;;OAIG;IACH,OAAO,CAAC,YAAY;IAmCpB,iFAAiF;IACjF,OAAO,CAAC,UAAU;IAgClB,OAAO,CAAC,OAAO;IA8Bf,8EAA8E;IAC9E,OAAO,CAAC,SAAS;IAwBjB,OAAO,CAAC,aAAa;CAgDtB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,74 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elementalfx/gravity",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Gravity mode for any web page: elements fall, collide, tumble and can be thrown around, then spring back into place. Zero dependencies.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": [
|
|
8
|
+
"./dist/element.js",
|
|
9
|
+
"./dist/*.global.js"
|
|
10
|
+
],
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./element": {
|
|
17
|
+
"types": "./dist/element.d.ts",
|
|
18
|
+
"import": "./dist/element.js"
|
|
19
|
+
},
|
|
20
|
+
"./global": "./dist/gravity.global.js",
|
|
21
|
+
"./package.json": "./package.json"
|
|
22
|
+
},
|
|
23
|
+
"main": "./dist/index.js",
|
|
24
|
+
"module": "./dist/index.js",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"unpkg": "./dist/gravity.global.js",
|
|
27
|
+
"jsdelivr": "./dist/gravity.global.js",
|
|
28
|
+
"files": [
|
|
29
|
+
"dist",
|
|
30
|
+
"README.md"
|
|
31
|
+
],
|
|
32
|
+
"keywords": [
|
|
33
|
+
"gravity",
|
|
34
|
+
"google-gravity",
|
|
35
|
+
"physics",
|
|
36
|
+
"physics-engine",
|
|
37
|
+
"2d-physics",
|
|
38
|
+
"rigid-body",
|
|
39
|
+
"box2d",
|
|
40
|
+
"easter-egg",
|
|
41
|
+
"konami-code",
|
|
42
|
+
"404-page",
|
|
43
|
+
"elementalfx",
|
|
44
|
+
"effects",
|
|
45
|
+
"animation",
|
|
46
|
+
"web-animation",
|
|
47
|
+
"webgl",
|
|
48
|
+
"web-components",
|
|
49
|
+
"custom-elements",
|
|
50
|
+
"framework-agnostic",
|
|
51
|
+
"reduced-motion",
|
|
52
|
+
"typescript"
|
|
53
|
+
],
|
|
54
|
+
"homepage": "https://iyerav42.github.io/elementalfx/#gravity",
|
|
55
|
+
"repository": {
|
|
56
|
+
"type": "git",
|
|
57
|
+
"url": "git+https://github.com/iyerav42/elementalfx.git",
|
|
58
|
+
"directory": "packages/gravity"
|
|
59
|
+
},
|
|
60
|
+
"bugs": {
|
|
61
|
+
"url": "https://github.com/iyerav42/elementalfx/issues"
|
|
62
|
+
},
|
|
63
|
+
"dependencies": {
|
|
64
|
+
"@elementalfx/core": "^0.1.0"
|
|
65
|
+
},
|
|
66
|
+
"publishConfig": {
|
|
67
|
+
"access": "public"
|
|
68
|
+
},
|
|
69
|
+
"elementalfx": {
|
|
70
|
+
"global": "gravity",
|
|
71
|
+
"globalEntry": "src/global.ts",
|
|
72
|
+
"sizeLimit": 13312
|
|
73
|
+
}
|
|
6
74
|
}
|