less.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050
  1. const MODES = (hljs) => {
  2. return {
  3. IMPORTANT: {
  4. scope: 'meta',
  5. begin: '!important'
  6. },
  7. BLOCK_COMMENT: hljs.C_BLOCK_COMMENT_MODE,
  8. HEXCOLOR: {
  9. scope: 'number',
  10. begin: /#(([0-9a-fA-F]{3,4})|(([0-9a-fA-F]{2}){3,4}))\b/
  11. },
  12. FUNCTION_DISPATCH: {
  13. className: "built_in",
  14. begin: /[\w-]+(?=\()/
  15. },
  16. ATTRIBUTE_SELECTOR_MODE: {
  17. scope: 'selector-attr',
  18. begin: /\[/,
  19. end: /\]/,
  20. illegal: '$',
  21. contains: [
  22. hljs.APOS_STRING_MODE,
  23. hljs.QUOTE_STRING_MODE
  24. ]
  25. },
  26. CSS_NUMBER_MODE: {
  27. scope: 'number',
  28. begin: hljs.NUMBER_RE + '(' +
  29. '%|em|ex|ch|rem' +
  30. '|vw|vh|vmin|vmax' +
  31. '|cm|mm|in|pt|pc|px' +
  32. '|deg|grad|rad|turn' +
  33. '|s|ms' +
  34. '|Hz|kHz' +
  35. '|dpi|dpcm|dppx' +
  36. ')?',
  37. relevance: 0
  38. },
  39. CSS_VARIABLE: {
  40. className: "attr",
  41. begin: /--[A-Za-z_][A-Za-z0-9_-]*/
  42. }
  43. };
  44. };
  45. const HTML_TAGS = [
  46. 'a',
  47. 'abbr',
  48. 'address',
  49. 'article',
  50. 'aside',
  51. 'audio',
  52. 'b',
  53. 'blockquote',
  54. 'body',
  55. 'button',
  56. 'canvas',
  57. 'caption',
  58. 'cite',
  59. 'code',
  60. 'dd',
  61. 'del',
  62. 'details',
  63. 'dfn',
  64. 'div',
  65. 'dl',
  66. 'dt',
  67. 'em',
  68. 'fieldset',
  69. 'figcaption',
  70. 'figure',
  71. 'footer',
  72. 'form',
  73. 'h1',
  74. 'h2',
  75. 'h3',
  76. 'h4',
  77. 'h5',
  78. 'h6',
  79. 'header',
  80. 'hgroup',
  81. 'html',
  82. 'i',
  83. 'iframe',
  84. 'img',
  85. 'input',
  86. 'ins',
  87. 'kbd',
  88. 'label',
  89. 'legend',
  90. 'li',
  91. 'main',
  92. 'mark',
  93. 'menu',
  94. 'nav',
  95. 'object',
  96. 'ol',
  97. 'optgroup',
  98. 'option',
  99. 'p',
  100. 'picture',
  101. 'q',
  102. 'quote',
  103. 'samp',
  104. 'section',
  105. 'select',
  106. 'source',
  107. 'span',
  108. 'strong',
  109. 'summary',
  110. 'sup',
  111. 'table',
  112. 'tbody',
  113. 'td',
  114. 'textarea',
  115. 'tfoot',
  116. 'th',
  117. 'thead',
  118. 'time',
  119. 'tr',
  120. 'ul',
  121. 'var',
  122. 'video'
  123. ];
  124. const SVG_TAGS = [
  125. 'defs',
  126. 'g',
  127. 'marker',
  128. 'mask',
  129. 'pattern',
  130. 'svg',
  131. 'switch',
  132. 'symbol',
  133. 'feBlend',
  134. 'feColorMatrix',
  135. 'feComponentTransfer',
  136. 'feComposite',
  137. 'feConvolveMatrix',
  138. 'feDiffuseLighting',
  139. 'feDisplacementMap',
  140. 'feFlood',
  141. 'feGaussianBlur',
  142. 'feImage',
  143. 'feMerge',
  144. 'feMorphology',
  145. 'feOffset',
  146. 'feSpecularLighting',
  147. 'feTile',
  148. 'feTurbulence',
  149. 'linearGradient',
  150. 'radialGradient',
  151. 'stop',
  152. 'circle',
  153. 'ellipse',
  154. 'image',
  155. 'line',
  156. 'path',
  157. 'polygon',
  158. 'polyline',
  159. 'rect',
  160. 'text',
  161. 'use',
  162. 'textPath',
  163. 'tspan',
  164. 'foreignObject',
  165. 'clipPath'
  166. ];
  167. const TAGS = [
  168. ...HTML_TAGS,
  169. ...SVG_TAGS,
  170. ];
  171. // Sorting, then reversing makes sure longer attributes/elements like
  172. // `font-weight` are matched fully instead of getting false positives on say `font`
  173. const MEDIA_FEATURES = [
  174. 'any-hover',
  175. 'any-pointer',
  176. 'aspect-ratio',
  177. 'color',
  178. 'color-gamut',
  179. 'color-index',
  180. 'device-aspect-ratio',
  181. 'device-height',
  182. 'device-width',
  183. 'display-mode',
  184. 'forced-colors',
  185. 'grid',
  186. 'height',
  187. 'hover',
  188. 'inverted-colors',
  189. 'monochrome',
  190. 'orientation',
  191. 'overflow-block',
  192. 'overflow-inline',
  193. 'pointer',
  194. 'prefers-color-scheme',
  195. 'prefers-contrast',
  196. 'prefers-reduced-motion',
  197. 'prefers-reduced-transparency',
  198. 'resolution',
  199. 'scan',
  200. 'scripting',
  201. 'update',
  202. 'width',
  203. // TODO: find a better solution?
  204. 'min-width',
  205. 'max-width',
  206. 'min-height',
  207. 'max-height'
  208. ].sort().reverse();
  209. // https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-classes
  210. const PSEUDO_CLASSES = [
  211. 'active',
  212. 'any-link',
  213. 'blank',
  214. 'checked',
  215. 'current',
  216. 'default',
  217. 'defined',
  218. 'dir', // dir()
  219. 'disabled',
  220. 'drop',
  221. 'empty',
  222. 'enabled',
  223. 'first',
  224. 'first-child',
  225. 'first-of-type',
  226. 'fullscreen',
  227. 'future',
  228. 'focus',
  229. 'focus-visible',
  230. 'focus-within',
  231. 'has', // has()
  232. 'host', // host or host()
  233. 'host-context', // host-context()
  234. 'hover',
  235. 'indeterminate',
  236. 'in-range',
  237. 'invalid',
  238. 'is', // is()
  239. 'lang', // lang()
  240. 'last-child',
  241. 'last-of-type',
  242. 'left',
  243. 'link',
  244. 'local-link',
  245. 'not', // not()
  246. 'nth-child', // nth-child()
  247. 'nth-col', // nth-col()
  248. 'nth-last-child', // nth-last-child()
  249. 'nth-last-col', // nth-last-col()
  250. 'nth-last-of-type', //nth-last-of-type()
  251. 'nth-of-type', //nth-of-type()
  252. 'only-child',
  253. 'only-of-type',
  254. 'optional',
  255. 'out-of-range',
  256. 'past',
  257. 'placeholder-shown',
  258. 'read-only',
  259. 'read-write',
  260. 'required',
  261. 'right',
  262. 'root',
  263. 'scope',
  264. 'target',
  265. 'target-within',
  266. 'user-invalid',
  267. 'valid',
  268. 'visited',
  269. 'where' // where()
  270. ].sort().reverse();
  271. // https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-elements
  272. const PSEUDO_ELEMENTS = [
  273. 'after',
  274. 'backdrop',
  275. 'before',
  276. 'cue',
  277. 'cue-region',
  278. 'first-letter',
  279. 'first-line',
  280. 'grammar-error',
  281. 'marker',
  282. 'part',
  283. 'placeholder',
  284. 'selection',
  285. 'slotted',
  286. 'spelling-error'
  287. ].sort().reverse();
  288. const ATTRIBUTES = [
  289. 'accent-color',
  290. 'align-content',
  291. 'align-items',
  292. 'align-self',
  293. 'alignment-baseline',
  294. 'all',
  295. 'anchor-name',
  296. 'animation',
  297. 'animation-composition',
  298. 'animation-delay',
  299. 'animation-direction',
  300. 'animation-duration',
  301. 'animation-fill-mode',
  302. 'animation-iteration-count',
  303. 'animation-name',
  304. 'animation-play-state',
  305. 'animation-range',
  306. 'animation-range-end',
  307. 'animation-range-start',
  308. 'animation-timeline',
  309. 'animation-timing-function',
  310. 'appearance',
  311. 'aspect-ratio',
  312. 'backdrop-filter',
  313. 'backface-visibility',
  314. 'background',
  315. 'background-attachment',
  316. 'background-blend-mode',
  317. 'background-clip',
  318. 'background-color',
  319. 'background-image',
  320. 'background-origin',
  321. 'background-position',
  322. 'background-position-x',
  323. 'background-position-y',
  324. 'background-repeat',
  325. 'background-size',
  326. 'baseline-shift',
  327. 'block-size',
  328. 'border',
  329. 'border-block',
  330. 'border-block-color',
  331. 'border-block-end',
  332. 'border-block-end-color',
  333. 'border-block-end-style',
  334. 'border-block-end-width',
  335. 'border-block-start',
  336. 'border-block-start-color',
  337. 'border-block-start-style',
  338. 'border-block-start-width',
  339. 'border-block-style',
  340. 'border-block-width',
  341. 'border-bottom',
  342. 'border-bottom-color',
  343. 'border-bottom-left-radius',
  344. 'border-bottom-right-radius',
  345. 'border-bottom-style',
  346. 'border-bottom-width',
  347. 'border-collapse',
  348. 'border-color',
  349. 'border-end-end-radius',
  350. 'border-end-start-radius',
  351. 'border-image',
  352. 'border-image-outset',
  353. 'border-image-repeat',
  354. 'border-image-slice',
  355. 'border-image-source',
  356. 'border-image-width',
  357. 'border-inline',
  358. 'border-inline-color',
  359. 'border-inline-end',
  360. 'border-inline-end-color',
  361. 'border-inline-end-style',
  362. 'border-inline-end-width',
  363. 'border-inline-start',
  364. 'border-inline-start-color',
  365. 'border-inline-start-style',
  366. 'border-inline-start-width',
  367. 'border-inline-style',
  368. 'border-inline-width',
  369. 'border-left',
  370. 'border-left-color',
  371. 'border-left-style',
  372. 'border-left-width',
  373. 'border-radius',
  374. 'border-right',
  375. 'border-right-color',
  376. 'border-right-style',
  377. 'border-right-width',
  378. 'border-spacing',
  379. 'border-start-end-radius',
  380. 'border-start-start-radius',
  381. 'border-style',
  382. 'border-top',
  383. 'border-top-color',
  384. 'border-top-left-radius',
  385. 'border-top-right-radius',
  386. 'border-top-style',
  387. 'border-top-width',
  388. 'border-width',
  389. 'bottom',
  390. 'box-align',
  391. 'box-decoration-break',
  392. 'box-direction',
  393. 'box-flex',
  394. 'box-flex-group',
  395. 'box-lines',
  396. 'box-ordinal-group',
  397. 'box-orient',
  398. 'box-pack',
  399. 'box-shadow',
  400. 'box-sizing',
  401. 'break-after',
  402. 'break-before',
  403. 'break-inside',
  404. 'caption-side',
  405. 'caret-color',
  406. 'clear',
  407. 'clip',
  408. 'clip-path',
  409. 'clip-rule',
  410. 'color',
  411. 'color-interpolation',
  412. 'color-interpolation-filters',
  413. 'color-profile',
  414. 'color-rendering',
  415. 'color-scheme',
  416. 'column-count',
  417. 'column-fill',
  418. 'column-gap',
  419. 'column-rule',
  420. 'column-rule-color',
  421. 'column-rule-style',
  422. 'column-rule-width',
  423. 'column-span',
  424. 'column-width',
  425. 'columns',
  426. 'contain',
  427. 'contain-intrinsic-block-size',
  428. 'contain-intrinsic-height',
  429. 'contain-intrinsic-inline-size',
  430. 'contain-intrinsic-size',
  431. 'contain-intrinsic-width',
  432. 'container',
  433. 'container-name',
  434. 'container-type',
  435. 'content',
  436. 'content-visibility',
  437. 'counter-increment',
  438. 'counter-reset',
  439. 'counter-set',
  440. 'cue',
  441. 'cue-after',
  442. 'cue-before',
  443. 'cursor',
  444. 'cx',
  445. 'cy',
  446. 'direction',
  447. 'display',
  448. 'dominant-baseline',
  449. 'empty-cells',
  450. 'enable-background',
  451. 'field-sizing',
  452. 'fill',
  453. 'fill-opacity',
  454. 'fill-rule',
  455. 'filter',
  456. 'flex',
  457. 'flex-basis',
  458. 'flex-direction',
  459. 'flex-flow',
  460. 'flex-grow',
  461. 'flex-shrink',
  462. 'flex-wrap',
  463. 'float',
  464. 'flood-color',
  465. 'flood-opacity',
  466. 'flow',
  467. 'font',
  468. 'font-display',
  469. 'font-family',
  470. 'font-feature-settings',
  471. 'font-kerning',
  472. 'font-language-override',
  473. 'font-optical-sizing',
  474. 'font-palette',
  475. 'font-size',
  476. 'font-size-adjust',
  477. 'font-smooth',
  478. 'font-smoothing',
  479. 'font-stretch',
  480. 'font-style',
  481. 'font-synthesis',
  482. 'font-synthesis-position',
  483. 'font-synthesis-small-caps',
  484. 'font-synthesis-style',
  485. 'font-synthesis-weight',
  486. 'font-variant',
  487. 'font-variant-alternates',
  488. 'font-variant-caps',
  489. 'font-variant-east-asian',
  490. 'font-variant-emoji',
  491. 'font-variant-ligatures',
  492. 'font-variant-numeric',
  493. 'font-variant-position',
  494. 'font-variation-settings',
  495. 'font-weight',
  496. 'forced-color-adjust',
  497. 'gap',
  498. 'glyph-orientation-horizontal',
  499. 'glyph-orientation-vertical',
  500. 'grid',
  501. 'grid-area',
  502. 'grid-auto-columns',
  503. 'grid-auto-flow',
  504. 'grid-auto-rows',
  505. 'grid-column',
  506. 'grid-column-end',
  507. 'grid-column-start',
  508. 'grid-gap',
  509. 'grid-row',
  510. 'grid-row-end',
  511. 'grid-row-start',
  512. 'grid-template',
  513. 'grid-template-areas',
  514. 'grid-template-columns',
  515. 'grid-template-rows',
  516. 'hanging-punctuation',
  517. 'height',
  518. 'hyphenate-character',
  519. 'hyphenate-limit-chars',
  520. 'hyphens',
  521. 'icon',
  522. 'image-orientation',
  523. 'image-rendering',
  524. 'image-resolution',
  525. 'ime-mode',
  526. 'initial-letter',
  527. 'initial-letter-align',
  528. 'inline-size',
  529. 'inset',
  530. 'inset-area',
  531. 'inset-block',
  532. 'inset-block-end',
  533. 'inset-block-start',
  534. 'inset-inline',
  535. 'inset-inline-end',
  536. 'inset-inline-start',
  537. 'isolation',
  538. 'justify-content',
  539. 'justify-items',
  540. 'justify-self',
  541. 'kerning',
  542. 'left',
  543. 'letter-spacing',
  544. 'lighting-color',
  545. 'line-break',
  546. 'line-height',
  547. 'line-height-step',
  548. 'list-style',
  549. 'list-style-image',
  550. 'list-style-position',
  551. 'list-style-type',
  552. 'margin',
  553. 'margin-block',
  554. 'margin-block-end',
  555. 'margin-block-start',
  556. 'margin-bottom',
  557. 'margin-inline',
  558. 'margin-inline-end',
  559. 'margin-inline-start',
  560. 'margin-left',
  561. 'margin-right',
  562. 'margin-top',
  563. 'margin-trim',
  564. 'marker',
  565. 'marker-end',
  566. 'marker-mid',
  567. 'marker-start',
  568. 'marks',
  569. 'mask',
  570. 'mask-border',
  571. 'mask-border-mode',
  572. 'mask-border-outset',
  573. 'mask-border-repeat',
  574. 'mask-border-slice',
  575. 'mask-border-source',
  576. 'mask-border-width',
  577. 'mask-clip',
  578. 'mask-composite',
  579. 'mask-image',
  580. 'mask-mode',
  581. 'mask-origin',
  582. 'mask-position',
  583. 'mask-repeat',
  584. 'mask-size',
  585. 'mask-type',
  586. 'masonry-auto-flow',
  587. 'math-depth',
  588. 'math-shift',
  589. 'math-style',
  590. 'max-block-size',
  591. 'max-height',
  592. 'max-inline-size',
  593. 'max-width',
  594. 'min-block-size',
  595. 'min-height',
  596. 'min-inline-size',
  597. 'min-width',
  598. 'mix-blend-mode',
  599. 'nav-down',
  600. 'nav-index',
  601. 'nav-left',
  602. 'nav-right',
  603. 'nav-up',
  604. 'none',
  605. 'normal',
  606. 'object-fit',
  607. 'object-position',
  608. 'offset',
  609. 'offset-anchor',
  610. 'offset-distance',
  611. 'offset-path',
  612. 'offset-position',
  613. 'offset-rotate',
  614. 'opacity',
  615. 'order',
  616. 'orphans',
  617. 'outline',
  618. 'outline-color',
  619. 'outline-offset',
  620. 'outline-style',
  621. 'outline-width',
  622. 'overflow',
  623. 'overflow-anchor',
  624. 'overflow-block',
  625. 'overflow-clip-margin',
  626. 'overflow-inline',
  627. 'overflow-wrap',
  628. 'overflow-x',
  629. 'overflow-y',
  630. 'overlay',
  631. 'overscroll-behavior',
  632. 'overscroll-behavior-block',
  633. 'overscroll-behavior-inline',
  634. 'overscroll-behavior-x',
  635. 'overscroll-behavior-y',
  636. 'padding',
  637. 'padding-block',
  638. 'padding-block-end',
  639. 'padding-block-start',
  640. 'padding-bottom',
  641. 'padding-inline',
  642. 'padding-inline-end',
  643. 'padding-inline-start',
  644. 'padding-left',
  645. 'padding-right',
  646. 'padding-top',
  647. 'page',
  648. 'page-break-after',
  649. 'page-break-before',
  650. 'page-break-inside',
  651. 'paint-order',
  652. 'pause',
  653. 'pause-after',
  654. 'pause-before',
  655. 'perspective',
  656. 'perspective-origin',
  657. 'place-content',
  658. 'place-items',
  659. 'place-self',
  660. 'pointer-events',
  661. 'position',
  662. 'position-anchor',
  663. 'position-visibility',
  664. 'print-color-adjust',
  665. 'quotes',
  666. 'r',
  667. 'resize',
  668. 'rest',
  669. 'rest-after',
  670. 'rest-before',
  671. 'right',
  672. 'rotate',
  673. 'row-gap',
  674. 'ruby-align',
  675. 'ruby-position',
  676. 'scale',
  677. 'scroll-behavior',
  678. 'scroll-margin',
  679. 'scroll-margin-block',
  680. 'scroll-margin-block-end',
  681. 'scroll-margin-block-start',
  682. 'scroll-margin-bottom',
  683. 'scroll-margin-inline',
  684. 'scroll-margin-inline-end',
  685. 'scroll-margin-inline-start',
  686. 'scroll-margin-left',
  687. 'scroll-margin-right',
  688. 'scroll-margin-top',
  689. 'scroll-padding',
  690. 'scroll-padding-block',
  691. 'scroll-padding-block-end',
  692. 'scroll-padding-block-start',
  693. 'scroll-padding-bottom',
  694. 'scroll-padding-inline',
  695. 'scroll-padding-inline-end',
  696. 'scroll-padding-inline-start',
  697. 'scroll-padding-left',
  698. 'scroll-padding-right',
  699. 'scroll-padding-top',
  700. 'scroll-snap-align',
  701. 'scroll-snap-stop',
  702. 'scroll-snap-type',
  703. 'scroll-timeline',
  704. 'scroll-timeline-axis',
  705. 'scroll-timeline-name',
  706. 'scrollbar-color',
  707. 'scrollbar-gutter',
  708. 'scrollbar-width',
  709. 'shape-image-threshold',
  710. 'shape-margin',
  711. 'shape-outside',
  712. 'shape-rendering',
  713. 'speak',
  714. 'speak-as',
  715. 'src', // @font-face
  716. 'stop-color',
  717. 'stop-opacity',
  718. 'stroke',
  719. 'stroke-dasharray',
  720. 'stroke-dashoffset',
  721. 'stroke-linecap',
  722. 'stroke-linejoin',
  723. 'stroke-miterlimit',
  724. 'stroke-opacity',
  725. 'stroke-width',
  726. 'tab-size',
  727. 'table-layout',
  728. 'text-align',
  729. 'text-align-all',
  730. 'text-align-last',
  731. 'text-anchor',
  732. 'text-combine-upright',
  733. 'text-decoration',
  734. 'text-decoration-color',
  735. 'text-decoration-line',
  736. 'text-decoration-skip',
  737. 'text-decoration-skip-ink',
  738. 'text-decoration-style',
  739. 'text-decoration-thickness',
  740. 'text-emphasis',
  741. 'text-emphasis-color',
  742. 'text-emphasis-position',
  743. 'text-emphasis-style',
  744. 'text-indent',
  745. 'text-justify',
  746. 'text-orientation',
  747. 'text-overflow',
  748. 'text-rendering',
  749. 'text-shadow',
  750. 'text-size-adjust',
  751. 'text-transform',
  752. 'text-underline-offset',
  753. 'text-underline-position',
  754. 'text-wrap',
  755. 'text-wrap-mode',
  756. 'text-wrap-style',
  757. 'timeline-scope',
  758. 'top',
  759. 'touch-action',
  760. 'transform',
  761. 'transform-box',
  762. 'transform-origin',
  763. 'transform-style',
  764. 'transition',
  765. 'transition-behavior',
  766. 'transition-delay',
  767. 'transition-duration',
  768. 'transition-property',
  769. 'transition-timing-function',
  770. 'translate',
  771. 'unicode-bidi',
  772. 'user-modify',
  773. 'user-select',
  774. 'vector-effect',
  775. 'vertical-align',
  776. 'view-timeline',
  777. 'view-timeline-axis',
  778. 'view-timeline-inset',
  779. 'view-timeline-name',
  780. 'view-transition-name',
  781. 'visibility',
  782. 'voice-balance',
  783. 'voice-duration',
  784. 'voice-family',
  785. 'voice-pitch',
  786. 'voice-range',
  787. 'voice-rate',
  788. 'voice-stress',
  789. 'voice-volume',
  790. 'white-space',
  791. 'white-space-collapse',
  792. 'widows',
  793. 'width',
  794. 'will-change',
  795. 'word-break',
  796. 'word-spacing',
  797. 'word-wrap',
  798. 'writing-mode',
  799. 'x',
  800. 'y',
  801. 'z-index',
  802. 'zoom'
  803. ].sort().reverse();
  804. // some grammars use them all as a single group
  805. const PSEUDO_SELECTORS = PSEUDO_CLASSES.concat(PSEUDO_ELEMENTS).sort().reverse();
  806. /*
  807. Language: Less
  808. Description: It's CSS, with just a little more.
  809. Author: Max Mikhailov <seven.phases.max@gmail.com>
  810. Website: http://lesscss.org
  811. Category: common, css, web
  812. */
  813. /** @type LanguageFn */
  814. function less(hljs) {
  815. const modes = MODES(hljs);
  816. const PSEUDO_SELECTORS$1 = PSEUDO_SELECTORS;
  817. const AT_MODIFIERS = "and or not only";
  818. const IDENT_RE = '[\\w-]+'; // yes, Less identifiers may begin with a digit
  819. const INTERP_IDENT_RE = '(' + IDENT_RE + '|@\\{' + IDENT_RE + '\\})';
  820. /* Generic Modes */
  821. const RULES = []; const VALUE_MODES = []; // forward def. for recursive modes
  822. const STRING_MODE = function(c) {
  823. return {
  824. // Less strings are not multiline (also include '~' for more consistent coloring of "escaped" strings)
  825. className: 'string',
  826. begin: '~?' + c + '.*?' + c
  827. };
  828. };
  829. const IDENT_MODE = function(name, begin, relevance) {
  830. return {
  831. className: name,
  832. begin: begin,
  833. relevance: relevance
  834. };
  835. };
  836. const AT_KEYWORDS = {
  837. $pattern: /[a-z-]+/,
  838. keyword: AT_MODIFIERS,
  839. attribute: MEDIA_FEATURES.join(" ")
  840. };
  841. const PARENS_MODE = {
  842. // used only to properly balance nested parens inside mixin call, def. arg list
  843. begin: '\\(',
  844. end: '\\)',
  845. contains: VALUE_MODES,
  846. keywords: AT_KEYWORDS,
  847. relevance: 0
  848. };
  849. // generic Less highlighter (used almost everywhere except selectors):
  850. VALUE_MODES.push(
  851. hljs.C_LINE_COMMENT_MODE,
  852. hljs.C_BLOCK_COMMENT_MODE,
  853. STRING_MODE("'"),
  854. STRING_MODE('"'),
  855. modes.CSS_NUMBER_MODE, // fixme: it does not include dot for numbers like .5em :(
  856. {
  857. begin: '(url|data-uri)\\(',
  858. starts: {
  859. className: 'string',
  860. end: '[\\)\\n]',
  861. excludeEnd: true
  862. }
  863. },
  864. modes.HEXCOLOR,
  865. PARENS_MODE,
  866. IDENT_MODE('variable', '@@?' + IDENT_RE, 10),
  867. IDENT_MODE('variable', '@\\{' + IDENT_RE + '\\}'),
  868. IDENT_MODE('built_in', '~?`[^`]*?`'), // inline javascript (or whatever host language) *multiline* string
  869. { // @media features (it’s here to not duplicate things in AT_RULE_MODE with extra PARENS_MODE overriding):
  870. className: 'attribute',
  871. begin: IDENT_RE + '\\s*:',
  872. end: ':',
  873. returnBegin: true,
  874. excludeEnd: true
  875. },
  876. modes.IMPORTANT,
  877. { beginKeywords: 'and not' },
  878. modes.FUNCTION_DISPATCH
  879. );
  880. const VALUE_WITH_RULESETS = VALUE_MODES.concat({
  881. begin: /\{/,
  882. end: /\}/,
  883. contains: RULES
  884. });
  885. const MIXIN_GUARD_MODE = {
  886. beginKeywords: 'when',
  887. endsWithParent: true,
  888. contains: [ { beginKeywords: 'and not' } ].concat(VALUE_MODES) // using this form to override VALUE’s 'function' match
  889. };
  890. /* Rule-Level Modes */
  891. const RULE_MODE = {
  892. begin: INTERP_IDENT_RE + '\\s*:',
  893. returnBegin: true,
  894. end: /[;}]/,
  895. relevance: 0,
  896. contains: [
  897. { begin: /-(webkit|moz|ms|o)-/ },
  898. modes.CSS_VARIABLE,
  899. {
  900. className: 'attribute',
  901. begin: '\\b(' + ATTRIBUTES.join('|') + ')\\b',
  902. end: /(?=:)/,
  903. starts: {
  904. endsWithParent: true,
  905. illegal: '[<=$]',
  906. relevance: 0,
  907. contains: VALUE_MODES
  908. }
  909. }
  910. ]
  911. };
  912. const AT_RULE_MODE = {
  913. className: 'keyword',
  914. begin: '@(import|media|charset|font-face|(-[a-z]+-)?keyframes|supports|document|namespace|page|viewport|host)\\b',
  915. starts: {
  916. end: '[;{}]',
  917. keywords: AT_KEYWORDS,
  918. returnEnd: true,
  919. contains: VALUE_MODES,
  920. relevance: 0
  921. }
  922. };
  923. // variable definitions and calls
  924. const VAR_RULE_MODE = {
  925. className: 'variable',
  926. variants: [
  927. // using more strict pattern for higher relevance to increase chances of Less detection.
  928. // this is *the only* Less specific statement used in most of the sources, so...
  929. // (we’ll still often loose to the css-parser unless there's '//' comment,
  930. // simply because 1 variable just can't beat 99 properties :)
  931. {
  932. begin: '@' + IDENT_RE + '\\s*:',
  933. relevance: 15
  934. },
  935. { begin: '@' + IDENT_RE }
  936. ],
  937. starts: {
  938. end: '[;}]',
  939. returnEnd: true,
  940. contains: VALUE_WITH_RULESETS
  941. }
  942. };
  943. const SELECTOR_MODE = {
  944. // first parse unambiguous selectors (i.e. those not starting with tag)
  945. // then fall into the scary lookahead-discriminator variant.
  946. // this mode also handles mixin definitions and calls
  947. variants: [
  948. {
  949. begin: '[\\.#:&\\[>]',
  950. end: '[;{}]' // mixin calls end with ';'
  951. },
  952. {
  953. begin: INTERP_IDENT_RE,
  954. end: /\{/
  955. }
  956. ],
  957. returnBegin: true,
  958. returnEnd: true,
  959. illegal: '[<=\'$"]',
  960. relevance: 0,
  961. contains: [
  962. hljs.C_LINE_COMMENT_MODE,
  963. hljs.C_BLOCK_COMMENT_MODE,
  964. MIXIN_GUARD_MODE,
  965. IDENT_MODE('keyword', 'all\\b'),
  966. IDENT_MODE('variable', '@\\{' + IDENT_RE + '\\}'), // otherwise it’s identified as tag
  967. {
  968. begin: '\\b(' + TAGS.join('|') + ')\\b',
  969. className: 'selector-tag'
  970. },
  971. modes.CSS_NUMBER_MODE,
  972. IDENT_MODE('selector-tag', INTERP_IDENT_RE, 0),
  973. IDENT_MODE('selector-id', '#' + INTERP_IDENT_RE),
  974. IDENT_MODE('selector-class', '\\.' + INTERP_IDENT_RE, 0),
  975. IDENT_MODE('selector-tag', '&', 0),
  976. modes.ATTRIBUTE_SELECTOR_MODE,
  977. {
  978. className: 'selector-pseudo',
  979. begin: ':(' + PSEUDO_CLASSES.join('|') + ')'
  980. },
  981. {
  982. className: 'selector-pseudo',
  983. begin: ':(:)?(' + PSEUDO_ELEMENTS.join('|') + ')'
  984. },
  985. {
  986. begin: /\(/,
  987. end: /\)/,
  988. relevance: 0,
  989. contains: VALUE_WITH_RULESETS
  990. }, // argument list of parametric mixins
  991. { begin: '!important' }, // eat !important after mixin call or it will be colored as tag
  992. modes.FUNCTION_DISPATCH
  993. ]
  994. };
  995. const PSEUDO_SELECTOR_MODE = {
  996. begin: IDENT_RE + ':(:)?' + `(${PSEUDO_SELECTORS$1.join('|')})`,
  997. returnBegin: true,
  998. contains: [ SELECTOR_MODE ]
  999. };
  1000. RULES.push(
  1001. hljs.C_LINE_COMMENT_MODE,
  1002. hljs.C_BLOCK_COMMENT_MODE,
  1003. AT_RULE_MODE,
  1004. VAR_RULE_MODE,
  1005. PSEUDO_SELECTOR_MODE,
  1006. RULE_MODE,
  1007. SELECTOR_MODE,
  1008. MIXIN_GUARD_MODE,
  1009. modes.FUNCTION_DISPATCH
  1010. );
  1011. return {
  1012. name: 'Less',
  1013. case_insensitive: true,
  1014. illegal: '[=>\'/<($"]',
  1015. contains: RULES
  1016. };
  1017. }
  1018. export { less as default };