-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add support for
amp-story-audio-sticker
- Loading branch information
1 parent
000ba86
commit 889a441
Showing
39 changed files
with
947 additions
and
9 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
100 changes: 100 additions & 0 deletions
100
packages/element-library/src/audio-sticker/constants.js
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,100 @@ | ||
/* | ||
* Copyright 2023 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { PanelTypes } from '@googleforcreators/design-system'; | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { SHARED_DEFAULT_ATTRIBUTES } from '../shared'; | ||
import headphoneCat from './sticker-images/headphone-cat/headphone-cat-pretap.png'; | ||
import tapePlayer from './sticker-images/tape-player/tape-player-pretap.png'; | ||
import loudSpeaker from './sticker-images/loud-speaker/loud-speaker-posttap.png'; | ||
import audioCloud from './sticker-images/audio-cloud/audio-cloud-posttap.png'; | ||
|
||
export const hasEditMode = false; | ||
export const hasEditModeIfLocked = false; | ||
export const hasEditModeMoveable = false; | ||
export const editModeGrayout = false; | ||
|
||
export const hasDesignMenu = true; | ||
|
||
export const hasDuplicateMenu = false; | ||
|
||
export const isMedia = false; | ||
|
||
export const canFlip = true; | ||
|
||
export const isMaskable = false; | ||
|
||
export const isAspectAlwaysLocked = false; | ||
|
||
export const resizeRules = { | ||
vertical: false, | ||
horizontal: false, | ||
diagonal: false, | ||
}; | ||
|
||
export const AUDIO_STICKERS = { | ||
'headphone-cat': headphoneCat, | ||
'tape-player': tapePlayer, | ||
'loud-speaker': loudSpeaker, | ||
'audio-cloud': audioCloud, | ||
}; | ||
|
||
export const AUDIO_STICKER_WIDTH_PRESETS = { | ||
SMALL: 120, | ||
LARGE: 180, | ||
}; | ||
|
||
export const AUDIO_STICKER_ASPECT_RATIOS = { | ||
'headphone-cat': 1.24, | ||
'tape-player': 1.18, | ||
'loud-speaker': 1, | ||
'audio-cloud': 1.54, | ||
}; | ||
|
||
export const AUDIO_STICKER_DEFAULT_PRESET = { | ||
x: 100, | ||
y: 100, | ||
width: | ||
AUDIO_STICKER_WIDTH_PRESETS.SMALL * | ||
AUDIO_STICKER_ASPECT_RATIOS['headphone-cat'], | ||
height: AUDIO_STICKER_WIDTH_PRESETS.SMALL, | ||
sticker: 'headphone-cat', | ||
size: 'small', | ||
}; | ||
|
||
export const AUDIO_STICKER_STYLES = { | ||
none: '', | ||
outline: 'border: 2px solid white; border-radius: 20px', | ||
dropshadow: 'filter: drop-shadow(0 0 0.75rem crimson);', | ||
}; | ||
|
||
export const defaultAttributes = { | ||
...SHARED_DEFAULT_ATTRIBUTES, | ||
size: 'small', | ||
sticker: 'headphone-cat', | ||
style: 'none', | ||
lockDimensions: true, | ||
}; | ||
|
||
export const panels = [ | ||
PanelTypes.ElementAlignment, | ||
PanelTypes.AudioSticker, | ||
PanelTypes.Animation, | ||
]; |
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,95 @@ | ||
/* | ||
* Copyright 2023 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
/** | ||
* External dependencies | ||
*/ | ||
import styled from 'styled-components'; | ||
import { useRef } from '@googleforcreators/react'; | ||
import { useTransformHandler } from '@googleforcreators/transform'; | ||
import { shouldDisplayBorder } from '@googleforcreators/masks'; | ||
import { StoryPropTypes } from '@googleforcreators/elements'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { | ||
elementFillContent, | ||
elementWithBackgroundColor, | ||
elementWithBorder, | ||
} from '../shared'; | ||
import { AUDIO_STICKERS, AUDIO_STICKER_STYLES } from './constants'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
|
||
const Element = styled.img` | ||
${elementFillContent} | ||
${elementWithBackgroundColor} | ||
${elementWithBorder} | ||
${({ stickerStyle }) => AUDIO_STICKER_STYLES[stickerStyle]} | ||
`; | ||
|
||
function AudioStickerDisplay({ element }) { | ||
const { | ||
id, | ||
border, | ||
width: elementWidth, | ||
height: elementHeight, | ||
sticker, | ||
style, | ||
} = element; | ||
|
||
const ref = useRef(null); | ||
|
||
useTransformHandler(id, (transform) => { | ||
// Since outside border is applied directly to the element, we need to | ||
// adjust the size of the element according to the border width. | ||
if (ref.current) { | ||
if (transform) { | ||
const { resize } = transform; | ||
if (resize && resize[0] !== 0 && resize[1] !== 0) { | ||
const [width, height] = resize; | ||
if (shouldDisplayBorder(element)) { | ||
ref.current.style.width = width + border.left + border.right + 'px'; | ||
ref.current.style.height = | ||
height + border.top + border.bottom + 'px'; | ||
} | ||
} | ||
} else { | ||
ref.current.style.width = ''; | ||
ref.current.style.height = ''; | ||
} | ||
} | ||
}); | ||
|
||
return ( | ||
<Element | ||
src={AUDIO_STICKERS[sticker]} | ||
stickerStyle={style} | ||
ref={ref} | ||
height={elementHeight} | ||
width={elementWidth} | ||
alt="audio-sticker" | ||
/> | ||
); | ||
} | ||
|
||
AudioStickerDisplay.propTypes = { | ||
element: StoryPropTypes.elements.shape.isRequired, | ||
}; | ||
|
||
export default AudioStickerDisplay; |
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,37 @@ | ||
/* | ||
* Copyright 2020 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* External dependencies | ||
*/ | ||
import styled from 'styled-components'; | ||
import { Icons } from '@googleforcreators/design-system'; | ||
|
||
const IconContainer = styled.div` | ||
height: 21px; | ||
width: 21px; | ||
overflow: hidden; | ||
`; | ||
|
||
function AudioStickerIcon() { | ||
return ( | ||
<IconContainer> | ||
<Icons.AudioSticker height={21} width={21} /> | ||
</IconContainer> | ||
); | ||
} | ||
|
||
export default AudioStickerIcon; |
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,21 @@ | ||
/* | ||
* Copyright 2023 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
export { default as Display } from './display'; | ||
export { default as Output } from './output'; | ||
export { default as LayerIcon } from './icon'; | ||
export { default as getLayerText } from './layer'; | ||
|
||
export * from './constants'; |
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,27 @@ | ||
/* | ||
* Copyright 2023 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { __ } from '@googleforcreators/i18n'; | ||
|
||
function getAudioStickerLayerText(element) { | ||
const { alt } = element?.resource || {}; | ||
|
||
return alt || __('Audio Sticker', 'web-stories'); | ||
} | ||
|
||
export default getAudioStickerLayerText; |
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,21 @@ | ||
/* | ||
* Copyright 2023 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
function AudioStickerOutput() { | ||
// TODO (@AnuragVasanwala): Need to move this logic here from 'packages/output/src/page.js'. | ||
return <div>{'AudioStickerOutput'}</div>; | ||
} | ||
|
||
export default AudioStickerOutput; |
Binary file added
BIN
+4.08 KB
...nt-library/src/audio-sticker/sticker-images/audio-cloud/audio-cloud-posttap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.31 KB
...ent-library/src/audio-sticker/sticker-images/audio-cloud/audio-cloud-pretap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+633 KB
...ibrary/src/audio-sticker/sticker-images/headphone-cat/headphone-cat-posttap.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+41.6 KB
...library/src/audio-sticker/sticker-images/headphone-cat/headphone-cat-pretap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+78.4 KB
...-library/src/audio-sticker/sticker-images/loud-speaker/loud-speaker-posttap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+31.6 KB
...t-library/src/audio-sticker/sticker-images/loud-speaker/loud-speaker-pretap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+26.8 KB
...nt-library/src/audio-sticker/sticker-images/tape-player/tape-player-posttap.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+12.1 KB
...ent-library/src/audio-sticker/sticker-images/tape-player/tape-player-pretap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Oops, something went wrong.