@webwriter/geogebra 1.0.0 → 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 (158) hide show
  1. package/.github/workflows/main.yml +8 -0
  2. package/README.md +629 -0
  3. package/assets/icons/file-earmark-arrow-up.svg +4 -0
  4. package/components/geogebra-app.styles.ts +10 -0
  5. package/components/geogebra-app.ts +517 -182
  6. package/components/geogebra-options.styles.ts +37 -0
  7. package/components/geogebra-options.ts +187 -0
  8. package/custom-elements.json +10518 -0
  9. package/dist/widgets/webwriter-geogebra-3d.css +444 -0
  10. package/dist/widgets/webwriter-geogebra-3d.js +25359 -1408
  11. package/dist/widgets/webwriter-geogebra-classic.css +444 -0
  12. package/dist/widgets/webwriter-geogebra-classic.js +25359 -1408
  13. package/dist/widgets/webwriter-geogebra-geometry.css +444 -0
  14. package/dist/widgets/webwriter-geogebra-geometry.js +25359 -1408
  15. package/dist/widgets/webwriter-geogebra-notes.css +444 -0
  16. package/dist/widgets/webwriter-geogebra-notes.js +25359 -1408
  17. package/dist/widgets/webwriter-geogebra-scientific.css +444 -0
  18. package/dist/widgets/webwriter-geogebra-scientific.js +25359 -1408
  19. package/dist/widgets/webwriter-geogebra.css +444 -0
  20. package/dist/widgets/webwriter-geogebra.js +25370 -1413
  21. package/editing-config.json +37 -0
  22. package/lit-localize.json +47 -0
  23. package/localization/ar.xlf +30 -0
  24. package/localization/bg.xlf +30 -0
  25. package/localization/cs.xlf +30 -0
  26. package/localization/da.xlf +30 -0
  27. package/localization/de.xlf +29 -0
  28. package/localization/el.xlf +30 -0
  29. package/localization/es.xlf +30 -0
  30. package/localization/et.xlf +30 -0
  31. package/localization/fi.xlf +30 -0
  32. package/localization/fr.xlf +30 -0
  33. package/localization/generated/ar.ts +22 -0
  34. package/localization/generated/bg.ts +22 -0
  35. package/localization/generated/cs.ts +22 -0
  36. package/localization/generated/da.ts +22 -0
  37. package/localization/generated/de.ts +21 -0
  38. package/localization/generated/el.ts +22 -0
  39. package/localization/generated/es.ts +22 -0
  40. package/localization/generated/et.ts +22 -0
  41. package/localization/generated/fi.ts +22 -0
  42. package/localization/generated/fr.ts +22 -0
  43. package/localization/generated/hu.ts +22 -0
  44. package/localization/generated/id.ts +22 -0
  45. package/localization/generated/index.js +3 -0
  46. package/localization/generated/it.ts +22 -0
  47. package/localization/generated/ja.ts +22 -0
  48. package/localization/generated/ko.ts +22 -0
  49. package/localization/generated/locale-codes.js +83 -0
  50. package/localization/generated/lt.ts +22 -0
  51. package/localization/generated/lv.ts +22 -0
  52. package/localization/generated/nb.ts +22 -0
  53. package/localization/generated/nl.ts +22 -0
  54. package/localization/generated/pl.ts +22 -0
  55. package/localization/generated/pt-BR.ts +22 -0
  56. package/localization/generated/pt-PT.ts +22 -0
  57. package/localization/generated/ro.ts +22 -0
  58. package/localization/generated/ru.ts +22 -0
  59. package/localization/generated/sk.ts +22 -0
  60. package/localization/generated/sl.ts +22 -0
  61. package/localization/generated/sv.ts +22 -0
  62. package/localization/generated/tr.ts +22 -0
  63. package/localization/generated/uk.ts +22 -0
  64. package/localization/generated/zh-hans.ts +20 -0
  65. package/localization/generated/zh-hant.ts +20 -0
  66. package/localization/hu.xlf +30 -0
  67. package/localization/id.xlf +30 -0
  68. package/localization/it.xlf +30 -0
  69. package/localization/ja.xlf +30 -0
  70. package/localization/ko.xlf +30 -0
  71. package/localization/lt.xlf +30 -0
  72. package/localization/lv.xlf +30 -0
  73. package/localization/nb.xlf +30 -0
  74. package/localization/nl.xlf +30 -0
  75. package/localization/pkg/ar.xliff +6 -0
  76. package/localization/pkg/bg.xliff +6 -0
  77. package/localization/pkg/cs.xliff +6 -0
  78. package/localization/pkg/da.xliff +6 -0
  79. package/localization/pkg/de.xliff +6 -0
  80. package/localization/pkg/el.xliff +6 -0
  81. package/localization/pkg/es.xliff +6 -0
  82. package/localization/pkg/et.xliff +6 -0
  83. package/localization/pkg/fi.xliff +6 -0
  84. package/localization/pkg/fr.xliff +6 -0
  85. package/localization/pkg/hu.xliff +6 -0
  86. package/localization/pkg/id.xliff +6 -0
  87. package/localization/pkg/it.xliff +6 -0
  88. package/localization/pkg/ja.xliff +6 -0
  89. package/localization/pkg/ko.xliff +6 -0
  90. package/localization/pkg/lt.xliff +6 -0
  91. package/localization/pkg/lv.xliff +6 -0
  92. package/localization/pkg/nb.xliff +6 -0
  93. package/localization/pkg/nl.xliff +6 -0
  94. package/localization/pkg/pl.xliff +6 -0
  95. package/localization/pkg/pt-BR.xliff +6 -0
  96. package/localization/pkg/pt-PT.xliff +6 -0
  97. package/localization/pkg/ro.xliff +6 -0
  98. package/localization/pkg/ru.xliff +6 -0
  99. package/localization/pkg/sk.xliff +6 -0
  100. package/localization/pkg/sl.xliff +6 -0
  101. package/localization/pkg/sv.xliff +6 -0
  102. package/localization/pkg/tr.xliff +6 -0
  103. package/localization/pkg/uk.xliff +6 -0
  104. package/localization/pkg/zh-hans.xliff +6 -0
  105. package/localization/pkg/zh-hant.xliff +6 -0
  106. package/localization/pl.xlf +30 -0
  107. package/localization/pt-BR.xlf +30 -0
  108. package/localization/pt-PT.xlf +30 -0
  109. package/localization/ro.xlf +30 -0
  110. package/localization/ru.xlf +30 -0
  111. package/localization/sk.xlf +30 -0
  112. package/localization/sl.xlf +30 -0
  113. package/localization/snippets/ar.xliff +4 -0
  114. package/localization/snippets/bg.xliff +4 -0
  115. package/localization/snippets/cs.xliff +4 -0
  116. package/localization/snippets/da.xliff +4 -0
  117. package/localization/snippets/de.xliff +4 -0
  118. package/localization/snippets/el.xliff +4 -0
  119. package/localization/snippets/es.xliff +4 -0
  120. package/localization/snippets/et.xliff +4 -0
  121. package/localization/snippets/fi.xliff +4 -0
  122. package/localization/snippets/fr.xliff +4 -0
  123. package/localization/snippets/hu.xliff +4 -0
  124. package/localization/snippets/id.xliff +4 -0
  125. package/localization/snippets/it.xliff +4 -0
  126. package/localization/snippets/ja.xliff +4 -0
  127. package/localization/snippets/ko.xliff +4 -0
  128. package/localization/snippets/lt.xliff +4 -0
  129. package/localization/snippets/lv.xliff +4 -0
  130. package/localization/snippets/nb.xliff +4 -0
  131. package/localization/snippets/nl.xliff +4 -0
  132. package/localization/snippets/pl.xliff +4 -0
  133. package/localization/snippets/pt-BR.xliff +4 -0
  134. package/localization/snippets/pt-PT.xliff +4 -0
  135. package/localization/snippets/ro.xliff +4 -0
  136. package/localization/snippets/ru.xliff +4 -0
  137. package/localization/snippets/sk.xliff +4 -0
  138. package/localization/snippets/sl.xliff +4 -0
  139. package/localization/snippets/sv.xliff +4 -0
  140. package/localization/snippets/tr.xliff +4 -0
  141. package/localization/snippets/uk.xliff +4 -0
  142. package/localization/snippets/zh-hans.xliff +4 -0
  143. package/localization/snippets/zh-hant.xliff +4 -0
  144. package/localization/sv.xlf +30 -0
  145. package/localization/tr.xlf +30 -0
  146. package/localization/uk.xlf +30 -0
  147. package/localization/zh-hans.xlf +30 -0
  148. package/localization/zh-hant.xlf +30 -0
  149. package/package.json +157 -157
  150. package/utils/boolean-attribute-converter.ts +8 -0
  151. package/widgets/webwriter-geogebra-3d.ts +9 -3
  152. package/widgets/webwriter-geogebra-classic.ts +9 -3
  153. package/widgets/webwriter-geogebra-evaluator.ts +9 -3
  154. package/widgets/webwriter-geogebra-geometry.ts +9 -3
  155. package/widgets/webwriter-geogebra-notes.ts +9 -3
  156. package/widgets/webwriter-geogebra-scientific.ts +9 -3
  157. package/widgets/webwriter-geogebra.ts +20 -11
  158. package/dist/widgets/webwriter-geogebra-evaluator.js +0 -1885
@@ -1,6 +1,16 @@
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"
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"
4
14
 
5
15
  export interface GeogebraAPI {
6
16
  evalCommand(cmdString: string): boolean
@@ -151,183 +161,414 @@ export interface GeogebraAPI {
151
161
  remove(): void
152
162
  }
153
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()
154
169
  export class GeogebraApp extends LitElementWw {
170
+ protected localize = LOCALIZE
155
171
 
156
- static styles = css`
157
- iframe {
158
- border: none;
159
- width: 100%;
160
- aspect-ratio: 16/9;
172
+ protected static get scopedElements() {
173
+ return {
174
+ "geogebra-options-panel": GeogebraOptions
161
175
  }
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
176
+ }
172
177
 
173
- @property({type: Number, reflect: true})
174
- height: number = 450
178
+ static styles = geogebraAppStyles
175
179
 
176
- @property({type: String, attribute: true, reflect: true}) // base64, material ID, file url
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})
177
212
  accessor src: string
178
213
 
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
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
+ })
325
566
 
326
- @property({type: String, reflect: true})
327
- detachedKeyboardParent: string
567
+ return properties
568
+ }
328
569
 
329
570
  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
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
331
572
 
332
573
  let filename: string, material_id: string, ggbBase64: string
333
574
  if(this.src && this.src.startsWith("data:")) {
@@ -340,10 +581,11 @@ export class GeogebraApp extends LitElementWw {
340
581
  filename = this.src
341
582
  }
342
583
 
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}
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}
344
585
  }
345
586
 
346
- updateSrc = () => {
587
+ private updateSrc = (a) => {
588
+ console.log("updateSrc called", a)
347
589
  if(!this.updatingGgb) {
348
590
  this.src = `data:application/vnd.geogebra.file;base64,${this.api.getBase64()}`
349
591
  }
@@ -360,31 +602,102 @@ export class GeogebraApp extends LitElementWw {
360
602
  this.api.registerUpdateListener(this.updateSrc)
361
603
  this.api.registerRenameListener(this.updateSrc)
362
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
+ ])
363
623
  })
364
624
  })
365
625
  }
366
626
 
367
- updatingGgb = false
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
368
638
 
369
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
+ })
370
667
 
371
- if(changed.has("src") && this.src && this.src.split(",").at(-1) !== this?.api?.getBase64()) {
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()) {
372
679
  this.updatingGgb = true
373
- this?.api?.setBase64(this.src.split(",").at(-1), () => this.updatingGgb = false)
680
+ this?.api?.setBase64(this.src.split(",").at(-1), () => {
681
+ this.updatingGgb = false
682
+ })
374
683
  }
375
- else if(changed.has("src") && !this.src) {
684
+ else if(!this.src) {
376
685
  this.updatingGgb = true
377
- this?.api?.setBase64("", () => this.updatingGgb = false)
686
+ this?.api?.setBase64("", () => {
687
+ this.updatingGgb = false
688
+ })
378
689
  }
379
690
  }
380
691
 
381
- apiReady: Promise<GeogebraAPI>
382
- api?: GeogebraAPI
692
+ private apiReady: Promise<GeogebraAPI>
693
+ private api?: GeogebraAPI
383
694
 
384
- initializeIFrame(e: Event) {
385
- const iframe = e.target as HTMLIFrameElement
695
+ private initializeIFrame(iframe: HTMLIFrameElement) {
386
696
  const doc = iframe.contentDocument
387
697
  const win = iframe.contentWindow
698
+ if (doc.getElementById("ggb-element")) {
699
+ return
700
+ }
388
701
  doc.body.style.margin = "0"
389
702
  if(this.ggbStyles) {
390
703
  const style = doc.createElement("style")
@@ -409,9 +722,31 @@ export class GeogebraApp extends LitElementWw {
409
722
  doc.body.append(deployScript)
410
723
  }
411
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
+
412
740
  render() {
413
741
  return html`
414
- <iframe id="ggb" @load=${this.initializeIFrame}></iframe>
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>
415
750
  `
416
751
  }
417
752
  }