plusui-native-core 0.1.39 → 0.1.41

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.
@@ -25,6 +25,29 @@ using namespace Microsoft::WRL;
25
25
 
26
26
  namespace plusui {
27
27
 
28
+ namespace {
29
+ constexpr char kHideScrollbarsScript[] = R"(
30
+ (function() {
31
+ var css = "::-webkit-scrollbar{display:none!important;width:0!important;height:0!important;}::-webkit-scrollbar-track{background:transparent!important;}::-webkit-scrollbar-thumb{background:transparent!important;}*{-ms-overflow-style:none!important;scrollbar-width:none!important;scrollbar-color:transparent transparent!important;}";
32
+ var styleId = "__plusui_hide_scrollbars";
33
+ var ensureStyle = function() {
34
+ if (document.getElementById(styleId)) return;
35
+ var style = document.createElement("style");
36
+ style.id = styleId;
37
+ style.type = "text/css";
38
+ style.appendChild(document.createTextNode(css));
39
+ var container = document.head || document.documentElement || document.body;
40
+ if (container) {
41
+ container.appendChild(style);
42
+ }
43
+ };
44
+ ensureStyle();
45
+ document.addEventListener("DOMContentLoaded", ensureStyle);
46
+ window.addEventListener("load", ensureStyle);
47
+ })();
48
+ )";
49
+ } // namespace
50
+
28
51
  // Note: Window::Impl is defined in window.cpp
29
52
  // This file only provides implementations for webview-specific methods
30
53
 
@@ -90,58 +113,9 @@ Window Window::create(void *windowHandle, const WindowConfig &config) {
90
113
  .c_str(),
91
114
  nullptr);
92
115
 
93
- // Hide scrollbars if disabled via CSS injection
116
+ // Disable scrollbars if configured
94
117
  if (!pImpl->config.scrollbars) {
95
- std::string scrollbarScript = R"(
96
- (function() {
97
- // Apply inline styles directly - immediate effect
98
- try {
99
- if (document.documentElement) {
100
- document.documentElement.style.overflow = 'hidden';
101
- document.documentElement.style.margin = '0';
102
- document.documentElement.style.padding = '0';
103
- }
104
- } catch (e) {}
105
-
106
- // Inject CSS stylesheet
107
- try {
108
- var style = document.createElement('style');
109
- style.textContent = 'html{overflow:hidden!important;margin:0!important;padding:0!important;height:100%!important;}body{overflow:hidden!important;margin:0!important;padding:0!important;height:100%!important;}::-webkit-scrollbar{display:none!important;width:0!important;height:0!important;}';
110
-
111
- if (document.head) {
112
- document.head.appendChild(style);
113
- } else if (document.documentElement) {
114
- document.documentElement.appendChild(style);
115
- } else {
116
- setTimeout(function() {
117
- if (document.head) {
118
- document.head.appendChild(style);
119
- } else if (document.documentElement) {
120
- document.documentElement.appendChild(style);
121
- }
122
- }, 10);
123
- }
124
- } catch (e) {}
125
-
126
- // Reapply on DOMContentLoaded
127
- try {
128
- var reapply = function() {
129
- if (document.documentElement) {
130
- document.documentElement.style.overflow = 'hidden';
131
- }
132
- if (document.body) {
133
- document.body.style.overflow = 'hidden';
134
- }
135
- };
136
-
137
- if (document.readyState === 'loading') {
138
- document.addEventListener('DOMContentLoaded', reapply);
139
- } else {
140
- reapply();
141
- }
142
- } catch (e) {}
143
- })();
144
- )";
118
+ std::string scrollbarScript = kHideScrollbarsScript;
145
119
  pImpl->webview->AddScriptToExecuteOnDocumentCreated(
146
120
  std::wstring(scrollbarScript.begin(),
147
121
  scrollbarScript.end())
@@ -713,17 +687,11 @@ Window Window::create(void *windowHandle, const WindowConfig &config) {
713
687
 
714
688
  // Hide scrollbars if disabled
715
689
  if (!win.pImpl->config.scrollbars) {
716
- NSString *scrollbarScript = @"(function() {"
717
- "var css = 'html, body { overflow: hidden !important; margin: 0 !important; padding: 0 !important; } ::-webkit-scrollbar { display: none !important; width: 0 !important; height: 0 !important; }';"
718
- "var style = document.createElement('style');"
719
- "style.type = 'text/css';"
720
- "style.appendChild(document.createTextNode(css));"
721
- "(document.head || document.documentElement).appendChild(style);"
722
- "})();";
723
-
724
- WKUserScript *scrollScript = [[WKUserScript alloc]
725
- initWithSource:scrollbarScript
726
- injectionTime:WKUserScriptInjectionTimeAtDocumentEnd
690
+ NSString *scrollbarScript = [NSString stringWithUTF8String:kHideScrollbarsScript];
691
+
692
+ WKUserScript *scrollScript = [[WKUserScript alloc]
693
+ initWithSource:scrollbarScript
694
+ injectionTime:WKUserScriptInjectionTimeAtDocumentEnd
727
695
  forMainFrameOnly:NO];
728
696
  [config.userContentController addUserScript:scrollScript];
729
697
  }
@@ -30,6 +30,29 @@ using namespace Microsoft::WRL;
30
30
 
31
31
  namespace plusui {
32
32
 
33
+ namespace {
34
+ constexpr char kHideScrollbarsScript[] = R"(
35
+ (function() {
36
+ var css = "::-webkit-scrollbar{display:none!important;width:0!important;height:0!important;}::-webkit-scrollbar-track{background:transparent!important;}::-webkit-scrollbar-thumb{background:transparent!important;}*{-ms-overflow-style:none!important;scrollbar-width:none!important;scrollbar-color:transparent transparent!important;}";
37
+ var styleId = "__plusui_hide_scrollbars";
38
+ var ensureStyle = function() {
39
+ if (document.getElementById(styleId)) return;
40
+ var style = document.createElement("style");
41
+ style.id = styleId;
42
+ style.type = "text/css";
43
+ style.appendChild(document.createTextNode(css));
44
+ var container = document.head || document.documentElement || document.body;
45
+ if (container) {
46
+ container.appendChild(style);
47
+ }
48
+ };
49
+ ensureStyle();
50
+ document.addEventListener("DOMContentLoaded", ensureStyle);
51
+ window.addEventListener("load", ensureStyle);
52
+ })();
53
+ )";
54
+ } // namespace
55
+
33
56
  struct Window::Impl {
34
57
  void *nativeWindow = nullptr;
35
58
  void *nativeWebView = nullptr;
@@ -793,15 +816,7 @@ Window Window::create(void *windowHandle, const WindowConfig &config) {
793
816
 
794
817
  // Inject scrollbar hiding CSS if disabled
795
818
  if (!pImpl->config.scrollbars) {
796
- std::string scrollbarScript = R"(
797
- (function() {
798
- var css = 'html, body { overflow: hidden !important; margin: 0 !important; padding: 0 !important; } ::-webkit-scrollbar { display: none !important; width: 0 !important; height: 0 !important; }';
799
- var style = document.createElement('style');
800
- style.type = 'text/css';
801
- style.appendChild(document.createTextNode(css));
802
- (document.head || document.documentElement).appendChild(style);
803
- })();
804
- )";
819
+ std::string scrollbarScript = kHideScrollbarsScript;
805
820
  pImpl->webview->AddScriptToExecuteOnDocumentCreated(
806
821
  std::wstring(scrollbarScript.begin(),
807
822
  scrollbarScript.end())
@@ -1183,13 +1198,7 @@ Window Window::create(void *windowHandle, const WindowConfig &config) {
1183
1198
 
1184
1199
  // Hide scrollbars if disabled
1185
1200
  if (!win.pImpl->config.scrollbars) {
1186
- NSString *scrollbarScript = @"(function() {"
1187
- "var css = 'html, body { overflow: hidden !important; margin: 0 !important; padding: 0 !important; } ::-webkit-scrollbar { display: none !important; width: 0 !important; height: 0 !important; }';"
1188
- "var style = document.createElement('style');"
1189
- "style.type = 'text/css';"
1190
- "style.appendChild(document.createTextNode(css));"
1191
- "(document.head || document.documentElement).appendChild(style);"
1192
- "})();";
1201
+ NSString *scrollbarScript = [NSString stringWithUTF8String:kHideScrollbarsScript];
1193
1202
 
1194
1203
  WKUserScript *scrollScript = [[WKUserScript alloc]
1195
1204
  initWithSource:scrollbarScript
@@ -1293,16 +1302,7 @@ void Window::navigate(const std::string &url) {
1293
1302
 
1294
1303
  // Apply scrollbar hiding CSS if configured
1295
1304
  if (!pImpl->config.scrollbars) {
1296
- std::string hideScrollbars = R"(
1297
- (function() {
1298
- document.documentElement.style.overflow = 'hidden';
1299
- document.documentElement.style.margin = '0';
1300
- document.documentElement.style.padding = '0';
1301
- document.body.style.overflow = 'hidden';
1302
- document.body.style.margin = '0';
1303
- document.body.style.padding = '0';
1304
- })();
1305
- )";
1305
+ std::string hideScrollbars = kHideScrollbarsScript;
1306
1306
  // Schedule this to run after a short delay to ensure DOM is ready
1307
1307
  #ifdef _WIN32
1308
1308
  if (pImpl->ready && pImpl->webview) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plusui-native-core",
3
- "version": "0.1.39",
3
+ "version": "0.1.41",
4
4
  "description": "PlusUI Core framework (frontend + backend implementations)",
5
5
  "type": "module",
6
6
  "files": [