uikit-v1.8.3-biimage-transparent-background-complete
This commit is contained in:
parent
f9e1eb69a9
commit
78e073bffb
20
BIIMAGE_TRANSPARENT_BACKGROUND_1.8.3.md
Normal file
20
BIIMAGE_TRANSPARENT_BACKGROUND_1.8.3.md
Normal file
@ -0,0 +1,20 @@
|
||||
# BiImage — Transparent Background (v1.8.3)
|
||||
|
||||
## مسئله
|
||||
|
||||
`BiImage` بهصورت پیشفرض `backgroundColor: #E5E7EB` را به خود `<img>` اعمال میکرد. لوگوهای دارای آلفای شفاف با یک مستطیل خاکستری در اندازه تصویر نمایش داده میشدند.
|
||||
|
||||
## تغییر
|
||||
|
||||
- رنگ پیشفرض حذف شد. پسزمینه بدون `bg` یا `backgroundColor` صریح، شفاف است.
|
||||
- استایلهای صریح `bg`, `bgColor`, `backgroundColor`, `style` و `sx` همچنان اعمال میشوند.
|
||||
- محاسبه ابعاد Responsive، `objectFit`، `fallbackSrc`، Hover، ResizeObserver و بهینهسازی CDN هیچ تغییری نکردند.
|
||||
- خروجی Remote نیز با اجرای `node scripts/build-bi-image-remote.mjs` از سورس بازسازی شده است.
|
||||
|
||||
## انتشار
|
||||
|
||||
پس از Deploy نسخه جدید، فایل `dist/remote/BiImage.js` باید روی سرویس Remote جایگزین شود. سامانههای مصرفکننده نیازی به تغییر کد JSX ندارند.
|
||||
|
||||
## آزمون
|
||||
|
||||
تستهای Node، تستهای مرورگر Chromium و بررسی همخوانی فایل Remote با سورس انجام میشوند.
|
||||
@ -109,13 +109,13 @@ import { BiImage } from "uikit/remote/ui/BiImage";
|
||||
| `style`, `className`, `sx` | استایل خود `<img>`؛ اغلب پراپهای CSS و میانبرهای Chakra (مثل `minW`, `maxW`, `rounded`, `bg`, `mx`, `p`) نیز پشتیبانی میشوند. |
|
||||
| `transition`, `transform`, `_hover`, `_focus`, `_active`, `_focusVisible` | CSS تعاملی و انیمیشن با استایل Scoped و بدون ChakraProvider. |
|
||||
| `objectFit`, `objectPosition` | کنترل نحوه نمایش در قاب محدود. |
|
||||
| `fallbackSrc` | جایگزین در نبودن یا خطای تصویر اصلی، بدون بهینهسازی؛ اگر آن هم خطا دهد پسزمینه خاکستری میماند. |
|
||||
| `fallbackSrc` | جایگزین در نبودن یا خطای تصویر اصلی، بدون بهینهسازی؛ اگر آن هم خطا دهد، تصویر بدون پسزمینه اجباری باقی میماند. |
|
||||
| `alt`, `loading`, `decoding`, `sizes`, `onLoad`, `onError`, `onClick` | پراپهای تصویر استاندارد که کامپوننت پشتیبانی میکند؛ `alt` را برای دسترسپذیری بدهید. |
|
||||
|
||||
- Breakpointهای پیشفرض مانند Chakra v2 هستند: `sm=30em`، `md=48em`، `lg=62em`، `xl=80em`، `2xl=96em`. تغییر breakpointهای سفارشی در تم Chakra بهصورت خودکار به کامپوننت مستقل منتقل نمیشود.
|
||||
- این کامپوننت بدون `ChakraProvider` کار میکند، اما موتور کامل Theme/StyleConfig چاکرا نیست؛ توکنهای سفارشی Theme، پراپ `fallback` از نوع React element و همه انتخابگرهای پیچیده `sx` معادل دقیق Chakra نیستند. مثالهای معمول Chakra Image (ابعاد ریسپانسیو، objectFit، Hover و Transition) پشتیبانی و در مرورگر تست شدهاند.
|
||||
- بهینهسازی CDN/HTTP با `processImage` موجود در `uikit/utils` انجام میشود؛ اندازه از layout با `ResizeObserver` گرفته میشود و تصویر با `q:100` در قالب WebP درخواست میشود. `data:image` و `blob:` از proxy عبور نمیکنند.
|
||||
- اگر `src` خالی باشد یا تصویر و fallback هر دو خطا بدهند، فقط پسزمینه خاکستری `#E5E7EB` نمایش داده میشود. برای تصویر با ارتفاع خودکار و بدون منبع، ارتفاعی تضمین نمیشود؛ در صورت نیاز ابعاد ثابت بدهید.
|
||||
- پسزمینه `BiImage` بهصورت پیشفرض شفاف است؛ اگر `src` خالی باشد یا تصویر و fallback هر دو خطا بدهند، پسزمینه خاکستری اجباری نمایش داده نمیشود. برای رنگ دلخواه، `bg` یا `backgroundColor` را صریحاً ارسال کنید. برای تصویر با ارتفاع خودکار و بدون منبع، ارتفاعی تضمین نمیشود؛ در صورت نیاز ابعاد ثابت بدهید.
|
||||
- فایل remote مستقل از Chakra و سایر فایلهای remote در `https://uikit.d.aiengines.ir/BiImage.js` منتشر میشود؛ wrapper React آن پس از Mount شدن در مرورگر بارگذاری میشود. **پس از انتشار پکیج، خود فایل remote نیز باید همراه خروجی `dist/remote/BiImage.js` روی CDN منتشر شود.** یک صفحه نمونه مستقل با چهار حالت در `dist/remote/BiImage-demo.html` هم موجود است؛ نسخه React دمو در `src/dev/AppHeaderPreview.jsx` مستند شده و هنگام build:demo بهروز میشود. بدون دسترسی به این فایل، تصویر رندر نمیشود.
|
||||
- هنگام تغییر نسخه import یا fallback، نام `BiImage` و این مسیر عمومی ثابت میماند. تغییرات بعدی فایل remote ممکن است با cache مرورگر/CDN تا refresh بعدی تأخیر داشته باشد.
|
||||
|
||||
|
||||
2
dist/remote/BiImage.js
vendored
2
dist/remote/BiImage.js
vendored
@ -121,7 +121,6 @@ function createImagePresentation(props = {}) {
|
||||
}
|
||||
// Defaults remain pixel-compatible with the original BiImage.
|
||||
styles.base.display = "block";
|
||||
styles.base.backgroundColor = "#E5E7EB";
|
||||
styles.base.width = "auto";
|
||||
styles.base.height = "auto";
|
||||
if (props.boxSize !== undefined) read({ boxSize: props.boxSize });
|
||||
@ -170,7 +169,6 @@ function imagePresentationCSS(presentation, selector) {
|
||||
|
||||
const TAG_NAME = "uikit-bi-image";
|
||||
const CDN_BASE = "https://cdn.d.aiengines.ir/";
|
||||
const PLACEHOLDER_COLOR = "#E5E7EB";
|
||||
|
||||
function resolveSource(src) {
|
||||
if (typeof src !== "string" || !src.trim()) return "";
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
2
dist/remote/index.html
vendored
2
dist/remote/index.html
vendored
@ -5,7 +5,7 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="color-scheme" content="light" />
|
||||
<title>UI Kit Remote Demo</title>
|
||||
<script type="module" crossorigin src="./demo-assets/index-OINSE4VD.js"></script>
|
||||
<script type="module" crossorigin src="./demo-assets/index-CmM0Kzar.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "uikit",
|
||||
"version": "1.8.2",
|
||||
"version": "1.8.3",
|
||||
"type": "module",
|
||||
"main": "./dist/index.js",
|
||||
"module": "./dist/index.js",
|
||||
|
||||
@ -5,7 +5,6 @@ import { createImagePresentation, imagePresentationCSS } from "./style-props.js"
|
||||
|
||||
const TAG_NAME = "uikit-bi-image";
|
||||
const CDN_BASE = "https://cdn.d.aiengines.ir/";
|
||||
const PLACEHOLDER_COLOR = "#E5E7EB";
|
||||
|
||||
function resolveSource(src) {
|
||||
if (typeof src !== "string" || !src.trim()) return "";
|
||||
|
||||
@ -111,7 +111,6 @@ export function createImagePresentation(props = {}) {
|
||||
}
|
||||
// Defaults remain pixel-compatible with the original BiImage.
|
||||
styles.base.display = "block";
|
||||
styles.base.backgroundColor = "#E5E7EB";
|
||||
styles.base.width = "auto";
|
||||
styles.base.height = "auto";
|
||||
if (props.boxSize !== undefined) read({ boxSize: props.boxSize });
|
||||
|
||||
@ -57,11 +57,11 @@ with sync_playwright() as p:
|
||||
dims=page.evaluate("() => {const i=window.resp.querySelector('img');return [i.getBoundingClientRect().width,i.getBoundingClientRect().height,i.currentSrc]}")
|
||||
print('responsive-resized',dims)
|
||||
assert dims[0]==300 and dims[1]==150 and '/rs:auto:300:0:0/' in dims[2]
|
||||
# Null src: gray box, no broken image icon.
|
||||
# Null src: transparent box, no broken image icon.
|
||||
page.evaluate("() => {window.el.componentProps={src:null,width:70,height:70}}")
|
||||
gray=page.evaluate("() => {let i=window.el.querySelector('img');return [i.getAttribute('src'),getComputedStyle(i).backgroundColor,i.getBoundingClientRect().width]}")
|
||||
print('gray',gray)
|
||||
assert gray==[None,'rgb(229, 231, 235)',70]
|
||||
print('transparent',gray)
|
||||
assert gray==[None,'rgba(0, 0, 0, 0)',70]
|
||||
assert len(urls)<12, f'unexpected repeated resizing: {urls}'
|
||||
browser.close()
|
||||
print('PASS: Chromium DOM sizing, aspect ratio, responsive observer, proxy URL and gray placeholder')
|
||||
print('PASS: Chromium DOM sizing, aspect ratio, responsive observer, proxy URL and transparent default')
|
||||
|
||||
@ -17,6 +17,10 @@ assert.equal(presentation.styles.sm.width, '70px');
|
||||
assert.equal(presentation.styles.sm.height, '70px');
|
||||
assert.equal(presentation.styles.base.objectFit, 'contain');
|
||||
assert.equal(presentation.styles.base.transition, 'transform 0.3s ease-in-out');
|
||||
assert.equal(presentation.styles.base.backgroundColor, undefined, 'a transparent logo must not get a gray backdrop');
|
||||
assert.equal(createImagePresentation({ bg: '#123456' }).styles.base.background, '#123456');
|
||||
assert.equal(createImagePresentation({ backgroundColor: 'transparent' }).styles.base.backgroundColor, 'transparent');
|
||||
assert.equal(createImagePresentation({ style: { backgroundColor: '#abcdef' } }).styles.base.backgroundColor, '#abcdef');
|
||||
assert.equal(presentation.pseudos._hover.base.transform, 'scale(1.3)');
|
||||
const css = imagePresentationCSS(presentation, 'uikit-bi-image > img[data-bi-image="test"]');
|
||||
assert.match(css, /@media \(min-width:30em\)/);
|
||||
|
||||
@ -40,6 +40,7 @@ with sync_playwright() as p:
|
||||
i = info()
|
||||
print('base', {k: v for k, v in i.items() if k != 'css'})
|
||||
assert i['w'] == 60 and i['h'] == 60 and i['fit'] == 'contain'
|
||||
assert page.evaluate("getComputedStyle(window.bi.querySelector('img')).backgroundColor") == 'rgba(0, 0, 0, 0)'
|
||||
assert 'transform' in i['transition'] and '/rs:auto:60:60:0/' in i['src'], i
|
||||
page.set_viewport_size({'width': 650, 'height': 400})
|
||||
page.wait_for_function("window.bi.querySelector('img').naturalWidth === 70")
|
||||
@ -52,6 +53,12 @@ with sync_playwright() as p:
|
||||
print('hover', {k: v for k, v in i.items() if k != 'css'})
|
||||
assert abs(i['w']-91) <= 1 and abs(i['h']-91) <= 1, i
|
||||
assert len([r for r in requests if '/rs:auto:91:' in r]) == 0, requests
|
||||
# Background remains configurable when explicitly passed.
|
||||
page.evaluate('''() => {window.bi.componentProps = {
|
||||
src:'https://cdn.d.aiengines.ir/logo.jpg', width:70, height:70,
|
||||
bg:'#123456', objectFit:'contain'
|
||||
};}''')
|
||||
assert page.evaluate("getComputedStyle(window.bi.querySelector('img')).backgroundColor") == 'rgb(18, 52, 86)'
|
||||
page.mouse.move(360, 320)
|
||||
page.wait_for_timeout(450)
|
||||
i = info()
|
||||
|
||||
@ -76,7 +76,7 @@ const makeUrl=(url,w,h)=>`https://img.d.aiengines.ir/preset:sharp${w||h?`/rs:aut
|
||||
|
||||
let el=mount({src:key,height:70,width:'auto',alt:'Portrait'});
|
||||
assert.equal(el.image.src,makeUrl(cdn,0,70),'height-constrained image should preserve natural width');
|
||||
assert.equal(el.image.style.backgroundColor,'#E5E7EB');
|
||||
assert.equal(el.image.style.backgroundColor, undefined, 'transparent by default');
|
||||
el.image.naturalWidth=140;el.image.naturalHeight=70;el.image.events.load({type:'load'});
|
||||
assert.equal(el.image.src,makeUrl(cdn,0,70),'natural width after loading must not trigger different size URL');
|
||||
observing.cb();
|
||||
@ -98,17 +98,17 @@ assert.equal(el.image.src,makeUrl('https://images.example.org/photo.png',0,40));
|
||||
el=mount({src:undefined,width:70,height:70});
|
||||
assert.equal(el.image.src,'');
|
||||
assert.equal(el.image.style.width,'70px');
|
||||
assert.equal(el.image.style.backgroundColor,'#E5E7EB');
|
||||
assert.equal(el.image.style.backgroundColor, undefined, 'transparent by default');
|
||||
|
||||
el=mount({src:key,width:70,height:70,fallbackSrc:'/static/placeholder.svg'});
|
||||
el.image.events.error({type:'error'});
|
||||
assert.equal(el.image.src,'/static/placeholder.svg','fallback should not be proxied or CDN-resolved');
|
||||
el.image.events.error({type:'error'});
|
||||
assert.equal(el.image.src,'','broken fallback should become gray only');
|
||||
assert.equal(el.image.src,'','broken fallback should not leave a broken image icon');
|
||||
|
||||
el=mount({src:key,width:70,height:70});
|
||||
el.image.events.error({type:'error'});
|
||||
assert.equal(el.image.src,'','broken image should leave gray only');
|
||||
assert.equal(el.image.src,'','broken image should not leave a broken image icon');
|
||||
|
||||
el=mount({src:'data:image/png;base64,ZmFrZQ==',width:80,height:60});
|
||||
assert.equal(el.image.src,'data:image/png;base64,ZmFrZQ==','data images should bypass proxy');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user