Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

iphonex-patch.js 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import _extends from 'babel-runtime/helpers/extends';
  2. /*
  3. Copyright 2013-2015 ASIAL CORPORATION
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. */
  14. // This object should not be exposed to users. Please keep this private.
  15. var iPhoneXPatch = {};
  16. iPhoneXPatch.isIPhoneXPortraitPatchActive = function () {
  17. return document.documentElement.getAttribute('onsflag-iphonex-portrait') != null && window.innerWidth < window.innerHeight;
  18. };
  19. iPhoneXPatch.isIPhoneXLandscapePatchActive = function () {
  20. // If width === height, treat it as landscape
  21. return document.documentElement.getAttribute('onsflag-iphonex-landscape') != null && window.innerWidth >= window.innerHeight;
  22. };
  23. /**
  24. * Returns the safe area lengths based on the current state of the safe areas.
  25. */
  26. iPhoneXPatch.getSafeAreaLengths = function () {
  27. var safeAreaLengths = void 0;
  28. if (iPhoneXPatch.isIPhoneXPortraitPatchActive()) {
  29. safeAreaLengths = {
  30. top: 44,
  31. right: 0,
  32. bottom: 34,
  33. left: 0
  34. };
  35. } else if (iPhoneXPatch.isIPhoneXLandscapePatchActive()) {
  36. safeAreaLengths = {
  37. top: 0,
  38. right: 44,
  39. bottom: 21,
  40. left: 44
  41. };
  42. } else {
  43. safeAreaLengths = {
  44. top: 0,
  45. right: 0,
  46. bottom: 0,
  47. left: 0
  48. };
  49. }
  50. return safeAreaLengths;
  51. };
  52. /**
  53. * Returns the safe area rect based on the current state of the safe areas.
  54. */
  55. iPhoneXPatch.getSafeAreaDOMRect = function () {
  56. var safeAreaRect = void 0;
  57. if (iPhoneXPatch.isIPhoneXPortraitPatchActive()) {
  58. safeAreaRect = {
  59. x: 0,
  60. y: 44, /* 0 + 44 (top safe area) */
  61. width: window.innerWidth,
  62. height: window.innerHeight - 78 /* height - 44 (top safe area) - 34 (bottom safe area) */
  63. };
  64. } else if (iPhoneXPatch.isIPhoneXLandscapePatchActive()) {
  65. safeAreaRect = {
  66. x: 44, /* 0 + 44 (left safe area) */
  67. y: 0,
  68. width: window.innerWidth - 88, /* width - 44 (left safe area) - 34 (right safe area) */
  69. height: window.innerHeight - 21 /* height - 21 (bottom safe area) */
  70. };
  71. } else {
  72. safeAreaRect = {
  73. x: 0,
  74. y: 0,
  75. width: window.innerWidth,
  76. height: window.innerHeight
  77. };
  78. }
  79. return _extends({}, safeAreaRect, {
  80. left: safeAreaRect.x,
  81. top: safeAreaRect.y,
  82. right: safeAreaRect.x + safeAreaRect.width,
  83. bottom: safeAreaRect.y + safeAreaRect.height
  84. });
  85. };
  86. export default iPhoneXPatch;