@webwriter/geogebra 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (160) hide show
  1. package/.github/workflows/main.yml +8 -0
  2. package/LICENSE +6 -6
  3. package/README.md +629 -0
  4. package/assets/icons/file-earmark-arrow-up.svg +4 -0
  5. package/components/geogebra-app.styles.ts +10 -0
  6. package/components/geogebra-app.ts +751 -416
  7. package/components/geogebra-options.styles.ts +37 -0
  8. package/components/geogebra-options.ts +187 -0
  9. package/custom-elements.json +10518 -0
  10. package/custom.d.ts +179 -179
  11. package/dist/widgets/webwriter-geogebra-3d.css +444 -0
  12. package/dist/widgets/webwriter-geogebra-3d.js +25359 -1408
  13. package/dist/widgets/webwriter-geogebra-classic.css +444 -0
  14. package/dist/widgets/webwriter-geogebra-classic.js +25359 -1408
  15. package/dist/widgets/webwriter-geogebra-geometry.css +444 -0
  16. package/dist/widgets/webwriter-geogebra-geometry.js +25359 -1408
  17. package/dist/widgets/webwriter-geogebra-notes.css +444 -0
  18. package/dist/widgets/webwriter-geogebra-notes.js +25359 -1408
  19. package/dist/widgets/webwriter-geogebra-scientific.css +444 -0
  20. package/dist/widgets/webwriter-geogebra-scientific.js +25359 -1408
  21. package/dist/widgets/webwriter-geogebra.css +444 -0
  22. package/dist/widgets/webwriter-geogebra.js +25370 -1413
  23. package/editing-config.json +37 -0
  24. package/lit-localize.json +47 -0
  25. package/localization/ar.xlf +30 -0
  26. package/localization/bg.xlf +30 -0
  27. package/localization/cs.xlf +30 -0
  28. package/localization/da.xlf +30 -0
  29. package/localization/de.xlf +29 -0
  30. package/localization/el.xlf +30 -0
  31. package/localization/es.xlf +30 -0
  32. package/localization/et.xlf +30 -0
  33. package/localization/fi.xlf +30 -0
  34. package/localization/fr.xlf +30 -0
  35. package/localization/generated/ar.ts +22 -0
  36. package/localization/generated/bg.ts +22 -0
  37. package/localization/generated/cs.ts +22 -0
  38. package/localization/generated/da.ts +22 -0
  39. package/localization/generated/de.ts +21 -0
  40. package/localization/generated/el.ts +22 -0
  41. package/localization/generated/es.ts +22 -0
  42. package/localization/generated/et.ts +22 -0
  43. package/localization/generated/fi.ts +22 -0
  44. package/localization/generated/fr.ts +22 -0
  45. package/localization/generated/hu.ts +22 -0
  46. package/localization/generated/id.ts +22 -0
  47. package/localization/generated/index.js +3 -0
  48. package/localization/generated/it.ts +22 -0
  49. package/localization/generated/ja.ts +22 -0
  50. package/localization/generated/ko.ts +22 -0
  51. package/localization/generated/locale-codes.js +83 -0
  52. package/localization/generated/lt.ts +22 -0
  53. package/localization/generated/lv.ts +22 -0
  54. package/localization/generated/nb.ts +22 -0
  55. package/localization/generated/nl.ts +22 -0
  56. package/localization/generated/pl.ts +22 -0
  57. package/localization/generated/pt-BR.ts +22 -0
  58. package/localization/generated/pt-PT.ts +22 -0
  59. package/localization/generated/ro.ts +22 -0
  60. package/localization/generated/ru.ts +22 -0
  61. package/localization/generated/sk.ts +22 -0
  62. package/localization/generated/sl.ts +22 -0
  63. package/localization/generated/sv.ts +22 -0
  64. package/localization/generated/tr.ts +22 -0
  65. package/localization/generated/uk.ts +22 -0
  66. package/localization/generated/zh-hans.ts +20 -0
  67. package/localization/generated/zh-hant.ts +20 -0
  68. package/localization/hu.xlf +30 -0
  69. package/localization/id.xlf +30 -0
  70. package/localization/it.xlf +30 -0
  71. package/localization/ja.xlf +30 -0
  72. package/localization/ko.xlf +30 -0
  73. package/localization/lt.xlf +30 -0
  74. package/localization/lv.xlf +30 -0
  75. package/localization/nb.xlf +30 -0
  76. package/localization/nl.xlf +30 -0
  77. package/localization/pkg/ar.xliff +6 -0
  78. package/localization/pkg/bg.xliff +6 -0
  79. package/localization/pkg/cs.xliff +6 -0
  80. package/localization/pkg/da.xliff +6 -0
  81. package/localization/pkg/de.xliff +6 -0
  82. package/localization/pkg/el.xliff +6 -0
  83. package/localization/pkg/es.xliff +6 -0
  84. package/localization/pkg/et.xliff +6 -0
  85. package/localization/pkg/fi.xliff +6 -0
  86. package/localization/pkg/fr.xliff +6 -0
  87. package/localization/pkg/hu.xliff +6 -0
  88. package/localization/pkg/id.xliff +6 -0
  89. package/localization/pkg/it.xliff +6 -0
  90. package/localization/pkg/ja.xliff +6 -0
  91. package/localization/pkg/ko.xliff +6 -0
  92. package/localization/pkg/lt.xliff +6 -0
  93. package/localization/pkg/lv.xliff +6 -0
  94. package/localization/pkg/nb.xliff +6 -0
  95. package/localization/pkg/nl.xliff +6 -0
  96. package/localization/pkg/pl.xliff +6 -0
  97. package/localization/pkg/pt-BR.xliff +6 -0
  98. package/localization/pkg/pt-PT.xliff +6 -0
  99. package/localization/pkg/ro.xliff +6 -0
  100. package/localization/pkg/ru.xliff +6 -0
  101. package/localization/pkg/sk.xliff +6 -0
  102. package/localization/pkg/sl.xliff +6 -0
  103. package/localization/pkg/sv.xliff +6 -0
  104. package/localization/pkg/tr.xliff +6 -0
  105. package/localization/pkg/uk.xliff +6 -0
  106. package/localization/pkg/zh-hans.xliff +6 -0
  107. package/localization/pkg/zh-hant.xliff +6 -0
  108. package/localization/pl.xlf +30 -0
  109. package/localization/pt-BR.xlf +30 -0
  110. package/localization/pt-PT.xlf +30 -0
  111. package/localization/ro.xlf +30 -0
  112. package/localization/ru.xlf +30 -0
  113. package/localization/sk.xlf +30 -0
  114. package/localization/sl.xlf +30 -0
  115. package/localization/snippets/ar.xliff +4 -0
  116. package/localization/snippets/bg.xliff +4 -0
  117. package/localization/snippets/cs.xliff +4 -0
  118. package/localization/snippets/da.xliff +4 -0
  119. package/localization/snippets/de.xliff +4 -0
  120. package/localization/snippets/el.xliff +4 -0
  121. package/localization/snippets/es.xliff +4 -0
  122. package/localization/snippets/et.xliff +4 -0
  123. package/localization/snippets/fi.xliff +4 -0
  124. package/localization/snippets/fr.xliff +4 -0
  125. package/localization/snippets/hu.xliff +4 -0
  126. package/localization/snippets/id.xliff +4 -0
  127. package/localization/snippets/it.xliff +4 -0
  128. package/localization/snippets/ja.xliff +4 -0
  129. package/localization/snippets/ko.xliff +4 -0
  130. package/localization/snippets/lt.xliff +4 -0
  131. package/localization/snippets/lv.xliff +4 -0
  132. package/localization/snippets/nb.xliff +4 -0
  133. package/localization/snippets/nl.xliff +4 -0
  134. package/localization/snippets/pl.xliff +4 -0
  135. package/localization/snippets/pt-BR.xliff +4 -0
  136. package/localization/snippets/pt-PT.xliff +4 -0
  137. package/localization/snippets/ro.xliff +4 -0
  138. package/localization/snippets/ru.xliff +4 -0
  139. package/localization/snippets/sk.xliff +4 -0
  140. package/localization/snippets/sl.xliff +4 -0
  141. package/localization/snippets/sv.xliff +4 -0
  142. package/localization/snippets/tr.xliff +4 -0
  143. package/localization/snippets/uk.xliff +4 -0
  144. package/localization/snippets/zh-hans.xliff +4 -0
  145. package/localization/snippets/zh-hant.xliff +4 -0
  146. package/localization/sv.xlf +30 -0
  147. package/localization/tr.xlf +30 -0
  148. package/localization/uk.xlf +30 -0
  149. package/localization/zh-hans.xlf +30 -0
  150. package/localization/zh-hant.xlf +30 -0
  151. package/package.json +163 -165
  152. package/tsconfig.json +7 -7
  153. package/utils/boolean-attribute-converter.ts +8 -0
  154. package/widgets/webwriter-geogebra-3d.ts +14 -8
  155. package/widgets/webwriter-geogebra-classic.ts +14 -8
  156. package/widgets/webwriter-geogebra-evaluator.ts +14 -8
  157. package/widgets/webwriter-geogebra-geometry.ts +14 -8
  158. package/widgets/webwriter-geogebra-notes.ts +14 -8
  159. package/widgets/webwriter-geogebra-scientific.ts +14 -8
  160. package/widgets/webwriter-geogebra.ts +28 -19
@@ -1,417 +1,752 @@
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 {html, css, PropertyValues, PropertyDeclaration} from "lit"
2
+ import {LitElementWw} from "@webwriter/lit"
3
+ import {property} from "lit/decorators.js"
4
+ import {keyed} from "lit/directives/keyed.js"
5
+
6
+ import "@shoelace-style/shoelace/dist/themes/light.css"
7
+
8
+ // @ts-ignore
9
+ import LOCALIZE from "../localization/generated"
10
+ import {localized, msg} from "@lit/localize"
11
+ import {geogebraAppStyles} from "./geogebra-app.styles"
12
+ import { booleanAttributeConverter } from "../utils/boolean-attribute-converter"
13
+ import { GeogebraOptions, type PropertyConfig } from "./geogebra-options"
14
+
15
+ export interface GeogebraAPI {
16
+ evalCommand(cmdString: string): boolean
17
+ evalLaTex(input: string): boolean
18
+ evalCommandGetLabels(cmdString: string): string
19
+ evalCommandCAS(text: string): string
20
+ insertEmbed(type: string, uri: string): void
21
+ deleteObject(objName: string): void
22
+ setAuxiliary(geo: any, status: boolean): void
23
+ setValue(objName: string, value: number): void
24
+ setTextValue(objName: string, value: string): void
25
+ setListValue(objName: string, i: number, value: number): void
26
+ setCoords(objName: string, x: number, y: number, z?: number): void
27
+ setCaption(objName: string, caption: string): void
28
+ setColor(objName: string, red: number, green: number, blue: number): void
29
+ setVisible(objName: string, visible: boolean): void
30
+ setLabelVisible(objName: string, visible: boolean): void
31
+ setLabelStyle(objName: string, style: 0 | 1 | 2 | 3): void
32
+ setFixed(objName: string, fixed: boolean, selectionAllowed: boolean): void
33
+ setTrace(objName: string, flag: boolean): void
34
+ renameObject(oldObjName: string, newObjName: string): boolean
35
+ setLayer(objName: string, layer: number): void
36
+ setLayerVisible(objName: string, visible: boolean): void
37
+ setLineStyle(objName: string, style: 0 | 1 | 2 | 3 | 4): void
38
+ setLineThickness(objName: string, thickness: -1 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13): void
39
+ setPointStyle(objName: string, size: -1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9): void
40
+ setPointSize(objName: string, size: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9): void
41
+ setDisplayStyle(objName: string, style: string): void
42
+ setFilling(objName: string, filling: number): void
43
+ getPNGBase64(exportScale: number, transparent?: boolean, dpi?: number): string
44
+ exportSVG(filename: string): void
45
+ exportSVG(callback: CallableFunction): void
46
+ exportPDF(scale: number, filename: string, sliderLabel?: string): void
47
+ exportPDF(scale: number, callback: CallableFunction, sliderLabel?: string): void
48
+ getScreenshotBase64(callback: CallableFunction): void
49
+ writePNGtoFile(fileName: string, exportScale?: number, transparent?: boolean, dpi?: number): boolean
50
+ isIndependent(objName: string): boolean
51
+ isMovable(objName: string): boolean
52
+ showAllObjects(): void
53
+ registerEmbedResolver(type: string, callback: CallableFunction): void
54
+ setAnimating(objName: string, animate: boolean): void
55
+ setAnimationSpeed(objName: string, speed: number): void
56
+ startAnimation(): void
57
+ stopAnimation(): void
58
+ isAnimationRunning(): boolean
59
+ getXcoord(objName: string): number
60
+ getYcoord(objName: string): number
61
+ getZcoord(objName: string): number
62
+ getValue(objName: string): number
63
+ getListValue(objName: string, index: number): number
64
+ getColor(objName: string): string
65
+ getVisible(objName: string): boolean
66
+ getValueString(objName: string, useLocalizedInput?: boolean): string
67
+ getDefinitionString(objName: string): string
68
+ getCommandString(objName: string, useLocalizedInput?: boolean): string
69
+ getLaTeXString(objName: string, value: boolean): string
70
+ getObjectType(objName: string): string
71
+ exists(objName: string): boolean
72
+ isDefined(objName: string): boolean
73
+ getAllObjectNames(type?: string): string[]
74
+ getObjectNumber(): number
75
+ getCASObjectNumber(): number
76
+ getObjectName(i: number): string
77
+ getLayer(objName: string): string
78
+ getLineStyle(objName: string): 0 | 1 | 2 | 3 | 4
79
+ getLineThickness(objName: string): -1 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13
80
+ getPointStyle(objName: string): -1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
81
+ getPointSize(objName: string): 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
82
+ getFilling(objName: string): number
83
+ getCaption(objName: string, substitutePlaceholders?: boolean): string
84
+ getLabelStyle(objName: string): 0 | 1 | 2 | 3
85
+ getLabelVisible(): boolean
86
+ isInteractive(objName: string): boolean
87
+ setMode(mode: number): void
88
+ getMode(): number
89
+ reset(): void
90
+ newConstruction(): void
91
+ refreshViews(): void
92
+ setOnTheFlyPointCreationActive(flag: boolean): void
93
+ setPointCapture(view: -1 | 1 | 2, mode: 0 | 1 | 2 | 3): void
94
+ setRounding(round: string): void
95
+ hideCursorWhenDragging(flag: boolean): void
96
+ setRepaintingActive(flag: boolean): void
97
+ setErrorDialogsActive(flag: boolean): void
98
+ setCoordSystem(xmin: number, xmax: number, ymin: number, ymax: number, zmin?: number, zmax?: number, yVertical?: boolean): void
99
+ setAxesVisible(xAxis: boolean, yAxis: boolean, zAxis?: boolean): void
100
+ setUndoPoint(): void
101
+ setAxisLabels(viewNumber: number, xAxis: string, yAxis: string, zAxis: string): void
102
+ setAxisSteps(viewNumber: number, xAxis: number, yAxis: number, zAxis: number): void
103
+ setAxisUnits(viewNumber: number, xAxis: string, yAxis: string, zAxis: string): void
104
+ setGridVisible(flag: boolean): void
105
+ setGridVisible(viewNumber: number, flag: boolean): void
106
+ getGridVisible(viewNumber: number): boolean
107
+ getPerspectiveXML(): string
108
+ undo(): void
109
+ redo(): void
110
+ showToolBar(show: boolean): void
111
+ setCustomToolBar(toolbar: string): void
112
+ addCustomTool(iconURL: string, name: string, category?: string, callback?: CallableFunction): void
113
+ showMenuBar(show: boolean): void
114
+ showAlgebraInput(show: boolean): void
115
+ showResetIcon(show: boolean): void
116
+ enableRightClick(enable: boolean): void
117
+ enableLabelDrags(enable: boolean): void
118
+ enableShiftDragZoom(enable: boolean): void
119
+ enableCAS(enable: boolean): void
120
+ enable3D(enable: boolean): void
121
+ setPerspective(perspective: string): void
122
+ setWidth(width: number): void
123
+ setHeight(height: number): void
124
+ setSize(width: number, height: number): void
125
+ recalculateEnvironments(): void
126
+ getEditorState(): any
127
+ setEditorState(state: any): void
128
+ getGraphicsOptions(viewId: number): any
129
+ setGraphicsOptions(viewID: number, options: any): void
130
+ setAlgebraOptions(options: any): void
131
+ registerAddListener(func: CallableFunction): void
132
+ unregisterAddListener(func: CallableFunction): void
133
+ registerRemoveListener(func: CallableFunction): void
134
+ unregisterRemoveListener(func: CallableFunction): void
135
+ registerUpdateListener(func: CallableFunction): void
136
+ unregisterUpdateListener(func: CallableFunction): void
137
+ registerClickListener(func: CallableFunction): void
138
+ unregisterClickListener(func: CallableFunction): void
139
+ registerObjectUpdateListener(objName: string, func: CallableFunction): void
140
+ unregisterObjectUpdateListener(objName: string): void
141
+ registerObjectClickListener(objName: string, func: CallableFunction): void
142
+ unregisterObjectClickListener(objName: string): void
143
+ registerRenameListener(func: CallableFunction): void
144
+ unregisterRenameListener(func: CallableFunction): void
145
+ registerClearListener(func: CallableFunction): void
146
+ unregisterClearListener(func: CallableFunction): void
147
+ registerStoreUndoListener(func: CallableFunction): void
148
+ unregisterStoreUndoListener(func: CallableFunction): void
149
+ registerClientListener(func: CallableFunction): void
150
+ unregisterClientListener(func: CallableFunction): void
151
+ evalXML(xmlString: string): void
152
+ setXML(xmlString: string): void
153
+ getXML(objName?: string): string
154
+ getAlgorithmXML(objName: string): string
155
+ getFileJSON(): any
156
+ setFileJSON(content: any): void
157
+ getBase64(callback?: CallableFunction): string
158
+ setBase64(value: string, callback?: CallableFunction): void
159
+ debug(str: string): void
160
+ getVersion(): string
161
+ remove(): void
162
+ }
163
+
164
+ /**
165
+ * @fires focus - Fired when the GeoGebra applet gains focus.
166
+ * @fires ggb-load - Fired when the GeoGebra API is ready. The event detail contains the API instance.
167
+ */
168
+ @localized()
169
+ export class GeogebraApp extends LitElementWw {
170
+ protected localize = LOCALIZE
171
+
172
+ protected static get scopedElements() {
173
+ return {
174
+ "geogebra-options-panel": GeogebraOptions
175
+ }
176
+ }
177
+
178
+ static styles = geogebraAppStyles
179
+
180
+ /**
181
+ * Custom CSS styles to apply to the GeoGebra applet.
182
+ */
183
+ @property({type: String})
184
+ accessor ggbStyles: string = css`
185
+ .GeoGebraFrame .toolbar .header-open-landscape .center, .GeoGebraFrame .toolbar .header-close-landscape .center {
186
+ top: 0 !important;
187
+ }
188
+ `.cssText
189
+
190
+ /**
191
+ * app name, default: "classic". "graphing" …​ GeoGebra Graphing Calculator "geometry" …​ GeoGebra Geometry "3d" …​ GeoGebra 3D Graphing Calculator "classic" …​ GeoGebra Classic "suite" …​ GeoGebra Calculator Suite "evaluator" …​ Equation Editor "scientific" …​Scientific Calculator "notes" …​ GeoGebra Notes
192
+ */
193
+ @property({type: String, attribute: true, reflect: true})
194
+ accessor type: "classic" | "geometry" | "3d" | "suite" | "evaluator" | "scientific" | "notes" = "classic"
195
+
196
+ /**
197
+ * Applet width
198
+ */
199
+ @property({type: Number, attribute: true, reflect: true})
200
+ accessor width: number = 800
201
+
202
+ /**
203
+ * Applet height
204
+ */
205
+ @property({type: Number, attribute: true, reflect: true})
206
+ accessor height: number = 450
207
+
208
+ /**
209
+ * Source of the GeoGebra file to load (base64-encoded string, material ID prefixed with "ggbid:", or file URL)
210
+ */
211
+ @property({type: String, attribute: true, reflect: true})
212
+ accessor src: string
213
+
214
+ /**
215
+ * Color of the border line drawn around the applet panel (as hex rgb string). Default: gray
216
+ */
217
+ @property({type: String, attribute: true, reflect: true})
218
+ accessor borderColor: string = "gray"
219
+
220
+ /**
221
+ * Size of applet's border radius in pixels.
222
+ */
223
+ @property({type: Number, attribute: true, reflect: true})
224
+ accessor borderRadius: number = 1
225
+
226
+ /**
227
+ * States whether right clicks should be handled by the applet. Setting this parameter to "false" disables context menus, properties dialogs and right-click-zooming. Default: true. NB also enables/disables some keyboard shortcuts eg Delete and Ctrl + R (recompute all objects). Default: true
228
+ */
229
+ @property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
230
+ accessor enableRightClick = true
231
+
232
+ /**
233
+ * States whether labels can be dragged. Default: true
234
+ */
235
+ @property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
236
+ accessor enableLabelDrags = true
237
+
238
+ /**
239
+ * States whether the Graphics View(s) should be moveable using Shift mouse drag (or. Ctrl + mouse drag) or zoomable using Shift + mouse wheel (or Ctrl + mouse wheel). Setting this parameter to "false" disables moving and zooming of the drawing pad. Default: true
240
+ */
241
+ @property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
242
+ accessor enableShiftDragZoom = true
243
+
244
+ /**
245
+ * States whether the zoom in / zoom out / home buttons should be shown in the Graphics View or not. Default: false
246
+ */
247
+ @property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
248
+ accessor showZoomButtons = false
249
+
250
+ /**
251
+ * States whether error dialogs will be shown if an invalid input is entered (using the Input Bar or JavaScript) Default: true
252
+ */
253
+ @property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
254
+ accessor errorDialogsActive = true
255
+
256
+ /**
257
+ * States whether the menubar of GeoGebra should be shown in the applet. Default: false
258
+ */
259
+ @property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
260
+ accessor showMenuBar = false
261
+
262
+ /**
263
+ * States whether the toolbar with the construction mode buttons should be shown in the applet. Default: false
264
+ */
265
+ @property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
266
+ accessor showToolBar = true
267
+
268
+ /**
269
+ * States whether the toolbar help text right to the toolbar buttons should be shown in the applet
270
+ */
271
+ @property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
272
+ accessor showToolBarHelp = false
273
+
274
+ /**
275
+ * Sets the toolbar according to a custom toolbar string where the int values are Toolbar Mode Values, `,` adds a separator within a menu, `|` starts a new menu and `||` adds a separator in the toolbar before starting a new menu. This will override the saved toolbar from the .ggb file / base64 string. Custom tools are numbered 100 001, 100 002, etc
276
+ */
277
+ @property({type: String, attribute: true, reflect: true})
278
+ accessor customToolBar: string
279
+
280
+ /**
281
+ * States whether the algebra input line (with input field, greek letters and command list) should be shown in the applet. Default: false
282
+ */
283
+ @property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
284
+ accessor showAlgebraInput = true
285
+
286
+ /**
287
+ * States whether a small icon (GeoGebra ellipse) should be shown in the upper right corner of the applet. Clicking on this icon resets the applet (i.e. it reloads the file given in the filename parameter). Default: false
288
+ */
289
+ @property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
290
+ accessor showResetIcon = false
291
+
292
+ /**
293
+ * ISO language string. GeoGebra tries to set your local language automatically (if it is available among the supported languages, of course). The default language for unsupported languages is English. If you want to specify a certain language manually, please use this parameter.
294
+ */
295
+ @property({type: String, attribute: true, reflect: true})
296
+ accessor language: String
297
+
298
+ /**
299
+ * ISO country string. This parameter only makes sense if you use it together with the language parameter.
300
+ */
301
+ @property({type: String, attribute: true, reflect: true})
302
+ accessor country: String
303
+
304
+ /**
305
+ * This parameter allows you to specify the argument passed to the JavaScript function ggbOnInit(), which is called once the applet is fully initialised. This is useful when you have multiple applets on a page.
306
+ */
307
+ @property({type: String, attribute: true, reflect: true})
308
+ accessor appletId: String
309
+
310
+ /**
311
+ * Determines whether the Style Bar can be shown (or will be shown if just Graphics View 1 is showing). Default: false
312
+ */
313
+ @property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
314
+ accessor allowStyleBar = false
315
+
316
+ /**
317
+ * Determines whether random numbers should be randomized on file load. Useful when you want the app to reload in exactly the same state it was saved. Default: true
318
+ */
319
+ @property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
320
+ accessor randomize = true
321
+
322
+ /**
323
+ * Specify seed for random numbers. Note that if you save a state of the app after user interacted with it and try to reload that state with the same randomSeed, you may get a different result. Use randomize for those use-cases.
324
+ */
325
+ @property({type: Number, attribute: true, reflect: true})
326
+ accessor randomSeed: number
327
+
328
+ /**
329
+ * When true, GeoGebra: runs ggbOnInit from HTML, ignores ggbOnInit from file, and ignores JS update scripts of objects in file. When false, GeoGebra: ignores ggbOnInit from HTML (use appletOnLoad parameter of GGBApplet instead), runs ggbOnInit from file, and runs JS update scripts of objects in file. Default: false
330
+ */
331
+ @property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
332
+ accessor useBrowserForJs = false
333
+
334
+ /**
335
+ * Determines whether logging is shown in the Browser's console. Default: false
336
+ */
337
+ @property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
338
+ accessor showLogging = false
339
+
340
+ /**
341
+ * Determines the sensitivity of object selection. The default value of 3 is usually fine to select and drag objects both with the mouse and touch. Use larger values (e.g. 4 or 5) to make it easier to select and drag objects. Default: 3
342
+ */
343
+ @property({type: Number, attribute: true, reflect: true})
344
+ accessor capturingThreshold = 3
345
+
346
+ /**
347
+ * Determines whether file saving, file loading, sign in and Options > Save settings are enabled. This argument is ignored when menubar is not showing. Default: true
348
+ */
349
+ @property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
350
+ accessor enableFileFeatures = true
351
+
352
+ /**
353
+ * Determines whether Undo and Redo icons are shown. This argument is ignored when toolbar is not showing. Default: true
354
+ */
355
+ @property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
356
+ accessor enableUndoRedo = true
357
+
358
+ /**
359
+ * For values see SetPerspective_Command in the GeoGebra Manual. Just for a blank start ie shouldn't be used with material_id, filename or ggbBase64 parameters
360
+ */
361
+ @property({type: String, attribute: true, reflect: true})
362
+ accessor perspective: String
363
+
364
+ /**
365
+ * Whether 3D should be enabled (for exam mode).
366
+ */
367
+ @property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
368
+ accessor enable3d: boolean
369
+
370
+ /**
371
+ * Whether CAS should be enabled (for exam mode).
372
+ */
373
+ @property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
374
+ accessor enableCAS: boolean
375
+
376
+ /**
377
+ * Determines whether input bar should be shown in algebra, on top of the applet or under the applet. When left empty (default), the position depends on file.
378
+ */
379
+ @property({type: String, attribute: true, reflect: true})
380
+ accessor algebraInputPosition: "algebra" | "top" | "bottom"
381
+
382
+ /**
383
+ * When set to true, this prevents the applet from getting focus automatically at the start. Default: false
384
+ */
385
+ @property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
386
+ accessor preventFocus = false
387
+
388
+ /**
389
+ * Name of CSS class that is used as container; applet will scale to fit into the container.
390
+ */
391
+ @property({type: String, attribute: true, reflect: true})
392
+ accessor scaleContainerClass: string
393
+
394
+ /**
395
+ * `true` to restrict the width of the applet and compute height automatically, add autoHeight: true. `false` if you want the applet to be restricted by both width and height of the container
396
+ */
397
+ @property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
398
+ accessor autoHeight = true
399
+
400
+ /**
401
+ * Determines whether automatic scaling may scale the applet up. Default: false
402
+ */
403
+ @property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
404
+ accessor allowUpscale = false
405
+
406
+ /**
407
+ * Determines whether a preview image and a play button should be rendered in place of the applet. Pushing the play button initializes the applet. Default: false
408
+ */
409
+ @property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
410
+ accessor playButton = false
411
+
412
+ /**
413
+ * Ratio by which the applet should be scaled (eg. 2 makes the applet 2 times bigger, including all texts and UI elements). Default: 1
414
+ */
415
+ @property({type: Number, attribute: true, reflect: true})
416
+ accessor scale = 1
417
+
418
+ /**
419
+ * Whether animation button should be visible
420
+ */
421
+ @property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
422
+ accessor showAnimationButton = false
423
+
424
+ /**
425
+ * Whether fullscreen button should be visible
426
+ */
427
+ @property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
428
+ accessor showFullscreenButton = false
429
+
430
+ /**
431
+ * Whether suggestion buttons (special points, solve) in Algebra View should be visible
432
+ */
433
+ @property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
434
+ accessor showSuggestionButtons = false
435
+
436
+ /**
437
+ * Whether "Welcome" tooltip should be shown
438
+ */
439
+ @property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
440
+ accessor showStartTooltip = false
441
+
442
+ /**
443
+ * String composed of number of decimal places and flags — valid flags are "s" for significant digits and "r" for rational numbers. Hence "10" means 10 decimal places, "10s" stands for 10 significant digits.
444
+ */
445
+ @property({type: String, attribute: true, reflect: true})
446
+ accessor rounding: string
447
+
448
+ /**
449
+ * Whether buttons should have shadow
450
+ */
451
+ @property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
452
+ accessor buttonShadows = false
453
+
454
+ /**
455
+ * Relative radius of button's rounded border. The border radius in pixels is buttonRounding * height /2, where height is the height of the button. Default: 0.2
456
+ */
457
+ @property({type: Number, attribute: true, reflect: true})
458
+ accessor buttonRounding: Number = 0.2
459
+
460
+ /**
461
+ * Border color of buttons on the graphics view. Default is black, if the button background is white, otherwise one shade darker than the background color
462
+ */
463
+ @property({type: String, attribute: true, reflect: true})
464
+ accessor buttonBorderColor: string
465
+
466
+ /**
467
+ * Background color of the evaluator app
468
+ */
469
+ @property({type: String, attribute: true, reflect: true})
470
+ accessor editorBackgroundColor: string
471
+
472
+ /**
473
+ * Foreground (text) color of the equation editor (appname = "evaluator")
474
+ */
475
+ @property({type: String, attribute: true, reflect: true})
476
+ accessor editorForegroundColor: string
477
+
478
+ /**
479
+ * Whether editor is in text mode or not (appname = "evaluator"). Default: false
480
+ */
481
+ @property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
482
+ accessor textmode = false
483
+
484
+ /**
485
+ * Whether to show keyboard when input is focused. When set to true, keyboard is always shown, for false it never appears, for auto it's shown unless closed by user. Default: true in evaluator app, auto in other apps
486
+ */
487
+ @property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
488
+ accessor showKeyboardOnFocus: boolean
489
+
490
+ /**
491
+ * Which keyboard is shown for equation editor (appname = "evaluator")
492
+ */
493
+ @property({type: String, attribute: true, reflect: true})
494
+ accessor keyboardType: "scientific" | "normal" | "notes"
495
+
496
+ /**
497
+ * Whether the Graphics View and Graphics View 2 should be transparent
498
+ */
499
+ @property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
500
+ accessor transparentGraphics = false
501
+
502
+ /**
503
+ * Whether running JavaScript from material files is disabled or not.
504
+ */
505
+ @property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
506
+ accessor disabledJavaScript = false
507
+
508
+ /**
509
+ * When set, the keyboard should be attached to the first element in DOM that fits the selector.
510
+ */
511
+ @property({type: String, attribute: true, reflect: true})
512
+ accessor detachedKeyboardParent: string
513
+
514
+ /**
515
+ * Used to force reset of the applet. Increment this property to reset the applet.
516
+ */
517
+ @property({type: Number})
518
+ protected accessor resetKey: number = 0
519
+
520
+ // A map of parameter names to their corresponding update functions in the GeoGebra API
521
+ private paramUpdateMap: Map<string, (value: number | string | boolean) => void>
522
+
523
+ private getConfigurableProperties() {
524
+ const properties: PropertyConfig[] = []
525
+ const ownProperties = (this.constructor as any).elementProperties as Map<string, PropertyDeclaration>
526
+
527
+ const excludedProperties = new Set([
528
+ "contentEditable",
529
+ "lang",
530
+ "src",
531
+ "width",
532
+ "height",
533
+ "ggbStyles",
534
+ "resetKey"
535
+ ])
536
+
537
+ ownProperties.forEach((config, propName) => {
538
+ if (excludedProperties.has(propName)) return
539
+
540
+ const currentValue = (this as any)[propName]
541
+ let propConfig: PropertyConfig = {
542
+ name: propName,
543
+ type: "string",
544
+ value: currentValue
545
+ }
546
+
547
+ if (config.type === Boolean || typeof currentValue === "boolean") {
548
+ propConfig.type = "boolean"
549
+ } else if (config.type === Number || typeof currentValue === "number") {
550
+ propConfig.type = "number"
551
+ } else if (config.type === String || typeof currentValue === "string") {
552
+ const selectProps: Record<string, string[]> = {
553
+ "algebraInputPosition": ["algebra", "top", "bottom"],
554
+ "type": ["classic", "geometry", "3d", "suite", "evaluator", "scientific", "notes"],
555
+ "keyboardType": ["scientific", "normal", "notes"]
556
+ }
557
+
558
+ if (selectProps[propName]) {
559
+ propConfig.type = "select"
560
+ propConfig.options = selectProps[propName]
561
+ }
562
+ }
563
+
564
+ properties.push(propConfig)
565
+ })
566
+
567
+ return properties
568
+ }
569
+
570
+ private get ggbProperties() {
571
+ const {appletId: id, type: appName, width, height, borderColor, borderRadius, enableRightClick, 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
572
+
573
+ let filename: string, material_id: string, ggbBase64: string
574
+ if(this.src && this.src.startsWith("data:")) {
575
+ ggbBase64 = this.src.split(",").at(-1)
576
+ }
577
+ else if(this.src && this.src.startsWith("ggbid:")) {
578
+ material_id = this.src.slice("ggbid:".length)
579
+ }
580
+ else if(this.src) {
581
+ filename = this.src
582
+ }
583
+
584
+ return {id, appName, filename, material_id, ggbBase64, width, height, borderColor, borderRadius, enableRightClick, 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}
585
+ }
586
+
587
+ private updateSrc = (a) => {
588
+ console.log("updateSrc called", a)
589
+ if(!this.updatingGgb) {
590
+ this.src = `data:application/vnd.geogebra.file;base64,${this.api.getBase64()}`
591
+ }
592
+ }
593
+
594
+ connectedCallback(): void {
595
+ super.connectedCallback()
596
+ this.apiReady = new Promise(r => {
597
+ this.addEventListener("ggb-load", (e: any) => {
598
+ r(e.detail.api)
599
+ this.api = e.detail.api
600
+ this.api.registerAddListener(this.updateSrc)
601
+ this.api.registerClearListener(this.updateSrc)
602
+ this.api.registerUpdateListener(this.updateSrc)
603
+ this.api.registerRenameListener(this.updateSrc)
604
+ this.api.registerRemoveListener(this.updateSrc)
605
+
606
+ this.paramUpdateMap = new Map<string, (value: number | string | boolean) => void>([
607
+ ["width", this.api.setWidth],
608
+ ["height", this.api.setHeight],
609
+ ["enableRightClick", this.api.enableRightClick],
610
+ ["enableLabelDrags", this.api.enableLabelDrags],
611
+ ["enableShiftDragZoom", this.api.enableShiftDragZoom],
612
+ ["errorDialogsActive", this.api.setErrorDialogsActive],
613
+ // ["showMenuBar", this.api.showMenuBar], // disabled because showMenuBar(false) does not work
614
+ ["showToolBar", this.api.showToolBar],
615
+ ["customToolBar", this.api.setCustomToolBar],
616
+ ["showAlgebraInput", this.api.showAlgebraInput],
617
+ ["showResetIcon", this.api.showResetIcon],
618
+ ["perspective", this.api.setPerspective],
619
+ ["enable3d", this.api.enable3D],
620
+ ["enableCAS", this.api.enableCAS],
621
+ ["rounding", this.api.setRounding],
622
+ ])
623
+ })
624
+ })
625
+ }
626
+
627
+ private handlePropertyChange(e: CustomEvent) {
628
+ const {name, value} = e.detail;
629
+ (this as any)[name] = value
630
+ }
631
+
632
+ private handleFileImport(e: CustomEvent) {
633
+ const { base64 } = e.detail
634
+ this.src = `data:application/vnd.geogebra.file;base64,${base64}`
635
+ }
636
+
637
+ private updatingGgb = false
638
+
639
+ protected updated(changed: PropertyValues): void {
640
+ console.log("GeogebraApp updated:", changed)
641
+ super.updated(changed)
642
+
643
+ if(!this.api) {
644
+ this.resetIFrame()
645
+ return
646
+ }
647
+ if (this.paramUpdateMap) {
648
+ let needFullReload = false
649
+
650
+ changed.forEach((_, key: PropertyKey) => {
651
+ const propName = key.toString()
652
+ console.log(`Property changed: ${propName}`)
653
+ if(propName === "src") {
654
+ return
655
+ }
656
+ if(this.paramUpdateMap.has(propName) && this.api) {
657
+ const updateFunc = this.paramUpdateMap.get(propName)
658
+ if(updateFunc) {
659
+ updateFunc.call(this.api, (this as any)[propName])
660
+ console.log(`Updated GeoGebra property ${propName} to value ${(this as any)[propName]}`)
661
+ }
662
+ } else {
663
+ console.log(`No update function found for property: ${propName}, reloading entire applet...`)
664
+ needFullReload = true
665
+ }
666
+ })
667
+
668
+ if(needFullReload) {
669
+ this.resetIFrame()
670
+ return
671
+ }
672
+ }
673
+
674
+
675
+ if(!changed.has("src") || !this.api) {
676
+ return
677
+ }
678
+ if(this.src && this.src.split(",").at(-1) !== this?.api?.getBase64()) {
679
+ this.updatingGgb = true
680
+ this?.api?.setBase64(this.src.split(",").at(-1), () => {
681
+ this.updatingGgb = false
682
+ })
683
+ }
684
+ else if(!this.src) {
685
+ this.updatingGgb = true
686
+ this?.api?.setBase64("", () => {
687
+ this.updatingGgb = false
688
+ })
689
+ }
690
+ }
691
+
692
+ private apiReady: Promise<GeogebraAPI>
693
+ private api?: GeogebraAPI
694
+
695
+ private initializeIFrame(iframe: HTMLIFrameElement) {
696
+ const doc = iframe.contentDocument
697
+ const win = iframe.contentWindow
698
+ if (doc.getElementById("ggb-element")) {
699
+ return
700
+ }
701
+ doc.body.style.margin = "0"
702
+ if(this.ggbStyles) {
703
+ const style = doc.createElement("style")
704
+ style.textContent = this.ggbStyles
705
+ doc.head.append(style)
706
+ }
707
+ doc.body.addEventListener("focusin", () => this.dispatchEvent(new FocusEvent("focus", {bubbles: true, composed: true})))
708
+ const ggbEl = doc.createElement("div")
709
+ ggbEl.id = "ggb-element"
710
+ doc.body.append(ggbEl);
711
+ const deployScript = doc.createElement("script")
712
+ deployScript.src = "https://www.geogebra.org/apps/deployggb.js"
713
+ deployScript.addEventListener("load", () => {
714
+ const createScript = doc.createElement("script")
715
+ createScript.textContent = `
716
+ 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}}))})
717
+ applet.inject("ggb-element")
718
+ `
719
+ doc.addEventListener("ggb-load", (e: any) => this.dispatchEvent(new CustomEvent("ggb-load", {bubbles: true, composed: true, detail: e.detail})))
720
+ doc.body.append(createScript)
721
+ })
722
+ doc.body.append(deployScript)
723
+ }
724
+
725
+ private resetIFrame() {
726
+ if(!this.api) {
727
+ return
728
+ }
729
+
730
+ this.api = undefined
731
+ this.apiReady = new Promise(r => {
732
+ this.addEventListener("ggb-load", (e: any) => {
733
+ r(e.detail.api)
734
+ }, {once: true})
735
+ })
736
+
737
+ this.resetKey++
738
+ }
739
+
740
+ render() {
741
+ return html`
742
+ ${keyed(this.resetKey, html`<iframe id="ggb" @load=${(e: Event) => this.initializeIFrame(e.target as HTMLIFrameElement)}></iframe>`)}
743
+ <geogebra-options-panel
744
+ part="options"
745
+ ?visible=${this.isContentEditable}
746
+ .properties=${this.getConfigurableProperties()}
747
+ @property-change=${this.handlePropertyChange}
748
+ @import-file=${this.handleFileImport}
749
+ ></geogebra-options-panel>
750
+ `
751
+ }
417
752
  }