@rive-app/canvas 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 -102
- 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
|
@@ -1084,7 +1084,7 @@ function Ya(a, b) {
|
|
|
1084
1084
|
return Xa(c, a, b);
|
|
1085
1085
|
}));
|
|
1086
1086
|
}
|
|
1087
|
-
var Za, $a, db = {
|
|
1087
|
+
var Za, $a, db = {487293:(a, b, c, d, e) => {
|
|
1088
1088
|
if ("undefined" === typeof window || void 0 === (window.AudioContext || window.webkitAudioContext)) {
|
|
1089
1089
|
return 0;
|
|
1090
1090
|
}
|
|
@@ -1147,11 +1147,11 @@ var Za, $a, db = {486221:(a, b, c, d, e) => {
|
|
|
1147
1147
|
}
|
|
1148
1148
|
window.miniaudio.referenceCount += 1;
|
|
1149
1149
|
return 1;
|
|
1150
|
-
},
|
|
1150
|
+
}, 489471:() => {
|
|
1151
1151
|
"undefined" !== typeof window.miniaudio && (window.miniaudio.unlock_event_types.map(function(a) {
|
|
1152
1152
|
document.removeEventListener(a, window.miniaudio.unlock, !0);
|
|
1153
1153
|
}), --window.miniaudio.referenceCount, 0 === window.miniaudio.referenceCount && delete window.miniaudio);
|
|
1154
|
-
},
|
|
1154
|
+
}, 489775:() => void 0 !== navigator.mediaDevices && void 0 !== navigator.mediaDevices.getUserMedia, 489879:() => {
|
|
1155
1155
|
try {
|
|
1156
1156
|
var a = new (window.AudioContext || window.webkitAudioContext)(), b = a.sampleRate;
|
|
1157
1157
|
a.close();
|
|
@@ -1159,7 +1159,7 @@ var Za, $a, db = {486221:(a, b, c, d, e) => {
|
|
|
1159
1159
|
} catch (c) {
|
|
1160
1160
|
return 0;
|
|
1161
1161
|
}
|
|
1162
|
-
},
|
|
1162
|
+
}, 490050:(a, b, c, d, e, f) => {
|
|
1163
1163
|
if ("undefined" === typeof window.miniaudio) {
|
|
1164
1164
|
return -1;
|
|
1165
1165
|
}
|
|
@@ -1205,7 +1205,7 @@ var Za, $a, db = {486221:(a, b, c, d, e) => {
|
|
|
1205
1205
|
a == window.miniaudio.device_type.playback && g.W.connect(g.I.destination);
|
|
1206
1206
|
g.hb = f;
|
|
1207
1207
|
return window.miniaudio.track_device(g);
|
|
1208
|
-
},
|
|
1208
|
+
}, 492927:a => window.miniaudio.get_device_by_index(a).I.sampleRate, 493E3:a => {
|
|
1209
1209
|
a = window.miniaudio.get_device_by_index(a);
|
|
1210
1210
|
void 0 !== a.W && (a.W.onaudioprocess = function() {
|
|
1211
1211
|
}, a.W.disconnect(), a.W = void 0);
|
|
@@ -1213,13 +1213,13 @@ var Za, $a, db = {486221:(a, b, c, d, e) => {
|
|
|
1213
1213
|
a.I.close();
|
|
1214
1214
|
a.I = void 0;
|
|
1215
1215
|
a.hb = void 0;
|
|
1216
|
-
},
|
|
1216
|
+
}, 493400:a => {
|
|
1217
1217
|
window.miniaudio.untrack_device_by_index(a);
|
|
1218
|
-
},
|
|
1218
|
+
}, 493450:a => {
|
|
1219
1219
|
a = window.miniaudio.get_device_by_index(a);
|
|
1220
1220
|
a.I.resume();
|
|
1221
1221
|
a.state = window.miniaudio.device_state.started;
|
|
1222
|
-
},
|
|
1222
|
+
}, 493589:a => {
|
|
1223
1223
|
a = window.miniaudio.get_device_by_index(a);
|
|
1224
1224
|
a.I.suspend();
|
|
1225
1225
|
a.state = window.miniaudio.device_state.stopped;
|
|
@@ -3752,12 +3752,1823 @@ moduleRtn = da;
|
|
|
3752
3752
|
/* 5 */
|
|
3753
3753
|
/***/ ((module) => {
|
|
3754
3754
|
|
|
3755
|
-
module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/canvas","version":"2.
|
|
3755
|
+
module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/canvas","version":"2.39.1","description":"Rive\'s canvas based web api.","main":"rive.js","homepage":"https://rive.app","repository":{"type":"git","url":"https://github.com/rive-app/rive-wasm/tree/master/js"},"keywords":["rive","animation"],"author":"Rive","contributors":["Luigi Rosso <luigi@rive.app> (https://rive.app)","Maxwell Talbot <max@rive.app> (https://rive.app)","Arthur Vivian <arthur@rive.app> (https://rive.app)","Umberto Sonnino <umberto@rive.app> (https://rive.app)","Matthew Sullivan <matt.j.sullivan@gmail.com> (mailto:matt.j.sullivan@gmail.com)"],"license":"MIT","files":["rive.js","rive.js.map","rive.wasm","rive_fallback.wasm","rive.d.ts","rive_advanced.mjs.d.ts","runtimeLoader.d.ts","utils","semantics"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
|
|
3756
3756
|
|
|
3757
3757
|
/***/ }),
|
|
3758
3758
|
/* 6 */
|
|
3759
3759
|
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
3760
3760
|
|
|
3761
|
+
__webpack_require__.r(__webpack_exports__);
|
|
3762
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
3763
|
+
/* harmony export */ AccessibilityOverlay: () => (/* reexport safe */ _accessibilityOverlay__WEBPACK_IMPORTED_MODULE_1__.AccessibilityOverlay),
|
|
3764
|
+
/* harmony export */ SemanticActionType: () => (/* reexport safe */ _types__WEBPACK_IMPORTED_MODULE_2__.SemanticActionType),
|
|
3765
|
+
/* harmony export */ SemanticMode: () => (/* reexport safe */ _types__WEBPACK_IMPORTED_MODULE_2__.SemanticMode),
|
|
3766
|
+
/* harmony export */ SemanticRole: () => (/* reexport safe */ _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole),
|
|
3767
|
+
/* harmony export */ SemanticState: () => (/* reexport safe */ _types__WEBPACK_IMPORTED_MODULE_2__.SemanticState),
|
|
3768
|
+
/* harmony export */ SemanticTrait: () => (/* reexport safe */ _types__WEBPACK_IMPORTED_MODULE_2__.SemanticTrait),
|
|
3769
|
+
/* harmony export */ SemanticTreeModel: () => (/* reexport safe */ _semanticTreeModel__WEBPACK_IMPORTED_MODULE_0__.SemanticTreeModel),
|
|
3770
|
+
/* harmony export */ hasState: () => (/* reexport safe */ _types__WEBPACK_IMPORTED_MODULE_2__.hasState),
|
|
3771
|
+
/* harmony export */ hasTrait: () => (/* reexport safe */ _types__WEBPACK_IMPORTED_MODULE_2__.hasTrait),
|
|
3772
|
+
/* harmony export */ roleName: () => (/* reexport safe */ _types__WEBPACK_IMPORTED_MODULE_2__.roleName),
|
|
3773
|
+
/* harmony export */ stateNames: () => (/* reexport safe */ _types__WEBPACK_IMPORTED_MODULE_2__.stateNames),
|
|
3774
|
+
/* harmony export */ traitNames: () => (/* reexport safe */ _types__WEBPACK_IMPORTED_MODULE_2__.traitNames)
|
|
3775
|
+
/* harmony export */ });
|
|
3776
|
+
/* harmony import */ var _semanticTreeModel__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(7);
|
|
3777
|
+
/* harmony import */ var _accessibilityOverlay__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(9);
|
|
3778
|
+
/* harmony import */ var _types__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(8);
|
|
3779
|
+
|
|
3780
|
+
|
|
3781
|
+
|
|
3782
|
+
|
|
3783
|
+
|
|
3784
|
+
/***/ }),
|
|
3785
|
+
/* 7 */
|
|
3786
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
3787
|
+
|
|
3788
|
+
__webpack_require__.r(__webpack_exports__);
|
|
3789
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
3790
|
+
/* harmony export */ SemanticTreeModel: () => (/* binding */ SemanticTreeModel)
|
|
3791
|
+
/* harmony export */ });
|
|
3792
|
+
/* harmony import */ var _types__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(8);
|
|
3793
|
+
var __spreadArray = (undefined && undefined.__spreadArray) || function (to, from, pack) {
|
|
3794
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
3795
|
+
if (ar || !(i in from)) {
|
|
3796
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
3797
|
+
ar[i] = from[i];
|
|
3798
|
+
}
|
|
3799
|
+
}
|
|
3800
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
3801
|
+
};
|
|
3802
|
+
|
|
3803
|
+
/**
|
|
3804
|
+
* Maintains an in-memory semantic tree built from incremental
|
|
3805
|
+
* {@link SemanticsDiff} updates received each frame from the WASM runtime.
|
|
3806
|
+
*
|
|
3807
|
+
* Processing order within {@link applyDiff} follows the contract defined in
|
|
3808
|
+
* `semantic_snapshot.hpp`: removed → added → moved → childrenUpdated →
|
|
3809
|
+
* updatedSemantic → updatedGeometry.
|
|
3810
|
+
*/
|
|
3811
|
+
var SemanticTreeModel = /** @class */ (function () {
|
|
3812
|
+
function SemanticTreeModel() {
|
|
3813
|
+
this._nodesById = new Map();
|
|
3814
|
+
this._roots = [];
|
|
3815
|
+
this._semanticVersion = 0;
|
|
3816
|
+
this._geometryVersion = 0;
|
|
3817
|
+
this._geometryChangedIds = new Set();
|
|
3818
|
+
this._semanticChangedIds = new Set();
|
|
3819
|
+
this._debug = false;
|
|
3820
|
+
}
|
|
3821
|
+
Object.defineProperty(SemanticTreeModel.prototype, "nodeCount", {
|
|
3822
|
+
get: function () {
|
|
3823
|
+
return this._nodesById.size;
|
|
3824
|
+
},
|
|
3825
|
+
enumerable: false,
|
|
3826
|
+
configurable: true
|
|
3827
|
+
});
|
|
3828
|
+
Object.defineProperty(SemanticTreeModel.prototype, "semanticVersion", {
|
|
3829
|
+
/** Bumped when semantic content or tree structure changes. */
|
|
3830
|
+
get: function () {
|
|
3831
|
+
return this._semanticVersion;
|
|
3832
|
+
},
|
|
3833
|
+
enumerable: false,
|
|
3834
|
+
configurable: true
|
|
3835
|
+
});
|
|
3836
|
+
Object.defineProperty(SemanticTreeModel.prototype, "geometryVersion", {
|
|
3837
|
+
/** Bumped when node bounds change without a semantic/structural change. */
|
|
3838
|
+
get: function () {
|
|
3839
|
+
return this._geometryVersion;
|
|
3840
|
+
},
|
|
3841
|
+
enumerable: false,
|
|
3842
|
+
configurable: true
|
|
3843
|
+
});
|
|
3844
|
+
Object.defineProperty(SemanticTreeModel.prototype, "geometryChangedIds", {
|
|
3845
|
+
/** Node IDs whose bounds changed in the most recent {@link applyDiff}. */
|
|
3846
|
+
get: function () {
|
|
3847
|
+
return this._geometryChangedIds;
|
|
3848
|
+
},
|
|
3849
|
+
enumerable: false,
|
|
3850
|
+
configurable: true
|
|
3851
|
+
});
|
|
3852
|
+
Object.defineProperty(SemanticTreeModel.prototype, "semanticChangedIds", {
|
|
3853
|
+
/**
|
|
3854
|
+
* Node IDs whose semantic fields (role/label/value/hint/flags/headingLevel)
|
|
3855
|
+
* changed in the most recent {@link applyDiff}. Structural changes (moves,
|
|
3856
|
+
* child reorders, removals) bump {@link semanticVersion} but don't mark
|
|
3857
|
+
* nodes here — element attributes don't depend on tree position.
|
|
3858
|
+
*/
|
|
3859
|
+
get: function () {
|
|
3860
|
+
return this._semanticChangedIds;
|
|
3861
|
+
},
|
|
3862
|
+
enumerable: false,
|
|
3863
|
+
configurable: true
|
|
3864
|
+
});
|
|
3865
|
+
Object.defineProperty(SemanticTreeModel.prototype, "roots", {
|
|
3866
|
+
/** Root node IDs in sibling order. */
|
|
3867
|
+
get: function () {
|
|
3868
|
+
return this._roots;
|
|
3869
|
+
},
|
|
3870
|
+
enumerable: false,
|
|
3871
|
+
configurable: true
|
|
3872
|
+
});
|
|
3873
|
+
/** Look up a node by its ID, or undefined if not in the tree. */
|
|
3874
|
+
SemanticTreeModel.prototype.nodeById = function (id) {
|
|
3875
|
+
return this._nodesById.get(id);
|
|
3876
|
+
};
|
|
3877
|
+
/** Current index of a node among its siblings (or roots), or -1 if absent. */
|
|
3878
|
+
SemanticTreeModel.prototype.siblingIndexOf = function (id) {
|
|
3879
|
+
var node = this._nodesById.get(id);
|
|
3880
|
+
if (!node)
|
|
3881
|
+
return -1;
|
|
3882
|
+
if (node.parentId < 0)
|
|
3883
|
+
return this._roots.indexOf(id);
|
|
3884
|
+
var parent = this._nodesById.get(node.parentId);
|
|
3885
|
+
return parent ? parent.children.indexOf(id) : -1;
|
|
3886
|
+
};
|
|
3887
|
+
/** Detach a node from its current parent (or from roots). */
|
|
3888
|
+
SemanticTreeModel.prototype.detach = function (id) {
|
|
3889
|
+
var node = this._nodesById.get(id);
|
|
3890
|
+
if (!node)
|
|
3891
|
+
return;
|
|
3892
|
+
if (node.parentId < 0) {
|
|
3893
|
+
var idx = this._roots.indexOf(id);
|
|
3894
|
+
if (idx !== -1)
|
|
3895
|
+
this._roots.splice(idx, 1);
|
|
3896
|
+
}
|
|
3897
|
+
else {
|
|
3898
|
+
var parent_1 = this._nodesById.get(node.parentId);
|
|
3899
|
+
if (parent_1) {
|
|
3900
|
+
var idx = parent_1.children.indexOf(id);
|
|
3901
|
+
if (idx !== -1)
|
|
3902
|
+
parent_1.children.splice(idx, 1);
|
|
3903
|
+
}
|
|
3904
|
+
}
|
|
3905
|
+
};
|
|
3906
|
+
/** Attach a node under a parent at a given sibling index (or as root). */
|
|
3907
|
+
SemanticTreeModel.prototype.attach = function (id, parentId, siblingIndex) {
|
|
3908
|
+
var node = this._nodesById.get(id);
|
|
3909
|
+
if (!node)
|
|
3910
|
+
return;
|
|
3911
|
+
if (parentId < 0) {
|
|
3912
|
+
node.parentId = -1;
|
|
3913
|
+
var idx = clamp(siblingIndex, 0, this._roots.length);
|
|
3914
|
+
this._roots.splice(idx, 0, id);
|
|
3915
|
+
}
|
|
3916
|
+
else {
|
|
3917
|
+
var parent_2 = this._nodesById.get(parentId);
|
|
3918
|
+
if (!parent_2) {
|
|
3919
|
+
node.parentId = -1;
|
|
3920
|
+
this._roots.push(id);
|
|
3921
|
+
}
|
|
3922
|
+
else {
|
|
3923
|
+
node.parentId = parentId;
|
|
3924
|
+
var idx = clamp(siblingIndex, 0, parent_2.children.length);
|
|
3925
|
+
parent_2.children.splice(idx, 0, id);
|
|
3926
|
+
}
|
|
3927
|
+
}
|
|
3928
|
+
};
|
|
3929
|
+
/** Recursively remove a node and all descendants. */
|
|
3930
|
+
SemanticTreeModel.prototype.removeSubtree = function (id) {
|
|
3931
|
+
var node = this._nodesById.get(id);
|
|
3932
|
+
if (!node)
|
|
3933
|
+
return;
|
|
3934
|
+
// Copy children array — we're mutating during traversal
|
|
3935
|
+
var kids = __spreadArray([], node.children, true);
|
|
3936
|
+
for (var _i = 0, kids_1 = kids; _i < kids_1.length; _i++) {
|
|
3937
|
+
var child = kids_1[_i];
|
|
3938
|
+
this.removeSubtree(child);
|
|
3939
|
+
}
|
|
3940
|
+
this.detach(id);
|
|
3941
|
+
this._nodesById.delete(id);
|
|
3942
|
+
};
|
|
3943
|
+
/**
|
|
3944
|
+
* Apply an incremental diff to the tree. Bumps version counters and notifies
|
|
3945
|
+
* listeners only when the tree actually changed.
|
|
3946
|
+
*
|
|
3947
|
+
* No-op diffs (field values identical to current model) do not bump
|
|
3948
|
+
* versions — the native side guards against emitting these, but applyDiff
|
|
3949
|
+
* defends its subscribers regardless.
|
|
3950
|
+
*/
|
|
3951
|
+
SemanticTreeModel.prototype.applyDiff = function (diff) {
|
|
3952
|
+
var _a, _b;
|
|
3953
|
+
var _this = this;
|
|
3954
|
+
this._geometryChangedIds.clear();
|
|
3955
|
+
this._semanticChangedIds.clear();
|
|
3956
|
+
var semanticChanged = false;
|
|
3957
|
+
var geometryChanged = false;
|
|
3958
|
+
var markSemantic = function () {
|
|
3959
|
+
semanticChanged = true;
|
|
3960
|
+
};
|
|
3961
|
+
var markSemanticNode = function (id) {
|
|
3962
|
+
semanticChanged = true;
|
|
3963
|
+
_this._semanticChangedIds.add(id);
|
|
3964
|
+
};
|
|
3965
|
+
var markGeometry = function (id) {
|
|
3966
|
+
geometryChanged = true;
|
|
3967
|
+
_this._geometryChangedIds.add(id);
|
|
3968
|
+
};
|
|
3969
|
+
// 1. removed
|
|
3970
|
+
for (var _i = 0, _c = diff.removed; _i < _c.length; _i++) {
|
|
3971
|
+
var id = _c[_i];
|
|
3972
|
+
if (this._nodesById.has(id)) {
|
|
3973
|
+
this.removeSubtree(id);
|
|
3974
|
+
markSemantic();
|
|
3975
|
+
}
|
|
3976
|
+
}
|
|
3977
|
+
// 2. added
|
|
3978
|
+
for (var _d = 0, _e = diff.added; _d < _e.length; _d++) {
|
|
3979
|
+
var n = _e[_d];
|
|
3980
|
+
var existing = this._nodesById.get(n.id);
|
|
3981
|
+
if (existing) {
|
|
3982
|
+
if (semanticFieldsDiffer(existing, n)) {
|
|
3983
|
+
applySemantic(existing, n);
|
|
3984
|
+
markSemanticNode(n.id);
|
|
3985
|
+
}
|
|
3986
|
+
if (geometryFieldsDiffer(existing, n)) {
|
|
3987
|
+
applyGeometry(existing, n);
|
|
3988
|
+
markGeometry(n.id);
|
|
3989
|
+
}
|
|
3990
|
+
}
|
|
3991
|
+
else {
|
|
3992
|
+
this._nodesById.set(n.id, nodeFromDiff(n));
|
|
3993
|
+
markSemanticNode(n.id);
|
|
3994
|
+
markGeometry(n.id);
|
|
3995
|
+
}
|
|
3996
|
+
this.detach(n.id);
|
|
3997
|
+
this.attach(n.id, n.parentId, n.siblingIndex);
|
|
3998
|
+
}
|
|
3999
|
+
// 3. moved
|
|
4000
|
+
// The runtime emits a node as "moved" when its parentId OR siblingIndex
|
|
4001
|
+
// changes, so a reorder-only move (same parent, new index) is still a
|
|
4002
|
+
// structural/semantic change. Compare the actual position before and after
|
|
4003
|
+
// re-attaching so that geometry-only or no-op moves don't bump the semantic
|
|
4004
|
+
// version (which would defeat the semantic/geometry version split).
|
|
4005
|
+
for (var _f = 0, _g = diff.moved; _f < _g.length; _f++) {
|
|
4006
|
+
var n = _g[_f];
|
|
4007
|
+
var existing = this._nodesById.get(n.id);
|
|
4008
|
+
if (!existing)
|
|
4009
|
+
continue;
|
|
4010
|
+
var parentChanged = existing.parentId !== n.parentId;
|
|
4011
|
+
var oldIndex = this.siblingIndexOf(n.id);
|
|
4012
|
+
var geomChanged = geometryFieldsDiffer(existing, n);
|
|
4013
|
+
if (geomChanged) {
|
|
4014
|
+
applyGeometry(existing, n);
|
|
4015
|
+
markGeometry(n.id);
|
|
4016
|
+
}
|
|
4017
|
+
this.detach(n.id);
|
|
4018
|
+
this.attach(n.id, n.parentId, n.siblingIndex);
|
|
4019
|
+
if (parentChanged || this.siblingIndexOf(n.id) !== oldIndex) {
|
|
4020
|
+
markSemantic();
|
|
4021
|
+
}
|
|
4022
|
+
}
|
|
4023
|
+
// 4. childrenUpdated
|
|
4024
|
+
for (var _h = 0, _j = diff.childrenUpdated; _h < _j.length; _h++) {
|
|
4025
|
+
var update = _j[_h];
|
|
4026
|
+
if (update.parentId < 0) {
|
|
4027
|
+
var next = update.childIds.filter(function (id) { return _this._nodesById.has(id); });
|
|
4028
|
+
if (!arraysEqual(this._roots, next)) {
|
|
4029
|
+
this._roots.length = 0;
|
|
4030
|
+
(_a = this._roots).push.apply(_a, next);
|
|
4031
|
+
for (var _k = 0, _l = this._roots; _k < _l.length; _k++) {
|
|
4032
|
+
var id = _l[_k];
|
|
4033
|
+
var node = this._nodesById.get(id);
|
|
4034
|
+
if (node)
|
|
4035
|
+
node.parentId = -1;
|
|
4036
|
+
}
|
|
4037
|
+
markSemantic();
|
|
4038
|
+
}
|
|
4039
|
+
}
|
|
4040
|
+
else {
|
|
4041
|
+
var parent_3 = this._nodesById.get(update.parentId);
|
|
4042
|
+
if (!parent_3)
|
|
4043
|
+
continue;
|
|
4044
|
+
var next = update.childIds.filter(function (id) { return _this._nodesById.has(id); });
|
|
4045
|
+
if (!arraysEqual(parent_3.children, next)) {
|
|
4046
|
+
parent_3.children.length = 0;
|
|
4047
|
+
(_b = parent_3.children).push.apply(_b, next);
|
|
4048
|
+
for (var _m = 0, _o = parent_3.children; _m < _o.length; _m++) {
|
|
4049
|
+
var id = _o[_m];
|
|
4050
|
+
var node = this._nodesById.get(id);
|
|
4051
|
+
if (node)
|
|
4052
|
+
node.parentId = update.parentId;
|
|
4053
|
+
}
|
|
4054
|
+
markSemantic();
|
|
4055
|
+
}
|
|
4056
|
+
}
|
|
4057
|
+
}
|
|
4058
|
+
// 5. updatedSemantic — semantic fields updated
|
|
4059
|
+
for (var _p = 0, _q = diff.updatedSemantic; _p < _q.length; _p++) {
|
|
4060
|
+
var n = _q[_p];
|
|
4061
|
+
var existing = this._nodesById.get(n.id);
|
|
4062
|
+
if (!existing)
|
|
4063
|
+
continue;
|
|
4064
|
+
if (!semanticFieldsDiffer(existing, n))
|
|
4065
|
+
continue;
|
|
4066
|
+
applySemantic(existing, n);
|
|
4067
|
+
markSemanticNode(n.id);
|
|
4068
|
+
}
|
|
4069
|
+
// 6. updatedGeometry — bounds of a semantic node updated
|
|
4070
|
+
for (var _r = 0, _s = diff.updatedGeometry; _r < _s.length; _r++) {
|
|
4071
|
+
var n = _s[_r];
|
|
4072
|
+
var existing = this._nodesById.get(n.id);
|
|
4073
|
+
if (!existing)
|
|
4074
|
+
continue;
|
|
4075
|
+
if (!geometryFieldsDiffer(existing, n))
|
|
4076
|
+
continue;
|
|
4077
|
+
applyGeometry(existing, n);
|
|
4078
|
+
markGeometry(n.id);
|
|
4079
|
+
}
|
|
4080
|
+
if (!semanticChanged && !geometryChanged)
|
|
4081
|
+
return;
|
|
4082
|
+
if (semanticChanged)
|
|
4083
|
+
this._semanticVersion++;
|
|
4084
|
+
if (geometryChanged)
|
|
4085
|
+
this._geometryVersion++;
|
|
4086
|
+
if (this._debug) {
|
|
4087
|
+
this.logDiff(diff, semanticChanged, geometryChanged);
|
|
4088
|
+
}
|
|
4089
|
+
};
|
|
4090
|
+
Object.defineProperty(SemanticTreeModel.prototype, "debug", {
|
|
4091
|
+
/** Enable/disable debug logging of diffs to the console. */
|
|
4092
|
+
set: function (enabled) {
|
|
4093
|
+
this._debug = enabled;
|
|
4094
|
+
},
|
|
4095
|
+
enumerable: false,
|
|
4096
|
+
configurable: true
|
|
4097
|
+
});
|
|
4098
|
+
SemanticTreeModel.prototype.logDiff = function (diff, semanticChanged, geometryChanged) {
|
|
4099
|
+
var lines = [
|
|
4100
|
+
"[rive:semantics] semantic v".concat(this._semanticVersion) +
|
|
4101
|
+
(geometryChanged ? " geometry v".concat(this._geometryVersion) : "") +
|
|
4102
|
+
(semanticChanged ? "" : " (geometry-only)"),
|
|
4103
|
+
];
|
|
4104
|
+
for (var _i = 0, _a = diff.removed; _i < _a.length; _i++) {
|
|
4105
|
+
var id = _a[_i];
|
|
4106
|
+
lines.push(" - removed #".concat(id));
|
|
4107
|
+
}
|
|
4108
|
+
for (var _b = 0, _c = diff.added; _b < _c.length; _b++) {
|
|
4109
|
+
var n = _c[_b];
|
|
4110
|
+
lines.push(" + added #".concat(n.id, " ").concat((0,_types__WEBPACK_IMPORTED_MODULE_0__.roleName)(n.role)) +
|
|
4111
|
+
(n.label ? " \"".concat(n.label, "\"") : "") +
|
|
4112
|
+
" bounds:(".concat(n.minX.toFixed(1), ",").concat(n.minY.toFixed(1), ")-(").concat(n.maxX.toFixed(1), ",").concat(n.maxY.toFixed(1), ")") +
|
|
4113
|
+
" states=[".concat((0,_types__WEBPACK_IMPORTED_MODULE_0__.stateNames)(n.stateFlags), "]") +
|
|
4114
|
+
" traits=[".concat((0,_types__WEBPACK_IMPORTED_MODULE_0__.traitNames)(n.traitFlags), "]"));
|
|
4115
|
+
}
|
|
4116
|
+
for (var _d = 0, _e = diff.moved; _d < _e.length; _d++) {
|
|
4117
|
+
var n = _e[_d];
|
|
4118
|
+
lines.push(" ~ moved #".concat(n.id, " \u2192 parent=").concat(n.parentId, " idx=").concat(n.siblingIndex) +
|
|
4119
|
+
" bounds:(".concat(n.minX.toFixed(1), ",").concat(n.minY.toFixed(1), ")-(").concat(n.maxX.toFixed(1), ",").concat(n.maxY.toFixed(1), ")"));
|
|
4120
|
+
}
|
|
4121
|
+
for (var _f = 0, _g = diff.childrenUpdated; _f < _g.length; _f++) {
|
|
4122
|
+
var u = _g[_f];
|
|
4123
|
+
lines.push(" \u2195 children of ".concat(u.parentId < 0 ? "root" : "#" + u.parentId, ": [").concat(u.childIds.join(", "), "]"));
|
|
4124
|
+
}
|
|
4125
|
+
for (var _h = 0, _j = diff.updatedSemantic; _h < _j.length; _h++) {
|
|
4126
|
+
var n = _j[_h];
|
|
4127
|
+
lines.push(" \u270E semantic #".concat(n.id, " ").concat((0,_types__WEBPACK_IMPORTED_MODULE_0__.roleName)(n.role)) +
|
|
4128
|
+
(n.label ? " \"".concat(n.label, "\"") : "") +
|
|
4129
|
+
" states=[".concat((0,_types__WEBPACK_IMPORTED_MODULE_0__.stateNames)(n.stateFlags), "]") +
|
|
4130
|
+
" traits=[".concat((0,_types__WEBPACK_IMPORTED_MODULE_0__.traitNames)(n.traitFlags), "]"));
|
|
4131
|
+
}
|
|
4132
|
+
for (var _k = 0, _l = diff.updatedGeometry; _k < _l.length; _k++) {
|
|
4133
|
+
var n = _l[_k];
|
|
4134
|
+
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), ")"));
|
|
4135
|
+
}
|
|
4136
|
+
console.log(lines.join("\n"));
|
|
4137
|
+
};
|
|
4138
|
+
/**
|
|
4139
|
+
* Returns every node in depth-first order, paired with its depth level.
|
|
4140
|
+
* Useful for debug logging / rendering a flat list.
|
|
4141
|
+
*/
|
|
4142
|
+
SemanticTreeModel.prototype.flattened = function () {
|
|
4143
|
+
var _this = this;
|
|
4144
|
+
var out = [];
|
|
4145
|
+
var walk = function (id, depth) {
|
|
4146
|
+
var node = _this._nodesById.get(id);
|
|
4147
|
+
if (!node)
|
|
4148
|
+
return;
|
|
4149
|
+
out.push({ depth: depth, node: node });
|
|
4150
|
+
for (var _i = 0, _a = node.children; _i < _a.length; _i++) {
|
|
4151
|
+
var child = _a[_i];
|
|
4152
|
+
walk(child, depth + 1);
|
|
4153
|
+
}
|
|
4154
|
+
};
|
|
4155
|
+
for (var _i = 0, _a = this._roots; _i < _a.length; _i++) {
|
|
4156
|
+
var root = _a[_i];
|
|
4157
|
+
walk(root, 0);
|
|
4158
|
+
}
|
|
4159
|
+
return out;
|
|
4160
|
+
};
|
|
4161
|
+
return SemanticTreeModel;
|
|
4162
|
+
}());
|
|
4163
|
+
|
|
4164
|
+
function clamp(v, min, max) {
|
|
4165
|
+
return v < min ? min : v > max ? max : v;
|
|
4166
|
+
}
|
|
4167
|
+
function arraysEqual(a, b) {
|
|
4168
|
+
if (a.length !== b.length)
|
|
4169
|
+
return false;
|
|
4170
|
+
for (var i = 0; i < a.length; i++) {
|
|
4171
|
+
if (a[i] !== b[i])
|
|
4172
|
+
return false;
|
|
4173
|
+
}
|
|
4174
|
+
return true;
|
|
4175
|
+
}
|
|
4176
|
+
function nodeFromDiff(n) {
|
|
4177
|
+
return {
|
|
4178
|
+
id: n.id,
|
|
4179
|
+
parentId: -1,
|
|
4180
|
+
role: n.role,
|
|
4181
|
+
label: n.label,
|
|
4182
|
+
value: n.value,
|
|
4183
|
+
hint: n.hint,
|
|
4184
|
+
stateFlags: n.stateFlags,
|
|
4185
|
+
traitFlags: n.traitFlags,
|
|
4186
|
+
headingLevel: n.headingLevel,
|
|
4187
|
+
minX: n.minX,
|
|
4188
|
+
minY: n.minY,
|
|
4189
|
+
maxX: n.maxX,
|
|
4190
|
+
maxY: n.maxY,
|
|
4191
|
+
children: [],
|
|
4192
|
+
};
|
|
4193
|
+
}
|
|
4194
|
+
/** Compare role/label/value/hint/stateFlags/traitFlags/headingLevel. */
|
|
4195
|
+
function semanticFieldsDiffer(a, b) {
|
|
4196
|
+
return (a.role !== b.role ||
|
|
4197
|
+
a.label !== b.label ||
|
|
4198
|
+
a.value !== b.value ||
|
|
4199
|
+
a.hint !== b.hint ||
|
|
4200
|
+
a.stateFlags !== b.stateFlags ||
|
|
4201
|
+
a.traitFlags !== b.traitFlags ||
|
|
4202
|
+
a.headingLevel !== b.headingLevel);
|
|
4203
|
+
}
|
|
4204
|
+
/** Compare only bounds (minX/minY/maxX/maxY). */
|
|
4205
|
+
function geometryFieldsDiffer(a, b) {
|
|
4206
|
+
return (a.minX !== b.minX ||
|
|
4207
|
+
a.minY !== b.minY ||
|
|
4208
|
+
a.maxX !== b.maxX ||
|
|
4209
|
+
a.maxY !== b.maxY);
|
|
4210
|
+
}
|
|
4211
|
+
function applySemantic(target, src) {
|
|
4212
|
+
target.role = src.role;
|
|
4213
|
+
target.label = src.label;
|
|
4214
|
+
target.value = src.value;
|
|
4215
|
+
target.hint = src.hint;
|
|
4216
|
+
target.stateFlags = src.stateFlags;
|
|
4217
|
+
target.traitFlags = src.traitFlags;
|
|
4218
|
+
target.headingLevel = src.headingLevel;
|
|
4219
|
+
}
|
|
4220
|
+
function applyGeometry(target, src) {
|
|
4221
|
+
target.minX = src.minX;
|
|
4222
|
+
target.minY = src.minY;
|
|
4223
|
+
target.maxX = src.maxX;
|
|
4224
|
+
target.maxY = src.maxY;
|
|
4225
|
+
}
|
|
4226
|
+
|
|
4227
|
+
|
|
4228
|
+
/***/ }),
|
|
4229
|
+
/* 8 */
|
|
4230
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
4231
|
+
|
|
4232
|
+
__webpack_require__.r(__webpack_exports__);
|
|
4233
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
4234
|
+
/* harmony export */ SemanticActionType: () => (/* binding */ SemanticActionType),
|
|
4235
|
+
/* harmony export */ SemanticMode: () => (/* binding */ SemanticMode),
|
|
4236
|
+
/* harmony export */ SemanticRole: () => (/* binding */ SemanticRole),
|
|
4237
|
+
/* harmony export */ SemanticState: () => (/* binding */ SemanticState),
|
|
4238
|
+
/* harmony export */ SemanticTrait: () => (/* binding */ SemanticTrait),
|
|
4239
|
+
/* harmony export */ hasState: () => (/* binding */ hasState),
|
|
4240
|
+
/* harmony export */ hasTrait: () => (/* binding */ hasTrait),
|
|
4241
|
+
/* harmony export */ roleName: () => (/* binding */ roleName),
|
|
4242
|
+
/* harmony export */ stateNames: () => (/* binding */ stateNames),
|
|
4243
|
+
/* harmony export */ traitNames: () => (/* binding */ traitNames)
|
|
4244
|
+
/* harmony export */ });
|
|
4245
|
+
// ---------------------------------------------------------------------------
|
|
4246
|
+
// SemanticRole — mirrors rive::SemanticRole
|
|
4247
|
+
// ---------------------------------------------------------------------------
|
|
4248
|
+
var SemanticRole = {
|
|
4249
|
+
none: 0,
|
|
4250
|
+
button: 1,
|
|
4251
|
+
link: 2,
|
|
4252
|
+
checkbox: 3,
|
|
4253
|
+
switchControl: 4,
|
|
4254
|
+
slider: 5,
|
|
4255
|
+
textField: 6,
|
|
4256
|
+
text: 7,
|
|
4257
|
+
image: 8,
|
|
4258
|
+
group: 9,
|
|
4259
|
+
list: 10,
|
|
4260
|
+
listItem: 11,
|
|
4261
|
+
tab: 12,
|
|
4262
|
+
tabList: 13,
|
|
4263
|
+
dialog: 14,
|
|
4264
|
+
alertDialog: 15,
|
|
4265
|
+
radioGroup: 16,
|
|
4266
|
+
radioButton: 17,
|
|
4267
|
+
};
|
|
4268
|
+
// ---------------------------------------------------------------------------
|
|
4269
|
+
// SemanticState — mirrors rive::SemanticState bitmask
|
|
4270
|
+
//
|
|
4271
|
+
// Bits 0-7 are trait-gated (only meaningful when the corresponding
|
|
4272
|
+
// SemanticTrait is set). Bits 8-13 are non-trait states.
|
|
4273
|
+
// ---------------------------------------------------------------------------
|
|
4274
|
+
var SemanticState = {
|
|
4275
|
+
None: 0,
|
|
4276
|
+
// Trait-gated
|
|
4277
|
+
Expanded: 1 << 0, // requires Expandable
|
|
4278
|
+
Selected: 1 << 1, // requires Selectable
|
|
4279
|
+
Checked: 1 << 2, // requires Checkable
|
|
4280
|
+
Mixed: 1 << 3, // requires Checkable; wins over Checked
|
|
4281
|
+
Toggled: 1 << 4, // requires Toggleable
|
|
4282
|
+
Required: 1 << 5, // requires Requirable
|
|
4283
|
+
Disabled: 1 << 6, // requires Enablable
|
|
4284
|
+
Focused: 1 << 7, // requires Focusable
|
|
4285
|
+
// Non-trait
|
|
4286
|
+
Hidden: 1 << 8,
|
|
4287
|
+
LiveRegion: 1 << 9,
|
|
4288
|
+
ReadOnly: 1 << 10,
|
|
4289
|
+
Modal: 1 << 11,
|
|
4290
|
+
Obscured: 1 << 12,
|
|
4291
|
+
Multiline: 1 << 13,
|
|
4292
|
+
};
|
|
4293
|
+
function hasState(flags, state) {
|
|
4294
|
+
return (flags & state) !== 0;
|
|
4295
|
+
}
|
|
4296
|
+
/**
|
|
4297
|
+
* Controls when the instance builds semantic trees and accessibility overlays.
|
|
4298
|
+
*
|
|
4299
|
+
* - `disabled`: no semantics work.
|
|
4300
|
+
* - `enabled`: semantics and overlay are active immediately after load.
|
|
4301
|
+
*/
|
|
4302
|
+
var SemanticMode = {
|
|
4303
|
+
Disabled: "disabled",
|
|
4304
|
+
Enabled: "enabled",
|
|
4305
|
+
};
|
|
4306
|
+
// ---------------------------------------------------------------------------
|
|
4307
|
+
// SemanticTrait — mirrors rive::SemanticTrait bitmask
|
|
4308
|
+
//
|
|
4309
|
+
// Traits declare what *capabilities* a node has. A state flag is only
|
|
4310
|
+
// meaningful when its corresponding trait is set.
|
|
4311
|
+
// ---------------------------------------------------------------------------
|
|
4312
|
+
var SemanticTrait = {
|
|
4313
|
+
None: 0,
|
|
4314
|
+
Expandable: 1 << 0,
|
|
4315
|
+
Selectable: 1 << 1,
|
|
4316
|
+
Checkable: 1 << 2,
|
|
4317
|
+
Toggleable: 1 << 3,
|
|
4318
|
+
Requirable: 1 << 4,
|
|
4319
|
+
Enablable: 1 << 5,
|
|
4320
|
+
Focusable: 1 << 6,
|
|
4321
|
+
};
|
|
4322
|
+
function hasTrait(flags, trait) {
|
|
4323
|
+
return (flags & trait) !== 0;
|
|
4324
|
+
}
|
|
4325
|
+
// ---------------------------------------------------------------------------
|
|
4326
|
+
// SemanticActionType — mirrors rive::SemanticActionType
|
|
4327
|
+
// ---------------------------------------------------------------------------
|
|
4328
|
+
var SemanticActionType = {
|
|
4329
|
+
tap: 0,
|
|
4330
|
+
increase: 1,
|
|
4331
|
+
decrease: 2,
|
|
4332
|
+
};
|
|
4333
|
+
// ---------------------------------------------------------------------------
|
|
4334
|
+
// Helpers — readable names for bitmask flags
|
|
4335
|
+
// ---------------------------------------------------------------------------
|
|
4336
|
+
var _roleNames = {};
|
|
4337
|
+
for (var _i = 0, _a = Object.entries(SemanticRole); _i < _a.length; _i++) {
|
|
4338
|
+
var _b = _a[_i], name_1 = _b[0], val = _b[1];
|
|
4339
|
+
_roleNames[val] = name_1;
|
|
4340
|
+
}
|
|
4341
|
+
var _stateEntries = Object.entries(SemanticState).filter(function (_a) {
|
|
4342
|
+
var v = _a[1];
|
|
4343
|
+
return v !== 0;
|
|
4344
|
+
});
|
|
4345
|
+
var _traitEntries = Object.entries(SemanticTrait).filter(function (_a) {
|
|
4346
|
+
var v = _a[1];
|
|
4347
|
+
return v !== 0;
|
|
4348
|
+
});
|
|
4349
|
+
function roleName(role) {
|
|
4350
|
+
var _a;
|
|
4351
|
+
return (_a = _roleNames[role]) !== null && _a !== void 0 ? _a : "unknown(".concat(role, ")");
|
|
4352
|
+
}
|
|
4353
|
+
function stateNames(flags) {
|
|
4354
|
+
if (flags === 0)
|
|
4355
|
+
return "none";
|
|
4356
|
+
var active = [];
|
|
4357
|
+
for (var _i = 0, _stateEntries_1 = _stateEntries; _i < _stateEntries_1.length; _i++) {
|
|
4358
|
+
var _a = _stateEntries_1[_i], name_2 = _a[0], bit = _a[1];
|
|
4359
|
+
if (flags & bit)
|
|
4360
|
+
active.push(name_2);
|
|
4361
|
+
}
|
|
4362
|
+
return active.join(", ") || "none";
|
|
4363
|
+
}
|
|
4364
|
+
function traitNames(flags) {
|
|
4365
|
+
if (flags === 0)
|
|
4366
|
+
return "none";
|
|
4367
|
+
var active = [];
|
|
4368
|
+
for (var _i = 0, _traitEntries_1 = _traitEntries; _i < _traitEntries_1.length; _i++) {
|
|
4369
|
+
var _a = _traitEntries_1[_i], name_3 = _a[0], bit = _a[1];
|
|
4370
|
+
if (flags & bit)
|
|
4371
|
+
active.push(name_3);
|
|
4372
|
+
}
|
|
4373
|
+
return active.join(", ") || "none";
|
|
4374
|
+
}
|
|
4375
|
+
|
|
4376
|
+
|
|
4377
|
+
/***/ }),
|
|
4378
|
+
/* 9 */
|
|
4379
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
4380
|
+
|
|
4381
|
+
__webpack_require__.r(__webpack_exports__);
|
|
4382
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
4383
|
+
/* harmony export */ AccessibilityOverlay: () => (/* binding */ AccessibilityOverlay)
|
|
4384
|
+
/* harmony export */ });
|
|
4385
|
+
/* harmony import */ var _types__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(8);
|
|
4386
|
+
|
|
4387
|
+
/**
|
|
4388
|
+
* Creates and manages an invisible DOM tree overlaying a Rive canvas. This is for
|
|
4389
|
+
* screen readers to discover and interact with the Rive content.
|
|
4390
|
+
*
|
|
4391
|
+
* Each semantic node in the {@link SemanticTreeModel} gets a corresponding
|
|
4392
|
+
* DOM element with appropriate ARIA role, states, and action handlers so
|
|
4393
|
+
* assistive technologies (i.e. screen readers) can discover
|
|
4394
|
+
* and interact with the Rive content.
|
|
4395
|
+
*
|
|
4396
|
+
* Each node receives a prefixed ID (`id=rive-{instanceId}-sem-{nodeId}`) to avoid host-page ID collisions.
|
|
4397
|
+
* The nodeID is Rive's semantic node ID from core runtime.
|
|
4398
|
+
* Each node is styled with `pointer-events: none`. Interactive nodes can receive
|
|
4399
|
+
* programmatic focus and keydown events without entering the browser Tab order.
|
|
4400
|
+
*/
|
|
4401
|
+
var AccessibilityOverlay = /** @class */ (function () {
|
|
4402
|
+
function AccessibilityOverlay(options) {
|
|
4403
|
+
var _this = this;
|
|
4404
|
+
var _a;
|
|
4405
|
+
this.elements = new Map();
|
|
4406
|
+
/** Visually-hidden description spans keyed by node ID, referenced by aria-describedby. */
|
|
4407
|
+
this.descElements = new Map();
|
|
4408
|
+
this.lastSemanticVersion = -1;
|
|
4409
|
+
this.lastGeometryVersion = -1;
|
|
4410
|
+
/** Text elements whose fit-scale needs recomputing, batched per update (see flushTextGeometry). */
|
|
4411
|
+
this.pendingTextGeometry = [];
|
|
4412
|
+
/** Last measured box-size|text key per text element, to skip redundant re-measures. */
|
|
4413
|
+
this.textGeometryKeys = new WeakMap();
|
|
4414
|
+
this.lastCanvasPositioning = {
|
|
4415
|
+
width: -1, height: -1, offsetTop: -1, offsetLeft: -1,
|
|
4416
|
+
};
|
|
4417
|
+
/**
|
|
4418
|
+
* Set when a ResizeObserver/window-resize signals the canvas geometry may have
|
|
4419
|
+
* changed, cleared once the transform is re-synced. Lets {@link needsUpdate}
|
|
4420
|
+
* report geometry changes without a per-frame `getBoundingClientRect()` reflow.
|
|
4421
|
+
* Starts true so the first update computes the transform.
|
|
4422
|
+
*/
|
|
4423
|
+
this._geometryDirty = true;
|
|
4424
|
+
/** True while reconciling the DOM (reserved for future focus-sync guards). */
|
|
4425
|
+
this.isUpdating = false;
|
|
4426
|
+
/**
|
|
4427
|
+
* Single child div of the overlay container that carries the artboard→CSS
|
|
4428
|
+
* transform. All semantic node elements are children of this div and express
|
|
4429
|
+
* their positions in raw artboard-space coordinates. The CSS transform on
|
|
4430
|
+
* this container maps artboard units to CSS pixels in one GPU pass — no
|
|
4431
|
+
* per-node matrix multiplication required.
|
|
4432
|
+
*/
|
|
4433
|
+
this.transformContainer = null;
|
|
4434
|
+
this._artboardBounds = { minX: 0, minY: 0, maxX: 0, maxY: 0 };
|
|
4435
|
+
this.repositionTimer = null;
|
|
4436
|
+
this.canvasResizeObserver = null;
|
|
4437
|
+
this.parentResizeObserver = null;
|
|
4438
|
+
/**
|
|
4439
|
+
* Detects canvas *position* drift. See {@link observePosition}.
|
|
4440
|
+
*/
|
|
4441
|
+
this.positionObserver = null;
|
|
4442
|
+
this._onWindowResize = function () { return _this.scheduleReposition(); };
|
|
4443
|
+
this.instanceId = options.instanceId;
|
|
4444
|
+
this.fireAction = options.fireAction;
|
|
4445
|
+
this.requestFocus = options.requestFocus;
|
|
4446
|
+
this.clearFocus = options.clearFocus;
|
|
4447
|
+
this.canvas = options.canvas;
|
|
4448
|
+
this.semanticsOptions = options.semanticsOptions;
|
|
4449
|
+
this.allowFocusInterrupt = (_a = options.allowFocusInterrupt) !== null && _a !== void 0 ? _a : false;
|
|
4450
|
+
this.container = this.createContainer(options.canvas);
|
|
4451
|
+
this.attachPositionObservers();
|
|
4452
|
+
}
|
|
4453
|
+
AccessibilityOverlay.prototype.getSemanticOverlayContainer = function () {
|
|
4454
|
+
return this.container;
|
|
4455
|
+
};
|
|
4456
|
+
// ---- Container lifecycle ----
|
|
4457
|
+
// Keep the a11y tree overlay matched to the canvas's position and size:
|
|
4458
|
+
// 1. The canvas resized — ResizeObserver
|
|
4459
|
+
// 2. The canvas's parent resized — ResizeObserver
|
|
4460
|
+
// 3. The window resized — resize event
|
|
4461
|
+
// 4. The canvas moved/drifted — IntersectionObserver (see observePosition)
|
|
4462
|
+
AccessibilityOverlay.prototype.attachPositionObservers = function () {
|
|
4463
|
+
var _this = this;
|
|
4464
|
+
this.canvasResizeObserver = new ResizeObserver(function () { return _this.scheduleReposition(); });
|
|
4465
|
+
this.canvasResizeObserver.observe(this.canvas);
|
|
4466
|
+
var parent = this.canvas.parentElement;
|
|
4467
|
+
if (parent) {
|
|
4468
|
+
this.parentResizeObserver = new ResizeObserver(function () { return _this.scheduleReposition(); });
|
|
4469
|
+
this.parentResizeObserver.observe(parent);
|
|
4470
|
+
}
|
|
4471
|
+
window.addEventListener("resize", this._onWindowResize);
|
|
4472
|
+
this.observePosition();
|
|
4473
|
+
};
|
|
4474
|
+
/**
|
|
4475
|
+
* Arms an IntersectionObserver whose root box is bounded to the canvas, so it
|
|
4476
|
+
* fires when the canvas moves relative to the viewport — position drift that
|
|
4477
|
+
* no ResizeObserver reports. Lets us re-sync the overlay container on a move
|
|
4478
|
+
* instead of recalculating the canvas bounding box every frame.
|
|
4479
|
+
*/
|
|
4480
|
+
AccessibilityOverlay.prototype.observePosition = function () {
|
|
4481
|
+
var _this = this;
|
|
4482
|
+
var _a;
|
|
4483
|
+
if (typeof IntersectionObserver === "undefined")
|
|
4484
|
+
return;
|
|
4485
|
+
(_a = this.positionObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
4486
|
+
this.positionObserver = null;
|
|
4487
|
+
var rect = this.canvas.getBoundingClientRect();
|
|
4488
|
+
// Can't frame a zero-area element; it will re-arm on the next reposition.
|
|
4489
|
+
if (!rect.width || !rect.height)
|
|
4490
|
+
return;
|
|
4491
|
+
// Shrink the viewport root box down to exactly the canvas: a negative inset
|
|
4492
|
+
// from each viewport edge to the matching canvas edge, in CSS shorthand
|
|
4493
|
+
// order (top, right, bottom, left). Rounded so sub-pixel jitter doesn't trip
|
|
4494
|
+
// the 1.0 threshold.
|
|
4495
|
+
var insetToPx = function (v) { return "".concat(-Math.round(v), "px"); };
|
|
4496
|
+
var rootMargin = [
|
|
4497
|
+
rect.top, // top: viewport top → canvas top
|
|
4498
|
+
window.innerWidth - rect.right, // right: viewport right → canvas right
|
|
4499
|
+
window.innerHeight - rect.bottom, // bottom: viewport bottom → canvas bottom
|
|
4500
|
+
rect.left, // left: viewport left → canvas left
|
|
4501
|
+
]
|
|
4502
|
+
.map(insetToPx)
|
|
4503
|
+
.join(" ");
|
|
4504
|
+
// The observer emits an initial notification for the current (contained)
|
|
4505
|
+
// state; ignore that and only react to a subsequent move.
|
|
4506
|
+
var armed = false;
|
|
4507
|
+
this.positionObserver = new IntersectionObserver(function () {
|
|
4508
|
+
if (!armed) {
|
|
4509
|
+
armed = true;
|
|
4510
|
+
return;
|
|
4511
|
+
}
|
|
4512
|
+
_this.scheduleReposition();
|
|
4513
|
+
}, { threshold: 1.0, rootMargin: rootMargin });
|
|
4514
|
+
this.positionObserver.observe(this.canvas);
|
|
4515
|
+
};
|
|
4516
|
+
AccessibilityOverlay.prototype.scheduleReposition = function () {
|
|
4517
|
+
var _this = this;
|
|
4518
|
+
// A resize/move may have changed canvas size/scale/position; force a
|
|
4519
|
+
// transform recompute on the next frame's update.
|
|
4520
|
+
this._geometryDirty = true;
|
|
4521
|
+
if (this.repositionTimer !== null)
|
|
4522
|
+
return;
|
|
4523
|
+
this.repositionTimer = setTimeout(function () {
|
|
4524
|
+
_this.repositionTimer = null;
|
|
4525
|
+
_this.syncContainerGeometry();
|
|
4526
|
+
// Re-arm the position observer at the canvas's new location.
|
|
4527
|
+
_this.observePosition();
|
|
4528
|
+
}, 500); // Throttle to avoid rapid style recalculations
|
|
4529
|
+
};
|
|
4530
|
+
AccessibilityOverlay.prototype.syncContainerGeometry = function () {
|
|
4531
|
+
var rect = this.canvas.getBoundingClientRect();
|
|
4532
|
+
var top = this.canvas.offsetTop;
|
|
4533
|
+
var left = this.canvas.offsetLeft;
|
|
4534
|
+
if (rect.width === this.lastCanvasPositioning.width &&
|
|
4535
|
+
rect.height === this.lastCanvasPositioning.height &&
|
|
4536
|
+
top === this.lastCanvasPositioning.offsetTop &&
|
|
4537
|
+
left === this.lastCanvasPositioning.offsetLeft)
|
|
4538
|
+
return;
|
|
4539
|
+
this.container.style.top = top + "px";
|
|
4540
|
+
this.container.style.left = left + "px";
|
|
4541
|
+
this.container.style.width = rect.width + "px";
|
|
4542
|
+
this.container.style.height = rect.height + "px";
|
|
4543
|
+
this.container.tabIndex = -1;
|
|
4544
|
+
this.lastCanvasPositioning.width = rect.width;
|
|
4545
|
+
this.lastCanvasPositioning.height = rect.height;
|
|
4546
|
+
this.lastCanvasPositioning.offsetTop = top;
|
|
4547
|
+
this.lastCanvasPositioning.offsetLeft = left;
|
|
4548
|
+
};
|
|
4549
|
+
AccessibilityOverlay.prototype.createContainer = function (canvas) {
|
|
4550
|
+
var _a, _b;
|
|
4551
|
+
var container = document.createElement("div");
|
|
4552
|
+
container.id = "rive-a11y-".concat(this.instanceId);
|
|
4553
|
+
container.setAttribute("role", "region");
|
|
4554
|
+
container.setAttribute("aria-label", (_b = (_a = this.semanticsOptions) === null || _a === void 0 ? void 0 : _a.riveCanvasLabel) !== null && _b !== void 0 ? _b : "Rive animation");
|
|
4555
|
+
// Size to the canvas's CSS layout box, not the parent container.
|
|
4556
|
+
var rect = canvas.getBoundingClientRect();
|
|
4557
|
+
container.style.cssText = [
|
|
4558
|
+
"position:absolute",
|
|
4559
|
+
"top:".concat(canvas.offsetTop, "px"),
|
|
4560
|
+
"left:".concat(canvas.offsetLeft, "px"),
|
|
4561
|
+
"width:".concat(rect.width, "px"),
|
|
4562
|
+
"height:".concat(rect.height, "px"),
|
|
4563
|
+
"overflow:hidden",
|
|
4564
|
+
"pointer-events:none",
|
|
4565
|
+
// Visually hidden but still in the accessibility tree.
|
|
4566
|
+
// `display:none` and `visibility:hidden` would hide from AT.
|
|
4567
|
+
"opacity:0",
|
|
4568
|
+
].join(";");
|
|
4569
|
+
canvas.insertAdjacentElement("afterend", container);
|
|
4570
|
+
return container;
|
|
4571
|
+
};
|
|
4572
|
+
/**
|
|
4573
|
+
* Returns what changed since the last update, or null if nothing changed.
|
|
4574
|
+
*
|
|
4575
|
+
* Callers use this to avoid recomputing the (relatively expensive)
|
|
4576
|
+
* artboard→canvas transform on frames where only node bounds changed in the
|
|
4577
|
+
* tree: the transform only needs recomputing when `layoutChanged` is true.
|
|
4578
|
+
*/
|
|
4579
|
+
AccessibilityOverlay.prototype.needsUpdate = function (tree) {
|
|
4580
|
+
var semanticChanged = tree.semanticVersion !== this.lastSemanticVersion;
|
|
4581
|
+
var nodeGeometryChanged = tree.geometryVersion !== this.lastGeometryVersion;
|
|
4582
|
+
var layoutChanged = this._geometryDirty || !this.transformContainer;
|
|
4583
|
+
if (!semanticChanged && !nodeGeometryChanged && !layoutChanged)
|
|
4584
|
+
return null;
|
|
4585
|
+
return { semanticChanged: semanticChanged, nodeGeometryChanged: nodeGeometryChanged, layoutChanged: layoutChanged };
|
|
4586
|
+
};
|
|
4587
|
+
/**
|
|
4588
|
+
* Update the overlay DOM to reflect the current state of the semantic tree.
|
|
4589
|
+
* Call once per frame after `applyDiff` when {@link needsUpdate} reports a
|
|
4590
|
+
* change, when layout/transform inputs are dirty, or when a fresh
|
|
4591
|
+
* `forwardMat` is supplied (even if the tree versions are unchanged).
|
|
4592
|
+
*
|
|
4593
|
+
* @param tree The in-memory semantic tree model
|
|
4594
|
+
* @param forwardMat Artboard→canvas-pixel transform from `computeAlignment`,
|
|
4595
|
+
* or null to reuse the existing CSS transform on the
|
|
4596
|
+
* transform container
|
|
4597
|
+
* @param dpr Device pixel ratio used for the canvas backing store
|
|
4598
|
+
* @param artboardBounds The artboard's own bounding rectangle
|
|
4599
|
+
*/
|
|
4600
|
+
AccessibilityOverlay.prototype.update = function (tree, forwardMat, dpr, artboardBounds, change) {
|
|
4601
|
+
var overlayChange = change !== null && change !== void 0 ? change : this.needsUpdate(tree);
|
|
4602
|
+
if (!overlayChange && forwardMat) {
|
|
4603
|
+
overlayChange = {
|
|
4604
|
+
semanticChanged: false,
|
|
4605
|
+
nodeGeometryChanged: false,
|
|
4606
|
+
layoutChanged: true,
|
|
4607
|
+
};
|
|
4608
|
+
}
|
|
4609
|
+
if (!overlayChange)
|
|
4610
|
+
return;
|
|
4611
|
+
this.performUpdate(tree, forwardMat, dpr, artboardBounds, overlayChange);
|
|
4612
|
+
};
|
|
4613
|
+
AccessibilityOverlay.prototype.performUpdate = function (tree, forwardMat, dpr, artboardBounds, change) {
|
|
4614
|
+
var _a;
|
|
4615
|
+
var semanticChanged = change.semanticChanged, nodeGeometryChanged = change.nodeGeometryChanged;
|
|
4616
|
+
// Per-node change sets only describe the most recent applyDiff. If more
|
|
4617
|
+
// than one semantic version elapsed since our last update (first build,
|
|
4618
|
+
// or a diff we never consumed), fall back to re-applying attributes on
|
|
4619
|
+
// every node rather than trusting an incomplete set.
|
|
4620
|
+
var reapplyAllAttributes = tree.semanticVersion - this.lastSemanticVersion > 1;
|
|
4621
|
+
this.lastSemanticVersion = tree.semanticVersion;
|
|
4622
|
+
this.lastGeometryVersion = tree.geometryVersion;
|
|
4623
|
+
this.isUpdating = true;
|
|
4624
|
+
this._artboardBounds = artboardBounds;
|
|
4625
|
+
// Container box + artboard transform only run when a fresh forwardMat was
|
|
4626
|
+
// supplied (layout/transform dirty). Node-only bounds updates reuse the
|
|
4627
|
+
// existing CSS transform and go through updateGeometryForChangedNodes.
|
|
4628
|
+
// Skipping syncContainerGeometry here on semantic-only frames avoids a
|
|
4629
|
+
// getBoundingClientRect() reflow on every animation frame. The throttled
|
|
4630
|
+
// scheduleReposition() path still keeps the container aligned when the page
|
|
4631
|
+
// layout shifts.
|
|
4632
|
+
if (forwardMat) {
|
|
4633
|
+
this.syncContainerGeometry();
|
|
4634
|
+
this.syncTransformContainer(forwardMat, dpr, artboardBounds);
|
|
4635
|
+
// Transform is now in sync with the latest layout.
|
|
4636
|
+
this._geometryDirty = false;
|
|
4637
|
+
}
|
|
4638
|
+
if (semanticChanged) {
|
|
4639
|
+
var rootEl = (_a = this.transformContainer) !== null && _a !== void 0 ? _a : this.container;
|
|
4640
|
+
var activeIds_1 = new Set();
|
|
4641
|
+
this.rebuildChildren(rootEl, tree.roots, tree, 0, // parentLeft in artboard space (transform container origin)
|
|
4642
|
+
0, // parentTop in artboard space
|
|
4643
|
+
activeIds_1, reapplyAllAttributes);
|
|
4644
|
+
var staleIds_2 = [];
|
|
4645
|
+
this.elements.forEach(function (_el, id) {
|
|
4646
|
+
if (!activeIds_1.has(id))
|
|
4647
|
+
staleIds_2.push(id);
|
|
4648
|
+
});
|
|
4649
|
+
for (var _i = 0, staleIds_1 = staleIds_2; _i < staleIds_1.length; _i++) {
|
|
4650
|
+
var id = staleIds_1[_i];
|
|
4651
|
+
var el = this.elements.get(id);
|
|
4652
|
+
if (el && el.parentNode)
|
|
4653
|
+
el.parentNode.removeChild(el);
|
|
4654
|
+
this.elements.delete(id);
|
|
4655
|
+
var desc = this.descElements.get(id);
|
|
4656
|
+
if (desc && desc.parentNode)
|
|
4657
|
+
desc.parentNode.removeChild(desc);
|
|
4658
|
+
this.descElements.delete(id);
|
|
4659
|
+
}
|
|
4660
|
+
}
|
|
4661
|
+
else if (nodeGeometryChanged) {
|
|
4662
|
+
this.updateGeometryForChangedNodes(tree);
|
|
4663
|
+
}
|
|
4664
|
+
// Text scaling needs layout reads; batch them into one pass after all
|
|
4665
|
+
// position/attribute writes so each frame forces at most one reflow.
|
|
4666
|
+
this.flushTextGeometry();
|
|
4667
|
+
this.isUpdating = false;
|
|
4668
|
+
};
|
|
4669
|
+
/** Remove the overlay from the DOM entirely. */
|
|
4670
|
+
AccessibilityOverlay.prototype.destroy = function () {
|
|
4671
|
+
var _a, _b, _c;
|
|
4672
|
+
if (this.repositionTimer !== null) {
|
|
4673
|
+
clearTimeout(this.repositionTimer);
|
|
4674
|
+
this.repositionTimer = null;
|
|
4675
|
+
}
|
|
4676
|
+
window.removeEventListener("resize", this._onWindowResize);
|
|
4677
|
+
(_a = this.canvasResizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
4678
|
+
(_b = this.parentResizeObserver) === null || _b === void 0 ? void 0 : _b.disconnect();
|
|
4679
|
+
(_c = this.positionObserver) === null || _c === void 0 ? void 0 : _c.disconnect();
|
|
4680
|
+
if (this.container.parentNode) {
|
|
4681
|
+
this.container.parentNode.removeChild(this.container);
|
|
4682
|
+
}
|
|
4683
|
+
this.elements.clear();
|
|
4684
|
+
this.descElements.clear();
|
|
4685
|
+
this.pendingTextGeometry.length = 0;
|
|
4686
|
+
};
|
|
4687
|
+
// ---- Tree → DOM reconciliation ----
|
|
4688
|
+
/**
|
|
4689
|
+
* Reconcile a parent DOM element's children with an ordered list of
|
|
4690
|
+
* semantic node IDs. Creates, updates, and reorders elements as needed.
|
|
4691
|
+
*
|
|
4692
|
+
* Node positions are expressed in artboard-space coordinates. The CSS
|
|
4693
|
+
* transform on the transform container maps artboard units to CSS pixels,
|
|
4694
|
+
* so no per-node matrix multiplication is required here.
|
|
4695
|
+
*
|
|
4696
|
+
* @param parentArtboardLeft Absolute artboard minX of the parent node (0 for roots)
|
|
4697
|
+
* @param parentArtboardTop Absolute artboard minY of the parent node (0 for roots)
|
|
4698
|
+
*/
|
|
4699
|
+
AccessibilityOverlay.prototype.rebuildChildren = function (parentEl, childIds, tree, parentArtboardLeft, parentArtboardTop, activeIds, applyAllAttributes) {
|
|
4700
|
+
for (var i = 0; i < childIds.length; i++) {
|
|
4701
|
+
var nodeId = childIds[i];
|
|
4702
|
+
var nodeData = tree.nodeById(nodeId);
|
|
4703
|
+
if (!nodeData)
|
|
4704
|
+
continue;
|
|
4705
|
+
activeIds.add(nodeId);
|
|
4706
|
+
var el = this.elements.get(nodeId);
|
|
4707
|
+
var isNew = !el;
|
|
4708
|
+
if (!el) {
|
|
4709
|
+
el = this.createElement(nodeData);
|
|
4710
|
+
this.elements.set(nodeId, el);
|
|
4711
|
+
}
|
|
4712
|
+
// Attributes are only applied to new elements and nodes whose semantic
|
|
4713
|
+
// fields changed in the latest diff. Skipping redundant setAttribute
|
|
4714
|
+
// calls eliminates WebKit AX notifications that knock VoiceOver off its
|
|
4715
|
+
// current element.
|
|
4716
|
+
if (isNew || applyAllAttributes || tree.semanticChangedIds.has(nodeId)) {
|
|
4717
|
+
this.applyAttributes(el, nodeData);
|
|
4718
|
+
}
|
|
4719
|
+
this.applyPosition(el, nodeData, parentArtboardLeft, parentArtboardTop);
|
|
4720
|
+
// Only touch the DOM tree if the element isn't already in the correct
|
|
4721
|
+
// position. Moving a focused element can blur it and knock AT off the
|
|
4722
|
+
// current node.
|
|
4723
|
+
var currentChild = parentEl.children[i];
|
|
4724
|
+
if (currentChild !== el) {
|
|
4725
|
+
if (currentChild) {
|
|
4726
|
+
parentEl.insertBefore(el, currentChild);
|
|
4727
|
+
}
|
|
4728
|
+
else {
|
|
4729
|
+
parentEl.appendChild(el);
|
|
4730
|
+
}
|
|
4731
|
+
}
|
|
4732
|
+
// Reflect the runtime Focused state into DOM focus. Runs after insertion
|
|
4733
|
+
// so the element is attached, and skips elements that already hold focus.
|
|
4734
|
+
// The cheap trait/state flag checks gate the (per-node) DOM queries below,
|
|
4735
|
+
// so the activeElement/closest/contains walks only run for a node that is
|
|
4736
|
+
// actually focusable + focused — not for every node on every frame.
|
|
4737
|
+
if ((0,_types__WEBPACK_IMPORTED_MODULE_0__.hasTrait)(nodeData.traitFlags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticTrait.Focusable) &&
|
|
4738
|
+
(0,_types__WEBPACK_IMPORTED_MODULE_0__.hasState)(nodeData.stateFlags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticState.Focused)) {
|
|
4739
|
+
var active = document.activeElement;
|
|
4740
|
+
// While focus is inside one of our modal dialogs, don't pull it back
|
|
4741
|
+
// out to a background node.
|
|
4742
|
+
var focusedModal = active === null || active === void 0 ? void 0 : active.closest('[aria-modal="true"]');
|
|
4743
|
+
var trappedByModal = !!focusedModal &&
|
|
4744
|
+
this.container.contains(focusedModal) &&
|
|
4745
|
+
!focusedModal.contains(el);
|
|
4746
|
+
if (active !== el && !trappedByModal && this.canMoveFocus()) {
|
|
4747
|
+
el.focus();
|
|
4748
|
+
}
|
|
4749
|
+
}
|
|
4750
|
+
// Recurse into children with this node's absolute artboard position.
|
|
4751
|
+
if (nodeData.children.length > 0) {
|
|
4752
|
+
this.rebuildChildren(el, nodeData.children, tree, nodeData.minX, nodeData.minY, activeIds, applyAllAttributes);
|
|
4753
|
+
}
|
|
4754
|
+
// Focus a modal/alert dialog when it first appears (after children are
|
|
4755
|
+
// built so the focus target can be resolved from the subtree).
|
|
4756
|
+
if (isNew)
|
|
4757
|
+
this.autoFocusDialogOnAppear(el, nodeData, tree);
|
|
4758
|
+
}
|
|
4759
|
+
};
|
|
4760
|
+
/**
|
|
4761
|
+
* Reposition only the subtrees whose bounds changed in the latest diff.
|
|
4762
|
+
* Descendants are included because node CSS positions are parent-relative.
|
|
4763
|
+
*/
|
|
4764
|
+
AccessibilityOverlay.prototype.updateGeometryForChangedNodes = function (tree) {
|
|
4765
|
+
var _a, _b;
|
|
4766
|
+
for (var _i = 0, _c = Array.from(tree.geometryChangedIds); _i < _c.length; _i++) {
|
|
4767
|
+
var nodeId = _c[_i];
|
|
4768
|
+
var nodeData = tree.nodeById(nodeId);
|
|
4769
|
+
if (!nodeData)
|
|
4770
|
+
continue;
|
|
4771
|
+
var parentLeft = 0;
|
|
4772
|
+
var parentTop = 0;
|
|
4773
|
+
var parentEl = (_a = this.transformContainer) !== null && _a !== void 0 ? _a : this.container;
|
|
4774
|
+
if (nodeData.parentId >= 0) {
|
|
4775
|
+
var parent_1 = tree.nodeById(nodeData.parentId);
|
|
4776
|
+
if (parent_1) {
|
|
4777
|
+
parentLeft = parent_1.minX;
|
|
4778
|
+
parentTop = parent_1.minY;
|
|
4779
|
+
parentEl = (_b = this.elements.get(nodeData.parentId)) !== null && _b !== void 0 ? _b : parentEl;
|
|
4780
|
+
}
|
|
4781
|
+
}
|
|
4782
|
+
this.updateNodeGeometrySubtree(tree, nodeId, parentLeft, parentTop, parentEl);
|
|
4783
|
+
}
|
|
4784
|
+
};
|
|
4785
|
+
AccessibilityOverlay.prototype.updateNodeGeometrySubtree = function (tree, nodeId, parentArtboardLeft, parentArtboardTop, _parentEl) {
|
|
4786
|
+
var nodeData = tree.nodeById(nodeId);
|
|
4787
|
+
if (!nodeData)
|
|
4788
|
+
return;
|
|
4789
|
+
var el = this.elements.get(nodeId);
|
|
4790
|
+
if (!el)
|
|
4791
|
+
return;
|
|
4792
|
+
this.applyPosition(el, nodeData, parentArtboardLeft, parentArtboardTop);
|
|
4793
|
+
for (var _i = 0, _a = nodeData.children; _i < _a.length; _i++) {
|
|
4794
|
+
var childId = _a[_i];
|
|
4795
|
+
this.updateNodeGeometrySubtree(tree, childId, nodeData.minX, nodeData.minY, el);
|
|
4796
|
+
}
|
|
4797
|
+
};
|
|
4798
|
+
/**
|
|
4799
|
+
* Whether the overlay may move focus now. Following focus already inside this
|
|
4800
|
+
* instance is always allowed; pulling it in from the host page is gated behind
|
|
4801
|
+
* allowFocusInterrupt (from the Rive class).
|
|
4802
|
+
*/
|
|
4803
|
+
AccessibilityOverlay.prototype.canMoveFocus = function () {
|
|
4804
|
+
var active = document.activeElement;
|
|
4805
|
+
var focusAlreadyInScope = active === this.canvas || this.container.contains(active);
|
|
4806
|
+
return focusAlreadyInScope || this.allowFocusInterrupt;
|
|
4807
|
+
};
|
|
4808
|
+
/**
|
|
4809
|
+
* Move focus into a newly appeared modal/alert dialog so screen readers
|
|
4810
|
+
* announce and read its content (web ATs don't auto-enter a freshly mounted
|
|
4811
|
+
* dialog). Skips when focus can't move (see canMoveFocus) or a descendant
|
|
4812
|
+
* already holds it. The dialog's aria-modal keeps focus trapped inside.
|
|
4813
|
+
*/
|
|
4814
|
+
AccessibilityOverlay.prototype.autoFocusDialogOnAppear = function (el, node, tree) {
|
|
4815
|
+
var _a;
|
|
4816
|
+
if (!isModalDialogRole(node.role, node.stateFlags))
|
|
4817
|
+
return;
|
|
4818
|
+
if (!this.canMoveFocus())
|
|
4819
|
+
return;
|
|
4820
|
+
// A descendant already holds focus — don't override it.
|
|
4821
|
+
var active = document.activeElement;
|
|
4822
|
+
if (active && active !== el && el.contains(active))
|
|
4823
|
+
return;
|
|
4824
|
+
var target = (_a = this.routeDefaultFocusTarget(node, tree)) !== null && _a !== void 0 ? _a : el;
|
|
4825
|
+
if (!target.hasAttribute("tabindex"))
|
|
4826
|
+
target.setAttribute("tabindex", "-1");
|
|
4827
|
+
if (document.activeElement !== target)
|
|
4828
|
+
target.focus({ preventScroll: true });
|
|
4829
|
+
};
|
|
4830
|
+
/**
|
|
4831
|
+
* Resolve the element assistive technologies (AT) should focus on appearance. Walks the subtree
|
|
4832
|
+
* depth-first and returns the first focusable node's host element, else the
|
|
4833
|
+
* inner <span> of the first labeled leaf. Container and unlabeled nodes are
|
|
4834
|
+
* descended into but never focused. Returns null if nothing qualifies.
|
|
4835
|
+
*/
|
|
4836
|
+
AccessibilityOverlay.prototype.routeDefaultFocusTarget = function (node, tree) {
|
|
4837
|
+
var _a;
|
|
4838
|
+
for (var _i = 0, _b = node.children; _i < _b.length; _i++) {
|
|
4839
|
+
var childId = _b[_i];
|
|
4840
|
+
var child = tree.nodeById(childId);
|
|
4841
|
+
if (!child)
|
|
4842
|
+
continue;
|
|
4843
|
+
var childEl = this.elements.get(childId);
|
|
4844
|
+
// Focusable node → its host element (even if it has children).
|
|
4845
|
+
if (childEl && isFocusableNode(child))
|
|
4846
|
+
return childEl;
|
|
4847
|
+
// Container or unlabeled node → descend without focusing it.
|
|
4848
|
+
if (child.children.length > 0 || !child.label) {
|
|
4849
|
+
var nested = this.routeDefaultFocusTarget(child, tree);
|
|
4850
|
+
if (nested)
|
|
4851
|
+
return nested;
|
|
4852
|
+
continue;
|
|
4853
|
+
}
|
|
4854
|
+
// Labeled leaf → its inner label span.
|
|
4855
|
+
if (childEl) {
|
|
4856
|
+
return (_a = childEl.querySelector(":scope > span")) !== null && _a !== void 0 ? _a : childEl;
|
|
4857
|
+
}
|
|
4858
|
+
}
|
|
4859
|
+
return null;
|
|
4860
|
+
};
|
|
4861
|
+
Object.defineProperty(AccessibilityOverlay.prototype, "nodeIdPrefix", {
|
|
4862
|
+
// ---- Element creation ----
|
|
4863
|
+
/** Shared `id` prefix for all semantic node elements of this instance. */
|
|
4864
|
+
get: function () {
|
|
4865
|
+
return "rive-".concat(this.instanceId, "-sem-");
|
|
4866
|
+
},
|
|
4867
|
+
enumerable: false,
|
|
4868
|
+
configurable: true
|
|
4869
|
+
});
|
|
4870
|
+
/** Recover the semantic node ID from an overlay element, or null. */
|
|
4871
|
+
AccessibilityOverlay.prototype.nodeIdFromElement = function (el) {
|
|
4872
|
+
if (!el.id.startsWith(this.nodeIdPrefix))
|
|
4873
|
+
return null;
|
|
4874
|
+
var raw = el.id.slice(this.nodeIdPrefix.length);
|
|
4875
|
+
// Guard the empty string explicitly: Number("") is 0, not NaN.
|
|
4876
|
+
if (!raw)
|
|
4877
|
+
return null;
|
|
4878
|
+
var id = Number(raw);
|
|
4879
|
+
return Number.isNaN(id) ? null : id;
|
|
4880
|
+
};
|
|
4881
|
+
AccessibilityOverlay.prototype.createElement = function (node) {
|
|
4882
|
+
var tag = tagForRole(node.role);
|
|
4883
|
+
var el = document.createElement(tag);
|
|
4884
|
+
el.id = "".concat(this.nodeIdPrefix).concat(node.id);
|
|
4885
|
+
el.style.cssText = BASE_NODE_STYLE;
|
|
4886
|
+
if (node.role === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.text) {
|
|
4887
|
+
// The positioned outer div is the AX element
|
|
4888
|
+
// VoiceOver uses for its highlight box; an inner <span> carries the text
|
|
4889
|
+
// without position:absolute (which would strip the span from VoiceOver's
|
|
4890
|
+
// bounds calculation).
|
|
4891
|
+
var textSpan = document.createElement("span");
|
|
4892
|
+
textSpan.style.cssText = SPAN_EXP;
|
|
4893
|
+
el.appendChild(textSpan);
|
|
4894
|
+
}
|
|
4895
|
+
this.attachActionHandlers(el, node);
|
|
4896
|
+
return el;
|
|
4897
|
+
};
|
|
4898
|
+
// ---- Action handlers ----
|
|
4899
|
+
/**
|
|
4900
|
+
* Wire arrow-key roving focus for a group member (tab, radio). Arrow keys
|
|
4901
|
+
* move focus to the next/previous member (wrapping), optionally Home/End jump
|
|
4902
|
+
* to first/last, and the newly focused member receives a tap action.
|
|
4903
|
+
*/
|
|
4904
|
+
AccessibilityOverlay.prototype.attachRovingNav = function (el, opts) {
|
|
4905
|
+
var _this = this;
|
|
4906
|
+
el.addEventListener("keydown", function (e) {
|
|
4907
|
+
var target = null;
|
|
4908
|
+
if (e.key === "ArrowRight" || e.key === "ArrowDown")
|
|
4909
|
+
target = "next";
|
|
4910
|
+
else if (e.key === "ArrowLeft" || e.key === "ArrowUp")
|
|
4911
|
+
target = "prev";
|
|
4912
|
+
else if (opts.includeHomeEnd && e.key === "Home")
|
|
4913
|
+
target = "first";
|
|
4914
|
+
else if (opts.includeHomeEnd && e.key === "End")
|
|
4915
|
+
target = "last";
|
|
4916
|
+
if (!target)
|
|
4917
|
+
return;
|
|
4918
|
+
e.preventDefault();
|
|
4919
|
+
var members = opts.members();
|
|
4920
|
+
var idx = members.indexOf(el);
|
|
4921
|
+
if (idx < 0)
|
|
4922
|
+
return;
|
|
4923
|
+
var n = members.length;
|
|
4924
|
+
var next = target === "next" ? members[(idx + 1) % n]
|
|
4925
|
+
: target === "prev" ? members[(idx - 1 + n) % n]
|
|
4926
|
+
: target === "first" ? members[0]
|
|
4927
|
+
: members[n - 1];
|
|
4928
|
+
if (next && next !== el) {
|
|
4929
|
+
next.focus();
|
|
4930
|
+
var nextId = _this.nodeIdFromElement(next);
|
|
4931
|
+
if (nextId !== null)
|
|
4932
|
+
_this.fireAction(nextId, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticActionType.tap);
|
|
4933
|
+
}
|
|
4934
|
+
});
|
|
4935
|
+
};
|
|
4936
|
+
AccessibilityOverlay.prototype.attachActionHandlers = function (el, node) {
|
|
4937
|
+
var _this = this;
|
|
4938
|
+
var role = node.role;
|
|
4939
|
+
var nodeId = node.id;
|
|
4940
|
+
if (isClickableRole(role)) {
|
|
4941
|
+
el.addEventListener("click", function () {
|
|
4942
|
+
_this.fireAction(nodeId, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticActionType.tap);
|
|
4943
|
+
});
|
|
4944
|
+
// Links activate on Enter only (Space scrolls the page per browser
|
|
4945
|
+
// convention). All other clickable roles accept both Enter and Space.
|
|
4946
|
+
var activationKeys_1 = role === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.link ? ["Enter"] : ["Enter", " "];
|
|
4947
|
+
el.addEventListener("keydown", function (e) {
|
|
4948
|
+
if (activationKeys_1.includes(e.key)) {
|
|
4949
|
+
e.preventDefault();
|
|
4950
|
+
_this.fireAction(nodeId, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticActionType.tap);
|
|
4951
|
+
}
|
|
4952
|
+
});
|
|
4953
|
+
}
|
|
4954
|
+
if (role === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.slider) {
|
|
4955
|
+
el.addEventListener("keydown", function (e) {
|
|
4956
|
+
if (e.key === "ArrowRight" || e.key === "ArrowUp") {
|
|
4957
|
+
e.preventDefault();
|
|
4958
|
+
_this.fireAction(nodeId, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticActionType.increase);
|
|
4959
|
+
}
|
|
4960
|
+
else if (e.key === "ArrowLeft" || e.key === "ArrowDown") {
|
|
4961
|
+
e.preventDefault();
|
|
4962
|
+
_this.fireAction(nodeId, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticActionType.decrease);
|
|
4963
|
+
}
|
|
4964
|
+
});
|
|
4965
|
+
}
|
|
4966
|
+
if (role === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.tab) {
|
|
4967
|
+
this.attachRovingNav(el, {
|
|
4968
|
+
includeHomeEnd: true,
|
|
4969
|
+
members: function () {
|
|
4970
|
+
var parent = el.parentElement;
|
|
4971
|
+
if (!parent)
|
|
4972
|
+
return [];
|
|
4973
|
+
return Array.from(parent.children).filter(function (c) {
|
|
4974
|
+
return c instanceof HTMLElement && c.getAttribute("role") === "tab";
|
|
4975
|
+
});
|
|
4976
|
+
},
|
|
4977
|
+
});
|
|
4978
|
+
}
|
|
4979
|
+
if (role === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.radioButton) {
|
|
4980
|
+
this.attachRovingNav(el, {
|
|
4981
|
+
includeHomeEnd: false,
|
|
4982
|
+
members: function () {
|
|
4983
|
+
var _a;
|
|
4984
|
+
var group = (_a = el.closest('[role="radiogroup"]')) !== null && _a !== void 0 ? _a : el.parentElement;
|
|
4985
|
+
if (!group)
|
|
4986
|
+
return [];
|
|
4987
|
+
return Array.from(group.querySelectorAll('[role="radio"]'));
|
|
4988
|
+
},
|
|
4989
|
+
});
|
|
4990
|
+
}
|
|
4991
|
+
// Focus handler for nodes with the Focusable trait. When AT focuses an
|
|
4992
|
+
// element, notify the C++ runtime so it can update internal focus state
|
|
4993
|
+
// (visual focus rings, etc.). Gated on Focusable trait
|
|
4994
|
+
if ((0,_types__WEBPACK_IMPORTED_MODULE_0__.hasTrait)(node.traitFlags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticTrait.Focusable)) {
|
|
4995
|
+
el.addEventListener("focus", function () {
|
|
4996
|
+
_this.requestFocus(nodeId);
|
|
4997
|
+
});
|
|
4998
|
+
}
|
|
4999
|
+
};
|
|
5000
|
+
// ---- Attribute application ----
|
|
5001
|
+
AccessibilityOverlay.prototype.applyAttributes = function (el, node) {
|
|
5002
|
+
var _a, _b, _c;
|
|
5003
|
+
var role = node.role;
|
|
5004
|
+
var flags = node.stateFlags;
|
|
5005
|
+
var traits = node.traitFlags;
|
|
5006
|
+
// Role
|
|
5007
|
+
var ariaRole = ariaRoleForSemantic(role);
|
|
5008
|
+
if (ariaRole) {
|
|
5009
|
+
setAttr(el, "role", ariaRole);
|
|
5010
|
+
}
|
|
5011
|
+
else {
|
|
5012
|
+
removeAttr(el, "role");
|
|
5013
|
+
}
|
|
5014
|
+
// Links: a bare <a> with no href has no link semantics, so set the role
|
|
5015
|
+
// explicitly (ariaRoleForSemantic returns null for link → native <a>).
|
|
5016
|
+
if (role === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.link) {
|
|
5017
|
+
setAttr(el, "role", "link");
|
|
5018
|
+
}
|
|
5019
|
+
// Tabindex — keep the screen-reader overlay out of the browser's sequential
|
|
5020
|
+
// Tab order. Interactive/focusable nodes remain programmatically focusable
|
|
5021
|
+
// so AT/runtime focus sync can still target them when needed. List items are
|
|
5022
|
+
// included because Mobile Safari won't iterate them otherwise.
|
|
5023
|
+
if (isInteractiveRole(role) ||
|
|
5024
|
+
(0,_types__WEBPACK_IMPORTED_MODULE_0__.hasTrait)(traits, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticTrait.Focusable) ||
|
|
5025
|
+
role === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.listItem) {
|
|
5026
|
+
setAttr(el, "tabindex", "-1");
|
|
5027
|
+
}
|
|
5028
|
+
else {
|
|
5029
|
+
removeAttr(el, "tabindex");
|
|
5030
|
+
}
|
|
5031
|
+
// Label / value / hint
|
|
5032
|
+
if (node.label) {
|
|
5033
|
+
setAttr(el, "aria-label", node.label);
|
|
5034
|
+
}
|
|
5035
|
+
else {
|
|
5036
|
+
removeAttr(el, "aria-label");
|
|
5037
|
+
}
|
|
5038
|
+
if (role === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.slider) {
|
|
5039
|
+
if (node.value) {
|
|
5040
|
+
// aria-valuenow must be numeric; keep the display string (e.g. "75%")
|
|
5041
|
+
// in aria-valuetext only.
|
|
5042
|
+
var numericValue = parseFloat(node.value);
|
|
5043
|
+
if (Number.isFinite(numericValue)) {
|
|
5044
|
+
setAttr(el, "aria-valuenow", String(numericValue));
|
|
5045
|
+
}
|
|
5046
|
+
else {
|
|
5047
|
+
removeAttr(el, "aria-valuenow");
|
|
5048
|
+
}
|
|
5049
|
+
setAttr(el, "aria-valuetext", node.value);
|
|
5050
|
+
}
|
|
5051
|
+
else {
|
|
5052
|
+
removeAttr(el, "aria-valuenow");
|
|
5053
|
+
removeAttr(el, "aria-valuetext");
|
|
5054
|
+
}
|
|
5055
|
+
// TODO: aria-valuemin / aria-valuemax are required by ARIA.
|
|
5056
|
+
// Defaulting to horizontal; vertical sliders need orientation data from C++.
|
|
5057
|
+
setAttr(el, "aria-orientation", "horizontal");
|
|
5058
|
+
setBoolAttr(el, "aria-readonly", (0,_types__WEBPACK_IMPORTED_MODULE_0__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticState.ReadOnly));
|
|
5059
|
+
}
|
|
5060
|
+
else {
|
|
5061
|
+
removeAttr(el, "aria-valuenow");
|
|
5062
|
+
removeAttr(el, "aria-valuetext");
|
|
5063
|
+
removeAttr(el, "aria-orientation");
|
|
5064
|
+
removeAttr(el, "aria-readonly");
|
|
5065
|
+
}
|
|
5066
|
+
if (node.hint) {
|
|
5067
|
+
var descId = "rive-".concat(this.instanceId, "-desc-").concat(node.id);
|
|
5068
|
+
var descEl = this.descElements.get(node.id);
|
|
5069
|
+
if (!descEl) {
|
|
5070
|
+
descEl = document.createElement("span");
|
|
5071
|
+
descEl.id = descId;
|
|
5072
|
+
descEl.style.cssText = DESC_SPAN_STYLE;
|
|
5073
|
+
this.container.appendChild(descEl);
|
|
5074
|
+
this.descElements.set(node.id, descEl);
|
|
5075
|
+
}
|
|
5076
|
+
if (descEl.textContent !== node.hint)
|
|
5077
|
+
descEl.textContent = node.hint;
|
|
5078
|
+
setAttr(el, "aria-describedby", descId);
|
|
5079
|
+
}
|
|
5080
|
+
else {
|
|
5081
|
+
removeAttr(el, "aria-describedby");
|
|
5082
|
+
var staleDesc = this.descElements.get(node.id);
|
|
5083
|
+
if (staleDesc) {
|
|
5084
|
+
if (staleDesc.parentNode)
|
|
5085
|
+
staleDesc.parentNode.removeChild(staleDesc);
|
|
5086
|
+
this.descElements.delete(node.id);
|
|
5087
|
+
}
|
|
5088
|
+
}
|
|
5089
|
+
// Text nodes: use textContent rather than aria-label so screen readers
|
|
5090
|
+
// announce the text in virtual/browse mode (aria-label on a bare <span>
|
|
5091
|
+
// with no widget role is ignored by some AT in document browse mode).
|
|
5092
|
+
if (role === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.text) {
|
|
5093
|
+
var textSpan = (_a = el.querySelector(":scope > span")) !== null && _a !== void 0 ? _a : el;
|
|
5094
|
+
var text = (_b = node.label) !== null && _b !== void 0 ? _b : "";
|
|
5095
|
+
if (textSpan.textContent !== text)
|
|
5096
|
+
textSpan.textContent = text;
|
|
5097
|
+
removeAttr(el, "aria-label");
|
|
5098
|
+
if (node.headingLevel > 0) {
|
|
5099
|
+
setAttr(el, "role", "heading");
|
|
5100
|
+
setAttr(el, "aria-level", String(node.headingLevel));
|
|
5101
|
+
}
|
|
5102
|
+
else {
|
|
5103
|
+
// The generic role branch above already cleared role="heading";
|
|
5104
|
+
// aria-level must go with it when a heading reverts to plain text.
|
|
5105
|
+
removeAttr(el, "aria-level");
|
|
5106
|
+
}
|
|
5107
|
+
}
|
|
5108
|
+
// ---- Trait-gated states ----
|
|
5109
|
+
// Only set the ARIA property when the trait is present. When the trait
|
|
5110
|
+
// is absent, remove the attribute so AT sees "not applicable" rather
|
|
5111
|
+
// than "false".
|
|
5112
|
+
if ((0,_types__WEBPACK_IMPORTED_MODULE_0__.hasTrait)(traits, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticTrait.Expandable) && ARIA_EXPANDED_ROLES.has(role)) {
|
|
5113
|
+
setBoolAttr(el, "aria-expanded", (0,_types__WEBPACK_IMPORTED_MODULE_0__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticState.Expanded));
|
|
5114
|
+
}
|
|
5115
|
+
else {
|
|
5116
|
+
removeAttr(el, "aria-expanded");
|
|
5117
|
+
}
|
|
5118
|
+
// aria-selected is required on ALL tabs per ARIA spec regardless of trait;
|
|
5119
|
+
// for other roles it is trait-gated and guarded to ARIA_SELECTED_ROLES.
|
|
5120
|
+
if (role === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.tab) {
|
|
5121
|
+
setBoolAttr(el, "aria-selected", (0,_types__WEBPACK_IMPORTED_MODULE_0__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticState.Selected));
|
|
5122
|
+
}
|
|
5123
|
+
else if ((0,_types__WEBPACK_IMPORTED_MODULE_0__.hasTrait)(traits, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticTrait.Selectable) && ARIA_SELECTED_ROLES.has(role)) {
|
|
5124
|
+
setBoolAttr(el, "aria-selected", (0,_types__WEBPACK_IMPORTED_MODULE_0__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticState.Selected));
|
|
5125
|
+
}
|
|
5126
|
+
else {
|
|
5127
|
+
removeAttr(el, "aria-selected");
|
|
5128
|
+
}
|
|
5129
|
+
if ((0,_types__WEBPACK_IMPORTED_MODULE_0__.hasTrait)(traits, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticTrait.Checkable) && ARIA_CHECKED_ROLES.has(role)) {
|
|
5130
|
+
// Mixed wins over Checked per the C++ precedence contract, but
|
|
5131
|
+
// role="switch" only accepts true/false — "mixed" is invalid per ARIA.
|
|
5132
|
+
if ((0,_types__WEBPACK_IMPORTED_MODULE_0__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticState.Mixed) && role !== _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.switchControl) {
|
|
5133
|
+
setAttr(el, "aria-checked", "mixed");
|
|
5134
|
+
}
|
|
5135
|
+
else {
|
|
5136
|
+
setBoolAttr(el, "aria-checked", (0,_types__WEBPACK_IMPORTED_MODULE_0__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticState.Checked));
|
|
5137
|
+
}
|
|
5138
|
+
}
|
|
5139
|
+
else {
|
|
5140
|
+
removeAttr(el, "aria-checked");
|
|
5141
|
+
}
|
|
5142
|
+
if ((0,_types__WEBPACK_IMPORTED_MODULE_0__.hasTrait)(traits, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticTrait.Toggleable)) {
|
|
5143
|
+
if (ARIA_PRESSED_ROLES.has(role)) {
|
|
5144
|
+
setBoolAttr(el, "aria-pressed", (0,_types__WEBPACK_IMPORTED_MODULE_0__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticState.Toggled));
|
|
5145
|
+
}
|
|
5146
|
+
else {
|
|
5147
|
+
removeAttr(el, "aria-pressed");
|
|
5148
|
+
}
|
|
5149
|
+
// switch uses aria-checked (not aria-pressed) for its on/off state.
|
|
5150
|
+
if (role === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.switchControl) {
|
|
5151
|
+
setBoolAttr(el, "aria-checked", (0,_types__WEBPACK_IMPORTED_MODULE_0__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticState.Toggled));
|
|
5152
|
+
}
|
|
5153
|
+
}
|
|
5154
|
+
else {
|
|
5155
|
+
removeAttr(el, "aria-pressed");
|
|
5156
|
+
}
|
|
5157
|
+
if ((0,_types__WEBPACK_IMPORTED_MODULE_0__.hasTrait)(traits, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticTrait.Requirable) && ARIA_REQUIRED_ROLES.has(role)) {
|
|
5158
|
+
setBoolAttr(el, "aria-required", (0,_types__WEBPACK_IMPORTED_MODULE_0__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticState.Required));
|
|
5159
|
+
}
|
|
5160
|
+
else {
|
|
5161
|
+
removeAttr(el, "aria-required");
|
|
5162
|
+
}
|
|
5163
|
+
if ((0,_types__WEBPACK_IMPORTED_MODULE_0__.hasTrait)(traits, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticTrait.Enablable)) {
|
|
5164
|
+
setBoolAttr(el, "aria-disabled", (0,_types__WEBPACK_IMPORTED_MODULE_0__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticState.Disabled));
|
|
5165
|
+
}
|
|
5166
|
+
else {
|
|
5167
|
+
removeAttr(el, "aria-disabled");
|
|
5168
|
+
}
|
|
5169
|
+
// ---- Non-trait states ----
|
|
5170
|
+
// Hide from AT when explicitly hidden, or when an image has no accessible
|
|
5171
|
+
// name — a nameless role="img" is a WCAG 1.1.1 violation; treat it as
|
|
5172
|
+
// decorative instead.
|
|
5173
|
+
var isDecorativeImage = role === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.image && !node.label;
|
|
5174
|
+
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) {
|
|
5175
|
+
setAttr(el, "aria-hidden", "true");
|
|
5176
|
+
}
|
|
5177
|
+
else {
|
|
5178
|
+
removeAttr(el, "aria-hidden");
|
|
5179
|
+
}
|
|
5180
|
+
if ((0,_types__WEBPACK_IMPORTED_MODULE_0__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticState.LiveRegion)) {
|
|
5181
|
+
setAttr(el, "aria-live", "polite");
|
|
5182
|
+
}
|
|
5183
|
+
else {
|
|
5184
|
+
removeAttr(el, "aria-live");
|
|
5185
|
+
}
|
|
5186
|
+
// textField-specific
|
|
5187
|
+
// TODO: Details here may change once we implement text inputs
|
|
5188
|
+
if (role === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.textField) {
|
|
5189
|
+
setBoolAttr(el, "aria-readonly", (0,_types__WEBPACK_IMPORTED_MODULE_0__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticState.ReadOnly));
|
|
5190
|
+
setBoolAttr(el, "aria-multiline", (0,_types__WEBPACK_IMPORTED_MODULE_0__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticState.Multiline));
|
|
5191
|
+
// Surface the current field value as DOM text so screen readers can
|
|
5192
|
+
// announce it. Only safe when the node has no semantic children —
|
|
5193
|
+
// setting textContent would remove any child elements from the DOM.
|
|
5194
|
+
if (node.children.length === 0) {
|
|
5195
|
+
var value = (_c = node.value) !== null && _c !== void 0 ? _c : "";
|
|
5196
|
+
if (el.textContent !== value)
|
|
5197
|
+
el.textContent = value;
|
|
5198
|
+
}
|
|
5199
|
+
}
|
|
5200
|
+
else {
|
|
5201
|
+
removeAttr(el, "aria-multiline");
|
|
5202
|
+
}
|
|
5203
|
+
// alertDialog is always modal per WAI-ARIA; a plain dialog only when the Modal state flag is set.
|
|
5204
|
+
if (isModalDialogRole(role, flags)) {
|
|
5205
|
+
setAttr(el, "aria-modal", "true");
|
|
5206
|
+
}
|
|
5207
|
+
else {
|
|
5208
|
+
removeAttr(el, "aria-modal");
|
|
5209
|
+
}
|
|
5210
|
+
};
|
|
5211
|
+
// ---- Positioning ----
|
|
5212
|
+
/**
|
|
5213
|
+
* Positions an element in artboard-space coordinates relative to its parent.
|
|
5214
|
+
*
|
|
5215
|
+
* Node bounds stay in raw artboard units — the CSS `transform: matrix(...)`
|
|
5216
|
+
* on the transform container maps artboard units to CSS pixels in one GPU
|
|
5217
|
+
* pass. No per-node forwardMat multiplication or DPR division needed here.
|
|
5218
|
+
*
|
|
5219
|
+
* Round to whole artboard units before comparing to avoid triggering AX
|
|
5220
|
+
* layout notifications from sub-unit floating-point animation jitter.
|
|
5221
|
+
*/
|
|
5222
|
+
AccessibilityOverlay.prototype.applyPosition = function (el, node, parentArtboardLeft, parentArtboardTop) {
|
|
5223
|
+
// Clamp each node's rect to the artboard viewport before computing CSS.
|
|
5224
|
+
// Without this, nodes whose artboard bounds exceed the artboard (e.g. a
|
|
5225
|
+
// scroll list container whose height is the full content, not the viewport)
|
|
5226
|
+
// produce CSS heights that overflow the transform container. WebKit then
|
|
5227
|
+
// unions all descendant AX rects and extends the container's AX origin
|
|
5228
|
+
// above the canvas regardless of overflow:hidden on ancestors.
|
|
5229
|
+
var ab = this._artboardBounds;
|
|
5230
|
+
var clampedMinX = Math.max(node.minX, ab.minX);
|
|
5231
|
+
var clampedMinY = Math.max(node.minY, ab.minY);
|
|
5232
|
+
var clampedMaxX = Math.min(node.maxX, ab.maxX);
|
|
5233
|
+
var clampedMaxY = Math.min(node.maxY, ab.maxY);
|
|
5234
|
+
var elLeft = clampedMinX - parentArtboardLeft;
|
|
5235
|
+
var elTop = clampedMinY - parentArtboardTop;
|
|
5236
|
+
var elWidth = Math.max(0, clampedMaxX - clampedMinX);
|
|
5237
|
+
var elHeight = Math.max(0, clampedMaxY - clampedMinY);
|
|
5238
|
+
var tx = Math.round(elLeft);
|
|
5239
|
+
var ty = Math.round(elTop);
|
|
5240
|
+
var pxWidth = Math.round(elWidth) + "px";
|
|
5241
|
+
var pxHeight = Math.round(elHeight) + "px";
|
|
5242
|
+
// Use left/top layout properties for positioning. VoiceOver reliably
|
|
5243
|
+
// handles layout position + a single ancestor CSS transform (the transform
|
|
5244
|
+
// container). Chaining CSS transforms across multiple stacking contexts
|
|
5245
|
+
// (transform container → node identity → item translate) caused VoiceOver
|
|
5246
|
+
// to compute the correct SIZE but wrong POSITION. Artboard clamping above
|
|
5247
|
+
// guarantees tx/ty are always ≥ 0, so the negative-top overflow problem
|
|
5248
|
+
// that originally prompted the switch to CSS transforms no longer applies.
|
|
5249
|
+
var pxLeft = tx + "px";
|
|
5250
|
+
var pxTop = ty + "px";
|
|
5251
|
+
if (el.style.left !== pxLeft)
|
|
5252
|
+
el.style.left = pxLeft;
|
|
5253
|
+
if (el.style.top !== pxTop)
|
|
5254
|
+
el.style.top = pxTop;
|
|
5255
|
+
if (el.style.width !== pxWidth)
|
|
5256
|
+
el.style.width = pxWidth;
|
|
5257
|
+
if (el.style.height !== pxHeight)
|
|
5258
|
+
el.style.height = pxHeight;
|
|
5259
|
+
// Clear any CSS transform from a previous render pass.
|
|
5260
|
+
if (el.style.transform)
|
|
5261
|
+
el.style.transform = "";
|
|
5262
|
+
if (node.role === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.text) {
|
|
5263
|
+
this.pendingTextGeometry.push(el);
|
|
5264
|
+
}
|
|
5265
|
+
};
|
|
5266
|
+
/**
|
|
5267
|
+
* Scale each queued text span to fit its layout box, batched so a frame
|
|
5268
|
+
* pays at most one synchronous layout: all measurement-reset writes first,
|
|
5269
|
+
* then all rect reads, then all transform writes. Interleaving
|
|
5270
|
+
* write→read→write per node would force a reflow per text node instead.
|
|
5271
|
+
*
|
|
5272
|
+
* Nodes whose box size and text are unchanged since the last pass are
|
|
5273
|
+
* skipped entirely (their existing transform is still correct — the scale
|
|
5274
|
+
* is a ratio of two rects, so ancestor transform changes cancel out).
|
|
5275
|
+
*/
|
|
5276
|
+
AccessibilityOverlay.prototype.flushTextGeometry = function () {
|
|
5277
|
+
var _a;
|
|
5278
|
+
if (this.pendingTextGeometry.length === 0)
|
|
5279
|
+
return;
|
|
5280
|
+
// Phase 1 — writes: reset spans to their natural size for measurement.
|
|
5281
|
+
// The previous pass's scale must be cleared, or the rect reads below
|
|
5282
|
+
// would measure the scaled span and compound the correction.
|
|
5283
|
+
var toMeasure = [];
|
|
5284
|
+
for (var _i = 0, _b = this.pendingTextGeometry; _i < _b.length; _i++) {
|
|
5285
|
+
var host = _b[_i];
|
|
5286
|
+
var span = (_a = host.querySelector(":scope > span")) !== null && _a !== void 0 ? _a : host;
|
|
5287
|
+
var key = "".concat(host.style.width, "|").concat(host.style.height, "|").concat(span.textContent);
|
|
5288
|
+
if (this.textGeometryKeys.get(host) === key)
|
|
5289
|
+
continue;
|
|
5290
|
+
span.style.width = "auto";
|
|
5291
|
+
span.style.height = "auto";
|
|
5292
|
+
span.style.transformOrigin = "0 0";
|
|
5293
|
+
span.style.transform = "";
|
|
5294
|
+
toMeasure.push({ host: host, span: span, key: key });
|
|
5295
|
+
}
|
|
5296
|
+
this.pendingTextGeometry.length = 0;
|
|
5297
|
+
// Phase 2 — reads: one layout pass covers every rect measurement.
|
|
5298
|
+
var transforms = toMeasure.map(function (_a) {
|
|
5299
|
+
var host = _a.host, span = _a.span;
|
|
5300
|
+
var parentRect = host.getBoundingClientRect();
|
|
5301
|
+
var natural = span.getBoundingClientRect();
|
|
5302
|
+
if (natural.width > 0 && natural.height > 0) {
|
|
5303
|
+
var scaleX = parentRect.width / natural.width;
|
|
5304
|
+
var scaleY = parentRect.height / natural.height;
|
|
5305
|
+
return "scale(".concat(scaleX, ", ").concat(scaleY, ")");
|
|
5306
|
+
}
|
|
5307
|
+
return "none";
|
|
5308
|
+
});
|
|
5309
|
+
// Phase 3 — writes: apply all transforms.
|
|
5310
|
+
for (var i = 0; i < toMeasure.length; i++) {
|
|
5311
|
+
var _c = toMeasure[i], host = _c.host, span = _c.span, key = _c.key;
|
|
5312
|
+
span.style.transform = transforms[i];
|
|
5313
|
+
this.textGeometryKeys.set(host, key);
|
|
5314
|
+
}
|
|
5315
|
+
};
|
|
5316
|
+
// ---- Transform container ----
|
|
5317
|
+
/**
|
|
5318
|
+
* Creates (on first call) and updates the artboard-space transform container.
|
|
5319
|
+
*
|
|
5320
|
+
* The container is sized to the artboard dimensions and carries a CSS
|
|
5321
|
+
* `transform: matrix(...)` equivalent to `forwardMat / dpr`. All semantic
|
|
5322
|
+
* node elements are children of this container and use raw artboard
|
|
5323
|
+
* coordinates as their CSS `left/top/width/height`, so the CSS compositor
|
|
5324
|
+
* applies the artboard→screen mapping in one pass.
|
|
5325
|
+
*/
|
|
5326
|
+
AccessibilityOverlay.prototype.syncTransformContainer = function (forwardMat, dpr, artboardBounds) {
|
|
5327
|
+
if (!this.transformContainer) {
|
|
5328
|
+
var tc = document.createElement("div");
|
|
5329
|
+
tc.style.cssText = [
|
|
5330
|
+
"position:absolute",
|
|
5331
|
+
"top:0",
|
|
5332
|
+
"left:0",
|
|
5333
|
+
// overflow:visible — artboard viewport clamping is done per-node in
|
|
5334
|
+
// applyPosition
|
|
5335
|
+
"overflow:visible",
|
|
5336
|
+
"pointer-events:none",
|
|
5337
|
+
"transform-origin:0 0",
|
|
5338
|
+
].join(";");
|
|
5339
|
+
this.container.appendChild(tc);
|
|
5340
|
+
this.transformContainer = tc;
|
|
5341
|
+
}
|
|
5342
|
+
var w = artboardBounds.maxX - artboardBounds.minX;
|
|
5343
|
+
var h = artboardBounds.maxY - artboardBounds.minY;
|
|
5344
|
+
this.transformContainer.style.width = Math.round(w) + "px";
|
|
5345
|
+
this.transformContainer.style.height = Math.round(h) + "px";
|
|
5346
|
+
var s = 1 / (dpr || 1);
|
|
5347
|
+
var a = forwardMat.xx * s;
|
|
5348
|
+
var b = forwardMat.xy * s;
|
|
5349
|
+
var c = forwardMat.yx * s;
|
|
5350
|
+
var d = forwardMat.yy * s;
|
|
5351
|
+
var tx = forwardMat.tx * s;
|
|
5352
|
+
var ty = forwardMat.ty * s;
|
|
5353
|
+
this.transformContainer.style.transform =
|
|
5354
|
+
"matrix(".concat(a, ",").concat(b, ",").concat(c, ",").concat(d, ",").concat(tx, ",").concat(ty, ")");
|
|
5355
|
+
};
|
|
5356
|
+
return AccessibilityOverlay;
|
|
5357
|
+
}());
|
|
5358
|
+
|
|
5359
|
+
// ---------------------------------------------------------------------------
|
|
5360
|
+
// Static helpers (module-private)
|
|
5361
|
+
// ---------------------------------------------------------------------------
|
|
5362
|
+
// ---------------------------------------------------------------------------
|
|
5363
|
+
// ARIA attribute eligibility — role sets
|
|
5364
|
+
//
|
|
5365
|
+
// Each set lists the Rive roles for which a given ARIA attribute is valid per
|
|
5366
|
+
// WAI-ARIA 1.2 ("Used in roles" + "Inherits into roles"). The trait-gated
|
|
5367
|
+
// blocks in applyAttributes check these before setting an attribute so that
|
|
5368
|
+
// C++ nodes with unexpected trait combinations never produce invalid markup.
|
|
5369
|
+
//
|
|
5370
|
+
// To add a new role: append it to the relevant set(s) here — no other changes
|
|
5371
|
+
// needed in applyAttributes.
|
|
5372
|
+
// ---------------------------------------------------------------------------
|
|
5373
|
+
/** aria-expanded: button, link, checkbox, switch (inherits button), tab. */
|
|
5374
|
+
var ARIA_EXPANDED_ROLES = new Set([
|
|
5375
|
+
_types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.button,
|
|
5376
|
+
_types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.link,
|
|
5377
|
+
_types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.checkbox,
|
|
5378
|
+
_types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.switchControl,
|
|
5379
|
+
_types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.tab,
|
|
5380
|
+
]);
|
|
5381
|
+
/**
|
|
5382
|
+
* aria-selected: tab is the only role in our current set that natively
|
|
5383
|
+
* supports it. Tab is also handled by an explicit unconditional branch in
|
|
5384
|
+
* applyAttributes (ARIA requires it there regardless of Selectable trait), but
|
|
5385
|
+
* the set still lists it so the constraint is visible in one place.
|
|
5386
|
+
*/
|
|
5387
|
+
var ARIA_SELECTED_ROLES = new Set([
|
|
5388
|
+
_types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.tab,
|
|
5389
|
+
]);
|
|
5390
|
+
/** aria-checked: checkbox, radio, switch. */
|
|
5391
|
+
var ARIA_CHECKED_ROLES = new Set([
|
|
5392
|
+
_types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.checkbox,
|
|
5393
|
+
_types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.radioButton,
|
|
5394
|
+
_types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.switchControl,
|
|
5395
|
+
]);
|
|
5396
|
+
/**
|
|
5397
|
+
* aria-pressed: button only. switch is a button subclass in ARIA but uses
|
|
5398
|
+
* aria-checked (not aria-pressed) for its on/off state — it is intentionally
|
|
5399
|
+
* excluded here and handled separately in the Toggleable block.
|
|
5400
|
+
*/
|
|
5401
|
+
var ARIA_PRESSED_ROLES = new Set([
|
|
5402
|
+
_types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.button,
|
|
5403
|
+
]);
|
|
5404
|
+
/** aria-required: checkbox, textbox, radiogroup. */
|
|
5405
|
+
var ARIA_REQUIRED_ROLES = new Set([
|
|
5406
|
+
_types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.checkbox,
|
|
5407
|
+
_types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.textField,
|
|
5408
|
+
_types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.radioGroup,
|
|
5409
|
+
]);
|
|
5410
|
+
// ---------------------------------------------------------------------------
|
|
5411
|
+
/** Style for visually-hidden description spans used with aria-describedby. */
|
|
5412
|
+
var DESC_SPAN_STYLE = [
|
|
5413
|
+
"position:absolute",
|
|
5414
|
+
"width:1px",
|
|
5415
|
+
"height:1px",
|
|
5416
|
+
"overflow:hidden",
|
|
5417
|
+
"pointer-events:none",
|
|
5418
|
+
"left:-9999px",
|
|
5419
|
+
].join(";");
|
|
5420
|
+
var BASE_NODE_STYLE = [
|
|
5421
|
+
"position:absolute",
|
|
5422
|
+
"pointer-events:none",
|
|
5423
|
+
"box-sizing:border-box",
|
|
5424
|
+
"overflow:visible",
|
|
5425
|
+
"margin:0",
|
|
5426
|
+
"padding:0",
|
|
5427
|
+
"transform-origin: 0px 0px 0px",
|
|
5428
|
+
"border:none",
|
|
5429
|
+
"background:transparent",
|
|
5430
|
+
"color:transparent",
|
|
5431
|
+
// "list-style:none",
|
|
5432
|
+
].join(";");
|
|
5433
|
+
var SPAN_EXP = [
|
|
5434
|
+
"display:inline-block",
|
|
5435
|
+
"white-space:nowrap",
|
|
5436
|
+
"pointer-events:none",
|
|
5437
|
+
].join(";");
|
|
5438
|
+
/**
|
|
5439
|
+
* Attribute writers that skip same-value mutations. Even a no-op setAttribute
|
|
5440
|
+
* fires a mutation record, and whether AX layers dedupe those is
|
|
5441
|
+
* browser-specific — skipping the write is the only browser-proof guard.
|
|
5442
|
+
*/
|
|
5443
|
+
function setAttr(el, attr, value) {
|
|
5444
|
+
if (el.getAttribute(attr) !== value)
|
|
5445
|
+
el.setAttribute(attr, value);
|
|
5446
|
+
}
|
|
5447
|
+
function removeAttr(el, attr) {
|
|
5448
|
+
if (el.hasAttribute(attr))
|
|
5449
|
+
el.removeAttribute(attr);
|
|
5450
|
+
}
|
|
5451
|
+
function setBoolAttr(el, attr, value) {
|
|
5452
|
+
setAttr(el, attr, value ? "true" : "false");
|
|
5453
|
+
}
|
|
5454
|
+
/** Roles that receive click/Enter/Space action handlers. */
|
|
5455
|
+
function isClickableRole(role) {
|
|
5456
|
+
switch (role) {
|
|
5457
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.button:
|
|
5458
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.link:
|
|
5459
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.checkbox:
|
|
5460
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.switchControl:
|
|
5461
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.tab:
|
|
5462
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.radioButton:
|
|
5463
|
+
return true;
|
|
5464
|
+
default:
|
|
5465
|
+
return false;
|
|
5466
|
+
}
|
|
5467
|
+
}
|
|
5468
|
+
/** Roles that receive tabindex="-1" for programmatic/AT focus (not Tab order). */
|
|
5469
|
+
function isInteractiveRole(role) {
|
|
5470
|
+
switch (role) {
|
|
5471
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.button:
|
|
5472
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.link:
|
|
5473
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.checkbox:
|
|
5474
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.switchControl:
|
|
5475
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.slider:
|
|
5476
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.tab:
|
|
5477
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.radioButton:
|
|
5478
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.textField:
|
|
5479
|
+
return true;
|
|
5480
|
+
default:
|
|
5481
|
+
return false;
|
|
5482
|
+
}
|
|
5483
|
+
}
|
|
5484
|
+
/**
|
|
5485
|
+
* A modal/alert dialog: alertDialog is always modal per WAI-ARIA, a plain
|
|
5486
|
+
* dialog only when the Modal state flag is set.
|
|
5487
|
+
*/
|
|
5488
|
+
function isModalDialogRole(role, flags) {
|
|
5489
|
+
return (role === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.alertDialog ||
|
|
5490
|
+
(role === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.dialog && (0,_types__WEBPACK_IMPORTED_MODULE_0__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticState.Modal)));
|
|
5491
|
+
}
|
|
5492
|
+
/** Whether a node can receive focus: an interactive role or the Focusable trait. */
|
|
5493
|
+
function isFocusableNode(node) {
|
|
5494
|
+
return (isInteractiveRole(node.role) ||
|
|
5495
|
+
(0,_types__WEBPACK_IMPORTED_MODULE_0__.hasTrait)(node.traitFlags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticTrait.Focusable));
|
|
5496
|
+
}
|
|
5497
|
+
/**
|
|
5498
|
+
* Choose an HTML tag for a given role. Prefer native semantic elements
|
|
5499
|
+
* where they exist — screen readers treat them more reliably than
|
|
5500
|
+
* generic elements with ARIA role overrides.
|
|
5501
|
+
*/
|
|
5502
|
+
function tagForRole(role) {
|
|
5503
|
+
switch (role) {
|
|
5504
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.link:
|
|
5505
|
+
return "a";
|
|
5506
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.text:
|
|
5507
|
+
// The outer div is the positioned AX element VoiceOver measures for its
|
|
5508
|
+
// highlight box. The text itself lives in a child <span> (see createElement).
|
|
5509
|
+
return "div";
|
|
5510
|
+
default:
|
|
5511
|
+
return "div";
|
|
5512
|
+
}
|
|
5513
|
+
}
|
|
5514
|
+
/**
|
|
5515
|
+
* Maps a Rive SemanticRole to an ARIA `role` attribute value.
|
|
5516
|
+
* Returns null for roles that don't need an explicit role attribute here
|
|
5517
|
+
* (e.g. text nodes use an outer div + inner span with textContent; heading
|
|
5518
|
+
* role is applied separately when headingLevel > 0).
|
|
5519
|
+
*/
|
|
5520
|
+
function ariaRoleForSemantic(role) {
|
|
5521
|
+
switch (role) {
|
|
5522
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.none:
|
|
5523
|
+
// TODO: Role "none" removes the node from the accessibility tree. For now, setting to Group, but maybe we want to switch to "none"
|
|
5524
|
+
// or "presentation".
|
|
5525
|
+
return "group";
|
|
5526
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.button:
|
|
5527
|
+
return "button";
|
|
5528
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.link:
|
|
5529
|
+
return null; // native <a>
|
|
5530
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.checkbox:
|
|
5531
|
+
return "checkbox";
|
|
5532
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.switchControl:
|
|
5533
|
+
return "switch";
|
|
5534
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.slider:
|
|
5535
|
+
return "slider";
|
|
5536
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.textField:
|
|
5537
|
+
return "textbox";
|
|
5538
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.image:
|
|
5539
|
+
return "img";
|
|
5540
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.group:
|
|
5541
|
+
return "group";
|
|
5542
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.list:
|
|
5543
|
+
return "list";
|
|
5544
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.listItem:
|
|
5545
|
+
return "listitem";
|
|
5546
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.tab:
|
|
5547
|
+
return "tab";
|
|
5548
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.tabList:
|
|
5549
|
+
return "tablist";
|
|
5550
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.dialog:
|
|
5551
|
+
return "dialog";
|
|
5552
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.alertDialog:
|
|
5553
|
+
return "alertdialog";
|
|
5554
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.radioGroup:
|
|
5555
|
+
return "radiogroup";
|
|
5556
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.radioButton:
|
|
5557
|
+
return "radio";
|
|
5558
|
+
case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.text:
|
|
5559
|
+
// Text nodes use <span>; heading role is applied separately
|
|
5560
|
+
// when headingLevel > 0.
|
|
5561
|
+
return null;
|
|
5562
|
+
default:
|
|
5563
|
+
return null;
|
|
5564
|
+
}
|
|
5565
|
+
}
|
|
5566
|
+
|
|
5567
|
+
|
|
5568
|
+
/***/ }),
|
|
5569
|
+
/* 10 */
|
|
5570
|
+
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
5571
|
+
|
|
3761
5572
|
__webpack_require__.r(__webpack_exports__);
|
|
3762
5573
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
3763
5574
|
/* harmony export */ AudioAssetWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_3__.AudioAssetWrapper),
|
|
@@ -3778,11 +5589,11 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
3778
5589
|
/* harmony export */ registerTouchInteractions: () => (/* reexport safe */ _registerTouchInteractions__WEBPACK_IMPORTED_MODULE_0__.registerTouchInteractions),
|
|
3779
5590
|
/* harmony export */ sanitizeUrl: () => (/* reexport safe */ _sanitizeUrl__WEBPACK_IMPORTED_MODULE_2__.sanitizeUrl)
|
|
3780
5591
|
/* harmony export */ });
|
|
3781
|
-
/* harmony import */ var _registerTouchInteractions__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(
|
|
3782
|
-
/* harmony import */ var _registerKeyboardInteractions__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(
|
|
3783
|
-
/* harmony import */ var _sanitizeUrl__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(
|
|
3784
|
-
/* harmony import */ var _finalizationRegistry__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(
|
|
3785
|
-
/* harmony import */ var _riveFont__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(
|
|
5592
|
+
/* harmony import */ var _registerTouchInteractions__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(11);
|
|
5593
|
+
/* harmony import */ var _registerKeyboardInteractions__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(12);
|
|
5594
|
+
/* harmony import */ var _sanitizeUrl__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(13);
|
|
5595
|
+
/* harmony import */ var _finalizationRegistry__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(14);
|
|
5596
|
+
/* harmony import */ var _riveFont__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(15);
|
|
3786
5597
|
|
|
3787
5598
|
|
|
3788
5599
|
|
|
@@ -3791,7 +5602,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
3791
5602
|
|
|
3792
5603
|
|
|
3793
5604
|
/***/ }),
|
|
3794
|
-
/*
|
|
5605
|
+
/* 11 */
|
|
3795
5606
|
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
3796
5607
|
|
|
3797
5608
|
__webpack_require__.r(__webpack_exports__);
|
|
@@ -4088,7 +5899,7 @@ var registerTouchInteractions = function (_a) {
|
|
|
4088
5899
|
|
|
4089
5900
|
|
|
4090
5901
|
/***/ }),
|
|
4091
|
-
/*
|
|
5902
|
+
/* 12 */
|
|
4092
5903
|
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
4093
5904
|
|
|
4094
5905
|
__webpack_require__.r(__webpack_exports__);
|
|
@@ -4128,9 +5939,16 @@ var FocusSessionState;
|
|
|
4128
5939
|
*/
|
|
4129
5940
|
var KeyboardInteractions = /** @class */ (function () {
|
|
4130
5941
|
function KeyboardInteractions(_a) {
|
|
4131
|
-
var canvas = _a.canvas, stateMachine = _a.stateMachine, hasFocusNodes = _a.hasFocusNodes;
|
|
5942
|
+
var canvas = _a.canvas, stateMachine = _a.stateMachine, hasFocusNodes = _a.hasFocusNodes, getOverlayElement = _a.getOverlayElement;
|
|
4132
5943
|
var _this = this;
|
|
5944
|
+
var _b;
|
|
4133
5945
|
this.focusSessionState = FocusSessionState.NotFocused;
|
|
5946
|
+
/** Whether the canvas currently has browser DOM focus. */
|
|
5947
|
+
this.canvasHasFocus = false;
|
|
5948
|
+
/** After Tab exits the last Rive node, ignore keydowns until focus re-enters the focus domain. */
|
|
5949
|
+
this.focusDomainReleased = false;
|
|
5950
|
+
/** Overlay element currently wired with focusin/keydown listeners, if any. */
|
|
5951
|
+
this.currentOverlayElement = null;
|
|
4134
5952
|
/**
|
|
4135
5953
|
* Handles the canvas gaining browser focus. The behavior differs based on how focus was gained -
|
|
4136
5954
|
*
|
|
@@ -4143,6 +5961,9 @@ var KeyboardInteractions = /** @class */ (function () {
|
|
|
4143
5961
|
* gates this so a click doesn't yank Rive focus to the first node on the focus event itself.
|
|
4144
5962
|
*/
|
|
4145
5963
|
this.onCanvasFocus = function (event) {
|
|
5964
|
+
_this.syncOverlayListener();
|
|
5965
|
+
_this.canvasHasFocus = true;
|
|
5966
|
+
_this.focusDomainReleased = false;
|
|
4146
5967
|
if (!_this.hasFocusNodes)
|
|
4147
5968
|
return;
|
|
4148
5969
|
if (_this.mainSm.focusState().hasFocus)
|
|
@@ -4158,9 +5979,22 @@ var KeyboardInteractions = /** @class */ (function () {
|
|
|
4158
5979
|
};
|
|
4159
5980
|
this.onCanvasBlur = function (_event) {
|
|
4160
5981
|
_this.focusSessionState = FocusSessionState.NotFocused;
|
|
5982
|
+
_this.canvasHasFocus = false;
|
|
5983
|
+
};
|
|
5984
|
+
this.onOverlayFocusIn = function (event) {
|
|
5985
|
+
if (_this.isInOverlay(event.target)) {
|
|
5986
|
+
_this.focusDomainReleased = false;
|
|
5987
|
+
}
|
|
5988
|
+
};
|
|
5989
|
+
this.onFocusDomainHostFocusIn = function (_event) {
|
|
5990
|
+
_this.syncOverlayListener();
|
|
4161
5991
|
};
|
|
4162
5992
|
this.onKeyDown = function (event) {
|
|
4163
|
-
|
|
5993
|
+
_this.syncOverlayListener();
|
|
5994
|
+
// After Tab exits the last Rive node, ignore keys until focus re-enters the focus domain.
|
|
5995
|
+
if (_this.focusDomainReleased)
|
|
5996
|
+
return;
|
|
5997
|
+
if (!_this.shouldRiveHandleKeyEvent(event))
|
|
4164
5998
|
return;
|
|
4165
5999
|
if (event.code === "Tab" && _this.hasFocusNodes) {
|
|
4166
6000
|
var forward = !event.shiftKey;
|
|
@@ -4172,17 +6006,23 @@ var KeyboardInteractions = /** @class */ (function () {
|
|
|
4172
6006
|
}
|
|
4173
6007
|
else {
|
|
4174
6008
|
// No more traversable nodes — release Tab to the page.
|
|
4175
|
-
// Set state immediately; onCanvasBlur will also fire naturally.
|
|
4176
6009
|
_this.focusSessionState = FocusSessionState.NotFocused;
|
|
6010
|
+
_this.focusDomainReleased = true;
|
|
6011
|
+
_this.canvasHasFocus = false;
|
|
4177
6012
|
}
|
|
6013
|
+
_this.syncOverlayListener();
|
|
4178
6014
|
}
|
|
4179
6015
|
};
|
|
4180
6016
|
this.canvas = canvas;
|
|
4181
6017
|
this.mainSm = stateMachine;
|
|
4182
6018
|
this.hasFocusNodes = hasFocusNodes;
|
|
6019
|
+
this.getOverlayElement = getOverlayElement;
|
|
6020
|
+
this.focusDomainHost = (_b = canvas.parentElement) !== null && _b !== void 0 ? _b : document;
|
|
4183
6021
|
canvas.addEventListener("focus", this.onCanvasFocus);
|
|
4184
6022
|
canvas.addEventListener("blur", this.onCanvasBlur);
|
|
4185
6023
|
canvas.addEventListener("keydown", this.onKeyDown);
|
|
6024
|
+
this.focusDomainHost.addEventListener("focusin", this.onFocusDomainHostFocusIn);
|
|
6025
|
+
this.syncOverlayListener();
|
|
4186
6026
|
}
|
|
4187
6027
|
/**
|
|
4188
6028
|
* Set the FocusSessionState. Useful for invoking a Rive "blur" without actually blurring from the <canvas>. This
|
|
@@ -4201,6 +6041,45 @@ var KeyboardInteractions = /** @class */ (function () {
|
|
|
4201
6041
|
KeyboardInteractions.prototype.notifyRiveFocused = function () {
|
|
4202
6042
|
this.focusSessionState = FocusSessionState.RiveFocused;
|
|
4203
6043
|
};
|
|
6044
|
+
/**
|
|
6045
|
+
* Whether Rive should handle this keydown — i.e. it currently owns keyboard input.
|
|
6046
|
+
* True when focus is anywhere in the Rive focus domain (the canvas itself or the
|
|
6047
|
+
* accessibility overlay), OR a focus session is active and the key landed on the
|
|
6048
|
+
* canvas.
|
|
6049
|
+
*/
|
|
6050
|
+
KeyboardInteractions.prototype.shouldRiveHandleKeyEvent = function (event) {
|
|
6051
|
+
var inFocusDomain = this.isInFocusDomain(document.activeElement) ||
|
|
6052
|
+
this.isInOverlay(event.target);
|
|
6053
|
+
if (inFocusDomain)
|
|
6054
|
+
return true;
|
|
6055
|
+
var sessionActive = this.focusSessionState !== FocusSessionState.NotFocused;
|
|
6056
|
+
var eventOnCanvas = event.target === this.canvas;
|
|
6057
|
+
return sessionActive && (this.canvasHasFocus || eventOnCanvas);
|
|
6058
|
+
};
|
|
6059
|
+
/** Rive focus domain = the canvas itself OR the accessibility overlay. */
|
|
6060
|
+
KeyboardInteractions.prototype.isInFocusDomain = function (target) {
|
|
6061
|
+
if (target === this.canvas)
|
|
6062
|
+
return true;
|
|
6063
|
+
return this.isInOverlay(target);
|
|
6064
|
+
};
|
|
6065
|
+
/** Overlay only (excludes the canvas) — the accessibility overlay subtree. */
|
|
6066
|
+
KeyboardInteractions.prototype.isInOverlay = function (target) {
|
|
6067
|
+
var _a, _b, _c;
|
|
6068
|
+
if (!(target instanceof Node))
|
|
6069
|
+
return false;
|
|
6070
|
+
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;
|
|
6071
|
+
};
|
|
6072
|
+
KeyboardInteractions.prototype.syncOverlayListener = function () {
|
|
6073
|
+
var _a, _b, _c, _d, _e, _f;
|
|
6074
|
+
var nextOverlayElement = (_b = (_a = this.getOverlayElement) === null || _a === void 0 ? void 0 : _a.call(this)) !== null && _b !== void 0 ? _b : null;
|
|
6075
|
+
if (nextOverlayElement === this.currentOverlayElement)
|
|
6076
|
+
return;
|
|
6077
|
+
(_c = this.currentOverlayElement) === null || _c === void 0 ? void 0 : _c.removeEventListener("focusin", this.onOverlayFocusIn);
|
|
6078
|
+
(_d = this.currentOverlayElement) === null || _d === void 0 ? void 0 : _d.removeEventListener("keydown", this.onKeyDown, true);
|
|
6079
|
+
this.currentOverlayElement = nextOverlayElement;
|
|
6080
|
+
(_e = this.currentOverlayElement) === null || _e === void 0 ? void 0 : _e.addEventListener("focusin", this.onOverlayFocusIn);
|
|
6081
|
+
(_f = this.currentOverlayElement) === null || _f === void 0 ? void 0 : _f.addEventListener("keydown", this.onKeyDown, true);
|
|
6082
|
+
};
|
|
4204
6083
|
/**
|
|
4205
6084
|
* Whether the canvas currently matches :focus-visible — the browser's heuristic for keyboard-
|
|
4206
6085
|
* (vs pointer-) driven focus. For older browser versions that don't support this selector, return false
|
|
@@ -4225,9 +6104,13 @@ var KeyboardInteractions = /** @class */ (function () {
|
|
|
4225
6104
|
return true;
|
|
4226
6105
|
};
|
|
4227
6106
|
KeyboardInteractions.prototype.cleanup = function () {
|
|
6107
|
+
var _a, _b;
|
|
4228
6108
|
this.canvas.removeEventListener("focus", this.onCanvasFocus);
|
|
4229
6109
|
this.canvas.removeEventListener("blur", this.onCanvasBlur);
|
|
4230
6110
|
this.canvas.removeEventListener("keydown", this.onKeyDown);
|
|
6111
|
+
this.focusDomainHost.removeEventListener("focusin", this.onFocusDomainHostFocusIn);
|
|
6112
|
+
(_a = this.currentOverlayElement) === null || _a === void 0 ? void 0 : _a.removeEventListener("focusin", this.onOverlayFocusIn);
|
|
6113
|
+
(_b = this.currentOverlayElement) === null || _b === void 0 ? void 0 : _b.removeEventListener("keydown", this.onKeyDown, true);
|
|
4231
6114
|
};
|
|
4232
6115
|
return KeyboardInteractions;
|
|
4233
6116
|
}());
|
|
@@ -4235,7 +6118,7 @@ var KeyboardInteractions = /** @class */ (function () {
|
|
|
4235
6118
|
|
|
4236
6119
|
|
|
4237
6120
|
/***/ }),
|
|
4238
|
-
/*
|
|
6121
|
+
/* 13 */
|
|
4239
6122
|
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
4240
6123
|
|
|
4241
6124
|
__webpack_require__.r(__webpack_exports__);
|
|
@@ -4288,7 +6171,7 @@ function sanitizeUrl(url) {
|
|
|
4288
6171
|
|
|
4289
6172
|
|
|
4290
6173
|
/***/ }),
|
|
4291
|
-
/*
|
|
6174
|
+
/* 14 */
|
|
4292
6175
|
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
4293
6176
|
|
|
4294
6177
|
__webpack_require__.r(__webpack_exports__);
|
|
@@ -4570,7 +6453,7 @@ var createFinalization = function (target, finalizable) {
|
|
|
4570
6453
|
|
|
4571
6454
|
|
|
4572
6455
|
/***/ }),
|
|
4573
|
-
/*
|
|
6456
|
+
/* 15 */
|
|
4574
6457
|
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
4575
6458
|
|
|
4576
6459
|
__webpack_require__.r(__webpack_exports__);
|
|
@@ -4715,14 +6598,16 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
4715
6598
|
/* harmony export */ Rive: () => (/* binding */ Rive),
|
|
4716
6599
|
/* harmony export */ RiveEventType: () => (/* binding */ RiveEventType),
|
|
4717
6600
|
/* harmony export */ RiveFile: () => (/* binding */ RiveFile),
|
|
4718
|
-
/* harmony export */ RiveFont: () => (/* reexport safe */
|
|
6601
|
+
/* harmony export */ RiveFont: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_3__.RiveFont),
|
|
4719
6602
|
/* harmony export */ RuntimeLoader: () => (/* reexport safe */ _runtimeLoader__WEBPACK_IMPORTED_MODULE_1__.RuntimeLoader),
|
|
6603
|
+
/* harmony export */ SemanticMode: () => (/* reexport safe */ _semantics__WEBPACK_IMPORTED_MODULE_2__.SemanticMode),
|
|
4720
6604
|
/* harmony export */ StateMachineInput: () => (/* binding */ StateMachineInput),
|
|
4721
6605
|
/* harmony export */ StateMachineInputType: () => (/* binding */ StateMachineInputType),
|
|
4722
6606
|
/* harmony export */ Testing: () => (/* binding */ Testing),
|
|
4723
6607
|
/* harmony export */ ViewModel: () => (/* binding */ ViewModel),
|
|
4724
6608
|
/* harmony export */ ViewModelInstance: () => (/* binding */ ViewModelInstance),
|
|
4725
6609
|
/* harmony export */ ViewModelInstanceArtboard: () => (/* binding */ ViewModelInstanceArtboard),
|
|
6610
|
+
/* harmony export */ ViewModelInstanceAssetFont: () => (/* binding */ ViewModelInstanceAssetFont),
|
|
4726
6611
|
/* harmony export */ ViewModelInstanceAssetImage: () => (/* binding */ ViewModelInstanceAssetImage),
|
|
4727
6612
|
/* harmony export */ ViewModelInstanceBoolean: () => (/* binding */ ViewModelInstanceBoolean),
|
|
4728
6613
|
/* harmony export */ ViewModelInstanceColor: () => (/* binding */ ViewModelInstanceColor),
|
|
@@ -4738,7 +6623,8 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
4738
6623
|
/* harmony export */ });
|
|
4739
6624
|
/* harmony import */ var _animation__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
|
|
4740
6625
|
/* harmony import */ var _runtimeLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3);
|
|
4741
|
-
/* harmony import */ var
|
|
6626
|
+
/* harmony import */ var _semantics__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6);
|
|
6627
|
+
/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(10);
|
|
4742
6628
|
var __extends = (undefined && undefined.__extends) || (function () {
|
|
4743
6629
|
var extendStatics = function (d, b) {
|
|
4744
6630
|
extendStatics = Object.setPrototypeOf ||
|
|
@@ -4813,6 +6699,7 @@ var __spreadArray = (undefined && undefined.__spreadArray) || function (to, from
|
|
|
4813
6699
|
|
|
4814
6700
|
|
|
4815
6701
|
|
|
6702
|
+
|
|
4816
6703
|
var RiveError = /** @class */ (function (_super) {
|
|
4817
6704
|
__extends(RiveError, _super);
|
|
4818
6705
|
function RiveError() {
|
|
@@ -4823,6 +6710,7 @@ var RiveError = /** @class */ (function (_super) {
|
|
|
4823
6710
|
return RiveError;
|
|
4824
6711
|
}(Error));
|
|
4825
6712
|
|
|
6713
|
+
|
|
4826
6714
|
// #regions helpers
|
|
4827
6715
|
var resolveErrorMessage = function (error) {
|
|
4828
6716
|
return error && error.isHandledError
|
|
@@ -5071,8 +6959,17 @@ var StateMachine = /** @class */ (function () {
|
|
|
5071
6959
|
this.inputs = [];
|
|
5072
6960
|
this.instance = new runtime.StateMachineInstance(stateMachine, artboard);
|
|
5073
6961
|
this.initInputs(runtime);
|
|
5074
|
-
this.hasFocusNodes = this.instance.hasFocusNodes();
|
|
5075
6962
|
}
|
|
6963
|
+
Object.defineProperty(StateMachine.prototype, "hasFocusNodes", {
|
|
6964
|
+
/**
|
|
6965
|
+
* Whether this state machine has focus nodes
|
|
6966
|
+
*/
|
|
6967
|
+
get: function () {
|
|
6968
|
+
return this.instance.hasFocusNodes();
|
|
6969
|
+
},
|
|
6970
|
+
enumerable: false,
|
|
6971
|
+
configurable: true
|
|
6972
|
+
});
|
|
5076
6973
|
Object.defineProperty(StateMachine.prototype, "name", {
|
|
5077
6974
|
get: function () {
|
|
5078
6975
|
return this.stateMachine.name;
|
|
@@ -5108,6 +7005,37 @@ var StateMachine = /** @class */ (function () {
|
|
|
5108
7005
|
StateMachine.prototype.advanceAndApply = function (time) {
|
|
5109
7006
|
this.instance.advanceAndApply(time);
|
|
5110
7007
|
};
|
|
7008
|
+
/**
|
|
7009
|
+
* Enables semantic tree tracking for this state machine instance.
|
|
7010
|
+
*/
|
|
7011
|
+
StateMachine.prototype.enableSemantics = function () {
|
|
7012
|
+
this.instance.enableSemantics();
|
|
7013
|
+
};
|
|
7014
|
+
/**
|
|
7015
|
+
* Returns the incremental semantic diff since the last call, or null
|
|
7016
|
+
* if semantics is not enabled or nothing changed.
|
|
7017
|
+
*/
|
|
7018
|
+
StateMachine.prototype.drainSemanticsDiff = function () {
|
|
7019
|
+
return this.instance.drainSemanticsDiff();
|
|
7020
|
+
};
|
|
7021
|
+
/**
|
|
7022
|
+
* Fire a semantic action (tap, increase, decrease) on a node.
|
|
7023
|
+
* @param nodeId - The semantic node ID to target
|
|
7024
|
+
* @param actionType - 0 = tap, 1 = increase, 2 = decrease
|
|
7025
|
+
*/
|
|
7026
|
+
StateMachine.prototype.fireSemanticAction = function (nodeId, actionType) {
|
|
7027
|
+
this.instance.fireSemanticAction(nodeId, actionType);
|
|
7028
|
+
};
|
|
7029
|
+
/**
|
|
7030
|
+
* When tools that enable accessible experiences traverse elements with focus,
|
|
7031
|
+
* we should call this method to focus the semantic node. It will also trigger
|
|
7032
|
+
* focus on any Focus listeners for this node
|
|
7033
|
+
* @param nodeId ID of the Semantic Node to focus
|
|
7034
|
+
* @returns boolean - True if focus was set, false otherwise
|
|
7035
|
+
*/
|
|
7036
|
+
StateMachine.prototype.focusSemanticNode = function (nodeId) {
|
|
7037
|
+
return this.instance.focusSemanticNode(nodeId);
|
|
7038
|
+
};
|
|
5111
7039
|
/**
|
|
5112
7040
|
* Returns the number of events reported from the last advance call
|
|
5113
7041
|
* @returns Number of events reported
|
|
@@ -5212,8 +7140,9 @@ var Animator = /** @class */ (function () {
|
|
|
5212
7140
|
* @param animatable the name(s) of animations and state machines to add
|
|
5213
7141
|
* @returns a list of names of the playing animations and state machines
|
|
5214
7142
|
*/
|
|
5215
|
-
Animator.prototype.add = function (animatables, playing, fireEvent) {
|
|
7143
|
+
Animator.prototype.add = function (animatables, playing, fireEvent, semanticsActive) {
|
|
5216
7144
|
if (fireEvent === void 0) { fireEvent = true; }
|
|
7145
|
+
if (semanticsActive === void 0) { semanticsActive = false; }
|
|
5217
7146
|
animatables = mapToStringArray(animatables);
|
|
5218
7147
|
// If animatables is empty, play or pause everything
|
|
5219
7148
|
if (animatables.length === 0) {
|
|
@@ -5252,6 +7181,9 @@ var Animator = /** @class */ (function () {
|
|
|
5252
7181
|
var sm = this.artboard.stateMachineByName(animatables[i]);
|
|
5253
7182
|
if (sm) {
|
|
5254
7183
|
var newStateMachine = new StateMachine(sm, this.runtime, playing, this.artboard);
|
|
7184
|
+
if (semanticsActive) {
|
|
7185
|
+
newStateMachine.enableSemantics();
|
|
7186
|
+
}
|
|
5255
7187
|
this.stateMachines.push(newStateMachine);
|
|
5256
7188
|
}
|
|
5257
7189
|
}
|
|
@@ -5317,7 +7249,7 @@ var Animator = /** @class */ (function () {
|
|
|
5317
7249
|
* @param animatables the name(s) of state machines to add
|
|
5318
7250
|
* @param playing whether state machines should play on instantiation
|
|
5319
7251
|
*/
|
|
5320
|
-
Animator.prototype.initStateMachines = function (animatables, playing) {
|
|
7252
|
+
Animator.prototype.initStateMachines = function (animatables, playing, semanticsActive) {
|
|
5321
7253
|
// Play/pause already instanced items, or create new instances
|
|
5322
7254
|
// This validation is kept to maintain compatibility with current behavior.
|
|
5323
7255
|
// But given that it this is called during artboard initialization
|
|
@@ -5333,6 +7265,9 @@ var Animator = /** @class */ (function () {
|
|
|
5333
7265
|
var sm = this.artboard.stateMachineByName(animatables[i]);
|
|
5334
7266
|
if (sm) {
|
|
5335
7267
|
var newStateMachine = new StateMachine(sm, this.runtime, playing, this.artboard);
|
|
7268
|
+
if (semanticsActive) {
|
|
7269
|
+
newStateMachine.enableSemantics();
|
|
7270
|
+
}
|
|
5336
7271
|
this.stateMachines.push(newStateMachine);
|
|
5337
7272
|
}
|
|
5338
7273
|
else {
|
|
@@ -5498,8 +7433,9 @@ var Animator = /** @class */ (function () {
|
|
|
5498
7433
|
* If there are no animations or state machines, add the first one found
|
|
5499
7434
|
* @returns the name of the animation or state machine instanced
|
|
5500
7435
|
*/
|
|
5501
|
-
Animator.prototype.atLeastOne = function (playing, fireEvent) {
|
|
7436
|
+
Animator.prototype.atLeastOne = function (playing, fireEvent, semanticsActive) {
|
|
5502
7437
|
if (fireEvent === void 0) { fireEvent = true; }
|
|
7438
|
+
if (semanticsActive === void 0) { semanticsActive = false; }
|
|
5503
7439
|
var instancedName;
|
|
5504
7440
|
if (this.animations.length === 0 && this.stateMachines.length === 0) {
|
|
5505
7441
|
if (this.artboard.animationCount() > 0) {
|
|
@@ -5508,7 +7444,7 @@ var Animator = /** @class */ (function () {
|
|
|
5508
7444
|
}
|
|
5509
7445
|
else if (this.artboard.stateMachineCount() > 0) {
|
|
5510
7446
|
// Add the first state machine
|
|
5511
|
-
this.add([(instancedName = this.artboard.stateMachineByIndex(0).name)], playing, fireEvent);
|
|
7447
|
+
this.add([(instancedName = this.artboard.stateMachineByIndex(0).name)], playing, fireEvent, semanticsActive);
|
|
5512
7448
|
}
|
|
5513
7449
|
}
|
|
5514
7450
|
return instancedName;
|
|
@@ -5900,6 +7836,9 @@ var ObjectObservers = /** @class */ (function () {
|
|
|
5900
7836
|
return ObjectObservers;
|
|
5901
7837
|
}());
|
|
5902
7838
|
var observers = new ObjectObservers();
|
|
7839
|
+
// #endregion
|
|
7840
|
+
// #region Rive
|
|
7841
|
+
var nextRiveInstanceId = 0;
|
|
5903
7842
|
var RiveFile = /** @class */ (function () {
|
|
5904
7843
|
function RiveFile(params) {
|
|
5905
7844
|
// Allow the runtime to automatically load assets hosted in Rive's runtime.
|
|
@@ -5966,7 +7905,7 @@ var RiveFile = /** @class */ (function () {
|
|
|
5966
7905
|
return [2 /*return*/];
|
|
5967
7906
|
}
|
|
5968
7907
|
if (this.assetLoader) {
|
|
5969
|
-
loaderWrapper = new
|
|
7908
|
+
loaderWrapper = new _utils__WEBPACK_IMPORTED_MODULE_3__.CustomFileAssetLoaderWrapper(this.runtime, this.assetLoader);
|
|
5970
7909
|
loader = loaderWrapper.assetLoader;
|
|
5971
7910
|
}
|
|
5972
7911
|
// Load the Rive file
|
|
@@ -5980,8 +7919,8 @@ var RiveFile = /** @class */ (function () {
|
|
|
5980
7919
|
performance.mark('rive:file-load:end');
|
|
5981
7920
|
performance.measure('rive:file-load', 'rive:file-load:start', 'rive:file-load:end');
|
|
5982
7921
|
}
|
|
5983
|
-
fileFinalizer = new
|
|
5984
|
-
|
|
7922
|
+
fileFinalizer = new _utils__WEBPACK_IMPORTED_MODULE_3__.FileFinalizer(this.file);
|
|
7923
|
+
_utils__WEBPACK_IMPORTED_MODULE_3__.finalizationRegistry.register(this, fileFinalizer);
|
|
5985
7924
|
if (this.destroyed) {
|
|
5986
7925
|
this.releaseFile();
|
|
5987
7926
|
return [2 /*return*/];
|
|
@@ -6139,7 +8078,7 @@ var RiveFile = /** @class */ (function () {
|
|
|
6139
8078
|
RiveFile.prototype.createBindableArtboard = function (nativeBindableArtboard) {
|
|
6140
8079
|
if (nativeBindableArtboard != null) {
|
|
6141
8080
|
var bindableArtboard = new BindableArtboard(nativeBindableArtboard);
|
|
6142
|
-
(0,
|
|
8081
|
+
(0,_utils__WEBPACK_IMPORTED_MODULE_3__.createFinalization)(bindableArtboard, bindableArtboard.nativeArtboard);
|
|
6143
8082
|
this.bindableArtboards.push(bindableArtboard);
|
|
6144
8083
|
return bindableArtboard;
|
|
6145
8084
|
}
|
|
@@ -6176,6 +8115,12 @@ var RiveFile = /** @class */ (function () {
|
|
|
6176
8115
|
}
|
|
6177
8116
|
return null;
|
|
6178
8117
|
};
|
|
8118
|
+
/**
|
|
8119
|
+
* @returns the names of the file's global view models, in file order.
|
|
8120
|
+
*/
|
|
8121
|
+
RiveFile.prototype.globalViewModelNames = function () {
|
|
8122
|
+
return this.file.globalViewModelNames();
|
|
8123
|
+
};
|
|
6179
8124
|
// Error message for missing source or buffer
|
|
6180
8125
|
RiveFile.missingErrorMessage = "Rive source file or data buffer required";
|
|
6181
8126
|
// Error message for file load error
|
|
@@ -6186,7 +8131,7 @@ var RiveFile = /** @class */ (function () {
|
|
|
6186
8131
|
var Rive = /** @class */ (function () {
|
|
6187
8132
|
function Rive(params) {
|
|
6188
8133
|
var _this = this;
|
|
6189
|
-
var _a, _b, _c;
|
|
8134
|
+
var _a, _b, _c, _d;
|
|
6190
8135
|
// Tracks if a Rive file is loaded
|
|
6191
8136
|
this.loaded = false;
|
|
6192
8137
|
// Tracks if a Rive file is destroyed
|
|
@@ -6214,6 +8159,12 @@ var Rive = /** @class */ (function () {
|
|
|
6214
8159
|
this.enableMultiTouch = false;
|
|
6215
8160
|
// Allow the runtime to automatically load assets hosted in Rive's runtime.
|
|
6216
8161
|
this.enableRiveAssetCDN = true;
|
|
8162
|
+
this.semanticsMode = _semantics__WEBPACK_IMPORTED_MODULE_2__.SemanticMode.Disabled;
|
|
8163
|
+
this.semanticsOptions = {
|
|
8164
|
+
riveCanvasLabel: "Rive animation",
|
|
8165
|
+
};
|
|
8166
|
+
/** True when this instance may drain semantics and render the overlay. */
|
|
8167
|
+
this._semanticsActive = false;
|
|
6217
8168
|
// Keep a local value of the set volume to update it asynchronously
|
|
6218
8169
|
this._volume = 1;
|
|
6219
8170
|
// Keep a local value of the set width to update it asynchronously
|
|
@@ -6242,12 +8193,29 @@ var Rive = /** @class */ (function () {
|
|
|
6242
8193
|
// visibilitychange handler from restarting a rendering loop the caller intentionally stopped.
|
|
6243
8194
|
this._explicitlyStoppedRendering = false;
|
|
6244
8195
|
this._viewModelInstance = null;
|
|
8196
|
+
// User-provided global view model instances, keyed by their global view
|
|
8197
|
+
// model's name. Globals not present here are still driven by the default
|
|
8198
|
+
// instances the runtime seeds; the getter only surfaces instances the user
|
|
8199
|
+
// has explicitly set.
|
|
8200
|
+
this._globalViewModelInstances = new Map();
|
|
6245
8201
|
this._dataEnums = null;
|
|
6246
8202
|
this._tabIndex = null;
|
|
6247
8203
|
this._prevHasFocus = false;
|
|
6248
8204
|
this._focusOptions = {
|
|
6249
8205
|
allowFocusInterrupt: false,
|
|
6250
8206
|
};
|
|
8207
|
+
// Tracks the semantic tree for the given graphic
|
|
8208
|
+
this._semanticTree = null;
|
|
8209
|
+
this._accessibilityOverlay = null;
|
|
8210
|
+
/**
|
|
8211
|
+
* True when an input to the accessibility overlay's artboard→canvas transform
|
|
8212
|
+
* (layout fit/alignment/bounds, devicePixelRatio, or layout scale) has changed
|
|
8213
|
+
* and the matrix must be recomputed on the next overlay update. Avoids calling
|
|
8214
|
+
* computeAlignment every frame when only the semantic tree changed.
|
|
8215
|
+
*/
|
|
8216
|
+
this._overlayTransformDirty = true;
|
|
8217
|
+
// Module-level counter for unique instance IDs for semantic overlay containers
|
|
8218
|
+
this._instanceId = "".concat(nextRiveInstanceId++);
|
|
6251
8219
|
this.drawOptimization = DrawOptimizationOptions.DrawOnChanged;
|
|
6252
8220
|
// When true, emits performance.mark/measure entries for load and render.
|
|
6253
8221
|
this.enablePerfMarks = false;
|
|
@@ -6307,6 +8275,7 @@ var Rive = /** @class */ (function () {
|
|
|
6307
8275
|
if (this.enablePerfMarks)
|
|
6308
8276
|
_runtimeLoader__WEBPACK_IMPORTED_MODULE_1__.RuntimeLoader.enablePerfMarks = true;
|
|
6309
8277
|
this._focusOptions = (_c = params.focusOptions) !== null && _c !== void 0 ? _c : this._focusOptions;
|
|
8278
|
+
this._tabIndex = (_d = params.tabIndex) !== null && _d !== void 0 ? _d : null;
|
|
6310
8279
|
// New event management system
|
|
6311
8280
|
this.eventManager = new EventManager();
|
|
6312
8281
|
if (params.onLoad)
|
|
@@ -6360,6 +8329,8 @@ var Rive = /** @class */ (function () {
|
|
|
6360
8329
|
artboard: params.artboard,
|
|
6361
8330
|
useOffscreenRenderer: params.useOffscreenRenderer,
|
|
6362
8331
|
tabIndex: params.tabIndex,
|
|
8332
|
+
semanticsMode: params.semanticsMode,
|
|
8333
|
+
semanticsOptions: params.semanticsOptions,
|
|
6363
8334
|
});
|
|
6364
8335
|
}
|
|
6365
8336
|
Object.defineProperty(Rive.prototype, "viewModelCount", {
|
|
@@ -6374,6 +8345,44 @@ var Rive = /** @class */ (function () {
|
|
|
6374
8345
|
console.warn("This function is deprecated: please use `new Rive({})` instead");
|
|
6375
8346
|
return new Rive(params);
|
|
6376
8347
|
};
|
|
8348
|
+
/**
|
|
8349
|
+
* @experimental Turns on semantics and the accessibility overlay for this
|
|
8350
|
+
* instance. Idempotent; safe to call before or after load. Use this to drive
|
|
8351
|
+
* a consumer-controlled accessibility toggle when constructed with the
|
|
8352
|
+
* default {@link SemanticMode.Disabled}.
|
|
8353
|
+
*/
|
|
8354
|
+
Rive.prototype.enableSemantics = function () {
|
|
8355
|
+
this.semanticsMode = _semantics__WEBPACK_IMPORTED_MODULE_2__.SemanticMode.Enabled;
|
|
8356
|
+
this.activateSemantics();
|
|
8357
|
+
};
|
|
8358
|
+
Rive.prototype.activateSemantics = function () {
|
|
8359
|
+
if (this._semanticsActive || this.semanticsMode === _semantics__WEBPACK_IMPORTED_MODULE_2__.SemanticMode.Disabled) {
|
|
8360
|
+
return;
|
|
8361
|
+
}
|
|
8362
|
+
this._semanticsActive = true;
|
|
8363
|
+
this.syncSemanticsOnStateMachines();
|
|
8364
|
+
};
|
|
8365
|
+
Rive.prototype.syncSemanticsOnStateMachines = function () {
|
|
8366
|
+
if (!this._semanticsActive || !this.animator) {
|
|
8367
|
+
return;
|
|
8368
|
+
}
|
|
8369
|
+
for (var _i = 0, _a = this.animator.stateMachines; _i < _a.length; _i++) {
|
|
8370
|
+
var stateMachine = _a[_i];
|
|
8371
|
+
stateMachine.enableSemantics();
|
|
8372
|
+
}
|
|
8373
|
+
};
|
|
8374
|
+
/**
|
|
8375
|
+
* Tears down the semantic tree and accessibility overlay. The overlay captures the
|
|
8376
|
+
* active state machine in its action closures, so it must not outlive the
|
|
8377
|
+
* instances it points at (reset/load delete them)
|
|
8378
|
+
*/
|
|
8379
|
+
Rive.prototype.cleanupSemantics = function () {
|
|
8380
|
+
this._semanticTree = null;
|
|
8381
|
+
if (this._accessibilityOverlay) {
|
|
8382
|
+
this._accessibilityOverlay.destroy();
|
|
8383
|
+
this._accessibilityOverlay = null;
|
|
8384
|
+
}
|
|
8385
|
+
};
|
|
6377
8386
|
// Event handler for when audio context becomes available
|
|
6378
8387
|
Rive.prototype.onSystemAudioChanged = function () {
|
|
6379
8388
|
this.volume = this._volume;
|
|
@@ -6381,7 +8390,7 @@ var Rive = /** @class */ (function () {
|
|
|
6381
8390
|
// Initializes the Rive object either from constructor or load()
|
|
6382
8391
|
Rive.prototype.init = function (_a) {
|
|
6383
8392
|
var _this = this;
|
|
6384
|
-
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;
|
|
8393
|
+
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;
|
|
6385
8394
|
if (this.destroyed) {
|
|
6386
8395
|
return;
|
|
6387
8396
|
}
|
|
@@ -6389,6 +8398,8 @@ var Rive = /** @class */ (function () {
|
|
|
6389
8398
|
this.buffer = buffer;
|
|
6390
8399
|
this.riveFile = riveFile;
|
|
6391
8400
|
this._tabIndex = tabIndex !== null && tabIndex !== void 0 ? tabIndex : null;
|
|
8401
|
+
this.semanticsMode = semanticsMode !== null && semanticsMode !== void 0 ? semanticsMode : _semantics__WEBPACK_IMPORTED_MODULE_2__.SemanticMode.Disabled;
|
|
8402
|
+
this.semanticsOptions = semanticsOptions !== null && semanticsOptions !== void 0 ? semanticsOptions : this.semanticsOptions;
|
|
6392
8403
|
// If no source file url specified, it's a bust
|
|
6393
8404
|
if (!this.src && !this.buffer && !this.riveFile) {
|
|
6394
8405
|
throw new RiveError(Rive.missingErrorMessage);
|
|
@@ -6408,6 +8419,9 @@ var Rive = /** @class */ (function () {
|
|
|
6408
8419
|
}
|
|
6409
8420
|
_this.runtime = runtime;
|
|
6410
8421
|
_this.removeRiveListeners();
|
|
8422
|
+
// load() reinitializes without cleanupInstances(); drop any stale overlay
|
|
8423
|
+
// bound to the previous file's state machines (no-op on first construct).
|
|
8424
|
+
_this.cleanupSemantics();
|
|
6411
8425
|
_this.deleteRiveRenderer();
|
|
6412
8426
|
// Get the canvas where you want to render the animation and create a renderer
|
|
6413
8427
|
if (_this.enablePerfMarks)
|
|
@@ -6472,7 +8486,7 @@ var Rive = /** @class */ (function () {
|
|
|
6472
8486
|
"isTouchScrollEnabled" in riveListenerOptions) {
|
|
6473
8487
|
touchScrollEnabledOption = riveListenerOptions.isTouchScrollEnabled;
|
|
6474
8488
|
}
|
|
6475
|
-
this.eventCleanup = (0,
|
|
8489
|
+
this.eventCleanup = (0,_utils__WEBPACK_IMPORTED_MODULE_3__.registerTouchInteractions)({
|
|
6476
8490
|
canvas: this.canvas,
|
|
6477
8491
|
artboard: this.artboard,
|
|
6478
8492
|
stateMachines: activeStateMachines,
|
|
@@ -6486,28 +8500,36 @@ var Rive = /** @class */ (function () {
|
|
|
6486
8500
|
layoutScaleFactor: this._layout.layoutScaleFactor,
|
|
6487
8501
|
advanceAndDrain: this.advanceAndReportChanges.bind(this)
|
|
6488
8502
|
});
|
|
6489
|
-
|
|
6490
|
-
// hasFocusNodes — unified focus tree check, gates tab traversal
|
|
6491
|
-
var smWithFocusNodes = playingStateMachines.filter(function (sm) { return sm.hasFocusNodes; });
|
|
6492
|
-
if (smWithFocusNodes.length) {
|
|
6493
|
-
// Set the canvas as a tabbable element if there are any focus nodes.
|
|
6494
|
-
// Prefer the tabIndex param set by the user, otherwise use 0.
|
|
6495
|
-
// But do not override any explicit tabIndex already set on the canvas, if any.
|
|
6496
|
-
var currentCanvasTabIndex = this.canvas.tabIndex;
|
|
6497
|
-
// By default, canvas elements have a tabIndex of -1
|
|
6498
|
-
if (currentCanvasTabIndex === -1 || isNaN(currentCanvasTabIndex)) {
|
|
6499
|
-
this.canvas.tabIndex = (this._tabIndex !== null ? this._tabIndex : 0);
|
|
6500
|
-
}
|
|
6501
|
-
if (typeof window !== "undefined") {
|
|
6502
|
-
this._keyboardInteractions = new _utils__WEBPACK_IMPORTED_MODULE_2__.KeyboardInteractions({
|
|
6503
|
-
canvas: this.canvas,
|
|
6504
|
-
stateMachine: smWithFocusNodes[0].instance, // work off assumption of single state machine
|
|
6505
|
-
hasFocusNodes: true,
|
|
6506
|
-
});
|
|
6507
|
-
}
|
|
6508
|
-
}
|
|
8503
|
+
this.ensureKeyboardInteractions();
|
|
6509
8504
|
}
|
|
6510
8505
|
};
|
|
8506
|
+
/**
|
|
8507
|
+
* Wire keyboard interactions when a playing state machine has focus nodes.
|
|
8508
|
+
* Called at listener setup and lazily each frame so late-bound bindable artboards work.
|
|
8509
|
+
*/
|
|
8510
|
+
Rive.prototype.ensureKeyboardInteractions = function () {
|
|
8511
|
+
var _this = this;
|
|
8512
|
+
if (this._keyboardInteractions ||
|
|
8513
|
+
this.shouldDisableRiveListeners ||
|
|
8514
|
+
typeof window === "undefined" ||
|
|
8515
|
+
!(this.canvas instanceof HTMLCanvasElement)) {
|
|
8516
|
+
return;
|
|
8517
|
+
}
|
|
8518
|
+
var smWithFocusNodes = this.animator.stateMachines.find(function (sm) { return sm.playing && sm.hasFocusNodes; });
|
|
8519
|
+
if (!smWithFocusNodes) {
|
|
8520
|
+
return;
|
|
8521
|
+
}
|
|
8522
|
+
var currentCanvasTabIndex = this.canvas.tabIndex;
|
|
8523
|
+
if (currentCanvasTabIndex === -1 || isNaN(currentCanvasTabIndex)) {
|
|
8524
|
+
this.canvas.tabIndex = (this._tabIndex !== null ? this._tabIndex : 0);
|
|
8525
|
+
}
|
|
8526
|
+
this._keyboardInteractions = new _utils__WEBPACK_IMPORTED_MODULE_3__.KeyboardInteractions({
|
|
8527
|
+
canvas: this.canvas,
|
|
8528
|
+
stateMachine: smWithFocusNodes.instance, // work off assumption of single state machine
|
|
8529
|
+
hasFocusNodes: true,
|
|
8530
|
+
getOverlayElement: function () { var _a, _b; return (_b = (_a = _this._accessibilityOverlay) === null || _a === void 0 ? void 0 : _a.getSemanticOverlayContainer()) !== null && _b !== void 0 ? _b : null; },
|
|
8531
|
+
});
|
|
8532
|
+
};
|
|
6511
8533
|
Rive.prototype.cleanupKeyboardInteractions = function () {
|
|
6512
8534
|
if (this._keyboardInteractions) {
|
|
6513
8535
|
this._keyboardInteractions.cleanup();
|
|
@@ -6590,6 +8612,12 @@ var Rive = /** @class */ (function () {
|
|
|
6590
8612
|
this.initArtboardSize();
|
|
6591
8613
|
// Check for audio
|
|
6592
8614
|
this.initializeAudio();
|
|
8615
|
+
if (this.semanticsMode === _semantics__WEBPACK_IMPORTED_MODULE_2__.SemanticMode.Enabled) {
|
|
8616
|
+
this.activateSemantics();
|
|
8617
|
+
}
|
|
8618
|
+
else if (this._semanticsActive) {
|
|
8619
|
+
this.syncSemanticsOnStateMachines();
|
|
8620
|
+
}
|
|
6593
8621
|
// Everything's set up, emit a load event
|
|
6594
8622
|
try {
|
|
6595
8623
|
this.loaded = true;
|
|
@@ -6648,10 +8676,10 @@ var Rive = /** @class */ (function () {
|
|
|
6648
8676
|
if (animationNames.length > 0 || stateMachineNames.length > 0) {
|
|
6649
8677
|
instanceNames = animationNames.concat(stateMachineNames);
|
|
6650
8678
|
this.animator.initLinearAnimations(animationNames, autoplay);
|
|
6651
|
-
this.animator.initStateMachines(stateMachineNames, autoplay);
|
|
8679
|
+
this.animator.initStateMachines(stateMachineNames, autoplay, this._semanticsActive);
|
|
6652
8680
|
}
|
|
6653
8681
|
else {
|
|
6654
|
-
instanceNames = [this.animator.atLeastOne(autoplay, false)];
|
|
8682
|
+
instanceNames = [this.animator.atLeastOne(autoplay, false, this._semanticsActive)];
|
|
6655
8683
|
}
|
|
6656
8684
|
// Queue up firing the playback events
|
|
6657
8685
|
this.taskQueue.add({
|
|
@@ -6661,15 +8689,29 @@ var Rive = /** @class */ (function () {
|
|
|
6661
8689
|
},
|
|
6662
8690
|
});
|
|
6663
8691
|
if (autoBind) {
|
|
8692
|
+
// Set the main view model instance (if the artboard has one)...
|
|
6664
8693
|
var viewModel = this.file.defaultArtboardViewModel(rootArtboard);
|
|
6665
8694
|
if (viewModel !== null) {
|
|
6666
8695
|
var runtimeInstance = viewModel.defaultInstance();
|
|
6667
8696
|
if (runtimeInstance !== null) {
|
|
6668
8697
|
var viewModelInstance = new ViewModelInstance(runtimeInstance, null);
|
|
6669
|
-
(0,
|
|
6670
|
-
this.
|
|
8698
|
+
(0,_utils__WEBPACK_IMPORTED_MODULE_3__.createFinalization)(viewModelInstance, viewModelInstance.runtimeInstance);
|
|
8699
|
+
this.setViewModelInstance(viewModelInstance);
|
|
6671
8700
|
}
|
|
6672
8701
|
}
|
|
8702
|
+
// ...and a default instance for each global view model (no longer
|
|
8703
|
+
// auto-created by the runtime), then apply everything in one rebind.
|
|
8704
|
+
for (var _i = 0, _a = this.file.globalViewModelNames(); _i < _a.length; _i++) {
|
|
8705
|
+
var name_1 = _a[_i];
|
|
8706
|
+
var globalViewModel = this.file.viewModelByName(name_1);
|
|
8707
|
+
if (globalViewModel !== null) {
|
|
8708
|
+
var instance = new ViewModel(globalViewModel).defaultInstance();
|
|
8709
|
+
if (instance !== null) {
|
|
8710
|
+
this.setGlobalViewModelInstance(name_1, instance);
|
|
8711
|
+
}
|
|
8712
|
+
}
|
|
8713
|
+
}
|
|
8714
|
+
this.bind();
|
|
6673
8715
|
}
|
|
6674
8716
|
};
|
|
6675
8717
|
// Draws the current artboard frame
|
|
@@ -6704,6 +8746,8 @@ var Rive = /** @class */ (function () {
|
|
|
6704
8746
|
* Rive internally updated focus outside of user interaction (e.g., via listener action)
|
|
6705
8747
|
*/
|
|
6706
8748
|
Rive.prototype.pollFocusState = function () {
|
|
8749
|
+
var _a, _b;
|
|
8750
|
+
this.ensureKeyboardInteractions();
|
|
6707
8751
|
if (!this._keyboardInteractions) {
|
|
6708
8752
|
this._prevHasFocus = false;
|
|
6709
8753
|
return;
|
|
@@ -6722,7 +8766,16 @@ var Rive = /** @class */ (function () {
|
|
|
6722
8766
|
// Only steal DOM focus on the false→true transition. If hasFocus stays
|
|
6723
8767
|
// true across frames and the user clicks away, do not re-focus the canvas again.
|
|
6724
8768
|
if (!this._prevHasFocus) {
|
|
6725
|
-
|
|
8769
|
+
// Steal DOM focus to the canvas only when focus isn't already held
|
|
8770
|
+
// somewhere inside this instance's focus scope. When the accessibility
|
|
8771
|
+
// overlay has driven focus onto a specific semantic node element (e.g.
|
|
8772
|
+
// an appearing alert dialog), focus is already in-scope. The steal
|
|
8773
|
+
// stays a fallback for runtime focus nodes that have no overlay element
|
|
8774
|
+
// to hold DOM focus.
|
|
8775
|
+
var scope = (_a = this._accessibilityOverlay) === null || _a === void 0 ? void 0 : _a.getSemanticOverlayContainer();
|
|
8776
|
+
var focusAlreadyInScope = document.activeElement === this.canvas ||
|
|
8777
|
+
((_b = scope === null || scope === void 0 ? void 0 : scope.contains(document.activeElement)) !== null && _b !== void 0 ? _b : false);
|
|
8778
|
+
if (!focusAlreadyInScope && this._focusOptions.allowFocusInterrupt) {
|
|
6726
8779
|
this.canvas.focus();
|
|
6727
8780
|
}
|
|
6728
8781
|
this._prevHasFocus = true;
|
|
@@ -6734,8 +8787,8 @@ var Rive = /** @class */ (function () {
|
|
|
6734
8787
|
// (state change clears focus). Release the DOM Tab trap so the next Tab moves to the next
|
|
6735
8788
|
// page element. EntryPending and NotFocused cases are intentional no-ops — EntryPending in
|
|
6736
8789
|
// particular must stay in its state (a click awaiting its first Tab) rather than be reset here.
|
|
6737
|
-
if (this._keyboardInteractions.focusSessionState ===
|
|
6738
|
-
this._keyboardInteractions.setFocusSessionState(
|
|
8790
|
+
if (this._keyboardInteractions.focusSessionState === _utils__WEBPACK_IMPORTED_MODULE_3__.FocusSessionState.RiveFocused) {
|
|
8791
|
+
this._keyboardInteractions.setFocusSessionState(_utils__WEBPACK_IMPORTED_MODULE_3__.FocusSessionState.NotFocused);
|
|
6739
8792
|
}
|
|
6740
8793
|
}
|
|
6741
8794
|
};
|
|
@@ -6746,7 +8799,7 @@ var Rive = /** @class */ (function () {
|
|
|
6746
8799
|
* @param elapsedTime time to advance the state machine by
|
|
6747
8800
|
*/
|
|
6748
8801
|
Rive.prototype.advanceAndReportChanges = function (elapsedTime) {
|
|
6749
|
-
var _a;
|
|
8802
|
+
var _a, _b;
|
|
6750
8803
|
// - Advance non-paused animations by the elapsed number of seconds
|
|
6751
8804
|
// - Advance any animations that require scrubbing
|
|
6752
8805
|
// - Advance to the first frame even when autoplay is false
|
|
@@ -6769,8 +8822,8 @@ var Rive = /** @class */ (function () {
|
|
|
6769
8822
|
// Instrument the first 3 frames so the Performance timeline shows precise
|
|
6770
8823
|
// per-call latency for advance, draw, and flush without polluting the trace.
|
|
6771
8824
|
var _perfFrame = this.enablePerfMarks && this.frameCount < 3 ? this.frameCount : -1;
|
|
6772
|
-
for (var
|
|
6773
|
-
var stateMachine = activeStateMachines_1[
|
|
8825
|
+
for (var _c = 0, activeStateMachines_1 = activeStateMachines; _c < activeStateMachines_1.length; _c++) {
|
|
8826
|
+
var stateMachine = activeStateMachines_1[_c];
|
|
6774
8827
|
// Check for events before the current frame's state machine advance
|
|
6775
8828
|
var numEventsReported = stateMachine.reportedEventCount();
|
|
6776
8829
|
if (numEventsReported) {
|
|
@@ -6785,11 +8838,11 @@ var Rive = /** @class */ (function () {
|
|
|
6785
8838
|
// Handle the event side effect if explicitly enabled
|
|
6786
8839
|
if (this.automaticallyHandleEvents) {
|
|
6787
8840
|
var newAnchorTag = document.createElement("a");
|
|
6788
|
-
var
|
|
6789
|
-
var sanitizedUrl = (0,
|
|
8841
|
+
var _d = event_1, url = _d.url, target = _d.target;
|
|
8842
|
+
var sanitizedUrl = (0,_utils__WEBPACK_IMPORTED_MODULE_3__.sanitizeUrl)(url);
|
|
6790
8843
|
url && newAnchorTag.setAttribute("href", sanitizedUrl);
|
|
6791
8844
|
target && newAnchorTag.setAttribute("target", target);
|
|
6792
|
-
if (sanitizedUrl && sanitizedUrl !==
|
|
8845
|
+
if (sanitizedUrl && sanitizedUrl !== _utils__WEBPACK_IMPORTED_MODULE_3__.BLANK_URL) {
|
|
6793
8846
|
newAnchorTag.click();
|
|
6794
8847
|
}
|
|
6795
8848
|
}
|
|
@@ -6810,6 +8863,61 @@ var Rive = /** @class */ (function () {
|
|
|
6810
8863
|
performance.mark("rive:sm-advance:end:f".concat(_perfFrame));
|
|
6811
8864
|
performance.measure("rive:sm-advance:f".concat(_perfFrame), "rive:sm-advance:start:f".concat(_perfFrame), "rive:sm-advance:end:f".concat(_perfFrame));
|
|
6812
8865
|
}
|
|
8866
|
+
if (this._semanticsActive) {
|
|
8867
|
+
var diff = stateMachine.drainSemanticsDiff();
|
|
8868
|
+
if (diff) {
|
|
8869
|
+
if (!this._semanticTree) {
|
|
8870
|
+
this._semanticTree = new _semantics__WEBPACK_IMPORTED_MODULE_2__.SemanticTreeModel();
|
|
8871
|
+
}
|
|
8872
|
+
this._semanticTree.applyDiff(diff);
|
|
8873
|
+
}
|
|
8874
|
+
}
|
|
8875
|
+
}
|
|
8876
|
+
// Update the accessibility overlay after all state machines have
|
|
8877
|
+
// been advanced and their diffs applied to the tree model.
|
|
8878
|
+
if (this._semanticsActive &&
|
|
8879
|
+
this._semanticTree &&
|
|
8880
|
+
activeStateMachines.length > 0 &&
|
|
8881
|
+
this.canvas instanceof HTMLCanvasElement) {
|
|
8882
|
+
if (!this._accessibilityOverlay) {
|
|
8883
|
+
var mainSm_1 = activeStateMachines[0];
|
|
8884
|
+
this._accessibilityOverlay = new _semantics__WEBPACK_IMPORTED_MODULE_2__.AccessibilityOverlay({
|
|
8885
|
+
canvas: this.canvas,
|
|
8886
|
+
instanceId: this._instanceId,
|
|
8887
|
+
semanticsOptions: this.semanticsOptions,
|
|
8888
|
+
allowFocusInterrupt: this._focusOptions.allowFocusInterrupt,
|
|
8889
|
+
fireAction: function (nodeId, actionType) {
|
|
8890
|
+
mainSm_1.fireSemanticAction(nodeId, actionType);
|
|
8891
|
+
},
|
|
8892
|
+
requestFocus: function (nodeId) {
|
|
8893
|
+
return mainSm_1.focusSemanticNode(nodeId);
|
|
8894
|
+
},
|
|
8895
|
+
clearFocus: function () {
|
|
8896
|
+
return mainSm_1.instance.clearFocus();
|
|
8897
|
+
},
|
|
8898
|
+
});
|
|
8899
|
+
}
|
|
8900
|
+
var overlayChange = (_a = this._accessibilityOverlay) === null || _a === void 0 ? void 0 : _a.needsUpdate(this._semanticTree);
|
|
8901
|
+
if (overlayChange || this._overlayTransformDirty) {
|
|
8902
|
+
// Only recompute the artboard→canvas transform when something that
|
|
8903
|
+
// affects it changed (canvas geometry or a layout/dpr input). When only
|
|
8904
|
+
// the semantic tree changed we pass null and reuse the existing CSS
|
|
8905
|
+
// transform on the overlay container.
|
|
8906
|
+
var forwardMat = null;
|
|
8907
|
+
if ((overlayChange === null || overlayChange === void 0 ? void 0 : overlayChange.layoutChanged) || this._overlayTransformDirty) {
|
|
8908
|
+
var fit_1 = this._layout.runtimeFit(this.runtime);
|
|
8909
|
+
var alignment = this._layout.runtimeAlignment(this.runtime);
|
|
8910
|
+
forwardMat = this.runtime.computeAlignment(fit_1, alignment, {
|
|
8911
|
+
minX: this._layout.minX,
|
|
8912
|
+
minY: this._layout.minY,
|
|
8913
|
+
maxX: this._layout.maxX,
|
|
8914
|
+
maxY: this._layout.maxY,
|
|
8915
|
+
}, this.artboard.bounds, this._devicePixelRatioUsed * this._layout.layoutScaleFactor);
|
|
8916
|
+
this._overlayTransformDirty = false;
|
|
8917
|
+
}
|
|
8918
|
+
this._accessibilityOverlay.update(this._semanticTree, forwardMat, this._devicePixelRatioUsed, this.artboard.bounds, overlayChange);
|
|
8919
|
+
forwardMat === null || forwardMat === void 0 ? void 0 : forwardMat.delete();
|
|
8920
|
+
}
|
|
6813
8921
|
}
|
|
6814
8922
|
// For linear animations that have been applied to the artboard, advance it
|
|
6815
8923
|
// by the elapsed time.
|
|
@@ -6825,7 +8933,7 @@ var Rive = /** @class */ (function () {
|
|
|
6825
8933
|
// Poll focus state to see whether or not to blur or pull up a virtual keyboard for any change to a text input node.
|
|
6826
8934
|
this.pollFocusState();
|
|
6827
8935
|
// Handle callbacks for view model property changes
|
|
6828
|
-
(
|
|
8936
|
+
(_b = this._viewModelInstance) === null || _b === void 0 ? void 0 : _b.handleCallbacks();
|
|
6829
8937
|
};
|
|
6830
8938
|
/**
|
|
6831
8939
|
* Draw rendering loop; renders animation frames at the correct time interval.
|
|
@@ -6987,6 +9095,8 @@ var Rive = /** @class */ (function () {
|
|
|
6987
9095
|
}
|
|
6988
9096
|
(_d = this._viewModelInstance) === null || _d === void 0 ? void 0 : _d.cleanup();
|
|
6989
9097
|
this._viewModelInstance = null;
|
|
9098
|
+
this._globalViewModelInstances.forEach(function (instance) { return instance.cleanup(); });
|
|
9099
|
+
this._globalViewModelInstances.clear();
|
|
6990
9100
|
this._dataEnums = null;
|
|
6991
9101
|
};
|
|
6992
9102
|
/**
|
|
@@ -7010,6 +9120,9 @@ var Rive = /** @class */ (function () {
|
|
|
7010
9120
|
this.eventCleanup();
|
|
7011
9121
|
}
|
|
7012
9122
|
this.cleanupKeyboardInteractions();
|
|
9123
|
+
// Tear down semantics before deleting state machines — the overlay's action
|
|
9124
|
+
// closures point at instances that stop() is about to free.
|
|
9125
|
+
this.cleanupSemantics();
|
|
7013
9126
|
// Delete all animation and state machine instances
|
|
7014
9127
|
this.stop();
|
|
7015
9128
|
if (this.artboard) {
|
|
@@ -7075,6 +9188,7 @@ var Rive = /** @class */ (function () {
|
|
|
7075
9188
|
return;
|
|
7076
9189
|
}
|
|
7077
9190
|
this.animator.play(animationNames);
|
|
9191
|
+
this.syncSemanticsOnStateMachines();
|
|
7078
9192
|
if (this.eventCleanup) {
|
|
7079
9193
|
this.eventCleanup();
|
|
7080
9194
|
}
|
|
@@ -7133,6 +9247,7 @@ var Rive = /** @class */ (function () {
|
|
|
7133
9247
|
this.eventCleanup();
|
|
7134
9248
|
}
|
|
7135
9249
|
this.cleanupKeyboardInteractions();
|
|
9250
|
+
this.cleanupSemantics();
|
|
7136
9251
|
};
|
|
7137
9252
|
/**
|
|
7138
9253
|
* Resets the animation
|
|
@@ -7176,6 +9291,8 @@ var Rive = /** @class */ (function () {
|
|
|
7176
9291
|
// Sets a new layout
|
|
7177
9292
|
set: function (layout) {
|
|
7178
9293
|
this._layout = layout;
|
|
9294
|
+
// Fit/alignment/bounds feed the overlay transform.
|
|
9295
|
+
this._overlayTransformDirty = true;
|
|
7179
9296
|
// If the maxX or maxY are 0, then set them to the canvas width and height
|
|
7180
9297
|
if (!layout.maxX || !layout.maxY) {
|
|
7181
9298
|
this.resizeToCanvas();
|
|
@@ -7198,6 +9315,8 @@ var Rive = /** @class */ (function () {
|
|
|
7198
9315
|
maxX: this.canvas.width,
|
|
7199
9316
|
maxY: this.canvas.height,
|
|
7200
9317
|
});
|
|
9318
|
+
// Layout bounds feed the overlay transform.
|
|
9319
|
+
this._overlayTransformDirty = true;
|
|
7201
9320
|
};
|
|
7202
9321
|
/**
|
|
7203
9322
|
* Accounts for devicePixelRatio as a multiplier to render the size of the canvas drawing surface.
|
|
@@ -7219,12 +9338,12 @@ var Rive = /** @class */ (function () {
|
|
|
7219
9338
|
this.canvas.height = dpr * height;
|
|
7220
9339
|
this._needsRedraw = true;
|
|
7221
9340
|
this.resizeToCanvas();
|
|
7222
|
-
this.drawFrame();
|
|
7223
9341
|
if (this.layout.fit === Fit.Layout) {
|
|
7224
9342
|
var scaleFactor = this._layout.layoutScaleFactor;
|
|
7225
9343
|
this.artboard.width = width / scaleFactor;
|
|
7226
9344
|
this.artboard.height = height / scaleFactor;
|
|
7227
9345
|
}
|
|
9346
|
+
this.drawFrame();
|
|
7228
9347
|
}
|
|
7229
9348
|
};
|
|
7230
9349
|
Object.defineProperty(Rive.prototype, "source", {
|
|
@@ -7245,6 +9364,30 @@ var Rive = /** @class */ (function () {
|
|
|
7245
9364
|
enumerable: false,
|
|
7246
9365
|
configurable: true
|
|
7247
9366
|
});
|
|
9367
|
+
Object.defineProperty(Rive.prototype, "semanticTree", {
|
|
9368
|
+
/**
|
|
9369
|
+
* Returns the semantic tree model when semantics are enabled, or null.
|
|
9370
|
+
* The overlay and external consumers use this to inspect the
|
|
9371
|
+
* current state of the semantic tree.
|
|
9372
|
+
*/
|
|
9373
|
+
get: function () {
|
|
9374
|
+
return this._semanticTree;
|
|
9375
|
+
},
|
|
9376
|
+
enumerable: false,
|
|
9377
|
+
configurable: true
|
|
9378
|
+
});
|
|
9379
|
+
Object.defineProperty(Rive.prototype, "accessibilityOverlay", {
|
|
9380
|
+
/**
|
|
9381
|
+
* Returns the accessibility overlay when semantics are enabled, or null.
|
|
9382
|
+
* External consumers can use this to inspect the
|
|
9383
|
+
* current state of the accessibility overlay for this instance.
|
|
9384
|
+
*/
|
|
9385
|
+
get: function () {
|
|
9386
|
+
return this._accessibilityOverlay;
|
|
9387
|
+
},
|
|
9388
|
+
enumerable: false,
|
|
9389
|
+
configurable: true
|
|
9390
|
+
});
|
|
7248
9391
|
Object.defineProperty(Rive.prototype, "animationNames", {
|
|
7249
9392
|
// Returns a list of animation names on the chosen artboard
|
|
7250
9393
|
get: function () {
|
|
@@ -7685,7 +9828,7 @@ var Rive = /** @class */ (function () {
|
|
|
7685
9828
|
}
|
|
7686
9829
|
for (var k = 0; k < artboard.stateMachineCount(); k++) {
|
|
7687
9830
|
var stateMachine = artboard.stateMachineByIndex(k);
|
|
7688
|
-
var
|
|
9831
|
+
var name_2 = stateMachine.name;
|
|
7689
9832
|
var instance = new this.runtime.StateMachineInstance(stateMachine, artboard);
|
|
7690
9833
|
var inputContents = [];
|
|
7691
9834
|
for (var l = 0; l < instance.inputCount(); l++) {
|
|
@@ -7693,7 +9836,7 @@ var Rive = /** @class */ (function () {
|
|
|
7693
9836
|
inputContents.push({ name: input.name, type: input.type });
|
|
7694
9837
|
}
|
|
7695
9838
|
artboardContents.stateMachines.push({
|
|
7696
|
-
name:
|
|
9839
|
+
name: name_2,
|
|
7697
9840
|
inputs: inputContents,
|
|
7698
9841
|
});
|
|
7699
9842
|
}
|
|
@@ -7803,30 +9946,67 @@ var Rive = /** @class */ (function () {
|
|
|
7803
9946
|
return this._devicePixelRatioUsed;
|
|
7804
9947
|
},
|
|
7805
9948
|
set: function (value) {
|
|
9949
|
+
if (value !== this._devicePixelRatioUsed) {
|
|
9950
|
+
this._overlayTransformDirty = true;
|
|
9951
|
+
}
|
|
7806
9952
|
this._devicePixelRatioUsed = value;
|
|
7807
9953
|
},
|
|
7808
9954
|
enumerable: false,
|
|
7809
9955
|
configurable: true
|
|
7810
9956
|
});
|
|
7811
9957
|
/**
|
|
7812
|
-
*
|
|
9958
|
+
* Sets the main view model instance and applies it (rebinds). Equivalent to
|
|
9959
|
+
* `setViewModelInstance(vmi)` followed by `bind()`.
|
|
7813
9960
|
*/
|
|
7814
9961
|
Rive.prototype.bindViewModelInstance = function (viewModelInstance) {
|
|
9962
|
+
if (!viewModelInstance) {
|
|
9963
|
+
return;
|
|
9964
|
+
}
|
|
9965
|
+
this.setViewModelInstance(viewModelInstance);
|
|
9966
|
+
this.bind();
|
|
9967
|
+
};
|
|
9968
|
+
/**
|
|
9969
|
+
* Sets the main view model instance in the data context WITHOUT rebinding.
|
|
9970
|
+
* Call {@link bind} to apply. Use this with {@link setGlobalViewModelInstance}
|
|
9971
|
+
* to batch multiple changes into a single rebind.
|
|
9972
|
+
*/
|
|
9973
|
+
Rive.prototype.setViewModelInstance = function (viewModelInstance) {
|
|
7815
9974
|
var _a;
|
|
7816
|
-
|
|
7817
|
-
|
|
7818
|
-
|
|
7819
|
-
|
|
7820
|
-
|
|
7821
|
-
|
|
7822
|
-
|
|
7823
|
-
|
|
7824
|
-
|
|
7825
|
-
|
|
7826
|
-
|
|
7827
|
-
|
|
7828
|
-
|
|
7829
|
-
}
|
|
9975
|
+
var runtimeInstance = viewModelInstance === null || viewModelInstance === void 0 ? void 0 : viewModelInstance.runtimeInstance;
|
|
9976
|
+
if (!this.artboard ||
|
|
9977
|
+
this.destroyed ||
|
|
9978
|
+
!viewModelInstance ||
|
|
9979
|
+
!runtimeInstance) {
|
|
9980
|
+
return;
|
|
9981
|
+
}
|
|
9982
|
+
viewModelInstance.internalIncrementReferenceCount();
|
|
9983
|
+
(_a = this._viewModelInstance) === null || _a === void 0 ? void 0 : _a.cleanup();
|
|
9984
|
+
this._viewModelInstance = viewModelInstance;
|
|
9985
|
+
if (this.animator.stateMachines.length > 0) {
|
|
9986
|
+
this.animator.stateMachines.forEach(function (stateMachine) {
|
|
9987
|
+
return stateMachine.instance.setViewModelInstance(runtimeInstance);
|
|
9988
|
+
});
|
|
9989
|
+
}
|
|
9990
|
+
else {
|
|
9991
|
+
this.artboard.setViewModelInstance(runtimeInstance);
|
|
9992
|
+
}
|
|
9993
|
+
};
|
|
9994
|
+
/**
|
|
9995
|
+
* Applies any pending `set*` view model instance changes by rebinding the
|
|
9996
|
+
* data binds once.
|
|
9997
|
+
* Implicitly creates and binds any view models that have not been set.
|
|
9998
|
+
*/
|
|
9999
|
+
Rive.prototype.bind = function () {
|
|
10000
|
+
if (!this.artboard || this.destroyed) {
|
|
10001
|
+
return;
|
|
10002
|
+
}
|
|
10003
|
+
if (this.animator.stateMachines.length > 0) {
|
|
10004
|
+
this.animator.stateMachines.forEach(function (stateMachine) {
|
|
10005
|
+
return stateMachine.instance.bind();
|
|
10006
|
+
});
|
|
10007
|
+
}
|
|
10008
|
+
else {
|
|
10009
|
+
this.artboard.bind();
|
|
7830
10010
|
}
|
|
7831
10011
|
};
|
|
7832
10012
|
Object.defineProperty(Rive.prototype, "viewModelInstance", {
|
|
@@ -7836,6 +10016,78 @@ var Rive = /** @class */ (function () {
|
|
|
7836
10016
|
enumerable: false,
|
|
7837
10017
|
configurable: true
|
|
7838
10018
|
});
|
|
10019
|
+
/**
|
|
10020
|
+
* Sets (or replaces) the global view model instance for the given global view
|
|
10021
|
+
* model name in the data context WITHOUT rebinding. The main instance and any
|
|
10022
|
+
* other globals keep their order. Call {@link bind} to apply — batch several
|
|
10023
|
+
* `set*` calls then a single `bind()` to avoid rebinding per set.
|
|
10024
|
+
* @param name - the name of the global view model
|
|
10025
|
+
* @param viewModelInstance - the instance to set for that global
|
|
10026
|
+
* @returns whether the instance was set (false if `name` does not match a
|
|
10027
|
+
* global view model in the file)
|
|
10028
|
+
*/
|
|
10029
|
+
Rive.prototype.setGlobalViewModelInstance = function (name, viewModelInstance) {
|
|
10030
|
+
var _a;
|
|
10031
|
+
var runtimeInstance = viewModelInstance === null || viewModelInstance === void 0 ? void 0 : viewModelInstance.runtimeInstance;
|
|
10032
|
+
if (!this.artboard || this.destroyed || !runtimeInstance) {
|
|
10033
|
+
return false;
|
|
10034
|
+
}
|
|
10035
|
+
var bound = false;
|
|
10036
|
+
if (this.animator.stateMachines.length > 0) {
|
|
10037
|
+
this.animator.stateMachines.forEach(function (stateMachine) {
|
|
10038
|
+
if (stateMachine.instance.setGlobalViewModelInstance(name, runtimeInstance)) {
|
|
10039
|
+
bound = true;
|
|
10040
|
+
}
|
|
10041
|
+
});
|
|
10042
|
+
}
|
|
10043
|
+
else {
|
|
10044
|
+
bound = this.artboard.setGlobalViewModelInstance(name, runtimeInstance);
|
|
10045
|
+
}
|
|
10046
|
+
if (bound) {
|
|
10047
|
+
viewModelInstance.internalIncrementReferenceCount();
|
|
10048
|
+
(_a = this._globalViewModelInstances.get(name)) === null || _a === void 0 ? void 0 : _a.cleanup();
|
|
10049
|
+
this._globalViewModelInstances.set(name, viewModelInstance);
|
|
10050
|
+
}
|
|
10051
|
+
return bound;
|
|
10052
|
+
};
|
|
10053
|
+
/**
|
|
10054
|
+
* @param name - the name of the global view model
|
|
10055
|
+
* @returns the global view model instance bound under the given name — the
|
|
10056
|
+
* instance set via {@link setGlobalViewModelInstance} or one created by
|
|
10057
|
+
* auto-bind — or null if none has been set/created for that name (globals are
|
|
10058
|
+
* not auto-created; the getter never creates one).
|
|
10059
|
+
*/
|
|
10060
|
+
Rive.prototype.globalViewModelInstance = function (name) {
|
|
10061
|
+
var cached = this._globalViewModelInstances.get(name);
|
|
10062
|
+
if (cached) {
|
|
10063
|
+
return cached;
|
|
10064
|
+
}
|
|
10065
|
+
if (!this.artboard || this.destroyed) {
|
|
10066
|
+
return null;
|
|
10067
|
+
}
|
|
10068
|
+
// State machines share the artboard's data context; query the first one
|
|
10069
|
+
// when present (mirroring how the setter routes), otherwise the artboard.
|
|
10070
|
+
// This is a pure read — it returns null unless an instance was set/bound.
|
|
10071
|
+
var runtimeInstance = this.animator.stateMachines.length > 0
|
|
10072
|
+
? this.animator.stateMachines[0].instance.globalViewModelInstance(name)
|
|
10073
|
+
: this.artboard.globalViewModelInstance(name);
|
|
10074
|
+
if (runtimeInstance === null) {
|
|
10075
|
+
return null;
|
|
10076
|
+
}
|
|
10077
|
+
var viewModelInstance = new ViewModelInstance(runtimeInstance, null);
|
|
10078
|
+
(0,_utils__WEBPACK_IMPORTED_MODULE_3__.createFinalization)(viewModelInstance, runtimeInstance);
|
|
10079
|
+
viewModelInstance.internalIncrementReferenceCount();
|
|
10080
|
+
this._globalViewModelInstances.set(name, viewModelInstance);
|
|
10081
|
+
return viewModelInstance;
|
|
10082
|
+
};
|
|
10083
|
+
/**
|
|
10084
|
+
* @returns the names of the file's global view models, in file order. Use
|
|
10085
|
+
* these with {@link setGlobalViewModelInstance} / {@link globalViewModelInstance}.
|
|
10086
|
+
*/
|
|
10087
|
+
Rive.prototype.globalViewModelNames = function () {
|
|
10088
|
+
var _a, _b;
|
|
10089
|
+
return (_b = (_a = this.file) === null || _a === void 0 ? void 0 : _a.globalViewModelNames()) !== null && _b !== void 0 ? _b : [];
|
|
10090
|
+
};
|
|
7839
10091
|
Rive.prototype.viewModelByIndex = function (index) {
|
|
7840
10092
|
var viewModel = this.file.viewModelByIndex(index);
|
|
7841
10093
|
if (viewModel !== null) {
|
|
@@ -7936,7 +10188,7 @@ var ViewModel = /** @class */ (function () {
|
|
|
7936
10188
|
var instance = this._viewModel.instanceByIndex(index);
|
|
7937
10189
|
if (instance !== null) {
|
|
7938
10190
|
var viewModelInstance = new ViewModelInstance(instance, null);
|
|
7939
|
-
(0,
|
|
10191
|
+
(0,_utils__WEBPACK_IMPORTED_MODULE_3__.createFinalization)(viewModelInstance, instance);
|
|
7940
10192
|
return viewModelInstance;
|
|
7941
10193
|
}
|
|
7942
10194
|
return null;
|
|
@@ -7945,7 +10197,7 @@ var ViewModel = /** @class */ (function () {
|
|
|
7945
10197
|
var instance = this._viewModel.instanceByName(name);
|
|
7946
10198
|
if (instance !== null) {
|
|
7947
10199
|
var viewModelInstance = new ViewModelInstance(instance, null);
|
|
7948
|
-
(0,
|
|
10200
|
+
(0,_utils__WEBPACK_IMPORTED_MODULE_3__.createFinalization)(viewModelInstance, instance);
|
|
7949
10201
|
return viewModelInstance;
|
|
7950
10202
|
}
|
|
7951
10203
|
return null;
|
|
@@ -7954,7 +10206,7 @@ var ViewModel = /** @class */ (function () {
|
|
|
7954
10206
|
var runtimeInstance = this._viewModel.defaultInstance();
|
|
7955
10207
|
if (runtimeInstance !== null) {
|
|
7956
10208
|
var viewModelInstance = new ViewModelInstance(runtimeInstance, null);
|
|
7957
|
-
(0,
|
|
10209
|
+
(0,_utils__WEBPACK_IMPORTED_MODULE_3__.createFinalization)(viewModelInstance, runtimeInstance);
|
|
7958
10210
|
return viewModelInstance;
|
|
7959
10211
|
}
|
|
7960
10212
|
return null;
|
|
@@ -7963,7 +10215,7 @@ var ViewModel = /** @class */ (function () {
|
|
|
7963
10215
|
var runtimeInstance = this._viewModel.instance();
|
|
7964
10216
|
if (runtimeInstance !== null) {
|
|
7965
10217
|
var viewModelInstance = new ViewModelInstance(runtimeInstance, null);
|
|
7966
|
-
(0,
|
|
10218
|
+
(0,_utils__WEBPACK_IMPORTED_MODULE_3__.createFinalization)(viewModelInstance, runtimeInstance);
|
|
7967
10219
|
return viewModelInstance;
|
|
7968
10220
|
}
|
|
7969
10221
|
return null;
|
|
@@ -8016,6 +10268,7 @@ var PropertyType;
|
|
|
8016
10268
|
PropertyType["Enum"] = "enum";
|
|
8017
10269
|
PropertyType["List"] = "list";
|
|
8018
10270
|
PropertyType["Image"] = "image";
|
|
10271
|
+
PropertyType["Font"] = "font";
|
|
8019
10272
|
PropertyType["Artboard"] = "artboard";
|
|
8020
10273
|
})(PropertyType || (PropertyType = {}));
|
|
8021
10274
|
var ViewModelInstance = /** @class */ (function () {
|
|
@@ -8151,7 +10404,7 @@ var ViewModelInstance = /** @class */ (function () {
|
|
|
8151
10404
|
return null;
|
|
8152
10405
|
};
|
|
8153
10406
|
ViewModelInstance.prototype.propertyFromPathSegments = function (pathSegments, index, type) {
|
|
8154
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
|
|
10407
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
8155
10408
|
if (index < pathSegments.length - 1) {
|
|
8156
10409
|
var viewModelInstance = this.internalViewModelInstance(pathSegments[index]);
|
|
8157
10410
|
if (viewModelInstance !== null) {
|
|
@@ -8211,8 +10464,14 @@ var ViewModelInstance = /** @class */ (function () {
|
|
|
8211
10464
|
return new ViewModelInstanceAssetImage(instance, this);
|
|
8212
10465
|
}
|
|
8213
10466
|
break;
|
|
10467
|
+
case PropertyType.Font:
|
|
10468
|
+
instance = (_t = (_s = this._runtimeInstance) === null || _s === void 0 ? void 0 : _s.font(pathSegments[index])) !== null && _t !== void 0 ? _t : null;
|
|
10469
|
+
if (instance !== null) {
|
|
10470
|
+
return new ViewModelInstanceAssetFont(instance, this);
|
|
10471
|
+
}
|
|
10472
|
+
break;
|
|
8214
10473
|
case PropertyType.Artboard:
|
|
8215
|
-
instance = (
|
|
10474
|
+
instance = (_v = (_u = this._runtimeInstance) === null || _u === void 0 ? void 0 : _u.artboard(pathSegments[index])) !== null && _v !== void 0 ? _v : null;
|
|
8216
10475
|
if (instance !== null) {
|
|
8217
10476
|
return new ViewModelInstanceArtboard(instance, this);
|
|
8218
10477
|
}
|
|
@@ -8228,7 +10487,7 @@ var ViewModelInstance = /** @class */ (function () {
|
|
|
8228
10487
|
var viewModelRuntimeInstance = (_a = this._runtimeInstance) === null || _a === void 0 ? void 0 : _a.viewModel(name);
|
|
8229
10488
|
if (viewModelRuntimeInstance !== null) {
|
|
8230
10489
|
var viewModelInstance = new ViewModelInstance(viewModelRuntimeInstance, this);
|
|
8231
|
-
(0,
|
|
10490
|
+
(0,_utils__WEBPACK_IMPORTED_MODULE_3__.createFinalization)(viewModelInstance, viewModelRuntimeInstance);
|
|
8232
10491
|
viewModelInstance.internalIncrementReferenceCount();
|
|
8233
10492
|
this._viewModelInstances.set(name, viewModelInstance);
|
|
8234
10493
|
return viewModelInstance;
|
|
@@ -8307,6 +10566,15 @@ var ViewModelInstance = /** @class */ (function () {
|
|
|
8307
10566
|
var viewmodelInstanceValue = this.propertyFromPath(path, PropertyType.Image);
|
|
8308
10567
|
return viewmodelInstanceValue;
|
|
8309
10568
|
};
|
|
10569
|
+
/**
|
|
10570
|
+
* method to access a view model property instance belonging
|
|
10571
|
+
* to the view model instance or to a nested view model instance
|
|
10572
|
+
* @param path - path to the font property
|
|
10573
|
+
*/
|
|
10574
|
+
ViewModelInstance.prototype.font = function (path) {
|
|
10575
|
+
var viewmodelInstanceValue = this.propertyFromPath(path, PropertyType.Font);
|
|
10576
|
+
return viewmodelInstanceValue;
|
|
10577
|
+
};
|
|
8310
10578
|
/**
|
|
8311
10579
|
* method to access an artboard property instance belonging
|
|
8312
10580
|
* to the view model instance or to a nested view model instance
|
|
@@ -8645,7 +10913,7 @@ var ViewModelInstanceList = /** @class */ (function (_super) {
|
|
|
8645
10913
|
var runtimeInstance = this._viewModelInstanceValue.instanceAt(index);
|
|
8646
10914
|
if (runtimeInstance != null) {
|
|
8647
10915
|
var viewModelInstance = new ViewModelInstance(runtimeInstance, this._parentViewModel);
|
|
8648
|
-
(0,
|
|
10916
|
+
(0,_utils__WEBPACK_IMPORTED_MODULE_3__.createFinalization)(viewModelInstance, runtimeInstance);
|
|
8649
10917
|
return viewModelInstance;
|
|
8650
10918
|
}
|
|
8651
10919
|
return null;
|
|
@@ -8716,6 +10984,25 @@ var ViewModelInstanceAssetImage = /** @class */ (function (_super) {
|
|
|
8716
10984
|
return ViewModelInstanceAssetImage;
|
|
8717
10985
|
}(ViewModelInstanceValue));
|
|
8718
10986
|
|
|
10987
|
+
var ViewModelInstanceAssetFont = /** @class */ (function (_super) {
|
|
10988
|
+
__extends(ViewModelInstanceAssetFont, _super);
|
|
10989
|
+
function ViewModelInstanceAssetFont(instance, root) {
|
|
10990
|
+
return _super.call(this, instance, root) || this;
|
|
10991
|
+
}
|
|
10992
|
+
Object.defineProperty(ViewModelInstanceAssetFont.prototype, "value", {
|
|
10993
|
+
set: function (font) {
|
|
10994
|
+
var _a;
|
|
10995
|
+
this._viewModelInstanceValue.value((_a = font === null || font === void 0 ? void 0 : font.nativeFont) !== null && _a !== void 0 ? _a : null);
|
|
10996
|
+
},
|
|
10997
|
+
enumerable: false,
|
|
10998
|
+
configurable: true
|
|
10999
|
+
});
|
|
11000
|
+
ViewModelInstanceAssetFont.prototype.internalHandleCallback = function (callback) {
|
|
11001
|
+
callback();
|
|
11002
|
+
};
|
|
11003
|
+
return ViewModelInstanceAssetFont;
|
|
11004
|
+
}(ViewModelInstanceValue));
|
|
11005
|
+
|
|
8719
11006
|
var ViewModelInstanceArtboard = /** @class */ (function (_super) {
|
|
8720
11007
|
__extends(ViewModelInstanceArtboard, _super);
|
|
8721
11008
|
function ViewModelInstanceArtboard(instance, root) {
|
|
@@ -8808,8 +11095,8 @@ var decodeAudio = function (bytes) { return __awaiter(void 0, void 0, void 0, fu
|
|
|
8808
11095
|
return [4 /*yield*/, decodedPromise];
|
|
8809
11096
|
case 1:
|
|
8810
11097
|
audio = _a.sent();
|
|
8811
|
-
audioWrapper = new
|
|
8812
|
-
|
|
11098
|
+
audioWrapper = new _utils__WEBPACK_IMPORTED_MODULE_3__.AudioWrapper(audio);
|
|
11099
|
+
_utils__WEBPACK_IMPORTED_MODULE_3__.finalizationRegistry.register(audioWrapper, audio);
|
|
8813
11100
|
return [2 /*return*/, audioWrapper];
|
|
8814
11101
|
}
|
|
8815
11102
|
});
|
|
@@ -8833,8 +11120,8 @@ var decodeImage = function (bytes) { return __awaiter(void 0, void 0, void 0, fu
|
|
|
8833
11120
|
return [4 /*yield*/, decodedPromise];
|
|
8834
11121
|
case 1:
|
|
8835
11122
|
image = _a.sent();
|
|
8836
|
-
imageWrapper = new
|
|
8837
|
-
|
|
11123
|
+
imageWrapper = new _utils__WEBPACK_IMPORTED_MODULE_3__.ImageWrapper(image);
|
|
11124
|
+
_utils__WEBPACK_IMPORTED_MODULE_3__.finalizationRegistry.register(imageWrapper, image);
|
|
8838
11125
|
return [2 /*return*/, imageWrapper];
|
|
8839
11126
|
}
|
|
8840
11127
|
});
|
|
@@ -8858,8 +11145,8 @@ var decodeFont = function (bytes) { return __awaiter(void 0, void 0, void 0, fun
|
|
|
8858
11145
|
return [4 /*yield*/, decodedPromise];
|
|
8859
11146
|
case 1:
|
|
8860
11147
|
font = _a.sent();
|
|
8861
|
-
fontWrapper = new
|
|
8862
|
-
|
|
11148
|
+
fontWrapper = new _utils__WEBPACK_IMPORTED_MODULE_3__.FontWrapper(font);
|
|
11149
|
+
_utils__WEBPACK_IMPORTED_MODULE_3__.finalizationRegistry.register(fontWrapper, font);
|
|
8863
11150
|
return [2 /*return*/, fontWrapper];
|
|
8864
11151
|
}
|
|
8865
11152
|
});
|