@wordpress/block-editor 12.12.0 → 12.13.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.
Files changed (287) hide show
  1. package/CHANGELOG.md +12 -10
  2. package/README.md +35 -3
  3. package/build/components/block-alignment-control/use-available-alignments.js +30 -28
  4. package/build/components/block-alignment-control/use-available-alignments.js.map +1 -1
  5. package/build/components/block-list/block.native.js +4 -4
  6. package/build/components/block-list/block.native.js.map +1 -1
  7. package/build/components/block-list/layout.js +2 -3
  8. package/build/components/block-list/layout.js.map +1 -1
  9. package/build/components/border-radius-control/index.js +3 -2
  10. package/build/components/border-radius-control/index.js.map +1 -1
  11. package/build/components/color-palette/with-color-context.js +6 -6
  12. package/build/components/color-palette/with-color-context.js.map +1 -1
  13. package/build/components/colors/with-colors.js +2 -8
  14. package/build/components/colors/with-colors.js.map +1 -1
  15. package/build/components/colors-gradients/control.js +6 -7
  16. package/build/components/colors-gradients/control.js.map +1 -1
  17. package/build/components/colors-gradients/use-multiple-origin-colors-and-gradients.js +5 -13
  18. package/build/components/colors-gradients/use-multiple-origin-colors-and-gradients.js.map +1 -1
  19. package/build/components/font-family/index.js +2 -3
  20. package/build/components/font-family/index.js.map +1 -1
  21. package/build/components/font-sizes/font-size-picker.js +3 -5
  22. package/build/components/font-sizes/font-size-picker.js.map +1 -1
  23. package/build/components/font-sizes/with-font-sizes.js +3 -4
  24. package/build/components/font-sizes/with-font-sizes.js.map +1 -1
  25. package/build/components/global-styles/filters-panel.js +7 -8
  26. package/build/components/global-styles/filters-panel.js.map +1 -1
  27. package/build/components/global-styles/image-settings-panel.js +2 -2
  28. package/build/components/global-styles/image-settings-panel.js.map +1 -1
  29. package/build/components/global-styles/typography-panel.js +1 -1
  30. package/build/components/global-styles/typography-panel.js.map +1 -1
  31. package/build/components/gradients/use-gradient.js +2 -5
  32. package/build/components/gradients/use-gradient.js.map +1 -1
  33. package/build/components/height-control/index.js +3 -3
  34. package/build/components/height-control/index.js.map +1 -1
  35. package/build/components/index.js +9 -2
  36. package/build/components/index.js.map +1 -1
  37. package/build/components/index.native.js +9 -2
  38. package/build/components/index.native.js.map +1 -1
  39. package/build/components/inner-blocks/index.js +2 -2
  40. package/build/components/inner-blocks/index.js.map +1 -1
  41. package/build/components/letter-spacing-control/index.js +3 -3
  42. package/build/components/letter-spacing-control/index.js.map +1 -1
  43. package/build/components/link-control/search-item.js +11 -0
  44. package/build/components/link-control/search-item.js.map +1 -1
  45. package/build/components/link-control/search-results.js +2 -1
  46. package/build/components/link-control/search-results.js.map +1 -1
  47. package/build/components/link-control/use-search-handler.js +10 -5
  48. package/build/components/link-control/use-search-handler.js.map +1 -1
  49. package/build/components/resizable-box-popover/index.js +1 -1
  50. package/build/components/resizable-box-popover/index.js.map +1 -1
  51. package/build/components/rich-text/index.js +1 -1
  52. package/build/components/rich-text/index.js.map +1 -1
  53. package/build/components/spacing-sizes-control/hooks/use-spacing-sizes.js +6 -3
  54. package/build/components/spacing-sizes-control/hooks/use-spacing-sizes.js.map +1 -1
  55. package/build/components/spacing-sizes-control/input-controls/spacing-input-control.js +3 -3
  56. package/build/components/spacing-sizes-control/input-controls/spacing-input-control.js.map +1 -1
  57. package/build/components/unit-control/index.js +3 -3
  58. package/build/components/unit-control/index.js.map +1 -1
  59. package/build/components/use-block-commands/index.js +6 -1
  60. package/build/components/use-block-commands/index.js.map +1 -1
  61. package/build/components/use-settings/index.js +212 -0
  62. package/build/components/use-settings/index.js.map +1 -0
  63. package/build/hooks/align.js +51 -35
  64. package/build/hooks/align.js.map +1 -1
  65. package/build/hooks/anchor.js +37 -32
  66. package/build/hooks/anchor.js.map +1 -1
  67. package/build/hooks/background.js +4 -4
  68. package/build/hooks/background.js.map +1 -1
  69. package/build/hooks/color.js +2 -4
  70. package/build/hooks/color.js.map +1 -1
  71. package/build/hooks/duotone.js +10 -9
  72. package/build/hooks/duotone.js.map +1 -1
  73. package/build/hooks/font-size.js +4 -4
  74. package/build/hooks/font-size.js.map +1 -1
  75. package/build/hooks/layout.js +10 -11
  76. package/build/hooks/layout.js.map +1 -1
  77. package/build/hooks/line-height.js +3 -3
  78. package/build/hooks/line-height.js.map +1 -1
  79. package/build/hooks/position.js +2 -3
  80. package/build/hooks/position.js.map +1 -1
  81. package/build/hooks/use-color-props.js +3 -11
  82. package/build/hooks/use-color-props.js.map +1 -1
  83. package/build/hooks/utils.js +1 -42
  84. package/build/hooks/utils.js.map +1 -1
  85. package/build/layouts/constrained.js +3 -3
  86. package/build/layouts/constrained.js.map +1 -1
  87. package/build/utils/object.js +4 -1
  88. package/build/utils/object.js.map +1 -1
  89. package/build/utils/transform-styles/index.js +19 -24
  90. package/build/utils/transform-styles/index.js.map +1 -1
  91. package/build-module/components/block-alignment-control/use-available-alignments.js +30 -28
  92. package/build-module/components/block-alignment-control/use-available-alignments.js.map +1 -1
  93. package/build-module/components/block-list/block.native.js +4 -4
  94. package/build-module/components/block-list/block.native.js.map +1 -1
  95. package/build-module/components/block-list/layout.js +2 -2
  96. package/build-module/components/block-list/layout.js.map +1 -1
  97. package/build-module/components/border-radius-control/index.js +3 -2
  98. package/build-module/components/border-radius-control/index.js.map +1 -1
  99. package/build-module/components/color-palette/with-color-context.js +6 -5
  100. package/build-module/components/color-palette/with-color-context.js.map +1 -1
  101. package/build-module/components/colors/with-colors.js +2 -7
  102. package/build-module/components/colors/with-colors.js.map +1 -1
  103. package/build-module/components/colors-gradients/control.js +6 -7
  104. package/build-module/components/colors-gradients/control.js.map +1 -1
  105. package/build-module/components/colors-gradients/use-multiple-origin-colors-and-gradients.js +5 -12
  106. package/build-module/components/colors-gradients/use-multiple-origin-colors-and-gradients.js.map +1 -1
  107. package/build-module/components/font-family/index.js +2 -2
  108. package/build-module/components/font-family/index.js.map +1 -1
  109. package/build-module/components/font-sizes/font-size-picker.js +3 -4
  110. package/build-module/components/font-sizes/font-size-picker.js.map +1 -1
  111. package/build-module/components/font-sizes/with-font-sizes.js +3 -3
  112. package/build-module/components/font-sizes/with-font-sizes.js.map +1 -1
  113. package/build-module/components/global-styles/filters-panel.js +7 -8
  114. package/build-module/components/global-styles/filters-panel.js.map +1 -1
  115. package/build-module/components/global-styles/image-settings-panel.js +2 -2
  116. package/build-module/components/global-styles/image-settings-panel.js.map +1 -1
  117. package/build-module/components/global-styles/typography-panel.js +1 -1
  118. package/build-module/components/global-styles/typography-panel.js.map +1 -1
  119. package/build-module/components/gradients/use-gradient.js +2 -4
  120. package/build-module/components/gradients/use-gradient.js.map +1 -1
  121. package/build-module/components/height-control/index.js +3 -2
  122. package/build-module/components/height-control/index.js.map +1 -1
  123. package/build-module/components/index.js +1 -1
  124. package/build-module/components/index.js.map +1 -1
  125. package/build-module/components/index.native.js +1 -1
  126. package/build-module/components/index.native.js.map +1 -1
  127. package/build-module/components/inner-blocks/index.js +2 -2
  128. package/build-module/components/inner-blocks/index.js.map +1 -1
  129. package/build-module/components/letter-spacing-control/index.js +3 -2
  130. package/build-module/components/letter-spacing-control/index.js.map +1 -1
  131. package/build-module/components/link-control/search-item.js +12 -1
  132. package/build-module/components/link-control/search-item.js.map +1 -1
  133. package/build-module/components/link-control/search-results.js +2 -1
  134. package/build-module/components/link-control/search-results.js.map +1 -1
  135. package/build-module/components/link-control/use-search-handler.js +10 -5
  136. package/build-module/components/link-control/use-search-handler.js.map +1 -1
  137. package/build-module/components/resizable-box-popover/index.js +1 -1
  138. package/build-module/components/resizable-box-popover/index.js.map +1 -1
  139. package/build-module/components/rich-text/index.js +1 -1
  140. package/build-module/components/rich-text/index.js.map +1 -1
  141. package/build-module/components/spacing-sizes-control/hooks/use-spacing-sizes.js +6 -2
  142. package/build-module/components/spacing-sizes-control/hooks/use-spacing-sizes.js.map +1 -1
  143. package/build-module/components/spacing-sizes-control/input-controls/spacing-input-control.js +3 -2
  144. package/build-module/components/spacing-sizes-control/input-controls/spacing-input-control.js.map +1 -1
  145. package/build-module/components/unit-control/index.js +3 -2
  146. package/build-module/components/unit-control/index.js.map +1 -1
  147. package/build-module/components/use-block-commands/index.js +5 -1
  148. package/build-module/components/use-block-commands/index.js.map +1 -1
  149. package/build-module/components/use-settings/index.js +203 -0
  150. package/build-module/components/use-settings/index.js.map +1 -0
  151. package/build-module/hooks/align.js +51 -35
  152. package/build-module/hooks/align.js.map +1 -1
  153. package/build-module/hooks/anchor.js +37 -32
  154. package/build-module/hooks/anchor.js.map +1 -1
  155. package/build-module/hooks/background.js +4 -4
  156. package/build-module/hooks/background.js.map +1 -1
  157. package/build-module/hooks/color.js +2 -4
  158. package/build-module/hooks/color.js.map +1 -1
  159. package/build-module/hooks/duotone.js +11 -10
  160. package/build-module/hooks/duotone.js.map +1 -1
  161. package/build-module/hooks/font-size.js +4 -4
  162. package/build-module/hooks/font-size.js.map +1 -1
  163. package/build-module/hooks/layout.js +10 -11
  164. package/build-module/hooks/layout.js.map +1 -1
  165. package/build-module/hooks/line-height.js +3 -3
  166. package/build-module/hooks/line-height.js.map +1 -1
  167. package/build-module/hooks/position.js +2 -3
  168. package/build-module/hooks/position.js.map +1 -1
  169. package/build-module/hooks/use-color-props.js +3 -11
  170. package/build-module/hooks/use-color-props.js.map +1 -1
  171. package/build-module/hooks/utils.js +2 -43
  172. package/build-module/hooks/utils.js.map +1 -1
  173. package/build-module/layouts/constrained.js +3 -2
  174. package/build-module/layouts/constrained.js.map +1 -1
  175. package/build-module/utils/object.js +3 -1
  176. package/build-module/utils/object.js.map +1 -1
  177. package/build-module/utils/transform-styles/index.js +20 -24
  178. package/build-module/utils/transform-styles/index.js.map +1 -1
  179. package/build-style/style-rtl.css +13 -6
  180. package/build-style/style.css +13 -6
  181. package/package.json +36 -34
  182. package/src/components/block-alignment-control/use-available-alignments.js +49 -34
  183. package/src/components/block-list/block.native.js +4 -4
  184. package/src/components/block-list/layout.js +2 -2
  185. package/src/components/block-styles/style.scss +1 -1
  186. package/src/components/border-radius-control/index.js +3 -2
  187. package/src/components/color-palette/with-color-context.js +9 -9
  188. package/src/components/colors/with-colors.js +6 -7
  189. package/src/components/colors-gradients/control.js +10 -7
  190. package/src/components/colors-gradients/use-multiple-origin-colors-and-gradients.js +29 -15
  191. package/src/components/font-family/index.js +2 -2
  192. package/src/components/font-sizes/font-size-picker.js +6 -4
  193. package/src/components/font-sizes/with-font-sizes.js +3 -5
  194. package/src/components/global-styles/filters-panel.js +9 -15
  195. package/src/components/global-styles/image-settings-panel.js +2 -2
  196. package/src/components/global-styles/typography-panel.js +1 -1
  197. package/src/components/gradients/use-gradient.js +10 -4
  198. package/src/components/height-control/index.js +3 -2
  199. package/src/components/index.js +1 -1
  200. package/src/components/index.native.js +1 -1
  201. package/src/components/inner-blocks/index.js +2 -2
  202. package/src/components/inserter/style.scss +9 -1
  203. package/src/components/letter-spacing-control/index.js +3 -2
  204. package/src/components/link-control/search-item.js +14 -0
  205. package/src/components/link-control/search-results.js +1 -0
  206. package/src/components/link-control/use-search-handler.js +22 -15
  207. package/src/components/resizable-box-popover/index.js +1 -1
  208. package/src/components/rich-text/index.js +1 -1
  209. package/src/components/spacing-sizes-control/hooks/use-spacing-sizes.js +7 -5
  210. package/src/components/spacing-sizes-control/input-controls/spacing-input-control.js +3 -2
  211. package/src/components/unit-control/index.js +3 -8
  212. package/src/components/use-block-commands/index.js +2 -1
  213. package/src/components/{use-setting → use-settings}/README.md +9 -10
  214. package/src/components/use-settings/index.js +272 -0
  215. package/src/components/{use-setting → use-settings}/test/index.js +47 -5
  216. package/src/hooks/align.js +79 -54
  217. package/src/hooks/anchor.js +75 -65
  218. package/src/hooks/background.js +7 -9
  219. package/src/hooks/color.js +7 -4
  220. package/src/hooks/duotone.js +24 -19
  221. package/src/hooks/font-size.js +4 -4
  222. package/src/hooks/layout.js +11 -11
  223. package/src/hooks/line-height.js +3 -3
  224. package/src/hooks/position.js +5 -3
  225. package/src/hooks/use-color-props.js +21 -14
  226. package/src/hooks/utils.js +88 -43
  227. package/src/layouts/constrained.js +3 -8
  228. package/src/utils/object.js +4 -1
  229. package/src/utils/test/__snapshots__/transform-styles.js.snap +103 -0
  230. package/src/utils/test/transform-styles.js +217 -0
  231. package/src/utils/transform-styles/index.js +25 -25
  232. package/build/components/use-setting/index.js +0 -161
  233. package/build/components/use-setting/index.js.map +0 -1
  234. package/build/utils/transform-styles/ast/index.js +0 -21
  235. package/build/utils/transform-styles/ast/index.js.map +0 -1
  236. package/build/utils/transform-styles/ast/parse.js +0 -660
  237. package/build/utils/transform-styles/ast/parse.js.map +0 -1
  238. package/build/utils/transform-styles/ast/stringify/compiler.js +0 -52
  239. package/build/utils/transform-styles/ast/stringify/compiler.js.map +0 -1
  240. package/build/utils/transform-styles/ast/stringify/compress.js +0 -178
  241. package/build/utils/transform-styles/ast/stringify/compress.js.map +0 -1
  242. package/build/utils/transform-styles/ast/stringify/identity.js +0 -207
  243. package/build/utils/transform-styles/ast/stringify/identity.js.map +0 -1
  244. package/build/utils/transform-styles/ast/stringify/index.js +0 -36
  245. package/build/utils/transform-styles/ast/stringify/index.js.map +0 -1
  246. package/build/utils/transform-styles/transforms/url-rewrite.js +0 -130
  247. package/build/utils/transform-styles/transforms/url-rewrite.js.map +0 -1
  248. package/build/utils/transform-styles/transforms/wrap.js +0 -59
  249. package/build/utils/transform-styles/transforms/wrap.js.map +0 -1
  250. package/build/utils/transform-styles/traverse.js +0 -37
  251. package/build/utils/transform-styles/traverse.js.map +0 -1
  252. package/build-module/components/use-setting/index.js +0 -154
  253. package/build-module/components/use-setting/index.js.map +0 -1
  254. package/build-module/utils/transform-styles/ast/index.js +0 -6
  255. package/build-module/utils/transform-styles/ast/index.js.map +0 -1
  256. package/build-module/utils/transform-styles/ast/parse.js +0 -654
  257. package/build-module/utils/transform-styles/ast/parse.js.map +0 -1
  258. package/build-module/utils/transform-styles/ast/stringify/compiler.js +0 -49
  259. package/build-module/utils/transform-styles/ast/stringify/compiler.js.map +0 -1
  260. package/build-module/utils/transform-styles/ast/stringify/compress.js +0 -176
  261. package/build-module/utils/transform-styles/ast/stringify/compress.js.map +0 -1
  262. package/build-module/utils/transform-styles/ast/stringify/identity.js +0 -206
  263. package/build-module/utils/transform-styles/ast/stringify/identity.js.map +0 -1
  264. package/build-module/utils/transform-styles/ast/stringify/index.js +0 -29
  265. package/build-module/utils/transform-styles/ast/stringify/index.js.map +0 -1
  266. package/build-module/utils/transform-styles/transforms/url-rewrite.js +0 -123
  267. package/build-module/utils/transform-styles/transforms/url-rewrite.js.map +0 -1
  268. package/build-module/utils/transform-styles/transforms/wrap.js +0 -52
  269. package/build-module/utils/transform-styles/transforms/wrap.js.map +0 -1
  270. package/build-module/utils/transform-styles/traverse.js +0 -28
  271. package/build-module/utils/transform-styles/traverse.js.map +0 -1
  272. package/src/components/use-setting/index.js +0 -218
  273. package/src/utils/transform-styles/ast/index.js +0 -5
  274. package/src/utils/transform-styles/ast/parse.js +0 -732
  275. package/src/utils/transform-styles/ast/stringify/compiler.js +0 -50
  276. package/src/utils/transform-styles/ast/stringify/compress.js +0 -238
  277. package/src/utils/transform-styles/ast/stringify/identity.js +0 -286
  278. package/src/utils/transform-styles/ast/stringify/index.js +0 -32
  279. package/src/utils/transform-styles/test/__snapshots__/traverse.js.snap +0 -7
  280. package/src/utils/transform-styles/test/traverse.js +0 -24
  281. package/src/utils/transform-styles/transforms/test/__snapshots__/url-rewrite.js.snap +0 -25
  282. package/src/utils/transform-styles/transforms/test/__snapshots__/wrap.js.snap +0 -64
  283. package/src/utils/transform-styles/transforms/test/url-rewrite.js +0 -39
  284. package/src/utils/transform-styles/transforms/test/wrap.js +0 -95
  285. package/src/utils/transform-styles/transforms/url-rewrite.js +0 -139
  286. package/src/utils/transform-styles/transforms/wrap.js +0 -56
  287. package/src/utils/transform-styles/traverse.js +0 -32
@@ -1,654 +0,0 @@
1
- /* eslint-disable @wordpress/no-unused-vars-before-return */
2
-
3
- // Adapted from https://github.com/reworkcss/css
4
- // because we needed to remove source map support.
5
-
6
- // http://www.w3.org/TR/CSS21/grammar.htm
7
- // https://github.com/visionmedia/css-parse/pull/49#issuecomment-30088027
8
- const commentre = /\/\*[^*]*\*+([^/*][^*]*\*+)*\//g;
9
- export default function (css, options) {
10
- options = options || {};
11
-
12
- /**
13
- * Positional.
14
- */
15
-
16
- let lineno = 1;
17
- let column = 1;
18
-
19
- /**
20
- * Update lineno and column based on `str`.
21
- */
22
-
23
- function updatePosition(str) {
24
- const lines = str.match(/\n/g);
25
- if (lines) {
26
- lineno += lines.length;
27
- }
28
- const i = str.lastIndexOf('\n');
29
- // eslint-disable-next-line no-bitwise
30
- column = ~i ? str.length - i : column + str.length;
31
- }
32
-
33
- /**
34
- * Mark position and patch `node.position`.
35
- */
36
-
37
- function position() {
38
- const start = {
39
- line: lineno,
40
- column
41
- };
42
- return function (node) {
43
- node.position = new Position(start);
44
- whitespace();
45
- return node;
46
- };
47
- }
48
-
49
- /**
50
- * Store position information for a node
51
- */
52
-
53
- function Position(start) {
54
- this.start = start;
55
- this.end = {
56
- line: lineno,
57
- column
58
- };
59
- this.source = options.source;
60
- }
61
-
62
- /**
63
- * Non-enumerable source string
64
- */
65
-
66
- Position.prototype.content = css;
67
-
68
- /**
69
- * Error `msg`.
70
- */
71
-
72
- const errorsList = [];
73
- function error(msg) {
74
- const err = new Error(options.source + ':' + lineno + ':' + column + ': ' + msg);
75
- err.reason = msg;
76
- err.filename = options.source;
77
- err.line = lineno;
78
- err.column = column;
79
- err.source = css;
80
- if (options.silent) {
81
- errorsList.push(err);
82
- } else {
83
- throw err;
84
- }
85
- }
86
-
87
- /**
88
- * Parse stylesheet.
89
- */
90
-
91
- function stylesheet() {
92
- const rulesList = rules();
93
- return {
94
- type: 'stylesheet',
95
- stylesheet: {
96
- source: options.source,
97
- rules: rulesList,
98
- parsingErrors: errorsList
99
- }
100
- };
101
- }
102
-
103
- /**
104
- * Opening brace.
105
- */
106
-
107
- function open() {
108
- return match(/^{\s*/);
109
- }
110
-
111
- /**
112
- * Closing brace.
113
- */
114
-
115
- function close() {
116
- return match(/^}/);
117
- }
118
-
119
- /**
120
- * Parse ruleset.
121
- */
122
-
123
- function rules() {
124
- let node;
125
- const accumulator = [];
126
- whitespace();
127
- comments(accumulator);
128
- while (css.length && css.charAt(0) !== '}' && (node = atrule() || rule())) {
129
- if (node !== false) {
130
- accumulator.push(node);
131
- comments(accumulator);
132
- }
133
- }
134
- return accumulator;
135
- }
136
-
137
- /**
138
- * Match `re` and return captures.
139
- */
140
-
141
- function match(re) {
142
- const m = re.exec(css);
143
- if (!m) {
144
- return;
145
- }
146
- const str = m[0];
147
- updatePosition(str);
148
- css = css.slice(str.length);
149
- return m;
150
- }
151
-
152
- /**
153
- * Parse whitespace.
154
- */
155
-
156
- function whitespace() {
157
- match(/^\s*/);
158
- }
159
-
160
- /**
161
- * Parse comments;
162
- */
163
-
164
- function comments(accumulator) {
165
- let c;
166
- accumulator = accumulator || [];
167
- // eslint-disable-next-line no-cond-assign
168
- while (c = comment()) {
169
- if (c !== false) {
170
- accumulator.push(c);
171
- }
172
- }
173
- return accumulator;
174
- }
175
-
176
- /**
177
- * Parse comment.
178
- */
179
-
180
- function comment() {
181
- const pos = position();
182
- if ('/' !== css.charAt(0) || '*' !== css.charAt(1)) {
183
- return;
184
- }
185
- let i = 2;
186
- while ('' !== css.charAt(i) && ('*' !== css.charAt(i) || '/' !== css.charAt(i + 1))) {
187
- ++i;
188
- }
189
- i += 2;
190
- if ('' === css.charAt(i - 1)) {
191
- return error('End of comment missing');
192
- }
193
- const str = css.slice(2, i - 2);
194
- column += 2;
195
- updatePosition(str);
196
- css = css.slice(i);
197
- column += 2;
198
- return pos({
199
- type: 'comment',
200
- comment: str
201
- });
202
- }
203
-
204
- /**
205
- * Parse selector.
206
- */
207
-
208
- function selector() {
209
- const m = match(/^([^{]+)/);
210
- if (!m) {
211
- return;
212
- }
213
- // FIXME: Remove all comments from selectors http://ostermiller.org/findcomment.html
214
- return trim(m[0]).replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*\/+/g, '').replace(/"(?:\\"|[^"])*"|'(?:\\'|[^'])*'/g, function (matched) {
215
- return matched.replace(/,/g, '\u200C');
216
- }).split(/\s*(?![^(]*\)),\s*/).map(function (s) {
217
- return s.replace(/\u200C/g, ',');
218
- });
219
- }
220
-
221
- /**
222
- * Parse declaration.
223
- */
224
-
225
- function declaration() {
226
- const pos = position();
227
-
228
- // prop.
229
- let prop = match(/^(\*?[-#\/\*\\\w]+(\[[0-9a-z_-]+\])?)\s*/);
230
- if (!prop) {
231
- return;
232
- }
233
- prop = trim(prop[0]);
234
-
235
- // :
236
- if (!match(/^:\s*/)) {
237
- return error("property missing ':'");
238
- }
239
-
240
- // val.
241
- const val = match(/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^\)]*?\)|[^};])+)/);
242
- const ret = pos({
243
- type: 'declaration',
244
- property: prop.replace(commentre, ''),
245
- value: val ? trim(val[0]).replace(commentre, '') : ''
246
- });
247
-
248
- // ;
249
- match(/^[;\s]*/);
250
- return ret;
251
- }
252
-
253
- /**
254
- * Parse declarations.
255
- */
256
-
257
- function declarations() {
258
- const decls = [];
259
- if (!open()) {
260
- return error("missing '{'");
261
- }
262
- comments(decls);
263
-
264
- // declarations.
265
- let decl;
266
- // eslint-disable-next-line no-cond-assign
267
- while (decl = declaration()) {
268
- if (decl !== false) {
269
- decls.push(decl);
270
- comments(decls);
271
- }
272
- }
273
- if (!close()) {
274
- return error("missing '}'");
275
- }
276
- return decls;
277
- }
278
-
279
- /**
280
- * Parse keyframe.
281
- */
282
-
283
- function keyframe() {
284
- let m;
285
- const vals = [];
286
- const pos = position();
287
-
288
- // eslint-disable-next-line no-cond-assign
289
- while (m = match(/^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/)) {
290
- vals.push(m[1]);
291
- match(/^,\s*/);
292
- }
293
- if (!vals.length) {
294
- return;
295
- }
296
- return pos({
297
- type: 'keyframe',
298
- values: vals,
299
- declarations: declarations()
300
- });
301
- }
302
-
303
- /**
304
- * Parse keyframes.
305
- */
306
-
307
- function atkeyframes() {
308
- const pos = position();
309
- let m = match(/^@([-\w]+)?keyframes\s*/);
310
- if (!m) {
311
- return;
312
- }
313
- const vendor = m[1];
314
-
315
- // identifier
316
- m = match(/^([-\w]+)\s*/);
317
- if (!m) {
318
- return error('@keyframes missing name');
319
- }
320
- const name = m[1];
321
- if (!open()) {
322
- return error("@keyframes missing '{'");
323
- }
324
- let frame;
325
- let frames = comments();
326
- // eslint-disable-next-line no-cond-assign
327
- while (frame = keyframe()) {
328
- frames.push(frame);
329
- frames = frames.concat(comments());
330
- }
331
- if (!close()) {
332
- return error("@keyframes missing '}'");
333
- }
334
- return pos({
335
- type: 'keyframes',
336
- name,
337
- vendor,
338
- keyframes: frames
339
- });
340
- }
341
-
342
- /**
343
- * Parse supports.
344
- */
345
-
346
- function atsupports() {
347
- const pos = position();
348
- const m = match(/^@supports *([^{]+)/);
349
- if (!m) {
350
- return;
351
- }
352
- const supports = trim(m[1]);
353
- if (!open()) {
354
- return error("@supports missing '{'");
355
- }
356
- const style = comments().concat(rules());
357
- if (!close()) {
358
- return error("@supports missing '}'");
359
- }
360
- return pos({
361
- type: 'supports',
362
- supports,
363
- rules: style
364
- });
365
- }
366
-
367
- /**
368
- * Parse host.
369
- */
370
-
371
- function athost() {
372
- const pos = position();
373
- const m = match(/^@host\s*/);
374
- if (!m) {
375
- return;
376
- }
377
- if (!open()) {
378
- return error("@host missing '{'");
379
- }
380
- const style = comments().concat(rules());
381
- if (!close()) {
382
- return error("@host missing '}'");
383
- }
384
- return pos({
385
- type: 'host',
386
- rules: style
387
- });
388
- }
389
-
390
- /**
391
- * Parse media.
392
- */
393
-
394
- function atmedia() {
395
- const pos = position();
396
- const m = match(/^@media *([^{]+)/);
397
- if (!m) {
398
- return;
399
- }
400
- const media = trim(m[1]);
401
- if (!open()) {
402
- return error("@media missing '{'");
403
- }
404
- const style = comments().concat(rules());
405
- if (!close()) {
406
- return error("@media missing '}'");
407
- }
408
- return pos({
409
- type: 'media',
410
- media,
411
- rules: style
412
- });
413
- }
414
-
415
- /**
416
- * Parse container.
417
- */
418
-
419
- function atcontainer() {
420
- const pos = position();
421
- const m = match(/^@container *([^{]+)/);
422
- if (!m) {
423
- return;
424
- }
425
- const container = trim(m[1]);
426
- if (!open()) {
427
- return error("@container missing '{'");
428
- }
429
- const style = comments().concat(rules());
430
- if (!close()) {
431
- return error("@container missing '}'");
432
- }
433
- return pos({
434
- type: 'container',
435
- container,
436
- rules: style
437
- });
438
- }
439
-
440
- /**
441
- * Parse custom-media.
442
- */
443
-
444
- function atcustommedia() {
445
- const pos = position();
446
- const m = match(/^@custom-media\s+(--[^\s]+)\s*([^{;]+);/);
447
- if (!m) {
448
- return;
449
- }
450
- return pos({
451
- type: 'custom-media',
452
- name: trim(m[1]),
453
- media: trim(m[2])
454
- });
455
- }
456
-
457
- /**
458
- * Parse paged media.
459
- */
460
-
461
- function atpage() {
462
- const pos = position();
463
- const m = match(/^@page */);
464
- if (!m) {
465
- return;
466
- }
467
- const sel = selector() || [];
468
- if (!open()) {
469
- return error("@page missing '{'");
470
- }
471
- let decls = comments();
472
-
473
- // declarations.
474
- let decl;
475
- // eslint-disable-next-line no-cond-assign
476
- while (decl = declaration()) {
477
- decls.push(decl);
478
- decls = decls.concat(comments());
479
- }
480
- if (!close()) {
481
- return error("@page missing '}'");
482
- }
483
- return pos({
484
- type: 'page',
485
- selectors: sel,
486
- declarations: decls
487
- });
488
- }
489
-
490
- /**
491
- * Parse document.
492
- */
493
-
494
- function atdocument() {
495
- const pos = position();
496
- const m = match(/^@([-\w]+)?document *([^{]+)/);
497
- if (!m) {
498
- return;
499
- }
500
- const vendor = trim(m[1]);
501
- const doc = trim(m[2]);
502
- if (!open()) {
503
- return error("@document missing '{'");
504
- }
505
- const style = comments().concat(rules());
506
- if (!close()) {
507
- return error("@document missing '}'");
508
- }
509
- return pos({
510
- type: 'document',
511
- document: doc,
512
- vendor,
513
- rules: style
514
- });
515
- }
516
-
517
- /**
518
- * Parse font-face.
519
- */
520
-
521
- function atfontface() {
522
- const pos = position();
523
- const m = match(/^@font-face\s*/);
524
- if (!m) {
525
- return;
526
- }
527
- if (!open()) {
528
- return error("@font-face missing '{'");
529
- }
530
- let decls = comments();
531
-
532
- // declarations.
533
- let decl;
534
- // eslint-disable-next-line no-cond-assign
535
- while (decl = declaration()) {
536
- decls.push(decl);
537
- decls = decls.concat(comments());
538
- }
539
- if (!close()) {
540
- return error("@font-face missing '}'");
541
- }
542
- return pos({
543
- type: 'font-face',
544
- declarations: decls
545
- });
546
- }
547
-
548
- /**
549
- * Parse import
550
- */
551
-
552
- const atimport = _compileAtrule('import');
553
-
554
- /**
555
- * Parse charset
556
- */
557
-
558
- const atcharset = _compileAtrule('charset');
559
-
560
- /**
561
- * Parse namespace
562
- */
563
-
564
- const atnamespace = _compileAtrule('namespace');
565
-
566
- /**
567
- * Parse non-block at-rules
568
- */
569
-
570
- function _compileAtrule(name) {
571
- const re = new RegExp('^@' + name + '\\s*([^;]+);');
572
- return function () {
573
- const pos = position();
574
- const m = match(re);
575
- if (!m) {
576
- return;
577
- }
578
- const ret = {
579
- type: name
580
- };
581
- ret[name] = m[1].trim();
582
- return pos(ret);
583
- };
584
- }
585
-
586
- /**
587
- * Parse at rule.
588
- */
589
-
590
- function atrule() {
591
- if (css[0] !== '@') {
592
- return;
593
- }
594
- return atkeyframes() || atmedia() || atcontainer() || atcustommedia() || atsupports() || atimport() || atcharset() || atnamespace() || atdocument() || atpage() || athost() || atfontface();
595
- }
596
-
597
- /**
598
- * Parse rule.
599
- */
600
-
601
- function rule() {
602
- const pos = position();
603
- const sel = selector();
604
- if (!sel) {
605
- return error('selector missing');
606
- }
607
- comments();
608
- return pos({
609
- type: 'rule',
610
- selectors: sel,
611
- declarations: declarations()
612
- });
613
- }
614
- return addParent(stylesheet());
615
- }
616
-
617
- /**
618
- * Trim `str`.
619
- */
620
-
621
- function trim(str) {
622
- return str ? str.replace(/^\s+|\s+$/g, '') : '';
623
- }
624
-
625
- /**
626
- * Adds non-enumerable parent node reference to each node.
627
- */
628
-
629
- function addParent(obj, parent) {
630
- const isNode = obj && typeof obj.type === 'string';
631
- const childParent = isNode ? obj : parent;
632
- for (const k in obj) {
633
- const value = obj[k];
634
- if (Array.isArray(value)) {
635
- value.forEach(function (v) {
636
- addParent(v, childParent);
637
- });
638
- } else if (value && typeof value === 'object') {
639
- addParent(value, childParent);
640
- }
641
- }
642
- if (isNode) {
643
- Object.defineProperty(obj, 'parent', {
644
- configurable: true,
645
- writable: true,
646
- enumerable: false,
647
- value: parent || null
648
- });
649
- }
650
- return obj;
651
- }
652
-
653
- /* eslint-enable @wordpress/no-unused-vars-before-return */
654
- //# sourceMappingURL=parse.js.map