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.
- package/CHANGELOG.md +171 -0
- package/LICENSE +26 -0
- package/README.de.md +318 -0
- package/README.md +304 -4
- package/THIRD-PARTY-NOTICES.md +2878 -0
- package/dist/src/mcp/config.js +125 -0
- package/dist/src/mcp/dispatch.js +123 -0
- package/dist/src/mcp/license/free-tools.js +16 -0
- package/dist/src/mcp/license/gate.js +209 -0
- package/dist/src/mcp/license/index.js +96 -0
- package/dist/src/mcp/license/instance-name.js +56 -0
- package/dist/src/mcp/license/key-source.js +58 -0
- package/dist/src/mcp/license/lemonsqueezy-verifier.js +207 -0
- package/dist/src/mcp/license/placeholder-verifier.js +10 -0
- package/dist/src/mcp/license/polar-ids.js +63 -0
- package/dist/src/mcp/license/polar-verifier.js +265 -0
- package/dist/src/mcp/license/product-ids.js +72 -0
- package/dist/src/mcp/license/state-store.js +91 -0
- package/dist/src/mcp/license/types.js +11 -0
- package/dist/src/mcp/logging.js +270 -0
- package/dist/src/mcp/product-info.js +48 -0
- package/dist/src/mcp/server.js +250 -0
- package/dist/src/mcp/setup.js +608 -0
- package/dist/src/mcp/start.cjs +95 -0
- package/dist/src/mcp/tool-definition.js +2 -0
- package/dist/src/mcp/tools.js +2004 -0
- package/dist/src/mcp/typography-rules.js +70 -0
- package/dist/src/transport/com.js +250 -0
- package/dist/src/transport/osascript.js +171 -0
- package/dist/src/transport/queue.js +19 -0
- package/dist/src/transport/script-bundle.js +92 -0
- package/dist/src/transport/transport.js +30 -0
- package/indesign/commands/10-app.js +6 -0
- package/indesign/commands/20-documents.js +513 -0
- package/indesign/commands/22-document-setup.js +118 -0
- package/indesign/commands/23-save-package.js +255 -0
- package/indesign/commands/25-export.js +379 -0
- package/indesign/commands/26-export-image.js +197 -0
- package/indesign/commands/27-textdefaults.js +151 -0
- package/indesign/commands/28-selection.js +174 -0
- package/indesign/commands/30-pages.js +1032 -0
- package/indesign/commands/31-view.js +210 -0
- package/indesign/commands/32-sections.js +203 -0
- package/indesign/commands/35-parents.js +428 -0
- package/indesign/commands/37-layout.js +760 -0
- package/indesign/commands/40-frames.js +836 -0
- package/indesign/commands/41-shapes.js +505 -0
- package/indesign/commands/42-groups.js +117 -0
- package/indesign/commands/43-layers.js +291 -0
- package/indesign/commands/44-effects.js +274 -0
- package/indesign/commands/45-frame-options.js +247 -0
- package/indesign/commands/47-anchored.js +287 -0
- package/indesign/commands/50-modify.js +781 -0
- package/indesign/commands/52-align.js +139 -0
- package/indesign/commands/55-fit.js +106 -0
- package/indesign/commands/60-images.js +771 -0
- package/indesign/commands/62-embed.js +120 -0
- package/indesign/commands/69-placeholders.js +127 -0
- package/indesign/commands/70-text.js +567 -0
- package/indesign/commands/71-outlines.js +92 -0
- package/indesign/commands/72-place-text.js +366 -0
- package/indesign/commands/74-stories.js +116 -0
- package/indesign/commands/75-tables.js +676 -0
- package/indesign/commands/76-text-variables.js +260 -0
- package/indesign/commands/77-story-options.js +86 -0
- package/indesign/commands/78-frame-lines.js +304 -0
- package/indesign/commands/79-check-typography.js +303 -0
- package/indesign/commands/80-styles.js +1620 -0
- package/indesign/commands/81-composition.js +355 -0
- package/indesign/commands/82-object-styles.js +263 -0
- package/indesign/commands/83-indents-tabs.js +237 -0
- package/indesign/commands/84-import-styles.js +142 -0
- package/indesign/commands/85-swatches.js +112 -0
- package/indesign/commands/86-gradients.js +185 -0
- package/indesign/commands/87-replace-swatch.js +180 -0
- package/indesign/commands/88-replace-font.js +217 -0
- package/indesign/interpreter.js +758 -0
- package/package.json +55 -6
- package/rules/typography-rules.json +31 -0
|
@@ -0,0 +1,428 @@
|
|
|
1
|
+
/* Bereich B – Musterseiten (parent pages) und Seitenzahl-Platzhalter. */
|
|
2
|
+
|
|
3
|
+
/* ---------------------------------------------------- list_parent_pages */
|
|
4
|
+
|
|
5
|
+
function idcMasterSpreadByName(doc, name) {
|
|
6
|
+
var spread, i;
|
|
7
|
+
try {
|
|
8
|
+
spread = doc.masterSpreads.itemByName(String(name));
|
|
9
|
+
if (spread && spread.isValid === true) { return spread; }
|
|
10
|
+
} catch (e) { /* weiter */ }
|
|
11
|
+
for (i = 0; i < doc.masterSpreads.length; i++) {
|
|
12
|
+
spread = doc.masterSpreads.item(i);
|
|
13
|
+
if (String(spread.name) === String(name)) { return spread; }
|
|
14
|
+
}
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function idcMasterSpreadNames(doc) {
|
|
19
|
+
var names = [];
|
|
20
|
+
var i;
|
|
21
|
+
for (i = 0; i < doc.masterSpreads.length; i++) {
|
|
22
|
+
names.push(String(doc.masterSpreads.item(i).name));
|
|
23
|
+
}
|
|
24
|
+
return names;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/* ID des Musterbogens, der einer Seite zugewiesen ist, sonst null. */
|
|
28
|
+
function idcAppliedMasterId(page) {
|
|
29
|
+
var master;
|
|
30
|
+
try {
|
|
31
|
+
master = page.appliedMaster;
|
|
32
|
+
if (master && master.isValid === true) { return Number(master.id); }
|
|
33
|
+
} catch (e) { /* keine */ }
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
IDC.register('list_parent_pages', { needs_document: true, read_only: true, ruler: 'page' },
|
|
38
|
+
function (ctx) {
|
|
39
|
+
var doc = ctx.doc;
|
|
40
|
+
var parents = [];
|
|
41
|
+
var applied = {};
|
|
42
|
+
var i, j, page, masterId, spread, entry, mpage, key, itemCount;
|
|
43
|
+
|
|
44
|
+
for (i = 0; i < doc.pages.length; i++) {
|
|
45
|
+
page = doc.pages.item(i);
|
|
46
|
+
masterId = idcAppliedMasterId(page);
|
|
47
|
+
if (masterId !== null) {
|
|
48
|
+
key = String(masterId);
|
|
49
|
+
if (!IDC.hasOwn(applied, key)) { applied[key] = []; }
|
|
50
|
+
applied[key].push(Number(page.id));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
for (i = 0; i < doc.masterSpreads.length; i++) {
|
|
55
|
+
spread = doc.masterSpreads.item(i);
|
|
56
|
+
key = String(Number(spread.id));
|
|
57
|
+
entry = {
|
|
58
|
+
name: String(spread.name),
|
|
59
|
+
prefix: String(spread.namePrefix),
|
|
60
|
+
base_name: String(spread.baseName),
|
|
61
|
+
applied_to_page_ids: IDC.hasOwn(applied, key) ? applied[key] : [],
|
|
62
|
+
pages: []
|
|
63
|
+
};
|
|
64
|
+
for (j = 0; j < spread.pages.length; j++) {
|
|
65
|
+
mpage = spread.pages.item(j);
|
|
66
|
+
itemCount = 0;
|
|
67
|
+
try { itemCount = mpage.pageItems.length; } catch (e) { itemCount = 0; }
|
|
68
|
+
entry.pages.push({
|
|
69
|
+
page_id: Number(mpage.id),
|
|
70
|
+
index: j,
|
|
71
|
+
side: IDC.pageSide(mpage),
|
|
72
|
+
item_count: itemCount
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
parents.push(entry);
|
|
76
|
+
}
|
|
77
|
+
return { parent_pages: parents, count: parents.length };
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
/* --------------------------------------------------- create_parent_page */
|
|
81
|
+
|
|
82
|
+
/*
|
|
83
|
+
* Sitzung 24 (Befund aus dem Praxiseinsatz, E-79): Musterbogen, auf dem ein anderer
|
|
84
|
+
* beruht (based_on). Name mit Praefix oder "[None]"; null = nichts angegeben.
|
|
85
|
+
*/
|
|
86
|
+
function idcBasedOnArg(doc, name) {
|
|
87
|
+
var spread;
|
|
88
|
+
if (name === undefined || name === null) { return null; }
|
|
89
|
+
if (idcMeansNoParent(name)) { return { none: true, spread: null, name: '[None]' }; }
|
|
90
|
+
spread = idcMasterSpreadByName(doc, name);
|
|
91
|
+
if (spread === null) {
|
|
92
|
+
IDC.fail('not_found', 'No master page named "' + name + '" for based_on. Use the full name with prefix.',
|
|
93
|
+
{ based_on: String(name), available: idcMasterSpreadNames(doc) });
|
|
94
|
+
}
|
|
95
|
+
return { none: false, spread: spread, name: String(spread.name) };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/* Musterbogen auf basedOn gruenden; Fehler als Warnung (der Bogen ist dann schon angelegt). */
|
|
99
|
+
function idcApplyBasedOn(ctx, spread, basedOn) {
|
|
100
|
+
if (basedOn === null) { return; }
|
|
101
|
+
try {
|
|
102
|
+
if (basedOn.none) { spread.appliedMaster = NothingEnum.NOTHING; }
|
|
103
|
+
else { spread.appliedMaster = basedOn.spread; }
|
|
104
|
+
} catch (e) {
|
|
105
|
+
ctx.warn('The master page was created, but InDesign could not base it on "' + basedOn.name + '": ' + String(e.message ? e.message : e) +
|
|
106
|
+
' – use apply_parent_to_page with one of its page_ids.');
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/* Seitenzahl eines Musterbogens auf count bringen (am Ende anfuegen oder entfernen). */
|
|
111
|
+
function idcSetMasterPageCount(ctx, spread, count) {
|
|
112
|
+
try {
|
|
113
|
+
while (spread.pages.length < count) { spread.pages.add(LocationOptions.AT_END); }
|
|
114
|
+
while (spread.pages.length > count) { spread.pages.item(spread.pages.length - 1).remove(); }
|
|
115
|
+
} catch (e) {
|
|
116
|
+
ctx.warn('Could not bring the master to ' + count + ' page(s): ' + String(e.message ? e.message : e));
|
|
117
|
+
}
|
|
118
|
+
if (spread.pages.length !== count) {
|
|
119
|
+
ctx.warn('The master has ' + spread.pages.length + ' page(s), not the ' + count + ' requested.');
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/* Zahl der Objekte auf allen Seiten eines Musterbogens. */
|
|
124
|
+
function idcMasterItemCount(spread) {
|
|
125
|
+
var count = 0, i;
|
|
126
|
+
for (i = 0; i < spread.pages.length; i++) {
|
|
127
|
+
try { count += spread.pages.item(i).pageItems.length; } catch (e) { /* weiter */ }
|
|
128
|
+
}
|
|
129
|
+
return count;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
IDC.register('create_parent_page', { needs_document: true, read_only: false, ruler: 'page' },
|
|
133
|
+
function (ctx) {
|
|
134
|
+
var args = ctx.args;
|
|
135
|
+
var doc = ctx.doc;
|
|
136
|
+
var baseName, prefix, facing, docFacing, spread, i, pageIds, fullName, pageCount, basedOn;
|
|
137
|
+
/* Sitzung 10 (Demo-Heft-Befund 1): InDesign springt auf die neue Musterseite; Ansicht merken. */
|
|
138
|
+
var keepView = idcKeepViewArg(args);
|
|
139
|
+
var view = null, viewRestored = null;
|
|
140
|
+
|
|
141
|
+
if (typeof args.base_name !== 'string' || args.base_name.length < 1 || args.base_name.length > 60) {
|
|
142
|
+
IDC.fail('invalid_argument', 'base_name is required (1 to 60 characters).', null);
|
|
143
|
+
}
|
|
144
|
+
baseName = args.base_name;
|
|
145
|
+
prefix = args.name_prefix === undefined || args.name_prefix === null ? null : String(args.name_prefix);
|
|
146
|
+
if (prefix !== null && !/^[A-Z]$/.test(prefix)) {
|
|
147
|
+
IDC.fail('invalid_argument', 'name_prefix must be a single capital letter (A-Z).', { name_prefix: prefix });
|
|
148
|
+
}
|
|
149
|
+
docFacing = doc.documentPreferences.facingPages === true;
|
|
150
|
+
facing = args.facing === undefined || args.facing === null ? docFacing : args.facing === true;
|
|
151
|
+
pageCount = null;
|
|
152
|
+
if (args.page_count !== undefined && args.page_count !== null) {
|
|
153
|
+
pageCount = args.page_count;
|
|
154
|
+
if (typeof pageCount !== 'number' || Math.floor(pageCount) !== pageCount || pageCount < 1 || pageCount > 10) {
|
|
155
|
+
IDC.fail('invalid_argument', 'page_count must be a whole number from 1 to 10 (InDesign allows at most 10 pages per spread).', { page_count: pageCount });
|
|
156
|
+
}
|
|
157
|
+
if (args.facing !== undefined && args.facing !== null && ((args.facing === true && pageCount === 1) || (args.facing === false && pageCount > 1))) {
|
|
158
|
+
IDC.fail('invalid_argument', 'facing ' + String(args.facing) + ' contradicts page_count ' + pageCount + '; pass only page_count.',
|
|
159
|
+
{ facing: args.facing, page_count: pageCount });
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
basedOn = idcBasedOnArg(doc, args.based_on);
|
|
163
|
+
|
|
164
|
+
if (prefix !== null) {
|
|
165
|
+
fullName = prefix + '-' + baseName;
|
|
166
|
+
if (idcMasterSpreadByName(doc, fullName) !== null) {
|
|
167
|
+
IDC.fail('invalid_state', 'A master page named "' + fullName + '" exists already.',
|
|
168
|
+
{ name: fullName, available: idcMasterSpreadNames(doc) });
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (keepView) { view = idcCaptureView(doc); }
|
|
173
|
+
try {
|
|
174
|
+
/* page_count: MasterSpreads.add(pagesPerSpread) – gilt auch in einseitigen Dokumenten (Sitzung 24). */
|
|
175
|
+
spread = pageCount === null ? doc.masterSpreads.add() : doc.masterSpreads.add(pageCount);
|
|
176
|
+
spread.baseName = baseName;
|
|
177
|
+
if (prefix !== null) { spread.namePrefix = prefix; }
|
|
178
|
+
} catch (e) {
|
|
179
|
+
IDC.fail('script_error', 'InDesign could not create the master page: ' + String(e.message ? e.message : e),
|
|
180
|
+
{ base_name: baseName, name_prefix: prefix, page_count: pageCount });
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (pageCount !== null) {
|
|
184
|
+
idcSetMasterPageCount(ctx, spread, pageCount);
|
|
185
|
+
} else if (facing && !docFacing) {
|
|
186
|
+
ctx.warn('facing true requested, but the document has single pages; the master has one page. Pass page_count 2 for a two-page master.');
|
|
187
|
+
}
|
|
188
|
+
idcApplyBasedOn(ctx, spread, basedOn);
|
|
189
|
+
if (pageCount === null && !facing && spread.pages.length > 1) {
|
|
190
|
+
try {
|
|
191
|
+
while (spread.pages.length > 1) { spread.pages.item(spread.pages.length - 1).remove(); }
|
|
192
|
+
} catch (e2) {
|
|
193
|
+
ctx.warn('Could not reduce the master to a single page: ' + String(e2.message ? e2.message : e2));
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
pageIds = [];
|
|
198
|
+
for (i = 0; i < spread.pages.length; i++) { pageIds.push(Number(spread.pages.item(i).id)); }
|
|
199
|
+
|
|
200
|
+
if (view !== null) {
|
|
201
|
+
viewRestored = view.window === null ? null : idcRestoreView(view);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
ctx.changes = { created_parent_page_ids: pageIds };
|
|
205
|
+
return {
|
|
206
|
+
name: String(spread.name),
|
|
207
|
+
prefix: String(spread.namePrefix),
|
|
208
|
+
base_name: String(spread.baseName),
|
|
209
|
+
page_ids: pageIds,
|
|
210
|
+
facing: spread.pages.length > 1,
|
|
211
|
+
page_count: spread.pages.length,
|
|
212
|
+
based_on: idcAppliedParentName(spread),
|
|
213
|
+
view_restored: viewRestored
|
|
214
|
+
};
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
/* ------------------------------------------------ duplicate_parent_page */
|
|
218
|
+
|
|
219
|
+
/*
|
|
220
|
+
* Sitzung 24 (E-79): Musterbogen mit allen Seiten und Objekten kopieren
|
|
221
|
+
* (MasterSpread.duplicate), dann umbenennen. Ohne base_name bleibt der
|
|
222
|
+
* Grundname der Vorlage, ohne name_prefix vergibt InDesign das naechste
|
|
223
|
+
* freie Praefix.
|
|
224
|
+
*/
|
|
225
|
+
IDC.register('duplicate_parent_page', { needs_document: true, read_only: false, ruler: 'page' },
|
|
226
|
+
function (ctx) {
|
|
227
|
+
var args = ctx.args;
|
|
228
|
+
var doc = ctx.doc;
|
|
229
|
+
var source, baseName, prefix, fullName, copy, i, pageIds, sourceItems, copyItems;
|
|
230
|
+
var keepView = idcKeepViewArg(args);
|
|
231
|
+
var view = null, viewRestored = null;
|
|
232
|
+
|
|
233
|
+
if (typeof args.source_name !== 'string' || args.source_name.length < 1) {
|
|
234
|
+
IDC.fail('invalid_argument', 'source_name is required (full master name with prefix, e.g. "A-Grundlayout").', null);
|
|
235
|
+
}
|
|
236
|
+
source = idcMasterSpreadByName(doc, args.source_name);
|
|
237
|
+
if (source === null) {
|
|
238
|
+
IDC.fail('not_found', 'No master page named "' + args.source_name + '". Use the full name with prefix.',
|
|
239
|
+
{ source_name: String(args.source_name), available: idcMasterSpreadNames(doc) });
|
|
240
|
+
}
|
|
241
|
+
baseName = args.base_name === undefined || args.base_name === null ? String(source.baseName) : args.base_name;
|
|
242
|
+
if (typeof baseName !== 'string' || baseName.length < 1 || baseName.length > 60) {
|
|
243
|
+
IDC.fail('invalid_argument', 'base_name must have 1 to 60 characters.', null);
|
|
244
|
+
}
|
|
245
|
+
prefix = args.name_prefix === undefined || args.name_prefix === null ? null : String(args.name_prefix);
|
|
246
|
+
if (prefix !== null && !/^[A-Z]$/.test(prefix)) {
|
|
247
|
+
IDC.fail('invalid_argument', 'name_prefix must be a single capital letter (A-Z).', { name_prefix: prefix });
|
|
248
|
+
}
|
|
249
|
+
if (prefix !== null) {
|
|
250
|
+
fullName = prefix + '-' + baseName;
|
|
251
|
+
if (idcMasterSpreadByName(doc, fullName) !== null) {
|
|
252
|
+
IDC.fail('invalid_state', 'A master page named "' + fullName + '" exists already.',
|
|
253
|
+
{ name: fullName, available: idcMasterSpreadNames(doc) });
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
sourceItems = idcMasterItemCount(source);
|
|
257
|
+
|
|
258
|
+
if (keepView) { view = idcCaptureView(doc); }
|
|
259
|
+
try {
|
|
260
|
+
copy = source.duplicate();
|
|
261
|
+
if (IDC.isArray(copy)) { copy = copy[0]; }
|
|
262
|
+
} catch (e) {
|
|
263
|
+
IDC.fail('script_error', 'InDesign could not duplicate the master page "' + String(source.name) + '": ' + String(e.message ? e.message : e),
|
|
264
|
+
{ source_name: String(source.name) });
|
|
265
|
+
}
|
|
266
|
+
try {
|
|
267
|
+
copy.baseName = baseName;
|
|
268
|
+
if (prefix !== null) { copy.namePrefix = prefix; }
|
|
269
|
+
} catch (e2) {
|
|
270
|
+
ctx.warn('The master page was duplicated as "' + String(copy.name) + '", but could not be renamed: ' + String(e2.message ? e2.message : e2));
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
pageIds = [];
|
|
274
|
+
for (i = 0; i < copy.pages.length; i++) { pageIds.push(Number(copy.pages.item(i).id)); }
|
|
275
|
+
copyItems = idcMasterItemCount(copy);
|
|
276
|
+
if (copyItems !== sourceItems) {
|
|
277
|
+
ctx.warn('The copy holds ' + copyItems + ' object(s), the source ' + sourceItems + ' – check it with get_page_state.');
|
|
278
|
+
}
|
|
279
|
+
if (view !== null) {
|
|
280
|
+
viewRestored = view.window === null ? null : idcRestoreView(view);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
ctx.changes = { created_parent_page_ids: pageIds };
|
|
284
|
+
return {
|
|
285
|
+
name: String(copy.name),
|
|
286
|
+
prefix: String(copy.namePrefix),
|
|
287
|
+
base_name: String(copy.baseName),
|
|
288
|
+
page_ids: pageIds,
|
|
289
|
+
page_count: copy.pages.length,
|
|
290
|
+
source_name: String(source.name),
|
|
291
|
+
based_on: idcAppliedParentName(copy),
|
|
292
|
+
item_count: copyItems,
|
|
293
|
+
source_item_count: sourceItems,
|
|
294
|
+
view_restored: viewRestored
|
|
295
|
+
};
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
/* --------------------------------------------------- apply_parent_to_page */
|
|
299
|
+
|
|
300
|
+
function idcMeansNoParent(name) {
|
|
301
|
+
var text = String(name).toLowerCase();
|
|
302
|
+
return text === '[none]' || text === 'none' || text === 'ohne' || text === '[ohne]' || text === '';
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
IDC.register('apply_parent_to_page', { needs_document: true, read_only: false, ruler: 'page' },
|
|
306
|
+
function (ctx) {
|
|
307
|
+
var args = ctx.args;
|
|
308
|
+
var doc = ctx.doc;
|
|
309
|
+
var found, page, spread;
|
|
310
|
+
|
|
311
|
+
if (args.page_id === undefined || args.page_id === null) {
|
|
312
|
+
IDC.fail('invalid_argument', 'page_id is required.', null);
|
|
313
|
+
}
|
|
314
|
+
if (args.parent_name === undefined || args.parent_name === null) {
|
|
315
|
+
IDC.fail('invalid_argument', 'parent_name is required (full name such as "A-Grundlayout", or "[None]" to detach).', null);
|
|
316
|
+
}
|
|
317
|
+
found = IDC.pageById(doc, args.page_id);
|
|
318
|
+
if (found === null) {
|
|
319
|
+
IDC.fail('not_found', 'No page with page_id ' + args.page_id + ' in this document.', { page_id: args.page_id });
|
|
320
|
+
}
|
|
321
|
+
page = found.page;
|
|
322
|
+
|
|
323
|
+
try {
|
|
324
|
+
if (idcMeansNoParent(args.parent_name)) {
|
|
325
|
+
page.appliedMaster = NothingEnum.NOTHING;
|
|
326
|
+
} else {
|
|
327
|
+
spread = idcMasterSpreadByName(doc, args.parent_name);
|
|
328
|
+
if (spread === null) {
|
|
329
|
+
IDC.fail('not_found', 'No master page named "' + args.parent_name + '". Use the full name with prefix.',
|
|
330
|
+
{ parent_name: String(args.parent_name), available: idcMasterSpreadNames(doc) });
|
|
331
|
+
}
|
|
332
|
+
page.appliedMaster = spread;
|
|
333
|
+
}
|
|
334
|
+
} catch (e) {
|
|
335
|
+
if (e && e.isIdcError) { throw e; }
|
|
336
|
+
IDC.fail('script_error', 'InDesign could not apply the master page: ' + String(e.message ? e.message : e),
|
|
337
|
+
{ page_id: args.page_id, parent_name: String(args.parent_name) });
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
ctx.changes = { modified_page_ids: [Number(page.id)] };
|
|
341
|
+
return {
|
|
342
|
+
page_id: Number(page.id),
|
|
343
|
+
parent_applied: idcAppliedParentName(page)
|
|
344
|
+
};
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
/* ------------------------------------------- override_parent_item_on_page */
|
|
348
|
+
|
|
349
|
+
IDC.register('override_parent_item_on_page', { needs_document: true, read_only: false, ruler: 'page' },
|
|
350
|
+
function (ctx) {
|
|
351
|
+
var args = ctx.args;
|
|
352
|
+
var doc = ctx.doc;
|
|
353
|
+
var page, found, local;
|
|
354
|
+
|
|
355
|
+
page = idcDocumentPageById(doc, args.page_id, 'page_id');
|
|
356
|
+
if (args.parent_item_id === undefined || args.parent_item_id === null) {
|
|
357
|
+
IDC.fail('invalid_argument', 'parent_item_id is required.', null);
|
|
358
|
+
}
|
|
359
|
+
found = IDC.itemById(doc, args.parent_item_id, 'parent');
|
|
360
|
+
if (found === null) {
|
|
361
|
+
if (IDC.itemById(doc, args.parent_item_id, 'document') !== null) {
|
|
362
|
+
IDC.fail('invalid_state', 'Object ' + args.parent_item_id + ' lies on a document page, not on a master spread.',
|
|
363
|
+
{ parent_item_id: args.parent_item_id });
|
|
364
|
+
}
|
|
365
|
+
IDC.fail('not_found', 'No object with id ' + args.parent_item_id + ' on any master spread.',
|
|
366
|
+
{ parent_item_id: args.parent_item_id });
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
try {
|
|
370
|
+
local = found.item.override(page);
|
|
371
|
+
if (IDC.isArray(local)) { local = local[0]; }
|
|
372
|
+
local = IDC.concrete(local);
|
|
373
|
+
} catch (e) {
|
|
374
|
+
IDC.fail('invalid_state', 'InDesign could not override the master item on this page (is its master applied to the page, and does the item lie on the master page of the same side – left/right?): ' +
|
|
375
|
+
String(e.message ? e.message : e),
|
|
376
|
+
{ page_id: Number(page.id), parent_item_id: args.parent_item_id });
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
ctx.changes = { created_frame_ids: [Number(local.id)] };
|
|
380
|
+
return {
|
|
381
|
+
frame_id: Number(local.id),
|
|
382
|
+
page_id: Number(page.id),
|
|
383
|
+
parent_item_id: Number(args.parent_item_id),
|
|
384
|
+
type: IDC.itemType(local)
|
|
385
|
+
};
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
/* ------------------------------------------- insert_page_number_marker */
|
|
389
|
+
|
|
390
|
+
IDC.register('insert_page_number_marker', { needs_document: true, read_only: false, ruler: 'page' },
|
|
391
|
+
function (ctx) {
|
|
392
|
+
var args = ctx.args;
|
|
393
|
+
var doc = ctx.doc;
|
|
394
|
+
var found, frame, position, points, target;
|
|
395
|
+
|
|
396
|
+
if (args.frame_id === undefined || args.frame_id === null) {
|
|
397
|
+
IDC.fail('invalid_argument', 'frame_id is required.', null);
|
|
398
|
+
}
|
|
399
|
+
position = args.position === undefined || args.position === null ? 'end' : String(args.position);
|
|
400
|
+
if (position !== 'start' && position !== 'end') {
|
|
401
|
+
IDC.fail('invalid_argument', 'position must be "start" or "end".', { position: position });
|
|
402
|
+
}
|
|
403
|
+
found = IDC.itemById(doc, args.frame_id, 'any');
|
|
404
|
+
if (found === null) {
|
|
405
|
+
IDC.fail('not_found', 'No object with frame_id ' + args.frame_id + '.', { frame_id: args.frame_id });
|
|
406
|
+
}
|
|
407
|
+
frame = found.item;
|
|
408
|
+
if (!IDC.isTextFrame(frame)) {
|
|
409
|
+
IDC.fail('invalid_state', 'Object ' + args.frame_id + ' is not a text frame (' + IDC.className(frame) + ').',
|
|
410
|
+
{ frame_id: args.frame_id });
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
try {
|
|
414
|
+
points = frame.insertionPoints;
|
|
415
|
+
target = position === 'start' ? points.item(0) : points.item(points.length - 1);
|
|
416
|
+
target.contents = SpecialCharacters.AUTO_PAGE_NUMBER;
|
|
417
|
+
} catch (e) {
|
|
418
|
+
IDC.fail('script_error', 'InDesign could not insert the page number marker: ' + String(e.message ? e.message : e),
|
|
419
|
+
{ frame_id: args.frame_id });
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
ctx.changes = { modified_frame_ids: [Number(frame.id)] };
|
|
423
|
+
return {
|
|
424
|
+
frame_id: Number(frame.id),
|
|
425
|
+
position: position,
|
|
426
|
+
on_parent_page: found.on_parent
|
|
427
|
+
};
|
|
428
|
+
});
|