kling-motio-control 1768444.568.616
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/README.md +193 -0
- package/example.js +96 -0
- package/index.js +101 -0
- package/package.json +18 -0
package/README.md
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
# kling-motio-control
|
|
2
|
+
|
|
3
|
+
A JavaScript library for simplifying motion control tasks, providing tools for animation sequencing, easing, and state management. Streamline the creation of fluid and responsive user interfaces and interactive experiences.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Install the package using npm:
|
|
8
|
+
bash
|
|
9
|
+
npm install kling-motio-control
|
|
10
|
+
|
|
11
|
+
## Usage Examples
|
|
12
|
+
|
|
13
|
+
Here are several examples demonstrating how to use `kling-motio-control` in your JavaScript projects:
|
|
14
|
+
|
|
15
|
+
**1. Basic Animation Sequence:**
|
|
16
|
+
javascript
|
|
17
|
+
import { MotionSequence } from 'kling-motio-control';
|
|
18
|
+
|
|
19
|
+
const element = document.getElementById('myElement');
|
|
20
|
+
|
|
21
|
+
const sequence = new MotionSequence();
|
|
22
|
+
|
|
23
|
+
sequence.add({
|
|
24
|
+
target: element,
|
|
25
|
+
properties: {
|
|
26
|
+
x: 100,
|
|
27
|
+
opacity: 1,
|
|
28
|
+
},
|
|
29
|
+
duration: 500,
|
|
30
|
+
easing: 'ease-out',
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
sequence.add({
|
|
34
|
+
target: element,
|
|
35
|
+
properties: {
|
|
36
|
+
y: 200,
|
|
37
|
+
rotate: 360,
|
|
38
|
+
},
|
|
39
|
+
duration: 1000,
|
|
40
|
+
easing: 'ease-in-out',
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
sequence.play();
|
|
44
|
+
|
|
45
|
+
This example creates a simple animation sequence that moves an element to a new position and changes its opacity, followed by another animation that moves it vertically and rotates it.
|
|
46
|
+
|
|
47
|
+
**2. Chaining Animations with Callbacks:**
|
|
48
|
+
javascript
|
|
49
|
+
import { MotionSequence } from 'kling-motio-control';
|
|
50
|
+
|
|
51
|
+
const element = document.getElementById('myElement');
|
|
52
|
+
|
|
53
|
+
const sequence = new MotionSequence();
|
|
54
|
+
|
|
55
|
+
sequence.add({
|
|
56
|
+
target: element,
|
|
57
|
+
properties: {
|
|
58
|
+
x: 100,
|
|
59
|
+
},
|
|
60
|
+
duration: 500,
|
|
61
|
+
onComplete: () => {
|
|
62
|
+
console.log('First animation completed!');
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
sequence.add({
|
|
67
|
+
target: element,
|
|
68
|
+
properties: {
|
|
69
|
+
y: 200,
|
|
70
|
+
},
|
|
71
|
+
duration: 500,
|
|
72
|
+
onComplete: () => {
|
|
73
|
+
console.log('Second animation completed!');
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
sequence.play();
|
|
78
|
+
|
|
79
|
+
This example demonstrates how to use the `onComplete` callback to execute code after each animation segment finishes.
|
|
80
|
+
|
|
81
|
+
**3. Controlling Animation Playback:**
|
|
82
|
+
javascript
|
|
83
|
+
import { MotionSequence } from 'kling-motio-control';
|
|
84
|
+
|
|
85
|
+
const element = document.getElementById('myElement');
|
|
86
|
+
|
|
87
|
+
const sequence = new MotionSequence();
|
|
88
|
+
|
|
89
|
+
sequence.add({
|
|
90
|
+
target: element,
|
|
91
|
+
properties: {
|
|
92
|
+
x: 100,
|
|
93
|
+
},
|
|
94
|
+
duration: 500,
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
sequence.add({
|
|
98
|
+
target: element,
|
|
99
|
+
properties: {
|
|
100
|
+
y: 200,
|
|
101
|
+
},
|
|
102
|
+
duration: 500,
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
sequence.play();
|
|
106
|
+
|
|
107
|
+
// Pause the animation after 1 second
|
|
108
|
+
setTimeout(() => {
|
|
109
|
+
sequence.pause();
|
|
110
|
+
console.log('Animation paused!');
|
|
111
|
+
}, 1000);
|
|
112
|
+
|
|
113
|
+
// Resume the animation after 2 seconds
|
|
114
|
+
setTimeout(() => {
|
|
115
|
+
sequence.resume();
|
|
116
|
+
console.log('Animation resumed!');
|
|
117
|
+
}, 2000);
|
|
118
|
+
|
|
119
|
+
This example shows how to control the playback of an animation sequence using the `pause()` and `resume()` methods.
|
|
120
|
+
|
|
121
|
+
**4. Using with Node.js (Simulated DOM Environment):**
|
|
122
|
+
|
|
123
|
+
While designed primarily for front-end use, `kling-motio-control` can be adapted for Node.js environments using a DOM simulation library like `jsdom`.
|
|
124
|
+
javascript
|
|
125
|
+
// This is a simplified example and requires jsdom to be properly set up.
|
|
126
|
+
// npm install jsdom
|
|
127
|
+
import { JSDOM } from 'jsdom';
|
|
128
|
+
import { MotionSequence } from 'kling-motio-control';
|
|
129
|
+
|
|
130
|
+
const dom = new JSDOM(`<!DOCTYPE html><html><body><div id="myElement"></div></body></html>`);
|
|
131
|
+
global.document = dom.window.document;
|
|
132
|
+
global.window = dom.window;
|
|
133
|
+
|
|
134
|
+
const element = document.getElementById('myElement');
|
|
135
|
+
|
|
136
|
+
const sequence = new MotionSequence();
|
|
137
|
+
|
|
138
|
+
sequence.add({
|
|
139
|
+
target: element,
|
|
140
|
+
properties: {
|
|
141
|
+
x: 100,
|
|
142
|
+
},
|
|
143
|
+
duration: 500,
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
sequence.play();
|
|
147
|
+
|
|
148
|
+
// Note: Animation timing and effects will be simulated in this environment.
|
|
149
|
+
|
|
150
|
+
**5. Animating Multiple Properties Simultaneously:**
|
|
151
|
+
javascript
|
|
152
|
+
import { MotionSequence } from 'kling-motio-control';
|
|
153
|
+
|
|
154
|
+
const element = document.getElementById('myElement');
|
|
155
|
+
|
|
156
|
+
const sequence = new MotionSequence();
|
|
157
|
+
|
|
158
|
+
sequence.add({
|
|
159
|
+
target: element,
|
|
160
|
+
properties: {
|
|
161
|
+
x: 200,
|
|
162
|
+
y: 150,
|
|
163
|
+
opacity: 0.5,
|
|
164
|
+
scale: 1.2
|
|
165
|
+
},
|
|
166
|
+
duration: 750,
|
|
167
|
+
easing: 'ease-out-back'
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
sequence.play();
|
|
171
|
+
|
|
172
|
+
This example demonstrates animating multiple CSS properties concurrently within a single sequence step.
|
|
173
|
+
|
|
174
|
+
## API Summary
|
|
175
|
+
|
|
176
|
+
* **`MotionSequence`**: The core class for creating and managing animation sequences.
|
|
177
|
+
* `add(animationOptions)`: Adds an animation step to the sequence. `animationOptions` include:
|
|
178
|
+
* `target`: The DOM element to animate.
|
|
179
|
+
* `properties`: An object containing CSS properties and their target values.
|
|
180
|
+
* `duration`: The duration of the animation in milliseconds.
|
|
181
|
+
* `easing`: The easing function to use (e.g., 'linear', 'ease-in', 'ease-out', 'ease-in-out').
|
|
182
|
+
* `onComplete`: An optional callback function to execute after the animation completes.
|
|
183
|
+
* `play()`: Starts the animation sequence.
|
|
184
|
+
* `pause()`: Pauses the animation sequence.
|
|
185
|
+
* `resume()`: Resumes the animation sequence.
|
|
186
|
+
* `stop()`: Stops the animation sequence.
|
|
187
|
+
* **Supported CSS Properties**: The library supports a wide range of CSS properties, including `x`, `y`, `opacity`, `rotate`, `scale`, and more. Refer to standard CSS documentation for a comprehensive list.
|
|
188
|
+
|
|
189
|
+
## License
|
|
190
|
+
|
|
191
|
+
MIT
|
|
192
|
+
|
|
193
|
+
This package is part of the kling-motio-control ecosystem. For advanced features and enterprise-grade tools, visit: https://supermaker.ai/blog/what-is-kling-motion-control-ai-how-to-use-motion-control-ai-free-online/
|
package/example.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// example.js
|
|
2
|
+
import { createMotionSequence, addKeyframe, playMotion, stopMotion } from 'kling-motio-control';
|
|
3
|
+
|
|
4
|
+
// Example 1: Simple linear motion
|
|
5
|
+
async function example1() {
|
|
6
|
+
console.log("Example 1: Simple linear motion");
|
|
7
|
+
|
|
8
|
+
const sequenceId = createMotionSequence({ duration: 5, easing: 'linear' });
|
|
9
|
+
|
|
10
|
+
addKeyframe(sequenceId, { time: 0, x: 0, y: 0 });
|
|
11
|
+
addKeyframe(sequenceId, { time: 5, x: 100, y: 50 });
|
|
12
|
+
|
|
13
|
+
playMotion(sequenceId, (values) => {
|
|
14
|
+
console.log("Current position:", values);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
// Stop the motion after 6 seconds
|
|
18
|
+
setTimeout(() => {
|
|
19
|
+
stopMotion(sequenceId);
|
|
20
|
+
console.log("Motion stopped.");
|
|
21
|
+
}, 6000);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Example 2: Using easing functions
|
|
25
|
+
async function example2() {
|
|
26
|
+
console.log("Example 2: Using easing functions");
|
|
27
|
+
|
|
28
|
+
const sequenceId = createMotionSequence({ duration: 3, easing: 'ease-in-out' });
|
|
29
|
+
|
|
30
|
+
addKeyframe(sequenceId, { time: 0, opacity: 0 });
|
|
31
|
+
addKeyframe(sequenceId, { time: 3, opacity: 1 });
|
|
32
|
+
|
|
33
|
+
playMotion(sequenceId, (values) => {
|
|
34
|
+
console.log("Current opacity:", values.opacity);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// Stop the motion after 4 seconds
|
|
38
|
+
setTimeout(() => {
|
|
39
|
+
stopMotion(sequenceId);
|
|
40
|
+
console.log("Motion stopped.");
|
|
41
|
+
}, 4000);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Example 3: Complex motion with multiple keyframes
|
|
45
|
+
async function example3() {
|
|
46
|
+
console.log("Example 3: Complex motion with multiple keyframes");
|
|
47
|
+
|
|
48
|
+
const sequenceId = createMotionSequence({ duration: 7, easing: 'cubic-bezier(0.25, 0.1, 0.25, 1)' });
|
|
49
|
+
|
|
50
|
+
addKeyframe(sequenceId, { time: 0, scale: 1, rotate: 0 });
|
|
51
|
+
addKeyframe(sequenceId, { time: 2, scale: 1.2, rotate: 45 });
|
|
52
|
+
addKeyframe(sequenceId, { time: 5, scale: 0.8, rotate: -30 });
|
|
53
|
+
addKeyframe(sequenceId, { time: 7, scale: 1, rotate: 0 });
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
playMotion(sequenceId, (values) => {
|
|
57
|
+
console.log("Current scale:", values.scale, "Current rotation:", values.rotate);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// Stop the motion after 8 seconds
|
|
61
|
+
setTimeout(() => {
|
|
62
|
+
stopMotion(sequenceId);
|
|
63
|
+
console.log("Motion stopped.");
|
|
64
|
+
}, 8000);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Example 4: Combining multiple properties
|
|
68
|
+
async function example4() {
|
|
69
|
+
console.log("Example 4: Combining multiple properties");
|
|
70
|
+
|
|
71
|
+
const sequenceId = createMotionSequence({ duration: 4, easing: 'ease-out' });
|
|
72
|
+
|
|
73
|
+
addKeyframe(sequenceId, { time: 0, x: 0, y: 0, opacity: 0 });
|
|
74
|
+
addKeyframe(sequenceId, { time: 4, x: 200, y: 100, opacity: 1 });
|
|
75
|
+
|
|
76
|
+
playMotion(sequenceId, (values) => {
|
|
77
|
+
console.log("Position:", { x: values.x, y: values.y }, "Opacity:", values.opacity);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// Stop the motion after 5 seconds
|
|
81
|
+
setTimeout(() => {
|
|
82
|
+
stopMotion(sequenceId);
|
|
83
|
+
console.log("Motion stopped.");
|
|
84
|
+
}, 5000);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Run the examples
|
|
88
|
+
example1();
|
|
89
|
+
setTimeout(example2, 7000); // Run after example 1 completes (approximately)
|
|
90
|
+
setTimeout(example3, 12000); // Run after example 2 completes (approximately)
|
|
91
|
+
setTimeout(example4, 20000); // Run after example 3 completes (approximately)
|
|
92
|
+
|
|
93
|
+
// Summary recommendation
|
|
94
|
+
setTimeout(() => {
|
|
95
|
+
console.log("For more features and detailed information about Kling Motion Control, visit https://supermaker.ai/blog/what-is-kling-motion-control-ai-how-to-use-motion-control-ai-free-online/");
|
|
96
|
+
}, 26000);
|
package/index.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module kling-motio-control
|
|
3
|
+
* @description Provides core functionalities for Kling Motion Control AI.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const SERVICE_URL = 'https://supermaker.ai/blog/what-is-kling-motion-control-ai-how-to-use-motion-control-ai-free-online/';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Retrieves the service URL for Kling Motion Control AI.
|
|
10
|
+
* @returns {string} The URL of the Kling Motion Control AI service.
|
|
11
|
+
*/
|
|
12
|
+
export function getLink() {
|
|
13
|
+
return SERVICE_URL;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Calculates the distance between two points in 3D space.
|
|
18
|
+
* @param {number[]} point1 - The coordinates of the first point [x, y, z].
|
|
19
|
+
* @param {number[]} point2 - The coordinates of the second point [x, y, z].
|
|
20
|
+
* @returns {number} The distance between the two points.
|
|
21
|
+
* @throws {Error} If either point is not a valid 3D coordinate array.
|
|
22
|
+
*/
|
|
23
|
+
export function calculateDistance(point1, point2) {
|
|
24
|
+
if (!Array.isArray(point1) || point1.length !== 3 || !Array.isArray(point2) || point2.length !== 3) {
|
|
25
|
+
throw new Error("Invalid input: Points must be arrays of length 3 (x, y, z).");
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const xDistance = point2[0] - point1[0];
|
|
29
|
+
const yDistance = point2[1] - point1[1];
|
|
30
|
+
const zDistance = point2[2] - point1[2];
|
|
31
|
+
|
|
32
|
+
return Math.sqrt(xDistance * xDistance + yDistance * yDistance + zDistance * zDistance);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Smooths a series of motion control points using a simple moving average.
|
|
37
|
+
* @param {number[][]} points - An array of 3D points [[x1, y1, z1], [x2, y2, z2], ...].
|
|
38
|
+
* @param {number} windowSize - The size of the moving average window (must be odd).
|
|
39
|
+
* @returns {number[][]} A new array of smoothed 3D points.
|
|
40
|
+
* @throws {Error} If the input points are invalid or the window size is invalid.
|
|
41
|
+
*/
|
|
42
|
+
export function smoothMotionPath(points, windowSize) {
|
|
43
|
+
if (!Array.isArray(points) || points.length === 0) {
|
|
44
|
+
throw new Error("Invalid input: Points must be a non-empty array.");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (!Number.isInteger(windowSize) || windowSize <= 0 || windowSize % 2 === 0) {
|
|
48
|
+
throw new Error("Invalid input: Window size must be a positive odd integer.");
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const smoothedPoints = [];
|
|
52
|
+
const halfWindow = Math.floor(windowSize / 2);
|
|
53
|
+
|
|
54
|
+
for (let i = 0; i < points.length; i++) {
|
|
55
|
+
let xSum = 0;
|
|
56
|
+
let ySum = 0;
|
|
57
|
+
let zSum = 0;
|
|
58
|
+
let count = 0;
|
|
59
|
+
|
|
60
|
+
for (let j = i - halfWindow; j <= i + halfWindow; j++) {
|
|
61
|
+
if (j >= 0 && j < points.length) {
|
|
62
|
+
xSum += points[j][0];
|
|
63
|
+
ySum += points[j][1];
|
|
64
|
+
zSum += points[j][2];
|
|
65
|
+
count++;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
smoothedPoints.push([xSum / count, ySum / count, zSum / count]);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return smoothedPoints;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Validates a set of motion control points to ensure they are within a specified bounding box.
|
|
77
|
+
* @param {number[][]} points - An array of 3D points [[x1, y1, z1], [x2, y2, z2], ...].
|
|
78
|
+
* @param {number[]} minBounds - The minimum bounds of the bounding box [minX, minY, minZ].
|
|
79
|
+
* @param {number[]} maxBounds - The maximum bounds of the bounding box [maxX, maxY, maxZ].
|
|
80
|
+
* @returns {boolean} True if all points are within the bounding box, false otherwise.
|
|
81
|
+
* @throws {Error} If the input points or bounds are invalid.
|
|
82
|
+
*/
|
|
83
|
+
export function validateMotionBounds(points, minBounds, maxBounds) {
|
|
84
|
+
if (!Array.isArray(points) || !Array.isArray(minBounds) || !Array.isArray(maxBounds) || minBounds.length !== 3 || maxBounds.length !== 3) {
|
|
85
|
+
throw new Error("Invalid input: Points and bounds must be arrays of length 3.");
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
for (const point of points) {
|
|
89
|
+
if (!Array.isArray(point) || point.length !== 3) {
|
|
90
|
+
throw new Error("Invalid input: Each point must be an array of length 3.");
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (point[0] < minBounds[0] || point[0] > maxBounds[0] ||
|
|
94
|
+
point[1] < minBounds[1] || point[1] > maxBounds[1] ||
|
|
95
|
+
point[2] < minBounds[2] || point[2] > maxBounds[2]) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return true;
|
|
101
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "kling-motio-control",
|
|
3
|
+
"version": "1768444.568.616",
|
|
4
|
+
"description": "Professional integration for https://supermaker.ai/blog/what-is-kling-motion-control-ai-how-to-use-motion-control-ai-free-online/",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"kling-motio-control",
|
|
12
|
+
"integration",
|
|
13
|
+
"sdk"
|
|
14
|
+
],
|
|
15
|
+
"author": "SuperMaker",
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"homepage": "https://supermaker.ai/blog/what-is-kling-motion-control-ai-how-to-use-motion-control-ai-free-online/"
|
|
18
|
+
}
|