@makhmudov.kay/az-editor 0.1.0-beta.13 → 0.1.0-beta.14
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/CHANGELOG.md +7 -0
- package/dist/az-editor.css +1 -1
- package/dist/az-editor.js +1009 -427
- package/dist/library/ImageControls.d.ts +5 -0
- package/dist/library/ImageManipulationOverlay.d.ts +8 -0
- package/dist/library/image-management.d.ts +30 -0
- package/docs/inline-images.ru.md +12 -0
- package/package.json +1 -1
package/dist/az-editor.js
CHANGED
|
@@ -2,12 +2,13 @@ import { createContext as e, forwardRef as t, useCallback as n, useContext as r,
|
|
|
2
2
|
import { DocxEditor as d, LOADING_SNAPSHOT as f, LocaleProvider as p, useChromeTranslate as m, useDocxEditor as h, useEditorEvent as g, useEditorState as _, useFonts as v } from "@docx-editor.dev/react";
|
|
3
3
|
import { packagedFonts as y } from "@docx-editor.dev/fonts";
|
|
4
4
|
import b from "jszip";
|
|
5
|
-
import {
|
|
6
|
-
import { createPortal as
|
|
7
|
-
import { Fragment as
|
|
8
|
-
import { lineAtPosition as
|
|
5
|
+
import { computeResizedImageExtentEmu as x, defineFontResolver as S, overlayFrameToSheetCssPixels as C, selectedImageStateOf as w } from "@docx-editor.dev/core/editor";
|
|
6
|
+
import { createPortal as T } from "react-dom";
|
|
7
|
+
import { Fragment as E, jsx as D, jsxs as O } from "react/jsx-runtime";
|
|
8
|
+
import { caretAt as k, hitTestPage as A, lineAtPosition as j, pageAtY as M } from "@docx-editor.dev/core/layout";
|
|
9
|
+
import { findNode as N, paragraphOffsetIndex as P, parentNodeOf as F } from "@docx-editor.dev/core/store";
|
|
9
10
|
//#region src/library/ru.ts
|
|
10
|
-
var
|
|
11
|
+
var ee = {
|
|
11
12
|
common: {
|
|
12
13
|
cancel: "Отмена",
|
|
13
14
|
apply: "Применить",
|
|
@@ -131,13 +132,13 @@ var D = {
|
|
|
131
132
|
blockSpacingRules: "Интервалы абзаца",
|
|
132
133
|
options: "Параметры интервалов…"
|
|
133
134
|
}
|
|
134
|
-
},
|
|
135
|
+
}, I = class extends Error {
|
|
135
136
|
code;
|
|
136
137
|
constructor(e) {
|
|
137
138
|
super(e), this.code = e;
|
|
138
139
|
}
|
|
139
140
|
};
|
|
140
|
-
function
|
|
141
|
+
function te(e) {
|
|
141
142
|
return e.throwIfAborted(), new Promise((t, n) => {
|
|
142
143
|
let r = () => {
|
|
143
144
|
cancelAnimationFrame(i), n(e.reason);
|
|
@@ -147,7 +148,7 @@ function k(e) {
|
|
|
147
148
|
e.addEventListener("abort", r, { once: !0 });
|
|
148
149
|
});
|
|
149
150
|
}
|
|
150
|
-
async function
|
|
151
|
+
async function ne(e, t, n, r, i, a = Infinity) {
|
|
151
152
|
let o = t.ownerDocument, s = e.getZoom(), c = e.getZoomMode(), l = e.getCurrentPage("viewport"), u = Array.from(t.querySelectorAll("*")).filter((e) => e.scrollHeight > e.clientHeight || e.scrollWidth > e.clientWidth).map((e) => ({
|
|
152
153
|
el: e,
|
|
153
154
|
top: e.scrollTop,
|
|
@@ -165,9 +166,9 @@ async function A(e, t, n, r, i, a = Infinity) {
|
|
|
165
166
|
async function m() {
|
|
166
167
|
let t = p(), n = 0;
|
|
167
168
|
for (; n < 2;) {
|
|
168
|
-
await
|
|
169
|
+
await te(i);
|
|
169
170
|
let r = e.snapshot();
|
|
170
|
-
if (r.parseError) throw new
|
|
171
|
+
if (r.parseError) throw new I("INVALID_DOCX");
|
|
171
172
|
let a = p();
|
|
172
173
|
n = !r.isLoading && !r.isOpening && a === t ? n + 1 : 0, t = a;
|
|
173
174
|
}
|
|
@@ -175,24 +176,24 @@ async function A(e, t, n, r, i, a = Infinity) {
|
|
|
175
176
|
try {
|
|
176
177
|
i.throwIfAborted(), await e.save(), await o.fonts.ready, i.throwIfAborted(), e.setZoom(1), await m();
|
|
177
178
|
let s = e.snapshot().page.total;
|
|
178
|
-
if (s > a) throw new
|
|
179
|
-
if (!s) throw new
|
|
179
|
+
if (s > a) throw new I("PAGE_LIMIT_EXCEEDED");
|
|
180
|
+
if (!s) throw new I("RENDER_FAILED");
|
|
180
181
|
let c = e.getDocumentHandle?.().revision, l = [], u = [];
|
|
181
182
|
n.replaceChildren();
|
|
182
183
|
for (let r = 0; r < s; r++) {
|
|
183
184
|
i.throwIfAborted(), e.scrollToPage(r + 1), await m();
|
|
184
185
|
let a = t.querySelector(`.docx-page[data-page-index="${r}"]`);
|
|
185
|
-
if (!a || a.dataset.materialized !== "true") throw new
|
|
186
|
+
if (!a || a.dataset.materialized !== "true") throw new I("RENDER_FAILED");
|
|
186
187
|
await Promise.all(Array.from(a.querySelectorAll("img")).map((e) => e.decode())), await o.fonts.ready, await m();
|
|
187
188
|
let s = Number.parseFloat(a.style.width), c = Number.parseFloat(a.style.height);
|
|
188
|
-
if (!Number.isFinite(s) || !Number.isFinite(c) || s <= 0 || c <= 0) throw new
|
|
189
|
+
if (!Number.isFinite(s) || !Number.isFinite(c) || s <= 0 || c <= 0) throw new I("RENDER_FAILED");
|
|
189
190
|
let d = a.cloneNode(!0);
|
|
190
191
|
d.classList.add("az-print-sheet"), d.removeAttribute("contenteditable"), d.removeAttribute("aria-hidden"), d.querySelectorAll("[contenteditable]").forEach((e) => e.removeAttribute("contenteditable")), d.querySelectorAll("[data-docx-hf-label]").forEach((e) => e.remove()), d.style.setProperty("page", `az-sheet-${r}`), l.push({
|
|
191
192
|
widthPt: s * 72 / 96,
|
|
192
193
|
heightPt: c * 72 / 96
|
|
193
194
|
}), u.push(`@page az-sheet-${r} { size: ${(s * .75).toFixed(3)}pt ${(c * .75).toFixed(3)}pt; margin: 0; }`), n.append(d);
|
|
194
195
|
}
|
|
195
|
-
if (r.textContent = u.join("\n"), await Promise.all(Array.from(n.querySelectorAll("img")).map((e) => e.decode())), await o.fonts.ready, await m(), e.snapshot().page.total !== s || e.getDocumentHandle?.().revision !== c || n.children.length !== s) throw new
|
|
196
|
+
if (r.textContent = u.join("\n"), await Promise.all(Array.from(n.querySelectorAll("img")).map((e) => e.decode())), await o.fonts.ready, await m(), e.snapshot().page.total !== s || e.getDocumentHandle?.().revision !== c || n.children.length !== s) throw new I("RENDER_FAILED");
|
|
196
197
|
return l;
|
|
197
198
|
} catch (e) {
|
|
198
199
|
throw n.replaceChildren(), r.textContent = "", e;
|
|
@@ -204,11 +205,11 @@ async function A(e, t, n, r, i, a = Infinity) {
|
|
|
204
205
|
}
|
|
205
206
|
//#endregion
|
|
206
207
|
//#region src/library/print-document.ts
|
|
207
|
-
function
|
|
208
|
+
function re(e, t) {
|
|
208
209
|
let n = e.ownerDocument, r = ".az-editor-content, .az-document-editor";
|
|
209
210
|
return ((t instanceof Element ? t.closest(r) : null) ?? n.activeElement?.closest(r)) === e;
|
|
210
211
|
}
|
|
211
|
-
async function
|
|
212
|
+
async function ie(e, t, n, r) {
|
|
212
213
|
let i = t.ownerDocument, a = i.defaultView, o = i.title, s = i.activeElement instanceof HTMLElement ? i.activeElement : null, c = e.getZoom(), l = e.getZoomMode(), u = e.getCurrentPage("viewport"), d = Array.from(t.querySelectorAll("*")).filter((e) => e.scrollHeight > e.clientHeight || e.scrollWidth > e.clientWidth).map((e) => ({
|
|
213
214
|
el: e,
|
|
214
215
|
top: e.scrollTop,
|
|
@@ -249,7 +250,7 @@ async function M(e, t, n, r) {
|
|
|
249
250
|
};
|
|
250
251
|
try {
|
|
251
252
|
E(), C = !0;
|
|
252
|
-
let n = (await
|
|
253
|
+
let n = (await ne(e, t, _, v, x)).length;
|
|
253
254
|
return E(), m.textContent = `Страниц: ${n}. В диалоге печати выберите «Сохранить как PDF». Масштаб — 100%, поля — нет, колонтитулы браузера — выключены.`, h.disabled = !1, h.focus(), T;
|
|
254
255
|
} catch (e) {
|
|
255
256
|
throw T(), e;
|
|
@@ -257,11 +258,11 @@ async function M(e, t, n, r) {
|
|
|
257
258
|
w();
|
|
258
259
|
}
|
|
259
260
|
}
|
|
260
|
-
var
|
|
261
|
-
function
|
|
261
|
+
var L = () => /* @__PURE__ */ Error("Изображение повреждено или имеет неподдерживаемый формат. Используйте PNG или JPEG.");
|
|
262
|
+
function ae(e) {
|
|
262
263
|
let t = new DataView(e.buffer, e.byteOffset, e.byteLength), n = (e) => t.getUint16(e), r = (e) => t.getUint32(e), i;
|
|
263
264
|
if (e.length >= 33 && r(0) === 2303741511 && r(4) === 218765834) {
|
|
264
|
-
if (r(8) !== 13 || r(12) !== 1229472850) throw
|
|
265
|
+
if (r(8) !== 13 || r(12) !== 1229472850) throw L();
|
|
265
266
|
i = {
|
|
266
267
|
mime: "image/png",
|
|
267
268
|
width: r(16),
|
|
@@ -270,36 +271,36 @@ function P(e) {
|
|
|
270
271
|
let t = 8, n = !1, a = !1;
|
|
271
272
|
for (; t + 12 <= e.length;) {
|
|
272
273
|
let i = r(t), o = r(t + 4);
|
|
273
|
-
if (i > e.length - t - 12 || o === 1633899596 || o === 1700284774) throw
|
|
274
|
+
if (i > e.length - t - 12 || o === 1633899596 || o === 1700284774) throw L();
|
|
274
275
|
if (o === 1229209940 && (n = !0), t += 12 + i, o === 1229278788) {
|
|
275
276
|
a = i === 0 && t === e.length;
|
|
276
277
|
break;
|
|
277
278
|
}
|
|
278
279
|
}
|
|
279
|
-
if (!n || !a) throw
|
|
280
|
+
if (!n || !a) throw L();
|
|
280
281
|
} else if (e.length >= 4 && n(0) === 65496 && n(e.length - 2) === 65497) {
|
|
281
282
|
let a = 2, o = !1, s;
|
|
282
283
|
for (; a + 4 <= e.length;) {
|
|
283
|
-
if (e[a++] !== 255) throw
|
|
284
|
+
if (e[a++] !== 255) throw L();
|
|
284
285
|
for (; e[a] === 255;) a++;
|
|
285
|
-
if (a + 3 > e.length) throw
|
|
286
|
+
if (a + 3 > e.length) throw L();
|
|
286
287
|
let c = e[a++], l = n(a);
|
|
287
|
-
if (l < 2 || a + l > e.length) throw
|
|
288
|
+
if (l < 2 || a + l > e.length) throw L();
|
|
288
289
|
if (c === 225 && l >= 16 && r(a + 2) === 1165519206 && n(a + 6) === 0) {
|
|
289
290
|
let e = a + 8, r = n(e) === 18761;
|
|
290
|
-
if (!r && n(e) !== 19789) throw
|
|
291
|
+
if (!r && n(e) !== 19789) throw L();
|
|
291
292
|
let i = (e) => t.getUint16(e, r), o = (e) => t.getUint32(e, r);
|
|
292
|
-
if (i(e + 2) !== 42) throw
|
|
293
|
+
if (i(e + 2) !== 42) throw L();
|
|
293
294
|
let c = e + o(e + 4), u = a + l;
|
|
294
|
-
if (c < e || c + 2 > u) throw
|
|
295
|
+
if (c < e || c + 2 > u) throw L();
|
|
295
296
|
let d = i(c);
|
|
296
|
-
if (c + 2 + d * 12 > u) throw
|
|
297
|
+
if (c + 2 + d * 12 > u) throw L();
|
|
297
298
|
for (let e = 0; e < d; e++) {
|
|
298
299
|
let t = c + 2 + e * 12;
|
|
299
300
|
if (i(t) === 274) {
|
|
300
|
-
if (i(t + 2) !== 3 || o(t + 4) !== 1) throw
|
|
301
|
+
if (i(t + 2) !== 3 || o(t + 4) !== 1) throw L();
|
|
301
302
|
let e = i(t + 8);
|
|
302
|
-
if (s !== void 0 && s !== e) throw
|
|
303
|
+
if (s !== void 0 && s !== e) throw L();
|
|
303
304
|
s = e;
|
|
304
305
|
}
|
|
305
306
|
}
|
|
@@ -309,7 +310,7 @@ function P(e) {
|
|
|
309
310
|
193,
|
|
310
311
|
194
|
|
311
312
|
].includes(c)) {
|
|
312
|
-
if (l < 8 || e[a + 2] !== 8) throw
|
|
313
|
+
if (l < 8 || e[a + 2] !== 8) throw L();
|
|
313
314
|
i = {
|
|
314
315
|
mime: "image/jpeg",
|
|
315
316
|
width: n(a + 5),
|
|
@@ -322,30 +323,30 @@ function P(e) {
|
|
|
322
323
|
}
|
|
323
324
|
a += l;
|
|
324
325
|
}
|
|
325
|
-
if (!o || !i) throw
|
|
326
|
+
if (!o || !i) throw L();
|
|
326
327
|
i.orientation = s;
|
|
327
328
|
}
|
|
328
|
-
if (!i || !i.width || !i.height) throw
|
|
329
|
+
if (!i || !i.width || !i.height) throw L();
|
|
329
330
|
return i;
|
|
330
331
|
}
|
|
331
|
-
function
|
|
332
|
+
function oe(e, t) {
|
|
332
333
|
let n = "";
|
|
333
334
|
for (let t = 0; t < e.length; t += 8192) n += String.fromCharCode(...e.subarray(t, t + 8192));
|
|
334
335
|
return `data:${t};base64,${btoa(n)}`;
|
|
335
336
|
}
|
|
336
|
-
function
|
|
337
|
+
function se(e) {
|
|
337
338
|
if (e.length > 349552) throw Error("Изображение превышает 256 КиБ. Уменьшите его перед вставкой.");
|
|
338
339
|
let t = e.match(/^data:(image\/(?:png|jpeg));base64,([A-Za-z0-9+/]+={0,2})$/);
|
|
339
|
-
if (!t || t[2].length % 4) throw
|
|
340
|
+
if (!t || t[2].length % 4) throw L();
|
|
340
341
|
let n;
|
|
341
342
|
try {
|
|
342
343
|
n = atob(t[2]);
|
|
343
344
|
} catch {
|
|
344
|
-
throw
|
|
345
|
+
throw L();
|
|
345
346
|
}
|
|
346
|
-
if (n.length > 262144 || btoa(n) !== t[2]) throw
|
|
347
|
-
let r = Uint8Array.from(n, (e) => e.charCodeAt(0)), i =
|
|
348
|
-
if (i.mime !== t[1]) throw
|
|
347
|
+
if (n.length > 262144 || btoa(n) !== t[2]) throw L();
|
|
348
|
+
let r = Uint8Array.from(n, (e) => e.charCodeAt(0)), i = ae(r);
|
|
349
|
+
if (i.mime !== t[1]) throw L();
|
|
349
350
|
if (i.width > 4096 || i.height > 4096 || i.width * i.height > 16777216) throw Error("Изображение превышает допустимые размеры (4096 пикселей, 16 Мп).");
|
|
350
351
|
if (i.orientation !== void 0 && i.orientation !== 1) throw Error("Изображение с ориентацией EXIF нужно повторно вставить через кнопку изображения.");
|
|
351
352
|
return {
|
|
@@ -353,7 +354,7 @@ function te(e) {
|
|
|
353
354
|
data: r
|
|
354
355
|
};
|
|
355
356
|
}
|
|
356
|
-
function
|
|
357
|
+
function ce(e, t) {
|
|
357
358
|
let n = /* @__PURE__ */ new Map();
|
|
358
359
|
for (let t of (e.getAttribute("style") ?? "").split(";").filter((e) => e.trim())) {
|
|
359
360
|
let e = t.indexOf(":"), r = t.slice(0, e).trim().toLowerCase();
|
|
@@ -385,27 +386,27 @@ function F(e, t) {
|
|
|
385
386
|
}
|
|
386
387
|
//#endregion
|
|
387
388
|
//#region src/library/layout-profile.ts
|
|
388
|
-
var
|
|
389
|
+
var le = Object.freeze({
|
|
389
390
|
widthMm: 210,
|
|
390
391
|
heightMm: 297,
|
|
391
392
|
topMm: 15,
|
|
392
393
|
rightMm: 20,
|
|
393
394
|
bottomMm: 35,
|
|
394
395
|
leftMm: 20
|
|
395
|
-
}),
|
|
396
|
-
function
|
|
396
|
+
}), ue = (e) => Math.round(e * 1440 / 25.4);
|
|
397
|
+
function de(e) {
|
|
397
398
|
return e.widthTwips - e.margins.left - e.margins.right - e.margins.gutter;
|
|
398
399
|
}
|
|
399
400
|
function R(e = {}) {
|
|
400
401
|
let t = e.page ?? {
|
|
401
|
-
widthTwips:
|
|
402
|
-
heightTwips:
|
|
402
|
+
widthTwips: ue(le.widthMm),
|
|
403
|
+
heightTwips: ue(le.heightMm),
|
|
403
404
|
orientation: "portrait",
|
|
404
405
|
margins: {
|
|
405
|
-
top:
|
|
406
|
-
right:
|
|
407
|
-
bottom:
|
|
408
|
-
left:
|
|
406
|
+
top: ue(le.topMm),
|
|
407
|
+
right: ue(le.rightMm),
|
|
408
|
+
bottom: ue(le.bottomMm),
|
|
409
|
+
left: ue(le.leftMm),
|
|
409
410
|
header: 0,
|
|
410
411
|
footer: 0,
|
|
411
412
|
gutter: 0
|
|
@@ -435,7 +436,7 @@ function R(e = {}) {
|
|
|
435
436
|
].some((e) => {
|
|
436
437
|
let t = n.margins[e];
|
|
437
438
|
return !Number.isSafeInteger(t) || t < 0 || t > 31680;
|
|
438
|
-
}) ||
|
|
439
|
+
}) || de(n) <= 0 || n.heightTwips - n.margins.top - n.margins.bottom <= 0) throw RangeError("Некорректная геометрия страницы: нужны целые twips, согласованная ориентация и положительная область текста (размеры до 22 дюймов).");
|
|
439
440
|
let i = e.lineSpacingPolicy ?? "normalize";
|
|
440
441
|
if (!["normalize", "preserve"].includes(i)) throw TypeError("Неизвестная политика межстрочного интервала.");
|
|
441
442
|
return {
|
|
@@ -445,57 +446,57 @@ function R(e = {}) {
|
|
|
445
446
|
lineSpacingPolicy: i
|
|
446
447
|
};
|
|
447
448
|
}
|
|
448
|
-
function
|
|
449
|
+
function fe(e, t) {
|
|
449
450
|
return e.widthTwips === t.widthTwips && e.heightTwips === t.heightTwips && e.orientation === t.orientation && Object.keys(e.margins).every((n) => e.margins[n] === t.margins[n]);
|
|
450
451
|
}
|
|
451
452
|
//#endregion
|
|
452
453
|
//#region src/library/hujjat/contract.ts
|
|
453
|
-
var
|
|
454
|
+
var pe = [
|
|
454
455
|
"uz",
|
|
455
456
|
"ru",
|
|
456
457
|
"uz_cyrl",
|
|
457
458
|
"en"
|
|
458
|
-
],
|
|
459
|
+
], me = 1048576, z = class extends Error {
|
|
459
460
|
warnings;
|
|
460
461
|
constructor(e, t = []) {
|
|
461
462
|
super(e), this.name = "HujjatCompatibilityError", this.warnings = t;
|
|
462
463
|
}
|
|
463
|
-
},
|
|
464
|
+
}, he = /* @__PURE__ */ new WeakMap();
|
|
464
465
|
function B(e, t, n, r = "warning", i = {}) {
|
|
465
466
|
let a = {
|
|
466
467
|
code: t,
|
|
467
468
|
message: n,
|
|
468
469
|
severity: r,
|
|
469
470
|
...i
|
|
470
|
-
}, o =
|
|
471
|
+
}, o = he.get(e);
|
|
471
472
|
(!o || o.length !== e.length) && (o = {
|
|
472
473
|
length: e.length,
|
|
473
474
|
keys: new Set(e.map((e) => JSON.stringify(e)))
|
|
474
|
-
},
|
|
475
|
+
}, he.set(e, o));
|
|
475
476
|
let s = JSON.stringify(a);
|
|
476
477
|
o.keys.has(s) || (e.push(a), o.keys.add(s), o.length = e.length);
|
|
477
478
|
}
|
|
478
|
-
function
|
|
479
|
+
function ge(e, t = !1) {
|
|
479
480
|
if (!t && e.some((e) => e.severity === "loss")) throw new z("Hujjat не сохраняет часть содержимого. Проверьте warnings; allowLossy разрешает экспорт с указанными потерями.", e);
|
|
480
481
|
}
|
|
481
|
-
function
|
|
482
|
+
function _e(e) {
|
|
482
483
|
return e.length <= 100 && /^[A-Za-z0-9_]+(?:\.[A-Za-z0-9_]+)*$/.test(e) && !e.split(".").some((e) => [
|
|
483
484
|
"__proto__",
|
|
484
485
|
"prototype",
|
|
485
486
|
"constructor"
|
|
486
487
|
].includes(e));
|
|
487
488
|
}
|
|
488
|
-
function
|
|
489
|
+
function ve(e) {
|
|
489
490
|
return /courier|mono|consolas/i.test(e) ? "freemono" : /arial|helvetica|calibri|sans|verdana|tahoma|segoe|roboto/i.test(e) ? "freesans" : "freeserif";
|
|
490
491
|
}
|
|
491
|
-
var
|
|
492
|
+
var ye = new Set("div p span br hr b strong i em u s sub sup h1 h2 h3 h4 h5 h6 ul ol li table colgroup col thead tbody tfoot tr td th".split(" ")), be = new Set("script style iframe object embed svg math img picture video audio canvas link meta form input textarea select button template noscript base frame frameset".split(" ")), xe = new Set("div p h1 h2 h3 h4 h5 h6 ul ol li table thead tbody tfoot tr td th br hr img".split(" ")), Se = {
|
|
492
493
|
pt: 1,
|
|
493
494
|
px: .75,
|
|
494
495
|
in: 72,
|
|
495
496
|
cm: 72 / 2.54,
|
|
496
497
|
mm: 72 / 25.4,
|
|
497
498
|
pc: 12
|
|
498
|
-
},
|
|
499
|
+
}, Ce = new Set(("color font-family font-size font-weight font-style text-decoration text-align text-transform text-indent letter-spacing line-height white-space vertical-align background background-color width height margin padding border border-color border-width border-style border-collapse table-layout page-break-before page-break-after page-break-inside break-before break-after break-inside " + [
|
|
499
500
|
"top",
|
|
500
501
|
"right",
|
|
501
502
|
"bottom",
|
|
@@ -508,15 +509,15 @@ var ue = new Set("div p span br hr b strong i em u s sub sup h1 h2 h3 h4 h5 h6 u
|
|
|
508
509
|
`border-${e}-width`,
|
|
509
510
|
`border-${e}-color`
|
|
510
511
|
]).join(" ")).split(" "));
|
|
511
|
-
function
|
|
512
|
+
function we(e, t) {
|
|
512
513
|
let n = /* @__PURE__ */ new Map();
|
|
513
514
|
for (let r of e.split(";")) {
|
|
514
515
|
if (!r.trim()) continue;
|
|
515
|
-
let e = r.indexOf(":"), i = r.slice(0, e).trim().toLowerCase(), a = r.slice(e + 1).trim(), o = /[<>{}\\@]|url\s*\(|expression|javascript|vbscript|behavior|binding|import|\/\*|!important/i.test(a) || a.length > 200 || /[()]/.test(a.replace(/(?:rgb|hsl)a?\([\d\s.,%/+-]+\)/gi, "")), s = [...a.matchAll(/(-?\d*\.?\d+)\s*(pt|px|in|cm|mm|pc)\b/gi)].some((e) => Math.abs(Number(e[1])) *
|
|
516
|
-
if (e < 1 || !
|
|
516
|
+
let e = r.indexOf(":"), i = r.slice(0, e).trim().toLowerCase(), a = r.slice(e + 1).trim(), o = /[<>{}\\@]|url\s*\(|expression|javascript|vbscript|behavior|binding|import|\/\*|!important/i.test(a) || a.length > 200 || /[()]/.test(a.replace(/(?:rgb|hsl)a?\([\d\s.,%/+-]+\)/gi, "")), s = [...a.matchAll(/(-?\d*\.?\d+)\s*(pt|px|in|cm|mm|pc)\b/gi)].some((e) => Math.abs(Number(e[1])) * Se[e[2].toLowerCase()] > 600);
|
|
517
|
+
if (e < 1 || !Ce.has(i) || !a || o || s || i === "color" && a.toLowerCase() === "auto") B(t, "css-removed", `Стиль ${i || r} не поддерживается контрактом Hujjat.`);
|
|
517
518
|
else {
|
|
518
519
|
if (i === "font-family") {
|
|
519
|
-
let e =
|
|
520
|
+
let e = ve(a);
|
|
520
521
|
a.replace(/['"]/g, "").toLowerCase() !== e && B(t, "font-substitution", `Шрифт ${a} заменён на ${e}.`), a = e;
|
|
521
522
|
}
|
|
522
523
|
if (/^(page-)?break-(before|after|inside)$/.test(i)) {
|
|
@@ -536,11 +537,11 @@ function he(e, t) {
|
|
|
536
537
|
}
|
|
537
538
|
return [...n].map(([e, t]) => `${e}:${t}`).join(";");
|
|
538
539
|
}
|
|
539
|
-
function
|
|
540
|
+
function Te(e) {
|
|
540
541
|
let t = document.createElement("template");
|
|
541
542
|
return t.innerHTML = e, t.content;
|
|
542
543
|
}
|
|
543
|
-
function
|
|
544
|
+
function Ee(e) {
|
|
544
545
|
let t = [], n = [], r = () => {
|
|
545
546
|
n.length && t.push(n), n = [];
|
|
546
547
|
};
|
|
@@ -549,7 +550,7 @@ function _e(e) {
|
|
|
549
550
|
n.push(e);
|
|
550
551
|
return;
|
|
551
552
|
}
|
|
552
|
-
let t = e instanceof Element &&
|
|
553
|
+
let t = e instanceof Element && xe.has(e.localName);
|
|
553
554
|
t && r();
|
|
554
555
|
for (let t of e.childNodes) i(t);
|
|
555
556
|
t && r();
|
|
@@ -574,10 +575,10 @@ function _e(e) {
|
|
|
574
575
|
}
|
|
575
576
|
}
|
|
576
577
|
}
|
|
577
|
-
function
|
|
578
|
+
function De(e) {
|
|
578
579
|
if (typeof e != "string" || !e.trim()) throw new z("HTML шаблона пуст.");
|
|
579
580
|
if (new TextEncoder().encode(e).length > 1048576) throw new z("HTML превышает 1 МБ (1048576 байт).");
|
|
580
|
-
let t =
|
|
581
|
+
let t = Te(e), n = document.createElement("div"), r = [], i = 0, a = 0;
|
|
581
582
|
function o(e, t, n, r) {
|
|
582
583
|
let i = 0;
|
|
583
584
|
for (let a of e.childNodes) s(a, t, n, a instanceof Element ? `${r}/${a.localName}[${i++}]` : r);
|
|
@@ -595,7 +596,7 @@ function ve(e) {
|
|
|
595
596
|
if (++a > 32) throw Error("В одном HTML-блоке допускается не более 32 изображений.");
|
|
596
597
|
let n = e.style;
|
|
597
598
|
if (Array.from(n).some((e) => !["width", "height"].includes(e))) throw Error("В Hujjat поддерживается строчное изображение без обтекания и эффектов; задайте только ширину и высоту.");
|
|
598
|
-
let r = e.getAttribute("src") ?? "", i =
|
|
599
|
+
let r = e.getAttribute("src") ?? "", i = ce(e, se(r)), o = document.createElement("img");
|
|
599
600
|
o.setAttribute("src", r), o.setAttribute("alt", Array.from(e.getAttribute("alt") ?? "").slice(0, 500).join("")), o.setAttribute("style", `width:${i.width}pt;height:${i.height}pt`), t.appendChild(o);
|
|
600
601
|
} catch (e) {
|
|
601
602
|
B(r, "image-invalid", e instanceof Error ? e.message : "Некорректное изображение.", "loss", {
|
|
@@ -605,11 +606,11 @@ function ve(e) {
|
|
|
605
606
|
}
|
|
606
607
|
return;
|
|
607
608
|
}
|
|
608
|
-
if (
|
|
609
|
+
if (be.has(c)) {
|
|
609
610
|
B(r, "html-element-removed", `Элемент ${c} удалён: он не поддерживается HTML-блоком Hujjat.`, "loss");
|
|
610
611
|
return;
|
|
611
612
|
}
|
|
612
|
-
if (!
|
|
613
|
+
if (!ye.has(c)) {
|
|
613
614
|
B(r, "html-tag-unwrapped", `Тег ${c} удалён с сохранением текста.`), o(e, t, n + 1, s);
|
|
614
615
|
return;
|
|
615
616
|
}
|
|
@@ -626,14 +627,14 @@ function ve(e) {
|
|
|
626
627
|
"colgroup"
|
|
627
628
|
].includes(c)) {
|
|
628
629
|
let e = [...u.matchAll(/(?:^|;)\s*width\s*:\s*([^;]+)/gi)].at(-1)?.[1].trim(), t = e?.match(/^(\d*\.?\d+)(pt|px|in|cm|mm|pc)$/i);
|
|
629
|
-
e && e.toLowerCase() !== "auto" && (!/^(?:\d*\.)?\d+(?:pt|px|in|cm|mm|pc|%)$/i.test(e) || !Number.isFinite(parseFloat(e)) || parseFloat(e) <= 0 || t && Number(t[1]) *
|
|
630
|
+
e && e.toLowerCase() !== "auto" && (!/^(?:\d*\.)?\d+(?:pt|px|in|cm|mm|pc|%)$/i.test(e) || !Number.isFinite(parseFloat(e)) || parseFloat(e) <= 0 || t && Number(t[1]) * Se[t[2].toLowerCase()] > 600) && B(r, "table-width-invalid", "Некорректная ширина таблицы или колонки.", "loss", {
|
|
630
631
|
stage: "import",
|
|
631
632
|
location: { htmlPath: s },
|
|
632
633
|
before: e
|
|
633
634
|
});
|
|
634
635
|
}
|
|
635
636
|
e.hasAttribute("bgcolor") && (u += `;background-color:${e.getAttribute("bgcolor")}`);
|
|
636
|
-
let d =
|
|
637
|
+
let d = we(u, r);
|
|
637
638
|
if (d && l.setAttribute("style", d), c === "td" || c === "th") for (let t of ["colspan", "rowspan"]) {
|
|
638
639
|
let n = e.getAttribute(t);
|
|
639
640
|
n && /^\d+$/.test(n) && Number(n) >= 1 && Number(n) <= 100 ? l.setAttribute(t, String(Number(n))) : n !== null && B(r, "table-span-invalid", "Некорректное объединение ячеек.", "loss", {
|
|
@@ -652,11 +653,11 @@ function ve(e) {
|
|
|
652
653
|
}
|
|
653
654
|
o(e, l, n + 1, s), t.appendChild(l);
|
|
654
655
|
}
|
|
655
|
-
o(t, n, 0, ""),
|
|
656
|
+
o(t, n, 0, ""), Ee(n);
|
|
656
657
|
let c = /* @__PURE__ */ new Set(), l = document.createTreeWalker(n, NodeFilter.SHOW_TEXT);
|
|
657
658
|
for (; l.nextNode();) for (let e of l.currentNode.textContent.matchAll(/\{([^{}]+)\}/g)) {
|
|
658
659
|
let t = e[1];
|
|
659
|
-
/^[A-Za-z0-9_.]+$/.test(t) && c.add(t),
|
|
660
|
+
/^[A-Za-z0-9_.]+$/.test(t) && c.add(t), _e(t) || B(r, "invalid-variable", `Проверьте переменную {${t}}: используйте ASCII-путь без пустых сегментов, до 100 символов.`);
|
|
660
661
|
}
|
|
661
662
|
let u = n.innerHTML || "<p></p>";
|
|
662
663
|
if (new TextEncoder().encode(u).length > 1048576) throw new z("HTML превышает 1 МБ (1048576 байт).");
|
|
@@ -666,11 +667,11 @@ function ve(e) {
|
|
|
666
667
|
warnings: r
|
|
667
668
|
};
|
|
668
669
|
}
|
|
669
|
-
function
|
|
670
|
-
if (!
|
|
670
|
+
function Oe(e) {
|
|
671
|
+
if (!pe.includes(e)) throw new z(`Неподдерживаемая локаль: ${e}.`);
|
|
671
672
|
}
|
|
672
|
-
function
|
|
673
|
-
|
|
673
|
+
function ke(e, t) {
|
|
674
|
+
Oe(t);
|
|
674
675
|
let n = e[t];
|
|
675
676
|
if (!n || !Array.isArray(n.blocks) || !n.blocks.length) throw new z(`Нет HTML-шаблона для локали ${t}.`);
|
|
676
677
|
return n.blocks.map((e) => {
|
|
@@ -678,10 +679,10 @@ function be(e, t) {
|
|
|
678
679
|
return e.props.html;
|
|
679
680
|
}).join("");
|
|
680
681
|
}
|
|
681
|
-
function
|
|
682
|
-
|
|
683
|
-
for (let t of Object.keys(e))
|
|
684
|
-
let r =
|
|
682
|
+
function Ae(e, t, n) {
|
|
683
|
+
Oe(t);
|
|
684
|
+
for (let t of Object.keys(e)) Oe(t);
|
|
685
|
+
let r = De(n), i = structuredClone(e);
|
|
685
686
|
return {
|
|
686
687
|
...r,
|
|
687
688
|
page: i[t]?.page,
|
|
@@ -699,13 +700,13 @@ function xe(e, t, n) {
|
|
|
699
700
|
}
|
|
700
701
|
//#endregion
|
|
701
702
|
//#region src/library/hujjat/xml.ts
|
|
702
|
-
var V = "http://schemas.openxmlformats.org/wordprocessingml/2006/main",
|
|
703
|
+
var V = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", je = (e) => e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'"), H = (e, t) => Array.from(e?.children ?? []).filter((e) => e.namespaceURI === "http://schemas.openxmlformats.org/wordprocessingml/2006/main" && (!t || e.localName === t)), U = (e, t) => H(e, t)[0] ?? null, W = (e, t = "val") => e?.getAttributeNS("http://schemas.openxmlformats.org/wordprocessingml/2006/main", t) ?? "", G = (e, t) => W(U(e, t)), K = (e) => e !== null && ![
|
|
703
704
|
"0",
|
|
704
705
|
"false",
|
|
705
706
|
"off",
|
|
706
707
|
"none"
|
|
707
|
-
].includes(W(e)), q = (e) => `${Number(e) / 20}pt`,
|
|
708
|
-
function
|
|
708
|
+
].includes(W(e)), q = (e) => `${Number(e) / 20}pt`, Me = (e) => Object.keys(e).length ? ` style="${je(Object.entries(e).map(([e, t]) => `${e}:${t}`).join(";"))}"` : "";
|
|
709
|
+
function Ne(e) {
|
|
709
710
|
if (/<!DOCTYPE|<!ENTITY/i.test(e)) throw new z("XML с DTD/ENTITY не поддерживается.");
|
|
710
711
|
let t = new DOMParser().parseFromString(e, "application/xml");
|
|
711
712
|
if (t.querySelector("parsererror")) throw new z("Повреждённый XML в DOCX.");
|
|
@@ -714,7 +715,7 @@ function we(e) {
|
|
|
714
715
|
}
|
|
715
716
|
async function J(e, t) {
|
|
716
717
|
let n = e.file(t);
|
|
717
|
-
return n ?
|
|
718
|
+
return n ? Ne(await new Promise((e, t) => {
|
|
718
719
|
let r = n.internalStream("uint8array"), i = 0, a = [];
|
|
719
720
|
r.on("data", (e) => {
|
|
720
721
|
i += e.length, i > 8388608 ? (r.pause(), t(new z("XML-часть DOCX превышает 8 МиБ."))) : a.push(e);
|
|
@@ -772,7 +773,7 @@ function Y(e, t = {}) {
|
|
|
772
773
|
baseline: "baseline"
|
|
773
774
|
}[s]), U(e, "caps") && (n["text-transform"] = K(U(e, "caps")) ? "uppercase" : "none"), G(e, "spacing") && (n["letter-spacing"] = q(G(e, "spacing"))), G(e, "position") && (n["--az-position"] = G(e, "position")), n;
|
|
774
775
|
}
|
|
775
|
-
function
|
|
776
|
+
function Pe(e, t) {
|
|
776
777
|
let n = t.reduce((e, t) => Y(t, e), {}), r = {
|
|
777
778
|
...e,
|
|
778
779
|
...n
|
|
@@ -788,7 +789,7 @@ function Te(e, t) {
|
|
|
788
789
|
]]) n[t] !== void 0 && (r[t] = e[t] === i == (n[t] === i) ? a : i);
|
|
789
790
|
return Y(null, r);
|
|
790
791
|
}
|
|
791
|
-
function
|
|
792
|
+
function Fe(e) {
|
|
792
793
|
let t = {}, n = G(e, "jc");
|
|
793
794
|
n && (t["text-align"] = {
|
|
794
795
|
both: "justify",
|
|
@@ -829,7 +830,7 @@ function Ee(e) {
|
|
|
829
830
|
}
|
|
830
831
|
return t;
|
|
831
832
|
}
|
|
832
|
-
function
|
|
833
|
+
function Ie(e) {
|
|
833
834
|
if (!e) return;
|
|
834
835
|
if (["nil", "none"].includes(W(e))) return "none";
|
|
835
836
|
let t = {
|
|
@@ -841,7 +842,7 @@ function De(e) {
|
|
|
841
842
|
}
|
|
842
843
|
//#endregion
|
|
843
844
|
//#region src/library/hujjat/page-layout.ts
|
|
844
|
-
function
|
|
845
|
+
function Le(e) {
|
|
845
846
|
let t = R().page, n = U(e, "pgSz"), r = U(e, "pgMar"), i = (e, t, n) => W(e, t) === "" ? n : Number(W(e, t)), a = i(n, "w", t.widthTwips), o = i(n, "h", t.heightTwips);
|
|
846
847
|
return R({ page: {
|
|
847
848
|
widthTwips: a,
|
|
@@ -850,10 +851,10 @@ function Oe(e) {
|
|
|
850
851
|
margins: Object.fromEntries(Object.entries(t.margins).map(([e, t]) => [e, i(r, e, t)]))
|
|
851
852
|
} }).page;
|
|
852
853
|
}
|
|
853
|
-
function
|
|
854
|
+
function Re(e, t, n, r) {
|
|
854
855
|
let i = R(t), a = Array.from(e.getElementsByTagNameNS(V, "sectPr")), o;
|
|
855
856
|
try {
|
|
856
|
-
o = a.map(
|
|
857
|
+
o = a.map(Le);
|
|
857
858
|
} catch (e) {
|
|
858
859
|
B(n, "unsupported-page-layout", e instanceof Error ? e.message : "Неподдерживаемые параметры страницы.", "loss", {
|
|
859
860
|
stage: "export",
|
|
@@ -866,9 +867,9 @@ function ke(e, t, n, r) {
|
|
|
866
867
|
location: { part: "word/document.xml" },
|
|
867
868
|
before: a.length,
|
|
868
869
|
after: 1
|
|
869
|
-
}), o.some((e) => !
|
|
870
|
+
}), o.some((e) => !fe(e, o[0]))) return;
|
|
870
871
|
let s = o[0] ?? R().page;
|
|
871
|
-
return
|
|
872
|
+
return fe(s, r ? {
|
|
872
873
|
...r,
|
|
873
874
|
orientation: s.orientation,
|
|
874
875
|
widthTwips: s.orientation === "landscape" ? 16838 : 11906,
|
|
@@ -886,7 +887,7 @@ function ke(e, t, n, r) {
|
|
|
886
887
|
}
|
|
887
888
|
//#endregion
|
|
888
889
|
//#region src/library/hujjat/paragraph-format.ts
|
|
889
|
-
function
|
|
890
|
+
function ze(e) {
|
|
890
891
|
let t, n = "auto";
|
|
891
892
|
for (let r of e) {
|
|
892
893
|
let e = U(r, "spacing");
|
|
@@ -899,10 +900,10 @@ function Ae(e) {
|
|
|
899
900
|
rule: n
|
|
900
901
|
} : void 0;
|
|
901
902
|
}
|
|
902
|
-
function
|
|
903
|
+
function Be(e) {
|
|
903
904
|
return e.rule === "auto" ? String(e.value / 240) : `${e.value / 20}pt`;
|
|
904
905
|
}
|
|
905
|
-
function
|
|
906
|
+
function Ve(e) {
|
|
906
907
|
let t = 0, n = 0;
|
|
907
908
|
for (let r of e) {
|
|
908
909
|
if (r["--az-hidden"] === "1") continue;
|
|
@@ -913,7 +914,7 @@ function Me(e) {
|
|
|
913
914
|
}
|
|
914
915
|
//#endregion
|
|
915
916
|
//#region src/library/hujjat/docx-chrome.ts
|
|
916
|
-
async function
|
|
917
|
+
async function He(e, t, n, r, i) {
|
|
917
918
|
let a = Object.keys(e.files).filter((e) => /^word\/(header|footer)[^/]*\.xml$/.test(e)), o = Array.from(t.getElementsByTagNameNS(V, "sectPr")).flatMap((e) => H(e).filter((e) => ["headerReference", "footerReference"].includes(e.localName)));
|
|
918
919
|
if (n === void 0) {
|
|
919
920
|
(a.length || o.length) && B(r, "header-footer-removed", "Для сохранения колонтитулов передайте page (или locales с page) в exportHujjat.", "loss", { stage: "export" });
|
|
@@ -956,8 +957,8 @@ async function Ne(e, t, n, r, i) {
|
|
|
956
957
|
}
|
|
957
958
|
//#endregion
|
|
958
959
|
//#region src/library/hujjat/server-page.ts
|
|
959
|
-
var
|
|
960
|
-
function
|
|
960
|
+
var Ue = 102400;
|
|
961
|
+
function We(e) {
|
|
961
962
|
if (e == null) return;
|
|
962
963
|
let t = (e) => {
|
|
963
964
|
throw new z(`Некорректное поле page.${e} в контракте Hujjat.`);
|
|
@@ -994,13 +995,13 @@ function Fe(e) {
|
|
|
994
995
|
e in n && r !== null && ((!r || typeof r != "object" || Array.isArray(r) || typeof r.html != "string") && t(`${e}.html`), new TextEncoder().encode(r.html).length > 102400 && t(`${e}.html (100 КиБ)`));
|
|
995
996
|
}
|
|
996
997
|
}
|
|
997
|
-
function
|
|
998
|
-
if (
|
|
998
|
+
function Ge(e, t) {
|
|
999
|
+
if (We(e), !e) return e;
|
|
999
1000
|
let n = structuredClone(e);
|
|
1000
1001
|
for (let e of ["header", "footer"]) {
|
|
1001
1002
|
let r = n[e];
|
|
1002
1003
|
if (!r || !r.html.trim()) continue;
|
|
1003
|
-
let i =
|
|
1004
|
+
let i = De(r.html);
|
|
1004
1005
|
n[e] = { html: i.html }, t.variables = [.../* @__PURE__ */ new Set([...t.variables, ...i.variables])], t.warnings.push(...i.warnings.map((t) => ({
|
|
1005
1006
|
...t,
|
|
1006
1007
|
location: {
|
|
@@ -1009,9 +1010,9 @@ function Ie(e, t) {
|
|
|
1009
1010
|
}
|
|
1010
1011
|
})));
|
|
1011
1012
|
}
|
|
1012
|
-
return
|
|
1013
|
+
return We(n), n;
|
|
1013
1014
|
}
|
|
1014
|
-
function
|
|
1015
|
+
function Ke(e, t = {}) {
|
|
1015
1016
|
let n = R();
|
|
1016
1017
|
return e?.orientation === "landscape" && ([n.page.widthTwips, n.page.heightTwips] = [n.page.heightTwips, n.page.widthTwips], n.page.orientation = "landscape"), R({
|
|
1017
1018
|
...t,
|
|
@@ -1020,8 +1021,8 @@ function Le(e, t = {}) {
|
|
|
1020
1021
|
}
|
|
1021
1022
|
//#endregion
|
|
1022
1023
|
//#region src/library/hujjat/docx-images.ts
|
|
1023
|
-
var
|
|
1024
|
-
async function
|
|
1024
|
+
var qe = "http://schemas.openxmlformats.org/officeDocument/2006/relationships", X = "http://schemas.openxmlformats.org/drawingml/2006/main", Je = "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing", Ye = "http://schemas.openxmlformats.org/drawingml/2006/picture";
|
|
1025
|
+
async function Xe(e) {
|
|
1025
1026
|
return new Promise((t, n) => {
|
|
1026
1027
|
let r = [], i = 0, a = !1, o = e.internalStream("uint8array");
|
|
1027
1028
|
o.on("data", (e) => {
|
|
@@ -1034,10 +1035,10 @@ async function Ve(e) {
|
|
|
1034
1035
|
}).resume();
|
|
1035
1036
|
});
|
|
1036
1037
|
}
|
|
1037
|
-
async function
|
|
1038
|
+
async function Ze(e) {
|
|
1038
1039
|
let t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), r = Object.keys(e.files).filter((e) => /^word\/(?:document|header[^/]*|footer[^/]*)\.xml$/.test(e)), i = 0, a = 0;
|
|
1039
1040
|
for (let o of r) {
|
|
1040
|
-
let r = (await J(e, o))?.documentElement, s = new Set(Array.from(r?.getElementsByTagNameNS(X, "blip") ?? []).map((e) => e.getAttributeNS(
|
|
1041
|
+
let r = (await J(e, o))?.documentElement, s = new Set(Array.from(r?.getElementsByTagNameNS(X, "blip") ?? []).map((e) => e.getAttributeNS(qe, "embed")).filter((e) => !!e));
|
|
1041
1042
|
if (!s.size) continue;
|
|
1042
1043
|
let c = (await J(e, `word/_rels/${o.slice(5)}.rels`))?.documentElement;
|
|
1043
1044
|
for (let r of s) {
|
|
@@ -1048,10 +1049,10 @@ async function He(e) {
|
|
|
1048
1049
|
if (o.length !== 1 || l?.getAttribute("TargetMode") === "External" || l?.getAttribute("Type") !== "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" || !/^word\/media\/[A-Za-z0-9_.-]+$/.test(d) || !e.file(d)) throw Error("Изображение DOCX должно быть встроенным ресурсом PNG/JPEG.");
|
|
1049
1050
|
let f = n.get(d);
|
|
1050
1051
|
if (!f) {
|
|
1051
|
-
let t = await
|
|
1052
|
+
let t = await Xe(e.file(d));
|
|
1052
1053
|
if (i += t.length, i > 2097152) throw Error("Общий размер изображений DOCX превышает 2 МиБ.");
|
|
1053
|
-
let r =
|
|
1054
|
-
|
|
1054
|
+
let r = oe(t, t[0] === 137 ? "image/png" : "image/jpeg");
|
|
1055
|
+
se(r), f = { src: r }, n.set(d, f);
|
|
1055
1056
|
}
|
|
1056
1057
|
t.set(s, f);
|
|
1057
1058
|
} catch (e) {
|
|
@@ -1061,7 +1062,7 @@ async function He(e) {
|
|
|
1061
1062
|
}
|
|
1062
1063
|
return t;
|
|
1063
1064
|
}
|
|
1064
|
-
function
|
|
1065
|
+
function Qe(e) {
|
|
1065
1066
|
if (e.namespaceURI !== X) return !1;
|
|
1066
1067
|
if (["xfrm", "prstGeom"].includes(e.localName)) return !0;
|
|
1067
1068
|
if (["noFill", "effectLst"].includes(e.localName)) return e.children.length === 0;
|
|
@@ -1069,34 +1070,34 @@ function Ue(e) {
|
|
|
1069
1070
|
let t = e.children[0];
|
|
1070
1071
|
return t.namespaceURI === X && t.localName === "noFill" && t.children.length === 0;
|
|
1071
1072
|
}
|
|
1072
|
-
function
|
|
1073
|
-
let i = (t, n) => Array.from(e.getElementsByTagNameNS(t, n)), a = i(
|
|
1073
|
+
function $e(e, t, n, r) {
|
|
1074
|
+
let i = (t, n) => Array.from(e.getElementsByTagNameNS(t, n)), a = i(Je, "inline"), o = i(Ye, "pic");
|
|
1074
1075
|
if (!a.length && !o.length) return r("drawing-removed", "Фигуры и текстовые блоки Word не поддерживаются HTML-блоком Hujjat."), "";
|
|
1075
1076
|
let s = (e) => (r("image-layout-unsupported", e), "");
|
|
1076
|
-
if (a.length !== 1 || o.length !== 1 || i(
|
|
1077
|
+
if (a.length !== 1 || o.length !== 1 || i(Je, "anchor").length) return s("Поддерживаются изображения в строке. Плавающее изображение нужно преобразовать в строчное.");
|
|
1077
1078
|
let c = i(X, "srcRect").some((e) => [
|
|
1078
1079
|
"l",
|
|
1079
1080
|
"r",
|
|
1080
1081
|
"t",
|
|
1081
1082
|
"b"
|
|
1082
|
-
].some((t) => Number(e.getAttribute(t) || 0) !== 0)), l = i(X, "xfrm").some((e) => Number(e.getAttribute("rot") || 0) !== 0 || ["flipH", "flipV"].some((t) => ["1", "true"].includes(e.getAttribute(t) ?? ""))), u = i(X, "effectLst").some((e) => e.children.length) || i(X, "effectDag").length || i(X, "tile").length || i(X, "hlinkClick").length || i(X, "hlinkHover").length, d = i(
|
|
1083
|
+
].some((t) => Number(e.getAttribute(t) || 0) !== 0)), l = i(X, "xfrm").some((e) => Number(e.getAttribute("rot") || 0) !== 0 || ["flipH", "flipV"].some((t) => ["1", "true"].includes(e.getAttribute(t) ?? ""))), u = i(X, "effectLst").some((e) => e.children.length) || i(X, "effectDag").length || i(X, "tile").length || i(X, "hlinkClick").length || i(X, "hlinkHover").length, d = i(Ye, "spPr").some((e) => Array.from(e.children).some((e) => !Qe(e))) || i(X, "prstGeom").some((e) => e.getAttribute("prst") !== "rect") || i(X, "fillRect").some((e) => Array.from(e.attributes).some((e) => Number(e.value) !== 0)), f = i(X, "blip");
|
|
1083
1084
|
if (c || l || u || d || f.some((e) => Array.from(e.children).some((e) => e.localName !== "extLst"))) return s("Обрезка, поворот, эффекты и ссылки изображения не сохраняются в Hujjat. Сначала примените их к самому файлу.");
|
|
1084
|
-
let p = Array.from(a[0].children).filter((e) => e.namespaceURI ===
|
|
1085
|
+
let p = Array.from(a[0].children).filter((e) => e.namespaceURI === Je && e.localName === "extent"), m = p[0], h = Number(m?.getAttribute("cx")) / 12700, g = Number(m?.getAttribute("cy")) / 12700;
|
|
1085
1086
|
if (p.length !== 1 || !Number.isFinite(h) || !Number.isFinite(g) || h <= 0 || g <= 0 || h > 600 || g > 600) return s("Размер изображения должен быть больше нуля и не превышать 600 pt.");
|
|
1086
|
-
let _ = f[0], v = _?.getAttributeNS(
|
|
1087
|
+
let _ = f[0], v = _?.getAttributeNS(qe, "embed"), y = n.get(`${t}#${v}`);
|
|
1087
1088
|
if (f.length !== 1 || _?.hasAttributeNS("http://schemas.openxmlformats.org/officeDocument/2006/relationships", "link") || !y || "error" in y) return r("image-invalid", y && "error" in y ? y.error : "Не удалось прочитать встроенное изображение DOCX."), "";
|
|
1088
|
-
let b = i(
|
|
1089
|
-
if ([b, ...i(
|
|
1089
|
+
let b = i(Je, "docPr")[0];
|
|
1090
|
+
if ([b, ...i(Ye, "cNvPr")].some((e) => ["1", "true"].includes(e?.getAttribute("hidden") ?? ""))) return r("hidden-image-removed", "Скрытое изображение Word исключено из HTML."), "";
|
|
1090
1091
|
let x = Array.from(b?.getAttribute("descr") || b?.getAttribute("title") || "").slice(0, 500).join("");
|
|
1091
|
-
return `<img src="${y.src}" alt="${
|
|
1092
|
+
return `<img src="${y.src}" alt="${je(x)}" style="width:${Number(h.toFixed(4))}pt;height:${Number(g.toFixed(4))}pt">`;
|
|
1092
1093
|
}
|
|
1093
|
-
function
|
|
1094
|
+
function et(e, t, n, r, i) {
|
|
1094
1095
|
let a = Math.round(n * 12700), o = Math.round(r * 12700);
|
|
1095
|
-
return `<w:r><w:drawing><wp:inline xmlns:wp="${
|
|
1096
|
+
return `<w:r><w:drawing><wp:inline xmlns:wp="${Je}" xmlns:a="${X}" xmlns:pic="${Ye}" xmlns:r="${qe}" distT="0" distB="0" distL="0" distR="0"><wp:extent cx="${a}" cy="${o}"/><wp:docPr id="${e}" name="Image ${e}" descr="${je(i)}"/><wp:cNvGraphicFramePr><a:graphicFrameLocks noChangeAspect="1"/></wp:cNvGraphicFramePr><a:graphic><a:graphicData uri="${Ye}"><pic:pic><pic:nvPicPr><pic:cNvPr id="${e}" name="Image ${e}"/><pic:cNvPicPr/></pic:nvPicPr><pic:blipFill><a:blip r:embed="${t}"/><a:stretch><a:fillRect/></a:stretch></pic:blipFill><pic:spPr><a:xfrm><a:off x="0" y="0"/><a:ext cx="${a}" cy="${o}"/></a:xfrm><a:prstGeom prst="rect"><a:avLst/></a:prstGeom></pic:spPr></pic:pic></a:graphicData></a:graphic></wp:inline></w:drawing></w:r>`;
|
|
1096
1097
|
}
|
|
1097
1098
|
//#endregion
|
|
1098
1099
|
//#region src/library/hujjat/docx-to-html.ts
|
|
1099
|
-
async function
|
|
1100
|
+
async function tt(e, t = {}, n) {
|
|
1100
1101
|
if (e.byteLength > 31457280) throw new z("DOCX превышает 30 МиБ.");
|
|
1101
1102
|
let r;
|
|
1102
1103
|
try {
|
|
@@ -1111,7 +1112,7 @@ async function Ke(e, t = {}, n) {
|
|
|
1111
1112
|
if (!Array.from(a?.getElementsByTagNameNS("*", "Override") ?? []).some((e) => e.getAttribute("PartName") === "/word/document.xml" && e.getAttribute("ContentType") === "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml")) throw new z("Файл не является обычным DOCX.");
|
|
1112
1113
|
let o = await J(r, "word/document.xml"), s = await J(r, "word/styles.xml"), c = await J(r, "word/numbering.xml"), l = U(o?.documentElement, "body");
|
|
1113
1114
|
if (!l) throw new z("В DOCX нет поддерживаемой структуры документа.");
|
|
1114
|
-
let u = [], d = await
|
|
1115
|
+
let u = [], d = await Ze(r), f = Re(l, t, u, n === void 0 ? void 0 : Ke(n).page), p, m = (e, t, n = "warning", r, i) => B(u, e, t, n, {
|
|
1115
1116
|
stage: "export",
|
|
1116
1117
|
location: p ? { ...p } : void 0,
|
|
1117
1118
|
before: r,
|
|
@@ -1121,7 +1122,7 @@ async function Ke(e, t = {}, n) {
|
|
|
1121
1122
|
let S = U(s?.documentElement, "docDefaults"), C = {
|
|
1122
1123
|
"margin-top": "0pt",
|
|
1123
1124
|
"margin-bottom": "8px",
|
|
1124
|
-
...
|
|
1125
|
+
...Fe(U(U(S, "pPrDefault"), "pPr"))
|
|
1125
1126
|
}, w = {
|
|
1126
1127
|
"font-family": "freeserif",
|
|
1127
1128
|
"font-size": "12pt",
|
|
@@ -1140,7 +1141,7 @@ async function Ke(e, t = {}, n) {
|
|
|
1140
1141
|
function P(e, t, n) {
|
|
1141
1142
|
if (N(n), e.namespaceURI !== "http://schemas.openxmlformats.org/wordprocessingml/2006/main") return h("unsupported-content", "Нестандартный объект Word не сохраняется в HTML."), "";
|
|
1142
1143
|
switch (e.localName) {
|
|
1143
|
-
case "t": return
|
|
1144
|
+
case "t": return je(Array.from(e.textContent ?? "").map((e) => {
|
|
1144
1145
|
let t = e === " " && j ? "\xA0" : e;
|
|
1145
1146
|
return j = e === " ", t;
|
|
1146
1147
|
}).join(""));
|
|
@@ -1154,11 +1155,11 @@ async function Ke(e, t = {}, n) {
|
|
|
1154
1155
|
...p,
|
|
1155
1156
|
runIndex: x++
|
|
1156
1157
|
};
|
|
1157
|
-
let r = U(e, "rPr"), i = Y(r,
|
|
1158
|
+
let r = U(e, "rPr"), i = Y(r, Pe(t, E(G(r, "rStyle")).map((e) => U(e, "rPr"))));
|
|
1158
1159
|
if (i["--az-hidden"] === "1") return h("hidden-text-removed", "Скрытый текст Word исключён из HTML."), "";
|
|
1159
1160
|
Number(i["--az-position"]) && m("baseline-shift-lost", "Вертикальное смещение фрагмента Word не представлено в HTML.", "loss", Number(i["--az-position"]) / 2, 0);
|
|
1160
1161
|
let a = Object.fromEntries(Object.entries(i).filter(([e]) => !e.startsWith("--az-")));
|
|
1161
|
-
return H(e).filter((e) => e.localName !== "rPr").map((e) => P(e, i, n + 1)).join("").split(/(<div style="page-break-before:always"><\/div>)/).map((e) => e.startsWith("<div ") ? e : e ? `<span${
|
|
1162
|
+
return H(e).filter((e) => e.localName !== "rPr").map((e) => P(e, i, n + 1)).join("").split(/(<div style="page-break-before:always"><\/div>)/).map((e) => e.startsWith("<div ") ? e : e ? `<span${Me(a)}>${e}</span>` : "").join("");
|
|
1162
1163
|
}
|
|
1163
1164
|
case "hyperlink":
|
|
1164
1165
|
B(u, "hyperlink-removed", "Ссылки сохраняются как текст без перехода.");
|
|
@@ -1175,7 +1176,7 @@ async function Ke(e, t = {}, n) {
|
|
|
1175
1176
|
bytes: 0
|
|
1176
1177
|
};
|
|
1177
1178
|
if (t.count >= 32) throw new z("В одном HTML-блоке допускается не более 32 изображений.");
|
|
1178
|
-
let n =
|
|
1179
|
+
let n = $e(e, v, d, h);
|
|
1179
1180
|
if (n && (t.count++, t.bytes += new TextEncoder().encode(n).length, y.set(v, t)), t.bytes > (v === "word/document.xml" ? 1048576 : 102400)) throw new z("Встроенные изображения превышают лимит HTML: 1 МБ на тело, 100 КиБ на колонтитул.");
|
|
1180
1181
|
return j = !1, n;
|
|
1181
1182
|
}
|
|
@@ -1203,7 +1204,7 @@ async function Ke(e, t = {}, n) {
|
|
|
1203
1204
|
}
|
|
1204
1205
|
return Array.from(e.children).map((e) => P(e, t, n + 1)).join("");
|
|
1205
1206
|
}
|
|
1206
|
-
function
|
|
1207
|
+
function F(e, n) {
|
|
1207
1208
|
p = {
|
|
1208
1209
|
part: v,
|
|
1209
1210
|
paragraphIndex: g.get(e)
|
|
@@ -1214,24 +1215,24 @@ async function Ke(e, t = {}, n) {
|
|
|
1214
1215
|
"pageBreakBefore",
|
|
1215
1216
|
"spacing"
|
|
1216
1217
|
].includes(e.localName)) && W(a, "before") === "0" && W(a, "after") === "0" && W(a, "line") === "1" && W(a, "lineRule") === "exact" && Array.from(e.children).every((e) => e === r)) return { html: "<div style=\"page-break-before:always\"></div>" };
|
|
1217
|
-
let o = [...i.map((e) => U(e, "pPr")), r], s = Object.assign({}, C, ...o.map(
|
|
1218
|
+
let o = [...i.map((e) => U(e, "pPr")), r], s = Object.assign({}, C, ...o.map(Fe)), c = o.map((e) => U(e, "numPr")).filter(Boolean).at(-1), l = G(c, "numId"), d = Number(G(c, "ilvl") || 0), f = G(r, "pStyle") === "AzHujjatListContinuation";
|
|
1218
1219
|
if (l && l !== "0" || f) {
|
|
1219
|
-
let e = O.get(l), t =
|
|
1220
|
+
let e = O.get(l), t = Fe(U(H(k.get(G(e, "abstractNumId")), "lvl").find((e) => W(e, "ilvl") === String(d)), "pPr"));
|
|
1220
1221
|
s["margin-left"] = q((parseFloat(s["margin-left"] ?? t["margin-left"] ?? "0") || 0) * 20 - 360), s["text-indent"] ??= t["text-indent"] ?? "0pt";
|
|
1221
1222
|
}
|
|
1222
1223
|
parseFloat(s["text-indent"] ?? "0") < 0 && parseFloat(s["margin-left"] ?? "0") >= 0 && (s["padding-left"] = s["margin-left"] ?? "0pt", s["margin-left"] = "0pt");
|
|
1223
|
-
let _ =
|
|
1224
|
-
_ && (s["line-height"] =
|
|
1225
|
-
let y =
|
|
1224
|
+
let _ = ze([U(U(S, "pPrDefault"), "pPr"), ...o]);
|
|
1225
|
+
_ && (s["line-height"] = Be(_));
|
|
1226
|
+
let y = Pe(w, i.map((e) => U(e, "rPr"))), b = Y(U(r, "rPr"), y);
|
|
1226
1227
|
b["--az-hidden"] === "1" && (m("hidden-paragraph-mark-lost", "Скрытый знак абзаца нельзя представить в HTML; его отдельный шрифт заменён стилем абзаца.", "loss", "hidden", "visible paragraph style"), b = {
|
|
1227
1228
|
...y,
|
|
1228
1229
|
"--az-hidden": "0"
|
|
1229
1230
|
}), s["font-family"] = b["font-family"], s["font-size"] = b["font-size"];
|
|
1230
1231
|
let T = Array.from(e.getElementsByTagNameNS(V, "r")).map((e) => {
|
|
1231
1232
|
let t = U(e, "rPr");
|
|
1232
|
-
return Y(t,
|
|
1233
|
+
return Y(t, Pe(y, E(G(t, "rStyle")).map((e) => U(e, "rPr"))));
|
|
1233
1234
|
}), A = s["line-height"];
|
|
1234
|
-
A && (/^\d*\.?\d+$/.test(A) ? Number(A) < 1 : A.endsWith("pt") && parseFloat(A) <
|
|
1235
|
+
A && (/^\d*\.?\d+$/.test(A) ? Number(A) < 1 : A.endsWith("pt") && parseFloat(A) < Ve([b, ...T])) && (t.lineSpacingPolicy === "preserve" ? m("line-height-overlap-risk", "Авторский тесный интервал сохранён; строки могут перекрываться. Фактические метрики шрифта требуют проверки.", "warning", A, A) : (s["line-height"] = /^\d*\.?\d+$/.test(A) ? "1" : "normal", m("line-height-normalized", "Тесный межстрочный интервал нормализован по размерам фрагментов. Проверьте переносы на используемых шрифтах.", "warning", A, s["line-height"]))), A?.endsWith("pt") && t.lineSpacingPolicy !== "preserve" && m("line-height-metrics-estimated", "Проверка интервала использует размеры и смещения фрагментов, а не метрики установленного шрифта. Результат нормализации требует проверки на используемых шрифтах.", "warning", A, s["line-height"]), _ && _.rule !== "auto" && m("line-rule-lost", "CSS line-height не сохраняет различие правил Word exact и atLeast.", "warning", _.rule, "CSS line-height"), o.some((e) => U(e, "tabs")) && h("tab-stops-removed", "Позиции, типы и заполнители табуляции не поддерживаются HTML-блоком.");
|
|
1235
1236
|
let M = [U(U(S, "pPrDefault"), "pPr"), ...o].map((e) => U(e, "widowControl")).filter(Boolean).at(-1);
|
|
1236
1237
|
M && B(u, "widow-control-lost", "Правило висячих строк Word не представлено в HTML-контракте.", "loss", {
|
|
1237
1238
|
stage: "export",
|
|
@@ -1239,7 +1240,7 @@ async function Ke(e, t = {}, n) {
|
|
|
1239
1240
|
before: K(M),
|
|
1240
1241
|
after: null
|
|
1241
1242
|
}), j = !0;
|
|
1242
|
-
let N = Array.from(e.children).filter((e) => e !== r).map((e) => P(e, y, n + 1)).join("").split("<div style=\"page-break-before:always\"></div>").map((e, t) => `${t ? "<div style=\"page-break-before:always\"></div>" : ""}<p${
|
|
1243
|
+
let N = Array.from(e.children).filter((e) => e !== r).map((e) => P(e, y, n + 1)).join("").split("<div style=\"page-break-before:always\"></div>").map((e, t) => `${t ? "<div style=\"page-break-before:always\"></div>" : ""}<p${Me(s)}>${e || "<br>"}</p>`).join("");
|
|
1243
1244
|
if (l && l !== "0") {
|
|
1244
1245
|
let e = O.get(l), t = H(k.get(G(e, "abstractNumId")), "lvl").find((e) => W(e, "ilvl") === String(d));
|
|
1245
1246
|
if (!t) return B(u, "numbering-unsupported", "Не найдена нумерация списка.", "loss"), { html: N };
|
|
@@ -1258,7 +1259,7 @@ async function Ke(e, t = {}, n) {
|
|
|
1258
1259
|
continuation: G(r, "pStyle") === "AzHujjatListContinuation"
|
|
1259
1260
|
};
|
|
1260
1261
|
}
|
|
1261
|
-
function
|
|
1262
|
+
function ee(e, t) {
|
|
1262
1263
|
N(t);
|
|
1263
1264
|
let n = U(e, "tblPr"), r = G(n, "tblStyle"), i = {
|
|
1264
1265
|
part: v,
|
|
@@ -1317,7 +1318,7 @@ async function Ke(e, t = {}, n) {
|
|
|
1317
1318
|
"bottom",
|
|
1318
1319
|
"left"
|
|
1319
1320
|
]) {
|
|
1320
|
-
let i = U(U(e, "tcBorders"), t), o = t === "top" && r > 0 || t === "bottom" && r < c.length - 1 ? "insideH" : t === "left" && x > 0 || t === "right" && x + p < d ? "insideV" : t, s = U(a, o), l =
|
|
1321
|
+
let i = U(U(e, "tcBorders"), t), o = t === "top" && r > 0 || t === "bottom" && r < c.length - 1 ? "insideH" : t === "left" && x > 0 || t === "right" && x + p < d ? "insideV" : t, s = U(a, o), l = Ie(i ?? s);
|
|
1321
1322
|
l && (g[`border-${t}`] = l);
|
|
1322
1323
|
let u = U(U(e, "tcMar"), t) ?? U(U(n, "tblCellMar"), t);
|
|
1323
1324
|
u && W(u, "w") && (g[`padding-${t}`] = q(W(u, "w")));
|
|
@@ -1326,7 +1327,7 @@ async function Ke(e, t = {}, n) {
|
|
|
1326
1327
|
element: i,
|
|
1327
1328
|
rowSpan: 1,
|
|
1328
1329
|
span: p,
|
|
1329
|
-
html:
|
|
1330
|
+
html: I(i, t + 1),
|
|
1330
1331
|
css: g
|
|
1331
1332
|
};
|
|
1332
1333
|
for (let e = x; e < x + p; e++) l.delete(e);
|
|
@@ -1340,26 +1341,26 @@ async function Ke(e, t = {}, n) {
|
|
|
1340
1341
|
"border-collapse": "collapse"
|
|
1341
1342
|
}, S = U(n, "tblInd");
|
|
1342
1343
|
W(S, "type") === "dxa" && (x["margin-left"] = q(W(S, "w"))), x["table-layout"] = s ? "fixed" : "auto";
|
|
1343
|
-
let C = m.map((e, t) => `<tr${
|
|
1344
|
-
return `<table${
|
|
1344
|
+
let C = m.map((e, t) => `<tr${Me(g[t])}>${e.map((e) => `<td${e.span > 1 ? ` colspan="${e.span}"` : ""}${e.rowSpan > 1 ? ` rowspan="${e.rowSpan}"` : ""}${Me(e.css)}>${e.html || "<p><br></p>"}</td>`).join("")}</tr>`), w = f ? `<colgroup>${o.map((e) => `<col style="width:${q(e)}">`).join("")}</colgroup>` : "";
|
|
1345
|
+
return `<table${Me(x)}>${w}${y ? `<thead>${C.slice(0, y).join("")}</thead>` : ""}<tbody>${C.slice(y).join("")}</tbody></table>`;
|
|
1345
1346
|
}
|
|
1346
|
-
function
|
|
1347
|
+
function I(e, t) {
|
|
1347
1348
|
N(t);
|
|
1348
1349
|
let n = "", r, i = () => {
|
|
1349
1350
|
r && (n += `</${r.tag}>`), r = void 0;
|
|
1350
1351
|
};
|
|
1351
1352
|
for (let a of Array.from(e.children)) if (a.namespaceURI !== "http://schemas.openxmlformats.org/wordprocessingml/2006/main") i(), h("unsupported-content", "Нестандартный блок Word не сохраняется в HTML.");
|
|
1352
1353
|
else if (a.localName === "p") {
|
|
1353
|
-
let e =
|
|
1354
|
+
let e = F(a, t + 1);
|
|
1354
1355
|
e.list ? ((r?.id !== e.list.id || r.tag !== e.list.tag) && (i(), r = e.list, r.tag === "ol" && A.has(r.id) && h("numbering-restart", "Продолжение нумерованного списка после другого блока начнётся с 1: Hujjat удаляет атрибут start."), A.add(r.id), n += `<${r.tag}>`), n += `<li>${e.html}</li>`) : e.continuation && r && n.endsWith("</li>") ? n = n.slice(0, -5) + e.html + "</li>" : (i(), n += e.html);
|
|
1355
|
-
} else a.localName === "tbl" ? (i(), n +=
|
|
1356
|
+
} else a.localName === "tbl" ? (i(), n += ee(a, t + 1)) : a.localName === "sectPr" || ([
|
|
1356
1357
|
"sdt",
|
|
1357
1358
|
"customXml",
|
|
1358
1359
|
"ins",
|
|
1359
1360
|
"del",
|
|
1360
1361
|
"moveFrom",
|
|
1361
1362
|
"moveTo"
|
|
1362
|
-
].includes(a.localName) ? (i(), h("block-flattened", `Блок Word ${a.localName} преобразован без интерактивности/истории.`), ["del", "moveFrom"].includes(a.localName) || (n +=
|
|
1363
|
+
].includes(a.localName) ? (i(), h("block-flattened", `Блок Word ${a.localName} преобразован без интерактивности/истории.`), ["del", "moveFrom"].includes(a.localName) || (n += I(U(a, "sdtContent") ?? a, t + 1))) : [
|
|
1363
1364
|
"tblPr",
|
|
1364
1365
|
"tblGrid",
|
|
1365
1366
|
"tcPr",
|
|
@@ -1370,26 +1371,26 @@ async function Ke(e, t = {}, n) {
|
|
|
1370
1371
|
].includes(a.localName) || (i(), h("unsupported-block", `Блок Word ${a.localName} не поддерживается HTML-адаптером.`)));
|
|
1371
1372
|
return i(), n;
|
|
1372
1373
|
}
|
|
1373
|
-
let
|
|
1374
|
-
return f && n !== void 0 && f.page.orientation !== (
|
|
1375
|
-
html:
|
|
1374
|
+
let te = I(l, 0) || "<p><br></p>", ne = await He(r, l, n, u, (e, t) => (v = t, A.clear(), g = new Map(Array.from(e.getElementsByTagNameNS(V, "p")).map((e, t) => [e, t])), _ = new Map(Array.from(e.getElementsByTagNameNS(V, "tbl")).map((e, t) => [e, t])), I(e, 0) || "<p><br></p>"));
|
|
1375
|
+
return f && n !== void 0 && f.page.orientation !== (ne?.orientation ?? "portrait") ? {
|
|
1376
|
+
html: te,
|
|
1376
1377
|
warnings: u,
|
|
1377
1378
|
layout: f,
|
|
1378
1379
|
page: {
|
|
1379
|
-
...
|
|
1380
|
+
...ne,
|
|
1380
1381
|
orientation: f.page.orientation
|
|
1381
1382
|
}
|
|
1382
1383
|
} : {
|
|
1383
|
-
html:
|
|
1384
|
+
html: te,
|
|
1384
1385
|
warnings: u,
|
|
1385
1386
|
layout: f,
|
|
1386
|
-
page:
|
|
1387
|
+
page: ne
|
|
1387
1388
|
};
|
|
1388
1389
|
}
|
|
1389
1390
|
//#endregion
|
|
1390
1391
|
//#region src/library/hujjat/table-grid.ts
|
|
1391
|
-
var
|
|
1392
|
-
function
|
|
1392
|
+
var nt = 1e-7;
|
|
1393
|
+
function rt(e, t, n) {
|
|
1393
1394
|
let r = Array.from({ length: e + 1 }, () => []), i = (e, t, n) => {
|
|
1394
1395
|
r[e].push({
|
|
1395
1396
|
to: t,
|
|
@@ -1409,7 +1410,7 @@ function Je(e, t, n) {
|
|
|
1409
1410
|
for (let n = 0; n < e.length; n++) for (let i of r[e[n]]) {
|
|
1410
1411
|
let r = o[e[n]] + i.distance;
|
|
1411
1412
|
if (a[i.to] !== -1) {
|
|
1412
|
-
if (Math.abs(o[i.to] - r) >
|
|
1413
|
+
if (Math.abs(o[i.to] - r) > nt) return null;
|
|
1413
1414
|
} else a[i.to] = a[t], o[i.to] = r, e.push(i.to);
|
|
1414
1415
|
}
|
|
1415
1416
|
}
|
|
@@ -1435,7 +1436,7 @@ function Je(e, t, n) {
|
|
|
1435
1436
|
high: u
|
|
1436
1437
|
};
|
|
1437
1438
|
}
|
|
1438
|
-
function
|
|
1439
|
+
function it(e, t) {
|
|
1439
1440
|
let { groups: n } = e, r = [...e.edges];
|
|
1440
1441
|
if (t !== void 0) for (let i = 0; i < n; i++) r.push({
|
|
1441
1442
|
from: 0,
|
|
@@ -1449,12 +1450,12 @@ function Ye(e, t) {
|
|
|
1449
1450
|
let i = Array(n).fill(0);
|
|
1450
1451
|
for (let e = 0; e < n; e++) {
|
|
1451
1452
|
let e = !1;
|
|
1452
|
-
for (let { from: t, to: n, distance: a } of r) i[n] > i[t] + a +
|
|
1453
|
+
for (let { from: t, to: n, distance: a } of r) i[n] > i[t] + a + nt && (i[n] = i[t] + a, e = !0);
|
|
1453
1454
|
if (!e) return i.map((e) => e - i[0]);
|
|
1454
1455
|
}
|
|
1455
1456
|
return null;
|
|
1456
1457
|
}
|
|
1457
|
-
function
|
|
1458
|
+
function at(e) {
|
|
1458
1459
|
if (!e) return null;
|
|
1459
1460
|
let t = (t) => ({
|
|
1460
1461
|
...e,
|
|
@@ -1463,45 +1464,45 @@ function Xe(e) {
|
|
|
1463
1464
|
distance: e.distance - t
|
|
1464
1465
|
}))
|
|
1465
1466
|
}), n = t(1);
|
|
1466
|
-
if (
|
|
1467
|
-
if (!
|
|
1467
|
+
if (it(n)) return n;
|
|
1468
|
+
if (!it(e)) return null;
|
|
1468
1469
|
let r = 0, i = 1, a = e;
|
|
1469
|
-
for (let e = 0; e < 40 && i - r >
|
|
1470
|
+
for (let e = 0; e < 40 && i - r > nt; e++) {
|
|
1470
1471
|
let e = (r + i) / 2, n = t(e);
|
|
1471
|
-
|
|
1472
|
+
it(n) ? (r = e, a = n) : i = e;
|
|
1472
1473
|
}
|
|
1473
|
-
return r >
|
|
1474
|
+
return r > nt ? a : null;
|
|
1474
1475
|
}
|
|
1475
|
-
function
|
|
1476
|
-
let t =
|
|
1476
|
+
function ot(e) {
|
|
1477
|
+
let t = it(e), n = it(e, 0);
|
|
1477
1478
|
if (n) return n;
|
|
1478
1479
|
let r = 0, i = Math.max(...t.map((t, n) => Math.max(e.low[n] - t, t - e.high[n]))) + 1;
|
|
1479
1480
|
for (let n = 0; n < 60 && i - r > 1e-6; n++) {
|
|
1480
|
-
let n = (r + i) / 2, a =
|
|
1481
|
+
let n = (r + i) / 2, a = it(e, n);
|
|
1481
1482
|
a ? (t = a, i = n) : r = n;
|
|
1482
1483
|
}
|
|
1483
1484
|
return t;
|
|
1484
1485
|
}
|
|
1485
|
-
function
|
|
1486
|
+
function st(e, t, n, r) {
|
|
1486
1487
|
let i = (e) => Number.isFinite(e) && e > 0 && e < (2 ** 53 - 1) / 4;
|
|
1487
1488
|
if (!Number.isInteger(e) || e < 1 || e > 1e3 || !i(t) || Math.round(t) < e) throw new z("Некорректный размер сетки таблицы.");
|
|
1488
1489
|
for (let t of n) if (!Number.isInteger(t.column) || !Number.isInteger(t.span) || t.column < 0 || t.span < 1 || t.column + t.span > e || !i(t.width)) throw new z("Некорректное ограничение ширины таблицы.");
|
|
1489
|
-
let a = (e) => e.source === "column" ? 0 : e.span === 1 ? 1 : 2, o = (e) => JSON.stringify(Object.entries(e.location ?? {}).sort(([e], [t]) => e < t ? -1 : +(e > t))), s = [...n].sort((e, t) => a(e) - a(t) || e.column - t.column || e.span - t.span || e.width - t.width || o(e).localeCompare(o(t), "en")), c = s.filter((e, t) => !t || a(e) !== a(s[t - 1]) || e.column !== s[t - 1].column || e.span !== s[t - 1].span || e.width !== s[t - 1].width), l =
|
|
1490
|
+
let a = (e) => e.source === "column" ? 0 : e.span === 1 ? 1 : 2, o = (e) => JSON.stringify(Object.entries(e.location ?? {}).sort(([e], [t]) => e < t ? -1 : +(e > t))), s = [...n].sort((e, t) => a(e) - a(t) || e.column - t.column || e.span - t.span || e.width - t.width || o(e).localeCompare(o(t), "en")), c = s.filter((e, t) => !t || a(e) !== a(s[t - 1]) || e.column !== s[t - 1].column || e.span !== s[t - 1].span || e.width !== s[t - 1].width), l = at(rt(e, t, c));
|
|
1490
1491
|
if (!l) {
|
|
1491
1492
|
let n = [];
|
|
1492
|
-
l =
|
|
1493
|
+
l = at(rt(e, t, []));
|
|
1493
1494
|
for (let r of c) {
|
|
1494
|
-
let i =
|
|
1495
|
+
let i = at(rt(e, t, [...n, r]));
|
|
1495
1496
|
i && (i.groups < l.groups && n.push(r), l = i);
|
|
1496
1497
|
}
|
|
1497
1498
|
}
|
|
1498
|
-
let u =
|
|
1499
|
+
let u = ot(l), d = l.offset.map((e, t) => e + u[l.component[t]]), f = Math.round(t), p = d.map((e) => Math.round(e));
|
|
1499
1500
|
p[0] = 0, p[e] = f;
|
|
1500
|
-
let m = d.map((e) => Math.floor(e + 1 +
|
|
1501
|
+
let m = d.map((e) => Math.floor(e + 1 + nt));
|
|
1501
1502
|
m[e] = f;
|
|
1502
1503
|
for (let t = e - 1; t > 0; t--) m[t] = Math.min(m[t], m[t + 1] - 1);
|
|
1503
1504
|
for (let t = 1; t < e; t++) {
|
|
1504
|
-
let e = Math.max(p[t - 1] + 1, Math.ceil(d[t] - 1 -
|
|
1505
|
+
let e = Math.max(p[t - 1] + 1, Math.ceil(d[t] - 1 - nt));
|
|
1505
1506
|
if (e > m[t]) throw new z("Сетка не представима положительными twips без превышения допуска округления.");
|
|
1506
1507
|
p[t] = Math.max(e, Math.min(m[t], p[t]));
|
|
1507
1508
|
}
|
|
@@ -1520,7 +1521,7 @@ function Qe(e, t, n, r) {
|
|
|
1520
1521
|
}
|
|
1521
1522
|
//#endregion
|
|
1522
1523
|
//#region src/library/hujjat/html-to-docx.ts
|
|
1523
|
-
var
|
|
1524
|
+
var ct = /^(font-|color$|text-align$|text-indent$|text-transform$|line-height$|letter-spacing$|white-space$|text-decoration$|vertical-align$)/, lt = new Set("p div h1 h2 h3 h4 h5 h6 ul ol li table hr".split(" ")), ut = {
|
|
1524
1525
|
black: "000000",
|
|
1525
1526
|
white: "FFFFFF",
|
|
1526
1527
|
red: "FF0000",
|
|
@@ -1539,14 +1540,14 @@ var $e = /^(font-|color$|text-align$|text-indent$|text-transform$|line-height$|l
|
|
|
1539
1540
|
teal: "008080",
|
|
1540
1541
|
aqua: "00FFFF"
|
|
1541
1542
|
};
|
|
1542
|
-
function
|
|
1543
|
+
function dt(e) {
|
|
1543
1544
|
if (!e) return;
|
|
1544
1545
|
if (/^#[\da-f]{6}$/i.test(e)) return e.slice(1);
|
|
1545
1546
|
if (/^#[\da-f]{3}$/i.test(e)) return e.slice(1).split("").map((e) => e + e).join("");
|
|
1546
1547
|
let t = e.match(/^rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/i);
|
|
1547
|
-
return t ? t.slice(1).map((e) => Math.min(255, Number(e)).toString(16).padStart(2, "0")).join("") :
|
|
1548
|
+
return t ? t.slice(1).map((e) => Math.min(255, Number(e)).toString(16).padStart(2, "0")).join("") : ut[e.toLowerCase()];
|
|
1548
1549
|
}
|
|
1549
|
-
function
|
|
1550
|
+
function ft(e) {
|
|
1550
1551
|
if (e === "0") return 0;
|
|
1551
1552
|
let t = e?.match(/^(-?\d*\.?\d+)(pt|px|in|cm|mm|pc)$/i);
|
|
1552
1553
|
return t ? Number(t[1]) * {
|
|
@@ -1559,9 +1560,9 @@ function rt(e) {
|
|
|
1559
1560
|
}[t[2].toLowerCase()] : void 0;
|
|
1560
1561
|
}
|
|
1561
1562
|
var Z = (e) => {
|
|
1562
|
-
let t =
|
|
1563
|
+
let t = ft(e);
|
|
1563
1564
|
return t === void 0 ? void 0 : Math.round(t * 20);
|
|
1564
|
-
},
|
|
1565
|
+
}, pt = (e, t) => (Z(e[`margin-${t}`]) ?? 0) + Math.max(0, Z(e[`padding-${t}`]) ?? 0);
|
|
1565
1566
|
function Q(e, t) {
|
|
1566
1567
|
let n = { ...t }, r = e.style;
|
|
1567
1568
|
for (let e of Array.from(r)) n[e] = r.getPropertyValue(e).trim();
|
|
@@ -1590,14 +1591,14 @@ function Q(e, t) {
|
|
|
1590
1591
|
h3: "12pt"
|
|
1591
1592
|
}[i] ?? "12pt"), r.fontWeight || (n["font-weight"] = "bold")), n;
|
|
1592
1593
|
}
|
|
1593
|
-
var
|
|
1594
|
-
async function
|
|
1594
|
+
var mt = (e) => Object.fromEntries(Object.entries(e).filter(([e]) => ct.test(e)));
|
|
1595
|
+
async function ht(e, t, n = R(), r) {
|
|
1595
1596
|
let i = {
|
|
1596
|
-
width:
|
|
1597
|
+
width: de(n.page),
|
|
1597
1598
|
cell: !1
|
|
1598
|
-
}, a =
|
|
1599
|
+
}, a = Te(e), o = 1, s = [], c = ["header", "footer"].flatMap((e) => r?.[e]?.html.trim() ? [{
|
|
1599
1600
|
kind: e,
|
|
1600
|
-
root:
|
|
1601
|
+
root: Te(r[e].html)
|
|
1601
1602
|
}] : []), l = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Map(), d = "word/document.xml", f = 0, p = /* @__PURE__ */ new WeakMap();
|
|
1602
1603
|
function m(e, t) {
|
|
1603
1604
|
let n = 0;
|
|
@@ -1638,7 +1639,7 @@ async function ot(e, t, n = R(), r) {
|
|
|
1638
1639
|
h.push(r);
|
|
1639
1640
|
return;
|
|
1640
1641
|
}
|
|
1641
|
-
let i = r && (
|
|
1642
|
+
let i = r && (lt.has(r.localName) || [
|
|
1642
1643
|
"br",
|
|
1643
1644
|
"td",
|
|
1644
1645
|
"th",
|
|
@@ -1657,16 +1658,16 @@ async function ot(e, t, n = R(), r) {
|
|
|
1657
1658
|
};
|
|
1658
1659
|
r?.line_height !== void 0 && (v["line-height"] = String(r.line_height));
|
|
1659
1660
|
function y(e) {
|
|
1660
|
-
let t = `<w:rFonts w:ascii="${
|
|
1661
|
-
return n !== void 0 && (t += `<w:sz w:val="${Math.round(n * 2)}"/>`), e["font-weight"] && (t += `<w:b w:val="${e["font-weight"] === "bold" || Number(e["font-weight"]) >= 600 ? "1" : "0"}"/>`), e["font-style"] && (t += `<w:i w:val="${e["font-style"] === "italic" ? "1" : "0"}"/>`), e["text-decoration"] && (t += `<w:u w:val="${e["text-decoration"].includes("underline") ? "single" : "none"}"/><w:strike w:val="${e["text-decoration"].includes("line-through") ? "1" : "0"}"/>`),
|
|
1661
|
+
let t = `<w:rFonts w:ascii="${je(e["font-family"] || "freeserif")}" w:hAnsi="${je(e["font-family"] || "freeserif")}"/>`, n = ft(e["font-size"]);
|
|
1662
|
+
return n !== void 0 && (t += `<w:sz w:val="${Math.round(n * 2)}"/>`), e["font-weight"] && (t += `<w:b w:val="${e["font-weight"] === "bold" || Number(e["font-weight"]) >= 600 ? "1" : "0"}"/>`), e["font-style"] && (t += `<w:i w:val="${e["font-style"] === "italic" ? "1" : "0"}"/>`), e["text-decoration"] && (t += `<w:u w:val="${e["text-decoration"].includes("underline") ? "single" : "none"}"/><w:strike w:val="${e["text-decoration"].includes("line-through") ? "1" : "0"}"/>`), dt(e.color) && (t += `<w:color w:val="${dt(e.color)}"/>`), dt(e["background-color"]) && (t += `<w:shd w:fill="${dt(e["background-color"])}"/>`), ["super", "sub"].includes(e["vertical-align"]) && (t += `<w:vertAlign w:val="${e["vertical-align"] === "super" ? "superscript" : "subscript"}"/>`), e["text-transform"] === "uppercase" && (t += "<w:caps/>"), Z(e["letter-spacing"]) !== void 0 && (t += `<w:spacing w:val="${Z(e["letter-spacing"])}"/>`), t;
|
|
1662
1663
|
}
|
|
1663
1664
|
function x(e, t) {
|
|
1664
1665
|
let n = "";
|
|
1665
|
-
for (let r of e) if (r.nodeType === 3) r.textContent && (n += `<w:r><w:rPr>${y(t)}</w:rPr><w:t xml:space="preserve">${
|
|
1666
|
+
for (let r of e) if (r.nodeType === 3) r.textContent && (n += `<w:r><w:rPr>${y(t)}</w:rPr><w:t xml:space="preserve">${je(r.textContent)}</w:t></w:r>`);
|
|
1666
1667
|
else if (r instanceof Element) {
|
|
1667
1668
|
if (r.localName === "br") n += `<w:r><w:rPr>${y(Q(r, t))}</w:rPr><w:br/></w:r>`;
|
|
1668
1669
|
else if (r.localName === "img") {
|
|
1669
|
-
let e = r.getAttribute("src") ?? "", t =
|
|
1670
|
+
let e = r.getAttribute("src") ?? "", t = se(e), i = ce(r, t), a = l.get(e);
|
|
1670
1671
|
if (!a) {
|
|
1671
1672
|
let n = l.size + 1;
|
|
1672
1673
|
a = {
|
|
@@ -1676,7 +1677,7 @@ async function ot(e, t, n = R(), r) {
|
|
|
1676
1677
|
}, l.set(e, a);
|
|
1677
1678
|
}
|
|
1678
1679
|
let o = u.get(d) ?? /* @__PURE__ */ new Set();
|
|
1679
|
-
o.add(e), u.set(d, o), n +=
|
|
1680
|
+
o.add(e), u.set(d, o), n += et(++f, `rIdImage${a.id}`, i.width, i.height, Array.from(r.getAttribute("alt") ?? "").slice(0, 500).join(""));
|
|
1680
1681
|
} else n += x(r.childNodes, Q(r, t));
|
|
1681
1682
|
}
|
|
1682
1683
|
return n;
|
|
@@ -1698,10 +1699,10 @@ async function ot(e, t, n = R(), r) {
|
|
|
1698
1699
|
before: e,
|
|
1699
1700
|
after: r ? e : 1
|
|
1700
1701
|
}), f = ` w:line="${Math.round(Math.max(+!r, e) * 240)}" w:lineRule="auto"`;
|
|
1701
|
-
} else if (
|
|
1702
|
+
} else if (ft(p) !== void 0) {
|
|
1702
1703
|
let e = [], i = (t) => e.push({
|
|
1703
1704
|
...t,
|
|
1704
|
-
"font-size": `${Math.round((
|
|
1705
|
+
"font-size": `${Math.round((ft(t["font-size"]) ?? 12) * 2) / 2}pt`
|
|
1705
1706
|
}), a = (e, t) => {
|
|
1706
1707
|
for (let n of e) if (n.nodeType === 3 && n.textContent) i(t);
|
|
1707
1708
|
else if (n instanceof Element) {
|
|
@@ -1710,7 +1711,7 @@ async function ot(e, t, n = R(), r) {
|
|
|
1710
1711
|
}
|
|
1711
1712
|
};
|
|
1712
1713
|
i(r), a(s, r);
|
|
1713
|
-
let c = Z(p) / 20 <
|
|
1714
|
+
let c = Z(p) / 20 < Ve(e), l = n.lineSpacingPolicy === "normalize";
|
|
1714
1715
|
c && B(t, l ? "line-height-normalized" : "line-height-overlap-risk", l ? "Тесный абсолютный интервал заменён естественным одинарным интервалом." : "Тесный абсолютный интервал сохранён; проверьте наложение строк.", "warning", {
|
|
1715
1716
|
stage: "import",
|
|
1716
1717
|
location: { htmlPath: o.htmlPath },
|
|
@@ -1761,11 +1762,11 @@ async function ot(e, t, n = R(), r) {
|
|
|
1761
1762
|
dotted: "dotted",
|
|
1762
1763
|
double: "double",
|
|
1763
1764
|
none: "nil"
|
|
1764
|
-
}[r] ?? "single"}" w:sz="${Math.max(0, Math.round((
|
|
1765
|
+
}[r] ?? "single"}" w:sz="${Math.max(0, Math.round((ft(i) ?? .75) * 8))}" w:color="${dt(a) ?? "000000"}"/>`;
|
|
1765
1766
|
}
|
|
1766
1767
|
function w(e, n, r) {
|
|
1767
1768
|
let i = Array.from(e.querySelectorAll("tr")).filter((t) => t.closest("table") === e), a = /* @__PURE__ */ new Map(), o = 1, s = [], c = n.width?.endsWith("%") ? parseFloat(n.width) : void 0, l = (r.left ?? 0) + (Z(n["margin-left"]) ?? 0), u = (r.right ?? 0) + (Z(n["margin-right"]) ?? 0), d = Math.max(1, r.width - l - u), f = Math.max(1, Math.round(Z(n.width) ?? (c === void 0 ? d : d * c / 100))), m = (e) => {
|
|
1768
|
-
let t =
|
|
1769
|
+
let t = ft(e);
|
|
1769
1770
|
return t === void 0 ? e?.endsWith("%") ? parseFloat(e) * f / 100 : void 0 : t * 20;
|
|
1770
1771
|
};
|
|
1771
1772
|
(r.before || r.after || Z(n["margin-top"]) || Z(n["margin-bottom"])) && B(t, "table-margin-approximation", "Вертикальные отступы контейнера вокруг таблицы требуют проверки.");
|
|
@@ -1791,7 +1792,7 @@ async function ot(e, t, n = R(), r) {
|
|
|
1791
1792
|
let u = [], d = o.parentElement;
|
|
1792
1793
|
for (; d && d !== e;) u.unshift(d), d = d.parentElement;
|
|
1793
1794
|
let f = (e) => ({
|
|
1794
|
-
...
|
|
1795
|
+
...mt(e),
|
|
1795
1796
|
...e["background-color"] ? { "background-color": e["background-color"] } : {}
|
|
1796
1797
|
}), g = Q(o, f(u.reduce((e, t) => Q(t, f(e)), n)));
|
|
1797
1798
|
o.localName === "th" && (g["font-weight"] = "bold");
|
|
@@ -1843,7 +1844,7 @@ async function ot(e, t, n = R(), r) {
|
|
|
1843
1844
|
}
|
|
1844
1845
|
}
|
|
1845
1846
|
if (_ > o) throw new z("Число явных колонок превышает логическую сетку ячеек.");
|
|
1846
|
-
let v =
|
|
1847
|
+
let v = st(o, f, s, t), y = "<w:p><w:pPr><w:spacing w:before=\"0\" w:after=\"0\"/></w:pPr></w:p>", b = !0, x = g.map((e, n) => {
|
|
1847
1848
|
let r = i[n], a = Q(r, {}), o = Z(a.height), s = o !== void 0 && o >= 0 ? `<w:trHeight w:val="${o}" w:hRule="atLeast"/>` : "";
|
|
1848
1849
|
["avoid", "auto"].includes(a["page-break-inside"]) && (s += `<w:cantSplit w:val="${a["page-break-inside"] === "avoid" ? "1" : "0"}"/>`);
|
|
1849
1850
|
let c = r.parentElement?.localName === "thead";
|
|
@@ -1853,7 +1854,7 @@ async function ot(e, t, n = R(), r) {
|
|
|
1853
1854
|
}), c || (b = !1), `<w:tr>${s ? `<w:trPr>${s}</w:trPr>` : ""}${e.map(({ element: e, column: t, span: n, rowSpan: r, css: i }) => {
|
|
1854
1855
|
let a = v.slice(t, t + n).reduce((e, t) => e + t, 0), o = `<w:tcW w:w="${a}" w:type="dxa"/>`;
|
|
1855
1856
|
if (n > 1 && (o += `<w:gridSpan w:val="${n}"/>`), r > 1 && (o += "<w:vMerge w:val=\"restart\"/>"), !e) return `<w:tc><w:tcPr>${o}${r === 0 ? "<w:vMerge/>" : ""}</w:tcPr>${y}</w:tc>`;
|
|
1856
|
-
let s =
|
|
1857
|
+
let s = dt(i["background-color"]);
|
|
1857
1858
|
s && (o += `<w:shd w:fill="${s}"/>`), [
|
|
1858
1859
|
"top",
|
|
1859
1860
|
"middle",
|
|
@@ -1868,7 +1869,7 @@ async function ot(e, t, n = R(), r) {
|
|
|
1868
1869
|
l && (o += `<w:tcBorders>${l}</w:tcBorders>`);
|
|
1869
1870
|
let u = c.map((e) => Z(i[`padding-${e}`]) === void 0 ? "" : `<w:${e} w:w="${Math.max(0, Z(i[`padding-${e}`]))}" w:type="dxa"/>`).join("");
|
|
1870
1871
|
u && (o += `<w:tcMar>${u}</w:tcMar>`);
|
|
1871
|
-
let d = Math.max(1, a - Math.max(0, Z(i["padding-left"]) ?? 0) - Math.max(0, Z(i["padding-right"]) ?? 0)), f = O(D(e.childNodes,
|
|
1872
|
+
let d = Math.max(1, a - Math.max(0, Z(i["padding-left"]) ?? 0) - Math.max(0, Z(i["padding-right"]) ?? 0)), f = O(D(e.childNodes, mt(i), void 0, {
|
|
1872
1873
|
width: d,
|
|
1873
1874
|
cell: !0
|
|
1874
1875
|
}));
|
|
@@ -1912,12 +1913,12 @@ async function ot(e, t, n = R(), r) {
|
|
|
1912
1913
|
u.length && l.push(...T([{ xml: S(u, n, a, m(d, e)) }], n)), u = [];
|
|
1913
1914
|
};
|
|
1914
1915
|
for (let [e, i] of f.entries()) {
|
|
1915
|
-
if (!(i instanceof Element) || !
|
|
1916
|
+
if (!(i instanceof Element) || !lt.has(i.localName)) {
|
|
1916
1917
|
u.length || (d = e), u.push(i);
|
|
1917
1918
|
continue;
|
|
1918
1919
|
}
|
|
1919
1920
|
h(e - 1);
|
|
1920
|
-
let f = Q(i,
|
|
1921
|
+
let f = Q(i, mt(n)), g = {
|
|
1921
1922
|
...m(e),
|
|
1922
1923
|
htmlPath: p.get(i)
|
|
1923
1924
|
};
|
|
@@ -1936,20 +1937,20 @@ async function ot(e, t, n = R(), r) {
|
|
|
1936
1937
|
let a = {
|
|
1937
1938
|
id: e,
|
|
1938
1939
|
pending: !0
|
|
1939
|
-
}, o = Q(i,
|
|
1940
|
+
}, o = Q(i, mt(f)), s = {
|
|
1940
1941
|
...g,
|
|
1941
1942
|
before: Math.max(t === 0 ? g.before ?? 0 : 0, Z(o["margin-top"]) ?? 0),
|
|
1942
1943
|
after: Math.max(t === n.length - 1 ? g.after ?? 0 : 0, Z(o["margin-bottom"]) ?? 0),
|
|
1943
|
-
left: (g.left ?? 0) +
|
|
1944
|
-
right: (g.right ?? 0) +
|
|
1944
|
+
left: (g.left ?? 0) + pt(f, "left") + pt(o, "left"),
|
|
1945
|
+
right: (g.right ?? 0) + pt(f, "right") + pt(o, "right")
|
|
1945
1946
|
}, c = Object.fromEntries(Object.entries(o).filter(([e]) => !/^(margin|padding)(-|$)/.test(e))), l = D(i.childNodes, c, a, s);
|
|
1946
1947
|
r.push(...T(E(l.length ? l : [{ xml: S([], c, a, s) }], o, p.get(i)), o));
|
|
1947
1948
|
}
|
|
1948
1949
|
l.push(...T(E(r, f, g.htmlPath), f));
|
|
1949
|
-
} else i.localName === "div" && Array.from(i.children).some((e) =>
|
|
1950
|
+
} else i.localName === "div" && Array.from(i.children).some((e) => lt.has(e.localName)) ? l.push(...T(E(D(i.childNodes, mt(f), a, {
|
|
1950
1951
|
...g,
|
|
1951
|
-
left: (g.left ?? 0) +
|
|
1952
|
-
right: (g.right ?? 0) +
|
|
1952
|
+
left: (g.left ?? 0) + pt(f, "left"),
|
|
1953
|
+
right: (g.right ?? 0) + pt(f, "right"),
|
|
1953
1954
|
before: Math.max(g.before ?? 0, Z(f["margin-top"]) ?? 0),
|
|
1954
1955
|
after: Math.max(g.after ?? 0, Z(f["margin-bottom"]) ?? 0)
|
|
1955
1956
|
}), f, g.htmlPath), f)) : i.localName === "div" && !i.children.length && !i.textContent && f["page-break-before"] === "always" && Array.from(i.style).every((e) => ["page-break-before", "break-before"].includes(e)) ? l.push({
|
|
@@ -1991,7 +1992,7 @@ async function ot(e, t, n = R(), r) {
|
|
|
1991
1992
|
before: r,
|
|
1992
1993
|
after: "baseline"
|
|
1993
1994
|
});
|
|
1994
|
-
let a =
|
|
1995
|
+
let a = lt.has(n.localName) && !["table", "hr"].includes(n.localName), o = e.startsWith("padding") && !i && (!a || !["padding-left", "padding-right"].includes(e)) || e.startsWith("border") && !i && n.localName !== "table" || e === "font-size" && ft(r) === void 0 || ["color", "background-color"].includes(e) && dt(r) === void 0, s = (n.localName === "tr" || n.localName === "img") && e === "height" && Z(r) !== void 0 && Z(r) >= 0;
|
|
1995
1996
|
(o || !s && !j.has(e) && !/^border-(top|right|bottom|left)-(width|style|color)$/.test(e)) && B(t, "html-style-approximation", `Стиль ${e} может измениться при открытии HTML в DOCX-редакторе.`, "warning", {
|
|
1996
1997
|
stage: "import",
|
|
1997
1998
|
location: { htmlPath: p.get(n) },
|
|
@@ -2000,42 +2001,42 @@ async function ot(e, t, n = R(), r) {
|
|
|
2000
2001
|
}
|
|
2001
2002
|
let M = new b();
|
|
2002
2003
|
M.file("[Content_Types].xml", "<Types xmlns=\"http://schemas.openxmlformats.org/package/2006/content-types\"><Default Extension=\"rels\" ContentType=\"application/vnd.openxmlformats-package.relationships+xml\"/><Default Extension=\"xml\" ContentType=\"application/xml\"/><Override PartName=\"/word/document.xml\" ContentType=\"application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml\"/><Override PartName=\"/word/styles.xml\" ContentType=\"application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml\"/><Override PartName=\"/word/numbering.xml\" ContentType=\"application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml\"/></Types>"), M.file("_rels/.rels", "<Relationships xmlns=\"http://schemas.openxmlformats.org/package/2006/relationships\"><Relationship Id=\"rId1\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument\" Target=\"word/document.xml\"/></Relationships>"), M.file("word/_rels/document.xml.rels", "<Relationships xmlns=\"http://schemas.openxmlformats.org/package/2006/relationships\"><Relationship Id=\"rIdStyles\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles\" Target=\"styles.xml\"/><Relationship Id=\"rIdNumbering\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering\" Target=\"numbering.xml\"/></Relationships>");
|
|
2003
|
-
let N = n.page, P = "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
|
|
2004
|
+
let N = n.page, P = "http://schemas.openxmlformats.org/officeDocument/2006/relationships", F = A.map(({ kind: e }) => `<w:${e}Reference w:type="default" r:id="rId${e}"/>`).join("");
|
|
2004
2005
|
for (let { kind: e, xml: t } of A) M.file(`word/${e}1.xml`, `<w:${e === "header" ? "hdr" : "ftr"} xmlns:w="${V}">${t}</w:${e === "header" ? "hdr" : "ftr"}>`);
|
|
2005
|
-
let
|
|
2006
|
-
M.file("[Content_Types].xml",
|
|
2007
|
-
let
|
|
2008
|
-
if (M.file("word/_rels/document.xml.rels",
|
|
2006
|
+
let ee = await M.file("[Content_Types].xml").async("string");
|
|
2007
|
+
M.file("[Content_Types].xml", ee.replace("</Types>", A.map(({ kind: e }) => `<Override PartName="/word/${e}1.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.${e}+xml"/>`).join("") + "</Types>"));
|
|
2008
|
+
let I = await M.file("word/_rels/document.xml.rels").async("string");
|
|
2009
|
+
if (M.file("word/_rels/document.xml.rels", I.replace("</Relationships>", A.map(({ kind: e }) => `<Relationship Id="rId${e}" Type="${P}/${e}" Target="${e}1.xml"/>`).join("") + "</Relationships>")), l.size) {
|
|
2009
2010
|
M.file("[Content_Types].xml", (await M.file("[Content_Types].xml").async("string")).replace("</Types>", "<Default Extension=\"png\" ContentType=\"image/png\"/><Default Extension=\"jpg\" ContentType=\"image/jpeg\"/></Types>"));
|
|
2010
2011
|
for (let e of l.values()) M.file(`word/${e.path}`, e.data);
|
|
2011
2012
|
for (let [e, t] of u) {
|
|
2012
2013
|
let n = `word/_rels/${e.slice(5)}.rels`, r = await M.file(n)?.async("string") ?? "<Relationships xmlns=\"http://schemas.openxmlformats.org/package/2006/relationships\"></Relationships>", i = Array.from(t, (e) => {
|
|
2013
2014
|
let t = l.get(e);
|
|
2014
|
-
return `<Relationship Id="rIdImage${t.id}" Type="${
|
|
2015
|
+
return `<Relationship Id="rIdImage${t.id}" Type="${qe}/image" Target="${t.path}"/>`;
|
|
2015
2016
|
}).join("");
|
|
2016
2017
|
M.file(n, r.replace("</Relationships>", i + "</Relationships>"));
|
|
2017
2018
|
}
|
|
2018
2019
|
}
|
|
2019
|
-
return M.file("word/document.xml", `<w:document xmlns:w="${V}" xmlns:r="${P}"><w:body>${k}<w:sectPr>${
|
|
2020
|
+
return M.file("word/document.xml", `<w:document xmlns:w="${V}" xmlns:r="${P}"><w:body>${k}<w:sectPr>${F}<w:pgSz w:w="${N.widthTwips}" w:h="${N.heightTwips}" w:orient="${N.orientation}"/><w:pgMar ${Object.entries(N.margins).map(([e, t]) => `w:${e}="${t}"`).join(" ")}/></w:sectPr></w:body></w:document>`), M.file("word/styles.xml", `<w:styles xmlns:w="${V}"><w:docDefaults><w:rPrDefault><w:rPr>${y(v)}</w:rPr></w:rPrDefault></w:docDefaults><w:style w:type="paragraph" w:default="1" w:styleId="Normal"><w:name w:val="Normal"/><w:pPr><w:spacing w:after="120"/></w:pPr></w:style><w:style w:type="paragraph" w:styleId="AzHujjatListContinuation"><w:name w:val="List continuation"/><w:basedOn w:val="Normal"/></w:style><w:style w:type="paragraph" w:styleId="AzHujjatPageBoundary"><w:name w:val="Page boundary"/><w:basedOn w:val="Normal"/></w:style></w:styles>`), M.file("word/numbering.xml", `<w:numbering xmlns:w="${V}">${s.map(({ id: e, tag: t }) => `<w:abstractNum w:abstractNumId="${e}"><w:multiLevelType w:val="singleLevel"/><w:lvl w:ilvl="0"><w:start w:val="1"/><w:numFmt w:val="${t === "ol" ? "decimal" : "bullet"}"/><w:lvlText w:val="${t === "ol" ? "%1." : "•"}"/><w:pPr><w:ind w:left="360" w:hanging="180"/></w:pPr></w:lvl></w:abstractNum><w:num w:numId="${e}"><w:abstractNumId w:val="${e}"/></w:num>`).join("")}</w:numbering>`), new Uint8Array(await M.generateAsync({
|
|
2020
2021
|
type: "arraybuffer",
|
|
2021
2022
|
compression: "DEFLATE"
|
|
2022
2023
|
}));
|
|
2023
2024
|
}
|
|
2024
2025
|
//#endregion
|
|
2025
2026
|
//#region src/library/hujjat/docx.ts
|
|
2026
|
-
async function
|
|
2027
|
+
async function gt(e, t) {
|
|
2027
2028
|
let n = t.page === void 0 ? t.locales?.[t.locale]?.page : t.page;
|
|
2028
|
-
|
|
2029
|
-
let r = await
|
|
2030
|
-
return i.warnings.unshift(...r.warnings), i.layout = r.layout, i.page =
|
|
2031
|
-
}
|
|
2032
|
-
async function
|
|
2033
|
-
let r =
|
|
2034
|
-
r.page =
|
|
2035
|
-
let i =
|
|
2036
|
-
|
|
2037
|
-
let a = await
|
|
2038
|
-
return
|
|
2029
|
+
We(n);
|
|
2030
|
+
let r = await tt(e, t.layout, n), i = Ae(t.locales ?? {}, t.locale, r.html);
|
|
2031
|
+
return i.warnings.unshift(...r.warnings), i.layout = r.layout, i.page = Ge(r.page, i), i.page !== void 0 && (i.locales[t.locale].page = structuredClone(i.page)), ge(i.warnings, t.allowLossy), i;
|
|
2032
|
+
}
|
|
2033
|
+
async function _t(e, t, n = {}) {
|
|
2034
|
+
let r = De(ke(e, t));
|
|
2035
|
+
r.page = Ge(e[t]?.page, r);
|
|
2036
|
+
let i = Ke(r.page, n.layout);
|
|
2037
|
+
fe(i.page, Ke(r.page).page) || B(r.warnings, "layout-not-carried-by-html", "Геометрия layout отличается от настроек page на сервере. Текущий PDF-контракт поддерживает только ориентацию A4 и фиксированные поля.", "warning", { stage: "import" });
|
|
2038
|
+
let a = await ht(r.html, r.warnings, i, r.page);
|
|
2039
|
+
return ge(r.warnings, n.allowLossy), {
|
|
2039
2040
|
...r,
|
|
2040
2041
|
document: a,
|
|
2041
2042
|
layout: i
|
|
@@ -2043,7 +2044,7 @@ async function ct(e, t, n = {}) {
|
|
|
2043
2044
|
}
|
|
2044
2045
|
//#endregion
|
|
2045
2046
|
//#region src/library/document-diagnostics.ts
|
|
2046
|
-
async function
|
|
2047
|
+
async function vt(e) {
|
|
2047
2048
|
if (e.byteLength > 31457280) throw new z("DOCX превышает 30 МиБ.");
|
|
2048
2049
|
let t = await b.loadAsync(e);
|
|
2049
2050
|
if (Object.keys(t.files).length > 2e3) throw new z("В DOCX более 2000 частей.");
|
|
@@ -2071,13 +2072,13 @@ async function lt(e) {
|
|
|
2071
2072
|
let n = {
|
|
2072
2073
|
part: "word/document.xml",
|
|
2073
2074
|
paragraphIndex: t
|
|
2074
|
-
}, r = U(e, "pPr"), i = d(G(r, "pStyle") || W(u, "styleId")), o =
|
|
2075
|
+
}, r = U(e, "pPr"), i = d(G(r, "pStyle") || W(u, "styleId")), o = ze([
|
|
2075
2076
|
s,
|
|
2076
2077
|
...i.map((e) => U(e, "pPr")),
|
|
2077
2078
|
r
|
|
2078
|
-
]), l =
|
|
2079
|
+
]), l = Pe(c, i.map((e) => U(e, "rPr"))), f = [Y(U(r, "rPr"), l)];
|
|
2079
2080
|
Array.from(e.getElementsByTagNameNS(V, "r")).forEach((e, t) => {
|
|
2080
|
-
let r = U(e, "rPr"), i = Y(r,
|
|
2081
|
+
let r = U(e, "rPr"), i = Y(r, Pe(l, d(G(r, "rStyle")).map((e) => U(e, "rPr"))));
|
|
2081
2082
|
i["--az-hidden"] !== "1" && (f.push(i), Number(i["--az-position"]) && B(a, "source-baseline-shift", "Исходный фрагмент смещён по вертикали; сохранён без нормализации.", "warning", {
|
|
2082
2083
|
stage: "import",
|
|
2083
2084
|
location: {
|
|
@@ -2087,12 +2088,12 @@ async function lt(e) {
|
|
|
2087
2088
|
before: Number(i["--az-position"]) / 2,
|
|
2088
2089
|
after: Number(i["--az-position"]) / 2
|
|
2089
2090
|
}));
|
|
2090
|
-
}), o && (o.rule === "auto" ? o.value < 240 : o.value / 20 <
|
|
2091
|
+
}), o && (o.rule === "auto" ? o.value < 240 : o.value / 20 < Ve(f)) && B(a, "source-tight-spacing", "Авторский тесный интервал сохранён. Проверьте наложение строк на используемых шрифтах.", "warning", {
|
|
2091
2092
|
stage: "import",
|
|
2092
2093
|
location: n,
|
|
2093
2094
|
before: `${o.rule}:${o.value}`,
|
|
2094
2095
|
after: `${o.rule}:${o.value}`
|
|
2095
|
-
}), [...Array.from(e.getElementsByTagNameNS("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "t")).map((e) => e.textContent ?? "").join("").matchAll(/\{([^{}]+)\}/g)].some((e) => !
|
|
2096
|
+
}), [...Array.from(e.getElementsByTagNameNS("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "t")).map((e) => e.textContent ?? "").join("").matchAll(/\{([^{}]+)\}/g)].some((e) => !_e(e[1])) && B(a, "invalid-variable", "В абзаце есть некорректный ключ переменной. Имя и исходный текст не изменены.", "warning", {
|
|
2096
2097
|
stage: "import",
|
|
2097
2098
|
location: n
|
|
2098
2099
|
});
|
|
@@ -2100,7 +2101,7 @@ async function lt(e) {
|
|
|
2100
2101
|
}
|
|
2101
2102
|
//#endregion
|
|
2102
2103
|
//#region src/library/font-diagnostics.ts
|
|
2103
|
-
function
|
|
2104
|
+
function yt(e) {
|
|
2104
2105
|
let t = 0, n = !1, r = !1, i = 0, a = [], o = /* @__PURE__ */ new Set(), s = {
|
|
2105
2106
|
state: typeof e == "function" ? "loading" : "unknown",
|
|
2106
2107
|
warnings: []
|
|
@@ -2126,7 +2127,7 @@ function ut(e) {
|
|
|
2126
2127
|
}
|
|
2127
2128
|
}, u = (e) => {
|
|
2128
2129
|
r = !0, B(a, "font-load-failed", `Не удалось подготовить шрифт (${e}). Разметка может использовать замену или оценочные метрики.`, "warning", { stage: "fonts" }), c();
|
|
2129
|
-
}, d = typeof e == "function" ?
|
|
2130
|
+
}, d = typeof e == "function" ? S(async (n) => {
|
|
2130
2131
|
let r = i;
|
|
2131
2132
|
t++, c();
|
|
2132
2133
|
try {
|
|
@@ -2155,17 +2156,17 @@ function ut(e) {
|
|
|
2155
2156
|
}
|
|
2156
2157
|
//#endregion
|
|
2157
2158
|
//#region src/library/EditorMount.tsx
|
|
2158
|
-
var
|
|
2159
|
-
function
|
|
2160
|
-
let t =
|
|
2159
|
+
var bt = /* @__PURE__ */ new WeakMap(), xt = e(() => {});
|
|
2160
|
+
function St(e) {
|
|
2161
|
+
let t = bt.get(e);
|
|
2161
2162
|
return t || (t = {
|
|
2162
2163
|
count: 0,
|
|
2163
2164
|
overflow: e.body.style.overflow
|
|
2164
|
-
},
|
|
2165
|
-
--t.count === 0 && (e.body.style.overflow = t.overflow,
|
|
2165
|
+
}, bt.set(e, t), e.body.style.overflow = "hidden"), ++t.count, () => {
|
|
2166
|
+
--t.count === 0 && (e.body.style.overflow = t.overflow, bt.delete(e));
|
|
2166
2167
|
};
|
|
2167
2168
|
}
|
|
2168
|
-
function
|
|
2169
|
+
function Ct({ expanded: e, onCollapse: t, retainSelection: r, className: i, style: a, children: s }) {
|
|
2169
2170
|
let u = c(null), d = c(t), f = c(r), p = c(null), m = n(() => {
|
|
2170
2171
|
p.current?.(), p.current = null;
|
|
2171
2172
|
}, []);
|
|
@@ -2221,7 +2222,7 @@ function mt({ expanded: e, onCollapse: t, retainSelection: r, className: i, styl
|
|
|
2221
2222
|
]) t.removeEventListener(e, g, !0);
|
|
2222
2223
|
};
|
|
2223
2224
|
if (!e) return _;
|
|
2224
|
-
let v =
|
|
2225
|
+
let v = St(t), y = (e) => {
|
|
2225
2226
|
e.key !== "Escape" || e.defaultPrevented || t.querySelectorAll("[data-az-fullscreen=\"true\"]").item(t.querySelectorAll("[data-az-fullscreen=\"true\"]").length - 1) === h && (Array.from(t.querySelectorAll("[role=\"dialog\"], [role=\"menu\"], [role=\"listbox\"], [data-az-print-root]")).some((e) => !n.includes(e) && e.getClientRects().length && getComputedStyle(e).visibility !== "hidden") || (e.preventDefault(), e.stopImmediatePropagation(), d.current()));
|
|
2226
2227
|
};
|
|
2227
2228
|
return t.addEventListener("keydown", y, !0), () => {
|
|
@@ -2231,11 +2232,11 @@ function mt({ expanded: e, onCollapse: t, retainSelection: r, className: i, styl
|
|
|
2231
2232
|
h,
|
|
2232
2233
|
e,
|
|
2233
2234
|
i
|
|
2234
|
-
]), /* @__PURE__ */
|
|
2235
|
+
]), /* @__PURE__ */ D("div", {
|
|
2235
2236
|
ref: u,
|
|
2236
2237
|
className: ["az-document-editor", i].filter(Boolean).join(" "),
|
|
2237
2238
|
style: a,
|
|
2238
|
-
children: h &&
|
|
2239
|
+
children: h && T(/* @__PURE__ */ D(xt, {
|
|
2239
2240
|
value: m,
|
|
2240
2241
|
children: s
|
|
2241
2242
|
}), h)
|
|
@@ -2243,20 +2244,20 @@ function mt({ expanded: e, onCollapse: t, retainSelection: r, className: i, styl
|
|
|
2243
2244
|
}
|
|
2244
2245
|
//#endregion
|
|
2245
2246
|
//#region src/library/image-insertion.ts
|
|
2246
|
-
var
|
|
2247
|
-
function
|
|
2247
|
+
var wt = 10485760, Tt = 2048;
|
|
2248
|
+
function Et(e, t) {
|
|
2248
2249
|
if (!e || !t || e > 4096 || t > 4096 || e * t > 16777216) throw Error("Слишком большое изображение. Максимум — 4096 пикселей по стороне и 16 мегапикселей.");
|
|
2249
2250
|
}
|
|
2250
|
-
function
|
|
2251
|
+
function Dt(e, t) {
|
|
2251
2252
|
return new Promise((n, r) => e.toBlob((e) => e ? n(e) : r(/* @__PURE__ */ Error("Не удалось подготовить изображение.")), t, .86));
|
|
2252
2253
|
}
|
|
2253
|
-
async function
|
|
2254
|
-
if (e.size >
|
|
2254
|
+
async function Ot(e, t) {
|
|
2255
|
+
if (e.size > wt) throw Error("Файл слишком большой. Выберите PNG или JPEG размером до 10 МБ.");
|
|
2255
2256
|
t.throwIfAborted();
|
|
2256
2257
|
let n = new Uint8Array(await e.arrayBuffer());
|
|
2257
2258
|
t.throwIfAborted();
|
|
2258
|
-
let r =
|
|
2259
|
-
|
|
2259
|
+
let r = ae(n);
|
|
2260
|
+
Et(r.width, r.height);
|
|
2260
2261
|
let i;
|
|
2261
2262
|
try {
|
|
2262
2263
|
i = await createImageBitmap(new Blob([n], { type: r.mime }), { imageOrientation: "from-image" });
|
|
@@ -2264,18 +2265,18 @@ async function yt(e, t) {
|
|
|
2264
2265
|
throw Error("Не удалось прочитать изображение. Выберите исправный PNG или JPEG.");
|
|
2265
2266
|
}
|
|
2266
2267
|
try {
|
|
2267
|
-
t.throwIfAborted(),
|
|
2268
|
-
let n = document.createElement("canvas"), a = Math.min(1,
|
|
2268
|
+
t.throwIfAborted(), Et(i.width, i.height);
|
|
2269
|
+
let n = document.createElement("canvas"), a = Math.min(1, Tt / Math.max(i.width, i.height));
|
|
2269
2270
|
for (let o = 0; o < 18; o++) {
|
|
2270
2271
|
t.throwIfAborted(), n.width = Math.max(1, Math.round(i.width * a)), n.height = Math.max(1, Math.round(i.height * a));
|
|
2271
2272
|
let o = n.getContext("2d");
|
|
2272
2273
|
if (!o) throw Error("Браузер не поддерживает подготовку изображений.");
|
|
2273
2274
|
o.drawImage(i, 0, 0, n.width, n.height);
|
|
2274
|
-
let s = await
|
|
2275
|
+
let s = await Dt(n, r.mime);
|
|
2275
2276
|
if (t.throwIfAborted(), s.size <= 262144) {
|
|
2276
2277
|
let n = new Uint8Array(await s.arrayBuffer());
|
|
2277
2278
|
t.throwIfAborted();
|
|
2278
|
-
let r =
|
|
2279
|
+
let r = ae(n), i = Math.min(.75, 400 / r.width, 500 / r.height);
|
|
2279
2280
|
return {
|
|
2280
2281
|
data: n,
|
|
2281
2282
|
mime: r.mime,
|
|
@@ -2293,10 +2294,10 @@ async function yt(e, t) {
|
|
|
2293
2294
|
}
|
|
2294
2295
|
//#endregion
|
|
2295
2296
|
//#region src/library/ImageInsertControl.tsx
|
|
2296
|
-
function
|
|
2297
|
+
function kt(e, t) {
|
|
2297
2298
|
return e.anchor.paragraphId === t.anchor.paragraphId && e.anchor.offset === t.anchor.offset && e.head.paragraphId === t.head.paragraphId && e.head.offset === t.head.offset;
|
|
2298
2299
|
}
|
|
2299
|
-
function
|
|
2300
|
+
function At({ disabled: e, documentKey: t }) {
|
|
2300
2301
|
let n = h(), r = _((e) => !e.editable || e.isLoading || !!e.isOpening || !!e.parseError), i = e || r, a = c(!1), s = c(null), u = c(null), [d, f] = l(!1), [p, m] = l("");
|
|
2301
2302
|
function v(e) {
|
|
2302
2303
|
e.controller.abort(), e.pin && e.editor.releaseSelection(e.pin), u.current === e && (u.current = null);
|
|
@@ -2315,11 +2316,11 @@ function xt({ disabled: e, documentKey: t }) {
|
|
|
2315
2316
|
e && !e.committing && (v(e), f(!1));
|
|
2316
2317
|
}), g("selectionChange", () => {
|
|
2317
2318
|
let e = u.current;
|
|
2318
|
-
e && e.editor.getDocumentHandle().revision === e.revision && !
|
|
2319
|
+
e && e.editor.getDocumentHandle().revision === e.revision && !kt(e.surface.state().selection, e.selection) && (v(e), f(!1));
|
|
2319
2320
|
});
|
|
2320
2321
|
function y(e) {
|
|
2321
2322
|
let t = e.editor.snapshot();
|
|
2322
|
-
return u.current === e && !e.controller.signal.aborted && a.current && e.editor.surface === e.surface && e.editor.mountGeneration === e.generation && e.editor.getDocumentHandle().revision === e.revision &&
|
|
2323
|
+
return u.current === e && !e.controller.signal.aborted && a.current && e.editor.surface === e.surface && e.editor.mountGeneration === e.generation && e.editor.getDocumentHandle().revision === e.revision && kt(e.surface.state().selection, e.selection) && t.editable && t.selectionCollapsed && !t.isLoading && !t.isOpening && !t.parseError;
|
|
2323
2324
|
}
|
|
2324
2325
|
function b() {
|
|
2325
2326
|
n?.surface && a.current && !d && (u.current && v(u.current), n.snapshot().selectionCollapsed ? (m(""), u.current = {
|
|
@@ -2342,7 +2343,7 @@ function xt({ disabled: e, documentKey: t }) {
|
|
|
2342
2343
|
else {
|
|
2343
2344
|
f(!0);
|
|
2344
2345
|
try {
|
|
2345
|
-
let e = await
|
|
2346
|
+
let e = await Ot(t, n.controller.signal);
|
|
2346
2347
|
if (u.current !== n || !a.current) return;
|
|
2347
2348
|
if (!y(n)) throw Error("Документ или позиция курсора изменились. Выберите изображение ещё раз.");
|
|
2348
2349
|
n.editor.focus();
|
|
@@ -2352,7 +2353,7 @@ function xt({ disabled: e, documentKey: t }) {
|
|
|
2352
2353
|
expectedPackageRevision: n.revision
|
|
2353
2354
|
}, i = n.editor.canExecuteImageCommand(r);
|
|
2354
2355
|
if (!i.ok) throw Error(`Не удалось вставить изображение: ${i.reason}`);
|
|
2355
|
-
let { paragraphId: o, offset: s } = n.selection.anchor, c =
|
|
2356
|
+
let { paragraphId: o, offset: s } = n.selection.anchor, c = j(n.surface.layout(), o, s), l = n.editor.getPageSetup(), d = l ? (l.pageWidthTwips - l.marginsTwips.left - l.marginsTwips.right - (l.gutterTwips ?? 0)) / 20 : 400, f = l ? (l.pageHeightTwips - l.marginsTwips.top - l.marginsTwips.bottom) / 20 : 500, p = c && c.box.width > 0 ? Math.min(c.box.width, d) : d, m = Math.min(1, p / e.widthPoints, f / e.heightPoints);
|
|
2356
2357
|
n.committing = !0;
|
|
2357
2358
|
let h = await n.surface.insertImage({
|
|
2358
2359
|
paragraphId: o,
|
|
@@ -2378,10 +2379,10 @@ function xt({ disabled: e, documentKey: t }) {
|
|
|
2378
2379
|
}
|
|
2379
2380
|
}
|
|
2380
2381
|
}
|
|
2381
|
-
return /* @__PURE__ */
|
|
2382
|
+
return /* @__PURE__ */ O("div", {
|
|
2382
2383
|
className: "az-image-insert-control",
|
|
2383
2384
|
children: [
|
|
2384
|
-
/* @__PURE__ */
|
|
2385
|
+
/* @__PURE__ */ D("button", {
|
|
2385
2386
|
type: "button",
|
|
2386
2387
|
className: "az-image-insert-button",
|
|
2387
2388
|
"aria-label": "Вставить изображение",
|
|
@@ -2390,7 +2391,7 @@ function xt({ disabled: e, documentKey: t }) {
|
|
|
2390
2391
|
"aria-busy": d,
|
|
2391
2392
|
onMouseDown: (e) => e.preventDefault(),
|
|
2392
2393
|
onClick: b,
|
|
2393
|
-
children: /* @__PURE__ */
|
|
2394
|
+
children: /* @__PURE__ */ O("svg", {
|
|
2394
2395
|
width: "20",
|
|
2395
2396
|
height: "20",
|
|
2396
2397
|
viewBox: "0 0 24 24",
|
|
@@ -2399,23 +2400,23 @@ function xt({ disabled: e, documentKey: t }) {
|
|
|
2399
2400
|
strokeWidth: "1.6",
|
|
2400
2401
|
"aria-hidden": "true",
|
|
2401
2402
|
children: [
|
|
2402
|
-
/* @__PURE__ */
|
|
2403
|
+
/* @__PURE__ */ D("rect", {
|
|
2403
2404
|
x: "3",
|
|
2404
2405
|
y: "3",
|
|
2405
2406
|
width: "18",
|
|
2406
2407
|
height: "18",
|
|
2407
2408
|
rx: "2"
|
|
2408
2409
|
}),
|
|
2409
|
-
/* @__PURE__ */
|
|
2410
|
+
/* @__PURE__ */ D("circle", {
|
|
2410
2411
|
cx: "8",
|
|
2411
2412
|
cy: "8",
|
|
2412
2413
|
r: "1.5"
|
|
2413
2414
|
}),
|
|
2414
|
-
/* @__PURE__ */
|
|
2415
|
+
/* @__PURE__ */ D("path", { d: "m3 17 5-5 4 4 4-6 5 7" })
|
|
2415
2416
|
]
|
|
2416
2417
|
})
|
|
2417
2418
|
}),
|
|
2418
|
-
/* @__PURE__ */
|
|
2419
|
+
/* @__PURE__ */ D("input", {
|
|
2419
2420
|
ref: s,
|
|
2420
2421
|
type: "file",
|
|
2421
2422
|
accept: "image/png,image/jpeg,.png,.jpg,.jpeg",
|
|
@@ -2423,7 +2424,7 @@ function xt({ disabled: e, documentKey: t }) {
|
|
|
2423
2424
|
hidden: !0,
|
|
2424
2425
|
onChange: (e) => void x(e)
|
|
2425
2426
|
}),
|
|
2426
|
-
p && /* @__PURE__ */
|
|
2427
|
+
p && /* @__PURE__ */ D("div", {
|
|
2427
2428
|
role: "alert",
|
|
2428
2429
|
className: "az-image-insert-error",
|
|
2429
2430
|
children: p
|
|
@@ -2432,9 +2433,586 @@ function xt({ disabled: e, documentKey: t }) {
|
|
|
2432
2433
|
});
|
|
2433
2434
|
}
|
|
2434
2435
|
//#endregion
|
|
2436
|
+
//#region src/library/image-management.ts
|
|
2437
|
+
var jt = 36e4, Mt = 12700, Nt = (e) => String(Number((e / jt).toFixed(4)));
|
|
2438
|
+
function Pt(e, t) {
|
|
2439
|
+
let n = e.session.partFor(e.storyScope());
|
|
2440
|
+
if (!n) return null;
|
|
2441
|
+
let r = N(n, t);
|
|
2442
|
+
if (r?.kind !== "drawing") return null;
|
|
2443
|
+
let i = F(n, t);
|
|
2444
|
+
for (; i && i.kind !== "paragraph";) i = F(n, i.id);
|
|
2445
|
+
if (i?.kind !== "paragraph") return null;
|
|
2446
|
+
let a = P(i), o = a.spanOf(r);
|
|
2447
|
+
return o ? {
|
|
2448
|
+
drawing: r,
|
|
2449
|
+
paragraph: i,
|
|
2450
|
+
span: o,
|
|
2451
|
+
alone: a.length === o.end - o.start
|
|
2452
|
+
} : null;
|
|
2453
|
+
}
|
|
2454
|
+
function Ft(e, t) {
|
|
2455
|
+
let n = Pt(e, t), r = n && j(e.layout(), n.paragraph.id, n.span.start), i = n && k(e.layout(), {
|
|
2456
|
+
paragraphId: n.paragraph.id,
|
|
2457
|
+
offset: n.span.start
|
|
2458
|
+
}), a = e.layout().pages[i?.pageIndex ?? 0];
|
|
2459
|
+
return {
|
|
2460
|
+
width: Math.min(600, r?.box.width || a?.contentBox.width || 600) * Mt,
|
|
2461
|
+
height: Math.min(600, a?.contentBox.height || 600) * Mt
|
|
2462
|
+
};
|
|
2463
|
+
}
|
|
2464
|
+
function It(e, t, n) {
|
|
2465
|
+
let r = e.state().selection;
|
|
2466
|
+
if (e.selectDrawing(t, n)) return !0;
|
|
2467
|
+
let i = Pt(e, t);
|
|
2468
|
+
if (i && i.drawing.children.some((e) => e.kind === "inlineDrawing")) {
|
|
2469
|
+
let r = {
|
|
2470
|
+
paragraphId: n,
|
|
2471
|
+
offset: i.span.end
|
|
2472
|
+
};
|
|
2473
|
+
if (e.setSelection({
|
|
2474
|
+
anchor: r,
|
|
2475
|
+
head: r
|
|
2476
|
+
}), w(e)?.id === t) return !0;
|
|
2477
|
+
}
|
|
2478
|
+
return e.setSelection(r), !1;
|
|
2479
|
+
}
|
|
2480
|
+
function Lt(e, t, n) {
|
|
2481
|
+
let r = w(e);
|
|
2482
|
+
if (r?.id !== t || !r.canMove) return {
|
|
2483
|
+
rejected: !0,
|
|
2484
|
+
reason: "Перемещение изображения запрещено."
|
|
2485
|
+
};
|
|
2486
|
+
let i = Pt(e, t);
|
|
2487
|
+
if (!i) return {
|
|
2488
|
+
rejected: !0,
|
|
2489
|
+
reason: "Изображение больше не найдено."
|
|
2490
|
+
};
|
|
2491
|
+
let a = n.offset;
|
|
2492
|
+
if (n.paragraphId === i.paragraph.id) {
|
|
2493
|
+
if (a >= i.span.start && a <= i.span.end) return { rejected: !1 };
|
|
2494
|
+
a > i.span.end && (a -= i.span.end - i.span.start);
|
|
2495
|
+
}
|
|
2496
|
+
let o = e.applyDrawingOps([{
|
|
2497
|
+
op: "deleteDrawing",
|
|
2498
|
+
drawingNodeId: t
|
|
2499
|
+
}, {
|
|
2500
|
+
op: "insertDrawing",
|
|
2501
|
+
paragraphId: n.paragraphId,
|
|
2502
|
+
offset: a,
|
|
2503
|
+
drawing: i.drawing
|
|
2504
|
+
}]);
|
|
2505
|
+
if (!o.rejected) {
|
|
2506
|
+
let t = e.session.partFor(e.storyScope()), r = t && N(t, n.paragraphId), i = r?.kind === "paragraph" && P(r).segments.find((e) => e.start === a && e.node.kind === "drawing");
|
|
2507
|
+
i && It(e, i.node.id, n.paragraphId);
|
|
2508
|
+
}
|
|
2509
|
+
return o;
|
|
2510
|
+
}
|
|
2511
|
+
//#endregion
|
|
2512
|
+
//#region src/library/ImageManipulationOverlay.tsx
|
|
2513
|
+
var Rt = [
|
|
2514
|
+
[
|
|
2515
|
+
"nw",
|
|
2516
|
+
0,
|
|
2517
|
+
0,
|
|
2518
|
+
"слева сверху"
|
|
2519
|
+
],
|
|
2520
|
+
[
|
|
2521
|
+
"n",
|
|
2522
|
+
.5,
|
|
2523
|
+
0,
|
|
2524
|
+
"сверху"
|
|
2525
|
+
],
|
|
2526
|
+
[
|
|
2527
|
+
"ne",
|
|
2528
|
+
1,
|
|
2529
|
+
0,
|
|
2530
|
+
"справа сверху"
|
|
2531
|
+
],
|
|
2532
|
+
[
|
|
2533
|
+
"e",
|
|
2534
|
+
1,
|
|
2535
|
+
.5,
|
|
2536
|
+
"справа"
|
|
2537
|
+
],
|
|
2538
|
+
[
|
|
2539
|
+
"se",
|
|
2540
|
+
1,
|
|
2541
|
+
1,
|
|
2542
|
+
"справа снизу"
|
|
2543
|
+
],
|
|
2544
|
+
[
|
|
2545
|
+
"s",
|
|
2546
|
+
.5,
|
|
2547
|
+
1,
|
|
2548
|
+
"снизу"
|
|
2549
|
+
],
|
|
2550
|
+
[
|
|
2551
|
+
"sw",
|
|
2552
|
+
0,
|
|
2553
|
+
1,
|
|
2554
|
+
"слева снизу"
|
|
2555
|
+
],
|
|
2556
|
+
[
|
|
2557
|
+
"w",
|
|
2558
|
+
0,
|
|
2559
|
+
.5,
|
|
2560
|
+
"слева"
|
|
2561
|
+
]
|
|
2562
|
+
];
|
|
2563
|
+
function zt({ host: e, disabled: t, aspect: n, onError: r, documentKey: i }) {
|
|
2564
|
+
let a = h(), s = _((e) => e.image), u = _((e) => e.zoom), [d, f] = l(null), [p, m] = l(null), [v, y] = l(null), [b, S] = l(null), w = c(null), E = c(!t);
|
|
2565
|
+
E.current = !t;
|
|
2566
|
+
let k = () => {
|
|
2567
|
+
w.current = null, y(null), S(null);
|
|
2568
|
+
}, j = () => {
|
|
2569
|
+
let t = (e.current?.closest(".az-editor-frame"))?.querySelector(".docx-content-mount") ?? null;
|
|
2570
|
+
f(t);
|
|
2571
|
+
let n = s && Array.from(t?.querySelectorAll("[data-drawing-node-id]") ?? []).find((e) => e.dataset.drawingNodeId === s.id && !e.closest(".docx-image-selection-overlay")), r = n?.querySelector("img") ?? (n?.tagName === "IMG" ? n : null);
|
|
2572
|
+
if (!t || !r || s?.kind !== "inline") {
|
|
2573
|
+
m(null);
|
|
2574
|
+
return;
|
|
2575
|
+
}
|
|
2576
|
+
let i = r.getBoundingClientRect(), a = t.getBoundingClientRect();
|
|
2577
|
+
m({
|
|
2578
|
+
left: i.left - a.left,
|
|
2579
|
+
top: i.top - a.top,
|
|
2580
|
+
width: i.width,
|
|
2581
|
+
height: i.height
|
|
2582
|
+
});
|
|
2583
|
+
};
|
|
2584
|
+
g("change", () => {
|
|
2585
|
+
k(), queueMicrotask(j);
|
|
2586
|
+
}), g("selectionChange", () => {
|
|
2587
|
+
a?.getSelectedImage()?.id !== w.current?.id && k(), queueMicrotask(j);
|
|
2588
|
+
}), o(() => {
|
|
2589
|
+
j();
|
|
2590
|
+
let t = e.current?.closest(".az-editor-frame"), n = t?.querySelector(".docx-editor__scroll-container"), r = new ResizeObserver(j);
|
|
2591
|
+
t && r.observe(t);
|
|
2592
|
+
let i = t?.querySelector(".docx-paginated-surface");
|
|
2593
|
+
return i && r.observe(i), n?.addEventListener("scroll", j), () => {
|
|
2594
|
+
r.disconnect(), n?.removeEventListener("scroll", j), k();
|
|
2595
|
+
};
|
|
2596
|
+
}, [
|
|
2597
|
+
a,
|
|
2598
|
+
s?.id,
|
|
2599
|
+
s?.widthEmu,
|
|
2600
|
+
s?.heightEmu,
|
|
2601
|
+
u,
|
|
2602
|
+
i
|
|
2603
|
+
]), o(() => {
|
|
2604
|
+
t && k();
|
|
2605
|
+
}, [t]);
|
|
2606
|
+
function N(e, t) {
|
|
2607
|
+
!E.current || !s || !a?.surface || !p || e.button !== 0 || (t ? !s.canResize : !s.canMove) || (e.preventDefault(), e.stopPropagation(), a.focus(), w.current = {
|
|
2608
|
+
id: s.id,
|
|
2609
|
+
revision: a.getDocumentHandle().revision,
|
|
2610
|
+
generation: a.mountGeneration,
|
|
2611
|
+
pointerId: e.pointerId,
|
|
2612
|
+
x: e.clientX,
|
|
2613
|
+
y: e.clientY,
|
|
2614
|
+
start: p,
|
|
2615
|
+
width: s.widthEmu,
|
|
2616
|
+
height: s.heightEmu,
|
|
2617
|
+
scale: a.surface.overlayCoordinates().paintScale,
|
|
2618
|
+
handle: t,
|
|
2619
|
+
moved: !1,
|
|
2620
|
+
size: {
|
|
2621
|
+
cx: s.widthEmu,
|
|
2622
|
+
cy: s.heightEmu
|
|
2623
|
+
},
|
|
2624
|
+
caret: null
|
|
2625
|
+
}, e.currentTarget.setPointerCapture(e.pointerId));
|
|
2626
|
+
}
|
|
2627
|
+
o(() => {
|
|
2628
|
+
if (!a || !d) return;
|
|
2629
|
+
let e = (e) => E.current && a.mountGeneration === e.generation && a.getDocumentHandle().revision === e.revision && a.getSelectedImage()?.id === e.id, t = (t) => {
|
|
2630
|
+
let r = w.current, i = a.surface;
|
|
2631
|
+
if (!r || !i || t.pointerId !== r.pointerId) return;
|
|
2632
|
+
if (!e(r)) {
|
|
2633
|
+
k();
|
|
2634
|
+
return;
|
|
2635
|
+
}
|
|
2636
|
+
let o = t.clientX - r.x, s = t.clientY - r.y;
|
|
2637
|
+
if (r.moved ||= Math.hypot(o, s) >= 3, r.moved) {
|
|
2638
|
+
if (t.preventDefault(), r.handle) {
|
|
2639
|
+
let e = x(r.width, r.height, r.handle, o / r.scale, s / r.scale, n), t = Ft(i, r.id);
|
|
2640
|
+
if (n) {
|
|
2641
|
+
let n = Math.min(1, t.width / e.cx, t.height / e.cy);
|
|
2642
|
+
e = {
|
|
2643
|
+
cx: Math.round(e.cx * n),
|
|
2644
|
+
cy: Math.round(e.cy * n)
|
|
2645
|
+
};
|
|
2646
|
+
} else e = {
|
|
2647
|
+
cx: Math.min(e.cx, t.width),
|
|
2648
|
+
cy: Math.min(e.cy, t.height)
|
|
2649
|
+
};
|
|
2650
|
+
r.size = e;
|
|
2651
|
+
let a = e.cx / Mt * r.scale, c = e.cy / Mt * r.scale;
|
|
2652
|
+
y({
|
|
2653
|
+
left: r.start.left + (r.handle.includes("w") ? r.start.width - a : 0),
|
|
2654
|
+
top: r.start.top + (r.handle.includes("n") ? r.start.height - c : 0),
|
|
2655
|
+
width: a,
|
|
2656
|
+
height: c
|
|
2657
|
+
});
|
|
2658
|
+
} else {
|
|
2659
|
+
let e = d.querySelector(".docx-paginated-surface");
|
|
2660
|
+
if (!e || i.storyScope().kind !== "body") {
|
|
2661
|
+
r.caret = null, S(null);
|
|
2662
|
+
return;
|
|
2663
|
+
}
|
|
2664
|
+
let n = e.getBoundingClientRect(), a = d.closest(".docx-editor__scroll-container"), o = a?.getBoundingClientRect();
|
|
2665
|
+
if (o && (t.clientY < o.top || t.clientY > o.bottom || t.clientX < o.left || t.clientX > o.right)) {
|
|
2666
|
+
r.caret = null, S(null);
|
|
2667
|
+
return;
|
|
2668
|
+
}
|
|
2669
|
+
let s = i.layout(), c = i.overlayCoordinates(), l = M(s, (t.clientY - n.top) / c.paintScale), u = C(s, {
|
|
2670
|
+
pageIndex: l,
|
|
2671
|
+
x: 0,
|
|
2672
|
+
y: 0,
|
|
2673
|
+
width: 0,
|
|
2674
|
+
height: 0
|
|
2675
|
+
}, c);
|
|
2676
|
+
if (r.caret = A(s, l, {
|
|
2677
|
+
x: (t.clientX - n.left - u.left) / c.paintScale,
|
|
2678
|
+
y: (t.clientY - n.top - u.top) / c.paintScale
|
|
2679
|
+
})?.caret ?? null, r.caret) {
|
|
2680
|
+
let e = C(s, {
|
|
2681
|
+
...r.caret,
|
|
2682
|
+
width: 2 / c.paintScale
|
|
2683
|
+
}, c), i = d.getBoundingClientRect();
|
|
2684
|
+
S({
|
|
2685
|
+
left: n.left - i.left + e.left,
|
|
2686
|
+
top: n.top - i.top + e.top,
|
|
2687
|
+
width: 2,
|
|
2688
|
+
height: e.height
|
|
2689
|
+
});
|
|
2690
|
+
let l = a;
|
|
2691
|
+
l && o && (t.clientY > o.bottom - 30 ? l.scrollTop += 12 : t.clientY < o.top + 30 && (l.scrollTop -= 12));
|
|
2692
|
+
} else S(null);
|
|
2693
|
+
}
|
|
2694
|
+
}
|
|
2695
|
+
}, i = (n) => {
|
|
2696
|
+
let i = w.current;
|
|
2697
|
+
if (i && n.pointerId === i.pointerId) {
|
|
2698
|
+
if (t(n), e(i) && i.moved && a.surface) {
|
|
2699
|
+
if (i.handle) {
|
|
2700
|
+
let e = a.exec({
|
|
2701
|
+
type: "setImageProperties",
|
|
2702
|
+
drawingNodeId: i.id,
|
|
2703
|
+
expectedPackageRevision: i.revision,
|
|
2704
|
+
widthEmu: i.size.cx,
|
|
2705
|
+
heightEmu: i.size.cy
|
|
2706
|
+
});
|
|
2707
|
+
e.ok || r(e.reason);
|
|
2708
|
+
} else if (i.caret) {
|
|
2709
|
+
let e = Lt(a.surface, i.id, i.caret.position);
|
|
2710
|
+
e.rejected && r(`Не удалось перенести изображение: ${e.reason ?? "выберите другую позицию в тексте"}`);
|
|
2711
|
+
}
|
|
2712
|
+
}
|
|
2713
|
+
k(), j(), a.focus();
|
|
2714
|
+
}
|
|
2715
|
+
}, o = (e) => {
|
|
2716
|
+
w.current && e.key === "Escape" && (e.preventDefault(), e.stopPropagation(), k());
|
|
2717
|
+
};
|
|
2718
|
+
return window.addEventListener("pointermove", t), window.addEventListener("pointerup", i), window.addEventListener("pointercancel", k), window.addEventListener("keydown", o, !0), () => {
|
|
2719
|
+
window.removeEventListener("pointermove", t), window.removeEventListener("pointerup", i), window.removeEventListener("pointercancel", k), window.removeEventListener("keydown", o, !0);
|
|
2720
|
+
};
|
|
2721
|
+
}, [
|
|
2722
|
+
a,
|
|
2723
|
+
d,
|
|
2724
|
+
n,
|
|
2725
|
+
s?.id,
|
|
2726
|
+
t
|
|
2727
|
+
]);
|
|
2728
|
+
let P = v ?? p;
|
|
2729
|
+
return !d || !P || s?.kind !== "inline" || t ? null : T(/* @__PURE__ */ O("div", {
|
|
2730
|
+
className: "az-image-overlay",
|
|
2731
|
+
children: [
|
|
2732
|
+
/* @__PURE__ */ D("div", {
|
|
2733
|
+
className: "az-image-frame",
|
|
2734
|
+
style: {
|
|
2735
|
+
...P,
|
|
2736
|
+
cursor: s.canMove ? "grab" : "default"
|
|
2737
|
+
},
|
|
2738
|
+
role: "group",
|
|
2739
|
+
"aria-label": "Выбранное изображение",
|
|
2740
|
+
onPointerDown: (e) => N(e, null)
|
|
2741
|
+
}),
|
|
2742
|
+
s.canResize && Rt.map(([e, t, n, r]) => /* @__PURE__ */ D("button", {
|
|
2743
|
+
type: "button",
|
|
2744
|
+
className: `az-image-handle az-image-handle--${e}`,
|
|
2745
|
+
"aria-label": `Изменить размер ${r}`,
|
|
2746
|
+
title: `Изменить размер ${r}`,
|
|
2747
|
+
style: {
|
|
2748
|
+
left: P.left + P.width * t - 5,
|
|
2749
|
+
top: P.top + P.height * n - 5
|
|
2750
|
+
},
|
|
2751
|
+
onPointerDown: (t) => N(t, e)
|
|
2752
|
+
}, e)),
|
|
2753
|
+
b && /* @__PURE__ */ D("div", {
|
|
2754
|
+
className: "az-image-drop-marker",
|
|
2755
|
+
style: b,
|
|
2756
|
+
"aria-label": "Место вставки изображения"
|
|
2757
|
+
})
|
|
2758
|
+
]
|
|
2759
|
+
}), d);
|
|
2760
|
+
}
|
|
2761
|
+
//#endregion
|
|
2762
|
+
//#region src/library/ImageControls.tsx
|
|
2763
|
+
function Bt({ disabled: e, documentKey: t }) {
|
|
2764
|
+
let n = h(), r = _((e) => e.image), a = _((e) => !e.editable || e.isLoading || !!e.isOpening || !!e.parseError), s = !!(e || a), u = c(!s), d = c(null), f = c(null), p = c(null), m = c(!1), [v, y] = l(!1), [b, x] = l(""), [S, C] = l(""), [w, T] = l(""), [E, k] = l(null), [A, j] = l(!0), [M, N] = l(""), P = () => {
|
|
2765
|
+
p.current?.controller.abort(), p.current = null, y(!1);
|
|
2766
|
+
};
|
|
2767
|
+
o(() => {
|
|
2768
|
+
u.current = !s, s && P();
|
|
2769
|
+
}, [s]), o(() => () => {
|
|
2770
|
+
p.current?.controller.abort(), p.current = null;
|
|
2771
|
+
}, [n, t]), i(() => {
|
|
2772
|
+
let e = f.current;
|
|
2773
|
+
return e?.addEventListener("cancel", P), () => e?.removeEventListener("cancel", P);
|
|
2774
|
+
}, []), i(() => {
|
|
2775
|
+
j(!0), x("");
|
|
2776
|
+
}, [r?.id]), i(() => {
|
|
2777
|
+
C(r ? Nt(r.widthEmu) : ""), T(r ? Nt(r.heightEmu) : ""), k(null);
|
|
2778
|
+
}, [
|
|
2779
|
+
r?.id,
|
|
2780
|
+
r?.widthEmu,
|
|
2781
|
+
r?.heightEmu
|
|
2782
|
+
]), i(() => {
|
|
2783
|
+
N(r?.description ?? "");
|
|
2784
|
+
}, [r?.id, r?.description]), g("change", P), g("selectionChange", () => {
|
|
2785
|
+
p.current && n?.getSelectedImage()?.id !== p.current.id && P();
|
|
2786
|
+
let e = n?.surface, t = e?.drawingSelectionIntent();
|
|
2787
|
+
if (!n || !e || !u.current || m.current || n.getSelectedImage() || t?.kind !== "pointer") return;
|
|
2788
|
+
let r = n.getDocumentHandle().revision, i = n.mountGeneration;
|
|
2789
|
+
m.current = !0, queueMicrotask(() => {
|
|
2790
|
+
try {
|
|
2791
|
+
if (!u.current || n.surface !== e || n.mountGeneration !== i || n.getDocumentHandle().revision !== r || n.getSelectedImage()) return;
|
|
2792
|
+
let a = e.drawingSelectionIntent(), o = Pt(e, t.drawingNodeId), s = e.state().selection;
|
|
2793
|
+
if (a.kind !== "pointer" || a.drawingNodeId !== t.drawingNodeId || !o || s.anchor.paragraphId !== o.paragraph.id || s.head.paragraphId !== o.paragraph.id || s.anchor.offset !== o.span.start || s.head.offset !== o.span.start) return;
|
|
2794
|
+
It(e, t.drawingNodeId, o.paragraph.id);
|
|
2795
|
+
} finally {
|
|
2796
|
+
m.current = !1;
|
|
2797
|
+
}
|
|
2798
|
+
});
|
|
2799
|
+
});
|
|
2800
|
+
let F = r && n?.surface ? Pt(n.surface, r.id) : null;
|
|
2801
|
+
function ee() {
|
|
2802
|
+
if (!n?.surface || !r || !u.current || !E) return;
|
|
2803
|
+
let e = Number((E === "width" ? S : w).replace(",", ".")) * jt, t = E === "width" ? e : A ? e * r.widthEmu / r.heightEmu : Number(S.replace(",", ".")) * jt, i = E === "height" ? e : A ? e * r.heightEmu / r.widthEmu : Number(w.replace(",", ".")) * jt;
|
|
2804
|
+
A || (E === "width" && w === Nt(r.heightEmu) && (i = r.heightEmu), E === "height" && S === Nt(r.widthEmu) && (t = r.widthEmu));
|
|
2805
|
+
let a = Ft(n.surface, r.id);
|
|
2806
|
+
if (![t, i].every((e) => Number.isFinite(e) && e >= 12700) || t > a.width || i > a.height) {
|
|
2807
|
+
x(`Размер должен быть от 0,0353 см и помещаться в область текста (до ${Nt(a.width)} × ${Nt(a.height)} см).`);
|
|
2808
|
+
return;
|
|
2809
|
+
}
|
|
2810
|
+
let o = n.exec({
|
|
2811
|
+
type: "setImageProperties",
|
|
2812
|
+
drawingNodeId: r.id,
|
|
2813
|
+
expectedPackageRevision: n.getDocumentHandle().revision,
|
|
2814
|
+
widthEmu: Math.round(t),
|
|
2815
|
+
heightEmu: Math.round(i)
|
|
2816
|
+
});
|
|
2817
|
+
x(o.ok ? "" : o.reason), o.ok && n.focus();
|
|
2818
|
+
}
|
|
2819
|
+
function I(e, t) {
|
|
2820
|
+
k(t), t === "width" ? (C(e), A && r && T(Nt(Number(e.replace(",", ".")) * jt * r.heightEmu / r.widthEmu))) : (T(e), A && r && C(Nt(Number(e.replace(",", ".")) * jt * r.widthEmu / r.heightEmu)));
|
|
2821
|
+
}
|
|
2822
|
+
function te() {
|
|
2823
|
+
n && r && u.current && !v && (P(), x(""), p.current = {
|
|
2824
|
+
controller: new AbortController(),
|
|
2825
|
+
id: r.id,
|
|
2826
|
+
revision: n.getDocumentHandle().revision,
|
|
2827
|
+
generation: n.mountGeneration
|
|
2828
|
+
}, f.current && (f.current.value = "", f.current.click()));
|
|
2829
|
+
}
|
|
2830
|
+
async function ne(e) {
|
|
2831
|
+
let t = e.target.files?.[0];
|
|
2832
|
+
e.target.value = "";
|
|
2833
|
+
let r = p.current, i = n?.surface;
|
|
2834
|
+
if (!r || !t || !n || !i) {
|
|
2835
|
+
P();
|
|
2836
|
+
return;
|
|
2837
|
+
}
|
|
2838
|
+
let a = () => p.current === r && !r.controller.signal.aborted && u.current && n.surface === i && n.mountGeneration === r.generation && n.getDocumentHandle().revision === r.revision && n.getSelectedImage()?.id === r.id;
|
|
2839
|
+
y(!0);
|
|
2840
|
+
try {
|
|
2841
|
+
let e = await Ot(t, r.controller.signal);
|
|
2842
|
+
if (!a()) return;
|
|
2843
|
+
let o = {
|
|
2844
|
+
type: "replaceImage",
|
|
2845
|
+
drawingNodeId: r.id,
|
|
2846
|
+
data: e.data,
|
|
2847
|
+
mime: e.mime,
|
|
2848
|
+
expectedPackageRevision: r.revision
|
|
2849
|
+
}, s = n.canExecuteImageCommand(o);
|
|
2850
|
+
if (!s.ok) throw Error(s.reason);
|
|
2851
|
+
let c = await i.replaceImage(r.id, e.data, e.mime, {
|
|
2852
|
+
expectedPackageRevision: r.revision,
|
|
2853
|
+
commitGuard: a
|
|
2854
|
+
});
|
|
2855
|
+
if (!c.ok) throw Error(c.detail ?? c.reason);
|
|
2856
|
+
n.focus();
|
|
2857
|
+
} catch (e) {
|
|
2858
|
+
r.controller.signal.aborted || x(e instanceof Error ? e.message : "Не удалось заменить изображение.");
|
|
2859
|
+
} finally {
|
|
2860
|
+
p.current === r && P();
|
|
2861
|
+
}
|
|
2862
|
+
}
|
|
2863
|
+
return /* @__PURE__ */ O("div", {
|
|
2864
|
+
ref: d,
|
|
2865
|
+
className: "az-image-controls-host",
|
|
2866
|
+
children: [
|
|
2867
|
+
r?.kind === "inline" && /* @__PURE__ */ O("section", {
|
|
2868
|
+
className: "az-image-controls",
|
|
2869
|
+
"aria-label": "Параметры изображения",
|
|
2870
|
+
children: [
|
|
2871
|
+
/* @__PURE__ */ D("strong", { children: "Изображение" }),
|
|
2872
|
+
/* @__PURE__ */ O("fieldset", {
|
|
2873
|
+
disabled: s || v,
|
|
2874
|
+
children: [
|
|
2875
|
+
/* @__PURE__ */ O("form", {
|
|
2876
|
+
onSubmit: (e) => {
|
|
2877
|
+
e.preventDefault(), ee();
|
|
2878
|
+
},
|
|
2879
|
+
className: "az-image-size",
|
|
2880
|
+
children: [
|
|
2881
|
+
/* @__PURE__ */ O("label", { children: ["Ширина, см", /* @__PURE__ */ D("input", {
|
|
2882
|
+
"aria-label": "Ширина, см",
|
|
2883
|
+
inputMode: "decimal",
|
|
2884
|
+
value: S,
|
|
2885
|
+
onChange: (e) => I(e.target.value, "width")
|
|
2886
|
+
})] }),
|
|
2887
|
+
/* @__PURE__ */ O("label", { children: ["Высота, см", /* @__PURE__ */ D("input", {
|
|
2888
|
+
"aria-label": "Высота, см",
|
|
2889
|
+
inputMode: "decimal",
|
|
2890
|
+
value: w,
|
|
2891
|
+
onChange: (e) => I(e.target.value, "height")
|
|
2892
|
+
})] }),
|
|
2893
|
+
/* @__PURE__ */ O("label", {
|
|
2894
|
+
className: "az-image-aspect",
|
|
2895
|
+
children: [/* @__PURE__ */ D("input", {
|
|
2896
|
+
type: "checkbox",
|
|
2897
|
+
checked: A,
|
|
2898
|
+
onChange: (e) => j(e.target.checked)
|
|
2899
|
+
}), "Сохранять пропорции"]
|
|
2900
|
+
}),
|
|
2901
|
+
/* @__PURE__ */ D("button", {
|
|
2902
|
+
type: "submit",
|
|
2903
|
+
disabled: !r.canResize || !E,
|
|
2904
|
+
children: "Применить размер"
|
|
2905
|
+
})
|
|
2906
|
+
]
|
|
2907
|
+
}),
|
|
2908
|
+
/* @__PURE__ */ D("div", {
|
|
2909
|
+
className: "az-image-alignment",
|
|
2910
|
+
"aria-label": "Выравнивание изображения",
|
|
2911
|
+
title: F?.alone ? void 0 : "Выравнивание доступно для изображения в отдельном абзаце.",
|
|
2912
|
+
children: [
|
|
2913
|
+
"left",
|
|
2914
|
+
"center",
|
|
2915
|
+
"right"
|
|
2916
|
+
].map((e, t) => /* @__PURE__ */ D("button", {
|
|
2917
|
+
type: "button",
|
|
2918
|
+
disabled: !F?.alone,
|
|
2919
|
+
"aria-label": [
|
|
2920
|
+
"Изображение слева",
|
|
2921
|
+
"Изображение по центру",
|
|
2922
|
+
"Изображение справа"
|
|
2923
|
+
][t],
|
|
2924
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
2925
|
+
onClick: () => {
|
|
2926
|
+
if (!u.current || !n || !F?.alone) return;
|
|
2927
|
+
let t = n.exec({
|
|
2928
|
+
type: "setAlignment",
|
|
2929
|
+
align: e
|
|
2930
|
+
});
|
|
2931
|
+
x(t.ok ? "" : t.reason), n.focus();
|
|
2932
|
+
},
|
|
2933
|
+
children: [
|
|
2934
|
+
"Слева",
|
|
2935
|
+
"По центру",
|
|
2936
|
+
"Справа"
|
|
2937
|
+
][t]
|
|
2938
|
+
}, e))
|
|
2939
|
+
}),
|
|
2940
|
+
/* @__PURE__ */ O("form", {
|
|
2941
|
+
className: "az-image-description",
|
|
2942
|
+
onSubmit: (e) => {
|
|
2943
|
+
if (e.preventDefault(), !u.current || !n || !r) return;
|
|
2944
|
+
let t = n.exec({
|
|
2945
|
+
type: "setImageProperties",
|
|
2946
|
+
drawingNodeId: r.id,
|
|
2947
|
+
description: M
|
|
2948
|
+
});
|
|
2949
|
+
x(t.ok ? "" : t.reason), t.ok && n.focus();
|
|
2950
|
+
},
|
|
2951
|
+
children: [/* @__PURE__ */ O("label", { children: ["Описание изображения", /* @__PURE__ */ D("input", {
|
|
2952
|
+
"aria-label": "Описание изображения",
|
|
2953
|
+
maxLength: 500,
|
|
2954
|
+
value: M,
|
|
2955
|
+
onChange: (e) => N(e.target.value)
|
|
2956
|
+
})] }), /* @__PURE__ */ D("button", {
|
|
2957
|
+
type: "submit",
|
|
2958
|
+
children: "Сохранить описание"
|
|
2959
|
+
})]
|
|
2960
|
+
}),
|
|
2961
|
+
/* @__PURE__ */ D("button", {
|
|
2962
|
+
type: "button",
|
|
2963
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
2964
|
+
onClick: te,
|
|
2965
|
+
children: v ? "Подготовка…" : "Заменить изображение"
|
|
2966
|
+
}),
|
|
2967
|
+
/* @__PURE__ */ D("button", {
|
|
2968
|
+
type: "button",
|
|
2969
|
+
className: "az-image-delete",
|
|
2970
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
2971
|
+
onClick: () => {
|
|
2972
|
+
if (!u.current || !n || !r) return;
|
|
2973
|
+
let e = n.exec({
|
|
2974
|
+
type: "deleteImage",
|
|
2975
|
+
drawingNodeId: r.id
|
|
2976
|
+
});
|
|
2977
|
+
x(e.ok ? "" : e.reason), e.ok && n.focus();
|
|
2978
|
+
},
|
|
2979
|
+
children: "Удалить изображение"
|
|
2980
|
+
})
|
|
2981
|
+
]
|
|
2982
|
+
}),
|
|
2983
|
+
/* @__PURE__ */ D("span", {
|
|
2984
|
+
className: "az-image-hint",
|
|
2985
|
+
children: "Перетащите изображение в нужное место текста. Размер меняется за маркеры рамки."
|
|
2986
|
+
})
|
|
2987
|
+
]
|
|
2988
|
+
}),
|
|
2989
|
+
/* @__PURE__ */ D("input", {
|
|
2990
|
+
ref: f,
|
|
2991
|
+
type: "file",
|
|
2992
|
+
accept: "image/png,image/jpeg,.png,.jpg,.jpeg",
|
|
2993
|
+
hidden: !0,
|
|
2994
|
+
"aria-label": "Новый файл изображения",
|
|
2995
|
+
onChange: (e) => void ne(e)
|
|
2996
|
+
}),
|
|
2997
|
+
b && /* @__PURE__ */ D("div", {
|
|
2998
|
+
role: "alert",
|
|
2999
|
+
className: "az-image-controls-error",
|
|
3000
|
+
children: b
|
|
3001
|
+
}),
|
|
3002
|
+
/* @__PURE__ */ D(zt, {
|
|
3003
|
+
host: d,
|
|
3004
|
+
disabled: s || v,
|
|
3005
|
+
aspect: A,
|
|
3006
|
+
onError: x,
|
|
3007
|
+
documentKey: t
|
|
3008
|
+
})
|
|
3009
|
+
]
|
|
3010
|
+
});
|
|
3011
|
+
}
|
|
3012
|
+
//#endregion
|
|
2435
3013
|
//#region src/library/EditorFrame.tsx
|
|
2436
|
-
function
|
|
2437
|
-
let t = h(), n = _((e) => e.zoom), i = r(
|
|
3014
|
+
function Vt({ forwardedRef: e }) {
|
|
3015
|
+
let t = h(), n = _((e) => e.zoom), i = r(xt);
|
|
2438
3016
|
return o(i, [n, i]), a(e, () => ({
|
|
2439
3017
|
load: (e) => {
|
|
2440
3018
|
t?.load(e);
|
|
@@ -2453,7 +3031,7 @@ function St({ forwardedRef: e }) {
|
|
|
2453
3031
|
snapshot: (e) => t?.snapshot(e) ?? f
|
|
2454
3032
|
}), [t]), null;
|
|
2455
3033
|
}
|
|
2456
|
-
function
|
|
3034
|
+
function Ht({ forwardedRef: e, ...t }) {
|
|
2457
3035
|
let n = m(), [r, a] = l(() => typeof matchMedia < "u" && matchMedia("(prefers-color-scheme: dark)").matches);
|
|
2458
3036
|
i(() => {
|
|
2459
3037
|
if (t.colorMode !== "system") return;
|
|
@@ -2461,15 +3039,15 @@ function Ct({ forwardedRef: e, ...t }) {
|
|
|
2461
3039
|
return n(), e.addEventListener("change", n), () => e.removeEventListener("change", n);
|
|
2462
3040
|
}, [t.colorMode]);
|
|
2463
3041
|
let o = t.colorMode === "dark" || t.colorMode === "system" && r, c = t.chrome !== !1, u = c && t.rulers !== !1, f = s(() => ({
|
|
2464
|
-
hyperlink: (e) => /* @__PURE__ */
|
|
2465
|
-
contentControl: (e) => /* @__PURE__ */
|
|
2466
|
-
equation: () => /* @__PURE__ */
|
|
2467
|
-
contextMenu: t.contextMenu === !1 ? !1 : (e) => /* @__PURE__ */
|
|
3042
|
+
hyperlink: (e) => /* @__PURE__ */ D(d.HyperLink, { ...e }),
|
|
3043
|
+
contentControl: (e) => /* @__PURE__ */ D(d.ContentControl, { ...e }),
|
|
3044
|
+
equation: () => /* @__PURE__ */ D(d.Equation, {}),
|
|
3045
|
+
contextMenu: t.contextMenu === !1 ? !1 : (e) => /* @__PURE__ */ D(d.ContextMenu, {
|
|
2468
3046
|
...e,
|
|
2469
3047
|
t: n
|
|
2470
3048
|
})
|
|
2471
3049
|
}), [t.contextMenu, n]);
|
|
2472
|
-
return /* @__PURE__ */
|
|
3050
|
+
return /* @__PURE__ */ O(d.Root, {
|
|
2473
3051
|
document: t.document,
|
|
2474
3052
|
fonts: t.fonts,
|
|
2475
3053
|
locale: t.locale,
|
|
@@ -2480,22 +3058,22 @@ function Ct({ forwardedRef: e, ...t }) {
|
|
|
2480
3058
|
onChange: t.onChange,
|
|
2481
3059
|
onFontError: t.onFontError,
|
|
2482
3060
|
popups: f,
|
|
2483
|
-
children: [/* @__PURE__ */
|
|
3061
|
+
children: [/* @__PURE__ */ D(Vt, { forwardedRef: e }), /* @__PURE__ */ O("div", {
|
|
2484
3062
|
className: [
|
|
2485
3063
|
"docx-editor",
|
|
2486
3064
|
"az-editor-frame",
|
|
2487
3065
|
o && "dark"
|
|
2488
3066
|
].filter(Boolean).join(" "),
|
|
2489
3067
|
children: [
|
|
2490
|
-
c && /* @__PURE__ */
|
|
3068
|
+
c && /* @__PURE__ */ O("div", {
|
|
2491
3069
|
className: "az-editor-chrome",
|
|
2492
|
-
children: [t.titleBar !== !1 && /* @__PURE__ */
|
|
3070
|
+
children: [t.titleBar !== !1 && /* @__PURE__ */ O("div", {
|
|
2493
3071
|
className: "az-editor-titlebar",
|
|
2494
3072
|
children: [
|
|
2495
3073
|
t.renderTitleBarLeft?.(),
|
|
2496
|
-
/* @__PURE__ */
|
|
3074
|
+
/* @__PURE__ */ O("div", {
|
|
2497
3075
|
className: "az-editor-title",
|
|
2498
|
-
children: [/* @__PURE__ */
|
|
3076
|
+
children: [/* @__PURE__ */ D("span", { children: t.title }), t.menu !== !1 && /* @__PURE__ */ D(d.Menu, {
|
|
2499
3077
|
t: n,
|
|
2500
3078
|
fileName: t.title,
|
|
2501
3079
|
onOpen: t.onOpen,
|
|
@@ -2505,11 +3083,11 @@ function Ct({ forwardedRef: e, ...t }) {
|
|
|
2505
3083
|
}),
|
|
2506
3084
|
t.renderTitleBarRight?.()
|
|
2507
3085
|
]
|
|
2508
|
-
}), /* @__PURE__ */
|
|
3086
|
+
}), /* @__PURE__ */ O("div", {
|
|
2509
3087
|
className: "az-editor-toolbar-row",
|
|
2510
3088
|
children: [
|
|
2511
|
-
/* @__PURE__ */
|
|
2512
|
-
/* @__PURE__ */
|
|
3089
|
+
/* @__PURE__ */ D(d.Toolbar, { t: n }),
|
|
3090
|
+
/* @__PURE__ */ D(At, {
|
|
2513
3091
|
disabled: t.imagesDisabled || t.mode === "view",
|
|
2514
3092
|
documentKey: t.document
|
|
2515
3093
|
}),
|
|
@@ -2517,18 +3095,22 @@ function Ct({ forwardedRef: e, ...t }) {
|
|
|
2517
3095
|
]
|
|
2518
3096
|
})]
|
|
2519
3097
|
}),
|
|
2520
|
-
|
|
3098
|
+
c && /* @__PURE__ */ D(Bt, {
|
|
3099
|
+
disabled: t.imagesDisabled || t.mode === "view",
|
|
3100
|
+
documentKey: t.document
|
|
3101
|
+
}),
|
|
3102
|
+
u && /* @__PURE__ */ D("div", {
|
|
2521
3103
|
className: "az-editor-ruler-row",
|
|
2522
3104
|
"data-testid": "docx-editor-ruler-row",
|
|
2523
3105
|
"data-ruler-unit": t.rulerUnit,
|
|
2524
|
-
children: /* @__PURE__ */
|
|
3106
|
+
children: /* @__PURE__ */ D(d.HorizontalRuler, { unit: t.rulerUnit })
|
|
2525
3107
|
}),
|
|
2526
|
-
c && /* @__PURE__ */
|
|
2527
|
-
/* @__PURE__ */
|
|
3108
|
+
c && /* @__PURE__ */ D(d.FontNotice, { t: n }),
|
|
3109
|
+
/* @__PURE__ */ O("div", {
|
|
2528
3110
|
className: "az-editor-workspace",
|
|
2529
3111
|
children: [
|
|
2530
|
-
c && t.navigation !== !1 && /* @__PURE__ */
|
|
2531
|
-
/* @__PURE__ */
|
|
3112
|
+
c && t.navigation !== !1 && /* @__PURE__ */ D(d.Navigation, {}),
|
|
3113
|
+
/* @__PURE__ */ O(d.Viewport, {
|
|
2532
3114
|
className: o ? "dark" : void 0,
|
|
2533
3115
|
style: {
|
|
2534
3116
|
flex: 1,
|
|
@@ -2537,33 +3119,33 @@ function Ct({ forwardedRef: e, ...t }) {
|
|
|
2537
3119
|
overflowAnchor: "none"
|
|
2538
3120
|
},
|
|
2539
3121
|
children: [
|
|
2540
|
-
c && /* @__PURE__ */
|
|
2541
|
-
/* @__PURE__ */
|
|
2542
|
-
u && /* @__PURE__ */
|
|
3122
|
+
c && /* @__PURE__ */ O(E, { children: [/* @__PURE__ */ D(d.HeaderFooterChrome, {}), /* @__PURE__ */ D(d.NotesChrome, {})] }),
|
|
3123
|
+
/* @__PURE__ */ D(d.Content, {}),
|
|
3124
|
+
u && /* @__PURE__ */ D("div", {
|
|
2543
3125
|
className: "az-editor-vertical-ruler",
|
|
2544
3126
|
"data-ruler-unit": t.rulerUnit,
|
|
2545
|
-
children: /* @__PURE__ */
|
|
3127
|
+
children: /* @__PURE__ */ D(d.VerticalRuler, { unit: t.rulerUnit })
|
|
2546
3128
|
}),
|
|
2547
3129
|
t.children
|
|
2548
3130
|
]
|
|
2549
3131
|
}),
|
|
2550
|
-
c && /* @__PURE__ */
|
|
3132
|
+
c && /* @__PURE__ */ O(E, { children: [/* @__PURE__ */ D(d.PageNumber, {}), /* @__PURE__ */ D(d.Loading, { overlay: !0 })] })
|
|
2551
3133
|
]
|
|
2552
3134
|
})
|
|
2553
3135
|
]
|
|
2554
3136
|
})]
|
|
2555
3137
|
});
|
|
2556
3138
|
}
|
|
2557
|
-
var
|
|
2558
|
-
return /* @__PURE__ */
|
|
3139
|
+
var Ut = t(function(e, t) {
|
|
3140
|
+
return /* @__PURE__ */ D(p, {
|
|
2559
3141
|
i18n: e.i18n,
|
|
2560
|
-
children: /* @__PURE__ */
|
|
3142
|
+
children: /* @__PURE__ */ D(Ht, {
|
|
2561
3143
|
...e,
|
|
2562
3144
|
forwardedRef: t
|
|
2563
3145
|
})
|
|
2564
3146
|
});
|
|
2565
|
-
}),
|
|
2566
|
-
function
|
|
3147
|
+
}), Wt = () => {};
|
|
3148
|
+
function Gt({ onStatusChange: e, fonts: t }) {
|
|
2567
3149
|
let n = c(e);
|
|
2568
3150
|
o(() => {
|
|
2569
3151
|
n.current = e;
|
|
@@ -2599,20 +3181,20 @@ function Et({ onStatusChange: e, fonts: t }) {
|
|
|
2599
3181
|
d
|
|
2600
3182
|
]), null;
|
|
2601
3183
|
}
|
|
2602
|
-
var
|
|
3184
|
+
var Kt = t(function(e, t) {
|
|
2603
3185
|
let n = c(null), r = c(null), f = c(null), [p, m] = l(""), [h, g] = l(!1), _ = e.fullscreen ?? h, b = (t) => {
|
|
2604
3186
|
e.fullscreen === void 0 && g(t), e.onFullscreenChange?.(t);
|
|
2605
|
-
}, x = s(() => y(), []), S = v(x),
|
|
3187
|
+
}, x = s(() => y(), []), S = v(x), C = e.fonts ?? S, w = s(() => yt(C), [C]), T = u(w.subscribe, w.snapshot, w.snapshot), k = c(e), A = c(0), j = c(!1), M = c(w);
|
|
2606
3188
|
o(() => {
|
|
2607
|
-
|
|
3189
|
+
k.current = e, M.current = w;
|
|
2608
3190
|
}), o(() => {
|
|
2609
|
-
|
|
2610
|
-
}, [
|
|
2611
|
-
async function
|
|
2612
|
-
if (!
|
|
3191
|
+
w.reset();
|
|
3192
|
+
}, [w, e.document]);
|
|
3193
|
+
async function N(e, t) {
|
|
3194
|
+
if (!k.current.onDiagnostics) return;
|
|
2613
3195
|
let n;
|
|
2614
3196
|
try {
|
|
2615
|
-
n = await
|
|
3197
|
+
n = await vt(e);
|
|
2616
3198
|
} catch {
|
|
2617
3199
|
n = [{
|
|
2618
3200
|
code: "diagnostics-unavailable",
|
|
@@ -2621,28 +3203,28 @@ var Dt = t(function(e, t) {
|
|
|
2621
3203
|
stage: "import"
|
|
2622
3204
|
}];
|
|
2623
3205
|
}
|
|
2624
|
-
|
|
3206
|
+
j.current && t === A.current && k.current.onDiagnostics?.(n);
|
|
2625
3207
|
}
|
|
2626
3208
|
i(() => {
|
|
2627
|
-
|
|
2628
|
-
let t = ++
|
|
2629
|
-
return
|
|
2630
|
-
|
|
3209
|
+
j.current = !0;
|
|
3210
|
+
let t = ++A.current;
|
|
3211
|
+
return k.current.onDiagnostics?.([]), e.document && e.document !== "blank" && N(e.document, t), () => {
|
|
3212
|
+
j.current = !1, ++A.current;
|
|
2631
3213
|
};
|
|
2632
3214
|
}, [e.document]);
|
|
2633
|
-
let
|
|
2634
|
-
function
|
|
3215
|
+
let P = (t) => e.ui !== !1 && e.ui?.[t] !== !1;
|
|
3216
|
+
function F(e) {
|
|
2635
3217
|
let t = r.current?.querySelector("[data-menu=\"file\"] > [role=\"menuitem\"][aria-expanded=\"true\"]");
|
|
2636
3218
|
t?.click(), t?.focus(), e();
|
|
2637
3219
|
}
|
|
2638
|
-
async function
|
|
3220
|
+
async function I() {
|
|
2639
3221
|
let t = n.current?.getEditor();
|
|
2640
3222
|
if (!t || !r.current || t.snapshot().isLoading || t.snapshot().parseError || window.document.querySelector("[data-az-print-root]")) return;
|
|
2641
3223
|
f.current?.abort();
|
|
2642
3224
|
let i = new AbortController();
|
|
2643
3225
|
f.current = i, m("");
|
|
2644
3226
|
try {
|
|
2645
|
-
await
|
|
3227
|
+
await ie(t, r.current, e.title ?? "Документ.docx", i.signal);
|
|
2646
3228
|
} catch (e) {
|
|
2647
3229
|
!i.signal.aborted && !(e instanceof DOMException && e.name === "AbortError") && m(e instanceof Error ? e.message : "Не удалось подготовить PDF.");
|
|
2648
3230
|
}
|
|
@@ -2660,33 +3242,33 @@ var Dt = t(function(e, t) {
|
|
|
2660
3242
|
if (s && t.contains(s)) return;
|
|
2661
3243
|
r.preventDefault(), r.stopImmediatePropagation();
|
|
2662
3244
|
let c = n.current?.getEditor(), l = c?.snapshot();
|
|
2663
|
-
!c || !l?.editable || l.isLoading || l.isOpening || l.parseError || e.mode === "view" || e.actionsDisabled ||
|
|
3245
|
+
!c || !l?.editable || l.isLoading || l.isOpening || l.parseError || e.mode === "view" || e.actionsDisabled || T.state === "loading" || (a === "undo" ? l.canUndo : l.canRedo) && c.exec({ type: a });
|
|
2664
3246
|
};
|
|
2665
3247
|
return t.addEventListener("keydown", i, !0), () => t.removeEventListener("keydown", i, !0);
|
|
2666
3248
|
}, [
|
|
2667
3249
|
e.mode,
|
|
2668
3250
|
e.actionsDisabled,
|
|
2669
|
-
|
|
3251
|
+
T.state
|
|
2670
3252
|
]), i(() => {
|
|
2671
3253
|
let t = (t) => {
|
|
2672
|
-
if (t.defaultPrevented || !(t.ctrlKey || t.metaKey) || t.altKey || t.shiftKey || !r.current || !
|
|
2673
|
-
let n = t.code === "KeyS" ? e.onSave : t.code === "KeyO" ? e.onOpen : t.code === "KeyP" &&
|
|
3254
|
+
if (t.defaultPrevented || !(t.ctrlKey || t.metaKey) || t.altKey || t.shiftKey || !r.current || !re(r.current, t.target) || window.document.querySelector("[data-az-print-root]") || t.code !== "KeyS" && t.code !== "KeyO" && !(t.code === "KeyP" && P("print"))) return;
|
|
3255
|
+
let n = t.code === "KeyS" ? e.onSave : t.code === "KeyO" ? e.onOpen : t.code === "KeyP" && P("print") ? () => void I() : void 0;
|
|
2674
3256
|
t.preventDefault(), t.stopImmediatePropagation(), e.actionsDisabled || n?.();
|
|
2675
3257
|
};
|
|
2676
3258
|
return window.addEventListener("keydown", t, !0), () => window.removeEventListener("keydown", t, !0);
|
|
2677
3259
|
}), a(t, () => ({
|
|
2678
3260
|
async save() {
|
|
2679
|
-
let e =
|
|
3261
|
+
let e = A.current, t = await n.current?.save();
|
|
2680
3262
|
if (!t) throw Error("Документ ещё не готов к сохранению.");
|
|
2681
|
-
return
|
|
3263
|
+
return N(t, e), t;
|
|
2682
3264
|
},
|
|
2683
3265
|
async exportHujjat(e) {
|
|
2684
3266
|
let t = await n.current?.save();
|
|
2685
3267
|
if (!t) throw new z("Документ ещё не готов к экспорту.");
|
|
2686
|
-
return
|
|
3268
|
+
return gt(t, e);
|
|
2687
3269
|
},
|
|
2688
3270
|
insertVariable(e) {
|
|
2689
|
-
if (!
|
|
3271
|
+
if (!_e(e)) throw new z("Некорректный ключ переменной. Используйте client.name, ASCII, до 100 символов.");
|
|
2690
3272
|
let t = n.current?.exec({
|
|
2691
3273
|
type: "pasteWithoutFormatting",
|
|
2692
3274
|
text: `{${e}}`
|
|
@@ -2696,7 +3278,7 @@ var Dt = t(function(e, t) {
|
|
|
2696
3278
|
},
|
|
2697
3279
|
setParagraphPagination(t) {
|
|
2698
3280
|
let r = n.current?.getEditor()?.snapshot();
|
|
2699
|
-
if (!r || r.isLoading || r.isOpening || r.parseError ||
|
|
3281
|
+
if (!r || r.isLoading || r.isOpening || r.parseError || T.state === "loading" || e.mode === "view" || e.actionsDisabled) throw new z("Редактор недоступен для изменения.");
|
|
2700
3282
|
let i = {};
|
|
2701
3283
|
for (let e of [
|
|
2702
3284
|
"keepNext",
|
|
@@ -2718,8 +3300,8 @@ var Dt = t(function(e, t) {
|
|
|
2718
3300
|
focus() {
|
|
2719
3301
|
n.current?.focus();
|
|
2720
3302
|
},
|
|
2721
|
-
print:
|
|
2722
|
-
})), /* @__PURE__ */
|
|
3303
|
+
print: I
|
|
3304
|
+
})), /* @__PURE__ */ D(Ct, {
|
|
2723
3305
|
className: e.className,
|
|
2724
3306
|
style: e.style,
|
|
2725
3307
|
expanded: _,
|
|
@@ -2730,30 +3312,30 @@ var Dt = t(function(e, t) {
|
|
|
2730
3312
|
e?.focus(), t && e?.releaseSelection(t);
|
|
2731
3313
|
};
|
|
2732
3314
|
},
|
|
2733
|
-
children: /* @__PURE__ */
|
|
3315
|
+
children: /* @__PURE__ */ O("div", {
|
|
2734
3316
|
className: "az-editor-content",
|
|
2735
3317
|
ref: r,
|
|
2736
|
-
children: [p && /* @__PURE__ */
|
|
3318
|
+
children: [p && /* @__PURE__ */ D("div", {
|
|
2737
3319
|
role: "alert",
|
|
2738
3320
|
className: "az-print-error",
|
|
2739
3321
|
children: p
|
|
2740
|
-
}), /* @__PURE__ */
|
|
2741
|
-
imagesDisabled: e.actionsDisabled ||
|
|
3322
|
+
}), /* @__PURE__ */ D(Ut, {
|
|
3323
|
+
imagesDisabled: e.actionsDisabled || T.state === "loading",
|
|
2742
3324
|
ref: n,
|
|
2743
3325
|
document: e.document ?? "blank",
|
|
2744
3326
|
title: e.title ?? "Документ.docx",
|
|
2745
|
-
fonts:
|
|
3327
|
+
fonts: w.fonts,
|
|
2746
3328
|
locale: e.locale ?? "ru-RU",
|
|
2747
|
-
i18n: e.i18n ??
|
|
3329
|
+
i18n: e.i18n ?? ee,
|
|
2748
3330
|
mode: e.mode ?? "edit",
|
|
2749
3331
|
colorMode: e.colorMode ?? "light",
|
|
2750
3332
|
zoom: e.zoom,
|
|
2751
3333
|
zoomMode: e.zoomMode,
|
|
2752
|
-
chrome:
|
|
2753
|
-
rulers:
|
|
3334
|
+
chrome: P("chrome"),
|
|
3335
|
+
rulers: P("rulers"),
|
|
2754
3336
|
rulerUnit: e.rulerUnit ?? "cm",
|
|
2755
|
-
titleBar:
|
|
2756
|
-
controls: /* @__PURE__ */
|
|
3337
|
+
titleBar: P("titleBar"),
|
|
3338
|
+
controls: /* @__PURE__ */ O(E, { children: [e.renderToolbarEnd?.(), (P("fullscreen") || _) && /* @__PURE__ */ D("button", {
|
|
2757
3339
|
type: "button",
|
|
2758
3340
|
className: "az-fullscreen-toggle",
|
|
2759
3341
|
"aria-expanded": _,
|
|
@@ -2761,7 +3343,7 @@ var Dt = t(function(e, t) {
|
|
|
2761
3343
|
"aria-label": _ ? e.labels?.collapse ?? "Свернуть редактор" : e.labels?.expand ?? "Развернуть на всю страницу",
|
|
2762
3344
|
onMouseDown: (e) => e.preventDefault(),
|
|
2763
3345
|
onClick: () => b(!_),
|
|
2764
|
-
children: /* @__PURE__ */
|
|
3346
|
+
children: /* @__PURE__ */ D("svg", {
|
|
2765
3347
|
width: "20",
|
|
2766
3348
|
height: "20",
|
|
2767
3349
|
viewBox: "0 0 24 24",
|
|
@@ -2769,63 +3351,63 @@ var Dt = t(function(e, t) {
|
|
|
2769
3351
|
stroke: "currentColor",
|
|
2770
3352
|
strokeWidth: "1.6",
|
|
2771
3353
|
"aria-hidden": "true",
|
|
2772
|
-
children: /* @__PURE__ */
|
|
3354
|
+
children: /* @__PURE__ */ D("path", { d: _ ? "M3 8h5V3M16 3v5h5M21 16h-5v5M8 21v-5H3" : "M8 3H3v5M21 8V3h-5M16 21h5v-5M3 16v5h5" })
|
|
2773
3355
|
})
|
|
2774
3356
|
})] }),
|
|
2775
|
-
navigation:
|
|
2776
|
-
contextMenu:
|
|
3357
|
+
navigation: P("navigation"),
|
|
3358
|
+
contextMenu: P("contextMenu"),
|
|
2777
3359
|
renderTitleBarLeft: e.renderTitleBarLeft,
|
|
2778
3360
|
renderTitleBarRight: e.renderTitleBarRight,
|
|
2779
3361
|
onChange: (t) => {
|
|
2780
|
-
t.source || (++
|
|
3362
|
+
t.source || (++A.current, k.current.onDiagnostics?.([]), e.onChange?.());
|
|
2781
3363
|
},
|
|
2782
3364
|
onSave: e.onSave,
|
|
2783
3365
|
onOpen: e.onOpen,
|
|
2784
3366
|
onFontError: (e) => {
|
|
2785
|
-
|
|
3367
|
+
M.current === w && j.current && (w.fail(e.code), k.current.onFontError?.(`Не удалось загрузить шрифт (${e.code}). Переносы могут отличаться от Word.`));
|
|
2786
3368
|
},
|
|
2787
|
-
menu:
|
|
3369
|
+
menu: P("menu") && {
|
|
2788
3370
|
reportIssue: !1,
|
|
2789
|
-
onOpen:
|
|
2790
|
-
onSave:
|
|
2791
|
-
children: /* @__PURE__ */
|
|
3371
|
+
onOpen: Wt,
|
|
3372
|
+
onSave: Wt,
|
|
3373
|
+
children: /* @__PURE__ */ O(d.Menu.File, {
|
|
2792
3374
|
preset: !1,
|
|
2793
3375
|
children: [
|
|
2794
|
-
e.fileActions?.map((t) => /* @__PURE__ */
|
|
2795
|
-
onSelect: () =>
|
|
3376
|
+
e.fileActions?.map((t) => /* @__PURE__ */ D(d.Menu.Row, {
|
|
3377
|
+
onSelect: () => F(t.onSelect),
|
|
2796
3378
|
disabled: e.actionsDisabled || t.disabled,
|
|
2797
3379
|
children: t.label
|
|
2798
3380
|
}, t.id)),
|
|
2799
|
-
e.onOpen && /* @__PURE__ */
|
|
2800
|
-
onSelect: () =>
|
|
3381
|
+
e.onOpen && /* @__PURE__ */ D(d.Menu.Row, {
|
|
3382
|
+
onSelect: () => F(e.onOpen),
|
|
2801
3383
|
disabled: e.actionsDisabled,
|
|
2802
3384
|
shortcut: "Ctrl+O",
|
|
2803
|
-
children: e.labels?.open ?? e.i18n?.toolbar?.open ??
|
|
3385
|
+
children: e.labels?.open ?? e.i18n?.toolbar?.open ?? ee.toolbar?.open
|
|
2804
3386
|
}),
|
|
2805
|
-
e.onSave && /* @__PURE__ */
|
|
2806
|
-
onSelect: () =>
|
|
3387
|
+
e.onSave && /* @__PURE__ */ D(d.Menu.Row, {
|
|
3388
|
+
onSelect: () => F(e.onSave),
|
|
2807
3389
|
disabled: e.actionsDisabled,
|
|
2808
3390
|
shortcut: "Ctrl+S",
|
|
2809
|
-
children: e.labels?.save ?? e.i18n?.toolbar?.save ??
|
|
3391
|
+
children: e.labels?.save ?? e.i18n?.toolbar?.save ?? ee.toolbar?.save
|
|
2810
3392
|
}),
|
|
2811
|
-
e.onExportPdf && /* @__PURE__ */
|
|
2812
|
-
onSelect: () =>
|
|
3393
|
+
e.onExportPdf && /* @__PURE__ */ D(d.Menu.Row, {
|
|
3394
|
+
onSelect: () => F(e.onExportPdf),
|
|
2813
3395
|
disabled: e.actionsDisabled,
|
|
2814
3396
|
children: e.labels?.exportPdf ?? "Скачать PDF"
|
|
2815
3397
|
}),
|
|
2816
|
-
|
|
2817
|
-
onSelect: () =>
|
|
3398
|
+
P("print") && /* @__PURE__ */ D(d.Menu.Row, {
|
|
3399
|
+
onSelect: () => F(() => void I()),
|
|
2818
3400
|
disabled: e.actionsDisabled,
|
|
2819
3401
|
shortcut: "Ctrl+P",
|
|
2820
3402
|
children: e.labels?.print ?? "Распечатать…"
|
|
2821
3403
|
}),
|
|
2822
|
-
/* @__PURE__ */
|
|
3404
|
+
/* @__PURE__ */ D(d.Menu.PageSetup, {})
|
|
2823
3405
|
]
|
|
2824
3406
|
})
|
|
2825
3407
|
},
|
|
2826
|
-
children: /* @__PURE__ */
|
|
3408
|
+
children: /* @__PURE__ */ D(Gt, {
|
|
2827
3409
|
onStatusChange: e.onStatusChange,
|
|
2828
|
-
fonts:
|
|
3410
|
+
fonts: T
|
|
2829
3411
|
})
|
|
2830
3412
|
})]
|
|
2831
3413
|
})
|
|
@@ -2833,12 +3415,12 @@ var Dt = t(function(e, t) {
|
|
|
2833
3415
|
});
|
|
2834
3416
|
//#endregion
|
|
2835
3417
|
//#region src/library/AzHtmlEditor.tsx
|
|
2836
|
-
function
|
|
3418
|
+
function qt(...e) {
|
|
2837
3419
|
let t = /* @__PURE__ */ new Map();
|
|
2838
3420
|
for (let n of e.flat()) t.set(JSON.stringify(n), n);
|
|
2839
3421
|
return [...t.values()];
|
|
2840
3422
|
}
|
|
2841
|
-
var
|
|
3423
|
+
var Jt = t(function(e, t) {
|
|
2842
3424
|
let { initialHtml: r, layout: s, page: u, onChange: d, onStatusChange: f, renderFallback: p, ...m } = e, [h] = l(r), [g] = l(() => structuredClone(u)), [_] = l(() => s ? {
|
|
2843
3425
|
...s,
|
|
2844
3426
|
page: s.page ? {
|
|
@@ -2851,23 +3433,23 @@ var kt = t(function(e, t) {
|
|
|
2851
3433
|
pages: 0,
|
|
2852
3434
|
error: null,
|
|
2853
3435
|
warnings: []
|
|
2854
|
-
}), S = c(b), C = c(null),
|
|
3436
|
+
}), S = c(b), C = c(null), w = c(null), T = c(!1), E = c(0), k = c(0), A = c(e);
|
|
2855
3437
|
o(() => {
|
|
2856
3438
|
A.current = e;
|
|
2857
3439
|
});
|
|
2858
3440
|
let j = n((e) => {
|
|
2859
|
-
|
|
3441
|
+
T.current && (S.current = {
|
|
2860
3442
|
...S.current,
|
|
2861
3443
|
...e
|
|
2862
3444
|
}, x(S.current), A.current.onStatusChange?.(S.current));
|
|
2863
3445
|
}, []), M = n(async (e = !1) => {
|
|
2864
|
-
let t = ++
|
|
3446
|
+
let t = ++E.current;
|
|
2865
3447
|
j({
|
|
2866
3448
|
phase: "loading",
|
|
2867
3449
|
error: null
|
|
2868
3450
|
});
|
|
2869
3451
|
try {
|
|
2870
|
-
let n = await
|
|
3452
|
+
let n = await _t({ uz: {
|
|
2871
3453
|
blocks: [{
|
|
2872
3454
|
type: "html",
|
|
2873
3455
|
props: { html: h.trim() ? h : "<p><br></p>" }
|
|
@@ -2877,10 +3459,10 @@ var kt = t(function(e, t) {
|
|
|
2877
3459
|
allowLossy: e,
|
|
2878
3460
|
layout: _
|
|
2879
3461
|
});
|
|
2880
|
-
if (!
|
|
2881
|
-
|
|
3462
|
+
if (!T.current || t !== E.current) return;
|
|
3463
|
+
w.current = n, y(n.document), j({ warnings: n.warnings });
|
|
2882
3464
|
} catch (e) {
|
|
2883
|
-
if (!
|
|
3465
|
+
if (!T.current || t !== E.current) return;
|
|
2884
3466
|
let n = e instanceof z ? e.warnings : [];
|
|
2885
3467
|
j({
|
|
2886
3468
|
phase: n.some((e) => e.severity === "loss") ? "blocked" : "error",
|
|
@@ -2894,8 +3476,8 @@ var kt = t(function(e, t) {
|
|
|
2894
3476
|
g,
|
|
2895
3477
|
j
|
|
2896
3478
|
]);
|
|
2897
|
-
i(() => (
|
|
2898
|
-
|
|
3479
|
+
i(() => (T.current = !0, M(), () => {
|
|
3480
|
+
T.current = !1, ++E.current;
|
|
2899
3481
|
}), [M]);
|
|
2900
3482
|
let N = n((e) => {
|
|
2901
3483
|
let t = e.error ? "error" : e.loading ? "loading" : S.current.phase === "exporting" ? "exporting" : "ready";
|
|
@@ -2906,14 +3488,14 @@ var kt = t(function(e, t) {
|
|
|
2906
3488
|
fonts: e.fonts
|
|
2907
3489
|
});
|
|
2908
3490
|
}, [j]), P = n(() => {
|
|
2909
|
-
|
|
2910
|
-
}, [j]),
|
|
2911
|
-
|
|
3491
|
+
T.current && ["ready", "exporting"].includes(S.current.phase) && (++k.current, j({ dirty: !0 }), A.current.onChange?.());
|
|
3492
|
+
}, [j]), F = n((e) => {
|
|
3493
|
+
T.current && e === E.current && S.current.phase === "exporting" && j({ phase: "ready" });
|
|
2912
3494
|
}, [j]);
|
|
2913
3495
|
return a(t, () => ({
|
|
2914
3496
|
async exportHtml(e = {}) {
|
|
2915
|
-
if (!
|
|
2916
|
-
let t =
|
|
3497
|
+
if (!T.current || S.current.phase !== "ready" || !w.current || !C.current) throw new z("HTML-редактор ещё не готов или занят.");
|
|
3498
|
+
let t = w.current, n = t.warnings.some((e) => e.code === "line-height-normalized");
|
|
2917
3499
|
if (!S.current.dirty && !n) return {
|
|
2918
3500
|
html: h,
|
|
2919
3501
|
variables: [...t.variables],
|
|
@@ -2922,7 +3504,7 @@ var kt = t(function(e, t) {
|
|
|
2922
3504
|
page: structuredClone(g),
|
|
2923
3505
|
changed: !1
|
|
2924
3506
|
};
|
|
2925
|
-
let r =
|
|
3507
|
+
let r = E.current, i = k.current;
|
|
2926
3508
|
j({
|
|
2927
3509
|
phase: "exporting",
|
|
2928
3510
|
error: null
|
|
@@ -2934,9 +3516,9 @@ var kt = t(function(e, t) {
|
|
|
2934
3516
|
layout: _,
|
|
2935
3517
|
page: t.page
|
|
2936
3518
|
});
|
|
2937
|
-
if (!
|
|
2938
|
-
let a =
|
|
2939
|
-
return j({ warnings: a }),
|
|
3519
|
+
if (!T.current || r !== E.current || i !== k.current) throw new z("Черновик изменился или закрыт во время экспорта. Повторите экспорт актуального документа.");
|
|
3520
|
+
let a = qt(t.warnings, n.warnings);
|
|
3521
|
+
return j({ warnings: a }), ge(a, e.allowLossy), {
|
|
2940
3522
|
html: n.html,
|
|
2941
3523
|
variables: n.variables,
|
|
2942
3524
|
warnings: a,
|
|
@@ -2945,22 +3527,22 @@ var kt = t(function(e, t) {
|
|
|
2945
3527
|
changed: !0
|
|
2946
3528
|
};
|
|
2947
3529
|
} finally {
|
|
2948
|
-
|
|
3530
|
+
F(r);
|
|
2949
3531
|
}
|
|
2950
3532
|
},
|
|
2951
3533
|
async acceptImportLoss() {
|
|
2952
|
-
if (!
|
|
3534
|
+
if (!T.current || S.current.phase !== "blocked") throw new z("Нет ожидающего решения об импорте.");
|
|
2953
3535
|
await M(!0);
|
|
2954
3536
|
},
|
|
2955
3537
|
insertVariable(e) {
|
|
2956
|
-
if (!
|
|
3538
|
+
if (!T.current || S.current.phase !== "ready" || A.current.mode === "view" || !C.current) throw new z("Редактор недоступен для изменения.");
|
|
2957
3539
|
C.current.insertVariable(e);
|
|
2958
3540
|
},
|
|
2959
3541
|
focus() {
|
|
2960
3542
|
C.current?.focus();
|
|
2961
3543
|
},
|
|
2962
3544
|
setParagraphPagination(e) {
|
|
2963
|
-
if (!
|
|
3545
|
+
if (!T.current || S.current.phase !== "ready" || A.current.mode === "view" || A.current.actionsDisabled || !C.current) throw new z("Редактор недоступен для изменения.");
|
|
2964
3546
|
C.current.setParagraphPagination(e);
|
|
2965
3547
|
}
|
|
2966
3548
|
}), [
|
|
@@ -2969,8 +3551,8 @@ var kt = t(function(e, t) {
|
|
|
2969
3551
|
g,
|
|
2970
3552
|
M,
|
|
2971
3553
|
j,
|
|
2972
|
-
|
|
2973
|
-
]), v ? /* @__PURE__ */
|
|
3554
|
+
F
|
|
3555
|
+
]), v ? /* @__PURE__ */ D(Kt, {
|
|
2974
3556
|
...m,
|
|
2975
3557
|
ref: C,
|
|
2976
3558
|
document: v,
|
|
@@ -2983,26 +3565,26 @@ var kt = t(function(e, t) {
|
|
|
2983
3565
|
actionsDisabled: e.actionsDisabled || b.phase !== "ready",
|
|
2984
3566
|
onChange: P,
|
|
2985
3567
|
onStatusChange: N
|
|
2986
|
-
}) : /* @__PURE__ */
|
|
3568
|
+
}) : /* @__PURE__ */ D("div", {
|
|
2987
3569
|
className: ["az-html-editor", e.className].filter(Boolean).join(" "),
|
|
2988
3570
|
style: e.style,
|
|
2989
|
-
children: p ? p(b) : /* @__PURE__ */
|
|
3571
|
+
children: p ? p(b) : /* @__PURE__ */ O("div", {
|
|
2990
3572
|
role: b.error ? "alert" : "status",
|
|
2991
|
-
children: [b.error ?? "Загрузка документа…", b.warnings.length > 0 && /* @__PURE__ */
|
|
3573
|
+
children: [b.error ?? "Загрузка документа…", b.warnings.length > 0 && /* @__PURE__ */ D("ul", { children: b.warnings.map((e, t) => /* @__PURE__ */ D("li", { children: e.message }, t)) })]
|
|
2992
3574
|
})
|
|
2993
3575
|
});
|
|
2994
|
-
}),
|
|
2995
|
-
function
|
|
3576
|
+
}), Yt = 31457280, Xt = "application/vnd.openxmlformats-officedocument.wordprocessingml.document", Zt = `${Xt}.main+xml`, Qt = 8388608, $ = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
|
|
3577
|
+
function $t(e) {
|
|
2996
3578
|
let t = new DOMParser().parseFromString(e, "application/xml");
|
|
2997
3579
|
if (t.getElementsByTagName("parsererror").length || /<!DOCTYPE/i.test(e)) throw Error("XML документа повреждён или содержит неподдерживаемую структуру.");
|
|
2998
3580
|
return t;
|
|
2999
3581
|
}
|
|
3000
|
-
function
|
|
3582
|
+
function en(e, t) {
|
|
3001
3583
|
let n = e.file(t);
|
|
3002
3584
|
return n ? new Promise((e, t) => {
|
|
3003
3585
|
let r = n.internalStream("uint8array"), i = [], a = 0;
|
|
3004
3586
|
r.on("data", (e) => {
|
|
3005
|
-
a += e.byteLength, a >
|
|
3587
|
+
a += e.byteLength, a > Qt ? (r.pause(), t(/* @__PURE__ */ Error("Структура документа слишком большая для этого прототипа."))) : i.push(e);
|
|
3006
3588
|
}), r.on("error", t), r.on("end", () => {
|
|
3007
3589
|
let t = new Uint8Array(a), n = 0;
|
|
3008
3590
|
for (let e of i) t.set(e, n), n += e.byteLength;
|
|
@@ -3010,7 +3592,7 @@ function Ft(e, t) {
|
|
|
3010
3592
|
}), r.resume();
|
|
3011
3593
|
}) : Promise.resolve("");
|
|
3012
3594
|
}
|
|
3013
|
-
async function
|
|
3595
|
+
async function tn(e) {
|
|
3014
3596
|
if (!/\.docx$/i.test(e.name)) throw Error("Откройте файл DOCX. Форматы DOC, DOCM и PDF здесь не поддерживаются.");
|
|
3015
3597
|
if (!e.size) throw Error("Файл DOCX пуст.");
|
|
3016
3598
|
if (e.size > 31457280) throw Error("Максимальный размер DOCX — 30 МБ.");
|
|
@@ -3023,14 +3605,14 @@ async function It(e) {
|
|
|
3023
3605
|
let r = Object.keys(n.files);
|
|
3024
3606
|
if (r.length > 2e3) throw Error("Слишком много вложенных частей в DOCX для этого прототипа.");
|
|
3025
3607
|
if (!n.file("[Content_Types].xml") || !n.file("word/document.xml")) throw Error("Файл не содержит структуру DOCX.");
|
|
3026
|
-
let i =
|
|
3027
|
-
if (Array.from(i.getElementsByTagNameNS("*", "Override")).find((e) => e.getAttribute("PartName") === "/word/document.xml")?.getAttribute("ContentType") !==
|
|
3028
|
-
let a =
|
|
3608
|
+
let i = $t(await en(n, "[Content_Types].xml"));
|
|
3609
|
+
if (Array.from(i.getElementsByTagNameNS("*", "Override")).find((e) => e.getAttribute("PartName") === "/word/document.xml")?.getAttribute("ContentType") !== Zt || r.some((e) => /vbaProject\.bin$/i.test(e))) throw Error("Поддерживается только обычный DOCX без макросов.");
|
|
3610
|
+
let a = $t(await en(n, "word/document.xml"));
|
|
3029
3611
|
if (a.documentElement.localName !== "document" || !a.getElementsByTagNameNS($, "body").length) throw Error("XML документа повреждён или использует неподдерживаемую разновидность DOCX.");
|
|
3030
3612
|
let o = /* @__PURE__ */ new Set(), s = [a];
|
|
3031
3613
|
for (let e of ["word/styles.xml", "word/fontTable.xml"]) {
|
|
3032
|
-
let t = await
|
|
3033
|
-
t && s.push(
|
|
3614
|
+
let t = await en(n, e);
|
|
3615
|
+
t && s.push($t(t));
|
|
3034
3616
|
}
|
|
3035
3617
|
for (let e of s) {
|
|
3036
3618
|
for (let t of e.getElementsByTagNameNS($, "rFonts")) for (let e of [
|
|
@@ -3047,7 +3629,7 @@ async function It(e) {
|
|
|
3047
3629
|
e && o.add(e);
|
|
3048
3630
|
}
|
|
3049
3631
|
}
|
|
3050
|
-
let c = await
|
|
3632
|
+
let c = await en(n, "docProps/app.xml"), l = c ? Number($t(c).getElementsByTagNameNS("*", "Pages")[0]?.textContent) : 0, { openDocumentForExport: u } = await import("@docx-editor.dev/core/export"), d = u(t.slice());
|
|
3051
3633
|
if (!d.ok) throw Error("Не удалось открыть структуру DOCX. Текущий документ сохранён в редакторе.");
|
|
3052
3634
|
return d.session.dispose(), {
|
|
3053
3635
|
name: e.name,
|
|
@@ -3064,16 +3646,16 @@ async function It(e) {
|
|
|
3064
3646
|
}
|
|
3065
3647
|
};
|
|
3066
3648
|
}
|
|
3067
|
-
function
|
|
3649
|
+
function nn(e) {
|
|
3068
3650
|
return `${(e.replace(/\.docx$/i, "").replace(/[<>:"/\\|?*\x00-\x1f]/g, "_").trim() || "Документ").replace(/ — редакция$/, "")} — редакция.docx`;
|
|
3069
3651
|
}
|
|
3070
|
-
function
|
|
3071
|
-
let n = URL.createObjectURL(new Blob([e], { type:
|
|
3652
|
+
function rn(e, t) {
|
|
3653
|
+
let n = URL.createObjectURL(new Blob([e], { type: Xt })), r = document.createElement("a");
|
|
3072
3654
|
r.href = n, r.download = t, document.body.append(r), r.click(), r.remove(), window.setTimeout(() => URL.revokeObjectURL(n), 3e4);
|
|
3073
3655
|
}
|
|
3074
3656
|
//#endregion
|
|
3075
3657
|
//#region src/library/pdf-export.ts
|
|
3076
|
-
async function
|
|
3658
|
+
async function an(e, t, n, r = {}) {
|
|
3077
3659
|
let i = AbortSignal.any([AbortSignal.timeout(95e3), ...r.signal ? [r.signal] : []]);
|
|
3078
3660
|
i.throwIfAborted();
|
|
3079
3661
|
let a = new FormData();
|
|
@@ -3102,13 +3684,13 @@ async function zt(e, t, n, r = {}) {
|
|
|
3102
3684
|
warnings: (o.headers.get("x-pdf-warnings") ?? "").split(",").filter(Boolean)
|
|
3103
3685
|
};
|
|
3104
3686
|
}
|
|
3105
|
-
function
|
|
3687
|
+
function on(e) {
|
|
3106
3688
|
let t = URL.createObjectURL(e.blob), n = document.createElement("a");
|
|
3107
3689
|
n.href = t, n.download = e.filename, document.body.append(n), n.click(), n.remove(), setTimeout(() => URL.revokeObjectURL(t), 6e4);
|
|
3108
3690
|
}
|
|
3109
3691
|
//#endregion
|
|
3110
3692
|
//#region src/library/pdf-profile.ts
|
|
3111
|
-
var
|
|
3693
|
+
var sn = {
|
|
3112
3694
|
id: "az-editor-pdf-a0c6eaaeb90716f0",
|
|
3113
3695
|
protocolVersion: 1,
|
|
3114
3696
|
core: "2.27.0",
|
|
@@ -3255,18 +3837,18 @@ var Vt = {
|
|
|
3255
3837
|
};
|
|
3256
3838
|
//#endregion
|
|
3257
3839
|
//#region src/library/hujjat/api.ts
|
|
3258
|
-
function
|
|
3840
|
+
function cn(e) {
|
|
3259
3841
|
if (!e || !Object.keys(e).length) throw new z("Нет локалей шаблона.");
|
|
3260
3842
|
for (let [t, n] of Object.entries(e)) {
|
|
3261
|
-
if (
|
|
3843
|
+
if (Oe(t), We(n?.page), !n || !Array.isArray(n.blocks) || !n.blocks.length) throw new z(`Нет блоков для ${t}.`);
|
|
3262
3844
|
for (let e of n.blocks) if (e.type === "html") {
|
|
3263
3845
|
if (typeof e.props?.html != "string" || !e.props.html.trim()) throw new z(`Пустой HTML для ${t}.`);
|
|
3264
3846
|
if (new TextEncoder().encode(e.props.html).length > 1048576) throw new z(`HTML для ${t} превышает 1 МБ.`);
|
|
3265
3847
|
}
|
|
3266
3848
|
}
|
|
3267
3849
|
}
|
|
3268
|
-
function
|
|
3269
|
-
if (
|
|
3850
|
+
function ln(e, t) {
|
|
3851
|
+
if (cn(t), !t.uz) throw new z("Для создания шаблона обязательна локаль uz.");
|
|
3270
3852
|
if (!e.productId || !e.name.trim() || e.name.length > 255) throw new z("Укажите продукт и название шаблона до 255 символов.");
|
|
3271
3853
|
return {
|
|
3272
3854
|
product_id: e.productId,
|
|
@@ -3275,11 +3857,11 @@ function Ut(e, t) {
|
|
|
3275
3857
|
locales: structuredClone(t)
|
|
3276
3858
|
};
|
|
3277
3859
|
}
|
|
3278
|
-
async function
|
|
3860
|
+
async function un(e) {
|
|
3279
3861
|
let t = AbortSignal.any([AbortSignal.timeout(95e3), ...e.signal ? [e.signal] : []]);
|
|
3280
|
-
t.throwIfAborted(),
|
|
3862
|
+
t.throwIfAborted(), cn(e.locales);
|
|
3281
3863
|
let n = e.locale ?? "uz";
|
|
3282
|
-
|
|
3864
|
+
Oe(n);
|
|
3283
3865
|
let r = new Headers(e.headers);
|
|
3284
3866
|
r.set("Content-Type", "application/json"), r.set("Accept", "application/pdf, application/json");
|
|
3285
3867
|
let i = await (e.fetcher ?? fetch)(e.url, {
|
|
@@ -3307,4 +3889,4 @@ async function Wt(e) {
|
|
|
3307
3889
|
};
|
|
3308
3890
|
}
|
|
3309
3891
|
//#endregion
|
|
3310
|
-
export {
|
|
3892
|
+
export { Kt as AzDocumentEditor, Jt as AzHtmlEditor, Xt as DOCX_MIME, pe as HUJJAT_LOCALES, Ue as HUJJAT_MAX_CHROME_BYTES, me as HUJJAT_MAX_HTML_BYTES, le as HUJJAT_PAGE, z as HujjatCompatibilityError, Yt as MAX_DOCX_BYTES, vt as analyzeDocxFormatting, ln as createHujjatTemplatePayload, rn as downloadDocx, on as downloadPdf, nn as exportFilename, gt as exportHujjatDocx, _t as importHujjatTemplate, sn as pdfRenderProfile, tn as readDocxFile, ke as readHujjatHtml, un as requestHujjatPreview, an as requestPdf, R as resolveHtmlLayout, De as sanitizeHujjatHtml, We as validateHujjatPage, _e as validateHujjatVariable, Ae as withHujjatLocale };
|