@rive-app/webgl2 2.38.5 → 2.39.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 +3 -2
- package/rive.d.ts +118 -1
- package/rive.js +2389 -104
- package/rive.js.map +1 -1
- package/rive.wasm +0 -0
- package/rive_advanced.mjs.d.ts +131 -0
- package/rive_fallback.wasm +0 -0
- package/semantics/accessibilityOverlay.d.ts +217 -0
- package/semantics/index.d.ts +5 -0
- package/semantics/semanticTreeModel.d.ts +64 -0
- package/semantics/types.d.ts +94 -0
- package/utils/registerKeyboardInteractions.d.ts +31 -1
package/rive.js
CHANGED
|
@@ -777,7 +777,7 @@ function Ma(a, b) {
|
|
|
777
777
|
return La(c, a, b);
|
|
778
778
|
}));
|
|
779
779
|
}
|
|
780
|
-
var Na, Oa, Sa = {
|
|
780
|
+
var Na, Oa, Sa = {573663:(a, b, c, d, e) => {
|
|
781
781
|
if ("undefined" === typeof window || void 0 === (window.AudioContext || window.webkitAudioContext)) {
|
|
782
782
|
return 0;
|
|
783
783
|
}
|
|
@@ -840,11 +840,11 @@ var Na, Oa, Sa = {571903:(a, b, c, d, e) => {
|
|
|
840
840
|
}
|
|
841
841
|
window.miniaudio.referenceCount += 1;
|
|
842
842
|
return 1;
|
|
843
|
-
},
|
|
843
|
+
}, 575841:() => {
|
|
844
844
|
"undefined" !== typeof window.miniaudio && (window.miniaudio.unlock_event_types.map(function(a) {
|
|
845
845
|
document.removeEventListener(a, window.miniaudio.unlock, !0);
|
|
846
846
|
}), --window.miniaudio.referenceCount, 0 === window.miniaudio.referenceCount && delete window.miniaudio);
|
|
847
|
-
},
|
|
847
|
+
}, 576145:() => void 0 !== navigator.mediaDevices && void 0 !== navigator.mediaDevices.getUserMedia, 576249:() => {
|
|
848
848
|
try {
|
|
849
849
|
var a = new (window.AudioContext || window.webkitAudioContext)(), b = a.sampleRate;
|
|
850
850
|
a.close();
|
|
@@ -852,7 +852,7 @@ var Na, Oa, Sa = {571903:(a, b, c, d, e) => {
|
|
|
852
852
|
} catch (c) {
|
|
853
853
|
return 0;
|
|
854
854
|
}
|
|
855
|
-
},
|
|
855
|
+
}, 576420:(a, b, c, d, e, f) => {
|
|
856
856
|
if ("undefined" === typeof window.miniaudio) {
|
|
857
857
|
return -1;
|
|
858
858
|
}
|
|
@@ -898,7 +898,7 @@ var Na, Oa, Sa = {571903:(a, b, c, d, e) => {
|
|
|
898
898
|
a == window.miniaudio.device_type.playback && g.V.connect(g.H.destination);
|
|
899
899
|
g.gb = f;
|
|
900
900
|
return window.miniaudio.track_device(g);
|
|
901
|
-
},
|
|
901
|
+
}, 579297:a => window.miniaudio.get_device_by_index(a).H.sampleRate, 579370:a => {
|
|
902
902
|
a = window.miniaudio.get_device_by_index(a);
|
|
903
903
|
void 0 !== a.V && (a.V.onaudioprocess = function() {
|
|
904
904
|
}, a.V.disconnect(), a.V = void 0);
|
|
@@ -906,13 +906,13 @@ var Na, Oa, Sa = {571903:(a, b, c, d, e) => {
|
|
|
906
906
|
a.H.close();
|
|
907
907
|
a.H = void 0;
|
|
908
908
|
a.gb = void 0;
|
|
909
|
-
},
|
|
909
|
+
}, 579770:a => {
|
|
910
910
|
window.miniaudio.untrack_device_by_index(a);
|
|
911
|
-
},
|
|
911
|
+
}, 579820:a => {
|
|
912
912
|
a = window.miniaudio.get_device_by_index(a);
|
|
913
913
|
a.H.resume();
|
|
914
914
|
a.state = window.miniaudio.device_state.started;
|
|
915
|
-
},
|
|
915
|
+
}, 579959:a => {
|
|
916
916
|
a = window.miniaudio.get_device_by_index(a);
|
|
917
917
|
a.H.suspend();
|
|
918
918
|
a.state = window.miniaudio.device_state.stopped;
|
|
@@ -3595,8 +3595,6 @@ var de = {__syscall_fcntl64:function(a, b, c) {
|
|
|
3595
3595
|
c[d] = F[b + 4 * d >> 2];
|
|
3596
3596
|
}
|
|
3597
3597
|
W.drawBuffers(c);
|
|
3598
|
-
}, glDrawElements:(a, b, c, d) => {
|
|
3599
|
-
W.drawElements(a, b, c, d);
|
|
3600
3598
|
}, glDrawElementsInstanced:(a, b, c, d, e) => {
|
|
3601
3599
|
W.drawElementsInstanced(a, b, c, d, e);
|
|
3602
3600
|
}, glEnable:a => W.enable(a), glEnableVertexAttribArray:a => {
|
|
@@ -3923,12 +3921,1823 @@ moduleRtn = ca;
|
|
|
3923
3921
|
/* 5 */
|
|
3924
3922
|
/***/ ((module) => {
|
|
3925
3923
|
|
|
3926
|
-
module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/webgl2","version":"2.
|
|
3924
|
+
module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/webgl2","version":"2.39.1","description":"Rive\'s webgl2 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)","Chris Dalton <chris@rive.app> (https://rive.app)"],"license":"MIT","files":["rive.js","rive.wasm","rive_fallback.wasm","rive.js.map","rive.d.ts","rive_advanced.mjs.d.ts","runtimeLoader.d.ts","utils","semantics"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
|
|
3927
3925
|
|
|
3928
3926
|
/***/ }),
|
|
3929
3927
|
/* 6 */
|
|
3930
3928
|
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
3931
3929
|
|
|
3930
|
+
__webpack_require__.r(__webpack_exports__);
|
|
3931
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
3932
|
+
/* harmony export */ AccessibilityOverlay: () => (/* reexport safe */ _accessibilityOverlay__WEBPACK_IMPORTED_MODULE_1__.AccessibilityOverlay),
|
|
3933
|
+
/* harmony export */ SemanticActionType: () => (/* reexport safe */ _types__WEBPACK_IMPORTED_MODULE_2__.SemanticActionType),
|
|
3934
|
+
/* harmony export */ SemanticMode: () => (/* reexport safe */ _types__WEBPACK_IMPORTED_MODULE_2__.SemanticMode),
|
|
3935
|
+
/* harmony export */ SemanticRole: () => (/* reexport safe */ _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole),
|
|
3936
|
+
/* harmony export */ SemanticState: () => (/* reexport safe */ _types__WEBPACK_IMPORTED_MODULE_2__.SemanticState),
|
|
3937
|
+
/* harmony export */ SemanticTrait: () => (/* reexport safe */ _types__WEBPACK_IMPORTED_MODULE_2__.SemanticTrait),
|
|
3938
|
+
/* harmony export */ SemanticTreeModel: () => (/* reexport safe */ _semanticTreeModel__WEBPACK_IMPORTED_MODULE_0__.SemanticTreeModel),
|
|
3939
|
+
/* harmony export */ hasState: () => (/* reexport safe */ _types__WEBPACK_IMPORTED_MODULE_2__.hasState),
|
|
3940
|
+
/* harmony export */ hasTrait: () => (/* reexport safe */ _types__WEBPACK_IMPORTED_MODULE_2__.hasTrait),
|
|
3941
|
+
/* harmony export */ roleName: () => (/* reexport safe */ _types__WEBPACK_IMPORTED_MODULE_2__.roleName),
|
|
3942
|
+
/* harmony export */ stateNames: () => (/* reexport safe */ _types__WEBPACK_IMPORTED_MODULE_2__.stateNames),
|
|
3943
|
+
/* harmony export */ traitNames: () => (/* reexport safe */ _types__WEBPACK_IMPORTED_MODULE_2__.traitNames)
|
|
3944
|
+
/* harmony export */ });
|
|
3945
|
+
/* harmony import */ var _semanticTreeModel__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(7);
|
|
3946
|
+
/* harmony import */ var _accessibilityOverlay__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(9);
|
|
3947
|
+
/* harmony import */ var _types__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(8);
|
|
3948
|
+
|
|
3949
|
+
|
|
3950
|
+
|
|
3951
|
+
|
|
3952
|
+
|
|
3953
|
+
/***/ }),
|
|
3954
|
+
/* 7 */
|
|
3955
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
3956
|
+
|
|
3957
|
+
__webpack_require__.r(__webpack_exports__);
|
|
3958
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
3959
|
+
/* harmony export */ SemanticTreeModel: () => (/* binding */ SemanticTreeModel)
|
|
3960
|
+
/* harmony export */ });
|
|
3961
|
+
/* harmony import */ var _types__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(8);
|
|
3962
|
+
var __spreadArray = (undefined && undefined.__spreadArray) || function (to, from, pack) {
|
|
3963
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
3964
|
+
if (ar || !(i in from)) {
|
|
3965
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
3966
|
+
ar[i] = from[i];
|
|
3967
|
+
}
|
|
3968
|
+
}
|
|
3969
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
3970
|
+
};
|
|
3971
|
+
|
|
3972
|
+
/**
|
|
3973
|
+
* Maintains an in-memory semantic tree built from incremental
|
|
3974
|
+
* {@link SemanticsDiff} updates received each frame from the WASM runtime.
|
|
3975
|
+
*
|
|
3976
|
+
* Processing order within {@link applyDiff} follows the contract defined in
|
|
3977
|
+
* `semantic_snapshot.hpp`: removed → added → moved → childrenUpdated →
|
|
3978
|
+
* updatedSemantic → updatedGeometry.
|
|
3979
|
+
*/
|
|
3980
|
+
var SemanticTreeModel = /** @class */ (function () {
|
|
3981
|
+
function SemanticTreeModel() {
|
|
3982
|
+
this._nodesById = new Map();
|
|
3983
|
+
this._roots = [];
|
|
3984
|
+
this._semanticVersion = 0;
|
|
3985
|
+
this._geometryVersion = 0;
|
|
3986
|
+
this._geometryChangedIds = new Set();
|
|
3987
|
+
this._semanticChangedIds = new Set();
|
|
3988
|
+
this._debug = false;
|
|
3989
|
+
}
|
|
3990
|
+
Object.defineProperty(SemanticTreeModel.prototype, "nodeCount", {
|
|
3991
|
+
get: function () {
|
|
3992
|
+
return this._nodesById.size;
|
|
3993
|
+
},
|
|
3994
|
+
enumerable: false,
|
|
3995
|
+
configurable: true
|
|
3996
|
+
});
|
|
3997
|
+
Object.defineProperty(SemanticTreeModel.prototype, "semanticVersion", {
|
|
3998
|
+
/** Bumped when semantic content or tree structure changes. */
|
|
3999
|
+
get: function () {
|
|
4000
|
+
return this._semanticVersion;
|
|
4001
|
+
},
|
|
4002
|
+
enumerable: false,
|
|
4003
|
+
configurable: true
|
|
4004
|
+
});
|
|
4005
|
+
Object.defineProperty(SemanticTreeModel.prototype, "geometryVersion", {
|
|
4006
|
+
/** Bumped when node bounds change without a semantic/structural change. */
|
|
4007
|
+
get: function () {
|
|
4008
|
+
return this._geometryVersion;
|
|
4009
|
+
},
|
|
4010
|
+
enumerable: false,
|
|
4011
|
+
configurable: true
|
|
4012
|
+
});
|
|
4013
|
+
Object.defineProperty(SemanticTreeModel.prototype, "geometryChangedIds", {
|
|
4014
|
+
/** Node IDs whose bounds changed in the most recent {@link applyDiff}. */
|
|
4015
|
+
get: function () {
|
|
4016
|
+
return this._geometryChangedIds;
|
|
4017
|
+
},
|
|
4018
|
+
enumerable: false,
|
|
4019
|
+
configurable: true
|
|
4020
|
+
});
|
|
4021
|
+
Object.defineProperty(SemanticTreeModel.prototype, "semanticChangedIds", {
|
|
4022
|
+
/**
|
|
4023
|
+
* Node IDs whose semantic fields (role/label/value/hint/flags/headingLevel)
|
|
4024
|
+
* changed in the most recent {@link applyDiff}. Structural changes (moves,
|
|
4025
|
+
* child reorders, removals) bump {@link semanticVersion} but don't mark
|
|
4026
|
+
* nodes here — element attributes don't depend on tree position.
|
|
4027
|
+
*/
|
|
4028
|
+
get: function () {
|
|
4029
|
+
return this._semanticChangedIds;
|
|
4030
|
+
},
|
|
4031
|
+
enumerable: false,
|
|
4032
|
+
configurable: true
|
|
4033
|
+
});
|
|
4034
|
+
Object.defineProperty(SemanticTreeModel.prototype, "roots", {
|
|
4035
|
+
/** Root node IDs in sibling order. */
|
|
4036
|
+
get: function () {
|
|
4037
|
+
return this._roots;
|
|
4038
|
+
},
|
|
4039
|
+
enumerable: false,
|
|
4040
|
+
configurable: true
|
|
4041
|
+
});
|
|
4042
|
+
/** Look up a node by its ID, or undefined if not in the tree. */
|
|
4043
|
+
SemanticTreeModel.prototype.nodeById = function (id) {
|
|
4044
|
+
return this._nodesById.get(id);
|
|
4045
|
+
};
|
|
4046
|
+
/** Current index of a node among its siblings (or roots), or -1 if absent. */
|
|
4047
|
+
SemanticTreeModel.prototype.siblingIndexOf = function (id) {
|
|
4048
|
+
var node = this._nodesById.get(id);
|
|
4049
|
+
if (!node)
|
|
4050
|
+
return -1;
|
|
4051
|
+
if (node.parentId < 0)
|
|
4052
|
+
return this._roots.indexOf(id);
|
|
4053
|
+
var parent = this._nodesById.get(node.parentId);
|
|
4054
|
+
return parent ? parent.children.indexOf(id) : -1;
|
|
4055
|
+
};
|
|
4056
|
+
/** Detach a node from its current parent (or from roots). */
|
|
4057
|
+
SemanticTreeModel.prototype.detach = function (id) {
|
|
4058
|
+
var node = this._nodesById.get(id);
|
|
4059
|
+
if (!node)
|
|
4060
|
+
return;
|
|
4061
|
+
if (node.parentId < 0) {
|
|
4062
|
+
var idx = this._roots.indexOf(id);
|
|
4063
|
+
if (idx !== -1)
|
|
4064
|
+
this._roots.splice(idx, 1);
|
|
4065
|
+
}
|
|
4066
|
+
else {
|
|
4067
|
+
var parent_1 = this._nodesById.get(node.parentId);
|
|
4068
|
+
if (parent_1) {
|
|
4069
|
+
var idx = parent_1.children.indexOf(id);
|
|
4070
|
+
if (idx !== -1)
|
|
4071
|
+
parent_1.children.splice(idx, 1);
|
|
4072
|
+
}
|
|
4073
|
+
}
|
|
4074
|
+
};
|
|
4075
|
+
/** Attach a node under a parent at a given sibling index (or as root). */
|
|
4076
|
+
SemanticTreeModel.prototype.attach = function (id, parentId, siblingIndex) {
|
|
4077
|
+
var node = this._nodesById.get(id);
|
|
4078
|
+
if (!node)
|
|
4079
|
+
return;
|
|
4080
|
+
if (parentId < 0) {
|
|
4081
|
+
node.parentId = -1;
|
|
4082
|
+
var idx = clamp(siblingIndex, 0, this._roots.length);
|
|
4083
|
+
this._roots.splice(idx, 0, id);
|
|
4084
|
+
}
|
|
4085
|
+
else {
|
|
4086
|
+
var parent_2 = this._nodesById.get(parentId);
|
|
4087
|
+
if (!parent_2) {
|
|
4088
|
+
node.parentId = -1;
|
|
4089
|
+
this._roots.push(id);
|
|
4090
|
+
}
|
|
4091
|
+
else {
|
|
4092
|
+
node.parentId = parentId;
|
|
4093
|
+
var idx = clamp(siblingIndex, 0, parent_2.children.length);
|
|
4094
|
+
parent_2.children.splice(idx, 0, id);
|
|
4095
|
+
}
|
|
4096
|
+
}
|
|
4097
|
+
};
|
|
4098
|
+
/** Recursively remove a node and all descendants. */
|
|
4099
|
+
SemanticTreeModel.prototype.removeSubtree = function (id) {
|
|
4100
|
+
var node = this._nodesById.get(id);
|
|
4101
|
+
if (!node)
|
|
4102
|
+
return;
|
|
4103
|
+
// Copy children array — we're mutating during traversal
|
|
4104
|
+
var kids = __spreadArray([], node.children, true);
|
|
4105
|
+
for (var _i = 0, kids_1 = kids; _i < kids_1.length; _i++) {
|
|
4106
|
+
var child = kids_1[_i];
|
|
4107
|
+
this.removeSubtree(child);
|
|
4108
|
+
}
|
|
4109
|
+
this.detach(id);
|
|
4110
|
+
this._nodesById.delete(id);
|
|
4111
|
+
};
|
|
4112
|
+
/**
|
|
4113
|
+
* Apply an incremental diff to the tree. Bumps version counters and notifies
|
|
4114
|
+
* listeners only when the tree actually changed.
|
|
4115
|
+
*
|
|
4116
|
+
* No-op diffs (field values identical to current model) do not bump
|
|
4117
|
+
* versions — the native side guards against emitting these, but applyDiff
|
|
4118
|
+
* defends its subscribers regardless.
|
|
4119
|
+
*/
|
|
4120
|
+
SemanticTreeModel.prototype.applyDiff = function (diff) {
|
|
4121
|
+
var _a, _b;
|
|
4122
|
+
var _this = this;
|
|
4123
|
+
this._geometryChangedIds.clear();
|
|
4124
|
+
this._semanticChangedIds.clear();
|
|
4125
|
+
var semanticChanged = false;
|
|
4126
|
+
var geometryChanged = false;
|
|
4127
|
+
var markSemantic = function () {
|
|
4128
|
+
semanticChanged = true;
|
|
4129
|
+
};
|
|
4130
|
+
var markSemanticNode = function (id) {
|
|
4131
|
+
semanticChanged = true;
|
|
4132
|
+
_this._semanticChangedIds.add(id);
|
|
4133
|
+
};
|
|
4134
|
+
var markGeometry = function (id) {
|
|
4135
|
+
geometryChanged = true;
|
|
4136
|
+
_this._geometryChangedIds.add(id);
|
|
4137
|
+
};
|
|
4138
|
+
// 1. removed
|
|
4139
|
+
for (var _i = 0, _c = diff.removed; _i < _c.length; _i++) {
|
|
4140
|
+
var id = _c[_i];
|
|
4141
|
+
if (this._nodesById.has(id)) {
|
|
4142
|
+
this.removeSubtree(id);
|
|
4143
|
+
markSemantic();
|
|
4144
|
+
}
|
|
4145
|
+
}
|
|
4146
|
+
// 2. added
|
|
4147
|
+
for (var _d = 0, _e = diff.added; _d < _e.length; _d++) {
|
|
4148
|
+
var n = _e[_d];
|
|
4149
|
+
var existing = this._nodesById.get(n.id);
|
|
4150
|
+
if (existing) {
|
|
4151
|
+
if (semanticFieldsDiffer(existing, n)) {
|
|
4152
|
+
applySemantic(existing, n);
|
|
4153
|
+
markSemanticNode(n.id);
|
|
4154
|
+
}
|
|
4155
|
+
if (geometryFieldsDiffer(existing, n)) {
|
|
4156
|
+
applyGeometry(existing, n);
|
|
4157
|
+
markGeometry(n.id);
|
|
4158
|
+
}
|
|
4159
|
+
}
|
|
4160
|
+
else {
|
|
4161
|
+
this._nodesById.set(n.id, nodeFromDiff(n));
|
|
4162
|
+
markSemanticNode(n.id);
|
|
4163
|
+
markGeometry(n.id);
|
|
4164
|
+
}
|
|
4165
|
+
this.detach(n.id);
|
|
4166
|
+
this.attach(n.id, n.parentId, n.siblingIndex);
|
|
4167
|
+
}
|
|
4168
|
+
// 3. moved
|
|
4169
|
+
// The runtime emits a node as "moved" when its parentId OR siblingIndex
|
|
4170
|
+
// changes, so a reorder-only move (same parent, new index) is still a
|
|
4171
|
+
// structural/semantic change. Compare the actual position before and after
|
|
4172
|
+
// re-attaching so that geometry-only or no-op moves don't bump the semantic
|
|
4173
|
+
// version (which would defeat the semantic/geometry version split).
|
|
4174
|
+
for (var _f = 0, _g = diff.moved; _f < _g.length; _f++) {
|
|
4175
|
+
var n = _g[_f];
|
|
4176
|
+
var existing = this._nodesById.get(n.id);
|
|
4177
|
+
if (!existing)
|
|
4178
|
+
continue;
|
|
4179
|
+
var parentChanged = existing.parentId !== n.parentId;
|
|
4180
|
+
var oldIndex = this.siblingIndexOf(n.id);
|
|
4181
|
+
var geomChanged = geometryFieldsDiffer(existing, n);
|
|
4182
|
+
if (geomChanged) {
|
|
4183
|
+
applyGeometry(existing, n);
|
|
4184
|
+
markGeometry(n.id);
|
|
4185
|
+
}
|
|
4186
|
+
this.detach(n.id);
|
|
4187
|
+
this.attach(n.id, n.parentId, n.siblingIndex);
|
|
4188
|
+
if (parentChanged || this.siblingIndexOf(n.id) !== oldIndex) {
|
|
4189
|
+
markSemantic();
|
|
4190
|
+
}
|
|
4191
|
+
}
|
|
4192
|
+
// 4. childrenUpdated
|
|
4193
|
+
for (var _h = 0, _j = diff.childrenUpdated; _h < _j.length; _h++) {
|
|
4194
|
+
var update = _j[_h];
|
|
4195
|
+
if (update.parentId < 0) {
|
|
4196
|
+
var next = update.childIds.filter(function (id) { return _this._nodesById.has(id); });
|
|
4197
|
+
if (!arraysEqual(this._roots, next)) {
|
|
4198
|
+
this._roots.length = 0;
|
|
4199
|
+
(_a = this._roots).push.apply(_a, next);
|
|
4200
|
+
for (var _k = 0, _l = this._roots; _k < _l.length; _k++) {
|
|
4201
|
+
var id = _l[_k];
|
|
4202
|
+
var node = this._nodesById.get(id);
|
|
4203
|
+
if (node)
|
|
4204
|
+
node.parentId = -1;
|
|
4205
|
+
}
|
|
4206
|
+
markSemantic();
|
|
4207
|
+
}
|
|
4208
|
+
}
|
|
4209
|
+
else {
|
|
4210
|
+
var parent_3 = this._nodesById.get(update.parentId);
|
|
4211
|
+
if (!parent_3)
|
|
4212
|
+
continue;
|
|
4213
|
+
var next = update.childIds.filter(function (id) { return _this._nodesById.has(id); });
|
|
4214
|
+
if (!arraysEqual(parent_3.children, next)) {
|
|
4215
|
+
parent_3.children.length = 0;
|
|
4216
|
+
(_b = parent_3.children).push.apply(_b, next);
|
|
4217
|
+
for (var _m = 0, _o = parent_3.children; _m < _o.length; _m++) {
|
|
4218
|
+
var id = _o[_m];
|
|
4219
|
+
var node = this._nodesById.get(id);
|
|
4220
|
+
if (node)
|
|
4221
|
+
node.parentId = update.parentId;
|
|
4222
|
+
}
|
|
4223
|
+
markSemantic();
|
|
4224
|
+
}
|
|
4225
|
+
}
|
|
4226
|
+
}
|
|
4227
|
+
// 5. updatedSemantic — semantic fields updated
|
|
4228
|
+
for (var _p = 0, _q = diff.updatedSemantic; _p < _q.length; _p++) {
|
|
4229
|
+
var n = _q[_p];
|
|
4230
|
+
var existing = this._nodesById.get(n.id);
|
|
4231
|
+
if (!existing)
|
|
4232
|
+
continue;
|
|
4233
|
+
if (!semanticFieldsDiffer(existing, n))
|
|
4234
|
+
continue;
|
|
4235
|
+
applySemantic(existing, n);
|
|
4236
|
+
markSemanticNode(n.id);
|
|
4237
|
+
}
|
|
4238
|
+
// 6. updatedGeometry — bounds of a semantic node updated
|
|
4239
|
+
for (var _r = 0, _s = diff.updatedGeometry; _r < _s.length; _r++) {
|
|
4240
|
+
var n = _s[_r];
|
|
4241
|
+
var existing = this._nodesById.get(n.id);
|
|
4242
|
+
if (!existing)
|
|
4243
|
+
continue;
|
|
4244
|
+
if (!geometryFieldsDiffer(existing, n))
|
|
4245
|
+
continue;
|
|
4246
|
+
applyGeometry(existing, n);
|
|
4247
|
+
markGeometry(n.id);
|
|
4248
|
+
}
|
|
4249
|
+
if (!semanticChanged && !geometryChanged)
|
|
4250
|
+
return;
|
|
4251
|
+
if (semanticChanged)
|
|
4252
|
+
this._semanticVersion++;
|
|
4253
|
+
if (geometryChanged)
|
|
4254
|
+
this._geometryVersion++;
|
|
4255
|
+
if (this._debug) {
|
|
4256
|
+
this.logDiff(diff, semanticChanged, geometryChanged);
|
|
4257
|
+
}
|
|
4258
|
+
};
|
|
4259
|
+
Object.defineProperty(SemanticTreeModel.prototype, "debug", {
|
|
4260
|
+
/** Enable/disable debug logging of diffs to the console. */
|
|
4261
|
+
set: function (enabled) {
|
|
4262
|
+
this._debug = enabled;
|
|
4263
|
+
},
|
|
4264
|
+
enumerable: false,
|
|
4265
|
+
configurable: true
|
|
4266
|
+
});
|
|
4267
|
+
SemanticTreeModel.prototype.logDiff = function (diff, semanticChanged, geometryChanged) {
|
|
4268
|
+
var lines = [
|
|
4269
|
+
"[rive:semantics] semantic v".concat(this._semanticVersion) +
|
|
4270
|
+
(geometryChanged ? " geometry v".concat(this._geometryVersion) : "") +
|
|
4271
|
+
(semanticChanged ? "" : " (geometry-only)"),
|
|
4272
|
+
];
|
|
4273
|
+
for (var _i = 0, _a = diff.removed; _i < _a.length; _i++) {
|
|
4274
|
+
var id = _a[_i];
|
|
4275
|
+
lines.push(" - removed #".concat(id));
|
|
4276
|
+
}
|
|
4277
|
+
for (var _b = 0, _c = diff.added; _b < _c.length; _b++) {
|
|
4278
|
+
var n = _c[_b];
|
|
4279
|
+
lines.push(" + added #".concat(n.id, " ").concat((0,_types__WEBPACK_IMPORTED_MODULE_0__.roleName)(n.role)) +
|
|
4280
|
+
(n.label ? " \"".concat(n.label, "\"") : "") +
|
|
4281
|
+
" bounds:(".concat(n.minX.toFixed(1), ",").concat(n.minY.toFixed(1), ")-(").concat(n.maxX.toFixed(1), ",").concat(n.maxY.toFixed(1), ")") +
|
|
4282
|
+
" states=[".concat((0,_types__WEBPACK_IMPORTED_MODULE_0__.stateNames)(n.stateFlags), "]") +
|
|
4283
|
+
" traits=[".concat((0,_types__WEBPACK_IMPORTED_MODULE_0__.traitNames)(n.traitFlags), "]"));
|
|
4284
|
+
}
|
|
4285
|
+
for (var _d = 0, _e = diff.moved; _d < _e.length; _d++) {
|
|
4286
|
+
var n = _e[_d];
|
|
4287
|
+
lines.push(" ~ moved #".concat(n.id, " \u2192 parent=").concat(n.parentId, " idx=").concat(n.siblingIndex) +
|
|
4288
|
+
" bounds:(".concat(n.minX.toFixed(1), ",").concat(n.minY.toFixed(1), ")-(").concat(n.maxX.toFixed(1), ",").concat(n.maxY.toFixed(1), ")"));
|
|
4289
|
+
}
|
|
4290
|
+
for (var _f = 0, _g = diff.childrenUpdated; _f < _g.length; _f++) {
|
|
4291
|
+
var u = _g[_f];
|
|
4292
|
+
lines.push(" \u2195 children of ".concat(u.parentId < 0 ? "root" : "#" + u.parentId, ": [").concat(u.childIds.join(", "), "]"));
|
|
4293
|
+
}
|
|
4294
|
+
for (var _h = 0, _j = diff.updatedSemantic; _h < _j.length; _h++) {
|
|
4295
|
+
var n = _j[_h];
|
|
4296
|
+
lines.push(" \u270E semantic #".concat(n.id, " ").concat((0,_types__WEBPACK_IMPORTED_MODULE_0__.roleName)(n.role)) +
|
|
4297
|
+
(n.label ? " \"".concat(n.label, "\"") : "") +
|
|
4298
|
+
" states=[".concat((0,_types__WEBPACK_IMPORTED_MODULE_0__.stateNames)(n.stateFlags), "]") +
|
|
4299
|
+
" traits=[".concat((0,_types__WEBPACK_IMPORTED_MODULE_0__.traitNames)(n.traitFlags), "]"));
|
|
4300
|
+
}
|
|
4301
|
+
for (var _k = 0, _l = diff.updatedGeometry; _k < _l.length; _k++) {
|
|
4302
|
+
var n = _l[_k];
|
|
4303
|
+
lines.push(" \u229E geometry #".concat(n.id, " (").concat(n.minX.toFixed(1), ",").concat(n.minY.toFixed(1), ")-(").concat(n.maxX.toFixed(1), ",").concat(n.maxY.toFixed(1), ")"));
|
|
4304
|
+
}
|
|
4305
|
+
console.log(lines.join("\n"));
|
|
4306
|
+
};
|
|
4307
|
+
/**
|
|
4308
|
+
* Returns every node in depth-first order, paired with its depth level.
|
|
4309
|
+
* Useful for debug logging / rendering a flat list.
|
|
4310
|
+
*/
|
|
4311
|
+
SemanticTreeModel.prototype.flattened = function () {
|
|
4312
|
+
var _this = this;
|
|
4313
|
+
var out = [];
|
|
4314
|
+
var walk = function (id, depth) {
|
|
4315
|
+
var node = _this._nodesById.get(id);
|
|
4316
|
+
if (!node)
|
|
4317
|
+
return;
|
|
4318
|
+
out.push({ depth: depth, node: node });
|
|
4319
|
+
for (var _i = 0, _a = node.children; _i < _a.length; _i++) {
|
|
4320
|
+
var child = _a[_i];
|
|
4321
|
+
walk(child, depth + 1);
|
|
4322
|
+
}
|
|
4323
|
+
};
|
|
4324
|
+
for (var _i = 0, _a = this._roots; _i < _a.length; _i++) {
|
|
4325
|
+
var root = _a[_i];
|
|
4326
|
+
walk(root, 0);
|
|
4327
|
+
}
|
|
4328
|
+
return out;
|
|
4329
|
+
};
|
|
4330
|
+
return SemanticTreeModel;
|
|
4331
|
+
}());
|
|
4332
|
+
|
|
4333
|
+
function clamp(v, min, max) {
|
|
4334
|
+
return v < min ? min : v > max ? max : v;
|
|
4335
|
+
}
|
|
4336
|
+
function arraysEqual(a, b) {
|
|
4337
|
+
if (a.length !== b.length)
|
|
4338
|
+
return false;
|
|
4339
|
+
for (var i = 0; i < a.length; i++) {
|
|
4340
|
+
if (a[i] !== b[i])
|
|
4341
|
+
return false;
|
|
4342
|
+
}
|
|
4343
|
+
return true;
|
|
4344
|
+
}
|
|
4345
|
+
function nodeFromDiff(n) {
|
|
4346
|
+
return {
|
|
4347
|
+
id: n.id,
|
|
4348
|
+
parentId: -1,
|
|
4349
|
+
role: n.role,
|
|
4350
|
+
label: n.label,
|
|
4351
|
+
value: n.value,
|
|
4352
|
+
hint: n.hint,
|
|
4353
|
+
stateFlags: n.stateFlags,
|
|
4354
|
+
traitFlags: n.traitFlags,
|
|
4355
|
+
headingLevel: n.headingLevel,
|
|
4356
|
+
minX: n.minX,
|
|
4357
|
+
minY: n.minY,
|
|
4358
|
+
maxX: n.maxX,
|
|
4359
|
+
maxY: n.maxY,
|
|
4360
|
+
children: [],
|
|
4361
|
+
};
|
|
4362
|
+
}
|
|
4363
|
+
/** Compare role/label/value/hint/stateFlags/traitFlags/headingLevel. */
|
|
4364
|
+
function semanticFieldsDiffer(a, b) {
|
|
4365
|
+
return (a.role !== b.role ||
|
|
4366
|
+
a.label !== b.label ||
|
|
4367
|
+
a.value !== b.value ||
|
|
4368
|
+
a.hint !== b.hint ||
|
|
4369
|
+
a.stateFlags !== b.stateFlags ||
|
|
4370
|
+
a.traitFlags !== b.traitFlags ||
|
|
4371
|
+
a.headingLevel !== b.headingLevel);
|
|
4372
|
+
}
|
|
4373
|
+
/** Compare only bounds (minX/minY/maxX/maxY). */
|
|
4374
|
+
function geometryFieldsDiffer(a, b) {
|
|
4375
|
+
return (a.minX !== b.minX ||
|
|
4376
|
+
a.minY !== b.minY ||
|
|
4377
|
+
a.maxX !== b.maxX ||
|
|
4378
|
+
a.maxY !== b.maxY);
|
|
4379
|
+
}
|
|
4380
|
+
function applySemantic(target, src) {
|
|
4381
|
+
target.role = src.role;
|
|
4382
|
+
target.label = src.label;
|
|
4383
|
+
target.value = src.value;
|
|
4384
|
+
target.hint = src.hint;
|
|
4385
|
+
target.stateFlags = src.stateFlags;
|
|
4386
|
+
target.traitFlags = src.traitFlags;
|
|
4387
|
+
target.headingLevel = src.headingLevel;
|
|
4388
|
+
}
|
|
4389
|
+
function applyGeometry(target, src) {
|
|
4390
|
+
target.minX = src.minX;
|
|
4391
|
+
target.minY = src.minY;
|
|
4392
|
+
target.maxX = src.maxX;
|
|
4393
|
+
target.maxY = src.maxY;
|
|
4394
|
+
}
|
|
4395
|
+
|
|
4396
|
+
|
|
4397
|
+
/***/ }),
|
|
4398
|
+
/* 8 */
|
|
4399
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
4400
|
+
|
|
4401
|
+
__webpack_require__.r(__webpack_exports__);
|
|
4402
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
4403
|
+
/* harmony export */ SemanticActionType: () => (/* binding */ SemanticActionType),
|
|
4404
|
+
/* harmony export */ SemanticMode: () => (/* binding */ SemanticMode),
|
|
4405
|
+
/* harmony export */ SemanticRole: () => (/* binding */ SemanticRole),
|
|
4406
|
+
/* harmony export */ SemanticState: () => (/* binding */ SemanticState),
|
|
4407
|
+
/* harmony export */ SemanticTrait: () => (/* binding */ SemanticTrait),
|
|
4408
|
+
/* harmony export */ hasState: () => (/* binding */ hasState),
|
|
4409
|
+
/* harmony export */ hasTrait: () => (/* binding */ hasTrait),
|
|
4410
|
+
/* harmony export */ roleName: () => (/* binding */ roleName),
|
|
4411
|
+
/* harmony export */ stateNames: () => (/* binding */ stateNames),
|
|
4412
|
+
/* harmony export */ traitNames: () => (/* binding */ traitNames)
|
|
4413
|
+
/* harmony export */ });
|
|
4414
|
+
// ---------------------------------------------------------------------------
|
|
4415
|
+
// SemanticRole — mirrors rive::SemanticRole
|
|
4416
|
+
// ---------------------------------------------------------------------------
|
|
4417
|
+
var SemanticRole = {
|
|
4418
|
+
none: 0,
|
|
4419
|
+
button: 1,
|
|
4420
|
+
link: 2,
|
|
4421
|
+
checkbox: 3,
|
|
4422
|
+
switchControl: 4,
|
|
4423
|
+
slider: 5,
|
|
4424
|
+
textField: 6,
|
|
4425
|
+
text: 7,
|
|
4426
|
+
image: 8,
|
|
4427
|
+
group: 9,
|
|
4428
|
+
list: 10,
|
|
4429
|
+
listItem: 11,
|
|
4430
|
+
tab: 12,
|
|
4431
|
+
tabList: 13,
|
|
4432
|
+
dialog: 14,
|
|
4433
|
+
alertDialog: 15,
|
|
4434
|
+
radioGroup: 16,
|
|
4435
|
+
radioButton: 17,
|
|
4436
|
+
};
|
|
4437
|
+
// ---------------------------------------------------------------------------
|
|
4438
|
+
// SemanticState — mirrors rive::SemanticState bitmask
|
|
4439
|
+
//
|
|
4440
|
+
// Bits 0-7 are trait-gated (only meaningful when the corresponding
|
|
4441
|
+
// SemanticTrait is set). Bits 8-13 are non-trait states.
|
|
4442
|
+
// ---------------------------------------------------------------------------
|
|
4443
|
+
var SemanticState = {
|
|
4444
|
+
None: 0,
|
|
4445
|
+
// Trait-gated
|
|
4446
|
+
Expanded: 1 << 0, // requires Expandable
|
|
4447
|
+
Selected: 1 << 1, // requires Selectable
|
|
4448
|
+
Checked: 1 << 2, // requires Checkable
|
|
4449
|
+
Mixed: 1 << 3, // requires Checkable; wins over Checked
|
|
4450
|
+
Toggled: 1 << 4, // requires Toggleable
|
|
4451
|
+
Required: 1 << 5, // requires Requirable
|
|
4452
|
+
Disabled: 1 << 6, // requires Enablable
|
|
4453
|
+
Focused: 1 << 7, // requires Focusable
|
|
4454
|
+
// Non-trait
|
|
4455
|
+
Hidden: 1 << 8,
|
|
4456
|
+
LiveRegion: 1 << 9,
|
|
4457
|
+
ReadOnly: 1 << 10,
|
|
4458
|
+
Modal: 1 << 11,
|
|
4459
|
+
Obscured: 1 << 12,
|
|
4460
|
+
Multiline: 1 << 13,
|
|
4461
|
+
};
|
|
4462
|
+
function hasState(flags, state) {
|
|
4463
|
+
return (flags & state) !== 0;
|
|
4464
|
+
}
|
|
4465
|
+
/**
|
|
4466
|
+
* Controls when the instance builds semantic trees and accessibility overlays.
|
|
4467
|
+
*
|
|
4468
|
+
* - `disabled`: no semantics work.
|
|
4469
|
+
* - `enabled`: semantics and overlay are active immediately after load.
|
|
4470
|
+
*/
|
|
4471
|
+
var SemanticMode = {
|
|
4472
|
+
Disabled: "disabled",
|
|
4473
|
+
Enabled: "enabled",
|
|
4474
|
+
};
|
|
4475
|
+
// ---------------------------------------------------------------------------
|
|
4476
|
+
// SemanticTrait — mirrors rive::SemanticTrait bitmask
|
|
4477
|
+
//
|
|
4478
|
+
// Traits declare what *capabilities* a node has. A state flag is only
|
|
4479
|
+
// meaningful when its corresponding trait is set.
|
|
4480
|
+
// ---------------------------------------------------------------------------
|
|
4481
|
+
var SemanticTrait = {
|
|
4482
|
+
None: 0,
|
|
4483
|
+
Expandable: 1 << 0,
|
|
4484
|
+
Selectable: 1 << 1,
|
|
4485
|
+
Checkable: 1 << 2,
|
|
4486
|
+
Toggleable: 1 << 3,
|
|
4487
|
+
Requirable: 1 << 4,
|
|
4488
|
+
Enablable: 1 << 5,
|
|
4489
|
+
Focusable: 1 << 6,
|
|
4490
|
+
};
|
|
4491
|
+
function hasTrait(flags, trait) {
|
|
4492
|
+
return (flags & trait) !== 0;
|
|
4493
|
+
}
|
|
4494
|
+
// ---------------------------------------------------------------------------
|
|
4495
|
+
// SemanticActionType — mirrors rive::SemanticActionType
|
|
4496
|
+
// ---------------------------------------------------------------------------
|
|
4497
|
+
var SemanticActionType = {
|
|
4498
|
+
tap: 0,
|
|
4499
|
+
increase: 1,
|
|
4500
|
+
decrease: 2,
|
|
4501
|
+
};
|
|
4502
|
+
// ---------------------------------------------------------------------------
|
|
4503
|
+
// Helpers — readable names for bitmask flags
|
|
4504
|
+
// ---------------------------------------------------------------------------
|
|
4505
|
+
var _roleNames = {};
|
|
4506
|
+
for (var _i = 0, _a = Object.entries(SemanticRole); _i < _a.length; _i++) {
|
|
4507
|
+
var _b = _a[_i], name_1 = _b[0], val = _b[1];
|
|
4508
|
+
_roleNames[val] = name_1;
|
|
4509
|
+
}
|
|
4510
|
+
var _stateEntries = Object.entries(SemanticState).filter(function (_a) {
|
|
4511
|
+
var v = _a[1];
|
|
4512
|
+
return v !== 0;
|
|
4513
|
+
});
|
|
4514
|
+
var _traitEntries = Object.entries(SemanticTrait).filter(function (_a) {
|
|
4515
|
+
var v = _a[1];
|
|
4516
|
+
return v !== 0;
|
|
4517
|
+
});
|
|
4518
|
+
function roleName(role) {
|
|
4519
|
+
var _a;
|
|
4520
|
+
return (_a = _roleNames[role]) !== null && _a !== void 0 ? _a : "unknown(".concat(role, ")");
|
|
4521
|
+
}
|
|
4522
|
+
function stateNames(flags) {
|
|
4523
|
+
if (flags === 0)
|
|
4524
|
+
return "none";
|
|
4525
|
+
var active = [];
|
|
4526
|
+
for (var _i = 0, _stateEntries_1 = _stateEntries; _i < _stateEntries_1.length; _i++) {
|
|
4527
|
+
var _a = _stateEntries_1[_i], name_2 = _a[0], bit = _a[1];
|
|
4528
|
+
if (flags & bit)
|
|
4529
|
+
active.push(name_2);
|
|
4530
|
+
}
|
|
4531
|
+
return active.join(", ") || "none";
|
|
4532
|
+
}
|
|
4533
|
+
function traitNames(flags) {
|
|
4534
|
+
if (flags === 0)
|
|
4535
|
+
return "none";
|
|
4536
|
+
var active = [];
|
|
4537
|
+
for (var _i = 0, _traitEntries_1 = _traitEntries; _i < _traitEntries_1.length; _i++) {
|
|
4538
|
+
var _a = _traitEntries_1[_i], name_3 = _a[0], bit = _a[1];
|
|
4539
|
+
if (flags & bit)
|
|
4540
|
+
active.push(name_3);
|
|
4541
|
+
}
|
|
4542
|
+
return active.join(", ") || "none";
|
|
4543
|
+
}
|
|
4544
|
+
|
|
4545
|
+
|
|
4546
|
+
/***/ }),
|
|
4547
|
+
/* 9 */
|
|
4548
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
4549
|
+
|
|
4550
|
+
__webpack_require__.r(__webpack_exports__);
|
|
4551
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
4552
|
+
/* harmony export */ AccessibilityOverlay: () => (/* binding */ AccessibilityOverlay)
|
|
4553
|
+
/* harmony export */ });
|
|
4554
|
+
/* harmony import */ var _types__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(8);
|
|
4555
|
+
|
|
4556
|
+
/**
|
|
4557
|
+
* Creates and manages an invisible DOM tree overlaying a Rive canvas. This is for
|
|
4558
|
+
* screen readers to discover and interact with the Rive content.
|
|
4559
|
+
*
|
|
4560
|
+
* Each semantic node in the {@link SemanticTreeModel} gets a corresponding
|
|
4561
|
+
* DOM element with appropriate ARIA role, states, and action handlers so
|
|
4562
|
+
* assistive technologies (i.e. screen readers) can discover
|
|
4563
|
+
* and interact with the Rive content.
|
|
4564
|
+
*
|
|
4565
|
+
* Each node receives a prefixed ID (`id=rive-{instanceId}-sem-{nodeId}`) to avoid host-page ID collisions.
|
|
4566
|
+
* The nodeID is Rive's semantic node ID from core runtime.
|
|
4567
|
+
* Each node is styled with `pointer-events: none`. Interactive nodes can receive
|
|
4568
|
+
* programmatic focus and keydown events without entering the browser Tab order.
|
|
4569
|
+
*/
|
|
4570
|
+
var AccessibilityOverlay = /** @class */ (function () {
|
|
4571
|
+
function AccessibilityOverlay(options) {
|
|
4572
|
+
var _this = this;
|
|
4573
|
+
var _a;
|
|
4574
|
+
this.elements = new Map();
|
|
4575
|
+
/** Visually-hidden description spans keyed by node ID, referenced by aria-describedby. */
|
|
4576
|
+
this.descElements = new Map();
|
|
4577
|
+
this.lastSemanticVersion = -1;
|
|
4578
|
+
this.lastGeometryVersion = -1;
|
|
4579
|
+
/** Text elements whose fit-scale needs recomputing, batched per update (see flushTextGeometry). */
|
|
4580
|
+
this.pendingTextGeometry = [];
|
|
4581
|
+
/** Last measured box-size|text key per text element, to skip redundant re-measures. */
|
|
4582
|
+
this.textGeometryKeys = new WeakMap();
|
|
4583
|
+
this.lastCanvasPositioning = {
|
|
4584
|
+
width: -1, height: -1, offsetTop: -1, offsetLeft: -1,
|
|
4585
|
+
};
|
|
4586
|
+
/**
|
|
4587
|
+
* Set when a ResizeObserver/window-resize signals the canvas geometry may have
|
|
4588
|
+
* changed, cleared once the transform is re-synced. Lets {@link needsUpdate}
|
|
4589
|
+
* report geometry changes without a per-frame `getBoundingClientRect()` reflow.
|
|
4590
|
+
* Starts true so the first update computes the transform.
|
|
4591
|
+
*/
|
|
4592
|
+
this._geometryDirty = true;
|
|
4593
|
+
/** True while reconciling the DOM (reserved for future focus-sync guards). */
|
|
4594
|
+
this.isUpdating = false;
|
|
4595
|
+
/**
|
|
4596
|
+
* Single child div of the overlay container that carries the artboard→CSS
|
|
4597
|
+
* transform. All semantic node elements are children of this div and express
|
|
4598
|
+
* their positions in raw artboard-space coordinates. The CSS transform on
|
|
4599
|
+
* this container maps artboard units to CSS pixels in one GPU pass — no
|
|
4600
|
+
* per-node matrix multiplication required.
|
|
4601
|
+
*/
|
|
4602
|
+
this.transformContainer = null;
|
|
4603
|
+
this._artboardBounds = { minX: 0, minY: 0, maxX: 0, maxY: 0 };
|
|
4604
|
+
this.repositionTimer = null;
|
|
4605
|
+
this.canvasResizeObserver = null;
|
|
4606
|
+
this.parentResizeObserver = null;
|
|
4607
|
+
/**
|
|
4608
|
+
* Detects canvas *position* drift. See {@link observePosition}.
|
|
4609
|
+
*/
|
|
4610
|
+
this.positionObserver = null;
|
|
4611
|
+
this._onWindowResize = function () { return _this.scheduleReposition(); };
|
|
4612
|
+
this.instanceId = options.instanceId;
|
|
4613
|
+
this.fireAction = options.fireAction;
|
|
4614
|
+
this.requestFocus = options.requestFocus;
|
|
4615
|
+
this.clearFocus = options.clearFocus;
|
|
4616
|
+
this.canvas = options.canvas;
|
|
4617
|
+
this.semanticsOptions = options.semanticsOptions;
|
|
4618
|
+
this.allowFocusInterrupt = (_a = options.allowFocusInterrupt) !== null && _a !== void 0 ? _a : false;
|
|
4619
|
+
this.container = this.createContainer(options.canvas);
|
|
4620
|
+
this.attachPositionObservers();
|
|
4621
|
+
}
|
|
4622
|
+
AccessibilityOverlay.prototype.getSemanticOverlayContainer = function () {
|
|
4623
|
+
return this.container;
|
|
4624
|
+
};
|
|
4625
|
+
// ---- Container lifecycle ----
|
|
4626
|
+
// Keep the a11y tree overlay matched to the canvas's position and size:
|
|
4627
|
+
// 1. The canvas resized — ResizeObserver
|
|
4628
|
+
// 2. The canvas's parent resized — ResizeObserver
|
|
4629
|
+
// 3. The window resized — resize event
|
|
4630
|
+
// 4. The canvas moved/drifted — IntersectionObserver (see observePosition)
|
|
4631
|
+
AccessibilityOverlay.prototype.attachPositionObservers = function () {
|
|
4632
|
+
var _this = this;
|
|
4633
|
+
this.canvasResizeObserver = new ResizeObserver(function () { return _this.scheduleReposition(); });
|
|
4634
|
+
this.canvasResizeObserver.observe(this.canvas);
|
|
4635
|
+
var parent = this.canvas.parentElement;
|
|
4636
|
+
if (parent) {
|
|
4637
|
+
this.parentResizeObserver = new ResizeObserver(function () { return _this.scheduleReposition(); });
|
|
4638
|
+
this.parentResizeObserver.observe(parent);
|
|
4639
|
+
}
|
|
4640
|
+
window.addEventListener("resize", this._onWindowResize);
|
|
4641
|
+
this.observePosition();
|
|
4642
|
+
};
|
|
4643
|
+
/**
|
|
4644
|
+
* Arms an IntersectionObserver whose root box is bounded to the canvas, so it
|
|
4645
|
+
* fires when the canvas moves relative to the viewport — position drift that
|
|
4646
|
+
* no ResizeObserver reports. Lets us re-sync the overlay container on a move
|
|
4647
|
+
* instead of recalculating the canvas bounding box every frame.
|
|
4648
|
+
*/
|
|
4649
|
+
AccessibilityOverlay.prototype.observePosition = function () {
|
|
4650
|
+
var _this = this;
|
|
4651
|
+
var _a;
|
|
4652
|
+
if (typeof IntersectionObserver === "undefined")
|
|
4653
|
+
return;
|
|
4654
|
+
(_a = this.positionObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
4655
|
+
this.positionObserver = null;
|
|
4656
|
+
var rect = this.canvas.getBoundingClientRect();
|
|
4657
|
+
// Can't frame a zero-area element; it will re-arm on the next reposition.
|
|
4658
|
+
if (!rect.width || !rect.height)
|
|
4659
|
+
return;
|
|
4660
|
+
// Shrink the viewport root box down to exactly the canvas: a negative inset
|
|
4661
|
+
// from each viewport edge to the matching canvas edge, in CSS shorthand
|
|
4662
|
+
// order (top, right, bottom, left). Rounded so sub-pixel jitter doesn't trip
|
|
4663
|
+
// the 1.0 threshold.
|
|
4664
|
+
var insetToPx = function (v) { return "".concat(-Math.round(v), "px"); };
|
|
4665
|
+
var rootMargin = [
|
|
4666
|
+
rect.top, // top: viewport top → canvas top
|
|
4667
|
+
window.innerWidth - rect.right, // right: viewport right → canvas right
|
|
4668
|
+
window.innerHeight - rect.bottom, // bottom: viewport bottom → canvas bottom
|
|
4669
|
+
rect.left, // left: viewport left → canvas left
|
|
4670
|
+
]
|
|
4671
|
+
.map(insetToPx)
|
|
4672
|
+
.join(" ");
|
|
4673
|
+
// The observer emits an initial notification for the current (contained)
|
|
4674
|
+
// state; ignore that and only react to a subsequent move.
|
|
4675
|
+
var armed = false;
|
|
4676
|
+
this.positionObserver = new IntersectionObserver(function () {
|
|
4677
|
+
if (!armed) {
|
|
4678
|
+
armed = true;
|
|
4679
|
+
return;
|
|
4680
|
+
}
|
|
4681
|
+
_this.scheduleReposition();
|
|
4682
|
+
}, { threshold: 1.0, rootMargin: rootMargin });
|
|
4683
|
+
this.positionObserver.observe(this.canvas);
|
|
4684
|
+
};
|
|
4685
|
+
AccessibilityOverlay.prototype.scheduleReposition = function () {
|
|
4686
|
+
var _this = this;
|
|
4687
|
+
// A resize/move may have changed canvas size/scale/position; force a
|
|
4688
|
+
// transform recompute on the next frame's update.
|
|
4689
|
+
this._geometryDirty = true;
|
|
4690
|
+
if (this.repositionTimer !== null)
|
|
4691
|
+
return;
|
|
4692
|
+
this.repositionTimer = setTimeout(function () {
|
|
4693
|
+
_this.repositionTimer = null;
|
|
4694
|
+
_this.syncContainerGeometry();
|
|
4695
|
+
// Re-arm the position observer at the canvas's new location.
|
|
4696
|
+
_this.observePosition();
|
|
4697
|
+
}, 500); // Throttle to avoid rapid style recalculations
|
|
4698
|
+
};
|
|
4699
|
+
AccessibilityOverlay.prototype.syncContainerGeometry = function () {
|
|
4700
|
+
var rect = this.canvas.getBoundingClientRect();
|
|
4701
|
+
var top = this.canvas.offsetTop;
|
|
4702
|
+
var left = this.canvas.offsetLeft;
|
|
4703
|
+
if (rect.width === this.lastCanvasPositioning.width &&
|
|
4704
|
+
rect.height === this.lastCanvasPositioning.height &&
|
|
4705
|
+
top === this.lastCanvasPositioning.offsetTop &&
|
|
4706
|
+
left === this.lastCanvasPositioning.offsetLeft)
|
|
4707
|
+
return;
|
|
4708
|
+
this.container.style.top = top + "px";
|
|
4709
|
+
this.container.style.left = left + "px";
|
|
4710
|
+
this.container.style.width = rect.width + "px";
|
|
4711
|
+
this.container.style.height = rect.height + "px";
|
|
4712
|
+
this.container.tabIndex = -1;
|
|
4713
|
+
this.lastCanvasPositioning.width = rect.width;
|
|
4714
|
+
this.lastCanvasPositioning.height = rect.height;
|
|
4715
|
+
this.lastCanvasPositioning.offsetTop = top;
|
|
4716
|
+
this.lastCanvasPositioning.offsetLeft = left;
|
|
4717
|
+
};
|
|
4718
|
+
AccessibilityOverlay.prototype.createContainer = function (canvas) {
|
|
4719
|
+
var _a, _b;
|
|
4720
|
+
var container = document.createElement("div");
|
|
4721
|
+
container.id = "rive-a11y-".concat(this.instanceId);
|
|
4722
|
+
container.setAttribute("role", "region");
|
|
4723
|
+
container.setAttribute("aria-label", (_b = (_a = this.semanticsOptions) === null || _a === void 0 ? void 0 : _a.riveCanvasLabel) !== null && _b !== void 0 ? _b : "Rive animation");
|
|
4724
|
+
// Size to the canvas's CSS layout box, not the parent container.
|
|
4725
|
+
var rect = canvas.getBoundingClientRect();
|
|
4726
|
+
container.style.cssText = [
|
|
4727
|
+
"position:absolute",
|
|
4728
|
+
"top:".concat(canvas.offsetTop, "px"),
|
|
4729
|
+
"left:".concat(canvas.offsetLeft, "px"),
|
|
4730
|
+
"width:".concat(rect.width, "px"),
|
|
4731
|
+
"height:".concat(rect.height, "px"),
|
|
4732
|
+
"overflow:hidden",
|
|
4733
|
+
"pointer-events:none",
|
|
4734
|
+
// Visually hidden but still in the accessibility tree.
|
|
4735
|
+
// `display:none` and `visibility:hidden` would hide from AT.
|
|
4736
|
+
"opacity:0",
|
|
4737
|
+
].join(";");
|
|
4738
|
+
canvas.insertAdjacentElement("afterend", container);
|
|
4739
|
+
return container;
|
|
4740
|
+
};
|
|
4741
|
+
/**
|
|
4742
|
+
* Returns what changed since the last update, or null if nothing changed.
|
|
4743
|
+
*
|
|
4744
|
+
* Callers use this to avoid recomputing the (relatively expensive)
|
|
4745
|
+
* artboard→canvas transform on frames where only node bounds changed in the
|
|
4746
|
+
* tree: the transform only needs recomputing when `layoutChanged` is true.
|
|
4747
|
+
*/
|
|
4748
|
+
AccessibilityOverlay.prototype.needsUpdate = function (tree) {
|
|
4749
|
+
var semanticChanged = tree.semanticVersion !== this.lastSemanticVersion;
|
|
4750
|
+
var nodeGeometryChanged = tree.geometryVersion !== this.lastGeometryVersion;
|
|
4751
|
+
var layoutChanged = this._geometryDirty || !this.transformContainer;
|
|
4752
|
+
if (!semanticChanged && !nodeGeometryChanged && !layoutChanged)
|
|
4753
|
+
return null;
|
|
4754
|
+
return { semanticChanged: semanticChanged, nodeGeometryChanged: nodeGeometryChanged, layoutChanged: layoutChanged };
|
|
4755
|
+
};
|
|
4756
|
+
/**
|
|
4757
|
+
* Update the overlay DOM to reflect the current state of the semantic tree.
|
|
4758
|
+
* Call once per frame after `applyDiff` when {@link needsUpdate} reports a
|
|
4759
|
+
* change, when layout/transform inputs are dirty, or when a fresh
|
|
4760
|
+
* `forwardMat` is supplied (even if the tree versions are unchanged).
|
|
4761
|
+
*
|
|
4762
|
+
* @param tree The in-memory semantic tree model
|
|
4763
|
+
* @param forwardMat Artboard→canvas-pixel transform from `computeAlignment`,
|
|
4764
|
+
* or null to reuse the existing CSS transform on the
|
|
4765
|
+
* transform container
|
|
4766
|
+
* @param dpr Device pixel ratio used for the canvas backing store
|
|
4767
|
+
* @param artboardBounds The artboard's own bounding rectangle
|
|
4768
|
+
*/
|
|
4769
|
+
AccessibilityOverlay.prototype.update = function (tree, forwardMat, dpr, artboardBounds, change) {
|
|
4770
|
+
var overlayChange = change !== null && change !== void 0 ? change : this.needsUpdate(tree);
|
|
4771
|
+
if (!overlayChange && forwardMat) {
|
|
4772
|
+
overlayChange = {
|
|
4773
|
+
semanticChanged: false,
|
|
4774
|
+
nodeGeometryChanged: false,
|
|
4775
|
+
layoutChanged: true,
|
|
4776
|
+
};
|
|
4777
|
+
}
|
|
4778
|
+
if (!overlayChange)
|
|
4779
|
+
return;
|
|
4780
|
+
this.performUpdate(tree, forwardMat, dpr, artboardBounds, overlayChange);
|
|
4781
|
+
};
|
|
4782
|
+
AccessibilityOverlay.prototype.performUpdate = function (tree, forwardMat, dpr, artboardBounds, change) {
|
|
4783
|
+
var _a;
|
|
4784
|
+
var semanticChanged = change.semanticChanged, nodeGeometryChanged = change.nodeGeometryChanged;
|
|
4785
|
+
// Per-node change sets only describe the most recent applyDiff. If more
|
|
4786
|
+
// than one semantic version elapsed since our last update (first build,
|
|
4787
|
+
// or a diff we never consumed), fall back to re-applying attributes on
|
|
4788
|
+
// every node rather than trusting an incomplete set.
|
|
4789
|
+
var reapplyAllAttributes = tree.semanticVersion - this.lastSemanticVersion > 1;
|
|
4790
|
+
this.lastSemanticVersion = tree.semanticVersion;
|
|
4791
|
+
this.lastGeometryVersion = tree.geometryVersion;
|
|
4792
|
+
this.isUpdating = true;
|
|
4793
|
+
this._artboardBounds = artboardBounds;
|
|
4794
|
+
// Container box + artboard transform only run when a fresh forwardMat was
|
|
4795
|
+
// supplied (layout/transform dirty). Node-only bounds updates reuse the
|
|
4796
|
+
// existing CSS transform and go through updateGeometryForChangedNodes.
|
|
4797
|
+
// Skipping syncContainerGeometry here on semantic-only frames avoids a
|
|
4798
|
+
// getBoundingClientRect() reflow on every animation frame. The throttled
|
|
4799
|
+
// scheduleReposition() path still keeps the container aligned when the page
|
|
4800
|
+
// layout shifts.
|
|
4801
|
+
if (forwardMat) {
|
|
4802
|
+
this.syncContainerGeometry();
|
|
4803
|
+
this.syncTransformContainer(forwardMat, dpr, artboardBounds);
|
|
4804
|
+
// Transform is now in sync with the latest layout.
|
|
4805
|
+
this._geometryDirty = false;
|
|
4806
|
+
}
|
|
4807
|
+
if (semanticChanged) {
|
|
4808
|
+
var rootEl = (_a = this.transformContainer) !== null && _a !== void 0 ? _a : this.container;
|
|
4809
|
+
var activeIds_1 = new Set();
|
|
4810
|
+
this.rebuildChildren(rootEl, tree.roots, tree, 0, // parentLeft in artboard space (transform container origin)
|
|
4811
|
+
0, // parentTop in artboard space
|
|
4812
|
+
activeIds_1, reapplyAllAttributes);
|
|
4813
|
+
var staleIds_2 = [];
|
|
4814
|
+
this.elements.forEach(function (_el, id) {
|
|
4815
|
+
if (!activeIds_1.has(id))
|
|
4816
|
+
staleIds_2.push(id);
|
|
4817
|
+
});
|
|
4818
|
+
for (var _i = 0, staleIds_1 = staleIds_2; _i < staleIds_1.length; _i++) {
|
|
4819
|
+
var id = staleIds_1[_i];
|
|
4820
|
+
var el = this.elements.get(id);
|
|
4821
|
+
if (el && el.parentNode)
|
|
4822
|
+
el.parentNode.removeChild(el);
|
|
4823
|
+
this.elements.delete(id);
|
|
4824
|
+
var desc = this.descElements.get(id);
|
|
4825
|
+
if (desc && desc.parentNode)
|
|
4826
|
+
desc.parentNode.removeChild(desc);
|
|
4827
|
+
this.descElements.delete(id);
|
|
4828
|
+
}
|
|
4829
|
+
}
|
|
4830
|
+
else if (nodeGeometryChanged) {
|
|
4831
|
+
this.updateGeometryForChangedNodes(tree);
|
|
4832
|
+
}
|
|
4833
|
+
// Text scaling needs layout reads; batch them into one pass after all
|
|
4834
|
+
// position/attribute writes so each frame forces at most one reflow.
|
|
4835
|
+
this.flushTextGeometry();
|
|
4836
|
+
this.isUpdating = false;
|
|
4837
|
+
};
|
|
4838
|
+
/** Remove the overlay from the DOM entirely. */
|
|
4839
|
+
AccessibilityOverlay.prototype.destroy = function () {
|
|
4840
|
+
var _a, _b, _c;
|
|
4841
|
+
if (this.repositionTimer !== null) {
|
|
4842
|
+
clearTimeout(this.repositionTimer);
|
|
4843
|
+
this.repositionTimer = null;
|
|
4844
|
+
}
|
|
4845
|
+
window.removeEventListener("resize", this._onWindowResize);
|
|
4846
|
+
(_a = this.canvasResizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
4847
|
+
(_b = this.parentResizeObserver) === null || _b === void 0 ? void 0 : _b.disconnect();
|
|
4848
|
+
(_c = this.positionObserver) === null || _c === void 0 ? void 0 : _c.disconnect();
|
|
4849
|
+
if (this.container.parentNode) {
|
|
4850
|
+
this.container.parentNode.removeChild(this.container);
|
|
4851
|
+
}
|
|
4852
|
+
this.elements.clear();
|
|
4853
|
+
this.descElements.clear();
|
|
4854
|
+
this.pendingTextGeometry.length = 0;
|
|
4855
|
+
};
|
|
4856
|
+
// ---- Tree → DOM reconciliation ----
|
|
4857
|
+
/**
|
|
4858
|
+
* Reconcile a parent DOM element's children with an ordered list of
|
|
4859
|
+
* semantic node IDs. Creates, updates, and reorders elements as needed.
|
|
4860
|
+
*
|
|
4861
|
+
* Node positions are expressed in artboard-space coordinates. The CSS
|
|
4862
|
+
* transform on the transform container maps artboard units to CSS pixels,
|
|
4863
|
+
* so no per-node matrix multiplication is required here.
|
|
4864
|
+
*
|
|
4865
|
+
* @param parentArtboardLeft Absolute artboard minX of the parent node (0 for roots)
|
|
4866
|
+
* @param parentArtboardTop Absolute artboard minY of the parent node (0 for roots)
|
|
4867
|
+
*/
|
|
4868
|
+
AccessibilityOverlay.prototype.rebuildChildren = function (parentEl, childIds, tree, parentArtboardLeft, parentArtboardTop, activeIds, applyAllAttributes) {
|
|
4869
|
+
for (var i = 0; i < childIds.length; i++) {
|
|
4870
|
+
var nodeId = childIds[i];
|
|
4871
|
+
var nodeData = tree.nodeById(nodeId);
|
|
4872
|
+
if (!nodeData)
|
|
4873
|
+
continue;
|
|
4874
|
+
activeIds.add(nodeId);
|
|
4875
|
+
var el = this.elements.get(nodeId);
|
|
4876
|
+
var isNew = !el;
|
|
4877
|
+
if (!el) {
|
|
4878
|
+
el = this.createElement(nodeData);
|
|
4879
|
+
this.elements.set(nodeId, el);
|
|
4880
|
+
}
|
|
4881
|
+
// Attributes are only applied to new elements and nodes whose semantic
|
|
4882
|
+
// fields changed in the latest diff. Skipping redundant setAttribute
|
|
4883
|
+
// calls eliminates WebKit AX notifications that knock VoiceOver off its
|
|
4884
|
+
// current element.
|
|
4885
|
+
if (isNew || applyAllAttributes || tree.semanticChangedIds.has(nodeId)) {
|
|
4886
|
+
this.applyAttributes(el, nodeData);
|
|
4887
|
+
}
|
|
4888
|
+
this.applyPosition(el, nodeData, parentArtboardLeft, parentArtboardTop);
|
|
4889
|
+
// Only touch the DOM tree if the element isn't already in the correct
|
|
4890
|
+
// position. Moving a focused element can blur it and knock AT off the
|
|
4891
|
+
// current node.
|
|
4892
|
+
var currentChild = parentEl.children[i];
|
|
4893
|
+
if (currentChild !== el) {
|
|
4894
|
+
if (currentChild) {
|
|
4895
|
+
parentEl.insertBefore(el, currentChild);
|
|
4896
|
+
}
|
|
4897
|
+
else {
|
|
4898
|
+
parentEl.appendChild(el);
|
|
4899
|
+
}
|
|
4900
|
+
}
|
|
4901
|
+
// Reflect the runtime Focused state into DOM focus. Runs after insertion
|
|
4902
|
+
// so the element is attached, and skips elements that already hold focus.
|
|
4903
|
+
// The cheap trait/state flag checks gate the (per-node) DOM queries below,
|
|
4904
|
+
// so the activeElement/closest/contains walks only run for a node that is
|
|
4905
|
+
// actually focusable + focused — not for every node on every frame.
|
|
4906
|
+
if ((0,_types__WEBPACK_IMPORTED_MODULE_0__.hasTrait)(nodeData.traitFlags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticTrait.Focusable) &&
|
|
4907
|
+
(0,_types__WEBPACK_IMPORTED_MODULE_0__.hasState)(nodeData.stateFlags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticState.Focused)) {
|
|
4908
|
+
var active = document.activeElement;
|
|
4909
|
+
// While focus is inside one of our modal dialogs, don't pull it back
|
|
4910
|
+
// out to a background node.
|
|
4911
|
+
var focusedModal = active === null || active === void 0 ? void 0 : active.closest('[aria-modal="true"]');
|
|
4912
|
+
var trappedByModal = !!focusedModal &&
|
|
4913
|
+
this.container.contains(focusedModal) &&
|
|
4914
|
+
!focusedModal.contains(el);
|
|
4915
|
+
if (active !== el && !trappedByModal && this.canMoveFocus()) {
|
|
4916
|
+
el.focus();
|
|
4917
|
+
}
|
|
4918
|
+
}
|
|
4919
|
+
// Recurse into children with this node's absolute artboard position.
|
|
4920
|
+
if (nodeData.children.length > 0) {
|
|
4921
|
+
this.rebuildChildren(el, nodeData.children, tree, nodeData.minX, nodeData.minY, activeIds, applyAllAttributes);
|
|
4922
|
+
}
|
|
4923
|
+
// Focus a modal/alert dialog when it first appears (after children are
|
|
4924
|
+
// built so the focus target can be resolved from the subtree).
|
|
4925
|
+
if (isNew)
|
|
4926
|
+
this.autoFocusDialogOnAppear(el, nodeData, tree);
|
|
4927
|
+
}
|
|
4928
|
+
};
|
|
4929
|
+
/**
|
|
4930
|
+
* Reposition only the subtrees whose bounds changed in the latest diff.
|
|
4931
|
+
* Descendants are included because node CSS positions are parent-relative.
|
|
4932
|
+
*/
|
|
4933
|
+
AccessibilityOverlay.prototype.updateGeometryForChangedNodes = function (tree) {
|
|
4934
|
+
var _a, _b;
|
|
4935
|
+
for (var _i = 0, _c = Array.from(tree.geometryChangedIds); _i < _c.length; _i++) {
|
|
4936
|
+
var nodeId = _c[_i];
|
|
4937
|
+
var nodeData = tree.nodeById(nodeId);
|
|
4938
|
+
if (!nodeData)
|
|
4939
|
+
continue;
|
|
4940
|
+
var parentLeft = 0;
|
|
4941
|
+
var parentTop = 0;
|
|
4942
|
+
var parentEl = (_a = this.transformContainer) !== null && _a !== void 0 ? _a : this.container;
|
|
4943
|
+
if (nodeData.parentId >= 0) {
|
|
4944
|
+
var parent_1 = tree.nodeById(nodeData.parentId);
|
|
4945
|
+
if (parent_1) {
|
|
4946
|
+
parentLeft = parent_1.minX;
|
|
4947
|
+
parentTop = parent_1.minY;
|
|
4948
|
+
parentEl = (_b = this.elements.get(nodeData.parentId)) !== null && _b !== void 0 ? _b : parentEl;
|
|
4949
|
+
}
|
|
4950
|
+
}
|
|
4951
|
+
this.updateNodeGeometrySubtree(tree, nodeId, parentLeft, parentTop, parentEl);
|
|
4952
|
+
}
|
|
4953
|
+
};
|
|
4954
|
+
AccessibilityOverlay.prototype.updateNodeGeometrySubtree = function (tree, nodeId, parentArtboardLeft, parentArtboardTop, _parentEl) {
|
|
4955
|
+
var nodeData = tree.nodeById(nodeId);
|
|
4956
|
+
if (!nodeData)
|
|
4957
|
+
return;
|
|
4958
|
+
var el = this.elements.get(nodeId);
|
|
4959
|
+
if (!el)
|
|
4960
|
+
return;
|
|
4961
|
+
this.applyPosition(el, nodeData, parentArtboardLeft, parentArtboardTop);
|
|
4962
|
+
for (var _i = 0, _a = nodeData.children; _i < _a.length; _i++) {
|
|
4963
|
+
var childId = _a[_i];
|
|
4964
|
+
this.updateNodeGeometrySubtree(tree, childId, nodeData.minX, nodeData.minY, el);
|
|
4965
|
+
}
|
|
4966
|
+
};
|
|
4967
|
+
/**
|
|
4968
|
+
* Whether the overlay may move focus now. Following focus already inside this
|
|
4969
|
+
* instance is always allowed; pulling it in from the host page is gated behind
|
|
4970
|
+
* allowFocusInterrupt (from the Rive class).
|
|
4971
|
+
*/
|
|
4972
|
+
AccessibilityOverlay.prototype.canMoveFocus = function () {
|
|
4973
|
+
var active = document.activeElement;
|
|
4974
|
+
var focusAlreadyInScope = active === this.canvas || this.container.contains(active);
|
|
4975
|
+
return focusAlreadyInScope || this.allowFocusInterrupt;
|
|
4976
|
+
};
|
|
4977
|
+
/**
|
|
4978
|
+
* Move focus into a newly appeared modal/alert dialog so screen readers
|
|
4979
|
+
* announce and read its content (web ATs don't auto-enter a freshly mounted
|
|
4980
|
+
* dialog). Skips when focus can't move (see canMoveFocus) or a descendant
|
|
4981
|
+
* already holds it. The dialog's aria-modal keeps focus trapped inside.
|
|
4982
|
+
*/
|
|
4983
|
+
AccessibilityOverlay.prototype.autoFocusDialogOnAppear = function (el, node, tree) {
|
|
4984
|
+
var _a;
|
|
4985
|
+
if (!isModalDialogRole(node.role, node.stateFlags))
|
|
4986
|
+
return;
|
|
4987
|
+
if (!this.canMoveFocus())
|
|
4988
|
+
return;
|
|
4989
|
+
// A descendant already holds focus — don't override it.
|
|
4990
|
+
var active = document.activeElement;
|
|
4991
|
+
if (active && active !== el && el.contains(active))
|
|
4992
|
+
return;
|
|
4993
|
+
var target = (_a = this.routeDefaultFocusTarget(node, tree)) !== null && _a !== void 0 ? _a : el;
|
|
4994
|
+
if (!target.hasAttribute("tabindex"))
|
|
4995
|
+
target.setAttribute("tabindex", "-1");
|
|
4996
|
+
if (document.activeElement !== target)
|
|
4997
|
+
target.focus({ preventScroll: true });
|
|
4998
|
+
};
|
|
4999
|
+
/**
|
|
5000
|
+
* Resolve the element assistive technologies (AT) should focus on appearance. Walks the subtree
|
|
5001
|
+
* depth-first and returns the first focusable node's host element, else the
|
|
5002
|
+
* inner <span> of the first labeled leaf. Container and unlabeled nodes are
|
|
5003
|
+
* descended into but never focused. Returns null if nothing qualifies.
|
|
5004
|
+
*/
|
|
5005
|
+
AccessibilityOverlay.prototype.routeDefaultFocusTarget = function (node, tree) {
|
|
5006
|
+
var _a;
|
|
5007
|
+
for (var _i = 0, _b = node.children; _i < _b.length; _i++) {
|
|
5008
|
+
var childId = _b[_i];
|
|
5009
|
+
var child = tree.nodeById(childId);
|
|
5010
|
+
if (!child)
|
|
5011
|
+
continue;
|
|
5012
|
+
var childEl = this.elements.get(childId);
|
|
5013
|
+
// Focusable node → its host element (even if it has children).
|
|
5014
|
+
if (childEl && isFocusableNode(child))
|
|
5015
|
+
return childEl;
|
|
5016
|
+
// Container or unlabeled node → descend without focusing it.
|
|
5017
|
+
if (child.children.length > 0 || !child.label) {
|
|
5018
|
+
var nested = this.routeDefaultFocusTarget(child, tree);
|
|
5019
|
+
if (nested)
|
|
5020
|
+
return nested;
|
|
5021
|
+
continue;
|
|
5022
|
+
}
|
|
5023
|
+
// Labeled leaf → its inner label span.
|
|
5024
|
+
if (childEl) {
|
|
5025
|
+
return (_a = childEl.querySelector(":scope > span")) !== null && _a !== void 0 ? _a : childEl;
|
|
5026
|
+
}
|
|
5027
|
+
}
|
|
5028
|
+
return null;
|
|
5029
|
+
};
|
|
5030
|
+
Object.defineProperty(AccessibilityOverlay.prototype, "nodeIdPrefix", {
|
|
5031
|
+
// ---- Element creation ----
|
|
5032
|
+
/** Shared `id` prefix for all semantic node elements of this instance. */
|
|
5033
|
+
get: function () {
|
|
5034
|
+
return "rive-".concat(this.instanceId, "-sem-");
|
|
5035
|
+
},
|
|
5036
|
+
enumerable: false,
|
|
5037
|
+
configurable: true
|
|
5038
|
+
});
|
|
5039
|
+
/** Recover the semantic node ID from an overlay element, or null. */
|
|
5040
|
+
AccessibilityOverlay.prototype.nodeIdFromElement = function (el) {
|
|
5041
|
+
if (!el.id.startsWith(this.nodeIdPrefix))
|
|
5042
|
+
return null;
|
|
5043
|
+
var raw = el.id.slice(this.nodeIdPrefix.length);
|
|
5044
|
+
// Guard the empty string explicitly: Number("") is 0, not NaN.
|
|
5045
|
+
if (!raw)
|
|
5046
|
+
return null;
|
|
5047
|
+
var id = Number(raw);
|
|
5048
|
+
return Number.isNaN(id) ? null : id;
|
|
5049
|
+
};
|
|
5050
|
+
AccessibilityOverlay.prototype.createElement = function (node) {
|
|
5051
|
+
var tag = tagForRole(node.role);
|
|
5052
|
+
var el = document.createElement(tag);
|
|
5053
|
+
el.id = "".concat(this.nodeIdPrefix).concat(node.id);
|
|
5054
|
+
el.style.cssText = BASE_NODE_STYLE;
|
|
5055
|
+
if (node.role === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.text) {
|
|
5056
|
+
// The positioned outer div is the AX element
|
|
5057
|
+
// VoiceOver uses for its highlight box; an inner <span> carries the text
|
|
5058
|
+
// without position:absolute (which would strip the span from VoiceOver's
|
|
5059
|
+
// bounds calculation).
|
|
5060
|
+
var textSpan = document.createElement("span");
|
|
5061
|
+
textSpan.style.cssText = SPAN_EXP;
|
|
5062
|
+
el.appendChild(textSpan);
|
|
5063
|
+
}
|
|
5064
|
+
this.attachActionHandlers(el, node);
|
|
5065
|
+
return el;
|
|
5066
|
+
};
|
|
5067
|
+
// ---- Action handlers ----
|
|
5068
|
+
/**
|
|
5069
|
+
* Wire arrow-key roving focus for a group member (tab, radio). Arrow keys
|
|
5070
|
+
* move focus to the next/previous member (wrapping), optionally Home/End jump
|
|
5071
|
+
* to first/last, and the newly focused member receives a tap action.
|
|
5072
|
+
*/
|
|
5073
|
+
AccessibilityOverlay.prototype.attachRovingNav = function (el, opts) {
|
|
5074
|
+
var _this = this;
|
|
5075
|
+
el.addEventListener("keydown", function (e) {
|
|
5076
|
+
var target = null;
|
|
5077
|
+
if (e.key === "ArrowRight" || e.key === "ArrowDown")
|
|
5078
|
+
target = "next";
|
|
5079
|
+
else if (e.key === "ArrowLeft" || e.key === "ArrowUp")
|
|
5080
|
+
target = "prev";
|
|
5081
|
+
else if (opts.includeHomeEnd && e.key === "Home")
|
|
5082
|
+
target = "first";
|
|
5083
|
+
else if (opts.includeHomeEnd && e.key === "End")
|
|
5084
|
+
target = "last";
|
|
5085
|
+
if (!target)
|
|
5086
|
+
return;
|
|
5087
|
+
e.preventDefault();
|
|
5088
|
+
var members = opts.members();
|
|
5089
|
+
var idx = members.indexOf(el);
|
|
5090
|
+
if (idx < 0)
|
|
5091
|
+
return;
|
|
5092
|
+
var n = members.length;
|
|
5093
|
+
var next = target === "next" ? members[(idx + 1) % n]
|
|
5094
|
+
: target === "prev" ? members[(idx - 1 + n) % n]
|
|
5095
|
+
: target === "first" ? members[0]
|
|
5096
|
+
: members[n - 1];
|
|
5097
|
+
if (next && next !== el) {
|
|
5098
|
+
next.focus();
|
|
5099
|
+
var nextId = _this.nodeIdFromElement(next);
|
|
5100
|
+
if (nextId !== null)
|
|
5101
|
+
_this.fireAction(nextId, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticActionType.tap);
|
|
5102
|
+
}
|
|
5103
|
+
});
|
|
5104
|
+
};
|
|
5105
|
+
AccessibilityOverlay.prototype.attachActionHandlers = function (el, node) {
|
|
5106
|
+
var _this = this;
|
|
5107
|
+
var role = node.role;
|
|
5108
|
+
var nodeId = node.id;
|
|
5109
|
+
if (isClickableRole(role)) {
|
|
5110
|
+
el.addEventListener("click", function () {
|
|
5111
|
+
_this.fireAction(nodeId, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticActionType.tap);
|
|
5112
|
+
});
|
|
5113
|
+
// Links activate on Enter only (Space scrolls the page per browser
|
|
5114
|
+
// convention). All other clickable roles accept both Enter and Space.
|
|
5115
|
+
var activationKeys_1 = role === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.link ? ["Enter"] : ["Enter", " "];
|
|
5116
|
+
el.addEventListener("keydown", function (e) {
|
|
5117
|
+
if (activationKeys_1.includes(e.key)) {
|
|
5118
|
+
e.preventDefault();
|
|
5119
|
+
_this.fireAction(nodeId, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticActionType.tap);
|
|
5120
|
+
}
|
|
5121
|
+
});
|
|
5122
|
+
}
|
|
5123
|
+
if (role === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.slider) {
|
|
5124
|
+
el.addEventListener("keydown", function (e) {
|
|
5125
|
+
if (e.key === "ArrowRight" || e.key === "ArrowUp") {
|
|
5126
|
+
e.preventDefault();
|
|
5127
|
+
_this.fireAction(nodeId, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticActionType.increase);
|
|
5128
|
+
}
|
|
5129
|
+
else if (e.key === "ArrowLeft" || e.key === "ArrowDown") {
|
|
5130
|
+
e.preventDefault();
|
|
5131
|
+
_this.fireAction(nodeId, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticActionType.decrease);
|
|
5132
|
+
}
|
|
5133
|
+
});
|
|
5134
|
+
}
|
|
5135
|
+
if (role === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.tab) {
|
|
5136
|
+
this.attachRovingNav(el, {
|
|
5137
|
+
includeHomeEnd: true,
|
|
5138
|
+
members: function () {
|
|
5139
|
+
var parent = el.parentElement;
|
|
5140
|
+
if (!parent)
|
|
5141
|
+
return [];
|
|
5142
|
+
return Array.from(parent.children).filter(function (c) {
|
|
5143
|
+
return c instanceof HTMLElement && c.getAttribute("role") === "tab";
|
|
5144
|
+
});
|
|
5145
|
+
},
|
|
5146
|
+
});
|
|
5147
|
+
}
|
|
5148
|
+
if (role === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.radioButton) {
|
|
5149
|
+
this.attachRovingNav(el, {
|
|
5150
|
+
includeHomeEnd: false,
|
|
5151
|
+
members: function () {
|
|
5152
|
+
var _a;
|
|
5153
|
+
var group = (_a = el.closest('[role="radiogroup"]')) !== null && _a !== void 0 ? _a : el.parentElement;
|
|
5154
|
+
if (!group)
|
|
5155
|
+
return [];
|
|
5156
|
+
return Array.from(group.querySelectorAll('[role="radio"]'));
|
|
5157
|
+
},
|
|
5158
|
+
});
|
|
5159
|
+
}
|
|
5160
|
+
// Focus handler for nodes with the Focusable trait. When AT focuses an
|
|
5161
|
+
// element, notify the C++ runtime so it can update internal focus state
|
|
5162
|
+
// (visual focus rings, etc.). Gated on Focusable trait
|
|
5163
|
+
if ((0,_types__WEBPACK_IMPORTED_MODULE_0__.hasTrait)(node.traitFlags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticTrait.Focusable)) {
|
|
5164
|
+
el.addEventListener("focus", function () {
|
|
5165
|
+
_this.requestFocus(nodeId);
|
|
5166
|
+
});
|
|
5167
|
+
}
|
|
5168
|
+
};
|
|
5169
|
+
// ---- Attribute application ----
|
|
5170
|
+
AccessibilityOverlay.prototype.applyAttributes = function (el, node) {
|
|
5171
|
+
var _a, _b, _c;
|
|
5172
|
+
var role = node.role;
|
|
5173
|
+
var flags = node.stateFlags;
|
|
5174
|
+
var traits = node.traitFlags;
|
|
5175
|
+
// Role
|
|
5176
|
+
var ariaRole = ariaRoleForSemantic(role);
|
|
5177
|
+
if (ariaRole) {
|
|
5178
|
+
setAttr(el, "role", ariaRole);
|
|
5179
|
+
}
|
|
5180
|
+
else {
|
|
5181
|
+
removeAttr(el, "role");
|
|
5182
|
+
}
|
|
5183
|
+
// Links: a bare <a> with no href has no link semantics, so set the role
|
|
5184
|
+
// explicitly (ariaRoleForSemantic returns null for link → native <a>).
|
|
5185
|
+
if (role === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.link) {
|
|
5186
|
+
setAttr(el, "role", "link");
|
|
5187
|
+
}
|
|
5188
|
+
// Tabindex — keep the screen-reader overlay out of the browser's sequential
|
|
5189
|
+
// Tab order. Interactive/focusable nodes remain programmatically focusable
|
|
5190
|
+
// so AT/runtime focus sync can still target them when needed. List items are
|
|
5191
|
+
// included because Mobile Safari won't iterate them otherwise.
|
|
5192
|
+
if (isInteractiveRole(role) ||
|
|
5193
|
+
(0,_types__WEBPACK_IMPORTED_MODULE_0__.hasTrait)(traits, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticTrait.Focusable) ||
|
|
5194
|
+
role === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.listItem) {
|
|
5195
|
+
setAttr(el, "tabindex", "-1");
|
|
5196
|
+
}
|
|
5197
|
+
else {
|
|
5198
|
+
removeAttr(el, "tabindex");
|
|
5199
|
+
}
|
|
5200
|
+
// Label / value / hint
|
|
5201
|
+
if (node.label) {
|
|
5202
|
+
setAttr(el, "aria-label", node.label);
|
|
5203
|
+
}
|
|
5204
|
+
else {
|
|
5205
|
+
removeAttr(el, "aria-label");
|
|
5206
|
+
}
|
|
5207
|
+
if (role === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.slider) {
|
|
5208
|
+
if (node.value) {
|
|
5209
|
+
// aria-valuenow must be numeric; keep the display string (e.g. "75%")
|
|
5210
|
+
// in aria-valuetext only.
|
|
5211
|
+
var numericValue = parseFloat(node.value);
|
|
5212
|
+
if (Number.isFinite(numericValue)) {
|
|
5213
|
+
setAttr(el, "aria-valuenow", String(numericValue));
|
|
5214
|
+
}
|
|
5215
|
+
else {
|
|
5216
|
+
removeAttr(el, "aria-valuenow");
|
|
5217
|
+
}
|
|
5218
|
+
setAttr(el, "aria-valuetext", node.value);
|
|
5219
|
+
}
|
|
5220
|
+
else {
|
|
5221
|
+
removeAttr(el, "aria-valuenow");
|
|
5222
|
+
removeAttr(el, "aria-valuetext");
|
|
5223
|
+
}
|
|
5224
|
+
// TODO: aria-valuemin / aria-valuemax are required by ARIA.
|
|
5225
|
+
// Defaulting to horizontal; vertical sliders need orientation data from C++.
|
|
5226
|
+
setAttr(el, "aria-orientation", "horizontal");
|
|
5227
|
+
setBoolAttr(el, "aria-readonly", (0,_types__WEBPACK_IMPORTED_MODULE_0__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticState.ReadOnly));
|
|
5228
|
+
}
|
|
5229
|
+
else {
|
|
5230
|
+
removeAttr(el, "aria-valuenow");
|
|
5231
|
+
removeAttr(el, "aria-valuetext");
|
|
5232
|
+
removeAttr(el, "aria-orientation");
|
|
5233
|
+
removeAttr(el, "aria-readonly");
|
|
5234
|
+
}
|
|
5235
|
+
if (node.hint) {
|
|
5236
|
+
var descId = "rive-".concat(this.instanceId, "-desc-").concat(node.id);
|
|
5237
|
+
var descEl = this.descElements.get(node.id);
|
|
5238
|
+
if (!descEl) {
|
|
5239
|
+
descEl = document.createElement("span");
|
|
5240
|
+
descEl.id = descId;
|
|
5241
|
+
descEl.style.cssText = DESC_SPAN_STYLE;
|
|
5242
|
+
this.container.appendChild(descEl);
|
|
5243
|
+
this.descElements.set(node.id, descEl);
|
|
5244
|
+
}
|
|
5245
|
+
if (descEl.textContent !== node.hint)
|
|
5246
|
+
descEl.textContent = node.hint;
|
|
5247
|
+
setAttr(el, "aria-describedby", descId);
|
|
5248
|
+
}
|
|
5249
|
+
else {
|
|
5250
|
+
removeAttr(el, "aria-describedby");
|
|
5251
|
+
var staleDesc = this.descElements.get(node.id);
|
|
5252
|
+
if (staleDesc) {
|
|
5253
|
+
if (staleDesc.parentNode)
|
|
5254
|
+
staleDesc.parentNode.removeChild(staleDesc);
|
|
5255
|
+
this.descElements.delete(node.id);
|
|
5256
|
+
}
|
|
5257
|
+
}
|
|
5258
|
+
// Text nodes: use textContent rather than aria-label so screen readers
|
|
5259
|
+
// announce the text in virtual/browse mode (aria-label on a bare <span>
|
|
5260
|
+
// with no widget role is ignored by some AT in document browse mode).
|
|
5261
|
+
if (role === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.text) {
|
|
5262
|
+
var textSpan = (_a = el.querySelector(":scope > span")) !== null && _a !== void 0 ? _a : el;
|
|
5263
|
+
var text = (_b = node.label) !== null && _b !== void 0 ? _b : "";
|
|
5264
|
+
if (textSpan.textContent !== text)
|
|
5265
|
+
textSpan.textContent = text;
|
|
5266
|
+
removeAttr(el, "aria-label");
|
|
5267
|
+
if (node.headingLevel > 0) {
|
|
5268
|
+
setAttr(el, "role", "heading");
|
|
5269
|
+
setAttr(el, "aria-level", String(node.headingLevel));
|
|
5270
|
+
}
|
|
5271
|
+
else {
|
|
5272
|
+
// The generic role branch above already cleared role="heading";
|
|
5273
|
+
// aria-level must go with it when a heading reverts to plain text.
|
|
5274
|
+
removeAttr(el, "aria-level");
|
|
5275
|
+
}
|
|
5276
|
+
}
|
|
5277
|
+
// ---- Trait-gated states ----
|
|
5278
|
+
// Only set the ARIA property when the trait is present. When the trait
|
|
5279
|
+
// is absent, remove the attribute so AT sees "not applicable" rather
|
|
5280
|
+
// than "false".
|
|
5281
|
+
if ((0,_types__WEBPACK_IMPORTED_MODULE_0__.hasTrait)(traits, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticTrait.Expandable) && ARIA_EXPANDED_ROLES.has(role)) {
|
|
5282
|
+
setBoolAttr(el, "aria-expanded", (0,_types__WEBPACK_IMPORTED_MODULE_0__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticState.Expanded));
|
|
5283
|
+
}
|
|
5284
|
+
else {
|
|
5285
|
+
removeAttr(el, "aria-expanded");
|
|
5286
|
+
}
|
|
5287
|
+
// aria-selected is required on ALL tabs per ARIA spec regardless of trait;
|
|
5288
|
+
// for other roles it is trait-gated and guarded to ARIA_SELECTED_ROLES.
|
|
5289
|
+
if (role === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.tab) {
|
|
5290
|
+
setBoolAttr(el, "aria-selected", (0,_types__WEBPACK_IMPORTED_MODULE_0__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticState.Selected));
|
|
5291
|
+
}
|
|
5292
|
+
else if ((0,_types__WEBPACK_IMPORTED_MODULE_0__.hasTrait)(traits, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticTrait.Selectable) && ARIA_SELECTED_ROLES.has(role)) {
|
|
5293
|
+
setBoolAttr(el, "aria-selected", (0,_types__WEBPACK_IMPORTED_MODULE_0__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticState.Selected));
|
|
5294
|
+
}
|
|
5295
|
+
else {
|
|
5296
|
+
removeAttr(el, "aria-selected");
|
|
5297
|
+
}
|
|
5298
|
+
if ((0,_types__WEBPACK_IMPORTED_MODULE_0__.hasTrait)(traits, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticTrait.Checkable) && ARIA_CHECKED_ROLES.has(role)) {
|
|
5299
|
+
// Mixed wins over Checked per the C++ precedence contract, but
|
|
5300
|
+
// role="switch" only accepts true/false — "mixed" is invalid per ARIA.
|
|
5301
|
+
if ((0,_types__WEBPACK_IMPORTED_MODULE_0__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticState.Mixed) && role !== _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.switchControl) {
|
|
5302
|
+
setAttr(el, "aria-checked", "mixed");
|
|
5303
|
+
}
|
|
5304
|
+
else {
|
|
5305
|
+
setBoolAttr(el, "aria-checked", (0,_types__WEBPACK_IMPORTED_MODULE_0__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticState.Checked));
|
|
5306
|
+
}
|
|
5307
|
+
}
|
|
5308
|
+
else {
|
|
5309
|
+
removeAttr(el, "aria-checked");
|
|
5310
|
+
}
|
|
5311
|
+
if ((0,_types__WEBPACK_IMPORTED_MODULE_0__.hasTrait)(traits, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticTrait.Toggleable)) {
|
|
5312
|
+
if (ARIA_PRESSED_ROLES.has(role)) {
|
|
5313
|
+
setBoolAttr(el, "aria-pressed", (0,_types__WEBPACK_IMPORTED_MODULE_0__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticState.Toggled));
|
|
5314
|
+
}
|
|
5315
|
+
else {
|
|
5316
|
+
removeAttr(el, "aria-pressed");
|
|
5317
|
+
}
|
|
5318
|
+
// switch uses aria-checked (not aria-pressed) for its on/off state.
|
|
5319
|
+
if (role === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.switchControl) {
|
|
5320
|
+
setBoolAttr(el, "aria-checked", (0,_types__WEBPACK_IMPORTED_MODULE_0__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticState.Toggled));
|
|
5321
|
+
}
|
|
5322
|
+
}
|
|
5323
|
+
else {
|
|
5324
|
+
removeAttr(el, "aria-pressed");
|
|
5325
|
+
}
|
|
5326
|
+
if ((0,_types__WEBPACK_IMPORTED_MODULE_0__.hasTrait)(traits, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticTrait.Requirable) && ARIA_REQUIRED_ROLES.has(role)) {
|
|
5327
|
+
setBoolAttr(el, "aria-required", (0,_types__WEBPACK_IMPORTED_MODULE_0__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticState.Required));
|
|
5328
|
+
}
|
|
5329
|
+
else {
|
|
5330
|
+
removeAttr(el, "aria-required");
|
|
5331
|
+
}
|
|
5332
|
+
if ((0,_types__WEBPACK_IMPORTED_MODULE_0__.hasTrait)(traits, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticTrait.Enablable)) {
|
|
5333
|
+
setBoolAttr(el, "aria-disabled", (0,_types__WEBPACK_IMPORTED_MODULE_0__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticState.Disabled));
|
|
5334
|
+
}
|
|
5335
|
+
else {
|
|
5336
|
+
removeAttr(el, "aria-disabled");
|
|
5337
|
+
}
|
|
5338
|
+
// ---- Non-trait states ----
|
|
5339
|
+
// Hide from AT when explicitly hidden, or when an image has no accessible
|
|
5340
|
+
// name — a nameless role="img" is a WCAG 1.1.1 violation; treat it as
|
|
5341
|
+
// decorative instead.
|
|
5342
|
+
var isDecorativeImage = role === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.image && !node.label;
|
|
5343
|
+
if ((0,_types__WEBPACK_IMPORTED_MODULE_0__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticState.Hidden) || (0,_types__WEBPACK_IMPORTED_MODULE_0__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticState.Obscured) || isDecorativeImage) {
|
|
5344
|
+
setAttr(el, "aria-hidden", "true");
|
|
5345
|
+
}
|
|
5346
|
+
else {
|
|
5347
|
+
removeAttr(el, "aria-hidden");
|
|
5348
|
+
}
|
|
5349
|
+
if ((0,_types__WEBPACK_IMPORTED_MODULE_0__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticState.LiveRegion)) {
|
|
5350
|
+
setAttr(el, "aria-live", "polite");
|
|
5351
|
+
}
|
|
5352
|
+
else {
|
|
5353
|
+
removeAttr(el, "aria-live");
|
|
5354
|
+
}
|
|
5355
|
+
// textField-specific
|
|
5356
|
+
// TODO: Details here may change once we implement text inputs
|
|
5357
|
+
if (role === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.textField) {
|
|
5358
|
+
setBoolAttr(el, "aria-readonly", (0,_types__WEBPACK_IMPORTED_MODULE_0__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticState.ReadOnly));
|
|
5359
|
+
setBoolAttr(el, "aria-multiline", (0,_types__WEBPACK_IMPORTED_MODULE_0__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticState.Multiline));
|
|
5360
|
+
// Surface the current field value as DOM text so screen readers can
|
|
5361
|
+
// announce it. Only safe when the node has no semantic children —
|
|
5362
|
+
// setting textContent would remove any child elements from the DOM.
|
|
5363
|
+
if (node.children.length === 0) {
|
|
5364
|
+
var value = (_c = node.value) !== null && _c !== void 0 ? _c : "";
|
|
5365
|
+
if (el.textContent !== value)
|
|
5366
|
+
el.textContent = value;
|
|
5367
|
+
}
|
|
5368
|
+
}
|
|
5369
|
+
else {
|
|
5370
|
+
removeAttr(el, "aria-multiline");
|
|
5371
|
+
}
|
|
5372
|
+
// alertDialog is always modal per WAI-ARIA; a plain dialog only when the Modal state flag is set.
|
|
5373
|
+
if (isModalDialogRole(role, flags)) {
|
|
5374
|
+
setAttr(el, "aria-modal", "true");
|
|
5375
|
+
}
|
|
5376
|
+
else {
|
|
5377
|
+
removeAttr(el, "aria-modal");
|
|
5378
|
+
}
|
|
5379
|
+
};
|
|
5380
|
+
// ---- Positioning ----
|
|
5381
|
+
/**
|
|
5382
|
+
* Positions an element in artboard-space coordinates relative to its parent.
|
|
5383
|
+
*
|
|
5384
|
+
* Node bounds stay in raw artboard units — the CSS `transform: matrix(...)`
|
|
5385
|
+
* on the transform container maps artboard units to CSS pixels in one GPU
|
|
5386
|
+
* pass. No per-node forwardMat multiplication or DPR division needed here.
|
|
5387
|
+
*
|
|
5388
|
+
* Round to whole artboard units before comparing to avoid triggering AX
|
|
5389
|
+
* layout notifications from sub-unit floating-point animation jitter.
|
|
5390
|
+
*/
|
|
5391
|
+
AccessibilityOverlay.prototype.applyPosition = function (el, node, parentArtboardLeft, parentArtboardTop) {
|
|
5392
|
+
// Clamp each node's rect to the artboard viewport before computing CSS.
|
|
5393
|
+
// Without this, nodes whose artboard bounds exceed the artboard (e.g. a
|
|
5394
|
+
// scroll list container whose height is the full content, not the viewport)
|
|
5395
|
+
// produce CSS heights that overflow the transform container. WebKit then
|
|
5396
|
+
// unions all descendant AX rects and extends the container's AX origin
|
|
5397
|
+
// above the canvas regardless of overflow:hidden on ancestors.
|
|
5398
|
+
var ab = this._artboardBounds;
|
|
5399
|
+
var clampedMinX = Math.max(node.minX, ab.minX);
|
|
5400
|
+
var clampedMinY = Math.max(node.minY, ab.minY);
|
|
5401
|
+
var clampedMaxX = Math.min(node.maxX, ab.maxX);
|
|
5402
|
+
var clampedMaxY = Math.min(node.maxY, ab.maxY);
|
|
5403
|
+
var elLeft = clampedMinX - parentArtboardLeft;
|
|
5404
|
+
var elTop = clampedMinY - parentArtboardTop;
|
|
5405
|
+
var elWidth = Math.max(0, clampedMaxX - clampedMinX);
|
|
5406
|
+
var elHeight = Math.max(0, clampedMaxY - clampedMinY);
|
|
5407
|
+
var tx = Math.round(elLeft);
|
|
5408
|
+
var ty = Math.round(elTop);
|
|
5409
|
+
var pxWidth = Math.round(elWidth) + "px";
|
|
5410
|
+
var pxHeight = Math.round(elHeight) + "px";
|
|
5411
|
+
// Use left/top layout properties for positioning. VoiceOver reliably
|
|
5412
|
+
// handles layout position + a single ancestor CSS transform (the transform
|
|
5413
|
+
// container). Chaining CSS transforms across multiple stacking contexts
|
|
5414
|
+
// (transform container → node identity → item translate) caused VoiceOver
|
|
5415
|
+
// to compute the correct SIZE but wrong POSITION. Artboard clamping above
|
|
5416
|
+
// guarantees tx/ty are always ≥ 0, so the negative-top overflow problem
|
|
5417
|
+
// that originally prompted the switch to CSS transforms no longer applies.
|
|
5418
|
+
var pxLeft = tx + "px";
|
|
5419
|
+
var pxTop = ty + "px";
|
|
5420
|
+
if (el.style.left !== pxLeft)
|
|
5421
|
+
el.style.left = pxLeft;
|
|
5422
|
+
if (el.style.top !== pxTop)
|
|
5423
|
+
el.style.top = pxTop;
|
|
5424
|
+
if (el.style.width !== pxWidth)
|
|
5425
|
+
el.style.width = pxWidth;
|
|
5426
|
+
if (el.style.height !== pxHeight)
|
|
5427
|
+
el.style.height = pxHeight;
|
|
5428
|
+
// Clear any CSS transform from a previous render pass.
|
|
5429
|
+
if (el.style.transform)
|
|
5430
|
+
el.style.transform = "";
|
|
5431
|
+
if (node.role === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.text) {
|
|
5432
|
+
this.pendingTextGeometry.push(el);
|
|
5433
|
+
}
|
|
5434
|
+
};
|
|
5435
|
+
/**
|
|
5436
|
+
* Scale each queued text span to fit its layout box, batched so a frame
|
|
5437
|
+
* pays at most one synchronous layout: all measurement-reset writes first,
|
|
5438
|
+
* then all rect reads, then all transform writes. Interleaving
|
|
5439
|
+
* write→read→write per node would force a reflow per text node instead.
|
|
5440
|
+
*
|
|
5441
|
+
* Nodes whose box size and text are unchanged since the last pass are
|
|
5442
|
+
* skipped entirely (their existing transform is still correct — the scale
|
|
5443
|
+
* is a ratio of two rects, so ancestor transform changes cancel out).
|
|
5444
|
+
*/
|
|
5445
|
+
AccessibilityOverlay.prototype.flushTextGeometry = function () {
|
|
5446
|
+
var _a;
|
|
5447
|
+
if (this.pendingTextGeometry.length === 0)
|
|
5448
|
+
return;
|
|
5449
|
+
// Phase 1 — writes: reset spans to their natural size for measurement.
|
|
5450
|
+
// The previous pass's scale must be cleared, or the rect reads below
|
|
5451
|
+
// would measure the scaled span and compound the correction.
|
|
5452
|
+
var toMeasure = [];
|
|
5453
|
+
for (var _i = 0, _b = this.pendingTextGeometry; _i < _b.length; _i++) {
|
|
5454
|
+
var host = _b[_i];
|
|
5455
|
+
var span = (_a = host.querySelector(":scope > span")) !== null && _a !== void 0 ? _a : host;
|
|
5456
|
+
var key = "".concat(host.style.width, "|").concat(host.style.height, "|").concat(span.textContent);
|
|
5457
|
+
if (this.textGeometryKeys.get(host) === key)
|
|
5458
|
+
continue;
|
|
5459
|
+
span.style.width = "auto";
|
|
5460
|
+
span.style.height = "auto";
|
|
5461
|
+
span.style.transformOrigin = "0 0";
|
|
5462
|
+
span.style.transform = "";
|
|
5463
|
+
toMeasure.push({ host: host, span: span, key: key });
|
|
5464
|
+
}
|
|
5465
|
+
this.pendingTextGeometry.length = 0;
|
|
5466
|
+
// Phase 2 — reads: one layout pass covers every rect measurement.
|
|
5467
|
+
var transforms = toMeasure.map(function (_a) {
|
|
5468
|
+
var host = _a.host, span = _a.span;
|
|
5469
|
+
var parentRect = host.getBoundingClientRect();
|
|
5470
|
+
var natural = span.getBoundingClientRect();
|
|
5471
|
+
if (natural.width > 0 && natural.height > 0) {
|
|
5472
|
+
var scaleX = parentRect.width / natural.width;
|
|
5473
|
+
var scaleY = parentRect.height / natural.height;
|
|
5474
|
+
return "scale(".concat(scaleX, ", ").concat(scaleY, ")");
|
|
5475
|
+
}
|
|
5476
|
+
return "none";
|
|
5477
|
+
});
|
|
5478
|
+
// Phase 3 — writes: apply all transforms.
|
|
5479
|
+
for (var i = 0; i < toMeasure.length; i++) {
|
|
5480
|
+
var _c = toMeasure[i], host = _c.host, span = _c.span, key = _c.key;
|
|
5481
|
+
span.style.transform = transforms[i];
|
|
5482
|
+
this.textGeometryKeys.set(host, key);
|
|
5483
|
+
}
|
|
5484
|
+
};
|
|
5485
|
+
// ---- Transform container ----
|
|
5486
|
+
/**
|
|
5487
|
+
* Creates (on first call) and updates the artboard-space transform container.
|
|
5488
|
+
*
|
|
5489
|
+
* The container is sized to the artboard dimensions and carries a CSS
|
|
5490
|
+
* `transform: matrix(...)` equivalent to `forwardMat / dpr`. All semantic
|
|
5491
|
+
* node elements are children of this container and use raw artboard
|
|
5492
|
+
* coordinates as their CSS `left/top/width/height`, so the CSS compositor
|
|
5493
|
+
* applies the artboard→screen mapping in one pass.
|
|
5494
|
+
*/
|
|
5495
|
+
AccessibilityOverlay.prototype.syncTransformContainer = function (forwardMat, dpr, artboardBounds) {
|
|
5496
|
+
if (!this.transformContainer) {
|
|
5497
|
+
var tc = document.createElement("div");
|
|
5498
|
+
tc.style.cssText = [
|
|
5499
|
+
"position:absolute",
|
|
5500
|
+
"top:0",
|
|
5501
|
+
"left:0",
|
|
5502
|
+
// overflow:visible — artboard viewport clamping is done per-node in
|
|
5503
|
+
// applyPosition
|
|
5504
|
+
"overflow:visible",
|
|
5505
|
+
"pointer-events:none",
|
|
5506
|
+
"transform-origin:0 0",
|
|
5507
|
+
].join(";");
|
|
5508
|
+
this.container.appendChild(tc);
|
|
5509
|
+
this.transformContainer = tc;
|
|
5510
|
+
}
|
|
5511
|
+
var w = artboardBounds.maxX - artboardBounds.minX;
|
|
5512
|
+
var h = artboardBounds.maxY - artboardBounds.minY;
|
|
5513
|
+
this.transformContainer.style.width = Math.round(w) + "px";
|
|
5514
|
+
this.transformContainer.style.height = Math.round(h) + "px";
|
|
5515
|
+
var s = 1 / (dpr || 1);
|
|
5516
|
+
var a = forwardMat.xx * s;
|
|
5517
|
+
var b = forwardMat.xy * s;
|
|
5518
|
+
var c = forwardMat.yx * s;
|
|
5519
|
+
var d = forwardMat.yy * s;
|
|
5520
|
+
var tx = forwardMat.tx * s;
|
|
5521
|
+
var ty = forwardMat.ty * s;
|
|
5522
|
+
this.transformContainer.style.transform =
|
|
5523
|
+
"matrix(".concat(a, ",").concat(b, ",").concat(c, ",").concat(d, ",").concat(tx, ",").concat(ty, ")");
|
|
5524
|
+
};
|
|
5525
|
+
return AccessibilityOverlay;
|
|
5526
|
+
}());
|
|
5527
|
+
|
|
5528
|
+
// ---------------------------------------------------------------------------
|
|
5529
|
+
// Static helpers (module-private)
|
|
5530
|
+
// ---------------------------------------------------------------------------
|
|
5531
|
+
// ---------------------------------------------------------------------------
|
|
5532
|
+
// ARIA attribute eligibility — role sets
|
|
5533
|
+
//
|
|
5534
|
+
// Each set lists the Rive roles for which a given ARIA attribute is valid per
|
|
5535
|
+
// WAI-ARIA 1.2 ("Used in roles" + "Inherits into roles"). The trait-gated
|
|
5536
|
+
// blocks in applyAttributes check these before setting an attribute so that
|
|
5537
|
+
// C++ nodes with unexpected trait combinations never produce invalid markup.
|
|
5538
|
+
//
|
|
5539
|
+
// To add a new role: append it to the relevant set(s) here — no other changes
|
|
5540
|
+
// needed in applyAttributes.
|
|
5541
|
+
// ---------------------------------------------------------------------------
|
|
5542
|
+
/** aria-expanded: button, link, checkbox, switch (inherits button), tab. */
|
|
5543
|
+
var ARIA_EXPANDED_ROLES = new Set([
|
|
5544
|
+
_types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.button,
|
|
5545
|
+
_types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.link,
|
|
5546
|
+
_types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.checkbox,
|
|
5547
|
+
_types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.switchControl,
|
|
5548
|
+
_types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.tab,
|
|
5549
|
+
]);
|
|
5550
|
+
/**
|
|
5551
|
+
* aria-selected: tab is the only role in our current set that natively
|
|
5552
|
+
* supports it. Tab is also handled by an explicit unconditional branch in
|
|
5553
|
+
* applyAttributes (ARIA requires it there regardless of Selectable trait), but
|
|
5554
|
+
* the set still lists it so the constraint is visible in one place.
|
|
5555
|
+
*/
|
|
5556
|
+
var ARIA_SELECTED_ROLES = new Set([
|
|
5557
|
+
_types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.tab,
|
|
5558
|
+
]);
|
|
5559
|
+
/** aria-checked: checkbox, radio, switch. */
|
|
5560
|
+
var ARIA_CHECKED_ROLES = new Set([
|
|
5561
|
+
_types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.checkbox,
|
|
5562
|
+
_types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.radioButton,
|
|
5563
|
+
_types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.switchControl,
|
|
5564
|
+
]);
|
|
5565
|
+
/**
|
|
5566
|
+
* aria-pressed: button only. switch is a button subclass in ARIA but uses
|
|
5567
|
+
* aria-checked (not aria-pressed) for its on/off state — it is intentionally
|
|
5568
|
+
* excluded here and handled separately in the Toggleable block.
|
|
5569
|
+
*/
|
|
5570
|
+
var ARIA_PRESSED_ROLES = new Set([
|
|
5571
|
+
_types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.button,
|
|
5572
|
+
]);
|
|
5573
|
+
/** aria-required: checkbox, textbox, radiogroup. */
|
|
5574
|
+
var ARIA_REQUIRED_ROLES = new Set([
|
|
5575
|
+
_types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.checkbox,
|
|
5576
|
+
_types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.textField,
|
|
5577
|
+
_types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.radioGroup,
|
|
5578
|
+
]);
|
|
5579
|
+
// ---------------------------------------------------------------------------
|
|
5580
|
+
/** Style for visually-hidden description spans used with aria-describedby. */
|
|
5581
|
+
var DESC_SPAN_STYLE = [
|
|
5582
|
+
"position:absolute",
|
|
5583
|
+
"width:1px",
|
|
5584
|
+
"height:1px",
|
|
5585
|
+
"overflow:hidden",
|
|
5586
|
+
"pointer-events:none",
|
|
5587
|
+
"left:-9999px",
|
|
5588
|
+
].join(";");
|
|
5589
|
+
var BASE_NODE_STYLE = [
|
|
5590
|
+
"position:absolute",
|
|
5591
|
+
"pointer-events:none",
|
|
5592
|
+
"box-sizing:border-box",
|
|
5593
|
+
"overflow:visible",
|
|
5594
|
+
"margin:0",
|
|
5595
|
+
"padding:0",
|
|
5596
|
+
"transform-origin: 0px 0px 0px",
|
|
5597
|
+
"border:none",
|
|
5598
|
+
"background:transparent",
|
|
5599
|
+
"color:transparent",
|
|
5600
|
+
// "list-style:none",
|
|
5601
|
+
].join(";");
|
|
5602
|
+
var SPAN_EXP = [
|
|
5603
|
+
"display:inline-block",
|
|
5604
|
+
"white-space:nowrap",
|
|
5605
|
+
"pointer-events:none",
|
|
5606
|
+
].join(";");
|
|
5607
|
+
/**
|
|
5608
|
+
* Attribute writers that skip same-value mutations. Even a no-op setAttribute
|
|
5609
|
+
* fires a mutation record, and whether AX layers dedupe those is
|
|
5610
|
+
* browser-specific — skipping the write is the only browser-proof guard.
|
|
5611
|
+
*/
|
|
5612
|
+
function setAttr(el, attr, value) {
|
|
5613
|
+
if (el.getAttribute(attr) !== value)
|
|
5614
|
+
el.setAttribute(attr, value);
|
|
5615
|
+
}
|
|
5616
|
+
function removeAttr(el, attr) {
|
|
5617
|
+
if (el.hasAttribute(attr))
|
|
5618
|
+
el.removeAttribute(attr);
|
|
5619
|
+
}
|
|
5620
|
+
function setBoolAttr(el, attr, value) {
|
|
5621
|
+
setAttr(el, attr, value ? "true" : "false");
|
|
5622
|
+
}
|
|
5623
|
+
/** Roles that receive click/Enter/Space action handlers. */
|
|
5624
|
+
function isClickableRole(role) {
|
|
5625
|
+
switch (role) {
|
|
5626
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.button:
|
|
5627
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.link:
|
|
5628
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.checkbox:
|
|
5629
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.switchControl:
|
|
5630
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.tab:
|
|
5631
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.radioButton:
|
|
5632
|
+
return true;
|
|
5633
|
+
default:
|
|
5634
|
+
return false;
|
|
5635
|
+
}
|
|
5636
|
+
}
|
|
5637
|
+
/** Roles that receive tabindex="-1" for programmatic/AT focus (not Tab order). */
|
|
5638
|
+
function isInteractiveRole(role) {
|
|
5639
|
+
switch (role) {
|
|
5640
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.button:
|
|
5641
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.link:
|
|
5642
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.checkbox:
|
|
5643
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.switchControl:
|
|
5644
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.slider:
|
|
5645
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.tab:
|
|
5646
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.radioButton:
|
|
5647
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.textField:
|
|
5648
|
+
return true;
|
|
5649
|
+
default:
|
|
5650
|
+
return false;
|
|
5651
|
+
}
|
|
5652
|
+
}
|
|
5653
|
+
/**
|
|
5654
|
+
* A modal/alert dialog: alertDialog is always modal per WAI-ARIA, a plain
|
|
5655
|
+
* dialog only when the Modal state flag is set.
|
|
5656
|
+
*/
|
|
5657
|
+
function isModalDialogRole(role, flags) {
|
|
5658
|
+
return (role === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.alertDialog ||
|
|
5659
|
+
(role === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.dialog && (0,_types__WEBPACK_IMPORTED_MODULE_0__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticState.Modal)));
|
|
5660
|
+
}
|
|
5661
|
+
/** Whether a node can receive focus: an interactive role or the Focusable trait. */
|
|
5662
|
+
function isFocusableNode(node) {
|
|
5663
|
+
return (isInteractiveRole(node.role) ||
|
|
5664
|
+
(0,_types__WEBPACK_IMPORTED_MODULE_0__.hasTrait)(node.traitFlags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticTrait.Focusable));
|
|
5665
|
+
}
|
|
5666
|
+
/**
|
|
5667
|
+
* Choose an HTML tag for a given role. Prefer native semantic elements
|
|
5668
|
+
* where they exist — screen readers treat them more reliably than
|
|
5669
|
+
* generic elements with ARIA role overrides.
|
|
5670
|
+
*/
|
|
5671
|
+
function tagForRole(role) {
|
|
5672
|
+
switch (role) {
|
|
5673
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.link:
|
|
5674
|
+
return "a";
|
|
5675
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.text:
|
|
5676
|
+
// The outer div is the positioned AX element VoiceOver measures for its
|
|
5677
|
+
// highlight box. The text itself lives in a child <span> (see createElement).
|
|
5678
|
+
return "div";
|
|
5679
|
+
default:
|
|
5680
|
+
return "div";
|
|
5681
|
+
}
|
|
5682
|
+
}
|
|
5683
|
+
/**
|
|
5684
|
+
* Maps a Rive SemanticRole to an ARIA `role` attribute value.
|
|
5685
|
+
* Returns null for roles that don't need an explicit role attribute here
|
|
5686
|
+
* (e.g. text nodes use an outer div + inner span with textContent; heading
|
|
5687
|
+
* role is applied separately when headingLevel > 0).
|
|
5688
|
+
*/
|
|
5689
|
+
function ariaRoleForSemantic(role) {
|
|
5690
|
+
switch (role) {
|
|
5691
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.none:
|
|
5692
|
+
// TODO: Role "none" removes the node from the accessibility tree. For now, setting to Group, but maybe we want to switch to "none"
|
|
5693
|
+
// or "presentation".
|
|
5694
|
+
return "group";
|
|
5695
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.button:
|
|
5696
|
+
return "button";
|
|
5697
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.link:
|
|
5698
|
+
return null; // native <a>
|
|
5699
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.checkbox:
|
|
5700
|
+
return "checkbox";
|
|
5701
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.switchControl:
|
|
5702
|
+
return "switch";
|
|
5703
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.slider:
|
|
5704
|
+
return "slider";
|
|
5705
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.textField:
|
|
5706
|
+
return "textbox";
|
|
5707
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.image:
|
|
5708
|
+
return "img";
|
|
5709
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.group:
|
|
5710
|
+
return "group";
|
|
5711
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.list:
|
|
5712
|
+
return "list";
|
|
5713
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.listItem:
|
|
5714
|
+
return "listitem";
|
|
5715
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.tab:
|
|
5716
|
+
return "tab";
|
|
5717
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.tabList:
|
|
5718
|
+
return "tablist";
|
|
5719
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.dialog:
|
|
5720
|
+
return "dialog";
|
|
5721
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.alertDialog:
|
|
5722
|
+
return "alertdialog";
|
|
5723
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.radioGroup:
|
|
5724
|
+
return "radiogroup";
|
|
5725
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.radioButton:
|
|
5726
|
+
return "radio";
|
|
5727
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.text:
|
|
5728
|
+
// Text nodes use <span>; heading role is applied separately
|
|
5729
|
+
// when headingLevel > 0.
|
|
5730
|
+
return null;
|
|
5731
|
+
default:
|
|
5732
|
+
return null;
|
|
5733
|
+
}
|
|
5734
|
+
}
|
|
5735
|
+
|
|
5736
|
+
|
|
5737
|
+
/***/ }),
|
|
5738
|
+
/* 10 */
|
|
5739
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
5740
|
+
|
|
3932
5741
|
__webpack_require__.r(__webpack_exports__);
|
|
3933
5742
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
3934
5743
|
/* harmony export */ AudioAssetWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_3__.AudioAssetWrapper),
|
|
@@ -3949,11 +5758,11 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
3949
5758
|
/* harmony export */ registerTouchInteractions: () => (/* reexport safe */ _registerTouchInteractions__WEBPACK_IMPORTED_MODULE_0__.registerTouchInteractions),
|
|
3950
5759
|
/* harmony export */ sanitizeUrl: () => (/* reexport safe */ _sanitizeUrl__WEBPACK_IMPORTED_MODULE_2__.sanitizeUrl)
|
|
3951
5760
|
/* harmony export */ });
|
|
3952
|
-
/* harmony import */ var _registerTouchInteractions__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(
|
|
3953
|
-
/* harmony import */ var _registerKeyboardInteractions__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(
|
|
3954
|
-
/* harmony import */ var _sanitizeUrl__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(
|
|
3955
|
-
/* harmony import */ var _finalizationRegistry__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(
|
|
3956
|
-
/* harmony import */ var _riveFont__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(
|
|
5761
|
+
/* harmony import */ var _registerTouchInteractions__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(11);
|
|
5762
|
+
/* harmony import */ var _registerKeyboardInteractions__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(12);
|
|
5763
|
+
/* harmony import */ var _sanitizeUrl__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(13);
|
|
5764
|
+
/* harmony import */ var _finalizationRegistry__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(14);
|
|
5765
|
+
/* harmony import */ var _riveFont__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(15);
|
|
3957
5766
|
|
|
3958
5767
|
|
|
3959
5768
|
|
|
@@ -3962,7 +5771,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
3962
5771
|
|
|
3963
5772
|
|
|
3964
5773
|
/***/ }),
|
|
3965
|
-
/*
|
|
5774
|
+
/* 11 */
|
|
3966
5775
|
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
3967
5776
|
|
|
3968
5777
|
__webpack_require__.r(__webpack_exports__);
|
|
@@ -4259,7 +6068,7 @@ var registerTouchInteractions = function (_a) {
|
|
|
4259
6068
|
|
|
4260
6069
|
|
|
4261
6070
|
/***/ }),
|
|
4262
|
-
/*
|
|
6071
|
+
/* 12 */
|
|
4263
6072
|
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
4264
6073
|
|
|
4265
6074
|
__webpack_require__.r(__webpack_exports__);
|
|
@@ -4299,9 +6108,16 @@ var FocusSessionState;
|
|
|
4299
6108
|
*/
|
|
4300
6109
|
var KeyboardInteractions = /** @class */ (function () {
|
|
4301
6110
|
function KeyboardInteractions(_a) {
|
|
4302
|
-
var canvas = _a.canvas, stateMachine = _a.stateMachine, hasFocusNodes = _a.hasFocusNodes;
|
|
6111
|
+
var canvas = _a.canvas, stateMachine = _a.stateMachine, hasFocusNodes = _a.hasFocusNodes, getOverlayElement = _a.getOverlayElement;
|
|
4303
6112
|
var _this = this;
|
|
6113
|
+
var _b;
|
|
4304
6114
|
this.focusSessionState = FocusSessionState.NotFocused;
|
|
6115
|
+
/** Whether the canvas currently has browser DOM focus. */
|
|
6116
|
+
this.canvasHasFocus = false;
|
|
6117
|
+
/** After Tab exits the last Rive node, ignore keydowns until focus re-enters the focus domain. */
|
|
6118
|
+
this.focusDomainReleased = false;
|
|
6119
|
+
/** Overlay element currently wired with focusin/keydown listeners, if any. */
|
|
6120
|
+
this.currentOverlayElement = null;
|
|
4305
6121
|
/**
|
|
4306
6122
|
* Handles the canvas gaining browser focus. The behavior differs based on how focus was gained -
|
|
4307
6123
|
*
|
|
@@ -4314,6 +6130,9 @@ var KeyboardInteractions = /** @class */ (function () {
|
|
|
4314
6130
|
* gates this so a click doesn't yank Rive focus to the first node on the focus event itself.
|
|
4315
6131
|
*/
|
|
4316
6132
|
this.onCanvasFocus = function (event) {
|
|
6133
|
+
_this.syncOverlayListener();
|
|
6134
|
+
_this.canvasHasFocus = true;
|
|
6135
|
+
_this.focusDomainReleased = false;
|
|
4317
6136
|
if (!_this.hasFocusNodes)
|
|
4318
6137
|
return;
|
|
4319
6138
|
if (_this.mainSm.focusState().hasFocus)
|
|
@@ -4329,9 +6148,22 @@ var KeyboardInteractions = /** @class */ (function () {
|
|
|
4329
6148
|
};
|
|
4330
6149
|
this.onCanvasBlur = function (_event) {
|
|
4331
6150
|
_this.focusSessionState = FocusSessionState.NotFocused;
|
|
6151
|
+
_this.canvasHasFocus = false;
|
|
6152
|
+
};
|
|
6153
|
+
this.onOverlayFocusIn = function (event) {
|
|
6154
|
+
if (_this.isInOverlay(event.target)) {
|
|
6155
|
+
_this.focusDomainReleased = false;
|
|
6156
|
+
}
|
|
6157
|
+
};
|
|
6158
|
+
this.onFocusDomainHostFocusIn = function (_event) {
|
|
6159
|
+
_this.syncOverlayListener();
|
|
4332
6160
|
};
|
|
4333
6161
|
this.onKeyDown = function (event) {
|
|
4334
|
-
|
|
6162
|
+
_this.syncOverlayListener();
|
|
6163
|
+
// After Tab exits the last Rive node, ignore keys until focus re-enters the focus domain.
|
|
6164
|
+
if (_this.focusDomainReleased)
|
|
6165
|
+
return;
|
|
6166
|
+
if (!_this.shouldRiveHandleKeyEvent(event))
|
|
4335
6167
|
return;
|
|
4336
6168
|
if (event.code === "Tab" && _this.hasFocusNodes) {
|
|
4337
6169
|
var forward = !event.shiftKey;
|
|
@@ -4343,17 +6175,23 @@ var KeyboardInteractions = /** @class */ (function () {
|
|
|
4343
6175
|
}
|
|
4344
6176
|
else {
|
|
4345
6177
|
// No more traversable nodes — release Tab to the page.
|
|
4346
|
-
// Set state immediately; onCanvasBlur will also fire naturally.
|
|
4347
6178
|
_this.focusSessionState = FocusSessionState.NotFocused;
|
|
6179
|
+
_this.focusDomainReleased = true;
|
|
6180
|
+
_this.canvasHasFocus = false;
|
|
4348
6181
|
}
|
|
6182
|
+
_this.syncOverlayListener();
|
|
4349
6183
|
}
|
|
4350
6184
|
};
|
|
4351
6185
|
this.canvas = canvas;
|
|
4352
6186
|
this.mainSm = stateMachine;
|
|
4353
6187
|
this.hasFocusNodes = hasFocusNodes;
|
|
6188
|
+
this.getOverlayElement = getOverlayElement;
|
|
6189
|
+
this.focusDomainHost = (_b = canvas.parentElement) !== null && _b !== void 0 ? _b : document;
|
|
4354
6190
|
canvas.addEventListener("focus", this.onCanvasFocus);
|
|
4355
6191
|
canvas.addEventListener("blur", this.onCanvasBlur);
|
|
4356
6192
|
canvas.addEventListener("keydown", this.onKeyDown);
|
|
6193
|
+
this.focusDomainHost.addEventListener("focusin", this.onFocusDomainHostFocusIn);
|
|
6194
|
+
this.syncOverlayListener();
|
|
4357
6195
|
}
|
|
4358
6196
|
/**
|
|
4359
6197
|
* Set the FocusSessionState. Useful for invoking a Rive "blur" without actually blurring from the <canvas>. This
|
|
@@ -4372,6 +6210,45 @@ var KeyboardInteractions = /** @class */ (function () {
|
|
|
4372
6210
|
KeyboardInteractions.prototype.notifyRiveFocused = function () {
|
|
4373
6211
|
this.focusSessionState = FocusSessionState.RiveFocused;
|
|
4374
6212
|
};
|
|
6213
|
+
/**
|
|
6214
|
+
* Whether Rive should handle this keydown — i.e. it currently owns keyboard input.
|
|
6215
|
+
* True when focus is anywhere in the Rive focus domain (the canvas itself or the
|
|
6216
|
+
* accessibility overlay), OR a focus session is active and the key landed on the
|
|
6217
|
+
* canvas.
|
|
6218
|
+
*/
|
|
6219
|
+
KeyboardInteractions.prototype.shouldRiveHandleKeyEvent = function (event) {
|
|
6220
|
+
var inFocusDomain = this.isInFocusDomain(document.activeElement) ||
|
|
6221
|
+
this.isInOverlay(event.target);
|
|
6222
|
+
if (inFocusDomain)
|
|
6223
|
+
return true;
|
|
6224
|
+
var sessionActive = this.focusSessionState !== FocusSessionState.NotFocused;
|
|
6225
|
+
var eventOnCanvas = event.target === this.canvas;
|
|
6226
|
+
return sessionActive && (this.canvasHasFocus || eventOnCanvas);
|
|
6227
|
+
};
|
|
6228
|
+
/** Rive focus domain = the canvas itself OR the accessibility overlay. */
|
|
6229
|
+
KeyboardInteractions.prototype.isInFocusDomain = function (target) {
|
|
6230
|
+
if (target === this.canvas)
|
|
6231
|
+
return true;
|
|
6232
|
+
return this.isInOverlay(target);
|
|
6233
|
+
};
|
|
6234
|
+
/** Overlay only (excludes the canvas) — the accessibility overlay subtree. */
|
|
6235
|
+
KeyboardInteractions.prototype.isInOverlay = function (target) {
|
|
6236
|
+
var _a, _b, _c;
|
|
6237
|
+
if (!(target instanceof Node))
|
|
6238
|
+
return false;
|
|
6239
|
+
return (_c = (_b = (_a = this.getOverlayElement) === null || _a === void 0 ? void 0 : _a.call(this)) === null || _b === void 0 ? void 0 : _b.contains(target)) !== null && _c !== void 0 ? _c : false;
|
|
6240
|
+
};
|
|
6241
|
+
KeyboardInteractions.prototype.syncOverlayListener = function () {
|
|
6242
|
+
var _a, _b, _c, _d, _e, _f;
|
|
6243
|
+
var nextOverlayElement = (_b = (_a = this.getOverlayElement) === null || _a === void 0 ? void 0 : _a.call(this)) !== null && _b !== void 0 ? _b : null;
|
|
6244
|
+
if (nextOverlayElement === this.currentOverlayElement)
|
|
6245
|
+
return;
|
|
6246
|
+
(_c = this.currentOverlayElement) === null || _c === void 0 ? void 0 : _c.removeEventListener("focusin", this.onOverlayFocusIn);
|
|
6247
|
+
(_d = this.currentOverlayElement) === null || _d === void 0 ? void 0 : _d.removeEventListener("keydown", this.onKeyDown, true);
|
|
6248
|
+
this.currentOverlayElement = nextOverlayElement;
|
|
6249
|
+
(_e = this.currentOverlayElement) === null || _e === void 0 ? void 0 : _e.addEventListener("focusin", this.onOverlayFocusIn);
|
|
6250
|
+
(_f = this.currentOverlayElement) === null || _f === void 0 ? void 0 : _f.addEventListener("keydown", this.onKeyDown, true);
|
|
6251
|
+
};
|
|
4375
6252
|
/**
|
|
4376
6253
|
* Whether the canvas currently matches :focus-visible — the browser's heuristic for keyboard-
|
|
4377
6254
|
* (vs pointer-) driven focus. For older browser versions that don't support this selector, return false
|
|
@@ -4396,9 +6273,13 @@ var KeyboardInteractions = /** @class */ (function () {
|
|
|
4396
6273
|
return true;
|
|
4397
6274
|
};
|
|
4398
6275
|
KeyboardInteractions.prototype.cleanup = function () {
|
|
6276
|
+
var _a, _b;
|
|
4399
6277
|
this.canvas.removeEventListener("focus", this.onCanvasFocus);
|
|
4400
6278
|
this.canvas.removeEventListener("blur", this.onCanvasBlur);
|
|
4401
6279
|
this.canvas.removeEventListener("keydown", this.onKeyDown);
|
|
6280
|
+
this.focusDomainHost.removeEventListener("focusin", this.onFocusDomainHostFocusIn);
|
|
6281
|
+
(_a = this.currentOverlayElement) === null || _a === void 0 ? void 0 : _a.removeEventListener("focusin", this.onOverlayFocusIn);
|
|
6282
|
+
(_b = this.currentOverlayElement) === null || _b === void 0 ? void 0 : _b.removeEventListener("keydown", this.onKeyDown, true);
|
|
4402
6283
|
};
|
|
4403
6284
|
return KeyboardInteractions;
|
|
4404
6285
|
}());
|
|
@@ -4406,7 +6287,7 @@ var KeyboardInteractions = /** @class */ (function () {
|
|
|
4406
6287
|
|
|
4407
6288
|
|
|
4408
6289
|
/***/ }),
|
|
4409
|
-
/*
|
|
6290
|
+
/* 13 */
|
|
4410
6291
|
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
4411
6292
|
|
|
4412
6293
|
__webpack_require__.r(__webpack_exports__);
|
|
@@ -4459,7 +6340,7 @@ function sanitizeUrl(url) {
|
|
|
4459
6340
|
|
|
4460
6341
|
|
|
4461
6342
|
/***/ }),
|
|
4462
|
-
/*
|
|
6343
|
+
/* 14 */
|
|
4463
6344
|
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
4464
6345
|
|
|
4465
6346
|
__webpack_require__.r(__webpack_exports__);
|
|
@@ -4741,7 +6622,7 @@ var createFinalization = function (target, finalizable) {
|
|
|
4741
6622
|
|
|
4742
6623
|
|
|
4743
6624
|
/***/ }),
|
|
4744
|
-
/*
|
|
6625
|
+
/* 15 */
|
|
4745
6626
|
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
4746
6627
|
|
|
4747
6628
|
__webpack_require__.r(__webpack_exports__);
|
|
@@ -4886,14 +6767,16 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
4886
6767
|
/* harmony export */ Rive: () => (/* binding */ Rive),
|
|
4887
6768
|
/* harmony export */ RiveEventType: () => (/* binding */ RiveEventType),
|
|
4888
6769
|
/* harmony export */ RiveFile: () => (/* binding */ RiveFile),
|
|
4889
|
-
/* harmony export */ RiveFont: () => (/* reexport safe */
|
|
6770
|
+
/* harmony export */ RiveFont: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_3__.RiveFont),
|
|
4890
6771
|
/* harmony export */ RuntimeLoader: () => (/* reexport safe */ _runtimeLoader__WEBPACK_IMPORTED_MODULE_1__.RuntimeLoader),
|
|
6772
|
+
/* harmony export */ SemanticMode: () => (/* reexport safe */ _semantics__WEBPACK_IMPORTED_MODULE_2__.SemanticMode),
|
|
4891
6773
|
/* harmony export */ StateMachineInput: () => (/* binding */ StateMachineInput),
|
|
4892
6774
|
/* harmony export */ StateMachineInputType: () => (/* binding */ StateMachineInputType),
|
|
4893
6775
|
/* harmony export */ Testing: () => (/* binding */ Testing),
|
|
4894
6776
|
/* harmony export */ ViewModel: () => (/* binding */ ViewModel),
|
|
4895
6777
|
/* harmony export */ ViewModelInstance: () => (/* binding */ ViewModelInstance),
|
|
4896
6778
|
/* harmony export */ ViewModelInstanceArtboard: () => (/* binding */ ViewModelInstanceArtboard),
|
|
6779
|
+
/* harmony export */ ViewModelInstanceAssetFont: () => (/* binding */ ViewModelInstanceAssetFont),
|
|
4897
6780
|
/* harmony export */ ViewModelInstanceAssetImage: () => (/* binding */ ViewModelInstanceAssetImage),
|
|
4898
6781
|
/* harmony export */ ViewModelInstanceBoolean: () => (/* binding */ ViewModelInstanceBoolean),
|
|
4899
6782
|
/* harmony export */ ViewModelInstanceColor: () => (/* binding */ ViewModelInstanceColor),
|
|
@@ -4909,7 +6792,8 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
4909
6792
|
/* harmony export */ });
|
|
4910
6793
|
/* harmony import */ var _animation__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
|
|
4911
6794
|
/* harmony import */ var _runtimeLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3);
|
|
4912
|
-
/* harmony import */ var
|
|
6795
|
+
/* harmony import */ var _semantics__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6);
|
|
6796
|
+
/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(10);
|
|
4913
6797
|
var __extends = (undefined && undefined.__extends) || (function () {
|
|
4914
6798
|
var extendStatics = function (d, b) {
|
|
4915
6799
|
extendStatics = Object.setPrototypeOf ||
|
|
@@ -4984,6 +6868,7 @@ var __spreadArray = (undefined && undefined.__spreadArray) || function (to, from
|
|
|
4984
6868
|
|
|
4985
6869
|
|
|
4986
6870
|
|
|
6871
|
+
|
|
4987
6872
|
var RiveError = /** @class */ (function (_super) {
|
|
4988
6873
|
__extends(RiveError, _super);
|
|
4989
6874
|
function RiveError() {
|
|
@@ -4994,6 +6879,7 @@ var RiveError = /** @class */ (function (_super) {
|
|
|
4994
6879
|
return RiveError;
|
|
4995
6880
|
}(Error));
|
|
4996
6881
|
|
|
6882
|
+
|
|
4997
6883
|
// #regions helpers
|
|
4998
6884
|
var resolveErrorMessage = function (error) {
|
|
4999
6885
|
return error && error.isHandledError
|
|
@@ -5242,8 +7128,17 @@ var StateMachine = /** @class */ (function () {
|
|
|
5242
7128
|
this.inputs = [];
|
|
5243
7129
|
this.instance = new runtime.StateMachineInstance(stateMachine, artboard);
|
|
5244
7130
|
this.initInputs(runtime);
|
|
5245
|
-
this.hasFocusNodes = this.instance.hasFocusNodes();
|
|
5246
7131
|
}
|
|
7132
|
+
Object.defineProperty(StateMachine.prototype, "hasFocusNodes", {
|
|
7133
|
+
/**
|
|
7134
|
+
* Whether this state machine has focus nodes
|
|
7135
|
+
*/
|
|
7136
|
+
get: function () {
|
|
7137
|
+
return this.instance.hasFocusNodes();
|
|
7138
|
+
},
|
|
7139
|
+
enumerable: false,
|
|
7140
|
+
configurable: true
|
|
7141
|
+
});
|
|
5247
7142
|
Object.defineProperty(StateMachine.prototype, "name", {
|
|
5248
7143
|
get: function () {
|
|
5249
7144
|
return this.stateMachine.name;
|
|
@@ -5279,6 +7174,37 @@ var StateMachine = /** @class */ (function () {
|
|
|
5279
7174
|
StateMachine.prototype.advanceAndApply = function (time) {
|
|
5280
7175
|
this.instance.advanceAndApply(time);
|
|
5281
7176
|
};
|
|
7177
|
+
/**
|
|
7178
|
+
* Enables semantic tree tracking for this state machine instance.
|
|
7179
|
+
*/
|
|
7180
|
+
StateMachine.prototype.enableSemantics = function () {
|
|
7181
|
+
this.instance.enableSemantics();
|
|
7182
|
+
};
|
|
7183
|
+
/**
|
|
7184
|
+
* Returns the incremental semantic diff since the last call, or null
|
|
7185
|
+
* if semantics is not enabled or nothing changed.
|
|
7186
|
+
*/
|
|
7187
|
+
StateMachine.prototype.drainSemanticsDiff = function () {
|
|
7188
|
+
return this.instance.drainSemanticsDiff();
|
|
7189
|
+
};
|
|
7190
|
+
/**
|
|
7191
|
+
* Fire a semantic action (tap, increase, decrease) on a node.
|
|
7192
|
+
* @param nodeId - The semantic node ID to target
|
|
7193
|
+
* @param actionType - 0 = tap, 1 = increase, 2 = decrease
|
|
7194
|
+
*/
|
|
7195
|
+
StateMachine.prototype.fireSemanticAction = function (nodeId, actionType) {
|
|
7196
|
+
this.instance.fireSemanticAction(nodeId, actionType);
|
|
7197
|
+
};
|
|
7198
|
+
/**
|
|
7199
|
+
* When tools that enable accessible experiences traverse elements with focus,
|
|
7200
|
+
* we should call this method to focus the semantic node. It will also trigger
|
|
7201
|
+
* focus on any Focus listeners for this node
|
|
7202
|
+
* @param nodeId ID of the Semantic Node to focus
|
|
7203
|
+
* @returns boolean - True if focus was set, false otherwise
|
|
7204
|
+
*/
|
|
7205
|
+
StateMachine.prototype.focusSemanticNode = function (nodeId) {
|
|
7206
|
+
return this.instance.focusSemanticNode(nodeId);
|
|
7207
|
+
};
|
|
5282
7208
|
/**
|
|
5283
7209
|
* Returns the number of events reported from the last advance call
|
|
5284
7210
|
* @returns Number of events reported
|
|
@@ -5383,8 +7309,9 @@ var Animator = /** @class */ (function () {
|
|
|
5383
7309
|
* @param animatable the name(s) of animations and state machines to add
|
|
5384
7310
|
* @returns a list of names of the playing animations and state machines
|
|
5385
7311
|
*/
|
|
5386
|
-
Animator.prototype.add = function (animatables, playing, fireEvent) {
|
|
7312
|
+
Animator.prototype.add = function (animatables, playing, fireEvent, semanticsActive) {
|
|
5387
7313
|
if (fireEvent === void 0) { fireEvent = true; }
|
|
7314
|
+
if (semanticsActive === void 0) { semanticsActive = false; }
|
|
5388
7315
|
animatables = mapToStringArray(animatables);
|
|
5389
7316
|
// If animatables is empty, play or pause everything
|
|
5390
7317
|
if (animatables.length === 0) {
|
|
@@ -5423,6 +7350,9 @@ var Animator = /** @class */ (function () {
|
|
|
5423
7350
|
var sm = this.artboard.stateMachineByName(animatables[i]);
|
|
5424
7351
|
if (sm) {
|
|
5425
7352
|
var newStateMachine = new StateMachine(sm, this.runtime, playing, this.artboard);
|
|
7353
|
+
if (semanticsActive) {
|
|
7354
|
+
newStateMachine.enableSemantics();
|
|
7355
|
+
}
|
|
5426
7356
|
this.stateMachines.push(newStateMachine);
|
|
5427
7357
|
}
|
|
5428
7358
|
}
|
|
@@ -5488,7 +7418,7 @@ var Animator = /** @class */ (function () {
|
|
|
5488
7418
|
* @param animatables the name(s) of state machines to add
|
|
5489
7419
|
* @param playing whether state machines should play on instantiation
|
|
5490
7420
|
*/
|
|
5491
|
-
Animator.prototype.initStateMachines = function (animatables, playing) {
|
|
7421
|
+
Animator.prototype.initStateMachines = function (animatables, playing, semanticsActive) {
|
|
5492
7422
|
// Play/pause already instanced items, or create new instances
|
|
5493
7423
|
// This validation is kept to maintain compatibility with current behavior.
|
|
5494
7424
|
// But given that it this is called during artboard initialization
|
|
@@ -5504,6 +7434,9 @@ var Animator = /** @class */ (function () {
|
|
|
5504
7434
|
var sm = this.artboard.stateMachineByName(animatables[i]);
|
|
5505
7435
|
if (sm) {
|
|
5506
7436
|
var newStateMachine = new StateMachine(sm, this.runtime, playing, this.artboard);
|
|
7437
|
+
if (semanticsActive) {
|
|
7438
|
+
newStateMachine.enableSemantics();
|
|
7439
|
+
}
|
|
5507
7440
|
this.stateMachines.push(newStateMachine);
|
|
5508
7441
|
}
|
|
5509
7442
|
else {
|
|
@@ -5669,8 +7602,9 @@ var Animator = /** @class */ (function () {
|
|
|
5669
7602
|
* If there are no animations or state machines, add the first one found
|
|
5670
7603
|
* @returns the name of the animation or state machine instanced
|
|
5671
7604
|
*/
|
|
5672
|
-
Animator.prototype.atLeastOne = function (playing, fireEvent) {
|
|
7605
|
+
Animator.prototype.atLeastOne = function (playing, fireEvent, semanticsActive) {
|
|
5673
7606
|
if (fireEvent === void 0) { fireEvent = true; }
|
|
7607
|
+
if (semanticsActive === void 0) { semanticsActive = false; }
|
|
5674
7608
|
var instancedName;
|
|
5675
7609
|
if (this.animations.length === 0 && this.stateMachines.length === 0) {
|
|
5676
7610
|
if (this.artboard.animationCount() > 0) {
|
|
@@ -5679,7 +7613,7 @@ var Animator = /** @class */ (function () {
|
|
|
5679
7613
|
}
|
|
5680
7614
|
else if (this.artboard.stateMachineCount() > 0) {
|
|
5681
7615
|
// Add the first state machine
|
|
5682
|
-
this.add([(instancedName = this.artboard.stateMachineByIndex(0).name)], playing, fireEvent);
|
|
7616
|
+
this.add([(instancedName = this.artboard.stateMachineByIndex(0).name)], playing, fireEvent, semanticsActive);
|
|
5683
7617
|
}
|
|
5684
7618
|
}
|
|
5685
7619
|
return instancedName;
|
|
@@ -6071,6 +8005,9 @@ var ObjectObservers = /** @class */ (function () {
|
|
|
6071
8005
|
return ObjectObservers;
|
|
6072
8006
|
}());
|
|
6073
8007
|
var observers = new ObjectObservers();
|
|
8008
|
+
// #endregion
|
|
8009
|
+
// #region Rive
|
|
8010
|
+
var nextRiveInstanceId = 0;
|
|
6074
8011
|
var RiveFile = /** @class */ (function () {
|
|
6075
8012
|
function RiveFile(params) {
|
|
6076
8013
|
// Allow the runtime to automatically load assets hosted in Rive's runtime.
|
|
@@ -6137,7 +8074,7 @@ var RiveFile = /** @class */ (function () {
|
|
|
6137
8074
|
return [2 /*return*/];
|
|
6138
8075
|
}
|
|
6139
8076
|
if (this.assetLoader) {
|
|
6140
|
-
loaderWrapper = new
|
|
8077
|
+
loaderWrapper = new _utils__WEBPACK_IMPORTED_MODULE_3__.CustomFileAssetLoaderWrapper(this.runtime, this.assetLoader);
|
|
6141
8078
|
loader = loaderWrapper.assetLoader;
|
|
6142
8079
|
}
|
|
6143
8080
|
// Load the Rive file
|
|
@@ -6151,8 +8088,8 @@ var RiveFile = /** @class */ (function () {
|
|
|
6151
8088
|
performance.mark('rive:file-load:end');
|
|
6152
8089
|
performance.measure('rive:file-load', 'rive:file-load:start', 'rive:file-load:end');
|
|
6153
8090
|
}
|
|
6154
|
-
fileFinalizer = new
|
|
6155
|
-
|
|
8091
|
+
fileFinalizer = new _utils__WEBPACK_IMPORTED_MODULE_3__.FileFinalizer(this.file);
|
|
8092
|
+
_utils__WEBPACK_IMPORTED_MODULE_3__.finalizationRegistry.register(this, fileFinalizer);
|
|
6156
8093
|
if (this.destroyed) {
|
|
6157
8094
|
this.releaseFile();
|
|
6158
8095
|
return [2 /*return*/];
|
|
@@ -6310,7 +8247,7 @@ var RiveFile = /** @class */ (function () {
|
|
|
6310
8247
|
RiveFile.prototype.createBindableArtboard = function (nativeBindableArtboard) {
|
|
6311
8248
|
if (nativeBindableArtboard != null) {
|
|
6312
8249
|
var bindableArtboard = new BindableArtboard(nativeBindableArtboard);
|
|
6313
|
-
(0,
|
|
8250
|
+
(0,_utils__WEBPACK_IMPORTED_MODULE_3__.createFinalization)(bindableArtboard, bindableArtboard.nativeArtboard);
|
|
6314
8251
|
this.bindableArtboards.push(bindableArtboard);
|
|
6315
8252
|
return bindableArtboard;
|
|
6316
8253
|
}
|
|
@@ -6347,6 +8284,12 @@ var RiveFile = /** @class */ (function () {
|
|
|
6347
8284
|
}
|
|
6348
8285
|
return null;
|
|
6349
8286
|
};
|
|
8287
|
+
/**
|
|
8288
|
+
* @returns the names of the file's global view models, in file order.
|
|
8289
|
+
*/
|
|
8290
|
+
RiveFile.prototype.globalViewModelNames = function () {
|
|
8291
|
+
return this.file.globalViewModelNames();
|
|
8292
|
+
};
|
|
6350
8293
|
// Error message for missing source or buffer
|
|
6351
8294
|
RiveFile.missingErrorMessage = "Rive source file or data buffer required";
|
|
6352
8295
|
// Error message for file load error
|
|
@@ -6357,7 +8300,7 @@ var RiveFile = /** @class */ (function () {
|
|
|
6357
8300
|
var Rive = /** @class */ (function () {
|
|
6358
8301
|
function Rive(params) {
|
|
6359
8302
|
var _this = this;
|
|
6360
|
-
var _a, _b, _c;
|
|
8303
|
+
var _a, _b, _c, _d;
|
|
6361
8304
|
// Tracks if a Rive file is loaded
|
|
6362
8305
|
this.loaded = false;
|
|
6363
8306
|
// Tracks if a Rive file is destroyed
|
|
@@ -6385,6 +8328,12 @@ var Rive = /** @class */ (function () {
|
|
|
6385
8328
|
this.enableMultiTouch = false;
|
|
6386
8329
|
// Allow the runtime to automatically load assets hosted in Rive's runtime.
|
|
6387
8330
|
this.enableRiveAssetCDN = true;
|
|
8331
|
+
this.semanticsMode = _semantics__WEBPACK_IMPORTED_MODULE_2__.SemanticMode.Disabled;
|
|
8332
|
+
this.semanticsOptions = {
|
|
8333
|
+
riveCanvasLabel: "Rive animation",
|
|
8334
|
+
};
|
|
8335
|
+
/** True when this instance may drain semantics and render the overlay. */
|
|
8336
|
+
this._semanticsActive = false;
|
|
6388
8337
|
// Keep a local value of the set volume to update it asynchronously
|
|
6389
8338
|
this._volume = 1;
|
|
6390
8339
|
// Keep a local value of the set width to update it asynchronously
|
|
@@ -6413,12 +8362,29 @@ var Rive = /** @class */ (function () {
|
|
|
6413
8362
|
// visibilitychange handler from restarting a rendering loop the caller intentionally stopped.
|
|
6414
8363
|
this._explicitlyStoppedRendering = false;
|
|
6415
8364
|
this._viewModelInstance = null;
|
|
8365
|
+
// User-provided global view model instances, keyed by their global view
|
|
8366
|
+
// model's name. Globals not present here are still driven by the default
|
|
8367
|
+
// instances the runtime seeds; the getter only surfaces instances the user
|
|
8368
|
+
// has explicitly set.
|
|
8369
|
+
this._globalViewModelInstances = new Map();
|
|
6416
8370
|
this._dataEnums = null;
|
|
6417
8371
|
this._tabIndex = null;
|
|
6418
8372
|
this._prevHasFocus = false;
|
|
6419
8373
|
this._focusOptions = {
|
|
6420
8374
|
allowFocusInterrupt: false,
|
|
6421
8375
|
};
|
|
8376
|
+
// Tracks the semantic tree for the given graphic
|
|
8377
|
+
this._semanticTree = null;
|
|
8378
|
+
this._accessibilityOverlay = null;
|
|
8379
|
+
/**
|
|
8380
|
+
* True when an input to the accessibility overlay's artboard→canvas transform
|
|
8381
|
+
* (layout fit/alignment/bounds, devicePixelRatio, or layout scale) has changed
|
|
8382
|
+
* and the matrix must be recomputed on the next overlay update. Avoids calling
|
|
8383
|
+
* computeAlignment every frame when only the semantic tree changed.
|
|
8384
|
+
*/
|
|
8385
|
+
this._overlayTransformDirty = true;
|
|
8386
|
+
// Module-level counter for unique instance IDs for semantic overlay containers
|
|
8387
|
+
this._instanceId = "".concat(nextRiveInstanceId++);
|
|
6422
8388
|
this.drawOptimization = DrawOptimizationOptions.DrawOnChanged;
|
|
6423
8389
|
// When true, emits performance.mark/measure entries for load and render.
|
|
6424
8390
|
this.enablePerfMarks = false;
|
|
@@ -6478,6 +8444,7 @@ var Rive = /** @class */ (function () {
|
|
|
6478
8444
|
if (this.enablePerfMarks)
|
|
6479
8445
|
_runtimeLoader__WEBPACK_IMPORTED_MODULE_1__.RuntimeLoader.enablePerfMarks = true;
|
|
6480
8446
|
this._focusOptions = (_c = params.focusOptions) !== null && _c !== void 0 ? _c : this._focusOptions;
|
|
8447
|
+
this._tabIndex = (_d = params.tabIndex) !== null && _d !== void 0 ? _d : null;
|
|
6481
8448
|
// New event management system
|
|
6482
8449
|
this.eventManager = new EventManager();
|
|
6483
8450
|
if (params.onLoad)
|
|
@@ -6531,6 +8498,8 @@ var Rive = /** @class */ (function () {
|
|
|
6531
8498
|
artboard: params.artboard,
|
|
6532
8499
|
useOffscreenRenderer: params.useOffscreenRenderer,
|
|
6533
8500
|
tabIndex: params.tabIndex,
|
|
8501
|
+
semanticsMode: params.semanticsMode,
|
|
8502
|
+
semanticsOptions: params.semanticsOptions,
|
|
6534
8503
|
});
|
|
6535
8504
|
}
|
|
6536
8505
|
Object.defineProperty(Rive.prototype, "viewModelCount", {
|
|
@@ -6545,6 +8514,44 @@ var Rive = /** @class */ (function () {
|
|
|
6545
8514
|
console.warn("This function is deprecated: please use `new Rive({})` instead");
|
|
6546
8515
|
return new Rive(params);
|
|
6547
8516
|
};
|
|
8517
|
+
/**
|
|
8518
|
+
* @experimental Turns on semantics and the accessibility overlay for this
|
|
8519
|
+
* instance. Idempotent; safe to call before or after load. Use this to drive
|
|
8520
|
+
* a consumer-controlled accessibility toggle when constructed with the
|
|
8521
|
+
* default {@link SemanticMode.Disabled}.
|
|
8522
|
+
*/
|
|
8523
|
+
Rive.prototype.enableSemantics = function () {
|
|
8524
|
+
this.semanticsMode = _semantics__WEBPACK_IMPORTED_MODULE_2__.SemanticMode.Enabled;
|
|
8525
|
+
this.activateSemantics();
|
|
8526
|
+
};
|
|
8527
|
+
Rive.prototype.activateSemantics = function () {
|
|
8528
|
+
if (this._semanticsActive || this.semanticsMode === _semantics__WEBPACK_IMPORTED_MODULE_2__.SemanticMode.Disabled) {
|
|
8529
|
+
return;
|
|
8530
|
+
}
|
|
8531
|
+
this._semanticsActive = true;
|
|
8532
|
+
this.syncSemanticsOnStateMachines();
|
|
8533
|
+
};
|
|
8534
|
+
Rive.prototype.syncSemanticsOnStateMachines = function () {
|
|
8535
|
+
if (!this._semanticsActive || !this.animator) {
|
|
8536
|
+
return;
|
|
8537
|
+
}
|
|
8538
|
+
for (var _i = 0, _a = this.animator.stateMachines; _i < _a.length; _i++) {
|
|
8539
|
+
var stateMachine = _a[_i];
|
|
8540
|
+
stateMachine.enableSemantics();
|
|
8541
|
+
}
|
|
8542
|
+
};
|
|
8543
|
+
/**
|
|
8544
|
+
* Tears down the semantic tree and accessibility overlay. The overlay captures the
|
|
8545
|
+
* active state machine in its action closures, so it must not outlive the
|
|
8546
|
+
* instances it points at (reset/load delete them)
|
|
8547
|
+
*/
|
|
8548
|
+
Rive.prototype.cleanupSemantics = function () {
|
|
8549
|
+
this._semanticTree = null;
|
|
8550
|
+
if (this._accessibilityOverlay) {
|
|
8551
|
+
this._accessibilityOverlay.destroy();
|
|
8552
|
+
this._accessibilityOverlay = null;
|
|
8553
|
+
}
|
|
8554
|
+
};
|
|
6548
8555
|
// Event handler for when audio context becomes available
|
|
6549
8556
|
Rive.prototype.onSystemAudioChanged = function () {
|
|
6550
8557
|
this.volume = this._volume;
|
|
@@ -6552,7 +8559,7 @@ var Rive = /** @class */ (function () {
|
|
|
6552
8559
|
// Initializes the Rive object either from constructor or load()
|
|
6553
8560
|
Rive.prototype.init = function (_a) {
|
|
6554
8561
|
var _this = this;
|
|
6555
|
-
var src = _a.src, buffer = _a.buffer, riveFile = _a.riveFile, animations = _a.animations, stateMachines = _a.stateMachines, artboard = _a.artboard, _b = _a.autoplay, autoplay = _b === void 0 ? false : _b, _c = _a.useOffscreenRenderer, useOffscreenRenderer = _c === void 0 ? false : _c, _d = _a.autoBind, autoBind = _d === void 0 ? false : _d, tabIndex = _a.tabIndex;
|
|
8562
|
+
var src = _a.src, buffer = _a.buffer, riveFile = _a.riveFile, animations = _a.animations, stateMachines = _a.stateMachines, artboard = _a.artboard, _b = _a.autoplay, autoplay = _b === void 0 ? false : _b, _c = _a.useOffscreenRenderer, useOffscreenRenderer = _c === void 0 ? false : _c, _d = _a.autoBind, autoBind = _d === void 0 ? false : _d, tabIndex = _a.tabIndex, semanticsMode = _a.semanticsMode, semanticsOptions = _a.semanticsOptions;
|
|
6556
8563
|
if (this.destroyed) {
|
|
6557
8564
|
return;
|
|
6558
8565
|
}
|
|
@@ -6560,6 +8567,8 @@ var Rive = /** @class */ (function () {
|
|
|
6560
8567
|
this.buffer = buffer;
|
|
6561
8568
|
this.riveFile = riveFile;
|
|
6562
8569
|
this._tabIndex = tabIndex !== null && tabIndex !== void 0 ? tabIndex : null;
|
|
8570
|
+
this.semanticsMode = semanticsMode !== null && semanticsMode !== void 0 ? semanticsMode : _semantics__WEBPACK_IMPORTED_MODULE_2__.SemanticMode.Disabled;
|
|
8571
|
+
this.semanticsOptions = semanticsOptions !== null && semanticsOptions !== void 0 ? semanticsOptions : this.semanticsOptions;
|
|
6563
8572
|
// If no source file url specified, it's a bust
|
|
6564
8573
|
if (!this.src && !this.buffer && !this.riveFile) {
|
|
6565
8574
|
throw new RiveError(Rive.missingErrorMessage);
|
|
@@ -6579,6 +8588,9 @@ var Rive = /** @class */ (function () {
|
|
|
6579
8588
|
}
|
|
6580
8589
|
_this.runtime = runtime;
|
|
6581
8590
|
_this.removeRiveListeners();
|
|
8591
|
+
// load() reinitializes without cleanupInstances(); drop any stale overlay
|
|
8592
|
+
// bound to the previous file's state machines (no-op on first construct).
|
|
8593
|
+
_this.cleanupSemantics();
|
|
6582
8594
|
_this.deleteRiveRenderer();
|
|
6583
8595
|
// Get the canvas where you want to render the animation and create a renderer
|
|
6584
8596
|
if (_this.enablePerfMarks)
|
|
@@ -6643,7 +8655,7 @@ var Rive = /** @class */ (function () {
|
|
|
6643
8655
|
"isTouchScrollEnabled" in riveListenerOptions) {
|
|
6644
8656
|
touchScrollEnabledOption = riveListenerOptions.isTouchScrollEnabled;
|
|
6645
8657
|
}
|
|
6646
|
-
this.eventCleanup = (0,
|
|
8658
|
+
this.eventCleanup = (0,_utils__WEBPACK_IMPORTED_MODULE_3__.registerTouchInteractions)({
|
|
6647
8659
|
canvas: this.canvas,
|
|
6648
8660
|
artboard: this.artboard,
|
|
6649
8661
|
stateMachines: activeStateMachines,
|
|
@@ -6657,28 +8669,36 @@ var Rive = /** @class */ (function () {
|
|
|
6657
8669
|
layoutScaleFactor: this._layout.layoutScaleFactor,
|
|
6658
8670
|
advanceAndDrain: this.advanceAndReportChanges.bind(this)
|
|
6659
8671
|
});
|
|
6660
|
-
|
|
6661
|
-
// hasFocusNodes — unified focus tree check, gates tab traversal
|
|
6662
|
-
var smWithFocusNodes = playingStateMachines.filter(function (sm) { return sm.hasFocusNodes; });
|
|
6663
|
-
if (smWithFocusNodes.length) {
|
|
6664
|
-
// Set the canvas as a tabbable element if there are any focus nodes.
|
|
6665
|
-
// Prefer the tabIndex param set by the user, otherwise use 0.
|
|
6666
|
-
// But do not override any explicit tabIndex already set on the canvas, if any.
|
|
6667
|
-
var currentCanvasTabIndex = this.canvas.tabIndex;
|
|
6668
|
-
// By default, canvas elements have a tabIndex of -1
|
|
6669
|
-
if (currentCanvasTabIndex === -1 || isNaN(currentCanvasTabIndex)) {
|
|
6670
|
-
this.canvas.tabIndex = (this._tabIndex !== null ? this._tabIndex : 0);
|
|
6671
|
-
}
|
|
6672
|
-
if (typeof window !== "undefined") {
|
|
6673
|
-
this._keyboardInteractions = new _utils__WEBPACK_IMPORTED_MODULE_2__.KeyboardInteractions({
|
|
6674
|
-
canvas: this.canvas,
|
|
6675
|
-
stateMachine: smWithFocusNodes[0].instance, // work off assumption of single state machine
|
|
6676
|
-
hasFocusNodes: true,
|
|
6677
|
-
});
|
|
6678
|
-
}
|
|
6679
|
-
}
|
|
8672
|
+
this.ensureKeyboardInteractions();
|
|
6680
8673
|
}
|
|
6681
8674
|
};
|
|
8675
|
+
/**
|
|
8676
|
+
* Wire keyboard interactions when a playing state machine has focus nodes.
|
|
8677
|
+
* Called at listener setup and lazily each frame so late-bound bindable artboards work.
|
|
8678
|
+
*/
|
|
8679
|
+
Rive.prototype.ensureKeyboardInteractions = function () {
|
|
8680
|
+
var _this = this;
|
|
8681
|
+
if (this._keyboardInteractions ||
|
|
8682
|
+
this.shouldDisableRiveListeners ||
|
|
8683
|
+
typeof window === "undefined" ||
|
|
8684
|
+
!(this.canvas instanceof HTMLCanvasElement)) {
|
|
8685
|
+
return;
|
|
8686
|
+
}
|
|
8687
|
+
var smWithFocusNodes = this.animator.stateMachines.find(function (sm) { return sm.playing && sm.hasFocusNodes; });
|
|
8688
|
+
if (!smWithFocusNodes) {
|
|
8689
|
+
return;
|
|
8690
|
+
}
|
|
8691
|
+
var currentCanvasTabIndex = this.canvas.tabIndex;
|
|
8692
|
+
if (currentCanvasTabIndex === -1 || isNaN(currentCanvasTabIndex)) {
|
|
8693
|
+
this.canvas.tabIndex = (this._tabIndex !== null ? this._tabIndex : 0);
|
|
8694
|
+
}
|
|
8695
|
+
this._keyboardInteractions = new _utils__WEBPACK_IMPORTED_MODULE_3__.KeyboardInteractions({
|
|
8696
|
+
canvas: this.canvas,
|
|
8697
|
+
stateMachine: smWithFocusNodes.instance, // work off assumption of single state machine
|
|
8698
|
+
hasFocusNodes: true,
|
|
8699
|
+
getOverlayElement: function () { var _a, _b; return (_b = (_a = _this._accessibilityOverlay) === null || _a === void 0 ? void 0 : _a.getSemanticOverlayContainer()) !== null && _b !== void 0 ? _b : null; },
|
|
8700
|
+
});
|
|
8701
|
+
};
|
|
6682
8702
|
Rive.prototype.cleanupKeyboardInteractions = function () {
|
|
6683
8703
|
if (this._keyboardInteractions) {
|
|
6684
8704
|
this._keyboardInteractions.cleanup();
|
|
@@ -6761,6 +8781,12 @@ var Rive = /** @class */ (function () {
|
|
|
6761
8781
|
this.initArtboardSize();
|
|
6762
8782
|
// Check for audio
|
|
6763
8783
|
this.initializeAudio();
|
|
8784
|
+
if (this.semanticsMode === _semantics__WEBPACK_IMPORTED_MODULE_2__.SemanticMode.Enabled) {
|
|
8785
|
+
this.activateSemantics();
|
|
8786
|
+
}
|
|
8787
|
+
else if (this._semanticsActive) {
|
|
8788
|
+
this.syncSemanticsOnStateMachines();
|
|
8789
|
+
}
|
|
6764
8790
|
// Everything's set up, emit a load event
|
|
6765
8791
|
try {
|
|
6766
8792
|
this.loaded = true;
|
|
@@ -6819,10 +8845,10 @@ var Rive = /** @class */ (function () {
|
|
|
6819
8845
|
if (animationNames.length > 0 || stateMachineNames.length > 0) {
|
|
6820
8846
|
instanceNames = animationNames.concat(stateMachineNames);
|
|
6821
8847
|
this.animator.initLinearAnimations(animationNames, autoplay);
|
|
6822
|
-
this.animator.initStateMachines(stateMachineNames, autoplay);
|
|
8848
|
+
this.animator.initStateMachines(stateMachineNames, autoplay, this._semanticsActive);
|
|
6823
8849
|
}
|
|
6824
8850
|
else {
|
|
6825
|
-
instanceNames = [this.animator.atLeastOne(autoplay, false)];
|
|
8851
|
+
instanceNames = [this.animator.atLeastOne(autoplay, false, this._semanticsActive)];
|
|
6826
8852
|
}
|
|
6827
8853
|
// Queue up firing the playback events
|
|
6828
8854
|
this.taskQueue.add({
|
|
@@ -6832,15 +8858,29 @@ var Rive = /** @class */ (function () {
|
|
|
6832
8858
|
},
|
|
6833
8859
|
});
|
|
6834
8860
|
if (autoBind) {
|
|
8861
|
+
// Set the main view model instance (if the artboard has one)...
|
|
6835
8862
|
var viewModel = this.file.defaultArtboardViewModel(rootArtboard);
|
|
6836
8863
|
if (viewModel !== null) {
|
|
6837
8864
|
var runtimeInstance = viewModel.defaultInstance();
|
|
6838
8865
|
if (runtimeInstance !== null) {
|
|
6839
8866
|
var viewModelInstance = new ViewModelInstance(runtimeInstance, null);
|
|
6840
|
-
(0,
|
|
6841
|
-
this.
|
|
8867
|
+
(0,_utils__WEBPACK_IMPORTED_MODULE_3__.createFinalization)(viewModelInstance, viewModelInstance.runtimeInstance);
|
|
8868
|
+
this.setViewModelInstance(viewModelInstance);
|
|
6842
8869
|
}
|
|
6843
8870
|
}
|
|
8871
|
+
// ...and a default instance for each global view model (no longer
|
|
8872
|
+
// auto-created by the runtime), then apply everything in one rebind.
|
|
8873
|
+
for (var _i = 0, _a = this.file.globalViewModelNames(); _i < _a.length; _i++) {
|
|
8874
|
+
var name_1 = _a[_i];
|
|
8875
|
+
var globalViewModel = this.file.viewModelByName(name_1);
|
|
8876
|
+
if (globalViewModel !== null) {
|
|
8877
|
+
var instance = new ViewModel(globalViewModel).defaultInstance();
|
|
8878
|
+
if (instance !== null) {
|
|
8879
|
+
this.setGlobalViewModelInstance(name_1, instance);
|
|
8880
|
+
}
|
|
8881
|
+
}
|
|
8882
|
+
}
|
|
8883
|
+
this.bind();
|
|
6844
8884
|
}
|
|
6845
8885
|
};
|
|
6846
8886
|
// Draws the current artboard frame
|
|
@@ -6875,6 +8915,8 @@ var Rive = /** @class */ (function () {
|
|
|
6875
8915
|
* Rive internally updated focus outside of user interaction (e.g., via listener action)
|
|
6876
8916
|
*/
|
|
6877
8917
|
Rive.prototype.pollFocusState = function () {
|
|
8918
|
+
var _a, _b;
|
|
8919
|
+
this.ensureKeyboardInteractions();
|
|
6878
8920
|
if (!this._keyboardInteractions) {
|
|
6879
8921
|
this._prevHasFocus = false;
|
|
6880
8922
|
return;
|
|
@@ -6893,7 +8935,16 @@ var Rive = /** @class */ (function () {
|
|
|
6893
8935
|
// Only steal DOM focus on the false→true transition. If hasFocus stays
|
|
6894
8936
|
// true across frames and the user clicks away, do not re-focus the canvas again.
|
|
6895
8937
|
if (!this._prevHasFocus) {
|
|
6896
|
-
|
|
8938
|
+
// Steal DOM focus to the canvas only when focus isn't already held
|
|
8939
|
+
// somewhere inside this instance's focus scope. When the accessibility
|
|
8940
|
+
// overlay has driven focus onto a specific semantic node element (e.g.
|
|
8941
|
+
// an appearing alert dialog), focus is already in-scope. The steal
|
|
8942
|
+
// stays a fallback for runtime focus nodes that have no overlay element
|
|
8943
|
+
// to hold DOM focus.
|
|
8944
|
+
var scope = (_a = this._accessibilityOverlay) === null || _a === void 0 ? void 0 : _a.getSemanticOverlayContainer();
|
|
8945
|
+
var focusAlreadyInScope = document.activeElement === this.canvas ||
|
|
8946
|
+
((_b = scope === null || scope === void 0 ? void 0 : scope.contains(document.activeElement)) !== null && _b !== void 0 ? _b : false);
|
|
8947
|
+
if (!focusAlreadyInScope && this._focusOptions.allowFocusInterrupt) {
|
|
6897
8948
|
this.canvas.focus();
|
|
6898
8949
|
}
|
|
6899
8950
|
this._prevHasFocus = true;
|
|
@@ -6905,8 +8956,8 @@ var Rive = /** @class */ (function () {
|
|
|
6905
8956
|
// (state change clears focus). Release the DOM Tab trap so the next Tab moves to the next
|
|
6906
8957
|
// page element. EntryPending and NotFocused cases are intentional no-ops — EntryPending in
|
|
6907
8958
|
// particular must stay in its state (a click awaiting its first Tab) rather than be reset here.
|
|
6908
|
-
if (this._keyboardInteractions.focusSessionState ===
|
|
6909
|
-
this._keyboardInteractions.setFocusSessionState(
|
|
8959
|
+
if (this._keyboardInteractions.focusSessionState === _utils__WEBPACK_IMPORTED_MODULE_3__.FocusSessionState.RiveFocused) {
|
|
8960
|
+
this._keyboardInteractions.setFocusSessionState(_utils__WEBPACK_IMPORTED_MODULE_3__.FocusSessionState.NotFocused);
|
|
6910
8961
|
}
|
|
6911
8962
|
}
|
|
6912
8963
|
};
|
|
@@ -6917,7 +8968,7 @@ var Rive = /** @class */ (function () {
|
|
|
6917
8968
|
* @param elapsedTime time to advance the state machine by
|
|
6918
8969
|
*/
|
|
6919
8970
|
Rive.prototype.advanceAndReportChanges = function (elapsedTime) {
|
|
6920
|
-
var _a;
|
|
8971
|
+
var _a, _b;
|
|
6921
8972
|
// - Advance non-paused animations by the elapsed number of seconds
|
|
6922
8973
|
// - Advance any animations that require scrubbing
|
|
6923
8974
|
// - Advance to the first frame even when autoplay is false
|
|
@@ -6940,8 +8991,8 @@ var Rive = /** @class */ (function () {
|
|
|
6940
8991
|
// Instrument the first 3 frames so the Performance timeline shows precise
|
|
6941
8992
|
// per-call latency for advance, draw, and flush without polluting the trace.
|
|
6942
8993
|
var _perfFrame = this.enablePerfMarks && this.frameCount < 3 ? this.frameCount : -1;
|
|
6943
|
-
for (var
|
|
6944
|
-
var stateMachine = activeStateMachines_1[
|
|
8994
|
+
for (var _c = 0, activeStateMachines_1 = activeStateMachines; _c < activeStateMachines_1.length; _c++) {
|
|
8995
|
+
var stateMachine = activeStateMachines_1[_c];
|
|
6945
8996
|
// Check for events before the current frame's state machine advance
|
|
6946
8997
|
var numEventsReported = stateMachine.reportedEventCount();
|
|
6947
8998
|
if (numEventsReported) {
|
|
@@ -6956,11 +9007,11 @@ var Rive = /** @class */ (function () {
|
|
|
6956
9007
|
// Handle the event side effect if explicitly enabled
|
|
6957
9008
|
if (this.automaticallyHandleEvents) {
|
|
6958
9009
|
var newAnchorTag = document.createElement("a");
|
|
6959
|
-
var
|
|
6960
|
-
var sanitizedUrl = (0,
|
|
9010
|
+
var _d = event_1, url = _d.url, target = _d.target;
|
|
9011
|
+
var sanitizedUrl = (0,_utils__WEBPACK_IMPORTED_MODULE_3__.sanitizeUrl)(url);
|
|
6961
9012
|
url && newAnchorTag.setAttribute("href", sanitizedUrl);
|
|
6962
9013
|
target && newAnchorTag.setAttribute("target", target);
|
|
6963
|
-
if (sanitizedUrl && sanitizedUrl !==
|
|
9014
|
+
if (sanitizedUrl && sanitizedUrl !== _utils__WEBPACK_IMPORTED_MODULE_3__.BLANK_URL) {
|
|
6964
9015
|
newAnchorTag.click();
|
|
6965
9016
|
}
|
|
6966
9017
|
}
|
|
@@ -6981,6 +9032,61 @@ var Rive = /** @class */ (function () {
|
|
|
6981
9032
|
performance.mark("rive:sm-advance:end:f".concat(_perfFrame));
|
|
6982
9033
|
performance.measure("rive:sm-advance:f".concat(_perfFrame), "rive:sm-advance:start:f".concat(_perfFrame), "rive:sm-advance:end:f".concat(_perfFrame));
|
|
6983
9034
|
}
|
|
9035
|
+
if (this._semanticsActive) {
|
|
9036
|
+
var diff = stateMachine.drainSemanticsDiff();
|
|
9037
|
+
if (diff) {
|
|
9038
|
+
if (!this._semanticTree) {
|
|
9039
|
+
this._semanticTree = new _semantics__WEBPACK_IMPORTED_MODULE_2__.SemanticTreeModel();
|
|
9040
|
+
}
|
|
9041
|
+
this._semanticTree.applyDiff(diff);
|
|
9042
|
+
}
|
|
9043
|
+
}
|
|
9044
|
+
}
|
|
9045
|
+
// Update the accessibility overlay after all state machines have
|
|
9046
|
+
// been advanced and their diffs applied to the tree model.
|
|
9047
|
+
if (this._semanticsActive &&
|
|
9048
|
+
this._semanticTree &&
|
|
9049
|
+
activeStateMachines.length > 0 &&
|
|
9050
|
+
this.canvas instanceof HTMLCanvasElement) {
|
|
9051
|
+
if (!this._accessibilityOverlay) {
|
|
9052
|
+
var mainSm_1 = activeStateMachines[0];
|
|
9053
|
+
this._accessibilityOverlay = new _semantics__WEBPACK_IMPORTED_MODULE_2__.AccessibilityOverlay({
|
|
9054
|
+
canvas: this.canvas,
|
|
9055
|
+
instanceId: this._instanceId,
|
|
9056
|
+
semanticsOptions: this.semanticsOptions,
|
|
9057
|
+
allowFocusInterrupt: this._focusOptions.allowFocusInterrupt,
|
|
9058
|
+
fireAction: function (nodeId, actionType) {
|
|
9059
|
+
mainSm_1.fireSemanticAction(nodeId, actionType);
|
|
9060
|
+
},
|
|
9061
|
+
requestFocus: function (nodeId) {
|
|
9062
|
+
return mainSm_1.focusSemanticNode(nodeId);
|
|
9063
|
+
},
|
|
9064
|
+
clearFocus: function () {
|
|
9065
|
+
return mainSm_1.instance.clearFocus();
|
|
9066
|
+
},
|
|
9067
|
+
});
|
|
9068
|
+
}
|
|
9069
|
+
var overlayChange = (_a = this._accessibilityOverlay) === null || _a === void 0 ? void 0 : _a.needsUpdate(this._semanticTree);
|
|
9070
|
+
if (overlayChange || this._overlayTransformDirty) {
|
|
9071
|
+
// Only recompute the artboard→canvas transform when something that
|
|
9072
|
+
// affects it changed (canvas geometry or a layout/dpr input). When only
|
|
9073
|
+
// the semantic tree changed we pass null and reuse the existing CSS
|
|
9074
|
+
// transform on the overlay container.
|
|
9075
|
+
var forwardMat = null;
|
|
9076
|
+
if ((overlayChange === null || overlayChange === void 0 ? void 0 : overlayChange.layoutChanged) || this._overlayTransformDirty) {
|
|
9077
|
+
var fit_1 = this._layout.runtimeFit(this.runtime);
|
|
9078
|
+
var alignment = this._layout.runtimeAlignment(this.runtime);
|
|
9079
|
+
forwardMat = this.runtime.computeAlignment(fit_1, alignment, {
|
|
9080
|
+
minX: this._layout.minX,
|
|
9081
|
+
minY: this._layout.minY,
|
|
9082
|
+
maxX: this._layout.maxX,
|
|
9083
|
+
maxY: this._layout.maxY,
|
|
9084
|
+
}, this.artboard.bounds, this._devicePixelRatioUsed * this._layout.layoutScaleFactor);
|
|
9085
|
+
this._overlayTransformDirty = false;
|
|
9086
|
+
}
|
|
9087
|
+
this._accessibilityOverlay.update(this._semanticTree, forwardMat, this._devicePixelRatioUsed, this.artboard.bounds, overlayChange);
|
|
9088
|
+
forwardMat === null || forwardMat === void 0 ? void 0 : forwardMat.delete();
|
|
9089
|
+
}
|
|
6984
9090
|
}
|
|
6985
9091
|
// For linear animations that have been applied to the artboard, advance it
|
|
6986
9092
|
// by the elapsed time.
|
|
@@ -6996,7 +9102,7 @@ var Rive = /** @class */ (function () {
|
|
|
6996
9102
|
// Poll focus state to see whether or not to blur or pull up a virtual keyboard for any change to a text input node.
|
|
6997
9103
|
this.pollFocusState();
|
|
6998
9104
|
// Handle callbacks for view model property changes
|
|
6999
|
-
(
|
|
9105
|
+
(_b = this._viewModelInstance) === null || _b === void 0 ? void 0 : _b.handleCallbacks();
|
|
7000
9106
|
};
|
|
7001
9107
|
/**
|
|
7002
9108
|
* Draw rendering loop; renders animation frames at the correct time interval.
|
|
@@ -7158,6 +9264,8 @@ var Rive = /** @class */ (function () {
|
|
|
7158
9264
|
}
|
|
7159
9265
|
(_d = this._viewModelInstance) === null || _d === void 0 ? void 0 : _d.cleanup();
|
|
7160
9266
|
this._viewModelInstance = null;
|
|
9267
|
+
this._globalViewModelInstances.forEach(function (instance) { return instance.cleanup(); });
|
|
9268
|
+
this._globalViewModelInstances.clear();
|
|
7161
9269
|
this._dataEnums = null;
|
|
7162
9270
|
};
|
|
7163
9271
|
/**
|
|
@@ -7181,6 +9289,9 @@ var Rive = /** @class */ (function () {
|
|
|
7181
9289
|
this.eventCleanup();
|
|
7182
9290
|
}
|
|
7183
9291
|
this.cleanupKeyboardInteractions();
|
|
9292
|
+
// Tear down semantics before deleting state machines — the overlay's action
|
|
9293
|
+
// closures point at instances that stop() is about to free.
|
|
9294
|
+
this.cleanupSemantics();
|
|
7184
9295
|
// Delete all animation and state machine instances
|
|
7185
9296
|
this.stop();
|
|
7186
9297
|
if (this.artboard) {
|
|
@@ -7246,6 +9357,7 @@ var Rive = /** @class */ (function () {
|
|
|
7246
9357
|
return;
|
|
7247
9358
|
}
|
|
7248
9359
|
this.animator.play(animationNames);
|
|
9360
|
+
this.syncSemanticsOnStateMachines();
|
|
7249
9361
|
if (this.eventCleanup) {
|
|
7250
9362
|
this.eventCleanup();
|
|
7251
9363
|
}
|
|
@@ -7304,6 +9416,7 @@ var Rive = /** @class */ (function () {
|
|
|
7304
9416
|
this.eventCleanup();
|
|
7305
9417
|
}
|
|
7306
9418
|
this.cleanupKeyboardInteractions();
|
|
9419
|
+
this.cleanupSemantics();
|
|
7307
9420
|
};
|
|
7308
9421
|
/**
|
|
7309
9422
|
* Resets the animation
|
|
@@ -7347,6 +9460,8 @@ var Rive = /** @class */ (function () {
|
|
|
7347
9460
|
// Sets a new layout
|
|
7348
9461
|
set: function (layout) {
|
|
7349
9462
|
this._layout = layout;
|
|
9463
|
+
// Fit/alignment/bounds feed the overlay transform.
|
|
9464
|
+
this._overlayTransformDirty = true;
|
|
7350
9465
|
// If the maxX or maxY are 0, then set them to the canvas width and height
|
|
7351
9466
|
if (!layout.maxX || !layout.maxY) {
|
|
7352
9467
|
this.resizeToCanvas();
|
|
@@ -7369,6 +9484,8 @@ var Rive = /** @class */ (function () {
|
|
|
7369
9484
|
maxX: this.canvas.width,
|
|
7370
9485
|
maxY: this.canvas.height,
|
|
7371
9486
|
});
|
|
9487
|
+
// Layout bounds feed the overlay transform.
|
|
9488
|
+
this._overlayTransformDirty = true;
|
|
7372
9489
|
};
|
|
7373
9490
|
/**
|
|
7374
9491
|
* Accounts for devicePixelRatio as a multiplier to render the size of the canvas drawing surface.
|
|
@@ -7390,12 +9507,12 @@ var Rive = /** @class */ (function () {
|
|
|
7390
9507
|
this.canvas.height = dpr * height;
|
|
7391
9508
|
this._needsRedraw = true;
|
|
7392
9509
|
this.resizeToCanvas();
|
|
7393
|
-
this.drawFrame();
|
|
7394
9510
|
if (this.layout.fit === Fit.Layout) {
|
|
7395
9511
|
var scaleFactor = this._layout.layoutScaleFactor;
|
|
7396
9512
|
this.artboard.width = width / scaleFactor;
|
|
7397
9513
|
this.artboard.height = height / scaleFactor;
|
|
7398
9514
|
}
|
|
9515
|
+
this.drawFrame();
|
|
7399
9516
|
}
|
|
7400
9517
|
};
|
|
7401
9518
|
Object.defineProperty(Rive.prototype, "source", {
|
|
@@ -7416,6 +9533,30 @@ var Rive = /** @class */ (function () {
|
|
|
7416
9533
|
enumerable: false,
|
|
7417
9534
|
configurable: true
|
|
7418
9535
|
});
|
|
9536
|
+
Object.defineProperty(Rive.prototype, "semanticTree", {
|
|
9537
|
+
/**
|
|
9538
|
+
* Returns the semantic tree model when semantics are enabled, or null.
|
|
9539
|
+
* The overlay and external consumers use this to inspect the
|
|
9540
|
+
* current state of the semantic tree.
|
|
9541
|
+
*/
|
|
9542
|
+
get: function () {
|
|
9543
|
+
return this._semanticTree;
|
|
9544
|
+
},
|
|
9545
|
+
enumerable: false,
|
|
9546
|
+
configurable: true
|
|
9547
|
+
});
|
|
9548
|
+
Object.defineProperty(Rive.prototype, "accessibilityOverlay", {
|
|
9549
|
+
/**
|
|
9550
|
+
* Returns the accessibility overlay when semantics are enabled, or null.
|
|
9551
|
+
* External consumers can use this to inspect the
|
|
9552
|
+
* current state of the accessibility overlay for this instance.
|
|
9553
|
+
*/
|
|
9554
|
+
get: function () {
|
|
9555
|
+
return this._accessibilityOverlay;
|
|
9556
|
+
},
|
|
9557
|
+
enumerable: false,
|
|
9558
|
+
configurable: true
|
|
9559
|
+
});
|
|
7419
9560
|
Object.defineProperty(Rive.prototype, "animationNames", {
|
|
7420
9561
|
// Returns a list of animation names on the chosen artboard
|
|
7421
9562
|
get: function () {
|
|
@@ -7856,7 +9997,7 @@ var Rive = /** @class */ (function () {
|
|
|
7856
9997
|
}
|
|
7857
9998
|
for (var k = 0; k < artboard.stateMachineCount(); k++) {
|
|
7858
9999
|
var stateMachine = artboard.stateMachineByIndex(k);
|
|
7859
|
-
var
|
|
10000
|
+
var name_2 = stateMachine.name;
|
|
7860
10001
|
var instance = new this.runtime.StateMachineInstance(stateMachine, artboard);
|
|
7861
10002
|
var inputContents = [];
|
|
7862
10003
|
for (var l = 0; l < instance.inputCount(); l++) {
|
|
@@ -7864,7 +10005,7 @@ var Rive = /** @class */ (function () {
|
|
|
7864
10005
|
inputContents.push({ name: input.name, type: input.type });
|
|
7865
10006
|
}
|
|
7866
10007
|
artboardContents.stateMachines.push({
|
|
7867
|
-
name:
|
|
10008
|
+
name: name_2,
|
|
7868
10009
|
inputs: inputContents,
|
|
7869
10010
|
});
|
|
7870
10011
|
}
|
|
@@ -7974,30 +10115,67 @@ var Rive = /** @class */ (function () {
|
|
|
7974
10115
|
return this._devicePixelRatioUsed;
|
|
7975
10116
|
},
|
|
7976
10117
|
set: function (value) {
|
|
10118
|
+
if (value !== this._devicePixelRatioUsed) {
|
|
10119
|
+
this._overlayTransformDirty = true;
|
|
10120
|
+
}
|
|
7977
10121
|
this._devicePixelRatioUsed = value;
|
|
7978
10122
|
},
|
|
7979
10123
|
enumerable: false,
|
|
7980
10124
|
configurable: true
|
|
7981
10125
|
});
|
|
7982
10126
|
/**
|
|
7983
|
-
*
|
|
10127
|
+
* Sets the main view model instance and applies it (rebinds). Equivalent to
|
|
10128
|
+
* `setViewModelInstance(vmi)` followed by `bind()`.
|
|
7984
10129
|
*/
|
|
7985
10130
|
Rive.prototype.bindViewModelInstance = function (viewModelInstance) {
|
|
10131
|
+
if (!viewModelInstance) {
|
|
10132
|
+
return;
|
|
10133
|
+
}
|
|
10134
|
+
this.setViewModelInstance(viewModelInstance);
|
|
10135
|
+
this.bind();
|
|
10136
|
+
};
|
|
10137
|
+
/**
|
|
10138
|
+
* Sets the main view model instance in the data context WITHOUT rebinding.
|
|
10139
|
+
* Call {@link bind} to apply. Use this with {@link setGlobalViewModelInstance}
|
|
10140
|
+
* to batch multiple changes into a single rebind.
|
|
10141
|
+
*/
|
|
10142
|
+
Rive.prototype.setViewModelInstance = function (viewModelInstance) {
|
|
7986
10143
|
var _a;
|
|
7987
|
-
|
|
7988
|
-
|
|
7989
|
-
|
|
7990
|
-
|
|
7991
|
-
|
|
7992
|
-
|
|
7993
|
-
|
|
7994
|
-
|
|
7995
|
-
|
|
7996
|
-
|
|
7997
|
-
|
|
7998
|
-
|
|
7999
|
-
|
|
8000
|
-
}
|
|
10144
|
+
var runtimeInstance = viewModelInstance === null || viewModelInstance === void 0 ? void 0 : viewModelInstance.runtimeInstance;
|
|
10145
|
+
if (!this.artboard ||
|
|
10146
|
+
this.destroyed ||
|
|
10147
|
+
!viewModelInstance ||
|
|
10148
|
+
!runtimeInstance) {
|
|
10149
|
+
return;
|
|
10150
|
+
}
|
|
10151
|
+
viewModelInstance.internalIncrementReferenceCount();
|
|
10152
|
+
(_a = this._viewModelInstance) === null || _a === void 0 ? void 0 : _a.cleanup();
|
|
10153
|
+
this._viewModelInstance = viewModelInstance;
|
|
10154
|
+
if (this.animator.stateMachines.length > 0) {
|
|
10155
|
+
this.animator.stateMachines.forEach(function (stateMachine) {
|
|
10156
|
+
return stateMachine.instance.setViewModelInstance(runtimeInstance);
|
|
10157
|
+
});
|
|
10158
|
+
}
|
|
10159
|
+
else {
|
|
10160
|
+
this.artboard.setViewModelInstance(runtimeInstance);
|
|
10161
|
+
}
|
|
10162
|
+
};
|
|
10163
|
+
/**
|
|
10164
|
+
* Applies any pending `set*` view model instance changes by rebinding the
|
|
10165
|
+
* data binds once.
|
|
10166
|
+
* Implicitly creates and binds any view models that have not been set.
|
|
10167
|
+
*/
|
|
10168
|
+
Rive.prototype.bind = function () {
|
|
10169
|
+
if (!this.artboard || this.destroyed) {
|
|
10170
|
+
return;
|
|
10171
|
+
}
|
|
10172
|
+
if (this.animator.stateMachines.length > 0) {
|
|
10173
|
+
this.animator.stateMachines.forEach(function (stateMachine) {
|
|
10174
|
+
return stateMachine.instance.bind();
|
|
10175
|
+
});
|
|
10176
|
+
}
|
|
10177
|
+
else {
|
|
10178
|
+
this.artboard.bind();
|
|
8001
10179
|
}
|
|
8002
10180
|
};
|
|
8003
10181
|
Object.defineProperty(Rive.prototype, "viewModelInstance", {
|
|
@@ -8007,6 +10185,78 @@ var Rive = /** @class */ (function () {
|
|
|
8007
10185
|
enumerable: false,
|
|
8008
10186
|
configurable: true
|
|
8009
10187
|
});
|
|
10188
|
+
/**
|
|
10189
|
+
* Sets (or replaces) the global view model instance for the given global view
|
|
10190
|
+
* model name in the data context WITHOUT rebinding. The main instance and any
|
|
10191
|
+
* other globals keep their order. Call {@link bind} to apply — batch several
|
|
10192
|
+
* `set*` calls then a single `bind()` to avoid rebinding per set.
|
|
10193
|
+
* @param name - the name of the global view model
|
|
10194
|
+
* @param viewModelInstance - the instance to set for that global
|
|
10195
|
+
* @returns whether the instance was set (false if `name` does not match a
|
|
10196
|
+
* global view model in the file)
|
|
10197
|
+
*/
|
|
10198
|
+
Rive.prototype.setGlobalViewModelInstance = function (name, viewModelInstance) {
|
|
10199
|
+
var _a;
|
|
10200
|
+
var runtimeInstance = viewModelInstance === null || viewModelInstance === void 0 ? void 0 : viewModelInstance.runtimeInstance;
|
|
10201
|
+
if (!this.artboard || this.destroyed || !runtimeInstance) {
|
|
10202
|
+
return false;
|
|
10203
|
+
}
|
|
10204
|
+
var bound = false;
|
|
10205
|
+
if (this.animator.stateMachines.length > 0) {
|
|
10206
|
+
this.animator.stateMachines.forEach(function (stateMachine) {
|
|
10207
|
+
if (stateMachine.instance.setGlobalViewModelInstance(name, runtimeInstance)) {
|
|
10208
|
+
bound = true;
|
|
10209
|
+
}
|
|
10210
|
+
});
|
|
10211
|
+
}
|
|
10212
|
+
else {
|
|
10213
|
+
bound = this.artboard.setGlobalViewModelInstance(name, runtimeInstance);
|
|
10214
|
+
}
|
|
10215
|
+
if (bound) {
|
|
10216
|
+
viewModelInstance.internalIncrementReferenceCount();
|
|
10217
|
+
(_a = this._globalViewModelInstances.get(name)) === null || _a === void 0 ? void 0 : _a.cleanup();
|
|
10218
|
+
this._globalViewModelInstances.set(name, viewModelInstance);
|
|
10219
|
+
}
|
|
10220
|
+
return bound;
|
|
10221
|
+
};
|
|
10222
|
+
/**
|
|
10223
|
+
* @param name - the name of the global view model
|
|
10224
|
+
* @returns the global view model instance bound under the given name — the
|
|
10225
|
+
* instance set via {@link setGlobalViewModelInstance} or one created by
|
|
10226
|
+
* auto-bind — or null if none has been set/created for that name (globals are
|
|
10227
|
+
* not auto-created; the getter never creates one).
|
|
10228
|
+
*/
|
|
10229
|
+
Rive.prototype.globalViewModelInstance = function (name) {
|
|
10230
|
+
var cached = this._globalViewModelInstances.get(name);
|
|
10231
|
+
if (cached) {
|
|
10232
|
+
return cached;
|
|
10233
|
+
}
|
|
10234
|
+
if (!this.artboard || this.destroyed) {
|
|
10235
|
+
return null;
|
|
10236
|
+
}
|
|
10237
|
+
// State machines share the artboard's data context; query the first one
|
|
10238
|
+
// when present (mirroring how the setter routes), otherwise the artboard.
|
|
10239
|
+
// This is a pure read — it returns null unless an instance was set/bound.
|
|
10240
|
+
var runtimeInstance = this.animator.stateMachines.length > 0
|
|
10241
|
+
? this.animator.stateMachines[0].instance.globalViewModelInstance(name)
|
|
10242
|
+
: this.artboard.globalViewModelInstance(name);
|
|
10243
|
+
if (runtimeInstance === null) {
|
|
10244
|
+
return null;
|
|
10245
|
+
}
|
|
10246
|
+
var viewModelInstance = new ViewModelInstance(runtimeInstance, null);
|
|
10247
|
+
(0,_utils__WEBPACK_IMPORTED_MODULE_3__.createFinalization)(viewModelInstance, runtimeInstance);
|
|
10248
|
+
viewModelInstance.internalIncrementReferenceCount();
|
|
10249
|
+
this._globalViewModelInstances.set(name, viewModelInstance);
|
|
10250
|
+
return viewModelInstance;
|
|
10251
|
+
};
|
|
10252
|
+
/**
|
|
10253
|
+
* @returns the names of the file's global view models, in file order. Use
|
|
10254
|
+
* these with {@link setGlobalViewModelInstance} / {@link globalViewModelInstance}.
|
|
10255
|
+
*/
|
|
10256
|
+
Rive.prototype.globalViewModelNames = function () {
|
|
10257
|
+
var _a, _b;
|
|
10258
|
+
return (_b = (_a = this.file) === null || _a === void 0 ? void 0 : _a.globalViewModelNames()) !== null && _b !== void 0 ? _b : [];
|
|
10259
|
+
};
|
|
8010
10260
|
Rive.prototype.viewModelByIndex = function (index) {
|
|
8011
10261
|
var viewModel = this.file.viewModelByIndex(index);
|
|
8012
10262
|
if (viewModel !== null) {
|
|
@@ -8107,7 +10357,7 @@ var ViewModel = /** @class */ (function () {
|
|
|
8107
10357
|
var instance = this._viewModel.instanceByIndex(index);
|
|
8108
10358
|
if (instance !== null) {
|
|
8109
10359
|
var viewModelInstance = new ViewModelInstance(instance, null);
|
|
8110
|
-
(0,
|
|
10360
|
+
(0,_utils__WEBPACK_IMPORTED_MODULE_3__.createFinalization)(viewModelInstance, instance);
|
|
8111
10361
|
return viewModelInstance;
|
|
8112
10362
|
}
|
|
8113
10363
|
return null;
|
|
@@ -8116,7 +10366,7 @@ var ViewModel = /** @class */ (function () {
|
|
|
8116
10366
|
var instance = this._viewModel.instanceByName(name);
|
|
8117
10367
|
if (instance !== null) {
|
|
8118
10368
|
var viewModelInstance = new ViewModelInstance(instance, null);
|
|
8119
|
-
(0,
|
|
10369
|
+
(0,_utils__WEBPACK_IMPORTED_MODULE_3__.createFinalization)(viewModelInstance, instance);
|
|
8120
10370
|
return viewModelInstance;
|
|
8121
10371
|
}
|
|
8122
10372
|
return null;
|
|
@@ -8125,7 +10375,7 @@ var ViewModel = /** @class */ (function () {
|
|
|
8125
10375
|
var runtimeInstance = this._viewModel.defaultInstance();
|
|
8126
10376
|
if (runtimeInstance !== null) {
|
|
8127
10377
|
var viewModelInstance = new ViewModelInstance(runtimeInstance, null);
|
|
8128
|
-
(0,
|
|
10378
|
+
(0,_utils__WEBPACK_IMPORTED_MODULE_3__.createFinalization)(viewModelInstance, runtimeInstance);
|
|
8129
10379
|
return viewModelInstance;
|
|
8130
10380
|
}
|
|
8131
10381
|
return null;
|
|
@@ -8134,7 +10384,7 @@ var ViewModel = /** @class */ (function () {
|
|
|
8134
10384
|
var runtimeInstance = this._viewModel.instance();
|
|
8135
10385
|
if (runtimeInstance !== null) {
|
|
8136
10386
|
var viewModelInstance = new ViewModelInstance(runtimeInstance, null);
|
|
8137
|
-
(0,
|
|
10387
|
+
(0,_utils__WEBPACK_IMPORTED_MODULE_3__.createFinalization)(viewModelInstance, runtimeInstance);
|
|
8138
10388
|
return viewModelInstance;
|
|
8139
10389
|
}
|
|
8140
10390
|
return null;
|
|
@@ -8187,6 +10437,7 @@ var PropertyType;
|
|
|
8187
10437
|
PropertyType["Enum"] = "enum";
|
|
8188
10438
|
PropertyType["List"] = "list";
|
|
8189
10439
|
PropertyType["Image"] = "image";
|
|
10440
|
+
PropertyType["Font"] = "font";
|
|
8190
10441
|
PropertyType["Artboard"] = "artboard";
|
|
8191
10442
|
})(PropertyType || (PropertyType = {}));
|
|
8192
10443
|
var ViewModelInstance = /** @class */ (function () {
|
|
@@ -8322,7 +10573,7 @@ var ViewModelInstance = /** @class */ (function () {
|
|
|
8322
10573
|
return null;
|
|
8323
10574
|
};
|
|
8324
10575
|
ViewModelInstance.prototype.propertyFromPathSegments = function (pathSegments, index, type) {
|
|
8325
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
|
|
10576
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
8326
10577
|
if (index < pathSegments.length - 1) {
|
|
8327
10578
|
var viewModelInstance = this.internalViewModelInstance(pathSegments[index]);
|
|
8328
10579
|
if (viewModelInstance !== null) {
|
|
@@ -8382,8 +10633,14 @@ var ViewModelInstance = /** @class */ (function () {
|
|
|
8382
10633
|
return new ViewModelInstanceAssetImage(instance, this);
|
|
8383
10634
|
}
|
|
8384
10635
|
break;
|
|
10636
|
+
case PropertyType.Font:
|
|
10637
|
+
instance = (_t = (_s = this._runtimeInstance) === null || _s === void 0 ? void 0 : _s.font(pathSegments[index])) !== null && _t !== void 0 ? _t : null;
|
|
10638
|
+
if (instance !== null) {
|
|
10639
|
+
return new ViewModelInstanceAssetFont(instance, this);
|
|
10640
|
+
}
|
|
10641
|
+
break;
|
|
8385
10642
|
case PropertyType.Artboard:
|
|
8386
|
-
instance = (
|
|
10643
|
+
instance = (_v = (_u = this._runtimeInstance) === null || _u === void 0 ? void 0 : _u.artboard(pathSegments[index])) !== null && _v !== void 0 ? _v : null;
|
|
8387
10644
|
if (instance !== null) {
|
|
8388
10645
|
return new ViewModelInstanceArtboard(instance, this);
|
|
8389
10646
|
}
|
|
@@ -8399,7 +10656,7 @@ var ViewModelInstance = /** @class */ (function () {
|
|
|
8399
10656
|
var viewModelRuntimeInstance = (_a = this._runtimeInstance) === null || _a === void 0 ? void 0 : _a.viewModel(name);
|
|
8400
10657
|
if (viewModelRuntimeInstance !== null) {
|
|
8401
10658
|
var viewModelInstance = new ViewModelInstance(viewModelRuntimeInstance, this);
|
|
8402
|
-
(0,
|
|
10659
|
+
(0,_utils__WEBPACK_IMPORTED_MODULE_3__.createFinalization)(viewModelInstance, viewModelRuntimeInstance);
|
|
8403
10660
|
viewModelInstance.internalIncrementReferenceCount();
|
|
8404
10661
|
this._viewModelInstances.set(name, viewModelInstance);
|
|
8405
10662
|
return viewModelInstance;
|
|
@@ -8478,6 +10735,15 @@ var ViewModelInstance = /** @class */ (function () {
|
|
|
8478
10735
|
var viewmodelInstanceValue = this.propertyFromPath(path, PropertyType.Image);
|
|
8479
10736
|
return viewmodelInstanceValue;
|
|
8480
10737
|
};
|
|
10738
|
+
/**
|
|
10739
|
+
* method to access a view model property instance belonging
|
|
10740
|
+
* to the view model instance or to a nested view model instance
|
|
10741
|
+
* @param path - path to the font property
|
|
10742
|
+
*/
|
|
10743
|
+
ViewModelInstance.prototype.font = function (path) {
|
|
10744
|
+
var viewmodelInstanceValue = this.propertyFromPath(path, PropertyType.Font);
|
|
10745
|
+
return viewmodelInstanceValue;
|
|
10746
|
+
};
|
|
8481
10747
|
/**
|
|
8482
10748
|
* method to access an artboard property instance belonging
|
|
8483
10749
|
* to the view model instance or to a nested view model instance
|
|
@@ -8816,7 +11082,7 @@ var ViewModelInstanceList = /** @class */ (function (_super) {
|
|
|
8816
11082
|
var runtimeInstance = this._viewModelInstanceValue.instanceAt(index);
|
|
8817
11083
|
if (runtimeInstance != null) {
|
|
8818
11084
|
var viewModelInstance = new ViewModelInstance(runtimeInstance, this._parentViewModel);
|
|
8819
|
-
(0,
|
|
11085
|
+
(0,_utils__WEBPACK_IMPORTED_MODULE_3__.createFinalization)(viewModelInstance, runtimeInstance);
|
|
8820
11086
|
return viewModelInstance;
|
|
8821
11087
|
}
|
|
8822
11088
|
return null;
|
|
@@ -8887,6 +11153,25 @@ var ViewModelInstanceAssetImage = /** @class */ (function (_super) {
|
|
|
8887
11153
|
return ViewModelInstanceAssetImage;
|
|
8888
11154
|
}(ViewModelInstanceValue));
|
|
8889
11155
|
|
|
11156
|
+
var ViewModelInstanceAssetFont = /** @class */ (function (_super) {
|
|
11157
|
+
__extends(ViewModelInstanceAssetFont, _super);
|
|
11158
|
+
function ViewModelInstanceAssetFont(instance, root) {
|
|
11159
|
+
return _super.call(this, instance, root) || this;
|
|
11160
|
+
}
|
|
11161
|
+
Object.defineProperty(ViewModelInstanceAssetFont.prototype, "value", {
|
|
11162
|
+
set: function (font) {
|
|
11163
|
+
var _a;
|
|
11164
|
+
this._viewModelInstanceValue.value((_a = font === null || font === void 0 ? void 0 : font.nativeFont) !== null && _a !== void 0 ? _a : null);
|
|
11165
|
+
},
|
|
11166
|
+
enumerable: false,
|
|
11167
|
+
configurable: true
|
|
11168
|
+
});
|
|
11169
|
+
ViewModelInstanceAssetFont.prototype.internalHandleCallback = function (callback) {
|
|
11170
|
+
callback();
|
|
11171
|
+
};
|
|
11172
|
+
return ViewModelInstanceAssetFont;
|
|
11173
|
+
}(ViewModelInstanceValue));
|
|
11174
|
+
|
|
8890
11175
|
var ViewModelInstanceArtboard = /** @class */ (function (_super) {
|
|
8891
11176
|
__extends(ViewModelInstanceArtboard, _super);
|
|
8892
11177
|
function ViewModelInstanceArtboard(instance, root) {
|
|
@@ -8979,8 +11264,8 @@ var decodeAudio = function (bytes) { return __awaiter(void 0, void 0, void 0, fu
|
|
|
8979
11264
|
return [4 /*yield*/, decodedPromise];
|
|
8980
11265
|
case 1:
|
|
8981
11266
|
audio = _a.sent();
|
|
8982
|
-
audioWrapper = new
|
|
8983
|
-
|
|
11267
|
+
audioWrapper = new _utils__WEBPACK_IMPORTED_MODULE_3__.AudioWrapper(audio);
|
|
11268
|
+
_utils__WEBPACK_IMPORTED_MODULE_3__.finalizationRegistry.register(audioWrapper, audio);
|
|
8984
11269
|
return [2 /*return*/, audioWrapper];
|
|
8985
11270
|
}
|
|
8986
11271
|
});
|
|
@@ -9004,8 +11289,8 @@ var decodeImage = function (bytes) { return __awaiter(void 0, void 0, void 0, fu
|
|
|
9004
11289
|
return [4 /*yield*/, decodedPromise];
|
|
9005
11290
|
case 1:
|
|
9006
11291
|
image = _a.sent();
|
|
9007
|
-
imageWrapper = new
|
|
9008
|
-
|
|
11292
|
+
imageWrapper = new _utils__WEBPACK_IMPORTED_MODULE_3__.ImageWrapper(image);
|
|
11293
|
+
_utils__WEBPACK_IMPORTED_MODULE_3__.finalizationRegistry.register(imageWrapper, image);
|
|
9009
11294
|
return [2 /*return*/, imageWrapper];
|
|
9010
11295
|
}
|
|
9011
11296
|
});
|
|
@@ -9029,8 +11314,8 @@ var decodeFont = function (bytes) { return __awaiter(void 0, void 0, void 0, fun
|
|
|
9029
11314
|
return [4 /*yield*/, decodedPromise];
|
|
9030
11315
|
case 1:
|
|
9031
11316
|
font = _a.sent();
|
|
9032
|
-
fontWrapper = new
|
|
9033
|
-
|
|
11317
|
+
fontWrapper = new _utils__WEBPACK_IMPORTED_MODULE_3__.FontWrapper(font);
|
|
11318
|
+
_utils__WEBPACK_IMPORTED_MODULE_3__.finalizationRegistry.register(fontWrapper, font);
|
|
9034
11319
|
return [2 /*return*/, fontWrapper];
|
|
9035
11320
|
}
|
|
9036
11321
|
});
|