From be1cd0becbee6dcd06079cfa6b35412fcec178d0 Mon Sep 17 00:00:00 2001 From: heroboy Date: Fri, 18 Nov 2022 10:06:16 +0800 Subject: [PATCH] allow image-size accept Url parameter This reverts commit 4cd797eadda6bc407772b3360de07de8ff3867bc. allow image-size accept Url parameter allow image-size accept Url parameter --- packages/less/src/less-node/image-size.js | 17 ++++++++++++++++- packages/test-data/css/_main/urls.css | 6 ++++++ packages/test-data/less/_main/urls.less | 8 ++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/packages/less/src/less-node/image-size.js b/packages/less/src/less-node/image-size.js index 888a7a136..e1c904646 100644 --- a/packages/less/src/less-node/image-size.js +++ b/packages/less/src/less-node/image-size.js @@ -5,7 +5,22 @@ import functionRegistry from './../less/functions/function-registry'; export default environment => { function imageSize(functionContext, filePathNode) { - let filePath = filePathNode.value; + let filePath; + + if (filePathNode.type === 'Url') { + filePath = filePathNode.value.value; + } + else if (filePathNode.type === 'Quoted') { + filePath = filePathNode.value; + } + + if (typeof filePath !== 'string') { + throw { + type :'Argument', + message: 'invalid argument for \'image-size\' function' + } + } + const currentFileInfo = functionContext.currentFileInfo; const currentDirectory = currentFileInfo.rewriteUrls ? currentFileInfo.currentDirectory : currentFileInfo.entryPath; diff --git a/packages/test-data/css/_main/urls.css b/packages/test-data/css/_main/urls.css index 1ca83e80d..1d4dceff9 100644 --- a/packages/test-data/css/_main/urls.css +++ b/packages/test-data/css/_main/urls.css @@ -74,6 +74,12 @@ width: 640px; height: 430px; } +#images { + background-image: url('../data/data-uri-fail.png'); + width: 640px; + height: 430px; + size: 640px 430px; +} #svg-functions { background-image: url('data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%201%201%22%3E%3ClinearGradient%20id%3D%22g%22%20x1%3D%220%25%22%20y1%3D%220%25%22%20x2%3D%220%25%22%20y2%3D%22100%25%22%3E%3Cstop%20offset%3D%220%25%22%20stop-color%3D%22%23000000%22%2F%3E%3Cstop%20offset%3D%22100%25%22%20stop-color%3D%22%23ffffff%22%2F%3E%3C%2FlinearGradient%3E%3Crect%20x%3D%220%22%20y%3D%220%22%20width%3D%221%22%20height%3D%221%22%20fill%3D%22url(%23g)%22%20%2F%3E%3C%2Fsvg%3E'); background-image: url('data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%201%201%22%3E%3ClinearGradient%20id%3D%22g%22%20x1%3D%220%25%22%20y1%3D%220%25%22%20x2%3D%220%25%22%20y2%3D%22100%25%22%3E%3Cstop%20offset%3D%220%25%22%20stop-color%3D%22%23000000%22%2F%3E%3Cstop%20offset%3D%223%25%22%20stop-color%3D%22%23ffa500%22%2F%3E%3Cstop%20offset%3D%22100%25%22%20stop-color%3D%22%23ffffff%22%2F%3E%3C%2FlinearGradient%3E%3Crect%20x%3D%220%22%20y%3D%220%22%20width%3D%221%22%20height%3D%221%22%20fill%3D%22url(%23g)%22%20%2F%3E%3C%2Fsvg%3E'); diff --git a/packages/test-data/less/_main/urls.less b/packages/test-data/less/_main/urls.less index 73de12b63..4d1f3961d 100644 --- a/packages/test-data/less/_main/urls.less +++ b/packages/test-data/less/_main/urls.less @@ -66,6 +66,14 @@ width: image-width('../data/data-uri-fail.png'); height: image-height('../data/data-uri-fail.png'); } + +#images{ + background-image: url('../data/data-uri-fail.png'); + width: image-width(url('../data/data-uri-fail.png')); + height: image-height($background-image); + size: image-size(url(../data/data-uri-fail.png)); +} + .add_an_import(@file_to_import) { @import "@{file_to_import}"; }