Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let regionMode = false
let interpolateMode: Parser.InterpolateModeType =
format.filetype === Parser.GERBER ? Parser.LINE : null
// arcs in drill files are always 180 degrees max
let quadrantMode: Parser.QuadrantModeType = null
const currentLayer: ImageLayer = {
type: IMAGE_LAYER,
size: BBox.empty(),
children: [],
}
let currentPath: ImagePath | ImageRegion | null = null
visit(image, visitNode)
addCurrentPathToLayer()
return {
type: IMAGE,
children: [currentLayer],
}
function addCurrentPathToLayer(): void {
if (currentPath) {
const pathSize = getPathBox(currentPath)
currentLayer.size = BBox.add(currentLayer.size, pathSize)
currentLayer.children.push(currentPath)
currentPath = null
}
}
return ast => {
// Mutate all pure text nodes to have normalized whitespace, so we don't
// confuse ' ' and '\n' etc.
normalizeTextNodes(ast);
// Then walk all nodes.
visitParents(ast, visitor);
}
}
setNodeData(node, 'indentLevel', level - 1)
// clear empty script, textarea, pre, style tags
if (length) {
const empty = hasOnlyEmptyTextChildren(node)
const isEmbeddedContent = isElement(node, 'style') || isElement(node, 'script')
if (empty) {
// eslint-disable-next-line no-param-reassign
node.children = []
}
if (usePrettier && !empty && isEmbeddedContent) {
prettierEmbeddedContent(node, level, indent, prettierOpts)
}
}
return visit.SKIP
}
let newline = false
// we have to look in the future because we indent leading text
// on a newline when a child text node contains a newline. If we wouldn't do this
// the formatter could produce an unstable result because in the next step we could produce newlines.
const collpased = peekCollpase(node, children)
/**
* Indent children
*/
index = -1
while (++index < length) {
// eslint-disable-next-line no-shadow
const child = children[index]
inst.instructionHandler({
node,
ancestors,
instructionParam: inst.instructionParam,
linkURL,
file,
})
).then(() => res(true))
// stop traversal because the instruction may change ast.
// the ast may be **completly different** after this instruction's execution.
// we will detect next instruction in the **next transform pass**.
return visit.EXIT
}
}
}
return visit.CONTINUE
})
if (!foundLinkInstruction) res(false) // didn't find any instruction
const inst = resolveLinkText(linkTextNode.value)
if (inst) {
foundLinkInstruction = true
Promise.resolve(
inst.instructionHandler({
node,
ancestors,
instructionParam: inst.instructionParam,
linkURL,
file,
})
).then(() => res(true))
// stop traversal because the instruction may change ast.
// the ast may be **completly different** after this instruction's execution.
// we will detect next instruction in the **next transform pass**.
return visit.EXIT
}
}
}
return visit.CONTINUE
})
if (!foundLinkInstruction) res(false) // didn't find any instruction
export default () => (ast: Node) => {
visitParents(ast, 'text', textVisitor);
visit(ast, 'raw', rawVisitor);
};
return (tree, file) => {
tree.children.unshift({
type: 'import',
value: `import DemoRenderer__LegacyDemoInstructions from '@runtime/DemoRenderer'`,
})
visit(tree, 'paragraph', (node: mdast.Paragraph, ancestors) =>
paragraphVistor(node, ancestors as mdast.Parent[], file)
)
}
}
function mapImageTreeToSvg(node: ImageNode): SvgElement {
switch (node.type) {
case IMAGE: {
let box = BBox.empty()
unistVisit(node, IMAGE_LAYER, (layer: ImageLayer) => {
box = BBox.add(box, layer.size)
})
const [xMin, yMin, width, height] = BBox.toViewBox(box)
const props = {
...BASE_SVG_PROPS,
width,
height,
viewBox: `${xMin} ${yMin} ${width} ${height}`,
}
return s('svg', props)
}
case IMAGE_LAYER: {
const vbox = BBox.toViewBox(node.size)
return s('g', {
transform: `translate(0, ${vbox[3] + 2 * vbox[1]}) scale(1,-1)`,
return new Promise(res => {
let foundLinkInstruction = false
visit(tree, 'link', (node, ancestors) => {
const linkURL = node.url
if (Array.isArray(node.children) && node.children.length === 1) {
const linkTextNode = node.children[0]
if (linkTextNode.type === 'text') {
const inst = resolveLinkText(linkTextNode.value)
if (inst) {
foundLinkInstruction = true
Promise.resolve(
inst.instructionHandler({
node,
ancestors,
instructionParam: inst.instructionParam,
linkURL,
file,
})
).then(() => res(true))
'use strict'
module.exports = visit
var visitParents = require('unist-util-visit-parents')
var CONTINUE = visitParents.CONTINUE
var SKIP = visitParents.SKIP
var EXIT = visitParents.EXIT
visit.CONTINUE = CONTINUE
visit.SKIP = SKIP
visit.EXIT = EXIT
function visit(tree, test, visitor, reverse) {
if (typeof test === 'function' && typeof visitor !== 'function') {
reverse = visitor
visitor = test
test = null
}
visitParents(tree, test, overload, reverse)
function overload(node, parents) {