Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: v2 #129

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
6 changes: 6 additions & 0 deletions .changeset/late-files-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@lottiefiles/relottie-extract-features': major
'@lottiefiles/relottie-metadata': major
---

feat: use v2 relottie packages with required changes
5 changes: 5 additions & 0 deletions .changeset/quick-pianos-train.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lottiefiles/relottie-parse': major
---

feat: capitalize Node type values after last@v2
5 changes: 5 additions & 0 deletions .changeset/sharp-phones-sip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lottiefiles/last-builder': minor
---

feat: add shape-modifier title
5 changes: 5 additions & 0 deletions .changeset/soft-students-sin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lottiefiles/last': major
---

feat(primitive): rename to PrimitiveNode, remove "valueType" prop & split it to StringNode, NumberNode, BooleanNode & NullNode
8 changes: 8 additions & 0 deletions .changeset/spicy-elephants-allow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@lottiefiles/last-builder': major
---

feat: required changes to support last@v2
- capitalize types
- remove "valueType", adjust "pt" helper after PrimitiveNode was split into String, Number, Null & Booelan Nodes
- remove the PrimitiveParts type since it is not relevant anymore after the "valueType" prop is removed
5 changes: 5 additions & 0 deletions .changeset/tall-pandas-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@lottiefiles/last': major
---

feat: capitalize Node type value
6 changes: 6 additions & 0 deletions .changeset/tiny-poets-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@lottiefiles/relottie-parse': major
---

feat: remove valueType option and don't add it prop to PrimtiveNode after last@v2 changes

7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ It represents Lottie constructs as JSON objects.

```json
{
"type": "root",
"type": "Root",
"title": "animation",
"hasExpressions": false,
"position": {
Expand All @@ -179,7 +179,7 @@ It represents Lottie constructs as JSON objects.
},
"children": [
{
"type": "attribute",
"type": "Attribute",
"key": {
"type": "key",
"position": {
Expand Down Expand Up @@ -211,7 +211,7 @@ It represents Lottie constructs as JSON objects.
},
"children": [
{
"type": "primitive",
"type": "String",
"value": "6.0.0",
"position": {
"start": {
Expand All @@ -225,7 +225,6 @@ It represents Lottie constructs as JSON objects.
"offset": 14
}
},
"valueType": "string"
}
]
}
Expand Down
22 changes: 11 additions & 11 deletions packages/last-builder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,59 +34,59 @@ const output = rt([

```javascript
{
type: 'root',
type: 'Root',
title: 'animation',
hasExpressions: false,
children: [
{
type: 'attribute',
type: 'Attribute',
key: 'v',
title: 'version',
children: [
{
type: 'primitive',
type: 'Strubg',
value: '4.8.0',
},
],
},
{
type: 'element',
type: 'Element',
key: 'meta',
title: 'metadata',
children: [
{
type: 'object',
type: 'Object',
title: 'custom',
children: [
{
type: 'attribute',
type: 'Attribute',
key: 'a',
title: 'author',
children: [
{
type: 'primitive',
type: 'String',
value: 'LottieFiles',
},
],
},
{
type: 'attribute',
type: 'Attribute',
key: 'd',
title: 'description',
children: [
{
type: 'primitive',
type: 'String',
value: 'A lottie animation.',
},
],
},
{
type: 'attribute',
type: 'Attribute',
key: 'data',
title: 'custom',
children: [
{
type: 'primitive',
type: 'Number',
value: 2,
},
],
Expand Down
22 changes: 11 additions & 11 deletions packages/last-builder/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,59 +20,59 @@ describe('should create a last tree correctly', () => {
]);

const output = {
type: 'root',
type: 'Root',
title: 'animation',
hasExpressions: false,
children: [
{
type: 'attribute',
type: 'Attribute',
key: 'v',
title: 'version',
children: [
{
type: 'primitive',
type: 'String',
value: '4.8.0',
},
],
},
{
type: 'element',
type: 'Element',
key: 'meta',
title: 'metadata',
children: [
{
type: 'object',
type: 'Object',
title: 'custom',
children: [
{
type: 'attribute',
type: 'Attribute',
key: 'a',
title: 'author',
children: [
{
type: 'primitive',
type: 'String',
value: 'LottieFiles',
},
],
},
{
type: 'attribute',
type: 'Attribute',
key: 'd',
title: 'description',
children: [
{
type: 'primitive',
type: 'String',
value: 'A lottie animation.',
},
],
},
{
type: 'attribute',
type: 'Attribute',
key: 'data',
title: 'custom',
children: [
{
type: 'primitive',
type: 'Number',
value: 2,
},
],
Expand Down
64 changes: 37 additions & 27 deletions packages/last-builder/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import type {
Root,
KeyValue,
KeyNode,
Primitive,
PrimitiveValue,
PrimitiveValueType,
PrimitiveNode,
PrimitiveNodeValue,
ObjectNode,
ObjectNodeValue,
ObjectTitle,
Expand All @@ -30,10 +29,6 @@ export interface Parts {
position?: Position;
}

export interface PrimitiveParts<T> extends Parts {
valueType?: T;
}

type Children<T> = T | T[];

function normalizeChildren<T>(children?: Children<T>): T[] {
Expand Down Expand Up @@ -70,22 +65,32 @@ function normalizeMemberChild<T>(child?: MemberChild<T>): [T] | [] {
}
}

function normalizePrimitiveValue<T>(value: T): T | string {
if (value === undefined) {
return 'empty';
} else {
return value;
}
}

/**
* Create a Primitive Node
* @param value - Primitive's value, e.g. 7
* @param value - Primitive's value, e.g. 7
* @param parts - additional data props e.g. Position
* @returns (last) Primitive node
* @returns
* - (last) PrimitiveNode
* - if value is not PrimitiveNodeValue, return a String node with value "UNKNOWN"
*/
export const pt = (value?: PrimitiveValue, parts?: PrimitiveParts<PrimitiveValueType>): Primitive => {
return u('primitive', { value: normalizePrimitiveValue(value) as PrimitiveValue, ...parts });
export const pt = (value?: PrimitiveNodeValue, parts?: Parts): PrimitiveNode => {
if (value === null) {
return u('Null', { value, ...parts });
}

switch (typeof value) {
case 'string':
return u('String', { value, ...parts });

case 'number':
return u('Number', { value, ...parts });

case 'boolean':
return u('Boolean', { value, ...parts });

default:
return u('String', { value: 'UNKNOWN', ...parts });
}
};

/**
Expand All @@ -95,7 +100,7 @@ export const pt = (value?: PrimitiveValue, parts?: PrimitiveParts<PrimitiveValue
* @returns (last) Key node
*/
export const ky = (value: string, parts?: Parts): KeyNode => {
return u('key', { ...parts }, value);
return u('Key', { ...parts }, value);
};

/**
Expand All @@ -107,7 +112,7 @@ export const ky = (value: string, parts?: Parts): KeyNode => {
*/
export const ob = (title: ObjectTitle, kids?: Children<ObjectNodeValue>, parts?: Parts): ObjectNode =>
u(
'object',
'Object',
{
title,
...parts,
Expand All @@ -124,7 +129,7 @@ export const ob = (title: ObjectTitle, kids?: Children<ObjectNodeValue>, parts?:
*/
export const ar = (title: ArrayTitle, kids?: Children<ArrayNodeValue>, parts?: Parts): ArrayNode =>
u(
'array',
'Array',
{
title,
...parts,
Expand All @@ -140,8 +145,13 @@ export const ar = (title: ArrayTitle, kids?: Children<ArrayNodeValue>, parts?: P
* @param parts - additional data props e.g. Position
* @returns (last) Attribute node
*/
export const at = (key: KeyValue, title: AttributeTitle, kid?: MemberChild<Primitive>, parts?: Parts): Attribute => {
return u('attribute', { key, title, ...parts }, normalizeMemberChild(kid));
export const at = (
key: KeyValue,
title: AttributeTitle,
kid?: MemberChild<PrimitiveNode>,
parts?: Parts,
): Attribute => {
return u('Attribute', { key, title, ...parts }, normalizeMemberChild(kid));
};

/**
Expand All @@ -153,7 +163,7 @@ export const at = (key: KeyValue, title: AttributeTitle, kid?: MemberChild<Primi
* @returns (last) Element node
*/
export const el = (key: KeyValue, title: ElementTitle, kid?: MemberChild<ObjectNode>, parts?: Parts): Element => {
return u('element', { key, title, ...parts }, normalizeMemberChild(kid));
return u('Element', { key, title, ...parts }, normalizeMemberChild(kid));
};

/**
Expand All @@ -165,7 +175,7 @@ export const el = (key: KeyValue, title: ElementTitle, kid?: MemberChild<ObjectN
* @returns (last) Collection node
*/
export const cl = (key: KeyValue, title: CollectionTitle, kid?: MemberChild<ArrayNode>, parts?: Parts): Collection => {
return u('collection', { key, title, ...parts }, normalizeMemberChild(kid));
return u('Collection', { key, title, ...parts }, normalizeMemberChild(kid));
};

/**
Expand All @@ -176,7 +186,7 @@ export const cl = (key: KeyValue, title: CollectionTitle, kid?: MemberChild<Arra
*/
export const rt = (kids?: Children<ObjectNodeValue>, parts?: Parts): Root => {
return u(
'root',
'Root',
{
title: TITLES.object.animation,
hasExpressions: false,
Expand Down
Loading
Loading