Plugin Directory

Changeset 3816104


Ignore:
Timestamp:
11/22/2026 04:34:24 AM (less than one hour ago)
Author:
celestinetan
Message:

Update to version 0.57.0 from GitHub

Location:
stubli
Files:
10 edited
1 copied

Legend:

Unmodified
Added
Removed
  • stubli/tags/0.57.0/assets/app/app.css

    r3814657 r3816104  
    360360.a-swatches [aria-checked="true"] { color: var(--ink); font-weight: 650; }
    361361.a-swatches [aria-checked="true"] span { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--ink); }
     362/* Any colour (0.57.0): a swatch like the others that opens the phone's colour picker. */
     363.a-any { position: relative; min-height: 64px; display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer; color: var(--muted); }
     364.a-any small { font-size: 12px; text-align: center; line-height: 1.2; }
     365.a-any-dot { width: 36px; height: 36px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0,0,0,.08); }
     366.a-any-dot.is-wheel { background: conic-gradient(#d94f4f, #e0b65a, #6fae5b, #3d8fb0, #6b3f5a, #d94f4f); }
     367.a-any[aria-checked="true"] { color: var(--ink); font-weight: 650; }
     368.a-any[aria-checked="true"] .a-any-dot { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--ink); }
     369.a-any-in { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; border: 0; padding: 0; }
     370.a-any:focus-within .a-any-dot { outline: 2px solid var(--ink); outline-offset: 3px; }
    362371.a-su-preview { margin: 18px 0 4px; padding: 16px; border-radius: 14px; background: var(--bg); color: var(--ink); box-shadow: inset 0 0 0 1px var(--field); font-size: 13px; position: relative; }
    363372.a-su-pv-head { display: flex; gap: 10px; align-items: center; }
  • stubli/tags/0.57.0/assets/app/app.js

    r3814657 r3816104  
    23952395        }
    23962396        function accentCss( a ) {
    2397                 if ( ! a || a.key === 'moss' ) { return ''; }
    2398                 return ':root,[data-mode="light"],[data-mode="paper"]{--accent:' + a.hex + ';--accent-ink:' + a.ink + ';--accent-text:' + ( a.key === 'gold' ? '#7d5f16' : a.hex ) + '}[data-mode="dark"]{--accent:' + a.dark + ';--accent-ink:#1c1916;--accent-text:' + a.dark + '}';
     2397                // Moss too is written out, so switching back to it replaces the colour the page loaded with.
     2398                if ( ! a ) { return ''; }
     2399                return ':root,[data-mode="light"],[data-mode="paper"]{--accent:' + a.hex + ';--accent-ink:' + a.ink + ';--accent-text:' + ( a.text || a.hex ) + '}[data-mode="dark"]{--accent:' + a.dark + ';--accent-ink:#1c1916;--accent-text:' + a.dark + '}';
    23992400        }
    24002401        function accentOf( key ) { return su.d.accents.filter( function ( a ) { return a.key === key; } )[ 0 ] || su.d.accents[ 0 ]; }
     2402        // The named colours, then Any colour (0.57.0, Celestine 22 Nov): the phone's own colour picker. Stubli keeps
     2403        // text on it readable and says so when it had to darken it (Setup::readable()).
     2404        function swatches( d, label ) {
     2405                var own = d.accents.filter( function ( c ) { return c.key === 'custom'; } )[ 0 ], on = d.accent === 'custom';
     2406                return '<div class="a-swatches" role="radiogroup" aria-labelledby="' + label + '">' + d.accents.filter( function ( c ) { return c.key !== 'custom'; } ).map( function ( c ) {
     2407                        var sel = c.key === d.accent;
     2408                        return '<button type="button" role="radio" aria-checked="' + sel + '" aria-label="' + esc( c.name + ( c.key === 'moss' ? __( ', the Stubli green', 'stubli' ) : '' ) ) + '" data-accent="' + c.key + '" tabindex="' + ( sel ? 0 : -1 ) + '"><span style="background:' + c.hex + '"></span><small>' + esc( c.name ) + '</small></button>';
     2409                } ).join( '' ) +
     2410                        '<label class="a-any" role="radio" aria-checked="' + on + '" tabindex="' + ( on ? 0 : -1 ) + '"><span class="a-any-dot' + ( own ? '' : ' is-wheel' ) + '"' + ( own ? ' style="background:' + own.hex + '"' : '' ) + '></span><small>' + __( 'Any colour', 'stubli' ) + '</small>' +
     2411                        '<input type="color" class="a-any-in" data-accent-any value="' + esc( own ? own.picked || own.hex : '#4f6a4a' ) + '" aria-label="' + esc( __( 'Pick any colour', 'stubli' ) ) + '"></label></div>' +
     2412                        ( on && own && own.adjusted ? '<p class="a-help" role="status">' + __( 'We darkened your colour a little so text on it stays readable.', 'stubli' ) + '</p>' : '' );
     2413        }
     2414        function bindAnyColour( save ) {
     2415                var any = $( '[data-accent-any]' );
     2416                if ( ! any ) { return; }
     2417                any.addEventListener( 'change', function () { save( { accent_hex: any.value }, '.a-any' ); } );
     2418                any.closest( '.a-any' ).addEventListener( 'keydown', function ( e ) { if ( e.key === 'Enter' || e.key === ' ' ) { e.preventDefault(); any.click(); } } );
     2419        }
    24012420        function applyLook() {
    24022421                var s = document.getElementById( 'stubli-accent' );
    … …  
    31003119                var d = su.d, a = accentOf( d.accent ), pm = 'light';
    31013120                root.innerHTML = arrangeHead( '#more', __( 'Colour and reading mode', 'stubli' ) ) + '<main class="a-main" id="main">' +
    3102                         '<p class="a-label" id="a-lk-col">' + _f( __( 'Colour: %s', 'stubli' ), esc( a.name ) ) + '</p><div class="a-swatches" role="radiogroup" aria-labelledby="a-lk-col">' + d.accents.map( function ( c ) {
    3103                                 var on = c.key === d.accent;
    3104                                 return '<button type="button" role="radio" aria-checked="' + on + '" aria-label="' + esc( c.name + ( c.key === 'moss' ? __( ', the Stubli green', 'stubli' ) : '' ) ) + '" data-accent="' + c.key + '" tabindex="' + ( on ? 0 : -1 ) + '"><span style="background:' + ( pm === 'dark' ? c.dark : c.hex ) + '"></span><small>' + esc( c.name ) + '</small></button>';
    3105                         } ).join( '' ) + '</div>' +
     3121                        '<p class="a-label" id="a-lk-col">' + _f( __( 'Colour: %s', 'stubli' ), esc( a.name ) ) + '</p>' + swatches( d, 'a-lk-col' ) +
    31063122                        ( d.accent === 'gold' && pm !== 'dark' ? ( '<p class="a-help" role="status">' + __( 'Gold is a soft colour, so your tabs blend in a little.', 'stubli' ) + '</p>' ) : '' ) +
    31073123                        '<p class="a-label" id="a-lk-mode" style="margin-top:20px">' + __( 'Reading mode', 'stubli' ) + '</p><div class="a-chips" role="radiogroup" aria-labelledby="a-lk-mode">' + [ [ 'light', __( 'Light', 'stubli' ) ], [ 'paper', __( 'Paper', 'stubli' ) ] ].map( function ( m ) {
    … …  
    31223138                        } );
    31233139                } );
     3140                bindAnyColour( save );
    31243141                $$( '[data-mode-pick]' ).forEach( function ( b ) { b.addEventListener( 'click', function () { save( { mode: b.dataset.modePick }, '[data-mode-pick="' + b.dataset.modePick + '"]' ); } ); } );
    31253142                var ss = $( '[data-lk-season]' );
    … …  
    32363253                                '<div class="a-su-pv-tabs">' + tabs.map( function ( t, i ) { return '<span' + ( i === 0 ? ' class="is-on"' : '' ) + '>' + esc( t ) + '</span>'; } ).join( '' ) + '</div>' +
    32373254                                ( '<div class="a-su-pv-grid"><span></span><span></span><span></span></div><span class="a-su-pv-btn">' + __( 'Follow', 'stubli' ) + '</span></div>' ) +
    3238                                 '<p class="a-label" id="a-su-col">' + _f( __( 'Colour: %s', 'stubli' ), esc( a.name ) ) + '</p><div class="a-swatches" role="radiogroup" aria-labelledby="a-su-col">' + d.accents.map( function ( c ) {
    3239                                         var on = c.key === d.accent;
    3240                                         return '<button type="button" role="radio" aria-checked="' + on + '" aria-label="' + esc( c.name + ( c.key === 'moss' ? __( ', the Stubli green', 'stubli' ) : '' ) ) + '" data-accent="' + c.key + '" tabindex="' + ( on ? 0 : -1 ) + '"><span style="background:' + ( pm === 'dark' ? c.dark : c.hex ) + '"></span><small>' + esc( c.name ) + '</small></button>';
    3241                                 } ).join( '' ) + '</div>' +
     3255                                '<p class="a-label" id="a-su-col">' + _f( __( 'Colour: %s', 'stubli' ), esc( a.name ) ) + '</p>' + swatches( d, 'a-su-col' ) +
    32423256                                ( d.accent === 'gold' && pm !== 'dark' ? ( '<p class="a-help" role="status">' + __( 'Gold is a soft colour, so your tabs blend in a little.', 'stubli' ) + '</p>' ) : '' ) +
    32433257                                ( '<p class="a-label" id="a-su-mode">' + __( 'Reading mode', 'stubli' ) + '</p><div class="a-chips" role="radiogroup" aria-labelledby="a-su-mode">' ) + [ [ 'light', __( 'Light', 'stubli' ) ], [ 'paper', __( 'Paper', 'stubli' ) ] ].map( function ( m ) {
    … …  
    33703384                                        e.preventDefault(); var nb = sw[ ( i + k + sw.length ) % sw.length ]; d.accent = nb.dataset.accent; renderSetup(); $( '[data-accent="' + d.accent + '"]' ).focus();
    33713385                                } );
     3386                        } );
     3387                        // Any colour is saved straight away, so the site can make it readable before the preview shows it.
     3388                        bindAnyColour( function ( change ) {
     3389                                send( 'POST', 'setup', change ).then( function ( nd ) { d.accents = nd.accents; d.accent = 'custom'; renderSetup(); var f = $( '.a-any' ); if ( f ) { f.focus(); } }, function ( e ) { toast( e.message ); } );
    33723390                        } );
    33733391                        $$( '[data-mode-pick]' ).forEach( function ( b ) { b.addEventListener( 'click', function () { d.mode = b.dataset.modePick; renderSetup(); $( '[data-mode-pick="' + d.mode + '"]' ).focus(); } ); } );
  • stubli/tags/0.57.0/includes/class-setup.php

    r3810626 r3816104  
    9898        public static function accent() {
    9999                $a = (string) get_option( 'stubli_accent', 'moss' );
     100                if ( 'custom' === $a ) {
     101                        return self::custom() ? 'custom' : 'moss';
     102                }
    100103                return isset( self::ACCENTS[ $a ] ) ? $a : 'moss';
    101104        }
    … …  
    121124                        return '';
    122125                }
    123                 list( , $light, $ink, $dark ) = array_map( 'sanitize_hex_color', self::ACCENTS[ $key ] );
    124                 // Gold is too pale for words on a light page, so text gets a deeper gold.
    125                 $text = 'gold' === $key ? '#7d5f16' : $light;
     126                $c = self::colours( $key );
     127                list( $light, $ink, $dark, $text ) = array( $c['hex'], $c['ink'], $c['dark'], $c['text'] );
    126128                return sprintf(
    127129                        ':root,[data-mode="light"],[data-mode="paper"]{--accent:%1$s;--accent-ink:%2$s;--accent-text:%4$s;--accent-far:%5$s;--st-accent:%1$s;--st-accent-ink:%2$s;--st-accent-text:%4$s;--st-accent-far:%5$s}[data-mode="dark"]{--accent:%3$s;--accent-ink:#1c1916;--accent-text:%3$s;--accent-far:#fff;--st-accent:%3$s;--st-accent-ink:#1c1916;--st-accent-text:%3$s;--st-accent-far:#fff}',
    … …  
    133135                        in_array( strtolower( $ink ), array( '#fff', '#ffffff' ), true ) ? '#000' : '#fff'
    134136                );
     137        }
     138
     139        /**
     140         * Any colour (0.57.0, Celestine 22 Nov): the owner's own accent, picked with the phone's colour picker.
     141         * Stored as option stubli_accent = 'custom' and stubli_accent_hex. Returns the colours to use, or null.
     142         *
     143         * @return array|null hex, ink, dark, text, adjusted.
     144         */
     145        public static function custom() {
     146                $hex = sanitize_hex_color( (string) get_option( 'stubli_accent_hex', '' ) );
     147                return $hex && 7 === strlen( $hex ) ? self::readable( $hex ) : null;
     148        }
     149
     150        /**
     151         * The colours for one accent: its own, the text on it, and a deeper shade for words on the page.
     152         *
     153         * @param string $key An ACCENTS key or 'custom'.
     154         * @return array
     155         */
     156        public static function colours( $key ) {
     157                if ( 'custom' === $key ) {
     158                        $c = self::custom();
     159                        if ( $c ) {
     160                                return $c;
     161                        }
     162                        $key = 'moss';
     163                }
     164                list( , $light, $ink, $dark ) = array_map( 'sanitize_hex_color', self::ACCENTS[ $key ] );
     165                // Gold is too pale for words on a light page, so text gets a deeper gold.
     166                return array(
     167                        'hex'      => $light,
     168                        'ink'      => $ink,
     169                        'dark'     => $dark,
     170                        'text'     => 'gold' === $key ? '#7d5f16' : $light,
     171                        'adjusted' => false,
     172                );
     173        }
     174
     175        /**
     176         * Make a colour safe to use (DESIGN.md §3.3: text on it at least 4.5:1). White or dark text, whichever reads;
     177         * if neither does, the colour is darkened until white text reads. Words in the accent on the page get a
     178         * shade dark enough to read on Paper (#f5efe6).
     179         *
     180         * @param string $hex #rrggbb.
     181         * @return array hex, ink, dark, text, adjusted.
     182         */
     183        public static function readable( $hex ) {
     184                $hex      = strtolower( $hex );
     185                $dark_ink = '#1d2433';
     186                $adjusted = false;
     187                // A colour almost the same as the page (white, cream) would make buttons vanish: darken it until it shows.
     188                for ( $i = 0; $i < 40 && self::contrast( $hex, '#f5efe6' ) < 1.5; $i++ ) {
     189                        $hex      = self::shade( $hex, 0.94 );
     190                        $adjusted = true;
     191                }
     192                if ( self::contrast( $hex, '#ffffff' ) >= 4.5 ) {
     193                        $ink = '#ffffff';
     194                } elseif ( self::contrast( $hex, $dark_ink ) >= 4.5 ) {
     195                        $ink = $dark_ink;
     196                } else {
     197                        $ink = '#ffffff';
     198                        for ( $i = 0; $i < 40 && self::contrast( $hex, $ink ) < 4.5; $i++ ) {
     199                                $hex = self::shade( $hex, 0.94 );
     200                        }
     201                        $adjusted = true;
     202                }
     203                $text = $hex;
     204                for ( $i = 0; $i < 60 && self::contrast( $text, '#f5efe6' ) < 4.5; $i++ ) {
     205                        $text = self::shade( $text, 0.93 );
     206                }
     207                return array(
     208                        'hex'      => $hex,
     209                        'ink'      => $ink,
     210                        'dark'     => $hex,
     211                        'text'     => $text,
     212                        'adjusted' => $adjusted,
     213                );
     214        }
     215
     216        /**
     217         * WCAG contrast ratio between two #rrggbb colours.
     218         *
     219         * @param string $a First colour.
     220         * @param string $b Second colour.
     221         * @return float
     222         */
     223        public static function contrast( $a, $b ) {
     224                $la = self::luminance( $a );
     225                $lb = self::luminance( $b );
     226                return ( max( $la, $lb ) + 0.05 ) / ( min( $la, $lb ) + 0.05 );
     227        }
     228
     229        /**
     230         * Relative luminance of a #rrggbb colour.
     231         *
     232         * @param string $hex Colour.
     233         * @return float
     234         */
     235        private static function luminance( $hex ) {
     236                $l = 0;
     237                foreach ( array( 0.2126, 0.7152, 0.0722 ) as $i => $w ) {
     238                        $c  = hexdec( substr( $hex, 1 + 2 * $i, 2 ) ) / 255;
     239                        $l += $w * ( $c <= 0.03928 ? $c / 12.92 : pow( ( $c + 0.055 ) / 1.055, 2.4 ) );
     240                }
     241                return $l;
     242        }
     243
     244        /**
     245         * A darker shade of a #rrggbb colour.
     246         *
     247         * @param string $hex    Colour.
     248         * @param float  $factor 0–1, smaller is darker.
     249         * @return string
     250         */
     251        private static function shade( $hex, $factor ) {
     252                $out = '#';
     253                for ( $i = 0; $i < 3; $i++ ) {
     254                        $out .= sprintf( '%02x', (int) round( hexdec( substr( $hex, 1 + 2 * $i, 2 ) ) * $factor ) );
     255                }
     256                return $out;
    135257        }
    136258
    … …  
    211333                                'ink'  => $a[2],
    212334                                'dark' => $a[3],
     335                                'text' => self::colours( $key )['text'],
     336                        );
     337                }
     338                $own = self::custom();
     339                if ( $own ) {
     340                        $accents[] = array(
     341                                'key'      => 'custom',
     342                                'name'     => __( 'Your own colour', 'stubli' ),
     343                                'hex'      => $own['hex'],
     344                                'ink'      => $own['ink'],
     345                                'dark'     => $own['dark'],
     346                                'text'     => $own['text'],
     347                                'picked'   => sanitize_hex_color( (string) get_option( 'stubli_accent_hex', '' ) ),
     348                                'adjusted' => $own['adjusted'],
    213349                        );
    214350                }
    … …  
    279415                        update_option( 'stubli_accent', (string) $c['accent'] );
    280416                }
     417                // Any colour: a #rrggbb from the colour picker. Kept as picked; what's shown is made readable in custom().
     418                if ( array_key_exists( 'accent_hex', $c ) ) {
     419                        $hex = sanitize_hex_color( (string) $c['accent_hex'] );
     420                        if ( $hex && 7 === strlen( $hex ) ) {
     421                                update_option( 'stubli_accent_hex', strtolower( $hex ) );
     422                                update_option( 'stubli_accent', 'custom' );
     423                        }
     424                }
    281425                if ( array_key_exists( 'mode', $c ) && in_array( (string) $c['mode'], self::MODES, true ) ) {
    282426                        update_option( 'stubli_mode', (string) $c['mode'] );
  • stubli/tags/0.57.0/readme.txt

    r3814657 r3816104  
    66Tested up to: 7.1
    77Requires PHP: 7.4
    8 Stable tag: 0.56.0
     8Stable tag: 0.57.0
    99License: GPLv2 or later
    1010License URI: https://www.gnu.org/licenses/gpl-2.0.html
    … …  
    110110== Changelog ==
    111111
     112= 0.57.0 =
     113* Any colour: besides the five colours, pick your own for buttons and tabs with your phone's colour picker. If it would make text hard to read, Stubli darkens it a little and tells you.
     114* Switching back to Moss in the app now shows it straight away.
     115
    112116= 0.56.0 =
    113117* Letters now look like letters: each one on its own sheet of lined paper, cream for theirs and white for yours, with who wrote it and when. Write back opens a page of its own, with the letter you're answering quoted underneath.
  • stubli/tags/0.57.0/wordgram.php

    r3814657 r3816104  
    33 * Plugin Name:       Stubli
    44 * Description:       Turns a WordPress site into a cosy, familiar photo-sharing home: a public profile with collections, a journal and a guest book, a private reader for the Stubli sites you follow, and comments between sites via Webmention.
    5  * Version:           0.56.0
     5 * Version:           0.57.0
    66 * Requires at least: 6.5
    77 * Requires PHP:      7.4
    … …  
    2222defined( 'ABSPATH' ) || exit;
    2323
    24 const VERSION        = '0.56.0';
     24const VERSION        = '0.57.0';
    2525const SCHEMA_VERSION = 5;
    2626const REST_NS        = 'stubli/v1';
  • stubli/trunk/assets/app/app.css

    r3814657 r3816104  
    360360.a-swatches [aria-checked="true"] { color: var(--ink); font-weight: 650; }
    361361.a-swatches [aria-checked="true"] span { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--ink); }
     362/* Any colour (0.57.0): a swatch like the others that opens the phone's colour picker. */
     363.a-any { position: relative; min-height: 64px; display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer; color: var(--muted); }
     364.a-any small { font-size: 12px; text-align: center; line-height: 1.2; }
     365.a-any-dot { width: 36px; height: 36px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0,0,0,.08); }
     366.a-any-dot.is-wheel { background: conic-gradient(#d94f4f, #e0b65a, #6fae5b, #3d8fb0, #6b3f5a, #d94f4f); }
     367.a-any[aria-checked="true"] { color: var(--ink); font-weight: 650; }
     368.a-any[aria-checked="true"] .a-any-dot { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--ink); }
     369.a-any-in { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; border: 0; padding: 0; }
     370.a-any:focus-within .a-any-dot { outline: 2px solid var(--ink); outline-offset: 3px; }
    362371.a-su-preview { margin: 18px 0 4px; padding: 16px; border-radius: 14px; background: var(--bg); color: var(--ink); box-shadow: inset 0 0 0 1px var(--field); font-size: 13px; position: relative; }
    363372.a-su-pv-head { display: flex; gap: 10px; align-items: center; }
  • stubli/trunk/assets/app/app.js

    r3814657 r3816104  
    23952395        }
    23962396        function accentCss( a ) {
    2397                 if ( ! a || a.key === 'moss' ) { return ''; }
    2398                 return ':root,[data-mode="light"],[data-mode="paper"]{--accent:' + a.hex + ';--accent-ink:' + a.ink + ';--accent-text:' + ( a.key === 'gold' ? '#7d5f16' : a.hex ) + '}[data-mode="dark"]{--accent:' + a.dark + ';--accent-ink:#1c1916;--accent-text:' + a.dark + '}';
     2397                // Moss too is written out, so switching back to it replaces the colour the page loaded with.
     2398                if ( ! a ) { return ''; }
     2399                return ':root,[data-mode="light"],[data-mode="paper"]{--accent:' + a.hex + ';--accent-ink:' + a.ink + ';--accent-text:' + ( a.text || a.hex ) + '}[data-mode="dark"]{--accent:' + a.dark + ';--accent-ink:#1c1916;--accent-text:' + a.dark + '}';
    23992400        }
    24002401        function accentOf( key ) { return su.d.accents.filter( function ( a ) { return a.key === key; } )[ 0 ] || su.d.accents[ 0 ]; }
     2402        // The named colours, then Any colour (0.57.0, Celestine 22 Nov): the phone's own colour picker. Stubli keeps
     2403        // text on it readable and says so when it had to darken it (Setup::readable()).
     2404        function swatches( d, label ) {
     2405                var own = d.accents.filter( function ( c ) { return c.key === 'custom'; } )[ 0 ], on = d.accent === 'custom';
     2406                return '<div class="a-swatches" role="radiogroup" aria-labelledby="' + label + '">' + d.accents.filter( function ( c ) { return c.key !== 'custom'; } ).map( function ( c ) {
     2407                        var sel = c.key === d.accent;
     2408                        return '<button type="button" role="radio" aria-checked="' + sel + '" aria-label="' + esc( c.name + ( c.key === 'moss' ? __( ', the Stubli green', 'stubli' ) : '' ) ) + '" data-accent="' + c.key + '" tabindex="' + ( sel ? 0 : -1 ) + '"><span style="background:' + c.hex + '"></span><small>' + esc( c.name ) + '</small></button>';
     2409                } ).join( '' ) +
     2410                        '<label class="a-any" role="radio" aria-checked="' + on + '" tabindex="' + ( on ? 0 : -1 ) + '"><span class="a-any-dot' + ( own ? '' : ' is-wheel' ) + '"' + ( own ? ' style="background:' + own.hex + '"' : '' ) + '></span><small>' + __( 'Any colour', 'stubli' ) + '</small>' +
     2411                        '<input type="color" class="a-any-in" data-accent-any value="' + esc( own ? own.picked || own.hex : '#4f6a4a' ) + '" aria-label="' + esc( __( 'Pick any colour', 'stubli' ) ) + '"></label></div>' +
     2412                        ( on && own && own.adjusted ? '<p class="a-help" role="status">' + __( 'We darkened your colour a little so text on it stays readable.', 'stubli' ) + '</p>' : '' );
     2413        }
     2414        function bindAnyColour( save ) {
     2415                var any = $( '[data-accent-any]' );
     2416                if ( ! any ) { return; }
     2417                any.addEventListener( 'change', function () { save( { accent_hex: any.value }, '.a-any' ); } );
     2418                any.closest( '.a-any' ).addEventListener( 'keydown', function ( e ) { if ( e.key === 'Enter' || e.key === ' ' ) { e.preventDefault(); any.click(); } } );
     2419        }
    24012420        function applyLook() {
    24022421                var s = document.getElementById( 'stubli-accent' );
    … …  
    31003119                var d = su.d, a = accentOf( d.accent ), pm = 'light';
    31013120                root.innerHTML = arrangeHead( '#more', __( 'Colour and reading mode', 'stubli' ) ) + '<main class="a-main" id="main">' +
    3102                         '<p class="a-label" id="a-lk-col">' + _f( __( 'Colour: %s', 'stubli' ), esc( a.name ) ) + '</p><div class="a-swatches" role="radiogroup" aria-labelledby="a-lk-col">' + d.accents.map( function ( c ) {
    3103                                 var on = c.key === d.accent;
    3104                                 return '<button type="button" role="radio" aria-checked="' + on + '" aria-label="' + esc( c.name + ( c.key === 'moss' ? __( ', the Stubli green', 'stubli' ) : '' ) ) + '" data-accent="' + c.key + '" tabindex="' + ( on ? 0 : -1 ) + '"><span style="background:' + ( pm === 'dark' ? c.dark : c.hex ) + '"></span><small>' + esc( c.name ) + '</small></button>';
    3105                         } ).join( '' ) + '</div>' +
     3121                        '<p class="a-label" id="a-lk-col">' + _f( __( 'Colour: %s', 'stubli' ), esc( a.name ) ) + '</p>' + swatches( d, 'a-lk-col' ) +
    31063122                        ( d.accent === 'gold' && pm !== 'dark' ? ( '<p class="a-help" role="status">' + __( 'Gold is a soft colour, so your tabs blend in a little.', 'stubli' ) + '</p>' ) : '' ) +
    31073123                        '<p class="a-label" id="a-lk-mode" style="margin-top:20px">' + __( 'Reading mode', 'stubli' ) + '</p><div class="a-chips" role="radiogroup" aria-labelledby="a-lk-mode">' + [ [ 'light', __( 'Light', 'stubli' ) ], [ 'paper', __( 'Paper', 'stubli' ) ] ].map( function ( m ) {
    … …  
    31223138                        } );
    31233139                } );
     3140                bindAnyColour( save );
    31243141                $$( '[data-mode-pick]' ).forEach( function ( b ) { b.addEventListener( 'click', function () { save( { mode: b.dataset.modePick }, '[data-mode-pick="' + b.dataset.modePick + '"]' ); } ); } );
    31253142                var ss = $( '[data-lk-season]' );
    … …  
    32363253                                '<div class="a-su-pv-tabs">' + tabs.map( function ( t, i ) { return '<span' + ( i === 0 ? ' class="is-on"' : '' ) + '>' + esc( t ) + '</span>'; } ).join( '' ) + '</div>' +
    32373254                                ( '<div class="a-su-pv-grid"><span></span><span></span><span></span></div><span class="a-su-pv-btn">' + __( 'Follow', 'stubli' ) + '</span></div>' ) +
    3238                                 '<p class="a-label" id="a-su-col">' + _f( __( 'Colour: %s', 'stubli' ), esc( a.name ) ) + '</p><div class="a-swatches" role="radiogroup" aria-labelledby="a-su-col">' + d.accents.map( function ( c ) {
    3239                                         var on = c.key === d.accent;
    3240                                         return '<button type="button" role="radio" aria-checked="' + on + '" aria-label="' + esc( c.name + ( c.key === 'moss' ? __( ', the Stubli green', 'stubli' ) : '' ) ) + '" data-accent="' + c.key + '" tabindex="' + ( on ? 0 : -1 ) + '"><span style="background:' + ( pm === 'dark' ? c.dark : c.hex ) + '"></span><small>' + esc( c.name ) + '</small></button>';
    3241                                 } ).join( '' ) + '</div>' +
     3255                                '<p class="a-label" id="a-su-col">' + _f( __( 'Colour: %s', 'stubli' ), esc( a.name ) ) + '</p>' + swatches( d, 'a-su-col' ) +
    32423256                                ( d.accent === 'gold' && pm !== 'dark' ? ( '<p class="a-help" role="status">' + __( 'Gold is a soft colour, so your tabs blend in a little.', 'stubli' ) + '</p>' ) : '' ) +
    32433257                                ( '<p class="a-label" id="a-su-mode">' + __( 'Reading mode', 'stubli' ) + '</p><div class="a-chips" role="radiogroup" aria-labelledby="a-su-mode">' ) + [ [ 'light', __( 'Light', 'stubli' ) ], [ 'paper', __( 'Paper', 'stubli' ) ] ].map( function ( m ) {
    … …  
    33703384                                        e.preventDefault(); var nb = sw[ ( i + k + sw.length ) % sw.length ]; d.accent = nb.dataset.accent; renderSetup(); $( '[data-accent="' + d.accent + '"]' ).focus();
    33713385                                } );
     3386                        } );
     3387                        // Any colour is saved straight away, so the site can make it readable before the preview shows it.
     3388                        bindAnyColour( function ( change ) {
     3389                                send( 'POST', 'setup', change ).then( function ( nd ) { d.accents = nd.accents; d.accent = 'custom'; renderSetup(); var f = $( '.a-any' ); if ( f ) { f.focus(); } }, function ( e ) { toast( e.message ); } );
    33723390                        } );
    33733391                        $$( '[data-mode-pick]' ).forEach( function ( b ) { b.addEventListener( 'click', function () { d.mode = b.dataset.modePick; renderSetup(); $( '[data-mode-pick="' + d.mode + '"]' ).focus(); } ); } );
  • stubli/trunk/includes/class-setup.php

    r3810626 r3816104  
    9898        public static function accent() {
    9999                $a = (string) get_option( 'stubli_accent', 'moss' );
     100                if ( 'custom' === $a ) {
     101                        return self::custom() ? 'custom' : 'moss';
     102                }
    100103                return isset( self::ACCENTS[ $a ] ) ? $a : 'moss';
    101104        }
    … …  
    121124                        return '';
    122125                }
    123                 list( , $light, $ink, $dark ) = array_map( 'sanitize_hex_color', self::ACCENTS[ $key ] );
    124                 // Gold is too pale for words on a light page, so text gets a deeper gold.
    125                 $text = 'gold' === $key ? '#7d5f16' : $light;
     126                $c = self::colours( $key );
     127                list( $light, $ink, $dark, $text ) = array( $c['hex'], $c['ink'], $c['dark'], $c['text'] );
    126128                return sprintf(
    127129                        ':root,[data-mode="light"],[data-mode="paper"]{--accent:%1$s;--accent-ink:%2$s;--accent-text:%4$s;--accent-far:%5$s;--st-accent:%1$s;--st-accent-ink:%2$s;--st-accent-text:%4$s;--st-accent-far:%5$s}[data-mode="dark"]{--accent:%3$s;--accent-ink:#1c1916;--accent-text:%3$s;--accent-far:#fff;--st-accent:%3$s;--st-accent-ink:#1c1916;--st-accent-text:%3$s;--st-accent-far:#fff}',
    … …  
    133135                        in_array( strtolower( $ink ), array( '#fff', '#ffffff' ), true ) ? '#000' : '#fff'
    134136                );
     137        }
     138
     139        /**
     140         * Any colour (0.57.0, Celestine 22 Nov): the owner's own accent, picked with the phone's colour picker.
     141         * Stored as option stubli_accent = 'custom' and stubli_accent_hex. Returns the colours to use, or null.
     142         *
     143         * @return array|null hex, ink, dark, text, adjusted.
     144         */
     145        public static function custom() {
     146                $hex = sanitize_hex_color( (string) get_option( 'stubli_accent_hex', '' ) );
     147                return $hex && 7 === strlen( $hex ) ? self::readable( $hex ) : null;
     148        }
     149
     150        /**
     151         * The colours for one accent: its own, the text on it, and a deeper shade for words on the page.
     152         *
     153         * @param string $key An ACCENTS key or 'custom'.
     154         * @return array
     155         */
     156        public static function colours( $key ) {
     157                if ( 'custom' === $key ) {
     158                        $c = self::custom();
     159                        if ( $c ) {
     160                                return $c;
     161                        }
     162                        $key = 'moss';
     163                }
     164                list( , $light, $ink, $dark ) = array_map( 'sanitize_hex_color', self::ACCENTS[ $key ] );
     165                // Gold is too pale for words on a light page, so text gets a deeper gold.
     166                return array(
     167                        'hex'      => $light,
     168                        'ink'      => $ink,
     169                        'dark'     => $dark,
     170                        'text'     => 'gold' === $key ? '#7d5f16' : $light,
     171                        'adjusted' => false,
     172                );
     173        }
     174
     175        /**
     176         * Make a colour safe to use (DESIGN.md §3.3: text on it at least 4.5:1). White or dark text, whichever reads;
     177         * if neither does, the colour is darkened until white text reads. Words in the accent on the page get a
     178         * shade dark enough to read on Paper (#f5efe6).
     179         *
     180         * @param string $hex #rrggbb.
     181         * @return array hex, ink, dark, text, adjusted.
     182         */
     183        public static function readable( $hex ) {
     184                $hex      = strtolower( $hex );
     185                $dark_ink = '#1d2433';
     186                $adjusted = false;
     187                // A colour almost the same as the page (white, cream) would make buttons vanish: darken it until it shows.
     188                for ( $i = 0; $i < 40 && self::contrast( $hex, '#f5efe6' ) < 1.5; $i++ ) {
     189                        $hex      = self::shade( $hex, 0.94 );
     190                        $adjusted = true;
     191                }
     192                if ( self::contrast( $hex, '#ffffff' ) >= 4.5 ) {
     193                        $ink = '#ffffff';
     194                } elseif ( self::contrast( $hex, $dark_ink ) >= 4.5 ) {
     195                        $ink = $dark_ink;
     196                } else {
     197                        $ink = '#ffffff';
     198                        for ( $i = 0; $i < 40 && self::contrast( $hex, $ink ) < 4.5; $i++ ) {
     199                                $hex = self::shade( $hex, 0.94 );
     200                        }
     201                        $adjusted = true;
     202                }
     203                $text = $hex;
     204                for ( $i = 0; $i < 60 && self::contrast( $text, '#f5efe6' ) < 4.5; $i++ ) {
     205                        $text = self::shade( $text, 0.93 );
     206                }
     207                return array(
     208                        'hex'      => $hex,
     209                        'ink'      => $ink,
     210                        'dark'     => $hex,
     211                        'text'     => $text,
     212                        'adjusted' => $adjusted,
     213                );
     214        }
     215
     216        /**
     217         * WCAG contrast ratio between two #rrggbb colours.
     218         *
     219         * @param string $a First colour.
     220         * @param string $b Second colour.
     221         * @return float
     222         */
     223        public static function contrast( $a, $b ) {
     224                $la = self::luminance( $a );
     225                $lb = self::luminance( $b );
     226                return ( max( $la, $lb ) + 0.05 ) / ( min( $la, $lb ) + 0.05 );
     227        }
     228
     229        /**
     230         * Relative luminance of a #rrggbb colour.
     231         *
     232         * @param string $hex Colour.
     233         * @return float
     234         */
     235        private static function luminance( $hex ) {
     236                $l = 0;
     237                foreach ( array( 0.2126, 0.7152, 0.0722 ) as $i => $w ) {
     238                        $c  = hexdec( substr( $hex, 1 + 2 * $i, 2 ) ) / 255;
     239                        $l += $w * ( $c <= 0.03928 ? $c / 12.92 : pow( ( $c + 0.055 ) / 1.055, 2.4 ) );
     240                }
     241                return $l;
     242        }
     243
     244        /**
     245         * A darker shade of a #rrggbb colour.
     246         *
     247         * @param string $hex    Colour.
     248         * @param float  $factor 0–1, smaller is darker.
     249         * @return string
     250         */
     251        private static function shade( $hex, $factor ) {
     252                $out = '#';
     253                for ( $i = 0; $i < 3; $i++ ) {
     254                        $out .= sprintf( '%02x', (int) round( hexdec( substr( $hex, 1 + 2 * $i, 2 ) ) * $factor ) );
     255                }
     256                return $out;
    135257        }
    136258
    … …  
    211333                                'ink'  => $a[2],
    212334                                'dark' => $a[3],
     335                                'text' => self::colours( $key )['text'],
     336                        );
     337                }
     338                $own = self::custom();
     339                if ( $own ) {
     340                        $accents[] = array(
     341                                'key'      => 'custom',
     342                                'name'     => __( 'Your own colour', 'stubli' ),
     343                                'hex'      => $own['hex'],
     344                                'ink'      => $own['ink'],
     345                                'dark'     => $own['dark'],
     346                                'text'     => $own['text'],
     347                                'picked'   => sanitize_hex_color( (string) get_option( 'stubli_accent_hex', '' ) ),
     348                                'adjusted' => $own['adjusted'],
    213349                        );
    214350                }
    … …  
    279415                        update_option( 'stubli_accent', (string) $c['accent'] );
    280416                }
     417                // Any colour: a #rrggbb from the colour picker. Kept as picked; what's shown is made readable in custom().
     418                if ( array_key_exists( 'accent_hex', $c ) ) {
     419                        $hex = sanitize_hex_color( (string) $c['accent_hex'] );
     420                        if ( $hex && 7 === strlen( $hex ) ) {
     421                                update_option( 'stubli_accent_hex', strtolower( $hex ) );
     422                                update_option( 'stubli_accent', 'custom' );
     423                        }
     424                }
    281425                if ( array_key_exists( 'mode', $c ) && in_array( (string) $c['mode'], self::MODES, true ) ) {
    282426                        update_option( 'stubli_mode', (string) $c['mode'] );
  • stubli/trunk/readme.txt

    r3814657 r3816104  
    66Tested up to: 7.1
    77Requires PHP: 7.4
    8 Stable tag: 0.56.0
     8Stable tag: 0.57.0
    99License: GPLv2 or later
    1010License URI: https://www.gnu.org/licenses/gpl-2.0.html
    … …  
    110110== Changelog ==
    111111
     112= 0.57.0 =
     113* Any colour: besides the five colours, pick your own for buttons and tabs with your phone's colour picker. If it would make text hard to read, Stubli darkens it a little and tells you.
     114* Switching back to Moss in the app now shows it straight away.
     115
    112116= 0.56.0 =
    113117* Letters now look like letters: each one on its own sheet of lined paper, cream for theirs and white for yours, with who wrote it and when. Write back opens a page of its own, with the letter you're answering quoted underneath.
  • stubli/trunk/wordgram.php

    r3814657 r3816104  
    33 * Plugin Name:       Stubli
    44 * Description:       Turns a WordPress site into a cosy, familiar photo-sharing home: a public profile with collections, a journal and a guest book, a private reader for the Stubli sites you follow, and comments between sites via Webmention.
    5  * Version:           0.56.0
     5 * Version:           0.57.0
    66 * Requires at least: 6.5
    77 * Requires PHP:      7.4
    … …  
    2222defined( 'ABSPATH' ) || exit;
    2323
    24 const VERSION        = '0.56.0';
     24const VERSION        = '0.57.0';
    2525const SCHEMA_VERSION = 5;
    2626const REST_NS        = 'stubli/v1';
Note: See TracChangeset for help on using the changeset viewer.