Keldos commited on
Commit
b6dd0c8
·
1 Parent(s): ec40641

PWA 适配全面屏

Browse files
web_assets/javascript/ChuanhuChat.js CHANGED
@@ -356,6 +356,7 @@ var gradioObserver = new MutationObserver(function (mutations) {
356
  window.addEventListener("DOMContentLoaded", function () {
357
  // const ga = document.getElementsByTagName("gradio-app");
358
  updateVH();
 
359
  gradioApp().addEventListener("render", initialize);
360
  isInIframe = (window.self !== window.top);
361
  historyLoaded = false;
@@ -363,9 +364,15 @@ window.addEventListener("DOMContentLoaded", function () {
363
  window.addEventListener('resize', ()=>{
364
  // setChatbotHeight();
365
  updateVH();
 
366
  setPopupBoxPosition();
367
- adjustSide();
 
 
 
368
  windowWidth = window.innerWidth;
 
 
369
  });
370
  window.addEventListener('scroll', ()=>{setPopupBoxPosition();});
371
  window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", adjustDarkMode);
 
356
  window.addEventListener("DOMContentLoaded", function () {
357
  // const ga = document.getElementsByTagName("gradio-app");
358
  updateVH();
359
+ windowWidth = window.innerWidth;
360
  gradioApp().addEventListener("render", initialize);
361
  isInIframe = (window.self !== window.top);
362
  historyLoaded = false;
 
364
  window.addEventListener('resize', ()=>{
365
  // setChatbotHeight();
366
  updateVH();
367
+ windowWidth = window.innerWidth;
368
  setPopupBoxPosition();
369
+ adjustSide();
370
+ });
371
+ window.addEventListener('orientationchange', (event) => {
372
+ updateVH();
373
  windowWidth = window.innerWidth;
374
+ setPopupBoxPosition();
375
+ adjustSide();
376
  });
377
  window.addEventListener('scroll', ()=>{setPopupBoxPosition();});
378
  window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", adjustDarkMode);
web_assets/javascript/webui.js CHANGED
@@ -87,8 +87,10 @@ function closeSide(sideArea) {
87
  sideArea.classList.remove('showSide');
88
  if (sideArea == toolbox) {
89
  chuanhuHeader.classList.remove('under-box');
 
90
  toolboxOpening = false;
91
  } else if (sideArea == menu) {
 
92
  menuOpening = false;
93
  }
94
  adjustMask();
@@ -98,8 +100,10 @@ function openSide(sideArea) {
98
  sideArea.classList.add('showSide');
99
  if (sideArea == toolbox) {
100
  chuanhuHeader.classList.add('under-box');
 
101
  toolboxOpening = true;
102
  } else if (sideArea == menu) {
 
103
  menuOpening = true;
104
  }
105
  // document.body.classList.add('popup-open');
@@ -225,6 +229,21 @@ function checkChatbotWidth() {
225
  } else {
226
  chatbotArea.classList.remove('chatbot-full-width');
227
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
228
  checkChatMoreMask();
229
  }
230
 
 
87
  sideArea.classList.remove('showSide');
88
  if (sideArea == toolbox) {
89
  chuanhuHeader.classList.remove('under-box');
90
+ chatbotArea.classList.remove('toolbox-open')
91
  toolboxOpening = false;
92
  } else if (sideArea == menu) {
93
+ chatbotArea.classList.remove('menu-open')
94
  menuOpening = false;
95
  }
96
  adjustMask();
 
100
  sideArea.classList.add('showSide');
101
  if (sideArea == toolbox) {
102
  chuanhuHeader.classList.add('under-box');
103
+ chatbotArea.classList.add('toolbox-open')
104
  toolboxOpening = true;
105
  } else if (sideArea == menu) {
106
+ chatbotArea.classList.add('menu-open')
107
  menuOpening = true;
108
  }
109
  // document.body.classList.add('popup-open');
 
229
  } else {
230
  chatbotArea.classList.remove('chatbot-full-width');
231
  }
232
+
233
+ if (windowWidth > 768) {
234
+ chatbotArea.classList.remove('no-toolbox');
235
+ chatbotArea.classList.remove('no-menu');
236
+
237
+ if (!chatbotArea.classList.contains('toolbox-open') && chatbotArea.classList.contains('menu-open')) {
238
+ chatbotArea.classList.add('no-toolbox');
239
+ } else if (!chatbotArea.classList.contains('menu-open') && chatbotArea.classList.contains('toolbox-open')) {
240
+ chatbotArea.classList.add('no-menu');
241
+ } else if (!chatbotArea.classList.contains('menu-open') && !chatbotArea.classList.contains('toolbox-open')) {
242
+ chatbotArea.classList.add('no-toolbox');
243
+ chatbotArea.classList.add('no-menu');
244
+ }
245
+ }
246
+
247
  checkChatMoreMask();
248
  }
249
 
web_assets/stylesheet/ChuanhuChat.css CHANGED
@@ -238,9 +238,13 @@ body.popup-open {
238
 
239
  @media screen and (max-width: 639px) {
240
  padding: 6px 16px;
 
 
241
  }
242
  @media screen and (min-width: 640px) {
243
  padding: 6px 24px;
 
 
244
  }
245
  /* @media screen and (min-width: 1024px) {
246
  padding: 6px 96px;
@@ -278,10 +282,6 @@ body.popup-open {
278
  .dark #chuanhu-area {
279
  background: var(--chatbot-background-color-dark);
280
  }
281
- /* #chatbot-area {
282
- justify-content: center;
283
- display: flex;
284
- } */
285
  #chatbot-header {
286
  justify-content: space-between;
287
  border-bottom: 0.5px solid var(--border-color-primary);
@@ -388,6 +388,7 @@ body.popup-open {
388
  /* margin: 0 auto; */
389
  gap: 20px;
390
  padding: 16px 16px 24px;
 
391
  display: flex;
392
  background: none;
393
  align-self: end;
@@ -537,6 +538,9 @@ button.chatbot-input-more-btn:active .sm-round-bg {
537
  #menu-area > div {
538
  width: var(--menu-width);
539
  }
 
 
 
540
  #menu-area.showSide {
541
  width: var(--menu-width);
542
  max-width: var(--menu-width);
@@ -566,6 +570,9 @@ button.chatbot-input-more-btn:active .sm-round-bg {
566
  z-index: 9999;
567
  overflow: unset;
568
  }
 
 
 
569
  #menu-area.showSide {
570
  left: 0;
571
  }
@@ -799,6 +806,7 @@ button.chatbot-input-more-btn:active .sm-round-bg {
799
  border-style: none;
800
  padding: 0;
801
  /* 理论上不该是0,但这里考虑内部gradio有好多container有padding了 */
 
802
  }
803
  #toolbox-area > .gradio-box > .gradio-tabs > div.tab-nav {
804
  display: flex;
@@ -867,6 +875,7 @@ button.chatbot-input-more-btn:active .sm-round-bg {
867
 
868
  #chuanhu-history {
869
  height: calc(100*var(--vh) - 65px - 61px);
 
870
  overflow-y: auto;
871
  }
872
  #chuanhu-history > div {
@@ -877,10 +886,12 @@ button.chatbot-input-more-btn:active .sm-round-bg {
877
  #chuanhu-menu-footer {
878
  position: absolute;
879
  bottom: 0;
880
- /* background: black; */
881
  height: auto;
882
  overflow: hidden;
883
  padding: 12px 18px;
 
 
884
  border-top: 0.8px solid var(--border-color-primary);
885
  }
886
  #menu-footer-btn-bar {
@@ -939,6 +950,26 @@ button.chatbot-input-more-btn:active .sm-round-bg {
939
  display: block;
940
  }
941
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
942
  #history-select-wrap {
943
  height: 600px;
944
  overflow: auto;
 
238
 
239
  @media screen and (max-width: 639px) {
240
  padding: 6px 16px;
241
+ padding-left: max(16px, env(safe-area-inset-left));
242
+ padding-right: max(16px, env(safe-area-inset-right));
243
  }
244
  @media screen and (min-width: 640px) {
245
  padding: 6px 24px;
246
+ padding-left: max(24px, env(safe-area-inset-left));
247
+ padding-right: max(24px, env(safe-area-inset-right));
248
  }
249
  /* @media screen and (min-width: 1024px) {
250
  padding: 6px 96px;
 
282
  .dark #chuanhu-area {
283
  background: var(--chatbot-background-color-dark);
284
  }
 
 
 
 
285
  #chatbot-header {
286
  justify-content: space-between;
287
  border-bottom: 0.5px solid var(--border-color-primary);
 
388
  /* margin: 0 auto; */
389
  gap: 20px;
390
  padding: 16px 16px 24px;
391
+ padding-bottom: max(24px, calc( env(safe-area-inset-bottom) + 6px));
392
  display: flex;
393
  background: none;
394
  align-self: end;
 
538
  #menu-area > div {
539
  width: var(--menu-width);
540
  }
541
+ #chuanhu-history {
542
+ padding-left: env(safe-area-inset-left);
543
+ }
544
  #menu-area.showSide {
545
  width: var(--menu-width);
546
  max-width: var(--menu-width);
 
570
  z-index: 9999;
571
  overflow: unset;
572
  }
573
+ #chuanhu-history {
574
+ padding-left: 0;
575
+ }
576
  #menu-area.showSide {
577
  left: 0;
578
  }
 
806
  border-style: none;
807
  padding: 0;
808
  /* 理论上不该是0,但这里考虑内部gradio有好多container有padding了 */
809
+ padding-right: env(safe-area-inset-right);
810
  }
811
  #toolbox-area > .gradio-box > .gradio-tabs > div.tab-nav {
812
  display: flex;
 
875
 
876
  #chuanhu-history {
877
  height: calc(100*var(--vh) - 65px - 61px);
878
+ height: calc(100*var(--vh) - 65px - calc(36px + 12px + max(12px, env(safe-area-inset-bottom)) + 1px ));
879
  overflow-y: auto;
880
  }
881
  #chuanhu-history > div {
 
886
  #chuanhu-menu-footer {
887
  position: absolute;
888
  bottom: 0;
889
+ background: var(--background-fill-primary);
890
  height: auto;
891
  overflow: hidden;
892
  padding: 12px 18px;
893
+ padding-bottom: max(12px, env(safe-area-inset-bottom));
894
+ padding-left: max(18px, env(safe-area-inset-left));
895
  border-top: 0.8px solid var(--border-color-primary);
896
  }
897
  #menu-footer-btn-bar {
 
950
  display: block;
951
  }
952
 
953
+ #chatbot-area.no-menu #chatbot-header {
954
+ padding-left: max(20px, env(safe-area-inset-left));
955
+ }
956
+ #chatbot-area.no-menu #chatbot-area {
957
+ padding-left: env(safe-area-inset-left);
958
+ }
959
+ #chatbot-area.no-menu #chatbot-input-box {
960
+ padding-left: max(16px, env(safe-area-inset-left));
961
+ }
962
+ #chatbot-area.no-toolbox #chatbot-header {
963
+ padding-right: max(16px, env(safe-area-inset-right));
964
+ }
965
+
966
+ #chatbot-area.no-toolbox #chatbot-area {
967
+ padding-right: env(safe-area-inset-right);
968
+ }
969
+
970
+ #chatbot-area.no-toolbox #chatbot-input-box {
971
+ padding-right: max(16px, env(safe-area-inset-right));
972
+ }
973
  #history-select-wrap {
974
  height: 600px;
975
  overflow: auto;