add initial marp implementation with sample content and build configuration
This commit is contained in:
51
node_modules/@marp-team/marpit/lib/postcss/import/hoisting.js
generated
vendored
Normal file
51
node_modules/@marp-team/marpit/lib/postcss/import/hoisting.js
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.importHoisting = exports.default = void 0;
|
||||
var _postcss_plugin = _interopRequireDefault(require("../../helpers/postcss_plugin"));
|
||||
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
||||
/** @module */
|
||||
|
||||
/**
|
||||
* Marpit PostCSS import hoisting plugin.
|
||||
*
|
||||
* Hoist `@charset` and `@import` at-rule to the beginning of CSS. Marpit is
|
||||
* manipulating CSS with many PostCSS plugins, so sometimes a few at-rules
|
||||
* cannot keep specification.
|
||||
*
|
||||
* This plugin takes care of hoisting for invalid at-rules.
|
||||
*
|
||||
* @function importHoisting
|
||||
*/
|
||||
const importHoisting = exports.importHoisting = (0, _postcss_plugin.default)('marpit-postcss-import-hoisting', () => css => {
|
||||
const hoisted = {
|
||||
charset: undefined,
|
||||
imports: []
|
||||
};
|
||||
css.walkAtRules(rule => {
|
||||
if (rule.name === 'charset') {
|
||||
rule.remove();
|
||||
if (!hoisted.charset) hoisted.charset = rule;
|
||||
} else if (rule.name === 'import') {
|
||||
hoisted.imports.push(rule.remove());
|
||||
}
|
||||
});
|
||||
const {
|
||||
first
|
||||
} = css
|
||||
|
||||
// Hoist at-rules
|
||||
;
|
||||
[hoisted.charset, ...hoisted.imports].filter(r => r).forEach((rule, idx) => {
|
||||
// Strip whitespace from the beginning of first at-rule
|
||||
const prependRule = idx === 0 ? rule.clone({
|
||||
raws: {
|
||||
before: undefined
|
||||
}
|
||||
}) : rule;
|
||||
first.before(prependRule);
|
||||
});
|
||||
});
|
||||
var _default = exports.default = importHoisting;
|
||||
80
node_modules/@marp-team/marpit/lib/postcss/import/parse.js
generated
vendored
Normal file
80
node_modules/@marp-team/marpit/lib/postcss/import/parse.js
generated
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.importParse = exports.default = void 0;
|
||||
var _postcss_plugin = _interopRequireDefault(require("../../helpers/postcss_plugin"));
|
||||
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
||||
/** @module */
|
||||
|
||||
/**
|
||||
* @typedef {object} ImportMeta
|
||||
* @prop {AtRule} node The at-rule node parsed by PostCSS.
|
||||
* @prop {string} value The specified value.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Marpit PostCSS import parse plugin.
|
||||
*
|
||||
* Parse `@import` and `@import-theme` rules that specify a plain string.
|
||||
*
|
||||
* The `@import` rule for Marpit theme follows CSS spec. It must precede all
|
||||
* other statements. (excepted `@charset`)
|
||||
*
|
||||
* When you are using CSS preprocessors like Sass, `@import` would resolve path
|
||||
* in compiling and would be lost definition. So you can use `@import-theme`
|
||||
* rule alternatively.
|
||||
*
|
||||
* A specification of `@import-theme` has a bit different from `@import`. You
|
||||
* can place `@import-theme` rule at any in the CSS root, and the content of
|
||||
* imported theme will always append to the beginning of CSS.
|
||||
*
|
||||
* @function importParse
|
||||
*/
|
||||
const importParse = exports.importParse = (0, _postcss_plugin.default)('marpit-postcss-import-parse', () => (css, {
|
||||
result
|
||||
}) => {
|
||||
const imports = {
|
||||
import: [],
|
||||
importTheme: []
|
||||
};
|
||||
let allowImport = true;
|
||||
css.walk(node => {
|
||||
if (node.type === 'atrule') {
|
||||
const push = target => {
|
||||
const [quote] = node.params;
|
||||
if (quote !== '"' && quote !== "'") return;
|
||||
const splitedValue = node.params.slice(1).split(quote);
|
||||
let value = '';
|
||||
splitedValue.every(v => {
|
||||
if (v.endsWith('\\')) {
|
||||
value = `${value}${v.slice(0, -1)}${quote}`;
|
||||
return true;
|
||||
}
|
||||
value = `${value}${v}`;
|
||||
return false;
|
||||
});
|
||||
node.marpitImportParse = value;
|
||||
target.push({
|
||||
node,
|
||||
value
|
||||
});
|
||||
};
|
||||
if (allowImport) {
|
||||
if (node.name === 'import') {
|
||||
push(imports.import);
|
||||
} else if (node.name !== 'charset') {
|
||||
allowImport = false;
|
||||
}
|
||||
}
|
||||
if (node.name === 'import-theme' && node.parent.type === 'root') {
|
||||
push(imports.importTheme);
|
||||
}
|
||||
} else if (node.type !== 'comment') {
|
||||
allowImport = false;
|
||||
}
|
||||
});
|
||||
result.marpitImport = [...imports.importTheme, ...imports.import];
|
||||
});
|
||||
var _default = exports.default = importParse;
|
||||
48
node_modules/@marp-team/marpit/lib/postcss/import/replace.js
generated
vendored
Normal file
48
node_modules/@marp-team/marpit/lib/postcss/import/replace.js
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.importReplace = exports.default = void 0;
|
||||
var _postcss_plugin = _interopRequireDefault(require("../../helpers/postcss_plugin"));
|
||||
var _parse = _interopRequireDefault(require("./parse"));
|
||||
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
||||
/** @module */
|
||||
|
||||
/**
|
||||
* Marpit PostCSS import replace plugin.
|
||||
*
|
||||
* Replace parsed `@import` / `@import-theme` rules.
|
||||
*
|
||||
* Please see {@link module:postcss/import/parse} about the specification of
|
||||
* each syntax.
|
||||
*
|
||||
* @function importReplace
|
||||
* @param {ThemeSet} themeSet ThemeSet instance.
|
||||
*/
|
||||
const importReplace = (themeSet, importedThemes = []) => (0, _postcss_plugin.default)('marpit-postcss-import-replace', () => ({
|
||||
plugins: [(0, _parse.default)(), (0, _postcss_plugin.default)('marpit-postcss-import-replace-processor', () => (css, {
|
||||
postcss
|
||||
}) => {
|
||||
const prepends = [];
|
||||
css.walk(node => {
|
||||
const name = node.marpitImportParse;
|
||||
if (name) {
|
||||
const theme = themeSet.get(name);
|
||||
if (theme) {
|
||||
if (importedThemes.includes(name)) throw new Error(`Circular "${name}" theme import is detected.`);
|
||||
const processed = postcss([importReplace(themeSet, [...importedThemes, name])]).process(theme.css);
|
||||
if (node.name === 'import') {
|
||||
node.replaceWith(processed.root);
|
||||
} else {
|
||||
node.remove();
|
||||
prepends.unshift(processed.root);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
for (const root of prepends) css.first.before(root);
|
||||
})()]
|
||||
}));
|
||||
exports.importReplace = importReplace;
|
||||
var _default = exports.default = importReplace;
|
||||
30
node_modules/@marp-team/marpit/lib/postcss/import/suppress.js
generated
vendored
Normal file
30
node_modules/@marp-team/marpit/lib/postcss/import/suppress.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.importSuppress = exports.default = void 0;
|
||||
var _postcss_plugin = _interopRequireDefault(require("../../helpers/postcss_plugin"));
|
||||
var _parse = _interopRequireDefault(require("./parse"));
|
||||
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
||||
/** @module */
|
||||
|
||||
/**
|
||||
* Marpit PostCSS import suppress plugin.
|
||||
*
|
||||
* Comment out `@import` / `@import-theme` rules that have imported theme.
|
||||
*
|
||||
* This plugin is useful to prevent the inline style's rolled-up theme import by
|
||||
* unexpected order.
|
||||
*
|
||||
* @function importSuppress
|
||||
* @param {ThemeSet} themeSet ThemeSet instance.
|
||||
*/
|
||||
const importSuppress = exports.importSuppress = (0, _postcss_plugin.default)('marpit-postcss-import-suppress', themeSet => ({
|
||||
plugins: [(0, _parse.default)(), (0, _postcss_plugin.default)('marpit-postcss-import-suppress', () => css => {
|
||||
css.walk(node => {
|
||||
if (node.marpitImportParse && themeSet.has(node.marpitImportParse)) node.replaceWith(`${node.raw('before')}/* ${node.toString()}; */`);
|
||||
});
|
||||
})()]
|
||||
}));
|
||||
var _default = exports.default = importSuppress;
|
||||
Reference in New Issue
Block a user