Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
515fef7
escape html strings (#66)
donfour May 2, 2023
24b8fa5
[Major Update] New Figma plugin UI flow (#69)
spikelu2016 May 4, 2023
ebd7ee4
fix merge conflicts
spikelu2016 May 4, 2023
dd6127e
fix incorrect duration calculation
spikelu2016 May 4, 2023
88e35d0
Support mixed font sizes, families, and weights (#70)
donfour May 5, 2023
0842445
add support for mixed text decoration
donfour May 5, 2023
1a81eb6
support mixed text transform
donfour May 5, 2023
3013c06
add support for blending multiple text fills together
donfour May 6, 2023
c1ea846
add support for mixed font fills
donfour May 6, 2023
ca1744c
wip: support lists
donfour May 8, 2023
c44b9df
support mixed text styles in lists
donfour May 8, 2023
7dca400
add list style for twcss, remove redundant div when there is only one…
donfour May 8, 2023
f97e102
Various bug fixes (#75)
spikelu2016 May 9, 2023
b74523a
replace slack with discord
spikelu2016 May 9, 2023
5bb9841
resolve merge conflicts
spikelu2016 May 9, 2023
fa8a428
add support for mixed letter spacing, fix bug with wrong <li>
donfour May 9, 2023
a21355d
Merge branch 'main' of https://github.com/bricks-cloud/bricks
donfour May 9, 2023
ac5cba0
get rid of redundant letter spacing styles
donfour May 9, 2023
8126e11
get rid of redundant font family styles
donfour May 9, 2023
b6ea4b5
support letter spacing in twcss
donfour May 9, 2023
ee68a29
save progress
spikelu2016 May 13, 2023
d59c6d3
save progress
spikelu2016 May 16, 2023
becfe39
fix various bugs for launch
spikelu2016 May 18, 2023
ed9489e
minor fixes
spikelu2016 May 18, 2023
d2a80c9
remove unnecessary code
spikelu2016 May 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ Bricks is composed of a number of components. Below is a description of each com
- `core`: engine that converts Figma nodes into coding files.

## License
Distributed under the Apache 2.0 License. See `LICENSE` for more information.
Distributed under the Apache 2.0 License and Bricks Enterprise License. See `LICENSE` for more information.

## Get in Touch
Email: spike@bricks-tech.com

<a href="https://join.slack.com/t/brickscommunity/shared_invite/zt-1pb2hy3h2-9rDYWMZdHKxHblzUG0CpTQ"><img src="https://img.shields.io/badge/slack-bricks-blue?logo=slack&labelColor=2EB67D" alt="Join Bricks on Slack"></a>
<a href="https://discord.gg/NM6aeBeqCD"><img src="https://img.shields.io/badge/discord-bricks-blue?logo=discord&labelColor=2EB67D" alt="Join Bricks on Discord"></a>
8 changes: 8 additions & 0 deletions core/ee/code/prop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ export const getTextVariableProp = (nodeId: string): string => {
for (const propBinding of propBindings) {
for (const location of propBinding.locations) {
if (location.type === "text") {
if (propBinding.dataType === DataType.boolean) {
if (isEmpty(propBinding.conditionalValue)) {
continue;
}

return `{${propBinding.prop} ? "${propBinding.defaultValue}" : "${propBinding.conditionalValue}"}`;
}

return `{${propBinding.prop}}`;
}
}
Expand Down
22 changes: 4 additions & 18 deletions core/ee/cv/component-recognition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Node, NodeType } from "../../src/bricks/node";
import { ExportFormat } from "../../src/design/adapter/node";
import { traverseNodes } from "../../src/utils";
import { AiApplication, aiApplicationRegistryGlobalInstance } from "../ui/ai-application-registry";
import { predictImage, predictText } from "../web/request";
import { predictImage } from "../web/request";

export const annotateNodeForHtmlTag = async (startingNode: Node) => {
try {
Expand Down Expand Up @@ -32,17 +32,10 @@ export const annotateNodeForHtmlTag = async (startingNode: Node) => {
return node?.getType() !== NodeType.VECTOR_GROUP;
});

// console.log("idImageMap", idImageMap);
// console.log("idTextMap", idTextMap);

const [predictImagesResult, predictTextsResult] = await Promise.allSettled([
const [predictImagesResult] = await Promise.allSettled([
predictImage(idImageMap),
predictText(idTextMap),
]);

const textPredictions =
predictTextsResult.status === "fulfilled" ? predictTextsResult.value : {};

const imagePredictions =
predictImagesResult.status === "fulfilled"
? predictImagesResult.value
Expand All @@ -52,23 +45,16 @@ export const annotateNodeForHtmlTag = async (startingNode: Node) => {
console.error("Error with image prediction", predictImagesResult.reason);
}

if (predictTextsResult.status === "rejected") {
console.error("Error with image prediction", predictTextsResult.reason);
}

// console.log("imagePredictions", imagePredictions);
// console.log("textPredictions", textPredictions);

await traverseNodes(startingNode, async (node) => {
if (node.node) {
const originalId = node.node.getOriginalId();
const predictedHtmlTag =
imagePredictions[originalId] || textPredictions[originalId];
imagePredictions[originalId];

if (predictedHtmlTag) {
aiApplicationRegistryGlobalInstance.addApplication(AiApplication.componentIdentification);
node.addAnnotations("htmlTag", predictedHtmlTag);
return predictedHtmlTag !== "a" && predictedHtmlTag !== "button";
return predictedHtmlTag !== "button";
}
}

Expand Down
54 changes: 25 additions & 29 deletions core/ee/loop/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { isEmpty } from "../../src/utils";
import { CssFramework } from "../../src/code/code";
import { getTwcssClass } from "../../src/code/generator/tailwindcss/css-to-twcss";
import { optionRegistryGlobalInstance } from "../../src/code/option-registry/option-registry";
import { areAllNodesSimilar, vectorGroupAnnotation } from "./loop";
import { areAllNodesSimilar } from "./loop";
import { nameRegistryGlobalInstance } from "../../src/code/name-registry/name-registry";
import { IdToPropBindingMap, propRegistryGlobalInstance } from "./prop-registry";
import uuid from "react-native-uuid";
import { shouldUseAsBackgroundImage } from "../../src/bricks/util";

type PropLocation = {
type: string;
Expand Down Expand Up @@ -393,39 +394,32 @@ export const gatherPropsFromSimilarNodes = (nodes: Node[], instanceIds: string[]
return [false, {}];
}

const cssProps: ComponentProperties = optionRegistryGlobalInstance.getOption().cssFramework === CssFramework.tailwindcss ? gatherTwcssPropsFromNodes(nodes, instanceIds) : gatherCssPropsFromNodes(nodes, instanceIds);
const [result, similarNodes] = areAllNodesSimilar(nodes);
if (!result) {
return [false, {}];
}

const cssProps: ComponentProperties = optionRegistryGlobalInstance.getOption().cssFramework === CssFramework.tailwindcss ? gatherTwcssPropsFromNodes(similarNodes, instanceIds) : gatherCssPropsFromNodes(similarNodes, instanceIds);
let componentProps: ComponentProperties = {
...gatherPropsFromImageNodes(nodes, instanceIds),
...gatherPropsFromVectorNodes(nodes, instanceIds),
...gatherTextPropsFromNodes(nodes, instanceIds),
...gatherPropsFromImageNodes(similarNodes, instanceIds),
...gatherPropsFromVectorNodes(similarNodes, instanceIds),
...gatherTextPropsFromNodes(similarNodes, instanceIds),
...cssProps,
};


let allVectorGroups: boolean = true;
for (const node of nodes) {
if (!node.hasAnnotation(vectorGroupAnnotation)) {
allVectorGroups = false;
}
}

if (allVectorGroups) {
let children: Node[] = similarNodes[0].getChildren();
if (isEmpty(children)) {
return [true, componentProps];
}

if (!areAllNodesSimilar(nodes)) {
return [false, {}];
}

let children: Node[] = nodes[0].getChildren();
for (let i = 0; i < children.length; i++) {
let similarNodes: Node[] = [];
for (const targetNode of nodes) {
let similarChildrenNodes: Node[] = [];
for (const targetNode of similarNodes) {
const targetChildren: Node[] = targetNode.getChildren();
similarNodes.push(targetChildren[i]);
similarChildrenNodes.push(targetChildren[i]);
}

const [result, targetProps] = gatherPropsFromSimilarNodes(similarNodes, instanceIds);
const [result, targetProps] = gatherPropsFromSimilarNodes(similarChildrenNodes, instanceIds);
if (!result) {
return [result, {}];
}
Expand All @@ -447,7 +441,7 @@ export const gatherPropsFromVectorNodes = (nodes: Node[], instanceIds: string[])
}

for (const node of nodes) {
if (!node.hasAnnotation(vectorGroupAnnotation)) {
if (node.getType() !== NodeType.VECTOR || shouldUseAsBackgroundImage(node)) {
return properties;
}
}
Expand Down Expand Up @@ -503,7 +497,7 @@ export const gatherPropsFromImageNodes = (nodes: Node[], instanceIds: string[]):
}

for (const node of nodes) {
if (node.getType() !== NodeType.IMAGE) {
if (node.getType() !== NodeType.IMAGE || shouldUseAsBackgroundImage(node)) {
return properties;
}
}
Expand Down Expand Up @@ -606,7 +600,8 @@ export const gatherCssPropsFromNodes = (potentiallyRepeatedNode: Node[], instanc
return properties;
}

const sampleNodeType: NodeType = potentiallyRepeatedNode[0].getType();
const sampleNode: Node = potentiallyRepeatedNode[0];
const sampleNodeType: NodeType = sampleNode.getType();

let existingCssKeys: Set<string> = new Set<string>();
for (const node of potentiallyRepeatedNode) {
Expand Down Expand Up @@ -676,7 +671,7 @@ export const gatherCssPropsFromNodes = (potentiallyRepeatedNode: Node[], instanc

Object.entries(properties).forEach(([id, { cssKey, bindings }]) => {
let firstBinding: PropValueBinding = bindings[0];
if (sampleNodeType === NodeType.IMAGE || sampleNodeType === NodeType.VECTOR_GROUP || sampleNodeType === NodeType.VECTOR) {
if (!shouldUseAsBackgroundImage(sampleNode) && (sampleNodeType === NodeType.IMAGE || sampleNodeType === NodeType.VECTOR_GROUP || sampleNodeType === NodeType.VECTOR)) {
if (cssKey !== "width" && cssKey !== "height") {
delete properties[id];
return;
Expand All @@ -702,7 +697,8 @@ export const gatherTwcssPropsFromNodes = (potentiallyRepeatedNode: Node[], insta
return properties;
}

const sampleNodeType: NodeType = potentiallyRepeatedNode[0].getType();
const sampleNode: Node = potentiallyRepeatedNode[0];
const sampleNodeType: NodeType = sampleNode.getType();

let existingCssKeys: Set<string> = new Set<string>();
for (const node of potentiallyRepeatedNode) {
Expand Down Expand Up @@ -778,7 +774,7 @@ export const gatherTwcssPropsFromNodes = (potentiallyRepeatedNode: Node[], insta
}

Object.entries(properties).forEach(([id, { cssKey, bindings }]) => {
if (sampleNodeType === NodeType.IMAGE || sampleNodeType === NodeType.VECTOR_GROUP || sampleNodeType === NodeType.VECTOR) {
if (!shouldUseAsBackgroundImage(sampleNode) && (sampleNodeType === NodeType.IMAGE || sampleNodeType === NodeType.VECTOR_GROUP || sampleNodeType === NodeType.VECTOR)) {
if (cssKey !== "width" && cssKey !== "height") {
delete properties[id];
return;
Expand Down
Loading