@webwriter/geogebra 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +6 -6
- package/components/geogebra-app.ts +416 -416
- package/custom.d.ts +179 -179
- package/package.json +165 -163
- package/tsconfig.json +7 -7
- package/widgets/webwriter-geogebra-3d.ts +8 -8
- package/widgets/webwriter-geogebra-classic.ts +8 -8
- package/widgets/webwriter-geogebra-evaluator.ts +8 -8
- package/widgets/webwriter-geogebra-geometry.ts +8 -8
- package/widgets/webwriter-geogebra-notes.ts +8 -8
- package/widgets/webwriter-geogebra-scientific.ts +8 -8
- package/widgets/webwriter-geogebra.ts +19 -19
- package/dist/widgets/webwriter-geogebra-evaluator.js +0 -1885
|
@@ -1,417 +1,417 @@
|
|
|
1
|
-
import {LitElement, html, css, PropertyValues} from "lit"
|
|
2
|
-
import {LitElementWw, option} from "@webwriter/lit"
|
|
3
|
-
import {customElement, property, query, queryAsync} from "lit/decorators.js"
|
|
4
|
-
|
|
5
|
-
export interface GeogebraAPI {
|
|
6
|
-
evalCommand(cmdString: string): boolean
|
|
7
|
-
evalLaTex(input: string): boolean
|
|
8
|
-
evalCommandGetLabels(cmdString: string): string
|
|
9
|
-
evalCommandCAS(text: string): string
|
|
10
|
-
insertEmbed(type: string, uri: string): void
|
|
11
|
-
deleteObject(objName: string): void
|
|
12
|
-
setAuxiliary(geo: any, status: boolean): void
|
|
13
|
-
setValue(objName: string, value: number): void
|
|
14
|
-
setTextValue(objName: string, value: string): void
|
|
15
|
-
setListValue(objName: string, i: number, value: number): void
|
|
16
|
-
setCoords(objName: string, x: number, y: number, z?: number): void
|
|
17
|
-
setCaption(objName: string, caption: string): void
|
|
18
|
-
setColor(objName: string, red: number, green: number, blue: number): void
|
|
19
|
-
setVisible(objName: string, visible: boolean): void
|
|
20
|
-
setLabelVisible(objName: string, visible: boolean): void
|
|
21
|
-
setLabelStyle(objName: string, style: 0 | 1 | 2 | 3): void
|
|
22
|
-
setFixed(objName: string, fixed: boolean, selectionAllowed: boolean): void
|
|
23
|
-
setTrace(objName: string, flag: boolean): void
|
|
24
|
-
renameObject(oldObjName: string, newObjName: string): boolean
|
|
25
|
-
setLayer(objName: string, layer: number): void
|
|
26
|
-
setLayerVisible(objName: string, visible: boolean): void
|
|
27
|
-
setLineStyle(objName: string, style: 0 | 1 | 2 | 3 | 4): void
|
|
28
|
-
setLineThickness(objName: string, thickness: -1 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13): void
|
|
29
|
-
setPointStyle(objName: string, size: -1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9): void
|
|
30
|
-
setPointSize(objName: string, size: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9): void
|
|
31
|
-
setDisplayStyle(objName: string, style: string): void
|
|
32
|
-
setFilling(objName: string, filling: number): void
|
|
33
|
-
getPNGBase64(exportScale: number, transparent?: boolean, dpi?: number): string
|
|
34
|
-
exportSVG(filename: string): void
|
|
35
|
-
exportSVG(callback: CallableFunction): void
|
|
36
|
-
exportPDF(scale: number, filename: string, sliderLabel?: string): void
|
|
37
|
-
exportPDF(scale: number, callback: CallableFunction, sliderLabel?: string): void
|
|
38
|
-
getScreenshotBase64(callback: CallableFunction): void
|
|
39
|
-
writePNGtoFile(fileName: string, exportScale?: number, transparent?: boolean, dpi?: number): boolean
|
|
40
|
-
isIndependent(objName: string): boolean
|
|
41
|
-
isMovable(objName: string): boolean
|
|
42
|
-
showAllObjects(): void
|
|
43
|
-
registerEmbedResolver(type: string, callback: CallableFunction): void
|
|
44
|
-
setAnimating(objName: string, animate: boolean): void
|
|
45
|
-
setAnimationSpeed(objName: string, speed: number): void
|
|
46
|
-
startAnimation(): void
|
|
47
|
-
stopAnimation(): void
|
|
48
|
-
isAnimationRunning(): boolean
|
|
49
|
-
getXcoord(objName: string): number
|
|
50
|
-
getYcoord(objName: string): number
|
|
51
|
-
getZcoord(objName: string): number
|
|
52
|
-
getValue(objName: string): number
|
|
53
|
-
getListValue(objName: string, index: number): number
|
|
54
|
-
getColor(objName: string): string
|
|
55
|
-
getVisible(objName: string): boolean
|
|
56
|
-
getValueString(objName: string, useLocalizedInput?: boolean): string
|
|
57
|
-
getDefinitionString(objName: string): string
|
|
58
|
-
getCommandString(objName: string, useLocalizedInput?: boolean): string
|
|
59
|
-
getLaTeXString(objName: string, value: boolean): string
|
|
60
|
-
getObjectType(objName: string): string
|
|
61
|
-
exists(objName: string): boolean
|
|
62
|
-
isDefined(objName: string): boolean
|
|
63
|
-
getAllObjectNames(type?: string): string[]
|
|
64
|
-
getObjectNumber(): number
|
|
65
|
-
getCASObjectNumber(): number
|
|
66
|
-
getObjectName(i: number): string
|
|
67
|
-
getLayer(objName: string): string
|
|
68
|
-
getLineStyle(objName: string): 0 | 1 | 2 | 3 | 4
|
|
69
|
-
getLineThickness(objName: string): -1 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13
|
|
70
|
-
getPointStyle(objName: string): -1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
|
|
71
|
-
getPointSize(objName: string): 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
|
|
72
|
-
getFilling(objName: string): number
|
|
73
|
-
getCaption(objName: string, substitutePlaceholders?: boolean): string
|
|
74
|
-
getLabelStyle(objName: string): 0 | 1 | 2 | 3
|
|
75
|
-
getLabelVisible(): boolean
|
|
76
|
-
isInteractive(objName: string): boolean
|
|
77
|
-
setMode(mode: number): void
|
|
78
|
-
getMode(): number
|
|
79
|
-
reset(): void
|
|
80
|
-
newConstruction(): void
|
|
81
|
-
refreshViews(): void
|
|
82
|
-
setOnTheFlyPointCreationActive(flag: boolean): void
|
|
83
|
-
setPointCapture(view: -1 | 1 | 2, mode: 0 | 1 | 2 | 3): void
|
|
84
|
-
setRounding(round: string): void
|
|
85
|
-
hideCursorWhenDragging(flag: boolean): void
|
|
86
|
-
setRepaintingActive(flag: boolean): void
|
|
87
|
-
setErrorDialogsActive(flag: boolean): void
|
|
88
|
-
setCoordSystem(xmin: number, xmax: number, ymin: number, ymax: number, zmin?: number, zmax?: number, yVertical?: boolean): void
|
|
89
|
-
setAxesVisible(xAxis: boolean, yAxis: boolean, zAxis?: boolean): void
|
|
90
|
-
setUndoPoint(): void
|
|
91
|
-
setAxisLabels(viewNumber: number, xAxis: string, yAxis: string, zAxis: string): void
|
|
92
|
-
setAxisSteps(viewNumber: number, xAxis: number, yAxis: number, zAxis: number): void
|
|
93
|
-
setAxisUnits(viewNumber: number, xAxis: string, yAxis: string, zAxis: string): void
|
|
94
|
-
setGridVisible(flag: boolean): void
|
|
95
|
-
setGridVisible(viewNumber: number, flag: boolean): void
|
|
96
|
-
getGridVisible(viewNumber: number): boolean
|
|
97
|
-
getPerspectiveXML(): string
|
|
98
|
-
undo(): void
|
|
99
|
-
redo(): void
|
|
100
|
-
showToolBar(show: boolean): void
|
|
101
|
-
setCustomToolBar(toolbar: string): void
|
|
102
|
-
addCustomTool(iconURL: string, name: string, category?: string, callback?: CallableFunction): void
|
|
103
|
-
showMenuBar(show: boolean): void
|
|
104
|
-
showAlgebraInput(show: boolean): void
|
|
105
|
-
showResetIcon(show: boolean): void
|
|
106
|
-
enableRightClick(enable: boolean): void
|
|
107
|
-
enableLabelDrags(enable: boolean): void
|
|
108
|
-
enableShiftDragZoom(enable: boolean): void
|
|
109
|
-
enableCAS(enable: boolean): void
|
|
110
|
-
enable3D(enable: boolean): void
|
|
111
|
-
setPerspective(perspective: string): void
|
|
112
|
-
setWidth(width: number): void
|
|
113
|
-
setHeight(height: number): void
|
|
114
|
-
setSize(width: number, height: number): void
|
|
115
|
-
recalculateEnvironments(): void
|
|
116
|
-
getEditorState(): any
|
|
117
|
-
setEditorState(state: any): void
|
|
118
|
-
getGraphicsOptions(viewId: number): any
|
|
119
|
-
setGraphicsOptions(viewID: number, options: any): void
|
|
120
|
-
setAlgebraOptions(options: any): void
|
|
121
|
-
registerAddListener(func: CallableFunction): void
|
|
122
|
-
unregisterAddListener(func: CallableFunction): void
|
|
123
|
-
registerRemoveListener(func: CallableFunction): void
|
|
124
|
-
unregisterRemoveListener(func: CallableFunction): void
|
|
125
|
-
registerUpdateListener(func: CallableFunction): void
|
|
126
|
-
unregisterUpdateListener(func: CallableFunction): void
|
|
127
|
-
registerClickListener(func: CallableFunction): void
|
|
128
|
-
unregisterClickListener(func: CallableFunction): void
|
|
129
|
-
registerObjectUpdateListener(objName: string, func: CallableFunction): void
|
|
130
|
-
unregisterObjectUpdateListener(objName: string): void
|
|
131
|
-
registerObjectClickListener(objName: string, func: CallableFunction): void
|
|
132
|
-
unregisterObjectClickListener(objName: string): void
|
|
133
|
-
registerRenameListener(func: CallableFunction): void
|
|
134
|
-
unregisterRenameListener(func: CallableFunction): void
|
|
135
|
-
registerClearListener(func: CallableFunction): void
|
|
136
|
-
unregisterClearListener(func: CallableFunction): void
|
|
137
|
-
registerStoreUndoListener(func: CallableFunction): void
|
|
138
|
-
unregisterStoreUndoListener(func: CallableFunction): void
|
|
139
|
-
registerClientListener(func: CallableFunction): void
|
|
140
|
-
unregisterClientListener(func: CallableFunction): void
|
|
141
|
-
evalXML(xmlString: string): void
|
|
142
|
-
setXML(xmlString: string): void
|
|
143
|
-
getXML(objName?: string): string
|
|
144
|
-
getAlgorithmXML(objName: string): string
|
|
145
|
-
getFileJSON(): any
|
|
146
|
-
setFileJSON(content: any): void
|
|
147
|
-
getBase64(callback?: CallableFunction): string
|
|
148
|
-
setBase64(value: string, callback?: CallableFunction): void
|
|
149
|
-
debug(str: string): void
|
|
150
|
-
getVersion(): string
|
|
151
|
-
remove(): void
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
export class GeogebraApp extends LitElementWw {
|
|
155
|
-
|
|
156
|
-
static styles = css`
|
|
157
|
-
iframe {
|
|
158
|
-
border: none;
|
|
159
|
-
width: 100%;
|
|
160
|
-
aspect-ratio: 16/9;
|
|
161
|
-
}
|
|
162
|
-
`
|
|
163
|
-
|
|
164
|
-
@property({type: String})
|
|
165
|
-
ggbStyles: string
|
|
166
|
-
|
|
167
|
-
@property({reflect: true})
|
|
168
|
-
type: "classic" | "geometry" | "3d" | "suite" | "evaluator" | "scientific" | "notes" = "classic"
|
|
169
|
-
|
|
170
|
-
@property({type: Number, reflect: true})
|
|
171
|
-
width: number = 800
|
|
172
|
-
|
|
173
|
-
@property({type: Number, reflect: true})
|
|
174
|
-
height: number = 450
|
|
175
|
-
|
|
176
|
-
@property({type: String, attribute: true, reflect: true}) // base64, material ID, file url
|
|
177
|
-
accessor src: string
|
|
178
|
-
|
|
179
|
-
@property({type: String, reflect: true})
|
|
180
|
-
borderColor: string = "gray"
|
|
181
|
-
|
|
182
|
-
@property({type: Number, reflect: true})
|
|
183
|
-
borderRadius: number = 1
|
|
184
|
-
|
|
185
|
-
@property({type: Boolean, reflect: true})
|
|
186
|
-
enableRightClick = true
|
|
187
|
-
|
|
188
|
-
@property({type: Boolean, reflect: true})
|
|
189
|
-
enableLabelDrags = true
|
|
190
|
-
|
|
191
|
-
@property({type: Boolean, reflect: true})
|
|
192
|
-
enableShiftDragZoom = true
|
|
193
|
-
|
|
194
|
-
@property({type: Boolean, reflect: true})
|
|
195
|
-
showZoomButtons = false
|
|
196
|
-
|
|
197
|
-
@property({type: Boolean, reflect: true})
|
|
198
|
-
errorDialogsActive = true
|
|
199
|
-
|
|
200
|
-
@property({type: Boolean, reflect: true})
|
|
201
|
-
showMenuBar = false
|
|
202
|
-
|
|
203
|
-
@property({type: Boolean, reflect: true})
|
|
204
|
-
showToolBar = false
|
|
205
|
-
|
|
206
|
-
@property({type: Boolean, reflect: true})
|
|
207
|
-
showToolBarHelp = false
|
|
208
|
-
|
|
209
|
-
@property({type: String, reflect: true})
|
|
210
|
-
customToolBar: string
|
|
211
|
-
|
|
212
|
-
@property({type: Boolean, reflect: true})
|
|
213
|
-
showAlgebraInput = true
|
|
214
|
-
|
|
215
|
-
@property({type: Boolean, reflect: true})
|
|
216
|
-
showResetIcon = false
|
|
217
|
-
|
|
218
|
-
@property({type: String, reflect: true})
|
|
219
|
-
language: String
|
|
220
|
-
|
|
221
|
-
@property({type: String, reflect: true})
|
|
222
|
-
country: String
|
|
223
|
-
|
|
224
|
-
@property({type: String, reflect: true})
|
|
225
|
-
appletId: String
|
|
226
|
-
|
|
227
|
-
@property({type: Boolean, reflect: true})
|
|
228
|
-
allowStyleBar = false
|
|
229
|
-
|
|
230
|
-
@property({type: Boolean, reflect: true})
|
|
231
|
-
randomize = true
|
|
232
|
-
|
|
233
|
-
@property({type: Number, reflect: true})
|
|
234
|
-
randomSeed: number
|
|
235
|
-
|
|
236
|
-
@property({type: Boolean, reflect: true})
|
|
237
|
-
useBrowserForJs = false
|
|
238
|
-
|
|
239
|
-
@property({type: Boolean, reflect: true})
|
|
240
|
-
showLogging = false
|
|
241
|
-
|
|
242
|
-
@property({type: Number, reflect: true})
|
|
243
|
-
capturingThreshold = 3
|
|
244
|
-
|
|
245
|
-
@property({type: Boolean, reflect: true})
|
|
246
|
-
enableFileFeatures = true
|
|
247
|
-
|
|
248
|
-
@property({type: Boolean, reflect: true})
|
|
249
|
-
enableUndoRedo = true
|
|
250
|
-
|
|
251
|
-
@property({type: String, reflect: true})
|
|
252
|
-
perspective: String
|
|
253
|
-
|
|
254
|
-
@property({type: Boolean, reflect: true})
|
|
255
|
-
enable3d: boolean
|
|
256
|
-
|
|
257
|
-
@property({type: Boolean, reflect: true})
|
|
258
|
-
enableCAS: boolean
|
|
259
|
-
|
|
260
|
-
@property({type: String, reflect: true})
|
|
261
|
-
algebraInputPosition: "algebra" | "top" | "bottom"
|
|
262
|
-
|
|
263
|
-
@property({type: Boolean, reflect: true})
|
|
264
|
-
preventFocus = false
|
|
265
|
-
|
|
266
|
-
@property({type: String, reflect: true})
|
|
267
|
-
scaleContainerClass: string
|
|
268
|
-
|
|
269
|
-
@property({type: Boolean, reflect: true})
|
|
270
|
-
autoHeight = true
|
|
271
|
-
|
|
272
|
-
@property({type: Boolean, reflect: true})
|
|
273
|
-
allowUpscale = false
|
|
274
|
-
|
|
275
|
-
@property({type: Boolean, reflect: true})
|
|
276
|
-
playButton = false
|
|
277
|
-
|
|
278
|
-
@property({type: Number, reflect: true})
|
|
279
|
-
scale = 1
|
|
280
|
-
|
|
281
|
-
@property({type: Boolean, reflect: true})
|
|
282
|
-
showAnimationButton = false
|
|
283
|
-
|
|
284
|
-
@property({type: Boolean, reflect: true})
|
|
285
|
-
showFullscreenButton = false
|
|
286
|
-
|
|
287
|
-
@property({type: Boolean, reflect: true})
|
|
288
|
-
showSuggestionButtons = false
|
|
289
|
-
|
|
290
|
-
@property({type: Boolean, reflect: true})
|
|
291
|
-
showStartTooltip = false
|
|
292
|
-
|
|
293
|
-
@property({type: String, reflect: true})
|
|
294
|
-
rounding: string
|
|
295
|
-
|
|
296
|
-
@property({type: Boolean, reflect: true})
|
|
297
|
-
buttonShadows = false
|
|
298
|
-
|
|
299
|
-
@property({type: Number, reflect: true})
|
|
300
|
-
buttonRounding: Number = 0.2
|
|
301
|
-
|
|
302
|
-
@property({type: String, reflect: true})
|
|
303
|
-
buttonBorderColor: string
|
|
304
|
-
|
|
305
|
-
@property({type: String, reflect: true})
|
|
306
|
-
editorBackgroundColor: string
|
|
307
|
-
|
|
308
|
-
@property({type: String, reflect: true})
|
|
309
|
-
editorForegroundColor: string
|
|
310
|
-
|
|
311
|
-
@property({type: Boolean, reflect: true})
|
|
312
|
-
textmode = false
|
|
313
|
-
|
|
314
|
-
@property({type: Boolean, reflect: true})
|
|
315
|
-
showKeyboardOnFocus: boolean
|
|
316
|
-
|
|
317
|
-
@property({type: String, reflect: true})
|
|
318
|
-
keyboardType: "scientific" | "normal" | "notes"
|
|
319
|
-
|
|
320
|
-
@property({type: Boolean, reflect: true})
|
|
321
|
-
transparentGraphics = false
|
|
322
|
-
|
|
323
|
-
@property({type: Boolean, reflect: true})
|
|
324
|
-
disabledJavaScript = false
|
|
325
|
-
|
|
326
|
-
@property({type: String, reflect: true})
|
|
327
|
-
detachedKeyboardParent: string
|
|
328
|
-
|
|
329
|
-
private get ggbProperties() {
|
|
330
|
-
const {appletId: id, type: appName, width, height, borderColor, borderRadius, enableLabelDrags, enableShiftDragZoom, showZoomButtons, errorDialogsActive, showMenuBar, showToolBar, showToolBarHelp, customToolBar, showAlgebraInput, showResetIcon, language, country, allowStyleBar, randomize, randomSeed, useBrowserForJs, showLogging, capturingThreshold, enableFileFeatures, perspective, enable3d, enableCAS, algebraInputPosition, preventFocus, scaleContainerClass, autoHeight, allowUpscale, playButton, scale, showAnimationButton, showFullscreenButton, showSuggestionButtons, showStartTooltip, rounding, buttonShadows, buttonRounding, buttonBorderColor, editorBackgroundColor, editorForegroundColor, textmode, showKeyboardOnFocus, keyboardType, transparentGraphics, disabledJavaScript, detachedKeyboardParent} = this
|
|
331
|
-
|
|
332
|
-
let filename: string, material_id: string, ggbBase64: string
|
|
333
|
-
if(this.src && this.src.startsWith("data:")) {
|
|
334
|
-
ggbBase64 = this.src.split(",").at(-1)
|
|
335
|
-
}
|
|
336
|
-
else if(this.src && this.src.startsWith("ggbid:")) {
|
|
337
|
-
material_id = this.src.slice("ggbid:".length)
|
|
338
|
-
}
|
|
339
|
-
else if(this.src) {
|
|
340
|
-
filename = this.src
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
return {id, appName, filename, material_id, ggbBase64, width, height, borderColor, borderRadius, enableLabelDrags, enableShiftDragZoom, showZoomButtons, errorDialogsActive, showMenuBar, showToolBar, showToolBarHelp, customToolBar, showAlgebraInput, showResetIcon, language: language ?? this.lang, country, allowStyleBar, randomize, randomSeed, useBrowserForJs, showLogging, capturingThreshold, enableFileFeatures, perspective, enable3d, enableCAS, algebraInputPosition, preventFocus, scaleContainerClass, autoHeight, allowUpscale, playButton, scale, showAnimationButton, showFullscreenButton, showSuggestionButtons, showStartTooltip, rounding, buttonShadows, buttonRounding, buttonBorderColor, editorBackgroundColor, editorForegroundColor, textmode, showKeyboardOnFocus, keyboardType, transparentGraphics, disabledJavaScript, detachedKeyboardParent}
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
updateSrc = () => {
|
|
347
|
-
if(!this.updatingGgb) {
|
|
348
|
-
this.src = `data:application/vnd.geogebra.file;base64,${this.api.getBase64()}`
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
connectedCallback(): void {
|
|
353
|
-
super.connectedCallback()
|
|
354
|
-
this.apiReady = new Promise(r => {
|
|
355
|
-
this.addEventListener("ggb-load", (e: any) => {
|
|
356
|
-
r(e.detail.api)
|
|
357
|
-
this.api = e.detail.api
|
|
358
|
-
this.api.registerAddListener(this.updateSrc)
|
|
359
|
-
this.api.registerClearListener(this.updateSrc)
|
|
360
|
-
this.api.registerUpdateListener(this.updateSrc)
|
|
361
|
-
this.api.registerRenameListener(this.updateSrc)
|
|
362
|
-
this.api.registerRemoveListener(this.updateSrc)
|
|
363
|
-
})
|
|
364
|
-
})
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
updatingGgb = false
|
|
368
|
-
|
|
369
|
-
protected updated(changed: PropertyValues): void {
|
|
370
|
-
|
|
371
|
-
if(changed.has("src") && this.src && this.src.split(",").at(-1) !== this?.api?.getBase64()) {
|
|
372
|
-
this.updatingGgb = true
|
|
373
|
-
this?.api?.setBase64(this.src.split(",").at(-1), () => this.updatingGgb = false)
|
|
374
|
-
}
|
|
375
|
-
else if(changed.has("src") && !this.src) {
|
|
376
|
-
this.updatingGgb = true
|
|
377
|
-
this?.api?.setBase64("", () => this.updatingGgb = false)
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
apiReady: Promise<GeogebraAPI>
|
|
382
|
-
api?: GeogebraAPI
|
|
383
|
-
|
|
384
|
-
initializeIFrame(e: Event) {
|
|
385
|
-
const iframe = e.target as HTMLIFrameElement
|
|
386
|
-
const doc = iframe.contentDocument
|
|
387
|
-
const win = iframe.contentWindow
|
|
388
|
-
doc.body.style.margin = "0"
|
|
389
|
-
if(this.ggbStyles) {
|
|
390
|
-
const style = doc.createElement("style")
|
|
391
|
-
style.textContent = this.ggbStyles
|
|
392
|
-
doc.head.append(style)
|
|
393
|
-
}
|
|
394
|
-
doc.body.addEventListener("focusin", () => this.dispatchEvent(new FocusEvent("focus", {bubbles: true, composed: true})))
|
|
395
|
-
const ggbEl = doc.createElement("div")
|
|
396
|
-
ggbEl.id = "ggb-element"
|
|
397
|
-
doc.body.append(ggbEl);
|
|
398
|
-
const deployScript = doc.createElement("script")
|
|
399
|
-
deployScript.src = "https://www.geogebra.org/apps/deployggb.js"
|
|
400
|
-
deployScript.addEventListener("load", () => {
|
|
401
|
-
const createScript = doc.createElement("script")
|
|
402
|
-
createScript.textContent = `
|
|
403
|
-
const applet = new GGBApplet({${JSON.stringify(this.ggbProperties).slice(1, -1)}, appletOnLoad: api => document.dispatchEvent(new CustomEvent("ggb-load", {bubbles: true, composed: true, detail: {api}}))})
|
|
404
|
-
applet.inject("ggb-element")
|
|
405
|
-
`
|
|
406
|
-
doc.addEventListener("ggb-load", (e: any) => this.dispatchEvent(new CustomEvent("ggb-load", {bubbles: true, composed: true, detail: e.detail})))
|
|
407
|
-
doc.body.append(createScript)
|
|
408
|
-
})
|
|
409
|
-
doc.body.append(deployScript)
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
render() {
|
|
413
|
-
return html`
|
|
414
|
-
<iframe id="ggb" @load=${this.initializeIFrame}></iframe>
|
|
415
|
-
`
|
|
416
|
-
}
|
|
1
|
+
import {LitElement, html, css, PropertyValues} from "lit"
|
|
2
|
+
import {LitElementWw, option} from "@webwriter/lit"
|
|
3
|
+
import {customElement, property, query, queryAsync} from "lit/decorators.js"
|
|
4
|
+
|
|
5
|
+
export interface GeogebraAPI {
|
|
6
|
+
evalCommand(cmdString: string): boolean
|
|
7
|
+
evalLaTex(input: string): boolean
|
|
8
|
+
evalCommandGetLabels(cmdString: string): string
|
|
9
|
+
evalCommandCAS(text: string): string
|
|
10
|
+
insertEmbed(type: string, uri: string): void
|
|
11
|
+
deleteObject(objName: string): void
|
|
12
|
+
setAuxiliary(geo: any, status: boolean): void
|
|
13
|
+
setValue(objName: string, value: number): void
|
|
14
|
+
setTextValue(objName: string, value: string): void
|
|
15
|
+
setListValue(objName: string, i: number, value: number): void
|
|
16
|
+
setCoords(objName: string, x: number, y: number, z?: number): void
|
|
17
|
+
setCaption(objName: string, caption: string): void
|
|
18
|
+
setColor(objName: string, red: number, green: number, blue: number): void
|
|
19
|
+
setVisible(objName: string, visible: boolean): void
|
|
20
|
+
setLabelVisible(objName: string, visible: boolean): void
|
|
21
|
+
setLabelStyle(objName: string, style: 0 | 1 | 2 | 3): void
|
|
22
|
+
setFixed(objName: string, fixed: boolean, selectionAllowed: boolean): void
|
|
23
|
+
setTrace(objName: string, flag: boolean): void
|
|
24
|
+
renameObject(oldObjName: string, newObjName: string): boolean
|
|
25
|
+
setLayer(objName: string, layer: number): void
|
|
26
|
+
setLayerVisible(objName: string, visible: boolean): void
|
|
27
|
+
setLineStyle(objName: string, style: 0 | 1 | 2 | 3 | 4): void
|
|
28
|
+
setLineThickness(objName: string, thickness: -1 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13): void
|
|
29
|
+
setPointStyle(objName: string, size: -1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9): void
|
|
30
|
+
setPointSize(objName: string, size: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9): void
|
|
31
|
+
setDisplayStyle(objName: string, style: string): void
|
|
32
|
+
setFilling(objName: string, filling: number): void
|
|
33
|
+
getPNGBase64(exportScale: number, transparent?: boolean, dpi?: number): string
|
|
34
|
+
exportSVG(filename: string): void
|
|
35
|
+
exportSVG(callback: CallableFunction): void
|
|
36
|
+
exportPDF(scale: number, filename: string, sliderLabel?: string): void
|
|
37
|
+
exportPDF(scale: number, callback: CallableFunction, sliderLabel?: string): void
|
|
38
|
+
getScreenshotBase64(callback: CallableFunction): void
|
|
39
|
+
writePNGtoFile(fileName: string, exportScale?: number, transparent?: boolean, dpi?: number): boolean
|
|
40
|
+
isIndependent(objName: string): boolean
|
|
41
|
+
isMovable(objName: string): boolean
|
|
42
|
+
showAllObjects(): void
|
|
43
|
+
registerEmbedResolver(type: string, callback: CallableFunction): void
|
|
44
|
+
setAnimating(objName: string, animate: boolean): void
|
|
45
|
+
setAnimationSpeed(objName: string, speed: number): void
|
|
46
|
+
startAnimation(): void
|
|
47
|
+
stopAnimation(): void
|
|
48
|
+
isAnimationRunning(): boolean
|
|
49
|
+
getXcoord(objName: string): number
|
|
50
|
+
getYcoord(objName: string): number
|
|
51
|
+
getZcoord(objName: string): number
|
|
52
|
+
getValue(objName: string): number
|
|
53
|
+
getListValue(objName: string, index: number): number
|
|
54
|
+
getColor(objName: string): string
|
|
55
|
+
getVisible(objName: string): boolean
|
|
56
|
+
getValueString(objName: string, useLocalizedInput?: boolean): string
|
|
57
|
+
getDefinitionString(objName: string): string
|
|
58
|
+
getCommandString(objName: string, useLocalizedInput?: boolean): string
|
|
59
|
+
getLaTeXString(objName: string, value: boolean): string
|
|
60
|
+
getObjectType(objName: string): string
|
|
61
|
+
exists(objName: string): boolean
|
|
62
|
+
isDefined(objName: string): boolean
|
|
63
|
+
getAllObjectNames(type?: string): string[]
|
|
64
|
+
getObjectNumber(): number
|
|
65
|
+
getCASObjectNumber(): number
|
|
66
|
+
getObjectName(i: number): string
|
|
67
|
+
getLayer(objName: string): string
|
|
68
|
+
getLineStyle(objName: string): 0 | 1 | 2 | 3 | 4
|
|
69
|
+
getLineThickness(objName: string): -1 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13
|
|
70
|
+
getPointStyle(objName: string): -1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
|
|
71
|
+
getPointSize(objName: string): 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
|
|
72
|
+
getFilling(objName: string): number
|
|
73
|
+
getCaption(objName: string, substitutePlaceholders?: boolean): string
|
|
74
|
+
getLabelStyle(objName: string): 0 | 1 | 2 | 3
|
|
75
|
+
getLabelVisible(): boolean
|
|
76
|
+
isInteractive(objName: string): boolean
|
|
77
|
+
setMode(mode: number): void
|
|
78
|
+
getMode(): number
|
|
79
|
+
reset(): void
|
|
80
|
+
newConstruction(): void
|
|
81
|
+
refreshViews(): void
|
|
82
|
+
setOnTheFlyPointCreationActive(flag: boolean): void
|
|
83
|
+
setPointCapture(view: -1 | 1 | 2, mode: 0 | 1 | 2 | 3): void
|
|
84
|
+
setRounding(round: string): void
|
|
85
|
+
hideCursorWhenDragging(flag: boolean): void
|
|
86
|
+
setRepaintingActive(flag: boolean): void
|
|
87
|
+
setErrorDialogsActive(flag: boolean): void
|
|
88
|
+
setCoordSystem(xmin: number, xmax: number, ymin: number, ymax: number, zmin?: number, zmax?: number, yVertical?: boolean): void
|
|
89
|
+
setAxesVisible(xAxis: boolean, yAxis: boolean, zAxis?: boolean): void
|
|
90
|
+
setUndoPoint(): void
|
|
91
|
+
setAxisLabels(viewNumber: number, xAxis: string, yAxis: string, zAxis: string): void
|
|
92
|
+
setAxisSteps(viewNumber: number, xAxis: number, yAxis: number, zAxis: number): void
|
|
93
|
+
setAxisUnits(viewNumber: number, xAxis: string, yAxis: string, zAxis: string): void
|
|
94
|
+
setGridVisible(flag: boolean): void
|
|
95
|
+
setGridVisible(viewNumber: number, flag: boolean): void
|
|
96
|
+
getGridVisible(viewNumber: number): boolean
|
|
97
|
+
getPerspectiveXML(): string
|
|
98
|
+
undo(): void
|
|
99
|
+
redo(): void
|
|
100
|
+
showToolBar(show: boolean): void
|
|
101
|
+
setCustomToolBar(toolbar: string): void
|
|
102
|
+
addCustomTool(iconURL: string, name: string, category?: string, callback?: CallableFunction): void
|
|
103
|
+
showMenuBar(show: boolean): void
|
|
104
|
+
showAlgebraInput(show: boolean): void
|
|
105
|
+
showResetIcon(show: boolean): void
|
|
106
|
+
enableRightClick(enable: boolean): void
|
|
107
|
+
enableLabelDrags(enable: boolean): void
|
|
108
|
+
enableShiftDragZoom(enable: boolean): void
|
|
109
|
+
enableCAS(enable: boolean): void
|
|
110
|
+
enable3D(enable: boolean): void
|
|
111
|
+
setPerspective(perspective: string): void
|
|
112
|
+
setWidth(width: number): void
|
|
113
|
+
setHeight(height: number): void
|
|
114
|
+
setSize(width: number, height: number): void
|
|
115
|
+
recalculateEnvironments(): void
|
|
116
|
+
getEditorState(): any
|
|
117
|
+
setEditorState(state: any): void
|
|
118
|
+
getGraphicsOptions(viewId: number): any
|
|
119
|
+
setGraphicsOptions(viewID: number, options: any): void
|
|
120
|
+
setAlgebraOptions(options: any): void
|
|
121
|
+
registerAddListener(func: CallableFunction): void
|
|
122
|
+
unregisterAddListener(func: CallableFunction): void
|
|
123
|
+
registerRemoveListener(func: CallableFunction): void
|
|
124
|
+
unregisterRemoveListener(func: CallableFunction): void
|
|
125
|
+
registerUpdateListener(func: CallableFunction): void
|
|
126
|
+
unregisterUpdateListener(func: CallableFunction): void
|
|
127
|
+
registerClickListener(func: CallableFunction): void
|
|
128
|
+
unregisterClickListener(func: CallableFunction): void
|
|
129
|
+
registerObjectUpdateListener(objName: string, func: CallableFunction): void
|
|
130
|
+
unregisterObjectUpdateListener(objName: string): void
|
|
131
|
+
registerObjectClickListener(objName: string, func: CallableFunction): void
|
|
132
|
+
unregisterObjectClickListener(objName: string): void
|
|
133
|
+
registerRenameListener(func: CallableFunction): void
|
|
134
|
+
unregisterRenameListener(func: CallableFunction): void
|
|
135
|
+
registerClearListener(func: CallableFunction): void
|
|
136
|
+
unregisterClearListener(func: CallableFunction): void
|
|
137
|
+
registerStoreUndoListener(func: CallableFunction): void
|
|
138
|
+
unregisterStoreUndoListener(func: CallableFunction): void
|
|
139
|
+
registerClientListener(func: CallableFunction): void
|
|
140
|
+
unregisterClientListener(func: CallableFunction): void
|
|
141
|
+
evalXML(xmlString: string): void
|
|
142
|
+
setXML(xmlString: string): void
|
|
143
|
+
getXML(objName?: string): string
|
|
144
|
+
getAlgorithmXML(objName: string): string
|
|
145
|
+
getFileJSON(): any
|
|
146
|
+
setFileJSON(content: any): void
|
|
147
|
+
getBase64(callback?: CallableFunction): string
|
|
148
|
+
setBase64(value: string, callback?: CallableFunction): void
|
|
149
|
+
debug(str: string): void
|
|
150
|
+
getVersion(): string
|
|
151
|
+
remove(): void
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export class GeogebraApp extends LitElementWw {
|
|
155
|
+
|
|
156
|
+
static styles = css`
|
|
157
|
+
iframe {
|
|
158
|
+
border: none;
|
|
159
|
+
width: 100%;
|
|
160
|
+
aspect-ratio: 16/9;
|
|
161
|
+
}
|
|
162
|
+
`
|
|
163
|
+
|
|
164
|
+
@property({type: String})
|
|
165
|
+
ggbStyles: string
|
|
166
|
+
|
|
167
|
+
@property({reflect: true})
|
|
168
|
+
type: "classic" | "geometry" | "3d" | "suite" | "evaluator" | "scientific" | "notes" = "classic"
|
|
169
|
+
|
|
170
|
+
@property({type: Number, reflect: true})
|
|
171
|
+
width: number = 800
|
|
172
|
+
|
|
173
|
+
@property({type: Number, reflect: true})
|
|
174
|
+
height: number = 450
|
|
175
|
+
|
|
176
|
+
@property({type: String, attribute: true, reflect: true}) // base64, material ID, file url
|
|
177
|
+
accessor src: string
|
|
178
|
+
|
|
179
|
+
@property({type: String, reflect: true})
|
|
180
|
+
borderColor: string = "gray"
|
|
181
|
+
|
|
182
|
+
@property({type: Number, reflect: true})
|
|
183
|
+
borderRadius: number = 1
|
|
184
|
+
|
|
185
|
+
@property({type: Boolean, reflect: true})
|
|
186
|
+
enableRightClick = true
|
|
187
|
+
|
|
188
|
+
@property({type: Boolean, reflect: true})
|
|
189
|
+
enableLabelDrags = true
|
|
190
|
+
|
|
191
|
+
@property({type: Boolean, reflect: true})
|
|
192
|
+
enableShiftDragZoom = true
|
|
193
|
+
|
|
194
|
+
@property({type: Boolean, reflect: true})
|
|
195
|
+
showZoomButtons = false
|
|
196
|
+
|
|
197
|
+
@property({type: Boolean, reflect: true})
|
|
198
|
+
errorDialogsActive = true
|
|
199
|
+
|
|
200
|
+
@property({type: Boolean, reflect: true})
|
|
201
|
+
showMenuBar = false
|
|
202
|
+
|
|
203
|
+
@property({type: Boolean, reflect: true})
|
|
204
|
+
showToolBar = false
|
|
205
|
+
|
|
206
|
+
@property({type: Boolean, reflect: true})
|
|
207
|
+
showToolBarHelp = false
|
|
208
|
+
|
|
209
|
+
@property({type: String, reflect: true})
|
|
210
|
+
customToolBar: string
|
|
211
|
+
|
|
212
|
+
@property({type: Boolean, reflect: true})
|
|
213
|
+
showAlgebraInput = true
|
|
214
|
+
|
|
215
|
+
@property({type: Boolean, reflect: true})
|
|
216
|
+
showResetIcon = false
|
|
217
|
+
|
|
218
|
+
@property({type: String, reflect: true})
|
|
219
|
+
language: String
|
|
220
|
+
|
|
221
|
+
@property({type: String, reflect: true})
|
|
222
|
+
country: String
|
|
223
|
+
|
|
224
|
+
@property({type: String, reflect: true})
|
|
225
|
+
appletId: String
|
|
226
|
+
|
|
227
|
+
@property({type: Boolean, reflect: true})
|
|
228
|
+
allowStyleBar = false
|
|
229
|
+
|
|
230
|
+
@property({type: Boolean, reflect: true})
|
|
231
|
+
randomize = true
|
|
232
|
+
|
|
233
|
+
@property({type: Number, reflect: true})
|
|
234
|
+
randomSeed: number
|
|
235
|
+
|
|
236
|
+
@property({type: Boolean, reflect: true})
|
|
237
|
+
useBrowserForJs = false
|
|
238
|
+
|
|
239
|
+
@property({type: Boolean, reflect: true})
|
|
240
|
+
showLogging = false
|
|
241
|
+
|
|
242
|
+
@property({type: Number, reflect: true})
|
|
243
|
+
capturingThreshold = 3
|
|
244
|
+
|
|
245
|
+
@property({type: Boolean, reflect: true})
|
|
246
|
+
enableFileFeatures = true
|
|
247
|
+
|
|
248
|
+
@property({type: Boolean, reflect: true})
|
|
249
|
+
enableUndoRedo = true
|
|
250
|
+
|
|
251
|
+
@property({type: String, reflect: true})
|
|
252
|
+
perspective: String
|
|
253
|
+
|
|
254
|
+
@property({type: Boolean, reflect: true})
|
|
255
|
+
enable3d: boolean
|
|
256
|
+
|
|
257
|
+
@property({type: Boolean, reflect: true})
|
|
258
|
+
enableCAS: boolean
|
|
259
|
+
|
|
260
|
+
@property({type: String, reflect: true})
|
|
261
|
+
algebraInputPosition: "algebra" | "top" | "bottom"
|
|
262
|
+
|
|
263
|
+
@property({type: Boolean, reflect: true})
|
|
264
|
+
preventFocus = false
|
|
265
|
+
|
|
266
|
+
@property({type: String, reflect: true})
|
|
267
|
+
scaleContainerClass: string
|
|
268
|
+
|
|
269
|
+
@property({type: Boolean, reflect: true})
|
|
270
|
+
autoHeight = true
|
|
271
|
+
|
|
272
|
+
@property({type: Boolean, reflect: true})
|
|
273
|
+
allowUpscale = false
|
|
274
|
+
|
|
275
|
+
@property({type: Boolean, reflect: true})
|
|
276
|
+
playButton = false
|
|
277
|
+
|
|
278
|
+
@property({type: Number, reflect: true})
|
|
279
|
+
scale = 1
|
|
280
|
+
|
|
281
|
+
@property({type: Boolean, reflect: true})
|
|
282
|
+
showAnimationButton = false
|
|
283
|
+
|
|
284
|
+
@property({type: Boolean, reflect: true})
|
|
285
|
+
showFullscreenButton = false
|
|
286
|
+
|
|
287
|
+
@property({type: Boolean, reflect: true})
|
|
288
|
+
showSuggestionButtons = false
|
|
289
|
+
|
|
290
|
+
@property({type: Boolean, reflect: true})
|
|
291
|
+
showStartTooltip = false
|
|
292
|
+
|
|
293
|
+
@property({type: String, reflect: true})
|
|
294
|
+
rounding: string
|
|
295
|
+
|
|
296
|
+
@property({type: Boolean, reflect: true})
|
|
297
|
+
buttonShadows = false
|
|
298
|
+
|
|
299
|
+
@property({type: Number, reflect: true})
|
|
300
|
+
buttonRounding: Number = 0.2
|
|
301
|
+
|
|
302
|
+
@property({type: String, reflect: true})
|
|
303
|
+
buttonBorderColor: string
|
|
304
|
+
|
|
305
|
+
@property({type: String, reflect: true})
|
|
306
|
+
editorBackgroundColor: string
|
|
307
|
+
|
|
308
|
+
@property({type: String, reflect: true})
|
|
309
|
+
editorForegroundColor: string
|
|
310
|
+
|
|
311
|
+
@property({type: Boolean, reflect: true})
|
|
312
|
+
textmode = false
|
|
313
|
+
|
|
314
|
+
@property({type: Boolean, reflect: true})
|
|
315
|
+
showKeyboardOnFocus: boolean
|
|
316
|
+
|
|
317
|
+
@property({type: String, reflect: true})
|
|
318
|
+
keyboardType: "scientific" | "normal" | "notes"
|
|
319
|
+
|
|
320
|
+
@property({type: Boolean, reflect: true})
|
|
321
|
+
transparentGraphics = false
|
|
322
|
+
|
|
323
|
+
@property({type: Boolean, reflect: true})
|
|
324
|
+
disabledJavaScript = false
|
|
325
|
+
|
|
326
|
+
@property({type: String, reflect: true})
|
|
327
|
+
detachedKeyboardParent: string
|
|
328
|
+
|
|
329
|
+
private get ggbProperties() {
|
|
330
|
+
const {appletId: id, type: appName, width, height, borderColor, borderRadius, enableLabelDrags, enableShiftDragZoom, showZoomButtons, errorDialogsActive, showMenuBar, showToolBar, showToolBarHelp, customToolBar, showAlgebraInput, showResetIcon, language, country, allowStyleBar, randomize, randomSeed, useBrowserForJs, showLogging, capturingThreshold, enableFileFeatures, perspective, enable3d, enableCAS, algebraInputPosition, preventFocus, scaleContainerClass, autoHeight, allowUpscale, playButton, scale, showAnimationButton, showFullscreenButton, showSuggestionButtons, showStartTooltip, rounding, buttonShadows, buttonRounding, buttonBorderColor, editorBackgroundColor, editorForegroundColor, textmode, showKeyboardOnFocus, keyboardType, transparentGraphics, disabledJavaScript, detachedKeyboardParent} = this
|
|
331
|
+
|
|
332
|
+
let filename: string, material_id: string, ggbBase64: string
|
|
333
|
+
if(this.src && this.src.startsWith("data:")) {
|
|
334
|
+
ggbBase64 = this.src.split(",").at(-1)
|
|
335
|
+
}
|
|
336
|
+
else if(this.src && this.src.startsWith("ggbid:")) {
|
|
337
|
+
material_id = this.src.slice("ggbid:".length)
|
|
338
|
+
}
|
|
339
|
+
else if(this.src) {
|
|
340
|
+
filename = this.src
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
return {id, appName, filename, material_id, ggbBase64, width, height, borderColor, borderRadius, enableLabelDrags, enableShiftDragZoom, showZoomButtons, errorDialogsActive, showMenuBar, showToolBar, showToolBarHelp, customToolBar, showAlgebraInput, showResetIcon, language: language ?? this.lang, country, allowStyleBar, randomize, randomSeed, useBrowserForJs, showLogging, capturingThreshold, enableFileFeatures, perspective, enable3d, enableCAS, algebraInputPosition, preventFocus, scaleContainerClass, autoHeight, allowUpscale, playButton, scale, showAnimationButton, showFullscreenButton, showSuggestionButtons, showStartTooltip, rounding, buttonShadows, buttonRounding, buttonBorderColor, editorBackgroundColor, editorForegroundColor, textmode, showKeyboardOnFocus, keyboardType, transparentGraphics, disabledJavaScript, detachedKeyboardParent}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
updateSrc = () => {
|
|
347
|
+
if(!this.updatingGgb) {
|
|
348
|
+
this.src = `data:application/vnd.geogebra.file;base64,${this.api.getBase64()}`
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
connectedCallback(): void {
|
|
353
|
+
super.connectedCallback()
|
|
354
|
+
this.apiReady = new Promise(r => {
|
|
355
|
+
this.addEventListener("ggb-load", (e: any) => {
|
|
356
|
+
r(e.detail.api)
|
|
357
|
+
this.api = e.detail.api
|
|
358
|
+
this.api.registerAddListener(this.updateSrc)
|
|
359
|
+
this.api.registerClearListener(this.updateSrc)
|
|
360
|
+
this.api.registerUpdateListener(this.updateSrc)
|
|
361
|
+
this.api.registerRenameListener(this.updateSrc)
|
|
362
|
+
this.api.registerRemoveListener(this.updateSrc)
|
|
363
|
+
})
|
|
364
|
+
})
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
updatingGgb = false
|
|
368
|
+
|
|
369
|
+
protected updated(changed: PropertyValues): void {
|
|
370
|
+
|
|
371
|
+
if(changed.has("src") && this.src && this.src.split(",").at(-1) !== this?.api?.getBase64()) {
|
|
372
|
+
this.updatingGgb = true
|
|
373
|
+
this?.api?.setBase64(this.src.split(",").at(-1), () => this.updatingGgb = false)
|
|
374
|
+
}
|
|
375
|
+
else if(changed.has("src") && !this.src) {
|
|
376
|
+
this.updatingGgb = true
|
|
377
|
+
this?.api?.setBase64("", () => this.updatingGgb = false)
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
apiReady: Promise<GeogebraAPI>
|
|
382
|
+
api?: GeogebraAPI
|
|
383
|
+
|
|
384
|
+
initializeIFrame(e: Event) {
|
|
385
|
+
const iframe = e.target as HTMLIFrameElement
|
|
386
|
+
const doc = iframe.contentDocument
|
|
387
|
+
const win = iframe.contentWindow
|
|
388
|
+
doc.body.style.margin = "0"
|
|
389
|
+
if(this.ggbStyles) {
|
|
390
|
+
const style = doc.createElement("style")
|
|
391
|
+
style.textContent = this.ggbStyles
|
|
392
|
+
doc.head.append(style)
|
|
393
|
+
}
|
|
394
|
+
doc.body.addEventListener("focusin", () => this.dispatchEvent(new FocusEvent("focus", {bubbles: true, composed: true})))
|
|
395
|
+
const ggbEl = doc.createElement("div")
|
|
396
|
+
ggbEl.id = "ggb-element"
|
|
397
|
+
doc.body.append(ggbEl);
|
|
398
|
+
const deployScript = doc.createElement("script")
|
|
399
|
+
deployScript.src = "https://www.geogebra.org/apps/deployggb.js"
|
|
400
|
+
deployScript.addEventListener("load", () => {
|
|
401
|
+
const createScript = doc.createElement("script")
|
|
402
|
+
createScript.textContent = `
|
|
403
|
+
const applet = new GGBApplet({${JSON.stringify(this.ggbProperties).slice(1, -1)}, appletOnLoad: api => document.dispatchEvent(new CustomEvent("ggb-load", {bubbles: true, composed: true, detail: {api}}))})
|
|
404
|
+
applet.inject("ggb-element")
|
|
405
|
+
`
|
|
406
|
+
doc.addEventListener("ggb-load", (e: any) => this.dispatchEvent(new CustomEvent("ggb-load", {bubbles: true, composed: true, detail: e.detail})))
|
|
407
|
+
doc.body.append(createScript)
|
|
408
|
+
})
|
|
409
|
+
doc.body.append(deployScript)
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
render() {
|
|
413
|
+
return html`
|
|
414
|
+
<iframe id="ggb" @load=${this.initializeIFrame}></iframe>
|
|
415
|
+
`
|
|
416
|
+
}
|
|
417
417
|
}
|