@webwriter/geogebra 1.0.1 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/publish.yml +8 -0
- package/LICENSE +6 -6
- package/README.md +785 -0
- package/custom-elements.json +11514 -0
- package/dist/chunks/af-35CD6HFH.js +12 -0
- package/dist/chunks/am-JMDT5LI7.js +12 -0
- package/dist/chunks/ar-JL4QKYYL.js +12 -0
- package/dist/chunks/az-3SZS6WCY.js +12 -0
- package/dist/chunks/be-C4GWVHR2.js +12 -0
- package/dist/chunks/bg-6QGE5EQ4.js +12 -0
- package/dist/chunks/bn-UM2BV46R.js +12 -0
- package/dist/chunks/bs-XE2PWKCS.js +12 -0
- package/dist/chunks/ca-ZO2BQKPZ.js +12 -0
- package/dist/chunks/ca-balear-GJKWY5R7.js +12 -0
- package/dist/chunks/ca-valencia-CNQYSJSJ.js +12 -0
- package/dist/chunks/chunk-ACU6XINJ.js +781 -0
- package/dist/chunks/chunk-ANJTU3IB.js +203 -0
- package/dist/chunks/chunk-BSUFUO7E.js +65 -0
- package/dist/chunks/cnr-MCZGASOD.js +12 -0
- package/dist/chunks/cs-4Q7FRISG.js +12 -0
- package/dist/chunks/cy-7VXG3AYH.js +12 -0
- package/dist/chunks/da-VDMHGBXD.js +12 -0
- package/dist/chunks/de-AT-YM5GCI75.js +12 -0
- package/dist/chunks/de-CH-LQNHTGYT.js +12 -0
- package/dist/chunks/de-GJT7RSHT.js +12 -0
- package/dist/chunks/el-ZVUVWEQ3.js +12 -0
- package/dist/chunks/en-AU-PCIYYC4M.js +12 -0
- package/dist/chunks/en-CA-37T7YUIL.js +12 -0
- package/dist/chunks/en-GB-ZYCA2CIZ.js +12 -0
- package/dist/chunks/en-IN-EPHXLNO6.js +12 -0
- package/dist/chunks/en-US-ECSJ5HDL.js +12 -0
- package/dist/chunks/es-5VBYK2HE.js +12 -0
- package/dist/chunks/et-OFQRRTW6.js +12 -0
- package/dist/chunks/eu-7TNOYFB7.js +12 -0
- package/dist/chunks/fa-KZU6GKWU.js +12 -0
- package/dist/chunks/fi-THJEKJPW.js +12 -0
- package/dist/chunks/fr-MUVVTBQZ.js +12 -0
- package/dist/chunks/ga-UWUVCWOT.js +12 -0
- package/dist/chunks/gl-NHQ52YCN.js +12 -0
- package/dist/chunks/gu-HVDD4QHO.js +12 -0
- package/dist/chunks/ha-2BPTATOZ.js +12 -0
- package/dist/chunks/he-MDESCUHJ.js +12 -0
- package/dist/chunks/hi-C6BGPR4Y.js +12 -0
- package/dist/chunks/hr-77MP3ELT.js +12 -0
- package/dist/chunks/hu-7PRNX6NB.js +12 -0
- package/dist/chunks/hy-R3VEL63L.js +12 -0
- package/dist/chunks/id-O6B2T3Y2.js +12 -0
- package/dist/chunks/is-XLNS5CAZ.js +12 -0
- package/dist/chunks/it-NZODUGUP.js +12 -0
- package/dist/chunks/ja-FFK5WXSB.js +12 -0
- package/dist/chunks/jv-GS3IRAIB.js +12 -0
- package/dist/chunks/ka-NWIJAO54.js +12 -0
- package/dist/chunks/kk-WQFRFG44.js +12 -0
- package/dist/chunks/km-AUKBN3YT.js +12 -0
- package/dist/chunks/kn-PKZFPECM.js +12 -0
- package/dist/chunks/ko-XNGAWKQ4.js +12 -0
- package/dist/chunks/ky-AQTYDJIL.js +12 -0
- package/dist/chunks/la-ERS7V4N4.js +12 -0
- package/dist/chunks/lb-KU3DVPI4.js +12 -0
- package/dist/chunks/locale-codes-TGY5LMYX.js +11 -0
- package/dist/chunks/lt-6RI4HSG3.js +12 -0
- package/dist/chunks/lv-RGIUQVA7.js +12 -0
- package/dist/chunks/mk-JMAYXTCL.js +12 -0
- package/dist/chunks/ml-5ZAIPAYV.js +12 -0
- package/dist/chunks/mn-N2GZBVDP.js +12 -0
- package/dist/chunks/mr-2SRCJIBC.js +12 -0
- package/dist/chunks/ms-WHD5PUQM.js +12 -0
- package/dist/chunks/mt-EXRK5UO6.js +12 -0
- package/dist/chunks/my-D2COGDRI.js +12 -0
- package/dist/chunks/nb-3XNBS2DU.js +12 -0
- package/dist/chunks/ne-PA4KUBGU.js +12 -0
- package/dist/chunks/nl-QMM3PBPM.js +12 -0
- package/dist/chunks/nn-CLFEMF2K.js +12 -0
- package/dist/chunks/no-CV376NZG.js +12 -0
- package/dist/chunks/or-KP7CET7X.js +12 -0
- package/dist/chunks/pa-CH5JYVXT.js +12 -0
- package/dist/chunks/pl-DDW4HT7M.js +12 -0
- package/dist/chunks/pt-BR-CVNA2MRU.js +12 -0
- package/dist/chunks/pt-CRTRYTDJ.js +12 -0
- package/dist/chunks/pt-PT-IZMPF3BY.js +12 -0
- package/dist/chunks/ro-FUOGHWJA.js +12 -0
- package/dist/chunks/ru-KAT4X5EC.js +12 -0
- package/dist/chunks/si-GDAXEOBK.js +12 -0
- package/dist/chunks/sk-CDSK6MY5.js +12 -0
- package/dist/chunks/sl-TFJQYNA4.js +12 -0
- package/dist/chunks/so-TXI6JJPW.js +12 -0
- package/dist/chunks/sq-KMM2QIRU.js +12 -0
- package/dist/chunks/sr-OTZNEL5Z.js +12 -0
- package/dist/chunks/sv-7CANJ6CF.js +12 -0
- package/dist/chunks/sw-5JDMTJ5K.js +12 -0
- package/dist/chunks/ta-HT4SO7PD.js +12 -0
- package/dist/chunks/te-FECCLHOI.js +12 -0
- package/dist/chunks/tg-FJWFJWF2.js +12 -0
- package/dist/chunks/th-JEP434LN.js +12 -0
- package/dist/chunks/tl-GN35ZR2F.js +12 -0
- package/dist/chunks/tr-IPVLQUE4.js +12 -0
- package/dist/chunks/uk-LHWPGFRV.js +12 -0
- package/dist/chunks/ur-7FU4XRAY.js +12 -0
- package/dist/chunks/uz-RO7XCKFE.js +12 -0
- package/dist/chunks/vi-5PHPTVV4.js +12 -0
- package/dist/chunks/zh-Hans-UM7MUEDB.js +12 -0
- package/dist/chunks/zh-Hant-7M2P4G7R.js +12 -0
- package/dist/chunks/zh-LHCPWZN2.js +12 -0
- package/dist/widgets/webwriter-geogebra-3d.js +23 -1880
- package/dist/widgets/webwriter-geogebra-classic.js +22 -1879
- package/dist/widgets/webwriter-geogebra-geometry.js +22 -1879
- package/dist/widgets/webwriter-geogebra-notes.js +22 -1879
- package/dist/widgets/webwriter-geogebra-scientific.js +22 -1879
- package/dist/widgets/webwriter-geogebra.js +34 -1887
- package/editing-config.json +856 -0
- package/lit-localize.json +111 -0
- package/localization/af.xlf +290 -0
- package/localization/am.xlf +290 -0
- package/localization/ar.xlf +295 -0
- package/localization/az.xlf +290 -0
- package/localization/be.xlf +290 -0
- package/localization/bg.xlf +295 -0
- package/localization/bn.xlf +290 -0
- package/localization/bs.xlf +290 -0
- package/localization/ca-balear.xlf +290 -0
- package/localization/ca-valencia.xlf +290 -0
- package/localization/ca.xlf +290 -0
- package/localization/cnr.xlf +290 -0
- package/localization/cs.xlf +295 -0
- package/localization/cy.xlf +290 -0
- package/localization/da.xlf +295 -0
- package/localization/de-AT.xlf +294 -0
- package/localization/de-CH.xlf +294 -0
- package/localization/de.xlf +294 -0
- package/localization/el.xlf +295 -0
- package/localization/es.xlf +295 -0
- package/localization/et.xlf +295 -0
- package/localization/eu.xlf +290 -0
- package/localization/fa.xlf +290 -0
- package/localization/fi.xlf +295 -0
- package/localization/fr.xlf +295 -0
- package/localization/ga.xlf +290 -0
- package/localization/generated/af.ts +16 -0
- package/localization/generated/am.ts +16 -0
- package/localization/generated/ar.ts +16 -0
- package/localization/generated/az.ts +16 -0
- package/localization/generated/be.ts +16 -0
- package/localization/generated/bg.ts +16 -0
- package/localization/generated/bn.ts +16 -0
- package/localization/generated/bs.ts +16 -0
- package/localization/generated/ca-balear.ts +16 -0
- package/localization/generated/ca-valencia.ts +16 -0
- package/localization/generated/ca.ts +16 -0
- package/localization/generated/cnr.ts +16 -0
- package/localization/generated/cs.ts +16 -0
- package/localization/generated/cy.ts +16 -0
- package/localization/generated/da.ts +16 -0
- package/localization/generated/de-AT.ts +16 -0
- package/localization/generated/de-CH.ts +16 -0
- package/localization/generated/de.ts +16 -0
- package/localization/generated/el.ts +16 -0
- package/localization/generated/en-AU.ts +16 -0
- package/localization/generated/en-CA.ts +16 -0
- package/localization/generated/en-GB.ts +16 -0
- package/localization/generated/en-IN.ts +16 -0
- package/localization/generated/en-US.ts +16 -0
- package/localization/generated/es.ts +16 -0
- package/localization/generated/et.ts +16 -0
- package/localization/generated/eu.ts +16 -0
- package/localization/generated/fa.ts +16 -0
- package/localization/generated/fi.ts +16 -0
- package/localization/generated/fr.ts +16 -0
- package/localization/generated/ga.ts +16 -0
- package/localization/generated/gl.ts +16 -0
- package/localization/generated/gu.ts +16 -0
- package/localization/generated/ha.ts +16 -0
- package/localization/generated/he.ts +16 -0
- package/localization/generated/hi.ts +16 -0
- package/localization/generated/hr.ts +16 -0
- package/localization/generated/hu.ts +16 -0
- package/localization/generated/hy.ts +16 -0
- package/localization/generated/id.ts +16 -0
- package/localization/generated/index.js +3 -0
- package/localization/generated/is.ts +16 -0
- package/localization/generated/it.ts +16 -0
- package/localization/generated/ja.ts +16 -0
- package/localization/generated/jv.ts +16 -0
- package/localization/generated/ka.ts +16 -0
- package/localization/generated/kk.ts +16 -0
- package/localization/generated/km.ts +16 -0
- package/localization/generated/kn.ts +16 -0
- package/localization/generated/ko.ts +16 -0
- package/localization/generated/ky.ts +16 -0
- package/localization/generated/la.ts +16 -0
- package/localization/generated/lb.ts +16 -0
- package/localization/generated/locale-codes.ts +211 -0
- package/localization/generated/lt.ts +16 -0
- package/localization/generated/lv.ts +16 -0
- package/localization/generated/mk.ts +16 -0
- package/localization/generated/ml.ts +16 -0
- package/localization/generated/mn.ts +16 -0
- package/localization/generated/mr.ts +16 -0
- package/localization/generated/ms.ts +16 -0
- package/localization/generated/mt.ts +16 -0
- package/localization/generated/my.ts +16 -0
- package/localization/generated/nb.ts +16 -0
- package/localization/generated/ne.ts +16 -0
- package/localization/generated/nl.ts +16 -0
- package/localization/generated/nn.ts +16 -0
- package/localization/generated/no.ts +16 -0
- package/localization/generated/or.ts +16 -0
- package/localization/generated/pa.ts +16 -0
- package/localization/generated/pl.ts +16 -0
- package/localization/generated/pt-BR.ts +16 -0
- package/localization/generated/pt-PT.ts +16 -0
- package/localization/generated/pt.ts +16 -0
- package/localization/generated/ro.ts +16 -0
- package/localization/generated/ru.ts +16 -0
- package/localization/generated/si.ts +16 -0
- package/localization/generated/sk.ts +16 -0
- package/localization/generated/sl.ts +16 -0
- package/localization/generated/so.ts +16 -0
- package/localization/generated/sq.ts +16 -0
- package/localization/generated/sr.ts +16 -0
- package/localization/generated/sv.ts +16 -0
- package/localization/generated/sw.ts +16 -0
- package/localization/generated/ta.ts +16 -0
- package/localization/generated/te.ts +16 -0
- package/localization/generated/tg.ts +16 -0
- package/localization/generated/th.ts +16 -0
- package/localization/generated/tl.ts +16 -0
- package/localization/generated/tr.ts +16 -0
- package/localization/generated/uk.ts +16 -0
- package/localization/generated/ur.ts +16 -0
- package/localization/generated/uz.ts +16 -0
- package/localization/generated/vi.ts +16 -0
- package/localization/generated/zh-Hans.ts +16 -0
- package/localization/generated/zh-Hant.ts +16 -0
- package/localization/generated/zh.ts +16 -0
- package/localization/gl.xlf +290 -0
- package/localization/gu.xlf +290 -0
- package/localization/ha.xlf +290 -0
- package/localization/he.xlf +290 -0
- package/localization/hi.xlf +290 -0
- package/localization/hr.xlf +290 -0
- package/localization/hu.xlf +295 -0
- package/localization/hy.xlf +290 -0
- package/localization/id.xlf +295 -0
- package/localization/is.xlf +290 -0
- package/localization/it.xlf +295 -0
- package/localization/ja.xlf +295 -0
- package/localization/jv.xlf +290 -0
- package/localization/ka.xlf +290 -0
- package/localization/kk.xlf +290 -0
- package/localization/km.xlf +290 -0
- package/localization/kn.xlf +290 -0
- package/localization/ko.xlf +295 -0
- package/localization/ky.xlf +290 -0
- package/localization/la.xlf +290 -0
- package/localization/lb.xlf +290 -0
- package/localization/lt.xlf +295 -0
- package/localization/lv.xlf +295 -0
- package/localization/mk.xlf +290 -0
- package/localization/ml.xlf +290 -0
- package/localization/mn.xlf +290 -0
- package/localization/mr.xlf +290 -0
- package/localization/ms.xlf +290 -0
- package/localization/mt.xlf +290 -0
- package/localization/my.xlf +290 -0
- package/localization/nb.xlf +295 -0
- package/localization/ne.xlf +290 -0
- package/localization/nl.xlf +295 -0
- package/localization/nn.xlf +290 -0
- package/localization/no.xlf +295 -0
- package/localization/or.xlf +290 -0
- package/localization/pa.xlf +290 -0
- package/localization/pkg/ar.xliff +6 -0
- package/localization/pkg/bg.xliff +6 -0
- package/localization/pkg/cs.xliff +6 -0
- package/localization/pkg/da.xliff +6 -0
- package/localization/pkg/de.xliff +6 -0
- package/localization/pkg/el.xliff +6 -0
- package/localization/pkg/es.xliff +6 -0
- package/localization/pkg/et.xliff +6 -0
- package/localization/pkg/fi.xliff +6 -0
- package/localization/pkg/fr.xliff +6 -0
- package/localization/pkg/hu.xliff +6 -0
- package/localization/pkg/id.xliff +6 -0
- package/localization/pkg/it.xliff +6 -0
- package/localization/pkg/ja.xliff +6 -0
- package/localization/pkg/ko.xliff +6 -0
- package/localization/pkg/lt.xliff +6 -0
- package/localization/pkg/lv.xliff +6 -0
- package/localization/pkg/nb.xliff +6 -0
- package/localization/pkg/nl.xliff +6 -0
- package/localization/pkg/pl.xliff +6 -0
- package/localization/pkg/pt-BR.xliff +6 -0
- package/localization/pkg/pt-PT.xliff +6 -0
- package/localization/pkg/ro.xliff +6 -0
- package/localization/pkg/ru.xliff +6 -0
- package/localization/pkg/sk.xliff +6 -0
- package/localization/pkg/sl.xliff +6 -0
- package/localization/pkg/sv.xliff +6 -0
- package/localization/pkg/tr.xliff +6 -0
- package/localization/pkg/uk.xliff +6 -0
- package/localization/pkg/zh-Hans.xliff +6 -0
- package/localization/pkg/zh-Hant.xliff +6 -0
- package/localization/pl.xlf +295 -0
- package/localization/pt-BR.xlf +295 -0
- package/localization/pt-PT.xlf +295 -0
- package/localization/pt.xlf +295 -0
- package/localization/ro.xlf +295 -0
- package/localization/ru.xlf +295 -0
- package/localization/si.xlf +290 -0
- package/localization/sk.xlf +295 -0
- package/localization/sl.xlf +295 -0
- package/localization/snippets/ar.xliff +4 -0
- package/localization/snippets/bg.xliff +4 -0
- package/localization/snippets/cs.xliff +4 -0
- package/localization/snippets/da.xliff +4 -0
- package/localization/snippets/de.xliff +4 -0
- package/localization/snippets/el.xliff +4 -0
- package/localization/snippets/es.xliff +4 -0
- package/localization/snippets/et.xliff +4 -0
- package/localization/snippets/fi.xliff +4 -0
- package/localization/snippets/fr.xliff +4 -0
- package/localization/snippets/hu.xliff +4 -0
- package/localization/snippets/id.xliff +4 -0
- package/localization/snippets/it.xliff +4 -0
- package/localization/snippets/ja.xliff +4 -0
- package/localization/snippets/ko.xliff +4 -0
- package/localization/snippets/lt.xliff +4 -0
- package/localization/snippets/lv.xliff +4 -0
- package/localization/snippets/nb.xliff +4 -0
- package/localization/snippets/nl.xliff +4 -0
- package/localization/snippets/pl.xliff +4 -0
- package/localization/snippets/pt-BR.xliff +4 -0
- package/localization/snippets/pt-PT.xliff +4 -0
- package/localization/snippets/ro.xliff +4 -0
- package/localization/snippets/ru.xliff +4 -0
- package/localization/snippets/sk.xliff +4 -0
- package/localization/snippets/sl.xliff +4 -0
- package/localization/snippets/sv.xliff +4 -0
- package/localization/snippets/tr.xliff +4 -0
- package/localization/snippets/uk.xliff +4 -0
- package/localization/snippets/zh-Hans.xliff +4 -0
- package/localization/snippets/zh-Hant.xliff +4 -0
- package/localization/so.xlf +290 -0
- package/localization/sq.xlf +290 -0
- package/localization/sr.xlf +290 -0
- package/localization/sv.xlf +295 -0
- package/localization/sw.xlf +290 -0
- package/localization/ta.xlf +290 -0
- package/localization/te.xlf +290 -0
- package/localization/tg.xlf +290 -0
- package/localization/th.xlf +290 -0
- package/localization/tl.xlf +290 -0
- package/localization/tr.xlf +295 -0
- package/localization/uk.xlf +295 -0
- package/localization/ur.xlf +290 -0
- package/localization/uz.xlf +290 -0
- package/localization/vi.xlf +290 -0
- package/localization/zh-Hans.xlf +295 -0
- package/localization/zh-Hant.xlf +295 -0
- package/localization/zh.xlf +295 -0
- package/package.json +272 -166
- package/src/components/geogebra-app.styles.ts +47 -0
- package/src/components/geogebra-app.ts +651 -0
- package/src/model/boolean-attribute-converter.ts +8 -0
- package/src/model/geogebra-api.ts +148 -0
- package/src/model/geogebra-options.ts +72 -0
- package/src/model/geogebra-parameters.ts +53 -0
- package/src/model/ggb-file.ts +30 -0
- package/src/types.d.ts +3 -0
- package/src/widgets/webwriter-geogebra-3d.ts +15 -0
- package/{widgets → src/widgets}/webwriter-geogebra-classic.ts +14 -8
- package/{widgets → src/widgets}/webwriter-geogebra-geometry.ts +14 -8
- package/{widgets → src/widgets}/webwriter-geogebra-notes.ts +14 -8
- package/{widgets → src/widgets}/webwriter-geogebra-scientific.ts +14 -8
- package/src/widgets/webwriter-geogebra.ts +28 -0
- package/tests/conversions.test.ts +80 -0
- package/tests/data-block.test.ts +72 -0
- package/tests/helpers.ts +48 -0
- package/tests/language.test.ts +49 -0
- package/tests/presentation.test.ts +80 -0
- package/tsconfig.json +4 -8
- package/components/geogebra-app.ts +0 -417
- package/custom.d.ts +0 -180
- package/widgets/webwriter-geogebra-3d.ts +0 -9
- package/widgets/webwriter-geogebra-evaluator.ts +0 -9
- package/widgets/webwriter-geogebra.ts +0 -20
|
@@ -0,0 +1,651 @@
|
|
|
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"
|
|
8
|
+
import {keyed} from "lit/directives/keyed.js"
|
|
9
|
+
|
|
10
|
+
import {geogebraAppStyles} from "./geogebra-app.styles"
|
|
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 } from "../model/geogebra-parameters"
|
|
15
|
+
import { base64ToBytes, bytesToBase64, dataUrlPayload, ggbDataUrl, GGB_MEDIA_TYPE, isGgbArchive } from "../model/ggb-file"
|
|
16
|
+
|
|
17
|
+
export type { GeogebraAPI }
|
|
18
|
+
|
|
19
|
+
declare global {
|
|
20
|
+
interface HTMLElementEventMap {
|
|
21
|
+
"ggb-load": CustomEvent<{api: GeogebraAPI}>
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 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):
|
|
27
|
+
* the applet fills the iframe (16:9, at least 18rem high), so `width` and `height` only set its size before the first resize.
|
|
28
|
+
*
|
|
29
|
+
* 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.
|
|
30
|
+
*
|
|
31
|
+
* Conversions: a `.ggb` file replaces the construction (import) and the current construction downloads as `.ggb` (export).
|
|
32
|
+
* `image/png` and `image/svg+xml` export the picture of the graphics view; both need the loaded applet and are lossy
|
|
33
|
+
* (no construction steps, no algebra view). A file that is no zip archive is refused before the widget changes.
|
|
34
|
+
*
|
|
35
|
+
* @part applet - The iframe that holds the GeoGebra applet.
|
|
36
|
+
* @fires focus - Fired when the GeoGebra applet gains focus.
|
|
37
|
+
* @fires ggb-load - Fired when the GeoGebra API is ready. The event detail contains the API instance.
|
|
38
|
+
*/
|
|
39
|
+
export class GeogebraApp extends LitElementWw {
|
|
40
|
+
static styles = geogebraAppStyles
|
|
41
|
+
|
|
42
|
+
static options = geogebraOptions
|
|
43
|
+
|
|
44
|
+
static actions = {
|
|
45
|
+
importConstruction: {
|
|
46
|
+
label: (widget: {msg: MsgFn}) => ({_: widget.msg("Import construction")}),
|
|
47
|
+
input: {type: "file" as const, accept: ".ggb", multiple: false},
|
|
48
|
+
},
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
static convertFrom = {".ggb": "importGgb"}
|
|
52
|
+
|
|
53
|
+
static convertTo = {".ggb": "exportGgb", "image/png": "exportPng", "image/svg+xml": "exportSvg"}
|
|
54
|
+
|
|
55
|
+
// The labels of the options are computed with msg, so the editor reads them again after a language change.
|
|
56
|
+
protected readonly localize = localizer(this, {
|
|
57
|
+
sourceLocale,
|
|
58
|
+
targetLocales,
|
|
59
|
+
load: (locale) => import(`../../localization/generated/${locale}.ts`),
|
|
60
|
+
drawer: true,
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
readonly msg: MsgFn = this.localize.msg
|
|
64
|
+
|
|
65
|
+
// The embedded construction is the "src" key of the JSON data block.
|
|
66
|
+
#data = jsonData<{src?: string}>(this, {
|
|
67
|
+
defaults: {},
|
|
68
|
+
changed: ({src}) => {
|
|
69
|
+
if (typeof src === "string" && src.startsWith("data:")) this.src = src
|
|
70
|
+
},
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Custom CSS styles to apply to the GeoGebra applet.
|
|
75
|
+
*/
|
|
76
|
+
@property({type: String})
|
|
77
|
+
accessor ggbStyles: string = css`
|
|
78
|
+
.GeoGebraFrame .toolbar .header-open-landscape .center, .GeoGebraFrame .toolbar .header-close-landscape .center {
|
|
79
|
+
top: 0 !important;
|
|
80
|
+
}
|
|
81
|
+
`.cssText
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* app name, default: "classic". "graphing" … GeoGebra Graphing Calculator "geometry" … GeoGebra Geometry "3d" … GeoGebra 3D Graphing Calculator "classic" … GeoGebra Classic "suite" … GeoGebra Calculator Suite "evaluator" … Equation Editor "scientific" …Scientific Calculator "notes" … GeoGebra Notes
|
|
85
|
+
*/
|
|
86
|
+
@property({type: String, attribute: true, reflect: true})
|
|
87
|
+
accessor type: "classic" | "geometry" | "3d" | "suite" | "evaluator" | "scientific" | "notes" = "classic"
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Applet width
|
|
91
|
+
*/
|
|
92
|
+
@property({type: Number, attribute: true, reflect: true})
|
|
93
|
+
accessor width: number = 800
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Applet height
|
|
97
|
+
*/
|
|
98
|
+
@property({type: Number, attribute: true, reflect: true})
|
|
99
|
+
accessor height: number = 450
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Source of the GeoGebra file to load (base64-encoded string, material ID prefixed with "ggbid:", or file URL)
|
|
103
|
+
*/
|
|
104
|
+
@property({type: String, attribute: true, reflect: true, converter: {
|
|
105
|
+
fromAttribute: (value: string | null) => value,
|
|
106
|
+
toAttribute: (value: string | null) => value?.startsWith("data:") ? null : value,
|
|
107
|
+
}})
|
|
108
|
+
accessor src: string | undefined
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Color of the border line drawn around the applet panel (as hex rgb string). Default: gray
|
|
112
|
+
*/
|
|
113
|
+
@property({type: String, attribute: true, reflect: true})
|
|
114
|
+
accessor borderColor: string = "gray"
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Size of applet's border radius in pixels.
|
|
118
|
+
*/
|
|
119
|
+
@property({type: Number, attribute: true, reflect: true})
|
|
120
|
+
accessor borderRadius: number = 1
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* States whether right clicks should be handled by the applet. Setting this parameter to "false" disables context menus, properties dialogs and right-click-zooming. Default: true. NB also enables/disables some keyboard shortcuts eg Delete and Ctrl + R (recompute all objects). Default: true
|
|
124
|
+
*/
|
|
125
|
+
@property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
|
|
126
|
+
accessor enableRightClick = true
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* States whether labels can be dragged. Default: true
|
|
130
|
+
*/
|
|
131
|
+
@property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
|
|
132
|
+
accessor enableLabelDrags = true
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* States whether the Graphics View(s) should be moveable using Shift mouse drag (or. Ctrl + mouse drag) or zoomable using Shift + mouse wheel (or Ctrl + mouse wheel). Setting this parameter to "false" disables moving and zooming of the drawing pad. Default: true
|
|
136
|
+
*/
|
|
137
|
+
@property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
|
|
138
|
+
accessor enableShiftDragZoom = true
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* States whether the zoom in / zoom out / home buttons should be shown in the Graphics View or not. Default: false
|
|
142
|
+
*/
|
|
143
|
+
@property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
|
|
144
|
+
accessor showZoomButtons = false
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* States whether error dialogs will be shown if an invalid input is entered (using the Input Bar or JavaScript) Default: true
|
|
148
|
+
*/
|
|
149
|
+
@property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
|
|
150
|
+
accessor errorDialogsActive = true
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* States whether the menubar of GeoGebra should be shown in the applet. Default: false
|
|
154
|
+
*/
|
|
155
|
+
@property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
|
|
156
|
+
accessor showMenuBar = false
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* States whether the toolbar with the construction mode buttons should be shown in the applet. Default: false
|
|
160
|
+
*/
|
|
161
|
+
@property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
|
|
162
|
+
accessor showToolBar = true
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* States whether the toolbar help text right to the toolbar buttons should be shown in the applet
|
|
166
|
+
*/
|
|
167
|
+
@property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
|
|
168
|
+
accessor showToolBarHelp = false
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* 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
|
|
172
|
+
*/
|
|
173
|
+
@property({type: String, attribute: true, reflect: true})
|
|
174
|
+
accessor customToolBar: string | undefined
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* States whether the algebra input line (with input field, greek letters and command list) should be shown in the applet. Default: false
|
|
178
|
+
*/
|
|
179
|
+
@property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
|
|
180
|
+
accessor showAlgebraInput = true
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* States whether a small icon (GeoGebra ellipse) should be shown in the upper right corner of the applet. Clicking on this icon resets the applet (i.e. it reloads the file given in the filename parameter). Default: false
|
|
184
|
+
*/
|
|
185
|
+
@property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
|
|
186
|
+
accessor showResetIcon = false
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* 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.
|
|
190
|
+
*/
|
|
191
|
+
@property({type: String, attribute: true, reflect: true})
|
|
192
|
+
accessor language: string | undefined
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* ISO country string. This parameter only makes sense if you use it together with the language parameter.
|
|
196
|
+
*/
|
|
197
|
+
@property({type: String, attribute: true, reflect: true})
|
|
198
|
+
accessor country: string | undefined
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* 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.
|
|
202
|
+
*/
|
|
203
|
+
@property({type: String, attribute: true, reflect: true})
|
|
204
|
+
accessor appletId: string | undefined
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Determines whether the Style Bar can be shown (or will be shown if just Graphics View 1 is showing). Default: false
|
|
208
|
+
*/
|
|
209
|
+
@property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
|
|
210
|
+
accessor allowStyleBar = false
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Determines whether random numbers should be randomized on file load. Useful when you want the app to reload in exactly the same state it was saved. Default: true
|
|
214
|
+
*/
|
|
215
|
+
@property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
|
|
216
|
+
accessor randomize = true
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* 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.
|
|
220
|
+
*/
|
|
221
|
+
@property({type: Number, attribute: true, reflect: true})
|
|
222
|
+
accessor randomSeed: number | undefined
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* 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
|
|
226
|
+
*/
|
|
227
|
+
@property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
|
|
228
|
+
accessor useBrowserForJs = false
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Determines whether logging is shown in the Browser's console. Default: false
|
|
232
|
+
*/
|
|
233
|
+
@property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
|
|
234
|
+
accessor showLogging = false
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Determines the sensitivity of object selection. The default value of 3 is usually fine to select and drag objects both with the mouse and touch. Use larger values (e.g. 4 or 5) to make it easier to select and drag objects. Default: 3
|
|
238
|
+
*/
|
|
239
|
+
@property({type: Number, attribute: true, reflect: true})
|
|
240
|
+
accessor capturingThreshold = 3
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Determines whether file saving, file loading, sign in and Options > Save settings are enabled. This argument is ignored when menubar is not showing. Default: true
|
|
244
|
+
*/
|
|
245
|
+
@property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
|
|
246
|
+
accessor enableFileFeatures = true
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Determines whether Undo and Redo icons are shown. This argument is ignored when toolbar is not showing. Default: true
|
|
250
|
+
*/
|
|
251
|
+
@property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
|
|
252
|
+
accessor enableUndoRedo = true
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* 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
|
|
256
|
+
*/
|
|
257
|
+
@property({type: String, attribute: true, reflect: true})
|
|
258
|
+
accessor perspective: string | undefined
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Whether 3D should be enabled (for exam mode).
|
|
262
|
+
*/
|
|
263
|
+
@property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
|
|
264
|
+
accessor enable3d: boolean | undefined
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Whether CAS should be enabled (for exam mode).
|
|
268
|
+
*/
|
|
269
|
+
@property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
|
|
270
|
+
accessor enableCAS: boolean | undefined
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* 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.
|
|
274
|
+
*/
|
|
275
|
+
@property({type: String, attribute: true, reflect: true})
|
|
276
|
+
accessor algebraInputPosition: "algebra" | "top" | "bottom" | undefined
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* When set to true, this prevents the applet from getting focus automatically at the start. Default: false
|
|
280
|
+
*/
|
|
281
|
+
@property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
|
|
282
|
+
accessor preventFocus = false
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Name of CSS class that is used as container; applet will scale to fit into the container.
|
|
286
|
+
*/
|
|
287
|
+
@property({type: String, attribute: true, reflect: true})
|
|
288
|
+
accessor scaleContainerClass: string | undefined
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* `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
|
|
292
|
+
*/
|
|
293
|
+
@property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
|
|
294
|
+
accessor autoHeight = true
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Determines whether automatic scaling may scale the applet up. Default: false
|
|
298
|
+
*/
|
|
299
|
+
@property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
|
|
300
|
+
accessor allowUpscale = false
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Determines whether a preview image and a play button should be rendered in place of the applet. Pushing the play button initializes the applet. Default: false
|
|
304
|
+
*/
|
|
305
|
+
@property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
|
|
306
|
+
accessor playButton = false
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Ratio by which the applet should be scaled (eg. 2 makes the applet 2 times bigger, including all texts and UI elements). Default: 1
|
|
310
|
+
*/
|
|
311
|
+
@property({type: Number, attribute: true, reflect: true})
|
|
312
|
+
accessor scale = 1
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Whether animation button should be visible
|
|
316
|
+
*/
|
|
317
|
+
@property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
|
|
318
|
+
accessor showAnimationButton = false
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Whether fullscreen button should be visible
|
|
322
|
+
*/
|
|
323
|
+
@property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
|
|
324
|
+
accessor showFullscreenButton = false
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Whether suggestion buttons (special points, solve) in Algebra View should be visible
|
|
328
|
+
*/
|
|
329
|
+
@property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
|
|
330
|
+
accessor showSuggestionButtons = false
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Whether "Welcome" tooltip should be shown
|
|
334
|
+
*/
|
|
335
|
+
@property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
|
|
336
|
+
accessor showStartTooltip = false
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* 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.
|
|
340
|
+
*/
|
|
341
|
+
@property({type: String, attribute: true, reflect: true})
|
|
342
|
+
accessor rounding: string | undefined
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Whether buttons should have shadow
|
|
346
|
+
*/
|
|
347
|
+
@property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
|
|
348
|
+
accessor buttonShadows = false
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* 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
|
|
352
|
+
*/
|
|
353
|
+
@property({type: Number, attribute: true, reflect: true})
|
|
354
|
+
accessor buttonRounding = 0.2
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* 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
|
|
358
|
+
*/
|
|
359
|
+
@property({type: String, attribute: true, reflect: true})
|
|
360
|
+
accessor buttonBorderColor: string | undefined
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Background color of the evaluator app
|
|
364
|
+
*/
|
|
365
|
+
@property({type: String, attribute: true, reflect: true})
|
|
366
|
+
accessor editorBackgroundColor: string | undefined
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* Foreground (text) color of the equation editor (appname = "evaluator")
|
|
370
|
+
*/
|
|
371
|
+
@property({type: String, attribute: true, reflect: true})
|
|
372
|
+
accessor editorForegroundColor: string | undefined
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Whether editor is in text mode or not (appname = "evaluator"). Default: false
|
|
376
|
+
*/
|
|
377
|
+
@property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
|
|
378
|
+
accessor textmode = false
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* 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
|
|
382
|
+
*/
|
|
383
|
+
@property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
|
|
384
|
+
accessor showKeyboardOnFocus: boolean | undefined
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* Which keyboard is shown for equation editor (appname = "evaluator")
|
|
388
|
+
*/
|
|
389
|
+
@property({type: String, attribute: true, reflect: true})
|
|
390
|
+
accessor keyboardType: "scientific" | "normal" | "notes" | undefined
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Whether the Graphics View and Graphics View 2 should be transparent
|
|
394
|
+
*/
|
|
395
|
+
@property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
|
|
396
|
+
accessor transparentGraphics = false
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Whether running JavaScript from material files is disabled or not.
|
|
400
|
+
*/
|
|
401
|
+
@property({type: Boolean, attribute: true, reflect: true, converter: booleanAttributeConverter})
|
|
402
|
+
accessor disabledJavaScript = false
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* When set, the keyboard should be attached to the first element in DOM that fits the selector.
|
|
406
|
+
*/
|
|
407
|
+
@property({type: String, attribute: true, reflect: true})
|
|
408
|
+
accessor detachedKeyboardParent: string | undefined
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* Used to force reset of the applet. Increment this property to reset the applet.
|
|
412
|
+
*/
|
|
413
|
+
@property({type: Number})
|
|
414
|
+
protected accessor resetKey: number = 0
|
|
415
|
+
|
|
416
|
+
// A map of parameter names to their corresponding update functions in the GeoGebra API
|
|
417
|
+
private paramUpdateMap?: Map<string, (value: never) => void>
|
|
418
|
+
|
|
419
|
+
private api?: GeogebraAPI
|
|
420
|
+
private listeners?: AbortController
|
|
421
|
+
private srcFrame = 0
|
|
422
|
+
@state()
|
|
423
|
+
private accessor ready = false
|
|
424
|
+
|
|
425
|
+
private resizer?: ResizeObserver
|
|
426
|
+
private resizeFrame = 0
|
|
427
|
+
private updatingGgb = false
|
|
428
|
+
|
|
429
|
+
private get ggbProperties() {
|
|
430
|
+
return appletParameters(this, this.lang, sourceLocale)
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
connectedCallback(): void {
|
|
434
|
+
super.connectedCallback()
|
|
435
|
+
this.listeners = new AbortController()
|
|
436
|
+
this.addEventListener("ggb-load", (e) => {
|
|
437
|
+
const api = e.detail.api
|
|
438
|
+
this.api = api
|
|
439
|
+
this.ready = true
|
|
440
|
+
this.observeSize()
|
|
441
|
+
api.registerAddListener(this.updateSrc)
|
|
442
|
+
api.registerClearListener(this.updateSrc)
|
|
443
|
+
api.registerUpdateListener(this.updateSrc)
|
|
444
|
+
api.registerRenameListener(this.updateSrc)
|
|
445
|
+
api.registerRemoveListener(this.updateSrc)
|
|
446
|
+
|
|
447
|
+
// showMenuBar is not updated live, because showMenuBar(false) does not work.
|
|
448
|
+
this.paramUpdateMap = new Map<string, (value: never) => void>([
|
|
449
|
+
["width", api.setWidth],
|
|
450
|
+
["height", api.setHeight],
|
|
451
|
+
["enableRightClick", api.enableRightClick],
|
|
452
|
+
["enableLabelDrags", api.enableLabelDrags],
|
|
453
|
+
["enableShiftDragZoom", api.enableShiftDragZoom],
|
|
454
|
+
["errorDialogsActive", api.setErrorDialogsActive],
|
|
455
|
+
["showToolBar", api.showToolBar],
|
|
456
|
+
["customToolBar", api.setCustomToolBar],
|
|
457
|
+
["showAlgebraInput", api.showAlgebraInput],
|
|
458
|
+
["showResetIcon", api.showResetIcon],
|
|
459
|
+
["perspective", api.setPerspective],
|
|
460
|
+
["enable3d", api.enable3D],
|
|
461
|
+
["enableCAS", api.enableCAS],
|
|
462
|
+
["rounding", api.setRounding],
|
|
463
|
+
])
|
|
464
|
+
}, {signal: this.listeners.signal})
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
disconnectedCallback(): void {
|
|
468
|
+
super.disconnectedCallback()
|
|
469
|
+
this.listeners?.abort()
|
|
470
|
+
this.resizer?.disconnect()
|
|
471
|
+
this.resizer = undefined
|
|
472
|
+
cancelAnimationFrame(this.resizeFrame)
|
|
473
|
+
this.resizeFrame = 0
|
|
474
|
+
this.ready = false
|
|
475
|
+
if (this.srcFrame) {
|
|
476
|
+
cancelAnimationFrame(this.srcFrame)
|
|
477
|
+
this.writeSrc()
|
|
478
|
+
}
|
|
479
|
+
this.api = undefined
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
protected updated(changed: PropertyValues<this>): void {
|
|
483
|
+
super.updated(changed)
|
|
484
|
+
|
|
485
|
+
if (changed.has("src")) this.#data.set({src: this.src?.startsWith("data:") ? this.src : undefined})
|
|
486
|
+
|
|
487
|
+
const api = this.api
|
|
488
|
+
if(!api) {
|
|
489
|
+
this.resetIFrame()
|
|
490
|
+
return
|
|
491
|
+
}
|
|
492
|
+
if (this.paramUpdateMap) {
|
|
493
|
+
let needFullReload = false
|
|
494
|
+
|
|
495
|
+
changed.forEach((_, key) => {
|
|
496
|
+
if(key === "src" || key === "ready") {
|
|
497
|
+
return
|
|
498
|
+
}
|
|
499
|
+
const updateFunc = this.paramUpdateMap?.get(key.toString())
|
|
500
|
+
if(updateFunc) {
|
|
501
|
+
updateFunc.call(api, this[key as keyof this] as never)
|
|
502
|
+
} else {
|
|
503
|
+
needFullReload = true
|
|
504
|
+
}
|
|
505
|
+
})
|
|
506
|
+
|
|
507
|
+
if(needFullReload) {
|
|
508
|
+
this.resetIFrame()
|
|
509
|
+
return
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
if(!changed.has("src")) {
|
|
514
|
+
return
|
|
515
|
+
}
|
|
516
|
+
const base64 = this.src?.split(",").at(-1)
|
|
517
|
+
if(this.src && base64 !== api.getBase64()) {
|
|
518
|
+
this.updatingGgb = true
|
|
519
|
+
api.setBase64(base64 ?? "", () => {
|
|
520
|
+
this.updatingGgb = false
|
|
521
|
+
})
|
|
522
|
+
}
|
|
523
|
+
else if(!this.src) {
|
|
524
|
+
this.updatingGgb = true
|
|
525
|
+
api.setBase64("", () => {
|
|
526
|
+
this.updatingGgb = false
|
|
527
|
+
})
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
async importConstruction(files: File[]) {
|
|
532
|
+
const file = files[0]
|
|
533
|
+
if (!file || !this.isConnected) return
|
|
534
|
+
this.src = ggbDataUrl(bytesToBase64(new Uint8Array(await file.arrayBuffer())))
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
async importGgb(file: File) {
|
|
538
|
+
const bytes = new Uint8Array(await file.arrayBuffer())
|
|
539
|
+
if (!isGgbArchive(bytes)) throw new Error(this.msg("The file is not a GeoGebra construction (.ggb)."))
|
|
540
|
+
const src = ggbDataUrl(bytesToBase64(bytes))
|
|
541
|
+
return () => { this.src = src }
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
exportGgb() {
|
|
545
|
+
const base64 = this.api?.getBase64() || dataUrlPayload(this.src)
|
|
546
|
+
if (!base64) return null
|
|
547
|
+
return new File([base64ToBytes(base64) as BlobPart], "construction.ggb", {type: GGB_MEDIA_TYPE})
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
exportPng() {
|
|
551
|
+
const base64 = this.api?.getPNGBase64(1, false, 72)
|
|
552
|
+
if (!base64) return null
|
|
553
|
+
return new File([base64ToBytes(base64) as BlobPart], "construction.png", {type: "image/png"})
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
exportSvg() {
|
|
557
|
+
const api = this.api
|
|
558
|
+
if (!api) return null
|
|
559
|
+
return new Promise<File | null>(resolve => {
|
|
560
|
+
const timeout = setTimeout(() => resolve(null), 8000)
|
|
561
|
+
api.exportSVG((svg: string) => {
|
|
562
|
+
clearTimeout(timeout)
|
|
563
|
+
resolve(svg ? new File([svg], "construction.svg", {type: "image/svg+xml"}) : null)
|
|
564
|
+
})
|
|
565
|
+
})
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
// Serializing the construction is costly and the applet reports every change of a drag, so it runs once per frame.
|
|
569
|
+
private updateSrc = () => {
|
|
570
|
+
if (this.updatingGgb || !this.api || this.srcFrame) return
|
|
571
|
+
this.srcFrame = requestAnimationFrame(this.writeSrc)
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
private writeSrc = () => {
|
|
575
|
+
this.srcFrame = 0
|
|
576
|
+
if(!this.updatingGgb && this.api) {
|
|
577
|
+
this.src = `data:application/vnd.geogebra.file;base64,${this.api.getBase64()}`
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
private initializeIFrame(iframe: HTMLIFrameElement) {
|
|
582
|
+
const doc = iframe.contentDocument
|
|
583
|
+
if (!doc || doc.getElementById("ggb-element")) {
|
|
584
|
+
return
|
|
585
|
+
}
|
|
586
|
+
doc.body.style.margin = "0"
|
|
587
|
+
if(this.ggbStyles) {
|
|
588
|
+
const style = doc.createElement("style")
|
|
589
|
+
style.textContent = this.ggbStyles
|
|
590
|
+
doc.head.append(style)
|
|
591
|
+
}
|
|
592
|
+
doc.body.addEventListener("focusin", () => this.dispatchEvent(new FocusEvent("focus", {bubbles: true, composed: true})))
|
|
593
|
+
const ggbEl = doc.createElement("div")
|
|
594
|
+
ggbEl.id = "ggb-element"
|
|
595
|
+
doc.body.append(ggbEl);
|
|
596
|
+
const deployScript = doc.createElement("script")
|
|
597
|
+
deployScript.src = "https://www.geogebra.org/apps/deployggb.js"
|
|
598
|
+
deployScript.addEventListener("load", () => {
|
|
599
|
+
const createScript = doc.createElement("script")
|
|
600
|
+
createScript.textContent = `
|
|
601
|
+
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}}))})
|
|
602
|
+
applet.inject("ggb-element")
|
|
603
|
+
`
|
|
604
|
+
doc.addEventListener("ggb-load", (e) => this.dispatchEvent(new CustomEvent("ggb-load", {bubbles: true, composed: true, detail: (e as CustomEvent<{api: GeogebraAPI}>).detail})))
|
|
605
|
+
doc.body.append(createScript)
|
|
606
|
+
})
|
|
607
|
+
doc.body.append(deployScript)
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
// The applet follows the size of the iframe, which follows the container; one resize per frame avoids loops.
|
|
611
|
+
private observeSize() {
|
|
612
|
+
const iframe = this.renderRoot.querySelector("iframe")
|
|
613
|
+
if (!iframe) return
|
|
614
|
+
this.resizer?.disconnect()
|
|
615
|
+
let last = ""
|
|
616
|
+
this.resizer = new ResizeObserver(() => {
|
|
617
|
+
cancelAnimationFrame(this.resizeFrame)
|
|
618
|
+
this.resizeFrame = requestAnimationFrame(() => {
|
|
619
|
+
const {width, height} = iframe.getBoundingClientRect()
|
|
620
|
+
const size = `${Math.round(width)}x${Math.round(height)}`
|
|
621
|
+
if (!this.api || !iframe.isConnected || width < 1 || size === last) return
|
|
622
|
+
last = size
|
|
623
|
+
this.api.setSize(Math.round(width), Math.round(height))
|
|
624
|
+
})
|
|
625
|
+
})
|
|
626
|
+
this.resizer.observe(iframe)
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
focus(options?: FocusOptions) {
|
|
630
|
+
this.renderRoot.querySelector("iframe")?.focus(options)
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
private resetIFrame() {
|
|
634
|
+
if(!this.api) {
|
|
635
|
+
return
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
this.api = undefined
|
|
639
|
+
this.ready = false
|
|
640
|
+
this.resetKey++
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
render() {
|
|
644
|
+
return html`
|
|
645
|
+
<div class="applet" ?data-ready=${this.ready}>
|
|
646
|
+
${keyed(this.resetKey, html`<iframe id="ggb" part="applet" title=${this.msg("GeoGebra applet")} @load=${(e: Event) => this.initializeIFrame(e.target as HTMLIFrameElement)}></iframe>`)}
|
|
647
|
+
<p class="print-note">${this.msg("Interactive content: open the document online to use the GeoGebra applet.")}</p>
|
|
648
|
+
</div>
|
|
649
|
+
`
|
|
650
|
+
}
|
|
651
|
+
}
|