ozdenui 0.1.0

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.
Files changed (149) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +14 -0
  3. data/NOTICE +5 -0
  4. data/README.md +242 -0
  5. data/exe/ozdenui +17 -0
  6. data/lib/ozdenui/AGENTS.md +210 -0
  7. data/lib/ozdenui/COMPONENTS.md +3017 -0
  8. data/lib/ozdenui/app.rb +749 -0
  9. data/lib/ozdenui/command.rb +107 -0
  10. data/lib/ozdenui/components.rb +368 -0
  11. data/lib/ozdenui/dialogs.rb +212 -0
  12. data/lib/ozdenui/files.rb +124 -0
  13. data/lib/ozdenui/icon.png +0 -0
  14. data/lib/ozdenui/kit.json +1 -0
  15. data/lib/ozdenui/kit.rb +115 -0
  16. data/lib/ozdenui/look.rb +229 -0
  17. data/lib/ozdenui/objects.rb +652 -0
  18. data/lib/ozdenui/server.rb +270 -0
  19. data/lib/ozdenui/values.rb +273 -0
  20. data/lib/ozdenui/version.rb +15 -0
  21. data/lib/ozdenui/web/basic/LICENSE +14 -0
  22. data/lib/ozdenui/web/basic/basic.min.css +1 -0
  23. data/lib/ozdenui/web/basic/basic.min.js +78 -0
  24. data/lib/ozdenui/web/basic/font/open-sans/LICENSE.txt +206 -0
  25. data/lib/ozdenui/web/basic/font/open-sans/OpenSans-Bold.ttf +0 -0
  26. data/lib/ozdenui/web/basic/font/open-sans/OpenSans-Regular.ttf +0 -0
  27. data/lib/ozdenui/web/basic/scroll-bar.min.js +3 -0
  28. data/lib/ozdenui/web/bridge.js +584 -0
  29. data/lib/ozdenui/web/comp/accordion.js +659 -0
  30. data/lib/ozdenui/web/comp/action-button/add.png +0 -0
  31. data/lib/ozdenui/web/comp/action-button.js +521 -0
  32. data/lib/ozdenui/web/comp/action-tab-bar.js +383 -0
  33. data/lib/ozdenui/web/comp/app-bar.js +237 -0
  34. data/lib/ozdenui/web/comp/badge.js +292 -0
  35. data/lib/ozdenui/web/comp/bottom-bar.js +555 -0
  36. data/lib/ozdenui/web/comp/breadcrumbs.js +524 -0
  37. data/lib/ozdenui/web/comp/canvas.js +652 -0
  38. data/lib/ozdenui/web/comp/chat-view.js +827 -0
  39. data/lib/ozdenui/web/comp/check-box.js +490 -0
  40. data/lib/ozdenui/web/comp/code-editor.js +965 -0
  41. data/lib/ozdenui/web/comp/color-picker.js +636 -0
  42. data/lib/ozdenui/web/comp/context-menu.js +951 -0
  43. data/lib/ozdenui/web/comp/currency-field.js +209 -0
  44. data/lib/ozdenui/web/comp/data-table/arrow.svg +2 -0
  45. data/lib/ozdenui/web/comp/data-table.js +937 -0
  46. data/lib/ozdenui/web/comp/date-picker.js +1055 -0
  47. data/lib/ozdenui/web/comp/dialog.js +992 -0
  48. data/lib/ozdenui/web/comp/email-field.js +65 -0
  49. data/lib/ozdenui/web/comp/file-picker.js +920 -0
  50. data/lib/ozdenui/web/comp/filters.js +807 -0
  51. data/lib/ozdenui/web/comp/form.js +602 -0
  52. data/lib/ozdenui/web/comp/full-screen-select/arrow.svg +2 -0
  53. data/lib/ozdenui/web/comp/full-screen-select/cancel.svg +2 -0
  54. data/lib/ozdenui/web/comp/full-screen-select.js +614 -0
  55. data/lib/ozdenui/web/comp/gauge.js +439 -0
  56. data/lib/ozdenui/web/comp/graph-box.js +3911 -0
  57. data/lib/ozdenui/web/comp/grid-group.js +185 -0
  58. data/lib/ozdenui/web/comp/hold-to-confirm-button/trash-red.png +0 -0
  59. data/lib/ozdenui/web/comp/hold-to-confirm-button/trash.png +0 -0
  60. data/lib/ozdenui/web/comp/hold-to-confirm-button.js +289 -0
  61. data/lib/ozdenui/web/comp/image-view.js +598 -0
  62. data/lib/ozdenui/web/comp/item-list.js +1740 -0
  63. data/lib/ozdenui/web/comp/json-editor.js +3221 -0
  64. data/lib/ozdenui/web/comp/json-view.js +597 -0
  65. data/lib/ozdenui/web/comp/label-editor.js +1140 -0
  66. data/lib/ozdenui/web/comp/left-menu/data-table.png +0 -0
  67. data/lib/ozdenui/web/comp/left-menu/home.png +0 -0
  68. data/lib/ozdenui/web/comp/left-menu/reports.png +0 -0
  69. data/lib/ozdenui/web/comp/left-menu/setting.png +0 -0
  70. data/lib/ozdenui/web/comp/left-menu.js +548 -0
  71. data/lib/ozdenui/web/comp/line-progress-bar.js +343 -0
  72. data/lib/ozdenui/web/comp/loading-screen.js +413 -0
  73. data/lib/ozdenui/web/comp/log-view.js +530 -0
  74. data/lib/ozdenui/web/comp/login-page.js +685 -0
  75. data/lib/ozdenui/web/comp/markdown-view.js +1045 -0
  76. data/lib/ozdenui/web/comp/menu-bar.js +624 -0
  77. data/lib/ozdenui/web/comp/mini-graph-box.js +492 -0
  78. data/lib/ozdenui/web/comp/minimal-accent.js +208 -0
  79. data/lib/ozdenui/web/comp/notice.js +229 -0
  80. data/lib/ozdenui/web/comp/number-field.js +128 -0
  81. data/lib/ozdenui/web/comp/numeric-keyboard.js +298 -0
  82. data/lib/ozdenui/web/comp/page-control.js +762 -0
  83. data/lib/ozdenui/web/comp/page-header.js +191 -0
  84. data/lib/ozdenui/web/comp/password-field/hide-btn.png +0 -0
  85. data/lib/ozdenui/web/comp/password-field/hide-btn2.png +0 -0
  86. data/lib/ozdenui/web/comp/password-field/show-btn.png +0 -0
  87. data/lib/ozdenui/web/comp/password-field/show-btn2.png +0 -0
  88. data/lib/ozdenui/web/comp/password-field.js +192 -0
  89. data/lib/ozdenui/web/comp/period-bar.js +436 -0
  90. data/lib/ozdenui/web/comp/phone-field.js +322 -0
  91. data/lib/ozdenui/web/comp/progress-bar.js +992 -0
  92. data/lib/ozdenui/web/comp/property-panel.js +3639 -0
  93. data/lib/ozdenui/web/comp/radio-button.js +527 -0
  94. data/lib/ozdenui/web/comp/range-slider.js +569 -0
  95. data/lib/ozdenui/web/comp/rich-text-editor.js +1064 -0
  96. data/lib/ozdenui/web/comp/scroll-area.js +308 -0
  97. data/lib/ozdenui/web/comp/scrolling-text.js +297 -0
  98. data/lib/ozdenui/web/comp/search-input/clear-round.svg +1 -0
  99. data/lib/ozdenui/web/comp/search-input/clear.svg +1 -0
  100. data/lib/ozdenui/web/comp/search-input/filter.png +0 -0
  101. data/lib/ozdenui/web/comp/search-input/filter.svg +1 -0
  102. data/lib/ozdenui/web/comp/search-input/search.svg +1 -0
  103. data/lib/ozdenui/web/comp/search-input.js +725 -0
  104. data/lib/ozdenui/web/comp/search-results.js +596 -0
  105. data/lib/ozdenui/web/comp/select-box.js +1862 -0
  106. data/lib/ozdenui/web/comp/settings-row.js +299 -0
  107. data/lib/ozdenui/web/comp/side-panel.js +616 -0
  108. data/lib/ozdenui/web/comp/slider-field.js +952 -0
  109. data/lib/ozdenui/web/comp/slider.js +838 -0
  110. data/lib/ozdenui/web/comp/smart-button/alert-black.png +0 -0
  111. data/lib/ozdenui/web/comp/smart-button/clock.png +0 -0
  112. data/lib/ozdenui/web/comp/smart-button.js +981 -0
  113. data/lib/ozdenui/web/comp/smart-table/clock.png +0 -0
  114. data/lib/ozdenui/web/comp/smart-table/down.png +0 -0
  115. data/lib/ozdenui/web/comp/smart-table/scroll.png +0 -0
  116. data/lib/ozdenui/web/comp/smart-table/sort.png +0 -0
  117. data/lib/ozdenui/web/comp/smart-table/up.png +0 -0
  118. data/lib/ozdenui/web/comp/smart-table.js +1883 -0
  119. data/lib/ozdenui/web/comp/sortable-list.js +1181 -0
  120. data/lib/ozdenui/web/comp/spark-line-box.js +738 -0
  121. data/lib/ozdenui/web/comp/splitter.js +411 -0
  122. data/lib/ozdenui/web/comp/status-bar.js +408 -0
  123. data/lib/ozdenui/web/comp/step-bar.js +345 -0
  124. data/lib/ozdenui/web/comp/stepper.js +753 -0
  125. data/lib/ozdenui/web/comp/tabs.js +1366 -0
  126. data/lib/ozdenui/web/comp/tag-input.js +1107 -0
  127. data/lib/ozdenui/web/comp/tap-effect.js +170 -0
  128. data/lib/ozdenui/web/comp/text-area-field.js +233 -0
  129. data/lib/ozdenui/web/comp/text-field.js +1006 -0
  130. data/lib/ozdenui/web/comp/time-line.js +398 -0
  131. data/lib/ozdenui/web/comp/time-picker.js +1032 -0
  132. data/lib/ozdenui/web/comp/tiny-select/arrow.svg +1 -0
  133. data/lib/ozdenui/web/comp/tiny-select.js +322 -0
  134. data/lib/ozdenui/web/comp/tiny-table.js +283 -0
  135. data/lib/ozdenui/web/comp/toast.js +891 -0
  136. data/lib/ozdenui/web/comp/toggle.js +757 -0
  137. data/lib/ozdenui/web/comp/tool-bar.js +760 -0
  138. data/lib/ozdenui/web/comp/tooltip.js +534 -0
  139. data/lib/ozdenui/web/comp/tree-view.js +1179 -0
  140. data/lib/ozdenui/web/comp/ui-effects.js +1097 -0
  141. data/lib/ozdenui/web/comp/ui-standards.js +403 -0
  142. data/lib/ozdenui/web/comp/url-field.js +190 -0
  143. data/lib/ozdenui/web/comp/web-view.js +588 -0
  144. data/lib/ozdenui/web/components.js +123 -0
  145. data/lib/ozdenui/web/index.html +39 -0
  146. data/lib/ozdenui/window.rb +188 -0
  147. data/lib/ozdenui/window_cocoa.rb +221 -0
  148. data/lib/ozdenui.rb +32 -0
  149. metadata +200 -0
@@ -0,0 +1,3639 @@
1
+ /* Bismillah */
2
+
3
+ /*
4
+
5
+ PropertyPanel - v26.09
6
+
7
+ UI COMPONENT TEMPLATE
8
+ - A property inspector at the right side of the screen, like the "Design" panel of design tools.
9
+ Full height, 240 px wide (width), in the dark look of the kit: its warm dark, fields with a thin line, the
10
+ accent #65A293, the titles of the sections in small capitals and a line under the chosen tab (style.tab.look:
11
+ "pill" puts a field behind it; style.sectionTitle.uppercase: 0 writes the titles as they are).
12
+ - Built from a JSON (data): header tabs, a title with action icons, and sections of items.
13
+ footer: one more section, fixed at the bottom (out of the scrolling part). Ex: a note field.
14
+ A section with mark: 1 has a line in the accent color at its left (style.panel.markWidth): a place the eye
15
+ finds again (Ex: Size and Position). WHY a line: a lighter background is too weak, an inverted one too strong.
16
+ headerTitle: a name at the left of the header; the tabs and the headerItem come next to it.
17
+ empty: { icon, title, text, hints: [{ keys, text }] } -> a page in the middle in place of the sections
18
+ (Ex: nothing is selected).
19
+ Each item has a type, a key, a value and its own settings. Every item type is a small object
20
+ built by its own function (see *** ITEM TYPES):
21
+ number -> [X 396] prefix text or icon (drag the prefix to change the value; prefixWidth for a word), unit, min, max, step, autoText
22
+ prefixClick: a click on the prefix (not a drag) gives this value, like a pick of the menu of a combo;
23
+ the prefix lights up under the mouse (Ex: "Left" -> the value "__side:right")
24
+ parseText(text): a text that is not a plain number goes to it; it returns the value ("100%", "auto")
25
+ or undefined (the old value comes back). A text value is shown as it is.
26
+ commaIsList: 1 -> a comma separates values ("12,0" goes to parseText as a list), it is not a decimal comma.
27
+ textToNumber(value): the number of a text value, to drag or step it (Ex: "100%" -> its width in px).
28
+ button: { icon, hint } -> [P 14, 10 ▢] a small button at the end of the field (also of a text). Its
29
+ click sends { kind: "action", key, value: "button", field } (field: the field, Ex: to open an editor
30
+ of the value at its height). So do a click on the prefix (not a drag; without prefixClick) and Alt+Down.
31
+ text -> [ name ] a text field
32
+ textarea -> a text of more lines (rows: 2). caption: the first line of the placeholder (it goes while writing). Saved on blur or Cmd/Ctrl+Enter.
33
+ select -> [ Left ⌄] a menu of options, optional icon, look: "plain" (no background)
34
+ combo -> [16 | ⌄] a number field and a menu of preset values
35
+ segmented -> [≡|≡|≡] icon or text buttons. With a value: one is selected. Without: action buttons.
36
+ iconButton -> [◎] an action, or a toggle (toggle: 1, value true/false)
37
+ constraints-> Horizontal and vertical selects and the constraints diagram. value: { horizontal, vertical }
38
+ alignGrid -> a 3x3 grid of the places of the content (the align of a group). value: "left top", "center"...
39
+ color -> [■ #3871E0 | 100%] a swatch, the color text and its opacity. A click on the swatch opens the
40
+ color picker (at the left of the panel): saturation / brightness, hue, opacity, the eyedropper (the browser's, or pickColor of the page)
41
+ (Chrome), the color text, and the color groups (palettes) under them.
42
+ palettes (a param of the panel): [{ key, name, colors, canAdd, emptyText }] or function (panel) -> that.
43
+ colors: ["#FFFFFF", { value: "var(--color-primary)", color: "#3871E0", hint: "Primary" }, ...]
44
+ canAdd: 1 -> an editable group: a + button adds the current color: change { kind: "addColor", key: palette key, value };
45
+ its colors are put in order by dragging: { kind: "orderColors", key, value: [the values in the new order] }.
46
+ A right click on a color: "Copy to ›" an editable group (they open at its side; addColor), "Delete" from an editable group
47
+ ({ kind: "removeColor", key, value }) or from Recent. A color with fixed: 1 is not moved (it can be deleted).
48
+ presets (of the item, old): shown as the first palette, "Presets".
49
+ Also: the color before / now (a click on "before" goes back), HEX / RGB / HSL text, and the
50
+ recent colors (recentColorsKey: kept in basic.storage).
51
+ The ticks before "Recent" and the group name: their colors are shown under every color field of
52
+ the panel (Recent | the selected group, two rows, "+N" shows the others); a click on one gives it to
53
+ the field, a right click opens the same menu (Copy to, Delete; a ContextMenu with a submenu when
54
+ comp/context-menu.js is loaded). Kept with recentColorsKey.
55
+ - Items of a row: put them in an array. span: 1 (one column), 2 (two columns), "full", or a width in px (a
56
+ number over 2: Ex: a switch of 100 and a field of 108 fill a row with the gap). An iconButton takes the
57
+ small last column. label: the caption above the item.
58
+ - Listen to every change from outside: onChange(panel, change) or panel.listen(fn): fn(panel, change) (returns a remover).
59
+ change = { kind: "value" | "action" | "tab" | "addColor" | "removeColor" | "orderColors", key, value, oldValue, item, sectionKey }
60
+ The panel keeps the values: getValues(), getValue(key), getData() (the JSON with the current values).
61
+ - openColorPickerFor(request): the same color picker (its groups, its recent colors) for a color that is not an item of
62
+ the panel. Ex: a parameter of a component, a cell of a table. The title of the picker moves it (a double click on it: back).
63
+ - buildColorStrip(request): the colors under a color field (the ticks of the picker) for such a color.
64
+ - setValue(key, value, silent) changes an item from outside (Ex: another object was selected).
65
+ - It is always created on the page (whatever container is open) and opened at the right side.
66
+ open() / close() / toggle() slide it. (Not show / hide: those are basic.js methods.)
67
+ - The menus (select, combo) are created on the page and removed with the panel.
68
+
69
+ USAGE:
70
+ const panel = PropertyPanel({
71
+ data: {
72
+ tabs: [{ key: "properties", text: "Properties" }, { key: "events", text: "Events" }],
73
+ activeTab: "properties",
74
+ title: "Label",
75
+ sections: [
76
+ { key: "position", title: "Position", items: [
77
+ [{ key: "x", type: "number", label: "Position", prefix: "X", value: 396 },
78
+ { key: "y", type: "number", prefix: "Y", value: 668 }],
79
+ { key: "rotation", type: "number", label: "Rotation", icon: "angle", value: 0, unit: "°" },
80
+ ] },
81
+ ],
82
+ },
83
+ onChange: function (self, change) { println(change.key + " = " + change.value); },
84
+ });
85
+ panel.setValue("x", 400, 1); // silent
86
+ panel.getValues(); // { x: 400, y: 668, rotation: 0 }
87
+
88
+ Started Date: September 2026
89
+ Webpage: https://bug7a.github.io/js-components/
90
+
91
+ Copyright 2020-2026 Bugra Ozden <bugra.ozden@gmail.com> (https://bug7a.github.io/)
92
+ Licensed under the Apache License, Version 2.0
93
+ SPDX-License-Identifier: Apache-2.0
94
+
95
+ */
96
+
97
+ "use strict";
98
+
99
+ // Default values:
100
+ const PropertyPanelDefaults = {
101
+ key: "0",
102
+ width: 240,
103
+ data: {}, // tabs, activeTab, headerTitle, headerItem, title, titleActions, sections, footer, empty (See the USAGE above)
104
+ opened: 1, // 1: Open at create time.
105
+ onChange: function (self, change) { }, // Every change: { kind, key, value, oldValue, item, sectionKey }
106
+ palettes: null, // The color groups of the color picker: [{ key, name, colors, canAdd, emptyText }] or function (panel) -> that
107
+ recentColorsKey: "", // The recent colors of the color picker are kept in basic.storage with this key. "": only until the page closes.
108
+ pickColor: null, // function (panel, done): the eyedropper where the browser has none (VS Code, Safari, Firefox): the page
109
+ // lets the user pick a color itself and calls done("#RRGGBB") (done("") : nothing was picked)
110
+ style: {
111
+ panel: {
112
+ color: "#1F1F1E", // The warm dark of the kit (its dark packages)
113
+ dividerColor: "#30302E",
114
+ markWidth: 3, // A section with mark: 1: a line in the accent color at its left
115
+ markOpacity: 0.65, // WHY: mixed with the panel, it stays calm
116
+ headerHeight: 48,
117
+ paddingLeft: 16,
118
+ paddingRight: 8,
119
+ motion: "0.25s",
120
+ },
121
+ grid: {
122
+ columnWidth: 88, // span: 1 (span: 2 = two columns + gap)
123
+ iconColumnWidth: 24,
124
+ gap: 8,
125
+ rowGap: 8,
126
+ itemHeight: 24,
127
+ },
128
+ text: {
129
+ color: "#EDEDEB",
130
+ softColor: "#9A9A97", // Captions, inactive tabs, prefixes
131
+ disabledColor: "#62625F",
132
+ fontSize: 12,
133
+ captionSize: 11,
134
+ titleSize: 13,
135
+ sectionTitleSize: 11,
136
+ },
137
+ sectionTitle: { // The title of a section (not the title of the panel)
138
+ textColor: "#C9C9C6",
139
+ uppercase: 1, // 0: as it is written
140
+ letterSpacing: 0.6, // px
141
+ },
142
+ tab: {
143
+ look: "underline", // "underline": a line in the accent under the chosen tab; "pill": a field behind it
144
+ },
145
+ field: {
146
+ color: "#292928",
147
+ borderColor: "#373735", // The line of a field at rest ("": none)
148
+ hoverBorderColor: "#575755",
149
+ focusBorderColor: "#65A293",
150
+ round: 7,
151
+ },
152
+ segmented: {
153
+ selectedColor: "#2E3D39", // A tint of the accent
154
+ selectedBorderColor: "#4F7D71",
155
+ hoverColor: "#333331",
156
+ },
157
+ button: {
158
+ hoverColor: "#2E2E2D",
159
+ activeColor: "#2E3D39", // toggle on: a tint of the accent
160
+ activeIconColor: "#8CC7B8",
161
+ iconColor: "#D6D6D3",
162
+ },
163
+ accent: {
164
+ color: "#65A293", // The accent of the kit: constraints lines, the chosen place, the focus
165
+ },
166
+ menu: {
167
+ color: "#232322",
168
+ borderColor: "#383836",
169
+ hoverColor: "#333331", // The row under the mouse is lighter (the text keeps its color)
170
+ textColor: "#EDEDEB",
171
+ round: 10,
172
+ rowHeight: 26,
173
+ maxHeight: 320,
174
+ shadow: "0 8px 24px rgba(0, 0, 0, 0.5)",
175
+ },
176
+ constraints: {
177
+ frameColor: "#4A4A48", // The inner frame of the constraints picture
178
+ },
179
+ alignGrid: {
180
+ cellColor: "#62625F", // The empty square of a place
181
+ hoverColor: "#9A9A97",
182
+ selectedColor: "#65A293", // The filled square of the chosen place (the accent)
183
+ },
184
+ textarea: {
185
+ lineHeight: 17,
186
+ fontFamily: "opensans, sans-serif",
187
+ },
188
+ colorPicker: {
189
+ width: 240,
190
+ padding: 12,
191
+ areaHeight: 150, // Saturation / brightness area
192
+ handleSize: 12,
193
+ sliderHeight: 12,
194
+ swatchSize: 18,
195
+ swatchGap: 5, // WHY 5: with the room of the rings (swatchRoom) 9 colors still fit one row
196
+ swatchRoom: 4, // px around the colors: the selected ring (3) and the hover growth are not cut by the scroll
197
+ swatchesMaxHeight: 126, // More colors scroll
198
+ quickSwatchSize: 14, // The colors under a color field (the ticks of the picker)
199
+ quickSwatchGap: 5,
200
+ },
201
+ empty: { // data.empty: the page in the middle (Ex: nothing is selected)
202
+ iconSize: 26,
203
+ iconColor: "#9A9A97",
204
+ iconBoxColor: "#292928",
205
+ iconBoxRound: 16,
206
+ },
207
+ swatch: {
208
+ size: 14,
209
+ borderColor: "rgba(255, 255, 255, 0.25)",
210
+ emptyColor: "#575755", // The line of an empty (transparent) color
211
+ },
212
+ scrollBar: { // basic/scroll-bar.js (ScrollBar) parameters of the panel
213
+ bar_color: "#FFFFFF",
214
+ bar_mouseOverColor: "#FFFFFF",
215
+ bar_opacity: 0.25,
216
+ bar_mouseOverOpacity: 0.5,
217
+ neverHide: 0,
218
+ showDots: 0,
219
+ },
220
+ }
221
+ };
222
+
223
+ const PropertyPanel = function (params = {}) {
224
+
225
+ // Merge params:
226
+ mergeIntoIfMissing(params, PropertyPanelDefaults);
227
+
228
+ // Edit params, if needed:
229
+ const _ps = params.style.panel;
230
+ params.left = "calc(100% - " + params.width + "px)";
231
+ params.top = 0;
232
+ params.height = "100%";
233
+ params.color = _ps.color;
234
+ const startData = params.data;
235
+ params.data = {}; // WHY: The working copy is made in setData().
236
+
237
+ // WHY: A side panel covers the page. Wherever it is called from, it is created on the page.
238
+ // NOTE: The container is put back by hand after endObject(), at the end of this function. (Like SidePanel)
239
+ const previousContainer = getDefaultContainerBox();
240
+ setDefaultContainerBox(page);
241
+
242
+ // BOX: Component container
243
+ let box = startObject(params);
244
+
245
+ // *** PRIVATE VARIABLES:
246
+ const _s = box.style;
247
+ const _t = _s.text;
248
+ const _g = _s.grid;
249
+ const panelWidth = Number(box.width) || PropertyPanelDefaults.width;
250
+ let controllers = {}; // key -> { item, sectionKey, field, cell, setValue(), setEnabled() }
251
+ let listeners = [];
252
+ let tabLabels = {};
253
+ let titleLabel = null;
254
+ let menu = null; // { obj, opener }
255
+ const MENU_MIN_WIDTH = 140;
256
+ const MENU_Z_INDEX = 2147482000; // WHY: Over everything of the page (the panel, modals).
257
+ const MENU_OFFSET = 4; // Space between the field and its menu.
258
+ const SCREEN_MARGIN = 8; // The menu stays this far from the window edges.
259
+ const SHIFT_STEP_FACTOR = 10; // Shift + arrow / scrub: 10 steps.
260
+ const PREFIX_CLICK_DISTANCE = 3; // px: a press on a prefix that moves less is a click (prefixClick), not a scrub.
261
+
262
+ // *** PUBLIC VARIABLES:
263
+ // NOTE: Default values are also public variables. (box.data: the JSON with the current values)
264
+
265
+ // *** PRIVATE FUNCTIONS:
266
+
267
+ // SVG of an icon name (PropertyPanel.icons) or a raw "<svg" string.
268
+ const getIcon = function (name, size = 16) {
269
+ if (!name) return "";
270
+ if (String(name).trim().indexOf("<svg") === 0) return name;
271
+ const path = PropertyPanel.icons[name];
272
+ if (!path) return basic.escapeHtml(name); // Not an icon: shown as text (Ex: "X")
273
+ return '<svg xmlns="http://www.w3.org/2000/svg" width="' + size + '" height="' + size + '" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round" style="display:block"><path d="' + path + '"/></svg>';
274
+ };
275
+
276
+ // span: 1, 2, "full", or a width in px (a number over 2: Ex: 100 + 108 + the gap = a full row)
277
+ const SPAN_PX_FROM = 3;
278
+ const getSpanWidth = function (span) {
279
+ if (span === "full") return panelWidth - _ps.paddingLeft - _ps.paddingRight;
280
+ if (typeof span === "number" && span >= SPAN_PX_FROM) return span;
281
+ if (span == 2) return _g.columnWidth * 2 + _g.gap;
282
+ return _g.columnWidth;
283
+ };
284
+
285
+ // Color of a text or an icon: its own color, or the disabled color.
286
+ const ink = function (enabled, color) {
287
+ return (enabled) ? color : _t.disabledColor;
288
+ };
289
+
290
+ // A one line label. html: an icon or a short text. props.plainText: a user text (never read as HTML).
291
+ // props.flex: takes the free space of its row and ends with "...". It never takes the pointer, its field does.
292
+ const textLabel = function (html, props = {}) {
293
+ const lbl = Label({
294
+ text: html,
295
+ fontSize: props.fontSize || _t.fontSize,
296
+ textColor: props.textColor || _t.color,
297
+ });
298
+ lbl.clickable = 0;
299
+ lbl.shrink = 0;
300
+ if (props.bold) lbl.bold = 1;
301
+ if (props.height !== undefined) lbl.height = props.height;
302
+ if (props.flex) {
303
+ lbl.grow = 1;
304
+ lbl.shrink = 1;
305
+ lbl.ellipsis = 1;
306
+ lbl.lineHeight = props.height || _g.itemHeight;
307
+ lbl.css = { flexBasis: "0px", minWidth: "0px" };
308
+ } else {
309
+ lbl.css = { display: "flex", alignItems: "center", whiteSpace: "nowrap" };
310
+ if (props.width !== undefined) {
311
+ lbl.width = props.width;
312
+ lbl.css.justifyContent = "center";
313
+ }
314
+ }
315
+ if (props.plainText !== undefined) lbl.plainText = props.plainText;
316
+ return lbl;
317
+ };
318
+
319
+ // Inner border that does not change the size.
320
+ const setBorder = function (obj, color) {
321
+ obj.boxShadow = (color) ? "inset 0 0 0 1px " + color : "none";
322
+ };
323
+
324
+ // fn(1) on mouseenter, fn(0) on mouseleave.
325
+ const onHover = function (obj, fn) {
326
+ obj.on("mouseenter", function () { fn(1); });
327
+ obj.on("mouseleave", function () { fn(0); });
328
+ };
329
+
330
+ // Enter and Space (and extraKeys) run fn, like a click.
331
+ const onActivateKey = function (obj, fn, extraKeys = []) {
332
+ obj.on("keydown", function (self, event) {
333
+ const isActivateKey = (event.key === "Enter" || event.key === " " || extraKeys.indexOf(event.key) > -1);
334
+ if (!isActivateKey) return;
335
+ event.preventDefault();
336
+ fn();
337
+ });
338
+ };
339
+
340
+ // Border of a field: focus, hover (when enabled) or its line at rest.
341
+ const paintField = function (field, state) {
342
+ if (state.isFocus) setBorder(field, _s.field.focusBorderColor);
343
+ else if (state.isHover && state.enabled) setBorder(field, _s.field.hoverBorderColor);
344
+ else setBorder(field, _s.field.borderColor || "");
345
+ };
346
+
347
+ const precisionOf = function (item) {
348
+ const hasPrecision = (item.precision !== undefined && item.precision !== "auto");
349
+ if (hasPrecision) return Math.max(0, Number(item.precision) || 0);
350
+ const text = String(item.step || 1);
351
+ return (text.indexOf(".") > -1) ? text.split(".")[1].length : 0;
352
+ };
353
+
354
+ const normalizeOptions = function (options) {
355
+ return (options || []).map(function (option) {
356
+ const isObject = (option !== null && typeof option === "object");
357
+ if (!isObject) return { value: option, text: String(option) };
358
+ return {
359
+ value: option.value,
360
+ text: (option.text !== undefined) ? option.text : String(option.value),
361
+ icon: option.icon,
362
+ hint: option.hint,
363
+ };
364
+ });
365
+ };
366
+
367
+ const findOption = function (options, value) {
368
+ for (let i = 0; i < options.length; i++) {
369
+ if (options[i].value === value) return options[i];
370
+ }
371
+ return null;
372
+ };
373
+
374
+ // *** CHANGES:
375
+
376
+ // Sends a change to the item, the onChange of the panel and the listeners.
377
+ const dispatch = function (change) {
378
+ if (change.item && typeof change.item.onChange === "function") change.item.onChange(box, change);
379
+ box.onChange(box, change);
380
+ listeners.slice().forEach(function (fn) { fn(box, change); });
381
+ };
382
+
383
+ // Some item types fill the missing parts of a value. (Ex: constraints)
384
+ const normalizeValue = function (item, value) {
385
+ const builder = ITEM_TYPES[item.type];
386
+ return (builder && builder.normalize) ? builder.normalize(value) : value;
387
+ };
388
+
389
+ // Keeps a new value of an item and sends the change (not when silent). Returns 1 when the value changed.
390
+ const changeValue = function (ctrl, value, silent = 0) {
391
+ value = normalizeValue(ctrl.item, value);
392
+ const oldValue = ctrl.item.value;
393
+ if (PropertyPanel.isSameValue(oldValue, value)) return 0;
394
+ ctrl.item.value = value;
395
+ if (silent) return 1;
396
+ dispatch({
397
+ kind: "value",
398
+ key: ctrl.item.key,
399
+ value: PropertyPanel.copyValue(value),
400
+ oldValue: oldValue,
401
+ item: ctrl.item,
402
+ sectionKey: ctrl.sectionKey,
403
+ });
404
+ return 1;
405
+ };
406
+
407
+ // A button without a value was clicked.
408
+ const sendAction = function (ctrl, value) {
409
+ dispatch({ kind: "action", key: ctrl.item.key, value: value, oldValue: undefined, item: ctrl.item, sectionKey: ctrl.sectionKey });
410
+ };
411
+
412
+ // The button at the end of a field (item.button). field: where the page opens what the button opens.
413
+ const sendFieldButton = function (ctrl) {
414
+ dispatch({ kind: "action", key: ctrl.item.key, value: "button", oldValue: undefined, item: ctrl.item, sectionKey: ctrl.sectionKey, field: ctrl.field });
415
+ };
416
+
417
+ // *** MENU (select, combo):
418
+
419
+ const closeMenu = function () {
420
+ if (!menu) return;
421
+ const closed = menu;
422
+ menu = null;
423
+ closed.obj.remove();
424
+ if (closed.onClose) closed.onClose();
425
+ };
426
+
427
+ // Under the field; above it when there is no space below.
428
+ const placeMenu = function (obj, rect, width) {
429
+ const height = obj.elem.offsetHeight;
430
+ let top = rect.bottom + MENU_OFFSET;
431
+ if (top + height > window.innerHeight - SCREEN_MARGIN) top = Math.max(SCREEN_MARGIN, rect.top - height - MENU_OFFSET);
432
+ obj.left = Math.max(SCREEN_MARGIN, Math.min(rect.left, window.innerWidth - width - SCREEN_MARGIN));
433
+ obj.top = top;
434
+ };
435
+
436
+ // anchor: the menu is placed under it. opener: the object that opens it; a click on it again closes the menu.
437
+ const openMenu = function (anchor, opener, options, currentValue, onPick) {
438
+ const isOpenByThisOpener = (menu && menu.opener === opener);
439
+ closeMenu();
440
+ if (isOpenByThisOpener) return;
441
+ if (!options.length) return;
442
+ const rect = anchor.elem.getBoundingClientRect();
443
+ const width = Math.max(rect.width, MENU_MIN_WIDTH);
444
+ const ms = _s.menu;
445
+
446
+ createIn(page, function () {
447
+
448
+ // GROUP: Menu
449
+ const obj = VGroup({ left: 0, top: 0, width: width, height: "auto", align: "left top", gap: 0, color: ms.color, round: ms.round });
450
+ obj.boxShadow = "0 0 0 1px " + ms.borderColor + ", " + ms.shadow;
451
+ obj.zIndex = MENU_Z_INDEX;
452
+ obj.css = {
453
+ padding: "6px 0px",
454
+ boxSizing: "border-box",
455
+ maxHeight: ms.maxHeight + "px",
456
+ alignItems: "stretch",
457
+ };
458
+ obj.scrollY = 1; // (also clickable)
459
+ obj.role = "listbox";
460
+
461
+ options.forEach(function (option) {
462
+
463
+ const isSelected = PropertyPanel.isSameValue(option.value, currentValue);
464
+
465
+ // GROUP: Menu row
466
+ const row = HGroup({ width: "100%", height: ms.rowHeight, align: "left center", gap: 0, color: "transparent" });
467
+ row.shrink = 0;
468
+ row.cursor = "pointer";
469
+ row.role = "option";
470
+ row.aria = { selected: (isSelected) ? "true" : "false" };
471
+ row.clickable = 1;
472
+
473
+ textLabel((isSelected) ? getIcon("check", 14) : "", { width: 28, height: ms.rowHeight, textColor: ms.textColor });
474
+ if (option.icon) textLabel(getIcon(option.icon, 16), { width: 22, height: ms.rowHeight, textColor: ms.textColor });
475
+ textLabel("", { flex: 1, height: ms.rowHeight, textColor: ms.textColor, plainText: option.text });
476
+
477
+ endGroup();
478
+
479
+ onHover(row, function (isHover) { row.color = (isHover) ? ms.hoverColor : "transparent"; });
480
+ row.on("click", function () {
481
+ closeMenu();
482
+ onPick(option.value);
483
+ });
484
+
485
+ });
486
+
487
+ endGroup();
488
+
489
+ placeMenu(obj, rect, width);
490
+
491
+ menu = { obj: obj, opener: opener };
492
+
493
+ });
494
+ };
495
+
496
+ // WHY: A pointerdown on the opener is left to its click, which closes the menu (a toggle).
497
+ const onDocumentPointerDown = function (self, event) {
498
+ if (!menu) return;
499
+ if (menu.obj.elem.contains(event.target)) return;
500
+ if (menu.opener.elem.contains(event.target)) return;
501
+ closeMenu();
502
+ };
503
+
504
+ // WHY: stopImmediatePropagation: this Escape closes the menu only (a page listener after it would also
505
+ // clear its selection). The focus goes back to the opener when it was in the menu.
506
+ const onDocumentKeyDown = function (self, event) {
507
+ if (!menu || event.key !== "Escape") return;
508
+ event.stopImmediatePropagation();
509
+ const opener = menu.opener;
510
+ const hadFocus = menu.obj.elem.contains(document.activeElement);
511
+ closeMenu();
512
+ if (hadFocus && opener.elem.tabIndex >= 0) opener.elem.focus();
513
+ };
514
+
515
+ // *** SMALL OBJECTS USED BY THE ITEM TYPES:
516
+
517
+ // FIELD: A text input in a field, with an optional prefix (a text or an icon) and a button at its end (item.button).
518
+ // Used by "number" and "text". Returns { field, input, el, prefix, button, setEnabled() }. The caller adds its own
519
+ // commit code and the click of the button.
520
+ const PREFIX_WIDTH = 26;
521
+ const FIELD_BUTTON_WIDTH = 22;
522
+ const buildInputField = function (item, width, prefixValue) {
523
+
524
+ const state = { isHover: 0, isFocus: 0, enabled: item.enabled != 0 };
525
+ const paint = function () { paintField(field, state); };
526
+
527
+ // GROUP: Field
528
+ const field = HGroup({ width: width, height: _g.itemHeight, align: "left center", gap: 0, color: _s.field.color, round: _s.field.round });
529
+ field.shrink = 0;
530
+ field.css = { boxSizing: "border-box", transition: "box-shadow 0.12s" };
531
+
532
+ // LABEL: Prefix ("X" or an icon)
533
+ // item.prefixWidth: a wider prefix for a word (Ex: "Bottom"); 26: a letter or an icon
534
+ const prefix = (prefixValue) ? textLabel(getIcon(prefixValue, 16), { width: item.prefixWidth || PREFIX_WIDTH, height: _g.itemHeight, textColor: _t.softColor }) : null;
535
+ if (prefix) prefix.css.paddingLeft = "2px";
536
+
537
+ // INPUT: Value
538
+ const input = Input({ width: 10, height: _g.itemHeight, minimal: 1, fontSize: _t.fontSize, textColor: _t.color });
539
+ input.grow = 1;
540
+ input.shrink = 1;
541
+ input.css.minWidth = "0px";
542
+ const el = input.inputElement;
543
+ Object.assign(el.style, {
544
+ width: "100%",
545
+ height: "100%",
546
+ boxSizing: "border-box",
547
+ padding: (prefix) ? "0px 4px 0px 2px" : "0px 8px",
548
+ backgroundColor: "transparent",
549
+ border: "0px",
550
+ color: _t.color,
551
+ fontSize: _t.fontSize + "px",
552
+ });
553
+ el.setAttribute("spellcheck", "false");
554
+ el.setAttribute("aria-label", item.hint || item.label || item.prefix || item.key);
555
+
556
+ // LABEL: The button at the end (item.button: { icon, hint })
557
+ let button = null;
558
+ if (item.button) {
559
+ button = textLabel(getIcon(item.button.icon, 14), { width: FIELD_BUTTON_WIDTH, height: _g.itemHeight, textColor: _t.softColor });
560
+ button.clickable = 1;
561
+ button.css.borderRadius = "0px " + _s.field.round + "px " + _s.field.round + "px 0px";
562
+ button.role = "button";
563
+ button.aria = { label: item.button.hint || "" };
564
+ button.elem.title = item.button.hint || "";
565
+ }
566
+
567
+ endGroup();
568
+
569
+ onHover(field, function (isHover) {
570
+ state.isHover = isHover;
571
+ paint();
572
+ });
573
+ if (button) {
574
+ onHover(button, function (isHover) {
575
+ const isLit = (isHover && state.enabled);
576
+ button.color = (isLit) ? _s.segmented.hoverColor : "transparent";
577
+ button.textColor = (isLit) ? _t.color : ink(state.enabled, _t.softColor);
578
+ });
579
+ }
580
+ el.addEventListener("focus", function () {
581
+ state.isFocus = 1;
582
+ paint();
583
+ });
584
+ el.addEventListener("blur", function () {
585
+ state.isFocus = 0;
586
+ paint();
587
+ });
588
+
589
+ const setEnabled = function (enabled) {
590
+ state.enabled = !!enabled;
591
+ el.disabled = !state.enabled;
592
+ el.style.color = ink(state.enabled, _t.color);
593
+ if (prefix) prefix.textColor = ink(state.enabled, _t.softColor);
594
+ if (button) {
595
+ button.textColor = ink(state.enabled, _t.softColor);
596
+ button.cursor = (state.enabled) ? "pointer" : "default";
597
+ }
598
+ paint();
599
+ };
600
+
601
+ setEnabled(state.enabled);
602
+
603
+ return { field: field, input: input, el: el, prefix: prefix, button: button, state: state, setEnabled: setEnabled };
604
+
605
+ };
606
+
607
+ // FIELD: number input. Used by "number" and "combo". A new value goes to changeValue(ctrl).
608
+ const buildNumberInput = function (ctrl, width) {
609
+
610
+ const item = ctrl.item;
611
+ const precision = precisionOf(item);
612
+ const step = Math.abs(Number(item.step)) || 1;
613
+ const min = (item.min !== undefined) ? Number(item.min) : -Infinity;
614
+ const max = (item.max !== undefined) ? Number(item.max) : Infinity;
615
+ let value = item.value;
616
+ let scrub = null;
617
+
618
+ const { field, input, el, prefix, button, state, setEnabled: setFieldEnabled } = buildInputField(item, width, item.icon || item.prefix);
619
+
620
+ const format = function (v) {
621
+ if (v === null || v === undefined || v === "") return item.autoText || "";
622
+ if (typeof v === "string") return v; // A text value of parseText ("100%", "auto")
623
+ return Number(v).toFixed(precision) + (item.unit || "");
624
+ };
625
+
626
+ // The number of a value: a number, or the number of a text value from textToNumber ("100%" -> 412 px).
627
+ // null: no number (a text value without textToNumber is not scrubbed or stepped).
628
+ const numberOf = function (v) {
629
+ if (typeof v === "number") return v;
630
+ if (typeof v !== "string" || !item.textToNumber) return null;
631
+ const n = Number(item.textToNumber(v));
632
+ return (isNaN(n)) ? null : n;
633
+ };
634
+
635
+ const clamp = function (v) {
636
+ const factor = Math.pow(10, precision);
637
+ return Math.round(basic.clamp(v, min, max) * factor) / factor;
638
+ };
639
+
640
+ // Text -> value. undefined: not a number (the old value comes back).
641
+ // parseText (item): a text that is not a plain number goes to it, and its answer is the value ("100%").
642
+ const parse = function (text) {
643
+ text = String(text).trim();
644
+ if (item.autoText && (text === "" || text.toLowerCase() === String(item.autoText).toLowerCase())) return null;
645
+ // WHY commaIsList: in a field of a list ("14, 10") 12,0 is two values, not the decimal 12.0
646
+ const plainNumber = (item.commaIsList) ? /^-?\d*\.?\d+(px)?$/i : /^-?\d*[.,]?\d+(px)?$/i;
647
+ const isPlainNumber = plainNumber.test(text);
648
+ if (item.parseText && !isPlainNumber) return item.parseText(text);
649
+ const match = text.replace(",", ".").match(/-?\d*\.?\d+/);
650
+ if (!match) return undefined;
651
+ return clamp(parseFloat(match[0]));
652
+ };
653
+
654
+ const commit = function (next) {
655
+ if (next !== undefined) value = next;
656
+ input.text = format(value);
657
+ el.title = (typeof value === "string") ? value : "";
658
+ if (next !== undefined) changeValue(ctrl, value);
659
+ };
660
+
661
+ el.addEventListener("focus", function () { input.select(); });
662
+ el.addEventListener("blur", function () {
663
+ // WHY: the text shows the value rounded to the step (12.4 -> "12"); leaving it (or Escape) without a change
664
+ // saved the rounded value and sent onChange
665
+ if (input.text === format(value)) return;
666
+ commit(parse(input.text));
667
+ });
668
+ const stepFactorOf = function (event) {
669
+ return (event.shiftKey) ? SHIFT_STEP_FACTOR : 1;
670
+ };
671
+
672
+ const stepByArrow = function (event) {
673
+ const base = numberOf(parse(input.text));
674
+ const start = (base === null) ? numberOf(value) : base;
675
+ if (start === null && typeof value === "string") return; // WHY: A text value with no number: nothing to step.
676
+ const direction = (event.key === "ArrowUp") ? 1 : -1;
677
+ commit(clamp((start || 0) + direction * step * stepFactorOf(event)));
678
+ input.select();
679
+ };
680
+
681
+ el.addEventListener("keydown", function (event) {
682
+ if (event.key === "Enter") {
683
+ event.preventDefault();
684
+ el.blur();
685
+ } else if (event.key === "Escape") {
686
+ event.preventDefault();
687
+ input.text = format(value);
688
+ el.blur();
689
+ } else if (button && event.altKey && event.key === "ArrowDown") {
690
+ event.preventDefault();
691
+ el.blur(); // WHY: the text written so far is kept first, the editor opens with it.
692
+ sendFieldButton(ctrl);
693
+ } else if (event.key === "ArrowUp" || event.key === "ArrowDown") {
694
+ event.preventDefault();
695
+ stepByArrow(event);
696
+ }
697
+ });
698
+ if (button) {
699
+ button.on("click", function () {
700
+ if (state.enabled) sendFieldButton(ctrl);
701
+ });
702
+ }
703
+
704
+ // Scrub: drag the prefix left / right. 1 px = 1 step (Shift: 10 steps)
705
+ // prefixClick: a press without a drag gives that value.
706
+ const hasPrefixClick = (item.prefixClick !== undefined);
707
+ if (prefix) {
708
+ prefix.clickable = 1;
709
+ prefix.css.touchAction = "none";
710
+ prefix.on("pointerdown", function (self, event) {
711
+ if (!state.enabled || event.button !== 0) return;
712
+ event.preventDefault();
713
+ if (document.activeElement === el) el.blur();
714
+ const start = numberOf(value);
715
+ // WHY: A text value with no number: no scrub (a click still works)
716
+ const canScrub = !(start === null && typeof value === "string");
717
+ scrub = { id: event.pointerId, x: event.clientX, start: start || 0, canScrub: canScrub, isMoved: 0 };
718
+ try {
719
+ prefix.elem.setPointerCapture(event.pointerId);
720
+ } catch (e) { } // WHY: It throws when the pointer is not active any more; the scrub still works without it.
721
+ });
722
+ prefix.on("pointermove", function (self, event) {
723
+ if (!scrub || event.pointerId !== scrub.id) return;
724
+ const movedPixels = Math.round(event.clientX - scrub.x);
725
+ if (Math.abs(movedPixels) >= PREFIX_CLICK_DISTANCE) scrub.isMoved = 1;
726
+ if (!scrub.canScrub || !scrub.isMoved) return;
727
+ const next = clamp(scrub.start + movedPixels * step * stepFactorOf(event));
728
+ if (next !== value) commit(next);
729
+ });
730
+ const endScrub = function () { scrub = null; };
731
+ prefix.on("pointerup", function (self, event) {
732
+ const isClick = (scrub && !scrub.isMoved && event.pointerId === scrub.id);
733
+ endScrub();
734
+ if (!isClick || !state.enabled) return;
735
+ if (!hasPrefixClick) {
736
+ if (button) sendFieldButton(ctrl); // WHY: the prefix is the name of the value: a click opens it, a drag changes it.
737
+ return;
738
+ }
739
+ setValue(item.prefixClick);
740
+ changeValue(ctrl, item.prefixClick);
741
+ });
742
+ prefix.on("pointercancel", endScrub);
743
+ if (hasPrefixClick) {
744
+ prefix.aria = { label: item.prefixHint || "" };
745
+ prefix.elem.title = item.prefixHint || "";
746
+ onHover(prefix, function (isHover) { prefix.textColor = (isHover && state.enabled) ? _t.color : _t.softColor; });
747
+ }
748
+ }
749
+
750
+ const setValue = function (v) {
751
+ value = v;
752
+ input.text = format(v);
753
+ el.title = (typeof v === "string") ? v : ""; // WHY: A long text value ("calc(100% - 40px)") is cut in the field.
754
+ };
755
+
756
+ const setEnabled = function (enabled) {
757
+ setFieldEnabled(enabled);
758
+ if (!prefix) return;
759
+ const activeCursor = (hasPrefixClick) ? "pointer" : "ew-resize";
760
+ prefix.cursor = (state.enabled) ? activeCursor : "default";
761
+ };
762
+
763
+ setValue(value);
764
+ setEnabled(state.enabled);
765
+
766
+ return { field: field, setValue: setValue, setEnabled: setEnabled };
767
+
768
+ };
769
+
770
+ // FIELD: select (a menu of options). Used by "select" and "constraints".
771
+ // look: "field" (default) or "plain" (no background, width hugs the text)
772
+ const buildSelect = function (config, width, onPick) {
773
+
774
+ const options = normalizeOptions(config.options);
775
+ const isPlain = (config.look === "plain");
776
+ const state = { isHover: 0, isFocus: 0, enabled: config.enabled != 0 };
777
+ let value = config.value;
778
+
779
+ // GROUP: Field
780
+ const field = HGroup({
781
+ width: (isPlain) ? "auto" : width,
782
+ height: _g.itemHeight,
783
+ align: "left center",
784
+ gap: 0,
785
+ color: (isPlain) ? "transparent" : _s.field.color,
786
+ round: _s.field.round,
787
+ });
788
+ field.shrink = 0;
789
+ field.cursor = "pointer";
790
+ field.css = { boxSizing: "border-box", outline: "none", paddingLeft: (config.icon) ? "0px" : "8px" };
791
+ field.tabIndex = 0;
792
+ field.role = "button";
793
+ field.aria = { haspopup: "listbox", label: config.hint || config.label || config.key || "Select" };
794
+ field.clickable = 1;
795
+
796
+ if (config.icon) textLabel(getIcon(config.icon, 16), { width: 28, height: _g.itemHeight, textColor: _t.softColor });
797
+ const lblText = textLabel("", { flex: !isPlain, height: _g.itemHeight });
798
+ const lblArrow = textLabel(getIcon("chevronDown", 12), { width: 22, height: _g.itemHeight, textColor: _t.softColor });
799
+
800
+ endGroup();
801
+
802
+ // Plain: a hover background, no border.
803
+ const paint = function () {
804
+ if (isPlain) field.color = (state.isHover && state.enabled) ? _s.button.hoverColor : "transparent";
805
+ else paintField(field, state);
806
+ };
807
+
808
+ const open = function () {
809
+ if (!state.enabled) return;
810
+ openMenu(field, field, options, value, function (picked) {
811
+ setValue(picked);
812
+ onPick(picked);
813
+ });
814
+ };
815
+ field.on("click", open);
816
+ onActivateKey(field, open, ["ArrowDown"]);
817
+ onHover(field, function (isHover) {
818
+ state.isHover = isHover;
819
+ paint();
820
+ });
821
+ field.on("focus", function () {
822
+ state.isFocus = !isPlain;
823
+ paint();
824
+ });
825
+ field.on("blur", function () {
826
+ state.isFocus = 0;
827
+ paint();
828
+ });
829
+
830
+ // The text of the option, or the value itself when it is not an option.
831
+ const textOfValue = function (v) {
832
+ const option = findOption(options, v);
833
+ if (option) return option.text;
834
+ if (v === undefined || v === null) return "";
835
+ return String(v);
836
+ };
837
+
838
+ const setValue = function (v) {
839
+ value = v;
840
+ lblText.plainText = textOfValue(v);
841
+ };
842
+
843
+ const setEnabled = function (enabled) {
844
+ state.enabled = !!enabled;
845
+ lblText.textColor = ink(state.enabled, _t.color);
846
+ lblArrow.textColor = ink(state.enabled, _t.softColor);
847
+ field.cursor = (state.enabled) ? "pointer" : "default";
848
+ field.tabIndex = (state.enabled) ? 0 : -1;
849
+ paint();
850
+ };
851
+
852
+ setValue(value);
853
+ setEnabled(state.enabled);
854
+
855
+ return { field: field, setValue: setValue, setEnabled: setEnabled };
856
+
857
+ };
858
+
859
+ // BUTTON: A small icon button. Used by "iconButton", the title actions and the section actions.
860
+ // toggle: 1 -> value true / false (active look). Otherwise an action.
861
+ const buildIconButton = function (ctrl) {
862
+
863
+ const item = ctrl.item;
864
+ const isToggle = basic.isOn(item.toggle);
865
+ const useAccent = (item.accent !== 0);
866
+ const state = { value: !!item.value, enabled: item.enabled != 0, isHover: 0 };
867
+
868
+ // LABEL: Button
869
+ const btn = textLabel("", { width: _g.iconColumnWidth, height: _g.itemHeight, textColor: _s.button.iconColor });
870
+ btn.round = _s.field.round;
871
+ btn.clickable = 1;
872
+ btn.cursor = "pointer";
873
+ btn.css = { outline: "none", transition: "background-color 0.12s" };
874
+ btn.tabIndex = 0;
875
+ btn.role = "button";
876
+ btn.aria = { label: item.hint || item.key };
877
+ if (item.hint) btn.elem.title = item.hint;
878
+
879
+ // WHY: The icon (innerHTML) is only written when the value changes, not on every hover.
880
+ const paintIcon = function () {
881
+ btn.text = getIcon((isToggle && state.value && item.iconActive) ? item.iconActive : item.icon, 16);
882
+ if (isToggle) btn.aria = { pressed: (state.value) ? "true" : "false" };
883
+ };
884
+
885
+ const paintColors = function () {
886
+ const isActive = isToggle && state.value && useAccent;
887
+ if (isActive) btn.color = _s.button.activeColor;
888
+ else if (state.isHover && state.enabled) btn.color = _s.button.hoverColor;
889
+ else btn.color = "transparent";
890
+ btn.textColor = ink(state.enabled, (isActive) ? _s.button.activeIconColor : _s.button.iconColor);
891
+ };
892
+
893
+ const press = function () {
894
+ if (!state.enabled) return;
895
+ if (!isToggle) {
896
+ sendAction(ctrl, item.value);
897
+ return;
898
+ }
899
+ state.value = !state.value;
900
+ paintIcon();
901
+ paintColors();
902
+ changeValue(ctrl, state.value);
903
+ };
904
+
905
+ const setValue = function (v) {
906
+ state.value = !!v;
907
+ paintIcon();
908
+ paintColors();
909
+ };
910
+
911
+ const setEnabled = function (enabled) {
912
+ state.enabled = !!enabled;
913
+ btn.cursor = (state.enabled) ? "pointer" : "default";
914
+ paintColors();
915
+ };
916
+
917
+ onHover(btn, function (isHover) {
918
+ state.isHover = isHover;
919
+ paintColors();
920
+ });
921
+ btn.on("click", press);
922
+ onActivateKey(btn, press);
923
+
924
+ paintIcon();
925
+ paintColors();
926
+
927
+ return { field: btn, setValue: setValue, setEnabled: setEnabled };
928
+
929
+ };
930
+
931
+ // ALIGN GRID: 3 x 3 places of the content. The chosen one is a filled square, the others empty squares.
932
+ const ALIGN_COLUMNS = ["left", "center", "right"];
933
+ const ALIGN_ROWS = ["top", "center", "bottom"];
934
+
935
+ // "center" -> "center center", "top left" -> "left top" (basic.js takes both orders).
936
+ const normalizeAlign = function (value) {
937
+ const words = String(value || "").trim().split(/\s+/);
938
+ if (words.length === 1) words.push("center");
939
+ // WHY: "center" is in both lists: only top / bottom and left / right tell the order.
940
+ const isVerticalFirst = /^(top|bottom)$/.test(words[0]) || /^(left|right)$/.test(words[1]);
941
+ return (isVerticalFirst) ? words[1] + " " + words[0] : words[0] + " " + words[1];
942
+ };
943
+
944
+ const buildAlignGrid = function (ctrl) {
945
+
946
+ const item = ctrl.item;
947
+ const ga = _s.alignGrid;
948
+ const SIZE = _g.itemHeight * 2 + _g.rowGap; // As high as two rows
949
+ const CELL = Math.floor(SIZE / 3); // The click area of one place
950
+ const MARK = 8; // The square in it
951
+ let value = normalizeAlign(item.value);
952
+ let enabled = item.enabled != 0;
953
+ const cells = []; // { area, mark, align, isHover }
954
+
955
+ const paintCell = function (cell) {
956
+ const isSelected = (cell.align === value);
957
+ const lineColor = (cell.isHover && enabled) ? ga.hoverColor : ga.cellColor;
958
+ cell.mark.color = (isSelected) ? ink(enabled, ga.selectedColor) : "transparent";
959
+ setBorder(cell.mark, (isSelected) ? "" : lineColor);
960
+ cell.area.aria = { checked: (isSelected) ? "true" : "false" };
961
+ };
962
+ const paint = function () { cells.forEach(paintCell); };
963
+
964
+ // BOX: Grid
965
+ const grid = startBox({ width: SIZE, height: SIZE, color: _s.field.color, round: _s.field.round });
966
+ grid.shrink = 0;
967
+ grid.role = "radiogroup";
968
+ grid.aria = { label: item.hint || item.label || item.key };
969
+ const offset = Math.floor((SIZE - CELL * 3) / 2);
970
+
971
+ ALIGN_ROWS.forEach(function (vertical, row) {
972
+ ALIGN_COLUMNS.forEach(function (horizontal, column) {
973
+ const align = horizontal + " " + vertical;
974
+
975
+ // BOX: The click area of a place
976
+ const area = startBox({ left: offset + column * CELL, top: offset + row * CELL, width: CELL, height: CELL, color: "transparent" });
977
+ area.clickable = 1;
978
+ area.cursor = "pointer";
979
+ area.tabIndex = 0;
980
+ area.role = "radio";
981
+ area.aria = { label: align };
982
+ area.css = { outline: "none" };
983
+ area.elem.title = align;
984
+
985
+ // BOX: The square
986
+ const mark = Box({ width: MARK, height: MARK, color: "transparent", round: 2 });
987
+ mark.center();
988
+ mark.css = { transition: "background-color 0.12s" };
989
+
990
+ endBox();
991
+
992
+ const cell = { area: area, mark: mark, align: align, isHover: 0 };
993
+ cells.push(cell);
994
+
995
+ const press = function () {
996
+ if (!enabled) return;
997
+ value = align;
998
+ paint();
999
+ changeValue(ctrl, value);
1000
+ };
1001
+ onHover(area, function (isHover) {
1002
+ cell.isHover = isHover;
1003
+ paintCell(cell);
1004
+ });
1005
+ area.on("click", press);
1006
+ onActivateKey(area, press);
1007
+ });
1008
+ });
1009
+
1010
+ endBox();
1011
+
1012
+ paint();
1013
+
1014
+ return {
1015
+ field: grid,
1016
+ setValue: function (v) { value = normalizeAlign(v); paint(); },
1017
+ setEnabled: function (e) { enabled = !!e; paint(); },
1018
+ };
1019
+
1020
+ };
1021
+
1022
+ // *** COLOR (the color item and its picker):
1023
+ // A value is a CSS color text: "#3871E0", "rgba(56, 113, 224, 0.5)", "transparent", "var(--color-primary)".
1024
+ // The field shows it as a base (the color without its opacity) and an opacity: [■ #3871E0 | 50%].
1025
+
1026
+ const HEX_TEXT = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i;
1027
+ const WRITTEN_AS_NUMBERS = /^(#|rgb|hsl)/i;
1028
+ const ALPHA_MIX = /^color-mix\(in srgb,\s*(.+)\s+([\d.]+)%,\s*transparent\)$/i; // What Alpha() makes of a token
1029
+ const CHECKER = "repeating-conic-gradient(#BBBBBB 0% 25%, #FFFFFF 0% 50%) 0 0 / 6px 6px";
1030
+ const ALPHA_INPUT_WIDTH = 46;
1031
+ const PICKER_SPACE = 8; // Between the panel and the color picker
1032
+ let movedPickerPlace = null; // { left, top }: the picker was moved by its title: it opens there until a double click on its title
1033
+
1034
+ // A CSS color -> { r, g, b, a }, read by a canvas. null: this page can not read it (Ex: an unknown token).
1035
+ const readColor = function (color) {
1036
+ if (!readColor.context) readColor.context = document.createElement("canvas").getContext("2d");
1037
+ const context = readColor.context;
1038
+ // WHY: A wrong color leaves the old fillStyle: two different starts tell a wrong color apart.
1039
+ context.fillStyle = "#000000";
1040
+ context.fillStyle = String(color || "");
1041
+ const read = context.fillStyle;
1042
+ context.fillStyle = "#FFFFFF";
1043
+ context.fillStyle = String(color || "");
1044
+ if (read !== context.fillStyle) return null;
1045
+ if (read.charAt(0) === "#") {
1046
+ return { r: parseInt(read.slice(1, 3), 16), g: parseInt(read.slice(3, 5), 16), b: parseInt(read.slice(5, 7), 16), a: 1 };
1047
+ }
1048
+ const parts = read.match(/[\d.]+/g);
1049
+ return { r: Number(parts[0]), g: Number(parts[1]), b: Number(parts[2]), a: (parts[3] !== undefined) ? Number(parts[3]) : 1 };
1050
+ };
1051
+
1052
+ const toHex = function (rgb) {
1053
+ const digits = [rgb.r, rgb.g, rgb.b].map(function (n) {
1054
+ return ("0" + Math.round(n).toString(16)).slice(-2);
1055
+ });
1056
+ return "#" + digits.join("").toUpperCase();
1057
+ };
1058
+
1059
+ const roundAlpha = function (alpha) {
1060
+ return Math.round(basic.clamp(alpha, 0, 1) * 100) / 100;
1061
+ };
1062
+
1063
+ // A value -> { base, alpha }. "rgba(0, 0, 0, 0.5)" -> "#000000", 0.5. Alpha("var(--x)", 0.5) -> "var(--x)", 0.5
1064
+ const splitAlpha = function (value) {
1065
+ const text = String((value === undefined || value === null) ? "" : value).trim();
1066
+ if (!text) return { base: "", alpha: 1 };
1067
+ const mix = text.match(ALPHA_MIX);
1068
+ if (mix) return { base: mix[1].trim(), alpha: Number(mix[2]) / 100 };
1069
+ const rgb = readColor(text);
1070
+ if (rgb && WRITTEN_AS_NUMBERS.test(text)) return { base: toHex(rgb), alpha: rgb.a };
1071
+ return { base: text, alpha: (rgb) ? rgb.a : 1 };
1072
+ };
1073
+
1074
+ // The opposite of splitAlpha: a base and an opacity -> one value.
1075
+ const joinAlpha = function (base, alpha) {
1076
+ alpha = roundAlpha(alpha);
1077
+ if (alpha >= 1) return base;
1078
+ const rgb = readColor(base);
1079
+ if (!rgb) return Alpha(base, alpha); // A token: color-mix() keeps it a token
1080
+ return "rgba(" + rgb.r + ", " + rgb.g + ", " + rgb.b + ", " + alpha + ")";
1081
+ };
1082
+
1083
+ // A typed text -> a value. Hex digits keep the opacity of the color ("3871e0" -> "#3871E0"); any other text is used as it is.
1084
+ const colorOfText = function (typed, alpha) {
1085
+ if (!HEX_TEXT.test(typed)) return typed;
1086
+ return joinAlpha("#" + typed.replace("#", "").toUpperCase(), alpha);
1087
+ };
1088
+
1089
+ const rgbToHsv = function (rgb) {
1090
+ const r = rgb.r / 255;
1091
+ const g = rgb.g / 255;
1092
+ const b = rgb.b / 255;
1093
+ const max = Math.max(r, g, b);
1094
+ const range = max - Math.min(r, g, b);
1095
+ let hue = 0;
1096
+ if (range && max === r) hue = ((g - b) / range) % 6;
1097
+ else if (range && max === g) hue = (b - r) / range + 2;
1098
+ else if (range) hue = (r - g) / range + 4;
1099
+ return { h: (hue * 60 + 360) % 360, s: (max) ? range / max : 0, v: max };
1100
+ };
1101
+
1102
+ const hsvToRgb = function (hsv) {
1103
+ const part = function (n) {
1104
+ const k = (n + hsv.h / 60) % 6;
1105
+ return Math.round((hsv.v - hsv.v * hsv.s * Math.max(0, Math.min(k, 4 - k, 1))) * 255);
1106
+ };
1107
+ return { r: part(5), g: part(3), b: part(1) };
1108
+ };
1109
+
1110
+ // *** COLOR PALETTES: the color groups of the picker (the palettes param, and the presets of an item).
1111
+
1112
+ let paletteCache = null; // WHY: palettes may be a function (the colors of a page): read once per setData / picker.
1113
+ let lastPaletteKey = "";
1114
+ let colorFormat = "hex"; // The text of the color picker: "hex", "rgb", "hsl"
1115
+ const COLOR_FORMATS = ["hex", "rgb", "hsl"];
1116
+ const RECENT_COLOR_COUNT = 9; // One row of the picker
1117
+
1118
+ const loadRecentColors = function () {
1119
+ if (!box.recentColorsKey) return [];
1120
+ const saved = basic.storage.load(box.recentColorsKey);
1121
+ return (Array.isArray(saved)) ? saved : [];
1122
+ };
1123
+ let recentColors = loadRecentColors();
1124
+
1125
+ const saveRecentColors = function () {
1126
+ if (box.recentColorsKey) basic.storage.save(box.recentColorsKey, recentColors);
1127
+ };
1128
+
1129
+ const rememberColor = function (value) {
1130
+ if (!value) return;
1131
+ recentColors = [value].concat(recentColors.filter(function (v) { return v !== value; })).slice(0, RECENT_COLOR_COUNT);
1132
+ saveRecentColors();
1133
+ };
1134
+
1135
+ const forgetColor = function (value) {
1136
+ recentColors = recentColors.filter(function (v) { return v !== value; });
1137
+ saveRecentColors();
1138
+ };
1139
+
1140
+ // The ticks of the picker: the recent colors and the colors of the selected group under every color field.
1141
+ // (kept with the recent colors, and the selected group with them)
1142
+ const QUICK_COLORS_KEY_END = "-quick";
1143
+ const loadQuickColors = function () {
1144
+ const saved = (box.recentColorsKey) ? basic.storage.load(box.recentColorsKey + QUICK_COLORS_KEY_END) : null;
1145
+ return Object.assign({ recent: 0, group: 0, paletteKey: "" }, saved || {});
1146
+ };
1147
+ const quickColors = loadQuickColors();
1148
+ lastPaletteKey = quickColors.paletteKey;
1149
+
1150
+ const saveQuickColors = function () {
1151
+ quickColors.paletteKey = lastPaletteKey;
1152
+ if (box.recentColorsKey) basic.storage.save(box.recentColorsKey + QUICK_COLORS_KEY_END, quickColors);
1153
+ };
1154
+
1155
+ let quickStrips = []; // The colors under the color fields: { obj, draw(), paint(value) }
1156
+
1157
+ const refreshQuickStrips = function () {
1158
+ quickStrips = quickStrips.filter(function (strip) { return !strip.obj._isRemoved; });
1159
+ quickStrips.forEach(function (strip) { strip.draw(); });
1160
+ };
1161
+
1162
+ const toPreset = function (preset) {
1163
+ if (preset && typeof preset === "object") return preset;
1164
+ return { value: preset, color: preset, hint: preset };
1165
+ };
1166
+
1167
+ const readPalettes = function () {
1168
+ const source = (typeof box.palettes === "function") ? box.palettes(box) : box.palettes;
1169
+ paletteCache = (Array.isArray(source)) ? source : [];
1170
+ return paletteCache;
1171
+ };
1172
+
1173
+ // The palettes of an item: its presets (old item setting) first, then the palettes of the panel.
1174
+ const palettesOf = function (item, isFresh) {
1175
+ const shared = (isFresh || !paletteCache) ? readPalettes() : paletteCache;
1176
+ const list = shared.map(function (palette) {
1177
+ return Object.assign({}, palette, { colors: (palette.colors || []).map(toPreset) });
1178
+ });
1179
+ const presets = (Array.isArray(item.presets)) ? item.presets.filter(function (p) { return p !== "|"; }) : [];
1180
+ if (presets.length) list.unshift({ key: "__presets", name: "Presets", colors: presets.map(toPreset) });
1181
+ return list;
1182
+ };
1183
+
1184
+ // The color to paint for a base: a token (var(--color-primary)) is painted with the color of its preset.
1185
+ const paintColorOf = function (item, value) {
1186
+ const parts = splitAlpha(value);
1187
+ if (!parts.base) return "transparent";
1188
+ let color = parts.base;
1189
+ palettesOf(item).forEach(function (palette) {
1190
+ palette.colors.forEach(function (preset) {
1191
+ if (preset.value === parts.base && preset.color) color = preset.color;
1192
+ });
1193
+ });
1194
+ return joinAlpha(color, parts.alpha);
1195
+ };
1196
+
1197
+ // A square that shows a color over a checkerboard (a transparent color shows the checkerboard).
1198
+ const paintChecker = function (obj, color) {
1199
+ obj.css.background = "linear-gradient(" + color + ", " + color + "), " + CHECKER;
1200
+ };
1201
+
1202
+ const SWATCH_HOVER_SCALE = 1.1; // WHY not more: the ring and the growth must stay in the room around the colors
1203
+
1204
+ // The ring of the selected color (a gap in the color of what is behind it, then the accent), or a thin edge.
1205
+ const paintSwatchRing = function (square, isSelected, backColor) {
1206
+ square.boxShadow = (isSelected) ? "0 0 0 2px " + backColor + ", 0 0 0 3px " + _s.accent.color : "inset 0 0 0 1px " + _s.swatch.borderColor;
1207
+ };
1208
+
1209
+ // The palette of the picker for an item: the selected one, or the first.
1210
+ const currentPaletteOf = function (item) {
1211
+ const list = palettesOf(item);
1212
+ return list.find(function (palette) { return palette.key === lastPaletteKey; }) || list[0] || null;
1213
+ };
1214
+
1215
+ // BOX: A small check box. onToggle(isOn) after a click. Returns it with setOn(isOn).
1216
+ const TICK_SIZE = 14;
1217
+ const buildTick = function (isOn, label, onToggle) {
1218
+ const tick = textLabel("", { width: TICK_SIZE, height: TICK_SIZE, textColor: "#FFFFFF" });
1219
+ tick.round = 3;
1220
+ tick.clickable = 1;
1221
+ tick.cursor = "pointer";
1222
+ tick.tabIndex = 0;
1223
+ tick.role = "checkbox";
1224
+ tick.elem.title = label;
1225
+ tick.setOn = function (on) {
1226
+ isOn = on;
1227
+ tick.text = (on) ? getIcon("check", 12) : "";
1228
+ tick.color = (on) ? _s.accent.color : "transparent";
1229
+ setBorder(tick, (on) ? "" : _t.softColor);
1230
+ tick.aria = { label: label, checked: (on) ? "true" : "false" };
1231
+ };
1232
+ const toggle = function () {
1233
+ tick.setOn((isOn) ? 0 : 1);
1234
+ onToggle(isOn);
1235
+ };
1236
+ tick.on("click", toggle);
1237
+ onActivateKey(tick, toggle);
1238
+ tick.setOn(isOn);
1239
+ return tick;
1240
+ };
1241
+
1242
+ // *** CHANGES OF THE COLOR GROUPS (the menu of a color in the picker and under the fields, a drag)
1243
+
1244
+ const RECENT_PALETTE = { key: "__recent", name: "Recent", isRecent: 1 };
1245
+
1246
+ const valueOfColor = function (color) {
1247
+ return (color && typeof color === "object") ? color.value : color;
1248
+ };
1249
+
1250
+ const hasColor = function (colors, value) {
1251
+ return colors.some(function (color) { return PropertyPanel.isSameValue(valueOfColor(color), value); });
1252
+ };
1253
+
1254
+ // A color is deleted from Recent or from an editable group (canAdd). (fixed: it only stays in its place)
1255
+ const canDeleteFrom = function (palette) {
1256
+ return (palette.isRecent || palette.canAdd) ? 1 : 0;
1257
+ };
1258
+
1259
+ // The editable groups a color of a palette can be copied to (not its own, not one that has it already).
1260
+ const copyTargetsOf = function (item, palette, value) {
1261
+ return palettesOf(item).filter(function (p) { return p.canAdd && p.key !== palette.key && !hasColor(p.colors, value); });
1262
+ };
1263
+
1264
+ // The change goes to the listener (it keeps the colors of its groups). A static palette (not a function)
1265
+ // is changed here: changeColors(colors) -> the new colors (WHY it must give the same result twice: the
1266
+ // listener may have changed the same array). origin: the ctrl of the color field.
1267
+ const changePaletteColors = function (origin, palette, change, changeColors) {
1268
+ dispatch(Object.assign({ key: palette.key, oldValue: undefined, item: origin.item, sectionKey: origin.sectionKey }, change));
1269
+ readPalettes();
1270
+ if (typeof box.palettes !== "function") {
1271
+ const shared = paletteCache.find(function (p) { return p.key === palette.key; });
1272
+ if (shared) shared.colors = changeColors((shared.colors || []).slice());
1273
+ }
1274
+ refreshQuickStrips();
1275
+ };
1276
+
1277
+ const addPaletteColor = function (origin, palette, value) {
1278
+ if (!value || hasColor(palette.colors, value)) return;
1279
+ changePaletteColors(origin, palette, { kind: "addColor", value: value }, function (colors) {
1280
+ return (hasColor(colors, value)) ? colors : colors.concat([value]);
1281
+ });
1282
+ };
1283
+
1284
+ const deletePaletteColor = function (origin, palette, value) {
1285
+ if (palette.isRecent) {
1286
+ forgetColor(value);
1287
+ refreshQuickStrips();
1288
+ return;
1289
+ }
1290
+ changePaletteColors(origin, palette, { kind: "removeColor", value: value }, function (colors) {
1291
+ return colors.filter(function (color) { return !PropertyPanel.isSameValue(valueOfColor(color), value); });
1292
+ });
1293
+ };
1294
+
1295
+ // values: every color of the palette in the new order (after a drag)
1296
+ const orderPaletteColors = function (origin, palette, values) {
1297
+ changePaletteColors(origin, palette, { kind: "orderColors", value: values }, function (colors) {
1298
+ const ordered = values.map(function (value) {
1299
+ return colors.find(function (color) { return PropertyPanel.isSameValue(valueOfColor(color), value); });
1300
+ });
1301
+ return ordered.filter(function (color) { return color !== undefined; });
1302
+ });
1303
+ };
1304
+
1305
+ // GROUP: The colors under a color field: the recent colors | the colors of the selected group (the ticks of
1306
+ // the picker), two rows at most: "+N" shows the others. A click gives the color to the field: onPick(value);
1307
+ // a right click opens its menu (Copy to, Delete). Hidden when no tick is on.
1308
+ // *** THE MENU OF A COLOR (a right click, in the picker and under a field):
1309
+ // [⧉ Copy to ›] its editable groups open at its side (on hover, a click, Enter or →)
1310
+ // [🗑 Delete ]
1311
+
1312
+ const COLOR_MENU_WIDTH = 150;
1313
+ const SUBMENU_OVERLAP = 4; // The list of groups covers the edge of the menu a little
1314
+
1315
+ // GROUP: A row of the menu of a color: an icon (or none), the text, an icon at the end (or none)
1316
+ const buildColorMenuRow = function (icon, text, label, endIcon) {
1317
+ const ms = _s.menu;
1318
+ const row = HGroup({ width: "100%", height: ms.rowHeight, align: "left center", gap: 0, padding: [8, 0], color: "transparent" });
1319
+ row.shrink = 0;
1320
+ row.clickable = 1;
1321
+ row.cursor = "pointer";
1322
+ row.tabIndex = 0;
1323
+ row.role = "menuitem";
1324
+ row.aria = { label: label };
1325
+ if (icon) textLabel(getIcon(icon, 14), { width: 24, height: ms.rowHeight, textColor: ms.textColor });
1326
+ const lblText = textLabel("", { flex: 1, height: ms.rowHeight, textColor: ms.textColor, plainText: text });
1327
+ if (!icon) lblText.css.paddingLeft = "4px";
1328
+ if (endIcon) textLabel(getIcon(endIcon, 14), { width: 18, height: ms.rowHeight, textColor: _t.softColor });
1329
+ endGroup();
1330
+ // keepHover: the row stays painted (Copy to, while its list is open)
1331
+ onHover(row, function (isHover) { row.color = (isHover || row.keepHover) ? ms.hoverColor : "transparent"; });
1332
+ return row;
1333
+ };
1334
+
1335
+ // GROUP: The menu of a color, in the current container (place it after: left, top).
1336
+ // menu: { value, targets (the editable groups), canDelete, groupName, onCopy(target), onDelete(), close() }
1337
+ const buildColorMenu = function (menu) {
1338
+ const ms = _s.menu;
1339
+ const menuBox = VGroup({ width: COLOR_MENU_WIDTH, height: "auto", align: "left top", gap: 0, color: ms.color, round: ms.round });
1340
+ menuBox.css = { position: "absolute", padding: "4px 0px", boxSizing: "border-box", alignItems: "stretch" };
1341
+ menuBox.boxShadow = "0 0 0 1px " + ms.borderColor + ", " + ms.shadow;
1342
+ menuBox.clickable = 1;
1343
+ menuBox.clipContent = 0; // (the list of groups is at its side)
1344
+ menuBox.role = "menu";
1345
+ menuBox.aria = { label: menu.value };
1346
+ let subMenu = null;
1347
+ let rowCopy = null;
1348
+
1349
+ const closeSubMenu = function () {
1350
+ if (!subMenu) return;
1351
+ subMenu.remove();
1352
+ subMenu = null;
1353
+ rowCopy.keepHover = 0;
1354
+ rowCopy.color = "transparent";
1355
+ };
1356
+
1357
+ // At the right of the menu (at its left when there is no room), its first row at "Copy to"; it goes up
1358
+ // when it would leave the bottom of the window.
1359
+ const placeSubMenu = function () {
1360
+ const menuRect = menuBox.elem.getBoundingClientRect();
1361
+ const width = subMenu.elem.offsetWidth;
1362
+ const height = subMenu.elem.offsetHeight;
1363
+ const fitsRight = (menuRect.right + width - SUBMENU_OVERLAP <= window.innerWidth - SCREEN_MARGIN);
1364
+ subMenu.left = (fitsRight) ? menuRect.width - SUBMENU_OVERLAP : SUBMENU_OVERLAP - width;
1365
+ const top = rowCopy.elem.offsetTop - 4; // WHY 4: the padding of the list, so its first row is at the row
1366
+ const overflow = menuRect.top + top + height - (window.innerHeight - SCREEN_MARGIN);
1367
+ subMenu.top = top - Math.max(0, overflow);
1368
+ };
1369
+
1370
+ const openSubMenu = function (focusFirst) {
1371
+ if (!subMenu) {
1372
+ subMenu = createIn(menuBox, function () {
1373
+ // GROUP: The editable groups
1374
+ const list = VGroup({ width: COLOR_MENU_WIDTH, height: "auto", align: "left top", gap: 0, color: ms.color, round: ms.round });
1375
+ list.css = { position: "absolute", padding: "4px 0px", boxSizing: "border-box", alignItems: "stretch" };
1376
+ list.boxShadow = "0 0 0 1px " + ms.borderColor + ", " + ms.shadow;
1377
+ list.clickable = 1;
1378
+ list.role = "menu";
1379
+ list.aria = { label: "Copy to" };
1380
+ menu.targets.forEach(function (target) {
1381
+ const row = buildColorMenuRow("", target.name, "Copy " + menu.value + " to " + target.name, "");
1382
+ const copy = function () {
1383
+ menu.close();
1384
+ menu.onCopy(target);
1385
+ };
1386
+ row.on("click", copy);
1387
+ onActivateKey(row, copy);
1388
+ });
1389
+ endGroup();
1390
+ // ← or Escape: back to "Copy to" (WHY stopPropagation: not the whole menu)
1391
+ list.on("keydown", function (self, event) {
1392
+ if (event.key !== "ArrowLeft" && event.key !== "Escape") return;
1393
+ event.preventDefault();
1394
+ event.stopPropagation();
1395
+ closeSubMenu();
1396
+ rowCopy.elem.focus();
1397
+ });
1398
+ return list;
1399
+ });
1400
+ rowCopy.keepHover = 1;
1401
+ rowCopy.color = ms.hoverColor;
1402
+ rowCopy.aria = { expanded: "true" };
1403
+ placeSubMenu();
1404
+ }
1405
+ if (focusFirst) subMenu.elem.querySelector("[role=menuitem]").focus({ preventScroll: true });
1406
+ };
1407
+
1408
+ if (menu.targets.length) {
1409
+ rowCopy = buildColorMenuRow("copy", "Copy to", "Copy " + menu.value + " to a color group", "chevronRight");
1410
+ rowCopy.aria = { haspopup: "menu", expanded: "false" };
1411
+ rowCopy.on("mouseenter", function () { openSubMenu(0); });
1412
+ rowCopy.on("click", function () { openSubMenu(1); });
1413
+ onActivateKey(rowCopy, function () { openSubMenu(1); }, ["ArrowRight"]);
1414
+ }
1415
+ if (menu.targets.length && menu.canDelete) {
1416
+ // BOX: Line
1417
+ const line = Box({ width: "100%", height: 1, color: ms.borderColor });
1418
+ line.shrink = 0;
1419
+ line.css.margin = "4px 0px";
1420
+ }
1421
+ if (menu.canDelete) {
1422
+ const rowDelete = buildColorMenuRow("trash", "Delete", "Delete " + menu.value + " from " + menu.groupName, "");
1423
+ const remove = function () {
1424
+ menu.close();
1425
+ menu.onDelete();
1426
+ };
1427
+ rowDelete.on("mouseenter", closeSubMenu);
1428
+ rowDelete.on("click", remove);
1429
+ onActivateKey(rowDelete, remove);
1430
+ }
1431
+ endGroup();
1432
+ return menuBox;
1433
+ };
1434
+
1435
+ // MENU: The menu of a color under a field as a ContextMenu (comp/context-menu.js), in the colors of the panel.
1436
+ // One for the panel, made the first time (box.own: removed with the panel). Its items change at every open.
1437
+ let quickContextMenu = null;
1438
+ let onQuickMenuClick = null;
1439
+
1440
+ // ctrlOfStrip: the ctrl of the color field of the strip
1441
+ const openQuickContextMenu = function (ctrlOfStrip, square, palette, value, event) {
1442
+ const targets = copyTargetsOf(ctrlOfStrip.item, palette, value);
1443
+ const canDelete = canDeleteFrom(palette);
1444
+ if (!targets.length && !canDelete) return;
1445
+ closeMenu(); // (the picker)
1446
+ if (!quickContextMenu) {
1447
+ const ms = _s.menu;
1448
+ quickContextMenu = box.own(ContextMenu({
1449
+ styleName: "dark",
1450
+ minWidth: COLOR_MENU_WIDTH,
1451
+ style: {
1452
+ menu: { color: ms.color, borderColor: ms.borderColor, shadow: ms.shadow, round: ms.round, zIndex: MENU_Z_INDEX },
1453
+ item: { height: ms.rowHeight, fontSize: _t.fontSize, textColor: ms.textColor },
1454
+ itemHover: { color: ms.hoverColor, textColor: ms.textColor },
1455
+ },
1456
+ onClick: function (self, item) { if (onQuickMenuClick) onQuickMenuClick(item); },
1457
+ }));
1458
+ }
1459
+ const items = [];
1460
+ if (targets.length) {
1461
+ items.push({ text: "Copy to", icon: getIcon("copy", 16), items: targets.map(function (target) { return { text: target.name, key: "copy", data: target }; }) });
1462
+ }
1463
+ if (targets.length && canDelete) items.push("-");
1464
+ if (canDelete) items.push({ text: "Delete", key: "delete", icon: getIcon("trash", 16) });
1465
+ onQuickMenuClick = function (item) {
1466
+ if (item.key === "copy") addPaletteColor(ctrlOfStrip, item.data, value);
1467
+ if (item.key === "delete") deletePaletteColor(ctrlOfStrip, palette, value);
1468
+ };
1469
+ quickContextMenu.setItems(items);
1470
+ const rect = square.elem.getBoundingClientRect();
1471
+ const x = (event) ? event.clientX : rect.left;
1472
+ const y = (event) ? event.clientY : rect.bottom;
1473
+ quickContextMenu.openAt(x, y, square);
1474
+ if (!event) quickContextMenu.activateFirst(); // (the keyboard: the first item is active)
1475
+ };
1476
+
1477
+ const QUICK_ROWS = 2; // The colors under a field: more rows are behind "+N"
1478
+ const MORE_BUTTON_SLOTS = 2; // "+N" takes the place of two colors
1479
+ const buildQuickStrip = function (ctrl, width, onPick) {
1480
+ const item = ctrl.item;
1481
+ const cp = _s.colorPicker;
1482
+ const size = cp.quickSwatchSize;
1483
+ const gap = cp.quickSwatchGap;
1484
+ const room = cp.swatchRoom;
1485
+ const strip = HGroup({ width: width, height: "auto", align: "left center", gap: gap, wrap: 1, color: "transparent" });
1486
+ strip.css = { padding: room + "px", boxSizing: "border-box" };
1487
+ strip.shrink = 0;
1488
+ endGroup();
1489
+
1490
+ const slotsInRow = Math.max(1, Math.floor((width - room * 2 + gap) / (size + gap)));
1491
+ const view = { obj: strip, value: "", squares: [], parts: [], enabled: 1, isOpen: 0 };
1492
+
1493
+ // The menu of a color (a right click, or the menu key): Copy to an editable group, Delete from its group.
1494
+ // (on the page, in the menu slot of the panel: a click outside or Escape closes it)
1495
+ // With comp/context-menu.js loaded it is a ContextMenu (its submenu), else the menu of the panel.
1496
+ const openQuickMenu = function (square, palette, value, event) {
1497
+ if (!view.enabled) return;
1498
+ if (typeof ContextMenu === "function") {
1499
+ openQuickContextMenu(ctrl, square, palette, value, event);
1500
+ return;
1501
+ }
1502
+ const isOpenByThisColor = (menu && menu.opener === square);
1503
+ closeMenu();
1504
+ if (isOpenByThisColor) return;
1505
+ const targets = copyTargetsOf(item, palette, value);
1506
+ const canDelete = canDeleteFrom(palette);
1507
+ if (!targets.length && !canDelete) return;
1508
+ createIn(page, function () {
1509
+ const menuBox = buildColorMenu({
1510
+ value: value,
1511
+ targets: targets,
1512
+ canDelete: canDelete,
1513
+ groupName: palette.name,
1514
+ onCopy: function (target) { addPaletteColor(ctrl, target, value); },
1515
+ onDelete: function () { deletePaletteColor(ctrl, palette, value); },
1516
+ close: closeMenu,
1517
+ });
1518
+ menuBox.zIndex = MENU_Z_INDEX;
1519
+ placeMenu(menuBox, square.elem.getBoundingClientRect(), COLOR_MENU_WIDTH);
1520
+ menu = { obj: menuBox, opener: square };
1521
+ });
1522
+ menu.obj.elem.querySelector("[role=menuitem]").focus({ preventScroll: true });
1523
+ };
1524
+
1525
+ // BOX: A color under the field
1526
+ const buildQuickSwatch = function (preset, palette) {
1527
+ const square = Box({ width: size, height: size, round: 3, color: "transparent" });
1528
+ square.shrink = 0;
1529
+ paintChecker(square, preset.color || preset.value);
1530
+ square.clickable = 1;
1531
+ square.cursor = "pointer";
1532
+ square.role = "button";
1533
+ square.tabIndex = 0;
1534
+ square.aria = { label: preset.hint || preset.value };
1535
+ square.elem.title = preset.hint || preset.value;
1536
+ square.css.transition = "transform 0.1s";
1537
+ onHover(square, function (isHover) { square.css.transform = (isHover && view.enabled) ? "scale(" + SWATCH_HOVER_SCALE + ")" : ""; });
1538
+ const pick = function () {
1539
+ if (view.enabled) onPick(preset.value);
1540
+ };
1541
+ square.on("click", pick);
1542
+ onActivateKey(square, pick);
1543
+ square.elem.addEventListener("contextmenu", function (event) {
1544
+ event.preventDefault();
1545
+ openQuickMenu(square, palette, preset.value, event);
1546
+ });
1547
+ square.on("keydown", function (self, event) {
1548
+ const isMenuKey = (event.key === "ContextMenu" || (event.key === "F10" && event.shiftKey));
1549
+ if (!isMenuKey) return;
1550
+ event.preventDefault();
1551
+ openQuickMenu(square, palette, preset.value, null);
1552
+ });
1553
+ square.presetValue = preset.value;
1554
+ view.squares.push(square);
1555
+ return square;
1556
+ };
1557
+
1558
+ // LABEL: "+N" (the hidden colors) or "Less"
1559
+ const buildMoreButton = function (text, label) {
1560
+ const btn = textLabel("", { width: size * MORE_BUTTON_SLOTS + gap, height: size, fontSize: _t.captionSize, textColor: _t.softColor, plainText: text });
1561
+ btn.round = 3;
1562
+ btn.clickable = 1;
1563
+ btn.cursor = "pointer";
1564
+ btn.role = "button";
1565
+ btn.tabIndex = 0;
1566
+ btn.aria = { label: label };
1567
+ btn.elem.title = label;
1568
+ onHover(btn, function (isHover) { btn.textColor = (isHover) ? _t.color : _t.softColor; });
1569
+ const toggle = function () {
1570
+ view.isOpen = (view.isOpen) ? 0 : 1;
1571
+ view.draw();
1572
+ };
1573
+ btn.on("click", toggle);
1574
+ onActivateKey(btn, toggle);
1575
+ return btn;
1576
+ };
1577
+
1578
+ view.draw = function () {
1579
+ view.parts.forEach(function (part) { part.remove(); });
1580
+ view.parts = [];
1581
+ view.squares = [];
1582
+ const recent = (quickColors.recent) ? recentColors : [];
1583
+ const palette = (quickColors.group) ? currentPaletteOf(item) : null;
1584
+ const groupColors = (palette) ? palette.colors : [];
1585
+ const hasLine = (recent.length && groupColors.length) ? 1 : 0;
1586
+ strip.visible = (!view.isHidden && (recent.length || groupColors.length)) ? 1 : 0;
1587
+
1588
+ // WHY the line counts as a color: it is simpler, and only a few px are lost
1589
+ const slotCount = recent.length + hasLine + groupColors.length;
1590
+ const maxSlots = slotsInRow * QUICK_ROWS;
1591
+ const isLong = (slotCount > maxSlots);
1592
+ const isCut = (isLong && !view.isOpen);
1593
+ const freeSlots = (isCut) ? maxSlots - MORE_BUTTON_SLOTS : slotCount;
1594
+ const shownRecent = recent.slice(0, freeSlots);
1595
+ const showLine = (hasLine && freeSlots > shownRecent.length);
1596
+ const shownGroup = groupColors.slice(0, Math.max(0, freeSlots - shownRecent.length - ((showLine) ? 1 : 0)));
1597
+ const hiddenCount = recent.length + groupColors.length - shownRecent.length - shownGroup.length;
1598
+
1599
+ createIn(strip, function () {
1600
+ shownRecent.forEach(function (value) {
1601
+ view.parts.push(buildQuickSwatch({ value: value, color: paintColorOf(item, value), hint: value + " (Recent)" }, RECENT_PALETTE));
1602
+ });
1603
+ // BOX: The line between the recent colors and the colors of the group
1604
+ if (showLine) {
1605
+ const line = Box({ width: 1, height: size, color: _ps.dividerColor });
1606
+ line.shrink = 0;
1607
+ line.clickable = 0;
1608
+ view.parts.push(line);
1609
+ }
1610
+ shownGroup.forEach(function (preset) {
1611
+ const hint = (preset.hint || preset.value) + " (" + palette.name + ")";
1612
+ view.parts.push(buildQuickSwatch({ value: preset.value, color: preset.color, hint: hint }, palette));
1613
+ });
1614
+ if (isCut) view.parts.push(buildMoreButton("+" + hiddenCount, "Show " + hiddenCount + " more colors"));
1615
+ else if (isLong) view.parts.push(buildMoreButton("Less", "Show two rows of colors"));
1616
+ });
1617
+ view.paint(view.value);
1618
+ };
1619
+
1620
+ view.paint = function (value) {
1621
+ view.value = value;
1622
+ view.squares.forEach(function (square) {
1623
+ paintSwatchRing(square, PropertyPanel.isSameValue(square.presetValue, value), _ps.color);
1624
+ });
1625
+ };
1626
+
1627
+ view.setEnabled = function (enabled) {
1628
+ view.enabled = enabled;
1629
+ strip.opacity = (enabled) ? 1 : 0.5;
1630
+ };
1631
+
1632
+ // isHidden: 1 -> not shown, whatever the ticks say (Ex: only under the field in use)
1633
+ view.setHidden = function (isHidden) {
1634
+ view.isHidden = (isHidden) ? 1 : 0;
1635
+ view.draw();
1636
+ };
1637
+
1638
+ quickStrips.push(view);
1639
+ view.draw();
1640
+ return view;
1641
+ };
1642
+
1643
+ // *** COLOR INPUTS: the color text and its opacity (%). Used by the color field and by the picker.
1644
+
1645
+ // INPUT: Opacity (%), at the end of a field made by buildInputField.
1646
+ const addAlphaInput = function (field, state, hint) {
1647
+ return createIn(field, function () {
1648
+ // BOX: Line between the color and its opacity
1649
+ const line = Box({ width: 1, height: 14, color: _ps.dividerColor });
1650
+ line.shrink = 0;
1651
+ line.clickable = 0;
1652
+ const alphaInput = Input({ width: ALPHA_INPUT_WIDTH, height: _g.itemHeight, minimal: 1, fontSize: _t.fontSize, textColor: _t.color });
1653
+ alphaInput.shrink = 0;
1654
+ const alphaEl = alphaInput.inputElement;
1655
+ Object.assign(alphaEl.style, {
1656
+ width: "100%",
1657
+ height: "100%",
1658
+ boxSizing: "border-box",
1659
+ padding: "0px 8px 0px 6px",
1660
+ backgroundColor: "transparent",
1661
+ border: "0px",
1662
+ color: _t.color,
1663
+ fontSize: _t.fontSize + "px",
1664
+ });
1665
+ alphaEl.setAttribute("spellcheck", "false");
1666
+ alphaEl.setAttribute("aria-label", hint + " opacity (%)");
1667
+ alphaEl.addEventListener("focus", function () {
1668
+ state.isFocus = 1;
1669
+ paintField(field, state);
1670
+ alphaInput.select();
1671
+ });
1672
+ alphaEl.addEventListener("blur", function () {
1673
+ state.isFocus = 0;
1674
+ paintField(field, state);
1675
+ });
1676
+ return alphaInput;
1677
+ });
1678
+ };
1679
+
1680
+ const rgbToHsl = function (rgb) {
1681
+ const r = rgb.r / 255;
1682
+ const g = rgb.g / 255;
1683
+ const b = rgb.b / 255;
1684
+ const max = Math.max(r, g, b);
1685
+ const min = Math.min(r, g, b);
1686
+ const lightness = (max + min) / 2;
1687
+ const range = max - min;
1688
+ const saturation = (range) ? range / (1 - Math.abs(2 * lightness - 1)) : 0;
1689
+ return { h: Math.round(rgbToHsv(rgb).h), s: Math.round(saturation * 100), l: Math.round(lightness * 100) };
1690
+ };
1691
+
1692
+ // The text of a base in a format: "#3871E0" -> "56, 113, 224" (rgb) or "220, 74%, 55%" (hsl). A token stays as it is.
1693
+ const formatBase = function (base, format) {
1694
+ if (format === "hex" || base.charAt(0) !== "#") return base;
1695
+ const rgb = readColor(base);
1696
+ // WHY: a "#" that is not a color (a typo: "#12345", "#") threw here in the rgb and hsl formats: the picker stayed
1697
+ // half drawn and the next color could not be typed. It is shown as it is.
1698
+ if (!rgb) return base;
1699
+ if (format === "rgb") return rgb.r + ", " + rgb.g + ", " + rgb.b;
1700
+ const hsl = rgbToHsl(rgb);
1701
+ return hsl.h + ", " + hsl.s + "%, " + hsl.l + "%";
1702
+ };
1703
+
1704
+ const NUMBERS_OF_THREE = /^\s*([\d.]+)%?\s*[, ]\s*([\d.]+)%?\s*[, ]\s*([\d.]+)%?\s*$/;
1705
+
1706
+ // "56, 113, 224" (rgb) or "220, 74, 55" (hsl) -> "#3871E0". null: it is not three numbers.
1707
+ const hexOfNumbers = function (typed, format) {
1708
+ const match = typed.match(NUMBERS_OF_THREE);
1709
+ if (!match || format === "hex") return null;
1710
+ const text = (format === "rgb") ? "rgb(" + match[1] + ", " + match[2] + ", " + match[3] + ")" : "hsl(" + match[1] + ", " + match[2] + "%, " + match[3] + "%)";
1711
+ const rgb = readColor(text);
1712
+ return (rgb) ? toHex(rgb) : null;
1713
+ };
1714
+
1715
+ const showColorInputs = function (input, alphaInput, value, format = "hex") {
1716
+ const parts = splitAlpha(value);
1717
+ input.text = formatBase(parts.base, format);
1718
+ alphaInput.text = (parts.base) ? Math.round(parts.alpha * 100) + "%" : "";
1719
+ };
1720
+
1721
+ // api: { getValue(), commit(value), refresh(), getFormat() (optional, "hex" when not given) }
1722
+ // (refresh: show the current value again)
1723
+ const connectColorInputs = function (input, alphaInput, api) {
1724
+
1725
+ const el = input.inputElement;
1726
+ const alphaEl = alphaInput.inputElement;
1727
+ const formatOf = function () {
1728
+ return (api.getFormat) ? api.getFormat() : "hex";
1729
+ };
1730
+
1731
+ const commitText = function () {
1732
+ const parts = splitAlpha(api.getValue());
1733
+ const typed = String(input.text).trim();
1734
+ if (typed === formatBase(parts.base, formatOf())) return;
1735
+ const hex = hexOfNumbers(typed, formatOf());
1736
+ api.commit((hex) ? joinAlpha(hex, parts.alpha) : colorOfText(typed, parts.alpha));
1737
+ };
1738
+
1739
+ const commitAlpha = function (percent) {
1740
+ const parts = splitAlpha(api.getValue());
1741
+ if (!parts.base || isNaN(percent)) {
1742
+ api.refresh();
1743
+ return;
1744
+ }
1745
+ api.commit(joinAlpha(parts.base, basic.clamp(percent, 0, 100) / 100));
1746
+ };
1747
+
1748
+ const percentOfInput = function () {
1749
+ return parseFloat(String(alphaInput.text).replace(",", "."));
1750
+ };
1751
+
1752
+ el.addEventListener("blur", commitText);
1753
+ el.addEventListener("keydown", function (event) {
1754
+ if (event.key === "Enter") {
1755
+ event.preventDefault();
1756
+ el.blur();
1757
+ } else if (event.key === "Escape") {
1758
+ event.preventDefault();
1759
+ api.refresh();
1760
+ el.blur();
1761
+ }
1762
+ });
1763
+
1764
+ // WHY the shown text: the % field wrote the value at every blur, also with no change (and after Escape):
1765
+ // "transparent" became "rgba(0, 0, 0, 0)", "rgb(55, 56, 54)" "#373836", and basic.js Designer got a change
1766
+ // the user did not make. The number field has the same check.
1767
+ alphaEl.addEventListener("blur", function () {
1768
+ const parts = splitAlpha(api.getValue());
1769
+ const shownText = (parts.base) ? Math.round(parts.alpha * 100) + "%" : "";
1770
+ if (String(alphaInput.text).trim() === shownText) return;
1771
+ commitAlpha(percentOfInput());
1772
+ });
1773
+ alphaEl.addEventListener("keydown", function (event) {
1774
+ const isArrow = (event.key === "ArrowUp" || event.key === "ArrowDown");
1775
+ if (isArrow) {
1776
+ event.preventDefault();
1777
+ const direction = (event.key === "ArrowUp") ? 1 : -1;
1778
+ const step = (event.shiftKey) ? SHIFT_STEP_FACTOR : 1;
1779
+ commitAlpha(Math.round(Math.round(splitAlpha(api.getValue()).alpha * 100) + direction * step));
1780
+ alphaInput.select();
1781
+ } else if (event.key === "Enter") {
1782
+ event.preventDefault();
1783
+ alphaEl.blur();
1784
+ } else if (event.key === "Escape") {
1785
+ event.preventDefault();
1786
+ api.refresh();
1787
+ alphaEl.blur();
1788
+ }
1789
+ });
1790
+
1791
+ };
1792
+
1793
+ // *** COLOR PICKER: a popup at the left of the panel (it uses the menu slot: one popup at a time).
1794
+ // [ saturation / brightness area ]
1795
+ // [eyedropper] [hue ]
1796
+ // [opacity ]
1797
+ // [ #3871E0 | 100% ]
1798
+ // [ Used on this page ⌄ + ] the palette list, then its colors
1799
+
1800
+ const openColorPicker = function (ctrl, colorField) {
1801
+
1802
+ const isOpenByThisOpener = (menu && menu.opener === colorField.opener);
1803
+ closeMenu();
1804
+ if (isOpenByThisOpener) return;
1805
+
1806
+ const cp = _s.colorPicker;
1807
+ const ms = _s.menu;
1808
+ const item = ctrl.item;
1809
+ const hint = item.hint || item.label || item.key;
1810
+ const contentWidth = cp.width - cp.padding * 2;
1811
+ const hasScreenDropper = (typeof window.EyeDropper === "function");
1812
+ const hasPageDropper = (typeof box.pickColor === "function" && !colorField.noPagePick);
1813
+ const hasEyeDropper = hasScreenDropper || hasPageDropper;
1814
+ const sliderWidth = contentWidth - ((hasEyeDropper) ? _g.itemHeight + _g.gap : 0);
1815
+ let palettes = palettesOf(item, 1);
1816
+ let isPaletteListOpen = 0;
1817
+ let paletteArea = null;
1818
+ let swatchViews = [];
1819
+ let hsv = { h: 0, s: 0, v: 0 };
1820
+ let alpha = 1;
1821
+ let obj = null;
1822
+ let area = null;
1823
+ let areaHandle = null;
1824
+ let hueSlider = null;
1825
+ let alphaSlider = null;
1826
+ let hexInput = null;
1827
+ let alphaInput = null;
1828
+ let formatButton = null;
1829
+ let previewNow = null;
1830
+ let recentViews = [];
1831
+ let recentArea = null;
1832
+ const TICK_MARGIN = cp.swatchRoom; // WHY: the ticks start where the colors start
1833
+ const valueAtOpen = colorField.getValue();
1834
+
1835
+ // STATE <-> VALUE
1836
+
1837
+ const rgbOfState = function () {
1838
+ return hsvToRgb(hsv);
1839
+ };
1840
+
1841
+ const valueOfState = function () {
1842
+ return joinAlpha(toHex(rgbOfState()), alpha);
1843
+ };
1844
+
1845
+ // WHY: The hue of a gray (or black) can not be read from its color: the old hue stays.
1846
+ const readState = function () {
1847
+ const parts = splitAlpha(colorField.getValue());
1848
+ const rgb = readColor(paintColorOf(item, parts.base)) || { r: 0, g: 0, b: 0 };
1849
+ const next = rgbToHsv(rgb);
1850
+ if (next.s === 0 || next.v === 0) next.h = hsv.h;
1851
+ hsv = next;
1852
+ alpha = (parts.base) ? parts.alpha : 1;
1853
+ };
1854
+
1855
+ const commitState = function () {
1856
+ colorField.commit(valueOfState());
1857
+ paintPicker();
1858
+ };
1859
+
1860
+ const commitValue = function (value) {
1861
+ colorField.commit(value);
1862
+ readState();
1863
+ paintPicker();
1864
+ };
1865
+
1866
+ // PAINT
1867
+
1868
+ const placeThumb = function (slider, ratio) {
1869
+ slider.thumb.css.left = Math.round(ratio * (slider.width - cp.sliderHeight)) + "px";
1870
+ };
1871
+
1872
+ const paintPicker = function () {
1873
+ const rgb = rgbOfState();
1874
+ const solid = "rgb(" + rgb.r + ", " + rgb.g + ", " + rgb.b + ")";
1875
+ area.color = "hsl(" + Math.round(hsv.h) + ", 100%, 50%)";
1876
+ areaHandle.css.left = Math.round(hsv.s * contentWidth - cp.handleSize / 2) + "px";
1877
+ areaHandle.css.top = Math.round((1 - hsv.v) * cp.areaHeight - cp.handleSize / 2) + "px";
1878
+ areaHandle.color = solid;
1879
+ placeThumb(hueSlider, hsv.h / 360);
1880
+ hueSlider.thumb.color = "hsl(" + Math.round(hsv.h) + ", 100%, 50%)";
1881
+ alphaSlider.css.background = "linear-gradient(to right, rgba(" + rgb.r + ", " + rgb.g + ", " + rgb.b + ", 0), " + solid + "), " + CHECKER;
1882
+ placeThumb(alphaSlider, alpha);
1883
+ paintChecker(alphaSlider.thumb, "rgba(" + rgb.r + ", " + rgb.g + ", " + rgb.b + ", " + alpha + ")");
1884
+ hueSlider.aria = { valuenow: Math.round(hsv.h) };
1885
+ alphaSlider.aria = { valuenow: Math.round(alpha * 100) };
1886
+ area.aria = { valuetext: "Saturation " + Math.round(hsv.s * 100) + "%, brightness " + Math.round(hsv.v * 100) + "%" };
1887
+ showColorInputs(hexInput, alphaInput, colorField.getValue(), colorFormat);
1888
+ formatButton.text = colorFormat.toUpperCase();
1889
+ paintChecker(previewNow, paintColorOf(item, colorField.getValue()));
1890
+ paintSelectedSwatch();
1891
+ };
1892
+
1893
+ const paintSelectedSwatch = function () {
1894
+ const value = colorField.getValue();
1895
+ swatchViews.concat(recentViews).forEach(function (view) {
1896
+ paintSwatchRing(view.obj, PropertyPanel.isSameValue(view.value, value), ms.color);
1897
+ });
1898
+ };
1899
+
1900
+ // DRAG: pointer down on a target, then moves until it is up. fn(ratioX, ratioY)
1901
+ const dragOn = function (target, fn) {
1902
+ const moveTo = function (event) {
1903
+ const rect = target.elem.getBoundingClientRect();
1904
+ fn(basic.clamp((event.clientX - rect.left) / rect.width, 0, 1), basic.clamp((event.clientY - rect.top) / rect.height, 0, 1));
1905
+ };
1906
+ target.elem.addEventListener("pointerdown", function (event) {
1907
+ event.preventDefault();
1908
+ target.elem.focus();
1909
+ target.elem.setPointerCapture(event.pointerId);
1910
+ moveTo(event);
1911
+ const onMove = function (moveEvent) { moveTo(moveEvent); };
1912
+ const onUp = function () {
1913
+ target.elem.removeEventListener("pointermove", onMove);
1914
+ target.elem.removeEventListener("pointerup", onUp);
1915
+ target.elem.removeEventListener("pointercancel", onUp);
1916
+ };
1917
+ target.elem.addEventListener("pointermove", onMove);
1918
+ target.elem.addEventListener("pointerup", onUp);
1919
+ target.elem.addEventListener("pointercancel", onUp);
1920
+ });
1921
+ };
1922
+
1923
+ // keys: { ArrowLeft: fn(step), ... } step is 1, or 10 with Shift.
1924
+ const onArrowKeys = function (target, keys) {
1925
+ target.on("keydown", function (self, event) {
1926
+ const fn = keys[event.key];
1927
+ if (!fn) return;
1928
+ event.preventDefault();
1929
+ fn((event.shiftKey) ? SHIFT_STEP_FACTOR : 1);
1930
+ commitState();
1931
+ });
1932
+ };
1933
+
1934
+ // VIEW
1935
+
1936
+ // BOX: A slider (hue or opacity) with a round thumb. ariaMax: the range a screen reader reads.
1937
+ const buildSlider = function (label, ariaMax) {
1938
+ const slider = startBox({ width: sliderWidth, height: cp.sliderHeight, round: cp.sliderHeight / 2, color: "transparent" });
1939
+ slider.css = { position: "relative", left: "0px", top: "0px" };
1940
+ slider.clipContent = 0;
1941
+ slider.clickable = 1;
1942
+ slider.cursor = "pointer";
1943
+ slider.tabIndex = 0;
1944
+ slider.role = "slider";
1945
+ slider.aria = { label: hint + " " + label, valuemin: 0, valuemax: ariaMax };
1946
+ slider.setFocusRing(_s.accent.color);
1947
+ slider.thumb = Box({ left: 0, top: 0, width: cp.sliderHeight, height: cp.sliderHeight, round: cp.sliderHeight / 2, color: "transparent" });
1948
+ slider.thumb.boxShadow = "0 0 0 2px #FFFFFF, 0 0 0 3px rgba(0, 0, 0, 0.35)";
1949
+ slider.thumb.clickable = 0;
1950
+ endBox();
1951
+ slider.shrink = 0;
1952
+ return slider;
1953
+ };
1954
+
1955
+ const buildPaletteHeader = function (palette) {
1956
+ // GROUP: The tick (the colors under the fields), the name of the palette (opens the list of palettes) and the add button
1957
+ HGroup({ width: contentWidth, height: _g.itemHeight, align: "left center", gap: 4, color: "transparent" });
1958
+ const tick = buildTick(quickColors.group, "Show the colors of the selected group under the color fields", function (isOn) {
1959
+ quickColors.group = isOn;
1960
+ saveQuickColors();
1961
+ refreshQuickStrips();
1962
+ });
1963
+ tick.css.marginLeft = TICK_MARGIN + "px";
1964
+ const btnList = HGroup({ width: 10, height: _g.itemHeight, align: "left center", gap: 2, padding: [6, 0], round: _s.field.round, color: "transparent" });
1965
+ btnList.grow = 1;
1966
+ btnList.css = { minWidth: "0px" };
1967
+ btnList.clickable = 1;
1968
+ btnList.cursor = "pointer";
1969
+ btnList.tabIndex = 0;
1970
+ btnList.role = "button";
1971
+ btnList.aria = { label: "Color group: " + ((palette) ? palette.name : "none"), expanded: (isPaletteListOpen) ? "true" : "false" };
1972
+ btnList.elem.title = "Choose a color group";
1973
+ textLabel("", { flex: 1, height: _g.itemHeight, bold: 1, plainText: (palette) ? palette.name : "No colors" });
1974
+ textLabel(getIcon((isPaletteListOpen) ? "chevronUp" : "chevronDown", 14), { width: 16, height: _g.itemHeight, textColor: _t.softColor });
1975
+ endGroup();
1976
+ onHover(btnList, function (isHover) { btnList.color = (isHover) ? _s.button.hoverColor : "transparent"; });
1977
+ const togglePaletteList = function () {
1978
+ isPaletteListOpen = (isPaletteListOpen) ? 0 : 1;
1979
+ drawPaletteArea();
1980
+ };
1981
+ btnList.on("click", togglePaletteList);
1982
+ onActivateKey(btnList, togglePaletteList);
1983
+
1984
+ if (palette && palette.canAdd && !isPaletteListOpen) {
1985
+ const btnAdd = textLabel(getIcon("plus", 14), { width: _g.itemHeight, height: _g.itemHeight, textColor: _s.button.iconColor });
1986
+ btnAdd.round = _s.field.round;
1987
+ btnAdd.clickable = 1;
1988
+ btnAdd.cursor = "pointer";
1989
+ btnAdd.tabIndex = 0;
1990
+ btnAdd.role = "button";
1991
+ btnAdd.aria = { label: "Add this color to " + palette.name };
1992
+ btnAdd.elem.title = "Add this color to " + palette.name;
1993
+ onHover(btnAdd, function (isHover) { btnAdd.color = (isHover) ? _s.button.hoverColor : "transparent"; });
1994
+ btnAdd.on("click", function () { addColorTo(palette, colorField.getValue()); });
1995
+ onActivateKey(btnAdd, function () { addColorTo(palette, colorField.getValue()); });
1996
+ }
1997
+ endGroup();
1998
+ };
1999
+
2000
+ const buildPaletteList = function (current) {
2001
+ palettes.forEach(function (palette) {
2002
+ const isSelected = (palette === current);
2003
+ // GROUP: A palette in the list
2004
+ const row = HGroup({ width: contentWidth, height: ms.rowHeight, align: "left center", gap: 0, round: _s.field.round, color: "transparent" });
2005
+ row.shrink = 0;
2006
+ row.clickable = 1;
2007
+ row.cursor = "pointer";
2008
+ row.tabIndex = 0;
2009
+ row.role = "option";
2010
+ row.aria = { selected: (isSelected) ? "true" : "false" };
2011
+ textLabel((isSelected) ? getIcon("check", 14) : "", { width: 24, height: ms.rowHeight });
2012
+ textLabel("", { flex: 1, height: ms.rowHeight, plainText: palette.name });
2013
+ textLabel("", { height: ms.rowHeight, textColor: _t.softColor, plainText: String(palette.colors.length) });
2014
+ endGroup();
2015
+ row.css.paddingRight = "6px";
2016
+ const choose = function () {
2017
+ lastPaletteKey = palette.key;
2018
+ isPaletteListOpen = 0;
2019
+ saveQuickColors();
2020
+ drawPaletteArea();
2021
+ if (quickColors.group) refreshQuickStrips(); // WHY: the tick goes with the selected group
2022
+ };
2023
+ onHover(row, function (isHover) { row.color = (isHover) ? _s.button.hoverColor : "transparent"; });
2024
+ row.on("click", choose);
2025
+ onActivateKey(row, choose);
2026
+ });
2027
+ };
2028
+
2029
+ // BOX: A color of a palette. A click gives its value; a right click opens its menu (Copy to, Delete);
2030
+ // in an editable group (canAdd) it is dragged to another place. Returns { obj, value, fixed } (for the selected ring).
2031
+ // palette: its group (RECENT_PALETTE for the recent colors). grid: the group of the colors (to drag in it).
2032
+ const buildSwatch = function (preset, palette, grid) {
2033
+ const square = Box({ width: cp.swatchSize, height: cp.swatchSize, round: 4, color: "transparent" });
2034
+ square.shrink = 0;
2035
+ paintChecker(square, preset.color || preset.value);
2036
+ square.clickable = 1;
2037
+ square.cursor = "pointer";
2038
+ square.role = "button";
2039
+ square.tabIndex = 0;
2040
+ square.aria = { label: preset.hint || preset.value };
2041
+ square.elem.title = preset.hint || preset.value;
2042
+ square.css.transition = "transform 0.1s";
2043
+ onHover(square, function (isHover) { square.css.transform = (isHover) ? "scale(" + SWATCH_HOVER_SCALE + ")" : ""; });
2044
+ const view = { obj: square, value: preset.value, fixed: preset.fixed };
2045
+ square.on("click", function () {
2046
+ if (square.wasDragged) return; // WHY: the end of a drag is not a click
2047
+ commitValue(preset.value);
2048
+ });
2049
+ onActivateKey(square, function () { commitValue(preset.value); });
2050
+ square.elem.addEventListener("contextmenu", function (event) {
2051
+ event.preventDefault();
2052
+ openColorMenu(view, palette, event);
2053
+ });
2054
+ square.on("keydown", function (self, event) {
2055
+ const isMenuKey = (event.key === "ContextMenu" || (event.key === "F10" && event.shiftKey));
2056
+ if (!isMenuKey) return;
2057
+ event.preventDefault();
2058
+ openColorMenu(view, palette, null);
2059
+ });
2060
+ const canMove = (grid && palette.canAdd && !preset.fixed);
2061
+ if (canMove) dragToOrder(view, palette, grid);
2062
+ return view;
2063
+ };
2064
+
2065
+ // *** THE MENU OF A COLOR (a right click): in the picker, so a click in it does not close the picker.
2066
+
2067
+ const COLOR_MENU_MARGIN = 4; // It stays this far from the edges of the picker
2068
+ let colorMenu = null;
2069
+
2070
+ const closeColorMenu = function () {
2071
+ if (!colorMenu) return;
2072
+ colorMenu.remove();
2073
+ colorMenu = null;
2074
+ };
2075
+
2076
+ // event: the right click (the menu at the mouse), or null (at the color: the keyboard)
2077
+ const openColorMenu = function (view, palette, event) {
2078
+ closeColorMenu();
2079
+ const targets = copyTargetsOf(item, palette, view.value);
2080
+ const canDelete = canDeleteFrom(palette);
2081
+ if (!targets.length && !canDelete) return;
2082
+
2083
+ colorMenu = createIn(obj, function () {
2084
+ const menuBox = buildColorMenu({
2085
+ value: view.value,
2086
+ targets: targets,
2087
+ canDelete: canDelete,
2088
+ groupName: palette.name,
2089
+ onCopy: function (target) { addColorTo(target, view.value); },
2090
+ onDelete: function () { deleteColor(view, palette); },
2091
+ close: closeColorMenu,
2092
+ });
2093
+ menuBox.zIndex = 1;
2094
+ return menuBox;
2095
+ });
2096
+
2097
+ // Escape closes only this menu (not the picker) and the focus goes back to the color.
2098
+ colorMenu.on("keydown", function (self, event) {
2099
+ if (event.key !== "Escape") return;
2100
+ event.stopPropagation();
2101
+ closeColorMenu();
2102
+ view.obj.elem.focus();
2103
+ });
2104
+
2105
+ const pickerRect = obj.elem.getBoundingClientRect();
2106
+ const squareRect = view.obj.elem.getBoundingClientRect();
2107
+ const x = (event) ? event.clientX : squareRect.left;
2108
+ const y = (event) ? event.clientY : squareRect.bottom;
2109
+ const maxLeft = pickerRect.width - COLOR_MENU_WIDTH - COLOR_MENU_MARGIN;
2110
+ const maxTop = pickerRect.height - colorMenu.elem.offsetHeight - COLOR_MENU_MARGIN;
2111
+ colorMenu.left = Math.round(basic.clamp(x - pickerRect.left, COLOR_MENU_MARGIN, maxLeft));
2112
+ colorMenu.top = Math.round(Math.max(COLOR_MENU_MARGIN, Math.min(y - pickerRect.top, maxTop)));
2113
+ const firstRow = colorMenu.elem.querySelector("[role=menuitem]");
2114
+ if (firstRow) firstRow.focus({ preventScroll: true });
2115
+ };
2116
+
2117
+ // *** CHANGES OF THE GROUPS (the picker draws its groups again after each one)
2118
+
2119
+ const afterGroupChange = function () {
2120
+ palettes = palettesOf(item);
2121
+ drawRecentArea();
2122
+ drawPaletteArea();
2123
+ };
2124
+
2125
+ const addColorTo = function (palette, value) {
2126
+ addPaletteColor(ctrl, palette, value);
2127
+ afterGroupChange();
2128
+ };
2129
+
2130
+ const deleteColor = function (view, palette) {
2131
+ deletePaletteColor(ctrl, palette, view.value);
2132
+ afterGroupChange();
2133
+ };
2134
+
2135
+ // The values of the colors in the order of the grid (after a drag).
2136
+ const sendOrder = function (palette, grid) {
2137
+ const values = [];
2138
+ Array.prototype.forEach.call(grid.elem.children, function (elem) {
2139
+ const view = swatchViews.find(function (v) { return v.obj.elem === elem; });
2140
+ if (view) values.push(view.value);
2141
+ });
2142
+ const isSameOrder = values.every(function (value, index) { return PropertyPanel.isSameValue(value, palette.colors[index].value); });
2143
+ if (isSameOrder) return;
2144
+ orderPaletteColors(ctrl, palette, values);
2145
+ afterGroupChange();
2146
+ };
2147
+
2148
+ // DRAG: a color of an editable group goes before or after the color under the mouse (not a fixed one).
2149
+ // It starts after a small move, so a click is still a click.
2150
+ const DRAG_START_DISTANCE = 4;
2151
+ const dragToOrder = function (view, palette, grid) {
2152
+ const square = view.obj;
2153
+ const moveTo = function (x, y) {
2154
+ const target = swatchViews.find(function (v) {
2155
+ if (v === view || v.fixed) return false;
2156
+ const rect = v.obj.elem.getBoundingClientRect();
2157
+ return (x >= rect.left && x <= rect.right && y >= rect.top && y <= rect.bottom);
2158
+ });
2159
+ if (!target) return;
2160
+ const rect = target.obj.elem.getBoundingClientRect();
2161
+ const isBefore = (x < rect.left + rect.width / 2);
2162
+ grid.elem.insertBefore(square.elem, (isBefore) ? target.obj.elem : target.obj.elem.nextSibling);
2163
+ };
2164
+ // WHY window, not setPointerCapture: moving the square in the grid (insertBefore) loses the capture,
2165
+ // and its pointerup never came (found with a real drag)
2166
+ square.elem.addEventListener("pointerdown", function (event) {
2167
+ if (event.button !== 0) return;
2168
+ const startX = event.clientX;
2169
+ const startY = event.clientY;
2170
+ let isDragging = 0;
2171
+ const onMove = function (moveEvent) {
2172
+ const distance = Math.abs(moveEvent.clientX - startX) + Math.abs(moveEvent.clientY - startY);
2173
+ if (!isDragging && distance < DRAG_START_DISTANCE) return;
2174
+ if (!isDragging) {
2175
+ isDragging = 1;
2176
+ square.opacity = 0.5;
2177
+ square.cursor = "grabbing";
2178
+ closeColorMenu();
2179
+ }
2180
+ moveTo(moveEvent.clientX, moveEvent.clientY);
2181
+ };
2182
+ const onUp = function () {
2183
+ window.removeEventListener("pointermove", onMove);
2184
+ window.removeEventListener("pointerup", onUp);
2185
+ window.removeEventListener("pointercancel", onUp);
2186
+ if (!isDragging || square._isRemoved) return; // (the picker was closed while dragging)
2187
+ square.opacity = 1;
2188
+ square.cursor = "pointer";
2189
+ square.wasDragged = 1;
2190
+ square.after(0, function () { square.wasDragged = 0; }); // WHY: after the click of this pointerup
2191
+ sendOrder(palette, grid);
2192
+ };
2193
+ window.addEventListener("pointermove", onMove);
2194
+ window.addEventListener("pointerup", onUp);
2195
+ window.addEventListener("pointercancel", onUp);
2196
+ });
2197
+ };
2198
+
2199
+ // GROUP: The recent colors with their tick (hidden when there are none). Drawn again after a delete.
2200
+ const drawRecentArea = function () {
2201
+ (recentArea.parts || []).forEach(function (part) { part.remove(); });
2202
+ recentViews = [];
2203
+ recentArea.visible = (recentColors.length) ? 1 : 0;
2204
+ if (!recentColors.length) return;
2205
+ recentArea.parts = createIn(recentArea, function () {
2206
+ // GROUP: The tick and the caption
2207
+ const head = HGroup({ width: contentWidth, height: TICK_SIZE + 2, align: "left center", gap: 6, color: "transparent" });
2208
+ const tick = buildTick(quickColors.recent, "Show the recent colors under the color fields", function (isOn) {
2209
+ quickColors.recent = isOn;
2210
+ saveQuickColors();
2211
+ refreshQuickStrips();
2212
+ });
2213
+ tick.css.marginLeft = TICK_MARGIN + "px";
2214
+ textLabel("", { fontSize: _t.captionSize, textColor: _t.softColor, plainText: "Recent" });
2215
+ endGroup();
2216
+ const row = HGroup({ width: contentWidth, height: "auto", align: "left center", gap: cp.swatchGap, color: "transparent" });
2217
+ row.css = { padding: cp.swatchRoom + "px", boxSizing: "border-box" };
2218
+ row.clipContent = 0;
2219
+ recentViews = recentColors.map(function (value) {
2220
+ return buildSwatch({ value: value, color: paintColorOf(item, value), hint: value }, RECENT_PALETTE, null);
2221
+ });
2222
+ endGroup();
2223
+ return [head, row];
2224
+ });
2225
+ paintSelectedSwatch();
2226
+ };
2227
+
2228
+ const buildSwatches = function (palette) {
2229
+ swatchViews = [];
2230
+ if (!palette.colors.length) {
2231
+ const lblEmpty = textLabel("", { textColor: _t.softColor, plainText: palette.emptyText || "No colors yet." });
2232
+ lblEmpty.css = { whiteSpace: "normal", lineHeight: "16px", padding: "2px 6px" };
2233
+ return null;
2234
+ }
2235
+ // GROUP: The colors of the palette (scrolls when there are many)
2236
+ // WHY the padding: the scroll cuts what goes out of the grid (the selected ring, the hover growth).
2237
+ const grid = HGroup({ width: contentWidth, height: "auto", align: "left top", gap: cp.swatchGap, wrap: 1, color: "transparent" });
2238
+ grid.css = { maxHeight: cp.swatchesMaxHeight + "px", padding: cp.swatchRoom + "px", boxSizing: "border-box" };
2239
+ grid.scrollY = 1; // (also clickable)
2240
+ palette.colors.forEach(function (preset) {
2241
+ swatchViews.push(buildSwatch(preset, palette, grid));
2242
+ });
2243
+ endGroup();
2244
+ return grid;
2245
+ };
2246
+
2247
+ // The palette part is drawn again when an other palette is chosen or its colors change.
2248
+ // The scroll of the colors stays when it is the same palette (Ex: after a drag or a delete).
2249
+ const drawPaletteArea = function () {
2250
+ closeColorMenu();
2251
+ const current = palettes.find(function (p) { return p.key === lastPaletteKey; }) || palettes[0];
2252
+ const isSamePalette = (paletteArea && current && paletteArea.paletteKey === current.key && paletteArea.grid);
2253
+ const keptScroll = (isSamePalette) ? paletteArea.grid.elem.scrollTop : 0;
2254
+ if (paletteArea) paletteArea.remove();
2255
+ paletteArea = createIn(obj, function () {
2256
+ // GROUP: Palettes
2257
+ const group = VGroup({ width: contentWidth, height: "auto", align: "left top", gap: 6, color: "transparent" });
2258
+ group.shrink = 0;
2259
+ buildPaletteHeader(current);
2260
+ if (isPaletteListOpen) buildPaletteList(current);
2261
+ else if (current) group.grid = buildSwatches(current);
2262
+ endGroup();
2263
+ return group;
2264
+ });
2265
+ paletteArea.paletteKey = (current) ? current.key : "";
2266
+ if (paletteArea.grid) paletteArea.grid.elem.scrollTop = keptScroll;
2267
+ paintSelectedSwatch();
2268
+ placePicker();
2269
+ };
2270
+
2271
+ // GROUP: The color before the picker opened (a click goes back to it) and the color now.
2272
+ const PREVIEW_WIDTH = 32;
2273
+ const buildPreview = function () {
2274
+ const preview = HGroup({ width: PREVIEW_WIDTH, height: _g.itemHeight, align: "left top", gap: 0, round: _s.field.round, color: "transparent" });
2275
+ preview.shrink = 0;
2276
+ preview.boxShadow = "inset 0 0 0 1px " + _s.swatch.borderColor;
2277
+ const before = Box({ width: PREVIEW_WIDTH / 2, height: _g.itemHeight, color: "transparent" });
2278
+ paintChecker(before, paintColorOf(item, valueAtOpen));
2279
+ before.clickable = 1;
2280
+ before.cursor = "pointer";
2281
+ before.role = "button";
2282
+ before.tabIndex = 0;
2283
+ before.aria = { label: "Back to the color before: " + (valueAtOpen || "none") };
2284
+ before.elem.title = "Before: " + (valueAtOpen || "none") + " (click to go back)";
2285
+ before.on("click", function () { commitValue(valueAtOpen); });
2286
+ onActivateKey(before, function () { commitValue(valueAtOpen); });
2287
+ previewNow = Box({ width: PREVIEW_WIDTH / 2, height: _g.itemHeight, color: "transparent" });
2288
+ previewNow.clickable = 0;
2289
+ endGroup();
2290
+ };
2291
+
2292
+ // LABEL: The format of the color text (a click: HEX -> RGB -> HSL)
2293
+ const buildFormatButton = function () {
2294
+ const btn = textLabel("HEX", { width: 34, height: _g.itemHeight, fontSize: 10, textColor: _t.softColor });
2295
+ btn.clickable = 1;
2296
+ btn.cursor = "pointer";
2297
+ btn.tabIndex = 0;
2298
+ btn.role = "button";
2299
+ btn.aria = { label: "Color format (HEX, RGB, HSL)" };
2300
+ btn.elem.title = "Change the format: HEX, RGB, HSL";
2301
+ const nextFormat = function () {
2302
+ colorFormat = COLOR_FORMATS[(COLOR_FORMATS.indexOf(colorFormat) + 1) % COLOR_FORMATS.length];
2303
+ paintPicker();
2304
+ };
2305
+ onHover(btn, function (isHover) { btn.textColor = (isHover) ? _t.color : _t.softColor; });
2306
+ btn.on("click", nextFormat);
2307
+ onActivateKey(btn, nextFormat);
2308
+ return btn;
2309
+ };
2310
+
2311
+ // WHY read once: a color outside of the panel may have a field that is drawn again while the picker is open.
2312
+ const fieldRect = colorField.rect || colorField.anchor.elem.getBoundingClientRect();
2313
+ const besideRect = colorField.besideRect || box.elem.getBoundingClientRect();
2314
+ let movedPlace = (colorField.besideRect) ? null : movedPickerPlace;
2315
+
2316
+ // At the left of the panel (or of besideRect), at the height of the field. Under the field when there is no
2317
+ // space at the left. A picker moved by its title stays where it was left.
2318
+ const placePicker = function () {
2319
+ const height = obj.elem.offsetHeight;
2320
+ let left = besideRect.left - cp.width - PICKER_SPACE;
2321
+ let top = fieldRect.top;
2322
+ if (left < SCREEN_MARGIN) {
2323
+ left = Math.min(fieldRect.left, window.innerWidth - cp.width - SCREEN_MARGIN);
2324
+ top = fieldRect.bottom + MENU_OFFSET;
2325
+ }
2326
+ if (movedPlace) {
2327
+ left = Math.min(movedPlace.left, window.innerWidth - cp.width - SCREEN_MARGIN);
2328
+ top = movedPlace.top;
2329
+ }
2330
+ obj.left = Math.max(SCREEN_MARGIN, left);
2331
+ obj.top = Math.max(SCREEN_MARGIN, Math.min(top, window.innerHeight - height - SCREEN_MARGIN));
2332
+ };
2333
+
2334
+ const keepMovedPlace = function (place) {
2335
+ movedPlace = place;
2336
+ if (!colorField.besideRect) movedPickerPlace = place;
2337
+ };
2338
+
2339
+ // DRAG: the title moves the picker, so it does not cover the object that is being colored.
2340
+ const moveByTitle = function (title) {
2341
+ title.clickable = 1;
2342
+ title.cursor = "move";
2343
+ title.elem.title = "Drag to move · Double click: back to its place";
2344
+ title.elem.addEventListener("pointerdown", function (event) {
2345
+ if (event.button !== 0 || event.target !== title.elem) return;
2346
+ event.preventDefault();
2347
+ const startX = event.clientX - obj.elem.getBoundingClientRect().left;
2348
+ const startY = event.clientY - obj.elem.getBoundingClientRect().top;
2349
+ const onMove = function (moveEvent) {
2350
+ keepMovedPlace({ left: moveEvent.clientX - startX, top: moveEvent.clientY - startY });
2351
+ placePicker();
2352
+ };
2353
+ const onUp = function () {
2354
+ window.removeEventListener("pointermove", onMove);
2355
+ window.removeEventListener("pointerup", onUp);
2356
+ window.removeEventListener("pointercancel", onUp);
2357
+ };
2358
+ window.addEventListener("pointermove", onMove);
2359
+ window.addEventListener("pointerup", onUp);
2360
+ window.addEventListener("pointercancel", onUp);
2361
+ });
2362
+ title.elem.addEventListener("dblclick", function (event) {
2363
+ if (event.target !== title.elem) return;
2364
+ keepMovedPlace(null);
2365
+ placePicker();
2366
+ });
2367
+ };
2368
+
2369
+ createIn(page, function () {
2370
+
2371
+ // GROUP: Color picker
2372
+ obj = VGroup({ left: 0, top: 0, width: cp.width, height: "auto", align: "left top", gap: 10, padding: cp.padding, color: ms.color, round: ms.round });
2373
+ obj.boxShadow = "0 0 0 1px " + ms.borderColor + ", " + ms.shadow;
2374
+ obj.zIndex = MENU_Z_INDEX;
2375
+ obj.css = { boxSizing: "border-box" };
2376
+ obj.clipContent = 0;
2377
+ obj.clickable = 1;
2378
+ obj.role = "dialog";
2379
+ obj.aria = { label: hint + " color" };
2380
+
2381
+ // GROUP: Title and close
2382
+ const pickerTitle = HGroup({ width: contentWidth, height: _g.itemHeight, align: "left center", gap: 4, color: "transparent" });
2383
+ textLabel("", { flex: 1, bold: 1, plainText: hint });
2384
+ const btnClose = textLabel(getIcon("close", 14), { width: _g.itemHeight, height: _g.itemHeight, textColor: _t.softColor });
2385
+ btnClose.round = _s.field.round;
2386
+ btnClose.clickable = 1;
2387
+ btnClose.cursor = "pointer";
2388
+ btnClose.tabIndex = 0;
2389
+ btnClose.role = "button";
2390
+ btnClose.aria = { label: "Close (Escape)" };
2391
+ btnClose.elem.title = "Close (Escape)";
2392
+ onHover(btnClose, function (isHover) { btnClose.color = (isHover) ? _s.button.hoverColor : "transparent"; });
2393
+ btnClose.on("click", closeMenu);
2394
+ onActivateKey(btnClose, closeMenu);
2395
+ endGroup();
2396
+ moveByTitle(pickerTitle);
2397
+
2398
+ // BOX: Saturation (left to right) and brightness (bottom to top) of the hue
2399
+ area = startBox({ width: contentWidth, height: cp.areaHeight, round: 4, color: "transparent" });
2400
+ area.css = { position: "relative", left: "0px", top: "0px", backgroundImage: "linear-gradient(to top, #000000, transparent), linear-gradient(to right, #FFFFFF, transparent)" };
2401
+ area.shrink = 0;
2402
+ area.clipContent = 0;
2403
+ area.clickable = 1;
2404
+ area.cursor = "crosshair";
2405
+ area.tabIndex = 0;
2406
+ area.role = "slider";
2407
+ area.aria = { label: hint + " saturation and brightness" };
2408
+ area.setFocusRing(_s.accent.color);
2409
+ areaHandle = Box({ left: 0, top: 0, width: cp.handleSize, height: cp.handleSize, round: cp.handleSize / 2, color: "transparent" });
2410
+ areaHandle.boxShadow = "0 0 0 2px #FFFFFF, 0 0 0 3px rgba(0, 0, 0, 0.35)";
2411
+ areaHandle.clickable = 0;
2412
+ endBox();
2413
+
2414
+ // GROUP: The eyedropper and the hue and opacity sliders
2415
+ // WHY: clipContent 0: the rings of the thumbs are bigger than the sliders.
2416
+ const sliderRow = HGroup({ width: contentWidth, height: "auto", align: "left center", gap: _g.gap, color: "transparent" });
2417
+ sliderRow.clipContent = 0;
2418
+ if (hasEyeDropper) {
2419
+ const btnDropper = textLabel(getIcon("eyedropper", 16), { width: _g.itemHeight, height: _g.itemHeight, textColor: _s.button.iconColor });
2420
+ btnDropper.round = _s.field.round;
2421
+ btnDropper.clickable = 1;
2422
+ btnDropper.cursor = "pointer";
2423
+ btnDropper.tabIndex = 0;
2424
+ btnDropper.role = "button";
2425
+ const dropperHint = (hasScreenDropper) ? "Pick a color from the screen" : "Pick a color from the page";
2426
+ btnDropper.aria = { label: dropperHint };
2427
+ btnDropper.elem.title = dropperHint;
2428
+ onHover(btnDropper, function (isHover) { btnDropper.color = (isHover) ? _s.button.hoverColor : "transparent"; });
2429
+ // WHY closed first: the page is clicked to pick; the value comes back through setValue (onChange)
2430
+ const pickFromPage = function () {
2431
+ const key = item.key;
2432
+ const keptAlpha = alpha;
2433
+ const ctrlAtPick = controllers[key];
2434
+ closeMenu();
2435
+ box.pickColor(box, function (color) {
2436
+ if (!box || !color) return;
2437
+ const pickedValue = joinAlpha(String(color).toUpperCase(), keptAlpha);
2438
+ if (colorField.isOutside) {
2439
+ colorField.commit(pickedValue);
2440
+ return;
2441
+ }
2442
+ // WHY the same ctrl: setData() while picking (another selection) makes new items with the same keys
2443
+ if (controllers[key] !== ctrlAtPick) return;
2444
+ box.setValue(key, pickedValue);
2445
+ });
2446
+ };
2447
+ const pickFromScreen = function () {
2448
+ if (!hasScreenDropper) {
2449
+ pickFromPage();
2450
+ return;
2451
+ }
2452
+ new window.EyeDropper().open().then(function (result) {
2453
+ if (!obj || obj._isRemoved) return;
2454
+ commitValue(joinAlpha(result.sRGBHex.toUpperCase(), alpha));
2455
+ }).catch(function () { }); // Escape: nothing was picked
2456
+ };
2457
+ btnDropper.on("click", pickFromScreen);
2458
+ onActivateKey(btnDropper, pickFromScreen);
2459
+ }
2460
+ // GROUP: Sliders
2461
+ const sliders = VGroup({ width: sliderWidth, height: "auto", align: "left top", gap: 10, color: "transparent" });
2462
+ sliders.clipContent = 0;
2463
+ hueSlider = buildSlider("hue", 360);
2464
+ hueSlider.css.background = "linear-gradient(to right, #FF0000, #FFFF00, #00FF00, #00FFFF, #0000FF, #FF00FF, #FF0000)";
2465
+ alphaSlider = buildSlider("opacity", 100);
2466
+ endGroup();
2467
+ endGroup();
2468
+
2469
+ // GROUP: Before / now, the format, the color text and its opacity
2470
+ HGroup({ width: contentWidth, height: _g.itemHeight, align: "left center", gap: 6, color: "transparent" });
2471
+ buildPreview();
2472
+ const inputs = buildInputField({ key: "hex", hint: hint }, contentWidth - PREVIEW_WIDTH - 6);
2473
+ inputs.el.style.paddingLeft = "4px";
2474
+ hexInput = inputs.input;
2475
+ alphaInput = addAlphaInput(inputs.field, inputs.state, hint);
2476
+ formatButton = createIn(inputs.field, buildFormatButton);
2477
+ inputs.field.elem.insertBefore(formatButton.elem, inputs.field.elem.firstChild);
2478
+ endGroup();
2479
+
2480
+ // GROUP: The recent colors (drawn by drawRecentArea)
2481
+ recentArea = VGroup({ width: contentWidth, height: "auto", align: "left top", gap: 6, color: "transparent" });
2482
+ recentArea.shrink = 0;
2483
+ recentArea.clipContent = 0;
2484
+ endGroup();
2485
+
2486
+ // BOX: Line
2487
+ const line = Box({ width: contentWidth, height: 1, color: ms.borderColor });
2488
+ line.shrink = 0;
2489
+
2490
+ endGroup();
2491
+
2492
+ });
2493
+
2494
+ menu = {
2495
+ obj: obj,
2496
+ opener: colorField.opener,
2497
+ ctrl: ctrl,
2498
+ colorField: colorField,
2499
+ sync: function () {
2500
+ readState();
2501
+ paintPicker();
2502
+ },
2503
+ onClose: function () {
2504
+ colorMenu = null; // (removed with the picker)
2505
+ const value = colorField.getValue();
2506
+ if (value !== valueAtOpen) {
2507
+ rememberColor(value);
2508
+ if (quickColors.recent) refreshQuickStrips();
2509
+ }
2510
+ if (colorField.onClose) colorField.onClose();
2511
+ },
2512
+ };
2513
+
2514
+ // WHY capture: a click anywhere else in the picker (a color too) closes the menu of a color first.
2515
+ obj.elem.addEventListener("pointerdown", function (event) {
2516
+ if (colorMenu && !colorMenu.elem.contains(event.target)) closeColorMenu();
2517
+ }, true);
2518
+
2519
+ dragOn(area, function (x, y) {
2520
+ hsv.s = x;
2521
+ hsv.v = 1 - y;
2522
+ commitState();
2523
+ });
2524
+ dragOn(hueSlider, function (x) {
2525
+ hsv.h = Math.min(x * 360, 359.9);
2526
+ commitState();
2527
+ });
2528
+ dragOn(alphaSlider, function (x) {
2529
+ alpha = roundAlpha(x);
2530
+ commitState();
2531
+ });
2532
+ onArrowKeys(area, {
2533
+ ArrowLeft: function (step) { hsv.s = basic.clamp(hsv.s - step / 100, 0, 1); },
2534
+ ArrowRight: function (step) { hsv.s = basic.clamp(hsv.s + step / 100, 0, 1); },
2535
+ ArrowUp: function (step) { hsv.v = basic.clamp(hsv.v + step / 100, 0, 1); },
2536
+ ArrowDown: function (step) { hsv.v = basic.clamp(hsv.v - step / 100, 0, 1); },
2537
+ });
2538
+ onArrowKeys(hueSlider, {
2539
+ ArrowLeft: function (step) { hsv.h = basic.clamp(hsv.h - step, 0, 359.9); },
2540
+ ArrowRight: function (step) { hsv.h = basic.clamp(hsv.h + step, 0, 359.9); },
2541
+ });
2542
+ onArrowKeys(alphaSlider, {
2543
+ ArrowLeft: function (step) { alpha = roundAlpha(alpha - step / 100); },
2544
+ ArrowRight: function (step) { alpha = roundAlpha(alpha + step / 100); },
2545
+ });
2546
+ connectColorInputs(hexInput, alphaInput, {
2547
+ getValue: colorField.getValue,
2548
+ commit: commitValue,
2549
+ refresh: paintPicker,
2550
+ getFormat: function () { return colorFormat; },
2551
+ });
2552
+
2553
+ readState();
2554
+ drawRecentArea();
2555
+ paintPicker();
2556
+ drawPaletteArea();
2557
+ area.elem.focus({ preventScroll: true });
2558
+
2559
+ };
2560
+
2561
+ // FIELD: color. [■ #3871E0 | 100%] A click on the swatch opens the color picker.
2562
+ const buildColorField = function (ctrl) {
2563
+
2564
+ const item = ctrl.item;
2565
+ const sw = _s.swatch;
2566
+ const hint = item.hint || item.label || item.key;
2567
+ const { field, input, el, state, setEnabled } = buildInputField(item, getSpanWidth(item.span));
2568
+ if (item.placeholder) input.placeholder = item.placeholder;
2569
+ el.style.paddingLeft = "4px";
2570
+ let value = "";
2571
+
2572
+ // BOX: Swatch (a checkerboard under the color: a transparent color shows it). A button: it opens the picker.
2573
+ const swatchArea = createIn(field, function () {
2574
+ const area = startBox({ width: sw.size + 12, height: _g.itemHeight, color: "transparent" });
2575
+ area.shrink = 0;
2576
+ area.clickable = 1;
2577
+ area.cursor = "pointer";
2578
+ area.role = "button";
2579
+ area.tabIndex = 0;
2580
+ area.aria = { label: "Open the color picker of " + hint, haspopup: "dialog" };
2581
+ area.elem.title = "Open the color picker";
2582
+ area.fill = Box({ width: sw.size, height: sw.size, round: 3, color: "transparent" });
2583
+ area.fill.center();
2584
+ area.fill.clickable = 0;
2585
+ endBox();
2586
+ return area;
2587
+ });
2588
+ field.elem.insertBefore(swatchArea.elem, field.elem.firstChild);
2589
+ const alphaInput = addAlphaInput(field, state, hint);
2590
+
2591
+ const paint = function () {
2592
+ const isEmpty = (splitAlpha(value).base === "");
2593
+ paintChecker(swatchArea.fill, paintColorOf(item, value));
2594
+ setBorder(swatchArea.fill, (isEmpty) ? sw.emptyColor : sw.borderColor);
2595
+ showColorInputs(input, alphaInput, value);
2596
+ strip.paint(value);
2597
+ };
2598
+
2599
+ const setValue = function (v) {
2600
+ value = (v === undefined || v === null) ? "" : String(v);
2601
+ paint();
2602
+ if (menu && menu.ctrl === ctrl) menu.sync();
2603
+ };
2604
+
2605
+ const commit = function (next) {
2606
+ value = String(next);
2607
+ paint();
2608
+ changeValue(ctrl, value);
2609
+ };
2610
+
2611
+ // GROUP: The quick colors under the field (the ticks of the picker)
2612
+ const strip = buildQuickStrip(ctrl, getSpanWidth(item.span), function (pickedValue) {
2613
+ if (state.enabled) commit(pickedValue);
2614
+ });
2615
+
2616
+ const colorField = {
2617
+ anchor: field,
2618
+ opener: swatchArea,
2619
+ getValue: function () { return value; },
2620
+ commit: commit,
2621
+ };
2622
+ const openPicker = function () {
2623
+ if (!state.enabled) return;
2624
+ openColorPicker(ctrl, colorField);
2625
+ };
2626
+ swatchArea.on("click", openPicker);
2627
+ onActivateKey(swatchArea, openPicker);
2628
+
2629
+ connectColorInputs(input, alphaInput, {
2630
+ getValue: colorField.getValue,
2631
+ commit: commit,
2632
+ refresh: paint,
2633
+ });
2634
+
2635
+ setValue(item.value);
2636
+ return {
2637
+ field: field,
2638
+ setValue: setValue,
2639
+ setEnabled: function (enabled) {
2640
+ setEnabled(enabled);
2641
+ alphaInput.inputElement.disabled = !enabled;
2642
+ alphaInput.inputElement.style.color = ink(enabled, _t.color);
2643
+ swatchArea.opacity = (enabled) ? 1 : 0.5;
2644
+ strip.setEnabled(enabled);
2645
+ },
2646
+ };
2647
+
2648
+ };
2649
+
2650
+ // *** ITEM TYPES:
2651
+ // Each one creates its object in the current container and returns { field, setValue(v), setEnabled(e) }.
2652
+ // ctrl.item is the working copy of the JSON item. changeValue(ctrl, v) keeps the value and sends the change.
2653
+ // An optional .normalize(value) fills the missing parts of a value (used before the value is kept).
2654
+
2655
+ const ITEM_TYPES = {
2656
+
2657
+ // [X 396] prefix / icon, unit, min, max, step, precision, autoText ("Auto" when the value is null)
2658
+ number: function (ctrl) {
2659
+ return buildNumberInput(ctrl, getSpanWidth(ctrl.item.span));
2660
+ },
2661
+
2662
+ // [ text ] placeholder
2663
+ // A text of more lines. caption: the first line of the placeholder, so it goes away while writing. rows: the lines (2).
2664
+ textarea: function (ctrl) {
2665
+ const item = ctrl.item;
2666
+ const ta = _s.textarea;
2667
+ const rows = item.rows || 2;
2668
+ const state = { isHover: 0, isFocus: 0, enabled: item.enabled != 0 };
2669
+
2670
+ // GROUP: Field (the caption, the text)
2671
+ const field = VGroup({ width: getSpanWidth(item.span || "full"), height: "auto", align: "left top", gap: 2, padding: [8, 6], color: _s.field.color, round: _s.field.round });
2672
+ field.shrink = 0;
2673
+ field.css = { boxSizing: "border-box", transition: "box-shadow 0.12s", alignItems: "stretch" };
2674
+ const paint = function () { paintField(field, state); };
2675
+
2676
+ endGroup();
2677
+
2678
+ // TEXTAREA: a raw element (a basic.js Input is one line)
2679
+ const area = document.createElement("textarea");
2680
+ area.rows = rows;
2681
+ area.spellcheck = false;
2682
+ const placeholderLines = [item.caption, item.placeholder].filter(Boolean);
2683
+ area.placeholder = placeholderLines.join("\n");
2684
+ area.setAttribute("aria-label", item.caption || item.hint || item.label || item.key);
2685
+ Object.assign(area.style, {
2686
+ width: "100%",
2687
+ boxSizing: "border-box",
2688
+ padding: "0px",
2689
+ border: "0px",
2690
+ outline: "none",
2691
+ resize: "none",
2692
+ background: "transparent",
2693
+ color: _t.color,
2694
+ font: _t.fontSize + "px " + ta.fontFamily,
2695
+ lineHeight: ta.lineHeight + "px",
2696
+ pointerEvents: "auto",
2697
+ userSelect: "text",
2698
+ });
2699
+ field.elem.appendChild(area);
2700
+
2701
+ const setValue = function (v) { area.value = (v === undefined || v === null) ? "" : String(v); };
2702
+ const save = function () { changeValue(ctrl, area.value); };
2703
+ onHover(field, function (isHover) {
2704
+ state.isHover = isHover;
2705
+ paint();
2706
+ });
2707
+ area.addEventListener("focus", function () {
2708
+ state.isFocus = 1;
2709
+ paint();
2710
+ });
2711
+ area.addEventListener("blur", function () {
2712
+ state.isFocus = 0;
2713
+ paint();
2714
+ save();
2715
+ });
2716
+ area.addEventListener("keydown", function (event) {
2717
+ event.stopPropagation(); // WHY: The keys of a text are not shortcuts of the page.
2718
+ const isSave = event.key === "Enter" && (event.metaKey || event.ctrlKey);
2719
+ if (isSave) {
2720
+ event.preventDefault();
2721
+ area.blur();
2722
+ } else if (event.key === "Escape") {
2723
+ event.preventDefault();
2724
+ setValue(ctrl.item.value);
2725
+ area.blur();
2726
+ }
2727
+ });
2728
+
2729
+ setValue(item.value);
2730
+ paint();
2731
+ return {
2732
+ field: field,
2733
+ setValue: setValue,
2734
+ setEnabled: function (enabled) {
2735
+ state.enabled = !!enabled;
2736
+ area.disabled = !state.enabled;
2737
+ paint();
2738
+ },
2739
+ };
2740
+ },
2741
+
2742
+ text: function (ctrl) {
2743
+ const item = ctrl.item;
2744
+ const { field, input, el, button, state, setEnabled } = buildInputField(item, getSpanWidth(item.span));
2745
+ if (item.placeholder) input.placeholder = item.placeholder;
2746
+ const setValue = function (v) { input.text = (v === undefined || v === null) ? "" : String(v); };
2747
+ el.addEventListener("blur", function () { changeValue(ctrl, String(input.text)); });
2748
+ el.addEventListener("keydown", function (event) {
2749
+ if (event.key === "Enter") {
2750
+ event.preventDefault();
2751
+ el.blur();
2752
+ } else if (event.key === "Escape") {
2753
+ event.preventDefault();
2754
+ setValue(ctrl.item.value);
2755
+ el.blur();
2756
+ } else if (button && event.altKey && event.key === "ArrowDown") {
2757
+ event.preventDefault();
2758
+ el.blur(); // WHY: the text written so far is kept first, the editor opens with it.
2759
+ sendFieldButton(ctrl);
2760
+ }
2761
+ });
2762
+ if (button) {
2763
+ button.on("click", function () {
2764
+ if (state.enabled) sendFieldButton(ctrl);
2765
+ });
2766
+ }
2767
+ setValue(item.value);
2768
+ return { field: field, setValue: setValue, setEnabled: setEnabled };
2769
+ },
2770
+
2771
+ // [ Left ⌄] options: ["A", "B"] or [{ value, text, icon }], icon, look: "plain"
2772
+ select: function (ctrl) {
2773
+ return buildSelect(ctrl.item, getSpanWidth(ctrl.item.span), function (v) { changeValue(ctrl, v); });
2774
+ },
2775
+
2776
+ // [16 | ⌄] a number field and preset values (options)
2777
+ combo: function (ctrl) {
2778
+ const item = ctrl.item;
2779
+ const width = getSpanWidth(item.span);
2780
+ const arrowWidth = 22;
2781
+ const r = _s.field.round + "px";
2782
+ let enabled = item.enabled != 0;
2783
+
2784
+ // GROUP: Number field + menu button
2785
+ const group = HGroup({ width: width, height: _g.itemHeight, align: "left center", gap: 1, color: "transparent" });
2786
+ group.shrink = 0;
2787
+
2788
+ const numberInput = buildNumberInput(ctrl, width - arrowWidth - 1);
2789
+ numberInput.field.css.borderRadius = r + " 0px 0px " + r;
2790
+
2791
+ // LABEL: Menu button
2792
+ const btnArrow = textLabel(getIcon("chevronDown", 12), { width: arrowWidth, height: _g.itemHeight, textColor: _t.softColor });
2793
+ btnArrow.color = _s.field.color;
2794
+ btnArrow.clickable = 1;
2795
+ btnArrow.cursor = "pointer";
2796
+ btnArrow.css.borderRadius = "0px " + r + " " + r + " 0px";
2797
+
2798
+ endGroup();
2799
+
2800
+ const options = normalizeOptions(item.options);
2801
+ onHover(btnArrow, function (isHover) {
2802
+ btnArrow.color = (isHover && enabled) ? _s.segmented.hoverColor : _s.field.color;
2803
+ });
2804
+ btnArrow.on("click", function () {
2805
+ if (!enabled) return;
2806
+ openMenu(group, btnArrow, options, ctrl.item.value, function (picked) {
2807
+ numberInput.setValue(picked);
2808
+ changeValue(ctrl, picked);
2809
+ });
2810
+ });
2811
+
2812
+ const setEnabled = function (e) {
2813
+ enabled = !!e;
2814
+ numberInput.setEnabled(e);
2815
+ btnArrow.textColor = ink(enabled, _t.softColor);
2816
+ };
2817
+
2818
+ return { field: group, setValue: numberInput.setValue, setEnabled: setEnabled };
2819
+ },
2820
+
2821
+ // [≡|≡|≡] options: [{ value, icon, text, hint }]. value !== undefined -> one is selected.
2822
+ segmented: function (ctrl) {
2823
+ const item = ctrl.item;
2824
+ const options = normalizeOptions(item.options);
2825
+ const isSelect = (item.mode) ? (item.mode === "select") : (item.value !== undefined);
2826
+ const r = _s.field.round + "px";
2827
+ let value = item.value;
2828
+ let enabled = item.enabled != 0;
2829
+ const parts = []; // { seg, option, isHover }
2830
+
2831
+ // One segment: background, border, icon color.
2832
+ const paintPart = function (part) {
2833
+ const isSelected = isSelect && PropertyPanel.isSameValue(part.option.value, value);
2834
+ const seg = part.seg;
2835
+ if (isSelected) seg.color = _s.segmented.selectedColor;
2836
+ else if (part.isHover && enabled) seg.color = _s.segmented.hoverColor;
2837
+ else seg.color = (isSelect) ? "transparent" : _s.field.color;
2838
+ setBorder(seg, (isSelected) ? _s.segmented.selectedBorderColor : "");
2839
+ seg.textColor = ink(enabled, (isSelect && !isSelected) ? _t.softColor : _s.button.iconColor);
2840
+ if (isSelect) seg.aria = { checked: (isSelected) ? "true" : "false" };
2841
+ };
2842
+ const paint = function () { parts.forEach(paintPart); };
2843
+
2844
+ // Select: every segment is round. Actions: only the outer corners of the row.
2845
+ const radiusOf = function (index) {
2846
+ if (isSelect) return r;
2847
+ if (index === 0) return r + " 0 0 " + r;
2848
+ if (index === options.length - 1) return "0 " + r + " " + r + " 0";
2849
+ return "0";
2850
+ };
2851
+
2852
+ // GROUP: Segments
2853
+ const group = HGroup({
2854
+ width: getSpanWidth(item.span),
2855
+ height: _g.itemHeight,
2856
+ align: "left center",
2857
+ gap: (isSelect) ? 0 : 1,
2858
+ color: (isSelect) ? _s.field.color : "transparent",
2859
+ round: _s.field.round,
2860
+ });
2861
+ group.shrink = 0;
2862
+ if (isSelect) setBorder(group, _s.field.borderColor || "");
2863
+ group.role = (isSelect) ? "radiogroup" : "group";
2864
+ group.aria = { label: item.hint || item.label || item.key };
2865
+
2866
+ options.forEach(function (option, index) {
2867
+ // LABEL: Segment
2868
+ const segHtml = (option.icon) ? getIcon(option.icon, 16) : basic.escapeHtml(option.text);
2869
+ const seg = textLabel(segHtml, { width: 10, height: _g.itemHeight, textColor: _s.button.iconColor });
2870
+ seg.grow = 1;
2871
+ seg.shrink = 1;
2872
+ seg.cursor = "pointer";
2873
+ seg.clickable = 1;
2874
+ seg.css = {
2875
+ flexBasis: "0px",
2876
+ outline: "none",
2877
+ transition: "background-color 0.12s",
2878
+ borderRadius: radiusOf(index),
2879
+ };
2880
+ seg.tabIndex = 0;
2881
+ seg.role = (isSelect) ? "radio" : "button";
2882
+ seg.aria = { label: option.hint || option.text };
2883
+ if (option.hint) seg.elem.title = option.hint;
2884
+
2885
+ const part = { seg: seg, option: option, isHover: 0 };
2886
+ parts.push(part);
2887
+
2888
+ const press = function () {
2889
+ if (!enabled) return;
2890
+ if (!isSelect) {
2891
+ sendAction(ctrl, option.value);
2892
+ return;
2893
+ }
2894
+ value = option.value;
2895
+ paint();
2896
+ changeValue(ctrl, value);
2897
+ };
2898
+ onHover(seg, function (isHover) {
2899
+ part.isHover = isHover;
2900
+ paintPart(part);
2901
+ });
2902
+ seg.on("click", press);
2903
+ onActivateKey(seg, press);
2904
+ });
2905
+
2906
+ endGroup();
2907
+
2908
+ paint();
2909
+
2910
+ return {
2911
+ field: group,
2912
+ setValue: function (v) { value = v; paint(); },
2913
+ setEnabled: function (e) { enabled = !!e; paint(); },
2914
+ };
2915
+ },
2916
+
2917
+ // [◎] icon, iconActive, toggle: 1 (value true / false), accent: 0 (no blue look when on)
2918
+ iconButton: buildIconButton,
2919
+
2920
+ alignGrid: buildAlignGrid,
2921
+
2922
+ color: buildColorField,
2923
+
2924
+ // Horizontal / vertical selects at the left and the constraints diagram at the right.
2925
+ // value: { horizontal: "left" | "right" | "leftRight" | "center" | "scale", vertical: "top" | "bottom" | "topBottom" | "center" | "scale" }
2926
+ constraints: function (ctrl) {
2927
+ const item = ctrl.item;
2928
+ let value = item.value; // Normalized: always has horizontal and vertical.
2929
+ let enabled = item.enabled != 0;
2930
+ const H_OPTIONS = [
2931
+ { value: "left", text: "Left" },
2932
+ { value: "right", text: "Right" },
2933
+ { value: "leftRight", text: "Left and right" },
2934
+ { value: "center", text: "Center" },
2935
+ { value: "scale", text: "Scale" },
2936
+ ];
2937
+ const V_OPTIONS = [
2938
+ { value: "top", text: "Top" },
2939
+ { value: "bottom", text: "Bottom" },
2940
+ { value: "topBottom", text: "Top and bottom" },
2941
+ { value: "center", text: "Center" },
2942
+ { value: "scale", text: "Scale" },
2943
+ ];
2944
+ const W = _g.columnWidth;
2945
+ const H = _g.itemHeight * 2 + _g.rowGap;
2946
+
2947
+ const change = function (next) {
2948
+ value = Object.assign({}, value, next);
2949
+ paint();
2950
+ changeValue(ctrl, value);
2951
+ };
2952
+
2953
+ // GROUP: Selects + diagram
2954
+ const group = HGroup({ width: getSpanWidth(2), height: H, align: "left top", gap: _g.gap, color: "transparent" });
2955
+ group.shrink = 0;
2956
+
2957
+ // GROUP: Selects
2958
+ VGroup({ width: W, height: H, align: "left top", gap: _g.rowGap, color: "transparent" });
2959
+ that.shrink = 0;
2960
+ const selH = buildSelect(
2961
+ { key: item.key + "-h", hint: "Horizontal constraint", icon: "constraintH", options: H_OPTIONS, value: value.horizontal },
2962
+ W, function (v) { change({ horizontal: v }); });
2963
+ const selV = buildSelect(
2964
+ { key: item.key + "-v", hint: "Vertical constraint", icon: "constraintV", options: V_OPTIONS, value: value.vertical },
2965
+ W, function (v) { change({ vertical: v }); });
2966
+ endGroup();
2967
+
2968
+ // BOX: Diagram
2969
+ const diagram = startBox({ width: W, height: H, color: _s.field.color, round: _s.field.round });
2970
+ diagram.shrink = 0;
2971
+
2972
+ const cx = Math.round(W / 2);
2973
+ const cy = Math.round(H / 2);
2974
+ // Inner frame
2975
+ const iw = 34;
2976
+ const ih = 22;
2977
+ const ix = cx - iw / 2;
2978
+ const iy = cy - ih / 2;
2979
+
2980
+ // BOX: Inner frame
2981
+ const frame = Box({ left: ix, top: iy, width: iw, height: ih, color: "transparent", round: 3 });
2982
+ setBorder(frame, _s.constraints.frameColor);
2983
+
2984
+ const line = function (left, top, width, height) {
2985
+ const obj = Box({ left: left, top: top, width: width, height: height, color: _t.disabledColor, round: 1 });
2986
+ obj.clickable = 0;
2987
+ return obj;
2988
+ };
2989
+ const lines = {
2990
+ top: line(cx - 1, iy - 13, 2, 9),
2991
+ bottom: line(cx - 1, iy + ih + 4, 2, 9),
2992
+ left: line(ix - 17, cy - 1, 13, 2),
2993
+ right: line(ix + iw + 4, cy - 1, 13, 2),
2994
+ centerH: line(cx - 6, cy, 12, 1),
2995
+ centerV: line(cx, cy - 6, 1, 12),
2996
+ };
2997
+
2998
+ // Click areas (bigger than the lines). Shift + click: both sides.
2999
+ const hitArea = function (left, top, width, height, onClick) {
3000
+ const obj = Box({ left: left, top: top, width: width, height: height, color: "transparent" });
3001
+ obj.clickable = 1;
3002
+ obj.cursor = "pointer";
3003
+ obj.on("click", function (self, event) {
3004
+ if (enabled) onClick(event.shiftKey);
3005
+ });
3006
+ return obj;
3007
+ };
3008
+ hitArea(cx - 10, 0, 20, iy - 2, function (shift) { change({ vertical: (shift && value.vertical === "bottom") ? "topBottom" : "top" }); });
3009
+ hitArea(cx - 10, iy + ih + 2, 20, H - iy - ih - 2, function (shift) { change({ vertical: (shift && value.vertical === "top") ? "topBottom" : "bottom" }); });
3010
+ hitArea(0, cy - 8, ix - 2, 16, function (shift) { change({ horizontal: (shift && value.horizontal === "right") ? "leftRight" : "left" }); });
3011
+ hitArea(ix + iw + 2, cy - 8, W - ix - iw - 2, 16, function (shift) { change({ horizontal: (shift && value.horizontal === "left") ? "leftRight" : "right" }); });
3012
+ hitArea(ix + 2, iy + 2, iw - 4, ih - 4, function () { change({ horizontal: "center", vertical: "center" }); });
3013
+
3014
+ endBox();
3015
+
3016
+ endGroup();
3017
+
3018
+ const paint = function () {
3019
+ const h = value.horizontal;
3020
+ const v = value.vertical;
3021
+ // Side lines: accent when on, gray when off. Center lines: accent when on, soft when off.
3022
+ const side = function (obj, isOn) { obj.color = (isOn) ? ink(enabled, _s.accent.color) : _t.disabledColor; };
3023
+ side(lines.top, v === "top" || v === "topBottom");
3024
+ side(lines.bottom, v === "bottom" || v === "topBottom");
3025
+ side(lines.left, h === "left" || h === "leftRight");
3026
+ side(lines.right, h === "right" || h === "leftRight");
3027
+ lines.centerH.color = (h === "center" && enabled) ? _s.accent.color : _t.softColor;
3028
+ lines.centerV.color = (v === "center" && enabled) ? _s.accent.color : _t.softColor;
3029
+ selH.setValue(h);
3030
+ selV.setValue(v);
3031
+ };
3032
+
3033
+ paint();
3034
+
3035
+ return {
3036
+ field: group,
3037
+ setValue: function (v) { value = v; paint(); },
3038
+ setEnabled: function (e) {
3039
+ enabled = !!e;
3040
+ selH.setEnabled(e);
3041
+ selV.setEnabled(e);
3042
+ paint();
3043
+ },
3044
+ };
3045
+ },
3046
+
3047
+ };
3048
+
3049
+ ITEM_TYPES.constraints.normalize = function (value) {
3050
+ return Object.assign({ horizontal: "left", vertical: "top" }, value || {});
3051
+ };
3052
+
3053
+ // *** VIEW BUILDERS:
3054
+
3055
+ // Builds an item with its type and registers it by its key. Returns its controller (or null).
3056
+ const registerItem = function (item, sectionKey) {
3057
+ const builder = ITEM_TYPES[item.type];
3058
+ if (!builder) {
3059
+ console.warn("PropertyPanel: Unknown item type: " + item.type);
3060
+ return null;
3061
+ }
3062
+ item.value = normalizeValue(item, item.value);
3063
+ const ctrl = { item: item, sectionKey: sectionKey };
3064
+ Object.assign(ctrl, builder(ctrl));
3065
+ if (item.key !== undefined) {
3066
+ if (controllers[item.key]) console.warn("PropertyPanel: Same key twice: " + item.key);
3067
+ controllers[item.key] = ctrl;
3068
+ }
3069
+ return ctrl;
3070
+ };
3071
+
3072
+ // item.visible: 0 hides the cell of the item (or the object itself when it has no cell).
3073
+ const applyVisible = function (ctrl) {
3074
+ if (!ctrl) return;
3075
+ const isHidden = (ctrl.item.visible === 0 || ctrl.item.visible === false);
3076
+ const obj = ctrl.cell || ctrl.field;
3077
+ obj.visible = (isHidden) ? 0 : 1;
3078
+ };
3079
+
3080
+ // One item of a row: the caption (if the row has one) and its object.
3081
+ const buildItem = function (item, sectionKey, hasCaption) {
3082
+
3083
+ // GROUP: Cell (as wide as its object)
3084
+ const cell = VGroup({ hug: 1, align: "left top", gap: 6, color: "transparent" });
3085
+ cell.shrink = 0;
3086
+
3087
+ if (hasCaption) {
3088
+ const caption = textLabel("", { fontSize: _t.captionSize, textColor: _t.softColor, height: 16, plainText: item.label || "" });
3089
+ // WHY: A long caption must not make the cell wider than its object: it takes the width of the cell.
3090
+ caption.css = { width: "0px", minWidth: "100%" };
3091
+ }
3092
+
3093
+ const ctrl = registerItem(item, sectionKey);
3094
+
3095
+ endGroup();
3096
+
3097
+ if (ctrl) {
3098
+ ctrl.cell = cell;
3099
+ applyVisible(ctrl);
3100
+ }
3101
+
3102
+ };
3103
+
3104
+ // Title + actions row (the panel title or a section title). Returns the title label.
3105
+ const buildTitleRow = function (text, actions, sectionKey, isMainTitle) {
3106
+ let lbl = null;
3107
+ HGroup({ width: "100%", height: (isMainTitle) ? 32 : 24, align: "left center", gap: 2, color: "transparent" });
3108
+ const st = _s.sectionTitle;
3109
+ lbl = textLabel("", {
3110
+ fontSize: (isMainTitle) ? _t.titleSize : _t.sectionTitleSize,
3111
+ textColor: (isMainTitle) ? _t.color : (st.textColor || _t.color),
3112
+ bold: 1,
3113
+ flex: 1,
3114
+ height: 24,
3115
+ plainText: text || "",
3116
+ });
3117
+ if (!isMainTitle && st.uppercase) lbl.css = { textTransform: "uppercase", letterSpacing: st.letterSpacing + "px" };
3118
+ (actions || []).forEach(function (action) {
3119
+ applyVisible(registerItem(Object.assign({ type: "iconButton", accent: 0 }, action), sectionKey));
3120
+ });
3121
+ endGroup();
3122
+ return lbl;
3123
+ };
3124
+
3125
+ const buildSection = function (section, isTitleBlock) {
3126
+
3127
+ // GROUP: Section
3128
+ const group = VGroup({ width: "100%", height: "auto", align: "left top", gap: _g.rowGap, color: "transparent" });
3129
+ group.shrink = 0;
3130
+ group.css = {
3131
+ padding: (isTitleBlock ? "8px " : "12px ") + _ps.paddingRight + "px " + (isTitleBlock ? "8px " : "16px ") + _ps.paddingLeft + "px",
3132
+ boxSizing: "border-box",
3133
+ borderBottom: "1px solid " + _ps.dividerColor,
3134
+ };
3135
+ if (section.mark) group.boxShadow = "inset " + _ps.markWidth + "px 0 0 " + Alpha(_s.accent.color, _ps.markOpacity);
3136
+
3137
+ // WHY: A section without a title and actions (Ex: a footer with a note) gets no empty title row.
3138
+ const hasTitleRow = isTitleBlock || !!section.title || (section.actions && section.actions.length > 0);
3139
+ const lbl = (hasTitleRow) ? buildTitleRow(section.title, section.actions, section.key, isTitleBlock) : null;
3140
+ if (isTitleBlock) titleLabel = lbl;
3141
+
3142
+ (section.items || []).forEach(function (row) {
3143
+ const items = (Array.isArray(row)) ? row : [row];
3144
+ const hasCaption = items.some(function (item) { return !!item.label; });
3145
+ // GROUP: Row
3146
+ HGroup({ width: "100%", height: "auto", align: "left bottom", gap: _g.gap, color: "transparent" });
3147
+ items.forEach(function (item) { buildItem(item, section.key, hasCaption); });
3148
+ endGroup();
3149
+ });
3150
+
3151
+ endGroup();
3152
+
3153
+ if (section.visible === 0 || section.visible === false) group.visible = 0;
3154
+ return group;
3155
+
3156
+ };
3157
+
3158
+ const paintTab = function (key) {
3159
+ const isActive = (key === box.data.activeTab);
3160
+ const isPill = (_s.tab.look === "pill");
3161
+ const lbl = tabLabels[key];
3162
+ lbl.color = (isActive && isPill) ? _s.field.color : "transparent";
3163
+ lbl.boxShadow = (isActive && !isPill) ? "inset 0 -2px 0 " + _s.accent.color : "none";
3164
+ lbl.textColor = (isActive) ? _t.color : _t.softColor;
3165
+ lbl.bold = isActive;
3166
+ lbl.aria = { selected: (isActive) ? "true" : "false" };
3167
+ };
3168
+
3169
+ const paintTabs = function () {
3170
+ Object.keys(tabLabels).forEach(paintTab);
3171
+ };
3172
+
3173
+ // Tabs and the item at the right of the header (Ex: zoom).
3174
+ const buildHeader = function () {
3175
+
3176
+ const data = box.data;
3177
+ if (box.headerRow) box.headerRow.remove();
3178
+ tabLabels = {};
3179
+
3180
+ createIn(box.header, function () {
3181
+
3182
+ // GROUP: Tabs row (created again by setData)
3183
+ box.headerRow = HGroup({ width: "100%", height: "100%", align: "left center", gap: 2, color: "transparent" });
3184
+
3185
+ // LABEL: The name (headerTitle). It takes the free room and ends with "..." when it is long.
3186
+ if (data.headerTitle !== undefined) {
3187
+ box.lblHeaderTitle = textLabel("", { flex: 1, bold: 1, fontSize: _t.titleSize, plainText: data.headerTitle });
3188
+ box.lblHeaderTitle.css.paddingLeft = "6px";
3189
+ }
3190
+
3191
+ (data.tabs || []).forEach(function (tab) {
3192
+ // LABEL: Tab
3193
+ // WHY as high as the header (underline): its line lies on the line under the header
3194
+ const isPill = (_s.tab.look === "pill");
3195
+ const lbl = textLabel("", { height: (isPill) ? 28 : "100%", plainText: tab.text || tab.key });
3196
+ if (isPill) lbl.round = _s.field.round;
3197
+ lbl.clickable = 1;
3198
+ lbl.cursor = "pointer";
3199
+ lbl.css = { padding: "0px 10px", outline: "none" };
3200
+ lbl.tabIndex = 0;
3201
+ lbl.role = "tab";
3202
+ tabLabels[tab.key] = lbl;
3203
+ const select = function () { box.setActiveTab(tab.key); };
3204
+ lbl.on("click", select);
3205
+ onActivateKey(lbl, select);
3206
+ onHover(lbl, function (isHover) {
3207
+ if (isHover && data.activeTab !== tab.key) lbl.textColor = _t.color;
3208
+ else paintTab(tab.key);
3209
+ });
3210
+ });
3211
+
3212
+ // BOX: Space (the name takes the free room when there is one)
3213
+ if (data.headerTitle === undefined) {
3214
+ const space = Box({ width: 10, height: 1, color: "transparent" });
3215
+ space.grow = 1;
3216
+ }
3217
+
3218
+ if (data.headerItem) {
3219
+ data.headerItem = Object.assign({ type: "select", look: "plain" }, data.headerItem);
3220
+ applyVisible(registerItem(data.headerItem, "header"));
3221
+ }
3222
+
3223
+ endGroup();
3224
+
3225
+ });
3226
+
3227
+ paintTabs();
3228
+
3229
+ };
3230
+
3231
+ // Title block and sections (in the scrolling box).
3232
+ const buildContent = function () {
3233
+
3234
+ if (box.content) box.content.remove();
3235
+ titleLabel = null;
3236
+ const data = box.data;
3237
+
3238
+ if (data.empty) {
3239
+ box.content = createIn(box.scrollBox, function () { return buildEmptyPage(data.empty); });
3240
+ return;
3241
+ }
3242
+
3243
+ createIn(box.scrollBox, function () {
3244
+ // GROUP: Content
3245
+ box.content = VGroup({ left: 0, top: 0, width: "100%", height: "auto", align: "left top", gap: 0, color: "transparent" });
3246
+ if (data.title !== undefined || (data.titleActions && data.titleActions.length)) {
3247
+ buildSection({ key: "title", title: data.title, actions: data.titleActions }, 1);
3248
+ }
3249
+ (data.sections || []).forEach(function (section) { buildSection(section, 0); });
3250
+ endGroup();
3251
+ });
3252
+
3253
+ };
3254
+
3255
+ // EMPTY PAGE: data.empty = { icon, title, text, hints: [{ keys, text }] }, in the middle of the panel.
3256
+ // (Ex: nothing is selected.) It takes the place of the sections.
3257
+ const EMPTY_TEXT_WIDTH = 184;
3258
+ const EMPTY_ICON_BOX = 56;
3259
+ const EMPTY_LIFT = 48; // WHY: A little above the middle looks centered (the optical middle).
3260
+
3261
+ const buildEmptyPage = function (empty) {
3262
+ const es = _s.empty;
3263
+ // GROUP: Empty page
3264
+ const emptyPage = VGroup({ left: 0, top: 0, width: "100%", height: "100%", align: "center center", gap: 0, color: "transparent" });
3265
+ emptyPage.css = { padding: "24px " + _ps.paddingRight + "px " + (24 + EMPTY_LIFT) + "px " + _ps.paddingLeft + "px", boxSizing: "border-box" };
3266
+
3267
+ if (empty.icon) {
3268
+ // LABEL: Icon in a soft square
3269
+ const icon = textLabel(getIcon(empty.icon, es.iconSize), { width: EMPTY_ICON_BOX, height: EMPTY_ICON_BOX, textColor: es.iconColor });
3270
+ icon.color = es.iconBoxColor;
3271
+ icon.round = es.iconBoxRound;
3272
+ icon.css.marginBottom = "16px";
3273
+ }
3274
+
3275
+ if (empty.title) {
3276
+ const lblTitle = textLabel("", { bold: 1, fontSize: _t.titleSize + 1, plainText: empty.title });
3277
+ lblTitle.role = "heading";
3278
+ lblTitle.aria = { level: 2 };
3279
+ lblTitle.css.marginBottom = "6px";
3280
+ }
3281
+
3282
+ if (empty.text) {
3283
+ const lblText = textLabel("", { textColor: _t.softColor, plainText: empty.text });
3284
+ lblText.width = EMPTY_TEXT_WIDTH;
3285
+ lblText.css = { display: "block", whiteSpace: "normal", textAlign: "center", lineHeight: "18px" };
3286
+ }
3287
+
3288
+ if (empty.hints && empty.hints.length) {
3289
+ // GROUP: Hints (what it does at the left, its key at the right: like the shortcuts of a menu)
3290
+ const hints = VGroup({ width: getSpanWidth("full"), height: "auto", align: "left top", gap: 8, color: "transparent" });
3291
+ hints.css = { marginTop: "20px", paddingTop: "16px", borderTop: "1px solid " + _ps.dividerColor };
3292
+ empty.hints.forEach(function (hint) {
3293
+ // GROUP: A hint
3294
+ HGroup({ width: "100%", height: "auto", align: "left center", gap: 8, color: "transparent" });
3295
+ textLabel("", { flex: 1, height: 20, fontSize: _t.captionSize, textColor: _t.softColor, plainText: hint.text });
3296
+ const keys = textLabel("", { height: 20, fontSize: _t.captionSize, plainText: hint.keys });
3297
+ keys.color = _s.field.color;
3298
+ keys.round = 4;
3299
+ keys.css = { padding: "0px 6px", minWidth: "20px", justifyContent: "center", boxSizing: "border-box" };
3300
+ endGroup();
3301
+ });
3302
+ endGroup();
3303
+ }
3304
+
3305
+ endGroup();
3306
+ return emptyPage;
3307
+ };
3308
+
3309
+ // FOOTER: data.footer, a section fixed at the bottom. The scrolling part ends above it.
3310
+ const FOOTER_SPACE = 10; // the space above and under the footer (the same: it fits its content)
3311
+ const buildFooter = function () {
3312
+ if (box.footerContent) box.footerContent.remove();
3313
+ box.footerContent = null;
3314
+ const footer = box.data.footer;
3315
+ box.footerBox.visible = (footer) ? 1 : 0;
3316
+ if (footer) {
3317
+ box.footerContent = createIn(box.footerBox, function () {
3318
+ const group = buildSection(Object.assign({ key: "footer" }, footer), 0);
3319
+ group.css.borderBottom = "none";
3320
+ group.css.padding = FOOTER_SPACE + "px " + _ps.paddingRight + "px " + FOOTER_SPACE + "px " + _ps.paddingLeft + "px";
3321
+ return group;
3322
+ });
3323
+ }
3324
+ placeScrollBox();
3325
+ };
3326
+
3327
+ const placeScrollBox = function () {
3328
+ const footerHeight = (box.footerContent) ? box.footerBox.elem.offsetHeight : 0;
3329
+ box.scrollBox.height = "calc(100% - " + (_ps.headerHeight + footerHeight) + "px)";
3330
+ };
3331
+
3332
+ // *** PUBLIC FUNCTIONS:
3333
+
3334
+ // Builds the panel again from a JSON. (The JSON is copied: getData() returns the copy with the current values.)
3335
+ box.setData = function (data) {
3336
+ closeMenu();
3337
+ paletteCache = null;
3338
+ controllers = {};
3339
+ // WHY: the strips of the items go with them; the ones of buildColorStrip() live outside of the panel.
3340
+ quickStrips = quickStrips.filter(function (strip) { return strip.isOutside; });
3341
+ box.data = PropertyPanel.copyData(data || {});
3342
+ buildHeader();
3343
+ buildContent();
3344
+ buildFooter();
3345
+ };
3346
+ // USAGE: panel.setData({ title: "Rectangle", sections: [...] })
3347
+
3348
+ // The JSON with the current values.
3349
+ box.getData = function () {
3350
+ return PropertyPanel.copyData(box.data);
3351
+ };
3352
+
3353
+ // { key: value } of every item with a key and a value.
3354
+ box.getValues = function () {
3355
+ const values = {};
3356
+ Object.keys(controllers).forEach(function (key) {
3357
+ const value = controllers[key].item.value;
3358
+ if (value !== undefined) values[key] = PropertyPanel.copyValue(value);
3359
+ });
3360
+ return values;
3361
+ };
3362
+
3363
+ box.getValue = function (key) {
3364
+ const ctrl = controllers[key];
3365
+ return (ctrl) ? PropertyPanel.copyValue(ctrl.item.value) : undefined;
3366
+ };
3367
+
3368
+ // silent: 1 -> no change event. Returns 1 when the key was found.
3369
+ box.setValue = function (key, value, silent = 0) {
3370
+ const ctrl = controllers[key];
3371
+ if (!ctrl) {
3372
+ console.warn("PropertyPanel: No item with the key: " + key);
3373
+ return 0;
3374
+ }
3375
+ const next = normalizeValue(ctrl.item, PropertyPanel.copyValue(value));
3376
+ if (PropertyPanel.isSameValue(ctrl.item.value, next)) return 1; // WHY: No DOM write for the same value.
3377
+ ctrl.setValue(PropertyPanel.copyValue(next));
3378
+ changeValue(ctrl, next, silent);
3379
+ return 1;
3380
+ };
3381
+ // USAGE: panel.setValue("x", 120, 1)
3382
+
3383
+ // The color picker for a color that is not an item of the panel. request:
3384
+ // { key, hint (its title), value, commit(value), onClose(), opener (an object: a click on it does not close the
3385
+ // picker, and opening it again from there closes it), rect (the field: the picker is at its height),
3386
+ // besideRect (the picker is at the left of this rect, not of the panel), noPagePick: 1 (the page can not be clicked now) }
3387
+ box.openColorPickerFor = function (request) {
3388
+ let value = String(request.value ?? "");
3389
+ const colorField = {
3390
+ isOutside: 1,
3391
+ opener: request.opener || { elem: document.createElement("div") },
3392
+ rect: request.rect,
3393
+ besideRect: request.besideRect,
3394
+ noPagePick: request.noPagePick,
3395
+ onClose: request.onClose,
3396
+ getValue: function () { return value; },
3397
+ commit: function (next) {
3398
+ value = String(next);
3399
+ request.commit(value);
3400
+ },
3401
+ };
3402
+ openColorPicker({ item: { key: request.key, hint: request.hint }, sectionKey: "" }, colorField);
3403
+ };
3404
+ // USAGE: panel.openColorPickerFor({ key: "tone", hint: "Tone", value: "#FF0000", rect: rect, opener: swatch, commit: write })
3405
+
3406
+ // The colors under a color field, for a color that is not an item of the panel. It follows the ticks of the picker and is
3407
+ // made in the current container. request: { key, hint, width, onPick(value) }. Returns { obj, paint(value), setHidden(isHidden) }.
3408
+ box.buildColorStrip = function (request) {
3409
+ const strip = buildQuickStrip({ item: { key: request.key, hint: request.hint }, sectionKey: "" }, request.width, request.onPick);
3410
+ strip.isOutside = 1;
3411
+ return strip;
3412
+ };
3413
+ // USAGE: const strip = panel.buildColorStrip({ key: "tone", hint: "Tone", width: 120, onPick: write }); strip.paint("#FF0000");
3414
+
3415
+ box.isColorPickerOpen = function () {
3416
+ return !!(menu && menu.colorField);
3417
+ };
3418
+
3419
+ box.closeColorPicker = function () {
3420
+ if (box.isColorPickerOpen()) closeMenu();
3421
+ };
3422
+
3423
+ // Is this element in a popup of the panel? (A popup of the page over it stays open for a click in the color picker.)
3424
+ box.isPopupElement = function (element) {
3425
+ return !!(menu && menu.obj.elem.contains(element));
3426
+ };
3427
+
3428
+ // Many values at once: { x: 10, y: 20 }
3429
+ box.setValues = function (values, silent = 0) {
3430
+ Object.keys(values || {}).forEach(function (key) { box.setValue(key, values[key], silent); });
3431
+ };
3432
+
3433
+ box.setEnabled = function (key, enabled) {
3434
+ const ctrl = controllers[key];
3435
+ if (!ctrl) return 0;
3436
+ ctrl.item.enabled = basic.isOn(enabled) ? 1 : 0;
3437
+ ctrl.setEnabled(ctrl.item.enabled);
3438
+ return 1;
3439
+ };
3440
+ // USAGE: panel.setEnabled("w", 0)
3441
+
3442
+ box.setItemVisible = function (key, visible) {
3443
+ const ctrl = controllers[key];
3444
+ if (!ctrl) return 0;
3445
+ ctrl.item.visible = basic.isOn(visible) ? 1 : 0;
3446
+ applyVisible(ctrl);
3447
+ return 1;
3448
+ };
3449
+
3450
+ box.getItem = function (key) {
3451
+ const ctrl = controllers[key];
3452
+ return (ctrl) ? ctrl.item : null;
3453
+ };
3454
+
3455
+ box.setTitle = function (text) {
3456
+ box.data.title = text;
3457
+ if (titleLabel) titleLabel.plainText = text || "";
3458
+ else buildContent(); // The title block did not exist.
3459
+ };
3460
+
3461
+ // silent: 1 -> no change event.
3462
+ box.setActiveTab = function (key, silent = 0) {
3463
+ const oldValue = box.data.activeTab;
3464
+ box.data.activeTab = key;
3465
+ paintTabs();
3466
+ if (silent || oldValue === key) return;
3467
+ dispatch({ kind: "tab", key: key, value: key, oldValue: oldValue, item: null, sectionKey: "header" });
3468
+ };
3469
+
3470
+ // Listens to every change. Returns a function that removes the listener.
3471
+ box.listen = function (fn) {
3472
+ listeners.push(fn);
3473
+ return function () { listeners = listeners.filter(function (f) { return f !== fn; }); };
3474
+ };
3475
+ // USAGE: const stop = panel.listen(function (panel, change) { println(change.key); }); stop();
3476
+
3477
+ box.open = function () {
3478
+ box.opened = 1;
3479
+ box.css.transform = "translateX(0px)";
3480
+ box.aria = { hidden: "false" };
3481
+ };
3482
+
3483
+ box.close = function () {
3484
+ closeMenu();
3485
+ box.opened = 0;
3486
+ box.css.transform = "translateX(100%)";
3487
+ box.aria = { hidden: "true" };
3488
+ };
3489
+
3490
+ box.toggle = function () {
3491
+ if (basic.isOn(box.opened)) {
3492
+ box.close();
3493
+ return;
3494
+ }
3495
+ box.open();
3496
+ };
3497
+
3498
+ // WHY: box.superRemove is overwritten by a component that extends this one, so the local copy is called below.
3499
+ const superRemove = box.remove;
3500
+ box.superRemove = superRemove;
3501
+ box.remove = function () {
3502
+ if (!box) return; // WHY: remove() can be called twice (also by the parent's remove()).
3503
+ closeMenu();
3504
+ superRemove.call(box); // NOTE: basic.js remove(). It cleans all the events and the objects inside.
3505
+ box = null;
3506
+ };
3507
+
3508
+ // *** OBJECT VIEW:
3509
+
3510
+ box.boxShadow = "inset 1px 0 0 " + _ps.dividerColor;
3511
+ box.css.transition = "transform " + _ps.motion + " ease";
3512
+ box.role = "complementary";
3513
+ box.aria = { label: "Properties" };
3514
+ box.clickable = 1;
3515
+
3516
+ // GROUP: Header (tabs)
3517
+ box.header = HGroup({ left: 0, top: 0, width: "100%", height: _ps.headerHeight, align: "left center", gap: 2, color: "transparent" });
3518
+ box.header.css = { padding: "0px " + _ps.paddingRight + "px 0px 10px", boxSizing: "border-box", borderBottom: "1px solid " + _ps.dividerColor };
3519
+ box.header.role = "tablist";
3520
+ endGroup();
3521
+
3522
+ // BOX: Scrolling content
3523
+ box.scrollBox = Box({ left: 0, top: _ps.headerHeight, width: "100%", height: "calc(100% - " + _ps.headerHeight + "px)", color: "transparent", scrollY: 1 });
3524
+
3525
+ // GROUP: Footer (data.footer, at the bottom)
3526
+ box.footerBox = VGroup({ left: 0, width: "100%", height: "auto", align: "left top", gap: 0, color: _ps.color });
3527
+ box.footerBox.css = { top: "auto", bottom: "0px", borderTop: "1px solid " + _ps.dividerColor, boxSizing: "border-box" };
3528
+ endGroup();
3529
+ box.footerBox.visible = 0;
3530
+
3531
+ // *** OBJECT INIT CODE:
3532
+
3533
+ // (listenTo / onPageResize: removed with the box)
3534
+ box.listenTo(document, "pointerdown", onDocumentPointerDown, true);
3535
+ box.listenTo(document, "keydown", onDocumentKeyDown);
3536
+ box.onPageResize(closeMenu);
3537
+ box.scrollBox.elem.addEventListener("scroll", closeMenu);
3538
+ box.footerBox.onResize(placeScrollBox); // WHY: The footer grows with its items (and with the fonts when they load).
3539
+
3540
+ box.setData(startData);
3541
+
3542
+ if (typeof ScrollBar !== "undefined") {
3543
+ ScrollBar({ scrollableBox: box.scrollBox, ..._s.scrollBar });
3544
+ }
3545
+
3546
+ if (basic.isOn(box.opened)) box.open();
3547
+ else box.close();
3548
+
3549
+ const panel = endObject(box);
3550
+
3551
+ // WHY: The container was moved to the page above. The caller goes on with its own container.
3552
+ setDefaultContainerBox(previousContainer);
3553
+
3554
+ return panel;
3555
+
3556
+ };
3557
+
3558
+ // *** STATIC FUNCTIONS:
3559
+
3560
+ // Values are numbers, texts, booleans or plain objects (constraints).
3561
+ PropertyPanel.copyValue = function (value) {
3562
+ if (value !== null && typeof value === "object") return JSON.parse(JSON.stringify(value));
3563
+ return value;
3564
+ };
3565
+
3566
+ PropertyPanel.isSameValue = function (a, b) {
3567
+ if (a === b) return true;
3568
+ if (a !== null && b !== null && typeof a === "object" && typeof b === "object") return JSON.stringify(a) === JSON.stringify(b);
3569
+ return false;
3570
+ };
3571
+
3572
+ // Copies the JSON. Functions (Ex: item.onChange) are kept as they are.
3573
+ PropertyPanel.copyData = function (data) {
3574
+ if (Array.isArray(data)) return data.map(PropertyPanel.copyData);
3575
+ if (data !== null && typeof data === "object") {
3576
+ const copy = {};
3577
+ Object.keys(data).forEach(function (key) { copy[key] = PropertyPanel.copyData(data[key]); });
3578
+ return copy;
3579
+ }
3580
+ return data;
3581
+ };
3582
+
3583
+ // *** ICONS: 16 x 16 SVG paths (stroke). Use the name as "icon", or give a raw "<svg ...>" string.
3584
+ // USAGE: PropertyPanel.icons.star = "M8 2l1.8 3.8 4.2.5-3.1 2.9.8 4.1L8 11.3 4.3 13.3l.8-4.1L2 6.3l4.2-.5z";
3585
+ PropertyPanel.icons = {
3586
+ alignLeft: "M2.5 2.5v11M5 5.5h8M5 10.5h5",
3587
+ alignCenterH: "M8 2v12M4 5.5h8M5.5 10.5h5",
3588
+ alignRight: "M13.5 2.5v11M3 5.5h8M6 10.5h5",
3589
+ alignTop: "M2.5 2.5h11M5.5 5v8M10.5 5v5",
3590
+ alignCenterV: "M2 8h12M5.5 4v8M10.5 5.5v5",
3591
+ alignBottom: "M2.5 13.5h11M5.5 3v8M10.5 6v5",
3592
+ frame: "M3 4.5h10v7H3zM6 8h4M8 6v4",
3593
+ component: "M5 2.5l1.5 1.5L5 5.5 3.5 4zM11 2.5l1.5 1.5L11 5.5 9.5 4zM5 10.5l1.5 1.5L5 13.5 3.5 12zM11 10.5l1.5 1.5-1.5 1.5L9.5 12z",
3594
+ link: "M7 9l2-2M6.5 5.5l1-1a2.5 2.5 0 013.5 3.5l-1 1M9.5 10.5l-1 1a2.5 2.5 0 01-3.5-3.5l1-1",
3595
+ target: "M8 2.5a5.5 5.5 0 100 11 5.5 5.5 0 000-11zM2.5 8h3M10.5 8h3M8 6.5a1.5 1.5 0 100 3 1.5 1.5 0 000-3z",
3596
+ more: "M3.5 7.2a.8.8 0 100 1.6.8.8 0 000-1.6zM8 7.2a.8.8 0 100 1.6.8.8 0 000-1.6zM12.5 7.2a.8.8 0 100 1.6.8.8 0 000-1.6z",
3597
+ constraintH: "M2.5 5v6M13.5 5v6M2.5 8h11",
3598
+ constraintV: "M5.5 2.5h5M5.5 13.5h5M8 2.5v11",
3599
+ angle: "M3 13h10M3 13V3M3 8.5A4.5 4.5 0 017.5 13",
3600
+ rotate: "M9.5 6.5l3 3-3 3-3-3zM3.5 9A5.5 5.5 0 0111 3.8M11 1.8v2.5H8.5",
3601
+ flipH: "M8 2v12M6 4.5L2.5 11.5H6zM10 4.5l3.5 7H10z",
3602
+ flipV: "M2 8h12M4.5 6l7-3.5V6zM4.5 10l7 3.5V10z",
3603
+ hugWidth: "M3 3v10M6 8h7M10.5 5.5L13 8l-2.5 2.5",
3604
+ fixedWidth: "M2.5 3v10M13.5 3v10M5.5 5.5h5M5.5 8h5M5.5 10.5h3",
3605
+ autoHeight: "M3.5 2.5h9a1 1 0 011 1v9a1 1 0 01-1 1h-9a1 1 0 01-1-1v-9a1 1 0 011-1zM5.5 5.5h5M5.5 8h5M5.5 10.5h3",
3606
+ clip: "M3.5 2.5h9a1 1 0 011 1v9a1 1 0 01-1 1h-9a1 1 0 01-1-1v-9a1 1 0 011-1zM9 13.5V9h4.5",
3607
+ eye: "M1.5 8s2.5-4.5 6.5-4.5S14.5 8 14.5 8s-2.5 4.5-6.5 4.5S1.5 8 1.5 8zM8 6a2 2 0 100 4 2 2 0 000-4z",
3608
+ eyeOff: "M1.5 8s2.5-4.5 6.5-4.5S14.5 8 14.5 8s-2.5 4.5-6.5 4.5S1.5 8 1.5 8zM8 6a2 2 0 100 4 2 2 0 000-4zM2.5 13.5l11-11",
3609
+ drop: "M8 2.5S4 7 4 9.5a4 4 0 008 0C12 7 8 2.5 8 2.5z",
3610
+ styles: "M5 3a2 2 0 100 4 2 2 0 000-4zM11 3a2 2 0 100 4 2 2 0 000-4zM5 9a2 2 0 100 4 2 2 0 000-4zM11 9a2 2 0 100 4 2 2 0 000-4z",
3611
+ opacity: "M3.5 2.5h9a1 1 0 011 1v9a1 1 0 01-1 1h-9a1 1 0 01-1-1v-9a1 1 0 011-1zM2.5 8h11M8 2.5v11",
3612
+ radius: "M2.5 6V4.5a2 2 0 012-2H6M10 2.5h1.5a2 2 0 012 2V6M13.5 10v1.5a2 2 0 01-2 2H10M6 13.5H4.5a2 2 0 01-2-2V10",
3613
+ textLeft: "M2.5 4h11M2.5 8h7M2.5 12h9",
3614
+ textCenter: "M2.5 4h11M4.5 8h7M3.5 12h9",
3615
+ textRight: "M2.5 4h11M6.5 8h7M4.5 12h9",
3616
+ textTop: "M3 2.5h10M8 13V6M5.5 8.5L8 6l2.5 2.5",
3617
+ textMiddle: "M3 8h10M8 2v3.5M6 3.5l2 2 2-2M8 14v-3.5M6 12.5l2-2 2 2",
3618
+ textBottom: "M3 13.5h10M8 3v7M5.5 7.5L8 10l2.5-2.5",
3619
+ lineHeight: "M3 2.5h10M3 13.5h10M5.5 11L8 5l2.5 6M6.4 9h3.2",
3620
+ letterSpacing: "M2.5 3v10M13.5 3v10M5.5 11L8 5l2.5 6M6.4 9h3.2",
3621
+ sliders: "M4 2.5v11M12 2.5v11M8 2.5v11M2.5 5.5h3M6.5 10.5h3M10.5 7h3",
3622
+ chevronDown: "M4.5 6.5L8 10l3.5-3.5",
3623
+ chevronUp: "M4.5 9.5L8 6l3.5 3.5",
3624
+ close: "M4 4l8 8M12 4l-8 8",
3625
+ pointer: "M4 2.5l8.5 5.2-3.7 1 2.1 3.9-1.7.9-2.1-3.9L4.3 12.2zM12 1.5v2M14.5 4h-2M13.8 2.2l-1.3 1.3",
3626
+ eyedropper: "M10.2 2.8a1.7 1.7 0 012.4 2.4l-1.4 1.4.7.7-1.1 1.1-3.3-3.3 1.1-1.1.7.7zM7.4 5.9L3 10.3V13h2.7l4.4-4.4",
3627
+ check: "M3.5 8.5l3 3 6-7",
3628
+ copy: "M6 6h7v7H6zM10 6V3H3v7h3",
3629
+ trash: "M2.5 4.5h11M6.5 4.5V3h3v1.5M4 4.5l.7 8.5h6.6l.7-8.5M6.8 7v3.5M9.2 7v3.5",
3630
+ chevronRight: "M6.5 4.5L10 8l-3.5 3.5",
3631
+ plus: "M8 3v10M3 8h10",
3632
+ minus: "M3 8h10",
3633
+ bold: "M5 3h3.8a2.4 2.4 0 0 1 0 4.8H5zM5 7.8h4.4a2.6 2.6 0 0 1 0 5.2H5z",
3634
+ italic: "M7 3h5M4 13h5M9.5 3l-3 10",
3635
+ flowHorizontal: "M2.5 8h11M10 4.5L13.5 8 10 11.5",
3636
+ flowVertical: "M8 2.5v11M4.5 10L8 13.5 11.5 10",
3637
+ wrap: "M2.5 4h11M2.5 8h9a2 2 0 0 1 0 4H8M9.5 10.5L8 12l1.5 1.5M2.5 12h3",
3638
+ ellipsis: "M2.5 8h.01M6 8h.01M9.5 8h.01M2.5 4.5h11M2.5 11.5h7",
3639
+ };