✨ 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 Point from "./point";
|
||||
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 */
|
||||
Svg.prototype.insertText = function() {};
|
||||
/** Runs insertText hooks */
|
||||
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 */
|
||||
Svg.prototype.debug = function() {};
|
||||
|
@ -162,9 +168,9 @@ Svg.prototype.renderPath = function(path) {
|
|||
};
|
||||
|
||||
Svg.prototype.renderPathText = function(path) {
|
||||
this.text = path.attributes.get("data-text");
|
||||
if (!this.text) return "";
|
||||
else this.insertText();
|
||||
let text = path.attributes.get("data-text");
|
||||
if (!text) return "";
|
||||
else this.text = this.insertText(text);
|
||||
let attributes = path.attributes.renderIfPrefixIs("data-text-");
|
||||
// Sadly aligning text along a patch can't be done in CSS only
|
||||
let offset = "";
|
||||
|
@ -188,12 +194,10 @@ Svg.prototype.renderText = function(point) {
|
|||
if (text !== false) {
|
||||
let joint = "";
|
||||
for (let string of text) {
|
||||
this.text = string;
|
||||
this.insertText();
|
||||
this.text = this.insertText(string);
|
||||
joint += this.text + " ";
|
||||
}
|
||||
this.text = joint;
|
||||
this.insertText();
|
||||
this.text = this.insertText(joint);
|
||||
}
|
||||
point.attributes.set("data-text-x", point.x);
|
||||
point.attributes.set("data-text-y", point.y);
|
||||
|
|
|
@ -2,14 +2,6 @@ import Point from "./point";
|
|||
import Bezier from "bezier-js";
|
||||
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 */
|
||||
export function macroName(name) {
|
||||
return `_macro_${name}`;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue