仲裁视频会议H5

index.js 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. 'use strict';
  2. const charset = 'charset';
  3. // eslint-disable-next-line no-control-regex
  4. const nonAscii = /[^\x00-\x7F]/;
  5. /**
  6. * @typedef {{add?: boolean}} Options
  7. */
  8. /**
  9. * @type {import('postcss').PluginCreator<Options>}
  10. * @param {Options} opts
  11. * @return {import('postcss').Plugin}
  12. */
  13. function pluginCreator(opts = {}) {
  14. return {
  15. postcssPlugin: 'postcss-normalize-' + charset,
  16. OnceExit(css, { AtRule }) {
  17. /** @type {import('postcss').AtRule | undefined} */
  18. let charsetRule;
  19. /** @type {import('postcss').Node | undefined} */
  20. let nonAsciiNode;
  21. css.walk((node) => {
  22. if (node.type === 'atrule' && node.name === charset) {
  23. if (!charsetRule) {
  24. charsetRule = node;
  25. }
  26. node.remove();
  27. } else if (
  28. !nonAsciiNode &&
  29. node.parent === css &&
  30. nonAscii.test(node.toString())
  31. ) {
  32. nonAsciiNode = node;
  33. }
  34. });
  35. if (nonAsciiNode) {
  36. if (!charsetRule && opts.add !== false) {
  37. charsetRule = new AtRule({
  38. name: charset,
  39. params: '"utf-8"',
  40. });
  41. }
  42. if (charsetRule) {
  43. charsetRule.source = nonAsciiNode.source;
  44. css.prepend(charsetRule);
  45. }
  46. }
  47. },
  48. };
  49. }
  50. pluginCreator.postcss = true;
  51. module.exports = pluginCreator;