layoutbridge-spm 0.0.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/CHANGELOG.md +171 -0
  2. package/LICENSE +26 -0
  3. package/README.de.md +318 -0
  4. package/README.md +304 -4
  5. package/THIRD-PARTY-NOTICES.md +2878 -0
  6. package/dist/src/mcp/config.js +125 -0
  7. package/dist/src/mcp/dispatch.js +123 -0
  8. package/dist/src/mcp/license/free-tools.js +16 -0
  9. package/dist/src/mcp/license/gate.js +209 -0
  10. package/dist/src/mcp/license/index.js +96 -0
  11. package/dist/src/mcp/license/instance-name.js +56 -0
  12. package/dist/src/mcp/license/key-source.js +58 -0
  13. package/dist/src/mcp/license/lemonsqueezy-verifier.js +207 -0
  14. package/dist/src/mcp/license/placeholder-verifier.js +10 -0
  15. package/dist/src/mcp/license/polar-ids.js +63 -0
  16. package/dist/src/mcp/license/polar-verifier.js +265 -0
  17. package/dist/src/mcp/license/product-ids.js +72 -0
  18. package/dist/src/mcp/license/state-store.js +91 -0
  19. package/dist/src/mcp/license/types.js +11 -0
  20. package/dist/src/mcp/logging.js +270 -0
  21. package/dist/src/mcp/product-info.js +48 -0
  22. package/dist/src/mcp/server.js +250 -0
  23. package/dist/src/mcp/setup.js +608 -0
  24. package/dist/src/mcp/start.cjs +95 -0
  25. package/dist/src/mcp/tool-definition.js +2 -0
  26. package/dist/src/mcp/tools.js +2004 -0
  27. package/dist/src/mcp/typography-rules.js +70 -0
  28. package/dist/src/transport/com.js +250 -0
  29. package/dist/src/transport/osascript.js +171 -0
  30. package/dist/src/transport/queue.js +19 -0
  31. package/dist/src/transport/script-bundle.js +92 -0
  32. package/dist/src/transport/transport.js +30 -0
  33. package/indesign/commands/10-app.js +6 -0
  34. package/indesign/commands/20-documents.js +513 -0
  35. package/indesign/commands/22-document-setup.js +118 -0
  36. package/indesign/commands/23-save-package.js +255 -0
  37. package/indesign/commands/25-export.js +379 -0
  38. package/indesign/commands/26-export-image.js +197 -0
  39. package/indesign/commands/27-textdefaults.js +151 -0
  40. package/indesign/commands/28-selection.js +174 -0
  41. package/indesign/commands/30-pages.js +1032 -0
  42. package/indesign/commands/31-view.js +210 -0
  43. package/indesign/commands/32-sections.js +203 -0
  44. package/indesign/commands/35-parents.js +428 -0
  45. package/indesign/commands/37-layout.js +760 -0
  46. package/indesign/commands/40-frames.js +836 -0
  47. package/indesign/commands/41-shapes.js +505 -0
  48. package/indesign/commands/42-groups.js +117 -0
  49. package/indesign/commands/43-layers.js +291 -0
  50. package/indesign/commands/44-effects.js +274 -0
  51. package/indesign/commands/45-frame-options.js +247 -0
  52. package/indesign/commands/47-anchored.js +287 -0
  53. package/indesign/commands/50-modify.js +781 -0
  54. package/indesign/commands/52-align.js +139 -0
  55. package/indesign/commands/55-fit.js +106 -0
  56. package/indesign/commands/60-images.js +771 -0
  57. package/indesign/commands/62-embed.js +120 -0
  58. package/indesign/commands/69-placeholders.js +127 -0
  59. package/indesign/commands/70-text.js +567 -0
  60. package/indesign/commands/71-outlines.js +92 -0
  61. package/indesign/commands/72-place-text.js +366 -0
  62. package/indesign/commands/74-stories.js +116 -0
  63. package/indesign/commands/75-tables.js +676 -0
  64. package/indesign/commands/76-text-variables.js +260 -0
  65. package/indesign/commands/77-story-options.js +86 -0
  66. package/indesign/commands/78-frame-lines.js +304 -0
  67. package/indesign/commands/79-check-typography.js +303 -0
  68. package/indesign/commands/80-styles.js +1620 -0
  69. package/indesign/commands/81-composition.js +355 -0
  70. package/indesign/commands/82-object-styles.js +263 -0
  71. package/indesign/commands/83-indents-tabs.js +237 -0
  72. package/indesign/commands/84-import-styles.js +142 -0
  73. package/indesign/commands/85-swatches.js +112 -0
  74. package/indesign/commands/86-gradients.js +185 -0
  75. package/indesign/commands/87-replace-swatch.js +180 -0
  76. package/indesign/commands/88-replace-font.js +217 -0
  77. package/indesign/interpreter.js +758 -0
  78. package/package.json +55 -6
  79. package/rules/typography-rules.json +31 -0
@@ -0,0 +1,210 @@
1
+ /*
2
+ * Sitzung 10 (Demo-Heft-Befund 1, 05.09.2026) – Ansicht steuern.
3
+ *
4
+ * show_page stellt das Layoutfenster eines Dokuments auf eine Seite oder
5
+ * Musterseite und passt sie ein; die Helfer idcCaptureView/idcRestoreView
6
+ * merken die Ansicht vor einem Eingriff und stellen sie danach wieder her
7
+ * (keep_view in create_parent_page, add_page und place_text_file mit
8
+ * autoflow – InDesign springt beim Anlegen von Muster- und Dokumentseiten
9
+ * ungefragt dorthin).
10
+ *
11
+ * Adobe-DOM (geprueft 05.09.2026): LayoutWindow.activePage (Page),
12
+ * LayoutWindow.activeSpread (Spread oder MasterSpread), zoomPercentage
13
+ * (5 bis 4000), zoom(ZoomOptions) mit FIT_PAGE, FIT_SPREAD, SHOW_PASTEBOARD,
14
+ * ACTUAL_SIZE; Window.bringToFront(); Application.activeWindow;
15
+ * Document.layoutWindows. Ein mit show_window false geoeffnetes Dokument hat
16
+ * kein Layoutfenster.
17
+ */
18
+
19
+ /* Layoutfenster eines Dokuments: das aktive, wenn es dazugehoert, sonst das erste; null ohne Fenster. */
20
+ function idcLayoutWindowOf(doc) {
21
+ var win = null, wins = null, parent = null;
22
+ try {
23
+ win = app.activeWindow;
24
+ if (win && win.isValid === true && IDC.className(win) === 'LayoutWindow') {
25
+ try { parent = win.parent; } catch (e0) { parent = null; }
26
+ if (parent && Number(parent.id) === Number(doc.id)) { return win; }
27
+ }
28
+ } catch (e1) { /* kein aktives Fenster */ }
29
+ try { wins = doc.layoutWindows; } catch (e2) { wins = null; }
30
+ if (wins === null || wins === undefined) { return null; }
31
+ try {
32
+ if (wins.length > 0) { return wins.item(0); }
33
+ } catch (e3) { /* leer */ }
34
+ return null;
35
+ }
36
+
37
+ /* Liegt die Seite auf einem Musterbogen? */
38
+ function idcPageIsParent(page) {
39
+ var parent = null;
40
+ try { parent = page.parent; } catch (e) { return false; }
41
+ return IDC.className(parent) === 'MasterSpread';
42
+ }
43
+
44
+ /* Ansicht eines Fensters als Datensatz fuer die Antwort. */
45
+ function idcDescribeView(win) {
46
+ var out = { has_window: win !== null, active_page_id: null, active_page_name: null, active_spread_id: null, is_parent_page: null, zoom_percentage: null };
47
+ var page = null, spread = null;
48
+ if (win === null) { return out; }
49
+ try { page = win.activePage; } catch (e0) { page = null; }
50
+ if (page !== null && page !== undefined) {
51
+ try { out.active_page_id = Number(page.id); } catch (e1) { /* bleibt null */ }
52
+ try { out.active_page_name = String(page.name); } catch (e2) { /* bleibt null */ }
53
+ out.is_parent_page = idcPageIsParent(page);
54
+ }
55
+ try { spread = win.activeSpread; } catch (e3) { spread = null; }
56
+ if (spread !== null && spread !== undefined) {
57
+ try { out.active_spread_id = Number(spread.id); } catch (e4) { /* bleibt null */ }
58
+ }
59
+ try { out.zoom_percentage = IDC.round(Number(win.zoomPercentage), 2); } catch (e5) { /* bleibt null */ }
60
+ return out;
61
+ }
62
+
63
+ /* Ansicht merken (vor einem Eingriff, der die Ansicht verschiebt). */
64
+ function idcCaptureView(doc) {
65
+ var view = { window: idcLayoutWindowOf(doc), page: null, spread: null, zoom: null };
66
+ if (view.window === null) { return view; }
67
+ try { view.page = view.window.activePage; } catch (e0) { view.page = null; }
68
+ try { view.spread = view.window.activeSpread; } catch (e1) { view.spread = null; }
69
+ try { view.zoom = Number(view.window.zoomPercentage); } catch (e2) { view.zoom = null; }
70
+ return view;
71
+ }
72
+
73
+ /* Gemerkte Ansicht wiederherstellen. Liefert true, wenn Seite oder Bogen zurueckgestellt wurden. */
74
+ function idcRestoreView(view) {
75
+ var win, restored = false;
76
+ if (view === null || view === undefined || view.window === null) { return false; }
77
+ win = view.window;
78
+ try {
79
+ if (view.page !== null && view.page.isValid === true) { win.activePage = view.page; restored = true; }
80
+ } catch (e0) { restored = false; }
81
+ if (!restored) {
82
+ try {
83
+ if (view.spread !== null && view.spread.isValid === true) { win.activeSpread = view.spread; restored = true; }
84
+ } catch (e1) { restored = false; }
85
+ }
86
+ try {
87
+ if (view.zoom !== null && !isNaN(view.zoom) && view.zoom > 0) { win.zoomPercentage = view.zoom; }
88
+ } catch (e2) { /* Zoom bleibt */ }
89
+ return restored;
90
+ }
91
+
92
+ /* keep_view-Parameter lesen: Vorgabe true. */
93
+ function idcKeepViewArg(args) {
94
+ if (args.keep_view === undefined || args.keep_view === null) { return true; }
95
+ if (typeof args.keep_view !== 'boolean') {
96
+ IDC.fail('invalid_argument', 'keep_view must be true or false.', { keep_view: args.keep_view });
97
+ }
98
+ return args.keep_view;
99
+ }
100
+
101
+ /* Seite eines Dokuments ueber ihren Namen (die gedruckte Seitenzahl), sonst null. */
102
+ function idcDocumentPageByName(doc, name) {
103
+ var i, page, matches = [];
104
+ for (i = 0; i < doc.pages.length; i++) {
105
+ page = doc.pages.item(i);
106
+ try { if (String(page.name) === String(name)) { matches.push(page); } } catch (e) { /* weiter */ }
107
+ }
108
+ return matches;
109
+ }
110
+
111
+ /* -------------------------------------------------------------- show_page */
112
+
113
+ IDC.register('show_page', { needs_document: true, read_only: false, ruler: 'none' },
114
+ function (ctx) {
115
+ var args = ctx.args;
116
+ var doc = ctx.doc;
117
+ var hasId = args.page_id !== undefined && args.page_id !== null;
118
+ var hasName = args.page_name !== undefined && args.page_name !== null;
119
+ var fit = args.fit === undefined || args.fit === null ? 'page' : String(args.fit);
120
+ var zoom = args.zoom === undefined || args.zoom === null ? null : args.zoom;
121
+ var activate = args.activate === true;
122
+ var win, found, page, matches, isParent, before, spread, option, i, names;
123
+
124
+ if (hasId === hasName) {
125
+ IDC.fail('invalid_argument', 'Pass exactly one of page_id (from list_pages or list_parent_pages) and page_name (the printed page number).', null);
126
+ }
127
+ if (fit !== 'page' && fit !== 'spread' && fit !== 'pasteboard' && fit !== 'actual_size' && fit !== 'none') {
128
+ IDC.fail('invalid_argument', 'fit must be page (default), spread, pasteboard, actual_size or none.', { fit: fit });
129
+ }
130
+ if (zoom !== null) {
131
+ if (typeof zoom !== 'number' || isNaN(zoom) || zoom < 5 || zoom > 4000) {
132
+ IDC.fail('invalid_argument', 'zoom must be a percentage from 5 to 4000.', { zoom: zoom });
133
+ }
134
+ }
135
+
136
+ if (hasId) {
137
+ found = IDC.pageById(doc, args.page_id);
138
+ if (found === null) {
139
+ IDC.fail('not_found', 'No page with page_id ' + args.page_id + ' in this document.', { page_id: args.page_id });
140
+ }
141
+ page = found.page;
142
+ isParent = found.is_parent_page;
143
+ } else {
144
+ matches = idcDocumentPageByName(doc, args.page_name);
145
+ if (matches.length === 0) {
146
+ names = [];
147
+ for (i = 0; i < doc.pages.length; i++) { try { names.push(String(doc.pages.item(i).name)); } catch (e0) { /* weiter */ } }
148
+ IDC.fail('not_found', 'No document page named "' + args.page_name + '".', { page_name: String(args.page_name), available: names });
149
+ }
150
+ if (matches.length > 1) {
151
+ ctx.warn('Several pages are named "' + args.page_name + '" (sections restart the numbering); the first one is shown – use page_id to be exact.');
152
+ }
153
+ page = matches[0];
154
+ isParent = false;
155
+ }
156
+
157
+ win = idcLayoutWindowOf(doc);
158
+ if (win === null) {
159
+ IDC.fail('invalid_state', 'The document has no layout window (opened with show_window false, or InDesign shows no window for it) – nothing to show. Open it with a window to control the view.', null);
160
+ }
161
+ before = idcDescribeView(win);
162
+
163
+ try {
164
+ win.activePage = page;
165
+ } catch (e1) {
166
+ spread = null;
167
+ try { spread = page.parent; } catch (e2) { spread = null; }
168
+ try {
169
+ if (spread !== null) { win.activeSpread = spread; }
170
+ else { throw e1; }
171
+ } catch (e3) {
172
+ IDC.fail('script_error', 'InDesign could not show the page: ' + String(e3.message ? e3.message : e3), { page_id: Number(page.id) });
173
+ }
174
+ }
175
+
176
+ if (fit !== 'none') {
177
+ if (typeof ZoomOptions === 'undefined') {
178
+ IDC.fail('invalid_state', 'This runtime has no ZoomOptions enumeration – pass zoom instead of fit.', null);
179
+ }
180
+ option = ZoomOptions.FIT_PAGE;
181
+ if (fit === 'spread') { option = ZoomOptions.FIT_SPREAD; }
182
+ if (fit === 'pasteboard') { option = ZoomOptions.SHOW_PASTEBOARD; }
183
+ if (fit === 'actual_size') { option = ZoomOptions.ACTUAL_SIZE; }
184
+ try { win.zoom(option); } catch (e4) {
185
+ ctx.warn('The page is shown, but InDesign could not fit the view (' + fit + '): ' + String(e4.message ? e4.message : e4));
186
+ }
187
+ }
188
+ if (zoom !== null) {
189
+ try { win.zoomPercentage = zoom; } catch (e5) {
190
+ ctx.warn('The page is shown, but InDesign refused zoom ' + zoom + ': ' + String(e5.message ? e5.message : e5));
191
+ }
192
+ }
193
+ if (activate) {
194
+ try { win.bringToFront(); } catch (e6) {
195
+ try { app.activeWindow = win; } catch (e7) { ctx.warn('Could not bring the window to the front: ' + String(e7.message ? e7.message : e7)); }
196
+ }
197
+ }
198
+
199
+ var after = idcDescribeView(win);
200
+ return {
201
+ page_id: Number(page.id),
202
+ page_name: after.active_page_id === Number(page.id) ? after.active_page_name : String(page.name),
203
+ is_parent_page: isParent,
204
+ fit: fit,
205
+ zoom_percentage: after.zoom_percentage,
206
+ window_activated: activate,
207
+ view: after,
208
+ previous_view: { active_page_id: before.active_page_id, active_page_name: before.active_page_name, zoom_percentage: before.zoom_percentage }
209
+ };
210
+ });
@@ -0,0 +1,203 @@
1
+ /* Wunschliste J2 Nr. 20 (Sitzung 8) – Abschnitte und Seitennummerierung: list_sections, set_section. */
2
+
3
+ var IDC_PAGE_NUMBER_STYLES = [
4
+ ['arabic', 'ARABIC'], ['upper_roman', 'UPPER_ROMAN'], ['lower_roman', 'LOWER_ROMAN'],
5
+ ['upper_letters', 'UPPER_LETTERS'], ['lower_letters', 'LOWER_LETTERS']
6
+ ];
7
+
8
+ function idcPageNumberStyleEnum() {
9
+ return typeof PageNumberStyle === 'undefined' ? null : PageNumberStyle;
10
+ }
11
+
12
+ function idcPageNumberStyleName(value) {
13
+ var i, enumObject = idcPageNumberStyleEnum();
14
+ if (value === undefined || value === null) { return null; }
15
+ if (typeof value === 'string') { return value; }
16
+ if (enumObject === null) { return String(value); }
17
+ for (i = 0; i < IDC_PAGE_NUMBER_STYLES.length; i++) {
18
+ try { if (IDC.enumIs(value, enumObject[IDC_PAGE_NUMBER_STYLES[i][1]])) { return IDC_PAGE_NUMBER_STYLES[i][0]; } } catch (e) { /* naechster */ }
19
+ }
20
+ return String(value);
21
+ }
22
+
23
+ function idcPageNumberStyleFor(name) {
24
+ var i, enumObject = idcPageNumberStyleEnum(), value = null;
25
+ for (i = 0; i < IDC_PAGE_NUMBER_STYLES.length; i++) {
26
+ if (IDC_PAGE_NUMBER_STYLES[i][0] === name) {
27
+ if (enumObject === null) { IDC.fail('invalid_state', 'This runtime has no PageNumberStyle enumeration.', null); }
28
+ try { value = enumObject[IDC_PAGE_NUMBER_STYLES[i][1]]; } catch (e) { value = null; }
29
+ if (value === null || value === undefined) {
30
+ IDC.fail('invalid_state', 'This InDesign has no page number style ' + name + '.', { page_number_style: name });
31
+ }
32
+ return value;
33
+ }
34
+ }
35
+ IDC.fail('invalid_argument', 'page_number_style must be one of arabic, upper_roman, lower_roman, upper_letters, lower_letters.', { page_number_style: name });
36
+ return null;
37
+ }
38
+
39
+ function idcDescribeSection(doc, section) {
40
+ var out = {
41
+ section_id: null, name: null, start_page_id: null, start_page_name: '', start_page_index: null, length: null,
42
+ continue_numbering: null, page_number_start: null, page_number_style: null,
43
+ section_prefix: null, include_section_prefix: null, marker: null
44
+ };
45
+ var page = null;
46
+ try { out.section_id = Number(section.id); } catch (e0) { /* null */ }
47
+ try { out.name = String(section.name); } catch (e1) { /* null */ }
48
+ try { page = section.pageStart; } catch (e2) { page = null; }
49
+ if (page !== null && page !== undefined) {
50
+ try { out.start_page_id = Number(page.id); } catch (e3) { /* null */ }
51
+ try { out.start_page_name = String(page.name); } catch (e4) { /* leer */ }
52
+ try { out.start_page_index = Number(page.documentOffset); } catch (e5) { /* null */ }
53
+ }
54
+ try { out.length = Number(section.length); } catch (e6) { /* null */ }
55
+ out.continue_numbering = idcReadBool(section, 'continueNumbering');
56
+ try { out.page_number_start = Number(section.pageNumberStart); } catch (e7) { /* null */ }
57
+ try { out.page_number_style = idcPageNumberStyleName(section.pageNumberStyle); } catch (e8) { /* null */ }
58
+ try { out.section_prefix = String(section.sectionPrefix); } catch (e9) { /* null */ }
59
+ out.include_section_prefix = idcReadBool(section, 'includeSectionPrefix');
60
+ try { out.marker = String(section.marker); } catch (e10) { /* null */ }
61
+ return out;
62
+ }
63
+
64
+ function idcAllSections(doc) {
65
+ var out = [], i;
66
+ try {
67
+ for (i = 0; i < doc.sections.length; i++) { out.push(idcDescribeSection(doc, doc.sections.item(i))); }
68
+ } catch (e) { /* leer */ }
69
+ return out;
70
+ }
71
+
72
+ function idcPageNames(doc) {
73
+ var out = [], i, page;
74
+ try {
75
+ for (i = 0; i < doc.pages.length; i++) {
76
+ page = doc.pages.item(i);
77
+ out.push({ page_id: Number(page.id), name: String(page.name) });
78
+ }
79
+ } catch (e) { /* leer */ }
80
+ return out;
81
+ }
82
+
83
+ function idcSectionStartingAt(doc, pageId) {
84
+ var i, section, page;
85
+ try {
86
+ for (i = 0; i < doc.sections.length; i++) {
87
+ section = doc.sections.item(i);
88
+ page = section.pageStart;
89
+ if (page && Number(page.id) === Number(pageId)) { return section; }
90
+ }
91
+ } catch (e) { /* keiner */ }
92
+ return null;
93
+ }
94
+
95
+ IDC.register('list_sections', { needs_document: true, read_only: true, ruler: 'none' },
96
+ function (ctx) {
97
+ var doc = ctx.doc;
98
+ var sections = idcAllSections(doc);
99
+ return { sections: sections, count: sections.length, pages: idcPageNames(doc) };
100
+ });
101
+
102
+ IDC.register('set_section', { needs_document: true, read_only: false, ruler: 'none' },
103
+ function (ctx) {
104
+ var args = ctx.args;
105
+ var doc = ctx.doc;
106
+ var found, page, section, created = false, removed = false, given = 0, before, styleValue, description, i, wanted;
107
+ var fields = ['continue_numbering', 'page_number_start', 'page_number_style', 'section_prefix', 'include_section_prefix', 'marker', 'name'];
108
+
109
+ if (args.page_id === undefined || args.page_id === null) {
110
+ IDC.fail('invalid_argument', 'page_id is required (the page on which the section starts).', null);
111
+ }
112
+ found = IDC.pageById(doc, args.page_id);
113
+ if (found === null) {
114
+ IDC.fail('not_found', 'No page with page_id ' + args.page_id + ' in this document.', { page_id: args.page_id });
115
+ }
116
+ if (found.is_parent_page) {
117
+ IDC.fail('invalid_argument', 'Sections start on document pages, not on parent pages.', { page_id: args.page_id });
118
+ }
119
+ page = found.page;
120
+ for (i = 0; i < fields.length; i++) { if (args[fields[i]] !== undefined && args[fields[i]] !== null) { given += 1; } }
121
+ if (args.remove === true) {
122
+ if (given > 0) { IDC.fail('invalid_argument', 'remove true cannot be combined with other settings.', null); }
123
+ } else if (given === 0) {
124
+ IDC.fail('invalid_argument', 'Pass at least one of continue_numbering, page_number_start, page_number_style, section_prefix, include_section_prefix, marker, name – or remove true.', null);
125
+ }
126
+ if (args.page_number_start !== undefined && args.page_number_start !== null) {
127
+ if (typeof args.page_number_start !== 'number' || Math.floor(args.page_number_start) !== args.page_number_start || args.page_number_start < 1 || args.page_number_start > 999999) {
128
+ IDC.fail('invalid_argument', 'page_number_start must be a whole number of 1 or more.', { page_number_start: args.page_number_start });
129
+ }
130
+ if (args.continue_numbering === true) {
131
+ IDC.fail('invalid_argument', 'page_number_start and continue_numbering true contradict each other.', null);
132
+ }
133
+ }
134
+ if (args.section_prefix !== undefined && args.section_prefix !== null) {
135
+ if (typeof args.section_prefix !== 'string' || args.section_prefix.length > 8) {
136
+ IDC.fail('invalid_argument', 'section_prefix must be a string of at most 8 characters.', { section_prefix: args.section_prefix });
137
+ }
138
+ }
139
+ styleValue = null;
140
+ if (args.page_number_style !== undefined && args.page_number_style !== null) {
141
+ styleValue = idcPageNumberStyleFor(args.page_number_style);
142
+ }
143
+
144
+ section = idcSectionStartingAt(doc, args.page_id);
145
+ if (args.remove === true) {
146
+ if (section === null) {
147
+ IDC.fail('not_found', 'No section starts on page ' + args.page_id + '.', { page_id: args.page_id });
148
+ }
149
+ try { if (Number(page.documentOffset) === 0) { IDC.fail('invalid_state', 'The section on the first page cannot be removed.', { page_id: args.page_id }); } } catch (e0) { if (e0 && e0.isIdcError) { throw e0; } }
150
+ before = idcDescribeSection(doc, section);
151
+ try { section.remove(); } catch (e1) {
152
+ IDC.fail('script_error', 'InDesign could not remove the section: ' + String(e1.message ? e1.message : e1), { page_id: args.page_id });
153
+ }
154
+ removed = true;
155
+ ctx.changes = { modified_document_ids: [Number(doc.id)] };
156
+ return { removed: true, section: before, sections: idcAllSections(doc), pages: idcPageNames(doc) };
157
+ }
158
+
159
+ if (section === null) {
160
+ try { section = doc.sections.add(page); } catch (e2) {
161
+ IDC.fail('script_error', 'InDesign could not start a section on page ' + args.page_id + ': ' + String(e2.message ? e2.message : e2), { page_id: args.page_id });
162
+ }
163
+ created = true;
164
+ }
165
+ before = idcDescribeSection(doc, section);
166
+ try {
167
+ if (args.page_number_start !== undefined && args.page_number_start !== null) {
168
+ section.continueNumbering = false;
169
+ section.pageNumberStart = args.page_number_start;
170
+ }
171
+ if (args.continue_numbering !== undefined && args.continue_numbering !== null) {
172
+ if (args.continue_numbering !== true && args.continue_numbering !== false) { IDC.fail('invalid_argument', 'continue_numbering must be true or false.', null); }
173
+ section.continueNumbering = args.continue_numbering;
174
+ }
175
+ if (styleValue !== null) { section.pageNumberStyle = styleValue; }
176
+ if (args.section_prefix !== undefined && args.section_prefix !== null) { section.sectionPrefix = args.section_prefix; }
177
+ if (args.include_section_prefix !== undefined && args.include_section_prefix !== null) {
178
+ if (args.include_section_prefix !== true && args.include_section_prefix !== false) { IDC.fail('invalid_argument', 'include_section_prefix must be true or false.', null); }
179
+ section.includeSectionPrefix = args.include_section_prefix;
180
+ }
181
+ if (args.marker !== undefined && args.marker !== null) {
182
+ if (typeof args.marker !== 'string') { IDC.fail('invalid_argument', 'marker must be a string.', null); }
183
+ section.marker = args.marker;
184
+ }
185
+ if (args.name !== undefined && args.name !== null) {
186
+ if (typeof args.name !== 'string') { IDC.fail('invalid_argument', 'name must be a string.', null); }
187
+ section.name = args.name;
188
+ }
189
+ } catch (e3) {
190
+ if (e3 && e3.isIdcError) { throw e3; }
191
+ IDC.fail('script_error', 'InDesign could not change the section: ' + String(e3.message ? e3.message : e3), { page_id: args.page_id });
192
+ }
193
+ description = idcDescribeSection(doc, section);
194
+ for (i = 0; i < fields.length; i++) {
195
+ wanted = args[fields[i]];
196
+ if (wanted === undefined || wanted === null) { continue; }
197
+ if (fields[i] === 'page_number_start' && description.page_number_start !== wanted) { ctx.warn('InDesign reports page_number_start ' + description.page_number_start + '.'); }
198
+ if (fields[i] === 'page_number_style' && description.page_number_style !== wanted) { ctx.warn('InDesign reports page_number_style ' + description.page_number_style + '.'); }
199
+ }
200
+ if (created) { ctx.warn('A new section was started on page ' + description.start_page_name + '; page names after it may have changed – read list_pages again.'); }
201
+ ctx.changes = { modified_document_ids: [Number(doc.id)] };
202
+ return { created: created, removed: removed, section: description, previous: before, sections: idcAllSections(doc), pages: idcPageNames(doc) };
203
+ });