wulf.js 2.1.1 → 2.2.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.
Files changed (146) hide show
  1. package/README.md +217 -11
  2. package/changelog.md +50 -0
  3. package/dist/anchor.esm.js +9 -0
  4. package/dist/anchor.esm.js.map +7 -0
  5. package/dist/anchor.global.js +695 -0
  6. package/dist/anchor.global.js.map +7 -0
  7. package/dist/anchor.global.min.js +6 -0
  8. package/dist/anchor.global.min.js.map +7 -0
  9. package/dist/autosize.css +1 -0
  10. package/dist/autosize.css.map +7 -0
  11. package/dist/autosize.esm.js +10 -0
  12. package/dist/autosize.esm.js.map +7 -0
  13. package/dist/autosize.global.js +657 -0
  14. package/dist/autosize.global.js.map +7 -0
  15. package/dist/autosize.global.min.js +6 -0
  16. package/dist/autosize.global.min.js.map +7 -0
  17. package/dist/autosize.layered.css +1 -0
  18. package/dist/autosize.layered.css.map +7 -0
  19. package/dist/chunks/chunk-22AIMRD5.js +119 -0
  20. package/dist/chunks/chunk-22AIMRD5.js.map +7 -0
  21. package/dist/chunks/chunk-5N2IRGDM.js +766 -0
  22. package/dist/chunks/chunk-5N2IRGDM.js.map +7 -0
  23. package/dist/chunks/chunk-72FVCNNZ.js +863 -0
  24. package/dist/chunks/chunk-72FVCNNZ.js.map +7 -0
  25. package/dist/chunks/chunk-AXZYYW7H.js +865 -0
  26. package/dist/chunks/chunk-AXZYYW7H.js.map +7 -0
  27. package/dist/chunks/chunk-CM3SBIVQ.js +1116 -0
  28. package/dist/chunks/chunk-CM3SBIVQ.js.map +7 -0
  29. package/dist/chunks/chunk-H4GRLGQ3.js +578 -0
  30. package/dist/chunks/chunk-H4GRLGQ3.js.map +7 -0
  31. package/dist/chunks/chunk-ITRU2RFV.js +1195 -0
  32. package/dist/chunks/chunk-ITRU2RFV.js.map +7 -0
  33. package/dist/chunks/chunk-NLUQZEL4.js +1029 -0
  34. package/dist/chunks/chunk-NLUQZEL4.js.map +7 -0
  35. package/dist/chunks/chunk-QV46A7FV.js +197 -0
  36. package/dist/chunks/chunk-QV46A7FV.js.map +7 -0
  37. package/dist/chunks/chunk-SXLUXN6W.js +612 -0
  38. package/dist/chunks/chunk-SXLUXN6W.js.map +7 -0
  39. package/dist/chunks/chunk-T2H4EJCW.js +621 -0
  40. package/dist/chunks/chunk-T2H4EJCW.js.map +7 -0
  41. package/dist/chunks/chunk-TILLYEF2.js +6044 -0
  42. package/dist/chunks/chunk-TILLYEF2.js.map +7 -0
  43. package/dist/chunks/chunk-VJO22BAT.js +72 -0
  44. package/dist/chunks/chunk-VJO22BAT.js.map +7 -0
  45. package/dist/chunks/chunk-ZGUU6DMM.js +77 -0
  46. package/dist/chunks/chunk-ZGUU6DMM.js.map +7 -0
  47. package/dist/focus-trap.esm.js +6 -594
  48. package/dist/focus-trap.esm.js.map +3 -3
  49. package/dist/focus-trap.global.js +176 -61
  50. package/dist/focus-trap.global.js.map +3 -3
  51. package/dist/focus-trap.global.min.js +4 -4
  52. package/dist/focus-trap.global.min.js.map +4 -4
  53. package/dist/index.esm.js +79 -10448
  54. package/dist/index.esm.js.map +4 -4
  55. package/dist/index.global.js +3660 -202
  56. package/dist/index.global.js.map +4 -4
  57. package/dist/index.global.min.js +6 -3
  58. package/dist/index.global.min.js.map +4 -4
  59. package/dist/mask.esm.js +16 -6094
  60. package/dist/mask.esm.js.map +4 -4
  61. package/dist/mask.global.js +44 -55
  62. package/dist/mask.global.js.map +3 -3
  63. package/dist/mask.global.min.js +3 -3
  64. package/dist/mask.global.min.js.map +4 -4
  65. package/dist/masonry.esm.js +15 -1158
  66. package/dist/masonry.esm.js.map +4 -4
  67. package/dist/masonry.global.js +84 -94
  68. package/dist/masonry.global.js.map +3 -3
  69. package/dist/masonry.global.min.js +4 -4
  70. package/dist/masonry.global.min.js.map +4 -4
  71. package/dist/scroll.css +1 -1
  72. package/dist/scroll.css.map +2 -2
  73. package/dist/scroll.esm.js +14 -1252
  74. package/dist/scroll.esm.js.map +3 -3
  75. package/dist/scroll.global.js +64 -58
  76. package/dist/scroll.global.js.map +3 -3
  77. package/dist/scroll.global.min.js +3 -3
  78. package/dist/scroll.global.min.js.map +4 -4
  79. package/dist/scroll.layered.css +1 -1
  80. package/dist/scroll.layered.css.map +2 -2
  81. package/dist/shortcut.esm.js +6 -901
  82. package/dist/shortcut.esm.js.map +4 -4
  83. package/dist/shortcut.global.js +43 -36
  84. package/dist/shortcut.global.js.map +3 -3
  85. package/dist/shortcut.global.min.js +6 -3
  86. package/dist/shortcut.global.min.js.map +4 -4
  87. package/dist/size-report.json +319 -0
  88. package/dist/sortable.css +1 -0
  89. package/dist/sortable.css.map +7 -0
  90. package/dist/sortable.esm.js +22 -0
  91. package/dist/sortable.esm.js.map +7 -0
  92. package/dist/sortable.global.js +1477 -0
  93. package/dist/sortable.global.js.map +7 -0
  94. package/dist/sortable.global.min.js +6 -0
  95. package/dist/sortable.global.min.js.map +7 -0
  96. package/dist/sortable.layered.css +1 -0
  97. package/dist/sortable.layered.css.map +7 -0
  98. package/dist/sri-manifest.json +64 -0
  99. package/dist/toast.css +1 -1
  100. package/dist/toast.css.map +2 -2
  101. package/dist/toast.esm.js +19 -1208
  102. package/dist/toast.esm.js.map +3 -3
  103. package/dist/toast.global.js +314 -111
  104. package/dist/toast.global.js.map +3 -3
  105. package/dist/toast.global.min.js +3 -3
  106. package/dist/toast.global.min.js.map +4 -4
  107. package/dist/toast.layered.css +1 -1
  108. package/dist/toast.layered.css.map +2 -2
  109. package/dist/types/anchor/Anchor.d.ts +41 -0
  110. package/dist/types/anchor/index.d.ts +3 -0
  111. package/dist/types/anchor/types.d.ts +115 -0
  112. package/dist/types/autosize/Autosize.d.ts +71 -0
  113. package/dist/types/autosize/index.d.ts +3 -0
  114. package/dist/types/autosize/types.d.ts +66 -0
  115. package/dist/types/common/AuditableComponent.d.ts +1 -1
  116. package/dist/types/common/registry.d.ts +40 -0
  117. package/dist/types/focus-trap/FocusTrap.d.ts +3 -1
  118. package/dist/types/index.d.ts +13 -1
  119. package/dist/types/scroll/types.d.ts +6 -0
  120. package/dist/types/shortcut/ShortcutManager.d.ts +2 -0
  121. package/dist/types/shortcut/types.d.ts +5 -0
  122. package/dist/types/sortable/Sortable.d.ts +75 -0
  123. package/dist/types/sortable/i18n/en.d.ts +2 -0
  124. package/dist/types/sortable/i18n/fr.d.ts +2 -0
  125. package/dist/types/sortable/i18n/index.d.ts +9 -0
  126. package/dist/types/sortable/i18n/types.d.ts +15 -0
  127. package/dist/types/sortable/index.d.ts +4 -0
  128. package/dist/types/sortable/types.d.ts +112 -0
  129. package/dist/types/toast/Toast.d.ts +6 -1
  130. package/dist/types/toast/ToastInstance.d.ts +7 -0
  131. package/dist/types/toast/ToastManager.d.ts +2 -2
  132. package/dist/types/toast/types.d.ts +27 -1
  133. package/dist/types/undo/UndoManager.d.ts +112 -0
  134. package/dist/types/undo/i18n/en.d.ts +2 -0
  135. package/dist/types/undo/i18n/fr.d.ts +2 -0
  136. package/dist/types/undo/i18n/index.d.ts +9 -0
  137. package/dist/types/undo/i18n/types.d.ts +6 -0
  138. package/dist/types/undo/index.d.ts +5 -0
  139. package/dist/types/undo/types.d.ts +106 -0
  140. package/dist/undo.esm.js +23 -0
  141. package/dist/undo.esm.js.map +7 -0
  142. package/dist/undo.global.js +1029 -0
  143. package/dist/undo.global.js.map +7 -0
  144. package/dist/undo.global.min.js +6 -0
  145. package/dist/undo.global.min.js.map +7 -0
  146. package/package.json +54 -5
@@ -0,0 +1,1029 @@
1
+ "use strict";
2
+ var __WulfIIFE = (() => {
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/undo/index.ts
22
+ var index_exports = {};
23
+ __export(index_exports, {
24
+ LocalizedComponent: () => LocalizedComponent,
25
+ Undo: () => UndoManager,
26
+ UndoManager: () => UndoManager,
27
+ createI18nManager: () => createI18nManager,
28
+ default: () => UndoManager,
29
+ undoEn: () => undoEn,
30
+ undoFr: () => undoFr,
31
+ undoI18n: () => undoI18n
32
+ });
33
+
34
+ // src/common/i18n.ts
35
+ var FORBIDDEN_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
36
+ function isSafeKey(key) {
37
+ return Boolean(key) && !FORBIDDEN_KEYS.has(key);
38
+ }
39
+ function normalizeLocaleCode(locale) {
40
+ const norm = String(locale ?? "").trim().toLowerCase().replace(/_/g, "-");
41
+ return isSafeKey(norm) ? norm : "";
42
+ }
43
+ function getPrimaryLanguage(normalizedLocale) {
44
+ const dashIndex = normalizedLocale.indexOf("-");
45
+ const primary = dashIndex > 0 ? normalizedLocale.slice(0, dashIndex) : null;
46
+ return primary && isSafeKey(primary) ? primary : null;
47
+ }
48
+ function assignDefined(target, source) {
49
+ if (!source || typeof source !== "object") return target;
50
+ for (const key of Object.keys(source)) {
51
+ if (isSafeKey(String(key)) && Object.hasOwn(source, key) && source[key] !== void 0) {
52
+ target[key] = source[key];
53
+ }
54
+ }
55
+ return target;
56
+ }
57
+ function createI18nManager(defaultLocale, locales) {
58
+ const fallbackLocale = normalizeLocaleCode(defaultLocale) || "fr";
59
+ const initialLocales = /* @__PURE__ */ Object.create(null);
60
+ for (const [loc, dict] of Object.entries(locales)) {
61
+ const norm = normalizeLocaleCode(loc);
62
+ if (norm) {
63
+ initialLocales[norm] = assignDefined(/* @__PURE__ */ Object.create(null), dict);
64
+ }
65
+ }
66
+ let currentLocale = fallbackLocale;
67
+ let activeLocales = /* @__PURE__ */ Object.create(null);
68
+ for (const [loc, dict] of Object.entries(initialLocales)) {
69
+ activeLocales[loc] = assignDefined(/* @__PURE__ */ Object.create(null), dict);
70
+ }
71
+ let globalOverrides = /* @__PURE__ */ Object.create(null);
72
+ function resolveActiveDictionaries() {
73
+ const dicts = [];
74
+ if (isSafeKey(currentLocale)) {
75
+ const exact = activeLocales[currentLocale];
76
+ if (exact) dicts.push(exact);
77
+ }
78
+ const primary = getPrimaryLanguage(currentLocale);
79
+ if (primary && activeLocales[primary]) {
80
+ dicts.push(activeLocales[primary]);
81
+ }
82
+ return dicts;
83
+ }
84
+ return {
85
+ setLocale(locale) {
86
+ if (locale && typeof locale === "string" && locale.trim()) {
87
+ const norm = normalizeLocaleCode(locale);
88
+ if (norm) {
89
+ currentLocale = norm;
90
+ }
91
+ }
92
+ },
93
+ getLocale() {
94
+ return currentLocale;
95
+ },
96
+ registerLocale(locale, translations) {
97
+ if (!locale || typeof locale !== "string" || !locale.trim() || !translations) return;
98
+ const norm = normalizeLocaleCode(locale);
99
+ if (!norm) return;
100
+ const base = assignDefined(/* @__PURE__ */ Object.create(null), activeLocales[norm]);
101
+ activeLocales[norm] = assignDefined(base, translations);
102
+ },
103
+ setI18n(overrides) {
104
+ if (!overrides || typeof overrides !== "object") return;
105
+ const base = assignDefined(/* @__PURE__ */ Object.create(null), globalOverrides);
106
+ globalOverrides = assignDefined(base, overrides);
107
+ },
108
+ t(key, instanceOverride) {
109
+ if (!isSafeKey(String(key))) {
110
+ return "";
111
+ }
112
+ if (instanceOverride && typeof instanceOverride === "object" && Object.hasOwn(instanceOverride, key) && instanceOverride[key] !== void 0) {
113
+ return String(instanceOverride[key]);
114
+ }
115
+ if (globalOverrides[key] !== void 0) {
116
+ return String(globalOverrides[key]);
117
+ }
118
+ for (const dict of resolveActiveDictionaries()) {
119
+ if (dict[key] !== void 0) {
120
+ return String(dict[key]);
121
+ }
122
+ }
123
+ const fallbackDict = activeLocales[fallbackLocale] || initialLocales[fallbackLocale];
124
+ if (fallbackDict && fallbackDict[key] !== void 0) {
125
+ return String(fallbackDict[key]);
126
+ }
127
+ return String(key);
128
+ },
129
+ getAll(instanceOverride) {
130
+ const result = {};
131
+ const fallback = activeLocales[fallbackLocale] || initialLocales[fallbackLocale];
132
+ assignDefined(result, fallback);
133
+ const activeDicts = resolveActiveDictionaries().reverse();
134
+ for (const dict of activeDicts) {
135
+ assignDefined(result, dict);
136
+ }
137
+ assignDefined(result, globalOverrides);
138
+ assignDefined(result, instanceOverride);
139
+ return result;
140
+ },
141
+ reset() {
142
+ currentLocale = fallbackLocale;
143
+ globalOverrides = /* @__PURE__ */ Object.create(null);
144
+ activeLocales = /* @__PURE__ */ Object.create(null);
145
+ for (const [loc, dict] of Object.entries(initialLocales)) {
146
+ activeLocales[loc] = assignDefined(/* @__PURE__ */ Object.create(null), dict);
147
+ }
148
+ }
149
+ };
150
+ }
151
+
152
+ // src/common/AuditableComponent.ts
153
+ var AuditableComponent = class {
154
+ /**
155
+ * Indication affichée en pied de warning pour expliquer comment désactiver l'audit.
156
+ */
157
+ getAuditDisableHint() {
158
+ return "Passez { audit: false } dans les options pour d\xE9sactiver cet avertissement";
159
+ }
160
+ /**
161
+ * Exécute l'audit d'accessibilité et émet un avertissement standardisé dans la console
162
+ * si l'audit est activé et que des contraintes manquent.
163
+ */
164
+ runAuditWarning(enabled = true) {
165
+ if (!enabled) return [];
166
+ const warnings = this.audit();
167
+ if (warnings.length > 0 && typeof console !== "undefined" && typeof console.warn === "function") {
168
+ console.warn(
169
+ `[${this.getAuditPrefix()}] Audit d'accessibilit\xE9 \u2014 ${warnings.length} contrainte(s) manquante(s) sur ${this.getAuditTargetLabel()} :
170
+ ` + warnings.map((w) => ` - ${w}`).join("\n") + `
171
+ (${this.getAuditDisableHint()})`
172
+ );
173
+ }
174
+ return warnings;
175
+ }
176
+ /**
177
+ * Vérifie si un attribut de référence d'IDs ARIA (ex: aria-labelledby, aria-describedby, aria-errormessage)
178
+ * pointe vers des éléments réellement présents dans le document (et optionnellement non vides).
179
+ */
180
+ checkAriaIdReferences(element, attrName, warnings, requireNonEmptyText = false) {
181
+ const rawValue = element.getAttribute(attrName)?.trim();
182
+ if (!rawValue) return false;
183
+ const doc = element.ownerDocument || document;
184
+ const root = typeof element.getRootNode === "function" ? element.getRootNode() : doc;
185
+ const ids = rawValue.split(/\s+/).filter(Boolean);
186
+ const targets = ids.map(
187
+ (id) => typeof ShadowRoot !== "undefined" && root instanceof ShadowRoot ? root.getElementById(id) : doc.getElementById(id)
188
+ );
189
+ const allFound = ids.length > 0 && targets.every((el) => Boolean(el));
190
+ if (!allFound) {
191
+ warnings.push(
192
+ `Attribut ${attrName}="${rawValue}" invalide : l'\xE9l\xE9ment cible est introuvable dans le DOM.`
193
+ );
194
+ return false;
195
+ }
196
+ if (requireNonEmptyText) {
197
+ const hasNonEmptyText = targets.some((el) => {
198
+ if (!el) return false;
199
+ const text = el.textContent?.trim() || el.getAttribute("aria-label")?.trim() || "";
200
+ return text.length > 0;
201
+ });
202
+ if (!hasNonEmptyText) {
203
+ warnings.push(
204
+ `Attribut ${attrName}="${rawValue}" invalide : l'\xE9l\xE9ment cible ne contient aucun texte accessible.`
205
+ );
206
+ return false;
207
+ }
208
+ }
209
+ return true;
210
+ }
211
+ };
212
+
213
+ // src/common/LocalizedComponent.ts
214
+ var LocalizedComponent = class extends AuditableComponent {
215
+ static _i18n;
216
+ /**
217
+ * Définit la langue globale du composant (ex: 'fr', 'en', 'es').
218
+ */
219
+ static setLocale(locale) {
220
+ if (this._i18n) {
221
+ this._i18n.setLocale(locale);
222
+ }
223
+ }
224
+ /**
225
+ * Retourne la langue globale active du composant.
226
+ */
227
+ static getLocale() {
228
+ return this._i18n ? this._i18n.getLocale() : "";
229
+ }
230
+ /**
231
+ * Enregistre un dictionnaire de traduction pour une langue donnée.
232
+ */
233
+ static registerLocale(locale, translations) {
234
+ if (this._i18n) {
235
+ this._i18n.registerLocale(locale, translations);
236
+ }
237
+ }
238
+ /**
239
+ * Surcharge les libellés globalement pour ce composant.
240
+ */
241
+ static setI18n(overrides) {
242
+ if (this._i18n) {
243
+ this._i18n.setI18n(overrides);
244
+ }
245
+ }
246
+ /**
247
+ * Retourne l'ensemble des libellés actifs résolus du composant.
248
+ */
249
+ static getI18n() {
250
+ return this._i18n ? this._i18n.getAll() : {};
251
+ }
252
+ /**
253
+ * Réinitialise les réglages de langue et surcharges globales.
254
+ */
255
+ static resetI18n() {
256
+ if (this._i18n) {
257
+ this._i18n.reset();
258
+ }
259
+ }
260
+ /**
261
+ * Résout une clé au niveau statique de la classe.
262
+ */
263
+ static t(key, instanceOverride) {
264
+ return this._i18n ? this._i18n.t(key, instanceOverride) : String(key);
265
+ }
266
+ /**
267
+ * Surcharges de localisation spécifiques à cette instance.
268
+ */
269
+ i18nOverrides;
270
+ constructor(i18nOverrides) {
271
+ super();
272
+ this.i18nOverrides = i18nOverrides;
273
+ }
274
+ /**
275
+ * Traduit une clé en tenant compte automatiquement des surcharges de l'instance courante.
276
+ */
277
+ t(key) {
278
+ const ctor = this.constructor;
279
+ return ctor._i18n ? ctor._i18n.t(key, this.i18nOverrides) : String(key);
280
+ }
281
+ };
282
+
283
+ // src/undo/i18n/fr.ts
284
+ var undoFr = {
285
+ undone: (label) => label ? `Action annul\xE9e : ${label}` : "Action annul\xE9e.",
286
+ redone: (label) => label ? `Action r\xE9tablie : ${label}` : "Action r\xE9tablie.",
287
+ nothingToUndo: "Aucune action \xE0 annuler.",
288
+ nothingToRedo: "Aucune action \xE0 r\xE9tablir."
289
+ };
290
+
291
+ // src/undo/i18n/en.ts
292
+ var undoEn = {
293
+ undone: (label) => label ? `Undone: ${label}` : "Action undone.",
294
+ redone: (label) => label ? `Redone: ${label}` : "Action redone.",
295
+ nothingToUndo: "Nothing to undo.",
296
+ nothingToRedo: "Nothing to redo."
297
+ };
298
+
299
+ // src/undo/i18n/index.ts
300
+ var undoI18n = createI18nManager("fr", {
301
+ fr: undoFr,
302
+ en: undoEn
303
+ });
304
+
305
+ // src/common/dom.ts
306
+ function stripBidiAndInvisibles(raw, maxLength = 4096) {
307
+ const safeLimit = Math.max(0, maxLength);
308
+ return String(raw ?? "").slice(0, safeLimit).replace(/[\u061C\u200B-\u200F\u202A-\u202E\u2066-\u2069\uFEFF]/g, "");
309
+ }
310
+ function isImeComposing(event) {
311
+ return Boolean(
312
+ event.isComposing || event.key === "Process" || event.key === "Enter" && event.keyCode === 229
313
+ );
314
+ }
315
+
316
+ // src/undo/UndoManager.ts
317
+ var SENSITIVE_AUTOCOMPLETE_TOKENS = /* @__PURE__ */ new Set([
318
+ "current-password",
319
+ "new-password",
320
+ "one-time-code",
321
+ "cc-number",
322
+ "cc-csc"
323
+ ]);
324
+ function clampInt(val, fallback, min, max) {
325
+ if (typeof val !== "number" || !Number.isFinite(val)) return fallback;
326
+ return Math.min(max, Math.max(min, Math.floor(val)));
327
+ }
328
+ function nowMs() {
329
+ return typeof performance !== "undefined" && typeof performance.now === "function" ? performance.now() : Date.now();
330
+ }
331
+ function isApplePlatform() {
332
+ if (typeof navigator === "undefined") return false;
333
+ const nav = navigator;
334
+ const plat = nav.userAgentData?.platform || navigator.platform || navigator.userAgent || "";
335
+ return /mac|iphone|ipad|ipod/i.test(plat);
336
+ }
337
+ function isEditableElement(target) {
338
+ if (!target || typeof target.tagName !== "string") return false;
339
+ const el = target;
340
+ const tag = el.tagName.toUpperCase();
341
+ if (tag === "INPUT") {
342
+ const type = el.type?.toLowerCase() || "text";
343
+ return !["button", "checkbox", "radio", "submit", "reset", "range", "color", "file", "image"].includes(type);
344
+ }
345
+ if (tag === "TEXTAREA" || tag === "SELECT") return true;
346
+ const ce = el.getAttribute?.("contenteditable")?.toLowerCase();
347
+ if (el.isContentEditable || ce === "true" || ce === "plaintext-only" || ce === "") {
348
+ return true;
349
+ }
350
+ const role = el.getAttribute?.("role");
351
+ if (role === "textbox" || role === "searchbox" || role === "combobox" || role === "spinbutton") {
352
+ return true;
353
+ }
354
+ return Boolean(
355
+ typeof el.closest === "function" && el.closest(
356
+ '[contenteditable="true"], [contenteditable="plaintext-only"], [contenteditable=""], [role="textbox"], [role="searchbox"], [role="combobox"], [role="spinbutton"]'
357
+ )
358
+ );
359
+ }
360
+ function isSensitiveElement(target) {
361
+ if (!target || typeof target.tagName !== "string") return false;
362
+ const el = target;
363
+ if (el.tagName.toUpperCase() === "INPUT" && (el.type || "").toLowerCase() === "password") {
364
+ return true;
365
+ }
366
+ const sensitiveAttr = el.getAttribute?.("data-mask-sensitive");
367
+ if (sensitiveAttr !== null && sensitiveAttr !== void 0 && sensitiveAttr !== "false") {
368
+ return true;
369
+ }
370
+ const ac = el.getAttribute?.("autocomplete");
371
+ if (ac) {
372
+ const tokens = ac.trim().toLowerCase().split(/\s+/);
373
+ if (tokens.some((tok) => SENSITIVE_AUTOCOMPLETE_TOKENS.has(tok))) {
374
+ return true;
375
+ }
376
+ }
377
+ return false;
378
+ }
379
+ function sanitizeLabel(label) {
380
+ if (typeof label !== "string") return void 0;
381
+ const clean = stripBidiAndInvisibles(label, 256).trim();
382
+ return clean || void 0;
383
+ }
384
+ var UndoManager = class extends LocalizedComponent {
385
+ static _i18n = undoI18n;
386
+ maxDepth;
387
+ coalesceMs;
388
+ cloneStrategy;
389
+ equalsFn;
390
+ keyboardOptions;
391
+ announceEnabled;
392
+ announceRoot;
393
+ langOverride;
394
+ onChange;
395
+ onUndo;
396
+ onRedo;
397
+ onError;
398
+ stack = [];
399
+ index = 0;
400
+ lastPushTime = -Infinity;
401
+ batchDepth = 0;
402
+ batchHasChange = false;
403
+ batchPendingState;
404
+ batchPendingLabel;
405
+ isApplying = false;
406
+ paused = false;
407
+ isDestroyed = false;
408
+ abortController = null;
409
+ bindings = /* @__PURE__ */ new Set();
410
+ srStatusEl = null;
411
+ announceTimerId = null;
412
+ constructor(initialState, options = {}) {
413
+ super(options.i18n);
414
+ this.maxDepth = clampInt(options.maxDepth, 100, 1, 1e4);
415
+ this.coalesceMs = clampInt(options.coalesceMs, 500, 0, 6e4);
416
+ this.cloneStrategy = options.clone ?? "structured";
417
+ this.equalsFn = options.equals;
418
+ this.announceEnabled = options.announce ?? true;
419
+ this.announceRoot = options.announceRoot ?? null;
420
+ this.langOverride = options.lang;
421
+ this.onChange = options.onChange;
422
+ this.onUndo = options.onUndo;
423
+ this.onRedo = options.onRedo;
424
+ this.onError = options.onError;
425
+ if (options.keyboard === false) {
426
+ this.keyboardOptions = null;
427
+ } else if (typeof options.keyboard === "object" && options.keyboard !== null) {
428
+ this.keyboardOptions = { ...options.keyboard };
429
+ } else {
430
+ this.keyboardOptions = {};
431
+ }
432
+ this.stack = [{ state: this.cloneState(initialState), timestamp: nowMs() }];
433
+ this.index = 0;
434
+ this.bindKeyboard();
435
+ this.runAuditWarning(options.audit ?? true);
436
+ }
437
+ /**
438
+ * Empile un nouvel état (ou le fusionne avec le sommet selon `coalesceMs` et `mergeKey`).
439
+ */
440
+ push(nextState, options) {
441
+ if (this.isDestroyed || this.isApplying) {
442
+ return false;
443
+ }
444
+ const cleanLabel = sanitizeLabel(options?.label);
445
+ const cloned = this.cloneState(nextState);
446
+ if (this.batchDepth > 0) {
447
+ this.batchPendingState = cloned;
448
+ this.batchHasChange = true;
449
+ if (cleanLabel && !this.batchPendingLabel) {
450
+ this.batchPendingLabel = cleanLabel;
451
+ }
452
+ return true;
453
+ }
454
+ const currentEntry = this.stack[this.index];
455
+ if (this.equalsFn && currentEntry && this.equalsFn(currentEntry.state, cloned)) {
456
+ return false;
457
+ }
458
+ const previousState = currentEntry.state;
459
+ this.stack.length = this.index + 1;
460
+ const t = nowMs();
461
+ const canCoalesce = options?.coalesce !== false && this.index > 0 && this.coalesceMs > 0 && t - this.lastPushTime <= this.coalesceMs && (options?.mergeKey !== void 0 && currentEntry.mergeKey === options.mergeKey || options?.mergeKey === void 0 && currentEntry.mergeKey === void 0);
462
+ if (canCoalesce) {
463
+ this.stack[this.index] = {
464
+ state: cloned,
465
+ label: cleanLabel ?? currentEntry.label,
466
+ mergeKey: options?.mergeKey,
467
+ timestamp: t
468
+ };
469
+ } else {
470
+ this.stack.push({
471
+ state: cloned,
472
+ label: cleanLabel,
473
+ mergeKey: options?.mergeKey,
474
+ timestamp: t
475
+ });
476
+ this.trimToMaxDepth();
477
+ this.index = this.stack.length - 1;
478
+ }
479
+ this.lastPushTime = t;
480
+ this.syncControls();
481
+ this.notifyCallback(this.onChange, "push", this.stack[this.index].state, previousState, this.stack[this.index].label);
482
+ return true;
483
+ }
484
+ /**
485
+ * Annule la dernière action et restaure l'état précédent.
486
+ */
487
+ undo() {
488
+ if (this.isDestroyed || this.isApplying || !this.canUndo()) {
489
+ return null;
490
+ }
491
+ return this.stepTo(this.index - 1, "undo");
492
+ }
493
+ /**
494
+ * Rétablit l'action suivante dans l'historique.
495
+ */
496
+ redo() {
497
+ if (this.isDestroyed || this.isApplying || !this.canRedo()) {
498
+ return null;
499
+ }
500
+ return this.stepTo(this.index + 1, "redo");
501
+ }
502
+ /**
503
+ * Saute directement à un index précis de la pile d'historique.
504
+ */
505
+ go(targetIndex) {
506
+ if (this.isDestroyed || this.isApplying || !Number.isInteger(targetIndex)) {
507
+ return null;
508
+ }
509
+ if (targetIndex < 0 || targetIndex >= this.stack.length || targetIndex === this.index) {
510
+ return null;
511
+ }
512
+ return this.stepTo(targetIndex, "go");
513
+ }
514
+ /**
515
+ * Regroupe plusieurs `push()` successifs dans une transaction atomique unique.
516
+ * Garantit un rollback complet et la libération du verrou en cas d'exception.
517
+ */
518
+ batch(fn, label) {
519
+ if (this.isDestroyed) {
520
+ return fn();
521
+ }
522
+ const isRoot = this.batchDepth === 0;
523
+ if (isRoot) {
524
+ this.batchHasChange = false;
525
+ this.batchPendingState = void 0;
526
+ this.batchPendingLabel = sanitizeLabel(label);
527
+ } else if (label && !this.batchPendingLabel) {
528
+ this.batchPendingLabel = sanitizeLabel(label);
529
+ }
530
+ this.batchDepth++;
531
+ try {
532
+ const result = fn();
533
+ if (isRoot && this.batchHasChange && this.batchPendingState !== void 0) {
534
+ const pending = this.batchPendingState;
535
+ const pendingLabel = this.batchPendingLabel;
536
+ const currentEntry = this.stack[this.index];
537
+ if (!this.equalsFn || !this.equalsFn(currentEntry.state, pending)) {
538
+ const previousState = currentEntry.state;
539
+ this.stack.length = this.index + 1;
540
+ this.stack.push({
541
+ state: pending,
542
+ label: pendingLabel,
543
+ timestamp: nowMs()
544
+ });
545
+ this.trimToMaxDepth();
546
+ this.index = this.stack.length - 1;
547
+ this.lastPushTime = -Infinity;
548
+ this.syncControls();
549
+ this.notifyCallback(this.onChange, "batch", pending, previousState, pendingLabel);
550
+ }
551
+ }
552
+ return result;
553
+ } catch (err) {
554
+ if (isRoot) {
555
+ this.batchHasChange = false;
556
+ this.batchPendingState = void 0;
557
+ this.batchPendingLabel = void 0;
558
+ }
559
+ throw err;
560
+ } finally {
561
+ this.batchDepth--;
562
+ if (isRoot) {
563
+ this.batchHasChange = false;
564
+ this.batchPendingState = void 0;
565
+ this.batchPendingLabel = void 0;
566
+ }
567
+ }
568
+ }
569
+ /**
570
+ * Interrompt la fenêtre de coalescing en cours : le prochain `push()` créera une nouvelle entrée.
571
+ */
572
+ checkpoint() {
573
+ this.lastPushTime = -Infinity;
574
+ }
575
+ /**
576
+ * Remplace toute la pile par un nouvel état initial.
577
+ */
578
+ reset(newInitialState, label) {
579
+ if (this.isDestroyed || this.isApplying) return;
580
+ const prev = this.stack[this.index]?.state;
581
+ const cleanLabel = sanitizeLabel(label);
582
+ const cloned = this.cloneState(newInitialState);
583
+ this.stack = [{ state: cloned, label: cleanLabel, timestamp: nowMs() }];
584
+ this.index = 0;
585
+ this.lastPushTime = -Infinity;
586
+ this.syncControls();
587
+ this.notifyCallback(this.onChange, "reset", cloned, prev, cleanLabel);
588
+ }
589
+ /**
590
+ * Vide l'historique passé et futur tout en conservant l'état courant comme nouvelle racine.
591
+ */
592
+ clear() {
593
+ if (this.isDestroyed || this.isApplying || this.stack.length === 0) return;
594
+ const curr = this.stack[this.index];
595
+ this.stack = [{ state: curr.state, label: curr.label, timestamp: curr.timestamp }];
596
+ this.index = 0;
597
+ this.lastPushTime = -Infinity;
598
+ this.syncControls();
599
+ this.notifyCallback(this.onChange, "clear", curr.state, curr.state, curr.label);
600
+ }
601
+ canUndo() {
602
+ return !this.isDestroyed && this.index > 0;
603
+ }
604
+ canRedo() {
605
+ return !this.isDestroyed && this.index < this.stack.length - 1;
606
+ }
607
+ getState() {
608
+ if (this.batchDepth > 0 && this.batchHasChange && this.batchPendingState !== void 0) {
609
+ return this.cloneState(this.batchPendingState);
610
+ }
611
+ if (this.stack.length === 0) {
612
+ return void 0;
613
+ }
614
+ return this.cloneState(this.stack[this.index].state);
615
+ }
616
+ getIndex() {
617
+ return this.index;
618
+ }
619
+ getLength() {
620
+ return this.stack.length;
621
+ }
622
+ getUndoLabel() {
623
+ return this.canUndo() ? this.stack[this.index].label : void 0;
624
+ }
625
+ getRedoLabel() {
626
+ return this.canRedo() ? this.stack[this.index + 1].label : void 0;
627
+ }
628
+ getHistory() {
629
+ return this.stack.map((entry) => ({
630
+ state: this.cloneState(entry.state),
631
+ label: entry.label,
632
+ mergeKey: entry.mergeKey,
633
+ timestamp: entry.timestamp
634
+ }));
635
+ }
636
+ /**
637
+ * Relie des boutons DOM Undo/Redo de façon non-destructive :
638
+ * gère `aria-disabled` (avec blocage `click` en phase capture), `aria-keyshortcuts`
639
+ * et `data-wulf-undo-label` sans jamais altérer les icônes ou libellés enfants.
640
+ */
641
+ bindControls(controls) {
642
+ if (this.isDestroyed || typeof HTMLElement === "undefined") {
643
+ return () => {
644
+ };
645
+ }
646
+ const undoEl = controls.undo instanceof HTMLElement ? controls.undo : null;
647
+ const redoEl = controls.redo instanceof HTMLElement ? controls.redo : null;
648
+ const opts = {
649
+ useNativeDisabled: Boolean(controls.useNativeDisabled),
650
+ updateAriaKeyShortcuts: controls.updateAriaKeyShortcuts !== false,
651
+ updateLabelAttribute: controls.updateLabelAttribute !== false
652
+ };
653
+ const ctrl = new AbortController();
654
+ const savedUndo = undoEl ? this.captureControlAttrs(undoEl, "data-wulf-undo-label") : null;
655
+ const savedRedo = redoEl ? this.captureControlAttrs(redoEl, "data-wulf-redo-label") : null;
656
+ const attachClick = (el, role) => {
657
+ el.addEventListener(
658
+ "click",
659
+ (event) => {
660
+ const enabled = role === "undo" ? this.canUndo() : this.canRedo();
661
+ if (!enabled || this.paused || this.isDestroyed) {
662
+ event.preventDefault();
663
+ event.stopImmediatePropagation();
664
+ return;
665
+ }
666
+ if (role === "undo") this.undo();
667
+ else this.redo();
668
+ },
669
+ { capture: true, signal: ctrl.signal }
670
+ );
671
+ };
672
+ if (undoEl) attachClick(undoEl, "undo");
673
+ if (redoEl) attachClick(redoEl, "redo");
674
+ const isApple = isApplePlatform();
675
+ const sync = () => {
676
+ if (undoEl) {
677
+ this.applyControlState(
678
+ undoEl,
679
+ this.canUndo(),
680
+ opts,
681
+ isApple ? "Meta+Z" : "Control+Z",
682
+ "data-wulf-undo-label",
683
+ this.getUndoLabel()
684
+ );
685
+ }
686
+ if (redoEl) {
687
+ this.applyControlState(
688
+ redoEl,
689
+ this.canRedo(),
690
+ opts,
691
+ isApple ? "Meta+Shift+Z" : "Control+Y Control+Shift+Z",
692
+ "data-wulf-redo-label",
693
+ this.getRedoLabel()
694
+ );
695
+ }
696
+ };
697
+ let unbound = false;
698
+ const unbind = () => {
699
+ if (unbound) return;
700
+ unbound = true;
701
+ ctrl.abort();
702
+ if (undoEl && savedUndo) this.restoreControlAttrs(undoEl, "data-wulf-undo-label", savedUndo);
703
+ if (redoEl && savedRedo) this.restoreControlAttrs(redoEl, "data-wulf-redo-label", savedRedo);
704
+ this.bindings.delete(binding);
705
+ };
706
+ const binding = { undoEl, redoEl, options: opts, sync, unbind };
707
+ this.bindings.add(binding);
708
+ sync();
709
+ return unbind;
710
+ }
711
+ pause() {
712
+ this.paused = true;
713
+ }
714
+ resume() {
715
+ if (!this.isDestroyed) {
716
+ this.paused = false;
717
+ }
718
+ }
719
+ isPaused() {
720
+ return this.paused;
721
+ }
722
+ /**
723
+ * Audite le respect de l'Axiome Primordial et l'accessibilité des contrôles liés.
724
+ */
725
+ audit() {
726
+ const warnings = [];
727
+ if (this.keyboardOptions?.allowInEditable) {
728
+ warnings.push(
729
+ "Option keyboard.allowInEditable: true d\xE9tect\xE9e \u2014 risque de d\xE9tourner Ctrl/Cmd+Z natif dans les zones de saisie (Axiome Primordial)."
730
+ );
731
+ }
732
+ for (const binding of this.bindings) {
733
+ for (const el of [binding.undoEl, binding.redoEl]) {
734
+ if (!el) continue;
735
+ const hasLabel = Boolean(el.getAttribute("aria-label")?.trim()) || this.checkAriaIdReferences(el, "aria-labelledby", warnings, true) || Boolean(el.textContent?.trim());
736
+ if (!hasLabel) {
737
+ warnings.push(
738
+ `Contr\xF4le Undo/Redo li\xE9 (${el.tagName.toLowerCase()}) sans nom accessible (ajoutez du texte visible, aria-label ou aria-labelledby).`
739
+ );
740
+ }
741
+ const tabIndexAttr = el.getAttribute("tabindex");
742
+ if (tabIndexAttr !== null) {
743
+ const parsed = Number.parseInt(tabIndexAttr, 10);
744
+ if (Number.isFinite(parsed) && parsed > 0) {
745
+ warnings.push(`\xC9vitez tabindex="${parsed}" (> 0) sur un contr\xF4le Undo/Redo.`);
746
+ }
747
+ }
748
+ }
749
+ }
750
+ return warnings;
751
+ }
752
+ getAuditPrefix() {
753
+ return "Wulf.Undo";
754
+ }
755
+ getAuditTargetLabel() {
756
+ return `UndoManager (${this.stack.length} \xE9tat(s))`;
757
+ }
758
+ /**
759
+ * Détruit l'instance : purge les listeners clavier, délie tous les contrôles,
760
+ * supprime la live-region et libère la pile mémoire.
761
+ */
762
+ destroy() {
763
+ if (this.isDestroyed) return;
764
+ this.isDestroyed = true;
765
+ if (this.abortController) {
766
+ this.abortController.abort();
767
+ this.abortController = null;
768
+ }
769
+ for (const binding of Array.from(this.bindings)) {
770
+ binding.unbind();
771
+ }
772
+ this.bindings.clear();
773
+ if (this.announceTimerId !== null) {
774
+ clearTimeout(this.announceTimerId);
775
+ this.announceTimerId = null;
776
+ }
777
+ if (this.srStatusEl) {
778
+ this.srStatusEl.remove();
779
+ this.srStatusEl = null;
780
+ }
781
+ this.stack = [];
782
+ this.index = -1;
783
+ this.batchPendingState = void 0;
784
+ }
785
+ // --- Implémentation interne ---
786
+ cloneState(value) {
787
+ if (this.cloneStrategy === "none") {
788
+ return value;
789
+ }
790
+ if (typeof this.cloneStrategy === "function") {
791
+ return this.cloneStrategy(value);
792
+ }
793
+ try {
794
+ return structuredClone(value);
795
+ } catch (err) {
796
+ throw new TypeError(
797
+ `[Wulf.Undo] Impossible de cloner l'\xE9tat via structuredClone() (fonction, n\u0153ud DOM ou Proxy non clonable). Utilisez { clone: "none" } ou fournissez une fonction clone personnalis\xE9e.`,
798
+ { cause: err }
799
+ );
800
+ }
801
+ }
802
+ trimToMaxDepth() {
803
+ const maxLen = this.maxDepth + 1;
804
+ if (this.stack.length > maxLen) {
805
+ this.stack.splice(0, this.stack.length - maxLen);
806
+ }
807
+ }
808
+ stepTo(targetIndex, action) {
809
+ const prevEntry = this.stack[this.index];
810
+ const nextEntry = this.stack[targetIndex];
811
+ const labelForAction = action === "undo" ? prevEntry?.label : nextEntry?.label;
812
+ this.isApplying = true;
813
+ try {
814
+ this.index = targetIndex;
815
+ this.lastPushTime = -Infinity;
816
+ this.syncControls();
817
+ const nextClone = this.cloneState(nextEntry.state);
818
+ const prevClone = this.cloneState(prevEntry.state);
819
+ if (action === "undo") {
820
+ this.notifyCallback(this.onUndo, "undo", nextClone, prevClone, labelForAction);
821
+ } else if (action === "redo") {
822
+ this.notifyCallback(this.onRedo, "redo", nextClone, prevClone, labelForAction);
823
+ }
824
+ this.notifyCallback(this.onChange, action, nextClone, prevClone, labelForAction);
825
+ if (this.announceEnabled && (action === "undo" || action === "redo")) {
826
+ const dict = this.resolveI18n();
827
+ this.announce(action === "undo" ? dict.undone(labelForAction) : dict.redone(labelForAction));
828
+ }
829
+ return this.cloneState(nextEntry.state);
830
+ } finally {
831
+ this.isApplying = false;
832
+ }
833
+ }
834
+ notifyCallback(cb, action, state, previousState, label) {
835
+ if (typeof cb !== "function") return;
836
+ const detail = {
837
+ state: this.cloneState(state),
838
+ previousState: this.cloneState(previousState),
839
+ action,
840
+ label,
841
+ index: this.index,
842
+ length: this.stack.length,
843
+ canUndo: this.canUndo(),
844
+ canRedo: this.canRedo()
845
+ };
846
+ try {
847
+ cb(detail);
848
+ } catch (err) {
849
+ const error = err instanceof Error ? err : new Error(String(err));
850
+ if (typeof this.onError === "function") {
851
+ try {
852
+ this.onError(error, action);
853
+ } catch (onErrEx) {
854
+ console.error("[Wulf.Undo] Erreur dans onError :", onErrEx);
855
+ }
856
+ } else {
857
+ console.error(`[Wulf.Undo] Erreur dans callback (${action}) :`, error);
858
+ }
859
+ }
860
+ }
861
+ bindKeyboard() {
862
+ if (!this.keyboardOptions || typeof window === "undefined") return;
863
+ const target = this.keyboardOptions.target ?? window;
864
+ if (!target || typeof target.addEventListener !== "function") return;
865
+ this.abortController = new AbortController();
866
+ target.addEventListener(
867
+ "keydown",
868
+ (ev) => this.handleKeyDown(ev),
869
+ { capture: false, signal: this.abortController.signal }
870
+ );
871
+ }
872
+ handleKeyDown(event) {
873
+ if (this.isDestroyed || this.paused || !this.keyboardOptions || event.defaultPrevented || isImeComposing(event)) {
874
+ return;
875
+ }
876
+ const composed = typeof event.composedPath === "function" ? event.composedPath() : [];
877
+ const nodes = composed.length > 0 ? composed : event.target ? [event.target] : [];
878
+ let isEditable = false;
879
+ let isSensitive = false;
880
+ for (const node of nodes) {
881
+ if (!isSensitive && isSensitiveElement(node)) isSensitive = true;
882
+ if (!isEditable && isEditableElement(node)) isEditable = true;
883
+ }
884
+ if (isSensitive) return;
885
+ if (isEditable && !this.keyboardOptions.allowInEditable) return;
886
+ const key = (event.key || "").toLowerCase();
887
+ if (key !== "z" && key !== "y") return;
888
+ const isApple = isApplePlatform();
889
+ const primaryMod = isApple ? event.metaKey && !event.ctrlKey : event.ctrlKey && !event.metaKey;
890
+ const isUndo = primaryMod && !event.altKey && !event.shiftKey && key === "z";
891
+ const isRedo = primaryMod && !event.altKey && event.shiftKey && key === "z" || !isApple && event.ctrlKey && !event.metaKey && !event.altKey && !event.shiftKey && key === "y";
892
+ if (isUndo && this.canUndo()) {
893
+ if (this.keyboardOptions.preventDefault !== false) event.preventDefault();
894
+ this.undo();
895
+ } else if (isRedo && this.canRedo()) {
896
+ if (this.keyboardOptions.preventDefault !== false) event.preventDefault();
897
+ this.redo();
898
+ }
899
+ }
900
+ captureControlAttrs(el, labelAttr) {
901
+ return {
902
+ hadDisabled: el.hasAttribute("disabled"),
903
+ prevDisabled: el.disabled ?? false,
904
+ hadAriaDisabled: el.hasAttribute("aria-disabled"),
905
+ prevAriaDisabled: el.getAttribute("aria-disabled"),
906
+ hadAriaKeyShortcuts: el.hasAttribute("aria-keyshortcuts"),
907
+ prevAriaKeyShortcuts: el.getAttribute("aria-keyshortcuts"),
908
+ hadLabelAttr: el.hasAttribute(labelAttr),
909
+ prevLabelAttr: el.getAttribute(labelAttr)
910
+ };
911
+ }
912
+ restoreControlAttrs(el, labelAttr, saved) {
913
+ if ("disabled" in el) {
914
+ if (saved.hadDisabled) {
915
+ el.disabled = saved.prevDisabled;
916
+ } else {
917
+ el.removeAttribute("disabled");
918
+ }
919
+ }
920
+ if (saved.hadAriaDisabled && saved.prevAriaDisabled !== null) {
921
+ el.setAttribute("aria-disabled", saved.prevAriaDisabled);
922
+ } else {
923
+ el.removeAttribute("aria-disabled");
924
+ }
925
+ if (saved.hadAriaKeyShortcuts && saved.prevAriaKeyShortcuts !== null) {
926
+ el.setAttribute("aria-keyshortcuts", saved.prevAriaKeyShortcuts);
927
+ } else {
928
+ el.removeAttribute("aria-keyshortcuts");
929
+ }
930
+ if (saved.hadLabelAttr && saved.prevLabelAttr !== null) {
931
+ el.setAttribute(labelAttr, saved.prevLabelAttr);
932
+ } else {
933
+ el.removeAttribute(labelAttr);
934
+ }
935
+ }
936
+ applyControlState(el, enabled, opts, keyShortcut, labelAttr, actionLabel) {
937
+ if (opts.useNativeDisabled && "disabled" in el) {
938
+ el.disabled = !enabled;
939
+ el.removeAttribute("aria-disabled");
940
+ } else {
941
+ el.setAttribute("aria-disabled", enabled ? "false" : "true");
942
+ }
943
+ if (opts.updateAriaKeyShortcuts) {
944
+ el.setAttribute("aria-keyshortcuts", keyShortcut);
945
+ }
946
+ if (opts.updateLabelAttribute) {
947
+ if (actionLabel) el.setAttribute(labelAttr, actionLabel);
948
+ else el.removeAttribute(labelAttr);
949
+ }
950
+ }
951
+ syncControls() {
952
+ for (const binding of this.bindings) {
953
+ binding.sync();
954
+ }
955
+ }
956
+ resolveI18n() {
957
+ if (this.langOverride) {
958
+ const prev = undoI18n.getLocale();
959
+ undoI18n.setLocale(this.langOverride);
960
+ const dict = undoI18n.getAll(this.i18nOverrides);
961
+ undoI18n.setLocale(prev);
962
+ return dict;
963
+ }
964
+ return undoI18n.getAll(this.i18nOverrides);
965
+ }
966
+ mountStatusRegion() {
967
+ if (typeof document === "undefined" || this.srStatusEl) return;
968
+ const status = document.createElement("div");
969
+ status.setAttribute("role", "status");
970
+ status.setAttribute("aria-live", "polite");
971
+ status.setAttribute("aria-atomic", "true");
972
+ status.setAttribute("data-wulf-undo-status", "true");
973
+ status.style.position = "absolute";
974
+ status.style.width = "1px";
975
+ status.style.height = "1px";
976
+ status.style.overflow = "hidden";
977
+ status.style.clipPath = "inset(50%)";
978
+ status.style.whiteSpace = "nowrap";
979
+ status.style.pointerEvents = "none";
980
+ let target = null;
981
+ if (this.announceRoot) {
982
+ if (typeof ShadowRoot !== "undefined" && this.announceRoot instanceof ShadowRoot) {
983
+ target = this.announceRoot;
984
+ } else if (typeof HTMLElement !== "undefined" && this.announceRoot instanceof HTMLElement) {
985
+ target = this.announceRoot;
986
+ } else if (typeof Document !== "undefined" && this.announceRoot instanceof Document) {
987
+ target = this.announceRoot.body || this.announceRoot.documentElement;
988
+ }
989
+ }
990
+ if (!target) {
991
+ target = document.body || document.documentElement;
992
+ }
993
+ if (!target) return;
994
+ target.appendChild(status);
995
+ this.srStatusEl = status;
996
+ }
997
+ announce(message) {
998
+ if (this.isDestroyed || typeof document === "undefined") return;
999
+ const clean = stripBidiAndInvisibles(message, 400).trim();
1000
+ if (!clean) return;
1001
+ const docWithNotify = document;
1002
+ if (typeof docWithNotify.ariaNotify === "function") {
1003
+ try {
1004
+ docWithNotify.ariaNotify(clean, { priority: "normal" });
1005
+ return;
1006
+ } catch {
1007
+ }
1008
+ }
1009
+ if (!this.srStatusEl) {
1010
+ this.mountStatusRegion();
1011
+ }
1012
+ if (!this.srStatusEl) return;
1013
+ if (this.announceTimerId !== null) {
1014
+ clearTimeout(this.announceTimerId);
1015
+ this.announceTimerId = null;
1016
+ }
1017
+ this.srStatusEl.textContent = "";
1018
+ this.announceTimerId = setTimeout(() => {
1019
+ this.announceTimerId = null;
1020
+ if (!this.isDestroyed && this.srStatusEl) {
1021
+ this.srStatusEl.textContent = clean;
1022
+ }
1023
+ }, 40);
1024
+ }
1025
+ };
1026
+ return __toCommonJS(index_exports);
1027
+ })();
1028
+ if (typeof window !== "undefined") { var __w = window.Wulf; if (!__w || typeof __w !== "object" || (typeof Node !== "undefined" && __w instanceof Node) || (typeof HTMLCollection !== "undefined" && __w instanceof HTMLCollection)) { __w = {}; window.Wulf = __w; } var __set = function(obj, key, val) { try { Object.defineProperty(obj, key, { value: val, writable: true, configurable: true, enumerable: true }); } catch (_) { try { obj[key] = val; } catch (__) {} } }; if (typeof __WulfIIFE !== "undefined" && __WulfIIFE) { var __e = __WulfIIFE; var __skip = ["__proto__","constructor","prototype"]; for (var k in __e) { if (Object.hasOwn(__e, k) && __skip.indexOf(k) === -1 && __w[k] === undefined) { __set(__w, k, __e[k]); } } if (__e.UndoManager) __set(__w, "Undo", Object.assign(__e.UndoManager, { Undo: __e.UndoManager, UndoManager: __e.UndoManager, i18n: __e.undoI18n, default: __e.UndoManager })); }}
1029
+ //# sourceMappingURL=undo.global.js.map