@rive-app/canvas 2.37.8 → 2.38.1
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/package.json +1 -1
- package/rive.d.ts +40 -1
- package/rive.js +283 -119
- package/rive.js.map +1 -1
- package/rive.wasm +0 -0
- package/rive_advanced.mjs.d.ts +24 -0
- package/rive_fallback.wasm +0 -0
- package/utils/finalizationRegistry.d.ts +1 -1
- package/utils/index.d.ts +1 -1
- package/utils/registerKeyboardInteractions.d.ts +67 -7
- package/utils/registerTouchInteractions.d.ts +2 -1
package/rive.js
CHANGED
|
@@ -1084,7 +1084,7 @@ function Za(a, b) {
|
|
|
1084
1084
|
return Ya(c, a, b);
|
|
1085
1085
|
}));
|
|
1086
1086
|
}
|
|
1087
|
-
var $a, ab, eb = {
|
|
1087
|
+
var $a, ab, eb = {485789:(a, b, c, d, e) => {
|
|
1088
1088
|
if ("undefined" === typeof window || void 0 === (window.AudioContext || window.webkitAudioContext)) {
|
|
1089
1089
|
return 0;
|
|
1090
1090
|
}
|
|
@@ -1147,11 +1147,11 @@ var $a, ab, eb = {484269:(a, b, c, d, e) => {
|
|
|
1147
1147
|
}
|
|
1148
1148
|
window.h.za += 1;
|
|
1149
1149
|
return 1;
|
|
1150
|
-
},
|
|
1150
|
+
}, 487967:() => {
|
|
1151
1151
|
"undefined" !== typeof window.h && (window.h.Sa.map(function(a) {
|
|
1152
1152
|
document.removeEventListener(a, window.h.unlock, !0);
|
|
1153
1153
|
}), --window.h.za, 0 === window.h.za && delete window.h);
|
|
1154
|
-
},
|
|
1154
|
+
}, 488271:() => void 0 !== navigator.mediaDevices && void 0 !== navigator.mediaDevices.getUserMedia, 488375:() => {
|
|
1155
1155
|
try {
|
|
1156
1156
|
var a = new (window.AudioContext || window.webkitAudioContext)(), b = a.sampleRate;
|
|
1157
1157
|
a.close();
|
|
@@ -1159,7 +1159,7 @@ var $a, ab, eb = {484269:(a, b, c, d, e) => {
|
|
|
1159
1159
|
} catch (c) {
|
|
1160
1160
|
return 0;
|
|
1161
1161
|
}
|
|
1162
|
-
},
|
|
1162
|
+
}, 488546:(a, b, c, d, e, f) => {
|
|
1163
1163
|
if ("undefined" === typeof window.h) {
|
|
1164
1164
|
return -1;
|
|
1165
1165
|
}
|
|
@@ -1205,7 +1205,7 @@ var $a, ab, eb = {484269:(a, b, c, d, e) => {
|
|
|
1205
1205
|
a == window.h.J.xa && g.Z.connect(g.L.destination);
|
|
1206
1206
|
g.pb = f;
|
|
1207
1207
|
return window.h.tc(g);
|
|
1208
|
-
},
|
|
1208
|
+
}, 491423:a => window.h.qa(a).L.sampleRate, 491496:a => {
|
|
1209
1209
|
a = window.h.qa(a);
|
|
1210
1210
|
void 0 !== a.Z && (a.Z.onaudioprocess = function() {
|
|
1211
1211
|
}, a.Z.disconnect(), a.Z = void 0);
|
|
@@ -1213,13 +1213,13 @@ var $a, ab, eb = {484269:(a, b, c, d, e) => {
|
|
|
1213
1213
|
a.L.close();
|
|
1214
1214
|
a.L = void 0;
|
|
1215
1215
|
a.pb = void 0;
|
|
1216
|
-
},
|
|
1216
|
+
}, 491896:a => {
|
|
1217
1217
|
window.h.Ab(a);
|
|
1218
|
-
},
|
|
1218
|
+
}, 491946:a => {
|
|
1219
1219
|
a = window.h.qa(a);
|
|
1220
1220
|
a.L.resume();
|
|
1221
1221
|
a.state = window.h.ga.wb;
|
|
1222
|
-
},
|
|
1222
|
+
}, 492085:a => {
|
|
1223
1223
|
a = window.h.qa(a);
|
|
1224
1224
|
a.L.suspend();
|
|
1225
1225
|
a.state = window.h.ga.stopped;
|
|
@@ -3752,7 +3752,7 @@ moduleRtn = ea;
|
|
|
3752
3752
|
/* 5 */
|
|
3753
3753
|
/***/ ((module) => {
|
|
3754
3754
|
|
|
3755
|
-
module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/canvas","version":"2.
|
|
3755
|
+
module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/canvas","version":"2.38.1","description":"Rive\'s canvas based web api.","main":"rive.js","homepage":"https://rive.app","repository":{"type":"git","url":"https://github.com/rive-app/rive-wasm/tree/master/js"},"keywords":["rive","animation"],"author":"Rive","contributors":["Luigi Rosso <luigi@rive.app> (https://rive.app)","Maxwell Talbot <max@rive.app> (https://rive.app)","Arthur Vivian <arthur@rive.app> (https://rive.app)","Umberto Sonnino <umberto@rive.app> (https://rive.app)","Matthew Sullivan <matt.j.sullivan@gmail.com> (mailto:matt.j.sullivan@gmail.com)"],"license":"MIT","files":["rive.js","rive.js.map","rive.wasm","rive_fallback.wasm","rive.d.ts","rive_advanced.mjs.d.ts","runtimeLoader.d.ts","utils"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
|
|
3756
3756
|
|
|
3757
3757
|
/***/ }),
|
|
3758
3758
|
/* 6 */
|
|
@@ -3766,14 +3766,15 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
3766
3766
|
/* harmony export */ CustomFileAssetLoaderWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_3__.CustomFileAssetLoaderWrapper),
|
|
3767
3767
|
/* harmony export */ FileAssetWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_3__.FileAssetWrapper),
|
|
3768
3768
|
/* harmony export */ FileFinalizer: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_3__.FileFinalizer),
|
|
3769
|
+
/* harmony export */ FocusSessionState: () => (/* reexport safe */ _registerKeyboardInteractions__WEBPACK_IMPORTED_MODULE_1__.FocusSessionState),
|
|
3769
3770
|
/* harmony export */ FontAssetWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_3__.FontAssetWrapper),
|
|
3770
3771
|
/* harmony export */ FontWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_3__.FontWrapper),
|
|
3771
3772
|
/* harmony export */ ImageAssetWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_3__.ImageAssetWrapper),
|
|
3772
3773
|
/* harmony export */ ImageWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_3__.ImageWrapper),
|
|
3774
|
+
/* harmony export */ KeyboardInteractions: () => (/* reexport safe */ _registerKeyboardInteractions__WEBPACK_IMPORTED_MODULE_1__.KeyboardInteractions),
|
|
3773
3775
|
/* harmony export */ RiveFont: () => (/* reexport safe */ _riveFont__WEBPACK_IMPORTED_MODULE_4__.RiveFont),
|
|
3774
3776
|
/* harmony export */ createFinalization: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_3__.createFinalization),
|
|
3775
3777
|
/* harmony export */ finalizationRegistry: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_3__.finalizationRegistry),
|
|
3776
|
-
/* harmony export */ registerKeyboardInteractions: () => (/* reexport safe */ _registerKeyboardInteractions__WEBPACK_IMPORTED_MODULE_1__.registerKeyboardInteractions),
|
|
3777
3778
|
/* harmony export */ registerTouchInteractions: () => (/* reexport safe */ _registerTouchInteractions__WEBPACK_IMPORTED_MODULE_0__.registerTouchInteractions),
|
|
3778
3779
|
/* harmony export */ sanitizeUrl: () => (/* reexport safe */ _sanitizeUrl__WEBPACK_IMPORTED_MODULE_2__.sanitizeUrl)
|
|
3779
3780
|
/* harmony export */ });
|
|
@@ -3869,7 +3870,7 @@ var getClientCoordinates = function (event, isTouchScrollEnabled, enableMultiTou
|
|
|
3869
3870
|
* the state machine pointer move/up/down functions based on cursor interaction
|
|
3870
3871
|
*/
|
|
3871
3872
|
var registerTouchInteractions = function (_a) {
|
|
3872
|
-
var canvas = _a.canvas, artboard = _a.artboard, _b = _a.stateMachines, stateMachines = _b === void 0 ? [] : _b, renderer = _a.renderer, rive = _a.rive, fit = _a.fit, alignment = _a.alignment, _c = _a.isTouchScrollEnabled, isTouchScrollEnabled = _c === void 0 ? false : _c, _d = _a.dispatchPointerExit, dispatchPointerExit = _d === void 0 ? true : _d, _e = _a.enableMultiTouch, enableMultiTouch = _e === void 0 ? false : _e, _f = _a.layoutScaleFactor, layoutScaleFactor = _f === void 0 ? 1.0 : _f;
|
|
3873
|
+
var canvas = _a.canvas, artboard = _a.artboard, _b = _a.stateMachines, stateMachines = _b === void 0 ? [] : _b, renderer = _a.renderer, rive = _a.rive, fit = _a.fit, alignment = _a.alignment, _c = _a.isTouchScrollEnabled, isTouchScrollEnabled = _c === void 0 ? false : _c, _d = _a.dispatchPointerExit, dispatchPointerExit = _d === void 0 ? true : _d, _e = _a.enableMultiTouch, enableMultiTouch = _e === void 0 ? false : _e, _f = _a.layoutScaleFactor, layoutScaleFactor = _f === void 0 ? 1.0 : _f, advanceAndDrain = _a.advanceAndDrain;
|
|
3873
3874
|
if (!canvas ||
|
|
3874
3875
|
!stateMachines.length ||
|
|
3875
3876
|
!renderer ||
|
|
@@ -4012,6 +4013,8 @@ var registerTouchInteractions = function (_a) {
|
|
|
4012
4013
|
var stateMachine = stateMachines_3[_c];
|
|
4013
4014
|
_loop_3(stateMachine);
|
|
4014
4015
|
}
|
|
4016
|
+
// Advance the state machine immediately so pointer down(s) takes effect synchronously
|
|
4017
|
+
advanceAndDrain(0);
|
|
4015
4018
|
break;
|
|
4016
4019
|
}
|
|
4017
4020
|
// Pointer click released on the canvas
|
|
@@ -4026,6 +4029,8 @@ var registerTouchInteractions = function (_a) {
|
|
|
4026
4029
|
var stateMachine = stateMachines_4[_d];
|
|
4027
4030
|
_loop_4(stateMachine);
|
|
4028
4031
|
}
|
|
4032
|
+
// Advance the state machine immediately so pointer up(s) takes effect synchronously
|
|
4033
|
+
advanceAndDrain(0);
|
|
4029
4034
|
// Release the primary touch lock once that finger lifts so the next
|
|
4030
4035
|
// touchstart can claim a new primary finger.
|
|
4031
4036
|
if (!enableMultiTouch &&
|
|
@@ -4044,6 +4049,8 @@ var registerTouchInteractions = function (_a) {
|
|
|
4044
4049
|
var stateMachine = stateMachines_5[_e];
|
|
4045
4050
|
_loop_5(stateMachine);
|
|
4046
4051
|
}
|
|
4052
|
+
// Advance the state machine immediately so pointer up(s) takes effect synchronously
|
|
4053
|
+
advanceAndDrain(0);
|
|
4047
4054
|
break;
|
|
4048
4055
|
}
|
|
4049
4056
|
default:
|
|
@@ -4086,60 +4093,145 @@ var registerTouchInteractions = function (_a) {
|
|
|
4086
4093
|
|
|
4087
4094
|
__webpack_require__.r(__webpack_exports__);
|
|
4088
4095
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
4089
|
-
/* harmony export */
|
|
4096
|
+
/* harmony export */ FocusSessionState: () => (/* binding */ FocusSessionState),
|
|
4097
|
+
/* harmony export */ KeyboardInteractions: () => (/* binding */ KeyboardInteractions)
|
|
4090
4098
|
/* harmony export */ });
|
|
4091
4099
|
/**
|
|
4092
|
-
*
|
|
4093
|
-
*
|
|
4100
|
+
* Tracks the relationship between the canvas's DOM focus and Rive's internal focus for the
|
|
4101
|
+
* current focus session.
|
|
4094
4102
|
*
|
|
4095
|
-
*
|
|
4103
|
+
* NotFocused — the canvas is not the active DOM element, or Rive entered and then released focus
|
|
4104
|
+
* internally this session. Either way the next Tab should move on to the next page
|
|
4105
|
+
* element, so Tab events are ignored.
|
|
4106
|
+
* EntryPending — the canvas has DOM focus but Rive holds no active focus node yet, and the next Tab should enter
|
|
4107
|
+
* the focus tree. This is the resting state for pointer-driven focus (a click on the
|
|
4108
|
+
* canvas), or an edge case for keyboard focus where initial focus action did not land on a focus node.
|
|
4109
|
+
* RiveFocused — a Rive node currently holds focus. Tab/Shift+Tab are routed to the Rive focus
|
|
4110
|
+
* manager and trapped inside the canvas until Rive notifies focus has ended.
|
|
4096
4111
|
*
|
|
4097
|
-
*
|
|
4098
|
-
*
|
|
4112
|
+
* When keyboard focus lands on the canvas, onCanvasFocus reads the direction focus came from and
|
|
4113
|
+
* moves into the focus tree immediately, going straight to RiveFocused. EntryPending is only set via pointer focus (or keyboard focus
|
|
4114
|
+
* where focusNext()/focusPrevious() return false but respects tabindex).
|
|
4099
4115
|
*/
|
|
4100
|
-
var
|
|
4101
|
-
|
|
4102
|
-
|
|
4103
|
-
|
|
4104
|
-
|
|
4105
|
-
|
|
4106
|
-
|
|
4107
|
-
|
|
4108
|
-
|
|
4109
|
-
|
|
4110
|
-
|
|
4111
|
-
|
|
4112
|
-
|
|
4113
|
-
|
|
4114
|
-
|
|
4115
|
-
|
|
4116
|
-
|
|
4117
|
-
|
|
4118
|
-
|
|
4119
|
-
|
|
4120
|
-
|
|
4121
|
-
|
|
4122
|
-
|
|
4123
|
-
|
|
4124
|
-
|
|
4125
|
-
|
|
4116
|
+
var FocusSessionState;
|
|
4117
|
+
(function (FocusSessionState) {
|
|
4118
|
+
FocusSessionState["NotFocused"] = "notFocused";
|
|
4119
|
+
FocusSessionState["EntryPending"] = "entryPending";
|
|
4120
|
+
FocusSessionState["RiveFocused"] = "riveFocused";
|
|
4121
|
+
})(FocusSessionState || (FocusSessionState = {}));
|
|
4122
|
+
/**
|
|
4123
|
+
* Manages keyboard and DOM focus interactions for a Rive canvas.
|
|
4124
|
+
*
|
|
4125
|
+
* Tracks the canvas focus session state (focusSessionState) and routes
|
|
4126
|
+
* Tab/Shift+Tab to the Rive state machine's focus manager. Exposes shared
|
|
4127
|
+
* state as properties so the Rive render loop can read them directly.
|
|
4128
|
+
*/
|
|
4129
|
+
var KeyboardInteractions = /** @class */ (function () {
|
|
4130
|
+
function KeyboardInteractions(_a) {
|
|
4131
|
+
var canvas = _a.canvas, stateMachine = _a.stateMachine, hasFocusNodes = _a.hasFocusNodes;
|
|
4132
|
+
var _this = this;
|
|
4133
|
+
this.focusSessionState = FocusSessionState.NotFocused;
|
|
4134
|
+
/**
|
|
4135
|
+
* Handles the canvas gaining browser focus. The behavior differs based on how focus was gained -
|
|
4136
|
+
*
|
|
4137
|
+
* Pointer-driven focus: the canvas now has focus but Rive holds nothing yet, so we move to EntryPending — this lets the
|
|
4138
|
+
* next Tab enter the focus tree even when the focus is pointer-driven
|
|
4139
|
+
*
|
|
4140
|
+
* Keyboard-driven focus: we enter the Rive focus tree immediately once canvas gains focus.
|
|
4141
|
+
* The direction is inferred from where focus came from: an element before the canvas in DOM order
|
|
4142
|
+
* means a forward Tab (focusNext), one after means a Shift+Tab (focusPrevious). :focus-visible
|
|
4143
|
+
* gates this so a click doesn't yank Rive focus to the first node on the focus event itself.
|
|
4144
|
+
*/
|
|
4145
|
+
this.onCanvasFocus = function (event) {
|
|
4146
|
+
if (!_this.hasFocusNodes)
|
|
4147
|
+
return;
|
|
4148
|
+
if (_this.mainSm.focusState().hasFocus)
|
|
4149
|
+
return;
|
|
4150
|
+
_this.focusSessionState = FocusSessionState.EntryPending;
|
|
4151
|
+
// Pointer focus waits for the user's next Tab (handled in onKeyDown). Keyboard focus enters now.
|
|
4152
|
+
if (!_this.isKeyboardDrivenFocus())
|
|
4153
|
+
return;
|
|
4154
|
+
var forward = _this.cameFromBeforeCanvas(event.relatedTarget);
|
|
4155
|
+
if (forward ? _this.mainSm.focusNext() : _this.mainSm.focusPrevious()) {
|
|
4156
|
+
_this.focusSessionState = FocusSessionState.RiveFocused;
|
|
4126
4157
|
}
|
|
4127
|
-
|
|
4128
|
-
|
|
4129
|
-
|
|
4130
|
-
|
|
4158
|
+
};
|
|
4159
|
+
this.onCanvasBlur = function (_event) {
|
|
4160
|
+
_this.focusSessionState = FocusSessionState.NotFocused;
|
|
4161
|
+
};
|
|
4162
|
+
this.onKeyDown = function (event) {
|
|
4163
|
+
if (_this.focusSessionState === FocusSessionState.NotFocused)
|
|
4164
|
+
return;
|
|
4165
|
+
if (event.code === "Tab" && _this.hasFocusNodes) {
|
|
4166
|
+
var forward = !event.shiftKey;
|
|
4167
|
+
var focusMoved = forward ? _this.mainSm.focusNext() : _this.mainSm.focusPrevious();
|
|
4168
|
+
if (focusMoved) {
|
|
4169
|
+
// A Rive node accepted focus — keep trapping Tab inside the canvas.
|
|
4170
|
+
_this.focusSessionState = FocusSessionState.RiveFocused;
|
|
4171
|
+
event.preventDefault();
|
|
4172
|
+
}
|
|
4173
|
+
else {
|
|
4174
|
+
// No more traversable nodes — release Tab to the page.
|
|
4175
|
+
// Set state immediately; onCanvasBlur will also fire naturally.
|
|
4176
|
+
_this.focusSessionState = FocusSessionState.NotFocused;
|
|
4177
|
+
}
|
|
4131
4178
|
}
|
|
4132
|
-
}
|
|
4179
|
+
};
|
|
4180
|
+
this.canvas = canvas;
|
|
4181
|
+
this.mainSm = stateMachine;
|
|
4182
|
+
this.hasFocusNodes = hasFocusNodes;
|
|
4183
|
+
canvas.addEventListener("focus", this.onCanvasFocus);
|
|
4184
|
+
canvas.addEventListener("blur", this.onCanvasBlur);
|
|
4185
|
+
canvas.addEventListener("keydown", this.onKeyDown);
|
|
4186
|
+
}
|
|
4187
|
+
/**
|
|
4188
|
+
* Set the FocusSessionState. Useful for invoking a Rive "blur" without actually blurring from the <canvas>. This
|
|
4189
|
+
* helps put the DOM focus state on the canvas rather than the <body>, so the user doesn't lose the spot in page navigation
|
|
4190
|
+
*
|
|
4191
|
+
* @param state FocusSessionState enum
|
|
4192
|
+
*/
|
|
4193
|
+
KeyboardInteractions.prototype.setFocusSessionState = function (state) {
|
|
4194
|
+
this.focusSessionState = state;
|
|
4133
4195
|
};
|
|
4134
|
-
|
|
4135
|
-
|
|
4136
|
-
|
|
4137
|
-
|
|
4138
|
-
|
|
4139
|
-
|
|
4140
|
-
|
|
4196
|
+
/**
|
|
4197
|
+
* Called by pollFocusState on the Rive instance when it observes hasFocus=true. Rive acquired
|
|
4198
|
+
* focus internally (e.g. via a listener action or state transition) without a DOM focus event,
|
|
4199
|
+
* so mark the session RiveFocused.
|
|
4200
|
+
*/
|
|
4201
|
+
KeyboardInteractions.prototype.notifyRiveFocused = function () {
|
|
4202
|
+
this.focusSessionState = FocusSessionState.RiveFocused;
|
|
4141
4203
|
};
|
|
4142
|
-
|
|
4204
|
+
/**
|
|
4205
|
+
* Whether the canvas currently matches :focus-visible — the browser's heuristic for keyboard-
|
|
4206
|
+
* (vs pointer-) driven focus. For older browser versions that don't support this selector, return false
|
|
4207
|
+
* so that we don't incorrectly assume pointer vs keyboard focus. Next tab would enter the focus tree in those edge cases.
|
|
4208
|
+
*/
|
|
4209
|
+
KeyboardInteractions.prototype.isKeyboardDrivenFocus = function () {
|
|
4210
|
+
try {
|
|
4211
|
+
return this.canvas.matches(":focus-visible");
|
|
4212
|
+
}
|
|
4213
|
+
catch (_a) {
|
|
4214
|
+
return false;
|
|
4215
|
+
}
|
|
4216
|
+
};
|
|
4217
|
+
KeyboardInteractions.prototype.cameFromBeforeCanvas = function (from) {
|
|
4218
|
+
if (!from)
|
|
4219
|
+
return true;
|
|
4220
|
+
var position = this.canvas.compareDocumentPosition(from);
|
|
4221
|
+
if (position & Node.DOCUMENT_POSITION_PRECEDING)
|
|
4222
|
+
return true;
|
|
4223
|
+
if (position & Node.DOCUMENT_POSITION_FOLLOWING)
|
|
4224
|
+
return false;
|
|
4225
|
+
return true;
|
|
4226
|
+
};
|
|
4227
|
+
KeyboardInteractions.prototype.cleanup = function () {
|
|
4228
|
+
this.canvas.removeEventListener("focus", this.onCanvasFocus);
|
|
4229
|
+
this.canvas.removeEventListener("blur", this.onCanvasBlur);
|
|
4230
|
+
this.canvas.removeEventListener("keydown", this.onKeyDown);
|
|
4231
|
+
};
|
|
4232
|
+
return KeyboardInteractions;
|
|
4233
|
+
}());
|
|
4234
|
+
|
|
4143
4235
|
|
|
4144
4236
|
|
|
4145
4237
|
/***/ }),
|
|
@@ -4337,6 +4429,9 @@ var CustomFileAssetLoaderWrapper = /** @class */ (function () {
|
|
|
4337
4429
|
else if (asset.isFont) {
|
|
4338
4430
|
assetWrapper = new FontAssetWrapper(asset);
|
|
4339
4431
|
}
|
|
4432
|
+
else {
|
|
4433
|
+
return false;
|
|
4434
|
+
}
|
|
4340
4435
|
return this._assetLoaderCallback(assetWrapper, bytes);
|
|
4341
4436
|
};
|
|
4342
4437
|
return CustomFileAssetLoaderWrapper;
|
|
@@ -4976,6 +5071,7 @@ var StateMachine = /** @class */ (function () {
|
|
|
4976
5071
|
this.inputs = [];
|
|
4977
5072
|
this.instance = new runtime.StateMachineInstance(stateMachine, artboard);
|
|
4978
5073
|
this.initInputs(runtime);
|
|
5074
|
+
this.hasFocusNodes = this.instance.hasFocusNodes();
|
|
4979
5075
|
}
|
|
4980
5076
|
Object.defineProperty(StateMachine.prototype, "name", {
|
|
4981
5077
|
get: function () {
|
|
@@ -5071,6 +5167,19 @@ var StateMachine = /** @class */ (function () {
|
|
|
5071
5167
|
this.instance.bindViewModelInstance(viewModelInstance.runtimeInstance);
|
|
5072
5168
|
}
|
|
5073
5169
|
};
|
|
5170
|
+
/**
|
|
5171
|
+
* Get metadata about the state of focus if applicable for this state machine.
|
|
5172
|
+
* @returns FocusState - { hasFocus: boolean, expectsKeyboardInput: boolean }
|
|
5173
|
+
*/
|
|
5174
|
+
StateMachine.prototype.focusState = function () {
|
|
5175
|
+
return this.instance.focusState();
|
|
5176
|
+
};
|
|
5177
|
+
/**
|
|
5178
|
+
* Clear focus from the Rive focus node tree.
|
|
5179
|
+
*/
|
|
5180
|
+
StateMachine.prototype.clearFocus = function () {
|
|
5181
|
+
this.instance.clearFocus();
|
|
5182
|
+
};
|
|
5074
5183
|
return StateMachine;
|
|
5075
5184
|
}());
|
|
5076
5185
|
// #endregion
|
|
@@ -6077,7 +6186,7 @@ var RiveFile = /** @class */ (function () {
|
|
|
6077
6186
|
var Rive = /** @class */ (function () {
|
|
6078
6187
|
function Rive(params) {
|
|
6079
6188
|
var _this = this;
|
|
6080
|
-
var _a, _b;
|
|
6189
|
+
var _a, _b, _c;
|
|
6081
6190
|
// Tracks if a Rive file is loaded
|
|
6082
6191
|
this.loaded = false;
|
|
6083
6192
|
// Tracks if a Rive file is destroyed
|
|
@@ -6096,8 +6205,8 @@ var Rive = /** @class */ (function () {
|
|
|
6096
6205
|
this.artboard = null;
|
|
6097
6206
|
// place to clear up pointer/touch event listeners
|
|
6098
6207
|
this.eventCleanup = null;
|
|
6099
|
-
//
|
|
6100
|
-
this.
|
|
6208
|
+
// Manages keyboard and DOM-focus interactions for the canvas.
|
|
6209
|
+
this._keyboardInteractions = null;
|
|
6101
6210
|
this.shouldDisableRiveListeners = false;
|
|
6102
6211
|
this.automaticallyHandleEvents = false;
|
|
6103
6212
|
this.dispatchPointerExit = true;
|
|
@@ -6135,6 +6244,10 @@ var Rive = /** @class */ (function () {
|
|
|
6135
6244
|
this._viewModelInstance = null;
|
|
6136
6245
|
this._dataEnums = null;
|
|
6137
6246
|
this._tabIndex = null;
|
|
6247
|
+
this._prevHasFocus = false;
|
|
6248
|
+
this._focusOptions = {
|
|
6249
|
+
allowFocusInterrupt: false,
|
|
6250
|
+
};
|
|
6138
6251
|
this.drawOptimization = DrawOptimizationOptions.DrawOnChanged;
|
|
6139
6252
|
// When true, emits performance.mark/measure entries for load and render.
|
|
6140
6253
|
this.enablePerfMarks = false;
|
|
@@ -6193,6 +6306,7 @@ var Rive = /** @class */ (function () {
|
|
|
6193
6306
|
this.enablePerfMarks = !!params.enablePerfMarks;
|
|
6194
6307
|
if (this.enablePerfMarks)
|
|
6195
6308
|
_runtimeLoader__WEBPACK_IMPORTED_MODULE_1__.RuntimeLoader.enablePerfMarks = true;
|
|
6309
|
+
this._focusOptions = (_c = params.focusOptions) !== null && _c !== void 0 ? _c : this._focusOptions;
|
|
6196
6310
|
// New event management system
|
|
6197
6311
|
this.eventManager = new EventManager();
|
|
6198
6312
|
if (params.onLoad)
|
|
@@ -6345,10 +6459,7 @@ var Rive = /** @class */ (function () {
|
|
|
6345
6459
|
if (this.eventCleanup) {
|
|
6346
6460
|
this.eventCleanup();
|
|
6347
6461
|
}
|
|
6348
|
-
|
|
6349
|
-
this.keyboardEventCleanup();
|
|
6350
|
-
this.keyboardEventCleanup = null;
|
|
6351
|
-
}
|
|
6462
|
+
this.cleanupKeyboardInteractions();
|
|
6352
6463
|
if (!this.shouldDisableRiveListeners) {
|
|
6353
6464
|
var playingStateMachines = this.animator.stateMachines.filter(function (sm) { return sm.playing; });
|
|
6354
6465
|
var activeStateMachines = playingStateMachines
|
|
@@ -6373,12 +6484,11 @@ var Rive = /** @class */ (function () {
|
|
|
6373
6484
|
dispatchPointerExit: dispatchPointerExit,
|
|
6374
6485
|
enableMultiTouch: enableMultiTouch,
|
|
6375
6486
|
layoutScaleFactor: this._layout.layoutScaleFactor,
|
|
6487
|
+
advanceAndDrain: this.advanceAndReportChanges.bind(this)
|
|
6376
6488
|
});
|
|
6377
6489
|
// Wire up keyboard interactions for state machines that have focus nodes.
|
|
6378
6490
|
// hasFocusNodes — unified focus tree check, gates tab traversal
|
|
6379
|
-
var smWithFocusNodes = playingStateMachines
|
|
6380
|
-
.filter(function (sm) { return sm.instance.hasFocusNodes(); })
|
|
6381
|
-
.map(function (sm) { return sm.instance; });
|
|
6491
|
+
var smWithFocusNodes = playingStateMachines.filter(function (sm) { return sm.hasFocusNodes; });
|
|
6382
6492
|
if (smWithFocusNodes.length) {
|
|
6383
6493
|
// Set the canvas as a tabbable element if there are any focus nodes.
|
|
6384
6494
|
// Prefer the tabIndex param set by the user, otherwise use 0.
|
|
@@ -6388,15 +6498,22 @@ var Rive = /** @class */ (function () {
|
|
|
6388
6498
|
if (currentCanvasTabIndex === -1 || isNaN(currentCanvasTabIndex)) {
|
|
6389
6499
|
this.canvas.tabIndex = (this._tabIndex !== null ? this._tabIndex : 0);
|
|
6390
6500
|
}
|
|
6391
|
-
|
|
6392
|
-
|
|
6393
|
-
|
|
6394
|
-
|
|
6395
|
-
|
|
6396
|
-
|
|
6501
|
+
if (typeof window !== "undefined") {
|
|
6502
|
+
this._keyboardInteractions = new _utils__WEBPACK_IMPORTED_MODULE_2__.KeyboardInteractions({
|
|
6503
|
+
canvas: this.canvas,
|
|
6504
|
+
stateMachine: smWithFocusNodes[0].instance, // work off assumption of single state machine
|
|
6505
|
+
hasFocusNodes: true,
|
|
6506
|
+
});
|
|
6507
|
+
}
|
|
6397
6508
|
}
|
|
6398
6509
|
}
|
|
6399
6510
|
};
|
|
6511
|
+
Rive.prototype.cleanupKeyboardInteractions = function () {
|
|
6512
|
+
if (this._keyboardInteractions) {
|
|
6513
|
+
this._keyboardInteractions.cleanup();
|
|
6514
|
+
this._keyboardInteractions = null;
|
|
6515
|
+
}
|
|
6516
|
+
};
|
|
6400
6517
|
/**
|
|
6401
6518
|
* Remove Rive Listeners setup on the canvas
|
|
6402
6519
|
*/
|
|
@@ -6405,10 +6522,7 @@ var Rive = /** @class */ (function () {
|
|
|
6405
6522
|
this.eventCleanup();
|
|
6406
6523
|
this.eventCleanup = null;
|
|
6407
6524
|
}
|
|
6408
|
-
|
|
6409
|
-
this.keyboardEventCleanup();
|
|
6410
|
-
this.keyboardEventCleanup = null;
|
|
6411
|
-
}
|
|
6525
|
+
this.cleanupKeyboardInteractions();
|
|
6412
6526
|
};
|
|
6413
6527
|
/**
|
|
6414
6528
|
* If the instance has audio and the system audio is not ready
|
|
@@ -6586,27 +6700,53 @@ var Rive = /** @class */ (function () {
|
|
|
6586
6700
|
return changed;
|
|
6587
6701
|
};
|
|
6588
6702
|
/**
|
|
6589
|
-
*
|
|
6590
|
-
*
|
|
6703
|
+
* Poll focus state each frame to see if we should focus/blur the canvas in case
|
|
6704
|
+
* Rive internally updated focus outside of user interaction (e.g., via listener action)
|
|
6591
6705
|
*/
|
|
6592
|
-
Rive.prototype.
|
|
6593
|
-
|
|
6594
|
-
|
|
6595
|
-
|
|
6596
|
-
var before = performance.now();
|
|
6597
|
-
// On the first pass, make sure lastTime has a valid value
|
|
6598
|
-
if (!this.lastRenderTime) {
|
|
6599
|
-
this.lastRenderTime = time;
|
|
6706
|
+
Rive.prototype.pollFocusState = function () {
|
|
6707
|
+
if (!this._keyboardInteractions) {
|
|
6708
|
+
this._prevHasFocus = false;
|
|
6709
|
+
return;
|
|
6600
6710
|
}
|
|
6601
|
-
//
|
|
6602
|
-
|
|
6603
|
-
|
|
6604
|
-
|
|
6605
|
-
onSecond === null || onSecond === void 0 ? void 0 : onSecond();
|
|
6711
|
+
var activeSm = this.animator.stateMachines.find(function (sm) { return sm.playing && sm.hasFocusNodes; }); // work off assumption of single state machine
|
|
6712
|
+
if (!activeSm) {
|
|
6713
|
+
this._prevHasFocus = false;
|
|
6714
|
+
return;
|
|
6606
6715
|
}
|
|
6607
|
-
|
|
6608
|
-
|
|
6609
|
-
|
|
6716
|
+
if (this.canvas instanceof HTMLCanvasElement) {
|
|
6717
|
+
var hasFocus = activeSm.focusState().hasFocus;
|
|
6718
|
+
if (hasFocus) {
|
|
6719
|
+
// Rive has an active focus node. Mark the session RiveFocused so Tab stays
|
|
6720
|
+
// trapped and a later internal release (hasFocus true → false) is detected.
|
|
6721
|
+
this._keyboardInteractions.notifyRiveFocused();
|
|
6722
|
+
// Only steal DOM focus on the false→true transition. If hasFocus stays
|
|
6723
|
+
// true across frames and the user clicks away, do not re-focus the canvas again.
|
|
6724
|
+
if (!this._prevHasFocus) {
|
|
6725
|
+
if (this.canvas !== document.activeElement && this._focusOptions.allowFocusInterrupt) {
|
|
6726
|
+
this.canvas.focus();
|
|
6727
|
+
}
|
|
6728
|
+
this._prevHasFocus = true;
|
|
6729
|
+
}
|
|
6730
|
+
return;
|
|
6731
|
+
}
|
|
6732
|
+
this._prevHasFocus = false;
|
|
6733
|
+
// hasFocus is false — only act when Rive previously held focus and released it internally
|
|
6734
|
+
// (state change clears focus). Release the DOM Tab trap so the next Tab moves to the next
|
|
6735
|
+
// page element. EntryPending and NotFocused cases are intentional no-ops — EntryPending in
|
|
6736
|
+
// particular must stay in its state (a click awaiting its first Tab) rather than be reset here.
|
|
6737
|
+
if (this._keyboardInteractions.focusSessionState === _utils__WEBPACK_IMPORTED_MODULE_2__.FocusSessionState.RiveFocused) {
|
|
6738
|
+
this._keyboardInteractions.setFocusSessionState(_utils__WEBPACK_IMPORTED_MODULE_2__.FocusSessionState.NotFocused);
|
|
6739
|
+
}
|
|
6740
|
+
}
|
|
6741
|
+
};
|
|
6742
|
+
/**
|
|
6743
|
+
* Handles important sequence of reporting Rive events, advancing the state machine or animation, and invoking various callbacks
|
|
6744
|
+
* due to state changes, view model property changes, etc.
|
|
6745
|
+
*
|
|
6746
|
+
* @param elapsedTime time to advance the state machine by
|
|
6747
|
+
*/
|
|
6748
|
+
Rive.prototype.advanceAndReportChanges = function (elapsedTime) {
|
|
6749
|
+
var _a;
|
|
6610
6750
|
// - Advance non-paused animations by the elapsed number of seconds
|
|
6611
6751
|
// - Advance any animations that require scrubbing
|
|
6612
6752
|
// - Advance to the first frame even when autoplay is false
|
|
@@ -6670,13 +6810,48 @@ var Rive = /** @class */ (function () {
|
|
|
6670
6810
|
performance.mark("rive:sm-advance:end:f".concat(_perfFrame));
|
|
6671
6811
|
performance.measure("rive:sm-advance:f".concat(_perfFrame), "rive:sm-advance:start:f".concat(_perfFrame), "rive:sm-advance:end:f".concat(_perfFrame));
|
|
6672
6812
|
}
|
|
6673
|
-
// stateMachine.instance.apply(this.artboard);
|
|
6674
6813
|
}
|
|
6675
|
-
//
|
|
6814
|
+
// For linear animations that have been applied to the artboard, advance it
|
|
6676
6815
|
// by the elapsed time.
|
|
6677
6816
|
if (this.animator.stateMachines.length == 0) {
|
|
6678
6817
|
this.artboard.advance(elapsedTime);
|
|
6679
6818
|
}
|
|
6819
|
+
// Check for any animations that looped
|
|
6820
|
+
this.animator.handleLooping();
|
|
6821
|
+
// Check for any state machines that had a state change
|
|
6822
|
+
this.animator.handleStateChanges();
|
|
6823
|
+
// Report advanced time
|
|
6824
|
+
this.animator.handleAdvancing(elapsedTime);
|
|
6825
|
+
// Poll focus state to see whether or not to blur or pull up a virtual keyboard for any change to a text input node.
|
|
6826
|
+
this.pollFocusState();
|
|
6827
|
+
// Handle callbacks for view model property changes
|
|
6828
|
+
(_a = this._viewModelInstance) === null || _a === void 0 ? void 0 : _a.handleCallbacks();
|
|
6829
|
+
};
|
|
6830
|
+
/**
|
|
6831
|
+
* Draw rendering loop; renders animation frames at the correct time interval.
|
|
6832
|
+
* @param time the time at which to render a frame
|
|
6833
|
+
*/
|
|
6834
|
+
Rive.prototype.draw = function (time, onSecond) {
|
|
6835
|
+
// Clear the frameRequestId, as we're now rendering a fresh frame
|
|
6836
|
+
this.frameRequestId = null;
|
|
6837
|
+
var before = performance.now();
|
|
6838
|
+
// Instrument the first 3 frames so the Performance timeline shows precise
|
|
6839
|
+
// per-call latency for advance, draw, and flush without polluting the trace.
|
|
6840
|
+
var _perfFrame = this.enablePerfMarks && this.frameCount < 3 ? this.frameCount : -1;
|
|
6841
|
+
// On the first pass, make sure lastTime has a valid value
|
|
6842
|
+
if (!this.lastRenderTime) {
|
|
6843
|
+
this.lastRenderTime = time;
|
|
6844
|
+
}
|
|
6845
|
+
// Handle the onSecond callback
|
|
6846
|
+
this.renderSecondTimer += time - this.lastRenderTime;
|
|
6847
|
+
if (this.renderSecondTimer > 5000) {
|
|
6848
|
+
this.renderSecondTimer = 0;
|
|
6849
|
+
onSecond === null || onSecond === void 0 ? void 0 : onSecond();
|
|
6850
|
+
}
|
|
6851
|
+
// Calculate the elapsed time between frames in seconds
|
|
6852
|
+
var elapsedTime = (time - this.lastRenderTime) / 1000;
|
|
6853
|
+
this.lastRenderTime = time;
|
|
6854
|
+
this.advanceAndReportChanges(elapsedTime);
|
|
6680
6855
|
var renderer = this.renderer;
|
|
6681
6856
|
// Do not draw on 0 canvas size
|
|
6682
6857
|
if (!this._hasZeroSize) {
|
|
@@ -6714,12 +6889,6 @@ var Rive = /** @class */ (function () {
|
|
|
6714
6889
|
this._needsRedraw = false;
|
|
6715
6890
|
}
|
|
6716
6891
|
}
|
|
6717
|
-
// Check for any animations that looped
|
|
6718
|
-
this.animator.handleLooping();
|
|
6719
|
-
// Check for any state machines that had a state change
|
|
6720
|
-
this.animator.handleStateChanges();
|
|
6721
|
-
// Report advanced time
|
|
6722
|
-
this.animator.handleAdvancing(elapsedTime);
|
|
6723
6892
|
// Add duration to create frame to durations array
|
|
6724
6893
|
this.frameCount++;
|
|
6725
6894
|
var after = performance.now();
|
|
@@ -6729,7 +6898,6 @@ var Rive = /** @class */ (function () {
|
|
|
6729
6898
|
this.frameTimes.shift();
|
|
6730
6899
|
this.durations.shift();
|
|
6731
6900
|
}
|
|
6732
|
-
(_a = this._viewModelInstance) === null || _a === void 0 ? void 0 : _a.handleCallbacks();
|
|
6733
6901
|
// Calling requestAnimationFrame will rerun draw() at the correct rate:
|
|
6734
6902
|
// https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Basic_animations
|
|
6735
6903
|
if (this.animator.isPlaying) {
|
|
@@ -6836,10 +7004,7 @@ var Rive = /** @class */ (function () {
|
|
|
6836
7004
|
if (this.eventCleanup !== null) {
|
|
6837
7005
|
this.eventCleanup();
|
|
6838
7006
|
}
|
|
6839
|
-
|
|
6840
|
-
this.keyboardEventCleanup();
|
|
6841
|
-
this.keyboardEventCleanup = null;
|
|
6842
|
-
}
|
|
7007
|
+
this.cleanupKeyboardInteractions();
|
|
6843
7008
|
// Delete all animation and state machine instances
|
|
6844
7009
|
this.stop();
|
|
6845
7010
|
if (this.artboard) {
|
|
@@ -6908,10 +7073,7 @@ var Rive = /** @class */ (function () {
|
|
|
6908
7073
|
if (this.eventCleanup) {
|
|
6909
7074
|
this.eventCleanup();
|
|
6910
7075
|
}
|
|
6911
|
-
|
|
6912
|
-
this.keyboardEventCleanup();
|
|
6913
|
-
this.keyboardEventCleanup = null;
|
|
6914
|
-
}
|
|
7076
|
+
this.cleanupKeyboardInteractions();
|
|
6915
7077
|
this.setupRiveListeners();
|
|
6916
7078
|
this.startRendering();
|
|
6917
7079
|
};
|
|
@@ -6929,10 +7091,7 @@ var Rive = /** @class */ (function () {
|
|
|
6929
7091
|
if (this.eventCleanup) {
|
|
6930
7092
|
this.eventCleanup();
|
|
6931
7093
|
}
|
|
6932
|
-
|
|
6933
|
-
this.keyboardEventCleanup();
|
|
6934
|
-
this.keyboardEventCleanup = null;
|
|
6935
|
-
}
|
|
7094
|
+
this.cleanupKeyboardInteractions();
|
|
6936
7095
|
this.animator.pause(animationNames);
|
|
6937
7096
|
};
|
|
6938
7097
|
Rive.prototype.scrub = function (animationNames, value) {
|
|
@@ -6968,10 +7127,7 @@ var Rive = /** @class */ (function () {
|
|
|
6968
7127
|
if (this.eventCleanup) {
|
|
6969
7128
|
this.eventCleanup();
|
|
6970
7129
|
}
|
|
6971
|
-
|
|
6972
|
-
this.keyboardEventCleanup();
|
|
6973
|
-
this.keyboardEventCleanup = null;
|
|
6974
|
-
}
|
|
7130
|
+
this.cleanupKeyboardInteractions();
|
|
6975
7131
|
};
|
|
6976
7132
|
/**
|
|
6977
7133
|
* Resets the animation
|
|
@@ -7722,6 +7878,14 @@ var Rive = /** @class */ (function () {
|
|
|
7722
7878
|
var _a, _b;
|
|
7723
7879
|
return (_b = (_a = this.riveFile) === null || _a === void 0 ? void 0 : _a.getDefaultBindableArtboard()) !== null && _b !== void 0 ? _b : null;
|
|
7724
7880
|
};
|
|
7881
|
+
/**
|
|
7882
|
+
* Clear focus applicable to active state machines with focus nodes. Useful if users want to
|
|
7883
|
+
* reset focus state and behavior within the Rive graphic at any point (i.e. blurring off the canvas)
|
|
7884
|
+
*/
|
|
7885
|
+
Rive.prototype.clearFocus = function () {
|
|
7886
|
+
var playingStateMachines = this.animator.stateMachines.filter(function (sm) { return sm.playing && sm.hasFocusNodes; });
|
|
7887
|
+
playingStateMachines.forEach(function (sm) { return sm.clearFocus(); });
|
|
7888
|
+
};
|
|
7725
7889
|
// Error message for missing source or buffer
|
|
7726
7890
|
Rive.missingErrorMessage = "Rive source file or data buffer required";
|
|
7727
7891
|
// Error message for removed rive file
|