@webwriter/geogebra 1.1.0 → 2.0.2

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 (338) hide show
  1. package/README.md +280 -124
  2. package/custom-elements.json +2255 -1259
  3. package/dist/chunks/af-35CD6HFH.js +12 -0
  4. package/dist/chunks/am-JMDT5LI7.js +12 -0
  5. package/dist/chunks/ar-JL4QKYYL.js +12 -0
  6. package/dist/chunks/az-3SZS6WCY.js +12 -0
  7. package/dist/chunks/be-C4GWVHR2.js +12 -0
  8. package/dist/chunks/bg-6QGE5EQ4.js +12 -0
  9. package/dist/chunks/bn-UM2BV46R.js +12 -0
  10. package/dist/chunks/bs-XE2PWKCS.js +12 -0
  11. package/dist/chunks/ca-ZO2BQKPZ.js +12 -0
  12. package/dist/chunks/ca-balear-GJKWY5R7.js +12 -0
  13. package/dist/chunks/ca-valencia-CNQYSJSJ.js +12 -0
  14. package/dist/chunks/chunk-ANJTU3IB.js +203 -0
  15. package/dist/chunks/chunk-BSUFUO7E.js +65 -0
  16. package/dist/chunks/chunk-RYZMQM25.js +789 -0
  17. package/dist/chunks/cnr-MCZGASOD.js +12 -0
  18. package/dist/chunks/cs-4Q7FRISG.js +12 -0
  19. package/dist/chunks/cy-7VXG3AYH.js +12 -0
  20. package/dist/chunks/da-VDMHGBXD.js +12 -0
  21. package/dist/chunks/de-AT-YM5GCI75.js +12 -0
  22. package/dist/chunks/de-CH-LQNHTGYT.js +12 -0
  23. package/dist/chunks/de-GJT7RSHT.js +12 -0
  24. package/dist/chunks/el-ZVUVWEQ3.js +12 -0
  25. package/dist/chunks/en-AU-PCIYYC4M.js +12 -0
  26. package/dist/chunks/en-CA-37T7YUIL.js +12 -0
  27. package/dist/chunks/en-GB-ZYCA2CIZ.js +12 -0
  28. package/dist/chunks/en-IN-EPHXLNO6.js +12 -0
  29. package/dist/chunks/en-US-ECSJ5HDL.js +12 -0
  30. package/dist/chunks/es-5VBYK2HE.js +12 -0
  31. package/dist/chunks/et-OFQRRTW6.js +12 -0
  32. package/dist/chunks/eu-7TNOYFB7.js +12 -0
  33. package/dist/chunks/fa-KZU6GKWU.js +12 -0
  34. package/dist/chunks/fi-THJEKJPW.js +12 -0
  35. package/dist/chunks/fr-MUVVTBQZ.js +12 -0
  36. package/dist/chunks/ga-UWUVCWOT.js +12 -0
  37. package/dist/chunks/gl-NHQ52YCN.js +12 -0
  38. package/dist/chunks/gu-HVDD4QHO.js +12 -0
  39. package/dist/chunks/ha-2BPTATOZ.js +12 -0
  40. package/dist/chunks/he-MDESCUHJ.js +12 -0
  41. package/dist/chunks/hi-C6BGPR4Y.js +12 -0
  42. package/dist/chunks/hr-77MP3ELT.js +12 -0
  43. package/dist/chunks/hu-7PRNX6NB.js +12 -0
  44. package/dist/chunks/hy-R3VEL63L.js +12 -0
  45. package/dist/chunks/id-O6B2T3Y2.js +12 -0
  46. package/dist/chunks/is-XLNS5CAZ.js +12 -0
  47. package/dist/chunks/it-NZODUGUP.js +12 -0
  48. package/dist/chunks/ja-FFK5WXSB.js +12 -0
  49. package/dist/chunks/jv-GS3IRAIB.js +12 -0
  50. package/dist/chunks/ka-NWIJAO54.js +12 -0
  51. package/dist/chunks/kk-WQFRFG44.js +12 -0
  52. package/dist/chunks/km-AUKBN3YT.js +12 -0
  53. package/dist/chunks/kn-PKZFPECM.js +12 -0
  54. package/dist/chunks/ko-XNGAWKQ4.js +12 -0
  55. package/dist/chunks/ky-AQTYDJIL.js +12 -0
  56. package/dist/chunks/la-ERS7V4N4.js +12 -0
  57. package/dist/chunks/lb-KU3DVPI4.js +12 -0
  58. package/dist/chunks/locale-codes-TGY5LMYX.js +11 -0
  59. package/dist/chunks/lt-6RI4HSG3.js +12 -0
  60. package/dist/chunks/lv-RGIUQVA7.js +12 -0
  61. package/dist/chunks/mk-JMAYXTCL.js +12 -0
  62. package/dist/chunks/ml-5ZAIPAYV.js +12 -0
  63. package/dist/chunks/mn-N2GZBVDP.js +12 -0
  64. package/dist/chunks/mr-2SRCJIBC.js +12 -0
  65. package/dist/chunks/ms-WHD5PUQM.js +12 -0
  66. package/dist/chunks/mt-EXRK5UO6.js +12 -0
  67. package/dist/chunks/my-D2COGDRI.js +12 -0
  68. package/dist/chunks/nb-3XNBS2DU.js +12 -0
  69. package/dist/chunks/ne-PA4KUBGU.js +12 -0
  70. package/dist/chunks/nl-QMM3PBPM.js +12 -0
  71. package/dist/chunks/nn-CLFEMF2K.js +12 -0
  72. package/dist/chunks/no-CV376NZG.js +12 -0
  73. package/dist/chunks/or-KP7CET7X.js +12 -0
  74. package/dist/chunks/pa-CH5JYVXT.js +12 -0
  75. package/dist/chunks/pl-DDW4HT7M.js +12 -0
  76. package/dist/chunks/pt-BR-CVNA2MRU.js +12 -0
  77. package/dist/chunks/pt-CRTRYTDJ.js +12 -0
  78. package/dist/chunks/pt-PT-IZMPF3BY.js +12 -0
  79. package/dist/chunks/ro-FUOGHWJA.js +12 -0
  80. package/dist/chunks/ru-KAT4X5EC.js +12 -0
  81. package/dist/chunks/si-GDAXEOBK.js +12 -0
  82. package/dist/chunks/sk-CDSK6MY5.js +12 -0
  83. package/dist/chunks/sl-TFJQYNA4.js +12 -0
  84. package/dist/chunks/so-TXI6JJPW.js +12 -0
  85. package/dist/chunks/sq-KMM2QIRU.js +12 -0
  86. package/dist/chunks/sr-OTZNEL5Z.js +12 -0
  87. package/dist/chunks/sv-7CANJ6CF.js +12 -0
  88. package/dist/chunks/sw-5JDMTJ5K.js +12 -0
  89. package/dist/chunks/ta-HT4SO7PD.js +12 -0
  90. package/dist/chunks/te-FECCLHOI.js +12 -0
  91. package/dist/chunks/tg-FJWFJWF2.js +12 -0
  92. package/dist/chunks/th-JEP434LN.js +12 -0
  93. package/dist/chunks/tl-GN35ZR2F.js +12 -0
  94. package/dist/chunks/tr-IPVLQUE4.js +12 -0
  95. package/dist/chunks/uk-LHWPGFRV.js +12 -0
  96. package/dist/chunks/ur-7FU4XRAY.js +12 -0
  97. package/dist/chunks/uz-RO7XCKFE.js +12 -0
  98. package/dist/chunks/vi-5PHPTVV4.js +12 -0
  99. package/dist/chunks/zh-Hans-UM7MUEDB.js +12 -0
  100. package/dist/chunks/zh-Hant-7M2P4G7R.js +12 -0
  101. package/dist/chunks/zh-LHCPWZN2.js +12 -0
  102. package/dist/widgets/webwriter-geogebra-3d.js +19 -25827
  103. package/dist/widgets/webwriter-geogebra-classic.js +18 -25826
  104. package/dist/widgets/webwriter-geogebra-geometry.js +18 -25826
  105. package/dist/widgets/webwriter-geogebra-notes.js +18 -25826
  106. package/dist/widgets/webwriter-geogebra-scientific.js +18 -25826
  107. package/dist/widgets/webwriter-geogebra.js +20 -25830
  108. package/editing-config.json +839 -20
  109. package/lit-localize.json +73 -9
  110. package/localization/af.xlf +290 -0
  111. package/localization/am.xlf +290 -0
  112. package/localization/ar.xlf +271 -6
  113. package/localization/az.xlf +290 -0
  114. package/localization/be.xlf +290 -0
  115. package/localization/bg.xlf +271 -6
  116. package/localization/bn.xlf +290 -0
  117. package/localization/bs.xlf +290 -0
  118. package/localization/ca-balear.xlf +290 -0
  119. package/localization/ca-valencia.xlf +290 -0
  120. package/localization/ca.xlf +290 -0
  121. package/localization/cnr.xlf +290 -0
  122. package/localization/cs.xlf +271 -6
  123. package/localization/cy.xlf +290 -0
  124. package/localization/da.xlf +271 -6
  125. package/localization/de-AT.xlf +294 -0
  126. package/localization/de-CH.xlf +294 -0
  127. package/localization/de.xlf +271 -6
  128. package/localization/el.xlf +271 -6
  129. package/localization/es.xlf +271 -6
  130. package/localization/et.xlf +271 -6
  131. package/localization/eu.xlf +290 -0
  132. package/localization/fa.xlf +290 -0
  133. package/localization/fi.xlf +271 -6
  134. package/localization/fr.xlf +271 -6
  135. package/localization/ga.xlf +290 -0
  136. package/localization/generated/af.ts +16 -0
  137. package/localization/generated/am.ts +16 -0
  138. package/localization/generated/ar.ts +6 -12
  139. package/localization/generated/az.ts +16 -0
  140. package/localization/generated/be.ts +16 -0
  141. package/localization/generated/bg.ts +6 -12
  142. package/localization/generated/bn.ts +16 -0
  143. package/localization/generated/bs.ts +16 -0
  144. package/localization/generated/ca-balear.ts +16 -0
  145. package/localization/generated/ca-valencia.ts +16 -0
  146. package/localization/generated/ca.ts +16 -0
  147. package/localization/generated/cnr.ts +16 -0
  148. package/localization/generated/cs.ts +6 -12
  149. package/localization/generated/cy.ts +16 -0
  150. package/localization/generated/da.ts +6 -12
  151. package/localization/generated/de-AT.ts +16 -0
  152. package/localization/generated/de-CH.ts +16 -0
  153. package/localization/generated/de.ts +6 -11
  154. package/localization/generated/el.ts +6 -12
  155. package/localization/generated/en-AU.ts +16 -0
  156. package/localization/generated/en-CA.ts +16 -0
  157. package/localization/generated/en-GB.ts +16 -0
  158. package/localization/generated/en-IN.ts +16 -0
  159. package/localization/generated/en-US.ts +16 -0
  160. package/localization/generated/es.ts +6 -12
  161. package/localization/generated/et.ts +6 -12
  162. package/localization/generated/eu.ts +16 -0
  163. package/localization/generated/fa.ts +16 -0
  164. package/localization/generated/fi.ts +6 -12
  165. package/localization/generated/fr.ts +6 -12
  166. package/localization/generated/ga.ts +16 -0
  167. package/localization/generated/gl.ts +16 -0
  168. package/localization/generated/gu.ts +16 -0
  169. package/localization/generated/ha.ts +16 -0
  170. package/localization/generated/he.ts +16 -0
  171. package/localization/generated/hi.ts +16 -0
  172. package/localization/generated/hr.ts +16 -0
  173. package/localization/generated/hu.ts +6 -12
  174. package/localization/generated/hy.ts +16 -0
  175. package/localization/generated/id.ts +6 -12
  176. package/localization/generated/is.ts +16 -0
  177. package/localization/generated/it.ts +6 -12
  178. package/localization/generated/ja.ts +6 -12
  179. package/localization/generated/jv.ts +16 -0
  180. package/localization/generated/ka.ts +16 -0
  181. package/localization/generated/kk.ts +16 -0
  182. package/localization/generated/km.ts +16 -0
  183. package/localization/generated/kn.ts +16 -0
  184. package/localization/generated/ko.ts +6 -12
  185. package/localization/generated/ky.ts +16 -0
  186. package/localization/generated/la.ts +16 -0
  187. package/localization/generated/lb.ts +16 -0
  188. package/localization/generated/locale-codes.ts +211 -0
  189. package/localization/generated/lt.ts +6 -12
  190. package/localization/generated/lv.ts +6 -12
  191. package/localization/generated/mk.ts +16 -0
  192. package/localization/generated/ml.ts +16 -0
  193. package/localization/generated/mn.ts +16 -0
  194. package/localization/generated/mr.ts +16 -0
  195. package/localization/generated/ms.ts +16 -0
  196. package/localization/generated/mt.ts +16 -0
  197. package/localization/generated/my.ts +16 -0
  198. package/localization/generated/nb.ts +6 -12
  199. package/localization/generated/ne.ts +16 -0
  200. package/localization/generated/nl.ts +6 -12
  201. package/localization/generated/nn.ts +16 -0
  202. package/localization/generated/no.ts +16 -0
  203. package/localization/generated/or.ts +16 -0
  204. package/localization/generated/pa.ts +16 -0
  205. package/localization/generated/pl.ts +6 -12
  206. package/localization/generated/pt-BR.ts +6 -12
  207. package/localization/generated/pt-PT.ts +6 -12
  208. package/localization/generated/pt.ts +16 -0
  209. package/localization/generated/ro.ts +6 -12
  210. package/localization/generated/ru.ts +6 -12
  211. package/localization/generated/si.ts +16 -0
  212. package/localization/generated/sk.ts +6 -12
  213. package/localization/generated/sl.ts +6 -12
  214. package/localization/generated/so.ts +16 -0
  215. package/localization/generated/sq.ts +16 -0
  216. package/localization/generated/sr.ts +16 -0
  217. package/localization/generated/sv.ts +6 -12
  218. package/localization/generated/sw.ts +16 -0
  219. package/localization/generated/ta.ts +16 -0
  220. package/localization/generated/te.ts +16 -0
  221. package/localization/generated/tg.ts +16 -0
  222. package/localization/generated/th.ts +16 -0
  223. package/localization/generated/tl.ts +16 -0
  224. package/localization/generated/tr.ts +6 -12
  225. package/localization/generated/uk.ts +6 -12
  226. package/localization/generated/ur.ts +16 -0
  227. package/localization/generated/uz.ts +16 -0
  228. package/localization/generated/vi.ts +16 -0
  229. package/localization/generated/zh-Hans.ts +16 -0
  230. package/localization/generated/zh-Hant.ts +16 -0
  231. package/localization/generated/zh.ts +16 -0
  232. package/localization/gl.xlf +290 -0
  233. package/localization/gu.xlf +290 -0
  234. package/localization/ha.xlf +290 -0
  235. package/localization/he.xlf +290 -0
  236. package/localization/hi.xlf +290 -0
  237. package/localization/hr.xlf +290 -0
  238. package/localization/hu.xlf +271 -6
  239. package/localization/hy.xlf +290 -0
  240. package/localization/id.xlf +271 -6
  241. package/localization/is.xlf +290 -0
  242. package/localization/it.xlf +271 -6
  243. package/localization/ja.xlf +271 -6
  244. package/localization/jv.xlf +290 -0
  245. package/localization/ka.xlf +290 -0
  246. package/localization/kk.xlf +290 -0
  247. package/localization/km.xlf +290 -0
  248. package/localization/kn.xlf +290 -0
  249. package/localization/ko.xlf +271 -6
  250. package/localization/ky.xlf +290 -0
  251. package/localization/la.xlf +290 -0
  252. package/localization/lb.xlf +290 -0
  253. package/localization/lt.xlf +271 -6
  254. package/localization/lv.xlf +271 -6
  255. package/localization/mk.xlf +290 -0
  256. package/localization/ml.xlf +290 -0
  257. package/localization/mn.xlf +290 -0
  258. package/localization/mr.xlf +290 -0
  259. package/localization/ms.xlf +290 -0
  260. package/localization/mt.xlf +290 -0
  261. package/localization/my.xlf +290 -0
  262. package/localization/nb.xlf +271 -6
  263. package/localization/ne.xlf +290 -0
  264. package/localization/nl.xlf +271 -6
  265. package/localization/nn.xlf +290 -0
  266. package/localization/no.xlf +295 -0
  267. package/localization/or.xlf +290 -0
  268. package/localization/pa.xlf +290 -0
  269. package/localization/pl.xlf +271 -6
  270. package/localization/pt-BR.xlf +271 -6
  271. package/localization/pt-PT.xlf +271 -6
  272. package/localization/pt.xlf +295 -0
  273. package/localization/ro.xlf +271 -6
  274. package/localization/ru.xlf +271 -6
  275. package/localization/si.xlf +290 -0
  276. package/localization/sk.xlf +271 -6
  277. package/localization/sl.xlf +271 -6
  278. package/localization/so.xlf +290 -0
  279. package/localization/sq.xlf +290 -0
  280. package/localization/sr.xlf +290 -0
  281. package/localization/sv.xlf +271 -6
  282. package/localization/sw.xlf +290 -0
  283. package/localization/ta.xlf +290 -0
  284. package/localization/te.xlf +290 -0
  285. package/localization/tg.xlf +290 -0
  286. package/localization/th.xlf +290 -0
  287. package/localization/tl.xlf +290 -0
  288. package/localization/tr.xlf +271 -6
  289. package/localization/uk.xlf +271 -6
  290. package/localization/ur.xlf +290 -0
  291. package/localization/uz.xlf +290 -0
  292. package/localization/vi.xlf +290 -0
  293. package/localization/zh-Hans.xlf +295 -0
  294. package/localization/zh-Hant.xlf +295 -0
  295. package/localization/zh.xlf +295 -0
  296. package/package.json +194 -86
  297. package/src/components/geogebra-app.styles.ts +47 -0
  298. package/{components → src/components}/geogebra-app.ts +237 -332
  299. package/src/model/geogebra-api.ts +148 -0
  300. package/src/model/geogebra-options.ts +72 -0
  301. package/src/model/geogebra-parameters.ts +53 -0
  302. package/src/model/ggb-file.ts +30 -0
  303. package/src/types.d.ts +3 -0
  304. package/{widgets → src/widgets}/webwriter-geogebra-3d.ts +1 -1
  305. package/{widgets → src/widgets}/webwriter-geogebra.ts +1 -2
  306. package/tests/conversions.test.ts +80 -0
  307. package/tests/data-block.test.ts +72 -0
  308. package/tests/helpers.ts +48 -0
  309. package/tests/language.test.ts +49 -0
  310. package/tests/presentation.test.ts +114 -0
  311. package/tsconfig.json +3 -7
  312. package/assets/icons/file-earmark-arrow-up.svg +0 -4
  313. package/components/geogebra-app.styles.ts +0 -10
  314. package/components/geogebra-options.styles.ts +0 -37
  315. package/components/geogebra-options.ts +0 -187
  316. package/custom.d.ts +0 -180
  317. package/dist/widgets/webwriter-geogebra-3d.css +0 -444
  318. package/dist/widgets/webwriter-geogebra-classic.css +0 -444
  319. package/dist/widgets/webwriter-geogebra-geometry.css +0 -444
  320. package/dist/widgets/webwriter-geogebra-notes.css +0 -444
  321. package/dist/widgets/webwriter-geogebra-scientific.css +0 -444
  322. package/dist/widgets/webwriter-geogebra.css +0 -444
  323. package/localization/generated/locale-codes.js +0 -83
  324. package/localization/generated/zh-hans.ts +0 -20
  325. package/localization/generated/zh-hant.ts +0 -20
  326. package/localization/zh-hans.xlf +0 -30
  327. package/localization/zh-hant.xlf +0 -30
  328. package/widgets/webwriter-geogebra-evaluator.ts +0 -15
  329. /package/.github/workflows/{main.yml → publish.yml} +0 -0
  330. /package/localization/pkg/{zh-hans.xliff → zh-Hans.xliff} +0 -0
  331. /package/localization/pkg/{zh-hant.xliff → zh-Hant.xliff} +0 -0
  332. /package/localization/snippets/{zh-hans.xliff → zh-Hans.xliff} +0 -0
  333. /package/localization/snippets/{zh-hant.xliff → zh-Hant.xliff} +0 -0
  334. /package/{utils → src/model}/boolean-attribute-converter.ts +0 -0
  335. /package/{widgets → src/widgets}/webwriter-geogebra-classic.ts +0 -0
  336. /package/{widgets → src/widgets}/webwriter-geogebra-geometry.ts +0 -0
  337. /package/{widgets → src/widgets}/webwriter-geogebra-notes.ts +0 -0
  338. /package/{widgets → src/widgets}/webwriter-geogebra-scientific.ts +0 -0
@@ -1,181 +1,80 @@
1
- import {html, css, PropertyValues, PropertyDeclaration} from "lit"
2
- import {LitElementWw} from "@webwriter/lit"
3
- import {property} from "lit/decorators.js"
1
+ import { LitElementWw } from "@webwriter/lit"
2
+ import { localizer } from "@webwriter/lit/localize"
3
+ import { jsonData } from "@webwriter/lit/data"
4
+ import type { MsgFn } from "@lit/localize"
5
+ import { sourceLocale, targetLocales } from "../../localization/generated/locale-codes"
6
+ import {html, css, type PropertyValues} from "lit"
7
+ import {property, state} from "lit/decorators.js"
4
8
  import {keyed} from "lit/directives/keyed.js"
5
9
 
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
10
  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
11
+ import { booleanAttributeConverter } from "../model/boolean-attribute-converter"
12
+ import type { GeogebraAPI } from "../model/geogebra-api"
13
+ import { geogebraOptions } from "../model/geogebra-options"
14
+ import { appletParameters, passThroughParameters, passThroughParametersAfterLocale } from "../model/geogebra-parameters"
15
+ import { base64ToBytes, bytesToBase64, dataUrlPayload, ggbDataUrl, GGB_MEDIA_TYPE, isGgbArchive } from "../model/ggb-file"
16
+
17
+ const appletSettings = new Set<PropertyKey>([
18
+ ...passThroughParameters,
19
+ ...passThroughParametersAfterLocale,
20
+ "appletId", "type", "lang", "language", "country", "ggbStyles",
21
+ ])
22
+
23
+ export type { GeogebraAPI }
24
+
25
+ declare global {
26
+ interface HTMLElementEventMap {
27
+ "ggb-load": CustomEvent<{api: GeogebraAPI}>
28
+ }
162
29
  }
163
30
 
164
31
  /**
32
+ * The applet runs in an iframe and handles keyboard, pointer and touch input itself. The widget resizes it with its container (300 to 2100 px):
33
+ * the applet fills the iframe (16:9, at least 18rem high), so `width` and `height` only set its size before the first resize.
34
+ *
35
+ * Theme: the host takes `--ww-text-color` and `--ww-font-family`; the focus ring uses `--ww-link-color`. The applet's own content is not themed.
36
+ *
37
+ * Conversions: a `.ggb` file replaces the construction (import) and the current construction downloads as `.ggb` (export).
38
+ * `image/png` and `image/svg+xml` export the picture of the graphics view; both need the loaded applet and are lossy
39
+ * (no construction steps, no algebra view). A file that is no zip archive is refused before the widget changes.
40
+ *
41
+ * @part applet - The iframe that holds the GeoGebra applet.
165
42
  * @fires focus - Fired when the GeoGebra applet gains focus.
166
43
  * @fires ggb-load - Fired when the GeoGebra API is ready. The event detail contains the API instance.
167
44
  */
168
- @localized()
169
45
  export class GeogebraApp extends LitElementWw {
170
- protected localize = LOCALIZE
46
+ static styles = geogebraAppStyles
171
47
 
172
- protected static get scopedElements() {
173
- return {
174
- "geogebra-options-panel": GeogebraOptions
175
- }
48
+ static options = geogebraOptions
49
+
50
+ static actions = {
51
+ importConstruction: {
52
+ label: (widget: {msg: MsgFn}) => ({_: widget.msg("Import construction")}),
53
+ input: {type: "file" as const, accept: ".ggb", multiple: false},
54
+ },
176
55
  }
177
56
 
178
- static styles = geogebraAppStyles
57
+ static convertFrom = {".ggb": "importGgb"}
58
+
59
+ static convertTo = {".ggb": "exportGgb", "image/png": "exportPng", "image/svg+xml": "exportSvg"}
60
+
61
+ // The labels of the options are computed with msg, so the editor reads them again after a language change.
62
+ protected readonly localize = localizer(this, {
63
+ sourceLocale,
64
+ targetLocales,
65
+ load: (locale) => import(`../../localization/generated/${locale}.ts`),
66
+ drawer: true,
67
+ })
68
+
69
+ readonly msg: MsgFn = this.localize.msg
70
+
71
+ // The embedded construction is the "src" key of the JSON data block.
72
+ #data = jsonData<{src?: string}>(this, {
73
+ defaults: {},
74
+ changed: ({src}) => {
75
+ if (typeof src === "string" && src.startsWith("data:")) this.src = src
76
+ },
77
+ })
179
78
 
180
79
  /**
181
80
  * Custom CSS styles to apply to the GeoGebra applet.
@@ -208,8 +107,11 @@ export class GeogebraApp extends LitElementWw {
208
107
  /**
209
108
  * Source of the GeoGebra file to load (base64-encoded string, material ID prefixed with "ggbid:", or file URL)
210
109
  */
211
- @property({type: String, attribute: true, reflect: true})
212
- accessor src: string
110
+ @property({type: String, attribute: true, reflect: true, converter: {
111
+ fromAttribute: (value: string | null) => value,
112
+ toAttribute: (value: string | null) => value?.startsWith("data:") ? null : value,
113
+ }})
114
+ accessor src: string | undefined
213
115
 
214
116
  /**
215
117
  * Color of the border line drawn around the applet panel (as hex rgb string). Default: gray
@@ -275,7 +177,7 @@ export class GeogebraApp extends LitElementWw {
275
177
  * 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
178
  */
277
179
  @property({type: String, attribute: true, reflect: true})
278
- accessor customToolBar: string
180
+ accessor customToolBar: string | undefined
279
181
 
280
182
  /**
281
183
  * States whether the algebra input line (with input field, greek letters and command list) should be shown in the applet. Default: false
@@ -293,19 +195,19 @@ export class GeogebraApp extends LitElementWw {
293
195
  * 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
196
  */
295
197
  @property({type: String, attribute: true, reflect: true})
296
- accessor language: String
198
+ accessor language: string | undefined
297
199
 
298
200
  /**
299
201
  * ISO country string. This parameter only makes sense if you use it together with the language parameter.
300
202
  */
301
203
  @property({type: String, attribute: true, reflect: true})
302
- accessor country: String
204
+ accessor country: string | undefined
303
205
 
304
206
  /**
305
207
  * 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
208
  */
307
209
  @property({type: String, attribute: true, reflect: true})
308
- accessor appletId: String
210
+ accessor appletId: string | undefined
309
211
 
310
212
  /**
311
213
  * Determines whether the Style Bar can be shown (or will be shown if just Graphics View 1 is showing). Default: false
@@ -323,7 +225,7 @@ export class GeogebraApp extends LitElementWw {
323
225
  * 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
226
  */
325
227
  @property({type: Number, attribute: true, reflect: true})
326
- accessor randomSeed: number
228
+ accessor randomSeed: number | undefined
327
229
 
328
230
  /**
329
231
  * 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
@@ -359,25 +261,25 @@ export class GeogebraApp extends LitElementWw {
359
261
  * 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
262
  */
361
263
  @property({type: String, attribute: true, reflect: true})
362
- accessor perspective: String
264
+ accessor perspective: string | undefined
363
265
 
364
266
  /**
365
267
  * Whether 3D should be enabled (for exam mode).
366
268
  */
367
269
  @property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
368
- accessor enable3d: boolean
270
+ accessor enable3d: boolean | undefined
369
271
 
370
272
  /**
371
273
  * Whether CAS should be enabled (for exam mode).
372
274
  */
373
275
  @property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
374
- accessor enableCAS: boolean
276
+ accessor enableCAS: boolean | undefined
375
277
 
376
278
  /**
377
279
  * 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
280
  */
379
281
  @property({type: String, attribute: true, reflect: true})
380
- accessor algebraInputPosition: "algebra" | "top" | "bottom"
282
+ accessor algebraInputPosition: "algebra" | "top" | "bottom" | undefined
381
283
 
382
284
  /**
383
285
  * When set to true, this prevents the applet from getting focus automatically at the start. Default: false
@@ -389,7 +291,7 @@ export class GeogebraApp extends LitElementWw {
389
291
  * Name of CSS class that is used as container; applet will scale to fit into the container.
390
292
  */
391
293
  @property({type: String, attribute: true, reflect: true})
392
- accessor scaleContainerClass: string
294
+ accessor scaleContainerClass: string | undefined
393
295
 
394
296
  /**
395
297
  * `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
@@ -443,7 +345,7 @@ export class GeogebraApp extends LitElementWw {
443
345
  * 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
346
  */
445
347
  @property({type: String, attribute: true, reflect: true})
446
- accessor rounding: string
348
+ accessor rounding: string | undefined
447
349
 
448
350
  /**
449
351
  * Whether buttons should have shadow
@@ -455,25 +357,25 @@ export class GeogebraApp extends LitElementWw {
455
357
  * 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
358
  */
457
359
  @property({type: Number, attribute: true, reflect: true})
458
- accessor buttonRounding: Number = 0.2
360
+ accessor buttonRounding = 0.2
459
361
 
460
362
  /**
461
363
  * 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
364
  */
463
365
  @property({type: String, attribute: true, reflect: true})
464
- accessor buttonBorderColor: string
366
+ accessor buttonBorderColor: string | undefined
465
367
 
466
368
  /**
467
369
  * Background color of the evaluator app
468
370
  */
469
371
  @property({type: String, attribute: true, reflect: true})
470
- accessor editorBackgroundColor: string
372
+ accessor editorBackgroundColor: string | undefined
471
373
 
472
374
  /**
473
375
  * Foreground (text) color of the equation editor (appname = "evaluator")
474
376
  */
475
377
  @property({type: String, attribute: true, reflect: true})
476
- accessor editorForegroundColor: string
378
+ accessor editorForegroundColor: string | undefined
477
379
 
478
380
  /**
479
381
  * Whether editor is in text mode or not (appname = "evaluator"). Default: false
@@ -485,13 +387,13 @@ export class GeogebraApp extends LitElementWw {
485
387
  * 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
388
  */
487
389
  @property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
488
- accessor showKeyboardOnFocus: boolean
390
+ accessor showKeyboardOnFocus: boolean | undefined
489
391
 
490
392
  /**
491
393
  * Which keyboard is shown for equation editor (appname = "evaluator")
492
394
  */
493
395
  @property({type: String, attribute: true, reflect: true})
494
- accessor keyboardType: "scientific" | "normal" | "notes"
396
+ accessor keyboardType: "scientific" | "normal" | "notes" | undefined
495
397
 
496
398
  /**
497
399
  * Whether the Graphics View and Graphics View 2 should be transparent
@@ -509,7 +411,7 @@ export class GeogebraApp extends LitElementWw {
509
411
  * When set, the keyboard should be attached to the first element in DOM that fits the selector.
510
412
  */
511
413
  @property({type: String, attribute: true, reflect: true})
512
- accessor detachedKeyboardParent: string
414
+ accessor detachedKeyboardParent: string | undefined
513
415
 
514
416
  /**
515
417
  * Used to force reset of the applet. Increment this property to reset the applet.
@@ -518,149 +420,92 @@ export class GeogebraApp extends LitElementWw {
518
420
  protected accessor resetKey: number = 0
519
421
 
520
422
  // 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
- }
423
+ private paramUpdateMap?: Map<string, (value: never) => void>
563
424
 
564
- properties.push(propConfig)
565
- })
425
+ private api?: GeogebraAPI
426
+ private listeners?: AbortController
427
+ private srcFrame = 0
428
+ @state()
429
+ private accessor ready = false
566
430
 
567
- return properties
568
- }
431
+ private resizer?: ResizeObserver
432
+ private resizeFrame = 0
433
+ private updatingGgb = false
569
434
 
570
435
  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
- }
436
+ return appletParameters(this, this.lang, sourceLocale)
592
437
  }
593
438
 
594
439
  connectedCallback(): void {
595
440
  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
441
+ this.listeners = new AbortController()
442
+ this.addEventListener("ggb-load", (e) => {
443
+ const api = e.detail.api
444
+ this.api = api
445
+ this.ready = true
446
+ this.observeSize()
447
+ api.registerAddListener(this.updateSrc)
448
+ api.registerClearListener(this.updateSrc)
449
+ api.registerUpdateListener(this.updateSrc)
450
+ api.registerRenameListener(this.updateSrc)
451
+ api.registerRemoveListener(this.updateSrc)
452
+
453
+ // showMenuBar is not updated live, because showMenuBar(false) does not work.
454
+ this.paramUpdateMap = new Map<string, (value: never) => void>([
455
+ ["width", api.setWidth],
456
+ ["height", api.setHeight],
457
+ ["enableRightClick", api.enableRightClick],
458
+ ["enableLabelDrags", api.enableLabelDrags],
459
+ ["enableShiftDragZoom", api.enableShiftDragZoom],
460
+ ["errorDialogsActive", api.setErrorDialogsActive],
461
+ ["showToolBar", api.showToolBar],
462
+ ["customToolBar", api.setCustomToolBar],
463
+ ["showAlgebraInput", api.showAlgebraInput],
464
+ ["showResetIcon", api.showResetIcon],
465
+ ["perspective", api.setPerspective],
466
+ ["enable3d", api.enable3D],
467
+ ["enableCAS", api.enableCAS],
468
+ ["rounding", api.setRounding],
469
+ ])
470
+ }, {signal: this.listeners.signal})
630
471
  }
631
472
 
632
- private handleFileImport(e: CustomEvent) {
633
- const { base64 } = e.detail
634
- this.src = `data:application/vnd.geogebra.file;base64,${base64}`
473
+ disconnectedCallback(): void {
474
+ super.disconnectedCallback()
475
+ this.listeners?.abort()
476
+ this.resizer?.disconnect()
477
+ this.resizer = undefined
478
+ cancelAnimationFrame(this.resizeFrame)
479
+ this.resizeFrame = 0
480
+ this.ready = false
481
+ if (this.srcFrame) {
482
+ cancelAnimationFrame(this.srcFrame)
483
+ this.writeSrc()
484
+ }
485
+ this.api = undefined
635
486
  }
636
487
 
637
- private updatingGgb = false
638
-
639
- protected updated(changed: PropertyValues): void {
640
- console.log("GeogebraApp updated:", changed)
488
+ protected updated(changed: PropertyValues<this>): void {
641
489
  super.updated(changed)
642
490
 
643
- if(!this.api) {
491
+ if (changed.has("src")) this.#data.set({src: this.src?.startsWith("data:") ? this.src : undefined})
492
+
493
+ const api = this.api
494
+ if(!api) {
644
495
  this.resetIFrame()
645
496
  return
646
497
  }
647
498
  if (this.paramUpdateMap) {
648
499
  let needFullReload = false
649
500
 
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
- }
501
+ changed.forEach((_, key) => {
502
+ // Saving a construction changes WebWriter's reactive data property. Only applet
503
+ // settings can require reinitialization. Construction changes are handled below.
504
+ if (!appletSettings.has(key)) return
505
+ const updateFunc = this.paramUpdateMap?.get(key.toString())
506
+ if(updateFunc) {
507
+ updateFunc.call(api, this[key as keyof this] as never)
662
508
  } else {
663
- console.log(`No update function found for property: ${propName}, reloading entire applet...`)
664
509
  needFullReload = true
665
510
  }
666
511
  })
@@ -670,32 +515,78 @@ export class GeogebraApp extends LitElementWw {
670
515
  return
671
516
  }
672
517
  }
673
-
674
518
 
675
- if(!changed.has("src") || !this.api) {
519
+ if(!changed.has("src")) {
676
520
  return
677
521
  }
678
- if(this.src && this.src.split(",").at(-1) !== this?.api?.getBase64()) {
522
+ const base64 = this.src?.split(",").at(-1)
523
+ if(this.src && base64 !== api.getBase64()) {
679
524
  this.updatingGgb = true
680
- this?.api?.setBase64(this.src.split(",").at(-1), () => {
525
+ api.setBase64(base64 ?? "", () => {
681
526
  this.updatingGgb = false
682
527
  })
683
528
  }
684
529
  else if(!this.src) {
685
530
  this.updatingGgb = true
686
- this?.api?.setBase64("", () => {
531
+ api.setBase64("", () => {
687
532
  this.updatingGgb = false
688
533
  })
689
534
  }
690
535
  }
691
536
 
692
- private apiReady: Promise<GeogebraAPI>
693
- private api?: GeogebraAPI
537
+ async importConstruction(files: File[]) {
538
+ const file = files[0]
539
+ if (!file || !this.isConnected) return
540
+ this.src = ggbDataUrl(bytesToBase64(new Uint8Array(await file.arrayBuffer())))
541
+ }
542
+
543
+ async importGgb(file: File) {
544
+ const bytes = new Uint8Array(await file.arrayBuffer())
545
+ if (!isGgbArchive(bytes)) throw new Error(this.msg("The file is not a GeoGebra construction (.ggb)."))
546
+ const src = ggbDataUrl(bytesToBase64(bytes))
547
+ return () => { this.src = src }
548
+ }
549
+
550
+ exportGgb() {
551
+ const base64 = this.api?.getBase64() || dataUrlPayload(this.src)
552
+ if (!base64) return null
553
+ return new File([base64ToBytes(base64) as BlobPart], "construction.ggb", {type: GGB_MEDIA_TYPE})
554
+ }
555
+
556
+ exportPng() {
557
+ const base64 = this.api?.getPNGBase64(1, false, 72)
558
+ if (!base64) return null
559
+ return new File([base64ToBytes(base64) as BlobPart], "construction.png", {type: "image/png"})
560
+ }
561
+
562
+ exportSvg() {
563
+ const api = this.api
564
+ if (!api) return null
565
+ return new Promise<File | null>(resolve => {
566
+ const timeout = setTimeout(() => resolve(null), 8000)
567
+ api.exportSVG((svg: string) => {
568
+ clearTimeout(timeout)
569
+ resolve(svg ? new File([svg], "construction.svg", {type: "image/svg+xml"}) : null)
570
+ })
571
+ })
572
+ }
573
+
574
+ // Serializing the construction is costly and the applet reports every change of a drag, so it runs once per frame.
575
+ private updateSrc = () => {
576
+ if (this.updatingGgb || !this.api || this.srcFrame) return
577
+ this.srcFrame = requestAnimationFrame(this.writeSrc)
578
+ }
579
+
580
+ private writeSrc = () => {
581
+ this.srcFrame = 0
582
+ if(!this.updatingGgb && this.api) {
583
+ this.src = `data:application/vnd.geogebra.file;base64,${this.api.getBase64()}`
584
+ }
585
+ }
694
586
 
695
587
  private initializeIFrame(iframe: HTMLIFrameElement) {
696
588
  const doc = iframe.contentDocument
697
- const win = iframe.contentWindow
698
- if (doc.getElementById("ggb-element")) {
589
+ if (!doc || doc.getElementById("ggb-element")) {
699
590
  return
700
591
  }
701
592
  doc.body.style.margin = "0"
@@ -716,37 +607,51 @@ export class GeogebraApp extends LitElementWw {
716
607
  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
608
  applet.inject("ggb-element")
718
609
  `
719
- doc.addEventListener("ggb-load", (e: any) => this.dispatchEvent(new CustomEvent("ggb-load", {bubbles: true, composed: true, detail: e.detail})))
610
+ doc.addEventListener("ggb-load", (e) => this.dispatchEvent(new CustomEvent("ggb-load", {bubbles: true, composed: true, detail: (e as CustomEvent<{api: GeogebraAPI}>).detail})))
720
611
  doc.body.append(createScript)
721
612
  })
722
613
  doc.body.append(deployScript)
723
614
  }
724
615
 
616
+ // The applet follows the size of the iframe, which follows the container; one resize per frame avoids loops.
617
+ private observeSize() {
618
+ const iframe = this.renderRoot.querySelector("iframe")
619
+ if (!iframe) return
620
+ this.resizer?.disconnect()
621
+ let last = ""
622
+ this.resizer = new ResizeObserver(() => {
623
+ cancelAnimationFrame(this.resizeFrame)
624
+ this.resizeFrame = requestAnimationFrame(() => {
625
+ const {width, height} = iframe.getBoundingClientRect()
626
+ const size = `${Math.round(width)}x${Math.round(height)}`
627
+ if (!this.api || !iframe.isConnected || width < 1 || size === last) return
628
+ last = size
629
+ this.api.setSize(Math.round(width), Math.round(height))
630
+ })
631
+ })
632
+ this.resizer.observe(iframe)
633
+ }
634
+
635
+ focus(options?: FocusOptions) {
636
+ this.renderRoot.querySelector("iframe")?.focus(options)
637
+ }
638
+
725
639
  private resetIFrame() {
726
640
  if(!this.api) {
727
641
  return
728
642
  }
729
643
 
730
644
  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
-
645
+ this.ready = false
737
646
  this.resetKey++
738
647
  }
739
648
 
740
649
  render() {
741
650
  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>
651
+ <div class="applet" ?data-ready=${this.ready}>
652
+ ${keyed(this.resetKey, html`<iframe id="ggb" part="applet" title=${this.msg("GeoGebra applet")} @load=${(e: Event) => this.initializeIFrame(e.target as HTMLIFrameElement)}></iframe>`)}
653
+ <p class="print-note">${this.msg("Interactive content: open the document online to use the GeoGebra applet.")}</p>
654
+ </div>
750
655
  `
751
656
  }
752
- }
657
+ }