Closed MrEnroke closed 1 year ago
OK, I understand your point. I would like to keep the props.assetsUrl
for convenience, but we could change the code in a way, that, if an asset file starts with /
or http
, the assetsUrl is ignored. So that only relative Urls use the assertsUrl.
getSpriteUrl() {
if(Utils.isAbsoluteUrl(this.props.sprite)) {
return this.props.sprite
} else {
return this.chessboard.props.assetsUrl + "extensions/arrows/" + this.props.sprite
}
}
Another way would be to define the path of the assets always relative from props.assetsUrl. "standard.svg" would become "pieces/standard.svg". With that way, we could set the assetsUrl to "" and put full paths in the file props.
getSpriteUrl() {
return this.chessboard.props.assetsUrl + this.props.sprite
}
Looking at the proposal, the first option includes a more complete solution, although I still doubt the need to include a fixed path such as /extensions/markers.
I would leave it up to everyone to define their path in props.sprite: 'extensions/markers/markers.svg'
You are right, the best solution is both
getSpriteUrl() {
if(Utils.isAbsoluteUrl(this.props.sprite)) {
return this.props.sprite
} else {
return this.chessboard.props.assetsUrl + this.props.sprite
}
}
unfortunately not backwards compatible. But I will implement it and increase a minor version number.
Published to https://registry.npmjs.org/ as cm-chessboard@7.7.1
In previous versions you could reference a full url from the corresponding "svgs".
sprite: { url: RESOURCES_URL + 'images/chess/setsnew/' + this.pieces + '/pieces.svg', size: 66, // the sprite size, defaults to 40x40px cache: true // cache the sprite inline, in the HTML },
Now the code is more restrictive and "forces" an intermediate path to exist:pieces: { type: PIECES_FILE_TYPE.svgSprite, // pieces are in an SVG sprite, no other type supported for now file: "standard.svg", // the filename of the sprite in
assets/pieces/tileSize: 40 // the tile size in the sprite },
Could you somehow afford a full url? In our case, the proposed structure is not interesting because we have more images related to the theme.
View commit: 167b4d7b7d233679df626987b642df4a7aab632f