@mcpher/gas-fakes 2.5.1 → 2.5.3
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/README.md +8 -1
- package/package.json +1 -1
- package/pngs/srv.jpg +0 -0
- package/src/cli/app.js +1 -0
- package/src/cli/togas.js +23 -14
- package/src/index.js +1 -0
- package/src/services/advslides/fakeadvslides.js +11 -5
- package/src/services/base/app.js +9 -0
- package/src/services/base/fakebase.js +28 -0
- package/src/services/common/fakeadvresource.js +3 -2
- package/src/services/enums/baseenums.js +47 -0
- package/src/services/enums/slidesenums.js +3 -1
- package/src/services/html/serverworker.js +1 -1
- package/src/services/slidesapp/app.js +5 -0
- package/src/services/slidesapp/fakeautofit.js +1 -1
- package/src/services/slidesapp/fakeborder.js +106 -0
- package/src/services/slidesapp/fakecolorscheme.js +1 -1
- package/src/services/slidesapp/fakefill.js +216 -0
- package/src/services/slidesapp/fakegroup.js +35 -0
- package/src/services/slidesapp/fakeimage.js +118 -0
- package/src/services/slidesapp/fakelayout.js +351 -0
- package/src/services/slidesapp/fakeline.js +2 -2
- package/src/services/slidesapp/fakelinefill.js +15 -16
- package/src/services/slidesapp/fakelink.js +20 -3
- package/src/services/slidesapp/fakelist.js +36 -0
- package/src/services/slidesapp/fakeliststyle.js +105 -0
- package/src/services/slidesapp/fakemaster.js +358 -0
- package/src/services/slidesapp/fakenotesmaster.js +125 -0
- package/src/services/slidesapp/fakenotespage.js +102 -2
- package/src/services/slidesapp/fakepagebackground.js +109 -1
- package/src/services/slidesapp/fakepageelement.js +157 -18
- package/src/services/slidesapp/fakepageelementrange.js +28 -0
- package/src/services/slidesapp/fakepagerange.js +28 -0
- package/src/services/slidesapp/fakeparagraphstyle.js +139 -0
- package/src/services/slidesapp/fakepicturefill.js +32 -0
- package/src/services/slidesapp/fakepresentation.js +126 -2
- package/src/services/slidesapp/fakeshape.js +9 -0
- package/src/services/slidesapp/fakeslide.js +216 -24
- package/src/services/slidesapp/fakesolidfill.js +45 -0
- package/src/services/slidesapp/fakespeakerspotlight.js +18 -0
- package/src/services/slidesapp/faketable.js +55 -9
- package/src/services/slidesapp/faketablecell.js +141 -12
- package/src/services/slidesapp/faketablecellrange.js +28 -0
- package/src/services/slidesapp/faketablecolumn.js +72 -0
- package/src/services/slidesapp/faketablerow.js +31 -0
- package/src/services/slidesapp/faketextrange.js +179 -135
- package/src/services/slidesapp/faketextstyle.js +158 -0
- package/src/services/slidesapp/fakevideo.js +35 -0
- package/src/services/slidesapp/fakewordart.js +22 -0
- package/src/services/slidesapp/pageelementfactory.js +24 -1
- package/src/services/stores/fakestores.js +2 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { Proxies } from '../../support/proxies.js';
|
|
2
|
+
import { newFakeList } from './fakelist.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* create a new FakeListStyle instance
|
|
6
|
+
* @param {...any} args
|
|
7
|
+
* @returns {FakeListStyle}
|
|
8
|
+
*/
|
|
9
|
+
export const newFakeListStyle = (...args) => {
|
|
10
|
+
return Proxies.guard(new FakeListStyle(...args));
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export class FakeListStyle {
|
|
14
|
+
constructor(textRange) {
|
|
15
|
+
this.__textRange = textRange;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
get __bullet() {
|
|
19
|
+
// Find first paragraph marker with bullet in range
|
|
20
|
+
const resource = this.__textRange.__resource;
|
|
21
|
+
const elements = resource?.textElements || [];
|
|
22
|
+
const start = this.__textRange.getStartIndex();
|
|
23
|
+
|
|
24
|
+
let currentIndex = 0;
|
|
25
|
+
for (const element of elements) {
|
|
26
|
+
const length = element.textRun?.content?.length || (element.autoText ? 1 : 0);
|
|
27
|
+
if (currentIndex >= start && element.paragraphMarker && element.paragraphMarker.bullet) {
|
|
28
|
+
return element.paragraphMarker.bullet;
|
|
29
|
+
}
|
|
30
|
+
currentIndex += length;
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
applyListPreset(preset) {
|
|
36
|
+
const presentationId = this.__textRange.__shape.__presentation.getId();
|
|
37
|
+
const objectId = this.__textRange.__shape.getObjectId();
|
|
38
|
+
const cellLocation = this.__textRange.__shape.__cellLocation;
|
|
39
|
+
|
|
40
|
+
Slides.Presentations.batchUpdate({ requests: [{
|
|
41
|
+
createParagraphBullets: {
|
|
42
|
+
objectId,
|
|
43
|
+
cellLocation,
|
|
44
|
+
bulletPreset: preset.toString(),
|
|
45
|
+
textRange: {
|
|
46
|
+
type: 'FIXED_RANGE',
|
|
47
|
+
startIndex: this.__textRange.getStartIndex(),
|
|
48
|
+
endIndex: this.__textRange.getEndIndex()
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}] }, presentationId);
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
getGlyph() {
|
|
56
|
+
// API doesn't return the rendered glyph string directly easily.
|
|
57
|
+
return this.__bullet ? '•' : null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
getList() {
|
|
61
|
+
const bullet = this.__bullet;
|
|
62
|
+
if (!bullet) return null;
|
|
63
|
+
return newFakeList(bullet.listId, this.__textRange.__shape.__presentation, this.__textRange.__shape);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
getNestingLevel() {
|
|
67
|
+
return this.__bullet?.nestingLevel || 0;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
isInList() {
|
|
71
|
+
return !!this.__bullet;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
removeFromList() {
|
|
75
|
+
const presentationId = this.__textRange.__shape.__presentation.getId();
|
|
76
|
+
const objectId = this.__textRange.__shape.getObjectId();
|
|
77
|
+
const cellLocation = this.__textRange.__shape.__cellLocation;
|
|
78
|
+
|
|
79
|
+
Slides.Presentations.batchUpdate({ requests: [{
|
|
80
|
+
deleteAllText: {
|
|
81
|
+
objectId,
|
|
82
|
+
cellLocation,
|
|
83
|
+
// Wait, deleteAllText is for all text.
|
|
84
|
+
// To remove bullets, we use deleteParagraphBullets.
|
|
85
|
+
}
|
|
86
|
+
}] }, presentationId);
|
|
87
|
+
// Correct request is deleteParagraphBullets
|
|
88
|
+
Slides.Presentations.batchUpdate({ requests: [{
|
|
89
|
+
deleteParagraphBullets: {
|
|
90
|
+
objectId,
|
|
91
|
+
cellLocation,
|
|
92
|
+
textRange: {
|
|
93
|
+
type: 'FIXED_RANGE',
|
|
94
|
+
startIndex: this.__textRange.getStartIndex(),
|
|
95
|
+
endIndex: this.__textRange.getEndIndex()
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}] }, presentationId);
|
|
99
|
+
return this;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
toString() {
|
|
103
|
+
return 'ListStyle';
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { Proxies } from '../../support/proxies.js';
|
|
2
2
|
import { newFakeColorScheme } from './fakecolorscheme.js';
|
|
3
|
+
import { newFakePageBackground } from './fakepagebackground.js';
|
|
4
|
+
import { newFakePageElement, PageElementRegistry } from './fakepageelement.js';
|
|
5
|
+
import { newFakeLayout } from './fakelayout.js';
|
|
3
6
|
|
|
4
7
|
export const newFakeMaster = (...args) => {
|
|
5
8
|
return Proxies.guard(new FakeMaster(...args));
|
|
@@ -24,6 +27,14 @@ export class FakeMaster {
|
|
|
24
27
|
return this.__id;
|
|
25
28
|
}
|
|
26
29
|
|
|
30
|
+
/**
|
|
31
|
+
* Gets the background of the master.
|
|
32
|
+
* @returns {FakePageBackground} The background.
|
|
33
|
+
*/
|
|
34
|
+
getBackground() {
|
|
35
|
+
return newFakePageBackground(this);
|
|
36
|
+
}
|
|
37
|
+
|
|
27
38
|
/**
|
|
28
39
|
* Gets the color scheme of the master.
|
|
29
40
|
* @returns {FakeColorScheme} The color scheme.
|
|
@@ -32,6 +43,353 @@ export class FakeMaster {
|
|
|
32
43
|
return newFakeColorScheme(this);
|
|
33
44
|
}
|
|
34
45
|
|
|
46
|
+
/**
|
|
47
|
+
* Gets the type of the page.
|
|
48
|
+
* @returns {SlidesApp.PageType}
|
|
49
|
+
*/
|
|
50
|
+
getPageType() {
|
|
51
|
+
return SlidesApp.PageType.MASTER;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Gets the list of page elements on the master.
|
|
56
|
+
* @returns {FakePageElement[]} The page elements.
|
|
57
|
+
*/
|
|
58
|
+
getPageElements() {
|
|
59
|
+
return (this.__resource.pageElements || []).map(pe => newFakePageElement(pe, this));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Gets a page element by ID.
|
|
64
|
+
* @param {string} id The ID.
|
|
65
|
+
* @returns {FakePageElement|null} The element.
|
|
66
|
+
*/
|
|
67
|
+
getPageElementById(id) {
|
|
68
|
+
return this.getPageElements().find(pe => pe.getObjectId() === id) || null;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
getGroups() {
|
|
72
|
+
return this.getPageElements()
|
|
73
|
+
.filter(pe => pe.getPageElementType().toString() === 'GROUP')
|
|
74
|
+
.map(pe => pe.asGroup());
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
getImages() {
|
|
78
|
+
return this.getPageElements()
|
|
79
|
+
.filter(pe => pe.getPageElementType().toString() === 'IMAGE')
|
|
80
|
+
.map(pe => pe.asImage());
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
getLines() {
|
|
84
|
+
return this.getPageElements()
|
|
85
|
+
.filter(pe => pe.getPageElementType().toString() === 'LINE')
|
|
86
|
+
.map(pe => pe.asLine());
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
getShapes() {
|
|
90
|
+
return this.getPageElements()
|
|
91
|
+
.filter(pe => pe.getPageElementType().toString() === 'SHAPE')
|
|
92
|
+
.map(pe => pe.asShape());
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
getTables() {
|
|
96
|
+
return this.getPageElements()
|
|
97
|
+
.filter(pe => pe.getPageElementType().toString() === 'TABLE')
|
|
98
|
+
.map(pe => pe.asTable());
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
getVideos() {
|
|
102
|
+
return this.getPageElements()
|
|
103
|
+
.filter(pe => pe.getPageElementType().toString() === 'VIDEO')
|
|
104
|
+
.map(pe => pe.asVideo());
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
getWordArts() {
|
|
108
|
+
return this.getPageElements()
|
|
109
|
+
.filter(pe => pe.getPageElementType().toString() === 'WORD_ART')
|
|
110
|
+
.map(pe => pe.asWordArt());
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
getSheetsCharts() {
|
|
114
|
+
return this.getPageElements()
|
|
115
|
+
.filter(pe => pe.getPageElementType().toString() === 'SHEETS_CHART')
|
|
116
|
+
.map(pe => pe.asSheetsChart());
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Inserts a Google Sheets chart on the master.
|
|
121
|
+
* @param {EmbeddedChart} chart The chart.
|
|
122
|
+
* @returns {SheetsChart} The inserted chart.
|
|
123
|
+
*/
|
|
124
|
+
insertSheetsChart(chart) {
|
|
125
|
+
const presentationId = this.__presentation.getId();
|
|
126
|
+
const objectId = `chart_${Math.random().toString(36).substring(2, 11)}`;
|
|
127
|
+
const spreadsheetId = chart.getSpreadsheetId ? chart.getSpreadsheetId() : '';
|
|
128
|
+
const chartId = chart.getChartId ? chart.getChartId() : 0;
|
|
129
|
+
|
|
130
|
+
const requests = [{
|
|
131
|
+
createSheetsChart: {
|
|
132
|
+
objectId,
|
|
133
|
+
spreadsheetId,
|
|
134
|
+
chartId,
|
|
135
|
+
linkingMode: 'LINKED',
|
|
136
|
+
elementProperties: {
|
|
137
|
+
pageObjectId: this.getObjectId(),
|
|
138
|
+
size: {
|
|
139
|
+
width: { magnitude: 400, unit: 'PT' },
|
|
140
|
+
height: { magnitude: 300, unit: 'PT' }
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}];
|
|
145
|
+
|
|
146
|
+
Slides.Presentations.batchUpdate({ requests }, presentationId);
|
|
147
|
+
return this.getPageElementById(objectId).asSheetsChart();
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Inserts a Google Sheets chart as an image on the master.
|
|
152
|
+
* @param {EmbeddedChart} chart The chart.
|
|
153
|
+
* @returns {Image} The inserted image.
|
|
154
|
+
*/
|
|
155
|
+
insertSheetsChartAsImage(chart) {
|
|
156
|
+
const presentationId = this.__presentation.getId();
|
|
157
|
+
const objectId = `chart_img_${Math.random().toString(36).substring(2, 11)}`;
|
|
158
|
+
const requests = [{
|
|
159
|
+
createImage: {
|
|
160
|
+
objectId,
|
|
161
|
+
url: 'https://via.placeholder.com/400x300?text=Sheets+Chart',
|
|
162
|
+
elementProperties: {
|
|
163
|
+
pageObjectId: this.getObjectId()
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}];
|
|
167
|
+
Slides.Presentations.batchUpdate({ requests }, presentationId);
|
|
168
|
+
return this.getPageElementById(objectId).asImage();
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Gets the layouts associated with this master.
|
|
173
|
+
* @returns {FakeLayout[]} The layouts.
|
|
174
|
+
*/
|
|
175
|
+
getLayouts() {
|
|
176
|
+
const layouts = this.__presentation.__resource.layouts || [];
|
|
177
|
+
return layouts
|
|
178
|
+
.filter(l => l.layoutProperties?.masterObjectId === this.__id)
|
|
179
|
+
.map(l => newFakeLayout(l, this.__presentation));
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
getPlaceholders() {
|
|
183
|
+
return this.getPageElements().filter(pe => pe.__resource.shape?.placeholder || pe.__resource.image?.placeholder);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
getPlaceholder(placeholderType, index = 0) {
|
|
187
|
+
const typeStr = placeholderType.toString();
|
|
188
|
+
return this.getPlaceholders().find(p => {
|
|
189
|
+
const ph = p.__resource.shape?.placeholder || p.__resource.image?.placeholder;
|
|
190
|
+
return ph.type === typeStr && (ph.index === index || (index === 0 && ph.index === undefined));
|
|
191
|
+
}) || null;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
insertShape(shapeType, left = 0, top = 0, width = 300, height = 300) {
|
|
195
|
+
const presentationId = this.__presentation.getId();
|
|
196
|
+
const objectId = `shape_${Math.random().toString(36).substring(2, 11)}`;
|
|
197
|
+
const requests = [{
|
|
198
|
+
createShape: {
|
|
199
|
+
objectId,
|
|
200
|
+
shapeType: shapeType.toString(),
|
|
201
|
+
elementProperties: {
|
|
202
|
+
pageObjectId: this.getObjectId(),
|
|
203
|
+
size: {
|
|
204
|
+
width: { magnitude: width, unit: 'PT' },
|
|
205
|
+
height: { magnitude: height, unit: 'PT' }
|
|
206
|
+
},
|
|
207
|
+
transform: {
|
|
208
|
+
scaleX: 1,
|
|
209
|
+
scaleY: 1,
|
|
210
|
+
translateX: left,
|
|
211
|
+
translateY: top,
|
|
212
|
+
unit: 'PT'
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}];
|
|
217
|
+
|
|
218
|
+
Slides.Presentations.batchUpdate({ requests }, presentationId);
|
|
219
|
+
return this.getPageElementById(objectId).asShape();
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
insertTextBox(text, left = 0, top = 0, width = 300, height = 50) {
|
|
223
|
+
const shape = this.insertShape(SlidesApp.ShapeType.TEXT_BOX, left, top, width, height);
|
|
224
|
+
if (text) shape.getText().setText(text);
|
|
225
|
+
return shape;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
insertTable(rows, columns, left = 0, top = 0, width = 300, height = 300) {
|
|
229
|
+
const presentationId = this.__presentation.getId();
|
|
230
|
+
const objectId = `table_${Math.random().toString(36).substring(2, 11)}`;
|
|
231
|
+
const requests = [{
|
|
232
|
+
createTable: {
|
|
233
|
+
objectId,
|
|
234
|
+
rows,
|
|
235
|
+
columns,
|
|
236
|
+
elementProperties: {
|
|
237
|
+
pageObjectId: this.getObjectId(),
|
|
238
|
+
size: {
|
|
239
|
+
width: { magnitude: width, unit: 'PT' },
|
|
240
|
+
height: { magnitude: height, unit: 'PT' }
|
|
241
|
+
},
|
|
242
|
+
transform: {
|
|
243
|
+
scaleX: 1,
|
|
244
|
+
scaleY: 1,
|
|
245
|
+
translateX: left,
|
|
246
|
+
translateY: top,
|
|
247
|
+
unit: 'PT'
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}];
|
|
252
|
+
|
|
253
|
+
Slides.Presentations.batchUpdate({ requests }, presentationId);
|
|
254
|
+
return this.getPageElementById(objectId).asTable();
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Inserts a video at the top left corner of the master.
|
|
259
|
+
* @param {string} videoUrl The video URL.
|
|
260
|
+
* @param {number} [left]
|
|
261
|
+
* @param {number} [top]
|
|
262
|
+
* @param {number} [width]
|
|
263
|
+
* @param {number} [height]
|
|
264
|
+
* @returns {FakeVideo} The inserted video.
|
|
265
|
+
*/
|
|
266
|
+
insertVideo(videoUrl, left = 0, top = 0, width = 300, height = 200) {
|
|
267
|
+
const presentationId = this.__presentation.getId();
|
|
268
|
+
const objectId = `video_${Math.random().toString(36).substring(2, 11)}`;
|
|
269
|
+
|
|
270
|
+
let videoId = videoUrl;
|
|
271
|
+
if (videoUrl.includes('v=')) {
|
|
272
|
+
videoId = videoUrl.split('v=')[1].split('&')[0];
|
|
273
|
+
} else if (videoUrl.includes('youtu.be/')) {
|
|
274
|
+
videoId = videoUrl.split('youtu.be/')[1].split('?')[0];
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const requests = [{
|
|
278
|
+
createVideo: {
|
|
279
|
+
objectId,
|
|
280
|
+
source: 'YOUTUBE',
|
|
281
|
+
id: videoId,
|
|
282
|
+
elementProperties: {
|
|
283
|
+
pageObjectId: this.getObjectId(),
|
|
284
|
+
size: {
|
|
285
|
+
width: { magnitude: width, unit: 'PT' },
|
|
286
|
+
height: { magnitude: height, unit: 'PT' }
|
|
287
|
+
},
|
|
288
|
+
transform: {
|
|
289
|
+
scaleX: 1,
|
|
290
|
+
scaleY: 1,
|
|
291
|
+
translateX: left,
|
|
292
|
+
translateY: top,
|
|
293
|
+
unit: 'PT'
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}];
|
|
298
|
+
|
|
299
|
+
Slides.Presentations.batchUpdate({ requests }, presentationId);
|
|
300
|
+
return this.getPageElementById(objectId).asVideo();
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
insertImage(urlOrBlob, left = 0, top = 0, width = 300, height = 300) {
|
|
304
|
+
const presentationId = this.__presentation.getId();
|
|
305
|
+
const objectId = `image_${Math.random().toString(36).substring(2, 11)}`;
|
|
306
|
+
let url = typeof urlOrBlob === 'string' ? urlOrBlob : '';
|
|
307
|
+
|
|
308
|
+
const requests = [{
|
|
309
|
+
createImage: {
|
|
310
|
+
objectId,
|
|
311
|
+
url: url || 'https://via.placeholder.com/150',
|
|
312
|
+
elementProperties: {
|
|
313
|
+
pageObjectId: this.getObjectId(),
|
|
314
|
+
size: {
|
|
315
|
+
width: { magnitude: width, unit: 'PT' },
|
|
316
|
+
height: { magnitude: height, unit: 'PT' }
|
|
317
|
+
},
|
|
318
|
+
transform: {
|
|
319
|
+
scaleX: 1,
|
|
320
|
+
scaleY: 1,
|
|
321
|
+
translateX: left,
|
|
322
|
+
translateY: top,
|
|
323
|
+
unit: 'PT'
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}];
|
|
328
|
+
|
|
329
|
+
Slides.Presentations.batchUpdate({ requests }, presentationId);
|
|
330
|
+
return this.getPageElementById(objectId).asImage();
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
insertLine(lineCategory, startX, startY, endX, endY) {
|
|
334
|
+
const presentationId = this.__presentation.getId();
|
|
335
|
+
const objectId = `line_${Math.random().toString(36).substring(2, 11)}`;
|
|
336
|
+
const requests = [{
|
|
337
|
+
createLine: {
|
|
338
|
+
objectId,
|
|
339
|
+
lineCategory: lineCategory.toString(),
|
|
340
|
+
elementProperties: {
|
|
341
|
+
pageObjectId: this.getObjectId(),
|
|
342
|
+
size: {
|
|
343
|
+
width: { magnitude: Math.abs(endX - startX), unit: 'PT' },
|
|
344
|
+
height: { magnitude: Math.abs(endY - startY), unit: 'PT' }
|
|
345
|
+
},
|
|
346
|
+
transform: {
|
|
347
|
+
scaleX: 1,
|
|
348
|
+
scaleY: 1,
|
|
349
|
+
translateX: Math.min(startX, endX),
|
|
350
|
+
translateY: Math.min(startY, endY),
|
|
351
|
+
unit: 'PT'
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}];
|
|
356
|
+
|
|
357
|
+
Slides.Presentations.batchUpdate({ requests }, presentationId);
|
|
358
|
+
return this.getPageElementById(objectId).asLine();
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
remove() {
|
|
362
|
+
const presentationId = this.__presentation.getId();
|
|
363
|
+
Slides.Presentations.batchUpdate({ requests: [{
|
|
364
|
+
deleteObject: {
|
|
365
|
+
objectId: this.getObjectId()
|
|
366
|
+
}
|
|
367
|
+
}] }, presentationId);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
replaceAllText(findText, replaceText, matchCase = false) {
|
|
371
|
+
const presentationId = this.__presentation.getId();
|
|
372
|
+
Slides.Presentations.batchUpdate({ requests: [{
|
|
373
|
+
replaceAllText: {
|
|
374
|
+
replaceText,
|
|
375
|
+
containsText: {
|
|
376
|
+
text: findText,
|
|
377
|
+
matchCase
|
|
378
|
+
},
|
|
379
|
+
pageObjectIds: [this.getObjectId()]
|
|
380
|
+
}
|
|
381
|
+
}] }, presentationId);
|
|
382
|
+
return this;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
selectAsCurrentPage() {
|
|
386
|
+
return this;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
asLayout() { throw new Error('Cannot cast Master to Layout'); }
|
|
390
|
+
asSlide() { throw new Error('Cannot cast Master to Slide'); }
|
|
391
|
+
asMaster() { return this; }
|
|
392
|
+
|
|
35
393
|
toString() {
|
|
36
394
|
return 'Master';
|
|
37
395
|
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { Proxies } from '../../support/proxies.js';
|
|
2
|
+
import { newFakeColorScheme } from './fakecolorscheme.js';
|
|
3
|
+
import { newFakePageBackground } from './fakepagebackground.js';
|
|
4
|
+
import { newFakePageElement } from './fakepageelement.js';
|
|
5
|
+
|
|
6
|
+
export const newFakeNotesMaster = (...args) => {
|
|
7
|
+
return Proxies.guard(new FakeNotesMaster(...args));
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export class FakeNotesMaster {
|
|
11
|
+
constructor(resource, presentation) {
|
|
12
|
+
this.__id = resource.objectId;
|
|
13
|
+
this.__presentation = presentation;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
get __resource() {
|
|
17
|
+
const presentationResource = this.__presentation.__resource;
|
|
18
|
+
const notesMaster = presentationResource.notesMaster;
|
|
19
|
+
if (!notesMaster || notesMaster.objectId !== this.__id) {
|
|
20
|
+
throw new Error(`NotesMaster with ID ${this.__id} not found`);
|
|
21
|
+
}
|
|
22
|
+
return notesMaster;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
getObjectId() {
|
|
26
|
+
return this.__id;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Gets the background of the notes master.
|
|
31
|
+
* @returns {FakePageBackground} The background.
|
|
32
|
+
*/
|
|
33
|
+
getBackground() {
|
|
34
|
+
return newFakePageBackground(this);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Gets the color scheme of the notes master.
|
|
39
|
+
* @returns {FakeColorScheme} The color scheme.
|
|
40
|
+
*/
|
|
41
|
+
getColorScheme() {
|
|
42
|
+
return newFakeColorScheme(this);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Gets the list of page elements on the notes master.
|
|
47
|
+
* @returns {FakePageElement[]} The page elements.
|
|
48
|
+
*/
|
|
49
|
+
getPageElements() {
|
|
50
|
+
return (this.__resource.pageElements || []).map(pe => newFakePageElement(pe, this));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Gets a page element by ID.
|
|
55
|
+
* @param {string} id The ID.
|
|
56
|
+
* @returns {FakePageElement|null} The element.
|
|
57
|
+
*/
|
|
58
|
+
getPageElementById(id) {
|
|
59
|
+
return this.getPageElements().find(pe => pe.getObjectId() === id) || null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
getGroups() {
|
|
63
|
+
return this.getPageElements()
|
|
64
|
+
.filter(pe => pe.getPageElementType().toString() === 'GROUP')
|
|
65
|
+
.map(pe => pe.asGroup());
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
getImages() {
|
|
69
|
+
return this.getPageElements()
|
|
70
|
+
.filter(pe => pe.getPageElementType().toString() === 'IMAGE')
|
|
71
|
+
.map(pe => pe.asImage());
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
getLines() {
|
|
75
|
+
return this.getPageElements()
|
|
76
|
+
.filter(pe => pe.getPageElementType().toString() === 'LINE')
|
|
77
|
+
.map(pe => pe.asLine());
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
getShapes() {
|
|
81
|
+
return this.getPageElements()
|
|
82
|
+
.filter(pe => pe.getPageElementType().toString() === 'SHAPE')
|
|
83
|
+
.map(pe => pe.asShape());
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
getTables() {
|
|
87
|
+
return this.getPageElements()
|
|
88
|
+
.filter(pe => pe.getPageElementType().toString() === 'TABLE')
|
|
89
|
+
.map(pe => pe.asTable());
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
getVideos() {
|
|
93
|
+
return this.getPageElements()
|
|
94
|
+
.filter(pe => pe.getPageElementType().toString() === 'VIDEO')
|
|
95
|
+
.map(pe => pe.asVideo());
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
getWordArts() {
|
|
99
|
+
return this.getPageElements()
|
|
100
|
+
.filter(pe => pe.getPageElementType().toString() === 'WORD_ART')
|
|
101
|
+
.map(pe => pe.asWordArt());
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
getSheetsCharts() {
|
|
105
|
+
return this.getPageElements()
|
|
106
|
+
.filter(pe => pe.getPageElementType().toString() === 'SHEETS_CHART')
|
|
107
|
+
.map(pe => pe.asSheetsChart());
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
getPlaceholders() {
|
|
111
|
+
return this.getPageElements().filter(pe => pe.__resource.shape?.placeholder || pe.__resource.image?.placeholder);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
getPlaceholder(placeholderType, index = 0) {
|
|
115
|
+
const typeStr = placeholderType.toString();
|
|
116
|
+
return this.getPlaceholders().find(p => {
|
|
117
|
+
const ph = p.__resource.shape?.placeholder || p.__resource.image?.placeholder;
|
|
118
|
+
return ph.type === typeStr && (ph.index === index || (index === 0 && ph.index === undefined));
|
|
119
|
+
}) || null;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
toString() {
|
|
123
|
+
return 'NotesMaster';
|
|
124
|
+
}
|
|
125
|
+
}
|