Files
Bogdan Chadkin 534f4b2c56 experimental: migrate image control to style object model (#4102)
Ref https://github.com/webstudio-is/webstudio/issues/1536
https://github.com/webstudio-is/webstudio/issues/3399

Refactored image control to maintain styles internally. Important to not
this is the first repeated style control. It accepts property and
additionally index of repeated style. Would work with future sections
like mask-image

We can also improve it to support both singular and repeated styles in
the future.

<img width="231" alt="Screenshot 2024-09-10 at 19 52 17"
src="https://github.com/user-attachments/assets/a0d27b1b-ae72-4454-b31e-d1f5af3bc4d1">
2024-09-10 20:29:25 +02:00

22 lines
601 B
TypeScript

type Predicate<Item> = (value: Item) => boolean;
export const removeByMutable = <Item>(
array: Item[],
predicate: Predicate<Item>
) => {
// reversed order to splice without breaking index
for (let index = array.length - 1; index >= 0; index -= 1) {
if (predicate(array[index])) {
array.splice(index, 1);
}
}
};
export const repeatUntil = <Item>(array: Item[], count: number) => {
const repeatedArray: Item[] = [];
for (let index = 0; index < Math.max(count, array.length); index += 1) {
repeatedArray.push(array[index % array.length]);
}
return repeatedArray;
};