@puresnake/snake-ui 0.0.0-stage → 0.0.1

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 (279) hide show
  1. package/LICENSE +21 -0
  2. package/changelog.md +1 -0
  3. package/components/snake-activity-list/snake-activity-list.vue +365 -0
  4. package/components/snake-activity-list/types.ts +29 -0
  5. package/components/snake-auxiliary-segmentation/snake-auxiliary-segmentation.vue +44 -0
  6. package/components/snake-auxiliary-segmentation/types.ts +5 -0
  7. package/components/snake-button/snake-button.vue +357 -0
  8. package/components/snake-button/types.ts +103 -0
  9. package/components/snake-button-sort/snake-button-sort.vue +72 -0
  10. package/components/snake-button-sort/types.ts +22 -0
  11. package/components/snake-calendar/snake-calendar.vue +998 -0
  12. package/components/snake-calendar/types.ts +189 -0
  13. package/components/snake-cell-group/snake-cell-group.vue +55 -0
  14. package/components/snake-cell-group/types.ts +19 -0
  15. package/components/snake-cell-item/snake-cell-item.vue +159 -0
  16. package/components/snake-cell-item/types.ts +66 -0
  17. package/components/snake-checkbox/snake-checkbox.vue +264 -0
  18. package/components/snake-checkbox/types.ts +70 -0
  19. package/components/snake-checkbox-group/snake-checkbox-group.vue +154 -0
  20. package/components/snake-checkbox-group/types.ts +52 -0
  21. package/components/snake-cms/blocks/v2/cms-v2-carousel.vue +87 -0
  22. package/components/snake-cms/blocks/v2/cms-v2-coupon.vue +25 -0
  23. package/components/snake-cms/blocks/v2/cms-v2-custom.vue +12 -0
  24. package/components/snake-cms/blocks/v2/cms-v2-divider.vue +33 -0
  25. package/components/snake-cms/blocks/v2/cms-v2-floatbutton.vue +28 -0
  26. package/components/snake-cms/blocks/v2/cms-v2-goods-list.vue +150 -0
  27. package/components/snake-cms/blocks/v2/cms-v2-hotzone.vue +41 -0
  28. package/components/snake-cms/blocks/v2/cms-v2-images.vue +41 -0
  29. package/components/snake-cms/blocks/v2/cms-v2-magiccube.vue +93 -0
  30. package/components/snake-cms/blocks/v2/cms-v2-notice.vue +80 -0
  31. package/components/snake-cms/blocks/v2/cms-v2-popup.vue +46 -0
  32. package/components/snake-cms/blocks/v2/cms-v2-richtext.vue +18 -0
  33. package/components/snake-cms/blocks/v2/cms-v2-search.vue +115 -0
  34. package/components/snake-cms/blocks/v2/cms-v2-video.vue +25 -0
  35. package/components/snake-cms/blocks/v2/shared.ts +84 -0
  36. package/components/snake-cms/snake-cms.vue +409 -0
  37. package/components/snake-cms/types.ts +50 -0
  38. package/components/snake-commodity-search/snake-commodity-search.vue +234 -0
  39. package/components/snake-commodity-search/types.ts +11 -0
  40. package/components/snake-config-provider/snake-config-provider.vue +61 -0
  41. package/components/snake-config-provider/types.ts +22 -0
  42. package/components/snake-count-down/snake-count-down.vue +231 -0
  43. package/components/snake-count-down/types.ts +103 -0
  44. package/components/snake-coupon/snake-coupon.vue +209 -0
  45. package/components/snake-coupon/types.ts +21 -0
  46. package/components/snake-custom-module/snake-custom-module.vue +25 -0
  47. package/components/snake-custom-module/types.ts +11 -0
  48. package/components/snake-drop-menu/snake-drop-menu.vue +123 -0
  49. package/components/snake-drop-menu/types.ts +95 -0
  50. package/components/snake-drop-menu-item/snake-drop-menu-item.vue +181 -0
  51. package/components/snake-drop-menu-item/types.ts +48 -0
  52. package/components/snake-empty/snake-empty.vue +100 -0
  53. package/components/snake-empty/types.ts +48 -0
  54. package/components/snake-filter-sorts/filter-page.vue +695 -0
  55. package/components/snake-filter-sorts/snake-filter-sorts.vue +185 -0
  56. package/components/snake-filter-sorts/types.ts +57 -0
  57. package/components/snake-floating-bubble/snake-floating-bubble.vue +157 -0
  58. package/components/snake-floating-bubble/types.ts +43 -0
  59. package/components/snake-follow/snake-follow.vue +18 -0
  60. package/components/snake-follow/types.ts +2 -0
  61. package/components/snake-form/snake-form.vue +124 -0
  62. package/components/snake-form/types.ts +96 -0
  63. package/components/snake-form-item/snake-form-item.vue +331 -0
  64. package/components/snake-form-item/types.ts +70 -0
  65. package/components/snake-goods-list/snake-goods-list.vue +792 -0
  66. package/components/snake-goods-list/types.ts +55 -0
  67. package/components/snake-graphic-navigation/snake-graphic-navigation.vue +198 -0
  68. package/components/snake-graphic-navigation/types.ts +43 -0
  69. package/components/snake-icon/icon-names.ts +222 -0
  70. package/components/snake-icon/snake-icon.vue +220 -0
  71. package/components/snake-icon/types.ts +45 -0
  72. package/components/snake-image/snake-image.vue +230 -0
  73. package/components/snake-image/types.ts +70 -0
  74. package/components/snake-images/snake-images.vue +80 -0
  75. package/components/snake-images/types.ts +5 -0
  76. package/components/snake-index-anchor/snake-index-anchor.vue +83 -0
  77. package/components/snake-index-anchor/types.ts +14 -0
  78. package/components/snake-index-list/anchor-registry.ts +80 -0
  79. package/components/snake-index-list/snake-index-list.vue +259 -0
  80. package/components/snake-index-list/types.ts +115 -0
  81. package/components/snake-index-list-panel/snake-index-list-panel.vue +277 -0
  82. package/components/snake-index-list-panel/types.ts +10 -0
  83. package/components/snake-input/snake-input.vue +225 -0
  84. package/components/snake-input/types.ts +99 -0
  85. package/components/snake-jump-applet/snake-jump-applet.vue +99 -0
  86. package/components/snake-jump-applet/types.ts +17 -0
  87. package/components/snake-line/snake-line.vue +42 -0
  88. package/components/snake-line/types.ts +30 -0
  89. package/components/snake-line-progress/snake-line-progress.vue +105 -0
  90. package/components/snake-line-progress/types.ts +26 -0
  91. package/components/snake-link/snake-link.vue +74 -0
  92. package/components/snake-link/types.ts +30 -0
  93. package/components/snake-list-switching/components/tree-select/index.vue +156 -0
  94. package/components/snake-list-switching/snake-list-switching.vue +1285 -0
  95. package/components/snake-list-switching/types.ts +11 -0
  96. package/components/snake-loading/snake-loading.vue +241 -0
  97. package/components/snake-loading/types.ts +34 -0
  98. package/components/snake-loadmore/snake-loadmore.vue +103 -0
  99. package/components/snake-loadmore/types.ts +56 -0
  100. package/components/snake-magic-cube/snake-magic-cube.vue +622 -0
  101. package/components/snake-magic-cube/types.ts +5 -0
  102. package/components/snake-modal/snake-modal.vue +434 -0
  103. package/components/snake-modal/types.ts +71 -0
  104. package/components/snake-navbar/snake-navbar.vue +194 -0
  105. package/components/snake-navbar/types.ts +54 -0
  106. package/components/snake-no-network/snake-no-network.vue +125 -0
  107. package/components/snake-no-network/types.ts +27 -0
  108. package/components/snake-notice/snake-notice.vue +44 -0
  109. package/components/snake-notice/types.ts +5 -0
  110. package/components/snake-notice-bar/snake-notice-bar.vue +336 -0
  111. package/components/snake-notice-bar/types.ts +82 -0
  112. package/components/snake-overlay/snake-overlay.vue +73 -0
  113. package/components/snake-overlay/types.ts +35 -0
  114. package/components/snake-page-popup/snake-page-popup.vue +146 -0
  115. package/components/snake-page-popup/types.ts +28 -0
  116. package/components/snake-parse/audio/audio.vue +286 -0
  117. package/components/snake-parse/audio/context.js +11 -0
  118. package/components/snake-parse/audio/index.js +34 -0
  119. package/components/snake-parse/node/node.vue +830 -0
  120. package/components/snake-parse/parser.js +1480 -0
  121. package/components/snake-parse/snake-parse.vue +548 -0
  122. package/components/snake-parse/static/app-plus/snake-parse/js/handler.js +109 -0
  123. package/components/snake-parse/static/app-plus/snake-parse/js/uni.webview.js +0 -0
  124. package/components/snake-parse/static/app-plus/snake-parse/js/uni.webview.min.js +1 -0
  125. package/components/snake-parse/static/app-plus/snake-parse/local.html +3 -0
  126. package/components/snake-parse/style/index.js +132 -0
  127. package/components/snake-parse/style/parser.js +175 -0
  128. package/components/snake-parse/types.ts +49 -0
  129. package/components/snake-picture-ads/snake-picture-ads.vue +292 -0
  130. package/components/snake-picture-ads/types.ts +5 -0
  131. package/components/snake-popup/snake-popup.vue +348 -0
  132. package/components/snake-popup/types.ts +88 -0
  133. package/components/snake-qr-code/qrcode.ts +1214 -0
  134. package/components/snake-qr-code/snake-qr-code.vue +408 -0
  135. package/components/snake-qr-code/types.ts +78 -0
  136. package/components/snake-radio/snake-radio.vue +271 -0
  137. package/components/snake-radio/types.ts +64 -0
  138. package/components/snake-radio-group/snake-radio-group.vue +98 -0
  139. package/components/snake-radio-group/types.ts +48 -0
  140. package/components/snake-read-more/snake-read-more.vue +140 -0
  141. package/components/snake-read-more/types.ts +53 -0
  142. package/components/snake-rich-text/snake-rich-text.vue +24 -0
  143. package/components/snake-rich-text/types.ts +5 -0
  144. package/components/snake-root-portal/snake-root-portal.vue +92 -0
  145. package/components/snake-root-portal/types.ts +9 -0
  146. package/components/snake-search/snake-search.vue +202 -0
  147. package/components/snake-search/types.ts +84 -0
  148. package/components/snake-select/snake-select.vue +371 -0
  149. package/components/snake-select/types.ts +75 -0
  150. package/components/snake-skeleton/snake-skeleton.vue +104 -0
  151. package/components/snake-skeleton/types.ts +32 -0
  152. package/components/snake-skeleton-item/snake-skeleton-item.vue +90 -0
  153. package/components/snake-skeleton-item/types.ts +30 -0
  154. package/components/snake-slider/snake-slider.vue +249 -0
  155. package/components/snake-slider/types.ts +59 -0
  156. package/components/snake-sticky/snake-sticky.vue +178 -0
  157. package/components/snake-sticky/types.ts +48 -0
  158. package/components/snake-subsection/snake-subsection.vue +188 -0
  159. package/components/snake-subsection/types.ts +54 -0
  160. package/components/snake-swiper/snake-swiper.vue +229 -0
  161. package/components/snake-swiper/types.ts +79 -0
  162. package/components/snake-switch/snake-switch.vue +100 -0
  163. package/components/snake-switch/types.ts +41 -0
  164. package/components/snake-tabbar/snake-tabbar.vue +306 -0
  165. package/components/snake-tabbar/types.ts +93 -0
  166. package/components/snake-tabs/snake-tabs.vue +305 -0
  167. package/components/snake-tabs/types.ts +79 -0
  168. package/components/snake-text/snake-text.vue +292 -0
  169. package/components/snake-text/types.ts +100 -0
  170. package/components/snake-textarea/snake-textarea.vue +171 -0
  171. package/components/snake-textarea/types.ts +79 -0
  172. package/components/snake-toast/snake-toast.vue +330 -0
  173. package/components/snake-toast/types.ts +55 -0
  174. package/components/snake-tooltip/position.ts +33 -0
  175. package/components/snake-tooltip/snake-tooltip.vue +339 -0
  176. package/components/snake-tooltip/types.ts +80 -0
  177. package/components/snake-transition/snake-transition.vue +315 -0
  178. package/components/snake-transition/types.ts +65 -0
  179. package/components/snake-upload/snake-upload.vue +1801 -0
  180. package/components/snake-upload/types.ts +256 -0
  181. package/components/snake-videos/snake-videos.vue +122 -0
  182. package/components/snake-videos/types.ts +7 -0
  183. package/iconfont.css +881 -0
  184. package/index.d.ts +7 -0
  185. package/index.scss +26 -0
  186. package/index.ts +94 -0
  187. package/libs/cms/blocks.ts +103 -0
  188. package/libs/cms/config.ts +25 -0
  189. package/libs/cms/index.ts +7 -0
  190. package/libs/cms/normalize.ts +135 -0
  191. package/libs/cms/resolve.ts +12 -0
  192. package/libs/cms/types.ts +164 -0
  193. package/libs/cms/use-commerce.ts +385 -0
  194. package/libs/cms/v2.ts +193 -0
  195. package/libs/config/index.ts +4 -0
  196. package/libs/config/modal.ts +93 -0
  197. package/libs/config/state.ts +33 -0
  198. package/libs/config/theme.ts +351 -0
  199. package/libs/config/toast.ts +71 -0
  200. package/libs/config/types.ts +135 -0
  201. package/libs/config/zIndex.ts +44 -0
  202. package/libs/css/color.scss +105 -0
  203. package/libs/css/common.scss +171 -0
  204. package/libs/css/style.h5.scss +7 -0
  205. package/libs/css/style.mp.scss +7 -0
  206. package/libs/css/style.theme.scss +70 -0
  207. package/libs/css/style.vue.scss +140 -0
  208. package/libs/form/async-validator.min.d.ts +75 -0
  209. package/libs/form/async-validator.min.js +3 -0
  210. package/libs/form/index.ts +3 -0
  211. package/libs/form/path.ts +40 -0
  212. package/libs/form/types.ts +51 -0
  213. package/libs/form/validate.ts +149 -0
  214. package/libs/foundation.ts +96 -0
  215. package/libs/function/$parent.ts +33 -0
  216. package/libs/function/clipboard.ts +13 -0
  217. package/libs/function/color.ts +55 -0
  218. package/libs/function/debounce.ts +34 -0
  219. package/libs/function/deepClone.ts +30 -0
  220. package/libs/function/deepMerge.ts +25 -0
  221. package/libs/function/emitter.ts +30 -0
  222. package/libs/function/format.ts +27 -0
  223. package/libs/function/getParent.ts +53 -0
  224. package/libs/function/getRect.ts +29 -0
  225. package/libs/function/guid.ts +11 -0
  226. package/libs/function/index.ts +31 -0
  227. package/libs/function/queryParams.ts +73 -0
  228. package/libs/function/random.ts +6 -0
  229. package/libs/function/randomArray.ts +14 -0
  230. package/libs/function/route.ts +155 -0
  231. package/libs/function/sleep.ts +7 -0
  232. package/libs/function/style.ts +58 -0
  233. package/libs/function/styleUtils.ts +83 -0
  234. package/libs/function/system.ts +14 -0
  235. package/libs/function/test.ts +202 -0
  236. package/libs/function/throttle.ts +36 -0
  237. package/libs/function/timeFormat.ts +27 -0
  238. package/libs/function/timeFrom.ts +27 -0
  239. package/libs/function/toast.ts +10 -0
  240. package/libs/function/trim.ts +11 -0
  241. package/libs/function/type2icon.ts +11 -0
  242. package/libs/function/unit.ts +45 -0
  243. package/libs/hooks/index.ts +11 -0
  244. package/libs/hooks/useChildren.ts +125 -0
  245. package/libs/hooks/useColor.ts +5 -0
  246. package/libs/hooks/useDebounce.ts +5 -0
  247. package/libs/hooks/useLocale.ts +13 -0
  248. package/libs/hooks/useModal.ts +131 -0
  249. package/libs/hooks/useParent.ts +62 -0
  250. package/libs/hooks/useRect.ts +44 -0
  251. package/libs/hooks/useRouter.ts +5 -0
  252. package/libs/hooks/useTheme.ts +31 -0
  253. package/libs/hooks/useThrottle.ts +5 -0
  254. package/libs/hooks/useToast.ts +116 -0
  255. package/libs/index.ts +18 -0
  256. package/libs/request/auto-http.ts +1 -0
  257. package/libs/request/index.ts +343 -0
  258. package/libs/runtime/accessors.ts +55 -0
  259. package/libs/runtime/context.ts +40 -0
  260. package/libs/runtime/index.ts +18 -0
  261. package/libs/runtime/types.ts +49 -0
  262. package/libs/util/calendar.ts +6 -0
  263. package/locale/index.ts +130 -0
  264. package/locale/lang/en-US.ts +67 -0
  265. package/locale/lang/zh-CN.ts +67 -0
  266. package/package.json +130 -5
  267. package/plugins/index.ts +1 -0
  268. package/plugins/root/README.md +86 -0
  269. package/plugins/root/index.ts +123 -0
  270. package/plugins/root/page.ts +77 -0
  271. package/plugins/root/root.ts +53 -0
  272. package/plugins/root/utils.ts +137 -0
  273. package/readme.md +79 -0
  274. package/theme.scss +118 -0
  275. package/types/components.d.ts +236 -0
  276. package/types/global.d.ts +21 -0
  277. package/types/index.d.ts +6 -0
  278. package/types/uni-app.d.ts +16 -0
  279. package/README.md +0 -3
@@ -0,0 +1,132 @@
1
+ /**
2
+ * @fileoverview style 插件
3
+ */
4
+ // #ifndef APP-PLUS-NVUE
5
+ import Parser from './parser';
6
+ // #endif
7
+
8
+ function Style() {
9
+ this.styles = [];
10
+ }
11
+
12
+ // #ifndef APP-PLUS-NVUE
13
+ Style.prototype.onParse = function (node, vm) {
14
+ // 获取样式
15
+ if (node.name === 'style' && node.children.length && node.children[0].type === 'text') {
16
+ this.styles = this.styles.concat(new Parser().parse(node.children[0].text));
17
+ } else if (node.name) {
18
+ // 匹配样式(对非文本标签)
19
+ // 存储不同优先级的样式 name < class < id < 后代
20
+ let matched = ['', '', '', ''];
21
+ for (let i = 0, len = this.styles.length; i < len; i++) {
22
+ const item = this.styles[i];
23
+ let res = match(node, item.key || item.list[item.list.length - 1]);
24
+ let j;
25
+ if (res) {
26
+ // 后代选择器
27
+ if (!item.key) {
28
+ j = item.list.length - 2;
29
+ for (let k = vm.stack.length; j >= 0 && k--;) {
30
+ // 子选择器
31
+ if (item.list[j] === '>') {
32
+ // 错误情况
33
+ if (j < 1 || j > item.list.length - 2) break;
34
+ if (match(vm.stack[k], item.list[j - 1])) {
35
+ j -= 2;
36
+ } else {
37
+ j++;
38
+ }
39
+ } else if (match(vm.stack[k], item.list[j])) {
40
+ j--;
41
+ }
42
+ }
43
+ res = 4;
44
+ }
45
+ if (item.key || j < 0) {
46
+ // 添加伪类
47
+ if (item.pseudo && node.children) {
48
+ let text;
49
+ item.style = item.style.replace(/content:([^;]+)/, (_, $1) => {
50
+ text = $1
51
+ .replace(/['"]/g, '')
52
+ // 处理 attr 函数
53
+ .replace(/attr\((.+?)\)/, (_, $1) => node.attrs[$1.trim()] || '')
54
+ // 编码 \xxx
55
+ .replace(/\\(\w{4})/, (_, $1) => String.fromCharCode(parseInt($1, 16)));
56
+ return '';
57
+ });
58
+ const pseudo = {
59
+ name: 'span',
60
+ attrs: {
61
+ style: item.style
62
+ },
63
+ children: [
64
+ {
65
+ type: 'text',
66
+ text
67
+ }
68
+ ]
69
+ };
70
+ if (item.pseudo === 'before') {
71
+ node.children.unshift(pseudo);
72
+ } else {
73
+ node.children.push(pseudo);
74
+ }
75
+ } else {
76
+ matched[res - 1] += item.style + (item.style[item.style.length - 1] === ';' ? '' : ';');
77
+ }
78
+ }
79
+ }
80
+ }
81
+ matched = matched.join('');
82
+ if (matched.length > 2) {
83
+ node.attrs.style = matched + (node.attrs.style || '');
84
+ }
85
+ }
86
+ };
87
+
88
+ /**
89
+ * @description 匹配样式
90
+ * @param {object} node 要匹配的标签
91
+ * @param {string|string[]} keys 选择器
92
+ * @returns {number} 0:不匹配;1:name 匹配;2:class 匹配;3:id 匹配
93
+ */
94
+ function match(node, keys) {
95
+ function matchItem(key) {
96
+ if (key[0] === '#') {
97
+ // 匹配 id
98
+ if (node.attrs.id && node.attrs.id.trim() === key.substr(1)) return 3;
99
+ } else if (key[0] === '.') {
100
+ // 匹配 class
101
+ key = key.substr(1);
102
+ const selectors = (node.attrs.class || '').split(' ');
103
+ for (let i = 0; i < selectors.length; i++) {
104
+ if (selectors[i].trim() === key) return 2;
105
+ }
106
+ } else if (node.name === key) {
107
+ // 匹配 name
108
+ return 1;
109
+ }
110
+ return 0;
111
+ }
112
+
113
+ // 多选择器交集
114
+ if (keys instanceof Array) {
115
+ let res = 0;
116
+ for (let j = 0; j < keys.length; j++) {
117
+ const tmp = matchItem(keys[j]);
118
+ // 任意一个不匹配就失败
119
+ if (!tmp) return 0;
120
+ // 优先级最大的一个作为最终优先级
121
+ if (tmp > res) {
122
+ res = tmp;
123
+ }
124
+ }
125
+ return res;
126
+ }
127
+
128
+ return matchItem(keys);
129
+ }
130
+ // #endif
131
+
132
+ export default Style;
@@ -0,0 +1,175 @@
1
+ const blank = {
2
+ ' ': true,
3
+ '\n': true,
4
+ '\t': true,
5
+ '\r': true,
6
+ '\f': true
7
+ };
8
+
9
+ function Parser() {
10
+ this.styles = [];
11
+ this.selectors = [];
12
+ }
13
+
14
+ /**
15
+ * @description 解析 css 字符串
16
+ * @param {string} content css 内容
17
+ */
18
+ Parser.prototype.parse = function (content) {
19
+ new Lexer(this).parse(content);
20
+ return this.styles;
21
+ };
22
+
23
+ /**
24
+ * @description 解析到一个选择器
25
+ * @param {string} name 名称
26
+ */
27
+ Parser.prototype.onSelector = function (name) {
28
+ // 不支持的选择器
29
+ if (name.includes('[') || name.includes('*') || name.includes('@')) return;
30
+ const selector = {};
31
+ // 伪类
32
+ if (name.includes(':')) {
33
+ const info = name.split(':');
34
+ const pseudo = info.pop();
35
+ if (pseudo === 'before' || pseudo === 'after') {
36
+ selector.pseudo = pseudo;
37
+ name = info[0];
38
+ } else return;
39
+ }
40
+
41
+ // 分割交集选择器
42
+ function splitItem(str) {
43
+ const arr = [];
44
+ let i, start;
45
+ for (i = 1, start = 0; i < str.length; i++) {
46
+ if (str[i] === '.' || str[i] === '#') {
47
+ arr.push(str.substring(start, i));
48
+ start = i;
49
+ }
50
+ }
51
+ if (!arr.length) {
52
+ return str;
53
+ } else {
54
+ arr.push(str.substring(start, i));
55
+ return arr;
56
+ }
57
+ }
58
+
59
+ // 后代选择器
60
+ if (name.includes(' ')) {
61
+ selector.list = [];
62
+ const list = name.split(' ');
63
+ for (let i = 0; i < list.length; i++) {
64
+ if (list[i].length) {
65
+ // 拆分子选择器
66
+ const arr = list[i].split('>');
67
+ for (let j = 0; j < arr.length; j++) {
68
+ selector.list.push(splitItem(arr[j]));
69
+ if (j < arr.length - 1) {
70
+ selector.list.push('>');
71
+ }
72
+ }
73
+ }
74
+ }
75
+ } else {
76
+ selector.key = splitItem(name);
77
+ }
78
+
79
+ this.selectors.push(selector);
80
+ };
81
+
82
+ /**
83
+ * @description 解析到选择器内容
84
+ * @param {string} content 内容
85
+ */
86
+ Parser.prototype.onContent = function (content) {
87
+ // 并集选择器
88
+ for (let i = 0; i < this.selectors.length; i++) {
89
+ this.selectors[i].style = content;
90
+ }
91
+ this.styles = this.styles.concat(this.selectors);
92
+ this.selectors = [];
93
+ };
94
+
95
+ /**
96
+ * @description css 词法分析器
97
+ * @param {object} handler 高层处理器
98
+ */
99
+ function Lexer(handler) {
100
+ this.selector = '';
101
+ this.style = '';
102
+ this.handler = handler;
103
+ }
104
+
105
+ Lexer.prototype.parse = function (content) {
106
+ this.i = 0;
107
+ this.content = content;
108
+ this.state = this.blank;
109
+ for (let len = content.length; this.i < len; this.i++) {
110
+ this.state(content[this.i]);
111
+ }
112
+ };
113
+
114
+ Lexer.prototype.comment = function () {
115
+ this.i = this.content.indexOf('*/', this.i) + 1;
116
+ if (!this.i) {
117
+ this.i = this.content.length;
118
+ }
119
+ };
120
+
121
+ Lexer.prototype.blank = function (c) {
122
+ if (!blank[c]) {
123
+ if (c === '/' && this.content[this.i + 1] === '*') {
124
+ this.comment();
125
+ return;
126
+ }
127
+ this.selector += c;
128
+ this.state = this.name;
129
+ }
130
+ };
131
+
132
+ Lexer.prototype.name = function (c) {
133
+ if (c === '/' && this.content[this.i + 1] === '*') {
134
+ this.comment();
135
+ return;
136
+ }
137
+ if (c === '{' || c === ',' || c === ';') {
138
+ this.handler.onSelector(this.selector.trimEnd());
139
+ this.selector = '';
140
+ if (c !== '{') {
141
+ while (blank[this.content[++this.i]]);
142
+ }
143
+ if (this.content[this.i] === '{') {
144
+ this.floor = 1;
145
+ this.state = this.val;
146
+ } else {
147
+ this.selector += this.content[this.i];
148
+ }
149
+ } else if (blank[c]) {
150
+ this.selector += ' ';
151
+ } else {
152
+ this.selector += c;
153
+ }
154
+ };
155
+
156
+ Lexer.prototype.val = function (c) {
157
+ if (c === '/' && this.content[this.i + 1] === '*') {
158
+ this.comment();
159
+ return;
160
+ }
161
+ if (c === '{') {
162
+ this.floor++;
163
+ } else if (c === '}') {
164
+ this.floor--;
165
+ if (!this.floor) {
166
+ this.handler.onContent(this.style);
167
+ this.style = '';
168
+ this.state = this.blank;
169
+ return;
170
+ }
171
+ }
172
+ this.style += c;
173
+ };
174
+
175
+ export default Parser;
@@ -0,0 +1,49 @@
1
+ /** snake-parse's public cross-platform rich-content contract. */
2
+ export interface ParseProps {
3
+ /** 要渲染的 HTML 内容。 */
4
+ content?: string;
5
+ /** 根容器样式。 */
6
+ containerStyle?: string;
7
+ /** 相对资源地址使用的主域名。 */
8
+ domain?: string;
9
+ /** 标签样式映射。 */
10
+ tagStyle?: Record<string, string>;
11
+ /** 是否延迟加载图片。 */
12
+ lazyLoad?: boolean;
13
+ /** 图片加载中的占位图。 */
14
+ loadingImg?: string;
15
+ /** 图片加载失败的占位图。 */
16
+ errorImg?: string;
17
+ /** 点击图片时是否打开预览。 */
18
+ previewImg?: boolean;
19
+ /** 是否显示图片长按菜单。 */
20
+ showImgMenu?: boolean;
21
+ /** 点击外部链接时是否复制地址。 */
22
+ copyLink?: boolean;
23
+ /** 播放新视频时是否暂停其他视频。 */
24
+ pauseVideo?: boolean;
25
+ /** 是否让表格独立横向滚动。 */
26
+ scrollTable?: boolean;
27
+ /** 文本是否可长按选择。 */
28
+ selectable?: boolean;
29
+ /** 是否使用 HTML 标题更新页面标题。 */
30
+ setTitle?: boolean;
31
+ /** 是否启用锚点定位,可指定偏移量。 */
32
+ useAnchor?: boolean | number;
33
+ }
34
+
35
+ /** 富文本加载、点击和媒体事件。 */
36
+ export interface ParseEmits {
37
+ /** 内容开始加载。 */
38
+ load: [];
39
+ /** 内容布局完成。 */
40
+ ready: [rect: UniApp.NodeInfo | Record<string, never>];
41
+ /** 用户点击图片。 */
42
+ imgtap: [attrs: Record<string, string> | undefined];
43
+ /** 用户点击链接。 */
44
+ linktap: [attrs: Record<string, string>];
45
+ /** 媒体开始播放。 */
46
+ play: [payload: { source: string; attrs: Record<string, string> | undefined }];
47
+ /** 富文本资源加载失败。 */
48
+ error: [payload: { source: string; attrs: Record<string, string> | undefined }];
49
+ }
@@ -0,0 +1,292 @@
1
+ <template>
2
+ <view class="pictureads" :style="{ backgroundColor: datas.backgroundColor }">
3
+ <view v-if="!imageList.length" :style="{ height: $snake.addUnit(datas.height * 2, 'rpx') }" class="upload">
4
+ 暂无图片
5
+ </view>
6
+ <!-- 一行一个 -->
7
+ <view
8
+ v-if="imageList.length && datas.swiperType === 0"
9
+ class="swiperType0"
10
+ :style="{ padding: `0 ${datas.pageMargin}rpx` }"
11
+ >
12
+ <view
13
+ v-for="(item, index) in imageList"
14
+ :key="index"
15
+ class="imgLis"
16
+ :style="{ 'margin-bottom': datas.imageMargin + 'rpx', height: $snake.addUnit(datas.height * 2, 'rpx') }"
17
+ @click="uni.$snake.navTo(item.url)"
18
+ >
19
+ <!-- 图片 -->
20
+ <image
21
+ class="image"
22
+ show-menu-by-longpress
23
+ :src="item.src"
24
+ :style="{ borderRadius: datas.borderRadius + 'rpx' }"
25
+ />
26
+ <!-- 标题 -->
27
+ <text v-if="item.text" class="title">{{ item.text }}</text>
28
+ </view>
29
+ </view>
30
+ <!-- 轮播组件 -->
31
+ <view
32
+ v-if="imageList.length && (datas.swiperType === 1 || datas.swiperType === 2)"
33
+ :style="{ padding: `0 ${datas.pageMargin}rpx` }"
34
+ >
35
+ <snake-swiper
36
+ :list="imageList"
37
+ :previous-margin="swiperMargin"
38
+ :next-margin="swiperMargin"
39
+ circular
40
+ :height="datas.height * 2"
41
+ :autoplay="imageList.length > 0"
42
+ :radius="datas.borderRadius"
43
+ name="src"
44
+ :show-title="true"
45
+ :loading="loading"
46
+ :interval="datas.interval || 3000"
47
+ :indicator-style="datas.pagingType === 'progressbar' ? 'width:100%; top: -2px; zIndex: 999;' : ''"
48
+ @change="change"
49
+ @click="clickPushTo"
50
+ >
51
+ <template #indicator>
52
+ <view v-if="datas.pagingType">
53
+ <!-- 指示器 -->
54
+ <!-- 样式一 -->
55
+ <view v-if="datas.pagingType === 'bullets'" class="dot-main">
56
+ <view
57
+ v-for="(item, index) in imageList"
58
+ :key="index"
59
+ class="dot-item"
60
+ :style="{ backgroundColor: current == index ? datas.indicatorColor : '' }"
61
+ />
62
+ </view>
63
+ <text
64
+ v-if="datas.pagingType === 'fraction'"
65
+ class="pagination"
66
+ :style="{ color: datas.indicatorColor }"
67
+ >
68
+ {{ current + 1 }}/{{ imageList.length }}
69
+ </text>
70
+ <!-- 样式3 -->
71
+ <view v-if="datas.pagingType === 'progressbar'" class="progressbar-box">
72
+ <view
73
+ class="progressbar"
74
+ :style="{
75
+ width: (100 / imageList.length) * (current + 1) + '%',
76
+ backgroundColor: datas.indicatorColor
77
+ }"
78
+ />
79
+ </view>
80
+ </view>
81
+ </template>
82
+ </snake-swiper>
83
+ </view>
84
+ </view>
85
+ </template>
86
+
87
+ <script>
88
+ /**
89
+ * @component PictureAds
90
+ * @description 以纵向图片列表或 Snake UI Swiper 展示广告,支持列表、轮播和指示器配置。
91
+ */
92
+
93
+ export default {
94
+ name: 'Pictureads',
95
+ options: { virtualHost: true, styleIsolation: 'shared' },
96
+ props: {
97
+ datas: {
98
+ type: [Object, null],
99
+ default() {
100
+ return {};
101
+ }
102
+ }
103
+ },
104
+ data() {
105
+ return {
106
+ current: 0,
107
+ loading: false
108
+ };
109
+ },
110
+ computed: {
111
+ imageList() {
112
+ return this.datas?.imageList || [];
113
+ },
114
+ // 轮播的前边距 和 后边距
115
+ swiperMargin() {
116
+ let margin = '';
117
+ // #ifdef MP-ALIPAY
118
+ margin = this.datas.swiperType === 2 ? '30rpx' : '';
119
+ // #endif
120
+ // #ifndef MP-ALIPAY
121
+ margin = this.datas.swiperType === 2 ? '60rpx' : '';
122
+ // #endif
123
+ return margin;
124
+ }
125
+ },
126
+ async mounted() {
127
+ await uni.$snake.sleep(300);
128
+ this.loading = false;
129
+ },
130
+ methods: {
131
+ change(e) {
132
+ this.current = e.current;
133
+ },
134
+ clickPushTo(index) {
135
+ const item = this.imageList[index] || {};
136
+ if (item?.startTime && item?.endTime && !item.url) {
137
+ return uni.$snake.toast('活动未开始');
138
+ }
139
+ uni.$snake.navTo(item.url);
140
+ }
141
+ }
142
+ };
143
+ </script>
144
+
145
+ <style scoped lang="scss">
146
+ :deep(.snake-swiper__indicator) {
147
+ display: none;
148
+ }
149
+
150
+ .pictureads {
151
+ position: relative;
152
+
153
+ /* 无图片 */
154
+ .upload {
155
+ display: flex;
156
+ align-items: center;
157
+ justify-content: center;
158
+ width: 100%;
159
+ height: 100%;
160
+ background: #ccc;
161
+ }
162
+
163
+ // 类型0
164
+ .swiperType0 {
165
+ box-sizing: border-box;
166
+
167
+ /* 图片列表 */
168
+ .imgLis {
169
+ position: relative;
170
+ // width: 750rpx;
171
+ width: 100%;
172
+ overflow: hidden;
173
+
174
+ /* 图片 */
175
+ .image {
176
+ width: 100%;
177
+ height: 100%;
178
+ }
179
+
180
+ .title {
181
+ position: absolute;
182
+ bottom: 0;
183
+ left: 0;
184
+ width: 100%;
185
+ height: 72rpx;
186
+ line-height: 72rpx;
187
+ color: #fff;
188
+ text-align: center;
189
+ background-color: rgba(51, 51, 51, 0.8);
190
+ }
191
+ }
192
+ }
193
+
194
+ /* 类型1 */
195
+ .type1 {
196
+ .swiper-slide {
197
+ position: relative;
198
+ width: 100%;
199
+ height: 100%;
200
+ }
201
+
202
+ .swiper-slide-image {
203
+ width: 100%;
204
+ height: 100%;
205
+ }
206
+
207
+ .title {
208
+ position: absolute;
209
+ bottom: 0;
210
+ left: 0;
211
+ box-sizing: border-box;
212
+ width: 100%;
213
+ height: 36px;
214
+ padding: 0 5px;
215
+ line-height: 36px;
216
+ color: #fff;
217
+ text-align: center;
218
+ text-align: left;
219
+ background-color: rgba(51, 51, 51, 0.8);
220
+ }
221
+ }
222
+
223
+ .type3 {
224
+ display: flex;
225
+ align-items: center;
226
+ justify-content: center;
227
+
228
+ .swiper-slide {
229
+ /* Center slide text vertically */
230
+ display: -webkit-box;
231
+ display: -ms-flexbox;
232
+ display: -webkit-flex;
233
+ display: flex;
234
+ -webkit-align-items: center;
235
+ align-items: center;
236
+ -webkit-justify-content: center;
237
+ justify-content: center;
238
+ height: 460rpx !important;
239
+ overflow: hidden;
240
+ font-size: 18px;
241
+ text-align: center;
242
+ box-shadow: rgba(147, 147, 147, 0.8) 0px 7px 24px 0px;
243
+ transform: scale(0.93);
244
+ transition: 300ms;
245
+ -webkit-box-pack: center;
246
+ -ms-flex-pack: center;
247
+ -webkit-box-align: center;
248
+ -ms-flex-align: center;
249
+ }
250
+
251
+ .swiper-slide-active {
252
+ height: 400rpx !important;
253
+ }
254
+ }
255
+ }
256
+
257
+ // 轮播
258
+ .swiper {
259
+ }
260
+
261
+ // 指示器 样式一
262
+ .dot-main {
263
+ display: flex;
264
+ align-items: center;
265
+ justify-content: center;
266
+
267
+ .dot-item {
268
+ width: 30rpx;
269
+ height: 4rpx;
270
+ margin: 0;
271
+ background-color: rgba(0, 0, 0, 0.4);
272
+ }
273
+ }
274
+
275
+ // 页码 样式二
276
+ .pagination {
277
+ font-size: 28rpx;
278
+ }
279
+
280
+ // 样式三
281
+ .progressbar-box {
282
+ width: 100%;
283
+ height: 4px;
284
+ background-color: rgba(0, 0, 0, 0.25);
285
+ }
286
+
287
+ .progressbar {
288
+ height: 4px;
289
+ background-color: #007aff;
290
+ transition: 300ms;
291
+ }
292
+ </style>
@@ -0,0 +1,5 @@
1
+ /** PictureAds 组件的公开属性。 */
2
+ export interface PictureAdsProps<Data extends Record<string, any> = Record<string, any>> {
3
+ /** CMS 装修组件配置数据。 */
4
+ datas?: Data;
5
+ }