@sdeck/plugin 0.2.0 → 0.3.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.
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +157 -1
- package/dist/index.js.map +9 -8
- package/dist/permissions.d.ts +1 -1
- package/dist/permissions.d.ts.map +1 -1
- package/dist/plugin.d.ts +45 -0
- package/dist/plugin.d.ts.map +1 -1
- package/dist/settings.d.ts +24 -3
- package/dist/settings.d.ts.map +1 -1
- package/dist/text.d.ts +44 -0
- package/dist/text.d.ts.map +1 -0
- package/package.json +4 -4
- package/src/index.ts +12 -0
- package/src/permissions.ts +6 -0
- package/src/plugin.ts +47 -0
- package/src/settings.ts +46 -6
- package/src/text.ts +192 -0
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,8 @@ export { type HostBridge, HostBridgeContext, useExpression, useHostState, useIma
|
|
|
8
8
|
export { type ConnectionOptions, type ConnectionState, type Link, ManagedConnection, PermanentError, } from "./connection.ts";
|
|
9
9
|
export { HOST_MODULES, type ManifestResult, PLUGIN_KEYWORD, type PluginManifest, parseManifest, SUPPORTED_API_VERSIONS, } from "./manifest.ts";
|
|
10
10
|
export { PERMISSION_TEXTS, PERMISSIONS, type Permission, PermissionError, type PermissionText, } from "./permissions.ts";
|
|
11
|
-
export { type Action, type ActionDef, type ActionProps, checkPlugin, type Deactivate, type DeckControls, defineAction, definePlugin, defineTrigger, type Onboarding, type OnboardingStep, type OptionSource, PLUGIN_API_VERSION, type PluginCommand, type PluginContext, type PluginDef, pluginNamespace, type RunContext, type RunFn, type RunOutcome, type RunResult, type SlotKind, type StarterPage, type StateDef, type StatusLevel, type Trigger, type TriggerContext, type TriggerDef, } from "./plugin.ts";
|
|
12
|
-
export { type BooleanField, behaviorFields, type ColorField, checkSchema, defaultValue, type FieldValue, type GroupsField, type ImageField, type InferSettings, isFieldVisible, type NumberField, type OptionGroup, optionGroups, type PageField, resolveSettings, type SecretField, type SelectField, type SelectOption, type SettingField, type SettingsSchema, type SettingValue, type TextField, } from "./settings.ts";
|
|
11
|
+
export { type Action, type ActionDef, type ActionProps, checkPlugin, type Deactivate, type DeckControls, defineAction, definePlugin, defineTrigger, type Onboarding, type OnboardingStep, type OptionSource, type Overlay, type OverlayProps, PLUGIN_API_VERSION, type PluginCommand, type PluginContext, type PluginDef, pluginNamespace, type RunContext, type RunFn, type RunOutcome, type RunResult, type SlotKind, type StarterPage, type StateDef, type StatusLevel, type Trigger, type TriggerContext, type TriggerDef, } from "./plugin.ts";
|
|
12
|
+
export { type BooleanField, behaviorFields, type ColorField, checkSchema, defaultValue, type FieldValue, type GroupsField, type ImageField, type InferSettings, isFieldVisible, liveSettings, type NumberField, type OptionGroup, optionGroups, type PageField, resolveSettings, type SecretField, type SelectField, type SelectOption, type SettingField, type SettingsSchema, type SettingValue, type SlotsField, slotList, type TextField, } from "./settings.ts";
|
|
13
13
|
export { Shared } from "./shared.ts";
|
|
14
|
+
export { fitText, layoutText, type TextLayout, type TextLayoutOptions, type TextRow, } from "./text.ts";
|
|
14
15
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,cAAc,YAAY,CAAC;AAC3B,OAAO,EACL,KAAK,UAAU,EACf,iBAAiB,EACjB,aAAa,EACb,YAAY,EACZ,QAAQ,EACR,YAAY,EACZ,WAAW,EACX,WAAW,GACZ,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,IAAI,EACT,iBAAiB,EACjB,cAAc,GACf,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,YAAY,EACZ,KAAK,cAAc,EACnB,cAAc,EACd,KAAK,cAAc,EACnB,aAAa,EACb,sBAAsB,GACvB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,gBAAgB,EAChB,WAAW,EACX,KAAK,UAAU,EACf,eAAe,EACf,KAAK,cAAc,GACpB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,KAAK,MAAM,EACX,KAAK,SAAS,EACd,KAAK,WAAW,EAChB,WAAW,EACX,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,KAAK,UAAU,EACf,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,kBAAkB,EAClB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,SAAS,EACd,eAAe,EACf,KAAK,UAAU,EACf,KAAK,KAAK,EACV,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,QAAQ,EACb,KAAK,WAAW,EAChB,KAAK,QAAQ,EACb,KAAK,WAAW,EAChB,KAAK,OAAO,EACZ,KAAK,cAAc,EACnB,KAAK,UAAU,GAChB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,KAAK,YAAY,EACjB,cAAc,EACd,KAAK,UAAU,EACf,WAAW,EACX,YAAY,EACZ,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,cAAc,EACd,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,YAAY,EACZ,KAAK,SAAS,EACd,eAAe,EACf,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,SAAS,GACf,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,cAAc,YAAY,CAAC;AAC3B,OAAO,EACL,KAAK,UAAU,EACf,iBAAiB,EACjB,aAAa,EACb,YAAY,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ChB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,QAAQ,EACR,KAAK,SAAS,GACf,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EACL,OAAO,EACP,UAAU,EACV,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,OAAO,GACb,MAAM,WAAW,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -307,6 +307,11 @@ var PERMISSION_TEXTS = {
|
|
|
307
307
|
action: "run other plugins' actions",
|
|
308
308
|
powerful: true
|
|
309
309
|
},
|
|
310
|
+
overlay: {
|
|
311
|
+
name: "Draw over buttons",
|
|
312
|
+
description: "Show images and text on top of any of your buttons.",
|
|
313
|
+
action: "draw over your buttons"
|
|
314
|
+
},
|
|
310
315
|
native: {
|
|
311
316
|
name: "Native code",
|
|
312
317
|
description: "Load compiled code, which sdeck cannot limit in any way.",
|
|
@@ -338,6 +343,7 @@ function defaultValue(field) {
|
|
|
338
343
|
case "color":
|
|
339
344
|
return field.default ?? "#000000";
|
|
340
345
|
case "groups":
|
|
346
|
+
case "slots":
|
|
341
347
|
return field.default ?? [];
|
|
342
348
|
case "select":
|
|
343
349
|
return field.default ?? field.options[0]?.value ?? "";
|
|
@@ -363,6 +369,12 @@ function optionGroups(value) {
|
|
|
363
369
|
];
|
|
364
370
|
});
|
|
365
371
|
}
|
|
372
|
+
var SLOT = /^(window|(key|sensor):\d{1,3})$/;
|
|
373
|
+
function slotList(value) {
|
|
374
|
+
if (!Array.isArray(value))
|
|
375
|
+
return;
|
|
376
|
+
return [...new Set(value.filter((v) => typeof v === "string" && SLOT.test(v)))];
|
|
377
|
+
}
|
|
366
378
|
function coerce(field, value) {
|
|
367
379
|
switch (field.type) {
|
|
368
380
|
case "number": {
|
|
@@ -377,6 +389,8 @@ function coerce(field, value) {
|
|
|
377
389
|
return typeof value === "string" && HEX.test(value) ? value.toLowerCase() : defaultValue(field);
|
|
378
390
|
case "groups":
|
|
379
391
|
return optionGroups(value) ?? defaultValue(field);
|
|
392
|
+
case "slots":
|
|
393
|
+
return slotList(value) ?? defaultValue(field);
|
|
380
394
|
case "select":
|
|
381
395
|
if (typeof value !== "string")
|
|
382
396
|
return defaultValue(field);
|
|
@@ -396,6 +410,9 @@ function resolveSettings(schema, stored) {
|
|
|
396
410
|
function behaviorFields(schema) {
|
|
397
411
|
return Object.fromEntries(Object.entries(schema).filter(([, field]) => !field.appearance));
|
|
398
412
|
}
|
|
413
|
+
function liveSettings(schema) {
|
|
414
|
+
return Object.entries(schema).flatMap(([key, field]) => ("live" in field) && field.live ? [key] : []);
|
|
415
|
+
}
|
|
399
416
|
function isFieldVisible(field, settings) {
|
|
400
417
|
if (!field.visibleIf)
|
|
401
418
|
return true;
|
|
@@ -413,6 +430,7 @@ function checkSchema(schema, sources = {}) {
|
|
|
413
430
|
"color",
|
|
414
431
|
"select",
|
|
415
432
|
"page",
|
|
433
|
+
"slots",
|
|
416
434
|
"image",
|
|
417
435
|
"groups",
|
|
418
436
|
"secret"
|
|
@@ -739,6 +757,140 @@ class Shared {
|
|
|
739
757
|
};
|
|
740
758
|
}
|
|
741
759
|
}
|
|
760
|
+
// src/text.ts
|
|
761
|
+
function emWidth(char) {
|
|
762
|
+
if (/[ᄀ-ᇿ⺀-鿿가-豈--⦆]/.test(char))
|
|
763
|
+
return 1;
|
|
764
|
+
if (/\p{Extended_Pictographic}/u.test(char))
|
|
765
|
+
return 1.25;
|
|
766
|
+
if (/\p{Mark}/u.test(char))
|
|
767
|
+
return 0;
|
|
768
|
+
if (char === " ")
|
|
769
|
+
return 0.27;
|
|
770
|
+
if (/[ijl.,:;'|!’‘·]/.test(char))
|
|
771
|
+
return 0.29;
|
|
772
|
+
if (/[Ifrt()[\]{}/\\"“”-]/.test(char))
|
|
773
|
+
return 0.41;
|
|
774
|
+
if (/[mwMW@%—]/.test(char))
|
|
775
|
+
return 0.93;
|
|
776
|
+
if (/[\p{Lu}\d]/u.test(char))
|
|
777
|
+
return 0.69;
|
|
778
|
+
return 0.6;
|
|
779
|
+
}
|
|
780
|
+
var textWidth = (text) => [...text].reduce((sum, c) => sum + emWidth(c), 0);
|
|
781
|
+
var CJK = "\\u2e80-\\u9fff\\uac00-\\ud7af\\uff00-\\uff60";
|
|
782
|
+
var TOKENS = new RegExp(`\\n|[^\\S\\n]+|[${CJK}]|[^\\s${CJK}]+`, "g");
|
|
783
|
+
function wrap(text, room) {
|
|
784
|
+
const lines = [];
|
|
785
|
+
let line;
|
|
786
|
+
let used = 0;
|
|
787
|
+
for (const match of text.matchAll(TOKENS)) {
|
|
788
|
+
const [token] = match;
|
|
789
|
+
const start = match.index;
|
|
790
|
+
const end = start + token.length;
|
|
791
|
+
if (token === `
|
|
792
|
+
`) {
|
|
793
|
+
lines.push(line ?? { start, end: start });
|
|
794
|
+
line = undefined;
|
|
795
|
+
continue;
|
|
796
|
+
}
|
|
797
|
+
const width = textWidth(token);
|
|
798
|
+
if (token.trim() === "") {
|
|
799
|
+
used += width;
|
|
800
|
+
continue;
|
|
801
|
+
}
|
|
802
|
+
if (line && used + width > room(lines.length)) {
|
|
803
|
+
lines.push(line);
|
|
804
|
+
line = undefined;
|
|
805
|
+
}
|
|
806
|
+
if (line) {
|
|
807
|
+
line.end = end;
|
|
808
|
+
used += width;
|
|
809
|
+
} else {
|
|
810
|
+
if (width > room(lines.length))
|
|
811
|
+
return;
|
|
812
|
+
line = { start, end };
|
|
813
|
+
used = width;
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
if (line)
|
|
817
|
+
lines.push(line);
|
|
818
|
+
return lines;
|
|
819
|
+
}
|
|
820
|
+
function layoutText(text, options) {
|
|
821
|
+
const { width, rows, min = 8, lineHeight = 1.2, position = "middle" } = options;
|
|
822
|
+
const tallest = Math.max(0, ...rows.map((r) => r.height));
|
|
823
|
+
const max = Math.max(min, Math.floor(options.max ?? tallest / lineHeight));
|
|
824
|
+
const slots = (size) => rows.flatMap((row, index) => {
|
|
825
|
+
const count = Math.floor((row.height + 0.01) / (size * lineHeight));
|
|
826
|
+
return Array.from({ length: count }, () => ({
|
|
827
|
+
index,
|
|
828
|
+
left: row.left ?? 0,
|
|
829
|
+
width: row.width ?? width
|
|
830
|
+
}));
|
|
831
|
+
});
|
|
832
|
+
const fill = (size, skip = 0) => {
|
|
833
|
+
const places = slots(size).slice(skip);
|
|
834
|
+
const lines = wrap(text, (i) => (places[i]?.width ?? 0) / size);
|
|
835
|
+
return lines && lines.length <= places.length ? lines : undefined;
|
|
836
|
+
};
|
|
837
|
+
let size = max;
|
|
838
|
+
if (!fill(max)) {
|
|
839
|
+
size = min;
|
|
840
|
+
for (let high = max;high - size > 1; ) {
|
|
841
|
+
const middle = Math.floor((size + high) / 2);
|
|
842
|
+
if (fill(middle))
|
|
843
|
+
size = middle;
|
|
844
|
+
else
|
|
845
|
+
high = middle;
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
const places = slots(size);
|
|
849
|
+
const last = rows.at(-1);
|
|
850
|
+
if (last && rows.length > 1 && places.length === 0) {
|
|
851
|
+
const top = rows[0]?.top ?? 0;
|
|
852
|
+
const whole = { top, height: last.top + last.height - top };
|
|
853
|
+
return layoutText(text, { ...options, rows: [whole] });
|
|
854
|
+
}
|
|
855
|
+
let skip = 0;
|
|
856
|
+
let lines = fill(size);
|
|
857
|
+
if (lines && position !== "top") {
|
|
858
|
+
const spare = places.length - lines.length;
|
|
859
|
+
for (let wanted = position === "bottom" ? spare : Math.floor(spare / 2);wanted > 0; wanted--) {
|
|
860
|
+
const moved = fill(size, wanted);
|
|
861
|
+
if (!moved)
|
|
862
|
+
continue;
|
|
863
|
+
lines = moved;
|
|
864
|
+
skip = wanted;
|
|
865
|
+
break;
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
lines ??= wrap(text, (i) => (places[i]?.width ?? width) / size) ?? wrap(text, () => Infinity) ?? [];
|
|
869
|
+
const height = size * lineHeight;
|
|
870
|
+
const used = places.slice(skip, skip + lines.length);
|
|
871
|
+
const placed = [];
|
|
872
|
+
for (const [i, line] of lines.entries()) {
|
|
873
|
+
const place = used[i];
|
|
874
|
+
const row = place && rows[place.index];
|
|
875
|
+
const before = placed.at(-1);
|
|
876
|
+
let top = before ? before.top + height : rows[0]?.top ?? 0;
|
|
877
|
+
if (row && used[i - 1]?.index !== place.index) {
|
|
878
|
+
const free = row.height - used.filter((p) => p.index === place.index).length * height;
|
|
879
|
+
top = row.top + (position === "top" ? 0 : position === "bottom" ? free : free / 2);
|
|
880
|
+
}
|
|
881
|
+
placed.push({
|
|
882
|
+
...line,
|
|
883
|
+
text: text.slice(line.start, line.end),
|
|
884
|
+
top,
|
|
885
|
+
left: place?.left ?? 0,
|
|
886
|
+
width: place?.width ?? width
|
|
887
|
+
});
|
|
888
|
+
}
|
|
889
|
+
return { size, lines: placed };
|
|
890
|
+
}
|
|
891
|
+
function fitText(text, { height, ...options }) {
|
|
892
|
+
return layoutText(text, { ...options, rows: [{ top: 0, height }] }).size;
|
|
893
|
+
}
|
|
742
894
|
export {
|
|
743
895
|
HOST_MODULES,
|
|
744
896
|
HostBridgeContext,
|
|
@@ -758,11 +910,15 @@ export {
|
|
|
758
910
|
defineAction,
|
|
759
911
|
definePlugin,
|
|
760
912
|
defineTrigger,
|
|
913
|
+
fitText,
|
|
761
914
|
isFieldVisible,
|
|
915
|
+
layoutText,
|
|
916
|
+
liveSettings,
|
|
762
917
|
optionGroups,
|
|
763
918
|
parseManifest,
|
|
764
919
|
pluginNamespace,
|
|
765
920
|
resolveSettings,
|
|
921
|
+
slotList,
|
|
766
922
|
useExpression,
|
|
767
923
|
useHostState,
|
|
768
924
|
useImage,
|
|
@@ -771,4 +927,4 @@ export {
|
|
|
771
927
|
useVariable
|
|
772
928
|
};
|
|
773
929
|
|
|
774
|
-
//# debugId=
|
|
930
|
+
//# debugId=A018C461B91F598364756E2164756E21
|