@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
@@ -0,0 +1,148 @@
1
+ export interface GeogebraAPI {
2
+ evalCommand(cmdString: string): boolean
3
+ evalLaTex(input: string): boolean
4
+ evalCommandGetLabels(cmdString: string): string
5
+ evalCommandCAS(text: string): string
6
+ insertEmbed(type: string, uri: string): void
7
+ deleteObject(objName: string): void
8
+ setAuxiliary(geo: any, status: boolean): void
9
+ setValue(objName: string, value: number): void
10
+ setTextValue(objName: string, value: string): void
11
+ setListValue(objName: string, i: number, value: number): void
12
+ setCoords(objName: string, x: number, y: number, z?: number): void
13
+ setCaption(objName: string, caption: string): void
14
+ setColor(objName: string, red: number, green: number, blue: number): void
15
+ setVisible(objName: string, visible: boolean): void
16
+ setLabelVisible(objName: string, visible: boolean): void
17
+ setLabelStyle(objName: string, style: 0 | 1 | 2 | 3): void
18
+ setFixed(objName: string, fixed: boolean, selectionAllowed: boolean): void
19
+ setTrace(objName: string, flag: boolean): void
20
+ renameObject(oldObjName: string, newObjName: string): boolean
21
+ setLayer(objName: string, layer: number): void
22
+ setLayerVisible(objName: string, visible: boolean): void
23
+ setLineStyle(objName: string, style: 0 | 1 | 2 | 3 | 4): void
24
+ setLineThickness(objName: string, thickness: -1 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13): void
25
+ setPointStyle(objName: string, size: -1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9): void
26
+ setPointSize(objName: string, size: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9): void
27
+ setDisplayStyle(objName: string, style: string): void
28
+ setFilling(objName: string, filling: number): void
29
+ getPNGBase64(exportScale: number, transparent?: boolean, dpi?: number): string
30
+ exportSVG(filename: string): void
31
+ exportSVG(callback: CallableFunction): void
32
+ exportPDF(scale: number, filename: string, sliderLabel?: string): void
33
+ exportPDF(scale: number, callback: CallableFunction, sliderLabel?: string): void
34
+ getScreenshotBase64(callback: CallableFunction): void
35
+ writePNGtoFile(fileName: string, exportScale?: number, transparent?: boolean, dpi?: number): boolean
36
+ isIndependent(objName: string): boolean
37
+ isMovable(objName: string): boolean
38
+ showAllObjects(): void
39
+ registerEmbedResolver(type: string, callback: CallableFunction): void
40
+ setAnimating(objName: string, animate: boolean): void
41
+ setAnimationSpeed(objName: string, speed: number): void
42
+ startAnimation(): void
43
+ stopAnimation(): void
44
+ isAnimationRunning(): boolean
45
+ getXcoord(objName: string): number
46
+ getYcoord(objName: string): number
47
+ getZcoord(objName: string): number
48
+ getValue(objName: string): number
49
+ getListValue(objName: string, index: number): number
50
+ getColor(objName: string): string
51
+ getVisible(objName: string): boolean
52
+ getValueString(objName: string, useLocalizedInput?: boolean): string
53
+ getDefinitionString(objName: string): string
54
+ getCommandString(objName: string, useLocalizedInput?: boolean): string
55
+ getLaTeXString(objName: string, value: boolean): string
56
+ getObjectType(objName: string): string
57
+ exists(objName: string): boolean
58
+ isDefined(objName: string): boolean
59
+ getAllObjectNames(type?: string): string[]
60
+ getObjectNumber(): number
61
+ getCASObjectNumber(): number
62
+ getObjectName(i: number): string
63
+ getLayer(objName: string): string
64
+ getLineStyle(objName: string): 0 | 1 | 2 | 3 | 4
65
+ getLineThickness(objName: string): -1 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13
66
+ getPointStyle(objName: string): -1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
67
+ getPointSize(objName: string): 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
68
+ getFilling(objName: string): number
69
+ getCaption(objName: string, substitutePlaceholders?: boolean): string
70
+ getLabelStyle(objName: string): 0 | 1 | 2 | 3
71
+ getLabelVisible(): boolean
72
+ isInteractive(objName: string): boolean
73
+ setMode(mode: number): void
74
+ getMode(): number
75
+ reset(): void
76
+ newConstruction(): void
77
+ refreshViews(): void
78
+ setOnTheFlyPointCreationActive(flag: boolean): void
79
+ setPointCapture(view: -1 | 1 | 2, mode: 0 | 1 | 2 | 3): void
80
+ setRounding(round: string): void
81
+ hideCursorWhenDragging(flag: boolean): void
82
+ setRepaintingActive(flag: boolean): void
83
+ setErrorDialogsActive(flag: boolean): void
84
+ setCoordSystem(xmin: number, xmax: number, ymin: number, ymax: number, zmin?: number, zmax?: number, yVertical?: boolean): void
85
+ setAxesVisible(xAxis: boolean, yAxis: boolean, zAxis?: boolean): void
86
+ setUndoPoint(): void
87
+ setAxisLabels(viewNumber: number, xAxis: string, yAxis: string, zAxis: string): void
88
+ setAxisSteps(viewNumber: number, xAxis: number, yAxis: number, zAxis: number): void
89
+ setAxisUnits(viewNumber: number, xAxis: string, yAxis: string, zAxis: string): void
90
+ setGridVisible(flag: boolean): void
91
+ setGridVisible(viewNumber: number, flag: boolean): void
92
+ getGridVisible(viewNumber: number): boolean
93
+ getPerspectiveXML(): string
94
+ undo(): void
95
+ redo(): void
96
+ showToolBar(show: boolean): void
97
+ setCustomToolBar(toolbar: string): void
98
+ addCustomTool(iconURL: string, name: string, category?: string, callback?: CallableFunction): void
99
+ showMenuBar(show: boolean): void
100
+ showAlgebraInput(show: boolean): void
101
+ showResetIcon(show: boolean): void
102
+ enableRightClick(enable: boolean): void
103
+ enableLabelDrags(enable: boolean): void
104
+ enableShiftDragZoom(enable: boolean): void
105
+ enableCAS(enable: boolean): void
106
+ enable3D(enable: boolean): void
107
+ setPerspective(perspective: string): void
108
+ setWidth(width: number): void
109
+ setHeight(height: number): void
110
+ setSize(width: number, height: number): void
111
+ recalculateEnvironments(): void
112
+ getEditorState(): any
113
+ setEditorState(state: any): void
114
+ getGraphicsOptions(viewId: number): any
115
+ setGraphicsOptions(viewID: number, options: any): void
116
+ setAlgebraOptions(options: any): void
117
+ registerAddListener(func: CallableFunction): void
118
+ unregisterAddListener(func: CallableFunction): void
119
+ registerRemoveListener(func: CallableFunction): void
120
+ unregisterRemoveListener(func: CallableFunction): void
121
+ registerUpdateListener(func: CallableFunction): void
122
+ unregisterUpdateListener(func: CallableFunction): void
123
+ registerClickListener(func: CallableFunction): void
124
+ unregisterClickListener(func: CallableFunction): void
125
+ registerObjectUpdateListener(objName: string, func: CallableFunction): void
126
+ unregisterObjectUpdateListener(objName: string): void
127
+ registerObjectClickListener(objName: string, func: CallableFunction): void
128
+ unregisterObjectClickListener(objName: string): void
129
+ registerRenameListener(func: CallableFunction): void
130
+ unregisterRenameListener(func: CallableFunction): void
131
+ registerClearListener(func: CallableFunction): void
132
+ unregisterClearListener(func: CallableFunction): void
133
+ registerStoreUndoListener(func: CallableFunction): void
134
+ unregisterStoreUndoListener(func: CallableFunction): void
135
+ registerClientListener(func: CallableFunction): void
136
+ unregisterClientListener(func: CallableFunction): void
137
+ evalXML(xmlString: string): void
138
+ setXML(xmlString: string): void
139
+ getXML(objName?: string): string
140
+ getAlgorithmXML(objName: string): string
141
+ getFileJSON(): any
142
+ setFileJSON(content: any): void
143
+ getBase64(callback?: CallableFunction): string
144
+ setBase64(value: string, callback?: CallableFunction): void
145
+ debug(str: string): void
146
+ getVersion(): string
147
+ remove(): void
148
+ }
@@ -0,0 +1,72 @@
1
+ type Labelled = {msg: (source: string) => string}
2
+
3
+ /** Editor option declarations of the GeoGebra widgets. */
4
+ export const geogebraOptions = {
5
+ type: {type: "select" as const, control: "select" as const, label: (widget: Labelled) => ({_: widget.msg("Type")}), options: [
6
+ {value: "classic", label: (widget: Labelled) => ({_: widget.msg("Classic")})},
7
+ {value: "geometry", label: (widget: Labelled) => ({_: widget.msg("Geometry")})},
8
+ {value: "3d", label: (widget: Labelled) => ({_: widget.msg("3D")})},
9
+ {value: "suite", label: (widget: Labelled) => ({_: widget.msg("Calculator Suite")})},
10
+ {value: "evaluator", label: (widget: Labelled) => ({_: widget.msg("Evaluator")})},
11
+ {value: "scientific", label: (widget: Labelled) => ({_: widget.msg("Scientific")})},
12
+ {value: "notes", label: (widget: Labelled) => ({_: widget.msg("Notes")})},
13
+ ]},
14
+ borderColor: {type: String, label: (widget: Labelled) => ({_: widget.msg("Border color")})},
15
+ borderRadius: {type: Number, label: (widget: Labelled) => ({_: widget.msg("Border radius")})},
16
+ enableRightClick: {type: Boolean, label: (widget: Labelled) => ({_: widget.msg("Enable right click")})},
17
+ enableLabelDrags: {type: Boolean, label: (widget: Labelled) => ({_: widget.msg("Allow dragging labels")})},
18
+ enableShiftDragZoom: {type: Boolean, label: (widget: Labelled) => ({_: widget.msg("Enable Shift-drag zoom")})},
19
+ showZoomButtons: {type: Boolean, label: (widget: Labelled) => ({_: widget.msg("Show zoom buttons")})},
20
+ errorDialogsActive: {type: Boolean, label: (widget: Labelled) => ({_: widget.msg("Show error dialogs")})},
21
+ showMenuBar: {type: Boolean, label: (widget: Labelled) => ({_: widget.msg("Show menu bar")})},
22
+ showToolBar: {type: Boolean, label: (widget: Labelled) => ({_: widget.msg("Show toolbar")})},
23
+ showToolBarHelp: {type: Boolean, label: (widget: Labelled) => ({_: widget.msg("Show toolbar help")})},
24
+ customToolBar: {type: String, label: (widget: Labelled) => ({_: widget.msg("Custom toolbar")})},
25
+ showAlgebraInput: {type: Boolean, label: (widget: Labelled) => ({_: widget.msg("Show algebra input")})},
26
+ showResetIcon: {type: Boolean, label: (widget: Labelled) => ({_: widget.msg("Show reset icon")})},
27
+ language: {type: String, label: (widget: Labelled) => ({_: widget.msg("Language")})},
28
+ country: {type: String, label: (widget: Labelled) => ({_: widget.msg("Country")})},
29
+ appletId: {type: String, label: (widget: Labelled) => ({_: widget.msg("Applet ID")})},
30
+ allowStyleBar: {type: Boolean, label: (widget: Labelled) => ({_: widget.msg("Allow style bar")})},
31
+ randomize: {type: Boolean, label: (widget: Labelled) => ({_: widget.msg("Randomize")})},
32
+ randomSeed: {type: Number, label: (widget: Labelled) => ({_: widget.msg("Random seed")})},
33
+ useBrowserForJs: {type: Boolean, label: (widget: Labelled) => ({_: widget.msg("Use browser for JavaScript")})},
34
+ showLogging: {type: Boolean, label: (widget: Labelled) => ({_: widget.msg("Show log messages")})},
35
+ capturingThreshold: {type: Number, label: (widget: Labelled) => ({_: widget.msg("Point capture threshold")})},
36
+ enableFileFeatures: {type: Boolean, label: (widget: Labelled) => ({_: widget.msg("Enable file features")})},
37
+ enableUndoRedo: {type: Boolean, label: (widget: Labelled) => ({_: widget.msg("Enable undo and redo")})},
38
+ perspective: {type: String, label: (widget: Labelled) => ({_: widget.msg("Perspective")})},
39
+ enable3d: {type: Boolean, label: (widget: Labelled) => ({_: widget.msg("Enable 3D")})},
40
+ enableCAS: {type: Boolean, label: (widget: Labelled) => ({_: widget.msg("Enable CAS")})},
41
+ algebraInputPosition: {type: "select" as const, label: (widget: Labelled) => ({_: widget.msg("Algebra input position")}), options: [
42
+ {value: "algebra", label: (widget: Labelled) => ({_: widget.msg("Algebra")})},
43
+ {value: "top", label: (widget: Labelled) => ({_: widget.msg("Top")})},
44
+ {value: "bottom", label: (widget: Labelled) => ({_: widget.msg("Bottom")})},
45
+ ]},
46
+ preventFocus: {type: Boolean, label: (widget: Labelled) => ({_: widget.msg("Prevent focus")})},
47
+ scaleContainerClass: {type: String, label: (widget: Labelled) => ({_: widget.msg("Scale container CSS class")})},
48
+ autoHeight: {type: Boolean, label: (widget: Labelled) => ({_: widget.msg("Automatic height")})},
49
+ allowUpscale: {type: Boolean, label: (widget: Labelled) => ({_: widget.msg("Allow upscaling")})},
50
+ playButton: {type: Boolean, label: (widget: Labelled) => ({_: widget.msg("Play button")})},
51
+ scale: {type: Number, label: (widget: Labelled) => ({_: widget.msg("Scale")})},
52
+ showAnimationButton: {type: Boolean, label: (widget: Labelled) => ({_: widget.msg("Show animation button")})},
53
+ showFullscreenButton: {type: Boolean, label: (widget: Labelled) => ({_: widget.msg("Show fullscreen button")})},
54
+ showSuggestionButtons: {type: Boolean, label: (widget: Labelled) => ({_: widget.msg("Show suggestion buttons")})},
55
+ showStartTooltip: {type: Boolean, label: (widget: Labelled) => ({_: widget.msg("Show startup tooltip")})},
56
+ rounding: {type: String, label: (widget: Labelled) => ({_: widget.msg("Rounding")})},
57
+ buttonShadows: {type: Boolean, label: (widget: Labelled) => ({_: widget.msg("Button shadows")})},
58
+ buttonRounding: {type: Number, label: (widget: Labelled) => ({_: widget.msg("Button corner rounding")})},
59
+ buttonBorderColor: {type: String, label: (widget: Labelled) => ({_: widget.msg("Button border color")})},
60
+ editorBackgroundColor: {type: String, label: (widget: Labelled) => ({_: widget.msg("Editor background color")})},
61
+ editorForegroundColor: {type: String, label: (widget: Labelled) => ({_: widget.msg("Editor foreground color")})},
62
+ textmode: {type: Boolean, label: (widget: Labelled) => ({_: widget.msg("Text mode")})},
63
+ showKeyboardOnFocus: {type: Boolean, label: (widget: Labelled) => ({_: widget.msg("Show keyboard on focus")})},
64
+ keyboardType: {type: "select" as const, label: (widget: Labelled) => ({_: widget.msg("Keyboard type")}), options: [
65
+ {value: "scientific", label: (widget: Labelled) => ({_: widget.msg("Scientific")})},
66
+ {value: "normal", label: (widget: Labelled) => ({_: widget.msg("Normal")})},
67
+ {value: "notes", label: (widget: Labelled) => ({_: widget.msg("Notes")})},
68
+ ]},
69
+ transparentGraphics: {type: Boolean, label: (widget: Labelled) => ({_: widget.msg("Transparent graphics")})},
70
+ disabledJavaScript: {type: Boolean, label: (widget: Labelled) => ({_: widget.msg("Disable JavaScript")})},
71
+ detachedKeyboardParent: {type: String, label: (widget: Labelled) => ({_: widget.msg("Detached keyboard parent")})},
72
+ }
@@ -0,0 +1,53 @@
1
+ // Properties of the widget that are handed to the applet as they are.
2
+ export const passThroughParameters = [
3
+ "width", "height", "borderColor", "borderRadius", "enableRightClick", "enableLabelDrags", "enableShiftDragZoom",
4
+ "showZoomButtons", "errorDialogsActive", "showMenuBar", "showToolBar", "showToolBarHelp", "customToolBar",
5
+ "showAlgebraInput", "showResetIcon",
6
+ ] as const
7
+
8
+ export const passThroughParametersAfterLocale = [
9
+ "allowStyleBar", "randomize", "randomSeed", "useBrowserForJs", "showLogging", "capturingThreshold",
10
+ "enableFileFeatures", "perspective", "enable3d", "enableCAS", "algebraInputPosition", "preventFocus",
11
+ "scaleContainerClass", "autoHeight", "allowUpscale", "playButton", "scale", "showAnimationButton",
12
+ "showFullscreenButton", "showSuggestionButtons", "showStartTooltip", "rounding", "buttonShadows",
13
+ "buttonRounding", "buttonBorderColor", "editorBackgroundColor", "editorForegroundColor", "textmode",
14
+ "showKeyboardOnFocus", "keyboardType", "transparentGraphics", "disabledJavaScript", "detachedKeyboardParent",
15
+ ] as const
16
+
17
+ type Source = {
18
+ appletId?: string
19
+ type: string
20
+ src?: string
21
+ language?: string
22
+ country?: string
23
+ } & Record<(typeof passThroughParameters)[number] | (typeof passThroughParametersAfterLocale)[number], unknown>
24
+
25
+ /** Maps the widget's properties to the parameters of the GeoGebra applet (deployggb.js). */
26
+ export function appletParameters(source: Source, lang: string, sourceLocale: string) {
27
+ let locale: Intl.Locale
28
+ try {
29
+ locale = new Intl.Locale(lang.trim() || sourceLocale)
30
+ } catch (error) {
31
+ if (!(error instanceof RangeError)) throw error
32
+ locale = new Intl.Locale(sourceLocale)
33
+ }
34
+
35
+ let filename: string | undefined, material_id: string | undefined, ggbBase64: string | undefined
36
+ const {src, language} = source
37
+ if (src?.startsWith("data:")) ggbBase64 = src.split(",").at(-1)
38
+ else if (src?.startsWith("ggbid:")) material_id = src.slice("ggbid:".length)
39
+ else if (src) filename = src
40
+
41
+ const pick = (keys: readonly (keyof Source)[]) => Object.fromEntries(keys.map(key => [key, source[key]]))
42
+ return {
43
+ id: source.appletId,
44
+ appName: source.type,
45
+ filename,
46
+ material_id,
47
+ ggbBase64,
48
+ ...pick(passThroughParameters),
49
+ language: language ?? locale.language,
50
+ country: source.country ?? (language ? undefined : locale.region ?? (locale.script ? locale.maximize().region : undefined)),
51
+ ...pick(passThroughParametersAfterLocale),
52
+ }
53
+ }
@@ -0,0 +1,30 @@
1
+ export const GGB_MEDIA_TYPE = "application/vnd.geogebra.file"
2
+
3
+ const ZIP_MAGIC = [0x50, 0x4b, 0x03, 0x04]
4
+
5
+ /** True when the bytes start like a zip archive, which every .ggb file is. */
6
+ export function isGgbArchive(bytes: Uint8Array): boolean {
7
+ return bytes.length > ZIP_MAGIC.length && ZIP_MAGIC.every((value, index) => bytes[index] === value)
8
+ }
9
+
10
+ export function bytesToBase64(bytes: Uint8Array): string {
11
+ let binary = ""
12
+ for (let index = 0; index < bytes.length; index += 0x8000) {
13
+ binary += String.fromCharCode(...bytes.subarray(index, index + 0x8000))
14
+ }
15
+ return btoa(binary)
16
+ }
17
+
18
+ export function base64ToBytes(base64: string): Uint8Array {
19
+ const binary = atob(base64)
20
+ const bytes = new Uint8Array(binary.length)
21
+ for (let index = 0; index < binary.length; index++) bytes[index] = binary.charCodeAt(index)
22
+ return bytes
23
+ }
24
+
25
+ export const ggbDataUrl = (base64: string) => `data:${GGB_MEDIA_TYPE};base64,${base64}`
26
+
27
+ /** The base64 payload of a data URL, or undefined for any other source (a file URL or "ggbid:" material). */
28
+ export function dataUrlPayload(src: string | undefined): string | undefined {
29
+ return src?.startsWith("data:") ? src.split(",").at(-1) : undefined
30
+ }
package/src/types.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ declare module "@webwriter/build/test" {
2
+ export function getMochaConfig(): Mocha.MochaOptions
3
+ }
@@ -5,7 +5,7 @@ import { GeogebraApp } from "../components/geogebra-app"
5
5
  * A GeoGebra 3D Graphing Calculator widget.
6
6
  */
7
7
  @customElement("webwriter-geogebra-3d")
8
- export class WebwriterGeogebra3D extends GeogebraApp {
8
+ export class WebwriterGeogebra3d extends GeogebraApp {
9
9
  constructor() {
10
10
  super()
11
11
  this.type = "3d" as const
@@ -1,5 +1,4 @@
1
- import {html, css} from "lit"
2
- import {LitElementWw} from "@webwriter/lit"
1
+ import {css} from "lit"
3
2
  import {customElement} from "lit/decorators.js"
4
3
  import { GeogebraApp } from "../components/geogebra-app"
5
4
 
@@ -0,0 +1,80 @@
1
+ /// <reference types="mocha" />
2
+ import "mocha/mocha.js";
3
+ import { assert } from "chai";
4
+ import { getMochaConfig } from "@webwriter/build/test";
5
+ import "../src/widgets/webwriter-geogebra-classic";
6
+ import { mountIn, unmountAll, SRC_A, SRC_B } from "./helpers";
7
+ import { bytesToBase64, base64ToBytes, isGgbArchive } from "../src/model/ggb-file";
8
+
9
+ mocha.setup(getMochaConfig());
10
+
11
+ const TAG = "webwriter-geogebra-classic";
12
+ const zip = new Uint8Array([0x50, 0x4b, 0x03, 0x04, 1, 2, 3, 4]);
13
+ const ggbFile = (bytes: Uint8Array, name = "valid.ggb") => new File([bytes as BlobPart], name, {type: ""});
14
+
15
+ describe("conversions", function () {
16
+ afterEach(unmountAll);
17
+
18
+ it("declares the same file keys in the runtime maps", function () {
19
+ const widget = customElements.get(TAG) as any;
20
+ assert.deepEqual(Object.keys(widget.convertFrom), [".ggb"]);
21
+ assert.deepEqual(Object.keys(widget.convertTo), [".ggb", "image/png", "image/svg+xml"]);
22
+ });
23
+
24
+ it("encodes and decodes the bytes of a construction", function () {
25
+ assert.equal(bytesToBase64(zip), btoa("PK\x03\x04\x01\x02\x03\x04"));
26
+ assert.deepEqual([...base64ToBytes(bytesToBase64(zip))], [...zip]);
27
+ assert.isFalse(isGgbArchive(new Uint8Array([1, 2, 3, 4, 5])));
28
+ });
29
+
30
+ it("imports a .ggb file only when the apply function runs", async function () {
31
+ const widget = await mountIn(`<${TAG} src="https://example.org/a.ggb"></${TAG}>`, TAG);
32
+ const apply = await widget.importGgb(ggbFile(zip));
33
+ assert.equal(widget.src, "https://example.org/a.ggb");
34
+ apply();
35
+ assert.equal(widget.src, `data:application/vnd.geogebra.file;base64,${bytesToBase64(zip)}`);
36
+ });
37
+
38
+ it("refuses a file that is no zip archive without touching the widget", async function () {
39
+ const widget = await mountIn(`<${TAG}></${TAG}>`, TAG);
40
+ let message = "";
41
+ try { await widget.importGgb(ggbFile(new TextEncoder().encode("not a zip"), "bad.ggb")) }
42
+ catch (error) { message = (error as Error).message }
43
+ assert.match(message, /GeoGebra construction/);
44
+ assert.isUndefined(widget.src);
45
+ });
46
+
47
+ it("exports the construction as .ggb and round-trips it", async function () {
48
+ const widget = await mountIn(`<${TAG}></${TAG}>`, TAG);
49
+ assert.isNull(widget.exportGgb());
50
+ widget.src = SRC_A;
51
+ const fromSrc = widget.exportGgb() as File;
52
+ assert.equal(fromSrc.name, "construction.ggb");
53
+ assert.equal(new TextDecoder().decode(await fromSrc.arrayBuffer()), "AAAA");
54
+ widget.api = {getBase64: () => SRC_B.split(",")[1]};
55
+ const live = widget.exportGgb() as File;
56
+ assert.equal(new TextDecoder().decode(await live.arrayBuffer()), "BBBB");
57
+ // Round trip: the exported bytes are a valid import for a second widget.
58
+ const again = await mountIn(`<${TAG}></${TAG}>`, TAG);
59
+ widget.api = {getBase64: () => bytesToBase64(zip)};
60
+ (await again.importGgb(await widget.exportGgb()))();
61
+ assert.equal(again.src, `data:application/vnd.geogebra.file;base64,${bytesToBase64(zip)}`);
62
+ });
63
+
64
+ it("exports the picture through the applet and declines without an applet", async function () {
65
+ const widget = await mountIn(`<${TAG}></${TAG}>`, TAG);
66
+ assert.isNull(widget.exportPng());
67
+ assert.isNull(widget.exportSvg());
68
+ widget.api = {
69
+ getPNGBase64: () => btoa("png"),
70
+ exportSVG: (callback: (svg: string) => void) => callback("<svg xmlns='http://www.w3.org/2000/svg'/>"),
71
+ };
72
+ const png = widget.exportPng() as File;
73
+ assert.equal(png.type, "image/png");
74
+ const svg = await widget.exportSvg() as File;
75
+ assert.equal(svg.type, "image/svg+xml");
76
+ assert.include(await svg.text(), "<svg");
77
+ });
78
+ });
79
+
80
+ mocha.run();
@@ -0,0 +1,72 @@
1
+ /// <reference types="mocha" />
2
+ import "mocha/mocha.js";
3
+ import { assert } from "chai";
4
+ import { getMochaConfig } from "@webwriter/build/test";
5
+ import "../src/widgets/webwriter-geogebra";
6
+ import { SRC_A, SRC_B, json, wait, until, mount, unmountAll, dataBlock } from "./helpers";
7
+
8
+ mocha.setup(getMochaConfig());
9
+
10
+ for (const mode of ["read", "edit"] as const) {
11
+ describe(`<webwriter-geogebra> data block (${mode} mode)`, function () {
12
+ const attrs = mode === "edit" ? ` contenteditable=""` : "";
13
+
14
+ beforeEach(function () {
15
+ document.designMode = mode === "edit" ? "on" : "off";
16
+ });
17
+ afterEach(unmountAll);
18
+
19
+ it("reads the data block on connect", async function () {
20
+ const el = await mount(`<webwriter-geogebra${attrs}><script type="application/json" slot="data">${json(SRC_A)}</script></webwriter-geogebra>`);
21
+ assert.isTrue(await until(() => el.src === SRC_A), `src is ${el.src}`);
22
+ assert.isFalse(el.hasAttribute("src"), "a data URL must not be reflected as an attribute");
23
+ });
24
+
25
+ it("creates the data block when src is set", async function () {
26
+ const el = await mount(`<webwriter-geogebra${attrs}></webwriter-geogebra>`);
27
+ assert.isNull(dataBlock(el), "no block before a construction");
28
+ el.src = SRC_B;
29
+ assert.isTrue(await until(() => dataBlock(el)), "block was not created");
30
+ const block = dataBlock(el)!;
31
+ assert.equal(block.type, "application/json");
32
+ assert.equal(block.slot, "data");
33
+ assert.equal(JSON.parse(block.textContent!).src, SRC_B);
34
+ assert.isFalse(el.hasAttribute("src"), "a data URL must not be reflected as an attribute");
35
+ });
36
+
37
+ it("replaces the value in the same block on a later src", async function () {
38
+ const el = await mount(`<webwriter-geogebra${attrs}><script type="application/json" slot="data">${json(SRC_A)}</script></webwriter-geogebra>`);
39
+ assert.isTrue(await until(() => el.src === SRC_A));
40
+ const block = dataBlock(el)!;
41
+ el.src = SRC_B;
42
+ assert.isTrue(await until(() => JSON.parse(block.textContent!).src === SRC_B), block.textContent!);
43
+ assert.strictEqual(dataBlock(el), block);
44
+ assert.equal(el.querySelectorAll("script").length, 1, "one block is kept");
45
+ });
46
+
47
+ it("updates the widget when the block changes", async function () {
48
+ const el = await mount(`<webwriter-geogebra${attrs}><script type="application/json" slot="data">${json(SRC_A)}</script></webwriter-geogebra>`);
49
+ assert.isTrue(await until(() => el.src === SRC_A));
50
+ dataBlock(el)!.textContent = json(SRC_B);
51
+ assert.isTrue(await until(() => el.src === SRC_B), `src is ${el.src}`);
52
+ });
53
+
54
+ it("keeps a file URL as an attribute and not in the block", async function () {
55
+ const el = await mount(`<webwriter-geogebra${attrs}></webwriter-geogebra>`);
56
+ el.src = "https://example.org/a.ggb";
57
+ assert.isTrue(await until(() => el.getAttribute("src") === "https://example.org/a.ggb"), "attribute");
58
+ await wait(300);
59
+ assert.isNull(dataBlock(el), "no block for a URL");
60
+ });
61
+
62
+ it("keeps unknown keys in the block", async function () {
63
+ const el = await mount(`<webwriter-geogebra${attrs}><script type="application/json" slot="data">{"src":"${SRC_A}","other":1}</script></webwriter-geogebra>`);
64
+ assert.isTrue(await until(() => el.src === SRC_A));
65
+ el.src = SRC_B;
66
+ assert.isTrue(await until(() => JSON.parse(dataBlock(el)!.textContent!).src === SRC_B));
67
+ assert.equal(JSON.parse(dataBlock(el)!.textContent!).other, 1, dataBlock(el)!.textContent!);
68
+ });
69
+ });
70
+ }
71
+
72
+ mocha.run();
@@ -0,0 +1,48 @@
1
+ export const SRC_A = "data:application/vnd.geogebra.file;base64,QUFBQQ=="
2
+ export const SRC_B = "data:application/vnd.geogebra.file;base64,QkJCQg=="
3
+
4
+ export const json = (src: string) => JSON.stringify({src})
5
+
6
+ export const wait = (ms: number) => new Promise<void>(resolve => setTimeout(resolve, ms))
7
+
8
+ export async function until(condition: () => unknown, ms = 20000) {
9
+ const end = performance.now() + ms
10
+ while (performance.now() < end) {
11
+ if (await condition()) return true
12
+ await wait(50)
13
+ }
14
+ return false
15
+ }
16
+
17
+ export async function mount<T extends HTMLElement = any>(html: string): Promise<T> {
18
+ const host = document.createElement("div")
19
+ host.className = "test-mount"
20
+ document.body.append(host)
21
+ host.innerHTML = html
22
+ const el = host.firstElementChild as any
23
+ await Promise.race([
24
+ customElements.whenDefined(el.localName),
25
+ wait(5000).then(() => { throw new Error(el.localName + " is not defined") })
26
+ ])
27
+ await el.updateComplete
28
+ return el
29
+ }
30
+
31
+ export function unmountAll() {
32
+ document.querySelectorAll(".test-mount").forEach(host => host.remove())
33
+ document.designMode = "off"
34
+ }
35
+
36
+ export const dataBlock = (el: Element) =>
37
+ el.querySelector<HTMLScriptElement>(':scope > script[type="application/json"][slot="data"]')
38
+
39
+ export async function mountIn<T extends HTMLElement = any>(html: string, selector: string): Promise<T> {
40
+ const host = document.createElement("div")
41
+ host.className = "test-mount"
42
+ document.body.append(host)
43
+ host.innerHTML = html
44
+ const el = host.querySelector(selector) as any
45
+ await customElements.whenDefined(selector)
46
+ await el.updateComplete
47
+ return el
48
+ }
@@ -0,0 +1,49 @@
1
+ /// <reference types="mocha" />
2
+ import "mocha/mocha.js";
3
+ import { assert } from "chai";
4
+ import { getMochaConfig } from "@webwriter/build/test";
5
+ import "../src/widgets/webwriter-geogebra";
6
+ import "../src/widgets/webwriter-geogebra-geometry";
7
+ import { until, mount, mountIn, unmountAll } from "./helpers";
8
+
9
+ mocha.setup(getMochaConfig());
10
+
11
+ describe("language and declarations", function () {
12
+ afterEach(unmountAll);
13
+
14
+ it("lang on an ancestor selects the catalog and the drawer text", async function () {
15
+ const widget = await mountIn(`<div lang="de"><webwriter-geogebra></webwriter-geogebra></div>`, "webwriter-geogebra");
16
+ await widget.updateComplete;
17
+ let changed = 0;
18
+ widget.addEventListener("optionschange", () => changed++, true);
19
+ assert.isTrue(await until(() => widget.localize.getLocale() === "de"), `locale ${widget.localize.getLocale()}`);
20
+ assert.isTrue(await until(() => widget.options.enableRightClick.label._ !== "Enable right click"), "label stays English");
21
+ const german = widget.options.enableRightClick.label._;
22
+ widget.parentElement.setAttribute("lang", "fr");
23
+ assert.isTrue(await until(() => widget.localize.getLocale() === "fr"), "locale fr");
24
+ assert.isTrue(await until(() => widget.options.enableRightClick.label._ !== german), "label did not change with the language");
25
+ assert.isAbove(changed, 0, "optionschange was not sent");
26
+ assert.isFalse(widget.hasAttribute("lang"), "an inherited language must not be written to the widget");
27
+ });
28
+
29
+ it("the applet language follows the tag and a bad tag falls back", async function () {
30
+ const widget = await mountIn(`<div lang="de-AT"><webwriter-geogebra-geometry></webwriter-geogebra-geometry></div>`, "webwriter-geogebra-geometry");
31
+ await widget.updateComplete;
32
+ assert.equal(widget.ggbProperties.language, "de");
33
+ assert.equal(widget.ggbProperties.country, "AT");
34
+ widget.parentElement.setAttribute("lang", "not a tag");
35
+ await widget.updateComplete;
36
+ assert.equal(widget.ggbProperties.language, "en");
37
+ assert.equal(widget.localize.getLocale(), "en");
38
+ });
39
+
40
+ it("still declares the options and actions", async function () {
41
+ const el = await mount(`<webwriter-geogebra></webwriter-geogebra>`);
42
+ assert.equal(el.options.type.control, "select");
43
+ assert.equal(el.options.enableRightClick.type, Boolean);
44
+ assert.isOk(el.options.showToolBar);
45
+ assert.equal(el.actions.importConstruction.input.accept, ".ggb");
46
+ });
47
+ });
48
+
49
+ mocha.run();