stuff
This commit is contained in:
parent
bc92231240
commit
b8225c639e
11904 changed files with 1472749 additions and 133 deletions
91
node_modules/@marp-team/marpit/lib/helpers/inline_style.js
generated
vendored
Normal file
91
node_modules/@marp-team/marpit/lib/helpers/inline_style.js
generated
vendored
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
var _postcss = require("postcss");
|
||||
/**
|
||||
* InlineStyle helper class.
|
||||
*
|
||||
* This is the declarative builder of an inline style using PostCSS. The output
|
||||
* string by `toString()` is sanitized unexpected declarations.
|
||||
*
|
||||
* @module
|
||||
* @alias module:helpers/inline_style
|
||||
*/
|
||||
class InlineStyle {
|
||||
/**
|
||||
* Create an InlineStyle instance.
|
||||
*
|
||||
* @function constructor
|
||||
* @param {Object|String|InlineStyle} [initialDecls] The initial declarations.
|
||||
*/
|
||||
constructor(initialDecls) {
|
||||
this.decls = {};
|
||||
if (initialDecls) {
|
||||
if (initialDecls instanceof InlineStyle || typeof initialDecls === 'string') {
|
||||
const root = (0, _postcss.parse)(initialDecls.toString(), {
|
||||
from: undefined
|
||||
});
|
||||
root.each(node => {
|
||||
if (node.type === 'decl') this.decls[node.prop] = node.value;
|
||||
});
|
||||
} else {
|
||||
this.decls = {
|
||||
...initialDecls
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete declaration.
|
||||
*
|
||||
* @param {string} prop A property name of declaration.
|
||||
* @returns {InlineStyle} Returns myself for chaining methods.
|
||||
*/
|
||||
delete(prop) {
|
||||
delete this.decls[prop];
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set declaration.
|
||||
*
|
||||
* @param {string} prop A property name of declaration.
|
||||
* @param {string} value A value of declaration.
|
||||
* @returns {InlineStyle} Returns myself for chaining methods.
|
||||
*/
|
||||
set(prop, value) {
|
||||
this.decls[prop] = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a string of declarations for the inline style.
|
||||
*
|
||||
* The unexpected declarations will strip to prevent a style injection.
|
||||
*/
|
||||
toString() {
|
||||
let built = '';
|
||||
for (const prop of Object.keys(this.decls)) {
|
||||
let parsed;
|
||||
try {
|
||||
parsed = (0, _postcss.parse)(`${prop}:${this.decls[prop]}`, {
|
||||
from: undefined
|
||||
});
|
||||
} catch {
|
||||
// A declaration that have value it cannot parse will ignore.
|
||||
}
|
||||
if (parsed) {
|
||||
parsed.each(node => {
|
||||
if (node.type !== 'decl' || node.prop !== prop) node.remove();
|
||||
});
|
||||
built += `${parsed.toString()};`;
|
||||
}
|
||||
}
|
||||
return built;
|
||||
}
|
||||
}
|
||||
exports.default = InlineStyle;
|
||||
32
node_modules/@marp-team/marpit/lib/helpers/postcss_plugin.js
generated
vendored
Normal file
32
node_modules/@marp-team/marpit/lib/helpers/postcss_plugin.js
generated
vendored
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
exports.plugin = plugin;
|
||||
/** @module */
|
||||
|
||||
/**
|
||||
* Generate PostCSS plugin.
|
||||
*
|
||||
* This is a glue code generator to migrate existed plugins to support
|
||||
* PostCSS 8.
|
||||
*
|
||||
* @param {string} name Plugin name.
|
||||
* @param {(Function|Object)} func Function with PostCSS plugin interface.
|
||||
* @returns {Function} A PostCSS plugin.
|
||||
*/
|
||||
function plugin(name, func) {
|
||||
return Object.defineProperty(function interface_(...args) {
|
||||
const retFunc = func.apply(this, args);
|
||||
return Object.defineProperty(typeof retFunc === 'function' ? {
|
||||
Once: retFunc
|
||||
} : retFunc, 'postcssPlugin', {
|
||||
value: name
|
||||
});
|
||||
}, 'postcss', {
|
||||
value: true
|
||||
});
|
||||
}
|
||||
var _default = exports.default = plugin;
|
||||
35
node_modules/@marp-team/marpit/lib/helpers/split.js
generated
vendored
Normal file
35
node_modules/@marp-team/marpit/lib/helpers/split.js
generated
vendored
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
exports.split = split;
|
||||
/** @module */
|
||||
/**
|
||||
* Split array into multiple arrays by specified condition.
|
||||
*
|
||||
* @param {Array} arr Target array.
|
||||
* @param {splitCallback} func Callback to split array.
|
||||
* @param {boolean} [keepSplitValue=false] Keep split value. The split
|
||||
* point is before the matched value.
|
||||
* @returns {Array[]} Split array.
|
||||
*/
|
||||
function split(arr, func, keepSplitValue = false) {
|
||||
const ret = [[]];
|
||||
for (const value of arr) {
|
||||
/**
|
||||
* Return true at the split point.
|
||||
*
|
||||
* @callback splitCallback
|
||||
* @param {*} value
|
||||
*/
|
||||
if (func(value)) {
|
||||
ret.push(keepSplitValue ? [value] : []);
|
||||
} else {
|
||||
ret[ret.length - 1].push(value);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
var _default = exports.default = split;
|
||||
21
node_modules/@marp-team/marpit/lib/helpers/wrap_array.js
generated
vendored
Normal file
21
node_modules/@marp-team/marpit/lib/helpers/wrap_array.js
generated
vendored
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.wrapArray = exports.default = void 0;
|
||||
/** @module */
|
||||
/**
|
||||
* Wrap value in array if it is not an array.
|
||||
*
|
||||
* @function wrapArray
|
||||
* @param {*} valOrArr
|
||||
* @return {Array}
|
||||
*/
|
||||
const wrapArray = valOrArr => {
|
||||
if (valOrArr == null || valOrArr === false) return [];
|
||||
if (valOrArr instanceof Array) return valOrArr;
|
||||
return [valOrArr];
|
||||
};
|
||||
exports.wrapArray = wrapArray;
|
||||
var _default = exports.default = wrapArray;
|
||||
47
node_modules/@marp-team/marpit/lib/helpers/wrap_tokens.js
generated
vendored
Normal file
47
node_modules/@marp-team/marpit/lib/helpers/wrap_tokens.js
generated
vendored
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
exports.wrapTokens = wrapTokens;
|
||||
/** @module */
|
||||
|
||||
/**
|
||||
* Wrap array of tokens by specified container object.
|
||||
*
|
||||
* @param {Token} Token markdown-it's Token class.
|
||||
* @param {String} type Token type. It will be suffixed by `_open` / `_close`.
|
||||
* @param {Object} container A container object to wrap tokens, includes tag
|
||||
* name and attributes.
|
||||
* @param {String} container.tag The name of container element.
|
||||
* @param {Object} [container.open] The object assigning to an opening token.
|
||||
* @param {Object} [container.close] The object assigning to a closing token.
|
||||
* @param {Token[]} [tokens=[]] Wrapping tokens.
|
||||
* @returns {Token[]} Wrapped tokens.
|
||||
*/
|
||||
function wrapTokens(Token, type, container, tokens = []) {
|
||||
const {
|
||||
tag
|
||||
} = container;
|
||||
|
||||
// Update nesting level of wrapping tokens
|
||||
for (const t of tokens) t.level += 1;
|
||||
|
||||
// Create markdown-it tokens
|
||||
const open = new Token(`${type}_open`, tag, 1);
|
||||
const close = new Token(`${type}_close`, tag, -1);
|
||||
Object.assign(open, {
|
||||
...(container.open || {})
|
||||
});
|
||||
Object.assign(close, {
|
||||
...(container.close || {})
|
||||
});
|
||||
|
||||
// Assign attributes
|
||||
for (const attr of Object.keys(container)) {
|
||||
if (!['open', 'close', 'tag'].includes(attr) && container[attr] != null) open.attrSet(attr, container[attr]);
|
||||
}
|
||||
return [open, ...tokens, close];
|
||||
}
|
||||
var _default = exports.default = wrapTokens;
|
||||
Loading…
Add table
Add a link
Reference in a new issue