@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,732 +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
-
10
- export default function ( css, options ) {
11
- options = options || {};
12
-
13
- /**
14
- * Positional.
15
- */
16
-
17
- let lineno = 1;
18
- let column = 1;
19
-
20
- /**
21
- * Update lineno and column based on `str`.
22
- */
23
-
24
- function updatePosition( str ) {
25
- const lines = str.match( /\n/g );
26
- if ( lines ) {
27
- lineno += lines.length;
28
- }
29
- const i = str.lastIndexOf( '\n' );
30
- // eslint-disable-next-line no-bitwise
31
- column = ~i ? str.length - i : column + str.length;
32
- }
33
-
34
- /**
35
- * Mark position and patch `node.position`.
36
- */
37
-
38
- function position() {
39
- const start = { line: lineno, column };
40
- return function ( node ) {
41
- node.position = new Position( start );
42
- whitespace();
43
- return node;
44
- };
45
- }
46
-
47
- /**
48
- * Store position information for a node
49
- */
50
-
51
- function Position( start ) {
52
- this.start = start;
53
- this.end = { line: lineno, column };
54
- this.source = options.source;
55
- }
56
-
57
- /**
58
- * Non-enumerable source string
59
- */
60
-
61
- Position.prototype.content = css;
62
-
63
- /**
64
- * Error `msg`.
65
- */
66
-
67
- const errorsList = [];
68
-
69
- function error( msg ) {
70
- const err = new Error(
71
- options.source + ':' + lineno + ':' + column + ': ' + msg
72
- );
73
- err.reason = msg;
74
- err.filename = options.source;
75
- err.line = lineno;
76
- err.column = column;
77
- err.source = css;
78
-
79
- if ( options.silent ) {
80
- errorsList.push( err );
81
- } else {
82
- throw err;
83
- }
84
- }
85
-
86
- /**
87
- * Parse stylesheet.
88
- */
89
-
90
- function stylesheet() {
91
- const rulesList = rules();
92
-
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 (
129
- css.length &&
130
- css.charAt( 0 ) !== '}' &&
131
- ( node = atrule() || rule() )
132
- ) {
133
- if ( node !== false ) {
134
- accumulator.push( node );
135
- comments( accumulator );
136
- }
137
- }
138
- return accumulator;
139
- }
140
-
141
- /**
142
- * Match `re` and return captures.
143
- */
144
-
145
- function match( re ) {
146
- const m = re.exec( css );
147
- if ( ! m ) {
148
- return;
149
- }
150
- const str = m[ 0 ];
151
- updatePosition( str );
152
- css = css.slice( str.length );
153
- return m;
154
- }
155
-
156
- /**
157
- * Parse whitespace.
158
- */
159
-
160
- function whitespace() {
161
- match( /^\s*/ );
162
- }
163
-
164
- /**
165
- * Parse comments;
166
- */
167
-
168
- function comments( accumulator ) {
169
- let c;
170
- accumulator = accumulator || [];
171
- // eslint-disable-next-line no-cond-assign
172
- while ( ( c = comment() ) ) {
173
- if ( c !== false ) {
174
- accumulator.push( c );
175
- }
176
- }
177
- return accumulator;
178
- }
179
-
180
- /**
181
- * Parse comment.
182
- */
183
-
184
- function comment() {
185
- const pos = position();
186
- if ( '/' !== css.charAt( 0 ) || '*' !== css.charAt( 1 ) ) {
187
- return;
188
- }
189
-
190
- let i = 2;
191
- while (
192
- '' !== css.charAt( i ) &&
193
- ( '*' !== css.charAt( i ) || '/' !== css.charAt( i + 1 ) )
194
- ) {
195
- ++i;
196
- }
197
- i += 2;
198
-
199
- if ( '' === css.charAt( i - 1 ) ) {
200
- return error( 'End of comment missing' );
201
- }
202
-
203
- const str = css.slice( 2, i - 2 );
204
- column += 2;
205
- updatePosition( str );
206
- css = css.slice( i );
207
- column += 2;
208
-
209
- return pos( {
210
- type: 'comment',
211
- comment: str,
212
- } );
213
- }
214
-
215
- /**
216
- * Parse selector.
217
- */
218
-
219
- function selector() {
220
- const m = match( /^([^{]+)/ );
221
- if ( ! m ) {
222
- return;
223
- }
224
- // FIXME: Remove all comments from selectors http://ostermiller.org/findcomment.html
225
- return trim( m[ 0 ] )
226
- .replace( /\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*\/+/g, '' )
227
- .replace( /"(?:\\"|[^"])*"|'(?:\\'|[^'])*'/g, function ( matched ) {
228
- return matched.replace( /,/g, '\u200C' );
229
- } )
230
- .split( /\s*(?![^(]*\)),\s*/ )
231
- .map( function ( s ) {
232
- return s.replace( /\u200C/g, ',' );
233
- } );
234
- }
235
-
236
- /**
237
- * Parse declaration.
238
- */
239
-
240
- function declaration() {
241
- const pos = position();
242
-
243
- // prop.
244
- let prop = match( /^(\*?[-#\/\*\\\w]+(\[[0-9a-z_-]+\])?)\s*/ );
245
- if ( ! prop ) {
246
- return;
247
- }
248
- prop = trim( prop[ 0 ] );
249
-
250
- // :
251
- if ( ! match( /^:\s*/ ) ) {
252
- return error( "property missing ':'" );
253
- }
254
-
255
- // val.
256
- const val = match(
257
- /^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^\)]*?\)|[^};])+)/
258
- );
259
-
260
- const ret = pos( {
261
- type: 'declaration',
262
- property: prop.replace( commentre, '' ),
263
- value: val ? trim( val[ 0 ] ).replace( commentre, '' ) : '',
264
- } );
265
-
266
- // ;
267
- match( /^[;\s]*/ );
268
-
269
- return ret;
270
- }
271
-
272
- /**
273
- * Parse declarations.
274
- */
275
-
276
- function declarations() {
277
- const decls = [];
278
-
279
- if ( ! open() ) {
280
- return error( "missing '{'" );
281
- }
282
- comments( decls );
283
-
284
- // declarations.
285
- let decl;
286
- // eslint-disable-next-line no-cond-assign
287
- while ( ( decl = declaration() ) ) {
288
- if ( decl !== false ) {
289
- decls.push( decl );
290
- comments( decls );
291
- }
292
- }
293
-
294
- if ( ! close() ) {
295
- return error( "missing '}'" );
296
- }
297
- return decls;
298
- }
299
-
300
- /**
301
- * Parse keyframe.
302
- */
303
-
304
- function keyframe() {
305
- let m;
306
- const vals = [];
307
- const pos = position();
308
-
309
- // eslint-disable-next-line no-cond-assign
310
- while ( ( m = match( /^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/ ) ) ) {
311
- vals.push( m[ 1 ] );
312
- match( /^,\s*/ );
313
- }
314
-
315
- if ( ! vals.length ) {
316
- return;
317
- }
318
-
319
- return pos( {
320
- type: 'keyframe',
321
- values: vals,
322
- declarations: declarations(),
323
- } );
324
- }
325
-
326
- /**
327
- * Parse keyframes.
328
- */
329
-
330
- function atkeyframes() {
331
- const pos = position();
332
- let m = match( /^@([-\w]+)?keyframes\s*/ );
333
-
334
- if ( ! m ) {
335
- return;
336
- }
337
- const vendor = m[ 1 ];
338
-
339
- // identifier
340
- m = match( /^([-\w]+)\s*/ );
341
- if ( ! m ) {
342
- return error( '@keyframes missing name' );
343
- }
344
- const name = m[ 1 ];
345
-
346
- if ( ! open() ) {
347
- return error( "@keyframes missing '{'" );
348
- }
349
-
350
- let frame;
351
- let frames = comments();
352
- // eslint-disable-next-line no-cond-assign
353
- while ( ( frame = keyframe() ) ) {
354
- frames.push( frame );
355
- frames = frames.concat( comments() );
356
- }
357
-
358
- if ( ! close() ) {
359
- return error( "@keyframes missing '}'" );
360
- }
361
-
362
- return pos( {
363
- type: 'keyframes',
364
- name,
365
- vendor,
366
- keyframes: frames,
367
- } );
368
- }
369
-
370
- /**
371
- * Parse supports.
372
- */
373
-
374
- function atsupports() {
375
- const pos = position();
376
- const m = match( /^@supports *([^{]+)/ );
377
-
378
- if ( ! m ) {
379
- return;
380
- }
381
- const supports = trim( m[ 1 ] );
382
-
383
- if ( ! open() ) {
384
- return error( "@supports missing '{'" );
385
- }
386
-
387
- const style = comments().concat( rules() );
388
-
389
- if ( ! close() ) {
390
- return error( "@supports missing '}'" );
391
- }
392
-
393
- return pos( {
394
- type: 'supports',
395
- supports,
396
- rules: style,
397
- } );
398
- }
399
-
400
- /**
401
- * Parse host.
402
- */
403
-
404
- function athost() {
405
- const pos = position();
406
- const m = match( /^@host\s*/ );
407
-
408
- if ( ! m ) {
409
- return;
410
- }
411
-
412
- if ( ! open() ) {
413
- return error( "@host missing '{'" );
414
- }
415
-
416
- const style = comments().concat( rules() );
417
-
418
- if ( ! close() ) {
419
- return error( "@host missing '}'" );
420
- }
421
-
422
- return pos( {
423
- type: 'host',
424
- rules: style,
425
- } );
426
- }
427
-
428
- /**
429
- * Parse media.
430
- */
431
-
432
- function atmedia() {
433
- const pos = position();
434
- const m = match( /^@media *([^{]+)/ );
435
-
436
- if ( ! m ) {
437
- return;
438
- }
439
- const media = trim( m[ 1 ] );
440
-
441
- if ( ! open() ) {
442
- return error( "@media missing '{'" );
443
- }
444
-
445
- const style = comments().concat( rules() );
446
-
447
- if ( ! close() ) {
448
- return error( "@media missing '}'" );
449
- }
450
-
451
- return pos( {
452
- type: 'media',
453
- media,
454
- rules: style,
455
- } );
456
- }
457
-
458
- /**
459
- * Parse container.
460
- */
461
-
462
- function atcontainer() {
463
- const pos = position();
464
- const m = match( /^@container *([^{]+)/ );
465
-
466
- if ( ! m ) {
467
- return;
468
- }
469
- const container = trim( m[ 1 ] );
470
-
471
- if ( ! open() ) {
472
- return error( "@container missing '{'" );
473
- }
474
-
475
- const style = comments().concat( rules() );
476
-
477
- if ( ! close() ) {
478
- return error( "@container missing '}'" );
479
- }
480
-
481
- return pos( {
482
- type: 'container',
483
- container,
484
- rules: style,
485
- } );
486
- }
487
-
488
- /**
489
- * Parse custom-media.
490
- */
491
-
492
- function atcustommedia() {
493
- const pos = position();
494
- const m = match( /^@custom-media\s+(--[^\s]+)\s*([^{;]+);/ );
495
- if ( ! m ) {
496
- return;
497
- }
498
-
499
- return pos( {
500
- type: 'custom-media',
501
- name: trim( m[ 1 ] ),
502
- media: trim( m[ 2 ] ),
503
- } );
504
- }
505
-
506
- /**
507
- * Parse paged media.
508
- */
509
-
510
- function atpage() {
511
- const pos = position();
512
- const m = match( /^@page */ );
513
- if ( ! m ) {
514
- return;
515
- }
516
-
517
- const sel = selector() || [];
518
-
519
- if ( ! open() ) {
520
- return error( "@page missing '{'" );
521
- }
522
- let decls = comments();
523
-
524
- // declarations.
525
- let decl;
526
- // eslint-disable-next-line no-cond-assign
527
- while ( ( decl = declaration() ) ) {
528
- decls.push( decl );
529
- decls = decls.concat( comments() );
530
- }
531
-
532
- if ( ! close() ) {
533
- return error( "@page missing '}'" );
534
- }
535
-
536
- return pos( {
537
- type: 'page',
538
- selectors: sel,
539
- declarations: decls,
540
- } );
541
- }
542
-
543
- /**
544
- * Parse document.
545
- */
546
-
547
- function atdocument() {
548
- const pos = position();
549
- const m = match( /^@([-\w]+)?document *([^{]+)/ );
550
- if ( ! m ) {
551
- return;
552
- }
553
-
554
- const vendor = trim( m[ 1 ] );
555
- const doc = trim( m[ 2 ] );
556
-
557
- if ( ! open() ) {
558
- return error( "@document missing '{'" );
559
- }
560
-
561
- const style = comments().concat( rules() );
562
-
563
- if ( ! close() ) {
564
- return error( "@document missing '}'" );
565
- }
566
-
567
- return pos( {
568
- type: 'document',
569
- document: doc,
570
- vendor,
571
- rules: style,
572
- } );
573
- }
574
-
575
- /**
576
- * Parse font-face.
577
- */
578
-
579
- function atfontface() {
580
- const pos = position();
581
- const m = match( /^@font-face\s*/ );
582
- if ( ! m ) {
583
- return;
584
- }
585
-
586
- if ( ! open() ) {
587
- return error( "@font-face missing '{'" );
588
- }
589
- let decls = comments();
590
-
591
- // declarations.
592
- let decl;
593
- // eslint-disable-next-line no-cond-assign
594
- while ( ( decl = declaration() ) ) {
595
- decls.push( decl );
596
- decls = decls.concat( comments() );
597
- }
598
-
599
- if ( ! close() ) {
600
- return error( "@font-face missing '}'" );
601
- }
602
-
603
- return pos( {
604
- type: 'font-face',
605
- declarations: decls,
606
- } );
607
- }
608
-
609
- /**
610
- * Parse import
611
- */
612
-
613
- const atimport = _compileAtrule( 'import' );
614
-
615
- /**
616
- * Parse charset
617
- */
618
-
619
- const atcharset = _compileAtrule( 'charset' );
620
-
621
- /**
622
- * Parse namespace
623
- */
624
-
625
- const atnamespace = _compileAtrule( 'namespace' );
626
-
627
- /**
628
- * Parse non-block at-rules
629
- */
630
-
631
- function _compileAtrule( name ) {
632
- const re = new RegExp( '^@' + name + '\\s*([^;]+);' );
633
- return function () {
634
- const pos = position();
635
- const m = match( re );
636
- if ( ! m ) {
637
- return;
638
- }
639
- const ret = { type: name };
640
- ret[ name ] = m[ 1 ].trim();
641
- return pos( ret );
642
- };
643
- }
644
-
645
- /**
646
- * Parse at rule.
647
- */
648
-
649
- function atrule() {
650
- if ( css[ 0 ] !== '@' ) {
651
- return;
652
- }
653
-
654
- return (
655
- atkeyframes() ||
656
- atmedia() ||
657
- atcontainer() ||
658
- atcustommedia() ||
659
- atsupports() ||
660
- atimport() ||
661
- atcharset() ||
662
- atnamespace() ||
663
- atdocument() ||
664
- atpage() ||
665
- athost() ||
666
- atfontface()
667
- );
668
- }
669
-
670
- /**
671
- * Parse rule.
672
- */
673
-
674
- function rule() {
675
- const pos = position();
676
- const sel = selector();
677
-
678
- if ( ! sel ) {
679
- return error( 'selector missing' );
680
- }
681
- comments();
682
-
683
- return pos( {
684
- type: 'rule',
685
- selectors: sel,
686
- declarations: declarations(),
687
- } );
688
- }
689
-
690
- return addParent( stylesheet() );
691
- }
692
-
693
- /**
694
- * Trim `str`.
695
- */
696
-
697
- function trim( str ) {
698
- return str ? str.replace( /^\s+|\s+$/g, '' ) : '';
699
- }
700
-
701
- /**
702
- * Adds non-enumerable parent node reference to each node.
703
- */
704
-
705
- function addParent( obj, parent ) {
706
- const isNode = obj && typeof obj.type === 'string';
707
- const childParent = isNode ? obj : parent;
708
-
709
- for ( const k in obj ) {
710
- const value = obj[ k ];
711
- if ( Array.isArray( value ) ) {
712
- value.forEach( function ( v ) {
713
- addParent( v, childParent );
714
- } );
715
- } else if ( value && typeof value === 'object' ) {
716
- addParent( value, childParent );
717
- }
718
- }
719
-
720
- if ( isNode ) {
721
- Object.defineProperty( obj, 'parent', {
722
- configurable: true,
723
- writable: true,
724
- enumerable: false,
725
- value: parent || null,
726
- } );
727
- }
728
-
729
- return obj;
730
- }
731
-
732
- /* eslint-enable @wordpress/no-unused-vars-before-return */