markmap-view
Advanced tools
Comparing version 0.2.2 to 0.2.3
@@ -1,2 +0,2 @@ | ||
/*! markmap-view v0.2.2 | MIT License */ | ||
/*! markmap-view v0.2.3 | MIT License */ | ||
'use strict'; | ||
@@ -6,19 +6,18 @@ | ||
function createCommonjsModule(fn, basedir, module) { | ||
return module = { | ||
path: basedir, | ||
exports: {}, | ||
require: function (path, base) { | ||
return commonjsRequire(path, (base === undefined || base === null) ? module.path : base); | ||
} | ||
}, fn(module, module.exports), module.exports; | ||
function _interopNamespace(e) { | ||
if (e && e.__esModule) return e; | ||
var n = Object.create(null); | ||
if (e) { | ||
Object.keys(e).forEach(function (k) { | ||
n[k] = e[k]; | ||
}); | ||
} | ||
function commonjsRequire () { | ||
throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs'); | ||
n['default'] = e; | ||
return Object.freeze(n); | ||
} | ||
var _extends_1 = createCommonjsModule(function (module) { | ||
function _extends() { | ||
module.exports = _extends = Object.assign || function (target) { | ||
var d3__namespace = /*#__PURE__*/_interopNamespace(d3); | ||
function _extends$1() { | ||
_extends$1 = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
@@ -37,8 +36,44 @@ var source = arguments[i]; | ||
return _extends.apply(this, arguments); | ||
return _extends$1.apply(this, arguments); | ||
} | ||
module.exports = _extends; | ||
}); | ||
function _assertThisInitialized(self) { | ||
if (self === void 0) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
return self; | ||
} | ||
function _defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
} | ||
function _setPrototypeOf(o, p) { | ||
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { | ||
o.__proto__ = p; | ||
return o; | ||
}; | ||
return _setPrototypeOf(o, p); | ||
} | ||
function _inheritsLoose(subClass, superClass) { | ||
subClass.prototype = Object.create(superClass.prototype); | ||
subClass.prototype.constructor = subClass; | ||
_setPrototypeOf(subClass, superClass); | ||
} | ||
function count(node) { | ||
@@ -48,3 +83,5 @@ var sum = 0, | ||
i = children && children.length; | ||
if (!i) sum = 1;else while (--i >= 0) sum += children[i].value; | ||
if (!i) sum = 1;else while (--i >= 0) { | ||
sum += children[i].value; | ||
} | ||
node.value = sum; | ||
@@ -123,3 +160,5 @@ } | ||
while (--i >= 0) sum += children[i].value; | ||
while (--i >= 0) { | ||
sum += children[i].value; | ||
} | ||
@@ -262,3 +301,5 @@ node.value = sum; | ||
do node.height = height; while ((node = node.parent) && node.height < ++height); | ||
do { | ||
node.height = height; | ||
} while ((node = node.parent) && node.height < ++height); | ||
} | ||
@@ -288,5 +329,9 @@ function Node(data) { | ||
const defaults = Object.freeze({ | ||
children: data => data.children, | ||
nodeSize: node => node.data.size, | ||
var defaults = Object.freeze({ | ||
children: function children(data) { | ||
return data.children; | ||
}, | ||
nodeSize: function nodeSize(node) { | ||
return node.data.size; | ||
}, | ||
spacing: 0 | ||
@@ -299,11 +344,15 @@ }); // Create a layout function with customizable options. Per D3-style, the | ||
function flextree(options) { | ||
const opts = Object.assign({}, defaults, options); | ||
var opts = Object.assign({}, defaults, options); | ||
function accessor(name) { | ||
const opt = opts[name]; | ||
return typeof opt === 'function' ? opt : () => opt; | ||
var opt = opts[name]; | ||
return typeof opt === 'function' ? opt : function () { | ||
return opt; | ||
}; | ||
} | ||
function layout(tree) { | ||
const wtree = wrap(getWrapper(), tree, node => node.children); | ||
var wtree = wrap(getWrapper(), tree, function (node) { | ||
return node.children; | ||
}); | ||
wtree.update(); | ||
@@ -314,91 +363,31 @@ return wtree.data; | ||
function getFlexNode() { | ||
const nodeSize = accessor('nodeSize'); | ||
const spacing = accessor('spacing'); | ||
return class FlexNode extends hierarchy.prototype.constructor { | ||
constructor(data) { | ||
super(data); | ||
} | ||
var nodeSize = accessor('nodeSize'); | ||
copy() { | ||
const c = wrap(this.constructor, this, node => node.children); | ||
c.each(node => node.data = node.data.data); | ||
return c; | ||
} | ||
var _spacing = accessor('spacing'); | ||
get size() { | ||
return nodeSize(this); | ||
} | ||
return /*#__PURE__*/function (_hierarchy$prototype$) { | ||
_inheritsLoose(FlexNode, _hierarchy$prototype$); | ||
spacing(oNode) { | ||
return spacing(this, oNode); | ||
function FlexNode(data) { | ||
return _hierarchy$prototype$.call(this, data) || this; | ||
} | ||
get nodes() { | ||
return this.descendants(); | ||
} | ||
var _proto = FlexNode.prototype; | ||
get xSize() { | ||
return this.size[0]; | ||
} | ||
_proto.copy = function copy() { | ||
var c = wrap(this.constructor, this, function (node) { | ||
return node.children; | ||
}); | ||
c.each(function (node) { | ||
return node.data = node.data.data; | ||
}); | ||
return c; | ||
}; | ||
get ySize() { | ||
return this.size[1]; | ||
} | ||
_proto.spacing = function spacing(oNode) { | ||
return _spacing(this, oNode); | ||
}; | ||
get top() { | ||
return this.y; | ||
} | ||
get bottom() { | ||
return this.y + this.ySize; | ||
} | ||
get left() { | ||
return this.x - this.xSize / 2; | ||
} | ||
get right() { | ||
return this.x + this.xSize / 2; | ||
} | ||
get root() { | ||
const ancs = this.ancestors(); | ||
return ancs[ancs.length - 1]; | ||
} | ||
get numChildren() { | ||
return this.hasChildren ? this.children.length : 0; | ||
} | ||
get hasChildren() { | ||
return !this.noChildren; | ||
} | ||
get noChildren() { | ||
return this.children === null; | ||
} | ||
get firstChild() { | ||
return this.hasChildren ? this.children[0] : null; | ||
} | ||
get lastChild() { | ||
return this.hasChildren ? this.children[this.numChildren - 1] : null; | ||
} | ||
get extents() { | ||
return (this.children || []).reduce((acc, kid) => FlexNode.maxExtents(acc, kid.extents), this.nodeExtents); | ||
} | ||
get nodeExtents() { | ||
FlexNode.maxExtents = function maxExtents(e0, e1) { | ||
return { | ||
top: this.top, | ||
bottom: this.bottom, | ||
left: this.left, | ||
right: this.right | ||
}; | ||
} | ||
static maxExtents(e0, e1) { | ||
return { | ||
top: Math.min(e0.top, e1.top), | ||
@@ -409,15 +398,112 @@ bottom: Math.max(e0.bottom, e1.bottom), | ||
}; | ||
} | ||
}; | ||
}; | ||
_createClass(FlexNode, [{ | ||
key: "size", | ||
get: function get() { | ||
return nodeSize(this); | ||
} | ||
}, { | ||
key: "nodes", | ||
get: function get() { | ||
return this.descendants(); | ||
} | ||
}, { | ||
key: "xSize", | ||
get: function get() { | ||
return this.size[0]; | ||
} | ||
}, { | ||
key: "ySize", | ||
get: function get() { | ||
return this.size[1]; | ||
} | ||
}, { | ||
key: "top", | ||
get: function get() { | ||
return this.y; | ||
} | ||
}, { | ||
key: "bottom", | ||
get: function get() { | ||
return this.y + this.ySize; | ||
} | ||
}, { | ||
key: "left", | ||
get: function get() { | ||
return this.x - this.xSize / 2; | ||
} | ||
}, { | ||
key: "right", | ||
get: function get() { | ||
return this.x + this.xSize / 2; | ||
} | ||
}, { | ||
key: "root", | ||
get: function get() { | ||
var ancs = this.ancestors(); | ||
return ancs[ancs.length - 1]; | ||
} | ||
}, { | ||
key: "numChildren", | ||
get: function get() { | ||
return this.hasChildren ? this.children.length : 0; | ||
} | ||
}, { | ||
key: "hasChildren", | ||
get: function get() { | ||
return !this.noChildren; | ||
} | ||
}, { | ||
key: "noChildren", | ||
get: function get() { | ||
return this.children === null; | ||
} | ||
}, { | ||
key: "firstChild", | ||
get: function get() { | ||
return this.hasChildren ? this.children[0] : null; | ||
} | ||
}, { | ||
key: "lastChild", | ||
get: function get() { | ||
return this.hasChildren ? this.children[this.numChildren - 1] : null; | ||
} | ||
}, { | ||
key: "extents", | ||
get: function get() { | ||
return (this.children || []).reduce(function (acc, kid) { | ||
return FlexNode.maxExtents(acc, kid.extents); | ||
}, this.nodeExtents); | ||
} | ||
}, { | ||
key: "nodeExtents", | ||
get: function get() { | ||
return { | ||
top: this.top, | ||
bottom: this.bottom, | ||
left: this.left, | ||
right: this.right | ||
}; | ||
} | ||
}]); | ||
return FlexNode; | ||
}(hierarchy.prototype.constructor); | ||
} | ||
function getWrapper() { | ||
const FlexNode = getFlexNode(); | ||
const nodeSize = accessor('nodeSize'); | ||
const spacing = accessor('spacing'); | ||
return class extends FlexNode { | ||
constructor(data) { | ||
super(data); | ||
Object.assign(this, { | ||
var FlexNode = getFlexNode(); | ||
var nodeSize = accessor('nodeSize'); | ||
var _spacing2 = accessor('spacing'); | ||
return /*#__PURE__*/function (_FlexNode) { | ||
_inheritsLoose(_class, _FlexNode); | ||
function _class(data) { | ||
var _this; | ||
_this = _FlexNode.call(this, data) || this; | ||
Object.assign(_assertThisInitialized(_this), { | ||
x: 0, | ||
@@ -429,49 +515,56 @@ y: 0, | ||
change: 0, | ||
lExt: this, | ||
lExt: _assertThisInitialized(_this), | ||
lExtRelX: 0, | ||
lThr: null, | ||
rExt: this, | ||
rExt: _assertThisInitialized(_this), | ||
rExtRelX: 0, | ||
rThr: null | ||
}); | ||
return _this; | ||
} | ||
get size() { | ||
return nodeSize(this.data); | ||
} | ||
var _proto2 = _class.prototype; | ||
spacing(oNode) { | ||
return spacing(this.data, oNode.data); | ||
} | ||
_proto2.spacing = function spacing(oNode) { | ||
return _spacing2(this.data, oNode.data); | ||
}; | ||
get x() { | ||
return this.data.x; | ||
} | ||
set x(v) { | ||
this.data.x = v; | ||
} | ||
get y() { | ||
return this.data.y; | ||
} | ||
set y(v) { | ||
this.data.y = v; | ||
} | ||
update() { | ||
_proto2.update = function update() { | ||
layoutChildren(this); | ||
resolveX(this); | ||
return this; | ||
} | ||
}; | ||
}; | ||
_createClass(_class, [{ | ||
key: "size", | ||
get: function get() { | ||
return nodeSize(this.data); | ||
} | ||
}, { | ||
key: "x", | ||
get: function get() { | ||
return this.data.x; | ||
}, | ||
set: function set(v) { | ||
this.data.x = v; | ||
} | ||
}, { | ||
key: "y", | ||
get: function get() { | ||
return this.data.y; | ||
}, | ||
set: function set(v) { | ||
this.data.y = v; | ||
} | ||
}]); | ||
return _class; | ||
}(FlexNode); | ||
} | ||
function wrap(FlexClass, treeData, children) { | ||
const _wrap = (data, parent) => { | ||
const node = new FlexClass(data); | ||
var _wrap = function _wrap(data, parent) { | ||
var node = new FlexClass(data); | ||
Object.assign(node, { | ||
parent, | ||
parent: parent, | ||
depth: parent === null ? 0 : parent.depth + 1, | ||
@@ -481,10 +574,14 @@ height: 0, | ||
}); | ||
const kidsData = children(data) || []; | ||
node.children = kidsData.length === 0 ? null : kidsData.map(kd => _wrap(kd, node)); | ||
var kidsData = children(data) || []; | ||
node.children = kidsData.length === 0 ? null : kidsData.map(function (kd) { | ||
return _wrap(kd, node); | ||
}); | ||
if (node.children) { | ||
Object.assign(node, node.children.reduce((hl, kid) => ({ | ||
height: Math.max(hl.height, kid.height + 1), | ||
length: hl.length + kid.length | ||
}), node)); | ||
Object.assign(node, node.children.reduce(function (hl, kid) { | ||
return { | ||
height: Math.max(hl.height, kid.height + 1), | ||
length: hl.length + kid.length | ||
}; | ||
}, node)); | ||
} | ||
@@ -499,33 +596,29 @@ | ||
Object.assign(layout, { | ||
nodeSize(arg) { | ||
nodeSize: function nodeSize(arg) { | ||
return arguments.length ? (opts.nodeSize = arg, layout) : opts.nodeSize; | ||
}, | ||
spacing(arg) { | ||
spacing: function spacing(arg) { | ||
return arguments.length ? (opts.spacing = arg, layout) : opts.spacing; | ||
}, | ||
children(arg) { | ||
children: function children(arg) { | ||
return arguments.length ? (opts.children = arg, layout) : opts.children; | ||
}, | ||
hierarchy(treeData, children) { | ||
const kids = typeof children === 'undefined' ? opts.children : children; | ||
hierarchy: function hierarchy(treeData, children) { | ||
var kids = typeof children === 'undefined' ? opts.children : children; | ||
return wrap(getFlexNode(), treeData, kids); | ||
}, | ||
dump: function dump(tree) { | ||
var nodeSize = accessor('nodeSize'); | ||
dump(tree) { | ||
const nodeSize = accessor('nodeSize'); | ||
const _dump = i0 => node => { | ||
const i1 = i0 + ' '; | ||
const i2 = i0 + ' '; | ||
const { | ||
x, | ||
y | ||
} = node; | ||
const size = nodeSize(node); | ||
const kids = node.children || []; | ||
const kdumps = kids.length === 0 ? ' ' : `,${i1}children: [${i2}${kids.map(_dump(i2)).join(i2)}${i1}],${i0}`; | ||
return `{ size: [${size.join(', ')}],${i1}x: ${x}, y: ${y}${kdumps}},`; | ||
var _dump = function _dump(i0) { | ||
return function (node) { | ||
var i1 = i0 + ' '; | ||
var i2 = i0 + ' '; | ||
var x = node.x, | ||
y = node.y; | ||
var size = nodeSize(node); | ||
var kids = node.children || []; | ||
var kdumps = kids.length === 0 ? ' ' : "," + i1 + "children: [" + i2 + kids.map(_dump(i2)).join(i2) + i1 + "]," + i0; | ||
return "{ size: [" + size.join(', ') + "]," + i1 + "x: " + x + ", y: " + y + kdumps + "},"; | ||
}; | ||
}; | ||
@@ -535,3 +628,2 @@ | ||
} | ||
}); | ||
@@ -542,12 +634,17 @@ return layout; | ||
const layoutChildren = (w, y = 0) => { | ||
var layoutChildren = function layoutChildren(w, y) { | ||
if (y === void 0) { | ||
y = 0; | ||
} | ||
w.y = y; | ||
(w.children || []).reduce((acc, kid) => { | ||
const [i, lastLows] = acc; | ||
(w.children || []).reduce(function (acc, kid) { | ||
var i = acc[0], | ||
lastLows = acc[1]; | ||
layoutChildren(kid, w.y + w.ySize); // The lowest vertical coordinate while extreme nodes still point | ||
// in current subtree. | ||
const lowY = (i === 0 ? kid.lExt : kid.rExt).bottom; | ||
var lowY = (i === 0 ? kid.lExt : kid.rExt).bottom; | ||
if (i !== 0) separate(w, i, lastLows); | ||
const lows = updateLows(lowY, i, lastLows); | ||
var lows = updateLows(lowY, i, lastLows); | ||
return [i + 1, lows]; | ||
@@ -564,3 +661,3 @@ }, [0, null]); | ||
const resolveX = (w, prevSum, parentX) => { | ||
var resolveX = function resolveX(w, prevSum, parentX) { | ||
// A call to resolveX without arguments is assumed to be for the root of | ||
@@ -573,7 +670,9 @@ // the tree. This will set the root's x-coord to zero. | ||
const sum = prevSum + w.relX; | ||
var sum = prevSum + w.relX; | ||
w.relX = sum + w.prelim - parentX; | ||
w.prelim = 0; | ||
w.x = parentX + w.relX; | ||
(w.children || []).forEach(k => resolveX(k, sum, w.x)); | ||
(w.children || []).forEach(function (k) { | ||
return resolveX(k, sum, w.x); | ||
}); | ||
return w; | ||
@@ -584,7 +683,8 @@ }; // Process shift and change for all children, to add intermediate spacing to | ||
const shiftChange = w => { | ||
(w.children || []).reduce((acc, child) => { | ||
const [lastShiftSum, lastChangeSum] = acc; | ||
const shiftSum = lastShiftSum + child.shift; | ||
const changeSum = lastChangeSum + shiftSum + child.change; | ||
var shiftChange = function shiftChange(w) { | ||
(w.children || []).reduce(function (acc, child) { | ||
var lastShiftSum = acc[0], | ||
lastChangeSum = acc[1]; | ||
var shiftSum = lastShiftSum + child.shift; | ||
var changeSum = lastChangeSum + shiftSum + child.change; | ||
child.relX += changeSum; | ||
@@ -598,10 +698,10 @@ return [shiftSum, changeSum]; | ||
const separate = (w, i, lows) => { | ||
const lSib = w.children[i - 1]; | ||
const curSubtree = w.children[i]; | ||
let rContour = lSib; | ||
let rSumMods = lSib.relX; | ||
let lContour = curSubtree; | ||
let lSumMods = curSubtree.relX; | ||
let isFirst = true; | ||
var separate = function separate(w, i, lows) { | ||
var lSib = w.children[i - 1]; | ||
var curSubtree = w.children[i]; | ||
var rContour = lSib; | ||
var rSumMods = lSib.relX; | ||
var lContour = curSubtree; | ||
var lSumMods = curSubtree.relX; | ||
var isFirst = true; | ||
@@ -613,3 +713,3 @@ while (rContour && lContour) { | ||
const dist = rSumMods + rContour.prelim - (lSumMods + lContour.prelim) + rContour.xSize / 2 + lContour.xSize / 2 + rContour.spacing(lContour); | ||
var dist = rSumMods + rContour.prelim - (lSumMods + lContour.prelim) + rContour.xSize / 2 + lContour.xSize / 2 + rContour.spacing(lContour); | ||
@@ -625,4 +725,4 @@ if (dist > 0 || dist < 0 && isFirst) { | ||
const rightBottom = rContour.bottom; | ||
const leftBottom = lContour.bottom; | ||
var rightBottom = rContour.bottom; | ||
var leftBottom = lContour.bottom; | ||
@@ -649,3 +749,3 @@ if (rightBottom <= leftBottom) { | ||
const moveSubtree = (subtree, distance) => { | ||
var moveSubtree = function moveSubtree(subtree, distance) { | ||
subtree.relX += distance; | ||
@@ -656,8 +756,8 @@ subtree.lExtRelX += distance; | ||
const distributeExtra = (w, curSubtreeI, leftSibI, dist) => { | ||
const curSubtree = w.children[curSubtreeI]; | ||
const n = curSubtreeI - leftSibI; // Are there intermediate children? | ||
var distributeExtra = function distributeExtra(w, curSubtreeI, leftSibI, dist) { | ||
var curSubtree = w.children[curSubtreeI]; | ||
var n = curSubtreeI - leftSibI; // Are there intermediate children? | ||
if (n > 1) { | ||
const delta = dist / n; | ||
var delta = dist / n; | ||
w.children[leftSibI + 1].shift += delta; | ||
@@ -669,17 +769,17 @@ curSubtree.shift -= delta; | ||
const nextLContour = w => { | ||
var nextLContour = function nextLContour(w) { | ||
return w.hasChildren ? w.firstChild : w.lThr; | ||
}; | ||
const nextRContour = w => { | ||
var nextRContour = function nextRContour(w) { | ||
return w.hasChildren ? w.lastChild : w.rThr; | ||
}; | ||
const setLThr = (w, i, lContour, lSumMods) => { | ||
const firstChild = w.firstChild; | ||
const lExt = firstChild.lExt; | ||
const curSubtree = w.children[i]; | ||
var setLThr = function setLThr(w, i, lContour, lSumMods) { | ||
var firstChild = w.firstChild; | ||
var lExt = firstChild.lExt; | ||
var curSubtree = w.children[i]; | ||
lExt.lThr = lContour; // Change relX so that the sum of modifier after following thread is correct. | ||
const diff = lSumMods - lContour.relX - firstChild.lExtRelX; | ||
var diff = lSumMods - lContour.relX - firstChild.lExtRelX; | ||
lExt.relX += diff; // Change preliminary x coordinate so that the node does not move. | ||
@@ -694,8 +794,8 @@ | ||
const setRThr = (w, i, rContour, rSumMods) => { | ||
const curSubtree = w.children[i]; | ||
const rExt = curSubtree.rExt; | ||
const lSib = w.children[i - 1]; | ||
var setRThr = function setRThr(w, i, rContour, rSumMods) { | ||
var curSubtree = w.children[i]; | ||
var rExt = curSubtree.rExt; | ||
var lSib = w.children[i - 1]; | ||
rExt.rThr = rContour; | ||
const diff = rSumMods - rContour.relX - curSubtree.rExtRelX; | ||
var diff = rSumMods - rContour.relX - curSubtree.rExtRelX; | ||
rExt.relX += diff; | ||
@@ -708,9 +808,9 @@ rExt.prelim -= diff; | ||
const positionRoot = w => { | ||
var positionRoot = function positionRoot(w) { | ||
if (w.hasChildren) { | ||
const k0 = w.firstChild; | ||
const kf = w.lastChild; | ||
const prelim = (k0.prelim + k0.relX - k0.xSize / 2 + kf.relX + kf.prelim + kf.xSize / 2) / 2; | ||
var k0 = w.firstChild; | ||
var kf = w.lastChild; | ||
var prelim = (k0.prelim + k0.relX - k0.xSize / 2 + kf.relX + kf.prelim + kf.xSize / 2) / 2; | ||
Object.assign(w, { | ||
prelim, | ||
prelim: prelim, | ||
lExt: k0.lExt, | ||
@@ -726,10 +826,12 @@ lExtRelX: k0.lExtRelX, | ||
const updateLows = (lowY, index, lastLows) => { | ||
var updateLows = function updateLows(lowY, index, lastLows) { | ||
// Remove siblings that are hidden by the new subtree. | ||
while (lastLows !== null && lowY >= lastLows.lowY) lastLows = lastLows.next; // Prepend the new subtree. | ||
while (lastLows !== null && lowY >= lastLows.lowY) { | ||
lastLows = lastLows.next; | ||
} // Prepend the new subtree. | ||
return { | ||
lowY, | ||
index, | ||
lowY: lowY, | ||
index: index, | ||
next: lastLows | ||
@@ -739,22 +841,3 @@ }; | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
/*! markmap-common v0.1.3 | MIT License */ | ||
/*! markmap-common v0.1.4 | MIT License */ | ||
class Hook { | ||
@@ -787,2 +870,20 @@ constructor() { | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
const uniqId = Math.random().toString(36).slice(2, 8); | ||
@@ -958,2 +1059,11 @@ let globalIndex = 0; | ||
function minBy(numbers, by) { | ||
const index = d3__namespace.minIndex(numbers, by); | ||
return numbers[index]; | ||
} | ||
function stopPropagation(e) { | ||
e.stopPropagation(); | ||
} | ||
function createViewHooks() { | ||
@@ -984,6 +1094,6 @@ return { | ||
this.viewHooks = createViewHooks(); | ||
this.svg = svg.datum ? svg : d3.select(svg); | ||
this.svg = svg.datum ? svg : d3__namespace.select(svg); | ||
this.styleNode = this.svg.append('style'); | ||
this.zoom = d3.zoom().on('zoom', this.handleZoom); | ||
this.options = _extends_1({}, Markmap.defaultOptions, opts); | ||
this.zoom = d3__namespace.zoom().on('zoom', this.handleZoom); | ||
this.options = _extends$1({}, Markmap.defaultOptions, opts); | ||
this.state = { | ||
@@ -1010,5 +1120,7 @@ id: this.options.id || getId() | ||
const styleText = `\ | ||
.${id} { line-height: 1; } | ||
.${id} a { color: #0097e6; } | ||
.${id} a:hover { color: #00a8ff; } | ||
.${id}-g > path { fill: none; } | ||
.${id}-g > g > circle { cursor: pointer; } | ||
.${id}-fo > div { display: inline-block; font: ${nodeFont}; white-space: nowrap; } | ||
@@ -1021,3 +1133,2 @@ .${id}-fo code { font-size: calc(1em - 2px); color: #555; background-color: #f0f0f0; border-radius: 2px; } | ||
.${id}-fo pre { margin: 0; padding: .2em .4em; } | ||
.${id}-g > g { cursor: pointer; } | ||
${extraStyle} | ||
@@ -1046,3 +1157,3 @@ `; | ||
} = d; | ||
data.p = _extends_1({}, data.p, { | ||
data.p = _extends$1({}, data.p, { | ||
f: !((_data$p = data.p) != null && _data$p.f) | ||
@@ -1086,3 +1197,3 @@ }); | ||
item.c = (_item$c = item.c) == null ? void 0 : _item$c.map(child => _extends_1({}, child)); | ||
item.c = (_item$c = item.c) == null ? void 0 : _item$c.map(child => _extends$1({}, child)); | ||
i += 1; | ||
@@ -1092,3 +1203,3 @@ const el = document.createElement('div'); | ||
container.append(el); | ||
item.p = _extends_1({}, item.p, { | ||
item.p = _extends$1({}, item.p, { | ||
// unique ID | ||
@@ -1124,3 +1235,3 @@ i, | ||
setData(data, opts) { | ||
if (!data) data = _extends_1({}, this.state.data); | ||
if (!data) data = _extends$1({}, this.state.data); | ||
this.state.data = data; | ||
@@ -1161,7 +1272,7 @@ this.initializeData(data); | ||
const links = tree.links(); | ||
const linkShape = d3.linkHorizontal(); | ||
const minX = d3.min(descendants, d => d.x - d.xSize / 2); | ||
const maxX = d3.max(descendants, d => d.x + d.xSize / 2); | ||
const minY = d3.min(descendants, d => d.y); | ||
const maxY = d3.max(descendants, d => d.y + d.ySizeInner); | ||
const linkShape = d3__namespace.linkHorizontal(); | ||
const minX = d3__namespace.min(descendants, d => d.x - d.xSize / 2); | ||
const maxX = d3__namespace.max(descendants, d => d.x + d.xSize / 2); | ||
const minY = d3__namespace.min(descendants, d => d.y); | ||
const maxY = d3__namespace.max(descendants, d => d.y + d.ySizeInner); | ||
Object.assign(this.state, { | ||
@@ -1179,3 +1290,3 @@ minX, | ||
const node = this.g.selectAll(childSelector('g')).data(descendants, d => d.data.p.k); | ||
const nodeEnter = node.enter().append('g').attr('transform', d => `translate(${y0 + origin.ySizeInner - d.ySizeInner},${x0 + origin.xSize / 2 - d.xSize})`).on('click', this.handleClick); | ||
const nodeEnter = node.enter().append('g').attr('transform', d => `translate(${y0 + origin.ySizeInner - d.ySizeInner},${x0 + origin.xSize / 2 - d.xSize})`); | ||
const nodeExit = this.transition(node.exit()); | ||
@@ -1192,3 +1303,3 @@ nodeExit.select('rect').attr('width', 0).attr('x', d => d.ySizeInner); | ||
const circle = nodeMerge.selectAll(childSelector('circle')).data(d => d.data.c ? [d] : [], d => d.data.p.k).join(enter => { | ||
return enter.append('circle').attr('stroke-width', '1.5').attr('cx', d => d.ySizeInner).attr('cy', d => d.xSize).attr('r', 0); | ||
return enter.append('circle').attr('stroke-width', '1.5').attr('cx', d => d.ySizeInner).attr('cy', d => d.xSize).attr('r', 0).on('click', this.handleClick); | ||
}, update => update, exit => exit.remove()); | ||
@@ -1201,3 +1312,3 @@ this.transition(circle).attr('r', 6).attr('stroke', d => color(d.data)).attr('fill', d => { | ||
const foreignObject = nodeMerge.selectAll(childSelector('foreignObject')).data(d => [d], d => d.data.p.k).join(enter => { | ||
const fo = enter.append('foreignObject').attr('class', `${id}-fo`).attr('x', paddingX).attr('y', 0).style('opacity', 0).attr('height', d => d.xSize); | ||
const fo = enter.append('foreignObject').attr('class', `${id}-fo`).attr('x', paddingX).attr('y', 0).style('opacity', 0).attr('height', d => d.xSize).on('mousedown', stopPropagation).on('dblclick', stopPropagation); | ||
fo.append('xhtml:div').select(function select(d) { | ||
@@ -1245,4 +1356,8 @@ const node = d.data.p.el.cloneNode(true); | ||
} | ||
/** | ||
* Fit the content to the viewport. | ||
*/ | ||
fit() { | ||
async fit() { | ||
const svgNode = this.svg.node(); | ||
@@ -1265,8 +1380,50 @@ const { | ||
const scale = Math.min(offsetWidth / naturalWidth * fitRatio, offsetHeight / naturalHeight * fitRatio, 2); | ||
const initialZoom = d3.zoomIdentity.translate((offsetWidth - naturalWidth * scale) / 2 - minY * scale, (offsetHeight - naturalHeight * scale) / 2 - minX * scale).scale(scale); | ||
const initialZoom = d3__namespace.zoomIdentity.translate((offsetWidth - naturalWidth * scale) / 2 - minY * scale, (offsetHeight - naturalHeight * scale) / 2 - minX * scale).scale(scale); | ||
return this.transition(this.svg).call(this.zoom.transform, initialZoom).end().catch(noop); | ||
} | ||
/** | ||
* Pan the content to make the provided node visible in the viewport. | ||
*/ | ||
rescale(scale) { | ||
async ensureView(node, padding) { | ||
let g; | ||
let itemData; | ||
this.g.selectAll(childSelector('g')).each(function walk(d) { | ||
if (d.data === node) { | ||
g = this; | ||
itemData = d; | ||
} | ||
}); | ||
if (!g || !itemData) return; | ||
const svgNode = this.svg.node(); | ||
const relRect = svgNode.getBoundingClientRect(); | ||
const transform = d3__namespace.zoomTransform(svgNode); | ||
const [left, right] = [itemData.y, itemData.y + itemData.ySizeInner + 2].map(x => x * transform.k + transform.x); | ||
const [top, bottom] = [itemData.x - itemData.xSize / 2, itemData.x + itemData.xSize / 2].map(y => y * transform.k + transform.y); // Skip if the node includes or is included in the container. | ||
const pd = _extends$1({ | ||
left: 0, | ||
right: 0, | ||
top: 0, | ||
bottom: 0 | ||
}, padding); | ||
const dxs = [pd.left - left, relRect.width - pd.right - right]; | ||
const dys = [pd.top - top, relRect.height - pd.bottom - bottom]; | ||
const dx = dxs[0] * dxs[1] > 0 ? minBy(dxs, Math.abs) / transform.k : 0; | ||
const dy = dys[0] * dys[1] > 0 ? minBy(dys, Math.abs) / transform.k : 0; | ||
if (dx || dy) { | ||
const newTransform = transform.translate(dx, dy); | ||
return this.transition(this.svg).call(this.zoom.transform, newTransform).end().catch(noop); | ||
} | ||
} | ||
/** | ||
* Scale content with it pinned at the center of the viewport. | ||
*/ | ||
async rescale(scale) { | ||
const svgNode = this.svg.node(); | ||
const { | ||
@@ -1278,3 +1435,3 @@ width: offsetWidth, | ||
const halfHeight = offsetHeight / 2; | ||
const transform = d3.zoomTransform(svgNode); | ||
const transform = d3__namespace.zoomTransform(svgNode); | ||
const newTransform = transform.translate((halfWidth - transform.x) * (1 - scale) / transform.k, (halfHeight - transform.y) * (1 - scale) / transform.k).scale(scale); | ||
@@ -1311,3 +1468,3 @@ return this.transition(this.svg).call(this.zoom.transform, newTransform).end().catch(noop); | ||
fitRatio: 0.95, | ||
color: (colorFn => node => colorFn(node.p.i))(d3.scaleOrdinal(d3.schemeCategory10)), | ||
color: (colorFn => node => colorFn(node.p.i))(d3__namespace.scaleOrdinal(d3__namespace.schemeCategory10)), | ||
paddingX: 8 | ||
@@ -1314,0 +1471,0 @@ }; |
@@ -1,5 +0,61 @@ | ||
/*! markmap-view v0.2.2 | MIT License */ | ||
import _extends from '@babel/runtime/helpers/esm/extends'; | ||
import { select, zoom, linkHorizontal, min, max, zoomIdentity, zoomTransform, scaleOrdinal, schemeCategory10 } from 'd3'; | ||
/*! markmap-view v0.2.3 | MIT License */ | ||
import * as d3 from 'd3'; | ||
function _extends$1() { | ||
_extends$1 = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return _extends$1.apply(this, arguments); | ||
} | ||
function _assertThisInitialized(self) { | ||
if (self === void 0) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
return self; | ||
} | ||
function _defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
} | ||
function _setPrototypeOf(o, p) { | ||
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { | ||
o.__proto__ = p; | ||
return o; | ||
}; | ||
return _setPrototypeOf(o, p); | ||
} | ||
function _inheritsLoose(subClass, superClass) { | ||
subClass.prototype = Object.create(superClass.prototype); | ||
subClass.prototype.constructor = subClass; | ||
_setPrototypeOf(subClass, superClass); | ||
} | ||
function count(node) { | ||
@@ -9,3 +65,5 @@ var sum = 0, | ||
i = children && children.length; | ||
if (!i) sum = 1;else while (--i >= 0) sum += children[i].value; | ||
if (!i) sum = 1;else while (--i >= 0) { | ||
sum += children[i].value; | ||
} | ||
node.value = sum; | ||
@@ -84,3 +142,5 @@ } | ||
while (--i >= 0) sum += children[i].value; | ||
while (--i >= 0) { | ||
sum += children[i].value; | ||
} | ||
@@ -223,3 +283,5 @@ node.value = sum; | ||
do node.height = height; while ((node = node.parent) && node.height < ++height); | ||
do { | ||
node.height = height; | ||
} while ((node = node.parent) && node.height < ++height); | ||
} | ||
@@ -249,5 +311,9 @@ function Node(data) { | ||
const defaults = Object.freeze({ | ||
children: data => data.children, | ||
nodeSize: node => node.data.size, | ||
var defaults = Object.freeze({ | ||
children: function children(data) { | ||
return data.children; | ||
}, | ||
nodeSize: function nodeSize(node) { | ||
return node.data.size; | ||
}, | ||
spacing: 0 | ||
@@ -260,11 +326,15 @@ }); // Create a layout function with customizable options. Per D3-style, the | ||
function flextree(options) { | ||
const opts = Object.assign({}, defaults, options); | ||
var opts = Object.assign({}, defaults, options); | ||
function accessor(name) { | ||
const opt = opts[name]; | ||
return typeof opt === 'function' ? opt : () => opt; | ||
var opt = opts[name]; | ||
return typeof opt === 'function' ? opt : function () { | ||
return opt; | ||
}; | ||
} | ||
function layout(tree) { | ||
const wtree = wrap(getWrapper(), tree, node => node.children); | ||
var wtree = wrap(getWrapper(), tree, function (node) { | ||
return node.children; | ||
}); | ||
wtree.update(); | ||
@@ -275,91 +345,31 @@ return wtree.data; | ||
function getFlexNode() { | ||
const nodeSize = accessor('nodeSize'); | ||
const spacing = accessor('spacing'); | ||
return class FlexNode extends hierarchy.prototype.constructor { | ||
constructor(data) { | ||
super(data); | ||
} | ||
var nodeSize = accessor('nodeSize'); | ||
copy() { | ||
const c = wrap(this.constructor, this, node => node.children); | ||
c.each(node => node.data = node.data.data); | ||
return c; | ||
} | ||
var _spacing = accessor('spacing'); | ||
get size() { | ||
return nodeSize(this); | ||
} | ||
return /*#__PURE__*/function (_hierarchy$prototype$) { | ||
_inheritsLoose(FlexNode, _hierarchy$prototype$); | ||
spacing(oNode) { | ||
return spacing(this, oNode); | ||
function FlexNode(data) { | ||
return _hierarchy$prototype$.call(this, data) || this; | ||
} | ||
get nodes() { | ||
return this.descendants(); | ||
} | ||
var _proto = FlexNode.prototype; | ||
get xSize() { | ||
return this.size[0]; | ||
} | ||
_proto.copy = function copy() { | ||
var c = wrap(this.constructor, this, function (node) { | ||
return node.children; | ||
}); | ||
c.each(function (node) { | ||
return node.data = node.data.data; | ||
}); | ||
return c; | ||
}; | ||
get ySize() { | ||
return this.size[1]; | ||
} | ||
_proto.spacing = function spacing(oNode) { | ||
return _spacing(this, oNode); | ||
}; | ||
get top() { | ||
return this.y; | ||
} | ||
get bottom() { | ||
return this.y + this.ySize; | ||
} | ||
get left() { | ||
return this.x - this.xSize / 2; | ||
} | ||
get right() { | ||
return this.x + this.xSize / 2; | ||
} | ||
get root() { | ||
const ancs = this.ancestors(); | ||
return ancs[ancs.length - 1]; | ||
} | ||
get numChildren() { | ||
return this.hasChildren ? this.children.length : 0; | ||
} | ||
get hasChildren() { | ||
return !this.noChildren; | ||
} | ||
get noChildren() { | ||
return this.children === null; | ||
} | ||
get firstChild() { | ||
return this.hasChildren ? this.children[0] : null; | ||
} | ||
get lastChild() { | ||
return this.hasChildren ? this.children[this.numChildren - 1] : null; | ||
} | ||
get extents() { | ||
return (this.children || []).reduce((acc, kid) => FlexNode.maxExtents(acc, kid.extents), this.nodeExtents); | ||
} | ||
get nodeExtents() { | ||
FlexNode.maxExtents = function maxExtents(e0, e1) { | ||
return { | ||
top: this.top, | ||
bottom: this.bottom, | ||
left: this.left, | ||
right: this.right | ||
}; | ||
} | ||
static maxExtents(e0, e1) { | ||
return { | ||
top: Math.min(e0.top, e1.top), | ||
@@ -370,15 +380,112 @@ bottom: Math.max(e0.bottom, e1.bottom), | ||
}; | ||
} | ||
}; | ||
}; | ||
_createClass(FlexNode, [{ | ||
key: "size", | ||
get: function get() { | ||
return nodeSize(this); | ||
} | ||
}, { | ||
key: "nodes", | ||
get: function get() { | ||
return this.descendants(); | ||
} | ||
}, { | ||
key: "xSize", | ||
get: function get() { | ||
return this.size[0]; | ||
} | ||
}, { | ||
key: "ySize", | ||
get: function get() { | ||
return this.size[1]; | ||
} | ||
}, { | ||
key: "top", | ||
get: function get() { | ||
return this.y; | ||
} | ||
}, { | ||
key: "bottom", | ||
get: function get() { | ||
return this.y + this.ySize; | ||
} | ||
}, { | ||
key: "left", | ||
get: function get() { | ||
return this.x - this.xSize / 2; | ||
} | ||
}, { | ||
key: "right", | ||
get: function get() { | ||
return this.x + this.xSize / 2; | ||
} | ||
}, { | ||
key: "root", | ||
get: function get() { | ||
var ancs = this.ancestors(); | ||
return ancs[ancs.length - 1]; | ||
} | ||
}, { | ||
key: "numChildren", | ||
get: function get() { | ||
return this.hasChildren ? this.children.length : 0; | ||
} | ||
}, { | ||
key: "hasChildren", | ||
get: function get() { | ||
return !this.noChildren; | ||
} | ||
}, { | ||
key: "noChildren", | ||
get: function get() { | ||
return this.children === null; | ||
} | ||
}, { | ||
key: "firstChild", | ||
get: function get() { | ||
return this.hasChildren ? this.children[0] : null; | ||
} | ||
}, { | ||
key: "lastChild", | ||
get: function get() { | ||
return this.hasChildren ? this.children[this.numChildren - 1] : null; | ||
} | ||
}, { | ||
key: "extents", | ||
get: function get() { | ||
return (this.children || []).reduce(function (acc, kid) { | ||
return FlexNode.maxExtents(acc, kid.extents); | ||
}, this.nodeExtents); | ||
} | ||
}, { | ||
key: "nodeExtents", | ||
get: function get() { | ||
return { | ||
top: this.top, | ||
bottom: this.bottom, | ||
left: this.left, | ||
right: this.right | ||
}; | ||
} | ||
}]); | ||
return FlexNode; | ||
}(hierarchy.prototype.constructor); | ||
} | ||
function getWrapper() { | ||
const FlexNode = getFlexNode(); | ||
const nodeSize = accessor('nodeSize'); | ||
const spacing = accessor('spacing'); | ||
return class extends FlexNode { | ||
constructor(data) { | ||
super(data); | ||
Object.assign(this, { | ||
var FlexNode = getFlexNode(); | ||
var nodeSize = accessor('nodeSize'); | ||
var _spacing2 = accessor('spacing'); | ||
return /*#__PURE__*/function (_FlexNode) { | ||
_inheritsLoose(_class, _FlexNode); | ||
function _class(data) { | ||
var _this; | ||
_this = _FlexNode.call(this, data) || this; | ||
Object.assign(_assertThisInitialized(_this), { | ||
x: 0, | ||
@@ -390,49 +497,56 @@ y: 0, | ||
change: 0, | ||
lExt: this, | ||
lExt: _assertThisInitialized(_this), | ||
lExtRelX: 0, | ||
lThr: null, | ||
rExt: this, | ||
rExt: _assertThisInitialized(_this), | ||
rExtRelX: 0, | ||
rThr: null | ||
}); | ||
return _this; | ||
} | ||
get size() { | ||
return nodeSize(this.data); | ||
} | ||
var _proto2 = _class.prototype; | ||
spacing(oNode) { | ||
return spacing(this.data, oNode.data); | ||
} | ||
_proto2.spacing = function spacing(oNode) { | ||
return _spacing2(this.data, oNode.data); | ||
}; | ||
get x() { | ||
return this.data.x; | ||
} | ||
set x(v) { | ||
this.data.x = v; | ||
} | ||
get y() { | ||
return this.data.y; | ||
} | ||
set y(v) { | ||
this.data.y = v; | ||
} | ||
update() { | ||
_proto2.update = function update() { | ||
layoutChildren(this); | ||
resolveX(this); | ||
return this; | ||
} | ||
}; | ||
}; | ||
_createClass(_class, [{ | ||
key: "size", | ||
get: function get() { | ||
return nodeSize(this.data); | ||
} | ||
}, { | ||
key: "x", | ||
get: function get() { | ||
return this.data.x; | ||
}, | ||
set: function set(v) { | ||
this.data.x = v; | ||
} | ||
}, { | ||
key: "y", | ||
get: function get() { | ||
return this.data.y; | ||
}, | ||
set: function set(v) { | ||
this.data.y = v; | ||
} | ||
}]); | ||
return _class; | ||
}(FlexNode); | ||
} | ||
function wrap(FlexClass, treeData, children) { | ||
const _wrap = (data, parent) => { | ||
const node = new FlexClass(data); | ||
var _wrap = function _wrap(data, parent) { | ||
var node = new FlexClass(data); | ||
Object.assign(node, { | ||
parent, | ||
parent: parent, | ||
depth: parent === null ? 0 : parent.depth + 1, | ||
@@ -442,10 +556,14 @@ height: 0, | ||
}); | ||
const kidsData = children(data) || []; | ||
node.children = kidsData.length === 0 ? null : kidsData.map(kd => _wrap(kd, node)); | ||
var kidsData = children(data) || []; | ||
node.children = kidsData.length === 0 ? null : kidsData.map(function (kd) { | ||
return _wrap(kd, node); | ||
}); | ||
if (node.children) { | ||
Object.assign(node, node.children.reduce((hl, kid) => ({ | ||
height: Math.max(hl.height, kid.height + 1), | ||
length: hl.length + kid.length | ||
}), node)); | ||
Object.assign(node, node.children.reduce(function (hl, kid) { | ||
return { | ||
height: Math.max(hl.height, kid.height + 1), | ||
length: hl.length + kid.length | ||
}; | ||
}, node)); | ||
} | ||
@@ -460,33 +578,29 @@ | ||
Object.assign(layout, { | ||
nodeSize(arg) { | ||
nodeSize: function nodeSize(arg) { | ||
return arguments.length ? (opts.nodeSize = arg, layout) : opts.nodeSize; | ||
}, | ||
spacing(arg) { | ||
spacing: function spacing(arg) { | ||
return arguments.length ? (opts.spacing = arg, layout) : opts.spacing; | ||
}, | ||
children(arg) { | ||
children: function children(arg) { | ||
return arguments.length ? (opts.children = arg, layout) : opts.children; | ||
}, | ||
hierarchy(treeData, children) { | ||
const kids = typeof children === 'undefined' ? opts.children : children; | ||
hierarchy: function hierarchy(treeData, children) { | ||
var kids = typeof children === 'undefined' ? opts.children : children; | ||
return wrap(getFlexNode(), treeData, kids); | ||
}, | ||
dump: function dump(tree) { | ||
var nodeSize = accessor('nodeSize'); | ||
dump(tree) { | ||
const nodeSize = accessor('nodeSize'); | ||
const _dump = i0 => node => { | ||
const i1 = i0 + ' '; | ||
const i2 = i0 + ' '; | ||
const { | ||
x, | ||
y | ||
} = node; | ||
const size = nodeSize(node); | ||
const kids = node.children || []; | ||
const kdumps = kids.length === 0 ? ' ' : `,${i1}children: [${i2}${kids.map(_dump(i2)).join(i2)}${i1}],${i0}`; | ||
return `{ size: [${size.join(', ')}],${i1}x: ${x}, y: ${y}${kdumps}},`; | ||
var _dump = function _dump(i0) { | ||
return function (node) { | ||
var i1 = i0 + ' '; | ||
var i2 = i0 + ' '; | ||
var x = node.x, | ||
y = node.y; | ||
var size = nodeSize(node); | ||
var kids = node.children || []; | ||
var kdumps = kids.length === 0 ? ' ' : "," + i1 + "children: [" + i2 + kids.map(_dump(i2)).join(i2) + i1 + "]," + i0; | ||
return "{ size: [" + size.join(', ') + "]," + i1 + "x: " + x + ", y: " + y + kdumps + "},"; | ||
}; | ||
}; | ||
@@ -496,3 +610,2 @@ | ||
} | ||
}); | ||
@@ -503,12 +616,17 @@ return layout; | ||
const layoutChildren = (w, y = 0) => { | ||
var layoutChildren = function layoutChildren(w, y) { | ||
if (y === void 0) { | ||
y = 0; | ||
} | ||
w.y = y; | ||
(w.children || []).reduce((acc, kid) => { | ||
const [i, lastLows] = acc; | ||
(w.children || []).reduce(function (acc, kid) { | ||
var i = acc[0], | ||
lastLows = acc[1]; | ||
layoutChildren(kid, w.y + w.ySize); // The lowest vertical coordinate while extreme nodes still point | ||
// in current subtree. | ||
const lowY = (i === 0 ? kid.lExt : kid.rExt).bottom; | ||
var lowY = (i === 0 ? kid.lExt : kid.rExt).bottom; | ||
if (i !== 0) separate(w, i, lastLows); | ||
const lows = updateLows(lowY, i, lastLows); | ||
var lows = updateLows(lowY, i, lastLows); | ||
return [i + 1, lows]; | ||
@@ -525,3 +643,3 @@ }, [0, null]); | ||
const resolveX = (w, prevSum, parentX) => { | ||
var resolveX = function resolveX(w, prevSum, parentX) { | ||
// A call to resolveX without arguments is assumed to be for the root of | ||
@@ -534,7 +652,9 @@ // the tree. This will set the root's x-coord to zero. | ||
const sum = prevSum + w.relX; | ||
var sum = prevSum + w.relX; | ||
w.relX = sum + w.prelim - parentX; | ||
w.prelim = 0; | ||
w.x = parentX + w.relX; | ||
(w.children || []).forEach(k => resolveX(k, sum, w.x)); | ||
(w.children || []).forEach(function (k) { | ||
return resolveX(k, sum, w.x); | ||
}); | ||
return w; | ||
@@ -545,7 +665,8 @@ }; // Process shift and change for all children, to add intermediate spacing to | ||
const shiftChange = w => { | ||
(w.children || []).reduce((acc, child) => { | ||
const [lastShiftSum, lastChangeSum] = acc; | ||
const shiftSum = lastShiftSum + child.shift; | ||
const changeSum = lastChangeSum + shiftSum + child.change; | ||
var shiftChange = function shiftChange(w) { | ||
(w.children || []).reduce(function (acc, child) { | ||
var lastShiftSum = acc[0], | ||
lastChangeSum = acc[1]; | ||
var shiftSum = lastShiftSum + child.shift; | ||
var changeSum = lastChangeSum + shiftSum + child.change; | ||
child.relX += changeSum; | ||
@@ -559,10 +680,10 @@ return [shiftSum, changeSum]; | ||
const separate = (w, i, lows) => { | ||
const lSib = w.children[i - 1]; | ||
const curSubtree = w.children[i]; | ||
let rContour = lSib; | ||
let rSumMods = lSib.relX; | ||
let lContour = curSubtree; | ||
let lSumMods = curSubtree.relX; | ||
let isFirst = true; | ||
var separate = function separate(w, i, lows) { | ||
var lSib = w.children[i - 1]; | ||
var curSubtree = w.children[i]; | ||
var rContour = lSib; | ||
var rSumMods = lSib.relX; | ||
var lContour = curSubtree; | ||
var lSumMods = curSubtree.relX; | ||
var isFirst = true; | ||
@@ -574,3 +695,3 @@ while (rContour && lContour) { | ||
const dist = rSumMods + rContour.prelim - (lSumMods + lContour.prelim) + rContour.xSize / 2 + lContour.xSize / 2 + rContour.spacing(lContour); | ||
var dist = rSumMods + rContour.prelim - (lSumMods + lContour.prelim) + rContour.xSize / 2 + lContour.xSize / 2 + rContour.spacing(lContour); | ||
@@ -586,4 +707,4 @@ if (dist > 0 || dist < 0 && isFirst) { | ||
const rightBottom = rContour.bottom; | ||
const leftBottom = lContour.bottom; | ||
var rightBottom = rContour.bottom; | ||
var leftBottom = lContour.bottom; | ||
@@ -610,3 +731,3 @@ if (rightBottom <= leftBottom) { | ||
const moveSubtree = (subtree, distance) => { | ||
var moveSubtree = function moveSubtree(subtree, distance) { | ||
subtree.relX += distance; | ||
@@ -617,8 +738,8 @@ subtree.lExtRelX += distance; | ||
const distributeExtra = (w, curSubtreeI, leftSibI, dist) => { | ||
const curSubtree = w.children[curSubtreeI]; | ||
const n = curSubtreeI - leftSibI; // Are there intermediate children? | ||
var distributeExtra = function distributeExtra(w, curSubtreeI, leftSibI, dist) { | ||
var curSubtree = w.children[curSubtreeI]; | ||
var n = curSubtreeI - leftSibI; // Are there intermediate children? | ||
if (n > 1) { | ||
const delta = dist / n; | ||
var delta = dist / n; | ||
w.children[leftSibI + 1].shift += delta; | ||
@@ -630,17 +751,17 @@ curSubtree.shift -= delta; | ||
const nextLContour = w => { | ||
var nextLContour = function nextLContour(w) { | ||
return w.hasChildren ? w.firstChild : w.lThr; | ||
}; | ||
const nextRContour = w => { | ||
var nextRContour = function nextRContour(w) { | ||
return w.hasChildren ? w.lastChild : w.rThr; | ||
}; | ||
const setLThr = (w, i, lContour, lSumMods) => { | ||
const firstChild = w.firstChild; | ||
const lExt = firstChild.lExt; | ||
const curSubtree = w.children[i]; | ||
var setLThr = function setLThr(w, i, lContour, lSumMods) { | ||
var firstChild = w.firstChild; | ||
var lExt = firstChild.lExt; | ||
var curSubtree = w.children[i]; | ||
lExt.lThr = lContour; // Change relX so that the sum of modifier after following thread is correct. | ||
const diff = lSumMods - lContour.relX - firstChild.lExtRelX; | ||
var diff = lSumMods - lContour.relX - firstChild.lExtRelX; | ||
lExt.relX += diff; // Change preliminary x coordinate so that the node does not move. | ||
@@ -655,8 +776,8 @@ | ||
const setRThr = (w, i, rContour, rSumMods) => { | ||
const curSubtree = w.children[i]; | ||
const rExt = curSubtree.rExt; | ||
const lSib = w.children[i - 1]; | ||
var setRThr = function setRThr(w, i, rContour, rSumMods) { | ||
var curSubtree = w.children[i]; | ||
var rExt = curSubtree.rExt; | ||
var lSib = w.children[i - 1]; | ||
rExt.rThr = rContour; | ||
const diff = rSumMods - rContour.relX - curSubtree.rExtRelX; | ||
var diff = rSumMods - rContour.relX - curSubtree.rExtRelX; | ||
rExt.relX += diff; | ||
@@ -669,9 +790,9 @@ rExt.prelim -= diff; | ||
const positionRoot = w => { | ||
var positionRoot = function positionRoot(w) { | ||
if (w.hasChildren) { | ||
const k0 = w.firstChild; | ||
const kf = w.lastChild; | ||
const prelim = (k0.prelim + k0.relX - k0.xSize / 2 + kf.relX + kf.prelim + kf.xSize / 2) / 2; | ||
var k0 = w.firstChild; | ||
var kf = w.lastChild; | ||
var prelim = (k0.prelim + k0.relX - k0.xSize / 2 + kf.relX + kf.prelim + kf.xSize / 2) / 2; | ||
Object.assign(w, { | ||
prelim, | ||
prelim: prelim, | ||
lExt: k0.lExt, | ||
@@ -687,10 +808,12 @@ lExtRelX: k0.lExtRelX, | ||
const updateLows = (lowY, index, lastLows) => { | ||
var updateLows = function updateLows(lowY, index, lastLows) { | ||
// Remove siblings that are hidden by the new subtree. | ||
while (lastLows !== null && lowY >= lastLows.lowY) lastLows = lastLows.next; // Prepend the new subtree. | ||
while (lastLows !== null && lowY >= lastLows.lowY) { | ||
lastLows = lastLows.next; | ||
} // Prepend the new subtree. | ||
return { | ||
lowY, | ||
index, | ||
lowY: lowY, | ||
index: index, | ||
next: lastLows | ||
@@ -700,4 +823,3 @@ }; | ||
/*! markmap-common v0.1.3 | MIT License */ | ||
/*! markmap-common v0.1.4 | MIT License */ | ||
class Hook { | ||
@@ -730,2 +852,20 @@ constructor() { | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
const uniqId = Math.random().toString(36).slice(2, 8); | ||
@@ -901,2 +1041,11 @@ let globalIndex = 0; | ||
function minBy(numbers, by) { | ||
const index = d3.minIndex(numbers, by); | ||
return numbers[index]; | ||
} | ||
function stopPropagation(e) { | ||
e.stopPropagation(); | ||
} | ||
function createViewHooks() { | ||
@@ -927,6 +1076,6 @@ return { | ||
this.viewHooks = createViewHooks(); | ||
this.svg = svg.datum ? svg : select(svg); | ||
this.svg = svg.datum ? svg : d3.select(svg); | ||
this.styleNode = this.svg.append('style'); | ||
this.zoom = zoom().on('zoom', this.handleZoom); | ||
this.options = _extends({}, Markmap.defaultOptions, opts); | ||
this.zoom = d3.zoom().on('zoom', this.handleZoom); | ||
this.options = _extends$1({}, Markmap.defaultOptions, opts); | ||
this.state = { | ||
@@ -953,5 +1102,7 @@ id: this.options.id || getId() | ||
const styleText = `\ | ||
.${id} { line-height: 1; } | ||
.${id} a { color: #0097e6; } | ||
.${id} a:hover { color: #00a8ff; } | ||
.${id}-g > path { fill: none; } | ||
.${id}-g > g > circle { cursor: pointer; } | ||
.${id}-fo > div { display: inline-block; font: ${nodeFont}; white-space: nowrap; } | ||
@@ -964,3 +1115,2 @@ .${id}-fo code { font-size: calc(1em - 2px); color: #555; background-color: #f0f0f0; border-radius: 2px; } | ||
.${id}-fo pre { margin: 0; padding: .2em .4em; } | ||
.${id}-g > g { cursor: pointer; } | ||
${extraStyle} | ||
@@ -989,3 +1139,3 @@ `; | ||
} = d; | ||
data.p = _extends({}, data.p, { | ||
data.p = _extends$1({}, data.p, { | ||
f: !((_data$p = data.p) != null && _data$p.f) | ||
@@ -1029,3 +1179,3 @@ }); | ||
item.c = (_item$c = item.c) == null ? void 0 : _item$c.map(child => _extends({}, child)); | ||
item.c = (_item$c = item.c) == null ? void 0 : _item$c.map(child => _extends$1({}, child)); | ||
i += 1; | ||
@@ -1035,3 +1185,3 @@ const el = document.createElement('div'); | ||
container.append(el); | ||
item.p = _extends({}, item.p, { | ||
item.p = _extends$1({}, item.p, { | ||
// unique ID | ||
@@ -1067,3 +1217,3 @@ i, | ||
setData(data, opts) { | ||
if (!data) data = _extends({}, this.state.data); | ||
if (!data) data = _extends$1({}, this.state.data); | ||
this.state.data = data; | ||
@@ -1104,7 +1254,7 @@ this.initializeData(data); | ||
const links = tree.links(); | ||
const linkShape = linkHorizontal(); | ||
const minX = min(descendants, d => d.x - d.xSize / 2); | ||
const maxX = max(descendants, d => d.x + d.xSize / 2); | ||
const minY = min(descendants, d => d.y); | ||
const maxY = max(descendants, d => d.y + d.ySizeInner); | ||
const linkShape = d3.linkHorizontal(); | ||
const minX = d3.min(descendants, d => d.x - d.xSize / 2); | ||
const maxX = d3.max(descendants, d => d.x + d.xSize / 2); | ||
const minY = d3.min(descendants, d => d.y); | ||
const maxY = d3.max(descendants, d => d.y + d.ySizeInner); | ||
Object.assign(this.state, { | ||
@@ -1122,3 +1272,3 @@ minX, | ||
const node = this.g.selectAll(childSelector('g')).data(descendants, d => d.data.p.k); | ||
const nodeEnter = node.enter().append('g').attr('transform', d => `translate(${y0 + origin.ySizeInner - d.ySizeInner},${x0 + origin.xSize / 2 - d.xSize})`).on('click', this.handleClick); | ||
const nodeEnter = node.enter().append('g').attr('transform', d => `translate(${y0 + origin.ySizeInner - d.ySizeInner},${x0 + origin.xSize / 2 - d.xSize})`); | ||
const nodeExit = this.transition(node.exit()); | ||
@@ -1135,3 +1285,3 @@ nodeExit.select('rect').attr('width', 0).attr('x', d => d.ySizeInner); | ||
const circle = nodeMerge.selectAll(childSelector('circle')).data(d => d.data.c ? [d] : [], d => d.data.p.k).join(enter => { | ||
return enter.append('circle').attr('stroke-width', '1.5').attr('cx', d => d.ySizeInner).attr('cy', d => d.xSize).attr('r', 0); | ||
return enter.append('circle').attr('stroke-width', '1.5').attr('cx', d => d.ySizeInner).attr('cy', d => d.xSize).attr('r', 0).on('click', this.handleClick); | ||
}, update => update, exit => exit.remove()); | ||
@@ -1144,3 +1294,3 @@ this.transition(circle).attr('r', 6).attr('stroke', d => color(d.data)).attr('fill', d => { | ||
const foreignObject = nodeMerge.selectAll(childSelector('foreignObject')).data(d => [d], d => d.data.p.k).join(enter => { | ||
const fo = enter.append('foreignObject').attr('class', `${id}-fo`).attr('x', paddingX).attr('y', 0).style('opacity', 0).attr('height', d => d.xSize); | ||
const fo = enter.append('foreignObject').attr('class', `${id}-fo`).attr('x', paddingX).attr('y', 0).style('opacity', 0).attr('height', d => d.xSize).on('mousedown', stopPropagation).on('dblclick', stopPropagation); | ||
fo.append('xhtml:div').select(function select(d) { | ||
@@ -1188,4 +1338,8 @@ const node = d.data.p.el.cloneNode(true); | ||
} | ||
/** | ||
* Fit the content to the viewport. | ||
*/ | ||
fit() { | ||
async fit() { | ||
const svgNode = this.svg.node(); | ||
@@ -1208,8 +1362,50 @@ const { | ||
const scale = Math.min(offsetWidth / naturalWidth * fitRatio, offsetHeight / naturalHeight * fitRatio, 2); | ||
const initialZoom = zoomIdentity.translate((offsetWidth - naturalWidth * scale) / 2 - minY * scale, (offsetHeight - naturalHeight * scale) / 2 - minX * scale).scale(scale); | ||
const initialZoom = d3.zoomIdentity.translate((offsetWidth - naturalWidth * scale) / 2 - minY * scale, (offsetHeight - naturalHeight * scale) / 2 - minX * scale).scale(scale); | ||
return this.transition(this.svg).call(this.zoom.transform, initialZoom).end().catch(noop); | ||
} | ||
/** | ||
* Pan the content to make the provided node visible in the viewport. | ||
*/ | ||
rescale(scale) { | ||
async ensureView(node, padding) { | ||
let g; | ||
let itemData; | ||
this.g.selectAll(childSelector('g')).each(function walk(d) { | ||
if (d.data === node) { | ||
g = this; | ||
itemData = d; | ||
} | ||
}); | ||
if (!g || !itemData) return; | ||
const svgNode = this.svg.node(); | ||
const relRect = svgNode.getBoundingClientRect(); | ||
const transform = d3.zoomTransform(svgNode); | ||
const [left, right] = [itemData.y, itemData.y + itemData.ySizeInner + 2].map(x => x * transform.k + transform.x); | ||
const [top, bottom] = [itemData.x - itemData.xSize / 2, itemData.x + itemData.xSize / 2].map(y => y * transform.k + transform.y); // Skip if the node includes or is included in the container. | ||
const pd = _extends$1({ | ||
left: 0, | ||
right: 0, | ||
top: 0, | ||
bottom: 0 | ||
}, padding); | ||
const dxs = [pd.left - left, relRect.width - pd.right - right]; | ||
const dys = [pd.top - top, relRect.height - pd.bottom - bottom]; | ||
const dx = dxs[0] * dxs[1] > 0 ? minBy(dxs, Math.abs) / transform.k : 0; | ||
const dy = dys[0] * dys[1] > 0 ? minBy(dys, Math.abs) / transform.k : 0; | ||
if (dx || dy) { | ||
const newTransform = transform.translate(dx, dy); | ||
return this.transition(this.svg).call(this.zoom.transform, newTransform).end().catch(noop); | ||
} | ||
} | ||
/** | ||
* Scale content with it pinned at the center of the viewport. | ||
*/ | ||
async rescale(scale) { | ||
const svgNode = this.svg.node(); | ||
const { | ||
@@ -1221,3 +1417,3 @@ width: offsetWidth, | ||
const halfHeight = offsetHeight / 2; | ||
const transform = zoomTransform(svgNode); | ||
const transform = d3.zoomTransform(svgNode); | ||
const newTransform = transform.translate((halfWidth - transform.x) * (1 - scale) / transform.k, (halfHeight - transform.y) * (1 - scale) / transform.k).scale(scale); | ||
@@ -1254,3 +1450,3 @@ return this.transition(this.svg).call(this.zoom.transform, newTransform).end().catch(noop); | ||
fitRatio: 0.95, | ||
color: (colorFn => node => colorFn(node.p.i))(scaleOrdinal(schemeCategory10)), | ||
color: (colorFn => node => colorFn(node.p.i))(d3.scaleOrdinal(d3.schemeCategory10)), | ||
paddingX: 8 | ||
@@ -1257,0 +1453,0 @@ }; |
@@ -1,7 +0,21 @@ | ||
/*! markmap-view v0.2.2 | MIT License */ | ||
/*! markmap-view v0.2.3 | MIT License */ | ||
(function (exports, d3) { | ||
'use strict'; | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
function _interopNamespace(e) { | ||
if (e && e.__esModule) return e; | ||
var n = Object.create(null); | ||
if (e) { | ||
Object.keys(e).forEach(function (k) { | ||
n[k] = e[k]; | ||
}); | ||
} | ||
n['default'] = e; | ||
return Object.freeze(n); | ||
} | ||
var d3__namespace = /*#__PURE__*/_interopNamespace(d3); | ||
function _extends$1() { | ||
_extends$1 = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
@@ -20,5 +34,44 @@ var source = arguments[i]; | ||
return _extends.apply(this, arguments); | ||
return _extends$1.apply(this, arguments); | ||
} | ||
function _assertThisInitialized(self) { | ||
if (self === void 0) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
return self; | ||
} | ||
function _defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
} | ||
function _setPrototypeOf(o, p) { | ||
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { | ||
o.__proto__ = p; | ||
return o; | ||
}; | ||
return _setPrototypeOf(o, p); | ||
} | ||
function _inheritsLoose(subClass, superClass) { | ||
subClass.prototype = Object.create(superClass.prototype); | ||
subClass.prototype.constructor = subClass; | ||
_setPrototypeOf(subClass, superClass); | ||
} | ||
function count(node) { | ||
@@ -28,3 +81,5 @@ var sum = 0, | ||
i = children && children.length; | ||
if (!i) sum = 1;else while (--i >= 0) sum += children[i].value; | ||
if (!i) sum = 1;else while (--i >= 0) { | ||
sum += children[i].value; | ||
} | ||
node.value = sum; | ||
@@ -103,3 +158,5 @@ } | ||
while (--i >= 0) sum += children[i].value; | ||
while (--i >= 0) { | ||
sum += children[i].value; | ||
} | ||
@@ -242,3 +299,5 @@ node.value = sum; | ||
do node.height = height; while ((node = node.parent) && node.height < ++height); | ||
do { | ||
node.height = height; | ||
} while ((node = node.parent) && node.height < ++height); | ||
} | ||
@@ -268,5 +327,9 @@ function Node(data) { | ||
const defaults = Object.freeze({ | ||
children: data => data.children, | ||
nodeSize: node => node.data.size, | ||
var defaults = Object.freeze({ | ||
children: function children(data) { | ||
return data.children; | ||
}, | ||
nodeSize: function nodeSize(node) { | ||
return node.data.size; | ||
}, | ||
spacing: 0 | ||
@@ -279,11 +342,15 @@ }); // Create a layout function with customizable options. Per D3-style, the | ||
function flextree(options) { | ||
const opts = Object.assign({}, defaults, options); | ||
var opts = Object.assign({}, defaults, options); | ||
function accessor(name) { | ||
const opt = opts[name]; | ||
return typeof opt === 'function' ? opt : () => opt; | ||
var opt = opts[name]; | ||
return typeof opt === 'function' ? opt : function () { | ||
return opt; | ||
}; | ||
} | ||
function layout(tree) { | ||
const wtree = wrap(getWrapper(), tree, node => node.children); | ||
var wtree = wrap(getWrapper(), tree, function (node) { | ||
return node.children; | ||
}); | ||
wtree.update(); | ||
@@ -294,91 +361,31 @@ return wtree.data; | ||
function getFlexNode() { | ||
const nodeSize = accessor('nodeSize'); | ||
const spacing = accessor('spacing'); | ||
return class FlexNode extends hierarchy.prototype.constructor { | ||
constructor(data) { | ||
super(data); | ||
} | ||
var nodeSize = accessor('nodeSize'); | ||
copy() { | ||
const c = wrap(this.constructor, this, node => node.children); | ||
c.each(node => node.data = node.data.data); | ||
return c; | ||
} | ||
var _spacing = accessor('spacing'); | ||
get size() { | ||
return nodeSize(this); | ||
} | ||
return /*#__PURE__*/function (_hierarchy$prototype$) { | ||
_inheritsLoose(FlexNode, _hierarchy$prototype$); | ||
spacing(oNode) { | ||
return spacing(this, oNode); | ||
function FlexNode(data) { | ||
return _hierarchy$prototype$.call(this, data) || this; | ||
} | ||
get nodes() { | ||
return this.descendants(); | ||
} | ||
var _proto = FlexNode.prototype; | ||
get xSize() { | ||
return this.size[0]; | ||
} | ||
_proto.copy = function copy() { | ||
var c = wrap(this.constructor, this, function (node) { | ||
return node.children; | ||
}); | ||
c.each(function (node) { | ||
return node.data = node.data.data; | ||
}); | ||
return c; | ||
}; | ||
get ySize() { | ||
return this.size[1]; | ||
} | ||
_proto.spacing = function spacing(oNode) { | ||
return _spacing(this, oNode); | ||
}; | ||
get top() { | ||
return this.y; | ||
} | ||
get bottom() { | ||
return this.y + this.ySize; | ||
} | ||
get left() { | ||
return this.x - this.xSize / 2; | ||
} | ||
get right() { | ||
return this.x + this.xSize / 2; | ||
} | ||
get root() { | ||
const ancs = this.ancestors(); | ||
return ancs[ancs.length - 1]; | ||
} | ||
get numChildren() { | ||
return this.hasChildren ? this.children.length : 0; | ||
} | ||
get hasChildren() { | ||
return !this.noChildren; | ||
} | ||
get noChildren() { | ||
return this.children === null; | ||
} | ||
get firstChild() { | ||
return this.hasChildren ? this.children[0] : null; | ||
} | ||
get lastChild() { | ||
return this.hasChildren ? this.children[this.numChildren - 1] : null; | ||
} | ||
get extents() { | ||
return (this.children || []).reduce((acc, kid) => FlexNode.maxExtents(acc, kid.extents), this.nodeExtents); | ||
} | ||
get nodeExtents() { | ||
FlexNode.maxExtents = function maxExtents(e0, e1) { | ||
return { | ||
top: this.top, | ||
bottom: this.bottom, | ||
left: this.left, | ||
right: this.right | ||
}; | ||
} | ||
static maxExtents(e0, e1) { | ||
return { | ||
top: Math.min(e0.top, e1.top), | ||
@@ -389,15 +396,112 @@ bottom: Math.max(e0.bottom, e1.bottom), | ||
}; | ||
} | ||
}; | ||
}; | ||
_createClass(FlexNode, [{ | ||
key: "size", | ||
get: function get() { | ||
return nodeSize(this); | ||
} | ||
}, { | ||
key: "nodes", | ||
get: function get() { | ||
return this.descendants(); | ||
} | ||
}, { | ||
key: "xSize", | ||
get: function get() { | ||
return this.size[0]; | ||
} | ||
}, { | ||
key: "ySize", | ||
get: function get() { | ||
return this.size[1]; | ||
} | ||
}, { | ||
key: "top", | ||
get: function get() { | ||
return this.y; | ||
} | ||
}, { | ||
key: "bottom", | ||
get: function get() { | ||
return this.y + this.ySize; | ||
} | ||
}, { | ||
key: "left", | ||
get: function get() { | ||
return this.x - this.xSize / 2; | ||
} | ||
}, { | ||
key: "right", | ||
get: function get() { | ||
return this.x + this.xSize / 2; | ||
} | ||
}, { | ||
key: "root", | ||
get: function get() { | ||
var ancs = this.ancestors(); | ||
return ancs[ancs.length - 1]; | ||
} | ||
}, { | ||
key: "numChildren", | ||
get: function get() { | ||
return this.hasChildren ? this.children.length : 0; | ||
} | ||
}, { | ||
key: "hasChildren", | ||
get: function get() { | ||
return !this.noChildren; | ||
} | ||
}, { | ||
key: "noChildren", | ||
get: function get() { | ||
return this.children === null; | ||
} | ||
}, { | ||
key: "firstChild", | ||
get: function get() { | ||
return this.hasChildren ? this.children[0] : null; | ||
} | ||
}, { | ||
key: "lastChild", | ||
get: function get() { | ||
return this.hasChildren ? this.children[this.numChildren - 1] : null; | ||
} | ||
}, { | ||
key: "extents", | ||
get: function get() { | ||
return (this.children || []).reduce(function (acc, kid) { | ||
return FlexNode.maxExtents(acc, kid.extents); | ||
}, this.nodeExtents); | ||
} | ||
}, { | ||
key: "nodeExtents", | ||
get: function get() { | ||
return { | ||
top: this.top, | ||
bottom: this.bottom, | ||
left: this.left, | ||
right: this.right | ||
}; | ||
} | ||
}]); | ||
return FlexNode; | ||
}(hierarchy.prototype.constructor); | ||
} | ||
function getWrapper() { | ||
const FlexNode = getFlexNode(); | ||
const nodeSize = accessor('nodeSize'); | ||
const spacing = accessor('spacing'); | ||
return class extends FlexNode { | ||
constructor(data) { | ||
super(data); | ||
Object.assign(this, { | ||
var FlexNode = getFlexNode(); | ||
var nodeSize = accessor('nodeSize'); | ||
var _spacing2 = accessor('spacing'); | ||
return /*#__PURE__*/function (_FlexNode) { | ||
_inheritsLoose(_class, _FlexNode); | ||
function _class(data) { | ||
var _this; | ||
_this = _FlexNode.call(this, data) || this; | ||
Object.assign(_assertThisInitialized(_this), { | ||
x: 0, | ||
@@ -409,49 +513,56 @@ y: 0, | ||
change: 0, | ||
lExt: this, | ||
lExt: _assertThisInitialized(_this), | ||
lExtRelX: 0, | ||
lThr: null, | ||
rExt: this, | ||
rExt: _assertThisInitialized(_this), | ||
rExtRelX: 0, | ||
rThr: null | ||
}); | ||
return _this; | ||
} | ||
get size() { | ||
return nodeSize(this.data); | ||
} | ||
var _proto2 = _class.prototype; | ||
spacing(oNode) { | ||
return spacing(this.data, oNode.data); | ||
} | ||
_proto2.spacing = function spacing(oNode) { | ||
return _spacing2(this.data, oNode.data); | ||
}; | ||
get x() { | ||
return this.data.x; | ||
} | ||
set x(v) { | ||
this.data.x = v; | ||
} | ||
get y() { | ||
return this.data.y; | ||
} | ||
set y(v) { | ||
this.data.y = v; | ||
} | ||
update() { | ||
_proto2.update = function update() { | ||
layoutChildren(this); | ||
resolveX(this); | ||
return this; | ||
} | ||
}; | ||
}; | ||
_createClass(_class, [{ | ||
key: "size", | ||
get: function get() { | ||
return nodeSize(this.data); | ||
} | ||
}, { | ||
key: "x", | ||
get: function get() { | ||
return this.data.x; | ||
}, | ||
set: function set(v) { | ||
this.data.x = v; | ||
} | ||
}, { | ||
key: "y", | ||
get: function get() { | ||
return this.data.y; | ||
}, | ||
set: function set(v) { | ||
this.data.y = v; | ||
} | ||
}]); | ||
return _class; | ||
}(FlexNode); | ||
} | ||
function wrap(FlexClass, treeData, children) { | ||
const _wrap = (data, parent) => { | ||
const node = new FlexClass(data); | ||
var _wrap = function _wrap(data, parent) { | ||
var node = new FlexClass(data); | ||
Object.assign(node, { | ||
parent, | ||
parent: parent, | ||
depth: parent === null ? 0 : parent.depth + 1, | ||
@@ -461,10 +572,14 @@ height: 0, | ||
}); | ||
const kidsData = children(data) || []; | ||
node.children = kidsData.length === 0 ? null : kidsData.map(kd => _wrap(kd, node)); | ||
var kidsData = children(data) || []; | ||
node.children = kidsData.length === 0 ? null : kidsData.map(function (kd) { | ||
return _wrap(kd, node); | ||
}); | ||
if (node.children) { | ||
Object.assign(node, node.children.reduce((hl, kid) => ({ | ||
height: Math.max(hl.height, kid.height + 1), | ||
length: hl.length + kid.length | ||
}), node)); | ||
Object.assign(node, node.children.reduce(function (hl, kid) { | ||
return { | ||
height: Math.max(hl.height, kid.height + 1), | ||
length: hl.length + kid.length | ||
}; | ||
}, node)); | ||
} | ||
@@ -479,33 +594,29 @@ | ||
Object.assign(layout, { | ||
nodeSize(arg) { | ||
nodeSize: function nodeSize(arg) { | ||
return arguments.length ? (opts.nodeSize = arg, layout) : opts.nodeSize; | ||
}, | ||
spacing(arg) { | ||
spacing: function spacing(arg) { | ||
return arguments.length ? (opts.spacing = arg, layout) : opts.spacing; | ||
}, | ||
children(arg) { | ||
children: function children(arg) { | ||
return arguments.length ? (opts.children = arg, layout) : opts.children; | ||
}, | ||
hierarchy(treeData, children) { | ||
const kids = typeof children === 'undefined' ? opts.children : children; | ||
hierarchy: function hierarchy(treeData, children) { | ||
var kids = typeof children === 'undefined' ? opts.children : children; | ||
return wrap(getFlexNode(), treeData, kids); | ||
}, | ||
dump: function dump(tree) { | ||
var nodeSize = accessor('nodeSize'); | ||
dump(tree) { | ||
const nodeSize = accessor('nodeSize'); | ||
const _dump = i0 => node => { | ||
const i1 = i0 + ' '; | ||
const i2 = i0 + ' '; | ||
const { | ||
x, | ||
y | ||
} = node; | ||
const size = nodeSize(node); | ||
const kids = node.children || []; | ||
const kdumps = kids.length === 0 ? ' ' : `,${i1}children: [${i2}${kids.map(_dump(i2)).join(i2)}${i1}],${i0}`; | ||
return `{ size: [${size.join(', ')}],${i1}x: ${x}, y: ${y}${kdumps}},`; | ||
var _dump = function _dump(i0) { | ||
return function (node) { | ||
var i1 = i0 + ' '; | ||
var i2 = i0 + ' '; | ||
var x = node.x, | ||
y = node.y; | ||
var size = nodeSize(node); | ||
var kids = node.children || []; | ||
var kdumps = kids.length === 0 ? ' ' : "," + i1 + "children: [" + i2 + kids.map(_dump(i2)).join(i2) + i1 + "]," + i0; | ||
return "{ size: [" + size.join(', ') + "]," + i1 + "x: " + x + ", y: " + y + kdumps + "},"; | ||
}; | ||
}; | ||
@@ -515,3 +626,2 @@ | ||
} | ||
}); | ||
@@ -522,12 +632,17 @@ return layout; | ||
const layoutChildren = (w, y = 0) => { | ||
var layoutChildren = function layoutChildren(w, y) { | ||
if (y === void 0) { | ||
y = 0; | ||
} | ||
w.y = y; | ||
(w.children || []).reduce((acc, kid) => { | ||
const [i, lastLows] = acc; | ||
(w.children || []).reduce(function (acc, kid) { | ||
var i = acc[0], | ||
lastLows = acc[1]; | ||
layoutChildren(kid, w.y + w.ySize); // The lowest vertical coordinate while extreme nodes still point | ||
// in current subtree. | ||
const lowY = (i === 0 ? kid.lExt : kid.rExt).bottom; | ||
var lowY = (i === 0 ? kid.lExt : kid.rExt).bottom; | ||
if (i !== 0) separate(w, i, lastLows); | ||
const lows = updateLows(lowY, i, lastLows); | ||
var lows = updateLows(lowY, i, lastLows); | ||
return [i + 1, lows]; | ||
@@ -544,3 +659,3 @@ }, [0, null]); | ||
const resolveX = (w, prevSum, parentX) => { | ||
var resolveX = function resolveX(w, prevSum, parentX) { | ||
// A call to resolveX without arguments is assumed to be for the root of | ||
@@ -553,7 +668,9 @@ // the tree. This will set the root's x-coord to zero. | ||
const sum = prevSum + w.relX; | ||
var sum = prevSum + w.relX; | ||
w.relX = sum + w.prelim - parentX; | ||
w.prelim = 0; | ||
w.x = parentX + w.relX; | ||
(w.children || []).forEach(k => resolveX(k, sum, w.x)); | ||
(w.children || []).forEach(function (k) { | ||
return resolveX(k, sum, w.x); | ||
}); | ||
return w; | ||
@@ -564,7 +681,8 @@ }; // Process shift and change for all children, to add intermediate spacing to | ||
const shiftChange = w => { | ||
(w.children || []).reduce((acc, child) => { | ||
const [lastShiftSum, lastChangeSum] = acc; | ||
const shiftSum = lastShiftSum + child.shift; | ||
const changeSum = lastChangeSum + shiftSum + child.change; | ||
var shiftChange = function shiftChange(w) { | ||
(w.children || []).reduce(function (acc, child) { | ||
var lastShiftSum = acc[0], | ||
lastChangeSum = acc[1]; | ||
var shiftSum = lastShiftSum + child.shift; | ||
var changeSum = lastChangeSum + shiftSum + child.change; | ||
child.relX += changeSum; | ||
@@ -578,10 +696,10 @@ return [shiftSum, changeSum]; | ||
const separate = (w, i, lows) => { | ||
const lSib = w.children[i - 1]; | ||
const curSubtree = w.children[i]; | ||
let rContour = lSib; | ||
let rSumMods = lSib.relX; | ||
let lContour = curSubtree; | ||
let lSumMods = curSubtree.relX; | ||
let isFirst = true; | ||
var separate = function separate(w, i, lows) { | ||
var lSib = w.children[i - 1]; | ||
var curSubtree = w.children[i]; | ||
var rContour = lSib; | ||
var rSumMods = lSib.relX; | ||
var lContour = curSubtree; | ||
var lSumMods = curSubtree.relX; | ||
var isFirst = true; | ||
@@ -593,3 +711,3 @@ while (rContour && lContour) { | ||
const dist = rSumMods + rContour.prelim - (lSumMods + lContour.prelim) + rContour.xSize / 2 + lContour.xSize / 2 + rContour.spacing(lContour); | ||
var dist = rSumMods + rContour.prelim - (lSumMods + lContour.prelim) + rContour.xSize / 2 + lContour.xSize / 2 + rContour.spacing(lContour); | ||
@@ -605,4 +723,4 @@ if (dist > 0 || dist < 0 && isFirst) { | ||
const rightBottom = rContour.bottom; | ||
const leftBottom = lContour.bottom; | ||
var rightBottom = rContour.bottom; | ||
var leftBottom = lContour.bottom; | ||
@@ -629,3 +747,3 @@ if (rightBottom <= leftBottom) { | ||
const moveSubtree = (subtree, distance) => { | ||
var moveSubtree = function moveSubtree(subtree, distance) { | ||
subtree.relX += distance; | ||
@@ -636,8 +754,8 @@ subtree.lExtRelX += distance; | ||
const distributeExtra = (w, curSubtreeI, leftSibI, dist) => { | ||
const curSubtree = w.children[curSubtreeI]; | ||
const n = curSubtreeI - leftSibI; // Are there intermediate children? | ||
var distributeExtra = function distributeExtra(w, curSubtreeI, leftSibI, dist) { | ||
var curSubtree = w.children[curSubtreeI]; | ||
var n = curSubtreeI - leftSibI; // Are there intermediate children? | ||
if (n > 1) { | ||
const delta = dist / n; | ||
var delta = dist / n; | ||
w.children[leftSibI + 1].shift += delta; | ||
@@ -649,17 +767,17 @@ curSubtree.shift -= delta; | ||
const nextLContour = w => { | ||
var nextLContour = function nextLContour(w) { | ||
return w.hasChildren ? w.firstChild : w.lThr; | ||
}; | ||
const nextRContour = w => { | ||
var nextRContour = function nextRContour(w) { | ||
return w.hasChildren ? w.lastChild : w.rThr; | ||
}; | ||
const setLThr = (w, i, lContour, lSumMods) => { | ||
const firstChild = w.firstChild; | ||
const lExt = firstChild.lExt; | ||
const curSubtree = w.children[i]; | ||
var setLThr = function setLThr(w, i, lContour, lSumMods) { | ||
var firstChild = w.firstChild; | ||
var lExt = firstChild.lExt; | ||
var curSubtree = w.children[i]; | ||
lExt.lThr = lContour; // Change relX so that the sum of modifier after following thread is correct. | ||
const diff = lSumMods - lContour.relX - firstChild.lExtRelX; | ||
var diff = lSumMods - lContour.relX - firstChild.lExtRelX; | ||
lExt.relX += diff; // Change preliminary x coordinate so that the node does not move. | ||
@@ -674,8 +792,8 @@ | ||
const setRThr = (w, i, rContour, rSumMods) => { | ||
const curSubtree = w.children[i]; | ||
const rExt = curSubtree.rExt; | ||
const lSib = w.children[i - 1]; | ||
var setRThr = function setRThr(w, i, rContour, rSumMods) { | ||
var curSubtree = w.children[i]; | ||
var rExt = curSubtree.rExt; | ||
var lSib = w.children[i - 1]; | ||
rExt.rThr = rContour; | ||
const diff = rSumMods - rContour.relX - curSubtree.rExtRelX; | ||
var diff = rSumMods - rContour.relX - curSubtree.rExtRelX; | ||
rExt.relX += diff; | ||
@@ -688,9 +806,9 @@ rExt.prelim -= diff; | ||
const positionRoot = w => { | ||
var positionRoot = function positionRoot(w) { | ||
if (w.hasChildren) { | ||
const k0 = w.firstChild; | ||
const kf = w.lastChild; | ||
const prelim = (k0.prelim + k0.relX - k0.xSize / 2 + kf.relX + kf.prelim + kf.xSize / 2) / 2; | ||
var k0 = w.firstChild; | ||
var kf = w.lastChild; | ||
var prelim = (k0.prelim + k0.relX - k0.xSize / 2 + kf.relX + kf.prelim + kf.xSize / 2) / 2; | ||
Object.assign(w, { | ||
prelim, | ||
prelim: prelim, | ||
lExt: k0.lExt, | ||
@@ -706,10 +824,12 @@ lExtRelX: k0.lExtRelX, | ||
const updateLows = (lowY, index, lastLows) => { | ||
var updateLows = function updateLows(lowY, index, lastLows) { | ||
// Remove siblings that are hidden by the new subtree. | ||
while (lastLows !== null && lowY >= lastLows.lowY) lastLows = lastLows.next; // Prepend the new subtree. | ||
while (lastLows !== null && lowY >= lastLows.lowY) { | ||
lastLows = lastLows.next; | ||
} // Prepend the new subtree. | ||
return { | ||
lowY, | ||
index, | ||
lowY: lowY, | ||
index: index, | ||
next: lastLows | ||
@@ -719,4 +839,3 @@ }; | ||
/*! markmap-common v0.1.3 | MIT License */ | ||
/*! markmap-common v0.1.4 | MIT License */ | ||
class Hook { | ||
@@ -749,2 +868,20 @@ constructor() { | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
const uniqId = Math.random().toString(36).slice(2, 8); | ||
@@ -920,2 +1057,11 @@ let globalIndex = 0; | ||
function minBy(numbers, by) { | ||
const index = d3__namespace.minIndex(numbers, by); | ||
return numbers[index]; | ||
} | ||
function stopPropagation(e) { | ||
e.stopPropagation(); | ||
} | ||
function createViewHooks() { | ||
@@ -946,6 +1092,6 @@ return { | ||
this.viewHooks = createViewHooks(); | ||
this.svg = svg.datum ? svg : d3.select(svg); | ||
this.svg = svg.datum ? svg : d3__namespace.select(svg); | ||
this.styleNode = this.svg.append('style'); | ||
this.zoom = d3.zoom().on('zoom', this.handleZoom); | ||
this.options = _extends({}, Markmap.defaultOptions, opts); | ||
this.zoom = d3__namespace.zoom().on('zoom', this.handleZoom); | ||
this.options = _extends$1({}, Markmap.defaultOptions, opts); | ||
this.state = { | ||
@@ -972,5 +1118,7 @@ id: this.options.id || getId() | ||
const styleText = `\ | ||
.${id} { line-height: 1; } | ||
.${id} a { color: #0097e6; } | ||
.${id} a:hover { color: #00a8ff; } | ||
.${id}-g > path { fill: none; } | ||
.${id}-g > g > circle { cursor: pointer; } | ||
.${id}-fo > div { display: inline-block; font: ${nodeFont}; white-space: nowrap; } | ||
@@ -983,3 +1131,2 @@ .${id}-fo code { font-size: calc(1em - 2px); color: #555; background-color: #f0f0f0; border-radius: 2px; } | ||
.${id}-fo pre { margin: 0; padding: .2em .4em; } | ||
.${id}-g > g { cursor: pointer; } | ||
${extraStyle} | ||
@@ -1008,3 +1155,3 @@ `; | ||
} = d; | ||
data.p = _extends({}, data.p, { | ||
data.p = _extends$1({}, data.p, { | ||
f: !((_data$p = data.p) != null && _data$p.f) | ||
@@ -1048,3 +1195,3 @@ }); | ||
item.c = (_item$c = item.c) == null ? void 0 : _item$c.map(child => _extends({}, child)); | ||
item.c = (_item$c = item.c) == null ? void 0 : _item$c.map(child => _extends$1({}, child)); | ||
i += 1; | ||
@@ -1054,3 +1201,3 @@ const el = document.createElement('div'); | ||
container.append(el); | ||
item.p = _extends({}, item.p, { | ||
item.p = _extends$1({}, item.p, { | ||
// unique ID | ||
@@ -1086,3 +1233,3 @@ i, | ||
setData(data, opts) { | ||
if (!data) data = _extends({}, this.state.data); | ||
if (!data) data = _extends$1({}, this.state.data); | ||
this.state.data = data; | ||
@@ -1123,7 +1270,7 @@ this.initializeData(data); | ||
const links = tree.links(); | ||
const linkShape = d3.linkHorizontal(); | ||
const minX = d3.min(descendants, d => d.x - d.xSize / 2); | ||
const maxX = d3.max(descendants, d => d.x + d.xSize / 2); | ||
const minY = d3.min(descendants, d => d.y); | ||
const maxY = d3.max(descendants, d => d.y + d.ySizeInner); | ||
const linkShape = d3__namespace.linkHorizontal(); | ||
const minX = d3__namespace.min(descendants, d => d.x - d.xSize / 2); | ||
const maxX = d3__namespace.max(descendants, d => d.x + d.xSize / 2); | ||
const minY = d3__namespace.min(descendants, d => d.y); | ||
const maxY = d3__namespace.max(descendants, d => d.y + d.ySizeInner); | ||
Object.assign(this.state, { | ||
@@ -1141,3 +1288,3 @@ minX, | ||
const node = this.g.selectAll(childSelector('g')).data(descendants, d => d.data.p.k); | ||
const nodeEnter = node.enter().append('g').attr('transform', d => `translate(${y0 + origin.ySizeInner - d.ySizeInner},${x0 + origin.xSize / 2 - d.xSize})`).on('click', this.handleClick); | ||
const nodeEnter = node.enter().append('g').attr('transform', d => `translate(${y0 + origin.ySizeInner - d.ySizeInner},${x0 + origin.xSize / 2 - d.xSize})`); | ||
const nodeExit = this.transition(node.exit()); | ||
@@ -1154,3 +1301,3 @@ nodeExit.select('rect').attr('width', 0).attr('x', d => d.ySizeInner); | ||
const circle = nodeMerge.selectAll(childSelector('circle')).data(d => d.data.c ? [d] : [], d => d.data.p.k).join(enter => { | ||
return enter.append('circle').attr('stroke-width', '1.5').attr('cx', d => d.ySizeInner).attr('cy', d => d.xSize).attr('r', 0); | ||
return enter.append('circle').attr('stroke-width', '1.5').attr('cx', d => d.ySizeInner).attr('cy', d => d.xSize).attr('r', 0).on('click', this.handleClick); | ||
}, update => update, exit => exit.remove()); | ||
@@ -1163,3 +1310,3 @@ this.transition(circle).attr('r', 6).attr('stroke', d => color(d.data)).attr('fill', d => { | ||
const foreignObject = nodeMerge.selectAll(childSelector('foreignObject')).data(d => [d], d => d.data.p.k).join(enter => { | ||
const fo = enter.append('foreignObject').attr('class', `${id}-fo`).attr('x', paddingX).attr('y', 0).style('opacity', 0).attr('height', d => d.xSize); | ||
const fo = enter.append('foreignObject').attr('class', `${id}-fo`).attr('x', paddingX).attr('y', 0).style('opacity', 0).attr('height', d => d.xSize).on('mousedown', stopPropagation).on('dblclick', stopPropagation); | ||
fo.append('xhtml:div').select(function select(d) { | ||
@@ -1207,4 +1354,8 @@ const node = d.data.p.el.cloneNode(true); | ||
} | ||
/** | ||
* Fit the content to the viewport. | ||
*/ | ||
fit() { | ||
async fit() { | ||
const svgNode = this.svg.node(); | ||
@@ -1227,8 +1378,50 @@ const { | ||
const scale = Math.min(offsetWidth / naturalWidth * fitRatio, offsetHeight / naturalHeight * fitRatio, 2); | ||
const initialZoom = d3.zoomIdentity.translate((offsetWidth - naturalWidth * scale) / 2 - minY * scale, (offsetHeight - naturalHeight * scale) / 2 - minX * scale).scale(scale); | ||
const initialZoom = d3__namespace.zoomIdentity.translate((offsetWidth - naturalWidth * scale) / 2 - minY * scale, (offsetHeight - naturalHeight * scale) / 2 - minX * scale).scale(scale); | ||
return this.transition(this.svg).call(this.zoom.transform, initialZoom).end().catch(noop); | ||
} | ||
/** | ||
* Pan the content to make the provided node visible in the viewport. | ||
*/ | ||
rescale(scale) { | ||
async ensureView(node, padding) { | ||
let g; | ||
let itemData; | ||
this.g.selectAll(childSelector('g')).each(function walk(d) { | ||
if (d.data === node) { | ||
g = this; | ||
itemData = d; | ||
} | ||
}); | ||
if (!g || !itemData) return; | ||
const svgNode = this.svg.node(); | ||
const relRect = svgNode.getBoundingClientRect(); | ||
const transform = d3__namespace.zoomTransform(svgNode); | ||
const [left, right] = [itemData.y, itemData.y + itemData.ySizeInner + 2].map(x => x * transform.k + transform.x); | ||
const [top, bottom] = [itemData.x - itemData.xSize / 2, itemData.x + itemData.xSize / 2].map(y => y * transform.k + transform.y); // Skip if the node includes or is included in the container. | ||
const pd = _extends$1({ | ||
left: 0, | ||
right: 0, | ||
top: 0, | ||
bottom: 0 | ||
}, padding); | ||
const dxs = [pd.left - left, relRect.width - pd.right - right]; | ||
const dys = [pd.top - top, relRect.height - pd.bottom - bottom]; | ||
const dx = dxs[0] * dxs[1] > 0 ? minBy(dxs, Math.abs) / transform.k : 0; | ||
const dy = dys[0] * dys[1] > 0 ? minBy(dys, Math.abs) / transform.k : 0; | ||
if (dx || dy) { | ||
const newTransform = transform.translate(dx, dy); | ||
return this.transition(this.svg).call(this.zoom.transform, newTransform).end().catch(noop); | ||
} | ||
} | ||
/** | ||
* Scale content with it pinned at the center of the viewport. | ||
*/ | ||
async rescale(scale) { | ||
const svgNode = this.svg.node(); | ||
const { | ||
@@ -1240,3 +1433,3 @@ width: offsetWidth, | ||
const halfHeight = offsetHeight / 2; | ||
const transform = d3.zoomTransform(svgNode); | ||
const transform = d3__namespace.zoomTransform(svgNode); | ||
const newTransform = transform.translate((halfWidth - transform.x) * (1 - scale) / transform.k, (halfHeight - transform.y) * (1 - scale) / transform.k).scale(scale); | ||
@@ -1273,3 +1466,3 @@ return this.transition(this.svg).call(this.zoom.transform, newTransform).end().catch(noop); | ||
fitRatio: 0.95, | ||
color: (colorFn => node => colorFn(node.p.i))(d3.scaleOrdinal(d3.schemeCategory10)), | ||
color: (colorFn => node => colorFn(node.p.i))(d3__namespace.scaleOrdinal(d3__namespace.schemeCategory10)), | ||
paddingX: 8 | ||
@@ -1276,0 +1469,0 @@ }; |
@@ -1,4 +0,4 @@ | ||
/*! markmap-view v0.2.2 | MIT License */ | ||
!function(t,e){"use strict";function n(){return(n=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(this,arguments)}function r(t){var e=0,n=t.children,r=n&&n.length;if(r)for(;--r>=0;)e+=n[r].value;else e=1;t.value=e}function i(t,e){var n,r,i,o,h,c=new l(t),d=+t.value&&(c.value=t.value),u=[c];for(null==e&&(e=s);n=u.pop();)if(d&&(n.value=+n.data.value),(i=e(n.data))&&(h=i.length))for(n.children=new Array(h),o=h-1;o>=0;--o)u.push(r=n.children[o]=new l(i[o])),r.parent=n,r.depth=n.depth+1;return c.eachBefore(a)}function s(t){return t.children}function o(t){t.data=t.data.data}function a(t){var e=0;do{t.height=e}while((t=t.parent)&&t.height<++e)}function l(t){this.data=t,this.depth=this.height=0,this.parent=null}l.prototype=i.prototype={constructor:l,count:function(){return this.eachAfter(r)},each:function(t){var e,n,r,i,s=this,o=[s];do{for(e=o.reverse(),o=[];s=e.pop();)if(t(s),n=s.children)for(r=0,i=n.length;r<i;++r)o.push(n[r])}while(o.length);return this},eachAfter:function(t){for(var e,n,r,i=this,s=[i],o=[];i=s.pop();)if(o.push(i),e=i.children)for(n=0,r=e.length;n<r;++n)s.push(e[n]);for(;i=o.pop();)t(i);return this},eachBefore:function(t){for(var e,n,r=this,i=[r];r=i.pop();)if(t(r),e=r.children)for(n=e.length-1;n>=0;--n)i.push(e[n]);return this},sum:function(t){return this.eachAfter((function(e){for(var n=+t(e.data)||0,r=e.children,i=r&&r.length;--i>=0;)n+=r[i].value;e.value=n}))},sort:function(t){return this.eachBefore((function(e){e.children&&e.children.sort(t)}))},path:function(t){for(var e=this,n=function(t,e){if(t===e)return t;var n=t.ancestors(),r=e.ancestors(),i=null;t=n.pop(),e=r.pop();for(;t===e;)i=t,t=n.pop(),e=r.pop();return i}(e,t),r=[e];e!==n;)e=e.parent,r.push(e);for(var i=r.length;t!==n;)r.splice(i,0,t),t=t.parent;return r},ancestors:function(){for(var t=this,e=[t];t=t.parent;)e.push(t);return e},descendants:function(){var t=[];return this.each((function(e){t.push(e)})),t},leaves:function(){var t=[];return this.eachBefore((function(e){e.children||t.push(e)})),t},links:function(){var t=this,e=[];return t.each((function(n){n!==t&&e.push({source:n.parent,target:n})})),e},copy:function(){return i(this).eachBefore(o)}};const h=Object.freeze({children:t=>t.children,nodeSize:t=>t.data.size,spacing:0});function c(t){const e=Object.assign({},h,t);function n(t){const n=e[t];return"function"==typeof n?n:()=>n}function r(t){const e=o(function(){const t=s(),e=n("nodeSize"),r=n("spacing");return class extends t{constructor(t){super(t),Object.assign(this,{x:0,y:0,relX:0,prelim:0,shift:0,change:0,lExt:this,lExtRelX:0,lThr:null,rExt:this,rExtRelX:0,rThr:null})}get size(){return e(this.data)}spacing(t){return r(this.data,t.data)}get x(){return this.data.x}set x(t){this.data.x=t}get y(){return this.data.y}set y(t){this.data.y=t}update(){return d(this),u(this),this}}}(),t,(t=>t.children));return e.update(),e.data}function s(){const t=n("nodeSize"),e=n("spacing");return class n extends i.prototype.constructor{constructor(t){super(t)}copy(){const t=o(this.constructor,this,(t=>t.children));return t.each((t=>t.data=t.data.data)),t}get size(){return t(this)}spacing(t){return e(this,t)}get nodes(){return this.descendants()}get xSize(){return this.size[0]}get ySize(){return this.size[1]}get top(){return this.y}get bottom(){return this.y+this.ySize}get left(){return this.x-this.xSize/2}get right(){return this.x+this.xSize/2}get root(){const t=this.ancestors();return t[t.length-1]}get numChildren(){return this.hasChildren?this.children.length:0}get hasChildren(){return!this.noChildren}get noChildren(){return null===this.children}get firstChild(){return this.hasChildren?this.children[0]:null}get lastChild(){return this.hasChildren?this.children[this.numChildren-1]:null}get extents(){return(this.children||[]).reduce(((t,e)=>n.maxExtents(t,e.extents)),this.nodeExtents)}get nodeExtents(){return{top:this.top,bottom:this.bottom,left:this.left,right:this.right}}static maxExtents(t,e){return{top:Math.min(t.top,e.top),bottom:Math.max(t.bottom,e.bottom),left:Math.min(t.left,e.left),right:Math.max(t.right,e.right)}}}}function o(t,e,n){const r=(e,i)=>{const s=new t(e);Object.assign(s,{parent:i,depth:null===i?0:i.depth+1,height:0,length:1});const o=n(e)||[];return s.children=0===o.length?null:o.map((t=>r(t,s))),s.children&&Object.assign(s,s.children.reduce(((t,e)=>({height:Math.max(t.height,e.height+1),length:t.length+e.length})),s)),s};return r(e,null)}return Object.assign(r,{nodeSize(t){return arguments.length?(e.nodeSize=t,r):e.nodeSize},spacing(t){return arguments.length?(e.spacing=t,r):e.spacing},children(t){return arguments.length?(e.children=t,r):e.children},hierarchy(t,n){const r=void 0===n?e.children:n;return o(s(),t,r)},dump(t){const e=n("nodeSize"),r=t=>n=>{const i=t+" ",s=t+" ",{x:o,y:a}=n,l=e(n),h=n.children||[],c=0===h.length?" ":`,${i}children: [${s}${h.map(r(s)).join(s)}${i}],${t}`;return`{ size: [${l.join(", ")}],${i}x: ${o}, y: ${a}${c}},`};return r("\n")(t)}}),r}c.version="2.1.1";const d=(t,e=0)=>(t.y=e,(t.children||[]).reduce(((e,n)=>{const[r,i]=e;d(n,t.y+t.ySize);const s=(0===r?n.lExt:n.rExt).bottom;0!==r&&f(t,r,i);return[r+1,E(s,r,i)]}),[0,null]),p(t),S(t),t),u=(t,e,n)=>{void 0===e&&(e=-t.relX-t.prelim,n=0);const r=e+t.relX;return t.relX=r+t.prelim-n,t.prelim=0,t.x=n+t.relX,(t.children||[]).forEach((e=>u(e,r,t.x))),t},p=t=>{(t.children||[]).reduce(((t,e)=>{const[n,r]=t,i=n+e.shift,s=r+i+e.change;return e.relX+=s,[i,s]}),[0,0])},f=(t,e,n)=>{const r=t.children[e-1],i=t.children[e];let s=r,o=r.relX,a=i,l=i.relX,h=!0;for(;s&&a;){s.bottom>n.lowY&&(n=n.next);const r=o+s.prelim-(l+a.prelim)+s.xSize/2+a.xSize/2+s.spacing(a);(r>0||r<0&&h)&&(l+=r,g(i,r),m(t,e,n.index,r)),h=!1;const c=s.bottom,d=a.bottom;c<=d&&(s=y(s),s&&(o+=s.relX)),c>=d&&(a=x(a),a&&(l+=a.relX))}!s&&a?v(t,e,a,l):s&&!a&&z(t,e,s,o)},g=(t,e)=>{t.relX+=e,t.lExtRelX+=e,t.rExtRelX+=e},m=(t,e,n,r)=>{const i=t.children[e],s=e-n;if(s>1){const e=r/s;t.children[n+1].shift+=e,i.shift-=e,i.change-=r-e}},x=t=>t.hasChildren?t.firstChild:t.lThr,y=t=>t.hasChildren?t.lastChild:t.rThr,v=(t,e,n,r)=>{const i=t.firstChild,s=i.lExt,o=t.children[e];s.lThr=n;const a=r-n.relX-i.lExtRelX;s.relX+=a,s.prelim-=a,i.lExt=o.lExt,i.lExtRelX=o.lExtRelX},z=(t,e,n,r)=>{const i=t.children[e],s=i.rExt,o=t.children[e-1];s.rThr=n;const a=r-n.relX-i.rExtRelX;s.relX+=a,s.prelim-=a,i.rExt=o.rExt,i.rExtRelX=o.rExtRelX},S=t=>{if(t.hasChildren){const e=t.firstChild,n=t.lastChild,r=(e.prelim+e.relX-e.xSize/2+n.relX+n.prelim+n.xSize/2)/2;Object.assign(t,{prelim:r,lExt:e.lExt,lExtRelX:e.lExtRelX,rExt:n.rExt,rExtRelX:n.rExtRelX})}},E=(t,e,n)=>{for(;null!==n&&t>=n.lowY;)n=n.next;return{lowY:t,index:e,next:n}}; | ||
/*! markmap-common v0.1.3 | MIT License */ | ||
class ${constructor(){this.listeners=[]}tap(t){return this.listeners.push(t),()=>this.revoke(t)}revoke(t){const e=this.listeners.indexOf(t);e>=0&&this.listeners.splice(e,1)}revokeAll(){this.listeners.splice(0)}call(...t){for(const e of this.listeners)e(...t)}}const k=Math.random().toString(36).slice(2,8);let w=0;function X(){}function b(t,e,n="c"){const r=(t,i)=>e(t,(()=>{var e;null==(e=t[n])||e.forEach((e=>{r(e,t)}))}),i);r(t)}function C(t){if(Array.from)return Array.from(t);const e=[];for(let n=0;n<t.length;n+=1)e.push(t[n]);return e}function O(t,...e){const n=(t||"").split(" ").filter(Boolean);return e.forEach((t=>{t&&n.indexOf(t)<0&&n.push(t)})),n.join(" ")}function j(t){if("string"==typeof t){const e=t;t=t=>t.tagName===e}const e=t;return function(){let t=C(this.childNodes);return e&&(t=t.filter((t=>e(t)))),t}}function R(t,e,n){const r=document.createElement(t);return e&&Object.entries(e).forEach((([t,e])=>{r[t]=e})),n&&Object.entries(n).forEach((([t,e])=>{r.setAttribute(t,e)})),r}const M=function(t){const e={};return function(...n){const r=`${n[0]}`;let i=e[r];return i||(i={value:t(...n)},e[r]=i),i.value}}((t=>{document.head.append(R("link",{rel:"preload",as:"script",href:t}))}));function I(t,e){if("script"===t.type)return new Promise(((e,r)=>{var i;document.head.append(R("script",n({},t.data,{onload:e,onerror:r}))),null!=(i=t.data)&&i.src||e()}));if("iife"===t.type){const{fn:n,getParams:r}=t.data;n(...(null==r?void 0:r(e))||[])}}function A(t){"style"===t.type?document.head.append(R("style",{textContent:t.data})):"stylesheet"===t.type&&document.head.append(R("link",n({rel:"stylesheet"},t.data)))}function H(t){const e=t.data;return Math.max(6-2*e.d,1.5)}const B=new $;class N{constructor(t,r){this.options=void 0,this.state=void 0,this.svg=void 0,this.styleNode=void 0,this.g=void 0,this.zoom=void 0,this.viewHooks=void 0,this.revokers=[],["handleZoom","handleClick"].forEach((t=>{this[t]=this[t].bind(this)})),this.viewHooks={transformHtml:new $},this.svg=t.datum?t:e.select(t),this.styleNode=this.svg.append("style"),this.zoom=e.zoom().on("zoom",this.handleZoom),this.options=n({},N.defaultOptions,r),this.state={id:this.options.id||(w+=1,`mm-${k}-${w}`)},this.g=this.svg.append("g").attr("class",`${this.state.id}-g`),this.updateStyle(),this.svg.call(this.zoom),this.revokers.push(B.tap((()=>{this.setData()})))}getStyleContent(){const{style:t,nodeFont:e}=this.options,{id:n}=this.state;return`.${n} a { color: #0097e6; }\n.${n} a:hover { color: #00a8ff; }\n.${n}-g > path { fill: none; }\n.${n}-fo > div { display: inline-block; font: ${e}; white-space: nowrap; }\n.${n}-fo code { font-size: calc(1em - 2px); color: #555; background-color: #f0f0f0; border-radius: 2px; }\n.${n}-fo :not(pre) > code { padding: .2em .4em; }\n.${n}-fo del { text-decoration: line-through; }\n.${n}-fo em { font-style: italic; }\n.${n}-fo strong { font-weight: bolder; }\n.${n}-fo pre { margin: 0; padding: .2em .4em; }\n.${n}-g > g { cursor: pointer; }\n${"function"==typeof t?t(n):""}\n`}updateStyle(){this.svg.attr("class",O(this.svg.attr("class"),this.state.id)),this.styleNode.text(this.getStyleContent())}handleZoom(t){const{transform:e}=t;this.g.attr("transform",e)}handleClick(t,e){var r;const{data:i}=e;i.p=n({},i.p,{f:!(null!=(r=i.p)&&r.f)}),this.renderData(e.data)}initializeData(t){let e=0;const{nodeFont:r,color:i,nodeMinHeight:s}=this.options,{id:o}=this.state,a=document.createElement("div"),l=`${o}-container`;a.className=O(a.className,`${o}-fo`,l);const h=document.createElement("style");h.textContent=`\n${this.getStyleContent()}\n.${l} {\n position: absolute;\n width: 0;\n height: 0;\n top: -100px;\n left: -100px;\n overflow: hidden;\n font: ${r};\n}\n.${l} > div {\n display: inline-block;\n}\n`,document.body.append(h,a),b(t,((t,r)=>{var s;t.c=null==(s=t.c)?void 0:s.map((t=>n({},t))),e+=1;const o=document.createElement("div");o.innerHTML=t.v,a.append(o),t.p=n({},t.p,{i:e,el:o}),i(t),r()}));const c=C(a.childNodes);this.viewHooks.transformHtml.call(this,c),b(t,((t,e,n)=>{var r;const i=t.p.el.getBoundingClientRect();t.v=t.p.el.innerHTML,t.p.s=[Math.ceil(i.width),Math.max(Math.ceil(i.height),s)],t.p.k=`${(null==n||null==(r=n.p)?void 0:r.i)||""}.${t.p.i}:${t.v}`,e()})),a.remove(),h.remove()}setOptions(t){Object.assign(this.options,t)}setData(t,e){t||(t=n({},this.state.data)),this.state.data=t,this.initializeData(t),e&&this.setOptions(e),this.renderData()}renderData(t){var n,r;if(!this.state.data)return;const{spacingHorizontal:i,paddingX:s,spacingVertical:o,autoFit:a,color:l}=this.options,{id:h}=this.state,d=c().children((t=>{var e;return!(null!=(e=t.p)&&e.f)&&t.c})).nodeSize((t=>{const[e,n]=t.data.p.s;return[n,e+(e?2*s:0)+i]})).spacing(((t,e)=>t.parent===e.parent?o:2*o)),u=d.hierarchy(this.state.data);d(u),function(t,e){b(t,((t,n)=>{t.ySizeInner=t.ySize-e,t.y+=e,n()}),"children")}(u,i);const p=u.descendants().reverse(),f=u.links(),g=e.linkHorizontal(),m=e.min(p,(t=>t.x-t.xSize/2)),x=e.max(p,(t=>t.x+t.xSize/2)),y=e.min(p,(t=>t.y)),v=e.max(p,(t=>t.y+t.ySizeInner));Object.assign(this.state,{minX:m,maxX:x,minY:y,maxY:v}),a&&this.fit();const z=t&&p.find((e=>e.data===t))||u,S=null!=(n=z.data.p.x0)?n:z.x,E=null!=(r=z.data.p.y0)?r:z.y,$=this.g.selectAll(j("g")).data(p,(t=>t.data.p.k)),k=$.enter().append("g").attr("transform",(t=>`translate(${E+z.ySizeInner-t.ySizeInner},${S+z.xSize/2-t.xSize})`)).on("click",this.handleClick),w=this.transition($.exit());w.select("rect").attr("width",0).attr("x",(t=>t.ySizeInner)),w.select("foreignObject").style("opacity",0),w.attr("transform",(t=>`translate(${z.y+z.ySizeInner-t.ySizeInner},${z.x+z.xSize/2-t.xSize})`)).remove();const X=$.merge(k);this.transition(X).attr("transform",(t=>`translate(${t.y},${t.x-t.xSize/2})`));const C=X.selectAll(j("rect")).data((t=>[t]),(t=>t.data.p.k)).join((t=>t.append("rect").attr("x",(t=>t.ySizeInner)).attr("y",(t=>t.xSize-H(t)/2)).attr("width",0).attr("height",H)),(t=>t),(t=>t.remove()));this.transition(C).attr("x",-1).attr("width",(t=>t.ySizeInner+2)).attr("fill",(t=>l(t.data)));const O=X.selectAll(j("circle")).data((t=>t.data.c?[t]:[]),(t=>t.data.p.k)).join((t=>t.append("circle").attr("stroke-width","1.5").attr("cx",(t=>t.ySizeInner)).attr("cy",(t=>t.xSize)).attr("r",0)),(t=>t),(t=>t.remove()));this.transition(O).attr("r",6).attr("stroke",(t=>l(t.data))).attr("fill",(t=>{var e;return null!=(e=t.data.p)&&e.f&&t.data.c?l(t.data):"#fff"}));const R=X.selectAll(j("foreignObject")).data((t=>[t]),(t=>t.data.p.k)).join((t=>{const e=t.append("foreignObject").attr("class",`${h}-fo`).attr("x",s).attr("y",0).style("opacity",0).attr("height",(t=>t.xSize));return e.append("xhtml:div").select((function(t){const e=t.data.p.el.cloneNode(!0);return this.replaceWith(e),e})).attr("xmlns","http://www.w3.org/1999/xhtml"),e}),(t=>t),(t=>t.remove())).attr("width",(t=>Math.max(0,t.ySizeInner-2*s)));this.transition(R).style("opacity",1);const M=this.g.selectAll(j("path")).data(f,(t=>t.target.data.p.k)).join((t=>{const e=[E+z.ySizeInner,S+z.xSize/2];return t.insert("path","g").attr("d",g({source:e,target:e}))}),(t=>t),(t=>{const e=[z.y+z.ySizeInner,z.x+z.xSize/2];return this.transition(t).attr("d",g({source:e,target:e})).remove()}));this.transition(M).attr("stroke",(t=>l(t.target.data))).attr("stroke-width",(t=>H(t.target))).attr("d",(t=>{const e=[t.source.y+t.source.ySizeInner,t.source.x+t.source.xSize/2],n=[t.target.y,t.target.x+t.target.xSize/2];return g({source:e,target:n})})),p.forEach((t=>{t.data.p.x0=t.x,t.data.p.y0=t.y}))}transition(t){const{duration:e}=this.options;return t.transition().duration(e)}fit(){const t=this.svg.node(),{width:n,height:r}=t.getBoundingClientRect(),{fitRatio:i}=this.options,{minX:s,maxX:o,minY:a,maxY:l}=this.state,h=l-a,c=o-s,d=Math.min(n/h*i,r/c*i,2),u=e.zoomIdentity.translate((n-h*d)/2-a*d,(r-c*d)/2-s*d).scale(d);return this.transition(this.svg).call(this.zoom.transform,u).end().catch(X)}rescale(t){const n=this.svg.node(),{width:r,height:i}=n.getBoundingClientRect(),s=r/2,o=i/2,a=e.zoomTransform(n),l=a.translate((s-a.x)*(1-t)/a.k,(o-a.y)*(1-t)/a.k).scale(t);return this.transition(this.svg).call(this.zoom.transform,l).end().catch(X)}destroy(){this.svg.remove(),this.revokers.forEach((t=>{t()}))}static create(t,e,n){const r=new N(t,e);return n&&(r.setData(n),r.fit()),r}}var T;N.defaultOptions={duration:500,nodeFont:"300 16px/20px sans-serif",nodeMinHeight:16,spacingVertical:5,spacingHorizontal:80,autoFit:!1,fitRatio:.95,color:(T=e.scaleOrdinal(e.schemeCategory10),t=>T(t.p.i)),paddingX:8},t.Markmap=N,t.loadCSS=function(t){for(const e of t)A(e)},t.loadJS=async function(t,e){const r=t.filter((t=>{var e;return"script"===t.type&&(null==(e=t.data)?void 0:e.src)}));r.length>1&&r.forEach((t=>M(t.data.src))),e=n({getMarkmap:()=>window.markmap},e);for(const n of t)await I(n,e)},t.refreshHook=B}(this.markmap=this.markmap||{},d3); | ||
/*! markmap-view v0.2.3 | MIT License */ | ||
!function(t,e){"use strict";function n(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(n){e[n]=t[n]})),e.default=t,Object.freeze(e)}var r=n(e);function i(){return(i=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(this,arguments)}function o(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function a(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function s(t,e,n){return e&&a(t.prototype,e),n&&a(t,n),t}function c(t,e){return(c=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function l(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,c(t,e)}function h(t){var e=0,n=t.children,r=n&&n.length;if(r)for(;--r>=0;)e+=n[r].value;else e=1;t.value=e}function u(t,e){var n,r,i,o,a,s=new g(t),c=+t.value&&(s.value=t.value),l=[s];for(null==e&&(e=d);n=l.pop();)if(c&&(n.value=+n.data.value),(i=e(n.data))&&(a=i.length))for(n.children=new Array(a),o=a-1;o>=0;--o)l.push(r=n.children[o]=new g(i[o])),r.parent=n,r.depth=n.depth+1;return s.eachBefore(p)}function d(t){return t.children}function f(t){t.data=t.data.data}function p(t){var e=0;do{t.height=e}while((t=t.parent)&&t.height<++e)}function g(t){this.data=t,this.depth=this.height=0,this.parent=null}g.prototype=u.prototype={constructor:g,count:function(){return this.eachAfter(h)},each:function(t){var e,n,r,i,o=this,a=[o];do{for(e=a.reverse(),a=[];o=e.pop();)if(t(o),n=o.children)for(r=0,i=n.length;r<i;++r)a.push(n[r])}while(a.length);return this},eachAfter:function(t){for(var e,n,r,i=this,o=[i],a=[];i=o.pop();)if(a.push(i),e=i.children)for(n=0,r=e.length;n<r;++n)o.push(e[n]);for(;i=a.pop();)t(i);return this},eachBefore:function(t){for(var e,n,r=this,i=[r];r=i.pop();)if(t(r),e=r.children)for(n=e.length-1;n>=0;--n)i.push(e[n]);return this},sum:function(t){return this.eachAfter((function(e){for(var n=+t(e.data)||0,r=e.children,i=r&&r.length;--i>=0;)n+=r[i].value;e.value=n}))},sort:function(t){return this.eachBefore((function(e){e.children&&e.children.sort(t)}))},path:function(t){for(var e=this,n=function(t,e){if(t===e)return t;var n=t.ancestors(),r=e.ancestors(),i=null;t=n.pop(),e=r.pop();for(;t===e;)i=t,t=n.pop(),e=r.pop();return i}(e,t),r=[e];e!==n;)e=e.parent,r.push(e);for(var i=r.length;t!==n;)r.splice(i,0,t),t=t.parent;return r},ancestors:function(){for(var t=this,e=[t];t=t.parent;)e.push(t);return e},descendants:function(){var t=[];return this.each((function(e){t.push(e)})),t},leaves:function(){var t=[];return this.eachBefore((function(e){e.children||t.push(e)})),t},links:function(){var t=this,e=[];return t.each((function(n){n!==t&&e.push({source:n.parent,target:n})})),e},copy:function(){return u(this).eachBefore(f)}};var m=Object.freeze({children:function(t){return t.children},nodeSize:function(t){return t.data.size},spacing:0});function v(t){var e=Object.assign({},m,t);function n(t){var n=e[t];return"function"==typeof n?n:function(){return n}}function r(t){var e,r,c,h=a((e=i(),r=n("nodeSize"),c=n("spacing"),function(t){function e(e){var n;return n=t.call(this,e)||this,Object.assign(o(n),{x:0,y:0,relX:0,prelim:0,shift:0,change:0,lExt:o(n),lExtRelX:0,lThr:null,rExt:o(n),rExtRelX:0,rThr:null}),n}l(e,t);var n=e.prototype;return n.spacing=function(t){return c(this.data,t.data)},n.update=function(){return y(this),x(this),this},s(e,[{key:"size",get:function(){return r(this.data)}},{key:"x",get:function(){return this.data.x},set:function(t){this.data.x=t}},{key:"y",get:function(){return this.data.y},set:function(t){this.data.y=t}}]),e}(e)),t,(function(t){return t.children}));return h.update(),h.data}function i(){var t=n("nodeSize"),e=n("spacing");return function(n){function r(t){return n.call(this,t)||this}l(r,n);var i=r.prototype;return i.copy=function(){var t=a(this.constructor,this,(function(t){return t.children}));return t.each((function(t){return t.data=t.data.data})),t},i.spacing=function(t){return e(this,t)},r.maxExtents=function(t,e){return{top:Math.min(t.top,e.top),bottom:Math.max(t.bottom,e.bottom),left:Math.min(t.left,e.left),right:Math.max(t.right,e.right)}},s(r,[{key:"size",get:function(){return t(this)}},{key:"nodes",get:function(){return this.descendants()}},{key:"xSize",get:function(){return this.size[0]}},{key:"ySize",get:function(){return this.size[1]}},{key:"top",get:function(){return this.y}},{key:"bottom",get:function(){return this.y+this.ySize}},{key:"left",get:function(){return this.x-this.xSize/2}},{key:"right",get:function(){return this.x+this.xSize/2}},{key:"root",get:function(){var t=this.ancestors();return t[t.length-1]}},{key:"numChildren",get:function(){return this.hasChildren?this.children.length:0}},{key:"hasChildren",get:function(){return!this.noChildren}},{key:"noChildren",get:function(){return null===this.children}},{key:"firstChild",get:function(){return this.hasChildren?this.children[0]:null}},{key:"lastChild",get:function(){return this.hasChildren?this.children[this.numChildren-1]:null}},{key:"extents",get:function(){return(this.children||[]).reduce((function(t,e){return r.maxExtents(t,e.extents)}),this.nodeExtents)}},{key:"nodeExtents",get:function(){return{top:this.top,bottom:this.bottom,left:this.left,right:this.right}}}]),r}(u.prototype.constructor)}function a(t,e,n){return function e(r,i){var o=new t(r);Object.assign(o,{parent:i,depth:null===i?0:i.depth+1,height:0,length:1});var a=n(r)||[];return o.children=0===a.length?null:a.map((function(t){return e(t,o)})),o.children&&Object.assign(o,o.children.reduce((function(t,e){return{height:Math.max(t.height,e.height+1),length:t.length+e.length}}),o)),o}(e,null)}return Object.assign(r,{nodeSize:function(t){return arguments.length?(e.nodeSize=t,r):e.nodeSize},spacing:function(t){return arguments.length?(e.spacing=t,r):e.spacing},children:function(t){return arguments.length?(e.children=t,r):e.children},hierarchy:function(t,n){var r=void 0===n?e.children:n;return a(i(),t,r)},dump:function(t){var e=n("nodeSize");return function t(n){return function(r){var i=n+" ",o=n+" ",a=r.x,s=r.y,c=e(r),l=r.children||[],h=0===l.length?" ":","+i+"children: ["+o+l.map(t(o)).join(o)+i+"],"+n;return"{ size: ["+c.join(", ")+"],"+i+"x: "+a+", y: "+s+h+"},"}}("\n")(t)}}),r}v.version="2.1.1";var y=function t(e,n){return void 0===n&&(n=0),e.y=n,(e.children||[]).reduce((function(n,r){var i=n[0],o=n[1];t(r,e.y+e.ySize);var a=(0===i?r.lExt:r.rExt).bottom;return 0!==i&&k(e,i,o),[i+1,C(a,i,o)]}),[0,null]),z(e),$(e),e},x=function t(e,n,r){void 0===n&&(n=-e.relX-e.prelim,r=0);var i=n+e.relX;return e.relX=i+e.prelim-r,e.prelim=0,e.x=r+e.relX,(e.children||[]).forEach((function(n){return t(n,i,e.x)})),e},z=function(t){(t.children||[]).reduce((function(t,e){var n=t[0],r=t[1],i=n+e.shift,o=r+i+e.change;return e.relX+=o,[i,o]}),[0,0])},k=function(t,e,n){for(var r=t.children[e-1],i=t.children[e],o=r,a=r.relX,s=i,c=i.relX,l=!0;o&&s;){o.bottom>n.lowY&&(n=n.next);var h=a+o.prelim-(c+s.prelim)+o.xSize/2+s.xSize/2+o.spacing(s);(h>0||h<0&&l)&&(c+=h,S(i,h),b(t,e,n.index,h)),l=!1;var u=o.bottom,d=s.bottom;u<=d&&(o=w(o))&&(a+=o.relX),u>=d&&(s=E(s))&&(c+=s.relX)}!o&&s?X(t,e,s,c):o&&!s&&O(t,e,o,a)},S=function(t,e){t.relX+=e,t.lExtRelX+=e,t.rExtRelX+=e},b=function(t,e,n,r){var i=t.children[e],o=e-n;if(o>1){var a=r/o;t.children[n+1].shift+=a,i.shift-=a,i.change-=r-a}},E=function(t){return t.hasChildren?t.firstChild:t.lThr},w=function(t){return t.hasChildren?t.lastChild:t.rThr},X=function(t,e,n,r){var i=t.firstChild,o=i.lExt,a=t.children[e];o.lThr=n;var s=r-n.relX-i.lExtRelX;o.relX+=s,o.prelim-=s,i.lExt=a.lExt,i.lExtRelX=a.lExtRelX},O=function(t,e,n,r){var i=t.children[e],o=i.rExt,a=t.children[e-1];o.rThr=n;var s=r-n.relX-i.rExtRelX;o.relX+=s,o.prelim-=s,i.rExt=a.rExt,i.rExtRelX=a.rExtRelX},$=function(t){if(t.hasChildren){var e=t.firstChild,n=t.lastChild,r=(e.prelim+e.relX-e.xSize/2+n.relX+n.prelim+n.xSize/2)/2;Object.assign(t,{prelim:r,lExt:e.lExt,lExtRelX:e.lExtRelX,rExt:n.rExt,rExtRelX:n.rExtRelX})}},C=function(t,e,n){for(;null!==n&&t>=n.lowY;)n=n.next;return{lowY:t,index:e,next:n}}; | ||
/*! markmap-common v0.1.4 | MIT License */ | ||
class j{constructor(){this.listeners=[]}tap(t){return this.listeners.push(t),()=>this.revoke(t)}revoke(t){const e=this.listeners.indexOf(t);e>=0&&this.listeners.splice(e,1)}revokeAll(){this.listeners.splice(0)}call(...t){for(const e of this.listeners)e(...t)}}function M(){return(M=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(this,arguments)}const R=Math.random().toString(36).slice(2,8);let I=0;function A(){}function H(t,e,n="c"){const r=(t,i)=>e(t,(()=>{var e;null==(e=t[n])||e.forEach((e=>{r(e,t)}))}),i);r(t)}function B(t){if(Array.from)return Array.from(t);const e=[];for(let n=0;n<t.length;n+=1)e.push(t[n]);return e}function T(t,...e){const n=(t||"").split(" ").filter(Boolean);return e.forEach((t=>{t&&n.indexOf(t)<0&&n.push(t)})),n.join(" ")}function N(t){if("string"==typeof t){const e=t;t=t=>t.tagName===e}const e=t;return function(){let t=B(this.childNodes);return e&&(t=t.filter((t=>e(t)))),t}}function D(t,e,n){const r=document.createElement(t);return e&&Object.entries(e).forEach((([t,e])=>{r[t]=e})),n&&Object.entries(n).forEach((([t,e])=>{r.setAttribute(t,e)})),r}const P=function(t){const e={};return function(...n){const r=`${n[0]}`;let i=e[r];return i||(i={value:t(...n)},e[r]=i),i.value}}((t=>{document.head.append(D("link",{rel:"preload",as:"script",href:t}))}));function Y(t,e){if("script"===t.type)return new Promise(((e,n)=>{var r;document.head.append(D("script",M({},t.data,{onload:e,onerror:n}))),null!=(r=t.data)&&r.src||e()}));if("iife"===t.type){const{fn:n,getParams:r}=t.data;n(...(null==r?void 0:r(e))||[])}}function _(t){"style"===t.type?document.head.append(D("style",{textContent:t.data})):"stylesheet"===t.type&&document.head.append(D("link",M({rel:"stylesheet"},t.data)))}function F(t){const e=t.data;return Math.max(6-2*e.d,1.5)}function V(t,e){return t[r.minIndex(t,e)]}function Z(t){t.stopPropagation()}const L=new j;class J{constructor(t,e){this.options=void 0,this.state=void 0,this.svg=void 0,this.styleNode=void 0,this.g=void 0,this.zoom=void 0,this.viewHooks=void 0,this.revokers=[],["handleZoom","handleClick"].forEach((t=>{this[t]=this[t].bind(this)})),this.viewHooks={transformHtml:new j},this.svg=t.datum?t:r.select(t),this.styleNode=this.svg.append("style"),this.zoom=r.zoom().on("zoom",this.handleZoom),this.options=i({},J.defaultOptions,e),this.state={id:this.options.id||(I+=1,`mm-${R}-${I}`)},this.g=this.svg.append("g").attr("class",`${this.state.id}-g`),this.updateStyle(),this.svg.call(this.zoom),this.revokers.push(L.tap((()=>{this.setData()})))}getStyleContent(){const{style:t,nodeFont:e}=this.options,{id:n}=this.state;return`.${n} { line-height: 1; }\n.${n} a { color: #0097e6; }\n.${n} a:hover { color: #00a8ff; }\n.${n}-g > path { fill: none; }\n.${n}-g > g > circle { cursor: pointer; }\n.${n}-fo > div { display: inline-block; font: ${e}; white-space: nowrap; }\n.${n}-fo code { font-size: calc(1em - 2px); color: #555; background-color: #f0f0f0; border-radius: 2px; }\n.${n}-fo :not(pre) > code { padding: .2em .4em; }\n.${n}-fo del { text-decoration: line-through; }\n.${n}-fo em { font-style: italic; }\n.${n}-fo strong { font-weight: bolder; }\n.${n}-fo pre { margin: 0; padding: .2em .4em; }\n${"function"==typeof t?t(n):""}\n`}updateStyle(){this.svg.attr("class",T(this.svg.attr("class"),this.state.id)),this.styleNode.text(this.getStyleContent())}handleZoom(t){const{transform:e}=t;this.g.attr("transform",e)}handleClick(t,e){var n;const{data:r}=e;r.p=i({},r.p,{f:!(null!=(n=r.p)&&n.f)}),this.renderData(e.data)}initializeData(t){let e=0;const{nodeFont:n,color:r,nodeMinHeight:o}=this.options,{id:a}=this.state,s=document.createElement("div"),c=`${a}-container`;s.className=T(s.className,`${a}-fo`,c);const l=document.createElement("style");l.textContent=`\n${this.getStyleContent()}\n.${c} {\n position: absolute;\n width: 0;\n height: 0;\n top: -100px;\n left: -100px;\n overflow: hidden;\n font: ${n};\n}\n.${c} > div {\n display: inline-block;\n}\n`,document.body.append(l,s),H(t,((t,n)=>{var o;t.c=null==(o=t.c)?void 0:o.map((t=>i({},t))),e+=1;const a=document.createElement("div");a.innerHTML=t.v,s.append(a),t.p=i({},t.p,{i:e,el:a}),r(t),n()}));const h=B(s.childNodes);this.viewHooks.transformHtml.call(this,h),H(t,((t,e,n)=>{var r;const i=t.p.el.getBoundingClientRect();t.v=t.p.el.innerHTML,t.p.s=[Math.ceil(i.width),Math.max(Math.ceil(i.height),o)],t.p.k=`${(null==n||null==(r=n.p)?void 0:r.i)||""}.${t.p.i}:${t.v}`,e()})),s.remove(),l.remove()}setOptions(t){Object.assign(this.options,t)}setData(t,e){t||(t=i({},this.state.data)),this.state.data=t,this.initializeData(t),e&&this.setOptions(e),this.renderData()}renderData(t){var e,n;if(!this.state.data)return;const{spacingHorizontal:i,paddingX:o,spacingVertical:a,autoFit:s,color:c}=this.options,{id:l}=this.state,h=v().children((t=>{var e;return!(null!=(e=t.p)&&e.f)&&t.c})).nodeSize((t=>{const[e,n]=t.data.p.s;return[n,e+(e?2*o:0)+i]})).spacing(((t,e)=>t.parent===e.parent?a:2*a)),u=h.hierarchy(this.state.data);h(u),function(t,e){H(t,((t,n)=>{t.ySizeInner=t.ySize-e,t.y+=e,n()}),"children")}(u,i);const d=u.descendants().reverse(),f=u.links(),p=r.linkHorizontal(),g=r.min(d,(t=>t.x-t.xSize/2)),m=r.max(d,(t=>t.x+t.xSize/2)),y=r.min(d,(t=>t.y)),x=r.max(d,(t=>t.y+t.ySizeInner));Object.assign(this.state,{minX:g,maxX:m,minY:y,maxY:x}),s&&this.fit();const z=t&&d.find((e=>e.data===t))||u,k=null!=(e=z.data.p.x0)?e:z.x,S=null!=(n=z.data.p.y0)?n:z.y,b=this.g.selectAll(N("g")).data(d,(t=>t.data.p.k)),E=b.enter().append("g").attr("transform",(t=>`translate(${S+z.ySizeInner-t.ySizeInner},${k+z.xSize/2-t.xSize})`)),w=this.transition(b.exit());w.select("rect").attr("width",0).attr("x",(t=>t.ySizeInner)),w.select("foreignObject").style("opacity",0),w.attr("transform",(t=>`translate(${z.y+z.ySizeInner-t.ySizeInner},${z.x+z.xSize/2-t.xSize})`)).remove();const X=b.merge(E);this.transition(X).attr("transform",(t=>`translate(${t.y},${t.x-t.xSize/2})`));const O=X.selectAll(N("rect")).data((t=>[t]),(t=>t.data.p.k)).join((t=>t.append("rect").attr("x",(t=>t.ySizeInner)).attr("y",(t=>t.xSize-F(t)/2)).attr("width",0).attr("height",F)),(t=>t),(t=>t.remove()));this.transition(O).attr("x",-1).attr("width",(t=>t.ySizeInner+2)).attr("fill",(t=>c(t.data)));const $=X.selectAll(N("circle")).data((t=>t.data.c?[t]:[]),(t=>t.data.p.k)).join((t=>t.append("circle").attr("stroke-width","1.5").attr("cx",(t=>t.ySizeInner)).attr("cy",(t=>t.xSize)).attr("r",0).on("click",this.handleClick)),(t=>t),(t=>t.remove()));this.transition($).attr("r",6).attr("stroke",(t=>c(t.data))).attr("fill",(t=>{var e;return null!=(e=t.data.p)&&e.f&&t.data.c?c(t.data):"#fff"}));const C=X.selectAll(N("foreignObject")).data((t=>[t]),(t=>t.data.p.k)).join((t=>{const e=t.append("foreignObject").attr("class",`${l}-fo`).attr("x",o).attr("y",0).style("opacity",0).attr("height",(t=>t.xSize)).on("mousedown",Z).on("dblclick",Z);return e.append("xhtml:div").select((function(t){const e=t.data.p.el.cloneNode(!0);return this.replaceWith(e),e})).attr("xmlns","http://www.w3.org/1999/xhtml"),e}),(t=>t),(t=>t.remove())).attr("width",(t=>Math.max(0,t.ySizeInner-2*o)));this.transition(C).style("opacity",1);const j=this.g.selectAll(N("path")).data(f,(t=>t.target.data.p.k)).join((t=>{const e=[S+z.ySizeInner,k+z.xSize/2];return t.insert("path","g").attr("d",p({source:e,target:e}))}),(t=>t),(t=>{const e=[z.y+z.ySizeInner,z.x+z.xSize/2];return this.transition(t).attr("d",p({source:e,target:e})).remove()}));this.transition(j).attr("stroke",(t=>c(t.target.data))).attr("stroke-width",(t=>F(t.target))).attr("d",(t=>{const e=[t.source.y+t.source.ySizeInner,t.source.x+t.source.xSize/2],n=[t.target.y,t.target.x+t.target.xSize/2];return p({source:e,target:n})})),d.forEach((t=>{t.data.p.x0=t.x,t.data.p.y0=t.y}))}transition(t){const{duration:e}=this.options;return t.transition().duration(e)}async fit(){const t=this.svg.node(),{width:e,height:n}=t.getBoundingClientRect(),{fitRatio:i}=this.options,{minX:o,maxX:a,minY:s,maxY:c}=this.state,l=c-s,h=a-o,u=Math.min(e/l*i,n/h*i,2),d=r.zoomIdentity.translate((e-l*u)/2-s*u,(n-h*u)/2-o*u).scale(u);return this.transition(this.svg).call(this.zoom.transform,d).end().catch(A)}async ensureView(t,e){let n,o;if(this.g.selectAll(N("g")).each((function(e){e.data===t&&(n=this,o=e)})),!n||!o)return;const a=this.svg.node(),s=a.getBoundingClientRect(),c=r.zoomTransform(a),[l,h]=[o.y,o.y+o.ySizeInner+2].map((t=>t*c.k+c.x)),[u,d]=[o.x-o.xSize/2,o.x+o.xSize/2].map((t=>t*c.k+c.y)),f=i({left:0,right:0,top:0,bottom:0},e),p=[f.left-l,s.width-f.right-h],g=[f.top-u,s.height-f.bottom-d],m=p[0]*p[1]>0?V(p,Math.abs)/c.k:0,v=g[0]*g[1]>0?V(g,Math.abs)/c.k:0;if(m||v){const t=c.translate(m,v);return this.transition(this.svg).call(this.zoom.transform,t).end().catch(A)}}async rescale(t){const e=this.svg.node(),{width:n,height:i}=e.getBoundingClientRect(),o=n/2,a=i/2,s=r.zoomTransform(e),c=s.translate((o-s.x)*(1-t)/s.k,(a-s.y)*(1-t)/s.k).scale(t);return this.transition(this.svg).call(this.zoom.transform,c).end().catch(A)}destroy(){this.svg.remove(),this.revokers.forEach((t=>{t()}))}static create(t,e,n){const r=new J(t,e);return n&&(r.setData(n),r.fit()),r}}var W;J.defaultOptions={duration:500,nodeFont:"300 16px/20px sans-serif",nodeMinHeight:16,spacingVertical:5,spacingHorizontal:80,autoFit:!1,fitRatio:.95,color:(W=r.scaleOrdinal(r.schemeCategory10),t=>W(t.p.i)),paddingX:8},t.Markmap=J,t.loadCSS=function(t){for(const e of t)_(e)},t.loadJS=async function(t,e){const n=t.filter((t=>{var e;return"script"===t.type&&(null==(e=t.data)?void 0:e.src)}));n.length>1&&n.forEach((t=>P(t.data.src))),e=M({getMarkmap:()=>window.markmap},e);for(const n of t)await Y(n,e)},t.refreshHook=L}(this.markmap=this.markmap||{},d3); |
{ | ||
"name": "markmap-view", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"description": "View markmaps in browser", | ||
@@ -23,9 +23,10 @@ "author": "Gerald <gera2ld@live.com>", | ||
"dev": "rollup -wc rollup.conf.js", | ||
"clean": "del dist", | ||
"clean": "del-cli dist", | ||
"prebuild": "run-s ci clean", | ||
"prepublishOnly": "run-s build", | ||
"ci": "run-s lint", | ||
"lint": "eslint --ext .ts .", | ||
"build:js": "rollup -c rollup.conf.js", | ||
"prebuild": "npm run ci && npm run clean", | ||
"prepublishOnly": "npm run build", | ||
"ci": "npm run lint", | ||
"lint": "eslint --ext .ts .", | ||
"build": "tsc && npm run build:js" | ||
"build:types": "tsc", | ||
"build": "run-s build:types build:js" | ||
}, | ||
@@ -49,3 +50,3 @@ "bugs": { | ||
"d3-flextree": "^2.1.1", | ||
"markmap-common": "^0.1.3" | ||
"markmap-common": "^0.1.4" | ||
}, | ||
@@ -55,3 +56,3 @@ "engines": { | ||
}, | ||
"gitHead": "cb2ed0a25207e2617bb8b4d3735d61d4b5392560" | ||
"gitHead": "efdba06cf8ff88739cafc02e2b324aee91340abc" | ||
} |
@@ -5,2 +5,8 @@ import * as d3 from 'd3'; | ||
export { loadJS, loadCSS }; | ||
interface IPadding { | ||
left: number; | ||
right: number; | ||
top: number; | ||
bottom: number; | ||
} | ||
declare type ID3SVGElement = d3.Selection<SVGElement, IMarkmapFlexTreeItem, HTMLElement, IMarkmapFlexTreeItem>; | ||
@@ -34,3 +40,13 @@ declare function createViewHooks(): { | ||
transition<T extends d3.BaseType, U, P extends d3.BaseType, Q>(sel: d3.Selection<T, U, P, Q>): d3.Transition<T, U, P, Q>; | ||
/** | ||
* Fit the content to the viewport. | ||
*/ | ||
fit(): Promise<void>; | ||
/** | ||
* Pan the content to make the provided node visible in the viewport. | ||
*/ | ||
ensureView(node: INode, padding: Partial<IPadding> | undefined): Promise<void>; | ||
/** | ||
* Scale content with it pinned at the center of the viewport. | ||
*/ | ||
rescale(scale: number): Promise<void>; | ||
@@ -37,0 +53,0 @@ destroy(): void; |
@@ -0,0 +0,0 @@ import { INode } from 'markmap-common'; |
137643
3823
Updatedmarkmap-common@^0.1.4