Join our webinar on Wednesday, June 26, at 1pm EDTHow Chia Mitigates Risk in the Crypto Industry.Register
Socket
Socket
Sign inDemoInstall

@netless/app-geogebra

Package Overview
Dependencies
0
Maintainers
12
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.6 to 0.0.7

dist/main.cjs.js

1

dist/index.d.ts

@@ -6,2 +6,3 @@ import type { NetlessApp } from "@netless/window-manager";

ggbBase64: string;
appName?: "classic" | "graphing" | "geometry" | "3d" | "suite" | "evaluator" | "scientific";
}

@@ -8,0 +9,0 @@ /**

4

dist/main.iife.js

@@ -1,3 +0,3 @@

var NetlessAppGeoGebra=function(u){"use strict";var _=Object.defineProperty;var W=(u,g,m)=>g in u?_(u,g,{enumerable:!0,configurable:!0,writable:!0,value:m}):u[g]=m;var o=(u,g,m)=>(W(u,typeof g!="symbol"?g+"":g,m),m);const g="!#%()*+,-./:;=?@[]^_`{|}~ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",m=g.length,k=Array(20),V=()=>{for(let r=0;r<20;r++)k[r]=g.charAt(Math.random()*m);return k.join("")};function M(r){try{return r()}catch(t){console.error(t)}}class N{constructor(){this.disposers=new Map}addDisposer(t,s=this.genUID()){return this.flush(s),this.disposers.set(s,Array.isArray(t)?()=>t.forEach(M):t),s}add(t,s=this.genUID()){const e=t();return e?this.addDisposer(e,s):s}addEventListener(t,s,e,i,a=this.genUID()){return t.addEventListener(s,e,i),this.addDisposer(()=>t.removeEventListener(s,e,i),a),a}setTimeout(t,s,e=this.genUID()){const i=window.setTimeout(()=>{this.remove(e),t()},s);return this.addDisposer(()=>window.clearTimeout(i),e)}setInterval(t,s,e=this.genUID()){const i=window.setInterval(t,s);return this.addDisposer(()=>window.clearInterval(i),e)}remove(t){const s=this.disposers.get(t);return this.disposers.delete(t),s}flush(t){const s=this.remove(t);if(s)try{s()}catch(e){console.error(e)}}flushAll(){this.disposers.forEach(M),this.disposers.clear()}genUID(){let t;do t=V();while(this.disposers.has(t));return t}}function X(r){return r!=null&&typeof r=="object"&&!Array.isArray(r)}function x(r,t){let s=r.getAttributes();if(s||(r.setAttributes(t),s=r.getAttributes()),!s)throw new Error("[NetlessAppMonaco] No attributes");return X(t)&&Object.keys(t).forEach(e=>{Object.prototype.hasOwnProperty.call(s,e)||r.updateAttributes([e],t[e])}),s}let L;function D(r){if(window.GGBApplet)return Promise.resolve(window.GGBApplet);if(L)return L;{const t=document.createElement("script");if(L=new Promise((s,e)=>{t.onload=()=>s(window.GGBApplet),t.onerror=()=>{L=void 0,e()}}),r){const s=r.lastIndexOf("GeoGebra")+8;t.src=r.slice(0,s)+"/deployggb.js"}else t.src="https://www.geogebra.org/apps/deployggb.js";return document.head.appendChild(t),L}}const B={appName:"classic",showMenuBar:!0,showAlgebraInput:!0,showToolBar:!0,customToolBar:"0 39 73 62 | 1 501 67 , 5 19 , 72 75 76 | 2 15 45 , 18 65 , 7 37 | 4 3 8 9 , 13 44 , 58 , 47 | 16 51 64 , 70 | 10 34 53 11 , 24 20 22 , 21 23 | 55 56 57 , 12 | 36 46 , 38 49 50 , 71 14 68 | 30 29 54 32 31 33 | 25 17 26 60 52 61 | 40 41 42 , 27 28 35 , 6",showToolBarHelp:!1,showResetIcon:!1,enableFileFeatures:!1,enableLabelDrags:!1,enableShiftDragZoom:!0,enableRightClick:!0,errorDialogsActive:!1,allowStyleBar:!1,preventFocus:!1,useBrowserForJS:!0,language:"en",borderColor:"transparent"},b=class{constructor(t){o(this,"clientId");o(this,"nickName");o(this,"api");o(this,"context");o(this,"delay");o(this,"currentAnimations",[]);o(this,"embeds",{});o(this,"storageCallback",0);o(this,"initAllEmbeds",()=>{for(const t of this.api.getAllObjectNames("embed"))this.initEmbed(t)});o(this,"objectsInWaiting",[]);o(this,"updateCallback",0);o(this,"dispatchUpdates",()=>{this.updateCallback||(this.updateCallback=setTimeout(this._dispatchUpdates,this.delay))});o(this,"_dispatchUpdates",()=>{const{objectsInWaiting:t}=this;this.objectsInWaiting=[];for(const s of t){const e=this.api.getEmbeddedCalculators(!0),i=e==null?void 0:e[s];i!=null&&i.controller&&this.sendEvent("evalGMContent",i.toJSON(),s);const a=this.api.getCommandString(s,!1);if(a){this.sendEvent("evalCommand",`${s} := ${a}`,s);const n=this.api.getObjectsOfItsGroup(s);n!=null&&n.length&&this.sendEvent("addToGroup",s,n)}if(!a||this.api.isMoveable(s)){const n=this.api.getXML(s);this.sendEvent("evalXML",n,s)}this.sendEvent("select",s,!0)}this.updateCallback=0});o(this,"updateListener",t=>{(this.api.hasUnlabeledPredecessors(t)||this.api.isMoveable(t))&&!this.currentAnimations.includes(t)&&(this.objectsInWaiting.includes(t)||(this.objectsInWaiting.push(t),this.dispatchUpdates()))});o(this,"addListener",t=>{const s=this.api.getImageFileName(t);if(s){const n=this.api.getFileJSON();for(const c of n.archive)c.fileName.includes(s)&&this.sendEvent("addImage",JSON.stringify(c))}const e=this.api.getXML(t),a=this.api.getCommandString(t)&&this.api.getAlgorithmXML(t);this.sendEvent("addObject",a||e,t),this.sendEvent("deselect"),this.sendEvent("select",t,!0),setTimeout(()=>this.initEmbed(t),500)});o(this,"removeListener",t=>{this.sendEvent("deleteObject",t),delete this.embeds[t]});o(this,"renameListener",(t,s)=>{this.sendEvent("renameObject",t,s)});o(this,"lastEditingLabel");o(this,"isSyncingViewState",0);o(this,"stopSyncViewState",()=>{this.isSyncingViewState=0});o(this,"_flushViewState",()=>{const{invXscale:t,invYscale:s,xMin:e,yMin:i}=JSON.parse(this.api.getViewProperties(0)),a=1/t,n=-e/t,c=-i/s;return this.viewState={scale:a,x:n,y:c},this.viewSyncCallback=0,this.viewState});o(this,"clientListener",t=>{let s,e;const i=t.type;switch(i){case"updateStyle":s=t.target,e=this.api.getXML(s),this.sendEvent("evalXML",e);break;case"editorStart":this.lastEditingLabel=t.target;break;case"editorKeyTyped":e=this.api.getEditorState(),this.sendEvent("setEditorState",e,this.lastEditingLabel);break;case"editorStop":this.lastEditingLabel=void 0,this.sendEvent("setEditorState",JSON.stringify({content:""}));break;case"deselect":this.sendEvent("deselect",t.target);break;case"select":this.sendEvent("select",t.target);break;case"embeddedContentChanged":s=t[1],e=t[2],this.sendEvent("embeddedContentChanged",e,s);break;case"undo":case"redo":case"addPolygonComplete":e=this.api.getXML(),this.sendEvent("setXML",e);break;case"addSlide":this.sendEvent(i);break;case"removeSlide":case"moveSlide":case"selectSlide":case"clearSlide":case"orderingChange":e=t[2],this.sendEvent(i,e);break;case"pasteSlide":({cardIdx:e,ggbFile:s}=t),this.sendEvent(i,e,s);break;case"startAnimation":s=t[1],this.currentAnimations.push(s),this.sendEvent(i,s,s);break;case"stopAnimation":s=t[1],this.currentAnimations.splice(this.currentAnimations.indexOf(s),1),this.sendEvent(i,s,s);break;case"groupObjects":case"ungroupObjects":e=t.targets,this.sendEvent(i,e);break;case"pasteElmsComplete":e=t.targets.map(a=>this.api.getXML(a)).join(""),this.sendEvent("evalXML",e);break;case"addGeoToTV":case"removeGeoFromTV":e=t[1],this.sendEvent(i,e);break;case"setValuesOfTV":e=t[2],this.sendEvent(i,e);break;case"showPointsTV":({column:e,show:s}=t),this.sendEvent(i,e,s);break;case"lockTextElement":case"unlockTextElement":e=t[1],this.sendEvent(i,e);break;case"viewChanged2D":this.viewSyncCallback||(this.isSyncingViewState||this.viewState.scale===0?this.viewSyncCallback=setTimeout(this._flushViewState,this.delay):this.viewSyncCallback=setTimeout(this._sendViewSyncEvent,this.delay));break;case"mouseDown":case"deleteGeos":case"dragEnd":break;default:console.debug("[GeoGebra] unhandled event ",t.type,t)}});o(this,"viewSyncCallback",0);o(this,"viewState",{scale:0,x:0,y:0});o(this,"_sendViewSyncEvent",()=>{this._flushViewState(),this.sendEvent("viewChanged2D",JSON.stringify(this.viewState)),this.viewSyncCallback=0});o(this,"_delayedRegisterListeners",()=>{this.registerListeners(),this.viewSyncCallback=0});o(this,"conflictedObjects",[]);o(this,"dispatch",t=>{var c,f;if(this.conflictedObjects.includes(t.label)&&t.type!=="conflictResolution")return;const e=t.embedLabel?this.embeds[t.embedLabel]:this,i=t.type,a=t.label,n=t.content;if(console.debug("[GeoGebra] receive:",i,a,n),i==="addObject")if(e.api.exists(a))if(this.context.isDecider)if(this.context.isDecider(this.clientId)){let l=1,d;do d=`${a}_${l}`,l++;while(e.api.exists(d));this.unregisterListeners(),e.api.renameObject(a,d),this.registerListeners();const p=e.api.getAlgorithmXML(d)||e.api.getXML(d);this.sendEvent("conflictResolution",p,a)}else this.conflictedObjects.push(a);else e.evalXML(n),e.api.previewRefresh();else e.evalXML(n),e.api.previewRefresh();else if(i==="conflictResolution"){const l=this.conflictedObjects.indexOf(a);l!==-1&&this.conflictedObjects.splice(l,1),e.evalXML(n),e.api.previewRefresh()}else if(i==="evalXML")e.evalXML(n),e.api.previewRefresh();else if(i==="setXML")e.setXML(n);else if(i==="evalCommand")e.evalCommand(n),e.api.previewRefresh();else if(i==="deleteObject")e.unregisterListeners(),e===this&&delete this.embeds[n],e.api.deleteObject(n),e.registerListeners();else if(i==="setEditorState")e.unregisterListeners(),e.api.setEditorState(n,a),e.registerListeners();else if(i==="addImage"){const l=JSON.parse(n);e.api.addImage(l.fileName,l.fileContent)}else if(["addSlide","removeSlide","moveSlide","clearSlide"].includes(i))e.api.handleSlideAction(i,n);else if(i==="selectSlide")e.unregisterListeners(),e.api.selectSlide(n),e.registerListeners();else if(i==="renameObject")e.unregisterListeners(),e.api.renameObject(n,a),e.registerListeners();else if(i==="pasteSlide")e.api.handleSlideAction(i,n,a);else if(i==="evalGMContent"){const l=(e.api.getEmbeddedCalculators(!0)||{})[a];l&&l.loadFromJSON(n)}else if(i==="startAnimation")e.api.setAnimating(a,!0),e.api.startAnimation();else if(i==="stopAnimation")e.api.setAnimating(a,!1);else if(i==="select"){if(n){const l=((f=(c=this.context).getColor)==null?void 0:f.call(c,t.clientId))||"#80808080";e.api.addMultiuserSelection(String(t.nickName),l,n,!!a)}}else if(i==="deselect")e.api.removeMultiuserSelections(String(t.nickName));else if(i==="orderingChange")e.api.updateOrdering(n);else if(i==="groupObjects")e.api.groupObjects(n);else if(i==="ungroupObjects")e.api.ungroupObjects(n);else if(i==="addToGroup")e.api.addToGroup(n,a);else if(i==="embeddedContentChanged")e.api.setEmbedContent(a,n);else if(i==="addGeoToTV")e.api.addGeoToTV(n);else if(i==="setValuesOfTV")e.api.setValuesOfTV(n);else if(i==="removeGeoFromTV")e.api.removeGeoFromTV(n);else if(i==="showPointsTV")e.api.showPointsTV(n,a);else if(i==="lockTextElement")e.api.lockTextElement(n);else if(i==="unlockTextElement")e.api.unlockTextElement(n);else if(i==="viewChanged2D")if(e.viewState.scale===0)e.api.evalCommand("Pan(0,0)"),e.startSyncViewState();else{const{scale:l,x:d,y:p}=JSON.parse(n),h=e._flushViewState();e.startSyncViewState(),e.api.evalCommand(`Pan(${d-h.x},${p-h.y})`),e.api.evalCommand(`ZoomIn(${l/h.scale})`)}else console.debug("[GeoGebra] unknown event",i,n,a)});var s;this.api=t.api,this.clientId=t.clientId,this.nickName=t.nickName,this.delay=(s=t.delay)!=null?s:200,this.context=t,setTimeout(()=>{this.api.evalCommand("Pan(0,0)")},this.delay)}createEvent(t,s,e){const i={type:t,content:s,clientId:this.clientId,nickName:this.nickName};return this.context.embedLabel&&(i.embedLabel=this.context.embedLabel),e&&(i.label=e),i}sendEvent(t,s,e){console.log("[GeoGebra] send:",t,e,s),this.context.postMessage(this.createEvent(t,s,e)),this.storageCallback||(this.storageCallback=setTimeout(()=>{this.context.save(this.api.getBase64()),this.storageCallback=0},this.delay))}evalCommand(t){this.unregisterListeners(),this.api.evalCommand(t),this.registerListeners()}evalXML(t){this.unregisterListeners(),this.api.evalXML(t),this.api.updateConstruction(),this.registerListeners(),setTimeout(this.initAllEmbeds,500)}setXML(t){this.unregisterListeners(),this.api.setXML(t),this.api.updateConstruction(),this.registerListeners()}initEmbed(t){if(this.embeds[t])return;const s=this.api.getEmbeddedCalculators();if(!s)return;const e=s[t];if(e&&"registerClientListener"in e){const i=new b({...this.context,clientId:this.clientId,nickName:this.nickName,api:e,embedLabel:t});i.registerListeners(),this.embeds[t]=i}}startSyncViewState(){clearTimeout(this.isSyncingViewState),this.isSyncingViewState=setTimeout(this.stopSyncViewState,1e3)}shouldSyncView(t,s,e,i){return Math.abs(s-t.scale)>b.Threshold/10||Math.abs(e-t.x)>b.Threshold||Math.abs(i-t.y)>b.Threshold}registerListeners(){this.api.registerUpdateListener(this.updateListener),this.api.registerRemoveListener(this.removeListener),this.api.registerAddListener(this.addListener),this.api.registerClientListener(this.clientListener),this.api.registerRenameListener(this.renameListener)}unregisterListeners(){this.api.unregisterUpdateListener(this.updateListener),this.api.unregisterRemoveListener(this.removeListener),this.api.unregisterAddListener(this.addListener),this.api.unregisterClientListener(this.clientListener),this.api.unregisterRenameListener(this.renameListener)}};let E=b;o(E,"Threshold",20);const R=`.netless-app-geogebra{width:100%!important;height:100%!important;overflow:hidden}.netless-app-geogebra.loading{background-color:#fff}.netless-app-geogebra.readonly{user-select:none;pointer-events:none}
`;function U(r,t){const s=new ResizeObserver(()=>t(r));return s.observe(r),()=>s.disconnect()}function P(r,t,s){const e=r.displayer,i=r.room;let a=[];const n=d=>{d.authorId!==e.observerId&&a.forEach(p=>p(d.payload))},c="sync--"+r.appId;return e.addMagixEventListener(c,n),{service:{addListener(d){a.push(d)},postMessage(d){i==null||i.dispatchMagixEvent(c,d)},load(){return t[s]},save(d){r.updateAttributes([s],d)}},disposer:()=>{a=[],e.removeMagixEventListener(c)}}}const F={kind:"GeoGebra",config:{enableShadowDOM:!1},async setup(r){var G,A;const t=r.displayer,s=t.observerId,e=(G=t.state.roomMembers.find(v=>v.memberId===s))==null?void 0:G.payload,i=(e==null?void 0:e.uid)||"",a=(e==null?void 0:e.nickName)||i,n=(A=r.getAppOptions())==null?void 0:A.HTML5Codebase,c=x(r,{uid:"",ggbBase64:""}),f=r.box;f.mountStyles(R);const l=document.createElement("div");l.classList.add("netless-app-geogebra","loading"),i!==c.uid&&c.uid&&l.classList.add("netless-app-geogebra","readonly"),f.mountContent(l);const d=new N,p={...B};p.language=navigator.language.startsWith("zh")?"zh":"en",c.ggbBase64&&(p.ggbBase64=c.ggbBase64),p.id="ggb_"+r.appId;let h;const C=P(r,c,"ggbBase64");function O(){const{width:v,height:S}=l.getBoundingClientRect();h==null||h.setWidth(v),h==null||h.setHeight(S)}p.appletOnLoad=v=>{console.log(`[GeoGebra]: loaded ${JSON.stringify(p.id)}`),h=v,O(),l.classList.remove("loading");const S=r.displayer,I=new E({clientId:S.observerId,nickName:a,api:v,isDecider:w=>S.state.roomMembers.map(y=>y.memberId).every(y=>w<=y),getColor:w=>{const j=S.memberState(w).strokeColor;return"#"+j.map(y=>y.toString(16).padStart(2,"0")).join("")+"80"},...C.service});I.registerListeners(),C.service.addListener(w=>{I.dispatch(w),h==null||h.setUndoPoint()})},d.add(()=>U(l,O)),r.emitter.on("destroy",()=>{console.log("[GeoGebra]: destroy"),d.flushAll(),C.disposer(),h==null||h.remove()});const J=await D(n),T=new J(p);n&&T.setHTML5Codebase(n),T.inject(l)}};return u.default=F,Object.defineProperties(u,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),u}({});
var NetlessAppGeoGebra=function(p){"use strict";var H=Object.defineProperty,Z=Object.defineProperties;var K=Object.getOwnPropertyDescriptors;var N=Object.getOwnPropertySymbols;var Y=Object.prototype.hasOwnProperty,q=Object.prototype.propertyIsEnumerable;var V=(p,h,g)=>h in p?H(p,h,{enumerable:!0,configurable:!0,writable:!0,value:g}):p[h]=g,E=(p,h)=>{for(var g in h||(h={}))Y.call(h,g)&&V(p,g,h[g]);if(N)for(var g of N(h))q.call(h,g)&&V(p,g,h[g]);return p},X=(p,h)=>Z(p,K(h));const h="!#%()*+,-./:;=?@[]^_`{|}~ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",g=h.length,C=Array(20),D=()=>{for(let i=0;i<20;i++)C[i]=h.charAt(Math.random()*g);return C.join("")};function k(i){try{return i()}catch(a){console.error(a)}}class x{constructor(){this.disposers=new Map}addDisposer(a,e=this.genUID()){return this.flush(e),this.disposers.set(e,Array.isArray(a)?()=>a.forEach(k):a),e}add(a,e=this.genUID()){return this.addDisposer(a(),e)}addEventListener(a,e,s,t,n=this.genUID()){return a.addEventListener(e,s,t),this.addDisposer(()=>a.removeEventListener(e,s,t),n),n}setTimeout(a,e,s=this.genUID()){const t=window.setTimeout(()=>{this.remove(s),a()},e);return this.addDisposer(()=>window.clearTimeout(t),s)}setInterval(a,e,s=this.genUID()){const t=window.setInterval(a,e);return this.addDisposer(()=>window.clearInterval(t),s)}remove(a){const e=this.disposers.get(a);return this.disposers.delete(a),e}flush(a){const e=this.remove(a);if(e)try{e()}catch(s){console.error(s)}}flushAll(){this.disposers.forEach(k),this.disposers.clear()}genUID(){let a;do a=D();while(this.disposers.has(a));return a}}function B(i){return i!=null&&typeof i=="object"&&!Array.isArray(i)}function R(i,a){let e=i.getAttributes();if(e||(i.setAttributes(a),e=i.getAttributes()),!e)throw new Error("[NetlessAppMonaco] No attributes");return B(a)&&Object.keys(a).forEach(s=>{Object.prototype.hasOwnProperty.call(e,s)||i.updateAttributes([s],a[s])}),e}let v;function U(i){if(window.GGBApplet)return Promise.resolve(window.GGBApplet);if(v)return v;{const a=document.createElement("script");if(v=new Promise((e,s)=>{a.onload=()=>e(window.GGBApplet),a.onerror=()=>{v=void 0,s()}}),i){const e=i.lastIndexOf("GeoGebra")+8;a.src=i.slice(0,e)+"/deployggb.js"}else a.src="https://www.geogebra.org/apps/deployggb.js";return document.head.appendChild(a),v}}const _={appName:"classic",showMenuBar:!0,showAlgebraInput:!0,showToolBar:!0,customToolBar:"0 39 73 62 | 1 501 67 , 5 19 , 72 75 76 | 2 15 45 , 18 65 , 7 37 | 4 3 8 9 , 13 44 , 58 , 47 | 16 51 64 , 70 | 10 34 53 11 , 24 20 22 , 21 23 | 55 56 57 , 12 | 36 46 , 38 49 50 , 71 14 68 | 30 29 54 32 31 33 | 25 17 26 60 52 61 | 40 41 42 , 27 28 35 , 6",showToolBarHelp:!1,showResetIcon:!1,enableFileFeatures:!1,enableLabelDrags:!1,enableShiftDragZoom:!0,enableRightClick:!0,errorDialogsActive:!1,allowStyleBar:!1,preventFocus:!1,useBrowserForJS:!0,language:"en",borderColor:"transparent"},L=class{constructor(i){var a;this.currentAnimations=[],this.embeds={},this.storageCallback=0,this.initAllEmbeds=()=>{for(const e of this.api.getAllObjectNames("embed"))this.initEmbed(e)},this.objectsInWaiting=[],this.updateCallback=0,this.dispatchUpdates=()=>{this.updateCallback||(this.updateCallback=setTimeout(this._dispatchUpdates,this.delay))},this._dispatchUpdates=()=>{const{objectsInWaiting:e}=this;this.objectsInWaiting=[];for(const s of e){const t=this.api.getEmbeddedCalculators(!0),n=t==null?void 0:t[s];n!=null&&n.controller&&this.sendEvent("evalGMContent",n.toJSON(),s);const o=this.api.getCommandString(s,!1);if(o){this.sendEvent("evalCommand",`${s} := ${o}`,s);const r=this.api.getObjectsOfItsGroup(s);r!=null&&r.length&&this.sendEvent("addToGroup",s,r)}if(!o||this.api.isMoveable(s)){const r=this.api.getXML(s);this.sendEvent("evalXML",r,s)}this.sendEvent("select",s,!0)}this.updateCallback=0},this.updateListener=e=>{(this.api.hasUnlabeledPredecessors(e)||this.api.isMoveable(e))&&!this.currentAnimations.includes(e)&&(this.objectsInWaiting.includes(e)||(this.objectsInWaiting.push(e),this.dispatchUpdates()))},this.addListener=e=>{const s=this.api.getImageFileName(e);if(s){const r=this.api.getFileJSON();for(const u of r.archive)u.fileName.includes(s)&&this.sendEvent("addImage",JSON.stringify(u))}const t=this.api.getXML(e),o=this.api.getCommandString(e)&&this.api.getAlgorithmXML(e);this.sendEvent("addObject",o||t,e),this.sendEvent("deselect"),this.sendEvent("select",e,!0),setTimeout(()=>this.initEmbed(e),500)},this.removeListener=e=>{this.sendEvent("deleteObject",e),delete this.embeds[e]},this.renameListener=(e,s)=>{this.sendEvent("renameObject",e,s)},this.isSyncingViewState=0,this.stopSyncViewState=()=>{this.isSyncingViewState=0},this._flushViewState=()=>{const{invXscale:e,invYscale:s,xMin:t,yMin:n}=JSON.parse(this.api.getViewProperties(0)),o=1/e,r=-t/e,u=-n/s;return this.viewState={scale:o,x:r,y:u},this.viewSyncCallback=0,this.viewState},this.clientListener=e=>{let s,t;const n=e.type;switch(n){case"updateStyle":s=e.target,t=this.api.getXML(s),this.sendEvent("evalXML",t);break;case"editorStart":this.lastEditingLabel=e.target;break;case"editorKeyTyped":t=this.api.getEditorState(),this.sendEvent("setEditorState",t,this.lastEditingLabel);break;case"editorStop":this.lastEditingLabel=void 0,this.sendEvent("setEditorState",JSON.stringify({content:""}));break;case"deselect":this.sendEvent("deselect",e.target);break;case"select":this.sendEvent("select",e.target);break;case"embeddedContentChanged":s=e[1],t=e[2],this.sendEvent("embeddedContentChanged",t,s);break;case"undo":case"redo":case"addPolygonComplete":t=this.api.getXML(),this.sendEvent("setXML",t);break;case"addSlide":this.sendEvent(n);break;case"removeSlide":case"moveSlide":case"selectSlide":case"clearSlide":case"orderingChange":t=e[2],this.sendEvent(n,t);break;case"pasteSlide":({cardIdx:t,ggbFile:s}=e),this.sendEvent(n,t,s);break;case"startAnimation":s=e[1],this.currentAnimations.push(s),this.sendEvent(n,s,s);break;case"stopAnimation":s=e[1],this.currentAnimations.splice(this.currentAnimations.indexOf(s),1),this.sendEvent(n,s,s);break;case"groupObjects":case"ungroupObjects":t=e.targets,this.sendEvent(n,t);break;case"pasteElmsComplete":t=e.targets.map(o=>this.api.getXML(o)).join(""),this.sendEvent("evalXML",t);break;case"addGeoToTV":case"removeGeoFromTV":t=e[1],this.sendEvent(n,t);break;case"setValuesOfTV":t=e[2],this.sendEvent(n,t);break;case"showPointsTV":({column:t,show:s}=e),this.sendEvent(n,t,s);break;case"lockTextElement":case"unlockTextElement":t=e[1],this.sendEvent(n,t);break;case"viewChanged2D":this.viewSyncCallback||(this.isSyncingViewState||this.viewState.scale===0?this.viewSyncCallback=setTimeout(this._flushViewState,this.delay):this.viewSyncCallback=setTimeout(this._sendViewSyncEvent,this.delay));break;case"mouseDown":case"deleteGeos":case"dragEnd":break;default:console.debug("[GeoGebra] unhandled event ",e.type,e)}},this.viewSyncCallback=0,this.viewState={scale:0,x:0,y:0},this._sendViewSyncEvent=()=>{this._flushViewState(),this.sendEvent("viewChanged2D",JSON.stringify(this.viewState)),this.viewSyncCallback=0},this._delayedRegisterListeners=()=>{this.registerListeners(),this.viewSyncCallback=0},this.conflictedObjects=[],this.dispatch=e=>{var u,m;if(this.conflictedObjects.includes(e.label)&&e.type!=="conflictResolution")return;const t=e.embedLabel?this.embeds[e.embedLabel]:this,n=e.type,o=e.label,r=e.content;if(console.debug("[GeoGebra] receive:",n,o,r),n==="addObject")if(t.api.exists(o))if(this.context.isDecider)if(this.context.isDecider(this.clientId)){let l=1,c;do c=`${o}_${l}`,l++;while(t.api.exists(c));this.unregisterListeners(),t.api.renameObject(o,c),this.registerListeners();const d=t.api.getAlgorithmXML(c)||t.api.getXML(c);this.sendEvent("conflictResolution",d,o)}else this.conflictedObjects.push(o);else t.evalXML(r),t.api.previewRefresh();else t.evalXML(r),t.api.previewRefresh();else if(n==="conflictResolution"){const l=this.conflictedObjects.indexOf(o);l!==-1&&this.conflictedObjects.splice(l,1),t.evalXML(r),t.api.previewRefresh()}else if(n==="evalXML")t.evalXML(r),t.api.previewRefresh();else if(n==="setXML")t.setXML(r);else if(n==="evalCommand")t.evalCommand(r),t.api.previewRefresh();else if(n==="deleteObject")t.unregisterListeners(),t===this&&delete this.embeds[r],t.api.deleteObject(r),t.registerListeners();else if(n==="setEditorState")t.unregisterListeners(),t.api.setEditorState(r,o),t.registerListeners();else if(n==="addImage"){const l=JSON.parse(r);t.api.addImage(l.fileName,l.fileContent)}else if(["addSlide","removeSlide","moveSlide","clearSlide"].includes(n))t.api.handleSlideAction(n,r);else if(n==="selectSlide")t.unregisterListeners(),t.api.selectSlide(r),t.registerListeners();else if(n==="renameObject")t.unregisterListeners(),t.api.renameObject(r,o),t.registerListeners();else if(n==="pasteSlide")t.api.handleSlideAction(n,r,o);else if(n==="evalGMContent"){const l=(t.api.getEmbeddedCalculators(!0)||{})[o];l&&l.loadFromJSON(r)}else if(n==="startAnimation")t.api.setAnimating(o,!0),t.api.startAnimation();else if(n==="stopAnimation")t.api.setAnimating(o,!1);else if(n==="select"){if(r){const l=((m=(u=this.context).getColor)==null?void 0:m.call(u,e.clientId))||"#80808080";t.api.addMultiuserSelection(String(e.nickName),l,r,!!o)}}else if(n==="deselect")t.api.removeMultiuserSelections(String(e.nickName));else if(n==="orderingChange")t.api.updateOrdering(r);else if(n==="groupObjects")t.api.groupObjects(r);else if(n==="ungroupObjects")t.api.ungroupObjects(r);else if(n==="addToGroup")t.api.addToGroup(r,o);else if(n==="embeddedContentChanged")t.api.setEmbedContent(o,r);else if(n==="addGeoToTV")t.api.addGeoToTV(r);else if(n==="setValuesOfTV")t.api.setValuesOfTV(r);else if(n==="removeGeoFromTV")t.api.removeGeoFromTV(r);else if(n==="showPointsTV")t.api.showPointsTV(r,o);else if(n==="lockTextElement")t.api.lockTextElement(r);else if(n==="unlockTextElement")t.api.unlockTextElement(r);else if(n==="viewChanged2D")if(t.viewState.scale===0)t.api.evalCommand("Pan(0,0)"),t.startSyncViewState();else{const{scale:l,x:c,y:d}=JSON.parse(r),b=t._flushViewState();t.startSyncViewState(),t.api.evalCommand(`Pan(${c-b.x},${d-b.y})`),t.api.evalCommand(`ZoomIn(${l/b.scale})`)}else console.debug("[GeoGebra] unknown event",n,r,o)},this.api=i.api,this.clientId=i.clientId,this.nickName=i.nickName,this.delay=(a=i.delay)!=null?a:200,this.context=i,setTimeout(()=>{this.api.evalCommand("Pan(0,0)")},this.delay)}createEvent(i,a,e){const s={type:i,content:a,clientId:this.clientId,nickName:this.nickName};return this.context.embedLabel&&(s.embedLabel=this.context.embedLabel),e&&(s.label=e),s}sendEvent(i,a,e){console.log("[GeoGebra] send:",i,e,a),this.context.postMessage(this.createEvent(i,a,e)),this.storageCallback||(this.storageCallback=setTimeout(()=>{this.context.save(this.api.getBase64()),this.storageCallback=0},this.delay))}evalCommand(i){this.unregisterListeners(),this.api.evalCommand(i),this.registerListeners()}evalXML(i){this.unregisterListeners(),this.api.evalXML(i),this.api.updateConstruction(),this.registerListeners(),setTimeout(this.initAllEmbeds,500)}setXML(i){this.unregisterListeners(),this.api.setXML(i),this.api.updateConstruction(),this.registerListeners()}initEmbed(i){if(this.embeds[i])return;const a=this.api.getEmbeddedCalculators();if(!a)return;const e=a[i];if(e&&"registerClientListener"in e){const s=new L(X(E({},this.context),{clientId:this.clientId,nickName:this.nickName,api:e,embedLabel:i}));s.registerListeners(),this.embeds[i]=s}}startSyncViewState(){clearTimeout(this.isSyncingViewState),this.isSyncingViewState=setTimeout(this.stopSyncViewState,1e3)}shouldSyncView(i,a,e,s){return Math.abs(a-i.scale)>L.Threshold/10||Math.abs(e-i.x)>L.Threshold||Math.abs(s-i.y)>L.Threshold}registerListeners(){this.api.registerUpdateListener(this.updateListener),this.api.registerRemoveListener(this.removeListener),this.api.registerAddListener(this.addListener),this.api.registerClientListener(this.clientListener),this.api.registerRenameListener(this.renameListener)}unregisterListeners(){this.api.unregisterUpdateListener(this.updateListener),this.api.unregisterRemoveListener(this.removeListener),this.api.unregisterAddListener(this.addListener),this.api.unregisterClientListener(this.clientListener),this.api.unregisterRenameListener(this.renameListener)}};let M=L;M.Threshold=20;var P=(()=>`.netless-app-geogebra{width:100%!important;height:100%!important;overflow:hidden}.netless-app-geogebra.loading{background-color:#fff}.netless-app-geogebra.readonly{user-select:none;pointer-events:none}
`)();function F(i,a){const e=new ResizeObserver(()=>a(i));return e.observe(i),()=>e.disconnect()}function J(i,a,e){const s=i.getDisplayer(),t=i.getRoom();let n=[];const o=l=>{l.authorId!==s.observerId&&n.forEach(c=>c(l.payload))},r="sync--"+i.appId;return s.addMagixEventListener(r,o),{service:{addListener(l){n.push(l)},postMessage(l){t==null||t.dispatchMagixEvent(r,l)},load(){return a[e]},save(l){i.updateAttributes([e],l)}},disposer:()=>{n=[],s.removeMagixEventListener(r)}}}const W=new Set(["classic","graphing","geometry","3d","suite","evaluator","scientific"]),$={kind:"GeoGebra",async setup(i){var T,G;const a=i.getDisplayer(),e=a.observerId,s=(T=a.state.roomMembers.find(f=>f.memberId===e))==null?void 0:T.payload,t=(s==null?void 0:s.uid)||"",n=(s==null?void 0:s.nickName)||t,o=(G=i.getAppOptions())==null?void 0:G.HTML5Codebase,r=R(i,{uid:"",ggbBase64:"",appName:"classic"}),u=i.getBox();u.mountStyles(P);const m=document.createElement("div");m.classList.add("netless-app-geogebra","loading"),t!==r.uid&&r.uid&&m.classList.add("netless-app-geogebra","readonly"),u.mountContent(m);const l=new x,c=E({},_);W.has(r.appName)&&(c.appName=r.appName),c.language=navigator.language.startsWith("zh")?"zh":"en",r.ggbBase64&&(c.ggbBase64=r.ggbBase64),c.id="ggb_"+i.appId;let d;const b=J(i,r,"ggbBase64");function A(){const{width:f,height:S}=m.getBoundingClientRect();d==null||d.setWidth(f),d==null||d.setHeight(S)}c.appletOnLoad=f=>{console.log(`[GeoGebra]: loaded ${JSON.stringify(c.id)}`),d=f,A(),m.classList.remove("loading");const S=i.getDisplayer(),I=new M(E({clientId:S.observerId,nickName:n,api:f,isDecider:w=>S.state.roomMembers.map(y=>y.memberId).every(y=>w<=y),getColor:w=>{const j=S.memberState(w).strokeColor;return"#"+j.map(y=>y.toString(16).padStart(2,"0")).join("")+"80"}},b.service));I.registerListeners(),b.service.addListener(w=>{I.dispatch(w),d==null||d.setUndoPoint()})},l.add(()=>F(m,A)),i.emitter.on("destroy",()=>{console.log("[GeoGebra]: destroy"),l.flushAll(),b.disposer(),d==null||d.remove()});const z=await U(o),O=new z(c);o&&O.setHTML5Codebase(o),O.inject(m)}};return p.default=$,Object.defineProperties(p,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}}),p}({});
//# sourceMappingURL=main.iife.js.map
{
"name": "@netless/app-geogebra",
"version": "0.0.6",
"main": "dist/main.js",
"module": "dist/main.mjs",
"version": "0.0.7",
"main": "dist/main.cjs.js",
"module": "dist/main.es.js",
"unpkg": "dist/main.iife.js",

@@ -15,3 +15,3 @@ "jsdelivr": "dist/main.iife.js",

"@netless/app-shared": "0.1.2",
"side-effect-manager": "^1.1.1"
"side-effect-manager": "^1.1.0"
},

@@ -18,0 +18,0 @@ "scripts": {

@@ -23,2 +23,3 @@ import { ensureAttributes } from "@netless/app-shared";

ggbBase64: string;
appName?: "classic" | "graphing" | "geometry" | "3d" | "suite" | "evaluator" | "scientific";
}

@@ -31,2 +32,4 @@

const ValidAppNames = new Set(["classic", "graphing", "geometry", "3d", "suite", "evaluator", "scientific"]);
/**

@@ -43,7 +46,4 @@ * NOTE: GeoGebra is licensed under GPLv3 and is free only in non-commercial use.

kind: "GeoGebra",
config: {
enableShadowDOM: false,
},
async setup(context) {
const displayer = context.displayer;
const displayer = context.getDisplayer();
const memberId = displayer.observerId;

@@ -61,5 +61,6 @@ const userPayload: UserPayload | undefined = displayer.state.roomMembers.find(

ggbBase64: "",
appName: "classic",
});
const box = context.box;
const box = context.getBox();
box.mountStyles(styles);

@@ -77,2 +78,5 @@

const params: GGBAppletParameters = { ...defaultParameters };
if (ValidAppNames.has(attrs.appName!)) {
params.appName = attrs.appName;
}
params.language = navigator.language.startsWith("zh") ? "zh" : "en";

@@ -101,3 +105,3 @@ if (attrs.ggbBase64) {

const displayer = context.displayer;
const displayer = context.getDisplayer();
const liveApp = new LiveApp({

@@ -104,0 +108,0 @@ clientId: displayer.observerId,

@@ -23,4 +23,4 @@ import type { Event } from "white-web-sdk";

} {
const displayer = context.displayer;
const room = context.room;
const displayer = context.getDisplayer();
const room = context.getRoom();

@@ -47,3 +47,3 @@ // eslint-disable-next-line @typescript-eslint/no-explicit-any

load() {
return attributes[key];
return attributes[key]!;
},

@@ -50,0 +50,0 @@ save(value: string) {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc