@mlightcad/cad-pdf-plugin 1.8.0-preview.3 → 1.8.0-preview.4
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/LICENSE +21 -21
- package/README.md +280 -186
- package/dist/cad-pdf-plugin-register.js +29 -11
- package/dist/cad-pdf-plugin-register.umd.cjs +1 -1
- package/dist/cad-pdf-plugin.js +17568 -8428
- package/dist/cad-pdf-plugin.umd.cjs +847 -13
- package/lib/AcApConvertToPdfCmd.d.ts.map +1 -1
- package/lib/AcApConvertToPdfCmd.js +14 -3
- package/lib/AcApConvertToPdfCmd.js.map +1 -1
- package/lib/AcApImportPdfCmd.d.ts +5 -3
- package/lib/AcApImportPdfCmd.d.ts.map +1 -1
- package/lib/AcApImportPdfCmd.js +5 -3
- package/lib/AcApImportPdfCmd.js.map +1 -1
- package/lib/AcApImportPdfPromptCmd.d.ts +16 -0
- package/lib/AcApImportPdfPromptCmd.d.ts.map +1 -0
- package/lib/AcApImportPdfPromptCmd.js +89 -0
- package/lib/AcApImportPdfPromptCmd.js.map +1 -0
- package/lib/AcApPdfBlockCmd.d.ts +15 -0
- package/lib/AcApPdfBlockCmd.d.ts.map +1 -0
- package/lib/AcApPdfBlockCmd.js +75 -0
- package/lib/AcApPdfBlockCmd.js.map +1 -0
- package/lib/AcApPdfDimCmd.d.ts +20 -0
- package/lib/AcApPdfDimCmd.d.ts.map +1 -0
- package/lib/AcApPdfDimCmd.js +413 -0
- package/lib/AcApPdfDimCmd.js.map +1 -0
- package/lib/AcApPdfDimSession.d.ts +82 -0
- package/lib/AcApPdfDimSession.d.ts.map +1 -0
- package/lib/AcApPdfDimSession.js +252 -0
- package/lib/AcApPdfDimSession.js.map +1 -0
- package/lib/AcApPdfFontResolver.d.ts.map +1 -1
- package/lib/AcApPdfFontResolver.js +2 -5
- package/lib/AcApPdfFontResolver.js.map +1 -1
- package/lib/AcApPdfHatchCmd.d.ts +33 -0
- package/lib/AcApPdfHatchCmd.d.ts.map +1 -0
- package/lib/AcApPdfHatchCmd.js +411 -0
- package/lib/AcApPdfHatchCmd.js.map +1 -0
- package/lib/AcApPdfHatchSession.d.ts +122 -0
- package/lib/AcApPdfHatchSession.d.ts.map +1 -0
- package/lib/AcApPdfHatchSession.js +357 -0
- package/lib/AcApPdfHatchSession.js.map +1 -0
- package/lib/AcApPdfImportConvertor.d.ts +47 -5
- package/lib/AcApPdfImportConvertor.d.ts.map +1 -1
- package/lib/AcApPdfImportConvertor.js +999 -108
- package/lib/AcApPdfImportConvertor.js.map +1 -1
- package/lib/AcApPdfImportOptions.d.ts +116 -0
- package/lib/AcApPdfImportOptions.d.ts.map +1 -0
- package/lib/AcApPdfImportOptions.js +31 -0
- package/lib/AcApPdfImportOptions.js.map +1 -0
- package/lib/AcApPdfImportResources.d.ts +41 -0
- package/lib/AcApPdfImportResources.d.ts.map +1 -0
- package/lib/AcApPdfImportResources.js +52 -0
- package/lib/AcApPdfImportResources.js.map +1 -0
- package/lib/AcApPdfPlugin.d.ts +3 -3
- package/lib/AcApPdfPlugin.d.ts.map +1 -1
- package/lib/AcApPdfPlugin.js +23 -5
- package/lib/AcApPdfPlugin.js.map +1 -1
- package/lib/AcApPdfScaleCmd.d.ts +22 -0
- package/lib/AcApPdfScaleCmd.d.ts.map +1 -0
- package/lib/AcApPdfScaleCmd.js +185 -0
- package/lib/AcApPdfScaleCmd.js.map +1 -0
- package/lib/AcApPdfTextCmd.d.ts +73 -0
- package/lib/AcApPdfTextCmd.d.ts.map +1 -0
- package/lib/AcApPdfTextCmd.js +777 -0
- package/lib/AcApPdfTextCmd.js.map +1 -0
- package/lib/AcApPdfTextSession.d.ts +232 -0
- package/lib/AcApPdfTextSession.d.ts.map +1 -0
- package/lib/AcApPdfTextSession.js +826 -0
- package/lib/AcApPdfTextSession.js.map +1 -0
- package/lib/acapPdfI18n.d.ts +11 -0
- package/lib/acapPdfI18n.d.ts.map +1 -0
- package/lib/acapPdfI18n.js +57 -0
- package/lib/acapPdfI18n.js.map +1 -0
- package/lib/acapPdfPrompts.d.ts +12 -0
- package/lib/acapPdfPrompts.d.ts.map +1 -0
- package/lib/acapPdfPrompts.js +100 -0
- package/lib/acapPdfPrompts.js.map +1 -0
- package/lib/index.d.ts +28 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +28 -0
- package/lib/index.js.map +1 -1
- package/lib/pdfDeprecatedMatching.d.ts +27 -0
- package/lib/pdfDeprecatedMatching.d.ts.map +1 -0
- package/lib/pdfDeprecatedMatching.js +20 -0
- package/lib/pdfDeprecatedMatching.js.map +1 -0
- package/lib/pdfDimStrokeTexts.d.ts +55 -0
- package/lib/pdfDimStrokeTexts.d.ts.map +1 -0
- package/lib/pdfDimStrokeTexts.js +274 -0
- package/lib/pdfDimStrokeTexts.js.map +1 -0
- package/lib/pdfDimensionConvert.d.ts +80 -0
- package/lib/pdfDimensionConvert.d.ts.map +1 -0
- package/lib/pdfDimensionConvert.js +566 -0
- package/lib/pdfDimensionConvert.js.map +1 -0
- package/lib/pdfEntityStrokes.d.ts +13 -0
- package/lib/pdfEntityStrokes.d.ts.map +1 -0
- package/lib/pdfEntityStrokes.js +86 -0
- package/lib/pdfEntityStrokes.js.map +1 -0
- package/lib/pdfHatchRecover.d.ts +57 -0
- package/lib/pdfHatchRecover.d.ts.map +1 -0
- package/lib/pdfHatchRecover.js +315 -0
- package/lib/pdfHatchRecover.js.map +1 -0
- package/lib/pdfImportAppend.d.ts +24 -0
- package/lib/pdfImportAppend.d.ts.map +1 -0
- package/lib/pdfImportAppend.js +35 -0
- package/lib/pdfImportAppend.js.map +1 -0
- package/lib/pdfImportEntities.d.ts +63 -0
- package/lib/pdfImportEntities.d.ts.map +1 -0
- package/lib/pdfImportEntities.js +307 -0
- package/lib/pdfImportEntities.js.map +1 -0
- package/lib/pdfImportImages.d.ts +90 -0
- package/lib/pdfImportImages.d.ts.map +1 -0
- package/lib/pdfImportImages.js +294 -0
- package/lib/pdfImportImages.js.map +1 -0
- package/lib/pdfImportShapes.d.ts +63 -0
- package/lib/pdfImportShapes.d.ts.map +1 -0
- package/lib/pdfImportShapes.js +248 -0
- package/lib/pdfImportShapes.js.map +1 -0
- package/lib/pdfVectorImport.d.ts +218 -5
- package/lib/pdfVectorImport.d.ts.map +1 -1
- package/lib/pdfVectorImport.js +566 -98
- package/lib/pdfVectorImport.js.map +1 -1
- package/lib/recognition/pdfCurveRecognition.d.ts +91 -0
- package/lib/recognition/pdfCurveRecognition.d.ts.map +1 -0
- package/lib/recognition/pdfCurveRecognition.js +506 -0
- package/lib/recognition/pdfCurveRecognition.js.map +1 -0
- package/lib/recognition/pdfDimDigitRecognition.d.ts +18 -0
- package/lib/recognition/pdfDimDigitRecognition.d.ts.map +1 -0
- package/lib/recognition/pdfDimDigitRecognition.js +520 -0
- package/lib/recognition/pdfDimDigitRecognition.js.map +1 -0
- package/lib/recognition/pdfDimensionPattern.d.ts +173 -0
- package/lib/recognition/pdfDimensionPattern.d.ts.map +1 -0
- package/lib/recognition/pdfDimensionPattern.js +1023 -0
- package/lib/recognition/pdfDimensionPattern.js.map +1 -0
- package/lib/recognition/pdfFormBlocks.d.ts +58 -0
- package/lib/recognition/pdfFormBlocks.d.ts.map +1 -0
- package/lib/recognition/pdfFormBlocks.js +260 -0
- package/lib/recognition/pdfFormBlocks.js.map +1 -0
- package/lib/recognition/pdfGlyphClustering.d.ts +81 -0
- package/lib/recognition/pdfGlyphClustering.d.ts.map +1 -0
- package/lib/recognition/pdfGlyphClustering.js +1005 -0
- package/lib/recognition/pdfGlyphClustering.js.map +1 -0
- package/lib/recognition/pdfGlyphDictionary.d.ts +49 -0
- package/lib/recognition/pdfGlyphDictionary.d.ts.map +1 -0
- package/lib/recognition/pdfGlyphDictionary.js +188 -0
- package/lib/recognition/pdfGlyphDictionary.js.map +1 -0
- package/lib/recognition/pdfHatchFaces.d.ts +84 -0
- package/lib/recognition/pdfHatchFaces.d.ts.map +1 -0
- package/lib/recognition/pdfHatchFaces.js +1285 -0
- package/lib/recognition/pdfHatchFaces.js.map +1 -0
- package/lib/recognition/pdfHatchRecognition.d.ts +222 -0
- package/lib/recognition/pdfHatchRecognition.d.ts.map +1 -0
- package/lib/recognition/pdfHatchRecognition.js +3781 -0
- package/lib/recognition/pdfHatchRecognition.js.map +1 -0
- package/lib/recognition/pdfRecGeometry.d.ts +67 -0
- package/lib/recognition/pdfRecGeometry.d.ts.map +1 -0
- package/lib/recognition/pdfRecGeometry.js +365 -0
- package/lib/recognition/pdfRecGeometry.js.map +1 -0
- package/lib/recognition/pdfTextFontKind.d.ts +16 -0
- package/lib/recognition/pdfTextFontKind.d.ts.map +1 -0
- package/lib/recognition/pdfTextFontKind.js +51 -0
- package/lib/recognition/pdfTextFontKind.js.map +1 -0
- package/lib/recognition/pdfTextMerge.d.ts +71 -0
- package/lib/recognition/pdfTextMerge.d.ts.map +1 -0
- package/lib/recognition/pdfTextMerge.js +382 -0
- package/lib/recognition/pdfTextMerge.js.map +1 -0
- package/lib/recognition/pdfTextRunMerge.d.ts +28 -0
- package/lib/recognition/pdfTextRunMerge.d.ts.map +1 -0
- package/lib/recognition/pdfTextRunMerge.js +90 -0
- package/lib/recognition/pdfTextRunMerge.js.map +1 -0
- package/lib/register.d.ts +8 -2
- package/lib/register.d.ts.map +1 -1
- package/lib/register.js +29 -4
- package/lib/register.js.map +1 -1
- package/lib/ui/AcUiPdfDimPanel.d.ts +55 -0
- package/lib/ui/AcUiPdfDimPanel.d.ts.map +1 -0
- package/lib/ui/AcUiPdfDimPanel.js +347 -0
- package/lib/ui/AcUiPdfDimPanel.js.map +1 -0
- package/lib/ui/AcUiPdfHatchPanel.d.ts +57 -0
- package/lib/ui/AcUiPdfHatchPanel.d.ts.map +1 -0
- package/lib/ui/AcUiPdfHatchPanel.js +420 -0
- package/lib/ui/AcUiPdfHatchPanel.js.map +1 -0
- package/lib/ui/AcUiPdfImportDialog.d.ts +120 -0
- package/lib/ui/AcUiPdfImportDialog.d.ts.map +1 -0
- package/lib/ui/AcUiPdfImportDialog.js +673 -0
- package/lib/ui/AcUiPdfImportDialog.js.map +1 -0
- package/lib/ui/AcUiPdfTextPanel.d.ts +95 -0
- package/lib/ui/AcUiPdfTextPanel.d.ts.map +1 -0
- package/lib/ui/AcUiPdfTextPanel.js +775 -0
- package/lib/ui/AcUiPdfTextPanel.js.map +1 -0
- package/package.json +11 -11
|
@@ -0,0 +1,775 @@
|
|
|
1
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
2
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
3
|
+
if (!m) return o;
|
|
4
|
+
var i = m.call(o), r, ar = [], e;
|
|
5
|
+
try {
|
|
6
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
7
|
+
}
|
|
8
|
+
catch (error) { e = { error: error }; }
|
|
9
|
+
finally {
|
|
10
|
+
try {
|
|
11
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
12
|
+
}
|
|
13
|
+
finally { if (e) throw e.error; }
|
|
14
|
+
}
|
|
15
|
+
return ar;
|
|
16
|
+
};
|
|
17
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
18
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
19
|
+
if (ar || !(i in from)) {
|
|
20
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
21
|
+
ar[i] = from[i];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
25
|
+
};
|
|
26
|
+
var __values = (this && this.__values) || function(o) {
|
|
27
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
28
|
+
if (m) return m.call(o);
|
|
29
|
+
if (o && typeof o.length === "number") return {
|
|
30
|
+
next: function () {
|
|
31
|
+
if (o && i >= o.length) o = void 0;
|
|
32
|
+
return { value: o && o[i++], done: !o };
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
36
|
+
};
|
|
37
|
+
import { acedApplyUiTheme, acedSubscribeUiTheme, resolveUiTheme } from '@mlightcad/cad-simple-viewer';
|
|
38
|
+
import { acapPdfT } from '../acapPdfI18n';
|
|
39
|
+
var STYLE_ID = 'ml-pdftext-panel-styles';
|
|
40
|
+
var NEW_STYLE_VALUE = '\u0000new';
|
|
41
|
+
/**
|
|
42
|
+
* `pdftext` review panel shown in the palette: one text style section per
|
|
43
|
+
* font kind (style, font, big font, height scale, width factor) and the list
|
|
44
|
+
* of recovered lines with editable text. All state lives in the
|
|
45
|
+
* {@link AcApPdfTextSession}; the panel only renders it and reports changes.
|
|
46
|
+
*/
|
|
47
|
+
var AcUiPdfTextPanel = /** @class */ (function () {
|
|
48
|
+
function AcUiPdfTextPanel(options) {
|
|
49
|
+
var _this = this;
|
|
50
|
+
this.rowEls = [];
|
|
51
|
+
/** Rows selected for merging (Ctrl/Shift+click). */
|
|
52
|
+
this.selected = new Set();
|
|
53
|
+
/**
|
|
54
|
+
* Collapsed style groups. Default collapsed so the line list gets the space;
|
|
55
|
+
* opening "New text style…" expands that group.
|
|
56
|
+
*/
|
|
57
|
+
this.collapsed = new Set(['shx', 'mesh']);
|
|
58
|
+
ensureStyles();
|
|
59
|
+
this.options = options;
|
|
60
|
+
this.session = options.session;
|
|
61
|
+
this.fontOptions = buildFontOptions(options.fonts);
|
|
62
|
+
this.element = h('div', 'ml-pdftext-panel');
|
|
63
|
+
var applyTheme = function () {
|
|
64
|
+
return acedApplyUiTheme(resolveUiTheme(_this.element.parentElement), _this.element);
|
|
65
|
+
};
|
|
66
|
+
applyTheme();
|
|
67
|
+
this.unsubscribeTheme = acedSubscribeUiTheme(applyTheme);
|
|
68
|
+
this.settingsEl = h('div', 'ml-pdftext-settings');
|
|
69
|
+
var linesTitle = h('div', 'ml-pdftext-section-title', t('lines'));
|
|
70
|
+
var toolbar = h('div', 'ml-pdftext-toolbar');
|
|
71
|
+
this.mergeButton = button(t('merge'), 'secondary', function () {
|
|
72
|
+
return _this.mergeSelected();
|
|
73
|
+
});
|
|
74
|
+
this.mergeButton.title = t('mergeTip');
|
|
75
|
+
this.splitButton = button(t('split'), 'secondary', function () {
|
|
76
|
+
return _this.splitSelected();
|
|
77
|
+
});
|
|
78
|
+
this.splitButton.title = t('splitTip');
|
|
79
|
+
var adjacent = button(t('mergeAdjacent'), 'secondary', function () {
|
|
80
|
+
return _this.mergeAdjacent();
|
|
81
|
+
});
|
|
82
|
+
adjacent.title = t('mergeAdjacentTip');
|
|
83
|
+
this.mergeInfo = h('span', 'ml-pdftext-hint');
|
|
84
|
+
toolbar.append(this.mergeButton, this.splitButton, adjacent, this.mergeInfo);
|
|
85
|
+
var selectHint = h('div', 'ml-pdftext-hint', t('selectHint'));
|
|
86
|
+
this.listEl = h('div', 'ml-pdftext-lines');
|
|
87
|
+
this.listEl.setAttribute('role', 'list');
|
|
88
|
+
var footer = h('div', 'ml-pdftext-footer');
|
|
89
|
+
var hide = checkbox(t('hideStrokes'), false, function (checked) {
|
|
90
|
+
return _this.options.onHideStrokes(checked);
|
|
91
|
+
});
|
|
92
|
+
this.counterEl = h('span', 'ml-pdftext-counter');
|
|
93
|
+
var buttons = h('div', 'ml-pdftext-buttons');
|
|
94
|
+
var cancel = button(t('cancel'), 'secondary', function () {
|
|
95
|
+
return _this.options.onClose(false);
|
|
96
|
+
});
|
|
97
|
+
this.applyButton = button(t('apply'), 'primary', function () {
|
|
98
|
+
return _this.options.onClose(true);
|
|
99
|
+
});
|
|
100
|
+
buttons.append(cancel, this.applyButton);
|
|
101
|
+
footer.append(hide, this.counterEl, buttons);
|
|
102
|
+
this.element.append(this.settingsEl, linesTitle, toolbar, selectHint, this.listEl, footer);
|
|
103
|
+
this.renderSettings();
|
|
104
|
+
this.renderRows();
|
|
105
|
+
this.updateCounter();
|
|
106
|
+
}
|
|
107
|
+
/** Focuses the first line that still needs text, if any. */
|
|
108
|
+
AcUiPdfTextPanel.prototype.focusFirstUnread = function () {
|
|
109
|
+
var index = this.session.rows.findIndex(function (row) { return row.source === 'unread'; });
|
|
110
|
+
this.focusRow(index >= 0 ? index : 0);
|
|
111
|
+
};
|
|
112
|
+
/** Redraws a line row from the session (e.g. text filled from glyphs). */
|
|
113
|
+
AcUiPdfTextPanel.prototype.refreshRow = function (index) {
|
|
114
|
+
var el = this.rowEls[index];
|
|
115
|
+
if (!el)
|
|
116
|
+
return;
|
|
117
|
+
var row = this.session.rows[index];
|
|
118
|
+
var input = el.querySelector('.ml-pdftext-text');
|
|
119
|
+
if (input && input.value !== row.text)
|
|
120
|
+
input.value = row.text;
|
|
121
|
+
var include = el.querySelector('.ml-pdftext-include');
|
|
122
|
+
if (include)
|
|
123
|
+
include.checked = row.included;
|
|
124
|
+
this.fillRow(el, row);
|
|
125
|
+
};
|
|
126
|
+
/** Removes listeners. The element is removed by the palette host. */
|
|
127
|
+
AcUiPdfTextPanel.prototype.destroy = function () {
|
|
128
|
+
this.unsubscribeTheme();
|
|
129
|
+
this.element.remove();
|
|
130
|
+
};
|
|
131
|
+
AcUiPdfTextPanel.prototype.changed = function (settings) {
|
|
132
|
+
if (settings === void 0) { settings = false; }
|
|
133
|
+
if (settings)
|
|
134
|
+
this.renderSettings();
|
|
135
|
+
this.updateCounter();
|
|
136
|
+
this.options.onChange();
|
|
137
|
+
};
|
|
138
|
+
// ---------------------------------------------------------------- settings
|
|
139
|
+
AcUiPdfTextPanel.prototype.renderSettings = function () {
|
|
140
|
+
var _a;
|
|
141
|
+
var _this = this;
|
|
142
|
+
(_a = this.settingsEl).replaceChildren.apply(_a, __spreadArray([], __read(this.session.kinds.map(function (kind) { return _this.renderKind(kind); })), false));
|
|
143
|
+
};
|
|
144
|
+
AcUiPdfTextPanel.prototype.renderKind = function (kind) {
|
|
145
|
+
var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
|
|
146
|
+
var _this = this;
|
|
147
|
+
var _e, _f;
|
|
148
|
+
var session = this.session;
|
|
149
|
+
var choice = session.choice(kind);
|
|
150
|
+
// Naming a new style forces the group open so the name field is visible.
|
|
151
|
+
if (((_e = this.naming) === null || _e === void 0 ? void 0 : _e.kind) === kind)
|
|
152
|
+
this.collapsed.delete(kind);
|
|
153
|
+
var isCollapsed = this.collapsed.has(kind);
|
|
154
|
+
var section = h('div', 'ml-pdftext-section');
|
|
155
|
+
if (isCollapsed)
|
|
156
|
+
section.classList.add('is-collapsed');
|
|
157
|
+
var header = h('button', 'ml-pdftext-section-header');
|
|
158
|
+
header.type = 'button';
|
|
159
|
+
header.setAttribute('aria-expanded', String(!isCollapsed));
|
|
160
|
+
var chevron = h('span', 'ml-pdftext-chevron', isCollapsed ? '▶' : '▼');
|
|
161
|
+
chevron.setAttribute('aria-hidden', 'true');
|
|
162
|
+
var title = h('span', 'ml-pdftext-section-title', t(kind === 'shx' ? 'shxGroup' : 'meshGroup'));
|
|
163
|
+
var summary = h('span', 'ml-pdftext-section-summary', choice.styleName
|
|
164
|
+
? "".concat(choice.styleName).concat(choice.font ? " \u00B7 ".concat(choice.font) : '')
|
|
165
|
+
: '');
|
|
166
|
+
header.append(chevron, title, summary);
|
|
167
|
+
header.addEventListener('click', function () {
|
|
168
|
+
if (_this.collapsed.has(kind))
|
|
169
|
+
_this.collapsed.delete(kind);
|
|
170
|
+
else
|
|
171
|
+
_this.collapsed.add(kind);
|
|
172
|
+
_this.renderSettings();
|
|
173
|
+
});
|
|
174
|
+
section.append(header);
|
|
175
|
+
var body = h('div', 'ml-pdftext-section-body');
|
|
176
|
+
if (isCollapsed) {
|
|
177
|
+
body.hidden = true;
|
|
178
|
+
section.append(body);
|
|
179
|
+
return section;
|
|
180
|
+
}
|
|
181
|
+
// Text style: existing styles, the pending new one, "New text style…".
|
|
182
|
+
var styleSelect = h('select', 'ml-pdftext-input');
|
|
183
|
+
var names = session.styleNames();
|
|
184
|
+
if (choice.isNew) {
|
|
185
|
+
styleSelect.append(option(choice.styleName, "".concat(choice.styleName, " (").concat(t('newTag'), ")")));
|
|
186
|
+
}
|
|
187
|
+
try {
|
|
188
|
+
for (var names_1 = __values(names), names_1_1 = names_1.next(); !names_1_1.done; names_1_1 = names_1.next()) {
|
|
189
|
+
var name_1 = names_1_1.value;
|
|
190
|
+
styleSelect.append(option(name_1, name_1));
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
194
|
+
finally {
|
|
195
|
+
try {
|
|
196
|
+
if (names_1_1 && !names_1_1.done && (_a = names_1.return)) _a.call(names_1);
|
|
197
|
+
}
|
|
198
|
+
finally { if (e_1) throw e_1.error; }
|
|
199
|
+
}
|
|
200
|
+
styleSelect.append(option(NEW_STYLE_VALUE, t('newStyle')));
|
|
201
|
+
styleSelect.value = choice.styleName;
|
|
202
|
+
styleSelect.addEventListener('change', function () {
|
|
203
|
+
var _a;
|
|
204
|
+
if (styleSelect.value === NEW_STYLE_VALUE) {
|
|
205
|
+
_this.naming = { kind: kind };
|
|
206
|
+
_this.collapsed.delete(kind);
|
|
207
|
+
_this.renderSettings();
|
|
208
|
+
(_a = _this.settingsEl
|
|
209
|
+
.querySelector('.ml-pdftext-new-name')) === null || _a === void 0 ? void 0 : _a.focus();
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
session.selectStyle(kind, styleSelect.value);
|
|
213
|
+
_this.naming = undefined;
|
|
214
|
+
_this.changed(true);
|
|
215
|
+
});
|
|
216
|
+
body.append(field(t('style'), styleSelect));
|
|
217
|
+
if (((_f = this.naming) === null || _f === void 0 ? void 0 : _f.kind) === kind)
|
|
218
|
+
body.append(this.renderNaming(kind));
|
|
219
|
+
// Font and big font.
|
|
220
|
+
var fontSelect = h('select', 'ml-pdftext-input');
|
|
221
|
+
var known = this.fontOptions.some(function (item) {
|
|
222
|
+
return sameName(item.value, choice.font);
|
|
223
|
+
});
|
|
224
|
+
if (!known && choice.font) {
|
|
225
|
+
fontSelect.append(option(choice.font, choice.font));
|
|
226
|
+
}
|
|
227
|
+
var _loop_1 = function (type, label) {
|
|
228
|
+
var e_5, _p;
|
|
229
|
+
var items = this_1.fontOptions.filter(function (item) { return item.type === type; });
|
|
230
|
+
if (items.length === 0)
|
|
231
|
+
return "continue";
|
|
232
|
+
var group = document.createElement('optgroup');
|
|
233
|
+
group.label = label;
|
|
234
|
+
try {
|
|
235
|
+
for (var items_1 = (e_5 = void 0, __values(items)), items_1_1 = items_1.next(); !items_1_1.done; items_1_1 = items_1.next()) {
|
|
236
|
+
var item = items_1_1.value;
|
|
237
|
+
group.append(option(item.value, item.label));
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
241
|
+
finally {
|
|
242
|
+
try {
|
|
243
|
+
if (items_1_1 && !items_1_1.done && (_p = items_1.return)) _p.call(items_1);
|
|
244
|
+
}
|
|
245
|
+
finally { if (e_5) throw e_5.error; }
|
|
246
|
+
}
|
|
247
|
+
fontSelect.append(group);
|
|
248
|
+
};
|
|
249
|
+
var this_1 = this;
|
|
250
|
+
try {
|
|
251
|
+
for (var _g = __values([
|
|
252
|
+
['shx', t('shxFonts')],
|
|
253
|
+
['mesh', t('ttfFonts')]
|
|
254
|
+
]), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
255
|
+
var _j = __read(_h.value, 2), type = _j[0], label = _j[1];
|
|
256
|
+
_loop_1(type, label);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
260
|
+
finally {
|
|
261
|
+
try {
|
|
262
|
+
if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
|
|
263
|
+
}
|
|
264
|
+
finally { if (e_2) throw e_2.error; }
|
|
265
|
+
}
|
|
266
|
+
fontSelect.value = matchValue(fontSelect, choice.font);
|
|
267
|
+
fontSelect.addEventListener('change', function () {
|
|
268
|
+
session.setFont(kind, fontSelect.value);
|
|
269
|
+
_this.changed(true);
|
|
270
|
+
});
|
|
271
|
+
body.append(field(t('font'), fontSelect));
|
|
272
|
+
var fontType = this.fontType(choice.font);
|
|
273
|
+
var bigSelect = h('select', 'ml-pdftext-input');
|
|
274
|
+
bigSelect.append(option('', t('noBigFont')));
|
|
275
|
+
if (choice.bigFont &&
|
|
276
|
+
!this.fontOptions.some(function (item) { return sameName(item.value, choice.bigFont); })) {
|
|
277
|
+
bigSelect.append(option(choice.bigFont, choice.bigFont));
|
|
278
|
+
}
|
|
279
|
+
try {
|
|
280
|
+
for (var _k = __values(this.fontOptions), _l = _k.next(); !_l.done; _l = _k.next()) {
|
|
281
|
+
var item = _l.value;
|
|
282
|
+
if (item.type === 'shx')
|
|
283
|
+
bigSelect.append(option(item.value, item.label));
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
287
|
+
finally {
|
|
288
|
+
try {
|
|
289
|
+
if (_l && !_l.done && (_c = _k.return)) _c.call(_k);
|
|
290
|
+
}
|
|
291
|
+
finally { if (e_3) throw e_3.error; }
|
|
292
|
+
}
|
|
293
|
+
bigSelect.value = matchValue(bigSelect, choice.bigFont);
|
|
294
|
+
bigSelect.disabled = fontType === 'mesh';
|
|
295
|
+
bigSelect.addEventListener('change', function () {
|
|
296
|
+
session.setBigFont(kind, bigSelect.value);
|
|
297
|
+
_this.changed(true);
|
|
298
|
+
});
|
|
299
|
+
body.append(field(t('bigFont'), bigSelect));
|
|
300
|
+
// Which fonts will draw the text, and warnings.
|
|
301
|
+
var fonts = [choice.font, choice.bigFont].filter(Boolean).join(' + ');
|
|
302
|
+
body.append(h('div', 'ml-pdftext-hint', t('fontsUsed', { fonts: fonts })));
|
|
303
|
+
try {
|
|
304
|
+
for (var _m = __values([choice.font, choice.bigFont]), _o = _m.next(); !_o.done; _o = _m.next()) {
|
|
305
|
+
var font = _o.value;
|
|
306
|
+
if (!font || this.fontType(font))
|
|
307
|
+
continue;
|
|
308
|
+
var fallback = this.options.replacementFont(font);
|
|
309
|
+
body.append(h('div', 'ml-pdftext-warning', t('fontMissing', { font: font, fallback: fallback || '-' })));
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
313
|
+
finally {
|
|
314
|
+
try {
|
|
315
|
+
if (_o && !_o.done && (_d = _m.return)) _d.call(_m);
|
|
316
|
+
}
|
|
317
|
+
finally { if (e_4) throw e_4.error; }
|
|
318
|
+
}
|
|
319
|
+
if (fontType && fontType !== kind) {
|
|
320
|
+
body.append(h('div', 'ml-pdftext-warning', t(kind === 'shx' ? 'fontNotShx' : 'fontNotTtf')));
|
|
321
|
+
}
|
|
322
|
+
if (session.changesExistingStyle(kind)) {
|
|
323
|
+
body.append(h('div', 'ml-pdftext-warning', t('styleChanges', { style: choice.styleName })));
|
|
324
|
+
}
|
|
325
|
+
// Size.
|
|
326
|
+
var sizeRow = h('div', 'ml-pdftext-size');
|
|
327
|
+
var height = numberInput(choice.heightScale, 0.01, function (value) {
|
|
328
|
+
session.setSize(kind, { heightScale: value });
|
|
329
|
+
_this.changed();
|
|
330
|
+
});
|
|
331
|
+
sizeRow.append(field(t('heightScale'), height));
|
|
332
|
+
var width = numberInput(choice.widthFactor, 0.01, function (value) {
|
|
333
|
+
session.setSize(kind, { widthFactor: value });
|
|
334
|
+
_this.changed();
|
|
335
|
+
});
|
|
336
|
+
width.disabled = choice.autoWidth;
|
|
337
|
+
var auto = checkbox(t('autoWidth'), choice.autoWidth, function (checked) {
|
|
338
|
+
session.setSize(kind, { autoWidth: checked });
|
|
339
|
+
_this.changed(true);
|
|
340
|
+
});
|
|
341
|
+
var widthField = field(t('widthFactor'), width);
|
|
342
|
+
widthField.append(auto);
|
|
343
|
+
sizeRow.append(widthField);
|
|
344
|
+
body.append(sizeRow);
|
|
345
|
+
section.append(body);
|
|
346
|
+
return section;
|
|
347
|
+
};
|
|
348
|
+
AcUiPdfTextPanel.prototype.renderNaming = function (kind) {
|
|
349
|
+
var _this = this;
|
|
350
|
+
var _a;
|
|
351
|
+
var wrap = h('div', 'ml-pdftext-naming');
|
|
352
|
+
var input = h('input', 'ml-pdftext-input ml-pdftext-new-name');
|
|
353
|
+
input.type = 'text';
|
|
354
|
+
input.placeholder = t('newStyleName');
|
|
355
|
+
var create = function () {
|
|
356
|
+
var error = _this.session.newStyle(kind, input.value);
|
|
357
|
+
if (error) {
|
|
358
|
+
_this.naming = { kind: kind, error: error };
|
|
359
|
+
var message = wrap.querySelector('.ml-pdftext-warning');
|
|
360
|
+
if (message)
|
|
361
|
+
message.textContent = t("nameError.".concat(error));
|
|
362
|
+
else
|
|
363
|
+
wrap.append(h('div', 'ml-pdftext-warning', t("nameError.".concat(error))));
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
_this.naming = undefined;
|
|
367
|
+
_this.changed(true);
|
|
368
|
+
};
|
|
369
|
+
input.addEventListener('keydown', function (event) {
|
|
370
|
+
if (event.key === 'Enter') {
|
|
371
|
+
event.preventDefault();
|
|
372
|
+
create();
|
|
373
|
+
}
|
|
374
|
+
else if (event.key === 'Escape') {
|
|
375
|
+
event.preventDefault();
|
|
376
|
+
_this.naming = undefined;
|
|
377
|
+
_this.renderSettings();
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
var row = h('div', 'ml-pdftext-naming-row');
|
|
381
|
+
row.append(input, button(t('create'), 'primary', create), button(t('cancel'), 'secondary', function () {
|
|
382
|
+
_this.naming = undefined;
|
|
383
|
+
_this.renderSettings();
|
|
384
|
+
}));
|
|
385
|
+
wrap.append(row);
|
|
386
|
+
if ((_a = this.naming) === null || _a === void 0 ? void 0 : _a.error) {
|
|
387
|
+
wrap.append(h('div', 'ml-pdftext-warning', t("nameError.".concat(this.naming.error))));
|
|
388
|
+
}
|
|
389
|
+
return wrap;
|
|
390
|
+
};
|
|
391
|
+
AcUiPdfTextPanel.prototype.fontType = function (font) {
|
|
392
|
+
var _a;
|
|
393
|
+
return (_a = this.fontOptions.find(function (item) { return sameName(item.value, font); })) === null || _a === void 0 ? void 0 : _a.type;
|
|
394
|
+
};
|
|
395
|
+
// ------------------------------------------------------------------- lines
|
|
396
|
+
/** Rebuilds the list (after a merge or split the rows change). */
|
|
397
|
+
AcUiPdfTextPanel.prototype.renderRows = function () {
|
|
398
|
+
var e_6, _a, e_7, _b;
|
|
399
|
+
this.rowEls.length = 0;
|
|
400
|
+
this.listEl.replaceChildren();
|
|
401
|
+
var order = this.session.rows
|
|
402
|
+
.map(function (row, index) { return ({ row: row, index: index }); })
|
|
403
|
+
// Lines nothing could read come first: they need the user.
|
|
404
|
+
.sort(function (a, b) {
|
|
405
|
+
return Number(b.row.source === 'unread') - Number(a.row.source === 'unread');
|
|
406
|
+
});
|
|
407
|
+
try {
|
|
408
|
+
for (var order_1 = __values(order), order_1_1 = order_1.next(); !order_1_1.done; order_1_1 = order_1.next()) {
|
|
409
|
+
var index = order_1_1.value.index;
|
|
410
|
+
var el = this.renderRow(index);
|
|
411
|
+
this.rowEls[index] = el;
|
|
412
|
+
this.listEl.append(el);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
416
|
+
finally {
|
|
417
|
+
try {
|
|
418
|
+
if (order_1_1 && !order_1_1.done && (_a = order_1.return)) _a.call(order_1);
|
|
419
|
+
}
|
|
420
|
+
finally { if (e_6) throw e_6.error; }
|
|
421
|
+
}
|
|
422
|
+
try {
|
|
423
|
+
// Rows that no longer exist cannot stay selected.
|
|
424
|
+
for (var _c = __values(__spreadArray([], __read(this.selected), false)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
425
|
+
var row = _d.value;
|
|
426
|
+
if (!this.session.rows.includes(row))
|
|
427
|
+
this.selected.delete(row);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
431
|
+
finally {
|
|
432
|
+
try {
|
|
433
|
+
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
434
|
+
}
|
|
435
|
+
finally { if (e_7) throw e_7.error; }
|
|
436
|
+
}
|
|
437
|
+
this.updateSelection();
|
|
438
|
+
};
|
|
439
|
+
AcUiPdfTextPanel.prototype.renderRow = function (index) {
|
|
440
|
+
var _this = this;
|
|
441
|
+
var _a, _b;
|
|
442
|
+
var row = this.session.rows[index];
|
|
443
|
+
var el = h('div', 'ml-pdftext-row');
|
|
444
|
+
el.setAttribute('role', 'listitem');
|
|
445
|
+
el.dataset.index = String(index);
|
|
446
|
+
// Ctrl/Shift+click selects rows (to merge them) instead of editing.
|
|
447
|
+
el.addEventListener('mousedown', function (event) {
|
|
448
|
+
if (!(event.ctrlKey || event.metaKey || event.shiftKey))
|
|
449
|
+
return;
|
|
450
|
+
var target = event.target;
|
|
451
|
+
if (target.closest('.ml-pdftext-include, .ml-pdftext-kind'))
|
|
452
|
+
return;
|
|
453
|
+
event.preventDefault();
|
|
454
|
+
_this.selectRow(_this.session.rows[index], event.shiftKey ? 'range' : 'toggle');
|
|
455
|
+
});
|
|
456
|
+
var include = h('input', 'ml-pdftext-include');
|
|
457
|
+
include.type = 'checkbox';
|
|
458
|
+
include.title = t('include');
|
|
459
|
+
include.checked = row.included;
|
|
460
|
+
include.addEventListener('change', function () {
|
|
461
|
+
_this.session.setIncluded(index, include.checked);
|
|
462
|
+
_this.updateRow(index);
|
|
463
|
+
_this.changed();
|
|
464
|
+
});
|
|
465
|
+
// A block of several lines is edited in a text area, one line per row.
|
|
466
|
+
var paragraphs = (_b = (_a = row.merge) === null || _a === void 0 ? void 0 : _a.paragraphs.length) !== null && _b !== void 0 ? _b : 1;
|
|
467
|
+
var multiline = paragraphs > 1 || row.text.includes('\n');
|
|
468
|
+
var input = multiline
|
|
469
|
+
? h('textarea', 'ml-pdftext-input ml-pdftext-text')
|
|
470
|
+
: h('input', 'ml-pdftext-input ml-pdftext-text');
|
|
471
|
+
if (input instanceof HTMLInputElement)
|
|
472
|
+
input.type = 'text';
|
|
473
|
+
else
|
|
474
|
+
input.rows = Math.max(2, row.text.split('\n').length);
|
|
475
|
+
input.value = row.text;
|
|
476
|
+
input.placeholder = t('textPlaceholder');
|
|
477
|
+
input.addEventListener('focus', function () {
|
|
478
|
+
if (!_this.selected.has(_this.session.rows[index])) {
|
|
479
|
+
_this.selectRow(_this.session.rows[index], 'single');
|
|
480
|
+
}
|
|
481
|
+
_this.options.onFocusRows(__spreadArray([], __read(_this.selected), false), true);
|
|
482
|
+
});
|
|
483
|
+
var edited = false;
|
|
484
|
+
var commit = function () {
|
|
485
|
+
if (!edited)
|
|
486
|
+
return;
|
|
487
|
+
edited = false;
|
|
488
|
+
var changed = _this.options.onCommitRow(index);
|
|
489
|
+
if (changed.length === 0)
|
|
490
|
+
return;
|
|
491
|
+
changed.forEach(function (other) { return _this.refreshRow(other); });
|
|
492
|
+
_this.changed();
|
|
493
|
+
};
|
|
494
|
+
input.addEventListener('input', function () {
|
|
495
|
+
edited = true;
|
|
496
|
+
_this.session.setText(index, input.value);
|
|
497
|
+
include.checked = _this.session.rows[index].included;
|
|
498
|
+
_this.updateRow(index);
|
|
499
|
+
_this.changed();
|
|
500
|
+
});
|
|
501
|
+
input.addEventListener('blur', commit);
|
|
502
|
+
input.addEventListener('keydown', function (event) {
|
|
503
|
+
var key = event.key;
|
|
504
|
+
// In a text area Enter starts a new line; Ctrl+Enter moves on.
|
|
505
|
+
if (key !== 'Enter')
|
|
506
|
+
return;
|
|
507
|
+
if (multiline && !event.ctrlKey)
|
|
508
|
+
return;
|
|
509
|
+
event.preventDefault();
|
|
510
|
+
commit();
|
|
511
|
+
_this.focusNext(index);
|
|
512
|
+
});
|
|
513
|
+
var tags = h('span', 'ml-pdftext-tags');
|
|
514
|
+
var badge = h('span', 'ml-pdftext-badge');
|
|
515
|
+
tags.append(badge);
|
|
516
|
+
if (row.merge)
|
|
517
|
+
tags.append(h('span', 'ml-pdftext-mtext', t('mtextTag')));
|
|
518
|
+
var kind = h('button', 'ml-pdftext-kind');
|
|
519
|
+
kind.type = 'button';
|
|
520
|
+
kind.title = t('switchKind');
|
|
521
|
+
kind.addEventListener('click', function () {
|
|
522
|
+
var current = _this.session.rows[index].kind;
|
|
523
|
+
_this.session.setKind(index, current === 'shx' ? 'mesh' : 'shx');
|
|
524
|
+
_this.updateRow(index);
|
|
525
|
+
_this.changed(true);
|
|
526
|
+
});
|
|
527
|
+
el.append(include, input, tags, kind);
|
|
528
|
+
this.fillRow(el, row);
|
|
529
|
+
return el;
|
|
530
|
+
};
|
|
531
|
+
AcUiPdfTextPanel.prototype.updateRow = function (index) {
|
|
532
|
+
var el = this.rowEls[index];
|
|
533
|
+
if (el)
|
|
534
|
+
this.fillRow(el, this.session.rows[index]);
|
|
535
|
+
};
|
|
536
|
+
AcUiPdfTextPanel.prototype.fillRow = function (el, row) {
|
|
537
|
+
el.dataset.source = row.source;
|
|
538
|
+
el.classList.toggle('is-skipped', !row.included || !row.text.trim());
|
|
539
|
+
var badge = el.querySelector('.ml-pdftext-badge');
|
|
540
|
+
if (badge)
|
|
541
|
+
badge.textContent = t("source.".concat(row.source));
|
|
542
|
+
var kind = el.querySelector('.ml-pdftext-kind');
|
|
543
|
+
if (kind)
|
|
544
|
+
kind.textContent = t("kind.".concat(row.kind));
|
|
545
|
+
};
|
|
546
|
+
AcUiPdfTextPanel.prototype.focusRow = function (index) {
|
|
547
|
+
var _a, _b;
|
|
548
|
+
(_b = (_a = this.rowEls[index]) === null || _a === void 0 ? void 0 : _a.querySelector('.ml-pdftext-text')) === null || _b === void 0 ? void 0 : _b.focus();
|
|
549
|
+
};
|
|
550
|
+
/** Enter: next unread line, else the next line in the list. */
|
|
551
|
+
AcUiPdfTextPanel.prototype.focusNext = function (index) {
|
|
552
|
+
var _a, _b;
|
|
553
|
+
var els = Array.from(this.listEl.children);
|
|
554
|
+
var position = els.findIndex(function (el) { return el.dataset.index === String(index); });
|
|
555
|
+
var after = __spreadArray(__spreadArray([], __read(els.slice(position + 1)), false), __read(els.slice(0, position)), false);
|
|
556
|
+
var target = (_b = (_a = after.find(function (el) { return el.dataset.source === 'unread'; })) !== null && _a !== void 0 ? _a : after[0]) !== null && _b !== void 0 ? _b : undefined;
|
|
557
|
+
if (target)
|
|
558
|
+
this.focusRow(Number(target.dataset.index));
|
|
559
|
+
};
|
|
560
|
+
// --------------------------------------------------------------- selection
|
|
561
|
+
/**
|
|
562
|
+
* Changes the selected rows: `single` selects only `row`, `toggle` adds or
|
|
563
|
+
* removes it (Ctrl+click), `range` selects from the last clicked row to
|
|
564
|
+
* `row` in list order (Shift+click).
|
|
565
|
+
*/
|
|
566
|
+
AcUiPdfTextPanel.prototype.selectRow = function (row, mode) {
|
|
567
|
+
var _this = this;
|
|
568
|
+
if (mode === 'range' &&
|
|
569
|
+
this.anchor &&
|
|
570
|
+
this.session.rows.includes(this.anchor)) {
|
|
571
|
+
var order = Array.from(this.listEl.children).map(function (el) { return _this.session.rows[Number(el.dataset.index)]; });
|
|
572
|
+
var a = order.indexOf(this.anchor);
|
|
573
|
+
var b = order.indexOf(row);
|
|
574
|
+
this.selected.clear();
|
|
575
|
+
for (var i = Math.min(a, b); i <= Math.max(a, b); i++) {
|
|
576
|
+
this.selected.add(order[i]);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
else if (mode === 'toggle') {
|
|
580
|
+
if (this.selected.has(row))
|
|
581
|
+
this.selected.delete(row);
|
|
582
|
+
else
|
|
583
|
+
this.selected.add(row);
|
|
584
|
+
this.anchor = row;
|
|
585
|
+
}
|
|
586
|
+
else {
|
|
587
|
+
this.selected.clear();
|
|
588
|
+
this.selected.add(row);
|
|
589
|
+
this.anchor = row;
|
|
590
|
+
}
|
|
591
|
+
this.updateSelection();
|
|
592
|
+
if (mode !== 'single')
|
|
593
|
+
this.options.onFocusRows(__spreadArray([], __read(this.selected), false), false);
|
|
594
|
+
};
|
|
595
|
+
AcUiPdfTextPanel.prototype.updateSelection = function () {
|
|
596
|
+
var _this = this;
|
|
597
|
+
this.rowEls.forEach(function (el, i) {
|
|
598
|
+
return el === null || el === void 0 ? void 0 : el.classList.toggle('is-selected', _this.selected.has(_this.session.rows[i]));
|
|
599
|
+
});
|
|
600
|
+
var rows = __spreadArray([], __read(this.selected), false);
|
|
601
|
+
this.mergeButton.disabled = rows.length < 2;
|
|
602
|
+
this.splitButton.disabled = !rows.some(function (row) { return row.merge; });
|
|
603
|
+
};
|
|
604
|
+
/** Merges the selected rows into one MTEXT row. */
|
|
605
|
+
AcUiPdfTextPanel.prototype.mergeSelected = function () {
|
|
606
|
+
var _this = this;
|
|
607
|
+
var indexes = __spreadArray([], __read(this.selected), false).map(function (row) {
|
|
608
|
+
return _this.session.rows.indexOf(row);
|
|
609
|
+
});
|
|
610
|
+
var merged = this.session.merge(indexes);
|
|
611
|
+
if (merged === undefined)
|
|
612
|
+
return;
|
|
613
|
+
this.selected.clear();
|
|
614
|
+
this.selected.add(this.session.rows[merged]);
|
|
615
|
+
this.anchor = this.session.rows[merged];
|
|
616
|
+
this.afterRowsChanged(merged);
|
|
617
|
+
};
|
|
618
|
+
/** Splits the selected merged rows back into their rows. */
|
|
619
|
+
AcUiPdfTextPanel.prototype.splitSelected = function () {
|
|
620
|
+
var e_8, _a;
|
|
621
|
+
var _this = this;
|
|
622
|
+
var restored = [];
|
|
623
|
+
try {
|
|
624
|
+
for (var _b = __values(__spreadArray([], __read(this.selected), false)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
625
|
+
var row = _c.value;
|
|
626
|
+
var indexes = this.session.split(this.session.rows.indexOf(row));
|
|
627
|
+
restored.push.apply(restored, __spreadArray([], __read(indexes.map(function (i) { return _this.session.rows[i]; })), false));
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
catch (e_8_1) { e_8 = { error: e_8_1 }; }
|
|
631
|
+
finally {
|
|
632
|
+
try {
|
|
633
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
634
|
+
}
|
|
635
|
+
finally { if (e_8) throw e_8.error; }
|
|
636
|
+
}
|
|
637
|
+
if (restored.length === 0)
|
|
638
|
+
return;
|
|
639
|
+
this.selected = new Set(restored);
|
|
640
|
+
this.anchor = restored[0];
|
|
641
|
+
this.afterRowsChanged(this.session.rows.indexOf(restored[0]));
|
|
642
|
+
};
|
|
643
|
+
/** Merges all rows that read as one line. */
|
|
644
|
+
AcUiPdfTextPanel.prototype.mergeAdjacent = function () {
|
|
645
|
+
var count = this.session.mergeAdjacent();
|
|
646
|
+
this.mergeInfo.textContent = t('mergedCount', { count: count });
|
|
647
|
+
if (count === 0)
|
|
648
|
+
return;
|
|
649
|
+
this.selected.clear();
|
|
650
|
+
this.afterRowsChanged();
|
|
651
|
+
};
|
|
652
|
+
AcUiPdfTextPanel.prototype.afterRowsChanged = function (focus) {
|
|
653
|
+
var _a;
|
|
654
|
+
this.renderRows();
|
|
655
|
+
this.changed(true);
|
|
656
|
+
if (focus !== undefined) {
|
|
657
|
+
this.options.onFocusRows(__spreadArray([], __read(this.selected), false), true);
|
|
658
|
+
(_a = this.rowEls[focus]) === null || _a === void 0 ? void 0 : _a.scrollIntoView({ block: 'nearest' });
|
|
659
|
+
}
|
|
660
|
+
};
|
|
661
|
+
AcUiPdfTextPanel.prototype.updateCounter = function () {
|
|
662
|
+
var ready = this.session.readyRows.length;
|
|
663
|
+
this.counterEl.textContent = t('ready', {
|
|
664
|
+
ready: ready,
|
|
665
|
+
count: this.session.rows.length
|
|
666
|
+
});
|
|
667
|
+
this.applyButton.disabled = ready === 0;
|
|
668
|
+
};
|
|
669
|
+
return AcUiPdfTextPanel;
|
|
670
|
+
}());
|
|
671
|
+
export { AcUiPdfTextPanel };
|
|
672
|
+
/** Panel string `jig.pdftext.panel.<key>`. */
|
|
673
|
+
function t(key, params) {
|
|
674
|
+
return acapPdfT("jig.pdftext.panel.".concat(key), params);
|
|
675
|
+
}
|
|
676
|
+
function h(tag, className, text) {
|
|
677
|
+
var el = document.createElement(tag);
|
|
678
|
+
if (className)
|
|
679
|
+
el.className = className;
|
|
680
|
+
if (text !== undefined)
|
|
681
|
+
el.textContent = text;
|
|
682
|
+
return el;
|
|
683
|
+
}
|
|
684
|
+
function option(value, label) {
|
|
685
|
+
var el = document.createElement('option');
|
|
686
|
+
el.value = value;
|
|
687
|
+
el.textContent = label;
|
|
688
|
+
return el;
|
|
689
|
+
}
|
|
690
|
+
function field(label, control) {
|
|
691
|
+
var el = h('label', 'ml-pdftext-field');
|
|
692
|
+
el.append(h('span', 'ml-pdftext-label', label), control);
|
|
693
|
+
return el;
|
|
694
|
+
}
|
|
695
|
+
function button(label, kind, onClick) {
|
|
696
|
+
var el = h('button', kind === 'primary' ? 'ml-pdftext-btn' : 'ml-pdftext-btn is-secondary', label);
|
|
697
|
+
el.type = 'button';
|
|
698
|
+
el.addEventListener('click', onClick);
|
|
699
|
+
return el;
|
|
700
|
+
}
|
|
701
|
+
function checkbox(label, checked, onChange) {
|
|
702
|
+
var el = h('label', 'ml-pdftext-check');
|
|
703
|
+
var input = h('input');
|
|
704
|
+
input.type = 'checkbox';
|
|
705
|
+
input.checked = checked;
|
|
706
|
+
input.addEventListener('change', function () { return onChange(input.checked); });
|
|
707
|
+
el.append(input, h('span', undefined, label));
|
|
708
|
+
return el;
|
|
709
|
+
}
|
|
710
|
+
function numberInput(value, step, onChange) {
|
|
711
|
+
var el = h('input', 'ml-pdftext-input ml-pdftext-number');
|
|
712
|
+
el.type = 'number';
|
|
713
|
+
el.min = String(step);
|
|
714
|
+
el.step = String(step);
|
|
715
|
+
el.value = String(Number(value.toFixed(3)));
|
|
716
|
+
el.addEventListener('input', function () {
|
|
717
|
+
var next = Number(el.value);
|
|
718
|
+
if (Number.isFinite(next) && next > 0)
|
|
719
|
+
onChange(next);
|
|
720
|
+
});
|
|
721
|
+
return el;
|
|
722
|
+
}
|
|
723
|
+
function sameName(a, b) {
|
|
724
|
+
return a.trim().toLowerCase() === b.trim().toLowerCase();
|
|
725
|
+
}
|
|
726
|
+
/** The option value matching `name` case-insensitively, else `name`. */
|
|
727
|
+
function matchValue(select, name) {
|
|
728
|
+
var match = Array.from(select.options).find(function (item) {
|
|
729
|
+
return sameName(item.value, name);
|
|
730
|
+
});
|
|
731
|
+
return match ? match.value : name;
|
|
732
|
+
}
|
|
733
|
+
/** Catalog fonts by first alias, labelled by file name (like the STYLE dialog). */
|
|
734
|
+
function buildFontOptions(fonts) {
|
|
735
|
+
var e_9, _a;
|
|
736
|
+
var _b;
|
|
737
|
+
var options = [];
|
|
738
|
+
var seen = new Set();
|
|
739
|
+
try {
|
|
740
|
+
for (var fonts_1 = __values(fonts), fonts_1_1 = fonts_1.next(); !fonts_1_1.done; fonts_1_1 = fonts_1.next()) {
|
|
741
|
+
var info = fonts_1_1.value;
|
|
742
|
+
var primary = (_b = info.name.find(function (name) { return name.trim(); })) === null || _b === void 0 ? void 0 : _b.trim();
|
|
743
|
+
if (!primary)
|
|
744
|
+
continue;
|
|
745
|
+
var key = primary.toLowerCase();
|
|
746
|
+
if (seen.has(key))
|
|
747
|
+
continue;
|
|
748
|
+
seen.add(key);
|
|
749
|
+
options.push({
|
|
750
|
+
value: primary,
|
|
751
|
+
label: info.file || primary,
|
|
752
|
+
type: info.type
|
|
753
|
+
});
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
757
|
+
finally {
|
|
758
|
+
try {
|
|
759
|
+
if (fonts_1_1 && !fonts_1_1.done && (_a = fonts_1.return)) _a.call(fonts_1);
|
|
760
|
+
}
|
|
761
|
+
finally { if (e_9) throw e_9.error; }
|
|
762
|
+
}
|
|
763
|
+
return options.sort(function (a, b) { return a.label.localeCompare(b.label); });
|
|
764
|
+
}
|
|
765
|
+
function ensureStyles() {
|
|
766
|
+
var css = "\n.ml-pdftext-panel {\n flex: 1;\n min-height: 0;\n display: flex;\n flex-direction: column;\n gap: 6px;\n padding: 8px;\n box-sizing: border-box;\n color: var(--ml-ui-text, #303133);\n font-size: 12px;\n}\n.ml-pdftext-settings {\n display: flex;\n flex-direction: column;\n gap: 6px;\n overflow: auto;\n max-height: 55%;\n flex-shrink: 0;\n}\n.ml-pdftext-section {\n display: flex;\n flex-direction: column;\n gap: 4px;\n padding: 4px 8px 6px;\n border: 1px solid var(--ml-ui-border, #dcdfe6);\n border-radius: 6px;\n}\n.ml-pdftext-section.is-collapsed {\n padding-bottom: 4px;\n}\n.ml-pdftext-section-header {\n display: flex;\n align-items: center;\n gap: 6px;\n margin: 0 -2px;\n padding: 2px;\n border: none;\n border-radius: 4px;\n background: transparent;\n color: inherit;\n font: inherit;\n text-align: left;\n cursor: pointer;\n}\n.ml-pdftext-section-header:hover {\n background: var(--ml-ui-hover, rgba(144, 147, 153, 0.12));\n}\n.ml-pdftext-chevron {\n flex: 0 0 auto;\n width: 1em;\n color: var(--ml-ui-text-muted, #606266);\n font-size: 10px;\n text-align: center;\n}\n.ml-pdftext-section-title {\n flex: 0 1 auto;\n font-weight: 600;\n min-width: 0;\n}\n.ml-pdftext-section-summary {\n flex: 1 1 auto;\n min-width: 0;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n color: var(--ml-ui-text-muted, #606266);\n font-weight: 400;\n text-align: right;\n}\n.ml-pdftext-section:not(.is-collapsed) .ml-pdftext-section-summary {\n display: none;\n}\n.ml-pdftext-section-body {\n display: flex;\n flex-direction: column;\n gap: 4px;\n}\n/* Author display:flex would otherwise override the UA [hidden] rule. */\n.ml-pdftext-section-body[hidden] {\n display: none;\n}\n.ml-pdftext-field {\n display: grid;\n grid-template-columns: 92px 1fr;\n align-items: center;\n gap: 6px;\n}\n.ml-pdftext-label {\n color: var(--ml-ui-text-muted, #606266);\n}\n.ml-pdftext-input {\n min-width: 0;\n box-sizing: border-box;\n padding: 3px 6px;\n border: 1px solid var(--ml-ui-border, #dcdfe6);\n border-radius: 4px;\n background: transparent;\n color: inherit;\n font: inherit;\n}\n.ml-pdftext-input option,\n.ml-pdftext-input optgroup {\n background: var(--ml-ui-bg, #ffffff);\n color: var(--ml-ui-text, #303133);\n}\n.ml-pdftext-input:focus {\n outline: none;\n border-color: var(--ml-ui-accent, #409eff);\n}\n.ml-pdftext-number {\n width: 72px;\n}\n.ml-pdftext-size {\n display: flex;\n flex-direction: column;\n gap: 4px;\n}\n.ml-pdftext-size .ml-pdftext-field {\n grid-template-columns: 92px auto 1fr;\n}\n.ml-pdftext-hint {\n color: var(--ml-ui-text-muted, #606266);\n}\n.ml-pdftext-warning {\n color: var(--ml-ui-danger, #f56c6c);\n}\n.ml-pdftext-naming {\n display: flex;\n flex-direction: column;\n gap: 4px;\n}\n.ml-pdftext-naming-row {\n display: flex;\n gap: 4px;\n}\n.ml-pdftext-naming-row .ml-pdftext-input {\n flex: 1;\n}\n.ml-pdftext-check {\n display: inline-flex;\n align-items: center;\n gap: 4px;\n cursor: pointer;\n}\n.ml-pdftext-lines {\n flex: 1;\n min-height: 80px;\n overflow: auto;\n display: flex;\n flex-direction: column;\n gap: 2px;\n}\n.ml-pdftext-toolbar {\n display: flex;\n flex-wrap: wrap;\n align-items: center;\n gap: 4px;\n}\n.ml-pdftext-toolbar .ml-pdftext-btn {\n min-width: 0;\n padding: 2px 8px;\n}\n.ml-pdftext-row {\n display: grid;\n grid-template-columns: auto 1fr auto auto;\n align-items: center;\n gap: 4px;\n padding: 2px 4px;\n border-radius: 4px;\n border-left: 3px solid transparent;\n}\n.ml-pdftext-row.is-selected {\n background: var(--ml-ui-canvas-fill, rgba(64, 158, 255, 0.2));\n}\ntextarea.ml-pdftext-text {\n resize: vertical;\n min-height: 2.6em;\n}\n.ml-pdftext-tags {\n display: inline-flex;\n flex-direction: column;\n align-items: flex-end;\n gap: 1px;\n}\n.ml-pdftext-mtext {\n font-size: 10px;\n padding: 0 4px;\n border-radius: 3px;\n color: #fff;\n background: var(--ml-ui-accent, #409eff);\n white-space: nowrap;\n}\n.ml-pdftext-row[data-source='unread'] {\n border-left-color: var(--ml-ui-danger, #f56c6c);\n}\n.ml-pdftext-row.is-skipped .ml-pdftext-text {\n opacity: 0.55;\n}\n.ml-pdftext-badge {\n color: var(--ml-ui-text-muted, #606266);\n font-size: 11px;\n white-space: nowrap;\n}\n.ml-pdftext-kind {\n border: 1px solid var(--ml-ui-border, #dcdfe6);\n border-radius: 4px;\n background: transparent;\n color: inherit;\n font-size: 11px;\n padding: 1px 5px;\n cursor: pointer;\n white-space: nowrap;\n}\n.ml-pdftext-footer {\n display: flex;\n align-items: center;\n flex-wrap: wrap;\n gap: 8px;\n padding-top: 6px;\n border-top: 1px solid var(--ml-ui-border, #dcdfe6);\n}\n.ml-pdftext-counter {\n flex: 1;\n color: var(--ml-ui-text-muted, #606266);\n}\n.ml-pdftext-buttons {\n display: flex;\n gap: 6px;\n}\n.ml-pdftext-btn {\n min-width: 64px;\n padding: 4px 12px;\n border-radius: 4px;\n border: 1px solid var(--ml-ui-accent, #409eff);\n background: var(--ml-ui-accent, #409eff);\n color: #fff;\n cursor: pointer;\n font: inherit;\n}\n.ml-pdftext-btn.is-secondary {\n border-color: var(--ml-ui-border, #dcdfe6);\n background: transparent;\n color: inherit;\n}\n.ml-pdftext-btn:disabled {\n opacity: 0.5;\n cursor: default;\n}\n".trim();
|
|
767
|
+
var style = document.getElementById(STYLE_ID);
|
|
768
|
+
if (!style) {
|
|
769
|
+
style = document.createElement('style');
|
|
770
|
+
style.id = STYLE_ID;
|
|
771
|
+
document.head.appendChild(style);
|
|
772
|
+
}
|
|
773
|
+
style.textContent = css;
|
|
774
|
+
}
|
|
775
|
+
//# sourceMappingURL=AcUiPdfTextPanel.js.map
|