feat: add SVG support to image preloading#145
feat: add SVG support to image preloading#145draggie wants to merge 1 commit intocallstackincubator:mainfrom
Conversation
|
Good work! I have a couple of ideas for improving code structure.
|
|
@draggie : It would be possible to use it this way, for example with an input field where the user enters a name, an SVG file is generated based on the text, and it can then be injected into the code. See the example below.
function createLogoSVG(text) {
return `
<svg viewBox="0 0 600 120" xmlns="http://www.w3.org/2000/svg">
<defs>
<linearGradient id="a" x1="0" x2="1">
<stop offset="0" stop-color="#00f7ff"/>
<stop offset="1" stop-color="#7a00ff"/>
</linearGradient>
<filter id="b">
<feGaussianBlur stdDeviation="6" result="blur"/>
<feMerge>
<feMergeNode in="blur"/>
<feMergeNode in="SourceGraphic"/>
</feMerge>
</filter>
</defs>
<rect width="100%" height="100%" fill="#fff"/>
<text
x="50%"
y="55%"
text-anchor="middle"
font-size="44"
fill="url(#a)"
filter="url(#b)"
>
${text}
</text>
</svg>
`;
}
const svg = createLogoSVG("Draggie");You can use it to create a chart using svg.
<svg width="700" height="450" viewBox="0 0 700 450" xmlns="http://www.w3.org/2000/svg">
<rect width="100%" height="100%" fill="#f3f3f3"/>
<defs>
<linearGradient id="a" x1="0" y1="0" x2="0" y2="1">
<stop offset="0%" stop-color="#9aa0a6" stop-opacity=".35"/>
<stop offset="100%" stop-color="#9aa0a6" stop-opacity=".05"/>
</linearGradient>
</defs>
<path stroke="#d9d9d9" d="M90 60h560M90 170h560M90 280h560"/>
<g fill="#6f6f6f" font-size="16" font-family="Arial">
<text x="10" y="65">0,000584</text>
<text x="10" y="175">0,000582</text>
<text x="10" y="285">0,000580</text>
<text x="10" y="395">0,000578</text>
</g>
<path stroke="#7c7c7c" stroke-width="2" d="M90 390h560"/>
<path d="M90 390v10m46-10v10m46-10v10m46-10v10m46-10v10m46-10v10m46-10v10m46-10v10m46-10v10m46-10v10m46-10v10m46-10v10m46-10v10" stroke="#7c7c7c"/>
<g fill="#6f6f6f" font-size="10" font-family="Arial" text-anchor="middle">
<text x="90" y="420">00:00</text>
<text x="136" y="420">01:00</text>
<text x="182" y="420">02:00</text>
<text x="228" y="420">03:00</text>
<text x="274" y="420">04:00</text>
<text x="320" y="420">05:00</text>
<text x="366" y="420">06:00</text>
<text x="412" y="420">07:00</text>
<text x="458" y="420">08:00</text>
<text x="504" y="420">09:00</text>
<text x="550" y="420">10:00</text>
<text x="596" y="420">11:00</text>
<text x="642" y="420">12:00</text>
</g>
<path d="m90 70 10 40 10-15 10 35 10-10 10 25 10-10 10 20 10-15 10 20 10-10 10 25 10-10 10 25 10 20 10-10 10 15 10-10 10 25 10 30 10-15 10-25 10 15 10-10 10 15 10-25 10 35 10-15 10 10 10-15 10-10 10 40 10-5 10-15 10-15 10 10 10-15 10 25 10-15 10 10 10-35 10 10 10-15 10 10 10-15 10 10 10-15 10-15 10-10 10 5 10-10 10 15 10-10 10 5 10-2 10 7v215H90Z" fill="url(#a)"/>
<path d="m90 70 10 40 10-15 10 35 10-10 10 25 10-10 10 20 10-15 10 20 10-10 10 25 10-10 10 25 10 20 10-10 10 15 10-10 10 25 10 30 10-15 10-25 10 15 10-10 10 15 10-25 10 35 10-15 10 10 10-15 10-10 10 40 10-5 10-15 10-15 10 10 10-15 10 25 10-15 10 10 10-35 10 10 10-15 10 10 10-15 10 10 10-15 10-15 10-10 10 5 10-10 10 15 10-10 10 5 10-2 10 7" fill="none" stroke="#787d84" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/>
<circle cx="640" cy="175" r="8" fill="#787d84"/>
</svg> |


Closes #132.
Summary
Adds MVP SVG support to image preloading on iOS and Android by rasterizing SVG input into PNG data before storing it in the existing preloaded image cache.
svg,width, andheightVoltra.Image/ preloaded asset rendering pathValidation
git diff --checknpm run format:checknpm run typecheck --workspace voltranpm run typecheck --workspace @use-voltra/iosnpm run typecheck --workspace @use-voltra/androidnpm run test:kotlin --workspace voltraNotes
The iOS implementation uses WebKit for runtime SVG rasterization, so the podspec now links WebKit. SVG inputs require explicit positive width and height for predictable raster output.
Preview
iOS

Android

