@miso.ai/client-sdk-ui 1.10.0-beta.11 → 1.10.0-beta.13
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/dist/cjs/layout/text/typewriter/index.js +10 -5
- package/dist/cjs/version.js +1 -1
- package/package.json +2 -2
- package/src/layout/text/typewriter/index.js +6 -4
- package/src/version.js +1 -1
- package/dist/cjs/layout/text/typewriter/progress.js +0 -45
- package/src/layout/text/typewriter/progress.js +0 -33
|
@@ -7,10 +7,9 @@ exports.default = void 0;
|
|
|
7
7
|
var _commons = require("@miso.ai/commons");
|
|
8
8
|
var _constants = require("../../../constants.js");
|
|
9
9
|
var _progressive = _interopRequireDefault(require("../../progressive.js"));
|
|
10
|
-
var _progress = _interopRequireDefault(require("./progress.js"));
|
|
11
10
|
var _plaintext = _interopRequireDefault(require("./plaintext.js"));
|
|
12
11
|
var _utils = require("./utils.js");
|
|
13
|
-
const _excluded = ["className", "tag", "format", "tooltip"];
|
|
12
|
+
const _excluded = ["className", "tag", "format", "tooltip", "speed", "acceleration", "nextCursorFn"];
|
|
14
13
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
14
|
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
|
|
16
15
|
const TYPE = 'typewriter';
|
|
@@ -31,7 +30,10 @@ class TypewriterLayout extends _progressive.default {
|
|
|
31
30
|
className = DEFAULT_CLASSNAME,
|
|
32
31
|
tag = 'auto',
|
|
33
32
|
format = 'markdown',
|
|
34
|
-
tooltip = false
|
|
33
|
+
tooltip = false,
|
|
34
|
+
speed,
|
|
35
|
+
acceleration,
|
|
36
|
+
nextCursorFn
|
|
35
37
|
} = _ref,
|
|
36
38
|
options = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
37
39
|
super(Object.assign({
|
|
@@ -43,7 +45,10 @@ class TypewriterLayout extends _progressive.default {
|
|
|
43
45
|
className
|
|
44
46
|
});
|
|
45
47
|
this._prevState = undefined;
|
|
46
|
-
this.
|
|
48
|
+
this._getNextCursor = typeof nextCursorFn === 'function' ? nextCursorFn : (0, _commons.pacer)({
|
|
49
|
+
speed,
|
|
50
|
+
acceleration
|
|
51
|
+
});
|
|
47
52
|
this._readiness = new _commons.Resolution();
|
|
48
53
|
|
|
49
54
|
// kick off sooner
|
|
@@ -154,7 +159,7 @@ class TypewriterLayout extends _progressive.default {
|
|
|
154
159
|
// new typing streak
|
|
155
160
|
result = this._renderer.clear(container, rendered);
|
|
156
161
|
} else {
|
|
157
|
-
const cursor = this.
|
|
162
|
+
const cursor = this._getNextCursor(rendered.cursor, state.doneAt, rendered.timestamp, state.timestamp);
|
|
158
163
|
result = this._renderer.update(container, rendered, Object.assign({}, state, {
|
|
159
164
|
cursor
|
|
160
165
|
}));
|
package/dist/cjs/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { trimObj, defineValues, Resolution } from '@miso.ai/commons';
|
|
1
|
+
import { trimObj, defineValues, Resolution, pacer } from '@miso.ai/commons';
|
|
2
2
|
import { LAYOUT_CATEGORY, STATUS } from '../../../constants.js';
|
|
3
3
|
import ProgressiveLayout from '../../progressive.js';
|
|
4
|
-
import ProgressController from './progress.js';
|
|
5
4
|
import PlaintextRenderer from './plaintext.js';
|
|
6
5
|
import { containerElement, cursorClassName, fromSameSession } from './utils.js';
|
|
7
6
|
|
|
@@ -27,6 +26,9 @@ export default class TypewriterLayout extends ProgressiveLayout {
|
|
|
27
26
|
tag = 'auto',
|
|
28
27
|
format = 'markdown',
|
|
29
28
|
tooltip = false,
|
|
29
|
+
speed,
|
|
30
|
+
acceleration,
|
|
31
|
+
nextCursorFn,
|
|
30
32
|
...options
|
|
31
33
|
} = {}) {
|
|
32
34
|
super({
|
|
@@ -39,7 +41,7 @@ export default class TypewriterLayout extends ProgressiveLayout {
|
|
|
39
41
|
className,
|
|
40
42
|
});
|
|
41
43
|
this._prevState = undefined;
|
|
42
|
-
this.
|
|
44
|
+
this._getNextCursor = typeof nextCursorFn === 'function' ? nextCursorFn : pacer({ speed, acceleration });
|
|
43
45
|
this._readiness = new Resolution();
|
|
44
46
|
|
|
45
47
|
// kick off sooner
|
|
@@ -134,7 +136,7 @@ export default class TypewriterLayout extends ProgressiveLayout {
|
|
|
134
136
|
// new typing streak
|
|
135
137
|
result = this._renderer.clear(container, rendered);
|
|
136
138
|
} else {
|
|
137
|
-
const cursor = this.
|
|
139
|
+
const cursor = this._getNextCursor(rendered.cursor, state.doneAt, rendered.timestamp, state.timestamp);
|
|
138
140
|
result = this._renderer.update(container, rendered, { ...state, cursor });
|
|
139
141
|
}
|
|
140
142
|
writeToState(result);
|
package/src/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '1.10.0-beta.
|
|
1
|
+
export default '1.10.0-beta.13';
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
class ProgressController {
|
|
8
|
-
constructor() {
|
|
9
|
-
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
10
|
-
this._cps = normalizeSpeedFunction(options);
|
|
11
|
-
}
|
|
12
|
-
get(prevState, newState) {
|
|
13
|
-
const cps = this._cps(newState);
|
|
14
|
-
const increment = Math.floor((newState.timestamp - prevState.timestamp) * cps / 1000);
|
|
15
|
-
return prevState.cursor + increment;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
exports.default = ProgressController;
|
|
19
|
-
function normalizeSpeedFunction() {
|
|
20
|
-
let {
|
|
21
|
-
speed = 100,
|
|
22
|
-
acceleration = 4
|
|
23
|
-
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
24
|
-
if (typeof speed === 'function') {
|
|
25
|
-
return speed;
|
|
26
|
-
}
|
|
27
|
-
if (typeof speed !== 'number') {
|
|
28
|
-
throw new Error(`Invalid speed: ${speed}`);
|
|
29
|
-
}
|
|
30
|
-
if (typeof acceleration !== 'number') {
|
|
31
|
-
throw new Error(`Invalid acceleration: ${acceleration}`);
|
|
32
|
-
}
|
|
33
|
-
return _ref => {
|
|
34
|
-
let {
|
|
35
|
-
doneAt,
|
|
36
|
-
timestamp
|
|
37
|
-
} = _ref;
|
|
38
|
-
let value = speed * (Math.random() + 0.5);
|
|
39
|
-
if (acceleration > 0 && doneAt !== undefined) {
|
|
40
|
-
// speed up gradually when input is done
|
|
41
|
-
value *= 1 + (timestamp - doneAt) * acceleration / 1000;
|
|
42
|
-
}
|
|
43
|
-
return value;
|
|
44
|
-
};
|
|
45
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
export default class ProgressController {
|
|
2
|
-
|
|
3
|
-
constructor(options = {}) {
|
|
4
|
-
this._cps = normalizeSpeedFunction(options);
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
get(prevState, newState) {
|
|
8
|
-
const cps = this._cps(newState);
|
|
9
|
-
const increment = Math.floor((newState.timestamp - prevState.timestamp) * cps / 1000);
|
|
10
|
-
return prevState.cursor + increment;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function normalizeSpeedFunction({ speed = 100, acceleration = 4 } = {}) {
|
|
16
|
-
if (typeof speed === 'function') {
|
|
17
|
-
return speed;
|
|
18
|
-
}
|
|
19
|
-
if (typeof speed !== 'number') {
|
|
20
|
-
throw new Error(`Invalid speed: ${speed}`);
|
|
21
|
-
}
|
|
22
|
-
if (typeof acceleration !== 'number') {
|
|
23
|
-
throw new Error(`Invalid acceleration: ${acceleration}`);
|
|
24
|
-
}
|
|
25
|
-
return ({ doneAt, timestamp }) => {
|
|
26
|
-
let value = speed * (Math.random() + 0.5);
|
|
27
|
-
if (acceleration > 0 && doneAt !== undefined) {
|
|
28
|
-
// speed up gradually when input is done
|
|
29
|
-
value *= 1 + ((timestamp - doneAt) * acceleration / 1000);
|
|
30
|
-
}
|
|
31
|
-
return value;
|
|
32
|
-
};
|
|
33
|
-
}
|