@unified-latex/unified-latex-ctan
Advanced tools
Comparing version 1.0.1 to 1.0.5
@@ -743,2 +743,28 @@ var __defProp = Object.defineProperty; | ||
// package/systeme/libs/systeme.ts | ||
import { printRaw } from "@unified-latex/unified-latex-util-print-raw"; | ||
import { match as match2 } from "@unified-latex/unified-latex-util-match"; | ||
import { arrayJoin } from "@unified-latex/unified-latex-util-split"; | ||
// ../structured-clone/dist/index.js | ||
(function() { | ||
if (typeof globalThis === "object") | ||
return; | ||
Object.defineProperty(Object.prototype, "__magic__", { | ||
get: function() { | ||
return this; | ||
}, | ||
configurable: true | ||
}); | ||
__magic__.globalThis = __magic__; | ||
delete Object.prototype.__magic__; | ||
})(); | ||
var clone = typeof globalThis.structuredClone === "function" ? globalThis.structuredClone : (obj) => JSON.parse(JSON.stringify(obj)); | ||
// package/systeme/libs/systeme.ts | ||
import { deleteComments } from "@unified-latex/unified-latex-util-comments"; | ||
import { visit } from "@unified-latex/unified-latex-util-visit"; | ||
import { updateRenderInfo as updateRenderInfo2 } from "@unified-latex/unified-latex-util-render-info"; | ||
import { getArgsContent } from "@unified-latex/unified-latex-util-arguments"; | ||
// package/tikz/provides.ts | ||
@@ -1477,23 +1503,6 @@ var macros10 = { | ||
// package/xcolor/libs/xcolor-macro-to-hex.ts | ||
import { getArgsContent } from "@unified-latex/unified-latex-util-arguments"; | ||
import { printRaw } from "@unified-latex/unified-latex-util-print-raw"; | ||
import { getArgsContent as getArgsContent2 } from "@unified-latex/unified-latex-util-arguments"; | ||
import { printRaw as printRaw2 } from "@unified-latex/unified-latex-util-print-raw"; | ||
import { deleteComments as deleteComments2 } from "@unified-latex/unified-latex-util-comments"; | ||
// ../structured-clone/dist/index.js | ||
(function() { | ||
if (typeof globalThis === "object") | ||
return; | ||
Object.defineProperty(Object.prototype, "__magic__", { | ||
get: function() { | ||
return this; | ||
}, | ||
configurable: true | ||
}); | ||
__magic__.globalThis = __magic__; | ||
delete Object.prototype.__magic__; | ||
})(); | ||
var clone = typeof globalThis.structuredClone === "function" ? globalThis.structuredClone : (obj) => JSON.parse(JSON.stringify(obj)); | ||
// package/xcolor/libs/xcolor-macro-to-hex.ts | ||
import { deleteComments } from "@unified-latex/unified-latex-util-comments"; | ||
// package/xcolor/libs/color-to-textcolor-macro.ts | ||
@@ -1500,0 +1509,0 @@ import { arg as arg2 } from "@unified-latex/unified-latex-builder"; |
@@ -5,2 +5,3 @@ export * from "./provides"; | ||
export * from "./libs/types"; | ||
export * from "./libs/systeme"; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -0,1 +1,21 @@ | ||
var __defProp = Object.defineProperty; | ||
var __defProps = Object.defineProperties; | ||
var __getOwnPropDescs = Object.getOwnPropertyDescriptors; | ||
var __getOwnPropSymbols = Object.getOwnPropertySymbols; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __propIsEnum = Object.prototype.propertyIsEnumerable; | ||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
var __spreadValues = (a, b) => { | ||
for (var prop in b || (b = {})) | ||
if (__hasOwnProp.call(b, prop)) | ||
__defNormalProp(a, prop, b[prop]); | ||
if (__getOwnPropSymbols) | ||
for (var prop of __getOwnPropSymbols(b)) { | ||
if (__propIsEnum.call(b, prop)) | ||
__defNormalProp(a, prop, b[prop]); | ||
} | ||
return a; | ||
}; | ||
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); | ||
// package/systeme/provides.ts | ||
@@ -100,8 +120,232 @@ var macros = { | ||
} | ||
// package/systeme/libs/systeme.ts | ||
import { printRaw as printRaw2 } from "@unified-latex/unified-latex-util-print-raw"; | ||
import { match as match2 } from "@unified-latex/unified-latex-util-match"; | ||
import { arrayJoin } from "@unified-latex/unified-latex-util-split"; | ||
// ../structured-clone/dist/index.js | ||
(function() { | ||
if (typeof globalThis === "object") | ||
return; | ||
Object.defineProperty(Object.prototype, "__magic__", { | ||
get: function() { | ||
return this; | ||
}, | ||
configurable: true | ||
}); | ||
__magic__.globalThis = __magic__; | ||
delete Object.prototype.__magic__; | ||
})(); | ||
var clone = typeof globalThis.structuredClone === "function" ? globalThis.structuredClone : (obj) => JSON.parse(JSON.stringify(obj)); | ||
function structuredClone(obj) { | ||
return clone(obj); | ||
} | ||
// package/systeme/libs/systeme.ts | ||
import { deleteComments } from "@unified-latex/unified-latex-util-comments"; | ||
import { visit } from "@unified-latex/unified-latex-util-visit"; | ||
import { updateRenderInfo } from "@unified-latex/unified-latex-util-render-info"; | ||
import { getArgsContent } from "@unified-latex/unified-latex-util-arguments"; | ||
var AMP = { type: "string", content: "&" }; | ||
var SEP = { type: "macro", content: "\\" }; | ||
var QUAD = { type: "macro", content: "quad" }; | ||
var PLUS = { type: "string", content: "+" }; | ||
var COLUMN_KERN_ADJUSTMENT = [ | ||
{ type: "string", content: "@" }, | ||
{ | ||
type: "group", | ||
content: [ | ||
{ type: "macro", content: "mkern" }, | ||
{ type: "string", content: "5mu" } | ||
] | ||
} | ||
]; | ||
function sortVariables(vars, whitelistedVariables) { | ||
const varMap = new Map(vars.map((v) => [v, printRaw2(v)])); | ||
const varNames = Array.from(new Set(varMap.values())); | ||
varNames.sort(); | ||
const nameToPos = whitelistedVariables ? new Map(whitelistedVariables.map((v, i) => [printRaw2(v), i])) : new Map(varNames.map((name, i) => [name, i])); | ||
return new Map(Array.from(varMap.entries()).map(([variable, name]) => { | ||
return [variable, nameToPos.get(name) ?? -1]; | ||
})); | ||
} | ||
function processLine(line, numVars, varOrder, hasEquals, hasAnnotation) { | ||
const ret = []; | ||
if (line.equation) { | ||
const nonVarItems = line.equation.left.filter((item) => item.variable == null); | ||
const varItems = line.equation.left.filter((item) => item.variable != null); | ||
let nonVarTerm = null; | ||
if (nonVarItems.length === 1) { | ||
nonVarTerm = nonVarItems[0]; | ||
} else if (nonVarItems.length > 1) { | ||
nonVarTerm = __spreadProps(__spreadValues({}, nonVarItems[0]), { | ||
content: nonVarItems[0].content.concat(nonVarItems.slice(1).flatMap((item) => { | ||
if (item.op) { | ||
return [item.op, ...item.content]; | ||
} | ||
return [PLUS, ...item.content]; | ||
})) | ||
}); | ||
} | ||
const allItems = nonVarTerm ? varItems.concat(nonVarTerm) : varItems; | ||
const indexToItem = new Map(allItems.map((item) => { | ||
if (item.variable == null) { | ||
return [numVars - 1, item]; | ||
} | ||
return [varOrder.get(item.variable), item]; | ||
})); | ||
let isFirstItem = true; | ||
for (let i = 0; i < numVars; i++) { | ||
const item = indexToItem.get(i); | ||
if (item) { | ||
if (isFirstItem && (match2.string(item.op, "+") || item.op == null)) { | ||
ret.push([]); | ||
ret.push(item.content); | ||
} else { | ||
ret.push([item.op || PLUS]); | ||
ret.push(item.content); | ||
} | ||
isFirstItem = false; | ||
} else { | ||
ret.push([]); | ||
ret.push([]); | ||
} | ||
} | ||
if (hasEquals) { | ||
const equalsPart = (line.equation.equals ? [line.equation.equals] : []).concat(line.equation.right); | ||
ret.push(equalsPart); | ||
} | ||
} | ||
if (hasAnnotation) { | ||
ret.push(line.annotation ? line.annotation.content : []); | ||
} | ||
return ret; | ||
} | ||
function arraySpecToSpacedArraySpec(spec, hasAnnotation) { | ||
const annotationSpec = hasAnnotation ? spec.charAt(spec.length - 1) : ""; | ||
const bodySpec = hasAnnotation ? spec.slice(0, spec.length - 1) : spec; | ||
const bodyStrings = Array.from(bodySpec).map((x) => [ | ||
{ type: "string", content: x } | ||
]); | ||
const body = arrayJoin(bodyStrings, COLUMN_KERN_ADJUSTMENT); | ||
return annotationSpec ? body.concat({ type: "string", content: annotationSpec }) : body; | ||
} | ||
function extractVariables(nodes) { | ||
return nodes.flatMap((node) => { | ||
if (node.type === "line" && node.equation) { | ||
return extractVariables(node.equation.left); | ||
} | ||
if (node.type === "equation") { | ||
return node.left.flatMap((item) => item.variable ? [item.variable] : []); | ||
} | ||
if (node.type === "item") { | ||
return node.variable ? [node.variable] : []; | ||
} | ||
return []; | ||
}); | ||
} | ||
function normalizeVariableWhitelist(vars) { | ||
if (!vars) { | ||
return null; | ||
} | ||
const normalized = vars.map((v) => typeof v === "string" ? { type: "string", content: v } : v); | ||
const ret = normalized.filter((v) => (match2.anyMacro(v) || match2.anyString(v)) && !match2.string(v, " ") && !match2.whitespace(v)); | ||
return ret; | ||
} | ||
function systemeContentsToArray(nodes, options) { | ||
nodes = structuredClone(nodes); | ||
deleteComments(nodes); | ||
const { properSpacing = true, whitelistedVariables } = options || {}; | ||
const coercedWhitelistedVariables = normalizeVariableWhitelist(whitelistedVariables); | ||
const systemeAst = parse(nodes, { whitelistedVariables }); | ||
const vars = extractVariables(systemeAst); | ||
const varOrder = sortVariables(vars, coercedWhitelistedVariables); | ||
let numVars = coercedWhitelistedVariables ? coercedWhitelistedVariables.length : Math.max(...Array.from(varOrder.values())) + 1; | ||
if (systemeAst.some((line) => { | ||
if (line.equation) { | ||
return line.equation.left.some((item) => item.variable == null); | ||
} | ||
})) { | ||
numVars += 1; | ||
} | ||
const hasEquals = systemeAst.some((line) => line.equation && line.equation.equals); | ||
const hasAnnotation = systemeAst.some((line) => line.annotation); | ||
let rows = systemeAst.map((line) => processLine(line, numVars, varOrder, hasEquals, hasAnnotation)); | ||
const noLeadingOperation = rows.every((row) => row[0].length === 0); | ||
let arraySignature = Array.from({ length: numVars }, () => "cr").join(""); | ||
if (noLeadingOperation) { | ||
arraySignature = arraySignature.slice(1); | ||
rows = rows.map((row) => row.slice(1)); | ||
} | ||
if (hasEquals) { | ||
arraySignature += "l"; | ||
} | ||
if (hasAnnotation) { | ||
arraySignature += "l"; | ||
rows = rows.map((row) => { | ||
if (row[row.length - 1].length === 0) { | ||
return row; | ||
} | ||
return [ | ||
...row.slice(0, row.length - 1), | ||
[QUAD, { type: "whitespace" }, ...row[row.length - 1]] | ||
]; | ||
}); | ||
} | ||
const arraySignatureWithSpacing = properSpacing ? arraySpecToSpacedArraySpec(arraySignature, hasAnnotation) : [{ type: "string", content: arraySignature }]; | ||
const bodyRows = rows.map((row) => arrayJoin(row, AMP)); | ||
const body = arrayJoin(bodyRows, SEP); | ||
const ret = { | ||
type: "environment", | ||
env: "array", | ||
args: [ | ||
{ | ||
type: "argument", | ||
openMark: "{", | ||
closeMark: "}", | ||
content: arraySignatureWithSpacing | ||
} | ||
], | ||
content: body | ||
}; | ||
return ret; | ||
} | ||
function attachSystemeSettingsAsRenderInfo(ast) { | ||
const systemeMatcher = match2.createMacroMatcher(["systeme", "sysdelim"]); | ||
visit(ast, (nodes, info) => { | ||
if (!info.context.inMathMode || !nodes.some(systemeMatcher)) { | ||
return; | ||
} | ||
const systemeLocations = nodes.flatMap((node, i) => match2.macro(node, "systeme") ? i : []); | ||
const sysdelimLocations = nodes.flatMap((node, i) => match2.macro(node, "sysdelim") ? i : []); | ||
if (systemeLocations.length === 0 || sysdelimLocations.length === 0) { | ||
return; | ||
} | ||
for (const i of systemeLocations) { | ||
const lastSysdelim = Math.max(...sysdelimLocations.filter((loc) => loc < i)); | ||
if (lastSysdelim >= 0) { | ||
const node = nodes[i]; | ||
const sysdelimMacro = nodes[lastSysdelim]; | ||
if (!match2.anyMacro(sysdelimMacro)) { | ||
throw new Error(`Expecting sysdelim macro but found "${printRaw2(sysdelimMacro)}"`); | ||
} | ||
const args = getArgsContent(sysdelimMacro); | ||
updateRenderInfo(node, { sysdelims: args }); | ||
} | ||
} | ||
}, { | ||
test: Array.isArray, | ||
includeArrays: true | ||
}); | ||
} | ||
export { | ||
attachSystemeSettingsAsRenderInfo, | ||
environments, | ||
extractVariables, | ||
macros, | ||
parse, | ||
printRaw | ||
printRaw, | ||
systemeContentsToArray | ||
}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@unified-latex/unified-latex-ctan", | ||
"version": "1.0.1", | ||
"version": "1.0.5", | ||
"description": "unified-latex tools relating to specific CTAN packages", | ||
@@ -8,13 +8,13 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@unified-latex/unified-latex-builder": "*", | ||
"@unified-latex/unified-latex-types": "*", | ||
"@unified-latex/unified-latex-util-arguments": "*", | ||
"@unified-latex/unified-latex-util-comments": "*", | ||
"@unified-latex/unified-latex-util-match": "*", | ||
"@unified-latex/unified-latex-util-pegjs": "*", | ||
"@unified-latex/unified-latex-util-print-raw": "*", | ||
"@unified-latex/unified-latex-util-render-info": "*", | ||
"@unified-latex/unified-latex-util-split": "*", | ||
"@unified-latex/unified-latex-util-trim": "*", | ||
"@unified-latex/unified-latex-util-visit": "*", | ||
"@unified-latex/unified-latex-builder": "^1.0.5", | ||
"@unified-latex/unified-latex-types": "^1.0.5", | ||
"@unified-latex/unified-latex-util-arguments": "^1.0.5", | ||
"@unified-latex/unified-latex-util-comments": "^1.0.5", | ||
"@unified-latex/unified-latex-util-match": "^1.0.5", | ||
"@unified-latex/unified-latex-util-pegjs": "^1.0.5", | ||
"@unified-latex/unified-latex-util-print-raw": "^1.0.5", | ||
"@unified-latex/unified-latex-util-render-info": "^1.0.5", | ||
"@unified-latex/unified-latex-util-split": "^1.0.5", | ||
"@unified-latex/unified-latex-util-trim": "^1.0.5", | ||
"@unified-latex/unified-latex-util-visit": "^1.0.5", | ||
"color": "^4.2.3" | ||
@@ -21,0 +21,0 @@ }, |
@@ -19,2 +19,11 @@ <!-- DO NOT MODIFY --> | ||
## Install | ||
```bash | ||
npm install @unified-latex/unified-latex-ctan | ||
``` | ||
This package contains both esm and commonjs exports. To explicitly access the esm export, | ||
import the `.js` file. To explicitly access the commonjs export, import the `.cjs` file. | ||
# Constants | ||
@@ -21,0 +30,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 11 instances in 1 package
826303
4727
0
34