@widgetic/editor 4.1.21 → 4.1.23
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.
- package/README.md +43 -0
- package/dist/components/editors/CompositionEditorApp.svelte +228 -206
- package/dist/components/editors/EmbedAssistantPanel.svelte +270 -48
- package/dist/components/editors/EmbedEditor.svelte +7 -23
- package/dist/components/ic/AngleInputController.svelte +18 -3
- package/dist/components/ic/NumberInputController.svelte +16 -2
- package/dist/composition/compositionApi.d.ts +25 -0
- package/dist/composition/compositionApi.js +34 -4
- package/dist/composition/compositionEditorController.d.ts +63 -3
- package/dist/composition/compositionEditorController.js +207 -10
- package/dist/composition/staleGuard.d.ts +111 -0
- package/dist/composition/staleGuard.js +279 -0
- package/dist/embedAssistant/embedAssistantSuggest.d.ts +20 -0
- package/dist/embedAssistant/embedAssistantSuggest.js +29 -0
- package/dist/embedAssistant/embedAssistantTurns.d.ts +73 -0
- package/dist/embedAssistant/embedAssistantTurns.js +56 -0
- package/dist/embedAssistant/types.d.ts +15 -0
- package/dist/i18n/language.d.ts +18 -4
- package/dist/i18n/messages.d.ts +9 -2
- package/dist/i18n/messages.js +11 -2
- package/dist/i18n/translate.d.ts +1 -1
- package/package.json +6 -1
- package/dist/components/ic/NumberControls.svelte +0 -505
- package/dist/components/ic/NumberControls.svelte.d.ts +0 -37
- package/dist/components/ic/numberControlsSteps.d.ts +0 -17
- package/dist/components/ic/numberControlsSteps.js +0 -23
- package/dist/components/ic/numberControlsValueArea.d.ts +0 -29
- package/dist/components/ic/numberControlsValueArea.js +0 -51
package/dist/i18n/translate.d.ts
CHANGED
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
* its sentences with it until the page gives another translator). The editor's screens get their words, in the page's
|
|
4
4
|
* language, from `useEditorLanguage` (see `language.ts`).
|
|
5
5
|
*/
|
|
6
|
-
export declare const translateEnglish: import("@widgetic/design-system/i18n").Translate<"editor.app.loading" | "editor.app.tryAgain" | "editor.app.retry" | "editor.failure.widgetNotPublished" | "editor.failure.sessionEndedWhileSaving" | "editor.failure.sessionEnded" | "editor.failure.compositionNotFound" | "editor.failure.noAccess" | "editor.failure.noWidget" | "editor.failure.widgetNotFound" | "editor.failure.saveNeedsConnection" | "editor.failure.loadNeedsConnection" | "editor.failure.saveFailed" | "editor.failure.loadFailed" | "editor.failure.settingsLoadFailed" | "editor.failure.noSettings" | "editor.failure.errorCode" | "editor.conflict.title" | "editor.conflict.bodyNamed" | "editor.conflict.body" | "editor.conflict.keepMine" | "editor.conflict.keepMineHint" | "editor.conflict.loadLatest" | "editor.conflict.loadLatestHint" | "editor.conflict.working" | "editor.conflict.resolveFailed" | "editor.presence.blockedTitleNamed" | "editor.presence.blockedTitleYou" | "editor.presence.blockedTitle" | "editor.presence.blockedBody" | "editor.presence.lostTitleNamed" | "editor.presence.lostTitleYou" | "editor.presence.lostTitle" | "editor.presence.lostBody" | "editor.presence.takeOver" | "editor.presence.takeOverHint" | "editor.presence.lookOnly" | "editor.presence.lookOnlyHint" | "editor.presence.working" | "editor.presence.actionFailed" | "editor.presence.readOnlyNamed" | "editor.presence.readOnlyYou" | "editor.presence.readOnly" | "editor.presence.readOnlyFree" | "editor.presence.startEditing" | "editor.props.title" | "editor.props.designTab" | "editor.props.contentTab" | "editor.props.contentCard" | "editor.props.save" | "editor.props.saving" | "editor.props.noConfiguration" | "editor.props.noDesignSchema" | "editor.props.noSchemaData" | "editor.props.noComponents" | "editor.props.noProperties" | "editor.props.addItem" | "editor.props.deleteItem" | "editor.contentBulkDrop.idleHint" | "editor.contentBulkDrop.dragOver" | "editor.contentBulkDrop.summaryAddedOnly" | "editor.contentBulkDrop.summaryWithLibraryOnly" | "editor.contentBulkDrop.uploadFailures" | "editor.contentBulkDrop.dismiss" | "editor.contentBulkDrop.uploadFailed" | "editor.contentBulkDrop.tooLarge" | "editor.contentBulkDrop.uploadingHeader" | "editor.embed.title" | "editor.embed.loading" | "editor.embed.noCode" | "editor.embed.codeHeader" | "editor.embed.headerArea" | "editor.embed.copy" | "editor.embed.copied" | "editor.embed.copiedHint" | "editor.embed.copyFailed" | "editor.embed.copyFailedHint" | "editor.embed.
|
|
6
|
+
export declare const translateEnglish: import("@widgetic/design-system/i18n").Translate<"editor.app.loading" | "editor.app.tryAgain" | "editor.app.retry" | "editor.failure.widgetNotPublished" | "editor.failure.sessionEndedWhileSaving" | "editor.failure.sessionEnded" | "editor.failure.compositionNotFound" | "editor.failure.noAccess" | "editor.failure.noWidget" | "editor.failure.widgetNotFound" | "editor.failure.saveNeedsConnection" | "editor.failure.loadNeedsConnection" | "editor.failure.saveFailed" | "editor.failure.loadFailed" | "editor.failure.settingsLoadFailed" | "editor.failure.noSettings" | "editor.failure.errorCode" | "editor.conflict.title" | "editor.conflict.bodyNamed" | "editor.conflict.body" | "editor.conflict.keepMine" | "editor.conflict.keepMineHint" | "editor.conflict.loadLatest" | "editor.conflict.loadLatestHint" | "editor.conflict.working" | "editor.conflict.resolveFailed" | "editor.stale.updating" | "editor.stale.updatingDescription" | "editor.stale.updatingStatus" | "editor.presence.blockedTitleNamed" | "editor.presence.blockedTitleYou" | "editor.presence.blockedTitle" | "editor.presence.blockedBody" | "editor.presence.lostTitleNamed" | "editor.presence.lostTitleYou" | "editor.presence.lostTitle" | "editor.presence.lostBody" | "editor.presence.takeOver" | "editor.presence.takeOverHint" | "editor.presence.lookOnly" | "editor.presence.lookOnlyHint" | "editor.presence.working" | "editor.presence.actionFailed" | "editor.presence.readOnlyNamed" | "editor.presence.readOnlyYou" | "editor.presence.readOnly" | "editor.presence.readOnlyFree" | "editor.presence.startEditing" | "editor.props.title" | "editor.props.designTab" | "editor.props.contentTab" | "editor.props.contentCard" | "editor.props.save" | "editor.props.saving" | "editor.props.noConfiguration" | "editor.props.noDesignSchema" | "editor.props.noSchemaData" | "editor.props.noComponents" | "editor.props.noProperties" | "editor.props.addItem" | "editor.props.deleteItem" | "editor.contentBulkDrop.idleHint" | "editor.contentBulkDrop.dragOver" | "editor.contentBulkDrop.summaryAddedOnly" | "editor.contentBulkDrop.summaryWithLibraryOnly" | "editor.contentBulkDrop.uploadFailures" | "editor.contentBulkDrop.dismiss" | "editor.contentBulkDrop.uploadFailed" | "editor.contentBulkDrop.tooLarge" | "editor.contentBulkDrop.uploadingHeader" | "editor.embed.title" | "editor.embed.loading" | "editor.embed.noCode" | "editor.embed.codeHeader" | "editor.embed.headerArea" | "editor.embed.copy" | "editor.embed.copied" | "editor.embed.copiedHint" | "editor.embed.copyFailed" | "editor.embed.copyFailedHint" | "editor.embed.pasteAreaAria" | "editor.embed.pasteInvalid" | "editor.embed.pasteApplied" | "editor.embed.pasteNotApplied" | "editor.embed.widgetDefaultsBanner" | "editor.embed.widgetDefaultsReset" | "editor.embedAssistant.tabLabel" | "editor.embedAssistant.title" | "editor.embedAssistant.welcome" | "editor.embedAssistant.chipOverlayExitIntent" | "editor.embedAssistant.chipCenteredFiveTimes" | "editor.embedAssistant.chipHideOnMobile" | "editor.embedAssistant.composerPlaceholder" | "editor.embedAssistant.newChat" | "editor.embedAssistant.collapse" | "editor.embedAssistant.working" | "editor.embedAssistant.continue" | "editor.embedAssistant.send" | "editor.embedAssistant.copyEmbedCode" | "editor.embedAssistant.errorGeneric" | "editor.embedAssistant.errorRateLimit" | "editor.embedAssistant.suggestionTabKey" | "editor.embedAssistant.suggestionTabHint" | "editor.embedAssistant.suggestionAnnouncement" | "editor.preview.title" | "editor.preview.dragHandle" | "editor.preview.desktop" | "editor.preview.mobile" | "editor.preview.widthShort" | "editor.preview.heightShort" | "editor.preview.noUrl" | "editor.preview.copyUrl" | "editor.preview.refresh" | "editor.preview.fitToPanel" | "editor.preview.mobileViewport" | "editor.preview.desktopViewport" | "editor.preview.openInNewTab" | "editor.preview.newTab" | "editor.preview.selectWidget" | "editor.preview.widgetName" | "editor.preview.notPublished" | "editor.preview.publishToPreview" | "editor.preview.frameTitle" | "editor.preview.frameTitleNamed" | "editor.preview.unavailable" | "editor.preview.loadFailedPreview" | "editor.preview.retry" | "editor.preview.retryBuild" | "editor.preview.retryPreview" | "editor.preview.fixErrors" | "editor.preview.viewErrors" | "editor.preview.runtimeError" | "editor.preview.compilationErrors" | "editor.preview.compilationErrorsDetail" | "editor.preview.noCodeYet" | "editor.preview.noPreview" | "editor.preview.building" | "editor.preview.loadingWidget" | "editor.preview.loadingPreview" | "editor.preview.checkingWidget" | "editor.preview.applyingSettings" | "editor.preview.connecting" | "editor.preview.generatingCode" | "editor.list.recentlyUsed" | "editor.list.more" | "editor.list.searchResults" | "editor.list.loadingMore" | "editor.list.deleteItem" | "editor.category.all" | "editor.category.mine" | "editor.category.sansSerif" | "editor.category.serif" | "editor.category.script" | "editor.category.other" | "editor.category.icons" | "editor.category.emojis" | "editor.category.clipart" | "editor.font.select" | "editor.font.title" | "editor.font.search" | "editor.font.list" | "editor.font.loading" | "editor.font.noneFound" | "editor.font.noneAvailable" | "editor.font.remove" | "editor.font.weight" | "editor.font.weightList" | "editor.fontWeight.withItalic" | "editor.fontWeight.italic" | "editor.fontWeight.thin" | "editor.fontWeight.extraLight" | "editor.fontWeight.light" | "editor.fontWeight.regular" | "editor.fontWeight.medium" | "editor.fontWeight.semiBold" | "editor.fontWeight.bold" | "editor.fontWeight.extraBold" | "editor.fontWeight.black" | "editor.vector.select" | "editor.vector.title" | "editor.vector.search" | "editor.vector.list" | "editor.vector.noneFound" | "editor.vector.noneAvailable" | "editor.file.useFile" | "editor.file.useImage" | "editor.file.useVideo" | "editor.file.useAudio" | "editor.file.useDocument" | "editor.file.addFile" | "editor.file.addImage" | "editor.file.addVideo" | "editor.file.addAudio" | "editor.file.addDocument" | "editor.file.play" | "editor.file.pause" | "editor.file.notFound" | "editor.file.emptyFolder" | "editor.file.clear" | "editor.file.pickFailed" | "editor.file.dialogTitle" | "editor.file.closeDialog" | "editor.color.noRecent" | "editor.color.picker" | "editor.date.pick" | "editor.date.pickRange" | "editor.date.invalid" | "editor.date.selectMonth" | "editor.date.selectYear" | "editor.date.calendarLabel" | "editor.date.rangeCalendarLabel" | "editor.date.previousMonth" | "editor.date.nextMonth" | "editor.dateField.dayHint" | "editor.dateField.monthHint" | "editor.dateField.yearHint" | "editor.dateField.dayLabel" | "editor.dateField.monthLabel" | "editor.dateField.yearLabel" | "editor.knowledge.loading" | "editor.knowledge.unavailable" | "editor.knowledge.retry" | "editor.knowledge.empty" | "editor.knowledge.listLabel" | "editor.knowledge.characters" | "editor.knowledge.processing" | "editor.knowledge.removeLabel" | "editor.knowledge.removeConfirm" | "editor.knowledge.keep" | "editor.knowledge.removing" | "editor.knowledge.sending" | "editor.knowledge.sendingOf" | "editor.knowledge.addFiles" | "editor.knowledge.dropHint" | "editor.knowledge.addText" | "editor.knowledge.documentsUsed" | "editor.knowledge.textUsed" | "editor.knowledge.titleLabel" | "editor.knowledge.titlePlaceholder" | "editor.knowledge.textLabel" | "editor.knowledge.textPlaceholder" | "editor.knowledge.addDocument" | "editor.knowledge.cancel" | "editor.knowledge.dismiss" | "editor.knowledgeError.titleRequired" | "editor.knowledgeError.titleTooLong" | "editor.knowledgeError.textRequired" | "editor.knowledgeError.textTooLong" | "editor.knowledgeError.fileRequired" | "editor.knowledgeError.fileTooLarge" | "editor.knowledgeError.fileTypeUnsupported" | "editor.knowledgeError.fileUnreadable" | "editor.knowledgeError.fileNoText" | "editor.knowledgeError.duplicate" | "editor.knowledgeError.limitDocuments" | "editor.knowledgeError.limitText" | "editor.knowledgeError.tryLater" | "editor.knowledgeError.tooManyAdds" | "editor.knowledgeError.connection" | "editor.knowledgeError.generic" | "editor.knowledgeError.moreProblems" | "editor.knowledgeError.notSent" | "editor.dropdown.select" | "editor.switch.off" | "editor.switch.on" | "editor.tags.add" | "editor.fixedPosition.set" | "editor.fixedPosition.topLeft" | "editor.fixedPosition.topCenter" | "editor.fixedPosition.topRight" | "editor.fixedPosition.centerLeft" | "editor.fixedPosition.centerCenter" | "editor.fixedPosition.centerRight" | "editor.fixedPosition.bottomLeft" | "editor.fixedPosition.bottomCenter" | "editor.fixedPosition.bottomRight" | "editor.corners.group" | "editor.corners.topLeft" | "editor.corners.topRight" | "editor.corners.bottomLeft" | "editor.corners.bottomRight" | "editor.corners.lock" | "editor.corners.unlock" | "editor.textArea.toolbar" | "editor.textArea.toggleBold" | "editor.textArea.toggleItalic" | "editor.textArea.toggleUnderline" | "editor.textArea.toggleLink" | "editor.textArea.text" | "editor.textArea.paragraph" | "editor.textArea.heading1" | "editor.textArea.heading2" | "editor.textArea.heading3" | "editor.textArea.bulletList" | "editor.textArea.numberedList" | "editor.textArea.checkList" | "editor.textArea.textStyles" | "editor.textArea.listStyles" | "editor.textArea.linkUrlLabel" | "editor.textArea.linkUrlPlaceholder" | "editor.textArea.linkUrlApply" | "editor.textArea.linkUrlRemove" | "editor.textArea.linkUrlEmpty" | "editor.textArea.linkUrlInvalid" | "editor.position.readout" | "editor.stepper.decrease" | "editor.stepper.increase" | "editor.tags.remove" | "editor.list.uploadedByYou" | "editor.vector.loadFailed" | "editor.textArea.closePanel" | "editor.textArea.closeColorMode" | "editor.embed.helpPrompt" | "editor.embed.learnMore" | "editor.embed.helpLinkAria" | "editor.schema.subtitleFont">;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@widgetic/editor",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.23",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -51,7 +51,9 @@
|
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"@widgetic/api-sdk": "*",
|
|
54
|
+
"@widgetic/brand": "^0.1.1",
|
|
54
55
|
"@widgetic/cache-layer": "^0.1.1",
|
|
56
|
+
"@widgetic/chat": ">=0.1.42",
|
|
55
57
|
"@widgetic/design-system": ">=0.5.28",
|
|
56
58
|
"@widgetic/file-browser": "^0.5.41",
|
|
57
59
|
"svelte": "^5.27.0"
|
|
@@ -67,7 +69,9 @@
|
|
|
67
69
|
"@types/fontfaceobserver": "^2.1.3",
|
|
68
70
|
"@types/node": "26.6.2",
|
|
69
71
|
"@widgetic/api-sdk": "^2.0.1",
|
|
72
|
+
"@widgetic/brand": "^0.1.1",
|
|
70
73
|
"@widgetic/cache-layer": "^0.1.1",
|
|
74
|
+
"@widgetic/chat": "^0.1.42",
|
|
71
75
|
"@widgetic/design-system": "^0.5.28",
|
|
72
76
|
"@widgetic/dev-tools": "^0.2.0",
|
|
73
77
|
"@widgetic/file-browser": "^0.5.41",
|
|
@@ -84,6 +88,7 @@
|
|
|
84
88
|
"tailwind-variants": "^0.3.0",
|
|
85
89
|
"tailwindcss": "^4.1.4",
|
|
86
90
|
"tailwindcss-animate": "^1.0.7",
|
|
91
|
+
"three": "^0.174.0",
|
|
87
92
|
"typescript": "^5.8.3",
|
|
88
93
|
"typescript-eslint": "^8.32.1",
|
|
89
94
|
"vite": "^6.2.6",
|
|
@@ -1,505 +0,0 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import { onDestroy } from 'svelte';
|
|
3
|
-
import { Input, StepperButton } from '@widgetic/design-system/components';
|
|
4
|
-
import { useEditorLanguage } from '../../i18n/language';
|
|
5
|
-
import { steppedNumber } from './numberControlsSteps';
|
|
6
|
-
import {
|
|
7
|
-
shouldRoutePointerToNumberInput,
|
|
8
|
-
selectionAfterValueAreaPress,
|
|
9
|
-
isPointerPastTextEnd,
|
|
10
|
-
selectionWhileDraggingFromValueChrome
|
|
11
|
-
} from './numberControlsValueArea';
|
|
12
|
-
|
|
13
|
-
const { t } = useEditorLanguage();
|
|
14
|
-
|
|
15
|
-
export let value: number;
|
|
16
|
-
export let onChange: (newValue: number) => void;
|
|
17
|
-
export let min: number;
|
|
18
|
-
export let max: number;
|
|
19
|
-
export let step: number = 1;
|
|
20
|
-
export let isLocked: boolean = false;
|
|
21
|
-
export let onFocus: () => void = () => {};
|
|
22
|
-
export let customInputClass: string = '';
|
|
23
|
-
export let wrapAround: boolean = false;
|
|
24
|
-
export let suffix: string = '';
|
|
25
|
-
/** Extra classes on the outer control surface (default full width of the control column). */
|
|
26
|
-
let className = '';
|
|
27
|
-
export { className as class };
|
|
28
|
-
export let disabled: boolean = false;
|
|
29
|
-
/**
|
|
30
|
-
* Padding at the end of the accent surface, after the steppers (Figma IC Number vs IC Angle field).
|
|
31
|
-
* The padding at the start is not on the surface: it is inside the text hit area, so the hit area reaches the edge.
|
|
32
|
-
*/
|
|
33
|
-
export let surfacePaddingClass: string = 'pe-1';
|
|
34
|
-
/** Padding at the start of the text hit area: it keeps the value 12px in from the edge (Figma IC Number: the value is at x=12). */
|
|
35
|
-
export let inputPaddingClass: string = 'ps-3';
|
|
36
|
-
/** @deprecated use `class` — kept for Angle layout width. */
|
|
37
|
-
export let width: string | undefined = undefined;
|
|
38
|
-
|
|
39
|
-
let inputValue = String(value);
|
|
40
|
-
let isEditing = false;
|
|
41
|
-
let isPressed = false;
|
|
42
|
-
let pressedStepper: 'increment' | 'decrement' | null = null;
|
|
43
|
-
|
|
44
|
-
let autoRepeatTimer: ReturnType<typeof setTimeout> | null = null;
|
|
45
|
-
let autoRepeatInterval: ReturnType<typeof setInterval> | null = null;
|
|
46
|
-
|
|
47
|
-
let numberInputEl: HTMLInputElement | null = null;
|
|
48
|
-
let valueAreaDragActive = false;
|
|
49
|
-
|
|
50
|
-
function measureTextWidth(text: string, font: string): number {
|
|
51
|
-
if (typeof document === 'undefined') return text.length * 8;
|
|
52
|
-
const canvas = document.createElement('canvas');
|
|
53
|
-
const context = canvas.getContext('2d');
|
|
54
|
-
if (!context) return text.length * 8;
|
|
55
|
-
context.font = font;
|
|
56
|
-
return context.measureText(text).width;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function textWidthOnInput(input: HTMLInputElement): number {
|
|
60
|
-
return measureTextWidth(input.value, getComputedStyle(input).font);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const HOLD_DELAY = 400;
|
|
64
|
-
const REPEAT_INTERVAL = 80;
|
|
65
|
-
|
|
66
|
-
// Add unique ID generation
|
|
67
|
-
const inputId = `number-input-${Math.random().toString(36).substr(2, 9)}`;
|
|
68
|
-
const suffixDescriptionId = suffix ? `${inputId}-suffix` : undefined;
|
|
69
|
-
|
|
70
|
-
$: isAtMin = !wrapAround && value <= min;
|
|
71
|
-
$: isAtMax = !wrapAround && value >= max;
|
|
72
|
-
$: isDisabled = disabled || isLocked;
|
|
73
|
-
|
|
74
|
-
// Update inputValue when value prop changes and we're not editing
|
|
75
|
-
$: if (!isEditing) {
|
|
76
|
-
inputValue = String(value);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const surfaceBaseClass =
|
|
80
|
-
'number-controls-surface flex h-9 w-full min-w-0 items-center gap-1 rounded-lg bg-accent transition-colors duration-fast hover:bg-accent-hover focus-within:outline-hidden focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2 focus-within:ring-offset-background disabled:pointer-events-none disabled:opacity-50';
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* One step of the stepper (button, hold or arrow key). Returns false when nothing was applied because the value is at a limit.
|
|
84
|
-
*/
|
|
85
|
-
function handleValueChange(adjustment: number): boolean {
|
|
86
|
-
try {
|
|
87
|
-
const newValue = steppedNumber(value, adjustment, { min, max, wrapAround });
|
|
88
|
-
|
|
89
|
-
// At a limit there is nothing to apply, and nothing to repeat: no event for the page, and a held button stops here
|
|
90
|
-
if (newValue === value) {
|
|
91
|
-
stopAutoRepeat();
|
|
92
|
-
return false;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
value = newValue;
|
|
96
|
-
// The field shows the new number at once, also when the person has typed in it. It used to keep the typed text
|
|
97
|
-
// (`isEditing` stays true while the field has the focus, and a stepper button does not take the focus) and
|
|
98
|
-
// `handleBlur` then wrote that old text back over the number the stepper had set.
|
|
99
|
-
inputValue = String(newValue);
|
|
100
|
-
isEditing = false;
|
|
101
|
-
onChange(newValue);
|
|
102
|
-
return true;
|
|
103
|
-
} catch (error) {
|
|
104
|
-
console.error('Error in handleValueChange:', error);
|
|
105
|
-
return false;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function handleInput(e: Event) {
|
|
110
|
-
const input = e.currentTarget as HTMLInputElement;
|
|
111
|
-
inputValue = input.value;
|
|
112
|
-
|
|
113
|
-
if (inputValue === '') {
|
|
114
|
-
isEditing = true;
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// Handle special cases
|
|
119
|
-
if (inputValue === '-0') {
|
|
120
|
-
inputValue = '0';
|
|
121
|
-
input.value = '0';
|
|
122
|
-
value = 0;
|
|
123
|
-
onChange(0);
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// If starts with 0 and has more digits, remove the leading 0
|
|
128
|
-
if (inputValue.startsWith('0') && inputValue.length > 1 && !inputValue.startsWith('-')) {
|
|
129
|
-
inputValue = inputValue.substring(1);
|
|
130
|
-
input.value = inputValue;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// Don't allow minus sign if:
|
|
134
|
-
// 1. min >= 0
|
|
135
|
-
// 2. there's already a minus sign
|
|
136
|
-
// 3. there are numbers before it
|
|
137
|
-
if (inputValue.includes('-')) {
|
|
138
|
-
if (min >= 0 || inputValue.indexOf('-') > 0 || inputValue.split('-').length > 2) {
|
|
139
|
-
// Remove all minus signs or keep only the first one if allowed
|
|
140
|
-
inputValue = min >= 0 ? inputValue.replace(/-/g, '') : '-' + inputValue.replace(/-/g, '');
|
|
141
|
-
input.value = inputValue;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// Update regex to prevent minus sign if min >= 0
|
|
146
|
-
// Only allow minus at the start of the string
|
|
147
|
-
const validNumberRegex = min >= 0 ? /^\d*$/ : /^-?\d*$/;
|
|
148
|
-
if (!validNumberRegex.test(inputValue)) {
|
|
149
|
-
// Remove any invalid characters
|
|
150
|
-
input.value = inputValue.replace(min >= 0 ? /[^\d]/g : /[^\d-]/g, '');
|
|
151
|
-
// If there's a minus, ensure it's at the start
|
|
152
|
-
if (input.value.includes('-') && input.value.indexOf('-') > 0) {
|
|
153
|
-
input.value = input.value.replace(/-/g, '');
|
|
154
|
-
}
|
|
155
|
-
inputValue = input.value;
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
const numValue = parseFloat(inputValue);
|
|
160
|
-
if (!isNaN(numValue)) {
|
|
161
|
-
isEditing = true;
|
|
162
|
-
|
|
163
|
-
// Validate both min and max during typing
|
|
164
|
-
if (wrapAround && max === 360) {
|
|
165
|
-
if (numValue >= 360) {
|
|
166
|
-
inputValue = '359';
|
|
167
|
-
value = 359;
|
|
168
|
-
onChange(359);
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
} else if (!wrapAround) {
|
|
172
|
-
if (numValue > max) {
|
|
173
|
-
inputValue = String(max);
|
|
174
|
-
value = max;
|
|
175
|
-
onChange(max);
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
if (numValue < min) {
|
|
179
|
-
inputValue = String(min);
|
|
180
|
-
value = min;
|
|
181
|
-
onChange(min);
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
// Value is within range
|
|
187
|
-
value = numValue;
|
|
188
|
-
onChange(numValue);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
function handleBlur() {
|
|
193
|
-
isEditing = false;
|
|
194
|
-
const finalValue = parseFloat(inputValue);
|
|
195
|
-
|
|
196
|
-
if (isNaN(finalValue) || inputValue === '' || inputValue === '-') {
|
|
197
|
-
value = min;
|
|
198
|
-
inputValue = String(min);
|
|
199
|
-
onChange(min);
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// Apply validation on blur
|
|
204
|
-
let validatedValue = finalValue;
|
|
205
|
-
if (!wrapAround) {
|
|
206
|
-
if (finalValue < min) validatedValue = min;
|
|
207
|
-
if (finalValue > max) validatedValue = max;
|
|
208
|
-
} else {
|
|
209
|
-
validatedValue = ((finalValue % 360) + 360) % 360;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
value = validatedValue;
|
|
213
|
-
inputValue = String(validatedValue);
|
|
214
|
-
onChange(validatedValue);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
function startAutoRepeat(operation: 'increment' | 'decrement', event: MouseEvent) {
|
|
218
|
-
// Only the main button steps: a right or middle click must not
|
|
219
|
-
if (event.button !== 0) return;
|
|
220
|
-
// Do not preventDefault on mousedown: it suppresses the button :active state and breaks press-feedback scale.
|
|
221
|
-
stopAutoRepeat();
|
|
222
|
-
|
|
223
|
-
const adjustment = operation === 'increment' ? step : -step;
|
|
224
|
-
isPressed = true;
|
|
225
|
-
pressedStepper = operation === 'increment' ? 'increment' : 'decrement';
|
|
226
|
-
|
|
227
|
-
// The button turns disabled when the value reaches a limit, and a disabled button gets no mouseup and no mouseleave:
|
|
228
|
-
// the release is watched on the window too, or the repeat would go on firing `onChange` at the limit until the next press.
|
|
229
|
-
window.addEventListener('mouseup', releasePress);
|
|
230
|
-
window.addEventListener('blur', releasePress);
|
|
231
|
-
|
|
232
|
-
// At a limit there is nothing to hold
|
|
233
|
-
if (!handleValueChange(adjustment)) return;
|
|
234
|
-
|
|
235
|
-
autoRepeatTimer = setTimeout(() => {
|
|
236
|
-
if (isPressed) {
|
|
237
|
-
autoRepeatInterval = setInterval(() => {
|
|
238
|
-
if (isPressed) {
|
|
239
|
-
handleValueChange(adjustment);
|
|
240
|
-
}
|
|
241
|
-
}, REPEAT_INTERVAL);
|
|
242
|
-
}
|
|
243
|
-
}, HOLD_DELAY);
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
/** The release of a press, seen on the window (see `startAutoRepeat`). */
|
|
247
|
-
function releasePress() {
|
|
248
|
-
stopAutoRepeat();
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
/** A stepper button pressed with the keyboard (Enter or Space) clicks without a mouse down: `detail` is 0 then. */
|
|
252
|
-
function handleStepperClick(operation: 'increment' | 'decrement', event: MouseEvent) {
|
|
253
|
-
if (event.detail !== 0) return;
|
|
254
|
-
handleValueChange(operation === 'increment' ? step : -step);
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
function stopAutoRepeat(event?: MouseEvent | FocusEvent) {
|
|
258
|
-
// Do not preventDefault on mouseup: it can shorten :active and weaken press-feedback on the steppers.
|
|
259
|
-
if (event) {
|
|
260
|
-
event.stopPropagation();
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
if (typeof window !== 'undefined') {
|
|
264
|
-
window.removeEventListener('mouseup', releasePress);
|
|
265
|
-
window.removeEventListener('blur', releasePress);
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
if (autoRepeatTimer !== null) {
|
|
269
|
-
clearTimeout(autoRepeatTimer);
|
|
270
|
-
autoRepeatTimer = null;
|
|
271
|
-
}
|
|
272
|
-
if (autoRepeatInterval !== null) {
|
|
273
|
-
clearInterval(autoRepeatInterval);
|
|
274
|
-
autoRepeatInterval = null;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
isPressed = false;
|
|
278
|
-
pressedStepper = null;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
function handleKeyDown(e: KeyboardEvent) {
|
|
282
|
-
if ((e.metaKey || e.ctrlKey) && e.key === 'a') {
|
|
283
|
-
e.preventDefault();
|
|
284
|
-
const input = e.currentTarget as HTMLInputElement;
|
|
285
|
-
input.setSelectionRange(0, input.value.length);
|
|
286
|
-
isEditing = true;
|
|
287
|
-
return;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
if (
|
|
291
|
-
e.key === 'Backspace' ||
|
|
292
|
-
e.key === 'Delete' ||
|
|
293
|
-
e.key === 'ArrowLeft' ||
|
|
294
|
-
e.key === 'ArrowRight' ||
|
|
295
|
-
e.key === 'Tab'
|
|
296
|
-
) {
|
|
297
|
-
isEditing = true;
|
|
298
|
-
return;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
if (e.metaKey || e.ctrlKey) {
|
|
302
|
-
return;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
if (e.key === 'ArrowUp') {
|
|
306
|
-
e.preventDefault();
|
|
307
|
-
handleValueChange(step);
|
|
308
|
-
} else if (e.key === 'ArrowDown') {
|
|
309
|
-
e.preventDefault();
|
|
310
|
-
handleValueChange(-step);
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
function focusNumberInput(input: HTMLInputElement) {
|
|
315
|
-
input.focus({ preventScroll: true });
|
|
316
|
-
isEditing = true;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
function endValueAreaDrag() {
|
|
320
|
-
valueAreaDragActive = false;
|
|
321
|
-
if (typeof window !== 'undefined') {
|
|
322
|
-
window.removeEventListener('mousemove', handleValueAreaMouseMove);
|
|
323
|
-
window.removeEventListener('mouseup', endValueAreaDrag);
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
function handleValueAreaMouseMove(event: MouseEvent) {
|
|
328
|
-
if (!valueAreaDragActive || isDisabled) return;
|
|
329
|
-
const input = numberInputEl ?? document.getElementById(inputId);
|
|
330
|
-
if (!(input instanceof HTMLInputElement)) return;
|
|
331
|
-
const pastEnd = isPointerPastTextEnd(
|
|
332
|
-
input.value,
|
|
333
|
-
input.getBoundingClientRect().left,
|
|
334
|
-
event.clientX,
|
|
335
|
-
textWidthOnInput(input)
|
|
336
|
-
);
|
|
337
|
-
const selection = selectionWhileDraggingFromValueChrome(
|
|
338
|
-
input.value.length,
|
|
339
|
-
pastEnd,
|
|
340
|
-
event.shiftKey
|
|
341
|
-
);
|
|
342
|
-
if (selection) {
|
|
343
|
-
input.setSelectionRange(selection.start, selection.end);
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
function handleValueAreaMouseDown(event: MouseEvent) {
|
|
348
|
-
if (isDisabled) return;
|
|
349
|
-
if (!shouldRoutePointerToNumberInput(event.target, inputId)) return;
|
|
350
|
-
const input = document.getElementById(inputId);
|
|
351
|
-
if (!(input instanceof HTMLInputElement)) return;
|
|
352
|
-
event.preventDefault();
|
|
353
|
-
focusNumberInput(input);
|
|
354
|
-
const { start, end } = selectionAfterValueAreaPress(inputValue, event.shiftKey);
|
|
355
|
-
input.setSelectionRange(start, end);
|
|
356
|
-
valueAreaDragActive = true;
|
|
357
|
-
window.addEventListener('mousemove', handleValueAreaMouseMove);
|
|
358
|
-
window.addEventListener('mouseup', endValueAreaDrag);
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
function handleInputMouseDown(event: MouseEvent) {
|
|
362
|
-
if (isDisabled || event.button !== 0) return;
|
|
363
|
-
const input = event.currentTarget as HTMLInputElement;
|
|
364
|
-
const pastEnd = isPointerPastTextEnd(
|
|
365
|
-
input.value,
|
|
366
|
-
input.getBoundingClientRect().left,
|
|
367
|
-
event.clientX,
|
|
368
|
-
textWidthOnInput(input)
|
|
369
|
-
);
|
|
370
|
-
if (!pastEnd) return;
|
|
371
|
-
event.preventDefault();
|
|
372
|
-
focusNumberInput(input);
|
|
373
|
-
const { start, end } = selectionAfterValueAreaPress(inputValue, event.shiftKey);
|
|
374
|
-
input.setSelectionRange(start, end);
|
|
375
|
-
valueAreaDragActive = true;
|
|
376
|
-
window.addEventListener('mousemove', handleValueAreaMouseMove);
|
|
377
|
-
window.addEventListener('mouseup', endValueAreaDrag);
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
onDestroy(() => {
|
|
381
|
-
stopAutoRepeat();
|
|
382
|
-
endValueAreaDrag();
|
|
383
|
-
});
|
|
384
|
-
</script>
|
|
385
|
-
|
|
386
|
-
<div
|
|
387
|
-
class="{surfaceBaseClass} {surfacePaddingClass} {className}"
|
|
388
|
-
style={width ? `width: ${width}` : undefined}
|
|
389
|
-
class:opacity-50={disabled}
|
|
390
|
-
class:pointer-events-none={disabled}
|
|
391
|
-
>
|
|
392
|
-
<!--
|
|
393
|
-
The hit area of the text: from the start edge of the surface to the steppers, with the surface's own rounded corner at
|
|
394
|
-
the start edge, so the whole area reads as one field. A label focuses the input when the area is clicked, so nothing in
|
|
395
|
-
it is dead space (the padding that keeps the value 12px in used to sit on the surface, outside the input, and the input
|
|
396
|
-
drew its own square hover box inside the rounded surface, which looked cut out).
|
|
397
|
-
-->
|
|
398
|
-
<!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
|
|
399
|
-
<label
|
|
400
|
-
for={inputId}
|
|
401
|
-
class="number-controls-hit-area flex h-full min-w-0 flex-1 items-center rounded-s-lg {inputPaddingClass} {isDisabled
|
|
402
|
-
? 'cursor-default'
|
|
403
|
-
: 'cursor-text'} {suffix ? 'justify-start gap-0' : ''}"
|
|
404
|
-
onmousedown={handleValueAreaMouseDown}
|
|
405
|
-
>
|
|
406
|
-
{#if suffix}
|
|
407
|
-
<span class="number-controls-value inline-flex w-fit max-w-full min-w-0 items-baseline gap-0">
|
|
408
|
-
<span class="number-controls-digit-sizer relative inline-block w-fit max-w-full">
|
|
409
|
-
<!-- The sizer is as wide as the digits themselves (no `ch` guess: a digit, a minus sign and a dot are not equally wide), so nothing is left after the number -->
|
|
410
|
-
<span class="invisible block whitespace-pre text-body tabular-nums" aria-hidden="true">
|
|
411
|
-
{inputValue || '0'}
|
|
412
|
-
</span>
|
|
413
|
-
<Input
|
|
414
|
-
id={inputId}
|
|
415
|
-
type="text"
|
|
416
|
-
bind:ref={numberInputEl}
|
|
417
|
-
value={inputValue}
|
|
418
|
-
aria-describedby={suffixDescriptionId}
|
|
419
|
-
onfocus={onFocus}
|
|
420
|
-
oninput={handleInput}
|
|
421
|
-
onblur={handleBlur}
|
|
422
|
-
onkeydown={handleKeyDown}
|
|
423
|
-
onmousedown={handleInputMouseDown}
|
|
424
|
-
readonly={isLocked}
|
|
425
|
-
{disabled}
|
|
426
|
-
class="number-controls-input number-controls-input-with-suffix select-text absolute inset-0 h-full w-full min-w-0 border-0 bg-transparent px-0 text-start text-body text-foreground shadow-none hover:bg-transparent focus-visible:ring-0 focus-visible:ring-offset-0 {customInputClass}"
|
|
427
|
-
/>
|
|
428
|
-
</span>
|
|
429
|
-
{#if suffixDescriptionId}
|
|
430
|
-
<span id={suffixDescriptionId} class="sr-only">{suffix}</span>
|
|
431
|
-
{/if}
|
|
432
|
-
<span
|
|
433
|
-
class="pointer-events-none shrink-0 select-none text-body text-foreground"
|
|
434
|
-
aria-hidden="true"
|
|
435
|
-
>
|
|
436
|
-
{suffix}
|
|
437
|
-
</span>
|
|
438
|
-
</span>
|
|
439
|
-
{:else}
|
|
440
|
-
<span class="number-controls-digit-sizer relative inline-block w-fit max-w-full">
|
|
441
|
-
<span class="invisible block whitespace-pre text-body tabular-nums" aria-hidden="true">
|
|
442
|
-
{inputValue || '0'}
|
|
443
|
-
</span>
|
|
444
|
-
<Input
|
|
445
|
-
id={inputId}
|
|
446
|
-
type="text"
|
|
447
|
-
bind:ref={numberInputEl}
|
|
448
|
-
value={inputValue}
|
|
449
|
-
onfocus={onFocus}
|
|
450
|
-
oninput={handleInput}
|
|
451
|
-
onblur={handleBlur}
|
|
452
|
-
onkeydown={handleKeyDown}
|
|
453
|
-
onmousedown={handleInputMouseDown}
|
|
454
|
-
readonly={isLocked}
|
|
455
|
-
{disabled}
|
|
456
|
-
class="number-controls-input absolute inset-0 h-full w-full min-w-0 border-0 bg-transparent px-0 text-body text-foreground shadow-none hover:bg-transparent focus-visible:ring-0 focus-visible:ring-offset-0 {customInputClass}"
|
|
457
|
-
/>
|
|
458
|
-
</span>
|
|
459
|
-
{/if}
|
|
460
|
-
</label>
|
|
461
|
-
|
|
462
|
-
<div class="flex shrink-0 items-center gap-0">
|
|
463
|
-
<StepperButton
|
|
464
|
-
kind="minus"
|
|
465
|
-
label={$t('editor.stepper.decrease')}
|
|
466
|
-
disabled={isDisabled || isAtMin}
|
|
467
|
-
data-pressed={pressedStepper === 'decrement' ? 'true' : undefined}
|
|
468
|
-
onmousedown={(e: MouseEvent) => startAutoRepeat('decrement', e)}
|
|
469
|
-
onmouseup={stopAutoRepeat}
|
|
470
|
-
onmouseleave={stopAutoRepeat}
|
|
471
|
-
onclick={(e: MouseEvent) => handleStepperClick('decrement', e)}
|
|
472
|
-
/>
|
|
473
|
-
<StepperButton
|
|
474
|
-
kind="plus"
|
|
475
|
-
label={$t('editor.stepper.increase')}
|
|
476
|
-
disabled={isDisabled || isAtMax}
|
|
477
|
-
data-pressed={pressedStepper === 'increment' ? 'true' : undefined}
|
|
478
|
-
onmousedown={(e: MouseEvent) => startAutoRepeat('increment', e)}
|
|
479
|
-
onmouseup={stopAutoRepeat}
|
|
480
|
-
onmouseleave={stopAutoRepeat}
|
|
481
|
-
onclick={(e: MouseEvent) => handleStepperClick('increment', e)}
|
|
482
|
-
/>
|
|
483
|
-
</div>
|
|
484
|
-
</div>
|
|
485
|
-
|
|
486
|
-
<style>
|
|
487
|
-
:global(.number-controls-input) {
|
|
488
|
-
flex: none;
|
|
489
|
-
width: 100%;
|
|
490
|
-
min-width: 0;
|
|
491
|
-
max-width: 100%;
|
|
492
|
-
font-variant-numeric: tabular-nums;
|
|
493
|
-
text-align: start;
|
|
494
|
-
appearance: textfield;
|
|
495
|
-
-moz-appearance: textfield;
|
|
496
|
-
padding-inline-end: 0 !important;
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
:global(.number-controls-input::-webkit-outer-spin-button),
|
|
500
|
-
:global(.number-controls-input::-webkit-inner-spin-button) {
|
|
501
|
-
-webkit-appearance: none;
|
|
502
|
-
appearance: none;
|
|
503
|
-
margin: 0;
|
|
504
|
-
}
|
|
505
|
-
</style>
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
2
|
-
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
3
|
-
$$bindings?: Bindings;
|
|
4
|
-
} & Exports;
|
|
5
|
-
(internal: unknown, props: Props & {
|
|
6
|
-
$$events?: Events;
|
|
7
|
-
$$slots?: Slots;
|
|
8
|
-
}): Exports & {
|
|
9
|
-
$set?: any;
|
|
10
|
-
$on?: any;
|
|
11
|
-
};
|
|
12
|
-
z_$$bindings?: Bindings;
|
|
13
|
-
}
|
|
14
|
-
declare const NumberControls: $$__sveltets_2_IsomorphicComponent<{
|
|
15
|
-
value: number;
|
|
16
|
-
onChange: (newValue: number) => void;
|
|
17
|
-
min: number;
|
|
18
|
-
max: number;
|
|
19
|
-
step?: number;
|
|
20
|
-
isLocked?: boolean;
|
|
21
|
-
onFocus?: () => void;
|
|
22
|
-
customInputClass?: string;
|
|
23
|
-
wrapAround?: boolean;
|
|
24
|
-
suffix?: string;
|
|
25
|
-
/** Extra classes on the outer control surface (default full width of the control column). */ class?: string;
|
|
26
|
-
disabled?: boolean;
|
|
27
|
-
/**
|
|
28
|
-
* Padding at the end of the accent surface, after the steppers (Figma IC Number vs IC Angle field).
|
|
29
|
-
* The padding at the start is not on the surface: it is inside the text hit area, so the hit area reaches the edge.
|
|
30
|
-
*/ surfacePaddingClass?: string;
|
|
31
|
-
/** Padding at the start of the text hit area: it keeps the value 12px in from the edge (Figma IC Number: the value is at x=12). */ inputPaddingClass?: string;
|
|
32
|
-
/** @deprecated use `class` — kept for Angle layout width. */ width?: string | undefined;
|
|
33
|
-
}, {
|
|
34
|
-
[evt: string]: CustomEvent<any>;
|
|
35
|
-
}, {}, {}, string>;
|
|
36
|
-
type NumberControls = InstanceType<typeof NumberControls>;
|
|
37
|
-
export default NumberControls;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The arithmetic of the number stepper (`NumberControls.svelte`), kept apart from the component so Node can test it.
|
|
3
|
-
*/
|
|
4
|
-
export interface NumberStepLimits {
|
|
5
|
-
/** The lowest value; no limit when left out. */
|
|
6
|
-
min?: number;
|
|
7
|
-
/** The highest value; no limit when left out. */
|
|
8
|
-
max?: number;
|
|
9
|
-
/** An angle: a step past 360 comes back round to 0, and a step below 0 to 360, instead of stopping at a limit. */
|
|
10
|
-
wrapAround?: boolean;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* The value after one press of a stepper button (or one arrow key): `currentValue` moved by `adjustment`, then kept inside
|
|
14
|
-
* the limits, or brought back round for an angle. At a limit the result is `currentValue` itself, which tells the caller
|
|
15
|
-
* that there is nothing to apply (and nothing to repeat).
|
|
16
|
-
*/
|
|
17
|
-
export declare function steppedNumber(currentValue: number, adjustment: number, { min, max, wrapAround }?: NumberStepLimits): number;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The arithmetic of the number stepper (`NumberControls.svelte`), kept apart from the component so Node can test it.
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* The value after one press of a stepper button (or one arrow key): `currentValue` moved by `adjustment`, then kept inside
|
|
6
|
-
* the limits, or brought back round for an angle. At a limit the result is `currentValue` itself, which tells the caller
|
|
7
|
-
* that there is nothing to apply (and nothing to repeat).
|
|
8
|
-
*/
|
|
9
|
-
export function steppedNumber(currentValue, adjustment, { min, max, wrapAround = false } = {}) {
|
|
10
|
-
let steppedValue = currentValue + adjustment;
|
|
11
|
-
if (wrapAround) {
|
|
12
|
-
if (steppedValue >= 360)
|
|
13
|
-
steppedValue -= 360;
|
|
14
|
-
if (steppedValue < 0)
|
|
15
|
-
steppedValue += 360;
|
|
16
|
-
return steppedValue;
|
|
17
|
-
}
|
|
18
|
-
if (min !== undefined && steppedValue < min)
|
|
19
|
-
steppedValue = min;
|
|
20
|
-
if (max !== undefined && steppedValue > max)
|
|
21
|
-
steppedValue = max;
|
|
22
|
-
return steppedValue;
|
|
23
|
-
}
|