@rive-app/webgl2 2.43.0 → 2.44.0

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/rive.js CHANGED
@@ -431,14 +431,14 @@ return}switch(c){case 1:c=d;E[b>>2]=c;E[b+4>>2]=(c-E[b>>2])/4294967296;break;cas
431
431
  !1;return c},["delete"](){this.g.m||dc(this);if(this.g.ka&&!this.g.ia)throw new O("Object already scheduled for deletion");Ub(this);var c=this.g;--c.count.value;0===c.count.value&&(c.D?c.K.R(c.D):c.u.h.R(c.m));this.g.ia||(this.g.D=void 0,this.g.m=void 0)},isDeleted:function(){return!this.g.m},deleteLater:function(){this.g.m||dc(this);if(this.g.ka&&!this.g.ia)throw new O("Object already scheduled for deletion");ec.push(this);this.g.ka=!0;return this}});const b=Symbol.dispose;b&&(a[b]=a["delete"])})();
432
432
  Object.assign(tc.prototype,{Mb(a){this.lb&&(a=this.lb(a));return a},Ya(a){this.R?.(a)},J:Zb,o:function(a){function b(){return this.wa?sc(this.h.N,{u:this.$b,m:c,K:this,D:a}):sc(this.h.N,{u:this,m:a})}var c=this.Mb(a);if(!c)return this.Ya(a),null;var d=rc(this.h,c);if(void 0!==d){if(0===d.g.count.value)return d.g.m=c,d.g.D=a,d.clone();d=d.clone();this.Ya(a);return d}d=this.h.Lb(c);d=gc[d];if(!d)return b.call(this);d=this.va?d.Cb:d.pointerType;var e=qc(c,this.h,d.h);return null===e?b.call(this):this.wa?
433
433
  sc(d.h.N,{u:d,m:e,K:this,D:a}):sc(d.h.N,{u:d,m:e})}});for(let a=0;32>a;++a)sd.push(Array(a));l.print&&(oa=l.print);l.printErr&&(w=l.printErr);l.wasmBinary&&(pa=l.wasmBinary);l.thisProgram&&(ja=l.thisProgram);if(l.preInit)for("function"==typeof l.preInit&&(l.preInit=[l.preInit]);0<l.preInit.length;)l.preInit.shift()();
434
- var Cd={362437:(a,b,c,d,e)=>{if("undefined"===typeof window||void 0===(window.AudioContext||window.webkitAudioContext))return 0;if("undefined"===typeof window.miniaudio){window.miniaudio={referenceCount:0};window.miniaudio.device_type={};window.miniaudio.device_type.playback=a;window.miniaudio.device_type.capture=b;window.miniaudio.device_type.duplex=c;window.miniaudio.device_state={};window.miniaudio.device_state.stopped=d;window.miniaudio.device_state.started=e;let f=window.miniaudio;f.devices=
434
+ var Cd={369781:(a,b,c,d,e)=>{if("undefined"===typeof window||void 0===(window.AudioContext||window.webkitAudioContext))return 0;if("undefined"===typeof window.miniaudio){window.miniaudio={referenceCount:0};window.miniaudio.device_type={};window.miniaudio.device_type.playback=a;window.miniaudio.device_type.capture=b;window.miniaudio.device_type.duplex=c;window.miniaudio.device_state={};window.miniaudio.device_state.stopped=d;window.miniaudio.device_state.started=e;let f=window.miniaudio;f.devices=
435
435
  [];f.track_device=function(g){for(var h=0;h<f.devices.length;++h)if(null==f.devices[h])return f.devices[h]=g,h;f.devices.push(g);return f.devices.length-1};f.untrack_device_by_index=function(g){for(f.devices[g]=null;0<f.devices.length;)if(null==f.devices[f.devices.length-1])f.devices.pop();else break};f.untrack_device=function(g){for(var h=0;h<f.devices.length;++h)if(f.devices[h]==g)return f.untrack_device_by_index(h)};f.get_device_by_index=function(g){return f.devices[g]};f.unlock_event_types=["touchend",
436
- "click"];f.unlock=function(){for(var g=0;g<f.devices.length;++g){var h=f.devices[g];null!=h&&null!=h.L&&h.state===f.device_state.started&&h.L.resume().then(()=>{zd(h.ib)},k=>{console.error("Failed to resume audiocontext",k)})}f.unlock_event_types.map(function(k){document.removeEventListener(k,f.unlock,!0)})};f.unlock_event_types.map(function(g){document.addEventListener(g,f.unlock,!0)})}window.miniaudio.referenceCount+=1;return 1},364615:()=>{"undefined"!==typeof window.miniaudio&&(window.miniaudio.unlock_event_types.map(function(a){document.removeEventListener(a,
437
- window.miniaudio.unlock,!0)}),--window.miniaudio.referenceCount,0===window.miniaudio.referenceCount&&delete window.miniaudio)},364919:()=>void 0!==navigator.mediaDevices&&void 0!==navigator.mediaDevices.getUserMedia,365023:()=>{try{var a=new (window.AudioContext||window.webkitAudioContext),b=a.sampleRate;a.close();return b}catch(c){return 0}},365194:(a,b,c,d,e,f)=>{if("undefined"===typeof window.miniaudio)return-1;var g={},h={};a==window.miniaudio.device_type.playback&&0!=c&&(h.sampleRate=c);g.L=
436
+ "click"];f.unlock=function(){for(var g=0;g<f.devices.length;++g){var h=f.devices[g];null!=h&&null!=h.L&&h.state===f.device_state.started&&h.L.resume().then(()=>{zd(h.ib)},k=>{console.error("Failed to resume audiocontext",k)})}f.unlock_event_types.map(function(k){document.removeEventListener(k,f.unlock,!0)})};f.unlock_event_types.map(function(g){document.addEventListener(g,f.unlock,!0)})}window.miniaudio.referenceCount+=1;return 1},371959:()=>{"undefined"!==typeof window.miniaudio&&(window.miniaudio.unlock_event_types.map(function(a){document.removeEventListener(a,
437
+ window.miniaudio.unlock,!0)}),--window.miniaudio.referenceCount,0===window.miniaudio.referenceCount&&delete window.miniaudio)},372263:()=>void 0!==navigator.mediaDevices&&void 0!==navigator.mediaDevices.getUserMedia,372367:()=>{try{var a=new (window.AudioContext||window.webkitAudioContext),b=a.sampleRate;a.close();return b}catch(c){return 0}},372538:(a,b,c,d,e,f)=>{if("undefined"===typeof window.miniaudio)return-1;var g={},h={};a==window.miniaudio.device_type.playback&&0!=c&&(h.sampleRate=c);g.L=
438
438
  new (window.AudioContext||window.webkitAudioContext)(h);g.L.suspend();g.state=window.miniaudio.device_state.stopped;c=0;a!=window.miniaudio.device_type.playback&&(c=b);g.aa=g.L.createScriptProcessor(d,c,b);g.aa.onaudioprocess=function(k){if(null==g.ua||0==g.ua.length)g.ua=new Float32Array(va.buffer,e,d*b);if(a==window.miniaudio.device_type.capture||a==window.miniaudio.device_type.duplex){for(var n=0;n<b;n+=1)for(var p=k.inputBuffer.getChannelData(n),u=g.ua,t=0;t<d;t+=1)u[t*b+n]=p[t];Ad(f,d,e)}if(a==
439
439
  window.miniaudio.device_type.playback||a==window.miniaudio.device_type.duplex)for(Bd(f,d,e),n=0;n<k.outputBuffer.numberOfChannels;++n)for(p=k.outputBuffer.getChannelData(n),u=g.ua,t=0;t<d;t+=1)p[t]=u[t*b+n];else for(n=0;n<k.outputBuffer.numberOfChannels;++n)k.outputBuffer.getChannelData(n).fill(0)};a!=window.miniaudio.device_type.capture&&a!=window.miniaudio.device_type.duplex||navigator.mediaDevices.getUserMedia({audio:!0,video:!1}).then(function(k){g.Ea=g.L.createMediaStreamSource(k);g.Ea.connect(g.aa);
440
- g.aa.connect(g.L.destination)}).catch(function(k){console.log("Failed to get user media: "+k)});a==window.miniaudio.device_type.playback&&g.aa.connect(g.L.destination);g.ib=f;return window.miniaudio.track_device(g)},368071:a=>window.miniaudio.get_device_by_index(a).L.sampleRate,368144:a=>{a=window.miniaudio.get_device_by_index(a);void 0!==a.aa&&(a.aa.onaudioprocess=function(){},a.aa.disconnect(),a.aa=void 0);void 0!==a.Ea&&(a.Ea.disconnect(),a.Ea=void 0);a.L.close();a.L=void 0;a.ib=void 0},368544:a=>
441
- {window.miniaudio.untrack_device_by_index(a)},368594:a=>{a=window.miniaudio.get_device_by_index(a);a.L.resume();a.state=window.miniaudio.device_state.started},368733:a=>{a=window.miniaudio.get_device_by_index(a);a.L.suspend();a.state=window.miniaudio.device_state.stopped}},Rb,vd,Qb,zd,Ad,Bd,Dd,Ed,Fd,za,vc,Hd={__syscall_fcntl64:function(a,b,c){Ka=c;try{var d=vb(a);switch(b){case 0:var e=La();if(0>e)break;for(;kb[e];)e++;return xb(d,e).Z;case 1:case 2:return 0;case 3:return d.flags;case 4:return e=
440
+ g.aa.connect(g.L.destination)}).catch(function(k){console.log("Failed to get user media: "+k)});a==window.miniaudio.device_type.playback&&g.aa.connect(g.L.destination);g.ib=f;return window.miniaudio.track_device(g)},375415:a=>window.miniaudio.get_device_by_index(a).L.sampleRate,375488:a=>{a=window.miniaudio.get_device_by_index(a);void 0!==a.aa&&(a.aa.onaudioprocess=function(){},a.aa.disconnect(),a.aa=void 0);void 0!==a.Ea&&(a.Ea.disconnect(),a.Ea=void 0);a.L.close();a.L=void 0;a.ib=void 0},375888:a=>
441
+ {window.miniaudio.untrack_device_by_index(a)},375938:a=>{a=window.miniaudio.get_device_by_index(a);a.L.resume();a.state=window.miniaudio.device_state.started},376077:a=>{a=window.miniaudio.get_device_by_index(a);a.L.suspend();a.state=window.miniaudio.device_state.stopped}},Rb,vd,Qb,zd,Ad,Bd,Dd,Ed,Fd,za,vc,Hd={__syscall_fcntl64:function(a,b,c){Ka=c;try{var d=vb(a);switch(b){case 0:var e=La();if(0>e)break;for(;kb[e];)e++;return xb(d,e).Z;case 1:case 2:return 0;case 3:return d.flags;case 4:return e=
442
442
  La(),d.flags|=e,0;case 12:return e=La(),ta[e+0>>1]=2,0;case 13:case 14:return 0}return-28}catch(f){if("undefined"==typeof Hb||"ErrnoError"!==f.name)throw f;return-f.Y}},__syscall_ioctl:function(a,b,c){Ka=c;try{var d=vb(a);switch(b){case 21509:return d.s?0:-59;case 21505:if(!d.s)return-59;if(d.s.X.Tb){a=[3,28,127,21,4,0,1,0,17,19,26,0,18,15,23,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];var e=La();D[e>>2]=25856;D[e+4>>2]=5;D[e+8>>2]=191;D[e+12>>2]=35387;for(var f=0;32>f;f++)A[e+f+17]=a[f]||0}return 0;case 21510:case 21511:case 21512:return d.s?
443
443
  0:-59;case 21506:case 21507:case 21508:if(!d.s)return-59;if(d.s.X.Ub)for(e=La(),a=[],f=0;32>f;f++)a.push(A[e+f+17]);return 0;case 21519:if(!d.s)return-59;e=La();return D[e>>2]=0;case 21520:return d.s?-28:-59;case 21537:case 21531:e=La();if(!d.i.Sb)throw new M(59);return d.i.Sb(d,b,e);case 21523:if(!d.s)return-59;d.s.X.Vb&&(f=[24,80],e=La(),ta[e>>1]=f[0],ta[e+2>>1]=f[1]);return 0;case 21524:return d.s?0:-59;case 21515:return d.s?0:-59;default:return-28}}catch(g){if("undefined"==typeof Hb||"ErrnoError"!==
444
444
  g.name)throw g;return-g.Y}},__syscall_openat:function(a,b,c,d){Ka=d;try{b=b?K(B,b):"";var e=b;if("/"===e.charAt(0))b=e;else{var f=-100===a?"/":vb(a).path;if(0==e.length)throw new M(44);b=f+"/"+e}var g=d?La():0;return Eb(b,c,g).Z}catch(h){if("undefined"==typeof Hb||"ErrnoError"!==h.name)throw h;return-h.Y}},_abort_js:()=>Aa(""),_embind_create_inheriting_constructor:(a,b,c)=>{a=Q(a);b=Tb(b,"wrapper");c=P(c);var d=b.h,e=d.N,f=d.C.N,g=d.C.constructor;a=Ib(a,function(...h){for(var k of d.C.jb)if(this[k]===
@@ -505,7 +505,7 @@ Ha.push(d)}Ga(Ha)}}if(l.preRun)for("function"==typeof l.preRun&&(l.preRun=[l.pre
505
505
  /* 5 */
506
506
  /***/ ((module) => {
507
507
 
508
- module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/webgl2","version":"2.43.0","description":"Rive\'s webgl2 based web api.","main":"rive.js","homepage":"https://rive.app","repository":{"type":"git","url":"https://github.com/rive-app/rive-wasm/tree/master/js"},"keywords":["rive","animation"],"author":"Rive","contributors":["Luigi Rosso <luigi@rive.app> (https://rive.app)","Maxwell Talbot <max@rive.app> (https://rive.app)","Arthur Vivian <arthur@rive.app> (https://rive.app)","Umberto Sonnino <umberto@rive.app> (https://rive.app)","Matthew Sullivan <matt.j.sullivan@gmail.com> (mailto:matt.j.sullivan@gmail.com)","Chris Dalton <chris@rive.app> (https://rive.app)"],"license":"MIT","files":["rive.js","rive.wasm","rive_fallback.wasm","rive.js.map","rive.d.ts","rive_advanced.mjs.d.ts","runtimeLoader.d.ts","utils","semantics"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
508
+ module.exports = /*#__PURE__*/JSON.parse('{"name":"@rive-app/webgl2","version":"2.44.0","description":"Rive\'s webgl2 based web api.","main":"rive.js","homepage":"https://rive.app","repository":{"type":"git","url":"https://github.com/rive-app/rive-wasm/tree/master/js"},"keywords":["rive","animation"],"author":"Rive","contributors":["Luigi Rosso <luigi@rive.app> (https://rive.app)","Maxwell Talbot <max@rive.app> (https://rive.app)","Arthur Vivian <arthur@rive.app> (https://rive.app)","Umberto Sonnino <umberto@rive.app> (https://rive.app)","Matthew Sullivan <matt.j.sullivan@gmail.com> (mailto:matt.j.sullivan@gmail.com)","Chris Dalton <chris@rive.app> (https://rive.app)"],"license":"MIT","files":["rive.js","rive.wasm","rive_fallback.wasm","rive.js.map","rive.d.ts","rive_advanced.mjs.d.ts","runtimeLoader.d.ts","utils","semantics"],"typings":"rive.d.ts","dependencies":{},"browser":{"fs":false,"path":false}}');
509
509
 
510
510
  /***/ }),
511
511
  /* 6 */
@@ -631,6 +631,17 @@ var SemanticTreeModel = /** @class */ (function () {
631
631
  SemanticTreeModel.prototype.nodeById = function (id) {
632
632
  return this._nodesById.get(id);
633
633
  };
634
+ /** The node with SemanticState.Focused, or undefined. */
635
+ SemanticTreeModel.prototype.focusedNode = function () {
636
+ // Manual iteration: runs every frame and must stop at the first hit (the
637
+ // TS target forbids for-of over Map iterators).
638
+ var it = this._nodesById.values();
639
+ for (var r = it.next(); !r.done; r = it.next()) {
640
+ if ((0,_types__WEBPACK_IMPORTED_MODULE_0__.hasState)(r.value.stateFlags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticState.Focused))
641
+ return r.value;
642
+ }
643
+ return;
644
+ };
634
645
  /** Current index of a node among its siblings (or roots), or -1 if absent. */
635
646
  SemanticTreeModel.prototype.siblingIndexOf = function (id) {
636
647
  var node = this._nodesById.get(id);
@@ -1178,8 +1189,42 @@ __webpack_require__.r(__webpack_exports__);
1178
1189
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
1179
1190
  /* harmony export */ AccessibilityOverlay: () => (/* binding */ AccessibilityOverlay)
1180
1191
  /* harmony export */ });
1181
- /* harmony import */ var _types__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(8);
1192
+ /* harmony import */ var _claimedKeyEvents__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(10);
1193
+ /* harmony import */ var _utils_canvasOffset__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(11);
1194
+ /* harmony import */ var _types__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(8);
1182
1195
 
1196
+
1197
+
1198
+ var warnedUnpositionedWrapper = false;
1199
+ /**
1200
+ * Warns once per page when no positioned element sits at or inside the canvas's
1201
+ * nearest scroll container: the overlay then can't scroll with the canvas. Reads only.
1202
+ */
1203
+ function warnIfWrapperUnpositioned(canvas) {
1204
+ if (warnedUnpositionedWrapper)
1205
+ return;
1206
+ // Null when detached (or display:none / fixed); nothing to judge yet.
1207
+ var offsetParent = canvas.offsetParent;
1208
+ if (!offsetParent)
1209
+ return;
1210
+ var scrolls = function (v) { return v === "auto" || v === "scroll" || v === "overlay"; };
1211
+ var scroller = null;
1212
+ var el = canvas.parentElement;
1213
+ // Bounds pathological nesting.
1214
+ var MAX_ANCESTOR_WALK = 32;
1215
+ for (var i = 0; el && el !== document.documentElement && i < MAX_ANCESTOR_WALK; i++, el = el.parentElement) {
1216
+ var style = getComputedStyle(el);
1217
+ if (scrolls(style.overflowX) || scrolls(style.overflowY)) {
1218
+ scroller = el;
1219
+ break;
1220
+ }
1221
+ }
1222
+ // Only the viewport scrolls: any offsetParent scrolls with the page.
1223
+ if (!scroller || scroller.contains(offsetParent))
1224
+ return;
1225
+ warnedUnpositionedWrapper = true;
1226
+ console.warn('[Rive] Semantics: give the element wrapping the <canvas> "position: relative" (or another positioned value) so the semantic overlay scrolls with the canvas. Without it, screen readers may scroll to stale positions when the canvas is inside a scrolling container.');
1227
+ }
1183
1228
  /**
1184
1229
  * Creates and manages an invisible DOM tree overlaying a Rive canvas. This is for
1185
1230
  * screen readers to discover and interact with the Rive content.
@@ -1197,7 +1242,7 @@ __webpack_require__.r(__webpack_exports__);
1197
1242
  var AccessibilityOverlay = /** @class */ (function () {
1198
1243
  function AccessibilityOverlay(options) {
1199
1244
  var _this = this;
1200
- var _a;
1245
+ var _a, _b;
1201
1246
  this.elements = new Map();
1202
1247
  /** Visually-hidden description spans keyed by node ID, referenced by aria-describedby. */
1203
1248
  this.descElements = new Map();
@@ -1207,6 +1252,8 @@ var AccessibilityOverlay = /** @class */ (function () {
1207
1252
  this.pendingTextGeometry = [];
1208
1253
  /** Last measured box-size|text key per text element, to skip redundant re-measures. */
1209
1254
  this.textGeometryKeys = new WeakMap();
1255
+ /** Node data last passed to applyAttributes per element; see {@link setEditingHostNode}. */
1256
+ this.appliedNodes = new WeakMap();
1210
1257
  this.lastCanvasPositioning = {
1211
1258
  width: -1, height: -1, offsetTop: -1, offsetLeft: -1,
1212
1259
  };
@@ -1219,6 +1266,10 @@ var AccessibilityOverlay = /** @class */ (function () {
1219
1266
  this._geometryDirty = true;
1220
1267
  /** True while reconciling the DOM (reserved for future focus-sync guards). */
1221
1268
  this.isUpdating = false;
1269
+ /** Node whose element the editing host stands in for, or null. */
1270
+ this.editingHostNodeId = null;
1271
+ /** Semantic version last folded into the editing host's decoration. */
1272
+ this.editingHostSemanticVersion = -1;
1222
1273
  /**
1223
1274
  * Single child div of the overlay container that carries the artboard→CSS
1224
1275
  * transform. All semantic node elements are children of this div and express
@@ -1243,9 +1294,116 @@ var AccessibilityOverlay = /** @class */ (function () {
1243
1294
  this.canvas = options.canvas;
1244
1295
  this.semanticsOptions = options.semanticsOptions;
1245
1296
  this.allowFocusInterrupt = (_a = options.allowFocusInterrupt) !== null && _a !== void 0 ? _a : false;
1297
+ this.isEditingHostFocused = (_b = options.isEditingHostFocused) !== null && _b !== void 0 ? _b : (function () { return false; });
1246
1298
  this.container = this.createContainer(options.canvas);
1247
1299
  this.attachPositionObservers();
1300
+ warnIfWrapperUnpositioned(options.canvas);
1248
1301
  }
1302
+ /**
1303
+ * Hide the stood-in node's element (no duplicate textbox for AT); re-derive the previous
1304
+ * one's aria-hidden.
1305
+ */
1306
+ AccessibilityOverlay.prototype.setEditingHostNode = function (nodeId) {
1307
+ if (this.editingHostNodeId === nodeId)
1308
+ return;
1309
+ var previous = this.editingHostNodeId;
1310
+ this.editingHostNodeId = nodeId;
1311
+ if (previous !== null) {
1312
+ var previousEl = this.elements.get(previous);
1313
+ // Re-derive rather than un-hide: the node may have become Hidden mid-session.
1314
+ if (previousEl) {
1315
+ var previousNode = this.appliedNodes.get(previousEl);
1316
+ if (previousNode && this.isAriaHidden(previousNode)) {
1317
+ setAttr(previousEl, "aria-hidden", "true");
1318
+ }
1319
+ else {
1320
+ removeAttr(previousEl, "aria-hidden");
1321
+ }
1322
+ }
1323
+ }
1324
+ if (nodeId !== null) {
1325
+ var el = this.elements.get(nodeId);
1326
+ if (el)
1327
+ setAttr(el, "aria-hidden", "true");
1328
+ }
1329
+ };
1330
+ /**
1331
+ * Describe the focused text field on the host and hide its element; no-op unless
1332
+ * semantics changed.
1333
+ * @param force - apply even if semantics are unchanged (session start).
1334
+ */
1335
+ AccessibilityOverlay.prototype.syncEditingHost = function (tree, host, force) {
1336
+ var _a;
1337
+ if (!force && tree.semanticVersion === this.editingHostSemanticVersion)
1338
+ return;
1339
+ this.editingHostSemanticVersion = tree.semanticVersion;
1340
+ var node = tree.focusedNode();
1341
+ if (node === undefined || node.role !== _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.textField) {
1342
+ // Nothing to describe; drop the stale description rather than misname the host.
1343
+ if (this.editingHostNodeId !== null) {
1344
+ host.resetDecoration();
1345
+ this.setEditingHostNode(null);
1346
+ }
1347
+ return;
1348
+ }
1349
+ // Every key is passed on every call, nulls included, so nothing survives from
1350
+ // the previously described field.
1351
+ host.setSecure((0,_types__WEBPACK_IMPORTED_MODULE_2__.hasState)(node.stateFlags, _types__WEBPACK_IMPORTED_MODULE_2__.SemanticState.Obscured));
1352
+ host.decorate({
1353
+ "aria-label": node.label || null,
1354
+ "aria-readonly": (0,_types__WEBPACK_IMPORTED_MODULE_2__.hasState)(node.stateFlags, _types__WEBPACK_IMPORTED_MODULE_2__.SemanticState.ReadOnly) ? "true" : null,
1355
+ "aria-multiline": (0,_types__WEBPACK_IMPORTED_MODULE_2__.hasState)(node.stateFlags, _types__WEBPACK_IMPORTED_MODULE_2__.SemanticState.Multiline) ? "true" : null,
1356
+ // Trait-gated to match applyAttributes.
1357
+ "aria-required": (0,_types__WEBPACK_IMPORTED_MODULE_2__.hasTrait)(node.traitFlags, _types__WEBPACK_IMPORTED_MODULE_2__.SemanticTrait.Requirable) &&
1358
+ (0,_types__WEBPACK_IMPORTED_MODULE_2__.hasState)(node.stateFlags, _types__WEBPACK_IMPORTED_MODULE_2__.SemanticState.Required)
1359
+ ? "true"
1360
+ : null,
1361
+ // The hint span applyAttributes maintains (update() runs earlier in the frame).
1362
+ "aria-describedby": (node.hint && ((_a = this.descElements.get(node.id)) === null || _a === void 0 ? void 0 : _a.id)) || null,
1363
+ });
1364
+ this.setEditingHostNode(node.id);
1365
+ };
1366
+ /** True while the editing host stands in for a node's element. */
1367
+ AccessibilityOverlay.prototype.hasEditingHost = function () {
1368
+ return this.editingHostNodeId !== null;
1369
+ };
1370
+ /**
1371
+ * Undo the stand-in; if the host still has DOM focus, move it to the focused node's
1372
+ * element so AT announces it.
1373
+ */
1374
+ AccessibilityOverlay.prototype.releaseEditingHost = function (tree, host) {
1375
+ var _a;
1376
+ host === null || host === void 0 ? void 0 : host.resetDecoration();
1377
+ this.setEditingHostNode(null);
1378
+ this.editingHostSemanticVersion = -1;
1379
+ if (!(host === null || host === void 0 ? void 0 : host.hasDomFocus()))
1380
+ return;
1381
+ var focusedNodeId = (_a = tree === null || tree === void 0 ? void 0 : tree.focusedNode()) === null || _a === void 0 ? void 0 : _a.id;
1382
+ if (focusedNodeId !== undefined)
1383
+ this.focusNodeElement(focusedNodeId);
1384
+ };
1385
+ /** Move DOM focus onto a node's element. No-op for a node with no element. */
1386
+ AccessibilityOverlay.prototype.focusNodeElement = function (nodeId) {
1387
+ var el = this.elements.get(nodeId);
1388
+ if (!el)
1389
+ return;
1390
+ this.focusElementInPlace(el);
1391
+ };
1392
+ // The overlay is positioned outside the canvas's scroll chain, so a plain focus()
1393
+ // would scroll the root instead; scroll the canvas into view through its real ancestors.
1394
+ AccessibilityOverlay.prototype.focusElementInPlace = function (el) {
1395
+ var _a, _b;
1396
+ this.syncContainerBeforeFocus();
1397
+ el.focus({ preventScroll: true });
1398
+ (_b = (_a = this.canvas).scrollIntoView) === null || _b === void 0 ? void 0 : _b.call(_a, {
1399
+ block: "nearest",
1400
+ inline: "nearest",
1401
+ behavior: "instant",
1402
+ });
1403
+ // The scroll moved the canvas; re-align now rather than after the observer throttle.
1404
+ this.syncContainerGeometry();
1405
+ this.observePosition();
1406
+ };
1249
1407
  AccessibilityOverlay.prototype.getSemanticOverlayContainer = function () {
1250
1408
  return this.container;
1251
1409
  };
@@ -1323,15 +1481,16 @@ var AccessibilityOverlay = /** @class */ (function () {
1323
1481
  _this.observePosition();
1324
1482
  }, 500); // Throttle to avoid rapid style recalculations
1325
1483
  };
1484
+ /** Returns true when the container's size changed (node transforms need recomputing). */
1326
1485
  AccessibilityOverlay.prototype.syncContainerGeometry = function () {
1327
1486
  var rect = this.canvas.getBoundingClientRect();
1328
- var top = this.canvas.offsetTop;
1329
- var left = this.canvas.offsetLeft;
1330
- if (rect.width === this.lastCanvasPositioning.width &&
1331
- rect.height === this.lastCanvasPositioning.height &&
1487
+ var _a = (0,_utils_canvasOffset__WEBPACK_IMPORTED_MODULE_1__.canvasOffset)(this.canvas), top = _a.top, left = _a.left;
1488
+ var sizeChanged = rect.width !== this.lastCanvasPositioning.width ||
1489
+ rect.height !== this.lastCanvasPositioning.height;
1490
+ if (!sizeChanged &&
1332
1491
  top === this.lastCanvasPositioning.offsetTop &&
1333
1492
  left === this.lastCanvasPositioning.offsetLeft)
1334
- return;
1493
+ return false;
1335
1494
  this.container.style.top = top + "px";
1336
1495
  this.container.style.left = left + "px";
1337
1496
  this.container.style.width = rect.width + "px";
@@ -1341,6 +1500,16 @@ var AccessibilityOverlay = /** @class */ (function () {
1341
1500
  this.lastCanvasPositioning.height = rect.height;
1342
1501
  this.lastCanvasPositioning.offsetTop = top;
1343
1502
  this.lastCanvasPositioning.offsetLeft = left;
1503
+ return sizeChanged;
1504
+ };
1505
+ /**
1506
+ * Re-align the container right before focusing one of its elements. The position
1507
+ * observer re-syncs after scrolling on a throttle; focusing an element while the
1508
+ * container is stale would make the browser scroll the page to where it sits.
1509
+ */
1510
+ AccessibilityOverlay.prototype.syncContainerBeforeFocus = function () {
1511
+ if (this.syncContainerGeometry())
1512
+ this._geometryDirty = true;
1344
1513
  };
1345
1514
  AccessibilityOverlay.prototype.createContainer = function (canvas) {
1346
1515
  var _a, _b;
@@ -1350,10 +1519,13 @@ var AccessibilityOverlay = /** @class */ (function () {
1350
1519
  container.setAttribute("aria-label", (_b = (_a = this.semanticsOptions) === null || _a === void 0 ? void 0 : _a.riveCanvasLabel) !== null && _b !== void 0 ? _b : "Rive animation");
1351
1520
  // Size to the canvas's CSS layout box, not the parent container.
1352
1521
  var rect = canvas.getBoundingClientRect();
1522
+ var _c = (0,_utils_canvasOffset__WEBPACK_IMPORTED_MODULE_1__.canvasOffset)(this.canvas), top = _c.top, left = _c.left;
1353
1523
  container.style.cssText = [
1354
1524
  "position:absolute",
1355
- "top:".concat(canvas.offsetTop, "px"),
1356
- "left:".concat(canvas.offsetLeft, "px"),
1525
+ "top:".concat(top, "px"),
1526
+ "left:".concat(left, "px"),
1527
+ "line-height:normal",
1528
+ "font-size:16px",
1357
1529
  "width:".concat(rect.width, "px"),
1358
1530
  "height:".concat(rect.height, "px"),
1359
1531
  "overflow:hidden",
@@ -1530,8 +1702,8 @@ var AccessibilityOverlay = /** @class */ (function () {
1530
1702
  // The cheap trait/state flag checks gate the (per-node) DOM queries below,
1531
1703
  // so the activeElement/closest/contains walks only run for a node that is
1532
1704
  // actually focusable + focused — not for every node on every frame.
1533
- if ((0,_types__WEBPACK_IMPORTED_MODULE_0__.hasTrait)(nodeData.traitFlags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticTrait.Focusable) &&
1534
- (0,_types__WEBPACK_IMPORTED_MODULE_0__.hasState)(nodeData.stateFlags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticState.Focused)) {
1705
+ if ((0,_types__WEBPACK_IMPORTED_MODULE_2__.hasTrait)(nodeData.traitFlags, _types__WEBPACK_IMPORTED_MODULE_2__.SemanticTrait.Focusable) &&
1706
+ (0,_types__WEBPACK_IMPORTED_MODULE_2__.hasState)(nodeData.stateFlags, _types__WEBPACK_IMPORTED_MODULE_2__.SemanticState.Focused)) {
1535
1707
  var active = document.activeElement;
1536
1708
  // While focus is inside one of our modal dialogs, don't pull it back
1537
1709
  // out to a background node.
@@ -1539,8 +1711,16 @@ var AccessibilityOverlay = /** @class */ (function () {
1539
1711
  var trappedByModal = !!focusedModal &&
1540
1712
  this.container.contains(focusedModal) &&
1541
1713
  !focusedModal.contains(el);
1542
- if (active !== el && !trappedByModal && this.canMoveFocus()) {
1543
- el.focus();
1714
+ // Not while the proxy has focus (would steal the caret, drop the keyboard) nor onto
1715
+ // its aria-hidden stand-in.
1716
+ if (nodeId !== this.editingHostNodeId &&
1717
+ active !== el &&
1718
+ !trappedByModal &&
1719
+ !this.isEditingHostFocused() &&
1720
+ this.canMoveFocus()) {
1721
+ // No scrollIntoView: this runs on semantic diffs and must not drag the page.
1722
+ this.syncContainerBeforeFocus();
1723
+ el.focus({ preventScroll: true });
1544
1724
  }
1545
1725
  }
1546
1726
  // Recurse into children with this node's absolute artboard position.
@@ -1679,7 +1859,7 @@ var AccessibilityOverlay = /** @class */ (function () {
1679
1859
  var el = document.createElement(tag);
1680
1860
  el.id = "".concat(this.nodeIdPrefix).concat(node.id);
1681
1861
  el.style.cssText = BASE_NODE_STYLE;
1682
- if (node.role === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.text) {
1862
+ if (node.role === _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.text) {
1683
1863
  // The positioned outer div is the AX element
1684
1864
  // VoiceOver uses for its highlight box; an inner <span> carries the text
1685
1865
  // without position:absolute (which would strip the span from VoiceOver's
@@ -1711,7 +1891,7 @@ var AccessibilityOverlay = /** @class */ (function () {
1711
1891
  target = "last";
1712
1892
  if (!target)
1713
1893
  return;
1714
- e.preventDefault();
1894
+ (0,_claimedKeyEvents__WEBPACK_IMPORTED_MODULE_0__.claimKeyEvent)(e);
1715
1895
  var members = opts.members();
1716
1896
  var idx = members.indexOf(el);
1717
1897
  if (idx < 0)
@@ -1722,10 +1902,10 @@ var AccessibilityOverlay = /** @class */ (function () {
1722
1902
  : target === "first" ? members[0]
1723
1903
  : members[n - 1];
1724
1904
  if (next && next !== el) {
1725
- next.focus();
1905
+ _this.focusElementInPlace(next);
1726
1906
  var nextId = _this.nodeIdFromElement(next);
1727
1907
  if (nextId !== null)
1728
- _this.fireAction(nextId, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticActionType.tap);
1908
+ _this.fireAction(nextId, _types__WEBPACK_IMPORTED_MODULE_2__.SemanticActionType.tap);
1729
1909
  }
1730
1910
  });
1731
1911
  };
@@ -1735,31 +1915,31 @@ var AccessibilityOverlay = /** @class */ (function () {
1735
1915
  var nodeId = node.id;
1736
1916
  if (isClickableRole(role)) {
1737
1917
  el.addEventListener("click", function () {
1738
- _this.fireAction(nodeId, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticActionType.tap);
1918
+ _this.fireAction(nodeId, _types__WEBPACK_IMPORTED_MODULE_2__.SemanticActionType.tap);
1739
1919
  });
1740
1920
  // Links activate on Enter only (Space scrolls the page per browser
1741
1921
  // convention). All other clickable roles accept both Enter and Space.
1742
- var activationKeys_1 = role === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.link ? ["Enter"] : ["Enter", " "];
1922
+ var activationKeys_1 = role === _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.link ? ["Enter"] : ["Enter", " "];
1743
1923
  el.addEventListener("keydown", function (e) {
1744
1924
  if (activationKeys_1.includes(e.key)) {
1745
- e.preventDefault();
1746
- _this.fireAction(nodeId, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticActionType.tap);
1925
+ (0,_claimedKeyEvents__WEBPACK_IMPORTED_MODULE_0__.claimKeyEvent)(e);
1926
+ _this.fireAction(nodeId, _types__WEBPACK_IMPORTED_MODULE_2__.SemanticActionType.tap);
1747
1927
  }
1748
1928
  });
1749
1929
  }
1750
- if (role === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.slider) {
1930
+ if (role === _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.slider) {
1751
1931
  el.addEventListener("keydown", function (e) {
1752
1932
  if (e.key === "ArrowRight" || e.key === "ArrowUp") {
1753
- e.preventDefault();
1754
- _this.fireAction(nodeId, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticActionType.increase);
1933
+ (0,_claimedKeyEvents__WEBPACK_IMPORTED_MODULE_0__.claimKeyEvent)(e);
1934
+ _this.fireAction(nodeId, _types__WEBPACK_IMPORTED_MODULE_2__.SemanticActionType.increase);
1755
1935
  }
1756
1936
  else if (e.key === "ArrowLeft" || e.key === "ArrowDown") {
1757
- e.preventDefault();
1758
- _this.fireAction(nodeId, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticActionType.decrease);
1937
+ (0,_claimedKeyEvents__WEBPACK_IMPORTED_MODULE_0__.claimKeyEvent)(e);
1938
+ _this.fireAction(nodeId, _types__WEBPACK_IMPORTED_MODULE_2__.SemanticActionType.decrease);
1759
1939
  }
1760
1940
  });
1761
1941
  }
1762
- if (role === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.tab) {
1942
+ if (role === _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.tab) {
1763
1943
  this.attachRovingNav(el, {
1764
1944
  includeHomeEnd: true,
1765
1945
  members: function () {
@@ -1772,7 +1952,7 @@ var AccessibilityOverlay = /** @class */ (function () {
1772
1952
  },
1773
1953
  });
1774
1954
  }
1775
- if (role === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.radioButton) {
1955
+ if (role === _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.radioButton) {
1776
1956
  this.attachRovingNav(el, {
1777
1957
  includeHomeEnd: false,
1778
1958
  members: function () {
@@ -1787,15 +1967,31 @@ var AccessibilityOverlay = /** @class */ (function () {
1787
1967
  // Focus handler for nodes with the Focusable trait. When AT focuses an
1788
1968
  // element, notify the C++ runtime so it can update internal focus state
1789
1969
  // (visual focus rings, etc.). Gated on Focusable trait
1790
- if ((0,_types__WEBPACK_IMPORTED_MODULE_0__.hasTrait)(node.traitFlags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticTrait.Focusable)) {
1970
+ if ((0,_types__WEBPACK_IMPORTED_MODULE_2__.hasTrait)(node.traitFlags, _types__WEBPACK_IMPORTED_MODULE_2__.SemanticTrait.Focusable)) {
1791
1971
  el.addEventListener("focus", function () {
1792
1972
  _this.requestFocus(nodeId);
1793
1973
  });
1794
1974
  }
1795
1975
  };
1796
1976
  // ---- Attribute application ----
1977
+ AccessibilityOverlay.prototype.isAriaHidden = function (node) {
1978
+ var role = node.role;
1979
+ var flags = node.stateFlags;
1980
+ // Hide from AT when explicitly hidden, or when an image has no accessible
1981
+ // name — a nameless role="img" is a WCAG 1.1.1 violation; treat it as
1982
+ // decorative instead.
1983
+ var isDecorativeImage = role === _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.image && !node.label;
1984
+ // The <input> proxy is the accessible element for the node it stands in for.
1985
+ var isEditingHostStandIn = node.id === this.editingHostNodeId;
1986
+ return ((0,_types__WEBPACK_IMPORTED_MODULE_2__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_2__.SemanticState.Hidden) ||
1987
+ // Obscured text fields stay reachable (value withheld, like a native password input).
1988
+ ((0,_types__WEBPACK_IMPORTED_MODULE_2__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_2__.SemanticState.Obscured) && role !== _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.textField) ||
1989
+ isDecorativeImage ||
1990
+ isEditingHostStandIn);
1991
+ };
1797
1992
  AccessibilityOverlay.prototype.applyAttributes = function (el, node) {
1798
1993
  var _a, _b, _c;
1994
+ this.appliedNodes.set(el, node);
1799
1995
  var role = node.role;
1800
1996
  var flags = node.stateFlags;
1801
1997
  var traits = node.traitFlags;
@@ -1809,7 +2005,7 @@ var AccessibilityOverlay = /** @class */ (function () {
1809
2005
  }
1810
2006
  // Links: a bare <a> with no href has no link semantics, so set the role
1811
2007
  // explicitly (ariaRoleForSemantic returns null for link → native <a>).
1812
- if (role === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.link) {
2008
+ if (role === _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.link) {
1813
2009
  setAttr(el, "role", "link");
1814
2010
  }
1815
2011
  // Tabindex — keep the screen-reader overlay out of the browser's sequential
@@ -1817,8 +2013,8 @@ var AccessibilityOverlay = /** @class */ (function () {
1817
2013
  // so AT/runtime focus sync can still target them when needed. List items are
1818
2014
  // included because Mobile Safari won't iterate them otherwise.
1819
2015
  if (isInteractiveRole(role) ||
1820
- (0,_types__WEBPACK_IMPORTED_MODULE_0__.hasTrait)(traits, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticTrait.Focusable) ||
1821
- role === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.listItem) {
2016
+ (0,_types__WEBPACK_IMPORTED_MODULE_2__.hasTrait)(traits, _types__WEBPACK_IMPORTED_MODULE_2__.SemanticTrait.Focusable) ||
2017
+ role === _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.listItem) {
1822
2018
  setAttr(el, "tabindex", "-1");
1823
2019
  }
1824
2020
  else {
@@ -1831,7 +2027,7 @@ var AccessibilityOverlay = /** @class */ (function () {
1831
2027
  else {
1832
2028
  removeAttr(el, "aria-label");
1833
2029
  }
1834
- if (role === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.slider) {
2030
+ if (role === _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.slider) {
1835
2031
  if (node.value) {
1836
2032
  // aria-valuenow must be numeric; keep the display string (e.g. "75%")
1837
2033
  // in aria-valuetext only.
@@ -1851,7 +2047,7 @@ var AccessibilityOverlay = /** @class */ (function () {
1851
2047
  // TODO: aria-valuemin / aria-valuemax are required by ARIA.
1852
2048
  // Defaulting to horizontal; vertical sliders need orientation data from C++.
1853
2049
  setAttr(el, "aria-orientation", "horizontal");
1854
- setBoolAttr(el, "aria-readonly", (0,_types__WEBPACK_IMPORTED_MODULE_0__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticState.ReadOnly));
2050
+ setBoolAttr(el, "aria-readonly", (0,_types__WEBPACK_IMPORTED_MODULE_2__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_2__.SemanticState.ReadOnly));
1855
2051
  }
1856
2052
  else {
1857
2053
  removeAttr(el, "aria-valuenow");
@@ -1885,7 +2081,7 @@ var AccessibilityOverlay = /** @class */ (function () {
1885
2081
  // Text nodes: use textContent rather than aria-label so screen readers
1886
2082
  // announce the text in virtual/browse mode (aria-label on a bare <span>
1887
2083
  // with no widget role is ignored by some AT in document browse mode).
1888
- if (role === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.text) {
2084
+ if (role === _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.text) {
1889
2085
  var textSpan = (_a = el.querySelector(":scope > span")) !== null && _a !== void 0 ? _a : el;
1890
2086
  var text = (_b = node.label) !== null && _b !== void 0 ? _b : "";
1891
2087
  if (textSpan.textContent !== text)
@@ -1905,77 +2101,73 @@ var AccessibilityOverlay = /** @class */ (function () {
1905
2101
  // Only set the ARIA property when the trait is present. When the trait
1906
2102
  // is absent, remove the attribute so AT sees "not applicable" rather
1907
2103
  // than "false".
1908
- if ((0,_types__WEBPACK_IMPORTED_MODULE_0__.hasTrait)(traits, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticTrait.Expandable) && ARIA_EXPANDED_ROLES.has(role)) {
1909
- setBoolAttr(el, "aria-expanded", (0,_types__WEBPACK_IMPORTED_MODULE_0__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticState.Expanded));
2104
+ if ((0,_types__WEBPACK_IMPORTED_MODULE_2__.hasTrait)(traits, _types__WEBPACK_IMPORTED_MODULE_2__.SemanticTrait.Expandable) && ARIA_EXPANDED_ROLES.has(role)) {
2105
+ setBoolAttr(el, "aria-expanded", (0,_types__WEBPACK_IMPORTED_MODULE_2__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_2__.SemanticState.Expanded));
1910
2106
  }
1911
2107
  else {
1912
2108
  removeAttr(el, "aria-expanded");
1913
2109
  }
1914
2110
  // aria-selected is required on ALL tabs per ARIA spec regardless of trait;
1915
2111
  // for other roles it is trait-gated and guarded to ARIA_SELECTED_ROLES.
1916
- if (role === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.tab) {
1917
- setBoolAttr(el, "aria-selected", (0,_types__WEBPACK_IMPORTED_MODULE_0__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticState.Selected));
2112
+ if (role === _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.tab) {
2113
+ setBoolAttr(el, "aria-selected", (0,_types__WEBPACK_IMPORTED_MODULE_2__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_2__.SemanticState.Selected));
1918
2114
  }
1919
- else if ((0,_types__WEBPACK_IMPORTED_MODULE_0__.hasTrait)(traits, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticTrait.Selectable) && ARIA_SELECTED_ROLES.has(role)) {
1920
- setBoolAttr(el, "aria-selected", (0,_types__WEBPACK_IMPORTED_MODULE_0__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticState.Selected));
2115
+ else if ((0,_types__WEBPACK_IMPORTED_MODULE_2__.hasTrait)(traits, _types__WEBPACK_IMPORTED_MODULE_2__.SemanticTrait.Selectable) && ARIA_SELECTED_ROLES.has(role)) {
2116
+ setBoolAttr(el, "aria-selected", (0,_types__WEBPACK_IMPORTED_MODULE_2__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_2__.SemanticState.Selected));
1921
2117
  }
1922
2118
  else {
1923
2119
  removeAttr(el, "aria-selected");
1924
2120
  }
1925
- if ((0,_types__WEBPACK_IMPORTED_MODULE_0__.hasTrait)(traits, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticTrait.Checkable) && ARIA_CHECKED_ROLES.has(role)) {
2121
+ if ((0,_types__WEBPACK_IMPORTED_MODULE_2__.hasTrait)(traits, _types__WEBPACK_IMPORTED_MODULE_2__.SemanticTrait.Checkable) && ARIA_CHECKED_ROLES.has(role)) {
1926
2122
  // Check state is a tri-state field, but not every checkable role
1927
2123
  // accepts all three values — see ARIA_MIXED_ROLES.
1928
- var checkState = (0,_types__WEBPACK_IMPORTED_MODULE_0__.checkStateOf)(flags);
1929
- if (checkState === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticCheckState.Mixed &&
2124
+ var checkState = (0,_types__WEBPACK_IMPORTED_MODULE_2__.checkStateOf)(flags);
2125
+ if (checkState === _types__WEBPACK_IMPORTED_MODULE_2__.SemanticCheckState.Mixed &&
1930
2126
  ARIA_MIXED_ROLES.has(role)) {
1931
2127
  setAttr(el, "aria-checked", "mixed");
1932
2128
  }
1933
2129
  else {
1934
- setBoolAttr(el, "aria-checked", checkState === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticCheckState.Checked);
2130
+ setBoolAttr(el, "aria-checked", checkState === _types__WEBPACK_IMPORTED_MODULE_2__.SemanticCheckState.Checked);
1935
2131
  }
1936
2132
  }
1937
2133
  else {
1938
2134
  removeAttr(el, "aria-checked");
1939
2135
  }
1940
- if ((0,_types__WEBPACK_IMPORTED_MODULE_0__.hasTrait)(traits, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticTrait.Toggleable)) {
2136
+ if ((0,_types__WEBPACK_IMPORTED_MODULE_2__.hasTrait)(traits, _types__WEBPACK_IMPORTED_MODULE_2__.SemanticTrait.Toggleable)) {
1941
2137
  if (ARIA_PRESSED_ROLES.has(role)) {
1942
- setBoolAttr(el, "aria-pressed", (0,_types__WEBPACK_IMPORTED_MODULE_0__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticState.Toggled));
2138
+ setBoolAttr(el, "aria-pressed", (0,_types__WEBPACK_IMPORTED_MODULE_2__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_2__.SemanticState.Toggled));
1943
2139
  }
1944
2140
  else {
1945
2141
  removeAttr(el, "aria-pressed");
1946
2142
  }
1947
2143
  // switch uses aria-checked (not aria-pressed) for its on/off state.
1948
- if (role === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.switchControl) {
1949
- setBoolAttr(el, "aria-checked", (0,_types__WEBPACK_IMPORTED_MODULE_0__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticState.Toggled));
2144
+ if (role === _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.switchControl) {
2145
+ setBoolAttr(el, "aria-checked", (0,_types__WEBPACK_IMPORTED_MODULE_2__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_2__.SemanticState.Toggled));
1950
2146
  }
1951
2147
  }
1952
2148
  else {
1953
2149
  removeAttr(el, "aria-pressed");
1954
2150
  }
1955
- if ((0,_types__WEBPACK_IMPORTED_MODULE_0__.hasTrait)(traits, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticTrait.Requirable) && ARIA_REQUIRED_ROLES.has(role)) {
1956
- setBoolAttr(el, "aria-required", (0,_types__WEBPACK_IMPORTED_MODULE_0__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticState.Required));
2151
+ if ((0,_types__WEBPACK_IMPORTED_MODULE_2__.hasTrait)(traits, _types__WEBPACK_IMPORTED_MODULE_2__.SemanticTrait.Requirable) && ARIA_REQUIRED_ROLES.has(role)) {
2152
+ setBoolAttr(el, "aria-required", (0,_types__WEBPACK_IMPORTED_MODULE_2__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_2__.SemanticState.Required));
1957
2153
  }
1958
2154
  else {
1959
2155
  removeAttr(el, "aria-required");
1960
2156
  }
1961
- if ((0,_types__WEBPACK_IMPORTED_MODULE_0__.hasTrait)(traits, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticTrait.Enablable)) {
1962
- setBoolAttr(el, "aria-disabled", (0,_types__WEBPACK_IMPORTED_MODULE_0__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticState.Disabled));
2157
+ if ((0,_types__WEBPACK_IMPORTED_MODULE_2__.hasTrait)(traits, _types__WEBPACK_IMPORTED_MODULE_2__.SemanticTrait.Enablable)) {
2158
+ setBoolAttr(el, "aria-disabled", (0,_types__WEBPACK_IMPORTED_MODULE_2__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_2__.SemanticState.Disabled));
1963
2159
  }
1964
2160
  else {
1965
2161
  removeAttr(el, "aria-disabled");
1966
2162
  }
1967
2163
  // ---- Non-trait states ----
1968
- // Hide from AT when explicitly hidden, or when an image has no accessible
1969
- // name — a nameless role="img" is a WCAG 1.1.1 violation; treat it as
1970
- // decorative instead.
1971
- var isDecorativeImage = role === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.image && !node.label;
1972
- 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) {
2164
+ if (this.isAriaHidden(node)) {
1973
2165
  setAttr(el, "aria-hidden", "true");
1974
2166
  }
1975
2167
  else {
1976
2168
  removeAttr(el, "aria-hidden");
1977
2169
  }
1978
- if ((0,_types__WEBPACK_IMPORTED_MODULE_0__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticState.LiveRegion)) {
2170
+ if ((0,_types__WEBPACK_IMPORTED_MODULE_2__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_2__.SemanticState.LiveRegion)) {
1979
2171
  setAttr(el, "aria-live", "polite");
1980
2172
  }
1981
2173
  else {
@@ -1983,17 +2175,26 @@ var AccessibilityOverlay = /** @class */ (function () {
1983
2175
  }
1984
2176
  // textField-specific
1985
2177
  // TODO: Details here may change once we implement text inputs
1986
- if (role === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.textField) {
1987
- setBoolAttr(el, "aria-readonly", (0,_types__WEBPACK_IMPORTED_MODULE_0__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticState.ReadOnly));
1988
- setBoolAttr(el, "aria-multiline", (0,_types__WEBPACK_IMPORTED_MODULE_0__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticState.Multiline));
2178
+ if (role === _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.textField) {
2179
+ setBoolAttr(el, "aria-readonly", (0,_types__WEBPACK_IMPORTED_MODULE_2__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_2__.SemanticState.ReadOnly));
2180
+ setBoolAttr(el, "aria-multiline", (0,_types__WEBPACK_IMPORTED_MODULE_2__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_2__.SemanticState.Multiline));
1989
2181
  // Surface the current field value as DOM text so screen readers can
1990
2182
  // announce it. Only safe when the node has no semantic children —
1991
2183
  // setting textContent would remove any child elements from the DOM.
1992
2184
  if (node.children.length === 0) {
1993
- var value = (_c = node.value) !== null && _c !== void 0 ? _c : "";
2185
+ var value = (0,_types__WEBPACK_IMPORTED_MODULE_2__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_2__.SemanticState.Obscured) ? "" : ((_c = node.value) !== null && _c !== void 0 ? _c : "");
1994
2186
  if (el.textContent !== value)
1995
2187
  el.textContent = value;
1996
2188
  }
2189
+ else {
2190
+ // A value rendered earlier (before the node had children) must not linger,
2191
+ // least of all once the field turns Obscured.
2192
+ for (var _i = 0, _d = Array.from(el.childNodes); _i < _d.length; _i++) {
2193
+ var child = _d[_i];
2194
+ if (child.nodeType === Node.TEXT_NODE)
2195
+ child.remove();
2196
+ }
2197
+ }
1997
2198
  }
1998
2199
  else {
1999
2200
  removeAttr(el, "aria-multiline");
@@ -2057,7 +2258,7 @@ var AccessibilityOverlay = /** @class */ (function () {
2057
2258
  // Clear any CSS transform from a previous render pass.
2058
2259
  if (el.style.transform)
2059
2260
  el.style.transform = "";
2060
- if (node.role === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.text) {
2261
+ if (node.role === _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.text) {
2061
2262
  this.pendingTextGeometry.push(el);
2062
2263
  }
2063
2264
  };
@@ -2116,7 +2317,8 @@ var AccessibilityOverlay = /** @class */ (function () {
2116
2317
  * Creates (on first call) and updates the artboard-space transform container.
2117
2318
  *
2118
2319
  * The container is sized to the artboard dimensions and carries a CSS
2119
- * `transform: matrix(...)` equivalent to `forwardMat / dpr`. All semantic
2320
+ * `transform: matrix(...)` that maps artboard coordinates to the canvas's CSS box
2321
+ * (forwardMat in backing-store pixels, scaled by CSS size / backing-store size). All semantic
2120
2322
  * node elements are children of this container and use raw artboard
2121
2323
  * coordinates as their CSS `left/top/width/height`, so the CSS compositor
2122
2324
  * applies the artboard→screen mapping in one pass.
@@ -2141,13 +2343,20 @@ var AccessibilityOverlay = /** @class */ (function () {
2141
2343
  var h = artboardBounds.maxY - artboardBounds.minY;
2142
2344
  this.transformContainer.style.width = Math.round(w) + "px";
2143
2345
  this.transformContainer.style.height = Math.round(h) + "px";
2144
- var s = 1 / (dpr || 1);
2145
- var a = forwardMat.xx * s;
2146
- var b = forwardMat.xy * s;
2147
- var c = forwardMat.yx * s;
2148
- var d = forwardMat.yy * s;
2149
- var tx = forwardMat.tx * s;
2150
- var ty = forwardMat.ty * s;
2346
+ // Backing-store pixels → CSS pixels. Measured rather than 1/dpr: a canvas can be
2347
+ // stretched by CSS, or have a stale backing store after a resize, and the drawn
2348
+ // content follows the CSS box either way. Equal to 1/dpr when they match.
2349
+ var cssWidth = this.lastCanvasPositioning.width;
2350
+ var cssHeight = this.lastCanvasPositioning.height;
2351
+ var fallback = 1 / (dpr || 1);
2352
+ var sx = this.canvas.width > 0 && cssWidth > 0 ? cssWidth / this.canvas.width : fallback;
2353
+ var sy = this.canvas.height > 0 && cssHeight > 0 ? cssHeight / this.canvas.height : fallback;
2354
+ var a = forwardMat.xx * sx;
2355
+ var b = forwardMat.xy * sy;
2356
+ var c = forwardMat.yx * sx;
2357
+ var d = forwardMat.yy * sy;
2358
+ var tx = forwardMat.tx * sx;
2359
+ var ty = forwardMat.ty * sy;
2151
2360
  this.transformContainer.style.transform =
2152
2361
  "matrix(".concat(a, ",").concat(b, ",").concat(c, ",").concat(d, ",").concat(tx, ",").concat(ty, ")");
2153
2362
  };
@@ -2170,11 +2379,11 @@ var AccessibilityOverlay = /** @class */ (function () {
2170
2379
  // ---------------------------------------------------------------------------
2171
2380
  /** aria-expanded: button, link, checkbox, switch (inherits button), tab. */
2172
2381
  var ARIA_EXPANDED_ROLES = new Set([
2173
- _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.button,
2174
- _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.link,
2175
- _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.checkbox,
2176
- _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.switchControl,
2177
- _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.tab,
2382
+ _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.button,
2383
+ _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.link,
2384
+ _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.checkbox,
2385
+ _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.switchControl,
2386
+ _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.tab,
2178
2387
  ]);
2179
2388
  /**
2180
2389
  * aria-selected: tab is the only role in our current set that natively
@@ -2183,13 +2392,13 @@ var ARIA_EXPANDED_ROLES = new Set([
2183
2392
  * the set still lists it so the constraint is visible in one place.
2184
2393
  */
2185
2394
  var ARIA_SELECTED_ROLES = new Set([
2186
- _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.tab,
2395
+ _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.tab,
2187
2396
  ]);
2188
2397
  /** aria-checked: checkbox, radio, switch. */
2189
2398
  var ARIA_CHECKED_ROLES = new Set([
2190
- _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.checkbox,
2191
- _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.radioButton,
2192
- _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.switchControl,
2399
+ _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.checkbox,
2400
+ _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.radioButton,
2401
+ _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.switchControl,
2193
2402
  ]);
2194
2403
  /**
2195
2404
  * aria-checked="mixed": checkbox only. ARIA defines checkbox as three-valued
@@ -2198,7 +2407,7 @@ var ARIA_CHECKED_ROLES = new Set([
2198
2407
  * emitting a value they do not support.
2199
2408
  */
2200
2409
  var ARIA_MIXED_ROLES = new Set([
2201
- _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.checkbox,
2410
+ _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.checkbox,
2202
2411
  ]);
2203
2412
  /**
2204
2413
  * aria-pressed: button only. switch is a button subclass in ARIA but uses
@@ -2206,13 +2415,13 @@ var ARIA_MIXED_ROLES = new Set([
2206
2415
  * excluded here and handled separately in the Toggleable block.
2207
2416
  */
2208
2417
  var ARIA_PRESSED_ROLES = new Set([
2209
- _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.button,
2418
+ _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.button,
2210
2419
  ]);
2211
2420
  /** aria-required: checkbox, textbox, radiogroup. */
2212
2421
  var ARIA_REQUIRED_ROLES = new Set([
2213
- _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.checkbox,
2214
- _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.textField,
2215
- _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.radioGroup,
2422
+ _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.checkbox,
2423
+ _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.textField,
2424
+ _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.radioGroup,
2216
2425
  ]);
2217
2426
  // ---------------------------------------------------------------------------
2218
2427
  /** Style for visually-hidden description spans used with aria-describedby. */
@@ -2261,12 +2470,12 @@ function setBoolAttr(el, attr, value) {
2261
2470
  /** Roles that receive click/Enter/Space action handlers. */
2262
2471
  function isClickableRole(role) {
2263
2472
  switch (role) {
2264
- case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.button:
2265
- case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.link:
2266
- case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.checkbox:
2267
- case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.switchControl:
2268
- case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.tab:
2269
- case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.radioButton:
2473
+ case _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.button:
2474
+ case _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.link:
2475
+ case _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.checkbox:
2476
+ case _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.switchControl:
2477
+ case _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.tab:
2478
+ case _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.radioButton:
2270
2479
  return true;
2271
2480
  default:
2272
2481
  return false;
@@ -2275,14 +2484,14 @@ function isClickableRole(role) {
2275
2484
  /** Roles that receive tabindex="-1" for programmatic/AT focus (not Tab order). */
2276
2485
  function isInteractiveRole(role) {
2277
2486
  switch (role) {
2278
- case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.button:
2279
- case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.link:
2280
- case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.checkbox:
2281
- case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.switchControl:
2282
- case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.slider:
2283
- case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.tab:
2284
- case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.radioButton:
2285
- case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.textField:
2487
+ case _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.button:
2488
+ case _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.link:
2489
+ case _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.checkbox:
2490
+ case _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.switchControl:
2491
+ case _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.slider:
2492
+ case _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.tab:
2493
+ case _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.radioButton:
2494
+ case _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.textField:
2286
2495
  return true;
2287
2496
  default:
2288
2497
  return false;
@@ -2293,13 +2502,13 @@ function isInteractiveRole(role) {
2293
2502
  * dialog only when the Modal state flag is set.
2294
2503
  */
2295
2504
  function isModalDialogRole(role, flags) {
2296
- return (role === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.alertDialog ||
2297
- (role === _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.dialog && (0,_types__WEBPACK_IMPORTED_MODULE_0__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticState.Modal)));
2505
+ return (role === _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.alertDialog ||
2506
+ (role === _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.dialog && (0,_types__WEBPACK_IMPORTED_MODULE_2__.hasState)(flags, _types__WEBPACK_IMPORTED_MODULE_2__.SemanticState.Modal)));
2298
2507
  }
2299
2508
  /** Whether a node can receive focus: an interactive role or the Focusable trait. */
2300
2509
  function isFocusableNode(node) {
2301
2510
  return (isInteractiveRole(node.role) ||
2302
- (0,_types__WEBPACK_IMPORTED_MODULE_0__.hasTrait)(node.traitFlags, _types__WEBPACK_IMPORTED_MODULE_0__.SemanticTrait.Focusable));
2511
+ (0,_types__WEBPACK_IMPORTED_MODULE_2__.hasTrait)(node.traitFlags, _types__WEBPACK_IMPORTED_MODULE_2__.SemanticTrait.Focusable));
2303
2512
  }
2304
2513
  /**
2305
2514
  * Choose an HTML tag for a given role. Prefer native semantic elements
@@ -2308,9 +2517,9 @@ function isFocusableNode(node) {
2308
2517
  */
2309
2518
  function tagForRole(role) {
2310
2519
  switch (role) {
2311
- case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.link:
2520
+ case _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.link:
2312
2521
  return "a";
2313
- case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.text:
2522
+ case _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.text:
2314
2523
  // The outer div is the positioned AX element VoiceOver measures for its
2315
2524
  // highlight box. The text itself lives in a child <span> (see createElement).
2316
2525
  return "div";
@@ -2326,43 +2535,43 @@ function tagForRole(role) {
2326
2535
  */
2327
2536
  function ariaRoleForSemantic(role) {
2328
2537
  switch (role) {
2329
- case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.none:
2538
+ case _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.none:
2330
2539
  // TODO: Role "none" removes the node from the accessibility tree. For now, setting to Group, but maybe we want to switch to "none"
2331
2540
  // or "presentation".
2332
2541
  return "group";
2333
- case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.button:
2542
+ case _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.button:
2334
2543
  return "button";
2335
- case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.link:
2544
+ case _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.link:
2336
2545
  return null; // native <a>
2337
- case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.checkbox:
2546
+ case _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.checkbox:
2338
2547
  return "checkbox";
2339
- case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.switchControl:
2548
+ case _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.switchControl:
2340
2549
  return "switch";
2341
- case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.slider:
2550
+ case _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.slider:
2342
2551
  return "slider";
2343
- case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.textField:
2552
+ case _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.textField:
2344
2553
  return "textbox";
2345
- case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.image:
2554
+ case _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.image:
2346
2555
  return "img";
2347
- case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.group:
2556
+ case _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.group:
2348
2557
  return "group";
2349
- case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.list:
2558
+ case _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.list:
2350
2559
  return "list";
2351
- case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.listItem:
2560
+ case _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.listItem:
2352
2561
  return "listitem";
2353
- case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.tab:
2562
+ case _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.tab:
2354
2563
  return "tab";
2355
- case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.tabList:
2564
+ case _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.tabList:
2356
2565
  return "tablist";
2357
- case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.dialog:
2566
+ case _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.dialog:
2358
2567
  return "dialog";
2359
- case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.alertDialog:
2568
+ case _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.alertDialog:
2360
2569
  return "alertdialog";
2361
- case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.radioGroup:
2570
+ case _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.radioGroup:
2362
2571
  return "radiogroup";
2363
- case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.radioButton:
2572
+ case _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.radioButton:
2364
2573
  return "radio";
2365
- case _types__WEBPACK_IMPORTED_MODULE_0__.SemanticRole.text:
2574
+ case _types__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.text:
2366
2575
  // Text nodes use <span>; heading role is applied separately
2367
2576
  // when headingLevel > 0.
2368
2577
  return null;
@@ -2376,6 +2585,56 @@ function ariaRoleForSemantic(role) {
2376
2585
  /* 10 */
2377
2586
  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
2378
2587
 
2588
+ __webpack_require__.r(__webpack_exports__);
2589
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
2590
+ /* harmony export */ claimKeyEvent: () => (/* binding */ claimKeyEvent),
2591
+ /* harmony export */ isKeyEventClaimed: () => (/* binding */ isKeyEventClaimed)
2592
+ /* harmony export */ });
2593
+ var claimed = new WeakSet();
2594
+ /**
2595
+ * Marks a key event as handled by a semantic overlay widget (and prevents its
2596
+ * default), so the Rive keyboard handler leaves it alone. A plain
2597
+ * `defaultPrevented` check can't tell these apart from host-page handlers.
2598
+ */
2599
+ function claimKeyEvent(event) {
2600
+ event.preventDefault();
2601
+ claimed.add(event);
2602
+ }
2603
+ function isKeyEventClaimed(event) {
2604
+ return claimed.has(event);
2605
+ }
2606
+
2607
+
2608
+ /***/ }),
2609
+ /* 11 */
2610
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
2611
+
2612
+ __webpack_require__.r(__webpack_exports__);
2613
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
2614
+ /* harmony export */ canvasOffset: () => (/* binding */ canvasOffset)
2615
+ /* harmony export */ });
2616
+ /**
2617
+ * Canvas offset within its offsetParent, minus the scroll of ancestors in between (they
2618
+ * move the canvas, not absolutely positioned siblings).
2619
+ */
2620
+ function canvasOffset(canvas) {
2621
+ var top = canvas.offsetTop;
2622
+ var left = canvas.offsetLeft;
2623
+ var offsetParent = canvas.offsetParent;
2624
+ if (!offsetParent)
2625
+ return { top: top, left: left };
2626
+ for (var el = canvas.parentElement; el && el !== offsetParent; el = el.parentElement) {
2627
+ top -= el.scrollTop;
2628
+ left -= el.scrollLeft;
2629
+ }
2630
+ return { top: top, left: left };
2631
+ }
2632
+
2633
+
2634
+ /***/ }),
2635
+ /* 12 */
2636
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
2637
+
2379
2638
  __webpack_require__.r(__webpack_exports__);
2380
2639
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
2381
2640
  /* harmony export */ AudioAssetWrapper: () => (/* reexport safe */ _finalizationRegistry__WEBPACK_IMPORTED_MODULE_3__.AudioAssetWrapper),
@@ -2396,11 +2655,11 @@ __webpack_require__.r(__webpack_exports__);
2396
2655
  /* harmony export */ registerTouchInteractions: () => (/* reexport safe */ _registerTouchInteractions__WEBPACK_IMPORTED_MODULE_0__.registerTouchInteractions),
2397
2656
  /* harmony export */ sanitizeUrl: () => (/* reexport safe */ _sanitizeUrl__WEBPACK_IMPORTED_MODULE_2__.sanitizeUrl)
2398
2657
  /* harmony export */ });
2399
- /* harmony import */ var _registerTouchInteractions__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(11);
2400
- /* harmony import */ var _registerKeyboardInteractions__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(12);
2401
- /* harmony import */ var _sanitizeUrl__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(13);
2402
- /* harmony import */ var _finalizationRegistry__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(14);
2403
- /* harmony import */ var _riveFont__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(15);
2658
+ /* harmony import */ var _registerTouchInteractions__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(13);
2659
+ /* harmony import */ var _registerKeyboardInteractions__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(14);
2660
+ /* harmony import */ var _sanitizeUrl__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(17);
2661
+ /* harmony import */ var _finalizationRegistry__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(18);
2662
+ /* harmony import */ var _riveFont__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(19);
2404
2663
 
2405
2664
 
2406
2665
 
@@ -2409,7 +2668,7 @@ __webpack_require__.r(__webpack_exports__);
2409
2668
 
2410
2669
 
2411
2670
  /***/ }),
2412
- /* 11 */
2671
+ /* 13 */
2413
2672
  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
2414
2673
 
2415
2674
  __webpack_require__.r(__webpack_exports__);
@@ -2488,7 +2747,7 @@ var getClientCoordinates = function (event, isTouchScrollEnabled, enableMultiTou
2488
2747
  * the state machine pointer move/up/down functions based on cursor interaction
2489
2748
  */
2490
2749
  var registerTouchInteractions = function (_a) {
2491
- var canvas = _a.canvas, artboard = _a.artboard, _b = _a.stateMachines, stateMachines = _b === void 0 ? [] : _b, renderer = _a.renderer, rive = _a.rive, fit = _a.fit, alignment = _a.alignment, _c = _a.isTouchScrollEnabled, isTouchScrollEnabled = _c === void 0 ? false : _c, _d = _a.dispatchPointerExit, dispatchPointerExit = _d === void 0 ? true : _d, _e = _a.enableMultiTouch, enableMultiTouch = _e === void 0 ? false : _e, _f = _a.layoutScaleFactor, layoutScaleFactor = _f === void 0 ? 1.0 : _f, advanceAndDrain = _a.advanceAndDrain;
2750
+ var canvas = _a.canvas, artboard = _a.artboard, _b = _a.stateMachines, stateMachines = _b === void 0 ? [] : _b, renderer = _a.renderer, rive = _a.rive, fit = _a.fit, alignment = _a.alignment, _c = _a.isTouchScrollEnabled, isTouchScrollEnabled = _c === void 0 ? false : _c, _d = _a.dispatchPointerExit, dispatchPointerExit = _d === void 0 ? true : _d, _e = _a.enableMultiTouch, enableMultiTouch = _e === void 0 ? false : _e, _f = _a.layoutScaleFactor, layoutScaleFactor = _f === void 0 ? 1.0 : _f, advanceAndDrain = _a.advanceAndDrain, summonKeyboard = _a.summonKeyboard, isTextProxyFocused = _a.isTextProxyFocused;
2492
2751
  if (!canvas ||
2493
2752
  !stateMachines.length ||
2494
2753
  !renderer ||
@@ -2508,8 +2767,10 @@ var registerTouchInteractions = function (_a) {
2508
2767
  * We're keeping track of the previous event to not send the synthetic mouse events if the
2509
2768
  * touch event was a click (touchstart -> touchend).
2510
2769
  *
2511
- * This is only needed when `isTouchScrollEnabled` is false
2512
- * When true, `preventDefault()` is called which prevents this behaviour.
2770
+ * Emulated events only occur when `isTouchScrollEnabled` is true; when false,
2771
+ * touchstart is default-prevented, which suppresses them.
2772
+ * Emulated mousedown is prevented while the proxy is focused, or it would blur it and
2773
+ * drop the keyboard.
2513
2774
  **/
2514
2775
  var _prevEventType = null;
2515
2776
  var _syntheticEventsActive = false;
@@ -2526,6 +2787,9 @@ var registerTouchInteractions = function (_a) {
2526
2787
  // https://stackoverflow.com/questions/9656990/how-to-prevent-simulated-mouse-events-in-mobile-browsers
2527
2788
  // https://stackoverflow.com/questions/25572070/javascript-touchend-versus-click-dilemma
2528
2789
  if (_syntheticEventsActive && event instanceof MouseEvent) {
2790
+ if (event.type === "mousedown" && (isTextProxyFocused === null || isTextProxyFocused === void 0 ? void 0 : isTextProxyFocused())) {
2791
+ event.preventDefault();
2792
+ }
2529
2793
  // Synthetic event finished
2530
2794
  if (event.type == "mouseup") {
2531
2795
  _syntheticEventsActive = false;
@@ -2632,7 +2896,7 @@ var registerTouchInteractions = function (_a) {
2632
2896
  _loop_3(stateMachine);
2633
2897
  }
2634
2898
  // Advance the state machine immediately so pointer down(s) takes effect synchronously
2635
- advanceAndDrain(0);
2899
+ advanceAndDrain(0, { pointerDown: true });
2636
2900
  break;
2637
2901
  }
2638
2902
  // Pointer click released on the canvas
@@ -2649,6 +2913,9 @@ var registerTouchInteractions = function (_a) {
2649
2913
  }
2650
2914
  // Advance the state machine immediately so pointer up(s) takes effect synchronously
2651
2915
  advanceAndDrain(0);
2916
+ // Still inside the touch gesture — summon the keyboard if the tap focused a
2917
+ // text input
2918
+ summonKeyboard === null || summonKeyboard === void 0 ? void 0 : summonKeyboard();
2652
2919
  // Release the primary touch lock once that finger lifts so the next
2653
2920
  // touchstart can claim a new primary finger.
2654
2921
  if (!enableMultiTouch &&
@@ -2669,6 +2936,7 @@ var registerTouchInteractions = function (_a) {
2669
2936
  }
2670
2937
  // Advance the state machine immediately so pointer up(s) takes effect synchronously
2671
2938
  advanceAndDrain(0);
2939
+ summonKeyboard === null || summonKeyboard === void 0 ? void 0 : summonKeyboard();
2672
2940
  break;
2673
2941
  }
2674
2942
  default:
@@ -2706,7 +2974,7 @@ var registerTouchInteractions = function (_a) {
2706
2974
 
2707
2975
 
2708
2976
  /***/ }),
2709
- /* 12 */
2977
+ /* 14 */
2710
2978
  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
2711
2979
 
2712
2980
  __webpack_require__.r(__webpack_exports__);
@@ -2714,6 +2982,43 @@ __webpack_require__.r(__webpack_exports__);
2714
2982
  /* harmony export */ FocusSessionState: () => (/* binding */ FocusSessionState),
2715
2983
  /* harmony export */ KeyboardInteractions: () => (/* binding */ KeyboardInteractions)
2716
2984
  /* harmony export */ });
2985
+ /* harmony import */ var _keyMap__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(15);
2986
+ /* harmony import */ var _semantics_claimedKeyEvents__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(10);
2987
+ /* harmony import */ var _textInputProxy__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(16);
2988
+
2989
+
2990
+
2991
+ /**
2992
+ * Defaults suppressed while typing (scroll/navigate/submit). Tab is traversal's; proxy
2993
+ * Space returns earlier as a printable.
2994
+ */
2995
+ var EDITING_NAV_CODES = new Set([
2996
+ "Space",
2997
+ "ArrowLeft",
2998
+ "ArrowRight",
2999
+ "ArrowUp",
3000
+ "ArrowDown",
3001
+ "Backspace",
3002
+ "Delete",
3003
+ "Home",
3004
+ "End",
3005
+ "Enter",
3006
+ "NumpadEnter",
3007
+ ]);
3008
+ /** A keystroke that types a character (not a Ctrl/Cmd shortcut). */
3009
+ function isPrintable(event) {
3010
+ return event.key.length === 1 && !event.ctrlKey && !event.metaKey;
3011
+ }
3012
+ function isArrowKey(key) {
3013
+ return (key === _keyMap__WEBPACK_IMPORTED_MODULE_0__.Key.left || key === _keyMap__WEBPACK_IMPORTED_MODULE_0__.Key.right || key === _keyMap__WEBPACK_IMPORTED_MODULE_0__.Key.up || key === _keyMap__WEBPACK_IMPORTED_MODULE_0__.Key.down);
3014
+ }
3015
+ /**
3016
+ * Alt/Ctrl/Meta arrows are browser/OS shortcuts (Alt+Left = back, Cmd+Arrow, etc.).
3017
+ * Shift is allowed: it is the spatial-navigation chord in Vivaldi/Opera.
3018
+ */
3019
+ function hasShortcutModifier(event) {
3020
+ return event.altKey || event.ctrlKey || event.metaKey;
3021
+ }
2717
3022
  /**
2718
3023
  * Tracks the relationship between DOM focus inside this Rive focus domain (canvas or semantic overlay)
2719
3024
  * and Rive's internal focus for the current focus session.
@@ -2739,7 +3044,8 @@ var FocusSessionState;
2739
3044
  FocusSessionState["RiveFocused"] = "riveFocused";
2740
3045
  })(FocusSessionState || (FocusSessionState = {}));
2741
3046
  /**
2742
- * Manages keyboard and DOM focus interactions for Rive's focus domain (<canvas> or semantic overlay).
3047
+ * Manages keyboard and DOM focus interactions for Rive's focus domain (<canvas>, semantic
3048
+ * overlay, text input proxy). Owns the proxy and the text input session state.
2743
3049
  * Because keyboard events can apply on either part of the domain, we need to track what events we should
2744
3050
  * handle/intercept, and when to release focus back to the page outside of the domain.
2745
3051
  *
@@ -2751,7 +3057,7 @@ var KeyboardInteractions = /** @class */ (function () {
2751
3057
  function KeyboardInteractions(_a) {
2752
3058
  var canvas = _a.canvas, stateMachine = _a.stateMachine, hasFocusNodes = _a.hasFocusNodes, getOverlayElement = _a.getOverlayElement;
2753
3059
  var _this = this;
2754
- var _b;
3060
+ var _b, _c;
2755
3061
  this.focusSessionState = FocusSessionState.NotFocused;
2756
3062
  /** Whether the canvas currently has browser DOM focus. */
2757
3063
  this.canvasHasFocus = false;
@@ -2759,6 +3065,19 @@ var KeyboardInteractions = /** @class */ (function () {
2759
3065
  this.focusDomainReleased = false;
2760
3066
  /** Overlay element currently wired with focusin/keydown listeners, if any. */
2761
3067
  this.currentOverlayElement = null;
3068
+ /** Codes whose keydown an overlay widget took, so their keyup is skipped too. */
3069
+ this.claimedKeyCodes = new Set();
3070
+ this.textInputSessionActive = false;
3071
+ /**
3072
+ * The proxy is always empty: copy Rive's selection; always preventDefault.
3073
+ */
3074
+ this.onCopy = function (event) {
3075
+ var _a;
3076
+ event.preventDefault();
3077
+ var selected = _this.mainSm.selectedText();
3078
+ if (selected)
3079
+ (_a = event.clipboardData) === null || _a === void 0 ? void 0 : _a.setData("text/plain", selected);
3080
+ };
2762
3081
  /**
2763
3082
  * Handles the canvas gaining browser focus. The behavior differs based on how focus was gained -
2764
3083
  *
@@ -2774,10 +3093,11 @@ var KeyboardInteractions = /** @class */ (function () {
2774
3093
  _this.syncOverlayListener();
2775
3094
  _this.canvasHasFocus = true;
2776
3095
  _this.focusDomainReleased = false;
2777
- if (!_this.hasFocusNodes)
2778
- return;
2779
- if (_this.mainSm.focusState().hasFocus)
3096
+ if (_this.isInFocusDomain(event.relatedTarget) ||
3097
+ !_this.hasFocusNodes ||
3098
+ _this.mainSm.focusState().hasFocus) {
2780
3099
  return;
3100
+ }
2781
3101
  _this.focusSessionState = FocusSessionState.EntryPending;
2782
3102
  // Pointer focus waits for the user's next Tab (handled in onKeyDown). Keyboard focus enters now.
2783
3103
  if (!_this.isKeyboardDrivenFocus())
@@ -2796,11 +3116,13 @@ var KeyboardInteractions = /** @class */ (function () {
2796
3116
  * When we're not in either of those buckets, it's safe to call `clearFocus()` on the SMI.
2797
3117
  */
2798
3118
  this.onCanvasBlur = function (event) {
3119
+ // Must stay before the state reset because beginTextInputSession sets the session state and
3120
+ // then focuses the proxy, which synchronously blurs the canvas.
3121
+ if (_this.inputProxy.owns(event.relatedTarget))
3122
+ return;
2799
3123
  _this.focusSessionState = FocusSessionState.NotFocused;
2800
3124
  _this.canvasHasFocus = false;
2801
- var movedWithinFocusDomain = _this.isInFocusDomain(event.relatedTarget);
2802
- var documentLostFocus = event.relatedTarget === null && !document.hasFocus();
2803
- if (movedWithinFocusDomain || documentLostFocus)
3125
+ if (_this.blurStaysWithRive(event.relatedTarget))
2804
3126
  return;
2805
3127
  _this.mainSm.clearFocus();
2806
3128
  };
@@ -2826,15 +3148,44 @@ var KeyboardInteractions = /** @class */ (function () {
2826
3148
  this.onFocusDomainHostFocusIn = function (event) {
2827
3149
  _this.syncOverlayListener();
2828
3150
  _this.onOverlayFocusIn(event);
3151
+ // Focus entering the proxy re-enters the focus domain, so clear any earlier Tab-out
3152
+ // release, or onKeyDown would drop the session's keystrokes.
3153
+ if (_this.inputProxy.owns(event.target)) {
3154
+ _this.focusDomainReleased = false;
3155
+ }
2829
3156
  };
3157
+ /**
3158
+ * Handles keydown events in the Rive focus domain. We route certain keys to different functions, with the following
3159
+ * fallback behavior:
3160
+ * 1. Tab/Shift+Tab - check if keyInput() takes this key, if not, call focusNext/Previous traversal if there are focus nodes
3161
+ * 2. Check - if a semantic overlay element's key handler claimed the event, don't intercept the key event further
3162
+ * 3. Send key to `keyInput()` on Rive state machine if applicable.
3163
+ * 4. If the keyInput returned false, and the key is directional arrow keys, call directional focus methods on state machine
3164
+ * 5. Printables: in a session the proxy's input event supplies text; otherwise textInput().
3165
+ * A printable fires both keyInput and textInput even if a listener claims it.
3166
+ * @param event KeyboardEvent
3167
+ * @returns void
3168
+ */
2830
3169
  this.onKeyDown = function (event) {
2831
3170
  _this.syncOverlayListener();
3171
+ // Keys that are part of an IME composition belong to the IME (candidate
3172
+ // navigation, commit). Safari reports the first one as keyCode 229 with
3173
+ // isComposing still false.
3174
+ if (event.isComposing || event.keyCode === 229)
3175
+ return;
2832
3176
  // After Tab exits the last Rive node, ignore keys until focus re-enters the focus domain.
2833
3177
  if (_this.focusDomainReleased)
2834
3178
  return;
2835
3179
  if (!_this.shouldRiveHandleKeyEvent(event))
2836
3180
  return;
2837
- if (event.code === "Tab" && _this.hasFocusNodes) {
3181
+ if (event.key === "Tab" && _this.hasFocusNodes) {
3182
+ // Tab listeners are matched per phase (down/repeat/up), as in the editor, so
3183
+ // each event is offered on its own; one that isn't claimed traverses.
3184
+ if (_this.mainSm.focusState().hasFocus &&
3185
+ _this.mainSm.keyInput(_keyMap__WEBPACK_IMPORTED_MODULE_0__.Key.tab, (0,_keyMap__WEBPACK_IMPORTED_MODULE_0__.modifiersFromEvent)(event), true, event.repeat)) {
3186
+ event.preventDefault();
3187
+ return;
3188
+ }
2838
3189
  var forward = !event.shiftKey;
2839
3190
  var focusMoved = forward ? _this.mainSm.focusNext() : _this.mainSm.focusPrevious();
2840
3191
  var focusState = _this.mainSm.focusState();
@@ -2847,13 +3198,74 @@ var KeyboardInteractions = /** @class */ (function () {
2847
3198
  }
2848
3199
  else {
2849
3200
  // No more traversable nodes — release Tab to the page.
3201
+ if (document.activeElement !== _this.canvas &&
3202
+ _this.isInFocusDomain(document.activeElement)) {
3203
+ // The browser's default Tab starts from the focused element; from an overlay element,
3204
+ // the nearest stop backward is the canvas itself. Start it from the
3205
+ // canvas instead, so a Shift+Tab goes to the proper element before Rive.
3206
+ _this.canvas.focus({ preventScroll: true });
3207
+ }
2850
3208
  _this.focusSessionState = FocusSessionState.NotFocused;
2851
3209
  _this.focusDomainReleased = true;
2852
3210
  _this.canvasHasFocus = false;
2853
3211
  }
2854
3212
  _this.syncOverlayListener();
3213
+ return;
3214
+ }
3215
+ // A semantic overlay widget (roving radio/tab group, slider, Enter/Space activation)
3216
+ // already acted on this key at its target, so don't act on it twice.
3217
+ if ((0,_semantics_claimedKeyEvents__WEBPACK_IMPORTED_MODULE_1__.isKeyEventClaimed)(event)) {
3218
+ _this.claimedKeyCodes.add(event.code);
3219
+ return;
3220
+ }
3221
+ // A new unclaimed press: drop any claim whose keyup never arrived.
3222
+ _this.claimedKeyCodes.delete(event.code);
3223
+ var fromProxy = _this.textInputSessionActive && _this.inputProxy.owns(event.target);
3224
+ var expectsKeyboardInput = _this.mainSm.focusState().expectsKeyboardInput;
3225
+ // The focused node gets first refusal (a TextInput's caret, or a keyboard listener
3226
+ // on that key). Keys with no Rive equivalent map to null and aren't dispatched.
3227
+ var key = (0,_keyMap__WEBPACK_IMPORTED_MODULE_0__.keyboardEventToRiveKey)(event);
3228
+ var consumed = key !== null &&
3229
+ _this.mainSm.keyInput(key, (0,_keyMap__WEBPACK_IMPORTED_MODULE_0__.modifiersFromEvent)(event), true, event.repeat);
3230
+ // An arrow key with no consumed key input moves focus spatially. While a Rive node holds focus,
3231
+ // arrows never scroll the page
3232
+ if (!consumed && key !== null && isArrowKey(key) && !hasShortcutModifier(event)) {
3233
+ consumed =
3234
+ _this.focusInDirection(key) || _this.mainSm.focusState().hasFocus;
3235
+ }
3236
+ if (isPrintable(event)) {
3237
+ // During a session the printable must reach the proxy: its input event is the
3238
+ // (IME- and dead-key-correct) text source, and C++ inserts nothing from keyInput.
3239
+ if (fromProxy)
3240
+ return;
3241
+ // Session live but focus elsewhere in Rive: refocus the proxy so the default inserts there.
3242
+ if (_this.textInputSessionActive && _this.isInFocusDomain(event.target)) {
3243
+ _this.inputProxy.focus();
3244
+ return;
3245
+ }
3246
+ if (!_this.textInputSessionActive && expectsKeyboardInput) {
3247
+ _this.mainSm.textInput(event.key);
3248
+ }
3249
+ }
3250
+ // Rive consumed it, or an unmodified editing key while typing (would scroll/submit).
3251
+ var typing = fromProxy || expectsKeyboardInput;
3252
+ if (consumed ||
3253
+ (typing && !hasShortcutModifier(event) && EDITING_NAV_CODES.has(event.code))) {
3254
+ event.preventDefault();
2855
3255
  }
2856
3256
  };
3257
+ this.onKeyUp = function (event) {
3258
+ if (event.isComposing || event.keyCode === 229)
3259
+ return;
3260
+ if (_this.claimedKeyCodes.delete(event.code))
3261
+ return;
3262
+ if (_this.focusSessionState === FocusSessionState.NotFocused)
3263
+ return;
3264
+ var key = (0,_keyMap__WEBPACK_IMPORTED_MODULE_0__.keyboardEventToRiveKey)(event);
3265
+ if (key === null)
3266
+ return;
3267
+ _this.mainSm.keyInput(key, (0,_keyMap__WEBPACK_IMPORTED_MODULE_0__.modifiersFromEvent)(event), false, false);
3268
+ };
2857
3269
  this.canvas = canvas;
2858
3270
  this.mainSm = stateMachine;
2859
3271
  this.hasFocusNodes = hasFocusNodes;
@@ -2862,9 +3274,74 @@ var KeyboardInteractions = /** @class */ (function () {
2862
3274
  canvas.addEventListener("focus", this.onCanvasFocus);
2863
3275
  canvas.addEventListener("blur", this.onCanvasBlur);
2864
3276
  canvas.addEventListener("keydown", this.onKeyDown);
3277
+ canvas.addEventListener("keyup", this.onKeyUp);
2865
3278
  this.focusDomainHost.addEventListener("focusin", this.onFocusDomainHostFocusIn);
2866
3279
  this.syncOverlayListener();
3280
+ this.inputProxy = new _textInputProxy__WEBPACK_IMPORTED_MODULE_2__.TextInputProxy({
3281
+ container: (_c = canvas.parentElement) !== null && _c !== void 0 ? _c : document.body,
3282
+ canvas: canvas,
3283
+ textInput: function (text) { return _this.mainSm.textInput(text); },
3284
+ // Proxy keystrokes go through the same handlers as the canvas.
3285
+ onKeyDown: this.onKeyDown,
3286
+ onKeyUp: this.onKeyUp,
3287
+ onCopy: this.onCopy,
3288
+ onBlur: function (relatedTarget) { return _this.handleProxyBlur(relatedTarget); },
3289
+ });
2867
3290
  }
3291
+ KeyboardInteractions.prototype.isTextInputSessionActive = function () {
3292
+ return this.textInputSessionActive;
3293
+ };
3294
+ /** Session active and the proxy holds DOM focus. */
3295
+ KeyboardInteractions.prototype.isEditingHostFocused = function () {
3296
+ return this.textInputSessionActive && this.inputProxy.hasDomFocus();
3297
+ };
3298
+ /** @param focusProxy move DOM focus to the proxy; false leaves it where it is. */
3299
+ KeyboardInteractions.prototype.beginTextInputSession = function (focusProxy) {
3300
+ this.textInputSessionActive = true;
3301
+ this.focusSessionState = FocusSessionState.RiveFocused;
3302
+ if (focusProxy)
3303
+ this.inputProxy.focus();
3304
+ };
3305
+ /** @param fromBlur focus is already leaving; don't park it on the canvas. */
3306
+ KeyboardInteractions.prototype.endTextInputSession = function (fromBlur) {
3307
+ if (fromBlur === void 0) { fromBlur = false; }
3308
+ if (!this.textInputSessionActive)
3309
+ return;
3310
+ this.textInputSessionActive = false;
3311
+ this.inputProxy.endSession();
3312
+ if (fromBlur || !this.inputProxy.hasDomFocus())
3313
+ return;
3314
+ // Nothing took DOM focus from the proxy (e.g. semantics is off). Park it on the
3315
+ // canvas so keys keep reaching Rive; onCanvasFocus ignores focus from the input proxy.
3316
+ this.canvas.focus({ preventScroll: true });
3317
+ };
3318
+ /** Must run synchronously in the pointer gesture or mobile keyboards won't open. */
3319
+ KeyboardInteractions.prototype.summonForPointer = function () {
3320
+ if (this.textInputSessionActive)
3321
+ this.inputProxy.focus();
3322
+ else
3323
+ this.beginTextInputSession(true);
3324
+ };
3325
+ Object.defineProperty(KeyboardInteractions.prototype, "editingHost", {
3326
+ /** The text-input proxy, for the semantics layer to decorate while editing. */
3327
+ get: function () {
3328
+ return this.inputProxy;
3329
+ },
3330
+ enumerable: false,
3331
+ configurable: true
3332
+ });
3333
+ KeyboardInteractions.prototype.handleProxyBlur = function (relatedTarget) {
3334
+ // Teardown already in progress (endTextInputSession blurred the proxy).
3335
+ if (!this.textInputSessionActive)
3336
+ return;
3337
+ // Still in Rive or the document blurred: keep the session (pollFocusState tears down).
3338
+ if (this.blurStaysWithRive(relatedTarget))
3339
+ return;
3340
+ // Blurred out of Rive entirely: release C++ focus and end the session.
3341
+ this.mainSm.clearFocus();
3342
+ this.endTextInputSession(true);
3343
+ this.focusSessionState = FocusSessionState.NotFocused;
3344
+ };
2868
3345
  /**
2869
3346
  * Set the FocusSessionState. Useful for invoking a Rive "blur" without actually blurring from the <canvas>. This
2870
3347
  * helps put the DOM focus state on the canvas rather than the <body>, so the user doesn't lose the spot in page navigation
@@ -2883,6 +3360,26 @@ var KeyboardInteractions = /** @class */ (function () {
2883
3360
  KeyboardInteractions.prototype.notifyRiveFocused = function () {
2884
3361
  this.focusSessionState = FocusSessionState.RiveFocused;
2885
3362
  };
3363
+ /** Blur into the focus domain, or the whole document losing focus (tab/window switch). */
3364
+ KeyboardInteractions.prototype.blurStaysWithRive = function (relatedTarget) {
3365
+ return (this.isInFocusDomain(relatedTarget) ||
3366
+ (relatedTarget === null && !document.hasFocus()));
3367
+ };
3368
+ /** Arrow keys map to directional focus; anything else is not a focus move. */
3369
+ KeyboardInteractions.prototype.focusInDirection = function (key) {
3370
+ switch (key) {
3371
+ case _keyMap__WEBPACK_IMPORTED_MODULE_0__.Key.left:
3372
+ return this.mainSm.focusLeft();
3373
+ case _keyMap__WEBPACK_IMPORTED_MODULE_0__.Key.right:
3374
+ return this.mainSm.focusRight();
3375
+ case _keyMap__WEBPACK_IMPORTED_MODULE_0__.Key.up:
3376
+ return this.mainSm.focusUp();
3377
+ case _keyMap__WEBPACK_IMPORTED_MODULE_0__.Key.down:
3378
+ return this.mainSm.focusDown();
3379
+ default:
3380
+ return false;
3381
+ }
3382
+ };
2886
3383
  /**
2887
3384
  * Determine if Rive should handle keyboard input. If session state is `NotFocused` - no.
2888
3385
  * DOM focus stays parked on the canvas after Rive releases focus internally, and that Tab
@@ -2900,14 +3397,12 @@ var KeyboardInteractions = /** @class */ (function () {
2900
3397
  var eventOnCanvas = event.target === this.canvas;
2901
3398
  return inFocusDomain || this.canvasHasFocus || eventOnCanvas;
2902
3399
  };
2903
- /**
2904
- * The Rive focus domain: the DOM that counts as "inside" Rive for focus purposes — today the
2905
- * canvas itself OR the accessibility overlay subtree. Anything added later belongs here, so
2906
- * session bookkeeping and keydown routing pick it up for free.
2907
- */
3400
+ /** DOM that counts as inside Rive for focus: canvas, overlay subtree, text-input proxy. */
2908
3401
  KeyboardInteractions.prototype.isInFocusDomain = function (target) {
2909
3402
  if (target === this.canvas)
2910
3403
  return true;
3404
+ if (this.inputProxy.owns(target))
3405
+ return true;
2911
3406
  return this.isInOverlay(target);
2912
3407
  };
2913
3408
  /** Overlay only (excludes the canvas) — the accessibility overlay subtree. */
@@ -2918,15 +3413,19 @@ var KeyboardInteractions = /** @class */ (function () {
2918
3413
  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;
2919
3414
  };
2920
3415
  KeyboardInteractions.prototype.syncOverlayListener = function () {
2921
- var _a, _b, _c, _d, _e, _f;
3416
+ var _a, _b, _c, _d, _e, _f, _g, _h;
2922
3417
  var nextOverlayElement = (_b = (_a = this.getOverlayElement) === null || _a === void 0 ? void 0 : _a.call(this)) !== null && _b !== void 0 ? _b : null;
2923
3418
  if (nextOverlayElement === this.currentOverlayElement)
2924
3419
  return;
2925
3420
  (_c = this.currentOverlayElement) === null || _c === void 0 ? void 0 : _c.removeEventListener("focusin", this.onOverlayFocusIn);
2926
- (_d = this.currentOverlayElement) === null || _d === void 0 ? void 0 : _d.removeEventListener("keydown", this.onKeyDown, true);
3421
+ (_d = this.currentOverlayElement) === null || _d === void 0 ? void 0 : _d.removeEventListener("keydown", this.onKeyDown);
3422
+ (_e = this.currentOverlayElement) === null || _e === void 0 ? void 0 : _e.removeEventListener("keyup", this.onKeyUp);
2927
3423
  this.currentOverlayElement = nextOverlayElement;
2928
- (_e = this.currentOverlayElement) === null || _e === void 0 ? void 0 : _e.addEventListener("focusin", this.onOverlayFocusIn);
2929
- (_f = this.currentOverlayElement) === null || _f === void 0 ? void 0 : _f.addEventListener("keydown", this.onKeyDown, true);
3424
+ (_f = this.currentOverlayElement) === null || _f === void 0 ? void 0 : _f.addEventListener("focusin", this.onOverlayFocusIn);
3425
+ // Bubble phase, so a semantic widget's own key handler runs first and can claim
3426
+ // the key via claimKeyEvent (see onKeyDown).
3427
+ (_g = this.currentOverlayElement) === null || _g === void 0 ? void 0 : _g.addEventListener("keydown", this.onKeyDown);
3428
+ (_h = this.currentOverlayElement) === null || _h === void 0 ? void 0 : _h.addEventListener("keyup", this.onKeyUp);
2930
3429
  };
2931
3430
  /**
2932
3431
  * Whether the canvas currently matches :focus-visible — the browser's heuristic for keyboard-
@@ -2952,13 +3451,22 @@ var KeyboardInteractions = /** @class */ (function () {
2952
3451
  return true;
2953
3452
  };
2954
3453
  KeyboardInteractions.prototype.cleanup = function () {
2955
- var _a, _b;
3454
+ var _a, _b, _c;
2956
3455
  this.canvas.removeEventListener("focus", this.onCanvasFocus);
2957
3456
  this.canvas.removeEventListener("blur", this.onCanvasBlur);
2958
3457
  this.canvas.removeEventListener("keydown", this.onKeyDown);
3458
+ this.canvas.removeEventListener("keyup", this.onKeyUp);
3459
+ this.claimedKeyCodes.clear();
2959
3460
  this.focusDomainHost.removeEventListener("focusin", this.onFocusDomainHostFocusIn);
2960
3461
  (_a = this.currentOverlayElement) === null || _a === void 0 ? void 0 : _a.removeEventListener("focusin", this.onOverlayFocusIn);
2961
- (_b = this.currentOverlayElement) === null || _b === void 0 ? void 0 : _b.removeEventListener("keydown", this.onKeyDown, true);
3462
+ (_b = this.currentOverlayElement) === null || _b === void 0 ? void 0 : _b.removeEventListener("keydown", this.onKeyDown);
3463
+ (_c = this.currentOverlayElement) === null || _c === void 0 ? void 0 : _c.removeEventListener("keyup", this.onKeyUp);
3464
+ // Removing a focused element drops focus to <body> with no blur; park on the canvas.
3465
+ if (this.inputProxy.hasDomFocus()) {
3466
+ this.canvas.focus({ preventScroll: true });
3467
+ }
3468
+ this.inputProxy.cleanup();
3469
+ this.textInputSessionActive = false;
2962
3470
  };
2963
3471
  return KeyboardInteractions;
2964
3472
  }());
@@ -2966,7 +3474,592 @@ var KeyboardInteractions = /** @class */ (function () {
2966
3474
 
2967
3475
 
2968
3476
  /***/ }),
2969
- /* 13 */
3477
+ /* 15 */
3478
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
3479
+
3480
+ __webpack_require__.r(__webpack_exports__);
3481
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
3482
+ /* harmony export */ Key: () => (/* binding */ Key),
3483
+ /* harmony export */ KeyModifiers: () => (/* binding */ KeyModifiers),
3484
+ /* harmony export */ keyboardEventToRiveKey: () => (/* binding */ keyboardEventToRiveKey),
3485
+ /* harmony export */ modifiersFromEvent: () => (/* binding */ modifiersFromEvent)
3486
+ /* harmony export */ });
3487
+ /*
3488
+ * Maps DOM keyboard events to the GLFW-style key codes and modifier bitmask
3489
+ * that StateMachineInstance.keyInput() expects. Values mirror `enum class Key`
3490
+ * and `enum class KeyModifiers` in rive-runtime focusable.hpp;
3491
+ * they are stable GLFW codes, so they live here as constants instead of an
3492
+ * embind enum.
3493
+ */
3494
+ var __spreadArray = (undefined && undefined.__spreadArray) || function (to, from, pack) {
3495
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
3496
+ if (ar || !(i in from)) {
3497
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
3498
+ ar[i] = from[i];
3499
+ }
3500
+ }
3501
+ return to.concat(ar || Array.prototype.slice.call(from));
3502
+ };
3503
+ var Key = {
3504
+ space: 32,
3505
+ apostrophe: 39, // '
3506
+ comma: 44, // ,
3507
+ minus: 45, // -
3508
+ period: 46, // .
3509
+ slash: 47, // /
3510
+ key0: 48,
3511
+ key1: 49,
3512
+ key2: 50,
3513
+ key3: 51,
3514
+ key4: 52,
3515
+ key5: 53,
3516
+ key6: 54,
3517
+ key7: 55,
3518
+ key8: 56,
3519
+ key9: 57,
3520
+ semicolon: 59, // ;
3521
+ equal: 61, // =
3522
+ a: 65,
3523
+ b: 66,
3524
+ c: 67,
3525
+ d: 68,
3526
+ e: 69,
3527
+ f: 70,
3528
+ g: 71,
3529
+ h: 72,
3530
+ i: 73,
3531
+ j: 74,
3532
+ k: 75,
3533
+ l: 76,
3534
+ m: 77,
3535
+ n: 78,
3536
+ o: 79,
3537
+ p: 80,
3538
+ q: 81,
3539
+ r: 82,
3540
+ s: 83,
3541
+ t: 84,
3542
+ u: 85,
3543
+ v: 86,
3544
+ w: 87,
3545
+ x: 88,
3546
+ y: 89,
3547
+ z: 90,
3548
+ leftBracket: 91, // [
3549
+ backslash: 92, // \
3550
+ rightBracket: 93, // ]
3551
+ graveAccent: 96, // `
3552
+ world1: 161, // non-US #1
3553
+ world2: 162, // non-US #2
3554
+ escape: 256,
3555
+ enter: 257,
3556
+ tab: 258,
3557
+ backspace: 259,
3558
+ insert: 260,
3559
+ deleteKey: 261,
3560
+ right: 262,
3561
+ left: 263,
3562
+ down: 264,
3563
+ up: 265,
3564
+ pageUp: 266,
3565
+ pageDown: 267,
3566
+ home: 268,
3567
+ end: 269,
3568
+ capsLock: 280,
3569
+ scrollLock: 281,
3570
+ numLock: 282,
3571
+ printScreen: 283,
3572
+ pause: 284,
3573
+ f1: 290,
3574
+ f2: 291,
3575
+ f3: 292,
3576
+ f4: 293,
3577
+ f5: 294,
3578
+ f6: 295,
3579
+ f7: 296,
3580
+ f8: 297,
3581
+ f9: 298,
3582
+ f10: 299,
3583
+ f11: 300,
3584
+ f12: 301,
3585
+ f13: 302,
3586
+ f14: 303,
3587
+ f15: 304,
3588
+ f16: 305,
3589
+ f17: 306,
3590
+ f18: 307,
3591
+ f19: 308,
3592
+ f20: 309,
3593
+ f21: 310,
3594
+ f22: 311,
3595
+ f23: 312,
3596
+ f24: 313,
3597
+ f25: 314,
3598
+ kp0: 320,
3599
+ kp1: 321,
3600
+ kp2: 322,
3601
+ kp3: 323,
3602
+ kp4: 324,
3603
+ kp5: 325,
3604
+ kp6: 326,
3605
+ kp7: 327,
3606
+ kp8: 328,
3607
+ kp9: 329,
3608
+ kpDecimal: 330,
3609
+ kpDivide: 331,
3610
+ kpMultiply: 332,
3611
+ kpSubtract: 333,
3612
+ kpAdd: 334,
3613
+ kpEnter: 335,
3614
+ kpEqual: 336,
3615
+ leftShift: 340,
3616
+ leftControl: 341,
3617
+ leftAlt: 342,
3618
+ leftSuper: 343,
3619
+ rightShift: 344,
3620
+ rightControl: 345,
3621
+ rightAlt: 346,
3622
+ rightSuper: 347,
3623
+ menu: 348,
3624
+ };
3625
+ var KeyModifiers = {
3626
+ none: 0,
3627
+ shift: 1 << 0,
3628
+ ctrl: 1 << 1,
3629
+ alt: 1 << 2,
3630
+ meta: 1 << 3,
3631
+ };
3632
+ // Physical key (KeyboardEvent.code) to Rive key, by US-QWERTY position.
3633
+ var CODE_TO_KEY = {
3634
+ // Modifiers are keys too (the editor sends them), and are also in the bitmask.
3635
+ ShiftLeft: Key.leftShift,
3636
+ ShiftRight: Key.rightShift,
3637
+ ControlLeft: Key.leftControl,
3638
+ ControlRight: Key.rightControl,
3639
+ AltLeft: Key.leftAlt,
3640
+ AltRight: Key.rightAlt,
3641
+ MetaLeft: Key.leftSuper,
3642
+ MetaRight: Key.rightSuper,
3643
+ KeyA: Key.a,
3644
+ KeyB: Key.b,
3645
+ KeyC: Key.c,
3646
+ KeyD: Key.d,
3647
+ KeyE: Key.e,
3648
+ KeyF: Key.f,
3649
+ KeyG: Key.g,
3650
+ KeyH: Key.h,
3651
+ KeyI: Key.i,
3652
+ KeyJ: Key.j,
3653
+ KeyK: Key.k,
3654
+ KeyL: Key.l,
3655
+ KeyM: Key.m,
3656
+ KeyN: Key.n,
3657
+ KeyO: Key.o,
3658
+ KeyP: Key.p,
3659
+ KeyQ: Key.q,
3660
+ KeyR: Key.r,
3661
+ KeyS: Key.s,
3662
+ KeyT: Key.t,
3663
+ KeyU: Key.u,
3664
+ KeyV: Key.v,
3665
+ KeyW: Key.w,
3666
+ KeyX: Key.x,
3667
+ KeyY: Key.y,
3668
+ KeyZ: Key.z,
3669
+ Digit0: Key.key0,
3670
+ Digit1: Key.key1,
3671
+ Digit2: Key.key2,
3672
+ Digit3: Key.key3,
3673
+ Digit4: Key.key4,
3674
+ Digit5: Key.key5,
3675
+ Digit6: Key.key6,
3676
+ Digit7: Key.key7,
3677
+ Digit8: Key.key8,
3678
+ Digit9: Key.key9,
3679
+ Numpad0: Key.kp0,
3680
+ Numpad1: Key.kp1,
3681
+ Numpad2: Key.kp2,
3682
+ Numpad3: Key.kp3,
3683
+ Numpad4: Key.kp4,
3684
+ Numpad5: Key.kp5,
3685
+ Numpad6: Key.kp6,
3686
+ Numpad7: Key.kp7,
3687
+ Numpad8: Key.kp8,
3688
+ Numpad9: Key.kp9,
3689
+ NumpadDecimal: Key.kpDecimal,
3690
+ NumpadDivide: Key.kpDivide,
3691
+ NumpadMultiply: Key.kpMultiply,
3692
+ NumpadSubtract: Key.kpSubtract,
3693
+ NumpadAdd: Key.kpAdd,
3694
+ NumpadEnter: Key.kpEnter,
3695
+ NumpadEqual: Key.kpEqual,
3696
+ Minus: Key.minus,
3697
+ Equal: Key.equal,
3698
+ BracketLeft: Key.leftBracket,
3699
+ BracketRight: Key.rightBracket,
3700
+ Backslash: Key.backslash,
3701
+ Semicolon: Key.semicolon,
3702
+ Quote: Key.apostrophe,
3703
+ Backquote: Key.graveAccent,
3704
+ Comma: Key.comma,
3705
+ Period: Key.period,
3706
+ Slash: Key.slash,
3707
+ IntlBackslash: Key.world1,
3708
+ IntlRo: Key.world2,
3709
+ Space: Key.space,
3710
+ Enter: Key.enter,
3711
+ Tab: Key.tab,
3712
+ Backspace: Key.backspace,
3713
+ Insert: Key.insert,
3714
+ Delete: Key.deleteKey,
3715
+ Escape: Key.escape,
3716
+ ArrowRight: Key.right,
3717
+ ArrowLeft: Key.left,
3718
+ ArrowDown: Key.down,
3719
+ ArrowUp: Key.up,
3720
+ PageUp: Key.pageUp,
3721
+ PageDown: Key.pageDown,
3722
+ Home: Key.home,
3723
+ End: Key.end,
3724
+ CapsLock: Key.capsLock,
3725
+ ScrollLock: Key.scrollLock,
3726
+ NumLock: Key.numLock,
3727
+ PrintScreen: Key.printScreen,
3728
+ Pause: Key.pause,
3729
+ ContextMenu: Key.menu,
3730
+ F1: Key.f1,
3731
+ F2: Key.f2,
3732
+ F3: Key.f3,
3733
+ F4: Key.f4,
3734
+ F5: Key.f5,
3735
+ F6: Key.f6,
3736
+ F7: Key.f7,
3737
+ F8: Key.f8,
3738
+ F9: Key.f9,
3739
+ F10: Key.f10,
3740
+ F11: Key.f11,
3741
+ F12: Key.f12,
3742
+ F13: Key.f13,
3743
+ F14: Key.f14,
3744
+ F15: Key.f15,
3745
+ F16: Key.f16,
3746
+ F17: Key.f17,
3747
+ F18: Key.f18,
3748
+ F19: Key.f19,
3749
+ F20: Key.f20,
3750
+ F21: Key.f21,
3751
+ F22: Key.f22,
3752
+ F23: Key.f23,
3753
+ F24: Key.f24,
3754
+ F25: Key.f25,
3755
+ };
3756
+ // Unshifted characters (event.key, lowercased) that name a Rive key.
3757
+ var CHAR_TO_KEY = (function () {
3758
+ var map = {
3759
+ " ": Key.space,
3760
+ "'": Key.apostrophe,
3761
+ ",": Key.comma,
3762
+ "-": Key.minus,
3763
+ ".": Key.period,
3764
+ "/": Key.slash,
3765
+ ";": Key.semicolon,
3766
+ "=": Key.equal,
3767
+ "[": Key.leftBracket,
3768
+ "\\": Key.backslash,
3769
+ "]": Key.rightBracket,
3770
+ "`": Key.graveAccent,
3771
+ };
3772
+ for (var c = 0; c < 26; c++)
3773
+ map[String.fromCharCode(97 + c)] = Key.a + c;
3774
+ for (var d = 0; d <= 9; d++)
3775
+ map[String(d)] = Key.key0 + d;
3776
+ return map;
3777
+ })();
3778
+ // Non-printable event.key values; each shares its name with its code.
3779
+ var NAMED_KEYS = new Set(__spreadArray([
3780
+ "Enter",
3781
+ "Tab",
3782
+ "Backspace",
3783
+ "Insert",
3784
+ "Delete",
3785
+ "Escape",
3786
+ "ArrowRight",
3787
+ "ArrowLeft",
3788
+ "ArrowDown",
3789
+ "ArrowUp",
3790
+ "PageUp",
3791
+ "PageDown",
3792
+ "Home",
3793
+ "End",
3794
+ "CapsLock",
3795
+ "ScrollLock",
3796
+ "NumLock",
3797
+ "PrintScreen",
3798
+ "Pause",
3799
+ "ContextMenu"
3800
+ ], Array.from({ length: 25 }, function (_, i) { return "F".concat(i + 1); }), true));
3801
+ /**
3802
+ * Maps a KeyboardEvent to a Rive key, or null if Rive has no equivalent.
3803
+ *
3804
+ * Resolves the logical key: what the user's layout labels the key, ignoring
3805
+ * Shift, so a listener on "A" fires on AZERTY's A too. `event.key` is preferred;
3806
+ * `event.code` is the fallback when `key` isn't a plain unshifted character
3807
+ * (shifted symbols, Option/AltGr output, non-Latin letters, dead keys).
3808
+ * Digit-row and numpad keys skip the character lookup so AZERTY's digit row
3809
+ * still reports digits and numpad digits stay distinct from the digit row.
3810
+ */
3811
+ function keyboardEventToRiveKey(event) {
3812
+ var _a, _b;
3813
+ var code = event.code, key = event.key;
3814
+ if (NAMED_KEYS.has(key)) {
3815
+ // NumpadEnter reports key "Enter"; keep it distinct.
3816
+ return code === "NumpadEnter" ? Key.kpEnter : (_a = CODE_TO_KEY[key]) !== null && _a !== void 0 ? _a : null;
3817
+ }
3818
+ if (!code.startsWith("Digit") && !code.startsWith("Numpad") && key) {
3819
+ var fromChar = CHAR_TO_KEY[key.toLowerCase()];
3820
+ if (fromChar !== undefined)
3821
+ return fromChar;
3822
+ }
3823
+ return (_b = CODE_TO_KEY[code]) !== null && _b !== void 0 ? _b : null;
3824
+ }
3825
+ function modifiersFromEvent(event) {
3826
+ var modifiers = KeyModifiers.none;
3827
+ if (event.shiftKey)
3828
+ modifiers |= KeyModifiers.shift;
3829
+ if (event.ctrlKey)
3830
+ modifiers |= KeyModifiers.ctrl;
3831
+ if (event.altKey)
3832
+ modifiers |= KeyModifiers.alt;
3833
+ if (event.metaKey)
3834
+ modifiers |= KeyModifiers.meta;
3835
+ return modifiers;
3836
+ }
3837
+
3838
+
3839
+ /***/ }),
3840
+ /* 16 */
3841
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
3842
+
3843
+ __webpack_require__.r(__webpack_exports__);
3844
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
3845
+ /* harmony export */ TextInputProxy: () => (/* binding */ TextInputProxy)
3846
+ /* harmony export */ });
3847
+ /* harmony import */ var _canvasOffset__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(11);
3848
+
3849
+ // 16px: the smallest font size at which iOS Safari doesn't zoom on focus
3850
+ var FONT_SIZE_PX = 16;
3851
+ /** Capture-critical attributes decorate() must not touch. */
3852
+ var PROTECTED_ATTRS = new Set([
3853
+ "type",
3854
+ "value",
3855
+ "style",
3856
+ "tabindex",
3857
+ "autocapitalize",
3858
+ "autocomplete",
3859
+ "autocorrect",
3860
+ "spellcheck",
3861
+ ]);
3862
+ /**
3863
+ * Invisible per-instance <input> capturing IME/dead-key/paste text; focusable inside a
3864
+ * gesture to raise mobile keyboards. Always empty: C++ owns value and caret. Decorated
3865
+ * for AT only while it holds DOM focus.
3866
+ */
3867
+ var TextInputProxy = /** @class */ (function () {
3868
+ function TextInputProxy(params) {
3869
+ var _this = this;
3870
+ // True between compositionstart/compositionend; we never commit mid-composition.
3871
+ this.composing = false;
3872
+ // Names set by decorate(), removed by resetDecoration().
3873
+ this.decoratedKeys = new Set();
3874
+ // Last written left/top, to skip no-op style writes.
3875
+ this.lastLeft = NaN;
3876
+ this.lastTop = NaN;
3877
+ /** Re-sync before input: the canvas may have scrolled since the session began. */
3878
+ this.reposition = function () { return _this.positionOverCanvas(); };
3879
+ this.onCompositionStart = function () {
3880
+ _this.composing = true;
3881
+ };
3882
+ this.onCompositionEnd = function () {
3883
+ _this.composing = false;
3884
+ // The composed text is now committed in element.value; forward it here. A
3885
+ // trailing `input` event (order varies by browser) then sees an empty field.
3886
+ _this.commit();
3887
+ };
3888
+ this.onInput = function () {
3889
+ if (_this.composing)
3890
+ return;
3891
+ _this.commit();
3892
+ };
3893
+ // An <input type=text> strips line breaks from its value, so forward the clipboard
3894
+ // text directly. Core's single-line fields strip them themselves.
3895
+ this.onPaste = function (event) {
3896
+ var _a;
3897
+ var text = (_a = event.clipboardData) === null || _a === void 0 ? void 0 : _a.getData("text/plain");
3898
+ if (!text)
3899
+ return;
3900
+ event.preventDefault();
3901
+ _this.params.textInput(text.replace(/\r\n?/g, "\n"));
3902
+ };
3903
+ this.onBlur = function (event) {
3904
+ _this.params.onBlur(event.relatedTarget);
3905
+ };
3906
+ this.params = params;
3907
+ this.element = this.createElement();
3908
+ this.positionOverCanvas();
3909
+ // Order vs. the overlay is unspecified; fine, Tab release starts from the canvas.
3910
+ this.params.container.appendChild(this.element);
3911
+ }
3912
+ // Registered first so it runs before the key handler inserts or moves the caret.
3913
+ TextInputProxy.prototype.listeners = function () {
3914
+ return [
3915
+ ["keydown", this.reposition],
3916
+ ["beforeinput", this.reposition],
3917
+ ["keydown", this.params.onKeyDown],
3918
+ ["keyup", this.params.onKeyUp],
3919
+ ["input", this.onInput],
3920
+ ["compositionstart", this.onCompositionStart],
3921
+ ["compositionend", this.onCompositionEnd],
3922
+ ["paste", this.onPaste],
3923
+ ["copy", this.params.onCopy],
3924
+ ["blur", this.onBlur],
3925
+ ];
3926
+ };
3927
+ TextInputProxy.prototype.createElement = function () {
3928
+ var el = document.createElement("input");
3929
+ el.type = "text";
3930
+ // Focusable but never in native tab order (Rive drives traversal synthetically),
3931
+ // and invisible without display:none (which would forbid focus).
3932
+ el.tabIndex = -1;
3933
+ el.setAttribute("aria-hidden", "true");
3934
+ // Always empty, so autocapitalize/autocorrect would misfire.
3935
+ el.setAttribute("autocapitalize", "off");
3936
+ el.setAttribute("autocomplete", "off");
3937
+ el.setAttribute("autocorrect", "off");
3938
+ el.spellcheck = false;
3939
+ // Over the canvas (not display:none) so iOS doesn't scroll-jump on keyboard open.
3940
+ // font-size must stay 16px or iOS Safari zooms on focus.
3941
+ el.style.cssText =
3942
+ "position:absolute;width:1px;height:1px;padding:0;margin:0;border:0;" +
3943
+ "outline:none;opacity:0;background:transparent;color:transparent;" +
3944
+ "caret-color:transparent;overflow:hidden;resize:none;z-index:0;" +
3945
+ // Focused programmatically only; must not swallow clicks
3946
+ "pointer-events:none;" +
3947
+ "font-size:".concat(FONT_SIZE_PX, "px;line-height:1;");
3948
+ for (var _i = 0, _a = this.listeners(); _i < _a.length; _i++) {
3949
+ var _b = _a[_i], type = _b[0], listener = _b[1];
3950
+ el.addEventListener(type, listener);
3951
+ }
3952
+ return el;
3953
+ };
3954
+ TextInputProxy.prototype.positionOverCanvas = function () {
3955
+ // Track the canvas (browsers scroll to the caret); clamp on-screen, one caret line box
3956
+ // (FONT_SIZE_PX) from the far edges, or the root scrolls to reveal it.
3957
+ var _a = (0,_canvasOffset__WEBPACK_IMPORTED_MODULE_0__.canvasOffset)(this.params.canvas), top = _a.top, left = _a.left;
3958
+ if (window.innerHeight > 0) {
3959
+ var r = this.params.canvas.getBoundingClientRect();
3960
+ top += clamp(r.top, 0, window.innerHeight - FONT_SIZE_PX) - r.top;
3961
+ left += clamp(r.left, 0, window.innerWidth - FONT_SIZE_PX) - r.left;
3962
+ }
3963
+ if (left !== this.lastLeft) {
3964
+ this.element.style.left = "".concat(left, "px");
3965
+ this.lastLeft = left;
3966
+ }
3967
+ if (top !== this.lastTop) {
3968
+ this.element.style.top = "".concat(top, "px");
3969
+ this.lastTop = top;
3970
+ }
3971
+ };
3972
+ /**
3973
+ * Forward the field's text to Rive and clear it.
3974
+ *
3975
+ * TODO: iOS won't autorepeat Backspace in an empty field (needs a text mirror).
3976
+ * */
3977
+ TextInputProxy.prototype.commit = function () {
3978
+ var text = this.element.value;
3979
+ if (!text)
3980
+ return;
3981
+ this.element.value = "";
3982
+ this.params.textInput(text);
3983
+ };
3984
+ /** Clear any transient value and decoration. Does not blur the element. */
3985
+ TextInputProxy.prototype.endSession = function () {
3986
+ this.element.value = "";
3987
+ // Browsers fire compositionend on blur, but a stuck flag would drop every
3988
+ // keystroke of the next session.
3989
+ this.composing = false;
3990
+ // Also covers blur-out, which bypasses the overlay.
3991
+ this.resetDecoration();
3992
+ };
3993
+ /** Must be called synchronously inside a gesture on iOS to raise the keyboard. */
3994
+ TextInputProxy.prototype.focus = function () {
3995
+ // Reposition first: iOS scrolls the focused input into view when the keyboard opens.
3996
+ this.positionOverCanvas();
3997
+ this.element.focus({ preventScroll: true });
3998
+ };
3999
+ TextInputProxy.prototype.hasDomFocus = function () {
4000
+ return document.activeElement === this.element;
4001
+ };
4002
+ TextInputProxy.prototype.owns = function (target) {
4003
+ return target === this.element;
4004
+ };
4005
+ /** See EditingHost.decorate. */
4006
+ TextInputProxy.prototype.decorate = function (attrs) {
4007
+ // aria-hidden outranks every attribute set below, so it must come off before this
4008
+ // element can stand in as the accessible element for the focused node.
4009
+ this.element.removeAttribute("aria-hidden");
4010
+ for (var _i = 0, _a = Object.entries(attrs); _i < _a.length; _i++) {
4011
+ var _b = _a[_i], name_1 = _b[0], value = _b[1];
4012
+ // Never override capture attrs.
4013
+ if (PROTECTED_ATTRS.has(name_1.toLowerCase()))
4014
+ continue;
4015
+ if (value === null) {
4016
+ this.element.removeAttribute(name_1);
4017
+ this.decoratedKeys.delete(name_1);
4018
+ }
4019
+ else {
4020
+ // Skip no-op writes: setting an attribute to the value it already has still
4021
+ // emits a mutation, and assistive tech is focused on this element mid-edit.
4022
+ if (this.element.getAttribute(name_1) !== value) {
4023
+ this.element.setAttribute(name_1, value);
4024
+ }
4025
+ this.decoratedKeys.add(name_1);
4026
+ }
4027
+ }
4028
+ };
4029
+ /**
4030
+ * type=password for obscured fields so AT doesn't echo keys.
4031
+ * TODO: source "type" from Core, not semantics.
4032
+ */
4033
+ TextInputProxy.prototype.setSecure = function (secure) {
4034
+ var type = secure ? "password" : "text";
4035
+ if (this.element.type !== type)
4036
+ this.element.type = type;
4037
+ };
4038
+ /** Drop all decoration and return to the AT-invisible baseline. */
4039
+ TextInputProxy.prototype.resetDecoration = function () {
4040
+ var _this = this;
4041
+ this.setSecure(false);
4042
+ this.decoratedKeys.forEach(function (name) { return _this.element.removeAttribute(name); });
4043
+ this.decoratedKeys.clear();
4044
+ this.element.setAttribute("aria-hidden", "true");
4045
+ };
4046
+ TextInputProxy.prototype.cleanup = function () {
4047
+ for (var _i = 0, _a = this.listeners(); _i < _a.length; _i++) {
4048
+ var _b = _a[_i], type = _b[0], listener = _b[1];
4049
+ this.element.removeEventListener(type, listener);
4050
+ }
4051
+ this.element.remove();
4052
+ };
4053
+ return TextInputProxy;
4054
+ }());
4055
+
4056
+ function clamp(v, min, max) {
4057
+ return Math.min(Math.max(v, min), Math.max(min, max));
4058
+ }
4059
+
4060
+
4061
+ /***/ }),
4062
+ /* 17 */
2970
4063
  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
2971
4064
 
2972
4065
  __webpack_require__.r(__webpack_exports__);
@@ -3019,7 +4112,7 @@ function sanitizeUrl(url) {
3019
4112
 
3020
4113
 
3021
4114
  /***/ }),
3022
- /* 14 */
4115
+ /* 18 */
3023
4116
  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
3024
4117
 
3025
4118
  __webpack_require__.r(__webpack_exports__);
@@ -3319,7 +4412,7 @@ var createFinalization = function (target, finalizable) {
3319
4412
 
3320
4413
 
3321
4414
  /***/ }),
3322
- /* 15 */
4415
+ /* 19 */
3323
4416
  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
3324
4417
 
3325
4418
  __webpack_require__.r(__webpack_exports__);
@@ -3491,7 +4584,7 @@ __webpack_require__.r(__webpack_exports__);
3491
4584
  /* harmony import */ var _animation__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
3492
4585
  /* harmony import */ var _runtimeLoader__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3);
3493
4586
  /* harmony import */ var _semantics__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6);
3494
- /* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(10);
4587
+ /* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(12);
3495
4588
  var __extends = (undefined && undefined.__extends) || (function () {
3496
4589
  var extendStatics = function (d, b) {
3497
4590
  extendStatics = Object.setPrototypeOf ||
@@ -5379,6 +6472,10 @@ var Rive = /** @class */ (function () {
5379
6472
  this._dataEnums = null;
5380
6473
  this._tabIndex = null;
5381
6474
  this._prevHasFocus = false;
6475
+ this._prevWantsTextInputSession = false;
6476
+ // Pointer-down defers the proxy focus: mousedown's default would refocus the canvas and
6477
+ // touchstart isn't user activation; pointer-up focuses it.
6478
+ this._inPointerDownDrain = false;
5382
6479
  this._focusOptions = {
5383
6480
  allowFocusInterrupt: false,
5384
6481
  };
@@ -5414,6 +6511,7 @@ var Rive = /** @class */ (function () {
5414
6511
  _this.resizeToCanvas();
5415
6512
  }
5416
6513
  };
6514
+ this.isEditingHostFocused = function () { var _a, _b; return (_b = (_a = _this._keyboardInteractions) === null || _a === void 0 ? void 0 : _a.isEditingHostFocused()) !== null && _b !== void 0 ? _b : false; };
5417
6515
  // Tracks the current animation frame request
5418
6516
  this.frameRequestId = null;
5419
6517
  /**
@@ -5734,11 +6832,21 @@ var Rive = /** @class */ (function () {
5734
6832
  dispatchPointerExit: dispatchPointerExit,
5735
6833
  enableMultiTouch: enableMultiTouch,
5736
6834
  layoutScaleFactor: this._layout.layoutScaleFactor,
5737
- advanceAndDrain: this.advanceAndReportChanges.bind(this)
6835
+ advanceAndDrain: this.advanceAndDrainForPointer.bind(this),
6836
+ summonKeyboard: this.summonKeyboardForGesture.bind(this),
6837
+ isTextProxyFocused: this.isEditingHostFocused,
5738
6838
  });
5739
6839
  this.ensureKeyboardInteractions();
5740
6840
  }
5741
6841
  };
6842
+ Object.defineProperty(Rive.prototype, "focusStateMachine", {
6843
+ // Assumes a single state machine drives focus.
6844
+ get: function () {
6845
+ return this.animator.stateMachines.find(function (sm) { return sm.playing && sm.hasFocusNodes; });
6846
+ },
6847
+ enumerable: false,
6848
+ configurable: true
6849
+ });
5742
6850
  /**
5743
6851
  * Wire keyboard interactions when a playing state machine has focus nodes.
5744
6852
  * Called at listener setup and lazily each frame so late-bound bindable artboards work.
@@ -5751,7 +6859,7 @@ var Rive = /** @class */ (function () {
5751
6859
  !(this.canvas instanceof HTMLCanvasElement)) {
5752
6860
  return;
5753
6861
  }
5754
- var smWithFocusNodes = this.animator.stateMachines.find(function (sm) { return sm.playing && sm.hasFocusNodes; });
6862
+ var smWithFocusNodes = this.focusStateMachine;
5755
6863
  if (!smWithFocusNodes) {
5756
6864
  return;
5757
6865
  }
@@ -5761,16 +6869,51 @@ var Rive = /** @class */ (function () {
5761
6869
  }
5762
6870
  this._keyboardInteractions = new _utils__WEBPACK_IMPORTED_MODULE_3__.KeyboardInteractions({
5763
6871
  canvas: this.canvas,
5764
- stateMachine: smWithFocusNodes.instance, // work off assumption of single state machine
6872
+ stateMachine: smWithFocusNodes.instance,
5765
6873
  hasFocusNodes: true,
5766
6874
  getOverlayElement: function () { var _a, _b; return (_b = (_a = _this._accessibilityOverlay) === null || _a === void 0 ? void 0 : _a.getSemanticOverlayContainer()) !== null && _b !== void 0 ? _b : null; },
5767
6875
  });
5768
6876
  };
6877
+ /** Runs inside touchend/mouseup so focusing the proxy raises the mobile keyboard. */
6878
+ Rive.prototype.summonKeyboardForGesture = function () {
6879
+ if (!this._keyboardInteractions)
6880
+ return;
6881
+ var activeSm = this.focusStateMachine;
6882
+ if (!activeSm)
6883
+ return;
6884
+ if (this.wantsTextInputSession(activeSm.focusState().expectsKeyboardInput)) {
6885
+ this._keyboardInteractions.summonForPointer();
6886
+ }
6887
+ };
6888
+ /** expectsKeyboardInput, and (with semantics on) the focused node is a textField. */
6889
+ Rive.prototype.wantsTextInputSession = function (expectsKeyboardInput) {
6890
+ var _a;
6891
+ if (!expectsKeyboardInput)
6892
+ return false;
6893
+ var node = (_a = this._semanticTree) === null || _a === void 0 ? void 0 : _a.focusedNode();
6894
+ return node === undefined || node.role === _semantics__WEBPACK_IMPORTED_MODULE_2__.SemanticRole.textField;
6895
+ };
6896
+ Rive.prototype.advanceAndDrainForPointer = function (elapsedTime, options) {
6897
+ if (!(options === null || options === void 0 ? void 0 : options.pointerDown)) {
6898
+ this.advanceAndReportChanges(elapsedTime);
6899
+ return;
6900
+ }
6901
+ this._inPointerDownDrain = true;
6902
+ try {
6903
+ this.advanceAndReportChanges(elapsedTime);
6904
+ }
6905
+ finally {
6906
+ this._inPointerDownDrain = false;
6907
+ }
6908
+ };
5769
6909
  Rive.prototype.cleanupKeyboardInteractions = function () {
6910
+ var _a;
5770
6911
  if (this._keyboardInteractions) {
5771
6912
  this._keyboardInteractions.cleanup();
5772
6913
  this._keyboardInteractions = null;
5773
6914
  }
6915
+ this._prevWantsTextInputSession = false;
6916
+ (_a = this._accessibilityOverlay) === null || _a === void 0 ? void 0 : _a.releaseEditingHost(null, null);
5774
6917
  };
5775
6918
  /**
5776
6919
  * Remove Rive Listeners setup on the canvas
@@ -6106,56 +7249,69 @@ var Rive = /** @class */ (function () {
6106
7249
  var _a, _b, _c;
6107
7250
  return (_c = (_b = (_a = this.riveFile) === null || _a === void 0 ? void 0 : _a.deferredSession) === null || _b === void 0 ? void 0 : _b.recordedThisFrame()) !== null && _c !== void 0 ? _c : false;
6108
7251
  };
6109
- /**
6110
- * Poll focus state each frame to see if we should focus/blur the canvas in case
6111
- * Rive internally updated focus outside of user interaction (e.g., via listener action)
6112
- */
7252
+ /** Rive can move focus on its own, so reconcile the text session and DOM focus each frame. */
6113
7253
  Rive.prototype.pollFocusState = function () {
6114
- var _a, _b;
6115
7254
  this.ensureKeyboardInteractions();
6116
- if (!this._keyboardInteractions) {
7255
+ var ki = this._keyboardInteractions;
7256
+ var activeSm = ki ? this.focusStateMachine : undefined;
7257
+ if (!ki || !activeSm || !(this.canvas instanceof HTMLCanvasElement)) {
6117
7258
  this._prevHasFocus = false;
7259
+ this._prevWantsTextInputSession = false;
6118
7260
  return;
6119
7261
  }
6120
- var activeSm = this.animator.stateMachines.find(function (sm) { return sm.playing && sm.hasFocusNodes; }); // work off assumption of single state machine
6121
- if (!activeSm) {
6122
- this._prevHasFocus = false;
6123
- return;
7262
+ var _a = activeSm.focusState(), hasFocus = _a.hasFocus, expectsKeyboardInput = _a.expectsKeyboardInput;
7263
+ this.syncTextInputSession(ki, this.wantsTextInputSession(expectsKeyboardInput));
7264
+ this.syncRiveFocus(ki, this.canvas, hasFocus);
7265
+ };
7266
+ /** Begin/end the text session on wantsSession edges; decorate the proxy while it has DOM focus. */
7267
+ Rive.prototype.syncTextInputSession = function (ki, wantsSession) {
7268
+ var host = ki.editingHost;
7269
+ var overlay = this._accessibilityOverlay;
7270
+ if (wantsSession) {
7271
+ var began = !this._prevWantsTextInputSession;
7272
+ if (began) {
7273
+ // In-domain or opted-in only; during pointer-down, pointer-up focuses instead.
7274
+ var focusProxy = !this._inPointerDownDrain &&
7275
+ (ki.isInFocusDomain(document.activeElement) ||
7276
+ !!this._focusOptions.allowFocusInterrupt);
7277
+ ki.beginTextInputSession(focusProxy);
7278
+ }
7279
+ // The <input> proxy stands in for the semantic DOM field only while it holds DOM focus.
7280
+ if (overlay && this._semanticTree) {
7281
+ if (host.hasDomFocus()) {
7282
+ overlay.syncEditingHost(this._semanticTree, host, began || !overlay.hasEditingHost());
7283
+ }
7284
+ else if (overlay.hasEditingHost()) {
7285
+ overlay.releaseEditingHost(this._semanticTree, host);
7286
+ }
7287
+ }
6124
7288
  }
6125
- if (this.canvas instanceof HTMLCanvasElement) {
6126
- var hasFocus = activeSm.focusState().hasFocus;
6127
- if (hasFocus) {
6128
- // Rive has an active focus node. Mark the session RiveFocused so Tab stays
6129
- // trapped and a later internal release (hasFocus true → false) is detected.
6130
- this._keyboardInteractions.notifyRiveFocused();
6131
- // Only steal DOM focus on the false→true transition. Rive can hold focus across
6132
- // frames while DOM focus sits elsewhere — a window switch preserves runtime focus
6133
- // by design — and that must not re-focus the canvas again.
6134
- if (!this._prevHasFocus) {
6135
- // Steal DOM focus to the canvas only when focus isn't already held
6136
- // somewhere inside this instance's focus scope. When the accessibility
6137
- // overlay has driven focus onto a specific semantic node element (e.g.
6138
- // an appearing alert dialog), focus is already in-scope. The steal
6139
- // stays a fallback for runtime focus nodes that have no overlay element
6140
- // to hold DOM focus.
6141
- var scope = (_a = this._accessibilityOverlay) === null || _a === void 0 ? void 0 : _a.getSemanticOverlayContainer();
6142
- var focusAlreadyInScope = document.activeElement === this.canvas ||
6143
- ((_b = scope === null || scope === void 0 ? void 0 : scope.contains(document.activeElement)) !== null && _b !== void 0 ? _b : false);
6144
- if (!focusAlreadyInScope && this._focusOptions.allowFocusInterrupt) {
6145
- this.canvas.focus();
6146
- }
6147
- this._prevHasFocus = true;
7289
+ else if (this._prevWantsTextInputSession) {
7290
+ // Overlay hand-off first, ahead of endTextInputSession's park-on-canvas fallback.
7291
+ overlay === null || overlay === void 0 ? void 0 : overlay.releaseEditingHost(this._semanticTree, host);
7292
+ ki.endTextInputSession();
7293
+ }
7294
+ this._prevWantsTextInputSession = wantsSession;
7295
+ };
7296
+ /** Mirror Rive's hasFocus into the keyboard session state and, on opt-in, canvas focus. */
7297
+ Rive.prototype.syncRiveFocus = function (ki, canvas, hasFocus) {
7298
+ if (hasFocus) {
7299
+ ki.notifyRiveFocused();
7300
+ // Pull focus from outside Rive only with allowFocusInterrupt.
7301
+ if (!this._prevHasFocus) {
7302
+ if (!ki.isInFocusDomain(document.activeElement) &&
7303
+ this._focusOptions.allowFocusInterrupt) {
7304
+ canvas.focus();
6148
7305
  }
6149
- return;
7306
+ this._prevHasFocus = true;
6150
7307
  }
7308
+ }
7309
+ else {
6151
7310
  this._prevHasFocus = false;
6152
- // hasFocus is false — only act when Rive previously held focus and released it internally
6153
- // (state change clears focus). Release the DOM Tab trap so the next Tab moves to the next
6154
- // page element. A DOM blur reaches here too now that onCanvasBlur clears Rive focus, but it
6155
- // has already set NotFocused, so this is a no-op. EntryPending and NotFocused are likewise
6156
- // intentional no-ops — EntryPending must stay put (a click awaiting its first Tab).
6157
- if (this._keyboardInteractions.focusSessionState === _utils__WEBPACK_IMPORTED_MODULE_3__.FocusSessionState.RiveFocused) {
6158
- this._keyboardInteractions.setFocusSessionState(_utils__WEBPACK_IMPORTED_MODULE_3__.FocusSessionState.NotFocused);
7311
+ // Rive released focus internally (e.g. a state change): drop the Tab trap so the next
7312
+ // Tab leaves the canvas.
7313
+ if (ki.focusSessionState === _utils__WEBPACK_IMPORTED_MODULE_3__.FocusSessionState.RiveFocused) {
7314
+ ki.setFocusSessionState(_utils__WEBPACK_IMPORTED_MODULE_3__.FocusSessionState.NotFocused);
6159
7315
  }
6160
7316
  }
6161
7317
  };
@@ -6253,6 +7409,7 @@ var Rive = /** @class */ (function () {
6253
7409
  instanceId: this._instanceId,
6254
7410
  semanticsOptions: this.semanticsOptions,
6255
7411
  allowFocusInterrupt: this._focusOptions.allowFocusInterrupt,
7412
+ isEditingHostFocused: this.isEditingHostFocused,
6256
7413
  fireAction: function (nodeId, actionType) {
6257
7414
  mainSm_1.fireSemanticAction(nodeId, actionType);
6258
7415
  },
@@ -6837,7 +7994,7 @@ var Rive = /** @class */ (function () {
6837
7994
  this.canvas.height = dpr * height;
6838
7995
  this._needsRedraw = true;
6839
7996
  this.resizeToCanvas();
6840
- if (this.layout.fit === Fit.Layout) {
7997
+ if (this.layout.fit === Fit.Layout && this.artboard) {
6841
7998
  var scaleFactor = this._layout.layoutScaleFactor;
6842
7999
  this.artboard.width = width / scaleFactor;
6843
8000
  this.artboard.height = height / scaleFactor;