mazey 5.6.10 → 5.7.0

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.
package/README.md CHANGED
@@ -121,6 +121,7 @@ There are some examples maintained by hand below. For more information, please c
121
121
  - [Storage Helpers](#storage-helpers)
122
122
  - [DOM](#dom)
123
123
  - [Class Helpers](#class-helpers)
124
+ - [hide and show](#hide-and-show)
124
125
  - [isValidCssSelector](#isvalidcssselector)
125
126
  - [resolveElementTarget](#resolveelementtarget)
126
127
  - [extractElementText](#extractelementtext)
@@ -139,6 +140,9 @@ There are some examples maintained by hand below. For more information, please c
139
140
  - [resolveLanguagePreference](#resolvelanguagepreference)
140
141
  - [setLanguagePreference](#setlanguagepreference)
141
142
  - [detectVisitorType](#detectvisitortype)
143
+ - [isPhone](#isphone)
144
+ - [isDesktop](#isdesktop)
145
+ - [isTablet](#istablet)
142
146
  - [isIOS](#isios)
143
147
  - [isAndroid](#isandroid)
144
148
  - [isMacOS](#ismacos)
@@ -1125,6 +1129,29 @@ addClass(dom, "test");
1125
1129
  removeClass(dom, "test");
1126
1130
  ```
1127
1131
 
1132
+ #### hide and show
1133
+
1134
+ Hide or show a CSS selector, one element, or an iterable or array-like element
1135
+ collection. Both helpers return the original target, so a caller can retain its
1136
+ own chaining convention. Duplicate elements are changed only once, and invalid
1137
+ selectors or unsupported values are ignored.
1138
+
1139
+ `hide()` preserves a visible element's inline `display` value. `show()` restores
1140
+ that value, or recovers the element's normal display when a stylesheet would
1141
+ otherwise keep it hidden.
1142
+
1143
+ ```javascript
1144
+ import { hide, show } from "mazey";
1145
+
1146
+ const notices = document.querySelectorAll(".notice");
1147
+
1148
+ hide(notices);
1149
+ show(notices);
1150
+
1151
+ hide("#temporary-message");
1152
+ show(document.querySelector("#temporary-message"));
1153
+ ```
1154
+
1128
1155
  #### isValidCssSelector
1129
1156
 
1130
1157
  Check whether a value is a CSS selector supported by the supplied query root.
@@ -1636,6 +1663,84 @@ or changed, so false positives and false negatives are possible.
1636
1663
  > generally requires server-side request information and provider-specific
1637
1664
  > validation.
1638
1665
 
1666
+ #### isPhone
1667
+
1668
+ Check whether the current browser represents a phone or handset-class device.
1669
+ The result excludes tablets.
1670
+
1671
+ ```javascript
1672
+ const result = isPhone();
1673
+
1674
+ console.log(result);
1675
+ ```
1676
+
1677
+ #### isDesktop
1678
+
1679
+ Check whether the current browser represents a desktop or laptop-class device.
1680
+ Recognized touchscreen Windows laptops remain desktop devices.
1681
+
1682
+ ```javascript
1683
+ const result = isDesktop();
1684
+
1685
+ console.log(result);
1686
+ ```
1687
+
1688
+ #### isTablet
1689
+
1690
+ Check whether the current browser represents a tablet. The helper recognizes
1691
+ conventional iPads, modern iPadOS desktop mode, Android user agents without a
1692
+ `Mobile` token, and bounded `Tablet` tokens.
1693
+
1694
+ ```javascript
1695
+ const result = isTablet();
1696
+
1697
+ console.log(result);
1698
+ ```
1699
+
1700
+ You can pass a user-agent string for deterministic or server-side
1701
+ classification:
1702
+
1703
+ ```javascript
1704
+ const result = isTablet(
1705
+ "Mozilla/5.0 (Linux; Android 14; SM-X710) AppleWebKit/537.36"
1706
+ );
1707
+
1708
+ console.log(result);
1709
+ ```
1710
+
1711
+ Output:
1712
+
1713
+ ```text
1714
+ true
1715
+ ```
1716
+
1717
+ The three helpers use mutually exclusive form-factor classifications for
1718
+ recognized devices:
1719
+
1720
+ | Device | `isPhone` | `isDesktop` | `isTablet` |
1721
+ |:---------------|:-----------|:------------|:-----------|
1722
+ | iPhone | `true` | `false` | `false` |
1723
+ | Android phone | `true` | `false` | `false` |
1724
+ | iPad | `false` | `false` | `true` |
1725
+ | Android tablet | `false` | `false` | `true` |
1726
+ | Windows laptop | `false` | `true` | `false` |
1727
+ | MacBook | `false` | `true` | `false` |
1728
+ | Unknown | `false` | `false` | `false` |
1729
+
1730
+ Each helper accepts an optional explicit user-agent string. Explicit input does
1731
+ not borrow the current browser's platform or touch signals. Without explicit
1732
+ input, all three return `false` during SSR when browser signals are unavailable.
1733
+
1734
+ Device classification is heuristic and spoofable. It does not use viewport
1735
+ width and is not a security API or a replacement for responsive CSS and feature
1736
+ detection. `getBrowserInfo().platform` remains a legacy broad grouping that
1737
+ reports iOS and Android as `"mobile"`; the new helpers provide a more specific
1738
+ phone, tablet, or desktop classification.
1739
+
1740
+ `isPhone` checks device form factor. The separate `isMobile` API is a direct
1741
+ alias of `isValidPhoneNumber`; it validates an 11-digit Chinese mobile-shaped
1742
+ number and does not inspect the browser or device.
1743
+
1639
1744
  #### isIOS
1640
1745
 
1641
1746
  Check whether the current browser represents iOS or iPadOS. The current-browser
package/README.zh-CN.md CHANGED
@@ -111,6 +111,9 @@ isNumber(z, { isInfinityAsNumber: true }); // 输出: true
111
111
  - [longestComSubsequence](#longestcomsubsequence)
112
112
  - [浏览器信息](#浏览器信息)
113
113
  - [detectVisitorType](#detectvisitortype)
114
+ - [isPhone](#isphone)
115
+ - [isDesktop](#isdesktop)
116
+ - [isTablet](#istablet)
114
117
  - [getBrowserInfo](#getbrowserinfo)
115
118
  - [isSafePWAEnv](#issafepwaenv)
116
119
  - [isStandalonePWA](#isstandalonepwa)
@@ -1145,6 +1148,70 @@ crawler
1145
1148
 
1146
1149
  > `unknown` 不表示访问者已经通过真人验证。此函数只使用浏览器端启发式规则,不能作为安全边界。请勿单独使用此结果进行身份验证、授权、支付决策、速率限制、欺诈防范或访问控制。验证真实爬虫通常需要服务端请求信息,以及服务提供商规定的验证流程。
1147
1150
 
1151
+ #### isPhone
1152
+
1153
+ 检查当前浏览器是否代表手机或手持设备。此结果不包含平板电脑。
1154
+
1155
+ ```javascript
1156
+ const result = isPhone();
1157
+
1158
+ console.log(result);
1159
+ ```
1160
+
1161
+ #### isDesktop
1162
+
1163
+ 检查当前浏览器是否代表桌面或笔记本电脑。触摸屏 Windows 笔记本电脑仍归类为桌面设备。
1164
+
1165
+ ```javascript
1166
+ const result = isDesktop();
1167
+
1168
+ console.log(result);
1169
+ ```
1170
+
1171
+ #### isTablet
1172
+
1173
+ 检查当前浏览器是否代表平板电脑。此函数支持常规 iPad 和 iPadOS 桌面模式。他还支持不含 `Mobile` 令牌的 Android User-Agent,以及独立的 `Tablet` 令牌。
1174
+
1175
+ ```javascript
1176
+ const result = isTablet();
1177
+
1178
+ console.log(result);
1179
+ ```
1180
+
1181
+ 可以传入 User-Agent 字符串。此方式适合确定性测试或服务端分类。
1182
+
1183
+ ```javascript
1184
+ const result = isTablet(
1185
+ "Mozilla/5.0 (Linux; Android 14; SM-X710) AppleWebKit/537.36"
1186
+ );
1187
+
1188
+ console.log(result);
1189
+ ```
1190
+
1191
+ 输出:
1192
+
1193
+ ```text
1194
+ true
1195
+ ```
1196
+
1197
+ 对于已识别的设备,这 3 个函数使用互斥的设备形态分类:
1198
+
1199
+ | 设备 | `isPhone` | `isDesktop` | `isTablet` |
1200
+ |:-----------------|:-----------|:------------|:-----------|
1201
+ | iPhone | `true` | `false` | `false` |
1202
+ | Android 手机 | `true` | `false` | `false` |
1203
+ | iPad | `false` | `false` | `true` |
1204
+ | Android 平板电脑 | `false` | `false` | `true` |
1205
+ | Windows 笔记本 | `false` | `true` | `false` |
1206
+ | MacBook | `false` | `true` | `false` |
1207
+ | 未知设备 | `false` | `false` | `false` |
1208
+
1209
+ 每个函数都接受可选的 User-Agent 字符串。显式输入不会读取当前浏览器的平台或触摸信号。SSR 环境无法读取浏览器信号且没有显式输入时,这 3 个函数均返回 `false`。
1210
+
1211
+ 设备分类使用可伪造的启发式规则,不读取视口宽度。这些函数不能作为安全 API,也不能替代响应式 CSS 和功能检测。`getBrowserInfo().platform` 保留原有的宽泛分类,并将 iOS 和 Android 报告为 `"mobile"`。新函数提供更具体的手机、平板电脑或桌面设备分类。
1212
+
1213
+ `isPhone` 用于检查设备形态。独立的 `isMobile` API 是 `isValidPhoneNumber` 的直接别名,用于验证 11 位中国手机号码形式的字符串,不会检查浏览器或设备。
1214
+
1148
1215
  #### getBrowserInfo
1149
1216
 
1150
1217
  获取浏览器信息。