1
+ /*
2
+ THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
3
+ if you want to view the source, please visit the github repository of this plugin
4
+ */
5
+
6
+ var __defProp = Object . defineProperty ;
7
+ var __getOwnPropDesc = Object . getOwnPropertyDescriptor ;
8
+ var __getOwnPropNames = Object . getOwnPropertyNames ;
9
+ var __hasOwnProp = Object . prototype . hasOwnProperty ;
10
+ var __export = ( target , all ) => {
11
+ for ( var name in all )
12
+ __defProp ( target , name , { get : all [ name ] , enumerable : true } ) ;
13
+ } ;
14
+ var __copyProps = ( to , from , except , desc ) => {
15
+ if ( from && typeof from === "object" || typeof from === "function" ) {
16
+ for ( let key of __getOwnPropNames ( from ) )
17
+ if ( ! __hasOwnProp . call ( to , key ) && key !== except )
18
+ __defProp ( to , key , { get : ( ) => from [ key ] , enumerable : ! ( desc = __getOwnPropDesc ( from , key ) ) || desc . enumerable } ) ;
19
+ }
20
+ return to ;
21
+ } ;
22
+ var __toCommonJS = ( mod ) => __copyProps ( __defProp ( { } , "__esModule" , { value : true } ) , mod ) ;
23
+
24
+ // src/main.mts
25
+ var main_exports = { } ;
26
+ __export ( main_exports , {
27
+ default : ( ) => ChangeCasePlugin
28
+ } ) ;
29
+ module . exports = __toCommonJS ( main_exports ) ;
30
+ var import_obsidian = require ( "obsidian" ) ;
31
+
32
+ // node_modules/.pnpm/[email protected] /node_modules/change-case/dist/index.js
33
+ var SPLIT_LOWER_UPPER_RE = / ( [ \p{ Ll} \d ] ) ( \p{ Lu} ) / gu;
34
+ var SPLIT_UPPER_UPPER_RE = / ( \p{ Lu} ) ( [ \p{ Lu} ] [ \p{ Ll} ] ) / gu;
35
+ var SPLIT_SEPARATE_NUMBER_RE = / ( \d ) \p{ Ll} | ( \p{ L} ) \d / u;
36
+ var DEFAULT_STRIP_REGEXP = / [ ^ \p{ L} \d ] + / giu;
37
+ var SPLIT_REPLACE_VALUE = "$1\0$2" ;
38
+ var DEFAULT_PREFIX_SUFFIX_CHARACTERS = "" ;
39
+ function split ( value ) {
40
+ let result = value . trim ( ) ;
41
+ result = result . replace ( SPLIT_LOWER_UPPER_RE , SPLIT_REPLACE_VALUE ) . replace ( SPLIT_UPPER_UPPER_RE , SPLIT_REPLACE_VALUE ) ;
42
+ result = result . replace ( DEFAULT_STRIP_REGEXP , "\0" ) ;
43
+ let start = 0 ;
44
+ let end = result . length ;
45
+ while ( result . charAt ( start ) === "\0" )
46
+ start ++ ;
47
+ if ( start === end )
48
+ return [ ] ;
49
+ while ( result . charAt ( end - 1 ) === "\0" )
50
+ end -- ;
51
+ return result . slice ( start , end ) . split ( / \0 / g) ;
52
+ }
53
+ function splitSeparateNumbers ( value ) {
54
+ var _a ;
55
+ const words = split ( value ) ;
56
+ for ( let i = 0 ; i < words . length ; i ++ ) {
57
+ const word = words [ i ] ;
58
+ const match = SPLIT_SEPARATE_NUMBER_RE . exec ( word ) ;
59
+ if ( match ) {
60
+ const offset = match . index + ( ( _a = match [ 1 ] ) != null ? _a : match [ 2 ] ) . length ;
61
+ words . splice ( i , 1 , word . slice ( 0 , offset ) , word . slice ( offset ) ) ;
62
+ }
63
+ }
64
+ return words ;
65
+ }
66
+ function noCase ( input , options ) {
67
+ var _a ;
68
+ const [ prefix , words , suffix ] = splitPrefixSuffix ( input , options ) ;
69
+ return prefix + words . map ( lowerFactory ( options == null ? void 0 : options . locale ) ) . join ( ( _a = options == null ? void 0 : options . delimiter ) != null ? _a : " " ) + suffix ;
70
+ }
71
+ function camelCase ( input , options ) {
72
+ var _a ;
73
+ const [ prefix , words , suffix ] = splitPrefixSuffix ( input , options ) ;
74
+ const lower = lowerFactory ( options == null ? void 0 : options . locale ) ;
75
+ const upper = upperFactory ( options == null ? void 0 : options . locale ) ;
76
+ const transform = ( options == null ? void 0 : options . mergeAmbiguousCharacters ) ? capitalCaseTransformFactory ( lower , upper ) : pascalCaseTransformFactory ( lower , upper ) ;
77
+ return prefix + words . map ( ( word , index ) => {
78
+ if ( index === 0 )
79
+ return lower ( word ) ;
80
+ return transform ( word , index ) ;
81
+ } ) . join ( ( _a = options == null ? void 0 : options . delimiter ) != null ? _a : "" ) + suffix ;
82
+ }
83
+ function pascalCase ( input , options ) {
84
+ var _a ;
85
+ const [ prefix , words , suffix ] = splitPrefixSuffix ( input , options ) ;
86
+ const lower = lowerFactory ( options == null ? void 0 : options . locale ) ;
87
+ const upper = upperFactory ( options == null ? void 0 : options . locale ) ;
88
+ const transform = ( options == null ? void 0 : options . mergeAmbiguousCharacters ) ? capitalCaseTransformFactory ( lower , upper ) : pascalCaseTransformFactory ( lower , upper ) ;
89
+ return prefix + words . map ( transform ) . join ( ( _a = options == null ? void 0 : options . delimiter ) != null ? _a : "" ) + suffix ;
90
+ }
91
+ function pascalSnakeCase ( input , options ) {
92
+ return capitalCase ( input , { delimiter : "_" , ...options } ) ;
93
+ }
94
+ function capitalCase ( input , options ) {
95
+ var _a ;
96
+ const [ prefix , words , suffix ] = splitPrefixSuffix ( input , options ) ;
97
+ const lower = lowerFactory ( options == null ? void 0 : options . locale ) ;
98
+ const upper = upperFactory ( options == null ? void 0 : options . locale ) ;
99
+ return prefix + words . map ( capitalCaseTransformFactory ( lower , upper ) ) . join ( ( _a = options == null ? void 0 : options . delimiter ) != null ? _a : " " ) + suffix ;
100
+ }
101
+ function constantCase ( input , options ) {
102
+ var _a ;
103
+ const [ prefix , words , suffix ] = splitPrefixSuffix ( input , options ) ;
104
+ return prefix + words . map ( upperFactory ( options == null ? void 0 : options . locale ) ) . join ( ( _a = options == null ? void 0 : options . delimiter ) != null ? _a : "_" ) + suffix ;
105
+ }
106
+ function dotCase ( input , options ) {
107
+ return noCase ( input , { delimiter : "." , ...options } ) ;
108
+ }
109
+ function kebabCase ( input , options ) {
110
+ return noCase ( input , { delimiter : "-" , ...options } ) ;
111
+ }
112
+ function pathCase ( input , options ) {
113
+ return noCase ( input , { delimiter : "/" , ...options } ) ;
114
+ }
115
+ function sentenceCase ( input , options ) {
116
+ var _a ;
117
+ const [ prefix , words , suffix ] = splitPrefixSuffix ( input , options ) ;
118
+ const lower = lowerFactory ( options == null ? void 0 : options . locale ) ;
119
+ const upper = upperFactory ( options == null ? void 0 : options . locale ) ;
120
+ const transform = capitalCaseTransformFactory ( lower , upper ) ;
121
+ return prefix + words . map ( ( word , index ) => {
122
+ if ( index === 0 )
123
+ return transform ( word ) ;
124
+ return lower ( word ) ;
125
+ } ) . join ( ( _a = options == null ? void 0 : options . delimiter ) != null ? _a : " " ) + suffix ;
126
+ }
127
+ function snakeCase ( input , options ) {
128
+ return noCase ( input , { delimiter : "_" , ...options } ) ;
129
+ }
130
+ function trainCase ( input , options ) {
131
+ return capitalCase ( input , { delimiter : "-" , ...options } ) ;
132
+ }
133
+ function lowerFactory ( locale ) {
134
+ return locale === false ? ( input ) => input . toLowerCase ( ) : ( input ) => input . toLocaleLowerCase ( locale ) ;
135
+ }
136
+ function upperFactory ( locale ) {
137
+ return locale === false ? ( input ) => input . toUpperCase ( ) : ( input ) => input . toLocaleUpperCase ( locale ) ;
138
+ }
139
+ function capitalCaseTransformFactory ( lower , upper ) {
140
+ return ( word ) => `${ upper ( word [ 0 ] ) } ${ lower ( word . slice ( 1 ) ) } ` ;
141
+ }
142
+ function pascalCaseTransformFactory ( lower , upper ) {
143
+ return ( word , index ) => {
144
+ const char0 = word [ 0 ] ;
145
+ const initial = index > 0 && char0 >= "0" && char0 <= "9" ? "_" + char0 : upper ( char0 ) ;
146
+ return initial + lower ( word . slice ( 1 ) ) ;
147
+ } ;
148
+ }
149
+ function splitPrefixSuffix ( input , options = { } ) {
150
+ var _a , _b , _c ;
151
+ const splitFn = ( _a = options . split ) != null ? _a : options . separateNumbers ? splitSeparateNumbers : split ;
152
+ const prefixCharacters = ( _b = options . prefixCharacters ) != null ? _b : DEFAULT_PREFIX_SUFFIX_CHARACTERS ;
153
+ const suffixCharacters = ( _c = options . suffixCharacters ) != null ? _c : DEFAULT_PREFIX_SUFFIX_CHARACTERS ;
154
+ let prefixIndex = 0 ;
155
+ let suffixIndex = input . length ;
156
+ while ( prefixIndex < input . length ) {
157
+ const char = input . charAt ( prefixIndex ) ;
158
+ if ( ! prefixCharacters . includes ( char ) )
159
+ break ;
160
+ prefixIndex ++ ;
161
+ }
162
+ while ( suffixIndex > prefixIndex ) {
163
+ const index = suffixIndex - 1 ;
164
+ const char = input . charAt ( index ) ;
165
+ if ( ! suffixCharacters . includes ( char ) )
166
+ break ;
167
+ suffixIndex = index ;
168
+ }
169
+ return [
170
+ input . slice ( 0 , prefixIndex ) ,
171
+ splitFn ( input . slice ( prefixIndex , suffixIndex ) ) ,
172
+ input . slice ( suffixIndex )
173
+ ] ;
174
+ }
175
+
176
+ // src/commands.mts
177
+ var wrap = ( id , fn ) => ( {
178
+ id,
179
+ name : fn ( id + " case" , { locale : false } ) ,
180
+ fn
181
+ } ) ;
182
+ var commands = [
183
+ wrap ( "lower" , ( s , o ) => s . toLocaleLowerCase ( ( o == null ? void 0 : o . locale ) || void 0 ) ) ,
184
+ wrap ( "upper" , ( s , o ) => s . toLocaleUpperCase ( ( o == null ? void 0 : o . locale ) || void 0 ) ) ,
185
+ wrap ( "camel" , camelCase ) ,
186
+ wrap ( "capital" , capitalCase ) ,
187
+ wrap ( "constant" , constantCase ) ,
188
+ wrap ( "dot" , dotCase ) ,
189
+ wrap ( "kebab" , kebabCase ) ,
190
+ wrap ( "no" , noCase ) ,
191
+ wrap ( "pascal" , pascalCase ) ,
192
+ wrap ( "pascalSnake" , pascalSnakeCase ) ,
193
+ wrap ( "path" , pathCase ) ,
194
+ wrap ( "sentence" , sentenceCase ) ,
195
+ wrap ( "snake" , snakeCase ) ,
196
+ wrap ( "train" , trainCase )
197
+ ] ;
198
+
199
+ // src/language.mts
200
+ var OBSIDIAN_LANG ;
201
+ try {
202
+ OBSIDIAN_LANG = self . localStorage . getItem ( "language" ) ;
203
+ } catch ( e ) {
204
+ }
205
+ var getLang = ( ) => {
206
+ let lang = OBSIDIAN_LANG ;
207
+ try {
208
+ lang || ( lang = self . navigator . language ) ;
209
+ } catch ( e ) {
210
+ }
211
+ return lang || void 0 ;
212
+ } ;
213
+
214
+ // src/main.mts
215
+ var normalizeSelection = ( {
216
+ anchor,
217
+ head
218
+ } ) => anchor . line < head . line ? [ anchor , head ] : anchor . line > head . line ? [ head , anchor ] : anchor . ch < head . ch ? [ anchor , head ] : [ head , anchor ] ;
219
+ var replaceAllSelections = ( editor , fn ) => {
220
+ if ( editor . somethingSelected ( ) ) {
221
+ const locale = getLang ( ) ;
222
+ editor . transaction ( {
223
+ changes : editor . listSelections ( ) . map ( ( selection ) => {
224
+ const [ from , to ] = normalizeSelection ( selection ) ;
225
+ const str = editor . getRange ( from , to ) . normalize ( ) ;
226
+ return { from, to, text : fn ( str , { locale } ) } ;
227
+ } )
228
+ } ) ;
229
+ }
230
+ } ;
231
+ var SelectCaseModal = class extends import_obsidian . FuzzySuggestModal {
232
+ constructor ( app , editor ) {
233
+ super ( app ) ;
234
+ this . _editor = editor ;
235
+ }
236
+ getItems ( ) {
237
+ return commands ;
238
+ }
239
+ getItemText ( cmd ) {
240
+ return cmd . name ;
241
+ }
242
+ onChooseItem ( cmd ) {
243
+ replaceAllSelections ( this . _editor , cmd . fn ) ;
244
+ }
245
+ } ;
246
+ var ChangeCasePlugin = class extends import_obsidian . Plugin {
247
+ async onload ( ) {
248
+ this . addCommand ( {
249
+ id : "select" ,
250
+ name : "Select from list" ,
251
+ icon : "case-sensitive" ,
252
+ editorCallback : ( editor ) => {
253
+ const modal = new SelectCaseModal ( this . app , editor ) ;
254
+ modal . setPlaceholder ( "Choose a format for the selection" ) ;
255
+ modal . open ( ) ;
256
+ }
257
+ } ) ;
258
+ for ( const { id, name, fn } of commands ) {
259
+ this . addCommand ( {
260
+ id,
261
+ name,
262
+ icon : "case-sensitive" ,
263
+ editorCallback : ( editor ) => {
264
+ replaceAllSelections ( editor , fn ) ;
265
+ }
266
+ } ) ;
267
+ }
268
+ }
269
+ } ;
270
+
271
+ /* nosourcemap */
0 commit comments