jsxgraph 1.4.4 → 1.4.6

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 (56) hide show
  1. package/README.md +24 -0
  2. package/build/Readme.md +17 -0
  3. package/build/bin/jsxcompressor.js +1 -0
  4. package/build/bin/jsxgraphcore-min.js +7 -0
  5. package/build/bin/jsxgraphcore.js +83017 -0
  6. package/build/bin/jsxgraphcore.min.js +67 -0
  7. package/build/compressor.build.json +14 -0
  8. package/build/compressor.deps.js +8 -0
  9. package/build/core-amd.build.json +14 -0
  10. package/build/core-amd.deps.js +81 -0
  11. package/build/core.build.json +14 -0
  12. package/build/core.deps.js +102 -0
  13. package/build/plot.build.json +15 -0
  14. package/distrib/README.md +24 -0
  15. package/distrib/geogebra.min.js +1 -1
  16. package/distrib/geonext.min.js +1 -1
  17. package/distrib/index.d.ts +28 -7
  18. package/distrib/intergeo.min.js +1 -1
  19. package/distrib/jsxgraph.css +6 -0
  20. package/distrib/jsxgraphcore.js +3 -3
  21. package/distrib/jsxgraphsrc.js +3558 -1857
  22. package/distrib/sketch.min.js +1 -1
  23. package/package.json +1 -1
  24. package/src/3d/box3d.js +43 -38
  25. package/src/3d/curve3d.js +157 -53
  26. package/src/3d/element3d.js +84 -0
  27. package/src/3d/linspace3d.js +427 -146
  28. package/src/3d/point3d.js +360 -123
  29. package/src/3d/surface3d.js +140 -42
  30. package/src/3d/view3d.js +319 -164
  31. package/src/base/board.js +163 -78
  32. package/src/base/constants.js +8 -1
  33. package/src/base/curve.js +51 -9
  34. package/src/base/polygon.js +111 -69
  35. package/src/base/text.js +122 -19
  36. package/src/base/ticks.js +12 -3
  37. package/src/element/button.js +7 -3
  38. package/src/element/checkbox.js +8 -4
  39. package/src/element/composition.js +7 -1
  40. package/src/element/conic.js +2 -2
  41. package/src/element/input.js +9 -5
  42. package/src/jsxgraph.js +4 -1
  43. package/src/loadjsxgraph.js +13 -8
  44. package/src/math/clip.js +34 -134
  45. package/src/math/geometry.js +204 -3
  46. package/src/math/math.js +1 -2
  47. package/src/math/nlp.js +865 -774
  48. package/src/options.js +185 -12
  49. package/src/options3d.js +24 -7
  50. package/src/parser/jessiecode.js +9 -3
  51. package/src/renderer/abstract.js +26 -15
  52. package/src/renderer/canvas.js +2 -2
  53. package/src/renderer/svg.js +15 -2
  54. package/src/utils/env.js +36 -53
  55. package/src/utils/type.js +75 -2
  56. package/src/3d/threed.js +0 -38
package/src/utils/env.js CHANGED
@@ -793,94 +793,76 @@ define(['jxg', 'utils/type'], function (JXG, Type) {
793
793
  window.setTimeout(timerFun, 1);
794
794
  },
795
795
 
796
- /**
797
- * Calculate the scale factor and vertical shift for the JSXGraph div
798
- * in full screen mode.
799
- *
800
- * @param {Object} obj Reference to a DOM node.
801
- * @returns Object {scale: number, vshift: number}
802
- * @see JXG.Board#fullscreenListener
803
- * @private
804
- */
805
- _getScaleFactors: function (node) {
806
- var width = node.getBoundingClientRect().width,
807
- height = node.getBoundingClientRect().height,
808
-
809
- // Determine the maximum scale factor.
810
- r_w = window.screen.width / width,
811
- r_h = window.screen.height / height,
812
-
813
- // Determine the vertical shift to place the div in the center of the screen
814
- vshift = (window.screen.height - height) * 0.5,
815
-
816
- // Scaling factor: if not supplied, it's taken as large as possible
817
- scale = Math.min(r_w, r_h);
818
-
819
- // Adapt vshift and scale for landscape on tablets
820
- if (window.matchMedia && window.matchMedia('(orientation:landscape)').matches &&
821
- window.screen.width < window.screen.height) {
822
- // Landscape on iOS: it returns 'landscape', but still width < height.
823
- r_w = window.screen.height / width;
824
- r_h = window.screen.width / height;
825
- scale = Math.min(r_w, r_h);
826
- vshift = (window.screen.width - height) * 0.5;
827
- }
828
- scale *= 0.85;
829
-
830
- return { scale: scale, vshift: vshift, width: width };
831
- },
832
-
833
796
  /**
834
797
  * Scale and vertically shift a DOM element (usually a JSXGraph div)
835
798
  * inside of a parent DOM
836
799
  * element which is set to fullscreen.
837
800
  * This is realized with a CSS transformation.
838
- * *
801
+ *
839
802
  * @param {String} wrap_id id of the parent DOM element which is in fullscreen mode
840
803
  * @param {String} inner_id id of the DOM element which is scaled and shifted
841
- * @param {Number} scale Scaling factor
842
- * @param {Number} vshift Vertical shift (in pixel)
804
+ * @param {Object} doc document object or shadow root
843
805
  *
844
806
  * @private
845
807
  * @see JXG.Board#toFullscreen
846
808
  * @see JXG.Board#fullscreenListener
847
809
  *
848
810
  */
849
- scaleJSXGraphDiv: function (wrap_id, inner_id, scale, vshift) {
850
- var len = document.styleSheets.length, style,
811
+ scaleJSXGraphDiv: function (wrap_id, inner_id, doc) {
812
+ var len = doc.styleSheets.length, style, rule, w, h, b, wi, hi, bi,
813
+ scale_l, vshift_l, // scale_p, vshift_p,
814
+ f = 0.85,
815
+ rule_inner_l, // rule_inner_p,
851
816
 
852
817
  pseudo_keys = [':fullscreen', ':-webkit-full-screen', ':-moz-full-screen', ':-ms-fullscreen'],
853
818
  len_pseudo = pseudo_keys.length, i,
854
819
 
855
- // CSS rules to center the inner div horizontally and vertically.
856
- rule_inner = '{margin:0 auto;transform:matrix(' + scale + ',0,0,' + scale + ',0,' + vshift + ');}',
857
-
858
820
  // A previously installed CSS rule to center the JSXGraph div has to
859
821
  // be searched and removed again.
860
822
  regex = new RegExp('.*#' + wrap_id + ':.*full.*screen.*#' + inner_id + '.*auto;.*transform:.*matrix');
861
823
 
824
+ b = doc.getElementById(wrap_id).getBoundingClientRect();
825
+ h = b.height;
826
+ w = b.width;
827
+
828
+ bi = doc.getElementById(inner_id).getBoundingClientRect();
829
+ hi = bi.height;
830
+ wi = bi.width;
831
+
832
+ if (wi / hi >= w / h) {
833
+ scale_l = f * w / wi;
834
+ } else {
835
+ scale_l = f * h / hi;
836
+ }
837
+ vshift_l = (h - hi) * 0.5;
838
+
839
+ // CSS rules to center the inner div horizontally and vertically.
840
+ rule_inner_l = '{margin:0 auto;transform:matrix(' + scale_l + ',0,0,' + scale_l + ',0,' + vshift_l + ');}';
841
+
862
842
  if (len === 0) {
863
843
  // In case there is not a single CSS rule defined at all.
864
844
  style = document.createElement('style');
865
845
  // WebKit hack :(
866
846
  style.appendChild(document.createTextNode(''));
867
847
  // Add the <style> element to the page
868
- document.body.appendChild(style);
869
- len = document.styleSheets.length;
848
+ doc.appendChild(style);
849
+ len = doc.styleSheets.length;
870
850
  }
871
851
 
872
852
  // Remove a previously installed CSS rule.
873
- if (document.styleSheets[len - 1].cssRules.length > 0 &&
874
- regex.test(document.styleSheets[len - 1].cssRules[0].cssText) &&
875
- document.styleSheets[len - 1].deleteRule) {
876
-
877
- document.styleSheets[len - 1].deleteRule(0);
853
+ if (doc.styleSheets[len - 1].cssRules.length > 0 &&
854
+ regex.test(doc.styleSheets[len - 1].cssRules[0].cssText) &&
855
+ doc.styleSheets[len - 1].deleteRule) {
856
+ doc.styleSheets[len - 1].deleteRule(0);
878
857
  }
879
858
 
880
859
  // Install a CSS rule to center the JSXGraph div at the first position of the list.
881
860
  for (i = 0; i < len_pseudo; i++) {
882
861
  try {
883
- document.styleSheets[len - 1].insertRule('#' + wrap_id + pseudo_keys[i] + ' #' + inner_id + rule_inner, 0);
862
+ rule = '#' + wrap_id + pseudo_keys[i] + ' #' + inner_id + rule_inner_l;
863
+ // rule = '@media all and (orientation:landscape) {' + rule + '}';
864
+ doc.styleSheets[len - 1].insertRule(rule, 0);
865
+
884
866
  break;
885
867
  } catch (err) {
886
868
  // console.log('JXG.scaleJSXGraphDiv: Could not add CSS rule "' + pseudo_keys[i] + '".');
@@ -892,6 +874,7 @@ define(['jxg', 'utils/type'], function (JXG, Type) {
892
874
  console.log('One possible reason could be that the id of the JSXGraph container does not start with a letter.');
893
875
  }
894
876
  }
877
+
895
878
  });
896
879
 
897
880
  return JXG;
package/src/utils/type.js CHANGED
@@ -141,13 +141,21 @@ define([
141
141
  * @returns {Boolean} True, if v is of type JXG.Point.
142
142
  */
143
143
  isPoint: function (v) {
144
- if (v !== null && typeof v === 'object') {
144
+ if (v !== null && typeof v === 'object' && this.exists(v.elementClass)) {
145
145
  return (v.elementClass === Const.OBJECT_CLASS_POINT);
146
146
  }
147
147
 
148
148
  return false;
149
149
  },
150
150
 
151
+ isPoint3D: function (v) {
152
+ if (v !== null && typeof v === 'object' && this.exists(v.elType)) {
153
+ return (v.elType === 'point3d');
154
+ }
155
+
156
+ return false;
157
+ },
158
+
151
159
  /**
152
160
  * Checks if a given variable is a reference of a JSXGraph Point element or an array of length at least two or
153
161
  * a function returning an array of length two or three.
@@ -395,6 +403,71 @@ define([
395
403
  return points;
396
404
  },
397
405
 
406
+ /**
407
+ * Test if the parents array contains existing points. If instead parents contains coordinate arrays or
408
+ * function returning coordinate arrays
409
+ * free points with these coordinates are created.
410
+ *
411
+ * @param {JXG.View3D} view View3D object
412
+ * @param {Array} parents Array containing parent elements for a new object. This array may contain
413
+ * <ul>
414
+ * <li> {@link JXG.Point3D} objects
415
+ * <li> {@link JXG.GeometryElement#name} of {@link JXG.Point3D} objects
416
+ * <li> {@link JXG.GeometryElement#id} of {@link JXG.Point3D} objects
417
+ * <li> Coordinates of 3D points given as array of numbers of length three, e.g. [2, 3, 1].
418
+ * <li> Coordinates of 3D points given as array of functions of length three. Each function returns one coordinate, e.g.
419
+ * [function(){ return 2; }, function(){ return 3; }, function(){ return 1; }]
420
+ * <li> Function returning coordinates, e.g. function() { return [2, 3, 1]; }
421
+ * </ul>
422
+ * In the last three cases a new 3D point will be created.
423
+ * @param {String} attrClass Main attribute class of newly created 3D points, see {@link JXG#copyAttributes}
424
+ * @param {Array} attrArray List of subtype attributes for the newly created 3D points. The list of subtypes is mapped to the list of new 3D points.
425
+ * @returns {Array} List of newly created {@link JXG.Point3D} elements or false if not all returned elements are 3D points.
426
+ */
427
+ providePoints3D: function (view, parents, attributes, attrClass, attrArray) {
428
+ var i, j,
429
+ len,
430
+ lenAttr = 0,
431
+ points = [], attr, val;
432
+
433
+ if (!this.isArray(parents)) {
434
+ parents = [parents];
435
+ }
436
+ len = parents.length;
437
+ if (this.exists(attrArray)) {
438
+ lenAttr = attrArray.length;
439
+ }
440
+ if (lenAttr === 0) {
441
+ attr = this.copyAttributes(attributes, view.board.options, attrClass);
442
+ }
443
+
444
+ for (i = 0; i < len; ++i) {
445
+ if (lenAttr > 0) {
446
+ j = Math.min(i, lenAttr - 1);
447
+ attr = this.copyAttributes(attributes, view.board.options, attrClass, attrArray[j]);
448
+ }
449
+
450
+ if (this.isArray(parents[i]) && parents[i].length > 1) {
451
+ points.push(view.create('point3d', parents[i], attr));
452
+ points[points.length - 1]._is_new = true;
453
+ } else if (this.isFunction(parents[i])) {
454
+ val = parents[i]();
455
+ if (this.isArray(val) && (val.length > 1)) {
456
+ points.push(view.create('point3d', [parents[i]], attr));
457
+ points[points.length - 1]._is_new = true;
458
+ }
459
+ } else {
460
+ points.push(view.select(parents[i]));
461
+ }
462
+
463
+ if (!this.isPoint3D(points[i])) {
464
+ return false;
465
+ }
466
+ }
467
+
468
+ return points;
469
+ },
470
+
398
471
  /**
399
472
  * Generates a function which calls the function fn in the scope of owner.
400
473
  * @param {Function} fn Function to call.
@@ -732,7 +805,7 @@ define([
732
805
  var x = Math.abs(val),
733
806
  str;
734
807
 
735
- if (x > 0.1) {
808
+ if (x >= 0.1) {
736
809
  str = this.toFixed(val, 2);
737
810
  } else if (x >= 0.01) {
738
811
  str = this.toFixed(val, 4);
package/src/3d/threed.js DELETED
@@ -1,38 +0,0 @@
1
- /*
2
- Copyright 2008-2022
3
- Matthias Ehmann,
4
- Carsten Miller,
5
- Andreas Walter,
6
- Alfred Wassermann
7
-
8
- This file is part of JSXGraph.
9
-
10
- JSXGraph is free software dual licensed under the GNU LGPL or MIT License.
11
-
12
- You can redistribute it and/or modify it under the terms of the
13
-
14
- * GNU Lesser General Public License as published by
15
- the Free Software Foundation, either version 3 of the License, or
16
- (at your option) any later version
17
- OR
18
- * MIT License: https://github.com/jsxgraph/jsxgraph/blob/master/LICENSE.MIT
19
-
20
- JSXGraph is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU Lesser General Public License for more details.
24
-
25
- You should have received a copy of the GNU Lesser General Public License and
26
- the MIT License along with JSXGraph. If not, see <http://www.gnu.org/licenses/>
27
- and <http://opensource.org/licenses/MIT/>.
28
- */
29
- /*global JXG:true, define: true*/
30
-
31
- define(['jxg'
32
- ], function (JXG) {
33
- "use strict";
34
-
35
- JXG.ThreeD = {};
36
-
37
- return JXG.ThreeD;
38
- });