@colixsystems/widget-sdk 0.343.0 → 0.343.2

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/linter.js CHANGED
@@ -3524,6 +3524,576 @@ function _hardcodedDesignRules(source) {
3524
3524
  return findings;
3525
3525
  }
3526
3526
 
3527
+ // sc-17931 — the SDK consumers a widget hands its whole style bag, and the
3528
+ // fields each paints from it (card-style.js, card-view.js).
3529
+ const _CARD_FIELD = CONTRACT.themeComponents.card.universalFields;
3530
+ // `<Card>`'s own props, each overriding the field it names (card-view.js);
3531
+ // a photo card paints no gradient.
3532
+ const _CARD_PROP_FIELDS = Object.freeze({
3533
+ ..._CARD_FIELD,
3534
+ shadow: "shadow",
3535
+ image: _CARD_FIELD.gradient,
3536
+ });
3537
+ const _CARD_SURFACE_READS = Object.freeze([
3538
+ _CARD_FIELD.background,
3539
+ _CARD_FIELD.borderColor,
3540
+ _CARD_FIELD.radius,
3541
+ _CARD_FIELD.padding,
3542
+ "shadow",
3543
+ ]);
3544
+ const _STYLE_BAG_HELPERS = Object.freeze({
3545
+ cardSurfaceStyle: _CARD_SURFACE_READS,
3546
+ cardOverlay: [..._CARD_SURFACE_READS, "margin"],
3547
+ cardGradientProps: [_CARD_FIELD.gradient],
3548
+ marginStyle: ["margin"],
3549
+ });
3550
+ // `margin` too, unless the card is told `withoutMargin`.
3551
+ const _CARD_READS = Object.freeze([..._CARD_SURFACE_READS, _CARD_FIELD.gradient]);
3552
+ const _BAG_FIELDS = new Set([..._CARD_READS, "margin"]);
3553
+
3554
+ const _ID = "[A-Za-z_$][\\w$]*";
3555
+ // Run on the mask, so an import inside a string or comment never matches;
3556
+ // `[^{}]` keeps an unclosed one linear.
3557
+ const _SDK_IMPORT_RE = new RegExp(`(?<![\\w$.])import\\s*(?:${_ID}\\s*,\\s*)?\\{([^{}]*)\\}\\s*from(?![\\w$])`, "g");
3558
+ const _SDK_SPECIFIER_RE = /^(["'])@colixsystems\/widget-sdk\1/;
3559
+ // An array method's callback is a record's renderer, never a component.
3560
+ const _ARRAY_METHODS = "map|flatMap|forEach|filter|reduce|reduceRight|find|findIndex|findLast|findLastIndex|some|every|sort";
3561
+ // A call wrapping a component: `memo(`, `React.forwardRef(`.
3562
+ const _WRAPPER = `(?:${_ID}\\s*\\.\\s*)*(?!(?:${_ARRAY_METHODS})(?![\\w$]))${_ID}\\s*\\(\\s*`;
3563
+ const _DEFAULT_EXPORT_NAME_RE = new RegExp(`(?<![\\w$.])export\\s+default\\s+(${_ID})\\s*(?=;|\\n|$)`, "g");
3564
+ const _BINDING_RE = new RegExp(`(?<![\\w$.])(?:const|let|var)\\s+(${_ID})\\s*=\\s*`, "g");
3565
+ const _BODY_DESTRUCTURE_RE = /(?<![\w$.])(?:const|let|var)\s*\{/g;
3566
+ const _DESTRUCTURE_SOURCE_RE = new RegExp(`^\\s*=\\s*(${_ID})\\s*(?:[;,\\n]|$)`);
3567
+ const _DESTRUCTURED_NAME_RE = new RegExp(`^(${_ID})\\s*(?:$|=|:\\s*(${_ID})\\s*(?:$|=))`);
3568
+ const _PARAM_MEMBER_RE = new RegExp(`(?<![\\w$.])(${_ID})\\s*\\??\\.\\s*(${_ID})`, "g");
3569
+ const _ATTR_VALUE_RE = /(?<![\w$.-])([A-Za-z_$][\w$]*)\s*=\s*\{/g;
3570
+ const _REFERENCE_CHAIN = `${_ID}(?:\\s*\\??\\.\\s*${_ID})*`;
3571
+ const _HANDED_REFERENCE_RE = new RegExp(`^(${_REFERENCE_CHAIN})\\s*(?:$|\\|\\||\\?\\?)`);
3572
+ const _BOUND_TO_BAG_RE = new RegExp(
3573
+ `^(?:\\{\\s*\\.\\.\\.\\s*(${_REFERENCE_CHAIN})|(${_REFERENCE_CHAIN})\\s*(?:[;,)\\n]|$|\\|\\||\\?\\?))`,
3574
+ );
3575
+ // `useWidgetStyle()` itself, as a value or a binding that ends with the call.
3576
+ const _HOOK_CALL = "useWidgetStyle()";
3577
+ const _HOOK_VALUE_RE = /^useWidgetStyle\s*\(\)$/;
3578
+ const _HOOK_BINDING_RE = /^useWidgetStyle\s*\(/;
3579
+ const _ENDS_EXPRESSION_RE = /^[ \t]*(?:[;,)\n]|$|\|\||\?\?)/;
3580
+ const _JSX_ATTR_RE = /(?<![\w$.-])([A-Za-z_$][\w$-]*)(\s*=\s*\{\})?/g;
3581
+ // Longest top level read per value, tag or parameter list.
3582
+ const _VALUE_TOP_LEVEL_CAP = 256;
3583
+ const _TAG_TOP_LEVEL_CAP = 512;
3584
+ const _PARAMS_TOP_LEVEL_CAP = 8192;
3585
+ const _HANDED_DEPTH_CAP = 4;
3586
+ // Longest value whose reading is remembered: an identical range pairs
3587
+ // identically wherever it sits, so it reads the same.
3588
+ const _MEMO_TEXT_CAP = 256;
3589
+ const _MEMO_ENTRIES_CAP = 4096;
3590
+ const _TAG_MEMO_TEXT_CAP = 64;
3591
+ const _OPENER_OF = Object.freeze({ ")": "(", "]": "[", "}": "{" });
3592
+
3593
+ /**
3594
+ * Partner offset of every `(`/`[`/`{` in `masked`, else -1, from one stack
3595
+ * pass. A closer pairs only with an opener of its own type on top of the
3596
+ * stack; any other closer (a regex literal's, JSX text's) is ignored.
3597
+ */
3598
+ function _bracketPartners(masked) {
3599
+ const partner = new Int32Array(masked.length).fill(-1);
3600
+ const stack = [];
3601
+ for (let i = 0; i < masked.length; i++) {
3602
+ const ch = masked[i];
3603
+ if (ch === "(" || ch === "[" || ch === "{") {
3604
+ stack.push(i);
3605
+ } else if (ch === ")" || ch === "]" || ch === "}") {
3606
+ const top = stack[stack.length - 1];
3607
+ if (top !== undefined && masked[top] === _OPENER_OF[ch]) {
3608
+ stack.pop();
3609
+ partner[top] = i;
3610
+ partner[i] = top;
3611
+ }
3612
+ }
3613
+ }
3614
+ return partner;
3615
+ }
3616
+
3617
+ const _BRACKET_RE = /[()[\]{}]/g;
3618
+
3619
+ /**
3620
+ * The top level of [from, to): each nested bracket group collapsed to its two
3621
+ * brackets. `at(k)` is the source offset of `own[k]`. Null past `cap`, or
3622
+ * when a bracket at the top level is unpaired or pairs outside the range —
3623
+ * then nothing in it can be trusted.
3624
+ */
3625
+ function _topLevelView(masked, partner, from, to, cap) {
3626
+ let own = "";
3627
+ // Flat pairs: offset in own, offset in masked, where each run starts.
3628
+ const runs = [];
3629
+ let i = from;
3630
+ while (i < to) {
3631
+ _BRACKET_RE.lastIndex = i;
3632
+ const bracket = _BRACKET_RE.exec(masked);
3633
+ const stop = bracket && bracket.index < to ? bracket.index : to;
3634
+ if (own.length + (stop - i) + 2 > cap) return null;
3635
+ if (stop > i) {
3636
+ runs.push(own.length, i);
3637
+ own += masked.slice(i, stop);
3638
+ }
3639
+ if (stop === to) break;
3640
+ const close = partner[stop];
3641
+ if (close < stop || close >= to) return null;
3642
+ runs.push(own.length, stop);
3643
+ own += masked[stop] + masked[close];
3644
+ i = close + 1;
3645
+ }
3646
+ return { own, at: _runLookup(runs) };
3647
+ }
3648
+
3649
+ // Source offset of `own[k]` from flat [own offset, source offset] run pairs.
3650
+ // Only a run's first character, or a group's opener, is ever looked up.
3651
+ function _runLookup(runs) {
3652
+ return (k) => {
3653
+ let r = runs.length - 2;
3654
+ while (r > 0 && runs[r] > k) r -= 2;
3655
+ return runs[r + 1] + (k - runs[r]);
3656
+ };
3657
+ }
3658
+
3659
+ const _TAG_STOP_RE = /[()[\]{}>]/g;
3660
+
3661
+ // The next bracket or `>` at or after `i`; a long run without one is
3662
+ // scanned once, however many tags start inside it.
3663
+ function _nextTagStop(ctx, i) {
3664
+ const last = ctx.lastStop;
3665
+ if (last && last.from <= i && i <= last.at) return last.at;
3666
+ _TAG_STOP_RE.lastIndex = i;
3667
+ const stop = _TAG_STOP_RE.exec(ctx.masked);
3668
+ const at = stop ? stop.index : ctx.masked.length;
3669
+ ctx.lastStop = { from: i, at };
3670
+ return at;
3671
+ }
3672
+
3673
+ /**
3674
+ * The top level of a JSX opening tag's body from `from` to its closing `>`,
3675
+ * collapsed as `_topLevelView` does, with `end` at that `>`. When it cannot
3676
+ * be read — past `cap`, an unpaired bracket, no `>` — only `reached` is set,
3677
+ * the offset the reading got to.
3678
+ */
3679
+ function _tagView(ctx, from, cap) {
3680
+ const { masked } = ctx;
3681
+ const partner = ctx.partner();
3682
+ let own = "";
3683
+ const runs = [];
3684
+ let i = from;
3685
+ for (;;) {
3686
+ const stop = _nextTagStop(ctx, i);
3687
+ if (stop >= masked.length || own.length + (stop - i) + 2 > cap) return { reached: stop };
3688
+ if (stop > i) {
3689
+ runs.push(own.length, i);
3690
+ own += masked.slice(i, stop);
3691
+ }
3692
+ if (masked[stop] === ">") return { own, at: _runLookup(runs), end: stop };
3693
+ const close = partner[stop];
3694
+ if (close < stop) return { reached: stop };
3695
+ runs.push(own.length, stop);
3696
+ own += masked[stop] + masked[close];
3697
+ i = close + 1;
3698
+ }
3699
+ }
3700
+
3701
+ // [start, end) of each comma-separated item of `own`.
3702
+ function _itemSpans(own) {
3703
+ const spans = [];
3704
+ let start = 0;
3705
+ for (let i = 0; i <= own.length; i++) {
3706
+ if (i === own.length || own[i] === ",") {
3707
+ spans.push([start, i]);
3708
+ start = i + 1;
3709
+ }
3710
+ }
3711
+ return spans;
3712
+ }
3713
+
3714
+ // Offsets of a top-level ternary's `?` and `:` in `own`, or null.
3715
+ function _ternaryAt(own) {
3716
+ let question = -1;
3717
+ let pending = 0;
3718
+ for (let i = 0; i < own.length; i++) {
3719
+ const ch = own[i];
3720
+ if (ch === "?") {
3721
+ if (own[i + 1] === "?" || own[i + 1] === ".") {
3722
+ i += 1;
3723
+ continue;
3724
+ }
3725
+ if (question < 0) question = i;
3726
+ else pending += 1;
3727
+ } else if (ch === ":" && question >= 0) {
3728
+ if (pending === 0) return { question, colon: i };
3729
+ pending -= 1;
3730
+ }
3731
+ }
3732
+ return null;
3733
+ }
3734
+
3735
+ /**
3736
+ * Collects into `chains` each reference the expression at view[from, to)
3737
+ * hands over whole: `style`, `props.style`, `style || {}`, each branch of a
3738
+ * ternary, an item of a style array, or (`inObject`) a spread.
3739
+ */
3740
+ function _handedChains(ctx, view, [from, to], inObject, depth, chains) {
3741
+ const text = view.own.slice(from, to);
3742
+ const lead = text.length - text.trimStart().length;
3743
+ const expr = text.trim();
3744
+ if (!expr || depth > _HANDED_DEPTH_CAP) return;
3745
+ if (inObject) {
3746
+ if (!expr.startsWith("...")) return;
3747
+ const spread = text.indexOf("...") + 3;
3748
+ _handedChains(ctx, view, [from + spread, to], false, depth + 1, chains);
3749
+ return;
3750
+ }
3751
+ const ternary = _ternaryAt(expr);
3752
+ if (ternary) {
3753
+ const base = from + lead;
3754
+ _handedChains(ctx, view, [base + ternary.question + 1, base + ternary.colon], false, depth + 1, chains);
3755
+ _handedChains(ctx, view, [base + ternary.colon + 1, to], false, depth + 1, chains);
3756
+ return;
3757
+ }
3758
+ if (_HOOK_VALUE_RE.test(expr)) {
3759
+ chains.push(_HOOK_CALL);
3760
+ return;
3761
+ }
3762
+ const reference = _HANDED_REFERENCE_RE.exec(expr);
3763
+ if (reference) {
3764
+ chains.push(reference[1]);
3765
+ return;
3766
+ }
3767
+ if (expr !== "[]" && expr !== "{}") return;
3768
+ const open = view.at(from + lead);
3769
+ const inner = _topLevelView(ctx.masked, ctx.partner(), open + 1, ctx.partner()[open], _VALUE_TOP_LEVEL_CAP);
3770
+ if (!inner) return;
3771
+ for (const span of _itemSpans(inner.own)) {
3772
+ _handedChains(ctx, inner, span, expr === "{}", depth + 1, chains);
3773
+ }
3774
+ }
3775
+
3776
+ // The references the bracket group opening at `open` (or its first item)
3777
+ // hands over whole.
3778
+ function _groupChains(ctx, open, firstItemOnly) {
3779
+ const partner = ctx.partner();
3780
+ const view = _topLevelView(ctx.masked, partner, open + 1, partner[open], _VALUE_TOP_LEVEL_CAP);
3781
+ if (!view) return [];
3782
+ const span = firstItemOnly ? _itemSpans(view.own)[0] : [0, view.own.length];
3783
+ const chains = [];
3784
+ _handedChains(ctx, view, span, false, 0, chains);
3785
+ return chains;
3786
+ }
3787
+
3788
+ // Whether the bracket group opening at `open` (or its first item) hands the bag.
3789
+ function _handsBag(ctx, roots, open, firstItemOnly) {
3790
+ return _groupChains(ctx, open, firstItemOnly).some((chain) => roots.isBag(chain));
3791
+ }
3792
+
3793
+ // `_handsBag` once the roots are final, remembered by the value's text.
3794
+ function _memoHandsBag(ctx, roots, open, firstItemOnly) {
3795
+ const close = ctx.partner()[open];
3796
+ const key = close > open && close - open <= _MEMO_TEXT_CAP ? ctx.masked.slice(open, close + 1) : null;
3797
+ const memo = firstItemOnly ? ctx.argMemo : ctx.valueMemo;
3798
+ if (key !== null && memo.has(key)) return memo.get(key);
3799
+ const hands = _handsBag(ctx, roots, open, firstItemOnly);
3800
+ if (key !== null && memo.size < _MEMO_ENTRIES_CAP) memo.set(key, hands);
3801
+ return hands;
3802
+ }
3803
+
3804
+ // A component's first parameter (a name, or the `{` of a destructured one):
3805
+ // a capitalised function or const, or the default export, unwrapped from
3806
+ // `memo(`/`forwardRef(`, never an array method's callback.
3807
+ function _componentParamRe(defaultNames) {
3808
+ const names = ["[A-Z][\\w$]*", ...defaultNames.map(_escapeRe)].join("|");
3809
+ return new RegExp(
3810
+ `(?<![\\w$.])(?:function\\s+(?:${names})\\s*` +
3811
+ `|(?:const|let|var)\\s+(?:${names})\\s*=\\s*(?:${_WRAPPER})?(?:function\\s*[\\w$]*\\s*)?` +
3812
+ `|export\\s+default\\s+(?:${_WRAPPER})?(?:function\\s*[\\w$]*\\s*)?)` +
3813
+ `\\(\\s*(${_ID}|\\{)`,
3814
+ "g",
3815
+ );
3816
+ }
3817
+
3818
+ // [prop key, local name] for each entry of the destructuring `{` at `open`.
3819
+ function _destructuredEntries(ctx, open) {
3820
+ const close = ctx.partner()[open];
3821
+ const view = close < 0 ? null : _topLevelView(ctx.masked, ctx.partner(), open + 1, close, _PARAMS_TOP_LEVEL_CAP);
3822
+ const entries = [];
3823
+ for (const [a, b] of view ? _itemSpans(view.own) : []) {
3824
+ const entry = _DESTRUCTURED_NAME_RE.exec(view.own.slice(a, b).trim());
3825
+ if (entry) entries.push([entry[1], entry[2] || entry[1]]);
3826
+ }
3827
+ return entries;
3828
+ }
3829
+
3830
+ function _pushTo(map, key, value) {
3831
+ const list = map.get(key);
3832
+ if (list) list.push(value);
3833
+ else map.set(key, [value]);
3834
+ }
3835
+
3836
+ // What a handed chain needs to be the bag: nothing, a name, or a prop key.
3837
+ function _chainNeed(chain, params) {
3838
+ if (chain === _HOOK_CALL) return { yes: true };
3839
+ const parts = chain.split(/\s*\??\.\s*/);
3840
+ if (parts.length === 1) return { name: parts[0] };
3841
+ if (parts.length !== 2 || !params.has(parts[0])) return null;
3842
+ return parts[1] === "style" ? { yes: true } : { key: parts[1] };
3843
+ }
3844
+
3845
+ /**
3846
+ * The style bag's roots, an allowlist over the whole bundle: `useWidgetStyle()`
3847
+ * or a name bound to it, `<param>.style` of a component, `style` destructured
3848
+ * from a component's props (in its parameters or its body, renamed or not),
3849
+ * a prop a JSX call site fills from one of those (read destructured or as
3850
+ * `<param>.<prop>`), or a `{ ...bag }` copy. Anything else — a style sheet,
3851
+ * the theme, a record's `item.style`, `style.header` — is not the bag.
3852
+ *
3853
+ * Propagated over a worklist, each name and prop key accepted once, so a
3854
+ * chain of components of any depth or order costs one pass.
3855
+ */
3856
+ function _styleBagRoots(contexts) {
3857
+ const defaults = new Set();
3858
+ for (const ctx of contexts) {
3859
+ for (const name of ctx.masked.matchAll(_DEFAULT_EXPORT_NAME_RE)) defaults.add(name[1]);
3860
+ }
3861
+ const componentParam = _componentParamRe([...defaults]);
3862
+ const params = new Set();
3863
+ const entries = [];
3864
+ for (const ctx of contexts) {
3865
+ for (const param of ctx.masked.matchAll(componentParam)) {
3866
+ // A named function expression (`.map(function Item(item)`) is no component.
3867
+ if (param[0].startsWith("function") && "(,=:?&|".includes(ctx.masked[_tokenBefore(ctx.masked, param.index).at])) continue;
3868
+ if (param[1] === "{") entries.push(..._destructuredEntries(ctx, param.index + param[0].length - 1));
3869
+ else params.add(param[1]);
3870
+ }
3871
+ }
3872
+ for (const ctx of contexts) {
3873
+ for (const pattern of ctx.masked.matchAll(_BODY_DESTRUCTURE_RE)) {
3874
+ const open = pattern.index + pattern[0].length - 1;
3875
+ const close = ctx.partner()[open];
3876
+ const source = close < 0 ? null : _DESTRUCTURE_SOURCE_RE.exec(ctx.masked.slice(close + 1, close + 81));
3877
+ if (source && params.has(source[1])) entries.push(..._destructuredEntries(ctx, open));
3878
+ }
3879
+ }
3880
+
3881
+ const names = new Set();
3882
+ const keys = new Set();
3883
+ const aliasesOf = new Map();
3884
+ const seeds = [];
3885
+ for (const [key, alias] of entries) {
3886
+ if (key === "style") seeds.push(["name", alias]);
3887
+ else _pushTo(aliasesOf, key, alias);
3888
+ }
3889
+ const wantedKeys = new Set(aliasesOf.keys());
3890
+ for (const ctx of contexts) {
3891
+ for (const member of ctx.masked.matchAll(_PARAM_MEMBER_RE)) {
3892
+ if (params.has(member[1])) wantedKeys.add(member[2]);
3893
+ }
3894
+ }
3895
+ const dependents = { name: new Map(), key: new Map() };
3896
+ const register = (target, chains) => {
3897
+ for (const chain of chains) {
3898
+ const need = _chainNeed(chain, params);
3899
+ if (!need) continue;
3900
+ if (need.yes) {
3901
+ seeds.push(target);
3902
+ return;
3903
+ }
3904
+ const [kind, value] = need.name !== undefined ? ["name", need.name] : ["key", need.key];
3905
+ _pushTo(dependents[kind], value, target);
3906
+ }
3907
+ };
3908
+ for (const ctx of contexts) {
3909
+ for (const binding of ctx.masked.matchAll(_BINDING_RE)) {
3910
+ const end = binding.index + binding[0].length;
3911
+ const tail = ctx.masked.slice(end, end + 160);
3912
+ const hook = _HOOK_BINDING_RE.exec(tail);
3913
+ if (hook) {
3914
+ const close = ctx.partner()[end + hook[0].length - 1];
3915
+ if (close > end && _ENDS_EXPRESSION_RE.test(ctx.masked.slice(close + 1, close + 9))) seeds.push(["name", binding[1]]);
3916
+ continue;
3917
+ }
3918
+ const bound = _BOUND_TO_BAG_RE.exec(tail);
3919
+ if (bound) register(["name", binding[1]], [bound[1] || bound[2]]);
3920
+ }
3921
+ for (const attr of ctx.masked.matchAll(_ATTR_VALUE_RE)) {
3922
+ if (!wantedKeys.has(attr[1]) || ["const", "let", "var"].includes(_wordBefore(ctx.masked, attr.index))) continue;
3923
+ register(["key", attr[1]], _groupChains(ctx, attr.index + attr[0].length - 1, false));
3924
+ }
3925
+ }
3926
+
3927
+ const queue = [];
3928
+ const accept = ([kind, value]) => {
3929
+ const set = kind === "name" ? names : keys;
3930
+ if (set.has(value)) return;
3931
+ set.add(value);
3932
+ queue.push([kind, value]);
3933
+ if (kind === "key") for (const alias of aliasesOf.get(value) || []) accept(["name", alias]);
3934
+ };
3935
+ seeds.forEach(accept);
3936
+ while (queue.length > 0) {
3937
+ const [kind, value] = queue.pop();
3938
+ for (const target of dependents[kind].get(value) || []) accept(target);
3939
+ }
3940
+ const hook = contexts.some((ctx) => ctx.masked.includes("useWidgetStyle"));
3941
+ return {
3942
+ isBag: (chain) => {
3943
+ const need = _chainNeed(chain, params);
3944
+ if (!need) return false;
3945
+ if (need.yes) return true;
3946
+ return need.name !== undefined ? names.has(need.name) : keys.has(need.key);
3947
+ },
3948
+ empty: () => names.size === 0 && params.size === 0 && !hook,
3949
+ };
3950
+ }
3951
+
3952
+ // Local name -> SDK export, for every consumer the source imports.
3953
+ function _importedConsumers(source, masked) {
3954
+ const consumers = new Map();
3955
+ for (const statement of masked.matchAll(_SDK_IMPORT_RE)) {
3956
+ // The mask blanks the specifier, so it is read from the source.
3957
+ const after = source.slice(statement.index + statement[0].length, statement.index + statement[0].length + 64);
3958
+ if (!_SDK_SPECIFIER_RE.test(after.trimStart())) continue;
3959
+ for (const item of statement[1].split(",")) {
3960
+ const [name, local = name] = item.trim().split(/\s+as\s+/);
3961
+ if (name === "Card" || name in _STYLE_BAG_HELPERS) consumers.set(local, name);
3962
+ }
3963
+ }
3964
+ return consumers;
3965
+ }
3966
+
3967
+ const _escapeRe = (name) => name.replace(/\$/g, "\\$");
3968
+
3969
+ const _CARD_PROP_ENTRIES = Object.entries(_CARD_PROP_FIELDS);
3970
+ /**
3971
+ * One `<Card …>` opening tag, read from its top-level `tag` view: the `{…}`
3972
+ * values it holds, relative to `from`, and the fields it reads from the bag.
3973
+ */
3974
+ function _cardTagReads(ctx, roots, from, tag) {
3975
+ const attrs = new Map();
3976
+ const values = [];
3977
+ _JSX_ATTR_RE.lastIndex = 0;
3978
+ let attr;
3979
+ while ((attr = _JSX_ATTR_RE.exec(tag.own))) {
3980
+ const open = attr[2] ? tag.at(attr.index + attr[0].length - 2) : -1;
3981
+ attrs.set(attr[1], open);
3982
+ if (open >= 0) values.push([open - from, ctx.partner()[open] - from]);
3983
+ }
3984
+ const style = attrs.get("style");
3985
+ if (style === undefined || style < 0 || !_memoHandsBag(ctx, roots, style, false)) return { values, reads: [] };
3986
+ const overridden = _CARD_PROP_ENTRIES.filter(([prop]) => attrs.has(prop)).map(([, field]) => field);
3987
+ const reads = _CARD_READS.filter((field) => !overridden.includes(field));
3988
+ if (!_dropsMargin(ctx, attrs.get("withoutMargin"))) reads.push("margin");
3989
+ return { values, reads };
3990
+ }
3991
+
3992
+ // A short tag's reading, remembered by its text; a long or one-off tag is
3993
+ // read afresh, so distinct tags cost no memo churn.
3994
+ function _memoCardTag(ctx, roots, from, view, memo) {
3995
+ const key = view.end - from <= _TAG_MEMO_TEXT_CAP ? ctx.masked.slice(from, view.end) : null;
3996
+ const known = key === null ? undefined : memo.get(key);
3997
+ if (known) return known;
3998
+ const card = _cardTagReads(ctx, roots, from, view);
3999
+ if (key !== null && memo.size < _MEMO_ENTRIES_CAP) memo.set(key, card);
4000
+ return card;
4001
+ }
4002
+
4003
+ // `withoutMargin` or `withoutMargin={true}`; a computed value may still be false.
4004
+ function _dropsMargin(ctx, value) {
4005
+ if (value === undefined) return false;
4006
+ if (value < 0) return true;
4007
+ const inner = _topLevelView(ctx.masked, ctx.partner(), value + 1, ctx.partner()[value], _VALUE_TOP_LEVEL_CAP);
4008
+ return Boolean(inner) && inner.own.trim() === "true";
4009
+ }
4010
+
4011
+ /**
4012
+ * Which of the `pending` fields the bundle reads by handing its style bag to
4013
+ * `<Card>` or a helper imported from the SDK. Each source's bracket and tag
4014
+ * indexes are built at most once and every value read is capped, so the scan
4015
+ * stays linear; it stops once every pending field is read.
4016
+ */
4017
+ function _styleBagReads(sources, pending) {
4018
+ const reads = new Set();
4019
+ const wanted = pending.filter((field) => _BAG_FIELDS.has(field));
4020
+ if (wanted.length === 0) return reads;
4021
+ const context = (source, masked = _stripNonCode(source, { keepHoleBraces: true })) => {
4022
+ let partner = null;
4023
+ return {
4024
+ masked,
4025
+ consumers: new Map(),
4026
+ partner: () => partner || (partner = _bracketPartners(masked)),
4027
+ valueMemo: new Map(),
4028
+ argMemo: new Map(),
4029
+ };
4030
+ };
4031
+ // Only a file that imports and uses a consumer is scanned; every file's
4032
+ // bindings and call sites feed the roots.
4033
+ const contexts = sources.map((source) => {
4034
+ if (!source.includes("@colixsystems/widget-sdk")) return { source };
4035
+ const ctx = context(source);
4036
+ const consumers = _importedConsumers(source, ctx.masked);
4037
+ if (consumers.size === 0) return ctx;
4038
+ const locals = [...consumers.keys()].map(_escapeRe).join("|");
4039
+ // A spread (`...marginStyle(`) still calls; a member (`x.marginStyle(`) does not.
4040
+ const calls = new RegExp(`(?<![\\w$])(?<!(?:^|[^.])\\.)(${locals})\\s*\\(`, "g");
4041
+ const tags = new RegExp(`<(${locals})(?![\\w$.])`, "g");
4042
+ const used = calls.test(ctx.masked) || tags.test(ctx.masked);
4043
+ calls.lastIndex = 0;
4044
+ tags.lastIndex = 0;
4045
+ return used ? { ...ctx, consumers, calls, tags } : ctx;
4046
+ });
4047
+ if (contexts.every((ctx) => !ctx.calls)) return reads;
4048
+ const all = contexts.map((ctx) => (ctx.masked === undefined ? context(ctx.source) : ctx));
4049
+ const roots = _styleBagRoots(all);
4050
+ if (roots.empty()) return reads;
4051
+ const add = (fields) => {
4052
+ fields.forEach((field) => reads.add(field));
4053
+ return wanted.every((field) => reads.has(field));
4054
+ };
4055
+ for (const ctx of all.filter((c) => c.calls)) {
4056
+ for (const call of ctx.masked.matchAll(ctx.calls)) {
4057
+ const helper = _STYLE_BAG_HELPERS[ctx.consumers.get(call[1])];
4058
+ if (helper && _memoHandsBag(ctx, roots, call.index + call[0].length - 1, true) && add(helper)) return reads;
4059
+ }
4060
+ // A tag inside another is read only from one of its `{…}` values, and a
4061
+ // tag inside an unreadable one's reach not at all, so each character is
4062
+ // read as one tag's top level at most.
4063
+ const open = [];
4064
+ const memo = new Map();
4065
+ let skipTo = 0;
4066
+ for (const tag of ctx.masked.matchAll(ctx.tags)) {
4067
+ if (tag.index < skipTo || ctx.consumers.get(tag[1]) !== "Card") continue;
4068
+ while (open.length > 0 && open[open.length - 1].end <= tag.index) open.pop();
4069
+ const outer = open[open.length - 1];
4070
+ const at = outer && tag.index - outer.from;
4071
+ if (outer && !outer.card.values.some(([a, b]) => a < at && at < b)) continue;
4072
+ const from = tag.index + tag[0].length;
4073
+ const view = _tagView(ctx, from, _TAG_TOP_LEVEL_CAP);
4074
+ if (view.reached !== undefined) {
4075
+ skipTo = view.reached;
4076
+ continue;
4077
+ }
4078
+ const card = _memoCardTag(ctx, roots, from, view, memo);
4079
+ open.push({ from, end: view.end, card });
4080
+ if (add(card.reads)) return reads;
4081
+ }
4082
+ }
4083
+ return reads;
4084
+ }
4085
+
4086
+ // Whether `\b<name>\b` matches `code`, from one pass over its words: a
4087
+ // regex per styleSchema field re-read the whole bundle per field (sc-8204).
4088
+ function _wordReader(code) {
4089
+ const words = new Set(code.match(/\w+/g));
4090
+ return (name) => {
4091
+ if (!name.includes("$")) return words.has(name);
4092
+ // Unescaped, `$` asserts end of input, so only the tail can match.
4093
+ return new RegExp(`\\b${name}\\b`).test(code.slice(-(name.length + 1)));
4094
+ };
4095
+ }
4096
+
3527
4097
  /**
3528
4098
  * sc-6455 — a `styleSchema` field the bundle never mentions is a DEAD
3529
4099
  * control: the Studio renders it in the widget editor and again on
@@ -3540,22 +4110,23 @@ function _hardcodedDesignRules(source) {
3540
4110
  * mentioned but misapplied uncaught, and catches the one that reaches an
3541
4111
  * author — declared, then forgotten.
3542
4112
  *
4113
+ * A field is read, too, by the SDK consumer the bundle hands its style bag
4114
+ * whole (sc-17931): `<Card style={style}>` paints the `card*` fields, `shadow`
4115
+ * and (without `withoutMargin`) `margin`, less any of them its own props
4116
+ * (`background`, `padding`, `shadow`, `image`, …) override; `cardOverlay`,
4117
+ * `cardSurfaceStyle`, `cardGradientProps` and `marginStyle` each read their
4118
+ * own subset. Handed whole means a reference to the bag (see
4119
+ * `_styleBagRoots`), alone, as a ternary branch, a style-array item or an
4120
+ * object spread (`{ ...style, flex: 1 }`). Only names imported from the SDK
4121
+ * count. Every miss stays on the safe side, still flagged: a namespace
4122
+ * import (`<UI.Card>`), compiled `createElement(Card, …)`, a bag reached
4123
+ * some other way, or a range whose brackets do not pair.
4124
+ *
3543
4125
  * @param {object} manifest widget manifest (reads `styleSchema` only)
3544
4126
  * @param {object|string[]|string} files bundle sources — a `{ name: source }`
3545
4127
  * map, an array of sources, or one source string
3546
4128
  * @returns {{ ok: boolean, findings: Array<{ rule: string, severity: string, label: string, line: number, snippet: string }> }}
3547
4129
  */
3548
- // Whether `\b<name>\b` matches `code`, from one pass over its words: a
3549
- // regex per styleSchema field re-read the whole bundle per field (sc-8204).
3550
- function _wordReader(code) {
3551
- const words = new Set(code.match(/\w+/g));
3552
- return (name) => {
3553
- if (!name.includes("$")) return words.has(name);
3554
- // Unescaped, `$` asserts end of input, so only the tail can match.
3555
- return new RegExp(`\\b${name}\\b`).test(code.slice(-(name.length + 1)));
3556
- };
3557
- }
3558
-
3559
4130
  export function lintStyleWiring(manifest, files) {
3560
4131
  const empty = { ok: true, findings: [] };
3561
4132
  const schema = manifest && manifest.styleSchema;
@@ -3572,12 +4143,14 @@ export function lintStyleWiring(manifest, files) {
3572
4143
  : new Set();
3573
4144
  const findings = [];
3574
4145
  const isRead = _wordReader(code);
3575
- for (const field of Object.keys(schema)) {
3576
- // A key that is not a bare identifier cannot be scanned by name; the
3577
- // manifest validator rejects those anyway.
3578
- if (!/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(field)) continue;
3579
- if (appliedByHelper.has(field)) continue;
3580
- if (isRead(field)) continue;
4146
+ // A key that is not a bare identifier cannot be scanned by name; the
4147
+ // manifest validator rejects those anyway.
4148
+ const unread = Object.keys(schema).filter(
4149
+ (field) => /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(field) && !appliedByHelper.has(field) && !isRead(field),
4150
+ );
4151
+ const bagReads = _styleBagReads(sources, unread);
4152
+ for (const field of unread) {
4153
+ if (bagReads.has(field)) continue;
3581
4154
  findings.push({
3582
4155
  rule: "style-field-unread",
3583
4156
  severity: "warning",
@@ -24,12 +24,8 @@ export { Text, TextInput } from "./bounded-text.native.js";
24
24
  // REQ-WSDK-PLATFORM §6 — `<Icon>` is implemented in one file that runs on
25
25
  // both platforms (lucide-react-native ships a working build for both).
26
26
  export { Icon } from "./icon.js";
27
- // REQ-WSDK-PLATFORM §6 — `<DateTimePicker>` (native). Wraps
28
- // @react-native-community/datetimepicker, which ships iOS / Android only
29
- // and has no react-native-web mapping, so the web build uses a separate
30
- // implementation backed by `<input type="date|time|datetime-local">` in
31
- // `./datetimepicker.js`. Both files honour the same ISO 8601 value /
32
- // onChange contract.
27
+ // REQ-WSDK-PLATFORM §6 — `<DateTimePicker>` (native): the shared field with
28
+ // the themed sheet on iOS and the OS dialogs on Android.
33
29
  export { DateTimePicker } from "./datetimepicker.native.js";
34
30
  // sc-1378 — `<FilePicker>` (native). Opens the OS document picker
35
31
  // (expo-document-picker); the web counterpart wraps a hidden file input.
@@ -20,6 +20,11 @@ const COMPONENT_TEXTS = Object.freeze({
20
20
  select_placeholder: { en: "Select", sv: "Välj" },
21
21
  no_options: { en: "No options", sv: "Inga alternativ" },
22
22
  done: { en: "Done", sv: "Klar" },
23
+ // The DateTimePicker sheet's fallbacks where an engine lacks the Intl names (Hermes).
24
+ picker_today: { en: "Today", sv: "I dag" },
25
+ picker_now: { en: "Now", sv: "Nu" },
26
+ picker_hour: { en: "Hour", sv: "Timme" },
27
+ picker_minute: { en: "Minute", sv: "Minut" },
23
28
  selected_count: {
24
29
  en: { one: "{count} selected", other: "{count} selected" },
25
30
  sv: { one: "{count} vald", other: "{count} valda" },
package/dist/sdk-texts.js CHANGED
@@ -16,6 +16,11 @@ export const COMPONENT_TEXTS = Object.freeze({
16
16
  select_placeholder: { en: "Select", sv: "Välj" },
17
17
  no_options: { en: "No options", sv: "Inga alternativ" },
18
18
  done: { en: "Done", sv: "Klar" },
19
+ // The DateTimePicker sheet's fallbacks where an engine lacks the Intl names (Hermes).
20
+ picker_today: { en: "Today", sv: "I dag" },
21
+ picker_now: { en: "Now", sv: "Nu" },
22
+ picker_hour: { en: "Hour", sv: "Timme" },
23
+ picker_minute: { en: "Minute", sv: "Minut" },
19
24
  selected_count: {
20
25
  en: { one: "{count} selected", other: "{count} selected" },
21
26
  sv: { one: "{count} vald", other: "{count} valda" },