✨ Updated insertText hook
This commit is contained in:
parent
11fb583195
commit
0a83da13b5
3 changed files with 14 additions and 18 deletions
|
@ -1,4 +1,4 @@
|
||||||
import { macroName, round, sampleStyle, methodHash } from "./utils";
|
import { macroName, round, sampleStyle } from "./utils";
|
||||||
import Part from "./part";
|
import Part from "./part";
|
||||||
import Point from "./point";
|
import Point from "./point";
|
||||||
import Path from "./path";
|
import Path from "./path";
|
||||||
|
|
22
src/svg.js
22
src/svg.js
|
@ -35,8 +35,14 @@ Svg.prototype.runHooks = function(hookName, data = false) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Method to attach insertText hooks on */
|
/** Runs insertText hooks */
|
||||||
Svg.prototype.insertText = function() {};
|
Svg.prototype.insertText = function(text) {
|
||||||
|
if (this.hooks.insertText.length > 0) {
|
||||||
|
for (let hook of this.hooks.insertText) text = hook.method(text, hook.data);
|
||||||
|
}
|
||||||
|
|
||||||
|
return text;
|
||||||
|
};
|
||||||
|
|
||||||
/** Debug method, exposes debug hook */
|
/** Debug method, exposes debug hook */
|
||||||
Svg.prototype.debug = function() {};
|
Svg.prototype.debug = function() {};
|
||||||
|
@ -162,9 +168,9 @@ Svg.prototype.renderPath = function(path) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Svg.prototype.renderPathText = function(path) {
|
Svg.prototype.renderPathText = function(path) {
|
||||||
this.text = path.attributes.get("data-text");
|
let text = path.attributes.get("data-text");
|
||||||
if (!this.text) return "";
|
if (!text) return "";
|
||||||
else this.insertText();
|
else this.text = this.insertText(text);
|
||||||
let attributes = path.attributes.renderIfPrefixIs("data-text-");
|
let attributes = path.attributes.renderIfPrefixIs("data-text-");
|
||||||
// Sadly aligning text along a patch can't be done in CSS only
|
// Sadly aligning text along a patch can't be done in CSS only
|
||||||
let offset = "";
|
let offset = "";
|
||||||
|
@ -188,12 +194,10 @@ Svg.prototype.renderText = function(point) {
|
||||||
if (text !== false) {
|
if (text !== false) {
|
||||||
let joint = "";
|
let joint = "";
|
||||||
for (let string of text) {
|
for (let string of text) {
|
||||||
this.text = string;
|
this.text = this.insertText(string);
|
||||||
this.insertText();
|
|
||||||
joint += this.text + " ";
|
joint += this.text + " ";
|
||||||
}
|
}
|
||||||
this.text = joint;
|
this.text = this.insertText(joint);
|
||||||
this.insertText();
|
|
||||||
}
|
}
|
||||||
point.attributes.set("data-text-x", point.x);
|
point.attributes.set("data-text-x", point.x);
|
||||||
point.attributes.set("data-text-y", point.y);
|
point.attributes.set("data-text-y", point.y);
|
||||||
|
|
|
@ -2,14 +2,6 @@ import Point from "./point";
|
||||||
import Bezier from "bezier-js";
|
import Bezier from "bezier-js";
|
||||||
import crypto from "crypto";
|
import crypto from "crypto";
|
||||||
|
|
||||||
/** Generates a hash, do not use this for security */
|
|
||||||
export function methodHash(method) {
|
|
||||||
return crypto
|
|
||||||
.createHash("sha1")
|
|
||||||
.update(method.toSource())
|
|
||||||
.digest("base64");
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Returns internal hook name for a macro */
|
/** Returns internal hook name for a macro */
|
||||||
export function macroName(name) {
|
export function macroName(name) {
|
||||||
return `_macro_${name}`;
|
return `_macro_${name}`;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue