layoutbridge-light 0.0.0-stage → 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 +22 -0
- package/LICENSE +26 -0
- package/README.de.md +338 -0
- package/README.md +325 -2
- package/THIRD-PARTY-NOTICES.md +2878 -0
- package/dist/src/mcp/catalog.js +126 -0
- package/dist/src/mcp/config.js +211 -0
- package/dist/src/mcp/dispatch.js +164 -0
- package/dist/src/mcp/epub-check.js +331 -0
- package/dist/src/mcp/epub-orientation.js +132 -0
- package/dist/src/mcp/license/free-tools.js +16 -0
- package/dist/src/mcp/license/gate.js +210 -0
- package/dist/src/mcp/license/index.js +107 -0
- package/dist/src/mcp/license/instance-name.js +57 -0
- package/dist/src/mcp/license/key-source.js +59 -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 +100 -0
- package/dist/src/mcp/license/polar-verifier.js +285 -0
- package/dist/src/mcp/license/product-ids.js +73 -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 +271 -0
- package/dist/src/mcp/product-info.js +54 -0
- package/dist/src/mcp/product.js +56 -0
- package/dist/src/mcp/server.js +253 -0
- package/dist/src/mcp/setup.js +680 -0
- package/dist/src/mcp/start.cjs +117 -0
- package/dist/src/mcp/tool-definition.js +2 -0
- package/dist/src/mcp/tools.js +2425 -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 +517 -0
- package/indesign/commands/22-document-setup.js +204 -0
- package/indesign/commands/23-save-package.js +258 -0
- package/indesign/commands/25-export.js +448 -0
- package/indesign/commands/26-export-image.js +202 -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 +837 -0
- package/indesign/commands/40-frames.js +851 -0
- package/indesign/commands/41-shapes.js +505 -0
- package/indesign/commands/42-groups.js +117 -0
- package/indesign/commands/43-layers.js +310 -0
- package/indesign/commands/44-effects.js +274 -0
- package/indesign/commands/45-frame-options.js +247 -0
- package/indesign/commands/47-anchored.js +331 -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 +1128 -0
- package/indesign/commands/62-embed.js +120 -0
- package/indesign/commands/69-placeholders.js +127 -0
- package/indesign/commands/70-text.js +675 -0
- package/indesign/commands/71-outlines.js +92 -0
- package/indesign/commands/72-place-text.js +476 -0
- package/indesign/commands/73-story-lock.js +157 -0
- package/indesign/commands/74-stories.js +121 -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 +452 -0
- package/indesign/commands/79-check-typography.js +341 -0
- package/indesign/commands/80-styles.js +1865 -0
- package/indesign/commands/81-composition.js +355 -0
- package/indesign/commands/82-object-styles.js +263 -0
- package/indesign/commands/83-drop-caps.js +87 -0
- package/indesign/commands/83-indents-tabs.js +264 -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 +212 -0
- package/indesign/commands/89-toc-index.js +945 -0
- package/indesign/commands/90-print-on-demand.js +495 -0
- package/indesign/commands/91-epub.js +546 -0
- package/indesign/interpreter.js +779 -0
- package/package.json +41 -4
- package/rules/typography-rules.json +31 -0
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
/* Wunschliste J2 Nr. 22 (Sitzung 8) – Textvariablen: list_text_variables, create_text_variable, insert_text_variable. */
|
|
2
|
+
|
|
3
|
+
var IDC_VARIABLE_TYPES = [
|
|
4
|
+
['custom_text', 'CUSTOM_TEXT_TYPE'],
|
|
5
|
+
['running_header_paragraph', 'MATCH_PARAGRAPH_STYLE_TYPE'],
|
|
6
|
+
['running_header_character', 'MATCH_CHARACTER_STYLE_TYPE'],
|
|
7
|
+
['file_name', 'FILE_NAME_TYPE'],
|
|
8
|
+
['output_date', 'OUTPUT_DATE_TYPE'],
|
|
9
|
+
['creation_date', 'CREATION_DATE_TYPE'],
|
|
10
|
+
['modification_date', 'MODIFICATION_DATE_TYPE'],
|
|
11
|
+
['last_page_number', 'LAST_PAGE_NUMBER_TYPE'],
|
|
12
|
+
['chapter_number', 'CHAPTER_NUMBER_TYPE']
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
function idcVariableTypesEnum() {
|
|
16
|
+
return typeof VariableTypes === 'undefined' ? null : VariableTypes;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function idcVariableTypeName(value) {
|
|
20
|
+
var i, enumObject = idcVariableTypesEnum();
|
|
21
|
+
if (value === undefined || value === null) { return null; }
|
|
22
|
+
if (enumObject === null) { return String(value); }
|
|
23
|
+
for (i = 0; i < IDC_VARIABLE_TYPES.length; i++) {
|
|
24
|
+
try { if (IDC.enumIs(value, enumObject[IDC_VARIABLE_TYPES[i][1]])) { return IDC_VARIABLE_TYPES[i][0]; } } catch (e) { /* naechster */ }
|
|
25
|
+
}
|
|
26
|
+
return String(value);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function idcVariableTypeFor(name) {
|
|
30
|
+
var i, enumObject = idcVariableTypesEnum(), value = null;
|
|
31
|
+
for (i = 0; i < IDC_VARIABLE_TYPES.length; i++) {
|
|
32
|
+
if (IDC_VARIABLE_TYPES[i][0] === name) {
|
|
33
|
+
if (enumObject === null) { IDC.fail('invalid_state', 'This runtime has no VariableTypes enumeration.', null); }
|
|
34
|
+
try { value = enumObject[IDC_VARIABLE_TYPES[i][1]]; } catch (e) { value = null; }
|
|
35
|
+
if (value === null || value === undefined) { IDC.fail('invalid_state', 'This InDesign has no variable type ' + name + '.', { type: name }); }
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
IDC.fail('invalid_argument', 'type must be one of ' + idcTableNames(IDC_VARIABLE_TYPES).join(', ') + '.', { type: name });
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function idcSearchStrategyName(value) {
|
|
44
|
+
if (value === undefined || value === null || typeof SearchStrategies === 'undefined') { return null; }
|
|
45
|
+
if (IDC.enumIs(value, SearchStrategies.FIRST_ON_PAGE)) { return 'first'; }
|
|
46
|
+
if (IDC.enumIs(value, SearchStrategies.LAST_ON_PAGE)) { return 'last'; }
|
|
47
|
+
return String(value);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function idcTextVariableByName(doc, name) {
|
|
51
|
+
var i, variable;
|
|
52
|
+
try {
|
|
53
|
+
for (i = 0; i < doc.textVariables.length; i++) {
|
|
54
|
+
variable = doc.textVariables.item(i);
|
|
55
|
+
if (String(variable.name) === String(name)) { return variable; }
|
|
56
|
+
}
|
|
57
|
+
} catch (e) { /* keiner */ }
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function idcCountVariableInstances(doc, variable) {
|
|
62
|
+
var count = 0, i, j, story, instances, instance;
|
|
63
|
+
try {
|
|
64
|
+
for (i = 0; i < doc.stories.length; i++) {
|
|
65
|
+
story = doc.stories.item(i);
|
|
66
|
+
instances = story.textVariableInstances;
|
|
67
|
+
for (j = 0; j < instances.length; j++) {
|
|
68
|
+
instance = instances.item(j);
|
|
69
|
+
try { if (String(instance.associatedTextVariable.name) === String(variable.name)) { count += 1; } } catch (e0) { /* ohne */ }
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
} catch (e1) { return null; }
|
|
73
|
+
return count;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function idcDescribeTextVariable(doc, variable) {
|
|
77
|
+
var out = { name: null, type: null, options: {}, instance_count: null, built_in: false };
|
|
78
|
+
var options = null, type;
|
|
79
|
+
try { out.name = String(variable.name); } catch (e0) { /* null */ }
|
|
80
|
+
try { type = variable.variableType; out.type = idcVariableTypeName(type); } catch (e1) { out.type = null; }
|
|
81
|
+
try { options = variable.variableOptions; } catch (e2) { options = null; }
|
|
82
|
+
if (options !== null && options !== undefined) {
|
|
83
|
+
if (out.type === 'custom_text') {
|
|
84
|
+
try { out.options.text = String(options.contents); } catch (e3) { /* ohne */ }
|
|
85
|
+
} else if (out.type === 'running_header_paragraph' || out.type === 'running_header_character') {
|
|
86
|
+
if (out.type === 'running_header_paragraph') {
|
|
87
|
+
try { out.options.paragraph_style = String(options.appliedParagraphStyle.name); } catch (e4) { out.options.paragraph_style = null; }
|
|
88
|
+
} else {
|
|
89
|
+
try { out.options.character_style = String(options.appliedCharacterStyle.name); } catch (e5) { out.options.character_style = null; }
|
|
90
|
+
}
|
|
91
|
+
try { out.options.use = idcSearchStrategyName(options.searchStrategy); } catch (e6) { /* ohne */ }
|
|
92
|
+
try { out.options.text_before = String(options.textBefore); } catch (e7) { /* ohne */ }
|
|
93
|
+
try { out.options.text_after = String(options.textAfter); } catch (e8) { /* ohne */ }
|
|
94
|
+
try { out.options.delete_end_punctuation = options.deleteEndPunctuation === true; } catch (e9) { /* ohne */ }
|
|
95
|
+
} else if (out.type === 'file_name') {
|
|
96
|
+
try { out.options.include_extension = options.includeExtension === true; } catch (e10) { /* ohne */ }
|
|
97
|
+
try { out.options.include_path = options.includePath === true; } catch (e11) { /* ohne */ }
|
|
98
|
+
try { out.options.text_before = String(options.textBefore); } catch (e12) { /* ohne */ }
|
|
99
|
+
try { out.options.text_after = String(options.textAfter); } catch (e13) { /* ohne */ }
|
|
100
|
+
} else if (out.type === 'output_date' || out.type === 'creation_date' || out.type === 'modification_date') {
|
|
101
|
+
try { out.options.format = String(options.format); } catch (e14) { /* ohne */ }
|
|
102
|
+
try { out.options.text_before = String(options.textBefore); } catch (e15) { /* ohne */ }
|
|
103
|
+
try { out.options.text_after = String(options.textAfter); } catch (e16) { /* ohne */ }
|
|
104
|
+
} else {
|
|
105
|
+
try { out.options.text_before = String(options.textBefore); } catch (e17) { /* ohne */ }
|
|
106
|
+
try { out.options.text_after = String(options.textAfter); } catch (e18) { /* ohne */ }
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
out.instance_count = idcCountVariableInstances(doc, variable);
|
|
110
|
+
return out;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/* Optionen einer Variablen aus den Werkzeugparametern schreiben. */
|
|
114
|
+
function idcApplyVariableOptions(ctx, doc, variable, type, args) {
|
|
115
|
+
var options = null, style, strategy;
|
|
116
|
+
try { options = variable.variableOptions; } catch (e0) { options = null; }
|
|
117
|
+
if (options === null || options === undefined) {
|
|
118
|
+
ctx.warn('InDesign exposes no options for this variable; nothing written.');
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
try {
|
|
122
|
+
if (type === 'custom_text') {
|
|
123
|
+
if (args.text === undefined || args.text === null) { IDC.fail('invalid_argument', 'custom_text needs text.', null); }
|
|
124
|
+
options.contents = idcNormaliseText(String(args.text));
|
|
125
|
+
} else if (type === 'running_header_paragraph' || type === 'running_header_character') {
|
|
126
|
+
if (type === 'running_header_paragraph') {
|
|
127
|
+
if (args.paragraph_style === undefined || args.paragraph_style === null) { IDC.fail('invalid_argument', 'running_header_paragraph needs paragraph_style.', null); }
|
|
128
|
+
style = idcParagraphStyleArg(doc, args.paragraph_style, 'paragraph_style');
|
|
129
|
+
options.appliedParagraphStyle = style;
|
|
130
|
+
} else {
|
|
131
|
+
if (typeof args.character_style !== 'string' || args.character_style === '') { IDC.fail('invalid_argument', 'running_header_character needs character_style.', null); }
|
|
132
|
+
style = idcCharacterStyleByName(doc, args.character_style);
|
|
133
|
+
if (style === null) { IDC.fail('not_found', 'Character style "' + args.character_style + '" not found.', { character_style: args.character_style }); }
|
|
134
|
+
options.appliedCharacterStyle = style;
|
|
135
|
+
}
|
|
136
|
+
if (args.use !== undefined && args.use !== null) {
|
|
137
|
+
if (typeof SearchStrategies === 'undefined') { IDC.fail('invalid_state', 'This runtime has no SearchStrategies enumeration.', null); }
|
|
138
|
+
if (args.use === 'first') { strategy = SearchStrategies.FIRST_ON_PAGE; }
|
|
139
|
+
else if (args.use === 'last') { strategy = SearchStrategies.LAST_ON_PAGE; }
|
|
140
|
+
else { IDC.fail('invalid_argument', 'use must be first or last.', { use: args.use }); }
|
|
141
|
+
options.searchStrategy = strategy;
|
|
142
|
+
}
|
|
143
|
+
if (args.text_before !== undefined && args.text_before !== null) { options.textBefore = String(args.text_before); }
|
|
144
|
+
if (args.text_after !== undefined && args.text_after !== null) { options.textAfter = String(args.text_after); }
|
|
145
|
+
if (args.delete_end_punctuation !== undefined && args.delete_end_punctuation !== null) { options.deleteEndPunctuation = args.delete_end_punctuation === true; }
|
|
146
|
+
} else if (type === 'file_name') {
|
|
147
|
+
if (args.include_extension !== undefined && args.include_extension !== null) { options.includeExtension = args.include_extension === true; }
|
|
148
|
+
if (args.include_path !== undefined && args.include_path !== null) { options.includePath = args.include_path === true; }
|
|
149
|
+
if (args.text_before !== undefined && args.text_before !== null) { options.textBefore = String(args.text_before); }
|
|
150
|
+
if (args.text_after !== undefined && args.text_after !== null) { options.textAfter = String(args.text_after); }
|
|
151
|
+
} else {
|
|
152
|
+
if (args.date_format !== undefined && args.date_format !== null && (type === 'output_date' || type === 'creation_date' || type === 'modification_date')) { options.format = String(args.date_format); }
|
|
153
|
+
if (args.text_before !== undefined && args.text_before !== null) { options.textBefore = String(args.text_before); }
|
|
154
|
+
if (args.text_after !== undefined && args.text_after !== null) { options.textAfter = String(args.text_after); }
|
|
155
|
+
}
|
|
156
|
+
} catch (e1) {
|
|
157
|
+
if (e1 && e1.isIdcError) { throw e1; }
|
|
158
|
+
IDC.fail('script_error', 'InDesign could not set the variable options: ' + String(e1.message ? e1.message : e1), { name: String(variable.name) });
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
IDC.register('list_text_variables', { needs_document: true, read_only: true, ruler: 'none' },
|
|
163
|
+
function (ctx) {
|
|
164
|
+
var doc = ctx.doc;
|
|
165
|
+
var out = [], i;
|
|
166
|
+
try {
|
|
167
|
+
for (i = 0; i < doc.textVariables.length; i++) { out.push(idcDescribeTextVariable(doc, doc.textVariables.item(i))); }
|
|
168
|
+
} catch (e) { /* leer */ }
|
|
169
|
+
return { variables: out, count: out.length };
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
IDC.register('create_text_variable', { needs_document: true, read_only: false, ruler: 'none' },
|
|
173
|
+
function (ctx) {
|
|
174
|
+
var args = ctx.args;
|
|
175
|
+
var doc = ctx.doc;
|
|
176
|
+
var name = args.name;
|
|
177
|
+
var existing, variable = null, created = false, typeValue, currentType, description, instances;
|
|
178
|
+
|
|
179
|
+
if (typeof name !== 'string' || name === '') { IDC.fail('invalid_argument', 'name is required.', null); }
|
|
180
|
+
existing = idcTextVariableByName(doc, name);
|
|
181
|
+
if (args.remove === true) {
|
|
182
|
+
if (existing === null) { IDC.fail('not_found', 'No text variable named "' + name + '".', { name: name }); }
|
|
183
|
+
instances = idcCountVariableInstances(doc, existing);
|
|
184
|
+
description = idcDescribeTextVariable(doc, existing);
|
|
185
|
+
try { existing.remove(); } catch (e0) {
|
|
186
|
+
IDC.fail('script_error', 'InDesign could not remove the variable "' + name + '": ' + String(e0.message ? e0.message : e0), { name: name });
|
|
187
|
+
}
|
|
188
|
+
if (instances !== null && instances > 0) { ctx.warn(instances + ' instance(s) of "' + name + '" in the text were removed with the variable.'); }
|
|
189
|
+
ctx.changes = { modified_document_ids: [Number(doc.id)] };
|
|
190
|
+
return { removed: true, variable: description };
|
|
191
|
+
}
|
|
192
|
+
if (typeof args.type !== 'string') { IDC.fail('invalid_argument', 'type is required.', null); }
|
|
193
|
+
typeValue = idcVariableTypeFor(args.type);
|
|
194
|
+
if (existing !== null) {
|
|
195
|
+
try { currentType = idcVariableTypeName(existing.variableType); } catch (e1) { currentType = null; }
|
|
196
|
+
if (currentType !== args.type) {
|
|
197
|
+
IDC.fail('invalid_state', 'A text variable named "' + name + '" exists with type ' + currentType + '; remove it first or choose another name.',
|
|
198
|
+
{ name: name, existing_type: currentType });
|
|
199
|
+
}
|
|
200
|
+
variable = existing;
|
|
201
|
+
} else {
|
|
202
|
+
try {
|
|
203
|
+
variable = doc.textVariables.add({ name: name, variableType: typeValue });
|
|
204
|
+
} catch (e2) {
|
|
205
|
+
IDC.fail('script_error', 'InDesign could not create the text variable "' + name + '": ' + String(e2.message ? e2.message : e2), { name: name });
|
|
206
|
+
}
|
|
207
|
+
created = true;
|
|
208
|
+
}
|
|
209
|
+
try {
|
|
210
|
+
idcApplyVariableOptions(ctx, doc, variable, args.type, args);
|
|
211
|
+
} catch (e3) {
|
|
212
|
+
/* Frisch angelegt und Optionen abgewiesen: nichts halb zuruecklassen. */
|
|
213
|
+
if (created) { try { variable.remove(); } catch (e4) { /* bleibt */ } }
|
|
214
|
+
throw e3;
|
|
215
|
+
}
|
|
216
|
+
description = idcDescribeTextVariable(doc, variable);
|
|
217
|
+
ctx.changes = { modified_document_ids: [Number(doc.id)] };
|
|
218
|
+
return { created: created, updated: !created, variable: description };
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
IDC.register('insert_text_variable', { needs_document: true, read_only: false, ruler: 'none' },
|
|
222
|
+
function (ctx) {
|
|
223
|
+
var args = ctx.args;
|
|
224
|
+
var doc = ctx.doc;
|
|
225
|
+
var found = idcTextFrameArg(doc, args, 'frame_id');
|
|
226
|
+
var story = idcStoryOf(found.item);
|
|
227
|
+
var variable, length = 0, index, insertionPoint, instance = null, resultText = null, description;
|
|
228
|
+
|
|
229
|
+
if (typeof args.name !== 'string' || args.name === '') { IDC.fail('invalid_argument', 'name is required (a text variable of the document).', null); }
|
|
230
|
+
variable = idcTextVariableByName(doc, args.name);
|
|
231
|
+
if (variable === null) { IDC.fail('not_found', 'No text variable named "' + args.name + '"; see list_text_variables.', { name: args.name }); }
|
|
232
|
+
try { length = Number(story.characters.length); } catch (e0) { length = 0; }
|
|
233
|
+
if (args.index === undefined || args.index === null) { index = length; }
|
|
234
|
+
else {
|
|
235
|
+
if (typeof args.index !== 'number' || Math.floor(args.index) !== args.index || args.index < 0 || args.index > length) {
|
|
236
|
+
IDC.fail('invalid_argument', 'index must be a whole number from 0 to the story length (' + length + ').', { index: args.index, story_length: length });
|
|
237
|
+
}
|
|
238
|
+
index = args.index;
|
|
239
|
+
}
|
|
240
|
+
try { insertionPoint = story.insertionPoints.item(index); } catch (e1) {
|
|
241
|
+
IDC.fail('script_error', 'InDesign could not address insertion point ' + index + '.', { index: index });
|
|
242
|
+
}
|
|
243
|
+
try {
|
|
244
|
+
instance = insertionPoint.textVariableInstances.add({ associatedTextVariable: variable });
|
|
245
|
+
} catch (e2) {
|
|
246
|
+
try {
|
|
247
|
+
instance = insertionPoint.textVariableInstances.add(LocationOptions.AT_END, undefined, { associatedTextVariable: variable });
|
|
248
|
+
} catch (e3) {
|
|
249
|
+
IDC.fail('script_error', 'InDesign could not insert the variable "' + args.name + '": ' + String(e3.message ? e3.message : e3), { name: args.name, index: index });
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
try { resultText = String(instance.resultText); } catch (e4) { resultText = null; }
|
|
253
|
+
description = { instance_id: null, name: args.name, story_id: Number(story.id), frame_id: Number(found.item.id), index: index, result_text: resultText, story_length: null };
|
|
254
|
+
try { description.instance_id = Number(instance.id); } catch (e5) { /* null */ }
|
|
255
|
+
try { description.story_length = Number(story.characters.length); } catch (e6) { /* null */ }
|
|
256
|
+
description.overset = idcOverflows(found.item);
|
|
257
|
+
if (description.overset === true) { ctx.warn('The story overflows after inserting the variable (Übersatz).'); }
|
|
258
|
+
ctx.changes = { modified_frame_ids: [Number(found.item.id)] };
|
|
259
|
+
return description;
|
|
260
|
+
});
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Auftrag A-7.4 (Sitzung 9) – set_story_options: storyweite Einstellungen,
|
|
3
|
+
* zuerst der optische Randausgleich (haengende Interpunktion).
|
|
4
|
+
* Adobe-DOM (StoryPreference, geprueft 05.09.2026):
|
|
5
|
+
* opticalMarginAlignment (Bool), opticalMarginSize (Punkt, 0.1–1296).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
function idcStoryPreferences(story) {
|
|
9
|
+
var prefs = null;
|
|
10
|
+
try { prefs = story.storyPreferences; } catch (e) { prefs = null; }
|
|
11
|
+
if (prefs === null || prefs === undefined) {
|
|
12
|
+
IDC.fail('invalid_state', 'The story has no storyPreferences in this runtime.', null);
|
|
13
|
+
}
|
|
14
|
+
return prefs;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function idcReadStoryOptions(story) {
|
|
18
|
+
var prefs = null;
|
|
19
|
+
var out = { optical_margin_alignment: null, optical_margin_size_pt: null };
|
|
20
|
+
try { prefs = story.storyPreferences; } catch (e0) { prefs = null; }
|
|
21
|
+
if (prefs === null || prefs === undefined) { return out; }
|
|
22
|
+
try { out.optical_margin_alignment = prefs.opticalMarginAlignment === true; } catch (e1) { /* null */ }
|
|
23
|
+
try {
|
|
24
|
+
out.optical_margin_size_pt = IDC.inPoints(function () { return IDC.round(Number(prefs.opticalMarginSize), 3); });
|
|
25
|
+
} catch (e2) { /* null */ }
|
|
26
|
+
return out;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function idcStoryFrameIds(story) {
|
|
30
|
+
var ids = [], containers, i;
|
|
31
|
+
try { containers = story.textContainers; } catch (e0) { return ids; }
|
|
32
|
+
for (i = 0; i < containers.length; i++) {
|
|
33
|
+
try { ids.push(Number(containers[i].id)); } catch (e1) { /* auslassen */ }
|
|
34
|
+
}
|
|
35
|
+
return ids;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
IDC.register('set_story_options', { needs_document: true, read_only: false, ruler: 'none' },
|
|
39
|
+
function (ctx) {
|
|
40
|
+
var args = ctx.args;
|
|
41
|
+
var doc = ctx.doc;
|
|
42
|
+
var found = idcTextFrameArg(doc, args, 'frame_id');
|
|
43
|
+
var frame = found.item;
|
|
44
|
+
var story = idcStoryOf(frame);
|
|
45
|
+
var changed = [];
|
|
46
|
+
var prefs, overset = null, before, after;
|
|
47
|
+
|
|
48
|
+
if (idcGiven(args.optical_margin_alignment) && typeof args.optical_margin_alignment !== 'boolean') {
|
|
49
|
+
IDC.fail('invalid_argument', 'optical_margin_alignment must be true or false.', { value: args.optical_margin_alignment });
|
|
50
|
+
}
|
|
51
|
+
if (idcGiven(args.optical_margin_size_pt)) {
|
|
52
|
+
idcNumberArg(args.optical_margin_size_pt, 'optical_margin_size_pt', 0.1, 1296);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
before = idcReadStoryOptions(story);
|
|
56
|
+
if (idcGiven(args.optical_margin_alignment) || idcGiven(args.optical_margin_size_pt)) {
|
|
57
|
+
prefs = idcStoryPreferences(story);
|
|
58
|
+
try {
|
|
59
|
+
if (idcGiven(args.optical_margin_alignment)) {
|
|
60
|
+
prefs.opticalMarginAlignment = args.optical_margin_alignment;
|
|
61
|
+
changed.push('optical_margin_alignment');
|
|
62
|
+
}
|
|
63
|
+
if (idcGiven(args.optical_margin_size_pt)) {
|
|
64
|
+
IDC.inPoints(function () { prefs.opticalMarginSize = args.optical_margin_size_pt; });
|
|
65
|
+
changed.push('optical_margin_size_pt');
|
|
66
|
+
}
|
|
67
|
+
} catch (e) {
|
|
68
|
+
IDC.fail('script_error', 'InDesign could not set the story options: ' + String(e.message ? e.message : e), { frame_id: args.frame_id });
|
|
69
|
+
}
|
|
70
|
+
ctx.changes = { modified_story_ids: [Number(story.id)] };
|
|
71
|
+
}
|
|
72
|
+
after = idcReadStoryOptions(story);
|
|
73
|
+
try { overset = story.overflows === true; } catch (e2) { overset = null; }
|
|
74
|
+
if (changed.length > 0 && overset === true) {
|
|
75
|
+
ctx.warn('The story overflows after the change – optical margin alignment recomposes every line.');
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
story_id: Number(story.id),
|
|
79
|
+
frame_ids: idcStoryFrameIds(story),
|
|
80
|
+
optical_margin_alignment: after.optical_margin_alignment,
|
|
81
|
+
optical_margin_size_pt: after.optical_margin_size_pt,
|
|
82
|
+
previous: before,
|
|
83
|
+
changed: changed,
|
|
84
|
+
overset: overset
|
|
85
|
+
};
|
|
86
|
+
});
|