-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into by/dont-drop-data-r…
…etention
- Loading branch information
Showing
121 changed files
with
3,782 additions
and
1,154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1,582 changes: 1,384 additions & 198 deletions
1,582
ee/frontend/mobile-replay/__snapshots__/transform.test.ts.snap
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// from https://gist.github.com/t1grok/a0f6d04db569890bcb57 | ||
|
||
interface rgb { | ||
r: number | ||
g: number | ||
b: number | ||
} | ||
interface yuv { | ||
y: number | ||
u: number | ||
v: number | ||
} | ||
|
||
function hexToRgb(hexColor: string): rgb | null { | ||
const shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i | ||
hexColor = hexColor.replace(shorthandRegex, function (_, r, g, b) { | ||
return r + r + g + g + b + b | ||
}) | ||
|
||
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hexColor) | ||
return result | ||
? { | ||
r: parseInt(result[1], 16), | ||
g: parseInt(result[2], 16), | ||
b: parseInt(result[3], 16), | ||
} | ||
: null | ||
} | ||
|
||
function rgbToYuv(rgbColor: rgb): yuv { | ||
let y, u, v | ||
|
||
y = rgbColor.r * 0.299 + rgbColor.g * 0.587 + rgbColor.b * 0.114 | ||
u = rgbColor.r * -0.168736 + rgbColor.g * -0.331264 + rgbColor.b * 0.5 + 128 | ||
v = rgbColor.r * 0.5 + rgbColor.g * -0.418688 + rgbColor.b * -0.081312 + 128 | ||
|
||
y = Math.floor(y) | ||
u = Math.floor(u) | ||
v = Math.floor(v) | ||
|
||
return { y: y, u: u, v: v } | ||
} | ||
|
||
export const isLight = (hexColor: string): boolean => { | ||
const rgbColor = hexToRgb(hexColor) | ||
if (!rgbColor) { | ||
return false | ||
} | ||
const yuvColor = rgbToYuv(rgbColor) | ||
return yuvColor.y > 128 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import { NodeType, serializedNodeWithId, wireframeNavigationBar, wireframeStatusBar } from '../mobile.types' | ||
import { isLight } from './colors' | ||
import { NAVIGATION_BAR_ID, STATUS_BAR_ID } from './transformers' | ||
import { ConversionContext, ConversionResult } from './types' | ||
import { asStyleString, makeStylesString } from './wireframeStyle' | ||
|
||
function spacerDiv(idSequence: Generator<number>): serializedNodeWithId { | ||
const spacerId = idSequence.next().value | ||
return { | ||
type: NodeType.Element, | ||
tagName: 'div', | ||
attributes: { | ||
style: 'width: 5px;', | ||
'data-rrweb-id': spacerId, | ||
}, | ||
id: spacerId, | ||
childNodes: [], | ||
} | ||
} | ||
|
||
function makeFakeNavButton(icon: string, context: ConversionContext): serializedNodeWithId { | ||
return { | ||
type: NodeType.Element, | ||
tagName: 'div', | ||
attributes: {}, | ||
id: context.idSequence.next().value, | ||
childNodes: [ | ||
{ | ||
type: NodeType.Text, | ||
textContent: icon, | ||
id: context.idSequence.next().value, | ||
}, | ||
], | ||
} | ||
} | ||
|
||
export function makeNavigationBar( | ||
wireframe: wireframeNavigationBar, | ||
_children: serializedNodeWithId[], | ||
context: ConversionContext | ||
): ConversionResult<serializedNodeWithId> | null { | ||
const _id = wireframe.id || NAVIGATION_BAR_ID | ||
|
||
const backArrowTriangle = makeFakeNavButton('◀', context) | ||
const homeCircle = makeFakeNavButton('⚪', context) | ||
const screenButton = makeFakeNavButton('⬜️', context) | ||
|
||
return { | ||
result: { | ||
type: NodeType.Element, | ||
tagName: 'div', | ||
attributes: { | ||
style: asStyleString([ | ||
makeStylesString(wireframe), | ||
'display:flex', | ||
'flex-direction:row', | ||
'align-items:center', | ||
'justify-content:space-around', | ||
'color:white', | ||
]), | ||
'data-rrweb-id': _id, | ||
}, | ||
id: _id, | ||
childNodes: [backArrowTriangle, homeCircle, screenButton], | ||
}, | ||
context, | ||
} | ||
} | ||
|
||
/** | ||
* tricky: we need to accept children because that's the interface of converters, but we don't use them | ||
*/ | ||
export function makeStatusBar( | ||
wireframe: wireframeStatusBar, | ||
_children: serializedNodeWithId[], | ||
context: ConversionContext | ||
): ConversionResult<serializedNodeWithId> { | ||
const clockId = context.idSequence.next().value | ||
// convert the wireframe timestamp to a date time, then get just the hour and minute of the time from that | ||
const clockTime = context.timestamp | ||
? new Date(context.timestamp).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }) | ||
: '' | ||
|
||
const clockFontColor = isLight(wireframe.style?.backgroundColor || '#ffffff') ? 'black' : 'white' | ||
|
||
const clock: serializedNodeWithId = { | ||
type: NodeType.Element, | ||
tagName: 'div', | ||
attributes: { | ||
'data-rrweb-id': clockId, | ||
}, | ||
id: clockId, | ||
childNodes: [ | ||
{ | ||
type: NodeType.Text, | ||
textContent: clockTime, | ||
id: context.idSequence.next().value, | ||
}, | ||
], | ||
} | ||
|
||
return { | ||
result: { | ||
type: NodeType.Element, | ||
tagName: 'div', | ||
attributes: { | ||
style: asStyleString([ | ||
makeStylesString(wireframe, { color: clockFontColor }), | ||
'display:flex', | ||
'flex-direction:row', | ||
'align-items:center', | ||
]), | ||
'data-rrweb-id': STATUS_BAR_ID, | ||
}, | ||
id: STATUS_BAR_ID, | ||
childNodes: [spacerDiv(context.idSequence), clock], | ||
}, | ||
context, | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.