@operato/image-marker 8.0.0-alpha.33 → 8.0.0-alpha.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,135 @@
1
+ import '../src/ox-image-marker.js'
2
+
3
+ import { html, TemplateResult } from 'lit'
4
+ import { styles as MDTypeScaleStyles } from '@material/web/typography/md-typescale-styles'
5
+
6
+ import { Shape } from '../src/types.js'
7
+
8
+ export default {
9
+ title: 'test-image-provider',
10
+ component: 'test-image-provider',
11
+ argTypes: {
12
+ imageUrl: { control: 'text', description: 'Image URL to display in the marker.' },
13
+ shapes: { control: 'object', description: 'List of shapes to display on the image.' },
14
+ currentShapeType: {
15
+ control: 'select',
16
+ options: ['text', 'rectangle', 'circle', 'triangle', 'line', 'arrow'],
17
+ description: 'The type of shape to draw on the image.'
18
+ }
19
+ }
20
+ }
21
+
22
+ interface Story<T> {
23
+ (args: T): TemplateResult
24
+ args?: Partial<T>
25
+ argTypes?: Record<string, unknown>
26
+ }
27
+
28
+ interface ArgTypes {
29
+ imageUrl: string
30
+ shapes: Shape[]
31
+ }
32
+
33
+ const Template: Story<ArgTypes> = ({ imageUrl, shapes = [] }: ArgTypes) => html`
34
+ <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap" rel="stylesheet" />
35
+ <link href="/themes/light.css" rel="stylesheet" />
36
+ <link href="/themes/dark.css" rel="stylesheet" />
37
+ <link href="/themes/spacing.css" rel="stylesheet" />
38
+ <link href="/themes/md-typescale-styles.css" rel="stylesheet" />
39
+
40
+ <link
41
+ href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL@20..48,100..700,0..1"
42
+ rel="stylesheet"
43
+ />
44
+ <link
45
+ href="https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL@20..48,100..700,0..1"
46
+ rel="stylesheet"
47
+ />
48
+ <link
49
+ href="https://fonts.googleapis.com/css2?family=Material+Symbols+Sharp:opsz,wght,FILL@20..48,100..700,0..1"
50
+ rel="stylesheet"
51
+ />
52
+
53
+ <style>
54
+ ${MDTypeScaleStyles.cssText}
55
+ </style>
56
+
57
+ <style>
58
+ html,
59
+ body {
60
+ margin: 0;
61
+ padding: 0;
62
+ overflow: hidden;
63
+
64
+ overscroll-behavior-y: none;
65
+
66
+ /* This is a font-stack that tries to use the system-default sans-serifs first */
67
+ font-family: Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
68
+ line-height: 1.5;
69
+ -webkit-font-smoothing: antialiased;
70
+
71
+ accent-color: var(--md-sys-color-primary);
72
+ }
73
+
74
+ body {
75
+ width: 100%;
76
+ height: 800px;
77
+ text-align: center;
78
+
79
+ background-color: var(--md-sys-color-background);
80
+ color: var(--md-sys-color-on-background);
81
+ }
82
+
83
+ ox-image-marker {
84
+ height: 650px;
85
+ box-sizing: border-box;
86
+ background-color: var(--md-sys-color-primary-container);
87
+ color: var(--md-sys-color-on-primary-container);
88
+ }
89
+ </style>
90
+
91
+ <script type="module">
92
+ import { TestImageProvider } from '../dist/stories/test-image-provider.js'
93
+ const imageMarker = document.body.querySelector('ox-image-marker')
94
+
95
+ imageMarker.setImageProvider(new TestImageProvider(1080, 720))
96
+ document.body.querySelector('[button1]').addEventListener('click', e => {
97
+ imageMarker.setImageProvider(new TestImageProvider(1600, 1200))
98
+ })
99
+ document.body.querySelector('[button2]').addEventListener('click', e => {
100
+ imageMarker.setImageProvider(new TestImageProvider(800, 600))
101
+ })
102
+ </script>
103
+
104
+ <ox-image-marker .imageUrl=${imageUrl} .shapes=${shapes}></ox-image-marker>
105
+ <div buttons>
106
+ <button button1>1200 x 800</button>
107
+ <button button2>800 x 600</button>
108
+ </div>
109
+ `
110
+
111
+ export const Regular = Template.bind({})
112
+ Regular.args = {
113
+ imageUrl: 'https://via.placeholder.com/800x600',
114
+ shapes: [
115
+ {
116
+ id: '1',
117
+ type: 'rectangle',
118
+ x: 100,
119
+ y: 100,
120
+ width: 200,
121
+ height: 150,
122
+ selected: true,
123
+ text: 'Rectangle 1'
124
+ },
125
+ {
126
+ id: '2',
127
+ type: 'circle',
128
+ cx: 300,
129
+ cy: 300,
130
+ r: 50,
131
+ selected: false,
132
+ text: 'Circle 1'
133
+ }
134
+ ]
135
+ }
@@ -0,0 +1,49 @@
1
+ import { ImageOptions, ImageProvider } from '../src/types'
2
+
3
+ export class TestImageProvider implements ImageProvider {
4
+ private width: number = 0
5
+ private height: number = 0
6
+
7
+ constructor(width: number, height: number) {
8
+ this.width = width
9
+ this.height = height
10
+ }
11
+
12
+ async getImage(options: ImageOptions): Promise<string> {
13
+ // 무작위 색상 생성 함수
14
+ const getRandomColor = () => {
15
+ const letters = '0123456789ABCDEF'
16
+ let color = '#'
17
+ for (let i = 0; i < 6; i++) {
18
+ color += letters[Math.floor(Math.random() * 16)]
19
+ }
20
+ return color
21
+ }
22
+
23
+ // 무작위 색상 그라데이션 이미지 생성
24
+ const canvas = document.createElement('canvas')
25
+ const ctx = canvas.getContext('2d')
26
+ if (!ctx) {
27
+ throw new Error('Failed to get canvas context')
28
+ }
29
+
30
+ const width = this.width
31
+ const height = this.height
32
+ canvas.width = width
33
+ canvas.height = height
34
+
35
+ const gradient = ctx.createLinearGradient(0, 0, width, height)
36
+ gradient.addColorStop(0, getRandomColor())
37
+ gradient.addColorStop(0.15, getRandomColor())
38
+ gradient.addColorStop(0.3, getRandomColor())
39
+ gradient.addColorStop(0.5, getRandomColor())
40
+ gradient.addColorStop(0.65, getRandomColor())
41
+ gradient.addColorStop(0.8, getRandomColor())
42
+ gradient.addColorStop(1, getRandomColor())
43
+
44
+ ctx.fillStyle = gradient
45
+ ctx.fillRect(0, 0, width, height)
46
+
47
+ return canvas.toDataURL()
48
+ }
49
+ }